@event4u/agent-config 9.28.0 → 9.30.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 (209) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/AGENTS.md +6 -6
  3. package/CHANGELOG.md +172 -5
  4. package/README.md +2 -1
  5. package/agents/templates/.ai-council.yml.example +55 -24
  6. package/dist/agent-src/commands/analyze/inbox.md +22 -1
  7. package/dist/agent-src/commands/cost/report.md +2 -2
  8. package/dist/agent-src/commands/explain-run.md +31 -1
  9. package/dist/agent-src/commands/team/adversarial.md +8 -7
  10. package/dist/agent-src/commands/team/delegate.md +14 -12
  11. package/dist/agent-src/commands/team/review.md +9 -8
  12. package/dist/agent-src/commands/team/status.md +9 -8
  13. package/dist/agent-src/commands/team.md +29 -19
  14. package/dist/agent-src/contexts/execution/auto-dispatch-classification.md +88 -2
  15. package/dist/agent-src/contexts/execution/auto-orchestration-activation.md +29 -21
  16. package/dist/agent-src/contexts/execution/host-capability-manifest.md +26 -15
  17. package/dist/agent-src/contexts/execution/orchestration-telemetry.md +22 -1
  18. package/dist/agent-src/contexts/execution/roadmap-process-loop.md +17 -0
  19. package/dist/agent-src/contexts/execution/subagent-response-contract.md +65 -1
  20. package/dist/agent-src/contexts/execution/subagent-routing.md +13 -11
  21. package/dist/agent-src/contexts/execution/subagent-spawn-contract.md +25 -0
  22. package/dist/agent-src/contexts/execution/subagent-steering.md +6 -3
  23. package/dist/agent-src/rules/delegation-policy.md +11 -7
  24. package/dist/agent-src/rules/preservation-guard.md +9 -0
  25. package/dist/agent-src/rules/settings-ask-protocol.md +8 -7
  26. package/dist/agent-src/rules/token-budget-discipline.md +1 -1
  27. package/dist/agent-src/scripts/roadmap_gates.ts +312 -0
  28. package/dist/agent-src/scripts/update_roadmap_progress.ts +72 -4
  29. package/dist/agent-src/skills/forensics-report/SKILL.md +114 -0
  30. package/dist/agent-src/skills/forensics-report/evals/triggers.json +17 -0
  31. package/dist/agent-src/skills/premortem/SKILL.md +30 -1
  32. package/dist/agent-src/skills/reasoning-orchestrator/SKILL.md +2 -1
  33. package/dist/agent-src/skills/subagent-orchestration/SKILL.md +17 -5
  34. package/dist/agent-src/skills/subagent-orchestration/schemas/subagent-status.json +61 -3
  35. package/dist/agent-src/skills/test-case-discovery/SKILL.md +1 -1
  36. package/dist/agent-src/templates/AGENTS.md +4 -4
  37. package/dist/agent-src/templates/agents/agent-project-settings.example.yml +1 -1
  38. package/dist/agent-src/templates/roadmaps.md +23 -0
  39. package/dist/cli/registry.js +2 -0
  40. package/dist/cli/registry.js.map +1 -1
  41. package/dist/cli-delegate/{chunk-22GCIJ2O.js → chunk-66OVWGB5.js} +1 -1
  42. package/dist/cli-delegate/{chunk-7OMQCH4V.js → chunk-BTJNRUX3.js} +22 -35
  43. package/dist/cli-delegate/{chunk-DVRS2KVR.js → chunk-DDUNNFYX.js} +24 -17
  44. package/dist/cli-delegate/{chunk-PQSAQKHW.js → chunk-EQY4FLJB.js} +3 -3
  45. package/dist/cli-delegate/{chunk-2BE5I2MN.js → chunk-IYTGIG2Y.js} +155 -91
  46. package/dist/cli-delegate/{chunk-GB2FSUEE.js → chunk-LCFJIQ4J.js} +32 -0
  47. package/dist/cli-delegate/{chunk-VSYT7OHO.js → chunk-LVRYBKTI.js} +31 -2
  48. package/dist/cli-delegate/chunk-MMJL4TIX.js +18 -0
  49. package/dist/cli-delegate/{chunk-JXARCGVN.js → chunk-MP3JT3IU.js} +1 -1
  50. package/dist/cli-delegate/chunk-O3CO5BFB.js +161 -0
  51. package/dist/cli-delegate/{chunk-REKCMYOU.js → chunk-PFBV6XRT.js} +36 -20
  52. package/dist/cli-delegate/chunk-RVGBH4XK.js +142 -0
  53. package/dist/cli-delegate/cmd_analyze_session.js +1 -1
  54. package/dist/cli-delegate/cmd_brand_status.js +1 -1
  55. package/dist/cli-delegate/cmd_conformance.js +2803 -137
  56. package/dist/cli-delegate/cmd_doctor.js +10 -5
  57. package/dist/cli-delegate/cmd_explain.js +2 -2
  58. package/dist/cli-delegate/cmd_export.js +4 -4
  59. package/dist/cli-delegate/cmd_handoff.js +88 -8
  60. package/dist/cli-delegate/cmd_mcp_available.js +1 -1
  61. package/dist/cli-delegate/cmd_migrate.js +2 -2
  62. package/dist/cli-delegate/cmd_packs_active.js +2 -2
  63. package/dist/cli-delegate/cmd_prune.js +4 -4
  64. package/dist/cli-delegate/cmd_route_audit.js +3 -2
  65. package/dist/cli-delegate/cmd_route_explain.js +1 -1
  66. package/dist/cli-delegate/cmd_session_recycle.js +177 -0
  67. package/dist/cli-delegate/cmd_settings_get.js +2 -8
  68. package/dist/cli-delegate/cmd_settings_migrate.js +4 -4
  69. package/dist/cli-delegate/cmd_settings_set.js +2 -2
  70. package/dist/cli-delegate/cmd_sync.js +4 -4
  71. package/dist/cli-delegate/cmd_uninstall.js +4 -4
  72. package/dist/cli-delegate/cmd_update.js +1 -1
  73. package/dist/cli-delegate/cmd_upgrade.js +1 -1
  74. package/dist/cli-delegate/cmd_validate.js +4 -4
  75. package/dist/cli-delegate/cmd_versions.js +1 -1
  76. package/dist/discovery/deprecation-report.md +1 -1
  77. package/dist/discovery/discovery-manifest.json +72 -23
  78. package/dist/discovery/discovery-manifest.json.sha256 +1 -1
  79. package/dist/discovery/discovery-manifest.summary.md +3 -2
  80. package/dist/discovery/orphan-report.md +1 -1
  81. package/dist/discovery/packs.json +39 -2
  82. package/dist/discovery/trust-report.md +2 -2
  83. package/dist/discovery/workspaces.json +12 -4
  84. package/dist/hooks/dispatch.js +2278 -611
  85. package/dist/install/install.mjs +56 -17
  86. package/dist/mcp/registry-manifest.json +3 -3
  87. package/dist/mcp/server.json +2 -2
  88. package/dist/mcp/server.mjs +4122 -699
  89. package/dist/router.json +1 -1
  90. package/dist/scripts/_lib/agent_settings.js +54 -0
  91. package/dist/scripts/_lib/agent_settings.js.map +1 -1
  92. package/dist/scripts/condense.js +147 -2
  93. package/dist/scripts/condense.js.map +1 -1
  94. package/dist/server/schemas/settings.js +12 -7
  95. package/dist/server/schemas/settings.js.map +1 -1
  96. package/dist/shared/settingsCarveOut.js +0 -9
  97. package/dist/shared/settingsCarveOut.js.map +1 -1
  98. package/dist/shared/settingsClasses.js +11 -9
  99. package/dist/shared/settingsClasses.js.map +1 -1
  100. package/dist/ui/assets/index-B5qGYOJo.js +26 -0
  101. package/dist/ui/assets/index-B5qGYOJo.js.map +1 -0
  102. package/dist/ui/index.html +1 -1
  103. package/docs/contracts/settings-classes.md +58 -12
  104. package/package.json +1 -1
  105. package/src/agent-src/scripts/roadmap_gates.ts +312 -0
  106. package/src/agent-src/scripts/update_roadmap_progress.ts +72 -4
  107. package/src/agent-src/templates/AGENTS.md +4 -4
  108. package/src/config/agent-settings.template.yml +88 -66
  109. package/src/config/discovery/packs.yml +11 -0
  110. package/src/config/discovery/workspaces.yml +1 -1
  111. package/src/config/dispatch-economy-metrics.json +61 -0
  112. package/src/config/evaluator-budgets.json +4 -4
  113. package/src/config/gate-violation-baselines.json +3 -3
  114. package/src/config/hook-token-budget.json +91 -0
  115. package/src/config/recycle-threshold-budget.json +12 -0
  116. package/src/config/rule-enforcement-baseline.json +86 -0
  117. package/src/scripts/_cli/cmd_conformance.ts +31 -44
  118. package/src/scripts/_cli/cmd_doctor.ts +65 -48
  119. package/src/scripts/_cli/cmd_session_recycle.ts +226 -0
  120. package/src/scripts/_dispatch.bash +23 -0
  121. package/src/scripts/_lib/agent_settings.ts +58 -0
  122. package/src/scripts/_lib/auto_dispatch.corpus.test.ts +1 -1
  123. package/src/scripts/_lib/auto_dispatch.ts +23 -18
  124. package/src/scripts/_lib/capsule_trigger.ts +124 -0
  125. package/src/scripts/_lib/host_capability.ts +63 -6
  126. package/src/scripts/_lib/judgment_ladder.ts +634 -0
  127. package/src/scripts/_lib/orchestration_gate.ts +8 -0
  128. package/src/scripts/_lib/orchestration_record.ts +78 -10
  129. package/src/scripts/_lib/orchestration_savings.ts +1 -1
  130. package/src/scripts/_lib/recycle_envelope_paths.ts +35 -0
  131. package/src/scripts/_lib/self_repair.ts +354 -13
  132. package/src/scripts/_lib/self_repair_store.ts +28 -0
  133. package/src/scripts/_lib/session_eol.ts +230 -0
  134. package/src/scripts/_lib/session_role.ts +42 -0
  135. package/src/scripts/_lib/subagent_capsule.ts +341 -0
  136. package/src/scripts/_lib/subagent_response.ts +94 -0
  137. package/src/scripts/_lib/subagent_spawn.ts +13 -0
  138. package/src/scripts/_lib/subagent_steering.ts +9 -4
  139. package/src/scripts/_lib/tier_budget_routing.ts +6 -1
  140. package/src/scripts/_lib/worker_budget.ts +37 -2
  141. package/src/scripts/ai_council/clients.ts +126 -55
  142. package/src/scripts/ai_council/config.ts +94 -6
  143. package/src/scripts/ai_council/handoff.ts +113 -0
  144. package/src/scripts/ai_council/modes.ts +19 -4
  145. package/src/scripts/ai_council/orchestrator.ts +105 -0
  146. package/src/scripts/ai_council/quorum.ts +84 -0
  147. package/src/scripts/ai_council/session.ts +44 -0
  148. package/src/scripts/ai_council/transport_resolver.ts +127 -1
  149. package/src/scripts/ai_team/availability.ts +110 -0
  150. package/src/scripts/ai_team/config.ts +34 -14
  151. package/src/scripts/ai_team/team_dispatch.ts +71 -29
  152. package/src/scripts/ask_transport.ts +221 -0
  153. package/src/scripts/bench_critic_protocol.ts +396 -0
  154. package/src/scripts/bench_hook_injection.ts +234 -0
  155. package/src/scripts/check_adr_frontmatter.ts +84 -40
  156. package/src/scripts/check_branch_freshness.ts +1 -0
  157. package/src/scripts/check_corpus_staleness.ts +18 -4
  158. package/src/scripts/check_detector_corpus.ts +219 -0
  159. package/src/scripts/check_gitignore_freshness.ts +42 -8
  160. package/src/scripts/check_hook_bundle_freshness.ts +24 -1
  161. package/src/scripts/check_kernel_prefix_stability.ts +1 -0
  162. package/src/scripts/check_standing_rule_delivery.ts +73 -32
  163. package/src/scripts/check_static_layer_stability.ts +154 -0
  164. package/src/scripts/check_suppression_hygiene.ts +48 -0
  165. package/src/scripts/condense.ts +162 -2
  166. package/src/scripts/council_cli.ts +401 -25
  167. package/src/scripts/dispatch_economy_report.ts +448 -0
  168. package/src/scripts/dispatch_r2_reviewer.ts +15 -2
  169. package/src/scripts/explain_run.ts +206 -4
  170. package/src/scripts/forensics_report.ts +333 -0
  171. package/src/scripts/generate_settings_reference.ts +1 -0
  172. package/src/scripts/handoff_context_hook.ts +112 -4
  173. package/src/scripts/hook_manifest.yaml +117 -10
  174. package/src/scripts/hooks/concern_registry.ts +8 -0
  175. package/src/scripts/hooks/delegation_nudge_hook.ts +106 -35
  176. package/src/scripts/hooks/dispatch_hook.ts +39 -2
  177. package/src/scripts/hooks/edit_shape_hook.ts +303 -0
  178. package/src/scripts/hooks/orchestration_record_hook.ts +19 -1
  179. package/src/scripts/hooks/reread_guard_hook.ts +314 -0
  180. package/src/scripts/hooks/rtk_wrap_hook.ts +133 -14
  181. package/src/scripts/hooks/session_eol_hook.ts +268 -0
  182. package/src/scripts/hooks/turn_end_gate_hook.ts +507 -0
  183. package/src/scripts/install-hooks.sh +1 -1
  184. package/src/scripts/language_mirror_hook.ts +89 -0
  185. package/src/scripts/lint_decision_impact.ts +14 -1
  186. package/src/scripts/lint_discovery_vocabulary.ts +2 -0
  187. package/src/scripts/lint_hook_manifest.ts +82 -0
  188. package/src/scripts/lint_never_silent.ts +276 -0
  189. package/src/scripts/lint_no_activation_gates.ts +271 -0
  190. package/src/scripts/lint_readme_serial_comma.ts +1 -0
  191. package/src/scripts/lint_rule_enforcement_declaration.ts +347 -0
  192. package/src/scripts/measure_turn_end_gate.ts +194 -0
  193. package/src/scripts/orchestration_record.ts +12 -1
  194. package/src/scripts/rebuild_hook_bundle.ts +178 -0
  195. package/src/scripts/release.ts +74 -2
  196. package/src/scripts/report_conformance_funnel.ts +284 -0
  197. package/src/scripts/report_imperative_density.ts +1 -0
  198. package/src/scripts/routing_doctor.ts +118 -36
  199. package/src/scripts/score_skill_selection.ts +19 -5
  200. package/src/scripts/self_repair_cli.ts +337 -59
  201. package/src/scripts/session_eol_report.ts +261 -0
  202. package/src/scripts/team_events_spike.ts +271 -0
  203. package/src/scripts/team_review_gate_hook.ts +31 -9
  204. package/src/server/schemas/settings.ts +24 -17
  205. package/src/shared/settingsCarveOut.ts +0 -10
  206. package/src/shared/settingsClasses.ts +11 -9
  207. package/src/templates/compact-instructions.md +40 -0
  208. package/dist/ui/assets/index-DmR0mbk4.js +0 -26
  209. package/dist/ui/assets/index-DmR0mbk4.js.map +0 -1
@@ -343,6 +343,7 @@ function _build_config(raw, source_path) {
343
343
  const cli_call_budget = _build_cli_call_budget(
344
344
  _asDict(_getOr(raw, "cli_call_budget", {}))
345
345
  );
346
+ const quorum = _build_quorum(_get(raw, "quorum", "majority"));
346
347
  const necessity_classifier = _build_necessity_classifier(
347
348
  _asDict(_getOr(raw, "necessity_classifier", {}))
348
349
  );
@@ -368,6 +369,7 @@ function _build_config(raw, source_path) {
368
369
  "debate_gates"
369
370
  );
370
371
  const restate = _build_restate(_asDict(_getOr(raw, "restate", {})), "restate");
372
+ const critic_protocol = _build_critic_protocol(_getOr(raw, "critic_protocol", "legacy"));
371
373
  const decision_resolution = _build_decision_resolution(
372
374
  _asDict(_getOr(raw, "decision_resolution", {}))
373
375
  );
@@ -389,6 +391,7 @@ function _build_config(raw, source_path) {
389
391
  advisors,
390
392
  consensus_scoring: consensus,
391
393
  cli_call_budget,
394
+ quorum,
392
395
  necessity_classifier,
393
396
  model_downgrade,
394
397
  debate,
@@ -397,6 +400,7 @@ function _build_config(raw, source_path) {
397
400
  chairman,
398
401
  debate_gates,
399
402
  restate,
403
+ critic_protocol,
400
404
  decision_resolution,
401
405
  routing,
402
406
  low_impact,
@@ -598,6 +602,16 @@ function _build_restate(d, scope) {
598
602
  }
599
603
  return { enabled: Boolean(enabled) };
600
604
  }
605
+ var _VALID_CRITIC_PROTOCOLS = /* @__PURE__ */ new Set(["legacy", "load_bearing"]);
606
+ function _build_critic_protocol(v) {
607
+ if (v === void 0 || v === null) return "legacy";
608
+ if (!(_isStr(v) && _VALID_CRITIC_PROTOCOLS.has(v))) {
609
+ throw new CouncilConfigError(
610
+ `\`critic_protocol\`=${_pyRepr(v)} not in ${_sortedListRepr(_VALID_CRITIC_PROTOCOLS)}.`
611
+ );
612
+ }
613
+ return v;
614
+ }
601
615
  var _VALID_RESOLUTION_MODES = /* @__PURE__ */ new Set([
602
616
  "agent",
603
617
  "council",
@@ -873,7 +887,7 @@ function _build_defaults(d) {
873
887
  if (!_isDict(d)) {
874
888
  throw new CouncilConfigError("`defaults` must be a mapping.");
875
889
  }
876
- const mode = _get(d, "mode", "api");
890
+ const mode = _get(d, "mode", "auto");
877
891
  if (!(_isStr(mode) && _VALID_MODES.has(mode))) {
878
892
  throw new CouncilConfigError(
879
893
  `defaults.mode=${_pyRepr(mode)} not in ${_sortedListRepr(_VALID_MODES)}.`
@@ -1035,7 +1049,7 @@ function _build_cost_budget(d) {
1035
1049
  }
1036
1050
  return cb;
1037
1051
  }
1038
- function _build_member(name, cfg, default_mode = "api") {
1052
+ function _build_member(name, cfg, default_mode = "auto") {
1039
1053
  if (!_VALID_PROVIDERS.has(name)) {
1040
1054
  throw new CouncilConfigError(
1041
1055
  `members.${name}: unknown provider; valid: ${_sortedListRepr(_VALID_PROVIDERS)}.`
@@ -1152,6 +1166,7 @@ function _build_member(name, cfg, default_mode = "api") {
1152
1166
  prompt_cache_ttl
1153
1167
  };
1154
1168
  }
1169
+ var _DEFAULT_CLI_CALLS_PER_DAY = 50;
1155
1170
  function _build_cli_call_budget(d) {
1156
1171
  if (!_isDict(d)) {
1157
1172
  throw new CouncilConfigError("`cli_call_budget` must be a mapping.");
@@ -1163,6 +1178,9 @@ function _build_cli_call_budget(d) {
1163
1178
  );
1164
1179
  }
1165
1180
  const caps = /* @__PURE__ */ new Map();
1181
+ for (const provider of _VALID_PROVIDERS) {
1182
+ caps.set(provider, _DEFAULT_CLI_CALLS_PER_DAY);
1183
+ }
1166
1184
  for (const [provider, value] of Object.entries(raw_caps)) {
1167
1185
  if (!_VALID_PROVIDERS.has(provider)) {
1168
1186
  throw new CouncilConfigError(
@@ -1190,6 +1208,17 @@ function _build_cli_call_budget(d) {
1190
1208
  }
1191
1209
  return { max_calls_per_day: caps, warn_at };
1192
1210
  }
1211
+ function _build_quorum(raw) {
1212
+ if (raw === "majority") {
1213
+ return "majority";
1214
+ }
1215
+ if (_isInt(raw) && !_isBool(raw) && raw >= 1) {
1216
+ return raw;
1217
+ }
1218
+ throw new CouncilConfigError(
1219
+ `\`quorum\`=${_pyRepr(raw)} must be 'majority' or an integer >= 1 (got ${_pyTypeName(raw)}).`
1220
+ );
1221
+ }
1193
1222
  function _build_advisor(name, cfg) {
1194
1223
  if (!_isDict(cfg)) {
1195
1224
  throw new CouncilConfigError(`advisors.${name}: must be a mapping.`);
@@ -0,0 +1,18 @@
1
+ import { createRequire as __acCreateRequire } from 'node:module'; const require = globalThis.require ?? __acCreateRequire(import.meta.url);
2
+
3
+ // src/scripts/hooks/hook_stdin.ts
4
+ import * as fs from "node:fs";
5
+ var _override = null;
6
+ function readHookStdin() {
7
+ if (_override !== null) return _override;
8
+ try {
9
+ if (process.stdin.isTTY) return "";
10
+ return fs.readFileSync(0, "utf-8");
11
+ } catch {
12
+ return "";
13
+ }
14
+ }
15
+
16
+ export {
17
+ readHookStdin
18
+ };
@@ -1,7 +1,7 @@
1
1
  import { createRequire as __acCreateRequire } from 'node:module'; const require = globalThis.require ?? __acCreateRequire(import.meta.url);
2
2
  import {
3
3
  resolve_project_root
4
- } from "./chunk-GB2FSUEE.js";
4
+ } from "./chunk-LCFJIQ4J.js";
5
5
  import {
6
6
  resolvePackageRoot
7
7
  } from "./chunk-MCJYCQPF.js";
@@ -0,0 +1,161 @@
1
+ import { createRequire as __acCreateRequire } from 'node:module'; const require = globalThis.require ?? __acCreateRequire(import.meta.url);
2
+
3
+ // src/scripts/hooks/state_io.ts
4
+ import fs from "node:fs";
5
+ import path from "node:path";
6
+ var LOCK_BASENAME = ".dispatcher.lock";
7
+ var REPLAY_ENV_VAR = "AGENT_CONFIG_REPLAY";
8
+ function is_replay_mode() {
9
+ return (process.env[REPLAY_ENV_VAR] ?? "").trim() === "1";
10
+ }
11
+ function _lock_path(state_dir) {
12
+ return path.join(state_dir, LOCK_BASENAME);
13
+ }
14
+ function _py_json_dumps(value, indent) {
15
+ const pad = " ".repeat(indent);
16
+ const escapeString = (s) => {
17
+ let out = '"';
18
+ for (const ch of s) {
19
+ const code = ch.codePointAt(0);
20
+ switch (ch) {
21
+ case '"':
22
+ out += '\\"';
23
+ break;
24
+ case "\\":
25
+ out += "\\\\";
26
+ break;
27
+ case "\n":
28
+ out += "\\n";
29
+ break;
30
+ case "\r":
31
+ out += "\\r";
32
+ break;
33
+ case " ":
34
+ out += "\\t";
35
+ break;
36
+ case "\b":
37
+ out += "\\b";
38
+ break;
39
+ case "\f":
40
+ out += "\\f";
41
+ break;
42
+ default:
43
+ if (code < 32 || code > 126) {
44
+ if (code > 65535) {
45
+ const c = code - 65536;
46
+ const hi = 55296 + (c >> 10);
47
+ const lo = 56320 + (c & 1023);
48
+ out += "\\u" + hi.toString(16).padStart(4, "0") + "\\u" + lo.toString(16).padStart(4, "0");
49
+ } else {
50
+ out += "\\u" + code.toString(16).padStart(4, "0");
51
+ }
52
+ } else {
53
+ out += ch;
54
+ }
55
+ }
56
+ }
57
+ return out + '"';
58
+ };
59
+ const render = (v, depth) => {
60
+ if (v === null || v === void 0) {
61
+ return "null";
62
+ }
63
+ if (typeof v === "boolean") {
64
+ return v ? "true" : "false";
65
+ }
66
+ if (typeof v === "number") {
67
+ if (!Number.isFinite(v)) {
68
+ if (Number.isNaN(v)) return "NaN";
69
+ return v > 0 ? "Infinity" : "-Infinity";
70
+ }
71
+ return String(v);
72
+ }
73
+ if (typeof v === "string") {
74
+ return escapeString(v);
75
+ }
76
+ const curPad = pad.repeat(depth + 1);
77
+ const closePad = pad.repeat(depth);
78
+ if (Array.isArray(v)) {
79
+ if (v.length === 0) {
80
+ return "[]";
81
+ }
82
+ const items = v.map((item) => curPad + render(item, depth + 1));
83
+ return "[\n" + items.join(",\n") + "\n" + closePad + "]";
84
+ }
85
+ if (typeof v === "object") {
86
+ const obj = v;
87
+ const keys = Object.keys(obj);
88
+ if (keys.length === 0) {
89
+ return "{}";
90
+ }
91
+ const items = keys.map(
92
+ (k) => curPad + escapeString(k) + ": " + render(obj[k], depth + 1)
93
+ );
94
+ return "{\n" + items.join(",\n") + "\n" + closePad + "}";
95
+ }
96
+ throw new TypeError(`Object of type ${typeof v} is not JSON serializable`);
97
+ };
98
+ return render(value, 0);
99
+ }
100
+ function atomic_write_json(target, payload, options = {}) {
101
+ if (is_replay_mode()) {
102
+ return;
103
+ }
104
+ const indent = options.indent ?? 2;
105
+ const targetPath = path.resolve(target);
106
+ const state_dir = path.dirname(targetPath);
107
+ fs.mkdirSync(state_dir, { recursive: true });
108
+ const body = _py_json_dumps(payload, indent) + "\n";
109
+ _atomic_write_text(targetPath, body);
110
+ }
111
+ function _acquire_lock(lock_path) {
112
+ const fd = fs.openSync(lock_path, "a", 420);
113
+ const held = lock_path + ".held";
114
+ const deadlineMs = 5e3;
115
+ const start = Date.now();
116
+ for (; ; ) {
117
+ try {
118
+ const heldFd = fs.openSync(held, "wx", 420);
119
+ fs.closeSync(heldFd);
120
+ return fd;
121
+ } catch (err) {
122
+ if (err.code !== "EEXIST") {
123
+ return fd;
124
+ }
125
+ if (Date.now() - start > deadlineMs) {
126
+ try {
127
+ fs.rmSync(held, { force: true });
128
+ } catch {
129
+ }
130
+ continue;
131
+ }
132
+ const sab = new Int32Array(new SharedArrayBuffer(4));
133
+ Atomics.wait(sab, 0, 0, 2);
134
+ }
135
+ }
136
+ }
137
+ function _release_lock(fd, lock_path) {
138
+ try {
139
+ fs.closeSync(fd);
140
+ } catch {
141
+ }
142
+ try {
143
+ fs.rmSync(lock_path + ".held", { force: true });
144
+ } catch {
145
+ }
146
+ }
147
+ function _atomic_write_text(target, text) {
148
+ const tmp = target + `.tmp.${process.pid}`;
149
+ const lock_path = _lock_path(path.dirname(target));
150
+ const fd = _acquire_lock(lock_path);
151
+ try {
152
+ fs.writeFileSync(tmp, text, { encoding: "utf-8" });
153
+ fs.renameSync(tmp, target);
154
+ } finally {
155
+ _release_lock(fd, lock_path);
156
+ }
157
+ }
158
+
159
+ export {
160
+ atomic_write_json
161
+ };
@@ -422,6 +422,11 @@ var binaryTag = defineScalarTag("tag:yaml.org,2002:binary", {
422
422
  });
423
423
  var YAML_DATE_REGEXP = /* @__PURE__ */ new RegExp("^([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])$");
424
424
  var YAML_TIMESTAMP_REGEXP = /* @__PURE__ */ new RegExp("^([0-9][0-9][0-9][0-9])-([0-9][0-9]?)-([0-9][0-9]?)(?:[Tt]|[ \\t]+)([0-9][0-9]?):([0-9][0-9]):([0-9][0-9])(?:\\.([0-9]*))?(?:[ \\t]*(Z|([-+])([0-9][0-9]?)(?::([0-9][0-9]))?))?$");
425
+ function makeUtcDate(year, month, day, hour = 0, minute = 0, second = 0, fraction = 0) {
426
+ const date = new Date(Date.UTC(year, month, day, hour, minute, second, fraction));
427
+ date.setUTCFullYear(year, month, day);
428
+ return date;
429
+ }
425
430
  function resolveYamlTimestamp(source) {
426
431
  let match = YAML_DATE_REGEXP.exec(source);
427
432
  if (match === null) match = YAML_TIMESTAMP_REGEXP.exec(source);
@@ -430,7 +435,7 @@ function resolveYamlTimestamp(source) {
430
435
  const month = +match[2] - 1;
431
436
  const day = +match[3];
432
437
  if (!match[4]) {
433
- const date2 = new Date(Date.UTC(year, month, day));
438
+ const date2 = makeUtcDate(year, month, day);
434
439
  if (date2.getUTCFullYear() !== year || date2.getUTCMonth() !== month || date2.getUTCDate() !== day) return NOT_RESOLVED;
435
440
  return date2;
436
441
  }
@@ -444,7 +449,7 @@ function resolveYamlTimestamp(source) {
444
449
  while (value.length < 3) value += "0";
445
450
  fraction = +value;
446
451
  }
447
- const date = new Date(Date.UTC(year, month, day, hour, minute, second, fraction));
452
+ const date = makeUtcDate(year, month, day, hour, minute, second, fraction);
448
453
  if (date.getUTCFullYear() !== year || date.getUTCMonth() !== month || date.getUTCDate() !== day) return NOT_RESOLVED;
449
454
  if (match[9]) {
450
455
  const offsetHour = +match[10];
@@ -542,7 +547,11 @@ var mapTag = defineMappingTag("tag:yaml.org,2002:map", {
542
547
  return Object.prototype.hasOwnProperty.call(container, String(key));
543
548
  },
544
549
  keys: (container) => Object.keys(container),
545
- get: (container, key) => container[String(key)]
550
+ get: (container, key) => {
551
+ const normalizedKey = String(key);
552
+ if (!Object.prototype.hasOwnProperty.call(container, normalizedKey)) return null;
553
+ return container[normalizedKey];
554
+ }
546
555
  });
547
556
  var setTag = defineMappingTag("tag:yaml.org,2002:set", {
548
557
  create: () => /* @__PURE__ */ new Set(),
@@ -563,9 +572,9 @@ var setTag = defineMappingTag("tag:yaml.org,2002:set", {
563
572
  });
564
573
  function createTagDefinitionMap() {
565
574
  return {
566
- scalar: {},
567
- sequence: {},
568
- mapping: {}
575
+ scalar: /* @__PURE__ */ Object.create(null),
576
+ sequence: /* @__PURE__ */ Object.create(null),
577
+ mapping: /* @__PURE__ */ Object.create(null)
569
578
  };
570
579
  }
571
580
  function createTagDefinitionListMap() {
@@ -735,7 +744,11 @@ var legacyMapTag = defineMappingTag("tag:yaml.org,2002:map", {
735
744
  return normalizedKey !== null && Object.prototype.hasOwnProperty.call(container, normalizedKey);
736
745
  },
737
746
  keys: (container) => Object.keys(container),
738
- get: (container, key) => container[String(key)]
747
+ get: (container, key) => {
748
+ const normalizedKey = String(key);
749
+ if (!Object.prototype.hasOwnProperty.call(container, normalizedKey)) return null;
750
+ return container[normalizedKey];
751
+ }
739
752
  });
740
753
  var DEFAULT_SNIPPET_OPTIONS = {
741
754
  maxLength: 79,
@@ -1071,10 +1084,10 @@ function getScalarValue(input, scalar) {
1071
1084
  return getPlainValue(input, valueStart, valueEnd);
1072
1085
  }
1073
1086
  }
1074
- var DEFAULT_TAG_HANDLERS = {
1087
+ var DEFAULT_TAG_HANDLERS = Object.assign(/* @__PURE__ */ Object.create(null), {
1075
1088
  "!": "!",
1076
1089
  "!!": "tag:yaml.org,2002:"
1077
- };
1090
+ });
1078
1091
  function tagPercentEncode(source) {
1079
1092
  return encodeURI(source).replace(/!/g, "%21");
1080
1093
  }
@@ -1327,6 +1340,10 @@ function constructFromEvents(events, options) {
1327
1340
  }
1328
1341
  case 6: {
1329
1342
  const frame = state.frames.pop();
1343
+ if (frame.kind === "mapping" && frame.hasKey) {
1344
+ state.position = frame.keyPosition;
1345
+ throwError$1(state, "incomplete mapping pair in event stream");
1346
+ }
1330
1347
  if (frame.kind === "document") state.documents.push(frame.value);
1331
1348
  else {
1332
1349
  const value = frame.tag.carrierIsResult ? frame.value : finalizeCollection(state, frame.position, frame.tag, frame.value);
@@ -1997,10 +2014,6 @@ function parseNode(state, parentIndent, nodeContext, allowToSeek, allowCompact,
1997
2014
  else if (state.lineIndent === parentIndent) indentStatus = 0;
1998
2015
  else indentStatus = -1;
1999
2016
  }
2000
- if (state.position === state.lineStart && testDocumentSeparator(state)) {
2001
- state.depth--;
2002
- return false;
2003
- }
2004
2017
  if (indentStatus === 1) while (true) {
2005
2018
  const ch = state.input.charCodeAt(state.position);
2006
2019
  const propertyState = snapshotState(state);
@@ -2549,14 +2562,14 @@ function chooseScalarStyle(state, string, layout, singleLineOnly, forceQuote, in
2549
2562
  if (char === CHAR_LINE_FEED) {
2550
2563
  hasLineBreak = true;
2551
2564
  if (shouldTrackWidth) {
2552
- hasFoldableLine = hasFoldableLine || i - previousLineBreak - 1 > lineWidth && string[previousLineBreak + 1] !== " ";
2565
+ hasFoldableLine = hasFoldableLine || i - previousLineBreak - 1 > lineWidth && !isMoreIndented(string[previousLineBreak + 1]);
2553
2566
  previousLineBreak = i;
2554
2567
  }
2555
2568
  } else if (!isPrintable(char)) return STYLE_DOUBLE;
2556
2569
  plain = plain && isPlainSafe(char, prevChar, inblock);
2557
2570
  prevChar = char;
2558
2571
  }
2559
- hasFoldableLine = hasFoldableLine || shouldTrackWidth && i - previousLineBreak - 1 > lineWidth && string[previousLineBreak + 1] !== " ";
2572
+ hasFoldableLine = hasFoldableLine || shouldTrackWidth && i - previousLineBreak - 1 > lineWidth && !isMoreIndented(string[previousLineBreak + 1]);
2560
2573
  }
2561
2574
  if (!hasLineBreak && !hasFoldableLine) {
2562
2575
  if (plain && !forceQuote) return STYLE_PLAIN;
@@ -2621,27 +2634,30 @@ function encodeFlowBreaks(string, indent) {
2621
2634
  function dropEndingNewline(string) {
2622
2635
  return string[string.length - 1] === "\n" ? string.slice(0, -1) : string;
2623
2636
  }
2637
+ function isMoreIndented(char) {
2638
+ return char === " " || char === " ";
2639
+ }
2624
2640
  function foldBlockScalar(string, width) {
2625
2641
  const lineRe = /(\n+)([^\n]*)/g;
2626
2642
  let nextLF = string.indexOf("\n");
2627
2643
  if (nextLF === -1) nextLF = string.length;
2628
2644
  lineRe.lastIndex = nextLF;
2629
2645
  let result = foldLine(string.slice(0, nextLF), width);
2630
- let prevMoreIndented = string[0] === "\n" || string[0] === " ";
2646
+ let prevMoreIndented = string[0] === "\n" || isMoreIndented(string[0]);
2631
2647
  let moreIndented;
2632
2648
  let match;
2633
2649
  while (match = lineRe.exec(string)) {
2634
2650
  const prefix = match[1];
2635
2651
  const line = match[2];
2636
- moreIndented = line[0] === " ";
2652
+ moreIndented = line !== "" && isMoreIndented(line[0]);
2637
2653
  result += prefix + (!prevMoreIndented && !moreIndented && line !== "" ? "\n" : "") + foldLine(line, width);
2638
2654
  prevMoreIndented = moreIndented;
2639
2655
  }
2640
2656
  return result;
2641
2657
  }
2642
2658
  function foldLine(line, width) {
2643
- if (line === "" || line[0] === " ") return line;
2644
- const breakRe = / [^ ]/g;
2659
+ if (line === "" || isMoreIndented(line[0])) return line;
2660
+ const breakRe = / [^ \t]/g;
2645
2661
  let match;
2646
2662
  let start = 0;
2647
2663
  let end;
@@ -2987,5 +3003,5 @@ export {
2987
3003
  /*! Bundled license information:
2988
3004
 
2989
3005
  js-yaml/dist/js-yaml.mjs:
2990
- (*! js-yaml 5.2.2 https://github.com/nodeca/js-yaml @license MIT *)
3006
+ (*! js-yaml 5.2.3 https://github.com/nodeca/js-yaml @license MIT *)
2991
3007
  */
@@ -0,0 +1,142 @@
1
+ import { createRequire as __acCreateRequire } from 'node:module'; const require = globalThis.require ?? __acCreateRequire(import.meta.url);
2
+
3
+ // src/scripts/_lib/recycle_envelope_paths.ts
4
+ import * as path from "node:path";
5
+ var RECYCLE_ENVELOPE_REL = path.join("agents", "runtime", "state", "recycle-envelope.json");
6
+ var RECYCLE_CONSUMED_REL = path.join(
7
+ "agents",
8
+ "runtime",
9
+ "state",
10
+ "recycle-envelope.consumed.json"
11
+ );
12
+ var RECYCLE_MAX_AGE_HOURS = 48;
13
+ var RECYCLE_ENVELOPE_MAX_BYTES = 6144;
14
+
15
+ // src/scripts/_lib/subagent_capsule.ts
16
+ var EPISTEMIC_STATES = ["verified", "assumed", "gap"];
17
+ var EPISTEMIC = new Set(EPISTEMIC_STATES);
18
+ var MAX_REF_CHARS = 200;
19
+ var MAX_LINE_CHARS = 240;
20
+ var MAX_ENTRIES = 40;
21
+ var CAPSULE_SCHEMA_VERSION = 2;
22
+ function isShortLine(value, max) {
23
+ return typeof value === "string" && value.length > 0 && value.length <= max && !value.includes("\n");
24
+ }
25
+ function checkList(errors, field, value, max, required) {
26
+ if (value === void 0) {
27
+ if (required) errors.push(`${field} is required`);
28
+ return;
29
+ }
30
+ if (!Array.isArray(value)) {
31
+ errors.push(`${field} must be an array`);
32
+ return;
33
+ }
34
+ if (value.length > MAX_ENTRIES) {
35
+ errors.push(`${field} carries ${value.length} entries (max ${MAX_ENTRIES}) \u2014 a capsule is a handoff, not a transcript`);
36
+ }
37
+ const bad = value.filter((x) => !isShortLine(x, max));
38
+ if (bad.length > 0) {
39
+ errors.push(
40
+ `${field} carries ${bad.length} entr${bad.length === 1 ? "y" : "ies"} that are not single lines of \u2264 ${max} chars (refs and short lines only, never bodies)`
41
+ );
42
+ }
43
+ }
44
+ var RECYCLE_ENVELOPE_KEYS = /* @__PURE__ */ new Set([
45
+ "capsule_version",
46
+ "variant",
47
+ "summary",
48
+ "task",
49
+ "workspace",
50
+ "written_at",
51
+ "acceptance_criteria",
52
+ "remaining",
53
+ "not_carried_forward",
54
+ "decisions",
55
+ "constraints",
56
+ "open_worker_envelopes",
57
+ "artifact_paths",
58
+ "assumptions"
59
+ ]);
60
+ function validateRecycleEnvelope(input) {
61
+ const errors = [];
62
+ if (typeof input !== "object" || input === null || Array.isArray(input)) {
63
+ return ["not an object"];
64
+ }
65
+ const e = input;
66
+ for (const key of Object.keys(e)) {
67
+ if (!RECYCLE_ENVELOPE_KEYS.has(key)) {
68
+ errors.push(
69
+ `unknown field "${key}" \u2014 a recycle envelope carries selection and pointers only; free-form additions (prose summaries included) are schema-invalid by construction`
70
+ );
71
+ }
72
+ }
73
+ if (e["capsule_version"] !== CAPSULE_SCHEMA_VERSION) {
74
+ errors.push(`capsule_version must be ${CAPSULE_SCHEMA_VERSION}`);
75
+ }
76
+ if (e["variant"] !== "main_session") {
77
+ errors.push("variant must be 'main_session'");
78
+ }
79
+ if (!isShortLine(e["summary"], MAX_LINE_CHARS)) {
80
+ errors.push(`summary must be a single line of 1\u2013${MAX_LINE_CHARS} chars`);
81
+ }
82
+ if (!isShortLine(e["task"], MAX_LINE_CHARS)) {
83
+ errors.push(`task must be a single line of 1\u2013${MAX_LINE_CHARS} chars`);
84
+ }
85
+ if (!isShortLine(e["workspace"], MAX_REF_CHARS)) {
86
+ errors.push(`workspace must be a path ref of \u2264 ${MAX_REF_CHARS} chars`);
87
+ }
88
+ const writtenAt = e["written_at"];
89
+ if (typeof writtenAt !== "string" || Number.isNaN(Date.parse(writtenAt))) {
90
+ errors.push("written_at must be a parseable ISO-8601 timestamp");
91
+ }
92
+ checkList(errors, "acceptance_criteria", e["acceptance_criteria"], MAX_LINE_CHARS, true);
93
+ if (Array.isArray(e["acceptance_criteria"]) && e["acceptance_criteria"].length === 0) {
94
+ errors.push('acceptance_criteria must carry at least one entry \u2014 the successor cannot know "done" without it');
95
+ }
96
+ checkList(errors, "remaining", e["remaining"], MAX_LINE_CHARS, true);
97
+ checkList(errors, "not_carried_forward", e["not_carried_forward"], MAX_LINE_CHARS, true);
98
+ checkList(errors, "decisions", e["decisions"], MAX_LINE_CHARS, false);
99
+ checkList(errors, "constraints", e["constraints"], MAX_LINE_CHARS, false);
100
+ checkList(errors, "open_worker_envelopes", e["open_worker_envelopes"], MAX_REF_CHARS, false);
101
+ checkList(errors, "artifact_paths", e["artifact_paths"], MAX_REF_CHARS, false);
102
+ const assumptions = e["assumptions"];
103
+ if (assumptions !== void 0) {
104
+ if (!Array.isArray(assumptions)) {
105
+ errors.push("assumptions must be an array");
106
+ } else {
107
+ if (assumptions.length > MAX_ENTRIES) {
108
+ errors.push(`assumptions carries ${assumptions.length} entries (max ${MAX_ENTRIES})`);
109
+ }
110
+ for (const [i, raw] of assumptions.entries()) {
111
+ errors.push(...validateAssumption(raw, `assumptions[${i}]`));
112
+ }
113
+ }
114
+ }
115
+ return errors;
116
+ }
117
+ function validateAssumption(input, label = "assumption") {
118
+ const errors = [];
119
+ if (typeof input !== "object" || input === null || Array.isArray(input)) {
120
+ return [`${label} is not an object`];
121
+ }
122
+ const a = input;
123
+ if (!isShortLine(a["statement"], MAX_LINE_CHARS)) {
124
+ errors.push(`${label}.statement must be a single line of 1\u2013${MAX_LINE_CHARS} chars`);
125
+ }
126
+ if (!isShortLine(a["basis"], MAX_REF_CHARS)) {
127
+ errors.push(`${label}.basis must be a ref token (file:line, id, path, command) of \u2264 ${MAX_REF_CHARS} chars`);
128
+ }
129
+ if (typeof a["epistemic_state"] !== "string" || !EPISTEMIC.has(a["epistemic_state"])) {
130
+ errors.push(`${label}.epistemic_state must be one of ${EPISTEMIC_STATES.join(" | ")}`);
131
+ }
132
+ return errors;
133
+ }
134
+
135
+ export {
136
+ RECYCLE_ENVELOPE_REL,
137
+ RECYCLE_CONSUMED_REL,
138
+ RECYCLE_MAX_AGE_HOURS,
139
+ RECYCLE_ENVELOPE_MAX_BYTES,
140
+ CAPSULE_SCHEMA_VERSION,
141
+ validateRecycleEnvelope
142
+ };
@@ -7,7 +7,7 @@ import {
7
7
  import {
8
8
  ProjectRootError,
9
9
  resolve_project_root
10
- } from "./chunk-GB2FSUEE.js";
10
+ } from "./chunk-LCFJIQ4J.js";
11
11
  import "./chunk-NDJLNC6Q.js";
12
12
  import "./chunk-J55WI3RR.js";
13
13
 
@@ -1,7 +1,7 @@
1
1
  import { createRequire as __acCreateRequire } from 'node:module'; const require = globalThis.require ?? __acCreateRequire(import.meta.url);
2
2
  import {
3
3
  resolve_project_root
4
- } from "./chunk-GB2FSUEE.js";
4
+ } from "./chunk-LCFJIQ4J.js";
5
5
  import "./chunk-NDJLNC6Q.js";
6
6
  import "./chunk-J55WI3RR.js";
7
7