pi-better-goal 0.18.2 → 0.18.3
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/package.json +1 -1
- package/src/index.ts +27 -10
- package/src/task-context.ts +2 -0
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1060,21 +1060,38 @@ export default function (pi: ExtensionAPI): void {
|
|
|
1060
1060
|
return { goal, restore: restoredOwner, plan };
|
|
1061
1061
|
};
|
|
1062
1062
|
|
|
1063
|
-
const
|
|
1064
|
-
const
|
|
1065
|
-
const event = value as Partial<OutcomeAcceptedEvent> | null;
|
|
1066
|
-
if (!preferences.autoStartFromOutcome || !ctx || !event ||
|
|
1067
|
-
typeof event.sessionId !== "string" || event.sessionId !== ctx.sessionManager.getSessionId()) return;
|
|
1063
|
+
const acceptOutcome = (ctx: ExtensionContext, event: OutcomeAcceptedEvent): string => {
|
|
1064
|
+
const saved = event.outcome;
|
|
1068
1065
|
const current = getGoal(ctx);
|
|
1069
|
-
if (current && current.
|
|
1066
|
+
if (current && current.goalId === saved.goalId) {
|
|
1067
|
+
if (current.status === "active") return "Goal is running.";
|
|
1068
|
+
if (current.status === "budgetLimited") return "Goal reached its token budget.";
|
|
1069
|
+
return `Goal ${current.status}.`;
|
|
1070
|
+
}
|
|
1071
|
+
if (saved.status !== "active") return `Goal ${saved.status}.`;
|
|
1072
|
+
if (current && current.status !== "complete") return "Goal saved. Another Goal owns execution. Inspect it with /goal.";
|
|
1070
1073
|
const reopenedGoal = current?.status === "complete" && current.goalId === event.reopenedGoalId ? current : undefined;
|
|
1071
|
-
if (event.reopenedGoalId && !reopenedGoal) return;
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1074
|
+
if (saved.goalId || (event.reopenedGoalId && !reopenedGoal)) return "Goal saved. Reinvoke its original Goal or workflow to continue.";
|
|
1075
|
+
const objective = saved.objective.trim();
|
|
1076
|
+
if (!canStartGoalFromOutcome(saved, reopenedGoal)) {
|
|
1077
|
+
if (objective.startsWith("/")) return "Goal saved. Reinvoke the original command to continue.";
|
|
1078
|
+
if (preferences.autoStartFromOutcome) return "Goal saved. Auto-start requires completion criteria in goal.doneWhen. Use /goal resume to start it manually.";
|
|
1079
|
+
}
|
|
1080
|
+
if (!preferences.autoStartFromOutcome) return "Goal saved. Use /goal resume to start it.";
|
|
1081
|
+
const prepared = prepareSavedGoal(ctx, objective, reopenedGoal);
|
|
1082
|
+
if (typeof prepared === "string") return `Goal saved. ${prepared}`;
|
|
1075
1083
|
if (prepared.restore) recordWorkflow(prepared.restore, prepared.plan);
|
|
1076
1084
|
setGoal(prepared.goal, ctx, "runtime", "bind");
|
|
1077
1085
|
resetContinuationState(prepared.goal);
|
|
1086
|
+
return "Goal is running.";
|
|
1087
|
+
};
|
|
1088
|
+
|
|
1089
|
+
const unsubscribeOutcomeAccepted = pi.events.on(OUTCOME_ACCEPTED_EVENT, (value: unknown) => {
|
|
1090
|
+
const ctx = currentCtx;
|
|
1091
|
+
const event = value as OutcomeAcceptedEvent | null;
|
|
1092
|
+
if (!ctx || typeof event?.outcome?.objective !== "string" ||
|
|
1093
|
+
typeof event.sessionId !== "string" || event.sessionId !== ctx.sessionManager.getSessionId()) return;
|
|
1094
|
+
event.feedback = acceptOutcome(ctx, event);
|
|
1078
1095
|
});
|
|
1079
1096
|
|
|
1080
1097
|
const inspectGoal = (ctx: ExtensionContext) => {
|
package/src/task-context.ts
CHANGED
|
@@ -16,6 +16,8 @@ export type GoalPanelStartRequest =
|
|
|
16
16
|
|
|
17
17
|
export interface OutcomeAcceptedEvent {
|
|
18
18
|
sessionId: string;
|
|
19
|
+
/** The Goal extension fills this in synchronously for the update_todo reply. */
|
|
20
|
+
feedback?: string;
|
|
19
21
|
reopenedGoalId?: string;
|
|
20
22
|
outcome: {
|
|
21
23
|
objective: string;
|