@event4u/agent-config 10.3.0 → 10.4.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 (47) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/CHANGELOG.md +78 -0
  3. package/README.md +1 -1
  4. package/dist/agent-src/commands/analyze.md +2 -1
  5. package/dist/agent-src/commands/design-system/capture.md +44 -0
  6. package/dist/agent-src/commands/design-system/generate.md +53 -0
  7. package/dist/agent-src/commands/design-system/import.md +63 -0
  8. package/dist/agent-src/commands/design-system.md +66 -0
  9. package/dist/agent-src/skills/design-system-capture/SKILL.md +9 -0
  10. package/dist/agent-src/skills/design-system-capture/references/design-system-json.md +70 -0
  11. package/dist/agent-src/templates/agents/agent-project-settings.example.yml +1 -1
  12. package/dist/agent-src/templates/scripts/work_engine/directives/ui/design.ts +4 -1
  13. package/dist/cli-delegate/chunk-RLN73PR5.js +157 -0
  14. package/dist/cli-delegate/{chunk-I5EAFRII.js → chunk-ZPSXJTLI.js} +2 -154
  15. package/dist/cli-delegate/cmd_conformance.js +671 -213
  16. package/dist/cli-delegate/cmd_handoff.js +8 -6
  17. package/dist/cli-delegate/cmd_session_recycle.js +5 -3
  18. package/dist/discovery/deprecation-report.md +1 -1
  19. package/dist/discovery/discovery-manifest.json +116 -11
  20. package/dist/discovery/discovery-manifest.json.sha256 +1 -1
  21. package/dist/discovery/discovery-manifest.summary.md +3 -3
  22. package/dist/discovery/dormancy-report.md +1 -1
  23. package/dist/discovery/orphan-report.md +1 -1
  24. package/dist/discovery/packs.json +9 -5
  25. package/dist/discovery/trust-report.md +2 -2
  26. package/dist/discovery/workspaces.json +8 -4
  27. package/dist/hooks/dispatch.js +940 -387
  28. package/dist/mcp/registry-manifest.json +2 -2
  29. package/dist/mcp/server.json +2 -2
  30. package/dist/mcp/server.mjs +1102 -592
  31. package/package.json +1 -1
  32. package/src/agent-src/templates/scripts/work_engine/directives/ui/design.ts +4 -1
  33. package/src/config/gate-coverage.yml +23 -2
  34. package/src/config/gate-violation-baselines.json +2 -2
  35. package/src/scripts/_lib/design_system_import.ts +987 -0
  36. package/src/scripts/design_system_import.ts +264 -0
  37. package/src/scripts/hook_manifest.yaml +71 -2
  38. package/src/scripts/hooks/concern_registry.ts +4 -0
  39. package/src/scripts/hooks/dispatch_hook.ts +10 -0
  40. package/src/scripts/hooks/host_semantics.ts +2 -0
  41. package/src/scripts/hooks/spawn_guard_shadow_hook.ts +212 -0
  42. package/src/scripts/hooks/subagent_ledger_hook.ts +723 -0
  43. package/src/scripts/hooks/turn_end_gate_hook.ts +39 -2
  44. package/src/scripts/lint_hook_manifest.ts +2 -0
  45. package/src/scripts/lint_rule_skill_pack_reach.ts +194 -13
  46. package/tests/fixtures/hooks/subagent_start.json +7 -0
  47. package/tests/fixtures/hooks/subagent_stop.json +8 -0
@@ -112,17 +112,17 @@ var require_visit = __commonJS({
112
112
  visit.BREAK = BREAK;
113
113
  visit.SKIP = SKIP;
114
114
  visit.REMOVE = REMOVE;
115
- function visit_(key, node, visitor, path69) {
116
- const ctrl = callVisitor(key, node, visitor, path69);
115
+ function visit_(key, node, visitor, path71) {
116
+ const ctrl = callVisitor(key, node, visitor, path71);
117
117
  if (identity.isNode(ctrl) || identity.isPair(ctrl)) {
118
- replaceNode(key, path69, ctrl);
119
- return visit_(key, ctrl, visitor, path69);
118
+ replaceNode(key, path71, ctrl);
119
+ return visit_(key, ctrl, visitor, path71);
120
120
  }
121
121
  if (typeof ctrl !== "symbol") {
122
122
  if (identity.isCollection(node)) {
123
- path69 = Object.freeze(path69.concat(node));
123
+ path71 = Object.freeze(path71.concat(node));
124
124
  for (let i = 0; i < node.items.length; ++i) {
125
- const ci = visit_(i, node.items[i], visitor, path69);
125
+ const ci = visit_(i, node.items[i], visitor, path71);
126
126
  if (typeof ci === "number")
127
127
  i = ci - 1;
128
128
  else if (ci === BREAK)
@@ -133,13 +133,13 @@ var require_visit = __commonJS({
133
133
  }
134
134
  }
135
135
  } else if (identity.isPair(node)) {
136
- path69 = Object.freeze(path69.concat(node));
137
- const ck = visit_("key", node.key, visitor, path69);
136
+ path71 = Object.freeze(path71.concat(node));
137
+ const ck = visit_("key", node.key, visitor, path71);
138
138
  if (ck === BREAK)
139
139
  return BREAK;
140
140
  else if (ck === REMOVE)
141
141
  node.key = null;
142
- const cv = visit_("value", node.value, visitor, path69);
142
+ const cv = visit_("value", node.value, visitor, path71);
143
143
  if (cv === BREAK)
144
144
  return BREAK;
145
145
  else if (cv === REMOVE)
@@ -160,17 +160,17 @@ var require_visit = __commonJS({
160
160
  visitAsync.BREAK = BREAK;
161
161
  visitAsync.SKIP = SKIP;
162
162
  visitAsync.REMOVE = REMOVE;
163
- async function visitAsync_(key, node, visitor, path69) {
164
- const ctrl = await callVisitor(key, node, visitor, path69);
163
+ async function visitAsync_(key, node, visitor, path71) {
164
+ const ctrl = await callVisitor(key, node, visitor, path71);
165
165
  if (identity.isNode(ctrl) || identity.isPair(ctrl)) {
166
- replaceNode(key, path69, ctrl);
167
- return visitAsync_(key, ctrl, visitor, path69);
166
+ replaceNode(key, path71, ctrl);
167
+ return visitAsync_(key, ctrl, visitor, path71);
168
168
  }
169
169
  if (typeof ctrl !== "symbol") {
170
170
  if (identity.isCollection(node)) {
171
- path69 = Object.freeze(path69.concat(node));
171
+ path71 = Object.freeze(path71.concat(node));
172
172
  for (let i = 0; i < node.items.length; ++i) {
173
- const ci = await visitAsync_(i, node.items[i], visitor, path69);
173
+ const ci = await visitAsync_(i, node.items[i], visitor, path71);
174
174
  if (typeof ci === "number")
175
175
  i = ci - 1;
176
176
  else if (ci === BREAK)
@@ -181,13 +181,13 @@ var require_visit = __commonJS({
181
181
  }
182
182
  }
183
183
  } else if (identity.isPair(node)) {
184
- path69 = Object.freeze(path69.concat(node));
185
- const ck = await visitAsync_("key", node.key, visitor, path69);
184
+ path71 = Object.freeze(path71.concat(node));
185
+ const ck = await visitAsync_("key", node.key, visitor, path71);
186
186
  if (ck === BREAK)
187
187
  return BREAK;
188
188
  else if (ck === REMOVE)
189
189
  node.key = null;
190
- const cv = await visitAsync_("value", node.value, visitor, path69);
190
+ const cv = await visitAsync_("value", node.value, visitor, path71);
191
191
  if (cv === BREAK)
192
192
  return BREAK;
193
193
  else if (cv === REMOVE)
@@ -214,23 +214,23 @@ var require_visit = __commonJS({
214
214
  }
215
215
  return visitor;
216
216
  }
217
- function callVisitor(key, node, visitor, path69) {
217
+ function callVisitor(key, node, visitor, path71) {
218
218
  if (typeof visitor === "function")
219
- return visitor(key, node, path69);
219
+ return visitor(key, node, path71);
220
220
  if (identity.isMap(node))
221
- return visitor.Map?.(key, node, path69);
221
+ return visitor.Map?.(key, node, path71);
222
222
  if (identity.isSeq(node))
223
- return visitor.Seq?.(key, node, path69);
223
+ return visitor.Seq?.(key, node, path71);
224
224
  if (identity.isPair(node))
225
- return visitor.Pair?.(key, node, path69);
225
+ return visitor.Pair?.(key, node, path71);
226
226
  if (identity.isScalar(node))
227
- return visitor.Scalar?.(key, node, path69);
227
+ return visitor.Scalar?.(key, node, path71);
228
228
  if (identity.isAlias(node))
229
- return visitor.Alias?.(key, node, path69);
229
+ return visitor.Alias?.(key, node, path71);
230
230
  return void 0;
231
231
  }
232
- function replaceNode(key, path69, node) {
233
- const parent = path69[path69.length - 1];
232
+ function replaceNode(key, path71, node) {
233
+ const parent = path71[path71.length - 1];
234
234
  if (identity.isCollection(parent)) {
235
235
  parent.items[key] = node;
236
236
  } else if (identity.isPair(parent)) {
@@ -840,10 +840,10 @@ var require_Collection = __commonJS({
840
840
  var createNode = require_createNode();
841
841
  var identity = require_identity();
842
842
  var Node = require_Node();
843
- function collectionFromPath(schema, path69, value) {
843
+ function collectionFromPath(schema, path71, value) {
844
844
  let v = value;
845
- for (let i = path69.length - 1; i >= 0; --i) {
846
- const k = path69[i];
845
+ for (let i = path71.length - 1; i >= 0; --i) {
846
+ const k = path71[i];
847
847
  if (typeof k === "number" && Number.isInteger(k) && k >= 0) {
848
848
  const a = [];
849
849
  a[k] = v;
@@ -862,7 +862,7 @@ var require_Collection = __commonJS({
862
862
  sourceObjects: /* @__PURE__ */ new Map()
863
863
  });
864
864
  }
865
- var isEmptyPath = (path69) => path69 == null || typeof path69 === "object" && !!path69[Symbol.iterator]().next().done;
865
+ var isEmptyPath = (path71) => path71 == null || typeof path71 === "object" && !!path71[Symbol.iterator]().next().done;
866
866
  var Collection = class extends Node.NodeBase {
867
867
  constructor(type, schema) {
868
868
  super(type);
@@ -892,11 +892,11 @@ var require_Collection = __commonJS({
892
892
  * be a Pair instance or a `{ key, value }` object, which may not have a key
893
893
  * that already exists in the map.
894
894
  */
895
- addIn(path69, value) {
896
- if (isEmptyPath(path69))
895
+ addIn(path71, value) {
896
+ if (isEmptyPath(path71))
897
897
  this.add(value);
898
898
  else {
899
- const [key, ...rest] = path69;
899
+ const [key, ...rest] = path71;
900
900
  const node = this.get(key, true);
901
901
  if (identity.isCollection(node))
902
902
  node.addIn(rest, value);
@@ -910,8 +910,8 @@ var require_Collection = __commonJS({
910
910
  * Removes a value from the collection.
911
911
  * @returns `true` if the item was found and removed.
912
912
  */
913
- deleteIn(path69) {
914
- const [key, ...rest] = path69;
913
+ deleteIn(path71) {
914
+ const [key, ...rest] = path71;
915
915
  if (rest.length === 0)
916
916
  return this.delete(key);
917
917
  const node = this.get(key, true);
@@ -925,8 +925,8 @@ var require_Collection = __commonJS({
925
925
  * scalar values from their surrounding node; to disable set `keepScalar` to
926
926
  * `true` (collections are always returned intact).
927
927
  */
928
- getIn(path69, keepScalar) {
929
- const [key, ...rest] = path69;
928
+ getIn(path71, keepScalar) {
929
+ const [key, ...rest] = path71;
930
930
  const node = this.get(key, true);
931
931
  if (rest.length === 0)
932
932
  return !keepScalar && identity.isScalar(node) ? node.value : node;
@@ -944,8 +944,8 @@ var require_Collection = __commonJS({
944
944
  /**
945
945
  * Checks if the collection includes a value with the key `key`.
946
946
  */
947
- hasIn(path69) {
948
- const [key, ...rest] = path69;
947
+ hasIn(path71) {
948
+ const [key, ...rest] = path71;
949
949
  if (rest.length === 0)
950
950
  return this.has(key);
951
951
  const node = this.get(key, true);
@@ -955,8 +955,8 @@ var require_Collection = __commonJS({
955
955
  * Sets a value in this collection. For `!!set`, `value` needs to be a
956
956
  * boolean to add/remove the item from the set.
957
957
  */
958
- setIn(path69, value) {
959
- const [key, ...rest] = path69;
958
+ setIn(path71, value) {
959
+ const [key, ...rest] = path71;
960
960
  if (rest.length === 0) {
961
961
  this.set(key, value);
962
962
  } else {
@@ -980,13 +980,13 @@ var require_Collection = __commonJS({
980
980
  var require_stringifyComment = __commonJS({
981
981
  "node_modules/yaml/dist/stringify/stringifyComment.js"(exports) {
982
982
  "use strict";
983
- var stringifyComment = (str8) => str8.replace(/^(?!$)(?: $)?/gm, "#");
983
+ var stringifyComment = (str9) => str9.replace(/^(?!$)(?: $)?/gm, "#");
984
984
  function indentComment(comment, indent) {
985
985
  if (/^\n+$/.test(comment))
986
986
  return comment.substring(1);
987
987
  return indent ? comment.replace(/^(?! *$)/gm, indent) : comment;
988
988
  }
989
- var lineComment = (str8, indent, comment) => str8.endsWith("\n") ? indentComment(comment, indent) : comment.includes("\n") ? "\n" + indentComment(comment, indent) : (str8.endsWith(" ") ? "" : " ") + comment;
989
+ var lineComment = (str9, indent, comment) => str9.endsWith("\n") ? indentComment(comment, indent) : comment.includes("\n") ? "\n" + indentComment(comment, indent) : (str9.endsWith(" ") ? "" : " ") + comment;
990
990
  exports.indentComment = indentComment;
991
991
  exports.lineComment = lineComment;
992
992
  exports.stringifyComment = stringifyComment;
@@ -1140,16 +1140,16 @@ var require_stringifyString = __commonJS({
1140
1140
  lineWidth: ctx.options.lineWidth,
1141
1141
  minContentWidth: ctx.options.minContentWidth
1142
1142
  });
1143
- var containsDocumentMarker = (str8) => /^(%|---|\.\.\.)/m.test(str8);
1144
- function lineLengthOverLimit(str8, lineWidth, indentLength) {
1143
+ var containsDocumentMarker = (str9) => /^(%|---|\.\.\.)/m.test(str9);
1144
+ function lineLengthOverLimit(str9, lineWidth, indentLength) {
1145
1145
  if (!lineWidth || lineWidth < 0)
1146
1146
  return false;
1147
1147
  const limit = lineWidth - indentLength;
1148
- const strLen = str8.length;
1148
+ const strLen = str9.length;
1149
1149
  if (strLen <= limit)
1150
1150
  return false;
1151
1151
  for (let i = 0, start = 0; i < strLen; ++i) {
1152
- if (str8[i] === "\n") {
1152
+ if (str9[i] === "\n") {
1153
1153
  if (i - start > limit)
1154
1154
  return true;
1155
1155
  start = i + 1;
@@ -1166,11 +1166,11 @@ var require_stringifyString = __commonJS({
1166
1166
  const { implicitKey } = ctx;
1167
1167
  const minMultiLineLength = ctx.options.doubleQuotedMinMultiLineLength;
1168
1168
  const indent = ctx.indent || (containsDocumentMarker(value) ? " " : "");
1169
- let str8 = "";
1169
+ let str9 = "";
1170
1170
  let start = 0;
1171
1171
  for (let i = 0, ch = json[i]; ch; ch = json[++i]) {
1172
1172
  if (ch === " " && json[i + 1] === "\\" && json[i + 2] === "n") {
1173
- str8 += json.slice(start, i) + "\\ ";
1173
+ str9 += json.slice(start, i) + "\\ ";
1174
1174
  i += 1;
1175
1175
  start = i;
1176
1176
  ch = "\\";
@@ -1179,38 +1179,38 @@ var require_stringifyString = __commonJS({
1179
1179
  switch (json[i + 1]) {
1180
1180
  case "u":
1181
1181
  {
1182
- str8 += json.slice(start, i);
1182
+ str9 += json.slice(start, i);
1183
1183
  const code = json.substr(i + 2, 4);
1184
1184
  switch (code) {
1185
1185
  case "0000":
1186
- str8 += "\\0";
1186
+ str9 += "\\0";
1187
1187
  break;
1188
1188
  case "0007":
1189
- str8 += "\\a";
1189
+ str9 += "\\a";
1190
1190
  break;
1191
1191
  case "000b":
1192
- str8 += "\\v";
1192
+ str9 += "\\v";
1193
1193
  break;
1194
1194
  case "001b":
1195
- str8 += "\\e";
1195
+ str9 += "\\e";
1196
1196
  break;
1197
1197
  case "0085":
1198
- str8 += "\\N";
1198
+ str9 += "\\N";
1199
1199
  break;
1200
1200
  case "00a0":
1201
- str8 += "\\_";
1201
+ str9 += "\\_";
1202
1202
  break;
1203
1203
  case "2028":
1204
- str8 += "\\L";
1204
+ str9 += "\\L";
1205
1205
  break;
1206
1206
  case "2029":
1207
- str8 += "\\P";
1207
+ str9 += "\\P";
1208
1208
  break;
1209
1209
  default:
1210
1210
  if (code.substr(0, 2) === "00")
1211
- str8 += "\\x" + code.substr(2);
1211
+ str9 += "\\x" + code.substr(2);
1212
1212
  else
1213
- str8 += json.substr(i, 6);
1213
+ str9 += json.substr(i, 6);
1214
1214
  }
1215
1215
  i += 5;
1216
1216
  start = i + 1;
@@ -1220,14 +1220,14 @@ var require_stringifyString = __commonJS({
1220
1220
  if (implicitKey || json[i + 2] === '"' || json.length < minMultiLineLength) {
1221
1221
  i += 1;
1222
1222
  } else {
1223
- str8 += json.slice(start, i) + "\n\n";
1223
+ str9 += json.slice(start, i) + "\n\n";
1224
1224
  while (json[i + 2] === "\\" && json[i + 3] === "n" && json[i + 4] !== '"') {
1225
- str8 += "\n";
1225
+ str9 += "\n";
1226
1226
  i += 2;
1227
1227
  }
1228
- str8 += indent;
1228
+ str9 += indent;
1229
1229
  if (json[i + 2] === " ")
1230
- str8 += "\\";
1230
+ str9 += "\\";
1231
1231
  i += 1;
1232
1232
  start = i + 1;
1233
1233
  }
@@ -1236,8 +1236,8 @@ var require_stringifyString = __commonJS({
1236
1236
  i += 1;
1237
1237
  }
1238
1238
  }
1239
- str8 = start ? str8 + json.slice(start) : json;
1240
- return implicitKey ? str8 : foldFlowLines.foldFlowLines(str8, indent, foldFlowLines.FOLD_QUOTED, getFoldOptions(ctx, false));
1239
+ str9 = start ? str9 + json.slice(start) : json;
1240
+ return implicitKey ? str9 : foldFlowLines.foldFlowLines(str9, indent, foldFlowLines.FOLD_QUOTED, getFoldOptions(ctx, false));
1241
1241
  }
1242
1242
  function singleQuotedString(value, ctx) {
1243
1243
  if (ctx.options.singleQuote === false || ctx.implicitKey && value.includes("\n") || /[ \t]\n|\n[ \t]/.test(value))
@@ -1365,15 +1365,15 @@ ${indent}${start}${value}${end}`;
1365
1365
  return quotedString(value, ctx);
1366
1366
  }
1367
1367
  }
1368
- const str8 = value.replace(/\n+/g, `$&
1368
+ const str9 = value.replace(/\n+/g, `$&
1369
1369
  ${indent}`);
1370
1370
  if (actualString) {
1371
- const test = (tag) => tag.default && tag.tag !== "tag:yaml.org,2002:str" && tag.test?.test(str8);
1371
+ const test = (tag) => tag.default && tag.tag !== "tag:yaml.org,2002:str" && tag.test?.test(str9);
1372
1372
  const { compat, tags } = ctx.doc.schema;
1373
1373
  if (tags.some(test) || compat?.some(test))
1374
1374
  return quotedString(value, ctx);
1375
1375
  }
1376
- return implicitKey ? str8 : foldFlowLines.foldFlowLines(str8, indent, foldFlowLines.FOLD_FLOW, getFoldOptions(ctx, false));
1376
+ return implicitKey ? str9 : foldFlowLines.foldFlowLines(str9, indent, foldFlowLines.FOLD_FLOW, getFoldOptions(ctx, false));
1377
1377
  }
1378
1378
  function stringifyString(item, ctx, onComment, onChompKeep) {
1379
1379
  const { implicitKey, inFlow } = ctx;
@@ -1525,11 +1525,11 @@ var require_stringify = __commonJS({
1525
1525
  const props = stringifyProps(node, tagObj, ctx);
1526
1526
  if (props.length > 0)
1527
1527
  ctx.indentAtStart = (ctx.indentAtStart ?? 0) + props.length + 1;
1528
- const str8 = typeof tagObj.stringify === "function" ? tagObj.stringify(node, ctx, onComment, onChompKeep) : identity.isScalar(node) ? stringifyString.stringifyString(node, ctx, onComment, onChompKeep) : node.toString(ctx, onComment, onChompKeep);
1528
+ const str9 = typeof tagObj.stringify === "function" ? tagObj.stringify(node, ctx, onComment, onChompKeep) : identity.isScalar(node) ? stringifyString.stringifyString(node, ctx, onComment, onChompKeep) : node.toString(ctx, onComment, onChompKeep);
1529
1529
  if (!props)
1530
- return str8;
1531
- return identity.isScalar(node) || str8[0] === "{" || str8[0] === "[" ? `${props} ${str8}` : `${props}
1532
- ${ctx.indent}${str8}`;
1530
+ return str9;
1531
+ return identity.isScalar(node) || str9[0] === "{" || str9[0] === "[" ? `${props} ${str9}` : `${props}
1532
+ ${ctx.indent}${str9}`;
1533
1533
  }
1534
1534
  exports.createStringifyContext = createStringifyContext;
1535
1535
  exports.stringify = stringify;
@@ -1564,8 +1564,8 @@ var require_stringifyPair = __commonJS({
1564
1564
  });
1565
1565
  let keyCommentDone = false;
1566
1566
  let chompKeep = false;
1567
- let str8 = stringify.stringify(key, ctx, () => keyCommentDone = true, () => chompKeep = true);
1568
- if (!explicitKey && !ctx.inFlow && str8.length > 1024) {
1567
+ let str9 = stringify.stringify(key, ctx, () => keyCommentDone = true, () => chompKeep = true);
1568
+ if (!explicitKey && !ctx.inFlow && str9.length > 1024) {
1569
1569
  if (simpleKeys)
1570
1570
  throw new Error("With simple keys, single line scalar must not span more than 1024 characters");
1571
1571
  explicitKey = true;
@@ -1574,27 +1574,27 @@ var require_stringifyPair = __commonJS({
1574
1574
  if (allNullValues || value == null) {
1575
1575
  if (keyCommentDone && onComment)
1576
1576
  onComment();
1577
- return str8 === "" ? "?" : explicitKey ? `? ${str8}` : str8;
1577
+ return str9 === "" ? "?" : explicitKey ? `? ${str9}` : str9;
1578
1578
  }
1579
1579
  } else if (allNullValues && !simpleKeys || value == null && explicitKey) {
1580
- str8 = `? ${str8}`;
1580
+ str9 = `? ${str9}`;
1581
1581
  if (keyComment && !keyCommentDone) {
1582
- str8 += stringifyComment.lineComment(str8, ctx.indent, commentString(keyComment));
1582
+ str9 += stringifyComment.lineComment(str9, ctx.indent, commentString(keyComment));
1583
1583
  } else if (chompKeep && onChompKeep)
1584
1584
  onChompKeep();
1585
- return str8;
1585
+ return str9;
1586
1586
  }
1587
1587
  if (keyCommentDone)
1588
1588
  keyComment = null;
1589
1589
  if (explicitKey) {
1590
1590
  if (keyComment)
1591
- str8 += stringifyComment.lineComment(str8, ctx.indent, commentString(keyComment));
1592
- str8 = `? ${str8}
1591
+ str9 += stringifyComment.lineComment(str9, ctx.indent, commentString(keyComment));
1592
+ str9 = `? ${str9}
1593
1593
  ${indent}:`;
1594
1594
  } else {
1595
- str8 = `${str8}:`;
1595
+ str9 = `${str9}:`;
1596
1596
  if (keyComment)
1597
- str8 += stringifyComment.lineComment(str8, ctx.indent, commentString(keyComment));
1597
+ str9 += stringifyComment.lineComment(str9, ctx.indent, commentString(keyComment));
1598
1598
  }
1599
1599
  let vsb, vcb, valueComment;
1600
1600
  if (identity.isNode(value)) {
@@ -1610,7 +1610,7 @@ ${indent}:`;
1610
1610
  }
1611
1611
  ctx.implicitKey = false;
1612
1612
  if (!explicitKey && !keyComment && identity.isScalar(value))
1613
- ctx.indentAtStart = str8.length + 1;
1613
+ ctx.indentAtStart = str9.length + 1;
1614
1614
  chompKeep = false;
1615
1615
  if (!indentSeq && indentStep.length >= 2 && !ctx.inFlow && !explicitKey && identity.isSeq(value) && !value.flow && !value.tag && !value.anchor) {
1616
1616
  ctx.indent = ctx.indent.substring(2);
@@ -1654,16 +1654,16 @@ ${ctx.indent}`;
1654
1654
  } else if (valueStr === "" || valueStr[0] === "\n") {
1655
1655
  ws = "";
1656
1656
  }
1657
- str8 += ws + valueStr;
1657
+ str9 += ws + valueStr;
1658
1658
  if (ctx.inFlow) {
1659
1659
  if (valueCommentDone && onComment)
1660
1660
  onComment();
1661
1661
  } else if (valueComment && !valueCommentDone) {
1662
- str8 += stringifyComment.lineComment(str8, ctx.indent, commentString(valueComment));
1662
+ str9 += stringifyComment.lineComment(str9, ctx.indent, commentString(valueComment));
1663
1663
  } else if (chompKeep && onChompKeep) {
1664
1664
  onChompKeep();
1665
1665
  }
1666
- return str8;
1666
+ return str9;
1667
1667
  }
1668
1668
  exports.stringifyPair = stringifyPair;
1669
1669
  }
@@ -1890,31 +1890,31 @@ var require_stringifyCollection = __commonJS({
1890
1890
  }
1891
1891
  }
1892
1892
  chompKeep = false;
1893
- let str9 = stringify.stringify(item, itemCtx, () => comment2 = null, () => chompKeep = true);
1893
+ let str10 = stringify.stringify(item, itemCtx, () => comment2 = null, () => chompKeep = true);
1894
1894
  if (comment2)
1895
- str9 += stringifyComment.lineComment(str9, itemIndent, commentString(comment2));
1895
+ str10 += stringifyComment.lineComment(str10, itemIndent, commentString(comment2));
1896
1896
  if (chompKeep && comment2)
1897
1897
  chompKeep = false;
1898
- lines.push(blockItemPrefix + str9);
1898
+ lines.push(blockItemPrefix + str10);
1899
1899
  }
1900
- let str8;
1900
+ let str9;
1901
1901
  if (lines.length === 0) {
1902
- str8 = flowChars.start + flowChars.end;
1902
+ str9 = flowChars.start + flowChars.end;
1903
1903
  } else {
1904
- str8 = lines[0];
1904
+ str9 = lines[0];
1905
1905
  for (let i = 1; i < lines.length; ++i) {
1906
1906
  const line = lines[i];
1907
- str8 += line ? `
1907
+ str9 += line ? `
1908
1908
  ${indent}${line}` : "\n";
1909
1909
  }
1910
1910
  }
1911
1911
  if (comment) {
1912
- str8 += "\n" + stringifyComment.indentComment(commentString(comment), indent);
1912
+ str9 += "\n" + stringifyComment.indentComment(commentString(comment), indent);
1913
1913
  if (onComment)
1914
1914
  onComment();
1915
1915
  } else if (chompKeep && onChompKeep)
1916
1916
  onChompKeep();
1917
- return str8;
1917
+ return str9;
1918
1918
  }
1919
1919
  function stringifyFlowCollection({ items }, ctx, { flowChars, itemIndent }) {
1920
1920
  const { indent, indentStep, flowCollectionPadding: fcPadding, options: { commentString } } = ctx;
@@ -1957,21 +1957,21 @@ ${indent}${line}` : "\n";
1957
1957
  }
1958
1958
  if (comment)
1959
1959
  reqNewline = true;
1960
- let str8 = stringify.stringify(item, itemCtx, () => comment = null);
1961
- reqNewline || (reqNewline = lines.length > linesAtValue || str8.includes("\n"));
1960
+ let str9 = stringify.stringify(item, itemCtx, () => comment = null);
1961
+ reqNewline || (reqNewline = lines.length > linesAtValue || str9.includes("\n"));
1962
1962
  if (i < items.length - 1) {
1963
- str8 += ",";
1963
+ str9 += ",";
1964
1964
  } else if (ctx.options.trailingComma) {
1965
1965
  if (ctx.options.lineWidth > 0) {
1966
- reqNewline || (reqNewline = lines.reduce((sum, line) => sum + line.length + 2, 2) + (str8.length + 2) > ctx.options.lineWidth);
1966
+ reqNewline || (reqNewline = lines.reduce((sum, line) => sum + line.length + 2, 2) + (str9.length + 2) > ctx.options.lineWidth);
1967
1967
  }
1968
1968
  if (reqNewline) {
1969
- str8 += ",";
1969
+ str9 += ",";
1970
1970
  }
1971
1971
  }
1972
1972
  if (comment)
1973
- str8 += stringifyComment.lineComment(str8, itemIndent, commentString(comment));
1974
- lines.push(str8);
1973
+ str9 += stringifyComment.lineComment(str9, itemIndent, commentString(comment));
1974
+ lines.push(str9);
1975
1975
  linesAtValue = lines.length;
1976
1976
  }
1977
1977
  const { start, end } = flowChars;
@@ -1983,11 +1983,11 @@ ${indent}${line}` : "\n";
1983
1983
  reqNewline = ctx.options.lineWidth > 0 && len > ctx.options.lineWidth;
1984
1984
  }
1985
1985
  if (reqNewline) {
1986
- let str8 = start;
1986
+ let str9 = start;
1987
1987
  for (const line of lines)
1988
- str8 += line ? `
1988
+ str9 += line ? `
1989
1989
  ${indentStep}${indent}${line}` : "\n";
1990
- return `${str8}
1990
+ return `${str9}
1991
1991
  ${indent}${end}`;
1992
1992
  } else {
1993
1993
  return `${start}${fcPadding}${lines.join(" ")}${fcPadding}${end}`;
@@ -2319,7 +2319,7 @@ var require_string = __commonJS({
2319
2319
  identify: (value) => typeof value === "string",
2320
2320
  default: true,
2321
2321
  tag: "tag:yaml.org,2002:str",
2322
- resolve: (str8) => str8,
2322
+ resolve: (str9) => str9,
2323
2323
  stringify(item, ctx, onComment, onChompKeep) {
2324
2324
  ctx = Object.assign({ actualString: true }, ctx);
2325
2325
  return stringifyString.stringifyString(item, ctx, onComment, onChompKeep);
@@ -2357,7 +2357,7 @@ var require_bool = __commonJS({
2357
2357
  default: true,
2358
2358
  tag: "tag:yaml.org,2002:bool",
2359
2359
  test: /^(?:[Tt]rue|TRUE|[Ff]alse|FALSE)$/,
2360
- resolve: (str8) => new Scalar.Scalar(str8[0] === "t" || str8[0] === "T"),
2360
+ resolve: (str9) => new Scalar.Scalar(str9[0] === "t" || str9[0] === "T"),
2361
2361
  stringify({ source, value }, ctx) {
2362
2362
  if (source && boolTag.test.test(source)) {
2363
2363
  const sv = source[0] === "t" || source[0] === "T";
@@ -2409,7 +2409,7 @@ var require_float = __commonJS({
2409
2409
  default: true,
2410
2410
  tag: "tag:yaml.org,2002:float",
2411
2411
  test: /^(?:[-+]?\.(?:inf|Inf|INF)|\.nan|\.NaN|\.NAN)$/,
2412
- resolve: (str8) => str8.slice(-3).toLowerCase() === "nan" ? NaN : str8[0] === "-" ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY,
2412
+ resolve: (str9) => str9.slice(-3).toLowerCase() === "nan" ? NaN : str9[0] === "-" ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY,
2413
2413
  stringify: stringifyNumber.stringifyNumber
2414
2414
  };
2415
2415
  var floatExp = {
@@ -2418,7 +2418,7 @@ var require_float = __commonJS({
2418
2418
  tag: "tag:yaml.org,2002:float",
2419
2419
  format: "EXP",
2420
2420
  test: /^[-+]?(?:\.[0-9]+|[0-9]+(?:\.[0-9]*)?)[eE][-+]?[0-9]+$/,
2421
- resolve: (str8) => parseFloat(str8),
2421
+ resolve: (str9) => parseFloat(str9),
2422
2422
  stringify(node) {
2423
2423
  const num = Number(node.value);
2424
2424
  return isFinite(num) ? num.toExponential() : stringifyNumber.stringifyNumber(node);
@@ -2429,11 +2429,11 @@ var require_float = __commonJS({
2429
2429
  default: true,
2430
2430
  tag: "tag:yaml.org,2002:float",
2431
2431
  test: /^[-+]?(?:\.[0-9]+|[0-9]+\.[0-9]*)$/,
2432
- resolve(str8) {
2433
- const node = new Scalar.Scalar(parseFloat(str8));
2434
- const dot = str8.indexOf(".");
2435
- if (dot !== -1 && str8[str8.length - 1] === "0")
2436
- node.minFractionDigits = str8.length - dot - 1;
2432
+ resolve(str9) {
2433
+ const node = new Scalar.Scalar(parseFloat(str9));
2434
+ const dot = str9.indexOf(".");
2435
+ if (dot !== -1 && str9[str9.length - 1] === "0")
2436
+ node.minFractionDigits = str9.length - dot - 1;
2437
2437
  return node;
2438
2438
  },
2439
2439
  stringify: stringifyNumber.stringifyNumber
@@ -2450,7 +2450,7 @@ var require_int = __commonJS({
2450
2450
  "use strict";
2451
2451
  var stringifyNumber = require_stringifyNumber();
2452
2452
  var intIdentify = (value) => typeof value === "bigint" || Number.isInteger(value);
2453
- var intResolve = (str8, offset, radix, { intAsBigInt }) => intAsBigInt ? BigInt(str8) : parseInt(str8.substring(offset), radix);
2453
+ var intResolve = (str9, offset, radix, { intAsBigInt }) => intAsBigInt ? BigInt(str9) : parseInt(str9.substring(offset), radix);
2454
2454
  function intStringify(node, radix, prefix) {
2455
2455
  const { value } = node;
2456
2456
  if (intIdentify(value) && value >= 0)
@@ -2463,7 +2463,7 @@ var require_int = __commonJS({
2463
2463
  tag: "tag:yaml.org,2002:int",
2464
2464
  format: "OCT",
2465
2465
  test: /^0o[0-7]+$/,
2466
- resolve: (str8, _onError, opt) => intResolve(str8, 2, 8, opt),
2466
+ resolve: (str9, _onError, opt) => intResolve(str9, 2, 8, opt),
2467
2467
  stringify: (node) => intStringify(node, 8, "0o")
2468
2468
  };
2469
2469
  var int2 = {
@@ -2471,7 +2471,7 @@ var require_int = __commonJS({
2471
2471
  default: true,
2472
2472
  tag: "tag:yaml.org,2002:int",
2473
2473
  test: /^[-+]?[0-9]+$/,
2474
- resolve: (str8, _onError, opt) => intResolve(str8, 0, 10, opt),
2474
+ resolve: (str9, _onError, opt) => intResolve(str9, 0, 10, opt),
2475
2475
  stringify: stringifyNumber.stringifyNumber
2476
2476
  };
2477
2477
  var intHex = {
@@ -2480,7 +2480,7 @@ var require_int = __commonJS({
2480
2480
  tag: "tag:yaml.org,2002:int",
2481
2481
  format: "HEX",
2482
2482
  test: /^0x[0-9a-fA-F]+$/,
2483
- resolve: (str8, _onError, opt) => intResolve(str8, 2, 16, opt),
2483
+ resolve: (str9, _onError, opt) => intResolve(str9, 2, 16, opt),
2484
2484
  stringify: (node) => intStringify(node, 16, "0x")
2485
2485
  };
2486
2486
  exports.int = int2;
@@ -2533,7 +2533,7 @@ var require_schema2 = __commonJS({
2533
2533
  identify: (value) => typeof value === "string",
2534
2534
  default: true,
2535
2535
  tag: "tag:yaml.org,2002:str",
2536
- resolve: (str8) => str8,
2536
+ resolve: (str9) => str9,
2537
2537
  stringify: stringifyJSON
2538
2538
  },
2539
2539
  {
@@ -2550,7 +2550,7 @@ var require_schema2 = __commonJS({
2550
2550
  default: true,
2551
2551
  tag: "tag:yaml.org,2002:bool",
2552
2552
  test: /^true$|^false$/,
2553
- resolve: (str8) => str8 === "true",
2553
+ resolve: (str9) => str9 === "true",
2554
2554
  stringify: stringifyJSON
2555
2555
  },
2556
2556
  {
@@ -2558,7 +2558,7 @@ var require_schema2 = __commonJS({
2558
2558
  default: true,
2559
2559
  tag: "tag:yaml.org,2002:int",
2560
2560
  test: /^-?(?:0|[1-9][0-9]*)$/,
2561
- resolve: (str8, _onError, { intAsBigInt }) => intAsBigInt ? BigInt(str8) : parseInt(str8, 10),
2561
+ resolve: (str9, _onError, { intAsBigInt }) => intAsBigInt ? BigInt(str9) : parseInt(str9, 10),
2562
2562
  stringify: ({ value }) => intIdentify(value) ? value.toString() : JSON.stringify(value)
2563
2563
  },
2564
2564
  {
@@ -2566,7 +2566,7 @@ var require_schema2 = __commonJS({
2566
2566
  default: true,
2567
2567
  tag: "tag:yaml.org,2002:float",
2568
2568
  test: /^-?(?:0|[1-9][0-9]*)(?:\.[0-9]*)?(?:[eE][-+]?[0-9]+)?$/,
2569
- resolve: (str8) => parseFloat(str8),
2569
+ resolve: (str9) => parseFloat(str9),
2570
2570
  stringify: stringifyJSON
2571
2571
  }
2572
2572
  ];
@@ -2574,9 +2574,9 @@ var require_schema2 = __commonJS({
2574
2574
  default: true,
2575
2575
  tag: "",
2576
2576
  test: /^/,
2577
- resolve(str8, onError) {
2578
- onError(`Unresolved plain scalar ${JSON.stringify(str8)}`);
2579
- return str8;
2577
+ resolve(str9, onError) {
2578
+ onError(`Unresolved plain scalar ${JSON.stringify(str9)}`);
2579
+ return str9;
2580
2580
  }
2581
2581
  };
2582
2582
  var schema = [map.map, seq.seq].concat(jsonScalars, jsonError);
@@ -2608,10 +2608,10 @@ var require_binary = __commonJS({
2608
2608
  if (typeof node_buffer.Buffer === "function") {
2609
2609
  return node_buffer.Buffer.from(src, "base64");
2610
2610
  } else if (typeof atob === "function") {
2611
- const str8 = atob(src.replace(/[\n\r]/g, ""));
2612
- const buffer = new Uint8Array(str8.length);
2613
- for (let i = 0; i < str8.length; ++i)
2614
- buffer[i] = str8.charCodeAt(i);
2611
+ const str9 = atob(src.replace(/[\n\r]/g, ""));
2612
+ const buffer = new Uint8Array(str9.length);
2613
+ for (let i = 0; i < str9.length; ++i)
2614
+ buffer[i] = str9.charCodeAt(i);
2615
2615
  return buffer;
2616
2616
  } else {
2617
2617
  onError("This environment does not support reading binary tags; either Buffer or atob is required");
@@ -2622,28 +2622,28 @@ var require_binary = __commonJS({
2622
2622
  if (!value)
2623
2623
  return "";
2624
2624
  const buf = value;
2625
- let str8;
2625
+ let str9;
2626
2626
  if (typeof node_buffer.Buffer === "function") {
2627
- str8 = buf instanceof node_buffer.Buffer ? buf.toString("base64") : node_buffer.Buffer.from(buf.buffer).toString("base64");
2627
+ str9 = buf instanceof node_buffer.Buffer ? buf.toString("base64") : node_buffer.Buffer.from(buf.buffer).toString("base64");
2628
2628
  } else if (typeof btoa === "function") {
2629
2629
  let s = "";
2630
2630
  for (let i = 0; i < buf.length; ++i)
2631
2631
  s += String.fromCharCode(buf[i]);
2632
- str8 = btoa(s);
2632
+ str9 = btoa(s);
2633
2633
  } else {
2634
2634
  throw new Error("This environment does not support writing binary tags; either Buffer or btoa is required");
2635
2635
  }
2636
2636
  type ?? (type = Scalar.Scalar.BLOCK_LITERAL);
2637
2637
  if (type !== Scalar.Scalar.QUOTE_DOUBLE) {
2638
2638
  const lineWidth = Math.max(ctx.options.lineWidth - ctx.indent.length, ctx.options.minContentWidth);
2639
- const n = Math.ceil(str8.length / lineWidth);
2639
+ const n = Math.ceil(str9.length / lineWidth);
2640
2640
  const lines = new Array(n);
2641
2641
  for (let i = 0, o = 0; i < n; ++i, o += lineWidth) {
2642
- lines[i] = str8.substr(o, lineWidth);
2642
+ lines[i] = str9.substr(o, lineWidth);
2643
2643
  }
2644
- str8 = lines.join(type === Scalar.Scalar.BLOCK_LITERAL ? "\n" : " ");
2644
+ str9 = lines.join(type === Scalar.Scalar.BLOCK_LITERAL ? "\n" : " ");
2645
2645
  }
2646
- return stringifyString.stringifyString({ comment, type, value: str8 }, ctx, onComment, onChompKeep);
2646
+ return stringifyString.stringifyString({ comment, type, value: str9 }, ctx, onComment, onChompKeep);
2647
2647
  }
2648
2648
  };
2649
2649
  exports.binary = binary;
@@ -2849,7 +2849,7 @@ var require_float2 = __commonJS({
2849
2849
  default: true,
2850
2850
  tag: "tag:yaml.org,2002:float",
2851
2851
  test: /^(?:[-+]?\.(?:inf|Inf|INF)|\.nan|\.NaN|\.NAN)$/,
2852
- resolve: (str8) => str8.slice(-3).toLowerCase() === "nan" ? NaN : str8[0] === "-" ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY,
2852
+ resolve: (str9) => str9.slice(-3).toLowerCase() === "nan" ? NaN : str9[0] === "-" ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY,
2853
2853
  stringify: stringifyNumber.stringifyNumber
2854
2854
  };
2855
2855
  var floatExp = {
@@ -2858,7 +2858,7 @@ var require_float2 = __commonJS({
2858
2858
  tag: "tag:yaml.org,2002:float",
2859
2859
  format: "EXP",
2860
2860
  test: /^[-+]?(?:[0-9][0-9_]*)?(?:\.[0-9_]*)?[eE][-+]?[0-9]+$/,
2861
- resolve: (str8) => parseFloat(str8.replace(/_/g, "")),
2861
+ resolve: (str9) => parseFloat(str9.replace(/_/g, "")),
2862
2862
  stringify(node) {
2863
2863
  const num = Number(node.value);
2864
2864
  return isFinite(num) ? num.toExponential() : stringifyNumber.stringifyNumber(node);
@@ -2869,11 +2869,11 @@ var require_float2 = __commonJS({
2869
2869
  default: true,
2870
2870
  tag: "tag:yaml.org,2002:float",
2871
2871
  test: /^[-+]?(?:[0-9][0-9_]*)?\.[0-9_]*$/,
2872
- resolve(str8) {
2873
- const node = new Scalar.Scalar(parseFloat(str8.replace(/_/g, "")));
2874
- const dot = str8.indexOf(".");
2872
+ resolve(str9) {
2873
+ const node = new Scalar.Scalar(parseFloat(str9.replace(/_/g, "")));
2874
+ const dot = str9.indexOf(".");
2875
2875
  if (dot !== -1) {
2876
- const f = str8.substring(dot + 1).replace(/_/g, "");
2876
+ const f = str9.substring(dot + 1).replace(/_/g, "");
2877
2877
  if (f[f.length - 1] === "0")
2878
2878
  node.minFractionDigits = f.length;
2879
2879
  }
@@ -2893,34 +2893,34 @@ var require_int2 = __commonJS({
2893
2893
  "use strict";
2894
2894
  var stringifyNumber = require_stringifyNumber();
2895
2895
  var intIdentify = (value) => typeof value === "bigint" || Number.isInteger(value);
2896
- function intResolve(str8, offset, radix, { intAsBigInt }) {
2897
- const sign = str8[0];
2896
+ function intResolve(str9, offset, radix, { intAsBigInt }) {
2897
+ const sign = str9[0];
2898
2898
  if (sign === "-" || sign === "+")
2899
2899
  offset += 1;
2900
- str8 = str8.substring(offset).replace(/_/g, "");
2900
+ str9 = str9.substring(offset).replace(/_/g, "");
2901
2901
  if (intAsBigInt) {
2902
2902
  switch (radix) {
2903
2903
  case 2:
2904
- str8 = `0b${str8}`;
2904
+ str9 = `0b${str9}`;
2905
2905
  break;
2906
2906
  case 8:
2907
- str8 = `0o${str8}`;
2907
+ str9 = `0o${str9}`;
2908
2908
  break;
2909
2909
  case 16:
2910
- str8 = `0x${str8}`;
2910
+ str9 = `0x${str9}`;
2911
2911
  break;
2912
2912
  }
2913
- const n2 = BigInt(str8);
2913
+ const n2 = BigInt(str9);
2914
2914
  return sign === "-" ? BigInt(-1) * n2 : n2;
2915
2915
  }
2916
- const n = parseInt(str8, radix);
2916
+ const n = parseInt(str9, radix);
2917
2917
  return sign === "-" ? -1 * n : n;
2918
2918
  }
2919
2919
  function intStringify(node, radix, prefix) {
2920
2920
  const { value } = node;
2921
2921
  if (intIdentify(value)) {
2922
- const str8 = value.toString(radix);
2923
- return value < 0 ? "-" + prefix + str8.substr(1) : prefix + str8;
2922
+ const str9 = value.toString(radix);
2923
+ return value < 0 ? "-" + prefix + str9.substr(1) : prefix + str9;
2924
2924
  }
2925
2925
  return stringifyNumber.stringifyNumber(node);
2926
2926
  }
@@ -2930,7 +2930,7 @@ var require_int2 = __commonJS({
2930
2930
  tag: "tag:yaml.org,2002:int",
2931
2931
  format: "BIN",
2932
2932
  test: /^[-+]?0b[0-1_]+$/,
2933
- resolve: (str8, _onError, opt) => intResolve(str8, 2, 2, opt),
2933
+ resolve: (str9, _onError, opt) => intResolve(str9, 2, 2, opt),
2934
2934
  stringify: (node) => intStringify(node, 2, "0b")
2935
2935
  };
2936
2936
  var intOct = {
@@ -2939,7 +2939,7 @@ var require_int2 = __commonJS({
2939
2939
  tag: "tag:yaml.org,2002:int",
2940
2940
  format: "OCT",
2941
2941
  test: /^[-+]?0[0-7_]+$/,
2942
- resolve: (str8, _onError, opt) => intResolve(str8, 1, 8, opt),
2942
+ resolve: (str9, _onError, opt) => intResolve(str9, 1, 8, opt),
2943
2943
  stringify: (node) => intStringify(node, 8, "0")
2944
2944
  };
2945
2945
  var int2 = {
@@ -2947,7 +2947,7 @@ var require_int2 = __commonJS({
2947
2947
  default: true,
2948
2948
  tag: "tag:yaml.org,2002:int",
2949
2949
  test: /^[-+]?[0-9][0-9_]*$/,
2950
- resolve: (str8, _onError, opt) => intResolve(str8, 0, 10, opt),
2950
+ resolve: (str9, _onError, opt) => intResolve(str9, 0, 10, opt),
2951
2951
  stringify: stringifyNumber.stringifyNumber
2952
2952
  };
2953
2953
  var intHex = {
@@ -2956,7 +2956,7 @@ var require_int2 = __commonJS({
2956
2956
  tag: "tag:yaml.org,2002:int",
2957
2957
  format: "HEX",
2958
2958
  test: /^[-+]?0x[0-9a-fA-F_]+$/,
2959
- resolve: (str8, _onError, opt) => intResolve(str8, 2, 16, opt),
2959
+ resolve: (str9, _onError, opt) => intResolve(str9, 2, 16, opt),
2960
2960
  stringify: (node) => intStringify(node, 16, "0x")
2961
2961
  };
2962
2962
  exports.int = int2;
@@ -3060,9 +3060,9 @@ var require_timestamp = __commonJS({
3060
3060
  "node_modules/yaml/dist/schema/yaml-1.1/timestamp.js"(exports) {
3061
3061
  "use strict";
3062
3062
  var stringifyNumber = require_stringifyNumber();
3063
- function parseSexagesimal(str8, asBigInt) {
3064
- const sign = str8[0];
3065
- const parts = sign === "-" || sign === "+" ? str8.substring(1) : str8;
3063
+ function parseSexagesimal(str9, asBigInt) {
3064
+ const sign = str9[0];
3065
+ const parts = sign === "-" || sign === "+" ? str9.substring(1) : str9;
3066
3066
  const num = (n) => asBigInt ? BigInt(n) : Number(n);
3067
3067
  const res = parts.replace(/_/g, "").split(":").reduce((res2, p) => res2 * num(60) + num(p), num(0));
3068
3068
  return sign === "-" ? num(-1) * res : res;
@@ -3099,7 +3099,7 @@ var require_timestamp = __commonJS({
3099
3099
  tag: "tag:yaml.org,2002:int",
3100
3100
  format: "TIME",
3101
3101
  test: /^[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+$/,
3102
- resolve: (str8, _onError, { intAsBigInt }) => parseSexagesimal(str8, intAsBigInt),
3102
+ resolve: (str9, _onError, { intAsBigInt }) => parseSexagesimal(str9, intAsBigInt),
3103
3103
  stringify: stringifySexagesimal
3104
3104
  };
3105
3105
  var floatTime = {
@@ -3108,7 +3108,7 @@ var require_timestamp = __commonJS({
3108
3108
  tag: "tag:yaml.org,2002:float",
3109
3109
  format: "TIME",
3110
3110
  test: /^[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\.[0-9_]*$/,
3111
- resolve: (str8) => parseSexagesimal(str8, false),
3111
+ resolve: (str9) => parseSexagesimal(str9, false),
3112
3112
  stringify: stringifySexagesimal
3113
3113
  };
3114
3114
  var timestamp = {
@@ -3119,8 +3119,8 @@ var require_timestamp = __commonJS({
3119
3119
  // may be omitted altogether, resulting in a date format. In such a case, the time part is
3120
3120
  // assumed to be 00:00:00Z (start of day, UTC).
3121
3121
  test: RegExp("^([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})(?:(?:t|T|[ \\t]+)([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2}(\\.[0-9]+)?)(?:[ \\t]*(Z|[-+][012]?[0-9](?::[0-9]{2})?))?)?$"),
3122
- resolve(str8) {
3123
- const match = str8.match(timestamp.test);
3122
+ resolve(str9) {
3123
+ const match = str9.match(timestamp.test);
3124
3124
  if (!match)
3125
3125
  throw new Error("!!timestamp expects a date, starting with yyyy-mm-dd");
3126
3126
  const [, year, month, day, hour, minute, second] = match.map(Number);
@@ -3471,9 +3471,9 @@ var require_Document = __commonJS({
3471
3471
  this.contents.add(value);
3472
3472
  }
3473
3473
  /** Adds a value to the document. */
3474
- addIn(path69, value) {
3474
+ addIn(path71, value) {
3475
3475
  if (assertCollection(this.contents))
3476
- this.contents.addIn(path69, value);
3476
+ this.contents.addIn(path71, value);
3477
3477
  }
3478
3478
  /**
3479
3479
  * Create a new `Alias` node, ensuring that the target `node` has the required anchor.
@@ -3548,14 +3548,14 @@ var require_Document = __commonJS({
3548
3548
  * Removes a value from the document.
3549
3549
  * @returns `true` if the item was found and removed.
3550
3550
  */
3551
- deleteIn(path69) {
3552
- if (Collection.isEmptyPath(path69)) {
3551
+ deleteIn(path71) {
3552
+ if (Collection.isEmptyPath(path71)) {
3553
3553
  if (this.contents == null)
3554
3554
  return false;
3555
3555
  this.contents = null;
3556
3556
  return true;
3557
3557
  }
3558
- return assertCollection(this.contents) ? this.contents.deleteIn(path69) : false;
3558
+ return assertCollection(this.contents) ? this.contents.deleteIn(path71) : false;
3559
3559
  }
3560
3560
  /**
3561
3561
  * Returns item at `key`, or `undefined` if not found. By default unwraps
@@ -3570,10 +3570,10 @@ var require_Document = __commonJS({
3570
3570
  * scalar values from their surrounding node; to disable set `keepScalar` to
3571
3571
  * `true` (collections are always returned intact).
3572
3572
  */
3573
- getIn(path69, keepScalar) {
3574
- if (Collection.isEmptyPath(path69))
3573
+ getIn(path71, keepScalar) {
3574
+ if (Collection.isEmptyPath(path71))
3575
3575
  return !keepScalar && identity.isScalar(this.contents) ? this.contents.value : this.contents;
3576
- return identity.isCollection(this.contents) ? this.contents.getIn(path69, keepScalar) : void 0;
3576
+ return identity.isCollection(this.contents) ? this.contents.getIn(path71, keepScalar) : void 0;
3577
3577
  }
3578
3578
  /**
3579
3579
  * Checks if the document includes a value with the key `key`.
@@ -3584,10 +3584,10 @@ var require_Document = __commonJS({
3584
3584
  /**
3585
3585
  * Checks if the document includes a value at `path`.
3586
3586
  */
3587
- hasIn(path69) {
3588
- if (Collection.isEmptyPath(path69))
3587
+ hasIn(path71) {
3588
+ if (Collection.isEmptyPath(path71))
3589
3589
  return this.contents !== void 0;
3590
- return identity.isCollection(this.contents) ? this.contents.hasIn(path69) : false;
3590
+ return identity.isCollection(this.contents) ? this.contents.hasIn(path71) : false;
3591
3591
  }
3592
3592
  /**
3593
3593
  * Sets a value in this document. For `!!set`, `value` needs to be a
@@ -3604,13 +3604,13 @@ var require_Document = __commonJS({
3604
3604
  * Sets a value in this document. For `!!set`, `value` needs to be a
3605
3605
  * boolean to add/remove the item from the set.
3606
3606
  */
3607
- setIn(path69, value) {
3608
- if (Collection.isEmptyPath(path69)) {
3607
+ setIn(path71, value) {
3608
+ if (Collection.isEmptyPath(path71)) {
3609
3609
  this.contents = value;
3610
3610
  } else if (this.contents == null) {
3611
- this.contents = Collection.collectionFromPath(this.schema, Array.from(path69), value);
3611
+ this.contents = Collection.collectionFromPath(this.schema, Array.from(path71), value);
3612
3612
  } else if (assertCollection(this.contents)) {
3613
- this.contents.setIn(path69, value);
3613
+ this.contents.setIn(path71, value);
3614
3614
  }
3615
3615
  }
3616
3616
  /**
@@ -5570,9 +5570,9 @@ var require_cst_visit = __commonJS({
5570
5570
  visit.BREAK = BREAK;
5571
5571
  visit.SKIP = SKIP;
5572
5572
  visit.REMOVE = REMOVE;
5573
- visit.itemAtPath = (cst, path69) => {
5573
+ visit.itemAtPath = (cst, path71) => {
5574
5574
  let item = cst;
5575
- for (const [field, index] of path69) {
5575
+ for (const [field, index] of path71) {
5576
5576
  const tok = item?.[field];
5577
5577
  if (tok && "items" in tok) {
5578
5578
  item = tok.items[index];
@@ -5581,23 +5581,23 @@ var require_cst_visit = __commonJS({
5581
5581
  }
5582
5582
  return item;
5583
5583
  };
5584
- visit.parentCollection = (cst, path69) => {
5585
- const parent = visit.itemAtPath(cst, path69.slice(0, -1));
5586
- const field = path69[path69.length - 1][0];
5584
+ visit.parentCollection = (cst, path71) => {
5585
+ const parent = visit.itemAtPath(cst, path71.slice(0, -1));
5586
+ const field = path71[path71.length - 1][0];
5587
5587
  const coll = parent?.[field];
5588
5588
  if (coll && "items" in coll)
5589
5589
  return coll;
5590
5590
  throw new Error("Parent collection not found");
5591
5591
  };
5592
- function _visit(path69, item, visitor) {
5593
- let ctrl = visitor(item, path69);
5592
+ function _visit(path71, item, visitor) {
5593
+ let ctrl = visitor(item, path71);
5594
5594
  if (typeof ctrl === "symbol")
5595
5595
  return ctrl;
5596
5596
  for (const field of ["key", "value"]) {
5597
5597
  const token = item[field];
5598
5598
  if (token && "items" in token) {
5599
5599
  for (let i = 0; i < token.items.length; ++i) {
5600
- const ci = _visit(Object.freeze(path69.concat([[field, i]])), token.items[i], visitor);
5600
+ const ci = _visit(Object.freeze(path71.concat([[field, i]])), token.items[i], visitor);
5601
5601
  if (typeof ci === "number")
5602
5602
  i = ci - 1;
5603
5603
  else if (ci === BREAK)
@@ -5608,10 +5608,10 @@ var require_cst_visit = __commonJS({
5608
5608
  }
5609
5609
  }
5610
5610
  if (typeof ctrl === "function" && field === "key")
5611
- ctrl = ctrl(item, path69);
5611
+ ctrl = ctrl(item, path71);
5612
5612
  }
5613
5613
  }
5614
- return typeof ctrl === "function" ? ctrl(item, path69) : ctrl;
5614
+ return typeof ctrl === "function" ? ctrl(item, path71) : ctrl;
5615
5615
  }
5616
5616
  exports.visit = visit;
5617
5617
  }
@@ -6913,14 +6913,14 @@ var require_parser = __commonJS({
6913
6913
  case "scalar":
6914
6914
  case "single-quoted-scalar":
6915
6915
  case "double-quoted-scalar": {
6916
- const fs66 = this.flowScalar(this.type);
6916
+ const fs68 = this.flowScalar(this.type);
6917
6917
  if (atNextItem || it.value) {
6918
- map.items.push({ start, key: fs66, sep: [] });
6918
+ map.items.push({ start, key: fs68, sep: [] });
6919
6919
  this.onKeyLine = true;
6920
6920
  } else if (it.sep) {
6921
- this.stack.push(fs66);
6921
+ this.stack.push(fs68);
6922
6922
  } else {
6923
- Object.assign(it, { key: fs66, sep: [] });
6923
+ Object.assign(it, { key: fs68, sep: [] });
6924
6924
  this.onKeyLine = true;
6925
6925
  }
6926
6926
  return;
@@ -7048,13 +7048,13 @@ var require_parser = __commonJS({
7048
7048
  case "scalar":
7049
7049
  case "single-quoted-scalar":
7050
7050
  case "double-quoted-scalar": {
7051
- const fs66 = this.flowScalar(this.type);
7051
+ const fs68 = this.flowScalar(this.type);
7052
7052
  if (!it || it.value)
7053
- fc.items.push({ start: [], key: fs66, sep: [] });
7053
+ fc.items.push({ start: [], key: fs68, sep: [] });
7054
7054
  else if (it.sep)
7055
- this.stack.push(fs66);
7055
+ this.stack.push(fs68);
7056
7056
  else
7057
- Object.assign(it, { key: fs66, sep: [] });
7057
+ Object.assign(it, { key: fs68, sep: [] });
7058
7058
  return;
7059
7059
  }
7060
7060
  case "flow-map-end":
@@ -7363,15 +7363,15 @@ var require_dist = __commonJS({
7363
7363
  });
7364
7364
 
7365
7365
  // src/scripts/hooks/dispatch_entry.ts
7366
- import * as path68 from "node:path";
7367
- import { fileURLToPath as fileURLToPath48 } from "node:url";
7366
+ import * as path70 from "node:path";
7367
+ import { fileURLToPath as fileURLToPath50 } from "node:url";
7368
7368
 
7369
7369
  // src/scripts/hooks/dispatch_hook.ts
7370
7370
  var import_yaml6 = __toESM(require_dist(), 1);
7371
7371
  import { spawnSync as spawnSync7 } from "node:child_process";
7372
- import fs65 from "node:fs";
7373
- import path67 from "node:path";
7374
- import { fileURLToPath as fileURLToPath47, pathToFileURL as pathToFileURL41 } from "node:url";
7372
+ import fs67 from "node:fs";
7373
+ import path69 from "node:path";
7374
+ import { fileURLToPath as fileURLToPath49, pathToFileURL as pathToFileURL43 } from "node:url";
7375
7375
 
7376
7376
  // src/scripts/_lib/spawn_env.ts
7377
7377
  var DENY_EXACT = /* @__PURE__ */ new Set([
@@ -25711,12 +25711,461 @@ if (_isCliEntry31()) {
25711
25711
  }
25712
25712
 
25713
25713
  // src/scripts/hooks/turn_end_gate_hook.ts
25714
+ import * as crypto7 from "node:crypto";
25715
+ import * as fs61 from "node:fs";
25716
+ import * as path62 from "node:path";
25717
+ import { fileURLToPath as fileURLToPath44, pathToFileURL as pathToFileURL38 } from "node:url";
25718
+
25719
+ // src/scripts/hooks/subagent_ledger_hook.ts
25714
25720
  import * as crypto6 from "node:crypto";
25715
25721
  import * as fs60 from "node:fs";
25716
25722
  import * as path61 from "node:path";
25717
25723
  import { fileURLToPath as fileURLToPath43, pathToFileURL as pathToFileURL37 } from "node:url";
25718
- var EXIT_BLOCK4 = 1;
25724
+
25725
+ // src/scripts/_lib/subagent_response.ts
25726
+ var MAX_SUMMARY_CHARS = 2e3;
25727
+ var MAX_RESPONSE_LINE_CHARS = 240;
25728
+ var MAX_RESPONSE_ENTRIES = 40;
25729
+ var MAX_ARTIFACT_REF_CHARS = 200;
25730
+ var MAX_ENVELOPE_CHARS = 12e3;
25731
+ var CONFIDENCE = /* @__PURE__ */ new Set(["low", "medium", "high"]);
25732
+ function validateResponse(input) {
25733
+ const errors = [];
25734
+ if (input === null || typeof input !== "object") {
25735
+ return { valid: false, errors: ["response is not an object"] };
25736
+ }
25737
+ const r = input;
25738
+ if (typeof r.summary !== "string") errors.push("summary missing or not a string");
25739
+ if (typeof r.handoff !== "string") errors.push("handoff missing or not a string");
25740
+ if (!CONFIDENCE.has(r.confidence)) errors.push(`confidence must be low|medium|high (got ${String(r.confidence)})`);
25741
+ if (!Array.isArray(r.findings)) errors.push("findings missing or not an array");
25742
+ if (!Array.isArray(r.risks)) errors.push("risks missing or not an array");
25743
+ if (Array.isArray(r.findings)) {
25744
+ for (const [i, f] of r.findings.entries()) {
25745
+ if (!f || typeof f.title !== "string") errors.push(`finding[${i}] missing title`);
25746
+ const refs = f?.evidence_refs;
25747
+ if (refs && refs.some((x) => typeof x !== "string" || x.includes("\n"))) {
25748
+ errors.push(`finding[${i}] evidence_refs must be ref tokens, not bodies`);
25749
+ }
25750
+ }
25751
+ }
25752
+ if (r.assumptions !== void 0) {
25753
+ if (!Array.isArray(r.assumptions)) {
25754
+ errors.push("assumptions must be an array of {statement, basis, epistemic_state}");
25755
+ } else {
25756
+ for (const [i, a] of r.assumptions.entries()) {
25757
+ errors.push(...validateAssumption(a, `assumptions[${i}]`));
25758
+ }
25759
+ }
25760
+ }
25761
+ if (typeof r.summary === "string" && r.summary.length > MAX_SUMMARY_CHARS) {
25762
+ errors.push(`summary is ${r.summary.length} chars (max ${MAX_SUMMARY_CHARS}) \u2014 the envelope carries a bounded summary; the full result belongs on disk (artifact_paths)`);
25763
+ }
25764
+ if (typeof r.handoff === "string" && r.handoff.length > MAX_RESPONSE_LINE_CHARS) {
25765
+ errors.push(`handoff is ${r.handoff.length} chars (max ${MAX_RESPONSE_LINE_CHARS})`);
25766
+ }
25767
+ for (const [key, arr] of [
25768
+ ["findings", r.findings],
25769
+ ["risks", r.risks],
25770
+ ["artifact_paths", r.artifact_paths]
25771
+ ]) {
25772
+ if (Array.isArray(arr) && arr.length > MAX_RESPONSE_ENTRIES) {
25773
+ errors.push(`${key} carries ${arr.length} entries (max ${MAX_RESPONSE_ENTRIES}) \u2014 an envelope is a handoff, not a transcript`);
25774
+ }
25775
+ }
25776
+ if (Array.isArray(r.risks)) {
25777
+ for (const [i, risk] of r.risks.entries()) {
25778
+ if (typeof risk === "string" && risk.length > MAX_RESPONSE_LINE_CHARS) {
25779
+ errors.push(`risks[${i}] is ${risk.length} chars (max ${MAX_RESPONSE_LINE_CHARS})`);
25780
+ }
25781
+ }
25782
+ }
25783
+ if (Array.isArray(r.findings)) {
25784
+ for (const [i, f] of r.findings.entries()) {
25785
+ if (f && typeof f.title === "string" && f.title.length > MAX_RESPONSE_LINE_CHARS) {
25786
+ errors.push(`finding[${i}] title is ${f.title.length} chars (max ${MAX_RESPONSE_LINE_CHARS})`);
25787
+ }
25788
+ }
25789
+ }
25790
+ if (r.artifact_paths !== void 0) {
25791
+ if (!Array.isArray(r.artifact_paths)) {
25792
+ errors.push("artifact_paths must be an array of path ref tokens");
25793
+ } else {
25794
+ for (const [i, p] of r.artifact_paths.entries()) {
25795
+ if (typeof p !== "string" || p.includes("\n") || p.length > MAX_ARTIFACT_REF_CHARS) {
25796
+ errors.push(`artifact_paths[${i}] must be a single-line path ref \u2264 ${MAX_ARTIFACT_REF_CHARS} chars`);
25797
+ }
25798
+ }
25799
+ }
25800
+ }
25801
+ try {
25802
+ const serialized = JSON.stringify(input);
25803
+ if (serialized.length > MAX_ENVELOPE_CHARS) {
25804
+ errors.push(`envelope serializes to ${serialized.length} chars (max ${MAX_ENVELOPE_CHARS}) \u2014 move content to disk and reference it via artifact_paths`);
25805
+ }
25806
+ } catch {
25807
+ errors.push("envelope is not JSON-serializable");
25808
+ }
25809
+ return { valid: errors.length === 0, errors };
25810
+ }
25811
+
25812
+ // src/scripts/hooks/subagent_ledger_hook.ts
25719
25813
  var EXIT_ALLOW18 = 0;
25814
+ function isObject7(v) {
25815
+ return typeof v === "object" && v !== null && !Array.isArray(v);
25816
+ }
25817
+ var LEDGER_DIR = path61.join("agents", "runtime", "state", "subagent-ledger");
25818
+ var OPEN_SUBDIR = "open";
25819
+ var OPEN_RECORD_TTL_MS = 24 * 60 * 60 * 1e3;
25820
+ function refFor(agentId) {
25821
+ return crypto6.createHash("sha256").update(agentId, "utf8").digest("hex").slice(0, 12);
25822
+ }
25823
+ function unwrapPayload2(envelope) {
25824
+ const inner = envelope["payload"];
25825
+ return isObject7(inner) ? inner : envelope;
25826
+ }
25827
+ function str4(payload, ...keys) {
25828
+ for (const k of keys) {
25829
+ const v = payload[k];
25830
+ if (typeof v === "string" && v) return v;
25831
+ }
25832
+ return null;
25833
+ }
25834
+ function extractParentId(payload, ownId) {
25835
+ const explicit = str4(payload, "parent_agent_id", "parentAgentId");
25836
+ if (explicit) return explicit;
25837
+ const session = payload["session"];
25838
+ if (isObject7(session)) {
25839
+ const sessionAgent = str4(session, "agent_id", "agentId");
25840
+ if (sessionAgent && sessionAgent !== ownId) return sessionAgent;
25841
+ }
25842
+ return null;
25843
+ }
25844
+ function classifyEnvelope(message) {
25845
+ if (message === null || !message.trim()) return { verdict: "absent", error_count: 0 };
25846
+ const candidates = _jsonObjectCandidates(message);
25847
+ if (candidates.length === 0) return { verdict: "absent", error_count: 0 };
25848
+ let best = null;
25849
+ for (const candidate of candidates) {
25850
+ const result = validateResponse(candidate);
25851
+ if (result.valid) return { verdict: "ok", error_count: 0 };
25852
+ if (best === null) best = { verdict: "fail", error_count: result.errors.length };
25853
+ }
25854
+ return best ?? { verdict: "absent", error_count: 0 };
25855
+ }
25856
+ function _jsonObjectCandidates(message) {
25857
+ const texts = [];
25858
+ for (const match of message.matchAll(/^[ \t]*```[ \t]*(?:json)?[ \t]*\r?\n([\s\S]*?)^[ \t]*```/gm)) {
25859
+ if (match[1]) texts.push(match[1]);
25860
+ }
25861
+ let depth = 0;
25862
+ let start = -1;
25863
+ let inString = false;
25864
+ let escaped = false;
25865
+ for (let i = 0; i < message.length; i++) {
25866
+ const ch = message[i];
25867
+ if (inString) {
25868
+ if (escaped) escaped = false;
25869
+ else if (ch === "\\") escaped = true;
25870
+ else if (ch === '"') inString = false;
25871
+ continue;
25872
+ }
25873
+ if (ch === '"') inString = true;
25874
+ else if (ch === "{") {
25875
+ if (depth === 0) start = i;
25876
+ depth++;
25877
+ } else if (ch === "}") {
25878
+ if (depth > 0) {
25879
+ depth--;
25880
+ if (depth === 0 && start !== -1) {
25881
+ texts.push(message.slice(start, i + 1));
25882
+ start = -1;
25883
+ }
25884
+ }
25885
+ }
25886
+ }
25887
+ const out = [];
25888
+ for (const text of texts) {
25889
+ try {
25890
+ const parsed = JSON.parse(text.trim());
25891
+ if (parsed !== null && typeof parsed === "object" && !Array.isArray(parsed)) out.push(parsed);
25892
+ } catch {
25893
+ }
25894
+ }
25895
+ return out;
25896
+ }
25897
+ function openDir(root) {
25898
+ return path61.join(root, LEDGER_DIR, OPEN_SUBDIR);
25899
+ }
25900
+ function openFile(root, ref) {
25901
+ return path61.join(openDir(root), `${ref}.json`);
25902
+ }
25903
+ var DEPTH_BASES = /* @__PURE__ */ new Set(["observed", "asserted-parent", "assumed-root"]);
25904
+ function _asOpenRecord(value, expectedRef) {
25905
+ if (!isObject7(value)) return null;
25906
+ const ref = value["ref"];
25907
+ if (typeof ref !== "string" || ref !== expectedRef) return null;
25908
+ if (typeof value["started_at"] !== "string") return null;
25909
+ if (typeof value["depth"] !== "number" || !Number.isFinite(value["depth"])) return null;
25910
+ if (typeof value["depth_basis"] !== "string" || !DEPTH_BASES.has(value["depth_basis"])) return null;
25911
+ const agentType = value["agent_type"];
25912
+ const parentRef = value["parent_ref"];
25913
+ const sessionId2 = value["session_id"];
25914
+ return {
25915
+ ref,
25916
+ agent_type: typeof agentType === "string" ? agentType : null,
25917
+ started_at: value["started_at"],
25918
+ parent_ref: typeof parentRef === "string" ? parentRef : null,
25919
+ depth: value["depth"],
25920
+ depth_basis: value["depth_basis"],
25921
+ session_id: typeof sessionId2 === "string" ? sessionId2 : null
25922
+ };
25923
+ }
25924
+ function readOpenRecords(root) {
25925
+ const out = /* @__PURE__ */ new Map();
25926
+ let names;
25927
+ try {
25928
+ names = fs60.readdirSync(openDir(root));
25929
+ } catch {
25930
+ return out;
25931
+ }
25932
+ for (const name of names) {
25933
+ if (!name.endsWith(".json")) continue;
25934
+ const expectedRef = name.slice(0, -".json".length);
25935
+ try {
25936
+ const raw = fs60.readFileSync(path61.join(openDir(root), name), "utf8");
25937
+ const rec = _asOpenRecord(JSON.parse(raw), expectedRef);
25938
+ if (rec) out.set(rec.ref, rec);
25939
+ } catch {
25940
+ }
25941
+ }
25942
+ return out;
25943
+ }
25944
+ function resolveDepth(parentRef, open) {
25945
+ if (parentRef === null) return { depth: 1, depth_basis: "assumed-root" };
25946
+ const parent = open.get(parentRef);
25947
+ if (!parent) return { depth: 2, depth_basis: "asserted-parent" };
25948
+ return { depth: parent.depth + 1, depth_basis: "observed" };
25949
+ }
25950
+ function ledgerFileFor(root, ts) {
25951
+ return path61.join(root, LEDGER_DIR, `${ts.slice(0, 7)}.jsonl`);
25952
+ }
25953
+ function appendLedgerLine(root, ts, line) {
25954
+ if (is_replay_mode()) return;
25955
+ const file = ledgerFileFor(root, ts);
25956
+ fs60.mkdirSync(path61.dirname(file), { recursive: true });
25957
+ fs60.appendFileSync(file, `${JSON.stringify(line)}
25958
+ `, "utf8");
25959
+ }
25960
+ var WALL_CLOCK_ARMS_MS = [
25961
+ { label: "5m", ms: 5 * 60 * 1e3 },
25962
+ { label: "15m", ms: 15 * 60 * 1e3 },
25963
+ { label: "30m", ms: 30 * 60 * 1e3 },
25964
+ { label: "2h", ms: 2 * 60 * 60 * 1e3 }
25965
+ ];
25966
+ function armsExceeded(elapsedMs) {
25967
+ if (elapsedMs === null || !Number.isFinite(elapsedMs)) return [];
25968
+ return WALL_CLOCK_ARMS_MS.filter((a) => elapsedMs >= a.ms).map((a) => a.label);
25969
+ }
25970
+ function openRecordStats(root, nowMs = Date.now()) {
25971
+ const ledgerPresent = fs60.existsSync(path61.join(root, LEDGER_DIR));
25972
+ const open = readOpenRecords(root);
25973
+ let maxDepth = 0;
25974
+ let counted = 0;
25975
+ let stale = 0;
25976
+ for (const rec of open.values()) {
25977
+ const started = Date.parse(rec.started_at);
25978
+ const isStale2 = Number.isFinite(started) && nowMs - started >= OPEN_RECORD_TTL_MS;
25979
+ if (isStale2) {
25980
+ stale++;
25981
+ continue;
25982
+ }
25983
+ counted++;
25984
+ if (rec.depth > maxDepth) maxDepth = rec.depth;
25985
+ }
25986
+ return {
25987
+ open_count: counted,
25988
+ max_depth: maxDepth,
25989
+ stale_excluded: stale,
25990
+ ledger_present: ledgerPresent
25991
+ };
25992
+ }
25993
+ function writeOpenRecord(root, rec) {
25994
+ atomic_write_json(openFile(root, rec.ref), rec);
25995
+ }
25996
+ function removeOpenRecord(root, ref) {
25997
+ if (is_replay_mode()) return;
25998
+ try {
25999
+ fs60.unlinkSync(openFile(root, ref));
26000
+ } catch {
26001
+ }
26002
+ }
26003
+ function countOpen(root) {
26004
+ try {
26005
+ return fs60.readdirSync(openDir(root)).filter((n) => n.endsWith(".json")).length;
26006
+ } catch {
26007
+ return 0;
26008
+ }
26009
+ }
26010
+ function reapStaleOpenRecords(root, nowIso) {
26011
+ const now = Date.parse(nowIso);
26012
+ if (!Number.isFinite(now)) return 0;
26013
+ let reaped = 0;
26014
+ for (const rec of readOpenRecords(root).values()) {
26015
+ const started = Date.parse(rec.started_at);
26016
+ if (!Number.isFinite(started) || now - started < OPEN_RECORD_TTL_MS) continue;
26017
+ removeOpenRecord(root, rec.ref);
26018
+ reaped++;
26019
+ appendLedgerLine(root, nowIso, {
26020
+ event: "subagent_reaped",
26021
+ ts: nowIso,
26022
+ ref: rec.ref,
26023
+ agent_type: rec.agent_type,
26024
+ depth: rec.depth,
26025
+ depth_basis: rec.depth_basis,
26026
+ // R2 round 2, finding 5: the arm list is NOT repeated here. A reap
26027
+ // fires only past OPEN_RECORD_TTL_MS (24 h), which exceeds every
26028
+ // arm (largest: 2 h), so `stop_loss_arms_exceeded` would be a
26029
+ // constant on this line — a field that cannot vary answers no
26030
+ // question. `age_ms` carries strictly more information and is what
26031
+ // a reader should aggregate over.
26032
+ age_ms: now - started,
26033
+ reason: "open record exceeded OPEN_RECORD_TTL_MS without a stop"
26034
+ });
26035
+ }
26036
+ return reaped;
26037
+ }
26038
+ function appendUnidentified(root, event, nowIso, payload) {
26039
+ appendLedgerLine(root, nowIso, {
26040
+ event,
26041
+ ts: nowIso,
26042
+ ref: null,
26043
+ unidentified: true,
26044
+ // The agent TYPE is an id-shaped enum and may still be present; it is
26045
+ // the only thing salvageable from a payload with no id.
26046
+ agent_type: str4(payload, "agent_type", "agentType", "subagent_type", "subagentType"),
26047
+ reason: "payload carried no agent id \u2014 nothing to correlate start with stop"
26048
+ });
26049
+ }
26050
+ function handleStart(root, payload, nowIso, sessionId2) {
26051
+ const agentId = str4(payload, "agent_id", "agentId");
26052
+ if (agentId === null) {
26053
+ appendUnidentified(root, "subagent_start", nowIso, payload);
26054
+ return;
26055
+ }
26056
+ const ref = refFor(agentId);
26057
+ const parentId = extractParentId(payload, agentId);
26058
+ const parentRef = parentId ? refFor(parentId) : null;
26059
+ const { depth, depth_basis } = resolveDepth(parentRef, readOpenRecords(root));
26060
+ const rec = {
26061
+ ref,
26062
+ agent_type: str4(payload, "agent_type", "agentType", "subagent_type", "subagentType"),
26063
+ started_at: nowIso,
26064
+ parent_ref: parentRef,
26065
+ depth,
26066
+ depth_basis,
26067
+ session_id: sessionId2
26068
+ };
26069
+ writeOpenRecord(root, rec);
26070
+ appendLedgerLine(root, nowIso, {
26071
+ event: "subagent_start",
26072
+ ts: nowIso,
26073
+ ref,
26074
+ agent_type: rec.agent_type,
26075
+ parent_ref: parentRef,
26076
+ depth,
26077
+ depth_basis,
26078
+ concurrent_open: countOpen(root)
26079
+ });
26080
+ }
26081
+ function handleStop(root, payload, nowIso) {
26082
+ const agentId = str4(payload, "agent_id", "agentId");
26083
+ if (agentId === null) {
26084
+ appendUnidentified(root, "subagent_stop", nowIso, payload);
26085
+ return;
26086
+ }
26087
+ const ref = refFor(agentId);
26088
+ const rec = readOpenRecords(root).get(ref) ?? null;
26089
+ let durationMs = null;
26090
+ if (rec) {
26091
+ const started = Date.parse(rec.started_at);
26092
+ if (Number.isFinite(started)) durationMs = Math.max(0, Date.parse(nowIso) - started);
26093
+ }
26094
+ const parse = classifyEnvelope(str4(payload, "last_assistant_message", "lastAssistantMessage"));
26095
+ removeOpenRecord(root, ref);
26096
+ appendLedgerLine(root, nowIso, {
26097
+ event: "subagent_stop",
26098
+ ts: nowIso,
26099
+ ref,
26100
+ agent_type: rec?.agent_type ?? str4(payload, "agent_type", "agentType", "subagent_type", "subagentType"),
26101
+ depth: rec?.depth ?? null,
26102
+ depth_basis: rec?.depth_basis ?? null,
26103
+ // `null` = the matching start was never seen. That is a finding about
26104
+ // the instrument's own coverage and is recorded as such, not as 0.
26105
+ duration_ms: durationMs,
26106
+ // Phase 3 Step 3, shadow: which wall-clock arms this dispatch would
26107
+ // have tripped. Recorded, never acted on.
26108
+ stop_loss_arms_exceeded: armsExceeded(durationMs),
26109
+ start_seen: rec !== null,
26110
+ envelope_parse: parse.verdict,
26111
+ envelope_error_count: parse.error_count,
26112
+ concurrent_open: countOpen(root)
26113
+ });
26114
+ }
26115
+ function processEnvelope2(envelope, consumerRoot) {
26116
+ try {
26117
+ if (!isObject7(envelope)) return EXIT_ALLOW18;
26118
+ const event = envelope["event"];
26119
+ if (event !== "subagent_start" && event !== "subagent_stop") return EXIT_ALLOW18;
26120
+ const payload = unwrapPayload2(envelope);
26121
+ const nowIso = (/* @__PURE__ */ new Date()).toISOString();
26122
+ const sessionId2 = str4(payload, "session_id", "sessionId") ?? str4(envelope, "session_id", "sessionId");
26123
+ reapStaleOpenRecords(consumerRoot, nowIso);
26124
+ if (event === "subagent_start") handleStart(consumerRoot, payload, nowIso, sessionId2);
26125
+ else handleStop(consumerRoot, payload, nowIso);
26126
+ } catch {
26127
+ return EXIT_ALLOW18;
26128
+ }
26129
+ return EXIT_ALLOW18;
26130
+ }
26131
+ function resolveConsumerRoot(envelope) {
26132
+ if (isObject7(envelope)) {
26133
+ const pr = str4(envelope, "workspace_root", "project_root");
26134
+ if (pr) return pr;
26135
+ const payload = unwrapPayload2(envelope);
26136
+ const cwd = str4(payload, "cwd");
26137
+ if (cwd) return cwd;
26138
+ }
26139
+ return process.cwd();
26140
+ }
26141
+ function main42() {
26142
+ const raw = readHookStdin();
26143
+ let envelope = {};
26144
+ try {
26145
+ envelope = raw.trim() ? JSON.parse(raw) : {};
26146
+ } catch {
26147
+ return EXIT_ALLOW18;
26148
+ }
26149
+ return processEnvelope2(envelope, resolveConsumerRoot(envelope));
26150
+ }
26151
+ function _isCliEntry32() {
26152
+ if (true) {
26153
+ return false;
26154
+ }
26155
+ if (process.argv[1] === void 0) return false;
26156
+ const argvUrl = pathToFileURL37(path61.resolve(process.argv[1])).href;
26157
+ if (import.meta.url === argvUrl) return true;
26158
+ try {
26159
+ return fs60.realpathSync(fileURLToPath43(import.meta.url)) === fs60.realpathSync(path61.resolve(process.argv[1]));
26160
+ } catch {
26161
+ return false;
26162
+ }
26163
+ }
26164
+ if (_isCliEntry32()) process.exit(main42());
26165
+
26166
+ // src/scripts/hooks/turn_end_gate_hook.ts
26167
+ var EXIT_BLOCK4 = 1;
26168
+ var EXIT_ALLOW19 = 0;
25720
26169
  var TRANSCRIPT_READ_MAX_BYTES = 8 * 1024 * 1024;
25721
26170
  function stripFencedBlocks(text) {
25722
26171
  const out = [];
@@ -25820,7 +26269,7 @@ function detectPromissory(reply) {
25820
26269
  }
25821
26270
  function readCiSettled(workspaceRoot2) {
25822
26271
  try {
25823
- const raw = fs60.readFileSync(path61.join(workspaceRoot2, STATE_FILE3), "utf-8");
26272
+ const raw = fs61.readFileSync(path62.join(workspaceRoot2, STATE_FILE3), "utf-8");
25824
26273
  const decoded = JSON.parse(raw);
25825
26274
  if (typeof decoded === "object" && decoded !== null && !Array.isArray(decoded)) {
25826
26275
  const ci = decoded["ci_last"];
@@ -25854,7 +26303,7 @@ function detectCompletionClaim(reply, ci) {
25854
26303
  }
25855
26304
  function readLanguagePin(workspaceRoot2) {
25856
26305
  try {
25857
- const raw = fs60.readFileSync(path61.join(workspaceRoot2, STATE_FILE5), "utf-8");
26306
+ const raw = fs61.readFileSync(path62.join(workspaceRoot2, STATE_FILE5), "utf-8");
25858
26307
  const decoded = JSON.parse(raw);
25859
26308
  if (typeof decoded === "object" && decoded !== null && !Array.isArray(decoded)) {
25860
26309
  const lang = decoded["language"];
@@ -25903,17 +26352,17 @@ function detectUnverifiedEdit(toolCalls) {
25903
26352
  };
25904
26353
  }
25905
26354
  function stateDir(workspaceRoot2) {
25906
- return path61.join(workspaceRoot2, "agents", "runtime", "state", "turn-end-gate");
26355
+ return path62.join(workspaceRoot2, "agents", "runtime", "state", "turn-end-gate");
25907
26356
  }
25908
26357
  function sessionStateFile2(workspaceRoot2, sessionKey) {
25909
- return path61.join(stateDir(workspaceRoot2), `${sessionKey}.json`);
26358
+ return path62.join(stateDir(workspaceRoot2), `${sessionKey}.json`);
25910
26359
  }
25911
26360
  function deriveSessionKey2(sessionId2) {
25912
- return crypto6.createHash("sha256").update(sessionId2).digest("hex").slice(0, 32);
26361
+ return crypto7.createHash("sha256").update(sessionId2).digest("hex").slice(0, 32);
25913
26362
  }
25914
26363
  function alreadyRefusedTurn(workspaceRoot2, sessionKey, turnOrdinal) {
25915
26364
  try {
25916
- const raw = fs60.readFileSync(sessionStateFile2(workspaceRoot2, sessionKey), "utf-8");
26365
+ const raw = fs61.readFileSync(sessionStateFile2(workspaceRoot2, sessionKey), "utf-8");
25917
26366
  const decoded = JSON.parse(raw);
25918
26367
  if (typeof decoded === "object" && decoded !== null && !Array.isArray(decoded)) {
25919
26368
  return decoded["refused_turn"] === turnOrdinal;
@@ -25938,10 +26387,10 @@ function readTranscriptTail(transcriptPath, opts = {}) {
25938
26387
  if (!transcriptPath || !isSafeTranscriptPath(transcriptPath, opts)) return empty;
25939
26388
  let lines;
25940
26389
  try {
25941
- if (opts.maxBytes !== void 0 && fs60.statSync(transcriptPath).size > opts.maxBytes) {
26390
+ if (opts.maxBytes !== void 0 && fs61.statSync(transcriptPath).size > opts.maxBytes) {
25942
26391
  return empty;
25943
26392
  }
25944
- lines = fs60.readFileSync(transcriptPath, "utf-8").split("\n");
26393
+ lines = fs61.readFileSync(transcriptPath, "utf-8").split("\n");
25945
26394
  } catch {
25946
26395
  return empty;
25947
26396
  }
@@ -26014,33 +26463,41 @@ function _messageText(content) {
26014
26463
  }
26015
26464
  return parts.length > 0 ? parts.join("\n") : null;
26016
26465
  }
26017
- function str4(v) {
26466
+ function str5(v) {
26018
26467
  return typeof v === "string" ? v : "";
26019
26468
  }
26020
- function main42() {
26469
+ function main43() {
26021
26470
  let envelope;
26022
26471
  let payload;
26023
26472
  try {
26024
26473
  [envelope, payload] = unwrap(readHookStdin(), "claude");
26025
26474
  } catch {
26026
- return EXIT_ALLOW18;
26475
+ return EXIT_ALLOW19;
26027
26476
  }
26028
- if (payload["stop_hook_active"] === true) return EXIT_ALLOW18;
26029
- const workspaceRoot2 = str4(envelope["workspace_root"]) || process.cwd();
26030
- const transcriptPath = str4(
26477
+ if (payload["stop_hook_active"] === true) return EXIT_ALLOW19;
26478
+ const workspaceRoot2 = str5(envelope["workspace_root"]) || process.cwd();
26479
+ let dispatchOpen = false;
26480
+ try {
26481
+ dispatchOpen = openRecordStats(workspaceRoot2).open_count > 0;
26482
+ } catch {
26483
+ }
26484
+ const transcriptPath = str5(
26031
26485
  payload["transcript_path"] ?? payload["transcriptPath"]
26032
26486
  );
26033
26487
  const { lastAssistant, turnOrdinal, toolCalls } = readTranscriptTail(transcriptPath, {
26034
26488
  maxBytes: TRANSCRIPT_READ_MAX_BYTES
26035
26489
  });
26036
- if (!lastAssistant) return EXIT_ALLOW18;
26490
+ if (!lastAssistant) return EXIT_ALLOW19;
26037
26491
  const sessionKey = deriveSessionKey2(
26038
- str4(envelope["session_id"]) || "unknown-session"
26492
+ str5(envelope["session_id"]) || "unknown-session"
26039
26493
  );
26040
- if (alreadyRefusedTurn(workspaceRoot2, sessionKey, turnOrdinal)) return EXIT_ALLOW18;
26494
+ if (alreadyRefusedTurn(workspaceRoot2, sessionKey, turnOrdinal)) return EXIT_ALLOW19;
26041
26495
  const findings = [];
26042
26496
  for (const f of [
26043
- detectPromissory(lastAssistant),
26497
+ // A and D are the completion-adjacent pair a pending dispatch excuses
26498
+ // (Phase 3 Step 2, narrowed by R2 round 2 finding 2). B and C are not
26499
+ // excused by anything about a dispatch and run unchanged.
26500
+ dispatchOpen ? null : detectPromissory(lastAssistant),
26044
26501
  detectLanguage(lastAssistant, readLanguagePin(workspaceRoot2)),
26045
26502
  detectUnverifiedEdit(toolCalls),
26046
26503
  // Round 7 § Phase 1 — detector D, in the same unconditional list as the
@@ -26050,11 +26507,11 @@ function main42() {
26050
26507
  // gating is where the comment above says gating belongs — inside the
26051
26508
  // detector: no CI observed, or a settled read, or no completion claim
26052
26509
  // ⇒ no finding.
26053
- detectCompletionClaim(lastAssistant, readCiSettled(workspaceRoot2))
26510
+ dispatchOpen ? null : detectCompletionClaim(lastAssistant, readCiSettled(workspaceRoot2))
26054
26511
  ]) {
26055
26512
  if (f) findings.push(f);
26056
26513
  }
26057
- if (findings.length === 0) return EXIT_ALLOW18;
26514
+ if (findings.length === 0) return EXIT_ALLOW19;
26058
26515
  markRefusedTurn(workspaceRoot2, sessionKey, turnOrdinal, findings[0].detector);
26059
26516
  const lines = findings.map(
26060
26517
  (f) => ` \xB7 ${f.detector}: ${f.reason}
@@ -26069,36 +26526,36 @@ ${lines.join("\n")}
26069
26526
  );
26070
26527
  return EXIT_BLOCK4;
26071
26528
  }
26072
- function _isCliEntry32() {
26529
+ function _isCliEntry33() {
26073
26530
  if (true) {
26074
26531
  return false;
26075
26532
  }
26076
26533
  if (process.argv[1] === void 0) {
26077
26534
  return false;
26078
26535
  }
26079
- const argvUrl = pathToFileURL37(path61.resolve(process.argv[1])).href;
26536
+ const argvUrl = pathToFileURL38(path62.resolve(process.argv[1])).href;
26080
26537
  if (import.meta.url === argvUrl) {
26081
26538
  return true;
26082
26539
  }
26083
26540
  try {
26084
- const here = fs60.realpathSync(fileURLToPath43(import.meta.url));
26085
- const argv = fs60.realpathSync(path61.resolve(process.argv[1]));
26541
+ const here = fs61.realpathSync(fileURLToPath44(import.meta.url));
26542
+ const argv = fs61.realpathSync(path62.resolve(process.argv[1]));
26086
26543
  return here === argv;
26087
26544
  } catch {
26088
26545
  return false;
26089
26546
  }
26090
26547
  }
26091
- if (_isCliEntry32()) {
26092
- process.exit(main42());
26548
+ if (_isCliEntry33()) {
26549
+ process.exit(main43());
26093
26550
  }
26094
26551
 
26095
26552
  // src/scripts/hooks/edit_shape_hook.ts
26096
26553
  import { spawnSync as spawnSync6 } from "node:child_process";
26097
- import * as crypto7 from "node:crypto";
26098
- import * as fs61 from "node:fs";
26099
- import * as path62 from "node:path";
26100
- import { fileURLToPath as fileURLToPath44, pathToFileURL as pathToFileURL38 } from "node:url";
26101
- var EXIT_ALLOW19 = 0;
26554
+ import * as crypto8 from "node:crypto";
26555
+ import * as fs62 from "node:fs";
26556
+ import * as path63 from "node:path";
26557
+ import { fileURLToPath as fileURLToPath45, pathToFileURL as pathToFileURL39 } from "node:url";
26558
+ var EXIT_ALLOW20 = 0;
26102
26559
  var EXIT_WARN11 = 2;
26103
26560
  var MIN_FILE_LINES = 50;
26104
26561
  var MAX_DIFF_RATIO = 0.2;
@@ -26114,10 +26571,10 @@ var EXEMPT_PATH_PATTERNS = [
26114
26571
  /(^|\/)agents\/runtime\//i
26115
26572
  // agents/runtime/**
26116
26573
  ];
26117
- function isObject7(v) {
26574
+ function isObject8(v) {
26118
26575
  return typeof v === "object" && v !== null && !Array.isArray(v);
26119
26576
  }
26120
- function str5(v) {
26577
+ function str6(v) {
26121
26578
  return typeof v === "string" ? v : "";
26122
26579
  }
26123
26580
  function isExemptPath(filePath) {
@@ -26150,7 +26607,7 @@ function effectiveDiffLines(cwd, relPath) {
26150
26607
  }
26151
26608
  function fileLineCount(absPath) {
26152
26609
  try {
26153
- const text = fs61.readFileSync(absPath, "utf8");
26610
+ const text = fs62.readFileSync(absPath, "utf8");
26154
26611
  if (text.length === 0) return 0;
26155
26612
  return text.split("\n").length - (text.endsWith("\n") ? 1 : 0);
26156
26613
  } catch {
@@ -26162,16 +26619,16 @@ function buildAdvisoryLine2(fileLines, diffLines) {
26162
26619
  return `this Write replaced ${fileLines} lines for an effective diff of ~${pct}% (${diffLines} changed lines) \u2014 a targeted Edit pays for the diff, not the file.`;
26163
26620
  }
26164
26621
  function deriveSessionKey3(envelope, payload) {
26165
- const raw = str5(envelope["session_id"]) || str5(payload["session_id"] ?? payload["sessionId"]);
26622
+ const raw = str6(envelope["session_id"]) || str6(payload["session_id"] ?? payload["sessionId"]);
26166
26623
  const material = raw || "unknown-session";
26167
- return crypto7.createHash("sha256").update(material).digest("hex");
26624
+ return crypto8.createHash("sha256").update(material).digest("hex");
26168
26625
  }
26169
26626
  function sessionStateFile3(workspaceRoot2, sessionKey) {
26170
- return path62.join(workspaceRoot2, "agents", "runtime", "state", "edit-shape", `${sessionKey}.json`);
26627
+ return path63.join(workspaceRoot2, "agents", "runtime", "state", "edit-shape", `${sessionKey}.json`);
26171
26628
  }
26172
26629
  function hasFiredThisSession2(workspaceRoot2, sessionKey) {
26173
26630
  try {
26174
- return fs61.existsSync(sessionStateFile3(workspaceRoot2, sessionKey));
26631
+ return fs62.existsSync(sessionStateFile3(workspaceRoot2, sessionKey));
26175
26632
  } catch {
26176
26633
  return false;
26177
26634
  }
@@ -26185,33 +26642,33 @@ function markFiredThisSession2(workspaceRoot2, sessionKey) {
26185
26642
  }
26186
26643
  }
26187
26644
  function extractToolName2(payload) {
26188
- return str5(payload["tool_name"] ?? payload["toolName"] ?? payload["tool"]);
26645
+ return str6(payload["tool_name"] ?? payload["toolName"] ?? payload["tool"]);
26189
26646
  }
26190
26647
  function extractFilePath(payload) {
26191
26648
  const ti = payload["tool_input"] ?? payload["toolInput"] ?? payload["input"];
26192
- if (!isObject7(ti)) return "";
26193
- return str5(ti["file_path"] ?? ti["path"] ?? ti["filePath"]);
26649
+ if (!isObject8(ti)) return "";
26650
+ return str6(ti["file_path"] ?? ti["path"] ?? ti["filePath"]);
26194
26651
  }
26195
- function main43() {
26652
+ function main44() {
26196
26653
  try {
26197
26654
  const [envelope, payload] = unwrap(readHookStdin(), "claude");
26198
- const event = str5(envelope["event"]);
26199
- if (event !== "" && event !== "post_tool_use") return EXIT_ALLOW19;
26655
+ const event = str6(envelope["event"]);
26656
+ if (event !== "" && event !== "post_tool_use") return EXIT_ALLOW20;
26200
26657
  const toolName = extractToolName2(payload);
26201
- if (toolName !== "Write") return EXIT_ALLOW19;
26658
+ if (toolName !== "Write") return EXIT_ALLOW20;
26202
26659
  const filePath = extractFilePath(payload);
26203
- if (!filePath) return EXIT_ALLOW19;
26204
- const workspaceRoot2 = str5(envelope["workspace_root"]).trim() || process.cwd();
26205
- const absPath = path62.isAbsolute(filePath) ? filePath : path62.resolve(workspaceRoot2, filePath);
26206
- const relPath = path62.relative(workspaceRoot2, absPath);
26207
- if (isExemptPath(relPath) || isExemptPath(absPath)) return EXIT_ALLOW19;
26660
+ if (!filePath) return EXIT_ALLOW20;
26661
+ const workspaceRoot2 = str6(envelope["workspace_root"]).trim() || process.cwd();
26662
+ const absPath = path63.isAbsolute(filePath) ? filePath : path63.resolve(workspaceRoot2, filePath);
26663
+ const relPath = path63.relative(workspaceRoot2, absPath);
26664
+ if (isExemptPath(relPath) || isExemptPath(absPath)) return EXIT_ALLOW20;
26208
26665
  const fileLines = fileLineCount(absPath);
26209
- if (fileLines < MIN_FILE_LINES) return EXIT_ALLOW19;
26666
+ if (fileLines < MIN_FILE_LINES) return EXIT_ALLOW20;
26210
26667
  const diffLines = effectiveDiffLines(workspaceRoot2, relPath.startsWith("..") ? absPath : relPath);
26211
- if (diffLines === 0) return EXIT_ALLOW19;
26212
- if (diffLines / fileLines > MAX_DIFF_RATIO) return EXIT_ALLOW19;
26668
+ if (diffLines === 0) return EXIT_ALLOW20;
26669
+ if (diffLines / fileLines > MAX_DIFF_RATIO) return EXIT_ALLOW20;
26213
26670
  const sessionKey = deriveSessionKey3(envelope, payload);
26214
- if (hasFiredThisSession2(workspaceRoot2, sessionKey)) return EXIT_ALLOW19;
26671
+ if (hasFiredThisSession2(workspaceRoot2, sessionKey)) return EXIT_ALLOW20;
26215
26672
  markFiredThisSession2(workspaceRoot2, sessionKey);
26216
26673
  process.stdout.write(
26217
26674
  `${JSON.stringify({
@@ -26223,38 +26680,38 @@ function main43() {
26223
26680
  );
26224
26681
  return EXIT_WARN11;
26225
26682
  } catch {
26226
- return EXIT_ALLOW19;
26683
+ return EXIT_ALLOW20;
26227
26684
  }
26228
26685
  }
26229
- function _isCliEntry33() {
26686
+ function _isCliEntry34() {
26230
26687
  if (true) {
26231
26688
  return false;
26232
26689
  }
26233
26690
  if (process.argv[1] === void 0) {
26234
26691
  return false;
26235
26692
  }
26236
- const argvUrl = pathToFileURL38(path62.resolve(process.argv[1])).href;
26693
+ const argvUrl = pathToFileURL39(path63.resolve(process.argv[1])).href;
26237
26694
  if (import.meta.url === argvUrl) {
26238
26695
  return true;
26239
26696
  }
26240
26697
  try {
26241
- const here = fs61.realpathSync(fileURLToPath44(import.meta.url));
26242
- const argv = fs61.realpathSync(path62.resolve(process.argv[1]));
26698
+ const here = fs62.realpathSync(fileURLToPath45(import.meta.url));
26699
+ const argv = fs62.realpathSync(path63.resolve(process.argv[1]));
26243
26700
  return here === argv;
26244
26701
  } catch {
26245
26702
  return false;
26246
26703
  }
26247
26704
  }
26248
- if (_isCliEntry33()) {
26249
- process.exit(main43());
26705
+ if (_isCliEntry34()) {
26706
+ process.exit(main44());
26250
26707
  }
26251
26708
 
26252
26709
  // src/scripts/hooks/reread_guard_hook.ts
26253
- import * as crypto8 from "node:crypto";
26254
- import * as fs62 from "node:fs";
26255
- import * as path63 from "node:path";
26256
- import { fileURLToPath as fileURLToPath45, pathToFileURL as pathToFileURL39 } from "node:url";
26257
- var EXIT_ALLOW20 = 0;
26710
+ import * as crypto9 from "node:crypto";
26711
+ import * as fs63 from "node:fs";
26712
+ import * as path64 from "node:path";
26713
+ import { fileURLToPath as fileURLToPath46, pathToFileURL as pathToFileURL40 } from "node:url";
26714
+ var EXIT_ALLOW21 = 0;
26258
26715
  var EXIT_WARN12 = 2;
26259
26716
  var EXEMPT_PATH_PATTERNS2 = [
26260
26717
  /(^|\/)dist\//i,
@@ -26270,10 +26727,10 @@ var EXEMPT_PATH_PATTERNS2 = [
26270
26727
  ];
26271
26728
  var READ_TOOLS = /* @__PURE__ */ new Set(["Read"]);
26272
26729
  var WRITE_TOOLS2 = /* @__PURE__ */ new Set(["Edit", "Write"]);
26273
- function isObject8(v) {
26730
+ function isObject9(v) {
26274
26731
  return typeof v === "object" && v !== null && !Array.isArray(v);
26275
26732
  }
26276
- function str6(v) {
26733
+ function str7(v) {
26277
26734
  return typeof v === "string" ? v : "";
26278
26735
  }
26279
26736
  function isExemptPath2(filePath) {
@@ -26284,21 +26741,21 @@ function emptyLedger() {
26284
26741
  return { reads: {}, writes: {}, fired: {} };
26285
26742
  }
26286
26743
  function deriveSessionKey4(envelope, payload) {
26287
- const raw = str6(envelope["session_id"]) || str6(payload["session_id"] ?? payload["sessionId"]);
26744
+ const raw = str7(envelope["session_id"]) || str7(payload["session_id"] ?? payload["sessionId"]);
26288
26745
  const material = raw || "unknown-session";
26289
- return crypto8.createHash("sha256").update(material).digest("hex");
26746
+ return crypto9.createHash("sha256").update(material).digest("hex");
26290
26747
  }
26291
26748
  function ledgerFile(workspaceRoot2, sessionKey) {
26292
- return path63.join(workspaceRoot2, "agents", "runtime", "state", "reread-guard", `${sessionKey}.json`);
26749
+ return path64.join(workspaceRoot2, "agents", "runtime", "state", "reread-guard", `${sessionKey}.json`);
26293
26750
  }
26294
26751
  function readLedger(workspaceRoot2, sessionKey) {
26295
26752
  try {
26296
- const parsed = JSON.parse(fs62.readFileSync(ledgerFile(workspaceRoot2, sessionKey), "utf8"));
26297
- if (!isObject8(parsed)) return emptyLedger();
26753
+ const parsed = JSON.parse(fs63.readFileSync(ledgerFile(workspaceRoot2, sessionKey), "utf8"));
26754
+ if (!isObject9(parsed)) return emptyLedger();
26298
26755
  return {
26299
- reads: isObject8(parsed["reads"]) ? parsed["reads"] : {},
26300
- writes: isObject8(parsed["writes"]) ? parsed["writes"] : {},
26301
- fired: isObject8(parsed["fired"]) ? parsed["fired"] : {}
26756
+ reads: isObject9(parsed["reads"]) ? parsed["reads"] : {},
26757
+ writes: isObject9(parsed["writes"]) ? parsed["writes"] : {},
26758
+ fired: isObject9(parsed["fired"]) ? parsed["fired"] : {}
26302
26759
  };
26303
26760
  } catch {
26304
26761
  return emptyLedger();
@@ -26311,14 +26768,14 @@ function writeLedger(workspaceRoot2, sessionKey, ledger) {
26311
26768
  }
26312
26769
  }
26313
26770
  function extractToolName3(payload) {
26314
- return str6(payload["tool_name"] ?? payload["toolName"] ?? payload["tool"]);
26771
+ return str7(payload["tool_name"] ?? payload["toolName"] ?? payload["tool"]);
26315
26772
  }
26316
26773
  function extractToolInput2(payload) {
26317
26774
  const ti = payload["tool_input"] ?? payload["toolInput"] ?? payload["input"];
26318
- return isObject8(ti) ? ti : {};
26775
+ return isObject9(ti) ? ti : {};
26319
26776
  }
26320
26777
  function extractFilePath2(toolInput) {
26321
- return str6(toolInput["file_path"] ?? toolInput["path"] ?? toolInput["filePath"]);
26778
+ return str7(toolInput["file_path"] ?? toolInput["path"] ?? toolInput["filePath"]);
26322
26779
  }
26323
26780
  function isRangedRead(toolInput) {
26324
26781
  for (const key of ["offset", "limit", "start_line", "end_line", "startLine", "endLine"]) {
@@ -26334,41 +26791,41 @@ function buildDuplicateReadLine(relPath, earlierTs) {
26334
26791
  function buildPostEditReadLine(relPath) {
26335
26792
  return `re-read guard: this session just edited ${relPath} \u2014 a full-file re-read re-pays for content you already have; a ranged Read (offset/limit) over the edited hunk is enough to verify the change.`;
26336
26793
  }
26337
- function main44() {
26794
+ function main45() {
26338
26795
  try {
26339
26796
  const [envelope, payload] = unwrap(readHookStdin(), "claude");
26340
- const event = str6(envelope["event"]);
26341
- if (event !== "" && event !== "pre_tool_use") return EXIT_ALLOW20;
26797
+ const event = str7(envelope["event"]);
26798
+ if (event !== "" && event !== "pre_tool_use") return EXIT_ALLOW21;
26342
26799
  const toolName = extractToolName3(payload);
26343
26800
  const isRead = READ_TOOLS.has(toolName);
26344
26801
  const isWrite = WRITE_TOOLS2.has(toolName);
26345
- if (!isRead && !isWrite) return EXIT_ALLOW20;
26802
+ if (!isRead && !isWrite) return EXIT_ALLOW21;
26346
26803
  const toolInput = extractToolInput2(payload);
26347
26804
  const filePath = extractFilePath2(toolInput);
26348
- if (!filePath) return EXIT_ALLOW20;
26349
- const workspaceRoot2 = str6(envelope["workspace_root"]).trim() || process.cwd();
26350
- const absPath = path63.isAbsolute(filePath) ? filePath : path63.resolve(workspaceRoot2, filePath);
26351
- const relPath = path63.relative(workspaceRoot2, absPath);
26352
- if (isExemptPath2(relPath) || isExemptPath2(absPath)) return EXIT_ALLOW20;
26805
+ if (!filePath) return EXIT_ALLOW21;
26806
+ const workspaceRoot2 = str7(envelope["workspace_root"]).trim() || process.cwd();
26807
+ const absPath = path64.isAbsolute(filePath) ? filePath : path64.resolve(workspaceRoot2, filePath);
26808
+ const relPath = path64.relative(workspaceRoot2, absPath);
26809
+ if (isExemptPath2(relPath) || isExemptPath2(absPath)) return EXIT_ALLOW21;
26353
26810
  const sessionKey = deriveSessionKey4(envelope, payload);
26354
26811
  const ledger = readLedger(workspaceRoot2, sessionKey);
26355
26812
  const key = relPath.startsWith("..") ? absPath : relPath;
26356
26813
  if (isWrite) {
26357
26814
  ledger.writes[key] = Date.now();
26358
26815
  writeLedger(workspaceRoot2, sessionKey, ledger);
26359
- return EXIT_ALLOW20;
26816
+ return EXIT_ALLOW21;
26360
26817
  }
26361
26818
  if (isRangedRead(toolInput)) {
26362
- return EXIT_ALLOW20;
26819
+ return EXIT_ALLOW21;
26363
26820
  }
26364
26821
  let mtime;
26365
26822
  let size;
26366
26823
  try {
26367
- const st = fs62.statSync(absPath);
26824
+ const st = fs63.statSync(absPath);
26368
26825
  mtime = st.mtimeMs;
26369
26826
  size = st.size;
26370
26827
  } catch {
26371
- return EXIT_ALLOW20;
26828
+ return EXIT_ALLOW21;
26372
26829
  }
26373
26830
  const prior = ledger.reads[key];
26374
26831
  const ownWrite = ledger.writes[key];
@@ -26383,7 +26840,7 @@ function main44() {
26383
26840
  if (ownWrite !== void 0) delete ledger.writes[key];
26384
26841
  if (advisory !== null) ledger.fired[key] = true;
26385
26842
  writeLedger(workspaceRoot2, sessionKey, ledger);
26386
- if (advisory === null) return EXIT_ALLOW20;
26843
+ if (advisory === null) return EXIT_ALLOW21;
26387
26844
  process.stdout.write(
26388
26845
  `${JSON.stringify({
26389
26846
  decision: "warn",
@@ -26394,37 +26851,37 @@ function main44() {
26394
26851
  );
26395
26852
  return EXIT_WARN12;
26396
26853
  } catch {
26397
- return EXIT_ALLOW20;
26854
+ return EXIT_ALLOW21;
26398
26855
  }
26399
26856
  }
26400
- function _isCliEntry34() {
26857
+ function _isCliEntry35() {
26401
26858
  if (true) {
26402
26859
  return false;
26403
26860
  }
26404
26861
  if (process.argv[1] === void 0) {
26405
26862
  return false;
26406
26863
  }
26407
- const argvUrl = pathToFileURL39(path63.resolve(process.argv[1])).href;
26864
+ const argvUrl = pathToFileURL40(path64.resolve(process.argv[1])).href;
26408
26865
  if (import.meta.url === argvUrl) {
26409
26866
  return true;
26410
26867
  }
26411
26868
  try {
26412
- const here = fs62.realpathSync(fileURLToPath45(import.meta.url));
26413
- const argv = fs62.realpathSync(path63.resolve(process.argv[1]));
26869
+ const here = fs63.realpathSync(fileURLToPath46(import.meta.url));
26870
+ const argv = fs63.realpathSync(path64.resolve(process.argv[1]));
26414
26871
  return here === argv;
26415
26872
  } catch {
26416
26873
  return false;
26417
26874
  }
26418
26875
  }
26419
- if (_isCliEntry34()) {
26420
- process.exit(main44());
26876
+ if (_isCliEntry35()) {
26877
+ process.exit(main45());
26421
26878
  }
26422
26879
 
26423
26880
  // src/scripts/hooks/session_eol_hook.ts
26424
- import * as fs64 from "node:fs";
26425
- import * as path66 from "node:path";
26881
+ import * as fs65 from "node:fs";
26882
+ import * as path67 from "node:path";
26426
26883
  import process11 from "node:process";
26427
- import { fileURLToPath as fileURLToPath46, pathToFileURL as pathToFileURL40 } from "node:url";
26884
+ import { fileURLToPath as fileURLToPath47, pathToFileURL as pathToFileURL41 } from "node:url";
26428
26885
 
26429
26886
  // src/config/recycle-threshold-budget.json
26430
26887
  var recycle_threshold_budget_default = {
@@ -26441,14 +26898,14 @@ var recycle_threshold_budget_default = {
26441
26898
  };
26442
26899
 
26443
26900
  // src/scripts/_lib/session_eol.ts
26444
- import * as crypto9 from "node:crypto";
26445
- import * as fs63 from "node:fs";
26446
- import * as path65 from "node:path";
26901
+ import * as crypto10 from "node:crypto";
26902
+ import * as fs64 from "node:fs";
26903
+ import * as path66 from "node:path";
26447
26904
 
26448
26905
  // src/scripts/_lib/cc_transcript.ts
26449
- import * as path64 from "node:path";
26906
+ import * as path65 from "node:path";
26450
26907
  import { homedir as homedir6 } from "node:os";
26451
- var DEFAULT_PROJECTS_ROOT = path64.join(homedir6(), ".claude", "projects");
26908
+ var DEFAULT_PROJECTS_ROOT = path65.join(homedir6(), ".claude", "projects");
26452
26909
  function billableInputTokens(u) {
26453
26910
  return u.input_tokens + u.cache_read_input_tokens + u.cache_creation_input_tokens;
26454
26911
  }
@@ -26557,17 +27014,17 @@ function scanEolSlice(text, prior) {
26557
27014
  return next;
26558
27015
  }
26559
27016
  function eolStateDir(workspaceRoot2) {
26560
- return path65.join(workspaceRoot2, "agents", "runtime", "state", "session-eol");
27017
+ return path66.join(workspaceRoot2, "agents", "runtime", "state", "session-eol");
26561
27018
  }
26562
27019
  function eolStateFile(workspaceRoot2, sessionKey) {
26563
- return path65.join(eolStateDir(workspaceRoot2), `${sessionKey}.json`);
27020
+ return path66.join(eolStateDir(workspaceRoot2), `${sessionKey}.json`);
26564
27021
  }
26565
27022
  function eolSessionKey(raw) {
26566
- return crypto9.createHash("sha256").update(raw || "unknown-session").digest("hex");
27023
+ return crypto10.createHash("sha256").update(raw || "unknown-session").digest("hex");
26567
27024
  }
26568
27025
  function readNewCompleteLines(filePath, fromByte) {
26569
27026
  try {
26570
- const { size } = fs63.statSync(filePath);
27027
+ const { size } = fs64.statSync(filePath);
26571
27028
  if (size < fromByte) {
26572
27029
  return { text: "", nextOffset: 0, truncated: true };
26573
27030
  }
@@ -26576,11 +27033,11 @@ function readNewCompleteLines(filePath, fromByte) {
26576
27033
  }
26577
27034
  const length = size - fromByte;
26578
27035
  const buffer = Buffer.alloc(length);
26579
- const fd = fs63.openSync(filePath, "r");
27036
+ const fd = fs64.openSync(filePath, "r");
26580
27037
  try {
26581
- fs63.readSync(fd, buffer, 0, length, fromByte);
27038
+ fs64.readSync(fd, buffer, 0, length, fromByte);
26582
27039
  } finally {
26583
- fs63.closeSync(fd);
27040
+ fs64.closeSync(fd);
26584
27041
  }
26585
27042
  const lastNewline = buffer.lastIndexOf(10);
26586
27043
  if (lastNewline === -1) {
@@ -26599,19 +27056,19 @@ function readNewCompleteLines(filePath, fromByte) {
26599
27056
  // src/scripts/hooks/session_eol_hook.ts
26600
27057
  var EXIT_WARN13 = 2;
26601
27058
  var THRESHOLD_OVERRIDE_ENV = "AGENT_RECYCLE_THRESHOLD_TOKENS";
26602
- var CONTEXT_FILL_REL = path66.join("agents", "runtime", "state", "context-fill.json");
26603
- function str7(value) {
27059
+ var CONTEXT_FILL_REL = path67.join("agents", "runtime", "state", "context-fill.json");
27060
+ function str8(value) {
26604
27061
  return typeof value === "string" ? value : "";
26605
27062
  }
26606
27063
  var stateFile3 = eolStateFile;
26607
27064
  function deriveSessionKey5(envelope, payload) {
26608
27065
  return eolSessionKey(
26609
- str7(envelope["session_id"]) || str7(payload["transcript_path"] ?? payload["transcriptPath"])
27066
+ str8(envelope["session_id"]) || str8(payload["transcript_path"] ?? payload["transcriptPath"])
26610
27067
  );
26611
27068
  }
26612
27069
  function readState3(file) {
26613
27070
  try {
26614
- const parsed = JSON.parse(fs64.readFileSync(file, "utf-8"));
27071
+ const parsed = JSON.parse(fs65.readFileSync(file, "utf-8"));
26615
27072
  if (parsed && typeof parsed === "object" && parsed.schema_version === 1 && parsed.counters && typeof parsed.counters.scanned_bytes === "number") {
26616
27073
  return {
26617
27074
  schema_version: 1,
@@ -26632,10 +27089,10 @@ function readState3(file) {
26632
27089
  };
26633
27090
  }
26634
27091
  function envelopeExists(workspaceRoot2, since = null) {
26635
- const target = path66.join(workspaceRoot2, RECYCLE_ENVELOPE_REL);
27092
+ const target = path67.join(workspaceRoot2, RECYCLE_ENVELOPE_REL);
26636
27093
  let raw;
26637
27094
  try {
26638
- raw = fs64.readFileSync(target, "utf-8");
27095
+ raw = fs65.readFileSync(target, "utf-8");
26639
27096
  } catch (exc) {
26640
27097
  return exc?.code !== "ENOENT";
26641
27098
  }
@@ -26649,7 +27106,7 @@ function envelopeExists(workspaceRoot2, since = null) {
26649
27106
  }
26650
27107
  }
26651
27108
  function buildMissingEnvelopeLine(workspaceRoot2) {
26652
- return `recycle advised earlier, but no envelope exists at ${path66.join(workspaceRoot2, RECYCLE_ENVELOPE_REL)} \u2014 /clear now starts the successor from nothing. Re-run \`agent-config session:recycle\` and check that it prints the absolute path it wrote before clearing.`;
27109
+ return `recycle advised earlier, but no envelope exists at ${path67.join(workspaceRoot2, RECYCLE_ENVELOPE_REL)} \u2014 /clear now starts the successor from nothing. Re-run \`agent-config session:recycle\` and check that it prints the absolute path it wrote before clearing.`;
26653
27110
  }
26654
27111
  function readThresholdTokens() {
26655
27112
  const override = process11.env[THRESHOLD_OVERRIDE_ENV];
@@ -26665,7 +27122,7 @@ function buildAdvisoryLine3(tokens, threshold) {
26665
27122
  }
26666
27123
  function writeContextFill(workspaceRoot2, tokens, threshold, ts) {
26667
27124
  try {
26668
- atomic_write_json(path66.join(workspaceRoot2, CONTEXT_FILL_REL), {
27125
+ atomic_write_json(path67.join(workspaceRoot2, CONTEXT_FILL_REL), {
26669
27126
  schema_version: 1,
26670
27127
  final_context_tokens: tokens,
26671
27128
  recycle_threshold_tokens: threshold,
@@ -26675,7 +27132,7 @@ function writeContextFill(workspaceRoot2, tokens, threshold, ts) {
26675
27132
  } catch {
26676
27133
  }
26677
27134
  }
26678
- function main45() {
27135
+ function main46() {
26679
27136
  const [envelope, payload] = unwrap(readHookStdin(), "claude");
26680
27137
  const event = String(envelope["event"] ?? "");
26681
27138
  if (event !== "" && event !== "stop") {
@@ -26685,7 +27142,7 @@ function main45() {
26685
27142
  return 0;
26686
27143
  }
26687
27144
  const workspaceRoot2 = String(envelope["workspace_root"] ?? "").trim() || process11.cwd();
26688
- const transcriptPath = str7(
27145
+ const transcriptPath = str8(
26689
27146
  payload["transcript_path"] ?? payload["transcriptPath"]
26690
27147
  ).trim();
26691
27148
  if (!transcriptPath || !isSafeTranscriptPath(transcriptPath)) {
@@ -26747,29 +27204,119 @@ function main45() {
26747
27204
  }
26748
27205
  return 0;
26749
27206
  }
26750
- function _isCliEntry35() {
27207
+ function _isCliEntry36() {
26751
27208
  if (true) {
26752
27209
  return false;
26753
27210
  }
26754
27211
  if (process11.argv[1] === void 0) {
26755
27212
  return false;
26756
27213
  }
26757
- const argvUrl = pathToFileURL40(path66.resolve(process11.argv[1])).href;
27214
+ const argvUrl = pathToFileURL41(path67.resolve(process11.argv[1])).href;
26758
27215
  if (import.meta.url === argvUrl) {
26759
27216
  return true;
26760
27217
  }
26761
27218
  try {
26762
- const here = fs64.realpathSync(fileURLToPath46(import.meta.url));
26763
- const argv = fs64.realpathSync(path66.resolve(process11.argv[1]));
27219
+ const here = fs65.realpathSync(fileURLToPath47(import.meta.url));
27220
+ const argv = fs65.realpathSync(path67.resolve(process11.argv[1]));
26764
27221
  return here === argv;
26765
27222
  } catch {
26766
27223
  return false;
26767
27224
  }
26768
27225
  }
26769
- if (_isCliEntry35()) {
26770
- process11.exit(main45());
27226
+ if (_isCliEntry36()) {
27227
+ process11.exit(main46());
26771
27228
  }
26772
27229
 
27230
+ // src/scripts/hooks/spawn_guard_shadow_hook.ts
27231
+ import * as fs66 from "node:fs";
27232
+ import * as path68 from "node:path";
27233
+ import { fileURLToPath as fileURLToPath48, pathToFileURL as pathToFileURL42 } from "node:url";
27234
+ var EXIT_ALLOW22 = 0;
27235
+ function isObject10(v) {
27236
+ return typeof v === "object" && v !== null && !Array.isArray(v);
27237
+ }
27238
+ var DISPATCH_TOOL_NAMES2 = /* @__PURE__ */ new Set(["Agent", "Task"]);
27239
+ var CANDIDATES = [
27240
+ { label: "n2m4", max_depth: 2, max_concurrent: 4 },
27241
+ { label: "n3m6", max_depth: 3, max_concurrent: 6 },
27242
+ { label: "n4m8", max_depth: 4, max_concurrent: 8 }
27243
+ ];
27244
+ function evaluateCandidates(depthEstimate, concurrentOpen) {
27245
+ void depthEstimate;
27246
+ return CANDIDATES.map((c) => {
27247
+ const on = [];
27248
+ if (concurrentOpen >= c.max_concurrent) on.push("concurrent");
27249
+ return { label: c.label, would_deny: on.length > 0, on };
27250
+ });
27251
+ }
27252
+ function unwrapPayload3(envelope) {
27253
+ const inner = envelope["payload"];
27254
+ return isObject10(inner) ? inner : envelope;
27255
+ }
27256
+ function extractToolName4(payload) {
27257
+ const v = payload["tool_name"] ?? payload["toolName"] ?? payload["tool"];
27258
+ return typeof v === "string" && v ? v : null;
27259
+ }
27260
+ function processEnvelope3(envelope, consumerRoot) {
27261
+ try {
27262
+ if (!isObject10(envelope)) return EXIT_ALLOW22;
27263
+ const payload = unwrapPayload3(envelope);
27264
+ const toolName = extractToolName4(payload);
27265
+ if (toolName === null || !DISPATCH_TOOL_NAMES2.has(toolName)) return EXIT_ALLOW22;
27266
+ const stats = openRecordStats(consumerRoot);
27267
+ const depthEstimate = stats.max_depth + 1;
27268
+ const verdicts = evaluateCandidates(depthEstimate, stats.open_count);
27269
+ const nowIso = (/* @__PURE__ */ new Date()).toISOString();
27270
+ appendLedgerLine(consumerRoot, nowIso, {
27271
+ event: "spawn_guard_shadow",
27272
+ ts: nowIso,
27273
+ tool: toolName,
27274
+ concurrent_open: stats.open_count,
27275
+ depth_estimate: depthEstimate,
27276
+ depth_estimate_basis: "deepest-open-record-plus-one",
27277
+ // R2 round 2, finding 3: the estimate is >= 2 whenever anything is
27278
+ // open, nesting or not, so it must not reach a derivation. It rides
27279
+ // as context with the flag that says so.
27280
+ depth_usable_for_derivation: false,
27281
+ // R2 round 2, finding 4: without these, a quiet estate, a ledger
27282
+ // this hook cannot see, and a root mismatch all emit byte-identical
27283
+ // records — the instrument-goes-quiet failure one layer up from the
27284
+ // one the ledger already fixed for itself.
27285
+ ledger_present: stats.ledger_present,
27286
+ stale_open_excluded: stats.stale_excluded,
27287
+ candidates: verdicts.map((v) => ({ label: v.label, would_deny: v.would_deny, on: v.on })),
27288
+ // Shadow posture is a property of this file, not of a setting —
27289
+ // there is no code path here that can deny.
27290
+ posture: "shadow"
27291
+ });
27292
+ } catch {
27293
+ return EXIT_ALLOW22;
27294
+ }
27295
+ return EXIT_ALLOW22;
27296
+ }
27297
+ function main47() {
27298
+ const raw = readHookStdin();
27299
+ let envelope = {};
27300
+ try {
27301
+ envelope = raw.trim() ? JSON.parse(raw) : {};
27302
+ } catch {
27303
+ return EXIT_ALLOW22;
27304
+ }
27305
+ return processEnvelope3(envelope, resolveConsumerRoot(envelope));
27306
+ }
27307
+ function _isCliEntry37() {
27308
+ if (true) return false;
27309
+ if (process.argv[1] === void 0) return false;
27310
+ const argvUrl = pathToFileURL42(path68.resolve(process.argv[1])).href;
27311
+ if (import.meta.url === argvUrl) return true;
27312
+ try {
27313
+ return fs66.realpathSync(fileURLToPath48(import.meta.url)) === fs66.realpathSync(path68.resolve(process.argv[1]));
27314
+ } catch {
27315
+ return false;
27316
+ }
27317
+ }
27318
+ if (_isCliEntry37()) process.exit(main47());
27319
+
26773
27320
  // src/scripts/hooks/concern_registry.ts
26774
27321
  var CONCERN_REGISTRY = {
26775
27322
  "src/scripts/chat_history.ts": main6,
@@ -26806,10 +27353,12 @@ var CONCERN_REGISTRY = {
26806
27353
  "src/scripts/hooks/orchestration_record_hook.ts": main39,
26807
27354
  "src/scripts/hooks/delegation_nudge_hook.ts": main40,
26808
27355
  "src/scripts/hooks/end_review_nudge_hook.ts": main41,
26809
- "src/scripts/hooks/turn_end_gate_hook.ts": main42,
26810
- "src/scripts/hooks/edit_shape_hook.ts": main43,
26811
- "src/scripts/hooks/reread_guard_hook.ts": main44,
26812
- "src/scripts/hooks/session_eol_hook.ts": main45
27356
+ "src/scripts/hooks/turn_end_gate_hook.ts": main43,
27357
+ "src/scripts/hooks/edit_shape_hook.ts": main44,
27358
+ "src/scripts/hooks/reread_guard_hook.ts": main45,
27359
+ "src/scripts/hooks/session_eol_hook.ts": main46,
27360
+ "src/scripts/hooks/subagent_ledger_hook.ts": main42,
27361
+ "src/scripts/hooks/spawn_guard_shadow_hook.ts": main47
26813
27362
  };
26814
27363
 
26815
27364
  // src/scripts/hooks/host_semantics.ts
@@ -26821,7 +27370,9 @@ var CLAUDE_HOOK_EVENT_NAME = {
26821
27370
  session_start: "SessionStart",
26822
27371
  session_end: "SessionEnd",
26823
27372
  stop: "Stop",
26824
- pre_compact: "PreCompact"
27373
+ pre_compact: "PreCompact",
27374
+ subagent_start: "SubagentStart",
27375
+ subagent_stop: "SubagentStop"
26825
27376
  };
26826
27377
  var CLAUDE_BLOCK_CAPABLE_EVENTS = /* @__PURE__ */ new Set([
26827
27378
  "pre_tool_use",
@@ -26863,12 +27414,12 @@ function emitFor(platform, event, severity, reasons, legacyExit) {
26863
27414
 
26864
27415
  // src/scripts/hooks/dispatch_hook.ts
26865
27416
  var _IN_BUNDLE = true;
26866
- var REPO_ROOT = path67.resolve(
26867
- path67.dirname(fileURLToPath47(import.meta.url)),
27417
+ var REPO_ROOT = path69.resolve(
27418
+ path69.dirname(fileURLToPath49(import.meta.url)),
26868
27419
  ..._IN_BUNDLE ? ["..", ".."] : ["..", "..", ".."]
26869
27420
  );
26870
- var MANIFEST_PATH = path67.join(REPO_ROOT, "src", "scripts", "hook_manifest.yaml");
26871
- var EXIT_ALLOW21 = 0;
27421
+ var MANIFEST_PATH = path69.join(REPO_ROOT, "src", "scripts", "hook_manifest.yaml");
27422
+ var EXIT_ALLOW23 = 0;
26872
27423
  var EXIT_BLOCK5 = 1;
26873
27424
  var EXIT_WARN14 = 2;
26874
27425
  var EVENT_VOCABULARY = /* @__PURE__ */ new Set([
@@ -26879,10 +27430,12 @@ var EVENT_VOCABULARY = /* @__PURE__ */ new Set([
26879
27430
  "post_tool_use",
26880
27431
  "stop",
26881
27432
  "pre_compact",
26882
- "agent_error"
27433
+ "agent_error",
27434
+ "subagent_start",
27435
+ "subagent_stop"
26883
27436
  ]);
26884
27437
  var _SEVERITY_BY_EXIT = {
26885
- [EXIT_ALLOW21]: "allow",
27438
+ [EXIT_ALLOW23]: "allow",
26886
27439
  [EXIT_BLOCK5]: "block",
26887
27440
  [EXIT_WARN14]: "warn"
26888
27441
  };
@@ -26919,7 +27472,7 @@ function _parse_concern_stdout(stdout_text) {
26919
27472
  return _isObject14(parsed) ? parsed : { _raw: parsed };
26920
27473
  }
26921
27474
  function _load_yaml3(p) {
26922
- const text = fs65.readFileSync(p, "utf-8");
27475
+ const text = fs67.readFileSync(p, "utf-8");
26923
27476
  const data = (0, import_yaml6.parse)(text, { version: "1.1" });
26924
27477
  return _isObject14(data) ? data : {};
26925
27478
  }
@@ -27076,7 +27629,7 @@ function _maybe_capture_payload(args, payload_text) {
27076
27629
  }
27077
27630
  try {
27078
27631
  const target = _expanduser3(capture_dir);
27079
- fs65.mkdirSync(target, { recursive: true });
27632
+ fs67.mkdirSync(target, { recursive: true });
27080
27633
  let payload;
27081
27634
  try {
27082
27635
  payload = payload_text.trim() ? JSON.parse(payload_text) : {};
@@ -27093,8 +27646,8 @@ function _maybe_capture_payload(args, payload_text) {
27093
27646
  const ts = Date.now();
27094
27647
  const native = (args.native_event || args.event).replace(/\//g, "_");
27095
27648
  const fname = `${args.platform}__${native}__${ts}__${process.pid}.json`;
27096
- fs65.writeFileSync(
27097
- path67.join(target, fname),
27649
+ fs67.writeFileSync(
27650
+ path69.join(target, fname),
27098
27651
  _py_json_dumps2(record, 2) + "\n",
27099
27652
  { encoding: "utf-8" }
27100
27653
  );
@@ -27105,7 +27658,7 @@ function _maybe_capture_payload(args, payload_text) {
27105
27658
  function _expanduser3(p) {
27106
27659
  if (p === "~" || p.startsWith("~/")) {
27107
27660
  const home = process.env["HOME"] || process.env["USERPROFILE"] || "";
27108
- return path67.join(home, p.slice(1));
27661
+ return path69.join(home, p.slice(1));
27109
27662
  }
27110
27663
  return p;
27111
27664
  }
@@ -27137,25 +27690,25 @@ function _resolve_tsx_invocation2(scriptPath, scriptArgs) {
27137
27690
  const walkUp = (start) => {
27138
27691
  let dir = start;
27139
27692
  for (; ; ) {
27140
- const candidate = path67.join(dir, "node_modules", ".bin", binName);
27693
+ const candidate = path69.join(dir, "node_modules", ".bin", binName);
27141
27694
  if (_isFile7(candidate)) {
27142
27695
  return candidate;
27143
27696
  }
27144
- const parent = path67.dirname(dir);
27697
+ const parent = path69.dirname(dir);
27145
27698
  if (parent === dir) {
27146
27699
  return null;
27147
27700
  }
27148
27701
  dir = parent;
27149
27702
  }
27150
27703
  };
27151
- const tsx = walkUp(path67.dirname(scriptPath)) ?? walkUp(path67.dirname(fileURLToPath47(import.meta.url)));
27704
+ const tsx = walkUp(path69.dirname(scriptPath)) ?? walkUp(path69.dirname(fileURLToPath49(import.meta.url)));
27152
27705
  if (tsx !== null) {
27153
27706
  return { command: tsx, args: [scriptPath, ...scriptArgs] };
27154
27707
  }
27155
27708
  return { command: "npx", args: ["tsx", scriptPath, ...scriptArgs] };
27156
27709
  }
27157
27710
  function _run_concern_inproc(main_fn, concern, envelope) {
27158
- const scriptAbs = path67.join(REPO_ROOT, String(concern["script"]));
27711
+ const scriptAbs = path69.join(REPO_ROOT, String(concern["script"]));
27159
27712
  const argsList = Array.isArray(concern["args"]) ? concern["args"].map((a) => String(a)) : [];
27160
27713
  argsList.push("--platform", String(envelope["platform"] || "generic"));
27161
27714
  const workspace = String(envelope["workspace_root"] || process.cwd());
@@ -27232,7 +27785,7 @@ function _run_concern(concern, envelope) {
27232
27785
  return _run_concern_inproc(inproc, concern, envelope);
27233
27786
  }
27234
27787
  }
27235
- const script = path67.join(REPO_ROOT, String(concern["script"]));
27788
+ const script = path69.join(REPO_ROOT, String(concern["script"]));
27236
27789
  const argsList = Array.isArray(concern["args"]) ? concern["args"].map((a) => String(a)) : [];
27237
27790
  const cmd = [script, ...argsList];
27238
27791
  cmd.push("--platform", String(envelope["platform"] || "generic"));
@@ -27289,7 +27842,7 @@ function _run_concern(concern, envelope) {
27289
27842
  }
27290
27843
  function _isFile7(p) {
27291
27844
  try {
27292
- return fs65.statSync(p).isFile();
27845
+ return fs67.statSync(p).isFile();
27293
27846
  } catch {
27294
27847
  return false;
27295
27848
  }
@@ -27304,17 +27857,17 @@ function _reduce(rcs) {
27304
27857
  if (rcs.some((rc) => rc === EXIT_WARN14)) {
27305
27858
  return EXIT_WARN14;
27306
27859
  }
27307
- return EXIT_ALLOW21;
27860
+ return EXIT_ALLOW23;
27308
27861
  }
27309
27862
  function _write_feedback(envelope, session_id, entries, final_rc, started_at) {
27310
27863
  if (is_replay_mode()) {
27311
27864
  return;
27312
27865
  }
27313
27866
  const workspace = String(envelope["workspace_root"] || process.cwd());
27314
- const state_root = path67.join(workspace, "agents", "runtime", "state");
27867
+ const state_root = path69.join(workspace, "agents", "runtime", "state");
27315
27868
  const fb_dir = feedback_dir(state_root, session_id);
27316
27869
  try {
27317
- fs65.mkdirSync(fb_dir, { recursive: true });
27870
+ fs67.mkdirSync(fb_dir, { recursive: true });
27318
27871
  } catch (exc) {
27319
27872
  const msg = exc instanceof Error ? exc.message : String(exc);
27320
27873
  process.stderr.write(`dispatch_hook: feedback dir unavailable: ${msg}
@@ -27322,7 +27875,7 @@ function _write_feedback(envelope, session_id, entries, final_rc, started_at) {
27322
27875
  return;
27323
27876
  }
27324
27877
  for (const entry of entries) {
27325
- const target = path67.join(fb_dir, `${entry["concern"]}.json`);
27878
+ const target = path69.join(fb_dir, `${entry["concern"]}.json`);
27326
27879
  try {
27327
27880
  atomic_write_json(target, entry);
27328
27881
  } catch (exc) {
@@ -27362,7 +27915,7 @@ function _write_feedback(envelope, session_id, entries, final_rc, started_at) {
27362
27915
  })
27363
27916
  };
27364
27917
  try {
27365
- atomic_write_json(path67.join(fb_dir, "summary.json"), summary);
27918
+ atomic_write_json(path69.join(fb_dir, "summary.json"), summary);
27366
27919
  } catch (exc) {
27367
27920
  const msg = exc instanceof Error ? exc.message : String(exc);
27368
27921
  process.stderr.write(`dispatch_hook: summary write failed: ${msg}
@@ -27377,12 +27930,12 @@ function _record_rule_trips(envelope, entries) {
27377
27930
  if (tripped.length === 0) return;
27378
27931
  try {
27379
27932
  const workspace = String(envelope["workspace_root"] || process.cwd());
27380
- const state_dir = path67.join(workspace, "agents", "runtime", "state");
27381
- const target = path67.join(state_dir, "rule-trips.json");
27382
- fs65.mkdirSync(state_dir, { recursive: true });
27933
+ const state_dir = path69.join(workspace, "agents", "runtime", "state");
27934
+ const target = path69.join(state_dir, "rule-trips.json");
27935
+ fs67.mkdirSync(state_dir, { recursive: true });
27383
27936
  let doc = { schema_version: 1, concerns: {} };
27384
27937
  try {
27385
- const parsed = JSON.parse(fs65.readFileSync(target, "utf-8"));
27938
+ const parsed = JSON.parse(fs67.readFileSync(target, "utf-8"));
27386
27939
  if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) doc = parsed;
27387
27940
  } catch {
27388
27941
  }
@@ -27481,7 +28034,7 @@ function _parse_args(argv) {
27481
28034
  }
27482
28035
  return args;
27483
28036
  }
27484
- function main46(argv) {
28037
+ function main48(argv) {
27485
28038
  const args = _parse_args(argv ?? process.argv.slice(2));
27486
28039
  if (args.project_dir) {
27487
28040
  const project_dir = _expanduser3(args.project_dir);
@@ -27499,13 +28052,13 @@ function main46(argv) {
27499
28052
  `dispatch_hook: unknown event '${args.event}'; allowed: ${_sortedRepr(EVENT_VOCABULARY)}
27500
28053
  `
27501
28054
  );
27502
- return EXIT_ALLOW21;
28055
+ return EXIT_ALLOW23;
27503
28056
  }
27504
28057
  const manifest_path = args.manifest;
27505
- if (!fs65.existsSync(manifest_path)) {
28058
+ if (!fs67.existsSync(manifest_path)) {
27506
28059
  process.stderr.write(`dispatch_hook: manifest missing at ${manifest_path}
27507
28060
  `);
27508
- return EXIT_ALLOW21;
28061
+ return EXIT_ALLOW23;
27509
28062
  }
27510
28063
  const manifest = _load_yaml3(manifest_path);
27511
28064
  if (args.min_version) {
@@ -27529,10 +28082,10 @@ function main46(argv) {
27529
28082
  concerns: concerns.map((c) => c["name"])
27530
28083
  };
27531
28084
  process.stdout.write(_py_json_dumps2(plan, 2) + "\n");
27532
- return EXIT_ALLOW21;
28085
+ return EXIT_ALLOW23;
27533
28086
  }
27534
28087
  if (concerns.length === 0) {
27535
- return EXIT_ALLOW21;
28088
+ return EXIT_ALLOW23;
27536
28089
  }
27537
28090
  const envelope = _build_envelope(args, payload_text);
27538
28091
  const session_id = _resolve_session_id(envelope);
@@ -27552,7 +28105,7 @@ function main46(argv) {
27552
28105
  const raw_rc = rc;
27553
28106
  if (rc >= 3) {
27554
28107
  if (!concern["fail_closed"]) {
27555
- rc = EXIT_ALLOW21;
28108
+ rc = EXIT_ALLOW23;
27556
28109
  } else {
27557
28110
  rc = EXIT_BLOCK5;
27558
28111
  }
@@ -27575,7 +28128,7 @@ function main46(argv) {
27575
28128
  if (message) {
27576
28129
  concern_messages.push({ rc, text: message });
27577
28130
  }
27578
- if (args.event === "session_start" && rc === EXIT_ALLOW21 && typeof reply["context"] === "string" && reply["context"].trim()) {
28131
+ if (args.event === "session_start" && rc === EXIT_ALLOW23 && typeof reply["context"] === "string" && reply["context"].trim()) {
27579
28132
  context_blocks.push(reply["context"].trim());
27580
28133
  }
27581
28134
  feedback_entries.push({
@@ -27594,7 +28147,7 @@ function main46(argv) {
27594
28147
  const final_rc = _reduce(rcs);
27595
28148
  _write_feedback(envelope, session_id, feedback_entries, final_rc, started_at);
27596
28149
  _record_rule_trips(envelope, feedback_entries);
27597
- if (context_blocks.length > 0 && final_rc === EXIT_ALLOW21) {
28150
+ if (context_blocks.length > 0 && final_rc === EXIT_ALLOW23) {
27598
28151
  process.stdout.write(context_blocks.join("\n\n") + "\n");
27599
28152
  }
27600
28153
  const decidingReasons = concern_messages.filter((m) => m.rc === final_rc).map((m) => m.text);
@@ -27615,7 +28168,7 @@ function main46(argv) {
27615
28168
  }
27616
28169
  function _isDir4(p) {
27617
28170
  try {
27618
- return fs65.statSync(p).isDirectory();
28171
+ return fs67.statSync(p).isDirectory();
27619
28172
  } catch {
27620
28173
  return false;
27621
28174
  }
@@ -27626,41 +28179,41 @@ function _sortedRepr(s) {
27626
28179
  }
27627
28180
  function _readStdin14() {
27628
28181
  try {
27629
- return fs65.readFileSync(0, "utf-8");
28182
+ return fs67.readFileSync(0, "utf-8");
27630
28183
  } catch {
27631
28184
  return "";
27632
28185
  }
27633
28186
  }
27634
- function _isCliEntry36() {
28187
+ function _isCliEntry38() {
27635
28188
  if (true) {
27636
28189
  return false;
27637
28190
  }
27638
28191
  if (process.argv[1] === void 0) {
27639
28192
  return false;
27640
28193
  }
27641
- const argvUrl = pathToFileURL41(path67.resolve(process.argv[1])).href;
28194
+ const argvUrl = pathToFileURL43(path69.resolve(process.argv[1])).href;
27642
28195
  if (import.meta.url === argvUrl) {
27643
28196
  return true;
27644
28197
  }
27645
28198
  try {
27646
- const here = fs65.realpathSync(fileURLToPath47(import.meta.url));
27647
- const argv = fs65.realpathSync(path67.resolve(process.argv[1]));
28199
+ const here = fs67.realpathSync(fileURLToPath49(import.meta.url));
28200
+ const argv = fs67.realpathSync(path69.resolve(process.argv[1]));
27648
28201
  return here === argv;
27649
28202
  } catch {
27650
28203
  return false;
27651
28204
  }
27652
28205
  }
27653
- var isCliEntry13 = _isCliEntry36();
28206
+ var isCliEntry13 = _isCliEntry38();
27654
28207
  if (isCliEntry13) {
27655
- process.exit(main46(process.argv.slice(2)));
28208
+ process.exit(main48(process.argv.slice(2)));
27656
28209
  }
27657
28210
 
27658
28211
  // src/scripts/hooks/dispatch_entry.ts
27659
- var _selfPath = fileURLToPath48(import.meta.url);
27660
- var _invokedDirectly2 = globalThis.__AC_HOOKS_BUNDLE_DIRECT === true || process.argv[1] !== void 0 && path68.resolve(process.argv[1]) === path68.resolve(_selfPath);
28212
+ var _selfPath = fileURLToPath50(import.meta.url);
28213
+ var _invokedDirectly2 = globalThis.__AC_HOOKS_BUNDLE_DIRECT === true || process.argv[1] !== void 0 && path70.resolve(process.argv[1]) === path70.resolve(_selfPath);
27661
28214
  if (_invokedDirectly2) {
27662
- process.exitCode = main46(process.argv.slice(2));
28215
+ process.exitCode = main48(process.argv.slice(2));
27663
28216
  }
27664
28217
  export {
27665
- main46 as main
28218
+ main48 as main
27666
28219
  };