@vellumai/assistant 0.10.7-dev.202607092332.9deedf4 → 0.10.7-dev.202607100313.fffdfea
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ARCHITECTURE.md +1 -2
- package/docs/architecture/memory.md +1 -3
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/package.json +0 -2
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/__tests__/contracts.test.ts +0 -2
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/credential-rpc.ts +3 -5
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/index.ts +2 -4
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/rpc.ts +4 -447
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/package.json +0 -2
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/__tests__/contracts.test.ts +0 -2
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/credential-rpc.ts +3 -5
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/index.ts +2 -4
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/rpc.ts +4 -447
- package/node_modules/@vellumai/service-contracts/package.json +0 -2
- package/node_modules/@vellumai/service-contracts/src/__tests__/contracts.test.ts +0 -2
- package/node_modules/@vellumai/service-contracts/src/credential-rpc.ts +3 -5
- package/node_modules/@vellumai/service-contracts/src/index.ts +2 -4
- package/node_modules/@vellumai/service-contracts/src/rpc.ts +4 -447
- package/openapi.yaml +1 -222
- package/package.json +1 -1
- package/scripts/memory-inspect.ts +2 -8
- package/src/__tests__/approval-routes-http.test.ts +0 -8
- package/src/__tests__/background-workers-disk-pressure.test.ts +4 -2
- package/src/__tests__/compaction-events.test.ts +0 -4
- package/src/__tests__/context-search-memory-source.test.ts +0 -1
- package/src/__tests__/conversation-agent-loop-disk-pressure.test.ts +0 -1
- package/src/__tests__/conversation-agent-loop-inference-profile.test.ts +0 -2
- package/src/__tests__/conversation-agent-loop-overflow.test.ts +0 -2
- package/src/__tests__/conversation-agent-loop.test.ts +0 -4
- package/src/__tests__/conversation-app-control-lifecycle.test.ts +0 -4
- package/src/__tests__/conversation-fork-crud.test.ts +18 -5
- package/src/__tests__/conversation-fork-retrospective.test.ts +483 -0
- package/src/__tests__/conversation-routes-disk-view.test.ts +0 -4
- package/src/__tests__/conversation-store.test.ts +0 -10
- package/src/__tests__/conversation-summarize-up-to.test.ts +0 -4
- package/src/__tests__/credential-execution-api-key-propagation.test.ts +0 -40
- package/src/__tests__/credential-execution-client.test.ts +3 -3
- package/src/__tests__/credential-execution-managed-contract.test.ts +8 -104
- package/src/__tests__/file-write-tool.test.ts +9 -13
- package/src/__tests__/graph-extraction-event-date.test.ts +0 -9
- package/src/__tests__/injection-block.test.ts +0 -1
- package/src/__tests__/job-handler-registration-guard.test.ts +0 -1
- package/src/__tests__/lexical-index-dual-write.test.ts +2 -2
- package/src/__tests__/llm-resolver.test.ts +0 -1
- package/src/__tests__/messages-after-tiebreaker.test.ts +0 -1
- package/src/__tests__/playbook-execution.test.ts +2 -26
- package/src/__tests__/plugin-import-boundary-guard.test.ts +0 -4
- package/src/__tests__/plugin-import-boundary-reverse-guard.test.ts +318 -0
- package/src/__tests__/proxy-approval-callback.test.ts +0 -1
- package/src/__tests__/rebuild-index-graph-nodes.test.ts +0 -4
- package/src/__tests__/send-endpoint-busy.test.ts +0 -12
- package/src/__tests__/service-contracts-import-guard.test.ts +4 -9
- package/src/__tests__/subagent-fork-spawn.test.ts +0 -37
- package/src/__tests__/task-memory-cleanup.test.ts +0 -11
- package/src/__tests__/voice-scoped-grant-consumer.test.ts +0 -1
- package/src/__tests__/voice-session-bridge.test.ts +0 -56
- package/src/__tests__/workspace-migration-009-backfill-conversation-disk-view.test.ts +0 -1
- package/src/__tests__/workspace-migration-013-repair-conversation-disk-view.test.ts +0 -1
- package/src/__tests__/workspace-migration-028-recover-conversations-from-disk-view.test.ts +0 -1
- package/src/__tests__/workspace-migration-129-remove-analyze-conversation-config.test.ts +190 -0
- package/src/cli/commands/db/repair-step-conversation-backfill.ts +0 -1
- package/src/config/bundled-skills/messaging/tools/messaging-analyze-style.ts +0 -6
- package/src/config/bundled-skills/playbooks/tools/playbook-create.ts +0 -3
- package/src/config/bundled-skills/playbooks/tools/playbook-delete.ts +0 -3
- package/src/config/bundled-skills/playbooks/tools/playbook-list.ts +1 -3
- package/src/config/bundled-skills/playbooks/tools/playbook-update.ts +0 -4
- package/src/config/call-site-defaults.ts +0 -1
- package/src/config/feature-flag-registry.json +0 -16
- package/src/config/schema.ts +0 -3
- package/src/config/schemas/call-site-catalog.ts +0 -6
- package/src/config/schemas/llm.ts +0 -1
- package/src/conversations/job-handlers/summarization.ts +0 -2
- package/src/daemon/conversation-agent-loop-handlers.ts +0 -1
- package/src/daemon/conversation-agent-loop.ts +1 -6
- package/src/daemon/conversation-lifecycle.ts +0 -14
- package/src/daemon/conversation-turn-finalize.ts +0 -1
- package/src/daemon/handlers/shared.ts +1 -2
- package/src/export/transcript-formatter.ts +9 -39
- package/src/home/conversation-starter-checkpoints.ts +9 -5
- package/src/home/job-handlers/conversation-starters.ts +24 -54
- package/src/hooks/types.ts +2 -2
- package/src/ipc/routes/__tests__/memory-v2-backfill.test.ts +5 -7
- package/src/persistence/__tests__/bulk-write-gate.test.ts +165 -0
- package/src/persistence/__tests__/immediate-transaction-guard.test.ts +70 -0
- package/src/persistence/auto-analysis-constants.ts +4 -13
- package/src/persistence/bulk-write-gate.ts +82 -0
- package/src/persistence/conversation-bootstrap.ts +3 -3
- package/src/persistence/conversation-crud.ts +158 -80
- package/src/persistence/conversation-key-store.ts +0 -2
- package/src/persistence/conversation-row-batch-delete.ts +16 -1
- package/src/persistence/conversation-types.ts +12 -1
- package/src/persistence/db-async-query.ts +18 -9
- package/src/persistence/db-connection.ts +20 -4
- package/src/persistence/db-maintenance.ts +78 -6
- package/src/persistence/embeddings/qdrant-client.ts +2 -18
- package/src/persistence/fork-message-copy.ts +18 -4
- package/src/persistence/jobs-store.ts +3 -86
- package/src/persistence/migrations/323-delete-non-default-memory-scopes.test.ts +148 -0
- package/src/persistence/migrations/323-delete-non-default-memory-scopes.ts +35 -0
- package/src/persistence/schema/conversations.ts +0 -1
- package/src/persistence/schema/memory-core.ts +17 -28
- package/src/persistence/schema/memory-graph.ts +0 -4
- package/src/persistence/schema/tasks.ts +0 -1
- package/src/persistence/steps.ts +2 -0
- package/src/playbooks/playbook-compiler.ts +2 -10
- package/src/plugins/defaults/memory/__tests__/db-maintenance.test.ts +105 -11
- package/src/plugins/defaults/memory/__tests__/jobs-store-enqueue-gate.test.ts +7 -62
- package/src/plugins/defaults/memory/__tests__/memory-retrospective-job.test.ts +47 -5
- package/src/plugins/defaults/memory/__tests__/memory-retrospective-skill-card.test.ts +29 -1
- package/src/plugins/defaults/memory/__tests__/memory-retrospective-startup-cleanup.test.ts +133 -70
- package/src/plugins/defaults/memory/activation-session-store.ts +1 -1
- package/src/plugins/defaults/memory/config.ts +1 -1
- package/src/plugins/defaults/memory/context-search/sources/conversations.ts +1 -1
- package/src/plugins/defaults/memory/context-search/sources/memory-v2.ts +1 -1
- package/src/plugins/defaults/memory/context-search/sources/memory.ts +1 -1
- package/src/plugins/defaults/memory/filing-jobs.ts +1 -1
- package/src/plugins/defaults/memory/fork-conversation-memory.ts +8 -4
- package/src/plugins/defaults/memory/frontmatter.ts +1 -1
- package/src/plugins/defaults/memory/graph/__tests__/handle-remember-v2.test.ts +4 -25
- package/src/plugins/defaults/memory/graph/bootstrap.ts +12 -18
- package/src/plugins/defaults/memory/graph/capability-seed.ts +4 -18
- package/src/plugins/defaults/memory/graph/consolidation.ts +7 -14
- package/src/plugins/defaults/memory/graph/conversation-graph-memory.ts +1 -3
- package/src/plugins/defaults/memory/graph/decay.ts +5 -10
- package/src/plugins/defaults/memory/graph/extraction-job.ts +2 -3
- package/src/plugins/defaults/memory/graph/extraction.test.ts +1 -9
- package/src/plugins/defaults/memory/graph/extraction.ts +1 -8
- package/src/plugins/defaults/memory/graph/graph-search.ts +1 -2
- package/src/plugins/defaults/memory/graph/injection.test.ts +0 -1
- package/src/plugins/defaults/memory/graph/injection.ts +1 -1
- package/src/plugins/defaults/memory/graph/narrative.ts +1 -3
- package/src/plugins/defaults/memory/graph/pattern-scan.ts +1 -4
- package/src/plugins/defaults/memory/graph/retriever.test.ts +0 -19
- package/src/plugins/defaults/memory/graph/retriever.ts +6 -14
- package/src/plugins/defaults/memory/graph/scoring.test.ts +0 -1
- package/src/plugins/defaults/memory/graph/store.test.ts +6 -58
- package/src/plugins/defaults/memory/graph/store.ts +5 -43
- package/src/plugins/defaults/memory/graph/tool-handlers.test.ts +0 -4
- package/src/plugins/defaults/memory/graph/tool-handlers.ts +1 -11
- package/src/plugins/defaults/memory/graph/types.ts +0 -3
- package/src/plugins/defaults/memory/hooks/init.ts +1 -1
- package/src/plugins/defaults/memory/indexer.ts +2 -45
- package/src/plugins/defaults/memory/injectors.ts +2 -3
- package/src/plugins/defaults/memory/job-handler-registration.ts +0 -4
- package/src/plugins/defaults/memory/job-handlers/backfill.ts +0 -1
- package/src/plugins/defaults/memory/job-handlers/embedding.test.ts +0 -1
- package/src/plugins/defaults/memory/job-handlers/embedding.ts +0 -4
- package/src/plugins/defaults/memory/job-handlers/index-maintenance.ts +1 -1
- package/src/plugins/defaults/memory/job-handlers.ts +5 -9
- package/src/plugins/defaults/memory/jobs/embed-concept-page.ts +1 -1
- package/src/plugins/defaults/memory/jobs/embed-pkb-file.test.ts +41 -21
- package/src/plugins/defaults/memory/jobs/embed-pkb-file.ts +10 -5
- package/src/plugins/defaults/memory/jobs-worker.ts +21 -9
- package/src/plugins/defaults/memory/logging.ts +17 -0
- package/src/plugins/defaults/memory/memory-retrospective-constants.ts +10 -7
- package/src/plugins/defaults/memory/memory-retrospective-enqueue.ts +5 -6
- package/src/plugins/defaults/memory/memory-retrospective-fork-boundary.ts +57 -20
- package/src/plugins/defaults/memory/memory-retrospective-job.ts +13 -15
- package/src/plugins/defaults/memory/memory-retrospective-skill-card.ts +2 -2
- package/src/plugins/defaults/memory/memory-retrospective-startup-cleanup.ts +52 -39
- package/src/plugins/defaults/memory/memory-retrospective-trigger-check.ts +1 -1
- package/src/plugins/defaults/memory/pkb/pkb-index.test.ts +25 -38
- package/src/plugins/defaults/memory/pkb/pkb-index.ts +7 -19
- package/src/plugins/defaults/memory/pkb/pkb-reconcile.test.ts +46 -28
- package/src/plugins/defaults/memory/pkb/pkb-reconcile.ts +4 -9
- package/src/plugins/defaults/memory/pkb/pkb-search.test.ts +3 -9
- package/src/plugins/defaults/memory/pkb/pkb-search.ts +2 -9
- package/src/plugins/defaults/memory/pkb/types.ts +0 -11
- package/src/plugins/defaults/memory/rerank-local.ts +1 -1
- package/src/plugins/defaults/memory/routes/memory-eval-routes.ts +1 -1
- package/src/plugins/defaults/memory/routes/memory-item-routes.test.ts +0 -1
- package/src/plugins/defaults/memory/routes/memory-item-routes.ts +3 -11
- package/src/plugins/defaults/memory/routes/memory-v2-routes.ts +1 -1
- package/src/plugins/defaults/memory/routes/memory-v3-routes.ts +1 -1
- package/src/plugins/defaults/memory/startup.ts +2 -3
- package/src/plugins/defaults/memory/task-memory-cleanup.ts +1 -1
- package/src/plugins/defaults/memory/tools.test.ts +1 -9
- package/src/plugins/defaults/memory/tools.ts +0 -1
- package/src/plugins/defaults/memory/v2/backfill-jobs.ts +1 -1
- package/src/plugins/defaults/memory/v2/cli-command-store.ts +1 -1
- package/src/plugins/defaults/memory/v2/consolidation-job.ts +1 -1
- package/src/plugins/defaults/memory/v2/frontmatter-sweep.ts +1 -1
- package/src/plugins/defaults/memory/v2/injection-events.ts +1 -1
- package/src/plugins/defaults/memory/v2/injection.ts +1 -1
- package/src/plugins/defaults/memory/v2/memory-v2-startup.ts +1 -1
- package/src/plugins/defaults/memory/v2/migration.ts +1 -1
- package/src/plugins/defaults/memory/v2/page-index.ts +1 -1
- package/src/plugins/defaults/memory/v2/prompts/consolidation.ts +1 -1
- package/src/plugins/defaults/memory/v2/prompts/router.ts +1 -1
- package/src/plugins/defaults/memory/v2/qdrant.ts +1 -1
- package/src/plugins/defaults/memory/v2/reranker.ts +1 -1
- package/src/plugins/defaults/memory/v2/router.ts +1 -1
- package/src/plugins/defaults/memory/v2/skill-store.ts +1 -1
- package/src/plugins/defaults/memory/v2/sweep-job.ts +1 -1
- package/src/plugins/defaults/memory/v3/candidate-match.ts +1 -1
- package/src/plugins/defaults/memory/v3/dense.ts +1 -1
- package/src/plugins/defaults/memory/v3/injector.ts +1 -1
- package/src/plugins/defaults/memory/v3/maintain-job.ts +1 -1
- package/src/plugins/defaults/memory/v3/orchestrate.ts +1 -1
- package/src/plugins/defaults/memory/v3/pool-select.ts +1 -1
- package/src/plugins/defaults/memory/v3/prune.ts +1 -1
- package/src/plugins/defaults/memory/v3/section-dense-store.ts +1 -1
- package/src/plugins/defaults/memory/v3/shadow-plugin.ts +1 -1
- package/src/plugins/defaults/memory/worker.ts +1 -1
- package/src/runtime/capabilities.ts +1 -1
- package/src/runtime/routes/__tests__/bookmark-routes.test.ts +0 -1
- package/src/runtime/routes/__tests__/conversation-management-routes.test.ts +0 -1
- package/src/runtime/routes/__tests__/conversation-query-routes.test.ts +0 -1
- package/src/runtime/routes/conversation-starter-routes.ts +12 -23
- package/src/runtime/routes/index.ts +0 -2
- package/src/runtime/services/__tests__/auto-analysis-guard.test.ts +1 -8
- package/src/runtime/services/__tests__/conversation-serializer.test.ts +0 -1
- package/src/runtime/services/auto-analysis-guard.ts +5 -5
- package/src/runtime/services/conversation-serializer.ts +2 -3
- package/src/tasks/SPEC.md +10 -17
- package/src/tools/executor.ts +1 -102
- package/src/tools/filesystem/write.ts +0 -2
- package/src/tools/tool-types.ts +0 -15
- package/src/tools/types.ts +0 -10
- package/src/workspace/migrations/028-recover-conversations-from-disk-view.ts +0 -1
- package/src/workspace/migrations/129-remove-analyze-conversation-config.ts +59 -0
- package/src/workspace/migrations/registry.ts +2 -0
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/__tests__/grants.test.ts +0 -686
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/grants.ts +0 -184
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/rendering.ts +0 -135
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/__tests__/grants.test.ts +0 -686
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/grants.ts +0 -184
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/rendering.ts +0 -135
- package/node_modules/@vellumai/service-contracts/src/__tests__/grants.test.ts +0 -686
- package/node_modules/@vellumai/service-contracts/src/grants.ts +0 -184
- package/node_modules/@vellumai/service-contracts/src/rendering.ts +0 -135
- package/src/__tests__/auto-analysis-end-to-end.test.ts +0 -621
- package/src/__tests__/auto-analysis-prompt.test.ts +0 -50
- package/src/__tests__/config-analysis.test.ts +0 -83
- package/src/__tests__/conversation-analysis-routes.test.ts +0 -156
- package/src/__tests__/credential-execution-approval-bridge.test.ts +0 -297
- package/src/config/schemas/analysis.ts +0 -32
- package/src/credential-execution/approval-bridge.ts +0 -320
- package/src/daemon/__tests__/conversation-lifecycle-auto-analyze.test.ts +0 -449
- package/src/plugins/defaults/memory/__tests__/find-analysis-conversation.test.ts +0 -197
- package/src/runtime/routes/conversation-analysis-routes.ts +0 -75
- package/src/runtime/services/__tests__/analyze-conversation.test.ts +0 -477
- package/src/runtime/services/__tests__/auto-analysis-enqueue.test.ts +0 -386
- package/src/runtime/services/__tests__/auto-analysis-prompt.test.ts +0 -53
- package/src/runtime/services/__tests__/conversation-analyze-job.test.ts +0 -213
- package/src/runtime/services/__tests__/manual-analysis-prompt.test.ts +0 -41
- package/src/runtime/services/analyze-conversation.ts +0 -334
- package/src/runtime/services/auto-analysis-enqueue.ts +0 -130
- package/src/runtime/services/auto-analysis-prompt.ts +0 -55
- package/src/runtime/services/conversation-analyze-job.ts +0 -53
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* graph.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import { and,
|
|
7
|
+
import { and, sql } from "drizzle-orm";
|
|
8
8
|
|
|
9
9
|
import { getDb } from "../persistence/db-connection.js";
|
|
10
10
|
import { memoryGraphNodes } from "../persistence/schema/index.js";
|
|
@@ -20,19 +20,12 @@ export interface CompiledPlaybooks {
|
|
|
20
20
|
includedCount: number;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
export interface CompilePlaybooksOptions {
|
|
24
|
-
scopeId?: string;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
23
|
interface PlaybookRow {
|
|
28
24
|
id: string;
|
|
29
25
|
content: string;
|
|
30
26
|
}
|
|
31
27
|
|
|
32
|
-
export function compilePlaybooks(
|
|
33
|
-
options?: CompilePlaybooksOptions,
|
|
34
|
-
): CompiledPlaybooks {
|
|
35
|
-
const scopeId = options?.scopeId ?? "default";
|
|
28
|
+
export function compilePlaybooks(): CompiledPlaybooks {
|
|
36
29
|
const db = getDb();
|
|
37
30
|
|
|
38
31
|
const rows: PlaybookRow[] = db
|
|
@@ -43,7 +36,6 @@ export function compilePlaybooks(
|
|
|
43
36
|
.from(memoryGraphNodes)
|
|
44
37
|
.where(
|
|
45
38
|
and(
|
|
46
|
-
eq(memoryGraphNodes.scopeId, scopeId),
|
|
47
39
|
sql`${memoryGraphNodes.sourceConversations} LIKE '%playbook:%'`,
|
|
48
40
|
sql`${memoryGraphNodes.fidelity} != 'gone'`,
|
|
49
41
|
),
|
|
@@ -22,38 +22,50 @@ const { getSqlite } = await import("../../../../persistence/db-connection.js");
|
|
|
22
22
|
const { initializeDb } = await import("../../../../persistence/db-init.js");
|
|
23
23
|
const { deleteMemoryCheckpoint, getMemoryCheckpoint } =
|
|
24
24
|
await import("../../../../persistence/checkpoints.js");
|
|
25
|
-
const { maybeRunDbMaintenance } =
|
|
25
|
+
const { maybeRunDbMaintenance, maybeRunPassiveWalCheckpoint } =
|
|
26
26
|
await import("../../../../persistence/db-maintenance.js");
|
|
27
|
-
const {
|
|
27
|
+
const { getLastInteractiveUserMessageTimestamp } =
|
|
28
28
|
await import("../../../../persistence/conversation-crud.js");
|
|
29
29
|
const { getDbPath } = await import("../../../../util/platform.js");
|
|
30
30
|
|
|
31
31
|
await initializeDb();
|
|
32
32
|
|
|
33
33
|
const MAINTENANCE_CHECKPOINT_KEY = "db_maintenance:last_run";
|
|
34
|
+
const PASSIVE_CHECKPOINT_KEY = "db_maintenance:last_passive_checkpoint";
|
|
34
35
|
const QUIET_PERIOD_MS = 3 * 60 * 60 * 1000;
|
|
35
36
|
|
|
36
37
|
beforeEach(() => {
|
|
37
38
|
deleteMemoryCheckpoint(MAINTENANCE_CHECKPOINT_KEY);
|
|
39
|
+
deleteMemoryCheckpoint(PASSIVE_CHECKPOINT_KEY);
|
|
38
40
|
const sqlite = getSqlite();
|
|
39
41
|
sqlite.exec("DELETE FROM messages");
|
|
40
42
|
sqlite.exec("DELETE FROM conversations");
|
|
41
43
|
});
|
|
42
44
|
|
|
43
45
|
/** Insert a message row directly, bypassing indexing/job side effects. */
|
|
44
|
-
function insertMessage(
|
|
46
|
+
function insertMessage(
|
|
47
|
+
role: "user" | "assistant",
|
|
48
|
+
createdAt: number,
|
|
49
|
+
conversationType: "standard" | "background" | "scheduled" = "standard",
|
|
50
|
+
): void {
|
|
45
51
|
const sqlite = getSqlite();
|
|
46
|
-
const convId = `conv-${createdAt}-${role}`;
|
|
52
|
+
const convId = `conv-${createdAt}-${role}-${conversationType}`;
|
|
47
53
|
sqlite
|
|
48
54
|
.prepare(
|
|
49
|
-
"INSERT OR IGNORE INTO conversations (id, created_at, updated_at) VALUES (?, ?, ?)",
|
|
55
|
+
"INSERT OR IGNORE INTO conversations (id, created_at, updated_at, conversation_type) VALUES (?, ?, ?, ?)",
|
|
50
56
|
)
|
|
51
|
-
.run(convId, createdAt, createdAt);
|
|
57
|
+
.run(convId, createdAt, createdAt, conversationType);
|
|
52
58
|
sqlite
|
|
53
59
|
.prepare(
|
|
54
60
|
"INSERT INTO messages (id, conversation_id, role, content, created_at) VALUES (?, ?, ?, ?, ?)",
|
|
55
61
|
)
|
|
56
|
-
.run(
|
|
62
|
+
.run(
|
|
63
|
+
`msg-${createdAt}-${role}-${conversationType}`,
|
|
64
|
+
convId,
|
|
65
|
+
role,
|
|
66
|
+
"[]",
|
|
67
|
+
createdAt,
|
|
68
|
+
);
|
|
57
69
|
}
|
|
58
70
|
|
|
59
71
|
/** Pile writes into the WAL (without checkpointing) so a truncating
|
|
@@ -186,16 +198,79 @@ describe("maybeRunDbMaintenance", () => {
|
|
|
186
198
|
// THEN it still runs, since only user activity gates it
|
|
187
199
|
expect(getMemoryCheckpoint(MAINTENANCE_CHECKPOINT_KEY)).toBe(String(now));
|
|
188
200
|
});
|
|
201
|
+
|
|
202
|
+
test("a recent user-role message in a background conversation does not keep maintenance deferred", async () => {
|
|
203
|
+
/** Background machinery persists user-role rows of its own — the
|
|
204
|
+
* memory-retrospective instruction message lands as `role: "user"` in a
|
|
205
|
+
* `background` conversation, and scheduled wake hints land in
|
|
206
|
+
* `scheduled` ones. On an always-on install those arrive around the
|
|
207
|
+
* clock, so counting them would starve maintenance forever. */
|
|
208
|
+
// GIVEN the human has been quiet past the quiet period
|
|
209
|
+
const now = Date.now();
|
|
210
|
+
insertMessage("user", now - (QUIET_PERIOD_MS + 60_000));
|
|
211
|
+
// AND background machinery wrote user-role rows just now
|
|
212
|
+
insertMessage("user", now - 60_000, "background");
|
|
213
|
+
insertMessage("user", now - 30_000, "scheduled");
|
|
214
|
+
|
|
215
|
+
// WHEN maintenance is considered
|
|
216
|
+
await maybeRunDbMaintenance(now);
|
|
217
|
+
|
|
218
|
+
// THEN it still runs — only interactive-conversation activity gates it
|
|
219
|
+
expect(getMemoryCheckpoint(MAINTENANCE_CHECKPOINT_KEY)).toBe(String(now));
|
|
220
|
+
});
|
|
189
221
|
});
|
|
190
222
|
|
|
191
|
-
describe("
|
|
223
|
+
describe("maybeRunPassiveWalCheckpoint", () => {
|
|
224
|
+
test("runs despite recent user activity — the passive pass has no quiet gate", async () => {
|
|
225
|
+
/** PASSIVE checkpoints block no readers or writers, so they must not be
|
|
226
|
+
* deferred by user activity; deferring them is what lets the WAL
|
|
227
|
+
* backlog grow on always-active installs. */
|
|
228
|
+
// GIVEN the user is active right now
|
|
229
|
+
const now = Date.now();
|
|
230
|
+
insertMessage("user", now - 1_000);
|
|
231
|
+
|
|
232
|
+
// WHEN the passive pass is considered
|
|
233
|
+
await maybeRunPassiveWalCheckpoint(now);
|
|
234
|
+
|
|
235
|
+
// THEN it runs and stamps its own checkpoint key
|
|
236
|
+
expect(getMemoryCheckpoint(PASSIVE_CHECKPOINT_KEY)).toBe(String(now));
|
|
237
|
+
// AND the truncating-maintenance key is untouched
|
|
238
|
+
expect(getMemoryCheckpoint(MAINTENANCE_CHECKPOINT_KEY)).toBeNull();
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
test("respects its own interval and skips when the last pass was recent", async () => {
|
|
242
|
+
const now = Date.now();
|
|
243
|
+
const recent = now - 60_000;
|
|
244
|
+
const { setMemoryCheckpoint } =
|
|
245
|
+
await import("../../../../persistence/checkpoints.js");
|
|
246
|
+
setMemoryCheckpoint(PASSIVE_CHECKPOINT_KEY, String(recent));
|
|
247
|
+
|
|
248
|
+
await maybeRunPassiveWalCheckpoint(now);
|
|
249
|
+
|
|
250
|
+
expect(getMemoryCheckpoint(PASSIVE_CHECKPOINT_KEY)).toBe(String(recent));
|
|
251
|
+
});
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
describe("applyConnectionPragmas", () => {
|
|
255
|
+
test("sets journal_size_limit so WAL resets shrink the file", () => {
|
|
256
|
+
/** Checkpointing alone never shrinks the WAL file; the size limit is what
|
|
257
|
+
* truncates it back after a burst. Pin that every connection carries it. */
|
|
258
|
+
const sqlite = getSqlite();
|
|
259
|
+
const row = sqlite.query("PRAGMA journal_size_limit").get() as {
|
|
260
|
+
journal_size_limit: number;
|
|
261
|
+
};
|
|
262
|
+
expect(row.journal_size_limit).toBe(67108864);
|
|
263
|
+
});
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
describe("getLastInteractiveUserMessageTimestamp", () => {
|
|
192
267
|
test("returns 0 when no user message exists", () => {
|
|
193
268
|
/** With only non-user rows present, there is no user activity to report. */
|
|
194
269
|
// GIVEN only an assistant message exists
|
|
195
270
|
insertMessage("assistant", Date.now());
|
|
196
271
|
|
|
197
272
|
// WHEN the last user message timestamp is read
|
|
198
|
-
const result =
|
|
273
|
+
const result = getLastInteractiveUserMessageTimestamp();
|
|
199
274
|
|
|
200
275
|
// THEN it reports 0 (no user activity)
|
|
201
276
|
expect(result).toBe(0);
|
|
@@ -211,7 +286,7 @@ describe("getLastUserMessageTimestamp", () => {
|
|
|
211
286
|
insertMessage("assistant", base);
|
|
212
287
|
|
|
213
288
|
// WHEN the last user message timestamp is read
|
|
214
|
-
const result =
|
|
289
|
+
const result = getLastInteractiveUserMessageTimestamp();
|
|
215
290
|
|
|
216
291
|
// THEN it returns the most recent user message, not the assistant row
|
|
217
292
|
expect(result).toBe(base - 5_000);
|
|
@@ -230,9 +305,28 @@ describe("getLastUserMessageTimestamp", () => {
|
|
|
230
305
|
insertMessage("user", base - 60 * 60 * 1000);
|
|
231
306
|
|
|
232
307
|
// WHEN the last user message timestamp is read
|
|
233
|
-
const result =
|
|
308
|
+
const result = getLastInteractiveUserMessageTimestamp();
|
|
234
309
|
|
|
235
310
|
// THEN it reports the genuinely most recent turn, not the last-inserted one
|
|
236
311
|
expect(result).toBe(base - 5_000);
|
|
237
312
|
});
|
|
313
|
+
|
|
314
|
+
test("ignores user-role rows in background and scheduled conversations", () => {
|
|
315
|
+
/** The memory-retrospective instruction message is persisted as
|
|
316
|
+
* `role: "user"` inside a `background` fork, and scheduled/heartbeat
|
|
317
|
+
* wake hints land in `scheduled`/`background` conversations — machine
|
|
318
|
+
* writes, not human activity. */
|
|
319
|
+
// GIVEN an older interactive user message
|
|
320
|
+
const base = Date.now();
|
|
321
|
+
insertMessage("user", base - 10_000);
|
|
322
|
+
// AND newer user-role rows written by background machinery
|
|
323
|
+
insertMessage("user", base - 5_000, "background");
|
|
324
|
+
insertMessage("user", base - 1_000, "scheduled");
|
|
325
|
+
|
|
326
|
+
// WHEN the last interactive user message timestamp is read
|
|
327
|
+
const result = getLastInteractiveUserMessageTimestamp();
|
|
328
|
+
|
|
329
|
+
// THEN only the interactive conversation's message counts
|
|
330
|
+
expect(result).toBe(base - 10_000);
|
|
331
|
+
});
|
|
238
332
|
});
|
|
@@ -10,8 +10,7 @@
|
|
|
10
10
|
// (`delete_qdrant_vectors`, `prune_*`) flow through unchanged.
|
|
11
11
|
//
|
|
12
12
|
// We verify (1) directly across the four config-shape variants, then
|
|
13
|
-
// smoke-test (2) at
|
|
14
|
-
// - `enqueueAutoAnalysisIfEnabled`
|
|
13
|
+
// smoke-test (2) at a central entry-point helper:
|
|
15
14
|
// - `enqueueMemoryRetrospectiveIfEnabled`
|
|
16
15
|
// Each call site re-checks `isMemoryEnabled()` itself, so we don't
|
|
17
16
|
// repeat 30+ identical scenarios — the helper test is the contract.
|
|
@@ -37,29 +36,19 @@ mock.module("../../../../config/loader.js", () => ({
|
|
|
37
36
|
if (memoryEnabled === null) return {};
|
|
38
37
|
return {
|
|
39
38
|
memory: { enabled: memoryEnabled, v2: { enabled: false } },
|
|
40
|
-
analysis: { idleTimeoutMs: 600_000, batchSize: 30 },
|
|
41
|
-
assistant: { featureFlags: { "auto-analyze": true } },
|
|
42
39
|
};
|
|
43
40
|
},
|
|
44
41
|
}));
|
|
45
42
|
|
|
46
|
-
// Stub
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
// Stub the conversation-source lookup so the recursion guards in the
|
|
52
|
-
// retrospective and auto-analysis paths fall through to the enqueue.
|
|
53
|
-
// `getConversation` returning null keeps `isLowYieldRetrospectiveSource`
|
|
54
|
-
// false, so the retrospective is enqueued rather than skipped.
|
|
43
|
+
// Stub the conversation-source lookup so the recursion guard in the
|
|
44
|
+
// retrospective path falls through to the enqueue. `getConversation`
|
|
45
|
+
// returning null keeps `isLowYieldRetrospectiveSource` false, so the
|
|
46
|
+
// retrospective is enqueued rather than skipped.
|
|
55
47
|
mock.module("../../../../persistence/conversation-crud.js", () => ({
|
|
56
48
|
getConversation: () => null,
|
|
57
49
|
getConversationSource: () => null,
|
|
58
50
|
reserveMessage: mock(async () => ({ id: "msg-reserve" })),
|
|
59
51
|
}));
|
|
60
|
-
mock.module("../../../../runtime/services/auto-analysis-guard.js", () => ({
|
|
61
|
-
isAutoAnalysisConversation: () => false,
|
|
62
|
-
}));
|
|
63
52
|
|
|
64
53
|
// Stub the qdrant breaker so `enqueueMemoryJob` doesn't trip on it.
|
|
65
54
|
mock.module(
|
|
@@ -122,8 +111,6 @@ mock.module("../../../../persistence/db-connection.js", () => ({
|
|
|
122
111
|
// Now load the real modules under test.
|
|
123
112
|
const { isMemoryEnabled } =
|
|
124
113
|
await import("../../../../persistence/jobs-store.js");
|
|
125
|
-
const { enqueueAutoAnalysisIfEnabled } =
|
|
126
|
-
await import("../../../../runtime/services/auto-analysis-enqueue.js");
|
|
127
114
|
const { enqueueMemoryRetrospectiveIfEnabled } =
|
|
128
115
|
await import("../memory-retrospective-enqueue.js");
|
|
129
116
|
|
|
@@ -162,55 +149,13 @@ describe("isMemoryEnabled", () => {
|
|
|
162
149
|
test("returns true (defensive) when getConfig throws", () => {
|
|
163
150
|
// If config can't be read, we can't tell whether memory has been
|
|
164
151
|
// disabled, so default to "enabled". Callers that already have their
|
|
165
|
-
// own getConfig try/catch
|
|
166
|
-
//
|
|
152
|
+
// own getConfig try/catch keep controlling the silent-failure
|
|
153
|
+
// semantic for the rest of their flow.
|
|
167
154
|
getConfigThrows = true;
|
|
168
155
|
expect(isMemoryEnabled()).toBe(true);
|
|
169
156
|
});
|
|
170
157
|
});
|
|
171
158
|
|
|
172
|
-
// ---------------------------------------------------------------------
|
|
173
|
-
// enqueueAutoAnalysisIfEnabled — representative entry-point helper
|
|
174
|
-
// ---------------------------------------------------------------------
|
|
175
|
-
|
|
176
|
-
describe("enqueueAutoAnalysisIfEnabled (call-site gate)", () => {
|
|
177
|
-
test("does NOT enqueue when memory.enabled is false", () => {
|
|
178
|
-
memoryEnabled = false;
|
|
179
|
-
enqueueAutoAnalysisIfEnabled({
|
|
180
|
-
conversationId: "conv-1",
|
|
181
|
-
trigger: "batch",
|
|
182
|
-
});
|
|
183
|
-
expect(dbInserts.length).toBe(0);
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
test("enqueues when memory.enabled is true", () => {
|
|
187
|
-
memoryEnabled = true;
|
|
188
|
-
enqueueAutoAnalysisIfEnabled({
|
|
189
|
-
conversationId: "conv-1",
|
|
190
|
-
trigger: "batch",
|
|
191
|
-
});
|
|
192
|
-
expect(dbInserts.length).toBeGreaterThan(0);
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
test("enqueues when memory.enabled is undefined (schema default)", () => {
|
|
196
|
-
memoryEnabled = undefined;
|
|
197
|
-
enqueueAutoAnalysisIfEnabled({
|
|
198
|
-
conversationId: "conv-1",
|
|
199
|
-
trigger: "batch",
|
|
200
|
-
});
|
|
201
|
-
expect(dbInserts.length).toBeGreaterThan(0);
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
test("enqueues when memory key is absent from config", () => {
|
|
205
|
-
memoryEnabled = null;
|
|
206
|
-
enqueueAutoAnalysisIfEnabled({
|
|
207
|
-
conversationId: "conv-1",
|
|
208
|
-
trigger: "batch",
|
|
209
|
-
});
|
|
210
|
-
expect(dbInserts.length).toBeGreaterThan(0);
|
|
211
|
-
});
|
|
212
|
-
});
|
|
213
|
-
|
|
214
159
|
// ---------------------------------------------------------------------
|
|
215
160
|
// enqueueMemoryRetrospectiveIfEnabled — representative entry-point
|
|
216
161
|
// ---------------------------------------------------------------------
|
|
@@ -1207,13 +1207,55 @@ describe("memoryRetrospectiveJob", () => {
|
|
|
1207
1207
|
expect(instructionText).not.toContain("(none)");
|
|
1208
1208
|
});
|
|
1209
1209
|
|
|
1210
|
-
test("prior fork-kind retrospective with
|
|
1211
|
-
//
|
|
1212
|
-
//
|
|
1213
|
-
//
|
|
1214
|
-
//
|
|
1210
|
+
test("prior fork-kind retrospective with an empty copied prefix attributes rows to the run", async () => {
|
|
1211
|
+
// Empty-prefix fork-kind prior (a tail-only fork whose inherited
|
|
1212
|
+
// compaction covered the whole cutoff range): no message carries
|
|
1213
|
+
// `forkSourceMessageId` and the conversation opens with the run's own
|
|
1214
|
+
// instruction row, so every row is the run's output and its saves feed
|
|
1215
|
+
// the dedup baseline.
|
|
1215
1216
|
priorRetroId = "prior-fork-retro-2";
|
|
1216
1217
|
|
|
1218
|
+
conversationOverrides[priorRetroId] = {
|
|
1219
|
+
source: "memory-retrospective-fork",
|
|
1220
|
+
forkParentMessageId: "m-src-2",
|
|
1221
|
+
};
|
|
1222
|
+
messagesByConversationId[priorRetroId] = [
|
|
1223
|
+
{
|
|
1224
|
+
role: "user",
|
|
1225
|
+
content: JSON.stringify([{ type: "text", text: "review the above" }]),
|
|
1226
|
+
createdAt: 900,
|
|
1227
|
+
metadata: JSON.stringify({
|
|
1228
|
+
kind: "memory_retrospective_instruction",
|
|
1229
|
+
hidden: true,
|
|
1230
|
+
}),
|
|
1231
|
+
},
|
|
1232
|
+
{
|
|
1233
|
+
role: "assistant",
|
|
1234
|
+
content: JSON.stringify([
|
|
1235
|
+
{
|
|
1236
|
+
type: "tool_use",
|
|
1237
|
+
name: "remember",
|
|
1238
|
+
input: { content: "empty-prefix save" },
|
|
1239
|
+
},
|
|
1240
|
+
]),
|
|
1241
|
+
createdAt: 1000,
|
|
1242
|
+
metadata: null,
|
|
1243
|
+
},
|
|
1244
|
+
];
|
|
1245
|
+
|
|
1246
|
+
await memoryRetrospectiveJob(makeJob(), stubConfig);
|
|
1247
|
+
|
|
1248
|
+
const instructionText = persistedInstructionText();
|
|
1249
|
+
expect(instructionText).toContain("- empty-prefix save");
|
|
1250
|
+
expect(instructionText).not.toContain("(none)");
|
|
1251
|
+
});
|
|
1252
|
+
|
|
1253
|
+
test("prior fork-kind retrospective with missing stamps degrades to empty dedup", async () => {
|
|
1254
|
+
// Stampless rows with no leading instruction row are indeterminate
|
|
1255
|
+
// (copied rows whose metadata lost its stamps): treating them as run
|
|
1256
|
+
// output would leak pre-fork content into the baseline.
|
|
1257
|
+
priorRetroId = "prior-fork-retro-3";
|
|
1258
|
+
|
|
1217
1259
|
conversationOverrides[priorRetroId] = {
|
|
1218
1260
|
source: "memory-retrospective-fork",
|
|
1219
1261
|
forkParentMessageId: "m-src-2",
|
|
@@ -438,18 +438,46 @@ describe("memory-retrospective skill card", () => {
|
|
|
438
438
|
expect(skills.map((s) => s.skillId)).toEqual(["tail-skill"]);
|
|
439
439
|
});
|
|
440
440
|
|
|
441
|
-
test("extractor
|
|
441
|
+
test("extractor attributes every row to a fork-kind run with an empty copied prefix", async () => {
|
|
442
|
+
// No stamps, and the conversation opens with the run's own instruction
|
|
443
|
+
// row: the copied prefix is empty, so the scaffold is the run's work.
|
|
442
444
|
conversationOverrides["retro-fork-2"] = {
|
|
443
445
|
source: "memory-retrospective-fork",
|
|
444
446
|
forkParentMessageId: null,
|
|
445
447
|
};
|
|
446
448
|
messagesByConversationId["retro-fork-2"] = [
|
|
449
|
+
{
|
|
450
|
+
role: "user",
|
|
451
|
+
content: JSON.stringify([{ type: "text", text: "review the above" }]),
|
|
452
|
+
createdAt: 900,
|
|
453
|
+
metadata: JSON.stringify({
|
|
454
|
+
kind: "memory_retrospective_instruction",
|
|
455
|
+
hidden: true,
|
|
456
|
+
}),
|
|
457
|
+
},
|
|
447
458
|
scaffoldMsg("tu-1", skillInput("skill-a"), { createdAt: 1000 }),
|
|
448
459
|
toolResultMsg("tu-1", { createdAt: 1100 }),
|
|
449
460
|
];
|
|
450
461
|
|
|
451
462
|
const skills = await extractRetrospectiveRunSkillScaffolds("retro-fork-2");
|
|
452
463
|
|
|
464
|
+
expect(skills.map((s) => s.skillId)).toEqual(["skill-a"]);
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
test("extractor degrades to empty for a stampless fork-kind run without a leading instruction row", async () => {
|
|
468
|
+
// Indeterminate shape (copied rows whose metadata lost its stamps):
|
|
469
|
+
// attributing it would surface source-authored scaffolds as run work.
|
|
470
|
+
conversationOverrides["retro-fork-3"] = {
|
|
471
|
+
source: "memory-retrospective-fork",
|
|
472
|
+
forkParentMessageId: null,
|
|
473
|
+
};
|
|
474
|
+
messagesByConversationId["retro-fork-3"] = [
|
|
475
|
+
scaffoldMsg("tu-1", skillInput("skill-a"), { createdAt: 1000 }),
|
|
476
|
+
toolResultMsg("tu-1", { createdAt: 1100 }),
|
|
477
|
+
];
|
|
478
|
+
|
|
479
|
+
const skills = await extractRetrospectiveRunSkillScaffolds("retro-fork-3");
|
|
480
|
+
|
|
453
481
|
expect(skills).toEqual([]);
|
|
454
482
|
});
|
|
455
483
|
|