pi-better-harness 0.66.1 → 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.
- package/CHANGELOG.md +7 -0
- package/README.md +8 -13
- package/extensions/settings/commands.ts +0 -1
- package/extensions/settings/index.ts +2 -45
- package/extensions/settings/page.ts +1 -2
- package/lib/install-settings.mjs +31 -12
- package/lib/prompt-manager.mjs +1 -1
- package/lib/prompt-tools.mjs +34 -19
- package/lib/prompt-ui.mjs +44 -0
- package/lib/prompt-web.mjs +31 -5
- package/lib/prompt.css +2 -0
- package/lib/prompt.html +6 -3
- package/node_modules/pi-better-background-tasks/src/shared-harness-commands.ts +0 -1
- package/node_modules/pi-better-background-tasks/src/shared-harness-page.ts +1 -2
- package/node_modules/pi-better-goal/src/shared-harness-commands.ts +0 -1
- package/node_modules/pi-better-goal/src/shared-harness-page.ts +1 -2
- package/node_modules/pi-better-sandbox/shared-harness-commands.ts +0 -1
- package/node_modules/pi-better-sandbox/shared-harness-page.ts +1 -2
- package/node_modules/pi-better-subagents/shared-harness-commands.ts +0 -1
- package/node_modules/pi-better-subagents/shared-harness-page.ts +1 -2
- package/package.json +1 -1
- package/lib/prompt-tui.mjs +0 -113
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
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
|
+
|
|
3
10
|
## [0.66.1] - 2026-12-04
|
|
4
11
|
|
|
5
12
|
### 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 **
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
|
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. **
|
|
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
|
|
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
|
|
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 {
|
|
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,
|
|
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"
|
|
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"]],
|
package/lib/install-settings.mjs
CHANGED
|
@@ -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
|
-
|
|
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
|
}
|
package/lib/prompt-manager.mjs
CHANGED
|
@@ -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.
|
|
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);
|
package/lib/prompt-tools.mjs
CHANGED
|
@@ -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
|
|
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
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
if (
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
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: "
|
|
176
|
-
description: "
|
|
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
|
-
|
|
196
|
-
|
|
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));
|
package/lib/prompt-web.mjs
CHANGED
|
@@ -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 === "
|
|
110
|
-
|
|
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.
|
|
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.
|
|
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"><
|
|
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"
|
|
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"
|
|
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"
|
|
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"
|
|
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
package/lib/prompt-tui.mjs
DELETED
|
@@ -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
|
-
}
|