@dadado/agent-kit-cli 6.17.0 → 6.19.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 (63) hide show
  1. package/dashboard/dashboard-data.mjs +8 -3
  2. package/dashboard/dashboard.html +140 -0
  3. package/dashboard/lib/guards.d.mts +20 -0
  4. package/dashboard/lib/guards.mjs +307 -0
  5. package/dashboard/lib/semantic-model.mjs +228 -1
  6. package/dist/{add-DRV3T42D.js → add-MRI5BXHH.js} +3 -3
  7. package/dist/{chunk-3IEE6Q37.js → chunk-2TX6NJEG.js} +1 -1
  8. package/dist/{chunk-IOQ6YXA3.js → chunk-3HNTNYPR.js} +1 -1
  9. package/dist/{chunk-MEZU47IB.js → chunk-5EBT3V7G.js} +1 -1
  10. package/dist/{chunk-5IJQGIOY.js → chunk-677W4QO3.js} +63 -1
  11. package/dist/{chunk-SKC6QZW4.js → chunk-6WUKLS4D.js} +1 -1
  12. package/dist/{chunk-YO4BLHDT.js → chunk-6XJZLH53.js} +149 -18
  13. package/dist/{chunk-J3YLSHRK.js → chunk-7MUTZHWP.js} +23 -4
  14. package/dist/{chunk-CJ3JAH7L.js → chunk-BGL5DRK2.js} +2 -2
  15. package/dist/{chunk-IJQAFPY3.js → chunk-C4LCOOL4.js} +3 -1
  16. package/dist/chunk-DTSL2RH7.js +433 -0
  17. package/dist/{chunk-4DLMU44M.js → chunk-EBDQYFA4.js} +71 -4
  18. package/dist/{chunk-AQTCXUYS.js → chunk-EOQMAU2J.js} +1 -1
  19. package/dist/{chunk-RAMT55TC.js → chunk-G2Z37XFM.js} +3 -3
  20. package/dist/{chunk-HKZH2IEE.js → chunk-GTP224FI.js} +1 -1
  21. package/dist/{chunk-QYIV6ZP6.js → chunk-HJWSOZXS.js} +52 -12
  22. package/dist/{chunk-AZCPUJJO.js → chunk-IQQQDEQ4.js} +2 -2
  23. package/dist/{chunk-ZFJIJUZ4.js → chunk-MPCNPZJZ.js} +1 -1
  24. package/dist/{hook-2YEC7GT5.js → chunk-NL3I2BWA.js} +104 -113
  25. package/dist/{chunk-WGAOM37Y.js → chunk-OKQ37A7E.js} +9 -9
  26. package/dist/{chunk-WRCXRV2U.js → chunk-P7732A25.js} +10 -0
  27. package/dist/{chunk-6RRG3WOE.js → chunk-Q35TWISF.js} +22 -1
  28. package/dist/{chunk-WA7IBNIL.js → chunk-QBYJNGCD.js} +2 -2
  29. package/dist/chunk-QWTBYXHN.js +751 -0
  30. package/dist/{chunk-SC2DBY2R.js → chunk-R4DUO5DA.js} +1 -0
  31. package/dist/{chunk-2Y27P6KC.js → chunk-SGTTC2JP.js} +4 -3
  32. package/dist/{chunk-TICKIKCQ.js → chunk-U23SLQGX.js} +5 -5
  33. package/dist/chunk-UATQQDVR.js +297 -0
  34. package/dist/{chunk-3YTFXTXH.js → chunk-UXQH2CNC.js} +2 -1
  35. package/dist/{chunk-VBQHBSIB.js → chunk-VJWWJA36.js} +3 -3
  36. package/dist/{chunk-OQNJRQPZ.js → chunk-W3ZJVBNY.js} +7 -4
  37. package/dist/{chunk-XDCCYBCJ.js → chunk-ZMYV6PRE.js} +13 -0
  38. package/dist/{commands-3O2HFLTW.js → commands-NL6UOEP7.js} +51 -17
  39. package/dist/{conflicts-UY6VTYIO.js → conflicts-XMN4PBCZ.js} +8 -8
  40. package/dist/{contribute-RF47NPZ2.js → contribute-QDTEJ42W.js} +4 -4
  41. package/dist/{countdown-JX3DZ2QU.js → countdown-7ONIVAG6.js} +40 -12
  42. package/dist/{dashboard-YNCFISNO.js → dashboard-P65XHYCU.js} +1 -1
  43. package/dist/{dashboard-broadcast-NK7PU72L.js → dashboard-broadcast-GYK34QYL.js} +1 -1
  44. package/dist/{diff-SVFAUOVP.js → diff-RLB7R2NE.js} +5 -5
  45. package/dist/{doctor-ATKYRCT4.js → doctor-OXMDSOXL.js} +11 -11
  46. package/dist/{engine-info-R6GXZ2VO.js → engine-info-BBI5QO5Y.js} +3 -3
  47. package/dist/{ground-control-D2X6CI66.js → ground-control-IDCXN5FK.js} +5 -5
  48. package/dist/hook-B4VUQOQF.js +108 -0
  49. package/dist/index.js +28 -28
  50. package/dist/{init-LUJRWMHC.js → init-BYONEUCW.js} +14 -14
  51. package/dist/{install-VQSO2JR7.js → install-HOR6VR44.js} +14 -14
  52. package/dist/{mission-control-JIF6GFSV.js → mission-control-QJBSZVNI.js} +2 -2
  53. package/dist/{queue-IEOXOBNL.js → queue-OJHKFKK3.js} +55 -11
  54. package/dist/{run-L63NZHAJ.js → run-PFANZJ5Y.js} +175 -27
  55. package/dist/{run-plan-BWJX6R7Q.js → run-plan-7EB4ERSQ.js} +46 -16
  56. package/dist/{scan-BWA64R7I.js → scan-K3T5RQLC.js} +1 -1
  57. package/dist/session-start-OSFSF4OZ.js +74 -0
  58. package/dist/sessions-WQU5DONU.js +102 -0
  59. package/dist/{setup-global-2X5TMDCB.js → setup-global-O34KFL2C.js} +6 -6
  60. package/dist/{status-MOOZCB5D.js → status-QB2FFYUP.js} +8 -8
  61. package/dist/{update-NMSO56CQ.js → update-N2EKKSE7.js} +16 -11
  62. package/package.json +1 -1
  63. package/dist/sessions-O7MYEMCT.js +0 -343
@@ -2,12 +2,13 @@ import {
2
2
  CLAUDE_SETTINGS_REL,
3
3
  GUARD_SHELL_HOOK_MARKER,
4
4
  RESOLVE_AGENT_KIT_REL,
5
- SESSION_START_HOOK_MARKER
6
- } from "./chunk-4DLMU44M.js";
5
+ SESSION_START_HOOK_MARKER,
6
+ mergeAllowRowsWithoutGuard
7
+ } from "./chunk-EBDQYFA4.js";
7
8
  import {
8
9
  CLAUDE_COMMANDS_DIR_REL,
9
10
  discoverInstalledCommands
10
- } from "./chunk-3YTFXTXH.js";
11
+ } from "./chunk-UXQH2CNC.js";
11
12
  import {
12
13
  findOnPath
13
14
  } from "./chunk-WGLPZXNU.js";
@@ -20,7 +21,7 @@ import {
20
21
  REQUIRED_SECRET_PATTERNS,
21
22
  detectGitDirty,
22
23
  runScanner
23
- } from "./chunk-SC2DBY2R.js";
24
+ } from "./chunk-R4DUO5DA.js";
24
25
  import {
25
26
  CONTEXT_CONFIG_REL,
26
27
  contextConfigPath
@@ -37,6 +38,7 @@ import { execFile } from "child_process";
37
38
  import { access, constants, readdir, readFile, stat } from "fs/promises";
38
39
  import path from "path";
39
40
  import { promisify } from "util";
41
+ var CLAUDE_SETTINGS_LOCAL_REL = ".claude/settings.local.json";
40
42
  var execFileAsync = promisify(execFile);
41
43
  var GIT_HOOK_CANONICAL_NAMES = ["pre-commit", "pre-push", "prepare-commit-msg"];
42
44
  var EXPECTED_EVENTS = [
@@ -168,6 +170,22 @@ async function assessClaudeCommandAdapters(rootDir) {
168
170
  `Claude Code command adapters missing: ${missing.length} of ${sources.length} installed kit commands have no \`.claude/commands/<name>.md\` (${shown.join(", ")}${more}), so they are not recognized as slash commands. Run \`agent-kit update --claude\` to generate them (writes only \`.claude/commands/*\`).`
169
171
  ];
170
172
  }
173
+ async function assessClaudeMergeAllowGuard(rootDir) {
174
+ const root = path.resolve(rootDir);
175
+ const files = [CLAUDE_SETTINGS_REL, CLAUDE_SETTINGS_LOCAL_REL];
176
+ const parsed = [];
177
+ for (const rel of files) {
178
+ try {
179
+ parsed.push(JSON.parse(await readFile(path.join(root, rel), "utf8")));
180
+ } catch {
181
+ }
182
+ }
183
+ const rows = mergeAllowRowsWithoutGuard(...parsed);
184
+ if (rows.length === 0) return [];
185
+ return [
186
+ `Claude merge allow rows without the guard hook: ${rows.map((r) => `\`${r}\``).join(", ")} in ${files.map((f) => `\`${f}\``).join(" / ")} skip the merge prompt, but no PreToolUse(Bash) \`agent-kit guard shell\` hook is wired, so nothing denies a merge into main/master/prod (the rows rely on guard rule \`pr-merge-protected-base\`). Run \`agent-kit install --claude\` (or add the hook back by hand if you removed it) or remove the rows.`
187
+ ];
188
+ }
171
189
  async function resolveGuardProbeArgv(root) {
172
190
  const hookBin = process.env.AGENT_KIT_HOOK_BIN;
173
191
  if (hookBin && await isExecutable(hookBin)) return [hookBin];
@@ -227,6 +245,7 @@ async function assessHooksHealth(rootDir) {
227
245
  const reasons = [];
228
246
  const wiredEvents = [];
229
247
  const advisories = [
248
+ ...await assessClaudeMergeAllowGuard(root),
230
249
  ...await assessGitHooksInstallDrift(root),
231
250
  ...await assessSignatureGateHook(root),
232
251
  ...await assessClaudeGuardProbe(root),
@@ -4,10 +4,10 @@ import {
4
4
  import {
5
5
  claudeRedactions,
6
6
  redactSecrets
7
- } from "./chunk-OQNJRQPZ.js";
7
+ } from "./chunk-W3ZJVBNY.js";
8
8
  import {
9
9
  findHitlGateInText
10
- } from "./chunk-WRCXRV2U.js";
10
+ } from "./chunk-P7732A25.js";
11
11
  import {
12
12
  findOnPath
13
13
  } from "./chunk-WGLPZXNU.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  whichBinary
3
- } from "./chunk-OQNJRQPZ.js";
3
+ } from "./chunk-W3ZJVBNY.js";
4
4
 
5
5
  // src/plan-loop/detect.ts
6
6
  var DETECT_ORDER = ["cursor-agent", "claude"];
@@ -64,6 +64,8 @@ async function detectAgentBackend(requested, whichFn = whichBinary) {
64
64
  }
65
65
 
66
66
  export {
67
+ isBackendId,
68
+ isRequestedBackend,
67
69
  listDetectBackendIds,
68
70
  detectAgentBackend
69
71
  };
@@ -0,0 +1,433 @@
1
+ import {
2
+ HANDOFF_REL
3
+ } from "./chunk-C4Q77GGJ.js";
4
+
5
+ // src/plan-loop/queue-lease.ts
6
+ import { randomUUID } from "crypto";
7
+ import { linkSync, mkdirSync, readFileSync, renameSync, unlinkSync, writeFileSync } from "fs";
8
+ import { hostname } from "os";
9
+ import path from "path";
10
+ var QUEUE_LEASE_RELPATH = ".cursor/context/run-plan-all.lock";
11
+ var QUEUE_LEASE_HEARTBEAT_MS = 3e4;
12
+ var QUEUE_LEASE_TTL_MS = 12e4;
13
+ var QUEUE_LEASE_INTERRUPT_WAIT_MS = 2e3;
14
+ var QUEUE_LEASE_SESSION_ENV = "AGENT_KIT_QUEUE_LEASE_SESSION";
15
+ function decideQueueLease(lease, probe) {
16
+ if (lease === null) return { kind: "free" };
17
+ if (lease === "corrupt") return { kind: "stale", lease: null, reason: "unreadable lease file" };
18
+ if (probe.session && probe.session === lease.session) return { kind: "own", lease };
19
+ const ttl = probe.ttlMs ?? QUEUE_LEASE_TTL_MS;
20
+ const beat = Date.parse(lease.heartbeatAt);
21
+ const fresh = Number.isFinite(beat) && probe.now - beat <= ttl;
22
+ if (lease.host !== probe.host) {
23
+ return fresh ? {
24
+ kind: "held",
25
+ lease,
26
+ orphan: false,
27
+ reason: `held by host ${lease.host} (fresh heartbeat)`
28
+ } : { kind: "stale", lease, reason: `heartbeat expired (host ${lease.host})` };
29
+ }
30
+ const dispatcherAlive = probe.alive(lease.dispatcher);
31
+ const agentAlive = lease.agent !== null && probe.alive(lease.agent);
32
+ if (agentAlive && !dispatcherAlive) {
33
+ return {
34
+ kind: "held",
35
+ lease,
36
+ orphan: true,
37
+ reason: `orphaned agent pid ${lease.agent?.pid} is still running (dispatcher pid ${lease.dispatcher.pid} is gone)`
38
+ };
39
+ }
40
+ if (agentAlive && !fresh) {
41
+ return {
42
+ kind: "held",
43
+ lease,
44
+ orphan: true,
45
+ reason: `agent pid ${lease.agent?.pid} is still running under an unresponsive dispatcher (pid ${lease.dispatcher.pid}, heartbeat expired)`
46
+ };
47
+ }
48
+ if (dispatcherAlive && fresh) {
49
+ return {
50
+ kind: "held",
51
+ lease,
52
+ orphan: false,
53
+ reason: `held by dispatcher pid ${lease.dispatcher.pid}`
54
+ };
55
+ }
56
+ if (!dispatcherAlive) {
57
+ return { kind: "stale", lease, reason: `dispatcher pid ${lease.dispatcher.pid} is gone` };
58
+ }
59
+ return {
60
+ kind: "stale",
61
+ lease,
62
+ reason: `heartbeat expired (dispatcher pid ${lease.dispatcher.pid})`
63
+ };
64
+ }
65
+ function formatQueueLeaseRefusal(v) {
66
+ const l = v.lease;
67
+ const who = [
68
+ `dispatcher pid ${l.dispatcher.pid}`,
69
+ l.agent ? `agent pid ${l.agent.pid}` : "no agent yet",
70
+ `session ${l.session}`,
71
+ `host ${l.host}`,
72
+ `started ${l.startedAt}`,
73
+ `last heartbeat ${l.heartbeatAt}`
74
+ ].join(", ");
75
+ const next = v.orphan ? `It may still be writing this repository. Check it (ps -o pid,etime,args -p ${l.agent?.pid}), stop it, then start /run-plan-all again.` : "Wait for that session to end (or stop it from the window that started it), then start /run-plan-all again.";
76
+ return `Queue lease held: another /run-plan-all owns this queue (${v.reason}; ${who}). ${next}`;
77
+ }
78
+ function procStart(pid) {
79
+ if (process.platform !== "linux") return null;
80
+ const stat = procStat(pid);
81
+ return stat?.start ?? null;
82
+ }
83
+ function procStat(pid) {
84
+ try {
85
+ const text = readFileSync(`/proc/${pid}/stat`, "utf8");
86
+ const fields = text.slice(text.lastIndexOf(")") + 2).split(" ");
87
+ const state = fields[0];
88
+ const ppid = Number(fields[1]);
89
+ const start = fields[19];
90
+ return state && start ? { state, ppid, start } : null;
91
+ } catch {
92
+ return null;
93
+ }
94
+ }
95
+ function procParent(pid) {
96
+ if (process.platform !== "linux") return null;
97
+ return procStat(pid)?.ppid ?? null;
98
+ }
99
+ function processAlive(proc) {
100
+ if (!Number.isInteger(proc.pid) || proc.pid <= 1) return false;
101
+ try {
102
+ process.kill(proc.pid, 0);
103
+ } catch (err) {
104
+ if (err.code !== "EPERM") return false;
105
+ }
106
+ if (process.platform !== "linux") return true;
107
+ const stat = procStat(proc.pid);
108
+ if (!stat) return false;
109
+ if (stat.state === "Z" || stat.state === "X") return false;
110
+ return proc.start === null || proc.start === stat.start;
111
+ }
112
+ function queueLeasePath(root) {
113
+ return path.join(root, QUEUE_LEASE_RELPATH);
114
+ }
115
+ function readQueueLease(root) {
116
+ let text;
117
+ try {
118
+ text = readFileSync(queueLeasePath(root), "utf8");
119
+ } catch (err) {
120
+ if (err.code === "ENOENT") return null;
121
+ return "corrupt";
122
+ }
123
+ try {
124
+ const v = JSON.parse(text);
125
+ const okProc = (p) => !!p && typeof p.pid === "number";
126
+ if (v.version !== 1 || typeof v.session !== "string" || typeof v.host !== "string" || !okProc(v.dispatcher) || v.agent !== null && !okProc(v.agent) || typeof v.startedAt !== "string" || typeof v.heartbeatAt !== "string") {
127
+ return "corrupt";
128
+ }
129
+ return v;
130
+ } catch {
131
+ return "corrupt";
132
+ }
133
+ }
134
+ function leaseTmp(root, lease) {
135
+ const tmp = `${queueLeasePath(root)}.${process.pid}.${randomUUID().slice(0, 8)}.tmp`;
136
+ writeFileSync(tmp, `${JSON.stringify(lease, null, 2)}
137
+ `, "utf8");
138
+ return tmp;
139
+ }
140
+ function writeLeaseAtomic(root, lease) {
141
+ renameSync(leaseTmp(root, lease), queueLeasePath(root));
142
+ }
143
+ function createLeaseExclusive(root, lease) {
144
+ const tmp = leaseTmp(root, lease);
145
+ try {
146
+ linkSync(tmp, queueLeasePath(root));
147
+ return true;
148
+ } catch (err) {
149
+ if (err.code === "EEXIST") return false;
150
+ throw err;
151
+ } finally {
152
+ try {
153
+ unlinkSync(tmp);
154
+ } catch {
155
+ }
156
+ }
157
+ }
158
+ function pauseMs(ms) {
159
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
160
+ }
161
+ var QUEUE_LEASE_TAKEOVER_SETTLE_MS = 150;
162
+ function inspectQueueLease(root, env = {}) {
163
+ return decideQueueLease(readQueueLease(root), {
164
+ host: env.host ?? hostname(),
165
+ now: (env.now ?? Date.now)(),
166
+ alive: env.alive ?? processAlive,
167
+ session: env.callerSession ?? process.env[QUEUE_LEASE_SESSION_ENV],
168
+ ttlMs: env.ttlMs
169
+ });
170
+ }
171
+ function acquireQueueLease(root, env = {}) {
172
+ const now = env.now ?? Date.now;
173
+ const host = env.host ?? hostname();
174
+ const pid = env.pid ?? process.pid;
175
+ const startOf = env.procStart ?? procStart;
176
+ const alive = env.alive ?? processAlive;
177
+ const session = env.session ?? randomUUID();
178
+ const iso = () => new Date(now()).toISOString();
179
+ const file = queueLeasePath(root);
180
+ mkdirSync(path.dirname(file), { recursive: true });
181
+ let lease = {
182
+ version: 1,
183
+ session,
184
+ host,
185
+ dispatcher: { pid, start: startOf(pid) },
186
+ agent: null,
187
+ startedAt: iso(),
188
+ heartbeatAt: iso()
189
+ };
190
+ let takeover = null;
191
+ if (!createLeaseExclusive(root, lease)) {
192
+ const verdict = decideQueueLease(readQueueLease(root), {
193
+ host,
194
+ now: now(),
195
+ alive,
196
+ ttlMs: env.ttlMs
197
+ });
198
+ if (verdict.kind === "held") {
199
+ return { ok: false, verdict, message: formatQueueLeaseRefusal(verdict) };
200
+ }
201
+ writeLeaseAtomic(root, lease);
202
+ pauseMs(env.settleMs ?? QUEUE_LEASE_TAKEOVER_SETTLE_MS);
203
+ const back = readQueueLease(root);
204
+ if (back === null || back === "corrupt" || back.session !== session) {
205
+ const held = {
206
+ kind: "held",
207
+ lease: back !== null && back !== "corrupt" ? back : lease,
208
+ orphan: false,
209
+ reason: "another dispatcher took over the stale lease first"
210
+ };
211
+ return { ok: false, verdict: held, message: formatQueueLeaseRefusal(held) };
212
+ }
213
+ takeover = verdict.kind === "stale" ? verdict : { kind: "stale", lease: null, reason: "lease file vanished" };
214
+ logQueueLeaseTakeover(root, takeover, { at: iso(), pid, session, holder: env.holder });
215
+ }
216
+ let released = false;
217
+ let lost = false;
218
+ const mine = () => {
219
+ const cur = readQueueLease(root);
220
+ if (cur !== null && cur !== "corrupt" && cur.session === session) return true;
221
+ if (!lost) {
222
+ lost = true;
223
+ env.onLost?.(cur !== null && cur !== "corrupt" ? cur : null);
224
+ }
225
+ return false;
226
+ };
227
+ const write = (next) => {
228
+ if (released || lost || !mine()) return;
229
+ lease = next;
230
+ writeLeaseAtomic(root, lease);
231
+ };
232
+ const timer = setInterval(() => {
233
+ try {
234
+ write({ ...lease, heartbeatAt: iso() });
235
+ } catch {
236
+ }
237
+ }, env.heartbeatMs ?? QUEUE_LEASE_HEARTBEAT_MS);
238
+ timer.unref();
239
+ let agent = null;
240
+ const release = () => {
241
+ if (released) return;
242
+ released = true;
243
+ clearInterval(timer);
244
+ try {
245
+ const cur = readQueueLease(root);
246
+ if (cur !== null && cur !== "corrupt" && cur.session === session) unlinkSync(file);
247
+ } catch {
248
+ }
249
+ };
250
+ const handle = {
251
+ session,
252
+ takeover,
253
+ setAgent: (agentPid) => {
254
+ if (agentPid === void 0) return;
255
+ agent = { pid: agentPid, start: startOf(agentPid) };
256
+ write({ ...lease, agent, heartbeatAt: iso() });
257
+ },
258
+ agent: () => agent,
259
+ beat: () => write({ ...lease, heartbeatAt: iso() }),
260
+ held: () => !released && !lost && mine(),
261
+ release,
262
+ releaseAfterAgent: (waitMs) => {
263
+ const deadline = now() + waitMs;
264
+ while (agent !== null && alive(agent) && now() < deadline) pauseMs(50);
265
+ if (agent !== null && alive(agent)) {
266
+ clearInterval(timer);
267
+ return false;
268
+ }
269
+ release();
270
+ return true;
271
+ }
272
+ };
273
+ return { ok: true, handle };
274
+ }
275
+ function logQueueLeaseTakeover(root, verdict, by) {
276
+ const file = path.join(root, HANDOFF_REL);
277
+ let text;
278
+ try {
279
+ text = readFileSync(file, "utf8");
280
+ } catch {
281
+ return null;
282
+ }
283
+ const old = verdict.lease;
284
+ const from = old ? `dispatcher pid ${old.dispatcher.pid}${old.agent ? `, agent pid ${old.agent.pid}` : ""}, session ${old.session}, host ${old.host}, started ${old.startedAt}, last heartbeat ${old.heartbeatAt}` : "no readable owner";
285
+ const line = `- **Queue lease takeover ${by.at} (${by.holder ?? "agent-kit run-plan-all"}, pid ${by.pid}, session ${by.session}):** took over a stale queue lease (${verdict.reason}; ${from}). Check the old owner's worktrees before resuming its rows.`;
286
+ const nl = text.indexOf("\n");
287
+ const next = nl === -1 ? `${text}
288
+ ${line}
289
+ ` : `${text.slice(0, nl + 1)}${line}
290
+ ${text.slice(nl + 1)}`;
291
+ writeFileSync(file, next, "utf8");
292
+ return line;
293
+ }
294
+ var LEASE_FREE_SLASHES = /* @__PURE__ */ new Set([
295
+ "summary",
296
+ "context-status",
297
+ "tips",
298
+ "review-pack",
299
+ "resolve-conflicts"
300
+ ]);
301
+ function nestedUnderLease(root, probe = {}) {
302
+ const session = probe.session ?? process.env[QUEUE_LEASE_SESSION_ENV];
303
+ if (!session) return null;
304
+ const lease = readQueueLease(root);
305
+ if (lease === null || lease === "corrupt" || lease.session !== session) return null;
306
+ const verdict = decideQueueLease(lease, {
307
+ host: probe.host ?? hostname(),
308
+ now: probe.now ?? Date.now(),
309
+ alive: probe.alive ?? processAlive,
310
+ ttlMs: probe.ttlMs
311
+ });
312
+ if (verdict.kind !== "held") return null;
313
+ const canCheck = probe.canCheckAncestry ?? process.platform === "linux";
314
+ if (!canCheck) return lease;
315
+ const parentOf = probe.parentOf ?? procParent;
316
+ const holders = /* @__PURE__ */ new Set([lease.dispatcher.pid, ...lease.agent ? [lease.agent.pid] : []]);
317
+ let p = probe.pid ?? process.pid;
318
+ for (let guard = 0; p !== null && p > 1 && guard < 128; guard++) {
319
+ if (holders.has(p)) return lease;
320
+ p = parentOf(p);
321
+ }
322
+ return null;
323
+ }
324
+ function formatPlanWriterRefusal(v, command) {
325
+ const l = v.lease;
326
+ const who = [
327
+ `dispatcher pid ${l.dispatcher.pid}`,
328
+ l.agent ? `agent pid ${l.agent.pid}` : "no agent yet",
329
+ `session ${l.session}`,
330
+ `host ${l.host}`,
331
+ `started ${l.startedAt}`
332
+ ].join(", ");
333
+ const next = v.orphan ? `It may still be writing this repository. Check it (ps -o pid,etime,args -p ${l.agent?.pid}), stop it, then start ${command} again.` : `Wait for that session to end (agent-kit sessions --live shows it), then start ${command} again.`;
334
+ return `Queue lease held: another live session writes this workspace's plans (${v.reason}; ${who}). ${command} did not start. ${next}`;
335
+ }
336
+ function gateCheckIn(root, session, env = {}) {
337
+ return () => {
338
+ try {
339
+ const v = inspectQueueLease(root, { ...env, callerSession: session() ?? void 0 });
340
+ if (v.kind !== "held") return null;
341
+ return `Queue lease held: another live session writes this workspace's plans (${v.reason}; session ${v.lease.session}); check with agent-kit sessions --live`;
342
+ } catch {
343
+ return null;
344
+ }
345
+ };
346
+ }
347
+ function acquirePlanWriterLease(root, command, env = {}) {
348
+ const nested = nestedUnderLease(root, {
349
+ host: env.host,
350
+ now: env.now?.(),
351
+ alive: env.alive,
352
+ ttlMs: env.ttlMs,
353
+ pid: env.pid,
354
+ ...env.nested
355
+ });
356
+ if (nested) return { kind: "nested", lease: nested };
357
+ const acquired = acquireQueueLease(root, { ...env, holder: env.holder ?? command });
358
+ if (acquired.ok) return { kind: "acquired", handle: acquired.handle };
359
+ return { kind: "refused", message: formatPlanWriterRefusal(acquired.verdict, command) };
360
+ }
361
+ var QUEUE_STATUS_LINE = /^- \*\*Queue status:\*\*[ \t]*(.*)$/m;
362
+ function holdQueueStatus(root, by) {
363
+ const file = path.join(root, HANDOFF_REL);
364
+ let text;
365
+ try {
366
+ text = readFileSync(file, "utf8");
367
+ } catch {
368
+ return null;
369
+ }
370
+ const m = QUEUE_STATUS_LINE.exec(text);
371
+ if (!m) return null;
372
+ const previous = (m[1] ?? "").trim();
373
+ if (!/^(running|paused)\b/i.test(previous)) return null;
374
+ const original = m[0];
375
+ const held = `- **Queue status:** held (by ${by.plan}, ${by.who}, ${by.at}; was ${previous})`;
376
+ writeFileSync(
377
+ file,
378
+ text.replace(original, () => held),
379
+ "utf8"
380
+ );
381
+ return () => {
382
+ try {
383
+ const now = readFileSync(file, "utf8");
384
+ const cur = QUEUE_STATUS_LINE.exec(now);
385
+ if (!cur || cur[0] !== held) return false;
386
+ writeFileSync(
387
+ file,
388
+ now.replace(held, () => original),
389
+ "utf8"
390
+ );
391
+ return true;
392
+ } catch {
393
+ return false;
394
+ }
395
+ };
396
+ }
397
+ function forwardTermination(agent, onExit, opts = {}) {
398
+ const kill = opts.kill ?? ((p, s) => {
399
+ process.kill(p, s);
400
+ });
401
+ const isAlive = opts.alive ?? processAlive;
402
+ const handler = (signal) => {
403
+ const proc = agent();
404
+ if (proc && proc.pid > 1 && isAlive(proc)) {
405
+ try {
406
+ kill(proc.pid, "SIGTERM");
407
+ } catch {
408
+ }
409
+ }
410
+ onExit(signal);
411
+ };
412
+ const signals = opts.signals ?? ["SIGTERM", "SIGHUP"];
413
+ const listeners = signals.map((sig) => [sig, () => handler(sig)]);
414
+ for (const [sig, fn] of listeners) process.on(sig, fn);
415
+ return () => {
416
+ for (const [sig, fn] of listeners) process.off(sig, fn);
417
+ };
418
+ }
419
+
420
+ export {
421
+ QUEUE_LEASE_RELPATH,
422
+ QUEUE_LEASE_INTERRUPT_WAIT_MS,
423
+ QUEUE_LEASE_SESSION_ENV,
424
+ formatQueueLeaseRefusal,
425
+ procStart,
426
+ inspectQueueLease,
427
+ acquireQueueLease,
428
+ LEASE_FREE_SLASHES,
429
+ gateCheckIn,
430
+ acquirePlanWriterLease,
431
+ holdQueueStatus,
432
+ forwardTermination
433
+ };
@@ -1,13 +1,15 @@
1
1
  import {
2
2
  INTERACTIVE_ALLOW_RULES,
3
- INTERACTIVE_DENY_RULES
4
- } from "./chunk-6RRG3WOE.js";
3
+ INTERACTIVE_DENY_RULES,
4
+ isMergeAllowRow,
5
+ permissionRowControl
6
+ } from "./chunk-Q35TWISF.js";
5
7
  import {
6
8
  assertRealContained,
7
9
  assertRealParentContained,
8
10
  isRealWriteTargetContained,
9
11
  resolveContained
10
- } from "./chunk-5IJQGIOY.js";
12
+ } from "./chunk-677W4QO3.js";
11
13
  import {
12
14
  ensureDir
13
15
  } from "./chunk-5B4DVO6C.js";
@@ -297,6 +299,63 @@ function instructionsBlock(entry) {
297
299
  JSON.stringify(buildGuardShellHookEntry(), null, 2)
298
300
  ].join("\n");
299
301
  }
302
+ function permissionRowsOf(root, kind) {
303
+ if (!isPlainObject(root) || !isPlainObject(root.permissions)) return [];
304
+ const list = root.permissions[kind];
305
+ return Array.isArray(list) ? list.filter((x) => typeof x === "string") : [];
306
+ }
307
+ function parseSettingsObject(raw) {
308
+ if (raw === null || raw.trim() === "") return {};
309
+ try {
310
+ const parsed = JSON.parse(raw);
311
+ return isPlainObject(parsed) ? parsed : {};
312
+ } catch {
313
+ return {};
314
+ }
315
+ }
316
+ function diffPermissionRows(beforeRaw, afterRaw) {
317
+ const before = parseSettingsObject(beforeRaw);
318
+ const after = parseSettingsObject(afterRaw);
319
+ const changes = [];
320
+ for (const kind of ["allow", "deny"]) {
321
+ const had = permissionRowsOf(before, kind);
322
+ const has = permissionRowsOf(after, kind);
323
+ for (const row of has) if (!had.includes(row)) changes.push({ change: "added", kind, row });
324
+ for (const row of had) if (!has.includes(row)) changes.push({ change: "removed", kind, row });
325
+ }
326
+ return changes;
327
+ }
328
+ function settingsHaveGuardHook(root) {
329
+ if (!isPlainObject(root) || !isPlainObject(root.hooks)) return false;
330
+ const groups = root.hooks.PreToolUse;
331
+ if (!Array.isArray(groups)) return false;
332
+ return groups.some((g) => {
333
+ if (!isPlainObject(g)) return false;
334
+ const matcher = g.matcher;
335
+ const coversBash = matcher === void 0 || matcher === "" || matcher === "*" || typeof matcher === "string" && /\bBash\b/.test(matcher);
336
+ return coversBash && groupHasMarker(g, GUARD_SHELL_HOOK_MARKER);
337
+ });
338
+ }
339
+ function mergeAllowRowsWithoutGuard(...roots) {
340
+ if (roots.some(settingsHaveGuardHook)) return [];
341
+ return roots.flatMap((r) => permissionRowsOf(r, "allow")).filter(isMergeAllowRow);
342
+ }
343
+ function formatPermissionsChanged(changes, opts) {
344
+ if (changes.length === 0) return [];
345
+ const unguarded = new Set(opts.mergeAllowWithoutGuard);
346
+ const lines = [`Permissions changed in ${CLAUDE_SETTINGS_REL}:`];
347
+ for (const c of changes) {
348
+ const sign = c.change === "added" ? "+" : "-";
349
+ const note = c.change === "removed" ? "removed" : unguarded.has(c.row) ? "no guard hook in this file: nothing denies a merge into main" : permissionRowControl(c.kind, c.row);
350
+ lines.push(` ${sign} ${c.kind} ${c.row} -- ${note}`);
351
+ }
352
+ if (unguarded.size > 0) {
353
+ lines.push(
354
+ ` WARNING: merge allow rows without the PreToolUse(Bash) \`agent-kit guard shell\` hook (guard rule \`pr-merge-protected-base\`): a merge into main/master/prod runs without a prompt. Add the guard hook back to ${CLAUDE_SETTINGS_REL} by hand or remove these rows.`
355
+ );
356
+ }
357
+ return lines;
358
+ }
300
359
  async function writeClaudeSessionStartHook(rootDir, opts = {}) {
301
360
  const authorized = opts.authorized ?? true;
302
361
  const abs = resolveContained(rootDir, CLAUDE_SETTINGS_REL);
@@ -330,9 +389,12 @@ async function writeClaudeSessionStartHook(rootDir, opts = {}) {
330
389
  await ensureDir(path2.dirname(abs));
331
390
  await writeFile2(abs, merged.content, "utf8");
332
391
  }
392
+ const written = parseSettingsObject(merged.content);
333
393
  const result = {
334
394
  relativePath: CLAUDE_SETTINGS_REL,
335
- status: merged.status
395
+ status: merged.status,
396
+ permissionChanges: diffPermissionRows(existing, merged.content),
397
+ mergeAllowWithoutGuard: mergeAllowRowsWithoutGuard(written)
336
398
  };
337
399
  if (merged.pending && (merged.pending.denyRows.length || merged.pending.allowRows.length || merged.pending.hookEntries.length)) {
338
400
  result.pending = merged.pending;
@@ -421,6 +483,9 @@ function formatClaudeSettingsDrift(report, opts) {
421
483
  const allowRows = [...report.allowRows, ...report.ambiguousAllowRows];
422
484
  if (allowRows.length > 0) {
423
485
  lines.push("Add to permissions.allow:", JSON.stringify(allowRows, null, 2));
486
+ for (const note of new Set(allowRows.map((row) => permissionRowControl("allow", row)))) {
487
+ lines.push(`(allow rows: ${note})`);
488
+ }
424
489
  if (report.ambiguousAllowRows.length > 0) {
425
490
  lines.push(
426
491
  `(${report.ambiguousAllowRows.length} row(s) ambiguous: no ${CLAUDE_SETTINGS_LEDGER_REL} ledger, so a deliberate deletion cannot be told apart.)`
@@ -440,6 +505,8 @@ export {
440
505
  RESOLVE_AGENT_KIT_REL,
441
506
  SESSION_START_HOOK_MARKER,
442
507
  GUARD_SHELL_HOOK_MARKER,
508
+ mergeAllowRowsWithoutGuard,
509
+ formatPermissionsChanged,
443
510
  writeClaudeSessionStartHook,
444
511
  planClaudeSettingsDrift,
445
512
  formatClaudeSettingsDrift
@@ -7,7 +7,7 @@ import {
7
7
  loadRegistry,
8
8
  packMemberFileTargets,
9
9
  skillFileTargets
10
- } from "./chunk-IOQ6YXA3.js";
10
+ } from "./chunk-3HNTNYPR.js";
11
11
 
12
12
  // src/lifecycle/targets.ts
13
13
  import path from "path";
@@ -2,7 +2,7 @@ import {
2
2
  compareSemver,
3
3
  normalizeSemver,
4
4
  readLocalKitVersion
5
- } from "./chunk-AZCPUJJO.js";
5
+ } from "./chunk-IQQQDEQ4.js";
6
6
  import {
7
7
  L0_ARTIFACTS
8
8
  } from "./chunk-WS6OX2IG.js";
@@ -15,11 +15,11 @@ import {
15
15
  mergeStats,
16
16
  recordOutcome,
17
17
  resolveProtectedGlobs
18
- } from "./chunk-IOQ6YXA3.js";
18
+ } from "./chunk-3HNTNYPR.js";
19
19
  import {
20
20
  loadManagedHashLedger,
21
21
  saveManagedHashLedger
22
- } from "./chunk-5IJQGIOY.js";
22
+ } from "./chunk-677W4QO3.js";
23
23
  import {
24
24
  KIT_PACKAGE_SPEC,
25
25
  KIT_VERSION
@@ -5,7 +5,7 @@ import {
5
5
  DEFAULT_REGISTRY_REF,
6
6
  DEFAULT_REGISTRY_URL,
7
7
  resolveRegistryRoot
8
- } from "./chunk-IOQ6YXA3.js";
8
+ } from "./chunk-3HNTNYPR.js";
9
9
 
10
10
  // src/lifecycle/resolve-cli.ts
11
11
  async function resolveRegistryFromCli(options) {