@agent-deck/cli 2.0.0 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/dist/agent-harness.d.ts +3 -0
  2. package/dist/agent-harness.d.ts.map +1 -1
  3. package/dist/agent-harness.js +64 -6
  4. package/dist/agent-harness.js.map +1 -1
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +10 -2
  7. package/dist/index.js.map +1 -1
  8. package/dist/mcp-bridge.d.ts +83 -1
  9. package/dist/mcp-bridge.d.ts.map +1 -1
  10. package/dist/mcp-bridge.js +252 -7
  11. package/dist/mcp-bridge.js.map +1 -1
  12. package/dist/mcp-config.d.ts +13 -1
  13. package/dist/mcp-config.d.ts.map +1 -1
  14. package/dist/mcp-config.js +49 -1
  15. package/dist/mcp-config.js.map +1 -1
  16. package/dist/muse-skills/agent-deck-playbooks/SKILL.md +23 -0
  17. package/dist/muse-skills/agent-deck-run/SKILL.md +86 -0
  18. package/dist/muse-skills/agent-deck-session/SKILL.md +59 -0
  19. package/dist/muse-skills/agent-deck-setup/SKILL.md +32 -0
  20. package/dist/muse-skills.d.ts +42 -0
  21. package/dist/muse-skills.d.ts.map +1 -0
  22. package/dist/muse-skills.js +149 -0
  23. package/dist/muse-skills.js.map +1 -0
  24. package/dist/run-adapter.d.ts +100 -0
  25. package/dist/run-adapter.d.ts.map +1 -0
  26. package/dist/run-adapter.js +73 -0
  27. package/dist/run-adapter.js.map +1 -0
  28. package/dist/run-claude.d.ts +41 -0
  29. package/dist/run-claude.d.ts.map +1 -0
  30. package/dist/run-claude.js +91 -0
  31. package/dist/run-claude.js.map +1 -0
  32. package/dist/run-codex.d.ts +75 -0
  33. package/dist/run-codex.d.ts.map +1 -0
  34. package/dist/run-codex.js +337 -0
  35. package/dist/run-codex.js.map +1 -0
  36. package/dist/run-cursor.d.ts +79 -0
  37. package/dist/run-cursor.d.ts.map +1 -0
  38. package/dist/run-cursor.js +455 -0
  39. package/dist/run-cursor.js.map +1 -0
  40. package/dist/run-detach.d.ts +36 -0
  41. package/dist/run-detach.d.ts.map +1 -0
  42. package/dist/run-detach.js +233 -0
  43. package/dist/run-detach.js.map +1 -0
  44. package/dist/run-muse.d.ts +127 -0
  45. package/dist/run-muse.d.ts.map +1 -0
  46. package/dist/run-muse.js +499 -0
  47. package/dist/run-muse.js.map +1 -0
  48. package/dist/run-status.d.ts +62 -0
  49. package/dist/run-status.d.ts.map +1 -0
  50. package/dist/run-status.js +552 -0
  51. package/dist/run-status.js.map +1 -0
  52. package/dist/run.d.ts +191 -0
  53. package/dist/run.d.ts.map +1 -0
  54. package/dist/run.js +680 -0
  55. package/dist/run.js.map +1 -0
  56. package/dist/setup.d.ts.map +1 -1
  57. package/dist/setup.js +51 -10
  58. package/dist/setup.js.map +1 -1
  59. package/dist/use.d.ts +1 -1
  60. package/dist/use.d.ts.map +1 -1
  61. package/dist/use.js +16 -15
  62. package/dist/use.js.map +1 -1
  63. package/package.json +5 -4
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-adapter.js","sourceRoot":"","sources":["../src/run-adapter.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AAwCH,wDAEC;AASD,oDAEC;AAED,8CAEC;AAED,0DAEC;AAED,4CAKC;AAlED,qEAAqE;AACxD,QAAA,kBAAkB,GAAsB;IACnD,oBAAoB;IACpB,MAAM;IACN,MAAM;IACN,MAAM;IACN,iBAAiB;IACjB,oBAAoB;IACpB,YAAY;CACb,CAAC;AAEF;;;;;;;GAOG;AACU,QAAA,cAAc,GAAsB;IAC/C,GAAG,0BAAkB;IACrB,MAAM;IACN,OAAO;IACP,kBAAkB;IAClB,iBAAiB;IACjB,oBAAoB;IACpB,yBAAyB;CAC1B,CAAC;AAEF,+EAA+E;AAClE,QAAA,mBAAmB,GAAG,aAAa,CAAC;AAEjD,iDAAiD;AACpC,QAAA,mBAAmB,GAAsB,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;AAE7D,QAAA,iBAAiB,GAAG,CAAC,UAAU,EAAE,MAAM,CAAU,CAAC;AAG/D,SAAgB,sBAAsB,CAAC,OAAwB;IAC7D,OAAO,OAAO,KAAK,MAAM,CAAC,CAAC,CAAC,sBAAc,CAAC,CAAC,CAAC,0BAAkB,CAAC;AAClE,CAAC;AAED,sCAAsC;AACzB,QAAA,qBAAqB,GAAG,CAAC,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAU,CAAC;AAGpF,uFAAuF;AAC1E,QAAA,kBAAkB,GAAG,EAAW,CAAC;AAE9C,SAAgB,oBAAoB,CAAC,KAAa;IAChD,OAAQ,6BAA2C,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACtE,CAAC;AAED,SAAgB,iBAAiB,CAAC,KAAa;IAC7C,OAAQ,0BAAwC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACnE,CAAC;AAED,SAAgB,uBAAuB;IACrC,OAAO,+FAA+F,CAAC;AACzG,CAAC;AAED,SAAgB,gBAAgB,CAAC,MAAc;IAC7C,IAAI,iBAAiB,CAAC,MAAM,CAAC,EAAE,CAAC;QAC9B,OAAO,mBAAmB,MAAM,yEAAyE,CAAC;IAC5G,CAAC;IACD,OAAO,8DAA8D,MAAM,IAAI,CAAC;AAClF,CAAC"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Claude adapter for `agent-deck run` (NOT-404).
3
+ *
4
+ * Moved verbatim out of run.ts (NOT-400): same SDK `query()` params, same
5
+ * message mapping, same missing-SDK remedy. No behavior change.
6
+ */
7
+ import { type ClientAdapter } from './run-adapter';
8
+ /** Minimal structural view of the SDK `query()` surface (the SDK loads lazily). */
9
+ export type RunQueryMessage = {
10
+ type?: string;
11
+ subtype?: string;
12
+ session_id?: string;
13
+ result?: unknown;
14
+ message?: {
15
+ content?: Array<{
16
+ type?: string;
17
+ text?: string;
18
+ name?: string;
19
+ }>;
20
+ };
21
+ };
22
+ export type RunQueryOptions = {
23
+ cwd: string;
24
+ resume?: string;
25
+ settingSources: readonly string[];
26
+ permissionMode: string;
27
+ allowedTools: readonly string[];
28
+ };
29
+ export type RunQueryFn = (params: {
30
+ prompt: string;
31
+ options: RunQueryOptions;
32
+ }) => AsyncIterable<RunQueryMessage>;
33
+ export declare function loadClaudeSdkQuery(): RunQueryFn;
34
+ export type ClaudeAdapterDeps = {
35
+ /** Injected in tests; production lazily requires the Claude Agent SDK. */
36
+ query?: RunQueryFn;
37
+ /** Override the SDK loader (tests use this to fail preflight deterministically). */
38
+ loadQuery?: () => RunQueryFn;
39
+ };
40
+ export declare function createClaudeAdapter(deps?: ClaudeAdapterDeps): ClientAdapter;
41
+ //# sourceMappingURL=run-claude.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-claude.d.ts","sourceRoot":"","sources":["../src/run-claude.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAKL,KAAK,aAAa,EAEnB,MAAM,eAAe,CAAC;AAGvB,mFAAmF;AACnF,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,OAAO,CAAC,EAAE;QACR,OAAO,CAAC,EAAE,KAAK,CAAC;YAAE,IAAI,CAAC,EAAE,MAAM,CAAC;YAAC,IAAI,CAAC,EAAE,MAAM,CAAC;YAAC,IAAI,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;KAClE,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,SAAS,MAAM,EAAE,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,CAAC,MAAM,EAAE;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,eAAe,CAAC;CAC1B,KAAK,aAAa,CAAC,eAAe,CAAC,CAAC;AAErC,wBAAgB,kBAAkB,IAAI,UAAU,CAgB/C;AAED,MAAM,MAAM,iBAAiB,GAAG;IAC9B,0EAA0E;IAC1E,KAAK,CAAC,EAAE,UAAU,CAAC;IACnB,oFAAoF;IACpF,SAAS,CAAC,EAAE,MAAM,UAAU,CAAC;CAC9B,CAAC;AAEF,wBAAgB,mBAAmB,CAAC,IAAI,GAAE,iBAAsB,GAAG,aAAa,CA+D/E"}
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loadClaudeSdkQuery = loadClaudeSdkQuery;
4
+ exports.createClaudeAdapter = createClaudeAdapter;
5
+ /**
6
+ * Claude adapter for `agent-deck run` (NOT-404).
7
+ *
8
+ * Moved verbatim out of run.ts (NOT-400): same SDK `query()` params, same
9
+ * message mapping, same missing-SDK remedy. No behavior change.
10
+ */
11
+ const run_adapter_1 = require("./run-adapter");
12
+ const paths_1 = require("./paths");
13
+ function loadClaudeSdkQuery() {
14
+ try {
15
+ const sdkPath = require.resolve('@anthropic-ai/claude-agent-sdk', {
16
+ paths: [(0, paths_1.getCliPackageRoot)()],
17
+ });
18
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
19
+ const sdk = require(sdkPath);
20
+ if (typeof sdk.query !== 'function') {
21
+ throw new Error('unexpected SDK shape');
22
+ }
23
+ return sdk.query;
24
+ }
25
+ catch {
26
+ throw new Error('The Claude Agent SDK is not installed. Reinstall the CLI (`agent-deck upgrade` or `npm install -g @agent-deck/cli@latest`) so @anthropic-ai/claude-agent-sdk is present, then retry.');
27
+ }
28
+ }
29
+ function createClaudeAdapter(deps = {}) {
30
+ let cachedQuery = deps.query;
31
+ const loadQuery = deps.loadQuery ?? loadClaudeSdkQuery;
32
+ const getQuery = () => {
33
+ if (!cachedQuery) {
34
+ cachedQuery = loadQuery();
35
+ }
36
+ return cachedQuery;
37
+ };
38
+ return {
39
+ id: 'claude',
40
+ async preflight() {
41
+ try {
42
+ getQuery();
43
+ return { ok: true };
44
+ }
45
+ catch (error) {
46
+ return { ok: false, remedy: error instanceof Error ? error.message : String(error) };
47
+ }
48
+ },
49
+ planStart() {
50
+ return { ok: true, trustOverride: false };
51
+ },
52
+ async *start(args) {
53
+ const query = getQuery();
54
+ const stream = query({
55
+ prompt: args.prompt,
56
+ options: {
57
+ cwd: args.cwd,
58
+ ...(args.resumeId ? { resume: args.resumeId } : {}),
59
+ settingSources: [...run_adapter_1.RUN_SETTING_SOURCES],
60
+ permissionMode: run_adapter_1.RUN_PERMISSION_MODE,
61
+ allowedTools: [...(0, run_adapter_1.allowedToolsForProfile)(args.tools)],
62
+ },
63
+ });
64
+ for await (const message of stream) {
65
+ const sessionId = typeof message.session_id === 'string' && message.session_id
66
+ ? message.session_id
67
+ : undefined;
68
+ const withSession = sessionId ? { sessionId } : {};
69
+ if (message.type === 'assistant') {
70
+ for (const block of message.message?.content ?? []) {
71
+ if (block.type === 'text' && typeof block.text === 'string') {
72
+ yield { kind: 'text', text: block.text, ...withSession };
73
+ }
74
+ else if (block.type === 'tool_use' && typeof block.name === 'string') {
75
+ yield { kind: 'tool', name: block.name, ...withSession };
76
+ }
77
+ }
78
+ }
79
+ else if (message.type === 'result') {
80
+ yield {
81
+ kind: 'result',
82
+ subtype: message.subtype ?? '',
83
+ result: message.result,
84
+ ...withSession,
85
+ };
86
+ }
87
+ }
88
+ },
89
+ };
90
+ }
91
+ //# sourceMappingURL=run-claude.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-claude.js","sourceRoot":"","sources":["../src/run-claude.ts"],"names":[],"mappings":";;AAwCA,gDAgBC;AASD,kDA+DC;AAhID;;;;;GAKG;AACH,+CAOuB;AACvB,mCAA4C;AA0B5C,SAAgB,kB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AC;6BAAM,IAAI,KAAK,CAAC,IAAI,KAAK,UAAU,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;4BACvE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,GAAG,WAAW,EAAE,CAAC;wBAC3D,CAAC;oBACH,CAAC;gBACH,CAAC;qBAAM,IAAI,OAAO,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;oBACrC,MAAM;wBACJ,IAAI,EAAE,QAAQ;wBACd,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,EAAE;wBAC9B,MAAM,EAAE,OAAO,CAAC,MAAM;wBACtB,GAAG,WAAW;qBACf,CAAC;gBACJ,CAAC;YACH,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,75 @@
1
+ import { type ClientAdapter, type NormalizedEvent, type RunToolsProfile } from './run-adapter';
2
+ /** Tool-profile mapping: readonly is `-s read-only`, edit is `-s workspace-write`. */
3
+ export declare const CODEX_SANDBOX_FOR_PROFILE: Record<RunToolsProfile, 'read-only' | 'workspace-write'>;
4
+ export declare const CODEX_JSONL_VERSION_NOTE = "codex-cli 0.157.1";
5
+ export declare function resolveCodexBin(): string;
6
+ export type CodexArgvArgs = {
7
+ prompt: string;
8
+ tools: RunToolsProfile;
9
+ resumeId?: string;
10
+ insideGitRepo: boolean;
11
+ };
12
+ /**
13
+ * Resume ids are codex thread ids (UUIDs); a leading `-` is never legitimate
14
+ * and would be parsed as a resume option (resume accepts
15
+ * `--dangerously-bypass-approvals-and-sandbox`, `-c`, ...), so it fails
16
+ * closed in planStart and throws here. Belt and suspenders with the `--`
17
+ * placement below: this builder never emits a dash-leading id at all.
18
+ */
19
+ export declare function assertSafeResumeId(resumeId: string): void;
20
+ /**
21
+ * Pure argv builder (everything after the `codex` binary). Start:
22
+ * `exec --json [--skip-git-repo-check] -s <mode> -- <prompt>`; resume:
23
+ * `exec resume --json [--skip-git-repo-check] -- <thread> <prompt>`
24
+ * (`codex exec resume [OPTIONS] [SESSION_ID] [PROMPT]` takes both positionals
25
+ * after `--`; verified `--help` after `--` is treated as a positional, not
26
+ * the help flag, on codex-cli 0.157.1).
27
+ * Resume takes no `-s`: the thread keeps its original sandbox.
28
+ * The `--` terminator keeps dash-leading prompts (markdown bullets, YAML
29
+ * frontmatter, or a literal `--dangerously-...` string) from being parsed
30
+ * as codex options.
31
+ */
32
+ export declare function buildCodexArgv(args: CodexArgvArgs): string[];
33
+ export declare function defaultIsGitRepo(cwd: string): boolean;
34
+ export type CodexProbeResult = {
35
+ code: number;
36
+ stdout: string;
37
+ stderr: string;
38
+ };
39
+ export type CodexProbe = (bin: string, argv: string[]) => CodexProbeResult;
40
+ export declare function defaultCodexProbe(bin: string, argv: string[]): CodexProbeResult;
41
+ export type CodexChild = {
42
+ /** Stdout split into lines (without line terminators). */
43
+ stdout: AsyncIterable<string>;
44
+ wait: () => Promise<{
45
+ code: number | null;
46
+ stderrTail: string;
47
+ }>;
48
+ };
49
+ export type CodexSpawn = (bin: string, argv: string[], opts: {
50
+ cwd: string;
51
+ }) => CodexChild;
52
+ export declare function defaultCodexSpawn(bin: string, argv: string[], opts: {
53
+ cwd: string;
54
+ }): CodexChild;
55
+ export type CodexLineContext = {
56
+ threadId: string | null;
57
+ };
58
+ /**
59
+ * Map one `codex exec --json` stdout line onto normalized events:
60
+ * `thread.started.thread_id` becomes the session id (no log line);
61
+ * `agent_message` items become `text`; command/tool items become `tool`;
62
+ * `turn.completed` becomes `result` (subtype `success`); provider `error`
63
+ * events become `notice` (non-fatal). Unknown kinds are ignored so a newer
64
+ * CLI cannot break the log. Never throws: unparseable lines become `notice`.
65
+ */
66
+ export declare function codexEventsFromLine(line: string, ctx: CodexLineContext): NormalizedEvent[];
67
+ export declare function codexTrustOverride(cwd: string, isGitRepo: (cwd: string) => boolean): boolean;
68
+ export type CodexAdapterDeps = {
69
+ bin?: string;
70
+ probe?: CodexProbe;
71
+ spawn?: CodexSpawn;
72
+ isGitRepo?: (cwd: string) => boolean;
73
+ };
74
+ export declare function createCodexAdapter(deps?: CodexAdapterDeps): ClientAdapter;
75
+ //# sourceMappingURL=run-codex.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-codex.d.ts","sourceRoot":"","sources":["../src/run-codex.ts"],"names":[],"mappings":"AAwBA,OAAO,EAEL,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,eAAe,EACrB,MAAM,eAAe,CAAC;AAEvB,sFAAsF;AACtF,eAAO,MAAM,yBAAyB,EAAE,MAAM,CAAC,eAAe,EAAE,WAAW,GAAG,iBAAiB,CAG9F,CAAC;AAEF,eAAO,MAAM,wBAAwB,sBAAsB,CAAC;AAE5D,wBAAgB,eAAe,IAAI,MAAM,CAExC;AAED,MAAM,MAAM,aAAa,GAAG;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,eAAe,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,OAAO,CAAC;CACxB,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAOzD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,aAAa,GAAG,MAAM,EAAE,CAoB5D;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAUrD;AAED,MAAM,MAAM,gBAAgB,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAChF,MAAM,MAAM,UAAU,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,gBAAgB,CAAC;AAE3E,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM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&& this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.CODEX_JSONL_VERSION_NOTE = exports.CODEX_SANDBOX_FOR_PROFILE = void 0;
7
+ exports.resolveCodexBin = resolveCodexBin;
8
+ exports.assertSafeResumeId = assertSafeResumeId;
9
+ exports.buildCodexArgv = buildCodexArgv;
10
+ exports.defaultIsGitRepo = defaultIsGitRepo;
11
+ exports.defaultCodexProbe = defaultCodexProbe;
12
+ exports.defaultCodexSpawn = defaultCodexSpawn;
13
+ exports.codexEventsFromLine = codexEventsFromLine;
14
+ exports.codexTrustOverride = codexTrustOverride;
15
+ exports.createCodexAdapter = createCodexAdapter;
16
+ /**
17
+ * Codex adapter for `agent-deck run` (NOT-404).
18
+ *
19
+ * Drives `codex exec --json` (start) and `codex exec resume` (resume) as a
20
+ * child process and maps the JSONL stream onto normalized events. Verified
21
+ * against codex-cli 0.157.1 (`codex exec --help`, `codex exec resume --help`,
22
+ * `codex login status`):
23
+ *
24
+ * - Start accepts `-s read-only|workspace-write`; resume accepts NO `-s`
25
+ * flag (neither does `fork`), so a resumed `edit` run fails closed in
26
+ * planStart instead of running with an unenforceable sandbox.
27
+ * - Signed-in preflight is `codex login status` (exit 0 + `Logged in ...`),
28
+ * which makes no model call.
29
+ * - `--skip-git-repo-check` exists on both start and resume and is passed
30
+ * only when --cwd is not inside a git work tree (recorded as
31
+ * `trustOverride: true` in meta.json).
32
+ *
33
+ * `--dangerously-bypass-approvals-and-sandbox` must never be used: there is
34
+ * no flag, env var, or option that selects it, and tests assert no generated
35
+ * argv ever contains it.
36
+ */
37
+ const node_child_process_1 = require("node:child_process");
38
+ const node_readline_1 = __importDefault(require("node:readline"));
39
+ /** Tool-profile mapping: readonly is `-s read-only`, edit is `-s workspace-write`. */
40
+ exports.CODEX_SANDBOX_FOR_PROFILE = {
41
+ readonly: 'read-only',
42
+ edit: 'workspace-write',
43
+ };
44
+ exports.CODEX_JSONL_VERSION_NOTE = 'codex-cli 0.157.1';
45
+ function resolveCodexBin() {
46
+ return process.env.CODEX_BIN?.trim() || 'codex';
47
+ }
48
+ /**
49
+ * Resume ids are codex thread ids (UUIDs); a leading `-` is never legitimate
50
+ * and would be parsed as a resume option (resume accepts
51
+ * `--dangerously-bypass-approvals-and-sandbox`, `-c`, ...), so it fails
52
+ * closed in planStart and throws here. Belt and suspenders with the `--`
53
+ * placement below: this builder never emits a dash-leading id at all.
54
+ */
55
+ function assertSafeResumeId(resumeId) {
56
+ if (resumeId.startsWith('-')) {
57
+ throw new Error(`Invalid --resume id ${JSON.stringify(resumeId)}: session ids never start with '-'. ` +
58
+ 'Pass the thread id printed as sessionId in a previous run log.');
59
+ }
60
+ }
61
+ /**
62
+ * Pure argv builder (everything after the `codex` binary). Start:
63
+ * `exec --json [--skip-git-repo-check] -s <mode> -- <prompt>`; resume:
64
+ * `exec resume --json [--skip-git-repo-check] -- <thread> <prompt>`
65
+ * (`codex exec resume [OPTIONS] [SESSION_ID] [PROMPT]` takes both positionals
66
+ * after `--`; verified `--help` after `--` is treated as a positional, not
67
+ * the help flag, on codex-cli 0.157.1).
68
+ * Resume takes no `-s`: the thread keeps its original sandbox.
69
+ * The `--` terminator keeps dash-leading prompts (markdown bullets, YAML
70
+ * frontmatter, or a literal `--dangerously-...` string) from being parsed
71
+ * as codex options.
72
+ */
73
+ function buildCodexArgv(args) {
74
+ const argv = ['exec'];
75
+ const resuming = args.resumeId !== undefined;
76
+ if (resuming) {
77
+ assertSafeResumeId(args.resumeId);
78
+ argv.push('resume');
79
+ }
80
+ argv.push('--json');
81
+ if (!args.insideGitRepo) {
82
+ argv.push('--skip-git-repo-check');
83
+ }
84
+ if (!resuming) {
85
+ argv.push('-s', exports.CODEX_SANDBOX_FOR_PROFILE[args.tools]);
86
+ }
87
+ argv.push('--');
88
+ if (resuming) {
89
+ argv.push(args.resumeId);
90
+ }
91
+ argv.push(args.prompt);
92
+ return argv;
93
+ }
94
+ function defaultIsGitRepo(cwd) {
95
+ try {
96
+ const probed = (0, node_child_process_1.spawnSync)('git', ['-C', cwd, 'rev-parse', '--is-inside-work-tree'], {
97
+ encoding: 'utf8',
98
+ timeout: 5000,
99
+ });
100
+ return probed.status === 0 && (probed.stdout ?? '').trim() === 'true';
101
+ }
102
+ catch {
103
+ return false;
104
+ }
105
+ }
106
+ function defaultCodexProbe(bin, argv) {
107
+ try {
108
+ const probed = (0, node_child_process_1.spawnSync)(bin, argv, { encoding: 'utf8', timeout: 15000 });
109
+ return { code: probed.status ?? 1, stdout: probed.stdout ?? '', stderr: probed.stderr ?? '' };
110
+ }
111
+ catch {
112
+ return { code: 127, stdout: '', stderr: '' };
113
+ }
114
+ }
115
+ function defaultCodexSpawn(bin, argv, opts) {
116
+ const child = (0, node_child_process_1.spawn)(bin, argv, { cwd: opts.cwd, stdio: ['ignore', 'pipe', 'pipe'] });
117
+ let spawnError = null;
118
+ child.on('error', (error) => {
119
+ spawnError = error;
120
+ child.stdout?.destroy();
121
+ });
122
+ const stderrChunks = [];
123
+ child.stderr?.on('data', (chunk) => {
124
+ stderrChunks.push(Buffer.from(chunk));
125
+ });
126
+ async function* lines() {
127
+ const rl = node_readline_1.default.createInterface({ input: child.stdout });
128
+ try {
129
+ for await (const line of rl) {
130
+ yield line;
131
+ }
132
+ }
133
+ catch {
134
+ // The stdout stream is destroyed when the spawn itself fails; the
135
+ // spawn error below is the actionable failure.
136
+ }
137
+ if (spawnError) {
138
+ throw spawnError;
139
+ }
140
+ }
141
+ const wait = () => new Promise((resolve) => {
142
+ let settled = false;
143
+ const done = (code) => {
144
+ if (settled) {
145
+ return;
146
+ }
147
+ settled = true;
148
+ resolve({
149
+ code,
150
+ stderrTail: Buffer.concat(stderrChunks).toString('utf8').slice(-2000),
151
+ });
152
+ };
153
+ child.on('close', done);
154
+ child.on('error', () => done(127));
155
+ });
156
+ return { stdout: lines(), wait };
157
+ }
158
+ function withSession(event, ctx) {
159
+ return ctx.threadId ? { ...event, sessionId: ctx.threadId } : event;
160
+ }
161
+ function asRecord(value) {
162
+ return typeof value === 'object' && value !== null ? value : null;
163
+ }
164
+ function nonEmptyString(value) {
165
+ return typeof value === 'string' && value ? value : null;
166
+ }
167
+ /**
168
+ * Map one `codex exec --json` stdout line onto normalized events:
169
+ * `thread.started.thread_id` becomes the session id (no log line);
170
+ * `agent_message` items become `text`; command/tool items become `tool`;
171
+ * `turn.completed` becomes `result` (subtype `success`); provider `error`
172
+ * events become `notice` (non-fatal). Unknown kinds are ignored so a newer
173
+ * CLI cannot break the log. Never throws: unparseable lines become `notice`.
174
+ */
175
+ function codexEventsFromLine(line, ctx) {
176
+ const trimmed = line.trim();
177
+ if (!trimmed) {
178
+ return [];
179
+ }
180
+ let event;
181
+ try {
182
+ event = JSON.parse(trimmed);
183
+ }
184
+ catch {
185
+ return [
186
+ withSession({ kind: 'notice', message: `unparseable codex output: ${trimmed.slice(0, 300)}` }, ctx),
187
+ ];
188
+ }
189
+ const record = asRecord(event);
190
+ if (!record) {
191
+ return [];
192
+ }
193
+ switch (record.type) {
194
+ case 'thread.started': {
195
+ const threadId = nonEmptyString(record.thread_id);
196
+ if (threadId) {
197
+ ctx.threadId = threadId;
198
+ }
199
+ return [];
200
+ }
201
+ case 'item.completed': {
202
+ const item = asRecord(record.item);
203
+ if (!item) {
204
+ return [];
205
+ }
206
+ if (item.type === 'agent_message') {
207
+ const text = nonEmptyString(item.text) ?? nonEmptyString(item.content);
208
+ return text ? [withSession({ kind: 'text', text }, ctx)] : [];
209
+ }
210
+ if (item.type === 'reasoning') {
211
+ return [];
212
+ }
213
+ const name = nonEmptyString(item.name) ??
214
+ (nonEmptyString(item.command) ? `command:${item.command}`.slice(0, 200) : null) ??
215
+ nonEmptyString(item.type) ??
216
+ 'item';
217
+ return [withSession({ kind: 'tool', name }, ctx)];
218
+ }
219
+ case 'turn.completed': {
220
+ const usage = record.usage === undefined ? null : { usage: record.usage };
221
+ return [withSession({ kind: 'result', subtype: 'success', result: usage }, ctx)];
222
+ }
223
+ case 'turn.failed': {
224
+ const detail = record.error ?? record.usage ?? null;
225
+ return [withSession({ kind: 'result', subtype: 'failed', result: detail }, ctx)];
226
+ }
227
+ case 'error': {
228
+ const message = nonEmptyString(record.message) ?? `codex error: ${trimmed.slice(0, 300)}`;
229
+ return [withSession({ kind: 'notice', message: message.slice(0, 500) }, ctx)];
230
+ }
231
+ default:
232
+ // turn.started and any future kinds carry nothing the log needs.
233
+ return [];
234
+ }
235
+ }
236
+ function codexTrustOverride(cwd, isGitRepo) {
237
+ try {
238
+ return !isGitRepo(cwd);
239
+ }
240
+ catch {
241
+ return true;
242
+ }
243
+ }
244
+ function createCodexAdapter(deps = {}) {
245
+ const bin = deps.bin ?? resolveCodexBin();
246
+ const probe = deps.probe ?? defaultCodexProbe;
247
+ const spawnFn = deps.spawn ?? defaultCodexSpawn;
248
+ const isGitRepo = deps.isGitRepo ?? defaultIsGitRepo;
249
+ return {
250
+ id: 'codex',
251
+ async preflight() {
252
+ const version = probe(bin, ['--version']);
253
+ if (version.code !== 0) {
254
+ return {
255
+ ok: false,
256
+ remedy: `codex CLI not found (tried "${bin}"): install codex-cli 0.157+ and ensure 'codex' is on PATH (or set CODEX_BIN=/path/to/codex), then retry.`,
257
+ };
258
+ }
259
+ const login = probe(bin, ['login', 'status']);
260
+ // `login status` reports on stderr ("Logged in using ChatGPT" on 0.157.1),
261
+ // so both streams count; the anchored match rejects "Not logged in".
262
+ const loginText = `${login.stdout}\n${login.stderr}`;
263
+ if (login.code !== 0 || !/^\s*logged in/im.test(loginText)) {
264
+ return {
265
+ ok: false,
266
+ remedy: 'codex is not signed in: run `codex login`, then retry.',
267
+ };
268
+ }
269
+ return { ok: true };
270
+ },
271
+ planStart(args) {
272
+ if (args.resumeId !== undefined && args.resumeId.startsWith('-')) {
273
+ return {
274
+ ok: false,
275
+ remedy: `Invalid --resume id ${JSON.stringify(args.resumeId)}: session ids never start with '-'. ` +
276
+ 'Pass the thread id printed as sessionId in a previous run log.',
277
+ };
278
+ }
279
+ if (args.resumeId !== undefined && args.tools === 'edit') {
280
+ return {
281
+ ok: false,
282
+ remedy: `Cannot resume codex thread ${args.resumeId} with --tools edit: 'codex exec resume' accepts no sandbox flag, ` +
283
+ 'so the edit sandbox cannot be enforced on resume. Start a new run without --resume, or resume with --tools readonly.',
284
+ };
285
+ }
286
+ return { ok: true, trustOverride: codexTrustOverride(args.cwd, isGitRepo) };
287
+ },
288
+ async *start(args) {
289
+ const insideGitRepo = !codexTrustOverride(args.cwd, isGitRepo);
290
+ const argv = buildCodexArgv({
291
+ prompt: args.prompt,
292
+ tools: args.tools,
293
+ ...(args.resumeId !== undefined ? { resumeId: args.resumeId } : {}),
294
+ insideGitRepo,
295
+ });
296
+ if (args.resumeId !== undefined) {
297
+ yield {
298
+ kind: 'notice',
299
+ message: `Resuming codex thread ${args.resumeId}: the thread keeps its original sandbox; ` +
300
+ `--tools ${args.tools} is recorded but cannot be re-applied on resume.`,
301
+ sessionId: args.resumeId,
302
+ };
303
+ }
304
+ const wrapSpawnError = (error) => new Error(`codex run failed: ${String(error instanceof Error ? error.message : error).slice(0, 300)}`);
305
+ let child;
306
+ try {
307
+ child = spawnFn(bin, argv, { cwd: args.cwd });
308
+ }
309
+ catch (error) {
310
+ throw wrapSpawnError(error);
311
+ }
312
+ const ctx = { threadId: args.resumeId ?? null };
313
+ try {
314
+ for await (const line of child.stdout) {
315
+ for (const event of codexEventsFromLine(line, ctx)) {
316
+ yield event;
317
+ }
318
+ }
319
+ }
320
+ catch (error) {
321
+ throw wrapSpawnError(error);
322
+ }
323
+ let settled;
324
+ try {
325
+ settled = await child.wait();
326
+ }
327
+ catch (error) {
328
+ throw wrapSpawnError(error);
329
+ }
330
+ const { code, stderrTail } = settled;
331
+ if (code !== 0) {
332
+ throw new Error(`codex exited with code ${code}${stderrTail ? `: ${stderrTail.slice(0, 300)}` : ''}`);
333
+ }
334
+ },
335
+ };
336
+ }
337
+ //# sourceMapp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,KAAK,CAAC;oBACd,CAAC;gBACH,CAAC;YACH,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,cAAc,CAAC,KAAK,CAAC,CAAC;YAC9B,CAAC;YACD,IAAI,OAAoD,CAAC;YACzD,IAAI,CAAC;gBACH,OAAO,GAAG,MAAM,KAAK,CAAC,IAAI,EAAE,CAAC;YAC/B,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,cAAc,CAAC,KAAK,CAAC,CAAC;YAC9B,CAAC;YACD,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;YACrC,IAAI,IAAI,KAAK,CAAC,EAAE,CAAC;gBACf,MAAM,IAAI,KAAK,CACb,0BAA0B,IAAI,GAAG,UAAU,CAAC,CAAC,CAAC,KAAK,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CACrF,CAAC;YACJ,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,79 @@
1
+ import { type ClientAdapter, type NormalizedEvent, type RunToolsProfile } from './run-adapter';
2
+ export declare const CURSOR_JSON_VERSION_NOTE = "cursor-agent 2026.10.01";
3
+ /** Single-shot result object; stream-json incremental shape is unverified. */
4
+ export declare const CURSOR_OUTPUT_FORMAT = "json";
5
+ export declare function resolveCursorBin(): string;
6
+ export type CursorArgvArgs = {
7
+ prompt: string;
8
+ tools: RunToolsProfile;
9
+ resumeId?: string;
10
+ };
11
+ /**
12
+ * Resume ids are cursor chat ids (32-hex); a leading `-` is never legitimate
13
+ * and would be parsed as a cursor-agent option, so it fails closed in
14
+ * planStart and throws here. Belt and suspenders with the `--` placement
15
+ * below: this builder never emits a dash-leading id at all.
16
+ */
17
+ export declare function assertSafeCursorResumeId(resumeId: string): void;
18
+ /**
19
+ * Pure argv builder (everything after the `cursor-agent` binary):
20
+ * `-p --trust --output-format json [--force] [--resume <id>] -- <prompt>`.
21
+ * `--force` only for the edit profile; `--yolo` and `--approve-mcps` are
22
+ * never emitted. The `--` terminator keeps dash-leading prompts from being
23
+ * parsed as cursor-agent options.
24
+ */
25
+ export declare function buildCursorArgv(args: CursorArgvArgs): string[];
26
+ export type CursorProbeResult = {
27
+ code: number;
28
+ stdout: string;
29
+ stderr: string;
30
+ };
31
+ export type CursorProbe = (bin: string, argv: string[]) => CursorProbeResult;
32
+ export declare function defaultCursorProbe(bin: string, argv: string[]): CursorProbeResult;
33
+ export type CursorChild = {
34
+ /** Stdout split into lines (without line terminators). */
35
+ stdout: AsyncIterable<string>;
36
+ wait: () => Promise<{
37
+ code: number | null;
38
+ stderrTail: string;
39
+ }>;
40
+ };
41
+ export type CursorSpawn = (bin: string, argv: string[], opts: {
42
+ cwd: string;
43
+ }) => CursorChild;
44
+ export declare function defaultCursorSpawn(bin: string, argv: string[], opts: {
45
+ cwd: string;
46
+ }): CursorChild;
47
+ /**
48
+ * `cursor-agent status --format json` exits 0 even when signed out
49
+ * (`{"status":"unauthenticated","isAuthenticated":false,...}`), so the
50
+ * output decides. The `isAuthenticated` boolean wins; the `status` string
51
+ * and a text fallback cover older shapes. Unknown output fails closed.
52
+ */
53
+ export declare function isCursorStatusAuthenticated(output: string): boolean;
54
+ /**
55
+ * Map the single-shot `--output-format json` stdout onto normalized events:
56
+ * the result object's `session_id` becomes `sessionId`; the answer text
57
+ * becomes one `text` event; tool arrays become `tool` events; warning arrays
58
+ * become `notice` events; the full object becomes the `result` payload
59
+ * (subtype `success`, or `failed` when the object carries `error`,
60
+ * `is_error: true`, or a non-`success` subtype).
61
+ *
62
+ * Throws (so the shared run code marks the run `error`) on "Workspace Trust
63
+ * Required", on empty output at exit 0, on non-JSON output, on a result
64
+ * object with no answer text, tool call, or error content (a bare session
65
+ * id, including the resume-id fallback, is not content), and — on start
66
+ * only, not resume — on a success whose output lacks a `◆ ... ·` deck
67
+ * receipt line. Never returns an empty event list: success always ends with
68
+ * a `result` event.
69
+ */
70
+ export declare function cursorEventsFromOutput(stdout: string, opts?: {
71
+ resumeId?: string;
72
+ }): NormalizedEvent[];
73
+ export type CursorAdapterDeps = {
74
+ bin?: string;
75
+ probe?: CursorProbe;
76
+ spawn?: CursorSpawn;
77
+ };
78
+ export declare function createCursorAdapter(deps?: CursorAdapterDeps): ClientAdapter;
79
+ //# sourceMappingURL=run-cursor.d.ts.map