@event4u/agent-config 1.19.0 → 1.21.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 (297) hide show
  1. package/.agent-src/commands/agent-handoff.md +14 -10
  2. package/.agent-src/commands/agents.md +1 -1
  3. package/.agent-src/commands/bug-fix.md +1 -1
  4. package/.agent-src/commands/bug-investigate.md +2 -2
  5. package/.agent-src/commands/chat-history/import.md +166 -0
  6. package/.agent-src/commands/chat-history/learn.md +178 -0
  7. package/.agent-src/commands/chat-history/show.md +17 -18
  8. package/.agent-src/commands/chat-history.md +26 -25
  9. package/.agent-src/commands/compress.md +12 -0
  10. package/.agent-src/commands/context/create.md +2 -2
  11. package/.agent-src/commands/context.md +1 -1
  12. package/.agent-src/commands/copilot-agents.md +1 -1
  13. package/.agent-src/commands/council/default.md +21 -12
  14. package/.agent-src/commands/council.md +1 -1
  15. package/.agent-src/commands/create-pr.md +28 -8
  16. package/.agent-src/commands/e2e-heal.md +1 -1
  17. package/.agent-src/commands/e2e-plan.md +1 -1
  18. package/.agent-src/commands/feature/dev.md +3 -3
  19. package/.agent-src/commands/feature.md +1 -1
  20. package/.agent-src/commands/fix/seeder.md +2 -2
  21. package/.agent-src/commands/fix.md +1 -1
  22. package/.agent-src/commands/jira-ticket.md +1 -1
  23. package/.agent-src/commands/judge.md +2 -2
  24. package/.agent-src/commands/memory.md +1 -1
  25. package/.agent-src/commands/mode.md +5 -5
  26. package/.agent-src/commands/module.md +1 -1
  27. package/.agent-src/commands/onboard.md +4 -4
  28. package/.agent-src/commands/optimize/augmentignore.md +1 -1
  29. package/.agent-src/commands/optimize-prompt.md +61 -0
  30. package/.agent-src/commands/optimize.md +1 -1
  31. package/.agent-src/commands/override.md +1 -1
  32. package/.agent-src/commands/review-changes.md +1 -1
  33. package/.agent-src/commands/review-routing.md +1 -1
  34. package/.agent-src/commands/roadmap.md +1 -1
  35. package/.agent-src/commands/set-cost-profile.md +3 -3
  36. package/.agent-src/commands/sync-agent-settings.md +2 -2
  37. package/.agent-src/commands/sync-gitignore.md +1 -1
  38. package/.agent-src/commands/tests/create.md +2 -2
  39. package/.agent-src/commands/tests.md +1 -1
  40. package/.agent-src/commands/threat-model.md +4 -4
  41. package/.agent-src/contexts/authority/commit-mechanics.md +14 -1
  42. package/.agent-src/contexts/authority/destructive-mechanics.md +14 -1
  43. package/.agent-src/contexts/authority/scope-mechanics.md +5 -0
  44. package/.agent-src/contexts/communication/rules-auto/guidelines-mechanics.md +76 -0
  45. package/.agent-src/contexts/communication/rules-auto/skill-quality-mechanics.md +76 -0
  46. package/.agent-src/contexts/communication/rules-auto/slash-command-routing-policy-mechanics.md +4 -4
  47. package/.agent-src/contexts/communication/rules-auto/think-before-action-mechanics.md +98 -0
  48. package/.agent-src/contexts/communication/rules-auto/token-efficiency-mechanics.md +93 -0
  49. package/.agent-src/contexts/communication/rules-auto/user-interaction-mechanics.md +125 -9
  50. package/.agent-src/contexts/execution/autonomy-mechanics.md +44 -0
  51. package/.agent-src/contexts/model-recommendations.md +2 -2
  52. package/.agent-src/contexts/override-system.md +1 -1
  53. package/.agent-src/personas/product-owner.md +2 -2
  54. package/.agent-src/personas/qa.md +1 -1
  55. package/.agent-src/rules/agent-authority.md +5 -6
  56. package/.agent-src/rules/agent-docs.md +11 -53
  57. package/.agent-src/rules/analysis-skill-routing.md +10 -40
  58. package/.agent-src/rules/architecture.md +6 -1
  59. package/.agent-src/rules/artifact-drafting-protocol.md +5 -0
  60. package/.agent-src/rules/artifact-engagement-recording.md +23 -59
  61. package/.agent-src/rules/ask-when-uncertain.md +24 -47
  62. package/.agent-src/rules/augment-portability.md +14 -62
  63. package/.agent-src/rules/augment-source-of-truth.md +10 -1
  64. package/.agent-src/rules/autonomous-execution.md +17 -98
  65. package/.agent-src/rules/capture-learnings.md +9 -80
  66. package/.agent-src/rules/cli-output-handling.md +12 -42
  67. package/.agent-src/rules/command-suggestion-policy.md +25 -73
  68. package/.agent-src/rules/commit-conventions.md +9 -58
  69. package/.agent-src/rules/commit-policy.md +16 -47
  70. package/.agent-src/rules/context-hygiene.md +5 -0
  71. package/.agent-src/rules/direct-answers.md +21 -42
  72. package/.agent-src/rules/docker-commands.md +11 -45
  73. package/.agent-src/rules/docs-sync.md +10 -56
  74. package/.agent-src/rules/downstream-changes.md +5 -0
  75. package/.agent-src/rules/e2e-testing.md +9 -44
  76. package/.agent-src/rules/guidelines.md +13 -75
  77. package/.agent-src/rules/improve-before-implement.md +10 -2
  78. package/.agent-src/rules/language-and-tone.md +35 -69
  79. package/.agent-src/rules/laravel-translations.md +11 -40
  80. package/.agent-src/rules/markdown-safe-codeblocks.md +4 -0
  81. package/.agent-src/rules/minimal-safe-diff.md +4 -0
  82. package/.agent-src/rules/missing-tool-handling.md +4 -0
  83. package/.agent-src/rules/model-recommendation.md +9 -61
  84. package/.agent-src/rules/no-attribution-footers.md +53 -0
  85. package/.agent-src/rules/no-cheap-questions.md +11 -27
  86. package/.agent-src/rules/no-council-references.md +76 -0
  87. package/.agent-src/rules/no-roadmap-references.md +8 -1
  88. package/.agent-src/rules/non-destructive-by-default.md +13 -43
  89. package/.agent-src/rules/onboarding-gate.md +9 -117
  90. package/.agent-src/rules/package-ci-checks.md +10 -37
  91. package/.agent-src/rules/php-coding.md +10 -55
  92. package/.agent-src/rules/preservation-guard.md +9 -0
  93. package/.agent-src/rules/review-routing-awareness.md +9 -97
  94. package/.agent-src/rules/reviewer-awareness.md +8 -83
  95. package/.agent-src/rules/roadmap-progress-sync.md +7 -170
  96. package/.agent-src/rules/role-mode-adherence.md +6 -2
  97. package/.agent-src/rules/rule-type-governance.md +8 -66
  98. package/.agent-src/rules/runtime-safety.md +5 -0
  99. package/.agent-src/rules/scope-control.md +17 -62
  100. package/.agent-src/rules/security-sensitive-stop.md +7 -1
  101. package/.agent-src/rules/size-enforcement.md +6 -1
  102. package/.agent-src/rules/skill-improvement-trigger.md +9 -49
  103. package/.agent-src/rules/skill-quality.md +7 -64
  104. package/.agent-src/rules/slash-command-routing-policy.md +11 -63
  105. package/.agent-src/rules/think-before-action.md +22 -87
  106. package/.agent-src/rules/token-efficiency.md +10 -74
  107. package/.agent-src/rules/token-optimizer-maintenance.md +68 -0
  108. package/.agent-src/rules/tool-safety.md +4 -0
  109. package/.agent-src/rules/ui-audit-gate.md +25 -61
  110. package/.agent-src/rules/upstream-proposal.md +9 -67
  111. package/.agent-src/rules/user-interaction.md +25 -95
  112. package/.agent-src/rules/verify-before-complete.md +1 -1
  113. package/.agent-src/skills/agent-docs-writing/SKILL.md +1 -1
  114. package/.agent-src/skills/ai-council/SKILL.md +69 -5
  115. package/.agent-src/skills/analysis-autonomous-mode/SKILL.md +1 -1
  116. package/.agent-src/skills/analysis-skill-router/SKILL.md +3 -3
  117. package/.agent-src/skills/artisan-commands/SKILL.md +2 -2
  118. package/.agent-src/skills/authz-review/SKILL.md +1 -1
  119. package/.agent-src/skills/aws-infrastructure/SKILL.md +5 -5
  120. package/.agent-src/skills/blast-radius-analyzer/SKILL.md +8 -8
  121. package/.agent-src/skills/bug-analyzer/SKILL.md +5 -5
  122. package/.agent-src/skills/code-refactoring/SKILL.md +4 -4
  123. package/.agent-src/skills/code-review/SKILL.md +2 -2
  124. package/.agent-src/skills/command-writing/SKILL.md +11 -0
  125. package/.agent-src/skills/composer-packages/SKILL.md +2 -2
  126. package/.agent-src/skills/context-authoring/SKILL.md +11 -0
  127. package/.agent-src/skills/context-document/SKILL.md +1 -1
  128. package/.agent-src/skills/copilot-agents-optimization/SKILL.md +23 -0
  129. package/.agent-src/skills/copilot-config/SKILL.md +1 -1
  130. package/.agent-src/skills/dcf-modeling/SKILL.md +89 -0
  131. package/.agent-src/skills/dependency-upgrade/SKILL.md +2 -2
  132. package/.agent-src/skills/devcontainer/SKILL.md +2 -2
  133. package/.agent-src/skills/developer-like-execution/SKILL.md +1 -1
  134. package/.agent-src/skills/docker/SKILL.md +1 -1
  135. package/.agent-src/skills/dto-creator/SKILL.md +1 -1
  136. package/.agent-src/skills/estimate-ticket/SKILL.md +2 -2
  137. package/.agent-src/skills/fe-design/SKILL.md +4 -4
  138. package/.agent-src/skills/feature-planning/SKILL.md +5 -5
  139. package/.agent-src/skills/funnel-analysis/SKILL.md +100 -0
  140. package/.agent-src/skills/laravel/SKILL.md +1 -1
  141. package/.agent-src/skills/laravel-notifications/SKILL.md +5 -5
  142. package/.agent-src/skills/laravel-pennant/SKILL.md +1 -1
  143. package/.agent-src/skills/laravel-pulse/SKILL.md +4 -4
  144. package/.agent-src/skills/laravel-reverb/SKILL.md +2 -2
  145. package/.agent-src/skills/laravel-scheduling/SKILL.md +1 -1
  146. package/.agent-src/skills/md-language-check/SKILL.md +1 -1
  147. package/.agent-src/skills/migration-creator/SKILL.md +7 -7
  148. package/.agent-src/skills/multi-tenancy/SKILL.md +8 -8
  149. package/.agent-src/skills/okr-tree-modeling/SKILL.md +93 -0
  150. package/.agent-src/skills/performance-analysis/SKILL.md +3 -3
  151. package/.agent-src/skills/pest-testing/SKILL.md +6 -6
  152. package/.agent-src/skills/php-service/SKILL.md +2 -2
  153. package/.agent-src/skills/project-analysis-hypothesis-driven/SKILL.md +3 -3
  154. package/.agent-src/skills/project-analysis-react/SKILL.md +1 -1
  155. package/.agent-src/skills/project-analysis-symfony/SKILL.md +1 -1
  156. package/.agent-src/skills/project-analysis-zend-laminas/SKILL.md +2 -2
  157. package/.agent-src/skills/project-analyzer/SKILL.md +4 -4
  158. package/.agent-src/skills/prompt-optimizer/SKILL.md +108 -0
  159. package/.agent-src/skills/readme-reviewer/SKILL.md +1 -1
  160. package/.agent-src/skills/rice-prioritization/SKILL.md +100 -0
  161. package/.agent-src/skills/rule-writing/SKILL.md +33 -0
  162. package/.agent-src/skills/sentry-integration/SKILL.md +1 -1
  163. package/.agent-src/skills/skill-writing/SKILL.md +14 -0
  164. package/.agent-src/skills/subagent-orchestration/SKILL.md +34 -2
  165. package/.agent-src/skills/terraform/SKILL.md +2 -2
  166. package/.agent-src/skills/terragrunt/SKILL.md +8 -8
  167. package/.agent-src/skills/test-performance/SKILL.md +5 -5
  168. package/.agent-src/skills/threat-modeling/SKILL.md +2 -2
  169. package/.agent-src/skills/token-optimizer/SKILL.md +110 -0
  170. package/.agent-src/skills/unit-economics-modeling/SKILL.md +104 -0
  171. package/.agent-src/skills/universal-project-analysis/SKILL.md +1 -1
  172. package/.agent-src/skills/using-git-worktrees/SKILL.md +1 -0
  173. package/.agent-src/templates/AGENTS.md +1 -1
  174. package/.agent-src/templates/agent-settings.md +25 -41
  175. package/.agent-src/templates/contexts/tenant-boundaries.md +2 -2
  176. package/.agent-src/templates/contexts.md +1 -1
  177. package/.agent-src/templates/copilot-instructions.md +21 -0
  178. package/.agent-src/templates/copilot-review-instructions.md +76 -0
  179. package/.agent-src/templates/features.md +1 -1
  180. package/.agent-src/templates/rule.md +127 -0
  181. package/.agent-src/templates/scripts/work_engine/hook_bootstrap.py +7 -5
  182. package/.agent-src/templates/scripts/work_engine/hooks/__init__.py +0 -4
  183. package/.agent-src/templates/scripts/work_engine/hooks/builtin/__init__.py +0 -4
  184. package/.agent-src/templates/scripts/work_engine/hooks/builtin/_chat_history_base.py +7 -51
  185. package/.agent-src/templates/scripts/work_engine/hooks/builtin/chat_history_append.py +1 -2
  186. package/.agent-src/templates/scripts/work_engine/hooks/builtin/chat_history_halt_append.py +1 -2
  187. package/.agent-src/templates/scripts/work_engine/hooks/builtin/memory_visibility.py +2 -3
  188. package/.agent-src/templates/skill.md +30 -1
  189. package/.claude-plugin/marketplace.json +11 -4
  190. package/AGENTS.md +71 -3
  191. package/CHANGELOG.md +180 -3
  192. package/README.md +24 -23
  193. package/config/agent-settings.template.yml +63 -23
  194. package/config/gitignore-block.txt +11 -4
  195. package/docs/architecture.md +84 -3
  196. package/docs/catalog.md +23 -11
  197. package/docs/contracts/adr-chat-history-split.md +10 -1
  198. package/docs/contracts/agent-memory-contract.md +1 -1
  199. package/docs/contracts/command-clusters.md +1 -1
  200. package/docs/contracts/context-paths.md +2 -1
  201. package/docs/contracts/cross-wing-handoff.md +133 -0
  202. package/docs/contracts/file-ownership-matrix.json +678 -609
  203. package/docs/contracts/hook-architecture-v1.md +8 -1
  204. package/docs/contracts/iron-law-overrides.txt +25 -0
  205. package/docs/contracts/kernel-membership.md +273 -0
  206. package/docs/contracts/load-context-schema.md +26 -11
  207. package/docs/contracts/memory-visibility-v1.md +8 -24
  208. package/docs/contracts/pilot/agent-authority.md +24 -0
  209. package/docs/contracts/pilot/direct-answers.md +70 -0
  210. package/docs/contracts/pilot/language-and-tone.md +63 -0
  211. package/docs/contracts/rule-classification.md +170 -0
  212. package/docs/contracts/rule-router.md +153 -0
  213. package/docs/customization.md +18 -7
  214. package/docs/decisions/ADR-001-kernel-swap-deferred.md +109 -0
  215. package/docs/decisions/ADR-002-kernel-bucket-overrides.md +124 -0
  216. package/docs/decisions/ADR-rule-kernel-and-router.md +122 -0
  217. package/docs/getting-started.md +19 -27
  218. package/docs/guidelines/agent-infra/ask-when-uncertain-demos.md +1 -1
  219. package/docs/guidelines/agent-infra/roadmap-progress-mechanics.md +176 -0
  220. package/docs/guidelines/agent-infra/rule-type-governance.md +73 -0
  221. package/docs/guidelines/agent-infra/size-and-scope.md +13 -2
  222. package/docs/guidelines/agent-infra/skill-quality-checklist.md +119 -0
  223. package/docs/guidelines/augment-portability-patterns.md +68 -0
  224. package/docs/guidelines/php/php-coding-patterns.md +62 -0
  225. package/docs/hook-payload-capture.md +221 -0
  226. package/docs/migrations/commands-1.15.0.md +17 -12
  227. package/docs/skills-catalog.md +5 -4
  228. package/llms.txt +4 -3
  229. package/package.json +1 -1
  230. package/scripts/_p43_bodies.py +235 -0
  231. package/scripts/_p43_compress.py +118 -0
  232. package/scripts/_p4_migrate.py +199 -0
  233. package/scripts/_pilot_council_question.py +57 -0
  234. package/scripts/_pilot_measure.py +53 -0
  235. package/scripts/agent-config +1 -1
  236. package/scripts/ai_council/_default_prices.py +4 -4
  237. package/scripts/ai_council/clients.py +1 -1
  238. package/scripts/ai_council/modes.py +3 -4
  239. package/scripts/ai_council/pricing.py +10 -9
  240. package/scripts/ai_council/session.py +107 -5
  241. package/scripts/build_linear_digest.py +3 -5
  242. package/scripts/build_rule_trigger_matrix.py +1 -9
  243. package/scripts/chat_history.py +952 -596
  244. package/scripts/check_always_budget.py +39 -6
  245. package/scripts/check_compressed_paths.py +213 -0
  246. package/scripts/check_compression.py +15 -0
  247. package/scripts/check_context_paths.py +1 -0
  248. package/scripts/check_council_layout.py +105 -0
  249. package/scripts/check_council_references.py +145 -0
  250. package/scripts/check_portability.py +2 -0
  251. package/scripts/check_references.py +14 -2
  252. package/scripts/check_token_optimizer_freshness.py +131 -0
  253. package/scripts/compile_router.py +148 -0
  254. package/scripts/compress.py +219 -11
  255. package/scripts/council_cli.py +63 -9
  256. package/scripts/council_prune.py +81 -0
  257. package/scripts/count_token_optimizer_usage.sh +54 -0
  258. package/scripts/hook_manifest.yaml +33 -0
  259. package/scripts/hooks/augment-chat-history.sh +10 -0
  260. package/scripts/hooks/cowork-dispatcher.sh +98 -0
  261. package/scripts/hooks/dispatch_hook.py +35 -0
  262. package/scripts/hooks_status.py +12 -1
  263. package/scripts/install-hooks.sh +2 -2
  264. package/scripts/install.sh +81 -2
  265. package/scripts/iron_law_sha.py +98 -0
  266. package/scripts/lint_handoffs.py +214 -0
  267. package/scripts/lint_hook_manifest.py +2 -1
  268. package/scripts/lint_load_context.py +35 -5
  269. package/scripts/measure_rule_budget.py +314 -0
  270. package/scripts/prototype_lint_contradictions.py +150 -0
  271. package/scripts/redact_hook_capture.py +148 -0
  272. package/scripts/schemas/rule.schema.json +55 -6
  273. package/scripts/schemas/skill.schema.json +5 -0
  274. package/scripts/skill_linter.py +359 -7
  275. package/scripts/smoke_path_resolution.py +93 -0
  276. package/scripts/update_prices.py +3 -3
  277. package/scripts/validate_frontmatter.py +41 -1
  278. package/.agent-src/commands/chat-history/checkpoint.md +0 -126
  279. package/.agent-src/commands/chat-history/clear.md +0 -103
  280. package/.agent-src/commands/chat-history/resume.md +0 -183
  281. package/.agent-src/contexts/communication/rules-auto/artifact-engagement-recording-mechanics.md +0 -72
  282. package/.agent-src/contexts/communication/rules-auto/augment-portability-mechanics.md +0 -79
  283. package/.agent-src/contexts/communication/rules-auto/cli-output-handling-mechanics.md +0 -87
  284. package/.agent-src/contexts/communication/rules-auto/command-suggestion-policy-mechanics.md +0 -62
  285. package/.agent-src/contexts/communication/rules-auto/docs-sync-mechanics.md +0 -78
  286. package/.agent-src/contexts/communication/rules-auto/package-ci-checks-mechanics.md +0 -85
  287. package/.agent-src/contexts/communication/rules-auto/review-routing-awareness-mechanics.md +0 -65
  288. package/.agent-src/contexts/communication/rules-auto/roadmap-progress-sync-mechanics.md +0 -78
  289. package/.agent-src/contexts/communication/rules-auto/ui-audit-gate-mechanics.md +0 -53
  290. package/.agent-src/rules/chat-history-cadence.md +0 -143
  291. package/.agent-src/rules/chat-history-ownership.md +0 -124
  292. package/.agent-src/rules/chat-history-visibility.md +0 -97
  293. package/.agent-src/templates/scripts/work_engine/hooks/builtin/chat_history_heartbeat.py +0 -50
  294. package/.agent-src/templates/scripts/work_engine/hooks/builtin/chat_history_turn_check.py +0 -49
  295. package/scripts/check_phase_coupling.py +0 -148
  296. /package/{docs → .agent-src/contexts}/contracts/artifact-engagement-flow.md +0 -0
  297. /package/{docs → .agent-src/contexts}/contracts/command-suggestion-flow.md +0 -0
@@ -0,0 +1,235 @@
1
+ #!/usr/bin/env python3
2
+ """P4.3 — Write compressed rule bodies. Run after _p43_compress.py."""
3
+ from __future__ import annotations
4
+ import pathlib
5
+
6
+ ROOT = pathlib.Path(__file__).resolve().parents[1]
7
+ RULES = ROOT / ".agent-src.uncompressed" / "rules"
8
+
9
+
10
+ def write(name: str, content: str) -> None:
11
+ p = RULES / f"{name}.md"
12
+ p.write_text(content, encoding="utf-8")
13
+ print(f" ✓ {name}: {len(content)} chars")
14
+
15
+
16
+ # Each entry is the FULL file content (frontmatter + body).
17
+ FILES: dict[str, str] = {}
18
+
19
+ FILES["think-before-action"] = """---
20
+ type: "auto"
21
+ tier: "2b"
22
+ description: "Before coding, modifying, or debugging — analyze first, verify with real tools, never guess or trial-and-error"
23
+ alwaysApply: false
24
+ source: package
25
+ load_context:
26
+ - .agent-src.uncompressed/contexts/communication/rules-auto/think-before-action-mechanics.md
27
+ triggers:
28
+ - intent: "before coding"
29
+ - intent: "before debugging"
30
+ - intent: "before modifying"
31
+ ---
32
+
33
+ # think-before-action
34
+
35
+ ## The Iron Law
36
+
37
+ ```
38
+ ANALYZE BEFORE CODING. VERIFY WITH REAL TOOLS. NEVER GUESS.
39
+ NO BLIND TRIAL-AND-ERROR. MAX 2 RETRIES PER APPROACH.
40
+ ```
41
+
42
+ - Always analyze before coding or modifying anything.
43
+ - Never guess behavior — verify using code, data, or tools.
44
+ - Prefer targeted inspection (jq, debugger, logs) over brute-force.
45
+ - Always verify results after changes (API, UI, tests).
46
+ - When behavior can be defined → prefer test-first / TDD.
47
+ - Unclear requirements → precise clarification question, not hidden assumptions.
48
+ - Refactors must preserve behavior, validation, examples, and anti-failure guidance unless explicitly changed.
49
+ - Do NOT modify code you do not fully understand — read it, trace the flow, then change it.
50
+ - Multiple valid frameworks/patterns coexist (Tailwind + Flux, multiple form libs, competing state stores) → do NOT pick one silently — ask. See [`no blind implementation`](../../docs/guidelines/agent-infra/agent-interaction-and-decision-quality.md#2-no-blind-implementation).
51
+
52
+ ## Mechanics — workflow, minimum read set, verify-with-real-tools, no blind retries
53
+
54
+ The five-step Understand → Analyze → Plan → Implement → Verify workflow, the minimum read set (symbol, callers, tests, abstractions, data), the memory-consult step, the verification matrix, the output-reduction patterns, the no-blind-retries protocol, and the "open files are context, not intent" clause all live in [`contexts/communication/rules-auto/think-before-action-mechanics.md`](../contexts/communication/rules-auto/think-before-action-mechanics.md). The rule above is the obligation surface; the mechanics file is the lookup material.
55
+
56
+ If analysis is skipped → results are unreliable.
57
+ """
58
+
59
+ FILES["guidelines"] = """---
60
+ type: "auto"
61
+ tier: "3"
62
+ description: "Writing or reviewing code — check relevant guideline before writing or reviewing code"
63
+ alwaysApply: false
64
+ source: package
65
+ load_context:
66
+ - .agent-src.uncompressed/contexts/communication/rules-auto/guidelines-mechanics.md
67
+ triggers:
68
+ - intent: "writing code"
69
+ - intent: "reviewing code"
70
+ - keyword: "convention"
71
+ ---
72
+
73
+ # Guidelines
74
+
75
+ Coding guidelines live under `docs/guidelines/` organized by language. **Always check the relevant guideline** before writing or reviewing code.
76
+
77
+ ## How guidelines work
78
+
79
+ - **Guidelines** = detailed coding conventions (reference material, read on demand).
80
+ - **Rules** = always-active behavior constraints (auto-loaded every conversation).
81
+ - **Skills** = agent capabilities and workflows (matched by topic).
82
+
83
+ Guidelines are the "how to write code" docs. Rules enforce critical subsets automatically. Skills reference guidelines when performing related tasks.
84
+
85
+ ## Index — see mechanics
86
+
87
+ The full file index (PHP, PHP patterns, E2E, agent-infra) plus the guidelines-vs-skills boundary and the "adding new guidelines" template live in [`contexts/communication/rules-auto/guidelines-mechanics.md`](../contexts/communication/rules-auto/guidelines-mechanics.md). The rule above is the obligation surface; the mechanics file is the catalog.
88
+ """
89
+
90
+ FILES["token-efficiency"] = """---
91
+ type: "auto"
92
+ tier: "2a"
93
+ description: "When running CLI tools, fetching logs, or producing replies — redirect verbose output, minimize tool calls, keep replies concise"
94
+ alwaysApply: false
95
+ source: package
96
+ load_context:
97
+ - .agent-src.uncompressed/contexts/communication/rules-auto/token-efficiency-mechanics.md
98
+ triggers:
99
+ - intent: "verbose CLI output"
100
+ - intent: "fetching logs"
101
+ - keyword: "minimize tool calls"
102
+ ---
103
+
104
+ # Token Efficiency
105
+
106
+ ## The Iron Laws
107
+
108
+ ```
109
+ NEVER load full command output into context. Redirect → read summary → targeted details.
110
+ ```
111
+
112
+ ```
113
+ NEVER call the same tool more than 2 times in a row with similar parameters.
114
+ If you catch yourself repeating a tool call — STOP, rethink, try a different approach, or ask the user.
115
+ ```
116
+
117
+ ## Fresh Output Over Memory
118
+
119
+ When a tool or command returns a value (branch name, file path, PR number), use that EXACT value in subsequent API calls. NEVER substitute a value from earlier in the conversation. Context decay causes silent mismatches — fresh output is the only source of truth.
120
+
121
+ ## Mechanics — anti-loop patterns, conversation efficiency, exceptions
122
+
123
+ The anti-loop patterns (extended-reasoning loops, "CRITICAL INSTRUCTION" self-prompting), the act-skip-narration / stop-early / keep-output-minimal / don't-re-read / minimize-tool-calls clauses, and the small-output / debugging / explicit-full-output exceptions all live in [`contexts/communication/rules-auto/token-efficiency-mechanics.md`](../contexts/communication/rules-auto/token-efficiency-mechanics.md). The rule above is the obligation surface; the mechanics file is the lookup material.
124
+
125
+ This rule NEVER overrides `user-interaction` or command rules. Token efficiency means fewer *unnecessary* words — NOT skipping required questions, numbered options, or command steps.
126
+ """
127
+
128
+ FILES["autonomous-execution"] = """---
129
+ type: "auto"
130
+ tier: "3"
131
+ description: "Deciding whether to ask the user or just act on a workflow step — trivial-vs-blocking classification, autonomy opt-in detection, commit default; defers to non-destructive-by-default for the Hard Floor"
132
+ alwaysApply: false
133
+ source: package
134
+ load_context:
135
+ - .agent-src.uncompressed/contexts/execution/autonomy-detection.md
136
+ - .agent-src.uncompressed/contexts/execution/autonomy-mechanics.md
137
+ - .agent-src.uncompressed/contexts/execution/autonomy-examples.md
138
+ triggers:
139
+ - intent: "trivial workflow question"
140
+ - intent: "autonomy mode"
141
+ - keyword: "personal.autonomy"
142
+ ---
143
+
144
+ # Autonomous Execution
145
+
146
+ User's time is the scarce resource. Trivial workflow questions are noise. This rule defines **trivial** (just act), **blocking** (still ask), the **hard floor** (always ask, no override), and the **commit default** (never commit, never ask — review-first by design).
147
+
148
+ ## Hard Floor — see [`non-destructive-by-default`](non-destructive-by-default.md)
149
+
150
+ The universal safety floor (production-branch merges, deploys, pushes, prod data/infra, whimsical bulk deletions, and commits containing bulk deletions or infra changes) is governed by the canonical [`non-destructive-by-default`](non-destructive-by-default.md) rule. It applies regardless of `personal.autonomy`, a standing autonomy directive, or any roadmap authorization. Nothing in **this** rule lifts it. If a trigger fires, stop and ask — every other section below assumes the floor has already been cleared.
151
+
152
+ ## Setting — `personal.autonomy`
153
+
154
+ Three values: `on` (suppress trivial questions), `off` (ask trivial questions too), `auto` (default — same as `off` until the user opts in via a standing autonomy directive). Read once on the first turn and cache. Missing key → treat as `on`. Full table, semantics, and cloud behavior: [`contexts/execution/autonomy-mechanics.md`](../contexts/execution/autonomy-mechanics.md).
155
+
156
+ ## Opt-in detection — match by intent, not exact string
157
+
158
+ In `auto` mode, flip to `on` for the rest of the conversation when the user expresses **"stop asking on trivial steps, just work"**. Recognize **intent**, not the literal substring. Opt-out (same intent, reversed) flips back to `off`. Both directions are **speech-act-checked**: the phrase must be a meta-instruction to the agent, not content / quote / subject / code / third-party reference / hypothetical. In doubt → keep current mode, no speculative flips.
159
+
160
+ Algorithm and speech-act heuristic: [`contexts/execution/autonomy-detection.md`](../contexts/execution/autonomy-detection.md). Anchor phrases (DE+EN), no-flip patterns, counter-examples, trivial-vs-blocking taxonomy, commit-policy summary, and named failure modes: [`contexts/execution/autonomy-mechanics.md`](../contexts/execution/autonomy-mechanics.md) + [`contexts/execution/autonomy-examples.md`](../contexts/execution/autonomy-examples.md).
161
+
162
+ ## See also
163
+
164
+ - [`non-destructive-by-default`](non-destructive-by-default.md) — universal safety floor; never overridden by autonomy
165
+ - [`scope-control`](scope-control.md) — git-ops permission gate
166
+ - [`ask-when-uncertain`](ask-when-uncertain.md) — vague-request triggers that always require asking
167
+ - [`no-cheap-questions`](no-cheap-questions.md) — mode-independent floor against context-derived asks
168
+ - [`commit-policy`](commit-policy.md) — never-commit / never-ask Iron Law
169
+ - [`/commit:in-chunks`](../commands/commit/in-chunks.md), [`/commit`](../commands/commit.md)
170
+ """
171
+
172
+ FILES["user-interaction"] = '''---
173
+ type: "auto"
174
+ tier: "3"
175
+ description: "Asking the user a question, presenting options, or summarizing progress — numbered-options Iron Law, single-recommendation rule, progress indicators"
176
+ alwaysApply: false
177
+ source: package
178
+ load_context:
179
+ - .agent-src.uncompressed/contexts/communication/rules-auto/user-interaction-mechanics.md
180
+ triggers:
181
+ - intent: "ask user a question"
182
+ - intent: "numbered options"
183
+ - intent: "summarizing progress"
184
+ ---
185
+
186
+ # User Interaction
187
+
188
+ Two Iron Laws govern every reply that contains numbered options.
189
+ They override conversation momentum, brevity, and the urge to defer
190
+ to the user. **Missing a recommendation is a rule violation, not a slip.**
191
+
192
+ ## Iron Law 1 — Single-Source Recommendation
193
+
194
+ ```
195
+ EXACTLY ONE LINE NAMES THE RECOMMENDED NUMBER. NO INLINE TAG. NO SECOND PROSE NUMBER.
196
+ THE OPTION BLOCK STAYS NEUTRAL. THE RECOMMENDATION LINE IS THE ONLY SOURCE OF TRUTH.
197
+ DRIFT BETWEEN OPTION-BLOCK AND PROSE IS STRUCTURALLY IMPOSSIBLE WHEN THE TAG DOES NOT EXIST.
198
+ MISSING RECOMMENDATION = RULE VIOLATION, NOT A SLIP.
199
+ POSITION-AGNOSTIC. END-OF-TURN MENUS COUNT. NEXT-STEP LISTS COUNT. NO EXCEPTIONS.
200
+ THE RECOMMENDATION LINE LIVES DIRECTLY UNDER THE OPTIONS BLOCK. NOWHERE ELSE.
201
+ PROSE NAMING A "RECOMMENDED" PATH ABOVE OR BEFORE THE OPTIONS BLOCK = NO RECOMMENDATION.
202
+ WRONG-LANGUAGE LABEL (`Recommendation:` WHEN USER IS GERMAN, OR VICE VERSA) = NO RECOMMENDATION.
203
+ ```
204
+
205
+ ## Iron Law 2 — Pre-Send Self-Check
206
+
207
+ ```
208
+ EVERY REPLY WITH NUMBERED OPTIONS RUNS THE SELF-CHECK. NO EXCEPTIONS.
209
+ SKIPPING IT IS A RULE VIOLATION, NOT A SLIP.
210
+ ```
211
+
212
+ Mechanical backstop:
213
+ `python3 scripts/check_reply_consistency.py --stdin < draft.md`
214
+ (non-zero exit on any rule below). Self-scan is the primary gate;
215
+ the script is the deterministic safety net.
216
+
217
+ ## Mechanics — rationale, failure modes, format details, examples
218
+
219
+ The "why take a position", position-agnostic clause, format
220
+ specification (neutral block + bolded recommendation line + caveat),
221
+ no-trailing-open-question rule, "what does NOT count" catalog, full
222
+ five-step pre-send self-check, named failure-mode catalog (end-of-turn
223
+ menu, trailing-question hedge, no-preference hedge, multi-block reply,
224
+ …), slip-handling protocol, numbered-options rules, format examples,
225
+ progress indicators, and summary-table patterns all live in
226
+ [`contexts/communication/rules-auto/user-interaction-mechanics.md`](../contexts/communication/rules-auto/user-interaction-mechanics.md).
227
+ The rule above is the obligation surface; the mechanics file is the
228
+ lookup material.
229
+ '''
230
+
231
+
232
+ if __name__ == "__main__":
233
+ for name, content in FILES.items():
234
+ write(name, content)
235
+ print(f"✓ wrote {len(FILES)} compressed rule bodies")
@@ -0,0 +1,118 @@
1
+ #!/usr/bin/env python3
2
+ """P4.3 — Surgical compression of 22 compress-and-keep auto-rules.
3
+
4
+ Writes new bodies for the largest rules (Iron Laws preserved verbatim,
5
+ extended rationale relocated to contexts/communication/rules-auto/).
6
+ Adds `triggers:` to all 22 so the router has a manifest entry per rule.
7
+ Idempotent — re-running rewrites the same content.
8
+ """
9
+ from __future__ import annotations
10
+
11
+ import pathlib
12
+ import re
13
+ import sys
14
+
15
+ ROOT = pathlib.Path(__file__).resolve().parents[1]
16
+ RULES = ROOT / ".agent-src.uncompressed" / "rules"
17
+ CTXDIR = ROOT / ".agent-src.uncompressed" / "contexts" / "communication" / "rules-auto"
18
+
19
+ # Triggers per rule (keyword / phrase / file_pattern / path_prefix / intent / command)
20
+ TRIGGERS: dict[str, list[dict]] = {
21
+ "architecture": [{"keyword": "controller"}, {"keyword": "service"}, {"keyword": "module"}, {"intent": "structural decision"}],
22
+ "artifact-drafting-protocol": [{"intent": "create new skill"}, {"intent": "create new rule"}, {"intent": "create new command"}, {"intent": "create new guideline"}],
23
+ "augment-source-of-truth": [{"path_prefix": ".agent-src/"}, {"path_prefix": ".augment/"}, {"path_prefix": ".claude/"}, {"path_prefix": ".cursor/"}],
24
+ "autonomous-execution": [{"intent": "trivial workflow question"}, {"intent": "autonomy mode"}, {"keyword": "personal.autonomy"}],
25
+ "context-hygiene": [{"intent": "long conversation"}, {"intent": "tool loop"}, {"intent": "fresh chat"}, {"keyword": "3-failure"}],
26
+ "downstream-changes": [{"intent": "after code edit"}, {"keyword": "callers"}, {"keyword": "imports"}, {"keyword": "downstream"}],
27
+ "guidelines": [{"intent": "writing code"}, {"intent": "reviewing code"}, {"keyword": "convention"}],
28
+ "improve-before-implement": [{"intent": "implement feature"}, {"intent": "architectural change"}, {"keyword": "refactor"}],
29
+ "markdown-safe-codeblocks": [{"intent": "markdown with code blocks"}, {"keyword": "triple backticks"}, {"file_pattern": "*.md"}],
30
+ "minimal-safe-diff": [{"intent": "writing a diff"}, {"intent": "reviewing a diff"}, {"keyword": "drive-by"}],
31
+ "missing-tool-handling": [{"keyword": "command not found"}, {"keyword": "not installed"}, {"intent": "install tool"}],
32
+ "no-attribution-footers": [{"intent": "PR body"}, {"intent": "commit message"}, {"intent": "Jira comment"}, {"keyword": "co-authored"}],
33
+ "no-roadmap-references": [{"path_prefix": "agents/roadmaps/"}, {"intent": "link from stable artifact"}],
34
+ "preservation-guard": [{"intent": "merge skill"}, {"intent": "compress rule"}, {"intent": "refactor artifact"}, {"keyword": "Iron Law"}],
35
+ "role-mode-adherence": [{"keyword": "active_role"}, {"keyword": "role-mode"}, {"intent": "mode marker"}],
36
+ "runtime-safety": [{"keyword": "execution"}, {"keyword": "automated"}, {"keyword": "assisted"}, {"keyword": "handler"}],
37
+ "security-sensitive-stop": [{"keyword": "auth"}, {"keyword": "billing"}, {"keyword": "tenant"}, {"keyword": "secret"}, {"keyword": "webhook"}],
38
+ "size-enforcement": [{"intent": "create rule"}, {"intent": "create skill"}, {"intent": "create command"}, {"intent": "create guideline"}],
39
+ "think-before-action": [{"intent": "before coding"}, {"intent": "before debugging"}, {"intent": "before modifying"}],
40
+ "token-efficiency": [{"intent": "verbose CLI output"}, {"intent": "fetching logs"}, {"keyword": "minimize tool calls"}],
41
+ "tool-safety": [{"keyword": "allowed_tools"}, {"keyword": "tool registry"}, {"intent": "external API"}],
42
+ "user-interaction": [{"intent": "ask user a question"}, {"intent": "numbered options"}, {"intent": "summarizing progress"}],
43
+ }
44
+
45
+
46
+ def _read(p: pathlib.Path) -> str:
47
+ return p.read_text(encoding="utf-8")
48
+
49
+
50
+ def _split_frontmatter(text: str) -> tuple[str, str]:
51
+ """Return (frontmatter_inner, body) — assumes leading ---\\n…---\\n\\n."""
52
+ m = re.match(r"^---\n(.*?)\n---\n*", text, re.DOTALL)
53
+ if not m:
54
+ raise ValueError("no frontmatter")
55
+ return m.group(1), text[m.end():]
56
+
57
+
58
+ def _format_triggers(items: list[dict]) -> str:
59
+ out = ["triggers:"]
60
+ for it in items:
61
+ ((k, v),) = it.items()
62
+ out.append(f' - {k}: "{v}"')
63
+ return "\n".join(out)
64
+
65
+
66
+ def _strip_old_triggers(fm: str) -> str:
67
+ """Remove an existing triggers: block (with its inline children)."""
68
+ lines = fm.splitlines()
69
+ out: list[str] = []
70
+ i = 0
71
+ while i < len(lines):
72
+ if lines[i].rstrip() == "triggers:":
73
+ i += 1
74
+ while i < len(lines) and lines[i].startswith((" ", "\t")):
75
+ i += 1
76
+ continue
77
+ out.append(lines[i])
78
+ i += 1
79
+ return "\n".join(out)
80
+
81
+
82
+ def patch_triggers_only(rule_id: str) -> bool:
83
+ """Inject triggers: into rule frontmatter without touching the body."""
84
+ p = RULES / f"{rule_id}.md"
85
+ if not p.exists():
86
+ print(f" ✗ missing: {rule_id}", file=sys.stderr)
87
+ return False
88
+ text = _read(p)
89
+ fm, body = _split_frontmatter(text)
90
+ fm = _strip_old_triggers(fm).rstrip()
91
+ triggers = TRIGGERS.get(rule_id)
92
+ if triggers:
93
+ fm = fm + "\n" + _format_triggers(triggers)
94
+ p.write_text(f"---\n{fm}\n---\n\n{body.lstrip()}", encoding="utf-8")
95
+ return True
96
+
97
+
98
+ def write_rule(rule_id: str, fm_extra: str, body: str) -> None:
99
+ """Overwrite a rule with given body + standard frontmatter additions."""
100
+ p = RULES / f"{rule_id}.md"
101
+ text = _read(p)
102
+ fm, _ = _split_frontmatter(text)
103
+ fm_clean = _strip_old_triggers(fm).rstrip()
104
+ triggers = TRIGGERS.get(rule_id)
105
+ parts = [fm_clean]
106
+ if fm_extra:
107
+ parts.append(fm_extra.rstrip())
108
+ if triggers:
109
+ parts.append(_format_triggers(triggers))
110
+ full_fm = "\n".join(parts)
111
+ p.write_text(f"---\n{full_fm}\n---\n\n{body.lstrip()}\n", encoding="utf-8")
112
+
113
+
114
+ if __name__ == "__main__":
115
+ # Imported by _p43_bodies.py — when run directly, only stamp triggers.
116
+ for rid in TRIGGERS:
117
+ patch_triggers_only(rid)
118
+ print("✓ triggers stamped on all 22 compress-and-keep rules")
@@ -0,0 +1,199 @@
1
+ #!/usr/bin/env python3
2
+ """P4.1 + P4.2 migration: rule → skill / guideline / command / contract stub.
3
+
4
+ Replaces 25 rules with thin stubs declaring `triggers:` + `routes_to:`.
5
+ For move-to-guideline, copies the rule body into a new guideline file.
6
+ For move-to-skill / command / contract, the target already carries the
7
+ procedure — stub keeps an Iron-Law one-liner only.
8
+ """
9
+ from __future__ import annotations
10
+ import re, sys, pathlib
11
+
12
+ ROOT = pathlib.Path(__file__).resolve().parents[1]
13
+ RULES = ROOT / ".agent-src.uncompressed" / "rules"
14
+ GUIDELINES = ROOT / "docs" / "guidelines"
15
+
16
+ # (rule_id, route, triggers, iron_law_one_liner)
17
+ # route format: "kind:id"
18
+ SKILL_MIGRATIONS = [
19
+ ("agent-docs", "skill:agent-docs-writing",
20
+ [("path_prefix", "agents/"), ("path_prefix", ".github/copilot-instructions"), ("keyword", "AGENTS.md"), ("keyword", "roadmap")],
21
+ "Read agent docs (`AGENTS.md`, `agents/`, module `agents/`) before work; update them after structural changes."),
22
+ ("analysis-skill-routing", "skill:analysis-skill-router",
23
+ [("keyword", "analyze"), ("keyword", "analysis"), ("phrase", "dig into the codebase")],
24
+ "Route analysis tasks to the narrowest matching `project-analysis-*` skill, not the broad fallback."),
25
+ ("capture-learnings", "skill:learning-to-rule-or-skill",
26
+ [("phrase", "after completing a task"), ("keyword", "learning"), ("keyword", "lesson")],
27
+ "After a task, capture repeated mistakes / successful patterns as a rule or skill — never lose the learning."),
28
+ ("cli-output-handling", "skill:rtk-output-filtering",
29
+ [("keyword", "git"), ("keyword", "phpstan"), ("keyword", "rector"), ("keyword", "phpunit"), ("keyword", "composer")],
30
+ "Wrap verbose CLI output with `rtk` when installed; fall back to `tail`/`grep` only when missing."),
31
+ ("commit-conventions", "skill:conventional-commits-writing",
32
+ [("keyword", "commit"), ("keyword", "branch"), ("phrase", "conventional commits")],
33
+ "Use Conventional Commits (`feat:`, `fix:`, `chore:` …); branches `<type>/<short-slug>`; never invent your own format."),
34
+ ("docker-commands", "skill:docker",
35
+ [("keyword", "docker"), ("keyword", "artisan"), ("keyword", "composer"), ("phrase", "inside the container")],
36
+ "Run PHP / artisan / composer / phpstan / rector / ecs / phpunit inside the project container, never on the host."),
37
+ ("docs-sync", "skill:agent-docs-writing",
38
+ [("path_prefix", ".agent-src.uncompressed/"), ("path_prefix", ".augment/"), ("keyword", "rename"), ("keyword", "delete")],
39
+ "On any add / rename / delete of skill / rule / command / guideline, update counts and cross-references in the same edit."),
40
+ ("e2e-testing", "command:e2e-heal",
41
+ [("keyword", "playwright"), ("keyword", "e2e"), ("phrase", "page object")],
42
+ "Playwright E2E: stable locators, no `waitForTimeout`, Page Objects for shared flows, fixtures over `beforeEach`."),
43
+ ("laravel-translations", "skill:laravel",
44
+ [("path_prefix", "lang/"), ("keyword", "translation"), ("keyword", "__()"), ("keyword", "trans(")],
45
+ "Use `__()`/`trans()` with language keys for every user-visible string; mirror keys across `lang/<locale>/` files."),
46
+ ("model-recommendation", "command:set-cost-profile",
47
+ [("phrase", "switch task"), ("phrase", "new task"), ("phrase", "which model")],
48
+ "On task / model switch, recommend the optimal model for the task complexity before any work begins."),
49
+ ("onboarding-gate", "command:onboard",
50
+ [("phrase", "first turn"), ("keyword", "onboarding"), ("path_prefix", ".agent-settings.yml")],
51
+ "First turn of a project: if `onboarding.onboarded` is false, prompt `/onboard` before executing any other request."),
52
+ ("package-ci-checks", "skill:lint-skills",
53
+ [("phrase", "task ci"), ("phrase", "before push"), ("phrase", "before pr")],
54
+ "Run `task ci` locally and confirm green before pushing or opening a PR in this package."),
55
+ ("review-routing-awareness", "skill:review-routing",
56
+ [("keyword", "reviewer"), ("phrase", "risk hotspot"), ("phrase", "ownership map")],
57
+ "Consult ownership-map and historical-bug-patterns before suggesting reviewers or claiming a change is safe."),
58
+ ("reviewer-awareness", "skill:review-routing",
59
+ [("keyword", "reviewer"), ("phrase", "suggest reviewers")],
60
+ "Anchor reviewer choice in paths and risk, never seniority; medium / high risk requires primary + secondary role."),
61
+ ("skill-improvement-trigger", "skill:skill-improvement-pipeline",
62
+ [("phrase", "after completing"), ("keyword", "improvement"), ("keyword", "pipeline")],
63
+ "After a meaningful task, trigger the post-task learning capture if `pipelines.skill_improvement` is enabled."),
64
+ ("slash-command-routing-policy", "skill:command-routing",
65
+ [("keyword", "/create-pr"), ("keyword", "/commit"), ("keyword", "/fix-ci"), ("phrase", "slash command")],
66
+ "On a slash-command invocation or pasted command body, route to the matching command file; never improvise."),
67
+ ("ui-audit-gate", "skill:existing-ui-audit",
68
+ [("path_prefix", "resources/views/"), ("path_prefix", "resources/js/"), ("keyword", "component"), ("keyword", "design token")],
69
+ "Before any non-trivial UI change, require `state.ui_audit` findings — gate, not suggestion."),
70
+ ("upstream-proposal", "skill:upstream-contribute",
71
+ [("phrase", "after creating"), ("phrase", "after improving"), ("keyword", "upstream")],
72
+ "After creating or significantly improving a skill / rule / guideline / command, ask whether to upstream it."),
73
+ ]
74
+
75
+ GUIDELINE_MIGRATIONS = [
76
+ ("artifact-engagement-recording", "contract:artifact-engagement-flow",
77
+ [("phrase", "/implement-ticket"), ("phrase", "/work"), ("keyword", "telemetry")],
78
+ "After a `/implement-ticket` or `/work` phase-step, emit one `telemetry:record` call with consulted + applied ids when telemetry is enabled."),
79
+ ("augment-portability", "guideline:augment-portability-patterns",
80
+ [("path_prefix", ".augment/"), ("path_prefix", ".agent-src.uncompressed/"), ("keyword", "portable")],
81
+ "Files inside `.augment/` and `.agent-src.uncompressed/` MUST stay project-agnostic — no project names, domains, stacks."),
82
+ ("command-suggestion-policy", "contract:command-suggestion-flow",
83
+ [("phrase", "free-form prompt"), ("phrase", "command suggestion")],
84
+ "When a free-form prompt matches a command, surface matches as numbered options with as-is escape; never auto-execute."),
85
+ ("php-coding", "guideline:php/php-coding-patterns",
86
+ [("file_pattern", "*.php"), ("keyword", "phpstan"), ("keyword", "ecs")],
87
+ "PHP: strict types, named comparisons, early returns, Eloquent conventions — full pattern library in the guideline."),
88
+ ("roadmap-progress-sync", "guideline:agent-infra/roadmap-progress-mechanics",
89
+ [("path_prefix", "agents/roadmaps/")],
90
+ "Any touch to `agents/roadmaps/` regenerates the dashboard in the same response; archive the roadmap when 0 open items remain."),
91
+ ("rule-type-governance", "guideline:agent-infra/rule-type-governance",
92
+ [("path_prefix", ".agent-src.uncompressed/rules/")],
93
+ "Choose `always` vs `auto` per the governance table; over-broad `always` rules degrade the kernel budget."),
94
+ ("skill-quality", "guideline:agent-infra/skill-quality-checklist",
95
+ [("path_prefix", ".agent-src.uncompressed/skills/")],
96
+ "Every skill must be executable, validated, and self-contained — full checklist in the guideline."),
97
+ ]
98
+
99
+
100
+
101
+ def yaml_triggers(triggers: list[tuple[str, str]]) -> str:
102
+ lines = []
103
+ for kind, val in triggers:
104
+ v = val.replace('"', '\\"')
105
+ lines.append(f' - {kind}: "{v}"')
106
+ return "\n".join(lines)
107
+
108
+
109
+ def parse_existing_frontmatter(text: str) -> tuple[dict, str]:
110
+ m = re.match(r"^---\n(.*?)\n---\n(.*)$", text, re.DOTALL)
111
+ if not m:
112
+ return {}, text
113
+ fm_text, body = m.group(1), m.group(2)
114
+ fm = {}
115
+ for line in fm_text.split("\n"):
116
+ if ":" not in line or line.startswith(" "):
117
+ continue
118
+ k, _, v = line.partition(":")
119
+ fm[k.strip()] = v.strip().strip('"')
120
+ return fm, body
121
+
122
+
123
+ def build_stub(rule_id: str, route: str, triggers: list[tuple[str, str]],
124
+ iron_law: str, existing_fm: dict) -> str:
125
+ desc = existing_fm.get("description", "")
126
+ tier = existing_fm.get("tier", "3")
127
+ rtype = existing_fm.get("type", "auto")
128
+ source = existing_fm.get("source", "package")
129
+ new_tier = {"1": "tier-1", "2a": "tier-2", "2b": "tier-2", "3": "tier-2",
130
+ "mechanical-already": "tier-2", "mech": "tier-2"}.get(tier, "tier-2")
131
+ fm_lines = [
132
+ "---",
133
+ f'type: "{rtype}"',
134
+ f'tier: "{new_tier}"',
135
+ f'description: "{desc}"',
136
+ f'source: {source}',
137
+ "triggers:",
138
+ yaml_triggers(triggers),
139
+ "routes_to:",
140
+ f' - "{route}"',
141
+ "---",
142
+ "",
143
+ f"# {rule_id.replace('-', ' ').title()}",
144
+ "",
145
+ f"**Iron Law.** {iron_law}",
146
+ "",
147
+ f"Body migrated to `{route}` (per P4 of `road-to-kernel-and-router.md`).",
148
+ "Trigger-set above activates this routing under the `balanced` and `full` profiles.",
149
+ ]
150
+ return "\n".join(fm_lines) + "\n"
151
+
152
+
153
+ def write_guideline(rule_id: str, route: str, body: str, existing_fm: dict) -> pathlib.Path:
154
+ kind, _, gid = route.partition(":")
155
+ if kind == "guideline":
156
+ target = GUIDELINES / f"{gid}.md"
157
+ elif kind == "contract":
158
+ target = ROOT / "docs" / "contracts" / f"{gid}.md"
159
+ else:
160
+ raise ValueError(f"unsupported route kind for guideline migration: {kind}")
161
+ if target.exists():
162
+ return target
163
+ target.parent.mkdir(parents=True, exist_ok=True)
164
+ desc = existing_fm.get("description", "")
165
+ header = (f"# {rule_id.replace('-', ' ').title()}\n\n"
166
+ f"> {desc}\n\n"
167
+ f"_Origin: migrated from `.agent-src.uncompressed/rules/{rule_id}.md` "
168
+ f"per P4.2 of `road-to-kernel-and-router.md`._\n\n")
169
+ target.write_text(header + body.lstrip())
170
+ return target
171
+
172
+
173
+ def main() -> int:
174
+ written = []
175
+ for rule_id, route, triggers, iron_law in SKILL_MIGRATIONS:
176
+ rule_path = RULES / f"{rule_id}.md"
177
+ if not rule_path.exists():
178
+ print(f" ✗ MISSING rule: {rule_id}"); continue
179
+ fm, body = parse_existing_frontmatter(rule_path.read_text())
180
+ stub = build_stub(rule_id, route, triggers, iron_law, fm)
181
+ rule_path.write_text(stub)
182
+ written.append(("skill-stub", rule_id, route, len(stub)))
183
+ for rule_id, route, triggers, iron_law in GUIDELINE_MIGRATIONS:
184
+ rule_path = RULES / f"{rule_id}.md"
185
+ if not rule_path.exists():
186
+ print(f" ✗ MISSING rule: {rule_id}"); continue
187
+ fm, body = parse_existing_frontmatter(rule_path.read_text())
188
+ write_guideline(rule_id, route, body, fm)
189
+ stub = build_stub(rule_id, route, triggers, iron_law, fm)
190
+ rule_path.write_text(stub)
191
+ written.append(("guideline", rule_id, route, len(stub)))
192
+ print(f"\nMigrated {len(written)} rules:")
193
+ for kind, rid, route, sz in written:
194
+ print(f" {kind:14s} {rid:35s} → {route:55s} stub={sz}c")
195
+ return 0
196
+
197
+
198
+ if __name__ == "__main__":
199
+ sys.exit(main())
@@ -0,0 +1,57 @@
1
+ """Build the Phase-1 council question file (one-off)."""
2
+ from pathlib import Path
3
+
4
+ OUT = Path("/tmp/council-p1/question.md")
5
+ OUT.parent.mkdir(parents=True, exist_ok=True)
6
+
7
+ framing = """# Cross-check request — Phase 1 of "Road to Rule Kernel and Router"
8
+
9
+ We are about to compress a 56-rule "always-active" set down to a small
10
+ hard-capped kernel + a router-loaded auto bucket. Phase 1 is purely
11
+ classification + projection — no source rules edited yet. Two contracts
12
+ were produced. We want a neutral second opinion BEFORE Phase 2 ships
13
+ compression to the actual rule files.
14
+
15
+ ## What we want from you
16
+
17
+ 1. **Disposition calls.** Look at the 56-rule classification. Are any
18
+ `keep-in-kernel` rules over-included (could safely become auto-tier)?
19
+ Are any `move-to-skill` / `move-to-guideline` calls wrong (e.g.
20
+ carrying an Iron Law that should stay always-on)? Cite the rule id
21
+ and the better disposition.
22
+ 2. **Kernel inclusion criteria.** Section 1 of `kernel-membership.md`
23
+ lists 4 criteria (Iron-Law floor / mode-independent / pre-action
24
+ gate / cross-cutting). Are these the right gates? Is anything
25
+ missing or redundant?
26
+ 3. **Compression-rate r = 0.742.** Three pilots gave r-values 0.677 /
27
+ 0.712 / 0.838. We locked the **mean**. Reasonable, or should we use
28
+ median (0.712) / max (0.838) as a more conservative budget cushion?
29
+ Note: pilot range straddles the typical 0.6-0.75 band; max came
30
+ from the shortest rule (already-lean floor effect).
31
+ 4. **The 1.5k per-rule cap with ADR-override.** Two of the three pilots
32
+ land >1.5k post-compression and would need an `iron-law-override`
33
+ ADR. Is the per-rule cap realistic, or should we raise the per-rule
34
+ ceiling (e.g. 2.5k or 3.5k) and lower the bucket cap (e.g. from 25k
35
+ to 20k)? What's the failure mode you'd be most worried about?
36
+ 5. **Anything we missed.** Risks, blind spots, sequencing problems.
37
+
38
+ Be specific. Cite the rule id or the section number. We will reject
39
+ generic "looks good" reviews.
40
+
41
+ ---
42
+
43
+ ## Contract 1 — docs/contracts/rule-classification.md
44
+
45
+ """
46
+
47
+ OUT.write_text(framing)
48
+ with OUT.open("a") as fh:
49
+ fh.write(Path("docs/contracts/rule-classification.md").read_text())
50
+ fh.write("\n\n---\n\n## Contract 2 — docs/contracts/kernel-membership.md\n\n")
51
+ fh.write(Path("docs/contracts/kernel-membership.md").read_text())
52
+ fh.write("\n\n---\n\n## Pilot inputs (compressed bodies, for reference)\n")
53
+ for rid in ("agent-authority", "direct-answers", "language-and-tone"):
54
+ fh.write(f"\n### Pilot — {rid}\n\n")
55
+ fh.write(Path(f"docs/contracts/pilot/{rid}.md").read_text())
56
+
57
+ print(f"wrote {OUT} — {OUT.stat().st_size} bytes")