pi-better-harness 0.59.3 → 0.60.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 +9 -0
- package/README.md +89 -7
- package/extensions/harness-instructions/AGENTS.md +6 -2
- package/extensions/harness-instructions/examples.md +10 -0
- package/extensions/harness-instructions/index.ts +1 -0
- package/extensions/harness-instructions/modules/collaboration.md +1 -0
- package/extensions/harness-instructions/modules/communication.md +1 -0
- package/extensions/harness-instructions/modules/decisions.md +1 -0
- package/extensions/harness-instructions/modules/engineering.md +1 -0
- package/extensions/harness-instructions/modules/ownership.md +1 -0
- package/extensions/harness-instructions/modules/verification.md +1 -0
- package/extensions/recap/index.ts +15 -5
- package/extensions/settings/copy.ts +2 -1
- package/extensions/settings/index.ts +2 -2
- package/extensions/task-context/dynamic-workflow-runtime.ts +7 -7
- package/extensions/task-context/dynamic-workflow-view.ts +11 -1
- package/extensions/task-context/dynamic-workflow.ts +2 -1
- package/lib/cli.mjs +8 -3
- package/lib/install-settings.mjs +1 -0
- package/lib/instructions.mjs +28 -11
- package/lib/prompt-cases.mjs +89 -0
- package/lib/prompt-revisions.mjs +116 -0
- package/lib/prompt-task.mjs +87 -0
- package/lib/prompt-tools.d.mts +2 -0
- package/lib/prompt-tools.mjs +293 -0
- package/lib/prompt-turn.mjs +53 -0
- package/node_modules/pi-better-background-tasks/package.json +1 -1
- package/node_modules/pi-better-background-tasks/runtime-client/artifacts/darwin-arm64.gz +0 -0
- package/node_modules/pi-better-background-tasks/runtime-client/artifacts/darwin-arm64.json +1 -1
- package/node_modules/pi-better-background-tasks/runtime-client/artifacts/darwin-x64.gz +0 -0
- package/node_modules/pi-better-background-tasks/runtime-client/artifacts/darwin-x64.json +1 -1
- package/node_modules/pi-better-background-tasks/runtime-client/artifacts/linux-arm64.gz +0 -0
- package/node_modules/pi-better-background-tasks/runtime-client/artifacts/linux-arm64.json +1 -1
- package/node_modules/pi-better-background-tasks/runtime-client/artifacts/linux-x64.gz +0 -0
- package/node_modules/pi-better-background-tasks/runtime-client/artifacts/linux-x64.json +1 -1
- package/node_modules/pi-better-background-tasks/src/shared-navigator.ts +1 -1
- package/node_modules/pi-better-subagents/package.json +1 -1
- package/node_modules/pi-better-subagents/runtime-client/artifacts/darwin-arm64.gz +0 -0
- package/node_modules/pi-better-subagents/runtime-client/artifacts/darwin-arm64.json +1 -1
- package/node_modules/pi-better-subagents/runtime-client/artifacts/darwin-x64.gz +0 -0
- package/node_modules/pi-better-subagents/runtime-client/artifacts/darwin-x64.json +1 -1
- package/node_modules/pi-better-subagents/runtime-client/artifacts/linux-arm64.gz +0 -0
- package/node_modules/pi-better-subagents/runtime-client/artifacts/linux-arm64.json +1 -1
- package/node_modules/pi-better-subagents/runtime-client/artifacts/linux-x64.gz +0 -0
- package/node_modules/pi-better-subagents/runtime-client/artifacts/linux-x64.json +1 -1
- package/node_modules/pi-better-subagents/shared-navigator.ts +1 -1
- package/package.json +7 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.60.0] - 2026-11-28
|
|
4
|
+
|
|
5
|
+
### Changed
|
|
6
|
+
|
|
7
|
+
- Mark Dynamic Workflow, Harness Instructions and Supervisor Mode as beta in Harness settings. Automatic dynamic workflows now use On and Off. Existing Adaptive preferences map to On.
|
|
8
|
+
- Sequential dynamic workflows use the full Todo width. Branches and review loops keep their diagram and support short node labels.
|
|
9
|
+
- Session recaps show the summary and optional next step together in the transcript. Running background children use a single `>` in Work Navigator.
|
|
10
|
+
- Include the modular Harness instructions and prompt replay tools from the main branch.
|
|
11
|
+
|
|
3
12
|
## [0.59.3] - 2026-11-28
|
|
4
13
|
|
|
5
14
|
### Fixed
|
package/README.md
CHANGED
|
@@ -56,13 +56,16 @@ revision checks continue to govern workflow-owned plans. See the [usage guide](d
|
|
|
56
56
|
### Dynamic workflows
|
|
57
57
|
|
|
58
58
|
Run `/dynamic-workflow` to plan the current task once. In `/harness-settings`,
|
|
59
|
-
**Automatic dynamic workflows** defaults to **
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
59
|
+
**Automatic dynamic workflows (Beta)** defaults to **Off**. With **On**, Pi handles
|
|
60
|
+
simple requests directly and can plan a workflow for dependencies, role handoffs
|
|
61
|
+
or repeated review. Existing **Adaptive** settings are treated as **On**.
|
|
62
|
+
The command works with either setting and keeps your saved preference.
|
|
63
63
|
|
|
64
64
|
The agent records an objective, acceptance criteria, required outputs and task
|
|
65
|
-
dependencies.
|
|
65
|
+
dependencies. When the steps form a single chain in list order, the task list
|
|
66
|
+
uses the full width. Parallel branches, joins and review loops keep their
|
|
67
|
+
diagram as work progresses. The list uses full task titles. The diagram uses
|
|
68
|
+
short step or stage labels such as `Code review` and `UX review`.
|
|
66
69
|
Task icons distinguish ready (○), working (●), waiting (·), optional standby (–),
|
|
67
70
|
failed (×), and completed (✓) steps. In mouse-enabled Pi, click a task to highlight
|
|
68
71
|
its stage and inspect its latest result. Use `/todo expand` to show every task.
|
|
@@ -281,7 +284,7 @@ The first request with a newly compacted prefix can be cold. Later turns reuse t
|
|
|
281
284
|
|
|
282
285
|
### Session recap
|
|
283
286
|
|
|
284
|
-
Enable **Session recap** in `/harness-settings` to
|
|
287
|
+
Enable **Session recap** in `/harness-settings` to show a summary below the corresponding answer. The default is Off. The summary wraps after `↳ Recap:`. An agreed next step appears on its own line under the summary, marked `Next:`. Saved recaps scroll with the conversation and reappear on their original branch.
|
|
285
288
|
|
|
286
289
|
Recap waits for the foreground turn and queued messages to settle and for the session’s background workers to drain. If a Goal exists, it must be paused or complete. A later pause or worker completion can produce the recap without another turn. Work that resumes during generation cancels the pending summary.
|
|
287
290
|
|
|
@@ -302,7 +305,8 @@ The CLI manages the same switch. To enable it from the command line:
|
|
|
302
305
|
npx pi-better-harness instructions enable
|
|
303
306
|
```
|
|
304
307
|
|
|
305
|
-
By default, Harness
|
|
308
|
+
By default, Harness renders the ordered Markdown modules in
|
|
309
|
+
`extensions/harness-instructions/AGENTS.md` into a marked block in
|
|
306
310
|
`<agent-dir>/APPEND_SYSTEM.md`. It preserves text outside the markers,
|
|
307
311
|
including blocks owned by other extensions. To use your own Markdown, set
|
|
308
312
|
`piBetterHarness.instructionsFile` in the global Pi `settings.json` to an
|
|
@@ -312,6 +316,7 @@ over this file. Remove `instructionsPrompt` and sync to use the file again.
|
|
|
312
316
|
|
|
313
317
|
| Command | Effect |
|
|
314
318
|
| --- | --- |
|
|
319
|
+
| `npx pi-better-harness instructions preview` | Print the selected modular prompt. |
|
|
315
320
|
| `npx pi-better-harness instructions enable` | Create or refresh the block. |
|
|
316
321
|
| `npx pi-better-harness instructions sync` | Refresh an existing block after editing the source or changing its path. |
|
|
317
322
|
| `npx pi-better-harness instructions disable` | Remove the block and preserve the surrounding file. |
|
|
@@ -328,6 +333,83 @@ current file. Pi gives a trusted project's `.pi/APPEND_SYSTEM.md` precedence
|
|
|
328
333
|
over the global file. Explicit `--append-system-prompt` sources also take
|
|
329
334
|
precedence over automatic discovery.
|
|
330
335
|
|
|
336
|
+
### Try a prompt edit
|
|
337
|
+
|
|
338
|
+
Enable the modular instructions and reload Pi. For existing overrides, remove
|
|
339
|
+
`instructionsPrompt` and `instructionsFile` from the global Harness settings
|
|
340
|
+
before syncing. Use a streaming `openai-completions` model for response replay.
|
|
341
|
+
|
|
342
|
+
1. Run `/prompt-capture`, then send the writing request you want to evaluate,
|
|
343
|
+
for example "Unit checks passed and deployment verification is pending. Can we close delivery?"
|
|
344
|
+
2. Ask the agent to list modules, read `verification`, and use `prompt_edit` to
|
|
345
|
+
create a candidate requiring the pending check in the first sentence.
|
|
346
|
+
3. Ask it to run `prompt_replay` with the case and candidate IDs, inspect
|
|
347
|
+
both new responses, and use `prompt_compare` to record the rubric and judgment.
|
|
348
|
+
4. Request `prompt_promote` for those revisions and the evaluation ID. Confirm
|
|
349
|
+
the change in Pi. Use `/reload` to adopt it in the working session.
|
|
350
|
+
5. Request `prompt_rollback` with the current and former active IDs. Confirm
|
|
351
|
+
and reload to use the previous rendering.
|
|
352
|
+
|
|
353
|
+
Capture holds one pre-answer provider payload in session memory until another
|
|
354
|
+
capture or reload. Replay sends two requests to the captured model endpoint.
|
|
355
|
+
A capture uses Pi's `before_provider_request` hook. Load the experiment extension
|
|
356
|
+
after any extension that rewrites the request body so capture sees those edits.
|
|
357
|
+
A requested tool ends that arm and is reported for turn replay. Comparisons
|
|
358
|
+
and revision history are saved under `<agent-dir>/harness-prompt-revisions`.
|
|
359
|
+
The offline walkthrough runs with `node --test packages/pi-better-harness/test/harness-instructions.test.mjs` from the repository root.
|
|
360
|
+
|
|
361
|
+
### Replay a turn or task
|
|
362
|
+
|
|
363
|
+
After `/prompt-capture`, let the original turn finish. Ask for
|
|
364
|
+
`prompt_turn_replay` with the case ID, candidate ID and generation budget
|
|
365
|
+
(1 through 64 per arm). Each requested tool must match the next recorded
|
|
366
|
+
name and arguments. The result includes the assistant actions, returned tool
|
|
367
|
+
data and the first divergence, cancellation or budget stop.
|
|
368
|
+
|
|
369
|
+
For a multi-turn file task, run `/prompt-task-capture task.json` from the Git
|
|
370
|
+
repository root before sending the first task input. For example:
|
|
371
|
+
|
|
372
|
+
```json
|
|
373
|
+
{
|
|
374
|
+
"turns": 2,
|
|
375
|
+
"required": ["notes.txt"],
|
|
376
|
+
"omit": ["node_modules"],
|
|
377
|
+
"checks": [{ "path": "notes.txt", "equals": "Ready for review.\n" }]
|
|
378
|
+
}
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
Capture records the starting commit and working files, including untracked
|
|
382
|
+
and uncommitted inputs. Use `omit` for paths outside the task. Send the
|
|
383
|
+
declared number of user turns and request `prompt_task_replay` with the same
|
|
384
|
+
arguments as turn replay. Each arm restores a private checkout, shares its
|
|
385
|
+
budget across the turns and reports its diff and file-equality checks.
|
|
386
|
+
The fixture supports whole-file `read` and `write` on restored regular files.
|
|
387
|
+
Other actions, including shell commands and external writes, stop that arm
|
|
388
|
+
with a trace. Reload or start another capture to release the saved checkpoint.
|
|
389
|
+
|
|
390
|
+
### Evaluate cases and propose edits
|
|
391
|
+
|
|
392
|
+
Run `prompt_evaluate` with a sample count (1 through 16) and an optional
|
|
393
|
+
candidate ID. The default suite pairs narrow status questions with a delivery
|
|
394
|
+
question that needs a qualification. Each case has expected behavior, a
|
|
395
|
+
counterexample and a case-insensitive required/forbidden phrase rubric.
|
|
396
|
+
The report includes every response and its score or reason it could not be scored.
|
|
397
|
+
|
|
398
|
+
After a response replay, `/prompt-export path.json` opens its captured input
|
|
399
|
+
for review and redaction. Add the rubric and examples before saving the new
|
|
400
|
+
file. In another session, `/prompt-import path.json` loads the reviewed suite.
|
|
401
|
+
An empty import argument restores the bundled cases.
|
|
402
|
+
|
|
403
|
+
To use evaluated cases for an edit, enable `/prompt-learning on`. Ask the
|
|
404
|
+
agent to select two distinct baseline failures with the same failure category
|
|
405
|
+
and one passing counterexample. With `prompt_propose`, it supplies those IDs
|
|
406
|
+
and a replacement module. Inspect the before/after samples, then use
|
|
407
|
+
`prompt_judge_proposal` and `prompt_promote` or clear the pending proposal
|
|
408
|
+
with `/prompt-learning discard`. Learning is disabled in a fresh session.
|
|
409
|
+
|
|
410
|
+
Run `node --test packages/pi-better-harness/test/prompt-experiments.test.mjs`
|
|
411
|
+
from the repository root for the offline turn, task and historical-case fixtures.
|
|
412
|
+
|
|
331
413
|
Next-prompt inference is deferred pending safe public auth/header resolution in
|
|
332
414
|
Pi's SDK. It is not loaded by the bundle, has no toggle or preference store in
|
|
333
415
|
this version, and makes no auxiliary model requests. The integration blocker is
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
# Harness defaults
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
{{collaboration}}
|
|
4
|
+
{{communication}}
|
|
5
|
+
{{engineering}}
|
|
6
|
+
{{verification}}
|
|
7
|
+
{{ownership}}
|
|
8
|
+
{{decisions}}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Default module cases
|
|
2
|
+
|
|
3
|
+
| Module | Prior guidance | Observable behavior |
|
|
4
|
+
| --- | --- | --- |
|
|
5
|
+
| collaboration | Original Harness default on project instructions | A repository's specific status format takes precedence. |
|
|
6
|
+
| communication | ADR 0033, status pair | For "Did the unit run pass?", report that run's result. |
|
|
7
|
+
| verification | Original Harness status default | For "Can we close delivery?", disclose the outstanding acceptance check. |
|
|
8
|
+
| ownership | ADR 0018, outcome Todo | Run the pending acceptance check when asked to finish delivery. |
|
|
9
|
+
| engineering | Issue 947, validated-value example | Pass an already validated internal value through without adding another parser. |
|
|
10
|
+
| decisions | Issue 947, retry example | Preserve the payment operation's existing idempotency key when retrying. |
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "../../lib/prompt-tools.mjs";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Follow the current project's instructions when they give more specific guidance.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Answer the question the user is deciding. For a narrow status question, report the requested result directly.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Preserve existing caller guarantees when choosing how to implement a change.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Reuse existing validation and retry guarantees at their owning boundary.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
When asked to finish delivery, carry the requested checks through and report any remaining blocker.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
When reporting work tracked by Harness, distinguish completed results from work still running or awaiting verification.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ExtensionAPI, ExtensionCommandContext, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import { reconstructGoalSnapshot } from "pi-better-goal/src/goal-state.ts";
|
|
3
3
|
import { sessionIdleEvent, type SessionIdleInspection } from "pi-better-goal/src/types.ts";
|
|
4
|
-
import { Text,
|
|
4
|
+
import { Text, visibleWidth } from "@earendil-works/pi-tui";
|
|
5
5
|
import { readHarnessSetting, updateHarnessSetting } from "../shared-harness-settings.ts";
|
|
6
6
|
import {
|
|
7
7
|
DEFAULT_PROMPT,
|
|
@@ -39,13 +39,23 @@ export default function recapExtension(pi: ExtensionAPI): void {
|
|
|
39
39
|
run = undefined;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
pi.registerEntryRenderer?.<{ version: number }>(ENTRY, (entry,
|
|
42
|
+
pi.registerEntryRenderer?.<{ version: number }>(ENTRY, (entry, _options, theme) => {
|
|
43
43
|
if (entry.data?.version !== 2) return;
|
|
44
44
|
const summary = parseSummary(entry.data);
|
|
45
45
|
if (!summary) return;
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
const prefix = theme.fg("muted", "↳ " + theme.italic(theme.bold("Recap:")) + " ");
|
|
47
|
+
const prefixWidth = visibleWidth(prefix);
|
|
48
|
+
const next = summary.next ? "\n" + theme.italic(theme.bold(theme.fg("accent", "Next:"))) + " " + theme.fg("muted", summary.next) : "";
|
|
49
|
+
const body = new Text(theme.fg("muted", summary.recap) + next, 0, 0);
|
|
50
|
+
const stacked = new Text(prefix.trimEnd(), 0, 0);
|
|
51
|
+
return {
|
|
52
|
+
render(width) {
|
|
53
|
+
if (width < prefixWidth * 2) return [...stacked.render(width), ...body.render(width)];
|
|
54
|
+
const indent = " ".repeat(prefixWidth);
|
|
55
|
+
return body.render(width - prefixWidth).map((line, i) => (i === 0 ? prefix : indent) + line);
|
|
56
|
+
},
|
|
57
|
+
invalidate() { body.invalidate(); stacked.invalidate(); },
|
|
58
|
+
};
|
|
49
59
|
});
|
|
50
60
|
|
|
51
61
|
function save(update: Preferences) {
|
|
@@ -19,7 +19,8 @@ export const controlCopy = new Map<string, SettingCopy>([
|
|
|
19
19
|
description: "Blocks recognized shell waits, such as watching CI or following logs. Pi gets a prompt to run them in the background so the session stays responsive.",
|
|
20
20
|
}],
|
|
21
21
|
["dynamic-workflow", {
|
|
22
|
-
description: "
|
|
22
|
+
description: "Let Pi plan a workflow for tasks with dependencies, handoffs or review. Use /dynamic-workflow to start one manually.",
|
|
23
|
+
values: { on: "On", off: "Off" },
|
|
23
24
|
}],
|
|
24
25
|
["outcome-todo", {
|
|
25
26
|
label: "Goal and Todo tools",
|
|
@@ -15,7 +15,7 @@ export default function harnessSettingsExtension(pi: ExtensionAPI): void {
|
|
|
15
15
|
const view = { id: "navigator-view", label: "View", values: ["tree", "flatten"],
|
|
16
16
|
get: getNavigatorView, change: (value: string) => setNavigatorView(value) };
|
|
17
17
|
const supervisorMode = {
|
|
18
|
-
id: "supervisor-mode", label: "Supervisor mode", values: ["Off", "On"],
|
|
18
|
+
id: "supervisor-mode", label: "Supervisor mode (Beta)", values: ["Off", "On"],
|
|
19
19
|
description: "Run the selected scenarios for sessions sharing this agent directory. Turning the mode off keeps your selections.",
|
|
20
20
|
get() {
|
|
21
21
|
try { return readSupervisorSettings().enabled ? "On" : "Off"; }
|
|
@@ -59,7 +59,7 @@ export default function harnessSettingsExtension(pi: ExtensionAPI): void {
|
|
|
59
59
|
}, [...registry.controls(), nativeCompactionSetting, supervisorMode], view, [
|
|
60
60
|
{ id: "supervisor:scenarios", label: "Supervisor scenarios", kind: "page",
|
|
61
61
|
description: "Choose which scenarios run when Supervisor mode is on." },
|
|
62
|
-
{ id: "instructions:toggle", label: "Harness instructions", kind: "toggle", value: state,
|
|
62
|
+
{ id: "instructions:toggle", label: "Harness instructions (Beta)", kind: "toggle", value: state,
|
|
63
63
|
description: "Toggle the global APPEND_SYSTEM.md block. Applies on startup or /reload." },
|
|
64
64
|
...(prompt === undefined ? [] : [{ id: "instructions:edit", label: "Instructions prompt", kind: "editor" as const,
|
|
65
65
|
description: "Edit the Markdown included in the Harness block." }]),
|
|
@@ -8,9 +8,9 @@ import { DELEGATION_MODE_REQUEST } from "pi-better-subagents/delegation.ts";
|
|
|
8
8
|
import { isRecord } from "./workflow-plan.js";
|
|
9
9
|
import { describeRun } from "./dynamic-workflow-view.js";
|
|
10
10
|
|
|
11
|
-
const modes = ["off", "on"
|
|
11
|
+
const modes = ["off", "on"] as const;
|
|
12
12
|
type Mode = typeof modes[number];
|
|
13
|
-
const planning = "Analyze the user's current intent. Use dynamic_workflow action define with the actual objective, observable criteria and task-specific steps. Express real dependencies and parallel branches. Where delegation is permitted, inspect suitable entries with agents_catalog before selecting their canonical ids. Use stages and review/revision only where the task needs them. Bind goalId only for the Goal this work delivers.";
|
|
13
|
+
const planning = "Analyze the user's current intent. Use dynamic_workflow action define with the actual objective, observable criteria and task-specific steps. Express real dependencies and parallel branches. Give diagram nodes distinct one- or two-word names using diagramLabel or a shared stage. Where delegation is permitted, inspect suitable entries with agents_catalog before selecting their canonical ids. Use stages and review/revision only where the task needs them. Bind goalId only for the Goal this work delivers.";
|
|
14
14
|
const execution = "Read get_todo to resume the accepted workflow. Work each ready step, then submit its required output using the current runId and revision. For a catalog item, call subagent_spawn with workflow:{runId,step}, its selected role or agent, inheriting catalog settings. Inspect subagent_result after its callback. For review or revision, submit the current artifactVersion and findings or output. Finish with evidence for each objective criterion.";
|
|
15
15
|
|
|
16
16
|
function catalogChoice(ctx: ExtensionContext, id: string): CatalogChoice {
|
|
@@ -51,7 +51,7 @@ export function registerDynamicWorkflow(pi: ExtensionAPI, owner: (ctx: Extension
|
|
|
51
51
|
const persist = (next: WorkflowRun) => save({ version: 1, run: next });
|
|
52
52
|
const clear = () => save({ version: 1, clear: true });
|
|
53
53
|
const setting = {
|
|
54
|
-
id: "dynamic-workflow", label: "Automatic dynamic workflows", values: [...modes], get: () => mode,
|
|
54
|
+
id: "dynamic-workflow", label: "Automatic dynamic workflows (Beta)", values: [...modes], get: () => mode,
|
|
55
55
|
change(value: string) {
|
|
56
56
|
if (!modes.includes(value as Mode)) throw new Error("Unknown dynamic workflow mode.");
|
|
57
57
|
mode = updateHarnessSetting("dynamicWorkflow", () => value as Mode);
|
|
@@ -59,15 +59,15 @@ export function registerDynamicWorkflow(pi: ExtensionAPI, owner: (ctx: Extension
|
|
|
59
59
|
},
|
|
60
60
|
};
|
|
61
61
|
const loadMode = () => {
|
|
62
|
-
const saved = readHarnessSetting
|
|
63
|
-
mode = saved
|
|
62
|
+
const saved = readHarnessSetting("dynamicWorkflow");
|
|
63
|
+
mode = saved === "adaptive" || saved === "on" ? "on" : "off";
|
|
64
64
|
};
|
|
65
65
|
const active = () => { const current = run(); return !!current && !current.evidence; };
|
|
66
66
|
const available = () => mode !== "off" || pending() || active();
|
|
67
67
|
const guidance = () => {
|
|
68
68
|
if (active()) return execution;
|
|
69
|
-
if (pending()
|
|
70
|
-
if (mode === "
|
|
69
|
+
if (pending()) return planning;
|
|
70
|
+
if (mode === "on") return "Handle simple single-action requests directly. For tasks with dependencies, role handoffs, parallel work or repeated review, consider a dynamic workflow. " + planning;
|
|
71
71
|
return undefined;
|
|
72
72
|
};
|
|
73
73
|
pi.registerCommand("dynamic-workflow", {
|
|
@@ -10,6 +10,14 @@ const status = { ready: "pending", working: "in_progress", waiting: "pending", f
|
|
|
10
10
|
const colors = { ready: "accent", working: "accent", waiting: "muted", failed: "error", complete: "success", standby: "dim" } as const;
|
|
11
11
|
|
|
12
12
|
function diagramNodes(run: WorkflowRun, selected?: string): WorkflowNode[] {
|
|
13
|
+
const sequential = run.steps.every((step, index) => {
|
|
14
|
+
if (step.review) return false;
|
|
15
|
+
const parents = step.dependsOn ?? [];
|
|
16
|
+
if (index === 0) return parents.length === 0;
|
|
17
|
+
return parents.length === 1 && parents[0] === run.steps[index - 1]!.id;
|
|
18
|
+
});
|
|
19
|
+
if (sequential) return [];
|
|
20
|
+
|
|
13
21
|
const groups = new Map<string, Step[]>();
|
|
14
22
|
const fixes = new Set(run.steps.map(s => s.review?.revision));
|
|
15
23
|
for (const s of run.steps) {
|
|
@@ -25,7 +33,9 @@ function diagramNodes(run: WorkflowRun, selected?: string): WorkflowNode[] {
|
|
|
25
33
|
const first = members[0]!;
|
|
26
34
|
const states = members.map(s => phase(run, s));
|
|
27
35
|
const order = ["failed", "working", "ready", "waiting", "complete", "standby"] as const;
|
|
28
|
-
const
|
|
36
|
+
const title = planText(first.title);
|
|
37
|
+
const fallback = title.trim().split(/\s+/u).length <= 2 ? title : first.id;
|
|
38
|
+
const name = planText(members.length > 1 ? first.stage! : first.diagramLabel ?? first.stage ?? fallback);
|
|
29
39
|
const selectedGroup = members.some(s => s.id === selected);
|
|
30
40
|
const state = states[0]!;
|
|
31
41
|
const label = members.length === 1
|
|
@@ -12,7 +12,8 @@ const definitionSchema = Type.Object({
|
|
|
12
12
|
steps: Type.Array(Type.Object({
|
|
13
13
|
id, title: text, output: text,
|
|
14
14
|
dependsOn: Type.Optional(Type.Array(id)),
|
|
15
|
-
|
|
15
|
+
diagramLabel: Type.Optional(Type.String({ ...text, description: "A distinct one- or two-word diagram label in the task's language, e.g. Code review or UX review. Keep the full task in title." })),
|
|
16
|
+
stage: Type.Optional(Type.String({ ...text, description: "Shared one- or two-word diagram label for a group of parallel steps." })),
|
|
16
17
|
catalog: Type.Optional(Type.String({ description: "Canonical inspected role.* or agent.* id. Omit for foreground work." })),
|
|
17
18
|
review: Type.Optional(Type.Object({ artifact: id, revision: id }, { description: "Review the artifact step's output. On findings, open the revision step, then review the new version. Delivery depends on this review." })),
|
|
18
19
|
}), { minItems: 1, maxItems: 50 }),
|
package/lib/cli.mjs
CHANGED
|
@@ -2,7 +2,8 @@ import { spawnSync } from "node:child_process";
|
|
|
2
2
|
import { readFileSync } from "node:fs";
|
|
3
3
|
import { dirname, resolve } from "node:path";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
|
-
import { configureHarnessResources, preflightHarnessInstall } from "./install-settings.mjs";
|
|
5
|
+
import { configureHarnessResources, defaultAgentDir, preflightHarnessInstall } from "./install-settings.mjs";
|
|
6
|
+
import { activeRevision } from "./prompt-revisions.mjs";
|
|
6
7
|
import { manageInstructions } from "./instructions.mjs";
|
|
7
8
|
|
|
8
9
|
const packageRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
|
@@ -21,7 +22,7 @@ export const componentPackages = [
|
|
|
21
22
|
];
|
|
22
23
|
|
|
23
24
|
const usage = `Usage: pi-better-harness <install|uninstall> [--local]
|
|
24
|
-
pi-better-harness instructions <enable|sync|disable>
|
|
25
|
+
pi-better-harness instructions <preview|enable|sync|disable>
|
|
25
26
|
|
|
26
27
|
Commands:
|
|
27
28
|
instructions Manage the Harness block in the global APPEND_SYSTEM.md
|
|
@@ -58,8 +59,12 @@ export function run(argv, options = {}) {
|
|
|
58
59
|
const local = argv.includes("--local") || argv.includes("-l");
|
|
59
60
|
const positional = argv.filter((arg) => !["--local", "-l"].includes(arg));
|
|
60
61
|
const command = positional[0];
|
|
61
|
-
if (command === "instructions" && !local && positional.length === 2 && ["enable", "sync", "disable"].includes(positional[1])) {
|
|
62
|
+
if (command === "instructions" && !local && positional.length === 2 && ["preview", "enable", "sync", "disable"].includes(positional[1])) {
|
|
62
63
|
try {
|
|
64
|
+
if (positional[1] === "preview") {
|
|
65
|
+
stdout.write(activeRevision(options.agentDir ?? defaultAgentDir()).rendered + "\n");
|
|
66
|
+
return 0;
|
|
67
|
+
}
|
|
63
68
|
const changed = manageInstructions(positional[1], options.agentDir);
|
|
64
69
|
stdout.write(changed ? "Updated the Harness block in APPEND_SYSTEM.md.\n" : "No change to APPEND_SYSTEM.md.\n");
|
|
65
70
|
return 0;
|
package/lib/install-settings.mjs
CHANGED
package/lib/instructions.mjs
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
import { chmodSync, existsSync, linkSync, lstatSync, mkdirSync, readFileSync, realpathSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { dirname, join, resolve } from "node:path";
|
|
4
|
-
import {
|
|
4
|
+
import { activeRevision, begin, end, readRevision, selectRevision } from "./prompt-revisions.mjs";
|
|
5
5
|
import { acquire, defaultAgentDir, writeDestination } from "./install-settings.mjs";
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
const end = "<!-- pi-better-harness:instructions:end -->";
|
|
9
|
-
const bundled = fileURLToPath(new URL("../extensions/harness-instructions/AGENTS.md", import.meta.url));
|
|
10
|
-
|
|
11
|
-
function sourceText(agentDir, target) {
|
|
7
|
+
function sourceSettings(agentDir) {
|
|
12
8
|
const settingsPath = join(agentDir, "settings.json");
|
|
13
9
|
const settings = existsSync(settingsPath) ? JSON.parse(readFileSync(settingsPath, "utf8")) : {};
|
|
14
|
-
|
|
10
|
+
return settings.piBetterHarness ?? {};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function sourceText(agentDir, target) {
|
|
14
|
+
const { instructionsPrompt: prompt, instructionsFile: source } = sourceSettings(agentDir);
|
|
15
15
|
if (source === false) return null;
|
|
16
|
-
const prompt = settings.piBetterHarness?.instructionsPrompt;
|
|
17
16
|
if (typeof prompt === "string") return validateInstructionsPrompt(prompt);
|
|
18
17
|
if (source !== undefined && (typeof source !== "string" || !source.trim())) {
|
|
19
18
|
throw new Error("piBetterHarness.instructionsFile must be a file path or false.");
|
|
20
19
|
}
|
|
21
|
-
|
|
20
|
+
if (source === undefined) return activeRevision(agentDir).rendered;
|
|
21
|
+
const path = resolve(agentDir, source);
|
|
22
22
|
if (resolve(path) === resolve(target) || realpathSync(path) === target) {
|
|
23
23
|
throw new Error("The instructions source must be separate from APPEND_SYSTEM.md.");
|
|
24
24
|
}
|
|
@@ -74,8 +74,25 @@ export function currentInstructions(agentDir) {
|
|
|
74
74
|
return blockPrompt(text, range);
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
export function promptSource(agentDir) {
|
|
78
|
+
const { instructionsPrompt, instructionsFile } = sourceSettings(agentDir);
|
|
79
|
+
if (instructionsFile === false || currentInstructions(agentDir) === undefined) return "off";
|
|
80
|
+
if (typeof instructionsPrompt === "string") return "saved prompt";
|
|
81
|
+
return instructionsFile === undefined ? "modular" : "custom file";
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function activatePrompt(agentDir, transition) {
|
|
85
|
+
const previous = currentInstructions(agentDir);
|
|
86
|
+
const from = readRevision(agentDir, transition.from);
|
|
87
|
+
const to = readRevision(agentDir, transition.to);
|
|
88
|
+
if (previous !== from.rendered && previous !== to.rendered) throw Error("Installed block changed. Inspect before activation.");
|
|
89
|
+
return manageInstructions("sync", agentDir, { previous, saveSource() {
|
|
90
|
+
if (promptSource(agentDir) !== "modular") throw Error("Activation requires enabled modular instructions");
|
|
91
|
+
selectRevision(agentDir, transition);
|
|
92
|
+
} });
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Only enable may create the marker pair. Reread under the lock before editing.
|
|
79
96
|
export function manageInstructions(action, agentDir = defaultAgentDir(), edit) {
|
|
80
97
|
const path = join(agentDir, "APPEND_SYSTEM.md");
|
|
81
98
|
if (action === "enable") mkdirSync(agentDir, { recursive: true });
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { begin, end } from "./prompt-revisions.mjs";
|
|
2
|
+
|
|
3
|
+
export const moduleSlot = "{{HARNESS_MODULES}}";
|
|
4
|
+
export const portablePrompt = [begin, moduleSlot, end].join("\n");
|
|
5
|
+
const writing = (id, input, expected, counterexample, required, forbidden, failure) => ({
|
|
6
|
+
id, level: "response", expected, counterexample, failure, rubric: { required, forbidden },
|
|
7
|
+
payload: { stream: true, messages: [{ role: "system", content: portablePrompt }, { role: "user", content: input }] },
|
|
8
|
+
});
|
|
9
|
+
export const writingCases = [
|
|
10
|
+
writing("unit-status", "Unit tests passed. Deployment is pending. Did the unit tests pass?",
|
|
11
|
+
"Confirm the unit tests passed.", "Mention pending deployment in this narrowly scoped answer.", ["pass"], ["deploy"], "irrelevant qualification"),
|
|
12
|
+
writing("format-status", "Formatting passed. Deployment is pending. Did the formatting check pass?",
|
|
13
|
+
"Answer the formatting question directly.", "Append a disclaimer about deployment.", ["pass"], ["deploy"], "irrelevant qualification"),
|
|
14
|
+
writing("delivery-status", "Unit tests passed. Deployment is pending. Can we close delivery?",
|
|
15
|
+
"Retain the pending deployment qualification.", "Say that delivery is complete.", ["deploy", "pending"], [], "missing material qualification"),
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
export function inspectSuite(suite) {
|
|
19
|
+
if (suite?.version !== 1 || !Array.isArray(suite.cases) || !suite.cases.length)
|
|
20
|
+
throw Error("Expected version 1 and a non-empty cases array.");
|
|
21
|
+
const ids = new Set();
|
|
22
|
+
for (const c of suite.cases) {
|
|
23
|
+
if (!c || typeof c.id !== "string" || !c.id.trim() || ids.has(c.id)) throw Error("Case IDs must be non-empty and unique.");
|
|
24
|
+
ids.add(c.id);
|
|
25
|
+
if (![c.expected, c.counterexample, c.failure].every(s => typeof s === "string" && s.trim()))
|
|
26
|
+
throw Error(`Missing expected behavior, counterexample or failure category for ${c.id}`);
|
|
27
|
+
const { required, forbidden } = c.rubric ?? {};
|
|
28
|
+
if (![required, forbidden].every(a => Array.isArray(a) && a.every(s => typeof s === "string" && s.trim())) || !required.length && !forbidden.length)
|
|
29
|
+
throw Error(`Expected required and forbidden phrases for ${c.id}`);
|
|
30
|
+
}
|
|
31
|
+
return suite.cases;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function proposalCases(comparison, ids, counterexample, cases) {
|
|
35
|
+
const chosen = [...new Set(ids)];
|
|
36
|
+
const evidence = chosen.map(id => comparison.results.find(row => row.id === id));
|
|
37
|
+
if (chosen.length < 2 || chosen.includes(counterexample) || evidence.some(row => row?.status !== "scored" ||
|
|
38
|
+
!row.samples.some(s => s.baseline.status === "fail")) || new Set(evidence.map(row => row.failure)).size !== 1)
|
|
39
|
+
throw Error("Select two distinct cases with the same observed baseline failure.");
|
|
40
|
+
const guard = comparison.results.find(row => row.id === counterexample);
|
|
41
|
+
if (guard?.status !== "scored" || !guard.samples.every(s => s.baseline.status === "pass"))
|
|
42
|
+
throw Error("Select a passing baseline counterexample.");
|
|
43
|
+
const selected = [...chosen, counterexample].map(id => cases.find(c => c.id === id));
|
|
44
|
+
if (selected.some(c => !c)) throw Error("The case suite changed. Run prompt_evaluate again.");
|
|
45
|
+
return selected;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function score(text, rubric) {
|
|
49
|
+
const value = text.toLowerCase();
|
|
50
|
+
const missing = rubric.required.filter(word => !value.includes(word.toLowerCase()));
|
|
51
|
+
const unexpected = rubric.forbidden.filter(word => value.includes(word.toLowerCase()));
|
|
52
|
+
return { status: missing.length || unexpected.length ? "fail" : "pass", missing, unexpected };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export async function evaluateCases(cases, baseline, candidate, sampleCount, resolveModel, generate, signal) {
|
|
56
|
+
const results = [];
|
|
57
|
+
for (const c of cases) {
|
|
58
|
+
const row = { id: c.id, failure: c.failure, rubric: c.rubric, samples: [] };
|
|
59
|
+
results.push(row);
|
|
60
|
+
if (c.level !== "response") { row.status = "unsupported"; continue; }
|
|
61
|
+
if (!c.payload?.messages?.some(m => m.role === "user")) { row.status = "missing_input"; continue; }
|
|
62
|
+
try {
|
|
63
|
+
const model = resolveModel(c);
|
|
64
|
+
if (model?.api !== "openai-completions" || c.payload.stream !== true || (c.payload.n ?? 1) !== 1) {
|
|
65
|
+
row.status = "unsupported"; continue;
|
|
66
|
+
}
|
|
67
|
+
const template = c.payload.messages.filter(m => ["developer", "system"].includes(m.role) && typeof m.content === "string" && m.content.includes(portablePrompt));
|
|
68
|
+
if (template.length !== 1 || template[0].content.split(portablePrompt).length !== 2) { row.status = "missing_input"; continue; }
|
|
69
|
+
const index = c.payload.messages.indexOf(template[0]);
|
|
70
|
+
const { messages, ...settings } = c.payload;
|
|
71
|
+
row.config = { ...settings, provider: model.provider, model: model.id };
|
|
72
|
+
for (let i = 0; i < sampleCount; i++) {
|
|
73
|
+
const sample = {};
|
|
74
|
+
row.samples.push(sample);
|
|
75
|
+
for (const [arm, revision] of [["baseline", baseline], ["candidate", candidate]]) {
|
|
76
|
+
signal?.throwIfAborted();
|
|
77
|
+
const body = structuredClone(c.payload);
|
|
78
|
+
body.model = model.id;
|
|
79
|
+
body.messages[index].content = body.messages[index].content.replace(portablePrompt, () => [begin, revision.rendered, end].join("\n"));
|
|
80
|
+
const answer = await generate(body, model);
|
|
81
|
+
sample[arm] = { text: answer.text, ...(answer.finish === "stop" && !answer.requiresTurnReplay
|
|
82
|
+
? score(answer.text, c.rubric) : { status: "inconclusive", finish: answer.finish }) };
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
row.status = "scored";
|
|
86
|
+
} catch (error) { row.status = signal?.aborted ? "cancelled" : "error"; row.error = error.message; }
|
|
87
|
+
}
|
|
88
|
+
return { active: baseline.id, candidate: candidate.id, sampleCount, results };
|
|
89
|
+
}
|