pi-better-goal 0.12.0 → 0.12.1
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 +31 -32
- package/src/prompt.ts +53 -0
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -30,6 +30,7 @@ import {
|
|
|
30
30
|
} from "./goal-state.js";
|
|
31
31
|
import { continuationEvidence, type ContinuationEvidence } from "./continuation.js";
|
|
32
32
|
import { currentPermissionHold, logicalPermissionBlockerKey, MAX_PERMISSION_BLOCKERS, MAX_PERMISSION_RECORDS, permissionHoldRecord, permissionInstruction, permissionRecord, reportedPermissionBlockers, reportedPermissionGap, type PermissionHold } from "./permission-hold.js";
|
|
33
|
+
import { publishGoalGuidance } from "./prompt.js";
|
|
33
34
|
import { observeGoalStall } from "./stall.js";
|
|
34
35
|
import {
|
|
35
36
|
flattenObjectiveForRail,
|
|
@@ -1360,12 +1361,12 @@ export default function (pi: ExtensionAPI): void {
|
|
|
1360
1361
|
(permissions.blockers.length === 0 ? "\nBlocker evidence is unavailable. Stay held; do not invent a retry scope." : "") : "";
|
|
1361
1362
|
// A held goal overrides workflow ownership without invoking or invalidating that workflow.
|
|
1362
1363
|
if (permissionPrompt && goal?.status === "paused") {
|
|
1363
|
-
return
|
|
1364
|
+
return publishGoalGuidance(event, permissionPrompt);
|
|
1364
1365
|
}
|
|
1365
1366
|
const pausedInstruction = permissionPrompt || (goal?.status === "paused" && (goal.pauseReason === "interrupt" || goal.pauseReason === "handback")
|
|
1366
1367
|
? pausedGoalPrompt(goal, preferences.conversationalResume, !harnessPresent) : "");
|
|
1367
1368
|
if (!isPokeable(goal) && !owner) {
|
|
1368
|
-
return
|
|
1369
|
+
return publishGoalGuidance(event, pausedInstruction);
|
|
1369
1370
|
}
|
|
1370
1371
|
|
|
1371
1372
|
const questionInstruction = snapshot.backgroundRunning
|
|
@@ -1379,31 +1380,28 @@ export default function (pi: ExtensionAPI): void {
|
|
|
1379
1380
|
if (!workflowAvailable(owner)) {
|
|
1380
1381
|
if (isPokeable(goal)) setGoal(goalWithStatus(goal, "paused"), ctx, "runtime");
|
|
1381
1382
|
recordWorkflow(null);
|
|
1382
|
-
return
|
|
1383
|
+
return publishGoalGuidance(event, `Workflow ${owner.name} is no longer a registered, valid skill. Stop work and ask the user to reinvoke the skill.`);
|
|
1383
1384
|
}
|
|
1384
1385
|
let instructions: string;
|
|
1385
1386
|
try {
|
|
1386
1387
|
instructions = readFileSync(owner.path, "utf8");
|
|
1387
1388
|
} catch {
|
|
1388
1389
|
if (isPokeable(goal)) setGoal(goalWithStatus(goal, "paused"), ctx, "runtime");
|
|
1389
|
-
return
|
|
1390
|
+
return publishGoalGuidance(event, `Workflow ${owner.name} is unavailable. Stop work and ask the user to restore or reinvoke the skill.`);
|
|
1390
1391
|
}
|
|
1391
|
-
return
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
(questionInstruction ? `\n\n${questionInstruction.trim()}` : "") +
|
|
1405
|
-
(heldInstruction ? `\n\n${heldInstruction}` : ""),
|
|
1406
|
-
};
|
|
1392
|
+
return publishGoalGuidance(
|
|
1393
|
+
event,
|
|
1394
|
+
pausedInstruction &&
|
|
1395
|
+
`${pausedInstruction}\n` + (permissionPrompt
|
|
1396
|
+
? "These permission constraints override the workflow instructions below.\n\n"
|
|
1397
|
+
: "While the goal is paused, this overrides the workflow instructions below: do not advance the workflow until the goal is resumed.\n\n"),
|
|
1398
|
+
`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}`,
|
|
1399
|
+
isPokeable(goal) && (harnessPresent
|
|
1400
|
+
? "Complete the goal only after the workflow completion audit."
|
|
1401
|
+
: `Active objective: ${goal.objective}. Complete it only after the workflow completion audit.`),
|
|
1402
|
+
questionInstruction && questionInstruction.trim(),
|
|
1403
|
+
heldInstruction,
|
|
1404
|
+
);
|
|
1407
1405
|
}
|
|
1408
1406
|
|
|
1409
1407
|
if (!isPokeable(goal)) return;
|
|
@@ -1413,18 +1411,19 @@ export default function (pi: ExtensionAPI): void {
|
|
|
1413
1411
|
if (harnessPresent) {
|
|
1414
1412
|
// Harness owns the outcome text. Retain only the Goal-specific guidance
|
|
1415
1413
|
// that the Outcome & Todo prompt cannot replace.
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1414
|
+
return publishGoalGuidance(
|
|
1415
|
+
event,
|
|
1416
|
+
heldInstruction,
|
|
1417
|
+
backgroundInstruction.trim(),
|
|
1418
|
+
questionInstruction.trim(),
|
|
1419
|
+
permissionPrompt,
|
|
1420
|
+
);
|
|
1421
|
+
}
|
|
1422
|
+
return publishGoalGuidance(
|
|
1423
|
+
event,
|
|
1424
|
+
`Pi Better Goal active objective: ${goal.objective}. ${heldInstruction || "Keep working through clear low-risk next steps, and mark complete only after an evidence-backed completion audit."}${backgroundInstruction}${questionInstruction}`,
|
|
1425
|
+
permissionPrompt,
|
|
1426
|
+
);
|
|
1428
1427
|
});
|
|
1429
1428
|
|
|
1430
1429
|
pi.on("agent_start", async (_event, ctx) => {
|
package/src/prompt.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Goal-owned system-prompt guidance.
|
|
3
|
+
*
|
|
4
|
+
* Published as a named section on hosts that render sections, never as a returned
|
|
5
|
+
* `systemPrompt` there: returning text sets `forceSystemPrompt`, and the request
|
|
6
|
+
* then carries an opaque rendered snapshot, so a section published afterwards
|
|
7
|
+
* never reaches the model.
|
|
8
|
+
*
|
|
9
|
+
* On older hosts (this package declares support back to pi 0.84.4) custom sections
|
|
10
|
+
* do not render at all, so the same text is appended instead. Publishing alone
|
|
11
|
+
* would silently deliver nothing on those versions.
|
|
12
|
+
*/
|
|
13
|
+
export const GOAL_SECTION = "goal";
|
|
14
|
+
|
|
15
|
+
/** The minimum shape this module needs; both the event options and a test double satisfy it. */
|
|
16
|
+
export interface PromptSectionTarget {
|
|
17
|
+
sections?: Record<string, string>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** What a handler receives; only these two fields are used. */
|
|
21
|
+
export interface BeforeAgentStartEvent {
|
|
22
|
+
systemPrompt: string;
|
|
23
|
+
systemPromptOptions?: unknown;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Mirrors `supportsPromptSections` in the vendored execution policy. */
|
|
27
|
+
function rendersSections(options: unknown): boolean {
|
|
28
|
+
const sections = (options as { sections?: unknown } | undefined)?.sections;
|
|
29
|
+
return typeof sections === "object" && sections !== null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Deliver guidance, choosing the channel this host understands.
|
|
34
|
+
*
|
|
35
|
+
* Appending within one turn is safe: pi normalizes a fresh options object for
|
|
36
|
+
* every `before_agent_start`, so this never accumulates between requests, and
|
|
37
|
+
* within a turn the parts belong together and keep their order.
|
|
38
|
+
*/
|
|
39
|
+
export function publishGoalGuidance(
|
|
40
|
+
event: BeforeAgentStartEvent,
|
|
41
|
+
...parts: Array<string | undefined | false>
|
|
42
|
+
): { systemPrompt: string } | undefined {
|
|
43
|
+
const text = parts.filter((part): part is string => typeof part === "string" && part.trim().length > 0).join("\n\n");
|
|
44
|
+
if (!text) return undefined;
|
|
45
|
+
if (!rendersSections(event.systemPromptOptions)) {
|
|
46
|
+
return { systemPrompt: `${event.systemPrompt}\n\n${text}` };
|
|
47
|
+
}
|
|
48
|
+
const target = event.systemPromptOptions as PromptSectionTarget;
|
|
49
|
+
const sections = (target.sections ??= {});
|
|
50
|
+
const existing = sections[GOAL_SECTION];
|
|
51
|
+
sections[GOAL_SECTION] = existing ? `${existing}\n\n${text}` : text;
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|