@hongmaple0820/scale-engine 0.25.0 → 0.26.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 (143) hide show
  1. package/LICENSE +15 -15
  2. package/README.en.md +368 -346
  3. package/README.md +548 -529
  4. package/dist/adapters/AiderAdapter.js +52 -52
  5. package/dist/adapters/AntigravityAdapter.d.ts +4 -0
  6. package/dist/adapters/AntigravityAdapter.js +21 -0
  7. package/dist/adapters/AntigravityAdapter.js.map +1 -0
  8. package/dist/adapters/ClaudeCodeAdapter.d.ts +4 -1
  9. package/dist/adapters/ClaudeCodeAdapter.js +34 -34
  10. package/dist/adapters/ClaudeCodeAdapter.js.map +1 -1
  11. package/dist/adapters/ClineAdapter.d.ts +4 -0
  12. package/dist/adapters/ClineAdapter.js +20 -0
  13. package/dist/adapters/ClineAdapter.js.map +1 -0
  14. package/dist/adapters/CodexAdapter.js +28 -28
  15. package/dist/adapters/CursorAdapter.js +26 -26
  16. package/dist/adapters/DeepSeekTuiAdapter.js +97 -97
  17. package/dist/adapters/DoubaoAdapter.js +33 -33
  18. package/dist/adapters/GeminiAdapter.js +26 -26
  19. package/dist/adapters/GenericProjectAgentAdapter.d.ts +29 -0
  20. package/dist/adapters/GenericProjectAgentAdapter.js +204 -0
  21. package/dist/adapters/GenericProjectAgentAdapter.js.map +1 -0
  22. package/dist/adapters/HermesAdapter.js +26 -26
  23. package/dist/adapters/JCodeAdapter.d.ts +4 -0
  24. package/dist/adapters/JCodeAdapter.js +19 -0
  25. package/dist/adapters/JCodeAdapter.js.map +1 -0
  26. package/dist/adapters/KiloCodeAdapter.d.ts +4 -0
  27. package/dist/adapters/KiloCodeAdapter.js +20 -0
  28. package/dist/adapters/KiloCodeAdapter.js.map +1 -0
  29. package/dist/adapters/KimiAdapter.js +32 -32
  30. package/dist/adapters/KiroAdapter.js +26 -26
  31. package/dist/adapters/OpenClawAdapter.js +26 -26
  32. package/dist/adapters/OpenCodeAdapter.js +26 -26
  33. package/dist/adapters/QCoderAdapter.js +26 -26
  34. package/dist/adapters/QoderAdapter.d.ts +4 -0
  35. package/dist/adapters/QoderAdapter.js +21 -0
  36. package/dist/adapters/QoderAdapter.js.map +1 -0
  37. package/dist/adapters/TraeAdapter.js +26 -26
  38. package/dist/adapters/VSCAdapter.js +26 -26
  39. package/dist/adapters/WindsurfAdapter.js +32 -32
  40. package/dist/adapters/WorkBuddyAdapter.js +26 -26
  41. package/dist/adapters/index.d.ts +5 -0
  42. package/dist/adapters/index.js +15 -0
  43. package/dist/adapters/index.js.map +1 -1
  44. package/dist/api/cli.js +133 -47
  45. package/dist/api/cli.js.map +1 -1
  46. package/dist/api/doctor.js +10 -3
  47. package/dist/api/doctor.js.map +1 -1
  48. package/dist/api/quickstart.js +7 -1
  49. package/dist/api/quickstart.js.map +1 -1
  50. package/dist/artifact/sqliteStore.js +89 -89
  51. package/dist/artifact/types.d.ts +1 -1
  52. package/dist/cli/phaseCommands.js +45 -45
  53. package/dist/context/AntiPatternRegistry.js +20 -20
  54. package/dist/context/ContextBuilder.js +155 -155
  55. package/dist/evolution/EvolutionEngine.js +31 -31
  56. package/dist/evolution/EvolutionEvaluator.d.ts +2 -0
  57. package/dist/evolution/EvolutionEvaluator.js +7 -1
  58. package/dist/evolution/EvolutionEvaluator.js.map +1 -1
  59. package/dist/fsm/FSMAgentBridge.js +11 -11
  60. package/dist/hooks/HookGeneratorEnhanced.js +218 -218
  61. package/dist/index.d.ts +1 -1
  62. package/dist/index.js +2 -2
  63. package/dist/index.js.map +1 -1
  64. package/dist/knowledge/SQLiteKnowledgeBase.js +28 -28
  65. package/dist/memory/MemoryBrain.js +52 -52
  66. package/dist/output/GovernanceDashboard.js +44 -44
  67. package/dist/output/HTMLArtifactLayer.js +31 -31
  68. package/dist/prompts/VibeTemplateGallery.js +121 -121
  69. package/dist/skills/SkillDiscovery.js +12 -1
  70. package/dist/skills/SkillDiscovery.js.map +1 -1
  71. package/dist/skills/routing/SkillPlanner.js +40 -40
  72. package/dist/workflow/EngineeringStandards.js +62 -62
  73. package/dist/workflow/GovernanceTemplatePacks.d.ts +1 -1
  74. package/dist/workflow/GovernanceTemplatePacks.js +1990 -162
  75. package/dist/workflow/GovernanceTemplatePacks.js.map +1 -1
  76. package/dist/workflow/GovernanceTemplates.d.ts +2 -0
  77. package/dist/workflow/GovernanceTemplates.js +1012 -1001
  78. package/dist/workflow/GovernanceTemplates.js.map +1 -1
  79. package/dist/workflow/ResourceGovernance.js +16 -16
  80. package/dist/workflow/TaskArtifactScaffolder.js +10 -10
  81. package/dist/workflow/UpgradeManager.d.ts +3 -2
  82. package/dist/workflow/UpgradeManager.js +134 -49
  83. package/dist/workflow/UpgradeManager.js.map +1 -1
  84. package/dist/workflow/WorkspaceTopology.js +18 -15
  85. package/dist/workflow/WorkspaceTopology.js.map +1 -1
  86. package/docs/ACTIVE_SECURITY_VISUAL_GATES.md +87 -87
  87. package/docs/BACKGROUND_HUNTER.md +62 -62
  88. package/docs/CODE_INTELLIGENCE.md +138 -138
  89. package/docs/CONTEXT_BUDGET.md +113 -113
  90. package/docs/DEPENDENCY_AUDIT.md +89 -89
  91. package/docs/EVOLUTION_SHADOW_MODE.md +63 -63
  92. package/docs/EXTERNAL_REFERENCES.md +63 -58
  93. package/docs/GITLAB_FLOW.md +125 -125
  94. package/docs/GOVERNANCE_DASHBOARD.md +85 -85
  95. package/docs/MEMORY_BRAIN.md +104 -104
  96. package/docs/MEMORY_FABRIC.md +134 -134
  97. package/docs/README.md +101 -92
  98. package/docs/RUNTIME_EVIDENCE.md +101 -101
  99. package/docs/SKILL-REPOSITORY.md +57 -57
  100. package/docs/SKILL_RADAR.md +122 -122
  101. package/docs/THIRD_PARTY_SKILLS.md +57 -57
  102. package/docs/WORKFLOW_EVAL.md +151 -151
  103. package/docs/guides/DEVELOPMENT_WORKFLOW.md +80 -0
  104. package/docs/guides/GETTING_STARTED.md +50 -0
  105. package/docs/start/README.md +78 -72
  106. package/docs/start/agent-governance-demo.md +107 -107
  107. package/docs/start/quickstart.md +137 -127
  108. package/docs/start/workflow-upgrade.md +32 -8
  109. package/docs/workflow/README.md +67 -0
  110. package/docs/workflow/node-library.md +52 -0
  111. package/docs/workflow/templates/api-contract.md +29 -0
  112. package/docs/workflow/templates/architecture-review.md +23 -0
  113. package/docs/workflow/templates/db-change-plan.md +20 -0
  114. package/docs/workflow/templates/docs-impact.md +17 -0
  115. package/docs/workflow/templates/e2e-plan.md +20 -0
  116. package/docs/workflow/templates/explore.md +16 -0
  117. package/docs/workflow/templates/github-actions-scale-preflight.yml +32 -0
  118. package/docs/workflow/templates/mini-prd.md +16 -0
  119. package/docs/workflow/templates/plan.md +37 -0
  120. package/docs/workflow/templates/pre-push-scale-preflight.sh +8 -0
  121. package/docs/workflow/templates/product-smoke.md +61 -0
  122. package/docs/workflow/templates/reality-check.md +28 -0
  123. package/docs/workflow/templates/resource-cleanup.md +17 -0
  124. package/docs/workflow/templates/resource-impact.md +25 -0
  125. package/docs/workflow/templates/review.md +12 -0
  126. package/docs/workflow/templates/runtime.md +23 -0
  127. package/docs/workflow/templates/security-review.md +26 -0
  128. package/docs/workflow/templates/skill-evidence.md +33 -0
  129. package/docs/workflow/templates/skill-plan.md +39 -0
  130. package/docs/workflow/templates/spec.md +17 -0
  131. package/docs/workflow/templates/standards-impact.md +28 -0
  132. package/docs/workflow/templates/summary.md +16 -0
  133. package/docs/workflow/templates/tasks.md +8 -0
  134. package/docs/workflow/templates/ui-spec.md +29 -0
  135. package/docs/workflow/templates/verification.md +20 -0
  136. package/docs/workflow/templates/visual-review.md +20 -0
  137. package/examples/demo-projects/agent-governance-demo/CONTEXT.md +14 -14
  138. package/examples/demo-projects/agent-governance-demo/README.md +48 -48
  139. package/examples/demo-projects/agent-governance-demo/docs/CONTEXT-MAP.md +14 -14
  140. package/examples/demo-projects/agent-governance-demo/package.json +22 -21
  141. package/examples/demo-projects/agent-governance-demo/src/oauth-state.ts +39 -39
  142. package/examples/demo-projects/agent-governance-demo/tests/oauth-state.test.ts +52 -52
  143. package/package.json +88 -78
@@ -1,113 +1,113 @@
1
- # Context Budget And Progressive Governance
2
-
3
- Status: implemented baseline
4
- Since: v0.20 development branch
5
-
6
- This feature keeps SCALE from becoming its own context pollution source. It separates always-loaded rules from on-demand documents, runtime evidence, historical archives, and generated artifacts.
7
-
8
- ## Commands
9
-
10
- Report token cost by context category:
11
-
12
- ```bash
13
- scale context budget --json
14
- ```
15
-
16
- Include provider-specific prompt cache policy:
17
-
18
- ```bash
19
- scale context budget --provider anthropic --json
20
- scale context budget --provider openai --json
21
- ```
22
-
23
- Write the report to `.scale/context-budget.json`:
24
-
25
- ```bash
26
- scale context budget --write
27
- ```
28
-
29
- Check thresholds:
30
-
31
- ```bash
32
- scale context doctor --max-always 2500 --max-task 8000
33
- ```
34
-
35
- Build a lazy-loaded task context pack:
36
-
37
- ```bash
38
- scale context pack \
39
- --task "Review frontend route with browser evidence" \
40
- --level L \
41
- --files src/routes/upload.tsx \
42
- --budget 4000 \
43
- --json
44
- ```
45
-
46
- Evaluate progressive governance mode:
47
-
48
- ```bash
49
- scale governance mode \
50
- --task "Change auth permissions and database migration" \
51
- --files src/auth/user.ts,migrations/001.sql \
52
- --requested-mode minimal \
53
- --json
54
- ```
55
-
56
- Report governance benefit and overhead:
57
-
58
- ```bash
59
- scale governance roi \
60
- --task-id TASK-123 \
61
- --task "Review frontend route with browser evidence" \
62
- --files src/routes/upload.tsx \
63
- --json
64
- ```
65
-
66
- ## Categories
67
-
68
- | Category | Meaning | Loading Policy |
69
- | --- | --- | --- |
70
- | `always` | Tiny entrypoint rules and source-of-truth governance config | Keep under strict token budget |
71
- | `on-demand` | Domain docs and governance guides | Load only when task trigger matches |
72
- | `evidence` | Runtime evidence and task artifacts | Summarize and reference by path |
73
- | `archive` | Historical plans and old roadmap context | Do not load unless explicitly requested |
74
- | `generated` | HTML reports, screenshots, graph outputs, generated artifacts | Keep manifest-only by default |
75
-
76
- ## Prompt Cache Policy
77
-
78
- V2.0 adds a cache policy layer for stable context. The policy is intentionally conservative:
79
-
80
- - `always` is cache-eligible by default because it contains stable entrypoint rules and governance source-of-truth config.
81
- - `on-demand` is not cache-eligible by default because it changes with task intent and can break stable prefix reuse.
82
- - `evidence`, `archive`, and `generated` are never cache-eligible by default.
83
- - Unsupported providers still write usage evidence; they do not pretend to support prompt caching.
84
-
85
- Provider behavior:
86
-
87
- | Provider | Strategy | Usage fields |
88
- | --- | --- | --- |
89
- | Anthropic | `anthropic-ephemeral` | `cache_creation_input_tokens`, `cache_read_input_tokens` |
90
- | OpenAI | `openai-automatic` | `prompt_tokens_details.cached_tokens` |
91
- | Other | `usage-ledger-only` | normal input/output usage only |
92
-
93
- The cache policy does not live in `ModelRouter`. `ModelRouter` selects a model; provider request builders or adapters apply provider-specific cache controls.
94
-
95
- ## Progressive Governance
96
-
97
- SCALE now has a baseline risk classifier. It keeps low-risk documentation work in `minimal` mode and escalates risky tasks to `standard`, `expanded`, or `critical`.
98
-
99
- Examples:
100
-
101
- | Signal | Mode |
102
- | --- | --- |
103
- | README typo | `minimal` |
104
- | normal implementation task | `standard` |
105
- | UI, browser, E2E, public interface, or cross-module work | `expanded` |
106
- | auth, permission, secret, database, migration, production config, release, or destructive operation | `critical` |
107
-
108
- This is not a replacement for verification. It only decides which governance behavior should activate.
109
-
110
- ## Governance ROI
111
-
112
- `scale governance roi` reports both benefit and overhead. Early ROI is estimated from context budget and risk signals. Later versions should replace estimates with measured eval data such as file reads saved, tool calls saved, fix iterations reduced, and human corrections avoided.
113
-
1
+ # Context Budget And Progressive Governance
2
+
3
+ Status: implemented baseline
4
+ Since: v0.20 development branch
5
+
6
+ This feature keeps SCALE from becoming its own context pollution source. It separates always-loaded rules from on-demand documents, runtime evidence, historical archives, and generated artifacts.
7
+
8
+ ## Commands
9
+
10
+ Report token cost by context category:
11
+
12
+ ```bash
13
+ scale context budget --json
14
+ ```
15
+
16
+ Include provider-specific prompt cache policy:
17
+
18
+ ```bash
19
+ scale context budget --provider anthropic --json
20
+ scale context budget --provider openai --json
21
+ ```
22
+
23
+ Write the report to `.scale/context-budget.json`:
24
+
25
+ ```bash
26
+ scale context budget --write
27
+ ```
28
+
29
+ Check thresholds:
30
+
31
+ ```bash
32
+ scale context doctor --max-always 2500 --max-task 8000
33
+ ```
34
+
35
+ Build a lazy-loaded task context pack:
36
+
37
+ ```bash
38
+ scale context pack \
39
+ --task "Review frontend route with browser evidence" \
40
+ --level L \
41
+ --files src/routes/upload.tsx \
42
+ --budget 4000 \
43
+ --json
44
+ ```
45
+
46
+ Evaluate progressive governance mode:
47
+
48
+ ```bash
49
+ scale governance mode \
50
+ --task "Change auth permissions and database migration" \
51
+ --files src/auth/user.ts,migrations/001.sql \
52
+ --requested-mode minimal \
53
+ --json
54
+ ```
55
+
56
+ Report governance benefit and overhead:
57
+
58
+ ```bash
59
+ scale governance roi \
60
+ --task-id TASK-123 \
61
+ --task "Review frontend route with browser evidence" \
62
+ --files src/routes/upload.tsx \
63
+ --json
64
+ ```
65
+
66
+ ## Categories
67
+
68
+ | Category | Meaning | Loading Policy |
69
+ | --- | --- | --- |
70
+ | `always` | Tiny entrypoint rules and source-of-truth governance config | Keep under strict token budget |
71
+ | `on-demand` | Domain docs and governance guides | Load only when task trigger matches |
72
+ | `evidence` | Runtime evidence and task artifacts | Summarize and reference by path |
73
+ | `archive` | Historical plans and old roadmap context | Do not load unless explicitly requested |
74
+ | `generated` | HTML reports, screenshots, graph outputs, generated artifacts | Keep manifest-only by default |
75
+
76
+ ## Prompt Cache Policy
77
+
78
+ V2.0 adds a cache policy layer for stable context. The policy is intentionally conservative:
79
+
80
+ - `always` is cache-eligible by default because it contains stable entrypoint rules and governance source-of-truth config.
81
+ - `on-demand` is not cache-eligible by default because it changes with task intent and can break stable prefix reuse.
82
+ - `evidence`, `archive`, and `generated` are never cache-eligible by default.
83
+ - Unsupported providers still write usage evidence; they do not pretend to support prompt caching.
84
+
85
+ Provider behavior:
86
+
87
+ | Provider | Strategy | Usage fields |
88
+ | --- | --- | --- |
89
+ | Anthropic | `anthropic-ephemeral` | `cache_creation_input_tokens`, `cache_read_input_tokens` |
90
+ | OpenAI | `openai-automatic` | `prompt_tokens_details.cached_tokens` |
91
+ | Other | `usage-ledger-only` | normal input/output usage only |
92
+
93
+ The cache policy does not live in `ModelRouter`. `ModelRouter` selects a model; provider request builders or adapters apply provider-specific cache controls.
94
+
95
+ ## Progressive Governance
96
+
97
+ SCALE now has a baseline risk classifier. It keeps low-risk documentation work in `minimal` mode and escalates risky tasks to `standard`, `expanded`, or `critical`.
98
+
99
+ Examples:
100
+
101
+ | Signal | Mode |
102
+ | --- | --- |
103
+ | README typo | `minimal` |
104
+ | normal implementation task | `standard` |
105
+ | UI, browser, E2E, public interface, or cross-module work | `expanded` |
106
+ | auth, permission, secret, database, migration, production config, release, or destructive operation | `critical` |
107
+
108
+ This is not a replacement for verification. It only decides which governance behavior should activate.
109
+
110
+ ## Governance ROI
111
+
112
+ `scale governance roi` reports both benefit and overhead. Early ROI is estimated from context budget and risk signals. Later versions should replace estimates with measured eval data such as file reads saved, tool calls saved, fix iterations reduced, and human corrections avoided.
113
+
@@ -1,89 +1,89 @@
1
- # Dependency Audit
2
-
3
- Dependency Audit is the G7 dependency sub-gate for SCALE Engine.
4
- It adds supply-chain checks without introducing a separate gate number such as `G6.8`.
5
-
6
- ## Scope
7
-
8
- The auditor is intentionally bounded:
9
-
10
- - reads `package-lock.json`
11
- - audits direct dependencies by default
12
- - supports `--changed-packages` for lockfile-diff workflows
13
- - scans only selected package roots under `node_modules`
14
- - caps package count and files per package
15
- - does not contact the registry by default
16
- - does not run install scripts
17
-
18
- This keeps local verification usable while still catching high-risk dependency behavior.
19
-
20
- ## Commands
21
-
22
- ```bash
23
- scale dependency audit
24
- scale dependency audit --json
25
- scale dependency audit --mode strict
26
- scale dependency audit --changed-packages left-pad,@scope/tool --json
27
- ```
28
-
29
- The command exits non-zero when the active mode has blocking findings.
30
-
31
- ## G7 Integration
32
-
33
- `SecurityGate` now emits two first-class evidence sources:
34
-
35
- - `built-in-security-scan`: source code security scan
36
- - `dependency-audit`: dependency supply-chain scan
37
-
38
- Both remain under `G7 Security`.
39
-
40
- ## Policy
41
-
42
- Policy lives at `.scale/security/dependency-policy.json`:
43
-
44
- ```json
45
- {
46
- "version": 1,
47
- "mode": "compatibility",
48
- "maxPackages": 50,
49
- "maxPackageFiles": 25,
50
- "allowPackages": [],
51
- "baselineFindings": []
52
- }
53
- ```
54
-
55
- Modes:
56
-
57
- - `compatibility`: blocks `CRITICAL`
58
- - `strict`: blocks `CRITICAL` and `HIGH`
59
- - `offline`: keeps local-only behavior; current offline findings follow compatibility blocking
60
-
61
- Use `baselineFindings` for accepted legacy dependency risk:
62
-
63
- ```json
64
- {
65
- "baselineFindings": [
66
- {
67
- "packageName": "legacy-tool",
68
- "version": "1.2.3",
69
- "ruleId": "dependency.install-script",
70
- "reason": "Pinned and reviewed during migration window."
71
- }
72
- ]
73
- }
74
- ```
75
-
76
- Prefer a baseline over `allowPackages` when only one finding is accepted. `allowPackages` suppresses all findings for that package.
77
-
78
- ## Current Findings
79
-
80
- The first implementation detects:
81
-
82
- - install lifecycle scripts
83
- - executable bin scripts
84
- - deprecated packages from lockfile metadata
85
- - dynamic code execution: `eval`, `new Function`
86
- - shell execution patterns
87
- - suspicious network access patterns
88
-
89
- Future network-backed checks can add npm registry metadata and `npm audit --json` ingestion, but they should stay optional and evidence-backed.
1
+ # Dependency Audit
2
+
3
+ Dependency Audit is the G7 dependency sub-gate for SCALE Engine.
4
+ It adds supply-chain checks without introducing a separate gate number such as `G6.8`.
5
+
6
+ ## Scope
7
+
8
+ The auditor is intentionally bounded:
9
+
10
+ - reads `package-lock.json`
11
+ - audits direct dependencies by default
12
+ - supports `--changed-packages` for lockfile-diff workflows
13
+ - scans only selected package roots under `node_modules`
14
+ - caps package count and files per package
15
+ - does not contact the registry by default
16
+ - does not run install scripts
17
+
18
+ This keeps local verification usable while still catching high-risk dependency behavior.
19
+
20
+ ## Commands
21
+
22
+ ```bash
23
+ scale dependency audit
24
+ scale dependency audit --json
25
+ scale dependency audit --mode strict
26
+ scale dependency audit --changed-packages left-pad,@scope/tool --json
27
+ ```
28
+
29
+ The command exits non-zero when the active mode has blocking findings.
30
+
31
+ ## G7 Integration
32
+
33
+ `SecurityGate` now emits two first-class evidence sources:
34
+
35
+ - `built-in-security-scan`: source code security scan
36
+ - `dependency-audit`: dependency supply-chain scan
37
+
38
+ Both remain under `G7 Security`.
39
+
40
+ ## Policy
41
+
42
+ Policy lives at `.scale/security/dependency-policy.json`:
43
+
44
+ ```json
45
+ {
46
+ "version": 1,
47
+ "mode": "compatibility",
48
+ "maxPackages": 50,
49
+ "maxPackageFiles": 25,
50
+ "allowPackages": [],
51
+ "baselineFindings": []
52
+ }
53
+ ```
54
+
55
+ Modes:
56
+
57
+ - `compatibility`: blocks `CRITICAL`
58
+ - `strict`: blocks `CRITICAL` and `HIGH`
59
+ - `offline`: keeps local-only behavior; current offline findings follow compatibility blocking
60
+
61
+ Use `baselineFindings` for accepted legacy dependency risk:
62
+
63
+ ```json
64
+ {
65
+ "baselineFindings": [
66
+ {
67
+ "packageName": "legacy-tool",
68
+ "version": "1.2.3",
69
+ "ruleId": "dependency.install-script",
70
+ "reason": "Pinned and reviewed during migration window."
71
+ }
72
+ ]
73
+ }
74
+ ```
75
+
76
+ Prefer a baseline over `allowPackages` when only one finding is accepted. `allowPackages` suppresses all findings for that package.
77
+
78
+ ## Current Findings
79
+
80
+ The first implementation detects:
81
+
82
+ - install lifecycle scripts
83
+ - executable bin scripts
84
+ - deprecated packages from lockfile metadata
85
+ - dynamic code execution: `eval`, `new Function`
86
+ - shell execution patterns
87
+ - suspicious network access patterns
88
+
89
+ Future network-backed checks can add npm registry metadata and `npm audit --json` ingestion, but they should stay optional and evidence-backed.
@@ -1,63 +1,63 @@
1
- # Evolution Shadow Mode
2
-
3
- SCALE V2 keeps self-evolution useful without letting one-off failures become hard blockers too early.
4
-
5
- ## Flow
6
-
7
- ```text
8
- Gate Failure
9
- -> Defect
10
- -> Lesson
11
- -> Proposed Rule
12
- -> Shadow Rule
13
- -> Candidate Hook
14
- -> Approved Blocking Hook
15
- ```
16
-
17
- ## Gate Failure To Defect
18
-
19
- `GateSystem` emits `gate.failed` for failed gate results. `AutoDefectCreator` tracks consecutive failures per session and gate stage.
20
-
21
- Default behavior:
22
-
23
- - three consecutive failures create one `Defect`
24
- - a passing `gate.executed` event resets the streak
25
- - defect payload uses `rootCauseCategory=gate_failure`
26
- - the original blockers, evidence, evidence record id, stage, and streak count are stored in defect context
27
-
28
- This is evidence capture only. It does not change source code or generate a hook.
29
-
30
- ## Rule Maturity
31
-
32
- New rules start in `shadow` mode. Shadow rules can record hits, but they do not block development.
33
-
34
- Promotion requires:
35
-
36
- - shadow hits >= 10
37
- - at least one defect evidence id
38
- - rollback method present
39
- - false positive rate within threshold
40
- - explicit approval before a blocking hook is allowed
41
-
42
- `RuleMaturity` exposes:
43
-
44
- - `createShadowRuleMaturity`
45
- - `recordShadowHit`
46
- - `evaluateRulePromotion`
47
- - `approveRuleMaturity`
48
-
49
- ## Hook Boundary
50
-
51
- `HookGenerator` still requires `rule.approved === true`.
52
-
53
- For V2 rules that carry maturity metadata, it also requires:
54
-
55
- ```text
56
- rule.maturity.stage === "approved-blocking"
57
- ```
58
-
59
- That means proposed or shadow rules can be observed and improved, but cannot become blocking hooks until explicitly promoted.
60
-
61
- ## Current Scope
62
-
63
- This release slice wires the core library path and gate events. CLI approval commands and persistent rule-maturity storage can be added later without changing the safety model.
1
+ # Evolution Shadow Mode
2
+
3
+ SCALE V2 keeps self-evolution useful without letting one-off failures become hard blockers too early.
4
+
5
+ ## Flow
6
+
7
+ ```text
8
+ Gate Failure
9
+ -> Defect
10
+ -> Lesson
11
+ -> Proposed Rule
12
+ -> Shadow Rule
13
+ -> Candidate Hook
14
+ -> Approved Blocking Hook
15
+ ```
16
+
17
+ ## Gate Failure To Defect
18
+
19
+ `GateSystem` emits `gate.failed` for failed gate results. `AutoDefectCreator` tracks consecutive failures per session and gate stage.
20
+
21
+ Default behavior:
22
+
23
+ - three consecutive failures create one `Defect`
24
+ - a passing `gate.executed` event resets the streak
25
+ - defect payload uses `rootCauseCategory=gate_failure`
26
+ - the original blockers, evidence, evidence record id, stage, and streak count are stored in defect context
27
+
28
+ This is evidence capture only. It does not change source code or generate a hook.
29
+
30
+ ## Rule Maturity
31
+
32
+ New rules start in `shadow` mode. Shadow rules can record hits, but they do not block development.
33
+
34
+ Promotion requires:
35
+
36
+ - shadow hits >= 10
37
+ - at least one defect evidence id
38
+ - rollback method present
39
+ - false positive rate within threshold
40
+ - explicit approval before a blocking hook is allowed
41
+
42
+ `RuleMaturity` exposes:
43
+
44
+ - `createShadowRuleMaturity`
45
+ - `recordShadowHit`
46
+ - `evaluateRulePromotion`
47
+ - `approveRuleMaturity`
48
+
49
+ ## Hook Boundary
50
+
51
+ `HookGenerator` still requires `rule.approved === true`.
52
+
53
+ For V2 rules that carry maturity metadata, it also requires:
54
+
55
+ ```text
56
+ rule.maturity.stage === "approved-blocking"
57
+ ```
58
+
59
+ That means proposed or shadow rules can be observed and improved, but cannot become blocking hooks until explicitly promoted.
60
+
61
+ ## Current Scope
62
+
63
+ This release slice wires the core library path and gate events. CLI approval commands and persistent rule-maturity storage can be added later without changing the safety model.