@octopi-agent/engine 0.97.15 → 0.98.4
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/agent.d.ts +2 -0
- package/dist/config-schema/engine.d.ts +4 -0
- package/dist/config-schema/governance.d.ts +2 -0
- package/dist/config-schema/governance.js +30 -0
- package/dist/harness/agent/builder.d.ts +11 -0
- package/dist/harness/agent/builder.js +59 -32
- package/dist/harness/agent/config-integrity.d.ts +66 -0
- package/dist/harness/agent/config-integrity.js +89 -0
- package/dist/harness/agent/wire-agent-builder.js +5 -0
- package/dist/harness/collaboration/autonomous-subsystem/index.d.ts +2 -2
- package/dist/harness/collaboration/autonomous-subsystem/index.js +1 -1
- package/dist/harness/collaboration/autonomous-subsystem/loader.js +3 -0
- package/dist/harness/collaboration/autonomous-subsystem/sense/engine.js +19 -2
- package/dist/harness/collaboration/autonomous-subsystem/think/completion-guard.d.ts +40 -0
- package/dist/harness/collaboration/autonomous-subsystem/think/completion-guard.js +59 -0
- package/dist/harness/collaboration/autonomous-subsystem/think/index.d.ts +2 -0
- package/dist/harness/collaboration/autonomous-subsystem/think/index.js +1 -0
- package/dist/harness/collaboration/autonomous-subsystem/think/model-resolver.js +1 -1
- package/dist/harness/collaboration/autonomous-subsystem/types.d.ts +9 -0
- package/dist/harness/context/capabilities/summary/resolver.d.ts +1 -1
- package/dist/harness/context/capabilities/summary/resolver.js +4 -4
- package/dist/harness/context/capabilities/summary/types.d.ts +2 -2
- package/dist/harness/context/layers.d.ts +2 -4
- package/dist/harness/context/layers.js +9 -11
- package/dist/harness/context/summarize.d.ts +1 -1
- package/dist/harness/context/summarize.js +2 -2
- package/dist/harness/context/system-prompt-assembler.d.ts +2 -0
- package/dist/harness/context/system-prompt-assembler.js +1 -0
- package/dist/harness/extension/execution-environment/effect-policy.d.ts +24 -2
- package/dist/harness/extension/execution-environment/effect-policy.js +30 -0
- package/dist/harness/extension/execution-environment/ops-audit.d.ts +6 -2
- package/dist/harness/extension/execution-environment/ops-audit.js +11 -12
- package/dist/harness/extension/execution-environment/undo-log.d.ts +6 -2
- package/dist/harness/extension/execution-environment/undo-log.js +31 -10
- package/dist/harness/extension/plugin-ecosystem/tools/builtin.js +17 -24
- package/dist/harness/extension/plugin-ecosystem/tools/document-tools.js +3 -9
- package/dist/harness/extension/plugin-ecosystem/tools/file-edit.js +3 -6
- package/dist/harness/extension/plugin-ecosystem/tools/file-ops.js +9 -5
- package/dist/harness/extension/plugin-ecosystem/tools/file-search.js +9 -130
- package/dist/harness/extension/plugin-ecosystem/tools/git-tools.js +122 -14
- package/dist/harness/extension/plugin-ecosystem/tools/package-tools.js +4 -13
- package/dist/harness/extension/plugin-ecosystem/tools/platform.d.ts +25 -11
- package/dist/harness/extension/plugin-ecosystem/tools/platform.js +168 -62
- package/dist/harness/governance/security/default-risk-policy.d.ts +1 -0
- package/dist/harness/governance/security/default-risk-policy.js +1 -0
- package/dist/harness/governance/security/default-security-guard.js +9 -0
- package/dist/harness/governance/security/index.d.ts +1 -0
- package/dist/harness/governance/security/index.js +2 -0
- package/dist/harness/governance/security/risk-evaluator.js +13 -0
- package/dist/harness/governance/security/risk-types.d.ts +12 -0
- package/dist/harness/governance/security/shell-parser-fallback.d.ts +29 -0
- package/dist/harness/governance/security/shell-parser-fallback.js +410 -0
- package/dist/harness/governance/security/shell-parser-shared.d.ts +83 -0
- package/dist/harness/governance/security/shell-parser-shared.js +188 -0
- package/dist/harness/governance/security/shell-parser-treesitter.d.ts +52 -0
- package/dist/harness/governance/security/shell-parser-treesitter.js +370 -0
- package/dist/harness/governance/security/shell-parser.d.ts +23 -10
- package/dist/harness/governance/security/shell-parser.js +37 -496
- package/dist/harness/governance/security/vendor/README.md +24 -0
- package/dist/harness/governance/security/vendor/tree-sitter-bash.LICENSE.txt +21 -0
- package/dist/harness/governance/security/vendor/tree-sitter-bash.wasm +0 -0
- package/dist/harness/memory/index.d.ts +6 -2
- package/dist/harness/memory/index.js +4 -1
- package/dist/harness/memory/memory-events.d.ts +25 -0
- package/dist/harness/memory/memory-events.js +38 -0
- package/dist/harness/memory/sqlite/agent-db.js +15 -0
- package/dist/harness/memory/sqlite/wisdom-store.d.ts +7 -2
- package/dist/harness/memory/sqlite/wisdom-store.js +51 -2
- package/dist/harness/memory/steward-policy.d.ts +3 -0
- package/dist/harness/memory/steward-policy.js +1 -1
- package/dist/harness/memory/types.d.ts +41 -3
- package/dist/harness/memory/wisdom-attribution.d.ts +136 -0
- package/dist/harness/memory/wisdom-attribution.js +287 -0
- package/dist/harness/memory/wisdom-events.d.ts +37 -0
- package/dist/harness/memory/wisdom-events.js +61 -0
- package/dist/harness/memory/wisdom-formation.d.ts +20 -1
- package/dist/harness/memory/wisdom-formation.js +55 -21
- package/dist/harness/memory/wisdom.d.ts +7 -2
- package/dist/harness/memory/wisdom.js +40 -2
- package/dist/harness/run/run-scope.d.ts +4 -0
- package/dist/harness/run/runner.d.ts +27 -2
- package/dist/harness/run/runner.js +48 -4
- package/dist/harness/shared/paths/glob.d.ts +52 -0
- package/dist/harness/shared/paths/glob.js +218 -0
- package/dist/harness/shared/paths/index.d.ts +84 -0
- package/dist/harness/shared/paths/index.js +179 -0
- package/dist/subsystems/cognition-steward/conceptualize/config.yaml +4 -2
- package/dist/subsystems/cognition-steward/conceptualize/handler.js +12 -20
- package/dist/subsystems/memory-steward/backfill/config.yaml +4 -2
- package/dist/subsystems/memory-steward/backfill/handler.js +44 -52
- package/dist/subsystems/wisdom-steward/attribute/SUBSYSTEM.md +24 -0
- package/dist/subsystems/wisdom-steward/attribute/config.yaml +60 -0
- package/dist/subsystems/wisdom-steward/attribute/handler.d.ts +23 -0
- package/dist/subsystems/wisdom-steward/attribute/handler.js +167 -0
- package/dist/subsystems/wisdom-steward/evaluate/handler.js +3 -1
- package/dist/subsystems/wisdom-steward/formation/config.yaml +12 -5
- package/dist/subsystems/wisdom-steward/formation/handler.js +12 -18
- package/dist/subsystems/wisdom-steward/govern/config.yaml +1 -1
- package/dist/subsystems/wisdom-steward/govern/handler.js +4 -0
- package/package.json +7 -2
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
import { readFileSync } from 'node:fs';
|
|
8
8
|
import { dirname, join } from 'node:path';
|
|
9
9
|
import { fileURLToPath } from 'node:url';
|
|
10
|
-
import { DEP_LLM_PORT, DEP_SUBSYSTEM_PROMPT, } from '@octopi-agent/engine/harness/collaboration/autonomous-subsystem/index.js';
|
|
10
|
+
import { DEP_LLM_PORT, DEP_SUBSYSTEM_PROMPT, chatForCompleteOutput, } from '@octopi-agent/engine/harness/collaboration/autonomous-subsystem/index.js';
|
|
11
11
|
import { admitCandidates } from '../../../harness/memory/steward-policy.js';
|
|
12
12
|
import { measureSessionDensity, } from '@octopi-agent/engine/harness/memory/backfill-coverage.js';
|
|
13
13
|
const DEP_MEMORY_STORE = 'memoryStore';
|
|
@@ -248,67 +248,59 @@ async function handler(input, deps) {
|
|
|
248
248
|
? `\n## Operating constitution (extract under these rules)\n${constitution.slice(0, 4000)}\n`
|
|
249
249
|
: '';
|
|
250
250
|
const systemPrompt = `${subsystemPrompt}${constitutionBlock}`.trim() || undefined;
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
if (res.finishReason === 'error') {
|
|
263
|
-
await markCoverage(deps, {
|
|
264
|
-
sessionId,
|
|
265
|
-
agentId,
|
|
266
|
-
fingerprint: coverageFingerprint,
|
|
267
|
-
status: 'failed',
|
|
268
|
-
reason: 'llm_error',
|
|
269
|
-
trigger: triggerKind,
|
|
270
|
-
});
|
|
271
|
-
return failOutput('llm_error', res.content || 'backfill failed: LLM chat error', sessionId, { agentId });
|
|
272
|
-
}
|
|
273
|
-
rawContent = res.content ?? '';
|
|
274
|
-
}
|
|
275
|
-
catch (err) {
|
|
276
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
277
|
-
await markCoverage(deps, {
|
|
278
|
-
sessionId,
|
|
279
|
-
agentId,
|
|
280
|
-
fingerprint: coverageFingerprint,
|
|
281
|
-
status: 'failed',
|
|
282
|
-
reason: 'llm_error',
|
|
283
|
-
trigger: triggerKind,
|
|
284
|
-
});
|
|
285
|
-
return failOutput('llm_error', `backfill failed: ${msg}`, sessionId, { agentId });
|
|
286
|
-
}
|
|
287
|
-
if (!rawContent.trim()) {
|
|
288
|
-
await markCoverage(deps, {
|
|
289
|
-
sessionId,
|
|
290
|
-
agentId,
|
|
291
|
-
fingerprint: coverageFingerprint,
|
|
292
|
-
status: 'failed',
|
|
293
|
-
reason: 'llm_empty',
|
|
294
|
-
trigger: triggerKind,
|
|
295
|
-
});
|
|
296
|
-
return failOutput('llm_empty', 'backfill failed: empty LLM content', sessionId, { agentId });
|
|
297
|
-
}
|
|
298
|
-
const parsed = extractJsonArray(rawContent);
|
|
299
|
-
if (!parsed) {
|
|
251
|
+
// maxTokens 只是生成配额(LLM 传参):截断(finish=length)或解析失败都放大配额重试
|
|
252
|
+
// 一次,仍失败显式上报——业务完整性优先,禁止静默半截结果
|
|
253
|
+
const outcome = await chatForCompleteOutput(llmPort, {
|
|
254
|
+
systemPrompt,
|
|
255
|
+
messages: [{
|
|
256
|
+
role: 'user',
|
|
257
|
+
content: `## Session evidence (session=${sessionId})\n${sessionText}\n\nExtract long-term memory propositions. Output strict JSON array only.`,
|
|
258
|
+
}],
|
|
259
|
+
maxTokens: config.maxTokens ?? 8192,
|
|
260
|
+
}, (text) => extractJsonArray(text));
|
|
261
|
+
if (!outcome.ok) {
|
|
300
262
|
await markCoverage(deps, {
|
|
301
263
|
sessionId,
|
|
302
264
|
agentId,
|
|
303
265
|
fingerprint: coverageFingerprint,
|
|
304
266
|
status: 'failed',
|
|
305
|
-
reason:
|
|
267
|
+
reason: outcome.reason,
|
|
306
268
|
trigger: triggerKind,
|
|
307
269
|
});
|
|
308
|
-
return failOutput(
|
|
270
|
+
return failOutput(outcome.reason, `backfill failed: ${outcome.message}`, sessionId, { agentId });
|
|
309
271
|
}
|
|
272
|
+
const parsed = outcome.parsed;
|
|
310
273
|
const candidates = parseCandidates(parsed, maxCandidates);
|
|
311
274
|
const result = await admitCandidates(memoryStore, candidates, `session:${sessionId};via:backfill`);
|
|
275
|
+
// 每条新记忆发 memory.stored(wisdom.steward.formation 增量触发)+
|
|
276
|
+
// cognition.conceptualize.request(概念化触发);信号失败不得拖垮 backfill 主流程
|
|
277
|
+
try {
|
|
278
|
+
const { emitMemoryStored } = await import('../../../harness/memory/memory-events.js');
|
|
279
|
+
const { emitConceptualizeRequest } = await import('../../../harness/memory/cognition-trigger.js');
|
|
280
|
+
const eventBus = deps?.eventBus;
|
|
281
|
+
for (const item of result.accepted) {
|
|
282
|
+
emitMemoryStored(eventBus, {
|
|
283
|
+
memoryId: item.id,
|
|
284
|
+
type: item.type,
|
|
285
|
+
status: item.status,
|
|
286
|
+
sessionId,
|
|
287
|
+
agentId,
|
|
288
|
+
});
|
|
289
|
+
emitConceptualizeRequest(eventBus, {
|
|
290
|
+
memoryId: item.id,
|
|
291
|
+
proposition: item.proposition,
|
|
292
|
+
evidence: item.evidence ?? '',
|
|
293
|
+
memoryType: item.type,
|
|
294
|
+
memoryStatus: item.status,
|
|
295
|
+
channel: item.channel,
|
|
296
|
+
sessionId,
|
|
297
|
+
agentId,
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
catch {
|
|
302
|
+
// 模块加载/总线异常:跳过信号,admit 结果照常上报
|
|
303
|
+
}
|
|
312
304
|
await markCoverage(deps, {
|
|
313
305
|
sessionId,
|
|
314
306
|
agentId,
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# wisdom.steward.attribute
|
|
2
|
+
|
|
3
|
+
你是**判断范式(maxim)的弱归因判官**。输入是若干「范式 × 任务窗口」候选(digest),你判断每个候选里范式在该窗口**是否真的起了作用**。
|
|
4
|
+
|
|
5
|
+
## 证据标准
|
|
6
|
+
|
|
7
|
+
- **assisted**:引用摘录显示范式真实影响了决策/行为——推理中引用其 id 或整句、按其姿态行动且改变了走向。任务结局只是辅助上下文。
|
|
8
|
+
- **contested**:有明确反例——摘录显示范式把方向带错,或其后出现与范式相反的事实/用户纠正。
|
|
9
|
+
- **unclear**:证据不足(仅在墙上、例行公事式引用、摘录看不出影响)。**宁可不判也不污染**。
|
|
10
|
+
|
|
11
|
+
任务成功 ≠ 范式有功;任务失败 ≠ 范式有过。只依据摘录中的行为证据下判断。
|
|
12
|
+
|
|
13
|
+
## 输出 JSON(只输出 JSON)
|
|
14
|
+
|
|
15
|
+
```json
|
|
16
|
+
{
|
|
17
|
+
"items": [
|
|
18
|
+
{ "pair": 1, "verdict": "assisted", "reason": "一句话依据" },
|
|
19
|
+
{ "pair": 2, "verdict": "unclear" }
|
|
20
|
+
]
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
硬规则:每个候选有且仅有一条判决;`verdict` ∈ `assisted | contested | unclear`;`pair` 用候选的 P 序号;无证据就判 `unclear`,不要硬凑。
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
id: wisdom.steward.attribute
|
|
2
|
+
name: Wisdom Steward Attribute
|
|
3
|
+
description: 弱归因判决:归因窗口 digest 批量 LLM 判决(assisted/contested/unclear),判决事件交 evaluate 入账
|
|
4
|
+
|
|
5
|
+
sense:
|
|
6
|
+
source: schedule
|
|
7
|
+
# 每日一次兜底脉搏;挂 govern 脉搏(governed 事件)+ 显式 attribute.request 增量触发
|
|
8
|
+
interval: 86400000
|
|
9
|
+
runOnStart: false
|
|
10
|
+
cooldownMs: 86400000
|
|
11
|
+
filter:
|
|
12
|
+
condition: "true"
|
|
13
|
+
events: ['wisdom.steward.governed', 'wisdom.steward.attribute.request']
|
|
14
|
+
emits: ['wisdom.steward.attributed', 'wisdom.steward.attribute.failed', 'wisdom.steward.evaluate.request']
|
|
15
|
+
isolation: isolated
|
|
16
|
+
|
|
17
|
+
think:
|
|
18
|
+
# code = 调 handler.ts 确定性实现(digest 构建 + LLM 判决解析;判决语义归 LLM)
|
|
19
|
+
implementation: code
|
|
20
|
+
strategy: deterministic
|
|
21
|
+
model: mini
|
|
22
|
+
maxIterations: 1
|
|
23
|
+
|
|
24
|
+
act:
|
|
25
|
+
mode: inject
|
|
26
|
+
|
|
27
|
+
signal:
|
|
28
|
+
severity: info
|
|
29
|
+
channel: [event]
|
|
30
|
+
|
|
31
|
+
boundary:
|
|
32
|
+
visibility: isolated
|
|
33
|
+
authority: act
|
|
34
|
+
security: trusted
|
|
35
|
+
|
|
36
|
+
tools:
|
|
37
|
+
mode: none
|
|
38
|
+
|
|
39
|
+
session:
|
|
40
|
+
mode: ephemeral
|
|
41
|
+
scope: agent
|
|
42
|
+
|
|
43
|
+
lifecycle:
|
|
44
|
+
maxConcurrent: 1
|
|
45
|
+
maxDurationMs: 120000
|
|
46
|
+
|
|
47
|
+
runtimeInject:
|
|
48
|
+
requires: ['wisdomStore', 'eventBus']
|
|
49
|
+
|
|
50
|
+
observability:
|
|
51
|
+
eventPrefix: wisdom.steward.attribute
|
|
52
|
+
|
|
53
|
+
metadata:
|
|
54
|
+
config:
|
|
55
|
+
dryRun: false
|
|
56
|
+
maxPairs: 40
|
|
57
|
+
sampleMax: 2
|
|
58
|
+
maxWindows: 500
|
|
59
|
+
maxTokens: 4096
|
|
60
|
+
windowRetentionMs: 2592000000
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* wisdom.steward.attribute — 弱归因判决(digest 批量 LLM 判决)
|
|
3
|
+
*
|
|
4
|
+
* 输入:归因窗口(run 收尾记账);判决只出自 LLM(digest + 引用摘录)。
|
|
5
|
+
* 输出:assisted/contested 事件 → `wisdom.steward.evaluate.request`(evaluate 入账)。
|
|
6
|
+
* 失败语义:缺 store/llmPort、LLM 错误、解析失败/覆盖率不符 → act.status=failed,
|
|
7
|
+
* **窗口保持 pending**(下批再判);宁可整批失败重试,不静默吞窗口。
|
|
8
|
+
* 只写 WisdomStore(E3);不写 Memory / Cognition / Knowledge。
|
|
9
|
+
*
|
|
10
|
+
* @module
|
|
11
|
+
*/
|
|
12
|
+
import type { SubsystemInput, SubsystemOutput, InjectedDependencies } from '@octopi-agent/engine/harness/collaboration/autonomous-subsystem/types.js';
|
|
13
|
+
declare function handler(_input: SubsystemInput, deps?: InjectedDependencies): Promise<SubsystemOutput>;
|
|
14
|
+
declare const _default: {
|
|
15
|
+
handler: typeof handler;
|
|
16
|
+
contract: {
|
|
17
|
+
input: string;
|
|
18
|
+
output: string;
|
|
19
|
+
};
|
|
20
|
+
dependencies: string[];
|
|
21
|
+
};
|
|
22
|
+
export default _default;
|
|
23
|
+
export { handler };
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* wisdom.steward.attribute — 弱归因判决(digest 批量 LLM 判决)
|
|
3
|
+
*
|
|
4
|
+
* 输入:归因窗口(run 收尾记账);判决只出自 LLM(digest + 引用摘录)。
|
|
5
|
+
* 输出:assisted/contested 事件 → `wisdom.steward.evaluate.request`(evaluate 入账)。
|
|
6
|
+
* 失败语义:缺 store/llmPort、LLM 错误、解析失败/覆盖率不符 → act.status=failed,
|
|
7
|
+
* **窗口保持 pending**(下批再判);宁可整批失败重试,不静默吞窗口。
|
|
8
|
+
* 只写 WisdomStore(E3);不写 Memory / Cognition / Knowledge。
|
|
9
|
+
*
|
|
10
|
+
* @module
|
|
11
|
+
*/
|
|
12
|
+
import { readFileSync } from 'node:fs';
|
|
13
|
+
import { dirname, join } from 'node:path';
|
|
14
|
+
import { fileURLToPath } from 'node:url';
|
|
15
|
+
import { DEP_LLM_PORT, DEP_SUBSYSTEM_PROMPT, chatForCompleteOutput, } from '@octopi-agent/engine/harness/collaboration/autonomous-subsystem/index.js';
|
|
16
|
+
import { buildAttributionDigest, emitWisdomEvaluateRequest, parseAttributionVerdicts, planAttributionBatch, verdictsToOutcomeEvents, } from '../../../harness/memory/index.js';
|
|
17
|
+
const DEP_WISDOM = 'wisdomStore';
|
|
18
|
+
const DEP_EVENT_BUS = 'eventBus';
|
|
19
|
+
const DEP_CONFIG = '__subsystem_config__';
|
|
20
|
+
function resolveSubsystemPrompt(deps, llmPort) {
|
|
21
|
+
const fromDeps = deps?.[DEP_SUBSYSTEM_PROMPT];
|
|
22
|
+
if (typeof fromDeps === 'string' && fromDeps.trim())
|
|
23
|
+
return fromDeps;
|
|
24
|
+
if (llmPort?.cognitivePrompt?.trim())
|
|
25
|
+
return llmPort.cognitivePrompt;
|
|
26
|
+
try {
|
|
27
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
28
|
+
return readFileSync(join(here, 'SUBSYSTEM.md'), 'utf8');
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return '';
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function failOutput(message, reason) {
|
|
35
|
+
return {
|
|
36
|
+
act: {
|
|
37
|
+
mode: 'inject',
|
|
38
|
+
status: 'failed',
|
|
39
|
+
error: message,
|
|
40
|
+
target: 'wisdom-store',
|
|
41
|
+
messages: [{ role: 'system', content: `wisdom.steward.attribute.failed reason=${reason}` }],
|
|
42
|
+
},
|
|
43
|
+
signals: [{ action: 'alert', reason: message, data: { reason } }],
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function skipOutput(detail, data) {
|
|
47
|
+
return {
|
|
48
|
+
act: {
|
|
49
|
+
mode: 'inject',
|
|
50
|
+
status: 'success',
|
|
51
|
+
target: 'wisdom-store',
|
|
52
|
+
messages: [{ role: 'system', content: `wisdom.steward.attribute.skipped ${detail}` }],
|
|
53
|
+
},
|
|
54
|
+
signals: [{ action: 'suggest', reason: 'attribute_skipped', data }],
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
async function handler(_input, deps) {
|
|
58
|
+
const wisdomStore = deps?.[DEP_WISDOM];
|
|
59
|
+
if (!wisdomStore)
|
|
60
|
+
throw new Error('wisdom.steward.attribute: wisdomStore not injected');
|
|
61
|
+
const config = deps?.[DEP_CONFIG] ?? {};
|
|
62
|
+
const dryRun = config.dryRun ?? false;
|
|
63
|
+
const now = Date.now();
|
|
64
|
+
// 保留期清理放入口:所有退出路径都执行(含提前返回/失败)
|
|
65
|
+
if (!dryRun) {
|
|
66
|
+
await wisdomStore.pruneWindows(now - (config.windowRetentionMs ?? 2592000000));
|
|
67
|
+
}
|
|
68
|
+
const windows = await wisdomStore.listPendingWindows(config.maxWindows ?? 500);
|
|
69
|
+
if (windows.length === 0)
|
|
70
|
+
return skipOutput('reason=no_pending_windows', {});
|
|
71
|
+
const alive = await wisdomStore.listForGovern({ includeRetired: false });
|
|
72
|
+
const batch = planAttributionBatch(windows, alive, {
|
|
73
|
+
sampleMax: config.sampleMax ?? 2,
|
|
74
|
+
maxPairs: config.maxPairs ?? 40,
|
|
75
|
+
});
|
|
76
|
+
if (batch.selected.length === 0) {
|
|
77
|
+
// 无候选或抽样未中:按设计关闭(判无可判);被 maxPairs 推迟的保持 pending
|
|
78
|
+
if (!dryRun)
|
|
79
|
+
await wisdomStore.markWindowsJudged(batch.closableWindowIds, now);
|
|
80
|
+
return skipOutput(`reason=no_candidates windows=${windows.length} closed=${batch.closableWindowIds.length} deferred=${batch.deferredWindowIds.length}`, {
|
|
81
|
+
windows: windows.length,
|
|
82
|
+
closedNoCandidate: batch.closableWindowIds.length,
|
|
83
|
+
cutByMaxPairs: batch.deferredWindowIds.length,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
const llmPort = deps?.[DEP_LLM_PORT];
|
|
87
|
+
if (!llmPort?.chat)
|
|
88
|
+
return failOutput('llmPort missing', 'llm_port_missing');
|
|
89
|
+
const { text: digest, pairRefs } = buildAttributionDigest(batch.selected);
|
|
90
|
+
const expectedPairs = batch.selected.map((_, i) => i + 1);
|
|
91
|
+
const outcome = await chatForCompleteOutput(llmPort, {
|
|
92
|
+
systemPrompt: resolveSubsystemPrompt(deps, llmPort) || undefined,
|
|
93
|
+
messages: [{ role: 'user', content: digest }],
|
|
94
|
+
maxTokens: config.maxTokens ?? 4096,
|
|
95
|
+
}, (text) => parseAttributionVerdicts(text, expectedPairs));
|
|
96
|
+
// parse_failed 已含覆盖率不符(缺项/重复/空 items):窗口保持 pending,下批再判
|
|
97
|
+
if (!outcome.ok)
|
|
98
|
+
return failOutput(outcome.message, outcome.reason);
|
|
99
|
+
const verdicts = outcome.parsed.items;
|
|
100
|
+
const events = verdictsToOutcomeEvents(verdicts, pairRefs, now);
|
|
101
|
+
const judgeWindowIds = [...new Set(batch.selected.map((c) => c.window.id))];
|
|
102
|
+
const closeIds = [...new Set([...judgeWindowIds, ...batch.closableWindowIds])];
|
|
103
|
+
if (dryRun) {
|
|
104
|
+
// 演练:不标记、不发事件、不清理——一切消费性操作全关
|
|
105
|
+
return {
|
|
106
|
+
act: {
|
|
107
|
+
mode: 'inject',
|
|
108
|
+
status: 'success',
|
|
109
|
+
target: 'wisdom-store',
|
|
110
|
+
messages: [{
|
|
111
|
+
role: 'system',
|
|
112
|
+
content: `wisdom.steward.attributed dryRun=true pairs=${batch.selected.length} ` +
|
|
113
|
+
`events=${events.length} deferred=${batch.deferredWindowIds.length}`,
|
|
114
|
+
}],
|
|
115
|
+
},
|
|
116
|
+
signals: [{
|
|
117
|
+
action: 'suggest',
|
|
118
|
+
reason: 'attribute_dry_run',
|
|
119
|
+
data: {
|
|
120
|
+
pairs: batch.selected.length,
|
|
121
|
+
verdicts: verdicts.map((v) => ({ pair: v.pair, verdict: v.verdict })),
|
|
122
|
+
events,
|
|
123
|
+
cutByMaxPairs: batch.deferredWindowIds.length,
|
|
124
|
+
dryRun: true,
|
|
125
|
+
},
|
|
126
|
+
}],
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
// 先标记 judged 再发判决事件:宁丢勿重(重复入账会污染 confidence / contestRate)。
|
|
130
|
+
// 只对本次真正标记到的窗口发事件(markWindowsJudged 返回值):跨进程重复判决不双记。
|
|
131
|
+
const newlyJudged = await wisdomStore.markWindowsJudged(closeIds, now);
|
|
132
|
+
const claimed = new Set(newlyJudged);
|
|
133
|
+
const emitEvents = events.filter((e) => e.ref && claimed.has(e.ref));
|
|
134
|
+
if (emitEvents.length > 0) {
|
|
135
|
+
emitWisdomEvaluateRequest(deps?.[DEP_EVENT_BUS], { events: emitEvents });
|
|
136
|
+
}
|
|
137
|
+
return {
|
|
138
|
+
act: {
|
|
139
|
+
mode: 'inject',
|
|
140
|
+
status: 'success',
|
|
141
|
+
target: 'wisdom-store',
|
|
142
|
+
messages: [{
|
|
143
|
+
role: 'system',
|
|
144
|
+
content: `wisdom.steward.attributed pairs=${batch.selected.length} events=${emitEvents.length} ` +
|
|
145
|
+
`closed=${newlyJudged.length} deferred=${batch.deferredWindowIds.length}`,
|
|
146
|
+
}],
|
|
147
|
+
},
|
|
148
|
+
signals: [{
|
|
149
|
+
action: 'suggest',
|
|
150
|
+
reason: 'attribute_completed',
|
|
151
|
+
data: {
|
|
152
|
+
pairs: batch.selected.length,
|
|
153
|
+
verdicts: verdicts.map((v) => ({ pair: v.pair, verdict: v.verdict })),
|
|
154
|
+
events: emitEvents,
|
|
155
|
+
closed: newlyJudged.length,
|
|
156
|
+
cutByMaxPairs: batch.deferredWindowIds.length,
|
|
157
|
+
dryRun: false,
|
|
158
|
+
},
|
|
159
|
+
}],
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
export default {
|
|
163
|
+
handler,
|
|
164
|
+
contract: { input: 'WisdomAttributeInput', output: 'WisdomAttributeResult' },
|
|
165
|
+
dependencies: [DEP_WISDOM],
|
|
166
|
+
};
|
|
167
|
+
export { handler };
|
|
@@ -25,7 +25,9 @@ async function handler(input, deps) {
|
|
|
25
25
|
const rawEvents = Array.isArray(payload.events) ? payload.events : [];
|
|
26
26
|
const events = rawEvents.filter(isOutcomeEvent);
|
|
27
27
|
if (events.length > 0 && !dryRun) {
|
|
28
|
-
|
|
28
|
+
// config 必须透传:recordOutcomes 内部推进 confidence/状态迁移,
|
|
29
|
+
// 否则 evaluation.* 配置在事件路径上被默认值绕过(评审 F4)
|
|
30
|
+
await store.recordOutcomes(events, config);
|
|
29
31
|
}
|
|
30
32
|
const entries = await store.listForGovern({ includeRetired: false });
|
|
31
33
|
let updated = 0;
|
|
@@ -4,17 +4,23 @@ description: 从 Memory/Cognition 稳定结构炼制判断范式(maxim;多
|
|
|
4
4
|
|
|
5
5
|
sense:
|
|
6
6
|
source: schedule
|
|
7
|
-
|
|
7
|
+
# 8h 兜底脉搏;启动首跳 + memory.stored 增量触发补足响应速度
|
|
8
|
+
interval: 28800000
|
|
9
|
+
runOnStart: true
|
|
10
|
+
cooldownMs: 3600000
|
|
8
11
|
filter:
|
|
9
12
|
condition: "true"
|
|
10
|
-
|
|
13
|
+
# minEvents 对订阅事件统一累积:攒 5 条新记忆才放行;显式触发请走 trigger API
|
|
14
|
+
minEvents: 5
|
|
15
|
+
events: ['wisdom.steward.formation.request', 'memory.stored']
|
|
11
16
|
emits: ['wisdom.steward.formed', 'wisdom.steward.formation.failed']
|
|
12
17
|
isolation: isolated
|
|
13
18
|
|
|
14
19
|
think:
|
|
15
|
-
|
|
20
|
+
# code = 调 handler.ts 确定性实现(llm 模式是自由 decide,handler 从未执行——2026-10-30 修复)
|
|
21
|
+
implementation: code
|
|
16
22
|
strategy: single
|
|
17
|
-
model:
|
|
23
|
+
model: mini
|
|
18
24
|
maxIterations: 1
|
|
19
25
|
|
|
20
26
|
act:
|
|
@@ -38,7 +44,7 @@ session:
|
|
|
38
44
|
|
|
39
45
|
lifecycle:
|
|
40
46
|
maxConcurrent: 1
|
|
41
|
-
maxDurationMs:
|
|
47
|
+
maxDurationMs: 120000
|
|
42
48
|
|
|
43
49
|
runtimeInject:
|
|
44
50
|
requires: ['wisdomStore', 'memoryStore']
|
|
@@ -52,3 +58,4 @@ metadata:
|
|
|
52
58
|
minMemorySupport: 2
|
|
53
59
|
minClusterSize: 5
|
|
54
60
|
maxEvidenceChars: 6000
|
|
61
|
+
maxTokens: 8192
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
import { readFileSync } from 'node:fs';
|
|
8
8
|
import { dirname, join } from 'node:path';
|
|
9
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';
|
|
10
|
+
import { DEP_LLM_PORT, DEP_SUBSYSTEM_PROMPT, chatForCompleteOutput, } from '@octopi-agent/engine/harness/collaboration/autonomous-subsystem/index.js';
|
|
11
|
+
import { formAndAdmit, parseWisdomFormationJson, planPromotionCandidates, } from '../../../harness/memory/index.js';
|
|
12
12
|
const DEP_WISDOM = 'wisdomStore';
|
|
13
13
|
const DEP_MEMORY = 'memoryStore';
|
|
14
14
|
const DEP_CONCEPT = 'conceptGraphStore';
|
|
@@ -155,24 +155,18 @@ async function handler(_input, deps) {
|
|
|
155
155
|
// 图不可用不阻断炼制
|
|
156
156
|
}
|
|
157
157
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
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');
|
|
158
|
+
// maxTokens 只是生成配额(LLM 传参):截断(finish=length)或解析失败都放大配额重试
|
|
159
|
+
// 一次,仍失败显式上报——业务完整性优先,禁止静默半截结果
|
|
160
|
+
const outcome = await chatForCompleteOutput(llmPort, {
|
|
161
|
+
systemPrompt: systemPrompt || undefined,
|
|
162
|
+
messages: [{ role: 'user', content: `${pack.text}${conceptHint}` }],
|
|
163
|
+
maxTokens: config.maxTokens ?? 8192,
|
|
164
|
+
}, (text) => parseWisdomFormationJson(text));
|
|
165
|
+
if (!outcome.ok) {
|
|
166
|
+
return failOutput(outcome.message, outcome.reason);
|
|
173
167
|
}
|
|
174
168
|
const allowedMemoryIds = new Set(pack.memoryIds);
|
|
175
|
-
const { results, droppedNotes } = await formAndAdmit(
|
|
169
|
+
const { results, droppedNotes } = await formAndAdmit(outcome.raw, wisdomStore, {
|
|
176
170
|
origin: 'distilled',
|
|
177
171
|
maxItems,
|
|
178
172
|
allowedMemoryIds,
|
|
@@ -4,7 +4,9 @@
|
|
|
4
4
|
* 只写 WisdomStore;可 dryRun。不写 Memory / Cognition。
|
|
5
5
|
*/
|
|
6
6
|
import { planWisdomGovern, wisdomUtility, } from '../../../harness/memory/wisdom-policy.js';
|
|
7
|
+
import { emitWisdomGoverned } from '../../../harness/memory/wisdom-events.js';
|
|
7
8
|
const DEP_WISDOM = 'wisdomStore';
|
|
9
|
+
const DEP_EVENT_BUS = 'eventBus';
|
|
8
10
|
const DEP_CONFIG = '__subsystem_config__';
|
|
9
11
|
async function handler(_input, deps) {
|
|
10
12
|
const store = deps?.[DEP_WISDOM];
|
|
@@ -33,6 +35,8 @@ async function handler(_input, deps) {
|
|
|
33
35
|
retired = plan.filter((p) => p.action === 'retire').length;
|
|
34
36
|
}
|
|
35
37
|
const stats = await store.stats();
|
|
38
|
+
// 治理脉搏:判官(wisdom.steward.attribute)等维护动作挂此脉搏;发射失败不影响 govern
|
|
39
|
+
emitWisdomGoverned(deps?.[DEP_EVENT_BUS]);
|
|
36
40
|
return {
|
|
37
41
|
act: {
|
|
38
42
|
mode: 'inject',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@octopi-agent/engine",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.98.4",
|
|
4
4
|
"description": "Octopi Engine — Harness product domains, library integrations, and embeddable Agent.run()",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -56,6 +56,10 @@
|
|
|
56
56
|
"types": "./dist/integration/*",
|
|
57
57
|
"import": "./dist/integration/*"
|
|
58
58
|
},
|
|
59
|
+
"./subsystems/*": {
|
|
60
|
+
"types": "./dist/subsystems/*",
|
|
61
|
+
"import": "./dist/subsystems/*"
|
|
62
|
+
},
|
|
59
63
|
"./config-schema/*": {
|
|
60
64
|
"types": "./dist/config-schema/*",
|
|
61
65
|
"import": "./dist/config-schema/*"
|
|
@@ -80,9 +84,10 @@
|
|
|
80
84
|
},
|
|
81
85
|
"dependencies": {
|
|
82
86
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
83
|
-
"@octopi-agent/core": "0.
|
|
87
|
+
"@octopi-agent/core": "0.98.4",
|
|
84
88
|
"js-yaml": "^4.3.2",
|
|
85
89
|
"undici": "^8.12.3",
|
|
90
|
+
"web-tree-sitter": "^0.27.1",
|
|
86
91
|
"zod": "^4.4.3"
|
|
87
92
|
},
|
|
88
93
|
"optionalDependencies": {
|