@octopi-agent/engine 0.102.10 → 0.121.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/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/console-access-key.d.ts +46 -0
- package/dist/config-admin/console-access-key.js +47 -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 +8 -2
- package/dist/config-admin/index.js +4 -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 +83 -0
- package/dist/config-admin/onboarding-apply.js +259 -0
- package/dist/config-admin/onboarding.d.ts +160 -0
- package/dist/config-admin/onboarding.js +298 -0
- package/dist/config-admin/password-policy.d.ts +24 -0
- package/dist/config-admin/password-policy.js +31 -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
|
@@ -5,13 +5,18 @@
|
|
|
5
5
|
* 语料命中为不可信资料,不得当指令执行。
|
|
6
6
|
* 可见性与 session 必须来自 Run context,禁止参数伪造。
|
|
7
7
|
*/
|
|
8
|
+
import { DEFAULT_TENANT_ID } from '@octopi-agent/core/types.js';
|
|
8
9
|
import { asSourceId } from '../../../knowledge/types.js';
|
|
9
10
|
import { wrapUntrustedKnowledgeBlock } from '../../../knowledge/grounding.js';
|
|
11
|
+
import { getRunScope } from '../../../run/run-scope.js';
|
|
10
12
|
function resolveIds(context) {
|
|
11
13
|
const ctx = (context ?? {});
|
|
12
14
|
return {
|
|
13
15
|
agentId: ctx.agentId?.trim() || 'default',
|
|
14
16
|
sessionId: ctx.sessionId?.trim() || undefined,
|
|
17
|
+
// 归属锚(arch/multi-tenancy.md §4/§6):run 归属租户(禁止参数伪造);
|
|
18
|
+
// 未接身份层 = DEFAULT 域(存量语义)
|
|
19
|
+
tenantId: getRunScope()?.principal?.tenantId ?? DEFAULT_TENANT_ID,
|
|
15
20
|
};
|
|
16
21
|
}
|
|
17
22
|
export function createKnowledgeTools(options) {
|
|
@@ -54,12 +59,13 @@ export function createKnowledgeSearchTool(options) {
|
|
|
54
59
|
if (!query)
|
|
55
60
|
return { hits: [], error: 'query is required' };
|
|
56
61
|
const limit = Math.min(Number(args.limit) || maxResults, 20);
|
|
57
|
-
const { agentId, sessionId } = resolveIds(context);
|
|
62
|
+
const { agentId, sessionId, tenantId } = resolveIds(context);
|
|
58
63
|
const sourceId = args.source_id ? String(args.source_id).trim() : '';
|
|
59
64
|
const sourceName = args.source ? String(args.source).trim() : '';
|
|
60
65
|
const result = await options.retriever.search(query, {
|
|
61
66
|
agentId,
|
|
62
67
|
sessionId,
|
|
68
|
+
tenantId,
|
|
63
69
|
limit,
|
|
64
70
|
sourceIds: sourceId ? [sourceId] : undefined,
|
|
65
71
|
source: sourceName || undefined,
|
|
@@ -110,11 +116,11 @@ export function createKnowledgeReadTool(options) {
|
|
|
110
116
|
},
|
|
111
117
|
handler: async (args, context) => {
|
|
112
118
|
const maxChars = Math.min(Number(args.max_chars) || maxReadChars, 32_000);
|
|
113
|
-
const { agentId, sessionId } = resolveIds(context);
|
|
119
|
+
const { agentId, sessionId, tenantId } = resolveIds(context);
|
|
114
120
|
const chunkId = args.chunk_id ? String(args.chunk_id) : '';
|
|
115
121
|
const canSee = (sourceId) => {
|
|
116
122
|
const src = options.sourceStore.get(sourceId);
|
|
117
|
-
return src ? options.sourceStore.isVisible(src, agentId, sessionId) : false;
|
|
123
|
+
return src ? options.sourceStore.isVisible(src, agentId, sessionId, { tenantId }) : false;
|
|
118
124
|
};
|
|
119
125
|
if (chunkId) {
|
|
120
126
|
const row = options.indexStore.getChunk(chunkId);
|
|
@@ -200,11 +206,11 @@ export function createKnowledgeClientTools(options) {
|
|
|
200
206
|
const query = String(args.query ?? '').trim();
|
|
201
207
|
if (!query)
|
|
202
208
|
return { hits: [], error: 'query is required' };
|
|
203
|
-
const { agentId, sessionId } = resolveIds(context);
|
|
209
|
+
const { agentId, sessionId, tenantId } = resolveIds(context);
|
|
204
210
|
const limit = Math.min(Number(args.limit) || maxResults, 20);
|
|
205
211
|
try {
|
|
206
212
|
await client.ensurePrincipal(agentId).catch(() => undefined);
|
|
207
|
-
const result = await client.search(agentId, query, { sessionId, limit });
|
|
213
|
+
const result = await client.search(agentId, query, { sessionId, limit, tenantId });
|
|
208
214
|
const hits = (result.hits ?? []);
|
|
209
215
|
return {
|
|
210
216
|
usedVector: result.usedVector,
|
|
@@ -243,7 +249,7 @@ export function createKnowledgeClientTools(options) {
|
|
|
243
249
|
},
|
|
244
250
|
handler: async (args, context) => {
|
|
245
251
|
const maxChars = Math.min(Number(args.max_chars) || maxReadChars, 32_000);
|
|
246
|
-
const { agentId } = resolveIds(context);
|
|
252
|
+
const { agentId, tenantId } = resolveIds(context);
|
|
247
253
|
try {
|
|
248
254
|
await client.ensurePrincipal(agentId).catch(() => undefined);
|
|
249
255
|
const chunkId = args.chunk_id ? String(args.chunk_id) : '';
|
|
@@ -251,7 +257,7 @@ export function createKnowledgeClientTools(options) {
|
|
|
251
257
|
const sourceId = args.source_id ? String(args.source_id) : '';
|
|
252
258
|
const data = await client.read(agentId, chunkId
|
|
253
259
|
? { chunkId }
|
|
254
|
-
: { sourceId, path });
|
|
260
|
+
: { sourceId, path }, { tenantId });
|
|
255
261
|
if (!data?.found) {
|
|
256
262
|
return { found: false, error: 'chunk not found' };
|
|
257
263
|
}
|
|
@@ -9,14 +9,23 @@
|
|
|
9
9
|
* when networkPolicy is not open (prompt the user to install manually).
|
|
10
10
|
*/
|
|
11
11
|
import { tmpdir } from 'node:os';
|
|
12
|
-
import { join } from 'node:path';
|
|
12
|
+
import { dirname, join } from 'node:path';
|
|
13
13
|
import { gateEffect } from '../../execution-environment/effect-policy.js';
|
|
14
14
|
import { containmentOptions, findExecutable, isUnderAttachmentRoot, isUnderSessionUndoRoot, resolveToolPath, } from './platform.js';
|
|
15
15
|
import { runAllowlistedArgv } from './allowlisted-run.js';
|
|
16
16
|
import { resolveNodeToolCommand } from './platform.js';
|
|
17
|
+
/**
|
|
18
|
+
* 解析并校验项目目录(containment / attachment / undo 保护)。
|
|
19
|
+
*
|
|
20
|
+
* `raw` 必传、无缺省:三个 package 工具的 cwd 都是必填入参,这里不再提供
|
|
21
|
+
* 「回落到会话 workspace」的路径——否则静默错靶会从这里重新长出来。
|
|
22
|
+
*
|
|
23
|
+
* @param context - 工具执行上下文(提供 containment 根)
|
|
24
|
+
* @param raw - 已由 `requireCwd` 校验非空的项目目录
|
|
25
|
+
* @returns 已解析并做过 containment 校验的项目目录
|
|
26
|
+
*/
|
|
17
27
|
function resolveCwd(context, raw) {
|
|
18
|
-
const
|
|
19
|
-
const abs = resolveToolPath(cwd, context?.cwd, containmentOptions(context));
|
|
28
|
+
const abs = resolveToolPath(raw, context?.cwd, containmentOptions(context));
|
|
20
29
|
if (isUnderAttachmentRoot(abs, context?.attachmentRoots)) {
|
|
21
30
|
throw new Error('session attachments are read-only; cannot run package tools under attachments root');
|
|
22
31
|
}
|
|
@@ -25,8 +34,36 @@ function resolveCwd(context, raw) {
|
|
|
25
34
|
}
|
|
26
35
|
return abs;
|
|
27
36
|
}
|
|
28
|
-
|
|
29
|
-
|
|
37
|
+
/**
|
|
38
|
+
* 三个 package 工具共用的 cwd 契约:必填,缺省绝不回落到会话 workspace。
|
|
39
|
+
*
|
|
40
|
+
* 依据:workspace 通常不是目标项目——`project_run` 会对着另一个仓库的同名脚本执行,
|
|
41
|
+
* `package_edit` 会改 workspace 自己的 package.json,`package_install` 会往错误目录装依赖。
|
|
42
|
+
* 静默错靶(改错文件/装错仓库)比显式报错代价高得多,所以这里 fail loud。
|
|
43
|
+
*
|
|
44
|
+
* @param context - 工具执行上下文(提供 containment 根)
|
|
45
|
+
* @param raw - 工具入参 cwd
|
|
46
|
+
* @param tool - 工具名,用于错误前缀(`<tool>_cwd_required`)
|
|
47
|
+
* @returns 已解析并做过 containment 校验的项目目录
|
|
48
|
+
*/
|
|
49
|
+
function requireCwd(context, raw, tool) {
|
|
50
|
+
const value = typeof raw === 'string' ? raw.trim() : '';
|
|
51
|
+
if (!value) {
|
|
52
|
+
throw new Error(`${tool}_cwd_required: pass the project directory containing package.json; it is never inferred from the workspace cwd`);
|
|
53
|
+
}
|
|
54
|
+
return resolveCwd(context, value);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* 把工具入参路径解析到**本次操作的项目目录**,而不是会话 workspace。
|
|
58
|
+
*
|
|
59
|
+
* @param raw - 工具入参中的相对/绝对路径
|
|
60
|
+
* @param context - 工具执行上下文
|
|
61
|
+
* @param label - 动作标签,用于错误信息
|
|
62
|
+
* @param baseCwd - 相对路径的基准目录(项目目录)
|
|
63
|
+
* @returns 已解析并做过 containment / denylist 校验的绝对路径
|
|
64
|
+
*/
|
|
65
|
+
function assertPathSafe(raw, context, label, baseCwd) {
|
|
66
|
+
const abs = resolveToolPath(raw, baseCwd, containmentOptions(context));
|
|
30
67
|
if (isUnderAttachmentRoot(abs, context?.attachmentRoots)) {
|
|
31
68
|
throw new Error(`session attachments are read-only; cannot ${label} under attachments root`);
|
|
32
69
|
}
|
|
@@ -139,9 +176,14 @@ export function createPackageEditTool() {
|
|
|
139
176
|
capabilities: ['fs-write', 'fs-read'],
|
|
140
177
|
description: 'Structurally edit package.json (scripts, dependencies, metadata) via dotted paths. Undoable. Prefer this over rewriting the whole file.',
|
|
141
178
|
parameters: {
|
|
179
|
+
cwd: {
|
|
180
|
+
type: 'string',
|
|
181
|
+
description: 'Project directory containing the package.json to edit (required; relative paths resolve against it, never against the workspace cwd)',
|
|
182
|
+
required: true,
|
|
183
|
+
},
|
|
142
184
|
path: {
|
|
143
185
|
type: 'string',
|
|
144
|
-
description: 'Path to package.json (default:
|
|
186
|
+
description: 'Path to package.json, relative to `cwd` (default: package.json in `cwd`)',
|
|
145
187
|
},
|
|
146
188
|
set: {
|
|
147
189
|
type: 'object',
|
|
@@ -157,9 +199,9 @@ export function createPackageEditTool() {
|
|
|
157
199
|
// 整文件读改写无合并语义:所在 tool_call 批次整体串行,防同路径并发读改写互相覆盖
|
|
158
200
|
executionMode: 'sequential',
|
|
159
201
|
handler: async (args, context) => {
|
|
160
|
-
const cwd =
|
|
202
|
+
const cwd = requireCwd(context, args.cwd, 'package_edit');
|
|
161
203
|
const rawPath = args.path ?? 'package.json';
|
|
162
|
-
const pkgPath = assertPathSafe(rawPath, context, 'edit');
|
|
204
|
+
const pkgPath = assertPathSafe(rawPath, context, 'edit', cwd);
|
|
163
205
|
const { pkg, raw: originalText } = await readPackageJson(pkgPath);
|
|
164
206
|
const set = args.set ?? {};
|
|
165
207
|
const remove = Array.isArray(args.remove) ? args.remove : [];
|
|
@@ -187,24 +229,88 @@ export function createPackageEditTool() {
|
|
|
187
229
|
}
|
|
188
230
|
const after = stringifyPreservingEol(pkg, originalText);
|
|
189
231
|
await effects.writeFile(pkgPath, after);
|
|
190
|
-
|
|
232
|
+
// 包管理器由**被编辑文件所在目录**判定(cwd 只是相对 path 的基准);
|
|
233
|
+
// 否则 path 指向别处时会报错仓库的 lockfile。
|
|
234
|
+
return { path: pkgPath, changed, packageManager: await detectPm(dirname(pkgPath)) };
|
|
191
235
|
},
|
|
192
236
|
};
|
|
193
237
|
}
|
|
238
|
+
/**
|
|
239
|
+
* 结果老化:回到「这次脚本跑成没跑成、结论是什么」
|
|
240
|
+
*
|
|
241
|
+
* 依据(default-web-1794346953041 实测,43 次 278,106 字符):
|
|
242
|
+
* - `stdout` 64%:ANSI 转义码 13,980 字符是纯噪声;结论(测试汇总/构建结果)在**末尾**;
|
|
243
|
+
* - `stderr` 29%:34 条 exit=0 的 stderr 共 37,002 字符,内容全是 `[AgentBuilder]`、
|
|
244
|
+
* `[overflow]`、`[Knowledge]` 这类**用例自身日志**,92% 不是错误行 → 成功时无诊断价值;
|
|
245
|
+
* - `isolation` 5%:43/43 完全相同(与 shell ager 已删的同一字段);
|
|
246
|
+
* - `scriptBody`/`cwd` 是入参或 package.json 可重读。
|
|
247
|
+
*
|
|
248
|
+
* 保留:退出码、脚本名、是否截断/终止、(失败时的)stderr 尾部、(成功与失败都保留的)
|
|
249
|
+
* stdout 尾部——尾部才是结论所在。
|
|
250
|
+
*
|
|
251
|
+
* @param result - project_run 的原始结果
|
|
252
|
+
* @returns 老化指针;结构不符时返回 undefined
|
|
253
|
+
*/
|
|
254
|
+
function ageProjectRunResult(result) {
|
|
255
|
+
if (!result || typeof result !== 'object')
|
|
256
|
+
return undefined;
|
|
257
|
+
const r = result;
|
|
258
|
+
const exitCode = typeof r.exitCode === 'number' ? r.exitCode : undefined;
|
|
259
|
+
if (exitCode === undefined)
|
|
260
|
+
return undefined;
|
|
261
|
+
// 剥 ANSI(0x1b[...m),它是纯渲染控制码,历史回看无意义
|
|
262
|
+
const stripAnsi = (s) => s.replace(/\u001b\[[0-9;]*m/g, '');
|
|
263
|
+
const stdout = stripAnsi(typeof r.stdout === 'string' ? r.stdout : '');
|
|
264
|
+
const stderr = stripAnsi(typeof r.stderr === 'string' ? r.stderr : '');
|
|
265
|
+
const outLen = typeof r.rawStdoutLength === 'number' ? r.rawStdoutLength : stdout.length;
|
|
266
|
+
const flags = [`exit ${exitCode}`];
|
|
267
|
+
if (r.truncated === true)
|
|
268
|
+
flags.push(`stdout capped, ${outLen} chars total`);
|
|
269
|
+
if (r.terminated === true) {
|
|
270
|
+
const why = typeof r.terminateReason === 'string' ? r.terminateReason : 'unknown';
|
|
271
|
+
flags.push(`terminated (${why})`);
|
|
272
|
+
}
|
|
273
|
+
const head = `[aged] project_run ${flags.join(', ')}`;
|
|
274
|
+
const TAIL = 900;
|
|
275
|
+
const tailLines = (s) => {
|
|
276
|
+
const trimmed = s.replace(/^\n+|\n+$/g, '');
|
|
277
|
+
if (!trimmed)
|
|
278
|
+
return '';
|
|
279
|
+
const lines = trimmed.split('\n');
|
|
280
|
+
if (trimmed.length <= TAIL)
|
|
281
|
+
return trimmed;
|
|
282
|
+
return lines.slice(-12).join('\n').slice(-TAIL);
|
|
283
|
+
};
|
|
284
|
+
const parts = [head];
|
|
285
|
+
// 失败时 stderr 是诊断主体;成功时(日志噪音)不保留
|
|
286
|
+
if (exitCode !== 0) {
|
|
287
|
+
const se = tailLines(stderr);
|
|
288
|
+
if (se)
|
|
289
|
+
parts.push(`stderr tail: ${se}`);
|
|
290
|
+
}
|
|
291
|
+
const out = tailLines(stdout);
|
|
292
|
+
if (out)
|
|
293
|
+
parts.push(`stdout tail: ${out}`);
|
|
294
|
+
return parts.join('\n');
|
|
295
|
+
}
|
|
194
296
|
/** project_run — run a named package.json script (runner; stripped on reduced) */
|
|
195
297
|
export function createProjectRunTool() {
|
|
196
298
|
return {
|
|
197
299
|
definition: {
|
|
198
300
|
name: 'project_run',
|
|
199
301
|
capabilities: ['runner'],
|
|
200
|
-
description: 'Run a named script from package.json#scripts (e.g. test, lint, build). Pass the script name only — never an arbitrary command string. Executes workspace code; blocked when the tool surface is reduced.',
|
|
302
|
+
description: 'Run a named script from package.json#scripts (e.g. test, lint, build). Pass the script name only — never an arbitrary command string. `cwd` is required: it is the project directory holding package.json and is never inferred from the session workspace. Executes workspace code; blocked when the tool surface is reduced.',
|
|
201
303
|
parameters: {
|
|
202
304
|
script: {
|
|
203
305
|
type: 'string',
|
|
204
306
|
description: 'Script name defined in package.json#scripts',
|
|
205
307
|
required: true,
|
|
206
308
|
},
|
|
207
|
-
cwd: {
|
|
309
|
+
cwd: {
|
|
310
|
+
type: 'string',
|
|
311
|
+
description: 'Project directory containing package.json (required; relative paths resolve against it, never against the workspace cwd)',
|
|
312
|
+
required: true,
|
|
313
|
+
},
|
|
208
314
|
args: {
|
|
209
315
|
type: 'array',
|
|
210
316
|
description: 'Extra args passed after the script (npm run <script> -- <args>)',
|
|
@@ -223,8 +329,10 @@ export function createProjectRunTool() {
|
|
|
223
329
|
},
|
|
224
330
|
},
|
|
225
331
|
},
|
|
332
|
+
// 历史视图收敛为「成败 + 尾部结论」(stdout 结论在末尾;成功时 stderr 是日志噪音)
|
|
333
|
+
ageResult: ({ result }) => ageProjectRunResult(result),
|
|
226
334
|
handler: async (args, context) => {
|
|
227
|
-
const cwd =
|
|
335
|
+
const cwd = requireCwd(context, args.cwd, 'project_run');
|
|
228
336
|
const script = String(args.script ?? '').trim();
|
|
229
337
|
if (!script || !/^[A-Za-z0-9][A-Za-z0-9:._-]*$/.test(script)) {
|
|
230
338
|
throw new Error(`project_run: invalid script name "${script}"`);
|
|
@@ -287,7 +395,11 @@ export function createPackageInstallTool() {
|
|
|
287
395
|
items: { type: 'string', description: 'Package spec' },
|
|
288
396
|
},
|
|
289
397
|
dev: { type: 'boolean', description: 'add as devDependency' },
|
|
290
|
-
cwd: {
|
|
398
|
+
cwd: {
|
|
399
|
+
type: 'string',
|
|
400
|
+
description: 'Project directory to install into (required; its lockfile selects the package manager, never inferred from the workspace cwd)',
|
|
401
|
+
required: true,
|
|
402
|
+
},
|
|
291
403
|
packageManager: {
|
|
292
404
|
type: 'string',
|
|
293
405
|
description: 'Force package manager (default: detect from lockfile)',
|
|
@@ -306,7 +418,7 @@ export function createPackageInstallTool() {
|
|
|
306
418
|
if (!['install', 'add', 'remove', 'ci'].includes(action)) {
|
|
307
419
|
throw new Error(`package_install: unsupported action "${action}"`);
|
|
308
420
|
}
|
|
309
|
-
const cwd =
|
|
421
|
+
const cwd = requireCwd(context, args.cwd, 'package_install');
|
|
310
422
|
const packages = Array.isArray(args.packages) ? args.packages.map(String) : [];
|
|
311
423
|
if ((action === 'add' || action === 'remove') && packages.length === 0) {
|
|
312
424
|
throw new Error(`package_install: action=${action} requires packages`);
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
import { accessSync, constants, existsSync, statSync } from 'node:fs';
|
|
8
8
|
import { delimiter, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
9
9
|
import { isPathUnderRoots, lexicalUnderRoots, realpathAllowMissing, } from '../../../shared/paths/index.js';
|
|
10
|
+
import { expandHomePath } from '../../../../paths.js';
|
|
10
11
|
import { matchesDenyPattern } from '../../../shared/paths/glob.js';
|
|
11
12
|
export { isPathUnderRoots };
|
|
12
13
|
/**
|
|
@@ -133,7 +134,42 @@ function denyPath(absPath, rawPath, options, denyPatterns) {
|
|
|
133
134
|
}
|
|
134
135
|
}
|
|
135
136
|
/**
|
|
136
|
-
*
|
|
137
|
+
* Expand a tool-input `~` prefix to the user home directory.
|
|
138
|
+
*
|
|
139
|
+
* `~`, `~/rest`, `~\rest` expand via the shared {@link expandHomePath}. The
|
|
140
|
+
* `~user/rest` form has no portable expansion; leaving it unexpanded would
|
|
141
|
+
* silently resolve it against the tool cwd — the exact mis-target this surface
|
|
142
|
+
* forbids — so it fails loud instead (use an absolute path, or `./~user/…` for
|
|
143
|
+
* a literal name).
|
|
144
|
+
*
|
|
145
|
+
* @param rawPath - caller-supplied path
|
|
146
|
+
* @returns expanded path (unchanged when there is no `~` prefix)
|
|
147
|
+
*/
|
|
148
|
+
function expandToolTilde(rawPath) {
|
|
149
|
+
// Surrounding whitespace around a `~` spelling is an ambiguity, not a name:
|
|
150
|
+
// `" ~/x"` would silently resolve against the cwd — the exact mis-target this
|
|
151
|
+
// surface forbids. Fail loud instead of picking a side (tool input is not a
|
|
152
|
+
// shell line; strip the whitespace yourself or use "./…" for a literal name).
|
|
153
|
+
const trimmed = rawPath.trim();
|
|
154
|
+
if (trimmed !== rawPath && trimmed.startsWith('~')) {
|
|
155
|
+
throw new Error(`path_invalid: "${rawPath}" has surrounding whitespace and would not expand to the user home; strip the whitespace, or pass "./${trimmed}" for a literal name`);
|
|
156
|
+
}
|
|
157
|
+
let expanded;
|
|
158
|
+
try {
|
|
159
|
+
expanded = expandHomePath(rawPath);
|
|
160
|
+
}
|
|
161
|
+
catch (error) {
|
|
162
|
+
// homedir() fails when HOME/USERPROFILE are unset and the passwd lookup
|
|
163
|
+
// fails; surface it as an actionable path_invalid, not a raw os error.
|
|
164
|
+
throw new Error(`path_invalid: cannot expand "${rawPath}": user home directory unavailable (${error instanceof Error ? error.message : String(error)})`);
|
|
165
|
+
}
|
|
166
|
+
if (expanded === rawPath && rawPath.startsWith('~')) {
|
|
167
|
+
throw new Error(`path_invalid: cannot expand "${rawPath}": ~user home lookup has no portable meaning; pass an absolute path, or "./${rawPath}" for a literal name`);
|
|
168
|
+
}
|
|
169
|
+
return expanded;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* 解析工具入参路径:`~` 展开到用户目录,绝对路径原样返回,相对路径相对 cwd
|
|
137
173
|
*
|
|
138
174
|
* 使用 path.isAbsolute,同时覆盖 POSIX /foo、Windows 盘符与 UNC。
|
|
139
175
|
*
|
|
@@ -143,7 +179,8 @@ function denyPath(absPath, rawPath, options, denyPatterns) {
|
|
|
143
179
|
* @returns 规范化后的绝对路径;containment 生效时为符号链接解析后的真实路径
|
|
144
180
|
*/
|
|
145
181
|
export function resolveToolPath(rawPath, cwd, options) {
|
|
146
|
-
const
|
|
182
|
+
const expanded = expandToolTilde(rawPath);
|
|
183
|
+
const abs = isAbsolute(expanded) ? resolve(expanded) : resolve(cwd ?? process.cwd(), expanded);
|
|
147
184
|
return containPath(abs, rawPath, options);
|
|
148
185
|
}
|
|
149
186
|
/**
|
|
@@ -156,9 +193,11 @@ export function resolveToolPath(rawPath, cwd, options) {
|
|
|
156
193
|
*/
|
|
157
194
|
export function resolveReadableToolPath(rawPath, cwd, attachmentRoots, options) {
|
|
158
195
|
const roots = attachmentRoots ?? [];
|
|
159
|
-
//
|
|
160
|
-
|
|
161
|
-
|
|
196
|
+
// `~` 先展开到用户目录(home 形态不是附件文件名);绝对路径原样,
|
|
197
|
+
// 相对路径先试 attachments 根(文件名直呼)
|
|
198
|
+
const expanded = expandToolTilde(rawPath);
|
|
199
|
+
if (!isAbsolute(expanded) && roots.length > 0) {
|
|
200
|
+
const cleaned = expanded.replace(/^[/\\]+/, '');
|
|
162
201
|
for (const root of roots) {
|
|
163
202
|
const rootResolved = resolve(root);
|
|
164
203
|
const candidate = resolve(rootResolved, cleaned);
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
*
|
|
17
17
|
* @module harness/extension/plugin-ecosystem/tools/tool-bus
|
|
18
18
|
*/
|
|
19
|
-
import { registerToolCapabilities } from '../../execution-environment/tool-capabilities.js';
|
|
19
|
+
import { registerToolCapabilities, resolveToolCapabilities, } from '../../execution-environment/tool-capabilities.js';
|
|
20
|
+
import { isToolPermitted } from '../../../governance/session-acl/tool-rights.js';
|
|
20
21
|
import { buildToolLlmParameters } from '../../../agent/tool-purpose.js';
|
|
21
22
|
import { isPluginToolPermitted } from './plugin-tool.js';
|
|
22
23
|
/**
|
|
@@ -94,28 +95,10 @@ export class DefaultToolBus {
|
|
|
94
95
|
}
|
|
95
96
|
// ── 解析 ──
|
|
96
97
|
resolve(agentId, policy) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
// "*" 表示放行全部(配置常见写法),不得只匹配字面量 "*"
|
|
102
|
-
const allowAll = allowSet.has('*');
|
|
103
|
-
if (!allowAll) {
|
|
104
|
-
tools = tools.filter(t => allowSet.has(t.definition.name));
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
if (policy.deny && policy.deny.length > 0) {
|
|
108
|
-
const denySet = new Set(policy.deny);
|
|
109
|
-
// deny '*' = deny every tool (mirror allow '*')
|
|
110
|
-
if (denySet.has('*')) {
|
|
111
|
-
tools = [];
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
tools = tools.filter(t => !denySet.has(t.definition.name));
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
return tools;
|
|
98
|
+
// 双闸:isPluginToolPermitted 保留源别默认(agent 级插件工具无策略=不暴露,全局内置默认暴露);
|
|
99
|
+
// isToolPermitted 补能力漏斗(denyCapabilities + 未知标签 fail-closed,与 runner 列表闸同语义)
|
|
100
|
+
return this.listForAgent(agentId).filter((tool) => isPluginToolPermitted(tool, policy) &&
|
|
101
|
+
isToolPermitted(tool.definition.name, resolveToolCapabilities(tool.definition.name), [policy]));
|
|
119
102
|
}
|
|
120
103
|
toLLMDefinitions(agentId, policy) {
|
|
121
104
|
return this.resolve(agentId, policy).map(definition => ({
|
|
@@ -165,7 +148,10 @@ export class DefaultToolBus {
|
|
|
165
148
|
}
|
|
166
149
|
const { getRunScope } = await import('../../../run/run-scope.js');
|
|
167
150
|
const effectivePolicy = getRunScope()?.toolRuntime?.agentToolPolicy ?? policy;
|
|
168
|
-
if (!isPluginToolPermitted(tool, effectivePolicy)
|
|
151
|
+
if (!isPluginToolPermitted(tool, effectivePolicy) ||
|
|
152
|
+
!isToolPermitted(tool.definition.name, resolveToolCapabilities(tool.definition.name), [
|
|
153
|
+
effectivePolicy,
|
|
154
|
+
])) {
|
|
169
155
|
throw new Error(`Plugin tool "${name}" is not allowed for agent "${context.agentId}"`);
|
|
170
156
|
}
|
|
171
157
|
this.validateArgs(name, args, tool.definition);
|
|
@@ -4,6 +4,8 @@ import type { SessionTaskService } from '../../../session/tasks/service.js';
|
|
|
4
4
|
import type { SessionHistoryPort } from '../../../session/history/index.js';
|
|
5
5
|
import type { WebSearchProvider } from './web-search-types.js';
|
|
6
6
|
import type { AskUserCallback } from './ask-user.js';
|
|
7
|
+
import type { BrowserService } from './browser-types.js';
|
|
8
|
+
import type { BrowserToolOptions } from './browser.js';
|
|
7
9
|
export interface ToolSetConfig {
|
|
8
10
|
memoryStore?: MemoryStore;
|
|
9
11
|
/** memory 工具的 confidence/gates 覆盖(与 octopi.json memory 段对齐) */
|
|
@@ -21,6 +23,11 @@ export interface ToolSetConfig {
|
|
|
21
23
|
defaultLimit?: number;
|
|
22
24
|
timeoutMs?: number;
|
|
23
25
|
};
|
|
26
|
+
/** 浏览器会话服务;未提供时不注册 browser_* */
|
|
27
|
+
browser?: {
|
|
28
|
+
service: BrowserService;
|
|
29
|
+
options?: BrowserToolOptions;
|
|
30
|
+
};
|
|
24
31
|
/** Summary 公用能力(http_request / file_read L1/L2) */
|
|
25
32
|
summary?: import('../../../context/capabilities/summary/index.js').ToolSummarySupport;
|
|
26
33
|
/** CredentialStore — http_request.credential(绑定强制见 store.resolve) */
|
|
@@ -3,6 +3,7 @@ import { createMemoryTools } from './memory.js';
|
|
|
3
3
|
import { createSessionTaskTools } from '../../../session/tasks/tools.js';
|
|
4
4
|
import { createAskUserTool } from './ask-user.js';
|
|
5
5
|
import { createWebSearchTool } from './web-search.js';
|
|
6
|
+
import { createBrowserTools } from './browser.js';
|
|
6
7
|
import { createSessionHistoryTools } from './session-history.js';
|
|
7
8
|
import { createDelegationTools } from './delegation.js';
|
|
8
9
|
export function createToolSet(config) {
|
|
@@ -26,6 +27,9 @@ export function createToolSet(config) {
|
|
|
26
27
|
}),
|
|
27
28
|
]
|
|
28
29
|
: []),
|
|
30
|
+
...(config?.browser
|
|
31
|
+
? createBrowserTools(config.browser.service, config.browser.options)
|
|
32
|
+
: []),
|
|
29
33
|
...(config?.sessionHistory
|
|
30
34
|
? createSessionHistoryTools({
|
|
31
35
|
history: config.sessionHistory,
|
|
@@ -8,6 +8,15 @@ export interface CredentialDatabaseOptions {
|
|
|
8
8
|
dbPath?: string;
|
|
9
9
|
wal?: boolean;
|
|
10
10
|
busyTimeoutMs?: number;
|
|
11
|
+
/**
|
|
12
|
+
* 把 `dbPath` 所在目录收紧到当前用户(POSIX 0700 / Windows ACL)。
|
|
13
|
+
*
|
|
14
|
+
* 默认 `false`:`dbPath` 是公开选项,调用方可能指向共享目录(`/var/lib/foo/app.db`),
|
|
15
|
+
* 不打招呼就 `chmod 700` 会把别人的服务状态一起锁掉。产品路径经
|
|
16
|
+
* {@link resolveCredentialPaths} 产出的专用目录,由 `CredentialStore.openDefault`
|
|
17
|
+
* 显式打开该开关;嵌入方指定自己的路径时自行负责目录权限。
|
|
18
|
+
*/
|
|
19
|
+
hardenDir?: boolean;
|
|
11
20
|
}
|
|
12
21
|
export interface CredentialPaths {
|
|
13
22
|
root: string;
|