@dadado/agent-kit-cli 6.23.0 → 6.25.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 (65) hide show
  1. package/README.md +1 -0
  2. package/dashboard/dashboard-data.mjs +126 -5
  3. package/dashboard/dashboard.html +45 -4
  4. package/dashboard/lib/live-refresh.mjs +1 -0
  5. package/dist/{add-RKZQX6ZK.js → add-OYLOMCM6.js} +14 -6
  6. package/dist/chunk-2F6NMQOA.js +519 -0
  7. package/dist/chunk-2QYWMSI5.js +193 -0
  8. package/dist/{chunk-B3VR5YBQ.js → chunk-2TW7ENWC.js} +12 -11
  9. package/dist/{chunk-2IP4OO6R.js → chunk-2XLI7XEY.js} +1 -1
  10. package/dist/chunk-6M6UKECW.js +176 -0
  11. package/dist/{chunk-UJCATSYO.js → chunk-7Y74KO7U.js} +45 -16
  12. package/dist/{chunk-DZCLMIAS.js → chunk-AQLBEEPD.js} +236 -2
  13. package/dist/{chunk-R4DUO5DA.js → chunk-AXQMVQ6O.js} +61 -237
  14. package/dist/{chunk-7TYA3GMI.js → chunk-C7SV7UP5.js} +7 -4
  15. package/dist/{chunk-F7YAAKYP.js → chunk-CIV42JGT.js} +7 -5
  16. package/dist/{chunk-CQHD6UKB.js → chunk-CXE6ASSX.js} +1 -0
  17. package/dist/{chunk-6BEFGKCU.js → chunk-EO5NGAYV.js} +1 -1
  18. package/dist/{chunk-MJJBIOSY.js → chunk-G5MQRP6M.js} +31 -13
  19. package/dist/chunk-GMG7ZH4E.js +357 -0
  20. package/dist/{chunk-5EBT3V7G.js → chunk-GQSSXDDK.js} +1 -1
  21. package/dist/{chunk-5LNHRL5E.js → chunk-H7RAFRRZ.js} +41 -245
  22. package/dist/{chunk-IESSMKOV.js → chunk-HSIHZWFF.js} +4 -4
  23. package/dist/{chunk-W3ZJVBNY.js → chunk-IFBIO7VT.js} +449 -418
  24. package/dist/{chunk-V2H57TFD.js → chunk-JG3CNGQM.js} +78 -170
  25. package/dist/{chunk-KDJ4ML7I.js → chunk-JGG574RK.js} +3 -3
  26. package/dist/{chunk-SGTTC2JP.js → chunk-KWYF7QNH.js} +1 -1
  27. package/dist/{chunk-CVZNSRXV.js → chunk-M4UL422I.js} +80 -15
  28. package/dist/{chunk-AWQ6KRFV.js → chunk-NJ2SUSWX.js} +1 -1
  29. package/dist/{chunk-DRZFWIBN.js → chunk-PIMGV3E5.js} +1 -1
  30. package/dist/{chunk-QNISTPPZ.js → chunk-QACMV46U.js} +3 -3
  31. package/dist/{chunk-5PSV76CQ.js → chunk-QLTGHJB3.js} +25 -6
  32. package/dist/{chunk-OYFCBYMP.js → chunk-QX55T4UX.js} +13 -1
  33. package/dist/chunk-SAQ3EE5R.js +138 -0
  34. package/dist/{chunk-C4LCOOL4.js → chunk-TOSAAQ5A.js} +1 -1
  35. package/dist/chunk-WKFE3RUC.js +433 -0
  36. package/dist/{chunk-BGL5DRK2.js → chunk-XGZOU4DS.js} +1 -1
  37. package/dist/{commands-SAQEEE6V.js → commands-UW2C2ZN4.js} +4 -4
  38. package/dist/{conflicts-5JOP4GX2.js → conflicts-RING6AHV.js} +6 -6
  39. package/dist/{contribute-BQKRT5GN.js → contribute-LSY75JZH.js} +5 -4
  40. package/dist/{countdown-25E5C7AR.js → countdown-SZ2P4XHB.js} +267 -23
  41. package/dist/{diff-6JSXBVSX.js → diff-NZVBVQSK.js} +13 -5
  42. package/dist/{doctor-I3MTHS7F.js → doctor-TJSXBVGV.js} +103 -17
  43. package/dist/{ground-control-IDCXN5FK.js → ground-control-ZJXPUIQN.js} +3 -3
  44. package/dist/{guard-RJZEEKSL.js → guard-ZO4Z3LLB.js} +47 -9
  45. package/dist/{handoff-5AGE2D3T.js → handoff-2OZSWGTE.js} +2 -0
  46. package/dist/{hook-WNA42CXE.js → hook-3VPKNSOO.js} +12 -10
  47. package/dist/index.js +27 -26
  48. package/dist/{init-FZ2UFPO7.js → init-UW2BJBO2.js} +21 -15
  49. package/dist/{install-CTLT3TSI.js → install-RQSI4CHG.js} +18 -15
  50. package/dist/installs-7TR4H4QH.js +222 -0
  51. package/dist/{mission-control-CRMCRZUU.js → mission-control-VSU6NT43.js} +1 -1
  52. package/dist/{queue-JW4VR33H.js → queue-JHYILLMX.js} +9 -9
  53. package/dist/{run-X2WOONTB.js → run-CQF5RM5X.js} +21 -21
  54. package/dist/{run-plan-4MOLLIES.js → run-plan-BEOCOJCF.js} +13 -13
  55. package/dist/{scan-K3T5RQLC.js → scan-7D3RMO34.js} +2 -1
  56. package/dist/{session-start-MV7A4263.js → session-start-QV7CEFRX.js} +16 -10
  57. package/dist/{sessions-UPFDWDMB.js → sessions-AWAAO3DU.js} +1 -1
  58. package/dist/{setup-global-VNADNTQ2.js → setup-global-ST4TT427.js} +8 -7
  59. package/dist/{status-SXA3OK5E.js → status-HUBPBGUU.js} +13 -10
  60. package/dist/update-DD5UZPGG.js +31 -0
  61. package/dist/update-all-YYUTXHGR.js +695 -0
  62. package/package.json +1 -1
  63. package/dist/chunk-4MR4QXMF.js +0 -52
  64. package/dist/chunk-HAFRAXGV.js +0 -17
  65. package/dist/update-RMAWXMCV.js +0 -304
@@ -0,0 +1,695 @@
1
+ import {
2
+ applyUpdateAtRoot
3
+ } from "./chunk-GMG7ZH4E.js";
4
+ import {
5
+ QUEUE_LEASE_SESSION_ENV,
6
+ inspectQueueLease
7
+ } from "./chunk-MFKHIWEL.js";
8
+ import {
9
+ CLAUDE_NESTED_SESSION_KEYS
10
+ } from "./chunk-IFBIO7VT.js";
11
+ import "./chunk-P7732A25.js";
12
+ import "./chunk-QLTGHJB3.js";
13
+ import "./chunk-HS7LVVLO.js";
14
+ import "./chunk-PIMGV3E5.js";
15
+ import "./chunk-NJ2SUSWX.js";
16
+ import "./chunk-EO5NGAYV.js";
17
+ import {
18
+ InstallsRegistryError,
19
+ inspectInstall,
20
+ listInstalls
21
+ } from "./chunk-WKFE3RUC.js";
22
+ import "./chunk-WGLPZXNU.js";
23
+ import "./chunk-Q35TWISF.js";
24
+ import "./chunk-QTON2GQX.js";
25
+ import {
26
+ detectProvider
27
+ } from "./chunk-2QYWMSI5.js";
28
+ import {
29
+ logger
30
+ } from "./chunk-ZB43YMHW.js";
31
+ import "./chunk-JGG574RK.js";
32
+ import "./chunk-2TW7ENWC.js";
33
+ import {
34
+ checkRunningCliVsNpmLatest,
35
+ compareSemver
36
+ } from "./chunk-M4UL422I.js";
37
+ import "./chunk-PFEUZXVT.js";
38
+ import "./chunk-C7SV7UP5.js";
39
+ import "./chunk-SAQ3EE5R.js";
40
+ import "./chunk-CGXLR77R.js";
41
+ import {
42
+ isProtectedPath,
43
+ loadAgentKitManifest,
44
+ resolveProtectedGlobs
45
+ } from "./chunk-JG3CNGQM.js";
46
+ import {
47
+ MANAGED_HASHES_REL
48
+ } from "./chunk-QX55T4UX.js";
49
+ import {
50
+ MANIFEST_RELATIVE_PATH
51
+ } from "./chunk-6M6UKECW.js";
52
+ import {
53
+ KIT_VERSION
54
+ } from "./chunk-7HDQEK6T.js";
55
+ import "./chunk-C4Q77GGJ.js";
56
+ import "./chunk-5B4DVO6C.js";
57
+
58
+ // src/commands/update-all.ts
59
+ import { execFile } from "child_process";
60
+ import { homedir } from "os";
61
+ import path from "path";
62
+ import { promisify } from "util";
63
+ import { confirm, isCancel } from "@clack/prompts";
64
+
65
+ // src/utils/agent-session.ts
66
+ var AGENT_KIT_HEADLESS_ENV = "AGENT_KIT_HEADLESS";
67
+ var AGENT_SESSION_MARKERS = [
68
+ ...CLAUDE_NESTED_SESSION_KEYS.map((key) => ({ key, label: "Claude Code agent session" })),
69
+ { key: "CURSOR_AGENT", label: "Cursor agent session" },
70
+ { key: AGENT_KIT_HEADLESS_ENV, label: "headless Agent Kit run" },
71
+ { key: QUEUE_LEASE_SESSION_ENV, label: "Agent Kit plan loop" }
72
+ ];
73
+ function markerSet(value) {
74
+ if (value === void 0) return false;
75
+ const v = value.trim().toLowerCase();
76
+ return v !== "" && v !== "0" && v !== "false";
77
+ }
78
+ function detectAgentSession(env = process.env) {
79
+ for (const marker of AGENT_SESSION_MARKERS) {
80
+ if (markerSet(env[marker.key])) return marker;
81
+ }
82
+ return null;
83
+ }
84
+ function operatorOnlyRefusal(command, probe = {}) {
85
+ const agent = detectAgentSession(probe.env ?? process.env);
86
+ if (agent) {
87
+ return `${command} is operator-only and refuses inside an agent session (${agent.label}: ${agent.key} is set); type it in your own terminal.`;
88
+ }
89
+ const stdinTTY = probe.stdinIsTTY ?? Boolean(process.stdin.isTTY);
90
+ const stdoutTTY = probe.stdoutIsTTY ?? Boolean(process.stdout.isTTY);
91
+ if (!stdinTTY || !stdoutTTY) {
92
+ return `${command} is operator-only and needs an interactive terminal (stdin and stdout must be a TTY); type it in your own terminal.`;
93
+ }
94
+ return null;
95
+ }
96
+
97
+ // src/commands/update-all.ts
98
+ var execFileAsync = promisify(execFile);
99
+ var KIT_PATHSPECS = [
100
+ ".cursor",
101
+ ".claude",
102
+ "autogit",
103
+ "git-hooks",
104
+ "AGENTS.md",
105
+ "CLAUDE.md"
106
+ ];
107
+ var UPDATE_ALL_COMMAND = "agent-kit update --all";
108
+ function parseRemote(url) {
109
+ const trimmed = url.trim();
110
+ if (!trimmed) return null;
111
+ let host;
112
+ let repoPath;
113
+ const scp = /^[^/@\s]+@([^:/\s]+):(.+)$/.exec(trimmed);
114
+ if (scp && !trimmed.includes("://")) {
115
+ host = scp[1];
116
+ repoPath = scp[2];
117
+ } else {
118
+ try {
119
+ const parsed = new URL(trimmed);
120
+ if (!parsed.hostname) return null;
121
+ host = parsed.hostname;
122
+ repoPath = parsed.pathname;
123
+ } catch {
124
+ return null;
125
+ }
126
+ }
127
+ repoPath = repoPath.replace(/^\/+/, "").replace(/\/+$/, "").replace(/\.git$/, "");
128
+ if (!repoPath.includes("/")) return null;
129
+ const lower = host.toLowerCase();
130
+ const forge = lower === "github.com" ? "github" : lower.includes("gitlab") ? "gitlab" : "none";
131
+ return { url: trimmed, host, repoPath, forge };
132
+ }
133
+ function forgeCreateArgv(remote, opts) {
134
+ if (remote.forge === "github") {
135
+ return {
136
+ cmd: "gh",
137
+ args: [
138
+ "pr",
139
+ "create",
140
+ "--repo",
141
+ remote.repoPath,
142
+ "--base",
143
+ opts.base,
144
+ "--head",
145
+ opts.head,
146
+ "--title",
147
+ opts.title,
148
+ "--body",
149
+ opts.body
150
+ ]
151
+ };
152
+ }
153
+ if (remote.forge === "gitlab") {
154
+ return {
155
+ cmd: "glab",
156
+ args: [
157
+ "mr",
158
+ "create",
159
+ "-R",
160
+ `${remote.host}/${remote.repoPath}`,
161
+ "--source-branch",
162
+ opts.head,
163
+ "--target-branch",
164
+ opts.base,
165
+ "--title",
166
+ opts.title,
167
+ "--description",
168
+ opts.body,
169
+ "--yes"
170
+ ]
171
+ };
172
+ }
173
+ return null;
174
+ }
175
+ function cleanGitEnv() {
176
+ const env = { ...process.env };
177
+ for (const key of ["GIT_DIR", "GIT_WORK_TREE", "GIT_COMMON_DIR", "GIT_INDEX_FILE"]) {
178
+ delete env[key];
179
+ }
180
+ return env;
181
+ }
182
+ function execError(err) {
183
+ const e = err;
184
+ const detail = (e.stderr ?? "").trim().split("\n").filter(Boolean).pop();
185
+ return new Error(detail || e.message || String(err));
186
+ }
187
+ var defaultGit = async (args, cwd) => {
188
+ try {
189
+ const { stdout } = await execFileAsync("git", [...args], {
190
+ cwd,
191
+ env: cleanGitEnv(),
192
+ encoding: "utf8",
193
+ maxBuffer: 16 * 1024 * 1024,
194
+ timeout: 12e4
195
+ });
196
+ return stdout.trim();
197
+ } catch (err) {
198
+ throw execError(err);
199
+ }
200
+ };
201
+ var defaultForge = async (cmd, args, cwd) => {
202
+ try {
203
+ const { stdout } = await execFileAsync(cmd, [...args], {
204
+ cwd,
205
+ encoding: "utf8",
206
+ timeout: 12e4
207
+ });
208
+ return stdout.trim();
209
+ } catch (err) {
210
+ throw execError(err);
211
+ }
212
+ };
213
+ async function gitOk(git, args, cwd) {
214
+ try {
215
+ return await git(args, cwd);
216
+ } catch {
217
+ return null;
218
+ }
219
+ }
220
+ function kitBranchName(version) {
221
+ return `chore/kit-${version}`;
222
+ }
223
+ function majorOf(version) {
224
+ const m = /^(\d+)\./.exec(version.trim());
225
+ return m ? Number(m[1]) : null;
226
+ }
227
+ function parsePorcelainZ(out) {
228
+ return out.split("\0").filter(Boolean).map((entry) => /^[ MTADRCU?!]{1,2} (.+)$/s.exec(entry)?.[1] ?? entry);
229
+ }
230
+ async function kitStatusPaths(git, root) {
231
+ const out = await git(
232
+ [
233
+ "status",
234
+ "--porcelain",
235
+ "-z",
236
+ "--no-renames",
237
+ "--untracked-files=all",
238
+ "--",
239
+ ...KIT_PATHSPECS
240
+ ],
241
+ root
242
+ );
243
+ return parsePorcelainZ(out);
244
+ }
245
+ async function resolvePreProd(git, root, hasRemote) {
246
+ const localStaging = await gitOk(
247
+ git,
248
+ ["rev-parse", "--verify", "--quiet", "refs/heads/staging"],
249
+ root
250
+ );
251
+ if (hasRemote) {
252
+ const remoteStaging = await gitOk(
253
+ git,
254
+ ["rev-parse", "--verify", "--quiet", "refs/remotes/origin/staging"],
255
+ root
256
+ );
257
+ let preProd = remoteStaging ? "staging" : null;
258
+ if (!preProd) {
259
+ const head = await gitOk(git, ["symbolic-ref", "--short", "refs/remotes/origin/HEAD"], root);
260
+ preProd = head ? head.replace(/^origin\//, "") : null;
261
+ }
262
+ if (!preProd) {
263
+ for (const candidate of ["main", "master"]) {
264
+ if (await gitOk(
265
+ git,
266
+ ["rev-parse", "--verify", "--quiet", `refs/remotes/origin/${candidate}`],
267
+ root
268
+ )) {
269
+ preProd = candidate;
270
+ break;
271
+ }
272
+ }
273
+ }
274
+ if (!preProd) return { preProd: null, hasLocal: false };
275
+ const local = await gitOk(
276
+ git,
277
+ ["rev-parse", "--verify", "--quiet", `refs/heads/${preProd}`],
278
+ root
279
+ );
280
+ return { preProd, hasLocal: Boolean(local) };
281
+ }
282
+ if (localStaging) return { preProd: "staging", hasLocal: true };
283
+ for (const candidate of ["main", "master"]) {
284
+ if (await gitOk(git, ["rev-parse", "--verify", "--quiet", `refs/heads/${candidate}`], root)) {
285
+ return { preProd: candidate, hasLocal: true };
286
+ }
287
+ }
288
+ return { preProd: null, hasLocal: false };
289
+ }
290
+ async function planRow(installPath, options = {}) {
291
+ const git = options.git ?? defaultGit;
292
+ const target = options.targetVersion ?? KIT_VERSION;
293
+ const branch = kitBranchName(target);
294
+ const row = {
295
+ path: installPath,
296
+ kind: "missing",
297
+ currentVersion: null,
298
+ targetVersion: target,
299
+ preProd: null,
300
+ behind: null,
301
+ dirtyKitFiles: [],
302
+ leaseHolder: null,
303
+ remote: null,
304
+ hasLocalPreProd: false,
305
+ skip: null,
306
+ branch
307
+ };
308
+ const record = await inspectInstall(installPath, options.inspect);
309
+ if (!record) {
310
+ row.skip = "no kit manifest any more (run agent-kit installs prune)";
311
+ return row;
312
+ }
313
+ row.kind = record.kind;
314
+ row.currentVersion = record.kitVersion;
315
+ const kindSkip = {
316
+ home: "home-level install (run agent-kit update in ~ by hand)",
317
+ fixture: "fixture (not its own repository)",
318
+ factory: "factory (the kit's own repository)"
319
+ };
320
+ if (kindSkip[record.kind]) {
321
+ row.skip = kindSkip[record.kind];
322
+ return row;
323
+ }
324
+ if (record.kind === "worktree" && !options.includeWorktrees) {
325
+ row.skip = "worktree (--include-worktrees to update it)";
326
+ return row;
327
+ }
328
+ if (!record.kitVersion) {
329
+ row.skip = "manifest has no version (run agent-kit update in it by hand)";
330
+ return row;
331
+ }
332
+ let cmp;
333
+ try {
334
+ cmp = compareSemver(record.kitVersion, target);
335
+ } catch {
336
+ row.skip = `unreadable version ${record.kitVersion} (run agent-kit update in it by hand)`;
337
+ return row;
338
+ }
339
+ if (cmp === 0) {
340
+ row.skip = `current (v${target})`;
341
+ return row;
342
+ }
343
+ if (cmp > 0) {
344
+ row.skip = `ahead of this CLI (v${record.kitVersion})`;
345
+ return row;
346
+ }
347
+ const fromMajor = majorOf(record.kitVersion);
348
+ const toMajor = majorOf(target);
349
+ if (fromMajor !== null && toMajor !== null && fromMajor < toMajor) {
350
+ row.skip = `major jump v${record.kitVersion} \u2192 v${target} (run a single-repo agent-kit update)`;
351
+ return row;
352
+ }
353
+ const inside = await gitOk(git, ["rev-parse", "--is-inside-work-tree"], installPath);
354
+ if (inside !== "true") {
355
+ row.skip = "not a git repository";
356
+ return row;
357
+ }
358
+ const lease = inspectQueueLease(installPath);
359
+ if (lease.kind === "held") {
360
+ row.leaseHolder = `session ${lease.lease.session} (pid ${lease.lease.dispatcher.pid})`;
361
+ }
362
+ const rawUrl = await gitOk(git, ["config", "--get", "remote.origin.url"], installPath);
363
+ row.remote = rawUrl ? parseRemote(rawUrl) : null;
364
+ if (rawUrl && !row.remote) {
365
+ row.skip = "origin URL not understood (update this repo by hand)";
366
+ return row;
367
+ }
368
+ if (row.remote && row.remote.forge === "none") {
369
+ const detected = await detectProvider(installPath, row.remote.url);
370
+ if (detected.provider === "gitlab") row.remote = { ...row.remote, forge: "gitlab" };
371
+ else if (detected.provider === "github") row.remote = { ...row.remote, forge: "github" };
372
+ }
373
+ if (row.remote && options.fetch !== false) {
374
+ await gitOk(git, ["fetch", "--quiet", "origin"], installPath);
375
+ }
376
+ const pre = await resolvePreProd(git, installPath, Boolean(row.remote));
377
+ row.preProd = pre.preProd;
378
+ row.hasLocalPreProd = pre.hasLocal;
379
+ if (!row.preProd) {
380
+ row.skip = "no pre-prod branch found (staging, main or master)";
381
+ return row;
382
+ }
383
+ if (row.remote && row.hasLocalPreProd) {
384
+ const counts = await gitOk(
385
+ git,
386
+ [
387
+ "rev-list",
388
+ "--left-right",
389
+ "--count",
390
+ `refs/heads/${row.preProd}...refs/remotes/origin/${row.preProd}`
391
+ ],
392
+ installPath
393
+ );
394
+ const [ahead, behind] = (counts ?? "").split(/\s+/).map(Number);
395
+ if (Number.isFinite(behind)) row.behind = behind;
396
+ if (Number.isFinite(ahead) && ahead > 0) {
397
+ row.skip = `diverged (local ${row.preProd} has ${ahead} commit(s) not on origin)`;
398
+ return row;
399
+ }
400
+ }
401
+ const manifest = await loadAgentKitManifest(installPath);
402
+ const protectedGlobs = resolveProtectedGlobs(manifest);
403
+ row.dirtyKitFiles = (await kitStatusPaths(git, installPath)).filter(
404
+ (p) => !isProtectedPath(p, protectedGlobs)
405
+ );
406
+ if (row.leaseHolder) {
407
+ row.skip = `live writer holds the queue lease (${row.leaseHolder})`;
408
+ return row;
409
+ }
410
+ if (row.dirtyKitFiles.length > 0) {
411
+ row.skip = `dirty kit files (${row.dirtyKitFiles.length}): commit or stash them first`;
412
+ return row;
413
+ }
414
+ const localBranch = await gitOk(
415
+ git,
416
+ ["rev-parse", "--verify", "--quiet", `refs/heads/${branch}`],
417
+ installPath
418
+ );
419
+ const remoteBranch = row.remote ? await gitOk(
420
+ git,
421
+ ["rev-parse", "--verify", "--quiet", `refs/remotes/origin/${branch}`],
422
+ installPath
423
+ ) : null;
424
+ if (localBranch || remoteBranch) {
425
+ row.skip = `branch ${branch} already exists (merge or close its PR/MR, then delete it)`;
426
+ return row;
427
+ }
428
+ return row;
429
+ }
430
+ function displayPath(p, home) {
431
+ return p === home ? "~" : p.startsWith(`${home}${path.sep}`) ? `~${p.slice(home.length)}` : p;
432
+ }
433
+ function renderTable(header, rows) {
434
+ const widths = header.map((h, i) => Math.max(h.length, ...rows.map((r) => (r[i] ?? "").length)));
435
+ const fmt = (r) => r.map((c, i) => i === r.length - 1 ? c : c.padEnd(widths[i] ?? 0)).join(" ").trimEnd();
436
+ return [fmt(header), ...rows.map(fmt)].join("\n");
437
+ }
438
+ function renderPlanTable(rows, home = homedir()) {
439
+ return renderTable(
440
+ ["REPO", "KIT", "PRE-PROD", "DIRTY", "LEASE", "ACTION"],
441
+ rows.map((r) => [
442
+ displayPath(r.path, home),
443
+ `${r.currentVersion ?? "?"} \u2192 ${r.targetVersion}`,
444
+ r.preProd ? `${r.preProd}${r.behind ? ` (behind ${r.behind})` : ""}` : "-",
445
+ String(r.dirtyKitFiles.length),
446
+ r.leaseHolder ? "held" : "free",
447
+ r.skip ? `skip: ${r.skip}` : `update on ${r.branch}`
448
+ ])
449
+ );
450
+ }
451
+ async function currentRef(git, root) {
452
+ const branch = await gitOk(git, ["branch", "--show-current"], root) || null;
453
+ const sha = await git(["rev-parse", "HEAD"], root);
454
+ return { branch, sha };
455
+ }
456
+ async function switchBack(git, root, start) {
457
+ if (start.branch) await git(["switch", start.branch], root);
458
+ else await git(["switch", "--detach", start.sha], root);
459
+ }
460
+ async function treeStatusPaths(git, root) {
461
+ return parsePorcelainZ(
462
+ await git(["status", "--porcelain", "-z", "--no-renames", "--untracked-files=all"], root)
463
+ );
464
+ }
465
+ async function executeRow(row, options = {}) {
466
+ if (row.skip) return { status: "skipped", note: row.skip };
467
+ const git = options.git ?? defaultGit;
468
+ const forge = options.forge ?? defaultForge;
469
+ const apply = options.apply ?? ((root2) => applyUpdateAtRoot(root2, {}));
470
+ const root = row.path;
471
+ const preProd = row.preProd;
472
+ const branch = row.branch;
473
+ let start;
474
+ let before;
475
+ try {
476
+ start = await currentRef(git, root);
477
+ before = new Set(await treeStatusPaths(git, root));
478
+ } catch (err) {
479
+ return { status: "error", note: `cannot read the repository state: ${err.message}` };
480
+ }
481
+ const newDirt = async () => (await treeStatusPaths(git, root)).filter((p) => !before.has(p));
482
+ let onKitBranch = false;
483
+ const leave = async (keepBranch) => {
484
+ await switchBack(git, root, start);
485
+ onKitBranch = false;
486
+ if (!keepBranch) await gitOk(git, ["branch", "-D", branch], root);
487
+ };
488
+ try {
489
+ let base = preProd;
490
+ if (row.remote) {
491
+ await git(["fetch", "--quiet", "origin", preProd], root);
492
+ if (row.hasLocalPreProd) {
493
+ await git(["switch", preProd], root);
494
+ try {
495
+ await git(["merge", "--ff-only", `refs/remotes/origin/${preProd}`], root);
496
+ } catch (err) {
497
+ await switchBack(git, root, start);
498
+ return {
499
+ status: "error",
500
+ note: `${preProd} cannot fast-forward from origin (diverged): ${err.message}`
501
+ };
502
+ }
503
+ } else {
504
+ base = `refs/remotes/origin/${preProd}`;
505
+ }
506
+ }
507
+ await git(["switch", "--no-track", "-c", branch, base], root);
508
+ onKitBranch = true;
509
+ const result = await apply(root);
510
+ if (result.status !== "applied") {
511
+ const reason = result.status === "no-manifest" ? "no kit manifest on the pre-prod branch" : result.reason;
512
+ const leftover = await newDirt();
513
+ if (leftover.length === 0) {
514
+ await leave(false);
515
+ return { status: "error", note: `update refused: ${reason}` };
516
+ }
517
+ return {
518
+ status: "error",
519
+ note: `update failed: ${reason}; left on ${branch} with ${leftover.length} uncommitted path(s) to inspect`
520
+ };
521
+ }
522
+ const candidates = /* @__PURE__ */ new Set([
523
+ ...result.stats.written,
524
+ ...result.stats.removed,
525
+ MANIFEST_RELATIVE_PATH,
526
+ MANAGED_HASHES_REL
527
+ ]);
528
+ const changed = (await newDirt()).filter((p) => candidates.has(p));
529
+ if (changed.length === 0) {
530
+ const stray2 = await newDirt();
531
+ if (stray2.length > 0) {
532
+ return {
533
+ status: "error",
534
+ note: `the apply changed ${stray2.length} path(s) it did not report; left on ${branch} to inspect`
535
+ };
536
+ }
537
+ await leave(false);
538
+ return { status: "current", note: `${preProd} already carries v${result.toVersion}` };
539
+ }
540
+ const message = `chore(agent-kit): update kit to v${result.toVersion}`;
541
+ await git(["add", "--", ...changed], root);
542
+ await git(["commit", "--quiet", "--only", "-m", message, "--", ...changed], root);
543
+ const stray = await newDirt();
544
+ if (stray.length > 0) {
545
+ return {
546
+ status: "error",
547
+ note: `committed on ${branch}, but ${stray.length} other new path(s) appeared (${stray.slice(0, 3).join(", ")}); left on ${branch}, not pushed`
548
+ };
549
+ }
550
+ if (!row.remote) {
551
+ await leave(true);
552
+ return { status: "committed", branch, note: "no remote: branch + commit only" };
553
+ }
554
+ try {
555
+ await git(["push", "--quiet", "-u", "origin", branch], root);
556
+ } catch (err) {
557
+ await leave(false);
558
+ return { status: "error", note: `push failed: ${err.message}` };
559
+ }
560
+ await leave(true);
561
+ const body = [
562
+ `Agent Kit v${result.fromVersion} \u2192 v${result.toVersion}, opened by \`${UPDATE_ALL_COMMAND}\`.`,
563
+ "",
564
+ `Only kit-managed paths are committed (${changed.length} file(s)); L3 protected paths are untouched.`,
565
+ "Review and merge it yourself; nothing was merged."
566
+ ].join("\n");
567
+ const argv = forgeCreateArgv(row.remote, { head: branch, base: preProd, title: message, body });
568
+ if (!argv) {
569
+ return {
570
+ status: "pushed",
571
+ branch,
572
+ note: `pushed; open the PR/MR on ${row.remote.host} by hand`
573
+ };
574
+ }
575
+ try {
576
+ const out = await forge(argv.cmd, argv.args, root);
577
+ const url = out.split("\n").find((l) => /^https?:\/\//.test(l.trim()))?.trim() ?? out.trim();
578
+ return { status: "opened", branch, url };
579
+ } catch (err) {
580
+ return {
581
+ status: "pushed",
582
+ branch,
583
+ note: `pushed, but ${argv.cmd} failed: ${err.message}; open the PR/MR by hand`
584
+ };
585
+ }
586
+ } catch (err) {
587
+ const message = err.message;
588
+ if (!onKitBranch) {
589
+ await switchBack(git, root, start).catch(() => void 0);
590
+ return { status: "error", note: message };
591
+ }
592
+ const leftover = await newDirt().catch(() => ["(status unreadable)"]);
593
+ if (leftover.length === 0) {
594
+ await leave(false).catch(() => void 0);
595
+ return { status: "error", note: message };
596
+ }
597
+ return { status: "error", note: `${message} (left on ${branch} with uncommitted changes)` };
598
+ }
599
+ }
600
+ function renderSummaryTable(results, home = homedir()) {
601
+ return renderTable(
602
+ ["REPO", "RESULT", "DETAIL"],
603
+ results.map(({ row, outcome }) => [
604
+ displayPath(row.path, home),
605
+ outcome.status,
606
+ outcome.status === "opened" ? outcome.url : outcome.note
607
+ ])
608
+ );
609
+ }
610
+ async function defaultConfirm(message) {
611
+ const ok = await confirm({ message, initialValue: false });
612
+ return !isCancel(ok) && ok === true;
613
+ }
614
+ async function runUpdateAll(options = {}) {
615
+ const out = options.out ?? ((line) => console.log(line));
616
+ const home = options.home ?? homedir();
617
+ const empty = { rows: [], results: [] };
618
+ const refusal = operatorOnlyRefusal(UPDATE_ALL_COMMAND, options.terminal);
619
+ if (refusal) {
620
+ logger.error(refusal);
621
+ return { status: "refused", reason: refusal, ...empty };
622
+ }
623
+ const cli = await checkRunningCliVsNpmLatest(process.cwd(), {
624
+ respectPrefs: false,
625
+ fetchLatest: options.npmLatest
626
+ });
627
+ if (cli.status !== "up-to-date") {
628
+ const reason = cli.status === "behind" ? `${cli.message} Update the CLI first, then run ${UPDATE_ALL_COMMAND} again.` : cli.status === "ahead" ? `${cli.message} ${UPDATE_ALL_COMMAND} only stamps released versions; install the npm release first.` : `Cannot confirm this CLI matches npm latest (${cli.message}); ${UPDATE_ALL_COMMAND} stops rather than guess.`;
629
+ logger.error(reason);
630
+ return { status: "preflight-stop", reason, ...empty };
631
+ }
632
+ let entries;
633
+ try {
634
+ entries = await listInstalls(options.installsFile ? { file: options.installsFile } : {});
635
+ } catch (err) {
636
+ const reason = err instanceof InstallsRegistryError ? err.message : String(err);
637
+ logger.error(reason);
638
+ return { status: "preflight-stop", reason, ...empty };
639
+ }
640
+ if (entries.length === 0) {
641
+ const reason = "No installs recorded. Run `agent-kit installs scan` first.";
642
+ logger.warn(reason);
643
+ return { status: "nothing-to-do", reason, ...empty };
644
+ }
645
+ const rows = [];
646
+ for (const entry of entries) {
647
+ rows.push(
648
+ await planRow(entry.path, {
649
+ targetVersion: options.targetVersion,
650
+ includeWorktrees: options.includeWorktrees,
651
+ inspect: options.inspect,
652
+ git: options.git
653
+ })
654
+ );
655
+ }
656
+ out(renderPlanTable(rows, home));
657
+ const todo = rows.filter((r) => !r.skip);
658
+ if (todo.length === 0) {
659
+ out("Nothing to update.");
660
+ return { status: "nothing-to-do", rows, results: [] };
661
+ }
662
+ const ask = options.confirm ?? defaultConfirm;
663
+ const ok = await ask(
664
+ `Update ${todo.length} repositor${todo.length === 1 ? "y" : "ies"}: one branch ${todo[0]?.branch} and one PR/MR each (nothing is merged)?`
665
+ );
666
+ if (!ok) {
667
+ out("Cancelled; nothing was changed.");
668
+ return { status: "declined", rows, results: [] };
669
+ }
670
+ const apply = options.apply ?? ((root) => applyUpdateAtRoot(root, { ...options.applyOptions }));
671
+ const results = [];
672
+ for (const row of rows) {
673
+ if (!row.skip) out(`
674
+ \u25B8 ${displayPath(row.path, home)}`);
675
+ const outcome = await executeRow(row, { git: options.git, forge: options.forge, apply });
676
+ results.push({ row, outcome });
677
+ }
678
+ out("");
679
+ out(renderSummaryTable(results, home));
680
+ return { status: "done", rows, results };
681
+ }
682
+ export {
683
+ KIT_PATHSPECS,
684
+ UPDATE_ALL_COMMAND,
685
+ defaultForge,
686
+ defaultGit,
687
+ executeRow,
688
+ forgeCreateArgv,
689
+ parsePorcelainZ,
690
+ parseRemote,
691
+ planRow,
692
+ renderPlanTable,
693
+ renderSummaryTable,
694
+ runUpdateAll
695
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dadado/agent-kit-cli",
3
- "version": "6.23.0",
3
+ "version": "6.25.0",
4
4
  "description": "Agent Kit CLI: HITL framework install and tooling for AI-assisted IDEs (rules, skills, plan/handoff, context).",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://agent.missionkit.io/",