@octopi-agent/engine 0.98.4 → 0.102.10
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 +35 -5
- package/dist/config-schema/agent.js +24 -4
- package/dist/config-schema/context.d.ts +6 -36
- package/dist/config-schema/context.js +4 -28
- package/dist/config-schema/engine.d.ts +57 -160
- package/dist/config-schema/engine.js +1 -5
- package/dist/config-schema/governance.d.ts +8 -1
- package/dist/config-schema/governance.js +8 -1
- package/dist/config-schema/models.d.ts +2 -8
- package/dist/config-schema/models.js +0 -2
- package/dist/config-schema/run.d.ts +2 -2
- package/dist/config-schema/run.js +2 -2
- package/dist/config-schema/shared.d.ts +0 -3
- package/dist/config-schema/shared.js +0 -2
- package/dist/config-schema/substrate.d.ts +14 -88
- package/dist/config-schema/substrate.js +22 -107
- package/dist/config.d.ts +45 -113
- package/dist/config.js +8 -2
- package/dist/harness/activation/dispatcher.js +7 -0
- package/dist/harness/activation/inbox.d.ts +3 -3
- package/dist/harness/activation/inbox.js +3 -3
- package/dist/harness/activation/runtime.js +13 -5
- package/dist/harness/activation/types.d.ts +2 -2
- package/dist/harness/agent/builder.d.ts +24 -3
- package/dist/harness/agent/builder.js +131 -27
- package/dist/harness/agent/config-bridge.js +9 -2
- package/dist/harness/agent/config-integrity.js +19 -2
- package/dist/harness/agent/wire-agent-builder.d.ts +11 -3
- package/dist/harness/agent/wire-agent-builder.js +26 -7
- package/dist/harness/capabilities/document/factory.d.ts +5 -0
- package/dist/harness/capabilities/document/factory.js +1 -0
- package/dist/harness/capabilities/document/port.js +6 -3
- package/dist/harness/capabilities/document/types.d.ts +5 -0
- package/dist/harness/collaboration/autonomous-subsystem/loader.js +1 -1
- package/dist/harness/collaboration/autonomous-subsystem/sense/engine.d.ts +1 -1
- package/dist/harness/collaboration/autonomous-subsystem/sense/engine.js +2 -2
- package/dist/harness/collaboration/autonomous-subsystem/sense/input-builder.js +4 -4
- package/dist/harness/collaboration/autonomous-subsystem/sense/metrics.d.ts +2 -2
- package/dist/harness/collaboration/autonomous-subsystem/sense/metrics.js +2 -2
- package/dist/harness/collaboration/autonomous-subsystem/signal/bus.d.ts +6 -0
- package/dist/harness/collaboration/autonomous-subsystem/signal/bus.js +25 -4
- package/dist/harness/collaboration/autonomous-subsystem/think/executor.js +1 -1
- package/dist/harness/collaboration/autonomous-subsystem/types.d.ts +3 -3
- package/dist/harness/collaboration/delegation/child-run.d.ts +1 -1
- package/dist/harness/collaboration/delegation/child-run.js +4 -4
- package/dist/harness/collaboration/delegation/index.d.ts +1 -1
- package/dist/harness/collaboration/delegation/index.js +1 -1
- package/dist/harness/collaboration/delegation/notifier.d.ts +6 -1
- package/dist/harness/collaboration/delegation/notifier.js +8 -1
- package/dist/harness/collaboration/delegation/service.d.ts +2 -0
- package/dist/harness/collaboration/delegation/service.js +2 -1
- package/dist/harness/collaboration/delegation/store.d.ts +2 -0
- package/dist/harness/collaboration/delegation/store.js +2 -1
- package/dist/harness/collaboration/delegation/types.d.ts +23 -2
- package/dist/harness/collaboration/delegation/types.js +22 -0
- package/dist/harness/collaboration/delegation/wiring.js +11 -1
- package/dist/harness/context/budget-allocator.d.ts +26 -18
- package/dist/harness/context/budget-allocator.js +67 -32
- package/dist/harness/context/capabilities/compact/engine.d.ts +0 -6
- package/dist/harness/context/capabilities/compact/engine.js +169 -121
- package/dist/harness/context/capabilities/compact/handover.d.ts +5 -3
- package/dist/harness/context/capabilities/compact/handover.js +7 -5
- package/dist/harness/context/capabilities/compact/index.d.ts +5 -1
- package/dist/harness/context/capabilities/compact/index.js +4 -0
- package/dist/harness/context/capabilities/compact/mechanical.d.ts +130 -0
- package/dist/harness/context/capabilities/compact/mechanical.js +268 -0
- package/dist/harness/context/capabilities/compact/messages.d.ts +60 -0
- package/dist/harness/context/capabilities/compact/messages.js +91 -0
- package/dist/harness/context/capabilities/compact/types.d.ts +76 -11
- package/dist/harness/context/capabilities/compact/types.js +11 -1
- package/dist/harness/context/capabilities/compact/view-split.d.ts +36 -0
- package/dist/harness/context/capabilities/compact/view-split.js +72 -0
- package/dist/harness/context/capabilities/summary/port.js +0 -1
- package/dist/harness/context/capabilities/summary/resolver.d.ts +1 -1
- package/dist/harness/context/capabilities/summary/resolver.js +1 -6
- package/dist/harness/context/capabilities/summary/tool-binding.d.ts +1 -1
- package/dist/harness/context/capabilities/summary/types.d.ts +3 -6
- package/dist/harness/context/context-size-ledger.d.ts +143 -0
- package/dist/harness/context/context-size-ledger.js +236 -0
- package/dist/harness/context/default-context-engine.d.ts +195 -119
- package/dist/harness/context/default-context-engine.js +1241 -743
- package/dist/harness/context/index.d.ts +2 -2
- package/dist/harness/context/index.js +1 -1
- package/dist/harness/context/layer-types.d.ts +15 -0
- package/dist/harness/context/layer-types.js +14 -1
- package/dist/harness/context/layers.d.ts +14 -15
- package/dist/harness/context/layers.js +41 -11
- package/dist/harness/context/message-selector.d.ts +10 -8
- package/dist/harness/context/message-selector.js +49 -27
- package/dist/harness/context/summarize.d.ts +2 -2
- package/dist/harness/context/summarize.js +9 -2
- package/dist/harness/context/system-prompt-assembler.d.ts +2 -0
- package/dist/harness/context/system-prompt-assembler.js +2 -1
- package/dist/harness/context/token-constants.d.ts +8 -6
- package/dist/harness/context/token-constants.js +8 -7
- package/dist/harness/context/token-estimate-fns.d.ts +37 -27
- package/dist/harness/context/token-estimate-fns.js +85 -66
- package/dist/harness/context/token-estimator.d.ts +27 -12
- package/dist/harness/context/token-estimator.js +120 -66
- package/dist/harness/context/token-segments.d.ts +88 -0
- package/dist/harness/context/token-segments.js +103 -0
- package/dist/harness/context/tool-result-aging.d.ts +6 -1
- package/dist/harness/context/tool-result-aging.js +16 -5
- package/dist/harness/context/tool-result-body.js +2 -0
- package/dist/harness/context/transform/anchors.d.ts +66 -0
- package/dist/harness/context/transform/anchors.js +125 -0
- package/dist/harness/context/transform/fold.d.ts +56 -0
- package/dist/harness/context/transform/fold.js +135 -0
- package/dist/harness/context/transform/migrate.d.ts +41 -0
- package/dist/harness/context/transform/migrate.js +69 -0
- package/dist/harness/context/transform/types.d.ts +129 -0
- package/dist/harness/context/transform/types.js +19 -0
- package/dist/harness/context/turn-envelope.d.ts +6 -3
- package/dist/harness/context/types.d.ts +127 -117
- package/dist/harness/extension/execution-environment/ops-audit.d.ts +1 -1
- package/dist/harness/extension/execution-environment/resource-limits.d.ts +1 -1
- package/dist/harness/extension/execution-environment/resource-limits.js +1 -1
- package/dist/harness/extension/plugin-ecosystem/channel-types.d.ts +1 -1
- package/dist/harness/extension/plugin-ecosystem/commands/index.d.ts +3 -1
- package/dist/harness/extension/plugin-ecosystem/commands/index.js +1 -0
- package/dist/harness/extension/plugin-ecosystem/commands/plugin-bridge.d.ts +12 -1
- package/dist/harness/extension/plugin-ecosystem/commands/plugin-bridge.js +14 -4
- package/dist/harness/extension/plugin-ecosystem/commands/router.d.ts +5 -4
- package/dist/harness/extension/plugin-ecosystem/commands/router.js +23 -14
- package/dist/harness/extension/plugin-ecosystem/commands/types.d.ts +8 -1
- package/dist/harness/extension/plugin-ecosystem/commands/types.js +2 -1
- package/dist/harness/extension/plugin-ecosystem/hooks/adapter.d.ts +54 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/adapter.js +397 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/compaction-integration.d.ts +16 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/compaction-integration.js +66 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/index.d.ts +4 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/index.js +2 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/iteration-snapshot.d.ts +11 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/iteration-snapshot.js +54 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/journal.d.ts +9 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/journal.js +22 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/policy-error.d.ts +12 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/policy-error.js +19 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/run-integration.d.ts +36 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/run-integration.js +338 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/services.d.ts +24 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/services.js +139 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/types.d.ts +229 -0
- package/dist/harness/extension/plugin-ecosystem/hooks/types.js +1 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/api.d.ts +83 -249
- package/dist/harness/extension/plugin-ecosystem/plugins/api.js +88 -214
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-registry.d.ts +43 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-registry.js +61 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/engine-compatibility.d.ts +4 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/engine-compatibility.js +18 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/entry.d.ts +7 -85
- package/dist/harness/extension/plugin-ecosystem/plugins/entry.js +8 -50
- package/dist/harness/extension/plugin-ecosystem/plugins/index.d.ts +6 -23
- package/dist/harness/extension/plugin-ecosystem/plugins/index.js +3 -23
- package/dist/harness/extension/plugin-ecosystem/plugins/loader.d.ts +50 -117
- package/dist/harness/extension/plugin-ecosystem/plugins/loader.js +316 -285
- package/dist/harness/extension/plugin-ecosystem/plugins/manager.d.ts +23 -490
- package/dist/harness/extension/plugin-ecosystem/plugins/manager.js +85 -353
- package/dist/harness/extension/plugin-ecosystem/plugins/manifest.d.ts +41 -223
- package/dist/harness/extension/plugin-ecosystem/plugins/manifest.js +138 -19
- package/dist/harness/extension/plugin-ecosystem/plugins/staging.d.ts +15 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/staging.js +15 -0
- package/dist/harness/extension/plugin-ecosystem/skills/manager.d.ts +6 -1
- package/dist/harness/extension/plugin-ecosystem/skills/manager.js +17 -1
- package/dist/harness/extension/plugin-ecosystem/tools/ask-user.d.ts +3 -0
- package/dist/harness/extension/plugin-ecosystem/tools/ask-user.js +46 -21
- package/dist/harness/extension/plugin-ecosystem/tools/delegation.js +18 -8
- package/dist/harness/extension/plugin-ecosystem/tools/plugin-tool.d.ts +11 -0
- package/dist/harness/extension/plugin-ecosystem/tools/plugin-tool.js +39 -0
- package/dist/harness/extension/plugin-ecosystem/tools/tool-bus.d.ts +1 -1
- package/dist/harness/extension/plugin-ecosystem/tools/tool-bus.js +11 -2
- package/dist/harness/governance/accounting/usage-ledger.d.ts +13 -1
- package/dist/harness/governance/accounting/usage-ledger.js +23 -1
- package/dist/harness/governance/human-in-the-loop/decision-cache.d.ts +3 -3
- package/dist/harness/governance/human-in-the-loop/decision-cache.js +2 -2
- package/dist/harness/governance/security/capability-enforcer.js +1 -2
- package/dist/harness/index.d.ts +12 -12
- package/dist/harness/index.js +7 -7
- package/dist/harness/knowledge/boot-config.d.ts +55 -0
- package/dist/harness/knowledge/boot-config.js +50 -0
- package/dist/harness/knowledge/catalog-types.d.ts +2 -0
- package/dist/harness/knowledge/client.d.ts +24 -2
- package/dist/harness/knowledge/client.js +19 -5
- package/dist/harness/knowledge/db.js +5 -0
- package/dist/harness/knowledge/describe-sample.d.ts +23 -0
- package/dist/harness/knowledge/describe-sample.js +58 -0
- package/dist/harness/knowledge/describe.d.ts +8 -0
- package/dist/harness/knowledge/describe.js +18 -2
- package/dist/harness/knowledge/engine-thread.js +6 -0
- package/dist/harness/knowledge/grounding.js +3 -1
- package/dist/harness/knowledge/http-app.js +35 -4
- package/dist/harness/knowledge/http-params.d.ts +18 -0
- package/dist/harness/knowledge/http-params.js +24 -0
- package/dist/harness/knowledge/index.d.ts +2 -0
- package/dist/harness/knowledge/index.js +1 -0
- package/dist/harness/knowledge/knowledge-serve-child.js +3 -0
- package/dist/harness/knowledge/purge.js +5 -2
- package/dist/harness/knowledge/query-service.d.ts +13 -2
- package/dist/harness/knowledge/query-service.js +4 -2
- package/dist/harness/knowledge/query-worker-client.d.ts +9 -1
- package/dist/harness/knowledge/query-worker-client.js +4 -2
- package/dist/harness/knowledge/query-worker.js +4 -2
- package/dist/harness/knowledge/read-http.js +5 -1
- package/dist/harness/knowledge/serve.d.ts +8 -7
- package/dist/harness/knowledge/serve.js +9 -0
- package/dist/harness/knowledge/source-store.js +26 -3
- package/dist/harness/knowledge/start-service-process.d.ts +15 -7
- package/dist/harness/knowledge/start-service-process.js +21 -9
- package/dist/harness/knowledge/types.d.ts +7 -0
- package/dist/harness/knowledge/writer-service.d.ts +37 -9
- package/dist/harness/knowledge/writer-service.js +120 -14
- package/dist/harness/knowledge/writer-worker-client.d.ts +10 -9
- package/dist/harness/knowledge/writer-worker-client.js +20 -2
- package/dist/harness/knowledge/writer-worker.js +9 -1
- package/dist/harness/memory/sqlite/wisdom-store.js +35 -10
- package/dist/harness/memory/types.d.ts +6 -4
- package/dist/harness/memory/wisdom-formation.d.ts +14 -3
- package/dist/harness/memory/wisdom-formation.js +85 -22
- package/dist/harness/memory/wisdom-gates.d.ts +14 -0
- package/dist/harness/memory/wisdom-gates.js +59 -19
- package/dist/harness/memory/wisdom.js +9 -0
- package/dist/harness/observability/observer/hub.js +25 -15
- package/dist/harness/observability/observer/types.d.ts +10 -6
- package/dist/harness/run/agent/agent.d.ts +40 -21
- package/dist/harness/run/agent/agent.js +66 -13
- package/dist/harness/run/agent/index.d.ts +1 -1
- package/dist/harness/run/budget/budget.d.ts +28 -10
- package/dist/harness/run/budget/budget.js +38 -15
- package/dist/harness/run/model/index.d.ts +3 -1
- package/dist/harness/run/model/index.js +2 -1
- package/dist/harness/run/model/resolver.d.ts +4 -1
- package/dist/harness/run/model/resolver.js +36 -2
- package/dist/harness/run/model/run-scope.d.ts +2 -0
- package/dist/harness/run/model/run-scope.js +7 -0
- package/dist/harness/run/model/types.d.ts +22 -5
- package/dist/harness/run/model/types.js +3 -2
- package/dist/harness/run/model/window-truth.d.ts +37 -0
- package/dist/harness/run/model/window-truth.js +39 -0
- package/dist/harness/run/reliability/context-length-feedback.d.ts +77 -0
- package/dist/harness/run/reliability/context-length-feedback.js +128 -0
- package/dist/harness/run/reliability/harness-events.d.ts +3 -3
- package/dist/harness/run/reliability/model-error-policy.js +4 -0
- package/dist/harness/run/reliability/run-agent.d.ts +10 -4
- package/dist/harness/run/reliability/run-agent.js +137 -53
- package/dist/harness/run/reliability/run-metrics-collector.d.ts +19 -8
- package/dist/harness/run/reliability/run-metrics-collector.js +38 -23
- package/dist/harness/run/run-guard/default-run-guard.js +8 -8
- package/dist/harness/run/run-scope.d.ts +37 -4
- package/dist/harness/run/runner.d.ts +44 -29
- package/dist/harness/run/runner.js +320 -102
- package/dist/harness/session/attachments/index.d.ts +1 -0
- package/dist/harness/session/attachments/index.js +1 -0
- package/dist/harness/session/attachments/inject.d.ts +21 -10
- package/dist/harness/session/attachments/inject.js +76 -24
- package/dist/harness/session/attachments/recall-index.d.ts +70 -0
- package/dist/harness/session/attachments/recall-index.js +219 -0
- package/dist/harness/session/attachments/service.d.ts +21 -0
- package/dist/harness/session/attachments/service.js +258 -139
- package/dist/harness/session/attachments/types.d.ts +6 -0
- package/dist/harness/session/transform-store.d.ts +136 -0
- package/dist/harness/session/transform-store.js +302 -0
- package/dist/harness/session/types.d.ts +2 -2
- package/dist/harness/shared/events/agent-event-map.d.ts +46 -13
- package/dist/harness/shared/events/agent-event-map.js +3 -2
- package/dist/harness/shared/events/scenario-events.d.ts +6 -6
- package/dist/harness/shared/types/agent-definition.d.ts +1 -2
- package/dist/index.d.ts +14 -17
- package/dist/index.js +7 -9
- package/dist/integration/observability/metrics.d.ts +6 -6
- package/dist/integration/observability/metrics.js +13 -13
- package/dist/integration/observability/observer-bridge.js +2 -2
- package/dist/integration/observability/trace-collector.d.ts +5 -5
- package/dist/integration/observability/trace-collector.js +34 -35
- package/dist/integration/observability/trace-events.d.ts +3 -3
- package/dist/integration/observability/trace-events.js +3 -3
- package/dist/integration/providers/anthropic.js +14 -1
- package/dist/integration/providers/openai.js +7 -1
- package/dist/integration/providers/usage.d.ts +1 -1
- package/dist/integration/providers/wire-dump.d.ts +1 -1
- package/dist/integration/storage/archive-manager.d.ts +6 -0
- package/dist/integration/storage/archive-manager.js +10 -0
- package/dist/integration/storage/jsonl.d.ts +1 -1
- package/dist/integration/storage/jsonl.js +18 -16
- package/dist/subsystems/wisdom-steward/formation/SUBSYSTEM.md +8 -1
- package/dist/subsystems/wisdom-steward/formation/config.yaml +1 -0
- package/dist/subsystems/wisdom-steward/formation/handler.js +27 -5
- package/package.json +11 -14
- package/dist/harness/context/hybrid-compressor.d.ts +0 -41
- package/dist/harness/context/hybrid-compressor.js +0 -159
- package/dist/harness/context/llm-summarizer.d.ts +0 -46
- package/dist/harness/context/llm-summarizer.js +0 -249
- package/dist/harness/context/smart-router.d.ts +0 -75
- package/dist/harness/context/smart-router.js +0 -118
- package/dist/harness/context/truncate-compressor.d.ts +0 -28
- package/dist/harness/context/truncate-compressor.js +0 -107
- package/dist/harness/extension/plugin-ecosystem/plugins/capability.d.ts +0 -97
- package/dist/harness/extension/plugin-ecosystem/plugins/capability.js +0 -155
- package/dist/harness/extension/plugin-ecosystem/plugins/hooks.d.ts +0 -7
- package/dist/harness/extension/plugin-ecosystem/plugins/hooks.js +0 -7
- package/dist/harness/extension/plugin-ecosystem/plugins/lifecycle.d.ts +0 -86
- package/dist/harness/extension/plugin-ecosystem/plugins/lifecycle.js +0 -139
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transform record store — durable ledger for compaction products.
|
|
3
|
+
*
|
|
4
|
+
* Layout (same base as turn-undo, sibling of `undo/` and `attachments/`):
|
|
5
|
+
*
|
|
6
|
+
* ```
|
|
7
|
+
* sessions/<sid>/transform/
|
|
8
|
+
* <agent-file>.jsonl # append-only entries: {kind:'record'|'revoke', ...}
|
|
9
|
+
* blobs/<sha256> # content-addressed replacement texts
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* Durability contract: blobs are written (atomic tmp+rename, skip-if-exists)
|
|
13
|
+
* **before** their record line is appended — a line is never readable without
|
|
14
|
+
* its blob. Revocations are append-only lines; the ledger folds them at load.
|
|
15
|
+
* Appends are serialized per (sessionId, agentId) inside the store (review F5:
|
|
16
|
+
* seq assignment must not race), and load returns records sorted by seq.
|
|
17
|
+
*
|
|
18
|
+
* ⚠️ This must NOT live under `sessions/<sid>/undo/` — that directory is
|
|
19
|
+
* deleted wholesale on turn-undo commit/discard.
|
|
20
|
+
*
|
|
21
|
+
* @module harness/session/transform-store
|
|
22
|
+
*/
|
|
23
|
+
import { createHash } from 'node:crypto';
|
|
24
|
+
import { appendFile, cp, mkdir, readFile, rename, rm, stat, writeFile } from 'node:fs/promises';
|
|
25
|
+
import { join } from 'node:path';
|
|
26
|
+
import { toSessionFileName } from '@octopi-agent/core/session-filename.js';
|
|
27
|
+
/**
|
|
28
|
+
* 解析会话 transform 目录
|
|
29
|
+
*
|
|
30
|
+
* @param sessionsDir - 通常 `OCTOPI_HOME/sessions`
|
|
31
|
+
* @param sessionId - 会话 id
|
|
32
|
+
* @returns 路径
|
|
33
|
+
*/
|
|
34
|
+
export function resolveSessionTransformPaths(sessionsDir, sessionId) {
|
|
35
|
+
const root = join(sessionsDir, toSessionFileName(sessionId), 'transform');
|
|
36
|
+
return { root, blobsDir: join(root, 'blobs') };
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* 复制会话 transform 账本(session fork 用)。
|
|
40
|
+
*
|
|
41
|
+
* 源缺失/复制失败返回 false——调用方降级路径是旧快照迁移(拷贝的 legacy 快照在
|
|
42
|
+
* 目标端一次性转换),不是静默成功。
|
|
43
|
+
*
|
|
44
|
+
* @param sessionsDir - `OCTOPI_HOME/sessions`
|
|
45
|
+
* @param fromSessionId - 源会话
|
|
46
|
+
* @param toSessionId - 目标会话
|
|
47
|
+
* @returns 是否完整复制
|
|
48
|
+
*/
|
|
49
|
+
export async function copySessionTransformDir(sessionsDir, fromSessionId, toSessionId) {
|
|
50
|
+
const from = resolveSessionTransformPaths(sessionsDir, fromSessionId).root;
|
|
51
|
+
const to = resolveSessionTransformPaths(sessionsDir, toSessionId).root;
|
|
52
|
+
const st = await stat(from).catch(() => undefined);
|
|
53
|
+
if (!st)
|
|
54
|
+
return false;
|
|
55
|
+
try {
|
|
56
|
+
await mkdir(to, { recursive: true });
|
|
57
|
+
await cp(from, to, { recursive: true, force: true });
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* 删除会话 transform 账本(会话删除清理;摘要正文含用户内容,不得遗留)。
|
|
66
|
+
*
|
|
67
|
+
* @param sessionsDir - `OCTOPI_HOME/sessions`
|
|
68
|
+
* @param sessionId - 会话 id
|
|
69
|
+
* @returns void
|
|
70
|
+
*/
|
|
71
|
+
export async function removeSessionTransformDir(sessionsDir, sessionId) {
|
|
72
|
+
await rm(resolveSessionTransformPaths(sessionsDir, sessionId).root, {
|
|
73
|
+
recursive: true,
|
|
74
|
+
force: true,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* 扫描 transform 孤儿目录(doctor 兜底)。
|
|
79
|
+
*
|
|
80
|
+
* 与 undo 不同:transform 账本**设计上常驻**(记录是持久事实),孤儿判据是
|
|
81
|
+
* 「会话 jsonl 已不存在而 transform/ 仍在」(删除清理之外的残留)。
|
|
82
|
+
*
|
|
83
|
+
* @param sessionsDir - `OCTOPI_HOME/sessions`
|
|
84
|
+
* @returns 孤儿列表
|
|
85
|
+
*/
|
|
86
|
+
export async function scanOrphanSessionTransform(sessionsDir) {
|
|
87
|
+
const { readdir } = await import('node:fs/promises');
|
|
88
|
+
const names = await readdir(sessionsDir, { withFileTypes: true }).catch(() => []);
|
|
89
|
+
const out = [];
|
|
90
|
+
for (const ent of names) {
|
|
91
|
+
if (!ent.isDirectory())
|
|
92
|
+
continue;
|
|
93
|
+
const transformRoot = join(sessionsDir, ent.name, 'transform');
|
|
94
|
+
const st = await stat(transformRoot).catch(() => undefined);
|
|
95
|
+
if (!st)
|
|
96
|
+
continue;
|
|
97
|
+
const sessionFile = join(sessionsDir, `${ent.name}.jsonl`);
|
|
98
|
+
if (await stat(sessionFile).catch(() => undefined))
|
|
99
|
+
continue; // 会话仍在:正常账本
|
|
100
|
+
let ledgerFiles = 0;
|
|
101
|
+
let blobFiles = 0;
|
|
102
|
+
try {
|
|
103
|
+
const items = await readdir(transformRoot, { withFileTypes: true });
|
|
104
|
+
ledgerFiles = items.filter((i) => i.isFile() && i.name.endsWith('.jsonl')).length;
|
|
105
|
+
}
|
|
106
|
+
catch { /* 视为 0 */ }
|
|
107
|
+
try {
|
|
108
|
+
blobFiles = (await readdir(join(transformRoot, 'blobs'))).length;
|
|
109
|
+
}
|
|
110
|
+
catch { /* 视为 0 */ }
|
|
111
|
+
out.push({ sessionDirName: ent.name, transformRoot, ledgerFiles, blobFiles });
|
|
112
|
+
}
|
|
113
|
+
return out;
|
|
114
|
+
}
|
|
115
|
+
/** Per-agent ledger file name (record lines also carry agentId — load filters by it). */
|
|
116
|
+
function agentLedgerFile(root, agentId) {
|
|
117
|
+
return join(root, `${agentId === '' ? '_' : encodeURIComponent(agentId)}.jsonl`);
|
|
118
|
+
}
|
|
119
|
+
/** sha256 hex of replacement text */
|
|
120
|
+
function blobHash(text) {
|
|
121
|
+
return createHash('sha256').update(text, 'utf8').digest('hex');
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* JSONL file-backed transform store (durable).
|
|
125
|
+
*/
|
|
126
|
+
export class JsonlTransformStore {
|
|
127
|
+
sessionsDir;
|
|
128
|
+
/** per (sessionId, agentId) append chain(F5:seq 分配互斥) */
|
|
129
|
+
appendChains = new Map();
|
|
130
|
+
/**
|
|
131
|
+
* @param options - sessionsDir (`OCTOPI_HOME/sessions`)
|
|
132
|
+
*/
|
|
133
|
+
constructor(options) {
|
|
134
|
+
this.sessionsDir = options.sessionsDir;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Load the ledger for (sessionId, agentId), blobs hydrated into `text`,
|
|
138
|
+
* records sorted by seq(fold 的 later-seq-wins 依赖序)。
|
|
139
|
+
*
|
|
140
|
+
* @param sessionId - session id
|
|
141
|
+
* @param agentId - agent id
|
|
142
|
+
* @returns ledger (empty when none)
|
|
143
|
+
*/
|
|
144
|
+
async load(sessionId, agentId) {
|
|
145
|
+
const { root, blobsDir } = resolveSessionTransformPaths(this.sessionsDir, sessionId);
|
|
146
|
+
const raw = await readFile(agentLedgerFile(root, agentId), 'utf8').catch(() => undefined);
|
|
147
|
+
if (raw === undefined)
|
|
148
|
+
return { records: [] };
|
|
149
|
+
const records = [];
|
|
150
|
+
const revokeTargets = new Set();
|
|
151
|
+
let hadEntries = false;
|
|
152
|
+
for (const line of raw.split('\n')) {
|
|
153
|
+
if (!line.trim())
|
|
154
|
+
continue;
|
|
155
|
+
hadEntries = true;
|
|
156
|
+
let entry;
|
|
157
|
+
try {
|
|
158
|
+
entry = JSON.parse(line);
|
|
159
|
+
}
|
|
160
|
+
catch {
|
|
161
|
+
// 损坏行跳过并保留其余账本:append-only 流的尾行可能被崩溃撕裂;
|
|
162
|
+
// 跳过是降级(少一段覆盖→原文可见),不是成功假象。完整校验在红线测试。
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
if (entry.kind === 'revoke') {
|
|
166
|
+
revokeTargets.add(entry.targetSeq);
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
if (entry.record.agentId !== agentId)
|
|
170
|
+
continue;
|
|
171
|
+
const record = { ...entry.record, revoked: false };
|
|
172
|
+
if (record.blobRef) {
|
|
173
|
+
const text = await readFile(join(blobsDir, record.blobRef.replace(/^sha256:/, '')), 'utf8').catch(() => undefined);
|
|
174
|
+
if (text === undefined) {
|
|
175
|
+
// blob 丢失(外部清扫):记录不生效(占位无文可渲染)——原文回可见是
|
|
176
|
+
// 降级方向(宁胖不丢),但不得静默(F7):如实告警。
|
|
177
|
+
console.warn(`[transform] session=${sessionId} agent=${agentId} record seq=${record.seq}: blob ${record.blobRef} missing; record dropped (raw text stays visible)`);
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
record.text = text;
|
|
181
|
+
}
|
|
182
|
+
records.push(record);
|
|
183
|
+
}
|
|
184
|
+
for (const record of records) {
|
|
185
|
+
if (revokeTargets.has(record.seq))
|
|
186
|
+
record.revoked = true;
|
|
187
|
+
}
|
|
188
|
+
// 文件序 → seq 序(跨进程交错写也可能倒置;fold 的 later-seq-wins 依赖它)
|
|
189
|
+
records.sort((a, b) => a.seq - b.seq);
|
|
190
|
+
return { records, hadEntries };
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Durably append records and/or revocations (serialized per key — seq safe).
|
|
194
|
+
*
|
|
195
|
+
* @param sessionId - session id
|
|
196
|
+
* @param agentId - agent id
|
|
197
|
+
* @param records - new records (seq assigned here)
|
|
198
|
+
* @param revokeSeqs - seqs to revoke
|
|
199
|
+
* @returns appended records with seq assigned
|
|
200
|
+
*/
|
|
201
|
+
async append(sessionId, agentId, records, revokeSeqs) {
|
|
202
|
+
const key = `${sessionId}\u0000${agentId}`;
|
|
203
|
+
const prev = this.appendChains.get(key) ?? Promise.resolve();
|
|
204
|
+
const task = prev.then(() => this.appendInternal(sessionId, agentId, records, revokeSeqs));
|
|
205
|
+
this.appendChains.set(key, task.catch(() => undefined));
|
|
206
|
+
return task;
|
|
207
|
+
}
|
|
208
|
+
async appendInternal(sessionId, agentId, records, revokeSeqs) {
|
|
209
|
+
const { root, blobsDir } = resolveSessionTransformPaths(this.sessionsDir, sessionId);
|
|
210
|
+
await mkdir(blobsDir, { recursive: true });
|
|
211
|
+
const existing = await this.load(sessionId, agentId);
|
|
212
|
+
let nextSeq = existing.records.reduce((n, r) => Math.max(n, r.seq), 0) + 1;
|
|
213
|
+
const at = Date.now();
|
|
214
|
+
const out = [];
|
|
215
|
+
const lines = [];
|
|
216
|
+
for (const rec of records) {
|
|
217
|
+
const seq = nextSeq++;
|
|
218
|
+
let blobRef;
|
|
219
|
+
if (rec.text !== undefined) {
|
|
220
|
+
const hash = blobHash(rec.text);
|
|
221
|
+
blobRef = `sha256:${hash}`;
|
|
222
|
+
await writeBlobIfAbsent(join(blobsDir, hash), rec.text);
|
|
223
|
+
}
|
|
224
|
+
const record = { ...rec, seq, blobRef, revoked: false };
|
|
225
|
+
out.push(record);
|
|
226
|
+
const { text: _text, revoked: _revoked, ...persisted } = record;
|
|
227
|
+
lines.push(JSON.stringify({ kind: 'record', record: persisted }));
|
|
228
|
+
}
|
|
229
|
+
for (const targetSeq of revokeSeqs ?? []) {
|
|
230
|
+
lines.push(JSON.stringify({ kind: 'revoke', seq: nextSeq++, targetSeq, at }));
|
|
231
|
+
}
|
|
232
|
+
if (lines.length > 0) {
|
|
233
|
+
await appendFile(agentLedgerFile(root, agentId), `${lines.join('\n')}\n`, 'utf8');
|
|
234
|
+
}
|
|
235
|
+
return out;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
/** 内容寻址 blob:不存在才写(tmp+rename 原子替换,防半截文件) */
|
|
239
|
+
async function writeBlobIfAbsent(path, text) {
|
|
240
|
+
const st = await stat(path).catch(() => undefined);
|
|
241
|
+
if (st)
|
|
242
|
+
return;
|
|
243
|
+
const tmp = `${path}.${process.pid}.${Date.now()}.tmp`;
|
|
244
|
+
await writeFile(tmp, text, 'utf8');
|
|
245
|
+
await rename(tmp, path);
|
|
246
|
+
}
|
|
247
|
+
let warnedInMemoryDurability = false;
|
|
248
|
+
/**
|
|
249
|
+
* In-memory transform store (standalone engines / tests). Same append semantics,
|
|
250
|
+
* no durability — permanence holds across assemblies within the process only.
|
|
251
|
+
* First append logs a one-time durability warning (review F4: degradation must
|
|
252
|
+
* not be silent).
|
|
253
|
+
*/
|
|
254
|
+
export class InMemoryTransformStore {
|
|
255
|
+
ledgers = new Map();
|
|
256
|
+
key(sessionId, agentId) {
|
|
257
|
+
return `${sessionId}\u0000${agentId}`;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Load the ledger for (sessionId, agentId).
|
|
261
|
+
*
|
|
262
|
+
* @param sessionId - session id
|
|
263
|
+
* @param agentId - agent id
|
|
264
|
+
* @returns ledger
|
|
265
|
+
*/
|
|
266
|
+
async load(sessionId, agentId) {
|
|
267
|
+
const entry = this.ledgers.get(this.key(sessionId, agentId));
|
|
268
|
+
return { records: entry ? entry.records.map((r) => ({ ...r })) : [] };
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Append records and/or revocations in memory.
|
|
272
|
+
*
|
|
273
|
+
* @param sessionId - session id
|
|
274
|
+
* @param agentId - agent id
|
|
275
|
+
* @param records - new records
|
|
276
|
+
* @param revokeSeqs - seqs to revoke
|
|
277
|
+
* @returns appended records
|
|
278
|
+
*/
|
|
279
|
+
async append(sessionId, agentId, records, revokeSeqs) {
|
|
280
|
+
if (records.length > 0 && !warnedInMemoryDurability) {
|
|
281
|
+
warnedInMemoryDurability = true;
|
|
282
|
+
console.warn('[transform] in-memory transform store: compaction products are process-local and will not survive restarts (inject JsonlTransformStore for durability)');
|
|
283
|
+
}
|
|
284
|
+
const key = this.key(sessionId, agentId);
|
|
285
|
+
const entry = this.ledgers.get(key) ?? { records: [], seq: 0 };
|
|
286
|
+
const out = [];
|
|
287
|
+
for (const rec of records) {
|
|
288
|
+
entry.seq += 1;
|
|
289
|
+
const record = { ...rec, seq: entry.seq, blobRef: undefined, revoked: false };
|
|
290
|
+
entry.records.push(record);
|
|
291
|
+
out.push({ ...record });
|
|
292
|
+
}
|
|
293
|
+
for (const targetSeq of revokeSeqs ?? []) {
|
|
294
|
+
entry.seq += 1;
|
|
295
|
+
const target = entry.records.find((r) => r.seq === targetSeq);
|
|
296
|
+
if (target)
|
|
297
|
+
target.revoked = true;
|
|
298
|
+
}
|
|
299
|
+
this.ledgers.set(key, entry);
|
|
300
|
+
return out;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @layer harness — Session 的具体结构和生命周期管理类型。
|
|
5
5
|
* Core 层的 SessionStore 接口是泛型的,不引用此文件。
|
|
6
6
|
*/
|
|
7
|
-
import type { Message,
|
|
7
|
+
import type { Message, Step, SessionMeta } from '@octopi-agent/core/types.js';
|
|
8
8
|
import type { SessionTask } from './tasks/types.js';
|
|
9
9
|
import type { ContextCompactSnapshot } from '../context/types.js';
|
|
10
10
|
import type { SessionParticipant } from '../governance/session-acl/types.js';
|
|
@@ -90,7 +90,7 @@ export interface SessionData {
|
|
|
90
90
|
spawnBy?: SessionSpawnLink;
|
|
91
91
|
meta: SessionMeta;
|
|
92
92
|
messages: Message[];
|
|
93
|
-
|
|
93
|
+
steps: Step[];
|
|
94
94
|
metadata: Record<string, unknown>;
|
|
95
95
|
lifecycle?: SessionLifecycleMeta;
|
|
96
96
|
/**
|
|
@@ -32,11 +32,11 @@ export interface AgentEventMap {
|
|
|
32
32
|
delayMs: number;
|
|
33
33
|
error: string;
|
|
34
34
|
};
|
|
35
|
-
'
|
|
35
|
+
'step.start': Record<string, never>;
|
|
36
36
|
'llm.usage': {
|
|
37
|
-
usage: import('@octopi-agent/core/types/
|
|
37
|
+
usage: import('@octopi-agent/core/types/step.js').TokenUsage;
|
|
38
38
|
};
|
|
39
|
-
'
|
|
39
|
+
'step.end': {
|
|
40
40
|
/** 本次调用的正文;error=true 时 = 中断前的部分流出(不是回答,不得当回复外发) */
|
|
41
41
|
content?: string;
|
|
42
42
|
userText?: string;
|
|
@@ -46,10 +46,15 @@ export interface AgentEventMap {
|
|
|
46
46
|
stopped?: boolean;
|
|
47
47
|
/** 本次 LLM 调用失败(只出现在重试中途;彻底失败走 agent_end reason='error') */
|
|
48
48
|
error?: boolean;
|
|
49
|
-
usage?: import('@octopi-agent/core/types/
|
|
49
|
+
usage?: import('@octopi-agent/core/types/step.js').TokenUsage;
|
|
50
50
|
/** F3 LLM 计时摘要(loop turn_end 透传;Run 页签耗时区消费) */
|
|
51
51
|
llmTiming?: import('@octopi-agent/core/loop/types.js').LoopLLMTiming;
|
|
52
|
-
|
|
52
|
+
/** 上下文用量三量纲(P0-C 单源分账):provider 实测(usage/stale 写入);无实测不写不猜 */
|
|
53
|
+
promptTokensActual?: number;
|
|
54
|
+
/** 请求视图估算(校准后,最近一次 assemble 口径;estimate 写入,压缩后清空待下轮重算) */
|
|
55
|
+
viewTokensEst?: number;
|
|
56
|
+
/** 全量原文估算(仅 Run 页签展示,不进决策/主显示) */
|
|
57
|
+
rawTokens?: number;
|
|
53
58
|
contextWindow?: number;
|
|
54
59
|
};
|
|
55
60
|
'tool.exec.start': {
|
|
@@ -111,7 +116,7 @@ export interface AgentEventMap {
|
|
|
111
116
|
stopReason?: string;
|
|
112
117
|
};
|
|
113
118
|
'budget.exceeded': {
|
|
114
|
-
reason: 'wall_clock' | '
|
|
119
|
+
reason: 'wall_clock' | 'steps' | 'tool_calls';
|
|
115
120
|
report?: unknown;
|
|
116
121
|
};
|
|
117
122
|
'run_guard.stopped': {
|
|
@@ -175,26 +180,53 @@ export interface AgentEventMap {
|
|
|
175
180
|
'persona.resolve.failed': {
|
|
176
181
|
error: string;
|
|
177
182
|
};
|
|
178
|
-
/** 上下文压缩开始(主动摘要 /
|
|
183
|
+
/** 上下文压缩开始(主动摘要 / 硬溢出 / 手动;UI 可显示进行中) */
|
|
179
184
|
'context.compact.start': {
|
|
180
|
-
reason: 'proactive' | 'overflow';
|
|
185
|
+
reason: 'proactive' | 'overflow' | 'manual';
|
|
181
186
|
tokensBefore?: number;
|
|
182
187
|
threshold?: number;
|
|
183
188
|
};
|
|
184
189
|
/** 上下文压缩结束 */
|
|
185
190
|
'context.compact.end': {
|
|
186
|
-
reason: 'proactive' | 'overflow';
|
|
191
|
+
reason: 'proactive' | 'overflow' | 'manual';
|
|
187
192
|
tokensBefore?: number;
|
|
188
193
|
tokensAfter?: number;
|
|
189
194
|
durationMs?: number;
|
|
190
195
|
cached?: boolean;
|
|
196
|
+
/** true=中止收尾(本轮作废、零写入)——不是「压缩完成」,UI 不得显示 compacted */
|
|
197
|
+
cancelled?: boolean;
|
|
191
198
|
};
|
|
192
|
-
/**
|
|
199
|
+
/** 上下文压缩受阻(failed=压缩失败已回退截断;denied=before_compaction 策略拒绝,非故障) */
|
|
193
200
|
'context.compact.error': {
|
|
194
|
-
reason?: 'proactive' | 'overflow';
|
|
201
|
+
reason?: 'proactive' | 'overflow' | 'manual';
|
|
195
202
|
error: string;
|
|
203
|
+
kind?: 'denied' | 'failed';
|
|
196
204
|
durationMs?: number;
|
|
197
205
|
};
|
|
206
|
+
/**
|
|
207
|
+
* overflow 症状告警(P3 红线 7):守门人触发 = 罕见异常信号,每次触发打告警。
|
|
208
|
+
* proactive_failed=A 类(前馈溢出,proactive 失效症状);config_drift/config_missing=F 类实证;
|
|
209
|
+
* structural_over_budget=D 类(保护段超限);window_mismatch=F 类归因未定(收缩兜底)。
|
|
210
|
+
*/
|
|
211
|
+
'context.overflow.alert': {
|
|
212
|
+
symptom: 'proactive_failed' | 'config_drift' | 'config_missing' | 'structural_over_budget' | 'window_mismatch';
|
|
213
|
+
message: string;
|
|
214
|
+
estimatedTokens?: number;
|
|
215
|
+
contextWindow?: number;
|
|
216
|
+
trigger?: 'T1' | 'T2' | 'T3';
|
|
217
|
+
};
|
|
218
|
+
/** 摘要请求进行中(P3):请求已发出、等 provider 返回——UI 据此显示「已发出 N 条 / 预算 Ms」而非只显示「进行中」 */
|
|
219
|
+
'context.compact.progress': {
|
|
220
|
+
reason?: 'proactive' | 'overflow' | 'manual';
|
|
221
|
+
/** 当前阶段(当前只有 summarize:请求已发出、等 provider 返回) */
|
|
222
|
+
phase: 'summarize';
|
|
223
|
+
/** 摘要请求体量(JSON 字符数)——事故里就是它从 ~150KB 涨到 2.13MB */
|
|
224
|
+
requestChars?: number;
|
|
225
|
+
/** 摘要请求消息条数 */
|
|
226
|
+
requestMessages?: number;
|
|
227
|
+
/** 本次调用的单次预算(ms);缺失 = 不设预算 */
|
|
228
|
+
timeoutMs?: number;
|
|
229
|
+
};
|
|
198
230
|
/** 摘要请求 cache-miss 旁路/穷尽可观测(F22):no_prefix=无同形前缀,window_guard=前缀放不下改文本化旁路,window_exhausted=最终失败 */
|
|
199
231
|
'context.compact.summarize_fallback': {
|
|
200
232
|
reason?: 'proactive' | 'overflow';
|
|
@@ -337,8 +369,8 @@ export declare const AgentEvents: {
|
|
|
337
369
|
readonly ENGINE_END: "engine.end";
|
|
338
370
|
readonly ENGINE_ERROR: "engine.error";
|
|
339
371
|
readonly ENGINE_MODEL_RETRY: "engine.model_retry";
|
|
340
|
-
readonly
|
|
341
|
-
readonly
|
|
372
|
+
readonly STEP_START: "step.start";
|
|
373
|
+
readonly STEP_END: "step.end";
|
|
342
374
|
/** Runner 收口计时(F3 转正) */
|
|
343
375
|
readonly RUN_TIMING: "run.timing";
|
|
344
376
|
readonly TOOL_EXEC_START: "tool.exec.start";
|
|
@@ -357,6 +389,7 @@ export declare const AgentEvents: {
|
|
|
357
389
|
readonly SESSION_UPDATED: "session.updated";
|
|
358
390
|
readonly PERSONA_RESOLVE_FAILED: "persona.resolve.failed";
|
|
359
391
|
readonly CONTEXT_COMPACT_START: "context.compact.start";
|
|
392
|
+
readonly CONTEXT_COMPACT_PROGRESS: "context.compact.progress";
|
|
360
393
|
readonly CONTEXT_COMPACT_END: "context.compact.end";
|
|
361
394
|
readonly CONTEXT_COMPACT_ERROR: "context.compact.error";
|
|
362
395
|
readonly CONTEXT_LAYERS_ASSEMBLED: "context.layers.assembled";
|
|
@@ -19,8 +19,8 @@ export const AgentEvents = {
|
|
|
19
19
|
ENGINE_END: 'engine.end',
|
|
20
20
|
ENGINE_ERROR: 'engine.error',
|
|
21
21
|
ENGINE_MODEL_RETRY: 'engine.model_retry',
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
STEP_START: 'step.start',
|
|
23
|
+
STEP_END: 'step.end',
|
|
24
24
|
/** Runner 收口计时(F3 转正) */
|
|
25
25
|
RUN_TIMING: 'run.timing',
|
|
26
26
|
TOOL_EXEC_START: 'tool.exec.start',
|
|
@@ -39,6 +39,7 @@ export const AgentEvents = {
|
|
|
39
39
|
SESSION_UPDATED: 'session.updated',
|
|
40
40
|
PERSONA_RESOLVE_FAILED: 'persona.resolve.failed',
|
|
41
41
|
CONTEXT_COMPACT_START: 'context.compact.start',
|
|
42
|
+
CONTEXT_COMPACT_PROGRESS: 'context.compact.progress',
|
|
42
43
|
CONTEXT_COMPACT_END: 'context.compact.end',
|
|
43
44
|
CONTEXT_COMPACT_ERROR: 'context.compact.error',
|
|
44
45
|
CONTEXT_LAYERS_ASSEMBLED: 'context.layers.assembled',
|
|
@@ -8,7 +8,7 @@ import type { ToolCall } from '@octopi-agent/core/types.js';
|
|
|
8
8
|
import type { TokenUsage } from '@octopi-agent/core/types.js';
|
|
9
9
|
import type { ClassifiedError, ErrorReason } from '@octopi-agent/core/interfaces/error-strategy.js';
|
|
10
10
|
export type { ErrorReason, ClassifiedError };
|
|
11
|
-
export type LoopEndReason = 'completed' | '
|
|
11
|
+
export type LoopEndReason = 'completed' | 'max_steps' | 'budget_exhausted' | 'plugin_stop' | 'interrupted' | 'error';
|
|
12
12
|
export type AgentEventDetail = {
|
|
13
13
|
type: 'loop_start';
|
|
14
14
|
sessionId: string;
|
|
@@ -17,12 +17,12 @@ export type AgentEventDetail = {
|
|
|
17
17
|
reason: LoopEndReason;
|
|
18
18
|
response?: string;
|
|
19
19
|
} | {
|
|
20
|
-
type: '
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
type: 'step_start';
|
|
21
|
+
stepId: string;
|
|
22
|
+
stepIndex: number;
|
|
23
23
|
} | {
|
|
24
|
-
type: '
|
|
25
|
-
|
|
24
|
+
type: 'step_end';
|
|
25
|
+
stepId: string;
|
|
26
26
|
shouldContinue: boolean;
|
|
27
27
|
phase?: 'pre_tools' | 'final';
|
|
28
28
|
} | {
|
|
@@ -18,7 +18,6 @@ export interface AgentPersona {
|
|
|
18
18
|
export interface ModelConfig {
|
|
19
19
|
provider: string;
|
|
20
20
|
model: string;
|
|
21
|
-
temperature?: number;
|
|
22
21
|
maxTokens?: number;
|
|
23
22
|
contextWindow?: number;
|
|
24
23
|
/** 回退模型列表(按优先级排序,由 resolveModelConfig 解析后的完整配置) */
|
|
@@ -65,7 +64,7 @@ export interface AgentDefinition {
|
|
|
65
64
|
rightsCeiling?: SessionRights;
|
|
66
65
|
/** 委派预算上限(请求预算与此取交集) */
|
|
67
66
|
budget?: {
|
|
68
|
-
|
|
67
|
+
maxSteps?: number;
|
|
69
68
|
maxTokens?: number;
|
|
70
69
|
timeoutMs?: number;
|
|
71
70
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -12,8 +12,8 @@ export { BudgetPolicyEngine, DEFAULT_BUDGET } from './harness/run/budget/budget.
|
|
|
12
12
|
export type { BudgetPolicyConfig } from './harness/run/budget/budget.js';
|
|
13
13
|
export { UsageLedger } from './harness/governance/accounting/usage-ledger.js';
|
|
14
14
|
export type { UsageLedgerSnapshot } from './harness/governance/accounting/usage-ledger.js';
|
|
15
|
-
export { emptyTokenUsage, makeTokenUsage, nominalTotalTokens, reportedPromptTokens, } from '@octopi-agent/core/types/
|
|
16
|
-
export type { TokenUsage } from '@octopi-agent/core/types/
|
|
15
|
+
export { emptyTokenUsage, makeTokenUsage, nominalTotalTokens, reportedPromptTokens, } from '@octopi-agent/core/types/step.js';
|
|
16
|
+
export type { TokenUsage } from '@octopi-agent/core/types/step.js';
|
|
17
17
|
export type { ModelProvider, LLMRequest, LLMResponse, LLMStreamChunk, LLMToolDefinition } from '@octopi-agent/core/interfaces/model-provider.js';
|
|
18
18
|
/** 领域富模型(注册/权限/参数校验);LLM 传输格式见 LLMToolDefinition */
|
|
19
19
|
export type { ToolDefinition, RegisteredTool, ToolHandler, ToolParameter, ToolSource, ToolExecutionContext } from '@octopi-agent/core/types/tools.js';
|
|
@@ -22,7 +22,7 @@ export type { SecurityAction } from '@octopi-agent/core/security-guard.js';
|
|
|
22
22
|
export type { Observer, Span, LogLevel } from '@octopi-agent/core/interfaces/observer.js';
|
|
23
23
|
export type { SessionStore, SessionListFilter } from '@octopi-agent/core/interfaces/session-store.js';
|
|
24
24
|
export type { SessionData, SessionLifecycleMeta, SessionLifecycleStatus, MemoryExtractionStatus } from './harness/session/types.js';
|
|
25
|
-
export type { ContextEngine, ContextEngineInfo, AssembleParams, AssembleResult, IngestParams,
|
|
25
|
+
export type { ContextEngine, ContextEngineInfo, AssembleParams, AssembleResult, IngestParams, AfterStepParams, TokenEstimator, SummarizeFunction, MessageSelector, SelectResult, SelectOptions, BudgetAllocator, BudgetAllocateParams, BudgetAllocateResult, } from './harness/context/types.js';
|
|
26
26
|
export { setRunTelemetryFactory, getRunTelemetryFactory } from './harness/observability/run-telemetry.js';
|
|
27
27
|
export type { RunTelemetry, RunTelemetryFactory } from './harness/observability/run-telemetry.js';
|
|
28
28
|
export { createRunTelemetry } from './integration/observability/run-telemetry.js';
|
|
@@ -31,7 +31,7 @@ export type { AgentTraceOptions } from './harness/agent/builder.js';
|
|
|
31
31
|
export type { AgentBuildOptions, AgentBuildResult, AgentBuildCoreResult } from './harness/agent/builder.js';
|
|
32
32
|
export type { ChannelAdapter, ChannelMessage, ChannelReply } from './harness/extension/plugin-ecosystem/channel-types.js';
|
|
33
33
|
export { Agent } from './harness/run/agent/index.js';
|
|
34
|
-
export type { AgentOptions } from './harness/run/agent/index.js';
|
|
34
|
+
export type { AgentOptions, RunIdentity } from './harness/run/agent/index.js';
|
|
35
35
|
export type { HarnessLoopEvent, BudgetControlEvent, ControlStopMetric, PolicyUnit } from './harness/run/reliability/harness-events.js';
|
|
36
36
|
export { SessionAwareRunner } from './harness/run/runner.js';
|
|
37
37
|
export { DEFAULT_TOOL_ISOLATION, resolveToolIsolationCwd, } from './harness/extension/execution-environment/isolation.js';
|
|
@@ -47,6 +47,7 @@ export { runWithToolLimits, resolveToolTimeoutMs, ToolTimeoutError, } from './ha
|
|
|
47
47
|
export type { EffectIntent, ConfirmEffect, ConfirmEffectDecision, UntrustedAdmission, JailIntent, OnJailUnavailable, OpsJailState, ToolSurface, SecurityDegradation, SessionEffectOverrides, } from './harness/extension/execution-environment/effect-policy.js';
|
|
48
48
|
export type { EffectRunMode, EffectPolicyConfig, EffectiveEffectPolicy, PathContainment, ShellEscapePolicy, } from './harness/extension/execution-environment/effect-policy.js';
|
|
49
49
|
export { scanOrphanSessionUndo, } from './harness/extension/execution-environment/undo-log.js';
|
|
50
|
+
export { scanOrphanSessionTransform } from './harness/session/transform-store.js';
|
|
50
51
|
export type { SessionUndoPaths, FileUndoEntry, DiscardFileEffectsResult, DiscardConflictReason, EditResendResult, NotReversedEffects, NotReversedReason, UndoLimitConfig, OrphanUndoDir, } from './harness/extension/execution-environment/undo-log.js';
|
|
51
52
|
export type { ShellJournalMode } from './harness/extension/execution-environment/effect-policy.js';
|
|
52
53
|
export type { ToolFileEffects } from '@octopi-agent/core/types/tools.js';
|
|
@@ -61,22 +62,17 @@ export { DefaultContextEngine } from './harness/context/default-context-engine.j
|
|
|
61
62
|
export type { DefaultContextEngineConfig } from './harness/context/default-context-engine.js';
|
|
62
63
|
export { HeuristicTokenEstimator, estimateTextTokens } from './harness/context/index.js';
|
|
63
64
|
export { DefaultMessageSelector } from './harness/context/message-selector.js';
|
|
64
|
-
export { TruncateCompressor } from './harness/context/truncate-compressor.js';
|
|
65
|
-
export { LLMSummaryCompressor } from './harness/context/llm-summarizer.js';
|
|
66
|
-
export { HybridCompressor } from './harness/context/hybrid-compressor.js';
|
|
67
65
|
export { DefaultBudgetAllocator } from './harness/context/budget-allocator.js';
|
|
68
|
-
export { SmartRouter } from './harness/context/smart-router.js';
|
|
69
|
-
export type { SmartRouterConfig, Route, RoutingDecision } from './harness/context/smart-router.js';
|
|
70
66
|
export { CapabilityEnforcer, PluginTrustLevel } from './harness/governance/security/capability-enforcer.js';
|
|
71
67
|
export { PluginManager } from './harness/extension/plugin-ecosystem/plugins/manager.js';
|
|
72
|
-
export {
|
|
73
|
-
export type { OctopiPluginDefinition
|
|
68
|
+
export { definePlugin } from './harness/extension/plugin-ecosystem/plugins/entry.js';
|
|
69
|
+
export type { OctopiPluginDefinition } from './harness/extension/plugin-ecosystem/plugins/entry.js';
|
|
74
70
|
export { PluginApi } from './harness/extension/plugin-ecosystem/plugins/api.js';
|
|
75
71
|
export { PluginLoader } from './harness/extension/plugin-ecosystem/plugins/loader.js';
|
|
76
|
-
export type { LoadedPlugin, PluginLoaderConfig, PluginEntryConfig } from './harness/extension/plugin-ecosystem/plugins/loader.js';
|
|
77
|
-
export {
|
|
78
|
-
export { validateManifest, parseManifest } from './harness/extension/plugin-ecosystem/plugins/manifest.js';
|
|
79
|
-
export type { PluginManifest,
|
|
72
|
+
export type { LoadedPlugin, PluginLoaderConfig, PluginEntryConfig, PluginDiagnostic } from './harness/extension/plugin-ecosystem/plugins/loader.js';
|
|
73
|
+
export { PluginContributionRegistry } from './harness/extension/plugin-ecosystem/plugins/contribution-registry.js';
|
|
74
|
+
export { validateManifest, parseManifest, validatePluginConfig, PLUGIN_API_VERSION } from './harness/extension/plugin-ecosystem/plugins/manifest.js';
|
|
75
|
+
export type { PluginManifest, PluginContributions, PluginHookName, PluginSessionOpName } from './harness/extension/plugin-ecosystem/plugins/manifest.js';
|
|
80
76
|
export { DefaultSkillManager, FileSystemSkillSource } from './harness/extension/plugin-ecosystem/skills/manager.js';
|
|
81
77
|
export type { SkillSource, DiscoveredSkill } from './harness/extension/plugin-ecosystem/skills/manager.js';
|
|
82
78
|
export type { SkillDefinition, SkillManager } from './harness/extension/plugin-ecosystem/skills/types.js';
|
|
@@ -92,7 +88,8 @@ export { readGitStatusSnapshot, parsePorcelainV2 } from './harness/extension/plu
|
|
|
92
88
|
export type { GitStatusSnapshot, GitStatusSnapshotBody, GitStatusSnapshotOptions, GitStatusEntry, GitStatusBranch, GitStatusCounts, GitStatusGroup, GitStatusKind, } from './harness/extension/plugin-ecosystem/tools/git-status-snapshot.js';
|
|
93
89
|
export { createSummaryPort, applyToolOutputGate, createCompactEngine } from './harness/context/capabilities/index.js';
|
|
94
90
|
export { createDefaultDocumentPort, createDocumentPortFromConfig, DocumentExtractError } from './harness/capabilities/document/index.js';
|
|
95
|
-
export type { SummaryPort, SummaryPolicy, ContentUnit, ToolSummarySupport, CompactEngine } from './harness/context/capabilities/index.js';
|
|
91
|
+
export type { SummaryPort, SummaryPolicy, ContentUnit, ToolSummarySupport, CompactEngine, CompactOutcome, CompactTransportOutcome } from './harness/context/capabilities/index.js';
|
|
92
|
+
export { toCompactTransport } from './harness/context/capabilities/compact/types.js';
|
|
96
93
|
export type { DocumentPort, ExtractResult, ExtractSource } from './harness/capabilities/document/index.js';
|
|
97
94
|
export type { ToolSet, ToolSetConfig } from './harness/extension/plugin-ecosystem/tools/tool-set.js';
|
|
98
95
|
export { createWebSearchTool } from './harness/extension/plugin-ecosystem/tools/web-search.js';
|
|
@@ -102,7 +99,7 @@ export { createSessionHistoryTools, createSessionSearchTool, createSessionReadTo
|
|
|
102
99
|
export type { SessionHistoryPort, SessionHistoryQuery, SessionHistorySearchResult, } from './harness/session/history/index.js';
|
|
103
100
|
export { buildFromConfig } from './harness/agent/config-bridge.js';
|
|
104
101
|
export type { BuiltAgent } from './harness/agent/config-bridge.js';
|
|
105
|
-
export { DefaultAgentRegistry, DelegationStore, DelegateService, DelegateResolutionError, InProcessTransport, RunnerChildRunPort, createChildRunExecutor, createDelegationNotifier, renderDelegationNotice, wireDelegation, createDelegationRuntime, AgentRegistryEvents, DelegationEvents, DELEGATION_SCHEMA_VERSION, } from './harness/collaboration/delegation/index.js';
|
|
102
|
+
export { DefaultAgentRegistry, DelegationStore, DelegateService, DelegateResolutionError, InProcessTransport, RunnerChildRunPort, createChildRunExecutor, createDelegationNotifier, renderDelegationNotice, wireDelegation, createDelegationRuntime, AgentRegistryEvents, DelegationEvents, DELEGATION_SCHEMA_VERSION, DEFAULT_DELEGATION_OUTPUT_CHARS, normalizeMaxOutputChars, } from './harness/collaboration/delegation/index.js';
|
|
106
103
|
export type { Delegation, DelegateRequest, DelegateResult, AgentHandle, AgentRegistry, AgentInfo, AgentQuery, AgentRelation, AgentRelationType, AgentDelegationPolicy, DelegateTransport, DelegatableAgent, DelegationRuntime, } from './harness/collaboration/delegation/index.js';
|
|
107
104
|
export { JsonlSessionStore } from './integration/storage/jsonl.js';
|
|
108
105
|
export { InMemorySessionStore } from './integration/storage/memory.js';
|
package/dist/index.js
CHANGED
|
@@ -11,7 +11,7 @@ export { AgentEvents } from './harness/shared/events/agent-event-map.js';
|
|
|
11
11
|
export { DefaultSecurityGuard } from './harness/governance/security/default-security-guard.js';
|
|
12
12
|
export { BudgetPolicyEngine, DEFAULT_BUDGET } from './harness/run/budget/budget.js';
|
|
13
13
|
export { UsageLedger } from './harness/governance/accounting/usage-ledger.js';
|
|
14
|
-
export { emptyTokenUsage, makeTokenUsage, nominalTotalTokens, reportedPromptTokens, } from '@octopi-agent/core/types/
|
|
14
|
+
export { emptyTokenUsage, makeTokenUsage, nominalTotalTokens, reportedPromptTokens, } from '@octopi-agent/core/types/step.js';
|
|
15
15
|
// ============================================================
|
|
16
16
|
// Harness 层
|
|
17
17
|
// ============================================================
|
|
@@ -31,24 +31,21 @@ export { resolveEffectiveEffectPolicy, requiresJail, buildOpsJailState, isPathAl
|
|
|
31
31
|
export { ProcessSandbox, createProcessSandbox, assessL4ProcessMinimum, probeProcessIsolation, scrubEnv, killProcessTree, supervisedSpawnProfile, } from './harness/extension/execution-environment/index.js';
|
|
32
32
|
export { runWithToolLimits, resolveToolTimeoutMs, ToolTimeoutError, } from './harness/extension/execution-environment/resource-limits.js';
|
|
33
33
|
export { scanOrphanSessionUndo, } from './harness/extension/execution-environment/undo-log.js';
|
|
34
|
+
export { scanOrphanSessionTransform } from './harness/session/transform-store.js';
|
|
34
35
|
export { InProcessSessionLock } from './harness/run/concurrency/session-lease.js';
|
|
35
36
|
export { SessionAclService, BUILTIN_SESSION_ROLES, computeEffectiveRights, } from './harness/governance/session-acl/index.js';
|
|
36
37
|
export { loadPersona, composePersonas, PersonaSource } from './harness/agent/persona.js';
|
|
37
38
|
export { DefaultContextEngine } from './harness/context/default-context-engine.js';
|
|
38
39
|
export { HeuristicTokenEstimator, estimateTextTokens } from './harness/context/index.js';
|
|
39
40
|
export { DefaultMessageSelector } from './harness/context/message-selector.js';
|
|
40
|
-
export { TruncateCompressor } from './harness/context/truncate-compressor.js';
|
|
41
|
-
export { LLMSummaryCompressor } from './harness/context/llm-summarizer.js';
|
|
42
|
-
export { HybridCompressor } from './harness/context/hybrid-compressor.js';
|
|
43
41
|
export { DefaultBudgetAllocator } from './harness/context/budget-allocator.js';
|
|
44
|
-
export { SmartRouter } from './harness/context/smart-router.js';
|
|
45
42
|
export { CapabilityEnforcer, PluginTrustLevel } from './harness/governance/security/capability-enforcer.js';
|
|
46
43
|
export { PluginManager } from './harness/extension/plugin-ecosystem/plugins/manager.js';
|
|
47
|
-
export {
|
|
44
|
+
export { definePlugin } from './harness/extension/plugin-ecosystem/plugins/entry.js';
|
|
48
45
|
export { PluginApi } from './harness/extension/plugin-ecosystem/plugins/api.js';
|
|
49
46
|
export { PluginLoader } from './harness/extension/plugin-ecosystem/plugins/loader.js';
|
|
50
|
-
export {
|
|
51
|
-
export { validateManifest, parseManifest } from './harness/extension/plugin-ecosystem/plugins/manifest.js';
|
|
47
|
+
export { PluginContributionRegistry } from './harness/extension/plugin-ecosystem/plugins/contribution-registry.js';
|
|
48
|
+
export { validateManifest, parseManifest, validatePluginConfig, PLUGIN_API_VERSION } from './harness/extension/plugin-ecosystem/plugins/manifest.js';
|
|
52
49
|
export { DefaultSkillManager, FileSystemSkillSource } from './harness/extension/plugin-ecosystem/skills/manager.js';
|
|
53
50
|
export { DefaultToolBus } from './harness/extension/plugin-ecosystem/tools/tool-bus.js';
|
|
54
51
|
export { buildToolLlmParameters, prepareHandlerArgs, readToolCallPurpose, resolveToolCallPurpose, sanitizeToolJsonSchema, toolDeclaresPurpose, TOOL_PURPOSE_PARAM, TOOL_PURPOSE_SYSTEM_NOTE, } from './harness/agent/tool-purpose.js';
|
|
@@ -58,12 +55,13 @@ export { createToolSet } from './harness/extension/plugin-ecosystem/tools/tool-s
|
|
|
58
55
|
export { readGitStatusSnapshot, parsePorcelainV2 } from './harness/extension/plugin-ecosystem/tools/git-status-snapshot.js';
|
|
59
56
|
export { createSummaryPort, applyToolOutputGate, createCompactEngine } from './harness/context/capabilities/index.js';
|
|
60
57
|
export { createDefaultDocumentPort, createDocumentPortFromConfig, DocumentExtractError } from './harness/capabilities/document/index.js';
|
|
58
|
+
export { toCompactTransport } from './harness/context/capabilities/compact/types.js';
|
|
61
59
|
export { createWebSearchTool } from './harness/extension/plugin-ecosystem/tools/web-search.js';
|
|
62
60
|
export { createSessionHistoryPort, resolveHistoryAccess, } from './harness/session/history/index.js';
|
|
63
61
|
export { createSessionHistoryTools, createSessionSearchTool, createSessionReadTool, } from './harness/extension/plugin-ecosystem/tools/session-history.js';
|
|
64
62
|
export { buildFromConfig } from './harness/agent/config-bridge.js';
|
|
65
63
|
// ── Delegation(L2 委派契约层;arch/delegation.md)──
|
|
66
|
-
export { DefaultAgentRegistry, DelegationStore, DelegateService, DelegateResolutionError, InProcessTransport, RunnerChildRunPort, createChildRunExecutor, createDelegationNotifier, renderDelegationNotice, wireDelegation, createDelegationRuntime, AgentRegistryEvents, DelegationEvents, DELEGATION_SCHEMA_VERSION, } from './harness/collaboration/delegation/index.js';
|
|
64
|
+
export { DefaultAgentRegistry, DelegationStore, DelegateService, DelegateResolutionError, InProcessTransport, RunnerChildRunPort, createChildRunExecutor, createDelegationNotifier, renderDelegationNotice, wireDelegation, createDelegationRuntime, AgentRegistryEvents, DelegationEvents, DELEGATION_SCHEMA_VERSION, DEFAULT_DELEGATION_OUTPUT_CHARS, normalizeMaxOutputChars, } from './harness/collaboration/delegation/index.js';
|
|
67
65
|
// ============================================================
|
|
68
66
|
// Integration 层(engine 库能力)
|
|
69
67
|
// ============================================================
|