@vellumai/assistant 0.10.7-dev.202607092332.9deedf4 → 0.10.7-dev.202607100313.fffdfea
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/ARCHITECTURE.md +1 -2
- package/docs/architecture/memory.md +1 -3
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/package.json +0 -2
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/__tests__/contracts.test.ts +0 -2
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/credential-rpc.ts +3 -5
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/index.ts +2 -4
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/rpc.ts +4 -447
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/package.json +0 -2
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/__tests__/contracts.test.ts +0 -2
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/credential-rpc.ts +3 -5
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/index.ts +2 -4
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/rpc.ts +4 -447
- package/node_modules/@vellumai/service-contracts/package.json +0 -2
- package/node_modules/@vellumai/service-contracts/src/__tests__/contracts.test.ts +0 -2
- package/node_modules/@vellumai/service-contracts/src/credential-rpc.ts +3 -5
- package/node_modules/@vellumai/service-contracts/src/index.ts +2 -4
- package/node_modules/@vellumai/service-contracts/src/rpc.ts +4 -447
- package/openapi.yaml +1 -222
- package/package.json +1 -1
- package/scripts/memory-inspect.ts +2 -8
- package/src/__tests__/approval-routes-http.test.ts +0 -8
- package/src/__tests__/background-workers-disk-pressure.test.ts +4 -2
- package/src/__tests__/compaction-events.test.ts +0 -4
- package/src/__tests__/context-search-memory-source.test.ts +0 -1
- package/src/__tests__/conversation-agent-loop-disk-pressure.test.ts +0 -1
- package/src/__tests__/conversation-agent-loop-inference-profile.test.ts +0 -2
- package/src/__tests__/conversation-agent-loop-overflow.test.ts +0 -2
- package/src/__tests__/conversation-agent-loop.test.ts +0 -4
- package/src/__tests__/conversation-app-control-lifecycle.test.ts +0 -4
- package/src/__tests__/conversation-fork-crud.test.ts +18 -5
- package/src/__tests__/conversation-fork-retrospective.test.ts +483 -0
- package/src/__tests__/conversation-routes-disk-view.test.ts +0 -4
- package/src/__tests__/conversation-store.test.ts +0 -10
- package/src/__tests__/conversation-summarize-up-to.test.ts +0 -4
- package/src/__tests__/credential-execution-api-key-propagation.test.ts +0 -40
- package/src/__tests__/credential-execution-client.test.ts +3 -3
- package/src/__tests__/credential-execution-managed-contract.test.ts +8 -104
- package/src/__tests__/file-write-tool.test.ts +9 -13
- package/src/__tests__/graph-extraction-event-date.test.ts +0 -9
- package/src/__tests__/injection-block.test.ts +0 -1
- package/src/__tests__/job-handler-registration-guard.test.ts +0 -1
- package/src/__tests__/lexical-index-dual-write.test.ts +2 -2
- package/src/__tests__/llm-resolver.test.ts +0 -1
- package/src/__tests__/messages-after-tiebreaker.test.ts +0 -1
- package/src/__tests__/playbook-execution.test.ts +2 -26
- package/src/__tests__/plugin-import-boundary-guard.test.ts +0 -4
- package/src/__tests__/plugin-import-boundary-reverse-guard.test.ts +318 -0
- package/src/__tests__/proxy-approval-callback.test.ts +0 -1
- package/src/__tests__/rebuild-index-graph-nodes.test.ts +0 -4
- package/src/__tests__/send-endpoint-busy.test.ts +0 -12
- package/src/__tests__/service-contracts-import-guard.test.ts +4 -9
- package/src/__tests__/subagent-fork-spawn.test.ts +0 -37
- package/src/__tests__/task-memory-cleanup.test.ts +0 -11
- package/src/__tests__/voice-scoped-grant-consumer.test.ts +0 -1
- package/src/__tests__/voice-session-bridge.test.ts +0 -56
- package/src/__tests__/workspace-migration-009-backfill-conversation-disk-view.test.ts +0 -1
- package/src/__tests__/workspace-migration-013-repair-conversation-disk-view.test.ts +0 -1
- package/src/__tests__/workspace-migration-028-recover-conversations-from-disk-view.test.ts +0 -1
- package/src/__tests__/workspace-migration-129-remove-analyze-conversation-config.test.ts +190 -0
- package/src/cli/commands/db/repair-step-conversation-backfill.ts +0 -1
- package/src/config/bundled-skills/messaging/tools/messaging-analyze-style.ts +0 -6
- package/src/config/bundled-skills/playbooks/tools/playbook-create.ts +0 -3
- package/src/config/bundled-skills/playbooks/tools/playbook-delete.ts +0 -3
- package/src/config/bundled-skills/playbooks/tools/playbook-list.ts +1 -3
- package/src/config/bundled-skills/playbooks/tools/playbook-update.ts +0 -4
- package/src/config/call-site-defaults.ts +0 -1
- package/src/config/feature-flag-registry.json +0 -16
- package/src/config/schema.ts +0 -3
- package/src/config/schemas/call-site-catalog.ts +0 -6
- package/src/config/schemas/llm.ts +0 -1
- package/src/conversations/job-handlers/summarization.ts +0 -2
- package/src/daemon/conversation-agent-loop-handlers.ts +0 -1
- package/src/daemon/conversation-agent-loop.ts +1 -6
- package/src/daemon/conversation-lifecycle.ts +0 -14
- package/src/daemon/conversation-turn-finalize.ts +0 -1
- package/src/daemon/handlers/shared.ts +1 -2
- package/src/export/transcript-formatter.ts +9 -39
- package/src/home/conversation-starter-checkpoints.ts +9 -5
- package/src/home/job-handlers/conversation-starters.ts +24 -54
- package/src/hooks/types.ts +2 -2
- package/src/ipc/routes/__tests__/memory-v2-backfill.test.ts +5 -7
- package/src/persistence/__tests__/bulk-write-gate.test.ts +165 -0
- package/src/persistence/__tests__/immediate-transaction-guard.test.ts +70 -0
- package/src/persistence/auto-analysis-constants.ts +4 -13
- package/src/persistence/bulk-write-gate.ts +82 -0
- package/src/persistence/conversation-bootstrap.ts +3 -3
- package/src/persistence/conversation-crud.ts +158 -80
- package/src/persistence/conversation-key-store.ts +0 -2
- package/src/persistence/conversation-row-batch-delete.ts +16 -1
- package/src/persistence/conversation-types.ts +12 -1
- package/src/persistence/db-async-query.ts +18 -9
- package/src/persistence/db-connection.ts +20 -4
- package/src/persistence/db-maintenance.ts +78 -6
- package/src/persistence/embeddings/qdrant-client.ts +2 -18
- package/src/persistence/fork-message-copy.ts +18 -4
- package/src/persistence/jobs-store.ts +3 -86
- package/src/persistence/migrations/323-delete-non-default-memory-scopes.test.ts +148 -0
- package/src/persistence/migrations/323-delete-non-default-memory-scopes.ts +35 -0
- package/src/persistence/schema/conversations.ts +0 -1
- package/src/persistence/schema/memory-core.ts +17 -28
- package/src/persistence/schema/memory-graph.ts +0 -4
- package/src/persistence/schema/tasks.ts +0 -1
- package/src/persistence/steps.ts +2 -0
- package/src/playbooks/playbook-compiler.ts +2 -10
- package/src/plugins/defaults/memory/__tests__/db-maintenance.test.ts +105 -11
- package/src/plugins/defaults/memory/__tests__/jobs-store-enqueue-gate.test.ts +7 -62
- package/src/plugins/defaults/memory/__tests__/memory-retrospective-job.test.ts +47 -5
- package/src/plugins/defaults/memory/__tests__/memory-retrospective-skill-card.test.ts +29 -1
- package/src/plugins/defaults/memory/__tests__/memory-retrospective-startup-cleanup.test.ts +133 -70
- package/src/plugins/defaults/memory/activation-session-store.ts +1 -1
- package/src/plugins/defaults/memory/config.ts +1 -1
- package/src/plugins/defaults/memory/context-search/sources/conversations.ts +1 -1
- package/src/plugins/defaults/memory/context-search/sources/memory-v2.ts +1 -1
- package/src/plugins/defaults/memory/context-search/sources/memory.ts +1 -1
- package/src/plugins/defaults/memory/filing-jobs.ts +1 -1
- package/src/plugins/defaults/memory/fork-conversation-memory.ts +8 -4
- package/src/plugins/defaults/memory/frontmatter.ts +1 -1
- package/src/plugins/defaults/memory/graph/__tests__/handle-remember-v2.test.ts +4 -25
- package/src/plugins/defaults/memory/graph/bootstrap.ts +12 -18
- package/src/plugins/defaults/memory/graph/capability-seed.ts +4 -18
- package/src/plugins/defaults/memory/graph/consolidation.ts +7 -14
- package/src/plugins/defaults/memory/graph/conversation-graph-memory.ts +1 -3
- package/src/plugins/defaults/memory/graph/decay.ts +5 -10
- package/src/plugins/defaults/memory/graph/extraction-job.ts +2 -3
- package/src/plugins/defaults/memory/graph/extraction.test.ts +1 -9
- package/src/plugins/defaults/memory/graph/extraction.ts +1 -8
- package/src/plugins/defaults/memory/graph/graph-search.ts +1 -2
- package/src/plugins/defaults/memory/graph/injection.test.ts +0 -1
- package/src/plugins/defaults/memory/graph/injection.ts +1 -1
- package/src/plugins/defaults/memory/graph/narrative.ts +1 -3
- package/src/plugins/defaults/memory/graph/pattern-scan.ts +1 -4
- package/src/plugins/defaults/memory/graph/retriever.test.ts +0 -19
- package/src/plugins/defaults/memory/graph/retriever.ts +6 -14
- package/src/plugins/defaults/memory/graph/scoring.test.ts +0 -1
- package/src/plugins/defaults/memory/graph/store.test.ts +6 -58
- package/src/plugins/defaults/memory/graph/store.ts +5 -43
- package/src/plugins/defaults/memory/graph/tool-handlers.test.ts +0 -4
- package/src/plugins/defaults/memory/graph/tool-handlers.ts +1 -11
- package/src/plugins/defaults/memory/graph/types.ts +0 -3
- package/src/plugins/defaults/memory/hooks/init.ts +1 -1
- package/src/plugins/defaults/memory/indexer.ts +2 -45
- package/src/plugins/defaults/memory/injectors.ts +2 -3
- package/src/plugins/defaults/memory/job-handler-registration.ts +0 -4
- package/src/plugins/defaults/memory/job-handlers/backfill.ts +0 -1
- package/src/plugins/defaults/memory/job-handlers/embedding.test.ts +0 -1
- package/src/plugins/defaults/memory/job-handlers/embedding.ts +0 -4
- package/src/plugins/defaults/memory/job-handlers/index-maintenance.ts +1 -1
- package/src/plugins/defaults/memory/job-handlers.ts +5 -9
- package/src/plugins/defaults/memory/jobs/embed-concept-page.ts +1 -1
- package/src/plugins/defaults/memory/jobs/embed-pkb-file.test.ts +41 -21
- package/src/plugins/defaults/memory/jobs/embed-pkb-file.ts +10 -5
- package/src/plugins/defaults/memory/jobs-worker.ts +21 -9
- package/src/plugins/defaults/memory/logging.ts +17 -0
- package/src/plugins/defaults/memory/memory-retrospective-constants.ts +10 -7
- package/src/plugins/defaults/memory/memory-retrospective-enqueue.ts +5 -6
- package/src/plugins/defaults/memory/memory-retrospective-fork-boundary.ts +57 -20
- package/src/plugins/defaults/memory/memory-retrospective-job.ts +13 -15
- package/src/plugins/defaults/memory/memory-retrospective-skill-card.ts +2 -2
- package/src/plugins/defaults/memory/memory-retrospective-startup-cleanup.ts +52 -39
- package/src/plugins/defaults/memory/memory-retrospective-trigger-check.ts +1 -1
- package/src/plugins/defaults/memory/pkb/pkb-index.test.ts +25 -38
- package/src/plugins/defaults/memory/pkb/pkb-index.ts +7 -19
- package/src/plugins/defaults/memory/pkb/pkb-reconcile.test.ts +46 -28
- package/src/plugins/defaults/memory/pkb/pkb-reconcile.ts +4 -9
- package/src/plugins/defaults/memory/pkb/pkb-search.test.ts +3 -9
- package/src/plugins/defaults/memory/pkb/pkb-search.ts +2 -9
- package/src/plugins/defaults/memory/pkb/types.ts +0 -11
- package/src/plugins/defaults/memory/rerank-local.ts +1 -1
- package/src/plugins/defaults/memory/routes/memory-eval-routes.ts +1 -1
- package/src/plugins/defaults/memory/routes/memory-item-routes.test.ts +0 -1
- package/src/plugins/defaults/memory/routes/memory-item-routes.ts +3 -11
- package/src/plugins/defaults/memory/routes/memory-v2-routes.ts +1 -1
- package/src/plugins/defaults/memory/routes/memory-v3-routes.ts +1 -1
- package/src/plugins/defaults/memory/startup.ts +2 -3
- package/src/plugins/defaults/memory/task-memory-cleanup.ts +1 -1
- package/src/plugins/defaults/memory/tools.test.ts +1 -9
- package/src/plugins/defaults/memory/tools.ts +0 -1
- package/src/plugins/defaults/memory/v2/backfill-jobs.ts +1 -1
- package/src/plugins/defaults/memory/v2/cli-command-store.ts +1 -1
- package/src/plugins/defaults/memory/v2/consolidation-job.ts +1 -1
- package/src/plugins/defaults/memory/v2/frontmatter-sweep.ts +1 -1
- package/src/plugins/defaults/memory/v2/injection-events.ts +1 -1
- package/src/plugins/defaults/memory/v2/injection.ts +1 -1
- package/src/plugins/defaults/memory/v2/memory-v2-startup.ts +1 -1
- package/src/plugins/defaults/memory/v2/migration.ts +1 -1
- package/src/plugins/defaults/memory/v2/page-index.ts +1 -1
- package/src/plugins/defaults/memory/v2/prompts/consolidation.ts +1 -1
- package/src/plugins/defaults/memory/v2/prompts/router.ts +1 -1
- package/src/plugins/defaults/memory/v2/qdrant.ts +1 -1
- package/src/plugins/defaults/memory/v2/reranker.ts +1 -1
- package/src/plugins/defaults/memory/v2/router.ts +1 -1
- package/src/plugins/defaults/memory/v2/skill-store.ts +1 -1
- package/src/plugins/defaults/memory/v2/sweep-job.ts +1 -1
- package/src/plugins/defaults/memory/v3/candidate-match.ts +1 -1
- package/src/plugins/defaults/memory/v3/dense.ts +1 -1
- package/src/plugins/defaults/memory/v3/injector.ts +1 -1
- package/src/plugins/defaults/memory/v3/maintain-job.ts +1 -1
- package/src/plugins/defaults/memory/v3/orchestrate.ts +1 -1
- package/src/plugins/defaults/memory/v3/pool-select.ts +1 -1
- package/src/plugins/defaults/memory/v3/prune.ts +1 -1
- package/src/plugins/defaults/memory/v3/section-dense-store.ts +1 -1
- package/src/plugins/defaults/memory/v3/shadow-plugin.ts +1 -1
- package/src/plugins/defaults/memory/worker.ts +1 -1
- package/src/runtime/capabilities.ts +1 -1
- package/src/runtime/routes/__tests__/bookmark-routes.test.ts +0 -1
- package/src/runtime/routes/__tests__/conversation-management-routes.test.ts +0 -1
- package/src/runtime/routes/__tests__/conversation-query-routes.test.ts +0 -1
- package/src/runtime/routes/conversation-starter-routes.ts +12 -23
- package/src/runtime/routes/index.ts +0 -2
- package/src/runtime/services/__tests__/auto-analysis-guard.test.ts +1 -8
- package/src/runtime/services/__tests__/conversation-serializer.test.ts +0 -1
- package/src/runtime/services/auto-analysis-guard.ts +5 -5
- package/src/runtime/services/conversation-serializer.ts +2 -3
- package/src/tasks/SPEC.md +10 -17
- package/src/tools/executor.ts +1 -102
- package/src/tools/filesystem/write.ts +0 -2
- package/src/tools/tool-types.ts +0 -15
- package/src/tools/types.ts +0 -10
- package/src/workspace/migrations/028-recover-conversations-from-disk-view.ts +0 -1
- package/src/workspace/migrations/129-remove-analyze-conversation-config.ts +59 -0
- package/src/workspace/migrations/registry.ts +2 -0
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/__tests__/grants.test.ts +0 -686
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/grants.ts +0 -184
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/rendering.ts +0 -135
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/__tests__/grants.test.ts +0 -686
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/grants.ts +0 -184
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/rendering.ts +0 -135
- package/node_modules/@vellumai/service-contracts/src/__tests__/grants.test.ts +0 -686
- package/node_modules/@vellumai/service-contracts/src/grants.ts +0 -184
- package/node_modules/@vellumai/service-contracts/src/rendering.ts +0 -135
- package/src/__tests__/auto-analysis-end-to-end.test.ts +0 -621
- package/src/__tests__/auto-analysis-prompt.test.ts +0 -50
- package/src/__tests__/config-analysis.test.ts +0 -83
- package/src/__tests__/conversation-analysis-routes.test.ts +0 -156
- package/src/__tests__/credential-execution-approval-bridge.test.ts +0 -297
- package/src/config/schemas/analysis.ts +0 -32
- package/src/credential-execution/approval-bridge.ts +0 -320
- package/src/daemon/__tests__/conversation-lifecycle-auto-analyze.test.ts +0 -449
- package/src/plugins/defaults/memory/__tests__/find-analysis-conversation.test.ts +0 -197
- package/src/runtime/routes/conversation-analysis-routes.ts +0 -75
- package/src/runtime/services/__tests__/analyze-conversation.test.ts +0 -477
- package/src/runtime/services/__tests__/auto-analysis-enqueue.test.ts +0 -386
- package/src/runtime/services/__tests__/auto-analysis-prompt.test.ts +0 -53
- package/src/runtime/services/__tests__/conversation-analyze-job.test.ts +0 -213
- package/src/runtime/services/__tests__/manual-analysis-prompt.test.ts +0 -41
- package/src/runtime/services/analyze-conversation.ts +0 -334
- package/src/runtime/services/auto-analysis-enqueue.ts +0 -130
- package/src/runtime/services/auto-analysis-prompt.ts +0 -55
- package/src/runtime/services/conversation-analyze-job.ts +0 -53
|
@@ -1,320 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CES approval bridge.
|
|
3
|
-
*
|
|
4
|
-
* Translates a CES `approval_required` response into an interactive
|
|
5
|
-
* confirmation prompt using the existing PermissionPrompter transport.
|
|
6
|
-
* When the guardian approves, the bridge commits the decision back to CES
|
|
7
|
-
* via the `record_grant` RPC rather than through local trust rules.
|
|
8
|
-
*
|
|
9
|
-
* Design principles:
|
|
10
|
-
* - The assistant never sees raw secret values. The rendered proposal text
|
|
11
|
-
* comes from CES (generated by `@vellumai/service-contracts` rendering).
|
|
12
|
-
* - Approved decisions are persisted inside CES, not in local trust rules.
|
|
13
|
-
* - After approval the bridge returns a `grantId` so the caller can retry
|
|
14
|
-
* the original tool invocation with the grant attached.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
import type {
|
|
18
|
-
ApprovalRequired,
|
|
19
|
-
RecordGrantResponse,
|
|
20
|
-
} from "@vellumai/service-contracts/credential-rpc";
|
|
21
|
-
|
|
22
|
-
import type { PermissionPrompter } from "../permissions/prompter.js";
|
|
23
|
-
import type { UserDecision } from "../permissions/types.js";
|
|
24
|
-
import { getLogger } from "../util/logger.js";
|
|
25
|
-
import type { CesClient } from "./client.js";
|
|
26
|
-
|
|
27
|
-
const log = getLogger("ces-approval-bridge");
|
|
28
|
-
|
|
29
|
-
// ---------------------------------------------------------------------------
|
|
30
|
-
// Decision mapping
|
|
31
|
-
// ---------------------------------------------------------------------------
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* CES approval decisions that the bridge presents to the guardian.
|
|
35
|
-
*
|
|
36
|
-
* Maps the existing confirmation transport decisions to CES grant semantics:
|
|
37
|
-
* - `allow` -> approved (single-use grant, no TTL)
|
|
38
|
-
* - `deny` -> denied
|
|
39
|
-
*/
|
|
40
|
-
export interface CesApprovalDecision {
|
|
41
|
-
/** The CES grant decision: approved or denied. */
|
|
42
|
-
grantDecision: "approved" | "denied";
|
|
43
|
-
/** ISO-8601 duration for temporary grants. Undefined for single-use or persistent. */
|
|
44
|
-
ttl: string | undefined;
|
|
45
|
-
/** The type of grant to create (controls persistence behaviour in CES). */
|
|
46
|
-
grantType: "allow_once" | undefined;
|
|
47
|
-
/** The original user decision from the confirmation transport. */
|
|
48
|
-
userDecision: UserDecision;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function mapUserDecisionToCesDecision(
|
|
52
|
-
decision: UserDecision,
|
|
53
|
-
): CesApprovalDecision {
|
|
54
|
-
switch (decision) {
|
|
55
|
-
case "allow":
|
|
56
|
-
return {
|
|
57
|
-
grantDecision: "approved",
|
|
58
|
-
ttl: undefined,
|
|
59
|
-
grantType: "allow_once",
|
|
60
|
-
userDecision: decision,
|
|
61
|
-
};
|
|
62
|
-
case "deny":
|
|
63
|
-
return {
|
|
64
|
-
grantDecision: "denied",
|
|
65
|
-
ttl: undefined,
|
|
66
|
-
grantType: undefined,
|
|
67
|
-
userDecision: decision,
|
|
68
|
-
};
|
|
69
|
-
default: {
|
|
70
|
-
// Exhaustiveness guard — treat unknown decisions as denials.
|
|
71
|
-
const _exhaustive: never = decision;
|
|
72
|
-
return {
|
|
73
|
-
grantDecision: "denied",
|
|
74
|
-
ttl: undefined,
|
|
75
|
-
grantType: undefined,
|
|
76
|
-
userDecision: decision,
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// ---------------------------------------------------------------------------
|
|
83
|
-
// Bridge result
|
|
84
|
-
// ---------------------------------------------------------------------------
|
|
85
|
-
|
|
86
|
-
export type CesApprovalBridgeResult =
|
|
87
|
-
| {
|
|
88
|
-
outcome: "approved";
|
|
89
|
-
grantId: string;
|
|
90
|
-
userDecision: UserDecision;
|
|
91
|
-
}
|
|
92
|
-
| {
|
|
93
|
-
outcome: "denied";
|
|
94
|
-
userDecision: UserDecision;
|
|
95
|
-
}
|
|
96
|
-
| {
|
|
97
|
-
outcome: "timeout";
|
|
98
|
-
}
|
|
99
|
-
| {
|
|
100
|
-
outcome: "error";
|
|
101
|
-
message: string;
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
// ---------------------------------------------------------------------------
|
|
105
|
-
// Bridge function
|
|
106
|
-
// ---------------------------------------------------------------------------
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Present a CES approval request to the guardian using the existing
|
|
110
|
-
* confirmation prompt infrastructure, then commit the decision to CES
|
|
111
|
-
* via the `record_grant` RPC.
|
|
112
|
-
*
|
|
113
|
-
* @param approval - The `approval_required` payload from CES.
|
|
114
|
-
* @param prompter - The PermissionPrompter that sends confirmation_request
|
|
115
|
-
* messages to the connected client.
|
|
116
|
-
* @param cesClient - The CES RPC client for committing the grant decision.
|
|
117
|
-
* @param options - Optional configuration for the bridge.
|
|
118
|
-
* @returns The outcome of the approval flow.
|
|
119
|
-
*/
|
|
120
|
-
export async function bridgeCesApproval(
|
|
121
|
-
approval: ApprovalRequired,
|
|
122
|
-
prompter: PermissionPrompter,
|
|
123
|
-
cesClient: CesClient,
|
|
124
|
-
options?: {
|
|
125
|
-
/** Whether an interactive client is connected. When false, auto-deny. */
|
|
126
|
-
isInteractive?: boolean;
|
|
127
|
-
/** Conversation ID for the confirmation prompt. */
|
|
128
|
-
conversationId?: string;
|
|
129
|
-
/** Abort signal for cooperative cancellation. */
|
|
130
|
-
signal?: AbortSignal;
|
|
131
|
-
},
|
|
132
|
-
): Promise<CesApprovalBridgeResult> {
|
|
133
|
-
const { proposal, renderedProposal, proposalHash, sessionId } = approval;
|
|
134
|
-
|
|
135
|
-
// Non-interactive sessions have no client to respond — fail closed.
|
|
136
|
-
if (options?.isInteractive === false) {
|
|
137
|
-
log.info(
|
|
138
|
-
{
|
|
139
|
-
event: "ces_approval_bridge_non_interactive",
|
|
140
|
-
proposalHash,
|
|
141
|
-
sessionId,
|
|
142
|
-
},
|
|
143
|
-
"CES approval request denied: non-interactive session",
|
|
144
|
-
);
|
|
145
|
-
return { outcome: "denied", userDecision: "deny" };
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// Build the tool name and input for the confirmation prompt. The tool
|
|
149
|
-
// name uses a `ces:` prefix so the client can distinguish CES approval
|
|
150
|
-
// requests from regular tool confirmation prompts.
|
|
151
|
-
const toolName = `ces:${proposal.type}`;
|
|
152
|
-
const input: Record<string, unknown> = {
|
|
153
|
-
credentialHandle: proposal.credentialHandle,
|
|
154
|
-
purpose: proposal.purpose,
|
|
155
|
-
renderedProposal,
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
if (proposal.type === "http") {
|
|
159
|
-
input.method = proposal.method;
|
|
160
|
-
input.url = proposal.url;
|
|
161
|
-
} else if (proposal.type === "command") {
|
|
162
|
-
input.command = proposal.command;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
// Present the confirmation prompt to the guardian. The prompter handles
|
|
166
|
-
// timeouts and abort signals internally.
|
|
167
|
-
const response = await prompter.prompt(
|
|
168
|
-
toolName,
|
|
169
|
-
input,
|
|
170
|
-
"high", // CES approval requests are always high-risk
|
|
171
|
-
[], // No allowlist options — CES manages its own grant patterns
|
|
172
|
-
[], // No scope options — CES manages scope internally
|
|
173
|
-
undefined, // No file diff
|
|
174
|
-
options?.conversationId,
|
|
175
|
-
"host", // CES operations target the host
|
|
176
|
-
false, // Persistent decisions are managed by CES, not trust.json
|
|
177
|
-
options?.signal,
|
|
178
|
-
);
|
|
179
|
-
|
|
180
|
-
// Detect prompter timeout: the PermissionPrompter resolves timeouts as
|
|
181
|
-
// decision: "deny" with a decisionContext containing "timed out". Surface
|
|
182
|
-
// this as a distinct outcome so the executor shows a timeout-specific
|
|
183
|
-
// message that encourages retrying rather than implying explicit denial.
|
|
184
|
-
const isTimeout =
|
|
185
|
-
response.decision === "deny" &&
|
|
186
|
-
typeof response.decisionContext === "string" &&
|
|
187
|
-
response.decisionContext.includes("timed out");
|
|
188
|
-
|
|
189
|
-
if (isTimeout) {
|
|
190
|
-
log.info(
|
|
191
|
-
{
|
|
192
|
-
event: "ces_approval_bridge_timeout",
|
|
193
|
-
proposalHash,
|
|
194
|
-
sessionId,
|
|
195
|
-
},
|
|
196
|
-
"CES approval bridge: prompter timed out",
|
|
197
|
-
);
|
|
198
|
-
return { outcome: "timeout" };
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
const cesDecision = mapUserDecisionToCesDecision(response.decision);
|
|
202
|
-
|
|
203
|
-
log.info(
|
|
204
|
-
{
|
|
205
|
-
event: "ces_approval_bridge_decision",
|
|
206
|
-
proposalHash,
|
|
207
|
-
sessionId,
|
|
208
|
-
userDecision: response.decision,
|
|
209
|
-
grantDecision: cesDecision.grantDecision,
|
|
210
|
-
ttl: cesDecision.ttl,
|
|
211
|
-
},
|
|
212
|
-
`CES approval bridge: guardian decision is "${cesDecision.grantDecision}"`,
|
|
213
|
-
);
|
|
214
|
-
|
|
215
|
-
return recordCesGrant({
|
|
216
|
-
approval,
|
|
217
|
-
cesClient,
|
|
218
|
-
decision: cesDecision,
|
|
219
|
-
reason: response.decision === "allow" ? "guardian_approved" : "guardian_denied",
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
async function recordCesGrant({
|
|
224
|
-
approval,
|
|
225
|
-
cesClient,
|
|
226
|
-
decision,
|
|
227
|
-
reason,
|
|
228
|
-
}: {
|
|
229
|
-
approval: ApprovalRequired;
|
|
230
|
-
cesClient: CesClient;
|
|
231
|
-
decision: CesApprovalDecision;
|
|
232
|
-
reason?: string;
|
|
233
|
-
}): Promise<CesApprovalBridgeResult> {
|
|
234
|
-
const { proposal, proposalHash, sessionId, conversationId } = approval;
|
|
235
|
-
|
|
236
|
-
if (decision.grantDecision === "denied") {
|
|
237
|
-
return { outcome: "denied", userDecision: decision.userDecision };
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
// Commit the approved grant to CES via record_grant RPC.
|
|
241
|
-
try {
|
|
242
|
-
const grantResponse: RecordGrantResponse = await cesClient.call(
|
|
243
|
-
"record_grant",
|
|
244
|
-
{
|
|
245
|
-
decision: {
|
|
246
|
-
proposal,
|
|
247
|
-
proposalHash,
|
|
248
|
-
decision: decision.grantDecision,
|
|
249
|
-
decidedBy: "guardian",
|
|
250
|
-
decidedAt: new Date().toISOString(),
|
|
251
|
-
reason,
|
|
252
|
-
ttl: decision.ttl,
|
|
253
|
-
grantType: decision.grantType,
|
|
254
|
-
},
|
|
255
|
-
sessionId,
|
|
256
|
-
conversationId,
|
|
257
|
-
},
|
|
258
|
-
);
|
|
259
|
-
|
|
260
|
-
if (!grantResponse.success) {
|
|
261
|
-
const errorMsg =
|
|
262
|
-
grantResponse.error?.message ?? "Unknown error recording grant";
|
|
263
|
-
log.warn(
|
|
264
|
-
{
|
|
265
|
-
event: "ces_approval_bridge_record_failed",
|
|
266
|
-
proposalHash,
|
|
267
|
-
sessionId,
|
|
268
|
-
error: errorMsg,
|
|
269
|
-
},
|
|
270
|
-
"CES record_grant RPC failed",
|
|
271
|
-
);
|
|
272
|
-
return { outcome: "error", message: errorMsg };
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
const grantId = grantResponse.grant?.grantId;
|
|
276
|
-
if (!grantId) {
|
|
277
|
-
log.warn(
|
|
278
|
-
{
|
|
279
|
-
event: "ces_approval_bridge_no_grant_id",
|
|
280
|
-
proposalHash,
|
|
281
|
-
sessionId,
|
|
282
|
-
},
|
|
283
|
-
"CES record_grant succeeded but returned no grantId",
|
|
284
|
-
);
|
|
285
|
-
return {
|
|
286
|
-
outcome: "error",
|
|
287
|
-
message: "Grant recorded but no grantId returned",
|
|
288
|
-
};
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
log.info(
|
|
292
|
-
{
|
|
293
|
-
event: "ces_approval_bridge_granted",
|
|
294
|
-
proposalHash,
|
|
295
|
-
sessionId,
|
|
296
|
-
grantId,
|
|
297
|
-
userDecision: decision.userDecision,
|
|
298
|
-
},
|
|
299
|
-
"CES approval bridge: grant recorded successfully",
|
|
300
|
-
);
|
|
301
|
-
|
|
302
|
-
return {
|
|
303
|
-
outcome: "approved",
|
|
304
|
-
grantId,
|
|
305
|
-
userDecision: decision.userDecision,
|
|
306
|
-
};
|
|
307
|
-
} catch (err) {
|
|
308
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
309
|
-
log.warn(
|
|
310
|
-
{
|
|
311
|
-
event: "ces_approval_bridge_rpc_error",
|
|
312
|
-
proposalHash,
|
|
313
|
-
sessionId,
|
|
314
|
-
error: msg,
|
|
315
|
-
},
|
|
316
|
-
"CES record_grant RPC call failed",
|
|
317
|
-
);
|
|
318
|
-
return { outcome: "error", message: msg };
|
|
319
|
-
}
|
|
320
|
-
}
|