pi-better-goal 0.16.1 → 0.16.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-better-goal",
3
- "version": "0.16.1",
3
+ "version": "0.16.3",
4
4
  "description": "Pi extension for goal tracking with background-aware continuation.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -106,6 +106,10 @@ export class AssignmentInbox {
106
106
  this.db.exec(this.shared ? `RELEASE ${this.alias}_ack` : "COMMIT");
107
107
  } catch (error) { this.db.exec(this.shared ? `ROLLBACK TO ${this.alias}_ack; RELEASE ${this.alias}_ack` : "ROLLBACK"); throw error; }
108
108
  }
109
+ get hasPendingChanges() {
110
+ return Boolean(this.more || this.db.prepare(`SELECT 1 FROM ${this.prefix}pending LIMIT 1`).get());
111
+ }
112
+
109
113
  get metrics() {
110
114
  const pending = this.db.prepare(`SELECT count(*) AS pending, min(since) AS oldestPendingAt FROM ${this.prefix}pending`).get();
111
115
  return { ...this.db.prepare(`SELECT * FROM ${this.prefix}position`).get(),
@@ -1,4 +1,3 @@
1
- import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
1
  import { existsSync } from "node:fs";
3
2
 
4
3
  export interface GoalCommandBinding {
@@ -8,12 +7,20 @@ export interface GoalCommandBinding {
8
7
  args: string;
9
8
  }
10
9
 
10
+ interface CommandRegistry {
11
+ getCommands(): readonly {
12
+ name: string;
13
+ source: GoalCommandBinding["source"];
14
+ sourceInfo: { path?: string | undefined };
15
+ }[];
16
+ }
17
+
11
18
  export function leadingCommand(text: string): { name: string; args: string } | null {
12
19
  const match = /^\/([^\s/]+)(?:\s+([\s\S]*))?$/.exec(text.trim());
13
20
  return match ? { name: match[1]!, args: match[2]?.trim() ?? "" } : null;
14
21
  }
15
22
 
16
- export function resolveGoalCommand(pi: ExtensionAPI, text: string): GoalCommandBinding | null {
23
+ export function resolveGoalCommand(pi: CommandRegistry, text: string): GoalCommandBinding | null {
17
24
  const parsed = leadingCommand(text);
18
25
  if (!parsed) return null;
19
26
  if (parsed.name === "goal") throw new Error("A goal cannot invoke /goal recursively.");
@@ -23,7 +30,7 @@ export function resolveGoalCommand(pi: ExtensionAPI, text: string): GoalCommandB
23
30
  return { name: command.name, source: command.source, path: command.sourceInfo.path, args: parsed.args };
24
31
  }
25
32
 
26
- export function commandAvailable(pi: ExtensionAPI, binding: GoalCommandBinding): boolean {
33
+ export function commandAvailable(pi: CommandRegistry, binding: GoalCommandBinding): boolean {
27
34
  return (binding.source === "extension" || existsSync(binding.path)) &&
28
35
  pi.getCommands().some((command) => command.name === binding.name &&
29
36
  command.source === binding.source && command.sourceInfo.path === binding.path);
package/src/index.ts CHANGED
@@ -368,8 +368,8 @@ export default function (pi: ExtensionAPI): void {
368
368
  return false;
369
369
  }
370
370
  };
371
- const recordWorkflow = (owner: ReturnType<typeof currentWorkflowOwner>): void => {
372
- pi.appendEntry(WORKFLOW_ENTRY_TYPE, workflowEntry(owner));
371
+ const recordWorkflow = (owner: ReturnType<typeof currentWorkflowOwner>, resumePlan = false): void => {
372
+ pi.appendEntry(WORKFLOW_ENTRY_TYPE, { ...workflowEntry(owner), ...(resumePlan && { resumePlan }) });
373
373
  pi.events.emit("pi-better-workflow:changed", owner);
374
374
  };
375
375
 
@@ -1008,14 +1008,14 @@ export default function (pi: ExtensionAPI): void {
1008
1008
  if (validateObjective(objective)) return;
1009
1009
  const owner = getWorkflow(ctx);
1010
1010
  if (owner && !workflowAvailable(owner)) return;
1011
- const retainedCommand = objective.startsWith("/") ? reopenedGoal?.command : undefined;
1011
+ const retainedCommand = reopenedGoal?.command;
1012
+ if (retainedCommand && !commandAvailable(pi, retainedCommand)) return;
1012
1013
  const command = retainedCommand ?? (owner ? resolveGoalCommand(pi, `/skill:${owner.name}`) : null);
1013
1014
  const goal = createGoalSnapshot(objective, null, undefined, command ?? undefined);
1015
+ const restoredOwner = retainedCommand ? goalWorkflowOwner(goal) : null;
1016
+ if (restoredOwner && owner && (restoredOwner.name !== owner.name || restoredOwner.path !== owner.path)) return;
1014
1017
  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
- }
1018
+ if (restoredOwner && !owner) recordWorkflow(restoredOwner, true);
1019
1019
  resetContinuationState(goal);
1020
1020
  });
1021
1021
 
@@ -1230,7 +1230,8 @@ export default function (pi: ExtensionAPI): void {
1230
1230
  }
1231
1231
  const audit = requestTaskContext(pi, "audit", current);
1232
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()));
1233
+ const evidence = [...input.evidence ?? [], ...audit.evidence ?? []];
1234
+ const missing = criteria.filter(criterion => !evidence.some(item => item.criterion === criterion && item.result.trim()));
1234
1235
  if (audit.ledgerBlocker || audit.openSteps?.length || missing.length) {
1235
1236
  const message = [
1236
1237
  "Verify the requested outcome before completing the Goal.",
@@ -90,6 +90,7 @@ export function createAssignmentReader(path, inboxPath = ":memory:", derivedConn
90
90
  connection(refresh = true) { if (refresh) this.revision(); return db; },
91
91
  changes() { this.revision(); return inbox.receive(db, identity); },
92
92
  acknowledgeChanges(batch, complete) { inbox.acknowledge(batch, complete); },
93
+ get hasPendingChanges() { return inbox.hasPendingChanges; },
93
94
  get changeMetrics() { return inbox.metrics; },
94
95
  get snapshotActive() { return snapshot; },
95
96
 
@@ -40,6 +40,8 @@ export interface TaskContextRequest {
40
40
  action: TaskContextAction;
41
41
  doneWhen?: readonly string[];
42
42
  openSteps?: readonly string[];
43
+ /** Evidence retained by a finished workflow bound to this Goal. */
44
+ evidence?: readonly { criterion: string; result: string }[];
43
45
  ledgerBlocker?: string;
44
46
  goalId?: string;
45
47
  /** Current widget width on a visual ownership inspection. */
@@ -73,7 +73,9 @@ export function boundPlanPath(entries: Iterable<EntryLike>, owner: WorkflowOwner
73
73
  for (const entry of entries) {
74
74
  if (entry.type !== "custom") continue;
75
75
  const data = entry.data;
76
- if (entry.customType === WORKFLOW_ENTRY && isRecord(data) && data.version === 1 && data.kind === "set") path = undefined;
76
+ if (entry.customType === WORKFLOW_ENTRY && isRecord(data) && data.version === 1 && data.kind === "set") {
77
+ if (data.resumePlan !== true || !isRecord(data.owner) || data.owner.name !== owner.name) path = undefined;
78
+ }
77
79
  if (entry.customType !== WORKFLOW_PLAN_ENTRY || !isRecord(data) || data.version !== 1) continue;
78
80
  if (data.kind === "clear") path = undefined;
79
81
  else if (data.kind === "set" && data.owner === owner.name && typeof data.path === "string") path = data.path;