{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../../src/core/unity-mcp/cli.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAgEH,wBAAgB,eAAe,IAAI,MAAM,CAExC;AAED,wBAAsB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAuDzE","sourcesContent":["/**\n * Unity MCP Vertical Slice — CLI (2.13.0).\n *\n * `jensen unity inspect [--json]`\n * `jensen unity schedule-proof [--json]`\n * `jensen unity server-config [--json]`\n *\n * One-shot, process-lifetime operations. `inspect` verifies SSH, connects to\n * the real Unity MCP relay, discovers enabled tools, performs a read-only\n * Console observation, records Evidence, and disconnects. `schedule-proof`\n * proves Mission → Scheduler → Assignment → Unity executor designation and\n * STOPS there; it does not execute anything. No persistent worker is implied.\n */\n\nimport { mkdtempSync } from \"node:fs\";\nimport { tmpdir } from \"node:os\";\nimport { join } from \"node:path\";\nimport chalk from \"chalk\";\nimport { getAgentDir } from \"../../config.js\";\nimport { EvidenceFileStore } from \"../context-runtime/evidence-archive.js\";\nimport { McpClientService } from \"../mcp-foundation/mcp-client-service.js\";\nimport { inspectUnity } from \"./unity-inspect.js\";\nimport { runUnitySchedulerProof } from \"./unity-scheduler-proof.js\";\nimport { buildUnityMcpServerDefinition, LOTG_UNITY_TARGET } from \"./unity-server-config.js\";\nimport type { UnityInspectionResult } from \"./unity-types.js\";\n\nconst SUBCOMMANDS = new Set([\"inspect\", \"schedule-proof\", \"server-config\"]);\n\nfunction flag(args: string[], name: string): boolean {\n\treturn args.includes(name);\n}\n\nfunction printJson(payload: unknown): void {\n\tprocess.stdout.write(`${JSON.stringify(payload, null, 2)}\\n`);\n}\n\nfunction codeOf(error: unknown): string | undefined {\n\tif (typeof error === \"object\" && error !== null && \"code\" in error) {\n\t\treturn String((error as { code: unknown }).code);\n\t}\n\treturn undefined;\n}\n\nfunction renderError(error: unknown): void {\n\tconst message = error instanceof Error ? error.message : String(error);\n\tconst code = codeOf(error);\n\tprocess.stderr.write(`${chalk.red(code ? `${code}: ${message}` : message)}\\n`);\n}\n\nfunction renderInspection(result: UnityInspectionResult): void {\n\tprocess.stdout.write(`UNITY MCP INSPECTION\\n`);\n\tprocess.stdout.write(`  server: ${result.serverId}\\n`);\n\tprocess.stdout.write(`  machine: ${result.machine}\\n`);\n\tprocess.stdout.write(`  connection: ${result.connection}\\n`);\n\tif (result.connectionReason) process.stdout.write(`  reason: ${result.connectionReason}\\n`);\n\tif (result.serverIdentity)\n\t\tprocess.stdout.write(`  identity: ${result.serverIdentity.name}@${result.serverIdentity.version}\\n`);\n\tif (result.protocolVersion) process.stdout.write(`  protocol: ${result.protocolVersion}\\n`);\n\tif (result.protocolEra) process.stdout.write(`  protocol era: ${result.protocolEra}\\n`);\n\tif (result.sessionId) process.stdout.write(`  session: ${result.sessionId}\\n`);\n\tif (result.tools.length > 0) {\n\t\tprocess.stdout.write(`  tools:\\n`);\n\t\tfor (const tool of result.tools) {\n\t\t\tprocess.stdout.write(`    ${tool.mutating ? \"WRITE\" : \"READ\"}  ${tool.name}\\n`);\n\t\t}\n\t}\n\tfor (const obs of result.observations) {\n\t\tprocess.stdout.write(`  ${obs.category}: ${obs.status}`);\n\t\tif (obs.missingTool) process.stdout.write(` (missing: ${obs.missingTool})`);\n\t\tprocess.stdout.write(\"\\n\");\n\t}\n\tfor (const id of result.evidenceIds) {\n\t\tprocess.stdout.write(`  evidence: ${id}\\n`);\n\t}\n}\n\nexport function printUnityUsage(): string {\n\treturn [\"  unity inspect [--json]\", \"  unity schedule-proof [--json]\", \"  unity server-config [--json]\"].join(\"\\n\");\n}\n\nexport async function handleUnityCommand(args: string[]): Promise<boolean> {\n\tif (args[0] !== \"unity\") return false;\n\tconst sub = args[1];\n\tif (!sub || !SUBCOMMANDS.has(sub)) return false;\n\n\tconst json = flag(args, \"--json\");\n\n\ttry {\n\t\tswitch (sub) {\n\t\t\tcase \"server-config\": {\n\t\t\t\tconst definition = buildUnityMcpServerDefinition(LOTG_UNITY_TARGET);\n\t\t\t\tif (json) printJson(definition);\n\t\t\t\telse {\n\t\t\t\t\tprocess.stdout.write(`${definition.id}\\n`);\n\t\t\t\t\tprocess.stdout.write(`  command: ${definition.command}\\n`);\n\t\t\t\t\tfor (const arg of definition.args ?? []) process.stdout.write(`  arg: ${arg}\\n`);\n\t\t\t\t}\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\tcase \"inspect\": {\n\t\t\t\tconst archive = new EvidenceFileStore(join(getAgentDir(), \"context-evidence\"));\n\t\t\t\tconst service = new McpClientService({ evidenceArchive: archive });\n\t\t\t\tconst result = await inspectUnity({ target: LOTG_UNITY_TARGET, service });\n\t\t\t\tif (json) printJson(result);\n\t\t\t\telse renderInspection(result);\n\t\t\t\tif (result.connection !== \"PASS\") process.exitCode = 1;\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\tcase \"schedule-proof\": {\n\t\t\t\tconst root = mkdtempSync(join(tmpdir(), \"unity-scheduler-proof-\"));\n\t\t\t\tconst result = await runUnitySchedulerProof({ root });\n\t\t\t\tif (json) printJson(result);\n\t\t\t\telse {\n\t\t\t\t\tprocess.stdout.write(`UNITY SCHEDULER PROOF\\n`);\n\t\t\t\t\tprocess.stdout.write(`  mission: ${result.missionId}\\n`);\n\t\t\t\t\tprocess.stdout.write(`  intent: ${result.intentId}\\n`);\n\t\t\t\t\tprocess.stdout.write(`  decision: ${result.decision}\\n`);\n\t\t\t\t\tprocess.stdout.write(`  executor: ${result.executorId}\\n`);\n\t\t\t\t\tif (result.assignmentId) process.stdout.write(`  assignment: ${result.assignmentId}\\n`);\n\t\t\t\t\tif (result.reason) process.stdout.write(`  reason: ${result.reason}\\n`);\n\t\t\t\t}\n\t\t\t\tif (result.decision !== \"ASSIGN\") process.exitCode = 1;\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\tdefault:\n\t\t\t\treturn false;\n\t\t}\n\t} catch (error) {\n\t\trenderError(error);\n\t\tprocess.exitCode = 1;\n\t\treturn true;\n\t}\n}\n"]}