@a-t-h-i/bot-lobby 0.6.69 → 0.6.71

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -42,7 +42,6 @@ naming the file it came from.
42
42
  | `webui/src/app/code/CodeSurface.tsx` | `apps/web/src/components/files/FilePreviewPanel.tsx` (`EditableFileSurface`), `components/files/ReadOnlySourcePreview.tsx`, `components/DiffPanel.tsx` |
43
43
  | `webui/src/app/code/codeRendering.ts` | `apps/web/src/lib/diffRendering.ts` (`DIFF_SURFACE_THEME_UNSAFE_CSS`, `resolveDiffThemeName`), `lib/syntaxHighlighting.ts` (`PREFERRED_HIGHLIGHTER`), `components/diffs/StyledDiffCodeView.tsx`, `components/files/fileSurfaceChrome.tsx` |
44
44
  | `webui/src/tabs/lobby/InlineActivity.tsx` | `apps/web/src/components/chat/WorkLog.tsx` |
45
- | `src/webui/palette-core.ts` (the built-in themes) | `packages/shared/src/themePalettes.ts` (Blossom is their T3 Chat theme, renamed) |
46
45
  | `src/harness/model-manifest.json` (copied as is) | `apps/server/src/provider/model-manifest.json` |
47
46
  | `src/harness/catalog.ts` | `apps/server/src/provider/ClaudeModelCatalog.ts` (effort descriptors and maps), `CodexProvider.ts` (effort levels), `antigravityAuthSupport.ts` (`buildAntigravityAcpSpawnInput`) |
48
47
  | `src/harness/cli-args.ts` | `packages/shared/src/cliArgs.ts` (`tokenizeCliArgs`) |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@a-t-h-i/bot-lobby",
3
- "version": "0.6.69",
3
+ "version": "0.6.71",
4
4
  "description": "Structured multi-agent software engineering orchestrator for Pi",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
package/src/lobby/host.ts CHANGED
@@ -11,6 +11,7 @@ import type { MetricRecord } from "../state/metrics.ts";
11
11
  import type { BotLobbyConfig, LobbyAgentKind, PanelMember } from "../schemas/configuration.ts";
12
12
  import type { ChatEntry, LobbyFeed } from "./feed.ts";
13
13
  import type { BackgroundSession } from "./sessions.ts";
14
+ import type { SavedSession } from "./saved-sessions.ts";
14
15
  import type { PlannerSeed, PlanningSession } from "./planner.ts";
15
16
  import type { PlanRecord, PlanSummary } from "../state/plan-history.ts";
16
17
  import type { KnowledgeBook } from "./knowledge.ts";
@@ -163,6 +164,12 @@ export interface LobbyService {
163
164
  renameSession?(key: string | undefined, name: string): string;
164
165
  /** Put an ended background session away from the list, or bring it back; returns a notice (throws when it cannot). */
165
166
  archiveSession?(key: string, archived: boolean): string;
167
+ /** The project's saved sessions not listed otherwise, newest first (archived ones marked). */
168
+ savedSessions?(): SavedSession[];
169
+ /** Put a saved session away from the list, or bring it back; returns a notice (throws when it cannot). */
170
+ archiveSaved?(sessionId: string, archived: boolean): string;
171
+ /** Delete a saved session's file; returns a notice (throws when it cannot). */
172
+ deleteSaved?(sessionId: string): string;
166
173
  /** Start a task in a new background session, named after the task; the session, or why not. */
167
174
  startSession(start: { request?: string; plan?: PlannedTask; auto?: boolean }): BackgroundSession | string;
168
175
  /** Auto mode for any task, whichever session drives it. */
package/src/lobby/keys.ts CHANGED
@@ -16,6 +16,8 @@ export const LOBBY_ACTIONS = {
16
16
  code: { key: "alt+e", help: "open or close the code viewer: changed files, diffs and editing" },
17
17
  nextTab: { key: "alt+]", help: "next tab" },
18
18
  prevTab: { key: "alt+[", help: "previous tab" },
19
+ nextSession: { key: "alt+down", help: "switch to the next session in the sidebar" },
20
+ prevSession: { key: "alt+up", help: "switch to the previous session in the sidebar" },
19
21
  } as const;
20
22
 
21
23
  export type LobbyAction = keyof typeof LOBBY_ACTIONS;
@@ -0,0 +1,75 @@
1
+ /**
2
+ * The project's saved sessions, as the sidebar keeps them: every pi session
3
+ * with something said in it stays listed (newest first) until the user
4
+ * archives it, which is remembered in the project's data folder, or deletes
5
+ * its file. Pure apart from the archive file, so the tests read the same list.
6
+ */
7
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
8
+ import { dirname, join } from "node:path";
9
+ import { dataRoot } from "../state/project.ts";
10
+
11
+ /** A saved session the sidebar can switch to. */
12
+ export interface SavedSession {
13
+ sessionId: string;
14
+ name: string;
15
+ /** When it last changed, ms since the epoch. */
16
+ at: number;
17
+ archived?: boolean;
18
+ }
19
+
20
+ /** What pi's session list says of a session file. */
21
+ export interface SessionFileInfo {
22
+ id: string;
23
+ path: string;
24
+ name?: string;
25
+ firstMessage?: string;
26
+ modified: Date;
27
+ messageCount: number;
28
+ }
29
+
30
+ /** Longest name drawn from a session's first message. */
31
+ const NAME_FROM_MESSAGE = 60;
32
+
33
+ export function archivedSessionsFile(root: string, configDir: string): string {
34
+ return join(dataRoot(root, configDir), "sessions", "archived.json");
35
+ }
36
+
37
+ export function readArchivedSessions(file: string): Set<string> {
38
+ if (!existsSync(file)) return new Set();
39
+ try {
40
+ const ids = JSON.parse(readFileSync(file, "utf8")) as unknown;
41
+ return new Set(Array.isArray(ids) ? ids.filter((id): id is string => typeof id === "string") : []);
42
+ } catch {
43
+ return new Set();
44
+ }
45
+ }
46
+
47
+ export function writeArchivedSessions(file: string, ids: ReadonlySet<string>): void {
48
+ mkdirSync(dirname(file), { recursive: true });
49
+ writeFileSync(file, `${JSON.stringify([...ids].sort(), null, 2)}\n`);
50
+ }
51
+
52
+ /** A session's name: the one it was given, else the start of its first message. */
53
+ export function savedName(info: Pick<SessionFileInfo, "name" | "firstMessage">): string {
54
+ const named = info.name?.replace(/\s+/g, " ").trim();
55
+ if (named) return named;
56
+ const first = (info.firstMessage ?? "").replace(/\s+/g, " ").trim();
57
+ if (!first) return "Untitled session";
58
+ return first.length > NAME_FROM_MESSAGE ? `${first.slice(0, NAME_FROM_MESSAGE - 1).trimEnd()}…` : first;
59
+ }
60
+
61
+ /**
62
+ * The saved sessions to list, newest first: those with messages, one per id, except the ones `shown` already
63
+ * (this window, its background sessions, live ones in other terminals). Archived ones come back marked.
64
+ */
65
+ export function savedSessions(files: readonly SessionFileInfo[], shown: ReadonlySet<string>, archived: ReadonlySet<string>): SavedSession[] {
66
+ const byId = new Map<string, SavedSession>();
67
+ for (const file of files) {
68
+ if (file.messageCount === 0 || shown.has(file.id)) continue;
69
+ const at = file.modified.getTime();
70
+ const known = byId.get(file.id);
71
+ if (known && known.at >= at) continue;
72
+ byId.set(file.id, { sessionId: file.id, name: savedName(file), at, ...(archived.has(file.id) ? { archived: true } : {}) });
73
+ }
74
+ return [...byId.values()].sort((a, b) => b.at - a.at);
75
+ }
@@ -42,6 +42,8 @@ import type { ChatJob, ChatWorker } from "./chat-agents.ts";
42
42
  import { routeChatMessage } from "../classifier/lobby.ts";
43
43
  import { availableClassifiers, classifier, effortFor, hintsFor } from "../classifier/instance.ts";
44
44
  import { cleanSessionName, launchPi, SessionRegistry, type BackgroundSession, type SessionLauncher } from "./sessions.ts";
45
+ import { archivedSessionsFile, readArchivedSessions, savedSessions, writeArchivedSessions, type SavedSession, type SessionFileInfo } from "./saved-sessions.ts";
46
+ import { rmSync } from "node:fs";
45
47
  import { askForSession } from "./session-questions.ts";
46
48
  import { SessionChats } from "./session-files.ts";
47
49
  import { answerMessage, questionnaires, settledQuestions, styleAnswers } from "./ask.ts";
@@ -308,15 +310,85 @@ let exitHooked = false;
308
310
  /** How many questions of each session were already announced, and which exits, so each is said once. */
309
311
  const announced = new Map<string, number>();
310
312
  const exitsSaid = new Set<string>();
311
- /** Other sessions' conversations, read from their files. */
312
- const chats = new SessionChats(async () => {
313
+ /** Every saved pi session of this project, as pi lists them from disk. */
314
+ async function listSessionFiles(): Promise<SessionFileInfo[]> {
313
315
  const state = serviceState;
314
316
  if (!state) return [];
315
317
  const dirs = new Map<string, string | undefined>([[state.ctx.cwd, state.ctx.sessionManager.getSessionDir()]]);
316
318
  if (!dirs.has(state.root)) dirs.set(state.root, undefined);
317
319
  const lists = await Promise.all([...dirs].map(([cwd, dir]) => SessionManager.list(cwd, dir).catch(() => [])));
318
320
  return lists.flat();
319
- }, () => lobbyTopics.bump("sessions"));
321
+ }
322
+
323
+ /** Other sessions' conversations, read from their files. */
324
+ const chats = new SessionChats(listSessionFiles, () => lobbyTopics.bump("sessions"));
325
+
326
+ /** How long a read of the saved sessions is reused before pi's list is read again. */
327
+ const SAVED_READ_MS = 4000;
328
+ let savedSeen: { at: number; root: string; files: SessionFileInfo[]; reading?: boolean } | undefined;
329
+
330
+ /** The session files last read; a stale read starts a fresh one, and the sidebar is told when it lands. */
331
+ function sessionFiles(state: Runtime): SessionFileInfo[] {
332
+ const now = Date.now();
333
+ if (savedSeen?.root !== state.root) savedSeen = { at: Number.NEGATIVE_INFINITY, root: state.root, files: [] };
334
+ const seen = savedSeen;
335
+ if (now - seen.at >= SAVED_READ_MS && !seen.reading) {
336
+ seen.reading = true;
337
+ void listSessionFiles()
338
+ .then((files) => {
339
+ const before = seen.files.map((file) => `${file.id}:${file.modified.getTime()}:${file.name ?? ""}`).join("|");
340
+ seen.files = files;
341
+ if (files.map((file) => `${file.id}:${file.modified.getTime()}:${file.name ?? ""}`).join("|") !== before) lobbyTopics.bump("sessions");
342
+ })
343
+ .catch(() => {})
344
+ .finally(() => {
345
+ seen.at = Date.now();
346
+ seen.reading = false;
347
+ });
348
+ }
349
+ return seen.files;
350
+ }
351
+
352
+ /** The project's saved sessions not shown otherwise (this window, its background sessions, other terminals'). */
353
+ function listSavedSessions(state: Runtime): SavedSession[] {
354
+ const shown = new Set<string>([
355
+ state.ctx.sessionManager.getSessionId(),
356
+ ...backgroundSessions().flatMap((session) => (session.sessionId ? [session.sessionId] : [])),
357
+ ...liveSessions(state).map((session) => session.sessionId),
358
+ ]);
359
+ return savedSessions(sessionFiles(state), shown, readArchivedSessions(archivedSessionsFile(state.root, state.configDir)));
360
+ }
361
+
362
+ /** Put a saved session away from the sidebar, or bring it back; remembered in the project's data folder. */
363
+ function archiveSaved(state: Runtime, sessionId: string, archived: boolean): string {
364
+ const saved = savedSessions(sessionFiles(state), new Set(), new Set()).find((session) => session.sessionId === sessionId);
365
+ if (!saved) throw new Error(`no saved session ${sessionId}`);
366
+ const file = archivedSessionsFile(state.root, state.configDir);
367
+ const ids = readArchivedSessions(file);
368
+ if (archived) ids.add(sessionId);
369
+ else ids.delete(sessionId);
370
+ writeArchivedSessions(file, ids);
371
+ lobbyTopics.bump("sessions");
372
+ return archived ? `archived ${saved.name}` : `brought back ${saved.name}`;
373
+ }
374
+
375
+ /** Delete a saved session's file for good; never this window's, a running one's, or one in another terminal. */
376
+ function deleteSaved(state: Runtime, sessionId: string): string {
377
+ const busy = state.ctx.sessionManager.getSessionId() === sessionId
378
+ || backgroundSessions().some((session) => session.alive && session.sessionId === sessionId)
379
+ || liveSessions(state).some((session) => session.sessionId === sessionId);
380
+ if (busy) throw new Error("that session is open: switch away from it or stop it first");
381
+ const files = sessionFiles(state).filter((file) => file.id === sessionId);
382
+ if (!files.length) throw new Error(`no saved session ${sessionId}`);
383
+ const name = savedSessions(files, new Set(), new Set())[0]?.name ?? sessionId;
384
+ for (const file of files) rmSync(file.path, { force: true });
385
+ if (savedSeen) savedSeen = { ...savedSeen, files: savedSeen.files.filter((file) => file.id !== sessionId) };
386
+ const archive = archivedSessionsFile(state.root, state.configDir);
387
+ const ids = readArchivedSessions(archive);
388
+ if (ids.delete(sessionId)) writeArchivedSessions(archive, ids);
389
+ lobbyTopics.bump("sessions");
390
+ return `deleted ${name}`;
391
+ }
320
392
 
321
393
  /** Launch background sessions with something else (tests); resets the registry. */
322
394
  export function setSessionLauncher(next: SessionLauncher | undefined): void {
@@ -1142,6 +1214,9 @@ export function createLobbyService(state: Runtime): LobbyService {
1142
1214
  sessions: () => backgroundSessions().filter((session) => session.projectRoot === state.root),
1143
1215
  renameSession: (key, name) => renameSession(state, key, name),
1144
1216
  archiveSession: (key, archived) => archiveSession(state, key, archived),
1217
+ savedSessions: () => listSavedSessions(state),
1218
+ archiveSaved: (sessionId, archived) => archiveSaved(state, sessionId, archived),
1219
+ deleteSaved: (sessionId) => deleteSaved(state, sessionId),
1145
1220
  startSession: (start) => startSession(state, start),
1146
1221
  isAuto: (taskId) => autoFor(state, taskId),
1147
1222
  setAuto: (taskId, on) => switchAuto(state, taskId, on),
@@ -17,7 +17,7 @@ import { plannerAnswer, plannerCommentLine, plannerGet, plannerNew, plannerRetry
17
17
  import { tasksArchive, tasksArchived, tasksAuto, tasksComment, tasksComments, tasksDelete, tasksEditComment, tasksGet, tasksList, tasksMessage, tasksRestore, tasksOpen, tasksResume, tasksDeliveryReview, tasksDeliveryDefer, tasksDeliver, tasksAccept, tasksSkipStep, tasksForceClose, tasksResolveApproval } from "./tasks.ts";
18
18
  import { knowledgeAccept, knowledgeAdd, knowledgeAsk, knowledgeComment, knowledgeDismiss, knowledgeEdit, knowledgeFiles, knowledgeLedger, knowledgeMove, knowledgeOpen, knowledgePin, knowledgeRemove, knowledgeReplaceFile, knowledgeRestore, knowledgeUnnote } from "./knowledge.ts";
19
19
  import { plansDiscard, plansGet, plansStart } from "./plans.ts";
20
- import { sessionsAnswer, sessionsArchive, sessionsChat, sessionsList, sessionsMessage, sessionsRename, sessionsStart, sessionsStop, sessionsSwitch } from "./sessions.ts";
20
+ import { sessionsAnswer, sessionsArchive, sessionsChat, sessionsDelete, sessionsList, sessionsMessage, sessionsRename, sessionsStart, sessionsStop, sessionsSwitch } from "./sessions.ts";
21
21
  import { settingsGet, settingsGrants, settingsHarnesses, settingsLinters, settingsSet } from "./settings.ts";
22
22
  import { lobbyRetention, lobbySetRetention } from "./retention.ts";
23
23
  import { terminalClose, terminalInput, terminalList, terminalOpen, terminalResize } from "./terminal.ts";
@@ -253,8 +253,12 @@ function buildRoutes(): Record<string, Route> {
253
253
  run: (body, ctx) => sessionsRename(body as { key?: string; name: string }, ctx),
254
254
  };
255
255
  routes["sessions.archive"] = {
256
- schema: Type.Object({ key: TaskId, archived: Type.Optional(Type.Boolean()) }, { additionalProperties: false }),
257
- run: (body, ctx) => sessionsArchive(body as { key: string; archived?: boolean }, ctx),
256
+ schema: Type.Object({ key: Type.Optional(TaskId), sessionId: Type.Optional(TaskId), archived: Type.Optional(Type.Boolean()) }, { additionalProperties: false }),
257
+ run: (body, ctx) => sessionsArchive(body as { key?: string; sessionId?: string; archived?: boolean }, ctx),
258
+ };
259
+ routes["sessions.delete"] = {
260
+ schema: Type.Object({ sessionId: TaskId }, { additionalProperties: false }),
261
+ run: (body, ctx) => sessionsDelete(body as { sessionId: string }, ctx),
258
262
  };
259
263
  routes["sessions.answer"] = {
260
264
  schema: Type.Object({ key: TaskId, dialogId: TaskId, answer: DialogAnswer }, { additionalProperties: false }),
@@ -10,6 +10,7 @@ import type { ApiContext } from "./index.ts";
10
10
  import { withAttachments } from "../uploads.ts";
11
11
  import { fail } from "./index.ts";
12
12
  import type { BackgroundSessionInfo } from "../protocol.ts";
13
+ import type { SavedSession } from "../../lobby/saved-sessions.ts";
13
14
 
14
15
  function infoOf(session: BackgroundSession): BackgroundSessionInfo {
15
16
  return {
@@ -26,8 +27,8 @@ function infoOf(session: BackgroundSession): BackgroundSessionInfo {
26
27
  }
27
28
 
28
29
  /** Background sessions this window started, plus live sessions elsewhere. */
29
- export function sessionsList(ctx: ApiContext): { background: BackgroundSessionInfo[]; live: unknown[] } {
30
- return { background: ctx.service.sessions().map(infoOf), live: [...ctx.service.liveSessions()] };
30
+ export function sessionsList(ctx: ApiContext): { background: BackgroundSessionInfo[]; live: unknown[]; saved: SavedSession[] } {
31
+ return { background: ctx.service.sessions().map(infoOf), live: [...ctx.service.liveSessions()], saved: ctx.service.savedSessions?.() ?? [] };
31
32
  }
32
33
 
33
34
  /** Find a background session by its key or its pi session id. */
@@ -101,6 +102,8 @@ export async function sessionsSwitch(body: { key?: string; sessionId?: string; c
101
102
  return { notice: await ctx.service.switchTo({ name: background.name, ...(background.sessionId ? { sessionId: background.sessionId } : {}), background }) };
102
103
  }
103
104
  const live = ctx.service.liveSessions().find((session) => session.sessionId === body.sessionId);
105
+ const saved = live ? undefined : ctx.service.savedSessions?.().find((session) => session.sessionId === body.sessionId);
106
+ if (saved) return { notice: await ctx.service.switchTo({ name: saved.name, sessionId: saved.sessionId }) };
104
107
  const name = live?.name ?? "that session";
105
108
  return { notice: `${name} is running in another terminal — switch there, or close it first and resume it here` };
106
109
  }
@@ -125,10 +128,22 @@ export function sessionsRename(body: { key?: string; name: string }, ctx: ApiCon
125
128
  }
126
129
 
127
130
  /** Put an ended background session away from the list (`archived` true, the default), or bring it back. */
128
- export function sessionsArchive(body: { key: string; archived?: boolean }, ctx: ApiContext): { notice: string } {
129
- if (!ctx.service.archiveSession) fail(501, "unsupported", "this lobby cannot archive sessions");
131
+ export function sessionsArchive(body: { key?: string; sessionId?: string; archived?: boolean }, ctx: ApiContext): { notice: string } {
132
+ if (!body.key && !body.sessionId) fail(400, "bad_request", "a session key or id is required");
133
+ if (body.key ? !ctx.service.archiveSession : !ctx.service.archiveSaved) fail(501, "unsupported", "this lobby cannot archive sessions");
134
+ try {
135
+ return { notice: body.key ? ctx.service.archiveSession!(body.key, body.archived ?? true) : ctx.service.archiveSaved!(body.sessionId!, body.archived ?? true) };
136
+ } catch (error) {
137
+ const message = (error as Error).message;
138
+ fail(/^no /.test(message) ? 404 : 409, /^no /.test(message) ? "not_found" : "conflict", message);
139
+ }
140
+ }
141
+
142
+ /** Delete a saved session's file for good. */
143
+ export function sessionsDelete(body: { sessionId: string }, ctx: ApiContext): { notice: string } {
144
+ if (!ctx.service.deleteSaved) fail(501, "unsupported", "this lobby cannot delete sessions");
130
145
  try {
131
- return { notice: ctx.service.archiveSession!(body.key, body.archived ?? true) };
146
+ return { notice: ctx.service.deleteSaved!(body.sessionId) };
132
147
  } catch (error) {
133
148
  const message = (error as Error).message;
134
149
  fail(/^no /.test(message) ? 404 : 409, /^no /.test(message) ? "not_found" : "conflict", message);
@@ -212,6 +212,12 @@ export function createFixtureService(name: string, feed = new LobbyFeed()): Lobb
212
212
  // The agent other than the oracle answering an @ mention, for as long as its scripted reply takes.
213
213
  let answering: string | undefined;
214
214
  const archivedBackgrounds: BackgroundSession[] = [];
215
+ // Saved sessions of the project, as pi would list them: a couple from earlier days.
216
+ const saved = [
217
+ { sessionId: "saved-1", name: "Tidy the settings page", at: Date.now() - 26 * 3600_000 },
218
+ { sessionId: "saved-2", name: "Why does the router double-render?", at: Date.now() - 3 * 86_400_000 },
219
+ ];
220
+ const savedArchived = new Set<string>();
215
221
  let sessionName = fixture.status.sessionName;
216
222
  let planning = fakePlanner(fixture.mockPlanner ?? defaultPlanner());
217
223
  let config: BotLobbyConfig = resolveConfig(fixture.settings?.config ?? {});
@@ -444,6 +450,22 @@ export function createFixtureService(name: string, feed = new LobbyFeed()): Lobb
444
450
  return session;
445
451
  },
446
452
  liveSessions: () => [...(fixture.liveSessions ?? [])],
453
+ savedSessions: () => saved.map((session) => ({ ...session, ...(savedArchived.has(session.sessionId) ? { archived: true } : {}) })),
454
+ archiveSaved: (sessionId: string, archived: boolean) => {
455
+ const session = saved.find((entry) => entry.sessionId === sessionId);
456
+ if (!session) throw new Error(`no saved session ${sessionId}`);
457
+ if (archived) savedArchived.add(sessionId);
458
+ else savedArchived.delete(sessionId);
459
+ lobbyTopics.bump("sessions");
460
+ return archived ? `archived ${session.name}` : `brought back ${session.name}`;
461
+ },
462
+ deleteSaved: (sessionId: string) => {
463
+ const index = saved.findIndex((entry) => entry.sessionId === sessionId);
464
+ if (index < 0) throw new Error(`no saved session ${sessionId}`);
465
+ const [session] = saved.splice(index, 1);
466
+ lobbyTopics.bump("sessions");
467
+ return `deleted ${session!.name}`;
468
+ },
447
469
  planner: () => planning,
448
470
  ...previousPlansFake(fixture.mockPreviousPlans ?? []),
449
471
  newPlanner: (seed?: { issue: { number: number; title: string; url?: string }; body: string }, seats?: string[]) => {