@hongmaple0820/scale-engine 0.23.0 → 0.24.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 (64) hide show
  1. package/dist/api/cli.js +192 -1
  2. package/dist/api/cli.js.map +1 -1
  3. package/dist/dashboard/MetricsAggregator.d.ts +38 -0
  4. package/dist/dashboard/MetricsAggregator.js +99 -0
  5. package/dist/dashboard/MetricsAggregator.js.map +1 -0
  6. package/dist/dashboard/index.d.ts +2 -0
  7. package/dist/dashboard/index.js +1 -0
  8. package/dist/dashboard/index.js.map +1 -1
  9. package/dist/dashboard/server.js +1 -1
  10. package/dist/dashboard/server.js.map +1 -1
  11. package/dist/evolution/AutoDefectCreator.d.ts +11 -2
  12. package/dist/evolution/AutoDefectCreator.js +46 -2
  13. package/dist/evolution/AutoDefectCreator.js.map +1 -1
  14. package/dist/evolution/EvolutionEngine.d.ts +3 -0
  15. package/dist/evolution/EvolutionEngine.js +18 -2
  16. package/dist/evolution/EvolutionEngine.js.map +1 -1
  17. package/dist/evolution/RuleMaturity.d.ts +39 -0
  18. package/dist/evolution/RuleMaturity.js +70 -0
  19. package/dist/evolution/RuleMaturity.js.map +1 -0
  20. package/dist/guardrails/ActiveRedTeam.d.ts +46 -0
  21. package/dist/guardrails/ActiveRedTeam.js +203 -0
  22. package/dist/guardrails/ActiveRedTeam.js.map +1 -0
  23. package/dist/guardrails/DependencyAuditor.d.ts +68 -0
  24. package/dist/guardrails/DependencyAuditor.js +331 -0
  25. package/dist/guardrails/DependencyAuditor.js.map +1 -0
  26. package/dist/hooks/HookGeneratorEnhanced.js +18 -18
  27. package/dist/index.d.ts +6 -0
  28. package/dist/index.js +5 -0
  29. package/dist/index.js.map +1 -1
  30. package/dist/output/GovernanceDashboard.d.ts +2 -0
  31. package/dist/output/GovernanceDashboard.js +31 -0
  32. package/dist/output/GovernanceDashboard.js.map +1 -1
  33. package/dist/routing/PromptCachePolicy.d.ts +37 -0
  34. package/dist/routing/PromptCachePolicy.js +97 -0
  35. package/dist/routing/PromptCachePolicy.js.map +1 -0
  36. package/dist/runtime/ModelUsageLedger.d.ts +50 -0
  37. package/dist/runtime/ModelUsageLedger.js +92 -0
  38. package/dist/runtime/ModelUsageLedger.js.map +1 -0
  39. package/dist/runtime/index.d.ts +1 -0
  40. package/dist/runtime/index.js +1 -0
  41. package/dist/runtime/index.js.map +1 -1
  42. package/dist/workflow/autonomous/BackgroundHunter.d.ts +74 -0
  43. package/dist/workflow/autonomous/BackgroundHunter.js +220 -0
  44. package/dist/workflow/autonomous/BackgroundHunter.js.map +1 -0
  45. package/dist/workflow/autonomous/index.d.ts +1 -0
  46. package/dist/workflow/autonomous/index.js +1 -0
  47. package/dist/workflow/autonomous/index.js.map +1 -1
  48. package/dist/workflow/gates/GateSystem.d.ts +10 -0
  49. package/dist/workflow/gates/GateSystem.js +62 -0
  50. package/dist/workflow/gates/GateSystem.js.map +1 -1
  51. package/dist/workflow/gates/VisualGate.d.ts +41 -0
  52. package/dist/workflow/gates/VisualGate.js +174 -0
  53. package/dist/workflow/gates/VisualGate.js.map +1 -0
  54. package/dist/workflow/index.d.ts +1 -0
  55. package/dist/workflow/index.js +1 -0
  56. package/dist/workflow/index.js.map +1 -1
  57. package/docs/ACTIVE_SECURITY_VISUAL_GATES.md +87 -0
  58. package/docs/BACKGROUND_HUNTER.md +62 -0
  59. package/docs/CONTEXT_BUDGET.md +32 -6
  60. package/docs/DEPENDENCY_AUDIT.md +89 -0
  61. package/docs/EVOLUTION_SHADOW_MODE.md +63 -0
  62. package/docs/GOVERNANCE_DASHBOARD.md +21 -5
  63. package/docs/README.md +22 -12
  64. package/package.json +13 -9
@@ -0,0 +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.
@@ -0,0 +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.
@@ -32,11 +32,27 @@ The dashboard reads existing local evidence:
32
32
 
33
33
  | Area | Source |
34
34
  | --- | --- |
35
- | Runtime evidence | `.scale/evidence/runtime/` |
36
- | Workflow eval | `.scale/evals/runs/` and `.scale/evals/failures/` |
37
- | Memory Brain | `.scale/memory/brain.sqlite` |
38
- | Resource Governance | workspace files plus `.scale/resource-policy.json` and `.scale/assets.json` |
39
- | HTML artifacts | task artifact manifests and rendered HTML files |
35
+ | Runtime evidence | `.scale/evidence/runtime/` |
36
+ | Workflow eval | `.scale/evals/runs/` and `.scale/evals/failures/` |
37
+ | Workflow metrics | `.scale/metrics/tasks.jsonl` |
38
+ | Gate evidence | `.scale/evidence/GATE-*.json` |
39
+ | Command runs | `.scale/evidence/command-runs/` |
40
+ | Model usage | `.scale/model-usage/usage.jsonl` |
41
+ | Memory Brain | `.scale/memory/brain.sqlite` |
42
+ | Resource Governance | workspace files plus `.scale/resource-policy.json` and `.scale/assets.json` |
43
+ | HTML artifacts | task artifact manifests and rendered HTML files |
44
+
45
+ ## Aggregated Metrics
46
+
47
+ V2.0 adds `MetricsAggregator` as the dashboard aggregation layer. It keeps the dashboard read-only and derives the following metrics from existing evidence:
48
+
49
+ - recent task count and first-pass rate
50
+ - average fix iterations
51
+ - gate failure distribution
52
+ - command output compression token savings
53
+ - model usage and prompt-cache savings
54
+
55
+ Each number must trace back to local JSON/JSONL evidence. If a source is absent, the dashboard reports zero rather than inventing values.
40
56
 
41
57
  ## Status Model
42
58
 
package/docs/README.md CHANGED
@@ -12,13 +12,15 @@
12
12
  | [start/artifact-lifecycle.md](start/artifact-lifecycle.md) | Artifact 生命周期完整 walkthrough |
13
13
  | [../README.md](../README.md) | 项目主页和能力总览 |
14
14
 
15
- ## 当前治理能力
16
-
17
- | 文档 | 说明 |
18
- | --- | --- |
15
+ ## 当前治理能力
16
+
17
+ | 文档 | 说明 |
18
+ | --- | --- |
19
19
  | [RESOURCE_GOVERNANCE.md](RESOURCE_GOVERNANCE.md) | 文档、报告、媒体、脚本、临时产物的生命周期治理 |
20
- | [ENGINEERING_STANDARDS.md](ENGINEERING_STANDARDS.md) | 日志、安全、ORM、框架、测试、部署等工程规范 |
21
- | [TOOL_ORCHESTRATION.md](TOOL_ORCHESTRATION.md) | skills、MCP、CLI、浏览器、桌面自动化的编排策略 |
20
+ | [ENGINEERING_STANDARDS.md](ENGINEERING_STANDARDS.md) | 日志、安全、ORM、框架、测试、部署等工程规范 |
21
+ | [BACKGROUND_HUNTER.md](BACKGROUND_HUNTER.md) | Background Hunter 只读主动巡检、诊断交接和 ignore baseline |
22
+ | [DEPENDENCY_AUDIT.md](DEPENDENCY_AUDIT.md) | 供应链依赖审计、G7 dependency 子门禁和 dependency policy |
23
+ | [TOOL_ORCHESTRATION.md](TOOL_ORCHESTRATION.md) | skills、MCP、CLI、浏览器、桌面自动化的编排策略 |
22
24
  | [RUNTIME_EVIDENCE.md](RUNTIME_EVIDENCE.md) | 会话 ledger、运行时证据和最终交付检查 |
23
25
  | [MEMORY_FABRIC.md](MEMORY_FABRIC.md) | Runtime evidence、session events、knowledge recall 和 graph status 的预算化上下文包 |
24
26
  | [MEMORY_BRAIN.md](MEMORY_BRAIN.md) | 证据驱动的长期记忆、矛盾检测、dream 整理和 failure replay 沉淀 |
@@ -32,12 +34,20 @@
32
34
  | [DOCUMENT_STANDARDS.md](DOCUMENT_STANDARDS.md) | 文档编写与维护规范 |
33
35
  | [GITLAB_FLOW.md](GITLAB_FLOW.md) | GitLab Flow 分支、发版、tag 和临时 worktree 生命周期规范 |
34
36
  | [SKILL-REPOSITORY.md](SKILL-REPOSITORY.md) | 受治理 skill repository 和安装安全策略 |
35
- | [VIBE-TEMPLATES.md](VIBE-TEMPLATES.md) | 可复制的 Vibe Coding 提示词模板 |
36
- | [LEADERSHIP-PRESETS.md](LEADERSHIP-PRESETS.md) | CEO、CTO、PM、Architect 等内置领导者角色预设 |
37
-
38
- ## 架构与参考
39
-
40
- | 文档 | 说明 |
37
+ | [VIBE-TEMPLATES.md](VIBE-TEMPLATES.md) | 可复制的 Vibe Coding 提示词模板 |
38
+ | [LEADERSHIP-PRESETS.md](LEADERSHIP-PRESETS.md) | CEO、CTO、PM、Architect 等内置领导者角色预设 |
39
+
40
+ ## 当前规划与执行蓝图
41
+
42
+ 这些文档描述计划中的架构演进,不代表当前 CLI 已全部实现。进入实现前应按文档中的验收标准和红线逐项拆分任务。
43
+
44
+ | 文档 | 说明 |
45
+ | --- | --- |
46
+ | [plans/2026-05-20-scale-engine-v2-final-architecture-plan.md](plans/2026-05-20-scale-engine-v2-final-architecture-plan.md) | SCALE Engine V2.0 最终架构落地方案:Prompt Cache、Dashboard 聚合、Background Hunter、供应链门禁、动态/视觉验证和 Evolution Shadow Mode |
47
+
48
+ ## 架构与参考
49
+
50
+ | 文档 | 说明 |
41
51
  | --- | --- |
42
52
  | [00-OVERVIEW.md](00-OVERVIEW.md) | 系统概览 |
43
53
  | [01-ARCHITECTURE.md](01-ARCHITECTURE.md) | 架构设计 |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hongmaple0820/scale-engine",
3
- "version": "0.23.0",
3
+ "version": "0.24.0",
4
4
  "description": "Executable AI agent governance with workflow gates, evidence, skill/tool orchestration, and traceable HTML artifacts",
5
5
  "type": "module",
6
6
  "bin": {
@@ -19,18 +19,22 @@
19
19
  "docs/README.md",
20
20
  "docs/CODE_INTELLIGENCE.md",
21
21
  "docs/CONTEXT_BUDGET.md",
22
+ "docs/BACKGROUND_HUNTER.md",
23
+ "docs/DEPENDENCY_AUDIT.md",
24
+ "docs/ACTIVE_SECURITY_VISUAL_GATES.md",
25
+ "docs/EVOLUTION_SHADOW_MODE.md",
22
26
  "docs/WORKFLOW_EVAL.md",
23
27
  "docs/SKILL_RADAR.md",
24
28
  "docs/MEMORY_BRAIN.md",
25
29
  "docs/GOVERNANCE_DASHBOARD.md",
26
- "docs/GITLAB_FLOW.md",
27
- "docs/MEMORY_FABRIC.md",
28
- "docs/RUNTIME_EVIDENCE.md",
29
- "docs/RESOURCE_GOVERNANCE.md",
30
- "docs/start",
31
- "image",
32
- "examples/demo-projects/agent-governance-demo"
33
- ],
30
+ "docs/GITLAB_FLOW.md",
31
+ "docs/MEMORY_FABRIC.md",
32
+ "docs/RUNTIME_EVIDENCE.md",
33
+ "docs/RESOURCE_GOVERNANCE.md",
34
+ "docs/start",
35
+ "image",
36
+ "examples/demo-projects/agent-governance-demo"
37
+ ],
34
38
  "publishConfig": {
35
39
  "access": "public"
36
40
  },