@event4u/agent-config 9.9.0 → 9.10.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 (384) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/CHANGELOG.md +153 -194
  3. package/README.md +1 -1
  4. package/dist/agent-src/commands/agent-status.md +12 -11
  5. package/dist/agent-src/commands/agents/user/accept.md +115 -30
  6. package/dist/agent-src/commands/agents/user/delete.md +147 -0
  7. package/dist/agent-src/commands/agents/user/review.md +65 -28
  8. package/dist/agent-src/commands/agents/user/show.md +82 -29
  9. package/dist/agent-src/commands/agents/user/update.md +2 -2
  10. package/dist/agent-src/commands/agents/user.md +16 -3
  11. package/dist/agent-src/commands/check-current-md.md +0 -10
  12. package/dist/agent-src/commands/condense.md +28 -97
  13. package/dist/agent-src/commands/cost/report.md +7 -0
  14. package/dist/agent-src/commands/fix/portability.md +0 -8
  15. package/dist/agent-src/commands/fix/refs.md +0 -8
  16. package/dist/agent-src/commands/humanize.md +2 -2
  17. package/dist/agent-src/commands/jira-ticket.md +1 -1
  18. package/dist/agent-src/commands/memory/load.md +11 -0
  19. package/dist/agent-src/commands/optimize/skills.md +1 -1
  20. package/dist/agent-src/commands/pr/create.md +4 -4
  21. package/dist/agent-src/commands/profile/show.md +3 -3
  22. package/dist/agent-src/commands/rule-compliance-audit.md +5 -4
  23. package/dist/agent-src/commands/security-audit-config.md +1 -1
  24. package/dist/agent-src/commands/sync/gitignore/fix.md +1 -1
  25. package/dist/agent-src/commands/tdd.md +21 -0
  26. package/dist/agent-src/commands/team/delegate.md +2 -2
  27. package/dist/agent-src/commands/team-knowledge/bootstrap.md +9 -8
  28. package/dist/agent-src/commands/team-knowledge/consolidate.md +8 -7
  29. package/dist/agent-src/commands/team.md +4 -1
  30. package/dist/agent-src/commands/upstream-contribute.md +0 -1
  31. package/dist/agent-src/contexts/authority/commit-mechanics.md +7 -0
  32. package/dist/agent-src/contexts/authority/destructive-mechanics.md +16 -0
  33. package/dist/agent-src/contexts/authority/scope-mechanics.md +61 -0
  34. package/dist/agent-src/contexts/communication/rules-auto/reply-close-mechanics.md +20 -18
  35. package/dist/agent-src/contexts/communication/rules-auto/skill-quality-mechanics.md +1 -1
  36. package/dist/agent-src/contexts/communication/rules-auto/slash-command-routing-policy-mechanics.md +1 -1
  37. package/dist/agent-src/contexts/communication/rules-auto/source-of-truth-mechanics.md +9 -10
  38. package/dist/agent-src/contexts/communication/rules-auto/think-before-action-mechanics.md +1 -1
  39. package/dist/agent-src/contexts/communication/rules-auto/user-interaction-mechanics.md +11 -0
  40. package/dist/agent-src/contexts/contracts/artifact-engagement-flow.md +26 -15
  41. package/dist/agent-src/contexts/contracts/command-suggestion-flow.md +3 -0
  42. package/dist/agent-src/contexts/execution/auto-dispatch-classification.md +67 -37
  43. package/dist/agent-src/contexts/execution/auto-orchestration-activation.md +1 -1
  44. package/dist/agent-src/contexts/execution/autonomy-examples.md +1 -1
  45. package/dist/agent-src/contexts/execution/autonomy-mechanics.md +7 -6
  46. package/dist/agent-src/contexts/execution/evidence-discipline.md +92 -77
  47. package/dist/agent-src/contexts/execution/orchestration-benchmark-gate.md +22 -21
  48. package/dist/agent-src/contexts/execution/orchestration-telemetry.md +24 -0
  49. package/dist/agent-src/contexts/execution/project-intelligence.md +122 -103
  50. package/dist/agent-src/contexts/execution/roadmap-execution-contract.md +23 -21
  51. package/dist/agent-src/contexts/execution/subagent-response-contract.md +5 -5
  52. package/dist/agent-src/contexts/execution/subagent-routing.md +11 -0
  53. package/dist/agent-src/contexts/execution/subagent-spawn-contract.md +13 -13
  54. package/dist/agent-src/contexts/execution/subagent-steering.md +36 -34
  55. package/dist/agent-src/contexts/execution/toolchain-resolver.md +1 -1
  56. package/dist/agent-src/contexts/execution/user-memory-channels.md +189 -0
  57. package/dist/agent-src/contexts/execution/verification-mechanics.md +9 -0
  58. package/dist/agent-src/contexts/model-recommendations.md +3 -2
  59. package/dist/agent-src/contexts/subagent-configuration.md +3 -3
  60. package/dist/agent-src/ghostwriter/README.md +2 -2
  61. package/dist/agent-src/packs/README.md +1 -1
  62. package/dist/agent-src/personas/README.md +5 -5
  63. package/dist/agent-src/personas/_template-specialist/persona.md +3 -3
  64. package/dist/agent-src/personas/backend-architect.md +24 -23
  65. package/dist/agent-src/personas/eloquent-tamer.md +30 -30
  66. package/dist/agent-src/personas/frontend-engineer.md +30 -30
  67. package/dist/agent-src/personas/product-owner.md +41 -38
  68. package/dist/agent-src/personas/qa.md +13 -13
  69. package/dist/agent-src/personas/security-engineer.md +22 -22
  70. package/dist/agent-src/presets/README.md +3 -3
  71. package/dist/agent-src/profiles/README.md +3 -3
  72. package/dist/agent-src/rules/active-remediation.md +2 -2
  73. package/dist/agent-src/rules/artifact-engagement-recording.md +4 -4
  74. package/dist/agent-src/rules/ask-when-uncertain.md +0 -4
  75. package/dist/agent-src/rules/augment-edit-discipline.md +1 -1
  76. package/dist/agent-src/rules/broken-access-control.md +4 -4
  77. package/dist/agent-src/rules/code-comment-discipline.md +1 -1
  78. package/dist/agent-src/rules/code-provenance.md +2 -2
  79. package/dist/agent-src/rules/commit-policy.md +4 -9
  80. package/dist/agent-src/rules/communication-through-line.md +5 -5
  81. package/dist/agent-src/rules/decision-revisit-gate.md +1 -1
  82. package/dist/agent-src/rules/doc-screenshot-hygiene.md +1 -1
  83. package/dist/agent-src/rules/domain-adoption-policy.md +1 -1
  84. package/dist/agent-src/rules/domain-safety-pii.md +1 -1
  85. package/dist/agent-src/rules/external-code-graph-interop.md +1 -1
  86. package/dist/agent-src/rules/fast-path-marker-visibility.md +43 -7
  87. package/dist/agent-src/rules/finance-safety-floor.md +1 -1
  88. package/dist/agent-src/rules/framework-neutrality-in-generic-skills.md +3 -3
  89. package/dist/agent-src/rules/history-discipline.md +1 -1
  90. package/dist/agent-src/rules/legal-safety-floor.md +1 -1
  91. package/dist/agent-src/rules/lethal-trifecta-guard.md +5 -5
  92. package/dist/agent-src/rules/low-impact-corpus-privacy-floor.md +10 -8
  93. package/dist/agent-src/rules/media-governance-routing.md +13 -13
  94. package/dist/agent-src/rules/media-sync-ground-truth.md +29 -11
  95. package/dist/agent-src/rules/no-cheap-questions.md +7 -7
  96. package/dist/agent-src/rules/no-decorative-emojis-in-git-surfaces.md +29 -18
  97. package/dist/agent-src/rules/non-destructive-by-default.md +5 -23
  98. package/dist/agent-src/rules/onboarding-gate.md +14 -4
  99. package/dist/agent-src/rules/persona-governance.md +2 -2
  100. package/dist/agent-src/rules/prefer-enums-over-literals.md +9 -9
  101. package/dist/agent-src/rules/preservation-guard.md +10 -2
  102. package/dist/agent-src/rules/question-not-instruction.md +1 -1
  103. package/dist/agent-src/rules/roadmap-progress-sync.md +6 -6
  104. package/dist/agent-src/rules/rule-type-governance.md +1 -1
  105. package/dist/agent-src/rules/scale-discipline.md +1 -1
  106. package/dist/agent-src/rules/scope-control.md +1 -1
  107. package/dist/agent-src/rules/secret-vcs-guard.md +1 -1
  108. package/dist/agent-src/rules/security-sensitive-stop.md +17 -11
  109. package/dist/agent-src/rules/senior-engineering-discipline.md +17 -17
  110. package/dist/agent-src/rules/session-canary.md +1 -1
  111. package/dist/agent-src/rules/skill-quality.md +1 -1
  112. package/dist/agent-src/rules/source-confidentiality.md +21 -19
  113. package/dist/agent-src/rules/source-of-truth.md +6 -5
  114. package/dist/agent-src/rules/spreadsheet-source-quality.md +2 -2
  115. package/dist/agent-src/rules/strategy-safety-floor.md +1 -1
  116. package/dist/agent-src/rules/think-before-action.md +5 -5
  117. package/dist/agent-src/rules/token-budget-discipline.md +5 -3
  118. package/dist/agent-src/rules/token-efficiency.md +2 -2
  119. package/dist/agent-src/rules/untrusted-input-defense.md +4 -4
  120. package/dist/agent-src/rules/user-interaction.md +12 -0
  121. package/dist/agent-src/rules/verify-before-complete.md +4 -24
  122. package/dist/agent-src/skills/adversarial-review/SKILL.md +2 -2
  123. package/dist/agent-src/skills/agent-security-review/SKILL.md +52 -45
  124. package/dist/agent-src/skills/agents-md-thin-root/SKILL.md +2 -2
  125. package/dist/agent-src/skills/ai-code-blindspots/SKILL.md +20 -20
  126. package/dist/agent-src/skills/ai-council/SKILL.md +185 -128
  127. package/dist/agent-src/skills/analysis-skill-router/SKILL.md +3 -3
  128. package/dist/agent-src/skills/api-endpoint/SKILL.md +2 -2
  129. package/dist/agent-src/skills/artisan-commands/SKILL.md +2 -2
  130. package/dist/agent-src/skills/async-python-patterns/SKILL.md +8 -7
  131. package/dist/agent-src/skills/authz-review/SKILL.md +16 -15
  132. package/dist/agent-src/skills/aws-infrastructure/SKILL.md +5 -5
  133. package/dist/agent-src/skills/blade-ui/SKILL.md +1 -1
  134. package/dist/agent-src/skills/bug-analyzer/SKILL.md +30 -12
  135. package/dist/agent-src/skills/code-intelligence/SKILL.md +0 -1
  136. package/dist/agent-src/skills/code-intelligence/evals/triggers.json +52 -0
  137. package/dist/agent-src/skills/code-review/SKILL.md +6 -6
  138. package/dist/agent-src/skills/command-routing/SKILL.md +5 -4
  139. package/dist/agent-src/skills/composer-packages/SKILL.md +2 -2
  140. package/dist/agent-src/skills/condense-memory/SKILL.md +43 -41
  141. package/dist/agent-src/skills/context-document/SKILL.md +23 -21
  142. package/dist/agent-src/skills/copilot-config/SKILL.md +6 -1
  143. package/dist/agent-src/skills/decision-record/SKILL.md +20 -18
  144. package/dist/agent-src/skills/design-intelligence/SKILL.md +4 -4
  145. package/dist/agent-src/skills/design-review/SKILL.md +15 -14
  146. package/dist/agent-src/skills/design-system-capture/reference/design-system-json.md +28 -25
  147. package/dist/agent-src/skills/devcontainer/SKILL.md +2 -2
  148. package/dist/agent-src/skills/docker/SKILL.md +1 -1
  149. package/dist/agent-src/skills/docx-authoring/evals/triggers.json +52 -0
  150. package/dist/agent-src/skills/emit-tickets/SKILL.md +2 -2
  151. package/dist/agent-src/skills/error-handling-patterns/SKILL.md +1 -1
  152. package/dist/agent-src/skills/estimate-ticket/SKILL.md +2 -2
  153. package/dist/agent-src/skills/evaluate-llm-feature/SKILL.md +0 -1
  154. package/dist/agent-src/skills/evaluate-llm-feature/evals/triggers.json +52 -0
  155. package/dist/agent-src/skills/existing-ui-audit/SKILL.md +6 -5
  156. package/dist/agent-src/skills/feature-planning/SKILL.md +2 -2
  157. package/dist/agent-src/skills/finishing-a-development-branch/SKILL.md +3 -3
  158. package/dist/agent-src/skills/flux/SKILL.md +1 -1
  159. package/dist/agent-src/skills/frontend-render-security/SKILL.md +13 -13
  160. package/dist/agent-src/skills/git-workflow/SKILL.md +33 -33
  161. package/dist/agent-src/skills/grafana/SKILL.md +5 -0
  162. package/dist/agent-src/skills/humanizer/SKILL.md +83 -66
  163. package/dist/agent-src/skills/humanizer/data/patterns.md +14 -14
  164. package/dist/agent-src/skills/humanizer/references/anti-aiisms.md +4 -4
  165. package/dist/agent-src/skills/judge-artifact-completeness/SKILL.md +82 -37
  166. package/dist/agent-src/skills/judge-bug-hunter/SKILL.md +17 -5
  167. package/dist/agent-src/skills/judge-injection-defense/SKILL.md +63 -25
  168. package/dist/agent-src/skills/judge-security-auditor/SKILL.md +2 -0
  169. package/dist/agent-src/skills/judge-synthesis/SKILL.md +72 -28
  170. package/dist/agent-src/skills/laravel-horizon/SKILL.md +5 -0
  171. package/dist/agent-src/skills/laravel-mail/SKILL.md +5 -4
  172. package/dist/agent-src/skills/laravel-middleware/SKILL.md +5 -4
  173. package/dist/agent-src/skills/laravel-notifications/SKILL.md +10 -9
  174. package/dist/agent-src/skills/laravel-pennant/SKILL.md +1 -1
  175. package/dist/agent-src/skills/laravel-pulse/SKILL.md +9 -8
  176. package/dist/agent-src/skills/laravel-reverb/SKILL.md +6 -5
  177. package/dist/agent-src/skills/laravel-scheduling/SKILL.md +6 -1
  178. package/dist/agent-src/skills/laravel-validation/SKILL.md +12 -0
  179. package/dist/agent-src/skills/launch-readiness/SKILL.md +1 -1
  180. package/dist/agent-src/skills/learning-to-rule-or-skill/SKILL.md +7 -7
  181. package/dist/agent-src/skills/learning-tutor/SKILL.md +44 -43
  182. package/dist/agent-src/skills/learning-tutor/evals/triggers.json +52 -0
  183. package/dist/agent-src/skills/license-compliance-audit/SKILL.md +7 -7
  184. package/dist/agent-src/skills/license-compliance-borrow-check/SKILL.md +3 -3
  185. package/dist/agent-src/skills/license-compliance-credits/SKILL.md +4 -4
  186. package/dist/agent-src/skills/llm-provider-knowledge/SKILL.md +0 -1
  187. package/dist/agent-src/skills/memory-consolidation/SKILL.md +69 -64
  188. package/dist/agent-src/skills/motion-choreographer/SKILL.md +6 -6
  189. package/dist/agent-src/skills/pdf-tools/evals/triggers.json +52 -0
  190. package/dist/agent-src/skills/performance-analysis/SKILL.md +7 -3
  191. package/dist/agent-src/skills/persona-improvement/SKILL.md +0 -2
  192. package/dist/agent-src/skills/persona-improvement/evals/triggers.json +52 -0
  193. package/dist/agent-src/skills/php-coder/SKILL.md +10 -0
  194. package/dist/agent-src/skills/prediction-pool-optimizer/SKILL.md +129 -120
  195. package/dist/agent-src/skills/prediction-pool-optimizer/reference/ev-fixtures.md +36 -35
  196. package/dist/agent-src/skills/prediction-pool-optimizer/reference/odds-and-bonus.md +45 -41
  197. package/dist/agent-src/skills/project-analysis-core/SKILL.md +4 -4
  198. package/dist/agent-src/skills/project-analysis-hypothesis-driven/SKILL.md +3 -3
  199. package/dist/agent-src/skills/project-analysis-react/SKILL.md +1 -1
  200. package/dist/agent-src/skills/project-analysis-symfony/SKILL.md +1 -1
  201. package/dist/agent-src/skills/project-analysis-zend-laminas/SKILL.md +2 -2
  202. package/dist/agent-src/skills/prompt-engineering-patterns/SKILL.md +1 -1
  203. package/dist/agent-src/skills/prompt-validator/SKILL.md +39 -39
  204. package/dist/agent-src/skills/quality-tools/SKILL.md +15 -15
  205. package/dist/agent-src/skills/react-shadcn-ui/SKILL.md +55 -19
  206. package/dist/agent-src/skills/react-shadcn-ui/reference/registry.md +29 -27
  207. package/dist/agent-src/skills/readme-writing-package/SKILL.md +2 -2
  208. package/dist/agent-src/skills/reasoning-orchestrator/SKILL.md +25 -25
  209. package/dist/agent-src/skills/recursive-verification/SKILL.md +6 -5
  210. package/dist/agent-src/skills/refine-prompt/SKILL.md +1 -1
  211. package/dist/agent-src/skills/refine-ticket/SKILL.md +20 -2
  212. package/dist/agent-src/skills/repomix-packer/SKILL.md +1 -1
  213. package/dist/agent-src/skills/requesting-code-review/SKILL.md +2 -2
  214. package/dist/agent-src/skills/roadmap-management/SKILL.md +80 -66
  215. package/dist/agent-src/skills/roadmap-writing/SKILL.md +84 -77
  216. package/dist/agent-src/skills/rule-refactor/SKILL.md +1 -1
  217. package/dist/agent-src/skills/screenshot-hygiene/evals/triggers.json +52 -0
  218. package/dist/agent-src/skills/security-audit/SKILL.md +26 -9
  219. package/dist/agent-src/skills/security-maturity-assessment/SKILL.md +38 -16
  220. package/dist/agent-src/skills/skill-improvement-pipeline/SKILL.md +14 -11
  221. package/dist/agent-src/skills/skill-writing/SKILL.md +9 -8
  222. package/dist/agent-src/skills/song-to-script/SKILL.md +93 -85
  223. package/dist/agent-src/skills/sql-writing/SKILL.md +2 -2
  224. package/dist/agent-src/skills/stakeholder-tradeoff/SKILL.md +4 -3
  225. package/dist/agent-src/skills/standards-from-config/SKILL.md +61 -43
  226. package/dist/agent-src/skills/subagent-orchestration/SKILL.md +22 -8
  227. package/dist/agent-src/skills/subagent-orchestration/prompts/README.md +28 -2
  228. package/dist/agent-src/skills/supply-chain-intake/SKILL.md +13 -13
  229. package/dist/agent-src/skills/systematic-debugging/SKILL.md +22 -21
  230. package/dist/agent-src/skills/tailwind-engineer/SKILL.md +1 -1
  231. package/dist/agent-src/skills/technical-specification/SKILL.md +5 -0
  232. package/dist/agent-src/skills/terraform/SKILL.md +2 -2
  233. package/dist/agent-src/skills/terragrunt/SKILL.md +8 -8
  234. package/dist/agent-src/skills/testing-anti-patterns/process-anti-patterns.md +1 -1
  235. package/dist/agent-src/skills/threat-modeling/SKILL.md +19 -13
  236. package/dist/agent-src/skills/universal-project-analysis/SKILL.md +1 -1
  237. package/dist/agent-src/skills/upstream-contribute/SKILL.md +0 -1
  238. package/dist/agent-src/skills/using-git-worktrees/SKILL.md +9 -9
  239. package/dist/agent-src/skills/validate-feature-fit/SKILL.md +3 -1
  240. package/dist/agent-src/skills/verify-completion-evidence/SKILL.md +4 -6
  241. package/dist/agent-src/skills/verify-repair-loop/SKILL.md +67 -61
  242. package/dist/agent-src/skills/video-director/SKILL.md +7 -7
  243. package/dist/agent-src/skills/worktree-lifecycle/SKILL.md +3 -3
  244. package/dist/agent-src/templates/agents/agent-project-settings.example.yml +1 -1
  245. package/dist/agent-src/templates/contexts/knowledge-pages.md +47 -45
  246. package/dist/agent-src/templates/contexts/lesson-card.md +2 -2
  247. package/dist/agent-src/templates/contexts/tenant-boundaries.md +2 -2
  248. package/dist/agent-src/templates/contexts.md +1 -1
  249. package/dist/agent-src/templates/features.md +1 -1
  250. package/dist/agent-src/templates/roadmaps.md +125 -116
  251. package/dist/agent-src/templates/rule.md +2 -1
  252. package/dist/agent-src/templates/scripts/pr_risk_review.ts +0 -0
  253. package/dist/agent-src/templates/scripts/telemetry/aggregator.ts +0 -0
  254. package/dist/agent-src/templates/scripts/tier_usage_report.ts +2 -2
  255. package/dist/agent-src/templates/scripts/work_engine/directives/ui/polish.ts +2 -2
  256. package/dist/agent-src/templates/scripts/work_engine/directives/ui/review.ts +1 -1
  257. package/dist/agent-src/user-types/README.md +8 -8
  258. package/dist/agent-src/user-types/galabau-field-crew.md +34 -33
  259. package/dist/agent-src/user-types/metalworking-shop.md +35 -34
  260. package/dist/agent-src/user-types/truck-driver.md +22 -20
  261. package/dist/cli/python/workspace_roles.js +2 -2
  262. package/dist/cli/python/workspace_roles.js.map +1 -1
  263. package/dist/discovery/deprecation-report.md +1 -1
  264. package/dist/discovery/discovery-manifest.json +88 -62
  265. package/dist/discovery/discovery-manifest.json.sha256 +1 -1
  266. package/dist/discovery/discovery-manifest.summary.md +3 -3
  267. package/dist/discovery/orphan-report.md +1 -1
  268. package/dist/discovery/packs.json +6 -5
  269. package/dist/discovery/trust-report.md +2 -2
  270. package/dist/discovery/workspaces.json +5 -4
  271. package/dist/hooks/dispatch.js +186 -12
  272. package/dist/install/install.mjs +8 -0
  273. package/dist/mcp/registry-manifest.json +3 -3
  274. package/dist/mcp/server.json +2 -2
  275. package/dist/mcp/server.mjs +1199 -857
  276. package/dist/router.json +1 -1
  277. package/dist/scripts/_lib/compile_time_toggles.js +48 -0
  278. package/dist/scripts/_lib/compile_time_toggles.js.map +1 -0
  279. package/dist/scripts/condense.js +234 -217
  280. package/dist/scripts/condense.js.map +1 -1
  281. package/dist/server/schemas/settings.js +4 -0
  282. package/dist/server/schemas/settings.js.map +1 -1
  283. package/dist/shared/userMd/utils.js +30 -0
  284. package/dist/shared/userMd/utils.js.map +1 -1
  285. package/dist/ui/assets/index-BpSQt5vm.js.map +1 -1
  286. package/docs/guidelines/agent-infra/api-cost-levers.md +56 -5
  287. package/docs/guidelines/agent-infra/simplicity-and-goal-demos.md +93 -33
  288. package/package.json +1 -1
  289. package/src/agent-src/templates/scripts/pr_risk_review.ts +0 -0
  290. package/src/agent-src/templates/scripts/telemetry/aggregator.ts +0 -0
  291. package/src/agent-src/templates/scripts/tier_usage_report.ts +2 -2
  292. package/src/agent-src/templates/scripts/work_engine/directives/ui/polish.ts +2 -2
  293. package/src/agent-src/templates/scripts/work_engine/directives/ui/review.ts +1 -1
  294. package/src/config/agent-settings.template.yml +32 -2
  295. package/src/config/ci-local-parity.yml +142 -0
  296. package/src/config/gate-coverage.yml +127 -0
  297. package/src/config/preamble-payload-budget.json +44 -0
  298. package/src/scripts/_cli/cmd_doctor.ts +78 -2
  299. package/src/scripts/_lib/agent_user_profile.ts +381 -0
  300. package/src/scripts/_lib/agents_overlay.ts +9 -0
  301. package/src/scripts/_lib/anchor_eval.ts +311 -0
  302. package/src/scripts/_lib/cc_transcript.ts +316 -0
  303. package/src/scripts/_lib/compile_time_toggles.ts +79 -0
  304. package/src/scripts/_lib/confusables.ts +101 -0
  305. package/src/scripts/_lib/duplicate_scope_census.ts +77 -0
  306. package/src/scripts/_lib/managed_agents_folder.ts +181 -0
  307. package/src/scripts/_lib/payload_hash_drift.ts +126 -0
  308. package/src/scripts/_lib/preservation_migration.ts +291 -0
  309. package/src/scripts/_lib/retrieval_sanitize.ts +166 -2
  310. package/src/scripts/_lib/scan_scope.ts +115 -0
  311. package/src/scripts/_lib/user_global_memory_audit.ts +187 -0
  312. package/src/scripts/_lib/user_global_observations.ts +830 -0
  313. package/src/scripts/_lib/user_global_revocations.ts +110 -0
  314. package/src/scripts/_lib/user_memory_gate_counters.ts +291 -0
  315. package/src/scripts/ai_council/blind_review.ts +0 -0
  316. package/src/scripts/ai_council/budget_guard.ts +90 -11
  317. package/src/scripts/ai_council/bundler.ts +2 -2
  318. package/src/scripts/ai_council/clients.ts +59 -3
  319. package/src/scripts/ai_council/config.ts +38 -0
  320. package/src/scripts/ai_council/orchestrator.ts +54 -9
  321. package/src/scripts/ai_team/team_dispatch.ts +17 -6
  322. package/src/scripts/anchor_eval_falsify.ts +198 -0
  323. package/src/scripts/anchor_scoring_run.ts +239 -0
  324. package/src/scripts/annotate_discovery.ts +1 -65
  325. package/src/scripts/bench_quality_run.ts +168 -4
  326. package/src/scripts/cache_realization_report.ts +782 -0
  327. package/src/scripts/check_artefact_count_messaging.ts +5 -1
  328. package/src/scripts/check_augment_description_cap.ts +15 -4
  329. package/src/scripts/check_ci_local_parity.ts +317 -0
  330. package/src/scripts/check_condensation.ts +96 -191
  331. package/src/scripts/check_context_paths.ts +38 -9
  332. package/src/scripts/check_gate_coverage.ts +299 -0
  333. package/src/scripts/check_iron_law_prominence.ts +22 -1
  334. package/src/scripts/check_kernel_prefix_stability.ts +0 -0
  335. package/src/scripts/check_no_new_legacy_path.ts +16 -6
  336. package/src/scripts/check_no_roadmap_refs.ts +22 -9
  337. package/src/scripts/check_originality_freshness.ts +167 -0
  338. package/src/scripts/check_preamble_payload_budget.ts +130 -0
  339. package/src/scripts/check_proposal.ts +0 -0
  340. package/src/scripts/check_references.ts +0 -1
  341. package/src/scripts/check_safety_floor_untouched.ts +171 -24
  342. package/src/scripts/check_site_links.ts +62 -3
  343. package/src/scripts/ci_status.ts +0 -0
  344. package/src/scripts/cluster_near_miss_patterns.ts +0 -0
  345. package/src/scripts/code_graph/build.ts +0 -0
  346. package/src/scripts/command_suggester/types.ts +0 -0
  347. package/src/scripts/compile_router.ts +10 -14
  348. package/src/scripts/condense.sh +3 -4
  349. package/src/scripts/condense.ts +247 -228
  350. package/src/scripts/cost/track.mjs +168 -33
  351. package/src/scripts/cost_summary.ts +33 -1
  352. package/src/scripts/council_cli.ts +45 -3
  353. package/src/scripts/discovery_graph.ts +0 -0
  354. package/src/scripts/encoding_corpus.ts +500 -0
  355. package/src/scripts/encoding_corpus_report.ts +216 -0
  356. package/src/scripts/generate_index.ts +19 -2
  357. package/src/scripts/install-hooks.sh +2 -2
  358. package/src/scripts/learning_sidecar.ts +0 -0
  359. package/src/scripts/lint_confusables.ts +10 -72
  360. package/src/scripts/lint_featured_skills.ts +0 -0
  361. package/src/scripts/lint_hidden_unicode.ts +208 -0
  362. package/src/scripts/lint_load_context.ts +17 -5
  363. package/src/scripts/lint_new_skill_gate.ts +9 -3
  364. package/src/scripts/lint_no_python_twin_rationale.ts +17 -2
  365. package/src/scripts/lint_originality.ts +1 -1
  366. package/src/scripts/lint_skill_originality.ts +1 -1
  367. package/src/scripts/lint_ticket_buildable.ts +1 -1
  368. package/src/scripts/mcp_server/tools.ts +4 -4
  369. package/src/scripts/measure_scope_dedup.ts +224 -0
  370. package/src/scripts/memory_lookup.ts +0 -0
  371. package/src/scripts/mine_session.ts +98 -0
  372. package/src/scripts/orchestration_payload_hash_drift.ts +145 -0
  373. package/src/scripts/preamble_byte_census.ts +574 -0
  374. package/src/scripts/probe_skill_registration.ts +2 -2
  375. package/src/scripts/redact_hook_capture.ts +13 -0
  376. package/src/scripts/release.ts +65 -10
  377. package/src/scripts/router_telemetry.ts +1 -1
  378. package/src/scripts/second_brain_retrieval.ts +14 -4
  379. package/src/scripts/skill_linter.ts +5 -0
  380. package/src/scripts/surface-tiers.yml +2 -0
  381. package/src/scripts/validate_pack_yaml.ts +0 -0
  382. package/src/server/schemas/settings.ts +8 -0
  383. package/src/shared/userMd/utils.ts +31 -0
  384. package/dist/agent-src/rules/telegraph-speak.md +0 -87
@@ -0,0 +1,574 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Preamble byte census — attributes the measured subagent cold-start payload
4
+ * to named sources (`road-to-cache-economy.md` Phase 3,
5
+ * steps 1-2): user-scope rules, project-scope rules, the CLAUDE.md
6
+ * hierarchy (project + user + `@`-imports + `CLAUDE.local.md`), the global
7
+ * user `profile.md` (road-to-global-user-memory), and the preloaded skills
8
+ * catalog (name + `description` frontmatter, the shape the host actually
9
+ * injects — verified against this repo's own skill-catalog listing).
10
+ *
11
+ * Everything NOT independently file-measurable — the host's raw
12
+ * tool-definition JSON and the per-spawn dispatch-prompt text — is reported
13
+ * as ONE labelled residual: measured_cold_start_median minus the sum of the
14
+ * file-measurable buckets above. That is disclosed, not hidden: no local
15
+ * transcript or file carries the request's system/tool payload (verified —
16
+ * `~/.claude/projects/**\/*.jsonl` records only `message.usage` counts and
17
+ * response content; a raw scan of a real transcript file's top-level keys
18
+ * turned up no `system`, `tools`, or prompt-body field). Because the
19
+ * residual is defined as the gap, the "buckets sum to the measured median"
20
+ * check is trivially satisfied BY CONSTRUCTION once a residual exists — this
21
+ * is stated plainly in the report rather than presented as an independent
22
+ * confirmation. The independently interesting number is what SHARE of the
23
+ * median the file-measurable buckets cover on their own.
24
+ *
25
+ * Also reports the MODELLED (never "measured") reduction from removing the
26
+ * duplicate-scope copy the C-2 census already finds — see
27
+ * `_lib/duplicate_scope_census.ts`, reused here rather than reimplemented.
28
+ *
29
+ * Class A (per the ADR-124 no-runtime-boundary contract): in-process,
30
+ * per-invocation, no socket, no daemon, no network. Reads local files
31
+ * (rules, CLAUDE.md hierarchy, skill frontmatter, transcripts) only.
32
+ *
33
+ * Usage:
34
+ * ./scripts-run src/scripts/preamble_byte_census [--format text|json]
35
+ * [--repo-root <path>] [--user-home <path>] [--user-rules-dir <path>]
36
+ * [--project-rules-dir <path>] [--skills-dir <path>]
37
+ * [--root <path>] [--max-age-days <n>]
38
+ */
39
+ import * as fs from 'node:fs';
40
+ import { homedir } from 'node:os';
41
+ import * as path from 'node:path';
42
+ import { fileURLToPath, pathToFileURL } from 'node:url';
43
+
44
+ import * as YAML from 'yaml';
45
+
46
+ import { resolveGlobalProfilePath } from './_lib/agent_user_profile.js';
47
+ import { DEFAULT_PROJECTS_ROOT, scanTranscripts } from './_lib/cc_transcript.js';
48
+ import { censusDuplicateScope } from './_lib/duplicate_scope_census.js';
49
+ import { computeColdStarts } from './cache_realization_report.js';
50
+
51
+ const _HERE = fileURLToPath(import.meta.url);
52
+ const REPO_ROOT = path.resolve(path.dirname(_HERE), '..', '..');
53
+ const CHARS_PER_TOKEN = 4;
54
+
55
+ // A sum within this tolerance of the measured median counts as "reconciled" —
56
+ // mirrors the roadmap's own ±10% verify line. See the module doc comment for
57
+ // why this is trivially satisfied once the residual bucket exists.
58
+ const SUM_TOLERANCE_PCT = 0.1;
59
+
60
+ function tokensFromChars(chars: number): number {
61
+ return chars / CHARS_PER_TOKEN;
62
+ }
63
+
64
+ function readCharsIfExists(p: string): number {
65
+ try {
66
+ return fs.statSync(p).size;
67
+ } catch {
68
+ return 0;
69
+ }
70
+ }
71
+
72
+ // ── source 1/2: rule directories ────────────────────────────────────────
73
+
74
+ export interface RuleDirCensus {
75
+ files: number;
76
+ chars: number;
77
+ }
78
+
79
+ export function censusRuleDir(dir: string): RuleDirCensus {
80
+ if (!fs.existsSync(dir)) return { files: 0, chars: 0 };
81
+ let files = 0;
82
+ let chars = 0;
83
+ for (const name of fs.readdirSync(dir)) {
84
+ if (!name.endsWith('.md')) continue;
85
+ try {
86
+ chars += fs.statSync(path.join(dir, name)).size;
87
+ files += 1;
88
+ } catch {
89
+ // Unreadable entry — skip rather than fail the whole census.
90
+ }
91
+ }
92
+ return { files, chars };
93
+ }
94
+
95
+ export interface PerRuleCost {
96
+ file: string;
97
+ chars: number;
98
+ tokens_estimate: number;
99
+ }
100
+
101
+ /** Top `limit` `.md` files in `dir` by byte size, descending — the per-rule per-spawn cost list (step 2). */
102
+ // A candidate list, not a verdict: routing a rule to dormancy goes through
103
+ // _lib/compile_time_toggles.ts (see its "dormancy routing" header) and needs an
104
+ // output-side bench first. Cost alone never justifies a flip.
105
+ export function topRulesByCost(dir: string, limit = 10): PerRuleCost[] {
106
+ if (!fs.existsSync(dir)) return [];
107
+ const entries: PerRuleCost[] = [];
108
+ for (const name of fs.readdirSync(dir)) {
109
+ if (!name.endsWith('.md')) continue;
110
+ let chars: number;
111
+ try {
112
+ chars = fs.statSync(path.join(dir, name)).size;
113
+ } catch {
114
+ continue;
115
+ }
116
+ entries.push({ file: name, chars, tokens_estimate: tokensFromChars(chars) });
117
+ }
118
+ entries.sort((a, b) => b.chars - a.chars || a.file.localeCompare(b.file));
119
+ return entries.slice(0, limit);
120
+ }
121
+
122
+ // ── source 3: CLAUDE.md hierarchy (project + user + @-imports + local) ──
123
+
124
+ export interface ClaudeMdCensus {
125
+ project_claude_md_chars: number;
126
+ project_claude_md_present: boolean;
127
+ project_claude_local_md_chars: number;
128
+ project_claude_local_md_present: boolean;
129
+ user_claude_md_chars: number;
130
+ user_claude_md_present: boolean;
131
+ /** Files pulled in by a top-level `@<path>` import line in the user CLAUDE.md. */
132
+ user_imports: { file: string; chars: number }[];
133
+ }
134
+
135
+ /** `@<path>` import lines, one per line, at the START of a line (Claude Code's own import syntax). */
136
+ const IMPORT_LINE_RE = /^@(\S+)\s*$/;
137
+
138
+ function parseClaudeMdImports(claudeMdPath: string): { file: string; chars: number }[] {
139
+ let text: string;
140
+ try {
141
+ text = fs.readFileSync(claudeMdPath, 'utf-8');
142
+ } catch {
143
+ return [];
144
+ }
145
+ const base = path.dirname(claudeMdPath);
146
+ const out: { file: string; chars: number }[] = [];
147
+ for (const line of text.split('\n')) {
148
+ const m = IMPORT_LINE_RE.exec(line.trim());
149
+ if (!m) continue;
150
+ const rel = m[1] as string;
151
+ const resolved = path.isAbsolute(rel) ? rel : path.join(base, rel);
152
+ const chars = readCharsIfExists(resolved);
153
+ if (chars > 0) out.push({ file: rel, chars });
154
+ }
155
+ return out;
156
+ }
157
+
158
+ export function censusClaudeMdHierarchy(repoRoot: string, userHome: string): ClaudeMdCensus {
159
+ const projectClaudeMd = path.join(repoRoot, 'CLAUDE.md');
160
+ const projectClaudeLocalMd = path.join(repoRoot, 'CLAUDE.local.md');
161
+ const userClaudeMd = path.join(userHome, '.claude', 'CLAUDE.md');
162
+
163
+ return {
164
+ project_claude_md_chars: readCharsIfExists(projectClaudeMd),
165
+ project_claude_md_present: fs.existsSync(projectClaudeMd),
166
+ project_claude_local_md_chars: readCharsIfExists(projectClaudeLocalMd),
167
+ project_claude_local_md_present: fs.existsSync(projectClaudeLocalMd),
168
+ user_claude_md_chars: readCharsIfExists(userClaudeMd),
169
+ user_claude_md_present: fs.existsSync(userClaudeMd),
170
+ user_imports: parseClaudeMdImports(userClaudeMd),
171
+ };
172
+ }
173
+
174
+ // ── source 4: global user profile.md (road-to-global-user-memory) ───────
175
+
176
+ export interface GlobalProfileCensus {
177
+ present: boolean;
178
+ chars: number;
179
+ path: string | null;
180
+ }
181
+
182
+ /**
183
+ * `resolveGlobalProfilePath` returns `null` when the layer hasn't landed /
184
+ * isn't written yet — treated as 0, per the roadmap's own honesty caveat.
185
+ * `env` is injectable so tests never touch this machine's real
186
+ * `~/.event4u/agent-config` — see `agent_user_profile.ts`.
187
+ */
188
+ export function censusGlobalProfile(env?: Parameters<typeof resolveGlobalProfilePath>[0]): GlobalProfileCensus {
189
+ const p = resolveGlobalProfilePath(env);
190
+ if (p === null) return { present: false, chars: 0, path: null };
191
+ return { present: true, chars: readCharsIfExists(p), path: p };
192
+ }
193
+
194
+ // ── source 5: preloaded skills catalog (name + description) ─────────────
195
+
196
+ export interface SkillsCatalogCensus {
197
+ skills: number;
198
+ chars: number;
199
+ }
200
+
201
+ interface RawSkillFrontmatter {
202
+ name?: unknown;
203
+ description?: unknown;
204
+ }
205
+
206
+ function parseFrontmatter(text: string): RawSkillFrontmatter {
207
+ if (!text.startsWith('---')) return {};
208
+ const end = text.indexOf('\n---', 3);
209
+ if (end === -1) return {};
210
+ const block = text.slice(3, end);
211
+ try {
212
+ const parsed: unknown = YAML.parse(block);
213
+ return typeof parsed === 'object' && parsed !== null ? (parsed as RawSkillFrontmatter) : {};
214
+ } catch {
215
+ return {};
216
+ }
217
+ }
218
+
219
+ /**
220
+ * Sums `- <name>: <description>\n` across every `SKILL.md` under `skillsDir`
221
+ * — the shape the host's own skill-catalog listing uses (verified against
222
+ * this session's own system-reminder catalog). This is the description-text
223
+ * component only; the exact on-wire bullet/wrapping format the host applies
224
+ * on top is not itself file-measurable, so this is a lower-bound estimate,
225
+ * stated as such wherever it is reported.
226
+ */
227
+ export function censusSkillsCatalog(skillsDir: string): SkillsCatalogCensus {
228
+ if (!fs.existsSync(skillsDir)) return { skills: 0, chars: 0 };
229
+ let skills = 0;
230
+ let chars = 0;
231
+ for (const entry of fs.readdirSync(skillsDir, { withFileTypes: true })) {
232
+ if (!entry.isDirectory()) continue;
233
+ const skillMd = path.join(skillsDir, entry.name, 'SKILL.md');
234
+ let text: string;
235
+ try {
236
+ text = fs.readFileSync(skillMd, 'utf-8');
237
+ } catch {
238
+ continue;
239
+ }
240
+ const fm = parseFrontmatter(text);
241
+ const name = typeof fm.name === 'string' && fm.name.length > 0 ? fm.name : entry.name;
242
+ const description = typeof fm.description === 'string' ? fm.description : '';
243
+ chars += `- ${name}: ${description}\n`.length;
244
+ skills += 1;
245
+ }
246
+ return { skills, chars };
247
+ }
248
+
249
+ // ── report assembly ───────────────────────────────────────────────────────
250
+
251
+ export interface ByteCensusSource {
252
+ name: string;
253
+ files: number;
254
+ chars: number;
255
+ tokens_estimate: number;
256
+ /** Estimate vs residual — see module doc comment. */
257
+ provenance: 'measured_local_file' | 'residual';
258
+ /** How this figure was derived — mandatory for anything not a plain file-size sum. */
259
+ basis: string;
260
+ }
261
+
262
+ export interface ByteCensus {
263
+ sources: ByteCensusSource[];
264
+ measurable_tokens_total: number;
265
+ /** Includes the residual bucket — always ≈ measured_cold_start_median by construction (see module doc comment). */
266
+ grand_total_tokens: number;
267
+ measured_cold_start_median: number | null;
268
+ cold_start_legs: number;
269
+ /** measurable_tokens_total / measured_cold_start_median — the honest, non-tautological number. */
270
+ measurable_share_of_median: number | null;
271
+ within_tolerance: boolean | null;
272
+ top_rules_by_cost: PerRuleCost[];
273
+ duplicate_scope: {
274
+ evaluable: boolean;
275
+ reason?: string | undefined;
276
+ shared_filenames: number;
277
+ duplicate_tokens_per_spawn: number;
278
+ };
279
+ /** MODELLED, never measured — see module doc comment and the `modelled` label on every field here. */
280
+ modelled_duplicate_removal: {
281
+ applicable: boolean;
282
+ reason?: string | undefined;
283
+ modelled_new_median: number | null;
284
+ modelled_reduction_pct: number | null;
285
+ };
286
+ }
287
+
288
+ export interface Options {
289
+ format: 'text' | 'json';
290
+ repoRoot: string;
291
+ userHome: string;
292
+ userRulesDir: string;
293
+ projectRulesDir: string;
294
+ skillsDir: string;
295
+ root: string;
296
+ maxAgeDays: number;
297
+ }
298
+
299
+ function defaultOptions(): Options {
300
+ const userHome = homedir();
301
+ return {
302
+ format: 'text',
303
+ repoRoot: REPO_ROOT,
304
+ userHome,
305
+ userRulesDir: path.join(userHome, '.claude', 'rules'),
306
+ projectRulesDir: path.join(REPO_ROOT, 'dist', 'agent-src', 'rules'),
307
+ skillsDir: path.join(REPO_ROOT, 'dist', 'agent-src', 'skills'),
308
+ root: DEFAULT_PROJECTS_ROOT,
309
+ maxAgeDays: 14,
310
+ };
311
+ }
312
+
313
+ export function parseArgs(argv: string[]): Options {
314
+ const opts = defaultOptions();
315
+ for (let i = 0; i < argv.length; i++) {
316
+ const a = argv[i];
317
+ if (a === undefined) continue;
318
+ if (a === '--format') opts.format = (argv[++i] as Options['format']) ?? opts.format;
319
+ else if (a.startsWith('--format=')) opts.format = a.slice('--format='.length) as Options['format'];
320
+ else if (a === '--repo-root') opts.repoRoot = argv[++i] ?? opts.repoRoot;
321
+ else if (a.startsWith('--repo-root=')) opts.repoRoot = a.slice('--repo-root='.length);
322
+ else if (a === '--user-home') opts.userHome = argv[++i] ?? opts.userHome;
323
+ else if (a.startsWith('--user-home=')) opts.userHome = a.slice('--user-home='.length);
324
+ else if (a === '--user-rules-dir') opts.userRulesDir = argv[++i] ?? opts.userRulesDir;
325
+ else if (a.startsWith('--user-rules-dir=')) opts.userRulesDir = a.slice('--user-rules-dir='.length);
326
+ else if (a === '--project-rules-dir') opts.projectRulesDir = argv[++i] ?? opts.projectRulesDir;
327
+ else if (a.startsWith('--project-rules-dir=')) opts.projectRulesDir = a.slice('--project-rules-dir='.length);
328
+ else if (a === '--skills-dir') opts.skillsDir = argv[++i] ?? opts.skillsDir;
329
+ else if (a.startsWith('--skills-dir=')) opts.skillsDir = a.slice('--skills-dir='.length);
330
+ else if (a === '--root') opts.root = argv[++i] ?? opts.root;
331
+ else if (a.startsWith('--root=')) opts.root = a.slice('--root='.length);
332
+ else if (a === '--max-age-days') opts.maxAgeDays = Number(argv[++i]) || opts.maxAgeDays;
333
+ else if (a.startsWith('--max-age-days=')) opts.maxAgeDays = Number(a.slice('--max-age-days='.length)) || opts.maxAgeDays;
334
+ }
335
+ if (opts.format !== 'text' && opts.format !== 'json') opts.format = 'text';
336
+ return opts;
337
+ }
338
+
339
+ /**
340
+ * Assembles the full census from already-computed measurements — pure, so
341
+ * tests can supply synthetic figures without touching real transcripts or
342
+ * this machine's `~/.claude`.
343
+ */
344
+ export function buildByteCensus(opts: {
345
+ userRules: RuleDirCensus;
346
+ projectRules: RuleDirCensus;
347
+ claudeMd: ClaudeMdCensus;
348
+ globalProfile: GlobalProfileCensus;
349
+ skillsCatalog: SkillsCatalogCensus;
350
+ topRules: PerRuleCost[];
351
+ duplicateScope: ReturnType<typeof censusDuplicateScope>;
352
+ measuredColdStartMedian: number | null;
353
+ coldStartLegs: number;
354
+ }): ByteCensus {
355
+ const claudeMdChars =
356
+ opts.claudeMd.project_claude_md_chars +
357
+ opts.claudeMd.project_claude_local_md_chars +
358
+ opts.claudeMd.user_claude_md_chars +
359
+ opts.claudeMd.user_imports.reduce((s, i) => s + i.chars, 0);
360
+ const claudeMdFiles =
361
+ (opts.claudeMd.project_claude_md_present ? 1 : 0) +
362
+ (opts.claudeMd.project_claude_local_md_present ? 1 : 0) +
363
+ (opts.claudeMd.user_claude_md_present ? 1 : 0) +
364
+ opts.claudeMd.user_imports.length;
365
+
366
+ const sources: ByteCensusSource[] = [
367
+ {
368
+ name: 'user-scope rules (~/.claude/rules/*.md)',
369
+ files: opts.userRules.files,
370
+ chars: opts.userRules.chars,
371
+ tokens_estimate: tokensFromChars(opts.userRules.chars),
372
+ provenance: 'measured_local_file',
373
+ basis: 'Σ byte size of every .md file in the user-scope rules directory, chars/4.',
374
+ },
375
+ {
376
+ name: 'project-scope rules (dist/agent-src/rules/*.md)',
377
+ files: opts.projectRules.files,
378
+ chars: opts.projectRules.chars,
379
+ tokens_estimate: tokensFromChars(opts.projectRules.chars),
380
+ provenance: 'measured_local_file',
381
+ basis: 'Σ byte size of every .md file in the project-scope rules directory, chars/4.',
382
+ },
383
+ {
384
+ name: 'CLAUDE.md hierarchy (project + project-local + user + user @-imports)',
385
+ files: claudeMdFiles,
386
+ chars: claudeMdChars,
387
+ tokens_estimate: tokensFromChars(claudeMdChars),
388
+ provenance: 'measured_local_file',
389
+ basis:
390
+ 'Byte size of project CLAUDE.md + project CLAUDE.local.md (if present) + user ~/.claude/CLAUDE.md ' +
391
+ '+ every file pulled in by a top-level "@<path>" import line in the user CLAUDE.md, chars/4.',
392
+ },
393
+ {
394
+ name: 'global user profile.md (road-to-global-user-memory)',
395
+ files: opts.globalProfile.present ? 1 : 0,
396
+ chars: opts.globalProfile.chars,
397
+ tokens_estimate: tokensFromChars(opts.globalProfile.chars),
398
+ provenance: 'measured_local_file',
399
+ basis: opts.globalProfile.present
400
+ ? `Byte size of ${opts.globalProfile.path as string}, chars/4.`
401
+ : 'Layer not written yet on this machine (resolveGlobalProfilePath() returned null) — treated as 0, per the roadmap\'s own honesty caveat.',
402
+ },
403
+ {
404
+ name: 'preloaded skills catalog (name + description, dist/agent-src/skills)',
405
+ files: opts.skillsCatalog.skills,
406
+ chars: opts.skillsCatalog.chars,
407
+ tokens_estimate: tokensFromChars(opts.skillsCatalog.chars),
408
+ provenance: 'measured_local_file',
409
+ basis:
410
+ 'Σ "- <name>: <description>\\n" over every SKILL.md frontmatter, chars/4 — the description-text ' +
411
+ 'component only; the host\'s exact on-wire catalog format is not independently file-measurable.',
412
+ },
413
+ ];
414
+
415
+ const measurableTokensTotal = sources.reduce((s, src) => s + src.tokens_estimate, 0);
416
+ const median = opts.measuredColdStartMedian;
417
+ const residualTokens = median !== null ? Math.max(0, median - measurableTokensTotal) : null;
418
+
419
+ if (residualTokens !== null) {
420
+ sources.push({
421
+ name: 'tool definitions + dispatch prompt (residual)',
422
+ files: 0,
423
+ chars: 0,
424
+ tokens_estimate: residualTokens,
425
+ provenance: 'residual',
426
+ basis:
427
+ 'measured_cold_start_median minus the sum of the file-measurable buckets above. No local transcript ' +
428
+ 'or file carries the request\'s raw tool-definition JSON or the per-spawn dispatch-prompt text ' +
429
+ '(verified: ~/.claude/projects/**/*.jsonl records only message.usage counts and response content, ' +
430
+ 'never the request system/tool payload) — this bucket exists so the gap is named rather than silently dropped.',
431
+ });
432
+ }
433
+
434
+ const grandTotal = sources.reduce((s, src) => s + src.tokens_estimate, 0);
435
+ const measurableShare = median !== null && median > 0 ? measurableTokensTotal / median : null;
436
+ const withinTolerance = median !== null ? Math.abs(grandTotal - median) / Math.max(1, median) <= SUM_TOLERANCE_PCT : null;
437
+
438
+ const dup = opts.duplicateScope;
439
+ let modelledNewMedian: number | null = null;
440
+ let modelledReductionPct: number | null = null;
441
+ let modelledApplicable = false;
442
+ let modelledReason: string | undefined;
443
+ if (median === null) {
444
+ modelledReason = 'no measured cold-start median available in this window';
445
+ } else if (!dup.evaluable) {
446
+ modelledReason = dup.reason ?? 'duplicate-scope census not evaluable';
447
+ } else {
448
+ modelledApplicable = true;
449
+ modelledNewMedian = Math.max(0, median - dup.duplicate_chars / CHARS_PER_TOKEN);
450
+ modelledReductionPct = median > 0 ? (median - modelledNewMedian) / median : 0;
451
+ }
452
+
453
+ return {
454
+ sources,
455
+ measurable_tokens_total: measurableTokensTotal,
456
+ grand_total_tokens: grandTotal,
457
+ measured_cold_start_median: median,
458
+ cold_start_legs: opts.coldStartLegs,
459
+ measurable_share_of_median: measurableShare,
460
+ within_tolerance: withinTolerance,
461
+ top_rules_by_cost: opts.topRules,
462
+ duplicate_scope: {
463
+ evaluable: dup.evaluable,
464
+ reason: dup.reason,
465
+ shared_filenames: dup.shared_filenames.length,
466
+ duplicate_tokens_per_spawn: dup.evaluable ? dup.duplicate_chars / CHARS_PER_TOKEN : 0,
467
+ },
468
+ modelled_duplicate_removal: {
469
+ applicable: modelledApplicable,
470
+ reason: modelledReason,
471
+ modelled_new_median: modelledNewMedian,
472
+ modelled_reduction_pct: modelledReductionPct,
473
+ },
474
+ };
475
+ }
476
+
477
+ export function buildReport(opts: Options): ByteCensus {
478
+ const userRules = censusRuleDir(opts.userRulesDir);
479
+ const projectRules = censusRuleDir(opts.projectRulesDir);
480
+ const claudeMd = censusClaudeMdHierarchy(opts.repoRoot, opts.userHome);
481
+ const globalProfile = censusGlobalProfile();
482
+ const skillsCatalog = censusSkillsCatalog(opts.skillsDir);
483
+ const topRules = topRulesByCost(opts.projectRulesDir, 10);
484
+ const duplicateScope = censusDuplicateScope(opts.userRulesDir, opts.projectRulesDir);
485
+
486
+ const scan = scanTranscripts({ root: opts.root, maxAgeDays: opts.maxAgeDays });
487
+ const coldStart = computeColdStarts(scan.records);
488
+ const measuredColdStartMedian = coldStart.legs > 0 ? coldStart.median_first_call_written_or_uncached : null;
489
+
490
+ return buildByteCensus({
491
+ userRules,
492
+ projectRules,
493
+ claudeMd,
494
+ globalProfile,
495
+ skillsCatalog,
496
+ topRules,
497
+ duplicateScope,
498
+ measuredColdStartMedian,
499
+ coldStartLegs: coldStart.legs,
500
+ });
501
+ }
502
+
503
+ function pct(v: number): string {
504
+ return `${(v * 100).toFixed(1)}%`;
505
+ }
506
+
507
+ export function renderText(r: ByteCensus): string {
508
+ const out: string[] = [];
509
+ out.push('Preamble byte census (road-to-cache-economy Phase 3, steps 1-2)');
510
+ out.push('');
511
+ out.push('Sources:');
512
+ for (const s of r.sources) {
513
+ out.push(` ${s.name}`);
514
+ out.push(` files=${s.files} chars=${s.chars} tokens_estimate=${Math.round(s.tokens_estimate)} [${s.provenance}]`);
515
+ out.push(` basis: ${s.basis}`);
516
+ }
517
+ out.push('');
518
+ out.push(`measurable_tokens_total (excludes residual): ${Math.round(r.measurable_tokens_total)}`);
519
+ out.push(`grand_total_tokens (includes residual): ${Math.round(r.grand_total_tokens)}`);
520
+ if (r.measured_cold_start_median !== null) {
521
+ out.push(`measured_cold_start_median: ${Math.round(r.measured_cold_start_median)} (${r.cold_start_legs} legs, this window)`);
522
+ out.push(`measurable_share_of_median: ${pct(r.measurable_share_of_median as number)} (the honest, non-tautological number)`);
523
+ out.push(
524
+ `sum check (grand_total vs median, ±10%): ${r.within_tolerance ? 'PASS' : 'FAIL'} — trivially PASS by ` +
525
+ 'construction once the residual bucket exists; see the module doc comment for why.',
526
+ );
527
+ } else {
528
+ out.push('measured_cold_start_median: pending — no subagent legs observed in this window; no residual computed.');
529
+ }
530
+ out.push('');
531
+ out.push('Top-10 project-scope rules by per-spawn token cost:');
532
+ for (const rule of r.top_rules_by_cost) {
533
+ out.push(` ${rule.file}: chars=${rule.chars} tokens_estimate=${Math.round(rule.tokens_estimate)}`);
534
+ }
535
+ out.push('');
536
+ out.push('Duplicate-scope census (C-2):');
537
+ if (r.duplicate_scope.evaluable) {
538
+ out.push(
539
+ ` ${r.duplicate_scope.shared_filenames} shared filename(s), ` +
540
+ `${Math.round(r.duplicate_scope.duplicate_tokens_per_spawn)} redundant tokens per spawn.`,
541
+ );
542
+ } else {
543
+ out.push(` not evaluable — ${r.duplicate_scope.reason ?? 'unknown reason'}`);
544
+ }
545
+ out.push('');
546
+ out.push('Modelled duplicate-copy removal (MODELLED, not measured):');
547
+ if (r.modelled_duplicate_removal.applicable) {
548
+ out.push(` modelled_new_median: ${Math.round(r.modelled_duplicate_removal.modelled_new_median as number)}`);
549
+ out.push(` modelled_reduction_pct: ${pct(r.modelled_duplicate_removal.modelled_reduction_pct as number)}`);
550
+ } else {
551
+ out.push(` not applicable — ${r.modelled_duplicate_removal.reason ?? 'unknown reason'}`);
552
+ }
553
+ out.push('');
554
+ out.push('The per-spawn payload ceiling (median ≤ 40k / p95 ≤ 50k) is a DOCUMENTED CANDIDATE, gated on C-3');
555
+ out.push('(preamble reducibility, still pending — no reduction intervention has landed). See');
556
+ out.push('docs/contracts/load-context-budget-model.md. This report does NOT enforce it.');
557
+ return out.join('\n');
558
+ }
559
+
560
+ export function main(argv: string[] = process.argv.slice(2)): number {
561
+ const opts = parseArgs(argv);
562
+ const report = buildReport(opts);
563
+ if (opts.format === 'json') {
564
+ process.stdout.write(JSON.stringify(report, null, 2) + '\n');
565
+ } else {
566
+ process.stdout.write(renderText(report) + '\n');
567
+ }
568
+ return 0;
569
+ }
570
+
571
+ if (process.argv[1] !== undefined) {
572
+ const invokedUrl = pathToFileURL(path.resolve(process.argv[1])).href;
573
+ if (import.meta.url === invokedUrl) process.exit(main());
574
+ }
@@ -416,7 +416,7 @@ export function run_probe(opts?: {
416
416
  // Group by (tool, skill_id). ≥ 2 entries → DUPLICATE.
417
417
  const by_key = new Map<string, Registration[]>();
418
418
  for (const reg of result.registrations) {
419
- const k = `${reg.tool}${reg.skill_id}`;
419
+ const k = `${reg.tool}\0${reg.skill_id}`;
420
420
  const arr = by_key.get(k) ?? [];
421
421
  arr.push(reg);
422
422
  by_key.set(k, arr);
@@ -426,7 +426,7 @@ export function run_probe(opts?: {
426
426
  if (regs.length < 2) {
427
427
  continue;
428
428
  }
429
- const [tool, skill_id] = composite.split('');
429
+ const [tool, skill_id] = composite.split('\0');
430
430
  const key = `${tool}:${skill_id}`;
431
431
  result.duplicates.set(key, regs);
432
432
  const hashes = new Set<string>();
@@ -51,6 +51,19 @@ const _USER_CONTENT_KEYS = new Set<string>([
51
51
  'submitted_prompt', 'submittedprompt',
52
52
  // Free-form transcript bodies (path stays — content is in another file)
53
53
  'transcript', 'transcript_text',
54
+ // Additive hardening (road-to-global-user-memory Phase 3, 2026-07-30):
55
+ // the global observation buffer's project-attribution footer
56
+ // (`user_global_observations.ts`'s `context.project_path` /
57
+ // `context.project_name` / `seen_in`) is a partial project map by
58
+ // design (see agents/settings/contexts/global-user-memory-cut.md § the
59
+ // replacement's own metadata surface) — if any tool call ever passes an
60
+ // observation object through as an argument, a hook capture of that
61
+ // call must not preserve these keys the way `_ENVELOPE_KEYS_KEEP`
62
+ // preserves genuinely structural fields like `cwd`. Reusing this file's
63
+ // existing key-name match (not a second redactor) mirrors the ADR-103
64
+ // hidden_unicode precedent: additive, and inputs without these keys are
65
+ // unaffected.
66
+ 'seen_in', 'project_path', 'project_name',
54
67
  ]);
55
68
 
56
69
  // Keys whose value is a structural / schema marker — keep as-is even when