@a-t-h-i/bot-lobby 0.6.61 → 0.6.63

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.
Files changed (101) hide show
  1. package/README.md +8 -8
  2. package/package.json +2 -1
  3. package/prompts/designer.md +25 -15
  4. package/prompts/master.md +284 -491
  5. package/prompts/panel.md +7 -0
  6. package/prompts/planner.md +15 -4
  7. package/prompts/qa.md +5 -1
  8. package/prompts/worker.md +0 -7
  9. package/scripts/builtin/affected_packages.mjs +106 -0
  10. package/scripts/builtin/check_changed.mjs +51 -0
  11. package/scripts/builtin/check_contract_breakage.mjs +118 -0
  12. package/scripts/builtin/circular_dependency_check.mjs +79 -0
  13. package/scripts/builtin/code_duplication_check.mjs +86 -0
  14. package/scripts/builtin/diff_summary.mjs +62 -0
  15. package/scripts/builtin/failure_digest.mjs +107 -0
  16. package/scripts/builtin/find_generated_files.mjs +79 -0
  17. package/scripts/builtin/find_symbol.mjs +81 -0
  18. package/scripts/builtin/find_test_fixtures.mjs +73 -0
  19. package/scripts/builtin/find_tests_for.mjs +12 -0
  20. package/scripts/builtin/lib/common.mjs +267 -0
  21. package/scripts/builtin/outline_file.mjs +77 -0
  22. package/scripts/builtin/project_commands.mjs +49 -0
  23. package/scripts/builtin/recent_changes.mjs +14 -0
  24. package/scripts/builtin/repo_map.mjs +65 -0
  25. package/scripts/builtin/run_changed_tests.mjs +48 -0
  26. package/src/delivery/transport.ts +1 -1
  27. package/src/desk/client-extension.ts +1 -31
  28. package/src/desk/ipc.ts +1 -11
  29. package/src/desk/session.ts +4 -101
  30. package/src/execution/agent-runner.ts +50 -8
  31. package/src/execution/assigned-session.ts +263 -0
  32. package/src/execution/assignment-discovery.ts +128 -0
  33. package/src/execution/assignment-policy.ts +46 -0
  34. package/src/execution/assignment.ts +175 -0
  35. package/src/execution/delegation.ts +9 -94
  36. package/src/execution/pi-runner.ts +99 -9
  37. package/src/harness/instructions.ts +1 -1
  38. package/src/index.ts +3 -0
  39. package/src/knowledge/design-record.ts +394 -0
  40. package/src/knowledge/file-notes.ts +36 -8
  41. package/src/lobby/ask.ts +6 -0
  42. package/src/lobby/exec.ts +28 -0
  43. package/src/lobby/host.ts +2 -11
  44. package/src/lobby/pi-commands.ts +83 -0
  45. package/src/lobby/planner.ts +50 -124
  46. package/src/lobby/prompts.ts +1 -7
  47. package/src/lobby/runtime.ts +2 -26
  48. package/src/lobby/service.ts +28 -27
  49. package/src/lobby/topics.ts +0 -2
  50. package/src/master/evidence-freshness.ts +96 -0
  51. package/src/master/master.ts +248 -74
  52. package/src/master/scout-cache.ts +1 -1
  53. package/src/master/scout-lock.ts +44 -0
  54. package/src/master/scout-prefetch.ts +78 -0
  55. package/src/pi/activity.ts +2 -0
  56. package/src/pi/assignment-guard.ts +157 -0
  57. package/src/pi/delegation.ts +2 -21
  58. package/src/pi/model-support.ts +0 -6
  59. package/src/pi/start-task.ts +18 -7
  60. package/src/pi/tools.ts +41 -8
  61. package/src/roles/scout.ts +3 -1
  62. package/src/roles/worker.ts +107 -5
  63. package/src/schemas/configuration.ts +11 -45
  64. package/src/schemas/findings.ts +3 -0
  65. package/src/schemas/task.ts +30 -12
  66. package/src/scripts/library.ts +31 -1
  67. package/src/scripts/pick.ts +31 -15
  68. package/src/state/archive.ts +10 -0
  69. package/src/state/checkpoint.ts +0 -1
  70. package/src/state/gitignore.ts +39 -0
  71. package/src/state/persistence.ts +56 -0
  72. package/src/state/recovery.ts +33 -1
  73. package/src/webui/api/index.ts +6 -35
  74. package/src/webui/api/retention.ts +44 -0
  75. package/src/webui/api/status.ts +5 -6
  76. package/src/webui/dev/fake-service.ts +8 -117
  77. package/src/webui/dev/fixtures.ts +2 -16
  78. package/src/webui/protocol.ts +3 -142
  79. package/src/workflow/draft-assignments.ts +118 -0
  80. package/src/workflow/workflow.ts +271 -214
  81. package/webui/dist/assets/{CodeSurface-BtzJOVyH.js → CodeSurface-CdyiJTYa.js} +1 -1
  82. package/webui/dist/assets/{TerminalView-Cz-KNWsq.js → TerminalView-D2nbR2J1.js} +1 -1
  83. package/webui/dist/assets/index-BTyu99rI.css +2 -0
  84. package/webui/dist/assets/index-BUGK22Z6.js +112 -0
  85. package/webui/dist/build.json +32 -68
  86. package/webui/dist/index.html +2 -2
  87. package/prompts/expert.md +0 -17
  88. package/prompts/goal-check.md +0 -44
  89. package/prompts/pr-review.md +0 -62
  90. package/prompts/splitter.md +0 -58
  91. package/src/execution/worker-trees.ts +0 -396
  92. package/src/lobby/issues.ts +0 -219
  93. package/src/lobby/pr-review.ts +0 -366
  94. package/src/lobby/pulls.ts +0 -250
  95. package/src/lobby/split.ts +0 -262
  96. package/src/master/goal-check.ts +0 -115
  97. package/src/webui/api/gh-error.ts +0 -17
  98. package/src/webui/api/git.ts +0 -98
  99. package/src/webui/api/issues.ts +0 -50
  100. package/webui/dist/assets/index-D5fvY8f8.js +0 -112
  101. package/webui/dist/assets/index-DFvk8ADr.css +0 -2
@@ -17,10 +17,9 @@ 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 { knowledgeAdd, knowledgeAsk, knowledgeComment, knowledgeEdit, knowledgeFiles, knowledgeOpen, knowledgeRemove, knowledgeReplaceFile, knowledgeUnnote } from "./knowledge.ts";
19
19
  import { plansDiscard, plansGet, plansStart } from "./plans.ts";
20
- import { gitCancelReview, gitJev, gitPull, gitPulls, gitReview } from "./git.ts";
21
- import { issuesCreate, issuesGet, issuesList } from "./issues.ts";
22
20
  import { sessionsAnswer, sessionsArchive, sessionsChat, sessionsList, sessionsMessage, sessionsRename, sessionsStart, sessionsStop, sessionsSwitch } from "./sessions.ts";
23
21
  import { settingsGet, settingsGrants, settingsHarnesses, settingsLinters, settingsSet } from "./settings.ts";
22
+ import { lobbyRetention, lobbySetRetention } from "./retention.ts";
24
23
  import { terminalClose, terminalInput, terminalList, terminalOpen, terminalResize } from "./terminal.ts";
25
24
  import { MAX_INPUT_CHARS } from "../terminal.ts";
26
25
  import { themesChoose, themesGet, themesRemove, themesRename, themesSave } from "./themes.ts";
@@ -77,7 +76,6 @@ interface Route {
77
76
 
78
77
  const Empty = Type.Object({}, { additionalProperties: false });
79
78
  const TaskId = Type.String({ minLength: 1, maxLength: 200 });
80
- const GhNumber = Type.Integer({ minimum: 1, maximum: 1_000_000_000 });
81
79
  const NoticeText = Type.String({ maxLength: 20_000 });
82
80
  /** Ids of files uploaded through `files.upload`; the message names them by path. */
83
81
  const Attachments = Type.Optional(Type.Array(Type.String({ minLength: 1, maxLength: 200 }), { maxItems: 8 }));
@@ -118,6 +116,11 @@ function buildRoutes(): Record<string, Route> {
118
116
  run: (body, ctx) => lobbySend(body as { text: string; attachments?: string[] }, ctx),
119
117
  };
120
118
  routes["lobby.abort"] = { schema: Empty, run: (_body, ctx) => lobbyAbort(ctx) };
119
+ routes["lobby.retention"] = { schema: Empty, run: (_body, ctx) => lobbyRetention(ctx) };
120
+ routes["lobby.setRetention"] = {
121
+ schema: Type.Object({ enabled: Type.Boolean() }, { additionalProperties: false }),
122
+ run: (body, ctx) => lobbySetRetention(body as { enabled: boolean }, ctx),
123
+ };
121
124
  routes["tasks.list"] = { schema: Empty, run: (_body, ctx) => tasksList(ctx) };
122
125
  routes["tasks.archived"] = { schema: Empty, run: (_body, ctx) => tasksArchived(ctx) };
123
126
  routes["tasks.get"] = {
@@ -329,38 +332,6 @@ function buildRoutes(): Record<string, Route> {
329
332
  schema: Type.Object({ id: TaskId }, { additionalProperties: false }),
330
333
  run: (body, ctx) => knowledgeUnnote(body as { id: string }, ctx),
331
334
  };
332
- routes["git.pulls"] = {
333
- schema: Type.Object({ refresh: Type.Optional(Type.Boolean()) }, { additionalProperties: false }),
334
- run: (body, ctx) => gitPulls(body as { refresh?: boolean }, ctx),
335
- };
336
- routes["git.pull"] = {
337
- schema: Type.Object({ number: GhNumber }, { additionalProperties: false }),
338
- run: (body, ctx) => gitPull(body as { number: number }, ctx),
339
- };
340
- routes["git.review"] = {
341
- schema: Type.Object({ number: GhNumber, focus: Type.Optional(Type.String({ maxLength: 2000 })) }, { additionalProperties: false }),
342
- run: (body, ctx) => gitReview(body as { number: number; focus?: string }, ctx),
343
- };
344
- routes["git.cancelReview"] = {
345
- schema: Type.Object({ number: GhNumber }, { additionalProperties: false }),
346
- run: (body, ctx) => gitCancelReview(body as { number: number }, ctx),
347
- };
348
- routes["git.jev"] = {
349
- schema: Type.Object({ number: GhNumber }, { additionalProperties: false }),
350
- run: (body, ctx) => gitJev(body as { number: number }, ctx),
351
- };
352
- routes["issues.list"] = {
353
- schema: Type.Object({ refresh: Type.Optional(Type.Boolean()) }, { additionalProperties: false }),
354
- run: (body, ctx) => issuesList(body as { refresh?: boolean }, ctx),
355
- };
356
- routes["issues.get"] = {
357
- schema: Type.Object({ number: GhNumber }, { additionalProperties: false }),
358
- run: (body, ctx) => issuesGet(body as { number: number }, ctx),
359
- };
360
- routes["issues.create"] = {
361
- schema: Type.Object({ text: Type.String({ maxLength: 20_000 }) }, { additionalProperties: false }),
362
- run: (body, ctx) => issuesCreate(body as { text: string }, ctx),
363
- };
364
335
  const codeRoot = (ctx: ApiContext) => ctx.service.projectRoot?.() ?? process.cwd();
365
336
  const CodePath = Type.String({ minLength: 1, maxLength: 4096 });
366
337
  routes["code.changes"] = { schema: Empty, run: (_body, ctx) => codeChanges(codeRoot(ctx)) };
@@ -0,0 +1,44 @@
1
+ /**
2
+ * `lobby.retention` / `lobby.setRetention`: whether the repo's `.gitignore`
3
+ * keeps `.pi/bot-lobby` tracked in git. Retention lives in the file itself,
4
+ * not in config — on writes `.pi/*` + `!.pi/bot-lobby/`, off restores the
5
+ * plain `.pi/` ignore; every other line is preserved as written.
6
+ */
7
+ import { readFileSync, writeFileSync } from "node:fs";
8
+ import { join } from "node:path";
9
+ import { detectProjectRoot } from "../../state/project.ts";
10
+ import { retentionEnabled, withRetention } from "../../state/gitignore.ts";
11
+ import type { ApiContext } from "./index.ts";
12
+ import { fail } from "./index.ts";
13
+
14
+ /** The repo's .gitignore, under the lobby's project root. */
15
+ function gitignorePath(ctx: ApiContext): string {
16
+ return join(ctx.service.projectRoot?.() ?? detectProjectRoot(process.cwd()), ".gitignore");
17
+ }
18
+
19
+ /** The file's content; missing is empty (retention off), anything else fails. */
20
+ function readGitignore(path: string): string {
21
+ try {
22
+ return readFileSync(path, "utf8");
23
+ } catch (error) {
24
+ if ((error as NodeJS.ErrnoException).code === "ENOENT") return "";
25
+ fail(500, "failed", `could not read this repository's .gitignore: ${(error as Error).message}`);
26
+ }
27
+ }
28
+
29
+ /** Whether `.pi/bot-lobby` is retained in git, read back from the file. */
30
+ export function lobbyRetention(ctx: ApiContext): { enabled: boolean } {
31
+ return { enabled: retentionEnabled(readGitignore(gitignorePath(ctx))) };
32
+ }
33
+
34
+ /** Rewrite the managed block so retention matches `enabled`. */
35
+ export function lobbySetRetention(body: { enabled: boolean }, ctx: ApiContext): { enabled: boolean } {
36
+ const path = gitignorePath(ctx);
37
+ const next = withRetention(readGitignore(path), body.enabled);
38
+ try {
39
+ writeFileSync(path, next, "utf8");
40
+ } catch (error) {
41
+ fail(500, "failed", `could not write this repository's .gitignore: ${(error as Error).message}`);
42
+ }
43
+ return { enabled: retentionEnabled(next) };
44
+ }
@@ -5,12 +5,12 @@
5
5
  */
6
6
  import { loadConfig } from "../../state/project.ts";
7
7
  import { LOBBY_ACTIONS, keyLabel, keyMap } from "../../lobby/keys.ts";
8
- import { TAB_LABELS, visibleTabs } from "../../lobby/prompts.ts";
8
+ import { TAB_IDS, TAB_LABELS } from "../../lobby/prompts.ts";
9
9
  import type { ApiContext } from "./index.ts";
10
10
  import type { KeyInfo, StatusInfo, TabInfo } from "../protocol.ts";
11
11
 
12
- function tabs(issuesEnabled: boolean): TabInfo[] {
13
- return visibleTabs(issuesEnabled).map((id, index) => ({ id, label: TAB_LABELS[id], key: `Alt+${index + 1}` }));
12
+ function tabs(): TabInfo[] {
13
+ return TAB_IDS.map((id, index) => ({ id, label: TAB_LABELS[id], key: `Alt+${index + 1}` }));
14
14
  }
15
15
 
16
16
  function keys(overrides: Readonly<Record<string, string>>): KeyInfo[] {
@@ -26,7 +26,6 @@ function keys(overrides: Readonly<Record<string, string>>): KeyInfo[] {
26
26
  /** The page shell's first call. */
27
27
  export function statusGet(ctx: ApiContext): StatusInfo {
28
28
  const service = ctx.service;
29
- const issuesEnabled = service.issuesEnabled();
30
29
  const workspace = service.workspace?.() ?? { name: "bot-lobby" };
31
30
  // The service's own config when it has one, so a saved panes or keys change shows without a restart.
32
31
  const config = service.config?.() ?? loadConfig();
@@ -37,10 +36,10 @@ export function statusGet(ctx: ApiContext): StatusInfo {
37
36
  sessionId: service.sessionId() ?? undefined,
38
37
  sessionName: service.sessionName() ?? undefined,
39
38
  busy: service.masterBusy(),
39
+ commands: service.commands?.() ?? [],
40
40
  port: ctx.port,
41
- issuesEnabled,
42
41
  panels: config.lobby.panels,
43
- tabs: tabs(issuesEnabled),
42
+ tabs: tabs(),
44
43
  keys: keys(config.lobby.keys),
45
44
  windows: [],
46
45
  ...(recovered ? { recovered } : {}),
@@ -9,6 +9,7 @@ import { LobbyFeed } from "../../lobby/feed.ts";
9
9
  import { promptHub } from "../../lobby/prompt-hub.ts";
10
10
  import { lobbyTopics } from "../../lobby/topics.ts";
11
11
  import { CHAT_AGENT_SOURCES, parseLobbyCommand, parseMention } from "../../lobby/prompts.ts";
12
+ import { piCommands } from "../../lobby/pi-commands.ts";
12
13
  import type { BackgroundSession, DialogAnswer, SessionDialog } from "../../lobby/sessions.ts";
13
14
  import { cleanSessionName } from "../../lobby/sessions.ts";
14
15
  import type { PlanComment } from "../../state/comments.ts";
@@ -68,119 +69,6 @@ function defaultPlanner(): NonNullable<ScenarioFixture["mockPlanner"]> {
68
69
 
69
70
  const DETAIL_ONLY = ["body", "state", "mergeable", "files", "notes", "comments"] as const;
70
71
 
71
- /** A list row: the detail fixture without the fields only a detail carries. */
72
- function summaryOf(entry: Record<string, unknown>): Record<string, unknown> {
73
- const row: Record<string, unknown> = { ...entry };
74
- for (const key of DETAIL_ONLY) delete row[key];
75
- return row;
76
- }
77
-
78
- /** The Git tab's `PullsState` as canned fixture data (`gh` is never run). */
79
- function fakePulls(entries: Array<Record<string, unknown>>) {
80
- const details = new Map<number, Record<string, unknown>>();
81
- const state = {
82
- pulls: [] as Array<Record<string, unknown>>,
83
- details,
84
- loading: false,
85
- loaded: false,
86
- error: undefined as string | undefined,
87
- async refresh() {
88
- state.pulls = entries.map(summaryOf);
89
- state.loaded = true;
90
- lobbyTopics.bump("git");
91
- },
92
- async detail(number: number) {
93
- const found = entries.find((entry) => entry.number === number);
94
- if (!found) {
95
- state.error = "GraphQL: Could not resolve to a PullRequest with the number of " + number + ".";
96
- return undefined;
97
- }
98
- state.error = undefined;
99
- details.set(number, found);
100
- return { ...found };
101
- },
102
- forget() {
103
- details.clear();
104
- },
105
- };
106
- return state;
107
- }
108
-
109
- /** Reviews and Jev's reads as canned data; a started review finishes after a moment. */
110
- function fakeReviews(saved: Array<Record<string, unknown>>, savedReads: Array<Record<string, unknown>>) {
111
- const reviews = new Map<number, Record<string, unknown>>(saved.map((review) => [review.number as number, { ...review }]));
112
- const reads = new Map<number, Record<string, unknown>>(savedReads.map((read) => [read.number as number, { ...read }]));
113
- const finish = (after: () => void): void => {
114
- const timer = setTimeout(() => {
115
- after();
116
- lobbyTopics.bump("git");
117
- }, 400);
118
- timer.unref?.();
119
- };
120
- return {
121
- reviews,
122
- reads,
123
- review: (number: number) => reviews.get(number),
124
- running: (number: number) => reviews.get(number)?.status === "running",
125
- async start(number: number, options: { focus?: string } = {}) {
126
- const review: Record<string, unknown> = { number, status: "running", startedAt: Date.now(), steps: ["reading the pull request from GitHub"], ...(options.focus ? { focus: options.focus } : {}) };
127
- reviews.set(number, review);
128
- lobbyTopics.bump("git");
129
- finish(() => Object.assign(review, { status: "done", verdict: "comment", finishedAt: Date.now(), model: "mock/qa", thinking: "medium", text: "## Verdict\nCOMMENT\n\n## Summary\nA canned review from the mock.\n\n## Findings\nNone." }));
130
- return review;
131
- },
132
- cancel(number: number): boolean {
133
- const review = reviews.get(number);
134
- if (review?.status !== "running") return false;
135
- review.status = "cancelled";
136
- review.finishedAt = Date.now();
137
- lobbyTopics.bump("git");
138
- return true;
139
- },
140
- async readWithJev(number: number) {
141
- const read: Record<string, unknown> = { number, status: "running" };
142
- reads.set(number, read);
143
- lobbyTopics.bump("git");
144
- finish(() => Object.assign(read, { status: "done", line: "small · low risk", read: { size: "small", sizeConfidence: 0.9, risky: 0.1, breaking: 0.05, security: 0.02, testsMissing: 0.2, model: "mock/jev", ms: 200 } }));
145
- return read;
146
- },
147
- };
148
- }
149
-
150
- /** The Issues tab's `IssuesState` as canned fixture data. */
151
- function fakeIssues(entries: Array<Record<string, unknown>>) {
152
- const details = new Map<number, Record<string, unknown>>();
153
- const state = {
154
- issues: [] as Array<Record<string, unknown>>,
155
- details,
156
- loading: false,
157
- loaded: false,
158
- error: undefined as string | undefined,
159
- notice: undefined as string | undefined,
160
- async refresh() {
161
- state.issues = entries.map(summaryOf);
162
- state.loaded = true;
163
- lobbyTopics.bump("issues");
164
- },
165
- async detail(number: number) {
166
- const found = entries.find((entry) => entry.number === number);
167
- if (!found) {
168
- state.error = "GraphQL: Could not resolve to an Issue with the number of " + number + ".";
169
- return undefined;
170
- }
171
- return { ...found };
172
- },
173
- async create(text: string) {
174
- const title = text.trim().split("\n")[0]!.replace(/^#+\s*/, "");
175
- const number = Math.max(0, ...entries.map((entry) => entry.number as number)) + 1;
176
- entries.unshift({ number, title, labels: [], body: text.trim().split("\n").slice(1).join("\n").trim(), state: "OPEN", comments: [] });
177
- state.notice = `created #${number} — https://github.com/example/bot-lobby/issues/${number}`;
178
- await state.refresh();
179
- },
180
- };
181
- return state;
182
- }
183
-
184
72
  /** The models the mock offers, unless a scenario's settings name its own. */
185
73
  const DEFAULT_MODELS: Array<{ id: string; label: string; thinkingLevels: string[] }> = [
186
74
  { id: "mock/gpt-5", label: "Mock GPT-5", thinkingLevels: ["low", "medium", "high"] },
@@ -349,6 +237,13 @@ export function createFixtureService(name: string, feed = new LobbyFeed()): Lobb
349
237
  const service = {
350
238
  sessionId: () => fixture.status.sessionId,
351
239
  sessionName: () => sessionName,
240
+ commands: () => [...piCommands(),
241
+ { name: "skill:pdf-tools", description: "Extract text and tables from PDF files." },
242
+ { name: "skill:release-notes", description: "Write release notes from merged pull requests." },
243
+ { name: "skill:tailwind-review", description: "Check Tailwind classes against the design tokens." },
244
+ { name: "mcp", description: "Manage MCP servers" },
245
+ { name: "review", description: "Review changes" },
246
+ ],
352
247
  masterBusy: () => fixture.status.busy || answering !== undefined,
353
248
  answering: () => answering,
354
249
  config: () => config,
@@ -384,7 +279,6 @@ export function createFixtureService(name: string, feed = new LobbyFeed()): Lobb
384
279
  { name: "tailwind-review", description: "Check Tailwind classes against the design tokens.", path: ".agents/skills/tailwind-review/SKILL.md" },
385
280
  ],
386
281
  }),
387
- issuesEnabled: () => fixture.status.issuesEnabled,
388
282
  workspace: () => ({ ...fixture.status.workspace }),
389
283
  zen: () => ({ ...(fixture.zen.task ? { task: { ...fixture.zen.task } } : {}), runs: [...fixture.zen.runs] }),
390
284
  feed,
@@ -560,9 +454,6 @@ export function createFixtureService(name: string, feed = new LobbyFeed()): Lobb
560
454
  },
561
455
  defaultPanel: () => ["backend", "designer", "qa", "researcher"],
562
456
  planningRounds: () => 5,
563
- pulls: fakePulls(fixture.mockPulls ?? []),
564
- reviews: fakeReviews(fixture.mockReviews ?? [], fixture.mockReads ?? []),
565
- issues: fakeIssues((fixture.mockIssues ?? []).map((issue) => ({ ...issue }))),
566
457
  sessionChat: () => [],
567
458
  hasOlderChat: () => false,
568
459
  switchTo: async (target: { name: string }) => (fixture.status.busy ? `${sessionName ?? "this window's session"} carries on in the background; switching this window to ${target.name}…` : `switching this window to ${target.name}…`),
@@ -19,7 +19,6 @@ export const SCENARIOS = [
19
19
  "reconnecting",
20
20
  "question",
21
21
  "questions3",
22
- "issues",
23
22
  "mockups",
24
23
  ] as const;
25
24
 
@@ -42,7 +41,6 @@ export interface ScenarioFixture {
42
41
  sessionId: string;
43
42
  sessionName: string;
44
43
  busy: boolean;
45
- issuesEnabled: boolean;
46
44
  };
47
45
  zen: { task?: Partial<SnapshotTask> & { id: string; title: string; state: string; plan?: string }; runs: unknown[] };
48
46
  feed: {
@@ -99,14 +97,6 @@ export interface ScenarioFixture {
99
97
  mockKnowledge?: Array<{ agent: string; file: string; label: string; chars: number; over: boolean; notes: number }>;
100
98
  /** One open knowledge file for `knowledge.open` (absent means an empty file). */
101
99
  mockKnowledgeView?: { agent: string; file: string; label: string; chars: number; over: boolean; notes: number; content: string; entries: Array<Record<string, unknown>>; attached: Array<Record<string, unknown>>; detached: Array<Record<string, unknown>> };
102
- /** Open pull requests for the `git.*` calls, each with its detail fields (absent means none). */
103
- mockPulls?: Array<Record<string, unknown>>;
104
- /** Saved reviews of those pull requests, by number. */
105
- mockReviews?: Array<Record<string, unknown>>;
106
- /** Jev's reads of those pull requests, by number. */
107
- mockReads?: Array<Record<string, unknown>>;
108
- /** Open issues for the `issues.*` calls, each with its detail fields (absent means none). */
109
- mockIssues?: Array<Record<string, unknown>>;
110
100
  }
111
101
 
112
102
  /** Whether `value` names a scenario. */
@@ -140,8 +130,8 @@ export function loadScenario(name: string | undefined): ScenarioFixture {
140
130
  if (!hasKeys(parsed, ["status", "zen", "feed", "history", "prompts", "oracleReply"])) {
141
131
  throw new Error(`fixtures/${scenario}.json must cover status, zen, feed, history, prompts and oracleReply`);
142
132
  }
143
- if (!hasKeys(parsed.status, ["workspace", "sessionId", "sessionName", "busy", "issuesEnabled"])) {
144
- throw new Error(`fixtures/${scenario}.json status must carry workspace, session, busy and issuesEnabled`);
133
+ if (!hasKeys(parsed.status, ["workspace", "sessionId", "sessionName", "busy"])) {
134
+ throw new Error(`fixtures/${scenario}.json status must carry workspace, session and busy`);
145
135
  }
146
136
  if (!hasKeys(parsed.zen, ["runs"]) || !hasKeys(parsed.feed, ["chat", "activity", "thoughts", "reply", "chatOlder"])) {
147
137
  throw new Error(`fixtures/${scenario}.json zen/feed are missing their fields`);
@@ -166,10 +156,6 @@ export function loadScenario(name: string | undefined): ScenarioFixture {
166
156
  mockClassifierMetrics: Array.isArray(parsed.mockClassifierMetrics) ? (parsed.mockClassifierMetrics as ScenarioFixture["mockClassifierMetrics"]) : [],
167
157
  mockKnowledge: Array.isArray(parsed.mockKnowledge) ? (parsed.mockKnowledge as ScenarioFixture["mockKnowledge"]) : [],
168
158
  mockKnowledgeView: isRecord(parsed.mockKnowledgeView) ? (parsed.mockKnowledgeView as unknown as ScenarioFixture["mockKnowledgeView"]) : undefined,
169
- mockPulls: Array.isArray(parsed.mockPulls) ? (parsed.mockPulls as ScenarioFixture["mockPulls"]) : [],
170
- mockReviews: Array.isArray(parsed.mockReviews) ? (parsed.mockReviews as ScenarioFixture["mockReviews"]) : [],
171
- mockReads: Array.isArray(parsed.mockReads) ? (parsed.mockReads as ScenarioFixture["mockReads"]) : [],
172
- mockIssues: Array.isArray(parsed.mockIssues) ? (parsed.mockIssues as ScenarioFixture["mockIssues"]) : [],
173
159
  settings: isRecord(parsed.settings) ? (parsed.settings as ScenarioFixture["settings"]) : undefined,
174
160
  };
175
161
  }
@@ -107,13 +107,13 @@ export interface ThemeStoreInfo {
107
107
  }
108
108
 
109
109
  export interface StatusInfo {
110
+ commands?: import("../lobby/pi-commands.ts").LobbySlashCommand[];
110
111
  workspace: { name: string; branch?: string };
111
112
  branch?: string;
112
113
  sessionId?: string;
113
114
  sessionName?: string;
114
115
  busy: boolean;
115
116
  port: number;
116
- issuesEnabled: boolean;
117
117
  /** Which panes the Lobby tab shows (`lobby.panels`). */
118
118
  panels: Record<"conversation" | "activity" | "thinking", boolean>;
119
119
  tabs: TabInfo[];
@@ -423,139 +423,6 @@ export interface PlanDetail {
423
423
  startedTaskId?: string;
424
424
  }
425
425
 
426
- /** The checks of a pull request as one state. */
427
- export type PullChecks = "passing" | "failing" | "pending";
428
-
429
- /** How a pull request's review stands, for the list's marks. */
430
- export interface PullReviewMark {
431
- status: "running" | "done" | "failed" | "cancelled" | "timeout";
432
- verdict?: "approve" | "changes" | "comment";
433
- /** The pull request has commits the review did not see. */
434
- stale: boolean;
435
- }
436
-
437
- /** One open pull request in the Git list. */
438
- export interface PullInfo {
439
- number: number;
440
- title: string;
441
- author?: string;
442
- headRef: string;
443
- baseRef: string;
444
- draft: boolean;
445
- updatedAt?: string;
446
- url?: string;
447
- additions: number;
448
- deletions: number;
449
- changedFiles: number;
450
- decision?: string;
451
- checks?: PullChecks;
452
- checkCount: number;
453
- labels: string[];
454
- review?: PullReviewMark;
455
- }
456
-
457
- /** One changed file. */
458
- export interface PullFileInfo {
459
- path: string;
460
- additions: number;
461
- deletions: number;
462
- }
463
-
464
- /** A review or a comment on a pull request. */
465
- export interface PullNoteInfo {
466
- author?: string;
467
- body: string;
468
- at?: string;
469
- state?: string;
470
- }
471
-
472
- /** A pull request with its description, files and discussion. */
473
- export interface PullDetailInfo extends PullInfo {
474
- body: string;
475
- state?: string;
476
- mergeable?: string;
477
- files: PullFileInfo[];
478
- notes: PullNoteInfo[];
479
- }
480
-
481
- /** The agent's review of a pull request (never posted to GitHub). */
482
- export interface PullReviewInfo {
483
- number: number;
484
- status: "running" | "done" | "failed" | "cancelled" | "timeout";
485
- focus?: string;
486
- startedAt: number;
487
- finishedAt?: number;
488
- steps: string[];
489
- text?: string;
490
- verdict?: "approve" | "changes" | "comment";
491
- error?: string;
492
- model?: string;
493
- thinking?: string;
494
- stale: boolean;
495
- /** Kept from an earlier session rather than run now. */
496
- saved?: boolean;
497
- }
498
-
499
- /** Jev's quick read of a pull request. */
500
- export interface PullReadInfo {
501
- number: number;
502
- status: "running" | "done" | "failed";
503
- line?: string;
504
- error?: string;
505
- read?: {
506
- size: string;
507
- sizeConfidence: number;
508
- risky: number;
509
- breaking: number;
510
- security: number;
511
- testsMissing: number;
512
- kind?: string;
513
- kindProbability?: number;
514
- model: string;
515
- ms: number;
516
- };
517
- }
518
-
519
- /** `git.pulls`: the open pull requests, or why they could not be read. */
520
- export interface GitPulls {
521
- pulls: PullInfo[];
522
- loading: boolean;
523
- loaded: boolean;
524
- error?: string;
525
- }
526
-
527
- /** `git.pull`: one pull request with our review and Jev's read of it. */
528
- export interface GitPull {
529
- pull: PullDetailInfo;
530
- review?: PullReviewInfo;
531
- read?: PullReadInfo;
532
- }
533
-
534
- /** One open issue in the Issues list. */
535
- export interface IssueInfo {
536
- number: number;
537
- title: string;
538
- labels: string[];
539
- author?: string;
540
- updatedAt?: string;
541
- url?: string;
542
- }
543
-
544
- /** An issue with its description and comments. */
545
- export interface IssueDetailInfo extends IssueInfo {
546
- body: string;
547
- state?: string;
548
- comments: Array<{ author?: string; body: string; createdAt?: string }>;
549
- }
550
-
551
- /** `issues.list`: the open issues, or why they could not be read. */
552
- export interface IssuesList {
553
- issues: IssueInfo[];
554
- loading: boolean;
555
- loaded: boolean;
556
- error?: string;
557
- }
558
-
559
426
  /** The calls the server answers: `POST /api/<name>` with the request as the JSON body. */
560
427
  export interface Api {
561
428
  "status.get": { request: Record<string, never>; result: StatusInfo };
@@ -563,6 +430,8 @@ export interface Api {
563
430
  "lobby.history": { request: { before?: number }; result: { entries: unknown[]; hasOlder: boolean } };
564
431
  "lobby.send": { request: { text: string; attachments?: string[] }; result: { notice?: string; open?: "plan" } };
565
432
  "lobby.abort": { request: Record<string, never>; result: Record<string, never> };
433
+ "lobby.retention": { request: Record<string, never>; result: { enabled: boolean } };
434
+ "lobby.setRetention": { request: { enabled: boolean }; result: { enabled: boolean } };
566
435
  "tasks.list": { request: Record<string, never>; result: { rows: TaskRow[] } };
567
436
  "tasks.archived": { request: Record<string, never>; result: { rows: TaskRow[] } };
568
437
  "tasks.comments": { request: { taskId: string }; result: { comments: PlanComment[] } };
@@ -631,14 +500,6 @@ export interface Api {
631
500
  "knowledge.replaceFile": { request: { agent: KnowledgeAgentName; file: string; text: string }; result: { notice: string } };
632
501
  "knowledge.comment": { request: { agent: KnowledgeAgentName; file: string; ref: EntryRefInfo; text: string }; result: { notice: string } };
633
502
  "knowledge.unnote": { request: { id: string }; result: { notice: string } };
634
- "git.pulls": { request: { refresh?: boolean }; result: GitPulls };
635
- "git.pull": { request: { number: number }; result: GitPull };
636
- "git.review": { request: { number: number; focus?: string }; result: { notice: string } };
637
- "git.cancelReview": { request: { number: number }; result: { notice: string } };
638
- "git.jev": { request: { number: number }; result: { notice: string } };
639
- "issues.list": { request: { refresh?: boolean }; result: IssuesList };
640
- "issues.get": { request: { number: number }; result: { issue: IssueDetailInfo } };
641
- "issues.create": { request: { text: string }; result: { notice: string } };
642
503
  "settings.get": { request: Record<string, never>; result: SettingsInfo };
643
504
  "settings.set": { request: { patch: Record<string, unknown> }; result: { config: BotLobbyConfig } };
644
505
  "settings.linters": { request: Record<string, never>; result: { linters: SettingsLinter[] } };
@@ -0,0 +1,118 @@
1
+ /**
2
+ * Draft worker assignments read off a plan, so the oracle starts from the
3
+ * files and steps the plan already names instead of deriving them again. A
4
+ * draft carries what the plan says for certain (the step, its objective, the
5
+ * project files it names, whether each exists) and leaves the rest to the
6
+ * oracle: the domain when the step does not say, the tools, contracts and
7
+ * verification. Consecutive small steps of one domain (a file each, at most)
8
+ * are folded into one draft, so they go out as one worker run.
9
+ *
10
+ * Drafts are hints for the oracle's `workerAssignment`, never dispatched as they are.
11
+ */
12
+ import { existsSync, statSync } from "node:fs";
13
+ import { dirname, isAbsolute, relative, resolve, sep } from "node:path";
14
+ import type { Domain } from "../schemas/agent.ts";
15
+ import type { AssignmentFile } from "../execution/assignment.ts";
16
+ import { planStepBlocks, planSteps } from "../pi/plan-checklist.ts";
17
+
18
+ export interface DraftAssignment {
19
+ /** 1-based plan steps the draft covers: one, or a run of small steps folded together. */
20
+ steps: number[];
21
+ id: string;
22
+ domain?: Domain;
23
+ objective: string;
24
+ actions: { step: number; instruction: string }[];
25
+ files: AssignmentFile[];
26
+ }
27
+
28
+ /** Path-like tokens: `src/a.ts`, `webui/src/App.tsx:42`, `docs/plan.md#x`. */
29
+ const PATH = /(?:^|[\s`'"(\[])((?:\.{1,2}\/)?[\w@.-]+(?:\/[\w@.-]+)*\.[A-Za-z][\w]{0,7})(?::\d+(?:-\d+)?)?(?=$|[\s`'",;:)\]#])/g;
30
+ const CREATE_WORDS = /\b(create|add(?:s|ing)? (?:a |an )?new|new file|scaffold|introduce)\b/i;
31
+ const DOMAIN_WORDS: [Domain, RegExp][] = [
32
+ ["designer", /\b(designer|design|ui|frontend|front-end|webui|css|styles?)\b/i],
33
+ ["qa", /\b(qa|tests?|testing|spec|coverage)\b/i],
34
+ ["backend", /\b(backend|back-end|dev|engine|server|api|runtime)\b/i],
35
+ ];
36
+ /** At most this many files for a step to count as small enough to fold. */
37
+ const SMALL_STEP_FILES = 1;
38
+ const MAX_FOLD = 4;
39
+
40
+ function inside(root: string, path: string): boolean {
41
+ const rel = relative(root, path);
42
+ return rel !== "" && !isAbsolute(rel) && rel !== ".." && !rel.startsWith(`..${sep}`);
43
+ }
44
+
45
+ /** The project files a step names: existing ones to edit, absent ones it creates under an existing folder. */
46
+ export function stepFiles(text: string, cwd: string): AssignmentFile[] {
47
+ const root = resolve(cwd);
48
+ const creates = CREATE_WORDS.test(text);
49
+ const seen = new Set<string>();
50
+ const files: AssignmentFile[] = [];
51
+ for (const match of text.matchAll(PATH)) {
52
+ const raw = match[1]!;
53
+ if (/^\d|^https?:|^www\./i.test(raw)) continue;
54
+ const full = resolve(root, raw);
55
+ if (!inside(root, full)) continue;
56
+ const path = relative(root, full).split(sep).join("/");
57
+ if (seen.has(path)) continue;
58
+ const exists = existsSync(full);
59
+ if (exists && !statSync(full).isFile()) continue;
60
+ if (!exists && !(creates && existsSync(dirname(full)))) continue;
61
+ seen.add(path);
62
+ files.push({ path, access: exists ? "edit" : "create", purpose: exists ? "Named in the plan's step; change it, or mark it reference if it is only read" : "The plan's step creates it" });
63
+ }
64
+ return files;
65
+ }
66
+
67
+ /** The domain a step's own words name, when exactly one does. */
68
+ export function stepDomain(text: string): Domain | undefined {
69
+ const tag = /\[(DEV|DESIGN|QA|BACKEND|DESIGNER)\]|\((backend|designer|qa)\)|^\s*(?:[-*\d.)\s]*)(backend|designer|qa)\s*[:—-]/im.exec(text);
70
+ const named = (tag?.[1] ?? tag?.[2] ?? tag?.[3])?.toLowerCase();
71
+ if (named) return named === "dev" ? "backend" : named === "design" ? "designer" : (named as Domain);
72
+ const hits = DOMAIN_WORDS.filter(([, words]) => words.test(text)).map(([domain]) => domain);
73
+ return hits.length === 1 ? hits[0] : undefined;
74
+ }
75
+
76
+ function clean(text: string): string {
77
+ return text.replace(/^\s*(?:[-*]|\d+[.)])\s+/, "").replace(/\s+/g, " ").trim();
78
+ }
79
+
80
+ /** Drafts for every step of `plan`, small consecutive same-domain steps folded together. */
81
+ export function draftAssignments(plan: string, cwd: string): DraftAssignment[] {
82
+ const blocks = planStepBlocks(plan)?.blocks;
83
+ const steps = blocks && blocks.length > 0 ? blocks : planSteps(plan);
84
+ const singles = steps.map((text, index) => ({ step: index + 1, text: clean(text), files: stepFiles(text, cwd), domain: stepDomain(text) }));
85
+ const drafts: DraftAssignment[] = [];
86
+ for (const single of singles) {
87
+ const last = drafts.at(-1);
88
+ const small = single.files.length <= SMALL_STEP_FILES;
89
+ const lastSmall = last && last.steps.length < MAX_FOLD && last.files.length <= last.steps.length * SMALL_STEP_FILES
90
+ && last.steps.every((step) => (singles[step - 1]?.files.length ?? 0) <= SMALL_STEP_FILES);
91
+ if (last && small && lastSmall && single.domain && last.domain === single.domain && last.steps.at(-1) === single.step - 1) {
92
+ last.steps.push(single.step);
93
+ last.id = `steps-${last.steps[0]}-${single.step}`;
94
+ last.objective = `Steps ${last.steps[0]}-${single.step}: ${last.actions.map((action) => action.instruction).concat(single.text).join("; ")}`;
95
+ last.actions.push({ step: last.actions.length + 1, instruction: single.text });
96
+ for (const file of single.files) if (!last.files.some((entry) => entry.path === file.path)) last.files.push(file);
97
+ continue;
98
+ }
99
+ drafts.push({
100
+ steps: [single.step], id: `step-${single.step}`, ...(single.domain ? { domain: single.domain } : {}),
101
+ objective: `Step ${single.step}: ${single.text}`, actions: [{ step: 1, instruction: single.text }], files: single.files,
102
+ });
103
+ }
104
+ return drafts;
105
+ }
106
+
107
+ /** The drafts as the oracle reads them: one compact line each, JSON for the files. */
108
+ export function draftAssignmentsNote(drafts: readonly DraftAssignment[]): string {
109
+ if (drafts.length === 0) return "";
110
+ const lines = drafts.map((draft) => {
111
+ const label = draft.steps.length > 1 ? `Steps ${draft.steps[0]}-${draft.steps.at(-1)}` : `Step ${draft.steps[0]}`;
112
+ return `- ${label} → id "${draft.id}"${draft.domain ? `, domain ${draft.domain}` : ""}; files ${JSON.stringify(draft.files.map(({ path, access }) => ({ path, access })))}${draft.steps.length > 1 ? " (small steps folded into one worker run)" : ""}`;
113
+ });
114
+ return [
115
+ "Draft assignments from the plan (the engine read the step texts and checked each named file exists). Start each workerAssignment from its draft: keep the id and files, mark files only read as reference, and add the tools, contracts and verification yourself. Steps without files need their files found first.",
116
+ ...lines,
117
+ ].join("\n");
118
+ }