pi-better-harness 0.66.1 → 0.67.1

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.67.1] - 2026-12-04
4
+
5
+ ### Changed
6
+
7
+ - The package README opens with a 12-second terminal demo and links to installation, the feature index and the extension comparison.
8
+
9
+ ## [0.67.0] - 2026-12-04
10
+
11
+ ### Changed
12
+
13
+ - Use **Prompts → Model instruction templates** in the local Web console to browse the official Codex text and enable it for matching OpenAI models. Changes apply on the next prompt.
14
+ - Open **Manage prompts** from a Web-enabled Pi session to edit Harness instructions, manage revisions and connect the session for replay. The terminal Prompt manager has been removed.
15
+
3
16
  ## [0.66.1] - 2026-12-04
4
17
 
5
18
  ### Changed
package/README.md CHANGED
@@ -1,8 +1,12 @@
1
1
  # pi-better-harness
2
2
 
3
- <img src="https://raw.githubusercontent.com/1aboveio/pi-better-harness/main/docs/images/brand/logo.png" alt="Pi Better Harness logo" width="128" height="128" />
3
+ See the current step in a live Todo list. Run builds and tests in the background while you keep talking to Pi. When the results arrive, an active Goal can continue the work and verify the outcome.
4
4
 
5
- `pi-better-harness` is a Pi meta package for an opt-in foreground write sandbox, delegated subagents, durable background tasks, synchronous SSH commands, goal tracking, and Goal & Todo.
5
+ [![Play the Pi terminal demo from prompt entry to the test result and elapsed time.](https://raw.githubusercontent.com/1aboveio/pi-better-harness/main/docs/images/package-gallery/harness-workflow.png)](https://github.com/1aboveio/pi-better-harness/blob/main/docs/images/package-gallery/harness-workflow.mp4)
6
+
7
+ [Play the 12-second demo](https://github.com/1aboveio/pi-better-harness/blob/main/docs/images/package-gallery/harness-workflow.mp4)
8
+
9
+ Install with `npx pi-better-harness install`, then start `pi`. [Install options](https://github.com/1aboveio/pi-better-harness/tree/main/packages/pi-better-harness#install) · [Feature index for agents](https://github.com/1aboveio/pi-better-harness/blob/main/llms.txt) · [Compare Pi extensions](https://github.com/1aboveio/pi-better-harness/blob/main/docs/extension-comparison.md)
6
10
 
7
11
  ## Quick Answer
8
12
 
@@ -22,13 +26,11 @@ Both Harness install methods include the shared server for subagents and backgro
22
26
 
23
27
  ## Official Codex model prompts
24
28
 
25
- When **Model instruction (Beta)** is on for a matching model on `openai` or `openai-codex`, Harness loads OpenAI's exact
29
+ When **Use model instruction templates for matching OpenAI models** is on for a matching model on `openai` or `openai-codex`, Harness loads OpenAI's exact
26
30
  `model_messages.instructions_template` alongside Pi's own instructions. Both
27
31
  foreground and isolated worker sessions use the packaged catalog. No local
28
32
  Codex installation, network request or Codex model cache is required.
29
- The switch under **OpenAI Optimization** in `/harness-settings` defaults to Off. Changes apply on the next prompt.
30
- In the Web console, open **Prompts → Model templates** to read the original
31
- template by release and model. Select a connected session under **Source** to
33
+ Open **Prompts → Model instruction templates** in the Web console to toggle the setting or read the original template by release and model. It defaults to Off and changes apply on the next prompt. Select a connected session under **Source** to
32
34
  read its loaded version. The viewer includes the upstream commit and SHA-256.
33
35
  Sessions pin the release on first use and retain it across resume and fork.
34
36
  Use `/reload` after upgrading Harness to adopt a newer packaged release.
@@ -247,12 +249,12 @@ The navigation stays in place while the selection scrolls. Esc returns from a pa
247
249
  | Tab | Settings and actions |
248
250
  | --- | --- |
249
251
  | Goals | Goal execution, Todo display and actions, project ledgers, workflow ownership and dynamic workflows |
250
- | Agents | Delegation, concurrency, run limits, skills, agent catalog and history |
252
+ | Agents | Delegation, execution mode (auto by default, managed or direct), concurrency, run limits, skills, agent catalog and history |
251
253
  | Sandbox | Sandbox activation, permissions, protected paths and diagnostics |
252
254
  | Background | Current activity, wait reviews and completion delivery |
253
255
  | Display | Pinned panels, tool output and animation |
254
256
  | Supervision | Supervisor mode, scenarios and recovery commitments |
255
- | OpenAI Optimization | Responses compaction and Model instruction (Beta) |
257
+ | OpenAI Optimization | Responses compaction |
256
258
  | Prompts | Recaps, prompt editor and prompt experiments |
257
259
  | Remote | Connect to a host, pull a session or move it to a host |
258
260
  | Audio | Read a reply or selected text aloud and stop playback |
@@ -328,8 +330,7 @@ Recap waits for the foreground turn and queued messages to settle and for the se
328
330
 
329
331
  ### Harness instructions
330
332
 
331
- Open `/harness-settings` and toggle **Harness instructions** from **Off** to
332
- **On**. Choose **Instructions prompt → Edit** to edit the current Markdown.
333
+ In the Web console, open **Prompts → Edit → Harness instructions**. Enable the block to edit its full-text override.
333
334
  Saving updates the Harness block and stores the text in the global Pi settings
334
335
  under `piBetterHarness.instructionsPrompt`. Turning the switch off removes the
335
336
  block. Turning it back on restores the saved text. Changes apply on the next
@@ -348,7 +349,7 @@ including blocks owned by other extensions. To use your own Markdown, set
348
349
  `piBetterHarness.instructionsFile` in the global Pi `settings.json` to an
349
350
  absolute path or a path relative to the agent directory (normally
350
351
  `~/.pi/agent`), then run `instructions sync`. A prompt saved in the editor takes precedence
351
- over this file. Remove `instructionsPrompt` and sync to use the file again.
352
+ over this file. Choose **Remove override** to restore the configured file or modular revision.
352
353
 
353
354
  | Command | Effect |
354
355
  | --- | --- |
@@ -378,7 +379,7 @@ To open either editor from Pi, start `PI_HARNESS_WEB_UI=1 pi`, run
378
379
  `/harness-settings` or `/better-harness-settings`, and press Enter on the
379
380
  first row of **Agents** or **Prompts**. **Edit agent defaults** saves the
380
381
  model and reasoning effort for a personal role or named agent. It uses
381
- the models available to the current Pi session. **Edit prompt modules**
382
+ the models available to the current Pi session. **Manage prompts**
382
383
  opens the prompt revision editor. The standalone web console opens the
383
384
  catalog in view-only mode. All use the current Pi agent directory
384
385
  (`PI_CODING_AGENT_DIR`). The CLI prints a
@@ -425,12 +426,10 @@ one, or when the reviewed manifest explicitly lists that turn in
425
426
  any unscored session.
426
427
 
427
428
  To compare a candidate on one response, capture it with `/harness-settings prompt-capture` or load
428
- a reviewed suite with `/harness-settings prompt-import`. The TUI can use its current session
429
- directly. For browser replay, choose **Connect browser** in the TUI that owns
430
- the capture or suite. The connection lasts until disconnect, reload or session
429
+ a reviewed suite with `/harness-settings prompt-import`. Open **Prompts → Manage prompts** in the owning Pi session and choose **Connect this Pi session** in the browser. The connection lasts until disconnect, reload or session
431
430
  shutdown. Select a captured request or a suite and model
432
431
  in **Replay** and choose the two saved revisions. Results and judgments stay in the agent directory and
433
- can be reopened from either interface. Promotion requires a reviewed result
432
+ can be reopened in the Web console. Promotion requires a reviewed result
434
433
  for the displayed baseline and candidate.
435
434
 
436
435
  Enable the modular instructions and reload Pi. For existing overrides, remove
@@ -49,7 +49,6 @@ const features: Feature[] = [
49
49
  ["View commitments", ""], ["Schedule a reminder", "remind", "Commitment ID and minutes"],
50
50
  ] } },
51
51
  { name: "recap-prompt", tab: "Prompts", label: "Recap prompt", link: "recap-prompt" },
52
- { name: "prompt-manager", tab: "Prompts", label: "Prompt manager", link: "prompt-manager" },
53
52
  { name: "prompt-capture", tab: "Prompts", label: "Capture next response" },
54
53
  { name: "prompt-task-capture", tab: "Prompts", label: "Capture task", operations: { "Capture": [["Capture", "", "Task manifest path"]] } },
55
54
  { name: "prompt-import", tab: "Prompts", label: "Load evaluation cases", operations: { "Cases": [
@@ -1,6 +1,4 @@
1
- import { getAgentDir, type ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
- import { currentInstructions, manageInstructions, validateInstructionsPrompt } from "../../lib/instructions.mjs";
3
- import { readHarnessSetting, updateHarnessSetting } from "../shared-harness-settings.ts";
1
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
4
2
  import { openSupervisorScenarios, readSupervisorSettings, setSupervisorEnabled } from "./supervisor.ts";
5
3
  import registerNativeCompaction, { nativeCompactionSetting } from "../native-compaction/index.ts";
6
4
  import { availableActions, harnessMenu } from "./commands.ts";
@@ -11,13 +9,6 @@ import { changeCallbackSetting, getCallbackSettings, saveCallbackDefault } from
11
9
  export default function harnessSettingsExtension(pi: ExtensionAPI): void {
12
10
  registerNativeCompaction(pi);
13
11
  const registry = createSettingsRegistry(pi);
14
- const templateKey = "openaiModelInstructionTemplate";
15
- const modelInstructionTemplate = {
16
- id: "model-instruction-template", label: "Model instruction (Beta)", values: ["Off", "On"],
17
- description: "Include the official Codex instructions for matching OpenAI models. Changes apply on the next prompt.",
18
- get: () => readHarnessSetting(templateKey) === true ? "On" : "Off",
19
- change(value: string) { updateHarnessSetting(templateKey, () => value === "On"); },
20
- };
21
12
  const supervisorMode = {
22
13
  id: "supervisor-mode", label: "Supervisor mode (Beta)", values: ["Off", "On"],
23
14
  description: "Run the selected scenarios for sessions sharing this agent directory. Turning the mode off keeps your selections.",
@@ -46,25 +37,15 @@ export default function harnessSettingsExtension(pi: ExtensionAPI): void {
46
37
  const links = registry.list();
47
38
  const controls = registry.controls();
48
39
  const available = availableActions(actions, links, controls);
49
- const agentDir = getAgentDir();
50
- let prompt: string | undefined;
51
- let readError: Error | undefined;
52
- try { prompt = currentInstructions(agentDir); }
53
- catch (error) { readError = error instanceof Error ? error : new Error(String(error)); }
54
- const state = readError ? "Unavailable" : prompt === undefined ? "Off" : "On";
55
40
  try {
56
41
  selected = await chooseHarnessSetting(ctx, links, selected, {
57
42
  get: readSettings,
58
43
  change: mode => changeCallbackSetting(pi, ctx, mode),
59
44
  save: () => saveCallbackDefault(readSettings().mode),
60
- }, [...controls, nativeCompactionSetting, modelInstructionTemplate, supervisorMode], [
45
+ }, [...controls, nativeCompactionSetting, supervisorMode], [
61
46
  ...available,
62
47
  { id: "supervisor:scenarios", label: "Supervisor scenarios", kind: "page",
63
48
  description: "Choose which scenarios run when Supervisor mode is on." },
64
- { id: "instructions:toggle", label: "Harness instructions (Beta)", kind: "toggle", value: state,
65
- description: "Toggle the global APPEND_SYSTEM.md block. Applies on startup or /reload." },
66
- ...(prompt === undefined ? [] : [{ id: "instructions:edit", label: "Instructions prompt", kind: "editor" as const,
67
- description: "Edit the Markdown included in the Harness block." }]),
68
49
  ]);
69
50
  } catch (error) {
70
51
  ctx.ui.notify(`Settings unavailable: ${error instanceof Error ? error.message : String(error)}`, "error");
@@ -82,30 +63,6 @@ export default function harnessSettingsExtension(pi: ExtensionAPI): void {
82
63
  catch (error) { ctx.ui.notify(`Supervisor mode: ${error instanceof Error ? error.message : String(error)}`, "error"); }
83
64
  continue;
84
65
  }
85
- if (selected.startsWith("instructions:")) {
86
- try {
87
- if (readError) throw readError;
88
- if (selected === "instructions:edit" && prompt !== undefined) {
89
- const edited = await ctx.ui.editor("Harness instructions", prompt);
90
- if (edited === undefined) continue;
91
- const next = validateInstructionsPrompt(edited);
92
- manageInstructions("sync", agentDir, {
93
- previous: prompt,
94
- saveSource: () => updateHarnessSetting("instructionsPrompt", () => next),
95
- });
96
- } else if (prompt === undefined) {
97
- if (readHarnessSetting("instructionsFile") === false) {
98
- updateHarnessSetting("instructionsFile", current => current === false ? undefined : current);
99
- }
100
- manageInstructions("enable", agentDir);
101
- } else {
102
- manageInstructions("disable", agentDir);
103
- }
104
- } catch (error) {
105
- ctx.ui.notify(`Harness instructions: ${error instanceof Error ? error.message : String(error)}`, "error");
106
- }
107
- continue;
108
- }
109
66
  const link = links.find(item => `link:${item.id}` === selected);
110
67
  if (!link) continue;
111
68
  try { await link.open(ctx); }
@@ -35,9 +35,8 @@ const groups: [string, string, string[]][] = [
35
35
  ["Supervision", "Scenarios", ["setting:supervisor-mode", "supervisor:scenarios"]],
36
36
  ["Supervision", "Recovery", ["action:Recovery commitments"]],
37
37
  ["OpenAI Optimization", "Context", ["setting:native-compaction"]],
38
- ["OpenAI Optimization", "Instructions", ["setting:model-instruction-template"]],
39
38
  ["Prompts", "Session recap", ["setting:session-recap", "link:recap-prompt", "action:Recap prompt"]],
40
- ["Prompts", "Instructions", ["link:prompts-web", "instructions:toggle", "link:prompt-manager", "action:Prompt manager", "instructions:edit"]],
39
+ ["Prompts", "Instructions", ["link:prompts-web"]],
41
40
  ["Prompts", "Experiments", ["action:Capture next response", "action:Capture task", "action:Load evaluation cases", "action:Export reviewed replay", "action:Case-based proposals"]],
42
41
  ["Remote", "Sessions", ["action:Remote sessions", "action:Move session to host"]],
43
42
  ["Audio", "Playback", ["action:Read aloud", "action:Stop playback"]],
@@ -1,5 +1,5 @@
1
1
  import { randomUUID } from "node:crypto";
2
- import { lstatSync, readFileSync, realpathSync, renameSync, rmSync, writeFileSync } from "node:fs";
2
+ import { lstatSync, mkdirSync, readFileSync, realpathSync, renameSync, rmSync, writeFileSync } from "node:fs";
3
3
  import { homedir } from "node:os";
4
4
  import { dirname, join, resolve } from "node:path";
5
5
  import { fileURLToPath } from "node:url";
@@ -153,8 +153,7 @@ export function preflightHarnessInstall(local, options = {}) {
153
153
  };
154
154
  }
155
155
 
156
- export function configureHarnessResources(local, options = {}) {
157
- const path = settingsPath(local, options);
156
+ function mutateSettings(path, allowMissing, mutate) {
158
157
  const destination = writeDestination(path);
159
158
  let release;
160
159
  try {
@@ -167,7 +166,34 @@ export function configureHarnessResources(local, options = {}) {
167
166
  try {
168
167
  // Read inside the lock and replace atomically so concurrent Pi writes are
169
168
  // never clobbered by a stale snapshot.
170
- const settings = readSettings(path);
169
+ const settings = readSettings(path, { allowMissing }) ?? {};
170
+ const result = mutate(settings);
171
+ temp = join(dirname(destination), `.settings-${randomUUID()}.tmp`);
172
+ writeFileSync(temp, `${JSON.stringify(settings, null, 2)}\n`, { mode: 0o600, flag: "wx" });
173
+ renameSync(temp, destination);
174
+ return result;
175
+ } finally {
176
+ if (temp) rmSync(temp, { force: true });
177
+ release();
178
+ }
179
+ }
180
+
181
+ export function updateHarnessDefault(dir, key, update) {
182
+ mkdirSync(dir, { recursive: true });
183
+ return mutateSettings(join(dir, "settings.json"), true, settings => {
184
+ if (!Object.hasOwn(settings, "piBetterHarness")) settings.piBetterHarness = {};
185
+ const values = settings.piBetterHarness;
186
+ if (!values || typeof values !== "object" || Array.isArray(values)) throw Error("Expected piBetterHarness to be an object.");
187
+ const next = update(values[key]);
188
+ if (next === undefined) delete values[key];
189
+ else values[key] = next;
190
+ return next;
191
+ });
192
+ }
193
+
194
+ export function configureHarnessResources(local, options = {}) {
195
+ const path = settingsPath(local, options);
196
+ mutateSettings(path, false, settings => {
171
197
  const packages = settings.packages ?? [];
172
198
  const harness = packages.find((entry) => matchesPackage(entry, HARNESS_PACKAGE));
173
199
  if (!harness) throw new Error("Pi did not register pi-better-harness");
@@ -189,12 +215,5 @@ export function configureHarnessResources(local, options = {}) {
189
215
  ),
190
216
  filteredHarness,
191
217
  ];
192
-
193
- temp = join(dirname(destination), `.settings-${randomUUID()}.tmp`);
194
- writeFileSync(temp, `${JSON.stringify(settings, null, 2)}\n`, { mode: 0o600, flag: "wx" });
195
- renameSync(temp, destination);
196
- } finally {
197
- if (temp) rmSync(temp, { force: true });
198
- release();
199
- }
218
+ });
200
219
  }
@@ -69,7 +69,7 @@ export async function managerAction(dir, args, session) {
69
69
  }
70
70
  if (action === "recommend_fork") return session ? session.run(args) : [];
71
71
  if (action === "replay" || action === "evaluate" || action === "fork") {
72
- if (!session) throw Error("No Pi session connected. Enable the connection in Prompt manager in Pi.");
72
+ if (!session) throw Error("No Pi session connected. Open Manage prompts in Pi and connect its session.");
73
73
  readRevision(dir, base);
74
74
  readRevision(dir, candidate);
75
75
  const result = await session.run(args);
@@ -1,7 +1,6 @@
1
1
  import { createHash, randomUUID } from "node:crypto";
2
2
  import { Type } from "@sinclair/typebox";
3
3
  import { loadedBlock } from "./prompt-manager.mjs";
4
- import { openPromptManager } from "./prompt-tui.mjs";
5
4
  import { webUiEnabled } from "./web-ui-flag.mjs";
6
5
  import { readFile, writeFile } from "node:fs/promises";
7
6
  import { relative, resolve } from "node:path";
@@ -75,13 +74,15 @@ export default function registerPromptTools(pi) {
75
74
  const codexModelPrompt = registerCodexModelPrompt(pi);
76
75
  const dir = defaultAgentDir();
77
76
  registerLocalSessions(pi, dir);
78
- let shared;
77
+ let promptContext;
78
+ let sharing;
79
79
  let consoleWeb;
80
80
  let catalogContext;
81
81
  async function openWeb(ctx, path) {
82
+ if (path.startsWith("/prompts/")) promptContext = ctx;
82
83
  if (path === "/catalog") catalogContext = ctx;
83
84
  const module = import("./prompt-web.mjs");
84
- const opening = consoleWeb ??= module.then(({startPromptWeb}) => startPromptWeb(dir, () => catalogContext));
85
+ const opening = consoleWeb ??= module.then(({startPromptWeb}) => startPromptWeb(dir, () => catalogContext, promptConnection));
85
86
  try {
86
87
  const [{openConsolePage}, web] = await Promise.all([module, opening]);
87
88
  if (consoleWeb === opening) openConsolePage(web, path, { write: line => ctx.ui.notify(line.trim(), "info") });
@@ -159,28 +160,40 @@ export default function registerPromptTools(pi) {
159
160
  },
160
161
  };
161
162
  };
162
- const openManager = ctx => {
163
- const session = connection(ctx);
164
- return openPromptManager(dir, ctx.ui, session, async () => {
165
- if (shared) { shared.close(); shared = undefined; forks = undefined; return "Browser connection closed."; }
166
- const { shareSession } = await import("./prompt-web.mjs");
167
- shared = await shareSession(dir, session.describe().name, session);
168
- forks = new SessionForks();
169
- return "Session available in the browser connection selector.";
170
- }, () => Boolean(shared), () => openWeb(ctx, "/prompts/edit"));
163
+ const promptConnection = {
164
+ status: () => promptContext ? { connected: Boolean(sharing) } : null,
165
+ async set(enabled) {
166
+ if (!promptContext) throw Error("Open Manage prompts from the Pi session you want to connect.");
167
+ if (!enabled) {
168
+ const pending = sharing;
169
+ sharing = undefined;
170
+ forks = undefined;
171
+ (await pending)?.close();
172
+ } else if (!sharing) {
173
+ const session = connection(promptContext);
174
+ const pending = import("./prompt-web.mjs").then(({ shareSession }) =>
175
+ shareSession(dir, session.describe().name, session));
176
+ sharing = pending;
177
+ try {
178
+ await pending;
179
+ if (sharing === pending) forks = new SessionForks();
180
+ } catch (error) {
181
+ if (sharing === pending) sharing = undefined;
182
+ throw error;
183
+ }
184
+ } else await sharing;
185
+ return this.status();
186
+ },
171
187
  };
172
188
  const browserLinks = [
173
189
  { id: "catalog-web", label: "Edit agent defaults", target: "browser",
174
190
  description: "Choose a model and reasoning effort for personal roles and named agents.", open: ctx => openWeb(ctx, "/catalog") },
175
- { id: "prompts-web", label: "Edit prompt modules", target: "browser",
176
- description: "Edit Harness prompt modules, preview a draft and publish a revision.", open: ctx => openWeb(ctx, "/prompts/edit") },
191
+ { id: "prompts-web", label: "Manage prompts", target: "browser",
192
+ description: "Manage Harness instructions, prompt revisions and model instruction templates.", open: ctx => openWeb(ctx, "/prompts/edit") },
177
193
  ];
178
194
  pi.events?.on("harness-settings:request", () => {
179
- pi.events.emit("harness-settings:register",
180
- { id: "prompt-manager", label: "Prompt manager", command: "/harness-settings prompt-manager", open: openManager });
181
195
  if (webUiEnabled()) for (const link of browserLinks) pi.events.emit("harness-settings:register", link);
182
196
  });
183
- pi.registerCommand("prompt-manager", { description: "Manage Harness prompt revisions", handler: (_, ctx) => openManager(ctx) });
184
197
  let capture;
185
198
  let run;
186
199
  let cases = writingCases;
@@ -192,8 +205,10 @@ export default function registerPromptTools(pi) {
192
205
  const opening = consoleWeb;
193
206
  consoleWeb = undefined;
194
207
  catalogContext = undefined;
195
- shared?.close();
196
- shared = undefined;
208
+ promptContext = undefined;
209
+ const pending = sharing;
210
+ sharing = undefined;
211
+ (await pending?.catch(() => undefined))?.close();
197
212
  forks = undefined;
198
213
  task?.snapshot.dispose();
199
214
  task = undefined;
package/lib/prompt-ui.mjs CHANGED
@@ -208,6 +208,13 @@ async function refresh(preferredEvidence) {
208
208
  const previous = state?.selected;
209
209
  state = await api("host_prompt_state"); selected = state.selected;
210
210
  agentDirectory(state.agentDir);
211
+ showConnection(state.connection);
212
+ const enabled = state.installed !== null;
213
+ el("instructions-enabled").checked = enabled;
214
+ el("instructions-enabled").disabled = false;
215
+ el("instructions-override").hidden = !enabled;
216
+ el("instructions-text").value = state.installed ?? "";
217
+ el("clear-instructions").hidden = state.source !== "saved prompt";
211
218
  el("active-id").textContent = state.active?.slice(0,12) || state.source;
212
219
  el("active-id").title = state.active || "";
213
220
  if (previous !== selected) { rows = structuredClone(state.modules); focused = rows[0]; }
@@ -319,6 +326,39 @@ async function refreshPair(preferredEvidence) {
319
326
  showEvidence();
320
327
  await refreshReplay();
321
328
  }
329
+ function showConnection(connection) {
330
+ const button = el("prompt-connection");
331
+ button.hidden = !connection;
332
+ if (!connection) return;
333
+ button.textContent = connection.connected ? "Disconnect this Pi session" : "Connect this Pi session";
334
+ button.onclick = handle(async () => {
335
+ showConnection(await api("set_prompt_connection", { enabled: !connection.connected }));
336
+ if (!el("templates").hidden) await showTemplate(true);
337
+ else await refreshReplay();
338
+ });
339
+ }
340
+ el("instructions-enabled").onchange = handle(async () => {
341
+ const control = el("instructions-enabled");
342
+ try { await api("set_instructions_enabled", { enabled: control.checked }); }
343
+ catch (error) { control.checked = state.installed !== null; throw error; }
344
+ await refresh();
345
+ });
346
+ el("save-instructions").onclick = handle(async () => {
347
+ await api("save_instructions_text", { previous: state.installed, text: el("instructions-text").value });
348
+ await refresh();
349
+ el("notice").textContent = "Override saved. Reload Pi to use it.";
350
+ });
351
+ el("clear-instructions").onclick = handle(async () => {
352
+ await api("clear_instructions_text", {previous:state.installed});
353
+ await refresh();
354
+ el("notice").textContent = "Override removed. Reload Pi to use the restored instructions.";
355
+ });
356
+ el("template-enabled").onchange = handle(async () => {
357
+ const control = el("template-enabled");
358
+ try { templateCatalog.enabled = await api("set_codex_templates", { enabled: control.checked }); }
359
+ finally { control.checked = templateCatalog.enabled; }
360
+ el("notice").textContent = "Saved. Applies on the next prompt.";
361
+ });
322
362
  let templateCatalog, templateRequest = 0;
323
363
  async function showTemplate(reloadCatalog = false) {
324
364
  const request = ++templateRequest;
@@ -328,9 +368,13 @@ async function showTemplate(reloadCatalog = false) {
328
368
  message.textContent = "Loading template…";
329
369
  try {
330
370
  if (reloadCatalog || !templateCatalog) {
371
+ el("template-enabled").disabled = true;
331
372
  const catalog = await api("codex_template_catalog");
332
373
  if (request !== templateRequest) return;
333
374
  templateCatalog = catalog;
375
+ showConnection(catalog.connection);
376
+ el("template-enabled").checked = catalog.enabled;
377
+ el("template-enabled").disabled = false;
334
378
  const previous = source.value;
335
379
  const releases = node("optgroup"); releases.label = "Packaged releases";
336
380
  for (const release of catalog.releases) releases.append(new Option(release.tag, release.tag));
@@ -4,6 +4,8 @@ import { mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from "nod
4
4
  import { join } from "node:path";
5
5
  import { spawn } from "node:child_process";
6
6
  import { hostInventories, mcpAuthenticator } from "./console-inventory.mjs";
7
+ import { currentInstructions, manageInstructions, validateInstructionsPrompt } from "./instructions.mjs";
8
+ import { readHarnessDefaults, updateHarnessDefault } from "./install-settings.mjs";
7
9
  import { managerAction } from "./prompt-manager.mjs";
8
10
  import { codexTemplateCatalog, readCodexTemplate } from "./codex-model-prompt.mjs";
9
11
  import { evaluateSessions, sessionSelection } from "./prompt-sessions.mjs";
@@ -92,7 +94,7 @@ function connections(dir, id) {
92
94
  catch (e) { if (e.code !== "ENOENT") throw e; return []; }
93
95
  });
94
96
  }
95
- export async function startPromptWeb(dir, catalogContext) {
97
+ export async function startPromptWeb(dir, catalogContext, promptConnection) {
96
98
  const inventory = hostInventories(dir);
97
99
  const authenticate = mcpAuthenticator(dir);
98
100
  return listen(async args => {
@@ -106,8 +108,32 @@ export async function startPromptWeb(dir, catalogContext) {
106
108
  if (args.action === "save_personal_defaults") throw Error("Open the agent editor from the Agents tab in Pi.");
107
109
  }
108
110
  if (args.action === "host_inventory") return inventory(args.inventory);
109
- if (args.action === "codex_template_catalog") return { ...codexTemplateCatalog(), sessions: connections(dir).map(({id, name}) => ({id, name})) };
110
- if (args.action === "host_prompt_state") return {...await managerAction(dir,{...args,action:"state"},null),agentDir:dir};
111
+ if (args.action === "set_prompt_connection") {
112
+ if (!promptConnection || typeof args.enabled !== "boolean") throw Error("Open Manage prompts in the owning Pi session.");
113
+ return promptConnection.set(args.enabled);
114
+ }
115
+ if (["set_codex_templates", "set_instructions_enabled", "save_instructions_text", "clear_instructions_text"].includes(args.action)) {
116
+ if (args.action === "save_instructions_text" || args.action === "clear_instructions_text") {
117
+ const clear = args.action === "clear_instructions_text";
118
+ if (typeof args.previous !== "string" || (!clear && typeof args.text !== "string")) throw Error("Expected instruction text.");
119
+ const next = clear ? undefined : validateInstructionsPrompt(args.text);
120
+ return manageInstructions("sync", dir, { previous: args.previous,
121
+ saveSource: () => updateHarnessDefault(dir, "instructionsPrompt", () => next) });
122
+ }
123
+ if (typeof args.enabled !== "boolean") throw Error("Expected a boolean setting.");
124
+ if (args.action === "set_codex_templates") {
125
+ return updateHarnessDefault(dir, "openaiModelInstructionTemplate", () => args.enabled);
126
+ }
127
+ if (args.enabled && readHarnessDefaults(dir).instructionsFile === false) {
128
+ updateHarnessDefault(dir, "instructionsFile", current => current === false ? undefined : current);
129
+ }
130
+ manageInstructions(args.enabled ? "enable" : "disable", dir);
131
+ return currentInstructions(dir) !== undefined;
132
+ }
133
+ if (args.action === "codex_template_catalog") return { ...codexTemplateCatalog(),
134
+ enabled: readHarnessDefaults(dir).openaiModelInstructionTemplate === true, connection: promptConnection?.status() ?? null,
135
+ sessions: connections(dir).map(({id, name}) => ({id, name})) };
136
+ if (args.action === "host_prompt_state") return {...await managerAction(dir,{...args,action:"state"},null),agentDir:dir, connection:promptConnection?.status() ?? null};
111
137
  if (["console_status","console_start","console_frame","console_inventory"].includes(args.action)) {
112
138
  const {consoleDaemon} = await import("./console-daemon.mjs");
113
139
  return consoleDaemon(dir,args);
@@ -116,12 +142,12 @@ export async function startPromptWeb(dir, catalogContext) {
116
142
  const list = needsPeer ? connections(dir, args.action === "codex_template" ? args.session : undefined) : [];
117
143
  const selected = list.find(s => s.id === args.session);
118
144
  const send = async (request, peer = selected) => {
119
- if (!peer) throw Error("Pi session disconnected. Reconnect from Prompt manager in Pi.");
145
+ if (!peer) throw Error("Pi session disconnected. Open Manage prompts in Pi and connect its session.");
120
146
  const origin = "http://127.0.0.1:" + Number(peer.port);
121
147
  let response;
122
148
  try { response = await fetch(origin + "/api", { method: "POST", redirect: "error",
123
149
  headers: { "content-type": "application/json", origin, authorization: "Bearer " + peer.token }, body: JSON.stringify(request) }); }
124
- catch { throw Error("Pi session closed. Reconnect from Prompt manager in Pi."); }
150
+ catch { throw Error("Pi session closed. Open Manage prompts in Pi and connect its session."); }
125
151
  if (response.status === 403) throw Error("Pi session connection expired.");
126
152
  const data = await response.json();
127
153
  if (!response.ok) throw Error(data.error);
package/lib/prompt.css CHANGED
@@ -177,3 +177,5 @@ mark { background: #d3eecf; color: var(--ink) }
177
177
  .module-list h3 { grid-column: 1/-1 } .workspace > section { padding: 14px }
178
178
  .filters,.panel-head,.panel-foot { padding-inline: 12px } .panel-head h2 { font-size: 18px }
179
179
  }
180
+ .prompt-toggle { display: flex; flex-direction: row; align-items: center; gap: .5rem; margin-block: 1rem; }
181
+ .prompt-toggle input { width: auto; }
package/lib/prompt.html CHANGED
@@ -2,17 +2,20 @@
2
2
  <title>Prompt manager · Pi Better Harness</title><link rel="stylesheet" href="/manager.css"></head><body><aside class="rail"><div class="brand"><img src="/console-logo.png" width="40" height="40" alt=""><div><b>Pi Better <br>Harness</b><small>Local console</small></div></div>
3
3
  <nav aria-label="Main navigation"></nav><div class="rail-foot" hidden>Agent directory<code></code></div></aside>
4
4
  <header class="crumb">Local <span>/</span> <strong></strong></header>
5
- <main class="prompts"><div class="page-head"><h1>Prompt manager</h1><a class="action" href="#revision-history" id="history-link">Revision history</a></div>
5
+ <main class="prompts"><div class="page-head"><h1>Prompt manager</h1><button id="prompt-connection" hidden></button><a class="action" href="#revision-history" id="history-link">Revision history</a></div>
6
6
  <div class="revision-bar panel"><div><span class="caption">Active revision</span><strong id="active-id"></strong></div>
7
7
  <label>Editing from<select id="revisions"></select></label><button id="refresh">Refresh</button></div>
8
- <p role="status" id="notice"></p><nav class="tabs" aria-label="Prompt workspace"><button data-view="edit">Edit</button><button data-view="replay">Replay</button><button data-view="templates">Model templates</button></nav>
8
+ <p role="status" id="notice"></p><nav class="tabs" aria-label="Prompt workspace"><button data-view="edit">Edit</button><button data-view="replay">Replay</button><button data-view="templates">Model instruction templates</button></nav>
9
9
  <section id="templates" hidden>
10
10
  <div class="page-head"><h2>Official Codex templates</h2><button id="template-refresh">Refresh</button></div>
11
+ <label class="prompt-toggle"><input type="checkbox" id="template-enabled" disabled>Use model instruction templates for matching OpenAI models</label>
11
12
  <div class="template-selectors"><label>Source<select id="template-source"></select></label><label id="template-model-label">Model<select id="template-model"></select></label></div>
12
13
  <p id="template-message" role="status"></p>
13
14
  <article id="template-result" hidden><h3 id="template-title"></h3><dl class="metadata"><dt>Release</dt><dd><a id="template-upstream"></a></dd><dt>SHA-256</dt><dd><code id="template-digest"></code></dd></dl><pre id="template-text" tabindex="0" aria-label="Original template text"></pre></article>
14
15
  </section>
15
- <section id="edit"><div class="workspace">
16
+ <section id="edit"><details class="panel disclosure"><summary>Harness instructions</summary>
17
+ <label class="prompt-toggle"><input type="checkbox" id="instructions-enabled" disabled>Enable Harness instructions</label>
18
+ <div id="instructions-override" hidden><label>Full-text override<textarea id="instructions-text" rows="8"></textarea></label><button id="save-instructions">Save override</button><button id="clear-instructions" hidden>Remove override</button></div></details><div class="workspace">
16
19
  <section class="panel module-list"><h2>Modules</h2><div id="rows"></div><button id="add">+ Add module</button></section>
17
20
  <section class="panel module-edit"><span id="module-origin" class="caption"></span><h2 id="module-title">Module</h2><code id="module-id"></code><div id="editor"></div>
18
21
  <details><summary>Review changes</summary><pre id="draftDiff"></pre></details><footer><button class="primary" id="save">Save revision</button><button id="compare">Replay saved revision</button></footer></section>
@@ -50,7 +50,6 @@ const features: Feature[] = [
50
50
  ["View commitments", ""], ["Schedule a reminder", "remind", "Commitment ID and minutes"],
51
51
  ] } },
52
52
  { name: "recap-prompt", tab: "Prompts", label: "Recap prompt", link: "recap-prompt" },
53
- { name: "prompt-manager", tab: "Prompts", label: "Prompt manager", link: "prompt-manager" },
54
53
  { name: "prompt-capture", tab: "Prompts", label: "Capture next response" },
55
54
  { name: "prompt-task-capture", tab: "Prompts", label: "Capture task", operations: { "Capture": [["Capture", "", "Task manifest path"]] } },
56
55
  { name: "prompt-import", tab: "Prompts", label: "Load evaluation cases", operations: { "Cases": [
@@ -36,9 +36,8 @@ const groups: [string, string, string[]][] = [
36
36
  ["Supervision", "Scenarios", ["setting:supervisor-mode", "supervisor:scenarios"]],
37
37
  ["Supervision", "Recovery", ["action:Recovery commitments"]],
38
38
  ["OpenAI Optimization", "Context", ["setting:native-compaction"]],
39
- ["OpenAI Optimization", "Instructions", ["setting:model-instruction-template"]],
40
39
  ["Prompts", "Session recap", ["setting:session-recap", "link:recap-prompt", "action:Recap prompt"]],
41
- ["Prompts", "Instructions", ["link:prompts-web", "instructions:toggle", "link:prompt-manager", "action:Prompt manager", "instructions:edit"]],
40
+ ["Prompts", "Instructions", ["link:prompts-web"]],
42
41
  ["Prompts", "Experiments", ["action:Capture next response", "action:Capture task", "action:Load evaluation cases", "action:Export reviewed replay", "action:Case-based proposals"]],
43
42
  ["Remote", "Sessions", ["action:Remote sessions", "action:Move session to host"]],
44
43
  ["Audio", "Playback", ["action:Read aloud", "action:Stop playback"]],
@@ -50,7 +50,6 @@ const features: Feature[] = [
50
50
  ["View commitments", ""], ["Schedule a reminder", "remind", "Commitment ID and minutes"],
51
51
  ] } },
52
52
  { name: "recap-prompt", tab: "Prompts", label: "Recap prompt", link: "recap-prompt" },
53
- { name: "prompt-manager", tab: "Prompts", label: "Prompt manager", link: "prompt-manager" },
54
53
  { name: "prompt-capture", tab: "Prompts", label: "Capture next response" },
55
54
  { name: "prompt-task-capture", tab: "Prompts", label: "Capture task", operations: { "Capture": [["Capture", "", "Task manifest path"]] } },
56
55
  { name: "prompt-import", tab: "Prompts", label: "Load evaluation cases", operations: { "Cases": [
@@ -36,9 +36,8 @@ const groups: [string, string, string[]][] = [
36
36
  ["Supervision", "Scenarios", ["setting:supervisor-mode", "supervisor:scenarios"]],
37
37
  ["Supervision", "Recovery", ["action:Recovery commitments"]],
38
38
  ["OpenAI Optimization", "Context", ["setting:native-compaction"]],
39
- ["OpenAI Optimization", "Instructions", ["setting:model-instruction-template"]],
40
39
  ["Prompts", "Session recap", ["setting:session-recap", "link:recap-prompt", "action:Recap prompt"]],
41
- ["Prompts", "Instructions", ["link:prompts-web", "instructions:toggle", "link:prompt-manager", "action:Prompt manager", "instructions:edit"]],
40
+ ["Prompts", "Instructions", ["link:prompts-web"]],
42
41
  ["Prompts", "Experiments", ["action:Capture next response", "action:Capture task", "action:Load evaluation cases", "action:Export reviewed replay", "action:Case-based proposals"]],
43
42
  ["Remote", "Sessions", ["action:Remote sessions", "action:Move session to host"]],
44
43
  ["Audio", "Playback", ["action:Read aloud", "action:Stop playback"]],
@@ -50,7 +50,6 @@ const features: Feature[] = [
50
50
  ["View commitments", ""], ["Schedule a reminder", "remind", "Commitment ID and minutes"],
51
51
  ] } },
52
52
  { name: "recap-prompt", tab: "Prompts", label: "Recap prompt", link: "recap-prompt" },
53
- { name: "prompt-manager", tab: "Prompts", label: "Prompt manager", link: "prompt-manager" },
54
53
  { name: "prompt-capture", tab: "Prompts", label: "Capture next response" },
55
54
  { name: "prompt-task-capture", tab: "Prompts", label: "Capture task", operations: { "Capture": [["Capture", "", "Task manifest path"]] } },
56
55
  { name: "prompt-import", tab: "Prompts", label: "Load evaluation cases", operations: { "Cases": [
@@ -36,9 +36,8 @@ const groups: [string, string, string[]][] = [
36
36
  ["Supervision", "Scenarios", ["setting:supervisor-mode", "supervisor:scenarios"]],
37
37
  ["Supervision", "Recovery", ["action:Recovery commitments"]],
38
38
  ["OpenAI Optimization", "Context", ["setting:native-compaction"]],
39
- ["OpenAI Optimization", "Instructions", ["setting:model-instruction-template"]],
40
39
  ["Prompts", "Session recap", ["setting:session-recap", "link:recap-prompt", "action:Recap prompt"]],
41
- ["Prompts", "Instructions", ["link:prompts-web", "instructions:toggle", "link:prompt-manager", "action:Prompt manager", "instructions:edit"]],
40
+ ["Prompts", "Instructions", ["link:prompts-web"]],
42
41
  ["Prompts", "Experiments", ["action:Capture next response", "action:Capture task", "action:Load evaluation cases", "action:Export reviewed replay", "action:Case-based proposals"]],
43
42
  ["Remote", "Sessions", ["action:Remote sessions", "action:Move session to host"]],
44
43
  ["Audio", "Playback", ["action:Read aloud", "action:Stop playback"]],
@@ -50,7 +50,6 @@ const features: Feature[] = [
50
50
  ["View commitments", ""], ["Schedule a reminder", "remind", "Commitment ID and minutes"],
51
51
  ] } },
52
52
  { name: "recap-prompt", tab: "Prompts", label: "Recap prompt", link: "recap-prompt" },
53
- { name: "prompt-manager", tab: "Prompts", label: "Prompt manager", link: "prompt-manager" },
54
53
  { name: "prompt-capture", tab: "Prompts", label: "Capture next response" },
55
54
  { name: "prompt-task-capture", tab: "Prompts", label: "Capture task", operations: { "Capture": [["Capture", "", "Task manifest path"]] } },
56
55
  { name: "prompt-import", tab: "Prompts", label: "Load evaluation cases", operations: { "Cases": [
@@ -36,9 +36,8 @@ const groups: [string, string, string[]][] = [
36
36
  ["Supervision", "Scenarios", ["setting:supervisor-mode", "supervisor:scenarios"]],
37
37
  ["Supervision", "Recovery", ["action:Recovery commitments"]],
38
38
  ["OpenAI Optimization", "Context", ["setting:native-compaction"]],
39
- ["OpenAI Optimization", "Instructions", ["setting:model-instruction-template"]],
40
39
  ["Prompts", "Session recap", ["setting:session-recap", "link:recap-prompt", "action:Recap prompt"]],
41
- ["Prompts", "Instructions", ["link:prompts-web", "instructions:toggle", "link:prompt-manager", "action:Prompt manager", "instructions:edit"]],
40
+ ["Prompts", "Instructions", ["link:prompts-web"]],
42
41
  ["Prompts", "Experiments", ["action:Capture next response", "action:Capture task", "action:Load evaluation cases", "action:Export reviewed replay", "action:Case-based proposals"]],
43
42
  ["Remote", "Sessions", ["action:Remote sessions", "action:Move session to host"]],
44
43
  ["Audio", "Playback", ["action:Read aloud", "action:Stop playback"]],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-better-harness",
3
- "version": "0.66.1",
3
+ "version": "0.67.1",
4
4
  "description": "Pi extension bundle for a write sandbox, subagents, background tasks, SSH, Goals, and Todo lists.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,113 +0,0 @@
1
- import { managerAction } from "./prompt-manager.mjs";
2
- import { comparisonReport } from "./prompt-report.mjs";
3
- import { webUiEnabled } from "./web-ui-flag.mjs";
4
-
5
- async function choose(ui, title, items) {
6
- const label = await ui.select(title, items.map(i => i.label));
7
- return items.find(i => i.label === label);
8
- }
9
-
10
- export async function openPromptManager(dir, ui, session, toggleShare, isShared, openBrowser) {
11
- let candidate;
12
- const request = args => managerAction(dir, args, session);
13
- for (;;) {
14
- let state;
15
- try { state = await request({ action: "state", candidate }); }
16
- catch (error) { ui.notify(error.message, "error"); return; }
17
- try {
18
- candidate = state.selected;
19
- const pair = { base: state.active, candidate };
20
- const loaded = state.session.loaded === null ? "no managed block" : state.loadedRevision?.slice(0, 10) ?? "override or unknown";
21
- const modelPrompt = state.session.codexModelPrompt;
22
- const reload = (state.loadNotice ? "\n" + state.loadNotice : "") + (modelPrompt
23
- ? `\n${modelPrompt.model} | openai/codex ${modelPrompt.tag} | SHA-256 ${modelPrompt.sha256}` : "");
24
- const share = isShared() ? "Disconnect browser" : "Connect browser";
25
- const action = await ui.select(`Prompt manager | ${state.source} | Active ${state.active.slice(0, 10)} | Selected ${candidate.slice(0, 10)}\nInstalled ${state.installedRevision?.slice(0, 10) ?? state.source} | Loaded ${loaded}${reload}`, [
26
- "Choose revision", "Modules", "Preview", "Review changes", "Publish manually", "History and rollback",
27
- "Replay a response", "Evaluate a case suite", "Evidence",
28
- ...(webUiEnabled() ? ["Open in browser", share] : []), "Close",
29
- ]);
30
- if (!action || action === "Close") return;
31
- if (action === "Choose revision") {
32
- candidate = (await choose(ui, "Revisions", state.records))?.id ?? candidate;
33
- } else if (action === "Modules") {
34
- const rows = structuredClone(state.modules);
35
- for (;;) {
36
- const item = await ui.select("Candidate modules", [...rows.map(r => r.id), "Add module", "Preview draft", "Save candidate"]);
37
- if (!item) break;
38
- if (item === "Save candidate") { candidate = await request({ action: "save", candidate, modules: rows }); break; }
39
- if (item === "Preview draft") { await ui.editor(item, await request({ action: "preview", candidate, modules: rows })); continue; }
40
- if (item === "Add module") {
41
- const id = await ui.input("Module name");
42
- if (!id) continue;
43
- const text = await ui.editor(id, "");
44
- if (text?.trim()) rows.push({ id:"user:" + id, origin:"user", text });
45
- continue;
46
- }
47
- const i = rows.findIndex(r => r.id === item);
48
- if (rows[i].origin === "bundled") {
49
- const bundle = state.attribution.bundled.find(r => r.id === item);
50
- const op = await ui.select(`${item} / ${rows[i].enabled ? "On" : "Off"} / ${bundle.version}`,
51
- ["Read shipped text", "Edit local override", "Reset to original", rows[i].enabled ? "Turn off" : "Turn on", "Package validation"]);
52
- if (op === "Edit local override") {
53
- const text = await ui.editor(item, rows[i].override ?? rows[i].text);
54
- if (text !== undefined) rows[i].override = text;
55
- }
56
- if (op === "Reset to original") { delete rows[i].override; delete rows[i].overrideBase; }
57
- if (op === "Turn off" || op === "Turn on") rows[i].enabled = op === "Turn on";
58
- if (op === "Read shipped text") await ui.editor(item + " (read-only)", rows[i].original);
59
- if (op === "Package validation") await ui.editor("Package validation", state.attribution.packageEvidence
60
- ? state.attribution.packageEvidence.scope + "\n" + state.attribution.packageEvidence.url : "No matching upstream evidence.");
61
- continue;
62
- }
63
- const op = await ui.select(item, ["Edit text", "Move up", "Move down", "Remove"]);
64
- if (op === "Edit text") rows[i].text = await ui.editor(item, rows[i].text) ?? rows[i].text;
65
- if (op === "Remove") rows.splice(i, 1);
66
- if (op === "Move up" && rows[i-1]?.origin === "user") rows.splice(i - 1, 0, rows.splice(i, 1)[0]);
67
- if (op === "Move down" && i < rows.length - 1) rows.splice(i + 1, 0, rows.splice(i, 1)[0]);
68
- }
69
- } else if (action === "Preview") {
70
- await ui.editor("Rendered prompt", state.rendered);
71
- } else if (action === "Review changes") {
72
- await ui.editor("Changes", `Parent ${state.parent ?? "(bundled)"}\n${state.parentDiff}\n\nActive ${state.active}\n${state.diff}`);
73
- } else if (action === "Publish manually") {
74
- if (await ui.confirm(action, state.diff + "\nPublish " + candidate + "?")) await request({ action: "publish", ...pair, confirmed: true });
75
- } else if (action === "History and rollback") {
76
- const entry = await choose(ui, action, state.history.map((h, i) => ({ ...h, label: `${i + 1}. ${h.action} ${h.from.slice(0, 10)} → ${h.to.slice(0, 10)}` })).reverse());
77
- if (entry && await ui.confirm("Rollback", "Restore " + entry.from + "?"))
78
- candidate = await request({ action: "rollback", base: state.active, candidate: entry.from, confirmed: true });
79
- } else if (action === "Open in browser") {
80
- await openBrowser();
81
- } else if (action === share) {
82
- ui.notify(await toggleShare(), "info");
83
- } else if (action === "Evidence") {
84
- const entry = await choose(ui, "Recorded comparisons", state.evidence.map((e, i) => ({ ...e,
85
- label: `${i + 1}. ${e.suite ?? e.model ?? "Comparison"} / ${e.judgment ?? "Awaiting judgment"}` })));
86
- if (!entry) continue;
87
- await ui.editor("Evidence", comparisonReport(entry));
88
- const op = await ui.select("Evidence", [...(entry.baselineOutput ? ["Compare baseline rerun"] : []),"Record judgment", ...(entry.judgment ? ["Promote evaluated revision"] : [])]);
89
- if (op === "Compare baseline rerun") { await ui.editor("Baseline rerun / Candidate rerun",comparisonReport(entry,"baseline")); continue; }
90
- if (op === "Record judgment") {
91
- const judgment = await ui.input("Judgment");
92
- if (judgment) await request({ action: "judge", base: entry.active, candidate, evidence: entry.evidenceId, judgment });
93
- } else if (op && await ui.confirm(op, state.diff)) await request({ action: "promote", ...pair, evidence: entry.evidenceId, confirmed: true });
94
- } else {
95
- let result;
96
- if (action === "Replay a response") {
97
- if (!state.session.captures.length) throw Error("No captured response. Use /harness-settings prompt-capture before sending a request.");
98
- const selected = await choose(ui, "Captured response", state.session.captures);
99
- if (selected) result = await request({ action: "replay", ...pair, caseId: selected.id });
100
- } else {
101
- if (!state.session.models.length) throw Error("No supported openai-completions model.");
102
- const selected = await choose(ui, "Reviewed suite", state.session.suites);
103
- if (!selected) continue;
104
- const model = await ui.select("Model", state.session.models);
105
- if (!model) continue;
106
- const count = await ui.input("Samples per case (1 to 16)", "1");
107
- if (count !== undefined) result = await request({ action: "evaluate", ...pair, suite: selected.id, model, samples: Number(count || 1) });
108
- }
109
- if (result) await ui.editor("Comparison", comparisonReport(result));
110
- }
111
- } catch (error) { ui.notify(error.message, "error"); }
112
- }
113
- }