@narumitw/pi-goal 0.54.4 → 0.54.6
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 +41 -166
- package/dist/chunks/{chunk-UQRRW4CY.js → chunk-6T3MHA45.js} +7 -6
- package/dist/chunks/chunk-6T3MHA45.js.map +7 -0
- package/dist/chunks/{chunk-QWIUWKRW.js → chunk-WLIH47XO.js} +57 -77
- package/dist/chunks/chunk-WLIH47XO.js.map +7 -0
- package/dist/chunks/{menu-WEFDREGC.js → menu-RGCRCQJK.js} +7 -22
- package/dist/chunks/menu-RGCRCQJK.js.map +7 -0
- package/dist/chunks/{settings-ui-MVYTTBHW.js → settings-ui-BAWNTINU.js} +6 -18
- package/dist/chunks/settings-ui-BAWNTINU.js.map +7 -0
- package/dist/index.ts +92 -126
- package/dist/index.ts.map +2 -2
- package/docs/managing-goals.md +47 -0
- package/docs/settings.md +91 -0
- package/package.json +55 -55
- package/src/accounting.ts +62 -66
- package/src/command-registration.ts +104 -102
- package/src/command.ts +101 -112
- package/src/commands.ts +465 -501
- package/src/errors.ts +127 -122
- package/src/goal-contract.ts +64 -64
- package/src/goal.ts +25 -25
- package/src/lifecycle.ts +615 -628
- package/src/markers.ts +6 -6
- package/src/menu.ts +565 -591
- package/src/persistence.ts +177 -192
- package/src/prompts.ts +53 -67
- package/src/run-protocol.ts +299 -325
- package/src/runtime.ts +1422 -1495
- package/src/safety.ts +51 -51
- package/src/settings-ui.ts +366 -393
- package/src/settings.ts +134 -147
- package/src/tool-policy.ts +6 -6
- package/src/tools.ts +360 -371
- package/src/wait.ts +47 -51
- package/src/workflow-mutex.ts +68 -68
- package/dist/chunks/chunk-QWIUWKRW.js.map +0 -7
- package/dist/chunks/chunk-UQRRW4CY.js.map +0 -7
- package/dist/chunks/menu-WEFDREGC.js.map +0 -7
- package/dist/chunks/settings-ui-MVYTTBHW.js.map +0 -7
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/settings-ui.ts"],
|
|
4
|
+
"sourcesContent": ["import { join } from \"node:path\";\nimport { type ExtensionCommandContext, getAgentDir } from \"@earendil-works/pi-coding-agent\";\nimport { notifyTerminal, safeTerminalText } from \"./errors.js\";\nimport type { GoalRuntime } from \"./runtime.js\";\nimport { DEFAULT_GOAL_SETTINGS, GOAL_SETTINGS_FILE, type GoalSettings, saveGoalSettings } from \"./settings.js\";\n\ninterface GoalSettingsUiOptions {\n settingsPath?: string;\n initialScreen?: \"settings\" | \"automatic\";\n save?: (settings: GoalSettings, settingsPath: string) => void;\n}\n\ninterface GoalSettingsApplyOptions {\n save?: (settings: GoalSettings) => void;\n}\n\ntype LimitField = \"automaticTurns\" | \"noProgressTurns\";\ntype LimitSelection = \"unlimited\" | \"default\" | \"custom\" | \"off\";\nexport async function showGoalSettings(\n runtime: GoalRuntime,\n ctx: ExtensionCommandContext,\n options: GoalSettingsUiOptions = {},\n) {\n const settingsPath = options.settingsPath ?? join(getAgentDir(), GOAL_SETTINGS_FILE);\n if (ctx.mode !== \"tui\") {\n notifyTerminal(ctx.ui, `Edit pi-goal settings manually: ${safeTerminalText(settingsPath)}`, \"info\");\n return;\n }\n const generation = runtime.menuGeneration;\n const isMenuCurrent = () => generation === runtime.menuGeneration && !runtime.menuController.signal.aborted;\n const { defineMenu, runMenu } = await import(\"@narumitw/pi-tui-kit\");\n if (!isMenuCurrent()) return;\n const invalid = runtime.settingsLoadIssue?.kind === \"invalid\";\n const previewGoalIds = new Map<LimitField, string | null>();\n type Screen = \"settings\" | \"automatic\" | \"no-progress\" | \"invalid\";\n type Action = \"open-automatic\" | \"open-no-progress\" | \"choose-automatic\" | \"choose-no-progress\" | \"set-rpc\";\n const menu = defineMenu<undefined, Screen, Action, ExtensionCommandContext>({\n start: invalid ? \"invalid\" : (options.initialScreen ?? \"settings\"),\n screens: {\n settings: () => ({\n kind: \"settings\",\n title: \"Pi Goal Settings\",\n lines: [`User settings \u00B7 ${safeTerminalText(settingsPath)}`],\n items: [\n {\n id: \"automaticTurns\",\n label: \"Automatic-work limit\",\n description: \"Pause automatic Goal work after a visible number of model responses.\",\n currentValue: formatAutomaticSettingValue(runtime.settings.continuationLimits.automaticTurns),\n action: \"open-automatic\",\n },\n {\n id: \"noProgressTurns\",\n label: \"No-progress guard\",\n description: \"Pause after repeated or empty tool-free automatic runs.\",\n currentValue: formatNoProgressSettingValue(runtime.settings.continuationLimits.noProgressTurns),\n action: \"open-no-progress\",\n },\n {\n id: \"rpcEnabled\",\n label: \"Managed run RPC\",\n description:\n \"Allow trusted installed extensions to start and cancel Goal runs; this is not an extension sandbox.\",\n currentValue: runtime.settings.rpc.enabled ? \"On\" : \"Off\",\n values: [\"Off\", \"On\"],\n action: \"set-rpc\",\n },\n ],\n }),\n automatic: () => limitChoiceScreen(runtime, \"automaticTurns\", \"choose-automatic\"),\n \"no-progress\": () => limitChoiceScreen(runtime, \"noProgressTurns\", \"choose-no-progress\"),\n invalid: () => ({\n kind: \"detail\",\n title: \"Pi Goal Settings \u00B7 Read only\",\n lines: [\n `Invalid settings file. Pi-goal is using built-in defaults. Fix ${safeTerminalText(settingsPath)} and run /reload. The file will not be overwritten.`,\n `Automatic-work limit: ${formatAutomaticWork(runtime.settings.continuationLimits.automaticTurns)}`,\n `No-progress guard: ${formatNoProgressProtection(runtime.settings.continuationLimits.noProgressTurns)}`,\n `Managed run RPC: ${runtime.settings.rpc.enabled ? \"On\" : \"Off\"}`,\n ],\n hint: \"back\",\n }),\n },\n actions: {\n \"open-automatic\": async () => {\n previewGoalIds.set(\"automaticTurns\", runtime.activeGoal?.id ?? null);\n return { kind: \"to\", screen: \"automatic\" };\n },\n \"open-no-progress\": async () => {\n previewGoalIds.set(\"noProgressTurns\", runtime.activeGoal?.id ?? null);\n return { kind: \"to\", screen: \"no-progress\" };\n },\n \"choose-automatic\": async ({ itemId }) =>\n applyLimitChoice(\n runtime,\n ctx,\n options,\n settingsPath,\n \"automaticTurns\",\n itemId,\n previewGoalIds.get(\"automaticTurns\") ?? null,\n isMenuCurrent,\n ),\n \"choose-no-progress\": async ({ itemId }) =>\n applyLimitChoice(\n runtime,\n ctx,\n options,\n settingsPath,\n \"noProgressTurns\",\n itemId,\n previewGoalIds.get(\"noProgressTurns\") ?? null,\n isMenuCurrent,\n ),\n \"set-rpc\": async ({ value }) => {\n const enabled = value === \"On\";\n if (enabled === runtime.settings.rpc.enabled) return { kind: \"stay\" };\n try {\n const next = {\n ...structuredClone(runtime.settings),\n rpc: { enabled },\n } satisfies GoalSettings;\n applyGoalSettings(runtime, next, ctx, {\n save: (settings) => (options.save ?? saveGoalSettings)(settings, settingsPath),\n });\n notifyTerminal(ctx.ui, `Managed run RPC: ${enabled ? \"On\" : \"Off\"}.`, \"info\");\n return { kind: \"stay\" };\n } catch (error) {\n notifySettingsFailure(ctx, settingsPath, error);\n return { kind: \"rejected\" };\n }\n },\n },\n });\n await runMenu(ctx, menu, {\n getState: () => undefined,\n signal: runtime.menuController.signal,\n isCurrent: isMenuCurrent,\n });\n}\n\nfunction limitChoiceScreen(runtime: GoalRuntime, field: LimitField, action: \"choose-automatic\" | \"choose-no-progress\") {\n const value = runtime.settings.continuationLimits[field];\n const goal = runtime.activeGoal;\n return {\n kind: \"actions\" as const,\n title: field === \"automaticTurns\" ? \"Automatic-work limit\" : \"No-progress guard\",\n lines: [\n field === \"automaticTurns\"\n ? `Current: ${formatAutomaticWork(value)}`\n : `Current: ${formatNoProgressProtection(value)}`,\n ...(field === \"automaticTurns\"\n ? [\n `Set a whole-number response limit for each automatic-work epoch. Default: ${DEFAULT_GOAL_SETTINGS.continuationLimits.automaticTurns}.`,\n ]\n : []),\n ...(goal\n ? [\n field === \"automaticTurns\"\n ? `Active goal: ${goal.automaticModelTurns} automatic responses used`\n : `Active goal: ${goal.toolFreeRepeatCount} repeated or empty runs detected`,\n ]\n : []),\n ],\n items: limitChoices(field, value, goal?.automaticModelTurns).map((item) => ({\n id: item.value,\n label: item.label,\n description: item.description,\n action,\n })),\n hint: \"back\" as const,\n };\n}\n\nfunction limitChoices(\n field: LimitField,\n value: number | null,\n automaticTurnsUsed: number | undefined,\n): Array<{ value: LimitSelection; label: string; description: string }> {\n if (field === \"automaticTurns\") {\n const unlimitedDescription =\n value === null\n ? \"No response-count cap. Completion, manual pause, blockers, provider limits, and other configured guards still apply.\"\n : automaticTurnsUsed === undefined\n ? `Remove the current ${value}-response cap. Goal work will have no response-count cap; other configured stop conditions remain.`\n : `Remove the current ${value}-response cap. The active goal has used ${automaticTurnsUsed} responses; other configured stop conditions remain.`;\n return [\n {\n value: \"custom\",\n label: \"Set response limit\u2026\",\n description: `Choose a whole-number response limit for each automatic-work epoch. Default: ${DEFAULT_GOAL_SETTINGS.continuationLimits.automaticTurns}.`,\n },\n { value: \"unlimited\", label: \"Unlimited\u2026\", description: unlimitedDescription },\n ];\n }\n const defaultLimit = DEFAULT_GOAL_SETTINGS.continuationLimits.noProgressTurns;\n return [\n {\n value: \"default\",\n label: `After ${defaultLimit} repeated runs (default)`,\n description: \"Pause after the default number of repeated or empty tool-free runs.\",\n },\n {\n value: \"custom\",\n label: \"Set threshold\u2026\",\n description: \"Choose a whole number of repeated or empty runs before pausing.\",\n },\n {\n value: \"off\",\n label: \"Off\",\n description: \"Do not pause based on repeated or empty tool-free runs.\",\n },\n ];\n}\n\nasync function applyLimitChoice(\n runtime: GoalRuntime,\n ctx: ExtensionCommandContext,\n options: GoalSettingsUiOptions,\n settingsPath: string,\n field: LimitField,\n itemId: string,\n activeGoalId: string | null,\n isCurrent: () => boolean,\n) {\n if (!isCurrent() || !isLimitSelection(itemId)) return { kind: \"rejected\" as const };\n if ((runtime.activeGoal?.id ?? null) !== activeGoalId) {\n notifyTerminal(\n ctx.ui,\n \"The active goal changed while the safety setting was open. No settings were changed.\",\n \"warning\",\n );\n return { kind: \"rejected\" as const };\n }\n const previous = runtime.settings.continuationLimits[field];\n const limit = await resolveLimitSelection(field, itemId, previous, ctx, isCurrent);\n if (!isCurrent()) return { kind: \"rejected\" as const };\n if (limit === undefined || limit === previous) return { kind: \"back\" as const };\n if ((runtime.activeGoal?.id ?? null) !== activeGoalId) {\n notifyTerminal(\n ctx.ui,\n \"The active goal changed while editing the safety setting. No settings were changed.\",\n \"warning\",\n );\n return { kind: \"rejected\" as const };\n }\n const confirmation = await confirmLowerActiveLimit(runtime, ctx, field, limit);\n if (!isCurrent() || !confirmation.apply) return { kind: \"rejected\" as const };\n if (confirmation.goalId !== undefined && runtime.activeGoal?.id !== confirmation.goalId) {\n notifyTerminal(ctx.ui, \"The active goal changed while confirming the limit. No settings were changed.\", \"warning\");\n return { kind: \"rejected\" as const };\n }\n try {\n applyGoalSettings(runtime, withLimit(runtime.settings, field, limit), ctx, {\n save: (settings) => (options.save ?? saveGoalSettings)(settings, settingsPath),\n });\n notifyTerminal(ctx.ui, formatLimitSuccess(field, limit), \"info\");\n return { kind: \"back\" as const };\n } catch (error) {\n notifySettingsFailure(ctx, settingsPath, error);\n return { kind: \"rejected\" as const };\n }\n}\n\nexport function applyGoalSettings(\n runtime: GoalRuntime,\n next: GoalSettings,\n ctx: ExtensionCommandContext,\n options: GoalSettingsApplyOptions = {},\n) {\n const snapshot = runtime.snapshotSettingsApplicationState();\n let fileSaved = false;\n try {\n runtime.settings = structuredClone(next);\n options.save?.(next);\n fileSaved = options.save !== undefined;\n const activeGoalId = runtime.activeGoal?.id;\n const abortOwnedRun = activeGoalId !== undefined && runtime.agentRunGoalId === activeGoalId;\n const pausedByAutomaticLimit = runtime.enforceAutomaticTurnLimit(ctx, abortOwnedRun);\n if (!pausedByAutomaticLimit) runtime.enforceNoProgressLimit(ctx, abortOwnedRun);\n if (runtime.activeGoal) {\n runtime.updateStatus(ctx, runtime.activeGoal);\n }\n } catch (error) {\n const rollbackErrors: unknown[] = [];\n try {\n runtime.restoreSettingsApplicationState(snapshot);\n } catch (rollbackError) {\n rollbackErrors.push(rollbackError);\n }\n if (fileSaved) {\n try {\n options.save?.(snapshot.settings);\n } catch (rollbackError) {\n rollbackErrors.push(rollbackError);\n }\n try {\n restorePersistedRuntime(runtime, ctx);\n } catch (rollbackError) {\n rollbackErrors.push(rollbackError);\n }\n }\n if (rollbackErrors.length > 0) {\n throw new AggregateError(\n [error, ...rollbackErrors],\n `pi-goal settings application failed and rollback was incomplete: ${formatError(error)}`,\n );\n }\n throw error;\n }\n}\n\nexport function parseGoalLimit(value: string): number | undefined {\n const normalized = value.trim();\n if (!/^\\d+$/u.test(normalized)) return undefined;\n const parsed = Number(normalized);\n return Number.isSafeInteger(parsed) && parsed > 0 ? parsed : undefined;\n}\n\nasync function resolveLimitSelection(\n field: LimitField,\n selection: LimitSelection,\n previous: number | null,\n ctx: ExtensionCommandContext,\n isCurrent: () => boolean,\n): Promise<number | null | undefined> {\n if (selection === \"off\") return null;\n if (selection === \"unlimited\") {\n if (previous === null) return null;\n const confirmed = await ctx.ui.confirm(\n \"Allow Unlimited automatic work?\",\n \"Tool loops can continue without a response-count limit and may consume substantial tokens and provider cost. Completion, manual pause, blockers, provider limits, and the no-progress guard still apply.\",\n );\n return isCurrent() && confirmed ? null : undefined;\n }\n if (selection === \"default\") {\n return DEFAULT_GOAL_SETTINGS.continuationLimits[field];\n }\n while (true) {\n const raw =\n field === \"automaticTurns\"\n ? await ctx.ui.editor(\n `Automatic-work response limit (whole number greater than 0) \u00B7 Default: ${DEFAULT_GOAL_SETTINGS.continuationLimits.automaticTurns}`,\n String(previous ?? DEFAULT_GOAL_SETTINGS.continuationLimits.automaticTurns),\n )\n : await ctx.ui.input(\n \"Repeated-run threshold (whole number greater than 0)\",\n previous === null ? \"Positive whole number\" : String(previous),\n );\n if (!isCurrent() || raw === undefined) return undefined;\n const parsed = parseGoalLimit(raw);\n if (parsed !== undefined) return parsed;\n notifyTerminal(\n ctx.ui,\n `Enter a whole number greater than 0. Choose ${field === \"automaticTurns\" ? \"Unlimited\" : \"Off\"} from the previous screen if you do not want a limit.`,\n \"warning\",\n );\n }\n}\n\nfunction restorePersistedRuntime(runtime: GoalRuntime, ctx: ExtensionCommandContext) {\n if (runtime.activeGoal) {\n runtime.persistGoal(runtime.activeGoal);\n runtime.updateStatus(ctx, runtime.activeGoal);\n runtime.restoreGoalWaitTimer(ctx);\n }\n}\n\nasync function confirmLowerActiveLimit(\n runtime: GoalRuntime,\n ctx: ExtensionCommandContext,\n field: LimitField,\n limit: number | null,\n) {\n const goal = runtime.activeGoal;\n if (goal?.status !== \"active\" || limit === null) return { apply: true };\n const used = field === \"automaticTurns\" ? goal.automaticModelTurns : goal.toolFreeRepeatCount;\n if (used < limit) return { apply: true };\n return {\n apply: await ctx.ui.confirm(\n \"Apply limit and pause now?\",\n `The active goal has already used ${used}. Setting this limit to ${limit} will pause it immediately without deleting progress.`,\n ),\n goalId: goal.id,\n };\n}\n\nfunction withLimit(settings: GoalSettings, field: LimitField, value: number | null): GoalSettings {\n return {\n ...structuredClone(settings),\n continuationLimits: { ...settings.continuationLimits, [field]: value },\n };\n}\n\nfunction formatAutomaticSettingValue(value: number | null) {\n return value === null ? \"Unlimited\" : `${value} responses`;\n}\n\nfunction formatNoProgressSettingValue(value: number | null) {\n if (value === null) return \"Off\";\n return `${value} ${value === 1 ? \"run\" : \"runs\"}`;\n}\n\nfunction formatAutomaticWork(value: number | null) {\n return value === null ? \"Unlimited\" : `Up to ${value} responses`;\n}\n\nfunction formatNoProgressProtection(value: number | null) {\n if (value === null) return \"Off\";\n return `After ${value} repeated ${value === 1 ? \"run\" : \"runs\"}`;\n}\n\nfunction formatLimitSuccess(field: LimitField, value: number | null) {\n return field === \"automaticTurns\"\n ? `Automatic-work limit: ${formatAutomaticWork(value)}.`\n : `No-progress guard: ${formatNoProgressProtection(value)}.`;\n}\n\nfunction isLimitSelection(value: string): value is LimitSelection {\n return value === \"unlimited\" || value === \"default\" || value === \"custom\" || value === \"off\";\n}\n\nfunction notifySettingsFailure(ctx: ExtensionCommandContext, settingsPath: string, error: unknown) {\n const path = safeTerminalText(settingsPath);\n const detail = safeTerminalText(formatError(error));\n notifyTerminal(\n ctx.ui,\n error instanceof AggregateError\n ? `Could not apply Goal settings, and rollback was incomplete. Check ${path}, run /reload, and verify the effective settings before retrying: ${detail}`\n : `Could not save Goal settings; the previous value remains. Check ${path} and retry: ${detail}`,\n \"error\",\n );\n}\n\nfunction formatError(error: unknown) {\n return error instanceof Error ? error.message : String(error);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;AAAA,SAAS,YAAY;AACrB,SAAuC,mBAAmB;AAiB1D,eAAsB,iBACpB,SACA,KACA,UAAiC,CAAC,GAClC;AACA,QAAM,eAAe,QAAQ,gBAAgB,KAAK,YAAY,GAAG,kBAAkB;AACnF,MAAI,IAAI,SAAS,OAAO;AACtB,mBAAe,IAAI,IAAI,mCAAmC,iBAAiB,YAAY,CAAC,IAAI,MAAM;AAClG;AAAA,EACF;AACA,QAAM,aAAa,QAAQ;AAC3B,QAAM,gBAAgB,MAAM,eAAe,QAAQ,kBAAkB,CAAC,QAAQ,eAAe,OAAO;AACpG,QAAM,EAAE,YAAY,QAAQ,IAAI,MAAM,OAAO,sBAAsB;AACnE,MAAI,CAAC,cAAc,EAAG;AACtB,QAAM,UAAU,QAAQ,mBAAmB,SAAS;AACpD,QAAM,iBAAiB,oBAAI,IAA+B;AAG1D,QAAM,OAAO,WAA+D;AAAA,IAC1E,OAAO,UAAU,YAAa,QAAQ,iBAAiB;AAAA,IACvD,SAAS;AAAA,MACP,UAAU,OAAO;AAAA,QACf,MAAM;AAAA,QACN,OAAO;AAAA,QACP,OAAO,CAAC,sBAAmB,iBAAiB,YAAY,CAAC,EAAE;AAAA,QAC3D,OAAO;AAAA,UACL;AAAA,YACE,IAAI;AAAA,YACJ,OAAO;AAAA,YACP,aAAa;AAAA,YACb,cAAc,4BAA4B,QAAQ,SAAS,mBAAmB,cAAc;AAAA,YAC5F,QAAQ;AAAA,UACV;AAAA,UACA;AAAA,YACE,IAAI;AAAA,YACJ,OAAO;AAA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/chunk-
|
|
46
|
+
} from "./chunks/chunk-WLIH47XO.js";
|
|
47
47
|
import {
|
|
48
48
|
DEFAULT_GOAL_SETTINGS,
|
|
49
49
|
currentTokenTotal,
|
|
@@ -52,83 +52,85 @@ import {
|
|
|
52
52
|
formatTokenCount,
|
|
53
53
|
isGoalContextOverflow,
|
|
54
54
|
isRetryableGoalInterruption,
|
|
55
|
+
isStaleContextError,
|
|
55
56
|
isUsageLimitedGoalInterruption,
|
|
56
57
|
notifyTerminal,
|
|
57
58
|
readGoalSettings,
|
|
58
59
|
safeGoalMenuText,
|
|
59
60
|
safeTerminalText,
|
|
60
61
|
truncateNotification
|
|
61
|
-
} from "./chunks/chunk-
|
|
62
|
+
} from "./chunks/chunk-6T3MHA45.js";
|
|
62
63
|
|
|
63
64
|
// src/command-registration.ts
|
|
64
65
|
function registerGoalCommand(pi, runtime, commands, options = {}) {
|
|
65
|
-
const loadGoalManager = cachedModuleLoader(
|
|
66
|
-
|
|
67
|
-
);
|
|
68
|
-
const loadGoalSettings = cachedModuleLoader(
|
|
69
|
-
options.loadGoalSettings ?? (() => import("./chunks/settings-ui-MVYTTBHW.js"))
|
|
70
|
-
);
|
|
66
|
+
const loadGoalManager = cachedModuleLoader(options.loadGoalManager ?? (() => import("./chunks/menu-RGCRCQJK.js")));
|
|
67
|
+
const loadGoalSettings = cachedModuleLoader(options.loadGoalSettings ?? (() => import("./chunks/settings-ui-BAWNTINU.js")));
|
|
71
68
|
pi.registerCommand("goal", {
|
|
72
69
|
description: "Run a goal to completion: /goal [--tokens 100k] <goal_to_complete>",
|
|
73
70
|
getArgumentCompletions: (prefix) => completeGoalArguments(prefix),
|
|
74
71
|
handler: async (args, ctx) => {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const result = parseCommand(args);
|
|
80
|
-
if (typeof result === "string") {
|
|
81
|
-
reportCommandError(result, ctx);
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
if (result.kind === "show" && args.trim() === "") {
|
|
85
|
-
const menuIsCurrent = captureMenuOwnership(runtime);
|
|
86
|
-
let managerModule;
|
|
87
|
-
try {
|
|
88
|
-
managerModule = await loadGoalManager();
|
|
89
|
-
} catch (error) {
|
|
90
|
-
if (!menuIsCurrent()) return;
|
|
91
|
-
throw error;
|
|
72
|
+
try {
|
|
73
|
+
if (runtime.hasLegacyQueueInterface() && isRemovedQueueCommand(args)) {
|
|
74
|
+
reportRemovedQueueCommand(ctx, runtime);
|
|
75
|
+
return;
|
|
92
76
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
77
|
+
const result = parseCommand(args);
|
|
78
|
+
if (typeof result === "string") {
|
|
79
|
+
reportCommandError(result, ctx);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (result.kind === "show" && args.trim() === "") {
|
|
83
|
+
const menuIsCurrent = captureMenuOwnership(runtime);
|
|
84
|
+
let managerModule;
|
|
98
85
|
try {
|
|
99
|
-
|
|
86
|
+
managerModule = await loadGoalManager();
|
|
100
87
|
} catch (error) {
|
|
101
|
-
if (!
|
|
88
|
+
if (!menuIsCurrent()) return;
|
|
102
89
|
throw error;
|
|
103
90
|
}
|
|
104
|
-
if (!
|
|
105
|
-
const {
|
|
106
|
-
await
|
|
107
|
-
|
|
108
|
-
|
|
91
|
+
if (!menuIsCurrent()) return;
|
|
92
|
+
const { showGoalManager } = managerModule;
|
|
93
|
+
await showGoalManager(runtime, commands, ctx, async (menuCtx, target) => {
|
|
94
|
+
const settingsAreCurrent = captureMenuOwnership(runtime);
|
|
95
|
+
let settingsModule;
|
|
96
|
+
try {
|
|
97
|
+
settingsModule = await loadGoalSettings();
|
|
98
|
+
} catch (error) {
|
|
99
|
+
if (!settingsAreCurrent()) return;
|
|
100
|
+
throw error;
|
|
101
|
+
}
|
|
102
|
+
if (!settingsAreCurrent()) return;
|
|
103
|
+
const { showGoalSettings } = settingsModule;
|
|
104
|
+
await showGoalSettings(runtime, menuCtx, {
|
|
105
|
+
settingsPath: options.settingsPath,
|
|
106
|
+
initialScreen: target
|
|
107
|
+
});
|
|
109
108
|
});
|
|
110
|
-
});
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
switch (result.kind) {
|
|
114
|
-
case "show":
|
|
115
|
-
commands.showGoal(ctx);
|
|
116
|
-
return;
|
|
117
|
-
case "pause":
|
|
118
|
-
commands.pauseGoal(ctx);
|
|
119
|
-
return;
|
|
120
|
-
case "resume":
|
|
121
|
-
await commands.resumeGoal(ctx);
|
|
122
|
-
return;
|
|
123
|
-
case "clear":
|
|
124
|
-
commands.clearGoal(ctx);
|
|
125
|
-
return;
|
|
126
|
-
case "edit":
|
|
127
|
-
await commands.editGoal(result.objective ?? "", result.tokenBudget, ctx);
|
|
128
|
-
return;
|
|
129
|
-
case "start":
|
|
130
|
-
await commands.startGoal(result.objective ?? "", result.tokenBudget, ctx);
|
|
131
109
|
return;
|
|
110
|
+
}
|
|
111
|
+
switch (result.kind) {
|
|
112
|
+
case "show":
|
|
113
|
+
commands.showGoal(ctx);
|
|
114
|
+
return;
|
|
115
|
+
case "pause":
|
|
116
|
+
commands.pauseGoal(ctx);
|
|
117
|
+
return;
|
|
118
|
+
case "resume":
|
|
119
|
+
await commands.resumeGoal(ctx);
|
|
120
|
+
return;
|
|
121
|
+
case "clear":
|
|
122
|
+
commands.clearGoal(ctx);
|
|
123
|
+
return;
|
|
124
|
+
case "edit":
|
|
125
|
+
await commands.editGoal(result.objective ?? "", result.tokenBudget, ctx);
|
|
126
|
+
return;
|
|
127
|
+
case "start":
|
|
128
|
+
await commands.startGoal(result.objective ?? "", result.tokenBudget, ctx);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
} catch (error) {
|
|
132
|
+
if (isStaleContextError(error)) return;
|
|
133
|
+
throw error;
|
|
132
134
|
}
|
|
133
135
|
}
|
|
134
136
|
});
|
|
@@ -189,11 +191,7 @@ New goal: ${safeGoalMenuText(objective, 4e3)}`
|
|
|
189
191
|
}
|
|
190
192
|
if (isRequestCurrent && !isRequestCurrent()) return;
|
|
191
193
|
if (this.runtime.activeGoal?.id !== existingGoal.id) {
|
|
192
|
-
notifyTerminal(
|
|
193
|
-
ctx.ui,
|
|
194
|
-
"The active goal changed while confirmation was open. Try again.",
|
|
195
|
-
"warning"
|
|
196
|
-
);
|
|
194
|
+
notifyTerminal(ctx.ui, "The active goal changed while confirmation was open. Try again.", "warning");
|
|
197
195
|
return;
|
|
198
196
|
}
|
|
199
197
|
}
|
|
@@ -299,11 +297,7 @@ New goal: ${safeGoalMenuText(objective, 4e3)}`
|
|
|
299
297
|
return;
|
|
300
298
|
}
|
|
301
299
|
if (this.runtime.activeGoal.status !== "active") {
|
|
302
|
-
notifyTerminal(
|
|
303
|
-
ctx.ui,
|
|
304
|
-
`Goal is ${this.runtime.activeGoal.status}; only active goals can be paused.`,
|
|
305
|
-
"warning"
|
|
306
|
-
);
|
|
300
|
+
notifyTerminal(ctx.ui, `Goal is ${this.runtime.activeGoal.status}; only active goals can be paused.`, "warning");
|
|
307
301
|
return;
|
|
308
302
|
}
|
|
309
303
|
const stoppedGoal = this.runtime.stopActiveGoal(ctx, {
|
|
@@ -330,11 +324,7 @@ New goal: ${safeGoalMenuText(objective, 4e3)}`
|
|
|
330
324
|
return;
|
|
331
325
|
}
|
|
332
326
|
if (this.runtime.activeGoal.tokenBudget !== void 0 && this.runtime.activeGoal.tokensUsed >= this.runtime.activeGoal.tokenBudget) {
|
|
333
|
-
notifyTerminal(
|
|
334
|
-
ctx.ui,
|
|
335
|
-
`Goal token budget is still reached: ${formatBudget(this.runtime.activeGoal)}`,
|
|
336
|
-
"warning"
|
|
337
|
-
);
|
|
327
|
+
notifyTerminal(ctx.ui, `Goal token budget is still reached: ${formatBudget(this.runtime.activeGoal)}`, "warning");
|
|
338
328
|
return;
|
|
339
329
|
}
|
|
340
330
|
if (!this.runtime.acquireWorkflow(ctx.sessionManager)) {
|
|
@@ -354,18 +344,12 @@ New goal: ${safeGoalMenuText(objective, 4e3)}`
|
|
|
354
344
|
this.runtime.clearGoalRecovery();
|
|
355
345
|
this.runtime.clearBudgetWrapUp();
|
|
356
346
|
this.runtime.clearStaleGoalToolCallBlock();
|
|
357
|
-
this.runtime.activeGoal = queueGoalSafetyReset(
|
|
358
|
-
transitionGoal(nextGoalInstance(this.runtime.activeGoal), "active")
|
|
359
|
-
);
|
|
347
|
+
this.runtime.activeGoal = queueGoalSafetyReset(transitionGoal(nextGoalInstance(this.runtime.activeGoal), "active"));
|
|
360
348
|
this.runtime.persistGoal(this.runtime.activeGoal);
|
|
361
349
|
if (this.runtime.activeGoal.status !== "active") {
|
|
362
350
|
this.runtime.updateStatus(ctx, this.runtime.activeGoal);
|
|
363
351
|
this.runtime.releaseWorkflow();
|
|
364
|
-
notifyTerminal(
|
|
365
|
-
ctx.ui,
|
|
366
|
-
`Goal token budget is still reached: ${formatBudget(this.runtime.activeGoal)}`,
|
|
367
|
-
"warning"
|
|
368
|
-
);
|
|
352
|
+
notifyTerminal(ctx.ui, `Goal token budget is still reached: ${formatBudget(this.runtime.activeGoal)}`, "warning");
|
|
369
353
|
return;
|
|
370
354
|
}
|
|
371
355
|
if (!this.runtime.ownsWorkflow(this.runtime.activeGoal)) return;
|
|
@@ -412,8 +396,7 @@ New goal: ${safeGoalMenuText(objective, 4e3)}`
|
|
|
412
396
|
}
|
|
413
397
|
if (!this.runtime.clearGoalWait(ctx, waitingGoal.id)) return;
|
|
414
398
|
const resumedGoal = this.runtime.activeGoal;
|
|
415
|
-
if (!resumedGoal || resumedGoal.id !== waitingGoal.id || resumedGoal.status !== "active")
|
|
416
|
-
return;
|
|
399
|
+
if (!resumedGoal || resumedGoal.id !== waitingGoal.id || resumedGoal.status !== "active") return;
|
|
417
400
|
const sent = await this.runtime.sendOwnedGoalPrompt(
|
|
418
401
|
ctx,
|
|
419
402
|
resumedGoal.id,
|
|
@@ -513,11 +496,7 @@ New goal: ${safeGoalMenuText(objective, 4e3)}`
|
|
|
513
496
|
if (editedGoal.status === "active") {
|
|
514
497
|
if (!this.runtime.ownsWorkflow(editedGoal)) return;
|
|
515
498
|
this.runtime.clearStaleGoalToolCallBlock();
|
|
516
|
-
const sent = await this.runtime.sendOwnedGoalPrompt(
|
|
517
|
-
ctx,
|
|
518
|
-
editedGoal.id,
|
|
519
|
-
buildObjectiveUpdatedPrompt(editedGoal)
|
|
520
|
-
);
|
|
499
|
+
const sent = await this.runtime.sendOwnedGoalPrompt(ctx, editedGoal.id, buildObjectiveUpdatedPrompt(editedGoal));
|
|
521
500
|
if (!sent) {
|
|
522
501
|
if (this.runtime.activeGoal?.id === editedGoal.id) {
|
|
523
502
|
if (previousStatus === "active" && previousGoal.waiting) {
|
|
@@ -604,7 +583,9 @@ New goal: ${safeGoalMenuText(objective, 4e3)}`
|
|
|
604
583
|
var REMOVED_QUEUE_SETTING_WARNING = "Ordered goal queue has been removed. Use /goal edit to reprioritize an active objective, or start /goal <objectives> if no active goal exists.";
|
|
605
584
|
var REMOVED_PERSISTED_QUEUE_WARNING = "Ordered goal queue has been removed. Start /goal <objectives> to continue with one merged objective, or use /goal clear to discard the old queue state.";
|
|
606
585
|
function registerGoalLifecycle(pi, runtime, runController, options = {}) {
|
|
586
|
+
let sessionActive = true;
|
|
607
587
|
pi.on("session_start", async (_event, ctx) => {
|
|
588
|
+
sessionActive = true;
|
|
608
589
|
runtime.bindWorkflowSession(ctx.sessionManager);
|
|
609
590
|
runtime.replaceMenuSession();
|
|
610
591
|
runtime.clearCompletionStatusTimer();
|
|
@@ -628,11 +609,7 @@ function registerGoalLifecycle(pi, runtime, runController, options = {}) {
|
|
|
628
609
|
runtime.legacyExperimentalGoalsSetting = settingsResult.kind !== "invalid" && settingsResult.legacyExperimentalGoals;
|
|
629
610
|
runController.bindSession(ctx);
|
|
630
611
|
if (settingsResult.kind === "invalid") {
|
|
631
|
-
notifyTerminal(
|
|
632
|
-
ctx.ui,
|
|
633
|
-
`pi-goal settings ignored: ${settingsResult.reason}. Using default settings.`,
|
|
634
|
-
"warning"
|
|
635
|
-
);
|
|
612
|
+
notifyTerminal(ctx.ui, `pi-goal settings ignored: ${settingsResult.reason}. Using default settings.`, "warning");
|
|
636
613
|
}
|
|
637
614
|
if (runtime.legacyExperimentalGoalsSetting && !runtime.legacyQueueState) {
|
|
638
615
|
notifyTerminal(ctx.ui, REMOVED_QUEUE_SETTING_WARNING, "warning");
|
|
@@ -690,6 +667,7 @@ function registerGoalLifecycle(pi, runtime, runController, options = {}) {
|
|
|
690
667
|
}
|
|
691
668
|
});
|
|
692
669
|
pi.on("session_shutdown", (_event, ctx) => {
|
|
670
|
+
sessionActive = false;
|
|
693
671
|
const shutdownSession = ctx.sessionManager;
|
|
694
672
|
runController.unbindSession();
|
|
695
673
|
runtime.closeMenuSession();
|
|
@@ -717,6 +695,7 @@ function registerGoalLifecycle(pi, runtime, runController, options = {}) {
|
|
|
717
695
|
runtime.unbindWorkflowSession(shutdownSession);
|
|
718
696
|
});
|
|
719
697
|
pi.on("session_before_compact", (event, ctx) => {
|
|
698
|
+
if (!sessionActive) return;
|
|
720
699
|
if (runtime.activeGoal?.status === "budget_limited") {
|
|
721
700
|
if (event.willRetry === true) return { cancel: true };
|
|
722
701
|
return;
|
|
@@ -731,6 +710,7 @@ function registerGoalLifecycle(pi, runtime, runController, options = {}) {
|
|
|
731
710
|
if (runtime.limitActiveGoalForBudget(ctx, false)) return { cancel: true };
|
|
732
711
|
});
|
|
733
712
|
pi.on("session_compact", async (event, ctx) => {
|
|
713
|
+
if (!sessionActive) return;
|
|
734
714
|
if (runtime.activeGoal?.status !== "active" || !runtime.ownsWorkflow(runtime.activeGoal)) {
|
|
735
715
|
runtime.clearGoalRecovery();
|
|
736
716
|
return;
|
|
@@ -758,6 +738,7 @@ function registerGoalLifecycle(pi, runtime, runController, options = {}) {
|
|
|
758
738
|
runtime.scheduleContinuationDispatch(ctx, runtime.activeGoal.id);
|
|
759
739
|
});
|
|
760
740
|
pi.on("input", (event, ctx) => {
|
|
741
|
+
if (!sessionActive) return;
|
|
761
742
|
if (event.source === "extension") {
|
|
762
743
|
if (runtime.consumeCancelledGoalPrompt(event.text) || runtime.consumeCancelledContinuationPrompt(event.text) || runtime.consumeStaleOwnedGoalPrompt(event.text)) {
|
|
763
744
|
return { action: "handled" };
|
|
@@ -786,6 +767,7 @@ function registerGoalLifecycle(pi, runtime, runController, options = {}) {
|
|
|
786
767
|
runtime.resetActiveSafetyEpoch(ctx);
|
|
787
768
|
});
|
|
788
769
|
pi.on("message_start", (event, ctx) => {
|
|
770
|
+
if (!sessionActive) return;
|
|
789
771
|
const message = event.message;
|
|
790
772
|
if (message.role === "assistant" && runtime.activeGoal?.status === "paused" && runtime.guardAbortGoalId === runtime.activeGoal.id) {
|
|
791
773
|
abortCurrentTurn(ctx);
|
|
@@ -802,9 +784,7 @@ function registerGoalLifecycle(pi, runtime, runController, options = {}) {
|
|
|
802
784
|
return;
|
|
803
785
|
}
|
|
804
786
|
if (message.role !== "user") return;
|
|
805
|
-
const prompt = Array.isArray(message.content) ? message.content.filter(
|
|
806
|
-
(part) => part && typeof part === "object" && Reflect.get(part, "type") === "text"
|
|
807
|
-
).map((part) => Reflect.get(part, "text")).filter((text) => typeof text === "string").join("\n") : typeof message.content === "string" ? message.content : "";
|
|
787
|
+
const prompt = Array.isArray(message.content) ? message.content.filter((part) => part && typeof part === "object" && Reflect.get(part, "type") === "text").map((part) => Reflect.get(part, "text")).filter((text) => typeof text === "string").join("\n") : typeof message.content === "string" ? message.content : "";
|
|
808
788
|
const ownedPrompt = runtime.consumeOwnedGoalPrompt(prompt);
|
|
809
789
|
const ownedPromptBoundary = runtime.hasOwnedPromptBoundary(prompt);
|
|
810
790
|
const queuedNonGoalInput = runtime.consumeQueuedNonGoalInput(prompt, !ownedPromptBoundary);
|
|
@@ -818,10 +798,7 @@ function registerGoalLifecycle(pi, runtime, runController, options = {}) {
|
|
|
818
798
|
return;
|
|
819
799
|
}
|
|
820
800
|
if (runtime.agentRunGoalId !== void 0 && runtime.agentRunGoalId !== ownedPrompt.goalId) {
|
|
821
|
-
runtime.activeGoal.baselineTokens = Math.max(
|
|
822
|
-
0,
|
|
823
|
-
currentTokenTotal(ctx) - runtime.activeGoal.tokensUsed
|
|
824
|
-
);
|
|
801
|
+
runtime.activeGoal.baselineTokens = Math.max(0, currentTokenTotal(ctx) - runtime.activeGoal.tokensUsed);
|
|
825
802
|
}
|
|
826
803
|
runtime.beginAgentRun(ownedPrompt.goalId, "manual");
|
|
827
804
|
if (ownedPrompt.resetSafetyEpoch) {
|
|
@@ -831,9 +808,8 @@ function registerGoalLifecycle(pi, runtime, runController, options = {}) {
|
|
|
831
808
|
runtime.updateStatus(ctx, runtime.activeGoal);
|
|
832
809
|
});
|
|
833
810
|
pi.on("context", (event, ctx) => {
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
);
|
|
811
|
+
if (!sessionActive) return;
|
|
812
|
+
const keptMessages = event.messages.filter((message) => runtime.keepBudgetWrapUpMessage(message));
|
|
837
813
|
const hasGoalContractHistory = keptMessages.some(isGoalContextContract) || runtime.hasGoalContextContractHistory(ctx);
|
|
838
814
|
const messages = runtime.activeGoal?.status === "active" && runtime.ownsWorkflow(runtime.activeGoal) ? reconcileGoalContextContract(keptMessages, runtime.activeGoal) : hasGoalContractHistory ? reconcileInactiveGoalContextContract(keptMessages) : keptMessages;
|
|
839
815
|
if (runtime.activeGoal?.status === "paused" && runtime.guardAbortGoalId === runtime.activeGoal.id) {
|
|
@@ -844,6 +820,7 @@ function registerGoalLifecycle(pi, runtime, runController, options = {}) {
|
|
|
844
820
|
}
|
|
845
821
|
});
|
|
846
822
|
pi.on("tool_call", (event, ctx) => {
|
|
823
|
+
if (!sessionActive) return;
|
|
847
824
|
runtime.markAgentToolAttempted();
|
|
848
825
|
if (runtime.activeGoal?.status === "budget_limited" && runtime.budgetWrapUp?.goalId === runtime.activeGoal.id && event.toolName !== "goal_complete") {
|
|
849
826
|
abortCurrentTurn(ctx);
|
|
@@ -864,6 +841,7 @@ function registerGoalLifecycle(pi, runtime, runController, options = {}) {
|
|
|
864
841
|
};
|
|
865
842
|
});
|
|
866
843
|
pi.on("tool_execution_end", (_event, ctx) => {
|
|
844
|
+
if (!sessionActive) return;
|
|
867
845
|
if (runtime.activeGoal?.status === "budget_limited" && runtime.budgetWrapUp?.goalId === runtime.activeGoal.id && !runtime.budgetWrapUp.delivered) {
|
|
868
846
|
runtime.queueBudgetWrapUp(ctx, runtime.activeGoal);
|
|
869
847
|
return;
|
|
@@ -878,6 +856,7 @@ function registerGoalLifecycle(pi, runtime, runController, options = {}) {
|
|
|
878
856
|
if (!runtime.goalToolsAvailable()) runtime.pauseGoalForUnavailableTools(ctx);
|
|
879
857
|
});
|
|
880
858
|
pi.on("before_agent_start", (event, ctx) => {
|
|
859
|
+
if (!sessionActive) return;
|
|
881
860
|
runtime.clearAgentRun();
|
|
882
861
|
if (runtime.guardAbortGoalId) runtime.guardAbortGoalId = void 0;
|
|
883
862
|
const goalPrompt = runtime.consumeOwnedGoalPrompt(event.prompt);
|
|
@@ -933,6 +912,7 @@ function registerGoalLifecycle(pi, runtime, runController, options = {}) {
|
|
|
933
912
|
return goalContractBoundaryResult(ctx, runtime.activeGoal);
|
|
934
913
|
});
|
|
935
914
|
pi.on("agent_start", (_event, _ctx) => {
|
|
915
|
+
if (!sessionActive) return;
|
|
936
916
|
const activeGoal = runtime.activeGoal;
|
|
937
917
|
if (activeGoal && runtime.guardAbortGoalId === activeGoal.id && activeGoal.status === "paused") {
|
|
938
918
|
if (runtime.consumeQueuedNonGoalFollowUpForAgentStart()) {
|
|
@@ -945,12 +925,14 @@ function registerGoalLifecycle(pi, runtime, runController, options = {}) {
|
|
|
945
925
|
runtime.beginRecoveryRunIfNeeded();
|
|
946
926
|
});
|
|
947
927
|
pi.on("turn_end", (event, ctx) => {
|
|
928
|
+
if (!sessionActive) return;
|
|
948
929
|
runtime.recordAutomaticTurn(ctx, event.message);
|
|
949
930
|
if (runtime.activeGoal?.status !== "active") {
|
|
950
931
|
runtime.ensureInactiveGoalContextContract(ctx);
|
|
951
932
|
}
|
|
952
933
|
});
|
|
953
934
|
pi.on("agent_end", (event, ctx) => {
|
|
935
|
+
if (!sessionActive) return;
|
|
954
936
|
const run = runtime.finishAgentRun();
|
|
955
937
|
if (run.goalId === null) return;
|
|
956
938
|
if (!runtime.canRecordGoalUsage() && !runtime.hasActiveBudgetWrapUp()) return;
|
|
@@ -1025,6 +1007,7 @@ function registerGoalLifecycle(pi, runtime, runController, options = {}) {
|
|
|
1025
1007
|
runtime.requestContinuation(currentGoal);
|
|
1026
1008
|
});
|
|
1027
1009
|
pi.on("agent_settled", (_event, ctx) => {
|
|
1010
|
+
if (!sessionActive) return;
|
|
1028
1011
|
if (runtime.activeGoal?.status === "active" && !runtime.ownsWorkflow(runtime.activeGoal)) {
|
|
1029
1012
|
runtime.cancelContinuationWork();
|
|
1030
1013
|
runtime.clearGoalRecovery();
|
|
@@ -1058,11 +1041,7 @@ function registerGoalLifecycle(pi, runtime, runController, options = {}) {
|
|
|
1058
1041
|
if (!stoppedGoal) return;
|
|
1059
1042
|
const details = assistant.errorMessage ? ` (${truncateNotification(assistant.errorMessage)})` : "";
|
|
1060
1043
|
if (status === "paused") {
|
|
1061
|
-
notifyTerminal(
|
|
1062
|
-
ctx.ui,
|
|
1063
|
-
`Goal paused after interruption${details}. Run /goal resume to continue.`,
|
|
1064
|
-
"warning"
|
|
1065
|
-
);
|
|
1044
|
+
notifyTerminal(ctx.ui, `Goal paused after interruption${details}. Run /goal resume to continue.`, "warning");
|
|
1066
1045
|
return;
|
|
1067
1046
|
}
|
|
1068
1047
|
if (status === "usage_limited") {
|
|
@@ -1192,12 +1171,7 @@ var GoalRunController = class {
|
|
|
1192
1171
|
return;
|
|
1193
1172
|
}
|
|
1194
1173
|
if (this.session !== session || this.generation !== session.generation) {
|
|
1195
|
-
this.emitError(
|
|
1196
|
-
runId,
|
|
1197
|
-
"start",
|
|
1198
|
-
"SUPERSEDED",
|
|
1199
|
-
"The pi-goal session changed while validating the request."
|
|
1200
|
-
);
|
|
1174
|
+
this.emitError(runId, "start", "SUPERSEDED", "The pi-goal session changed while validating the request.");
|
|
1201
1175
|
return;
|
|
1202
1176
|
}
|
|
1203
1177
|
if (this.usedRunIds.has(runId)) {
|
|
@@ -1239,12 +1213,7 @@ var GoalRunController = class {
|
|
|
1239
1213
|
} catch (error) {
|
|
1240
1214
|
if (this.ownsRun(run, session.generation)) {
|
|
1241
1215
|
this.closeCurrentRun();
|
|
1242
|
-
this.emitError(
|
|
1243
|
-
runId,
|
|
1244
|
-
"start",
|
|
1245
|
-
"ACTIVATION_FAILED",
|
|
1246
|
-
`Goal activation failed: ${formatError(error)}`
|
|
1247
|
-
);
|
|
1216
|
+
this.emitError(runId, "start", "ACTIVATION_FAILED", `Goal activation failed: ${formatError(error)}`);
|
|
1248
1217
|
}
|
|
1249
1218
|
return;
|
|
1250
1219
|
}
|
|
@@ -1314,12 +1283,11 @@ var GoalRunController = class {
|
|
|
1314
1283
|
});
|
|
1315
1284
|
return;
|
|
1316
1285
|
}
|
|
1317
|
-
if (
|
|
1286
|
+
if (run.lastStatus === snapshot.status) return;
|
|
1318
1287
|
this.publishStateEvent(run, snapshot);
|
|
1319
1288
|
}
|
|
1320
1289
|
publishStateEvent(run, snapshot) {
|
|
1321
1290
|
const status = snapshot.status;
|
|
1322
|
-
if (status === "queued") return;
|
|
1323
1291
|
run.lastStatus = status;
|
|
1324
1292
|
const event = {
|
|
1325
1293
|
type: "state",
|
|
@@ -1526,8 +1494,7 @@ function registerGoalTools(pi, runtime) {
|
|
|
1526
1494
|
if (blockedGoal.status !== "active") {
|
|
1527
1495
|
return reject(`goal is ${blockedGoal.status}, not active`);
|
|
1528
1496
|
}
|
|
1529
|
-
if (!runtime.ownsWorkflow(blockedGoal))
|
|
1530
|
-
return reject("active Goal no longer owns its workflow");
|
|
1497
|
+
if (!runtime.ownsWorkflow(blockedGoal)) return reject("active Goal no longer owns its workflow");
|
|
1531
1498
|
if (!reason) return reject("reason is empty");
|
|
1532
1499
|
if (reason.length > MAX_BLOCKER_REASON_LENGTH) return reject("reason is too long");
|
|
1533
1500
|
if (!evidence) return reject("evidence is empty");
|
|
@@ -1594,8 +1561,7 @@ function registerGoalTools(pi, runtime) {
|
|
|
1594
1561
|
if (activeGoal.status !== "active") {
|
|
1595
1562
|
return reject(`goal is ${activeGoal.status}, not active`);
|
|
1596
1563
|
}
|
|
1597
|
-
if (!runtime.ownsWorkflow(activeGoal))
|
|
1598
|
-
return reject("active Goal no longer owns its workflow");
|
|
1564
|
+
if (!runtime.ownsWorkflow(activeGoal)) return reject("active Goal no longer owns its workflow");
|
|
1599
1565
|
if (activeGoal.waiting) return reject("goal is already waiting");
|
|
1600
1566
|
if (!reason) return reject("reason is empty");
|
|
1601
1567
|
if (reason.length > MAX_GOAL_WAIT_REASON_LENGTH) return reject("reason is too long");
|