@matthewfl/pi-contemplator 0.1.14 → 0.1.15

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": "@matthewfl/pi-contemplator",
3
- "version": "0.1.14",
3
+ "version": "0.1.15",
4
4
  "description": "A Pi extension that keeps long-running agentic sessions on track with background memory, contemplation, and structural review.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -50,10 +50,11 @@
50
50
  "@earendil-works/pi-tui": "*"
51
51
  },
52
52
  "devDependencies": {
53
- "@earendil-works/pi-agent-core": "^0.84.4",
54
- "@earendil-works/pi-ai": "^0.84.4",
55
- "@earendil-works/pi-coding-agent": "^0.84.4",
56
- "@earendil-works/pi-tui": "^0.84.4",
53
+ "@earendil-works/pi-agent-core": "^0.85.0",
54
+ "@earendil-works/pi-ai": "^0.85.0",
55
+ "@earendil-works/pi-coding-agent": "^0.85.0",
56
+ "@earendil-works/pi-server": "^0.85.0",
57
+ "@earendil-works/pi-tui": "^0.85.0",
57
58
  "@types/node": "^22.0.0",
58
59
  "typebox": "^1.1.38",
59
60
  "typescript": "^5.6.0",
@@ -506,6 +506,8 @@ export class Contemplator {
506
506
  this.history = [];
507
507
  this.historyEntryIds = [];
508
508
  const historyMessagesByEntryId = new Map<string, AgentMessage>();
509
+ const checkpointCoveredObservationIds = new Set<string>();
510
+ const checkpointCoveredReviewIds = new Set<string>();
509
511
  let resetProjection: ReturnType<typeof fullProjection> | undefined;
510
512
  if (resetTracking) {
511
513
  this.deliveredProbeIds.clear();
@@ -539,7 +541,7 @@ export class Contemplator {
539
541
  }
540
542
  }
541
543
  if (entry.customType === CONTEMPLATOR_MESSAGE && entry.data && typeof entry.data === "object") {
542
- const data = entry.data as { message?: unknown; compacted?: unknown; retainedMessageEntryIds?: unknown };
544
+ const data = entry.data as { message?: unknown; compacted?: unknown; retainedMessageEntryIds?: unknown; coveredObservationIds?: unknown; coveredReviewIds?: unknown };
543
545
  const message = data.message;
544
546
  if (message && typeof message === "object") {
545
547
  const typedMessage = message as AgentMessage;
@@ -550,6 +552,8 @@ export class Contemplator {
550
552
  : [];
551
553
  this.history = [typedMessage, ...retainedIds.map((id) => historyMessagesByEntryId.get(id)!)];
552
554
  this.historyEntryIds = [entry.id, ...retainedIds];
555
+ if (Array.isArray(data.coveredObservationIds)) for (const id of data.coveredObservationIds) if (typeof id === "string") checkpointCoveredObservationIds.add(id);
556
+ if (Array.isArray(data.coveredReviewIds)) for (const id of data.coveredReviewIds) if (typeof id === "string") checkpointCoveredReviewIds.add(id);
553
557
  } else {
554
558
  this.history.push(typedMessage);
555
559
  this.historyEntryIds.push(entry.id);
@@ -607,10 +611,10 @@ export class Contemplator {
607
611
  }
608
612
  }
609
613
  if (resetTracking && resetProjection) {
610
- // Successful contemplator update prompts are the durable coverage record.
611
- // Only memories present in those prompts are considered seen after reload;
612
- // memories from a failed, unpersisted run remain pending and retryable.
613
- const coveredIds = new Set<string>();
614
+ // Successful update prompts and private-history compaction checkpoints are
615
+ // the durable coverage record. Checkpoints carry ids from prompts replaced
616
+ // by their summary; failed, unpersisted runs remain pending and retryable.
617
+ const coveredIds = new Set<string>([...checkpointCoveredObservationIds, ...checkpointCoveredReviewIds]);
614
618
  for (const message of this.history) {
615
619
  if (message.role !== "user") continue;
616
620
  const text = customMessageText(message.content);
@@ -1359,7 +1363,28 @@ export class Contemplator {
1359
1363
  debugLog("contemplator.compaction_postponed", { reason: "retained history lacked durable entry ids", retainedMessageCount: retainedMessages.length, retainedReferenceCount: retainedMessageEntryIds.length });
1360
1364
  return;
1361
1365
  }
1362
- const checkpoint = { version: 2, compacted: true, message: summaryMessage, retainedMessageEntryIds };
1366
+ // Record only coverage evidenced by the exact durable prompt prefix being
1367
+ // replaced. `seen*Ids` may also contain observations appended concurrently
1368
+ // while summary generation awaited; those remain pending and must not be
1369
+ // declared covered before their own prompt is persisted. Coverage is a delta
1370
+ // per checkpoint, and restore unions checkpoints, avoiding cumulative O(n²)
1371
+ // id duplication across a very long session.
1372
+ const prefixCoveredIds = new Set<string>();
1373
+ for (const message of history.slice(0, prefixEnd)) {
1374
+ if (message.role !== "user") continue;
1375
+ const text = customMessageText(message.content);
1376
+ if (!text.includes("NEW MEMORY UPDATE")) continue;
1377
+ for (const id of memoryReferenceIds(text)) prefixCoveredIds.add(id);
1378
+ }
1379
+ const currentProjection = fullProjection(ctx.sessionManager.getBranch() as Entry[]);
1380
+ const checkpoint = {
1381
+ version: 2,
1382
+ compacted: true,
1383
+ message: summaryMessage,
1384
+ retainedMessageEntryIds,
1385
+ coveredObservationIds: currentProjection.observations.filter((item) => prefixCoveredIds.has(item.id)).map((item) => item.id),
1386
+ coveredReviewIds: (currentProjection.reviews ?? []).filter((item) => prefixCoveredIds.has(item.id)).map((item) => item.id),
1387
+ };
1363
1388
  const checkpointEntryId = this.appendContemplatorHistoryEntry(ctx, checkpoint);
1364
1389
  this.history = [summaryMessage, ...retainedMessages];
1365
1390
  this.historyEntryIds = [checkpointEntryId, ...retainedMessageEntryIds];