feat: v2.6.0 — Chat UI composer (+ menu, project files, activity panel, permission mode, Stop), git on a workspace's extra folders (#70), long paste as a file (#68), S3 server mode (experimental)

Chat UI:
- Each Claude/Codex session keeps its own chat/terminal view; Settings only
  sets how new sessions open.
- Composer + menu: upload, project files and folders (#54, also dragged from
  the Files/Changes tree), context files, recent uploads, skills, plugins.
- Activity side panel (progress, outputs, files read, uploads, memory,
  skills, connectors) with a file preview; edited-file counts per turn.
- Permission-mode chip (Shift+Tab steps, read back from the pane:
  server/lib/pane-mode.js, GET|POST /api/run/:id/permission-mode).
- Stop (Esc) while the main agent works; the status is checked per agent
  (with session_id /api/agents ignores its status filter) and re-read every
  5 s while Stop shows.
- Dropped images shown in the conversation (GET /api/run/drop/:name, the
  requester's own drop dir), full-size viewer.
- A plain-text paste over 5,000 characters is attached as pasted-text.txt,
  so no prompt reaches tmux/argv limits (#68).

Changes panel: every /api/lanes/:id/git* route takes ?source=<lane_sources
id> (sourceFolder; ENOSOURCE otherwise) and a folder picker switches the
whole panel to a workspace's extra folder (#70).

Server mode S3 (one Linux user per account) — experimental, verified with
fake sudo plus a P6 managed-settings spike on a test account:
- member tmux listing runs in the background (cached, 15 s => unknown);
- transcript snapshot copy is async, chunked, temp file + rename;
- Express Layer patch only on Express 4;
- tmux capturePane/sendKey go to the member's own server.

Docs: the multi-user design moved in as docs/plans/server-mode/README.md
(the AgentHub-Server repo is gone); S3-PLAN P6 result; LANES/API/openapi.
This commit is contained in:
2026-10-09 15:51:19 +07:00
parent ce773a3f5a
commit fa156d6a59
114 changed files with 5831 additions and 885 deletions
+85
View File
@@ -3035,3 +3035,88 @@ describe("Nested Agent Spawning", () => {
);
});
});
describe("GET /api/sessions/:id/outline", () => {
it("reads progress, outputs and context off the session's tool events", async () => {
const sid = "outline-" + Date.now();
const pre = (tool_name, tool_input, tool_response) =>
post("/api/hooks/event", {
hook_type: "PostToolUse",
data: { session_id: sid, tool_name, tool_input, tool_response },
});
await post("/api/hooks/event", { hook_type: "SessionStart", data: { session_id: sid } });
await pre(
"TaskCreate",
{ subject: "Parse plan" },
{ task: { id: "1", subject: "Parse plan" } }
);
await pre(
"TaskCreate",
{ subject: "Parse plan" },
{ task: { id: "1", subject: "Parse plan" } }
);
await pre(
"TaskCreate",
{ subject: "Build report" },
{ task: { id: "2", subject: "Build report" } }
);
await pre("TaskUpdate", { taskId: "1", status: "completed" });
await pre("TaskUpdate", { taskId: "2", status: "in_progress" });
await pre("Write", { file_path: "/w/a.xlsx", content: "x" });
await pre("Write", { file_path: "/w/b.md", content: "x" });
await pre("Write", { file_path: "/w/a.xlsx", content: "y" });
await pre("Skill", { skill: "xlsx" });
await pre("Skill", { skill: "xlsx" });
await pre("mcp__plugin_vercel_vercel__list_projects", {});
const res = await fetch(`/api/sessions/${sid}/outline`);
assert.equal(res.status, 200);
assert.deepEqual(res.body.progress, [
{ id: "1", subject: "Parse plan", status: "completed" },
{ id: "2", subject: "Build report", status: "in_progress" },
]);
assert.deepEqual(res.body.outputs, ["/w/a.xlsx", "/w/b.md"]);
assert.deepEqual(res.body.skills, ["xlsx"]);
assert.deepEqual(res.body.mcp, ["vercel_vercel"]);
// A TodoWrite replaces the list wholesale.
await pre("TodoWrite", { todos: [{ content: "Verify", status: "pending" }] });
const again = await fetch(`/api/sessions/${sid}/outline`);
assert.deepEqual(again.body.progress, [{ id: "0", subject: "Verify", status: "pending" }]);
assert.equal((await fetch("/api/sessions/nope-outline/outline")).status, 404);
});
it("splits what a session used (uploads, files, memory) from what it changed", async () => {
const sid = "outline-used-" + Date.now();
const pre = (tool_name, tool_input) =>
post("/api/hooks/event", {
hook_type: "PostToolUse",
data: { session_id: sid, tool_name, tool_input, tool_response: {} },
});
const drop = "/tmp/agenthub-drops-1000/0123456789abcdef-minutes.xlsx";
await post("/api/hooks/event", { hook_type: "SessionStart", data: { session_id: sid } });
await post("/api/hooks/event", {
hook_type: "UserPromptSubmit",
data: {
session_id: sid,
prompt: `compare these ${drop}\n/tmp/agenthub-drops-1000/fedcba9876543210.png`,
},
});
const mem = "/home/u/.claude/projects/-w/memory/release.md";
await pre("Read", { file_path: drop });
await pre("Read", { file_path: "/w/src/a.ts" });
await pre("Read", { file_path: "/w/src/c.ts" });
await pre("Read", { file_path: mem });
await pre("Edit", { file_path: "/w/src/a.ts", old_string: "a", new_string: "b" });
await pre("MultiEdit", { file_path: "/w/src/b.ts", edits: [] });
await pre("Write", { file_path: mem, content: "x" });
const { body } = await fetch(`/api/sessions/${sid}/outline`);
assert.deepEqual(body.uploads, ["/tmp/agenthub-drops-1000/fedcba9876543210.png", drop]);
// a.ts was read, then edited: an output, no longer a file it only used.
assert.deepEqual(body.files, ["/w/src/c.ts"]);
assert.deepEqual(body.memory, [mem]);
assert.deepEqual(body.outputs, ["/w/src/b.ts", "/w/src/a.ts"]);
});
});
+64
View File
@@ -2017,6 +2017,70 @@ describe("a session's own worktree (claude --worktree)", () => {
});
});
describe("an extra folder's own repo (?source=)", () => {
const { execFileSync } = require("child_process");
const gitEnv = Object.fromEntries(
Object.entries(process.env).filter(([k]) => !k.startsWith("GIT_"))
);
const gitIn = (dir, ...args) =>
execFileSync("git", ["-C", dir, "-c", "user.name=t", "-c", "user.email=t@t", ...args], {
encoding: "utf8",
env: gitEnv,
});
let ws, extra, laneId, otherLaneId, sourceId, fileSourceId;
before(async () => {
const root = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), "lane-src-git-")));
ws = path.join(root, "ws");
extra = path.join(root, "extra");
for (const dir of [ws, extra]) {
fs.mkdirSync(dir);
gitIn(dir, "init", "-q", "-b", "main");
fs.writeFileSync(path.join(dir, "a.txt"), "a\n");
gitIn(dir, "add", ".");
gitIn(dir, "commit", "-qm", "init");
}
laneId = (await request("POST", "/api/lanes", { cwd: ws })).body.lane.id;
otherLaneId = (await request("POST", "/api/lanes", { cwd: extra })).body.lane.id;
const src = require("../lib/lane-sources");
sourceId = src.addFolder(laneId, extra).id;
fileSourceId = require("../db")
.db.prepare(
"INSERT INTO lane_sources (lane_id, kind, path, name, added_at) VALUES (?, 'file', ?, 'f', '2026-10-09T00:00:00Z')"
)
.run(laneId, path.join(extra, "a.txt")).lastInsertRowid;
});
it("reads and writes git in the extra folder, never falling back", async () => {
fs.writeFileSync(path.join(extra, "only-in-extra.txt"), "x\n");
const inExtra = await request("GET", `/api/lanes/${laneId}/git/changes?source=${sourceId}`);
assert.ok(inExtra.body.files.some((f) => f.path === "only-in-extra.txt"));
const facts = await request("GET", `/api/lanes/${laneId}/git?source=${sourceId}`);
assert.equal(facts.body.base, "main");
const main = await request("GET", `/api/lanes/${laneId}/git/changes`);
assert.ok(!main.body.files.some((f) => f.path === "only-in-extra.txt"));
const ok = await request("POST", `/api/lanes/${laneId}/git/stage?source=${sourceId}`, {
paths: ["only-in-extra.txt"],
});
assert.equal(ok.status, 200);
assert.match(gitIn(extra, "diff", "--cached", "--name-only"), /only-in-extra\.txt/);
});
it("answers ENOSOURCE for a source that is not this workspace's folder", async () => {
for (const id of ["nope", "999999", String(fileSourceId)]) {
const r = await request("POST", `/api/lanes/${laneId}/git/stage?source=${id}`, {
paths: ["only-in-extra.txt"],
});
assert.equal(r.status, 404, id);
assert.equal(r.body.error.code, "ENOSOURCE", id);
}
// Another workspace's request may not borrow this one's source id.
const r = await request("GET", `/api/lanes/${otherLaneId}/git/changes?source=${sourceId}`);
assert.equal(r.status, 404);
assert.equal(r.body.error.code, "ENOSOURCE");
});
});
// The server, not a stale client list, picks the tab and refuses a second pane
// on a session one already holds.
describe("start: slot auto and a session already live", () => {
+175 -2
View File
@@ -2,7 +2,8 @@
/**
* @file run.test.js
* @description Route tests for the terminal-run feature: same-origin guard,
* laneId/cwd validation, spawn/kill/list against a mocked tmux backend.
* laneId/cwd validation, spawn/kill/list against a mocked tmux backend, a
* dropped image served back, and a live pane's permission mode.
* @author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
*/
const { describe, it, before, after, beforeEach } = require("node:test");
@@ -55,7 +56,7 @@ function fetchJson(p, opts = {}) {
} catch {
parsed = raw;
}
resolve({ status: res.statusCode, body: parsed });
resolve({ status: res.statusCode, body: parsed, headers: res.headers });
});
}
);
@@ -209,6 +210,27 @@ describe("/api/run", () => {
});
});
describe("GET /api/run/files", () => {
let srv;
const DIR = path.join(TMP, "files-proj");
before(async () => {
fs.mkdirSync(path.join(DIR, "src", "lib"), { recursive: true });
fs.writeFileSync(path.join(DIR, "src", "lib", "a.js"), "");
srv = http.createServer(createApp());
await new Promise((r) => srv.listen(0, r));
BASE = `http://127.0.0.1:${srv.address().port}`;
});
after(() => new Promise((r) => srv.close(r)));
const list = async (qs) =>
(await fetchJson(`/api/run/files?cwd=${encodeURIComponent(DIR)}${qs}`)).body.items;
it("lists files only, unless dirs=1 adds the folders with a trailing slash", async () => {
assert.deepEqual(await list(""), ["src/lib/a.js"]);
assert.deepEqual(await list("&dirs=1"), ["src/", "src/lib/", "src/lib/a.js"]);
assert.deepEqual(await list("&dirs=1&q=lib"), ["src/lib/", "src/lib/a.js"]);
});
});
describe("POST /api/run/drop-image", () => {
let srv;
before(async () => {
@@ -274,3 +296,154 @@ describe("POST /api/run/drop-image", () => {
assert.equal(r.status, 400);
});
});
describe("GET /api/run/drop/:name", () => {
let srv;
before(async () => {
srv = http.createServer(createApp());
await new Promise((r) => srv.listen(0, r));
BASE = `http://127.0.0.1:${srv.address().port}`;
});
after(() => new Promise((r) => srv.close(r)));
const PNG = Buffer.from("89504e470d0a1a0a0000", "hex");
it("serves a dropped image back as an image that runs nothing", async () => {
const saved = await fetchJson("/api/run/drop-image", {
method: "POST",
raw: { type: "image/png", buf: PNG },
});
const r = await fetchJson(`/api/run/drop/${path.basename(saved.body.path)}`);
assert.equal(r.status, 200);
assert.equal(r.headers["content-type"], "image/png");
assert.equal(r.headers["x-content-type-options"], "nosniff");
assert.match(r.headers["content-security-policy"], /sandbox/);
fs.unlinkSync(saved.body.path);
});
it("serves no file that is not a dropped image", async () => {
const link = path.join(
os.tmpdir(),
`agenthub-drops-${os.userInfo().uid}`,
"fedcba9876543210.png"
);
fs.rmSync(link, { force: true });
fs.symlinkSync("/etc/passwd", link);
const pdf = await fetchJson("/api/run/drop-file?name=a.pdf", {
method: "POST",
raw: { type: "application/pdf", buf: Buffer.from("%PDF") },
});
for (const name of [
path.basename(pdf.body.path), // a drop, but no image
"0123456789abcdef.png", // the right shape, never dropped
"..%2F..%2Fetc%2Fpasswd",
"passwd.png", // no random prefix
"fedcba9876543210.png", // a link planted under a drop's name
]) {
const r = await fetchJson(`/api/run/drop/${name}`);
assert.equal(r.status, 404, name);
}
fs.unlinkSync(pdf.body.path);
fs.unlinkSync(link);
});
});
describe("/api/run/:id/permission-mode", () => {
let srv;
before(async () => {
srv = http.createServer(createApp());
await new Promise((r) => srv.listen(0, r));
BASE = `http://127.0.0.1:${srv.address().port}`;
});
after(() => new Promise((r) => srv.close(r)));
beforeEach(() => tmux.__reset());
// A live claude pane whose mode line follows Shift+Tab around Claude Code's cycle.
const LINES = {
default: " ⏸ manual mode on · ← for agents",
acceptEdits: " ⏵⏵ accept edits on (shift+tab to cycle) · ← for agents",
plan: " ⏸ plan mode on (shift+tab to cycle) · ← for agents",
auto: " ⏵⏵ auto mode on (shift+tab to cycle) · ← for agents",
};
function fakePane(start) {
const cycle = ["default", "acceptEdits", "plan", "auto"];
const state = { mode: start, presses: 0 };
tmux.__setExecImpl((args) => {
if (args[0] === "capture-pane") return `❯ \n${"─".repeat(20)}\n${LINES[state.mode]}\n`;
if (args[0] === "send-keys" && args.at(-1) === "BTab") {
state.presses++;
state.mode = cycle[(cycle.indexOf(state.mode) + 1) % cycle.length];
}
return "";
});
return state;
}
it("GET reads the mode off the pane", async () => {
fakePane("plan");
const r = await fetchJson("/api/run/agenthub-lane-9/permission-mode");
assert.equal(r.status, 200);
assert.equal(r.body.mode, "plan");
});
it("POST presses Shift+Tab until the pane shows the mode asked for", async () => {
const state = fakePane("default");
const r = await fetchJson("/api/run/agenthub-lane-9/permission-mode", {
method: "POST",
body: { mode: "auto" },
});
assert.equal(r.status, 200);
assert.equal(r.body.mode, "auto");
assert.equal(state.presses, 3);
});
it("POST of a mode not in the cycle ends where it started, and says so", async () => {
const state = fakePane("acceptEdits");
const r = await fetchJson("/api/run/agenthub-lane-9/permission-mode", {
method: "POST",
body: { mode: "bypassPermissions" },
});
assert.equal(r.status, 409);
assert.equal(r.body.error.code, "EMODEUNAVAILABLE");
assert.equal(state.mode, "acceptEdits");
});
it("POST presses nothing when the mode line cannot be read", async () => {
let presses = 0;
tmux.__setExecImpl((args) => {
if (args[0] === "capture-pane") return "Select model\n❯ 1. Default\n";
if (args[0] === "send-keys") presses++;
return "";
});
const r = await fetchJson("/api/run/agenthub-lane-9/permission-mode", {
method: "POST",
body: { mode: "plan" },
});
assert.equal(r.status, 409);
assert.equal(r.body.error.code, "EMODEUNKNOWN");
assert.equal(presses, 0);
});
it("POST refuses a mode outside the allowlist", async () => {
fakePane("default");
const r = await fetchJson("/api/run/agenthub-lane-9/permission-mode", {
method: "POST",
body: { mode: "dontAsk; rm -rf ~" },
});
assert.equal(r.status, 400);
assert.equal(r.body.error.code, "EBADMODE");
});
it("answers 404 for a pane that is not running", async () => {
tmux.__setExecImpl((args) => {
if (args[0] === "has-session") {
const e = new Error("gone");
e.status = 1;
throw e;
}
return "";
});
const r = await fetchJson("/api/run/agenthub-lane-999/permission-mode");
assert.equal(r.status, 404);
});
});
@@ -185,6 +185,15 @@ describe("server mode", () => {
body: { prefs: { "agenthub.chatUi": null } },
});
assert.deepEqual((await call("GET", "/api/me/prefs", { cookie: boss })).body.prefs, {});
// The appearance (useTheme's storage keys) follows the account too.
const look = {
theme: "light",
"agenthub.theme.light": "canvas",
"agenthub.theme.dark": "darcula",
};
const saved = await call("PUT", "/api/me/prefs", { cookie: ana, body: { prefs: look } });
assert.equal(saved.status, 200);
assert.deepEqual(saved.body.prefs, look);
});
it("checks a WebSocket upgrade's login and Origin", async () => {
@@ -143,6 +143,12 @@ describe("server mode", () => {
assert.equal((await get("/api/lanes", "alice")).counts.total, 1);
assert.deepEqual(await laneIds("boss"), [LANE_A, LANE_B]);
assert.deepEqual(await laneIds("ana"), [LANE_A, LANE_B]);
// Each carries its owner's name, for the staff sidebar's per-user groups.
const owners = (await get("/api/lanes", "ana")).lanes.map((l) => [l.id, l.owner_name]);
assert.deepEqual(owners.sort(), [
[LANE_A, "alice"],
[LANE_B, "bob"],
]);
assert.deepEqual(
(await get("/api/workspaces", "bob")).lanes.map((l) => l.id),
[LANE_B]
+4 -1
View File
@@ -461,7 +461,10 @@ describe("a member's huge or sparse files", () => {
assert.equal(renames, 1);
const copy = path.join(getTranscriptSnapshotDir(), `${sid}.jsonl`);
assert.ok(fs.readFileSync(copy).equals(fs.readFileSync(src)));
assert.ok(warned.some((w) => w.includes("agent-x.jsonl")), JSON.stringify(warned));
assert.ok(
warned.some((w) => w.includes("agent-x.jsonl")),
JSON.stringify(warned)
);
assert.deepEqual(
fs.readdirSync(getTranscriptSnapshotDir()).filter((f) => f.endsWith(".tmp")),
[]
@@ -414,3 +414,47 @@ describe("GET /:id/transcript — mid-turn queued user messages (attachment/queu
assert.equal(bySnippet("and update the docs").sender, "user");
});
});
describe("GET /:id/transcript — what the chat needs to show live work", () => {
it("carries each assistant line's stop_reason and an edit result's +/- lines", async () => {
const cwd = "/tmp/cam-live-work";
const sid = "cccc1111-2222-3333-4444-555566667777";
writeTranscript(cwd, sid, [
{ type: "user", message: { role: "user", content: "fix it" } },
{
type: "assistant",
message: {
role: "assistant",
stop_reason: "tool_use",
content: [{ type: "tool_use", id: "e1", name: "Edit", input: { file_path: "/w/a.ts" } }],
},
},
{
type: "user",
message: {
role: "user",
content: [{ type: "tool_result", tool_use_id: "e1", content: "ok" }],
},
toolUseResult: {
filePath: "/w/a.ts",
structuredPatch: [{ lines: [" a", "-b", "+c", "+d"] }],
},
},
{
type: "assistant",
message: {
role: "assistant",
stop_reason: "end_turn",
content: [{ type: "text", text: "done" }],
},
},
]);
await req("POST", "/api/sessions", { id: sid, cwd });
const { body } = await req("GET", `/api/sessions/${sid}/transcript?limit=200`);
const [, call, result, done] = body.messages;
assert.equal(call.stop_reason, "tool_use");
assert.equal(done.stop_reason, "end_turn");
assert.deepEqual(result.content[0].diff, { added: 2, removed: 1 });
});
});
+33 -1
View File
@@ -18,7 +18,7 @@ const fs = require("node:fs");
const TEST_DB = path.join(os.tmpdir(), `transcript-sender-${Date.now()}-${process.pid}.db`);
process.env.DASHBOARD_DB_PATH = TEST_DB;
const { classifyTranscriptSender } = require("../routes/sessions");
const { classifyTranscriptSender, patchCounts } = require("../routes/sessions");
const { db } = require("../db");
after(() => {
@@ -136,3 +136,35 @@ describe("classifyTranscriptSender — subagent transcript", () => {
assert.equal(classifyTranscriptSender(assistant(), true), "assistant");
});
});
describe("patchCounts — the +/- lines of a Write/Edit result", () => {
it("counts a structuredPatch's added and removed lines, not its context", () => {
const r = {
filePath: "/w/a.ts",
structuredPatch: [
{
oldStart: 1,
oldLines: 3,
newStart: 1,
newLines: 4,
lines: [" a", "-b", "+c", "+d", " e"],
},
{ oldStart: 9, oldLines: 1, newStart: 10, newLines: 0, lines: ["-z"] },
],
};
assert.deepEqual(patchCounts(r), { added: 2, removed: 2 });
});
it("counts a created file's lines as added", () => {
assert.deepEqual(patchCounts({ type: "create", content: "a\nb\nc\n", structuredPatch: [] }), {
added: 3,
removed: 0,
});
});
it("answers null for a result that is no edit", () => {
assert.equal(patchCounts({ stdout: "ok" }), null);
assert.equal(patchCounts("text"), null);
assert.equal(patchCounts(undefined), null);
});
});