From 511d2b7fb9470eee2625f0d8f55382a1c5ab2a74 Mon Sep 17 00:00:00 2001 From: suraj-markup Date: Tue, 17 Mar 2026 15:51:02 +0530 Subject: [PATCH] Resolve remaining PR review comments - Remove redundant project-existence check after autoDetectProject - Wrap SIGTERM in try/catch for restart flow (dead process case) - Remove unused setCallerContext export from caller-context.ts - Fix unused vi import lint error in init.test.ts Co-Authored-By: Claude Opus 4.6 --- packages/cli/__tests__/commands/init.test.ts | 2 +- packages/cli/__tests__/commands/start.test.ts | 1 - packages/cli/src/commands/spawn.ts | 9 -------- packages/cli/src/commands/start.ts | 2 +- packages/cli/src/lib/caller-context.ts | 23 ------------------- 5 files changed, 2 insertions(+), 35 deletions(-) diff --git a/packages/cli/__tests__/commands/init.test.ts b/packages/cli/__tests__/commands/init.test.ts index dfbf68c21..ce724a1f5 100644 --- a/packages/cli/__tests__/commands/init.test.ts +++ b/packages/cli/__tests__/commands/init.test.ts @@ -1,4 +1,4 @@ -import { describe, it, expect, vi } from "vitest"; +import { describe, it, expect } from "vitest"; import { Command } from "commander"; import { registerInit } from "../../src/commands/init.js"; diff --git a/packages/cli/__tests__/commands/start.test.ts b/packages/cli/__tests__/commands/start.test.ts index 2b0af2f21..b6942c859 100644 --- a/packages/cli/__tests__/commands/start.test.ts +++ b/packages/cli/__tests__/commands/start.test.ts @@ -127,7 +127,6 @@ vi.mock("../../src/lib/running-state.js", () => ({ vi.mock("../../src/lib/caller-context.js", () => ({ isHumanCaller: vi.fn().mockReturnValue(true), getCallerType: vi.fn().mockReturnValue("human"), - setCallerContext: vi.fn(), })); vi.mock("../../src/lib/detect-env.js", () => ({ diff --git a/packages/cli/src/commands/spawn.ts b/packages/cli/src/commands/spawn.ts index eecd3d075..943115b11 100644 --- a/packages/cli/src/commands/spawn.ts +++ b/packages/cli/src/commands/spawn.ts @@ -214,15 +214,6 @@ export function registerSpawn(program: Command): void { } } - if (!config.projects[projectId]) { - console.error( - chalk.red( - `Unknown project: ${projectId}\nAvailable: ${Object.keys(config.projects).join(", ")}`, - ), - ); - process.exit(1); - } - if (!opts.claimPr && opts.assignOnGithub) { console.error(chalk.red("--assign-on-github requires --claim-pr on `ao spawn`.")); process.exit(1); diff --git a/packages/cli/src/commands/start.ts b/packages/cli/src/commands/start.ts index 63e44aa14..7046888c6 100644 --- a/packages/cli/src/commands/start.ts +++ b/packages/cli/src/commands/start.ts @@ -802,7 +802,7 @@ export function registerStart(program: Command): void { project = config.projects[newId]; // Continue to startup below } else if (choice.trim() === "3") { - process.kill(running.pid, "SIGTERM"); + try { process.kill(running.pid, "SIGTERM"); } catch { /* already dead */ } const { waitForExit } = await import("../lib/running-state.js"); if (!waitForExit(running.pid, 5000)) { console.log(chalk.yellow(" Process didn't exit cleanly, sending SIGKILL...")); diff --git a/packages/cli/src/lib/caller-context.ts b/packages/cli/src/lib/caller-context.ts index 0b77eda96..67106209a 100644 --- a/packages/cli/src/lib/caller-context.ts +++ b/packages/cli/src/lib/caller-context.ts @@ -1,13 +1,5 @@ export type CallerType = "human" | "orchestrator" | "agent"; -export interface CallerContextOpts { - callerType: CallerType; - sessionId?: string; - projectId?: string; - configPath?: string; - port?: number; -} - /** * Detect who is calling the CLI. * - If AO_CALLER_TYPE is set, trust it. @@ -28,18 +20,3 @@ export function getCallerType(): CallerType { export function isHumanCaller(): boolean { return getCallerType() === "human"; } - -/** - * Inject AO context environment variables into an env record. - * Used when spawning orchestrator/agent sessions so they know their context. - */ -export function setCallerContext( - env: Record, - opts: CallerContextOpts, -): void { - env["AO_CALLER_TYPE"] = opts.callerType; - if (opts.sessionId) env["AO_SESSION_ID"] = opts.sessionId; - if (opts.projectId) env["AO_PROJECT_ID"] = opts.projectId; - if (opts.configPath) env["AO_CONFIG_PATH"] = opts.configPath; - if (opts.port !== undefined && opts.port !== null) env["AO_PORT"] = String(opts.port); -}