pi-better-goal 0.15.0 → 0.16.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 +4 -0
- package/package.json +1 -1
- package/src/index.ts +34 -8
- package/src/task-context.ts +12 -6
package/README.md
CHANGED
|
@@ -50,6 +50,10 @@ With **Auto-start Goal** enabled, a successful explicit `update_todo` outcome sa
|
|
|
50
50
|
|
|
51
51
|
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.
|
|
52
52
|
|
|
53
|
+
For an active Goal with a bound Outcome, the agent completes both through `update_goal`. It supplies an `evidence` array with one `{criterion, result}` per `doneWhen` entry, using the Outcome objective if no criteria were recorded. Each result should identify the observed result and its source. Open Todo steps and open items on an associated work ledger block completion. These checks also apply after a workflow scheduler reports `finish`. The user can still complete a Goal manually with `/goal complete`.
|
|
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
|
+
|
|
53
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.
|
|
54
58
|
|
|
55
59
|
## Settings Storage
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -998,18 +998,24 @@ export default function (pi: ExtensionAPI): void {
|
|
|
998
998
|
const unsubscribeOutcomeAccepted = pi.events.on(OUTCOME_ACCEPTED_EVENT, (value: unknown) => {
|
|
999
999
|
const ctx = currentCtx;
|
|
1000
1000
|
const event = value as Partial<OutcomeAcceptedEvent> | null;
|
|
1001
|
-
if (!
|
|
1002
|
-
typeof event.sessionId !== "string" || event.sessionId !== ctx.sessionManager.getSessionId()
|
|
1003
|
-
!canStartGoalFromOutcome(event.outcome)) return;
|
|
1001
|
+
if (!ctx || !event ||
|
|
1002
|
+
typeof event.sessionId !== "string" || event.sessionId !== ctx.sessionManager.getSessionId()) return;
|
|
1004
1003
|
const current = getGoal(ctx);
|
|
1005
1004
|
if (current && current.status !== "complete") return;
|
|
1005
|
+
const reopenedGoal = current?.status === "complete" && current.goalId === event.reopenedGoalId ? current : undefined;
|
|
1006
|
+
if ((!reopenedGoal && !preferences.autoStartFromOutcome) || !canStartGoalFromOutcome(event.outcome, reopenedGoal)) return;
|
|
1006
1007
|
const objective = event.outcome.objective.trim();
|
|
1007
1008
|
if (validateObjective(objective)) return;
|
|
1008
1009
|
const owner = getWorkflow(ctx);
|
|
1009
1010
|
if (owner && !workflowAvailable(owner)) return;
|
|
1010
|
-
const
|
|
1011
|
+
const retainedCommand = objective.startsWith("/") ? reopenedGoal?.command : undefined;
|
|
1012
|
+
const command = retainedCommand ?? (owner ? resolveGoalCommand(pi, `/skill:${owner.name}`) : null);
|
|
1011
1013
|
const goal = createGoalSnapshot(objective, null, undefined, command ?? undefined);
|
|
1012
1014
|
setGoal(goal, ctx, "runtime", true);
|
|
1015
|
+
if (retainedCommand) {
|
|
1016
|
+
const retainedOwner = goalWorkflowOwner(goal);
|
|
1017
|
+
if (retainedOwner && (owner?.name !== retainedOwner.name || owner?.path !== retainedOwner.path)) recordWorkflow(retainedOwner);
|
|
1018
|
+
}
|
|
1013
1019
|
resetContinuationState(goal);
|
|
1014
1020
|
});
|
|
1015
1021
|
|
|
@@ -1180,13 +1186,17 @@ export default function (pi: ExtensionAPI): void {
|
|
|
1180
1186
|
pi.registerTool({
|
|
1181
1187
|
name: "update_goal",
|
|
1182
1188
|
label: "Update Goal",
|
|
1183
|
-
description: "Mark the
|
|
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 a bound Outcome has no criteria, use its objective. A scheduler finish alone only confirms that workflow actions have settled.",
|
|
1184
1190
|
promptSnippet: "Mark the current Codex-style goal complete after verification.",
|
|
1185
1191
|
parameters: Type.Object({
|
|
1192
|
+
evidence: Type.Optional(Type.Array(Type.Object({
|
|
1193
|
+
criterion: Type.String(),
|
|
1194
|
+
result: Type.String({ description: "Observed result and its source, such as a test run, deployment receipt, or issue state." }),
|
|
1195
|
+
}))),
|
|
1186
1196
|
status: Type.String({ description: "Only 'complete' is accepted." }),
|
|
1187
1197
|
}),
|
|
1188
1198
|
async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
|
|
1189
|
-
const input = params as { status: string };
|
|
1199
|
+
const input = params as { status: string; evidence?: Array<{ criterion: string; result: string }> };
|
|
1190
1200
|
if (input.status !== "complete") {
|
|
1191
1201
|
return {
|
|
1192
1202
|
content: [{ type: "text", text: "Only status:'complete' is accepted." }],
|
|
@@ -1214,7 +1224,23 @@ export default function (pi: ExtensionAPI): void {
|
|
|
1214
1224
|
details: { ok: false, goal: current, due: verdict.due },
|
|
1215
1225
|
};
|
|
1216
1226
|
}
|
|
1217
|
-
const
|
|
1227
|
+
const latest = getGoal(ctx);
|
|
1228
|
+
if (latest?.goalId !== current.goalId || latest.status !== current.status) {
|
|
1229
|
+
return { content: [{ type: "text", text: "Goal changed during the completion check. Read the current Goal." }], details: { ok: false, goal: latest } };
|
|
1230
|
+
}
|
|
1231
|
+
const audit = requestTaskContext(pi, "audit", current);
|
|
1232
|
+
const criteria = audit.doneWhen?.length ? audit.doneWhen : audit.objective ? [audit.objective] : [];
|
|
1233
|
+
const missing = criteria.filter(criterion => !input.evidence?.some(item => item.criterion === criterion && item.result.trim()));
|
|
1234
|
+
if (audit.ledgerBlocker || audit.openSteps?.length || missing.length) {
|
|
1235
|
+
const message = [
|
|
1236
|
+
"Verify the requested outcome before completing the Goal.",
|
|
1237
|
+
...(audit.ledgerBlocker ? [audit.ledgerBlocker] : []),
|
|
1238
|
+
...(audit.openSteps ?? []).map(step => `Open Todo: ${step}`),
|
|
1239
|
+
...missing.map(criterion => `Missing evidence: ${criterion}`),
|
|
1240
|
+
].join("\n");
|
|
1241
|
+
return { content: [{ type: "text", text: message }], details: { ok: false, goal: current, missing, openSteps: audit.openSteps } };
|
|
1242
|
+
}
|
|
1243
|
+
const goal = goalWithStatus(latest, "complete");
|
|
1218
1244
|
setGoal(goal, ctx, "tool");
|
|
1219
1245
|
if (getWorkflow(ctx)) recordWorkflow(null);
|
|
1220
1246
|
const warning = verdict?.allow ? verdict.warning : undefined;
|
|
@@ -1505,7 +1531,7 @@ export default function (pi: ExtensionAPI): void {
|
|
|
1505
1531
|
`${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",
|
|
1506
1532
|
`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}`,
|
|
1507
1533
|
isPokeable(goal) && (harnessPresent
|
|
1508
|
-
? "Complete the goal only after the workflow completion audit."
|
|
1534
|
+
? "Complete the goal only after the workflow completion audit and verification of every accepted Outcome criterion."
|
|
1509
1535
|
: `Active objective: ${goal.objective}. Complete it only after the workflow completion audit.`),
|
|
1510
1536
|
questionInstruction && questionInstruction.trim(),
|
|
1511
1537
|
heldInstruction,
|
package/src/task-context.ts
CHANGED
|
@@ -4,12 +4,13 @@ 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" | "bind" | "pause" | "resume" | "complete";
|
|
7
|
+
export type TaskContextAction = "inspect" | "audit" | "start" | "bind" | "pause" | "resume" | "complete";
|
|
8
8
|
|
|
9
9
|
export const OUTCOME_ACCEPTED_EVENT = "pi-better-harness:outcome-accepted";
|
|
10
10
|
|
|
11
11
|
export interface OutcomeAcceptedEvent {
|
|
12
12
|
sessionId: string;
|
|
13
|
+
reopenedGoalId?: string;
|
|
13
14
|
outcome: {
|
|
14
15
|
objective: string;
|
|
15
16
|
doneWhen?: readonly string[];
|
|
@@ -19,13 +20,15 @@ export interface OutcomeAcceptedEvent {
|
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
/** Only explicit, actionable outcomes qualify; prose and restored state do not. */
|
|
22
|
-
export function canStartGoalFromOutcome(value: unknown): value is OutcomeAcceptedEvent["outcome"] {
|
|
23
|
+
export function canStartGoalFromOutcome(value: unknown, reopenedGoal?: Pick<GoalSnapshot, "objective" | "command">): value is OutcomeAcceptedEvent["outcome"] {
|
|
23
24
|
if (!value || typeof value !== "object") return false;
|
|
24
25
|
const outcome = value as Partial<OutcomeAcceptedEvent["outcome"]>;
|
|
26
|
+
const objective = typeof outcome.objective === "string" ? outcome.objective.trim() : "";
|
|
27
|
+
const retainsCommand = reopenedGoal?.command && reopenedGoal.objective.trim() === objective;
|
|
25
28
|
return outcome.status === "active" && outcome.goalId === undefined &&
|
|
26
|
-
|
|
27
|
-
Array.isArray(outcome.doneWhen) && outcome.doneWhen.length > 0 &&
|
|
28
|
-
|
|
29
|
+
!!objective && (!objective.startsWith("/") || !!retainsCommand) &&
|
|
30
|
+
(reopenedGoal !== undefined || (Array.isArray(outcome.doneWhen) && outcome.doneWhen.length > 0 &&
|
|
31
|
+
outcome.doneWhen.every(item => typeof item === "string" && !!item.trim())));
|
|
29
32
|
}
|
|
30
33
|
|
|
31
34
|
/**
|
|
@@ -35,10 +38,13 @@ export function canStartGoalFromOutcome(value: unknown): value is OutcomeAccepte
|
|
|
35
38
|
*/
|
|
36
39
|
export interface TaskContextRequest {
|
|
37
40
|
action: TaskContextAction;
|
|
41
|
+
doneWhen?: readonly string[];
|
|
42
|
+
openSteps?: readonly string[];
|
|
43
|
+
ledgerBlocker?: string;
|
|
38
44
|
goalId?: string;
|
|
39
45
|
/** Current widget width on a visual ownership inspection. */
|
|
40
46
|
width?: number;
|
|
41
|
-
/** The raw original goal trigger;
|
|
47
|
+
/** The raw original goal trigger; returned as the refined objective on audit. */
|
|
42
48
|
objective?: string;
|
|
43
49
|
/** Hooks authority: a present Harness runtime sets this even when Outcome & Todo is off. */
|
|
44
50
|
enabled?: boolean;
|