@event4u/agent-config 9.9.0 → 9.11.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 (479) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/CHANGELOG.md +212 -194
  3. package/README.md +13 -16
  4. package/agents/templates/.ai-council.yml.example +481 -0
  5. package/agents/templates/.ai-video.xml.example +247 -0
  6. package/dist/agent-src/commands/agent-status.md +12 -11
  7. package/dist/agent-src/commands/agents/user/accept.md +115 -30
  8. package/dist/agent-src/commands/agents/user/delete.md +147 -0
  9. package/dist/agent-src/commands/agents/user/review.md +65 -28
  10. package/dist/agent-src/commands/agents/user/show.md +82 -29
  11. package/dist/agent-src/commands/agents/user/update.md +2 -2
  12. package/dist/agent-src/commands/agents/user.md +16 -3
  13. package/dist/agent-src/commands/check-current-md.md +0 -10
  14. package/dist/agent-src/commands/condense.md +28 -97
  15. package/dist/agent-src/commands/cost/report.md +7 -0
  16. package/dist/agent-src/commands/fix/portability.md +0 -8
  17. package/dist/agent-src/commands/fix/refs.md +0 -8
  18. package/dist/agent-src/commands/humanize.md +2 -2
  19. package/dist/agent-src/commands/jira-ticket.md +1 -1
  20. package/dist/agent-src/commands/memory/load.md +11 -0
  21. package/dist/agent-src/commands/optimize/skills.md +1 -1
  22. package/dist/agent-src/commands/pr/create.md +4 -4
  23. package/dist/agent-src/commands/profile/show.md +3 -3
  24. package/dist/agent-src/commands/rule-compliance-audit.md +5 -4
  25. package/dist/agent-src/commands/security-audit-config.md +1 -1
  26. package/dist/agent-src/commands/sync/gitignore/fix.md +1 -1
  27. package/dist/agent-src/commands/tdd.md +21 -0
  28. package/dist/agent-src/commands/team/delegate.md +2 -2
  29. package/dist/agent-src/commands/team-knowledge/bootstrap.md +9 -8
  30. package/dist/agent-src/commands/team-knowledge/consolidate.md +8 -7
  31. package/dist/agent-src/commands/team.md +4 -1
  32. package/dist/agent-src/commands/upstream-contribute.md +0 -1
  33. package/dist/agent-src/contexts/authority/commit-mechanics.md +7 -0
  34. package/dist/agent-src/contexts/authority/destructive-mechanics.md +16 -0
  35. package/dist/agent-src/contexts/authority/scope-mechanics.md +61 -0
  36. package/dist/agent-src/contexts/communication/rules-auto/reply-close-mechanics.md +20 -18
  37. package/dist/agent-src/contexts/communication/rules-auto/skill-quality-mechanics.md +1 -1
  38. package/dist/agent-src/contexts/communication/rules-auto/slash-command-routing-policy-mechanics.md +1 -1
  39. package/dist/agent-src/contexts/communication/rules-auto/source-of-truth-mechanics.md +9 -10
  40. package/dist/agent-src/contexts/communication/rules-auto/think-before-action-mechanics.md +1 -1
  41. package/dist/agent-src/contexts/communication/rules-auto/user-interaction-mechanics.md +11 -0
  42. package/dist/agent-src/contexts/contracts/artifact-engagement-flow.md +26 -15
  43. package/dist/agent-src/contexts/contracts/command-suggestion-flow.md +3 -0
  44. package/dist/agent-src/contexts/execution/auto-dispatch-classification.md +67 -37
  45. package/dist/agent-src/contexts/execution/auto-orchestration-activation.md +1 -1
  46. package/dist/agent-src/contexts/execution/autonomy-examples.md +1 -1
  47. package/dist/agent-src/contexts/execution/autonomy-mechanics.md +7 -6
  48. package/dist/agent-src/contexts/execution/evidence-discipline.md +92 -77
  49. package/dist/agent-src/contexts/execution/orchestration-benchmark-gate.md +22 -21
  50. package/dist/agent-src/contexts/execution/orchestration-telemetry.md +24 -0
  51. package/dist/agent-src/contexts/execution/project-intelligence.md +122 -103
  52. package/dist/agent-src/contexts/execution/roadmap-execution-contract.md +23 -21
  53. package/dist/agent-src/contexts/execution/subagent-response-contract.md +5 -5
  54. package/dist/agent-src/contexts/execution/subagent-routing.md +11 -0
  55. package/dist/agent-src/contexts/execution/subagent-spawn-contract.md +13 -13
  56. package/dist/agent-src/contexts/execution/subagent-steering.md +36 -34
  57. package/dist/agent-src/contexts/execution/toolchain-resolver.md +1 -1
  58. package/dist/agent-src/contexts/execution/user-memory-channels.md +189 -0
  59. package/dist/agent-src/contexts/execution/verification-mechanics.md +9 -0
  60. package/dist/agent-src/contexts/model-recommendations.md +3 -2
  61. package/dist/agent-src/contexts/subagent-configuration.md +3 -3
  62. package/dist/agent-src/ghostwriter/README.md +2 -2
  63. package/dist/agent-src/packs/README.md +1 -1
  64. package/dist/agent-src/personas/README.md +5 -5
  65. package/dist/agent-src/personas/_template-specialist/persona.md +3 -3
  66. package/dist/agent-src/personas/backend-architect.md +24 -23
  67. package/dist/agent-src/personas/eloquent-tamer.md +30 -30
  68. package/dist/agent-src/personas/frontend-engineer.md +30 -30
  69. package/dist/agent-src/personas/product-owner.md +41 -38
  70. package/dist/agent-src/personas/qa.md +13 -13
  71. package/dist/agent-src/personas/security-engineer.md +22 -22
  72. package/dist/agent-src/presets/README.md +3 -3
  73. package/dist/agent-src/profiles/README.md +3 -3
  74. package/dist/agent-src/rules/active-remediation.md +2 -2
  75. package/dist/agent-src/rules/artifact-engagement-recording.md +4 -4
  76. package/dist/agent-src/rules/ask-when-uncertain.md +0 -4
  77. package/dist/agent-src/rules/augment-edit-discipline.md +1 -1
  78. package/dist/agent-src/rules/broken-access-control.md +4 -4
  79. package/dist/agent-src/rules/code-comment-discipline.md +1 -1
  80. package/dist/agent-src/rules/code-provenance.md +2 -2
  81. package/dist/agent-src/rules/commit-policy.md +4 -9
  82. package/dist/agent-src/rules/communication-through-line.md +5 -5
  83. package/dist/agent-src/rules/decision-revisit-gate.md +1 -1
  84. package/dist/agent-src/rules/design-fidelity.md +1 -1
  85. package/dist/agent-src/rules/doc-screenshot-hygiene.md +1 -1
  86. package/dist/agent-src/rules/domain-adoption-policy.md +1 -1
  87. package/dist/agent-src/rules/domain-safety-pii.md +1 -1
  88. package/dist/agent-src/rules/external-code-graph-interop.md +1 -1
  89. package/dist/agent-src/rules/fast-path-marker-visibility.md +43 -7
  90. package/dist/agent-src/rules/finance-safety-floor.md +1 -1
  91. package/dist/agent-src/rules/framework-neutrality-in-generic-skills.md +3 -3
  92. package/dist/agent-src/rules/history-discipline.md +1 -1
  93. package/dist/agent-src/rules/legal-safety-floor.md +1 -1
  94. package/dist/agent-src/rules/lethal-trifecta-guard.md +5 -5
  95. package/dist/agent-src/rules/low-impact-corpus-privacy-floor.md +10 -8
  96. package/dist/agent-src/rules/media-governance-routing.md +13 -13
  97. package/dist/agent-src/rules/media-sync-ground-truth.md +29 -11
  98. package/dist/agent-src/rules/no-cheap-questions.md +7 -7
  99. package/dist/agent-src/rules/no-decorative-emojis-in-git-surfaces.md +29 -18
  100. package/dist/agent-src/rules/non-destructive-by-default.md +5 -23
  101. package/dist/agent-src/rules/onboarding-gate.md +14 -4
  102. package/dist/agent-src/rules/persona-governance.md +2 -2
  103. package/dist/agent-src/rules/prefer-enums-over-literals.md +9 -9
  104. package/dist/agent-src/rules/preservation-guard.md +10 -2
  105. package/dist/agent-src/rules/question-not-instruction.md +1 -1
  106. package/dist/agent-src/rules/roadmap-progress-sync.md +6 -6
  107. package/dist/agent-src/rules/rule-type-governance.md +1 -1
  108. package/dist/agent-src/rules/scale-discipline.md +1 -1
  109. package/dist/agent-src/rules/scope-control.md +1 -1
  110. package/dist/agent-src/rules/secret-vcs-guard.md +1 -1
  111. package/dist/agent-src/rules/security-sensitive-stop.md +17 -11
  112. package/dist/agent-src/rules/senior-engineering-discipline.md +17 -17
  113. package/dist/agent-src/rules/session-canary.md +1 -1
  114. package/dist/agent-src/rules/skill-quality.md +1 -1
  115. package/dist/agent-src/rules/source-confidentiality.md +21 -19
  116. package/dist/agent-src/rules/source-of-truth.md +6 -5
  117. package/dist/agent-src/rules/spreadsheet-source-quality.md +2 -2
  118. package/dist/agent-src/rules/strategy-safety-floor.md +1 -1
  119. package/dist/agent-src/rules/think-before-action.md +5 -5
  120. package/dist/agent-src/rules/token-budget-discipline.md +5 -3
  121. package/dist/agent-src/rules/token-efficiency.md +2 -2
  122. package/dist/agent-src/rules/untrusted-input-defense.md +4 -4
  123. package/dist/agent-src/rules/user-interaction.md +12 -0
  124. package/dist/agent-src/rules/verify-before-complete.md +4 -24
  125. package/dist/agent-src/skills/adversarial-review/SKILL.md +2 -2
  126. package/dist/agent-src/skills/agent-security-review/SKILL.md +52 -45
  127. package/dist/agent-src/skills/agents-md-thin-root/SKILL.md +2 -2
  128. package/dist/agent-src/skills/ai-code-blindspots/SKILL.md +20 -20
  129. package/dist/agent-src/skills/ai-council/SKILL.md +185 -128
  130. package/dist/agent-src/skills/analysis-skill-router/SKILL.md +3 -3
  131. package/dist/agent-src/skills/api-endpoint/SKILL.md +2 -2
  132. package/dist/agent-src/skills/artisan-commands/SKILL.md +2 -2
  133. package/dist/agent-src/skills/async-python-patterns/SKILL.md +8 -7
  134. package/dist/agent-src/skills/authz-review/SKILL.md +16 -15
  135. package/dist/agent-src/skills/aws-infrastructure/SKILL.md +5 -5
  136. package/dist/agent-src/skills/blade-ui/SKILL.md +1 -1
  137. package/dist/agent-src/skills/bug-analyzer/SKILL.md +30 -12
  138. package/dist/agent-src/skills/code-intelligence/SKILL.md +0 -1
  139. package/dist/agent-src/skills/code-intelligence/evals/triggers.json +52 -0
  140. package/dist/agent-src/skills/code-review/SKILL.md +6 -6
  141. package/dist/agent-src/skills/command-routing/SKILL.md +5 -4
  142. package/dist/agent-src/skills/composer-packages/SKILL.md +2 -2
  143. package/dist/agent-src/skills/condense-memory/SKILL.md +43 -41
  144. package/dist/agent-src/skills/context-document/SKILL.md +23 -21
  145. package/dist/agent-src/skills/copilot-config/SKILL.md +6 -1
  146. package/dist/agent-src/skills/decision-record/SKILL.md +20 -18
  147. package/dist/agent-src/skills/design-intelligence/SKILL.md +4 -4
  148. package/dist/agent-src/skills/design-review/SKILL.md +15 -14
  149. package/dist/agent-src/skills/design-system-capture/reference/design-system-json.md +28 -25
  150. package/dist/agent-src/skills/devcontainer/SKILL.md +2 -2
  151. package/dist/agent-src/skills/docker/SKILL.md +1 -1
  152. package/dist/agent-src/skills/docx-authoring/evals/triggers.json +52 -0
  153. package/dist/agent-src/skills/emit-tickets/SKILL.md +2 -2
  154. package/dist/agent-src/skills/error-handling-patterns/SKILL.md +1 -1
  155. package/dist/agent-src/skills/estimate-ticket/SKILL.md +2 -2
  156. package/dist/agent-src/skills/evaluate-llm-feature/SKILL.md +0 -1
  157. package/dist/agent-src/skills/evaluate-llm-feature/evals/triggers.json +52 -0
  158. package/dist/agent-src/skills/existing-ui-audit/SKILL.md +21 -7
  159. package/dist/agent-src/skills/fe-design/SKILL.md +10 -0
  160. package/dist/agent-src/skills/feature-planning/SKILL.md +2 -2
  161. package/dist/agent-src/skills/finishing-a-development-branch/SKILL.md +3 -3
  162. package/dist/agent-src/skills/flux/SKILL.md +1 -1
  163. package/dist/agent-src/skills/frontend-render-security/SKILL.md +13 -13
  164. package/dist/agent-src/skills/git-workflow/SKILL.md +33 -33
  165. package/dist/agent-src/skills/grafana/SKILL.md +5 -0
  166. package/dist/agent-src/skills/humanizer/SKILL.md +83 -66
  167. package/dist/agent-src/skills/humanizer/data/patterns.md +14 -14
  168. package/dist/agent-src/skills/humanizer/references/anti-aiisms.md +4 -4
  169. package/dist/agent-src/skills/judge-artifact-completeness/SKILL.md +82 -37
  170. package/dist/agent-src/skills/judge-bug-hunter/SKILL.md +17 -5
  171. package/dist/agent-src/skills/judge-injection-defense/SKILL.md +63 -25
  172. package/dist/agent-src/skills/judge-security-auditor/SKILL.md +2 -0
  173. package/dist/agent-src/skills/judge-synthesis/SKILL.md +72 -28
  174. package/dist/agent-src/skills/laravel-horizon/SKILL.md +5 -0
  175. package/dist/agent-src/skills/laravel-mail/SKILL.md +5 -4
  176. package/dist/agent-src/skills/laravel-middleware/SKILL.md +5 -4
  177. package/dist/agent-src/skills/laravel-notifications/SKILL.md +10 -9
  178. package/dist/agent-src/skills/laravel-pennant/SKILL.md +1 -1
  179. package/dist/agent-src/skills/laravel-pulse/SKILL.md +9 -8
  180. package/dist/agent-src/skills/laravel-reverb/SKILL.md +6 -5
  181. package/dist/agent-src/skills/laravel-scheduling/SKILL.md +6 -1
  182. package/dist/agent-src/skills/laravel-validation/SKILL.md +12 -0
  183. package/dist/agent-src/skills/launch-readiness/SKILL.md +1 -1
  184. package/dist/agent-src/skills/learning-to-rule-or-skill/SKILL.md +7 -7
  185. package/dist/agent-src/skills/learning-tutor/SKILL.md +44 -43
  186. package/dist/agent-src/skills/learning-tutor/evals/triggers.json +52 -0
  187. package/dist/agent-src/skills/license-compliance-audit/SKILL.md +7 -7
  188. package/dist/agent-src/skills/license-compliance-borrow-check/SKILL.md +3 -3
  189. package/dist/agent-src/skills/license-compliance-credits/SKILL.md +4 -4
  190. package/dist/agent-src/skills/llm-provider-knowledge/SKILL.md +0 -1
  191. package/dist/agent-src/skills/memory-consolidation/SKILL.md +69 -64
  192. package/dist/agent-src/skills/motion-choreographer/SKILL.md +6 -6
  193. package/dist/agent-src/skills/pdf-tools/evals/triggers.json +52 -0
  194. package/dist/agent-src/skills/performance-analysis/SKILL.md +7 -3
  195. package/dist/agent-src/skills/persona-improvement/SKILL.md +0 -2
  196. package/dist/agent-src/skills/persona-improvement/evals/triggers.json +52 -0
  197. package/dist/agent-src/skills/php-coder/SKILL.md +10 -0
  198. package/dist/agent-src/skills/prediction-pool-optimizer/SKILL.md +129 -120
  199. package/dist/agent-src/skills/prediction-pool-optimizer/reference/ev-fixtures.md +36 -35
  200. package/dist/agent-src/skills/prediction-pool-optimizer/reference/odds-and-bonus.md +45 -41
  201. package/dist/agent-src/skills/project-analysis-core/SKILL.md +4 -4
  202. package/dist/agent-src/skills/project-analysis-hypothesis-driven/SKILL.md +3 -3
  203. package/dist/agent-src/skills/project-analysis-react/SKILL.md +1 -1
  204. package/dist/agent-src/skills/project-analysis-symfony/SKILL.md +1 -1
  205. package/dist/agent-src/skills/project-analysis-zend-laminas/SKILL.md +2 -2
  206. package/dist/agent-src/skills/prompt-engineering-patterns/SKILL.md +1 -1
  207. package/dist/agent-src/skills/prompt-validator/SKILL.md +39 -39
  208. package/dist/agent-src/skills/quality-tools/SKILL.md +15 -15
  209. package/dist/agent-src/skills/react-shadcn-ui/SKILL.md +55 -19
  210. package/dist/agent-src/skills/react-shadcn-ui/reference/registry.md +29 -27
  211. package/dist/agent-src/skills/readme-writing-package/SKILL.md +2 -2
  212. package/dist/agent-src/skills/reasoning-orchestrator/SKILL.md +25 -25
  213. package/dist/agent-src/skills/recursive-verification/SKILL.md +6 -5
  214. package/dist/agent-src/skills/refine-prompt/SKILL.md +1 -1
  215. package/dist/agent-src/skills/refine-ticket/SKILL.md +20 -2
  216. package/dist/agent-src/skills/repomix-packer/SKILL.md +1 -1
  217. package/dist/agent-src/skills/requesting-code-review/SKILL.md +2 -2
  218. package/dist/agent-src/skills/roadmap-management/SKILL.md +80 -66
  219. package/dist/agent-src/skills/roadmap-writing/SKILL.md +84 -77
  220. package/dist/agent-src/skills/rule-refactor/SKILL.md +1 -1
  221. package/dist/agent-src/skills/screenshot-hygiene/evals/triggers.json +52 -0
  222. package/dist/agent-src/skills/security-audit/SKILL.md +26 -9
  223. package/dist/agent-src/skills/security-maturity-assessment/SKILL.md +38 -16
  224. package/dist/agent-src/skills/skill-improvement-pipeline/SKILL.md +14 -11
  225. package/dist/agent-src/skills/skill-writing/SKILL.md +9 -8
  226. package/dist/agent-src/skills/song-to-script/SKILL.md +93 -85
  227. package/dist/agent-src/skills/sql-writing/SKILL.md +2 -2
  228. package/dist/agent-src/skills/stakeholder-tradeoff/SKILL.md +4 -3
  229. package/dist/agent-src/skills/standards-from-config/SKILL.md +61 -43
  230. package/dist/agent-src/skills/subagent-orchestration/SKILL.md +22 -8
  231. package/dist/agent-src/skills/subagent-orchestration/prompts/README.md +28 -2
  232. package/dist/agent-src/skills/supply-chain-intake/SKILL.md +13 -13
  233. package/dist/agent-src/skills/systematic-debugging/SKILL.md +22 -21
  234. package/dist/agent-src/skills/tailwind-engineer/SKILL.md +1 -1
  235. package/dist/agent-src/skills/technical-specification/SKILL.md +5 -0
  236. package/dist/agent-src/skills/terraform/SKILL.md +2 -2
  237. package/dist/agent-src/skills/terragrunt/SKILL.md +8 -8
  238. package/dist/agent-src/skills/testing-anti-patterns/process-anti-patterns.md +1 -1
  239. package/dist/agent-src/skills/threat-modeling/SKILL.md +19 -13
  240. package/dist/agent-src/skills/universal-project-analysis/SKILL.md +1 -1
  241. package/dist/agent-src/skills/upstream-contribute/SKILL.md +0 -1
  242. package/dist/agent-src/skills/using-git-worktrees/SKILL.md +9 -9
  243. package/dist/agent-src/skills/validate-feature-fit/SKILL.md +3 -1
  244. package/dist/agent-src/skills/verify-completion-evidence/SKILL.md +4 -6
  245. package/dist/agent-src/skills/verify-repair-loop/SKILL.md +67 -61
  246. package/dist/agent-src/skills/video-director/SKILL.md +7 -7
  247. package/dist/agent-src/skills/worktree-lifecycle/SKILL.md +3 -3
  248. package/dist/agent-src/templates/agents/agent-project-settings.example.yml +1 -1
  249. package/dist/agent-src/templates/contexts/knowledge-pages.md +47 -45
  250. package/dist/agent-src/templates/contexts/lesson-card.md +2 -2
  251. package/dist/agent-src/templates/contexts/tenant-boundaries.md +2 -2
  252. package/dist/agent-src/templates/contexts.md +1 -1
  253. package/dist/agent-src/templates/features.md +1 -1
  254. package/dist/agent-src/templates/roadmaps.md +125 -116
  255. package/dist/agent-src/templates/rule.md +2 -1
  256. package/dist/agent-src/templates/scripts/pr_risk_review.ts +0 -0
  257. package/dist/agent-src/templates/scripts/telemetry/aggregator.ts +0 -0
  258. package/dist/agent-src/templates/scripts/tier_usage_report.ts +2 -2
  259. package/dist/agent-src/templates/scripts/work_engine/directives/ui/apply.ts +30 -30
  260. package/dist/agent-src/templates/scripts/work_engine/directives/ui/design.ts +88 -33
  261. package/dist/agent-src/templates/scripts/work_engine/directives/ui/polish.ts +22 -2
  262. package/dist/agent-src/templates/scripts/work_engine/directives/ui/review.ts +21 -2
  263. package/dist/agent-src/templates/scripts/work_engine/directives/ui/stack_bundles.ts +179 -0
  264. package/dist/agent-src/templates/scripts/work_engine/stack/detect.ts +155 -4
  265. package/dist/agent-src/templates/scripts/work_engine/state.ts +21 -4
  266. package/dist/agent-src/user-types/README.md +8 -8
  267. package/dist/agent-src/user-types/galabau-field-crew.md +34 -33
  268. package/dist/agent-src/user-types/metalworking-shop.md +35 -34
  269. package/dist/agent-src/user-types/truck-driver.md +22 -20
  270. package/dist/cli/initRouting.js +74 -11
  271. package/dist/cli/initRouting.js.map +1 -1
  272. package/dist/cli/main.js +14 -3
  273. package/dist/cli/main.js.map +1 -1
  274. package/dist/cli/python/workspace_roles.js +2 -2
  275. package/dist/cli/python/workspace_roles.js.map +1 -1
  276. package/dist/cli-delegate/chunk-4SV3XGFA.js +6910 -0
  277. package/dist/cli-delegate/chunk-736JCWLM.js +1104 -0
  278. package/dist/cli-delegate/chunk-7DSAMZFU.js +356 -0
  279. package/dist/cli-delegate/chunk-7HQ52DHU.js +74 -0
  280. package/dist/cli-delegate/chunk-BJGXZNPM.js +266 -0
  281. package/dist/cli-delegate/chunk-FTAISGDQ.js +117 -0
  282. package/dist/cli-delegate/chunk-GME3Q44L.js +82 -0
  283. package/dist/cli-delegate/chunk-GRRPEPRN.js +336 -0
  284. package/dist/cli-delegate/chunk-HJ6DAJHR.js +502 -0
  285. package/dist/cli-delegate/chunk-IR7P7JWA.js +872 -0
  286. package/dist/cli-delegate/chunk-J55WI3RR.js +47 -0
  287. package/dist/cli-delegate/chunk-MCJYCQPF.js +35 -0
  288. package/dist/cli-delegate/chunk-NDJLNC6Q.js +169 -0
  289. package/dist/cli-delegate/chunk-OMIVVCG2.js +26 -0
  290. package/dist/cli-delegate/chunk-OY53J6II.js +7336 -0
  291. package/dist/cli-delegate/chunk-RDGRHAAB.js +259 -0
  292. package/dist/cli-delegate/chunk-TFG57JJM.js +1969 -0
  293. package/dist/cli-delegate/chunk-XX6TOPD7.js +715 -0
  294. package/dist/cli-delegate/chunk-YMFO6FDN.js +10603 -0
  295. package/dist/cli-delegate/cmd_analyze_session.js +294 -0
  296. package/dist/cli-delegate/cmd_conformance.js +646 -0
  297. package/dist/cli-delegate/cmd_converge.js +326 -0
  298. package/dist/cli-delegate/cmd_doctor.js +144 -0
  299. package/dist/cli-delegate/cmd_explain.js +2508 -0
  300. package/dist/cli-delegate/cmd_export.js +296 -0
  301. package/dist/cli-delegate/cmd_fleet.js +332 -0
  302. package/dist/cli-delegate/cmd_memory_get.js +3878 -0
  303. package/dist/cli-delegate/cmd_migrate.js +11 -0
  304. package/dist/cli-delegate/cmd_preflight.js +270 -0
  305. package/dist/cli-delegate/cmd_prune.js +444 -0
  306. package/dist/cli-delegate/cmd_refresh.js +28 -0
  307. package/dist/cli-delegate/cmd_settings_check.js +574 -0
  308. package/dist/cli-delegate/cmd_settings_migrate.js +223 -0
  309. package/dist/cli-delegate/cmd_sync.js +264 -0
  310. package/dist/cli-delegate/cmd_uninstall.js +656 -0
  311. package/dist/cli-delegate/cmd_update.js +425 -0
  312. package/dist/cli-delegate/cmd_upgrade.js +444 -0
  313. package/dist/cli-delegate/cmd_validate.js +305 -0
  314. package/dist/cli-delegate/cmd_versions.js +370 -0
  315. package/dist/discovery/deprecation-report.md +1 -1
  316. package/dist/discovery/discovery-manifest.json +100 -67
  317. package/dist/discovery/discovery-manifest.json.sha256 +1 -1
  318. package/dist/discovery/discovery-manifest.summary.md +4 -4
  319. package/dist/discovery/orphan-report.md +1 -1
  320. package/dist/discovery/packs.json +16 -10
  321. package/dist/discovery/trust-report.md +2 -2
  322. package/dist/discovery/workspaces.json +7 -5
  323. package/dist/hooks/dispatch.js +186 -12
  324. package/dist/install/emit_host_rules_cli.js +2 -1
  325. package/dist/install/emit_host_rules_cli.js.map +1 -1
  326. package/dist/install/install.mjs +418 -378
  327. package/dist/install/rule_scope.js +5 -1
  328. package/dist/install/rule_scope.js.map +1 -1
  329. package/dist/install/toolDetection.js +40 -12
  330. package/dist/install/toolDetection.js.map +1 -1
  331. package/dist/install/wizard-plan.js +2 -2
  332. package/dist/install/wizard-plan.js.map +1 -1
  333. package/dist/mcp/registry-manifest.json +3 -3
  334. package/dist/mcp/server.json +2 -2
  335. package/dist/mcp/server.mjs +2194 -1003
  336. package/dist/router.json +1 -1
  337. package/dist/scripts/_lib/compile_time_toggles.js +48 -0
  338. package/dist/scripts/_lib/compile_time_toggles.js.map +1 -0
  339. package/dist/scripts/condense.js +234 -217
  340. package/dist/scripts/condense.js.map +1 -1
  341. package/dist/server/schemas/settings.js +4 -0
  342. package/dist/server/schemas/settings.js.map +1 -1
  343. package/dist/shared/userMd/utils.js +30 -0
  344. package/dist/shared/userMd/utils.js.map +1 -1
  345. package/dist/ui/assets/index-BpSQt5vm.js.map +1 -1
  346. package/docs/guidelines/agent-infra/api-cost-levers.md +56 -5
  347. package/docs/guidelines/agent-infra/simplicity-and-goal-demos.md +93 -33
  348. package/package.json +4 -2
  349. package/src/agent-src/templates/scripts/pr_risk_review.ts +0 -0
  350. package/src/agent-src/templates/scripts/telemetry/aggregator.ts +0 -0
  351. package/src/agent-src/templates/scripts/tier_usage_report.ts +2 -2
  352. package/src/agent-src/templates/scripts/work_engine/directives/ui/apply.ts +30 -30
  353. package/src/agent-src/templates/scripts/work_engine/directives/ui/design.ts +88 -33
  354. package/src/agent-src/templates/scripts/work_engine/directives/ui/polish.ts +22 -2
  355. package/src/agent-src/templates/scripts/work_engine/directives/ui/review.ts +21 -2
  356. package/src/agent-src/templates/scripts/work_engine/directives/ui/stack_bundles.ts +179 -0
  357. package/src/agent-src/templates/scripts/work_engine/stack/detect.ts +155 -4
  358. package/src/agent-src/templates/scripts/work_engine/state.ts +21 -4
  359. package/src/config/agent-settings.template.yml +32 -2
  360. package/src/config/ci-local-parity.yml +142 -0
  361. package/src/config/discovery/packs.yml +7 -0
  362. package/src/config/evaluator-budgets.json +1 -1
  363. package/src/config/gate-coverage.yml +127 -0
  364. package/src/config/pack-size-budget.json +27 -0
  365. package/src/config/preamble-payload-budget.json +44 -0
  366. package/src/install/emit_host_rules_cli.ts +2 -1
  367. package/src/install/rule_scope.ts +5 -1
  368. package/src/install/toolDetection.ts +39 -8
  369. package/src/install/wizard-plan.ts +2 -2
  370. package/src/scripts/_cli/cmd_conformance.ts +2 -1
  371. package/src/scripts/_cli/cmd_converge.ts +2 -1
  372. package/src/scripts/_cli/cmd_doctor.ts +292 -15
  373. package/src/scripts/_cli/cmd_export.ts +2 -1
  374. package/src/scripts/_cli/cmd_fleet.ts +2 -1
  375. package/src/scripts/_cli/cmd_migrate.ts +2 -1
  376. package/src/scripts/_cli/cmd_preflight.ts +2 -1
  377. package/src/scripts/_cli/cmd_refresh.ts +2 -1
  378. package/src/scripts/_cli/cmd_update.ts +2 -1
  379. package/src/scripts/_cli/cmd_upgrade.ts +2 -1
  380. package/src/scripts/_cli/cmd_versions.ts +2 -1
  381. package/src/scripts/_cli/detection_report.ts +480 -0
  382. package/src/scripts/_dispatch.bash +52 -14
  383. package/src/scripts/_lib/agent_user_profile.ts +381 -0
  384. package/src/scripts/_lib/agents_overlay.ts +9 -0
  385. package/src/scripts/_lib/anchor_eval.ts +311 -0
  386. package/src/scripts/_lib/cc_transcript.ts +316 -0
  387. package/src/scripts/_lib/changelog_eras.ts +103 -9
  388. package/src/scripts/_lib/compile_time_toggles.ts +79 -0
  389. package/src/scripts/_lib/confusables.ts +101 -0
  390. package/src/scripts/_lib/duplicate_scope_census.ts +77 -0
  391. package/src/scripts/_lib/environment_detector.ts +441 -0
  392. package/src/scripts/_lib/managed_agents_folder.ts +181 -0
  393. package/src/scripts/_lib/package_root.ts +72 -0
  394. package/src/scripts/_lib/payload_hash_drift.ts +126 -0
  395. package/src/scripts/_lib/preservation_migration.ts +291 -0
  396. package/src/scripts/_lib/retrieval_sanitize.ts +166 -2
  397. package/src/scripts/_lib/scan_scope.ts +115 -0
  398. package/src/scripts/_lib/user_global_memory_audit.ts +187 -0
  399. package/src/scripts/_lib/user_global_observations.ts +830 -0
  400. package/src/scripts/_lib/user_global_revocations.ts +110 -0
  401. package/src/scripts/_lib/user_memory_gate_counters.ts +291 -0
  402. package/src/scripts/ai_council/blind_review.ts +0 -0
  403. package/src/scripts/ai_council/budget_guard.ts +90 -11
  404. package/src/scripts/ai_council/bundler.ts +2 -2
  405. package/src/scripts/ai_council/clients.ts +59 -3
  406. package/src/scripts/ai_council/config.ts +53 -7
  407. package/src/scripts/ai_council/modes.ts +68 -2
  408. package/src/scripts/ai_council/orchestrator.ts +54 -9
  409. package/src/scripts/ai_council/transport_resolver.ts +331 -0
  410. package/src/scripts/ai_team/team_dispatch.ts +17 -6
  411. package/src/scripts/anchor_eval_falsify.ts +198 -0
  412. package/src/scripts/anchor_scoring_run.ts +239 -0
  413. package/src/scripts/annotate_discovery.ts +1 -65
  414. package/src/scripts/bench_quality_run.ts +168 -4
  415. package/src/scripts/cache_realization_report.ts +782 -0
  416. package/src/scripts/check_artefact_count_messaging.ts +5 -1
  417. package/src/scripts/check_augment_description_cap.ts +15 -4
  418. package/src/scripts/check_bundle_path_leakage.ts +10 -4
  419. package/src/scripts/check_ci_local_parity.ts +317 -0
  420. package/src/scripts/check_condensation.ts +96 -191
  421. package/src/scripts/check_context_paths.ts +38 -9
  422. package/src/scripts/check_dependency_floors.ts +153 -0
  423. package/src/scripts/check_gate_coverage.ts +299 -0
  424. package/src/scripts/check_iron_law_prominence.ts +22 -1
  425. package/src/scripts/check_kernel_prefix_stability.ts +0 -0
  426. package/src/scripts/check_no_new_legacy_path.ts +16 -6
  427. package/src/scripts/check_no_roadmap_refs.ts +22 -9
  428. package/src/scripts/check_originality_freshness.ts +167 -0
  429. package/src/scripts/check_pack_size.ts +188 -0
  430. package/src/scripts/check_preamble_payload_budget.ts +130 -0
  431. package/src/scripts/check_proposal.ts +0 -0
  432. package/src/scripts/check_references.ts +0 -1
  433. package/src/scripts/check_safety_floor_untouched.ts +171 -24
  434. package/src/scripts/check_site_links.ts +62 -3
  435. package/src/scripts/ci_status.ts +0 -0
  436. package/src/scripts/cluster_near_miss_patterns.ts +0 -0
  437. package/src/scripts/code_graph/build.ts +0 -0
  438. package/src/scripts/command_suggester/types.ts +0 -0
  439. package/src/scripts/compile_router.ts +10 -14
  440. package/src/scripts/condense.sh +3 -4
  441. package/src/scripts/condense.ts +247 -228
  442. package/src/scripts/cost/track.mjs +168 -33
  443. package/src/scripts/cost_summary.ts +33 -1
  444. package/src/scripts/council_cli.ts +51 -5
  445. package/src/scripts/discovery_graph.ts +0 -0
  446. package/src/scripts/encoding_corpus.ts +500 -0
  447. package/src/scripts/encoding_corpus_report.ts +216 -0
  448. package/src/scripts/evaluator_umbrella.sh +34 -1
  449. package/src/scripts/generate_index.ts +19 -2
  450. package/src/scripts/install-hooks.sh +2 -2
  451. package/src/scripts/learning_sidecar.ts +0 -0
  452. package/src/scripts/lint_confusables.ts +10 -72
  453. package/src/scripts/lint_eval_fixture_citations.ts +113 -0
  454. package/src/scripts/lint_featured_skills.ts +0 -0
  455. package/src/scripts/lint_hidden_unicode.ts +208 -0
  456. package/src/scripts/lint_load_context.ts +17 -5
  457. package/src/scripts/lint_new_skill_gate.ts +9 -3
  458. package/src/scripts/lint_no_python_twin_rationale.ts +17 -2
  459. package/src/scripts/lint_originality.ts +1 -1
  460. package/src/scripts/lint_skill_originality.ts +1 -1
  461. package/src/scripts/lint_ticket_buildable.ts +1 -1
  462. package/src/scripts/lint_ui_stack_bundles.ts +170 -0
  463. package/src/scripts/mcp_server/tools.ts +4 -4
  464. package/src/scripts/measure_scope_dedup.ts +224 -0
  465. package/src/scripts/memory_lookup.ts +0 -0
  466. package/src/scripts/mine_session.ts +98 -0
  467. package/src/scripts/orchestration_payload_hash_drift.ts +145 -0
  468. package/src/scripts/preamble_byte_census.ts +574 -0
  469. package/src/scripts/probe_skill_registration.ts +2 -2
  470. package/src/scripts/redact_hook_capture.ts +13 -0
  471. package/src/scripts/release.ts +65 -10
  472. package/src/scripts/router_telemetry.ts +1 -1
  473. package/src/scripts/second_brain_retrieval.ts +14 -4
  474. package/src/scripts/skill_linter.ts +5 -0
  475. package/src/scripts/surface-tiers.yml +2 -0
  476. package/src/scripts/validate_pack_yaml.ts +0 -0
  477. package/src/server/schemas/settings.ts +8 -0
  478. package/src/shared/userMd/utils.ts +31 -0
  479. package/dist/agent-src/rules/telegraph-speak.md +0 -87
@@ -109,7 +109,7 @@ export const UNLIMITED_TOKENS_FALLBACK = 16384;
109
109
  // OpenAI reasoning models (o1, o3, o4 families) reject `max_tokens` and the
110
110
  // `system` role; they require `max_completion_tokens` and accept only `user`
111
111
  // (and `developer`) messages.
112
- const _REASONING_PREFIXES: readonly string[] = ['o1', 'o3', 'o4'];
112
+ const _REASONING_PREFIXES: readonly string[] = ['o1', 'o3', 'o4', 'gpt-5'];
113
113
 
114
114
  export function _is_reasoning_model(model: string): boolean {
115
115
  const name = model.toLowerCase();
@@ -132,6 +132,38 @@ export class CliClientError extends Error {
132
132
  }
133
133
  }
134
134
 
135
+ /**
136
+ * Anthropic cache_control TTL tiers (road-to-cache-economy Phase 4).
137
+ * `'5m'` is the permanent default — see `prompt_cache.ttl` in
138
+ * `docs/contracts/ai-council-config.md` for the falsification condition
139
+ * that would be required before `'1h'` is ever enabled anywhere.
140
+ */
141
+ export type PromptCacheTtl = '5m' | '1h';
142
+ export const DEFAULT_PROMPT_CACHE_TTL: PromptCacheTtl = '5m';
143
+
144
+ /**
145
+ * Anthropic's cache_control ordering rule: within one request, a 1-hour
146
+ * breakpoint must be positioned before any 5-minute breakpoint. This
147
+ * client always applies the SAME configured ttl to both of its
148
+ * breakpoints (see `_ask_impl`), so the two are never mixed in
149
+ * practice — this guard exists so a future per-breakpoint ttl never
150
+ * regresses that invariant silently.
151
+ */
152
+ export function assertCacheBreakpointOrder(ttls: readonly PromptCacheTtl[]): void {
153
+ let sawFiveMinute = false;
154
+ for (const ttl of ttls) {
155
+ if (ttl === '5m') {
156
+ sawFiveMinute = true;
157
+ } else if (ttl === '1h' && sawFiveMinute) {
158
+ throw new TypeError(
159
+ `cache_control breakpoint order violation: a '1h' breakpoint ` +
160
+ `followed a '5m' one (${JSON.stringify(ttls)}) — Anthropic ` +
161
+ `requires every 1h breakpoint before any 5m breakpoint.`,
162
+ );
163
+ }
164
+ }
165
+ }
166
+
135
167
  /** Normalised output from a single council member (dataclass `CouncilResponse`). */
136
168
  export class CouncilResponse {
137
169
  provider: string;
@@ -319,6 +351,10 @@ interface ApiClientOptions {
319
351
  // unless it asks — so a single call never pays the ~1.25× write premium by
320
352
  // surprise. Only AnthropicClient consumes this; other providers ignore it.
321
353
  enable_prompt_cache?: boolean | undefined;
354
+ // TTL tier for both cache_control breakpoints (road-to-cache-economy
355
+ // Phase 4). Default '5m' when omitted — see `DEFAULT_PROMPT_CACHE_TTL`.
356
+ // Only meaningful when `enable_prompt_cache` is true.
357
+ prompt_cache_ttl?: PromptCacheTtl | undefined;
322
358
  }
323
359
 
324
360
  /** Shared ctor-options shape for the CLI clients. */
@@ -380,11 +416,17 @@ export class AnthropicClient extends ExternalAIClient {
380
416
  // ApiClientOptions.enable_prompt_cache. Prevents silent activation (and the
381
417
  // write premium) for callers that don't benefit from a shared-prefix cache.
382
418
  private _enablePromptCache: boolean;
419
+ // TTL applied to BOTH cache_control breakpoints below. '5m' (the
420
+ // default) is never serialised on the wire — omitting `ttl` is the
421
+ // Anthropic API's own 5-minute default, so the default case stays
422
+ // byte-identical to the pre-Phase-4 request shape.
423
+ private _promptCacheTtl: PromptCacheTtl;
383
424
 
384
425
  constructor(opts: ApiClientOptions = {}) {
385
426
  super();
386
427
  this.model = opts.model ?? DEFAULT_ANTHROPIC_MODEL;
387
428
  this._enablePromptCache = opts.enable_prompt_cache ?? false;
429
+ this._promptCacheTtl = opts.prompt_cache_ttl ?? DEFAULT_PROMPT_CACHE_TTL;
388
430
  if (opts.client !== undefined && opts.client !== null) {
389
431
  this._client = opts.client;
390
432
  return;
@@ -455,6 +497,18 @@ export class AnthropicClient extends ExternalAIClient {
455
497
  // base_system_prompt alone is often below the model's min cacheable
456
498
  // prefix and would never cache solo — the artefact block is where
457
499
  // the real saving lands. Two breakpoints (≤ the 4 allowed).
500
+ //
501
+ // Both breakpoints share the SAME configured ttl (road-to-
502
+ // cache-economy Phase 4) — they never diverge, so the API's
503
+ // "1h before 5m" ordering rule can never be violated here; the
504
+ // assertion below is a regression guard, not a live branch.
505
+ // Default '5m' omits the `ttl` field entirely (Anthropic's own
506
+ // default), so an unconfigured member's wire shape is unchanged
507
+ // from before Phase 4.
508
+ const ttl = this._promptCacheTtl;
509
+ assertCacheBreakpointOrder([ttl, ttl]);
510
+ const cache_control: Record<string, unknown> =
511
+ ttl === '1h' ? { type: 'ephemeral', ttl: '1h' } : { type: 'ephemeral' };
458
512
  const kwargs: Record<string, unknown> = this._enablePromptCache
459
513
  ? {
460
514
  model: this.model,
@@ -463,7 +517,7 @@ export class AnthropicClient extends ExternalAIClient {
463
517
  {
464
518
  type: 'text',
465
519
  text: system_prompt,
466
- cache_control: { type: 'ephemeral' },
520
+ cache_control,
467
521
  },
468
522
  ],
469
523
  messages: [
@@ -473,11 +527,13 @@ export class AnthropicClient extends ExternalAIClient {
473
527
  // volatile suffix (round critiques) rides after
474
528
  // it, so round N+1 reads the cached prefix
475
529
  // instead of re-writing it (A3 read unlock).
530
+ // The volatile suffix NEVER carries cache_control
531
+ // — the ttl reaches only the stable prefix.
476
532
  content: [
477
533
  {
478
534
  type: 'text',
479
535
  text: stable_prompt,
480
- cache_control: { type: 'ephemeral' },
536
+ cache_control,
481
537
  },
482
538
  ...(volatile_suffix
483
539
  ? [{ type: 'text', text: volatile_suffix }]
@@ -14,12 +14,16 @@
14
14
  * Validation contract (8 rules, all enforced at load time):
15
15
  *
16
16
  * 1. `enabled` is a bool.
17
- * 2. `defaults.mode` ∈ {`api`, `manual`, `cli`}; per-member mode same
18
- * set. Semantics: `api` = SDK call against a stored key (billable);
17
+ * 2. `defaults.mode` ∈ {`api`, `manual`, `cli`, `auto`}; per-member mode
18
+ * same set. Semantics: `api` = SDK call against a stored key (billable);
19
19
  * `manual` = copy & paste — human transports prompt + reply between
20
20
  * the agent and an external chat surface (free); `cli` = shell out to
21
21
  * a locally-installed CLI under subscription auth (free for
22
- * first-party CLIs, billable for community wrappers).
22
+ * first-party CLIs, billable for community wrappers); `auto` = pick
23
+ * per provider per invocation (cli → api → unavailable), resolved by
24
+ * `transport_resolver.ts`. `auto` is opt-in — it is never the shipped
25
+ * default, because flipping it would move an existing user's spend
26
+ * from per-token dollars onto subscription quota with no config edit.
23
27
  * 3. `members.<name>` keys are restricted to the known provider set.
24
28
  * 4. `cost_budget.*` numeric fields are >= 0.
25
29
  * 5. Enabled members carry a non-empty `model` and `api_key_ref` when
@@ -30,7 +34,8 @@
30
34
  * even if syntactically plausible.
31
35
  * 7. Resolved `file:` key paths must have mode 0o600 (delegated to
32
36
  * `resolve_api_key`; runs at use-time, not parse-time).
33
- * 8. `binary:` is only valid when the member's effective mode is `cli`;
37
+ * 8. `binary:` is only valid when the member's effective mode is `cli` or
38
+ * `auto` (auto may resolve to the cli rung);
34
39
  * `cli_call_budget.max_calls_per_day.<provider>` keys must be valid
35
40
  * providers.
36
41
  *
@@ -60,7 +65,7 @@ const _VALID_PROVIDERS: ReadonlySet<string> = new Set([
60
65
  'xai',
61
66
  'perplexity',
62
67
  ]);
63
- const _VALID_MODES: ReadonlySet<string> = new Set(['api', 'manual', 'cli']);
68
+ const _VALID_MODES: ReadonlySet<string> = new Set(['api', 'manual', 'cli', 'auto']);
64
69
 
65
70
  /**
66
71
  * Prefixes that signal "this is a raw API key" so we refuse it loudly
@@ -362,6 +367,9 @@ export interface CostBudgetConfig {
362
367
  readonly max_output_tokens: number;
363
368
  readonly max_calls: number;
364
369
  readonly max_total_usd: number;
370
+ /** Rolling 24h cap. 0 disables it — and disabling it also disables the spend
371
+ * ledger, since the orchestrator only appends an entry while a cap is live. */
372
+ readonly daily_limit_usd: number;
365
373
  }
366
374
 
367
375
  export interface MemberConfig {
@@ -380,6 +388,13 @@ export interface MemberConfig {
380
388
  * back to deterministic config order.
381
389
  */
382
390
  readonly tier: number | null;
391
+ /**
392
+ * Cache-control TTL tier for this member's Anthropic breakpoints
393
+ * (road-to-cache-economy Phase 4). `'5m'` is the permanent default —
394
+ * see `prompt_cache.ttl` in `docs/contracts/ai-council-config.md` for
395
+ * the falsification condition that gates ever enabling `'1h'`.
396
+ */
397
+ readonly prompt_cache_ttl: '5m' | '1h';
383
398
  }
384
399
 
385
400
  /**
@@ -1591,12 +1606,14 @@ function _build_cost_budget(d: Dict): CostBudgetConfig {
1591
1606
  max_output_tokens: _pyInt(_get(d, 'max_output_tokens', 200_000)),
1592
1607
  max_calls: _pyInt(_get(d, 'max_calls', 50)),
1593
1608
  max_total_usd: _pyFloat(_get(d, 'max_total_usd', 20.0)),
1609
+ daily_limit_usd: _pyFloat(_get(d, 'daily_limit_usd', 0.0)),
1594
1610
  };
1595
1611
  const fields: Array<[keyof CostBudgetConfig, boolean]> = [
1596
1612
  ['max_input_tokens', false],
1597
1613
  ['max_output_tokens', false],
1598
1614
  ['max_calls', false],
1599
1615
  ['max_total_usd', true],
1616
+ ['daily_limit_usd', true],
1600
1617
  ];
1601
1618
  for (const [fname, isFloat] of fields) {
1602
1619
  const val = cb[fname];
@@ -1643,10 +1660,13 @@ function _build_member(
1643
1660
  `members.${name}.binary must be a non-empty string when set.`,
1644
1661
  );
1645
1662
  }
1646
- if (effective_mode !== 'cli') {
1663
+ // `auto` may resolve to the cli rung, so a binary override is
1664
+ // legitimate there too — rejecting it would make `auto` unusable for
1665
+ // anyone whose CLI is not on `$PATH` under its default name.
1666
+ if (effective_mode !== 'cli' && effective_mode !== 'auto') {
1647
1667
  throw new CouncilConfigError(
1648
1668
  `members.${name}.binary is only valid when the member's ` +
1649
- `effective mode is 'cli' (got ${_pyRepr(effective_mode)}). Set ` +
1669
+ `effective mode is 'cli' or 'auto' (got ${_pyRepr(effective_mode)}). Set ` +
1650
1670
  `\`mode: cli\` on the member or \`defaults.mode: cli\` to use ` +
1651
1671
  `this field.`,
1652
1672
  );
@@ -1716,6 +1736,31 @@ function _build_member(
1716
1736
  }
1717
1737
  tier = tier_raw;
1718
1738
  }
1739
+ // road-to-cache-economy Phase 4: `prompt_cache` stays accepted as a
1740
+ // bare bool (the pre-existing, undocumented enable/disable form —
1741
+ // untouched here) OR as a mapping carrying `ttl`. '5m' is the
1742
+ // permanent default; see docs/contracts/ai-council-config.md
1743
+ // § Prompt cache TTL for the falsification condition on '1h'.
1744
+ const prompt_cache_raw = _get(cfg, 'prompt_cache', null);
1745
+ let prompt_cache_ttl: '5m' | '1h' = '5m';
1746
+ if (prompt_cache_raw !== null && prompt_cache_raw !== undefined && !_isBool(prompt_cache_raw)) {
1747
+ if (!_isDict(prompt_cache_raw)) {
1748
+ throw new CouncilConfigError(
1749
+ `members.${name}.prompt_cache must be a bool or a mapping ` +
1750
+ `(got ${_pyTypeName(prompt_cache_raw)}).`,
1751
+ );
1752
+ }
1753
+ const ttl_raw = _get(prompt_cache_raw, 'ttl', '5m');
1754
+ if (ttl_raw !== '5m' && ttl_raw !== '1h') {
1755
+ throw new CouncilConfigError(
1756
+ `members.${name}.prompt_cache.ttl must be '5m' or '1h' (got ` +
1757
+ `${_pyRepr(ttl_raw)}). '5m' remains the default until a ` +
1758
+ `pre-registered 30-debate gap sample clears 40% at ` +
1759
+ `>=5-minute inter-round gaps.`,
1760
+ );
1761
+ }
1762
+ prompt_cache_ttl = ttl_raw;
1763
+ }
1719
1764
  return {
1720
1765
  name,
1721
1766
  enabled: member_enabled,
@@ -1726,6 +1771,7 @@ function _build_member(
1726
1771
  model_ladder: ladder,
1727
1772
  participate_low_impact: participate_raw,
1728
1773
  tier,
1774
+ prompt_cache_ttl,
1729
1775
  };
1730
1776
  }
1731
1777
 
@@ -12,17 +12,43 @@
12
12
  * - `manual` — copy-paste loop with the user as transport (free).
13
13
  * - `cli` — shell out to a locally-installed provider CLI under the
14
14
  * user's subscription auth. `billable=False`.
15
+ * - `auto` — resolve per provider per invocation (cli → api → unavailable).
16
+ * Accepted here as a VALUE; the concrete transport is chosen by
17
+ * `transport_resolver.ts`, which owns the chain and the billing
18
+ * classification. `manual` is never part of the auto chain.
15
19
  *
16
20
  * Resolution precedence — first non-empty wins:
17
21
  *
18
22
  * 1. Invocation flag e.g. `/council mode:manual`
19
23
  * 2. Per-member setting `ai_council.members.<name>.mode`
20
- * 3. Global setting `ai_council.mode`
24
+ * 3. Global setting `ai_council.mode` OR `ai_council.defaults.mode`
25
+ * (see `resolve_global_mode` — both shapes reach
26
+ * this resolver, and they must agree)
21
27
  * 4. Built-in default `manual`
28
+ *
29
+ * ## Two distinct defaults — the reconciliation (road-to-zero-ceremony-detection)
30
+ *
31
+ * The contract used to describe a single fallback (`"api"`) while this module
32
+ * implemented `manual`. Both were right about different layers, and the docs
33
+ * conflated them. They are now named separately:
34
+ *
35
+ * - **Loader default** — when a config file omits `defaults.mode` entirely,
36
+ * `config.ts::_build_defaults` fills `api`. Unchanged; this is what every
37
+ * real config observes, because the loader always populates the key.
38
+ * - **Built-in fallback** — when NO layer supplies a mode at all (a settings
39
+ * dict handed straight to the resolver, no config file involved), the answer
40
+ * is `manual`, below. That is the fail-closed direction the no-silent-spend
41
+ * Iron Law requires: a caller who supplied no transport preference has not
42
+ * asked to spend money, so the free transport wins.
22
43
  */
23
44
 
24
- export const VALID_MODES: ReadonlySet<string> = new Set(['api', 'manual', 'cli']);
45
+ export const VALID_MODES: ReadonlySet<string> = new Set(['api', 'manual', 'cli', 'auto']);
25
46
 
47
+ /**
48
+ * Built-in fallback when no layer supplies a mode. `manual` — free, no key,
49
+ * no spend. NOT the same as the loader's `defaults.mode` default (`api`); see
50
+ * the module header.
51
+ */
26
52
  export const DEFAULT_MODE = 'manual';
27
53
 
28
54
  /** Raised when a configured / invoked mode is not in `VALID_MODES`. */
@@ -72,6 +98,46 @@ function _pyReprList(items: string[]): string {
72
98
  return `[${items.map((i) => _pyRepr(i)).join(', ')}]`;
73
99
  }
74
100
 
101
+ /**
102
+ * Extract the global transport mode from an `ai_council` block, accepting BOTH
103
+ * shapes the block legitimately arrives in.
104
+ *
105
+ * `council_cli.ts::_synthesize_ai_council_block` FLATTENS the loader's
106
+ * `defaults.mode` onto a top-level `mode` key, so the normal path presents the
107
+ * flat shape. But `build_members` is on the exported surface, and callers that
108
+ * hand it a RAW `.ai-council.yml`-shaped dict present the nested shape. Reading
109
+ * only the flat key silently dropped the configured default on that path and
110
+ * fell through to `DEFAULT_MODE`.
111
+ *
112
+ * Flat wins when both are present — it is the synthesized, already-resolved
113
+ * value. Returns `null` when neither shape carries a usable string, letting the
114
+ * precedence chain continue to the built-in.
115
+ */
116
+ export function resolve_global_mode(
117
+ aiBlock: ReadonlyMap<string, unknown> | Record<string, unknown> | null | undefined,
118
+ ): string | null {
119
+ if (aiBlock === null || aiBlock === undefined) {
120
+ return null;
121
+ }
122
+ const flat = _normalise(_settingsGet(aiBlock, 'mode'));
123
+ if (flat !== null) {
124
+ return flat;
125
+ }
126
+ const defaults = _settingsGet(aiBlock, 'defaults');
127
+ if (defaults === null || defaults === undefined) {
128
+ return null;
129
+ }
130
+ if (!(defaults instanceof Map) && typeof defaults !== 'object') {
131
+ return null;
132
+ }
133
+ if (Array.isArray(defaults)) {
134
+ return null;
135
+ }
136
+ return _normalise(
137
+ _settingsGet(defaults as ReadonlyMap<string, unknown> | Record<string, unknown>, 'mode'),
138
+ );
139
+ }
140
+
75
141
  export interface ResolveModeOptions {
76
142
  invocationMode?: string | null;
77
143
  memberSettings?: ReadonlyMap<string, unknown> | Record<string, unknown> | null;
@@ -51,6 +51,7 @@ import type {
51
51
  import {
52
52
  estimate_cost,
53
53
  estimate_input_tokens,
54
+ reprice_with_cache,
54
55
  } from './pricing.js';
55
56
  import type { ProjectContext } from './project_context.js';
56
57
  import type { AdvisorPlan } from './advisors.js';
@@ -779,22 +780,34 @@ function _run_round(
779
780
  spent.output += response.output_tokens;
780
781
  let actual_usd: number | null = null;
781
782
  if (estimates !== null && table !== null) {
782
- // Bill the actual output against the budget using the
783
- // member's per-1M output rate. Re-use estimate_cost with
784
- // the *real* token count.
785
- const actual = estimate_cost(
783
+ // Realized cost bills the OBSERVED cache read/write tokens
784
+ // (Anthropic's usage.input_tokens excludes them), unlike the
785
+ // cache-agnostic pre-flight estimate above — see
786
+ // `reprice_with_cache`'s docstring for why the two stay separate.
787
+ // ttl is '5m': the request builder emits `cache_control:
788
+ // {type:'ephemeral'}` with no explicit ttl, i.e. the 5-min default.
789
+ const actual = reprice_with_cache(
786
790
  member.name,
787
791
  member.model,
788
- response.input_tokens,
789
- response.output_tokens,
792
+ {
793
+ input_tokens: response.input_tokens,
794
+ cache_read_input_tokens: response.cache_read_input_tokens,
795
+ cache_creation_input_tokens: response.cache_creation_input_tokens,
796
+ output_tokens: response.output_tokens,
797
+ },
790
798
  table,
799
+ '5m',
791
800
  );
792
801
  actual_usd = _total_usd(actual);
793
802
  spent.usd += _total_usd(actual);
794
803
  // Persist to the rolling 24h ledger when the daily cap is
795
804
  // active. Errors are swallowed inside record_spend.
796
805
  if (budget.daily_limit_usd > 0 && !response.error) {
797
- _record_daily_spend(_total_usd(actual), member.name, member.model);
806
+ _record_daily_spend(_total_usd(actual), member.name, member.model, {
807
+ cache_read_input_tokens: response.cache_read_input_tokens,
808
+ cache_creation_input_tokens: response.cache_creation_input_tokens,
809
+ cache_ttl: '5m',
810
+ });
798
811
  }
799
812
  }
800
813
  _stamp_transport_metadata(response, member, actual_usd);
@@ -1116,12 +1129,32 @@ export interface RunDebateOptions {
1116
1129
  project?: ProjectContext | null;
1117
1130
  original_ask?: string;
1118
1131
  max_rounds?: number;
1132
+ /**
1133
+ * Third argument (road-to-cache-economy Phase 4): the observed
1134
+ * wall-clock gap, in ms, between the PREVIOUS round finishing (≈ when
1135
+ * its stable prefix was written to the prompt cache) and THIS round
1136
+ * starting (≈ when the same prefix would be read, if byte-identical).
1137
+ * `null` on round 1 — nothing was written yet. Existing callers that
1138
+ * declare only the first two parameters keep working unchanged (JS
1139
+ * ignores extra call arguments).
1140
+ */
1119
1141
  on_round_complete?:
1120
- | ((round_number: number, responses: CouncilResponse[]) => void)
1142
+ | ((
1143
+ round_number: number,
1144
+ responses: CouncilResponse[],
1145
+ cache_gap_ms_since_previous_round?: number | null,
1146
+ ) => void)
1121
1147
  | null;
1122
1148
  on_continue?: DebateContinuePrompt | null;
1123
1149
  advisor_plans?: Map<string, AdvisorPlan> | null;
1124
1150
  seed_round_1?: CouncilResponse[] | null;
1151
+ /**
1152
+ * Injectable wall-clock source for the Phase-4 gap measurement above.
1153
+ * Defaults to `Date.now`. Tests inject a scripted clock so "rounds
1154
+ * seconds apart" vs "a >5-minute gap" can be asserted deterministically,
1155
+ * without a real multi-minute sleep.
1156
+ */
1157
+ now?: (() => number) | null;
1125
1158
  /**
1126
1159
  * Phase 3: when true (from `ai_council.debate_gates.enabled`), round-2+
1127
1160
  * prompts carry the anti-conformity directive. Default `false` → the debate
@@ -1186,6 +1219,7 @@ export function run_debate(
1186
1219
  const on_continue = opts.on_continue ?? null;
1187
1220
  const advisor_plans = opts.advisor_plans ?? null;
1188
1221
  const seed_round_1 = opts.seed_round_1 ?? null;
1222
+ const now = opts.now ?? Date.now;
1189
1223
 
1190
1224
  if (max_rounds < 1) {
1191
1225
  throw new Error(`max_rounds must be >= 1 (got ${max_rounds})`);
@@ -1207,6 +1241,9 @@ export function run_debate(
1207
1241
  // per-round positions block rides in a volatile suffix (see consult loop).
1208
1242
  let current_suffix = '';
1209
1243
  let current_user_prompt = question.user_prompt;
1244
+ // road-to-cache-economy Phase 4: wall-clock marker for the inter-round
1245
+ // cache-gap measurement. `null` until round 1 finishes.
1246
+ let previous_round_end_ms: number | null = null;
1210
1247
 
1211
1248
  // Phase 3 restate: one pre-round-1 call per member. Runs BEFORE any debate
1212
1249
  // spend so a diverging restatement can be flagged before round-2 cost.
@@ -1231,6 +1268,9 @@ export function run_debate(
1231
1268
 
1232
1269
  for (let round_idx = 0; round_idx < max_rounds; round_idx++) {
1233
1270
  const round_number = round_idx + 1;
1271
+ const round_start_ms = now();
1272
+ const cache_gap_ms_since_previous_round: number | null =
1273
+ previous_round_end_ms === null ? null : round_start_ms - previous_round_end_ms;
1234
1274
  let results: CouncilResponse[];
1235
1275
  if (round_idx === 0 && seed_round_1 !== null) {
1236
1276
  // Pivot from /council default — reuse the existing round 1
@@ -1276,7 +1316,7 @@ export function run_debate(
1276
1316
  }
1277
1317
  all_rounds.push(results);
1278
1318
  if (on_round_complete !== null) {
1279
- on_round_complete(round_number, results);
1319
+ on_round_complete(round_number, results, cache_gap_ms_since_previous_round);
1280
1320
  }
1281
1321
 
1282
1322
  // Prep the user-prompt for the next round so the cost estimate
@@ -1334,6 +1374,11 @@ export function run_debate(
1334
1374
  }
1335
1375
  }
1336
1376
  }
1377
+ // road-to-cache-economy Phase 4: mark the end of this round AFTER the
1378
+ // continue-prompt gate above — an interactive pause there is exactly
1379
+ // the kind of real-world inter-round gap this measurement exists to
1380
+ // observe, so it must fall inside the window, not before it.
1381
+ previous_round_end_ms = now();
1337
1382
  }
1338
1383
 
1339
1384
  return all_rounds;