@hongmaple0820/scale-engine 0.25.0 → 0.27.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 (171) hide show
  1. package/LICENSE +15 -15
  2. package/README.en.md +384 -346
  3. package/README.md +564 -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 +190 -56
  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 +53 -53
  53. package/dist/cli/phaseCommands.js.map +1 -1
  54. package/dist/context/AntiPatternRegistry.js +20 -20
  55. package/dist/context/ContextBudget.d.ts +14 -0
  56. package/dist/context/ContextBudget.js +50 -14
  57. package/dist/context/ContextBudget.js.map +1 -1
  58. package/dist/context/ContextBuilder.js +155 -155
  59. package/dist/context/ContextCompiler.d.ts +34 -0
  60. package/dist/context/ContextCompiler.js +120 -0
  61. package/dist/context/ContextCompiler.js.map +1 -0
  62. package/dist/eval/WorkflowEval.js +4 -6
  63. package/dist/eval/WorkflowEval.js.map +1 -1
  64. package/dist/evolution/EvolutionEngine.js +31 -31
  65. package/dist/evolution/EvolutionEvaluator.d.ts +2 -0
  66. package/dist/evolution/EvolutionEvaluator.js +7 -1
  67. package/dist/evolution/EvolutionEvaluator.js.map +1 -1
  68. package/dist/fsm/FSMAgentBridge.js +11 -11
  69. package/dist/governance/GovernanceRoi.d.ts +6 -1
  70. package/dist/governance/GovernanceRoi.js +32 -0
  71. package/dist/governance/GovernanceRoi.js.map +1 -1
  72. package/dist/guardrails/DependencyAuditor.js +38 -0
  73. package/dist/guardrails/DependencyAuditor.js.map +1 -1
  74. package/dist/hooks/HookGeneratorEnhanced.js +218 -218
  75. package/dist/index.d.ts +2 -1
  76. package/dist/index.js +3 -2
  77. package/dist/index.js.map +1 -1
  78. package/dist/knowledge/SQLiteKnowledgeBase.js +28 -28
  79. package/dist/memory/MemoryBrain.js +52 -52
  80. package/dist/output/GovernanceDashboard.js +44 -44
  81. package/dist/output/HTMLArtifactLayer.js +31 -31
  82. package/dist/prompts/VibeTemplateGallery.js +121 -121
  83. package/dist/runtime/AiOsRuntime.d.ts +53 -0
  84. package/dist/runtime/AiOsRuntime.js +142 -0
  85. package/dist/runtime/AiOsRuntime.js.map +1 -0
  86. package/dist/runtime/index.d.ts +1 -0
  87. package/dist/runtime/index.js +1 -0
  88. package/dist/runtime/index.js.map +1 -1
  89. package/dist/skills/SkillDiscovery.js +12 -1
  90. package/dist/skills/SkillDiscovery.js.map +1 -1
  91. package/dist/skills/routing/SkillPlanner.js +128 -40
  92. package/dist/skills/routing/SkillPlanner.js.map +1 -1
  93. package/dist/skills/routing/SkillRoutingTypes.d.ts +17 -0
  94. package/dist/tools/SafeCommandRunner.d.ts +16 -0
  95. package/dist/tools/SafeCommandRunner.js +83 -0
  96. package/dist/tools/SafeCommandRunner.js.map +1 -0
  97. package/dist/workflow/EngineeringStandards.js +62 -62
  98. package/dist/workflow/GovernanceTemplatePacks.d.ts +1 -1
  99. package/dist/workflow/GovernanceTemplatePacks.js +1990 -162
  100. package/dist/workflow/GovernanceTemplatePacks.js.map +1 -1
  101. package/dist/workflow/GovernanceTemplates.d.ts +2 -0
  102. package/dist/workflow/GovernanceTemplates.js +1012 -1001
  103. package/dist/workflow/GovernanceTemplates.js.map +1 -1
  104. package/dist/workflow/ResourceGovernance.js +16 -16
  105. package/dist/workflow/TaskArtifactScaffolder.js +10 -10
  106. package/dist/workflow/UpgradeManager.d.ts +3 -2
  107. package/dist/workflow/UpgradeManager.js +134 -49
  108. package/dist/workflow/UpgradeManager.js.map +1 -1
  109. package/dist/workflow/WorkspaceTopology.js +18 -15
  110. package/dist/workflow/WorkspaceTopology.js.map +1 -1
  111. package/dist/workflow/gates/GateSystem.js +3 -9
  112. package/dist/workflow/gates/GateSystem.js.map +1 -1
  113. package/docs/ACTIVE_SECURITY_VISUAL_GATES.md +87 -87
  114. package/docs/AI_ENGINEERING_OS_POSITIONING.md +462 -0
  115. package/docs/BACKGROUND_HUNTER.md +62 -62
  116. package/docs/CODE_INTELLIGENCE.md +138 -138
  117. package/docs/CONTEXT_BUDGET.md +155 -113
  118. package/docs/DEPENDENCY_AUDIT.md +118 -89
  119. package/docs/EVOLUTION_SHADOW_MODE.md +63 -63
  120. package/docs/EXTERNAL_REFERENCES.md +63 -58
  121. package/docs/GITLAB_FLOW.md +125 -125
  122. package/docs/GOVERNANCE_DASHBOARD.md +85 -85
  123. package/docs/MEMORY_BRAIN.md +104 -104
  124. package/docs/MEMORY_FABRIC.md +136 -134
  125. package/docs/README.md +102 -92
  126. package/docs/RUNTIME_EVIDENCE.md +101 -101
  127. package/docs/SKILL-REPOSITORY.md +57 -57
  128. package/docs/SKILL_RADAR.md +135 -122
  129. package/docs/THIRD_PARTY_SKILLS.md +57 -57
  130. package/docs/WORKFLOW_EVAL.md +151 -151
  131. package/docs/guides/DEVELOPMENT_WORKFLOW.md +80 -0
  132. package/docs/guides/GETTING_STARTED.md +50 -0
  133. package/docs/start/README.md +78 -72
  134. package/docs/start/agent-governance-demo.md +107 -107
  135. package/docs/start/quickstart.md +137 -127
  136. package/docs/start/workflow-upgrade.md +32 -8
  137. package/docs/workflow/README.md +67 -0
  138. package/docs/workflow/node-library.md +52 -0
  139. package/docs/workflow/templates/api-contract.md +29 -0
  140. package/docs/workflow/templates/architecture-review.md +23 -0
  141. package/docs/workflow/templates/db-change-plan.md +20 -0
  142. package/docs/workflow/templates/docs-impact.md +17 -0
  143. package/docs/workflow/templates/e2e-plan.md +20 -0
  144. package/docs/workflow/templates/explore.md +16 -0
  145. package/docs/workflow/templates/github-actions-scale-preflight.yml +32 -0
  146. package/docs/workflow/templates/mini-prd.md +16 -0
  147. package/docs/workflow/templates/plan.md +37 -0
  148. package/docs/workflow/templates/pre-push-scale-preflight.sh +8 -0
  149. package/docs/workflow/templates/product-smoke.md +61 -0
  150. package/docs/workflow/templates/reality-check.md +28 -0
  151. package/docs/workflow/templates/resource-cleanup.md +17 -0
  152. package/docs/workflow/templates/resource-impact.md +25 -0
  153. package/docs/workflow/templates/review.md +12 -0
  154. package/docs/workflow/templates/runtime.md +23 -0
  155. package/docs/workflow/templates/security-review.md +26 -0
  156. package/docs/workflow/templates/skill-evidence.md +33 -0
  157. package/docs/workflow/templates/skill-plan.md +39 -0
  158. package/docs/workflow/templates/spec.md +17 -0
  159. package/docs/workflow/templates/standards-impact.md +28 -0
  160. package/docs/workflow/templates/summary.md +16 -0
  161. package/docs/workflow/templates/tasks.md +8 -0
  162. package/docs/workflow/templates/ui-spec.md +29 -0
  163. package/docs/workflow/templates/verification.md +20 -0
  164. package/docs/workflow/templates/visual-review.md +20 -0
  165. package/examples/demo-projects/agent-governance-demo/CONTEXT.md +14 -14
  166. package/examples/demo-projects/agent-governance-demo/README.md +48 -48
  167. package/examples/demo-projects/agent-governance-demo/docs/CONTEXT-MAP.md +14 -14
  168. package/examples/demo-projects/agent-governance-demo/package.json +22 -21
  169. package/examples/demo-projects/agent-governance-demo/src/oauth-state.ts +39 -39
  170. package/examples/demo-projects/agent-governance-demo/tests/oauth-state.test.ts +52 -52
  171. package/package.json +95 -78
@@ -1,138 +1,138 @@
1
- # Code Intelligence
2
-
3
- SCALE uses an adapter-first code intelligence layer. It can consume external code graph tools when they exist, read graph artifacts such as Graphify outputs, and fall back to a scoped internal source scan when no provider is available.
4
-
5
- The goal is not to replace IDE indexing. The goal is to make exploration measurable:
6
-
7
- - which provider answered the query
8
- - whether fallback was used
9
- - which files are likely relevant
10
- - how many file reads were avoided
11
- - what confidence the result has
12
-
13
- ## Quick Start
14
-
15
- Create the optional provider configuration:
16
-
17
- ```bash
18
- scale codegraph init
19
- ```
20
-
21
- Inspect provider availability:
22
-
23
- ```bash
24
- scale codegraph status
25
- scale codegraph status --json
26
- ```
27
-
28
- Query code intelligence:
29
-
30
- ```bash
31
- scale codegraph query "UserService.create"
32
- scale codegraph impact --symbol UserService.create
33
- scale codegraph context --symbol UserService.create --budget 2000
34
- scale codegraph roi --symbol UserService.create
35
- ```
36
-
37
- ## Configuration
38
-
39
- The configuration file lives at:
40
-
41
- ```text
42
- .scale/code-intelligence.json
43
- ```
44
-
45
- Default shape:
46
-
47
- ```json
48
- {
49
- "version": "1.0",
50
- "providers": [
51
- {
52
- "id": "codegraph",
53
- "type": "external-cli",
54
- "enabled": true,
55
- "command": "codegraph",
56
- "capabilities": ["symbols", "callers", "callees", "impact", "context"]
57
- },
58
- {
59
- "id": "graphify",
60
- "type": "artifact",
61
- "enabled": true,
62
- "manifest": "graphify-out/GRAPH_REPORT.md",
63
- "capabilities": ["summary", "module-map", "context"]
64
- }
65
- ],
66
- "fallback": {
67
- "enabled": true,
68
- "tools": ["internal-scan", "rg", "read"]
69
- }
70
- }
71
- ```
72
-
73
- ## Provider Types
74
-
75
- | Type | Use |
76
- | --- | --- |
77
- | `external-cli` | Detects an installed external code graph command. SCALE does not auto-install it. The first version treats this as availability evidence until a stable command contract is configured. |
78
- | `artifact` | Reads a local graph manifest or report file. JSON manifests can provide symbol impact data. |
79
- | fallback | Uses a bounded internal source scan when providers are unavailable or return no hits. |
80
-
81
- ## JSON Artifact Provider
82
-
83
- Artifact providers can point at a JSON manifest:
84
-
85
- ```json
86
- {
87
- "symbols": [
88
- {
89
- "name": "UserService.create",
90
- "file": "src/user.ts",
91
- "callers": ["src/api.ts"],
92
- "callees": ["src/db.ts"]
93
- }
94
- ],
95
- "files": [
96
- {
97
- "path": "src/user.ts",
98
- "symbols": ["UserService.create"]
99
- }
100
- ]
101
- }
102
- ```
103
-
104
- This allows SCALE to answer impact queries without reading the whole repository.
105
-
106
- ## ROI Metrics
107
-
108
- Code intelligence reports include:
109
-
110
- | Metric | Meaning |
111
- | --- | --- |
112
- | `graphHits` | Number of hits from graph providers. |
113
- | `fallbackCount` | Whether fallback was needed. |
114
- | `baselineFileReads` | Estimated broad exploration file reads. |
115
- | `recommendedFileReads` | Scoped file reads recommended by the query result. |
116
- | `fileReadsSaved` | Estimated avoided reads. |
117
- | `toolCallsSaved` | Estimated avoided exploration tool calls. |
118
-
119
- These numbers are deliberately conservative. They are a local signal for whether graph-assisted exploration is worth keeping default for a task class.
120
-
121
- ## Governance ROI
122
-
123
- `scale governance roi` can include code intelligence:
124
-
125
- ```bash
126
- scale governance roi --symbol UserService.create
127
- scale governance roi --code-query createUser
128
- ```
129
-
130
- When a graph provider answers, the module is reported as measured evidence. When fallback is used, the module is reported as estimated and needs more evidence before becoming a stronger default.
131
-
132
- ## Policy
133
-
134
- - SCALE must run when no code graph provider is installed.
135
- - Missing providers must produce explicit fallback, not silent success.
136
- - External tools are detected but not installed automatically.
137
- - Source files are read only through a bounded fallback scan.
138
- - Large generated graph outputs should stay outside default prompt context; use summaries and file paths.
1
+ # Code Intelligence
2
+
3
+ SCALE uses an adapter-first code intelligence layer. It can consume external code graph tools when they exist, read graph artifacts such as Graphify outputs, and fall back to a scoped internal source scan when no provider is available.
4
+
5
+ The goal is not to replace IDE indexing. The goal is to make exploration measurable:
6
+
7
+ - which provider answered the query
8
+ - whether fallback was used
9
+ - which files are likely relevant
10
+ - how many file reads were avoided
11
+ - what confidence the result has
12
+
13
+ ## Quick Start
14
+
15
+ Create the optional provider configuration:
16
+
17
+ ```bash
18
+ scale codegraph init
19
+ ```
20
+
21
+ Inspect provider availability:
22
+
23
+ ```bash
24
+ scale codegraph status
25
+ scale codegraph status --json
26
+ ```
27
+
28
+ Query code intelligence:
29
+
30
+ ```bash
31
+ scale codegraph query "UserService.create"
32
+ scale codegraph impact --symbol UserService.create
33
+ scale codegraph context --symbol UserService.create --budget 2000
34
+ scale codegraph roi --symbol UserService.create
35
+ ```
36
+
37
+ ## Configuration
38
+
39
+ The configuration file lives at:
40
+
41
+ ```text
42
+ .scale/code-intelligence.json
43
+ ```
44
+
45
+ Default shape:
46
+
47
+ ```json
48
+ {
49
+ "version": "1.0",
50
+ "providers": [
51
+ {
52
+ "id": "codegraph",
53
+ "type": "external-cli",
54
+ "enabled": true,
55
+ "command": "codegraph",
56
+ "capabilities": ["symbols", "callers", "callees", "impact", "context"]
57
+ },
58
+ {
59
+ "id": "graphify",
60
+ "type": "artifact",
61
+ "enabled": true,
62
+ "manifest": "graphify-out/GRAPH_REPORT.md",
63
+ "capabilities": ["summary", "module-map", "context"]
64
+ }
65
+ ],
66
+ "fallback": {
67
+ "enabled": true,
68
+ "tools": ["internal-scan", "rg", "read"]
69
+ }
70
+ }
71
+ ```
72
+
73
+ ## Provider Types
74
+
75
+ | Type | Use |
76
+ | --- | --- |
77
+ | `external-cli` | Detects an installed external code graph command. SCALE does not auto-install it. The first version treats this as availability evidence until a stable command contract is configured. |
78
+ | `artifact` | Reads a local graph manifest or report file. JSON manifests can provide symbol impact data. |
79
+ | fallback | Uses a bounded internal source scan when providers are unavailable or return no hits. |
80
+
81
+ ## JSON Artifact Provider
82
+
83
+ Artifact providers can point at a JSON manifest:
84
+
85
+ ```json
86
+ {
87
+ "symbols": [
88
+ {
89
+ "name": "UserService.create",
90
+ "file": "src/user.ts",
91
+ "callers": ["src/api.ts"],
92
+ "callees": ["src/db.ts"]
93
+ }
94
+ ],
95
+ "files": [
96
+ {
97
+ "path": "src/user.ts",
98
+ "symbols": ["UserService.create"]
99
+ }
100
+ ]
101
+ }
102
+ ```
103
+
104
+ This allows SCALE to answer impact queries without reading the whole repository.
105
+
106
+ ## ROI Metrics
107
+
108
+ Code intelligence reports include:
109
+
110
+ | Metric | Meaning |
111
+ | --- | --- |
112
+ | `graphHits` | Number of hits from graph providers. |
113
+ | `fallbackCount` | Whether fallback was needed. |
114
+ | `baselineFileReads` | Estimated broad exploration file reads. |
115
+ | `recommendedFileReads` | Scoped file reads recommended by the query result. |
116
+ | `fileReadsSaved` | Estimated avoided reads. |
117
+ | `toolCallsSaved` | Estimated avoided exploration tool calls. |
118
+
119
+ These numbers are deliberately conservative. They are a local signal for whether graph-assisted exploration is worth keeping default for a task class.
120
+
121
+ ## Governance ROI
122
+
123
+ `scale governance roi` can include code intelligence:
124
+
125
+ ```bash
126
+ scale governance roi --symbol UserService.create
127
+ scale governance roi --code-query createUser
128
+ ```
129
+
130
+ When a graph provider answers, the module is reported as measured evidence. When fallback is used, the module is reported as estimated and needs more evidence before becoming a stronger default.
131
+
132
+ ## Policy
133
+
134
+ - SCALE must run when no code graph provider is installed.
135
+ - Missing providers must produce explicit fallback, not silent success.
136
+ - External tools are detected but not installed automatically.
137
+ - Source files are read only through a bounded fallback scan.
138
+ - Large generated graph outputs should stay outside default prompt context; use summaries and file paths.
@@ -1,113 +1,155 @@
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
+ Build the unified AI OS runtime plan that embeds the context pack with memory, skill routing, adaptive workflow, and ROI:
47
+
48
+ ```bash
49
+ scale ai-os plan \
50
+ --task-id TASK-123 \
51
+ --task "Review frontend route with browser evidence" \
52
+ --level L \
53
+ --files src/routes/upload.tsx \
54
+ --budget 8000 \
55
+ --json
56
+ ```
57
+
58
+ The context pack now uses the baseline Context Compiler. Each candidate section is scored by category, task/file relevance, risk level, and budget fit. The JSON output includes compiler metadata so callers can explain why a section was loaded or omitted:
59
+
60
+ ```json
61
+ {
62
+ "compiler": {
63
+ "strategy": "relevance-budget-v1",
64
+ "budget": 4000,
65
+ "totalCandidateTokens": 6200,
66
+ "estimatedTokenSavings": 2200,
67
+ "ranking": [
68
+ {
69
+ "id": "runtime-evidence",
70
+ "included": true,
71
+ "score": 292,
72
+ "matchedSignals": ["evidence", "high-risk-evidence"],
73
+ "reason": "Evidence is needed for completion and verification claims."
74
+ }
75
+ ]
76
+ }
77
+ }
78
+ ```
79
+
80
+ Evaluate progressive governance mode:
81
+
82
+ ```bash
83
+ scale governance mode \
84
+ --task "Change auth permissions and database migration" \
85
+ --files src/auth/user.ts,migrations/001.sql \
86
+ --requested-mode minimal \
87
+ --json
88
+ ```
89
+
90
+ Report governance benefit and overhead:
91
+
92
+ ```bash
93
+ scale governance roi \
94
+ --task-id TASK-123 \
95
+ --task "Review frontend route with browser evidence" \
96
+ --files src/routes/upload.tsx \
97
+ --json
98
+ ```
99
+
100
+ ## Categories
101
+
102
+ | Category | Meaning | Loading Policy |
103
+ | --- | --- | --- |
104
+ | `always` | Tiny entrypoint rules and source-of-truth governance config | Keep under strict token budget |
105
+ | `on-demand` | Domain docs and governance guides | Load only when task trigger matches |
106
+ | `evidence` | Runtime evidence and task artifacts | Summarize and reference by path |
107
+ | `archive` | Historical plans and old roadmap context | Do not load unless explicitly requested |
108
+ | `generated` | HTML reports, screenshots, graph outputs, generated artifacts | Keep manifest-only by default |
109
+
110
+ ## Prompt Cache Policy
111
+
112
+ V2.0 adds a cache policy layer for stable context. The policy is intentionally conservative:
113
+
114
+ - `always` is cache-eligible by default because it contains stable entrypoint rules and governance source-of-truth config.
115
+ - `on-demand` is not cache-eligible by default because it changes with task intent and can break stable prefix reuse.
116
+ - `evidence`, `archive`, and `generated` are never cache-eligible by default.
117
+ - Unsupported providers still write usage evidence; they do not pretend to support prompt caching.
118
+
119
+ Provider behavior:
120
+
121
+ | Provider | Strategy | Usage fields |
122
+ | --- | --- | --- |
123
+ | Anthropic | `anthropic-ephemeral` | `cache_creation_input_tokens`, `cache_read_input_tokens` |
124
+ | OpenAI | `openai-automatic` | `prompt_tokens_details.cached_tokens` |
125
+ | Other | `usage-ledger-only` | normal input/output usage only |
126
+
127
+ The cache policy does not live in `ModelRouter`. `ModelRouter` selects a model; provider request builders or adapters apply provider-specific cache controls.
128
+
129
+ ## Progressive Governance
130
+
131
+ 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`.
132
+
133
+ Examples:
134
+
135
+ | Signal | Mode |
136
+ | --- | --- |
137
+ | README typo | `minimal` |
138
+ | normal implementation task | `standard` |
139
+ | UI, browser, E2E, public interface, or cross-module work | `expanded` |
140
+ | auth, permission, secret, database, migration, production config, release, or destructive operation | `critical` |
141
+
142
+ This is not a replacement for verification. It only decides which governance behavior should activate.
143
+
144
+ ## Governance ROI
145
+
146
+ `scale governance roi` reports both benefit and overhead. In v0.27.0, `scale ai-os plan` also attaches ROI modules for:
147
+
148
+ - `context-budget`
149
+ - `context-compiler`
150
+ - `memory-provider-runtime`
151
+ - `skill-routing-engine`
152
+ - `progressive-governance`
153
+
154
+ Early ROI is still estimated from context budget, compiler savings, recall count, skill evidence steps, 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.
155
+