@a-t-h-i/bot-lobby 0.5.1 → 0.6.0

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.
@@ -19,7 +19,8 @@ import { overThreshold } from "../knowledge/compactor.ts";
19
19
  import { applyApprovalChoice, describeTask, describeOversizedKnowledge, type ApprovalChoice } from "../workflow/workflow.ts";
20
20
  import { applyStatus, registerRevealShortcut, setMinimized } from "./ui.ts";
21
21
  import { openSettings } from "./settings-ui.ts";
22
- import { kickoff, startTask } from "./start-task.ts";
22
+ import { kickoff, startPlannedTask, startTask } from "./start-task.ts";
23
+ import { setAuto, toggleOwnAuto } from "./owner.ts";
23
24
  import { autoOpenLobby, showLobby } from "../lobby/runtime.ts";
24
25
  import { modelRef, thinkingMismatches } from "./model-support.ts";
25
26
  import { describeRun, runFromLog } from "./run-summary.ts";
@@ -28,6 +29,7 @@ import { modelLookup } from "./tools.ts";
28
29
  const HELP = [
29
30
  "/bot-lobby Open the lobby: tasks, plan, quick fix, metrics (alt+l)",
30
31
  "/bot-lobby <request> Start a task through the workflow",
32
+ "/bot-lobby --task [--auto] <request> Start a task even when the request begins with a subcommand word",
31
33
  "/bot-lobby status [taskId] Show the active task",
32
34
  "/bot-lobby tasks List tasks",
33
35
  "/bot-lobby pause|resume Pause or resume the active task",
@@ -39,21 +41,29 @@ const HELP = [
39
41
  "/bot-lobby config Show effective configuration",
40
42
  "/bot-lobby minimize|restore Hide or restore bot-lobby for this session (ctrl+shift+m)",
41
43
  "/bot-lobby claim <taskId> Take ownership of an orphaned task",
44
+ "/bot-lobby auto [on|off] Auto mode: the oracle drives this session's task without asking (alt+g)",
45
+ "/bot-lobby start-plan PLAN-… [auto] Start a planned task here; its agreed plan needs no approval",
42
46
  "/bot-lobby help This help",
43
47
  ].join("\n");
44
48
 
45
49
  /** Subcommands only win when no free-form text follows (so tasks still start). */
46
- const SUBCOMMANDS = new Set(["lobby", "help", "status", "runs", "tasks", "pause", "resume", "cancel", "approve", "amend", "decline", "knowledge", "config", "settings", "minimize", "restore", "claim"]);
50
+ const SUBCOMMANDS = new Set(["lobby", "help", "status", "runs", "tasks", "pause", "resume", "cancel", "approve", "amend", "decline", "knowledge", "config", "settings", "minimize", "restore", "claim", "auto", "start-plan"]);
47
51
 
48
52
  function isTaskId(value: string | undefined): boolean {
49
53
  return Boolean(value && /^TASK-/.test(value));
50
54
  }
51
55
 
52
- function parseCommand(args: string): { sub: string | undefined; rest: string[]; restText: string } {
56
+ export function parseCommand(args: string): { sub: string | undefined; rest: string[]; restText: string; auto?: boolean } {
53
57
  const trimmed = args.trim();
58
+ // `--task [--auto] <request>` always starts a task (a background session started from the lobby sends this).
59
+ const forced = /^--task(\s+--auto)?(?:\s+([\s\S]*))?$/.exec(trimmed);
60
+ if (forced) return { sub: undefined, rest: [], restText: (forced[2] ?? "").trim(), ...(forced[1] ? { auto: true } : {}) };
54
61
  const [sub, ...rest] = trimmed.split(/\s+/).filter(Boolean);
55
62
  if (!sub || !SUBCOMMANDS.has(sub)) return { sub: undefined, rest: [], restText: trimmed };
56
- if (sub !== "amend" && sub !== "claim" && rest.length > 0 && !(rest.length === 1 && isTaskId(rest[0]))) {
63
+ const takesArgs = sub === "amend" || sub === "claim"
64
+ || (sub === "auto" && rest.length === 1 && /^(on|off)$/i.test(rest[0]!))
65
+ || (sub === "start-plan" && rest.length >= 1 && rest.length <= 2 && /^PLAN-/.test(rest[0]!) && (rest.length === 1 || rest[1] === "auto"));
66
+ if (!takesArgs && rest.length > 0 && !(rest.length === 1 && isTaskId(rest[0]))) {
57
67
  return { sub: undefined, rest: [], restText: trimmed };
58
68
  }
59
69
  return { sub, rest, restText: trimmed.slice(sub.length).trim() };
@@ -187,6 +197,17 @@ function showConfig(ctx: ExtensionCommandContext): void {
187
197
  ctx.ui.notify(`${globalConfigPath()}\n${JSON.stringify(config, null, 2)}${notes}`, warnings.length > 0 ? "warning" : "info");
188
198
  }
189
199
 
200
+ /** `/bot-lobby auto [on|off]`: switch (or set) auto mode for this session's task. */
201
+ function autoCommand(ctx: ExtensionCommandContext, configDir: string, value: string | undefined): void {
202
+ if (!value) return ctx.ui.notify(`bot-lobby: ${toggleOwnAuto()}`, "info");
203
+ const root = detectProjectRoot(ctx.cwd, configDir);
204
+ const task = activeTask(root, configDir, ctx.sessionManager.getSessionId());
205
+ if (!task) return ctx.ui.notify("bot-lobby: no active task in this session — auto mode applies to a task", "warning");
206
+ const on = value.toLowerCase() === "on";
207
+ setAuto(root, configDir, task.id, on, ctx.sessionManager.getSessionId());
208
+ ctx.ui.notify(`bot-lobby: auto mode ${on ? "on" : "off"} for ${task.id}`, "info");
209
+ }
210
+
190
211
  export function registerCommands(pi: ExtensionAPI, configDir: string): void {
191
212
  registerRevealShortcut(pi, configDir);
192
213
  pi.registerCommand("bot-lobby", {
@@ -197,13 +218,13 @@ export function registerCommands(pi: ExtensionAPI, configDir: string): void {
197
218
  return filtered.length > 0 ? filtered : null;
198
219
  },
199
220
  handler: async (args, ctx) => {
200
- const { sub, rest, restText } = parseCommand(args ?? "");
221
+ const { sub, rest, restText, auto } = parseCommand(args ?? "");
201
222
  if (!sub) {
202
223
  if (!restText) {
203
224
  if (!showLobby()) ctx.ui.notify(HELP, "info");
204
225
  return;
205
226
  }
206
- if (await startTask(pi, ctx, configDir, restText)) autoOpenLobby();
227
+ if (await startTask(pi, ctx, configDir, restText, auto ? { auto } : {})) autoOpenLobby();
207
228
  return;
208
229
  }
209
230
  switch (sub) {
@@ -242,6 +263,13 @@ export function registerCommands(pi: ExtensionAPI, configDir: string): void {
242
263
  return applyStatus(ctx, detectProjectRoot(ctx.cwd, configDir), configDir);
243
264
  case "claim":
244
265
  return claimTaskCommand(ctx, configDir, rest[0]);
266
+ case "auto":
267
+ return autoCommand(ctx, configDir, rest[0]);
268
+ case "start-plan": {
269
+ const started = await startPlannedTask(pi, ctx, configDir, rest[0]!, { auto: rest[1] === "auto" });
270
+ if (typeof started === "string") return ctx.ui.notify(`bot-lobby: ${started}`, "warning");
271
+ return autoOpenLobby();
272
+ }
245
273
  default:
246
274
  return showConfig(ctx);
247
275
  }
package/src/pi/events.ts CHANGED
@@ -13,8 +13,9 @@ import { isSubagentProcess, visibleTools } from "./quiet.ts";
13
13
  import { registerQuietTools } from "./tool-renderers.ts";
14
14
  import { taskRequest, type Task } from "../schemas/task.ts";
15
15
  import { pendingComments, readPlanComments, type PlanComment } from "../state/comments.ts";
16
+ import { isAutoMode } from "../state/auto.ts";
16
17
 
17
- export function masterTaskContext(task: Task, comments: readonly PlanComment[] = []): string {
18
+ export function masterTaskContext(task: Task, comments: readonly PlanComment[] = [], auto = false): string {
18
19
  const open = pendingComments(comments);
19
20
  return [
20
21
  `Task ${task.id}: ${task.title}`,
@@ -23,6 +24,8 @@ export function masterTaskContext(task: Task, comments: readonly PlanComment[] =
23
24
  task.plan ? `Approved plan:\n${truncate(task.plan, 3000)}` : "",
24
25
  task.amendments.length > 0 ? `User amendments:\n${task.amendments.map((entry) => `- ${entry}`).join("\n")}` : "",
25
26
  open.length > 0 ? `Open plan comments (from the lobby):\n${open.map((comment) => `- ${truncate(comment.text, 600)}`).join("\n")}` : "",
27
+ task.approvedPlan ? `The user agreed this task's plan in the planning panel (${task.approvedPlan}): follow it, do not ask them to approve a proposal (propose is approved automatically), and answer open questions from the plan.` : "",
28
+ auto ? "AUTO MODE is on: drive this task to completion without the user. Do not ask them anything (clarify and ask_user_question are not answered); decide yourself, record each decision, and keep calling the orchestrate tool until the task is complete or truly blocked." : "",
26
29
  ]
27
30
  .filter((line) => line.length > 0)
28
31
  .join("\n\n");
@@ -89,7 +92,7 @@ export function registerLifecycle(pi: ExtensionAPI, configDir: string): void {
89
92
  const selected = selectKnowledge(`${taskRequest(task)} ${task.proposal ?? ""}`, slices);
90
93
  event.systemPromptOptions.sections["bot-lobby"] = compilePrompt({
91
94
  domain: "master",
92
- task: masterTaskContext(task, readPlanComments(root, configDir, task.id)),
95
+ task: masterTaskContext(task, readPlanComments(root, configDir, task.id), isAutoMode(root, configDir, task.id)),
93
96
  standards: selected.standards,
94
97
  knowledge: selected.knowledge,
95
98
  decisions: selected.decisions,
package/src/pi/notify.ts CHANGED
@@ -35,6 +35,24 @@ export function ping(state: TaskState, title: string): void {
35
35
  if (payload) process.stderr.write(payload);
36
36
  }
37
37
 
38
+ const waiting = new Set<string>();
39
+
40
+ /**
41
+ * Ping for a task's new state. A proposal approved without asking (auto mode,
42
+ * a plan agreed in the planning panel, or approvals switched off) passes
43
+ * through awaiting_approval within one step, so that ping waits a tick and
44
+ * fires once, only if the task still waits for the user.
45
+ */
46
+ export function pingTransition(task: { id: string; state: TaskState; title: string }, later: (fn: () => void) => void = queueMicrotask): void {
47
+ if (task.state !== "awaiting_approval") return ping(task.state, task.title);
48
+ if (waiting.has(task.id)) return;
49
+ waiting.add(task.id);
50
+ later(() => {
51
+ waiting.delete(task.id);
52
+ if (task.state === "awaiting_approval") ping(task.state, task.title);
53
+ });
54
+ }
55
+
38
56
  /** Emit one ping when an approval is first recorded; never from a subagent. */
39
57
  export function pingApproval(domain: string, detail: string): void {
40
58
  if (isSubagentProcess()) return;
@@ -0,0 +1,216 @@
1
+ /**
2
+ * What a session does for the task it drives, on its own clock. Every few
3
+ * seconds a session that owns a task (in the terminal or headless, started
4
+ * from another window's lobby) passes on what other sessions left for its
5
+ * oracle, plan comments and inbox messages, and in auto mode keeps the oracle
6
+ * going whenever its turn ends before the task is done. Subagents never own
7
+ * tasks, so none of this runs in them.
8
+ */
9
+ import type { KeyId } from "@earendil-works/pi-tui";
10
+ import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
11
+ import { TERMINAL_STATES, type Task } from "../schemas/task.ts";
12
+ import { activeTask, loadTask } from "../state/persistence.ts";
13
+ import { detectProjectRoot, loadConfig } from "../state/project.ts";
14
+ import { commentMessage, markCommentsDelivered, readPlanComments, undeliveredComments } from "../state/comments.ts";
15
+ import { inboxMessage, markInboxDelivered, readInbox } from "../state/inbox.ts";
16
+ import { isAutoMode, setAutoMode } from "../state/auto.ts";
17
+ import { isSubagentProcess } from "./quiet.ts";
18
+ import { isMinimized } from "./ui.ts";
19
+
20
+ /** How often the owning session looks for comments, messages and auto-mode work. */
21
+ export const OWNER_POLL_MS = 3000;
22
+ /** Auto mode stops nudging after this many nudged turns in a row that left the task unchanged. */
23
+ export const MAX_IDLE_NUDGES = 3;
24
+ /** The default key that switches auto mode; `lobby.keys.toggleAuto` rebinds it. */
25
+ export const AUTO_KEY = "alt+g";
26
+
27
+ export type OwnerEvent =
28
+ | { kind: "comments" | "inbox"; taskId: string; count: number }
29
+ | { kind: "auto"; taskId: string; on: boolean }
30
+ | { kind: "nudge"; taskId: string }
31
+ | { kind: "stalled"; taskId: string };
32
+
33
+ interface Owner {
34
+ pi: ExtensionAPI;
35
+ ctx: ExtensionContext;
36
+ root: string;
37
+ configDir: string;
38
+ timer?: ReturnType<typeof setInterval>;
39
+ auto?: AutoTrack;
40
+ }
41
+
42
+ let owner: Owner | undefined;
43
+ let listener: ((event: OwnerEvent) => void) | undefined;
44
+
45
+ /** Hear what the owner did (the lobby logs it in its activity feed). */
46
+ export function onOwnerEvent(fn: ((event: OwnerEvent) => void) | undefined): void {
47
+ listener = fn;
48
+ }
49
+
50
+ function ownTask(state: Owner): Task | undefined {
51
+ return activeTask(state.root, state.configDir, state.ctx.sessionManager.getSessionId());
52
+ }
53
+
54
+ function live(task: Task | undefined): task is Task {
55
+ return Boolean(task && !TERMINAL_STATES.includes(task.state));
56
+ }
57
+
58
+ /** Pass new plan comments on this session's task to its Master (held while minimized or paused). */
59
+ export function deliverComments(): number {
60
+ const state = owner;
61
+ if (!state || isMinimized()) return 0;
62
+ const task = ownTask(state);
63
+ if (!live(task) || task.paused) return 0;
64
+ const fresh = undeliveredComments(readPlanComments(state.root, state.configDir, task.id));
65
+ if (fresh.length === 0) return 0;
66
+ const current = loadTask(state.root, state.configDir, task.id) ?? task;
67
+ state.pi.sendUserMessage(commentMessage(task.id, fresh, Boolean(current.plan)), state.ctx.isIdle() ? undefined : { deliverAs: "steer" });
68
+ markCommentsDelivered(state.root, state.configDir, task.id, fresh.map((comment) => comment.id));
69
+ listener?.({ kind: "comments", taskId: task.id, count: fresh.length });
70
+ return fresh.length;
71
+ }
72
+
73
+ /** Pass messages other sessions left for this session's task to its Master, as if typed here. */
74
+ export function deliverInbox(): number {
75
+ const state = owner;
76
+ if (!state) return 0;
77
+ const task = ownTask(state);
78
+ if (!live(task)) return 0;
79
+ const fresh = readInbox(state.root, state.configDir, task.id).filter((message) => !message.delivered);
80
+ if (fresh.length === 0) return 0;
81
+ state.pi.sendUserMessage(inboxMessage(fresh), state.ctx.isIdle() ? undefined : { deliverAs: "steer" });
82
+ markInboxDelivered(state.root, state.configDir, task.id, fresh.map((message) => message.id));
83
+ listener?.({ kind: "inbox", taskId: task.id, count: fresh.length });
84
+ return fresh.length;
85
+ }
86
+
87
+ /** What auto mode remembers between nudges: the task as it was, and how many nudges changed nothing. */
88
+ export interface AutoTrack {
89
+ fingerprint: string;
90
+ idle: number;
91
+ stalled: boolean;
92
+ }
93
+
94
+ /** Everything a workflow step changes, cheaply: two equal fingerprints mean the oracle made no progress. */
95
+ export function taskFingerprint(task: Task): string {
96
+ return [
97
+ task.state,
98
+ task.paused,
99
+ task.updatedAt,
100
+ task.proposal?.length ?? 0,
101
+ task.plan?.length ?? 0,
102
+ task.decisions.length,
103
+ task.approvals.length,
104
+ task.blockers.length,
105
+ task.reviewRecords.length,
106
+ task.workerRuns?.length ?? 0,
107
+ task.runLog?.length ?? 0,
108
+ ].join("|");
109
+ }
110
+
111
+ /**
112
+ * Whether to nudge an idle oracle in auto mode. Each nudge that leaves the
113
+ * task unchanged counts; after `MAX_IDLE_NUDGES` of them auto mode stalls
114
+ * (and says so once) until the task changes again.
115
+ */
116
+ export function autoStep(previous: AutoTrack | undefined, fingerprint: string): { nudge: boolean; track: AutoTrack; stalledNow: boolean } {
117
+ const idle = previous && previous.fingerprint === fingerprint ? previous.idle + 1 : 0;
118
+ if (idle >= MAX_IDLE_NUDGES) {
119
+ return { nudge: false, track: { fingerprint, idle, stalled: true }, stalledNow: !previous?.stalled };
120
+ }
121
+ return { nudge: true, track: { fingerprint, idle, stalled: false }, stalledNow: false };
122
+ }
123
+
124
+ export function autoNudge(task: Task): string {
125
+ return `Auto mode: ${task.id} is ${task.state}. Keep driving it to completion with the orchestrate tool: decide anything open yourself and record it. Do not wait for me.`;
126
+ }
127
+
128
+ /** In auto mode, start the idle oracle's next turn (unless it keeps making no progress). */
129
+ export function driveAuto(): boolean {
130
+ const state = owner;
131
+ if (!state || isMinimized()) return false;
132
+ const task = ownTask(state);
133
+ if (!live(task) || task.paused || !isAutoMode(state.root, state.configDir, task.id)) {
134
+ state.auto = undefined;
135
+ return false;
136
+ }
137
+ if (!state.ctx.isIdle()) return false;
138
+ const step = autoStep(state.auto, taskFingerprint(task));
139
+ state.auto = step.track;
140
+ if (step.stalledNow) {
141
+ listener?.({ kind: "stalled", taskId: task.id });
142
+ state.ctx.ui.notify(`bot-lobby: auto mode — the oracle made no progress on ${task.id} after ${MAX_IDLE_NUDGES} nudges; it needs you.`, "warning");
143
+ }
144
+ if (!step.nudge) return false;
145
+ state.pi.sendUserMessage(autoNudge(task));
146
+ listener?.({ kind: "nudge", taskId: task.id });
147
+ return true;
148
+ }
149
+
150
+ /** Switch auto mode for a task; switching it on for this session's own idle task starts the oracle at once. */
151
+ export function setAuto(root: string, configDir: string, taskId: string, on: boolean, by?: string): void {
152
+ setAutoMode(root, configDir, taskId, on, by);
153
+ listener?.({ kind: "auto", taskId, on });
154
+ const state = owner;
155
+ if (!state || state.root !== root) return;
156
+ const task = ownTask(state);
157
+ if (task?.id !== taskId) return;
158
+ state.auto = undefined;
159
+ if (on) driveAuto();
160
+ }
161
+
162
+ /** Switch auto mode for this session's task; returns the notice to show. */
163
+ export function toggleOwnAuto(): string {
164
+ const state = owner;
165
+ if (!state) return "bot-lobby is not running in this session";
166
+ const task = ownTask(state);
167
+ if (!live(task)) return "no active task in this session — auto mode applies to a task";
168
+ const on = !isAutoMode(state.root, state.configDir, task.id);
169
+ setAuto(state.root, state.configDir, task.id, on, state.ctx.sessionManager.getSessionId());
170
+ return on ? `auto mode on for ${task.id}: the oracle drives it to completion without asking you` : `auto mode off for ${task.id}: the oracle asks you again`;
171
+ }
172
+
173
+ /** One tick of the owner's clock. */
174
+ export function ownerTick(): void {
175
+ deliverComments();
176
+ deliverInbox();
177
+ driveAuto();
178
+ }
179
+
180
+ function stop(): void {
181
+ if (owner?.timer) clearInterval(owner.timer);
182
+ owner = undefined;
183
+ }
184
+
185
+ /** Start the owner's clock for this session (called on session_start; exported for tests). */
186
+ export function startOwner(pi: ExtensionAPI, ctx: ExtensionContext, configDir: string, pollMs = OWNER_POLL_MS): void {
187
+ stop();
188
+ if (isSubagentProcess()) return;
189
+ owner = { pi, ctx, root: detectProjectRoot(ctx.cwd, configDir), configDir };
190
+ if (pollMs > 0) {
191
+ owner.timer = setInterval(() => ownerTick(), pollMs);
192
+ owner.timer.unref?.();
193
+ }
194
+ }
195
+
196
+ export function registerOwner(pi: ExtensionAPI, configDir: string): void {
197
+ if (isSubagentProcess()) return;
198
+ const track = (ctx: ExtensionContext) => {
199
+ if (owner) owner.ctx = ctx;
200
+ };
201
+ pi.on("session_start", (_event, ctx) => startOwner(pi, ctx, configDir));
202
+ pi.on("session_shutdown", () => stop());
203
+ pi.on("agent_start", (_event, ctx) => track(ctx));
204
+ pi.on("agent_end", (_event, ctx) => track(ctx));
205
+ // Auto mode has nobody to answer a question: tell the oracle to decide instead.
206
+ pi.on("tool_call", (event, ctx) => {
207
+ if (event.toolName !== "ask_user_question" || !owner) return undefined;
208
+ const task = activeTask(owner.root, owner.configDir, ctx.sessionManager.getSessionId());
209
+ if (!live(task) || !isAutoMode(owner.root, owner.configDir, task.id)) return undefined;
210
+ return { block: true, reason: `Auto mode is on for ${task.id}: nobody will answer. Decide this yourself from the request, the plan and your reconnaissance, record the decision, and continue.` };
211
+ });
212
+ pi.registerShortcut((loadConfig().lobby.keys.toggleAuto ?? AUTO_KEY) as KeyId, {
213
+ description: "bot-lobby: switch auto mode for this session's task",
214
+ handler: (ctx) => ctx.ui.notify(`bot-lobby: ${toggleOwnAuto()}`, "info"),
215
+ });
216
+ }
@@ -352,14 +352,18 @@ function entryDescription(kind: SettingsKind, view: EntryView): string {
352
352
  /** The lobby's on/off settings as the settings menu lists them; `panel:*` are the Lobby tab's panes. */
353
353
  export type LobbySwitch = "autoOpen" | "autoAsk" | "mouse" | "issues" | `panel:${LobbyPanel}`;
354
354
 
355
- const PANEL_SWITCH_LABELS: Record<LobbyPanel, string> = { scene: "Zen scene pane", conversation: "Conversation pane", activity: "Activity log pane", thinking: "Thinking pane" };
355
+ const PANEL_SWITCH_LABELS: Record<LobbyPanel, string> = { animations: "Animations in the lobby", conversation: "Conversation pane", activity: "Activity log pane", thinking: "Thinking pane" };
356
356
 
357
357
  export const LOBBY_SWITCHES: ReadonlyArray<{ id: LobbySwitch; label: string; help: string }> = [
358
358
  { id: "autoOpen", label: "Open with a task", help: "open the lobby when this session starts or resumes a task" },
359
359
  { id: "autoAsk", label: "Ask at once", help: "put the panel's questions to you as soon as a round ends, while the Plan tab is open" },
360
360
  { id: "mouse", label: "Mouse", help: "click tabs and draft lines, scroll with the wheel (shift+drag still selects text)" },
361
361
  { id: "issues", label: "Issues tab", help: "the GitHub Issues tab" },
362
- ...LOBBY_PANELS.map((panel) => ({ id: `panel:${panel}` as const, label: PANEL_SWITCH_LABELS[panel], help: "shown on the Lobby tab; its key in the lobby toggles it too" })),
362
+ ...LOBBY_PANELS.map((panel) => ({
363
+ id: `panel:${panel}` as const,
364
+ label: PANEL_SWITCH_LABELS[panel],
365
+ help: panel === "animations" ? "the animated oracle and agents on the Lobby tab; off keeps only the task's status (they still show above pi's editor while the lobby is hidden); alt+z toggles it too" : "shown on the Lobby tab; its key in the lobby toggles it too",
366
+ })),
363
367
  ];
364
368
 
365
369
  export function lobbySwitch(config: BotLobbyConfig, id: LobbySwitch): boolean {
@@ -12,6 +12,8 @@ import { transition } from "../state/task-state.ts";
12
12
  import { shortTitle } from "../text.ts";
13
13
  import { applyStatus } from "./ui.ts";
14
14
  import { applyMasterModel } from "./settings-ui.ts";
15
+ import { setAutoMode } from "../state/auto.ts";
16
+ import { loadPlannedTask, markPlannedTaskStarted, plannedTaskRequest } from "../state/backlog.ts";
15
17
 
16
18
  function uniqueTaskId(root: string, configDir: string, request: string): string {
17
19
  const base = nextTaskId(request);
@@ -41,7 +43,16 @@ export function kickoff(task: Task): string {
41
43
  * Returns the task, or undefined (with a warning) when this session already
42
44
  * owns an active one.
43
45
  */
44
- export async function startTask(pi: ExtensionAPI, ctx: ExtensionContext, configDir: string, request: string): Promise<Task | undefined> {
46
+ export interface StartOptions {
47
+ /** The planned task (PLAN-…) this task starts from: the user agreed its plan, so its proposal needs no approval. */
48
+ approvedPlan?: string;
49
+ /** Start in auto mode: the oracle drives it to completion without asking. */
50
+ auto?: boolean;
51
+ /** The task's short title (a planned task's own title); derived from the request otherwise. */
52
+ title?: string;
53
+ }
54
+
55
+ export async function startTask(pi: ExtensionAPI, ctx: ExtensionContext, configDir: string, request: string, options: StartOptions = {}): Promise<Task | undefined> {
45
56
  const root = detectProjectRoot(ctx.cwd, configDir);
46
57
  ensureProjectStructure(root, configDir);
47
58
  const sessionId = ctx.sessionManager.getSessionId();
@@ -50,10 +61,14 @@ export async function startTask(pi: ExtensionAPI, ctx: ExtensionContext, configD
50
61
  ctx.ui.notify(`bot-lobby ${existing.id} is already active in this session. Finish it or run /bot-lobby cancel ${existing.id} first.`, "warning");
51
62
  return undefined;
52
63
  }
53
- const task = createTask(uniqueTaskId(root, configDir, request), shortTitle(request), new Date().toISOString(), request, sessionId);
64
+ const task = createTask(uniqueTaskId(root, configDir, options.title ?? request), options.title ?? shortTitle(request), new Date().toISOString(), request, sessionId);
65
+ if (options.approvedPlan) task.approvedPlan = options.approvedPlan;
54
66
  createTaskDir(root, configDir, task);
55
67
  transition(task, "clarifying");
56
68
  saveTask(root, configDir, task);
69
+ if (options.auto) setAutoMode(root, configDir, task.id, true, sessionId);
70
+ // A session that starts a task is named after it, so /resume and the lobby list it by name.
71
+ if (!pi.getSessionName()) pi.setSessionName(task.title);
57
72
  applyStatus(ctx, root, configDir);
58
73
  await applyMasterModel(pi, ctx, loadConfig());
59
74
  ctx.ui.notify(`bot-lobby ${task.id} started`, "info");
@@ -61,3 +76,19 @@ export async function startTask(pi: ExtensionAPI, ctx: ExtensionContext, configD
61
76
  pi.sendUserMessage(kickoff(task), ctx.isIdle() ? undefined : { deliverAs: "followUp" });
62
77
  return task;
63
78
  }
79
+
80
+ /**
81
+ * Start a task saved from the planning panel in this session. The user
82
+ * already agreed its plan, so the task carries it as approved and its
83
+ * proposal goes through without asking. Returns the task, or a reason.
84
+ */
85
+ export async function startPlannedTask(pi: ExtensionAPI, ctx: ExtensionContext, configDir: string, planId: string, options: { auto?: boolean } = {}): Promise<Task | string> {
86
+ const root = detectProjectRoot(ctx.cwd, configDir);
87
+ const plan = loadPlannedTask(root, configDir, planId);
88
+ if (!plan) return `no planned task ${planId}`;
89
+ if (plan.status !== "pending") return `${planId} was already started${plan.startedTaskId ? ` as ${plan.startedTaskId}` : ""}`;
90
+ const task = await startTask(pi, ctx, configDir, plannedTaskRequest(plan), { approvedPlan: plan.id, title: plan.title, ...(options.auto ? { auto: true } : {}) });
91
+ if (!task) return `this session already drives a task; finish or cancel it first`;
92
+ markPlannedTaskStarted(root, configDir, plan.id, task.id);
93
+ return task;
94
+ }
package/src/pi/ui.ts CHANGED
@@ -246,15 +246,15 @@ export class ZenScene {
246
246
  * an expression frame, the widget state or the elapsed second, so any other
247
247
  * repaint (typing, streaming output) reuses the last lines.
248
248
  */
249
- lines(width: number, rows: number, theme: Theme | undefined, now = Date.now()): string[] {
249
+ lines(width: number, rows: number, theme: Theme | undefined, now = Date.now(), still = false): string[] {
250
250
  const expressions = Object.fromEntries(EXPRESSION_KEYS.map((key) => [key, this.expressions[key].frame])) as Partial<Record<ExpressionKey, number>>;
251
251
  const variants = Object.fromEntries(SLOT_IDS.map((id) => [id, this.expressions[id].variant])) as Partial<Record<SlotId, number>>;
252
252
  const quiet = isQuiet();
253
253
  const frameKey = [...EXPRESSION_KEYS.map((key) => expressions[key] ?? 0), ...SLOT_IDS.map((id) => variants[id] ?? 0)].join(",");
254
254
  const motion = this.motion(now);
255
- const key = `${width}|${rows}|${this.tick}|${frameKey}|${motion.phase}|${motion.talk}|${zenVersion}|${Math.floor(now / 1000)}|${quiet}`;
255
+ const key = `${width}|${rows}|${this.tick}|${frameKey}|${motion.phase}|${motion.talk}|${zenVersion}|${Math.floor(now / 1000)}|${quiet}|${still}`;
256
256
  if (this.cache && this.cache.key === key && this.cache.theme === theme) return this.cache.lines;
257
- const opts = { width, rows, tick: this.tick, theme, expressions, variants, oracleActivity, oracleMotion: motion };
257
+ const opts = { width, rows, tick: this.tick, theme, expressions, variants, oracleActivity, oracleMotion: motion, still };
258
258
  const lines = panelLines(zenState.task, zenState.runs, now, quiet, opts).map((line) => truncateToWidth(line, width));
259
259
  this.cache = { key, theme, lines };
260
260
  return lines;
@@ -202,12 +202,20 @@ export function largeLines(
202
202
  width: number,
203
203
  budget: number,
204
204
  theme?: PanelTheme,
205
+ still = false,
205
206
  ): string[] {
206
207
  if (width < LARGE_MIN_WIDTH) return [];
207
208
  const head = boxLines(input, width, theme);
208
209
  const alert = input.alert ? [alertLine(input.alert, width, theme, input.alertKind ?? "warning")] : [];
209
210
  const avail = Math.max(0, lineBudget(budget) - head.length - alert.length);
210
- return [...head, ...alert, ...bodyLines(input, width, theme, avail)];
211
+ return [...head, ...alert, ...(still ? stillLines(input, width, theme, avail) : bodyLines(input, width, theme, avail))];
212
+ }
213
+
214
+ /** The scene without its animations: what the agents are doing, then the task checklist. */
215
+ function stillLines(input: LargeSceneInput, width: number, theme: PanelTheme | undefined, avail: number): string[] {
216
+ const feed = input.feed && avail >= 1 ? [feedRow(input.feed, width, theme)] : [];
217
+ const entries = clamp(avail - feed.length - 1, 0, MAX_TASK_ROWS);
218
+ return [...feed, ...sectionLines(input, width, theme, entries)];
211
219
  }
212
220
 
213
221
  /** Clamp a caller line budget to the scene cap, ignoring non-finite input. */
package/src/pi/zen.ts CHANGED
@@ -520,7 +520,8 @@ function compactPanel(
520
520
  ): string[] {
521
521
  const metrics = sceneMetrics(task, runs, now);
522
522
  const expressions = opts.expressions ?? {};
523
- const fixed = [...bannerLines(width), headerLine(task, now, quiet), ...compactStrip(task.state, metrics.slots, expressions, opts.theme)];
523
+ const strip = opts.still ? [] : compactStrip(task.state, metrics.slots, expressions, opts.theme);
524
+ const fixed = [...bannerLines(width), headerLine(task, now, quiet), ...strip];
524
525
  const tail = tailLines(task, runs, now, tick, steps, opts.theme);
525
526
  const room = Math.max(0, MAX_PANEL_LINES - fixed.length - tail.length);
526
527
  return [...fixed, ...tail, ...checklistLines(steps, room)].map((line) => truncateToWidth(line, width));
@@ -613,6 +614,8 @@ export interface PanelOptions {
613
614
  oracleActivity?: string;
614
615
  /** Caller-clocked oracle animation: the expression's sub-step and the lip-sync shape. */
615
616
  oracleMotion?: OracleMotion;
617
+ /** Leave out the oracle and agent animations: status, alert, activity and checklist only. */
618
+ still?: boolean;
616
619
  }
617
620
 
618
621
  /** The oracle's clocked animation state beyond its expression frame (see expressions.ts). */
@@ -640,8 +643,9 @@ export function panelLines(
640
643
  const tick = opts.tick ?? 0;
641
644
  const steps = planChecklist(task.plan ?? "", runs);
642
645
  const budget = largeLineBudget(opts.rows ?? DEFAULT_ROWS);
643
- if (width >= LARGE_MIN_WIDTH && budget >= MIN_LARGE_LINES) {
644
- const scene = largeLines(sceneInput(task, runs, now, quiet, tick, steps, opts), width, budget, opts.theme);
646
+ // The still scene has no tower or agent strip to fit, so any height keeps the large tier's status box.
647
+ if (width >= LARGE_MIN_WIDTH && (budget >= MIN_LARGE_LINES || opts.still)) {
648
+ const scene = largeLines(sceneInput(task, runs, now, quiet, tick, steps, opts), width, budget, opts.theme, opts.still);
645
649
  return scene.map((line) => truncateToWidth(line, width));
646
650
  }
647
651
  return compactPanel(task, runs, now, quiet, tick, steps, opts, width);
@@ -83,8 +83,13 @@ export function isPanelMember(value: string): value is PanelMember {
83
83
  return (PANEL_MEMBERS as readonly string[]).includes(value);
84
84
  }
85
85
 
86
- /** Lobby panes that can be shown or hidden (the Lobby tab's scene, conversation, activity log and thinking). */
87
- export const LOBBY_PANELS = ["scene", "conversation", "activity", "thinking"] as const;
86
+ /**
87
+ * Lobby panes that can be shown or hidden: the Lobby tab's animated oracle and
88
+ * agents (off by default: the lobby keeps only the task's status, and the
89
+ * animations show above pi's editor while the lobby is hidden), the
90
+ * conversation, the activity log and thinking.
91
+ */
92
+ export const LOBBY_PANELS = ["animations", "conversation", "activity", "thinking"] as const;
88
93
  export type LobbyPanel = (typeof LOBBY_PANELS)[number];
89
94
 
90
95
  /** The full-screen lobby. */
@@ -154,7 +159,7 @@ export const DEFAULT_CONFIG: BotLobbyConfig = {
154
159
  planningPanel: [...PANEL_MEMBERS],
155
160
  autoAsk: true,
156
161
  issues: false,
157
- panels: { scene: true, conversation: true, activity: true, thinking: true },
162
+ panels: { animations: false, conversation: true, activity: true, thinking: true },
158
163
  keys: {},
159
164
  mouse: true,
160
165
  },
@@ -119,6 +119,8 @@ export interface Task {
119
119
  updatedAt: string;
120
120
  /** The pi session (ctx.sessionManager id) that owns this task; absent on legacy tasks. */
121
121
  ownerSessionId?: string;
122
+ /** The planned task (PLAN-…) whose plan the user agreed in the planning panel: its proposal needs no approval. */
123
+ approvedPlan?: string;
122
124
  }
123
125
 
124
126
  export function createTask(
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Auto mode, per task: the oracle drives the task to completion without
3
+ * asking the user anything. The flag lives in its own file beside the task,
4
+ * not in state.json, so any session can switch it (from the lobby, for a task
5
+ * another session drives) without racing the owner's saves of the task.
6
+ */
7
+ import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
8
+ import { dirname, join } from "node:path";
9
+ import { taskDirFor } from "./persistence.ts";
10
+
11
+ interface AutoFile {
12
+ on: boolean;
13
+ at: string;
14
+ /** The session that last switched it. */
15
+ by?: string;
16
+ }
17
+
18
+ export function autoPath(root: string, configDir: string, taskId: string): string {
19
+ return join(taskDirFor(root, configDir, taskId), "auto.json");
20
+ }
21
+
22
+ /** Whether auto mode is on for the task; off when the file is missing or unreadable. */
23
+ export function isAutoMode(root: string, configDir: string, taskId: string): boolean {
24
+ const path = autoPath(root, configDir, taskId);
25
+ if (!existsSync(path)) return false;
26
+ try {
27
+ return (JSON.parse(readFileSync(path, "utf8")) as Partial<AutoFile>).on === true;
28
+ } catch {
29
+ return false;
30
+ }
31
+ }
32
+
33
+ /** Switch auto mode for the task (through a temp file, so a reader never sees half a write). */
34
+ export function setAutoMode(root: string, configDir: string, taskId: string, on: boolean, by?: string, now = new Date()): void {
35
+ const path = autoPath(root, configDir, taskId);
36
+ mkdirSync(dirname(path), { recursive: true });
37
+ const record: AutoFile = { on, at: now.toISOString(), ...(by ? { by } : {}) };
38
+ writeFileSync(`${path}.tmp`, `${JSON.stringify(record)}\n`);
39
+ renameSync(`${path}.tmp`, path);
40
+ }