@vess-id/vess 0.0.0-dev-20260902121045
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/LICENSE +64 -0
- package/README.md +215 -0
- package/bin/vess.js +2 -0
- package/dist/__mocks__/@napi-rs/keyring.d.ts +9 -0
- package/dist/__mocks__/@napi-rs/keyring.d.ts.map +1 -0
- package/dist/__mocks__/@napi-rs/keyring.js +33 -0
- package/dist/__mocks__/@napi-rs/keyring.js.map +1 -0
- package/dist/__mocks__/node-mac-auth.d.ts +8 -0
- package/dist/__mocks__/node-mac-auth.d.ts.map +1 -0
- package/dist/__mocks__/node-mac-auth.js +29 -0
- package/dist/__mocks__/node-mac-auth.js.map +1 -0
- package/dist/adapter/mcp/http-transport.d.ts +40 -0
- package/dist/adapter/mcp/http-transport.d.ts.map +1 -0
- package/dist/adapter/mcp/http-transport.js +228 -0
- package/dist/adapter/mcp/http-transport.js.map +1 -0
- package/dist/adapter/mcp/mcp-adapter.d.ts +43 -0
- package/dist/adapter/mcp/mcp-adapter.d.ts.map +1 -0
- package/dist/adapter/mcp/mcp-adapter.js +65 -0
- package/dist/adapter/mcp/mcp-adapter.js.map +1 -0
- package/dist/adapter/mcp/mcp-server.factory.d.ts +44 -0
- package/dist/adapter/mcp/mcp-server.factory.d.ts.map +1 -0
- package/dist/adapter/mcp/mcp-server.factory.js +311 -0
- package/dist/adapter/mcp/mcp-server.factory.js.map +1 -0
- package/dist/adapter/mcp/stdio-transport.d.ts +7 -0
- package/dist/adapter/mcp/stdio-transport.d.ts.map +1 -0
- package/dist/adapter/mcp/stdio-transport.js +13 -0
- package/dist/adapter/mcp/stdio-transport.js.map +1 -0
- package/dist/adapter/mcp/transport.d.ts +10 -0
- package/dist/adapter/mcp/transport.d.ts.map +1 -0
- package/dist/adapter/mcp/transport.js +14 -0
- package/dist/adapter/mcp/transport.js.map +1 -0
- package/dist/approval/approval-token.d.ts +23 -0
- package/dist/approval/approval-token.d.ts.map +1 -0
- package/dist/approval/approval-token.js +81 -0
- package/dist/approval/approval-token.js.map +1 -0
- package/dist/audit/audit-dto-mapper.d.ts +29 -0
- package/dist/audit/audit-dto-mapper.d.ts.map +1 -0
- package/dist/audit/audit-dto-mapper.js +61 -0
- package/dist/audit/audit-dto-mapper.js.map +1 -0
- package/dist/audit/audit-logger.d.ts +35 -0
- package/dist/audit/audit-logger.d.ts.map +1 -0
- package/dist/audit/audit-logger.js +67 -0
- package/dist/audit/audit-logger.js.map +1 -0
- package/dist/audit/audit-sync.d.ts +12 -0
- package/dist/audit/audit-sync.d.ts.map +1 -0
- package/dist/audit/audit-sync.js +65 -0
- package/dist/audit/audit-sync.js.map +1 -0
- package/dist/auth/user-authenticator.d.ts +51 -0
- package/dist/auth/user-authenticator.d.ts.map +1 -0
- package/dist/auth/user-authenticator.js +155 -0
- package/dist/auth/user-authenticator.js.map +1 -0
- package/dist/bootstrap/sdk-precheck.d.ts +9 -0
- package/dist/bootstrap/sdk-precheck.d.ts.map +1 -0
- package/dist/bootstrap/sdk-precheck.js +103 -0
- package/dist/bootstrap/sdk-precheck.js.map +1 -0
- package/dist/cli/claude-config-path.d.ts +17 -0
- package/dist/cli/claude-config-path.d.ts.map +1 -0
- package/dist/cli/claude-config-path.js +59 -0
- package/dist/cli/claude-config-path.js.map +1 -0
- package/dist/cli/cli-db.d.ts +12 -0
- package/dist/cli/cli-db.d.ts.map +1 -0
- package/dist/cli/cli-db.js +20 -0
- package/dist/cli/cli-db.js.map +1 -0
- package/dist/cli/cli-utils.d.ts +14 -0
- package/dist/cli/cli-utils.d.ts.map +1 -0
- package/dist/cli/cli-utils.js +57 -0
- package/dist/cli/cli-utils.js.map +1 -0
- package/dist/cli/daemon-utils.d.ts +30 -0
- package/dist/cli/daemon-utils.d.ts.map +1 -0
- package/dist/cli/daemon-utils.js +131 -0
- package/dist/cli/daemon-utils.js.map +1 -0
- package/dist/cli/daemon.d.ts +13 -0
- package/dist/cli/daemon.d.ts.map +1 -0
- package/dist/cli/daemon.js +207 -0
- package/dist/cli/daemon.js.map +1 -0
- package/dist/cli/doctor.d.ts +6 -0
- package/dist/cli/doctor.d.ts.map +1 -0
- package/dist/cli/doctor.js +136 -0
- package/dist/cli/doctor.js.map +1 -0
- package/dist/cli/env-delete.d.ts +6 -0
- package/dist/cli/env-delete.d.ts.map +1 -0
- package/dist/cli/env-delete.js +80 -0
- package/dist/cli/env-delete.js.map +1 -0
- package/dist/cli/env-list.d.ts +5 -0
- package/dist/cli/env-list.d.ts.map +1 -0
- package/dist/cli/env-list.js +42 -0
- package/dist/cli/env-list.js.map +1 -0
- package/dist/cli/env-post-integration.d.ts +21 -0
- package/dist/cli/env-post-integration.d.ts.map +1 -0
- package/dist/cli/env-post-integration.js +300 -0
- package/dist/cli/env-post-integration.js.map +1 -0
- package/dist/cli/env-restore.d.ts +15 -0
- package/dist/cli/env-restore.d.ts.map +1 -0
- package/dist/cli/env-restore.js +130 -0
- package/dist/cli/env-restore.js.map +1 -0
- package/dist/cli/env.d.ts +14 -0
- package/dist/cli/env.d.ts.map +1 -0
- package/dist/cli/env.js +182 -0
- package/dist/cli/env.js.map +1 -0
- package/dist/cli/error-handlers.d.ts +13 -0
- package/dist/cli/error-handlers.d.ts.map +1 -0
- package/dist/cli/error-handlers.js +32 -0
- package/dist/cli/error-handlers.js.map +1 -0
- package/dist/cli/hook-check-env.d.ts +12 -0
- package/dist/cli/hook-check-env.d.ts.map +1 -0
- package/dist/cli/hook-check-env.js +117 -0
- package/dist/cli/hook-check-env.js.map +1 -0
- package/dist/cli/hook-session-project.d.ts +10 -0
- package/dist/cli/hook-session-project.d.ts.map +1 -0
- package/dist/cli/hook-session-project.js +206 -0
- package/dist/cli/hook-session-project.js.map +1 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +361 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/init-guard.d.ts +13 -0
- package/dist/cli/init-guard.d.ts.map +1 -0
- package/dist/cli/init-guard.js +62 -0
- package/dist/cli/init-guard.js.map +1 -0
- package/dist/cli/init.d.ts +19 -0
- package/dist/cli/init.d.ts.map +1 -0
- package/dist/cli/init.js +440 -0
- package/dist/cli/init.js.map +1 -0
- package/dist/cli/install.d.ts +14 -0
- package/dist/cli/install.d.ts.map +1 -0
- package/dist/cli/install.js +183 -0
- package/dist/cli/install.js.map +1 -0
- package/dist/cli/login.d.ts +6 -0
- package/dist/cli/login.d.ts.map +1 -0
- package/dist/cli/login.js +76 -0
- package/dist/cli/login.js.map +1 -0
- package/dist/cli/logs.d.ts +32 -0
- package/dist/cli/logs.d.ts.map +1 -0
- package/dist/cli/logs.js +147 -0
- package/dist/cli/logs.js.map +1 -0
- package/dist/cli/otel-headers.d.ts +12 -0
- package/dist/cli/otel-headers.d.ts.map +1 -0
- package/dist/cli/otel-headers.js +38 -0
- package/dist/cli/otel-headers.js.map +1 -0
- package/dist/cli/project.d.ts +8 -0
- package/dist/cli/project.d.ts.map +1 -0
- package/dist/cli/project.js +102 -0
- package/dist/cli/project.js.map +1 -0
- package/dist/cli/reset.d.ts +8 -0
- package/dist/cli/reset.d.ts.map +1 -0
- package/dist/cli/reset.js +137 -0
- package/dist/cli/reset.js.map +1 -0
- package/dist/cli/run.d.ts +22 -0
- package/dist/cli/run.d.ts.map +1 -0
- package/dist/cli/run.js +103 -0
- package/dist/cli/run.js.map +1 -0
- package/dist/cli/start.d.ts +2 -0
- package/dist/cli/start.d.ts.map +1 -0
- package/dist/cli/start.js +29 -0
- package/dist/cli/start.js.map +1 -0
- package/dist/cli/status.d.ts +12 -0
- package/dist/cli/status.d.ts.map +1 -0
- package/dist/cli/status.js +131 -0
- package/dist/cli/status.js.map +1 -0
- package/dist/cli/telemetry-setup.d.ts +27 -0
- package/dist/cli/telemetry-setup.d.ts.map +1 -0
- package/dist/cli/telemetry-setup.js +157 -0
- package/dist/cli/telemetry-setup.js.map +1 -0
- package/dist/cli/uninstall.d.ts +8 -0
- package/dist/cli/uninstall.d.ts.map +1 -0
- package/dist/cli/uninstall.js +110 -0
- package/dist/cli/uninstall.js.map +1 -0
- package/dist/cli/version.d.ts +2 -0
- package/dist/cli/version.d.ts.map +1 -0
- package/dist/cli/version.js +10 -0
- package/dist/cli/version.js.map +1 -0
- package/dist/config/config.d.ts +10 -0
- package/dist/config/config.d.ts.map +1 -0
- package/dist/config/config.js +64 -0
- package/dist/config/config.js.map +1 -0
- package/dist/config/constants.d.ts +11 -0
- package/dist/config/constants.d.ts.map +1 -0
- package/dist/config/constants.js +14 -0
- package/dist/config/constants.js.map +1 -0
- package/dist/config/paths.d.ts +9 -0
- package/dist/config/paths.d.ts.map +1 -0
- package/dist/config/paths.js +58 -0
- package/dist/config/paths.js.map +1 -0
- package/dist/config/version.d.ts +3 -0
- package/dist/config/version.d.ts.map +1 -0
- package/dist/config/version.js +80 -0
- package/dist/config/version.js.map +1 -0
- package/dist/core/execution-engine.d.ts +289 -0
- package/dist/core/execution-engine.d.ts.map +1 -0
- package/dist/core/execution-engine.js +1931 -0
- package/dist/core/execution-engine.js.map +1 -0
- package/dist/core/runtime.d.ts +43 -0
- package/dist/core/runtime.d.ts.map +1 -0
- package/dist/core/runtime.js +147 -0
- package/dist/core/runtime.js.map +1 -0
- package/dist/core/sync-scheduler.d.ts +42 -0
- package/dist/core/sync-scheduler.d.ts.map +1 -0
- package/dist/core/sync-scheduler.js +131 -0
- package/dist/core/sync-scheduler.js.map +1 -0
- package/dist/core/types.d.ts +106 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +7 -0
- package/dist/core/types.js.map +1 -0
- package/dist/daemon/service-manager.d.ts +68 -0
- package/dist/daemon/service-manager.d.ts.map +1 -0
- package/dist/daemon/service-manager.js +303 -0
- package/dist/daemon/service-manager.js.map +1 -0
- package/dist/env/env-classifier.d.ts +14 -0
- package/dist/env/env-classifier.d.ts.map +1 -0
- package/dist/env/env-classifier.js +94 -0
- package/dist/env/env-classifier.js.map +1 -0
- package/dist/env/env-parser.d.ts +13 -0
- package/dist/env/env-parser.d.ts.map +1 -0
- package/dist/env/env-parser.js +33 -0
- package/dist/env/env-parser.js.map +1 -0
- package/dist/env/env-profile-store.d.ts +15 -0
- package/dist/env/env-profile-store.d.ts.map +1 -0
- package/dist/env/env-profile-store.js +35 -0
- package/dist/env/env-profile-store.js.map +1 -0
- package/dist/env/env-reference.d.ts +10 -0
- package/dist/env/env-reference.d.ts.map +1 -0
- package/dist/env/env-reference.js +33 -0
- package/dist/env/env-reference.js.map +1 -0
- package/dist/env/env-resolver.d.ts +18 -0
- package/dist/env/env-resolver.d.ts.map +1 -0
- package/dist/env/env-resolver.js +48 -0
- package/dist/env/env-resolver.js.map +1 -0
- package/dist/env/fs-utils.d.ts +9 -0
- package/dist/env/fs-utils.d.ts.map +1 -0
- package/dist/env/fs-utils.js +59 -0
- package/dist/env/fs-utils.js.map +1 -0
- package/dist/env/secret-backend.d.ts +15 -0
- package/dist/env/secret-backend.d.ts.map +1 -0
- package/dist/env/secret-backend.js +24 -0
- package/dist/env/secret-backend.js.map +1 -0
- package/dist/executor/executor-registry.d.ts +22 -0
- package/dist/executor/executor-registry.d.ts.map +1 -0
- package/dist/executor/executor-registry.js +42 -0
- package/dist/executor/executor-registry.js.map +1 -0
- package/dist/executor/process-launcher.d.ts +26 -0
- package/dist/executor/process-launcher.d.ts.map +1 -0
- package/dist/executor/process-launcher.js +98 -0
- package/dist/executor/process-launcher.js.map +1 -0
- package/dist/executor/secret-file.d.ts +28 -0
- package/dist/executor/secret-file.d.ts.map +1 -0
- package/dist/executor/secret-file.js +127 -0
- package/dist/executor/secret-file.js.map +1 -0
- package/dist/gateway/auth.d.ts +26 -0
- package/dist/gateway/auth.d.ts.map +1 -0
- package/dist/gateway/auth.js +66 -0
- package/dist/gateway/auth.js.map +1 -0
- package/dist/gateway/gateway-client.d.ts +363 -0
- package/dist/gateway/gateway-client.d.ts.map +1 -0
- package/dist/gateway/gateway-client.js +611 -0
- package/dist/gateway/gateway-client.js.map +1 -0
- package/dist/identity/agent-identity.d.ts +29 -0
- package/dist/identity/agent-identity.d.ts.map +1 -0
- package/dist/identity/agent-identity.js +54 -0
- package/dist/identity/agent-identity.js.map +1 -0
- package/dist/identity/did-manager.d.ts +17 -0
- package/dist/identity/did-manager.d.ts.map +1 -0
- package/dist/identity/did-manager.js +29 -0
- package/dist/identity/did-manager.js.map +1 -0
- package/dist/identity/key-manager.d.ts +21 -0
- package/dist/identity/key-manager.d.ts.map +1 -0
- package/dist/identity/key-manager.js +126 -0
- package/dist/identity/key-manager.js.map +1 -0
- package/dist/identity/session-key.d.ts +13 -0
- package/dist/identity/session-key.d.ts.map +1 -0
- package/dist/identity/session-key.js +17 -0
- package/dist/identity/session-key.js.map +1 -0
- package/dist/policy/policy-evaluator.d.ts +63 -0
- package/dist/policy/policy-evaluator.d.ts.map +1 -0
- package/dist/policy/policy-evaluator.js +266 -0
- package/dist/policy/policy-evaluator.js.map +1 -0
- package/dist/policy/policy-loader.d.ts +10 -0
- package/dist/policy/policy-loader.d.ts.map +1 -0
- package/dist/policy/policy-loader.js +71 -0
- package/dist/policy/policy-loader.js.map +1 -0
- package/dist/policy/types.d.ts +21 -0
- package/dist/policy/types.d.ts.map +1 -0
- package/dist/policy/types.js +3 -0
- package/dist/policy/types.js.map +1 -0
- package/dist/telemetry/claude-settings.d.ts +67 -0
- package/dist/telemetry/claude-settings.d.ts.map +1 -0
- package/dist/telemetry/claude-settings.js +191 -0
- package/dist/telemetry/claude-settings.js.map +1 -0
- package/dist/telemetry/otel-headers.d.ts +27 -0
- package/dist/telemetry/otel-headers.d.ts.map +1 -0
- package/dist/telemetry/otel-headers.js +33 -0
- package/dist/telemetry/otel-headers.js.map +1 -0
- package/dist/telemetry/project-key.d.ts +12 -0
- package/dist/telemetry/project-key.d.ts.map +1 -0
- package/dist/telemetry/project-key.js +113 -0
- package/dist/telemetry/project-key.js.map +1 -0
- package/dist/utils/credential-errors.d.ts +73 -0
- package/dist/utils/credential-errors.d.ts.map +1 -0
- package/dist/utils/credential-errors.js +90 -0
- package/dist/utils/credential-errors.js.map +1 -0
- package/dist/utils/resource-canonicalizer.d.ts +19 -0
- package/dist/utils/resource-canonicalizer.d.ts.map +1 -0
- package/dist/utils/resource-canonicalizer.js +100 -0
- package/dist/utils/resource-canonicalizer.js.map +1 -0
- package/dist/utils/vc-utils.d.ts +23 -0
- package/dist/utils/vc-utils.d.ts.map +1 -0
- package/dist/utils/vc-utils.js +53 -0
- package/dist/utils/vc-utils.js.map +1 -0
- package/dist/wallet/sqlite.d.ts +4 -0
- package/dist/wallet/sqlite.d.ts.map +1 -0
- package/dist/wallet/sqlite.js +158 -0
- package/dist/wallet/sqlite.js.map +1 -0
- package/dist/wallet/vp-builder.d.ts +26 -0
- package/dist/wallet/vp-builder.d.ts.map +1 -0
- package/dist/wallet/vp-builder.js +55 -0
- package/dist/wallet/vp-builder.js.map +1 -0
- package/dist/wallet/wallet.d.ts +64 -0
- package/dist/wallet/wallet.d.ts.map +1 -0
- package/dist/wallet/wallet.js +179 -0
- package/dist/wallet/wallet.js.map +1 -0
- package/package.json +71 -0
- package/required-sdk-symbols.json +15 -0
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
import { PolicyEvaluator } from '../policy/policy-evaluator';
|
|
2
|
+
import { Wallet } from '../wallet/wallet';
|
|
3
|
+
import { VPBuilder } from '../wallet/vp-builder';
|
|
4
|
+
import { AuditLogger } from '../audit/audit-logger';
|
|
5
|
+
import { AgentdGatewayClient } from '../gateway/gateway-client';
|
|
6
|
+
import { ApprovalTokenService } from '../approval/approval-token';
|
|
7
|
+
import { ExecuteRequest, ExecuteResult, ListToolsResult, ExecutionContext } from './types';
|
|
8
|
+
import { SecretBackend } from '../env/secret-backend';
|
|
9
|
+
export declare class ExecutionEngine {
|
|
10
|
+
private readonly policyEvaluator;
|
|
11
|
+
private readonly wallet;
|
|
12
|
+
private readonly vpBuilder;
|
|
13
|
+
private readonly auditLogger;
|
|
14
|
+
private readonly gatewayClient;
|
|
15
|
+
private readonly context;
|
|
16
|
+
private readonly tokenService;
|
|
17
|
+
private readonly secretBackend?;
|
|
18
|
+
private lastPolicySyncTime;
|
|
19
|
+
private clientInfo?;
|
|
20
|
+
private agentRegistered;
|
|
21
|
+
/**
|
|
22
|
+
* Wall-clock timestamp (ms) of the most recent registerAgent attempt, used
|
|
23
|
+
* to throttle retries during a sustained outage so we don't hammer the API
|
|
24
|
+
* with one POST per tool call. See REGISTRATION_RETRY_COOLDOWN_MS.
|
|
25
|
+
*/
|
|
26
|
+
private lastRegistrationAttemptAt;
|
|
27
|
+
/**
|
|
28
|
+
* In-flight registerAgent promise, exposed via `registrationInFlight` for
|
|
29
|
+
* deterministic test waits. `null` when no fetch is pending. Tests await
|
|
30
|
+
* this to flush the fire-and-forget catch handler without resorting to
|
|
31
|
+
* arbitrary setTimeout sleeps that race the microtask queue.
|
|
32
|
+
*/
|
|
33
|
+
private inFlightRegistration;
|
|
34
|
+
private recentOOBRequests;
|
|
35
|
+
private static readonly OOB_COOLDOWN_MS;
|
|
36
|
+
private static readonly OOB_MAP_MAX_SIZE;
|
|
37
|
+
/**
|
|
38
|
+
* Minimum interval between registerAgent attempts when the flag is unset
|
|
39
|
+
* (i.e., the previous attempt failed non-409). 5s is large enough to avoid
|
|
40
|
+
* a request storm against `POST /v1/agents/create` during a sustained
|
|
41
|
+
* outage (ALB rolling, DB connection storm), and small enough that a
|
|
42
|
+
* recovered API picks the agent back up within a couple of tool calls.
|
|
43
|
+
*/
|
|
44
|
+
private static readonly REGISTRATION_RETRY_COOLDOWN_MS;
|
|
45
|
+
constructor(policyEvaluator: PolicyEvaluator, wallet: Wallet, vpBuilder: VPBuilder, auditLogger: AuditLogger | null, gatewayClient: AgentdGatewayClient, context: ExecutionContext, tokenService: ApprovalTokenService, secretBackend?: SecretBackend | undefined);
|
|
46
|
+
/**
|
|
47
|
+
* Record a successful policy sync timestamp (called by SyncScheduler).
|
|
48
|
+
*/
|
|
49
|
+
setLastPolicySyncTime(time: number): void;
|
|
50
|
+
/**
|
|
51
|
+
* Set MCP client info (from oninitialized callback).
|
|
52
|
+
* Used to derive a meaningful agent name for deferred registration.
|
|
53
|
+
*/
|
|
54
|
+
setClientInfo(info: {
|
|
55
|
+
name: string;
|
|
56
|
+
version: string;
|
|
57
|
+
}): void;
|
|
58
|
+
/**
|
|
59
|
+
* Ensure the agent is registered in the API.
|
|
60
|
+
* Called lazily on first tool execution (fire-and-forget).
|
|
61
|
+
* Uses clientInfo from MCP initialize handshake if available.
|
|
62
|
+
*
|
|
63
|
+
* Retry semantics (audit fix for audit_events vs /agents divergence):
|
|
64
|
+
* - Optimistic flag: mark `agentRegistered = true` BEFORE the fetch so
|
|
65
|
+
* concurrent `execute()` calls don't all fire duplicate registrations.
|
|
66
|
+
* - On 409 (GatewayHttpError with status 409): leave the flag true — the
|
|
67
|
+
* agent row already exists in the DB. We type-check via the typed
|
|
68
|
+
* `GatewayHttpError.status` field rather than substring-matching the
|
|
69
|
+
* message, so a future change to the error wording can't accidentally
|
|
70
|
+
* reclassify "already exists" 409s as 5xx-style retries (or vice versa).
|
|
71
|
+
* A string-match fallback (`'409' / 'already exists' / 'duplicate'`)
|
|
72
|
+
* remains for older/non-typed Error instances thrown from other layers
|
|
73
|
+
* (e.g. middleware / network helpers that haven't been converted).
|
|
74
|
+
* - On any other failure (5xx, network, etc.): reset the flag to false so
|
|
75
|
+
* the next `execute()` retries — subject to the retry cool-down below.
|
|
76
|
+
* - Cool-down: at most one POST every REGISTRATION_RETRY_COOLDOWN_MS while
|
|
77
|
+
* the flag stays false. Without this, a sustained 5xx (e.g. ALB rolling,
|
|
78
|
+
* DB connection storm) would result in one POST per tool call.
|
|
79
|
+
* - Retry horizon: there is intentionally NO upper bound on the number of
|
|
80
|
+
* cool-down cycles. agentd is a long-lived daemon, so for a sustained
|
|
81
|
+
* outage we want it to keep retrying (once per cool-down) and self-heal
|
|
82
|
+
* the moment the gateway recovers — a hard cap would permanently brick
|
|
83
|
+
* registration after N failures, which is strictly worse. Tool execution
|
|
84
|
+
* itself does not block on registration (it is fire-and-forget), so an
|
|
85
|
+
* unregistered agent degrades gracefully rather than deadlocking.
|
|
86
|
+
* - No stuck-flag deadlock: `inFlightRegistration` is reset to `null` in
|
|
87
|
+
* the `.finally()` below on EVERY settle (success, 409, or 5xx), so the
|
|
88
|
+
* `agentRegistered=false` + in-flight-guard combination can never wedge
|
|
89
|
+
* permanently — the next post-cool-down `execute()` always re-attempts.
|
|
90
|
+
*/
|
|
91
|
+
private ensureAgentRegistered;
|
|
92
|
+
/**
|
|
93
|
+
* Test-only accessor for the in-flight registerAgent promise.
|
|
94
|
+
*
|
|
95
|
+
* Awaiting this yields a deterministic wait for the fire-and-forget
|
|
96
|
+
* `.catch()` handler to finish updating internal state (the
|
|
97
|
+
* `agentRegistered` flag and the cool-down timestamp). Tests use this in
|
|
98
|
+
* place of arbitrary `setTimeout` sleeps, which would race the microtask
|
|
99
|
+
* queue and flake under load.
|
|
100
|
+
*
|
|
101
|
+
* Returns `null` when no registration is in flight.
|
|
102
|
+
*/
|
|
103
|
+
get registrationInFlight(): Promise<void> | null;
|
|
104
|
+
/**
|
|
105
|
+
* Execute an action request.
|
|
106
|
+
* This is the single entry point for all adapters (MCP, future IDE, SDK).
|
|
107
|
+
*/
|
|
108
|
+
execute(request: ExecuteRequest): Promise<ExecuteResult>;
|
|
109
|
+
/**
|
|
110
|
+
* Ensure a valid VC exists for the requested action.
|
|
111
|
+
* Follows the 4-step acquisition flow from spec §6.1:
|
|
112
|
+
*
|
|
113
|
+
* Step 1: Check wallet for valid VC (verify revocation via Gateway using VC jti)
|
|
114
|
+
* Step 2: Check Gateway for approved requests
|
|
115
|
+
* Step 3: Try auto-issue via Gateway
|
|
116
|
+
* Step 4: Terminal approval prompt -> quick-approve via Gateway
|
|
117
|
+
*
|
|
118
|
+
* @param approvalContext — Cedar 一元化 Step 3.5 retry path. When the agent
|
|
119
|
+
* re-invokes ensureVC after the user clicked 承認 in the approval UI, the
|
|
120
|
+
* caller threads the ledger token + approval outcome ids here so Step 3's
|
|
121
|
+
* `autoIssueVC` call carries them to the API. The API consumes the
|
|
122
|
+
* single-use token and injects `context.approval.granted = true` into
|
|
123
|
+
* Cedar evaluation, flipping the prior `auth_required` to `permit`.
|
|
124
|
+
*/
|
|
125
|
+
private ensureVC;
|
|
126
|
+
/**
|
|
127
|
+
* True when an error is a Cedar forbid 403 (policy_forbidden) from the gateway.
|
|
128
|
+
*
|
|
129
|
+
* Primary path: `gatewayClient.autoIssueVC` throws `GatewayHttpError` on any
|
|
130
|
+
* non-ok, carrying the 403 status + body — that's the branch that fires today.
|
|
131
|
+
* The plain-`Error` message fallback is intentionally retained (not dead): it
|
|
132
|
+
* is cheap defensive coverage for a future caller that surfaces the forbid as
|
|
133
|
+
* a wrapped/plain Error, and keeps parity with remote-mcp's message-only
|
|
134
|
+
* `isPolicyForbiddenError`. The `policy_forbidden` token is snake_case and
|
|
135
|
+
* unlikely to collide with unrelated error prose.
|
|
136
|
+
*/
|
|
137
|
+
private isPolicyForbiddenError;
|
|
138
|
+
private policyForbiddenReason;
|
|
139
|
+
private executeLocal;
|
|
140
|
+
/**
|
|
141
|
+
* Execute locally with an already-acquired VC (skips ensureVC).
|
|
142
|
+
* Used by both the normal path (after ensureVC) and handleApprovalResponse (after quickApprove).
|
|
143
|
+
*/
|
|
144
|
+
private executeLocalWithVC;
|
|
145
|
+
/**
|
|
146
|
+
* Execute locally when Gateway is unreachable.
|
|
147
|
+
* All 4 conditions from spec §7.6 must be true:
|
|
148
|
+
* 1. Valid cached VC exists
|
|
149
|
+
* 2. VC not expired
|
|
150
|
+
* 3. Synced org policy not stale (30 min TTL)
|
|
151
|
+
* 4. Local policy does not deny
|
|
152
|
+
*/
|
|
153
|
+
private executeLocalOffline;
|
|
154
|
+
private executeViaGateway;
|
|
155
|
+
private executeViaGatewayWithVC;
|
|
156
|
+
/**
|
|
157
|
+
* Handle a re-invocation with pendingRequestId (OOB approval polling).
|
|
158
|
+
*/
|
|
159
|
+
private handlePendingApproval;
|
|
160
|
+
/**
|
|
161
|
+
* Create an OOB (out-of-band) approval request.
|
|
162
|
+
* Returns a URL for the user to approve in their browser.
|
|
163
|
+
*
|
|
164
|
+
* Called in two contexts:
|
|
165
|
+
* - ensureVC Step 4: for high/critical risk actions that require browser approval.
|
|
166
|
+
* - tryOOBFallbackAfterRetryExhaustion: for ANY risk level when a VC expires
|
|
167
|
+
* mid-execution and retry is exhausted. In this case OOB is used as a fallback
|
|
168
|
+
* because the normal in-band flow cannot recover an expired credential — the
|
|
169
|
+
* user must re-authorize via browser regardless of risk level.
|
|
170
|
+
*/
|
|
171
|
+
private createOOBApprovalRequest;
|
|
172
|
+
/**
|
|
173
|
+
* Revoke the stale credential and attempt to create an OOB approval request
|
|
174
|
+
* as a fallback after retry exhaustion. Returns an ExecuteResult with
|
|
175
|
+
* waitingForApproval on success, or null if OOB creation fails (caller falls
|
|
176
|
+
* through to the original error).
|
|
177
|
+
*/
|
|
178
|
+
private tryOOBFallbackAfterRetryExhaustion;
|
|
179
|
+
/**
|
|
180
|
+
* Create an in-band approval response for low/medium risk actions.
|
|
181
|
+
* Generates an approval token for the MCP client to present back.
|
|
182
|
+
*/
|
|
183
|
+
private createInBandApprovalResponse;
|
|
184
|
+
/**
|
|
185
|
+
* Pre-request permissions for multiple actions (batch).
|
|
186
|
+
* Triggers VC acquisition for each action without executing.
|
|
187
|
+
* This allows the user to approve multiple actions at once.
|
|
188
|
+
*/
|
|
189
|
+
requestPermissions(actions: string[]): Promise<ExecuteResult>;
|
|
190
|
+
listAvailableTools(): Promise<ListToolsResult>;
|
|
191
|
+
/**
|
|
192
|
+
* Resolve env vars for os.process.run from .env file.
|
|
193
|
+
* Returns empty record if no env_profile specified or .env not found.
|
|
194
|
+
*/
|
|
195
|
+
private resolveProcessEnv;
|
|
196
|
+
private getActionRiskLevel;
|
|
197
|
+
private getDefaultVCTTL;
|
|
198
|
+
private handleApprovalResponse;
|
|
199
|
+
private getResourceType;
|
|
200
|
+
/**
|
|
201
|
+
* Extract specific resource ID from action input using ACTION_REGISTRY target_bindings.
|
|
202
|
+
* For gateway (SaaS) actions, the resource ID (e.g., channel ID) is in the input parameters.
|
|
203
|
+
* Returns undefined for actions without param-sourced bindings or when the param is absent
|
|
204
|
+
* (e.g., target_bindings with required: false).
|
|
205
|
+
*/
|
|
206
|
+
private extractResourceIdFromInput;
|
|
207
|
+
/**
|
|
208
|
+
* #1009 — this OOB re-invocation check is agentd's own defense-in-depth
|
|
209
|
+
* resource re-validation, separate from Gate-2's Cedar resolver in
|
|
210
|
+
* packages/api. #893 taught Gate-2's JiraResourceResolver that a
|
|
211
|
+
* project-scoped grant (e.g. "AIDENTITY") legitimately covers an
|
|
212
|
+
* issue-scoped request (e.g. "AIDENTITY-127"), but that fix never touched
|
|
213
|
+
* this agentd-side check, which stayed a plain string comparison. A grant
|
|
214
|
+
* that Gate-2 correctly approved would then be rejected here on re-invoke,
|
|
215
|
+
* permanently: the approval never resolves. Mirror the same hierarchy
|
|
216
|
+
* check so both enforcement paths agree.
|
|
217
|
+
*
|
|
218
|
+
* TODO(provider-generic): this is Jira-only by construction —
|
|
219
|
+
* `extractProjectKey` parses the Jira `KEY-123` shape, and the sole caller
|
|
220
|
+
* gates on `r.provider === 'jira'` (~:1216). packages/api expresses the same
|
|
221
|
+
* idea through `ResourceResolverRegistry` + `supportsHierarchicalMatch()`,
|
|
222
|
+
* so a second provider that needs hierarchy (e.g. GitHub org → repo) would
|
|
223
|
+
* have to be added in BOTH places, in two different shapes.
|
|
224
|
+
*
|
|
225
|
+
* Deliberately not abstracted yet: agentd is a local daemon that does not
|
|
226
|
+
* share the API's DI container or resolver registry, so mirroring that
|
|
227
|
+
* abstraction here means either duplicating the registry or extracting it
|
|
228
|
+
* into the SDK — real work that one provider does not justify. Jira is
|
|
229
|
+
* currently the only registered hierarchical resolver.
|
|
230
|
+
*
|
|
231
|
+
* When a second one appears, extract the resolver interface into the SDK
|
|
232
|
+
* (alongside `extractProjectKey`, which already lives there) and have both
|
|
233
|
+
* enforcement paths consume it, rather than adding a second `provider ===`
|
|
234
|
+
* branch here. 🪤 The hazard this guards against is silent divergence: if
|
|
235
|
+
* the two paths disagree about what a grant covers, Gate-2 approves and
|
|
236
|
+
* agentd rejects on re-invoke, and the approval never resolves — exactly
|
|
237
|
+
* the #1009 bug this method was written to fix.
|
|
238
|
+
*/
|
|
239
|
+
private resourceIdHierarchicallyMatches;
|
|
240
|
+
/**
|
|
241
|
+
* The single predicate deciding "does this approval cover this resource?".
|
|
242
|
+
*
|
|
243
|
+
* 🔴 Extracted because the check exists at TWO call sites — the pre-claim
|
|
244
|
+
* check (~:1213, over `request.input`) and the post-claim re-validation
|
|
245
|
+
* (~:1310, over the stored `actionParams`). They were byte-identical copies,
|
|
246
|
+
* and the live 2026-07-30 calendar bug hit BOTH: fixing only one produced a
|
|
247
|
+
* test that still failed, from the other site's near-identical message.
|
|
248
|
+
* Two independent copies of one security decision is how they silently drift
|
|
249
|
+
* (#1232 is the same lesson for terminal-status sets living in 3 places).
|
|
250
|
+
*/
|
|
251
|
+
private approvedResourceMatches;
|
|
252
|
+
/**
|
|
253
|
+
* `primary` is Google Calendar's alias for the token owner's OWN calendar,
|
|
254
|
+
* so `primary` and that owner's calendar address name one resource. The
|
|
255
|
+
* approval surfaces deliberately substitute the address for the alias —
|
|
256
|
+
* `public/js/pages/approve.js:514-521` and
|
|
257
|
+
* `slack-approve.service.ts:224-238` both do it, because asking a human to
|
|
258
|
+
* approve a write to "primary" tells them nothing about which calendar.
|
|
259
|
+
*
|
|
260
|
+
* But nothing rewrites the request's stored actionParams to match, and
|
|
261
|
+
* `canonicalResourceId` has no notion of the alias (resolving it needs the
|
|
262
|
+
* Google OAuth token, i.e. a DB read that agentd and remote-mcp cannot do —
|
|
263
|
+
* INV-1). So re-invocation compares `"owner@gmail.com"` against `"primary"`,
|
|
264
|
+
* they differ byte-wise, and the approval can NEVER be satisfied. Reported
|
|
265
|
+
* live 2026-07-30: the user approved, retried, and was rejected forever.
|
|
266
|
+
*
|
|
267
|
+
* 🔴 THIS IS NOT A WILDCARD. The alias only matches an id that looks like a
|
|
268
|
+
* calendar ADDRESS, and only in the alias→address direction. A named shared
|
|
269
|
+
* calendar (`team@group.calendar.google.com`) is a different resource and
|
|
270
|
+
* still fails, which is what the third case in
|
|
271
|
+
* `oob-approval-calendar-primary-alias.test.ts` pins — without that bound
|
|
272
|
+
* this check would degrade into "any calendar approval covers any calendar".
|
|
273
|
+
*
|
|
274
|
+
* 🪤 Same failure SHAPE as #1009/#893 (Jira): Gate-2 approves, agentd's plain
|
|
275
|
+
* `===` rejects on re-invoke, and the approval never resolves. That one got
|
|
276
|
+
* `resourceIdHierarchicallyMatches`; this is the alias-equivalence sibling.
|
|
277
|
+
* When a third case appears, extract a resolver interface into the SDK so
|
|
278
|
+
* both enforcement paths consume one definition (see the TODO above) rather
|
|
279
|
+
* than growing a third branch here.
|
|
280
|
+
*/
|
|
281
|
+
private calendarPrimaryAliasMatches;
|
|
282
|
+
private isRecentOOBRequest;
|
|
283
|
+
private trackOOBRequest;
|
|
284
|
+
/** Verify a wallet VC: check revocation via Gateway, handle expiry. Returns the VC if valid, null if invalid. */
|
|
285
|
+
private verifyWalletVC;
|
|
286
|
+
private handleResourceMismatch;
|
|
287
|
+
private logAudit;
|
|
288
|
+
}
|
|
289
|
+
//# sourceMappingURL=execution-engine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execution-engine.d.ts","sourceRoot":"","sources":["../../src/core/execution-engine.ts"],"names":[],"mappings":"AAoBA,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AAC5D,OAAO,EAAE,MAAM,EAAuC,MAAM,kBAAkB,CAAA;AAC9E,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACnD,OAAO,EAA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