start method

  1. @override
Future<ShellSession> start(
  1. ShellRequest request
)
override

Starts a session for request, returning a live ShellSession.

May throw if the command is invalid or the node is at capacity; the node runtime translates failures into a node.session.rejected message.

Implementation

@override
Future<ShellSession> start(ShellRequest request) async {
  if (allowCommand != null && !allowCommand!(request)) {
    throw ProcessException(
      request.command ?? defaultShell,
      request.args,
      'Command not permitted by node policy',
    );
  }

  final (executable, args) = resolveShellInvocation(request, defaultShell);
  // Client's choice, then the node's, then the user's home — and only then
  // wherever this process happens to be standing. See `resolveStartDirectory`.
  final cwd = resolveStartDirectory(
    requested: request.cwd,
    configured: workingDirectory,
  );
  final process = await Process.start(
    executable,
    args,
    workingDirectory: cwd,
    // `withUserHome` only fills in `HOME` when neither this process nor the
    // request supplies one — a node run as a service is handed no `HOME`, and
    // a shell without one is subtly broken rather than obviously so.
    environment: withUserHome({
      ...baseEnvironment,
      ..._ptyEnv(request),
      ...request.env,
    }),
    includeParentEnvironment: true,
  );
  return ProcessShellSession(
    process,
    shellFamily: classifyShellFamily(executable),
  );
}