@event4u/agent-config 1.20.0 → 1.22.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 (268) hide show
  1. package/.agent-src/commands/agents.md +1 -1
  2. package/.agent-src/commands/bug-fix.md +2 -1
  3. package/.agent-src/commands/bug-investigate.md +3 -2
  4. package/.agent-src/commands/challenge-me/vision.md +348 -0
  5. package/.agent-src/commands/challenge-me/with-docs.md +333 -0
  6. package/.agent-src/commands/challenge-me.md +61 -0
  7. package/.agent-src/commands/chat-history/import.md +60 -64
  8. package/.agent-src/commands/compress.md +12 -0
  9. package/.agent-src/commands/context/create.md +2 -2
  10. package/.agent-src/commands/context.md +1 -1
  11. package/.agent-src/commands/copilot-agents.md +1 -1
  12. package/.agent-src/commands/council/default.md +69 -10
  13. package/.agent-src/commands/council.md +1 -1
  14. package/.agent-src/commands/create-pr.md +7 -3
  15. package/.agent-src/commands/e2e-heal.md +1 -1
  16. package/.agent-src/commands/e2e-plan.md +1 -1
  17. package/.agent-src/commands/feature/dev.md +3 -3
  18. package/.agent-src/commands/feature.md +1 -1
  19. package/.agent-src/commands/fix/seeder.md +2 -2
  20. package/.agent-src/commands/fix.md +1 -1
  21. package/.agent-src/commands/grill-me.md +38 -0
  22. package/.agent-src/commands/jira-ticket.md +1 -1
  23. package/.agent-src/commands/judge/steps.md +1 -1
  24. package/.agent-src/commands/judge.md +2 -2
  25. package/.agent-src/commands/memory.md +1 -1
  26. package/.agent-src/commands/mode.md +5 -5
  27. package/.agent-src/commands/module.md +1 -1
  28. package/.agent-src/commands/onboard.md +4 -4
  29. package/.agent-src/commands/optimize/augmentignore.md +1 -1
  30. package/.agent-src/commands/optimize-prompt.md +61 -0
  31. package/.agent-src/commands/optimize.md +1 -1
  32. package/.agent-src/commands/override.md +1 -1
  33. package/.agent-src/commands/review-changes.md +1 -1
  34. package/.agent-src/commands/review-routing.md +1 -1
  35. package/.agent-src/commands/roadmap/ai-council.md +183 -0
  36. package/.agent-src/commands/roadmap/create.md +6 -1
  37. package/.agent-src/commands/roadmap/process-full.md +58 -0
  38. package/.agent-src/commands/roadmap/process-phase.md +69 -0
  39. package/.agent-src/commands/roadmap/process-step.md +57 -0
  40. package/.agent-src/commands/roadmap.md +45 -17
  41. package/.agent-src/commands/set-cost-profile.md +3 -3
  42. package/.agent-src/commands/sync-agent-settings.md +2 -2
  43. package/.agent-src/commands/tests/create.md +2 -2
  44. package/.agent-src/commands/tests.md +1 -1
  45. package/.agent-src/commands/threat-model.md +5 -4
  46. package/.agent-src/contexts/augment-infrastructure.md +1 -1
  47. package/.agent-src/contexts/authority/commit-mechanics.md +14 -1
  48. package/.agent-src/contexts/authority/destructive-mechanics.md +14 -1
  49. package/.agent-src/contexts/authority/scope-mechanics.md +5 -0
  50. package/.agent-src/contexts/communication/rules-auto/guidelines-mechanics.md +76 -0
  51. package/.agent-src/contexts/communication/rules-auto/slash-command-routing-policy-mechanics.md +54 -19
  52. package/.agent-src/contexts/communication/rules-auto/think-before-action-mechanics.md +98 -0
  53. package/.agent-src/contexts/communication/rules-auto/token-efficiency-mechanics.md +93 -0
  54. package/.agent-src/contexts/communication/rules-auto/user-interaction-mechanics.md +128 -5
  55. package/.agent-src/contexts/execution/autonomy-mechanics.md +44 -0
  56. package/.agent-src/contexts/execution/roadmap-process-loop.md +125 -0
  57. package/.agent-src/contexts/model-recommendations.md +2 -2
  58. package/.agent-src/contexts/override-system.md +1 -1
  59. package/.agent-src/contexts/skills-and-commands.md +1 -1
  60. package/.agent-src/personas/product-owner.md +2 -2
  61. package/.agent-src/personas/qa.md +1 -1
  62. package/.agent-src/rules/agent-authority.md +5 -6
  63. package/.agent-src/rules/agent-docs.md +11 -53
  64. package/.agent-src/rules/analysis-skill-routing.md +10 -40
  65. package/.agent-src/rules/architecture.md +6 -1
  66. package/.agent-src/rules/artifact-drafting-protocol.md +5 -0
  67. package/.agent-src/rules/artifact-engagement-recording.md +23 -59
  68. package/.agent-src/rules/ask-when-uncertain.md +24 -47
  69. package/.agent-src/rules/augment-portability.md +14 -62
  70. package/.agent-src/rules/augment-source-of-truth.md +10 -1
  71. package/.agent-src/rules/autonomous-execution.md +17 -98
  72. package/.agent-src/rules/capture-learnings.md +9 -80
  73. package/.agent-src/rules/cli-output-handling.md +12 -42
  74. package/.agent-src/rules/command-suggestion-policy.md +25 -73
  75. package/.agent-src/rules/commit-conventions.md +9 -58
  76. package/.agent-src/rules/commit-policy.md +16 -47
  77. package/.agent-src/rules/context-hygiene.md +5 -0
  78. package/.agent-src/rules/direct-answers.md +21 -50
  79. package/.agent-src/rules/docker-commands.md +11 -45
  80. package/.agent-src/rules/docs-sync.md +10 -56
  81. package/.agent-src/rules/downstream-changes.md +5 -0
  82. package/.agent-src/rules/e2e-testing.md +9 -44
  83. package/.agent-src/rules/guidelines.md +13 -75
  84. package/.agent-src/rules/improve-before-implement.md +11 -2
  85. package/.agent-src/rules/invite-challenge.md +71 -0
  86. package/.agent-src/rules/language-and-tone.md +41 -106
  87. package/.agent-src/rules/laravel-translations.md +11 -40
  88. package/.agent-src/rules/markdown-safe-codeblocks.md +4 -0
  89. package/.agent-src/rules/minimal-safe-diff.md +4 -0
  90. package/.agent-src/rules/missing-tool-handling.md +4 -0
  91. package/.agent-src/rules/model-recommendation.md +9 -61
  92. package/.agent-src/rules/no-attribution-footers.md +5 -0
  93. package/.agent-src/rules/no-cheap-questions.md +11 -27
  94. package/.agent-src/rules/no-council-references.md +76 -0
  95. package/.agent-src/rules/no-roadmap-references.md +7 -0
  96. package/.agent-src/rules/non-destructive-by-default.md +13 -43
  97. package/.agent-src/rules/onboarding-gate.md +9 -117
  98. package/.agent-src/rules/package-ci-checks.md +10 -37
  99. package/.agent-src/rules/php-coding.md +10 -55
  100. package/.agent-src/rules/preservation-guard.md +9 -0
  101. package/.agent-src/rules/review-routing-awareness.md +9 -97
  102. package/.agent-src/rules/reviewer-awareness.md +8 -83
  103. package/.agent-src/rules/roadmap-progress-sync.md +7 -170
  104. package/.agent-src/rules/role-mode-adherence.md +6 -2
  105. package/.agent-src/rules/rule-type-governance.md +8 -66
  106. package/.agent-src/rules/runtime-safety.md +5 -0
  107. package/.agent-src/rules/scope-control.md +17 -62
  108. package/.agent-src/rules/security-sensitive-stop.md +7 -1
  109. package/.agent-src/rules/size-enforcement.md +6 -1
  110. package/.agent-src/rules/skill-improvement-trigger.md +9 -49
  111. package/.agent-src/rules/skill-quality.md +7 -113
  112. package/.agent-src/rules/slash-command-routing-policy.md +11 -63
  113. package/.agent-src/rules/think-before-action.md +22 -87
  114. package/.agent-src/rules/token-efficiency.md +10 -74
  115. package/.agent-src/rules/token-optimizer-maintenance.md +68 -0
  116. package/.agent-src/rules/tool-safety.md +4 -0
  117. package/.agent-src/rules/ui-audit-gate.md +25 -61
  118. package/.agent-src/rules/upstream-proposal.md +9 -67
  119. package/.agent-src/rules/user-interaction.md +22 -108
  120. package/.agent-src/rules/verify-before-complete.md +1 -1
  121. package/.agent-src/skills/adversarial-review/SKILL.md +1 -0
  122. package/.agent-src/skills/agent-docs-writing/SKILL.md +1 -1
  123. package/.agent-src/skills/ai-council/SKILL.md +197 -8
  124. package/.agent-src/skills/analysis-autonomous-mode/SKILL.md +1 -1
  125. package/.agent-src/skills/analysis-skill-router/SKILL.md +3 -3
  126. package/.agent-src/skills/artisan-commands/SKILL.md +2 -2
  127. package/.agent-src/skills/authz-review/SKILL.md +1 -1
  128. package/.agent-src/skills/aws-infrastructure/SKILL.md +5 -5
  129. package/.agent-src/skills/blast-radius-analyzer/SKILL.md +8 -8
  130. package/.agent-src/skills/bug-analyzer/SKILL.md +6 -5
  131. package/.agent-src/skills/code-refactoring/SKILL.md +4 -4
  132. package/.agent-src/skills/code-review/SKILL.md +2 -2
  133. package/.agent-src/skills/command-writing/SKILL.md +11 -0
  134. package/.agent-src/skills/composer-packages/SKILL.md +2 -2
  135. package/.agent-src/skills/context-authoring/SKILL.md +11 -0
  136. package/.agent-src/skills/context-document/SKILL.md +1 -1
  137. package/.agent-src/skills/copilot-agents-optimization/SKILL.md +23 -0
  138. package/.agent-src/skills/copilot-config/SKILL.md +1 -1
  139. package/.agent-src/skills/dependency-upgrade/SKILL.md +2 -2
  140. package/.agent-src/skills/devcontainer/SKILL.md +2 -2
  141. package/.agent-src/skills/developer-like-execution/SKILL.md +1 -1
  142. package/.agent-src/skills/docker/SKILL.md +1 -1
  143. package/.agent-src/skills/dto-creator/SKILL.md +1 -1
  144. package/.agent-src/skills/estimate-ticket/SKILL.md +2 -2
  145. package/.agent-src/skills/fe-design/SKILL.md +4 -4
  146. package/.agent-src/skills/feature-planning/SKILL.md +5 -5
  147. package/.agent-src/skills/funnel-analysis/SKILL.md +1 -1
  148. package/.agent-src/skills/laravel/SKILL.md +1 -1
  149. package/.agent-src/skills/laravel-notifications/SKILL.md +5 -5
  150. package/.agent-src/skills/laravel-pennant/SKILL.md +1 -1
  151. package/.agent-src/skills/laravel-pulse/SKILL.md +4 -4
  152. package/.agent-src/skills/laravel-reverb/SKILL.md +2 -2
  153. package/.agent-src/skills/laravel-scheduling/SKILL.md +1 -1
  154. package/.agent-src/skills/migration-creator/SKILL.md +7 -7
  155. package/.agent-src/skills/multi-tenancy/SKILL.md +8 -8
  156. package/.agent-src/skills/performance-analysis/SKILL.md +3 -3
  157. package/.agent-src/skills/pest-testing/SKILL.md +6 -6
  158. package/.agent-src/skills/php-service/SKILL.md +2 -2
  159. package/.agent-src/skills/project-analysis-hypothesis-driven/SKILL.md +3 -3
  160. package/.agent-src/skills/project-analysis-react/SKILL.md +1 -1
  161. package/.agent-src/skills/project-analysis-symfony/SKILL.md +1 -1
  162. package/.agent-src/skills/project-analysis-zend-laminas/SKILL.md +2 -2
  163. package/.agent-src/skills/project-analyzer/SKILL.md +4 -4
  164. package/.agent-src/skills/prompt-optimizer/SKILL.md +108 -0
  165. package/.agent-src/skills/readme-reviewer/SKILL.md +1 -1
  166. package/.agent-src/skills/roadmap-management/SKILL.md +7 -7
  167. package/.agent-src/skills/rule-writing/SKILL.md +33 -0
  168. package/.agent-src/skills/sentry-integration/SKILL.md +1 -1
  169. package/.agent-src/skills/skill-writing/SKILL.md +14 -0
  170. package/.agent-src/skills/systematic-debugging/SKILL.md +22 -2
  171. package/.agent-src/skills/technical-specification/SKILL.md +58 -1
  172. package/.agent-src/skills/terraform/SKILL.md +2 -2
  173. package/.agent-src/skills/terragrunt/SKILL.md +8 -8
  174. package/.agent-src/skills/test-performance/SKILL.md +5 -5
  175. package/.agent-src/skills/threat-modeling/SKILL.md +3 -2
  176. package/.agent-src/skills/token-optimizer/SKILL.md +110 -0
  177. package/.agent-src/skills/universal-project-analysis/SKILL.md +1 -1
  178. package/.agent-src/templates/AGENTS.md +1 -1
  179. package/.agent-src/templates/agent-settings.md +35 -19
  180. package/.agent-src/templates/command.md +17 -1
  181. package/.agent-src/templates/contexts/tenant-boundaries.md +2 -2
  182. package/.agent-src/templates/contexts.md +1 -1
  183. package/.agent-src/templates/copilot-instructions.md +21 -0
  184. package/.agent-src/templates/copilot-review-instructions.md +76 -0
  185. package/.agent-src/templates/features.md +1 -1
  186. package/.agent-src/templates/roadmaps.md +10 -2
  187. package/.agent-src/templates/rule.md +129 -0
  188. package/.agent-src/templates/skill.md +17 -0
  189. package/.claude-plugin/marketplace.json +12 -2
  190. package/AGENTS.md +32 -5
  191. package/CHANGELOG.md +107 -3
  192. package/README.md +22 -21
  193. package/config/agent-settings.template.yml +66 -10
  194. package/config/gitignore-block.txt +7 -0
  195. package/docs/architecture.md +86 -5
  196. package/docs/catalog.md +16 -6
  197. package/docs/contracts/agent-memory-contract.md +1 -1
  198. package/docs/contracts/command-clusters.md +45 -1
  199. package/docs/contracts/context-paths.md +2 -1
  200. package/docs/contracts/file-ownership-matrix.json +354 -500
  201. package/docs/contracts/iron-law-overrides.txt +25 -0
  202. package/docs/contracts/kernel-membership.md +273 -0
  203. package/docs/contracts/load-context-schema.md +26 -11
  204. package/docs/contracts/pilot/agent-authority.md +24 -0
  205. package/docs/contracts/pilot/direct-answers.md +70 -0
  206. package/docs/contracts/pilot/language-and-tone.md +63 -0
  207. package/docs/contracts/rule-classification.md +170 -0
  208. package/docs/contracts/rule-router.md +153 -0
  209. package/docs/customization.md +17 -6
  210. package/docs/decisions/ADR-001-kernel-swap-deferred.md +109 -0
  211. package/docs/decisions/ADR-002-kernel-bucket-overrides.md +124 -0
  212. package/docs/decisions/ADR-003-flat-cluster-subs-and-colon-syntax.md +126 -0
  213. package/docs/decisions/ADR-rule-kernel-and-router.md +122 -0
  214. package/docs/getting-started.md +2 -2
  215. package/docs/guidelines/agent-infra/naming.md +1 -1
  216. package/docs/guidelines/agent-infra/roadmap-progress-mechanics.md +176 -0
  217. package/docs/guidelines/agent-infra/rule-type-governance.md +73 -0
  218. package/docs/guidelines/agent-infra/size-and-scope.md +13 -2
  219. package/docs/guidelines/agent-infra/skill-quality-checklist.md +119 -0
  220. package/docs/guidelines/augment-portability-patterns.md +68 -0
  221. package/docs/guidelines/php/php-coding-patterns.md +62 -0
  222. package/package.json +1 -1
  223. package/scripts/_p43_bodies.py +235 -0
  224. package/scripts/_p43_compress.py +118 -0
  225. package/scripts/_p4_migrate.py +199 -0
  226. package/scripts/_phase2_shim_helper.py +1 -1
  227. package/scripts/_pilot_council_question.py +57 -0
  228. package/scripts/_pilot_measure.py +53 -0
  229. package/scripts/ai_council/session.py +107 -5
  230. package/scripts/build_linear_digest.py +3 -5
  231. package/scripts/check_always_budget.py +39 -6
  232. package/scripts/check_compressed_paths.py +213 -0
  233. package/scripts/check_compression.py +15 -0
  234. package/scripts/check_context_paths.py +1 -0
  235. package/scripts/check_council_layout.py +105 -0
  236. package/scripts/check_council_references.py +145 -0
  237. package/scripts/check_portability.py +2 -0
  238. package/scripts/check_references.py +2 -0
  239. package/scripts/check_token_optimizer_freshness.py +131 -0
  240. package/scripts/compile_router.py +148 -0
  241. package/scripts/compress.py +219 -11
  242. package/scripts/council_cli.py +132 -11
  243. package/scripts/council_prune.py +81 -0
  244. package/scripts/count_token_optimizer_usage.sh +54 -0
  245. package/scripts/install.sh +44 -2
  246. package/scripts/iron_law_sha.py +98 -0
  247. package/scripts/lint_load_context.py +35 -5
  248. package/scripts/measure_rule_budget.py +314 -0
  249. package/scripts/migrate_command_suggestions.py +2 -2
  250. package/scripts/prototype_lint_contradictions.py +150 -0
  251. package/scripts/schemas/command.schema.json +5 -0
  252. package/scripts/schemas/rule.schema.json +60 -6
  253. package/scripts/schemas/skill.schema.json +5 -0
  254. package/scripts/skill_linter.py +197 -7
  255. package/scripts/smoke_path_resolution.py +93 -0
  256. package/scripts/validate_frontmatter.py +41 -1
  257. package/.agent-src/commands/roadmap/execute.md +0 -109
  258. package/.agent-src/contexts/communication/rules-auto/artifact-engagement-recording-mechanics.md +0 -72
  259. package/.agent-src/contexts/communication/rules-auto/augment-portability-mechanics.md +0 -79
  260. package/.agent-src/contexts/communication/rules-auto/cli-output-handling-mechanics.md +0 -87
  261. package/.agent-src/contexts/communication/rules-auto/command-suggestion-policy-mechanics.md +0 -62
  262. package/.agent-src/contexts/communication/rules-auto/docs-sync-mechanics.md +0 -78
  263. package/.agent-src/contexts/communication/rules-auto/package-ci-checks-mechanics.md +0 -85
  264. package/.agent-src/contexts/communication/rules-auto/review-routing-awareness-mechanics.md +0 -65
  265. package/.agent-src/contexts/communication/rules-auto/roadmap-progress-sync-mechanics.md +0 -78
  266. package/.agent-src/contexts/communication/rules-auto/ui-audit-gate-mechanics.md +0 -53
  267. /package/{docs → .agent-src/contexts}/contracts/artifact-engagement-flow.md +0 -0
  268. /package/{docs → .agent-src/contexts}/contracts/command-suggestion-flow.md +0 -0
@@ -0,0 +1,119 @@
1
+ # Skill Quality
2
+
3
+ > Creating, editing, or reviewing skills — minimum quality standard, every skill must be executable, validated, and self-contained
4
+
5
+ _Origin: migrated from `.agent-src.uncompressed/rules/skill-quality.md` per P4.2 of `road-to-kernel-and-router.md`._
6
+
7
+ # Skill Quality
8
+
9
+ ## Minimum Sharpness
10
+
11
+ Every skill must answer four questions. If ANY answer is weak, the skill is not done.
12
+
13
+ | # | Question | Section | Standard |
14
+ |---|---|---|---|
15
+ | 1 | When should I use this? | `When to use` | Concrete trigger, not generic |
16
+ | 2 | What exactly do I do? | `Procedure` | Executable steps with decisions |
17
+ | 3 | How do I verify it worked? | `Procedure` (validation step) | Concrete checks, not "verify it works" |
18
+ | 4 | What common failure must I avoid? | `Gotcha` + `Do NOT` | Real failure patterns, not platitudes |
19
+
20
+ ## Required Sections
21
+
22
+ Every skill MUST have: `When to use`, `Procedure`, `Gotcha`, `Output format`, `Do NOT`.
23
+
24
+ ## Frontmatter Contract
25
+
26
+ Every skill's YAML frontmatter MUST validate against `scripts/schemas/skill.schema.json`.
27
+ Violations are reported by `scripts/skill_linter.py` as `schema_<rule>` errors
28
+ and fail `python3 scripts/validate_frontmatter.py` and the full CI pipeline.
29
+
30
+ ## Description Triggering
31
+
32
+ Claude routes skills by their frontmatter `description`. Pushy,
33
+ trigger-rich descriptions are required — polite or hedged ones cause
34
+ undertriggering. The full recipe (concrete verb phrase, ≥2 triggers,
35
+ `even if they don't explicitly ask for …` tail, ≤200 chars,
36
+ litmus test) lives in
37
+ [`contexts/communication/rules-auto/skill-quality-mechanics.md`](../contexts/communication/rules-auto/skill-quality-mechanics.md)
38
+ § Description Triggering.
39
+
40
+ ## Skill Independence
41
+
42
+ ```
43
+ If a skill is not executable without opening a guideline, it is broken.
44
+ ```
45
+
46
+ - Skills MAY reference guidelines for detailed conventions
47
+ - Skills MUST NOT outsource their core workflow to guidelines
48
+ - If removing guideline references makes the skill useless → the skill is too weak
49
+
50
+ **Litmus test:** Cover all guideline references in the Procedure. Is it still executable?
51
+ If not → the skill needs more own steps, decisions, and validation — not more guideline links.
52
+
53
+ ## Merge & Compression Preservation
54
+
55
+ When merging or compressing skills, the result MUST preserve the
56
+ strongest validation, strongest examples, all anti-patterns, all
57
+ decision criteria, and trigger quality. Full preservation invariants
58
+ and "merge is invalid if …" / "compression may remove …" lists in
59
+ [`contexts/communication/rules-auto/skill-quality-mechanics.md`](../contexts/communication/rules-auto/skill-quality-mechanics.md)
60
+ § Merge Preservation and § Compression Preservation.
61
+
62
+ ## Refactor Safety
63
+
64
+ When refactoring or optimizing skills:
65
+
66
+ - NEVER weaken validation to pass linter
67
+ - NEVER remove anti-patterns to reduce size
68
+ - NEVER replace concrete checks with "verify it works"
69
+ - NEVER merge skills if the result is broader than either source
70
+ - ALWAYS run linter before and after — fail count must not increase
71
+
72
+ ## Senior-Tier Required Structure
73
+
74
+ Skills with `tier: senior` in YAML frontmatter MUST carry four named
75
+ blocks beyond the standard required sections:
76
+
77
+ | # | Block | Heading / Location | Standard |
78
+ |---|---|---|---|
79
+ | 1 | Context-First lead | Frontmatter `description` | First sentence anchors the cognition cluster (domain + senior role); second sentence names the trigger. |
80
+ | 2 | Related Skills | `## Related Skills` | Two-list pattern — `**WHEN to use this**` (situations this skill resolves) + `**WHEN NOT to use this**` (route-elsewhere peers, named). |
81
+ | 3 | Proactive Triggers | `## When the agent should load this` | 3–5 concrete user-prompt patterns (paraphrases users actually type), not abstract categories. |
82
+ | 4 | Output Artifacts | `## Output` | 1–4 named artifacts with shape (file path, table, markdown structure) — orchestrator-citable identifier each. |
83
+
84
+ **Forward-only.** `scripts/skill_linter.py` enforces these blocks for
85
+ `tier: senior` skills only; mid-tier and untiered skills skip the
86
+ check. No retrofit pass on existing Wing-1 skills.
87
+
88
+ Subsection specs (≤ 6-line spec + 1 reference example each), good /
89
+ bad pattern pairs, and the WHEN-NOT routing peer rules live in
90
+ [`contexts/communication/rules-auto/skill-quality-mechanics.md`](../contexts/communication/rules-auto/skill-quality-mechanics.md)
91
+ § Senior-tier patterns.
92
+
93
+ ## Structural Malice Floor
94
+
95
+ `scripts/skill_linter.py` runs five regex patterns against every
96
+ skill / rule / command body — credential exfiltration, remote
97
+ execution, force-push to a protected ref, world-readable secret
98
+ files, and shell-injection in subprocess calls. A match emits
99
+ ``Issue("error", "malice:<pattern>", "<line>:<matched>")`` and the
100
+ linter exits with code **3** (security-failure), distinct from
101
+ exit 2 (build-failure) so CI surfaces can split the two.
102
+
103
+ The check is **structural**, not semantic — it catches the shapes
104
+ the [`tool-safety`](tool-safety.md) rule denies in prose: hidden
105
+ credentials, arbitrary execution, write-without-approval. Fixtures
106
+ and the exit-code-3 contract live in
107
+ [`tests/test_skill_linter_malice.py`](../../tests/test_skill_linter_malice.py).
108
+
109
+ ## Confidence Tagging
110
+
111
+ Senior-tier procedure steps MAY append `[CONFIDENCE: high|medium|low]`
112
+ at the end of multi-step chains where the agent's evidence varies
113
+ across steps. Optional but recommended when a step's output feeds a
114
+ downstream decision.
115
+
116
+ Text-tag form is deliberate. Emoji 🟢 / 🟡 / 🔴 is **not** allowed —
117
+ collides with [`direct-answers`](direct-answers.md) § Emoji scope
118
+ (functional markers only). Linter does not enforce the tag itself;
119
+ the rule documents the placement so authors converge on one form.
@@ -0,0 +1,68 @@
1
+ # Augment Portability
2
+
3
+ > Editing or creating files inside .augment/ directory — skills, rules, commands, templates, contexts must be project-agnostic
4
+
5
+ _Origin: migrated from `.agent-src.uncompressed/rules/augment-portability.md` per P4.2 of `road-to-kernel-and-router.md`._
6
+
7
+ # Package Portability
8
+
9
+ Everything that ships with the `event4u/agent-config` package MUST be
10
+ **project-agnostic**. That includes:
11
+
12
+ - Everything inside `.augment/` (skills, rules, commands, guidelines,
13
+ templates, contexts)
14
+ - The package repo's own root `AGENTS.md`
15
+ - The package repo's own `.github/copilot-instructions.md`
16
+
17
+ All three are either installed into consumer projects (`.augment/` via
18
+ `install.sh`) or read by AI tools when working on the package itself
19
+ (`AGENTS.md`, `copilot-instructions.md`). Leaking consumer-specific
20
+ content into any of them pollutes downstream projects or misleads agents.
21
+
22
+ ## Rules
23
+
24
+ - NEVER reference a specific consumer project, repo name, domain, or tech
25
+ stack directly. The package repo itself (`event4u/agent-config`) MAY be
26
+ named inside its own root `AGENTS.md` and `copilot-instructions.md` —
27
+ that is meta about the package, not a leak.
28
+ - NEVER hardcode consumer-project paths, class names, or conventions.
29
+ - Write content so it works as a **reusable package** across any project.
30
+ - Project-specific behavior belongs in the **consumer's** `.agent-settings.yml`,
31
+ `AGENTS.md`, or `agents/` — never in files shipped by this package.
32
+ - If a skill or rule needs project-specific input, read it from
33
+ `.agent-settings.yml` or accept it as a parameter.
34
+ - When reviewing or editing package files, always ask: "Would this still
35
+ make sense in a completely different project?"
36
+
37
+ ## Runtime invocations — no `task` commands
38
+
39
+ Skills, rules, commands, guidelines, personas, and context docs run in
40
+ **consumer projects**, which may not have Task installed. **Never**
41
+ reference a `task <something>` invocation inside any artefact file
42
+ under `.agent-src.uncompressed/{skills,rules,commands,guidelines,personas,contexts}/`
43
+ (and therefore also not in the compressed mirror under `.agent-src/`).
44
+ Use direct script invocations instead.
45
+
46
+ ## Consumer CLI — `./agent-config`
47
+
48
+ A subset of package scripts is exposed through a project-local CLI
49
+ wrapper `./agent-config` (written into the project root by the
50
+ installer, gitignored). Artefacts MUST prefer the CLI over raw
51
+ `python3 scripts/…` paths for every command the CLI already covers.
52
+
53
+ ## Translation tables — see mechanics
54
+
55
+ The full `task`-to-script translation table, the `./agent-config`
56
+ CLI mapping, and the rationale (Task absence on consumers,
57
+ maintainer-vs-artefact split) all live in
58
+ [`contexts/communication/rules-auto/augment-portability-mechanics.md`](../contexts/communication/rules-auto/augment-portability-mechanics.md).
59
+ Pull it whenever an artefact is about to mention a runtime
60
+ invocation.
61
+
62
+ ## Enforcement
63
+
64
+ `scripts/check_portability.py` scans `.augment/`, `.agent-src.uncompressed/`,
65
+ and the package repo's root `AGENTS.md` + `.github/copilot-instructions.md`
66
+ for forbidden identifiers, for any `task <name>` invocation inside
67
+ artefact files, and for direct script invocations that bypass the
68
+ `./agent-config` CLI. It runs in CI and must pass before any PR.
@@ -0,0 +1,62 @@
1
+ # Php Coding
2
+
3
+ > Writing or reviewing PHP code — strict types, naming, comparisons, early returns, Eloquent conventions
4
+
5
+ _Origin: migrated from `.agent-src.uncompressed/rules/php-coding.md` per P4.2 of `road-to-kernel-and-router.md`._
6
+
7
+ # PHP Coding Rules
8
+
9
+ - Use `declare(strict_types=1)` in every **new** PHP file. Not required when modifying existing files that don't have it.
10
+ - If the project has a `Math` helper class, use it for ALL business calculations. Never use native PHP arithmetic operators (`+`, `-`, `*`, `/`) for business calculations. Search for the `Math` class in the project.
11
+ - Never use `var_dump()`, `print_r()`, or `dd()` — they are disallowed by PHPStan config. Exception: legacy projects where these are already used and no alternative is feasible.
12
+ - Never use `float` for money — use `decimal` or the `Math` helper.
13
+ - Always use `===` / `!==` (strict comparison), Yoda style: `null === $var`.
14
+ - Early return over nested if/else.
15
+ - No one-liner if statements.
16
+ - Single quotes for strings without interpolation. `sprintf()` for complex strings.
17
+ - Variables: `camelCase`. Array keys: `snake_case`. Constants: `UPPER_SNAKE_CASE`.
18
+ - Typed properties, parameters, and return types — always.
19
+ - Constructor property promotion where it makes sense.
20
+
21
+ ## Eloquent Models — Attribute Access
22
+
23
+ Read `eloquent.access_style` from `.agent-settings.yml` to determine the preferred style.
24
+ Default: `getters_setters`. See the `eloquent` skill for the full reference table and examples.
25
+
26
+ - **`getters_setters`** (strict): Every attribute has a typed getter + fluent setter. Inside the model: `getAttribute('column_name')`/`setAttribute('column_name', $value)`. Outside: always getters/setters. If a getter doesn't exist yet, create it first.
27
+ - **`get_attribute`**: Use `getAttribute('column_name')`/`setAttribute('column_name', $value)` everywhere, no getters/setters needed.
28
+ - **`magic_properties`**: Laravel default `$model->column_name` everywhere.
29
+
30
+ ### Relationship Getters
31
+
32
+ - Every relationship MUST have a typed getter method **above** the relationship method.
33
+ - **Inside the getter:** use `$this->getAttribute('relationship_name')`, NEVER `$this->relationship_name`.
34
+ - **Outside the model:** ALWAYS use the getter (`$model->getEquipment()`), NEVER access the magic property (`$model->equipment`).
35
+ - Use `instanceof` checks instead of `null ===` when checking relationship results.
36
+
37
+ ## Eloquent Models — Observers over `booted()`
38
+
39
+ - Do NOT use `booted()` / `boot()` for model lifecycle hooks (saving, saved, deleted, etc.).
40
+ - Use a dedicated **Observer** class registered via `#[ObservedBy]` attribute.
41
+ - This keeps models slim and lifecycle logic testable and discoverable.
42
+
43
+ ## PHPStan
44
+
45
+ - Always fix the root cause. Do NOT add entries to `phpstan-baseline.neon`.
46
+ - Adding `ignoreErrors` to `phpstan.neon` is allowed for **structural toolchain limitations** (e.g., Pest runtime bindings). NOT for individual code issues. **If unsure → ask the user.**
47
+ - If a fix is truly impossible (confirmed false positive), use an inline ignore as last resort:
48
+ ```php
49
+ // @phpstan-ignore-next-line — false positive: reason here
50
+ ```
51
+
52
+ ## Testing
53
+
54
+ - Always write tests in **Pest**, not PHPUnit class syntax — unless the user explicitly asks for PHPUnit.
55
+ - Pest tests in `tests/Unit/` automatically use `UnitTestCase` as the base class (configured in `tests/Pest.php`).
56
+
57
+ ## PHPDoc
58
+
59
+ - Only add PHPDoc when type hints are insufficient (e.g. generic arrays: `@param array<int, MyObject> $items`).
60
+ - Do NOT add PHPDoc that just repeats the method signature.
61
+ - One docblock per method — never split into multiple `/** */` blocks.
62
+ - Tag order: `@param` → `@return` → `@throws`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@event4u/agent-config",
3
- "version": "1.20.0",
3
+ "version": "1.22.0",
4
4
  "description": "Shared agent configuration \u2014 skills, rules, commands, guidelines, and templates for AI coding tools",
5
5
  "license": "MIT",
6
6
  "private": false,
@@ -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")