feat(daemon): serve a live-only prompt-history read
The web composer's ↑/↓ recall needs the plugin's prompt history, so the browser
and nvim walk one list instead of two. The daemon relays it and stores nothing:
it is a router, and the plugin stays the authority (AGENTS.md rule 2).
- plugin `hello` advertises the new `promptHistory` capability; the daemon never
relays the read to a plugin that did not advertise it
- `workspace.query{kind:"promptHistory",limit}` is answered by the plugin from
its own `prompt.history` archive (workspace cwd), oldest-first
- `GET /api/v1/workspaces/:id/prompt-history?limit=` → `{v, workspaceId, live,
supported, entries}`; `limit` defaults to 200 and clamps to 500, an unknown
workspace is a 404, and malformed entries are dropped
- the read deliberately does **not** call `instances.ensure()`: recall is a
keystroke, not a lifecycle event, so a workspace with no connected plugin
answers `{live:false, supported:false, entries:[]}` instead of booting an nvim
- `PluginConnection.capabilities` joins the interface the daemon sees, and the
fake connection grows a writable one so the gate is testable
No event or reducer change: `fixtures/` are untouched.
This commit is contained in:
1 parent
c24f30fe71
commit
32292873f9
6 files changed
+204
No files matched your search
@@ -281,6 +281,96 @@ describe("HTTP API", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("relays prompt history to a capable live instance without a session id", async () => {
|
||||
conn.commandHandler = async (call) => {
|
||||
if (call.method === "workspace.query" && call.params?.kind === "promptHistory") {
|
||||
return { seq: 1, disposition: "started", entries: ["oldest", "newest"] } as never;
|
||||
}
|
||||
return { seq: 1, disposition: "started" };
|
||||
};
|
||||
|
||||
const res = await fetch(`${h.url}/api/v1/workspaces/ws-1/prompt-history?limit=50`, authed());
|
||||
expect(res.status).toBe(200);
|
||||
expect(await res.json()).toEqual({
|
||||
v: 1,
|
||||
workspaceId: "ws-1",
|
||||
live: true,
|
||||
supported: true,
|
||||
entries: ["oldest", "newest"],
|
||||
});
|
||||
|
||||
const call = conn.commands.find((c) => c.params?.kind === "promptHistory");
|
||||
expect(call?.method).toBe("workspace.query");
|
||||
expect(call?.params).toEqual({ kind: "promptHistory", limit: 50 });
|
||||
// Workspace-scoped: the read is not about one session.
|
||||
expect(call).not.toHaveProperty("sessionId");
|
||||
expect(h.instances.ensureCalls).toEqual([]);
|
||||
});
|
||||
|
||||
it("answers empty prompt history without spawning an instance", async () => {
|
||||
// No connection at all: the read must not call `instances.ensure()`.
|
||||
h.instances.instances.delete("ws-1");
|
||||
h.instances.states.delete("ws-1");
|
||||
|
||||
const res = await fetch(`${h.url}/api/v1/workspaces/ws-1/prompt-history`, authed());
|
||||
expect(res.status).toBe(200);
|
||||
expect(await res.json()).toEqual({ v: 1, workspaceId: "ws-1", live: false, supported: false, entries: [] });
|
||||
expect(h.instances.ensureCalls).toEqual([]);
|
||||
expect(conn.commands).toHaveLength(0);
|
||||
});
|
||||
|
||||
it("skips the relay for a live instance without the promptHistory capability", async () => {
|
||||
conn.capabilities = ["snapshot", "attention"];
|
||||
|
||||
const res = await fetch(`${h.url}/api/v1/workspaces/ws-1/prompt-history`, authed());
|
||||
expect(res.status).toBe(200);
|
||||
expect(await res.json()).toEqual({ v: 1, workspaceId: "ws-1", live: true, supported: false, entries: [] });
|
||||
expect(conn.commands).toHaveLength(0);
|
||||
expect(h.instances.ensureCalls).toEqual([]);
|
||||
});
|
||||
|
||||
it("404s prompt history for an unknown workspace", async () => {
|
||||
const res = await fetch(`${h.url}/api/v1/workspaces/ws-nope/prompt-history`, authed());
|
||||
expect(res.status).toBe(404);
|
||||
expect(((await res.json()) as { code: string }).code).toBe(ERROR_CODES.NOT_FOUND);
|
||||
expect(conn.commands).toHaveLength(0);
|
||||
});
|
||||
|
||||
it("clamps the prompt-history limit and keeps the newest entries", async () => {
|
||||
const all = Array.from({ length: 600 }, (_, i) => `e${i}`);
|
||||
conn.commandHandler = async () => ({ seq: 1, disposition: "started", entries: all }) as never;
|
||||
|
||||
const res = await fetch(`${h.url}/api/v1/workspaces/ws-1/prompt-history?limit=9999`, authed());
|
||||
expect(res.status).toBe(200);
|
||||
const body = (await res.json()) as { entries: string[] };
|
||||
|
||||
expect(conn.commands[0]?.params).toEqual({ kind: "promptHistory", limit: 500 });
|
||||
expect(body.entries).toHaveLength(500);
|
||||
// Oldest-first on the wire, so the tail is the recent end.
|
||||
expect(body.entries[0]).toBe("e100");
|
||||
expect(body.entries.at(-1)).toBe("e599");
|
||||
|
||||
// A garbage limit is ignored and the documented default applies.
|
||||
conn.commands = [];
|
||||
await fetch(`${h.url}/api/v1/workspaces/ws-1/prompt-history?limit=lots`, authed());
|
||||
expect(conn.commands[0]?.params).toEqual({ kind: "promptHistory", limit: 200 });
|
||||
});
|
||||
|
||||
it("normalizes a malformed prompt-history ack", async () => {
|
||||
conn.commandHandler = async () =>
|
||||
({ seq: 1, disposition: "started", entries: ["keep", 7, null, "", " ", "also"] }) as never;
|
||||
|
||||
const res = await fetch(`${h.url}/api/v1/workspaces/ws-1/prompt-history`, authed());
|
||||
expect(res.status).toBe(200);
|
||||
expect(((await res.json()) as { entries: string[] }).entries).toEqual(["keep", "also"]);
|
||||
|
||||
// A missing `entries` degrades to an empty list, never an error.
|
||||
conn.commandHandler = async () => ({ seq: 1, disposition: "started" });
|
||||
const bare = await fetch(`${h.url}/api/v1/workspaces/ws-1/prompt-history`, authed());
|
||||
expect(bare.status).toBe(200);
|
||||
expect(((await bare.json()) as { entries: string[] }).entries).toEqual([]);
|
||||
});
|
||||
|
||||
it("serves the disk-projected recent-session feed for the activity column", async () => {
|
||||
h.workspaces.recentSessionRows = [
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user