@rune-kit/rune 2.10.0 → 2.12.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 (240) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +65 -6
  3. package/commands/rune.md +168 -168
  4. package/compiler/__tests__/detect-invariants.test.js +136 -0
  5. package/compiler/__tests__/doctor-mesh.test.js +229 -0
  6. package/compiler/__tests__/hook-dispatch.test.js +91 -0
  7. package/compiler/__tests__/hooks-antigravity.test.js +118 -0
  8. package/compiler/__tests__/hooks-cursor.test.js +139 -0
  9. package/compiler/__tests__/hooks-install.test.js +305 -0
  10. package/compiler/__tests__/hooks-merge.test.js +204 -0
  11. package/compiler/__tests__/hooks-tiers.test.js +519 -0
  12. package/compiler/__tests__/hooks-windsurf.test.js +115 -0
  13. package/compiler/__tests__/inject-claude-md.test.js +152 -0
  14. package/compiler/__tests__/load-invariants.test.js +408 -0
  15. package/compiler/__tests__/onboard-invariants.test.js +240 -0
  16. package/compiler/adapters/hooks/antigravity.js +140 -0
  17. package/compiler/adapters/hooks/claude.js +166 -0
  18. package/compiler/adapters/hooks/cursor.js +191 -0
  19. package/compiler/adapters/hooks/index.js +82 -0
  20. package/compiler/adapters/hooks/tier-emitter.js +182 -0
  21. package/compiler/adapters/hooks/windsurf.js +202 -0
  22. package/compiler/bin/rune.js +196 -6
  23. package/compiler/commands/hook-dispatch.js +87 -0
  24. package/compiler/commands/hooks/install.js +120 -0
  25. package/compiler/commands/hooks/merge.js +211 -0
  26. package/compiler/commands/hooks/presets.js +116 -0
  27. package/compiler/commands/hooks/status.js +112 -0
  28. package/compiler/commands/hooks/tiers.js +221 -0
  29. package/compiler/commands/hooks/uninstall.js +94 -0
  30. package/compiler/doctor.js +236 -0
  31. package/contexts/dev.md +34 -34
  32. package/contexts/research.md +43 -43
  33. package/contexts/review.md +55 -55
  34. package/extensions/ai-ml/PACK.md +88 -88
  35. package/extensions/ai-ml/skills/ai-agents.md +172 -172
  36. package/extensions/ai-ml/skills/code-sandbox.md +187 -187
  37. package/extensions/ai-ml/skills/deep-research.md +146 -146
  38. package/extensions/ai-ml/skills/embedding-search.md +66 -66
  39. package/extensions/ai-ml/skills/fine-tuning-guide.md +74 -74
  40. package/extensions/ai-ml/skills/llm-architect.md +125 -125
  41. package/extensions/ai-ml/skills/llm-integration.md +64 -64
  42. package/extensions/ai-ml/skills/prompt-patterns.md +72 -72
  43. package/extensions/ai-ml/skills/rag-patterns.md +66 -66
  44. package/extensions/ai-ml/skills/web-extraction.md +114 -114
  45. package/extensions/analytics/PACK.md +92 -92
  46. package/extensions/analytics/skills/ab-testing.md +72 -72
  47. package/extensions/analytics/skills/dashboard-patterns.md +83 -83
  48. package/extensions/analytics/skills/data-validation.md +68 -68
  49. package/extensions/analytics/skills/funnel-analysis.md +81 -81
  50. package/extensions/analytics/skills/sql-patterns.md +57 -57
  51. package/extensions/analytics/skills/statistical-analysis.md +79 -79
  52. package/extensions/analytics/skills/tracking-setup.md +71 -71
  53. package/extensions/backend/PACK.md +104 -104
  54. package/extensions/backend/skills/api-patterns.md +84 -84
  55. package/extensions/backend/skills/async-pipeline.md +193 -193
  56. package/extensions/backend/skills/auth-patterns.md +97 -97
  57. package/extensions/backend/skills/background-jobs.md +133 -133
  58. package/extensions/backend/skills/caching-patterns.md +108 -108
  59. package/extensions/backend/skills/cli-generation.md +133 -133
  60. package/extensions/backend/skills/database-patterns.md +87 -87
  61. package/extensions/backend/skills/middleware-patterns.md +104 -104
  62. package/extensions/chrome-ext/PACK.md +93 -93
  63. package/extensions/chrome-ext/skills/cws-preflight.md +143 -143
  64. package/extensions/chrome-ext/skills/cws-publish.md +104 -104
  65. package/extensions/chrome-ext/skills/ext-ai-integration.md +251 -251
  66. package/extensions/chrome-ext/skills/ext-messaging.md +139 -139
  67. package/extensions/chrome-ext/skills/ext-storage.md +133 -133
  68. package/extensions/chrome-ext/skills/mv3-scaffold.md +164 -164
  69. package/extensions/content/PACK.md +96 -96
  70. package/extensions/content/skills/blog-patterns.md +88 -88
  71. package/extensions/content/skills/cms-integration.md +131 -131
  72. package/extensions/content/skills/content-scoring.md +107 -107
  73. package/extensions/content/skills/i18n.md +83 -83
  74. package/extensions/content/skills/mdx-authoring.md +137 -137
  75. package/extensions/content/skills/reference.md +1014 -1014
  76. package/extensions/content/skills/seo-patterns.md +67 -67
  77. package/extensions/content/skills/video-repurpose.md +153 -153
  78. package/extensions/devops/PACK.md +101 -101
  79. package/extensions/devops/skills/chaos-testing.md +67 -67
  80. package/extensions/devops/skills/ci-cd.md +75 -75
  81. package/extensions/devops/skills/docker.md +58 -58
  82. package/extensions/devops/skills/edge-serverless.md +163 -163
  83. package/extensions/devops/skills/infra-as-code.md +158 -158
  84. package/extensions/devops/skills/kubernetes.md +110 -110
  85. package/extensions/devops/skills/monitoring.md +57 -57
  86. package/extensions/devops/skills/server-setup.md +64 -64
  87. package/extensions/devops/skills/ssl-domain.md +42 -42
  88. package/extensions/ecommerce/PACK.md +116 -116
  89. package/extensions/ecommerce/skills/cart-system.md +79 -79
  90. package/extensions/ecommerce/skills/inventory-mgmt.md +102 -102
  91. package/extensions/ecommerce/skills/order-management.md +126 -126
  92. package/extensions/ecommerce/skills/payment-integration.md +472 -472
  93. package/extensions/ecommerce/skills/shopify-dev.md +69 -69
  94. package/extensions/ecommerce/skills/subscription-billing.md +93 -93
  95. package/extensions/ecommerce/skills/tax-compliance.md +117 -117
  96. package/extensions/gamedev/PACK.md +142 -142
  97. package/extensions/gamedev/skills/asset-pipeline.md +74 -74
  98. package/extensions/gamedev/skills/audio-system.md +129 -129
  99. package/extensions/gamedev/skills/camera-system.md +87 -87
  100. package/extensions/gamedev/skills/ecs.md +98 -98
  101. package/extensions/gamedev/skills/game-loops.md +72 -72
  102. package/extensions/gamedev/skills/input-system.md +199 -199
  103. package/extensions/gamedev/skills/multiplayer.md +180 -180
  104. package/extensions/gamedev/skills/particles.md +105 -105
  105. package/extensions/gamedev/skills/physics-engine.md +89 -89
  106. package/extensions/gamedev/skills/scene-management.md +146 -146
  107. package/extensions/gamedev/skills/threejs-patterns.md +90 -90
  108. package/extensions/gamedev/skills/webgl.md +71 -71
  109. package/extensions/mobile/PACK.md +106 -106
  110. package/extensions/mobile/skills/app-store-connect.md +152 -152
  111. package/extensions/mobile/skills/app-store-prep.md +66 -66
  112. package/extensions/mobile/skills/deep-linking.md +109 -109
  113. package/extensions/mobile/skills/flutter.md +60 -60
  114. package/extensions/mobile/skills/ios-build-pipeline.md +142 -142
  115. package/extensions/mobile/skills/native-bridge.md +66 -66
  116. package/extensions/mobile/skills/ota-updates.md +97 -97
  117. package/extensions/mobile/skills/push-notifications.md +111 -111
  118. package/extensions/mobile/skills/react-native.md +82 -82
  119. package/extensions/saas/PACK.md +116 -116
  120. package/extensions/saas/skills/billing-integration.md +200 -200
  121. package/extensions/saas/skills/feature-flags.md +130 -130
  122. package/extensions/saas/skills/multi-tenant.md +103 -103
  123. package/extensions/saas/skills/onboarding-flow.md +139 -139
  124. package/extensions/saas/skills/subscription-flow.md +95 -95
  125. package/extensions/saas/skills/team-management.md +144 -144
  126. package/extensions/security/PACK.md +99 -99
  127. package/extensions/security/skills/api-security.md +140 -140
  128. package/extensions/security/skills/compliance.md +68 -68
  129. package/extensions/security/skills/owasp-audit.md +64 -64
  130. package/extensions/security/skills/pentest-patterns.md +77 -77
  131. package/extensions/security/skills/secret-mgmt.md +65 -65
  132. package/extensions/security/skills/supply-chain.md +65 -65
  133. package/extensions/trading/PACK.md +80 -80
  134. package/extensions/trading/skills/chart-components.md +55 -55
  135. package/extensions/trading/skills/experiment-loop.md +125 -125
  136. package/extensions/trading/skills/fintech-patterns.md +47 -47
  137. package/extensions/trading/skills/indicator-library.md +58 -58
  138. package/extensions/trading/skills/quant-analysis.md +111 -111
  139. package/extensions/trading/skills/realtime-data.md +58 -58
  140. package/extensions/trading/skills/trade-logic.md +104 -104
  141. package/extensions/ui/PACK.md +130 -130
  142. package/extensions/ui/skills/a11y-audit.md +91 -91
  143. package/extensions/ui/skills/animation-patterns.md +127 -127
  144. package/extensions/ui/skills/component-patterns.md +100 -100
  145. package/extensions/ui/skills/design-decision.md +108 -108
  146. package/extensions/ui/skills/design-system.md +68 -68
  147. package/extensions/ui/skills/landing-patterns.md +155 -155
  148. package/extensions/ui/skills/palette-picker.md +173 -173
  149. package/extensions/ui/skills/react-health.md +90 -90
  150. package/extensions/ui/skills/type-system.md +125 -125
  151. package/extensions/ui/skills/web-vitals.md +153 -153
  152. package/extensions/zalo/PACK.md +145 -145
  153. package/extensions/zalo/skills/zalo-oa-mcp.md +317 -317
  154. package/extensions/zalo/skills/zalo-oa-messaging.md +429 -429
  155. package/extensions/zalo/skills/zalo-oa-setup.md +236 -236
  156. package/extensions/zalo/skills/zalo-oa-webhook.md +189 -189
  157. package/extensions/zalo/skills/zalo-personal-messaging.md +194 -194
  158. package/extensions/zalo/skills/zalo-personal-setup.md +153 -153
  159. package/extensions/zalo/skills/zalo-rate-guard.md +219 -219
  160. package/hooks/auto-format/index.cjs +48 -48
  161. package/hooks/hooks.json +111 -111
  162. package/hooks/post-session-reflect/index.cjs +189 -189
  163. package/hooks/pre-compact/index.cjs +95 -95
  164. package/hooks/run-hook.cmd +1 -1
  165. package/hooks/secrets-scan/index.cjs +100 -100
  166. package/hooks/session-start/index.cjs +71 -71
  167. package/hooks/typecheck/index.cjs +65 -65
  168. package/package.json +63 -63
  169. package/references/ui-pro-max-data/LICENSE-UI-PRO-MAX +21 -21
  170. package/references/ui-pro-max-data/charts.csv +26 -26
  171. package/references/ui-pro-max-data/colors.csv +161 -161
  172. package/references/ui-pro-max-data/styles.csv +68 -68
  173. package/references/ui-pro-max-data/typography.csv +74 -74
  174. package/references/ui-pro-max-data/ui-reasoning.csv +162 -162
  175. package/references/ui-pro-max-data/ux-guidelines.csv +99 -99
  176. package/skills/adversary/SKILL.md +283 -283
  177. package/skills/asset-creator/SKILL.md +157 -157
  178. package/skills/audit/SKILL.md +147 -2
  179. package/skills/autopsy/SKILL.md +335 -335
  180. package/skills/ba/SKILL.md +85 -1
  181. package/skills/brainstorm/SKILL.md +380 -342
  182. package/skills/browser-pilot/SKILL.md +169 -168
  183. package/skills/constraint-check/SKILL.md +165 -165
  184. package/skills/context-engine/SKILL.md +408 -404
  185. package/skills/cook/SKILL.md +917 -863
  186. package/skills/db/SKILL.md +273 -273
  187. package/skills/debug/SKILL.md +465 -465
  188. package/skills/dependency-doctor/SKILL.md +265 -235
  189. package/skills/deploy/SKILL.md +274 -231
  190. package/skills/design/DESIGN-REFERENCE.md +365 -365
  191. package/skills/design/SKILL.md +590 -589
  192. package/skills/doc-processor/SKILL.md +254 -254
  193. package/skills/docs/SKILL.md +374 -374
  194. package/skills/docs-seeker/SKILL.md +178 -177
  195. package/skills/fix/SKILL.md +332 -330
  196. package/skills/git/SKILL.md +339 -339
  197. package/skills/hallucination-guard/SKILL.md +220 -219
  198. package/skills/incident/SKILL.md +254 -253
  199. package/skills/integrity-check/SKILL.md +169 -169
  200. package/skills/journal/SKILL.md +241 -240
  201. package/skills/launch/SKILL.md +344 -344
  202. package/skills/logic-guardian/SKILL.md +269 -251
  203. package/skills/marketing/SKILL.md +351 -289
  204. package/skills/mcp-builder/SKILL.md +425 -425
  205. package/skills/neural-memory/SKILL.md +359 -362
  206. package/skills/onboard/SKILL.md +432 -403
  207. package/skills/onboard/references/invariants-template.md +76 -0
  208. package/skills/onboard/scripts/detect-invariants.js +439 -0
  209. package/skills/onboard/scripts/inject-claude-md.js +150 -0
  210. package/skills/onboard/scripts/onboard-invariants.js +194 -0
  211. package/skills/perf/SKILL.md +347 -346
  212. package/skills/plan/SKILL.md +435 -428
  213. package/skills/preflight/SKILL.md +415 -415
  214. package/skills/problem-solver/SKILL.md +380 -284
  215. package/skills/rescue/SKILL.md +474 -474
  216. package/skills/research/SKILL.md +4 -0
  217. package/skills/retro/SKILL.md +3 -1
  218. package/skills/review/SKILL.md +614 -588
  219. package/skills/review-intake/SKILL.md +249 -249
  220. package/skills/safeguard/SKILL.md +200 -200
  221. package/skills/sast/SKILL.md +190 -190
  222. package/skills/scaffold/SKILL.md +328 -287
  223. package/skills/scope-guard/SKILL.md +183 -180
  224. package/skills/scout/SKILL.md +269 -263
  225. package/skills/sentinel/SKILL.md +384 -381
  226. package/skills/sentinel-env/SKILL.md +254 -254
  227. package/skills/sequential-thinking/SKILL.md +234 -234
  228. package/skills/session-bridge/SKILL.md +595 -543
  229. package/skills/session-bridge/scripts/load-invariants.js +397 -0
  230. package/skills/skill-forge/SKILL.md +581 -581
  231. package/skills/skill-router/SKILL.md +3 -0
  232. package/skills/slides/SKILL.md +19 -0
  233. package/skills/surgeon/SKILL.md +215 -215
  234. package/skills/team/SKILL.md +557 -537
  235. package/skills/test/SKILL.md +620 -614
  236. package/skills/trend-scout/SKILL.md +145 -145
  237. package/skills/verification/SKILL.md +334 -326
  238. package/skills/video-creator/SKILL.md +201 -201
  239. package/skills/watchdog/SKILL.md +168 -168
  240. package/skills/worktree/SKILL.md +140 -140
@@ -1,251 +1,269 @@
1
- ---
2
- name: logic-guardian
3
- description: Protects complex business logic from accidental deletion or overwrite. Maintains a logic manifest, enforces pre-edit gates, and validates post-edit diffs.
4
- metadata:
5
- author: runedev
6
- version: "0.1.0"
7
- layer: L2
8
- model: sonnet
9
- group: quality
10
- tools: "Read, Write, Edit, Glob, Grep"
11
- ---
12
-
13
- # logic-guardian
14
-
15
- ## Purpose
16
-
17
- Complex projects (trading bots, payment systems, game engines, state machines) contain interconnected logic that AI agents routinely destroy by accident. The pattern is always the same: new session starts, agent doesn't know existing logic, rewrites or deletes working code, project regresses. `logic-guardian` breaks this cycle by maintaining a machine-readable logic manifest, enforcing a pre-edit gate on logic files, and validating that edits don't silently remove existing logic. It is the "institutional memory" for business logic.
18
-
19
- ## Triggers
20
-
21
- - `/rune logic-guardian` — manual invocation (scan project, generate/update manifest)
22
- - Auto-trigger: when `cook` or `fix` targets a file listed in `.rune/logic-manifest.json`
23
- - Auto-trigger: when `surgeon` plans refactoring on logic-heavy modules
24
- - Auto-trigger: when `.rune/logic-manifest.json` exists in project root
25
-
26
- ## Calls (outbound connections)
27
-
28
- - `scout` (L2): scan project to discover logic files and extract function signatures
29
- - `verification` (L3): run tests after logic edits to confirm no regression
30
- - `hallucination-guard` (L3): verify that referenced functions/imports actually exist after edit
31
- - `journal` (L3): record logic changes as ADRs for cross-session persistence
32
- - `session-bridge` (L3): save manifest state so next session loads it immediately
33
-
34
- ## Called By (inbound connections)
35
-
36
- - `cook` (L1): Phase 1.5 — when complex logic project detected, load manifest before planning
37
- - `fix` (L2): pre-edit gatebefore modifying any file in the manifest
38
- - `surgeon` (L2): pre-refactor — before restructuring logic modules
39
- - `team` (L1): validate logic integrity across parallel workstreams
40
- - `review` (L2): check if reviewed diff removes or modifies manifested logic
41
-
42
- ## Workflow
43
-
44
- ### Phase 0 — Load or Initialize Manifest
45
-
46
- 1. Use `Read` on `.rune/logic-manifest.json`
47
- 2. If file exists:
48
- - Parse manifest, display summary: "Loaded logic manifest: N components, M functions, K parameters"
49
- - Proceed to Phase 1 (Validate)
50
- 3. If file does NOT exist:
51
- - Announce: "No logic manifest found. Scanning project to generate one."
52
- - Proceed to Phase 3 (Generate)
53
-
54
- ### Phase 1Validate Manifest Against Codebase
55
-
56
- Ensure the manifest matches the actual code (detect drift):
57
-
58
- 1. For each component in the manifest:
59
- - Use `Read` on the component's `file_path`
60
- - Verify each listed function exists (by name + signature match)
61
- - Check if any NEW functions exist in the file that aren't in the manifest
62
- 2. Report:
63
- - `SYNCED`manifest matches code perfectly
64
- - `DRIFT_DETECTED` — list specific discrepancies (missing functions, new unlisted functions, changed signatures)
65
- 3. If drift detected: ask user whether to update manifest or investigate changes
66
-
67
- ### Phase 2 Pre-Edit Gate (called by fix/surgeon/cook)
68
-
69
- Before ANY edit to a manifested file:
70
-
71
- 1. Load the manifest (Phase 0)
72
- 2. Display the affected component's current spec:
73
- ```
74
- COMPONENT: [name]
75
- STATUS: ACTIVE | TESTING | DEPRECATED
76
- FUNCTIONS: [list with one-line descriptions]
77
- PARAMETERS: [configurable values with current settings]
78
- DEPENDENCIES: [what other components depend on this]
79
- LAST_MODIFIED: [date]
80
- ```
81
- 3. Require the agent to explicitly state:
82
- - What it intends to change
83
- - What it will NOT change
84
- - Which existing functions/logic will be preserved
85
- 4. If the agent cannot list the existing functions → BLOCK the edit. Force a `Read` of the file first.
86
-
87
- ### Phase 3 Generate Manifest (first-time or rescan)
88
-
89
- Scan the project and build the manifest:
90
-
91
- 1. Use `scout` to find logic-heavy files:
92
- - Search for files with complex conditionals, state machines, strategy patterns
93
- - Look for files matching: `**/logic/**`, `**/strategy/**`, `**/engine/**`, `**/core/**`, `**/scenarios/**`, `**/rules/**`, `**/pipeline/**`, `**/trailing/**`, `**/signals/**`
94
- - Also search for files with high cyclomatic complexity (many if/else/switch branches)
95
- 2. For each discovered file:
96
- - `Read` the file
97
- - Extract: functions/methods, their parameters, return types, key conditionals
98
- - Classify the component's role: ENTRY_LOGIC, EXIT_LOGIC, FILTER, VALIDATOR, STATE_MACHINE, PIPELINE, CALCULATOR, etc.
99
- - Determine status: ACTIVE (has callers + tests), TESTING (no production callers), DEPRECATED (commented out or unused)
100
- 3. Map dependencies between components:
101
- - Which component calls which
102
- - Which share state or config
103
- - Which must be modified together (co-change groups)
104
- 4. Write manifest to `.rune/logic-manifest.json`
105
- 5. Save summary to neural memory via `session-bridge`
106
-
107
- ### Phase 4 Post-Edit Validation
108
-
109
- After any edit to a manifested file:
110
-
111
- 1. Re-read the edited file
112
- 2. Compare against the manifest's function list:
113
- - Any function REMOVED? → ALERT: "Function [name] was removed. Was this intentional?"
114
- - Any function SIGNATURE changed? → WARN: "Signature of [name] changed. Check callers."
115
- - Any PARAMETERS changed? → WARN: "Parameter [name] changed from [old] to [new]. Verify downstream."
116
- 3. Run `verification` to execute tests
117
- 4. If all checks pass: update the manifest with new state
118
- 5. If function was removed unintentionally: offer to restore from git
119
-
120
- ### Phase 5 Cross-Session Handoff
121
-
122
- Ensure the next session can pick up where this one left off:
123
-
124
- 1. Update `.rune/logic-manifest.json` with:
125
- - Current component states
126
- - Last validation timestamp
127
- - Any pending changes or known issues
128
- 2. Save key decisions to `journal` as ADRs
129
- 3. Save manifest summary to neural memory:
130
- - "Project X has N active logic components: [list]. Last validated [date]."
131
- - "Component Y was modified: [what changed and why]"
132
-
133
- ## Output Format
134
-
135
- ### Manifest Schema (`.rune/logic-manifest.json`)
136
-
137
- ```json
138
- {
139
- "version": "1.0",
140
- "project": "project-name",
141
- "last_validated": "2026-03-05T10:00:00Z",
142
- "components": [
143
- {
144
- "name": "rsi-entry-detector",
145
- "file_path": "src/scenarios/rsi_entry/detect.py",
146
- "role": "ENTRY_LOGIC",
147
- "status": "ACTIVE",
148
- "functions": [
149
- {
150
- "name": "detect_entry_signal",
151
- "signature": "(df: DataFrame, ticket: Ticket, config: Settings) -> Signal | None",
152
- "description": "3-step RSI entry detection: challenge -> zone check -> entry point",
153
- "critical": true
154
- }
155
- ],
156
- "parameters": [
157
- { "name": "rsi_period", "value": 7, "source": "settings.py" },
158
- { "name": "challenge_threshold_long", "value": 65, "source": "settings.py" }
159
- ],
160
- "dependencies": ["trend-pass-tracker", "indicator-calculator"],
161
- "dependents": ["production-worker", "backtest-engine"],
162
- "last_modified": "2026-03-01",
163
- "last_modifier": "human",
164
- "checksum": "sha256:abc123..."
165
- }
166
- ],
167
- "co_change_groups": [
168
- {
169
- "name": "entry-pipeline",
170
- "components": ["trend-pass-tracker", "rsi-entry-detector", "indicator-calculator"],
171
- "reason": "These components share RSI parameters and must be modified together"
172
- }
173
- ]
174
- }
175
- ```
176
-
177
- ### Validation Report
178
-
179
- ```
180
- ## Logic Guardian Report
181
-
182
- ### Manifest Status: SYNCED | DRIFT_DETECTED
183
- - Components: N active, M testing, K deprecated
184
- - Last validated: [timestamp]
185
-
186
- ### Pre-Edit Gate
187
- - File: [path]
188
- - Component: [name] (ACTIVE)
189
- - Functions preserved: [list]
190
- - Intended change: [description]
191
- - Impact: [downstream effects]
192
-
193
- ### Post-Edit Validation
194
- - Functions removed: [none | list]
195
- - Signatures changed: [none | list]
196
- - Parameters changed: [none | list]
197
- - Tests: PASS | FAIL
198
- - Manifest: UPDATED | NEEDS_REVIEW
199
- ```
200
-
201
- ## Constraints
202
-
203
- 1. MUST load manifest before ANY edit to a manifested file — the entire point is pre-edit awareness
204
- 2. MUST NOT allow edits to ACTIVE logic without the agent explicitly listing what will be preserved — prevents silent overwrites
205
- 3. MUST alert on function removal — the #1 failure mode is deleting working logic
206
- 4. MUST run tests after editing manifested files — logic changes without test verification are blind
207
- 5. MUST update manifest after validated edits — stale manifests provide false confidence
208
- 6. MUST NOT auto-generate manifest for files the agent hasn't read — manifest must reflect actual understanding
209
-
210
- ## Mesh Gates
211
-
212
- | Gate | Requires | If Missing |
213
- |------|----------|------------|
214
- | PRE_EDIT | `.rune/logic-manifest.json` loaded + component spec displayed | BLOCK edit. Run Phase 0 + Phase 2 first. |
215
- | POST_EDIT | All manifest functions still present OR removal explicitly acknowledged | ALERT + offer git restore |
216
- | CROSS_SESSION | Manifest updated + summary saved to journal/nmem | WARN: next session will lack context |
217
-
218
- ## Sharp Edges
219
-
220
- | Failure Mode | Severity | Mitigation |
221
- |---|---|---|
222
- | Agent edits manifested file without loading manifest first | CRITICAL | Phase 2 gate: cook/fix MUST call logic-guardian before editing manifested files |
223
- | Manifest drifts from actual code (manual edits not tracked) | HIGH | Phase 1 validation on every load detect and reconcile drift |
224
- | Agent acknowledges existing logic but still overwrites it | HIGH | Post-edit Phase 4 diff check catches removed functions regardless of agent claims |
225
- | Manifest becomes too large (100+ components) | MEDIUM | Group related functions into composite components; track at module level not function level |
226
- | False sense of security — manifest exists but is outdated | MEDIUM | Checksum comparison on every load; warn if file hash doesn't match manifest |
227
- | Agent treats manifest generation as a one-time task | LOW | Phase 5 cross-session handoff ensures manifest stays alive across sessions |
228
-
229
- ## Done When
230
-
231
- - `.rune/logic-manifest.json` exists and passes Phase 1 validation (SYNCED)
232
- - All manifested components have status (ACTIVE/TESTING/DEPRECATED) and function listings
233
- - Pre-edit gate blocks edits without manifest awareness (Phase 2 enforced)
234
- - Post-edit validation confirms no unintended function removal (Phase 4 passed)
235
- - Manifest summary saved to journal + neural memory for cross-session handoff
236
- - Tests pass after any logic edit
237
-
238
- ## Returns
239
-
240
- | Artifact | Format | Location |
241
- |----------|--------|----------|
242
- | Logic manifest | JSON | `.rune/logic-manifest.json` |
243
- | Validation report (SYNCED / DRIFT) | Markdown | inline |
244
- | Pre-edit gate summary | Structured text | inline |
245
- | ADR entries for logic changes | Markdown | via `journal` L3 |
246
-
247
- ## Cost Profile
248
-
249
- ~1,000-2,000 tokens for manifest load + pre-edit gate. ~3,000-5,000 tokens for full project scan (Phase 3). Sonnet for code analysis; haiku for file scanning via scout.
250
-
251
- **Scope guardrail:** logic-guardian protects existing logic it does not implement new features or refactor code.
1
+ ---
2
+ name: logic-guardian
3
+ description: Protects complex business logic from accidental deletion or overwrite. Maintains a logic manifest, enforces pre-edit gates, and validates post-edit diffs.
4
+ metadata:
5
+ author: runedev
6
+ version: "0.3.0"
7
+ layer: L2
8
+ model: sonnet
9
+ group: quality
10
+ tools: "Read, Write, Edit, Glob, Grep"
11
+ listen: invariants.loaded
12
+ ---
13
+
14
+ # logic-guardian
15
+
16
+ ## Purpose
17
+
18
+ Complex projects (trading bots, payment systems, game engines, state machines) contain interconnected logic that AI agents routinely destroy by accident. The pattern is always the same: new session starts, agent doesn't know existing logic, rewrites or deletes working code, project regresses. `logic-guardian` breaks this cycle by maintaining a machine-readable logic manifest, enforcing a pre-edit gate on logic files, and validating that edits don't silently remove existing logic. It is the "institutional memory" for business logic.
19
+
20
+ ## Triggers
21
+
22
+ - `/rune logic-guardian` manual invocation (scan project, generate/update manifest)
23
+ - Auto-trigger: when `cook` or `fix` targets a file listed in `.rune/logic-manifest.json`
24
+ - Auto-trigger: when `surgeon` plans refactoring on logic-heavy modules
25
+ - Auto-trigger: when `.rune/logic-manifest.json` exists in project root
26
+
27
+ ## Calls (outbound connections)
28
+
29
+ - `scout` (L2): scan project to discover logic files and extract function signatures
30
+ - `verification` (L3): run tests after logic edits to confirm no regression
31
+ - `hallucination-guard` (L3): verify that referenced functions/imports actually exist after edit
32
+ - `journal` (L3): record logic changes as ADRs for cross-session persistence
33
+ - `session-bridge` (L3): save manifest state so next session loads it immediately
34
+
35
+ ## Called By (inbound connections)
36
+
37
+ - `cook` (L1): Phase 1.5when complex logic project detected, load manifest before planning
38
+ - `fix` (L2): pre-edit gate — before modifying any file in the manifest
39
+ - `surgeon` (L2): pre-refactor before restructuring logic modules
40
+ - `team` (L1): validate logic integrity across parallel workstreams
41
+ - `review` (L2): check if reviewed diff removes or modifies manifested logic
42
+
43
+ ## Workflow
44
+
45
+ ### Phase 0 — Load Manifest + Invariants
46
+
47
+ 1. Use `Read` on `.rune/logic-manifest.json`
48
+ 2. If file exists:
49
+ - Parse manifest, display summary: "Loaded logic manifest: N components, M functions, K parameters"
50
+ - Proceed to step 4 (load invariants)
51
+ 3. If manifest does NOT exist:
52
+ - Announce: "No logic manifest found. Scanning project to generate one."
53
+ - Proceed to Phase 3 (Generate)
54
+ 4. Obtain invariants (seeded by `onboard` see onboard Step 5.4):
55
+ - **Preferred**: consume the `invariants.loaded` signal emitted by `session-bridge` at session start (contains pre-parsed `rules[]` + stats). No second file read needed.
56
+ - **Fallback**: if no signal was emitted this session, `Read` `.rune/INVARIANTS.md` directly and invoke `skills/session-bridge/scripts/load-invariants.js` to parse.
57
+ - Entries come from `## Danger Zones`, `## Critical Invariants`, `## State Machine Rules`, `## Cross-File Consistency`, and `## Auto-detected (new)`. Archived rules are automatically excluded by the loader.
58
+ - Each entry follows the `WHAT / WHERE / WHY` contract from `invariants-template.md`.
59
+ - Treat `INVARIANTS.md` as the **primary source of cross-file rules** — the JSON manifest covers component-level signatures; INVARIANTS.md covers rules that span files (shared constants, state transitions, mirrored schemas).
60
+ - If the file is absent, log **WARN**: "INVARIANTS.md not found — run `rune onboard` to seed baseline rules." Do not block.
61
+ - Cache parsed rules keyed by glob so Phase 2 can match the edit target in O(rules × globs) time.
62
+
63
+ ### Phase 1 Validate Manifest Against Codebase
64
+
65
+ Ensure the manifest matches the actual code (detect drift):
66
+
67
+ 1. For each component in the manifest:
68
+ - Use `Read` on the component's `file_path`
69
+ - Verify each listed function exists (by name + signature match)
70
+ - Check if any NEW functions exist in the file that aren't in the manifest
71
+ 2. Report:
72
+ - `SYNCED` manifest matches code perfectly
73
+ - `DRIFT_DETECTED` — list specific discrepancies (missing functions, new unlisted functions, changed signatures)
74
+ 3. If drift detected: ask user whether to update manifest or investigate changes
75
+
76
+ ### Phase 2 — Pre-Edit Gate (called by fix/surgeon/cook)
77
+
78
+ Before ANY edit to a manifested file:
79
+
80
+ 1. Load the manifest (Phase 0)
81
+ 2. Display the affected component's current spec:
82
+ ```
83
+ COMPONENT: [name]
84
+ STATUS: ACTIVE | TESTING | DEPRECATED
85
+ FUNCTIONS: [list with one-line descriptions]
86
+ PARAMETERS: [configurable values with current settings]
87
+ DEPENDENCIES: [what other components depend on this]
88
+ LAST_MODIFIED: [date]
89
+ ```
90
+ 3. Require the agent to explicitly state:
91
+ - What it intends to change
92
+ - What it will NOT change
93
+ - Which existing functions/logic will be preserved
94
+ 4. If the agent cannot list the existing functions BLOCK the edit. Force a `Read` of the file first.
95
+ 5. **Cross-file invariant check** — for each rule loaded from `.rune/INVARIANTS.md` in Phase 0:
96
+ - If the target file matches any rule's `WHERE` glob, surface the rule to the agent before the edit proceeds:
97
+ ```
98
+ INVARIANT (from .rune/INVARIANTS.md):
99
+ WHAT: <rule.what>
100
+ WHY: <rule.why>
101
+ ```
102
+ - The agent MUST either (a) acknowledge the rule in its plan, or (b) explicitly mark it obsolete and move the entry to `## Archived`.
103
+ - A matched rule with no acknowledgement → BLOCK in `strict` preset, WARN in `gentle` preset.
104
+
105
+ ### Phase 3 Generate Manifest (first-time or rescan)
106
+
107
+ Scan the project and build the manifest:
108
+
109
+ 1. Use `scout` to find logic-heavy files:
110
+ - Search for files with complex conditionals, state machines, strategy patterns
111
+ - Look for files matching: `**/logic/**`, `**/strategy/**`, `**/engine/**`, `**/core/**`, `**/scenarios/**`, `**/rules/**`, `**/pipeline/**`, `**/trailing/**`, `**/signals/**`
112
+ - Also search for files with high cyclomatic complexity (many if/else/switch branches)
113
+ 2. For each discovered file:
114
+ - `Read` the file
115
+ - Extract: functions/methods, their parameters, return types, key conditionals
116
+ - Classify the component's role: ENTRY_LOGIC, EXIT_LOGIC, FILTER, VALIDATOR, STATE_MACHINE, PIPELINE, CALCULATOR, etc.
117
+ - Determine status: ACTIVE (has callers + tests), TESTING (no production callers), DEPRECATED (commented out or unused)
118
+ 3. Map dependencies between components:
119
+ - Which component calls which
120
+ - Which share state or config
121
+ - Which must be modified together (co-change groups)
122
+ 4. Write manifest to `.rune/logic-manifest.json`
123
+ 5. Save summary to neural memory via `session-bridge`
124
+
125
+ ### Phase 4 — Post-Edit Validation
126
+
127
+ After any edit to a manifested file:
128
+
129
+ 1. Re-read the edited file
130
+ 2. Compare against the manifest's function list:
131
+ - Any function REMOVED? → ALERT: "Function [name] was removed. Was this intentional?"
132
+ - Any function SIGNATURE changed? → WARN: "Signature of [name] changed. Check callers."
133
+ - Any PARAMETERS changed? → WARN: "Parameter [name] changed from [old] to [new]. Verify downstream."
134
+ 3. Run `verification` to execute tests
135
+ 4. If all checks pass: update the manifest with new state
136
+ 5. If function was removed unintentionally: offer to restore from git
137
+
138
+ ### Phase 5 — Cross-Session Handoff
139
+
140
+ Ensure the next session can pick up where this one left off:
141
+
142
+ 1. Update `.rune/logic-manifest.json` with:
143
+ - Current component states
144
+ - Last validation timestamp
145
+ - Any pending changes or known issues
146
+ 2. Save key decisions to `journal` as ADRs
147
+ 3. Save manifest summary to neural memory:
148
+ - "Project X has N active logic components: [list]. Last validated [date]."
149
+ - "Component Y was modified: [what changed and why]"
150
+
151
+ ## Output Format
152
+
153
+ ### Manifest Schema (`.rune/logic-manifest.json`)
154
+
155
+ ```json
156
+ {
157
+ "version": "1.0",
158
+ "project": "project-name",
159
+ "last_validated": "2026-03-05T10:00:00Z",
160
+ "components": [
161
+ {
162
+ "name": "rsi-entry-detector",
163
+ "file_path": "src/scenarios/rsi_entry/detect.py",
164
+ "role": "ENTRY_LOGIC",
165
+ "status": "ACTIVE",
166
+ "functions": [
167
+ {
168
+ "name": "detect_entry_signal",
169
+ "signature": "(df: DataFrame, ticket: Ticket, config: Settings) -> Signal | None",
170
+ "description": "3-step RSI entry detection: challenge -> zone check -> entry point",
171
+ "critical": true
172
+ }
173
+ ],
174
+ "parameters": [
175
+ { "name": "rsi_period", "value": 7, "source": "settings.py" },
176
+ { "name": "challenge_threshold_long", "value": 65, "source": "settings.py" }
177
+ ],
178
+ "dependencies": ["trend-pass-tracker", "indicator-calculator"],
179
+ "dependents": ["production-worker", "backtest-engine"],
180
+ "last_modified": "2026-03-01",
181
+ "last_modifier": "human",
182
+ "checksum": "sha256:abc123..."
183
+ }
184
+ ],
185
+ "co_change_groups": [
186
+ {
187
+ "name": "entry-pipeline",
188
+ "components": ["trend-pass-tracker", "rsi-entry-detector", "indicator-calculator"],
189
+ "reason": "These components share RSI parameters and must be modified together"
190
+ }
191
+ ]
192
+ }
193
+ ```
194
+
195
+ ### Validation Report
196
+
197
+ ```
198
+ ## Logic Guardian Report
199
+
200
+ ### Manifest Status: SYNCED | DRIFT_DETECTED
201
+ - Components: N active, M testing, K deprecated
202
+ - Last validated: [timestamp]
203
+
204
+ ### Pre-Edit Gate
205
+ - File: [path]
206
+ - Component: [name] (ACTIVE)
207
+ - Functions preserved: [list]
208
+ - Intended change: [description]
209
+ - Impact: [downstream effects]
210
+
211
+ ### Post-Edit Validation
212
+ - Functions removed: [none | list]
213
+ - Signatures changed: [none | list]
214
+ - Parameters changed: [none | list]
215
+ - Tests: PASS | FAIL
216
+ - Manifest: UPDATED | NEEDS_REVIEW
217
+ ```
218
+
219
+ ## Constraints
220
+
221
+ 1. MUST load manifest before ANY edit to a manifested file — the entire point is pre-edit awareness
222
+ 2. MUST NOT allow edits to ACTIVE logic without the agent explicitly listing what will be preserved prevents silent overwrites
223
+ 3. MUST alert on function removal the #1 failure mode is deleting working logic
224
+ 4. MUST run tests after editing manifested files logic changes without test verification are blind
225
+ 5. MUST update manifest after validated edits stale manifests provide false confidence
226
+ 6. MUST NOT auto-generate manifest for files the agent hasn't read manifest must reflect actual understanding
227
+
228
+ ## Mesh Gates
229
+
230
+ | Gate | Requires | If Missing |
231
+ |------|----------|------------|
232
+ | PRE_EDIT | `.rune/logic-manifest.json` loaded + component spec displayed | BLOCK edit. Run Phase 0 + Phase 2 first. |
233
+ | POST_EDIT | All manifest functions still present OR removal explicitly acknowledged | ALERT + offer git restore |
234
+ | CROSS_SESSION | Manifest updated + summary saved to journal/nmem | WARN: next session will lack context |
235
+
236
+ ## Sharp Edges
237
+
238
+ | Failure Mode | Severity | Mitigation |
239
+ |---|---|---|
240
+ | Agent edits manifested file without loading manifest first | CRITICAL | Phase 2 gate: cook/fix MUST call logic-guardian before editing manifested files |
241
+ | Manifest drifts from actual code (manual edits not tracked) | HIGH | Phase 1 validation on every load — detect and reconcile drift |
242
+ | Agent acknowledges existing logic but still overwrites it | HIGH | Post-edit Phase 4 diff check catches removed functions regardless of agent claims |
243
+ | Manifest becomes too large (100+ components) | MEDIUM | Group related functions into composite components; track at module level not function level |
244
+ | False sense of security manifest exists but is outdated | MEDIUM | Checksum comparison on every load; warn if file hash doesn't match manifest |
245
+ | Agent treats manifest generation as a one-time task | LOW | Phase 5 cross-session handoff ensures manifest stays alive across sessions |
246
+
247
+ ## Done When
248
+
249
+ - `.rune/logic-manifest.json` exists and passes Phase 1 validation (SYNCED)
250
+ - All manifested components have status (ACTIVE/TESTING/DEPRECATED) and function listings
251
+ - Pre-edit gate blocks edits without manifest awareness (Phase 2 enforced)
252
+ - Post-edit validation confirms no unintended function removal (Phase 4 passed)
253
+ - Manifest summary saved to journal + neural memory for cross-session handoff
254
+ - Tests pass after any logic edit
255
+
256
+ ## Returns
257
+
258
+ | Artifact | Format | Location |
259
+ |----------|--------|----------|
260
+ | Logic manifest | JSON | `.rune/logic-manifest.json` |
261
+ | Validation report (SYNCED / DRIFT) | Markdown | inline |
262
+ | Pre-edit gate summary | Structured text | inline |
263
+ | ADR entries for logic changes | Markdown | via `journal` L3 |
264
+
265
+ ## Cost Profile
266
+
267
+ ~1,000-2,000 tokens for manifest load + pre-edit gate. ~3,000-5,000 tokens for full project scan (Phase 3). Sonnet for code analysis; haiku for file scanning via scout.
268
+
269
+ **Scope guardrail:** logic-guardian protects existing logic — it does not implement new features or refactor code.