@vellumai/assistant 0.8.9 → 0.8.10-dev.202606092238.d04fd59

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.
Files changed (147) hide show
  1. package/AGENTS.md +1 -1
  2. package/examples/plugins/echo/README.md +3 -3
  3. package/node_modules/@vellumai/skill-host-contracts/src/tool-types.ts +2 -0
  4. package/openapi.yaml +38 -12
  5. package/package.json +1 -1
  6. package/scripts/sync-llm-catalog.ts +2 -0
  7. package/src/__tests__/agent-loop-exit-reason.test.ts +19 -14
  8. package/src/__tests__/build-persisted-content.test.ts +75 -1
  9. package/src/__tests__/config-managed-gemini-defaults.test.ts +2 -46
  10. package/src/__tests__/context-overflow-reducer.test.ts +264 -124
  11. package/src/__tests__/context-window-manager-overflow-rung.test.ts +289 -0
  12. package/src/__tests__/conversation-agent-loop-overflow.test.ts +22 -22
  13. package/src/__tests__/conversation-agent-loop.test.ts +45 -37
  14. package/src/__tests__/conversation-fork-crud.test.ts +110 -0
  15. package/src/__tests__/conversation-provider-retry-repair.test.ts +16 -20
  16. package/src/__tests__/conversation-runtime-assembly.test.ts +118 -5
  17. package/src/__tests__/conversation-surfaces-app-control.test.ts +4 -1
  18. package/src/__tests__/conversation-tool-setup-app-refresh.test.ts +91 -142
  19. package/src/__tests__/conversation-tool-setup-skill-attribution.test.ts +116 -0
  20. package/src/__tests__/conversation-tool-setup-test-helpers.ts +98 -0
  21. package/src/__tests__/corrected-target.test.ts +93 -0
  22. package/src/__tests__/credential-execution-feature-gates.test.ts +3 -5
  23. package/src/__tests__/credential-security-invariants.test.ts +1 -0
  24. package/src/__tests__/embedding-managed-proxy-selection.test.ts +6 -40
  25. package/src/__tests__/external-plugin-loader.test.ts +0 -1
  26. package/src/__tests__/guardian-routing-invariants.test.ts +91 -0
  27. package/src/__tests__/history-repair-hook.test.ts +2 -0
  28. package/src/__tests__/host-app-control-proxy.test.ts +45 -0
  29. package/src/__tests__/llm-catalog-parity.test.ts +4 -0
  30. package/src/__tests__/memory-retrieval-hook.test.ts +29 -15
  31. package/src/__tests__/notification-decision-strategy.test.ts +3 -3
  32. package/src/__tests__/persistence-secret-redaction.test.ts +78 -0
  33. package/src/__tests__/plugin-bootstrap.test.ts +82 -73
  34. package/src/__tests__/plugin-tool-contribution.test.ts +7 -4
  35. package/src/__tests__/plugin-types.test.ts +0 -8
  36. package/src/__tests__/provider-catalog-visibility.test.ts +1 -9
  37. package/src/__tests__/retry-thinking-adaptive-only.test.ts +245 -0
  38. package/src/__tests__/server-history-render.test.ts +39 -0
  39. package/src/__tests__/skills.test.ts +123 -0
  40. package/src/__tests__/title-generate-hook.test.ts +2 -0
  41. package/src/__tests__/tool-audit-listener.test.ts +51 -0
  42. package/src/__tests__/tool-executor-lifecycle-events.test.ts +32 -0
  43. package/src/__tests__/tool-start-timestamp.test.ts +218 -0
  44. package/src/agent/loop.ts +26 -23
  45. package/src/api/events/tool-result.ts +9 -0
  46. package/src/api/events/tool-use-start.ts +7 -0
  47. package/src/api/responses/conversation-message.ts +91 -14
  48. package/src/approvals/guardian-request-resolvers.ts +26 -0
  49. package/src/cli/commands/channel-verification-sessions.ts +6 -6
  50. package/src/cli/commands/inference-providers.ts +0 -8
  51. package/src/cli/commands/plugins.ts +2 -2
  52. package/src/cli/lib/__tests__/install-from-github.test.ts +174 -18
  53. package/src/cli/lib/__tests__/plugin-catalog-cache.test.ts +1 -1
  54. package/src/cli/lib/__tests__/plugin-details.test.ts +1 -1
  55. package/src/cli/lib/__tests__/plugin-marketplace.test.ts +1 -1
  56. package/src/cli/lib/__tests__/search-plugins.test.ts +11 -11
  57. package/src/cli/lib/install-from-github.ts +130 -19
  58. package/src/cli/lib/plugin-catalog-cache.ts +1 -1
  59. package/src/cli/lib/plugin-details.ts +4 -4
  60. package/src/cli/lib/plugin-marketplace.ts +2 -2
  61. package/src/cli/lib/search-plugins.ts +6 -6
  62. package/src/config/bundled-skills/skill-management/SKILL.md +89 -1
  63. package/src/config/env-registry.ts +12 -0
  64. package/src/config/feature-flag-registry.json +0 -80
  65. package/src/config/loader.ts +5 -22
  66. package/src/config/seed-inference-profiles.ts +1 -1
  67. package/src/config/skills.ts +101 -47
  68. package/src/context/strip-injections.ts +7 -4
  69. package/src/daemon/conversation-agent-loop-handlers.ts +102 -6
  70. package/src/daemon/conversation-agent-loop.ts +134 -232
  71. package/src/daemon/conversation-runtime-assembly.ts +44 -8
  72. package/src/daemon/conversation-tool-setup.ts +9 -1
  73. package/src/daemon/external-plugins-bootstrap.ts +33 -87
  74. package/src/daemon/handlers/config-channels.ts +11 -2
  75. package/src/daemon/handlers/shared.ts +9 -1
  76. package/src/daemon/handlers/skills.ts +6 -2
  77. package/src/daemon/host-app-control-proxy.ts +72 -57
  78. package/src/daemon/message-protocol.ts +0 -7
  79. package/src/daemon/message-types/skills.ts +4 -0
  80. package/src/events/tool-audit-listener.ts +7 -1
  81. package/src/memory/__tests__/tool-invocation-test-helpers.ts +69 -0
  82. package/src/memory/conversation-crud.ts +44 -1
  83. package/src/memory/db-init.ts +4 -0
  84. package/src/memory/embedding-backend.ts +5 -22
  85. package/src/memory/memory-retrospective-startup-cleanup.ts +1 -1
  86. package/src/memory/migrations/275-tool-invocations-add-skill-id.test.ts +81 -0
  87. package/src/memory/migrations/275-tool-invocations-add-skill-id.ts +20 -0
  88. package/src/memory/migrations/276-tool-invocations-created-at-id-index.test.ts +68 -0
  89. package/src/memory/migrations/276-tool-invocations-created-at-id-index.ts +20 -0
  90. package/src/memory/migrations/index.ts +2 -0
  91. package/src/memory/schema/conversations.ts +3 -0
  92. package/src/memory/tool-execution-events-store.test.ts +162 -0
  93. package/src/memory/tool-execution-events-store.ts +73 -0
  94. package/src/memory/tool-usage-store.ts +4 -3
  95. package/src/memory/v2/__tests__/injected-block-slugs.test.ts +51 -0
  96. package/src/memory/v2/activation-store.ts +50 -1
  97. package/src/memory/v2/injected-block-slugs.ts +30 -0
  98. package/src/notifications/__tests__/copy-composer.test.ts +244 -0
  99. package/src/notifications/access-request-copy.ts +298 -0
  100. package/src/notifications/adapters/slack.ts +3 -3
  101. package/src/notifications/adapters/telegram.ts +2 -1
  102. package/src/notifications/copy-composer.ts +49 -267
  103. package/src/notifications/decision-engine.ts +16 -35
  104. package/src/notifications/home-feed-side-effect.ts +1 -6
  105. package/src/platform/client.ts +1 -3
  106. package/src/platform/feature-gate.ts +3 -12
  107. package/src/plugin-api/constants.ts +2 -0
  108. package/src/plugin-api/index.ts +34 -6
  109. package/src/plugin-api/types.ts +19 -0
  110. package/src/plugins/defaults/compaction/compact.ts +39 -1
  111. package/src/plugins/defaults/compaction/context-overflow-reducer.ts +240 -32
  112. package/src/plugins/defaults/compaction/corrected-target.ts +53 -0
  113. package/src/plugins/defaults/compaction/window-manager.ts +136 -0
  114. package/src/plugins/defaults/index.ts +24 -0
  115. package/src/plugins/defaults/memory-retrieval/hooks/post-compact.ts +68 -43
  116. package/src/plugins/defaults/memory-retrieval/hooks/{user-prompt-submit-temp.ts → user-prompt-submit.ts} +36 -67
  117. package/src/plugins/defaults/memory-retrieval/package.json +14 -0
  118. package/src/plugins/external-api.ts +1 -1
  119. package/src/plugins/types.ts +5 -51
  120. package/src/providers/inference/__tests__/base-url-route-validation.test.ts +1 -2
  121. package/src/providers/model-catalog.ts +57 -1
  122. package/src/providers/registry.ts +0 -8
  123. package/src/providers/retry.ts +35 -7
  124. package/src/runtime/routes/__tests__/acp-routes.test.ts +151 -0
  125. package/src/runtime/routes/__tests__/inference-provider-connection-routes.test.ts +0 -62
  126. package/src/runtime/routes/__tests__/plugins-routes.test.ts +4 -4
  127. package/src/runtime/routes/acp-routes.test.ts +106 -0
  128. package/src/runtime/routes/acp-routes.ts +248 -2
  129. package/src/runtime/routes/browser-tabs-routes.ts +1 -1
  130. package/src/runtime/routes/channel-verification-routes.ts +14 -5
  131. package/src/runtime/routes/chatgpt-subscription-auth-routes.ts +0 -14
  132. package/src/runtime/routes/inbound-stages/acl-enforcement.ts +33 -34
  133. package/src/runtime/routes/inference-provider-connection-routes.ts +0 -45
  134. package/src/runtime/routes/plugins-routes.ts +3 -3
  135. package/src/runtime/verification-outbound-actions.ts +147 -2
  136. package/src/runtime/verification-templates.ts +29 -3
  137. package/src/telemetry/types.ts +25 -1
  138. package/src/telemetry/usage-telemetry-reporter.test.ts +141 -7
  139. package/src/telemetry/usage-telemetry-reporter.ts +63 -7
  140. package/src/tools/executor.ts +4 -1
  141. package/src/tools/skills/load.ts +11 -6
  142. package/src/tools/terminal/safe-env.ts +1 -0
  143. package/src/tools/types.ts +10 -0
  144. package/src/__tests__/plugin-skill-contribution.test.ts +0 -355
  145. package/src/daemon/message-types/browser.ts +0 -10
  146. package/src/notifications/__tests__/emit-signal-home-feed.test.ts +0 -187
  147. package/src/plugins/plugin-skill-contributions.ts +0 -292
@@ -4,6 +4,8 @@
4
4
  * Exposes spawn, steer, cancel, close, sessions, and permission operations
5
5
  * over HTTP and IPC.
6
6
  */
7
+ import { randomUUID } from "node:crypto";
8
+
7
9
  import { and, desc, eq, inArray, notInArray } from "drizzle-orm";
8
10
  import { z } from "zod";
9
11
 
@@ -13,16 +15,20 @@ import { prepareAgentEnv } from "../../acp/prepare-agent-env.js";
13
15
  import { formatResolveFailure } from "../../acp/resolve-agent.js";
14
16
  import { AcpResumeError } from "../../acp/session-manager.js";
15
17
  import type { AcpSessionState } from "../../acp/types.js";
18
+ import { getConfig } from "../../config/loader.js";
16
19
  import { getDb } from "../../memory/db-connection.js";
17
20
  import { rawChanges } from "../../memory/raw-query.js";
18
21
  import { acpSessionHistory } from "../../memory/schema.js";
22
+ import type { UserDecision } from "../../permissions/types.js";
19
23
  import { broadcastMessage } from "../../runtime/assistant-event-hub.js";
20
24
  import { getLogger } from "../../util/logger.js";
21
25
  import { ACTOR_PRINCIPALS } from "../auth/route-policy.js";
26
+ import * as pendingInteractions from "../pending-interactions.js";
22
27
  import {
23
28
  BadRequestError,
24
29
  ConflictError,
25
30
  FailedDependencyError,
31
+ ForbiddenError,
26
32
  NotFoundError,
27
33
  } from "./errors.js";
28
34
  import type { RouteDefinition, RouteHandlerArgs } from "./types.js";
@@ -53,7 +59,109 @@ type SessionEntry = z.infer<typeof sessionEntrySchema>;
53
59
  // Handlers
54
60
  // ---------------------------------------------------------------------------
55
61
 
56
- async function spawnSession({ body }: RouteHandlerArgs) {
62
+ /**
63
+ * Surface a high-risk confirmation for an ACP route that starts a host agent
64
+ * subprocess (`POST /v1/acp/spawn`, and the resume branch of
65
+ * `POST /v1/acp/:id/steer`) and resolve to the guardian's decision.
66
+ *
67
+ * Unlike the `acp_spawn` / `acp_steer` skill tools (which are dispatched
68
+ * through `ToolExecutor`/`PermissionChecker` and so inherit the descriptors'
69
+ * `risk: "high"` approval prompt), these HTTP/IPC routes reach the ACP
70
+ * session manager directly. A spawned ACP agent is a host subprocess with
71
+ * advertised filesystem + terminal access whose in-session permission
72
+ * requests are auto-allowed, so starting one is exactly the high-risk action
73
+ * the descriptors gate. Without this prompt a caller holding only
74
+ * `chat.write` could start one with no human in the loop — directly via
75
+ * spawn (arbitrary `cwd`), or by resuming a terminal session via steer (its
76
+ * persisted `cwd`, enumerable through `GET /v1/acp/sessions`) (ATL-822).
77
+ *
78
+ * The confirmation is registered with `directResolve` so `POST /v1/confirm`
79
+ * resolves it without a live `Conversation` object. That route requires the
80
+ * bound guardian (`approval.write` + `requireGuardian`) — a strictly higher
81
+ * bar than the `chat.write` these routes demand — so the `chat.write` caller
82
+ * cannot self-approve. Timeout and client disconnect both deny, matching the
83
+ * tool path's "no interactive client → do not run" posture.
84
+ */
85
+ function awaitRouteApproval(args: {
86
+ toolName: string;
87
+ input: Record<string, unknown>;
88
+ conversationId: string;
89
+ signal?: AbortSignal;
90
+ }): Promise<UserDecision> {
91
+ const { toolName, input, conversationId, signal } = args;
92
+ const requestId = randomUUID();
93
+ // Mirror the interactive prompt timeout; fall back to the schema default
94
+ // (300s) if the timeouts block is somehow absent so the gate never wedges.
95
+ const timeoutMs = (getConfig().timeouts?.permissionTimeoutSec ?? 300) * 1000;
96
+
97
+ return new Promise<UserDecision>((resolve) => {
98
+ let settled = false;
99
+ const settle = (
100
+ decision: UserDecision,
101
+ state: "approved" | "rejected" | "cancelled",
102
+ ) => {
103
+ if (settled) return;
104
+ settled = true;
105
+ clearTimeout(timer);
106
+ signal?.removeEventListener("abort", onAbort);
107
+ // Idempotent: the `/v1/confirm` directResolve path already removed the
108
+ // entry before invoking us, so this is a no-op there and only fires
109
+ // `interaction_resolved` for the timeout/abort paths.
110
+ pendingInteractions.resolve(requestId, state);
111
+ resolve(decision);
112
+ };
113
+
114
+ const timer = setTimeout(() => {
115
+ log.warn(
116
+ { requestId, toolName, conversationId },
117
+ "ACP route approval timed out — denying",
118
+ );
119
+ settle("deny", "cancelled");
120
+ }, timeoutMs);
121
+
122
+ const onAbort = () => settle("deny", "cancelled");
123
+ if (signal?.aborted) {
124
+ clearTimeout(timer);
125
+ resolve("deny");
126
+ return;
127
+ }
128
+ signal?.addEventListener("abort", onAbort, { once: true });
129
+
130
+ pendingInteractions.register(requestId, {
131
+ conversationId,
132
+ kind: "confirmation",
133
+ confirmationDetails: {
134
+ toolName,
135
+ input,
136
+ riskLevel: "high",
137
+ executionTarget: "host",
138
+ allowlistOptions: [],
139
+ scopeOptions: [],
140
+ persistentDecisionsAllowed: false,
141
+ },
142
+ directResolve: (decision) =>
143
+ settle(decision, decision === "allow" ? "approved" : "rejected"),
144
+ });
145
+
146
+ broadcastMessage(
147
+ {
148
+ type: "confirmation_request",
149
+ requestId,
150
+ toolName,
151
+ input,
152
+ riskLevel: "high",
153
+ executionTarget: "host",
154
+ allowlistOptions: [],
155
+ scopeOptions: [],
156
+ conversationId,
157
+ persistentDecisionsAllowed: false,
158
+ },
159
+ conversationId,
160
+ );
161
+ });
162
+ }
163
+
164
+ async function spawnSession({ body, abortSignal }: RouteHandlerArgs) {
57
165
  const agent = body?.agent as string | undefined;
58
166
  const task = body?.task as string | undefined;
59
167
  const conversationId = body?.conversationId as string | undefined;
@@ -63,6 +171,22 @@ async function spawnSession({ body }: RouteHandlerArgs) {
63
171
  throw new BadRequestError("agent, task, and conversationId are required");
64
172
  }
65
173
 
174
+ // High-risk approval gate. Block BEFORE any side effects — resolution can
175
+ // trigger a `bun` global install (auto-install.ts) and `manager.spawn`
176
+ // launches the host subprocess — so an unapproved request mutates nothing.
177
+ const decision = await awaitRouteApproval({
178
+ toolName: "acp_spawn",
179
+ input: { agent, task, cwd },
180
+ conversationId,
181
+ signal: abortSignal,
182
+ });
183
+ if (decision !== "allow") {
184
+ throw new ForbiddenError(
185
+ "Spawning an ACP coding agent requires guardian approval, which was " +
186
+ "not granted.",
187
+ );
188
+ }
189
+
66
190
  // Resolve the agent, silently auto-installing a missing allowlisted
67
191
  // adapter binary (see acp/auto-install.ts). Shared with the skill-tool
68
192
  // path in tools/acp/spawn.ts; only the transport mapping differs.
@@ -117,6 +241,43 @@ async function steerSession({ pathParams, body }: RouteHandlerArgs) {
117
241
  // broadcastMessage plays the sender role spawnSession gives it, so
118
242
  // connected clients render the session.
119
243
  const manager = getAcpSessionManager();
244
+
245
+ // Resume re-spawns the host agent subprocess, so it crosses the same
246
+ // high-risk boundary as spawn and needs guardian approval (ATL-822). A
247
+ // steer of a session still active in memory only redirects an
248
+ // already-running, already-approved process, so it is left unprompted —
249
+ // matching "gate before spawning". A resume only happens when the id is
250
+ // absent from memory AND a resumable history row (non-null cwd) exists.
251
+ if (!manager.getActiveAndPendingIds().includes(id)) {
252
+ const resumable = getDb()
253
+ .select({
254
+ cwd: acpSessionHistory.cwd,
255
+ agentId: acpSessionHistory.agentId,
256
+ parentConversationId: acpSessionHistory.parentConversationId,
257
+ })
258
+ .from(acpSessionHistory)
259
+ .where(eq(acpSessionHistory.id, id))
260
+ .get();
261
+ if (resumable?.cwd != null) {
262
+ // Guardian approval is an out-of-band human action that can take far
263
+ // longer than a client's ack timeout (the macOS client uses 10s; the
264
+ // approval window is permissionTimeoutSec, default 300s). Blocking the
265
+ // HTTP response here would surface as a client transport failure even
266
+ // on an eventual approval. Acknowledge immediately and run approval +
267
+ // resume in the background, streaming via SSE like any other ACP
268
+ // activity. The request abortSignal is deliberately NOT threaded into
269
+ // the wait — the request is already complete.
270
+ void approveThenResume({
271
+ id,
272
+ instruction,
273
+ agentId: resumable.agentId,
274
+ cwd: resumable.cwd,
275
+ conversationId: resumable.parentConversationId,
276
+ });
277
+ return { acpSessionId: id, steered: false, approvalPending: true };
278
+ }
279
+ }
280
+
120
281
  try {
121
282
  const { resumed } = await manager.steerOrResume(
122
283
  id,
@@ -138,6 +299,81 @@ async function steerSession({ pathParams, body }: RouteHandlerArgs) {
138
299
  }
139
300
  }
140
301
 
302
+ /**
303
+ * Background worker for an approval-gated ACP resume initiated over the steer
304
+ * route. Awaits the guardian decision (see `awaitRouteApproval`), then resumes
305
+ * via the session manager so the agent's output streams back over SSE. A
306
+ * denial, timeout, or resume failure is surfaced as an `acp_session_error` on
307
+ * the parent conversation so the client isn't left with an optimistic steer
308
+ * row and no follow-up. Never throws — it owns the request lifecycle after the
309
+ * route has already acked.
310
+ */
311
+ async function approveThenResume(args: {
312
+ id: string;
313
+ instruction: string;
314
+ agentId: string;
315
+ cwd: string;
316
+ conversationId: string;
317
+ }): Promise<void> {
318
+ const decision = await awaitRouteApproval({
319
+ toolName: "acp_steer",
320
+ input: {
321
+ acp_session_id: args.id,
322
+ instruction: args.instruction,
323
+ agent: args.agentId,
324
+ cwd: args.cwd,
325
+ },
326
+ conversationId: args.conversationId,
327
+ });
328
+
329
+ if (decision !== "allow") {
330
+ log.info(
331
+ { acpSessionId: args.id, conversationId: args.conversationId },
332
+ "ACP resume approval not granted — skipping resume",
333
+ );
334
+ broadcastMessage(
335
+ {
336
+ type: "acp_session_error",
337
+ // Key the error by the daemon session id (the value the steer route
338
+ // accepts and ACP SSE consumers index by — see registerSession, where
339
+ // state.id is the broadcast acpSessionId), NOT the persisted protocol
340
+ // id. A denied resume never emits acp_session_spawned to map the
341
+ // protocol id, so a protocol-keyed error would be dropped.
342
+ acpSessionId: args.id,
343
+ error: "Resume was not approved.",
344
+ },
345
+ args.conversationId,
346
+ );
347
+ return;
348
+ }
349
+
350
+ try {
351
+ await getAcpSessionManager().steerOrResume(
352
+ args.id,
353
+ args.instruction,
354
+ broadcastMessage,
355
+ );
356
+ } catch (err) {
357
+ const message =
358
+ err instanceof AcpResumeError || err instanceof Error
359
+ ? err.message
360
+ : String(err);
361
+ log.warn(
362
+ { acpSessionId: args.id, conversationId: args.conversationId, err },
363
+ "Approved ACP resume failed",
364
+ );
365
+ broadcastMessage(
366
+ {
367
+ type: "acp_session_error",
368
+ // Daemon session id (route + SSE key), not the protocol id — see above.
369
+ acpSessionId: args.id,
370
+ error: message,
371
+ },
372
+ args.conversationId,
373
+ );
374
+ }
375
+ }
376
+
141
377
  async function cancelSession({ pathParams }: RouteHandlerArgs) {
142
378
  const id = pathParams?.id as string;
143
379
  const manager = getAcpSessionManager();
@@ -276,7 +512,10 @@ export const ROUTES: RouteDefinition[] = [
276
512
  "Send a steering instruction to an ACP session. Sessions no longer " +
277
513
  "in memory (completed, or lost to a daemon restart) are " +
278
514
  "transparently resumed from persisted history first, when the agent " +
279
- "supports ACP session loading.",
515
+ "supports ACP session loading. Resuming a terminal session re-spawns " +
516
+ "the host agent, so it requires guardian approval: the route acks " +
517
+ "immediately with approvalPending=true and performs the resume in the " +
518
+ "background once approved, streaming results over SSE.",
280
519
  tags: ["acp"],
281
520
  requestBody: z.object({
282
521
  instruction: z.string(),
@@ -290,6 +529,13 @@ export const ROUTES: RouteDefinition[] = [
290
529
  .describe(
291
530
  "True when the session was resumed from persisted history before steering.",
292
531
  ),
532
+ approvalPending: z
533
+ .boolean()
534
+ .optional()
535
+ .describe(
536
+ "True when the steer triggered a guardian-approval-gated resume " +
537
+ "that will run asynchronously; watch SSE for the outcome.",
538
+ ),
293
539
  }),
294
540
  },
295
541
  {
@@ -114,7 +114,7 @@ async function handleBrowserTabs({ body = {} }: RouteHandlerArgs) {
114
114
  }
115
115
  } else if (targetClientId) {
116
116
  // Only scope-clear the targeted client's pin. With the per-(conversationId,
117
- // clientId) pin store (#31361), passing no clientId to clearPinnedTab
117
+ // clientId) pin store, passing no clientId to clearPinnedTab
118
118
  // would wipe pins for *every* connected client on this conversation
119
119
  // and break their routing — so we skip the clear entirely when the
120
120
  // caller didn't explicitly target a client. The stale pin (if any)
@@ -23,6 +23,7 @@ import { ACTOR_PRINCIPALS } from "../auth/route-policy.js";
23
23
  import { revokePendingSessions } from "../channel-verification-service.js";
24
24
  import {
25
25
  cancelOutbound,
26
+ deliverVerificationEmail,
26
27
  deliverVerificationSlack,
27
28
  normalizeTelegramDestination,
28
29
  resendOutbound,
@@ -139,11 +140,15 @@ export async function handleCreateVerificationSession({
139
140
  verificationRateLimiter.recordFailure(rateLimitKey);
140
141
  }
141
142
 
142
- // Dispatch Slack DM delivery from the daemon process (not sandboxed).
143
+ // Dispatch delivery from the daemon process (not sandboxed).
143
144
  if (result._pendingSlackDm) {
144
145
  const { userId, text, assistantId: aid } = result._pendingSlackDm;
145
146
  deliverVerificationSlack(userId, text, aid);
146
147
  }
148
+ if (result._pendingEmail) {
149
+ const { to, text, subject, assistantId: aid } = result._pendingEmail;
150
+ deliverVerificationEmail(to, text, subject, aid);
151
+ }
147
152
 
148
153
  if (!result.success) {
149
154
  if (result.error === "rate_limited") {
@@ -157,8 +162,8 @@ export async function handleCreateVerificationSession({
157
162
  );
158
163
  }
159
164
 
160
- // Strip internal field from the response
161
- const { _pendingSlackDm: _, ...publicResult } = result;
165
+ // Strip internal fields from the response
166
+ const { _pendingSlackDm: _, _pendingEmail: __, ...publicResult } = result;
162
167
  return publicResult;
163
168
  }
164
169
 
@@ -204,11 +209,15 @@ export async function handleResendVerificationSession({
204
209
 
205
210
  const result = resendOutbound({ channel, originConversationId });
206
211
 
207
- // Dispatch Slack DM delivery from the daemon process (not sandboxed).
212
+ // Dispatch delivery from the daemon process (not sandboxed).
208
213
  if (result._pendingSlackDm) {
209
214
  const { userId, text, assistantId: aid } = result._pendingSlackDm;
210
215
  deliverVerificationSlack(userId, text, aid);
211
216
  }
217
+ if (result._pendingEmail) {
218
+ const { to, text, subject, assistantId: aid } = result._pendingEmail;
219
+ deliverVerificationEmail(to, text, subject, aid);
220
+ }
212
221
 
213
222
  if (!result.success) {
214
223
  if (result.error === "rate_limited") {
@@ -221,7 +230,7 @@ export async function handleResendVerificationSession({
221
230
  );
222
231
  }
223
232
 
224
- const { _pendingSlackDm: _, ...publicResult } = result;
233
+ const { _pendingSlackDm: _, _pendingEmail: __, ...publicResult } = result;
225
234
  return publicResult;
226
235
  }
227
236
 
@@ -11,8 +11,6 @@
11
11
 
12
12
  import { z } from "zod";
13
13
 
14
- import { isAssistantFeatureFlagEnabled } from "../../config/assistant-feature-flags.js";
15
- import { getConfigReadOnly } from "../../config/loader.js";
16
14
  import { getDb } from "../../memory/db-connection.js";
17
15
  import {
18
16
  createConnection,
@@ -29,18 +27,8 @@ import {
29
27
  import { setSecureKeyAsync } from "../../security/secure-keys.js";
30
28
  import { getLogger } from "../../util/logger.js";
31
29
  import { ACTOR_PRINCIPALS } from "../auth/route-policy.js";
32
- import { BadRequestError } from "./errors.js";
33
30
  import type { RouteDefinition, RouteHandlerArgs } from "./types.js";
34
31
 
35
- function requireFeatureFlag() {
36
- const config = getConfigReadOnly();
37
- if (!isAssistantFeatureFlagEnabled("chatgpt-subscription-auth", config)) {
38
- throw new BadRequestError(
39
- "ChatGPT subscription auth is not enabled for this assistant.",
40
- );
41
- }
42
- }
43
-
44
32
  const log = getLogger("chatgpt-subscription-auth");
45
33
 
46
34
  // ---------------------------------------------------------------------------
@@ -87,7 +75,6 @@ function cleanupExpiredEntries(): void {
87
75
  // ---------------------------------------------------------------------------
88
76
 
89
77
  async function handleStartAuth(_args: RouteHandlerArgs) {
90
- requireFeatureFlag();
91
78
  cleanupExpiredEntries();
92
79
 
93
80
  const codeVerifier = generateCodeVerifier();
@@ -115,7 +102,6 @@ async function handleStartAuth(_args: RouteHandlerArgs) {
115
102
  }
116
103
 
117
104
  async function handleExchange(args: RouteHandlerArgs) {
118
- requireFeatureFlag();
119
105
  const { code, state } = args.body as { code: string; state: string };
120
106
 
121
107
  const pending = pendingAuths.get(state);
@@ -23,7 +23,7 @@ import {
23
23
  findByInviteCodeHash,
24
24
  findByInviteCodeHashAnyChannel,
25
25
  } from "../../../memory/invite-store.js";
26
- import { MESSAGE_PREVIEW_MAX_LENGTH } from "../../../notifications/copy-composer.js";
26
+ import { MESSAGE_PREVIEW_MAX_LENGTH } from "../../../notifications/access-request-copy.js";
27
27
  import { resolveGuardianName } from "../../../prompts/user-reference.js";
28
28
  import { getLogger } from "../../../util/logger.js";
29
29
  import { truncate } from "../../../util/truncate.js";
@@ -332,12 +332,12 @@ export async function enforceIngressAcl(
332
332
 
333
333
  return {
334
334
  resolvedMember: null,
335
- earlyResponse: ({
335
+ earlyResponse: {
336
336
  accepted: true,
337
337
  denied: true,
338
338
  reason: "verification_challenge_sent",
339
339
  verificationSessionId: slackVerifyResult.sessionId,
340
- }),
340
+ },
341
341
  };
342
342
  }
343
343
  }
@@ -375,12 +375,12 @@ export async function enforceIngressAcl(
375
375
 
376
376
  return {
377
377
  resolvedMember: null,
378
- earlyResponse: ({
378
+ earlyResponse: {
379
379
  accepted: true,
380
380
  denied: true,
381
381
  reason: "verification_challenge_sent",
382
382
  verificationSessionId: emailVerifyResult.sessionId,
383
- }),
383
+ },
384
384
  };
385
385
  }
386
386
  }
@@ -438,14 +438,14 @@ export async function enforceIngressAcl(
438
438
 
439
439
  return {
440
440
  resolvedMember: null,
441
- earlyResponse: ({
441
+ earlyResponse: {
442
442
  accepted: true,
443
443
  denied: true,
444
444
  reason: "not_a_member",
445
445
  // Include reply text so the gateway can deliver directly when
446
446
  // callback delivery failed (e.g. signing-key mismatch → 401).
447
447
  ...(!replyDelivered && { replyText }),
448
- }),
448
+ },
449
449
  };
450
450
  }
451
451
  }
@@ -610,12 +610,12 @@ export async function enforceIngressAcl(
610
610
 
611
611
  return {
612
612
  resolvedMember,
613
- earlyResponse: ({
613
+ earlyResponse: {
614
614
  accepted: true,
615
615
  denied: true,
616
616
  reason: "verification_challenge_sent",
617
617
  verificationSessionId: slackVerifyResult.sessionId,
618
- }),
618
+ },
619
619
  };
620
620
  }
621
621
  }
@@ -682,12 +682,12 @@ export async function enforceIngressAcl(
682
682
  }
683
683
  return {
684
684
  resolvedMember,
685
- earlyResponse: ({
685
+ earlyResponse: {
686
686
  accepted: true,
687
687
  denied: true,
688
688
  reason: `member_${channelStatusToMemberStatus(resolvedMember.channel.status)}`,
689
689
  ...(!inactiveReplyDelivered && { replyText: inactiveReplyText }),
690
- }),
690
+ },
691
691
  };
692
692
  }
693
693
  }
@@ -722,15 +722,14 @@ export async function enforceIngressAcl(
722
722
  }
723
723
  return {
724
724
  resolvedMember,
725
- earlyResponse: ({
725
+ earlyResponse: {
726
726
  accepted: true,
727
727
  denied: true,
728
728
  reason: "policy_deny",
729
729
  ...(!denyReplyDelivered && { replyText: denyReplyText }),
730
- }),
730
+ },
731
731
  };
732
732
  }
733
-
734
733
  }
735
734
  }
736
735
 
@@ -786,11 +785,11 @@ async function handleInviteTokenIntercept(params: {
786
785
  );
787
786
 
788
787
  if (dedupResult.duplicate) {
789
- return ({
788
+ return {
790
789
  accepted: true,
791
790
  duplicate: true,
792
791
  eventId: dedupResult.eventId,
793
- });
792
+ };
794
793
  }
795
794
 
796
795
  const outcome = redeemInvite({
@@ -835,11 +834,11 @@ async function handleInviteTokenIntercept(params: {
835
834
  }
836
835
  }
837
836
  markProcessed(dedupResult.eventId);
838
- return ({
837
+ return {
839
838
  accepted: true,
840
839
  eventId: dedupResult.eventId,
841
840
  inviteRedemption: "already_member",
842
- });
841
+ };
843
842
  }
844
843
 
845
844
  const replyText = getInviteRedemptionReply(outcome);
@@ -861,22 +860,22 @@ async function handleInviteTokenIntercept(params: {
861
860
 
862
861
  if (outcome.ok && outcome.type === "redeemed") {
863
862
  markProcessed(dedupResult.eventId);
864
- return ({
863
+ return {
865
864
  accepted: true,
866
865
  eventId: dedupResult.eventId,
867
866
  inviteRedemption: "redeemed",
868
867
  memberId: outcome.memberId,
869
- });
868
+ };
870
869
  }
871
870
 
872
871
  // Failed redemption — inform the user and deny
873
872
  markProcessed(dedupResult.eventId);
874
- return ({
873
+ return {
875
874
  accepted: true,
876
875
  eventId: dedupResult.eventId,
877
876
  denied: true,
878
877
  inviteRedemption: outcome.reason,
879
- });
878
+ };
880
879
  }
881
880
 
882
881
  // ---------------------------------------------------------------------------
@@ -942,11 +941,11 @@ async function handleInviteCodeIntercept(params: {
942
941
  );
943
942
 
944
943
  if (dedupResult.duplicate) {
945
- return ({
944
+ return {
946
945
  accepted: true,
947
946
  duplicate: true,
948
947
  eventId: dedupResult.eventId,
949
- });
948
+ };
950
949
  }
951
950
 
952
951
  const mismatchReply = "This invite is not valid for this channel.";
@@ -965,12 +964,12 @@ async function handleInviteCodeIntercept(params: {
965
964
  }
966
965
  }
967
966
  markProcessed(dedupResult.eventId);
968
- return ({
967
+ return {
969
968
  accepted: true,
970
969
  eventId: dedupResult.eventId,
971
970
  denied: true,
972
971
  inviteRedemption: "channel_mismatch",
973
- });
972
+ };
974
973
  }
975
974
  return null;
976
975
  }
@@ -988,11 +987,11 @@ async function handleInviteCodeIntercept(params: {
988
987
  );
989
988
 
990
989
  if (dedupResult.duplicate) {
991
- return ({
990
+ return {
992
991
  accepted: true,
993
992
  duplicate: true,
994
993
  eventId: dedupResult.eventId,
995
- });
994
+ };
996
995
  }
997
996
 
998
997
  let outcome: ReturnType<typeof redeemInviteByCode>;
@@ -1046,11 +1045,11 @@ async function handleInviteCodeIntercept(params: {
1046
1045
  }
1047
1046
  }
1048
1047
  markProcessed(dedupResult.eventId);
1049
- return ({
1048
+ return {
1050
1049
  accepted: true,
1051
1050
  eventId: dedupResult.eventId,
1052
1051
  inviteRedemption: "already_member",
1053
- });
1052
+ };
1054
1053
  }
1055
1054
 
1056
1055
  const replyText = getInviteRedemptionReply(outcome);
@@ -1072,22 +1071,22 @@ async function handleInviteCodeIntercept(params: {
1072
1071
 
1073
1072
  if (outcome.ok && outcome.type === "redeemed") {
1074
1073
  markProcessed(dedupResult.eventId);
1075
- return ({
1074
+ return {
1076
1075
  accepted: true,
1077
1076
  eventId: dedupResult.eventId,
1078
1077
  inviteRedemption: "redeemed",
1079
1078
  memberId: outcome.memberId,
1080
- });
1079
+ };
1081
1080
  }
1082
1081
 
1083
1082
  // Failed redemption (expired, revoked, etc.) — inform and deny
1084
1083
  markProcessed(dedupResult.eventId);
1085
- return ({
1084
+ return {
1086
1085
  accepted: true,
1087
1086
  eventId: dedupResult.eventId,
1088
1087
  denied: true,
1089
1088
  inviteRedemption: !outcome.ok ? outcome.reason : undefined,
1090
- });
1089
+ };
1091
1090
  }
1092
1091
 
1093
1092
  // ---------------------------------------------------------------------------