@octopi-agent/engine 0.86.38 → 0.97.15
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-admin/agent-presets.d.ts +70 -0
- package/dist/config-admin/agent-presets.js +243 -0
- package/dist/config-admin/discover.d.ts +30 -0
- package/dist/config-admin/discover.js +48 -0
- package/dist/config-admin/env.d.ts +22 -0
- package/dist/config-admin/env.js +41 -0
- package/dist/config-admin/index.d.ts +20 -0
- package/dist/config-admin/index.js +15 -0
- package/dist/config-admin/model-presets.d.ts +75 -0
- package/dist/config-admin/model-presets.js +249 -0
- package/dist/config-admin/name-guard.d.ts +14 -0
- package/dist/config-admin/name-guard.js +24 -0
- package/dist/config-admin/patch.d.ts +56 -0
- package/dist/config-admin/patch.js +201 -0
- package/dist/config-admin/port.d.ts +68 -0
- package/dist/config-admin/port.js +21 -0
- package/dist/config-admin/redact.d.ts +39 -0
- package/dist/config-admin/redact.js +42 -0
- package/dist/config-schema/agent.d.ts +43 -1
- package/dist/config-schema/agent.js +12 -5
- package/dist/config-schema/context.d.ts +7 -2
- package/dist/config-schema/context.js +8 -0
- package/dist/config-schema/engine.d.ts +110 -8
- package/dist/config-schema/governance.d.ts +43 -1
- package/dist/config-schema/governance.js +160 -2
- package/dist/config-schema/models.d.ts +7 -4
- package/dist/config-schema/models.js +4 -1
- package/dist/config-schema/observability.d.ts +9 -0
- package/dist/config-schema/observability.js +29 -0
- package/dist/config-schema/run.d.ts +3 -0
- package/dist/config-schema/run.js +14 -0
- package/dist/config-schema/shared.d.ts +3 -0
- package/dist/config-schema/shared.js +12 -0
- package/dist/config-schema/substrate.d.ts +1 -1
- package/dist/config.d.ts +60 -13
- package/dist/config.js +81 -78
- package/dist/harness/activation/dispatcher.d.ts +8 -2
- package/dist/harness/activation/dispatcher.js +33 -5
- package/dist/harness/activation/inbox.d.ts +87 -0
- package/dist/harness/activation/inbox.js +169 -0
- package/dist/harness/activation/runtime.d.ts +9 -8
- package/dist/harness/activation/runtime.js +100 -8
- package/dist/harness/activation/types.d.ts +19 -0
- package/dist/harness/activation/types.js +2 -0
- package/dist/harness/agent/builder.d.ts +18 -3
- package/dist/harness/agent/builder.js +42 -17
- package/dist/harness/agent/config-bridge.d.ts +5 -0
- package/dist/harness/agent/config-bridge.js +7 -1
- package/dist/harness/agent/config-integrity.d.ts +72 -0
- package/dist/harness/agent/config-integrity.js +146 -0
- package/dist/harness/agent/tool-purpose.d.ts +9 -1
- package/dist/harness/agent/tool-purpose.js +11 -2
- package/dist/harness/agent/wire-agent-builder.js +11 -3
- package/dist/harness/collaboration/autonomous-subsystem/boundary/validator.d.ts +11 -1
- package/dist/harness/collaboration/autonomous-subsystem/boundary/validator.js +11 -1
- package/dist/harness/collaboration/autonomous-subsystem/loader.d.ts +13 -0
- package/dist/harness/collaboration/autonomous-subsystem/loader.js +16 -1
- package/dist/harness/collaboration/autonomous-subsystem/runtime.d.ts +4 -0
- package/dist/harness/collaboration/autonomous-subsystem/runtime.js +3 -1
- package/dist/harness/collaboration/autonomous-subsystem/think/executor.js +3 -1
- package/dist/harness/collaboration/delegation/child-run.js +21 -5
- package/dist/harness/collaboration/delegation/notifier.js +4 -3
- package/dist/harness/collaboration/delegation/service.js +2 -3
- package/dist/harness/collaboration/delegation/wiring.js +6 -5
- package/dist/harness/collaboration/orchestration/reflector/llm-reflector.d.ts +1 -1
- package/dist/harness/collaboration/orchestration/reflector/llm-reflector.js +1 -1
- package/dist/harness/context/capabilities/compact/engine.d.ts +30 -0
- package/dist/harness/context/capabilities/compact/engine.js +198 -46
- package/dist/harness/context/capabilities/compact/handover.d.ts +78 -0
- package/dist/harness/context/capabilities/compact/handover.js +107 -0
- package/dist/harness/context/capabilities/compact/index.d.ts +3 -1
- package/dist/harness/context/capabilities/compact/index.js +2 -1
- package/dist/harness/context/capabilities/compact/types.d.ts +30 -1
- package/dist/harness/context/capabilities/summary/executor.js +2 -1
- package/dist/harness/context/capabilities/summary/policies.js +8 -5
- package/dist/harness/context/constitution/default-agents.md +11 -10
- package/dist/harness/context/default-context-engine.d.ts +34 -4
- package/dist/harness/context/default-context-engine.js +198 -53
- package/dist/harness/context/hybrid-compressor.js +6 -0
- package/dist/harness/context/layer-types.d.ts +36 -0
- package/dist/harness/context/layer-types.js +38 -0
- package/dist/harness/context/llm-summarizer.d.ts +2 -8
- package/dist/harness/context/llm-summarizer.js +69 -91
- package/dist/harness/context/message-selector.js +4 -3
- package/dist/harness/context/root-instructions.js +1 -1
- package/dist/harness/context/summarize.d.ts +2 -0
- package/dist/harness/context/summarize.js +7 -2
- package/dist/harness/context/system-prompt-assembler.js +10 -4
- package/dist/harness/context/tool-result-aging.js +2 -2
- package/dist/harness/context/truncate-compressor.js +7 -0
- package/dist/harness/context/turn-envelope.d.ts +4 -3
- package/dist/harness/context/turn-envelope.js +4 -3
- package/dist/harness/context/types.d.ts +33 -1
- package/dist/harness/extension/execution-environment/dangerous-commands.d.ts +28 -0
- package/dist/harness/extension/execution-environment/dangerous-commands.js +129 -0
- package/dist/harness/extension/execution-environment/effect-policy.d.ts +133 -4
- package/dist/harness/extension/execution-environment/effect-policy.js +263 -14
- package/dist/harness/extension/execution-environment/index.d.ts +4 -2
- package/dist/harness/extension/execution-environment/index.js +2 -1
- package/dist/harness/extension/execution-environment/isolation.js +5 -1
- package/dist/harness/extension/execution-environment/kill-switch.d.ts +34 -0
- package/dist/harness/extension/execution-environment/kill-switch.js +46 -0
- package/dist/harness/extension/execution-environment/ops-audit.d.ts +200 -0
- package/dist/harness/extension/execution-environment/ops-audit.js +338 -0
- package/dist/harness/extension/execution-environment/privileged-exec.d.ts +158 -0
- package/dist/harness/extension/execution-environment/privileged-exec.js +418 -0
- package/dist/harness/extension/execution-environment/process-info.d.ts +180 -0
- package/dist/harness/extension/execution-environment/process-info.js +466 -0
- package/dist/harness/extension/execution-environment/process-isolation.d.ts +7 -0
- package/dist/harness/extension/execution-environment/process-isolation.js +9 -0
- package/dist/harness/extension/execution-environment/sandbox.d.ts +109 -0
- package/dist/harness/extension/execution-environment/sandbox.js +264 -29
- package/dist/harness/extension/execution-environment/tool-capabilities.d.ts +1 -1
- package/dist/harness/extension/execution-environment/tool-capabilities.js +6 -0
- package/dist/harness/extension/execution-environment/types.d.ts +19 -0
- package/dist/harness/extension/plugin-ecosystem/channel-types.d.ts +5 -0
- package/dist/harness/extension/plugin-ecosystem/tools/allowlisted-run.d.ts +6 -0
- package/dist/harness/extension/plugin-ecosystem/tools/allowlisted-run.js +50 -0
- package/dist/harness/extension/plugin-ecosystem/tools/ask-user.d.ts +4 -5
- package/dist/harness/extension/plugin-ecosystem/tools/ask-user.js +5 -15
- package/dist/harness/extension/plugin-ecosystem/tools/builtin.d.ts +3 -0
- package/dist/harness/extension/plugin-ecosystem/tools/builtin.js +53 -2
- package/dist/harness/extension/plugin-ecosystem/tools/file-search.js +10 -17
- package/dist/harness/extension/plugin-ecosystem/tools/git-runner.d.ts +31 -0
- package/dist/harness/extension/plugin-ecosystem/tools/git-runner.js +104 -0
- package/dist/harness/extension/plugin-ecosystem/tools/git-status-snapshot.d.ts +111 -0
- package/dist/harness/extension/plugin-ecosystem/tools/git-status-snapshot.js +197 -0
- package/dist/harness/extension/plugin-ecosystem/tools/git-tools.d.ts +8 -8
- package/dist/harness/extension/plugin-ecosystem/tools/git-tools.js +9 -100
- package/dist/harness/extension/plugin-ecosystem/tools/index.d.ts +6 -0
- package/dist/harness/extension/plugin-ecosystem/tools/index.js +4 -0
- package/dist/harness/extension/plugin-ecosystem/tools/privileged-tool.d.ts +43 -0
- package/dist/harness/extension/plugin-ecosystem/tools/privileged-tool.js +350 -0
- package/dist/harness/extension/plugin-ecosystem/tools/process-tools.d.ts +30 -0
- package/dist/harness/extension/plugin-ecosystem/tools/process-tools.js +137 -0
- package/dist/harness/governance/human-in-the-loop/decision-cache.d.ts +54 -4
- package/dist/harness/governance/human-in-the-loop/decision-cache.js +42 -16
- package/dist/harness/governance/security/temp-path.d.ts +9 -0
- package/dist/harness/governance/security/temp-path.js +13 -2
- package/dist/harness/governance/session-acl/seed-roles.js +14 -0
- package/dist/harness/index.d.ts +4 -0
- package/dist/harness/index.js +3 -0
- package/dist/harness/knowledge/file-identity.d.ts +8 -0
- package/dist/harness/knowledge/file-identity.js +26 -1
- package/dist/harness/knowledge/fts.js +1 -2
- package/dist/harness/knowledge/grounding.js +5 -5
- package/dist/harness/knowledge/index-store.d.ts +31 -4
- package/dist/harness/knowledge/index-store.js +180 -48
- package/dist/harness/knowledge/ingest.d.ts +115 -115
- package/dist/harness/knowledge/ingest.js +150 -150
- package/dist/harness/knowledge/knowledge-serve-child.js +1 -1
- package/dist/harness/knowledge/purge.js +4 -1
- package/dist/harness/memory/backfill-coverage.js +3 -1
- package/dist/harness/memory/sqlite/keyword-search.d.ts +1 -0
- package/dist/harness/memory/sqlite/keyword-search.js +4 -3
- package/dist/harness/observability/observer/hub.js +38 -1
- package/dist/harness/observability/observer/run-snapshot.js +1 -0
- package/dist/harness/observability/observer/types.d.ts +27 -0
- package/dist/harness/run/agent/agent.d.ts +7 -0
- package/dist/harness/run/agent/agent.js +23 -1
- package/dist/harness/run/reliability/fallback-provider.d.ts +117 -5
- package/dist/harness/run/reliability/fallback-provider.js +262 -22
- package/dist/harness/run/reliability/harness-events.d.ts +24 -1
- package/dist/harness/run/reliability/model-error-policy.d.ts +32 -0
- package/dist/harness/run/reliability/model-error-policy.js +42 -0
- package/dist/harness/run/reliability/provider-wrapper.js +29 -2
- package/dist/harness/run/reliability/refusal-guard.d.ts +20 -0
- package/dist/harness/run/reliability/refusal-guard.js +102 -0
- package/dist/harness/run/reliability/run-agent.js +231 -33
- package/dist/harness/run/run-guard/default-run-guard.js +1 -1
- package/dist/harness/run/run-scope.d.ts +31 -0
- package/dist/harness/run/runner.d.ts +132 -2
- package/dist/harness/run/runner.js +679 -60
- package/dist/harness/session/attachments/llm-intent.js +2 -1
- package/dist/harness/session/history/port.js +15 -5
- package/dist/harness/session/in-memory-store.d.ts +5 -0
- package/dist/harness/session/in-memory-store.js +33 -2
- package/dist/harness/session/tasks/render.d.ts +4 -1
- package/dist/harness/session/tasks/render.js +10 -7
- package/dist/harness/session/title.js +25 -9
- package/dist/harness/shared/events/agent-event-map.d.ts +92 -0
- package/dist/harness/shared/events/agent-event-map.js +7 -0
- package/dist/index.d.ts +6 -4
- package/dist/index.js +4 -3
- package/dist/integration/agent-runtime/channel-message-source.js +19 -1
- package/dist/integration/index.d.ts +2 -0
- package/dist/integration/index.js +1 -0
- package/dist/integration/observability/loop-watchdog.d.ts +56 -0
- package/dist/integration/observability/loop-watchdog.js +177 -0
- package/dist/integration/observability/metrics.d.ts +3 -0
- package/dist/integration/observability/metrics.js +18 -7
- package/dist/integration/observability/run-telemetry.d.ts +8 -0
- package/dist/integration/observability/run-telemetry.js +31 -8
- package/dist/integration/observability/trace-collector.js +26 -4
- package/dist/integration/observability/trace-events.d.ts +1 -0
- package/dist/integration/observability/trace-events.js +2 -0
- package/dist/integration/observability/trace-logger.js +27 -17
- package/dist/integration/providers/anthropic.d.ts +23 -0
- package/dist/integration/providers/anthropic.js +97 -12
- package/dist/integration/providers/fetch-timeout.d.ts +42 -0
- package/dist/integration/providers/fetch-timeout.js +51 -0
- package/dist/integration/providers/openai.d.ts +10 -0
- package/dist/integration/providers/openai.js +58 -11
- package/dist/integration/providers/provider-diagnostics.d.ts +80 -0
- package/dist/integration/providers/provider-diagnostics.js +89 -0
- package/dist/integration/providers/timeout-coherence.d.ts +52 -0
- package/dist/integration/providers/timeout-coherence.js +68 -0
- package/dist/integration/providers/wire-dump.d.ts +62 -0
- package/dist/integration/providers/wire-dump.js +111 -2
- package/dist/integration/storage/jsonl.d.ts +19 -1
- package/dist/integration/storage/jsonl.js +100 -4
- package/dist/paths.d.ts +19 -0
- package/dist/paths.js +38 -1
- package/dist/subsystems/cognition-steward/conceptualize/handler.js +1 -1
- package/dist/subsystems/memory-steward/backfill/handler.js +1 -1
- package/dist/subsystems/safety-guard/config.yaml +3 -1
- package/dist/subsystems/wisdom-steward/formation/handler.js +1 -1
- package/package.json +3 -2
|
@@ -18,6 +18,8 @@
|
|
|
18
18
|
import { getTextContent } from '@octopi-agent/core/types.js';
|
|
19
19
|
import { classifyError } from '@octopi-agent/core/loop/error-classifier.js';
|
|
20
20
|
import { agentLoop } from '@octopi-agent/core/loop/agent-loop.js';
|
|
21
|
+
import { maxAttemptsFor } from './model-error-policy.js';
|
|
22
|
+
import { guardRefusalProvider } from './refusal-guard.js';
|
|
21
23
|
import { recordToolCall, detectNoProgressLoop, } from '../concurrency/tool-loop-detection.js';
|
|
22
24
|
import { severityToAction } from '@octopi-agent/core/security-guard.js';
|
|
23
25
|
import { RunMetricsCollector } from './run-metrics-collector.js';
|
|
@@ -62,6 +64,78 @@ function estimateCost(snapshot, pricing) {
|
|
|
62
64
|
const outputCost = (snapshot.outputTokens / 1_000_000) * defaultPricing.outputPer1M;
|
|
63
65
|
return inputCost + cachedCost + outputCost;
|
|
64
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* 入队一条「模型调用即将重试」通知
|
|
69
|
+
*
|
|
70
|
+
* onError 不是 generator,无法直接 yield;与 SecurityGuard 同策略入队,
|
|
71
|
+
* 由主循环在下一个事件边界推出。
|
|
72
|
+
*
|
|
73
|
+
* @param state - Run 状态(承载待推队列)
|
|
74
|
+
* @param error - 分类后的错误
|
|
75
|
+
* @param attempt - 本次尝试序号(从 0 起)
|
|
76
|
+
* @param delayMs - 重试前等待时长
|
|
77
|
+
*/
|
|
78
|
+
/**
|
|
79
|
+
* 入队一条「模型调用即将重试」通知,并登记待执行的退避等待
|
|
80
|
+
*
|
|
81
|
+
* onError 不是 generator,无法直接 yield;与 SecurityGuard 同策略入队,
|
|
82
|
+
* 由主循环在下一个事件边界推出。
|
|
83
|
+
*
|
|
84
|
+
* **等待不在这里执行**(2026-10-27 评审修正):若在此 `await sleep(delayMs)`,
|
|
85
|
+
* generator 会卡在 onError 内,外层 for-await 没有任何事件可排空,
|
|
86
|
+
* 通知要等睡眠结束才送达——`rate_limit` 带 `Retry-After` 时用户在整个等待期仍是零反馈。
|
|
87
|
+
* 因此把退避时长登记到 state,由排空处在 `yield` 之后再 sleep。
|
|
88
|
+
*
|
|
89
|
+
* @param state - reliability 运行态
|
|
90
|
+
* @param error - 已分类错误
|
|
91
|
+
* @param attempt - 本次尝试序号(从 0 起)
|
|
92
|
+
* @param delayMs - 重试前需等待的时长
|
|
93
|
+
* @param maxAttempts - 该原因的允许重试次数(由调用方给出,避免表外原因显示 0)
|
|
94
|
+
*/
|
|
95
|
+
function pushRetryNotice(state, error, attempt, delayMs, maxAttempts) {
|
|
96
|
+
state.pendingModelRetryEvents.push({
|
|
97
|
+
type: 'model_retry',
|
|
98
|
+
timestamp: Date.now(),
|
|
99
|
+
data: {
|
|
100
|
+
attempt: attempt + 1,
|
|
101
|
+
maxAttempts,
|
|
102
|
+
reason: error.reason,
|
|
103
|
+
delayMs,
|
|
104
|
+
error: (error.message || '').slice(0, 500),
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
// 多条通知合并成一次等待:取最大退避,避免退避时长被叠加放大
|
|
108
|
+
state.pendingRetryDelayMs = Math.max(state.pendingRetryDelayMs, delayMs);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* 可被 abort 打断的等待
|
|
112
|
+
*
|
|
113
|
+
* `rate_limit` 的 `Retry-After` 可达数十秒;若用裸 `setTimeout`,
|
|
114
|
+
* 用户按下停止后仍要等满整个退避窗口才能生效。
|
|
115
|
+
*
|
|
116
|
+
* @param ms - 等待时长
|
|
117
|
+
* @param signal - 运行中止信号(可选)
|
|
118
|
+
* @returns 到时或被中止时 resolve(不 reject:中止由循环自身处理)
|
|
119
|
+
*/
|
|
120
|
+
async function sleepUnlessAborted(ms, signal) {
|
|
121
|
+
if (ms <= 0)
|
|
122
|
+
return;
|
|
123
|
+
if (!signal) {
|
|
124
|
+
await new Promise((resolve) => setTimeout(resolve, ms));
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
if (signal.aborted)
|
|
128
|
+
return;
|
|
129
|
+
await new Promise((resolve) => {
|
|
130
|
+
const done = () => {
|
|
131
|
+
clearTimeout(timer);
|
|
132
|
+
signal.removeEventListener('abort', done);
|
|
133
|
+
resolve();
|
|
134
|
+
};
|
|
135
|
+
const timer = setTimeout(done, ms);
|
|
136
|
+
signal.addEventListener('abort', done, { once: true });
|
|
137
|
+
});
|
|
138
|
+
}
|
|
65
139
|
function createInitialState(checkpointInterval = 15) {
|
|
66
140
|
return {
|
|
67
141
|
planningOnlyAttempts: 0,
|
|
@@ -83,6 +157,8 @@ function createInitialState(checkpointInterval = 15) {
|
|
|
83
157
|
modelErrorAttempt: 0,
|
|
84
158
|
pendingBudgetHardYield: false,
|
|
85
159
|
pendingSecurityEvents: [],
|
|
160
|
+
pendingRetryDelayMs: 0,
|
|
161
|
+
pendingModelRetryEvents: [],
|
|
86
162
|
wrapUp: false,
|
|
87
163
|
advisoryTriggered: new Set(),
|
|
88
164
|
};
|
|
@@ -183,6 +259,9 @@ export async function* runAgentWithReliability(context, config, harness, signal)
|
|
|
183
259
|
const originalBeforeToolCall = config.beforeToolCall;
|
|
184
260
|
const wrappedConfig = {
|
|
185
261
|
...config,
|
|
262
|
+
// 内容过滤拒答守卫:把「200 内联罐头拒答」转成 content_filter 模型错误,
|
|
263
|
+
// 复用 onError/重试链路(阈值型误杀原样重试常过;耗尽走诚实收口)
|
|
264
|
+
model: guardRefusalProvider(config.model),
|
|
186
265
|
// getFollowUpMessages:返回 reliability 层注入的 steer 消息
|
|
187
266
|
getFollowUpMessages: async () => {
|
|
188
267
|
const msgs = [...pendingFollowUps];
|
|
@@ -195,6 +274,38 @@ export async function* runAgentWithReliability(context, config, harness, signal)
|
|
|
195
274
|
},
|
|
196
275
|
// beforeToolCall:Budget hard 闸 + wrap-up 控制 + SecurityGuard 检查 + 原始回调
|
|
197
276
|
beforeToolCall: async (ctx, signal) => {
|
|
277
|
+
// ops P5 kill switch:宿主侧急停,先于一切执行(不依赖 LLM/agent 合作,agent 无法解除)
|
|
278
|
+
{
|
|
279
|
+
const scope = getRunScope();
|
|
280
|
+
const killPaths = scope?.toolRuntime?.killSwitchPaths;
|
|
281
|
+
if (killPaths && killPaths.length > 0) {
|
|
282
|
+
const { checkKillSwitch } = await import('../../extension/execution-environment/kill-switch.js');
|
|
283
|
+
const killState = checkKillSwitch(killPaths);
|
|
284
|
+
if (killState.engaged) {
|
|
285
|
+
const reason = `kill_switch_active: agent execution is halted by the host sentinel (${killState.path})`;
|
|
286
|
+
state.pendingSecurityEvents.push({
|
|
287
|
+
type: 'security_blocked',
|
|
288
|
+
timestamp: Date.now(),
|
|
289
|
+
data: {
|
|
290
|
+
sessionId: scope?.sessionId,
|
|
291
|
+
agentId: scope?.agentId,
|
|
292
|
+
reason,
|
|
293
|
+
toolName: ctx.toolCall.name,
|
|
294
|
+
action: 'reject',
|
|
295
|
+
severity: 'high',
|
|
296
|
+
violations: [
|
|
297
|
+
{
|
|
298
|
+
type: 'unauthorized_tool',
|
|
299
|
+
severity: 'high',
|
|
300
|
+
description: reason,
|
|
301
|
+
},
|
|
302
|
+
],
|
|
303
|
+
},
|
|
304
|
+
});
|
|
305
|
+
return { block: true, reason, terminate: true };
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
198
309
|
// Budget hard:阻止本批工具继续执行(turn_end 在工具之前 yield)
|
|
199
310
|
if (budget && !state.budgetStop) {
|
|
200
311
|
const hard = budget.checkHardOnly();
|
|
@@ -274,6 +385,27 @@ export async function* runAgentWithReliability(context, config, harness, signal)
|
|
|
274
385
|
sessionRights,
|
|
275
386
|
])) {
|
|
276
387
|
const reason = `tool_rights_denied: "${ctx.toolCall.name}" is not permitted for this session participant`;
|
|
388
|
+
// ops P5/§8.6:提权请求者缺权 → **确认闸门之前**拒绝并留痕(not_authorized,
|
|
389
|
+
// 无弹窗)。工具 handler 根本不会执行——确认 ≠ 请求者可信。
|
|
390
|
+
if (ctx.toolCall.name === 'priv_exec') {
|
|
391
|
+
scope?.toolRuntime?.recordOpsEvent?.({
|
|
392
|
+
event: 'ops.escalation.denied',
|
|
393
|
+
data: {
|
|
394
|
+
argv: [
|
|
395
|
+
String(ctx.toolCall.arguments?.cmd ?? ''),
|
|
396
|
+
...(ctx.toolCall.arguments?.args ?? []),
|
|
397
|
+
],
|
|
398
|
+
why: 'not_authorized',
|
|
399
|
+
toolName: ctx.toolCall.name,
|
|
400
|
+
origin: {
|
|
401
|
+
sessionId: scope?.sessionId,
|
|
402
|
+
agentId: scope?.agentId,
|
|
403
|
+
runId: scope?.runId ?? null,
|
|
404
|
+
participants: scope?.toolRuntime?.sessionParticipants ?? [],
|
|
405
|
+
},
|
|
406
|
+
},
|
|
407
|
+
});
|
|
408
|
+
}
|
|
277
409
|
state.pendingSecurityEvents.push({
|
|
278
410
|
type: 'security_blocked',
|
|
279
411
|
timestamp: Date.now(),
|
|
@@ -353,24 +485,10 @@ export async function* runAgentWithReliability(context, config, harness, signal)
|
|
|
353
485
|
afterToolCall: async (ctx, signal) => {
|
|
354
486
|
// SecurityGuard 检查工具输出(字符串直扫;结构化结果序列化后扫,防 MCP/对象结果绕过)
|
|
355
487
|
if (harness.security && ctx.result.content != null) {
|
|
356
|
-
const raw = ctx.result.content;
|
|
357
|
-
const scanText = typeof raw === 'string'
|
|
358
|
-
? raw
|
|
359
|
-
: (() => {
|
|
360
|
-
try {
|
|
361
|
-
return JSON.stringify(raw);
|
|
362
|
-
}
|
|
363
|
-
catch {
|
|
364
|
-
return String(raw);
|
|
365
|
-
}
|
|
366
|
-
})();
|
|
367
488
|
// 超大 payload 截断扫描,避免序列化字符串拖垮 checkToolOutput
|
|
368
|
-
const outputCheck = harness.security.checkToolOutput(
|
|
489
|
+
const outputCheck = harness.security.checkToolOutput(truncateForOutputScan(toolOutputScanText(ctx.result.content)));
|
|
369
490
|
if (!outputCheck.isClean) {
|
|
370
|
-
const action = severityToAction(outputCheck.violations.
|
|
371
|
-
const order = { critical: 4, high: 3, medium: 2, low: 1 };
|
|
372
|
-
return order[v.severity] > order[worst.severity] ? v : worst;
|
|
373
|
-
}, outputCheck.violations[0]).severity);
|
|
491
|
+
const action = severityToAction(worstOutputViolation(outputCheck.violations).severity);
|
|
374
492
|
// 输出侧无「事前确认」语义:confirm/high 一律拦截该输出
|
|
375
493
|
if (action === 'block' || action === 'reject' || action === 'confirm') {
|
|
376
494
|
const reason = outputCheck.violations
|
|
@@ -392,6 +510,28 @@ export async function* runAgentWithReliability(context, config, harness, signal)
|
|
|
392
510
|
}
|
|
393
511
|
return undefined;
|
|
394
512
|
},
|
|
513
|
+
// onToolUpdate:部分输出经 SecurityGuard 出口扫描后转发(展示通道)。
|
|
514
|
+
// 与 afterToolCall 同一判定口径(共享助手)——否则恶意工具可借部分输出绕过出口扫描;
|
|
515
|
+
// 违规部分扣发,最终结果仍走 afterToolCall 裁决。
|
|
516
|
+
onToolUpdate: config.onToolUpdate
|
|
517
|
+
? (params) => {
|
|
518
|
+
const partial = params.partial;
|
|
519
|
+
if (harness.security && partial.content != null) {
|
|
520
|
+
const outputCheck = harness.security.checkToolOutput(truncateForOutputScan(toolOutputScanText(partial.content)));
|
|
521
|
+
if (!outputCheck.isClean)
|
|
522
|
+
return;
|
|
523
|
+
}
|
|
524
|
+
config.onToolUpdate({
|
|
525
|
+
toolCall: params.toolCall,
|
|
526
|
+
partial: {
|
|
527
|
+
...partial,
|
|
528
|
+
content: typeof partial.content === 'string'
|
|
529
|
+
? capPartialTail(partial.content)
|
|
530
|
+
: partial.content,
|
|
531
|
+
},
|
|
532
|
+
});
|
|
533
|
+
}
|
|
534
|
+
: undefined,
|
|
395
535
|
// onTurnComplete:可靠性副作用(注入 steer 指令,不控制停止)
|
|
396
536
|
onTurnComplete: async (ctx) => {
|
|
397
537
|
// 一轮成功走到这里:重置模型错误 attempt
|
|
@@ -658,27 +798,23 @@ export async function* runAgentWithReliability(context, config, harness, signal)
|
|
|
658
798
|
if (harness.errorStrategy) {
|
|
659
799
|
const action = harness.errorStrategy.onModelError(classified, attempt);
|
|
660
800
|
if (action.action === 'retry') {
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
801
|
+
const delayMs = action.delayMs ?? 0;
|
|
802
|
+
// maxAttempts 取「本次实际允许的重试次数」;自定义 strategy 对表外原因也重试时,
|
|
803
|
+
// 至少报 1(而不是 0),避免 UI 显示「第 1 次 / 共 0 次」
|
|
804
|
+
pushRetryNotice(state, classified, attempt, delayMs, Math.max(1, maxAttemptsFor(classified.reason)));
|
|
664
805
|
return 'retry';
|
|
665
806
|
}
|
|
666
807
|
return 'abort';
|
|
667
808
|
}
|
|
668
|
-
//
|
|
669
|
-
// network 含对端断连(undici terminated / socket hang up
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
await new Promise(resolve => setTimeout(resolve, delayMs));
|
|
678
|
-
}
|
|
679
|
-
return 'retry';
|
|
680
|
-
}
|
|
681
|
-
return 'abort';
|
|
809
|
+
// 默认:按错误原因分级重试(次数上限见 MODEL_ERROR_MAX_ATTEMPTS)
|
|
810
|
+
// network 含对端断连(undici terminated / socket hang up),重试常可自愈;
|
|
811
|
+
// timeout 只给 1 次——一次失败已经耗掉整个 watchdog 窗口(流 300s + 同步兜底 300s),
|
|
812
|
+
// 原样再来 3 轮正是 2026-10-27 那次 52 分钟黑屏的成因。
|
|
813
|
+
const maxAttempts = maxAttemptsFor(classified.reason);
|
|
814
|
+
if (attempt < maxAttempts) {
|
|
815
|
+
const delayMs = classified.retryAfterMs ?? (attempt + 1) * 1000;
|
|
816
|
+
pushRetryNotice(state, classified, attempt, delayMs, maxAttempts);
|
|
817
|
+
return 'retry';
|
|
682
818
|
}
|
|
683
819
|
return 'abort';
|
|
684
820
|
},
|
|
@@ -690,6 +826,18 @@ export async function* runAgentWithReliability(context, config, harness, signal)
|
|
|
690
826
|
const sec = state.pendingSecurityEvents.shift();
|
|
691
827
|
yield sec;
|
|
692
828
|
}
|
|
829
|
+
// 模型重试通知(onError 入队,此处推出:重试窗口必须对用户可见)
|
|
830
|
+
while (state.pendingModelRetryEvents.length > 0) {
|
|
831
|
+
const retry = state.pendingModelRetryEvents.shift();
|
|
832
|
+
yield retry;
|
|
833
|
+
}
|
|
834
|
+
// 退避等待放在通知 yield 之后:消费方已看到「即将重试 + 等多久」,
|
|
835
|
+
// 而 agentLoop 此刻挂在 turn_end 之后未继续,下一次调用不会提前发起。
|
|
836
|
+
if (state.pendingRetryDelayMs > 0) {
|
|
837
|
+
const waitMs = state.pendingRetryDelayMs;
|
|
838
|
+
state.pendingRetryDelayMs = 0;
|
|
839
|
+
await sleepUnlessAborted(waitMs, signal);
|
|
840
|
+
}
|
|
693
841
|
// Observer:run 结束前附带 RunMetricsCollector 快照(P1 Guard 面板)
|
|
694
842
|
if (event.type === 'agent_end') {
|
|
695
843
|
const scope = getRunScope();
|
|
@@ -1026,3 +1174,53 @@ function executeRecoveryActions(actions, messages) {
|
|
|
1026
1174
|
}
|
|
1027
1175
|
}
|
|
1028
1176
|
}
|
|
1177
|
+
/**
|
|
1178
|
+
* 工具输出扫描文本:字符串直扫;结构化结果序列化后扫(防 MCP/对象结果绕过)。
|
|
1179
|
+
*
|
|
1180
|
+
* @param content - 工具输出内容
|
|
1181
|
+
* @returns 扫描文本
|
|
1182
|
+
*/
|
|
1183
|
+
function toolOutputScanText(content) {
|
|
1184
|
+
if (typeof content === 'string')
|
|
1185
|
+
return content;
|
|
1186
|
+
try {
|
|
1187
|
+
return JSON.stringify(content);
|
|
1188
|
+
}
|
|
1189
|
+
catch {
|
|
1190
|
+
return String(content);
|
|
1191
|
+
}
|
|
1192
|
+
}
|
|
1193
|
+
/**
|
|
1194
|
+
* 超大 payload 截断扫描,避免序列化字符串拖垮 checkToolOutput。
|
|
1195
|
+
*
|
|
1196
|
+
* @param text - 扫描文本
|
|
1197
|
+
* @returns 截断后的扫描文本(前 100k)
|
|
1198
|
+
*/
|
|
1199
|
+
function truncateForOutputScan(text) {
|
|
1200
|
+
return text.length > 100_000 ? text.slice(0, 100_000) : text;
|
|
1201
|
+
}
|
|
1202
|
+
/**
|
|
1203
|
+
* 最重违规(afterToolCall 与部分输出扣发共用同一裁决口径)。
|
|
1204
|
+
*
|
|
1205
|
+
* @param violations - 违规列表(非空;调用方已判 isClean=false)
|
|
1206
|
+
* @returns 最重违规
|
|
1207
|
+
*/
|
|
1208
|
+
function worstOutputViolation(violations) {
|
|
1209
|
+
const order = {
|
|
1210
|
+
critical: 4,
|
|
1211
|
+
high: 3,
|
|
1212
|
+
medium: 2,
|
|
1213
|
+
low: 1,
|
|
1214
|
+
};
|
|
1215
|
+
return violations.reduce((worst, v) => (order[v.severity] > order[worst.severity] ? v : worst), violations[0]);
|
|
1216
|
+
}
|
|
1217
|
+
/**
|
|
1218
|
+
* 部分输出载荷截断(保留尾部 4KB:流式输出的最新片段才有展示价值)。
|
|
1219
|
+
*
|
|
1220
|
+
* @param text - 部分输出文本
|
|
1221
|
+
* @param maxChars - 上限(缺省 4096)
|
|
1222
|
+
* @returns 尾部截断结果
|
|
1223
|
+
*/
|
|
1224
|
+
function capPartialTail(text, maxChars = 4096) {
|
|
1225
|
+
return text.length > maxChars ? text.slice(text.length - maxChars) : text;
|
|
1226
|
+
}
|
|
@@ -366,10 +366,10 @@ ${summaryText}${taskLine}${recoveryLine}${signalsLine}
|
|
|
366
366
|
|
|
367
367
|
只回复一个词(OK/CONCERN/STOP),如果需要可以加冒号说明原因。`;
|
|
368
368
|
try {
|
|
369
|
+
// 不指定温度:由模型配置(ModelInfo.temperature)或服务端默认决定
|
|
369
370
|
const response = await this.model.chat({
|
|
370
371
|
messages: [{ role: 'user', content: prompt }],
|
|
371
372
|
model: this.config.llmModel || undefined,
|
|
372
|
-
temperature: 0,
|
|
373
373
|
});
|
|
374
374
|
const text = response.content.trim().toUpperCase();
|
|
375
375
|
if (text.startsWith('STOP')) {
|
|
@@ -36,14 +36,45 @@ export interface RunToolRuntime {
|
|
|
36
36
|
requireCredentialBindings?: boolean;
|
|
37
37
|
/** D7 require jail */
|
|
38
38
|
requireJail?: boolean;
|
|
39
|
+
/** 授权无笼(effectPolicy.jail=none):跳过 jail 包裹,注记 disabled_by_config */
|
|
40
|
+
disableJail?: boolean;
|
|
39
41
|
/** jail $HOME write (project/host) */
|
|
40
42
|
homeWrite?: boolean;
|
|
41
43
|
/** Run-level securityDegraded hook */
|
|
42
44
|
noteSecurityDegraded?: (reason: string) => void;
|
|
45
|
+
/** ops 审计回传(ops P2):动作/越权写入 → 统一审计账本 */
|
|
46
|
+
recordOpsEvent?: (record: {
|
|
47
|
+
event: string;
|
|
48
|
+
data: Record<string, unknown>;
|
|
49
|
+
}) => void;
|
|
43
50
|
/** L2 级别 */
|
|
44
51
|
pathContainment?: "strict" | "soft" | "none";
|
|
45
52
|
confirmEffect?: import("@octopi-agent/core/types/tools.js").ToolExecutionContext["confirmEffect"];
|
|
46
53
|
effectChannel?: "engine" | "host-gate";
|
|
54
|
+
/** 提权策略(ops P3/P4,resolved):priv_exec 匹配面(allowlist 全等 / full 全量) */
|
|
55
|
+
escalation?: {
|
|
56
|
+
policy: "none" | "allowlist" | "full";
|
|
57
|
+
via: "sudo" | "direct";
|
|
58
|
+
allow: Array<{
|
|
59
|
+
cmd: string;
|
|
60
|
+
args?: string[];
|
|
61
|
+
confirm?: boolean;
|
|
62
|
+
}>;
|
|
63
|
+
};
|
|
64
|
+
/** 危险命令减速带 resolved(§6):full 档 pre-exec 闸 + 确认超时(超时一律 deny) */
|
|
65
|
+
dangerousCommands?: {
|
|
66
|
+
policy: "confirm" | "deny" | "off";
|
|
67
|
+
timeoutMs: number;
|
|
68
|
+
};
|
|
69
|
+
/** 会话参与者身份(SEC-2 / ops P5):提权审计 requester 入账 */
|
|
70
|
+
sessionParticipants?: Array<{
|
|
71
|
+
agentId: string;
|
|
72
|
+
roleId: string;
|
|
73
|
+
}>;
|
|
74
|
+
/** kill switch 哨兵路径(ops P5):beforeToolCall 逐工具闸的检查面 */
|
|
75
|
+
killSwitchPaths?: string[];
|
|
76
|
+
/** 特权部署标记(§5 P4/§8.1):jail=none / full 档 / root 进程——UI 常驻 `PRIVILEGED` 数据源 */
|
|
77
|
+
privileged?: boolean;
|
|
47
78
|
/** L1 processLimits(false = 不强制 timeoutMs 看门狗) */
|
|
48
79
|
processLimits?: boolean;
|
|
49
80
|
/** shell 工具策略(gateEffect;deny=拒绝 shell) */
|
|
@@ -19,6 +19,7 @@ import type { Agent } from './agent/index.js';
|
|
|
19
19
|
import type { HarnessLoopEvent } from './reliability/harness-events.js';
|
|
20
20
|
import type { ReliabilityHarness } from './reliability/run-agent.js';
|
|
21
21
|
import type { SessionTaskService } from '../session/tasks/service.js';
|
|
22
|
+
import type { SessionInboxEntry, SessionInboxBinding } from '../activation/inbox.js';
|
|
22
23
|
import { type ToolIsolationMode } from '../extension/execution-environment/isolation.js';
|
|
23
24
|
import { type SessionLease } from './concurrency/session-lease.js';
|
|
24
25
|
/** 运行器配置 */
|
|
@@ -60,6 +61,31 @@ export interface SessionAwareRunnerConfig {
|
|
|
60
61
|
modelRef?: string;
|
|
61
62
|
defaultProvider?: string;
|
|
62
63
|
}) => import('./model/types.js').ResolvedModel | null;
|
|
64
|
+
/**
|
|
65
|
+
* ops 审计账本路径(ops P2);缺省 `<OCTOPI_HOME>/audit/ops.<agentId>.jsonl`。
|
|
66
|
+
* 与 effectPolicy.opsAuditPath 同义;effectPolicy 优先。
|
|
67
|
+
*/
|
|
68
|
+
opsAuditPath?: string;
|
|
69
|
+
/**
|
|
70
|
+
* 审计外送收口路径(ops P5);与 effectPolicy.opsAuditExportPath 同义,effectPolicy 优先。
|
|
71
|
+
* 宿主侧、agent 不可写面;缺省不外送。
|
|
72
|
+
*/
|
|
73
|
+
opsAuditExportPath?: string;
|
|
74
|
+
/**
|
|
75
|
+
* kill switch 哨兵覆盖(ops P5);缺省 `<OCTOPI_HOME>/agents/<agentId>/KILL`。
|
|
76
|
+
* 文件存在 = 停止该 agent 全部执行(run 准入 + 逐工具闸),宿主 `octopi ops kill` 写入。
|
|
77
|
+
*/
|
|
78
|
+
killSwitchPath?: string;
|
|
79
|
+
/**
|
|
80
|
+
* 安全配置漂移守卫(ops P2 §4.3/§8.4 拍板:漂移拒新 run)。
|
|
81
|
+
* 宿主注入(通常 `createFileSecurityIntegrity`);未注入 = 无守卫(库嵌入自担)。
|
|
82
|
+
*/
|
|
83
|
+
securityIntegrity?: {
|
|
84
|
+
/** 启动期锚定的安全字段指纹(审计记录的「旧摘要」) */
|
|
85
|
+
fingerprint: string;
|
|
86
|
+
/** 复核当前安全配置(宿主实现,通常重读配置文件) */
|
|
87
|
+
recheck: () => import('../agent/config-integrity.js').SecurityConfigDrift | Promise<import('../agent/config-integrity.js').SecurityConfigDrift>;
|
|
88
|
+
};
|
|
63
89
|
/**
|
|
64
90
|
* 工具效应隔离策略(宪法 I5)
|
|
65
91
|
*
|
|
@@ -120,6 +146,12 @@ export interface SessionAwareRunnerConfig {
|
|
|
120
146
|
agentId: string;
|
|
121
147
|
}) => void;
|
|
122
148
|
}
|
|
149
|
+
/**
|
|
150
|
+
* 失败凭证消息中附带残句的截断上限(显示用途;完整残句在带 error 标记的 turn 账本)
|
|
151
|
+
*
|
|
152
|
+
* 展示型截断,与 wire-dump 的消息截断同性质——不是部署可变参数,故不进配置。
|
|
153
|
+
*/
|
|
154
|
+
export declare const LLM_ERROR_PARTIAL_MAX_CHARS = 2000;
|
|
123
155
|
export interface RunConfig {
|
|
124
156
|
systemPrompt: string;
|
|
125
157
|
agentId?: string;
|
|
@@ -169,6 +201,16 @@ export declare function adaptLoopEvent(event: HarnessLoopEvent, meta: {
|
|
|
169
201
|
sessionId: string;
|
|
170
202
|
}, state: {
|
|
171
203
|
assistantContent: string;
|
|
204
|
+
/**
|
|
205
|
+
* 本次 LLM 调用(自上次 turn_end 起)流出的部分文本。
|
|
206
|
+
* 失败轮的正文只能来自这里——不得回落到上一次调用的完整回复冒充本次输出。
|
|
207
|
+
*/
|
|
208
|
+
callStreamedContent?: string;
|
|
209
|
+
/** 最近一次 turn_end 的正文快照与错误标记,供 runner 落 turn 账本 */
|
|
210
|
+
lastTurnContent?: string;
|
|
211
|
+
lastTurnError?: boolean;
|
|
212
|
+
/** `agent_end.reason='error'` 时的错误文本,收口落失败凭证 */
|
|
213
|
+
errorMessage?: string;
|
|
172
214
|
lastUserContent?: string;
|
|
173
215
|
stopReason?: string;
|
|
174
216
|
/** 引擎为何终止(人类可读);收口落一条 runStopped 消息,禁止静默停止 */
|
|
@@ -194,9 +236,32 @@ export declare class SessionAwareRunner {
|
|
|
194
236
|
/** Effective effectPolicy.mode (for Runtime injection / UI) */
|
|
195
237
|
private effectMode;
|
|
196
238
|
private effectCommitManual;
|
|
239
|
+
/** store 缺 syncMessages 通道时只 warn 一次 */
|
|
240
|
+
private warnedMissingSync;
|
|
197
241
|
private effectProcessLimits;
|
|
198
242
|
private effectNetwork;
|
|
199
243
|
private effectRequireJail;
|
|
244
|
+
/** ops P0:jail 意图(auto/require/none)——none=授权无笼 */
|
|
245
|
+
private effectJail;
|
|
246
|
+
/** ops P2:审计账本开关(effectPolicy.opsAudit;未解析时回落配置缺省 on) */
|
|
247
|
+
/** ops P3:提权策略(resolved;priv_exec 全等匹配面) */
|
|
248
|
+
private effectEscalation?;
|
|
249
|
+
/** ops P4:危险命令减速带 resolved(§6;full 档 pre-exec 闸 + 确认超时) */
|
|
250
|
+
private effectDangerousCommands?;
|
|
251
|
+
/** ops P4:特权部署标记(jail=none / full 档 / root 进程)——UI 常驻 PRIVILEGED 数据源 */
|
|
252
|
+
private effectPrivileged;
|
|
253
|
+
/** ops P5:kill switch 哨兵路径(run 准入已查;逐工具闸复用同面) */
|
|
254
|
+
private killSwitchPaths;
|
|
255
|
+
/** ops P2:审计账本开关(effectPolicy.opsAudit;未解析时回落配置缺省 on) */
|
|
256
|
+
private effectOpsAudit;
|
|
257
|
+
/** ops P2:hash 链审计账本(懒建;写失败降级申报,不吞) */
|
|
258
|
+
private opsJournal?;
|
|
259
|
+
/** ops P5:审计外送收口(宿主侧见证副本;未配置则不外送) */
|
|
260
|
+
private opsExporter?;
|
|
261
|
+
/** ops P2:账本缺省文件名的 agent 锚(每 runner 单 agent;handle 起点锚定) */
|
|
262
|
+
private opsAuditAgentId?;
|
|
263
|
+
/** ops P2:审计事件的 session 归属(写失败申报等无 run 载荷时用) */
|
|
264
|
+
private opsAuditSessionId?;
|
|
200
265
|
private effectRequireCredentialBindings;
|
|
201
266
|
private effectHomeWrite;
|
|
202
267
|
private effectShellEscape;
|
|
@@ -236,6 +301,23 @@ export declare class SessionAwareRunner {
|
|
|
236
301
|
constructor(agent: Agent, harness: ReliabilityHarness, store: TypedSessionStore, config?: SessionAwareRunnerConfig & {
|
|
237
302
|
events?: import('@octopi-agent/core/primitives/event-bus.js').EventBus;
|
|
238
303
|
});
|
|
304
|
+
/**
|
|
305
|
+
* ops 审计记账(ops P2):写 hash 链账本。
|
|
306
|
+
*
|
|
307
|
+
* `opsAudit: off` 时整体静默(宿主的显式选择);写失败降级为 securityDegraded
|
|
308
|
+
* 申报——P2 不 fail-closed 业务(与 §5.6 记账同策略),P3 提权通道再收紧为硬前置。
|
|
309
|
+
*
|
|
310
|
+
* @param event - §7 事件词表
|
|
311
|
+
* @param data - 事件载荷(hash 走 canonicalJson,键序无关)
|
|
312
|
+
*/
|
|
313
|
+
private recordOpsAudit;
|
|
314
|
+
/** 外送收口(懒建;仅配置了宿主侧收口路径时启用) */
|
|
315
|
+
private resolveOpsExporter;
|
|
316
|
+
/**
|
|
317
|
+
* 审计链路降级申报(写失败/外送失败)。
|
|
318
|
+
* 双通道:harness 字段会被下一次 run 起点重置抹掉,必须同时发在线事件(评审实证)。
|
|
319
|
+
*/
|
|
320
|
+
private noteOpsDegradation;
|
|
239
321
|
/**
|
|
240
322
|
* 注入 Observer Hub(Gateway / 测试用)
|
|
241
323
|
*
|
|
@@ -276,6 +358,9 @@ export declare class SessionAwareRunner {
|
|
|
276
358
|
dispose(): void;
|
|
277
359
|
/** 设置工具运行时上下文提供者 */
|
|
278
360
|
setToolContextProvider(provider: ToolContextProvider): void;
|
|
361
|
+
private steeringProvider?;
|
|
362
|
+
/** 注册一个运行期提示源(只进 steering 接缝);单槽,后注册者覆盖前注册者。 */
|
|
363
|
+
setSteeringProvider(provider: (() => Promise<Message[]>) | undefined): void;
|
|
279
364
|
/**
|
|
280
365
|
* 设置 persona 解析器
|
|
281
366
|
*
|
|
@@ -337,6 +422,9 @@ export declare class SessionAwareRunner {
|
|
|
337
422
|
tokens: number;
|
|
338
423
|
text?: string;
|
|
339
424
|
}>): void;
|
|
425
|
+
/** 通知委派服务:结果已真正写入父上下文,而非仅仅发进事件总线。 */
|
|
426
|
+
setDelegationDeliveryAck(ack: ((delegationId: string) => void) | undefined): void;
|
|
427
|
+
private delegationDeliveryAck?;
|
|
340
428
|
/**
|
|
341
429
|
* 处理一条消息
|
|
342
430
|
*
|
|
@@ -346,7 +434,7 @@ export declare class SessionAwareRunner {
|
|
|
346
434
|
* @param signal - 中止信号
|
|
347
435
|
* @yields AgentEvent 事件流(向后兼容格式)
|
|
348
436
|
*/
|
|
349
|
-
handle(sessionId: string, input: Message, runConfig: RunConfig, signal?: AbortSignal): AsyncGenerator<import('@octopi-agent/core/primitives/event-bus.js').AgentEvent>;
|
|
437
|
+
handle(sessionId: string, input: Message, runConfig: RunConfig, signal?: AbortSignal, inboxBinding?: SessionInboxBinding, initialInboxEntry?: SessionInboxEntry): AsyncGenerator<import('@octopi-agent/core/primitives/event-bus.js').AgentEvent>;
|
|
350
438
|
/**
|
|
351
439
|
* Session compact under the same session lock as handle (E1/E4).
|
|
352
440
|
*
|
|
@@ -368,6 +456,8 @@ export declare class SessionAwareRunner {
|
|
|
368
456
|
maxTokens?: number;
|
|
369
457
|
}) => Promise<string>;
|
|
370
458
|
compactTargetTokens?: number;
|
|
459
|
+
/** task 快照:交接式摘要指令尾部注入 */
|
|
460
|
+
taskSnapshot?: string;
|
|
371
461
|
}) => Promise<{
|
|
372
462
|
ok: boolean;
|
|
373
463
|
compacted: boolean;
|
|
@@ -424,8 +514,48 @@ export declare class SessionAwareRunner {
|
|
|
424
514
|
* @throws 若已定形(禁止二次改写)
|
|
425
515
|
*/
|
|
426
516
|
private bakeTurnStart;
|
|
427
|
-
/**
|
|
517
|
+
/** 构造 turn 闭标消息(write-once 由调用处重复检查保证) */
|
|
518
|
+
private makeTurnEndMessage;
|
|
519
|
+
/**
|
|
520
|
+
* 追加 turn 闭标(幂等收养,按信封区间判形)。
|
|
521
|
+
*
|
|
522
|
+
* turn_end 是状态标记(turn 已闭)而非事件:崩溃续跑时 ensurePreviousTurnClosed
|
|
523
|
+
* 会为上一个未闭信封补写闭标(它是第二处闭标写者,规则相近),同 id 的历史闭标
|
|
524
|
+
* 不算「本信封已闭」——只有本信封区间(最后一个同 id turn_start 之后)已存在
|
|
525
|
+
* 闭标才跳过。曾经的全局 write-once throw 把良性重复升级成 run error
|
|
526
|
+
* (loop 已 completed 仍被中止,2026-10-28 事故)。
|
|
527
|
+
*
|
|
528
|
+
* 边界:找不到同 id turn_start(lastStartIdx=-1,如 abort-before-bake)时按
|
|
529
|
+
* 「全序列已有一枚闭标即收养」处理——不动消息数组,交由下一轮修复器收敛。
|
|
530
|
+
*
|
|
531
|
+
* @param messages - 会话消息序列(append-only)
|
|
532
|
+
* @param turnId - 本 turn id
|
|
533
|
+
*/
|
|
428
534
|
private appendTurnEnd;
|
|
535
|
+
/**
|
|
536
|
+
* 尽力持久化 turnSeq 计数器(缺 updateMetadata 的 store 跳过,收尾整包 save 兜底)。
|
|
537
|
+
*
|
|
538
|
+
* 失败不中断 Run(幂等收养已兜住 id 复用的硬失败),但必须留痕:
|
|
539
|
+
* 2026-10-28 事故的事后诊断正困于「计数器丢失」无任何日志。
|
|
540
|
+
*
|
|
541
|
+
* @param sessionId - 会话 id
|
|
542
|
+
* @param turnSeq - 已分配的最新序号
|
|
543
|
+
*/
|
|
544
|
+
private persistTurnSeq;
|
|
545
|
+
/**
|
|
546
|
+
* Run 进行中转录增量落盘:把 durable 口径的历史对齐到存储。
|
|
547
|
+
*
|
|
548
|
+
* 口径与收尾合并一致(ephemeral 运行期消息不落历史);调用方契约:
|
|
549
|
+
* turn_start 定形之后才可同步(bake 原地改写 user 消息)。尽力而为——
|
|
550
|
+
* 失败不中断 Run(收尾整包 save 是权威写),store 无 syncMessages 时跳过。
|
|
551
|
+
*
|
|
552
|
+
* @param sessionId - 会话 id
|
|
553
|
+
* @param agentId - 本 Run 身份(assistant/tool 归因,首次同步前补齐)
|
|
554
|
+
* @param keptPrefix - 上下文租约点之前的 Discourse 前缀(与收尾 keptPrefix 同源)
|
|
555
|
+
* @param runMessages - 本 Run 视图消息(含 ephemeral,此处过滤)
|
|
556
|
+
* @returns 是否成功对齐(false 时调用方不得推进已同步计数,待下个事件重试)
|
|
557
|
+
*/
|
|
558
|
+
private persistRunMessages;
|
|
429
559
|
/** 旧路径:persona + injectedContext 字符串拼接;结果返回给 runContext,不写共享 Agent */
|
|
430
560
|
private concatSystemPrompt;
|
|
431
561
|
/**
|