@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,104 +1,104 @@
1
- # Memory Brain
2
-
3
- Memory Brain is SCALE's project-scoped long-term memory layer. It is separate from Memory Fabric:
4
-
5
- - Memory Fabric builds a compact context pack for the current task.
6
- - Memory Brain stores reviewed project knowledge with evidence, confidence, scope, and contradiction checks.
7
-
8
- The first version is local-first and uses SQLite:
9
-
10
- ```text
11
- .scale/memory/brain.sqlite
12
- .scale/memory/brain-manifest.json
13
- ```
14
-
15
- ## Commands
16
-
17
- ```bash
18
- scale memory ingest --from evidence --task-id <task-id>
19
- scale memory ingest --from candidate --candidate-id <candidate-id>
20
- scale memory ingest --from failure --failure-id <failure-replay-id>
21
- scale memory query "OAuth callback state design"
22
- scale memory contradictions
23
- scale memory dream
24
- scale memory promote <memory-node-id-or-candidate-id>
25
- scale memory export --output .scale/memory/export.jsonl
26
- scale memory import .scale/memory/export.jsonl
27
- ```
28
-
29
- ## Node Contract
30
-
31
- ```ts
32
- interface MemoryNode {
33
- id: string
34
- type: 'fact' | 'decision' | 'incident' | 'relation' | 'contradiction'
35
- title: string
36
- summary: string
37
- entities: string[]
38
- source: 'runtime-evidence' | 'task-artifact' | 'docs' | 'git' | 'manual'
39
- evidencePaths: string[]
40
- confidence: number
41
- scope: 'project' | 'workspace' | 'global-candidate'
42
- status: 'candidate' | 'active' | 'stale' | 'rejected'
43
- createdAt: string
44
- updatedAt: string
45
- lastVerifiedAt?: string
46
- }
47
- ```
48
-
49
- ## Evidence Rule
50
-
51
- Active memory must have at least one evidence path. SCALE blocks promotion when this is not true.
52
-
53
- Runtime evidence and learning candidates are ingested as `candidate` records first. `scale memory promote` is the explicit boundary where reviewed memory becomes active.
54
-
55
- Failure replay records can also be ingested as `incident` candidates:
56
-
57
- ```bash
58
- scale eval run --suite workflow-baseline
59
- scale eval failures --since 30d
60
- scale memory ingest --from failure --failure-id <failure-replay-id>
61
- scale memory promote <memory-node-id>
62
- ```
63
-
64
- This connects Eval Harness failures to long-term memory without automatically rewriting project standards. A failure becomes active memory only after promotion and only if the replay artifact is present as evidence.
65
-
66
- ## Scope Rule
67
-
68
- Project memory stays project-scoped by default. `global-candidate` is allowed for export and review, but it cannot be activated inside a project brain. This prevents one project's temporary truth from becoming a global rule.
69
-
70
- ## Contradiction Rule
71
-
72
- `scale memory contradictions` reports conflicts instead of resolving them automatically. Examples:
73
-
74
- - one memory says a provider is enabled, another says it is disabled
75
- - one memory says a route exists, another says it is missing
76
- - one memory says an operation is allowed, another says it is blocked
77
-
78
- The command exits non-zero when active contradictions exist.
79
-
80
- ## Dream Maintenance
81
-
82
- `scale memory dream` is a maintenance pass. It reports:
83
-
84
- - promotion candidates
85
- - stale active memories
86
- - duplicate groups
87
- - contradictions
88
- - suggested docs to update
89
- - active memories missing evidence
90
-
91
- It does not auto-promote standards, rewrite docs, or delete memories.
92
-
93
- ## Resource Lifecycle
94
-
95
- Memory Brain files under `.scale/memory/` are local runtime state by default. Commit only curated exports, documented decisions, or task artifacts that were intentionally reviewed.
96
-
97
- Recommended flow:
98
-
99
- ```text
100
- runtime evidence -> memory settle -> memory ingest -> memory promote -> docs/standards update when stable
101
- eval failure replay -> memory ingest --from failure -> memory promote -> workflow rule update when stable
102
- ```
103
-
104
- This keeps memory useful without turning every session observation into permanent project truth.
1
+ # Memory Brain
2
+
3
+ Memory Brain is SCALE's project-scoped long-term memory layer. It is separate from Memory Fabric:
4
+
5
+ - Memory Fabric builds a compact context pack for the current task.
6
+ - Memory Brain stores reviewed project knowledge with evidence, confidence, scope, and contradiction checks.
7
+
8
+ The first version is local-first and uses SQLite:
9
+
10
+ ```text
11
+ .scale/memory/brain.sqlite
12
+ .scale/memory/brain-manifest.json
13
+ ```
14
+
15
+ ## Commands
16
+
17
+ ```bash
18
+ scale memory ingest --from evidence --task-id <task-id>
19
+ scale memory ingest --from candidate --candidate-id <candidate-id>
20
+ scale memory ingest --from failure --failure-id <failure-replay-id>
21
+ scale memory query "OAuth callback state design"
22
+ scale memory contradictions
23
+ scale memory dream
24
+ scale memory promote <memory-node-id-or-candidate-id>
25
+ scale memory export --output .scale/memory/export.jsonl
26
+ scale memory import .scale/memory/export.jsonl
27
+ ```
28
+
29
+ ## Node Contract
30
+
31
+ ```ts
32
+ interface MemoryNode {
33
+ id: string
34
+ type: 'fact' | 'decision' | 'incident' | 'relation' | 'contradiction'
35
+ title: string
36
+ summary: string
37
+ entities: string[]
38
+ source: 'runtime-evidence' | 'task-artifact' | 'docs' | 'git' | 'manual'
39
+ evidencePaths: string[]
40
+ confidence: number
41
+ scope: 'project' | 'workspace' | 'global-candidate'
42
+ status: 'candidate' | 'active' | 'stale' | 'rejected'
43
+ createdAt: string
44
+ updatedAt: string
45
+ lastVerifiedAt?: string
46
+ }
47
+ ```
48
+
49
+ ## Evidence Rule
50
+
51
+ Active memory must have at least one evidence path. SCALE blocks promotion when this is not true.
52
+
53
+ Runtime evidence and learning candidates are ingested as `candidate` records first. `scale memory promote` is the explicit boundary where reviewed memory becomes active.
54
+
55
+ Failure replay records can also be ingested as `incident` candidates:
56
+
57
+ ```bash
58
+ scale eval run --suite workflow-baseline
59
+ scale eval failures --since 30d
60
+ scale memory ingest --from failure --failure-id <failure-replay-id>
61
+ scale memory promote <memory-node-id>
62
+ ```
63
+
64
+ This connects Eval Harness failures to long-term memory without automatically rewriting project standards. A failure becomes active memory only after promotion and only if the replay artifact is present as evidence.
65
+
66
+ ## Scope Rule
67
+
68
+ Project memory stays project-scoped by default. `global-candidate` is allowed for export and review, but it cannot be activated inside a project brain. This prevents one project's temporary truth from becoming a global rule.
69
+
70
+ ## Contradiction Rule
71
+
72
+ `scale memory contradictions` reports conflicts instead of resolving them automatically. Examples:
73
+
74
+ - one memory says a provider is enabled, another says it is disabled
75
+ - one memory says a route exists, another says it is missing
76
+ - one memory says an operation is allowed, another says it is blocked
77
+
78
+ The command exits non-zero when active contradictions exist.
79
+
80
+ ## Dream Maintenance
81
+
82
+ `scale memory dream` is a maintenance pass. It reports:
83
+
84
+ - promotion candidates
85
+ - stale active memories
86
+ - duplicate groups
87
+ - contradictions
88
+ - suggested docs to update
89
+ - active memories missing evidence
90
+
91
+ It does not auto-promote standards, rewrite docs, or delete memories.
92
+
93
+ ## Resource Lifecycle
94
+
95
+ Memory Brain files under `.scale/memory/` are local runtime state by default. Commit only curated exports, documented decisions, or task artifacts that were intentionally reviewed.
96
+
97
+ Recommended flow:
98
+
99
+ ```text
100
+ runtime evidence -> memory settle -> memory ingest -> memory promote -> docs/standards update when stable
101
+ eval failure replay -> memory ingest --from failure -> memory promote -> workflow rule update when stable
102
+ ```
103
+
104
+ This keeps memory useful without turning every session observation into permanent project truth.
@@ -1,134 +1,134 @@
1
- # Memory Fabric
2
-
3
- Memory Fabric 是 SCALE 用来降低长会话 token 消耗、提升 Agent 记忆质量的上下文压缩层。它不会把所有历史文档都塞回提示词,而是按任务范围生成一个可审计的 context pack。
4
-
5
- 它聚合四类信息:
6
-
7
- - Runtime Evidence:真实运行过的命令、工具、浏览器、skill、MCP 和人工验证证据。
8
- - Session Events:当前会话的阶段、工具使用和证据写入事件。
9
- - Knowledge Recall:从项目知识库召回已验证经验、规则和历史教训。
10
- - Project Graph:检测 `graphify-out/GRAPH_REPORT.md` 或 `.scale/graph/manifest.json`,只引用图谱状态和摘要,不把大型图谱全文塞进上下文。
11
-
12
- ## 基本命令
13
-
14
- 生成上下文包:
15
-
16
- ```bash
17
- scale memory pack \
18
- --task-id 2026-05-18-runtime-evidence \
19
- --session-id 2026-05-18-runtime-evidence \
20
- --task "继续实现 runtime evidence 与最终交付检查" \
21
- --level M \
22
- --files src/runtime,src/api/cli.ts \
23
- --budget 4000
24
- ```
25
-
26
- 输出 JSON,便于其他 Agent、CLI 或评审工具读取:
27
-
28
- ```bash
29
- scale memory pack \
30
- --task "修复 OAuth callback state 过期处理" \
31
- --level M \
32
- --budget 4000 \
33
- --json
34
- ```
35
-
36
- 检查上下文预算:
37
-
38
- ```bash
39
- scale memory doctor \
40
- --task "跨模块权限重构" \
41
- --level L \
42
- --budget 3000
43
- ```
44
-
45
- 把完成任务后的运行证据沉淀成学习候选:
46
-
47
- ```bash
48
- scale memory settle \
49
- --task-id 2026-05-18-runtime-evidence \
50
- --session-id 2026-05-18-runtime-evidence \
51
- --task "继续实现 runtime evidence 与最终交付检查" \
52
- --level M \
53
- --budget 4000
54
- ```
55
-
56
- `settle` 会写入:
57
-
58
- ```text
59
- .scale/memory/learning-candidates/<candidate-id>.json
60
- .scale/memory/learning-candidates/<candidate-id>.md
61
- ```
62
-
63
- 这些文件是本地运行时学习候选,默认不应该直接提交到 Git。它们的作用是让人类或评审 Agent 判断“这条经验是否值得进入长期知识库、工程规范或模块文档”。
64
-
65
- ## 预算策略
66
-
67
- Memory Fabric 使用估算 token 预算控制上下文规模。优先级从高到低:
68
-
69
- 1. Runtime Evidence:失败证据和通过证据优先保留。
70
- 2. Session Events:最近会话事件优先保留。
71
- 3. Knowledge Recall:按任务描述和文件范围召回 Top K 知识。
72
- 4. Project Graph:只保留图谱报告路径和短摘要。
73
-
74
- 当预算不足时,低优先级 section 会被标记为 omitted,并写入原因。这样 Agent 能知道哪些上下文被刻意裁剪,而不是误以为项目没有相关信息。
75
-
76
- ## 与知识库和自我进化的关系
77
-
78
- Memory Fabric 不替代知识库。它是知识库、运行证据和图谱之间的读取层:
79
-
80
- - Runtime Evidence 记录“这次实际做过什么”。
81
- - Knowledge Base 记录“长期可复用的经验和规则”。
82
- - Graphify 或项目图谱记录“模块之间的结构关系”。
83
- - Memory Fabric 在每次任务开始、恢复、评审或发版前,生成本次最相关的上下文包。
84
-
85
- 任务完成后,应该把真正稳定的经验沉淀到知识库或长期维护文档中;`.scale/events/` 和 `.scale/evidence/` 仍然是本地运行时产物,不应默认提交到 Git。
86
-
87
- 新的推荐闭环是:
88
-
89
- ```text
90
- runtime evidence -> memory pack -> memory settle -> 人审 -> knowledge/docs/rules
91
- ```
92
-
93
- 也就是说,Memory Fabric 先把证据和上下文压缩成候选,不会自动把一次会话里的判断升级成长期规则。存在失败证据时,候选会标记为 `resolve-failures-first`,避免把未闭环问题沉淀成“经验”。
94
-
95
- ## 推荐使用场景
96
-
97
- - 长会话恢复前:先生成 context pack,避免重复读大量文档。
98
- - 多 Agent 协作前:把 context pack 交给审查 Agent 或测试 Agent。
99
- - 发版前:用 runtime evidence 和 session events 检查是否存在未闭环失败。
100
- - 任务结束后:用 `memory settle` 生成学习候选,再决定是否进入知识库、模块文档或工程规范。
101
- - 大型项目治理:结合 service matrix、resource governance 和 engineering standards,生成任务相关而不是全仓库噪声上下文。
102
-
103
- ## 当前边界
104
-
105
- - 当前版本不内置向量数据库;如果项目配置了 SQLite knowledge base,会使用现有召回接口。
106
- - 当前版本只检测 Graphify 产物是否存在并生成摘要,不主动运行 Graphify。
107
- - HTML 可视化报告适合后续加在 context pack 之上;Memory Fabric 的核心产物先保持 JSON/Markdown,方便 diff、测试和 CLI 集成。
108
-
109
- ## Memory Provider Router
110
-
111
- SCALE now treats strong memory systems as providers instead of rebuilding them inside the workflow engine.
112
-
113
- Default provider order:
114
-
115
- ```text
116
- agentmemory -> gbrain -> scale-local
117
- ```
118
-
119
- Commands:
120
-
121
- ```bash
122
- scale memory provider init
123
- scale memory provider status --json
124
- scale memory provider recall "OAuth callback Redis state" --json
125
- ```
126
-
127
- Provider rules:
128
-
129
- - `agentmemory` and `gbrain` are external providers and start disabled until endpoint, privacy, retention, and delete boundaries are reviewed.
130
- - External providers are read-only by default. Writes require an explicit provider policy change.
131
- - `scale-local` remains the fallback provider through Memory Brain and only promotes reviewed, evidence-backed memory.
132
- - `memory pack` automatically includes a `provider-memory` section when provider recall returns relevant active memories.
133
-
134
- This keeps agents flexible: they can ask the router for memory before planning, verification, review, or release, while SCALE still records which provider was used and why fallback was required.
1
+ # Memory Fabric
2
+
3
+ Memory Fabric 是 SCALE 用来降低长会话 token 消耗、提升 Agent 记忆质量的上下文压缩层。它不会把所有历史文档都塞回提示词,而是按任务范围生成一个可审计的 context pack。
4
+
5
+ 它聚合四类信息:
6
+
7
+ - Runtime Evidence:真实运行过的命令、工具、浏览器、skill、MCP 和人工验证证据。
8
+ - Session Events:当前会话的阶段、工具使用和证据写入事件。
9
+ - Knowledge Recall:从项目知识库召回已验证经验、规则和历史教训。
10
+ - Project Graph:检测 `graphify-out/GRAPH_REPORT.md` 或 `.scale/graph/manifest.json`,只引用图谱状态和摘要,不把大型图谱全文塞进上下文。
11
+
12
+ ## 基本命令
13
+
14
+ 生成上下文包:
15
+
16
+ ```bash
17
+ scale memory pack \
18
+ --task-id 2026-05-18-runtime-evidence \
19
+ --session-id 2026-05-18-runtime-evidence \
20
+ --task "继续实现 runtime evidence 与最终交付检查" \
21
+ --level M \
22
+ --files src/runtime,src/api/cli.ts \
23
+ --budget 4000
24
+ ```
25
+
26
+ 输出 JSON,便于其他 Agent、CLI 或评审工具读取:
27
+
28
+ ```bash
29
+ scale memory pack \
30
+ --task "修复 OAuth callback state 过期处理" \
31
+ --level M \
32
+ --budget 4000 \
33
+ --json
34
+ ```
35
+
36
+ 检查上下文预算:
37
+
38
+ ```bash
39
+ scale memory doctor \
40
+ --task "跨模块权限重构" \
41
+ --level L \
42
+ --budget 3000
43
+ ```
44
+
45
+ 把完成任务后的运行证据沉淀成学习候选:
46
+
47
+ ```bash
48
+ scale memory settle \
49
+ --task-id 2026-05-18-runtime-evidence \
50
+ --session-id 2026-05-18-runtime-evidence \
51
+ --task "继续实现 runtime evidence 与最终交付检查" \
52
+ --level M \
53
+ --budget 4000
54
+ ```
55
+
56
+ `settle` 会写入:
57
+
58
+ ```text
59
+ .scale/memory/learning-candidates/<candidate-id>.json
60
+ .scale/memory/learning-candidates/<candidate-id>.md
61
+ ```
62
+
63
+ 这些文件是本地运行时学习候选,默认不应该直接提交到 Git。它们的作用是让人类或评审 Agent 判断“这条经验是否值得进入长期知识库、工程规范或模块文档”。
64
+
65
+ ## 预算策略
66
+
67
+ Memory Fabric 使用估算 token 预算控制上下文规模。优先级从高到低:
68
+
69
+ 1. Runtime Evidence:失败证据和通过证据优先保留。
70
+ 2. Session Events:最近会话事件优先保留。
71
+ 3. Knowledge Recall:按任务描述和文件范围召回 Top K 知识。
72
+ 4. Project Graph:只保留图谱报告路径和短摘要。
73
+
74
+ 当预算不足时,低优先级 section 会被标记为 omitted,并写入原因。这样 Agent 能知道哪些上下文被刻意裁剪,而不是误以为项目没有相关信息。
75
+
76
+ ## 与知识库和自我进化的关系
77
+
78
+ Memory Fabric 不替代知识库。它是知识库、运行证据和图谱之间的读取层:
79
+
80
+ - Runtime Evidence 记录“这次实际做过什么”。
81
+ - Knowledge Base 记录“长期可复用的经验和规则”。
82
+ - Graphify 或项目图谱记录“模块之间的结构关系”。
83
+ - Memory Fabric 在每次任务开始、恢复、评审或发版前,生成本次最相关的上下文包。
84
+
85
+ 任务完成后,应该把真正稳定的经验沉淀到知识库或长期维护文档中;`.scale/events/` 和 `.scale/evidence/` 仍然是本地运行时产物,不应默认提交到 Git。
86
+
87
+ 新的推荐闭环是:
88
+
89
+ ```text
90
+ runtime evidence -> memory pack -> memory settle -> 人审 -> knowledge/docs/rules
91
+ ```
92
+
93
+ 也就是说,Memory Fabric 先把证据和上下文压缩成候选,不会自动把一次会话里的判断升级成长期规则。存在失败证据时,候选会标记为 `resolve-failures-first`,避免把未闭环问题沉淀成“经验”。
94
+
95
+ ## 推荐使用场景
96
+
97
+ - 长会话恢复前:先生成 context pack,避免重复读大量文档。
98
+ - 多 Agent 协作前:把 context pack 交给审查 Agent 或测试 Agent。
99
+ - 发版前:用 runtime evidence 和 session events 检查是否存在未闭环失败。
100
+ - 任务结束后:用 `memory settle` 生成学习候选,再决定是否进入知识库、模块文档或工程规范。
101
+ - 大型项目治理:结合 service matrix、resource governance 和 engineering standards,生成任务相关而不是全仓库噪声上下文。
102
+
103
+ ## 当前边界
104
+
105
+ - 当前版本不内置向量数据库;如果项目配置了 SQLite knowledge base,会使用现有召回接口。
106
+ - 当前版本只检测 Graphify 产物是否存在并生成摘要,不主动运行 Graphify。
107
+ - HTML 可视化报告适合后续加在 context pack 之上;Memory Fabric 的核心产物先保持 JSON/Markdown,方便 diff、测试和 CLI 集成。
108
+
109
+ ## Memory Provider Router
110
+
111
+ SCALE now treats strong memory systems as providers instead of rebuilding them inside the workflow engine.
112
+
113
+ Default provider order:
114
+
115
+ ```text
116
+ agentmemory -> gbrain -> scale-local
117
+ ```
118
+
119
+ Commands:
120
+
121
+ ```bash
122
+ scale memory provider init
123
+ scale memory provider status --json
124
+ scale memory provider recall "OAuth callback Redis state" --json
125
+ ```
126
+
127
+ Provider rules:
128
+
129
+ - `agentmemory` and `gbrain` are external providers and start disabled until endpoint, privacy, retention, and delete boundaries are reviewed.
130
+ - External providers are read-only by default. Writes require an explicit provider policy change.
131
+ - `scale-local` remains the fallback provider through Memory Brain and only promotes reviewed, evidence-backed memory.
132
+ - `memory pack` automatically includes a `provider-memory` section when provider recall returns relevant active memories.
133
+
134
+ This keeps agents flexible: they can ask the router for memory before planning, verification, review, or release, while SCALE still records which provider was used and why fallback was required.