@botbotgo/agent-harness 0.0.475 → 0.0.476
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/README.md +3 -1234
- package/README.zh.md +3 -1191
- package/dist/acp.js +1 -1
- package/dist/api.js +1 -404
- package/dist/benchmark/checkpoint-resume-cost-benchmark.js +1 -55
- package/dist/benchmark/deepagent-local-model-benchmark.js +2 -35
- package/dist/benchmark/upstream-runtime-ab-benchmark.js +1 -179
- package/dist/cli/chat-interactive.js +25 -244
- package/dist/cli/chat-rendering.js +6 -100
- package/dist/cli/chat-stream.js +23 -512
- package/dist/cli/chat-ui.js +21 -199
- package/dist/cli/chat-workspace.js +2 -210
- package/dist/cli/main.js +21 -428
- package/dist/cli/managed-service-commands.js +9 -63
- package/dist/cli/managed-service.js +2 -137
- package/dist/cli/options-init-chat.js +1 -108
- package/dist/cli/options-runtime.js +1 -158
- package/dist/cli/options-serve.js +1 -282
- package/dist/cli/options.js +2 -19
- package/dist/cli/process-guards.js +1 -139
- package/dist/cli/request-tree.js +7 -296
- package/dist/cli/runtime-commands.js +12 -258
- package/dist/cli/runtime-output.js +16 -155
- package/dist/cli/server-commands.js +16 -270
- package/dist/cli/workspace.js +1 -67
- package/dist/cli.js +1 -7
- package/dist/client/acp.js +1 -1
- package/dist/client/in-process.js +1 -67
- package/dist/client/index.js +1 -2
- package/dist/client/types.js +0 -1
- package/dist/client.js +1 -1
- package/dist/contracts/core.js +1 -1
- package/dist/contracts/runtime-evaluation.js +0 -1
- package/dist/contracts/runtime-memory.js +0 -1
- package/dist/contracts/runtime-observability.js +0 -1
- package/dist/contracts/runtime-requests.js +0 -1
- package/dist/contracts/runtime-scheduling.js +0 -1
- package/dist/contracts/runtime.js +1 -27
- package/dist/contracts/types.js +1 -3
- package/dist/contracts/workspace.js +0 -1
- package/dist/flow/build-flow-graph.js +1 -50
- package/dist/flow/export-mermaid.js +2 -464
- package/dist/flow/export-sequence-mermaid.js +2 -325
- package/dist/flow/flow-graph-normalization.js +1 -214
- package/dist/flow/flow-graph-runtime.js +1 -107
- package/dist/flow/flow-graph-upstream.js +1 -494
- package/dist/flow/index.js +1 -3
- package/dist/flow/types.js +0 -1
- package/dist/index.js +1 -5
- package/dist/init-project.js +1 -1
- package/dist/knowledge/config.js +1 -32
- package/dist/knowledge/contracts.js +0 -1
- package/dist/knowledge/index.js +1 -2
- package/dist/knowledge/module.js +12 -909
- package/dist/knowledge/procedural/config.js +1 -125
- package/dist/knowledge/procedural/index.js +1 -2
- package/dist/knowledge/procedural/manager.js +9 -345
- package/dist/mcp.js +1 -2
- package/dist/package-version.d.ts +1 -1
- package/dist/package-version.js +1 -2
- package/dist/persistence/file-store.js +3 -758
- package/dist/persistence/sqlite-request-context-store.js +5 -54
- package/dist/persistence/sqlite-request-queue-store.js +10 -108
- package/dist/persistence/sqlite-runtime.js +1 -86
- package/dist/persistence/sqlite-store.js +62 -810
- package/dist/persistence/types.js +0 -1
- package/dist/projections/presentation.js +37 -206
- package/dist/projections/request-events.js +2 -502
- package/dist/projections/upstream-events.js +1 -201
- package/dist/protocol/a2a/http-discovery.js +1 -178
- package/dist/protocol/a2a/http-rpc.js +6 -622
- package/dist/protocol/a2a/http.js +1 -138
- package/dist/protocol/a2a/task-state.js +3 -317
- package/dist/protocol/acp/client.js +8 -294
- package/dist/protocol/acp/harness-client.js +1 -218
- package/dist/protocol/acp/http.js +5 -130
- package/dist/protocol/acp/server.js +1 -310
- package/dist/protocol/acp/stdio.js +2 -69
- package/dist/protocol/ag-ui/http.js +3 -378
- package/dist/protocol/mcp/server.js +1 -428
- package/dist/resource/backend/workspace-scoped-backend.js +1 -319
- package/dist/resource/isolation.js +1 -237
- package/dist/resource/mcp/tool-support.js +3 -296
- package/dist/resource/mcp-tool-support.js +1 -2
- package/dist/resource/providers/resource-provider.js +1 -215
- package/dist/resource/resource-impl.js +1 -3
- package/dist/resource/resource-types.js +0 -1
- package/dist/resource/resource.js +1 -1
- package/dist/resource/sources.js +1 -247
- package/dist/resource/tools/function-tool-resolver.js +2 -272
- package/dist/runtime/adapter/compat/deepagent-compat.js +1 -29
- package/dist/runtime/adapter/compat/openai-compatible.js +1 -55
- package/dist/runtime/adapter/direct-builtin-utility.js +2 -90
- package/dist/runtime/adapter/flow/execution-context.js +1 -71
- package/dist/runtime/adapter/flow/invocation-flow.js +8 -425
- package/dist/runtime/adapter/flow/invoke-runtime.js +1 -20
- package/dist/runtime/adapter/flow/stream-runtime.js +11 -1395
- package/dist/runtime/adapter/invocation-result.js +2 -473
- package/dist/runtime/adapter/local-tool-invocation.js +6 -638
- package/dist/runtime/adapter/middleware/context-hygiene.js +1 -83
- package/dist/runtime/adapter/middleware-assembly.js +5 -477
- package/dist/runtime/adapter/model/invocation-request.js +3 -183
- package/dist/runtime/adapter/model/message-assembly.js +1 -28
- package/dist/runtime/adapter/model/model-providers.js +23 -1115
- package/dist/runtime/adapter/model/prompted-json-tool-call-capture.js +1 -40
- package/dist/runtime/adapter/model/prompted-json-tool-policy.js +1 -22
- package/dist/runtime/adapter/resilience.js +1 -104
- package/dist/runtime/adapter/runtime-adapter-support.js +3 -141
- package/dist/runtime/adapter/runtime-shell.js +5 -166
- package/dist/runtime/adapter/stream-event-projection.js +2 -622
- package/dist/runtime/adapter/stream-text-consumption.js +1 -18
- package/dist/runtime/adapter/terminal-status.js +2 -67
- package/dist/runtime/adapter/tool/builtin-middleware-tools.js +6 -627
- package/dist/runtime/adapter/tool/declared-middleware.js +1 -154
- package/dist/runtime/adapter/tool/interrupt-policy.js +1 -34
- package/dist/runtime/adapter/tool/provider-tool.js +1 -25
- package/dist/runtime/adapter/tool/resolved-tool.js +1 -225
- package/dist/runtime/adapter/tool/tool-arguments.js +3 -486
- package/dist/runtime/adapter/tool/tool-hitl.js +1 -346
- package/dist/runtime/adapter/tool/tool-name-mapping.js +1 -128
- package/dist/runtime/adapter/tool/tool-output-artifacts.js +2 -88
- package/dist/runtime/adapter/tool/tool-replay.js +1 -37
- package/dist/runtime/adapter/tool-resolution.js +1 -86
- package/dist/runtime/adapter/upstream-configurable-keys.js +1 -2
- package/dist/runtime/agent-runtime-adapter.js +60 -2338
- package/dist/runtime/agent-runtime-assembly.js +7 -249
- package/dist/runtime/env/runtime-env.js +1 -62
- package/dist/runtime/harness/background-runtime.js +1 -8
- package/dist/runtime/harness/bindings.js +1 -58
- package/dist/runtime/harness/events/event-bus.js +1 -16
- package/dist/runtime/harness/events/event-sink.js +1 -61
- package/dist/runtime/harness/events/events.js +1 -80
- package/dist/runtime/harness/events/listener-runtime.js +1 -13
- package/dist/runtime/harness/events/runtime-event-operations.js +1 -9
- package/dist/runtime/harness/events/streaming.js +1 -100
- package/dist/runtime/harness/events/timeline.js +1 -52
- package/dist/runtime/harness/public-shapes.js +1 -186
- package/dist/runtime/harness/run/artifact-paths.js +1 -15
- package/dist/runtime/harness/run/governance.js +1 -295
- package/dist/runtime/harness/run/helpers.js +1 -71
- package/dist/runtime/harness/run/inspection.js +1 -409
- package/dist/runtime/harness/run/operator-overview.js +1 -80
- package/dist/runtime/harness/run/queue-diagnostics.js +1 -15
- package/dist/runtime/harness/run/recovery.js +1 -162
- package/dist/runtime/harness/run/resources.js +1 -60
- package/dist/runtime/harness/run/resume.js +1 -56
- package/dist/runtime/harness/run/routing.js +1 -48
- package/dist/runtime/harness/run/run-lifecycle.js +1 -66
- package/dist/runtime/harness/run/run-operations.js +1 -217
- package/dist/runtime/harness/run/run-queue.js +1 -43
- package/dist/runtime/harness/run/run-slot-acquisition.js +1 -157
- package/dist/runtime/harness/run/session-records.js +1 -97
- package/dist/runtime/harness/run/start-run.js +1 -120
- package/dist/runtime/harness/run/startup-runtime.js +1 -69
- package/dist/runtime/harness/run/stream-run.js +8 -1418
- package/dist/runtime/harness/run/surface-semantics.js +1 -79
- package/dist/runtime/harness/runtime-defaults.js +1 -39
- package/dist/runtime/harness/system/boundary-analysis.js +1 -234
- package/dist/runtime/harness/system/health-monitor.js +1 -258
- package/dist/runtime/harness/system/inventory.js +1 -129
- package/dist/runtime/harness/system/mem0-ingestion-sync.js +5 -345
- package/dist/runtime/harness/system/policy-engine.js +1 -175
- package/dist/runtime/harness/system/runtime-memory-candidates.js +4 -110
- package/dist/runtime/harness/system/runtime-memory-consolidation.js +1 -51
- package/dist/runtime/harness/system/runtime-memory-manager.js +10 -693
- package/dist/runtime/harness/system/runtime-memory-policy.js +1 -155
- package/dist/runtime/harness/system/runtime-memory-records.js +11 -577
- package/dist/runtime/harness/system/runtime-memory-sync.js +5 -206
- package/dist/runtime/harness/system/session-memory-sync.js +3 -113
- package/dist/runtime/harness/system/skill-requirements.js +1 -112
- package/dist/runtime/harness/system/store.js +9 -365
- package/dist/runtime/harness/tool-gateway/index.js +1 -2
- package/dist/runtime/harness/tool-gateway/policy.js +1 -45
- package/dist/runtime/harness/tool-gateway/validation.js +1 -176
- package/dist/runtime/harness/tool-schema.js +1 -3
- package/dist/runtime/harness.js +3 -1490
- package/dist/runtime/index.js +1 -3
- package/dist/runtime/layout/runtime-layout.js +1 -31
- package/dist/runtime/maintenance/checkpoint-maintenance.js +2 -178
- package/dist/runtime/maintenance/file-checkpoint-saver.js +1 -106
- package/dist/runtime/maintenance/runtime-record-maintenance.js +2 -169
- package/dist/runtime/maintenance/sqlite-checkpoint-saver.js +4 -289
- package/dist/runtime/parsing/output-content.js +10 -550
- package/dist/runtime/parsing/output-parsing.js +1 -4
- package/dist/runtime/parsing/output-recovery.js +3 -213
- package/dist/runtime/parsing/output-tool-args.js +7 -663
- package/dist/runtime/parsing/stream-event-parsing.js +3 -362
- package/dist/runtime/prompts/runtime-prompts.js +4 -73
- package/dist/runtime/scheduling/system-schedule-manager.js +11 -532
- package/dist/runtime/skills/skill-metadata.js +1 -197
- package/dist/runtime/startup-tracing.js +2 -37
- package/dist/runtime/support/compiled-binding.js +1 -290
- package/dist/runtime/support/embedding-models.js +1 -118
- package/dist/runtime/support/harness-support.js +5 -137
- package/dist/runtime/support/llamaindex.js +1 -108
- package/dist/runtime/support/runtime-adapter-options.js +1 -29
- package/dist/runtime/support/runtime-factories.js +1 -51
- package/dist/runtime/support/vector-stores.js +9 -270
- package/dist/scaffold/init-project.js +54 -233
- package/dist/tooling/extensions.js +1 -311
- package/dist/tooling/module-loader.js +1 -55
- package/dist/tools.js +1 -176
- package/dist/utils/agent-display.js +1 -18
- package/dist/utils/bundled-text.js +4 -39
- package/dist/utils/compiled-binding.js +1 -33
- package/dist/utils/fs.js +2 -45
- package/dist/utils/id.js +1 -9
- package/dist/utils/message-content.js +1 -30
- package/dist/utils/object.js +1 -6
- package/dist/workspace/agent-binding-compiler.js +3 -613
- package/dist/workspace/compile.js +1 -472
- package/dist/workspace/framework-contract-validation.js +2 -322
- package/dist/workspace/index.js +1 -1
- package/dist/workspace/object-loader-paths.js +1 -71
- package/dist/workspace/object-loader-readers.js +1 -187
- package/dist/workspace/object-loader.js +1 -754
- package/dist/workspace/resource-compilers.js +1 -374
- package/dist/workspace/support/agent-capabilities.js +1 -37
- package/dist/workspace/support/agent-execution-config.js +1 -44
- package/dist/workspace/support/discovery.js +1 -147
- package/dist/workspace/support/source-collectors.js +1 -30
- package/dist/workspace/support/source-protocols.js +2 -192
- package/dist/workspace/support/workspace-ref-utils.js +1 -362
- package/dist/workspace/tool-hydration.js +1 -280
- package/dist/workspace/validate.js +1 -99
- package/dist/workspace/yaml-object-reader.js +1 -285
- package/package.json +7 -3
|
@@ -1,175 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
export class PolicyEngine {
|
|
3
|
-
/**
|
|
4
|
-
* Runtime governance gate for a compiled binding.
|
|
5
|
-
* This engine may allow or block execution with reasons, but it must not
|
|
6
|
-
* redefine upstream planning or execution semantics.
|
|
7
|
-
*/
|
|
8
|
-
evaluate(binding) {
|
|
9
|
-
const reasons = [];
|
|
10
|
-
const bundles = [];
|
|
11
|
-
let allowed = true;
|
|
12
|
-
const governance = typeof binding.harnessRuntime.governance === "object" && binding.harnessRuntime.governance
|
|
13
|
-
? binding.harnessRuntime.governance
|
|
14
|
-
: undefined;
|
|
15
|
-
const remoteMcp = typeof governance?.remoteMcp === "object" && governance.remoteMcp
|
|
16
|
-
? governance.remoteMcp
|
|
17
|
-
: undefined;
|
|
18
|
-
const denyConfig = typeof governance?.deny === "object" && governance.deny
|
|
19
|
-
? governance.deny
|
|
20
|
-
: undefined;
|
|
21
|
-
if (denyConfig) {
|
|
22
|
-
const deniedNames = new Set(Array.isArray(denyConfig.toolNames)
|
|
23
|
-
? denyConfig.toolNames.filter((item) => typeof item === "string" && item.trim().length > 0).map((item) => item.trim())
|
|
24
|
-
: []);
|
|
25
|
-
const deniedCategories = new Set(Array.isArray(denyConfig.categories)
|
|
26
|
-
? denyConfig.categories.filter((item) => typeof item === "string" && item.trim().length > 0).map((item) => item.trim())
|
|
27
|
-
: []);
|
|
28
|
-
const tools = binding.execution?.params?.tools ?? binding.langchainAgentParams?.tools ?? binding.deepAgentParams?.tools ?? [];
|
|
29
|
-
const blocked = tools.filter((tool) => {
|
|
30
|
-
const category = tool.type === "mcp"
|
|
31
|
-
? "mcp"
|
|
32
|
-
: tool.type === "backend"
|
|
33
|
-
? "backend"
|
|
34
|
-
: tool.type === "provider"
|
|
35
|
-
? "provider-native"
|
|
36
|
-
: "local";
|
|
37
|
-
return deniedNames.has(tool.name) || deniedCategories.has(category);
|
|
38
|
-
});
|
|
39
|
-
if (blocked.length > 0) {
|
|
40
|
-
allowed = false;
|
|
41
|
-
reasons.push(`runtime governance denied tool access: ${blocked.map((tool) => tool.name).join(", ")}`);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
if (remoteMcp) {
|
|
45
|
-
const normalizeServerRef = (value) => {
|
|
46
|
-
if (typeof value !== "string" || value.trim().length === 0) {
|
|
47
|
-
return undefined;
|
|
48
|
-
}
|
|
49
|
-
const trimmed = value.trim();
|
|
50
|
-
return trimmed.startsWith("mcp/") ? trimmed : `mcp/${trimmed}`;
|
|
51
|
-
};
|
|
52
|
-
const readStringSet = (value) => new Set(Array.isArray(value)
|
|
53
|
-
? value.filter((item) => typeof item === "string" && item.trim().length > 0).map((item) => item.trim())
|
|
54
|
-
: []);
|
|
55
|
-
const riskRank = {
|
|
56
|
-
low: 0,
|
|
57
|
-
medium: 1,
|
|
58
|
-
high: 2,
|
|
59
|
-
};
|
|
60
|
-
const maxPromptInjectionRisk = remoteMcp.maxPromptInjectionRisk === "low" || remoteMcp.maxPromptInjectionRisk === "medium" || remoteMcp.maxPromptInjectionRisk === "high"
|
|
61
|
-
? remoteMcp.maxPromptInjectionRisk
|
|
62
|
-
: undefined;
|
|
63
|
-
const allowServerRefs = new Set(Array.isArray(remoteMcp.allowServerRefs)
|
|
64
|
-
? remoteMcp.allowServerRefs
|
|
65
|
-
.map((item) => normalizeServerRef(item))
|
|
66
|
-
.filter((item) => Boolean(item))
|
|
67
|
-
: []);
|
|
68
|
-
const denyServerRefs = new Set(Array.isArray(remoteMcp.denyServerRefs)
|
|
69
|
-
? remoteMcp.denyServerRefs
|
|
70
|
-
.map((item) => normalizeServerRef(item))
|
|
71
|
-
.filter((item) => Boolean(item))
|
|
72
|
-
: []);
|
|
73
|
-
const denyTransports = readStringSet(remoteMcp.denyTransports);
|
|
74
|
-
const allowTrustTiers = readStringSet(remoteMcp.allowTrustTiers);
|
|
75
|
-
const denyTrustTiers = readStringSet(remoteMcp.denyTrustTiers);
|
|
76
|
-
const allowTenantScopes = readStringSet(remoteMcp.allowTenantScopes);
|
|
77
|
-
const denyTenantScopes = readStringSet(remoteMcp.denyTenantScopes);
|
|
78
|
-
const denyPromptInjectionRisks = readStringSet(remoteMcp.denyPromptInjectionRisks);
|
|
79
|
-
const allowOauthScopes = readStringSet(remoteMcp.allowOauthScopes);
|
|
80
|
-
const denyOauthScopes = readStringSet(remoteMcp.denyOauthScopes);
|
|
81
|
-
const tools = binding.execution?.params?.tools ?? binding.langchainAgentParams?.tools ?? binding.deepAgentParams?.tools ?? [];
|
|
82
|
-
const deniedRemoteTools = tools.flatMap((tool) => {
|
|
83
|
-
if (tool.type !== "mcp") {
|
|
84
|
-
return [];
|
|
85
|
-
}
|
|
86
|
-
const config = typeof tool.config === "object" && tool.config && !Array.isArray(tool.config)
|
|
87
|
-
? tool.config
|
|
88
|
-
: undefined;
|
|
89
|
-
const mcpRef = typeof config?.mcp === "object" && config.mcp && !Array.isArray(config.mcp)
|
|
90
|
-
? config.mcp
|
|
91
|
-
: undefined;
|
|
92
|
-
const inlineMcpServer = typeof config?.mcpServer === "object" && config.mcpServer && !Array.isArray(config.mcpServer)
|
|
93
|
-
? config.mcpServer
|
|
94
|
-
: undefined;
|
|
95
|
-
const serverRef = normalizeServerRef(mcpRef?.serverRef);
|
|
96
|
-
const transport = typeof inlineMcpServer?.transport === "string" && inlineMcpServer.transport.trim().length > 0
|
|
97
|
-
? inlineMcpServer.transport.trim()
|
|
98
|
-
: undefined;
|
|
99
|
-
const trustTier = inlineMcpServer?.trustTier === "trusted" || inlineMcpServer?.trustTier === "reviewed" || inlineMcpServer?.trustTier === "untrusted"
|
|
100
|
-
? inlineMcpServer.trustTier
|
|
101
|
-
: undefined;
|
|
102
|
-
const tenantScope = inlineMcpServer?.tenantScope === "workspace" ||
|
|
103
|
-
inlineMcpServer?.tenantScope === "project" ||
|
|
104
|
-
inlineMcpServer?.tenantScope === "tenant" ||
|
|
105
|
-
inlineMcpServer?.tenantScope === "cross-tenant"
|
|
106
|
-
? inlineMcpServer.tenantScope
|
|
107
|
-
: undefined;
|
|
108
|
-
const promptInjectionRisk = inlineMcpServer?.promptInjectionRisk === "low" ||
|
|
109
|
-
inlineMcpServer?.promptInjectionRisk === "medium" ||
|
|
110
|
-
inlineMcpServer?.promptInjectionRisk === "high"
|
|
111
|
-
? inlineMcpServer.promptInjectionRisk
|
|
112
|
-
: undefined;
|
|
113
|
-
const oauth = typeof inlineMcpServer?.oauth === "object" && inlineMcpServer.oauth && !Array.isArray(inlineMcpServer.oauth)
|
|
114
|
-
? inlineMcpServer.oauth
|
|
115
|
-
: undefined;
|
|
116
|
-
const oauthScopes = Array.isArray(oauth?.scopes)
|
|
117
|
-
? oauth.scopes.filter((item) => typeof item === "string" && item.trim().length > 0).map((item) => item.trim())
|
|
118
|
-
: [];
|
|
119
|
-
const serverDenied = serverRef ? denyServerRefs.has(serverRef) || (allowServerRefs.size > 0 && !allowServerRefs.has(serverRef)) : false;
|
|
120
|
-
const transportDenied = transport ? denyTransports.has(transport) : false;
|
|
121
|
-
const trustDenied = trustTier ? denyTrustTiers.has(trustTier) || (allowTrustTiers.size > 0 && !allowTrustTiers.has(trustTier)) : false;
|
|
122
|
-
const tenantDenied = tenantScope ? denyTenantScopes.has(tenantScope) || (allowTenantScopes.size > 0 && !allowTenantScopes.has(tenantScope)) : false;
|
|
123
|
-
const promptRiskDenied = (promptInjectionRisk ? denyPromptInjectionRisks.has(promptInjectionRisk) : false)
|
|
124
|
-
|| (promptInjectionRisk && maxPromptInjectionRisk ? riskRank[promptInjectionRisk] > riskRank[maxPromptInjectionRisk] : false);
|
|
125
|
-
const oauthDenied = oauthScopes.some((scope) => denyOauthScopes.has(scope))
|
|
126
|
-
|| (allowOauthScopes.size > 0 && oauthScopes.some((scope) => !allowOauthScopes.has(scope)));
|
|
127
|
-
return serverDenied || transportDenied || trustDenied || tenantDenied || promptRiskDenied || oauthDenied
|
|
128
|
-
? [{
|
|
129
|
-
toolName: tool.name,
|
|
130
|
-
...(serverRef ? { serverRef } : {}),
|
|
131
|
-
...(transport ? { transport } : {}),
|
|
132
|
-
...(trustTier ? { trustTier } : {}),
|
|
133
|
-
...(tenantScope ? { tenantScope } : {}),
|
|
134
|
-
...(promptInjectionRisk ? { promptInjectionRisk } : {}),
|
|
135
|
-
...(oauthScopes.length > 0 ? { oauthScopes } : {}),
|
|
136
|
-
}]
|
|
137
|
-
: [];
|
|
138
|
-
});
|
|
139
|
-
if (deniedRemoteTools.length > 0) {
|
|
140
|
-
allowed = false;
|
|
141
|
-
const details = deniedRemoteTools.map((tool) => {
|
|
142
|
-
if (tool.serverRef && tool.transport) {
|
|
143
|
-
return `${tool.toolName} (${tool.serverRef}, ${tool.transport})`;
|
|
144
|
-
}
|
|
145
|
-
if (tool.serverRef) {
|
|
146
|
-
return `${tool.toolName} (${tool.serverRef})`;
|
|
147
|
-
}
|
|
148
|
-
if (tool.transport) {
|
|
149
|
-
return `${tool.toolName} (${tool.transport})`;
|
|
150
|
-
}
|
|
151
|
-
if (tool.trustTier) {
|
|
152
|
-
return `${tool.toolName} (${tool.trustTier})`;
|
|
153
|
-
}
|
|
154
|
-
return tool.toolName;
|
|
155
|
-
});
|
|
156
|
-
reasons.push(`runtime governance denied remote MCP access: ${details.join(", ")}`);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
for (const evaluator of getPolicyEvaluators()) {
|
|
160
|
-
const decision = evaluator.evaluate(binding);
|
|
161
|
-
if (!decision) {
|
|
162
|
-
continue;
|
|
163
|
-
}
|
|
164
|
-
if (!decision.allowed) {
|
|
165
|
-
allowed = false;
|
|
166
|
-
}
|
|
167
|
-
reasons.push(...decision.reasons);
|
|
168
|
-
if (Array.isArray(decision.bundles)) {
|
|
169
|
-
bundles.push(...decision.bundles);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
return bundles.length > 0 ? { allowed, reasons, bundles } : { allowed, reasons };
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
export { PolicyEngine as GovernanceEngine, };
|
|
1
|
+
import{getPolicyEvaluators as W}from"../../../tooling/extensions.js";class q{evaluate(a){const f=[],v=[];let d=!0;const p=typeof a.harnessRuntime.governance=="object"&&a.harnessRuntime.governance?a.harnessRuntime.governance:void 0,s=typeof p?.remoteMcp=="object"&&p.remoteMcp?p.remoteMcp:void 0,u=typeof p?.deny=="object"&&p.deny?p.deny:void 0;if(u){const c=new Set(Array.isArray(u.toolNames)?u.toolNames.filter(r=>typeof r=="string"&&r.trim().length>0).map(r=>r.trim()):[]),o=new Set(Array.isArray(u.categories)?u.categories.filter(r=>typeof r=="string"&&r.trim().length>0).map(r=>r.trim()):[]),l=(a.execution?.params?.tools??a.langchainAgentParams?.tools??a.deepAgentParams?.tools??[]).filter(r=>{const j=r.type==="mcp"?"mcp":r.type==="backend"?"backend":r.type==="provider"?"provider-native":"local";return c.has(r.name)||o.has(j)});l.length>0&&(d=!1,f.push(`runtime governance denied tool access: ${l.map(r=>r.name).join(", ")}`))}if(s){const c=t=>{if(typeof t!="string"||t.trim().length===0)return;const e=t.trim();return e.startsWith("mcp/")?e:`mcp/${e}`},o=t=>new Set(Array.isArray(t)?t.filter(e=>typeof e=="string"&&e.trim().length>0).map(e=>e.trim()):[]),A={low:0,medium:1,high:2},l=s.maxPromptInjectionRisk==="low"||s.maxPromptInjectionRisk==="medium"||s.maxPromptInjectionRisk==="high"?s.maxPromptInjectionRisk:void 0,r=new Set(Array.isArray(s.allowServerRefs)?s.allowServerRefs.map(t=>c(t)).filter(t=>!!t):[]),j=new Set(Array.isArray(s.denyServerRefs)?s.denyServerRefs.map(t=>c(t)).filter(t=>!!t):[]),$=o(s.denyTransports),T=o(s.allowTrustTiers),x=o(s.denyTrustTiers),w=o(s.allowTenantScopes),N=o(s.denyTenantScopes),M=o(s.denyPromptInjectionRisks),k=o(s.allowOauthScopes),D=o(s.denyOauthScopes),P=(a.execution?.params?.tools??a.langchainAgentParams?.tools??a.deepAgentParams?.tools??[]).flatMap(t=>{if(t.type!=="mcp")return[];const e=typeof t.config=="object"&&t.config&&!Array.isArray(t.config)?t.config:void 0,z=typeof e?.mcp=="object"&&e.mcp&&!Array.isArray(e.mcp)?e.mcp:void 0,n=typeof e?.mcpServer=="object"&&e.mcpServer&&!Array.isArray(e.mcpServer)?e.mcpServer:void 0,y=c(z?.serverRef),S=typeof n?.transport=="string"&&n.transport.trim().length>0?n.transport.trim():void 0,h=n?.trustTier==="trusted"||n?.trustTier==="reviewed"||n?.trustTier==="untrusted"?n.trustTier:void 0,g=n?.tenantScope==="workspace"||n?.tenantScope==="project"||n?.tenantScope==="tenant"||n?.tenantScope==="cross-tenant"?n.tenantScope:void 0,m=n?.promptInjectionRisk==="low"||n?.promptInjectionRisk==="medium"||n?.promptInjectionRisk==="high"?n.promptInjectionRisk:void 0,I=typeof n?.oauth=="object"&&n.oauth&&!Array.isArray(n.oauth)?n.oauth:void 0,R=Array.isArray(I?.scopes)?I.scopes.filter(i=>typeof i=="string"&&i.trim().length>0).map(i=>i.trim()):[],b=y?j.has(y)||r.size>0&&!r.has(y):!1,O=S?$.has(S):!1,C=h?x.has(h)||T.size>0&&!T.has(h):!1,E=g?N.has(g)||w.size>0&&!w.has(g):!1,B=(m?M.has(m):!1)||(m&&l?A[m]>A[l]:!1),G=R.some(i=>D.has(i))||k.size>0&&R.some(i=>!k.has(i));return b||O||C||E||B||G?[{toolName:t.name,...y?{serverRef:y}:{},...S?{transport:S}:{},...h?{trustTier:h}:{},...g?{tenantScope:g}:{},...m?{promptInjectionRisk:m}:{},...R.length>0?{oauthScopes:R}:{}}]:[]});if(P.length>0){d=!1;const t=P.map(e=>e.serverRef&&e.transport?`${e.toolName} (${e.serverRef}, ${e.transport})`:e.serverRef?`${e.toolName} (${e.serverRef})`:e.transport?`${e.toolName} (${e.transport})`:e.trustTier?`${e.toolName} (${e.trustTier})`:e.toolName);f.push(`runtime governance denied remote MCP access: ${t.join(", ")}`)}}for(const c of W()){const o=c.evaluate(a);o&&(o.allowed||(d=!1),f.push(...o.reasons),Array.isArray(o.bundles)&&v.push(...o.bundles))}return v.length>0?{allowed:d,reasons:f,bundles:v}:{allowed:d,reasons:f}}}export{q as GovernanceEngine,q as PolicyEngine};
|
|
@@ -1,110 +1,4 @@
|
|
|
1
|
-
function
|
|
2
|
-
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
return typeof value === "string" && value.trim().length > 0 ? value.trim() : undefined;
|
|
6
|
-
}
|
|
7
|
-
function asNumber(value) {
|
|
8
|
-
return typeof value === "number" && Number.isFinite(value) ? value : undefined;
|
|
9
|
-
}
|
|
10
|
-
function asStringArray(value) {
|
|
11
|
-
if (!Array.isArray(value)) {
|
|
12
|
-
return undefined;
|
|
13
|
-
}
|
|
14
|
-
const items = value
|
|
15
|
-
.filter((item) => typeof item === "string" && item.trim().length > 0)
|
|
16
|
-
.map((item) => item.trim());
|
|
17
|
-
return items.length > 0 ? items : undefined;
|
|
18
|
-
}
|
|
19
|
-
function stringifyCandidateContent(output) {
|
|
20
|
-
if (typeof output === "string") {
|
|
21
|
-
return output.trim();
|
|
22
|
-
}
|
|
23
|
-
if (typeof output === "number" || typeof output === "boolean") {
|
|
24
|
-
return String(output);
|
|
25
|
-
}
|
|
26
|
-
if (typeof output === "object" && output !== null) {
|
|
27
|
-
try {
|
|
28
|
-
return JSON.stringify(output, null, 2);
|
|
29
|
-
}
|
|
30
|
-
catch {
|
|
31
|
-
return "";
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return "";
|
|
35
|
-
}
|
|
36
|
-
function normalizeCandidate(value, fallback) {
|
|
37
|
-
const record = asRecord(value);
|
|
38
|
-
if (!record) {
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
const content = asString(record.content);
|
|
42
|
-
if (!content) {
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
45
|
-
return {
|
|
46
|
-
content,
|
|
47
|
-
...(asString(record.summary) ? { summary: asString(record.summary) } : {}),
|
|
48
|
-
...(asString(record.kind) ?? fallback.kind ? { kind: asString(record.kind) ?? fallback.kind } : {}),
|
|
49
|
-
...(asString(record.scope) ?? fallback.scope ? { scope: asString(record.scope) ?? fallback.scope } : {}),
|
|
50
|
-
...(asNumber(record.confidence) !== undefined ? { confidence: asNumber(record.confidence) } : {}),
|
|
51
|
-
...(asStringArray(record.tags) ?? fallback.tags ? { tags: asStringArray(record.tags) ?? fallback.tags } : {}),
|
|
52
|
-
...(asString(record.sourceType) ?? fallback.sourceType ? { sourceType: asString(record.sourceType) ?? fallback.sourceType } : {}),
|
|
53
|
-
...(asString(record.sourceRef) ? { sourceRef: asString(record.sourceRef) } : {}),
|
|
54
|
-
...(asString(record.observedAt) ? { observedAt: asString(record.observedAt) } : {}),
|
|
55
|
-
...(asString(record.sensitivity) ? { sensitivity: asString(record.sensitivity) } : {}),
|
|
56
|
-
...(typeof record.noStore === "boolean" ? { noStore: record.noStore } : {}),
|
|
57
|
-
...(asRecord(record.provenance) ? { provenance: asRecord(record.provenance) } : {}),
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
export function extractMemoryCandidatesFromToolOutput(tool, output) {
|
|
61
|
-
const memoryConfig = asRecord(tool.config?.memory);
|
|
62
|
-
if (memoryConfig?.enabled !== true) {
|
|
63
|
-
return [];
|
|
64
|
-
}
|
|
65
|
-
const fallback = {
|
|
66
|
-
sourceType: "tool-output",
|
|
67
|
-
kind: asString(memoryConfig.kind),
|
|
68
|
-
scope: asString(memoryConfig.scope) ?? "session",
|
|
69
|
-
tags: asStringArray(memoryConfig.tags),
|
|
70
|
-
};
|
|
71
|
-
const explicitCandidates = asRecord(output)?.memoryCandidates;
|
|
72
|
-
if (Array.isArray(explicitCandidates)) {
|
|
73
|
-
const maxCandidates = asNumber(memoryConfig.maxCandidates) ?? explicitCandidates.length;
|
|
74
|
-
return explicitCandidates
|
|
75
|
-
.map((candidate) => normalizeCandidate(candidate, fallback))
|
|
76
|
-
.filter((candidate) => Boolean(candidate))
|
|
77
|
-
.slice(0, maxCandidates);
|
|
78
|
-
}
|
|
79
|
-
const content = stringifyCandidateContent(output);
|
|
80
|
-
if (!content) {
|
|
81
|
-
return [];
|
|
82
|
-
}
|
|
83
|
-
return [{
|
|
84
|
-
content,
|
|
85
|
-
...(fallback.kind ? { kind: fallback.kind } : {}),
|
|
86
|
-
...(fallback.scope ? { scope: fallback.scope } : {}),
|
|
87
|
-
...(fallback.tags ? { tags: fallback.tags } : {}),
|
|
88
|
-
sourceType: fallback.sourceType,
|
|
89
|
-
}];
|
|
90
|
-
}
|
|
91
|
-
export function renderMemoryCandidatesMarkdown(title, candidates) {
|
|
92
|
-
const lines = [`# ${title}`, ""];
|
|
93
|
-
if (candidates.length === 0) {
|
|
94
|
-
lines.push("(none)", "");
|
|
95
|
-
return lines.join("\n");
|
|
96
|
-
}
|
|
97
|
-
for (const candidate of candidates) {
|
|
98
|
-
lines.push(`## ${(candidate.summary ?? candidate.content).split("\n")[0].slice(0, 120)}`);
|
|
99
|
-
lines.push(`- kind: ${candidate.kind ?? "summary"}`);
|
|
100
|
-
lines.push(`- scope: ${candidate.scope ?? "session"}`);
|
|
101
|
-
lines.push(`- source_type: ${candidate.sourceType ?? "tool-output"}`);
|
|
102
|
-
if (candidate.tags && candidate.tags.length > 0) {
|
|
103
|
-
lines.push(`- tags: ${candidate.tags.join(", ")}`);
|
|
104
|
-
}
|
|
105
|
-
lines.push("");
|
|
106
|
-
lines.push(candidate.summary ?? candidate.content);
|
|
107
|
-
lines.push("");
|
|
108
|
-
}
|
|
109
|
-
return lines.join("\n");
|
|
110
|
-
}
|
|
1
|
+
function s(n){return typeof n=="object"&&n!==null&&!Array.isArray(n)?n:void 0}function o(n){return typeof n=="string"&&n.trim().length>0?n.trim():void 0}function u(n){return typeof n=="number"&&Number.isFinite(n)?n:void 0}function d(n){if(!Array.isArray(n))return;const t=n.filter(e=>typeof e=="string"&&e.trim().length>0).map(e=>e.trim());return t.length>0?t:void 0}function a(n){if(typeof n=="string")return n.trim();if(typeof n=="number"||typeof n=="boolean")return String(n);if(typeof n=="object"&&n!==null)try{return JSON.stringify(n,null,2)}catch{return""}return""}function f(n,t){const e=s(n);if(!e)return null;const r=o(e.content);return r?{content:r,...o(e.summary)?{summary:o(e.summary)}:{},...o(e.kind)??t.kind?{kind:o(e.kind)??t.kind}:{},...o(e.scope)??t.scope?{scope:o(e.scope)??t.scope}:{},...u(e.confidence)!==void 0?{confidence:u(e.confidence)}:{},...d(e.tags)??t.tags?{tags:d(e.tags)??t.tags}:{},...o(e.sourceType)??t.sourceType?{sourceType:o(e.sourceType)??t.sourceType}:{},...o(e.sourceRef)?{sourceRef:o(e.sourceRef)}:{},...o(e.observedAt)?{observedAt:o(e.observedAt)}:{},...o(e.sensitivity)?{sensitivity:o(e.sensitivity)}:{},...typeof e.noStore=="boolean"?{noStore:e.noStore}:{},...s(e.provenance)?{provenance:s(e.provenance)}:{}}:null}function m(n,t){const e=s(n.config?.memory);if(e?.enabled!==!0)return[];const r={sourceType:"tool-output",kind:o(e.kind),scope:o(e.scope)??"session",tags:d(e.tags)},i=s(t)?.memoryCandidates;if(Array.isArray(i)){const y=u(e.maxCandidates)??i.length;return i.map(c=>f(c,r)).filter(c=>!!c).slice(0,y)}const p=a(t);return p?[{content:p,...r.kind?{kind:r.kind}:{},...r.scope?{scope:r.scope}:{},...r.tags?{tags:r.tags}:{},sourceType:r.sourceType}]:[]}function g(n,t){const e=[`# ${n}`,""];if(t.length===0)return e.push("(none)",""),e.join(`
|
|
2
|
+
`);for(const r of t)e.push(`## ${(r.summary??r.content).split(`
|
|
3
|
+
`)[0].slice(0,120)}`),e.push(`- kind: ${r.kind??"summary"}`),e.push(`- scope: ${r.scope??"session"}`),e.push(`- source_type: ${r.sourceType??"tool-output"}`),r.tags&&r.tags.length>0&&e.push(`- tags: ${r.tags.join(", ")}`),e.push(""),e.push(r.summary??r.content),e.push("");return e.join(`
|
|
4
|
+
`)}export{m as extractMemoryCandidatesFromToolOutput,g as renderMemoryCandidatesMarkdown};
|
|
@@ -1,51 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
function normalizeText(value) {
|
|
3
|
-
return value.toLowerCase().replace(/\s+/g, " ").trim();
|
|
4
|
-
}
|
|
5
|
-
function sortByLastConfirmed(records) {
|
|
6
|
-
return [...records].sort((left, right) => left.lastConfirmedAt.localeCompare(right.lastConfirmedAt));
|
|
7
|
-
}
|
|
8
|
-
export async function consolidateStructuredMemoryScope(input) {
|
|
9
|
-
const now = input.now ?? new Date().toISOString();
|
|
10
|
-
const records = sortByLastConfirmed(await listMemoryRecordsForScopes(input.store, [input.scope]));
|
|
11
|
-
const updates = new Map();
|
|
12
|
-
if (input.config?.dedupe !== false) {
|
|
13
|
-
const activeRecords = records.filter((record) => record.status === "active");
|
|
14
|
-
const seen = new Map();
|
|
15
|
-
for (const record of activeRecords) {
|
|
16
|
-
const identity = `${record.canonicalKey}:${normalizeText(record.content)}`;
|
|
17
|
-
const prior = seen.get(identity);
|
|
18
|
-
if (!prior) {
|
|
19
|
-
seen.set(identity, record);
|
|
20
|
-
continue;
|
|
21
|
-
}
|
|
22
|
-
const archived = {
|
|
23
|
-
...prior,
|
|
24
|
-
status: "archived",
|
|
25
|
-
lastConfirmedAt: now,
|
|
26
|
-
supersedes: Array.from(new Set([...prior.supersedes, record.id])),
|
|
27
|
-
revision: prior.revision + 1,
|
|
28
|
-
};
|
|
29
|
-
updates.set(archived.id, archived);
|
|
30
|
-
seen.set(identity, record);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
if (typeof input.config?.maxAgeDays === "number" && input.config.maxAgeDays > 0) {
|
|
34
|
-
const threshold = Date.parse(now) - input.config.maxAgeDays * 24 * 60 * 60 * 1000;
|
|
35
|
-
for (const record of records) {
|
|
36
|
-
if (record.status !== "active") {
|
|
37
|
-
continue;
|
|
38
|
-
}
|
|
39
|
-
const updated = Date.parse(record.lastConfirmedAt);
|
|
40
|
-
if (Number.isFinite(updated) && updated < threshold) {
|
|
41
|
-
updates.set(record.id, {
|
|
42
|
-
...record,
|
|
43
|
-
status: "stale",
|
|
44
|
-
revision: record.revision + 1,
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
await Promise.all(Array.from(updates.values()).map((record) => input.store.put(["memories", "records", input.scope], `${record.id}.json`, record)));
|
|
50
|
-
await rebuildStructuredMemoryProjections(input.store, input.namespace, input.title, input.scope, input.maxEntries);
|
|
51
|
-
}
|
|
1
|
+
import{listMemoryRecordsForScopes as f,rebuildStructuredMemoryProjections as m}from"./runtime-memory-records.js";function l(e){return e.toLowerCase().replace(/\s+/g," ").trim()}function y(e){return[...e].sort((r,a)=>r.lastConfirmedAt.localeCompare(a.lastConfirmedAt))}async function g(e){const r=e.now??new Date().toISOString(),a=y(await f(e.store,[e.scope])),i=new Map;if(e.config?.dedupe!==!1){const t=a.filter(o=>o.status==="active"),s=new Map;for(const o of t){const n=`${o.canonicalKey}:${l(o.content)}`,c=s.get(n);if(!c){s.set(n,o);continue}const d={...c,status:"archived",lastConfirmedAt:r,supersedes:Array.from(new Set([...c.supersedes,o.id])),revision:c.revision+1};i.set(d.id,d),s.set(n,o)}}if(typeof e.config?.maxAgeDays=="number"&&e.config.maxAgeDays>0){const t=Date.parse(r)-e.config.maxAgeDays*24*60*60*1e3;for(const s of a){if(s.status!=="active")continue;const o=Date.parse(s.lastConfirmedAt);Number.isFinite(o)&&o<t&&i.set(s.id,{...s,status:"stale",revision:s.revision+1})}}await Promise.all(Array.from(i.values()).map(t=>e.store.put(["memories","records",e.scope],`${t.id}.json`,t))),await m(e.store,e.namespace,e.title,e.scope,e.maxEntries)}export{g as consolidateStructuredMemoryScope};
|