@vellumai/assistant 0.10.8-dev.202607131933.b36ce20 → 0.10.8-dev.202607132124.866aced
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/docs/activation-funnel-telemetry.md +20 -18
- package/node_modules/@vellumai/gateway-client/src/gateway-ipc-contracts.ts +20 -0
- package/openapi.yaml +1 -2
- package/package.json +2 -2
- package/scripts/build-test-fixtures.ts +3 -2
- package/scripts/test.ts +2 -7
- package/src/__tests__/auth-fallback-events-store.test.ts +45 -39
- package/src/__tests__/contacts-tools.test.ts +21 -12
- package/src/__tests__/conversation-clear-safety.test.ts +18 -7
- package/src/__tests__/conversation-store.test.ts +53 -78
- package/src/__tests__/conversation-surfaces-activation-emit.test.ts +35 -27
- package/src/__tests__/internal-telemetry-routes.test.ts +23 -13
- package/src/__tests__/prune-old-conversations-job.test.ts +14 -12
- package/src/cli/commands/apps.help.ts +40 -0
- package/src/cli/commands/apps.ts +61 -0
- package/src/cli/index.help.ts +2 -0
- package/src/cli/lib/__tests__/plugin-catalog-local.test.ts +2 -0
- package/src/cli/lib/__tests__/plugin-catalog-platform.test.ts +6 -2
- package/src/cli/lib/__tests__/plugin-catalog-resolve.test.ts +197 -0
- package/src/cli/lib/__tests__/plugin-details.test.ts +349 -240
- package/src/cli/lib/__tests__/search-plugins.test.ts +48 -1
- package/src/cli/lib/plugin-catalog-local.ts +1 -1
- package/src/cli/lib/plugin-catalog-platform.ts +6 -2
- package/src/cli/lib/plugin-catalog-resolve.ts +72 -0
- package/src/cli/lib/plugin-details.ts +100 -34
- package/src/cli/lib/plugin-marketplace.ts +1 -1
- package/src/cli/lib/search-plugins.ts +6 -0
- package/src/cli/program.ts +2 -0
- package/src/config/__tests__/feature-flag-registry-bundled.test.ts +2 -2
- package/src/config/bundled-skills/contacts/tools/contact-merge.ts +4 -2
- package/src/contacts/contact-store.ts +3 -58
- package/src/onboarding/__tests__/onboarding-events-store.test.ts +65 -38
- package/src/onboarding/onboarding-events-store.ts +63 -126
- package/src/persistence/__tests__/main-db-readonly-probe.ts +5 -4
- package/src/persistence/conversation-crud.ts +43 -31
- package/src/persistence/db-connection.ts +3 -2
- package/src/persistence/job-handlers/cleanup.ts +11 -10
- package/src/persistence/lifecycle-events-store.test.ts +46 -64
- package/src/persistence/lifecycle-events-store.ts +24 -62
- package/src/persistence/migrations/329-move-onboarding-events-to-telemetry-db.test.ts +86 -52
- package/src/persistence/migrations/330-move-auth-fallback-events-to-telemetry-db.test.ts +74 -51
- package/src/persistence/migrations/331-move-lifecycle-events-to-telemetry-db.test.ts +76 -56
- package/src/persistence/migrations/332-move-skill-loaded-events-to-telemetry-db.test.ts +89 -85
- package/src/persistence/migrations/333-create-telemetry-events-table.test.ts +66 -0
- package/src/persistence/migrations/333-create-telemetry-events-table.ts +43 -0
- package/src/persistence/migrations/334-backfill-telemetry-events-outbox.test.ts +584 -0
- package/src/persistence/migrations/334-backfill-telemetry-events-outbox.ts +386 -0
- package/src/persistence/schema/infrastructure.ts +14 -102
- package/src/persistence/steps.ts +4 -0
- package/src/runtime/__tests__/agent-wake.test.ts +100 -7
- package/src/runtime/agent-wake.ts +44 -2
- package/src/runtime/routes/__tests__/contact-routes-merge-relay.test.ts +186 -0
- package/src/runtime/routes/__tests__/plugins-routes.test.ts +144 -60
- package/src/runtime/routes/contact-routes.ts +34 -42
- package/src/runtime/routes/conversation-routes.ts +0 -2
- package/src/runtime/routes/plugins-routes.ts +58 -16
- package/src/security/auth-fallback-events-store.ts +28 -78
- package/src/telemetry/__tests__/config-setting-events-store.test.ts +25 -72
- package/src/telemetry/__tests__/config-setting-snapshot.test.ts +10 -7
- package/src/telemetry/__tests__/watchdog-events-store.test.ts +33 -95
- package/src/telemetry/config-setting-events-store.ts +22 -73
- package/src/telemetry/skill-loaded-events-store.test.ts +46 -95
- package/src/telemetry/skill-loaded-events-store.ts +30 -85
- package/src/telemetry/telemetry-event-sources.ts +80 -180
- package/src/telemetry/telemetry-events-outbox.test.ts +233 -0
- package/src/telemetry/telemetry-events-outbox.ts +149 -0
- package/src/telemetry/types.ts +11 -12
- package/src/telemetry/usage-telemetry-reporter.test.ts +654 -223
- package/src/telemetry/usage-telemetry-reporter.ts +48 -8
- package/src/telemetry/watchdog-direct-emit.ts +1 -1
- package/src/telemetry/watchdog-events-store.ts +21 -69
- package/src/usage/attribution.ts +2 -2
- package/src/util/telemetry-db-path.ts +9 -8
|
@@ -29,9 +29,11 @@ and a custom daemon turn-counting hook are not needed.
|
|
|
29
29
|
|
|
30
30
|
Flow, end to end:
|
|
31
31
|
|
|
32
|
-
1. **Daemon records** an activation event into the SQLite `
|
|
33
|
-
|
|
34
|
-
`
|
|
32
|
+
1. **Daemon records** an activation event into the SQLite `telemetry_events`
|
|
33
|
+
outbox — the row stores the record-time wire payload, including the
|
|
34
|
+
deterministic activation `daemon_event_id` (§3) — via
|
|
35
|
+
`recordActivationEvent()` in
|
|
36
|
+
`assistant/src/onboarding/onboarding-events-store.ts`:
|
|
35
37
|
- emission is **deterministic, tied to a `ui_show` surface** — there is no
|
|
36
38
|
model-facing tool. The model tags the surface it is already rendering for a
|
|
37
39
|
rail move with an optional `activation_moment` parameter on `ui_show`; the
|
|
@@ -55,9 +57,9 @@ Flow, end to end:
|
|
|
55
57
|
user has not consented; default-off when there is no platform session).
|
|
56
58
|
2. **Reporter flushes** every ~5 min: `usage-telemetry-reporter.ts`
|
|
57
59
|
(`REPORT_INTERVAL_MS = 5 * 60 * 1000`, with a one-time
|
|
58
|
-
`INITIAL_FLUSH_DELAY_MS = 30_000` after startup) POSTs
|
|
59
|
-
rows to `/v1/telemetry/ingest/` as `type: "onboarding"` events
|
|
60
|
-
|
|
60
|
+
`INITIAL_FLUSH_DELAY_MS = 30_000` after startup) POSTs queued onboarding
|
|
61
|
+
rows to `/v1/telemetry/ingest/` as `type: "onboarding"` events — the stored
|
|
62
|
+
record-time payloads as-is — and deletes the rows after a successful upload.
|
|
61
63
|
3. **Platform ingests** the onboarding events and writes GCS NDJSON.
|
|
62
64
|
4. **BigQuery** exposes them via the external table
|
|
63
65
|
`vellum-ai-prod.telemetry.onboarding_raw`, which already carries the
|
|
@@ -93,9 +95,9 @@ All five steps are recorded deterministically on surface commit. The north star
|
|
|
93
95
|
(≥5 user messages) is derived downstream from the existing `turn` telemetry, not
|
|
94
96
|
a materialized activation event (see §1).
|
|
95
97
|
|
|
96
|
-
On the wire, each onboarding event also sets `screen = step_name` (to satisfy
|
|
97
|
-
|
|
98
|
-
|
|
98
|
+
On the wire, each onboarding event also sets `screen = step_name` (to satisfy
|
|
99
|
+
the platform's legacy-path validation), and `completed_at` is the ISO-8601
|
|
100
|
+
record time.
|
|
99
101
|
|
|
100
102
|
---
|
|
101
103
|
|
|
@@ -108,21 +110,21 @@ daemon_event_id = `${funnel_version}:${session_id}:${step_name}`
|
|
|
108
110
|
```
|
|
109
111
|
|
|
110
112
|
Built by `buildActivationDaemonEventId()` in
|
|
111
|
-
`assistant/src/telemetry/activation-funnel.ts`. The
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
still collapse with already-ingested rows from the same session.
|
|
113
|
+
`assistant/src/telemetry/activation-funnel.ts`. The store freezes the id into
|
|
114
|
+
the outbox payload **at record time**, keyed on the **funnel version the row was
|
|
115
|
+
recorded under**, NOT whatever constant the binary that later flushes it carries.
|
|
116
|
+
This keeps the id stable across a version bump so rows queued offline / flushed
|
|
117
|
+
after an upgrade still collapse with already-ingested rows from the same session.
|
|
117
118
|
|
|
118
119
|
A moment that fires more than once (e.g. a model double-emit) therefore lands
|
|
119
120
|
with the same `daemon_event_id` and is collapsed downstream by the existing dbt
|
|
120
121
|
earliest-wins dedup on `daemon_event_id`. For boolean "moment complete"
|
|
121
122
|
semantics, earliest-wins is correct.
|
|
122
123
|
|
|
123
|
-
**
|
|
124
|
-
row
|
|
125
|
-
|
|
124
|
+
**Flush safety:** each outbox row keeps its own random row `id`, and the reporter
|
|
125
|
+
acknowledges (deletes) shipped rows by that row id, NOT by `daemon_event_id`. The
|
|
126
|
+
deterministic id lives only in the wire payload, so it never affects flush
|
|
127
|
+
bookkeeping.
|
|
126
128
|
|
|
127
129
|
---
|
|
128
130
|
|
|
@@ -108,6 +108,26 @@ export type UpdateContactChannelIpcResponse = z.infer<
|
|
|
108
108
|
typeof UpdateContactChannelIpcResponseSchema
|
|
109
109
|
>;
|
|
110
110
|
|
|
111
|
+
export const MergeContactsIpcParamsSchema = z.object({
|
|
112
|
+
keepId: z.string().min(1),
|
|
113
|
+
mergeId: z.string().min(1),
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
export type MergeContactsIpcParams = z.infer<
|
|
117
|
+
typeof MergeContactsIpcParamsSchema
|
|
118
|
+
>;
|
|
119
|
+
|
|
120
|
+
export const MergeContactsIpcResponseSchema = z.object({
|
|
121
|
+
ok: z.literal(true),
|
|
122
|
+
// The gateway-native handler owns the full contact payload shape; pass it
|
|
123
|
+
// through verbatim rather than re-declaring channel fields here.
|
|
124
|
+
contact: z.object({}).passthrough().optional(),
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
export type MergeContactsIpcResponse = z.infer<
|
|
128
|
+
typeof MergeContactsIpcResponseSchema
|
|
129
|
+
>;
|
|
130
|
+
|
|
111
131
|
export const MarkChannelVerifiedIpcParamsSchema = z.object({
|
|
112
132
|
contactChannelId: z.string().min(1),
|
|
113
133
|
// Audit source for the verification. CLI/session-driven verifications
|
package/openapi.yaml
CHANGED
|
@@ -5822,6 +5822,7 @@ paths:
|
|
|
5822
5822
|
ok:
|
|
5823
5823
|
type: boolean
|
|
5824
5824
|
contact:
|
|
5825
|
+
description: Merged (surviving) contact
|
|
5825
5826
|
type: object
|
|
5826
5827
|
properties:
|
|
5827
5828
|
id:
|
|
@@ -5926,10 +5927,8 @@ paths:
|
|
|
5926
5927
|
- updatedAt
|
|
5927
5928
|
- channels
|
|
5928
5929
|
additionalProperties: false
|
|
5929
|
-
description: Merged contact
|
|
5930
5930
|
required:
|
|
5931
5931
|
- ok
|
|
5932
|
-
- contact
|
|
5933
5932
|
additionalProperties: false
|
|
5934
5933
|
/v1/contacts/prompt:
|
|
5935
5934
|
post:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vellumai/assistant",
|
|
3
|
-
"version": "0.10.8-dev.
|
|
3
|
+
"version": "0.10.8-dev.202607132124.866aced",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"test:stable": "EXCLUDE_EXPERIMENTAL=true bun run scripts/test.ts",
|
|
31
31
|
"test:bench": "find src -type f -name '*.benchmark.test.ts' -print0 | xargs -0 -P 1 -I {} bun test {}",
|
|
32
32
|
"test:filesystem-tools": "bash scripts/test-filesystem-tools.sh",
|
|
33
|
-
"postinstall": "cd .. && (git config core.hooksPath || git config core.hooksPath .githooks 2>/dev/null || true) && ([ -f meta/
|
|
33
|
+
"postinstall": "cd .. && (git config core.hooksPath || git config core.hooksPath .githooks 2>/dev/null || true) && ([ -f meta/sync-bundled-copies.ts ] && bun run meta/sync-bundled-copies.ts 2>/dev/null || true)"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@agentclientprotocol/sdk": "0.25.0",
|
|
@@ -69,8 +69,9 @@ async function buildMigratedFixture(outWorkspaceDir: string): Promise<void> {
|
|
|
69
69
|
mkdirSync(destDbDir, { recursive: true });
|
|
70
70
|
|
|
71
71
|
// The four DBs are captured together: the migrated state spans them (e.g.
|
|
72
|
-
// llm_request_logs in `logs`, memory_jobs in `memory`,
|
|
73
|
-
// `telemetry`), so a partial capture would leave a test
|
|
72
|
+
// llm_request_logs in `logs`, memory_jobs in `memory`, telemetry_events +
|
|
73
|
+
// flush_checkpoints in `telemetry`), so a partial capture would leave a test
|
|
74
|
+
// with missing tables.
|
|
74
75
|
const captures = [
|
|
75
76
|
[getSqlite(), getDbPath()],
|
|
76
77
|
[getLogsSqlite(), getLogsDbPath()],
|
package/scripts/test.ts
CHANGED
|
@@ -73,16 +73,11 @@ const KNOWN_BROKEN_FILES = new Set<string>([]);
|
|
|
73
73
|
// and feature-flag-registry-bundled.test.ts fails. Running the sync here is
|
|
74
74
|
// idempotent and cheap (two file copies).
|
|
75
75
|
function syncFeatureFlagRegistry(): void {
|
|
76
|
-
const syncScript = join(
|
|
77
|
-
"..",
|
|
78
|
-
"meta",
|
|
79
|
-
"feature-flags",
|
|
80
|
-
"sync-bundled-copies.ts",
|
|
81
|
-
);
|
|
76
|
+
const syncScript = join("..", "meta", "sync-bundled-copies.ts");
|
|
82
77
|
if (!existsSync(syncScript)) {
|
|
83
78
|
return;
|
|
84
79
|
}
|
|
85
|
-
Bun.spawnSync(["bun", "run", "meta/
|
|
80
|
+
Bun.spawnSync(["bun", "run", "meta/sync-bundled-copies.ts"], {
|
|
86
81
|
cwd: join(process.cwd(), ".."),
|
|
87
82
|
stdout: "ignore",
|
|
88
83
|
stderr: "ignore",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { beforeEach, describe, expect, mock, test } from "bun:test";
|
|
1
|
+
import { beforeEach, describe, expect, mock, spyOn, test } from "bun:test";
|
|
2
2
|
|
|
3
3
|
let shareAnalytics = true;
|
|
4
4
|
|
|
@@ -6,19 +6,23 @@ mock.module("../platform/consent-cache.js", () => ({
|
|
|
6
6
|
getCachedShareAnalytics: () => shareAnalytics,
|
|
7
7
|
}));
|
|
8
8
|
|
|
9
|
-
import
|
|
9
|
+
import * as dbConnection from "../persistence/db-connection.js";
|
|
10
10
|
import { initializeDb } from "../persistence/db-init.js";
|
|
11
|
-
import { authFallbackEvents } from "../persistence/schema/index.js";
|
|
12
11
|
import {
|
|
13
12
|
type AuthFallbackCount,
|
|
14
|
-
queryUnreportedAuthFallbackEvents,
|
|
15
13
|
recordAuthFallbackCounts,
|
|
16
14
|
} from "../security/auth-fallback-events-store.js";
|
|
15
|
+
import {
|
|
16
|
+
discardPendingTelemetryOutboxEvents,
|
|
17
|
+
queryTelemetryOutboxBatch,
|
|
18
|
+
} from "../telemetry/telemetry-events-outbox.js";
|
|
19
|
+
import type { AuthFallbackTelemetryEvent } from "../telemetry/types.js";
|
|
20
|
+
import { APP_VERSION } from "../version.js";
|
|
17
21
|
|
|
18
22
|
await initializeDb();
|
|
19
23
|
|
|
20
|
-
function
|
|
21
|
-
|
|
24
|
+
function pendingRows() {
|
|
25
|
+
return queryTelemetryOutboxBatch("auth_fallback", 100);
|
|
22
26
|
}
|
|
23
27
|
|
|
24
28
|
const SAMPLE: AuthFallbackCount[] = [
|
|
@@ -39,63 +43,65 @@ const SAMPLE: AuthFallbackCount[] = [
|
|
|
39
43
|
describe("auth-fallback-events-store", () => {
|
|
40
44
|
beforeEach(() => {
|
|
41
45
|
shareAnalytics = true;
|
|
42
|
-
|
|
46
|
+
discardPendingTelemetryOutboxEvents("auth_fallback");
|
|
43
47
|
});
|
|
44
48
|
|
|
45
|
-
test("records one row per count entry
|
|
49
|
+
test("records one outbox row per count entry with the full wire payload", () => {
|
|
46
50
|
const recorded = recordAuthFallbackCounts(1000, 2000, SAMPLE);
|
|
47
51
|
expect(recorded).toBe(2);
|
|
48
52
|
|
|
49
|
-
const rows =
|
|
53
|
+
const rows = pendingRows();
|
|
50
54
|
expect(rows.length).toBe(2);
|
|
51
|
-
const
|
|
52
|
-
|
|
55
|
+
const payloads = rows.map(
|
|
56
|
+
(r) => JSON.parse(r.payload) as AuthFallbackTelemetryEvent,
|
|
57
|
+
);
|
|
58
|
+
const byGuard = Object.fromEntries(payloads.map((p) => [p.guard, p]));
|
|
59
|
+
expect(byGuard["edge"]).toEqual({
|
|
60
|
+
type: "auth_fallback",
|
|
61
|
+
daemon_event_id: expect.any(String),
|
|
62
|
+
recorded_at: expect.any(Number),
|
|
63
|
+
guard: "edge",
|
|
53
64
|
path: "/v1/messages",
|
|
54
|
-
|
|
65
|
+
failure_kind: "missing_authorization",
|
|
55
66
|
count: 7,
|
|
56
|
-
|
|
57
|
-
|
|
67
|
+
window_start: 1000,
|
|
68
|
+
window_end: 2000,
|
|
69
|
+
assistant_version: APP_VERSION,
|
|
58
70
|
});
|
|
59
71
|
expect(byGuard["edge-scoped"]).toMatchObject({
|
|
60
72
|
path: "/v1/files",
|
|
61
|
-
|
|
73
|
+
failure_kind: "insufficient_scope",
|
|
62
74
|
count: 2,
|
|
63
75
|
});
|
|
76
|
+
// The wire daemon_event_id matches the outbox row id, and recorded_at
|
|
77
|
+
// matches the row's created_at (record-time stamping).
|
|
78
|
+
rows.forEach((row, i) => {
|
|
79
|
+
expect(payloads[i].daemon_event_id).toBe(row.id);
|
|
80
|
+
expect(payloads[i].recorded_at).toBe(row.createdAt);
|
|
81
|
+
});
|
|
64
82
|
});
|
|
65
83
|
|
|
66
84
|
test("honors the share_analytics opt-out (records nothing)", () => {
|
|
67
85
|
shareAnalytics = false;
|
|
68
86
|
const recorded = recordAuthFallbackCounts(1000, 2000, SAMPLE);
|
|
69
87
|
expect(recorded).toBe(0);
|
|
70
|
-
expect(
|
|
88
|
+
expect(pendingRows().length).toBe(0);
|
|
71
89
|
});
|
|
72
90
|
|
|
73
91
|
test("empty counts batch is a no-op", () => {
|
|
74
92
|
expect(recordAuthFallbackCounts(1000, 2000, [])).toBe(0);
|
|
75
|
-
expect(
|
|
93
|
+
expect(pendingRows().length).toBe(0);
|
|
76
94
|
});
|
|
77
95
|
|
|
78
|
-
test("
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
first[0].createdAt,
|
|
89
|
-
first[0].id,
|
|
90
|
-
1,
|
|
91
|
-
);
|
|
92
|
-
expect(second.length).toBe(1);
|
|
93
|
-
expect(second[0].id).not.toBe(first[0].id);
|
|
94
|
-
|
|
95
|
-
// Cursor past the last row returns nothing.
|
|
96
|
-
const last = all[all.length - 1];
|
|
97
|
-
expect(
|
|
98
|
-
queryUnreportedAuthFallbackEvents(last.createdAt, last.id, 100).length,
|
|
99
|
-
).toBe(0);
|
|
96
|
+
test("records all-or-nothing: db unavailable returns 0 with no rows", () => {
|
|
97
|
+
const spy = spyOn(dbConnection, "getTelemetryDb").mockReturnValue(null);
|
|
98
|
+
try {
|
|
99
|
+
expect(recordAuthFallbackCounts(1000, 2000, SAMPLE)).toBe(0);
|
|
100
|
+
} finally {
|
|
101
|
+
spy.mockRestore();
|
|
102
|
+
}
|
|
103
|
+
// No partial batch: the gateway's `recorded === 0` retry contract means
|
|
104
|
+
// any committed remnant would later double-count.
|
|
105
|
+
expect(pendingRows().length).toBe(0);
|
|
100
106
|
});
|
|
101
107
|
});
|
|
@@ -25,8 +25,9 @@ mock.module("../config/env.js", () => ({
|
|
|
25
25
|
let searchContactsOverride: unknown[] | null = null;
|
|
26
26
|
|
|
27
27
|
// Skill tools call cliIpcCall instead of the gateway HTTP.
|
|
28
|
-
// Mock the IPC client to dispatch contact reads
|
|
29
|
-
//
|
|
28
|
+
// Mock the IPC client to dispatch contact reads to the real store (backed by
|
|
29
|
+
// the test DB) and serve `merge_contacts` as a fake gateway relay, without
|
|
30
|
+
// needing a running IPC server.
|
|
30
31
|
mock.module("../ipc/cli-client.js", () => ({
|
|
31
32
|
cliIpcCall: async (method: string, params?: Record<string, unknown>) => {
|
|
32
33
|
const store = await import("../contacts/contact-store.js");
|
|
@@ -45,9 +46,25 @@ mock.module("../ipc/cli-client.js", () => ({
|
|
|
45
46
|
return { ok: true, result: { ok: true, contact } };
|
|
46
47
|
}
|
|
47
48
|
if (method === "merge_contacts") {
|
|
49
|
+
// Fake gateway relay: the daemon route relays merges to the gateway
|
|
50
|
+
// merge core, which validates and mirrors back into the assistant DB.
|
|
51
|
+
// Emulate that against the fixture DB via the mirror write path.
|
|
48
52
|
const { keepId, mergeId } = body as { keepId: string; mergeId: string };
|
|
49
|
-
|
|
50
|
-
|
|
53
|
+
// The tool pre-validates both contacts via getContact, so the fake only
|
|
54
|
+
// needs the survivor row (for keepDisplayName).
|
|
55
|
+
const keep = store.getContact(keepId);
|
|
56
|
+
if (!keep) {
|
|
57
|
+
return { ok: false, error: `Contact "${keepId}" not found` };
|
|
58
|
+
}
|
|
59
|
+
store.mergeContactMirror({
|
|
60
|
+
keepContactId: keepId,
|
|
61
|
+
mergeContactId: mergeId,
|
|
62
|
+
keepDisplayName: keep.displayName,
|
|
63
|
+
});
|
|
64
|
+
return {
|
|
65
|
+
ok: true,
|
|
66
|
+
result: { ok: true, contact: store.getContact(keepId) },
|
|
67
|
+
};
|
|
51
68
|
}
|
|
52
69
|
return { ok: false, error: `Unknown IPC method: ${method}` };
|
|
53
70
|
},
|
|
@@ -80,14 +97,6 @@ beforeAll(() => {
|
|
|
80
97
|
const path = url.pathname;
|
|
81
98
|
|
|
82
99
|
try {
|
|
83
|
-
if (path === "/v1/contacts/merge" && req.method === "POST") {
|
|
84
|
-
const mergeRoute = ROUTES.find(
|
|
85
|
-
(r) => r.operationId === "merge_contacts",
|
|
86
|
-
)!;
|
|
87
|
-
const body = (await req.json()) as Record<string, unknown>;
|
|
88
|
-
const result = mergeRoute.handler({ body });
|
|
89
|
-
return Response.json(result);
|
|
90
|
-
}
|
|
91
100
|
if (path === "/v1/contacts" && req.method === "GET") {
|
|
92
101
|
const listRoute = ROUTES.find(
|
|
93
102
|
(r) => r.operationId === "listContacts",
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* - Missing X-Confirm-Destructive header returns BadRequestError
|
|
7
7
|
* - Wrong header value returns BadRequestError
|
|
8
8
|
* - Correct header clears data
|
|
9
|
-
* -
|
|
9
|
+
* - telemetry_events contains the `conversations_clear_all` audit entry after clear
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import { describe, expect, mock, test } from "bun:test";
|
|
@@ -170,20 +170,31 @@ describe("DELETE /v1/conversations — route handler", () => {
|
|
|
170
170
|
expect(getConversation(conv.id)).toBeNull();
|
|
171
171
|
});
|
|
172
172
|
|
|
173
|
-
test("
|
|
173
|
+
test("telemetry_events contains conversations_clear_all after successful clear", async () => {
|
|
174
174
|
await clearRoute.handler({
|
|
175
175
|
pathParams: {},
|
|
176
176
|
body: {},
|
|
177
177
|
headers: { "x-confirm-destructive": "clear-all-conversations" },
|
|
178
178
|
});
|
|
179
179
|
|
|
180
|
-
// The audit row
|
|
180
|
+
// The audit row lands in the telemetry_events outbox on the dedicated
|
|
181
|
+
// telemetry DB; the durable trail persists platform-side once flushed.
|
|
181
182
|
const rows = getTelemetrySqlite()!
|
|
182
183
|
.query(
|
|
183
|
-
"SELECT
|
|
184
|
+
"SELECT id, payload FROM telemetry_events WHERE name = 'lifecycle'",
|
|
184
185
|
)
|
|
185
|
-
.all() as Array<{
|
|
186
|
-
|
|
187
|
-
|
|
186
|
+
.all() as Array<{ id: string; payload: string }>;
|
|
187
|
+
const audits = rows
|
|
188
|
+
.map((r) => ({
|
|
189
|
+
id: r.id,
|
|
190
|
+
payload: JSON.parse(r.payload) as Record<string, unknown>,
|
|
191
|
+
}))
|
|
192
|
+
.filter((r) => r.payload.event_name === "conversations_clear_all");
|
|
193
|
+
expect(audits.length).toBeGreaterThanOrEqual(1);
|
|
194
|
+
expect(audits[0].payload).toMatchObject({
|
|
195
|
+
type: "lifecycle",
|
|
196
|
+
daemon_event_id: audits[0].id,
|
|
197
|
+
event_name: "conversations_clear_all",
|
|
198
|
+
});
|
|
188
199
|
});
|
|
189
200
|
});
|
|
@@ -19,10 +19,32 @@ import {
|
|
|
19
19
|
import { isLastUserMessageToolResult } from "../persistence/conversation-queries.js";
|
|
20
20
|
import { getDb, getTelemetryDb } from "../persistence/db-connection.js";
|
|
21
21
|
import { initializeDb } from "../persistence/db-init.js";
|
|
22
|
-
import {
|
|
22
|
+
import { telemetryEvents } from "../persistence/schema/index.js";
|
|
23
23
|
// Initialize db once before all tests
|
|
24
24
|
await initializeDb();
|
|
25
25
|
|
|
26
|
+
/** Seed a pending telemetry outbox row (default name: skill_loaded). */
|
|
27
|
+
function seedTelemetryEvent(
|
|
28
|
+
id: string,
|
|
29
|
+
createdAt: number,
|
|
30
|
+
conversationId: string | null,
|
|
31
|
+
name = "skill_loaded",
|
|
32
|
+
): void {
|
|
33
|
+
getTelemetryDb()!
|
|
34
|
+
.insert(telemetryEvents)
|
|
35
|
+
.values({ id, name, createdAt, conversationId, payload: "{}" })
|
|
36
|
+
.run();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function pendingTelemetryEventIds(): string[] {
|
|
40
|
+
return getTelemetryDb()!
|
|
41
|
+
.select()
|
|
42
|
+
.from(telemetryEvents)
|
|
43
|
+
.all()
|
|
44
|
+
.map((r) => r.id)
|
|
45
|
+
.sort();
|
|
46
|
+
}
|
|
47
|
+
|
|
26
48
|
describe("deleteLastExchange", () => {
|
|
27
49
|
beforeEach(() => {
|
|
28
50
|
// Reset database between tests by dropping and recreating tables
|
|
@@ -351,109 +373,62 @@ describe("attachment orphan cleanup", () => {
|
|
|
351
373
|
expect(linkCount.c).toBe(0);
|
|
352
374
|
});
|
|
353
375
|
|
|
354
|
-
test("clearAll removes
|
|
355
|
-
// Privacy posture: Clear All wins over unflushed telemetry — the
|
|
356
|
-
//
|
|
357
|
-
//
|
|
358
|
-
getTelemetryDb()!.delete(
|
|
376
|
+
test("clearAll removes pending skill_loaded telemetry_events rows", async () => {
|
|
377
|
+
// Privacy posture: Clear All wins over unflushed telemetry — the pending
|
|
378
|
+
// skill_loaded rows (conversation id, skill name, model attribution)
|
|
379
|
+
// must not survive the wipe and ship later.
|
|
380
|
+
getTelemetryDb()!.delete(telemetryEvents).run();
|
|
359
381
|
const conv = createConversation("test");
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
{
|
|
364
|
-
id: "sle-clear-1",
|
|
365
|
-
createdAt: 1000,
|
|
366
|
-
conversationId: conv.id,
|
|
367
|
-
skillName: "web-research",
|
|
368
|
-
},
|
|
369
|
-
// Rows without a conversation are wiped too.
|
|
370
|
-
{ id: "sle-clear-2", createdAt: 2000, skillName: "tasks" },
|
|
371
|
-
])
|
|
372
|
-
.run();
|
|
382
|
+
seedTelemetryEvent("sle-clear-1", 1000, conv.id);
|
|
383
|
+
// Rows without a conversation are wiped too.
|
|
384
|
+
seedTelemetryEvent("sle-clear-2", 2000, null);
|
|
373
385
|
|
|
374
386
|
await clearAll();
|
|
375
387
|
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
388
|
+
const skillRows = getTelemetryDb()!
|
|
389
|
+
.select()
|
|
390
|
+
.from(telemetryEvents)
|
|
391
|
+
.all()
|
|
392
|
+
.filter((r) => r.name === "skill_loaded");
|
|
393
|
+
expect(skillRows).toHaveLength(0);
|
|
379
394
|
});
|
|
380
395
|
|
|
381
|
-
test("deleteConversation removes that conversation's
|
|
382
|
-
getTelemetryDb()!.delete(
|
|
396
|
+
test("deleteConversation removes that conversation's telemetry_events rows", async () => {
|
|
397
|
+
getTelemetryDb()!.delete(telemetryEvents).run();
|
|
383
398
|
const conv = createConversation("doomed");
|
|
384
399
|
await addMessage(conv.id, "user", "hello");
|
|
385
400
|
const other = createConversation("kept");
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
id: "sle-del-1",
|
|
391
|
-
createdAt: 1000,
|
|
392
|
-
conversationId: conv.id,
|
|
393
|
-
skillName: "web-research",
|
|
394
|
-
},
|
|
395
|
-
{
|
|
396
|
-
id: "sle-del-2",
|
|
397
|
-
createdAt: 2000,
|
|
398
|
-
conversationId: other.id,
|
|
399
|
-
skillName: "tasks",
|
|
400
|
-
},
|
|
401
|
-
])
|
|
402
|
-
.run();
|
|
401
|
+
seedTelemetryEvent("te-del-1", 1000, conv.id);
|
|
402
|
+
seedTelemetryEvent("te-del-2", 2000, other.id);
|
|
403
|
+
// Redaction keys on conversation_id regardless of event name.
|
|
404
|
+
seedTelemetryEvent("te-del-3", 3000, conv.id, "future_event");
|
|
403
405
|
|
|
404
406
|
deleteConversation(conv.id);
|
|
405
407
|
|
|
406
|
-
|
|
407
|
-
expect(remaining.map((r) => r.id)).toEqual(["sle-del-2"]);
|
|
408
|
+
expect(pendingTelemetryEventIds()).toEqual(["te-del-2"]);
|
|
408
409
|
});
|
|
409
410
|
|
|
410
|
-
test("deleteConversation removes
|
|
411
|
-
getTelemetryDb()!.delete(
|
|
411
|
+
test("deleteConversation removes telemetry_events rows when the conversation has no messages", () => {
|
|
412
|
+
getTelemetryDb()!.delete(telemetryEvents).run();
|
|
412
413
|
const conv = createConversation("empty");
|
|
413
|
-
|
|
414
|
-
.insert(skillLoadedEvents)
|
|
415
|
-
.values({
|
|
416
|
-
id: "sle-del-empty",
|
|
417
|
-
createdAt: 1000,
|
|
418
|
-
conversationId: conv.id,
|
|
419
|
-
skillName: "web-research",
|
|
420
|
-
})
|
|
421
|
-
.run();
|
|
414
|
+
seedTelemetryEvent("te-del-empty", 1000, conv.id);
|
|
422
415
|
|
|
423
416
|
deleteConversation(conv.id);
|
|
424
417
|
|
|
425
|
-
expect(
|
|
426
|
-
getTelemetryDb()!.select().from(skillLoadedEvents).all(),
|
|
427
|
-
).toHaveLength(0);
|
|
418
|
+
expect(pendingTelemetryEventIds()).toHaveLength(0);
|
|
428
419
|
});
|
|
429
420
|
|
|
430
|
-
test("deleteConversationGently removes that conversation's
|
|
431
|
-
getTelemetryDb()!.delete(
|
|
421
|
+
test("deleteConversationGently removes that conversation's telemetry_events rows", async () => {
|
|
422
|
+
getTelemetryDb()!.delete(telemetryEvents).run();
|
|
432
423
|
const conv = createConversation("doomed");
|
|
433
424
|
await addMessage(conv.id, "user", "hello");
|
|
434
425
|
const other = createConversation("kept");
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
.values([
|
|
438
|
-
{
|
|
439
|
-
id: "sle-gentle-1",
|
|
440
|
-
createdAt: 1000,
|
|
441
|
-
conversationId: conv.id,
|
|
442
|
-
skillName: "web-research",
|
|
443
|
-
},
|
|
444
|
-
{
|
|
445
|
-
id: "sle-gentle-2",
|
|
446
|
-
createdAt: 2000,
|
|
447
|
-
conversationId: other.id,
|
|
448
|
-
skillName: "tasks",
|
|
449
|
-
},
|
|
450
|
-
])
|
|
451
|
-
.run();
|
|
426
|
+
seedTelemetryEvent("te-gentle-1", 1000, conv.id);
|
|
427
|
+
seedTelemetryEvent("te-gentle-2", 2000, other.id);
|
|
452
428
|
|
|
453
429
|
await deleteConversationGently(conv.id);
|
|
454
430
|
|
|
455
|
-
|
|
456
|
-
expect(remaining.map((r) => r.id)).toEqual(["sle-gentle-2"]);
|
|
431
|
+
expect(pendingTelemetryEventIds()).toEqual(["te-gentle-2"]);
|
|
457
432
|
});
|
|
458
433
|
|
|
459
434
|
test("deleteLastExchange does not delete unlinked user uploads", async () => {
|