pi-better-harness 0.66.0 → 0.67.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.
Files changed (44) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +8 -13
  3. package/extensions/settings/commands.ts +0 -1
  4. package/extensions/settings/index.ts +2 -45
  5. package/extensions/settings/page.ts +1 -2
  6. package/lib/install-settings.mjs +31 -12
  7. package/lib/prompt-manager.mjs +1 -1
  8. package/lib/prompt-tools.mjs +34 -19
  9. package/lib/prompt-ui.mjs +44 -0
  10. package/lib/prompt-web.mjs +31 -5
  11. package/lib/prompt.css +2 -0
  12. package/lib/prompt.html +6 -3
  13. package/node_modules/pi-better-background-tasks/package.json +2 -2
  14. package/node_modules/pi-better-background-tasks/runtime-client/artifacts/darwin-arm64.json +1 -1
  15. package/node_modules/pi-better-background-tasks/runtime-client/artifacts/darwin-x64.json +1 -1
  16. package/node_modules/pi-better-background-tasks/runtime-client/artifacts/linux-arm64.json +1 -1
  17. package/node_modules/pi-better-background-tasks/runtime-client/artifacts/linux-x64.json +1 -1
  18. package/node_modules/pi-better-background-tasks/runtime-client/artifacts/win32-x64.json +1 -1
  19. package/node_modules/pi-better-background-tasks/runtime-client/src/runtime/client.mjs +53 -6
  20. package/node_modules/pi-better-background-tasks/runtime-client/src/runtime/startup-worker.mjs +10 -0
  21. package/node_modules/pi-better-background-tasks/src/observed-waits.ts +3 -3
  22. package/node_modules/pi-better-background-tasks/src/shared-harness-commands.ts +0 -1
  23. package/node_modules/pi-better-background-tasks/src/shared-harness-page.ts +1 -2
  24. package/node_modules/pi-better-background-tasks/src/work-observation.ts +11 -8
  25. package/node_modules/pi-better-goal/src/shared-harness-commands.ts +0 -1
  26. package/node_modules/pi-better-goal/src/shared-harness-page.ts +1 -2
  27. package/node_modules/pi-better-sandbox/shared-harness-commands.ts +0 -1
  28. package/node_modules/pi-better-sandbox/shared-harness-page.ts +1 -2
  29. package/node_modules/pi-better-subagents/README.md +4 -1
  30. package/node_modules/pi-better-subagents/index.ts +3 -5
  31. package/node_modules/pi-better-subagents/package.json +2 -2
  32. package/node_modules/pi-better-subagents/runtime-client/artifacts/darwin-arm64.json +1 -1
  33. package/node_modules/pi-better-subagents/runtime-client/artifacts/darwin-x64.json +1 -1
  34. package/node_modules/pi-better-subagents/runtime-client/artifacts/linux-arm64.json +1 -1
  35. package/node_modules/pi-better-subagents/runtime-client/artifacts/linux-x64.json +1 -1
  36. package/node_modules/pi-better-subagents/runtime-client/artifacts/win32-x64.json +1 -1
  37. package/node_modules/pi-better-subagents/runtime-client/src/runtime/client.mjs +53 -6
  38. package/node_modules/pi-better-subagents/runtime-client/src/runtime/startup-worker.mjs +10 -0
  39. package/node_modules/pi-better-subagents/shared-catalog.ts +2 -2
  40. package/node_modules/pi-better-subagents/shared-harness-commands.ts +0 -1
  41. package/node_modules/pi-better-subagents/shared-harness-page.ts +1 -2
  42. package/node_modules/pi-better-subagents/work-observation.ts +52 -26
  43. package/package.json +4 -4
  44. package/lib/prompt-tui.mjs +0 -113
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.67.0] - 2026-12-04
4
+
5
+ ### Changed
6
+
7
+ - 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.
8
+ - 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.
9
+
10
+ ## [0.66.1] - 2026-12-04
11
+
12
+ ### Changed
13
+
14
+ - Pi starts the local task server in the background. You can enter a prompt while the server starts, and the first task reuses the connection.
15
+
3
16
  ## [0.66.0] - 2026-12-04
4
17
 
5
18
  ### Changed
package/README.md CHANGED
@@ -22,13 +22,11 @@ Both Harness install methods include the shared server for subagents and backgro
22
22
 
23
23
  ## Official Codex model prompts
24
24
 
25
- When **Model instruction (Beta)** is on for a matching model on `openai` or `openai-codex`, Harness loads OpenAI's exact
25
+ 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
26
  `model_messages.instructions_template` alongside Pi's own instructions. Both
27
27
  foreground and isolated worker sessions use the packaged catalog. No local
28
28
  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
29
+ 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
30
  read its loaded version. The viewer includes the upstream commit and SHA-256.
33
31
  Sessions pin the release on first use and retain it across resume and fork.
34
32
  Use `/reload` after upgrading Harness to adopt a newer packaged release.
@@ -252,7 +250,7 @@ The navigation stays in place while the selection scrolls. Esc returns from a pa
252
250
  | Background | Current activity, wait reviews and completion delivery |
253
251
  | Display | Pinned panels, tool output and animation |
254
252
  | Supervision | Supervisor mode, scenarios and recovery commitments |
255
- | OpenAI Optimization | Responses compaction and Model instruction (Beta) |
253
+ | OpenAI Optimization | Responses compaction |
256
254
  | Prompts | Recaps, prompt editor and prompt experiments |
257
255
  | Remote | Connect to a host, pull a session or move it to a host |
258
256
  | Audio | Read a reply or selected text aloud and stop playback |
@@ -328,8 +326,7 @@ Recap waits for the foreground turn and queued messages to settle and for the se
328
326
 
329
327
  ### Harness instructions
330
328
 
331
- Open `/harness-settings` and toggle **Harness instructions** from **Off** to
332
- **On**. Choose **Instructions prompt → Edit** to edit the current Markdown.
329
+ In the Web console, open **Prompts → Edit → Harness instructions**. Enable the block to edit its full-text override.
333
330
  Saving updates the Harness block and stores the text in the global Pi settings
334
331
  under `piBetterHarness.instructionsPrompt`. Turning the switch off removes the
335
332
  block. Turning it back on restores the saved text. Changes apply on the next
@@ -348,7 +345,7 @@ including blocks owned by other extensions. To use your own Markdown, set
348
345
  `piBetterHarness.instructionsFile` in the global Pi `settings.json` to an
349
346
  absolute path or a path relative to the agent directory (normally
350
347
  `~/.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.
348
+ over this file. Choose **Remove override** to restore the configured file or modular revision.
352
349
 
353
350
  | Command | Effect |
354
351
  | --- | --- |
@@ -378,7 +375,7 @@ To open either editor from Pi, start `PI_HARNESS_WEB_UI=1 pi`, run
378
375
  `/harness-settings` or `/better-harness-settings`, and press Enter on the
379
376
  first row of **Agents** or **Prompts**. **Edit agent defaults** saves the
380
377
  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**
378
+ the models available to the current Pi session. **Manage prompts**
382
379
  opens the prompt revision editor. The standalone web console opens the
383
380
  catalog in view-only mode. All use the current Pi agent directory
384
381
  (`PI_CODING_AGENT_DIR`). The CLI prints a
@@ -425,12 +422,10 @@ one, or when the reviewed manifest explicitly lists that turn in
425
422
  any unscored session.
426
423
 
427
424
  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
425
+ 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
426
  shutdown. Select a captured request or a suite and model
432
427
  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
428
+ can be reopened in the Web console. Promotion requires a reviewed result
434
429
  for the displayed baseline and candidate.
435
430
 
436
431
  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>
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-better-background-tasks",
3
- "version": "0.21.19",
3
+ "version": "0.21.20",
4
4
  "description": "Pi extension for durable background shell tasks, watchers, logs, and status inspection.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -70,7 +70,7 @@
70
70
  "vitest": "^3.0.0"
71
71
  },
72
72
  "dependencies": {
73
- "pi-better-server": "0.11.10",
73
+ "pi-better-server": "0.11.11",
74
74
  "proper-lockfile": "^4.1.2"
75
75
  }
76
76
  }
@@ -1 +1 @@
1
- {"build":{"contentId":"06b98bf4e6f1e7d77c53fe8ded1995829309d0c843065993a03575f692ad0640","dependencyLockDigest":"4643e416af0b366e78fbaf142d8f69b0591f8a4d3c9db6c07d2ae25157ec9180","format":1,"nodeVersion":"24.14.1","piSdkVersion":"1.7.0","platform":"darwin-arm64","protocolVersion":1,"serverVersion":"0.11.10","sourceDigest":"75441154c84cf249c9abc0b836a6f95f424de3e9bbfb617c5938e025d76d78a7"},"sha256":"49bf8c261c1e4c0ca676641e5d1a59e15ee91a8236df4313feb6e83d5d54f5ab"}
1
+ {"build":{"contentId":"7ea53a9ab306acdb807d91d40e390a626649719ab6c3dc68abac89a5bdf0a50b","dependencyLockDigest":"4643e416af0b366e78fbaf142d8f69b0591f8a4d3c9db6c07d2ae25157ec9180","format":1,"nodeVersion":"24.14.1","piSdkVersion":"1.7.0","platform":"darwin-arm64","protocolVersion":1,"serverVersion":"0.11.11","sourceDigest":"9201868088ad78f5d2c2ded80d7929df5bcbc5e6ce3455c042d80dede4cf384c"},"sha256":"8851a7e15b3082c98017b5d4d6ee11d68e28bab15028100dab71f462c25e939d"}
@@ -1 +1 @@
1
- {"build":{"contentId":"91fac528426cbd0cc8958763e11436b1c23a1080a64ce943f1e0a468b7c99eef","dependencyLockDigest":"4643e416af0b366e78fbaf142d8f69b0591f8a4d3c9db6c07d2ae25157ec9180","format":1,"nodeVersion":"24.14.1","piSdkVersion":"1.7.0","platform":"darwin-x64","protocolVersion":1,"serverVersion":"0.11.10","sourceDigest":"75441154c84cf249c9abc0b836a6f95f424de3e9bbfb617c5938e025d76d78a7"},"sha256":"f399c112766a7da82899f3e1ec69e074e9b2562c304da5199562c21b8564171a"}
1
+ {"build":{"contentId":"6b8c0f8e8dc0e8857f9b506f9b02e4656a55b906ba8e865d674cfd61ea52ccd4","dependencyLockDigest":"4643e416af0b366e78fbaf142d8f69b0591f8a4d3c9db6c07d2ae25157ec9180","format":1,"nodeVersion":"24.14.1","piSdkVersion":"1.7.0","platform":"darwin-x64","protocolVersion":1,"serverVersion":"0.11.11","sourceDigest":"9201868088ad78f5d2c2ded80d7929df5bcbc5e6ce3455c042d80dede4cf384c"},"sha256":"db7abb20bd5a0958676bff1bb8237cbfb01bcaa4fc73030656f72ea5b8046307"}
@@ -1 +1 @@
1
- {"build":{"contentId":"d41ad3e6a413ded11bd420200d93e20673e5259a8b7a502a86a529bea996dc03","dependencyLockDigest":"4643e416af0b366e78fbaf142d8f69b0591f8a4d3c9db6c07d2ae25157ec9180","format":1,"nodeVersion":"24.14.1","piSdkVersion":"1.7.0","platform":"linux-arm64","protocolVersion":1,"serverVersion":"0.11.10","sourceDigest":"75441154c84cf249c9abc0b836a6f95f424de3e9bbfb617c5938e025d76d78a7"},"sha256":"96a4831055f9e95e7b298e10615567cbc19fdf7bf74b4a81784a7611e3c60553"}
1
+ {"build":{"contentId":"41f305a8be6279c9d7772f298faaaa5d13ee5917fc5d594580f4d0020f4319f7","dependencyLockDigest":"4643e416af0b366e78fbaf142d8f69b0591f8a4d3c9db6c07d2ae25157ec9180","format":1,"nodeVersion":"24.14.1","piSdkVersion":"1.7.0","platform":"linux-arm64","protocolVersion":1,"serverVersion":"0.11.11","sourceDigest":"9201868088ad78f5d2c2ded80d7929df5bcbc5e6ce3455c042d80dede4cf384c"},"sha256":"430e3a1bce7f7f870c17e8da26562e0f77bb4c921ba58c4255418357005c0a29"}
@@ -1 +1 @@
1
- {"build":{"contentId":"d531e6509c6baecc9e109a8f31ed03631eccf62ebc1c812432d316a3b7012c24","dependencyLockDigest":"4643e416af0b366e78fbaf142d8f69b0591f8a4d3c9db6c07d2ae25157ec9180","format":1,"nodeVersion":"24.14.1","piSdkVersion":"1.7.0","platform":"linux-x64","protocolVersion":1,"serverVersion":"0.11.10","sourceDigest":"75441154c84cf249c9abc0b836a6f95f424de3e9bbfb617c5938e025d76d78a7"},"sha256":"3cff5bafbedc4f1238596216f8c12ddf0f0740ff21262c7409dbc2cf97f03837"}
1
+ {"build":{"contentId":"59d0b5a9267847833cbe977d923b6ba71e01b60b10ab064a924a722a322d4498","dependencyLockDigest":"4643e416af0b366e78fbaf142d8f69b0591f8a4d3c9db6c07d2ae25157ec9180","format":1,"nodeVersion":"24.14.1","piSdkVersion":"1.7.0","platform":"linux-x64","protocolVersion":1,"serverVersion":"0.11.11","sourceDigest":"9201868088ad78f5d2c2ded80d7929df5bcbc5e6ce3455c042d80dede4cf384c"},"sha256":"d7a9a566e17d45a3122b903d471874dc2131f7ae28eb9b78e182bec3366d7a60"}
@@ -1 +1 @@
1
- {"build":{"contentId":"57cbe0230cf34b955e6b9575fa3ed54b9b2eb5ef58132c1d3f84864d239bfc93","dependencyLockDigest":"4643e416af0b366e78fbaf142d8f69b0591f8a4d3c9db6c07d2ae25157ec9180","format":1,"nodeVersion":"24.14.1","piSdkVersion":"1.7.0","platform":"win32-x64","protocolVersion":1,"serverVersion":"0.11.10","sourceDigest":"75441154c84cf249c9abc0b836a6f95f424de3e9bbfb617c5938e025d76d78a7"},"sha256":"4e76e369fded7c2c0726bee174d532c9ef540a4d4f8b8d792a988fdf4f74160e"}
1
+ {"build":{"contentId":"25560d031d54c564df55a5d21c7b5831bc26f0a821306e66608875a80691d031","dependencyLockDigest":"4643e416af0b366e78fbaf142d8f69b0591f8a4d3c9db6c07d2ae25157ec9180","format":1,"nodeVersion":"24.14.1","piSdkVersion":"1.7.0","platform":"win32-x64","protocolVersion":1,"serverVersion":"0.11.11","sourceDigest":"9201868088ad78f5d2c2ded80d7929df5bcbc5e6ce3455c042d80dede4cf384c"},"sha256":"6d6d0dfd2556e5723e03a6b419edb512cdaa254bbb073935ce265a9d6932e1ff"}