feat: add multi-session desktop workspace
This commit is contained in:
@@ -18,11 +18,16 @@ function connect(socketPath) {
|
||||
function request(socket, frame) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let buffer = "";
|
||||
const onError = (error) => {
|
||||
socket.off("data", onData);
|
||||
reject(error);
|
||||
};
|
||||
const onData = (chunk) => {
|
||||
buffer += chunk;
|
||||
const newline = buffer.indexOf("\n");
|
||||
if (newline === -1) return;
|
||||
socket.off("data", onData);
|
||||
socket.off("error", onError);
|
||||
try {
|
||||
resolve(JSON.parse(buffer.slice(0, newline)));
|
||||
} catch (error) {
|
||||
@@ -30,7 +35,7 @@ function request(socket, frame) {
|
||||
}
|
||||
};
|
||||
socket.on("data", onData);
|
||||
socket.once("error", reject);
|
||||
socket.once("error", onError);
|
||||
socket.write(`${JSON.stringify(frame)}\n`);
|
||||
});
|
||||
}
|
||||
@@ -89,6 +94,32 @@ test("starts the home agent and dispatches local protocol requests to the select
|
||||
payload: { worktreePath: feature },
|
||||
});
|
||||
const featureAgent = selected.result.agent;
|
||||
const workspace = await request(socket, {
|
||||
version: "v1",
|
||||
id: "workspace-1",
|
||||
op: "get_workspace",
|
||||
});
|
||||
const summary = await request(socket, {
|
||||
version: "v1",
|
||||
id: "summary-1",
|
||||
op: "get_workspace_summary",
|
||||
});
|
||||
assert.equal(typeof workspace.result.bridgeInstanceId, "string");
|
||||
assert.equal(workspace.result.directories.length, 2);
|
||||
assert.equal(summary.result.openCount, 2);
|
||||
assert.equal(summary.result.directoryCount, 2);
|
||||
assert.equal(summary.result.resourceWarning, false);
|
||||
const snapshot = await request(socket, {
|
||||
version: "v1",
|
||||
id: "snapshot-1",
|
||||
op: "get_session_runtime_snapshot",
|
||||
payload: { runtimeId: featureAgent.runtimeId },
|
||||
});
|
||||
assert.equal(snapshot.result.runtime.runtimeId, featureAgent.runtimeId);
|
||||
assert.equal(
|
||||
snapshot.result.bridgeInstanceId,
|
||||
workspace.result.bridgeInstanceId,
|
||||
);
|
||||
const prompt = await request(socket, {
|
||||
version: "v1",
|
||||
id: "prompt-1",
|
||||
@@ -98,18 +129,48 @@ test("starts the home agent and dispatches local protocol requests to the select
|
||||
});
|
||||
|
||||
assert.equal(prompt.ok, true);
|
||||
const named = await request(socket, {
|
||||
version: "v1",
|
||||
id: "name-1",
|
||||
op: "set_session_name",
|
||||
agentId: featureAgent.id,
|
||||
payload: { name: "Feature work" },
|
||||
});
|
||||
const compacted = await request(socket, {
|
||||
version: "v1",
|
||||
id: "compact-1",
|
||||
op: "compact",
|
||||
agentId: featureAgent.id,
|
||||
payload: { customInstructions: "Preserve tests" },
|
||||
});
|
||||
assert.equal(named.ok, true);
|
||||
assert.equal(compacted.ok, true);
|
||||
assert.deepEqual(
|
||||
fixture.calls.map(({ options }) => options.cwd),
|
||||
[home, feature],
|
||||
);
|
||||
assert.deepEqual(fixture.calls[1].adapter.sent, [
|
||||
{ type: "get_state" },
|
||||
{ type: "get_state" },
|
||||
{ type: "get_session_stats" },
|
||||
{ type: "get_messages" },
|
||||
{ type: "get_commands" },
|
||||
{ type: "get_available_models" },
|
||||
{ type: "prompt", message: "Use this worktree" },
|
||||
{ type: "set_session_name", name: "Feature work" },
|
||||
{ type: "compact", customInstructions: "Preserve tests" },
|
||||
]);
|
||||
fixture.calls[1].options.onEvent({
|
||||
type: "agent_state",
|
||||
data: { state: "idle" },
|
||||
});
|
||||
const closed = await request(socket, {
|
||||
version: "v1",
|
||||
id: "close-1",
|
||||
op: "close_session_runtime",
|
||||
payload: { runtimeId: featureAgent.runtimeId },
|
||||
});
|
||||
assert.equal(closed.ok, true);
|
||||
|
||||
const forgotten = await request(socket, {
|
||||
version: "v1",
|
||||
|
||||
Reference in New Issue
Block a user