@octopi-agent/engine 0.58.0 → 0.70.7

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 (226) hide show
  1. package/dist/config-schema/context.d.ts +1 -1
  2. package/dist/config-schema/context.js +1 -1
  3. package/dist/config-schema/engine.d.ts +122 -1
  4. package/dist/config-schema/engine.js +4 -1
  5. package/dist/config-schema/substrate.d.ts +123 -0
  6. package/dist/config-schema/substrate.js +161 -0
  7. package/dist/config.d.ts +101 -1
  8. package/dist/harness/agent/builder.d.ts +15 -1
  9. package/dist/harness/agent/builder.js +41 -4
  10. package/dist/harness/agent/config-bridge.js +17 -4
  11. package/dist/harness/{context/capabilities → capabilities}/document/backends/docx.d.ts +1 -1
  12. package/dist/harness/{context/capabilities → capabilities}/document/backends/docx.js +1 -1
  13. package/dist/harness/{context/capabilities → capabilities}/document/backends/office-parser.d.ts +1 -1
  14. package/dist/harness/{context/capabilities → capabilities}/document/backends/office-parser.js +1 -1
  15. package/dist/harness/{context/capabilities → capabilities}/document/backends/pdf.d.ts +1 -1
  16. package/dist/harness/{context/capabilities → capabilities}/document/backends/pdf.js +13 -3
  17. package/dist/harness/{context/capabilities → capabilities}/document/backends/plain.d.ts +1 -1
  18. package/dist/harness/{context/capabilities → capabilities}/document/backends/plain.js +13 -4
  19. package/dist/harness/{context/capabilities → capabilities}/document/backends/sheet.d.ts +1 -1
  20. package/dist/harness/{context/capabilities → capabilities}/document/backends/sheet.js +25 -5
  21. package/dist/harness/{context/capabilities → capabilities}/document/backends/xmind.d.ts +1 -1
  22. package/dist/harness/{context/capabilities → capabilities}/document/backends/xmind.js +1 -1
  23. package/dist/harness/{context/capabilities → capabilities}/document/errors.d.ts +1 -1
  24. package/dist/harness/{context/capabilities → capabilities}/document/errors.js +1 -1
  25. package/dist/harness/capabilities/document/factory.d.ts +33 -0
  26. package/dist/harness/capabilities/document/factory.js +37 -0
  27. package/dist/harness/{context/capabilities → capabilities}/document/format.d.ts +1 -1
  28. package/dist/harness/{context/capabilities → capabilities}/document/format.js +1 -1
  29. package/dist/harness/{context/capabilities → capabilities}/document/html-to-md.d.ts +1 -1
  30. package/dist/harness/{context/capabilities → capabilities}/document/html-to-md.js +1 -1
  31. package/dist/harness/{context/capabilities → capabilities}/document/index.d.ts +3 -1
  32. package/dist/harness/{context/capabilities → capabilities}/document/index.js +2 -1
  33. package/dist/harness/{context/capabilities → capabilities}/document/legacy/factory.d.ts +3 -1
  34. package/dist/harness/{context/capabilities → capabilities}/document/legacy/factory.js +3 -1
  35. package/dist/harness/{context/capabilities → capabilities}/document/legacy/soffice.d.ts +3 -1
  36. package/dist/harness/{context/capabilities → capabilities}/document/legacy/soffice.js +44 -1
  37. package/dist/harness/{context/capabilities → capabilities}/document/port.d.ts +1 -1
  38. package/dist/harness/{context/capabilities → capabilities}/document/port.js +4 -4
  39. package/dist/harness/{context/capabilities → capabilities}/document/types.d.ts +11 -1
  40. package/dist/harness/{context/capabilities → capabilities}/document/types.js +1 -1
  41. package/dist/harness/capabilities/document/worker-port.d.ts +13 -0
  42. package/dist/harness/capabilities/document/worker-port.js +78 -0
  43. package/dist/harness/context/capabilities/index.d.ts +2 -2
  44. package/dist/harness/context/capabilities/index.js +2 -2
  45. package/dist/harness/context/capabilities/summary/gate.js +2 -2
  46. package/dist/harness/context/capabilities/summary/policies.js +5 -5
  47. package/dist/harness/context/capabilities/summary/registry.js +29 -24
  48. package/dist/harness/context/layer-health.js +3 -2
  49. package/dist/harness/context/layers.d.ts +27 -13
  50. package/dist/harness/context/layers.js +76 -66
  51. package/dist/harness/context/system-prompt-assembler.d.ts +3 -0
  52. package/dist/harness/context/system-prompt-assembler.js +11 -1
  53. package/dist/harness/extension/plugin-ecosystem/client-tools/index.d.ts +4 -0
  54. package/dist/harness/extension/plugin-ecosystem/client-tools/index.js +3 -0
  55. package/dist/harness/extension/plugin-ecosystem/client-tools/invoke.d.ts +56 -0
  56. package/dist/harness/extension/plugin-ecosystem/client-tools/invoke.js +281 -0
  57. package/dist/harness/extension/plugin-ecosystem/client-tools/registry.d.ts +98 -0
  58. package/dist/harness/extension/plugin-ecosystem/client-tools/registry.js +250 -0
  59. package/dist/harness/extension/plugin-ecosystem/client-tools/stream.d.ts +124 -0
  60. package/dist/harness/extension/plugin-ecosystem/client-tools/stream.js +372 -0
  61. package/dist/harness/extension/plugin-ecosystem/client-tools/types.d.ts +109 -0
  62. package/dist/harness/extension/plugin-ecosystem/client-tools/types.js +8 -0
  63. package/dist/harness/extension/plugin-ecosystem/index.d.ts +1 -0
  64. package/dist/harness/extension/plugin-ecosystem/index.js +1 -0
  65. package/dist/harness/extension/plugin-ecosystem/tools/builtin.js +1 -1
  66. package/dist/harness/extension/plugin-ecosystem/tools/knowledge.d.ts +10 -0
  67. package/dist/harness/extension/plugin-ecosystem/tools/knowledge.js +102 -5
  68. package/dist/harness/extension/plugin-ecosystem/tools/memory.d.ts +11 -1
  69. package/dist/harness/extension/plugin-ecosystem/tools/memory.js +14 -0
  70. package/dist/harness/index.d.ts +8 -5
  71. package/dist/harness/index.js +4 -2
  72. package/dist/harness/knowledge/adapters.d.ts +8 -5
  73. package/dist/harness/knowledge/adapters.js +53 -13
  74. package/dist/harness/knowledge/client.d.ts +197 -0
  75. package/dist/harness/knowledge/client.js +237 -0
  76. package/dist/harness/knowledge/connector-fetcher.d.ts +2 -2
  77. package/dist/harness/knowledge/connectors.d.ts +3 -3
  78. package/dist/harness/knowledge/connectors.js +14 -8
  79. package/dist/harness/knowledge/db.d.ts +40 -5
  80. package/dist/harness/knowledge/db.js +441 -113
  81. package/dist/harness/knowledge/document-extract-worker.js +55 -12
  82. package/dist/harness/knowledge/embed-runner.d.ts +53 -0
  83. package/dist/harness/knowledge/embed-runner.js +171 -0
  84. package/dist/harness/knowledge/engine-thread.d.ts +1 -0
  85. package/dist/harness/knowledge/engine-thread.js +302 -0
  86. package/dist/harness/knowledge/extract-document.d.ts +21 -5
  87. package/dist/harness/knowledge/extract-document.js +32 -8
  88. package/dist/harness/knowledge/fetchers.d.ts +14 -3
  89. package/dist/harness/knowledge/fetchers.js +52 -16
  90. package/dist/harness/knowledge/file-identity.d.ts +53 -0
  91. package/dist/harness/knowledge/file-identity.js +172 -0
  92. package/dist/harness/knowledge/file-index-store.d.ts +50 -0
  93. package/dist/harness/knowledge/file-index-store.js +132 -0
  94. package/dist/harness/knowledge/file-limits.d.ts +86 -0
  95. package/dist/harness/knowledge/file-limits.js +175 -0
  96. package/dist/harness/knowledge/fts.d.ts +60 -0
  97. package/dist/harness/knowledge/fts.js +218 -0
  98. package/dist/harness/knowledge/grounding.d.ts +3 -2
  99. package/dist/harness/knowledge/http-app.d.ts +50 -0
  100. package/dist/harness/knowledge/http-app.js +652 -0
  101. package/dist/harness/knowledge/http-bridge.d.ts +49 -0
  102. package/dist/harness/knowledge/http-bridge.js +17 -0
  103. package/dist/harness/knowledge/index-store.d.ts +158 -93
  104. package/dist/harness/knowledge/index-store.js +982 -441
  105. package/dist/harness/knowledge/index.d.ts +45 -5
  106. package/dist/harness/knowledge/index.js +23 -2
  107. package/dist/harness/knowledge/ingest.d.ts +262 -87
  108. package/dist/harness/knowledge/ingest.js +1072 -480
  109. package/dist/harness/knowledge/job-control-state.d.ts +29 -0
  110. package/dist/harness/knowledge/job-control-state.js +44 -0
  111. package/dist/harness/knowledge/job-control.d.ts +35 -0
  112. package/dist/harness/knowledge/job-control.js +86 -0
  113. package/dist/harness/knowledge/job-queue.d.ts +62 -0
  114. package/dist/harness/knowledge/job-queue.js +173 -0
  115. package/dist/harness/knowledge/knowledge-serve-child.d.ts +1 -0
  116. package/dist/harness/knowledge/knowledge-serve-child.js +100 -0
  117. package/dist/harness/knowledge/local-stack.d.ts +27 -0
  118. package/dist/harness/knowledge/local-stack.js +63 -0
  119. package/dist/harness/knowledge/membership-store.d.ts +65 -0
  120. package/dist/harness/knowledge/membership-store.js +198 -0
  121. package/dist/harness/knowledge/network-guard.d.ts +11 -2
  122. package/dist/harness/knowledge/network-guard.js +130 -85
  123. package/dist/harness/knowledge/parse-text-in-worker.d.ts +32 -0
  124. package/dist/harness/knowledge/parse-text-in-worker.js +158 -0
  125. package/dist/harness/knowledge/query-service.d.ts +272 -0
  126. package/dist/harness/knowledge/query-service.js +326 -0
  127. package/dist/harness/knowledge/query-worker-client.d.ts +96 -0
  128. package/dist/harness/knowledge/query-worker-client.js +207 -0
  129. package/dist/harness/knowledge/query-worker.d.ts +1 -0
  130. package/dist/harness/knowledge/query-worker.js +186 -0
  131. package/dist/harness/knowledge/read-http.d.ts +35 -0
  132. package/dist/harness/knowledge/read-http.js +373 -0
  133. package/dist/harness/knowledge/retriever.d.ts +22 -5
  134. package/dist/harness/knowledge/retriever.js +66 -35
  135. package/dist/harness/knowledge/secret-scan.d.ts +13 -2
  136. package/dist/harness/knowledge/secret-scan.js +25 -2
  137. package/dist/harness/knowledge/serve.d.ts +48 -0
  138. package/dist/harness/knowledge/serve.js +336 -0
  139. package/dist/harness/knowledge/source-store.d.ts +97 -19
  140. package/dist/harness/knowledge/source-store.js +166 -94
  141. package/dist/harness/knowledge/start-service-process.d.ts +49 -0
  142. package/dist/harness/knowledge/start-service-process.js +158 -0
  143. package/dist/harness/knowledge/text-parse-worker.d.ts +1 -0
  144. package/dist/harness/knowledge/text-parse-worker.js +54 -0
  145. package/dist/harness/knowledge/types.d.ts +1 -1
  146. package/dist/harness/knowledge/types.js +1 -1
  147. package/dist/harness/knowledge/vector-ann.d.ts +42 -0
  148. package/dist/harness/knowledge/vector-ann.js +68 -0
  149. package/dist/harness/knowledge/writer-lock.d.ts +13 -0
  150. package/dist/harness/knowledge/writer-lock.js +71 -0
  151. package/dist/harness/knowledge/writer-service.d.ts +194 -0
  152. package/dist/harness/knowledge/writer-service.js +355 -0
  153. package/dist/harness/knowledge/writer-worker-client.d.ts +102 -0
  154. package/dist/harness/knowledge/writer-worker-client.js +381 -0
  155. package/dist/harness/knowledge/writer-worker.d.ts +1 -0
  156. package/dist/harness/knowledge/writer-worker.js +189 -0
  157. package/dist/harness/memory/cognition-decay.d.ts +36 -0
  158. package/dist/harness/memory/cognition-decay.js +55 -0
  159. package/dist/harness/memory/cognition-gates.d.ts +60 -0
  160. package/dist/harness/memory/cognition-gates.js +191 -0
  161. package/dist/harness/memory/cognition-trigger.d.ts +30 -0
  162. package/dist/harness/memory/cognition-trigger.js +41 -0
  163. package/dist/harness/memory/cognition-types.d.ts +1 -1
  164. package/dist/harness/memory/cognition.d.ts +40 -8
  165. package/dist/harness/memory/cognition.js +432 -79
  166. package/dist/harness/memory/conceptualizer.d.ts +66 -0
  167. package/dist/harness/memory/conceptualizer.js +246 -0
  168. package/dist/harness/memory/index.d.ts +16 -2
  169. package/dist/harness/memory/index.js +11 -1
  170. package/dist/harness/memory/sqlite/agent-db.d.ts +9 -0
  171. package/dist/harness/memory/sqlite/agent-db.js +118 -15
  172. package/dist/harness/memory/sqlite/cognition-store.d.ts +55 -16
  173. package/dist/harness/memory/sqlite/cognition-store.js +591 -144
  174. package/dist/harness/memory/sqlite/embedding.d.ts +5 -2
  175. package/dist/harness/memory/sqlite/embedding.js +109 -16
  176. package/dist/harness/memory/sqlite/keyword-search.d.ts +21 -0
  177. package/dist/harness/memory/sqlite/keyword-search.js +64 -0
  178. package/dist/harness/memory/sqlite/wisdom-store.d.ts +33 -14
  179. package/dist/harness/memory/sqlite/wisdom-store.js +257 -44
  180. package/dist/harness/memory/types.d.ts +331 -16
  181. package/dist/harness/memory/types.js +49 -0
  182. package/dist/harness/memory/wisdom-formation.d.ts +101 -0
  183. package/dist/harness/memory/wisdom-formation.js +304 -0
  184. package/dist/harness/memory/wisdom-gates.d.ts +50 -0
  185. package/dist/harness/memory/wisdom-gates.js +204 -0
  186. package/dist/harness/memory/wisdom-policy.d.ts +107 -0
  187. package/dist/harness/memory/wisdom-policy.js +220 -0
  188. package/dist/harness/memory/wisdom-types.d.ts +3 -2
  189. package/dist/harness/memory/wisdom-types.js +2 -2
  190. package/dist/harness/memory/wisdom.d.ts +27 -0
  191. package/dist/harness/memory/wisdom.js +181 -0
  192. package/dist/harness/run/agent/agent.d.ts +9 -0
  193. package/dist/harness/run/agent/agent.js +19 -0
  194. package/dist/harness/run/reliability/run-agent.js +6 -2
  195. package/dist/harness/run/runner.js +2 -1
  196. package/dist/harness/session/attachments/service.d.ts +1 -1
  197. package/dist/harness/session/attachments/service.js +1 -1
  198. package/dist/harness/session/index.d.ts +1 -0
  199. package/dist/harness/session/index.js +1 -0
  200. package/dist/harness/session/title.d.ts +86 -0
  201. package/dist/harness/session/title.js +268 -0
  202. package/dist/harness/shared/events/agent-event-map.d.ts +8 -0
  203. package/dist/harness/shared/events/agent-event-map.js +1 -0
  204. package/dist/index.d.ts +7 -3
  205. package/dist/index.js +3 -1
  206. package/dist/subsystems/cognition-steward/conceptualize/SUBSYSTEM.md +43 -0
  207. package/dist/subsystems/cognition-steward/conceptualize/config.yaml +50 -0
  208. package/dist/subsystems/cognition-steward/conceptualize/handler.d.ts +9 -0
  209. package/dist/subsystems/cognition-steward/conceptualize/handler.js +125 -0
  210. package/dist/subsystems/cognition-steward/consolidate/SUBSYSTEM.md +6 -0
  211. package/dist/subsystems/cognition-steward/consolidate/config.yaml +54 -0
  212. package/dist/subsystems/cognition-steward/consolidate/handler.d.ts +12 -0
  213. package/dist/subsystems/cognition-steward/consolidate/handler.js +93 -0
  214. package/dist/subsystems/wisdom-steward/evaluate/config.yaml +50 -0
  215. package/dist/subsystems/wisdom-steward/evaluate/handler.d.ts +18 -0
  216. package/dist/subsystems/wisdom-steward/evaluate/handler.js +91 -0
  217. package/dist/subsystems/wisdom-steward/formation/SUBSYSTEM.md +42 -0
  218. package/dist/subsystems/wisdom-steward/formation/config.yaml +54 -0
  219. package/dist/subsystems/wisdom-steward/formation/handler.d.ts +18 -0
  220. package/dist/subsystems/wisdom-steward/formation/handler.js +212 -0
  221. package/dist/subsystems/wisdom-steward/govern/config.yaml +55 -0
  222. package/dist/subsystems/wisdom-steward/govern/handler.d.ts +17 -0
  223. package/dist/subsystems/wisdom-steward/govern/handler.js +68 -0
  224. package/dist/worker-path.d.ts +8 -0
  225. package/dist/worker-path.js +15 -0
  226. package/package.json +2 -2
@@ -115,50 +115,365 @@ export interface MemoryStore {
115
115
  }): Promise<number>;
116
116
  stats(): Promise<MemoryStats>;
117
117
  }
118
- /** 智慧条目 — 思维范式 */
118
+ /** 范式生命周期 */
119
+ export type WisdomStatus = 'candidate' | 'trial' | 'active' | 'strengthened' | 'contested' | 'retired' | 'superseded';
120
+ export declare const WISDOM_STATUSES: readonly WisdomStatus[];
121
+ /** 可注入状态(contested 默认不注入) */
122
+ export declare const WISDOM_INJECTABLE_STATUSES: readonly WisdomStatus[];
123
+ /** 写入来源 */
124
+ export type WisdomOrigin = 'factory' | 'distilled' | 'agent_write' | 'admin';
125
+ export declare const WISDOM_ORIGINS: readonly WisdomOrigin[];
126
+ /** 范式形态 */
127
+ export type WisdomKind = 'generalize' | 'corrective' | 'selection' | 'boundary';
128
+ export declare const WISDOM_KINDS: readonly WisdomKind[];
129
+ /** 软退休原因 */
130
+ export type WisdomRetireReason = 'capacity' | 'high_miss' | 'zero_apply' | 'superseded' | 'counterevidence' | 'admin';
131
+ /** 适用域 — 问题形态签名(非主题关键词堆) */
132
+ export interface WisdomScenario {
133
+ /** 问题形态(如「验证型宣称」「失败排查」) */
134
+ problemTypes: string[];
135
+ /** 触发线索(任务特征 / 领域 / 失败模式) */
136
+ signals?: string[];
137
+ /** 明确不适用 */
138
+ antiScenarios?: string[];
139
+ }
140
+ /** 操作效应 — 元认知可执行(禁止空壳格言) */
141
+ export interface WisdomEffect {
142
+ /** 推理时先问的问题 */
143
+ questions?: string[];
144
+ /** 要校准的偏见 */
145
+ biases?: string[];
146
+ /** 姿态简述 */
147
+ posture?: string;
148
+ }
149
+ /** 溯源 — MDL 多源压缩 */
150
+ export interface WisdomDerivation {
151
+ memoryIds: string[];
152
+ conceptIds?: string[];
153
+ sessionIds?: string[];
154
+ communityId?: string;
155
+ promotionBatchId?: string;
156
+ }
157
+ /** 反证登记(可错论) */
158
+ export interface WisdomCounterevidence {
159
+ ref: string;
160
+ note: string;
161
+ at: number;
162
+ weight: number;
163
+ }
164
+ /** 结局统计(弱归因线索,非因果证明) */
165
+ export interface WisdomOutcomes {
166
+ applied: number;
167
+ cited: number;
168
+ assisted: number;
169
+ contested: number;
170
+ lastAppliedAt?: number;
171
+ lastOutcomeAt?: number;
172
+ /** 置信度评估水位:已并入 confidence 的 assisted/contested 累计值(增量更新) */
173
+ evalAssisted?: number;
174
+ evalContested?: number;
175
+ }
176
+ /** 智慧条目 — 判断范式(maxim) */
119
177
  export interface WisdomEntry {
120
178
  id: string;
121
- content: string;
122
- derivedFrom: string[];
179
+ /** 核心范式陈述 */
180
+ statement: string;
181
+ rationale?: string;
182
+ scenario: WisdomScenario;
183
+ effect: WisdomEffect;
184
+ status: WisdomStatus;
185
+ confidence: number;
123
186
  priority: number;
124
- confidence?: number;
187
+ derivedFrom: WisdomDerivation;
188
+ exceptions?: string[];
189
+ counterevidence?: WisdomCounterevidence[];
190
+ outcomes: WisdomOutcomes;
191
+ origin: WisdomOrigin;
192
+ kind: WisdomKind;
193
+ supersededBy?: string;
125
194
  createdAt: number;
126
- applicableScenarios?: string[];
195
+ updatedAt: number;
196
+ }
197
+ /** 出生门控 reason */
198
+ export type WisdomGateReason = 'ok' | 'empty_statement' | 'statement_too_long' | 'empty_problem_types' | 'empty_effect' | 'secret_like' | 'persona_overwrite' | 'insufficient_support' | 'duplicate_statement' | 'semantic_conflict' | 'capacity_admit_stop' | 'invalid_status' | 'invalid_origin' | 'invalid_kind' | 'missing_derived_from' | 'unknown_derived_id' | 'supersedes_target_missing';
199
+ export interface WisdomGateOutcome {
200
+ ok: boolean;
201
+ reason: WisdomGateReason;
202
+ message?: string;
203
+ }
204
+ /** admit 入口(代码执法;意图归 LLM) */
205
+ export interface AdmitWisdomInput {
206
+ statement: string;
207
+ rationale?: string;
208
+ scenario: WisdomScenario;
209
+ effect: WisdomEffect;
210
+ derivedFrom: WisdomDerivation;
211
+ kind: WisdomKind;
212
+ origin?: WisdomOrigin;
213
+ exceptions?: string[];
214
+ /** 显式取代既有条目 */
215
+ supersedesId?: string;
216
+ priority?: number;
217
+ confidence?: number;
218
+ /** factory / 显式 agent_write 可直达 active;distilled 一律 trial 起步 */
219
+ initialStatus?: WisdomStatus;
220
+ }
221
+ export type AdmitWisdomAction = 'created' | 'superseded' | 'rejected';
222
+ export interface AdmitWisdomResult {
223
+ action: AdmitWisdomAction;
224
+ id?: string;
225
+ reason?: WisdomGateReason;
226
+ message?: string;
227
+ }
228
+ /** 注入检索 */
229
+ export interface WisdomInjectQuery {
230
+ /** 本轮任务/查询文本(场景匹配) */
231
+ text?: string;
232
+ /** 小核心条数硬顶 */
233
+ coreMaxItems?: number;
234
+ /** 场景条数硬顶 */
235
+ scenarioMaxItems?: number;
236
+ /** 是否包含 trial(默认 false) */
237
+ includeTrial?: boolean;
238
+ }
239
+ export interface WisdomInjectPick {
240
+ entry: WisdomEntry;
241
+ /** core = 常备小核心;scenario = 本轮匹配 */
242
+ bucket: 'core' | 'scenario';
243
+ /** 场景匹配分(core 为 1) */
244
+ score: number;
127
245
  }
128
- /** WisdomStore — 智慧存储接口 */
246
+ export type WisdomOutcomeSignal = 'applied' | 'cited' | 'assisted' | 'contested' | 'ignored';
247
+ /** 结局观测窗口内的一次弱信号 */
248
+ export interface WisdomOutcomeEvent {
249
+ wisdomId: string;
250
+ signal: WisdomOutcomeSignal;
251
+ at?: number;
252
+ note?: string;
253
+ ref?: string;
254
+ }
255
+ export interface WisdomStats {
256
+ total: number;
257
+ byStatus: Record<WisdomStatus, number>;
258
+ avgConfidence: number;
259
+ avgPriority: number;
260
+ totalApplied: number;
261
+ totalContested: number;
262
+ }
263
+ /**
264
+ * WisdomStore — 判断范式存储
265
+ *
266
+ * 写入只经 admit*(门控在 wisdom-gates)。检索主路径是 selectForInjection。
267
+ */
129
268
  export interface WisdomStore {
130
- store(entry: Omit<WisdomEntry, 'id' | 'createdAt'>): Promise<string>;
131
- getAll(): Promise<WisdomEntry[]>;
132
- delete(id: string): Promise<void>;
269
+ readonly name: string;
270
+ admit(input: AdmitWisdomInput, options?: {
271
+ allowedMemoryIds?: ReadonlySet<string>;
272
+ }): Promise<AdmitWisdomResult>;
273
+ get(id: string): Promise<WisdomEntry | null>;
274
+ /** 注入选择:core + scenario(不含 retired/superseded/candidate) */
275
+ selectForInjection(query: WisdomInjectQuery): Promise<WisdomInjectPick[]>;
276
+ /** 治理全量读(含 contested;不含 superseded 链内容可另取) */
277
+ listForGovern(filter?: {
278
+ includeRetired?: boolean;
279
+ }): Promise<WisdomEntry[]>;
280
+ update(id: string, patch: Partial<WisdomEntry>): Promise<void>;
281
+ softRetire(id: string, meta: {
282
+ by: string;
283
+ reason: WisdomRetireReason | string;
284
+ }): Promise<void>;
285
+ /** 弱归因结局入账 */
286
+ recordOutcomes(events: WisdomOutcomeEvent[]): Promise<void>;
287
+ /** 注入命中轻量入账(S1 applied);不跑 confidence 规划 */
288
+ touchApplied(ids: string[]): Promise<void>;
289
+ stats(): Promise<WisdomStats>;
133
290
  }
134
- /** 概念节点 */
291
+ /** 概念种类 — 基本层级偏置 */
292
+ export type ConceptKind = 'entity' | 'construct' | 'method' | 'problem' | 'constraint';
293
+ export declare const CONCEPT_KINDS: readonly ConceptKind[];
294
+ /** 关系类型;`related` 为弱边(共现级) */
295
+ export type ConceptRelationType = 'causes' | 'part_of' | 'opposes' | 'similar_to' | 'evolves_to' | 'related';
296
+ export declare const CONCEPT_RELATION_TYPES: readonly ConceptRelationType[];
297
+ /** 强关系(需持证);`related` / `similar_to` 不在此列 */
298
+ export declare const STRONG_RELATION_TYPES: readonly ConceptRelationType[];
299
+ /** 概念/边运行时状态(与 Memory 对齐) */
300
+ export type ConceptStatus = 'shadow' | 'active' | 'strengthened';
301
+ /** 证据形态 — 持证件字段 */
302
+ export type EvidenceClass = 'causal' | 'mereonymy' | 'negation' | 'analogy' | 'evolution' | 'cooccur';
303
+ /** 边持证件:强边入库必填 */
304
+ export interface EdgeBasis {
305
+ /** 独立支撑命题 */
306
+ memoryIds: string[];
307
+ /** 证据中的原句片段(须 ⊆ evidence/contextSlice) */
308
+ cue: string;
309
+ evidenceClass: EvidenceClass;
310
+ licensedAt: number;
311
+ }
312
+ /** 概念节点(义项,非词面) */
135
313
  export interface ConceptNode {
136
314
  id: string;
137
315
  name: string;
316
+ kind: ConceptKind;
317
+ /** 原型描述(含论域) */
138
318
  description?: string;
139
319
  frequency: number;
140
320
  memoryIds: string[];
321
+ /** 论域标签(义项指纹) */
322
+ domain: string[];
323
+ status: ConceptStatus;
324
+ embedding?: number[] | null;
325
+ createdAt: number;
326
+ updatedAt: number;
141
327
  }
142
328
  /** 概念关系 */
143
329
  export interface ConceptEdge {
330
+ id: string;
144
331
  sourceId: string;
145
332
  targetId: string;
146
- relationType: 'causes' | 'part_of' | 'opposes' | 'similar_to' | 'evolves_to' | 'related';
333
+ relationType: ConceptRelationType;
147
334
  strength: number;
148
335
  description?: string;
336
+ status: ConceptStatus;
337
+ basis: EdgeBasis;
338
+ createdAt: number;
339
+ updatedAt: number;
149
340
  }
150
341
  /** 认知图谱 */
151
342
  export interface ConceptGraph {
152
343
  nodes: ConceptNode[];
153
344
  edges: ConceptEdge[];
154
345
  }
155
- /** ConceptGraphStore — 认知图谱存储接口 */
346
+ /** 合并候选(近阈带 / 指纹可疑) */
347
+ export interface MergeCandidate {
348
+ id: string;
349
+ leftId: string;
350
+ rightId: string;
351
+ reason: string;
352
+ distance: number | null;
353
+ fingerprintDiff: string[];
354
+ status: 'open' | 'merged' | 'kept_split' | 'dropped';
355
+ createdAt: number;
356
+ resolvedAt?: number;
357
+ resolvedAction?: string;
358
+ }
359
+ /** `causal_candidate` 等旁路假设,不进慢图强边 */
360
+ export interface EdgeAux {
361
+ id: string;
362
+ edgeKey: string;
363
+ kind: 'causal_candidate';
364
+ memoryIds: string[];
365
+ cue: string;
366
+ note?: string;
367
+ createdAt: number;
368
+ }
369
+ export type AdmitConceptAction = 'created' | 'merged' | 'merge_candidate' | 'rejected';
370
+ export interface AdmitConceptResult {
371
+ action: AdmitConceptAction;
372
+ /** created / merged 时的节点 id */
373
+ id?: string;
374
+ /** merge_candidate 时的候选 id */
375
+ candidateId?: string;
376
+ reason?: ConceptGateReason;
377
+ message?: string;
378
+ }
379
+ export type AdmitEdgeAction = 'active' | 'shadow' | 'demoted' | 'rejected' | 'candidate_only';
380
+ export interface AdmitEdgeResult {
381
+ action: AdmitEdgeAction;
382
+ edgeId?: string;
383
+ /** demoted 时实际入库的关系类型 */
384
+ relationType?: ConceptRelationType;
385
+ reason?: ConceptGateReason;
386
+ message?: string;
387
+ }
388
+ export type ConceptGateReason = 'ok' | 'empty_name' | 'invalid_kind' | 'invalid_relation' | 'mdl_insufficient' | 'pseudo_concept' | 'secret_like' | 'budget_node' | 'budget_edge' | 'cue_mismatch' | 'multi_evidence_required' | 'cooccur_no_escalation' | 'demoted_related' | 'candidate_only' | 'fingerprint_conflict' | 'capacity_admit_stop' | 'no_context_slice';
389
+ export interface AdmitConceptInput {
390
+ name: string;
391
+ kind: ConceptKind;
392
+ description?: string;
393
+ domain?: string[];
394
+ memoryIds?: string[];
395
+ /** 提出该概念的命题条数(MDL);缺省用 memoryIds.length */
396
+ supportCount?: number;
397
+ }
398
+ export interface AdmitEdgeInput {
399
+ sourceId: string;
400
+ targetId: string;
401
+ relationType: ConceptRelationType;
402
+ strength: number;
403
+ description?: string;
404
+ basis: EdgeBasis;
405
+ /** 用于 cue 校验的证据/语境全文;缺省跳过 cue 子串校验(仅类型门控) */
406
+ evidenceText?: string;
407
+ }
408
+ export interface SpreadingActivateOptions {
409
+ /** BFS/扩散深度(默认 2) */
410
+ depth?: number;
411
+ /** 距离衰减(默认 0.55) */
412
+ delta?: number;
413
+ /** 激活地板(默认 0.08) */
414
+ tau?: number;
415
+ /** 节点上限(默认 40) */
416
+ limit?: number;
417
+ /** 仅这些 status(默认 active + strengthened) */
418
+ statuses?: ConceptStatus[];
419
+ }
420
+ export interface ActivatedGraph extends ConceptGraph {
421
+ /** nodeId → 激活值 */
422
+ activation: Record<string, number>;
423
+ seeds: string[];
424
+ }
425
+ export interface ConceptGraphStats {
426
+ nodes: number;
427
+ edges: number;
428
+ byStatus: Record<ConceptStatus, number>;
429
+ byKind: Record<ConceptKind, number>;
430
+ openMergeCandidates: number;
431
+ causalCandidates: number;
432
+ }
433
+ export interface DecayResult {
434
+ decayedEdges: number;
435
+ gcNodes: number;
436
+ gcEdges: number;
437
+ }
438
+ /**
439
+ * ConceptGraphStore — 认知图谱存储
440
+ *
441
+ * 写入只经 admit*(门控在 layers 之上的 cognition-gates / conceptualizer)。
442
+ * 检索主路径是 spreadingActivate;getFullGraph 供巩固与 health。
443
+ */
156
444
  export interface ConceptGraphStore {
157
- addConcept(concept: Omit<ConceptNode, 'id' | 'frequency' | 'memoryIds'>): Promise<string>;
158
- addEdge(edge: ConceptEdge): Promise<void>;
159
- queryRelated(conceptName: string, depth?: number): Promise<ConceptGraph>;
160
- extractFromText(text: string, memoryId: string): Promise<void>;
445
+ admitConcept(input: AdmitConceptInput): Promise<AdmitConceptResult>;
446
+ admitEdge(input: AdmitEdgeInput): Promise<AdmitEdgeResult>;
447
+ /** 记录「假因果」假设,不进慢图 */
448
+ addCausalCandidate(input: {
449
+ sourceId: string;
450
+ targetId: string;
451
+ memoryIds: string[];
452
+ cue: string;
453
+ note?: string;
454
+ }): Promise<void>;
455
+ listMergeCandidates(limit?: number): Promise<MergeCandidate[]>;
456
+ resolveMerge(id: string, action: 'merge' | 'keep_split' | 'drop'): Promise<void>;
457
+ /** Hebbian 加强(使用痕迹 / 新证据) */
458
+ reinforce(input: {
459
+ nodeIds?: string[];
460
+ edgeIds?: string[];
461
+ /** 0–1 证据强度 */
462
+ evidenceStrength?: number;
463
+ }): Promise<void>;
464
+ /** 反证:降权或改型 */
465
+ counterEvidence(input: {
466
+ edgeId: string;
467
+ memoryId?: string;
468
+ /** 是否改标 opposes */
469
+ markOpposes?: boolean;
470
+ }): Promise<void>;
471
+ promote(ids: string[], to: 'active' | 'strengthened'): Promise<void>;
472
+ demote(ids: string[], to: 'shadow'): Promise<void>;
473
+ applyDecay(now?: number): Promise<DecayResult>;
474
+ spreadingActivate(seeds: string[], options?: SpreadingActivateOptions): Promise<ActivatedGraph>;
161
475
  getFullGraph(): Promise<ConceptGraph>;
476
+ stats(): Promise<ConceptGraphStats>;
162
477
  }
163
478
  export interface MemoryWriteSlot {
164
479
  type: MemoryType;
@@ -5,3 +5,52 @@
5
5
  * 实现:InMemory* / Sqlite*(AgentDatabase)。非 Kernel。
6
6
  */
7
7
  export const MEMORY_TYPES = ['fact', 'method', 'norm'];
8
+ export const WISDOM_STATUSES = [
9
+ 'candidate',
10
+ 'trial',
11
+ 'active',
12
+ 'strengthened',
13
+ 'contested',
14
+ 'retired',
15
+ 'superseded',
16
+ ];
17
+ /** 可注入状态(contested 默认不注入) */
18
+ export const WISDOM_INJECTABLE_STATUSES = [
19
+ 'trial',
20
+ 'active',
21
+ 'strengthened',
22
+ ];
23
+ export const WISDOM_ORIGINS = [
24
+ 'factory',
25
+ 'distilled',
26
+ 'agent_write',
27
+ 'admin',
28
+ ];
29
+ export const WISDOM_KINDS = [
30
+ 'generalize',
31
+ 'corrective',
32
+ 'selection',
33
+ 'boundary',
34
+ ];
35
+ export const CONCEPT_KINDS = [
36
+ 'entity',
37
+ 'construct',
38
+ 'method',
39
+ 'problem',
40
+ 'constraint',
41
+ ];
42
+ export const CONCEPT_RELATION_TYPES = [
43
+ 'causes',
44
+ 'part_of',
45
+ 'opposes',
46
+ 'similar_to',
47
+ 'evolves_to',
48
+ 'related',
49
+ ];
50
+ /** 强关系(需持证);`related` / `similar_to` 不在此列 */
51
+ export const STRONG_RELATION_TYPES = [
52
+ 'causes',
53
+ 'part_of',
54
+ 'opposes',
55
+ 'evolves_to',
56
+ ];
@@ -0,0 +1,101 @@
1
+ /**
2
+ * Wisdom formation — 炼制解析、场景匹配、注入排版
3
+ *
4
+ * LLM 判「是不是范式、适用域」;本模块做结构解析 + admit 门控 + 关键词场景匹配。
5
+ * 禁止 session 全文 ETL。规范:arch/wisdom-layer-formation.md §6 / §9。
6
+ *
7
+ * @module harness/memory/wisdom-formation
8
+ */
9
+ import type { AdmitWisdomInput, AdmitWisdomResult, WisdomEntry, WisdomInjectPick, WisdomKind, WisdomStore } from './types.js';
10
+ export interface RawWisdomFormationOutput {
11
+ items?: unknown;
12
+ droppedNotes?: unknown;
13
+ }
14
+ export interface ParsedWisdomItem {
15
+ statement: string;
16
+ rationale?: string;
17
+ problemTypes: string[];
18
+ signals?: string[];
19
+ antiScenarios?: string[];
20
+ questions?: string[];
21
+ biases?: string[];
22
+ posture?: string;
23
+ memoryIds: string[];
24
+ conceptIds?: string[];
25
+ exceptions?: string[];
26
+ kind: WisdomKind;
27
+ }
28
+ export interface ParsedWisdomFormation {
29
+ items: ParsedWisdomItem[];
30
+ droppedNotes: string[];
31
+ }
32
+ /**
33
+ * 从 LLM 文本提取 `{items, droppedNotes}`。
34
+ *
35
+ * @param text - LLM 输出
36
+ * @returns 解析结果或 null
37
+ */
38
+ export declare function parseWisdomFormationJson(text: string): RawWisdomFormationOutput | null;
39
+ /**
40
+ * 归一化 raw → 严格 Parsed(丢弃残缺项,不半写)。
41
+ *
42
+ * @param raw - 解析后的 JSON
43
+ * @returns 有效 items 与丢弃说明
44
+ */
45
+ export declare function normalizeWisdomFormation(raw: RawWisdomFormationOutput): ParsedWisdomFormation;
46
+ /**
47
+ * Parsed → AdmitWisdomInput(distilled 默认)。
48
+ *
49
+ * @param item - 已归一项
50
+ * @param options - origin / supersedesId
51
+ * @returns admit 入参
52
+ */
53
+ export declare function toAdmitWisdomInput(item: ParsedWisdomItem, options?: {
54
+ origin?: AdmitWisdomInput['origin'];
55
+ supersedesId?: string;
56
+ }): AdmitWisdomInput;
57
+ /**
58
+ * 炼制解析并逐条 admit。
59
+ *
60
+ * @param llmText - LLM 原文
61
+ * @param store - WisdomStore
62
+ * @param options - origin / maxItems
63
+ * @returns admit 结果与丢弃笔记
64
+ */
65
+ export declare function formAndAdmit(llmText: string, store: WisdomStore, options?: {
66
+ origin?: AdmitWisdomInput['origin'];
67
+ maxItems?: number;
68
+ allowedMemoryIds?: ReadonlySet<string>;
69
+ dryRun?: boolean;
70
+ }): Promise<{
71
+ results: AdmitWisdomResult[];
72
+ droppedNotes: string[];
73
+ }>;
74
+ /**
75
+ * 关键词/字面场景匹配分。
76
+ *
77
+ * @param entry - 条目
78
+ * @param text - 本轮查询/任务文本
79
+ * @returns [0,1];无命中为 0
80
+ */
81
+ export declare function scenarioMatchScore(entry: WisdomEntry, text: string): number;
82
+ /**
83
+ * 选择注入集:小核心 + 场景匹配。
84
+ *
85
+ * @param entries - 可注入条目(store 已滤状态)
86
+ * @param text - 本轮文本
87
+ * @param options - 条数硬顶
88
+ * @returns 排序后的注入选择
89
+ */
90
+ export declare function pickForInjection(entries: WisdomEntry[], text: string, options?: {
91
+ coreMaxItems?: number;
92
+ scenarioMaxItems?: number;
93
+ includeTrial?: boolean;
94
+ }): WisdomInjectPick[];
95
+ /**
96
+ * 按 problemTypes 分组渲染 system 片段(不含 # 思维框架 头,由 WisdomLayer 加)。
97
+ *
98
+ * @param picks - 注入选择
99
+ * @returns 正文
100
+ */
101
+ export declare function formatWisdomBody(picks: WisdomInjectPick[]): string;