pi-better-goal 0.16.3 → 0.17.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/README.md +18 -14
- package/package.json +1 -1
- package/src/index.ts +143 -76
- package/src/settings-page.ts +2 -2
- package/src/task-context.ts +15 -2
- package/src/workflow.ts +9 -3
package/README.md
CHANGED
|
@@ -31,7 +31,7 @@ never falls back to a global scanner. Elapsed-clock rendering reads only session
|
|
|
31
31
|
memory and does not collect activity.
|
|
32
32
|
|
|
33
33
|
- `/goal` runtime for starting, pausing, resuming, completing, and clearing the current objective.
|
|
34
|
-
- `/goal settings` opens an interactive settings page in the TUI. Select a row with Up/Down and toggle with Space/Enter; changes save immediately, and Escape closes the page. Automatic continuation, conversational resume, and **Pause on Esc** default to `on`. **Auto-start
|
|
34
|
+
- `/goal settings` opens an interactive settings page in the TUI. Select a row with Up/Down and toggle with Space/Enter; changes save immediately, and Escape closes the page. Automatic continuation, conversational resume, and **Pause on Esc** default to `on`. **Auto-start Goals** defaults to `off` and is also available directly on the `/harness-settings` main page. Automatic continuation controls idle and background-drain wakes; conversational resume controls the agent's Escape-pause resume tool; Pause on Esc controls whether editor Escape pauses the active goal. Goal kickoff, `/goal resume`, and `alt+g` remain available with these controls off. For scripts or non-interactive sessions, use `/goal settings auto-continue on|off`, `/goal settings conversational-resume on|off`, `/goal settings pause-on-escape on|off`, or `/goal settings auto-run on|off`; bare `/goal settings` prints the saved values outside the TUI.
|
|
35
35
|
- `escape` pauses the active goal by default, and it stays paused while you talk to the agent. With **Pause on Esc** off, observed editor Escape leaves the goal active while preserving native streaming interruption and menu/dialog cancellation. Automatic continuation remains independent. Hosts without terminal/focus inspection and unknown custom editors retain generic abort-to-pause behavior because they cannot identify Escape reliably. With conversational resume enabled, say "go" (the agent then calls `goal_resume`), or use `/goal resume` or `alt+g`. `/goal pause` resumes only through `/goal resume` or `alt+g`. Paused goals are never poked. On a macOS terminal without Option-as-Meta, `alt+g` types `©`; use `/goal resume` there.
|
|
36
36
|
- Background work that finishes while an `ask_user_question` is pending is handed to the agent right after the answer.
|
|
37
37
|
- A compact goal widget that does not replace Pi's footer.
|
|
@@ -40,21 +40,25 @@ memory and does not collect activity.
|
|
|
40
40
|
- Permission failure reports remain available to the agent as diagnostic evidence. They do not pause Goal or require a one-turn `/goal resume` release. The agent can retry, wait, or continue other authorized work; tool and sandbox permissions remain enforced independently. Repeated unchanged work still reaches the ordinary no-progress hold. Legacy permission-paused goals resume normally with `/goal resume` or `alt+g`.
|
|
41
41
|
- An observable-progress stall state for active goals.
|
|
42
42
|
|
|
43
|
-
##
|
|
43
|
+
## Goal & Todo in Harness
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
Harness saves the Goal objective, its acceptance criteria, boundaries and Todo steps.
|
|
46
|
+
The Goal extension manages execution, including timing, pause, resume and completion
|
|
47
|
+
checks. `/goal` shows the current Goal and its execution status. Use `/goal pause`
|
|
48
|
+
or `/goal resume` on a saved Goal or unfinished Todo, including older checklists.
|
|
49
|
+
Explicit resume starts work once. Pausing stores the hold before interrupting the
|
|
50
|
+
foreground turn. Already delegated tasks keep their execution owners.
|
|
46
51
|
|
|
47
|
-
|
|
52
|
+
In `/harness-settings`, **Auto-start Goals** defaults to Off. Turn it on to start a newly
|
|
53
|
+
saved Goal with acceptance criteria, explicitly reopened work, or an issue workflow
|
|
54
|
+
invoked with `/skill:rush-issues` or `/skill:resolve-issues`. Saving a checklist, opening a session and changing a setting do not
|
|
55
|
+
start execution. A workflow-owned Goal keeps its coordinator and completion gates.
|
|
48
56
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
Explicitly setting the same bound Outcome back to `active` after Goal completion starts a fresh Goal for its remaining work, including when Auto-start Goal is off. The new Goal preserves the Todo. Restoring an older session that saved active work against an already completed Goal leaves that work active and unbound. Running `/goal <exact Outcome objective>` binds it again with its Todo intact.
|
|
56
|
-
|
|
57
|
-
When a workflow already owns the session, the new Goal binds its registered coordinator without invoking it again. Its scheduler and completion checks continue to apply. An unavailable or invalid workflow coordinator prevents automatic creation.
|
|
57
|
+
A Goal with recorded acceptance criteria requires completion evidence for each criterion.
|
|
58
|
+
If the criteria are empty, verify the objective. Open Todo steps and open items in an
|
|
59
|
+
associated work ledger block agent-requested completion. The user can mark a running
|
|
60
|
+
Goal complete directly with `/goal complete`. Explicitly reopening completed work
|
|
61
|
+
with `update_todo({ goal: { objective, status: "active" } })` keeps its Todo and original workflow checks. With auto-start off, use `/goal resume` to restart it.
|
|
58
62
|
|
|
59
63
|
## Settings Storage
|
|
60
64
|
|
|
@@ -101,7 +105,7 @@ How a gate reports an unverifiable run follows the workflow that owns it. The is
|
|
|
101
105
|
|
|
102
106
|
- **Completion.** `update_goal` complete is refused, with each due action (action, unit, first 200 characters of detail), unless the scheduler reports `finish` and nothing else is due (an empty due list means workers are still running, so it is refused too). An unverifiable issue-workflow run is refused as well, with the step that restores it: bind the task plan with `update_todo({workflow:{path,revision}})`, rebind the run with `/skill:<coordinator>`, or fix the scheduler. The Goal stays active.
|
|
103
107
|
- **Pause.** `release_workflow` is refused unless every unfinished unit is quiet (nothing due for it) or blocked `human-decision` with `humanItem` 2-5. A unit blocked `retry-ci` or any other reason the run retries itself, or a `human-decision` item 1, is named in the refusal and the Goal stays active. Execution failures keep the fail-open warning here, so a genuine human hold can always hand the run back.
|
|
104
|
-
- **Auto-bind.**
|
|
108
|
+
- **Auto-bind.** With **Auto-start Goals** on, invoking `/skill:rush-issues` or `/skill:resolve-issues` with no active goal (none, or a completed one) creates and activates a Goal whose objective is the invocation text, exactly as `/goal <invocation>` would, without sending the command a second time. A paused or active Goal is left alone.
|
|
105
109
|
- **Wait timer.** When the scheduler's only due action is `wait` with a "next automatic attempt is at <ISO time>" detail, the next automatic continuation is scheduled for that time (at most the maximum timer delay, at least 5 seconds) and the wake-up is not counted as a no-progress retry. Other due work, or an unparseable time, uses the ordinary retry schedule. `autoContinue` off disables this timer.
|
|
106
110
|
|
|
107
111
|
When `pi-better-plan` is installed, it defers its prompt, checklist, and `update_plan` tool to a skill-owned task plan. Skills without this metadata retain normal goal and plan behavior. The skill itself owns its planning format and worker policy; the harness does not enumerate skills or impose a shared workflow schema. The former `pi-better-plan-workflow: coordinator` metadata remains supported for installed skills.
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -46,7 +46,7 @@ import { collectSubagentActivity } from "./subagents.js";
|
|
|
46
46
|
import { currentWorkflowOwner, ISSUE_WORKFLOW_SKILLS, skillCommandName, workflowEntry, workflowOwnerFromSkill, WORKFLOW_ENTRY_TYPE } from "./workflow.js";
|
|
47
47
|
import { completionGate, pauseGate, schedulerWaitUntil, operationResumeSchedulerGate } from "./workflow-gates.js";
|
|
48
48
|
import { workflowRehydrateMessage, WORKFLOW_REHYDRATE_MESSAGE_TYPE } from "./rehydrate.js";
|
|
49
|
-
import { canStartGoalFromOutcome, OUTCOME_ACCEPTED_EVENT, requestTaskContext, type OutcomeAcceptedEvent } from "./task-context.js";
|
|
49
|
+
import { canStartGoalFromOutcome, GOAL_PANEL_START_EVENT, type GoalPanelStartRequest, OUTCOME_ACCEPTED_EVENT, requestTaskContext, type OutcomeAcceptedEvent } from "./task-context.js";
|
|
50
50
|
import {
|
|
51
51
|
EVENT_ACTIVITY,
|
|
52
52
|
EVENT_READY,
|
|
@@ -123,14 +123,14 @@ function pausedGoalPrompt(goal: GoalSnapshot, conversationalResume: boolean, inc
|
|
|
123
123
|
const BLOCKING_QUESTION_TOOLS: ReadonlySet<string> = new Set(["ask_user_question"]);
|
|
124
124
|
|
|
125
125
|
const GOAL_ACTIONS: readonly AutocompleteItem[] = [
|
|
126
|
-
{ value: "pause", label: "pause", description: "Pause the
|
|
127
|
-
{ value: "resume", label: "resume", description: "
|
|
126
|
+
{ value: "pause", label: "pause", description: "Pause work on the current Goal and Todo" },
|
|
127
|
+
{ value: "resume", label: "resume", description: "Start or resume work on the current Goal and Todo" },
|
|
128
128
|
{ value: "clear", label: "clear", description: "Remove the current goal" },
|
|
129
129
|
{ value: "complete", label: "complete", description: "Mark the current goal complete" },
|
|
130
|
-
{ value: "settings", label: "settings", description: "Inspect or persist goal continuation, resume, Escape pause, and
|
|
130
|
+
{ value: "settings", label: "settings", description: "Inspect or persist goal continuation, resume, Escape pause, and automatic execution settings" },
|
|
131
131
|
];
|
|
132
132
|
|
|
133
|
-
const GOAL_SETTINGS = ["auto-continue", "conversational-resume", "pause-on-escape", "auto-
|
|
133
|
+
const GOAL_SETTINGS = ["auto-continue", "conversational-resume", "pause-on-escape", "auto-run"] as const;
|
|
134
134
|
|
|
135
135
|
export function goalArgumentCompletions(argumentPrefix: string): AutocompleteItem[] | null {
|
|
136
136
|
const prefix = argumentPrefix.trimStart().toLowerCase();
|
|
@@ -249,9 +249,15 @@ function formatGoal(
|
|
|
249
249
|
stall = observeGoalStall(goal, continuation),
|
|
250
250
|
preferences: GoalPreferences = { autoContinue: true, conversationalResume: true, pauseOnEscape: true, autoStartFromOutcome: false },
|
|
251
251
|
permissions?: PermissionHold | null,
|
|
252
|
+
saved?: { objective: string; status: string },
|
|
252
253
|
): string {
|
|
253
254
|
const settings = formatPreferences(preferences);
|
|
254
255
|
if (!goal) {
|
|
256
|
+
if (saved) {
|
|
257
|
+
const status = saved.status === "active" ? "saved" : saved.status;
|
|
258
|
+
const control = status === "saved" || status === "paused" ? "\nUse /goal resume to work on its Todo." : "";
|
|
259
|
+
return `Goal: ${saved.objective}\nStatus: ${status}${control}\n${settings}`;
|
|
260
|
+
}
|
|
255
261
|
return `No goal is set.\n${settings}`;
|
|
256
262
|
}
|
|
257
263
|
const budget = goal.tokenBudget === null ? "none" : String(goal.tokenBudget);
|
|
@@ -288,7 +294,7 @@ function formatPreferences(preferences: GoalPreferences): string {
|
|
|
288
294
|
`Automatic continuation setting: ${preferences.autoContinue ? "on" : "off"}${WAKE_DISABLED ? " (disabled by environment)" : ""}`,
|
|
289
295
|
`Conversational resume setting: ${preferences.conversationalResume ? "on" : "off"}`,
|
|
290
296
|
`Pause on Esc setting: ${preferences.pauseOnEscape ? "on" : "off"}`,
|
|
291
|
-
`Auto-start
|
|
297
|
+
`Auto-start Goals setting: ${preferences.autoStartFromOutcome ? "on" : "off"}`,
|
|
292
298
|
].join("\n");
|
|
293
299
|
}
|
|
294
300
|
|
|
@@ -407,7 +413,7 @@ export default function (pi: ExtensionAPI): void {
|
|
|
407
413
|
ctx.ui.notify(message, type);
|
|
408
414
|
};
|
|
409
415
|
|
|
410
|
-
const setGoal = (goal: GoalSnapshot, ctx: ExtensionContext, source: GoalEntrySource,
|
|
416
|
+
const setGoal = (goal: GoalSnapshot, ctx: ExtensionContext, source: GoalEntrySource, binding: "start" | "bind" | "adopt" = "start"): void => {
|
|
411
417
|
executionGeneration += 1;
|
|
412
418
|
lastAgentEvidence = null;
|
|
413
419
|
const previous = getGoal(ctx);
|
|
@@ -416,13 +422,13 @@ export default function (pi: ExtensionAPI): void {
|
|
|
416
422
|
// Bridge lifecycle after the raw Goal entry is durable. Harness may own the
|
|
417
423
|
// structured outcome, but Goal still owns its trigger, clocks, pauses, and wakes.
|
|
418
424
|
if (!previous || previous.goalId !== goal.goalId) {
|
|
419
|
-
requestTaskContext(pi,
|
|
425
|
+
requestTaskContext(pi, binding, goal);
|
|
420
426
|
} else if (goal.status === "complete") {
|
|
421
427
|
requestTaskContext(pi, "complete", goal);
|
|
422
428
|
} else if (goal.status === "paused" || goal.status === "budgetLimited") {
|
|
423
|
-
requestTaskContext(pi, "pause", goal);
|
|
429
|
+
requestTaskContext(pi, "pause", goal, undefined, source === "command");
|
|
424
430
|
} else if (goal.status === "active" && previous.status !== "active") {
|
|
425
|
-
requestTaskContext(pi, "resume", goal);
|
|
431
|
+
requestTaskContext(pi, "resume", goal, undefined, source === "command");
|
|
426
432
|
}
|
|
427
433
|
continuationQueuedFor = null;
|
|
428
434
|
backgroundDrainTracker = null;
|
|
@@ -522,8 +528,9 @@ export default function (pi: ExtensionAPI): void {
|
|
|
522
528
|
): { ok: true; goal: GoalSnapshot } | { ok: false; message: string } => {
|
|
523
529
|
const current = getGoal(ctx);
|
|
524
530
|
const held = current?.status === "active" && currentContinuationState(ctx, current.goalId)?.blocked === true;
|
|
525
|
-
if (!current
|
|
526
|
-
|
|
531
|
+
if (!current) return { ok: false, message: "No Goal is set." };
|
|
532
|
+
if (current.status !== "paused" && !held) {
|
|
533
|
+
return { ok: false, message: current.status === "active" ? "This Goal is already running." : `This Goal is ${current.status}.` };
|
|
527
534
|
}
|
|
528
535
|
if (source === "tool" && currentContinuationState(ctx, current.goalId)?.blocked) {
|
|
529
536
|
return { ok: false, message: "Only /goal resume or alt+g can reopen a no-progress hold." };
|
|
@@ -995,28 +1002,117 @@ export default function (pi: ExtensionAPI): void {
|
|
|
995
1002
|
if (latestSnapshot) collectIfPossible();
|
|
996
1003
|
});
|
|
997
1004
|
|
|
1005
|
+
// Both auto-start and manual resume must recover the same command and workflow checks.
|
|
1006
|
+
const prepareSavedGoal = (ctx: ExtensionContext, objective: string, previous?: GoalSnapshot, handoffOwner?: string) => {
|
|
1007
|
+
const invalid = validateObjective(objective);
|
|
1008
|
+
if (invalid) return invalid;
|
|
1009
|
+
const owner = getWorkflow(ctx);
|
|
1010
|
+
if (owner && !workflowAvailable(owner)) return `Restore /skill:${owner.name} before continuing its Todo.`;
|
|
1011
|
+
if (previous) {
|
|
1012
|
+
const blocker = resumeBlocker(previous, ctx);
|
|
1013
|
+
if (blocker) return blocker;
|
|
1014
|
+
}
|
|
1015
|
+
if (objective.startsWith("/") && (!previous?.command || previous.objective.trim() !== objective)) {
|
|
1016
|
+
return "Reinvoke the original command to continue this Goal.";
|
|
1017
|
+
}
|
|
1018
|
+
const command = previous?.command ?? (owner ? resolveGoalCommand(pi, `/skill:${owner.name}`) : null);
|
|
1019
|
+
const goal = createGoalSnapshot(objective, null, undefined, command ?? undefined);
|
|
1020
|
+
const restoredOwner = previous?.command ? goalWorkflowOwner(goal) : null;
|
|
1021
|
+
const completedOwner = previous?.command?.source === "skill"
|
|
1022
|
+
? currentWorkflowOwner(ctx.sessionManager.getBranch(), previous.goalId) : null;
|
|
1023
|
+
if ((completedOwner && (restoredOwner?.name !== completedOwner.name || restoredOwner.path !== completedOwner.path)) ||
|
|
1024
|
+
(handoffOwner && restoredOwner?.name !== handoffOwner) ||
|
|
1025
|
+
(restoredOwner && owner && (restoredOwner.name !== owner.name || restoredOwner.path !== owner.path))) {
|
|
1026
|
+
return "Reinvoke the original workflow to continue its Todo.";
|
|
1027
|
+
}
|
|
1028
|
+
return { goal, restore: owner ? null : restoredOwner };
|
|
1029
|
+
};
|
|
1030
|
+
|
|
998
1031
|
const unsubscribeOutcomeAccepted = pi.events.on(OUTCOME_ACCEPTED_EVENT, (value: unknown) => {
|
|
999
1032
|
const ctx = currentCtx;
|
|
1000
1033
|
const event = value as Partial<OutcomeAcceptedEvent> | null;
|
|
1001
|
-
if (!ctx || !event ||
|
|
1034
|
+
if (!preferences.autoStartFromOutcome || !ctx || !event ||
|
|
1002
1035
|
typeof event.sessionId !== "string" || event.sessionId !== ctx.sessionManager.getSessionId()) return;
|
|
1003
1036
|
const current = getGoal(ctx);
|
|
1004
1037
|
if (current && current.status !== "complete") return;
|
|
1005
1038
|
const reopenedGoal = current?.status === "complete" && current.goalId === event.reopenedGoalId ? current : undefined;
|
|
1006
|
-
if (
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1039
|
+
if (event.reopenedGoalId && !reopenedGoal) return;
|
|
1040
|
+
if (!canStartGoalFromOutcome(event.outcome, reopenedGoal)) return;
|
|
1041
|
+
const prepared = prepareSavedGoal(ctx, event.outcome.objective.trim(), reopenedGoal);
|
|
1042
|
+
if (typeof prepared === "string") return;
|
|
1043
|
+
setGoal(prepared.goal, ctx, "runtime", "bind");
|
|
1044
|
+
if (prepared.restore) recordWorkflow(prepared.restore, true);
|
|
1045
|
+
resetContinuationState(prepared.goal);
|
|
1046
|
+
});
|
|
1047
|
+
|
|
1048
|
+
const inspectGoal = (ctx: ExtensionContext) => {
|
|
1049
|
+
const current = getGoal(ctx);
|
|
1050
|
+
const saved = requestTaskContext(pi, "saved").savedGoal;
|
|
1051
|
+
const goal = current?.status === "complete" && saved && saved.goalId !== current.goalId ? null : current;
|
|
1052
|
+
const bound = saved && goal && saved.goalId === goal.goalId;
|
|
1053
|
+
const continuation = goal ? currentContinuationState(ctx, goal.goalId) : null;
|
|
1054
|
+
const permissionHold = goal ? currentPermissionHold(ctx, goal.goalId) : null;
|
|
1055
|
+
const stall = observeGoalStall(goal, continuation, { foregroundRunning, backgroundRunning: latestSnapshot?.backgroundRunning ?? false });
|
|
1056
|
+
const displayed = bound ? { ...goal, objective: saved.objective } : goal;
|
|
1057
|
+
return {
|
|
1058
|
+
content: [{ type: "text" as const, text: formatGoal(displayed, continuation, stall, preferences, permissionHold, saved) }],
|
|
1059
|
+
details: { goal: displayed ?? saved ?? null,
|
|
1060
|
+
executionStatus: goal?.status ?? (saved?.status === "active" ? "saved" : saved?.status ?? null),
|
|
1061
|
+
continuation, permissionHold, stall, preferences: { ...preferences },
|
|
1062
|
+
timing: goal ? goalTiming(goal) : null, hasGoal: !!(goal || saved) },
|
|
1063
|
+
};
|
|
1064
|
+
};
|
|
1065
|
+
|
|
1066
|
+
// Explicit controls can attach execution to a saved Goal or legacy checklist.
|
|
1067
|
+
// Pausing writes a paused snapshot directly, so it cannot queue a kickoff.
|
|
1068
|
+
const controlGoal = (action: "pause" | "resume", ctx: ExtensionContext, expectedSavedObjective?: string): void => {
|
|
1069
|
+
const current = getGoal(ctx);
|
|
1070
|
+
const { savedGoal, handoffOwner } = requestTaskContext(pi, "saved");
|
|
1071
|
+
if (expectedSavedObjective !== undefined &&
|
|
1072
|
+
(savedGoal?.objective !== expectedSavedObjective || savedGoal.status !== "active" || savedGoal.goalId)) return;
|
|
1073
|
+
const warn = (message: string) => ctx.ui.notify(message, "warning");
|
|
1074
|
+
if (savedGoal && (!current || current.goalId !== savedGoal.goalId)) {
|
|
1075
|
+
if (current && current.status !== "complete") {
|
|
1076
|
+
warn("A different Goal still owns execution. Inspect it with /goal. Use /goal clear to release it before switching tasks.");
|
|
1077
|
+
return;
|
|
1078
|
+
}
|
|
1079
|
+
if (savedGoal.status === "complete" || savedGoal.status === "cancelled") {
|
|
1080
|
+
warn(`This Goal is ${savedGoal.status}.`);
|
|
1081
|
+
return;
|
|
1082
|
+
}
|
|
1083
|
+
const previous = current?.status === "complete" && current.goalId === savedGoal.reopenedGoalId ? current : undefined;
|
|
1084
|
+
if (savedGoal.goalId || (savedGoal.reopenedGoalId && !previous)) {
|
|
1085
|
+
warn("This task has a previous execution or workflow binding. Reinvoke its original Goal or workflow to continue.");
|
|
1086
|
+
return;
|
|
1087
|
+
}
|
|
1088
|
+
const prepared = prepareSavedGoal(ctx, savedGoal.objective, previous, handoffOwner);
|
|
1089
|
+
if (typeof prepared === "string") { warn(prepared); return; }
|
|
1090
|
+
const { goal } = prepared;
|
|
1091
|
+
setGoal(action === "pause" ? goalWithStatus(goal, "paused") : goal, ctx, "command", "adopt");
|
|
1092
|
+
if (prepared.restore) recordWorkflow(prepared.restore, true);
|
|
1093
|
+
if (action === "resume") queueGoalContinuation(goal, ctx);
|
|
1094
|
+
} else if (action === "resume") {
|
|
1095
|
+
if (!current) { warn("No saved Goal or unfinished Todo to resume."); return; }
|
|
1096
|
+
const result = resumeGoal(ctx, "command");
|
|
1097
|
+
if (!result.ok) { warn(result.message); return; }
|
|
1098
|
+
} else {
|
|
1099
|
+
if (!current) { warn("No saved Goal or unfinished Todo to pause."); return; }
|
|
1100
|
+
if (current.status !== "active") { warn(`Goal is already ${current.status}.`); return; }
|
|
1101
|
+
setGoal(goalWithStatus(current, "paused"), ctx, "command");
|
|
1102
|
+
}
|
|
1103
|
+
if (action === "pause" && isForegroundBusy(ctx)) ctx.abort?.();
|
|
1104
|
+
notifyGoal(ctx, action === "pause" ? "Goal paused." : "Goal resumed.");
|
|
1105
|
+
};
|
|
1106
|
+
|
|
1107
|
+
const unsubscribePanelStart = pi.events.on(GOAL_PANEL_START_EVENT, value => {
|
|
1108
|
+
const request = value as GoalPanelStartRequest | undefined;
|
|
1109
|
+
if (request?.action === "probe") {
|
|
1110
|
+
request.available = true;
|
|
1111
|
+
return;
|
|
1112
|
+
}
|
|
1113
|
+
const ctx = currentCtx;
|
|
1114
|
+
if (request?.action !== "start" || !ctx?.hasUI || request.sessionId !== ctx.sessionManager.getSessionId()) return;
|
|
1115
|
+
if (typeof request.objective === "string") controlGoal("resume", ctx, request.objective);
|
|
1020
1116
|
});
|
|
1021
1117
|
|
|
1022
1118
|
const changePreference = async (ctx: ExtensionCommandContext, key: keyof GoalPreferences, enabled: boolean): Promise<void> => {
|
|
@@ -1044,21 +1140,17 @@ export default function (pi: ExtensionAPI): void {
|
|
|
1044
1140
|
ctx.ui.notify(`${formatPreferences(preferences)}\nPreferences: ${goalPreferencesPath()}`, "info");
|
|
1045
1141
|
}
|
|
1046
1142
|
};
|
|
1047
|
-
const contribution = { id: "goal", label: "Goal", command: "/goal settings", open: openSettings };
|
|
1048
1143
|
const autoStartControl = {
|
|
1049
1144
|
id: "goal-auto-start",
|
|
1050
|
-
label: "Auto-start
|
|
1145
|
+
label: "Auto-start Goals",
|
|
1051
1146
|
values: ["Off", "On"],
|
|
1052
1147
|
get: () => preferences.autoStartFromOutcome ? "On" : "Off",
|
|
1053
1148
|
async change(value: string, ctx: ExtensionCommandContext) {
|
|
1054
|
-
if (value !== "On" && value !== "Off") throw new Error("Invalid Auto-start
|
|
1149
|
+
if (value !== "On" && value !== "Off") throw new Error("Invalid Auto-start Goals mode.");
|
|
1055
1150
|
await changePreference(ctx, "autoStartFromOutcome", value === "On");
|
|
1056
1151
|
},
|
|
1057
1152
|
};
|
|
1058
|
-
const registerSettings = () =>
|
|
1059
|
-
pi.events.emit("harness-settings:register", contribution);
|
|
1060
|
-
pi.events.emit("harness-settings:register", autoStartControl);
|
|
1061
|
-
};
|
|
1153
|
+
const registerSettings = () => pi.events.emit("harness-settings:register", autoStartControl);
|
|
1062
1154
|
const unsubscribeSettingsRequest = pi.events.on("harness-settings:request", registerSettings);
|
|
1063
1155
|
registerSettings();
|
|
1064
1156
|
|
|
@@ -1075,10 +1167,11 @@ export default function (pi: ExtensionAPI): void {
|
|
|
1075
1167
|
await openSettings(ctx);
|
|
1076
1168
|
return;
|
|
1077
1169
|
}
|
|
1078
|
-
const [,
|
|
1170
|
+
const [, name, mode, ...extra] = trimmed.split(/\s+/);
|
|
1171
|
+
const setting = name === "auto-start-from-outcome" ? "auto-run" : name;
|
|
1079
1172
|
if (setting !== undefined && (!GOAL_SETTINGS.includes(setting as typeof GOAL_SETTINGS[number]) ||
|
|
1080
1173
|
(mode !== "on" && mode !== "off") || extra.length > 0)) {
|
|
1081
|
-
notifyGoal(ctx, "Usage: /goal settings [auto-continue|conversational-resume|pause-on-escape|auto-
|
|
1174
|
+
notifyGoal(ctx, "Usage: /goal settings [auto-continue|conversational-resume|pause-on-escape|auto-run on|off]", "warning");
|
|
1082
1175
|
return;
|
|
1083
1176
|
}
|
|
1084
1177
|
if (setting !== undefined) {
|
|
@@ -1097,30 +1190,12 @@ export default function (pi: ExtensionAPI): void {
|
|
|
1097
1190
|
}
|
|
1098
1191
|
|
|
1099
1192
|
if (!trimmed) {
|
|
1100
|
-
|
|
1101
|
-
// Inspection is always explicit user intent; show the full summary even while busy.
|
|
1102
|
-
ctx.ui.notify(formatGoal(current, continuation, observeGoalStall(current, continuation, { foregroundRunning }), preferences,
|
|
1103
|
-
current ? currentPermissionHold(ctx, current.goalId) : null), "info");
|
|
1104
|
-
return;
|
|
1105
|
-
}
|
|
1106
|
-
|
|
1107
|
-
if (trimmed === "pause") {
|
|
1108
|
-
if (!current || current.status !== "active") {
|
|
1109
|
-
notifyGoal(ctx, "Only active goals can be paused.", "warning");
|
|
1110
|
-
return;
|
|
1111
|
-
}
|
|
1112
|
-
setGoal(goalWithStatus(current, "paused"), ctx, "command");
|
|
1113
|
-
notifyGoal(ctx, "Goal paused.");
|
|
1193
|
+
ctx.ui.notify(inspectGoal(ctx).content[0]!.text, "info");
|
|
1114
1194
|
return;
|
|
1115
1195
|
}
|
|
1116
1196
|
|
|
1117
|
-
if (trimmed === "resume") {
|
|
1118
|
-
|
|
1119
|
-
if (!result.ok) {
|
|
1120
|
-
notifyGoal(ctx, result.message, current?.status === "paused" ? "error" : "warning");
|
|
1121
|
-
return;
|
|
1122
|
-
}
|
|
1123
|
-
notifyGoal(ctx, "Goal resumed.");
|
|
1197
|
+
if (trimmed === "pause" || trimmed === "resume") {
|
|
1198
|
+
controlGoal(trimmed, ctx);
|
|
1124
1199
|
return;
|
|
1125
1200
|
}
|
|
1126
1201
|
|
|
@@ -1170,23 +1245,14 @@ export default function (pi: ExtensionAPI): void {
|
|
|
1170
1245
|
promptSnippet: "Inspect the current goal, status, token budget, tokens used, active time, and total elapsed time.",
|
|
1171
1246
|
parameters: Type.Object({}),
|
|
1172
1247
|
async execute(_toolCallId, _params, _signal, _onUpdate, ctx) {
|
|
1173
|
-
|
|
1174
|
-
const continuation = goal ? currentContinuationState(ctx, goal.goalId) : null;
|
|
1175
|
-
const stall = observeGoalStall(goal, continuation, {
|
|
1176
|
-
foregroundRunning,
|
|
1177
|
-
backgroundRunning: latestSnapshot?.backgroundRunning ?? false,
|
|
1178
|
-
});
|
|
1179
|
-
return {
|
|
1180
|
-
content: [{ type: "text", text: formatGoal(goal, continuation, stall, preferences, goal ? currentPermissionHold(ctx, goal.goalId) : null) }],
|
|
1181
|
-
details: { goal, continuation, permissionHold: goal ? currentPermissionHold(ctx, goal.goalId) : null, stall, preferences: { ...preferences }, timing: goal ? goalTiming(goal) : null, hasGoal: goal !== null },
|
|
1182
|
-
};
|
|
1248
|
+
return inspectGoal(ctx);
|
|
1183
1249
|
},
|
|
1184
1250
|
});
|
|
1185
1251
|
|
|
1186
1252
|
pi.registerTool({
|
|
1187
1253
|
name: "update_goal",
|
|
1188
1254
|
label: "Update Goal",
|
|
1189
|
-
description: "Mark the Goal complete after verifying the requested outcome. For each recorded doneWhen criterion, supply its exact text and observed result in evidence. If
|
|
1255
|
+
description: "Mark the Goal complete after verifying the requested outcome. For each recorded doneWhen criterion, supply its exact text and observed result in evidence. If the Goal has no criteria, use its objective. A scheduler finish alone only confirms that workflow actions have settled.",
|
|
1190
1256
|
promptSnippet: "Mark the current Codex-style goal complete after verification.",
|
|
1191
1257
|
parameters: Type.Object({
|
|
1192
1258
|
evidence: Type.Optional(Type.Array(Type.Object({
|
|
@@ -1206,7 +1272,9 @@ export default function (pi: ExtensionAPI): void {
|
|
|
1206
1272
|
const current = getGoal(ctx);
|
|
1207
1273
|
if (!current) {
|
|
1208
1274
|
return {
|
|
1209
|
-
content: [{ type: "text", text: "
|
|
1275
|
+
content: [{ type: "text", text: requestTaskContext(pi, "saved").savedGoal
|
|
1276
|
+
? "For a saved Goal, record verified completion with update_todo and goal.status set to complete."
|
|
1277
|
+
: "No goal is set." }],
|
|
1210
1278
|
details: { ok: false, goal: null },
|
|
1211
1279
|
};
|
|
1212
1280
|
}
|
|
@@ -1288,11 +1356,10 @@ export default function (pi: ExtensionAPI): void {
|
|
|
1288
1356
|
});
|
|
1289
1357
|
|
|
1290
1358
|
pi.registerShortcut?.(GOAL_RESUME_SHORTCUT, {
|
|
1291
|
-
description: "
|
|
1359
|
+
description: "Start or resume work on the current Goal and Todo",
|
|
1292
1360
|
handler: (ctx) => {
|
|
1293
1361
|
currentCtx = ctx;
|
|
1294
|
-
|
|
1295
|
-
notifyGoal(ctx, result.ok ? "Goal resumed." : result.message, result.ok ? "info" : "warning");
|
|
1362
|
+
controlGoal("resume", ctx);
|
|
1296
1363
|
},
|
|
1297
1364
|
});
|
|
1298
1365
|
|
|
@@ -1460,10 +1527,9 @@ export default function (pi: ExtensionAPI): void {
|
|
|
1460
1527
|
try {
|
|
1461
1528
|
const owner = workflowOwnerFromSkill(skillName, command.sourceInfo.path, registeredSkillPath);
|
|
1462
1529
|
if (owner) {
|
|
1463
|
-
//
|
|
1464
|
-
// exactly as `/goal <this invocation>` would. The user's message already runs the skill.
|
|
1530
|
+
// The input already runs the skill. Opt-in supervision must not send it twice.
|
|
1465
1531
|
const existing = getGoal(ctx);
|
|
1466
|
-
if (AUTO_BIND_SKILLS.has(skillName) && (!existing || existing.status === "complete")) {
|
|
1532
|
+
if (preferences.autoStartFromOutcome && AUTO_BIND_SKILLS.has(skillName) && (!existing || existing.status === "complete")) {
|
|
1467
1533
|
try {
|
|
1468
1534
|
startOrReplaceGoal(event.text.trim(), null, ctx, "command", false);
|
|
1469
1535
|
} catch (error) {
|
|
@@ -1532,7 +1598,7 @@ export default function (pi: ExtensionAPI): void {
|
|
|
1532
1598
|
`${pausedInstruction}\n` + "While the goal is paused, this overrides the workflow instructions below: do not advance the workflow until the goal is resumed.\n\n",
|
|
1533
1599
|
`Active workflow: ${owner.name} (${owner.path}). Its task plan owns planning and the parent is a coordinator, not a product-code implementer. Follow the workflow instructions below, including on resumed turns:\n\n${instructions}`,
|
|
1534
1600
|
isPokeable(goal) && (harnessPresent
|
|
1535
|
-
? "Complete the goal only after the workflow completion audit and verification of every accepted
|
|
1601
|
+
? "Complete the goal only after the workflow completion audit and verification of every accepted Goal criterion."
|
|
1536
1602
|
: `Active objective: ${goal.objective}. Complete it only after the workflow completion audit.`),
|
|
1537
1603
|
questionInstruction && questionInstruction.trim(),
|
|
1538
1604
|
heldInstruction,
|
|
@@ -1741,6 +1807,7 @@ export default function (pi: ExtensionAPI): void {
|
|
|
1741
1807
|
pi.on("session_shutdown", async (_event, ctx) => {
|
|
1742
1808
|
if (typeof unsubscribeSettingsRequest === "function") unsubscribeSettingsRequest();
|
|
1743
1809
|
if (typeof unsubscribeOperationAdmission === "function") unsubscribeOperationAdmission();
|
|
1810
|
+
if (typeof unsubscribePanelStart === "function") unsubscribePanelStart();
|
|
1744
1811
|
if (typeof unsubscribeOutcomeAccepted === "function") unsubscribeOutcomeAccepted();
|
|
1745
1812
|
|
|
1746
1813
|
executionGeneration += 1;
|
package/src/settings-page.ts
CHANGED
|
@@ -6,7 +6,7 @@ const rows: { key: keyof GoalPreferences; label: string }[] = [
|
|
|
6
6
|
{ key: "autoContinue", label: "Automatic continuation" },
|
|
7
7
|
{ key: "conversationalResume", label: "Conversational resume" },
|
|
8
8
|
{ key: "pauseOnEscape", label: "Pause on Esc" },
|
|
9
|
-
{ key: "autoStartFromOutcome", label: "Auto-start
|
|
9
|
+
{ key: "autoStartFromOutcome", label: "Auto-start Goals" },
|
|
10
10
|
];
|
|
11
11
|
|
|
12
12
|
export function createGoalSettingsPage(
|
|
@@ -48,7 +48,7 @@ export function createGoalSettingsPage(
|
|
|
48
48
|
render(width: number) {
|
|
49
49
|
const w = Math.max(1, Math.floor(width));
|
|
50
50
|
const preferences = handlers.get();
|
|
51
|
-
const lines = [theme.fg("accent", theme.bold(" Goal settings")), ""];
|
|
51
|
+
const lines = [theme.fg("accent", theme.bold(" Goal execution settings")), ""];
|
|
52
52
|
rows.forEach(({ key, label }, index) => {
|
|
53
53
|
const selected = row === index;
|
|
54
54
|
const title = theme.fg(selected ? "accent" : "text", (selected ? "> " : " ") + label);
|
package/src/task-context.ts
CHANGED
|
@@ -4,10 +4,16 @@ import type { GoalSnapshot } from "./types.js";
|
|
|
4
4
|
/** Synchronous request bus shared with an installed `pi-better-harness` runtime. */
|
|
5
5
|
export const TASK_CONTEXT_EVENT = "pi-better-harness:task-context";
|
|
6
6
|
|
|
7
|
-
export type TaskContextAction = "inspect" | "audit" | "start" | "bind" | "pause" | "resume" | "complete";
|
|
7
|
+
export type TaskContextAction = "saved" | "adopt" | "inspect" | "audit" | "start" | "bind" | "pause" | "resume" | "complete";
|
|
8
8
|
|
|
9
9
|
export const OUTCOME_ACCEPTED_EVENT = "pi-better-harness:outcome-accepted";
|
|
10
10
|
|
|
11
|
+
/** The Todo panel probes once on installation and requests a start only on a user click. */
|
|
12
|
+
export const GOAL_PANEL_START_EVENT = "pi-better-goal:panel-start";
|
|
13
|
+
export type GoalPanelStartRequest =
|
|
14
|
+
| { action: "probe"; available?: boolean }
|
|
15
|
+
| { action: "start"; sessionId: string; objective: string };
|
|
16
|
+
|
|
11
17
|
export interface OutcomeAcceptedEvent {
|
|
12
18
|
sessionId: string;
|
|
13
19
|
reopenedGoalId?: string;
|
|
@@ -38,6 +44,10 @@ export function canStartGoalFromOutcome(value: unknown, reopenedGoal?: Pick<Goal
|
|
|
38
44
|
*/
|
|
39
45
|
export interface TaskContextRequest {
|
|
40
46
|
action: TaskContextAction;
|
|
47
|
+
savedGoal?: { objective: string; status: string; goalId?: string; reopenedGoalId?: string };
|
|
48
|
+
handoffOwner?: string;
|
|
49
|
+
manual?: boolean;
|
|
50
|
+
status?: GoalSnapshot["status"];
|
|
41
51
|
doneWhen?: readonly string[];
|
|
42
52
|
openSteps?: readonly string[];
|
|
43
53
|
/** Evidence retained by a finished workflow bound to this Goal. */
|
|
@@ -68,12 +78,15 @@ export function requestTaskContext(
|
|
|
68
78
|
action: TaskContextAction,
|
|
69
79
|
goal?: GoalSnapshot | null,
|
|
70
80
|
width?: number,
|
|
81
|
+
manual = false,
|
|
71
82
|
): TaskContextRequest {
|
|
72
83
|
const request: TaskContextRequest = { action };
|
|
84
|
+
if (manual) request.manual = true;
|
|
73
85
|
if (width !== undefined) request.width = width;
|
|
74
86
|
if (goal) {
|
|
75
87
|
request.goalId = goal.goalId;
|
|
76
|
-
if (action === "
|
|
88
|
+
if (action === "adopt") request.status = goal.status;
|
|
89
|
+
if (action === "start" || action === "bind" || action === "adopt") request.objective = goal.objective;
|
|
77
90
|
}
|
|
78
91
|
pi.events.emit(TASK_CONTEXT_EVENT, request);
|
|
79
92
|
return request;
|
package/src/workflow.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
2
|
import { parse } from "yaml";
|
|
3
|
+
import { EXTENSION_NAME } from "./types.js";
|
|
3
4
|
|
|
4
5
|
export const WORKFLOW_ENTRY_TYPE = "pi-better-workflow";
|
|
5
6
|
|
|
@@ -83,10 +84,15 @@ export function workflowEntry(owner: WorkflowOwner | null) {
|
|
|
83
84
|
: { version: 1, kind: "set" as const, owner };
|
|
84
85
|
}
|
|
85
86
|
|
|
86
|
-
export function currentWorkflowOwner(entries: Iterable<SessionEntryLike
|
|
87
|
+
export function currentWorkflowOwner(entries: Iterable<SessionEntryLike>, atGoalCompletion?: string): WorkflowOwner | null {
|
|
87
88
|
let owner: WorkflowOwner | null = null;
|
|
88
89
|
for (const entry of entries) {
|
|
89
|
-
if (entry.type !== "custom"
|
|
90
|
+
if (entry.type !== "custom") continue;
|
|
91
|
+
if (atGoalCompletion && entry.customType === EXTENSION_NAME) {
|
|
92
|
+
const data = entry.data as { kind?: string; goal?: { goalId?: string; status?: string } } | null;
|
|
93
|
+
if (data?.kind === "set" && data.goal?.goalId === atGoalCompletion && data.goal.status === "complete") return owner;
|
|
94
|
+
}
|
|
95
|
+
if (entry.customType !== WORKFLOW_ENTRY_TYPE) continue;
|
|
90
96
|
const data = entry.data as { version?: unknown; kind?: unknown; owner?: Partial<WorkflowOwner> } | null;
|
|
91
97
|
if (data?.version !== 1) continue;
|
|
92
98
|
if (data.kind === "clear") owner = null;
|
|
@@ -95,7 +101,7 @@ export function currentWorkflowOwner(entries: Iterable<SessionEntryLike>): Workf
|
|
|
95
101
|
owner = data.owner as WorkflowOwner;
|
|
96
102
|
}
|
|
97
103
|
}
|
|
98
|
-
return owner;
|
|
104
|
+
return atGoalCompletion ? null : owner;
|
|
99
105
|
}
|
|
100
106
|
|
|
101
107
|
export function skillCommandName(text: string): string | null {
|