run method

  1. @override
Future<void> run(
  1. LocalCommandContext context,
  2. List<String> args
)
override

Runs the command with parsed args.

Implementation

@override
Future<void> run(LocalCommandContext context, List<String> args) async {
  final runFullScreen = context.runFullScreen;
  if (runFullScreen == null) {
    context.writeLine(':ide requires an interactive terminal.');
    return;
  }
  if (args.length > 1) {
    context.writeLine('usage: :ide [path]');
    return;
  }
  final arg = args.isEmpty ? null : args.first;

  // Connected → the remote node at its working directory; local → this machine.
  final Workspace workspace;
  if (context.client != null) {
    final root = resolveRemoteIdeRoot(arg, context.currentRemoteCwd?.call());
    if (root == null) {
      context.writeLine(
        ':ide: remote working directory unknown yet — run a command first, '
        'or pass an absolute path.',
      );
      return;
    }
    workspace = RemoteWorkspace(
      client: context.requireClient,
      nodeId: context.node.id.value,
      rootPath: root,
      shellFamily: context.shellFamily,
    );
  } else {
    final root = _resolveRoot(arg);
    if (!Directory(root).existsSync()) {
      context.writeLine(':ide: no such directory: $root');
      return;
    }
    workspace = LocalWorkspace(root);
  }

  // Wire the AI agent panel to the configured provider (env / ai.yaml). When
  // none is configured the panel shows setup help instead. The agent's
  // run_command tool is gated by the same command_shield used by `:ai`.
  final aiConfig = AiConfigIo.load();
  final aiProvider = aiConfig == null
      ? null
      : providerFor(aiConfig, http.Client());
  final shield = CommandShield(
    analyzer: Analyzer(
      securityAnalyzer: SecurityAnalyzer(
        detectors: [
          ...SecurityAnalyzer.defaultDetectors,
          KnowledgeRiskDetector(),
        ],
      ),
    ),
  );

  await runFullScreen((input) async {
    final app = IdeApp(
      workspace: workspace,
      terminal: Terminal(inputOverride: input),
      aiProvider: aiProvider,
      aiModel: aiConfig?.model,
      shield: shield,
      commandSyntax: ideCommandSyntaxFor(context.shellFamily),
    );
    await app.run();
  });
}