@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
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* cognition.steward.consolidate — 概念图巩固批
|
|
3
|
+
*
|
|
4
|
+
* 本轮实现:衰减 → 指纹冲突 keep_split → 按支撑晋升 → 容量水位。
|
|
5
|
+
* 未实现步骤(LLM 合并裁决 / causal_candidate 转正 / Wisdom 信号 / anchor:missing GC)
|
|
6
|
+
* 显式记入 skipped,不得假装完成规格 §7.2 全部步骤。
|
|
7
|
+
*
|
|
8
|
+
* 只写 ConceptGraphStore;不写 Memory / Wisdom。
|
|
9
|
+
*/
|
|
10
|
+
const DEP_CONCEPT_GRAPH = 'conceptGraphStore';
|
|
11
|
+
const DEP_CONFIG = '__subsystem_config__';
|
|
12
|
+
/** 本 handler 已声明但未执行的规格步骤 */
|
|
13
|
+
const SKIPPED_STEPS = [
|
|
14
|
+
'merge_llm_adjudication',
|
|
15
|
+
'causal_candidate_promotion',
|
|
16
|
+
'counter_evidence_scan',
|
|
17
|
+
'wisdom_promotion_signal',
|
|
18
|
+
'anchor_missing_gc',
|
|
19
|
+
];
|
|
20
|
+
async function handler(_input, deps) {
|
|
21
|
+
const store = deps?.[DEP_CONCEPT_GRAPH];
|
|
22
|
+
if (!store) {
|
|
23
|
+
throw new Error('cognition.steward.consolidate: conceptGraphStore not injected');
|
|
24
|
+
}
|
|
25
|
+
const config = deps?.[DEP_CONFIG] ?? {};
|
|
26
|
+
const promoteMinSupport = config.promoteMinSupport ?? 3;
|
|
27
|
+
// 1. 衰减 + 无支撑 GC(store 内)
|
|
28
|
+
const decay = await store.applyDecay();
|
|
29
|
+
// 2. merge candidates:指纹冲突保守 keep_split(禁假合并)
|
|
30
|
+
const candidates = await store.listMergeCandidates(100);
|
|
31
|
+
let keptSplit = 0;
|
|
32
|
+
if (config.autoKeepSplitConflicts !== false) {
|
|
33
|
+
for (const c of candidates) {
|
|
34
|
+
if (c.reason.includes('conflict') ||
|
|
35
|
+
c.reason === 'domain_disjoint' ||
|
|
36
|
+
c.reason === 'fingerprint_conflict') {
|
|
37
|
+
await store.resolveMerge(c.id, 'keep_split');
|
|
38
|
+
keptSplit += 1;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
// 3. 晋升:memoryIds 支撑 ≥ promoteMinSupport 的 shadow 节点
|
|
43
|
+
const graph = await store.getFullGraph();
|
|
44
|
+
const toPromote = graph.nodes
|
|
45
|
+
.filter((n) => n.status === 'shadow' && n.memoryIds.length >= promoteMinSupport)
|
|
46
|
+
.map((n) => n.id);
|
|
47
|
+
if (toPromote.length) {
|
|
48
|
+
await store.promote(toPromote, 'active');
|
|
49
|
+
}
|
|
50
|
+
// 4. 容量水位
|
|
51
|
+
const stats = await store.stats();
|
|
52
|
+
const warnNodes = config.warnNodes ?? 5000;
|
|
53
|
+
const warnEdges = config.warnEdges ?? 20_000;
|
|
54
|
+
const stopNodes = config.stopNodes ?? 10_000;
|
|
55
|
+
const stopEdges = config.stopEdges ?? 40_000;
|
|
56
|
+
const capacity = stats.nodes >= stopNodes || stats.edges >= stopEdges
|
|
57
|
+
? 'admit_stop'
|
|
58
|
+
: stats.nodes >= warnNodes || stats.edges >= warnEdges
|
|
59
|
+
? 'warn'
|
|
60
|
+
: 'ok';
|
|
61
|
+
return {
|
|
62
|
+
act: {
|
|
63
|
+
mode: 'inject',
|
|
64
|
+
status: 'success',
|
|
65
|
+
target: 'concept-graph',
|
|
66
|
+
messages: [
|
|
67
|
+
{
|
|
68
|
+
role: 'system',
|
|
69
|
+
content: `cognition.steward.consolidated decayed=${decay.decayedEdges} gcNodes=${decay.gcNodes} ` +
|
|
70
|
+
`promoted=${toPromote.length} keptSplit=${keptSplit} capacity=${capacity} ` +
|
|
71
|
+
`nodes=${stats.nodes} edges=${stats.edges} ` +
|
|
72
|
+
`skipped=[${SKIPPED_STEPS.join(',')}]`,
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
},
|
|
76
|
+
signals: [
|
|
77
|
+
{
|
|
78
|
+
action: 'suggest',
|
|
79
|
+
reason: 'consolidated_partial',
|
|
80
|
+
data: {
|
|
81
|
+
decay,
|
|
82
|
+
promoted: toPromote.length,
|
|
83
|
+
keptSplit,
|
|
84
|
+
capacity,
|
|
85
|
+
stats,
|
|
86
|
+
openMergeCandidates: stats.openMergeCandidates,
|
|
87
|
+
skippedSteps: [...SKIPPED_STEPS],
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
],
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
export default handler;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
id: wisdom.steward.evaluate
|
|
2
|
+
name: Wisdom Steward Evaluate
|
|
3
|
+
description: 弱归因结局入账 + confidence/状态迁移(可 dryRun;不写 Memory/Cognition)
|
|
4
|
+
|
|
5
|
+
sense:
|
|
6
|
+
source: eventBus
|
|
7
|
+
filter:
|
|
8
|
+
condition: "true"
|
|
9
|
+
events: ['wisdom.steward.evaluate.request']
|
|
10
|
+
emits: ['wisdom.steward.evaluated']
|
|
11
|
+
isolation: isolated
|
|
12
|
+
|
|
13
|
+
think:
|
|
14
|
+
implementation: code
|
|
15
|
+
strategy: deterministic
|
|
16
|
+
maxIterations: 1
|
|
17
|
+
|
|
18
|
+
act:
|
|
19
|
+
mode: inject
|
|
20
|
+
|
|
21
|
+
signal:
|
|
22
|
+
severity: info
|
|
23
|
+
channel: [event]
|
|
24
|
+
|
|
25
|
+
boundary:
|
|
26
|
+
visibility: isolated
|
|
27
|
+
authority: act
|
|
28
|
+
security: trusted
|
|
29
|
+
|
|
30
|
+
tools:
|
|
31
|
+
mode: none
|
|
32
|
+
|
|
33
|
+
session:
|
|
34
|
+
mode: ephemeral
|
|
35
|
+
scope: agent
|
|
36
|
+
|
|
37
|
+
lifecycle:
|
|
38
|
+
maxConcurrent: 1
|
|
39
|
+
maxDurationMs: 15000
|
|
40
|
+
|
|
41
|
+
runtimeInject:
|
|
42
|
+
requires: ['wisdomStore']
|
|
43
|
+
|
|
44
|
+
observability:
|
|
45
|
+
eventPrefix: wisdom.steward.evaluate
|
|
46
|
+
|
|
47
|
+
metadata:
|
|
48
|
+
config:
|
|
49
|
+
dryRun: false
|
|
50
|
+
minAppliesForActive: 3
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* wisdom.steward.evaluate — 弱归因结局入账 + 状态迁移
|
|
3
|
+
*
|
|
4
|
+
* payload.events 为可选 WisdomOutcomeEvent[];无事件时对存活条目做批量
|
|
5
|
+
* confidence/状态规划(只基于已入账 outcomes)。不写 Memory / Cognition。
|
|
6
|
+
*/
|
|
7
|
+
import type { SubsystemInput, SubsystemOutput, InjectedDependencies } from '@octopi-agent/engine/harness/collaboration/autonomous-subsystem/types.js';
|
|
8
|
+
declare function handler(input: SubsystemInput, deps?: InjectedDependencies): Promise<SubsystemOutput>;
|
|
9
|
+
declare const _default: {
|
|
10
|
+
handler: typeof handler;
|
|
11
|
+
contract: {
|
|
12
|
+
input: string;
|
|
13
|
+
output: string;
|
|
14
|
+
};
|
|
15
|
+
dependencies: string[];
|
|
16
|
+
};
|
|
17
|
+
export default _default;
|
|
18
|
+
export { handler };
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* wisdom.steward.evaluate — 弱归因结局入账 + 状态迁移
|
|
3
|
+
*
|
|
4
|
+
* payload.events 为可选 WisdomOutcomeEvent[];无事件时对存活条目做批量
|
|
5
|
+
* confidence/状态规划(只基于已入账 outcomes)。不写 Memory / Cognition。
|
|
6
|
+
*/
|
|
7
|
+
import { planConfidenceUpdate, } from '../../../harness/memory/wisdom-policy.js';
|
|
8
|
+
const DEP_WISDOM = 'wisdomStore';
|
|
9
|
+
const DEP_CONFIG = '__subsystem_config__';
|
|
10
|
+
function isOutcomeEvent(v) {
|
|
11
|
+
if (!v || typeof v !== 'object')
|
|
12
|
+
return false;
|
|
13
|
+
const o = v;
|
|
14
|
+
return (typeof o.wisdomId === 'string' &&
|
|
15
|
+
typeof o.signal === 'string' &&
|
|
16
|
+
['applied', 'cited', 'assisted', 'contested', 'ignored'].includes(o.signal));
|
|
17
|
+
}
|
|
18
|
+
async function handler(input, deps) {
|
|
19
|
+
const store = deps?.[DEP_WISDOM];
|
|
20
|
+
if (!store)
|
|
21
|
+
throw new Error('wisdom.steward.evaluate: wisdomStore not injected');
|
|
22
|
+
const config = deps?.[DEP_CONFIG] ?? {};
|
|
23
|
+
const dryRun = config.dryRun ?? false;
|
|
24
|
+
const payload = (input.payload ?? {});
|
|
25
|
+
const rawEvents = Array.isArray(payload.events) ? payload.events : [];
|
|
26
|
+
const events = rawEvents.filter(isOutcomeEvent);
|
|
27
|
+
if (events.length > 0 && !dryRun) {
|
|
28
|
+
await store.recordOutcomes(events);
|
|
29
|
+
}
|
|
30
|
+
const entries = await store.listForGovern({ includeRetired: false });
|
|
31
|
+
let updated = 0;
|
|
32
|
+
let statusChanges = 0;
|
|
33
|
+
const planned = [];
|
|
34
|
+
for (const e of entries) {
|
|
35
|
+
// 终态不再评估(superseded 链已封;retired 由 govern 处理)
|
|
36
|
+
if (e.status === 'superseded' || e.status === 'retired')
|
|
37
|
+
continue;
|
|
38
|
+
// recordOutcomes 已增量更新过的条目:水位对齐后 plan 为 null 或仅状态迁移
|
|
39
|
+
const plan = planConfidenceUpdate(e, config);
|
|
40
|
+
if (!plan)
|
|
41
|
+
continue;
|
|
42
|
+
planned.push({
|
|
43
|
+
id: plan.id,
|
|
44
|
+
status: plan.status,
|
|
45
|
+
confidence: plan.confidence,
|
|
46
|
+
reason: plan.reason,
|
|
47
|
+
});
|
|
48
|
+
if (!dryRun) {
|
|
49
|
+
await store.update(plan.id, {
|
|
50
|
+
confidence: plan.confidence,
|
|
51
|
+
status: plan.status,
|
|
52
|
+
outcomes: {
|
|
53
|
+
...e.outcomes,
|
|
54
|
+
evalAssisted: plan.evalAssisted,
|
|
55
|
+
evalContested: plan.evalContested,
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
updated++;
|
|
59
|
+
}
|
|
60
|
+
if (plan.status !== e.status)
|
|
61
|
+
statusChanges++;
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
act: {
|
|
65
|
+
mode: 'inject',
|
|
66
|
+
status: 'success',
|
|
67
|
+
target: 'wisdom-store',
|
|
68
|
+
messages: [{
|
|
69
|
+
role: 'system',
|
|
70
|
+
content: `wisdom.steward.evaluated events=${events.length} updated=${updated} statusChanges=${statusChanges} dryRun=${dryRun}`,
|
|
71
|
+
}],
|
|
72
|
+
},
|
|
73
|
+
signals: [{
|
|
74
|
+
action: 'suggest',
|
|
75
|
+
reason: 'evaluation_completed',
|
|
76
|
+
data: {
|
|
77
|
+
events: events.length,
|
|
78
|
+
updated,
|
|
79
|
+
statusChanges,
|
|
80
|
+
dryRun,
|
|
81
|
+
planned: planned.slice(0, 20),
|
|
82
|
+
},
|
|
83
|
+
}],
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
export default {
|
|
87
|
+
handler,
|
|
88
|
+
contract: { input: 'WisdomEvaluateInput', output: 'WisdomEvaluateResult' },
|
|
89
|
+
dependencies: [DEP_WISDOM],
|
|
90
|
+
};
|
|
91
|
+
export { handler };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# wisdom.steward.formation
|
|
2
|
+
|
|
3
|
+
把 **多条稳定 Memory 命题** 压缩成 **一条判断范式(maxim)**。
|
|
4
|
+
|
|
5
|
+
## 任务
|
|
6
|
+
|
|
7
|
+
输入是 method/norm 命题包(及可选概念线索),输出 0–N 条 maxim。
|
|
8
|
+
|
|
9
|
+
## 输出 JSON(只输出 JSON)
|
|
10
|
+
|
|
11
|
+
```json
|
|
12
|
+
{
|
|
13
|
+
"items": [
|
|
14
|
+
{
|
|
15
|
+
"statement": "面对…时,先…",
|
|
16
|
+
"rationale": "为何这样想(一句话,不是步骤)",
|
|
17
|
+
"problemTypes": ["验证型宣称", "失败排查"],
|
|
18
|
+
"signals": ["工具已调用但未核对结果"],
|
|
19
|
+
"antiScenarios": ["用户明确要求假设成功"],
|
|
20
|
+
"questions": ["证据在哪里?"],
|
|
21
|
+
"biases": ["把过程当结果"],
|
|
22
|
+
"posture": "先证伪再扩展",
|
|
23
|
+
"memoryIds": ["m1", "m2"],
|
|
24
|
+
"conceptIds": [],
|
|
25
|
+
"exceptions": [],
|
|
26
|
+
"kind": "corrective"
|
|
27
|
+
}
|
|
28
|
+
],
|
|
29
|
+
"droppedNotes": ["不足以形成范式的主题说明"]
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## 硬规则
|
|
34
|
+
|
|
35
|
+
1. **单位是范式**:改「该怎么想」,不要写步骤(method)或行为开关(norm)。
|
|
36
|
+
2. **多源**:每条至少 2 个 memoryIds(不同命题)。
|
|
37
|
+
3. **有操作效应**:questions / biases / posture 至少一项。
|
|
38
|
+
4. **有适用域**:problemTypes 非空;写清 antiScenarios。
|
|
39
|
+
5. 不输出 secrets、统计句、人格/宪法句。
|
|
40
|
+
6. 无合格范式时输出 `{"items":[],"droppedNotes":["…"]}`,不要硬凑。
|
|
41
|
+
|
|
42
|
+
kind ∈ `generalize | corrective | selection | boundary`。
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
id: wisdom.steward.formation
|
|
2
|
+
name: Wisdom Steward Formation
|
|
3
|
+
description: 从 Memory/Cognition 稳定结构炼制判断范式(maxim;多源门控;不写 Memory/Cognition)
|
|
4
|
+
|
|
5
|
+
sense:
|
|
6
|
+
source: schedule
|
|
7
|
+
interval: 86400000
|
|
8
|
+
filter:
|
|
9
|
+
condition: "true"
|
|
10
|
+
events: ['wisdom.steward.formation.request']
|
|
11
|
+
emits: ['wisdom.steward.formed', 'wisdom.steward.formation.failed']
|
|
12
|
+
isolation: isolated
|
|
13
|
+
|
|
14
|
+
think:
|
|
15
|
+
implementation: llm
|
|
16
|
+
strategy: single
|
|
17
|
+
model: summary
|
|
18
|
+
maxIterations: 1
|
|
19
|
+
|
|
20
|
+
act:
|
|
21
|
+
mode: inject
|
|
22
|
+
|
|
23
|
+
signal:
|
|
24
|
+
severity: info
|
|
25
|
+
channel: [event]
|
|
26
|
+
|
|
27
|
+
boundary:
|
|
28
|
+
visibility: isolated
|
|
29
|
+
authority: act
|
|
30
|
+
security: trusted
|
|
31
|
+
|
|
32
|
+
tools:
|
|
33
|
+
mode: none
|
|
34
|
+
|
|
35
|
+
session:
|
|
36
|
+
mode: ephemeral
|
|
37
|
+
scope: agent
|
|
38
|
+
|
|
39
|
+
lifecycle:
|
|
40
|
+
maxConcurrent: 1
|
|
41
|
+
maxDurationMs: 60000
|
|
42
|
+
|
|
43
|
+
runtimeInject:
|
|
44
|
+
requires: ['wisdomStore', 'memoryStore']
|
|
45
|
+
|
|
46
|
+
observability:
|
|
47
|
+
eventPrefix: wisdom.steward.formation
|
|
48
|
+
|
|
49
|
+
metadata:
|
|
50
|
+
config:
|
|
51
|
+
maxItemsPerRun: 2
|
|
52
|
+
minMemorySupport: 2
|
|
53
|
+
minClusterSize: 5
|
|
54
|
+
maxEvidenceChars: 6000
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* wisdom.steward.formation — Memory/Cognition 稳定结构 → 判断范式
|
|
3
|
+
*
|
|
4
|
+
* 失败语义:缺 store/llmPort、LLM 错误、解析失败 → act.status=failed。
|
|
5
|
+
* 只写 WisdomStore(E3);不写 Memory / Cognition / Knowledge。
|
|
6
|
+
*/
|
|
7
|
+
import type { SubsystemInput, SubsystemOutput, InjectedDependencies } from '@octopi-agent/engine/harness/collaboration/autonomous-subsystem/types.js';
|
|
8
|
+
declare function handler(_input: SubsystemInput, deps?: InjectedDependencies): Promise<SubsystemOutput>;
|
|
9
|
+
declare const _default: {
|
|
10
|
+
handler: typeof handler;
|
|
11
|
+
contract: {
|
|
12
|
+
input: string;
|
|
13
|
+
output: string;
|
|
14
|
+
};
|
|
15
|
+
dependencies: string[];
|
|
16
|
+
};
|
|
17
|
+
export default _default;
|
|
18
|
+
export { handler };
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* wisdom.steward.formation — Memory/Cognition 稳定结构 → 判断范式
|
|
3
|
+
*
|
|
4
|
+
* 失败语义:缺 store/llmPort、LLM 错误、解析失败 → act.status=failed。
|
|
5
|
+
* 只写 WisdomStore(E3);不写 Memory / Cognition / Knowledge。
|
|
6
|
+
*/
|
|
7
|
+
import { readFileSync } from 'node:fs';
|
|
8
|
+
import { dirname, join } from 'node:path';
|
|
9
|
+
import { fileURLToPath } from 'node:url';
|
|
10
|
+
import { DEP_LLM_PORT, DEP_SUBSYSTEM_PROMPT, } from '@octopi-agent/engine/harness/collaboration/autonomous-subsystem/index.js';
|
|
11
|
+
import { formAndAdmit, planPromotionCandidates } from '../../../harness/memory/index.js';
|
|
12
|
+
const DEP_WISDOM = 'wisdomStore';
|
|
13
|
+
const DEP_MEMORY = 'memoryStore';
|
|
14
|
+
const DEP_CONCEPT = 'conceptGraphStore';
|
|
15
|
+
const DEP_CONFIG = '__subsystem_config__';
|
|
16
|
+
function resolveSubsystemPrompt(deps, llmPort) {
|
|
17
|
+
const fromDeps = deps?.[DEP_SUBSYSTEM_PROMPT];
|
|
18
|
+
if (typeof fromDeps === 'string' && fromDeps.trim())
|
|
19
|
+
return fromDeps;
|
|
20
|
+
if (llmPort?.cognitivePrompt?.trim())
|
|
21
|
+
return llmPort.cognitivePrompt;
|
|
22
|
+
try {
|
|
23
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
24
|
+
return readFileSync(join(here, 'SUBSYSTEM.md'), 'utf8');
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return '';
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function failOutput(message, reason) {
|
|
31
|
+
return {
|
|
32
|
+
act: {
|
|
33
|
+
mode: 'inject',
|
|
34
|
+
status: 'failed',
|
|
35
|
+
error: message,
|
|
36
|
+
target: 'wisdom-store',
|
|
37
|
+
messages: [{ role: 'system', content: `wisdom.steward.formation.failed reason=${reason}` }],
|
|
38
|
+
},
|
|
39
|
+
signals: [{ action: 'alert', reason: message, data: { reason } }],
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* 聚合炼制原料:promotion 候选 + 同型 method/norm 簇。
|
|
44
|
+
*
|
|
45
|
+
* @param memoryStore - MemoryStore
|
|
46
|
+
* @param minCluster - 触发阈值
|
|
47
|
+
* @param maxChars - 证据包字符上限
|
|
48
|
+
* @returns 证据包文本与 memoryIds
|
|
49
|
+
*/
|
|
50
|
+
async function buildEvidencePack(memoryStore, minCluster, maxChars) {
|
|
51
|
+
const all = await memoryStore.listForGovern({ includeDeleted: false });
|
|
52
|
+
const alive = all.filter((e) => !e.deleted && (e.status ?? 'active') !== 'shadow');
|
|
53
|
+
const promotions = planPromotionCandidates(alive, 20);
|
|
54
|
+
// 按 type+首 tag 聚簇(代码侧选择;语义归 LLM)
|
|
55
|
+
const clusters = new Map();
|
|
56
|
+
for (const e of alive) {
|
|
57
|
+
if (e.type !== 'method' && e.type !== 'norm')
|
|
58
|
+
continue;
|
|
59
|
+
const key = `${e.type}:${e.tags[0] ?? 'general'}`;
|
|
60
|
+
const list = clusters.get(key) ?? [];
|
|
61
|
+
list.push(e);
|
|
62
|
+
clusters.set(key, list);
|
|
63
|
+
}
|
|
64
|
+
const bigClusters = [...clusters.entries()]
|
|
65
|
+
.filter(([, list]) => list.length >= minCluster)
|
|
66
|
+
.sort((a, b) => b[1].length - a[1].length)
|
|
67
|
+
.slice(0, 4);
|
|
68
|
+
const parts = [];
|
|
69
|
+
const ids = new Set();
|
|
70
|
+
if (promotions.length) {
|
|
71
|
+
parts.push('## 晋升候选(method/norm)');
|
|
72
|
+
for (const p of promotions.slice(0, 10)) {
|
|
73
|
+
parts.push(`- [${p.type}] (${p.id}) ${p.content}`);
|
|
74
|
+
ids.add(p.id);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
for (const [key, list] of bigClusters) {
|
|
78
|
+
parts.push(`## 簇 ${key}(n=${list.length})`);
|
|
79
|
+
for (const e of list.slice(0, 8)) {
|
|
80
|
+
parts.push(`- [${e.type}] (${e.id}) ${e.content}`);
|
|
81
|
+
if (e.evidence)
|
|
82
|
+
parts.push(` 证据: ${e.evidence.slice(0, 180)}`);
|
|
83
|
+
ids.add(e.id);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
let text = parts.join('\n');
|
|
87
|
+
if (text.length > maxChars)
|
|
88
|
+
text = text.slice(0, maxChars);
|
|
89
|
+
return {
|
|
90
|
+
text,
|
|
91
|
+
memoryIds: [...ids],
|
|
92
|
+
clusterHits: bigClusters.length,
|
|
93
|
+
promotionCount: promotions.length,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
async function handler(_input, deps) {
|
|
97
|
+
const wisdomStore = deps?.[DEP_WISDOM];
|
|
98
|
+
const memoryStore = deps?.[DEP_MEMORY];
|
|
99
|
+
if (!wisdomStore)
|
|
100
|
+
throw new Error('wisdom.steward.formation: wisdomStore not injected');
|
|
101
|
+
if (!memoryStore)
|
|
102
|
+
throw new Error('wisdom.steward.formation: memoryStore not injected');
|
|
103
|
+
const config = deps?.[DEP_CONFIG] ?? {};
|
|
104
|
+
const minCluster = config.minClusterSize ?? 5;
|
|
105
|
+
const maxChars = config.maxEvidenceChars ?? 6000;
|
|
106
|
+
const maxItems = config.maxItemsPerRun ?? 2;
|
|
107
|
+
const dryRun = config.dryRun ?? false;
|
|
108
|
+
const minPromotionStack = config.minPromotionStack ?? 3;
|
|
109
|
+
const pack = await buildEvidencePack(memoryStore, minCluster, maxChars);
|
|
110
|
+
// 触发器(防「见者有份」):真实簇 或 晋升候选堆叠;仅有零散材料不打 LLM
|
|
111
|
+
const hasCluster = pack.clusterHits > 0;
|
|
112
|
+
const hasStackedPromotions = pack.promotionCount >= minPromotionStack;
|
|
113
|
+
if (!pack.text.trim() || pack.memoryIds.length < (config.minMemorySupport ?? 2) || (!hasCluster && !hasStackedPromotions)) {
|
|
114
|
+
return {
|
|
115
|
+
act: {
|
|
116
|
+
mode: 'inject',
|
|
117
|
+
status: 'success',
|
|
118
|
+
target: 'wisdom-store',
|
|
119
|
+
messages: [{
|
|
120
|
+
role: 'system',
|
|
121
|
+
content: `wisdom.steward.formation.skipped reason=no_trigger memoryIds=${pack.memoryIds.length} ` +
|
|
122
|
+
`clusters=${pack.clusterHits} promotions=${pack.promotionCount}`,
|
|
123
|
+
}],
|
|
124
|
+
},
|
|
125
|
+
signals: [{
|
|
126
|
+
action: 'suggest',
|
|
127
|
+
reason: 'no_trigger',
|
|
128
|
+
data: {
|
|
129
|
+
memoryIds: pack.memoryIds.length,
|
|
130
|
+
clusterHits: pack.clusterHits,
|
|
131
|
+
promotionCount: pack.promotionCount,
|
|
132
|
+
},
|
|
133
|
+
}],
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
const llmPort = deps?.[DEP_LLM_PORT];
|
|
137
|
+
if (!llmPort?.chat) {
|
|
138
|
+
return failOutput('llmPort missing', 'llm_port_missing');
|
|
139
|
+
}
|
|
140
|
+
const systemPrompt = resolveSubsystemPrompt(deps, llmPort);
|
|
141
|
+
// 概念线索(可选;缺失不失败)
|
|
142
|
+
let conceptHint = '';
|
|
143
|
+
const conceptStore = deps?.[DEP_CONCEPT];
|
|
144
|
+
if (conceptStore) {
|
|
145
|
+
try {
|
|
146
|
+
const graph = await conceptStore.getFullGraph();
|
|
147
|
+
const names = graph.nodes
|
|
148
|
+
.filter((n) => n.status !== 'shadow')
|
|
149
|
+
.slice(0, 20)
|
|
150
|
+
.map((n) => n.name);
|
|
151
|
+
if (names.length)
|
|
152
|
+
conceptHint = `\n概念线索: ${names.join('、')}`;
|
|
153
|
+
}
|
|
154
|
+
catch {
|
|
155
|
+
// 图不可用不阻断炼制
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
let llmText = '';
|
|
159
|
+
try {
|
|
160
|
+
const res = await llmPort.chat({
|
|
161
|
+
systemPrompt: systemPrompt || undefined,
|
|
162
|
+
messages: [{ role: 'user', content: `${pack.text}${conceptHint}` }],
|
|
163
|
+
temperature: 0.3,
|
|
164
|
+
maxTokens: 2048,
|
|
165
|
+
});
|
|
166
|
+
if (res.finishReason === 'error') {
|
|
167
|
+
return failOutput(res.content || 'llm chat error', 'llm_error');
|
|
168
|
+
}
|
|
169
|
+
llmText = res.content ?? '';
|
|
170
|
+
}
|
|
171
|
+
catch (err) {
|
|
172
|
+
return failOutput(err instanceof Error ? err.message : String(err), 'llm_error');
|
|
173
|
+
}
|
|
174
|
+
const allowedMemoryIds = new Set(pack.memoryIds);
|
|
175
|
+
const { results, droppedNotes } = await formAndAdmit(llmText, wisdomStore, {
|
|
176
|
+
origin: 'distilled',
|
|
177
|
+
maxItems,
|
|
178
|
+
allowedMemoryIds,
|
|
179
|
+
dryRun,
|
|
180
|
+
});
|
|
181
|
+
const created = results.filter((r) => r.action === 'created' || r.action === 'superseded');
|
|
182
|
+
const rejected = results.filter((r) => r.action === 'rejected');
|
|
183
|
+
return {
|
|
184
|
+
act: {
|
|
185
|
+
mode: 'inject',
|
|
186
|
+
status: 'success',
|
|
187
|
+
target: 'wisdom-store',
|
|
188
|
+
messages: [{
|
|
189
|
+
role: 'system',
|
|
190
|
+
content: `wisdom.steward.formed created=${created.length} rejected=${rejected.length} ` +
|
|
191
|
+
`dropped=${droppedNotes.length} dryRun=${dryRun}`,
|
|
192
|
+
}],
|
|
193
|
+
},
|
|
194
|
+
signals: [{
|
|
195
|
+
action: 'suggest',
|
|
196
|
+
reason: 'formation_completed',
|
|
197
|
+
data: {
|
|
198
|
+
created: created.map((r) => r.id),
|
|
199
|
+
rejected: rejected.map((r) => ({ reason: r.reason, message: r.message })),
|
|
200
|
+
droppedNotes,
|
|
201
|
+
sourceMemoryIds: pack.memoryIds.slice(0, 30),
|
|
202
|
+
dryRun,
|
|
203
|
+
},
|
|
204
|
+
}],
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
export default {
|
|
208
|
+
handler,
|
|
209
|
+
contract: { input: 'WisdomFormationInput', output: 'WisdomFormationResult' },
|
|
210
|
+
dependencies: [DEP_WISDOM, DEP_MEMORY],
|
|
211
|
+
};
|
|
212
|
+
export { handler };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
id: wisdom.steward.govern
|
|
2
|
+
name: Wisdom Steward Govern
|
|
3
|
+
description: 范式库治理:零应用衰减、容量演化、软退休(不污染主会话)
|
|
4
|
+
|
|
5
|
+
sense:
|
|
6
|
+
source: schedule
|
|
7
|
+
interval: 3600000
|
|
8
|
+
filter:
|
|
9
|
+
condition: "true"
|
|
10
|
+
events: ['wisdom.steward.govern.request']
|
|
11
|
+
emits: ['wisdom.steward.governed']
|
|
12
|
+
isolation: isolated
|
|
13
|
+
|
|
14
|
+
think:
|
|
15
|
+
implementation: code
|
|
16
|
+
strategy: deterministic
|
|
17
|
+
maxIterations: 1
|
|
18
|
+
|
|
19
|
+
act:
|
|
20
|
+
mode: inject
|
|
21
|
+
|
|
22
|
+
signal:
|
|
23
|
+
severity: info
|
|
24
|
+
channel: [event]
|
|
25
|
+
|
|
26
|
+
boundary:
|
|
27
|
+
visibility: isolated
|
|
28
|
+
authority: act
|
|
29
|
+
security: trusted
|
|
30
|
+
|
|
31
|
+
tools:
|
|
32
|
+
mode: none
|
|
33
|
+
|
|
34
|
+
session:
|
|
35
|
+
mode: ephemeral
|
|
36
|
+
scope: agent
|
|
37
|
+
|
|
38
|
+
lifecycle:
|
|
39
|
+
maxConcurrent: 1
|
|
40
|
+
maxDurationMs: 15000
|
|
41
|
+
|
|
42
|
+
runtimeInject:
|
|
43
|
+
requires: ['wisdomStore']
|
|
44
|
+
|
|
45
|
+
observability:
|
|
46
|
+
eventPrefix: wisdom.steward.govern
|
|
47
|
+
|
|
48
|
+
metadata:
|
|
49
|
+
config:
|
|
50
|
+
dryRun: false
|
|
51
|
+
softCap: 50
|
|
52
|
+
hardCap: 80
|
|
53
|
+
zeroApplyIdleMs: 2592000000
|
|
54
|
+
priorityDecayStep: 5
|
|
55
|
+
priorityFloor: 5
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* wisdom.steward.govern — 零应用衰减 + 容量演化 + 软退休
|
|
3
|
+
*
|
|
4
|
+
* 只写 WisdomStore;可 dryRun。不写 Memory / Cognition。
|
|
5
|
+
*/
|
|
6
|
+
import type { SubsystemInput, SubsystemOutput, InjectedDependencies } from '@octopi-agent/engine/harness/collaboration/autonomous-subsystem/types.js';
|
|
7
|
+
declare function handler(_input: SubsystemInput, deps?: InjectedDependencies): Promise<SubsystemOutput>;
|
|
8
|
+
declare const _default: {
|
|
9
|
+
handler: typeof handler;
|
|
10
|
+
contract: {
|
|
11
|
+
input: string;
|
|
12
|
+
output: string;
|
|
13
|
+
};
|
|
14
|
+
dependencies: string[];
|
|
15
|
+
};
|
|
16
|
+
export default _default;
|
|
17
|
+
export { handler };
|