summaryrefslogtreecommitdiffhomepage
path: root/packages/conversation-store/src
diff options
context:
space:
mode:
authorAdam Malczewski <[email protected]>2026-06-11 21:12:03 +0900
committerAdam Malczewski <[email protected]>2026-06-11 21:12:03 +0900
commite7eada4802ceebd86c83bcd6e3eca70152e7f331 (patch)
tree447095fd60b43980358d1565506f3ae2430e5f29 /packages/conversation-store/src
parent35937cee7f838e414eb8147c67205e01d85a4da0 (diff)
downloaddispatch-e7eada4802ceebd86c83bcd6e3eca70152e7f331.tar.gz
dispatch-e7eada4802ceebd86c83bcd6e3eca70152e7f331.zip
feat(lsp,cwd): LSP integration + per-conversation cwd; fix cache-warming cache bust
LSP + per-conversation CWD feature: - new bundled `lsp` extension: hand-rolled JSON-RPC codec (framing/rpc), lazy one-server-per-(serverID,root), per-cwd config resolution, on-demand `lsp` tool - `conversation-store`: getCwd/setCwd (cwdKey); `session-orchestrator` defaults a turn's cwd from the store - `transport-http`: cwd + lsp status endpoints; wire types in transport-contract - host-bin: register lsp; config wiring Cache-warming fix (the warm read 0% on the first reheat after a message): - warm assembled tools under a different cwd than the real turn (a reheat sends no cwd, and the warm service had no store fallback). The skills filter rewrites the cwd-sensitive `load_skill` description, so the tools block — the first bytes of the prompt-cache prefix — diverged and the cache missed entirely. Warm now resolves cwd as opts.cwd ?? conversationStore.getCwd(), mirroring handleMessage. - capture warm sends as `provider.request` spans flagged `warm:true` (thread a child logger into providerOpts) so warm vs real bodies are diffable (obs §3.1). - kernel logger: span-close now merges child-bound attrs like span-open, so a `warm:true` query finds the closed span (with usage/status), not just the open. Tests: warm forwards a warm-flagged logger; warm falls back to stored cwd; logger open/close attr consistency. Full suite green (873).
Diffstat (limited to 'packages/conversation-store/src')
-rw-r--r--packages/conversation-store/src/keys.ts4
-rw-r--r--packages/conversation-store/src/store.test.ts46
-rw-r--r--packages/conversation-store/src/store.ts16
3 files changed, 66 insertions, 0 deletions
diff --git a/packages/conversation-store/src/keys.ts b/packages/conversation-store/src/keys.ts
index 0ba25d8..e7204db 100644
--- a/packages/conversation-store/src/keys.ts
+++ b/packages/conversation-store/src/keys.ts
@@ -45,3 +45,7 @@ export function parseMetricsOrdinal(key: string): number {
const n = Number.parseInt(last, 10);
return Number.isNaN(n) ? -1 : n;
}
+
+export function cwdKey(conversationId: string): string {
+ return `conv:${conversationId}:cwd`;
+}
diff --git a/packages/conversation-store/src/store.test.ts b/packages/conversation-store/src/store.test.ts
index a82b4cc..49b0e58 100644
--- a/packages/conversation-store/src/store.test.ts
+++ b/packages/conversation-store/src/store.test.ts
@@ -750,3 +750,49 @@ describe("ConversationStore reconcile.repair span", () => {
}
});
});
+
+describe("ConversationStore cwd", () => {
+ let storage: StorageNamespace;
+
+ beforeEach(() => {
+ storage = createMemoryStorage();
+ });
+
+ it("setCwd then getCwd returns the value", async () => {
+ const store = createConversationStore(storage);
+ await store.setCwd("conv1", "/home/user/project");
+ const result = await store.getCwd("conv1");
+ expect(result).toBe("/home/user/project");
+ });
+
+ it("getCwd returns null when never set", async () => {
+ const store = createConversationStore(storage);
+ const result = await store.getCwd("conv_unknown");
+ expect(result).toBeNull();
+ });
+
+ it("setCwd is an upsert (second set overwrites)", async () => {
+ const store = createConversationStore(storage);
+ await store.setCwd("conv1", "/first/path");
+ await store.setCwd("conv1", "/second/path");
+ const result = await store.getCwd("conv1");
+ expect(result).toBe("/second/path");
+ });
+
+ it("cwd persists across a fresh store instance on the same db file", async () => {
+ const store1 = createConversationStore(storage);
+ await store1.setCwd("conv1", "/persisted/path");
+
+ const store2 = createConversationStore(storage);
+ const result = await store2.getCwd("conv1");
+ expect(result).toBe("/persisted/path");
+ });
+
+ it("cwd of one conversation does not leak into another", async () => {
+ const store = createConversationStore(storage);
+ await store.setCwd("convA", "/path/a");
+ await store.setCwd("convB", "/path/b");
+ expect(await store.getCwd("convA")).toBe("/path/a");
+ expect(await store.getCwd("convB")).toBe("/path/b");
+ });
+});
diff --git a/packages/conversation-store/src/store.ts b/packages/conversation-store/src/store.ts
index 6b91d58..0948f64 100644
--- a/packages/conversation-store/src/store.ts
+++ b/packages/conversation-store/src/store.ts
@@ -11,6 +11,7 @@ import { defineService } from "@dispatch/kernel";
import {
chunkKey,
chunkPrefix,
+ cwdKey,
metricsKey,
metricsPrefix,
metricsSeqKey,
@@ -28,6 +29,10 @@ export interface ConversationStore {
) => Promise<readonly StoredChunk[]>;
readonly appendMetrics: (conversationId: string, metrics: TurnMetrics) => Promise<void>;
readonly loadMetrics: (conversationId: string) => Promise<readonly TurnMetrics[]>;
+ /** The persisted working directory for a conversation, or null if never set. */
+ readonly getCwd: (conversationId: string) => Promise<string | null>;
+ /** Persist (upsert) the working directory for a conversation. */
+ readonly setCwd: (conversationId: string, cwd: string) => Promise<void>;
}
export const conversationStoreHandle = defineService<ConversationStore>("conversation-store/store");
@@ -154,5 +159,16 @@ export function createConversationStore(
return result;
},
+
+ async getCwd(conversationId) {
+ return await storage.get(cwdKey(conversationId));
+ },
+
+ async setCwd(conversationId, cwd) {
+ await storage.set(cwdKey(conversationId), cwd);
+ if (logger !== undefined) {
+ logger.debug("cwd set", { conversationId });
+ }
+ },
};
}