@dadado/agent-kit-cli 6.18.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 (62) 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-JZKFUH2O.js → add-MRI5BXHH.js} +3 -3
  7. package/dist/{chunk-OKIFM3IH.js → chunk-2TX6NJEG.js} +1 -1
  8. package/dist/{chunk-VRSBZKTA.js → chunk-3HNTNYPR.js} +1 -1
  9. package/dist/{chunk-H5D3HF2N.js → chunk-5EBT3V7G.js} +1 -1
  10. package/dist/{chunk-B4MUKUVS.js → chunk-677W4QO3.js} +58 -1
  11. package/dist/{chunk-SKC6QZW4.js → chunk-6WUKLS4D.js} +1 -1
  12. package/dist/{chunk-CRH2Q6KY.js → chunk-6XJZLH53.js} +149 -18
  13. package/dist/{chunk-UEW42NIF.js → chunk-7MUTZHWP.js} +3 -3
  14. package/dist/{chunk-L7BL4246.js → chunk-BGL5DRK2.js} +2 -2
  15. package/dist/{chunk-44SDKJYY.js → chunk-C4LCOOL4.js} +3 -1
  16. package/dist/chunk-DTSL2RH7.js +433 -0
  17. package/dist/{chunk-XHANIDPK.js → chunk-EBDQYFA4.js} +1 -1
  18. package/dist/{chunk-YP5OCR4I.js → chunk-EOQMAU2J.js} +1 -1
  19. package/dist/{chunk-WJRNI5FJ.js → chunk-G2Z37XFM.js} +3 -3
  20. package/dist/{chunk-4KV3TXKC.js → chunk-GTP224FI.js} +1 -1
  21. package/dist/{chunk-357Y422W.js → chunk-HJWSOZXS.js} +52 -12
  22. package/dist/{chunk-42AA2VFW.js → chunk-IQQQDEQ4.js} +2 -2
  23. package/dist/{chunk-ZFJIJUZ4.js → chunk-MPCNPZJZ.js} +1 -1
  24. package/dist/{hook-AZ5LSJBJ.js → chunk-NL3I2BWA.js} +104 -113
  25. package/dist/{chunk-R4VLVX7B.js → chunk-OKQ37A7E.js} +9 -9
  26. package/dist/{chunk-WRCXRV2U.js → chunk-P7732A25.js} +10 -0
  27. package/dist/{chunk-BDIWC3WB.js → chunk-QBYJNGCD.js} +2 -2
  28. package/dist/chunk-QWTBYXHN.js +751 -0
  29. package/dist/{chunk-SC2DBY2R.js → chunk-R4DUO5DA.js} +1 -0
  30. package/dist/{chunk-MOJRD6HF.js → chunk-SGTTC2JP.js} +4 -3
  31. package/dist/{chunk-CTVVGKYB.js → chunk-U23SLQGX.js} +5 -5
  32. package/dist/chunk-UATQQDVR.js +297 -0
  33. package/dist/{chunk-2CBKKCVU.js → chunk-UXQH2CNC.js} +2 -1
  34. package/dist/{chunk-VY7AFID2.js → chunk-VJWWJA36.js} +3 -3
  35. package/dist/{chunk-Y7BH6KIE.js → chunk-W3ZJVBNY.js} +6 -3
  36. package/dist/{chunk-XDCCYBCJ.js → chunk-ZMYV6PRE.js} +13 -0
  37. package/dist/{commands-5P2E5LL4.js → commands-NL6UOEP7.js} +50 -16
  38. package/dist/{conflicts-A4B422EL.js → conflicts-XMN4PBCZ.js} +7 -7
  39. package/dist/{contribute-GAHG3J4Q.js → contribute-QDTEJ42W.js} +4 -4
  40. package/dist/{countdown-C6NY2TSG.js → countdown-7ONIVAG6.js} +39 -11
  41. package/dist/{dashboard-YNCFISNO.js → dashboard-P65XHYCU.js} +1 -1
  42. package/dist/{dashboard-broadcast-NK7PU72L.js → dashboard-broadcast-GYK34QYL.js} +1 -1
  43. package/dist/{diff-EYAGGEU4.js → diff-RLB7R2NE.js} +5 -5
  44. package/dist/{doctor-GOMPRU6F.js → doctor-OXMDSOXL.js} +10 -10
  45. package/dist/{engine-info-R6GXZ2VO.js → engine-info-BBI5QO5Y.js} +3 -3
  46. package/dist/{ground-control-MJGF5QRE.js → ground-control-IDCXN5FK.js} +4 -4
  47. package/dist/hook-B4VUQOQF.js +108 -0
  48. package/dist/index.js +27 -27
  49. package/dist/{init-WW5DR3DX.js → init-BYONEUCW.js} +13 -13
  50. package/dist/{install-RN2DRLK6.js → install-HOR6VR44.js} +13 -13
  51. package/dist/{mission-control-JIF6GFSV.js → mission-control-QJBSZVNI.js} +2 -2
  52. package/dist/{queue-7EBQGPPW.js → queue-OJHKFKK3.js} +54 -10
  53. package/dist/{run-GOMAHNV2.js → run-PFANZJ5Y.js} +174 -26
  54. package/dist/{run-plan-EUQ5WWF6.js → run-plan-7EB4ERSQ.js} +45 -15
  55. package/dist/{scan-BWA64R7I.js → scan-K3T5RQLC.js} +1 -1
  56. package/dist/session-start-OSFSF4OZ.js +74 -0
  57. package/dist/sessions-WQU5DONU.js +102 -0
  58. package/dist/{setup-global-DJWURJS3.js → setup-global-O34KFL2C.js} +6 -6
  59. package/dist/{status-2WYPLWTN.js → status-QB2FFYUP.js} +8 -8
  60. package/dist/{update-5VFQNBY5.js → update-N2EKKSE7.js} +10 -10
  61. package/package.json +1 -1
  62. package/dist/sessions-O7MYEMCT.js +0 -343
@@ -820,12 +820,225 @@ export function cadenceWindowIdFromNow(now = Date.now()) {
820
820
  return `w-${d.getUTCFullYear()}${p(d.getUTCMonth() + 1)}${p(d.getUTCDate())}${p(d.getUTCHours())}${p(d.getUTCMinutes())}${p(d.getUTCSeconds())}`;
821
821
  }
822
822
 
823
+ /** One `- id:` to-do row in plan frontmatter. */
824
+ const FRONTMATTER_TODO_ID_RE = /^\s*-\s+id:\s*(\S+)\s*$/;
825
+ /** `evidence:` key inside a to-do row. */
826
+ const FRONTMATTER_EVIDENCE_RE = /^\s*evidence:\s*(.*)$/;
827
+ /** Structured PR ref: `<repo>#<n>` with no space (`agent-kit-dev#1484`, `colony#125`). */
828
+ const EVIDENCE_STRUCTURED_PR_RE = /(?<![\w#/.-])([A-Za-z][A-Za-z0-9._-]*)#(\d+)\b/g;
829
+ /** Prose fallback PR ref: a bare `#<n>` (older plans: `PR #1361`, `Colony #114`). */
830
+ const EVIDENCE_PROSE_PR_RE = /(?<![\w#/])#(\d+)\b/g;
831
+ /** Commit SHA token: 7-40 lowercase hex holding at least one digit and one letter. */
832
+ const EVIDENCE_SHA_RE = /(?<![\w/#.-])[0-9a-f]{7,40}(?![\w-])/g;
833
+ /** Owed classifier: a plan with less of its delivered lines alive reads as rewritten. */
834
+ export const OWED_SURVIVAL_REWRITTEN_PCT = 50;
835
+ const MAX_OWED_EVIDENCE_LINE = 160;
836
+ /** Cap on per-plan evidence rows carried by the cadence attention item. */
837
+ const MAX_CADENCE_PLAN_EVIDENCE = 50;
838
+
839
+ function unquoteYamlScalar(raw) {
840
+ const v = String(raw || "").trim();
841
+ if (v.startsWith('"') && v.endsWith('"') && v.length >= 2) {
842
+ try {
843
+ return JSON.parse(v);
844
+ } catch {
845
+ return v.slice(1, -1);
846
+ }
847
+ }
848
+ if (v.startsWith("'") && v.endsWith("'") && v.length >= 2) {
849
+ return v.slice(1, -1).replace(/''/g, "'");
850
+ }
851
+ return v;
852
+ }
853
+
854
+ /**
855
+ * Per-to-do `evidence:` strings from plan frontmatter, keyed by to-do id.
856
+ * Single-line scalars only (double-quoted, single-quoted or plain); a missing
857
+ * or empty value is omitted.
858
+ * @param {string} frontmatter - text between the `---` fences
859
+ * @returns {Map<string, string>}
860
+ */
861
+ export function parseTodoEvidenceFromFrontmatter(frontmatter) {
862
+ const out = new Map();
863
+ if (typeof frontmatter !== "string" || !frontmatter) return out;
864
+ let current = null;
865
+ for (const line of frontmatter.split("\n")) {
866
+ const idMatch = FRONTMATTER_TODO_ID_RE.exec(line);
867
+ if (idMatch) {
868
+ current = idMatch[1];
869
+ continue;
870
+ }
871
+ if (!current) continue;
872
+ if (/^\S/.test(line)) {
873
+ current = null;
874
+ continue;
875
+ }
876
+ const ev = FRONTMATTER_EVIDENCE_RE.exec(line);
877
+ if (ev && !out.has(current)) {
878
+ const value = unquoteYamlScalar(ev[1]);
879
+ if (value) out.set(current, value);
880
+ }
881
+ }
882
+ return out;
883
+ }
884
+
885
+ /**
886
+ * Delivery refs in one to-do `evidence:` string. Structured `<repo>#<n>` refs
887
+ * win; a plan without them falls back to bare `#<n>` prose refs (repo null).
888
+ * SHAs are 7-40 hex tokens with a digit and a letter. Refs only: no prose
889
+ * leaves this function.
890
+ * @param {unknown} evidence
891
+ * @returns {{ prs: { repo: string|null, number: number }[], shas: string[], structured: boolean }}
892
+ */
893
+ export function parseTodoEvidenceRefs(evidence) {
894
+ const empty = { prs: [], shas: [], structured: false };
895
+ if (typeof evidence !== "string" || !evidence.trim()) return empty;
896
+ const prs = [];
897
+ const seenPr = new Set();
898
+ for (const m of evidence.matchAll(EVIDENCE_STRUCTURED_PR_RE)) {
899
+ const repo = m[1].toLowerCase();
900
+ if (repo === "pr") continue;
901
+ const key = `${repo}#${m[2]}`;
902
+ if (seenPr.has(key)) continue;
903
+ seenPr.add(key);
904
+ prs.push({ repo, number: Number(m[2]) });
905
+ }
906
+ const structured = prs.length > 0;
907
+ if (!structured) {
908
+ for (const m of evidence.matchAll(EVIDENCE_PROSE_PR_RE)) {
909
+ const key = `#${m[1]}`;
910
+ if (seenPr.has(key)) continue;
911
+ seenPr.add(key);
912
+ prs.push({ repo: null, number: Number(m[1]) });
913
+ }
914
+ }
915
+ const shas = [];
916
+ for (const m of evidence.matchAll(EVIDENCE_SHA_RE)) {
917
+ const sha = m[0];
918
+ if (!/[0-9]/.test(sha) || !/[a-f]/.test(sha) || shas.includes(sha)) continue;
919
+ shas.push(sha);
920
+ }
921
+ return { prs, shas, structured };
922
+ }
923
+
924
+ /**
925
+ * Attach `evidenceRefs` to parsed to-do items from the plan frontmatter.
926
+ * Mutates and returns `todos`; items without evidence are left unchanged.
927
+ * @param {string} frontmatter
928
+ * @param {{ id: string }[]} todos
929
+ */
930
+ export function attachTodoEvidenceRefs(frontmatter, todos) {
931
+ const evidence = parseTodoEvidenceFromFrontmatter(frontmatter);
932
+ if (evidence.size === 0) return todos;
933
+ for (const todo of todos || []) {
934
+ const text = todo && evidence.get(todo.id);
935
+ if (!text) continue;
936
+ const refs = parseTodoEvidenceRefs(text);
937
+ if (refs.prs.length > 0 || refs.shas.length > 0) todo.evidenceRefs = refs;
938
+ }
939
+ return todos;
940
+ }
941
+
942
+ /**
943
+ * Merged delivery refs of a plan's completed to-dos (structured first).
944
+ * @param {object} plan
945
+ * @returns {{ prs: { repo: string|null, number: number }[], shas: string[], structured: boolean }}
946
+ */
947
+ export function planDeliveryRefs(plan) {
948
+ const prs = [];
949
+ const shas = [];
950
+ const seenPr = new Set();
951
+ let structured = false;
952
+ for (const todo of plan?.todos?.items || []) {
953
+ if (todo?.status !== "completed") continue;
954
+ const refs = todo.evidenceRefs;
955
+ if (!refs) continue;
956
+ if (refs.structured) structured = true;
957
+ for (const pr of refs.prs || []) {
958
+ const key = `${pr.repo || ""}#${pr.number}`;
959
+ if (seenPr.has(key)) continue;
960
+ seenPr.add(key);
961
+ prs.push(pr);
962
+ }
963
+ for (const sha of refs.shas || []) {
964
+ if (!shas.includes(sha)) shas.push(sha);
965
+ }
966
+ }
967
+ return { prs, shas, structured };
968
+ }
969
+
970
+ function formatDeliveryRefs(refs) {
971
+ const parts = [];
972
+ const prs = refs.prs.slice(0, 3).map((p) => (p.repo ? `${p.repo}#${p.number}` : `#${p.number}`));
973
+ if (prs.length > 0) {
974
+ const more = refs.prs.length > 3 ? ` +${refs.prs.length - 3}` : "";
975
+ parts.push(`${prs.join(", ")}${more}`);
976
+ }
977
+ if (refs.shas.length > 0) {
978
+ const more = refs.shas.length > 2 ? ` +${refs.shas.length - 2}` : "";
979
+ parts.push(`merged ${refs.shas.slice(0, 2).join(", ")}${more}`);
980
+ }
981
+ if (parts.length === 0) return "no PR ref or merge SHA in to-do evidence";
982
+ return parts.join(" ") + (refs.structured ? "" : " (prose refs)");
983
+ }
984
+
985
+ /**
986
+ * Classify one terminal plan for the owed review set, with one evidence line.
987
+ * Reads frontmatter facts only (to-do status, structured `evidence:` refs);
988
+ * `survival` comes from the on-demand blame script and is never computed on
989
+ * the Mission Control snapshot path. A class never removes a plan from the
990
+ * owed set by itself.
991
+ * @param {object} plan
992
+ * @param {string} lifecycle - resolvePlanLifecycle result
993
+ * @param {{ survival?: { added: number, alive: number } | null }} [opts]
994
+ * @returns {{ classification: 'delivered-nothing'|'partial-parked'|'superseded-or-rewritten'|'live-unreviewed', evidenceLine: string }}
995
+ */
996
+ export function classifyOwedPlan(plan, lifecycle, opts = {}) {
997
+ const stats = todoStats(plan);
998
+ const done = `${stats.completed} of ${stats.total} to-dos completed`;
999
+ if (stats.completed === 0) {
1000
+ const why = stats.cancelled > 0 && stats.open === 0 ? "all cancelled" : "none completed";
1001
+ return { classification: "delivered-nothing", evidenceLine: `${done} (${why})` };
1002
+ }
1003
+ const refs = planDeliveryRefs(plan);
1004
+ let refsText = formatDeliveryRefs(refs);
1005
+ const survival = opts.survival;
1006
+ if (survival && Number.isFinite(survival.added) && survival.added > 0) {
1007
+ const pct = Math.round((Math.max(0, survival.alive) / survival.added) * 100);
1008
+ const survivalText = `about ${pct}% of ${survival.added} delivered lines alive`;
1009
+ if (pct < OWED_SURVIVAL_REWRITTEN_PCT) {
1010
+ return {
1011
+ classification: "superseded-or-rewritten",
1012
+ evidenceLine: truncateStr(`${survivalText}; ${refsText}`, MAX_OWED_EVIDENCE_LINE),
1013
+ };
1014
+ }
1015
+ refsText = `${survivalText}; ${refsText}`;
1016
+ }
1017
+ if (lifecycle === "parked" && stats.open > 0) {
1018
+ return {
1019
+ classification: "partial-parked",
1020
+ evidenceLine: truncateStr(`parked, ${done}; ${refsText}`, MAX_OWED_EVIDENCE_LINE),
1021
+ };
1022
+ }
1023
+ return {
1024
+ classification: "live-unreviewed",
1025
+ evidenceLine: truncateStr(`${done}; ${refsText}`, MAX_OWED_EVIDENCE_LINE),
1026
+ };
1027
+ }
1028
+
823
1029
  /**
824
1030
  * List still-unreviewed work for cadence emit and batch CTAs.
825
1031
  * Includes untriaged monitors and terminal plans without a matching monitor
826
1032
  * file (existence). Every report slug enters `monitorSlugs`; triage only gates
827
1033
  * first-loop inclusion. Does not emit owed attention rows.
828
- * @returns {{ kind: 'report'|'owed', planFile: string, slug: string, path: string }[]}
1034
+ * A terminal plan with zero completed to-dos delivered nothing (all cancelled,
1035
+ * or parked with every to-do still open) and is never owed. A parked plan with
1036
+ * open work is owed for its completed slice only: `completedTodoIds` names it.
1037
+ * Archived plans are not in `plans` (basenames only), so they are never owed.
1038
+ * `TERMINAL_FIELD_REPORT_LIFECYCLES` stays unchanged: it also drives prompt
1039
+ * clear and report demotion.
1040
+ * Owed targets also carry `classification` and one `evidenceLine` (classifyOwedPlan).
1041
+ * @returns {{ kind: 'report'|'owed', planFile: string, slug: string, path: string, lifecycle?: string, completedTodoIds?: string[], totalTodos?: number, classification?: string, evidenceLine?: string }[]}
829
1042
  */
830
1043
  export function listUnreviewedReviewTargets(
831
1044
  plans,
@@ -865,12 +1078,18 @@ export function listUnreviewedReviewTargets(
865
1078
  if (!isPlanLifecycleTerminal(lifecycle)) continue;
866
1079
  const slug = planFile.replace(/\.plan\.md$/i, "");
867
1080
  if (!slug || monitorSlugs.has(normalizeSlug(slug))) continue;
1081
+ const stats = todoStats(plan);
1082
+ if (stats.completed === 0) continue;
868
1083
  seenPlans.add(planFile);
869
1084
  targets.push({
870
1085
  kind: "owed",
871
1086
  planFile,
872
1087
  slug,
873
1088
  path: `.cursor/plans/${planFile}`,
1089
+ lifecycle,
1090
+ completedTodoIds: stats.items.filter((t) => t.status === "completed").map((t) => t.id),
1091
+ totalTodos: stats.total,
1092
+ ...classifyOwedPlan(plan, lifecycle),
874
1093
  });
875
1094
  }
876
1095
 
@@ -1025,6 +1244,14 @@ export function buildCadenceAttentionItem(ledger, targets, opts = {}) {
1025
1244
  modifiedAt: parsed.lastBatchCompleteAt || null,
1026
1245
  progress: null,
1027
1246
  pendingPlanFiles: parsed.pendingPlanFiles.slice(),
1247
+ planEvidence: liveTargets
1248
+ .filter((t) => t && t.kind === "owed" && typeof t.evidenceLine === "string")
1249
+ .slice(0, MAX_CADENCE_PLAN_EVIDENCE)
1250
+ .map((t) => ({
1251
+ planFile: t.planFile,
1252
+ classification: t.classification || null,
1253
+ evidenceLine: t.evidenceLine,
1254
+ })),
1028
1255
  action: {
1029
1256
  type: "copy",
1030
1257
  target: batchTarget,
@@ -5,7 +5,7 @@ import {
5
5
  import {
6
6
  REGISTRY_CLI_ARGS,
7
7
  resolveRegistryFromCli
8
- } from "./chunk-4KV3TXKC.js";
8
+ } from "./chunk-GTP224FI.js";
9
9
  import {
10
10
  logger
11
11
  } from "./chunk-ZB43YMHW.js";
@@ -22,8 +22,8 @@ import {
22
22
  resolveProtectedGlobs,
23
23
  saveManifest,
24
24
  upsertIdList
25
- } from "./chunk-VRSBZKTA.js";
26
- import "./chunk-B4MUKUVS.js";
25
+ } from "./chunk-3HNTNYPR.js";
26
+ import "./chunk-677W4QO3.js";
27
27
  import {
28
28
  KIT_VERSION
29
29
  } from "./chunk-7HDQEK6T.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  MANIFEST_RELATIVE_PATH
3
- } from "./chunk-VRSBZKTA.js";
3
+ } from "./chunk-3HNTNYPR.js";
4
4
  import {
5
5
  fileExists
6
6
  } from "./chunk-5B4DVO6C.js";
@@ -8,7 +8,7 @@ import {
8
8
  saveManagedHashLedger,
9
9
  shouldPreserveCustomizedOverlay,
10
10
  toPosixRel
11
- } from "./chunk-B4MUKUVS.js";
11
+ } from "./chunk-677W4QO3.js";
12
12
  import {
13
13
  HANDOFF_REL
14
14
  } from "./chunk-C4Q77GGJ.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  gateExitNotePath
3
- } from "./chunk-L7BL4246.js";
3
+ } from "./chunk-BGL5DRK2.js";
4
4
 
5
5
  // src/plan-loop/merge-detect.ts
6
6
  async function isAncestor(git, ref, baseRef) {
@@ -393,7 +393,64 @@ var KNOWN_SHIPPED_OVERLAY_HASHES = /* @__PURE__ */ new Set([
393
393
  "003bba4475ade592a61220ff32000bcf52ec8043fc842a0c3d2d72768439dc2e",
394
394
  "653c713e3d9e09bc6d89b4b4b12ba65123ac69d8f1a85ae7dbc3cff0729b9054",
395
395
  "45cdac355b105d057cd78fb5651d9b8d853a9a9110fb28b7450296d5df921c3b",
396
- "a809a5a06fd11a6329622d5acfad85c1ef06fef9bb9f28b24ac04780b225b2df"
396
+ "a809a5a06fd11a6329622d5acfad85c1ef06fef9bb9f28b24ac04780b225b2df",
397
+ "516b10a893c1568de4dc1a69cbf14db4f42d8d507c2c0b5521e633061d5fd0dc",
398
+ "ce4740e27188398f1c9a85cbea696fb466b77ee6827c90532e6cb4bacac3cb97",
399
+ "e8f0afb63630ce34dc96d693daf16e5b9d00c7a697af786402a1de4503ec30c0",
400
+ "baf992c14f3372b10652afa242335b38b4d41103b720f498c0601287006f80e6",
401
+ // prior .cursor/agents/clickup-tasks.md (model: claude-sonnet-4, before model roles)
402
+ "c72a7f6662cc6f91d1cda9f9e21e00913b065f5fb94aea17bafd5810bcd20ae6",
403
+ // prior .cursor/agents/docs-repo.md (model: claude-sonnet-4, before model roles)
404
+ "3885de12b0a533cd6908657e704b64567a13ca21d6a7629ac9346155ceb8a70a",
405
+ // prior .cursor/agents/git-autogit.md (model: claude-sonnet-4, before model roles)
406
+ "b9caafeefbea658e1ffad854dbd8eafa7a71a641efe7afdc725199c31337528e",
407
+ // prior .cursor/agents/mission-kit-comms.md (model: claude-sonnet-4, before model roles)
408
+ "a675fce8ae9de8dcfd9497e34bf95ffd1484367f5bb001aef272a604549f1825",
409
+ // prior .cursor/agents/n8n-workflows.md (model: claude-sonnet-4, before model roles)
410
+ "c6f7ea487f595a0bb8cd2df509941954dcb89c8aaafda1595da733858e9fab6d",
411
+ // prior .cursor/agents/prompts-agents.md (model: claude-sonnet-4, before model roles)
412
+ "fd166cb04ddd131dd96be21935789589eacd5a66c52e532ee9a68002b821d216",
413
+ // prior .cursor/agents/security-reviewer.md (model: claude-sonnet-4, before model roles)
414
+ "ae7d2f6caf94420dcad56b32d9e074691a27cb5ad630f3dada6b1839871f24a1",
415
+ // prior .cursor/agents/sql-schema.md (model: claude-sonnet-4, before model roles)
416
+ "f4e94e6ea1867ad2a46228011bb1ae9d429f7bc3f4e9b9977ae30279ac652f95",
417
+ "12e2c286160dd6a650c39487b66bb50d3876986bda2e546817deebece6da6f55",
418
+ "9c895c0a9a26ca8951acfddf297e2d83f353825ea278f4a799762b16f9929422",
419
+ "edceace01030b75745465a69bfff76dafcc4ed7e5b6bda1f46b389c3e9482308",
420
+ "59bc60f5fd1107619a1a4cece1a2f0b5a6a9b99d9c89e40e37d64dc17cf6c6d0",
421
+ "bcb2298e71140c9b03e3b6734d66993e52a8c596843e61741098fa0f2df0668b",
422
+ "8daa46b59d6e47c837b6d51de96ce46bd945d4852f9994d3a172f736199a6cb8",
423
+ "a654499f93743cb888aaba1b097590a221e94de45ce13095f15292ba0364519b",
424
+ "c8aff7996e3f067f914739bb6808d6f3fb0715fb67c7e3292cb07111c8a1cd69",
425
+ "0a9b9fafa4d8e9dee21a7f6339007aa1ee6f197fdf4627fc537b8d821ca71462",
426
+ "126f49b01f3fdf088d0ae853e8efbcb5fa6813e31ac70dae563482a93adb39f5",
427
+ "207372c1883c178dde339ddddc508cdbb021106bfc3a83135d3a4dff350743ce",
428
+ "255b0e47c5b66f21c20b922527525f7d979e9b07f3adbf65c2ecec120d943e60",
429
+ "2a24f8ae133207bae901252688c860eb0884c3f1dbb9194ee38ded16b77505e6",
430
+ "3cb3fd2a05ea8e2118169a51728054e237f633db909bdf707e10af999bbd6491",
431
+ "3f4e5be930c74b24f8b48951fa257f25b8beb411e94f19bd461880325b272412",
432
+ "425dd510af1a0b9c34b861c430718c485c838a03b6c5e626ef93b3c4bdf23f0e",
433
+ "44753d21150253b5c95411991065999dbb669979dc8b69370806652a728e79e9",
434
+ "529b05b1629aaba4890d6dbdd324a606a8a38ea54b13498be0cb0ae3fd513bd3",
435
+ "5c54c753f966114175ab29f6a52aa98b1b4579eebb53989f3af4984b65d81842",
436
+ "5c8b3e4ec2a165ce33a44ac6ae087f2c3fb9f97252b2a04cf0b0fc75cc9abd6d",
437
+ "5d8b6ea2cd141a2ad6fe6307f8fdbd97b3378ff11ce5bc378ee91ede6fcc915f",
438
+ "62064072abf11e7be23d3ef49d3d95ec26b27863bf759cfd713bd8c653502dcd",
439
+ "721b9ec0aecd82e37019d0d6ddca4020bd60c113447c80048a068359cbfbef6c",
440
+ "74128a798669da13a093c63b290003f5eac838cbde3e4552e731e796c83dd54e",
441
+ "8a3691544d7a09840f914f8fd65d5dcbc93651898fa3dabdddc9e9fff718311b",
442
+ "8e6a1cb5a27d5b6641e3aeff9fbb1179e6aca31360e27d0fcad430969b6006a5",
443
+ "ac085f197a72b944afaffc43d4ed2145ed0bccae91fd73606df0e32df951002b",
444
+ "acfe2d3cb0fcd13eebd7355ad485b0ba452722373a08e4417b1225c59aac9852",
445
+ "afe9fa80c2859a7a374db2024da20b13fb70f25b04c40870adddfa8746abd3a8",
446
+ "cb49e08c6e3c38934eb40ab5e01f95cd5d7012eec5b4cf4f0c550fe10d3c0bf6",
447
+ "dca0d79d4b3d9448d93bc629e71c5856d64bfcdf9a671aa5b34de4e8bd51d998",
448
+ "df7020e0b786b458c025b868764c996d56f16d56e01d8d68e6ad2a84bb8546e8",
449
+ "e1918d9e3466e2edac3e10d3a24ac2ddd1879a4ec31c8b0cd301560b65a61d6b",
450
+ "e96e3362611663fa0bb839e827170f8958ed24fc484b491d90ae3f51c5699332",
451
+ "ea780d4ed8902f3f8fb83696718f070a24192c5654686ae34437d197a339599a",
452
+ "ed6108dc8cdd666d1182059cb6675f55986dc181e376d09a14e678ce37ac1845",
453
+ "f2ba9bac4d507367adbf1a531eb16cb70e4aff937866515858c36381c7e6ea4a"
397
454
  ]);
398
455
 
399
456
  // src/lifecycle/paths.ts
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  formatHitlGateLine
3
- } from "./chunk-WRCXRV2U.js";
3
+ } from "./chunk-P7732A25.js";
4
4
 
5
5
  // src/plan-loop/driver-events.ts
6
6
  import { createInterface } from "readline";
@@ -3,15 +3,7 @@ import {
3
3
  ScrollRegion,
4
4
  renderMcLive,
5
5
  runMcTuiLoop
6
- } from "./chunk-ZFJIJUZ4.js";
7
- import {
8
- countPendingTodos,
9
- findActivePlanFile,
10
- readPlan,
11
- readRunQueueState,
12
- resolveActivePlanFromHandoff,
13
- resolveActivePlanPath
14
- } from "./chunk-7ABY6DYH.js";
6
+ } from "./chunk-MPCNPZJZ.js";
15
7
  import {
16
8
  DRIVER_PROTOCOL_VERSION,
17
9
  DriverAgentSink,
@@ -20,11 +12,34 @@ import {
20
12
  createDriverEmitter,
21
13
  driverReplies,
22
14
  driverStop
23
- } from "./chunk-SKC6QZW4.js";
15
+ } from "./chunk-6WUKLS4D.js";
16
+ import {
17
+ QUEUE_LEASE_INTERRUPT_WAIT_MS,
18
+ QUEUE_LEASE_SESSION_ENV,
19
+ acquirePlanWriterLease,
20
+ forwardTermination,
21
+ gateCheckIn,
22
+ holdQueueStatus,
23
+ procStart
24
+ } from "./chunk-DTSL2RH7.js";
25
+ import {
26
+ CLAUDE_SUBAGENT_MODEL_ENV,
27
+ describeResolvedRoles,
28
+ readPlanRoleOverrides,
29
+ resolveSubworkerModel
30
+ } from "./chunk-UATQQDVR.js";
31
+ import {
32
+ countPendingTodos,
33
+ findActivePlanFile,
34
+ readPlan,
35
+ readRunQueueState,
36
+ resolveActivePlanFromHandoff,
37
+ resolveActivePlanPath
38
+ } from "./chunk-7ABY6DYH.js";
24
39
  import {
25
40
  classifyGateExit,
26
41
  landGateExit
27
- } from "./chunk-L7BL4246.js";
42
+ } from "./chunk-BGL5DRK2.js";
28
43
  import {
29
44
  parsePlanFrontmatter
30
45
  } from "./chunk-L5V3W3DY.js";
@@ -34,13 +49,13 @@ import {
34
49
  parseStreamLine,
35
50
  redactSecrets,
36
51
  renderStreamEvent
37
- } from "./chunk-Y7BH6KIE.js";
52
+ } from "./chunk-W3ZJVBNY.js";
38
53
  import {
39
54
  LineSplitter,
40
55
  formatHitlSummary,
41
56
  operatorQuitStop,
42
57
  sumUsage
43
- } from "./chunk-WRCXRV2U.js";
58
+ } from "./chunk-P7732A25.js";
44
59
  import {
45
60
  TtySpinner,
46
61
  shouldUseVisualMotion,
@@ -837,9 +852,12 @@ async function runTickWithSpinner(label, backend, opts, plain) {
837
852
  },
838
853
  (seams) => backend.run({
839
854
  ...opts,
840
- hitl: seams.hitl,
855
+ hitl: { ...seams.hitl, checkIn: opts.hitl?.checkIn },
841
856
  render: seams.render,
842
- onSpawn: seams.onSpawn,
857
+ onSpawn: (info) => {
858
+ opts.onSpawn?.(info);
859
+ seams.onSpawn(info);
860
+ },
843
861
  log: seams.log
844
862
  })
845
863
  );
@@ -962,7 +980,25 @@ async function runPlanLoop(opts) {
962
980
  await unlink(stopFile);
963
981
  } catch {
964
982
  }
983
+ let lease = null;
984
+ let nestedSession = null;
985
+ const checkIn = gateCheckIn(opts.root, () => lease?.session ?? nestedSession, opts.lease);
986
+ let restoreQueue = null;
987
+ let previousLeaseSession;
988
+ let leaseSessionSet = false;
989
+ const releaseLease = (interrupted) => {
990
+ restoreQueue?.();
991
+ restoreQueue = null;
992
+ if (interrupted) lease?.releaseAfterAgent(QUEUE_LEASE_INTERRUPT_WAIT_MS);
993
+ else lease?.release();
994
+ if (leaseSessionSet) {
995
+ if (previousLeaseSession === void 0) delete process.env[QUEUE_LEASE_SESSION_ENV];
996
+ else process.env[QUEUE_LEASE_SESSION_ENV] = previousLeaseSession;
997
+ leaseSessionSet = false;
998
+ }
999
+ };
965
1000
  const onSigInt = () => {
1001
+ releaseLease(true);
966
1002
  if (driver) {
967
1003
  emit({
968
1004
  type: "run_end",
@@ -980,6 +1016,24 @@ async function runPlanLoop(opts) {
980
1016
  process.exit(130);
981
1017
  };
982
1018
  process.on("SIGINT", onSigInt);
1019
+ let tickAgent = null;
1020
+ const offTermination = driver ? forwardTermination(
1021
+ () => tickAgent,
1022
+ (signal) => {
1023
+ releaseLease(true);
1024
+ emit({
1025
+ type: "run_end",
1026
+ exitCode: 130,
1027
+ ticks: ticksRun,
1028
+ pending: null,
1029
+ reason: `interrupted (${signal})`,
1030
+ planExhausted: false,
1031
+ usage: runUsage
1032
+ });
1033
+ process.exit(130);
1034
+ }
1035
+ ) : () => {
1036
+ };
983
1037
  try {
984
1038
  const persona = driver ? null : await loadCliRunPlanPersona(opts.root);
985
1039
  const banners = createPersonaBannerPrinter(persona);
@@ -1010,12 +1064,51 @@ async function runPlanLoop(opts) {
1010
1064
  say(`${opts.backend.id} not found on PATH`, "error");
1011
1065
  return finishRun(1, `${opts.backend.id} not found on PATH`, pendingAtStart);
1012
1066
  }
1067
+ const writer = acquirePlanWriterLease(opts.root, "agent-kit run-plan", {
1068
+ ...opts.lease,
1069
+ onLost: (by) => say(
1070
+ `Queue lease lost: ${by ? `session ${by.session} (pid ${by.dispatcher.pid})` : "the lease file"} replaced this run's lease. Another session may be writing this workspace's plans.`,
1071
+ "warn"
1072
+ )
1073
+ });
1074
+ if (writer.kind === "refused") {
1075
+ say(writer.message, "error");
1076
+ return finishRun(1, writer.message, pendingAtStart);
1077
+ }
1078
+ if (writer.kind === "nested") {
1079
+ nestedSession = writer.lease.session;
1080
+ say(
1081
+ `Queue lease: running under session ${writer.lease.session} (dispatcher pid ${writer.lease.dispatcher.pid}).`
1082
+ );
1083
+ } else {
1084
+ lease = writer.handle;
1085
+ if (lease.takeover) {
1086
+ say(
1087
+ `Queue lease: took over a stale lease (${lease.takeover.reason}); the takeover is logged in HANDOFF.`,
1088
+ "warn"
1089
+ );
1090
+ }
1091
+ previousLeaseSession = process.env[QUEUE_LEASE_SESSION_ENV];
1092
+ process.env[QUEUE_LEASE_SESSION_ENV] = lease.session;
1093
+ leaseSessionSet = true;
1094
+ restoreQueue = holdQueueStatus(opts.root, {
1095
+ plan: path4.basename(planPath),
1096
+ who: `agent-kit run-plan session ${lease.session}`,
1097
+ at: (/* @__PURE__ */ new Date()).toISOString()
1098
+ });
1099
+ if (restoreQueue) {
1100
+ say(
1101
+ "Queue status: held while this run-plan runs outside the queue; restored when it ends."
1102
+ );
1103
+ }
1104
+ }
1013
1105
  let stopReason;
1014
1106
  let planExhausted = false;
1015
1107
  let exitCode = 0;
1016
1108
  let endReason = "";
1017
1109
  let backend = opts.backend;
1018
1110
  let limitSwitched = false;
1111
+ const rolesWarned = /* @__PURE__ */ new Set();
1019
1112
  const stopRequested = () => {
1020
1113
  if (!driver?.reader.stopRequested()) return false;
1021
1114
  const msg = `Stop requested by the driver (stop_after_tick) - stopping after tick ${ticksRun}. The plan is as the tick left it.`;
@@ -1092,12 +1185,41 @@ async function runPlanLoop(opts) {
1092
1185
  });
1093
1186
  };
1094
1187
  try {
1188
+ const switched = backend !== opts.backend;
1189
+ const tickModel = switched && opts.roles && opts.roles.modelSource !== "flag" ? void 0 : opts.model;
1190
+ let tickEnv;
1191
+ if (opts.roles) {
1192
+ const planOverrides = readPlanRoleOverrides(await readPlan(planPath).catch(() => ""));
1193
+ const sub = resolveSubworkerModel({
1194
+ backend: backend.id,
1195
+ roles: opts.roles.roles,
1196
+ plan: planOverrides
1197
+ });
1198
+ if (sub.warning && !rolesWarned.has(sub.warning)) {
1199
+ rolesWarned.add(sub.warning);
1200
+ say(`roles: ${sub.warning}`, "warn");
1201
+ }
1202
+ if (sub.model && backend.id === "claude") {
1203
+ tickEnv = { [CLAUDE_SUBAGENT_MODEL_ENV]: sub.model };
1204
+ }
1205
+ say(
1206
+ describeResolvedRoles({
1207
+ backendId: backend.id,
1208
+ backendSource: switched ? "flag" : opts.roles.backendSource,
1209
+ ...tickModel ? { model: tickModel } : {},
1210
+ ...tickModel && opts.roles.modelSource ? { modelSource: opts.roles.modelSource } : {},
1211
+ subworker: sub
1212
+ })
1213
+ );
1214
+ }
1095
1215
  const runOpts = {
1096
1216
  workspace: opts.root,
1097
1217
  prompt: TICK_PROMPT,
1098
- model: opts.model,
1218
+ model: tickModel,
1099
1219
  logPath,
1100
- hitl: { policy: opts.noHitl ? "off" : "prompt" }
1220
+ hitl: { policy: opts.noHitl ? "off" : "prompt", checkIn },
1221
+ ...tickEnv ? { env: tickEnv } : {},
1222
+ onSpawn: (info) => lease?.setAgent(info.pid)
1101
1223
  };
1102
1224
  const result = driver ? await backend.run({
1103
1225
  ...runOpts,
@@ -1106,9 +1228,15 @@ async function runPlanLoop(opts) {
1106
1228
  hitl: {
1107
1229
  policy: opts.noHitl ? "off" : "driver",
1108
1230
  readAnswer: driver.reader.read,
1109
- write: driver.writeErr
1231
+ write: driver.writeErr,
1232
+ checkIn
1233
+ },
1234
+ onSpawn: (info) => {
1235
+ lease?.setAgent(info.pid);
1236
+ tickAgent = info.pid === void 0 ? null : { pid: info.pid, start: procStart(info.pid) };
1110
1237
  }
1111
1238
  }) : await runTickWithSpinner(`tick ${tick}`, backend, runOpts, opts.plain === true);
1239
+ tickAgent = null;
1112
1240
  agentExit = result.exitCode;
1113
1241
  tickUsage = result.usage?.total() ?? null;
1114
1242
  for (const line of formatHitlSummary(result.hitl)) say(line);
@@ -1118,6 +1246,7 @@ async function runPlanLoop(opts) {
1118
1246
  landSummary = lastResult?.resultText.trim() || lastResult?.assistantTexts.at(-1)?.trim() || void 0;
1119
1247
  landGateText = lastResult ? [lastResult.resultText, ...lastResult.assistantTexts].join("\n") : void 0;
1120
1248
  } catch (err) {
1249
+ tickAgent = null;
1121
1250
  say(String(err), "error");
1122
1251
  agentExit = 1;
1123
1252
  endTick(null, null);
@@ -1270,6 +1399,8 @@ async function runPlanLoop(opts) {
1270
1399
  return finishRun(exitCode, endReason || "stopped", pendingNow, planExhausted);
1271
1400
  } finally {
1272
1401
  process.off("SIGINT", onSigInt);
1402
+ offTermination();
1403
+ releaseLease(false);
1273
1404
  }
1274
1405
  }
1275
1406
 
@@ -4,11 +4,11 @@ import {
4
4
  RESOLVE_AGENT_KIT_REL,
5
5
  SESSION_START_HOOK_MARKER,
6
6
  mergeAllowRowsWithoutGuard
7
- } from "./chunk-XHANIDPK.js";
7
+ } from "./chunk-EBDQYFA4.js";
8
8
  import {
9
9
  CLAUDE_COMMANDS_DIR_REL,
10
10
  discoverInstalledCommands
11
- } from "./chunk-2CBKKCVU.js";
11
+ } from "./chunk-UXQH2CNC.js";
12
12
  import {
13
13
  findOnPath
14
14
  } from "./chunk-WGLPZXNU.js";
@@ -21,7 +21,7 @@ import {
21
21
  REQUIRED_SECRET_PATTERNS,
22
22
  detectGitDirty,
23
23
  runScanner
24
- } from "./chunk-SC2DBY2R.js";
24
+ } from "./chunk-R4DUO5DA.js";
25
25
  import {
26
26
  CONTEXT_CONFIG_REL,
27
27
  contextConfigPath
@@ -4,10 +4,10 @@ import {
4
4
  import {
5
5
  claudeRedactions,
6
6
  redactSecrets
7
- } from "./chunk-Y7BH6KIE.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";