@a-t-h-i/bot-lobby 0.6.47 → 0.6.48

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.
@@ -68,5 +68,10 @@ fontsource packages, `@fontsource-variable/*`) as files in `webui/dist/assets`,
68
68
  so the Typeface setting works offline. Each is under the SIL Open Font
69
69
  License 1.1 (https://openfontlicense.org): Inter (The Inter Project Authors),
70
70
  Geist and Geist Mono (Vercel), IBM Plex Sans (IBM Corp.), Manrope (The
71
- Manrope Project Authors) and JetBrains Mono (The JetBrains Mono Project
72
- Authors).
71
+ Manrope Project Authors), JetBrains Mono (The JetBrains Mono Project
72
+ Authors), DM Sans (The DM Sans Project Authors), Plus Jakarta Sans (The Plus
73
+ Jakarta Sans Project Authors), Figtree (The Figtree Project Authors), Outfit
74
+ (The Outfit Project Authors), Nunito (The Nunito Project Authors), Space
75
+ Grotesk (The Space Grotesk Project Authors), Source Sans 3 and Source Code Pro
76
+ (Adobe), Fira Code (The Fira Code Project Authors) and Roboto Mono (The Roboto
77
+ Mono Project Authors).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@a-t-h-i/bot-lobby",
3
- "version": "0.6.47",
3
+ "version": "0.6.48",
4
4
  "description": "Structured multi-agent software engineering orchestrator for Pi",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -57,12 +57,22 @@
57
57
  "@earendil-works/pi-ai": "1.0.1",
58
58
  "@earendil-works/pi-coding-agent": "1.0.1",
59
59
  "@earendil-works/pi-tui": "1.0.1",
60
+ "@fontsource-variable/dm-sans": "^5.3.0",
61
+ "@fontsource-variable/figtree": "^5.3.0",
62
+ "@fontsource-variable/fira-code": "^5.3.0",
60
63
  "@fontsource-variable/geist": "^5.3.0",
61
64
  "@fontsource-variable/geist-mono": "^5.3.0",
62
65
  "@fontsource-variable/ibm-plex-sans": "^5.3.0",
63
66
  "@fontsource-variable/inter": "^5.3.0",
64
67
  "@fontsource-variable/jetbrains-mono": "^5.3.0",
65
68
  "@fontsource-variable/manrope": "^5.3.0",
69
+ "@fontsource-variable/nunito": "^5.3.0",
70
+ "@fontsource-variable/outfit": "^5.3.0",
71
+ "@fontsource-variable/plus-jakarta-sans": "^5.3.0",
72
+ "@fontsource-variable/roboto-mono": "^5.3.0",
73
+ "@fontsource-variable/source-code-pro": "^5.3.1",
74
+ "@fontsource-variable/source-sans-3": "^5.3.1",
75
+ "@fontsource-variable/space-grotesk": "^5.3.0",
66
76
  "@playwright/test": "1.62.0",
67
77
  "@tailwindcss/vite": "4.3.3",
68
78
  "@types/node": "^22.10.0",
@@ -6,36 +6,50 @@ accessibility, frontend performance and the design language. Everything that
6
6
  runs in the browser is yours, including client-side logic and canvas,
7
7
  WebGL/three.js graphics.
8
8
 
9
- You have real visual taste. Your work is calm, considered and quietly
10
- delightful: the understated, crafted aesthetic of Anthropic's latest models,
11
- not a generic template. Every screen should feel intentional — clear hierarchy,
12
- room to breathe, and small moments of feedback that make the product feel alive
13
- without ever getting in the way.
14
-
15
- ## Existing design language comes first
16
-
17
- Inspect the existing application before introducing new UI patterns. Prefer
18
- extending existing components, tokens, spacing, typography, colors,
19
- interactions and layouts; never introduce a visually similar but separate
20
- component when an existing one can be extended. Where no design system exists,
21
- establish a small one (tokens plus a few primitives) rather than scattering
22
- one-off values.
23
-
24
- ## Aesthetic
25
-
26
- - Calm and editorial: generous whitespace, content first, nothing competing
27
- for attention. Remove before you add.
28
- - Considered typography carries the hierarchy; decoration does not.
29
- - A restrained, warm palette: warm off-white and near-black neutrals rather
30
- than pure `#fff`/`#000`, with one purposeful accent used sparingly for primary
31
- actions, focus and key states.
32
- - Soft radii, hairline borders and subtle depth. No gratuitous gradients,
33
- glassmorphism, heavy shadows or visual noise unless the product already
34
- speaks that language.
35
- - Consistency is taste: the same thing always looks and behaves the same way.
9
+ You bring craft, not a house style. The look of the product is the user's
10
+ call: you never impose an aesthetic of your own, and nothing visual should
11
+ surprise the user once it is built.
12
+
13
+ ## The existing design language comes first
14
+
15
+ In a project that already has a UI, follow its design language exactly: its
16
+ components, tokens, spacing, typography, colours, radii, shadows, icons,
17
+ element types and motion. Inspect the existing application before you add
18
+ anything, extend the components it has instead of making visually similar
19
+ new ones, and match how it already does the same kind of thing (if it uses
20
+ pop-overs for quick edits, so do you). Depart from it only when the user
21
+ explicitly asks for a different style, and then only as far as they asked.
22
+ Where no design system exists yet, establish a small one (tokens plus a few
23
+ primitives) from the choices the user makes, rather than scattering one-off
24
+ values.
25
+
26
+ ## Ask, don't assume
27
+
28
+ The user makes the design decisions; you make them concrete. Before you build
29
+ anything visual that the existing UI does not already settle, ask the user
30
+ with `ask_user_question` about every choice that is theirs to make, for
31
+ example:
32
+
33
+ - the visual style or direction (when there is no existing one to follow);
34
+ - sizes: buttons and controls, spacing density, type scale;
35
+ - element types: a modal or a pop-over, a drawer or a page, rich text or a
36
+ plain text field, a tooltip or inline help, tabs or a segmented switch,
37
+ a toast or an inline message;
38
+ - motion: whether something animates, how, and how fast;
39
+ - colours, radii, icons and empty, loading and error states where they are
40
+ new.
41
+
42
+ Group related choices into one questionnaire (one question each, with a
43
+ recommendation marked) instead of asking one at a time, and say what the
44
+ existing UI already does when it does. Decide yourself only what the existing
45
+ design language already answers, or what the user has said to leave to you.
46
+ When you report, list each design decision and who made it.
36
47
 
37
48
  ## Styling craft
38
49
 
50
+ Sound practice for whatever style the project has or the user picks; where the
51
+ existing UI does something differently, the existing UI wins.
52
+
39
53
  - **Type:** a modular scale (ratio about 1.2–1.25) with at most two families.
40
54
  Body text at 16px or larger, line-height about 1.5; headings tighter (about
41
55
  1.1–1.25) with slightly reduced letter-spacing at large sizes. Keep line
@@ -91,8 +105,8 @@ product, and a generic render is a failed one.
91
105
 
92
106
  ## Interaction and motion
93
107
 
94
- You like interactive UIs that give the user subtle, fun feedback — never
95
- over-animated.
108
+ Motion and feedback follow the existing UI and what the user chose; where
109
+ neither says, ask. As defaults to offer:
96
110
 
97
111
  - Every action gets a response: pressed states, optimistic updates, inline
98
112
  confirmation ("Saved"), skeletons or progress for waits over ~300ms, and
@@ -100,25 +114,29 @@ over-animated.
100
114
  - Motion explains change: animate only `transform` and `opacity`, 150–250ms,
101
115
  ease-out when entering and ease-in when leaving. Never animate layout
102
116
  properties, and never delay the user to show an animation.
103
- - Small playful touches are welcome where they fit the product — a gentle
104
- check-mark draw, a soft spring on a toggle, a light stagger on a short list —
105
- but no looping or attention-seeking motion.
106
117
  - Always honor `prefers-reduced-motion`: keep the state change, drop the
107
118
  movement.
108
119
 
109
120
  ## Show the options
110
121
 
111
122
  When a visual decision is the user's to make (a layout, a screen, how a
112
- component looks, a direction for the whole UI), show it rather than describe
113
- it: ask with `ask_user_question` and give every option an `htmlPreview`, a
114
- static mockup of that option — HTML and CSS only (no scripts, images, fonts or
115
- links: the sandbox strips them), laid out for a page about 1200px wide, with
116
- the real content, palette and proportions of what you would build, never grey
117
- placeholder boxes. The user sees the focused option's mockup beside the
118
- question, expands it and scrolls through all the options side by side, so
119
- draw each option at the same fidelity. Ask before you build, and only about
120
- what is theirs to choose; decide the rest yourself. In the planning panel,
121
- draw the same mockups as fenced `mockup` blocks under your options.
123
+ component looks or behaves, a direction for the whole UI), show it rather than
124
+ describe it: ask with `ask_user_question` and give every option an
125
+ `htmlPreview`, a mockup of that option in HTML and CSS, laid out for a page
126
+ about 1200px wide, with the real content, palette and proportions of what you
127
+ would build, in the project's existing design language, never grey
128
+ placeholder boxes. Make every mockup interactive: use real `button`, `input`,
129
+ `select`, `textarea`, `label` and `details`/`summary` elements with their
130
+ hover, focus, active, checked and open states, and CSS transitions and
131
+ `@keyframes` for the motion the option proposes (a pop-over opening, a
132
+ toggle, a list arriving), at the speed you would ship. There are no scripts,
133
+ images, fonts or links (the sandbox strips them), so build the behaviour from
134
+ CSS: `:hover`, `:focus-within`, `:checked` with sibling selectors, and
135
+ `details[open]`. The user sees the focused option's mockup beside the
136
+ question, tries it there, expands it and scrolls through all the options side
137
+ by side, so draw each option at the same fidelity. Ask before you build. In
138
+ the planning panel, draw the same mockups as fenced `mockup` blocks under
139
+ your options.
122
140
 
123
141
  ## Accessibility
124
142
 
@@ -133,8 +151,8 @@ screen.
133
151
 
134
152
  - Mobile-first, responsive from 320px up; test the narrowest and widest
135
153
  layouts.
136
- - Reuse existing components and tokens; keep components small, typed and
137
- composable, with state lifted only as far as needed.
154
+ - Reuse the project's existing components, styles and tokens; keep components
155
+ small, typed and composable, with state lifted only as far as needed.
138
156
  - Performance is UX: no layout shift (reserve space for media and async
139
157
  content), lazy-load below-the-fold assets, size images correctly, keep
140
158
  bundles lean and avoid needless re-renders.
package/prompts/master.md CHANGED
@@ -142,9 +142,10 @@ and reason about the change inside it:
142
142
  For anything the user will see (a UI request, a layout, a screen, a visual
143
143
  direction), show the choices rather than describe them. When you ask about a
144
144
  visual decision, use `ask_user_question` and give each option an
145
- `htmlPreview` mockup (static HTML and CSS of that option, laid out for a page
146
- about 1200px wide); the user expands the mockups and scrolls through the
147
- options side by side. When the choice needs real design work, delegate it to
145
+ `htmlPreview` mockup (HTML and CSS of that option in the project's existing
146
+ design language, laid out for a page about 1200px wide, with real controls and
147
+ CSS states and animations so the user can try it); the user expands the
148
+ mockups and scrolls through the options side by side. When the choice needs real design work, delegate it to
148
149
  the designer, who asks with its own mockups. In planning, the panel draws
149
150
  mockups under its options the same way.
150
151
 
package/src/ask/tool.ts CHANGED
@@ -22,9 +22,9 @@ export { ASK_TOOL };
22
22
 
23
23
  const OptionSchema = Type.Object({
24
24
  htmlPreview: Type.Optional(Type.Object({
25
- html: Type.String({ maxLength: MAX_PREVIEW_HTML, description: "Static HTML of a mockup of this option; scripts, images, fonts and links are stripped." }),
25
+ html: Type.String({ maxLength: MAX_PREVIEW_HTML, description: "HTML of a mockup of this option. Controls (button, input, select, textarea, label, details/summary) stay live and CSS transitions and keyframes run, so the user can try it; scripts, forms, images, fonts and links are stripped." }),
26
26
  css: Type.Optional(Type.String({ maxLength: MAX_PREVIEW_CSS })),
27
- }, { additionalProperties: false, description: "A static HTML/CSS mockup of this option, laid out for a page about 1200px wide: shown as a thumbnail beside the question, which the user expands to scroll through every option's mockup. Give one to every option of a visual question (a layout, a screen, a component's look)." })),
27
+ }, { additionalProperties: false, description: "An interactive HTML/CSS mockup of this option (no scripts: interaction through CSS states), laid out for a page about 1200px wide: shown as a thumbnail beside the question, which the user expands to scroll through every option's mockup. Give one to every option of a visual question (a layout, a screen, a component's look)." })),
28
28
  label: Type.String({ maxLength: MAX_LABEL, description: `The option as the user sees and picks it: 1-5 words, at most ${MAX_LABEL} characters.` }),
29
29
  description: Type.Optional(Type.String({ description: "What choosing it means: its trade-offs or consequences. Markdown." })),
30
30
  preview: Type.Optional(Type.String({ description: "Markdown shown beside the options while this one is focused: a mockup, a code snippet, a diagram, a config. Only when seeing it helps the user compare." })),
@@ -46,6 +46,8 @@ export interface AgentRequest {
46
46
  context: AgentContext;
47
47
  model?: string;
48
48
  mcpTools?: string[];
49
+ /** False when the agent's settings turn its auto-compaction off. */
50
+ autoCompact?: boolean;
49
51
  delegationQuota?: { used: number };
50
52
  thinking?: string;
51
53
  timeoutMs: number;
@@ -254,6 +256,7 @@ async function runAgentOnce(request: AgentRequest, run: ProcessRunner, attempt:
254
256
  request.onUpdate?.(child);
255
257
  },
256
258
  mcpTools: request.mcpTools,
259
+ ...(request.autoCompact === false ? { autoCompact: false } : {}),
257
260
  task: request.instruction,
258
261
  systemPrompt,
259
262
  tools: toolsFor(request),
@@ -1,6 +1,7 @@
1
1
  import type { AgentRun } from "../schemas/findings.ts";
2
2
  import type { Domain, Role } from "../schemas/agent.ts";
3
3
  import { delegationHost } from "./delegation.ts";
4
+ import { AUTO_COMPACT_ENV } from "../pi/quiet.ts";
4
5
  import { fileURLToPath } from "node:url";
5
6
  import { spawn, type ChildProcess } from "node:child_process";
6
7
  import { existsSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
@@ -44,6 +45,8 @@ export interface PiRunOptions {
44
45
  onEvent?: (event: PiStreamEvent) => void;
45
46
  /** Extra environment for the subagent process. */
46
47
  env?: Record<string, string>;
48
+ /** False when the agent's settings turn its auto-compaction off. */
49
+ autoCompact?: boolean;
47
50
  /** Kill the agent after this long without any output; 0 disables. */
48
51
  stallTimeoutMs?: number;
49
52
  /** Silence allowed while one tool call is in flight (tests, builds); 0 disables. */
@@ -765,7 +768,8 @@ function writePromptFile(prompt: string): { file: string; cleanup: () => void }
765
768
  }
766
769
 
767
770
  /** Run one isolated subagent and normalise its outcome. */
768
- export async function runPiAgent(options: PiRunOptions, run: ProcessRunner = spawnPiProcess): Promise<PiRunResult> {
771
+ export async function runPiAgent(given: PiRunOptions, run: ProcessRunner = spawnPiProcess): Promise<PiRunResult> {
772
+ const options = given.autoCompact === false ? { ...given, env: { ...given.env, [AUTO_COMPACT_ENV]: "0" } } : given;
769
773
  const host = await delegationHost(options, run);
770
774
  let prompt: ReturnType<typeof writePromptFile> | undefined;
771
775
  try {
@@ -0,0 +1,66 @@
1
+ /**
2
+ * What the oracle learns, shared on its compaction loop. When the oracle's own context is compacted, the checkpoint
3
+ * it writes ends with a "Knowledge to share" section: durable project facts, standards and decisions, each tagged
4
+ * with the agent it belongs to. Those lines go into that agent's knowledge files (through `applyKnowledge`, which
5
+ * drops duplicates), so the oracle keeps its own knowledge current and the domain agents (designer, backend, QA)
6
+ * get what concerns them without the oracle having to remember to write it down.
7
+ */
8
+ import { applyKnowledge, type KnowledgeKind } from "./store.ts";
9
+ import type { KnowledgeAgent } from "./paths.ts";
10
+
11
+ export const DIGEST_HEADING = "Knowledge to share";
12
+
13
+ /** Added to the oracle's compaction instruction. */
14
+ export const DIGEST_INSTRUCTION = [
15
+ `Finish with a section headed "## ${DIGEST_HEADING}": the durable things this stretch of work established about the project that an agent will need again, one per line, each as \`- [agent:kind] text\`.`,
16
+ "agent is master (you: how the user works, project-wide facts), designer (UI, UX, design language, frontend), backend (APIs, data, services, infrastructure) or qa (testing, verification, known failures).",
17
+ "kind is knowledge (a fact or a useful pattern), standard (a rule the user wants followed) or decision (a choice the user made, with its reason).",
18
+ "Give the user's own words where they set a rule or a preference. Leave out task progress, guesses, and anything only true for this task. Write `- none` when nothing qualifies. At most 12 lines.",
19
+ ].join(" ");
20
+
21
+ const AGENTS: readonly KnowledgeAgent[] = ["master", "designer", "backend", "qa"];
22
+ const KINDS: readonly KnowledgeKind[] = ["knowledge", "standard", "decision"];
23
+ const MAX_ITEMS = 12;
24
+ const MAX_CHARS = 400;
25
+
26
+ export interface DigestItem {
27
+ agent: KnowledgeAgent;
28
+ kind: KnowledgeKind;
29
+ text: string;
30
+ }
31
+
32
+ /** The tagged lines under the "Knowledge to share" heading; anything malformed is skipped. */
33
+ export function parseDigest(summary: string): DigestItem[] {
34
+ const lines = summary.split(/\r?\n/);
35
+ const start = lines.findIndex((line) => /^#{1,4}\s*knowledge to share\s*$/i.test(line.trim()));
36
+ if (start < 0) return [];
37
+ const items: DigestItem[] = [];
38
+ for (const line of lines.slice(start + 1)) {
39
+ if (/^#{1,4}\s/.test(line.trim())) break;
40
+ const match = /^\s*[-*]\s*\[\s*([a-z]+)\s*:\s*([a-z]+)\s*\]\s*(.+?)\s*$/i.exec(line);
41
+ if (!match) continue;
42
+ const agent = match[1]!.toLowerCase() as KnowledgeAgent;
43
+ const kind = match[2]!.toLowerCase() as KnowledgeKind;
44
+ const text = match[3]!.replace(/\s+/g, " ").trim();
45
+ if (!AGENTS.includes(agent) || !KINDS.includes(kind) || !text || text.length > MAX_CHARS) continue;
46
+ items.push({ agent, kind, text });
47
+ if (items.length >= MAX_ITEMS) break;
48
+ }
49
+ return items;
50
+ }
51
+
52
+ /** Write each item into its agent's knowledge; returns how many were new, by agent. */
53
+ export function shareDigest(dataRoot: string, items: readonly DigestItem[], now = new Date()): Partial<Record<KnowledgeAgent, number>> {
54
+ const added: Partial<Record<KnowledgeAgent, number>> = {};
55
+ for (const item of items) {
56
+ const text = item.kind === "decision" ? item.text : `- ${item.text}`;
57
+ if (applyKnowledge({ dataRoot, agent: item.agent, kind: item.kind, text, now }).result === "added") added[item.agent] = (added[item.agent] ?? 0) + 1;
58
+ }
59
+ return added;
60
+ }
61
+
62
+ /** "2 for the designer, 1 for QA" */
63
+ export function describeShared(added: Partial<Record<KnowledgeAgent, number>>): string {
64
+ const names: Record<KnowledgeAgent, string> = { master: "the oracle", designer: "the designer", backend: "backend", qa: "QA" };
65
+ return AGENTS.filter((agent) => added[agent]).map((agent) => `${added[agent]} for ${names[agent]}`).join(", ");
66
+ }
@@ -1008,6 +1008,8 @@ export class PlanningSession {
1008
1008
  model,
1009
1009
  thinking,
1010
1010
  mcpTools: profile.mcpTools,
1011
+ ...(profile.autoCompact === false ? { autoCompact: false } : {}),
1012
+ ...(profile.autoCompact === false ? { autoCompact: false } : {}),
1011
1013
  onChildRun: (child) => {
1012
1014
  this.deps.feed?.step(label, `child ${child.runId.slice(0, 8)}: ${child.step ?? child.status}`, child.runId);
1013
1015
  if (child.status !== "running") this.deps.feed?.end(child.runId, child.status !== "success");
@@ -279,6 +279,7 @@ export class PullReviews {
279
279
  model,
280
280
  thinking,
281
281
  mcpTools: profile.mcpTools,
282
+ ...(profile.autoCompact === false ? { autoCompact: false } : {}),
282
283
  onChildRun: (child) => {
283
284
  this.deps.feed?.step(REVIEW_SOURCE, `child ${child.runId.slice(0, 8)}: ${child.step ?? child.status}`, child.runId);
284
285
  if (child.status !== "running") this.deps.feed?.end(child.runId, child.status !== "success");
@@ -92,6 +92,8 @@ export interface QuickFixProfile {
92
92
  timeoutMs: number;
93
93
  instructions?: string;
94
94
  mcpTools?: string[];
95
+ /** False when its settings turn the agent's auto-compaction off. */
96
+ autoCompact?: boolean;
95
97
  /** Where the job goes when its model runs out of usage or is unavailable. */
96
98
  }
97
99
 
@@ -340,6 +342,8 @@ export class QuickFixQueue {
340
342
  model,
341
343
  thinking,
342
344
  mcpTools: profile.mcpTools,
345
+ ...(profile.autoCompact === false ? { autoCompact: false } : {}),
346
+ ...(profile.autoCompact === false ? { autoCompact: false } : {}),
343
347
  delegationQuota: quota,
344
348
  agent: { runId: job.id, taskId: job.id, domain: "backend", role: "worker" },
345
349
  onChildRun: (child) => {
@@ -60,7 +60,7 @@ export interface ScoutRequest {
60
60
  /** Model, thinking and time limit for one run, from settings. */
61
61
  function profileFields(config: BotLobbyConfig, resolver: ProfileResolver | undefined, domain: Domain, role: AgentRequest["role"]) {
62
62
  const profile = profileFor(config, resolver, domain, role);
63
- return { model: profile.model, mcpTools: profile.mcpTools, thinking: profile.thinking, timeoutMs: profile.timeoutMs, time: boundedAgentTime(profile.timeoutMs) };
63
+ return { model: profile.model, mcpTools: profile.mcpTools, ...(profile.autoCompact === false ? { autoCompact: false } : {}), thinking: profile.thinking, timeoutMs: profile.timeoutMs, time: boundedAgentTime(profile.timeoutMs) };
64
64
  }
65
65
 
66
66
  function scoutInstruction(request: ScoutRequest, domain: Domain): string {
@@ -71,6 +71,7 @@ export async function runResearch(request: ResearchRequest, run: ProcessRunner =
71
71
  context: researchContext(request),
72
72
  model: profile.model,
73
73
  mcpTools: profile.mcpTools,
74
+ ...(profile.autoCompact === false ? { autoCompact: false } : {}),
74
75
  thinking: profile.thinking,
75
76
  timeoutMs: profile.timeoutMs,
76
77
  ...(request.time ? { time: request.time } : {}),
@@ -1,6 +1,31 @@
1
- import { compact, DEFAULT_COMPACTION_SETTINGS, estimateTokens, findCutPoint, type ExtensionAPI, type TurnEndEvent } from "@earendil-works/pi-coding-agent";
1
+ import { compact, CONFIG_DIR_NAME, DEFAULT_COMPACTION_SETTINGS, estimateTokens, findCutPoint, type ExtensionAPI, type ExtensionContext, type TurnEndEvent } from "@earendil-works/pi-coding-agent";
2
2
  import { contextMarks, freshContextOn } from "./fresh-context.ts";
3
- import { isSubagentProcess } from "./quiet.ts";
3
+ import { AUTO_COMPACT_ENV, isSubagentProcess } from "./quiet.ts";
4
+ import { dataRoot, detectProjectRoot, loadConfig } from "../state/project.ts";
5
+ import { describeShared, DIGEST_INSTRUCTION, parseDigest, shareDigest, type DigestItem } from "../knowledge/oracle-digest.ts";
6
+
7
+ const CHECKPOINT = "Write a concise checkpoint with: Requirements and constraints; Decisions; Files changed; Verification and evidence; Failed approaches (do not repeat); Unfinished work and next action; Outstanding children and their assignments. Preserve concrete file references and distinguish verified facts from guesses. The parent remains responsible for integration and verification.";
8
+
9
+ export interface AutoCompactionOptions {
10
+ /** Whether this agent compacts on its own: a subagent by its environment, the oracle by its settings. */
11
+ enabled?: () => boolean;
12
+ /** Where the oracle's shared knowledge goes; by default the project's knowledge files. */
13
+ share?: (items: DigestItem[], ctx: ExtensionContext) => string;
14
+ }
15
+
16
+ function enabledBySettings(): boolean {
17
+ if (isSubagentProcess()) return process.env[AUTO_COMPACT_ENV] !== "0";
18
+ try {
19
+ return loadConfig().master.autoCompact !== false;
20
+ } catch {
21
+ return true;
22
+ }
23
+ }
24
+
25
+ function shareWithAgents(items: DigestItem[], ctx: ExtensionContext): string {
26
+ const root = detectProjectRoot(ctx.cwd, CONFIG_DIR_NAME);
27
+ return describeShared(shareDigest(dataRoot(root, CONFIG_DIR_NAME), items));
28
+ }
4
29
 
5
30
  export const CONTEXT_TARGET = 64_000;
6
31
 
@@ -8,13 +33,20 @@ export function compactionThreshold(window: number, reserve = DEFAULT_COMPACTION
8
33
  return Math.max(1, Math.min(CONTEXT_TARGET, Math.floor(window * 0.6), window - Math.min(reserve, Math.floor(window / 2))));
9
34
  }
10
35
 
11
- /** Compact at a settled tool boundary; ctx.compact() would abort the turn we need to continue. */
12
- export function registerAutoCompaction(pi: ExtensionAPI, summarize: typeof compact = compact): void {
36
+ /**
37
+ * Compact at a settled tool boundary; ctx.compact() would abort the turn we need to continue. Each agent's settings
38
+ * can turn it off. The oracle's checkpoint also lists what it learned that is worth keeping, tagged by agent, and
39
+ * that goes into the knowledge base: its own, and the designer's, backend's and QA's where it concerns them.
40
+ */
41
+ export function registerAutoCompaction(pi: ExtensionAPI, summarize: typeof compact = compact, options: AutoCompactionOptions = {}): void {
42
+ const enabled = options.enabled ?? enabledBySettings;
43
+ const share = options.share ?? shareWithAgents;
44
+ const oracle = !isSubagentProcess();
13
45
  let busy = false;
14
46
  let lastLeaf: string | null | undefined;
15
47
  pi.on("session_start", () => { busy = false; lastLeaf = undefined; });
16
48
  pi.on("turn_end", async (event: TurnEndEvent, ctx) => {
17
- if (busy || !ctx.model) return;
49
+ if (busy || !ctx.model || !enabled()) return;
18
50
  const leaf = ctx.sessionManager.getLeafId();
19
51
  if (leaf === lastLeaf) return;
20
52
  const configured = pi.getSettings().compaction;
@@ -61,9 +93,18 @@ export function registerAutoCompaction(pi: ExtensionAPI, summarize: typeof compa
61
93
  const headers = auth.headers ? Object.fromEntries(Object.entries(auth.headers).filter((entry): entry is [string, string] => entry[1] !== null)) : undefined;
62
94
  const retry = pi.getSettings().retry;
63
95
  const retryPolicy = { enabled: retry?.enabled ?? true, maxRetries: retry?.maxRetries ?? 3, baseDelayMs: retry?.baseDelayMs ?? 2_000, maxAgentDelayMs: retry?.maxAgentDelayMs };
64
- const result = await summarize({ firstKeptEntryId, messagesToSummarize: messages, turnPrefixMessages: [], isSplitTurn: false, tokensBefore: estimate, previousSummary: previous?.type === "compaction" ? previous.summary : undefined, fileOps, settings: { enabled: true, reserveTokens: reserve, keepRecentTokens } }, auth.baseUrl ? { ...ctx.model, baseUrl: auth.baseUrl } : ctx.model, auth.apiKey, headers, "Write a concise checkpoint with: Requirements and constraints; Decisions; Files changed; Verification and evidence; Failed approaches (do not repeat); Unfinished work and next action; Outstanding children and their assignments. Preserve concrete file references and distinguish verified facts from guesses. The parent remains responsible for integration and verification.", ctx.signal, undefined, undefined, auth.env, retryPolicy);
96
+ const result = await summarize({ firstKeptEntryId, messagesToSummarize: messages, turnPrefixMessages: [], isSplitTurn: false, tokensBefore: estimate, previousSummary: previous?.type === "compaction" ? previous.summary : undefined, fileOps, settings: { enabled: true, reserveTokens: reserve, keepRecentTokens } }, auth.baseUrl ? { ...ctx.model, baseUrl: auth.baseUrl } : ctx.model, auth.apiKey, headers, oracle ? `${CHECKPOINT} ${DIGEST_INSTRUCTION}` : CHECKPOINT, ctx.signal, undefined, undefined, auth.env, retryPolicy);
65
97
  ctx.signal?.throwIfAborted();
66
98
  ctx.ui.notify("Agent context compacted", "info");
99
+ if (oracle) {
100
+ try {
101
+ const items = parseDigest(result.summary);
102
+ const shared = items.length ? share(items, ctx) : "";
103
+ if (shared) ctx.ui.notify(`Knowledge updated: ${shared}`, "info");
104
+ } catch (error) {
105
+ ctx.ui.notify(`Could not update knowledge: ${(error as Error).message}`, "warning");
106
+ }
107
+ }
67
108
  return { entries: [...event.entries, { type: "compaction" as const, summary: result.summary, firstKeptEntryId, usage: result.usage, details: result.details }] };
68
109
  } catch (error) {
69
110
  ctx.ui.notify(`Context compaction failed: ${(error as Error).message}`, "warning");
package/src/pi/quiet.ts CHANGED
@@ -58,6 +58,9 @@ export function webToolsFor(active: string[], taskActive: boolean, hidden: reado
58
58
  return { active: [...active, ...back], hidden: [] };
59
59
  }
60
60
 
61
+ /** Set to "0" in a subagent's environment when its settings turn auto-compaction off. */
62
+ export const AUTO_COMPACT_ENV = "BOT_LOBBY_AUTO_COMPACT";
63
+
61
64
  /** True inside a bot-lobby subagent process (marked in `spawnPiProcess`). */
62
65
  export function isSubagentProcess(): boolean {
63
66
  return process.env.BOT_LOBBY_SUBAGENT === "1";
@@ -31,6 +31,8 @@ export interface AgentModelConfig {
31
31
  mcpTools?: string[];
32
32
  /** Time limit per run; falls back to `workflow.agentTimeoutMs`. */
33
33
  timeoutMs?: number;
34
+ /** Compact this agent's context on its own as it fills (on unless false); the oracle's also updates the knowledge base. */
35
+ autoCompact?: boolean;
34
36
  }
35
37
 
36
38
  /** Scouts pick a model and a time limit only; their thinking is fixed at `SCOUT_THINKING`. */
@@ -40,6 +42,8 @@ export interface ScoutConfig {
40
42
  timeoutMs: number;
41
43
  /** Tool calls a scout may make: it is told to wrap up at 60% and refused more past this, so it reports with what it has; 0 = no limit. */
42
44
  maxToolCalls: number;
45
+ /** Compact a scout's context on its own as it fills (on unless false). */
46
+ autoCompact?: boolean;
43
47
  }
44
48
 
45
49
  /** Subagent kinds with their own settings entry. */
@@ -351,7 +355,7 @@ function normalizeAgent(base: AgentModelConfig, override: Partial<AgentModelConf
351
355
  const thinking = isThinkingLevel(merged.thinking) ? merged.thinking : base.thinking;
352
356
  const timeoutMs = positive(merged.timeoutMs) ?? base.timeoutMs;
353
357
  const mcpTools = normalizeMcpTools(merged.mcpTools);
354
- return { model: merged.model, thinking, ...(mcpTools.length ? { mcpTools } : {}), ...(typeof merged.instructions === "string" ? { instructions: merged.instructions } : {}), ...(timeoutMs ? { timeoutMs } : {}) };
358
+ return { model: merged.model, thinking, ...(mcpTools.length ? { mcpTools } : {}), ...(typeof merged.instructions === "string" ? { instructions: merged.instructions } : {}), ...(timeoutMs ? { timeoutMs } : {}), ...(merged.autoCompact === false ? { autoCompact: false } : {}) };
355
359
  }
356
360
 
357
361
  /** Scouts keep a model and a time limit; any thinking value in the file is dropped. */
@@ -363,6 +367,7 @@ function normalizeScout(override: Partial<ScoutConfig> | undefined): ScoutConfig
363
367
  timeoutMs: positive(override?.timeoutMs) ?? base.timeoutMs,
364
368
  maxToolCalls: typeof override?.maxToolCalls === "number" && Number.isFinite(override.maxToolCalls) && override.maxToolCalls >= 0 ? Math.round(override.maxToolCalls) : base.maxToolCalls,
365
369
  ...(mcpTools.length ? { mcpTools } : {}),
370
+ ...(override?.autoCompact === false ? { autoCompact: false } : {}),
366
371
  };
367
372
  }
368
373
 
@@ -513,6 +518,13 @@ export interface AgentProfile {
513
518
  instructions?: string;
514
519
  /** Exact native MCP tool names this profile may call; empty grants none. */
515
520
  mcpTools?: string[];
521
+ /** False when its settings turn auto-compaction off. */
522
+ autoCompact?: boolean;
523
+ }
524
+
525
+ /** `{ autoCompact: false }` when an entry turns auto-compaction off, else nothing. */
526
+ function compactField(entry: { autoCompact?: boolean }): { autoCompact?: false } {
527
+ return entry.autoCompact === false ? { autoCompact: false } : {};
516
528
  }
517
529
 
518
530
  /** The settings entry a domain/role run draws from. */
@@ -537,10 +549,10 @@ export function agentProfile(config: BotLobbyConfig, domain: Domain, role: Role)
537
549
  const instructions = config.agents[domain].instructions;
538
550
  const fallback = config.workflow.agentTimeoutMs;
539
551
  if (kind === "scout") {
540
- return { kind, model: modelOf(config.scout.model), thinking: SCOUT_THINKING, timeoutMs: config.scout.timeoutMs || fallback, instructions, ...(config.scout.mcpTools?.length ? { mcpTools: config.scout.mcpTools } : {}) };
552
+ return { kind, model: modelOf(config.scout.model), thinking: SCOUT_THINKING, timeoutMs: config.scout.timeoutMs || fallback, instructions, ...(config.scout.mcpTools?.length ? { mcpTools: config.scout.mcpTools } : {}), ...compactField(config.scout) };
541
553
  }
542
554
  const entry = kind === "researcher" ? config.researcher : config.agents[kind];
543
- return { kind, model: modelOf(entry.model), thinking: entry.thinking, timeoutMs: entry.timeoutMs ?? fallback, instructions, ...(entry.mcpTools?.length ? { mcpTools: entry.mcpTools } : {}) };
555
+ return { kind, model: modelOf(entry.model), thinking: entry.thinking, timeoutMs: entry.timeoutMs ?? fallback, instructions, ...(entry.mcpTools?.length ? { mcpTools: entry.mcpTools } : {}), ...compactField(entry) };
544
556
  }
545
557
 
546
558
  /** The settings entry of a lobby agent (quick fix or planner). */
@@ -549,19 +561,19 @@ export function lobbyAgentConfig(config: BotLobbyConfig, kind: LobbyAgentKind):
549
561
  }
550
562
 
551
563
  /** Profile for a lobby agent run, from settings alone; `model` is undefined while unset. */
552
- export function lobbyAgentProfile(config: BotLobbyConfig, kind: LobbyAgentKind): { model?: string; thinking: string; timeoutMs: number; instructions?: string; mcpTools?: string[] } {
564
+ export function lobbyAgentProfile(config: BotLobbyConfig, kind: LobbyAgentKind): { model?: string; thinking: string; timeoutMs: number; instructions?: string; mcpTools?: string[]; autoCompact?: boolean } {
553
565
  const entry = lobbyAgentConfig(config, kind);
554
- return { model: modelOf(entry.model), thinking: entry.thinking, timeoutMs: entry.timeoutMs ?? config.workflow.agentTimeoutMs, instructions: entry.instructions, ...(entry.mcpTools?.length ? { mcpTools: entry.mcpTools } : {}) };
566
+ return { model: modelOf(entry.model), thinking: entry.thinking, timeoutMs: entry.timeoutMs ?? config.workflow.agentTimeoutMs, instructions: entry.instructions, ...(entry.mcpTools?.length ? { mcpTools: entry.mcpTools } : {}), ...compactField(entry) };
555
567
  }
556
568
 
557
569
  /**
558
570
  * A planning panel seat's profile: the domain's (or the researcher's) model,
559
571
  * thinking and custom instructions, bounded by the planner's per-turn limit.
560
572
  */
561
- export function panelMemberProfile(config: BotLobbyConfig, member: PanelMember): { model?: string; thinking: string; timeoutMs: number; instructions?: string; mcpTools?: string[] } {
573
+ export function panelMemberProfile(config: BotLobbyConfig, member: PanelMember): { model?: string; thinking: string; timeoutMs: number; instructions?: string; mcpTools?: string[]; autoCompact?: boolean } {
562
574
  const entry = member === "researcher" ? config.researcher : config.agents[member];
563
575
  const timeoutMs = config.planner.timeoutMs ?? config.workflow.agentTimeoutMs;
564
- return { model: modelOf(entry.model), thinking: entry.thinking, timeoutMs, instructions: entry.instructions, ...(entry.mcpTools?.length ? { mcpTools: entry.mcpTools } : {}) };
576
+ return { model: modelOf(entry.model), thinking: entry.thinking, timeoutMs, instructions: entry.instructions, ...(entry.mcpTools?.length ? { mcpTools: entry.mcpTools } : {}), ...compactField(entry) };
565
577
  }
566
578
 
567
579
  /** Resolves the model, thinking and time limit one subagent run uses. */