pi-better-goal 0.13.3 → 0.14.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 +10 -3
- package/package.json +1 -1
- package/src/index.ts +46 -11
- package/src/preferences.ts +6 -3
- package/src/settings-page.ts +2 -1
- package/src/task-context.ts +25 -3
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ Use `pi-better-goal` when a Pi session should keep an explicit objective visible
|
|
|
13
13
|
## Core Features
|
|
14
14
|
|
|
15
15
|
- `/goal` runtime for starting, pausing, resuming, completing, and clearing the current objective.
|
|
16
|
-
- `/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.
|
|
16
|
+
- `/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 Goal** 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-start-from-outcome on|off`; bare `/goal settings` prints the saved values outside the TUI.
|
|
17
17
|
- `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.
|
|
18
18
|
- Background work that finishes while an `ask_user_question` is pending is handed to the agent right after the answer.
|
|
19
19
|
- A compact goal widget that does not replace Pi's footer.
|
|
@@ -28,13 +28,20 @@ When `pi-better-harness` is installed, its optional **Outcome & Todo** runtime o
|
|
|
28
28
|
|
|
29
29
|
`/goal` does not install, enable, or configure Outcome & Todo. Install Harness and enable **Outcome & Todo** in `/harness-settings` if you want that shared outcome and checklist. Without Harness, this package keeps its standalone prompts and behavior unchanged. The stored Goal objective remains the raw original trigger (for example, a bound command invocation) so `/goal resume` can re-enter the work; it is not the authoritative business outcome when Harness owns one.
|
|
30
30
|
|
|
31
|
+
With **Auto-start Goal** enabled, a successful explicit `update_todo` outcome save can create and bind a Goal. The outcome must be active, unbound, have a nonempty objective and at least one nonempty `doneWhen` acceptance criterion. All criteria must contain text. Slash-shaped command invocations do not qualify; invoke those commands explicitly. Outcome & Todo hooks must also be enabled. The existing outcome, boundaries and Todo stay intact. No kickoff message is queued for the already-running tool turn; subsequent idle/background continuation obeys its existing setting and gates.
|
|
32
|
+
|
|
33
|
+
Existing active, paused or budget-limited Goals are never replaced or resumed. Refinements of a bound outcome do not create another Goal. A new unbound task can start after the previous Goal completes. Session restore, branch navigation and enabling the preference do not replay saved outcomes; the next explicit qualifying save is the trigger. Completing a checklist or outcome does not complete the Goal.
|
|
34
|
+
|
|
35
|
+
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.
|
|
36
|
+
|
|
31
37
|
## Settings Storage
|
|
32
38
|
|
|
33
39
|
Goal preferences are saved only in Pi's global `~/.pi/agent/settings.json` under
|
|
34
40
|
`piBetterHarness.goal` (or `$PI_CODING_AGENT_DIR/settings.json` when overridden).
|
|
35
41
|
The payload retains `version: 1` and the boolean `autoContinue`,
|
|
36
|
-
`conversationalResume`, and `
|
|
37
|
-
|
|
42
|
+
`conversationalResume`, `pauseOnEscape`, and `autoStartFromOutcome` fields. The
|
|
43
|
+
first three default to `true`; `autoStartFromOutcome` defaults to `false`.
|
|
44
|
+
Updates preserve other Pi settings and other `piBetterHarness` keys.
|
|
38
45
|
|
|
39
46
|
On first read, an existing `extensions/pi-better-goal-preferences.json` in the
|
|
40
47
|
agent directory is validated and migrated when the global Goal key is absent.
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -45,7 +45,7 @@ import { collectSubagentActivity } from "./subagents.js";
|
|
|
45
45
|
import { currentWorkflowOwner, ISSUE_WORKFLOW_SKILLS, skillCommandName, workflowEntry, workflowOwnerFromSkill, WORKFLOW_ENTRY_TYPE } from "./workflow.js";
|
|
46
46
|
import { completionGate, pauseGate, schedulerWaitUntil, operationResumeSchedulerGate } from "./workflow-gates.js";
|
|
47
47
|
import { workflowRehydrateMessage, WORKFLOW_REHYDRATE_MESSAGE_TYPE } from "./rehydrate.js";
|
|
48
|
-
import { requestTaskContext } from "./task-context.js";
|
|
48
|
+
import { canStartGoalFromOutcome, OUTCOME_ACCEPTED_EVENT, requestTaskContext, type OutcomeAcceptedEvent } from "./task-context.js";
|
|
49
49
|
import {
|
|
50
50
|
EVENT_ACTIVITY,
|
|
51
51
|
EVENT_READY,
|
|
@@ -125,10 +125,10 @@ const GOAL_ACTIONS: readonly AutocompleteItem[] = [
|
|
|
125
125
|
{ value: "resume", label: "resume", description: "Resume the paused goal" },
|
|
126
126
|
{ value: "clear", label: "clear", description: "Remove the current goal" },
|
|
127
127
|
{ value: "complete", label: "complete", description: "Mark the current goal complete" },
|
|
128
|
-
{ value: "settings", label: "settings", description: "Inspect or persist goal continuation,
|
|
128
|
+
{ value: "settings", label: "settings", description: "Inspect or persist goal continuation, resume, Escape pause, and Outcome auto-start controls" },
|
|
129
129
|
];
|
|
130
130
|
|
|
131
|
-
const GOAL_SETTINGS = ["auto-continue", "conversational-resume", "pause-on-escape"] as const;
|
|
131
|
+
const GOAL_SETTINGS = ["auto-continue", "conversational-resume", "pause-on-escape", "auto-start-from-outcome"] as const;
|
|
132
132
|
|
|
133
133
|
export function goalArgumentCompletions(argumentPrefix: string): AutocompleteItem[] | null {
|
|
134
134
|
const prefix = argumentPrefix.trimStart().toLowerCase();
|
|
@@ -244,7 +244,7 @@ function formatGoal(
|
|
|
244
244
|
goal: GoalSnapshot | null,
|
|
245
245
|
continuation: ReturnType<typeof currentContinuationState> = null,
|
|
246
246
|
stall = observeGoalStall(goal, continuation),
|
|
247
|
-
preferences: GoalPreferences = { autoContinue: true, conversationalResume: true, pauseOnEscape: true },
|
|
247
|
+
preferences: GoalPreferences = { autoContinue: true, conversationalResume: true, pauseOnEscape: true, autoStartFromOutcome: false },
|
|
248
248
|
permissions?: PermissionHold | null,
|
|
249
249
|
): string {
|
|
250
250
|
const settings = formatPreferences(preferences);
|
|
@@ -285,6 +285,7 @@ function formatPreferences(preferences: GoalPreferences): string {
|
|
|
285
285
|
`Automatic continuation setting: ${preferences.autoContinue ? "on" : "off"}${WAKE_DISABLED ? " (disabled by environment)" : ""}`,
|
|
286
286
|
`Conversational resume setting: ${preferences.conversationalResume ? "on" : "off"}`,
|
|
287
287
|
`Pause on Esc setting: ${preferences.pauseOnEscape ? "on" : "off"}`,
|
|
288
|
+
`Auto-start Goal setting: ${preferences.autoStartFromOutcome ? "on" : "off"}`,
|
|
288
289
|
].join("\n");
|
|
289
290
|
}
|
|
290
291
|
|
|
@@ -341,7 +342,7 @@ export default function (pi: ExtensionAPI): void {
|
|
|
341
342
|
let terminalInputIsEditor: (() => boolean) | undefined;
|
|
342
343
|
let uiPromptDepth = 0;
|
|
343
344
|
let lastAgentEvidence: ContinuationEvidence | null = null;
|
|
344
|
-
let preferences: GoalPreferences = { autoContinue: true, conversationalResume: true, pauseOnEscape: true };
|
|
345
|
+
let preferences: GoalPreferences = { autoContinue: true, conversationalResume: true, pauseOnEscape: true, autoStartFromOutcome: false };
|
|
345
346
|
/** Background items active when each pending blocking question started, keyed by tool call id. */
|
|
346
347
|
const pendingQuestions = new Map<string, Map<string, BackgroundWorkItem>>();
|
|
347
348
|
|
|
@@ -396,7 +397,7 @@ export default function (pi: ExtensionAPI): void {
|
|
|
396
397
|
ctx.ui.notify(message, type);
|
|
397
398
|
};
|
|
398
399
|
|
|
399
|
-
const setGoal = (goal: GoalSnapshot, ctx: ExtensionContext, source: GoalEntrySource): void => {
|
|
400
|
+
const setGoal = (goal: GoalSnapshot, ctx: ExtensionContext, source: GoalEntrySource, bindOutcome = false): void => {
|
|
400
401
|
executionGeneration += 1;
|
|
401
402
|
lastAgentEvidence = null;
|
|
402
403
|
const previous = getGoal(ctx);
|
|
@@ -405,7 +406,7 @@ export default function (pi: ExtensionAPI): void {
|
|
|
405
406
|
// Bridge lifecycle after the raw Goal entry is durable. Harness may own the
|
|
406
407
|
// structured outcome, but Goal still owns its trigger, clocks, pauses, and wakes.
|
|
407
408
|
if (!previous || previous.goalId !== goal.goalId) {
|
|
408
|
-
requestTaskContext(pi, "start", goal);
|
|
409
|
+
requestTaskContext(pi, bindOutcome ? "bind" : "start", goal);
|
|
409
410
|
} else if (goal.status === "complete") {
|
|
410
411
|
requestTaskContext(pi, "complete", goal);
|
|
411
412
|
} else if (goal.status === "paused" || goal.status === "budgetLimited") {
|
|
@@ -897,6 +898,24 @@ export default function (pi: ExtensionAPI): void {
|
|
|
897
898
|
if (latestSnapshot) collectIfPossible();
|
|
898
899
|
});
|
|
899
900
|
|
|
901
|
+
const unsubscribeOutcomeAccepted = pi.events.on(OUTCOME_ACCEPTED_EVENT, (value: unknown) => {
|
|
902
|
+
const ctx = currentCtx;
|
|
903
|
+
const event = value as Partial<OutcomeAcceptedEvent> | null;
|
|
904
|
+
if (!preferences.autoStartFromOutcome || !ctx || !event ||
|
|
905
|
+
typeof event.sessionId !== "string" || event.sessionId !== ctx.sessionManager.getSessionId() ||
|
|
906
|
+
!canStartGoalFromOutcome(event.outcome)) return;
|
|
907
|
+
const current = getGoal(ctx);
|
|
908
|
+
if (current && current.status !== "complete") return;
|
|
909
|
+
const objective = event.outcome.objective.trim();
|
|
910
|
+
if (validateObjective(objective)) return;
|
|
911
|
+
const owner = getWorkflow(ctx);
|
|
912
|
+
if (owner && !workflowAvailable(owner)) return;
|
|
913
|
+
const command = owner ? resolveGoalCommand(pi, `/skill:${owner.name}`) : null;
|
|
914
|
+
const goal = createGoalSnapshot(objective, null, undefined, command ?? undefined);
|
|
915
|
+
setGoal(goal, ctx, "runtime", true);
|
|
916
|
+
resetContinuationState(goal);
|
|
917
|
+
});
|
|
918
|
+
|
|
900
919
|
const changePreference = async (ctx: ExtensionCommandContext, key: keyof GoalPreferences, enabled: boolean): Promise<void> => {
|
|
901
920
|
const previous = preferences;
|
|
902
921
|
preferences = writeGoalPreference(key, enabled);
|
|
@@ -923,7 +942,20 @@ export default function (pi: ExtensionAPI): void {
|
|
|
923
942
|
}
|
|
924
943
|
};
|
|
925
944
|
const contribution = { id: "goal", label: "Goal", command: "/goal settings", open: openSettings };
|
|
926
|
-
const
|
|
945
|
+
const autoStartControl = {
|
|
946
|
+
id: "goal-auto-start",
|
|
947
|
+
label: "Auto-start Goal",
|
|
948
|
+
values: ["Off", "On"],
|
|
949
|
+
get: () => preferences.autoStartFromOutcome ? "On" : "Off",
|
|
950
|
+
async change(value: string, ctx: ExtensionCommandContext) {
|
|
951
|
+
if (value !== "On" && value !== "Off") throw new Error("Invalid Auto-start Goal mode.");
|
|
952
|
+
await changePreference(ctx, "autoStartFromOutcome", value === "On");
|
|
953
|
+
},
|
|
954
|
+
};
|
|
955
|
+
const registerSettings = () => {
|
|
956
|
+
pi.events.emit("harness-settings:register", contribution);
|
|
957
|
+
pi.events.emit("harness-settings:register", autoStartControl);
|
|
958
|
+
};
|
|
927
959
|
const unsubscribeSettingsRequest = pi.events.on("harness-settings:request", registerSettings);
|
|
928
960
|
registerSettings();
|
|
929
961
|
|
|
@@ -943,13 +975,14 @@ export default function (pi: ExtensionAPI): void {
|
|
|
943
975
|
const [, setting, mode, ...extra] = trimmed.split(/\s+/);
|
|
944
976
|
if (setting !== undefined && (!GOAL_SETTINGS.includes(setting as typeof GOAL_SETTINGS[number]) ||
|
|
945
977
|
(mode !== "on" && mode !== "off") || extra.length > 0)) {
|
|
946
|
-
notifyGoal(ctx, "Usage: /goal settings [auto-continue|conversational-resume|pause-on-escape on|off]", "warning");
|
|
978
|
+
notifyGoal(ctx, "Usage: /goal settings [auto-continue|conversational-resume|pause-on-escape|auto-start-from-outcome on|off]", "warning");
|
|
947
979
|
return;
|
|
948
980
|
}
|
|
949
981
|
if (setting !== undefined) {
|
|
950
982
|
try {
|
|
951
983
|
const key = setting === "auto-continue" ? "autoContinue"
|
|
952
|
-
: setting === "conversational-resume" ? "conversationalResume"
|
|
984
|
+
: setting === "conversational-resume" ? "conversationalResume"
|
|
985
|
+
: setting === "pause-on-escape" ? "pauseOnEscape" : "autoStartFromOutcome";
|
|
953
986
|
await changePreference(ctx, key, mode === "on");
|
|
954
987
|
} catch (error) {
|
|
955
988
|
notifyGoal(ctx, error instanceof Error ? error.message : String(error), "error");
|
|
@@ -1232,6 +1265,7 @@ export default function (pi: ExtensionAPI): void {
|
|
|
1232
1265
|
try {
|
|
1233
1266
|
preferences = readGoalPreferences();
|
|
1234
1267
|
} catch (error) {
|
|
1268
|
+
preferences = { ...preferences, autoStartFromOutcome: false };
|
|
1235
1269
|
notifyGoal(ctx, error instanceof Error ? error.message : String(error), "error");
|
|
1236
1270
|
}
|
|
1237
1271
|
const restoredGoal = getGoal(ctx);
|
|
@@ -1559,6 +1593,7 @@ export default function (pi: ExtensionAPI): void {
|
|
|
1559
1593
|
pi.on("session_shutdown", async (_event, ctx) => {
|
|
1560
1594
|
if (typeof unsubscribeSettingsRequest === "function") unsubscribeSettingsRequest();
|
|
1561
1595
|
if (typeof unsubscribeOperationAdmission === "function") unsubscribeOperationAdmission();
|
|
1596
|
+
if (typeof unsubscribeOutcomeAccepted === "function") unsubscribeOutcomeAccepted();
|
|
1562
1597
|
|
|
1563
1598
|
executionGeneration += 1;
|
|
1564
1599
|
sessionGeneration += 1;
|
|
@@ -1580,4 +1615,4 @@ export default function (pi: ExtensionAPI): void {
|
|
|
1580
1615
|
// Best-effort cleanup.
|
|
1581
1616
|
}
|
|
1582
1617
|
});
|
|
1583
|
-
}
|
|
1618
|
+
}
|
package/src/preferences.ts
CHANGED
|
@@ -11,6 +11,7 @@ export interface GoalPreferences {
|
|
|
11
11
|
autoContinue: boolean;
|
|
12
12
|
conversationalResume: boolean;
|
|
13
13
|
pauseOnEscape: boolean;
|
|
14
|
+
autoStartFromOutcome: boolean;
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
export interface GoalPreferenceSeams extends HarnessSettingsSeams {}
|
|
@@ -39,19 +40,21 @@ export function readGoalPreferences(seams: GoalPreferenceSeams = {}): GoalPrefer
|
|
|
39
40
|
|
|
40
41
|
function parseGoalPreferences(parsed: unknown, path: string): GoalPreferences {
|
|
41
42
|
if (parsed === undefined) {
|
|
42
|
-
return { autoContinue: true, conversationalResume: true, pauseOnEscape: true };
|
|
43
|
+
return { autoContinue: true, conversationalResume: true, pauseOnEscape: true, autoStartFromOutcome: false };
|
|
43
44
|
}
|
|
44
45
|
const value = parsed as Partial<GoalPreferences> & { version?: unknown } | null;
|
|
45
46
|
if (value?.version !== 1 ||
|
|
46
47
|
(value.autoContinue !== undefined && typeof value.autoContinue !== "boolean") ||
|
|
47
48
|
(value.conversationalResume !== undefined && typeof value.conversationalResume !== "boolean") ||
|
|
48
|
-
(value.pauseOnEscape !== undefined && typeof value.pauseOnEscape !== "boolean")
|
|
49
|
-
|
|
49
|
+
(value.pauseOnEscape !== undefined && typeof value.pauseOnEscape !== "boolean") ||
|
|
50
|
+
(value.autoStartFromOutcome !== undefined && typeof value.autoStartFromOutcome !== "boolean")) {
|
|
51
|
+
throw new Error(`Goal preferences at ${path} must contain version 1 and boolean autoContinue/conversationalResume/pauseOnEscape/autoStartFromOutcome settings.`);
|
|
50
52
|
}
|
|
51
53
|
return {
|
|
52
54
|
autoContinue: value.autoContinue ?? true,
|
|
53
55
|
conversationalResume: value.conversationalResume ?? true,
|
|
54
56
|
pauseOnEscape: value.pauseOnEscape ?? true,
|
|
57
|
+
autoStartFromOutcome: value.autoStartFromOutcome ?? false,
|
|
55
58
|
};
|
|
56
59
|
}
|
|
57
60
|
|
package/src/settings-page.ts
CHANGED
|
@@ -6,6 +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 Goal" },
|
|
9
10
|
];
|
|
10
11
|
|
|
11
12
|
export function createGoalSettingsPage(
|
|
@@ -65,4 +66,4 @@ export function createGoalSettingsPage(
|
|
|
65
66
|
return lines.map((line) => truncateToWidth(line, w, ""));
|
|
66
67
|
},
|
|
67
68
|
};
|
|
68
|
-
}
|
|
69
|
+
}
|
package/src/task-context.ts
CHANGED
|
@@ -4,7 +4,29 @@ 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" | "start" | "pause" | "resume" | "complete";
|
|
7
|
+
export type TaskContextAction = "inspect" | "start" | "bind" | "pause" | "resume" | "complete";
|
|
8
|
+
|
|
9
|
+
export const OUTCOME_ACCEPTED_EVENT = "pi-better-harness:outcome-accepted";
|
|
10
|
+
|
|
11
|
+
export interface OutcomeAcceptedEvent {
|
|
12
|
+
sessionId: string;
|
|
13
|
+
outcome: {
|
|
14
|
+
objective: string;
|
|
15
|
+
doneWhen?: readonly string[];
|
|
16
|
+
status: string;
|
|
17
|
+
goalId?: string;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Only explicit, actionable outcomes qualify; prose and restored state do not. */
|
|
22
|
+
export function canStartGoalFromOutcome(value: unknown): value is OutcomeAcceptedEvent["outcome"] {
|
|
23
|
+
if (!value || typeof value !== "object") return false;
|
|
24
|
+
const outcome = value as Partial<OutcomeAcceptedEvent["outcome"]>;
|
|
25
|
+
return outcome.status === "active" && outcome.goalId === undefined &&
|
|
26
|
+
typeof outcome.objective === "string" && !!outcome.objective.trim() && !outcome.objective.trim().startsWith("/") &&
|
|
27
|
+
Array.isArray(outcome.doneWhen) && outcome.doneWhen.length > 0 &&
|
|
28
|
+
outcome.doneWhen.every(item => typeof item === "string" && !!item.trim());
|
|
29
|
+
}
|
|
8
30
|
|
|
9
31
|
/**
|
|
10
32
|
* Mutable request. A present Harness runtime sets `enabled` to a boolean even
|
|
@@ -16,7 +38,7 @@ export interface TaskContextRequest {
|
|
|
16
38
|
goalId?: string;
|
|
17
39
|
/** Current widget width on a visual ownership inspection. */
|
|
18
40
|
width?: number;
|
|
19
|
-
/** The raw original goal trigger; only start requests carry it. */
|
|
41
|
+
/** The raw original goal trigger; only start/bind requests carry it. */
|
|
20
42
|
objective?: string;
|
|
21
43
|
/** Hooks authority: a present Harness runtime sets this even when Outcome & Todo is off. */
|
|
22
44
|
enabled?: boolean;
|
|
@@ -43,7 +65,7 @@ export function requestTaskContext(
|
|
|
43
65
|
if (width !== undefined) request.width = width;
|
|
44
66
|
if (goal) {
|
|
45
67
|
request.goalId = goal.goalId;
|
|
46
|
-
if (action === "start") request.objective = goal.objective;
|
|
68
|
+
if (action === "start" || action === "bind") request.objective = goal.objective;
|
|
47
69
|
}
|
|
48
70
|
pi.events.emit(TASK_CONTEXT_EVENT, request);
|
|
49
71
|
return request;
|