@octopi-agent/engine 0.65.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.
- package/dist/config-schema/engine.d.ts +84 -0
- package/dist/config-schema/engine.js +4 -1
- package/dist/config-schema/substrate.d.ts +86 -0
- package/dist/config-schema/substrate.js +114 -0
- package/dist/config.d.ts +71 -0
- package/dist/harness/agent/builder.d.ts +1 -1
- package/dist/harness/agent/builder.js +27 -2
- package/dist/harness/agent/config-bridge.js +17 -4
- package/dist/harness/context/capabilities/summary/gate.js +2 -2
- package/dist/harness/context/capabilities/summary/policies.js +5 -5
- package/dist/harness/context/capabilities/summary/registry.js +29 -24
- package/dist/harness/context/layer-health.js +3 -2
- package/dist/harness/context/layers.d.ts +27 -13
- package/dist/harness/context/layers.js +76 -66
- package/dist/harness/context/system-prompt-assembler.d.ts +3 -0
- package/dist/harness/context/system-prompt-assembler.js +11 -1
- package/dist/harness/extension/plugin-ecosystem/client-tools/index.d.ts +4 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/index.js +3 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/invoke.d.ts +56 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/invoke.js +281 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/registry.d.ts +98 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/registry.js +250 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/stream.d.ts +124 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/stream.js +372 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/types.d.ts +109 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/types.js +8 -0
- package/dist/harness/extension/plugin-ecosystem/index.d.ts +1 -0
- package/dist/harness/extension/plugin-ecosystem/index.js +1 -0
- package/dist/harness/extension/plugin-ecosystem/tools/builtin.js +1 -1
- package/dist/harness/extension/plugin-ecosystem/tools/memory.d.ts +11 -1
- package/dist/harness/extension/plugin-ecosystem/tools/memory.js +14 -0
- package/dist/harness/index.d.ts +4 -3
- package/dist/harness/index.js +2 -1
- package/dist/harness/knowledge/query-service.js +5 -5
- package/dist/harness/knowledge/retriever.js +1 -1
- package/dist/harness/knowledge/source-store.d.ts +17 -2
- package/dist/harness/knowledge/source-store.js +6 -5
- package/dist/harness/memory/cognition-decay.d.ts +36 -0
- package/dist/harness/memory/cognition-decay.js +55 -0
- package/dist/harness/memory/cognition-gates.d.ts +60 -0
- package/dist/harness/memory/cognition-gates.js +191 -0
- package/dist/harness/memory/cognition-trigger.d.ts +30 -0
- package/dist/harness/memory/cognition-trigger.js +41 -0
- package/dist/harness/memory/cognition-types.d.ts +1 -1
- package/dist/harness/memory/cognition.d.ts +40 -8
- package/dist/harness/memory/cognition.js +432 -79
- package/dist/harness/memory/conceptualizer.d.ts +66 -0
- package/dist/harness/memory/conceptualizer.js +246 -0
- package/dist/harness/memory/index.d.ts +16 -2
- package/dist/harness/memory/index.js +11 -1
- package/dist/harness/memory/sqlite/agent-db.d.ts +9 -0
- package/dist/harness/memory/sqlite/agent-db.js +118 -15
- package/dist/harness/memory/sqlite/cognition-store.d.ts +55 -16
- package/dist/harness/memory/sqlite/cognition-store.js +591 -144
- package/dist/harness/memory/sqlite/wisdom-store.d.ts +33 -14
- package/dist/harness/memory/sqlite/wisdom-store.js +257 -44
- package/dist/harness/memory/types.d.ts +331 -16
- package/dist/harness/memory/types.js +49 -0
- package/dist/harness/memory/wisdom-formation.d.ts +101 -0
- package/dist/harness/memory/wisdom-formation.js +304 -0
- package/dist/harness/memory/wisdom-gates.d.ts +50 -0
- package/dist/harness/memory/wisdom-gates.js +204 -0
- package/dist/harness/memory/wisdom-policy.d.ts +107 -0
- package/dist/harness/memory/wisdom-policy.js +220 -0
- package/dist/harness/memory/wisdom-types.d.ts +3 -2
- package/dist/harness/memory/wisdom-types.js +2 -2
- package/dist/harness/memory/wisdom.d.ts +27 -0
- package/dist/harness/memory/wisdom.js +181 -0
- package/dist/harness/run/agent/agent.d.ts +9 -0
- package/dist/harness/run/agent/agent.js +19 -0
- package/dist/harness/run/reliability/run-agent.js +6 -2
- package/dist/harness/run/runner.js +2 -1
- package/dist/harness/session/index.d.ts +1 -0
- package/dist/harness/session/index.js +1 -0
- package/dist/harness/session/title.d.ts +86 -0
- package/dist/harness/session/title.js +268 -0
- package/dist/harness/shared/events/agent-event-map.d.ts +8 -0
- package/dist/harness/shared/events/agent-event-map.js +1 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +1 -0
- package/dist/subsystems/cognition-steward/conceptualize/SUBSYSTEM.md +43 -0
- package/dist/subsystems/cognition-steward/conceptualize/config.yaml +50 -0
- package/dist/subsystems/cognition-steward/conceptualize/handler.d.ts +9 -0
- package/dist/subsystems/cognition-steward/conceptualize/handler.js +125 -0
- package/dist/subsystems/cognition-steward/consolidate/SUBSYSTEM.md +6 -0
- package/dist/subsystems/cognition-steward/consolidate/config.yaml +54 -0
- package/dist/subsystems/cognition-steward/consolidate/handler.d.ts +12 -0
- package/dist/subsystems/cognition-steward/consolidate/handler.js +93 -0
- package/dist/subsystems/wisdom-steward/evaluate/config.yaml +50 -0
- package/dist/subsystems/wisdom-steward/evaluate/handler.d.ts +18 -0
- package/dist/subsystems/wisdom-steward/evaluate/handler.js +91 -0
- package/dist/subsystems/wisdom-steward/formation/SUBSYSTEM.md +42 -0
- package/dist/subsystems/wisdom-steward/formation/config.yaml +54 -0
- package/dist/subsystems/wisdom-steward/formation/handler.d.ts +18 -0
- package/dist/subsystems/wisdom-steward/formation/handler.js +212 -0
- package/dist/subsystems/wisdom-steward/govern/config.yaml +55 -0
- package/dist/subsystems/wisdom-steward/govern/handler.d.ts +17 -0
- package/dist/subsystems/wisdom-steward/govern/handler.js +68 -0
- 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
|
-
|
|
122
|
-
|
|
179
|
+
/** 核心范式陈述 */
|
|
180
|
+
statement: string;
|
|
181
|
+
rationale?: string;
|
|
182
|
+
scenario: WisdomScenario;
|
|
183
|
+
effect: WisdomEffect;
|
|
184
|
+
status: WisdomStatus;
|
|
185
|
+
confidence: number;
|
|
123
186
|
priority: number;
|
|
124
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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:
|
|
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
|
-
/**
|
|
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
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
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;
|