pi-better-goal 0.14.2 → 0.14.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.14.2",
3
+ "version": "0.14.3",
4
4
  "description": "Pi extension for goal tracking with background-aware continuation.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -65,6 +65,8 @@ export function createAssignmentReader(path) {
65
65
  db ??= new DatabaseSync(path, { readOnly: true });
66
66
  return `${identity}:${db.prepare("PRAGMA data_version").get().data_version}`;
67
67
  },
68
+ connection(refresh = true) { if (refresh) this.revision(); return db; },
69
+
68
70
  beginSnapshot() {
69
71
  this.revision();
70
72
  if (snapshot) throw new Error("Coordinator snapshot already open");
@@ -80,6 +82,7 @@ export function createAssignmentReader(path) {
80
82
  return { revision: this.revision(), release };
81
83
  } catch (error) { release(); throw error; }
82
84
  },
85
+
83
86
  read(owner) {
84
87
  try {
85
88
  this.revision();
@@ -115,6 +118,33 @@ export function createAssignmentReader(path) {
115
118
  return new Map([...hashes].map(([key, hash]) => [key, hash.digest("hex")]));
116
119
  } catch { return undefined; }
117
120
  },
121
+ upgradeObligations() {
122
+ try { this.revision(); } catch (error) {
123
+ if (error.code === "ENOENT") return [];
124
+ throw error;
125
+ }
126
+ const version = db.prepare("SELECT value FROM schema_meta WHERE key='schema_version'").get()?.value;
127
+ if (!["1", "2", "3", "4"].includes(version)) throw new Error("Unsupported coordinator schema during upgrade");
128
+ const obligations = db.prepare("SELECT operation_id, task_id, observer_kind FROM operations WHERE phase='running' AND terminal_revision=0").all()
129
+ .map(row => ({ kind: "unsettled-operation", id: row.task_id, operationId: row.operation_id, observer: row.observer_kind }));
130
+ const reasons = db.prepare("SELECT claim_id AS id, state FROM resume_claims WHERE state IN ('claimed', 'published')").all()
131
+ .map(row => ({ kind: "resume-claim", id: row.id, state: row.state }));
132
+ for (const row of db.prepare("SELECT wait_id, generation, phase FROM waits WHERE owner_kind='worker-conversation' AND phase NOT IN ('consumed', 'cancelled') AND dispatch_disarmed=0").all()) {
133
+ reasons.push({ kind: "worker-wait", id: row.wait_id, generation: row.generation, phase: row.phase });
134
+ }
135
+ if (db.prepare("SELECT 1 FROM sqlite_master WHERE type='table' AND name='subagent_launch_intents'").get()) {
136
+ for (const row of db.prepare("SELECT owner, request_key, attempts FROM subagent_launch_intents WHERE state='accepted'").all()) {
137
+ reasons.push({ kind: "launch-intent", id: row.request_key, owner: row.owner, attempts: JSON.parse(row.attempts).map(attempt => attempt.id) });
138
+ }
139
+ }
140
+ for (const row of db.prepare("SELECT value FROM coordinator_state WHERE key LIKE 'background-request-v1:%'").all()) {
141
+ const request = JSON.parse(row.value);
142
+ if (request.state !== 'returned') reasons.push({kind:'background-request', id:request.key, owner:request.owner});
143
+ }
144
+ return [...obligations, ...reasons];
145
+ },
146
+
118
147
  close() { if (snapshot) { db.exec("ROLLBACK"); snapshot = false; } db?.close(); db = undefined; statements.clear(); identity = undefined; },
148
+
119
149
  };
120
150
  }