@howaboua/pi-notes-compaction 0.0.6 → 0.0.7

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/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # @howaboua/pi-notes-compaction
2
2
 
3
+ ## 0.0.7
4
+
5
+ - Shared local agent history now remains readable after its owner closes or Shepherdr is removed.
6
+
3
7
  ## 0.0.6
4
8
 
5
9
  - Requires Pi 1.2.0 or newer.
package/README.md CHANGED
@@ -18,7 +18,7 @@ With Pi Codex Conversion 3.0.48 or newer, local notes work alongside Codex tools
18
18
 
19
19
  The agent keeps the familiar `notes`, `history`, `new_context` and `get_context_remaining` tools. Notes use virtual paths. Relative paths belong to the current agent. History searches the selected Pi session branch, including earlier windows. It does not create a second transcript archive.
20
20
 
21
- Previously shared local notes remain readable after the other agent closes or Shepherdr is removed. Notes follows the saved family relationships and attachment aliases without requiring PCC. Reads use the other session's saved branch. When only a retained attachment snapshot is available, the result identifies it as detached or potentially stale. Cross-agent writes and history still require their live routing service.
21
+ Previously shared local notes and history remain readable after the other agent closes or Shepherdr is removed. Notes follows the saved family relationships and attachment aliases without requiring PCC. Reads use the other session's saved branch and preserve its history IDs. When only a retained attachment snapshot is available, notes identify it as detached or potentially stale. Snapshots do not contain history. Cross-agent writes still require their live routing service. Saved history reads do not fetch or decrypt remote history.
22
22
 
23
23
  By default, `new_context` starts a fresh window without generating a summary. The agent receives recent note paths, and Pi's saved history remains available for lookup.
24
24
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@howaboua/pi-notes-compaction",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -70,6 +70,7 @@ async function* reverseLines(file: FileHandle, size: number) {
70
70
  export async function readSavedNotesSession(
71
71
  path: string,
72
72
  signal?: AbortSignal,
73
+ history = false,
73
74
  ): Promise<SavedNotesSession> {
74
75
  signal?.throwIfAborted();
75
76
  const file = await open(path, "r");
@@ -104,7 +105,13 @@ export async function readSavedNotesSession(
104
105
  else if (active && NOTE_ENTRIES.has(entry.customType))
105
106
  branch.push(entry);
106
107
  else continue;
107
- } else if (active && Check(Handoff, entry)) branch.push(entry);
108
+ } else if (
109
+ active &&
110
+ history &&
111
+ (entry.type === "message" || entry.type === "custom_message")
112
+ )
113
+ branch.push(entry as SessionEntry);
114
+ else if (active && Check(Handoff, entry)) branch.push(entry);
108
115
  else continue;
109
116
  }
110
117
  const after = await file.stat();
@@ -5,6 +5,7 @@ import type {
5
5
  } from "@earendil-works/pi-coding-agent";
6
6
  import { type Static, Type } from "typebox";
7
7
  import { Check } from "typebox/value";
8
+ import { useHistory } from "./history.js";
8
9
  import { collectNotes, normalizeNoteParams, readNotes } from "./notes.js";
9
10
  import {
10
11
  readSavedNotesSession,
@@ -152,18 +153,44 @@ export async function readSharedNotes(
152
153
  store: Pick<NotesStore, "read">,
153
154
  params: Record<string, unknown>,
154
155
  signal?: AbortSignal,
156
+ ): Promise<Record<string, unknown> | undefined> {
157
+ return readSharedSession(ctx, store, params, "notes", signal);
158
+ }
159
+
160
+ export async function readSharedHistory(
161
+ ctx: ExtensionContext,
162
+ store: Pick<NotesStore, "read">,
163
+ params: Record<string, unknown>,
164
+ signal?: AbortSignal,
165
+ ): Promise<Record<string, unknown> | undefined> {
166
+ return readSharedSession(ctx, store, params, "history", signal);
167
+ }
168
+
169
+ async function readSharedSession(
170
+ ctx: ExtensionContext,
171
+ store: Pick<NotesStore, "read">,
172
+ params: Record<string, unknown>,
173
+ namespace: "notes" | "history",
174
+ signal?: AbortSignal,
155
175
  ): Promise<Record<string, unknown> | undefined> {
156
176
  if (
177
+ namespace === "notes" &&
157
178
  !["read_file", "list_files_by_prefix", "search_contents"].includes(
158
179
  String(params["action"]),
159
180
  )
160
181
  )
161
182
  return;
162
- const path = params["path"] ?? params["prefix"] ?? params["path_prefix"];
183
+ const path =
184
+ namespace === "history"
185
+ ? params["agent_name"]
186
+ : (params["path"] ?? params["prefix"] ?? params["path_prefix"]);
163
187
  if (typeof path !== "string" || !path.startsWith("/")) return;
164
- const target = /^(\/root(?:\/[a-zA-Z0-9_-]+)*?)\/notes(?:\/|$)/.exec(
165
- path,
166
- )?.[1];
188
+ const target =
189
+ namespace === "history"
190
+ ? /^\/root(?:\/[a-zA-Z0-9_-]+)*$/.test(path)
191
+ ? path
192
+ : undefined
193
+ : /^(\/root(?:\/[a-zA-Z0-9_-]+)*?)\/notes(?:\/|$)/.exec(path)?.[1];
167
194
  if (!target) return;
168
195
  const outputAgent = target;
169
196
  const current: SavedNotesSession = {
@@ -180,11 +207,13 @@ export async function readSharedNotes(
180
207
  native: string,
181
208
  ) {
182
209
  return {
183
- ...readNotes(
184
- collectNotes(store, session.branch),
185
- normalizeNoteParams(query, native),
186
- outputAgent,
187
- ),
210
+ ...(namespace === "history"
211
+ ? useHistory(session.branch, query, session.threadId)
212
+ : readNotes(
213
+ collectNotes(store, session.branch),
214
+ normalizeNoteParams(query, native),
215
+ outputAgent,
216
+ )),
188
217
  source: "saved-session",
189
218
  read_only: true,
190
219
  remote: { state: "not_fetched" },
@@ -201,10 +230,14 @@ export async function readSharedNotes(
201
230
  retained?: unknown,
202
231
  detached = false,
203
232
  ): Promise<Record<string, unknown> | undefined> {
204
- if (file && !detached) {
233
+ if (file && (!detached || namespace === "history")) {
205
234
  let saved: SavedNotesSession | undefined;
206
235
  try {
207
- saved = await readSavedNotesSession(file, signal);
236
+ saved = await readSavedNotesSession(
237
+ file,
238
+ signal,
239
+ namespace === "history",
240
+ );
208
241
  } catch (error) {
209
242
  signal?.throwIfAborted();
210
243
  if (
@@ -212,7 +245,8 @@ export async function readSharedNotes(
212
245
  error instanceof Error &&
213
246
  "code" in error &&
214
247
  error.code === "ENOENT" &&
215
- retained !== undefined
248
+ retained !== undefined &&
249
+ namespace === "notes"
216
250
  )
217
251
  )
218
252
  throw error;
@@ -223,7 +257,11 @@ export async function readSharedNotes(
223
257
  return resolve(saved, destination, query);
224
258
  }
225
259
  }
226
- if (destination !== identity.agentName || !Check(Snapshot, retained))
260
+ if (
261
+ namespace === "history" ||
262
+ destination !== identity.agentName ||
263
+ !Check(Snapshot, retained)
264
+ )
227
265
  return;
228
266
  const entry: SessionEntry = {
229
267
  type: "custom",
@@ -260,6 +298,7 @@ export async function readSharedNotes(
260
298
  const identity = savedNotesIdentity(session);
261
299
  if (identity.agentName === destination) {
262
300
  if (
301
+ namespace === "notes" &&
263
302
  identity.storage === "remote" &&
264
303
  !session.branch.some(
265
304
  (entry) =>
@@ -332,7 +371,11 @@ export async function readSharedNotes(
332
371
  );
333
372
  if (Check(Member, member)) {
334
373
  if (member.machine !== "local") return;
335
- const saved = await readSavedNotesSession(member.sessionFile, signal);
374
+ const saved = await readSavedNotesSession(
375
+ member.sessionFile,
376
+ signal,
377
+ namespace === "history",
378
+ );
336
379
  const child = savedNotesIdentity(saved);
337
380
  if (
338
381
  child.sessionId !== identity.sessionId ||
@@ -349,6 +392,7 @@ export async function readSharedNotes(
349
392
  const saved = await readSavedNotesSession(
350
393
  routing.parent.slice(0, -".shepherdr-context.json".length),
351
394
  signal,
395
+ namespace === "history",
352
396
  );
353
397
  const parent = savedNotesIdentity(saved);
354
398
  if (
package/src/tools.ts CHANGED
@@ -24,7 +24,11 @@ import {
24
24
  sourceSessionIds,
25
25
  useNotes,
26
26
  } from "./notes.js";
27
- import { readSharedNotes, sharedNotesUnavailable } from "./shared-notes.js";
27
+ import {
28
+ readSharedHistory,
29
+ readSharedNotes,
30
+ sharedNotesUnavailable,
31
+ } from "./shared-notes.js";
28
32
  import type { NotesStore } from "./store.js";
29
33
 
30
34
  const NOTES_ACTIONS = [
@@ -463,9 +467,33 @@ function createQueryExecutor(
463
467
  assertActive();
464
468
  const params = relevant("history", input);
465
469
  const query = { namespace: "history", params } as const;
466
- const routed =
467
- !shared && (await lifecycle.bridge?.route?.(query, callId, ctx, signal));
468
- if (routed) return routed;
470
+ if (!shared) {
471
+ try {
472
+ const routed = await lifecycle.bridge?.route?.(
473
+ query,
474
+ callId,
475
+ ctx,
476
+ signal,
477
+ );
478
+ if (routed) return routed;
479
+ } catch (error) {
480
+ signal?.throwIfAborted();
481
+ if (
482
+ !sharedNotesUnavailable(error) &&
483
+ !(
484
+ error instanceof Error &&
485
+ error.message ===
486
+ "Counterpart history requires its live attached owner; native history is unchanged"
487
+ )
488
+ )
489
+ throw error;
490
+ const saved = await readSharedHistory(ctx, store, params, signal);
491
+ if (saved) return result(saved);
492
+ throw error;
493
+ }
494
+ const saved = await readSharedHistory(ctx, store, params, signal);
495
+ if (saved) return result(saved);
496
+ }
469
497
  if (params["agent_name"] && params["agent_name"] !== lifecycle.agent(ctx))
470
498
  throw new Error(
471
499
  "That agent's history is not available here. Omit agent_name to search this session.",