pi-better-goal 0.12.1 → 0.12.2
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 +5 -3
- package/package.json +1 -1
- package/src/index.ts +2 -2
- package/src/workflow-gates.ts +60 -14
- package/src/workflow.ts +7 -0
package/README.md
CHANGED
|
@@ -65,10 +65,12 @@ After every successful context compaction (Pi's `session_compact` event) while a
|
|
|
65
65
|
|
|
66
66
|
### Scheduler-backed workflow gates
|
|
67
67
|
|
|
68
|
-
A coordinator that ships the resolve-issues scheduler (`scripts/next-actions.mjs` in its skill directory, or in a sibling `resolve-issues` skill) keeps its Goal from ending while the run still has work. The extension first runs `node next-actions.mjs --run <run dir> --slots 1 --peek --json` (read-only, 20-second timeout), where the run directory is the folder of the task plan bound through `
|
|
68
|
+
A coordinator that ships the resolve-issues scheduler (`scripts/next-actions.mjs` in its skill directory, or in a sibling `resolve-issues` skill) keeps its Goal from ending while the run still has work. The extension first runs `node next-actions.mjs --run <run dir> --slots 1 --peek --json` (read-only, 20-second timeout), where the run directory is the folder of the task plan bound through `update_todo` with `workflow.path` and `workflow.revision`. For completion and handback only, if the sole due action is `sync`, it reruns with `--sync` to obtain a fresh issue tree. This live check has a four-minute timeout to accommodate the tree fetcher's network attempts and follow-ups. Because `--peek` suppresses scheduler bookkeeping but not issue-tree cache writes, the live check uses a temporary copy of the scheduler's plan, tree, bookkeeping, review, and result inputs; it does not write the bound run. Heartbeat probes never request live synchronization. A failed or incomplete tree fetch that produces `sync` still refuses completion or handback; cached evidence is not treated as live. Output that is not a well-formed due list is a failure, not an empty run: a due entry without an `action` invalidates the whole answer instead of being dropped, so it cannot hide due work.
|
|
69
69
|
|
|
70
|
-
-
|
|
71
|
-
|
|
70
|
+
How a gate reports an unverifiable run follows the workflow that owns it. The issue workflows (`rush-issues` and `resolve-issues`) always have a scheduler available (rush-issues through its `resolve-issues` dependency), so only that scheduler can declare their run finished: a missing plan, a missing scheduler, a scheduler error, a timeout, or invalid output refuses completion and leaves the Goal active and the workflow bound. A coordinator that ships no scheduler, such as a release workflow, has no run authority to consult, so its completion gate keeps the fail-open warning that avoids deadlocking it.
|
|
71
|
+
|
|
72
|
+
- **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.
|
|
73
|
+
- **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.
|
|
72
74
|
- **Auto-bind.** 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.
|
|
73
75
|
- **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.
|
|
74
76
|
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -42,7 +42,7 @@ import {
|
|
|
42
42
|
import { createRenderScheduler } from "./shared-render-scheduler.js";
|
|
43
43
|
import { initializeNavigatorPanels, setNavigatorPanel } from "./shared-navigator-panels.js";
|
|
44
44
|
import { collectSubagentActivity } from "./subagents.js";
|
|
45
|
-
import { currentWorkflowOwner, skillCommandName, workflowEntry, workflowOwnerFromSkill, WORKFLOW_ENTRY_TYPE } from "./workflow.js";
|
|
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
48
|
import { requestTaskContext } from "./task-context.js";
|
|
@@ -66,7 +66,7 @@ const MAX_TIMER_DELAY_MS = 2_147_483_647;
|
|
|
66
66
|
/** Never re-poll a workflow's scheduler sooner than this, even when its stated attempt time has passed. */
|
|
67
67
|
const MIN_WAIT_DELAY_MS = 5_000;
|
|
68
68
|
/** Workflow skills whose invocation binds a goal when none is active, so the run cannot stop silently. */
|
|
69
|
-
const AUTO_BIND_SKILLS =
|
|
69
|
+
const AUTO_BIND_SKILLS = ISSUE_WORKFLOW_SKILLS;
|
|
70
70
|
const WAKE_DISABLED =
|
|
71
71
|
process.env.PI_BETTER_GOAL_DISABLE_WAKE === "1" ||
|
|
72
72
|
process.env.PI_BETTER_EXTENSION_DISABLE_WAKE === "1";
|
package/src/workflow-gates.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { cpSync, existsSync, mkdtempSync, readFileSync, rmSync, statSync } from
|
|
|
3
3
|
import { tmpdir } from "node:os";
|
|
4
4
|
import { dirname, join } from "node:path";
|
|
5
5
|
|
|
6
|
-
import type
|
|
6
|
+
import { ISSUE_WORKFLOW_SKILLS, type WorkflowOwner } from "./workflow.js";
|
|
7
7
|
|
|
8
8
|
/** Branch entry the plan extension writes when it binds a workflow-owned task plan. */
|
|
9
9
|
const WORKFLOW_PLAN_ENTRY = "pi-better-workflow-plan";
|
|
@@ -88,13 +88,18 @@ function parseSchedulerOutput(stdout: string): SchedulerRun {
|
|
|
88
88
|
return { ok: false, reason: "the scheduler printed output that is not JSON" };
|
|
89
89
|
}
|
|
90
90
|
if (!isRecord(parsed) || !Array.isArray(parsed.due)) return { ok: false, reason: "the scheduler output has no due list" };
|
|
91
|
-
const due
|
|
92
|
-
|
|
91
|
+
const due: SchedulerAction[] = [];
|
|
92
|
+
for (const item of parsed.due) {
|
|
93
|
+
// A malformed entry could hide due work, so it invalidates the answer instead of being dropped.
|
|
94
|
+
if (!isRecord(item) || typeof item.action !== "string") {
|
|
95
|
+
return { ok: false, reason: "the scheduler output has a due entry without an action" };
|
|
96
|
+
}
|
|
97
|
+
due.push({
|
|
93
98
|
action: item.action,
|
|
94
99
|
unit: item.unit === null || item.unit === undefined ? null : String(item.unit),
|
|
95
100
|
detail: typeof item.detail === "string" ? item.detail : "",
|
|
96
|
-
}
|
|
97
|
-
|
|
101
|
+
});
|
|
102
|
+
}
|
|
98
103
|
return { ok: true, due };
|
|
99
104
|
}
|
|
100
105
|
|
|
@@ -114,6 +119,10 @@ function executeScheduler(script: string, runDir: string, timeoutMs: number, liv
|
|
|
114
119
|
if (error) {
|
|
115
120
|
// An exit status of 1 means "actions due"; any other failure (exit 2, timeout, spawn error) is real.
|
|
116
121
|
if ((error as { code?: unknown }).code !== 1) {
|
|
122
|
+
if ((error as { killed?: unknown }).killed === true) {
|
|
123
|
+
resolve({ ok: false, reason: `the scheduler timed out after ${timeoutMs} ms` });
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
117
126
|
const detail = String(stderr).trim().split("\n")[0] || error.message;
|
|
118
127
|
resolve({ ok: false, reason: `the scheduler failed (${detail.slice(0, DETAIL_LIMIT)})` });
|
|
119
128
|
return;
|
|
@@ -150,11 +159,14 @@ interface PlannedRun {
|
|
|
150
159
|
script: string;
|
|
151
160
|
}
|
|
152
161
|
|
|
153
|
-
|
|
162
|
+
/** The run a gate would check, or what it could not locate, so each gate decides how to report it. */
|
|
163
|
+
type RunLocation = PlannedRun | { missing: "scheduler" | "plan"; problem: string };
|
|
164
|
+
|
|
165
|
+
function locateRun(entries: Iterable<EntryLike>, owner: WorkflowOwner): RunLocation {
|
|
154
166
|
const script = findScheduler(owner);
|
|
155
|
-
if (!script) return {
|
|
167
|
+
if (!script) return { missing: "scheduler", problem: `${owner.name} ships no scheduler` };
|
|
156
168
|
const plan = boundPlanPath(entries, owner);
|
|
157
|
-
if (!plan) return {
|
|
169
|
+
if (!plan) return { missing: "plan", problem: `no task plan is bound for ${owner.name} yet` };
|
|
158
170
|
return { runDir: dirname(plan), script };
|
|
159
171
|
}
|
|
160
172
|
|
|
@@ -167,16 +179,50 @@ function describe(action: SchedulerAction): string {
|
|
|
167
179
|
return `- ${action.action}${action.unit ? ` (unit ${action.unit})` : ""}: ${detail}`;
|
|
168
180
|
}
|
|
169
181
|
|
|
170
|
-
/**
|
|
182
|
+
/** Coordinators whose runs the resolve-issues scheduler drives, so only it can declare the run finished. */
|
|
183
|
+
function schedulerOwnsCompletion(owner: WorkflowOwner): boolean {
|
|
184
|
+
return ISSUE_WORKFLOW_SKILLS.has(owner.name);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function unverifiedCompletion(owner: WorkflowOwner, problem: string, recovery: string): GateVerdict {
|
|
188
|
+
return {
|
|
189
|
+
allow: false,
|
|
190
|
+
due: [],
|
|
191
|
+
message: `Goal not marked complete: ${problem}, so the run's completion is not verified. ${recovery} ` +
|
|
192
|
+
`The ${owner.name} workflow stays bound and the Goal stays active.`,
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Completion is allowed only when the scheduler reports `finish` and nothing else is due. For the
|
|
198
|
+
* issue workflows an unavailable plan or scheduler never counts as permission: the run has a
|
|
199
|
+
* completion authority, and only that authority may declare it finished. Any other coordinator has
|
|
200
|
+
* no scheduler to consult, so its gate keeps the fail-open warning that avoids deadlocking it.
|
|
201
|
+
*/
|
|
171
202
|
export async function completionGate(
|
|
172
203
|
entries: Iterable<EntryLike>,
|
|
173
204
|
owner: WorkflowOwner,
|
|
174
205
|
options: { timeoutMs?: number } = {},
|
|
175
206
|
): Promise<GateVerdict> {
|
|
207
|
+
const owned = schedulerOwnsCompletion(owner);
|
|
176
208
|
const located = locateRun(entries, owner);
|
|
177
|
-
if ("
|
|
209
|
+
if ("missing" in located) {
|
|
210
|
+
if (!owned) return unchecked(`${located.problem}, so the run was not checked`);
|
|
211
|
+
const recovery = located.missing === "plan"
|
|
212
|
+
? `Bind the run's task plan with update_todo({workflow:{path,revision}}), or rebind the run with /skill:${owner.name}, ` +
|
|
213
|
+
"then call update_goal again once the scheduler reports finish."
|
|
214
|
+
: `Restore the run's scheduler or rebind the run with /skill:${owner.name}, ` +
|
|
215
|
+
"then call update_goal again once the scheduler reports finish.";
|
|
216
|
+
return unverifiedCompletion(owner, located.problem, recovery);
|
|
217
|
+
}
|
|
178
218
|
const run = await settlementScheduler(located.script, located.runDir, options.timeoutMs);
|
|
179
|
-
if (!run.ok)
|
|
219
|
+
if (!run.ok) {
|
|
220
|
+
const problem = `the ${owner.name} run could not be checked (${run.reason})`;
|
|
221
|
+
if (!owned) return unchecked(problem);
|
|
222
|
+
return unverifiedCompletion(owner, problem,
|
|
223
|
+
`Fix the scheduler, or rebind the run with /skill:${owner.name} if its plan moved, ` +
|
|
224
|
+
"then call update_goal again once the scheduler reports finish.");
|
|
225
|
+
}
|
|
180
226
|
const open = run.due.filter((action) => action.action !== "finish");
|
|
181
227
|
if (open.length === 0 && run.due.length > 0) return { allow: true };
|
|
182
228
|
if (open.length === 0) {
|
|
@@ -215,7 +261,7 @@ export async function pauseGate(
|
|
|
215
261
|
options: { timeoutMs?: number } = {},
|
|
216
262
|
): Promise<GateVerdict> {
|
|
217
263
|
const located = locateRun(entries, owner);
|
|
218
|
-
if ("
|
|
264
|
+
if ("missing" in located) return unchecked(`${located.problem}, so the run was not checked`);
|
|
219
265
|
const units = readUnits(located.runDir);
|
|
220
266
|
if (!units) return unchecked(`could not read the ${owner.name} task plan`);
|
|
221
267
|
const run = await settlementScheduler(located.script, located.runDir, options.timeoutMs);
|
|
@@ -271,7 +317,7 @@ export async function operationResumeSchedulerGate(
|
|
|
271
317
|
options: { timeoutMs?: number } = {},
|
|
272
318
|
): Promise<OperationResumeSchedulerGate> {
|
|
273
319
|
const located = locateRun(entries, owner);
|
|
274
|
-
if ("
|
|
320
|
+
if ("missing" in located) return { ok: false, reason: `${located.problem}, so the run was not checked` };
|
|
275
321
|
const run = await runScheduler(located.script, located.runDir, options.timeoutMs);
|
|
276
322
|
if (!run.ok) return { ok: false, reason: `Workflow admission evidence unavailable: ${run.reason}` };
|
|
277
323
|
return { ok: true, waitUntil: waitUntil(run.due) };
|
|
@@ -284,7 +330,7 @@ export async function schedulerWaitUntil(
|
|
|
284
330
|
options: { timeoutMs?: number } = {},
|
|
285
331
|
): Promise<number | undefined> {
|
|
286
332
|
const located = locateRun(entries, owner);
|
|
287
|
-
if ("
|
|
333
|
+
if ("missing" in located) return undefined;
|
|
288
334
|
const run = await runScheduler(located.script, located.runDir, options.timeoutMs);
|
|
289
335
|
return run.ok ? waitUntil(run.due) : undefined;
|
|
290
336
|
}
|
package/src/workflow.ts
CHANGED
|
@@ -3,6 +3,13 @@ import { parse } from "yaml";
|
|
|
3
3
|
|
|
4
4
|
export const WORKFLOW_ENTRY_TYPE = "pi-better-workflow";
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Coordinators whose runs the resolve-issues scheduler drives, so only its next-actions scheduler can
|
|
8
|
+
* declare the run finished. Other coordinators (a release workflow, say) ship no scheduler, and their
|
|
9
|
+
* completion gates keep the fail-open behavior that avoids deadlocking them.
|
|
10
|
+
*/
|
|
11
|
+
export const ISSUE_WORKFLOW_SKILLS: ReadonlySet<string> = new Set(["rush-issues", "resolve-issues"]);
|
|
12
|
+
|
|
6
13
|
export interface WorkflowOwner {
|
|
7
14
|
name: string;
|
|
8
15
|
path: string;
|