@vellumai/assistant 0.8.9-staging.2 → 0.8.9-staging.3

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 (111) hide show
  1. package/docs/activation-funnel-telemetry.md +310 -0
  2. package/package.json +1 -1
  3. package/src/__tests__/activation-early-marking.test.ts +120 -0
  4. package/src/__tests__/agent-loop-output-hooks.test.ts +13 -13
  5. package/src/__tests__/approval-cascade.test.ts +1 -1
  6. package/src/__tests__/compaction-direct.test.ts +32 -18
  7. package/src/__tests__/compaction-events.test.ts +2 -2
  8. package/src/__tests__/compaction.benchmark.test.ts +1 -1
  9. package/src/__tests__/context-overflow-reducer.test.ts +5 -5
  10. package/src/__tests__/context-window-manager-compact-retry.test.ts +1 -1
  11. package/src/__tests__/conversation-abort-tool-results.test.ts +1 -1
  12. package/src/__tests__/conversation-confirmation-signals.test.ts +1 -1
  13. package/src/__tests__/conversation-error.test.ts +15 -1
  14. package/src/__tests__/conversation-history-web-search.test.ts +5 -0
  15. package/src/__tests__/conversation-media-retry.test.ts +1 -1
  16. package/src/__tests__/conversation-process-app-control-preactivation.test.ts +40 -0
  17. package/src/__tests__/conversation-process-callsite.test.ts +1 -1
  18. package/src/__tests__/conversation-provider-retry-repair.test.ts +1 -1
  19. package/src/__tests__/conversation-queue.test.ts +1 -1
  20. package/src/__tests__/conversation-runtime-assembly.test.ts +71 -0
  21. package/src/__tests__/conversation-slash-queue.test.ts +1 -1
  22. package/src/__tests__/conversation-slash-unknown.test.ts +1 -1
  23. package/src/__tests__/conversation-speed-override.test.ts +1 -1
  24. package/src/__tests__/conversation-surfaces-activation-emit.test.ts +395 -0
  25. package/src/__tests__/conversation-surfaces-app-control.test.ts +44 -0
  26. package/src/__tests__/conversation-undo.test.ts +2 -2
  27. package/src/__tests__/conversation-workspace-cache-state.test.ts +1 -1
  28. package/src/__tests__/conversation-workspace-injection.test.ts +1 -1
  29. package/src/__tests__/conversation-workspace-tool-tracking.test.ts +1 -1
  30. package/src/__tests__/cu-unified-flow.test.ts +36 -0
  31. package/src/__tests__/history-repair-hook.test.ts +2 -0
  32. package/src/__tests__/memory-retrieval-hook.test.ts +1 -2
  33. package/src/__tests__/persist-unsendable-image-downscale.test.ts +145 -0
  34. package/src/__tests__/persist-unsendable-image.test.ts +97 -1
  35. package/src/__tests__/post-turn-tool-result-truncation.test.ts +69 -0
  36. package/src/__tests__/skill-feature-flags-integration.test.ts +5 -7
  37. package/src/__tests__/title-generate-hook.test.ts +2 -0
  38. package/src/__tests__/web-fetch.test.ts +45 -0
  39. package/src/acp/__tests__/helpers/acp-config-stub.ts +0 -2
  40. package/src/acp/resolve-agent.test.ts +0 -56
  41. package/src/acp/resolve-agent.ts +10 -38
  42. package/src/agent/loop.ts +13 -27
  43. package/src/cli/lib/__tests__/install-from-github.test.ts +232 -29
  44. package/src/cli/lib/__tests__/plugin-details.test.ts +28 -19
  45. package/src/cli/lib/__tests__/plugin-marketplace.test.ts +57 -7
  46. package/src/cli/lib/__tests__/search-plugins.test.ts +17 -10
  47. package/src/cli/lib/install-from-github.ts +258 -41
  48. package/src/cli/lib/plugin-details.ts +20 -13
  49. package/src/cli/lib/plugin-marketplace.ts +23 -5
  50. package/src/cli/lib/search-plugins.ts +14 -8
  51. package/src/config/acp-defaults.ts +3 -3
  52. package/src/config/acp-schema.ts +1 -7
  53. package/src/config/bundled-skills/acp/SKILL.md +4 -17
  54. package/src/config/bundled-skills/acp/TOOLS.json +2 -2
  55. package/src/config/feature-flag-registry.json +3 -18
  56. package/src/context/post-turn-tool-result-truncation.ts +39 -1
  57. package/src/daemon/conversation-agent-loop-handlers.ts +8 -1
  58. package/src/daemon/conversation-agent-loop.ts +78 -78
  59. package/src/daemon/conversation-error.ts +31 -4
  60. package/src/daemon/conversation-history.ts +1 -1
  61. package/src/daemon/conversation-media-retry.ts +19 -6
  62. package/src/daemon/conversation-messaging.ts +17 -0
  63. package/src/daemon/conversation-process.ts +14 -5
  64. package/src/daemon/conversation-queue-manager.ts +8 -0
  65. package/src/daemon/conversation-runtime-assembly.ts +37 -1
  66. package/src/daemon/conversation-surfaces.ts +141 -3
  67. package/src/daemon/conversation.ts +48 -13
  68. package/src/daemon/persist-unsendable-image.ts +62 -25
  69. package/src/daemon/process-message.ts +1 -1
  70. package/src/memory/__tests__/activation-session-store.test.ts +41 -0
  71. package/src/memory/__tests__/onboarding-events-store.test.ts +80 -0
  72. package/src/memory/activation-session-store.ts +43 -0
  73. package/src/memory/db-init.ts +4 -0
  74. package/src/memory/migrations/273-onboarding-events-funnel-columns.ts +46 -0
  75. package/src/memory/migrations/274-create-activation-sessions.ts +15 -0
  76. package/src/memory/migrations/index.ts +2 -0
  77. package/src/memory/onboarding-events-store.ts +66 -18
  78. package/src/memory/schema/infrastructure.ts +13 -0
  79. package/src/messaging/providers/telegram-bot/api.ts +14 -5
  80. package/src/notifications/adapters/telegram.ts +7 -1
  81. package/src/plugin-api/constants.ts +2 -2
  82. package/src/plugin-api/index.ts +2 -2
  83. package/src/plugin-api/types.ts +19 -5
  84. package/src/plugins/defaults/compaction/compact.ts +24 -15
  85. package/src/plugins/defaults/compaction/context-overflow-reducer.ts +4 -4
  86. package/src/plugins/defaults/compaction/manager-store.ts +1 -1
  87. package/src/{context → plugins/defaults/compaction}/window-manager.ts +12 -12
  88. package/src/plugins/defaults/memory-retrieval/hooks/user-prompt-submit-temp.ts +12 -18
  89. package/src/prompts/system-prompt.ts +61 -10
  90. package/src/prompts/templates/BOOTSTRAP-ACTIVATION-RAIL.md +37 -2
  91. package/src/providers/openai/__tests__/vision-not-supported.test.ts +75 -0
  92. package/src/providers/openai/chat-completions-provider.ts +25 -0
  93. package/src/runtime/routes/__tests__/stt-routes.test.ts +112 -0
  94. package/src/runtime/routes/acp-routes.test.ts +3 -20
  95. package/src/runtime/routes/conversation-routes.ts +2 -0
  96. package/src/runtime/routes/playground/__tests__/force-compact.test.ts +1 -1
  97. package/src/runtime/routes/stt-routes.ts +45 -12
  98. package/src/runtime/routes/workspace-routes.ts +50 -15
  99. package/src/telemetry/__tests__/activation-funnel.test.ts +95 -0
  100. package/src/telemetry/activation-funnel.ts +167 -0
  101. package/src/telemetry/types.ts +13 -0
  102. package/src/telemetry/usage-telemetry-reporter.test.ts +154 -0
  103. package/src/telemetry/usage-telemetry-reporter.ts +26 -1
  104. package/src/tools/acp/list-agents.test.ts +2 -18
  105. package/src/tools/acp/list-agents.ts +3 -15
  106. package/src/tools/acp/spawn.test.ts +0 -10
  107. package/src/tools/browser/browser-execution.ts +12 -2
  108. package/src/tools/network/web-fetch.ts +65 -24
  109. package/src/tools/ui-surface/definitions.ts +7 -0
  110. package/src/acp/feature-gate.test.ts +0 -48
  111. package/src/acp/feature-gate.ts +0 -34
@@ -0,0 +1,310 @@
1
+ # Activation Funnel Telemetry — Runbook + Analytics Handoff
2
+
3
+ > **Linear:** JARVIS-1102 (event emission) — gates JARVIS-1092 (10% rollout) and JARVIS-1093 (dashboard).
4
+ > **Funnel version:** `activation_v1_2026_06`
5
+ > **LD flag:** `experiment-activation-flow-2026-06-03`
6
+ > **Cohort arm tag:** `ab_variant = "variant-a"` (treatment); `control` = the no-rail arm.
7
+
8
+ This doc is the single executable reference for the activation-rail funnel
9
+ telemetry: what it measures, how it flows, the event vocabulary, the dedup
10
+ contract, the local smoke-test runbook, the BigQuery verification query, and the
11
+ canonical handoff blurb for the dashboard work. It is meant to be runnable by
12
+ another engineer without reading the implementation.
13
+
14
+ ---
15
+
16
+ ## 1. Overview — what it measures and how it flows
17
+
18
+ The activation funnel measures how far a new user gets on their first run of the
19
+ **activation rail** (the onboarding experience driven by
20
+ `BOOTSTRAP-ACTIVATION-RAIL.md`). It emits five milestone ("funnel") events per
21
+ session into the **existing onboarding telemetry substrate** — no new event type,
22
+ no new ingest endpoint, no new BigQuery table.
23
+
24
+ The north-star "≥5 user messages within 24h per LD variant" metric is **not** a
25
+ materialized activation event. It is computed downstream by joining the existing
26
+ per-user-message `turn` telemetry events (`turn_index` per conversation) to the
27
+ platform's `flag_assignment_raw` cohort-assignment table — so a dedicated event
28
+ and a custom daemon turn-counting hook are not needed.
29
+
30
+ Flow, end to end:
31
+
32
+ 1. **Daemon records** an activation event into the SQLite `onboarding_events`
33
+ table via `recordActivationEvent()` in
34
+ `assistant/src/memory/onboarding-events-store.ts`:
35
+ - emission is **deterministic, tied to a `ui_show` surface** — there is no
36
+ model-facing tool. The model tags the surface it is already rendering for a
37
+ rail move with an optional `activation_moment` parameter on `ui_show`; the
38
+ daemon captures that tag on the surface's server-side state and records the
39
+ milestone (gated on `isActivationSession`). **Timing is per-moment**
40
+ (`ACTIVATION_MOMENT_EMIT_AT` in `activation-funnel.ts`): most moments record
41
+ when the user **commits** the surface (clicks an action / submits /
42
+ selects) via `handleSurfaceAction()`; the one exception is
43
+ `first_wow_executed`, which records at **render time** in
44
+ `surfaceProxyResolver` — the Run result/`work_result` surface is often
45
+ display-only and may never be committed, so a commit-time emit would never
46
+ fire (and deferring it to a later click would conflate "executed" with
47
+ "interacted"). Show-timing tags are recorded immediately and not stored, so
48
+ the commit path never double-emits. The token→step-name map and the
49
+ show/commit timing both live in
50
+ `assistant/src/telemetry/activation-funnel.ts`;
51
+ - emission is best-effort (wrapped in try/catch) and never blocks or alters
52
+ the surface-action flow;
53
+ - `recordActivationEvent` respects the `getConfig().collectUsageData` opt-out
54
+ gate (returns `null` / no row when disabled).
55
+ 2. **Reporter flushes** every ~5 min: `usage-telemetry-reporter.ts`
56
+ (`REPORT_INTERVAL_MS = 5 * 60 * 1000`, with a one-time
57
+ `INITIAL_FLUSH_DELAY_MS = 30_000` after startup) POSTs unreported onboarding
58
+ rows to `/v1/telemetry/ingest/` as `type: "onboarding"` events, mapping the
59
+ funnel columns onto the wire shape.
60
+ 3. **Platform ingests** the onboarding events and writes GCS NDJSON.
61
+ 4. **BigQuery** exposes them via the external table
62
+ `vellum-ai-prod.telemetry.onboarding_raw`, which already carries the
63
+ `session_id / step_name / step_index / completed_at / funnel_version /
64
+ ab_variant` columns. The existing dbt model dedups on `daemon_event_id`
65
+ (earliest-wins).
66
+
67
+ No platform / dbt / terraform change is required — the activation events ride the
68
+ `type: "onboarding"` substrate that already exists end to end.
69
+
70
+ ---
71
+
72
+ ## 2. Event vocabulary
73
+
74
+ The single source of truth is `assistant/src/telemetry/activation-funnel.ts`
75
+ (`ACTIVATION_STEPS`). `funnel_version = "activation_v1_2026_06"`
76
+ (`ACTIVATION_FUNNEL_VERSION`). `ab_variant = "variant-a"`
77
+ (`ACTIVATION_AB_VARIANT`, the treatment arm).
78
+
79
+ Each step is recorded when the user commits the `ui_show` surface the model
80
+ tagged with the corresponding `activation_moment` token (see §1). The
81
+ token→step-name map is the `moment_*` column below.
82
+
83
+ | step_index | step_name | `activation_moment` token | Recorded on commit of |
84
+ | ---------- | --------------------------------- | ------------------------- | --------------------------------------------------------------- |
85
+ | 1 | `activation_moment_1_complete` | `moment_1` | Port-summary card OR no-port intake `choice` surface |
86
+ | 2 | `activation_moment_2_complete` | `moment_2` | Propose offer surface (the `ui_show` offer card/choice) |
87
+ | 3 | `activation_moment_3_complete` | `moment_3` | task-selection surface |
88
+ | 4 | `activation_first_wow_executed` | `first_wow_executed` | Run result surface (e.g. `work_result`) |
89
+ | 5 | `activation_first_wow_interacted` | `first_wow_interacted` | user clicks an action on the tagged result surface (see §1, §4) |
90
+
91
+ All five steps are recorded deterministically on surface commit. The north star
92
+ (≥5 user messages) is derived downstream from the existing `turn` telemetry, not
93
+ a materialized activation event (see §1).
94
+
95
+ On the wire, each onboarding event also sets `screen = step_name` (to satisfy the
96
+ SQLite `screen TEXT NOT NULL` column and the platform's legacy-path validation),
97
+ and `completed_at` is the ISO-8601 record time.
98
+
99
+ ---
100
+
101
+ ## 3. Dedup contract
102
+
103
+ Activation rows carry a **deterministic** `daemon_event_id`:
104
+
105
+ ```
106
+ daemon_event_id = `${funnel_version}:${session_id}:${step_name}`
107
+ ```
108
+
109
+ Built by `buildActivationDaemonEventId()` in
110
+ `assistant/src/telemetry/activation-funnel.ts`. The reporter overrides
111
+ `daemon_event_id` for activation rows (where `session_id && step_name &&
112
+ funnel_version` are all present) and keys it on the **row's stored
113
+ `funnel_version`**, NOT the running binary's current constant. This keeps the id
114
+ stable across a version bump so rows queued offline / flushed after an upgrade
115
+ still collapse with already-ingested rows from the same session.
116
+
117
+ A moment that fires more than once (e.g. a model double-emit) therefore lands
118
+ with the same `daemon_event_id` and is collapsed downstream by the existing dbt
119
+ earliest-wins dedup on `daemon_event_id`. For boolean "moment complete"
120
+ semantics, earliest-wins is correct.
121
+
122
+ **Checkpoint safety:** the SQLite watermark cursor in the reporter advances on the
123
+ row `id` / `createdAt`, NOT on `daemon_event_id`. The deterministic id is a
124
+ wire-only override, so overriding it never affects flush checkpointing.
125
+
126
+ ---
127
+
128
+ ## 4. Cohort scoping
129
+
130
+ Events only emit for conversations explicitly marked as **activation-rail
131
+ sessions**:
132
+
133
+ - The marker lives in the `activation_sessions` table
134
+ (`assistant/src/memory/activation-session-store.ts`,
135
+ `markActivationSession` / `isActivationSession`).
136
+ - It is set in `assistant/src/prompts/system-prompt.ts` **only when the
137
+ `BOOTSTRAP-ACTIVATION-RAIL.md` template is actually active** (i.e.
138
+ `bootstrapTemplate === ACTIVATION_RAIL_BOOTSTRAP_TEMPLATE`), which the web
139
+ prechat context selects only for users whose
140
+ `experiment-activation-flow-2026-06-03` cohort puts them on the rail. (It is
141
+ also set up-front in `conversation.ts` `setOnboardingContext` so the marker is
142
+ available before the first turn's tool resolution.)
143
+ - Emission is **gated on the marker at commit time**: when a tagged `ui_show`
144
+ surface is committed, the daemon records the milestone only if
145
+ `isActivationSession(conversationId)` is true. A stray `activation_moment` tag
146
+ in a normal chat is therefore ignored and never pollutes the funnel. (`moment_4`
147
+ / `first_wow_interacted` deduping is handled the same way as any other moment —
148
+ see the dedup contract in §3 — and the per-surface tag is cleared after the
149
+ first record so a single surface commit emits at most once.)
150
+
151
+ The activation **session id is the daemon `conversation_id`** of the rail
152
+ conversation. That same value is `session_id` on every activation event.
153
+
154
+ ---
155
+
156
+ ## 5. Local smoke-test runbook
157
+
158
+ Goal: drive one dev session through the activation cohort, emit all five events,
159
+ flush, and verify rows in BigQuery. Executable by another engineer.
160
+
161
+ ### 5.1 Put the dev user in the activation cohort
162
+
163
+ The rail is gated by the LD flag `experiment-activation-flow-2026-06-03`. Two
164
+ options:
165
+
166
+ - **In-app feature-flags override (fastest):** open the in-app Feature Flags
167
+ panel and force `experiment-activation-flow-2026-06-03` ON for the dev user.
168
+ - **LaunchDarkly targeting:** target the dev user for the flag in the LD
169
+ dashboard (per the LD-flag-two-repo convention, targeting is dashboard-side).
170
+
171
+ When the flag is ON, the web prechat context selects
172
+ `BOOTSTRAP-ACTIVATION-RAIL.md` as the bootstrap template, and the daemon marks
173
+ the conversation in `activation_sessions` on first build of the system prompt.
174
+
175
+ ### 5.2 Confirm usage-data collection is enabled — and do NOT run in dev mode
176
+
177
+ Two gates must both be satisfied or no rows reach BigQuery:
178
+
179
+ 1. `recordActivationEvent` no-ops when `config.collectUsageData` is false, so the
180
+ dev build/config must have usage-data collection enabled, or no rows are
181
+ written to SQLite.
182
+ 2. **Dev mode disables the flush entirely.** `assistant/src/daemon/lifecycle.ts`
183
+ computes the effective setting as `collectUsageData = !isDevMode &&
184
+ config.collectUsageData`, so when the daemon runs in dev mode (`VELLUM_DEV=1`)
185
+ the `UsageTelemetryReporter` is never started — rows accumulate in SQLite but
186
+ are never POSTed, and the "wait/restart for flush" steps below will never
187
+ reach BigQuery. For an end-to-end smoke test, run the daemon **outside dev
188
+ mode** (so the reporter starts), or explicitly invoke the reporter's
189
+ `flush()` via a dev hook. The SQLite rows can still be inspected directly in
190
+ dev mode, but the BigQuery verification (§6) requires a real flush.
191
+
192
+ ### 5.3 Start a fresh activation conversation and capture its id
193
+
194
+ Start a brand-new conversation with the flag ON (it must be the rail bootstrap, so
195
+ start it from the web prechat flow / activation entry, not an existing chat).
196
+ Note its `conversation_id` — this is the `session_id` you will query on.
197
+
198
+ If multiple daemons are running, kill ALL `daemon/main.ts` processes, remove
199
+ `~/.vellum/vellum.sock`, and start fresh, so the conversation is served by a known
200
+ daemon writing to a known SQLite DB.
201
+
202
+ ### 5.4 Drive the rail through all five model moments
203
+
204
+ Work the conversation through the rail moves so the model tags each surface and
205
+ you commit it (the model tags surfaces via `ui_show`'s `activation_moment`
206
+ parameter; which surface maps to which moment is documented in
207
+ `BOOTSTRAP-ACTIVATION-RAIL.md` and §2). Each milestone records when YOU commit
208
+ the tagged surface:
209
+
210
+ 1. Commit the Port-summary card / no-port intake `choice` → `activation_moment_1_complete`.
211
+ 2. Commit the Propose offer surface → `activation_moment_2_complete`.
212
+ 3. Commit the task-selection surface → `activation_moment_3_complete`.
213
+ 4. Commit the Run result surface → `activation_first_wow_executed`.
214
+ 5. Click an action on the result surface → `activation_first_wow_interacted`.
215
+
216
+ ### 5.5 Force / await a telemetry flush
217
+
218
+ The reporter flushes on a schedule: a first flush ~30s after startup
219
+ (`INITIAL_FLUSH_DELAY_MS`) and then every ~5 min (`REPORT_INTERVAL_MS`). Either:
220
+
221
+ - **Wait** for the next scheduled flush (≤ ~5 min), or
222
+ - **Restart the daemon** to take the ~30s post-startup flush, or
223
+ - call the reporter's `flush()` path directly if you have a dev hook into the
224
+ running daemon.
225
+
226
+ A successful flush POSTs the unreported onboarding rows to
227
+ `/v1/telemetry/ingest/` as `type: "onboarding"` events.
228
+
229
+ ### 5.6 Verify in BigQuery
230
+
231
+ Wait for the platform → GCS NDJSON → BigQuery pipeline to land the events, then
232
+ run the query in §6.
233
+
234
+ ---
235
+
236
+ ## 6. BigQuery verification query
237
+
238
+ ```sql
239
+ SELECT step_name, step_index, COUNT(*) AS n
240
+ FROM `vellum-ai-prod.telemetry.onboarding_raw`
241
+ WHERE funnel_version = 'activation_v1_2026_06'
242
+ AND session_id = '<dev conversation id>'
243
+ GROUP BY 1, 2
244
+ ORDER BY 2;
245
+ ```
246
+
247
+ **Expected:** all five `activation_*` step names for the one session, step_index
248
+ 1–5, each with `n = 1`:
249
+
250
+ ```
251
+ activation_moment_1_complete | 1 | 1
252
+ activation_moment_2_complete | 2 | 1
253
+ activation_moment_3_complete | 3 | 1
254
+ activation_first_wow_executed | 4 | 1
255
+ activation_first_wow_interacted | 5 | 1
256
+ ```
257
+
258
+ A missing row means that milestone never emitted (re-drive that rail move); an
259
+ `n > 1` before dbt dedup is harmless (the deterministic `daemon_event_id`
260
+ collapses it earliest-wins).
261
+
262
+ ---
263
+
264
+ ## 7. Canonical handoff blurb (paste-ready for the final JARVIS-1102 PR description)
265
+
266
+ > **Activation funnel telemetry — handoff for JARVIS-1093.** The activation rail
267
+ > now emits five milestone funnel events into the existing onboarding telemetry
268
+ > substrate (`type: "onboarding"` → `/v1/telemetry/ingest/` → GCS NDJSON →
269
+ > `vellum-ai-prod.telemetry.onboarding_raw`), so no new event type, ingest
270
+ > endpoint, or BigQuery table is involved. Cohort is gated by the LaunchDarkly
271
+ > flag **`experiment-activation-flow-2026-06-03`**; only rail (treatment)
272
+ > conversations emit. Every event carries **`funnel_version =
273
+ "activation_v1_2026_06"`** and **`ab_variant`** tagged `"variant-a"` for
274
+ > treatment (`"control"` is the no-rail arm, measured for now from generic `turn`
275
+ > events). The event vocabulary (step_name → step_index): `activation_moment_1_complete`
276
+ > (1), `activation_moment_2_complete` (2), `activation_moment_3_complete` (3),
277
+ > `activation_first_wow_executed` (4), `activation_first_wow_interacted` (5).
278
+ > `session_id` is the rail conversation's id. The **north star** ("≥5 user
279
+ > messages within 24h per LD variant") is **not** a funnel event — compute it
280
+ > downstream by joining the existing `turn` telemetry events (`turn_index` per
281
+ > conversation) to the platform's `flag_assignment_raw` cohort-assignment table.
282
+ > **Dedup contract:** each row's `daemon_event_id` is deterministic,
283
+ > `${funnel_version}:${session_id}:${step_name}`, keyed on the row's stored
284
+ > `funnel_version`; the existing dbt earliest-wins dedup on `daemon_event_id`
285
+ > collapses any repeated moment to a single row. Build funnel conversion as a
286
+ > step_index 1→5 progression per `session_id`, filtered to `funnel_version =
287
+ 'activation_v1_2026_06'`.
288
+
289
+ ---
290
+
291
+ ## 8. Notes
292
+
293
+ - **JARVIS-1102 "naming check" (resolved).** Events fire **deterministically on
294
+ the real user commit of a `ui_show` surface, not every text turn**. The model
295
+ passively tags the surface for a rail move with `activation_moment`; the daemon
296
+ records the milestone in `handleSurfaceAction` when the user commits that
297
+ surface (firing conditions / surface→moment mapping documented in
298
+ `BOOTSTRAP-ACTIVATION-RAIL.md`). This removes the standalone
299
+ `emit_activation_event` tool (and its cohort preactivation) entirely and ties
300
+ emission to a genuine user action, resolving the naming-check open
301
+ interpretation.
302
+ - **Stream B (multivariate cohort flag conversion) is NOT in this work.** It is
303
+ gated on the platform team's in-flight string-flag serving — until the platform
304
+ can serve string/multivariate flags, flipping
305
+ `experiment-activation-flow-2026-06-03` boolean→multivariate client-side would
306
+ silently disable the live allowlisted rail. Until then, `ab_variant` is the
307
+ constant `"variant-a"` (only treatment runs the rail), and the **control side**
308
+ of the comparison is measured from generic `turn` events split by the
309
+ platform's experiment exposure mapping. Once Stream B lands, the daemon tags the
310
+ real assigned arm and the cross-cohort comparison works with zero rework.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vellumai/assistant",
3
- "version": "0.8.9-staging.2",
3
+ "version": "0.8.9-staging.3",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -0,0 +1,120 @@
1
+ /**
2
+ * Early activation-session marking.
3
+ *
4
+ * The agent loop resolves TOOLS before the SYSTEM PROMPT, so the activation
5
+ * marker must be written before tool resolution on the first activation-rail
6
+ * turn — otherwise the `activation` skill is not preactivated and the emit
7
+ * handler is gated off for the very turn that emits Moment 1. The marking lives
8
+ * in `applyBootstrapTemplate`, which is called from `setOnboardingContext` (the
9
+ * earliest point the conversation knows its bootstrap selection) as well as
10
+ * from `buildSystemPrompt` as an idempotent backstop.
11
+ *
12
+ * These tests exercise `applyBootstrapTemplate` directly against the real
13
+ * DB-backed `isActivationSession` and a real workspace BOOTSTRAP.md, proving the
14
+ * marker is set INDEPENDENT of any `buildSystemPrompt` render.
15
+ */
16
+
17
+ import { copyFileSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
18
+ import { join } from "node:path";
19
+ import { beforeEach, describe, expect, mock, test } from "bun:test";
20
+
21
+ const TEST_DIR = process.env.VELLUM_WORKSPACE_DIR!;
22
+
23
+ mock.module("../util/logger.js", () => ({
24
+ getLogger: () =>
25
+ new Proxy({} as Record<string, unknown>, {
26
+ get: () => () => {},
27
+ }),
28
+ }));
29
+
30
+ const { applyBootstrapTemplate } = await import("../prompts/system-prompt.js");
31
+ const { isActivationSession } =
32
+ await import("../memory/activation-session-store.js");
33
+ const { ACTIVATION_RAIL_BOOTSTRAP_TEMPLATE } =
34
+ await import("../telemetry/activation-funnel.js");
35
+ const { getDb } = await import("../memory/db-connection.js");
36
+ const { initializeDb } = await import("../memory/db-init.js");
37
+ const { activationSessions } = await import("../memory/schema.js");
38
+
39
+ initializeDb();
40
+
41
+ /** Seed the workspace BOOTSTRAP.md with the unmodified generic template so the
42
+ * one-shot reseed inside `applyBootstrapTemplate` fires. */
43
+ function seedGenericBootstrap(): void {
44
+ mkdirSync(TEST_DIR, { recursive: true });
45
+ const generic = readFileSync(
46
+ join(import.meta.dirname, "..", "prompts", "templates", "BOOTSTRAP.md"),
47
+ "utf-8",
48
+ );
49
+ writeFileSync(join(TEST_DIR, "BOOTSTRAP.md"), generic, "utf-8");
50
+ }
51
+
52
+ describe("applyBootstrapTemplate — early activation marking", () => {
53
+ beforeEach(() => {
54
+ getDb().delete(activationSessions).run();
55
+ });
56
+
57
+ test("marks the conversation when the activation-rail template is applied", () => {
58
+ seedGenericBootstrap();
59
+ expect(isActivationSession("rail-conv")).toBe(false);
60
+
61
+ // No buildSystemPrompt call — marking must happen here.
62
+ applyBootstrapTemplate(ACTIVATION_RAIL_BOOTSTRAP_TEMPLATE, "rail-conv");
63
+
64
+ expect(isActivationSession("rail-conv")).toBe(true);
65
+ });
66
+
67
+ test("does not mark when a non-rail bootstrap template is applied", () => {
68
+ seedGenericBootstrap();
69
+
70
+ applyBootstrapTemplate("BOOTSTRAP-REFERENCE.md", "non-rail-conv");
71
+
72
+ expect(isActivationSession("non-rail-conv")).toBe(false);
73
+ });
74
+
75
+ test("does not mark when no conversation id is supplied", () => {
76
+ seedGenericBootstrap();
77
+
78
+ applyBootstrapTemplate(ACTIVATION_RAIL_BOOTSTRAP_TEMPLATE);
79
+
80
+ // Nothing to assert by id; confirm the table stayed empty.
81
+ const rows = getDb().select().from(activationSessions).all();
82
+ expect(rows.length).toBe(0);
83
+ });
84
+
85
+ test("does not mark when BOOTSTRAP.md is customized to something else", () => {
86
+ mkdirSync(TEST_DIR, { recursive: true });
87
+ // A user-customized BOOTSTRAP.md is neither the generic template (so the
88
+ // reseed no-ops) nor the activation-rail template — the rail is not active.
89
+ writeFileSync(
90
+ join(TEST_DIR, "BOOTSTRAP.md"),
91
+ "# My custom bootstrap\n",
92
+ "utf-8",
93
+ );
94
+
95
+ applyBootstrapTemplate(ACTIVATION_RAIL_BOOTSTRAP_TEMPLATE, "custom-conv");
96
+
97
+ expect(isActivationSession("custom-conv")).toBe(false);
98
+ });
99
+
100
+ test("marks idempotently when BOOTSTRAP.md already holds the rail template", () => {
101
+ mkdirSync(TEST_DIR, { recursive: true });
102
+ // Simulate a later turn: BOOTSTRAP.md already holds the rail template, so
103
+ // the reseed no-ops but marking still fires (idempotent backstop).
104
+ copyFileSync(
105
+ join(
106
+ import.meta.dirname,
107
+ "..",
108
+ "prompts",
109
+ "templates",
110
+ ACTIVATION_RAIL_BOOTSTRAP_TEMPLATE,
111
+ ),
112
+ join(TEST_DIR, "BOOTSTRAP.md"),
113
+ );
114
+
115
+ applyBootstrapTemplate(ACTIVATION_RAIL_BOOTSTRAP_TEMPLATE, "rail-conv-2");
116
+ applyBootstrapTemplate(ACTIVATION_RAIL_BOOTSTRAP_TEMPLATE, "rail-conv-2");
117
+
118
+ expect(isActivationSession("rail-conv-2")).toBe(true);
119
+ });
120
+ });
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Tests for the `pre-model-call` and `assistant-message` plugin hooks: a plugin
2
+ * Tests for the `pre-model-call` and `post-model-call` plugin hooks: a plugin
3
3
  * can edit the outbound request, transform the finalized assistant message
4
4
  * (persisted + streamed), and defer the live stream so the transformed text is
5
5
  * emitted once. All hooks here use neutral transforms (redaction / uppercasing).
@@ -9,7 +9,7 @@ import { beforeEach, describe, expect, test } from "bun:test";
9
9
  import type { AgentEvent } from "../agent/loop.js";
10
10
  import { AgentLoop } from "../agent/loop.js";
11
11
  import type {
12
- AssistantMessageContext,
12
+ PostModelCallContext,
13
13
  PreModelCallContext,
14
14
  } from "../plugin-api/types.js";
15
15
  import { resetPluginRegistryAndRegisterDefaults } from "../plugins/defaults/index.js";
@@ -55,7 +55,7 @@ function lastAssistant(history: Message[]): Message {
55
55
 
56
56
  function registerOutputHookPlugin(hooks: {
57
57
  preModelCall?: (ctx: PreModelCallContext) => void;
58
- assistantMessage?: (ctx: AssistantMessageContext) => void;
58
+ postModelCall?: (ctx: PostModelCallContext) => void;
59
59
  }): void {
60
60
  registerPlugin({
61
61
  manifest: { name: "test-output-hooks", version: "0.0.0" },
@@ -67,10 +67,10 @@ function registerOutputHookPlugin(hooks: {
67
67
  },
68
68
  }
69
69
  : {}),
70
- ...(hooks.assistantMessage
70
+ ...(hooks.postModelCall
71
71
  ? {
72
- "assistant-message": async (ctx: AssistantMessageContext) => {
73
- hooks.assistantMessage!(ctx);
72
+ "post-model-call": async (ctx: PostModelCallContext) => {
73
+ hooks.postModelCall!(ctx);
74
74
  },
75
75
  }
76
76
  : {}),
@@ -83,9 +83,9 @@ describe("agent loop output hooks", () => {
83
83
  resetPluginRegistryAndRegisterDefaults();
84
84
  });
85
85
 
86
- test("assistant-message transforms the persisted message content", async () => {
86
+ test("post-model-call transforms the persisted message content", async () => {
87
87
  registerOutputHookPlugin({
88
- assistantMessage: (ctx) => {
88
+ postModelCall: (ctx) => {
89
89
  ctx.content = ctx.content.map((b) =>
90
90
  b.type === "text"
91
91
  ? { type: "text", text: b.text.replace("secret", "[redacted]") }
@@ -113,7 +113,7 @@ describe("agent loop output hooks", () => {
113
113
  preModelCall: (ctx) => {
114
114
  ctx.deferAssistantOutput = true;
115
115
  },
116
- assistantMessage: (ctx) => {
116
+ postModelCall: (ctx) => {
117
117
  ctx.content = [{ type: "text", text: "[filtered]" }];
118
118
  },
119
119
  });
@@ -137,7 +137,7 @@ describe("agent loop output hooks", () => {
137
137
 
138
138
  test("without defer, the real text still streams while storage is transformed", async () => {
139
139
  registerOutputHookPlugin({
140
- assistantMessage: (ctx) => {
140
+ postModelCall: (ctx) => {
141
141
  ctx.content = [{ type: "text", text: "[stored]" }];
142
142
  },
143
143
  });
@@ -168,7 +168,7 @@ describe("agent loop output hooks", () => {
168
168
  stopReason: "tool_use",
169
169
  };
170
170
  registerOutputHookPlugin({
171
- assistantMessage: (ctx) => {
171
+ postModelCall: (ctx) => {
172
172
  ctx.content = ctx.content.map((b) =>
173
173
  b.type === "text" ? { type: "text", text: b.text.toUpperCase() } : b,
174
174
  );
@@ -237,7 +237,7 @@ describe("agent loop output hooks", () => {
237
237
  // mid-mutation would survive into history. The loop must clone the
238
238
  // content before invoking the hook.
239
239
  registerOutputHookPlugin({
240
- assistantMessage: (ctx) => {
240
+ postModelCall: (ctx) => {
241
241
  ctx.content.push({ type: "text", text: "[INJECTED]" });
242
242
  throw new Error("boom");
243
243
  },
@@ -269,7 +269,7 @@ describe("agent loop output hooks", () => {
269
269
  preModelCall: (ctx) => {
270
270
  ctx.deferAssistantOutput = true;
271
271
  },
272
- assistantMessage: (ctx) => {
272
+ postModelCall: (ctx) => {
273
273
  seen.calls += 1;
274
274
  ctx.content = ctx.content.map((b) =>
275
275
  b.type === "text" ? { type: "text", text: b.text.toUpperCase() } : b,
@@ -173,7 +173,7 @@ mock.module("../memory/retriever.js", () => ({
173
173
  injectMemoryRecallAsUserBlock: (msgs: Message[]) => msgs,
174
174
  }));
175
175
 
176
- mock.module("../context/window-manager.js", () => ({
176
+ mock.module("../plugins/defaults/compaction/window-manager.js", () => ({
177
177
  ContextWindowManager: class {
178
178
  constructor() {}
179
179
  updateConfig() {}
@@ -3,19 +3,29 @@
3
3
  *
4
4
  * The agent loop calls {@link defaultCompact} directly with a
5
5
  * {@link CompactionContext} rather than routing through a middleware pipeline.
6
- * These tests assert that the default implementation delegates to the
7
- * supplied {@link ContextWindowManager} and forwards the request's
8
- * conversational options verbatim. The orchestrator integration path
9
- * (conversation-agent-loop) is exercised by
6
+ * These tests assert that the default implementation resolves the
7
+ * conversation's {@link ContextWindowManager} from the compaction store and
8
+ * forwards the request's conversational options verbatim. The orchestrator
9
+ * integration path (conversation-agent-loop) is exercised by
10
10
  * `conversation-agent-loop-overflow.test.ts`.
11
11
  */
12
12
 
13
- import { describe, expect, test } from "bun:test";
13
+ import { describe, expect, mock, test } from "bun:test";
14
14
 
15
- import {
16
- type CompactionContext,
17
- defaultCompact,
18
- } from "../plugins/defaults/compaction/compact.js";
15
+ // `defaultCompact` resolves the manager from the per-conversation compaction
16
+ // store. Register each test's canned stub in a map the mocked store reads from.
17
+ const fakeContextWindowManagers = new Map<string, unknown>();
18
+ mock.module("../plugins/defaults/compaction/manager-store.js", () => ({
19
+ createContextWindowManager: () => undefined,
20
+ getContextWindowManager: (conversationId: string) =>
21
+ fakeContextWindowManagers.get(conversationId),
22
+ disposeContextWindowManager: (conversationId: string) => {
23
+ fakeContextWindowManagers.delete(conversationId);
24
+ },
25
+ }));
26
+
27
+ const { defaultCompact } =
28
+ await import("../plugins/defaults/compaction/compact.js");
19
29
 
20
30
  type ContextWindowResultShape = {
21
31
  compacted: boolean;
@@ -55,13 +65,17 @@ function makeResult(
55
65
  };
56
66
  }
57
67
 
58
- function makeManager(result: ContextWindowResultShape) {
68
+ /** Register a stub manager under a conversation id and return its recorder. */
69
+ function registerManager(
70
+ conversationId: string,
71
+ result: ContextWindowResultShape,
72
+ ) {
59
73
  const observed: {
60
74
  messages: unknown;
61
75
  signal: unknown;
62
76
  options: unknown;
63
77
  }[] = [];
64
- const manager = {
78
+ fakeContextWindowManagers.set(conversationId, {
65
79
  maybeCompact: async (
66
80
  messages: unknown,
67
81
  signal: unknown,
@@ -70,8 +84,8 @@ function makeManager(result: ContextWindowResultShape) {
70
84
  observed.push({ messages, signal, options });
71
85
  return result;
72
86
  },
73
- } as unknown as CompactionContext["manager"];
74
- return { manager, observed };
87
+ });
88
+ return observed;
75
89
  }
76
90
 
77
91
  describe("defaultCompact", () => {
@@ -81,13 +95,13 @@ describe("defaultCompact", () => {
81
95
  summaryText: "manager-summary",
82
96
  compactedMessages: 7,
83
97
  });
84
- const { manager, observed } = makeManager(expected);
98
+ const observed = registerManager("conv-delegates", expected);
85
99
  const messages = [{ role: "user", content: "hi" }] as never;
86
100
  const signal = new AbortController().signal;
87
101
 
88
102
  // WHEN defaultCompact runs with those messages and a signal
89
103
  const result = (await defaultCompact({
90
- manager,
104
+ conversationId: "conv-delegates",
91
105
  messages,
92
106
  signal,
93
107
  })) as unknown as ContextWindowResultShape;
@@ -105,11 +119,11 @@ describe("defaultCompact", () => {
105
119
 
106
120
  test("forwards the request's compaction options to the manager", async () => {
107
121
  // GIVEN a manager and a fully-populated compaction context
108
- const { manager, observed } = makeManager(makeResult());
122
+ const observed = registerManager("conv-options", makeResult());
109
123
 
110
124
  // WHEN defaultCompact runs with force/profile/trust options
111
125
  await defaultCompact({
112
- manager,
126
+ conversationId: "conv-options",
113
127
  messages: [] as never,
114
128
  force: true,
115
129
  overrideProfile: "fast-profile",
@@ -118,7 +132,7 @@ describe("defaultCompact", () => {
118
132
  actorTrustClass: "guardian",
119
133
  });
120
134
 
121
- // THEN the manager received exactly those options, and the manager,
135
+ // THEN the manager received exactly those options, and the conversation id,
122
136
  // messages, and signal are not leaked into the options bag
123
137
  expect(observed).toHaveLength(1);
124
138
  expect(observed[0]!.options).toEqual({
@@ -12,8 +12,8 @@ import { describe, expect, mock, test } from "bun:test";
12
12
 
13
13
  import { CompactionCircuit } from "../agent/compaction-circuit.js";
14
14
  import type { AgentEvent } from "../agent/loop.js";
15
- import type { ContextWindowResult } from "../context/window-manager.js";
16
15
  import type { ServerMessage } from "../daemon/message-protocol.js";
16
+ import type { ContextWindowResult } from "../plugins/defaults/compaction/window-manager.js";
17
17
  import type { Message, ProviderResponse } from "../providers/types.js";
18
18
 
19
19
  // ---------------------------------------------------------------------------
@@ -187,7 +187,7 @@ let mockCompactResult: ContextWindowResult = {
187
187
  summaryText: "",
188
188
  };
189
189
 
190
- mock.module("../context/window-manager.js", () => ({
190
+ mock.module("../plugins/defaults/compaction/window-manager.js", () => ({
191
191
  ContextWindowManager: class {
192
192
  nonPersistedPrefixCount = 0;
193
193
  constructor() {}