@octopi-agent/engine 0.102.10 → 0.121.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/builtin-model-info.js +28 -7
- package/dist/config-admin/agent-presets.d.ts +32 -0
- package/dist/config-admin/agent-presets.js +133 -0
- package/dist/config-admin/discover.d.ts +33 -4
- package/dist/config-admin/discover.js +101 -6
- package/dist/config-admin/env.d.ts +11 -0
- package/dist/config-admin/env.js +41 -0
- package/dist/config-admin/error-copy.d.ts +106 -0
- package/dist/config-admin/error-copy.js +287 -0
- package/dist/config-admin/i18n.d.ts +21 -0
- package/dist/config-admin/i18n.js +19 -0
- package/dist/config-admin/index.d.ts +6 -2
- package/dist/config-admin/index.js +3 -1
- package/dist/config-admin/model-presets.d.ts +14 -0
- package/dist/config-admin/model-presets.js +595 -70
- package/dist/config-admin/onboarding-apply.d.ts +71 -0
- package/dist/config-admin/onboarding-apply.js +235 -0
- package/dist/config-admin/onboarding.d.ts +154 -0
- package/dist/config-admin/onboarding.js +270 -0
- package/dist/config-admin/redact.d.ts +42 -9
- package/dist/config-admin/redact.js +69 -5
- package/dist/config-schema/agent.d.ts +5 -1
- package/dist/config-schema/agent.js +20 -2
- package/dist/config-schema/browser.d.ts +62 -0
- package/dist/config-schema/browser.js +89 -0
- package/dist/config-schema/context.d.ts +7 -2
- package/dist/config-schema/context.js +6 -3
- package/dist/config-schema/engine.d.ts +86 -7
- package/dist/config-schema/engine.js +9 -2
- package/dist/config-schema/governance.d.ts +12 -1
- package/dist/config-schema/governance.js +10 -2
- package/dist/config-schema/models.d.ts +12 -8
- package/dist/config-schema/models.js +16 -1
- package/dist/config-schema/run.d.ts +4 -0
- package/dist/config-schema/run.js +10 -0
- package/dist/config-schema/shared.d.ts +1 -0
- package/dist/config-schema/shared.js +4 -2
- package/dist/config-schema/substrate.d.ts +5 -0
- package/dist/config-schema/substrate.js +8 -0
- package/dist/config.d.ts +116 -10
- package/dist/config.js +109 -13
- package/dist/file-mode.d.ts +67 -0
- package/dist/file-mode.js +182 -0
- package/dist/fork-child.d.ts +82 -0
- package/dist/fork-child.js +123 -0
- package/dist/harness/activation/delegated-run.d.ts +42 -0
- package/dist/harness/activation/delegated-run.js +71 -0
- package/dist/harness/activation/dispatcher.js +4 -0
- package/dist/harness/activation/index.d.ts +1 -0
- package/dist/harness/activation/run-backend.d.ts +92 -0
- package/dist/harness/activation/run-backend.js +16 -0
- package/dist/harness/activation/run-protocol.d.ts +392 -0
- package/dist/harness/activation/run-protocol.js +19 -0
- package/dist/harness/activation/runtime.d.ts +33 -0
- package/dist/harness/activation/runtime.js +119 -28
- package/dist/harness/activation/types.d.ts +19 -2
- package/dist/harness/agent/builder.d.ts +12 -0
- package/dist/harness/agent/builder.js +78 -22
- package/dist/harness/agent/config-bridge.d.ts +10 -1
- package/dist/harness/agent/config-bridge.js +15 -3
- package/dist/harness/agent/registered-tool-adapter.d.ts +27 -0
- package/dist/harness/agent/registered-tool-adapter.js +67 -0
- package/dist/harness/agent/wire-agent-builder.d.ts +2 -0
- package/dist/harness/agent/wire-agent-builder.js +9 -2
- package/dist/harness/capabilities/document/backends/plain.js +2 -1
- package/dist/harness/capabilities/document/legacy/factory.js +3 -2
- package/dist/harness/collaboration/autonomous-subsystem/audit/reader.d.ts +17 -0
- package/dist/harness/collaboration/autonomous-subsystem/audit/reader.js +66 -36
- package/dist/harness/collaboration/autonomous-subsystem/audit/writer.d.ts +6 -2
- package/dist/harness/collaboration/autonomous-subsystem/audit/writer.js +27 -7
- package/dist/harness/collaboration/autonomous-subsystem/boundary/validator.js +13 -0
- package/dist/harness/collaboration/autonomous-subsystem/loader.js +1 -0
- package/dist/harness/collaboration/autonomous-subsystem/runtime.d.ts +11 -0
- package/dist/harness/collaboration/autonomous-subsystem/runtime.js +17 -0
- package/dist/harness/collaboration/autonomous-subsystem/sense/engine.d.ts +13 -3
- package/dist/harness/collaboration/autonomous-subsystem/sense/engine.js +48 -39
- package/dist/harness/collaboration/autonomous-subsystem/think/executor.js +3 -0
- package/dist/harness/collaboration/autonomous-subsystem/types.d.ts +4 -0
- package/dist/harness/collaboration/delegation/child-run.d.ts +9 -0
- package/dist/harness/collaboration/delegation/child-run.js +34 -2
- package/dist/harness/collaboration/delegation/registry-types.d.ts +2 -0
- package/dist/harness/collaboration/delegation/service.d.ts +9 -4
- package/dist/harness/collaboration/delegation/service.js +33 -12
- package/dist/harness/collaboration/delegation/store.d.ts +2 -0
- package/dist/harness/collaboration/delegation/store.js +1 -0
- package/dist/harness/collaboration/delegation/types.d.ts +11 -0
- package/dist/harness/collaboration/delegation/wiring.d.ts +2 -0
- package/dist/harness/collaboration/delegation/wiring.js +1 -0
- package/dist/harness/context/capabilities/compact/engine.d.ts +44 -5
- package/dist/harness/context/capabilities/compact/engine.js +127 -39
- package/dist/harness/context/capabilities/compact/index.d.ts +2 -1
- package/dist/harness/context/capabilities/compact/index.js +1 -1
- package/dist/harness/context/capabilities/compact/types.d.ts +59 -9
- package/dist/harness/context/capabilities/summary/gate.d.ts +19 -2
- package/dist/harness/context/capabilities/summary/gate.js +53 -6
- package/dist/harness/context/capabilities/summary/registry.js +20 -0
- package/dist/harness/context/capabilities/summary/tool-binding.js +16 -12
- package/dist/harness/context/capabilities/summary/tool-bindings.d.ts +13 -0
- package/dist/harness/context/capabilities/summary/tool-bindings.js +22 -0
- package/dist/harness/context/capabilities/summary/types.d.ts +16 -0
- package/dist/harness/context/constitution/default-agents.md +85 -0
- package/dist/harness/context/context-size-ledger.js +8 -1
- package/dist/harness/context/default-context-engine.d.ts +100 -6
- package/dist/harness/context/default-context-engine.js +382 -89
- package/dist/harness/context/index.d.ts +2 -1
- package/dist/harness/context/index.js +1 -0
- package/dist/harness/context/layer-health.d.ts +4 -0
- package/dist/harness/context/layer-health.js +4 -0
- package/dist/harness/context/layer-types.d.ts +57 -0
- package/dist/harness/context/layer-types.js +73 -1
- package/dist/harness/context/layers.d.ts +3 -0
- package/dist/harness/context/layers.js +13 -6
- package/dist/harness/context/prefix-fingerprint.d.ts +46 -0
- package/dist/harness/context/prefix-fingerprint.js +52 -0
- package/dist/harness/context/summarize.js +18 -0
- package/dist/harness/context/system-prompt-assembler.d.ts +2 -0
- package/dist/harness/context/system-prompt-assembler.js +5 -2
- package/dist/harness/context/tool-result-aging.d.ts +104 -16
- package/dist/harness/context/tool-result-aging.js +211 -57
- package/dist/harness/context/types.d.ts +71 -4
- package/dist/harness/context/types.js +25 -1
- package/dist/harness/extension/execution-environment/effect-policy.d.ts +4 -3
- package/dist/harness/extension/execution-environment/effect-policy.js +2 -2
- package/dist/harness/extension/execution-environment/privileged-exec.js +4 -1
- package/dist/harness/extension/execution-environment/workspace.js +1 -1
- package/dist/harness/extension/plugin-ecosystem/channel-types.d.ts +27 -1
- package/dist/harness/extension/plugin-ecosystem/channel-types.js +11 -2
- package/dist/harness/extension/plugin-ecosystem/client-tools/registry.d.ts +12 -0
- package/dist/harness/extension/plugin-ecosystem/client-tools/registry.js +25 -0
- package/dist/harness/extension/plugin-ecosystem/commands/builtin.js +28 -1
- package/dist/harness/extension/plugin-ecosystem/index.d.ts +1 -0
- package/dist/harness/extension/plugin-ecosystem/index.js +1 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/api.d.ts +168 -1
- package/dist/harness/extension/plugin-ecosystem/plugins/api.js +156 -15
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-instances.d.ts +95 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-instances.js +170 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-kinds.d.ts +178 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-kinds.js +314 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-registry.d.ts +40 -5
- package/dist/harness/extension/plugin-ecosystem/plugins/contribution-registry.js +45 -26
- package/dist/harness/extension/plugin-ecosystem/plugins/index.d.ts +1 -1
- package/dist/harness/extension/plugin-ecosystem/plugins/loader.d.ts +11 -1
- package/dist/harness/extension/plugin-ecosystem/plugins/loader.js +42 -76
- package/dist/harness/extension/plugin-ecosystem/plugins/manager.d.ts +30 -1
- package/dist/harness/extension/plugin-ecosystem/plugins/manager.js +46 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/manifest.d.ts +9 -0
- package/dist/harness/extension/plugin-ecosystem/plugins/manifest.js +19 -14
- package/dist/harness/extension/plugin-ecosystem/plugins/staging.d.ts +3 -1
- package/dist/harness/extension/plugin-ecosystem/plugins/staging.js +1 -1
- package/dist/harness/extension/plugin-ecosystem/tools/browser-types.d.ts +333 -0
- package/dist/harness/extension/plugin-ecosystem/tools/browser-types.js +16 -0
- package/dist/harness/extension/plugin-ecosystem/tools/browser.d.ts +64 -0
- package/dist/harness/extension/plugin-ecosystem/tools/browser.js +692 -0
- package/dist/harness/extension/plugin-ecosystem/tools/builtin.d.ts +0 -37
- package/dist/harness/extension/plugin-ecosystem/tools/builtin.js +108 -4
- package/dist/harness/extension/plugin-ecosystem/tools/delegation.js +18 -0
- package/dist/harness/extension/plugin-ecosystem/tools/file-edit.js +34 -0
- package/dist/harness/extension/plugin-ecosystem/tools/file-search.d.ts +0 -6
- package/dist/harness/extension/plugin-ecosystem/tools/file-search.js +57 -4
- package/dist/harness/extension/plugin-ecosystem/tools/git-tools.js +81 -13
- package/dist/harness/extension/plugin-ecosystem/tools/http.js +5 -0
- package/dist/harness/extension/plugin-ecosystem/tools/knowledge.js +13 -7
- package/dist/harness/extension/plugin-ecosystem/tools/package-tools.js +126 -14
- package/dist/harness/extension/plugin-ecosystem/tools/platform.d.ts +1 -1
- package/dist/harness/extension/plugin-ecosystem/tools/platform.js +44 -5
- package/dist/harness/extension/plugin-ecosystem/tools/tool-bus.js +10 -24
- package/dist/harness/extension/plugin-ecosystem/tools/tool-set.d.ts +7 -0
- package/dist/harness/extension/plugin-ecosystem/tools/tool-set.js +4 -0
- package/dist/harness/governance/credentials/db.d.ts +9 -0
- package/dist/harness/governance/credentials/db.js +122 -31
- package/dist/harness/governance/credentials/store.d.ts +68 -7
- package/dist/harness/governance/credentials/store.js +177 -64
- package/dist/harness/governance/credentials/types.d.ts +13 -2
- package/dist/harness/governance/index.d.ts +1 -0
- package/dist/harness/governance/index.js +1 -0
- package/dist/harness/governance/registry/db.d.ts +32 -0
- package/dist/harness/governance/registry/db.js +142 -0
- package/dist/harness/governance/registry/index.d.ts +9 -0
- package/dist/harness/governance/registry/index.js +9 -0
- package/dist/harness/governance/registry/service.d.ts +381 -0
- package/dist/harness/governance/registry/service.js +825 -0
- package/dist/harness/governance/registry/types.d.ts +77 -0
- package/dist/harness/governance/registry/types.js +7 -0
- package/dist/harness/governance/security/default-security-guard.d.ts +3 -0
- package/dist/harness/governance/security/default-security-guard.js +12 -1
- package/dist/harness/governance/security/risk-evaluator.d.ts +13 -3
- package/dist/harness/governance/security/risk-evaluator.js +307 -21
- package/dist/harness/governance/security/shell-parser-treesitter.js +12 -4
- package/dist/harness/governance/session-acl/tool-rights.d.ts +1 -0
- package/dist/harness/index.d.ts +5 -3
- package/dist/harness/index.js +2 -2
- package/dist/harness/knowledge/boot-config.d.ts +2 -0
- package/dist/harness/knowledge/boot-config.js +2 -0
- package/dist/harness/knowledge/client.d.ts +53 -7
- package/dist/harness/knowledge/client.js +77 -20
- package/dist/harness/knowledge/db.d.ts +16 -0
- package/dist/harness/knowledge/db.js +107 -41
- package/dist/harness/knowledge/engine-thread.js +5 -7
- package/dist/harness/knowledge/grounding.js +4 -1
- package/dist/harness/knowledge/http-app.d.ts +15 -0
- package/dist/harness/knowledge/http-app.js +82 -21
- package/dist/harness/knowledge/http-bridge.d.ts +15 -0
- package/dist/harness/knowledge/http-bridge.js +19 -0
- package/dist/harness/knowledge/knowledge-serve-child.js +2 -3
- package/dist/harness/knowledge/query-service.d.ts +12 -2
- package/dist/harness/knowledge/query-service.js +75 -41
- package/dist/harness/knowledge/query-worker-client.d.ts +5 -1
- package/dist/harness/knowledge/query-worker-client.js +4 -1
- package/dist/harness/knowledge/query-worker.js +5 -3
- package/dist/harness/knowledge/read-http.d.ts +2 -0
- package/dist/harness/knowledge/read-http.js +9 -2
- package/dist/harness/knowledge/retriever.d.ts +1 -1
- package/dist/harness/knowledge/retriever.js +1 -2
- package/dist/harness/knowledge/serve.d.ts +6 -1
- package/dist/harness/knowledge/serve.js +5 -6
- package/dist/harness/knowledge/source-store.d.ts +101 -5
- package/dist/harness/knowledge/source-store.js +297 -71
- package/dist/harness/knowledge/start-service-process.d.ts +27 -8
- package/dist/harness/knowledge/start-service-process.js +49 -90
- package/dist/harness/knowledge/tenant-gate.d.ts +81 -0
- package/dist/harness/knowledge/tenant-gate.js +167 -0
- package/dist/harness/knowledge/writer-service.d.ts +18 -2
- package/dist/harness/knowledge/writer-service.js +80 -16
- package/dist/harness/knowledge/writer-worker-client.d.ts +9 -2
- package/dist/harness/knowledge/writer-worker-client.js +20 -3
- package/dist/harness/knowledge/writer-worker.js +11 -4
- package/dist/harness/memory/backfill-trigger.d.ts +10 -3
- package/dist/harness/memory/backfill-trigger.js +19 -19
- package/dist/harness/memory/cognition-seeds.d.ts +45 -0
- package/dist/harness/memory/cognition-seeds.js +67 -0
- package/dist/harness/memory/cognition.d.ts +12 -3
- package/dist/harness/memory/cognition.js +55 -35
- package/dist/harness/memory/conceptualizer.d.ts +11 -1
- package/dist/harness/memory/conceptualizer.js +10 -1
- package/dist/harness/memory/context-slice.d.ts +42 -0
- package/dist/harness/memory/context-slice.js +197 -0
- package/dist/harness/memory/health-probe.d.ts +8 -2
- package/dist/harness/memory/health-probe.js +10 -13
- package/dist/harness/memory/index.d.ts +5 -1
- package/dist/harness/memory/index.js +3 -1
- package/dist/harness/memory/sqlite/agent-db.d.ts +1 -0
- package/dist/harness/memory/sqlite/agent-db.js +9 -8
- package/dist/harness/memory/sqlite/cognition-store.d.ts +26 -3
- package/dist/harness/memory/sqlite/cognition-store.js +103 -45
- package/dist/harness/memory/sqlite/memory-store.js +4 -0
- package/dist/harness/memory/sqlite/sqlite-vec.d.ts +24 -1
- package/dist/harness/memory/sqlite/sqlite-vec.js +37 -1
- package/dist/harness/memory/types.d.ts +18 -2
- package/dist/harness/observability/observer/hub.d.ts +10 -0
- package/dist/harness/observability/observer/hub.js +95 -2
- package/dist/harness/run/agent/agent.js +3 -2
- package/dist/harness/run/concurrency/tool-validator.js +4 -3
- package/dist/harness/run/reliability/run-agent.d.ts +22 -0
- package/dist/harness/run/reliability/run-agent.js +79 -10
- package/dist/harness/run/run-host.d.ts +302 -0
- package/dist/harness/run/run-host.js +978 -0
- package/dist/harness/run/run-scope.d.ts +11 -0
- package/dist/harness/run/run-scope.js +19 -1
- package/dist/harness/run/runner.d.ts +149 -22
- package/dist/harness/run/runner.js +352 -35
- package/dist/harness/session/in-memory-store.js +13 -1
- package/dist/harness/session/schedules/service.d.ts +10 -2
- package/dist/harness/session/schedules/service.js +13 -2
- package/dist/harness/session/tasks/tools.js +12 -0
- package/dist/harness/session/types.d.ts +10 -14
- package/dist/harness/shared/events/agent-event-map.d.ts +29 -0
- package/dist/harness/shared/types/agent-definition.d.ts +6 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +2 -1
- package/dist/integration/agent-runtime/channel-message-source.d.ts +3 -1
- package/dist/integration/agent-runtime/channel-message-source.js +4 -3
- package/dist/integration/browser/camoufox.d.ts +40 -0
- package/dist/integration/browser/camoufox.js +80 -0
- package/dist/integration/browser/index.d.ts +91 -0
- package/dist/integration/browser/index.js +110 -0
- package/dist/integration/browser/install.d.ts +47 -0
- package/dist/integration/browser/install.js +214 -0
- package/dist/integration/browser/playwright.d.ts +224 -0
- package/dist/integration/browser/playwright.js +925 -0
- package/dist/integration/browser/service.d.ts +41 -0
- package/dist/integration/browser/service.js +181 -0
- package/dist/integration/browser/stealth.d.ts +42 -0
- package/dist/integration/browser/stealth.js +104 -0
- package/dist/integration/providers/anthropic-message-normalize.d.ts +20 -0
- package/dist/integration/providers/anthropic-message-normalize.js +48 -0
- package/dist/integration/providers/anthropic.js +27 -2
- package/dist/integration/providers/fetch-timeout.d.ts +17 -0
- package/dist/integration/providers/fetch-timeout.js +24 -0
- package/dist/integration/providers/openai.d.ts +8 -0
- package/dist/integration/providers/openai.js +41 -1
- package/dist/integration/providers/wire-dump-diff.js +2 -1
- package/dist/integration/providers/wire-dump.d.ts +56 -2
- package/dist/integration/providers/wire-dump.js +119 -6
- package/dist/integration/storage/archive-manager.d.ts +14 -2
- package/dist/integration/storage/archive-manager.js +24 -8
- package/dist/integration/storage/atomic-tmp.d.ts +12 -0
- package/dist/integration/storage/atomic-tmp.js +36 -0
- package/dist/integration/storage/jsonl.d.ts +9 -0
- package/dist/integration/storage/jsonl.js +137 -38
- package/dist/integration/storage/session-index.d.ts +5 -0
- package/dist/integration/storage/session-index.js +25 -4
- package/dist/integration/tools/assemble.d.ts +50 -0
- package/dist/integration/tools/assemble.js +137 -0
- package/dist/paths.d.ts +18 -0
- package/dist/paths.js +36 -0
- package/dist/subsystems/cognition-steward/conceptualize/config.yaml +3 -1
- package/dist/subsystems/cognition-steward/conceptualize/handler.js +74 -5
- package/dist/subsystems/cognition-steward/consolidate/SUBSYSTEM.md +3 -2
- package/dist/subsystems/cognition-steward/consolidate/config.yaml +11 -2
- package/dist/subsystems/cognition-steward/consolidate/handler.d.ts +6 -3
- package/dist/subsystems/cognition-steward/consolidate/handler.js +266 -28
- package/dist/subsystems/memory-steward/backfill/handler.js +3 -2
- package/dist/subsystems/memory-steward/govern/config.yaml +6 -1
- package/dist/subsystems/wisdom-steward/attribute/config.yaml +5 -1
- package/dist/subsystems/wisdom-steward/formation/config.yaml +3 -0
- package/dist/subsystems/wisdom-steward/govern/config.yaml +6 -1
- package/package.json +5 -3
|
@@ -20,46 +20,9 @@
|
|
|
20
20
|
* - 建议在 ToolPolicy 的 deny 列表中禁用不需要的工具
|
|
21
21
|
*/
|
|
22
22
|
import type { RegisteredTool } from '@octopi-agent/core/types.js';
|
|
23
|
-
/**
|
|
24
|
-
* Shell 工具 — 执行 shell 命令
|
|
25
|
-
*
|
|
26
|
-
* 参数:
|
|
27
|
-
* - command (string, required): 要执行的 shell 命令
|
|
28
|
-
* - cwd (string, optional): 工作目录
|
|
29
|
-
* - timeout (number, optional): 超时时间(毫秒,默认 60000)
|
|
30
|
-
*
|
|
31
|
-
* 返回:
|
|
32
|
-
* - stdout: 标准输出
|
|
33
|
-
* - stderr: 标准错误
|
|
34
|
-
* - exitCode: 退出码
|
|
35
|
-
* - durationMs: 执行耗时
|
|
36
|
-
* - shell: 实际使用的 shell(kind/executable)
|
|
37
|
-
* - hints: 沙箱归因提示(仅当 jail 拒绝并已归因时出现,如 setuid exec)
|
|
38
|
-
*/
|
|
39
23
|
export declare function createShellTool(options?: {
|
|
40
24
|
summary?: import('../../../context/capabilities/summary/index.js').ToolSummarySupport;
|
|
41
25
|
}): RegisteredTool;
|
|
42
|
-
/**
|
|
43
|
-
* File Read 工具 — 读取文件内容
|
|
44
|
-
*
|
|
45
|
-
* 参数:
|
|
46
|
-
* - path (string, required): 文件路径
|
|
47
|
-
* - offset (number, optional): 起始行号(1-indexed)
|
|
48
|
-
* - limit (number, optional): 最大行数
|
|
49
|
-
*
|
|
50
|
-
* 返回:
|
|
51
|
-
* - content: 文件内容
|
|
52
|
-
* - totalLines: 文件总行数
|
|
53
|
-
* - truncated: 是否被截断
|
|
54
|
-
*
|
|
55
|
-
* 大文件:kind_sensitive + L1 硬顶;code 默认不 L2 摘要。
|
|
56
|
-
*/
|
|
57
|
-
/**
|
|
58
|
-
* 创建 file_read 工具
|
|
59
|
-
*
|
|
60
|
-
* @param options - 可选 SummaryPort / toolBindings 注入(与 octopi.json summary.tools 同源)
|
|
61
|
-
* @returns RegisteredTool
|
|
62
|
-
*/
|
|
63
26
|
export declare function createFileReadTool(options?: {
|
|
64
27
|
summary?: import('../../../context/capabilities/summary/index.js').ToolSummarySupport;
|
|
65
28
|
}): RegisteredTool;
|
|
@@ -50,6 +50,78 @@ import { matchesDenyPattern } from '../../../shared/paths/glob.js';
|
|
|
50
50
|
* - shell: 实际使用的 shell(kind/executable)
|
|
51
51
|
* - hints: 沙箱归因提示(仅当 jail 拒绝并已归因时出现,如 setuid exec)
|
|
52
52
|
*/
|
|
53
|
+
/**
|
|
54
|
+
* shell 短输出阈值:低于此值时**保留完整 stdout**(而不是首尾行)。
|
|
55
|
+
*
|
|
56
|
+
* 注意这里不是「不老化」——不老化意味着返回原文,会连 `isolation`/`shell`
|
|
57
|
+
* 这些逐条重复的元数据一起留下(实测每条 338 字符),26 条短输出累计 8,788
|
|
58
|
+
* 字符永久驻留。老化恒定执行,只是短输出不必截行。
|
|
59
|
+
*/
|
|
60
|
+
const SHELL_AGING_FULL_KEEP_CHARS = 600;
|
|
61
|
+
/** 老化后保留的首尾行数:尾部多留——错误与汇总通常在末尾 */
|
|
62
|
+
const SHELL_AGING_HEAD_LINES = 3;
|
|
63
|
+
const SHELL_AGING_TAIL_LINES = 5;
|
|
64
|
+
/** 指针里每行/整体长度上限(防单行超长把指针撑成正文) */
|
|
65
|
+
const SHELL_AGING_LINE_CHARS = 160;
|
|
66
|
+
const SHELL_AGING_STDERR_CHARS = 300;
|
|
67
|
+
/**
|
|
68
|
+
* shell 结果老化:保留「够不够成功 + 输出长什么样」,丢掉重复元数据
|
|
69
|
+
*
|
|
70
|
+
* 丢弃依据(2026-11-13 实测 35 条未老化结果):
|
|
71
|
+
* - `isolation`(315 字符/条,11,025 合计):同一会话内**只有一种取值**,纯噪音;
|
|
72
|
+
* - `shell`(43 字符/条):`{kind, executable}` 全程不变;
|
|
73
|
+
* - `durationMs`:对历史回看无意义。
|
|
74
|
+
* 三者合计占 shell 结果的 36%。
|
|
75
|
+
*
|
|
76
|
+
* 保留的是「只有结果才知道」的事实:
|
|
77
|
+
* - `exitCode`:成功与否;`undefined` 表示被终止、没有退出码;
|
|
78
|
+
* - `terminated` / `terminateReason`:输出可能不完整——模型必须知道,否则会把
|
|
79
|
+
* 半截输出当完整结果(这是 shell 最危险的误读);
|
|
80
|
+
* - `rawStdoutLength`:闸门截断前的真实长度,「还有多少没看到」的唯一依据;
|
|
81
|
+
* - `stderr`:非空时保留开头——失败原因通常在此。
|
|
82
|
+
*
|
|
83
|
+
* @param result - shell 的原始返回对象
|
|
84
|
+
* @returns 一段事实摘要;短输出返回 undefined(保留原文)
|
|
85
|
+
*/
|
|
86
|
+
function ageShellResult(result) {
|
|
87
|
+
if (!result || typeof result !== 'object')
|
|
88
|
+
return undefined;
|
|
89
|
+
const r = result;
|
|
90
|
+
const stdout = typeof r.stdout === 'string' ? r.stdout : undefined;
|
|
91
|
+
if (stdout === undefined)
|
|
92
|
+
return undefined;
|
|
93
|
+
const raw = typeof r.rawStdoutLength === 'number' ? r.rawStdoutLength : stdout.length;
|
|
94
|
+
const stderr = typeof r.stderr === 'string' ? r.stderr.trim() : '';
|
|
95
|
+
const terminated = r.terminated === true;
|
|
96
|
+
const reason = typeof r.terminateReason === 'string' ? r.terminateReason : '';
|
|
97
|
+
// 短输出:保留完整正文(仍然去掉元数据),不必截成首尾行
|
|
98
|
+
const keepFull = stdout.length <= SHELL_AGING_FULL_KEEP_CHARS && !terminated;
|
|
99
|
+
const code = typeof r.exitCode === 'number' ? `exit ${r.exitCode}` : 'exit code unknown';
|
|
100
|
+
const head = [];
|
|
101
|
+
if (terminated)
|
|
102
|
+
head.push(`terminated${reason ? ` (${reason})` : ''}`);
|
|
103
|
+
if (raw > stdout.length)
|
|
104
|
+
head.push(`output ${raw} chars, shown ${stdout.length}`);
|
|
105
|
+
const filter = (arr) => arr.filter((l) => l.trim() !== '');
|
|
106
|
+
const trim = (l) => l.length <= SHELL_AGING_LINE_CHARS ? l : `${l.slice(0, SHELL_AGING_LINE_CHARS)}…`;
|
|
107
|
+
const lines = filter(stdout.split('\n'));
|
|
108
|
+
const headLines = keepFull ? lines.map(trim) : lines.slice(0, SHELL_AGING_HEAD_LINES).map(trim);
|
|
109
|
+
const tailLines = !keepFull && lines.length > SHELL_AGING_HEAD_LINES + SHELL_AGING_TAIL_LINES
|
|
110
|
+
? lines.slice(-SHELL_AGING_TAIL_LINES).map(trim)
|
|
111
|
+
: [];
|
|
112
|
+
const parts = [`[aged] shell ${code}`];
|
|
113
|
+
if (head.length)
|
|
114
|
+
parts[0] += `, ${head.join(', ')}`;
|
|
115
|
+
if (stderr) {
|
|
116
|
+
const s = stderr.length <= SHELL_AGING_STDERR_CHARS ? stderr : `${stderr.slice(0, SHELL_AGING_STDERR_CHARS)}…`;
|
|
117
|
+
parts.push(`stderr: ${s.split('\n').slice(0, 3).map(trim).join(' / ')}`);
|
|
118
|
+
}
|
|
119
|
+
if (headLines.length)
|
|
120
|
+
parts.push(`head: ${headLines.join(' ⏎ ')}`);
|
|
121
|
+
if (tailLines.length)
|
|
122
|
+
parts.push(`tail: ${tailLines.join(' ⏎ ')}`);
|
|
123
|
+
return parts.join('\n');
|
|
124
|
+
}
|
|
53
125
|
export function createShellTool(options) {
|
|
54
126
|
const shell = resolvePlatformShell();
|
|
55
127
|
const syntaxHint = shell.kind === 'bash'
|
|
@@ -80,6 +152,7 @@ export function createShellTool(options) {
|
|
|
80
152
|
// D1: tool-bus outer watchdog ceiling; ProcessSandbox enforces the real kill.
|
|
81
153
|
timeoutMs: 600_000,
|
|
82
154
|
},
|
|
155
|
+
ageResult: ({ result }) => ageShellResult(result),
|
|
83
156
|
handler: async (args, context) => {
|
|
84
157
|
const command = args.command;
|
|
85
158
|
const cwd = args.cwd ?? context?.cwd ?? process.cwd();
|
|
@@ -278,6 +351,34 @@ export function createShellTool(options) {
|
|
|
278
351
|
* @param options - 可选 SummaryPort / toolBindings 注入(与 octopi.json summary.tools 同源)
|
|
279
352
|
* @returns RegisteredTool
|
|
280
353
|
*/
|
|
354
|
+
/**
|
|
355
|
+
* file_read 结果老化:正文全丢,只留「读的是哪一段」
|
|
356
|
+
*
|
|
357
|
+
* 正文必须丢:留着头几百字符会被读成「文件开头就是这些」,而实际内容可能已被后续
|
|
358
|
+
* 编辑改动。指针明确要求重读,时态才不歧义。
|
|
359
|
+
*
|
|
360
|
+
* 保留 `fromLine`/`toLine`/`totalLines`/`truncated`:这是「重读哪一段」的唯一依据,
|
|
361
|
+
* 也是「当初是否读全」的证据。摘要结果(`summary.applied`)不老化——它已被提炼,
|
|
362
|
+
* 丢弃后要再跑一次摘要才能拿回同等信息,成本远高于保留。
|
|
363
|
+
*
|
|
364
|
+
* @param result - file_read 的原始返回对象
|
|
365
|
+
* @returns 一行定位事实;已摘要/字段不全时 undefined(保留原文)
|
|
366
|
+
*/
|
|
367
|
+
function ageFileReadResult(result) {
|
|
368
|
+
if (!result || typeof result !== 'object')
|
|
369
|
+
return undefined;
|
|
370
|
+
const r = result;
|
|
371
|
+
const summary = r.summary;
|
|
372
|
+
if (summary?.applied === true)
|
|
373
|
+
return undefined;
|
|
374
|
+
const from = r.fromLine;
|
|
375
|
+
const to = r.toLine;
|
|
376
|
+
const total = r.totalLines;
|
|
377
|
+
if (typeof from !== 'number' || typeof to !== 'number' || typeof total !== 'number')
|
|
378
|
+
return undefined;
|
|
379
|
+
const truncated = r.truncated === true ? ', truncated' : '';
|
|
380
|
+
return `[aged] file_read lines ${from}-${to}/${total}${truncated} — call file_read for current text`;
|
|
381
|
+
}
|
|
281
382
|
export function createFileReadTool(options) {
|
|
282
383
|
return {
|
|
283
384
|
definition: {
|
|
@@ -287,7 +388,7 @@ export function createFileReadTool(options) {
|
|
|
287
388
|
parameters: {
|
|
288
389
|
path: {
|
|
289
390
|
type: 'string',
|
|
290
|
-
description: 'Path to the file to read',
|
|
391
|
+
description: 'Path to the file to read (~/… expands to the user home, subject to path containment)',
|
|
291
392
|
required: true,
|
|
292
393
|
},
|
|
293
394
|
offset: {
|
|
@@ -318,6 +419,7 @@ export function createFileReadTool(options) {
|
|
|
318
419
|
},
|
|
319
420
|
},
|
|
320
421
|
},
|
|
422
|
+
ageResult: ({ result }) => ageFileReadResult(result),
|
|
321
423
|
handler: async (args, context) => {
|
|
322
424
|
const { readFile } = await import('node:fs/promises');
|
|
323
425
|
const pathModule = await import('node:path');
|
|
@@ -388,7 +490,7 @@ export function createFileWriteTool() {
|
|
|
388
490
|
parameters: {
|
|
389
491
|
path: {
|
|
390
492
|
type: 'string',
|
|
391
|
-
description: 'Path to the file to write',
|
|
493
|
+
description: 'Path to the file to write (~/… expands to the user home, subject to path containment)',
|
|
392
494
|
required: true,
|
|
393
495
|
},
|
|
394
496
|
content: {
|
|
@@ -404,6 +506,8 @@ export function createFileWriteTool() {
|
|
|
404
506
|
},
|
|
405
507
|
// 整文件覆写无合并语义:所在 tool_call 批次整体串行,防同路径并行写互相抹掉
|
|
406
508
|
executionMode: 'sequential',
|
|
509
|
+
// content 是整份文件正文:占空间,且文件后续被改后就变成与当前内容不符的过期副本
|
|
510
|
+
ageArgs: true,
|
|
407
511
|
handler: async (args, context) => {
|
|
408
512
|
const { mkdir } = await import('node:fs/promises');
|
|
409
513
|
const { dirname } = await import('node:path');
|
|
@@ -475,7 +579,7 @@ export function createFileDeleteTool() {
|
|
|
475
579
|
parameters: {
|
|
476
580
|
path: {
|
|
477
581
|
type: 'string',
|
|
478
|
-
description: 'Path to the file to delete',
|
|
582
|
+
description: 'Path to the file to delete (~/… expands to the user home, subject to path containment)',
|
|
479
583
|
required: true,
|
|
480
584
|
},
|
|
481
585
|
},
|
|
@@ -612,7 +716,7 @@ export function createFileListTool(options) {
|
|
|
612
716
|
parameters: {
|
|
613
717
|
path: {
|
|
614
718
|
type: 'string',
|
|
615
|
-
description: 'Directory path to list (optional; default "." = workspace cwd)',
|
|
719
|
+
description: 'Directory path to list (optional; default "." = workspace cwd; ~/… expands to the user home, subject to path containment)',
|
|
616
720
|
},
|
|
617
721
|
recursive: {
|
|
618
722
|
type: 'boolean',
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
* 工具与 `DelegateService` 分离:服务可被嵌入方直接用,不经 LLM 工具面。
|
|
11
11
|
*/
|
|
12
12
|
import { DelegateResolutionError } from '../../../collaboration/delegation/service.js';
|
|
13
|
+
import { getRunScope } from '../../../run/run-scope.js';
|
|
13
14
|
import { DEFAULT_DELEGATION_OUTPUT_CHARS, isTerminalDelegationStatus, } from '../../../collaboration/delegation/types.js';
|
|
14
15
|
/** 委派单摘要(进 LLM 结果,字段名 snake_case 对齐其他工具) */
|
|
15
16
|
function delegationSummary(d) {
|
|
@@ -18,6 +19,7 @@ function delegationSummary(d) {
|
|
|
18
19
|
status: d.status,
|
|
19
20
|
target: d.target.agentId ?? d.resolvedAgentId ?? d.target.trait,
|
|
20
21
|
resolved_agent_id: d.resolvedAgentId,
|
|
22
|
+
title: d.title,
|
|
21
23
|
task: d.task,
|
|
22
24
|
depth: d.depth,
|
|
23
25
|
child_session_id: d.childSessionId,
|
|
@@ -105,6 +107,12 @@ export function createDelegateDispatchTool(service) {
|
|
|
105
107
|
description: 'What the child should accomplish (goes into the child user message)',
|
|
106
108
|
required: true,
|
|
107
109
|
},
|
|
110
|
+
title: {
|
|
111
|
+
type: 'string',
|
|
112
|
+
description: 'Short session title for the child session (plain text single line, ≤120 chars; ' +
|
|
113
|
+
'shown in session lists and the sub-session panel). Set it explicitly when dispatching.',
|
|
114
|
+
required: true,
|
|
115
|
+
},
|
|
108
116
|
input: {
|
|
109
117
|
type: 'string',
|
|
110
118
|
description: 'Explicit input material for the task. The child does NOT inherit your context.',
|
|
@@ -144,6 +152,11 @@ export function createDelegateDispatchTool(service) {
|
|
|
144
152
|
};
|
|
145
153
|
}
|
|
146
154
|
const contextMode = args.context === 'fork' ? 'fork' : 'clean';
|
|
155
|
+
// 非字符串一律拒绝(数字/对象强转会变出假标题);空白压缩后为空也拒绝
|
|
156
|
+
const title = typeof args.title === 'string' ? args.title.replace(/\s+/g, ' ').trim() : '';
|
|
157
|
+
if (!title) {
|
|
158
|
+
return { ok: false, error: 'delegate_dispatch requires `title` (non-empty session title)' };
|
|
159
|
+
}
|
|
147
160
|
const timeoutMs = args.timeout_ms != null ? Number(args.timeout_ms) : undefined;
|
|
148
161
|
const maxSteps = args.max_steps != null ? Number(args.max_steps) : undefined;
|
|
149
162
|
const maxTokens = args.max_tokens != null ? Number(args.max_tokens) : undefined;
|
|
@@ -156,11 +169,16 @@ export function createDelegateDispatchTool(service) {
|
|
|
156
169
|
agentId: context.agentId,
|
|
157
170
|
sessionId: context.sessionId,
|
|
158
171
|
runId: context.runId ?? '',
|
|
172
|
+
// §8 委派限本租户:父 run 归属随调用传播(无归属 = DEFAULT 存量域)
|
|
173
|
+
...(getRunScope()?.principal?.tenantId === undefined
|
|
174
|
+
? {}
|
|
175
|
+
: { tenantId: getRunScope().principal.tenantId }),
|
|
159
176
|
},
|
|
160
177
|
// D3 权限随调用传播:父的有效权限作为子的天花板,不得借委派提权
|
|
161
178
|
parentRights: await readRunSessionRights(),
|
|
162
179
|
target: agent ? { agentId: agent } : { trait },
|
|
163
180
|
task: String(args.task ?? ''),
|
|
181
|
+
title,
|
|
164
182
|
input: String(args.input ?? ''),
|
|
165
183
|
maxOutputChars,
|
|
166
184
|
context: contextMode,
|
|
@@ -13,6 +13,39 @@
|
|
|
13
13
|
import { containmentOptions, isPathUnderRoots, isUnderAttachmentRoot, isUnderSessionUndoRoot, resolveToolPath, } from './platform.js';
|
|
14
14
|
import { gateEffect } from '../../execution-environment/effect-policy.js';
|
|
15
15
|
import { detectEol, oldTextCandidates, toEol } from './eol.js';
|
|
16
|
+
/**
|
|
17
|
+
* file_edit 结果老化:只保留「执行事实」,丢掉与参数重复或已过时的部分
|
|
18
|
+
*
|
|
19
|
+
* 为什么只留这么多(2026-11-13 拍板):`assistant.tool_calls` 里已原样保留
|
|
20
|
+
* `old_text`/`new_text`(参数老化默认关闭),因此结果侧再放一遍 `preview.old`/
|
|
21
|
+
* `preview.new` 是纯重复;`preview.before`/`preview.after` 是**编辑前**的文件内容,
|
|
22
|
+
* 成功编辑后必然不成立,属于会误导的过期副本。真正只有结果才知道的是执行事实:
|
|
23
|
+
*
|
|
24
|
+
* - `matchCount` / `replacedCount`:`matchCount: 9, replacedCount: 1` 意味着还有
|
|
25
|
+
* 8 处同形文本未改——参数里看不到这个信息;
|
|
26
|
+
* - 失败原因(error 原文,红线:不截断、不改写)。
|
|
27
|
+
*
|
|
28
|
+
* @param result - file_edit 的原始返回对象
|
|
29
|
+
* @returns 供模型读取的一行事实;无法识别时 undefined(回落默认指针)
|
|
30
|
+
*/
|
|
31
|
+
function ageFileEditResult(result) {
|
|
32
|
+
if (!result || typeof result !== 'object')
|
|
33
|
+
return undefined;
|
|
34
|
+
const r = result;
|
|
35
|
+
const base = String(r.path ?? '')
|
|
36
|
+
.split('/')
|
|
37
|
+
.pop();
|
|
38
|
+
if (!base)
|
|
39
|
+
return undefined;
|
|
40
|
+
const matched = typeof r.matchCount === 'number' ? r.matchCount : undefined;
|
|
41
|
+
const replaced = typeof r.replacedCount === 'number' ? r.replacedCount : undefined;
|
|
42
|
+
if (matched === undefined || replaced === undefined)
|
|
43
|
+
return undefined;
|
|
44
|
+
const dryRun = r.dryRun === true ? ' (dry run)' : '';
|
|
45
|
+
// 只在「匹配多处但只改一处」时显式提示,避免默认路径制造噪音
|
|
46
|
+
const partial = matched > replaced ? ` — ${matched - replaced} other match(es) left unchanged` : '';
|
|
47
|
+
return `[aged] file_edit ${replaced}/${matched} replaced in ${base}${dryRun}${partial}`;
|
|
48
|
+
}
|
|
16
49
|
export function createFileEditTool() {
|
|
17
50
|
return {
|
|
18
51
|
definition: {
|
|
@@ -47,6 +80,7 @@ export function createFileEditTool() {
|
|
|
47
80
|
},
|
|
48
81
|
// 同文件并发读改写互相覆盖(丢编辑):所在 tool_call 批次整体串行
|
|
49
82
|
executionMode: 'sequential',
|
|
83
|
+
ageResult: ({ result }) => ageFileEditResult(result),
|
|
50
84
|
handler: async (args, context) => {
|
|
51
85
|
const { readFile } = await import('node:fs/promises');
|
|
52
86
|
const rawPath = args.path;
|
|
@@ -22,12 +22,6 @@
|
|
|
22
22
|
*/
|
|
23
23
|
import type { RegisteredTool } from '@octopi-agent/core/types.js';
|
|
24
24
|
import { type ToolSummarySupport } from '../../../context/capabilities/summary/index.js';
|
|
25
|
-
/**
|
|
26
|
-
* 创建 file_search 工具
|
|
27
|
-
*
|
|
28
|
-
* @param options - 可选 summary support(L1 预算 binding;file_search 恒不跑 L2)
|
|
29
|
-
* @returns RegisteredTool
|
|
30
|
-
*/
|
|
31
25
|
export declare function createFileSearchTool(options?: {
|
|
32
26
|
summary?: ToolSummarySupport;
|
|
33
27
|
}): RegisteredTool;
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
* - 忽略常见无关目录(node_modules, .git 等)
|
|
21
21
|
* - 零结果时返回 diagnostics + hints,便于调用方自纠
|
|
22
22
|
*/
|
|
23
|
+
import { ELIDED_PREVIEW_MARK, TRUNCATED_MARK } from '@octopi-agent/core/elision.js';
|
|
23
24
|
import { resolveSupportBinding, } from '../../../context/capabilities/summary/index.js';
|
|
24
25
|
import { containmentOptions, resolveToolPath, } from './platform.js';
|
|
25
26
|
import { globToPathRegex, matchesDenyPattern } from '../../../shared/paths/glob.js';
|
|
@@ -32,10 +33,10 @@ const IGNORED_DIRS = new Set([
|
|
|
32
33
|
const DEFAULT_MAX_FILE_BYTES = 50_000_000;
|
|
33
34
|
/** L1 收缩后 content 预览行的字符上限(超长行是单条膨胀元凶;定位符不受影响) */
|
|
34
35
|
const CONTENT_PREVIEW_CHARS = 200;
|
|
35
|
-
/** content 行机械截断标记(机械截断 ≠
|
|
36
|
-
const CONTENT_TRUNCATED_MARK =
|
|
37
|
-
/** 预览整条省略占位(file+line
|
|
38
|
-
const PREVIEW_OMITTED =
|
|
36
|
+
/** content 行机械截断标记(机械截断 ≠ 摘要改写;词汇表单一来源:core/elision) */
|
|
37
|
+
const CONTENT_TRUNCATED_MARK = TRUNCATED_MARK;
|
|
38
|
+
/** 预览整条省略占位(file+line 永远全保;词汇表单一来源:core/elision) */
|
|
39
|
+
const PREVIEW_OMITTED = ELIDED_PREVIEW_MARK;
|
|
39
40
|
/** file_search L1 缺省预算(与 summary registry 缺省一致;可经 summary.tools.file_search.maxReturnChars 覆盖) */
|
|
40
41
|
const DEFAULT_MAX_RETURN_CHARS = 8000;
|
|
41
42
|
/**
|
|
@@ -44,6 +45,56 @@ const DEFAULT_MAX_RETURN_CHARS = 8000;
|
|
|
44
45
|
* @param options - 可选 summary support(L1 预算 binding;file_search 恒不跑 L2)
|
|
45
46
|
* @returns RegisteredTool
|
|
46
47
|
*/
|
|
48
|
+
/**
|
|
49
|
+
* 结果老化:把搜索结果压成「按文件聚合的行号清单」
|
|
50
|
+
*
|
|
51
|
+
* 依据(default-web-1794346953041 实测,277 次 681,273 字符):
|
|
52
|
+
* - `before`/`after` 上下文行占 `matches` 的 58.6%(243,857 字符)——搜索时刻的文件摘录,
|
|
53
|
+
* 行号就是回到原文的路径;
|
|
54
|
+
* - `content` 是已截断的匹配行(工具自己的 L1 已声明「file+line 清单全保,body 是预览」);
|
|
55
|
+
* - `matchedFiles` 277 条中 230 条可由 `matches` 聚合推出,其余 47 条只差排序、计数完全一致;
|
|
56
|
+
* - `diagnostics` 里 45% 是入参回显(root/patterns/compiledPatterns/glob/patternMode),
|
|
57
|
+
* 且 `patterns` 与 `compiledPatterns` 在 240/277 条完全相同。
|
|
58
|
+
*
|
|
59
|
+
* 保留「回到现场」的最小充分集:**哪个文件、哪几行、原始命中总数、是否被截断**。
|
|
60
|
+
* 逐条列 `file` 会重复 N 次(实测 58,444 字符),按文件聚合后均值降到 101 字符
|
|
61
|
+
* (默认机械指针 282/条)——这是「per-tool ager 优于默认规则」的前提。
|
|
62
|
+
*
|
|
63
|
+
* 不暗示「重跑可得同一结果」:文件此后可能被编辑、行号会漂移,
|
|
64
|
+
* 指针只陈述「当时在此处命中」(与 git_diff 固定 sha 才保留原文的判据同源)。
|
|
65
|
+
*
|
|
66
|
+
* @param result - file_search 的原始结果
|
|
67
|
+
* @returns 聚合指针;结构不符时返回 undefined(保留原文)
|
|
68
|
+
*/
|
|
69
|
+
function ageFileSearchResult(result) {
|
|
70
|
+
if (!result || typeof result !== 'object')
|
|
71
|
+
return undefined;
|
|
72
|
+
const r = result;
|
|
73
|
+
const matches = r.matches;
|
|
74
|
+
if (!Array.isArray(matches))
|
|
75
|
+
return undefined;
|
|
76
|
+
// 按首次出现顺序聚合,避免排序引入不确定性(纯函数要求逐字节稳定)
|
|
77
|
+
const byFile = new Map();
|
|
78
|
+
for (const m of matches) {
|
|
79
|
+
const file = m?.file;
|
|
80
|
+
const line = m?.line;
|
|
81
|
+
if (typeof file !== 'string' || typeof line !== 'number')
|
|
82
|
+
continue;
|
|
83
|
+
const lines = byFile.get(file);
|
|
84
|
+
if (lines)
|
|
85
|
+
lines.push(line);
|
|
86
|
+
else
|
|
87
|
+
byFile.set(file, [line]);
|
|
88
|
+
}
|
|
89
|
+
const shown = matches.length;
|
|
90
|
+
// totalMatches 是「已返回条数」,max_results 截断时真实命中更多——如实标注下界
|
|
91
|
+
const count = r.truncated === true ? `>=${shown} (truncated)` : `${shown}`;
|
|
92
|
+
const head = `[aged] file_search ${count} hits in ${byFile.size} file(s)`;
|
|
93
|
+
if (byFile.size === 0)
|
|
94
|
+
return `${head} — no locators retained`;
|
|
95
|
+
const body = Array.from(byFile, ([file, lines]) => ` ${file}: ${lines.join(', ')}`).join('\n');
|
|
96
|
+
return `${head}\n${body}`;
|
|
97
|
+
}
|
|
47
98
|
export function createFileSearchTool(options) {
|
|
48
99
|
return {
|
|
49
100
|
definition: {
|
|
@@ -113,6 +164,8 @@ export function createFileSearchTool(options) {
|
|
|
113
164
|
},
|
|
114
165
|
timeoutMs: 30_000,
|
|
115
166
|
},
|
|
167
|
+
// 历史视图收敛为定位符清单(file+line 全保,body 与入参回显可弃)
|
|
168
|
+
ageResult: ({ result }) => ageFileSearchResult(result),
|
|
116
169
|
handler: async (args, context) => {
|
|
117
170
|
const { open, readdir, stat } = await import('node:fs/promises');
|
|
118
171
|
const { basename, extname, join, relative } = await import('node:path');
|
|
@@ -15,8 +15,8 @@ function resolveCwd(context, raw) {
|
|
|
15
15
|
}
|
|
16
16
|
return abs;
|
|
17
17
|
}
|
|
18
|
-
function assertPathSafe(raw, context, label) {
|
|
19
|
-
const abs = resolveToolPath(raw,
|
|
18
|
+
function assertPathSafe(raw, context, label, baseCwd) {
|
|
19
|
+
const abs = resolveToolPath(raw, baseCwd, containmentOptions(context));
|
|
20
20
|
if (isUnderAttachmentRoot(abs, context?.attachmentRoots)) {
|
|
21
21
|
throw new Error(`session attachments are read-only; cannot ${label} under attachments root`);
|
|
22
22
|
}
|
|
@@ -28,15 +28,20 @@ function assertPathSafe(raw, context, label) {
|
|
|
28
28
|
/**
|
|
29
29
|
* Pathspec for git porcelain.
|
|
30
30
|
*
|
|
31
|
-
* Simple paths are L2-resolved
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
31
|
+
* Simple paths are L2-resolved against the repository cwd the git command runs
|
|
32
|
+
* in — not the session workspace cwd (`context.cwd`). With an explicit
|
|
33
|
+
* `cwd: /repo` and `paths: ["CHANGELOG.md"]` the old workspace-based resolve
|
|
34
|
+
* produced `/workspace/CHANGELOG.md`, which git rejected as "outside
|
|
35
|
+
* repository". Containment still applies (`allowRoots`, denylist).
|
|
36
|
+
* Glob/magic specs (src/*.ts, :(exclude)...) must stay relative -
|
|
37
|
+
* absolute-resolving them turns the pattern into a literal path and silently
|
|
38
|
+
* matches nothing. Those pass through after a .. / absolute / NUL ban; cwd is
|
|
39
|
+
* already L2-contained.
|
|
35
40
|
*/
|
|
36
|
-
function toGitPathspec(raw, context, label) {
|
|
41
|
+
function toGitPathspec(raw, context, label, baseCwd) {
|
|
37
42
|
const isMagic = raw.startsWith(':(') || /[*?\[]/.test(raw);
|
|
38
43
|
if (!isMagic) {
|
|
39
|
-
return assertPathSafe(raw, context, label);
|
|
44
|
+
return assertPathSafe(raw, context, label, baseCwd);
|
|
40
45
|
}
|
|
41
46
|
const denylist = context?.pathDenylist ?? [];
|
|
42
47
|
// A glob pathspec is matched by git, not by us, so we cannot prove it excludes
|
|
@@ -176,6 +181,65 @@ function toText(result, context, contentKind) {
|
|
|
176
181
|
isolation: result.isolation,
|
|
177
182
|
};
|
|
178
183
|
}
|
|
184
|
+
/**
|
|
185
|
+
* git 输出结果的老化策略(`git_status` / `git_diff` 共用骨架)
|
|
186
|
+
*
|
|
187
|
+
* 判据是「这个结果描述的世界还会不会变」,不是结果大小:
|
|
188
|
+
* - `git_status`:工作树状态**按设计就会变** → 全丢 + 一句提示
|
|
189
|
+
* - `git_diff` unstaged/staged:补丁正文会过时 → 只留 stat 规模,正文丢弃
|
|
190
|
+
* - `git_diff --commit <sha>` / `git_show <sha>`:不可变事实 → 保留(超长也不丢)
|
|
191
|
+
*
|
|
192
|
+
* `isolation` / `durationMs` / `terminated` 等执行元数据对已老化结果无意义,
|
|
193
|
+
* 且 `isolation` 实测在同一会话内**只有一种取值**(52 条完全相同)——纯噪音,一并略去。
|
|
194
|
+
*
|
|
195
|
+
* @param args - 原始调用参数(判定 revision 是否固定 sha)
|
|
196
|
+
* @param result - 原始工具结果(`{ stdout, stderr, ... }`)
|
|
197
|
+
* @returns 替换文本;undefined = 保留原文
|
|
198
|
+
*/
|
|
199
|
+
function ageGitResult(args, result, toolName) {
|
|
200
|
+
if (!result || typeof result !== 'object')
|
|
201
|
+
return undefined;
|
|
202
|
+
const r = result;
|
|
203
|
+
if (typeof r.stdout !== 'string')
|
|
204
|
+
return undefined;
|
|
205
|
+
const stdout = r.stdout;
|
|
206
|
+
if (stdout.trim() === '')
|
|
207
|
+
return `[aged ${toolName}] (no output)`;
|
|
208
|
+
// 固定 sha 的调用描述的是不可变事实:保留原文(超长也给头部 + 行数标记)
|
|
209
|
+
const rev = typeof args.revision === 'string' ? args.revision.trim() : '';
|
|
210
|
+
const fixedRev = /^[0-9a-f]{7,40}$/i.test(rev);
|
|
211
|
+
const mode = typeof args.mode === 'string' ? args.mode : '';
|
|
212
|
+
if (toolName === 'git_status') {
|
|
213
|
+
const lines = stdout.split('\n').filter((l) => l.trim() !== '');
|
|
214
|
+
const branch = lines.find((l) => l.startsWith('##')) ?? '';
|
|
215
|
+
const changed = lines.filter((l) => !l.startsWith('##')).length;
|
|
216
|
+
const head = branch.replace(/^##\s*/, '').slice(0, 80);
|
|
217
|
+
return `[stale git_status] ${changed} changed entries${head ? `, branch ${head}` : ''} — call git_status again for current state`;
|
|
218
|
+
}
|
|
219
|
+
if (toolName === 'git_diff' && mode === 'commit' && fixedRev) {
|
|
220
|
+
return undefined; // 某 commit 的 diff 永久有效 → 走默认规则
|
|
221
|
+
}
|
|
222
|
+
if (toolName === 'git_show' && fixedRev) {
|
|
223
|
+
return undefined;
|
|
224
|
+
}
|
|
225
|
+
// git_commit 的结果记录「某次提交确实发生」——sha 是不可变锚点,必须保留。
|
|
226
|
+
// stdout 首行形如 `[main 4c5eaf11] subject`,其后是文件统计与 create mode。
|
|
227
|
+
if (toolName === 'git_commit') {
|
|
228
|
+
const first = stdout.split('\n')[0]?.trim() ?? '';
|
|
229
|
+
const stats = stdout
|
|
230
|
+
.split('\n')
|
|
231
|
+
.filter((l) => /\d+ files? changed/.test(l) || l.startsWith(' create mode '))
|
|
232
|
+
.join(' ')
|
|
233
|
+
.trim();
|
|
234
|
+
return `[aged git_commit] ${first.slice(0, 160)}${stats ? ` — ${stats.slice(0, 120)}` : ''}`;
|
|
235
|
+
}
|
|
236
|
+
// 其余(unstaged/staged diff、HEAD 类浮动 revision):正文会过时,只留规模
|
|
237
|
+
const files = (stdout.match(/^diff --git /gm) ?? []).length;
|
|
238
|
+
// `+++ b/x` 是文件头,不是新增行:负向前瞻须吃掉两个 `+`
|
|
239
|
+
const added = (stdout.match(/^\+(?!\+\+)/gm) ?? []).length;
|
|
240
|
+
const removed = (stdout.match(/^-(?!--)/gm) ?? []).length;
|
|
241
|
+
return `[stale ${toolName}] patch dropped: ${files} file(s), +${added} −${removed} lines${fixedRev ? ` @ ${rev.slice(0, 12)}` : ''} — call again for current patch`;
|
|
242
|
+
}
|
|
179
243
|
/** git_status — porcelain working tree status */
|
|
180
244
|
export function createGitStatusTool() {
|
|
181
245
|
return {
|
|
@@ -192,10 +256,11 @@ export function createGitStatusTool() {
|
|
|
192
256
|
},
|
|
193
257
|
},
|
|
194
258
|
},
|
|
259
|
+
ageResult: ({ args, result }) => ageGitResult(args, result, 'git_status'),
|
|
195
260
|
handler: async (args, context) => {
|
|
196
261
|
const cwd = resolveCwd(context, args.cwd);
|
|
197
262
|
const paths = Array.isArray(args.paths) ? args.paths : [];
|
|
198
|
-
const pathArgs = paths.length > 0 ? ['--', ...paths.map((p) => toGitPathspec(p, context, 'status'))] : [];
|
|
263
|
+
const pathArgs = paths.length > 0 ? ['--', ...paths.map((p) => toGitPathspec(p, context, 'status', cwd))] : [];
|
|
199
264
|
const result = await runGit(context, cwd, [
|
|
200
265
|
'status',
|
|
201
266
|
'--porcelain=v1',
|
|
@@ -234,6 +299,7 @@ export function createGitDiffTool() {
|
|
|
234
299
|
},
|
|
235
300
|
},
|
|
236
301
|
},
|
|
302
|
+
ageResult: ({ args, result }) => ageGitResult(args, result, 'git_diff'),
|
|
237
303
|
handler: async (args, context) => {
|
|
238
304
|
const cwd = resolveCwd(context, args.cwd);
|
|
239
305
|
const modeRaw = args.mode ?? 'unstaged';
|
|
@@ -252,7 +318,7 @@ export function createGitDiffTool() {
|
|
|
252
318
|
gitArgs.push('--stat');
|
|
253
319
|
const paths = Array.isArray(args.paths) ? args.paths : [];
|
|
254
320
|
if (paths.length > 0) {
|
|
255
|
-
gitArgs.push('--', ...paths.map((p) => toGitPathspec(p, context, 'diff')));
|
|
321
|
+
gitArgs.push('--', ...paths.map((p) => toGitPathspec(p, context, 'diff', cwd)));
|
|
256
322
|
}
|
|
257
323
|
const result = await runGit(context, cwd, gitArgs, { timeoutMs: 120_000 });
|
|
258
324
|
return { ...toText(result, context, 'diff'), cwd, mode };
|
|
@@ -295,7 +361,7 @@ export function createGitLogTool() {
|
|
|
295
361
|
gitArgs.push(rev);
|
|
296
362
|
const paths = Array.isArray(args.paths) ? args.paths : [];
|
|
297
363
|
if (paths.length > 0) {
|
|
298
|
-
gitArgs.push('--', ...paths.map((p) => toGitPathspec(p, context, 'log')));
|
|
364
|
+
gitArgs.push('--', ...paths.map((p) => toGitPathspec(p, context, 'log', cwd)));
|
|
299
365
|
}
|
|
300
366
|
const result = await runGit(context, cwd, gitArgs);
|
|
301
367
|
return { ...toText(result), cwd, limit, revision: rev };
|
|
@@ -354,6 +420,8 @@ export function createGitCommitTool() {
|
|
|
354
420
|
},
|
|
355
421
|
},
|
|
356
422
|
},
|
|
423
|
+
// 历史视图保留「sha + subject + 统计」:message 与入参逐字相同(25/26 实测),可整体丢弃
|
|
424
|
+
ageResult: ({ args, result }) => ageGitResult(args, result, 'git_commit'),
|
|
357
425
|
handler: async (args, context) => {
|
|
358
426
|
const cwd = resolveCwd(context, args.cwd);
|
|
359
427
|
const message = String(args.message ?? '').trim();
|
|
@@ -371,7 +439,7 @@ export function createGitCommitTool() {
|
|
|
371
439
|
agentId: context?.agentId,
|
|
372
440
|
});
|
|
373
441
|
const paths = Array.isArray(args.paths) ? args.paths : [];
|
|
374
|
-
const resolvedPaths = paths.map((p) => toGitPathspec(p, context, 'commit'));
|
|
442
|
+
const resolvedPaths = paths.map((p) => toGitPathspec(p, context, 'commit', cwd));
|
|
375
443
|
const useAll = args.all === true;
|
|
376
444
|
if (resolvedPaths.length > 0 || useAll) {
|
|
377
445
|
const addArgs = ['add'];
|
|
@@ -529,7 +597,7 @@ export function createGitRestoreTool() {
|
|
|
529
597
|
const paths = Array.isArray(args.paths) ? args.paths : [];
|
|
530
598
|
if (paths.length === 0)
|
|
531
599
|
throw new Error('git_restore: paths is required');
|
|
532
|
-
const resolvedPaths = paths.map((p) => toGitPathspec(p, context, 'restore'));
|
|
600
|
+
const resolvedPaths = paths.map((p) => toGitPathspec(p, context, 'restore', cwd));
|
|
533
601
|
await gateEffect({
|
|
534
602
|
kind: 'vcs',
|
|
535
603
|
operation: 'restore',
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
* 超长响应:经 capabilities SummaryPort 做 L2 软净化 + L1 硬顶(见 arch/summary-compact.md §3.6)。
|
|
11
11
|
*/
|
|
12
12
|
import { applyToolOutputGate, resolveSupportBinding, } from '../../../context/capabilities/summary/index.js';
|
|
13
|
+
import { getRunScope } from '../../../run/run-scope.js';
|
|
13
14
|
import { guardedRequest, } from '../../../knowledge/network-guard.js';
|
|
14
15
|
const HTTP_CONSUMER = { kind: 'tool', id: 'http_request' };
|
|
15
16
|
/**
|
|
@@ -93,8 +94,12 @@ export function createHttpRequestTool(options) {
|
|
|
93
94
|
// 只紧不松:config/tool/context/untrusted 任一为 true 即强制
|
|
94
95
|
const requireBindings = context?.requireCredentialBindings === true ||
|
|
95
96
|
options?.requireBindings === true;
|
|
97
|
+
// 凭证域归属(arch/multi-tenancy.md §4):run 归属租户锚定解析域(平台 ∪ 本域);
|
|
98
|
+
// 无 run 归属 = 宿主面(信任边界)——租户 run 由 Runner principal.tenantId 兜底锚定
|
|
99
|
+
const runTenantId = getRunScope()?.principal?.tenantId;
|
|
96
100
|
const resolved = await store.resolve(credentialName, HTTP_CONSUMER, {
|
|
97
101
|
requireBindings: requireBindings ? true : undefined,
|
|
102
|
+
...(runTenantId ? { tenantId: runTenantId } : {}),
|
|
98
103
|
});
|
|
99
104
|
if (!resolved) {
|
|
100
105
|
throw new Error(`credential not found or secret unavailable: ${credentialName}`);
|