@dadado/agent-kit-cli 6.7.2 → 6.9.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.
@@ -1,335 +0,0 @@
1
- import {
2
- runPlanLoop,
3
- shouldUseLiveTui,
4
- withLiveTui
5
- } from "./chunk-5WDFOFL4.js";
6
- import "./chunk-R6WH5P7R.js";
7
- import {
8
- REVIEW_PACK_SLASH,
9
- runReviewJob
10
- } from "./chunk-S7XAV6JK.js";
11
- import {
12
- detectAgentBackend,
13
- listDetectBackendIds
14
- } from "./chunk-BB22FGQ4.js";
15
- import "./chunk-BSYQJ5WF.js";
16
- import {
17
- LAND_ON_GATE_DESCRIPTION,
18
- classifyGateExit,
19
- landGateExit
20
- } from "./chunk-26KXYR5T.js";
21
- import "./chunk-3LLXDHIU.js";
22
- import {
23
- negatedFlag
24
- } from "./chunk-XDCCYBCJ.js";
25
- import "./chunk-L5V3W3DY.js";
26
- import "./chunk-MUTTNRX4.js";
27
- import {
28
- buildDispatchPrompt,
29
- classifySlash,
30
- ensureDispatchLogPath,
31
- normalizeSlashName,
32
- promoteBlockedMessage,
33
- readCommandFile,
34
- runHeadlessDispatch,
35
- unknownSlashMessage
36
- } from "./chunk-BZI5G3OZ.js";
37
- import {
38
- getBackend
39
- } from "./chunk-6UKI4CAN.js";
40
- import {
41
- HITL_UNANSWERED_EXIT_CODE,
42
- formatHitlSummary,
43
- hitlExitCode
44
- } from "./chunk-MTLQN57O.js";
45
- import "./chunk-WGLPZXNU.js";
46
- import "./chunk-6RRG3WOE.js";
47
- import "./chunk-QTON2GQX.js";
48
- import {
49
- logger
50
- } from "./chunk-ZB43YMHW.js";
51
- import "./chunk-C4Q77GGJ.js";
52
- import "./chunk-5B4DVO6C.js";
53
-
54
- // src/commands/run.ts
55
- import { homedir } from "os";
56
- import path from "path";
57
- import { defineCommand } from "citty";
58
- function displayPath(target, home = homedir()) {
59
- const resolvedHome = path.resolve(home);
60
- if (target === resolvedHome) return "~";
61
- const prefix = resolvedHome.endsWith(path.sep) ? resolvedHome : `${resolvedHome}${path.sep}`;
62
- return target.startsWith(prefix) ? `~${path.sep}${target.slice(prefix.length)}` : target;
63
- }
64
- async function executeRun(input) {
65
- const root = path.resolve(input.cwd);
66
- const slash = normalizeSlashName(input.slash);
67
- if (!slash) {
68
- return { exitCode: 1, error: "Provide a slash: agent-kit run <slash>" };
69
- }
70
- const kind = classifySlash(slash);
71
- if (kind === "promote-blocked") {
72
- return { exitCode: 1, error: promoteBlockedMessage(slash) };
73
- }
74
- if (kind === "unknown") {
75
- return { exitCode: 1, error: unknownSlashMessage(slash) };
76
- }
77
- if (input.maxPackBytes?.trim() && slash !== REVIEW_PACK_SLASH) {
78
- return { exitCode: 1, error: `--max-pack-bytes only applies to ${REVIEW_PACK_SLASH}` };
79
- }
80
- if (input.includeReviewed && slash !== REVIEW_PACK_SLASH) {
81
- return { exitCode: 1, error: `--include-reviewed only applies to ${REVIEW_PACK_SLASH}` };
82
- }
83
- const detected = await detectAgentBackend(input.backend, input.whichFn);
84
- if (!detected.ok) {
85
- return { exitCode: 1, error: detected.message };
86
- }
87
- if (kind === "run-plan") {
88
- let backend;
89
- try {
90
- backend = getBackend(detected.id);
91
- } catch (err) {
92
- return { exitCode: 1, error: String(err) };
93
- }
94
- if (input.dryRun) {
95
- const preview = [
96
- `--dry-run: alias agent-kit run-plan (backend ${detected.id} at ${displayPath(detected.bin)})`,
97
- "No agent will be started. Tick prompt is the existing run-plan loop prompt."
98
- ].join("\n");
99
- return { exitCode: 0, stdout: preview };
100
- }
101
- const code = await runPlanLoop({
102
- root,
103
- maxTicks: input.maxTicks,
104
- sleepSeconds: input.sleepSeconds,
105
- model: input.model,
106
- dryRun: false,
107
- backend,
108
- noHitl: input.noHitl === true,
109
- plain: input.plain === true,
110
- landOnGate: input.landOnGate === true
111
- });
112
- return { exitCode: code };
113
- }
114
- if (slash === REVIEW_PACK_SLASH) {
115
- try {
116
- return await runReviewJob({
117
- root,
118
- backendId: detected.id,
119
- bin: detected.bin,
120
- model: input.model,
121
- maxPackBytes: input.maxPackBytes,
122
- includeReviewed: input.includeReviewed === true,
123
- noHitl: input.noHitl === true,
124
- dryRun: input.dryRun
125
- });
126
- } catch (err) {
127
- return { exitCode: 1, error: String(err) };
128
- }
129
- }
130
- const file = await readCommandFile(root, slash);
131
- if (!file.ok) {
132
- return { exitCode: 1, error: file.message };
133
- }
134
- const prompt = buildDispatchPrompt(file.body);
135
- if (input.dryRun) {
136
- const stdout = [
137
- "--dry-run: no agent will be started.",
138
- `Slash: ${slash}`,
139
- `Command file: ${path.relative(root, file.path)}`,
140
- `Backend: ${detected.id} (${displayPath(detected.bin)})`,
141
- "Prompt:",
142
- prompt
143
- ].join("\n");
144
- return { exitCode: 0, stdout };
145
- }
146
- const logPath = await ensureDispatchLogPath(root);
147
- console.log(`Dispatch: ${slash} via ${detected.id}`);
148
- console.log(`Command file: ${path.relative(root, file.path)}`);
149
- console.log(`Log: ${path.relative(root, logPath)}`);
150
- try {
151
- const dispatch = {
152
- backendId: detected.id,
153
- bin: detected.bin,
154
- workspace: root,
155
- prompt,
156
- model: input.model,
157
- logPath
158
- };
159
- const result = shouldUseLiveTui({ plain: input.plain }) ? await withLiveTui(
160
- { root, backend: detected.id, logPath, noHitl: input.noHitl === true },
161
- (seams) => runHeadlessDispatch({
162
- ...dispatch,
163
- hitl: seams.hitl,
164
- render: seams.render,
165
- onSpawn: seams.onSpawn,
166
- log: seams.log
167
- })
168
- ) : await runHeadlessDispatch({
169
- ...dispatch,
170
- hitl: { policy: input.noHitl ? "off" : "prompt" }
171
- });
172
- for (const line of formatHitlSummary(result.hitl)) console.log(line);
173
- const exitCode = hitlExitCode(result.exitCode, result.hitl);
174
- const trigger = input.landOnGate ? classifyGateExit({ stop: result.hitl?.stop, failed: exitCode !== 0 }) : null;
175
- if (trigger) {
176
- const stop = result.hitl?.stop;
177
- const summary = result.lastResult?.resultText.trim() || result.lastResult?.assistantTexts.at(-1)?.trim() || void 0;
178
- try {
179
- await landGateExit({
180
- root,
181
- outcome: {
182
- trigger,
183
- exitCode,
184
- reason: stop?.message ?? `${detected.id} exited with code ${exitCode}`,
185
- command: `run ${slash}`,
186
- backend: detected.id,
187
- logPath,
188
- ...stop ? { askId: stop.askId } : {},
189
- ...summary ? { summary } : {},
190
- ...result.lastResult ? {
191
- gateText: [
192
- result.lastResult.resultText,
193
- ...result.lastResult.assistantTexts
194
- ].join("\n")
195
- } : {}
196
- },
197
- log: (line) => console.log(line)
198
- });
199
- } catch (err) {
200
- console.log(`gate-exit: landing failed: ${String(err)}`);
201
- }
202
- }
203
- return { exitCode };
204
- } catch (err) {
205
- return { exitCode: 1, error: String(err) };
206
- }
207
- }
208
- var runDispatchArgs = {
209
- cwd: {
210
- type: "string",
211
- description: "Project root (default: current directory)",
212
- default: process.cwd()
213
- },
214
- backend: {
215
- type: "string",
216
- description: `Agent CLI (${listDetectBackendIds().join(" | ")}; default: auto)`,
217
- default: "auto"
218
- },
219
- model: {
220
- type: "string",
221
- description: "Optional model id passed to the agent CLI",
222
- default: ""
223
- },
224
- "dry-run": {
225
- type: "boolean",
226
- description: "Print the resolved backend and prompt, then exit without starting an agent",
227
- default: false
228
- },
229
- "max-ticks": {
230
- type: "string",
231
- description: "For run-plan alias only: maximum ticks (default: 10)",
232
- default: "10"
233
- },
234
- sleep: {
235
- type: "string",
236
- description: "For run-plan alias only: seconds between ticks (default: 5)",
237
- default: "5"
238
- },
239
- "no-hitl": {
240
- type: "boolean",
241
- description: `CI: never prompt; a HITL gate stops the run with exit ${HITL_UNANSWERED_EXIT_CODE} (no default answer)`,
242
- default: false
243
- },
244
- plain: {
245
- type: "boolean",
246
- description: "Status lines instead of the Mission Control live view (the default on a TTY; non-TTY, NO_COLOR and CI are always plain)",
247
- default: false
248
- },
249
- "land-on-gate": {
250
- type: "boolean",
251
- description: LAND_ON_GATE_DESCRIPTION,
252
- default: false
253
- }
254
- };
255
- var maxPackBytesArg = {
256
- type: "string",
257
- description: "For review-pack only: diff pack ceiling in bytes (default: 98304; a branch whose section does not fit is listed as not reviewed, never cut)",
258
- default: ""
259
- };
260
- var includeReviewedArg = {
261
- type: "boolean",
262
- description: "For review-pack only: also review branches whose tip is unchanged since the last completed review (.cursor/context/review-ledger.json)",
263
- default: false
264
- };
265
- async function runSlashCli(slash, args) {
266
- const maxTicks = Number.parseInt(String(args["max-ticks"]), 10);
267
- const sleepSeconds = Number.parseFloat(String(args.sleep));
268
- if (!Number.isFinite(maxTicks) || maxTicks < 1) {
269
- logger.error("--max-ticks must be a positive integer");
270
- process.exitCode = 1;
271
- return;
272
- }
273
- if (!Number.isFinite(sleepSeconds) || sleepSeconds < 0) {
274
- logger.error("--sleep must be a non-negative number");
275
- process.exitCode = 1;
276
- return;
277
- }
278
- const result = await executeRun({
279
- slash,
280
- cwd: String(args.cwd),
281
- backend: String(args.backend),
282
- model: args.model ? String(args.model) : void 0,
283
- dryRun: Boolean(args["dry-run"]),
284
- maxTicks,
285
- sleepSeconds,
286
- noHitl: negatedFlag(args, "hitl"),
287
- plain: Boolean(args.plain),
288
- landOnGate: Boolean(args["land-on-gate"]),
289
- ...args["max-pack-bytes"] ? { maxPackBytes: String(args["max-pack-bytes"]) } : {},
290
- ...args["include-reviewed"] ? { includeReviewed: true } : {}
291
- });
292
- if (result.stdout) {
293
- console.log(result.stdout);
294
- }
295
- if (result.error) {
296
- logger.error(result.error);
297
- }
298
- process.exitCode = result.exitCode;
299
- }
300
- var runCommand = defineCommand({
301
- meta: {
302
- name: "run",
303
- description: "Start one headless session from an L0 slash file. Numbered-list HITL answered from the terminal (claude backend). Never git-prod."
304
- },
305
- args: {
306
- slash: {
307
- type: "positional",
308
- description: "Slash name (e.g. run-plan-all, backlog-add, continue-plan)",
309
- required: true
310
- },
311
- ...runDispatchArgs,
312
- "max-pack-bytes": maxPackBytesArg,
313
- "include-reviewed": includeReviewedArg
314
- },
315
- async run({ args }) {
316
- await runSlashCli(String(args.slash ?? ""), args);
317
- }
318
- });
319
- var runPlanAllCommand = defineCommand({
320
- meta: {
321
- name: "run-plan-all",
322
- description: "Headless /run-plan-all queue from the L0 file. Numbered-list HITL answered from the terminal (claude backend). Never git-prod."
323
- },
324
- args: runDispatchArgs,
325
- async run({ args }) {
326
- await runSlashCli("run-plan-all", args);
327
- }
328
- });
329
- export {
330
- displayPath,
331
- executeRun,
332
- runCommand,
333
- runPlanAllCommand,
334
- runSlashCli
335
- };