pi-posthorse 0.10.30 → 0.10.32
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 +6 -6
- package/src/recovery-notes.ts +27 -22
- package/src/recovery.ts +46 -29
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-posthorse",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.32",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Posthorse: fresh context, same journey. No-summary context rollover for Pi, with sparse budget reminders, handoffs, notes, and history.",
|
|
6
6
|
"keywords": [
|
|
@@ -51,8 +51,8 @@
|
|
|
51
51
|
"lint:fix:oxlint": "oxlint --fix ."
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
|
-
"@earendil-works/pi-coding-agent": ">=1.5.
|
|
55
|
-
"@earendil-works/pi-tui": ">=1.5.
|
|
54
|
+
"@earendil-works/pi-coding-agent": ">=1.5.2",
|
|
55
|
+
"@earendil-works/pi-tui": ">=1.5.2",
|
|
56
56
|
"typebox": "*"
|
|
57
57
|
},
|
|
58
58
|
"peerDependenciesMeta": {
|
|
@@ -67,9 +67,9 @@
|
|
|
67
67
|
}
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
|
-
"@earendil-works/pi-ai": "1.5.
|
|
71
|
-
"@earendil-works/pi-coding-agent": "1.5.
|
|
72
|
-
"@earendil-works/pi-tui": "1.5.
|
|
70
|
+
"@earendil-works/pi-ai": "1.5.2",
|
|
71
|
+
"@earendil-works/pi-coding-agent": "1.5.2",
|
|
72
|
+
"@earendil-works/pi-tui": "1.5.2",
|
|
73
73
|
"@types/node": "24.19.1",
|
|
74
74
|
"oxc-parser": "0.157.0",
|
|
75
75
|
"oxfmt": "0.76.0",
|
package/src/recovery-notes.ts
CHANGED
|
@@ -196,26 +196,24 @@ function sessionNotes(
|
|
|
196
196
|
sources.notes === undefined ? defaultDir : scopeDirectory(sources.notes.binding),
|
|
197
197
|
};
|
|
198
198
|
}
|
|
199
|
+
/**
|
|
200
|
+
* The task notes a chain wrote or read. `primaryNotePath` names the most recently written note
|
|
201
|
+
* the chain has not since cleared. `section` renders the note lines that fit a character budget;
|
|
202
|
+
* every rendered section ends with an instruction that names that note.
|
|
203
|
+
*/
|
|
199
204
|
export function sessionNotesEvidence(
|
|
200
205
|
chainEntries: readonly EntryLike[],
|
|
201
206
|
allEntries: readonly EntryLike[],
|
|
202
207
|
projected: readonly ProjectedEntry[],
|
|
203
|
-
options: NoteSources & {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
const { span
|
|
208
|
+
options: NoteSources & { readonly span: RetainedSpan | undefined },
|
|
209
|
+
): {
|
|
210
|
+
readonly primaryNotePath: string | undefined;
|
|
211
|
+
readonly section: (maxChars: number) => string | undefined;
|
|
212
|
+
} {
|
|
213
|
+
const { span } = options;
|
|
209
214
|
const { all, notesDirectory } = sessionNotes(chainEntries, allEntries, projected, options);
|
|
210
|
-
if (all.length === 0) {
|
|
211
|
-
return { section: undefined, primaryNotePath: undefined };
|
|
212
|
-
}
|
|
213
215
|
const written = all.filter((note) => note.kind === "written").slice(0, MAX_WRITTEN_NOTES);
|
|
214
216
|
const primary = written[0];
|
|
215
|
-
const primaryNotePath =
|
|
216
|
-
primary === undefined
|
|
217
|
-
? undefined
|
|
218
|
-
: (pathElsewhere(primary, notesDirectory) ?? primary.absPath ?? primary.notePath);
|
|
219
217
|
const readOnly = all.filter((note) => note.kind === "read").slice(0, MAX_READ_NOTES);
|
|
220
218
|
const lines = [
|
|
221
219
|
...written.map((note) => formatWrittenNoteLine(note, span, notesDirectory)),
|
|
@@ -223,15 +221,20 @@ export function sessionNotesEvidence(
|
|
|
223
221
|
];
|
|
224
222
|
const header = "Task notes in this session:";
|
|
225
223
|
const action = formatNotesAction(primary, span, notesDirectory);
|
|
226
|
-
const selected: string[] = [];
|
|
227
|
-
for (const line of lines) {
|
|
228
|
-
if ([header, ...selected, line, action].join("\n").length <= maxChars) {
|
|
229
|
-
selected.push(line);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
224
|
return {
|
|
233
|
-
|
|
234
|
-
|
|
225
|
+
primaryNotePath:
|
|
226
|
+
primary === undefined
|
|
227
|
+
? undefined
|
|
228
|
+
: (pathElsewhere(primary, notesDirectory) ?? primary.absPath ?? primary.notePath),
|
|
229
|
+
section: (maxChars) => {
|
|
230
|
+
const selected: string[] = [];
|
|
231
|
+
for (const line of lines) {
|
|
232
|
+
if ([header, ...selected, line, action].join("\n").length <= maxChars) {
|
|
233
|
+
selected.push(line);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
return selected.length === 0 ? undefined : [header, ...selected, action].join("\n");
|
|
237
|
+
},
|
|
235
238
|
};
|
|
236
239
|
}
|
|
237
240
|
export function renderSessionNotes(
|
|
@@ -243,5 +246,7 @@ export function renderSessionNotes(
|
|
|
243
246
|
readonly maxChars: number;
|
|
244
247
|
},
|
|
245
248
|
): string | undefined {
|
|
246
|
-
return sessionNotesEvidence(chainEntries, allEntries, projected, options).section
|
|
249
|
+
return sessionNotesEvidence(chainEntries, allEntries, projected, options).section(
|
|
250
|
+
options.maxChars,
|
|
251
|
+
);
|
|
247
252
|
}
|
package/src/recovery.ts
CHANGED
|
@@ -208,35 +208,53 @@ function sharedLimit(lengths: readonly number[], budget: number): number {
|
|
|
208
208
|
}
|
|
209
209
|
return MAX_RECOVERY_RECORD_CHARS;
|
|
210
210
|
}
|
|
211
|
-
|
|
211
|
+
type ChainNotes = ReturnType<typeof sessionNotesEvidence> & {
|
|
212
|
+
readonly span: RetainedSpan | undefined;
|
|
213
|
+
};
|
|
214
|
+
/** Task notes of the current automatic chain, with the retained span their lines refer to. */
|
|
215
|
+
function chainNotes(
|
|
212
216
|
entries: readonly EntryLike[],
|
|
213
217
|
projected: readonly ProjectedEntry[],
|
|
214
|
-
|
|
218
|
+
sources: {
|
|
215
219
|
readonly retained: ReadonlySet<string>;
|
|
216
|
-
readonly reserveParts: readonly (string | undefined)[];
|
|
217
220
|
readonly notes?: NotesRecovery | undefined;
|
|
218
|
-
readonly maxChars: number;
|
|
219
221
|
},
|
|
220
|
-
):
|
|
221
|
-
const
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
entries.slice(automaticChainStart(entries)),
|
|
227
|
-
entries,
|
|
228
|
-
projected,
|
|
229
|
-
{
|
|
230
|
-
retained,
|
|
222
|
+
): ChainNotes {
|
|
223
|
+
const span = retainedSpan(entries.slice(contextStart(entries).start), sources.retained);
|
|
224
|
+
return {
|
|
225
|
+
span,
|
|
226
|
+
...sessionNotesEvidence(entries.slice(automaticChainStart(entries)), entries, projected, {
|
|
227
|
+
...sources,
|
|
231
228
|
span,
|
|
232
|
-
|
|
233
|
-
|
|
229
|
+
}),
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* The preamble with its notes section, and the older checkpoint the record still quotes. A note
|
|
234
|
+
* written in the chain is newer than everything the checkpoint that opened the chain describes.
|
|
235
|
+
* A section that names such a note therefore replaces the checkpoint, and no room is held for
|
|
236
|
+
* it. A record too small for that section keeps the checkpoint.
|
|
237
|
+
*/
|
|
238
|
+
function rolloverPreamble(
|
|
239
|
+
notes: ChainNotes,
|
|
240
|
+
reserveParts: readonly (string | undefined)[],
|
|
241
|
+
checkpoint: EntryLike | undefined,
|
|
242
|
+
maxChars: number,
|
|
243
|
+
): { readonly preamble: string; readonly checkpoint: EntryLike | undefined } {
|
|
244
|
+
const base = buildRolloverPreamble(notes.span);
|
|
245
|
+
const section = (kept?: EntryLike) => {
|
|
246
|
+
const reserved = joined([base, ...reserveParts, priorCheckpoint(kept, 0)]).length;
|
|
247
|
+
return notes.section(
|
|
248
|
+
Math.min(
|
|
234
249
|
MAX_NOTES_SECTION_CHARS,
|
|
235
|
-
Math.max(0, maxChars -
|
|
250
|
+
Math.max(0, maxChars - reserved - HANDOFF_OVERHEAD_RESERVE),
|
|
236
251
|
),
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
252
|
+
);
|
|
253
|
+
};
|
|
254
|
+
const superseding = notes.primaryNotePath === undefined ? undefined : section();
|
|
255
|
+
return superseding === undefined
|
|
256
|
+
? { preamble: joined([base, section(checkpoint)]), checkpoint }
|
|
257
|
+
: { preamble: joined([base, superseding]), checkpoint: undefined };
|
|
240
258
|
}
|
|
241
259
|
/** Raw owner anchors and projected tool evidence have distinct provenance and share one bounded payload. */
|
|
242
260
|
export function buildAutoRecovery(
|
|
@@ -255,7 +273,6 @@ export function buildAutoRecovery(
|
|
|
255
273
|
retained,
|
|
256
274
|
maxChars,
|
|
257
275
|
});
|
|
258
|
-
const priorWindow = history.checkpoint;
|
|
259
276
|
const emptyInputHeader =
|
|
260
277
|
retained.size > 0
|
|
261
278
|
? "No discarded owner or visible coordination inputs were selected for this recovery record."
|
|
@@ -270,16 +287,16 @@ export function buildAutoRecovery(
|
|
|
270
287
|
inputHeader,
|
|
271
288
|
...fixed.map((record) => formatRecord(record, 0)),
|
|
272
289
|
header,
|
|
273
|
-
priorCheckpoint(priorWindow, 0),
|
|
274
290
|
skippedRecords(history.skipped, 0),
|
|
275
291
|
];
|
|
276
|
-
const
|
|
277
|
-
|
|
292
|
+
const notes = chainNotes(entries, projected, { retained, notes: options.notes });
|
|
293
|
+
const { preamble, checkpoint: priorWindow } = rolloverPreamble(
|
|
294
|
+
notes,
|
|
278
295
|
reserveParts,
|
|
296
|
+
history.checkpoint,
|
|
279
297
|
maxChars,
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
const minimum = [preamble, ...reserveParts];
|
|
298
|
+
);
|
|
299
|
+
const minimum = [preamble, ...reserveParts, priorCheckpoint(priorWindow, 0)];
|
|
283
300
|
const plan = planBatch(
|
|
284
301
|
batch,
|
|
285
302
|
header,
|
|
@@ -316,7 +333,7 @@ export function buildAutoRecovery(
|
|
|
316
333
|
);
|
|
317
334
|
return {
|
|
318
335
|
handoff: joined([...fixedParts, renderIndex(others, available), renderedBatch, prior]),
|
|
319
|
-
primaryNotePath,
|
|
336
|
+
primaryNotePath: notes.primaryNotePath,
|
|
320
337
|
};
|
|
321
338
|
}
|
|
322
339
|
export function buildAutoHandoff(
|