pi-better-harness 0.50.0 → 0.51.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 +19 -0
- package/README.md +15 -13
- package/extensions/settings/copy.ts +69 -0
- package/extensions/settings/index.ts +1 -1
- package/extensions/settings/page.ts +81 -34
- package/extensions/settings/registry.ts +2 -0
- package/extensions/task-context/compact-task-header.ts +11 -6
- package/extensions/task-context/index.ts +55 -20
- package/extensions/task-context/outcome-state.ts +18 -2
- package/extensions/task-context/plan-presentation.ts +8 -4
- package/extensions/task-context/work-ledger-actions.ts +1 -1
- package/extensions/task-context/workflow-plan.ts +93 -10
- package/extensions/tool-call-guard/waits.ts +1 -1
- package/node_modules/pi-better-background-tasks/README.md +21 -10
- 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/runtime-client/src/runtime/root.mjs +5 -2
- package/node_modules/pi-better-background-tasks/src/index.ts +19 -0
- package/node_modules/pi-better-background-tasks/src/managed-frontend.ts +76 -5
- package/node_modules/pi-better-background-tasks/src/navigator-provider.ts +4 -0
- package/node_modules/pi-better-background-tasks/src/observed-waits.ts +168 -24
- package/node_modules/pi-better-background-tasks/src/process.ts +45 -11
- package/node_modules/pi-better-background-tasks/src/review-settings.ts +18 -0
- package/node_modules/pi-better-background-tasks/src/runtime.ts +8 -73
- package/node_modules/pi-better-background-tasks/src/shared-navigator.ts +47 -26
- package/node_modules/pi-better-background-tasks/src/shared-operation-coordinator/src/outbox.ts +9 -0
- package/node_modules/pi-better-background-tasks/src/shared-operation-coordinator/src/store.ts +6 -0
- package/node_modules/pi-better-background-tasks/src/stall.ts +7 -4
- package/node_modules/pi-better-background-tasks/src/supervised-progress.ts +43 -0
- package/node_modules/pi-better-background-tasks/src/supervisor/README.md +1 -4
- package/node_modules/pi-better-background-tasks/src/supervisor/emit-runner.mjs +1 -0
- package/node_modules/pi-better-background-tasks/src/supervisor/generated/process.mjs +49 -11
- package/node_modules/pi-better-background-tasks/src/supervisor/generated/runner.mjs +47 -4
- package/node_modules/pi-better-background-tasks/src/supervisor/generated/store.mjs +3 -3
- package/node_modules/pi-better-background-tasks/src/supervisor/generated/watch-fingerprint.mjs +69 -0
- package/node_modules/pi-better-background-tasks/src/supervisor/runner.ts +38 -3
- package/node_modules/pi-better-background-tasks/src/supervisor/store.ts +3 -3
- package/node_modules/pi-better-background-tasks/src/supervisor/supervisor.ts +6 -3
- package/node_modules/pi-better-background-tasks/src/tools.ts +26 -16
- package/node_modules/pi-better-background-tasks/src/types.ts +4 -2
- package/node_modules/pi-better-background-tasks/src/watch-fingerprint.ts +70 -0
- package/node_modules/pi-better-goal/README.md +4 -0
- package/node_modules/pi-better-goal/package.json +1 -1
- package/node_modules/pi-better-goal/src/index.ts +34 -8
- package/node_modules/pi-better-goal/src/task-context.ts +12 -6
- package/node_modules/pi-better-sandbox/README.md +3 -3
- package/node_modules/pi-better-sandbox/package.json +1 -1
- package/node_modules/pi-better-subagents/README.md +12 -10
- package/node_modules/pi-better-subagents/assignment-outcomes.ts +2 -5
- package/node_modules/pi-better-subagents/assignment-report.ts +20 -0
- package/node_modules/pi-better-subagents/batch.mjs +14 -5
- package/node_modules/pi-better-subagents/bin/recover-workspace.mjs +19 -0
- package/node_modules/pi-better-subagents/cleanup.ts +10 -2
- package/node_modules/pi-better-subagents/config.ts +7 -1
- package/node_modules/pi-better-subagents/continuation.ts +4 -2
- package/node_modules/pi-better-subagents/docs/usage.md +39 -53
- package/node_modules/pi-better-subagents/failures.ts +10 -2
- package/node_modules/pi-better-subagents/finalization.ts +7 -2
- package/node_modules/pi-better-subagents/index.ts +163 -60
- package/node_modules/pi-better-subagents/isolated-workspace.ts +557 -0
- package/node_modules/pi-better-subagents/list.mjs +2 -2
- package/node_modules/pi-better-subagents/managed-launch-client.ts +23 -6
- package/node_modules/pi-better-subagents/output-payload.ts +26 -12
- package/node_modules/pi-better-subagents/package.json +4 -2
- package/node_modules/pi-better-subagents/parse.ts +10 -5
- package/node_modules/pi-better-subagents/registry.ts +23 -5
- package/node_modules/pi-better-subagents/retained-result.ts +65 -0
- 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/runtime-client/src/runtime/root.mjs +5 -2
- package/node_modules/pi-better-subagents/session-selection.ts +2 -1
- package/node_modules/pi-better-subagents/session-store.ts +9 -0
- package/node_modules/pi-better-subagents/settings-page.ts +147 -108
- package/node_modules/pi-better-subagents/shared-catalog.ts +23 -7
- package/node_modules/pi-better-subagents/shared-navigator.ts +47 -26
- package/node_modules/pi-better-subagents/shared-operation-coordinator/src/outbox.ts +9 -0
- package/node_modules/pi-better-subagents/shared-operation-coordinator/src/store.ts +6 -0
- package/node_modules/pi-better-subagents/task-guard.ts +13 -1
- package/node_modules/pi-better-subagents/task-policy.ts +5 -1
- package/node_modules/pi-better-subagents/tools.ts +4 -7
- package/node_modules/pi-better-subagents/work-observation.ts +20 -1
- package/node_modules/pi-better-subagents/workspace-files.ts +114 -0
- package/node_modules/pi-better-subagents/workspace-scope.ts +6 -0
- package/node_modules/pi-better-subagents/worktree-feedback.ts +77 -0
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.51.0] - 2026-11-22
|
|
4
|
+
|
|
5
|
+
### Changed
|
|
6
|
+
|
|
7
|
+
- Find related controls together in `/harness-settings` and `/subagents`. Subagent settings show help for the focused row, wrap long values in narrow terminals, and display the configured shortcuts for editing. (#876)
|
|
8
|
+
- Choose Clone or Worktree for isolated subagent work and select **No limit** for the run timeout. Both workspace modes preserve files and partial results for recovery. (#875)
|
|
9
|
+
- A Goal bound to an Outcome now checks its acceptance evidence and unfinished work before completing. Rush Todo stages keep their blockers until delivery evidence arrives. (#854, #873)
|
|
10
|
+
- Bundle Subagents 0.37.0, Background Tasks 0.20.0, Goal 0.16.0 and Sandbox 0.15.1. Background Tasks and Subagents carry the Server 0.7.0 runtime.
|
|
11
|
+
|
|
12
|
+
## [0.50.1] - 2026-11-22
|
|
13
|
+
|
|
14
|
+
### Changed
|
|
15
|
+
|
|
16
|
+
- Clarify the labels and descriptions in `/harness-settings` so the display, tools, and project work ledger are easier to distinguish. (#868)
|
|
17
|
+
|
|
18
|
+
### Fixed
|
|
19
|
+
|
|
20
|
+
- Summarize Rush Todo stages from every issue in the saved plan, including folded rows. Show an in-progress dot alongside a blocker when other issues are still moving through that stage. (#870)
|
|
21
|
+
|
|
3
22
|
## [0.50.0] - 2026-11-20
|
|
4
23
|
|
|
5
24
|
### Changed
|
package/README.md
CHANGED
|
@@ -20,9 +20,9 @@ Use `pi-better-harness` when you want the full working set for Pi. It manages:
|
|
|
20
20
|
|
|
21
21
|
## Outcome & Todo
|
|
22
22
|
|
|
23
|
-
In `/harness-settings`, **Outcome
|
|
24
|
-
defaults to **On**, and **Outcome
|
|
25
|
-
**Off**. **
|
|
23
|
+
In `/harness-settings`, **Outcome and Todo panel** (`outcome-todo-display`)
|
|
24
|
+
defaults to **On**, and **Outcome and Todo tools** (`outcome-todo`) defaults to
|
|
25
|
+
**Off**. **Project work ledger** (`outcome-todo-ledger`) is a third independent
|
|
26
26
|
control and defaults to **Off**. Saved outcomes and checklists display even when
|
|
27
27
|
hooks are off; missing state creates no placeholder, state, or settings. Turning
|
|
28
28
|
display off does not disable hooks. Saved v1 `enabled` remains the hooks
|
|
@@ -66,7 +66,7 @@ Existing Plan session histories restore as Todo. Workflow task-plan files and
|
|
|
66
66
|
revision checks stay unchanged; skills continue using their own records when the
|
|
67
67
|
optional interface is off. See the [usage guide](docs/usage.md#outcome--todo).
|
|
68
68
|
|
|
69
|
-
The separate **
|
|
69
|
+
The separate **Project work ledger** setting enables a durable project-scoped
|
|
70
70
|
record of the overall outcome, boundaries, and high-level items. It stays off by
|
|
71
71
|
default; turning it off removes ledger views and hints without deleting records.
|
|
72
72
|
The same `update_todo` / `get_todo` interface carries optional ledger payloads and
|
|
@@ -150,14 +150,14 @@ need interactive confirmation. Full policy: [pi-better-sandbox](https://github.c
|
|
|
150
150
|
|
|
151
151
|
## Minimal Tool Output
|
|
152
152
|
|
|
153
|
-
The bundled harness provides **Tool output
|
|
153
|
+
The bundled harness provides **Tool output** with **Normal** and **Compact** in
|
|
154
154
|
`/harness-settings`. `/tool-output minimal`, `/tool-output normal`, and
|
|
155
155
|
`/tool-output` (toggle) remain compatibility shortcuts to the same preference.
|
|
156
156
|
Minimal mode folds each tool call into a single-line header, including running
|
|
157
157
|
calls. The tool-specific icon and tool name share a state color: accent while
|
|
158
158
|
running, muted when completed, and error-colored when failed. In fullscreen Pi, a soft highlight travels through the entire visible running tool name and its
|
|
159
159
|
inline command/path details; details stay dim between highlight passes. Scrollback terminals keep static state colors.
|
|
160
|
-
Choose **Tool animation
|
|
160
|
+
Choose **Tool progress animation** set to **Off** in `/harness-settings` for static running headers.
|
|
161
161
|
Running and failed calls retain text labels so state never depends on color or
|
|
162
162
|
motion alone. Tool rows are indented two columns past
|
|
163
163
|
the assistant text padding. Long
|
|
@@ -210,13 +210,15 @@ pi -e ./packages/pi-better-harness/extensions/minimal-output/index.ts
|
|
|
210
210
|
## Harness Settings
|
|
211
211
|
|
|
212
212
|
The bundled harness provides `/harness-settings`, using Pi's native settings
|
|
213
|
-
list.
|
|
214
|
-
|
|
213
|
+
list. Work planning comes first, followed by delegation and sandbox access,
|
|
214
|
+
background waits and completion delivery, then display settings. It opens
|
|
215
|
+
the settings screens of loaded Sandbox, Subagents, and Goal
|
|
216
|
+
packages without duplicating their configuration, plus the **Agent catalog** shortcut
|
|
215
217
|
to the `/agents` catalog. `/sandbox`, `/subagents settings`, `/agents`, and
|
|
216
218
|
`/goal settings` remain available in standalone installations.
|
|
217
219
|
Packages without a settings screen are not listed. Pi's `/settings` is unchanged.
|
|
218
220
|
|
|
219
|
-
**
|
|
221
|
+
**Navigator layout** selects **Flat list** (the default) or **Tree**. Flatten keeps the Subagents
|
|
220
222
|
and Background Tasks groups and includes tasks launched by subagents. Tree puts
|
|
221
223
|
Main and subagents at the same level, with each agent's background tasks indented
|
|
222
224
|
beneath it. Switching applies immediately and saves `piBetterHarness.navigatorView`.
|
|
@@ -224,19 +226,19 @@ Worker-owned tasks expose status and logs; their execution remains managed by th
|
|
|
224
226
|
owning agent. Older worker tasks appear when a retained assignment wait proves
|
|
225
227
|
their parent, so unrelated sessions are never inferred from a reused conversation.
|
|
226
228
|
|
|
227
|
-
**
|
|
229
|
+
**Pin work panels** controls the shared navigator used by Goal, Outcome & Todo,
|
|
228
230
|
Subagents, and Background Tasks. **On** (the default) keeps it above the input;
|
|
229
231
|
**Off** places it in the conversation so it scrolls with chat. Changes apply
|
|
230
232
|
immediately and save under `piBetterHarness.navigator` for future sessions.
|
|
231
233
|
Package controls and detail views remain available in either mode. Standalone
|
|
232
234
|
packages use the same shared navigator and saved preference.
|
|
233
235
|
|
|
234
|
-
The hub includes **Tool output** and **Tool animation** when the bundled renderer
|
|
236
|
+
The hub includes **Tool output** and **Tool progress animation** when the bundled renderer
|
|
235
237
|
extension is loaded. Changes apply immediately and save the default for future
|
|
236
238
|
sessions. The animation preference is stored in `piBetterHarness.toolAnimation`;
|
|
237
239
|
normal output and expanded tool details are never animated.
|
|
238
|
-
The hub also owns **
|
|
239
|
-
Tasks. Choose **
|
|
240
|
+
The hub also owns **Completion delivery**, shared by Subagents and Background
|
|
241
|
+
Tasks. Choose **When idle** (the default) or **During run**. Changes
|
|
240
242
|
apply immediately and autosave to the current session branch, including across
|
|
241
243
|
reloads. Press **Ctrl+S** to save the current choice as your default for future
|
|
242
244
|
Pi sessions; changing a session afterward does not change that saved default.
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
interface SettingCopy {
|
|
2
|
+
label?: string;
|
|
3
|
+
description: string;
|
|
4
|
+
values?: Readonly<Record<string, string>>;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
// Use stable contribution IDs so existing versions of the extensions get the same help.
|
|
8
|
+
export const controlCopy = new Map<string, SettingCopy>([
|
|
9
|
+
["background-review-interval", {
|
|
10
|
+
label: "Background wait reviews",
|
|
11
|
+
description: "When the session is waiting for a local task with callbacks on, Pi asks the main agent to review it after this long without progress. Each review shows elapsed time and the last check or output.",
|
|
12
|
+
}],
|
|
13
|
+
["goal-auto-start", {
|
|
14
|
+
description: "Start a Goal automatically when Pi accepts an Outcome with work to do and there is no unfinished Goal.",
|
|
15
|
+
}],
|
|
16
|
+
["tool-call-guard", {
|
|
17
|
+
label: "Foreground wait guard",
|
|
18
|
+
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.",
|
|
19
|
+
}],
|
|
20
|
+
["outcome-todo", {
|
|
21
|
+
label: "Outcome and Todo tools",
|
|
22
|
+
description: "Lets Pi record what the session should deliver and track its progress as a checklist.",
|
|
23
|
+
}],
|
|
24
|
+
["outcome-todo-ledger", {
|
|
25
|
+
label: "Project work ledger",
|
|
26
|
+
description: "Lets sessions attach a saved project checklist and carry its progress across sessions. Use /ledger to list or attach a ledger.",
|
|
27
|
+
}],
|
|
28
|
+
["outcome-todo-display", {
|
|
29
|
+
label: "Outcome and Todo panel",
|
|
30
|
+
description: "Shows the session objective and checklist in the TUI when Outcome and Todo tools are on.",
|
|
31
|
+
}],
|
|
32
|
+
["navigator-sticky", {
|
|
33
|
+
label: "Pin work panels",
|
|
34
|
+
description: "Keeps the work panels above the editor as the conversation scrolls. Off lets them scroll with the conversation on supported Pi versions.",
|
|
35
|
+
}],
|
|
36
|
+
["navigator-view", {
|
|
37
|
+
label: "Navigator layout",
|
|
38
|
+
description: "Tree nests tasks under their agent. Flat list groups rows by work type.",
|
|
39
|
+
values: { tree: "Tree", flatten: "Flat list" },
|
|
40
|
+
}],
|
|
41
|
+
["tool-output", {
|
|
42
|
+
description: "Normal shows the usual tool transcript. Compact groups completed calls and hides their details until you expand the group.",
|
|
43
|
+
values: { Minimal: "Compact" },
|
|
44
|
+
}],
|
|
45
|
+
["tool-animation", {
|
|
46
|
+
label: "Tool progress animation",
|
|
47
|
+
description: "Shows an animated shimmer on active tool calls. Turn it off to remove that animation.",
|
|
48
|
+
values: { Shimmer: "On" },
|
|
49
|
+
}],
|
|
50
|
+
]);
|
|
51
|
+
|
|
52
|
+
export const linkCopy = new Map<string, SettingCopy>([
|
|
53
|
+
["agents", {
|
|
54
|
+
label: "Agent catalog",
|
|
55
|
+
description: "Browse the agents Pi can delegate to and manage their profiles.",
|
|
56
|
+
}],
|
|
57
|
+
["goal", {
|
|
58
|
+
label: "Goal settings",
|
|
59
|
+
description: "Choose when Goals continue automatically, resume from conversation, or pause on Escape.",
|
|
60
|
+
}],
|
|
61
|
+
["sandbox", {
|
|
62
|
+
label: "Sandbox settings",
|
|
63
|
+
description: "Review sandbox permissions for what tools can access and where they can run.",
|
|
64
|
+
}],
|
|
65
|
+
["subagents", {
|
|
66
|
+
label: "Subagent settings",
|
|
67
|
+
description: "Choose how Pi delegates work and set limits for concurrent subagents, timeouts, and progress alerts.",
|
|
68
|
+
}],
|
|
69
|
+
]);
|
|
@@ -24,7 +24,7 @@ export default function harnessSettingsExtension(pi: ExtensionAPI): void {
|
|
|
24
24
|
const readSettings = (): ReturnType<typeof getCallbackSettings> => {
|
|
25
25
|
try { return getCallbackSettings(ctx); }
|
|
26
26
|
catch (error) {
|
|
27
|
-
const message = `Callback default unavailable
|
|
27
|
+
const message = `Callback default unavailable. Using When idle. ${error instanceof Error ? error.message : String(error)}`;
|
|
28
28
|
if (!reported.has(message)) { ctx.ui.notify(message, "error"); reported.add(message); }
|
|
29
29
|
return { mode: "hold", source: "default" };
|
|
30
30
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { Theme } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import { Container, SettingsList, Text, getKeybindings, setKeybindings, KeybindingsManager, TUI_KEYBINDINGS, matchesKey, type SettingItem } from "@earendil-works/pi-tui";
|
|
1
|
+
import type { ExtensionCommandContext, Theme } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { Container, SettingsList, Spacer, Text, getKeybindings, setKeybindings, KeybindingsManager, TUI_KEYBINDINGS, matchesKey, type SettingItem } from "@earendil-works/pi-tui";
|
|
3
|
+
import { controlCopy, linkCopy } from "./copy.ts";
|
|
3
4
|
import type { SettingsControl, SettingsLink } from "./registry.ts";
|
|
4
5
|
|
|
5
6
|
export interface CallbackSettingsControl {
|
|
@@ -9,45 +10,91 @@ export interface CallbackSettingsControl {
|
|
|
9
10
|
}
|
|
10
11
|
|
|
11
12
|
const CALLBACK_SETTING_ID = "callbacks:while-busy";
|
|
12
|
-
const
|
|
13
|
+
const callbackLabels = { hold: "When idle", steer: "During run" };
|
|
14
|
+
const callbackDescription = (source: "session" | "default") => [
|
|
15
|
+
"When idle holds background and subagent results until the run ends. During run can deliver them between tool calls.",
|
|
16
|
+
source === "session" ? "Using this session’s setting." : "Using the default.",
|
|
17
|
+
"Changes apply to this session. Ctrl+S saves your default.",
|
|
18
|
+
].join("\n");
|
|
13
19
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
20
|
+
// Keep each package page beside the controls used for the same task.
|
|
21
|
+
const taskOrder = [
|
|
22
|
+
"setting:outcome-todo", "setting:goal-auto-start", "link:goal", "setting:outcome-todo-ledger",
|
|
23
|
+
"link:subagents", "link:agents", "link:sandbox",
|
|
24
|
+
"setting:tool-call-guard", "setting:background-review-interval", CALLBACK_SETTING_ID,
|
|
25
|
+
"setting:navigator-view", "setting:navigator-sticky", "setting:outcome-todo-display",
|
|
26
|
+
"setting:tool-output", "setting:tool-animation",
|
|
27
|
+
];
|
|
28
|
+
const position = new Map(taskOrder.map((id, index) => [id, index]));
|
|
29
|
+
|
|
30
|
+
function presentControl(control: SettingsControl) {
|
|
31
|
+
const copy = controlCopy.get(control.id);
|
|
32
|
+
const valueLabels = copy?.values;
|
|
33
|
+
const display = (raw: string) => valueLabels && Object.hasOwn(valueLabels, raw) ? valueLabels[raw]! : raw;
|
|
34
|
+
const values = control.values.map(display);
|
|
35
|
+
const description = typeof control.description === "string" && control.description.trim()
|
|
36
|
+
? control.description : copy?.description;
|
|
37
|
+
const item: SettingItem = {
|
|
38
|
+
id: `setting:${control.id}`,
|
|
39
|
+
label: copy?.label ?? control.label,
|
|
40
|
+
currentValue: display(control.get()),
|
|
41
|
+
description: [description ?? `Available values are ${values.join(", ")}.`, copy && "Saved as a user default."].filter(Boolean).join("\n"),
|
|
42
|
+
values,
|
|
43
|
+
};
|
|
44
|
+
return { control, item, display, values };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function presentLink(link: SettingsLink): SettingItem {
|
|
48
|
+
const copy = linkCopy.get(link.id);
|
|
49
|
+
const description = typeof link.description === "string" && link.description.trim()
|
|
50
|
+
? link.description : copy?.description;
|
|
51
|
+
const action = "Open";
|
|
52
|
+
return {
|
|
53
|
+
id: `link:${link.id}`,
|
|
54
|
+
label: copy?.label ?? link.label,
|
|
55
|
+
currentValue: action,
|
|
56
|
+
description: [description, `You can also run ${link.command}.`].filter(Boolean).join("\n"),
|
|
57
|
+
values: [action],
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export async function chooseHarnessSetting(ctx: ExtensionCommandContext, links: SettingsLink[], selected?: string, callbacks?: CallbackSettingsControl, controls: SettingsControl[] = [], navigatorView?: SettingsControl): Promise<string | undefined> {
|
|
62
|
+
return ctx.ui.custom((tui, theme: Theme, _kb, done: (id?: string) => void) => {
|
|
63
|
+
const currentCallback = callbacks?.get();
|
|
64
|
+
let callbackMode = currentCallback?.mode ?? "hold";
|
|
65
|
+
const callbackSetting: SettingItem | undefined = currentCallback && {
|
|
18
66
|
id: CALLBACK_SETTING_ID,
|
|
19
|
-
label: "
|
|
20
|
-
currentValue:
|
|
21
|
-
description:
|
|
22
|
-
values:
|
|
23
|
-
}
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
const items
|
|
67
|
+
label: "Completion delivery",
|
|
68
|
+
currentValue: callbackLabels[callbackMode],
|
|
69
|
+
description: callbackDescription(currentCallback.source),
|
|
70
|
+
values: Object.values(callbackLabels),
|
|
71
|
+
};
|
|
72
|
+
const allControls = navigatorView ? [...controls, navigatorView] : [...controls];
|
|
73
|
+
const entries = allControls.map(presentControl);
|
|
74
|
+
const items = [
|
|
27
75
|
...(callbackSetting ? [callbackSetting] : []),
|
|
28
|
-
...
|
|
29
|
-
...links.map(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
];
|
|
33
|
-
const feedback = new Text("", 0, 0);
|
|
76
|
+
...entries.map(({ item }) => item),
|
|
77
|
+
...links.map(presentLink),
|
|
78
|
+
].sort((a, b) => (position.get(a.id) ?? position.size) - (position.get(b.id) ?? position.size));
|
|
79
|
+
const feedback = new Text("", 2, 0);
|
|
34
80
|
let changing = false;
|
|
35
81
|
const report = (message: string, error = false) => {
|
|
36
|
-
feedback.setText(theme.fg(error ? "error" : "
|
|
82
|
+
feedback.setText(theme.fg(error ? "error" : "text", message));
|
|
37
83
|
tui.requestRender?.();
|
|
38
84
|
};
|
|
39
85
|
const list = new SettingsList(items, 10, {
|
|
40
86
|
label: (text, active) => theme.fg(active ? "accent" : "text", text),
|
|
41
87
|
value: (text, active) => active ? theme.inverse(text) : theme.fg("muted", text),
|
|
42
|
-
description: text => theme.fg("
|
|
88
|
+
description: text => theme.fg("text", text), cursor: "> ", hint: text => theme.fg("dim", text),
|
|
43
89
|
}, (id, value) => {
|
|
44
|
-
const
|
|
45
|
-
if (
|
|
46
|
-
const previous = control.get();
|
|
90
|
+
const entry = entries.find(({ item }) => item.id === id);
|
|
91
|
+
if (entry) {
|
|
92
|
+
const previous = entry.display(entry.control.get());
|
|
93
|
+
const next = entry.control.values[entry.values.indexOf(value)]!;
|
|
47
94
|
changing = true;
|
|
48
95
|
report("Saving setting...");
|
|
49
|
-
Promise.resolve().then(() => control.change(
|
|
50
|
-
list.updateValue(id, control.get());
|
|
96
|
+
Promise.resolve().then(() => entry.control.change(next, ctx)).then(() => {
|
|
97
|
+
list.updateValue(id, entry.display(entry.control.get()));
|
|
51
98
|
report("Setting saved.");
|
|
52
99
|
}).catch(error => {
|
|
53
100
|
list.updateValue(id, previous);
|
|
@@ -57,13 +104,13 @@ export async function chooseHarnessSetting(ctx: any, links: SettingsLink[], sele
|
|
|
57
104
|
}
|
|
58
105
|
if (id !== CALLBACK_SETTING_ID || !callbacks || !callbackSetting) { done(id); return; }
|
|
59
106
|
try {
|
|
60
|
-
const nextMode = value ===
|
|
107
|
+
const nextMode = value === callbackLabels.steer ? "steer" : "hold";
|
|
61
108
|
callbacks.change(nextMode);
|
|
62
109
|
callbackMode = nextMode;
|
|
63
|
-
callbackSetting.description = "
|
|
110
|
+
callbackSetting.description = callbackDescription("session");
|
|
64
111
|
report("Session setting saved.");
|
|
65
112
|
} catch (error) {
|
|
66
|
-
list.updateValue(CALLBACK_SETTING_ID,
|
|
113
|
+
list.updateValue(CALLBACK_SETTING_ID, callbackLabels[callbackMode]);
|
|
67
114
|
report(error instanceof Error ? error.message : String(error), true);
|
|
68
115
|
}
|
|
69
116
|
}, () => done(), { enableSearch: false });
|
|
@@ -79,9 +126,9 @@ export async function chooseHarnessSetting(ctx: any, links: SettingsLink[], sele
|
|
|
79
126
|
} finally { setKeybindings(bindings); }
|
|
80
127
|
}
|
|
81
128
|
const page = new Container();
|
|
82
|
-
page.addChild(new Text(theme.fg("
|
|
129
|
+
page.addChild(new Text(theme.bold(theme.fg("text", "Harness settings")), 0, 0));
|
|
130
|
+
page.addChild(new Spacer(1));
|
|
83
131
|
page.addChild(list);
|
|
84
|
-
if (callbacks) page.addChild(new Text(theme.fg("dim", "Callbacks autosave to this session. Ctrl+S saves the default for future sessions."), 0, 0));
|
|
85
132
|
page.addChild(feedback);
|
|
86
133
|
return {
|
|
87
134
|
render: (width: number) => page.render(width),
|
|
@@ -97,4 +144,4 @@ export async function chooseHarnessSetting(ctx: any, links: SettingsLink[], sele
|
|
|
97
144
|
},
|
|
98
145
|
};
|
|
99
146
|
});
|
|
100
|
-
}
|
|
147
|
+
}
|
|
@@ -3,6 +3,7 @@ import type { ExtensionAPI, ExtensionCommandContext } from "@earendil-works/pi-c
|
|
|
3
3
|
export interface SettingsLink {
|
|
4
4
|
id: string;
|
|
5
5
|
label: string;
|
|
6
|
+
description?: string;
|
|
6
7
|
command: string;
|
|
7
8
|
open(ctx: ExtensionCommandContext): Promise<void> | void;
|
|
8
9
|
}
|
|
@@ -10,6 +11,7 @@ export interface SettingsLink {
|
|
|
10
11
|
export interface SettingsControl {
|
|
11
12
|
id: string;
|
|
12
13
|
label: string;
|
|
14
|
+
description?: string;
|
|
13
15
|
values: string[];
|
|
14
16
|
get(): string;
|
|
15
17
|
change(value: string, ctx: ExtensionCommandContext): Promise<void> | void;
|
|
@@ -14,19 +14,24 @@ export function canRenderTaskRuntime(width: number, runtime: CompactTaskHeader["
|
|
|
14
14
|
return visibleWidth(runtime.status + (runtime.clock ? ` ${runtime.clock}` : "")) + 6 <= Math.floor(width);
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
export function renderCompactTaskHeader(summary: string | undefined, width: number, theme: PlanRenderTheme, header: CompactTaskHeader): string[] {
|
|
17
|
+
export function renderCompactTaskHeader(summary: string | undefined, width: number, theme: PlanRenderTheme, header: CompactTaskHeader, inProgress = false): string[] {
|
|
18
18
|
const size = Math.max(1, Math.floor(width));
|
|
19
|
-
|
|
19
|
+
let left = theme.fg("warning", "todo") + (header.disclosure ? theme.fg("accent", ` ${header.disclosure}`) : "") +
|
|
20
20
|
(summary ? theme.fg("dim", ` ${summary}`) : "");
|
|
21
21
|
const runtime = header.runtime;
|
|
22
22
|
const tone = runtime?.status === "complete" ? "success" : runtime?.status === "active" ? "accent" : "warning";
|
|
23
23
|
const right = runtime ? theme.fg(tone, runtime.status) + (runtime.clock ? theme.fg("dim", ` ${runtime.clock}`) : "") : "";
|
|
24
24
|
const rightWidth = visibleWidth(right);
|
|
25
|
-
const
|
|
25
|
+
const showRuntime = right && canRenderTaskRuntime(size, runtime);
|
|
26
|
+
const leftWidth = showRuntime ? Math.max(4, size - rightWidth - 2) : size;
|
|
27
|
+
const progressMark = " · ●";
|
|
28
|
+
if (inProgress && visibleWidth(left) + visibleWidth(progressMark) <= leftWidth) {
|
|
29
|
+
left += theme.fg("accent", progressMark);
|
|
30
|
+
}
|
|
26
31
|
const title = truncateToWidth(left, leftWidth);
|
|
27
|
-
const heading =
|
|
32
|
+
const heading = showRuntime
|
|
28
33
|
? title + " ".repeat(Math.max(2, size - visibleWidth(title) - rightWidth)) + right
|
|
29
|
-
:
|
|
34
|
+
: title;
|
|
30
35
|
const lines = [truncateToWidth(heading, size)];
|
|
31
36
|
const indent = Math.min(2, size - 1);
|
|
32
37
|
const details: string[] = [];
|
|
@@ -40,4 +45,4 @@ export function renderCompactTaskHeader(summary: string | undefined, width: numb
|
|
|
40
45
|
}
|
|
41
46
|
if (details.length > 0) lines.push(...details, "");
|
|
42
47
|
return lines;
|
|
43
|
-
}
|
|
48
|
+
}
|
|
@@ -10,7 +10,7 @@ import { OUTCOME_ENTRY, prepareOutcome, restoreOutcome, formatOutcome, type Outc
|
|
|
10
10
|
import { changeOutcomeTodoPreference, parseOutcomeTodoPreferences } from "./preferences.js";
|
|
11
11
|
import { canRenderTaskRuntime, renderCompactTaskHeader, type CompactTaskHeader } from "./compact-task-header.js";
|
|
12
12
|
import type { GoalSnapshot } from "pi-better-goal/src/types.ts";
|
|
13
|
-
import {
|
|
13
|
+
import { OUTCOME_ACCEPTED_EVENT, type TaskContextRequest } from "pi-better-goal/src/task-context.ts";
|
|
14
14
|
|
|
15
15
|
import {
|
|
16
16
|
completedPlanClearDelay,
|
|
@@ -168,7 +168,7 @@ export default function taskContextExtension(pi: ExtensionAPI): void {
|
|
|
168
168
|
let enabled = false;
|
|
169
169
|
let display = true;
|
|
170
170
|
let ledgerEnabled = false;
|
|
171
|
-
let
|
|
171
|
+
let sessionContext: ExtensionContext | undefined;
|
|
172
172
|
let outcome: Outcome | null = null;
|
|
173
173
|
const taskTools = ["update_todo", "get_todo"] as const;
|
|
174
174
|
const syncTools = (): void => {
|
|
@@ -303,7 +303,7 @@ export default function taskContextExtension(pi: ExtensionAPI): void {
|
|
|
303
303
|
};
|
|
304
304
|
|
|
305
305
|
const attachLedger = (ctx: ExtensionContext, id: string): WorkLedger => {
|
|
306
|
-
if (!ledgerEnabled) throw new Error("
|
|
306
|
+
if (!ledgerEnabled) throw new Error("Project work ledger is off. Enable it in /harness-settings first.");
|
|
307
307
|
const candidate = readAssociatedWorkLedger(ctx.cwd, id);
|
|
308
308
|
if (ledgerId !== id) pi.appendEntry(WORK_LEDGER_ASSOCIATION_ENTRY, workLedgerAssociationEntry(id));
|
|
309
309
|
ledgerId = id;
|
|
@@ -434,10 +434,11 @@ export default function taskContextExtension(pi: ExtensionAPI): void {
|
|
|
434
434
|
|
|
435
435
|
const restore = (ctx: ExtensionContext): void => {
|
|
436
436
|
const entries = ctx.sessionManager.getBranch();
|
|
437
|
-
|
|
437
|
+
sessionContext = ctx;
|
|
438
|
+
const trigger = reconstructGoalSnapshot(entries);
|
|
439
|
+
outcome = restoreOutcome(entries, trigger);
|
|
438
440
|
restoreLedgerState(ctx);
|
|
439
441
|
if (enabled) {
|
|
440
|
-
const trigger = reconstructGoalSnapshot(entries);
|
|
441
442
|
if (!outcome && trigger && trigger.status !== "complete") {
|
|
442
443
|
outcome = { objective: trigger.objective, source: "goal", goalId: trigger.goalId, status: trigger.status === "active" ? "active" : "paused" };
|
|
443
444
|
} else if (outcome?.goalId && outcome.status !== "complete" && outcome.status !== "cancelled") {
|
|
@@ -484,7 +485,6 @@ export default function taskContextExtension(pi: ExtensionAPI): void {
|
|
|
484
485
|
|
|
485
486
|
const installWidget = (ctx: ExtensionContext): void => {
|
|
486
487
|
if (!ctx.hasUI) return;
|
|
487
|
-
widgetContext = ctx;
|
|
488
488
|
setNavigatorPanel(ctx,
|
|
489
489
|
EXTENSION_NAME,
|
|
490
490
|
(tui, theme) => {
|
|
@@ -535,7 +535,7 @@ export default function taskContextExtension(pi: ExtensionAPI): void {
|
|
|
535
535
|
promptSnippet: "Remember the accepted outcome and update Todo, workflow, or durable ledger progress",
|
|
536
536
|
promptGuidelines: [
|
|
537
537
|
"Capture the accepted outcome before substantive implementation, delegation, or investigation. An outcome-only update is valid; do not invent a checklist or acceptance criteria.",
|
|
538
|
-
"Use newTask:true with its outcome when the user switches to unrelated work. Omit newTask for a correction or refinement of the same task.
|
|
538
|
+
"Use newTask:true with its outcome when the user switches to unrelated work. Omit newTask for a correction or refinement of the same task. For an active Goal, call update_goal after verifying delivery. Otherwise mark the outcome complete explicitly.",
|
|
539
539
|
"Use a Todo checklist when several meaningful milestones help track delivery; update it when work completes, is blocked, or changes scope.",
|
|
540
540
|
"Write each Todo label as a short action in plain language, usually 3-7 English words or a similarly short phrase in the task's language. For example: 'Add Todo toggle' or 'Test keyboard controls'. Put methods, file paths, rationale, and acceptance criteria in the outcome, explanation, or workflow records, not the label. Apply this to workflow titles too; do not copy long issue headings.",
|
|
541
541
|
"For generic plans only, mark distinct milestones in_progress when work is actually underway. Do not mark a delegated step completed until its result or failure has been inspected and integrated.",
|
|
@@ -549,7 +549,7 @@ export default function taskContextExtension(pi: ExtensionAPI): void {
|
|
|
549
549
|
],
|
|
550
550
|
parameters: UpdatePlanSchema,
|
|
551
551
|
async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
|
|
552
|
-
if (!enabled) throw new Error("Outcome
|
|
552
|
+
if (!enabled) throw new Error("Outcome and Todo tools are off. Enable them in /harness-settings.");
|
|
553
553
|
const owner = workflowPlanOwner(ctx);
|
|
554
554
|
const input = params as {
|
|
555
555
|
explanation?: string; newTask?: boolean; todo?: PlanStepInput[]; outcome?: OutcomeInput;
|
|
@@ -560,7 +560,7 @@ export default function taskContextExtension(pi: ExtensionAPI): void {
|
|
|
560
560
|
input.newTask !== undefined || input.explanation !== undefined) {
|
|
561
561
|
throw new Error("Send update_todo ledger alone; ledger changes are not combined with outcome, Todo, or workflow changes.");
|
|
562
562
|
}
|
|
563
|
-
if (!ledgerEnabled) throw new Error("
|
|
563
|
+
if (!ledgerEnabled) throw new Error("Project work ledger is off. Enable it in /harness-settings first.");
|
|
564
564
|
const result = executeLedgerMutation(input.ledger, ctx.cwd, ledgerSessionBinding(ctx));
|
|
565
565
|
if (result.details.ledger && result.details.ledger.id === ledgerId) {
|
|
566
566
|
ledger = result.details.ledger;
|
|
@@ -577,6 +577,20 @@ export default function taskContextExtension(pi: ExtensionAPI): void {
|
|
|
577
577
|
if (input.todo !== undefined && owner) throw new Error(`${owner} owns the task plan. Send workflow instead of todo.`);
|
|
578
578
|
const nextOutcome = input.outcome ? prepareOutcome(outcome, input.outcome, input.newTask) : null;
|
|
579
579
|
if (!input.newTask) assertOutcomeCompletionAllowed(ctx, nextOutcome);
|
|
580
|
+
let reopenedGoalId: string | undefined;
|
|
581
|
+
if (nextOutcome?.goalId) {
|
|
582
|
+
const goal = reconstructGoalSnapshot(ctx.sessionManager.getBranch());
|
|
583
|
+
if (goal?.goalId === nextOutcome.goalId) {
|
|
584
|
+
if (nextOutcome.status === "complete" && goal.status === "active") {
|
|
585
|
+
throw new Error("This Outcome belongs to an active Goal. Verify its acceptance criteria and use update_goal to complete both.");
|
|
586
|
+
}
|
|
587
|
+
if (nextOutcome.status === "active" && goal.status === "complete") {
|
|
588
|
+
if (input.outcome?.status === "active") reopenedGoalId = nextOutcome.goalId;
|
|
589
|
+
delete nextOutcome.goalId;
|
|
590
|
+
if (nextOutcome.source === "goal") delete nextOutcome.source;
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
}
|
|
580
594
|
const replacement = input.todo?.length ? replacePlan(input.newTask ? null : currentPlan, input.todo, input.explanation) : null;
|
|
581
595
|
const detachOnCommit = input.newTask && ledgerId !== null;
|
|
582
596
|
// Commit task memory only after the requested checklist or workflow operation succeeds.
|
|
@@ -590,7 +604,7 @@ export default function taskContextExtension(pi: ExtensionAPI): void {
|
|
|
590
604
|
saveOutcome(nextOutcome);
|
|
591
605
|
const sessionId = ctx.sessionManager.getSessionId?.();
|
|
592
606
|
if (typeof sessionId === "string") {
|
|
593
|
-
pi.events.emit(OUTCOME_ACCEPTED_EVENT, { sessionId, outcome: { ...nextOutcome } });
|
|
607
|
+
pi.events.emit(OUTCOME_ACCEPTED_EVENT, { sessionId, reopenedGoalId, outcome: { ...nextOutcome } });
|
|
594
608
|
}
|
|
595
609
|
};
|
|
596
610
|
if (!input.workflow && input.todo === undefined) {
|
|
@@ -694,10 +708,10 @@ export default function taskContextExtension(pi: ExtensionAPI): void {
|
|
|
694
708
|
promptSnippet: "Inspect the common work plan: outcome, Todo or workflow rows, and the associated durable ledger",
|
|
695
709
|
parameters: getTodoParameters,
|
|
696
710
|
async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
|
|
697
|
-
if (!enabled) throw new Error("Outcome
|
|
711
|
+
if (!enabled) throw new Error("Outcome and Todo tools are off. Enable them in /harness-settings.");
|
|
698
712
|
const input = params as { ledger?: GetTodoLedgerInput };
|
|
699
713
|
if (input.ledger !== undefined && !ledgerEnabled) {
|
|
700
|
-
throw new Error("
|
|
714
|
+
throw new Error("Project work ledger is off. Enable it in /harness-settings first.");
|
|
701
715
|
}
|
|
702
716
|
refreshAssociatedLedger(ctx);
|
|
703
717
|
const ledgerText = ledgerTodoText();
|
|
@@ -785,7 +799,7 @@ export default function taskContextExtension(pi: ExtensionAPI): void {
|
|
|
785
799
|
handler: async (args, ctx) => {
|
|
786
800
|
const [action = "", value = ""] = args.trim().split(/\s+/, 2);
|
|
787
801
|
if (!ledgerEnabled && (action === "" || action === "list" || action === "show")) {
|
|
788
|
-
ctx.ui.notify("
|
|
802
|
+
ctx.ui.notify("Project work ledger is off. Enable it in /harness-settings to view ledgers.", "warning");
|
|
789
803
|
return;
|
|
790
804
|
}
|
|
791
805
|
const store = openWorkLedgerStore({ cwd: ctx.cwd });
|
|
@@ -813,7 +827,7 @@ export default function taskContextExtension(pi: ExtensionAPI): void {
|
|
|
813
827
|
return;
|
|
814
828
|
}
|
|
815
829
|
if (!ledgerEnabled) {
|
|
816
|
-
ctx.ui.notify("
|
|
830
|
+
ctx.ui.notify("Project work ledger is off. Enable it in /harness-settings before associating a ledger.", "warning");
|
|
817
831
|
return;
|
|
818
832
|
}
|
|
819
833
|
if (!value) {
|
|
@@ -867,21 +881,42 @@ export default function taskContextExtension(pi: ExtensionAPI): void {
|
|
|
867
881
|
registerSettings();
|
|
868
882
|
const unsubscribeTask = pi.events.on("pi-better-harness:task-context", (event: unknown) => {
|
|
869
883
|
if (!event || typeof event !== "object") return;
|
|
870
|
-
const request = event as
|
|
884
|
+
const request = event as TaskContextRequest;
|
|
871
885
|
request.enabled = enabled;
|
|
886
|
+
if (request.action === "audit") {
|
|
887
|
+
if (enabled && outcome?.goalId && outcome.goalId === request.goalId) {
|
|
888
|
+
request.objective = outcome.objective;
|
|
889
|
+
request.doneWhen = outcome.doneWhen?.filter(criterion => criterion.trim());
|
|
890
|
+
if (sessionContext) {
|
|
891
|
+
try {
|
|
892
|
+
assertOutcomeCompletionAllowed(sessionContext, { ...outcome, status: "complete" });
|
|
893
|
+
} catch (error) {
|
|
894
|
+
request.ledgerBlocker = error instanceof Error ? error.message : String(error);
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
if (sessionContext && !workflowPlanOwner(sessionContext) && !rushBinding) {
|
|
898
|
+
request.openSteps = currentPlan?.steps.filter(step => step.status !== "completed").map(step => step.step);
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
return;
|
|
902
|
+
}
|
|
872
903
|
if (request.action === "inspect") {
|
|
873
|
-
const goal =
|
|
874
|
-
request.display = !!(typeof request.goalId === "string" &&
|
|
904
|
+
const goal = sessionContext ? reconstructGoalSnapshot(sessionContext.sessionManager.getBranch()) : null;
|
|
905
|
+
request.display = !!(typeof request.goalId === "string" && sessionContext?.hasUI && display && displayMode !== "hidden" &&
|
|
875
906
|
outcome && request.goalId === outcome.goalId && goal?.goalId === request.goalId && typeof request.width === "number" &&
|
|
876
|
-
canRenderTaskRuntime(request.width, goalHeaderRuntime(goal)) && displayedWorkflowOwner === workflowPlanOwner(
|
|
907
|
+
canRenderTaskRuntime(request.width, goalHeaderRuntime(goal)) && displayedWorkflowOwner === workflowPlanOwner(sessionContext));
|
|
877
908
|
}
|
|
878
909
|
if (!enabled || request.action === "inspect") return;
|
|
879
910
|
if (request.action === "bind") {
|
|
880
|
-
if (request.goalId && request.objective?.trim() === outcome?.objective &&
|
|
911
|
+
if (request.goalId && request.objective?.trim() === outcome?.objective && outcome?.status === "active" && !outcome.goalId) {
|
|
881
912
|
saveOutcome({ ...outcome, goalId: request.goalId });
|
|
882
913
|
}
|
|
883
914
|
} else if (request.action === "start" && request.goalId && request.objective?.trim()) {
|
|
884
915
|
if (outcome?.goalId === request.goalId) return;
|
|
916
|
+
if (outcome?.status === "active" && !outcome.goalId && outcome.objective === request.objective.trim()) {
|
|
917
|
+
saveOutcome({ ...outcome, goalId: request.goalId });
|
|
918
|
+
return;
|
|
919
|
+
}
|
|
885
920
|
clearWorkflowPlan();
|
|
886
921
|
if (currentPlan) clearPlan();
|
|
887
922
|
saveOutcome({ objective: request.objective.trim(), status: "active", goalId: request.goalId, source: "goal" });
|
|
@@ -953,7 +988,7 @@ export default function taskContextExtension(pi: ExtensionAPI): void {
|
|
|
953
988
|
if (typeof unsubscribeSettings === "function") unsubscribeSettings();
|
|
954
989
|
if (typeof unsubscribeTask === "function") unsubscribeTask();
|
|
955
990
|
refreshWidget = undefined;
|
|
956
|
-
|
|
991
|
+
sessionContext = undefined;
|
|
957
992
|
try {
|
|
958
993
|
setNavigatorPanel(ctx, EXTENSION_NAME, undefined);
|
|
959
994
|
} catch { /* best-effort cleanup */ }
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { reconstructGoalSnapshot } from "pi-better-goal/src/goal-state.ts";
|
|
2
|
+
import type { GoalSnapshot } from "pi-better-goal/src/types.ts";
|
|
3
|
+
|
|
1
4
|
export const OUTCOME_ENTRY = "pi-better-harness:outcome";
|
|
2
5
|
|
|
3
6
|
export interface OutcomeInput {
|
|
@@ -33,9 +36,13 @@ export function prepareOutcome(current: Outcome | null, input: OutcomeInput, new
|
|
|
33
36
|
};
|
|
34
37
|
}
|
|
35
38
|
|
|
36
|
-
export function restoreOutcome(
|
|
39
|
+
export function restoreOutcome(
|
|
40
|
+
entries: readonly { type: string; customType?: string; data?: unknown }[],
|
|
41
|
+
goal?: GoalSnapshot | null,
|
|
42
|
+
): Outcome | null {
|
|
43
|
+
let lastOutcomeIndex = -1;
|
|
37
44
|
let outcome: Outcome | null = null;
|
|
38
|
-
for (const entry of entries) {
|
|
45
|
+
for (const [index, entry] of entries.entries()) {
|
|
39
46
|
if (entry.type !== "custom" || entry.customType !== OUTCOME_ENTRY) continue;
|
|
40
47
|
const data = entry.data as { version?: number; outcome?: Outcome } | null;
|
|
41
48
|
if (data?.version !== 1 || !data.outcome) continue;
|
|
@@ -43,10 +50,19 @@ export function restoreOutcome(entries: Iterable<{ type: string; customType?: st
|
|
|
43
50
|
const parsed = prepareOutcome(null, data.outcome);
|
|
44
51
|
if (typeof data.outcome.goalId === "string") parsed.goalId = data.outcome.goalId;
|
|
45
52
|
outcome = parsed;
|
|
53
|
+
lastOutcomeIndex = index;
|
|
46
54
|
} catch {
|
|
47
55
|
// A malformed entry is not permission to replace previously valid task state.
|
|
48
56
|
}
|
|
49
57
|
}
|
|
58
|
+
// Older sessions could save new active work against a Goal that was already complete.
|
|
59
|
+
if (outcome?.status === "active" && goal?.status === "complete" && outcome.goalId === goal.goalId) {
|
|
60
|
+
const previous = reconstructGoalSnapshot(entries.slice(0, lastOutcomeIndex));
|
|
61
|
+
if (previous?.goalId === goal.goalId && previous.status === "complete") {
|
|
62
|
+
delete outcome.goalId;
|
|
63
|
+
if (outcome.source === "goal") delete outcome.source;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
50
66
|
return outcome;
|
|
51
67
|
}
|
|
52
68
|
|