@dadado/agent-kit-cli 6.23.0 → 6.26.0

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 (86) hide show
  1. package/README.md +1 -0
  2. package/dashboard/dashboard-data.mjs +126 -5
  3. package/dashboard/dashboard.html +48 -7
  4. package/dashboard/lib/guards.mjs +1 -0
  5. package/dashboard/lib/live-refresh.mjs +1 -0
  6. package/dist/{add-RKZQX6ZK.js → add-G7KEZLWP.js} +17 -8
  7. package/dist/{chunk-7HDQEK6T.js → chunk-2G4K4ZI5.js} +7 -3
  8. package/dist/{chunk-5PSV76CQ.js → chunk-2GXN7HVG.js} +26 -7
  9. package/dist/chunk-2QYWMSI5.js +193 -0
  10. package/dist/{chunk-B3VR5YBQ.js → chunk-2TW7ENWC.js} +12 -11
  11. package/dist/{chunk-IESSMKOV.js → chunk-5A72LTR3.js} +7 -7
  12. package/dist/{chunk-R4DUO5DA.js → chunk-AXQMVQ6O.js} +61 -237
  13. package/dist/{chunk-6WUKLS4D.js → chunk-BIFTTL2O.js} +1 -1
  14. package/dist/{chunk-AWQ6KRFV.js → chunk-BVZDPVUL.js} +1 -1
  15. package/dist/{chunk-QNISTPPZ.js → chunk-ENRXS5O6.js} +19 -12
  16. package/dist/chunk-FB6G6OD6.js +519 -0
  17. package/dist/{chunk-MFKHIWEL.js → chunk-FOVHFMSH.js} +1 -1
  18. package/dist/{chunk-6BEFGKCU.js → chunk-FUSNEYGU.js} +29 -3
  19. package/dist/chunk-H7KAXI5R.js +357 -0
  20. package/dist/chunk-HGB4DHXV.js +138 -0
  21. package/dist/{chunk-W3ZJVBNY.js → chunk-HXV6VQD4.js} +2374 -983
  22. package/dist/{chunk-BGL5DRK2.js → chunk-I3FGWNU5.js} +4 -4
  23. package/dist/chunk-IHVJTGYR.js +144 -0
  24. package/dist/{chunk-5LNHRL5E.js → chunk-IUY24WPE.js} +93 -263
  25. package/dist/chunk-JG5MKMOM.js +248 -0
  26. package/dist/{chunk-SGTTC2JP.js → chunk-JWIJHO67.js} +17 -2
  27. package/dist/chunk-KMK4T4ZM.js +34 -0
  28. package/dist/{chunk-ZMYV6PRE.js → chunk-LEVNLHH3.js} +2 -1
  29. package/dist/{chunk-2IP4OO6R.js → chunk-MGVV6YC4.js} +1 -1
  30. package/dist/{chunk-7TYA3GMI.js → chunk-MWRYQLEG.js} +7 -4
  31. package/dist/chunk-NHJ4IAVN.js +435 -0
  32. package/dist/{chunk-C4Q77GGJ.js → chunk-O7VMHCNN.js} +6 -0
  33. package/dist/{chunk-5EBT3V7G.js → chunk-OVRGTHZD.js} +1 -1
  34. package/dist/{chunk-F7YAAKYP.js → chunk-PCIYXGB3.js} +7 -5
  35. package/dist/{chunk-UJCATSYO.js → chunk-PLLXFSN2.js} +46 -17
  36. package/dist/{chunk-OYFCBYMP.js → chunk-RJP47EGS.js} +18 -1
  37. package/dist/{chunk-KDJ4ML7I.js → chunk-RRJVC35Y.js} +4 -4
  38. package/dist/{chunk-DRZFWIBN.js → chunk-SWJJW624.js} +1 -1
  39. package/dist/{chunk-MJJBIOSY.js → chunk-SYRJ5TTK.js} +34 -12
  40. package/dist/{chunk-L5V3W3DY.js → chunk-TTUFIE26.js} +60 -14
  41. package/dist/{chunk-JFS4GKP7.js → chunk-XXPI4H4D.js} +2 -2
  42. package/dist/{chunk-CVZNSRXV.js → chunk-Y5526WCN.js} +84 -19
  43. package/dist/{chunk-CQHD6UKB.js → chunk-Y575INEC.js} +2 -1
  44. package/dist/{chunk-V2H57TFD.js → chunk-ZNZHDPS3.js} +80 -170
  45. package/dist/{commands-SAQEEE6V.js → commands-K4HSDML5.js} +8 -6
  46. package/dist/{conflicts-5JOP4GX2.js → conflicts-4SUWIPWP.js} +9 -10
  47. package/dist/{contribute-BQKRT5GN.js → contribute-HE4WCBRY.js} +7 -5
  48. package/dist/{countdown-25E5C7AR.js → countdown-TYQHVAIX.js} +305 -32
  49. package/dist/{dashboard-P65XHYCU.js → dashboard-6V6PCNYF.js} +1 -1
  50. package/dist/{dashboard-broadcast-GYK34QYL.js → dashboard-broadcast-PMVQ7PXU.js} +1 -1
  51. package/dist/{diff-6JSXBVSX.js → diff-3XUZM7ZT.js} +15 -6
  52. package/dist/{doctor-I3MTHS7F.js → doctor-KGUWU5SN.js} +106 -19
  53. package/dist/{engine-info-BBI5QO5Y.js → engine-info-VM4VPGQM.js} +2 -2
  54. package/dist/{ground-control-IDCXN5FK.js → ground-control-ZIDHEOPW.js} +7 -4
  55. package/dist/{guard-RJZEEKSL.js → guard-ZO4Z3LLB.js} +47 -9
  56. package/dist/{handoff-5AGE2D3T.js → handoff-LLT4CI6H.js} +4 -3
  57. package/dist/{hook-WNA42CXE.js → hook-UPZ3CPYS.js} +22 -20
  58. package/dist/index.js +51 -33
  59. package/dist/{init-FZ2UFPO7.js → init-ZHLVXEVT.js} +25 -18
  60. package/dist/install-XWOG64W3.js +42 -0
  61. package/dist/installs-2ROXPO6M.js +223 -0
  62. package/dist/{mission-control-CRMCRZUU.js → mission-control-IGOI3WHS.js} +2 -2
  63. package/dist/models-5BDXREWM.js +45 -0
  64. package/dist/paths-JTPV6SXH.js +107 -0
  65. package/dist/pi-DCMDOY65.js +248 -0
  66. package/dist/{plan-index-BNLUU6T5.js → plan-index-5QZJK4AG.js} +2 -3
  67. package/dist/{queue-JW4VR33H.js → queue-Z5VNNHM6.js} +10 -12
  68. package/dist/{run-X2WOONTB.js → run-QURAXAR2.js} +27 -33
  69. package/dist/{run-plan-4MOLLIES.js → run-plan-4MMHVCTS.js} +35 -23
  70. package/dist/{scan-K3T5RQLC.js → scan-7D3RMO34.js} +2 -1
  71. package/dist/{session-start-MV7A4263.js → session-start-NC2HE5X5.js} +20 -14
  72. package/dist/{sessions-UPFDWDMB.js → sessions-WWWLYPW6.js} +4 -4
  73. package/dist/{setup-global-VNADNTQ2.js → setup-global-WDMARD4Z.js} +12 -10
  74. package/dist/{status-SXA3OK5E.js → status-2WNJL7PP.js} +17 -13
  75. package/dist/update-YSVOYYK5.js +32 -0
  76. package/dist/update-all-5XLTCHPX.js +697 -0
  77. package/package.json +14 -4
  78. package/pi/agent-kit.ts +224 -0
  79. package/dist/chunk-4MR4QXMF.js +0 -52
  80. package/dist/chunk-7ABY6DYH.js +0 -89
  81. package/dist/chunk-C4LCOOL4.js +0 -71
  82. package/dist/chunk-DZCLMIAS.js +0 -391
  83. package/dist/chunk-HAFRAXGV.js +0 -17
  84. package/dist/chunk-MUTTNRX4.js +0 -53
  85. package/dist/install-CTLT3TSI.js +0 -38
  86. package/dist/update-RMAWXMCV.js +0 -304
package/package.json CHANGED
@@ -1,7 +1,10 @@
1
1
  {
2
2
  "name": "@dadado/agent-kit-cli",
3
- "version": "6.23.0",
3
+ "version": "6.26.0",
4
4
  "description": "Agent Kit CLI: HITL framework install and tooling for AI-assisted IDEs (rules, skills, plan/handoff, context).",
5
+ "keywords": [
6
+ "pi-package"
7
+ ],
5
8
  "license": "Apache-2.0",
6
9
  "homepage": "https://agent.missionkit.io/",
7
10
  "repository": {
@@ -21,9 +24,15 @@
21
24
  "files": [
22
25
  "dist",
23
26
  "dashboard",
27
+ "pi/agent-kit.ts",
24
28
  "LICENSE",
25
29
  "NOTICE"
26
30
  ],
31
+ "pi": {
32
+ "extensions": [
33
+ "./pi/agent-kit.ts"
34
+ ]
35
+ },
27
36
  "scripts": {
28
37
  "sync-dashboard": "node ../../scripts/sync-cli-dashboard.mjs",
29
38
  "prepack": "node ../../scripts/sync-cli-dashboard.mjs",
@@ -31,11 +40,11 @@
31
40
  "build": "node ../../scripts/sync-cli-dashboard.mjs && tsup src/index.ts --format esm --dts --clean",
32
41
  "dev": "tsx src/index.ts",
33
42
  "start": "tsx src/index.ts",
34
- "lint": "biome check src",
43
+ "lint": "biome check src pi",
35
44
  "overlay:hashes": "tsx src/lifecycle/refresh-known-hashes.ts",
36
45
  "overlay:hashes:check": "tsx src/lifecycle/refresh-known-hashes.ts --check",
37
46
  "test": "vitest run",
38
- "typecheck": "tsc --noEmit"
47
+ "typecheck": "tsc --noEmit && tsc -p tsconfig.pi.json"
39
48
  },
40
49
  "dependencies": {
41
50
  "@clack/prompts": "^1.8.1",
@@ -47,6 +56,7 @@
47
56
  "tsup": "^9.0.0",
48
57
  "tsx": "^4.23.15",
49
58
  "vite": "^8.3.5",
50
- "vitest": "^5.0.5"
59
+ "vitest": "^5.0.5",
60
+ "yaml": "^2.9.0"
51
61
  }
52
62
  }
@@ -0,0 +1,224 @@
1
+ /**
2
+ * Agent Kit bridge for pi (ADR 2026-11-28_pi-harness-interactive-surface-extension).
3
+ *
4
+ * - Asks the `agent-kit` CLI on PATH where the kit is (`agent-kit paths --json`); this file knows
5
+ * no kit layout, so a layout change only changes the CLI answer.
6
+ * - Feeds pi the kit's command directory as prompt templates and its skill directories as skills,
7
+ * read in place: nothing is generated or copied into the repository.
8
+ * - Adds the session-start context from `agent-kit hook session-start --format pi` to the system
9
+ * prompt as a named `agent-kit` section.
10
+ * - Runs only the `agent-kit` binary on PATH, never repository code (no node_modules/.bin, no dist).
11
+ * - Fail-open: any CLI problem leaves pi running with one warning and no kit context.
12
+ *
13
+ * Runtime imports are node builtins only, so the file loads from the published package as is.
14
+ */
15
+ import { execFile } from "node:child_process";
16
+ import { homedir } from "node:os";
17
+ import { resolve, sep } from "node:path";
18
+
19
+ const CLI = "agent-kit";
20
+ const PATHS_SCHEMA_VERSION = 1;
21
+ const PATHS_TIMEOUT_MS = 10_000;
22
+ const CONTEXT_TIMEOUT_MS = 20_000;
23
+ const SECTION = "agent-kit";
24
+ const TOO_OLD =
25
+ "agent-kit: the CLI on PATH is too old for the pi bridge (no `paths`); update agent-kit.";
26
+ /** Survives pi's /reload, which re-creates this module's closure in the same process. */
27
+ const TARGET_KEY = Symbol.for("agent-kit.pi-bridge.target");
28
+
29
+ interface KitPaths {
30
+ schemaVersion: number;
31
+ kitVersion: string;
32
+ root: string;
33
+ commands: string | null;
34
+ skills: string[];
35
+ }
36
+ interface Kit {
37
+ paths: KitPaths;
38
+ context: string;
39
+ }
40
+ type Resolution = { kit?: Kit; warning?: string };
41
+ type NotifyType = "info" | "warning" | "error";
42
+ interface Ctx {
43
+ cwd: string;
44
+ ui: { notify(message: string, type?: NotifyType): void };
45
+ }
46
+ interface BeforeAgentStartEvent {
47
+ messageType?: "user" | "custom";
48
+ systemPrompt: string;
49
+ systemPromptOptions?: { sections?: Record<string, string> };
50
+ }
51
+ interface InputEvent {
52
+ text: string;
53
+ }
54
+ type Handler<E> = (event: E, ctx: Ctx) => unknown;
55
+ interface PiApi {
56
+ on(event: "session_start", handler: Handler<unknown>): void;
57
+ on(event: "resources_discover", handler: Handler<unknown>): void;
58
+ on(event: "before_agent_start", handler: Handler<BeforeAgentStartEvent>): void;
59
+ on(event: "input", handler: Handler<InputEvent>): void;
60
+ getCommands(): { name: string; source: string; sourceInfo: { path: string } }[];
61
+ registerCommand(
62
+ name: string,
63
+ options: { description: string; handler: (args: string, ctx: Ctx) => Promise<void> },
64
+ ): void;
65
+ }
66
+ interface CliRun {
67
+ code: number | null;
68
+ stdout: string;
69
+ stderr: string;
70
+ missing: boolean;
71
+ timedOut: boolean;
72
+ }
73
+
74
+ function runCli(args: string[], timeout: number, cwd?: string): Promise<CliRun> {
75
+ return new Promise((done) => {
76
+ const child = execFile(
77
+ CLI,
78
+ args,
79
+ { cwd, timeout, encoding: "utf8", maxBuffer: 4 * 1024 * 1024 },
80
+ (error, stdout, stderr) => {
81
+ const err = error as (NodeJS.ErrnoException & { killed?: boolean }) | null;
82
+ done({
83
+ code: err ? (typeof err.code === "number" ? err.code : null) : 0,
84
+ stdout: String(stdout ?? ""),
85
+ stderr: String(stderr ?? ""),
86
+ missing: err?.code === "ENOENT",
87
+ timedOut: err?.killed === true,
88
+ });
89
+ },
90
+ );
91
+ child.stdin?.end(); // the hook reads stdin until EOF
92
+ });
93
+ }
94
+
95
+ function why(step: string, run: CliRun, timeout: number): string {
96
+ if (run.missing)
97
+ return `agent-kit: no \`agent-kit\` on PATH; install the Agent Kit CLI to use the pi bridge.`;
98
+ if (run.timedOut) return `agent-kit: \`${step}\` timed out after ${timeout / 1000}s.`;
99
+ if (run.code === 0) return `agent-kit: \`${step}\` printed nothing.`;
100
+ const detail = run.stderr.trim().split("\n")[0] ?? "";
101
+ return `agent-kit: \`${step}\` failed (exit ${run.code ?? "?"})${detail ? `: ${detail}` : ""}.`;
102
+ }
103
+
104
+ function parsePaths(stdout: string): KitPaths | string {
105
+ let value: Partial<KitPaths>;
106
+ try {
107
+ value = JSON.parse(stdout) as Partial<KitPaths>;
108
+ } catch {
109
+ return TOO_OLD;
110
+ }
111
+ if (value.schemaVersion !== PATHS_SCHEMA_VERSION) {
112
+ return `agent-kit: \`agent-kit paths\` answered schemaVersion ${String(value.schemaVersion)}, this bridge reads ${PATHS_SCHEMA_VERSION}; run \`agent-kit pi install\` to update it.`;
113
+ }
114
+ if (typeof value.root !== "string" || !Array.isArray(value.skills)) return TOO_OLD;
115
+ return value as KitPaths;
116
+ }
117
+
118
+ async function resolveKit(dir: string): Promise<Resolution> {
119
+ const run = await runCli(["paths", "--json", "--cwd", dir], PATHS_TIMEOUT_MS);
120
+ // Contract: outside a kit, exit 1 and nothing on stdout. Older CLIs print help for `paths`.
121
+ if (run.code === 1 && run.stdout.trim() === "") return {};
122
+ if (/unknown command/i.test(run.stderr)) return { warning: TOO_OLD };
123
+ if (run.code !== 0) return { warning: why("agent-kit paths", run, PATHS_TIMEOUT_MS) };
124
+ const paths = parsePaths(run.stdout);
125
+ if (typeof paths === "string") return { warning: paths };
126
+
127
+ const args = ["hook", "session-start", "--format", "pi", "--cwd", paths.root];
128
+ const hook = await runCli(args, CONTEXT_TIMEOUT_MS, paths.root);
129
+ const header = `Agent Kit root: ${paths.root} (agent-kit ${paths.kitVersion}, pi bridge). Run kit shell commands from this root.`;
130
+ if (hook.code !== 0 || hook.stdout.trim() === "") {
131
+ const warning = `${why("agent-kit hook session-start", hook, CONTEXT_TIMEOUT_MS)} Commands and skills load; no kit context.`;
132
+ return { kit: { paths, context: "" }, warning };
133
+ }
134
+ return { kit: { paths, context: `${header}\n\n${hook.stdout.trim()}` } };
135
+ }
136
+
137
+ function expandHome(input: string): string {
138
+ return input === "~" || input.startsWith("~/") ? homedir() + input.slice(1) : input;
139
+ }
140
+
141
+ type Target = { cwd: string; dir: string };
142
+ const store = globalThis as typeof globalThis & { [TARGET_KEY]?: Target };
143
+
144
+ export default function agentKitBridge(pi: PiApi): void {
145
+ let kit: Kit | undefined;
146
+ /** Arguments typed after a kit command, held from `input` until `before_agent_start`. */
147
+ let pendingArgs: string | undefined;
148
+
149
+ const load = async (dir: string, ctx: Ctx): Promise<Resolution> => {
150
+ const result = await resolveKit(dir);
151
+ kit = result.kit;
152
+ if (result.warning) ctx.ui.notify(result.warning, "warning");
153
+ return result;
154
+ };
155
+
156
+ pi.on("session_start", async (_event, ctx) => {
157
+ const target = store[TARGET_KEY];
158
+ await load(target && target.cwd === ctx.cwd ? target.dir : ctx.cwd, ctx);
159
+ });
160
+
161
+ pi.on("resources_discover", () => {
162
+ if (!kit) return {};
163
+ return {
164
+ promptPaths: kit.paths.commands ? [kit.paths.commands] : [],
165
+ skillPaths: kit.paths.skills,
166
+ };
167
+ });
168
+
169
+ // Kit commands use no `$@`, so pi drops what follows `/<command>`. Forward it as an
170
+ // `ARGUMENTS:` message (the Claude Code adapter's convention), for kit commands only.
171
+ pi.on("input", (event) => {
172
+ pendingArgs = undefined;
173
+ const match = /^\/(\S+)\s+(\S[\s\S]*)$/.exec(event.text.trim());
174
+ const commandsDir = kit?.paths.commands;
175
+ if (!match || !commandsDir) return { action: "continue" };
176
+ const fromKit = pi
177
+ .getCommands()
178
+ .some(
179
+ (c) =>
180
+ c.name === match[1] &&
181
+ c.source === "prompt" &&
182
+ c.sourceInfo.path.startsWith(commandsDir + sep),
183
+ );
184
+ if (fromKit) pendingArgs = match[2];
185
+ return { action: "continue" };
186
+ });
187
+
188
+ pi.on("before_agent_start", (event) => {
189
+ const args = event.messageType === "custom" ? undefined : pendingArgs;
190
+ pendingArgs = undefined;
191
+ const message = args
192
+ ? { customType: "agent-kit-arguments", content: `ARGUMENTS: ${args}`, display: true }
193
+ : undefined;
194
+ const context = kit?.context ?? "";
195
+ const sections = event.systemPromptOptions?.sections;
196
+ if (sections) {
197
+ if (context) sections[SECTION] = context;
198
+ else delete sections[SECTION];
199
+ return message ? { message } : undefined;
200
+ }
201
+ if (!context) return message ? { message } : undefined;
202
+ return { message, systemPrompt: `${event.systemPrompt}\n\n${context}` };
203
+ });
204
+
205
+ pi.registerCommand("agent-kit", {
206
+ description:
207
+ "Point the Agent Kit bridge at a repo (default: current dir) and reload its context; then /reload for its commands",
208
+ handler: async (args, ctx) => {
209
+ const raw = args.trim();
210
+ const dir = raw ? resolve(ctx.cwd, expandHome(raw)) : ctx.cwd;
211
+ const result = await load(dir, ctx);
212
+ if (!result.kit) {
213
+ if (!result.warning)
214
+ ctx.ui.notify(`agent-kit: no Agent Kit at or above ${dir}.`, "warning");
215
+ return;
216
+ }
217
+ store[TARGET_KEY] = { cwd: ctx.cwd, dir };
218
+ ctx.ui.notify(
219
+ `agent-kit: context loaded from ${result.kit.paths.root}. Run /reload to load its slash commands and skills.`,
220
+ "info",
221
+ );
222
+ },
223
+ });
224
+ }
@@ -1,52 +0,0 @@
1
- import {
2
- L0_ARTIFACTS
3
- } from "./chunk-CGXLR77R.js";
4
- import {
5
- allSkills,
6
- loadPackManifest,
7
- loadRegistry,
8
- packMemberFileTargets,
9
- skillFileTargets
10
- } from "./chunk-V2H57TFD.js";
11
-
12
- // src/lifecycle/targets.ts
13
- import path from "path";
14
- var toPosix = (rel) => rel.split(path.sep).join("/");
15
- async function managedPairs(registryRoot, manifest, index) {
16
- const pairs = [];
17
- const missingSkills = [];
18
- const push = (sourceRel, targetRel, origin) => {
19
- pairs.push({ sourceRel: toPosix(sourceRel), targetRel: toPosix(targetRel), origin });
20
- };
21
- for (const a of L0_ARTIFACTS) push(a.source, a.target, "l0");
22
- for (const packId of manifest.packs ?? []) {
23
- const pack = await loadPackManifest(registryRoot, packId);
24
- for (const member of pack.members) {
25
- for (const { sourceRel, targetRel } of await packMemberFileTargets(registryRoot, member)) {
26
- push(sourceRel, targetRel, "pack");
27
- }
28
- }
29
- }
30
- if ((manifest.skills ?? []).length > 0) {
31
- const pool = allSkills(index ?? await loadRegistry(registryRoot));
32
- for (const id of manifest.skills ?? []) {
33
- const skill = pool.find((s) => s.id === id);
34
- if (!skill) {
35
- missingSkills.push(id);
36
- continue;
37
- }
38
- for (const { sourceRel, targetRel } of await skillFileTargets(
39
- registryRoot,
40
- skill.path,
41
- skill.id
42
- )) {
43
- push(sourceRel, targetRel, "skill");
44
- }
45
- }
46
- }
47
- return { pairs, missingSkills };
48
- }
49
-
50
- export {
51
- managedPairs
52
- };
@@ -1,89 +0,0 @@
1
- import {
2
- extractHandoffNamedPlans,
3
- namedPlanCandidatePaths,
4
- parsePlanFrontmatter
5
- } from "./chunk-L5V3W3DY.js";
6
- import {
7
- HANDOFF_REL
8
- } from "./chunk-C4Q77GGJ.js";
9
- import {
10
- fileExists
11
- } from "./chunk-5B4DVO6C.js";
12
-
13
- // src/plan-loop/plan-state.ts
14
- import { readdir, readFile } from "fs/promises";
15
- import path from "path";
16
- function countPendingTodos(raw) {
17
- return parsePlanFrontmatter(raw).todos.filter(
18
- (t) => (t.status === "pending" || t.status === "in_progress") && t.id !== "dogfood-poc"
19
- ).length;
20
- }
21
- async function findActivePlanFile(plansDir) {
22
- if (!await fileExists(plansDir)) return null;
23
- const files = (await readdir(plansDir)).filter((f) => f.endsWith(".plan.md")).sort();
24
- return files[0] ? path.join(plansDir, files[0]) : null;
25
- }
26
- async function readPlan(planPath) {
27
- return readFile(planPath, "utf8");
28
- }
29
- var QUEUE_CURSOR_RE = /^- \*\*Queue cursor:\*\*\s*(.+)$/m;
30
- var QUEUE_STATUS_RE = /^- \*\*Queue status:\*\*\s*(.+)$/m;
31
- var QUEUE_DONE_STATUSES = /* @__PURE__ */ new Set(["exhausted", "completed", "done"]);
32
- function readRunQueueState(handoff) {
33
- const queue = extractHandoffNamedPlans(handoff).runQueue;
34
- let cursorIndex = null;
35
- let cursorPlan = null;
36
- const cursorRaw = QUEUE_CURSOR_RE.exec(handoff)?.[1]?.trim() ?? "";
37
- const indexMatch = /^(\d+)\b/.exec(cursorRaw);
38
- if (indexMatch?.[1]) cursorIndex = Number(indexMatch[1]);
39
- const currentMatch = /current:\s*`?([^`()]+?)`?\s*\)/i.exec(cursorRaw);
40
- if (currentMatch?.[1]) {
41
- const base = currentMatch[1].trim().split("/").pop() ?? "";
42
- if (/\.plan\.md$/i.test(base)) cursorPlan = base;
43
- }
44
- const status = QUEUE_STATUS_RE.exec(handoff)?.[1]?.trim().split(/\s+/)[0]?.replace(/[`*]/g, "");
45
- const queueStatus = status ? status : null;
46
- const finished = queueStatus !== null && QUEUE_DONE_STATUSES.has(queueStatus.toLowerCase());
47
- let cursor = null;
48
- if (cursorIndex !== null && cursorIndex >= 0 && cursorIndex < queue.length) {
49
- cursor = cursorIndex;
50
- } else if (cursorPlan && queue.includes(cursorPlan)) {
51
- cursor = queue.indexOf(cursorPlan);
52
- }
53
- const current = cursor !== null ? queue[cursor] ?? null : cursorPlan;
54
- return { queue, cursor, current, status: queueStatus, finished };
55
- }
56
- function defaultPlanStateIo() {
57
- return {
58
- readFile: async (file) => {
59
- try {
60
- return await readFile(file, "utf8");
61
- } catch {
62
- return null;
63
- }
64
- },
65
- findActivePlan: findActivePlanFile
66
- };
67
- }
68
- async function resolveActivePlanFromHandoff(root, handoff, io = defaultPlanStateIo()) {
69
- const queue = readRunQueueState(handoff);
70
- const base = (queue.queue.length > 0 && !queue.finished ? queue.current : null) ?? extractHandoffNamedPlans(handoff).active;
71
- if (!base) return io.findActivePlan(path.join(root, ".cursor", "plans"));
72
- for (const candidate of namedPlanCandidatePaths(root, base)) {
73
- if (await io.readFile(candidate) !== null) return candidate;
74
- }
75
- return null;
76
- }
77
- async function resolveActivePlanPath(root, io = defaultPlanStateIo()) {
78
- const handoff = await io.readFile(path.join(root, HANDOFF_REL)) ?? "";
79
- return resolveActivePlanFromHandoff(root, handoff, io);
80
- }
81
-
82
- export {
83
- countPendingTodos,
84
- findActivePlanFile,
85
- readPlan,
86
- readRunQueueState,
87
- resolveActivePlanFromHandoff,
88
- resolveActivePlanPath
89
- };
@@ -1,71 +0,0 @@
1
- import {
2
- whichBinary
3
- } from "./chunk-W3ZJVBNY.js";
4
-
5
- // src/plan-loop/detect.ts
6
- var DETECT_ORDER = ["cursor-agent", "claude"];
7
- var EXPLICIT_ONLY_BACKENDS = ["codex", "cursor-acp", "openrouter"];
8
- var INSTALL_HINTS = {
9
- "cursor-agent": "Install the Cursor Agent CLI and ensure `cursor-agent` is on PATH (https://cursor.com/docs/cli).",
10
- claude: "Install Claude Code and ensure `claude` is on PATH (https://code.claude.com/docs/en/quickstart).",
11
- "cursor-acp": "Install the Cursor Agent CLI and ensure `cursor-agent` is on PATH (https://cursor.com/docs/cli/acp); sign in with `cursor-agent login`.",
12
- codex: "Install the Codex CLI and ensure `codex` is on PATH (https://developers.openai.com/codex/cli).",
13
- openrouter: "Install Ori and ensure `ori` is on PATH, then sign in with `ori login` (OpenRouter credentials). The kit never falls back to a first-party `claude` here: that would bill Anthropic instead of OpenRouter."
14
- };
15
- var BACKEND_BIN = {
16
- "cursor-agent": "cursor-agent",
17
- claude: "claude",
18
- codex: "codex",
19
- "cursor-acp": "cursor-agent",
20
- openrouter: "ori"
21
- };
22
- function isBackendId(id) {
23
- return id === "cursor-agent" || id === "claude" || id === "codex" || id === "cursor-acp" || id === "openrouter";
24
- }
25
- function isRequestedBackend(id) {
26
- return id === "auto" || isBackendId(id);
27
- }
28
- function listDetectBackendIds() {
29
- return ["auto", ...DETECT_ORDER, ...EXPLICIT_ONLY_BACKENDS];
30
- }
31
- async function detectAgentBackend(requested, whichFn = whichBinary) {
32
- const id = requested.trim().toLowerCase();
33
- if (id === "glm" || id.startsWith("glm-") || id === "glm4") {
34
- return {
35
- ok: false,
36
- message: "No documented GLM CLI binary is registered. Refusing a stub that would claim to work. Use --backend auto, cursor-agent, or claude."
37
- };
38
- }
39
- if (!isRequestedBackend(id)) {
40
- return {
41
- ok: false,
42
- message: `Unknown backend '${requested}'. Supported: ${listDetectBackendIds().join(", ")}.`
43
- };
44
- }
45
- if (id === "auto") {
46
- for (const candidate of DETECT_ORDER) {
47
- const bin2 = await whichFn(candidate);
48
- if (bin2) return { ok: true, id: candidate, bin: bin2 };
49
- }
50
- return {
51
- ok: false,
52
- message: [
53
- "No agent CLI found on PATH (tried: cursor-agent, claude).",
54
- INSTALL_HINTS["cursor-agent"],
55
- INSTALL_HINTS.claude
56
- ].join(" ")
57
- };
58
- }
59
- const bin = await whichFn(BACKEND_BIN[id]);
60
- if (!bin) {
61
- return { ok: false, message: `${BACKEND_BIN[id]} not found on PATH. ${INSTALL_HINTS[id]}` };
62
- }
63
- return { ok: true, id, bin };
64
- }
65
-
66
- export {
67
- isBackendId,
68
- isRequestedBackend,
69
- listDetectBackendIds,
70
- detectAgentBackend
71
- };