summaryrefslogtreecommitdiffhomepage
path: root/packages/transport-contract/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/transport-contract/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/transport-contract/src')
-rw-r--r--packages/transport-contract/src/contract.types.test.ts118
-rw-r--r--packages/transport-contract/src/index.ts43
2 files changed, 161 insertions, 0 deletions
diff --git a/packages/transport-contract/src/contract.types.test.ts b/packages/transport-contract/src/contract.types.test.ts
new file mode 100644
index 0000000..da7e1e0
--- /dev/null
+++ b/packages/transport-contract/src/contract.types.test.ts
@@ -0,0 +1,118 @@
+/**
+ * Compile-time assertions for transport-contract types.
+ *
+ * These are never executed — they exist solely to prove the exported types
+ * compile with conforming literals. If a shape changes, this file fails to
+ * typecheck.
+ */
+
+import { describe, expect, it } from "vitest";
+import type {
+ CwdResponse,
+ LspServerInfo,
+ LspServerState,
+ LspStatusResponse,
+ SetCwdRequest,
+} from "./index.js";
+
+// ─── CwdResponse ─────────────────────────────────────────────────────────────
+
+const _cwdNull: CwdResponse = {
+ conversationId: "conv-1",
+ cwd: null,
+};
+
+const _cwdSet: CwdResponse = {
+ conversationId: "conv-2",
+ cwd: "/home/user/project",
+};
+
+// ─── SetCwdRequest ───────────────────────────────────────────────────────────
+
+const _setCwd: SetCwdRequest = {
+ cwd: "/tmp/workspace",
+};
+
+// ─── LspServerState ──────────────────────────────────────────────────────────
+
+const _stateConnected: LspServerState = "connected";
+const _stateStarting: LspServerState = "starting";
+const _stateError: LspServerState = "error";
+const _stateNotStarted: LspServerState = "not-started";
+
+// ─── LspServerInfo ───────────────────────────────────────────────────────────
+
+const _serverOk: LspServerInfo = {
+ id: "typescript",
+ name: "TypeScript Language Server",
+ root: "/home/user/project",
+ extensions: [".ts", ".tsx"],
+ state: "connected",
+};
+
+const _serverErr: LspServerInfo = {
+ id: "luau-lsp",
+ name: "Luau LSP",
+ root: "/home/user/game",
+ extensions: [".luau"],
+ state: "error",
+ error: "Failed to start: binary not found",
+};
+
+// ─── LspStatusResponse ───────────────────────────────────────────────────────
+
+const _lspNoCwd: LspStatusResponse = {
+ conversationId: "conv-3",
+ cwd: null,
+ servers: [],
+};
+
+const _lspWithServers: LspStatusResponse = {
+ conversationId: "conv-4",
+ cwd: "/home/user/project",
+ servers: [_serverOk, _serverErr],
+};
+
+// ─── Runtime smoke (vitest needs a suite) ────────────────────────────────────
+
+describe("transport-contract types compile and are exported", () => {
+ it("CwdResponse: null cwd round-trips", () => {
+ expect(_cwdNull).toEqual({ conversationId: "conv-1", cwd: null });
+ });
+
+ it("CwdResponse: set cwd round-trips", () => {
+ expect(_cwdSet.cwd).toBe("/home/user/project");
+ });
+
+ it("SetCwdRequest: carries cwd", () => {
+ expect(_setCwd.cwd).toBe("/tmp/workspace");
+ });
+
+ it("LspServerState: all four variants are valid", () => {
+ const states: LspServerState[] = [
+ _stateConnected,
+ _stateStarting,
+ _stateError,
+ _stateNotStarted,
+ ];
+ expect(states).toHaveLength(4);
+ });
+
+ it("LspServerInfo: ok server has no error field", () => {
+ expect(_serverOk.state).toBe("connected");
+ expect(_serverOk.error).toBeUndefined();
+ });
+
+ it("LspServerInfo: error server carries error message", () => {
+ expect(_serverErr.state).toBe("error");
+ expect(_serverErr.error).toBe("Failed to start: binary not found");
+ });
+
+ it("LspStatusResponse: empty servers when cwd is null", () => {
+ expect(_lspNoCwd.servers).toEqual([]);
+ });
+
+ it("LspStatusResponse: populated servers when cwd is set", () => {
+ expect(_lspWithServers.servers).toHaveLength(2);
+ });
+});
diff --git a/packages/transport-contract/src/index.ts b/packages/transport-contract/src/index.ts
index 95111ae..f0e50f8 100644
--- a/packages/transport-contract/src/index.ts
+++ b/packages/transport-contract/src/index.ts
@@ -154,6 +154,49 @@ export interface ThroughputResponse {
readonly models: readonly ThroughputModelStat[];
}
+// ─── Per-conversation working directory (cwd) ─────────────────────────────────
+
+/** Response of `GET /conversations/:id/cwd`. `cwd` is null when never set. */
+export interface CwdResponse {
+ readonly conversationId: string;
+ readonly cwd: string | null;
+}
+
+/** Body of `PUT /conversations/:id/cwd`. */
+export interface SetCwdRequest {
+ readonly cwd: string;
+}
+
+// ─── Per-conversation LSP status ──────────────────────────────────────────────
+
+/** The connection state of a single language server for a workspace. */
+export type LspServerState = "connected" | "starting" | "error" | "not-started";
+
+/** One language server's status as reported to the frontend. */
+export interface LspServerInfo {
+ /** Stable server id, e.g. "typescript", "luau-lsp". */
+ readonly id: string;
+ /** Human-readable display name. */
+ readonly name: string;
+ /** The resolved workspace root the server is (or would be) rooted at (absolute). */
+ readonly root: string;
+ /** File extensions this server handles, e.g. [".ts", ".tsx"] or [".luau"]. */
+ readonly extensions: readonly string[];
+ /** Current connection state. */
+ readonly state: LspServerState;
+ /** Present only when `state === "error"`: a short human-readable reason. */
+ readonly error?: string;
+}
+
+/** Response of `GET /conversations/:id/lsp`. */
+export interface LspStatusResponse {
+ readonly conversationId: string;
+ /** The conversation's persisted cwd, or null if unset (then `servers` is empty). */
+ readonly cwd: string | null;
+ /** The language servers configured for `cwd` and their live state. */
+ readonly servers: readonly LspServerInfo[];
+}
+
/**
* Request body for `POST /chat/warm` — manually trigger a prompt-cache WARMING
* request for a conversation (e.g. a frontend "warm now" button, or fast tests