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);
  // Resolve a leading `~` (the client may pass `~/...` as the working dir, e.g.
  // an ephemeral `run`/drive mount path) against the node user's home. On
  // Windows, also translate an MSYS cwd (`/c/...`, as Git Bash reports `$PWD`
  // and as TAB-completion's one-shot exec reuses it) into a Windows path
  // `Process.start` can actually `chdir` into.
  final raw = request.cwd;
  var cwd = raw != null ? expandUserHome(raw) : workingDirectory;
  if (Platform.isWindows && cwd != null && cwd.startsWith('/')) {
    cwd = windowsPathFromMsys(cwd);
  }
  final process = await Process.start(
    executable,
    args,
    workingDirectory: cwd,
    environment: {...baseEnvironment, ..._ptyEnv(request), ...request.env},
    includeParentEnvironment: true,
  );
  return ProcessShellSession(
    process,
    shellFamily: classifyShellFamily(executable),
  );
}