@howaboua/pi-agent-comms 0.0.1-dev.14.1.g7d1d3da173aa → 0.0.2

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.
Files changed (38) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/README.md +4 -4
  3. package/docs/BOARD.md +2 -2
  4. package/docs/NOTES.md +14 -2
  5. package/package.json +5 -5
  6. package/src/board/briefing.ts +2 -2
  7. package/src/board/contract.ts +31 -27
  8. package/src/board/identity.ts +49 -29
  9. package/src/board/protocol.ts +98 -59
  10. package/src/board/settings/panel.ts +11 -8
  11. package/src/board/tool.ts +5 -0
  12. package/src/guidance.ts +14 -14
  13. package/src/notes/AGENTS.md +1 -1
  14. package/src/notes/attachment-snapshot.ts +33 -20
  15. package/src/notes/feature.ts +67 -1
  16. package/src/notes/history-search-pruning.mjs +110 -76
  17. package/src/notes/history-search-worker.mjs +1 -1
  18. package/src/notes/integrations.ts +6 -3
  19. package/src/notes/note-result.ts +70 -39
  20. package/src/notes/notes-lookup.ts +1 -1
  21. package/src/notes/query-input.ts +1 -0
  22. package/src/notes/saved-session-access.ts +12 -8
  23. package/src/notes/saved-session.ts +31 -15
  24. package/src/notes/saved-sharing-records.ts +110 -75
  25. package/src/notes/session-pruning-cleanup.mjs +163 -0
  26. package/src/notes/session-pruning-exit.mjs +312 -0
  27. package/src/notes/session-pruning-screen.ts +1 -1
  28. package/src/notes/session-pruning-sparse.mjs +133 -0
  29. package/src/notes/session-pruning-state.mjs +123 -0
  30. package/src/notes/session-pruning.ts +34 -1
  31. package/src/notes/settings-controls.ts +13 -17
  32. package/src/notes/settings-screen.ts +2 -6
  33. package/src/notes/shared-notes.ts +19 -11
  34. package/src/notes/shared-session-reader.ts +4 -2
  35. package/src/notes/tool-contracts.ts +71 -44
  36. package/src/notes/tools.ts +2 -2
  37. package/src/notes/tree-handoff-read.ts +47 -32
  38. package/src/notes/window-message.ts +6 -18
package/src/guidance.ts CHANGED
@@ -18,38 +18,40 @@ export interface CommsFeature extends FeatureSettings {
18
18
  function communicationGuidance(
19
19
  notes: boolean,
20
20
  board: boolean,
21
- agents: boolean,
22
21
  gpt = false,
23
22
  ): string {
24
23
  return [
25
24
  board
26
25
  ? gpt
27
- ? "Board→peer findings/discovery, ownership/decisions/blockers affecting peers. Self-contained detail welcome; direct discovery≠parent relay. Existing thread replies; known shared peers→link≠repeat. No ack/status spam/duplicate completion reports."
28
- : "Board: share findings, discoveries, ownership, decisions and blockers that change peers' work. Self-contained detail lets peers read directly, without a parent relay. Reply in existing threads. Link rather than repeat for peers with known Board access. Skip acknowledgements, routine status and duplicate completion reports."
26
+ ? "Board→new peer-work findings/decisions/ownership/blockers only; no change→no post. Peers read directly; no parent relay. No idle wake; active subscribers may be interrupted."
27
+ : "Board: post only findings, decisions, ownership changes or blockers that change peers' work. Peers read posts directly; do not relay them through the parent. Posts do not wake idle agents but may interrupt active subscribers."
29
28
  : "",
30
29
  notes
31
30
  ? [
31
+ gpt
32
+ ? "Notes writes don't wake peers."
33
+ : "Notes writes do not wake peers.",
32
34
  board
33
35
  ? gpt
34
- ? "Notes→current work/progress/recovery + Board references."
35
- : "Notes: current work, progress and recovery, with Board references."
36
+ ? "Notes→recovery; link Board evidence."
37
+ : "Notes holds recovery checkpoints; link Board evidence."
36
38
  : "",
37
39
  gpt
38
- ? "Keep Notes checkpoints. Known recipient access→brief outcome/blocker + path; recipient READS checkpoint≠request full report."
39
- : "Keep checkpoints in Notes. When the recipient is known to have access, return a brief outcome or blocker plus its path. The recipient reads the checkpoint for details rather than asking for a full report.",
40
+ ? "Known recipient Notes access→brief outcome/blocker + checkpoint path; recipient reads checkpoint instead of requesting its contents."
41
+ : "With known recipient Notes access, return a brief outcome or blocker plus the checkpoint path; the recipient reads the checkpoint instead of requesting its contents.",
40
42
  ]
41
43
  .filter(Boolean)
42
44
  .join(" ")
43
45
  : "",
44
46
  notes || board
45
47
  ? gpt
46
- ? `${notes && board ? "Notes/Board" : notes ? "Notes" : "Board"} available here≠recipient access. Unknown/unshared access→self-contained actions taken/findings/unresolved state, not bare references.`
47
- : `${notes && board ? "Notes and Board" : notes ? "Notes" : "Board"} availability here does not establish recipient access. If access is unknown or unshared, send a self-contained account of what you did, found and left unresolved, not just private references.`
48
+ ? `${notes && board ? "Notes/Board" : notes ? "Notes" : "Board"} available here≠recipient access. Known access→link≠repeat; otherwise self-contained actions/findings/unresolved state.`
49
+ : `${notes && board ? "Notes and Board" : notes ? "Notes" : "Board"} availability here does not establish recipient access. Link rather than repeat when access is known; otherwise give a self-contained account of actions, findings and unresolved state.`
48
50
  : "",
49
- agents && notes && board
51
+ notes || board
50
52
  ? gpt
51
- ? "agents→assignments/urgent action≠default peer knowledge bus."
52
- : "Use agents for assignments and urgent action, not as the default peer knowledge relay."
53
+ ? "Direct messages→assignments or urgent action, not status or courtesy updates."
54
+ : "Use direct messages for assignments or urgent action, not status or courtesy updates."
53
55
  : "",
54
56
  ]
55
57
  .filter(Boolean)
@@ -73,11 +75,9 @@ export function registerCommunicationGuidance(
73
75
  (ctx) => Boolean(notes?.enabled(ctx) || board?.enabled(ctx)),
74
76
  async (ctx, windowId, messages) => {
75
77
  // Feature owners supply enablement independently of provider declarations.
76
- // Shepherdr keeps agents active, including as a nested Code/Notebook tool.
77
78
  const capabilities = [
78
79
  notes?.enabled(ctx) ?? false,
79
80
  board?.enabled(ctx) ?? false,
80
- pi.getActiveTools().includes("agents"),
81
81
  Boolean(notes?.gptPromptMode() || board?.gptPromptMode()),
82
82
  ] as const;
83
83
  const routing = communicationGuidance(...capabilities);
@@ -21,7 +21,7 @@
21
21
  - Return initial and rebound identity from before_agent_start, never send it during startup. Pi inserts its initial system entry ahead of returned hook messages; startup sends otherwise put per-session identity before the shared cache prefix.
22
22
  - Automatic rollover uses the successor window message as its custom kickoff. That entry is not yet in the branch during before_agent_start; adopt its identity instead of restoring the outgoing window or returning another boundary.
23
23
  - Compaction handoff reads are transient branch contributions anchored to their persisted summary. Rechain only the projected branch, never append contributions or persist their IDs as Pi's first-kept boundary. Compare projected entry identity, not branch length.
24
- - Session pruning preserves JSONL order/count/IDs and unchanged raw lines; Observatory rebases derived source ranges using header `notesPruning` generations, never a tail receipt alone. Its final tail-copy/rename must contain no await. Released Pi's already-flushed same-path writes are append-only; re-trace SDK rewrite paths when changing this boundary. Do not mutate its live history or coordinate foreign JSONL writers.
24
+ - Live session pruning preserves JSONL order/count/IDs. Sparse cleanup runs only after the owning Pi process exits, never inside shutdown or on reload/fork. Retain roots, leaves, branchpoints, physical last and supported structured reference targets; skip live registered owners. FD checks do not prove an idle manager has closed. Observatory rebases derived ranges using new header `notesPruning` generations, never tail receipts alone. Final validation/rename must contain no await. Never mutate Pi's live history or coordinate foreign JSONL writers.
25
25
  - Pi persists incoming messages after before_agent_start, agent_start and message_end hooks, before returned startup messages. History assigns the kickoff prefix only to the first untrimmed window, never later or identity-only boundaries. Label saved-note continuation prompts in context once their entries exist. Schedule pruning from Notes' admitted window identity, then verify its persisted marker after settlement.
26
26
  - Pruning must not turn removed delivered instruction carriers into pending-message redelivery. Coalesce only proven complete state snapshots per branch leaf; unknown custom protocols can contain deltas. Keep current Notes revisions, monitor snapshots, Board routes and notebook epochs, not historical model-facing text disguised as state.
27
27
  - Role handoffs prepare the outgoing provider before selecting the successor model and starting the normal window kickoff. Keep checkpoint and compaction gates, rechecking session/window after async work. Role guidance exposes IDs/descriptions only. In-run compaction restores its persisted carrier before the summary without a new turn or prefix edit.
@@ -1,35 +1,48 @@
1
- import { Type } from "typebox";
2
- import { Check } from "typebox/value";
1
+ import {
2
+ arr,
3
+ compile,
4
+ lit,
5
+ num,
6
+ obj,
7
+ opt,
8
+ str,
9
+ union,
10
+ } from "@earendil-works/pi-schema";
3
11
  import { contextTargetAgent, isContextAgentName } from "./agent-identity.js";
4
12
  import type { RemoteNoteReference } from "./context-sharing.js";
5
13
  import { normalizeNoteParams, readNotes } from "./notes.js";
6
14
  import type { NoteRevision } from "./store.js";
7
15
 
8
- const Snapshot = Type.Object({
9
- protocol: Type.Literal(1),
10
- timestamp: Type.Number({ minimum: 0 }),
11
- files: Type.Array(
12
- Type.Object({
13
- path: Type.String(),
14
- text: Type.String(),
15
- createdAt: Type.Number(),
16
- updatedAt: Type.Number(),
17
- operation: Type.Optional(
18
- Type.Union([
19
- Type.Literal("local_append_overlay"),
20
- Type.Literal("local_replacement"),
21
- ]),
16
+ const Snapshot = obj(
17
+ {
18
+ protocol: lit(1),
19
+ timestamp: num({ minimum: 0 }),
20
+ files: arr(
21
+ obj(
22
+ {
23
+ path: str(),
24
+ text: str(),
25
+ createdAt: num(),
26
+ updatedAt: num(),
27
+ operation: opt(
28
+ union([lit("local_append_overlay"), lit("local_replacement")]),
29
+ ),
30
+ },
31
+ { open: true },
22
32
  ),
23
- }),
24
- ),
25
- });
33
+ ),
34
+ },
35
+ { open: true },
36
+ );
37
+
38
+ const snapshotValidator = compile(Snapshot);
26
39
 
27
40
  /** Retained checkpoints remain readable without a running owner or database. */
28
41
  export function readAttachmentSnapshot(
29
42
  snapshot: unknown,
30
43
  params: Record<string, unknown>,
31
44
  ): Record<string, unknown> {
32
- if (!Check(Snapshot, snapshot))
45
+ if (!snapshotValidator.check(snapshot))
33
46
  throw new Error("Invalid retained note snapshot");
34
47
  if (
35
48
  !["list_files_by_prefix", "read_file", "search_contents"].includes(
@@ -7,6 +7,11 @@ import type {
7
7
  import type { CommsFeature } from "../guidance.js";
8
8
  import type { OpenSettings } from "../settings-navigation.js";
9
9
  import type { NotesRuntime } from "./index.js";
10
+ import {
11
+ admitSessionCleanup,
12
+ previousCleanupFailure,
13
+ } from "./session-pruning-exit.mjs";
14
+ import { cleanupStatus } from "./session-pruning-state.mjs";
10
15
  import {
11
16
  legacyNotesConfigured,
12
17
  loadNotesSettings,
@@ -53,6 +58,43 @@ export function createNotesFeature(
53
58
  let store: NotesStore | undefined;
54
59
  let storage: Promise<NotesStore> | undefined;
55
60
  let closed = false;
61
+ let staleOpening = false;
62
+ let releaseCleanupOwner: (() => void) | undefined;
63
+ const admit = async (ctx: ExtensionContext) => {
64
+ if (releaseCleanupOwner) return !staleOpening;
65
+ let reason: string | undefined;
66
+ try {
67
+ const claim = await admitSessionCleanup(
68
+ ctx.sessionManager.getSessionFile(),
69
+ ctx.sessionManager.getSessionId(),
70
+ ctx.sessionManager.getHeader(),
71
+ );
72
+ releaseCleanupOwner = claim?.release;
73
+ if (claim?.stale)
74
+ reason =
75
+ "This session was cleaned while Pi was opening it. Restart Pi to load its saved tree safely.";
76
+ } catch (error) {
77
+ reason = `Pi could not safely open this session: ${String(error)}. Resolve the problem and restart Pi.`;
78
+ }
79
+ if (!reason) return true;
80
+ staleOpening = true;
81
+ console.error(reason);
82
+ ctx.ui.notify(reason, "error");
83
+ if (ctx.mode === "rpc") {
84
+ // RPC honours startup shutdown after attaching input. Returning lets it
85
+ // reach that check before accepting normal commands.
86
+ ctx.shutdown();
87
+ return false;
88
+ }
89
+ if (ctx.mode === "tui") ctx.shutdown();
90
+ else {
91
+ // Released print/json mode installs graceful SIGTERM handling before
92
+ // session_start, but does not bind the documented ctx.shutdown action.
93
+ process.kill(process.pid, "SIGTERM");
94
+ }
95
+ // Do not finish binding or start an initial prompt/tree while exiting.
96
+ await new Promise<never>(() => {});
97
+ };
56
98
  const ensureStore = () =>
57
99
  (storage ??= (async () => {
58
100
  const { NotesStore } = await import("./store.js");
@@ -110,6 +152,22 @@ export function createNotesFeature(
110
152
  await open(ctx);
111
153
  });
112
154
  pi.on("session_start", async (_event, ctx) => {
155
+ if (!(await admit(ctx))) return;
156
+ const file = ctx.sessionManager.getSessionFile();
157
+ if (file) {
158
+ try {
159
+ const error = previousCleanupFailure(
160
+ cleanupStatus(file, dirname(notesSettingsPath())),
161
+ ctx.sessionManager.getSessionId(),
162
+ );
163
+ if (error) ctx.ui.notify(error, "warning");
164
+ } catch (error) {
165
+ ctx.ui.notify(
166
+ `Previous session cleanup status could not be read: ${String(error)}. Check Notes storage permissions and retry.`,
167
+ "warning",
168
+ );
169
+ }
170
+ }
113
171
  try {
114
172
  settings = loadNotesSettings(ctx);
115
173
  writeSettings(notesSettingsPath(), settings);
@@ -126,12 +184,20 @@ export function createNotesFeature(
126
184
  );
127
185
  }
128
186
  });
187
+ pi.on("agent_settled", async (_event, ctx) => {
188
+ // A brand-new session has no JSONL file until its first persisted turn.
189
+ await admit(ctx);
190
+ });
129
191
  pi.on("model_select", async (_event, ctx) => {
130
192
  if (!runtime && settings && modelIsActive(settings, ctx.model))
131
193
  await ensure(ctx);
132
194
  });
133
- pi.on("session_shutdown", () => {
195
+ pi.on("session_shutdown", (event) => {
134
196
  closed = true;
197
+ if (event.reason !== "quit") {
198
+ releaseCleanupOwner?.();
199
+ releaseCleanupOwner = undefined;
200
+ }
135
201
  store?.close();
136
202
  });
137
203
  pi.registerCommand("notes", {
@@ -1,6 +1,7 @@
1
1
  import { open } from "node:fs/promises";
2
+ import { StringDecoder } from "node:string_decoder";
2
3
 
3
- /** @typedef {{file:string; sessionId:string; generation:string; excluded:Set<string>}} PrunedHistory */
4
+ /** @typedef {{file:string; sessionId:string; generation:string; size:number; surviving:Set<string>; excluded:Set<string>}} PrunedHistory */
4
5
 
5
6
  /** The live SessionManager still contains old text until restart. Read the committed
6
7
  * source so later indexing, settings toggles and /reload cannot resurrect its terms.
@@ -8,11 +9,11 @@ import { open } from "node:fs/promises";
8
9
  export function createHistoryPruning() {
9
10
  /** @type {PrunedHistory | undefined} */
10
11
  let cached;
11
- const empty = new Set();
12
+ const empty = () => false;
12
13
  /** @param {import("./sqlite.mjs").Database} db
13
14
  * @param {string} sessionId
14
15
  * @param {string | undefined} file
15
- * @returns {Promise<ReadonlySet<string>>}
16
+ * @returns {Promise<(id:string) => boolean>}
16
17
  */
17
18
  return async (db, sessionId, file) => {
18
19
  if (!file) return empty;
@@ -25,92 +26,125 @@ export function createHistoryPruning() {
25
26
  return empty;
26
27
  throw error;
27
28
  }
28
- let stream;
29
29
  try {
30
30
  const { size } = await input.stat();
31
31
  if (!size) return empty;
32
- stream = input.createReadStream({
33
- start: 0,
34
- end: size - 1,
35
- autoClose: false,
36
- encoding: "utf8",
37
- });
38
- /** @type {PrunedHistory | undefined} */
39
- let source;
40
- let pending = "";
41
- for await (const chunk of stream) {
42
- pending += chunk;
43
- let start = 0;
44
- let end;
45
- while ((end = pending.indexOf("\n", start)) >= 0) {
46
- const entry = JSON.parse(pending.slice(start, end));
47
- start = end + 1;
48
- if (!source) {
49
- if (entry.type !== "session" || entry.id !== sessionId)
50
- throw new Error("History source identity changed");
51
- const marker = entry.notesPruning;
52
- if (marker === undefined) return empty;
53
- if (
54
- marker?.version !== 1 ||
55
- marker.sessionId !== sessionId ||
56
- typeof marker.generation !== "string"
57
- )
58
- throw new Error("Invalid history pruning marker");
59
- if (
60
- cached?.file === file &&
61
- cached.sessionId === sessionId &&
62
- cached.generation === marker.generation
63
- )
64
- return cached.excluded;
65
- source = {
66
- file,
67
- sessionId,
68
- generation: marker.generation,
69
- excluded: new Set(),
70
- };
71
- continue;
32
+ let header;
33
+ for await (const entry of records(input, 0, size)) {
34
+ header = entry;
35
+ break;
36
+ }
37
+ if (header?.type !== "session" || header.id !== sessionId)
38
+ throw new Error("History source identity changed");
39
+ const marker = header.notesPruning;
40
+ if (marker === undefined) return empty;
41
+ if (
42
+ marker?.version !== 1 ||
43
+ marker.sessionId !== sessionId ||
44
+ typeof marker.generation !== "string"
45
+ )
46
+ throw new Error("Invalid history pruning marker");
47
+ const previous =
48
+ cached?.file === file &&
49
+ cached.sessionId === sessionId &&
50
+ cached.generation === marker.generation &&
51
+ cached.size <= size
52
+ ? cached
53
+ : undefined;
54
+ const incremental = previous !== undefined;
55
+ if (previous?.size === size) return exclusion(previous);
56
+ /** @type {PrunedHistory} */
57
+ const source = previous ?? {
58
+ file,
59
+ sessionId,
60
+ generation: marker.generation,
61
+ size: 0,
62
+ surviving: new Set(),
63
+ excluded: new Set(),
64
+ };
65
+ // A failed suffix scan invalidates mutated cache sets. Ordinary appends
66
+ // scan only their suffix, not the full session or every indexed document.
67
+ cached = undefined;
68
+ for await (const entry of records(input, source.size, size)) {
69
+ if (!incremental && entry.type === "session") continue;
70
+ if (typeof entry.id !== "string" || source.surviving.has(entry.id))
71
+ throw new Error("Invalid history source entry identity");
72
+ source.surviving.add(entry.id);
73
+ const message = entry.type === "message" ? entry.message : undefined;
74
+ if (
75
+ (entry.type === "custom" &&
76
+ entry.customType === "notes-compaction:pruned:v1") ||
77
+ (["user", "assistant"].includes(message?.role) &&
78
+ !visibleText(message.content))
79
+ )
80
+ source.excluded.add(entry.id);
81
+ }
82
+ source.size = size;
83
+ const excluded = exclusion(source);
84
+ if (!incremental) {
85
+ const removeTerms = db.prepare(
86
+ "DELETE FROM history_terms WHERE rowid = ?",
87
+ );
88
+ const removeDocument = db.prepare(
89
+ "DELETE FROM history_documents WHERE id = ?",
90
+ );
91
+ /** @type {import("./sqlite.mjs").Statement<[string], {id:number; item_id:string}>} */
92
+ const documents = db.prepare(
93
+ "SELECT id, item_id FROM history_documents WHERE session_id = ?",
94
+ );
95
+ db.transaction(() => {
96
+ for (const row of documents.all(sessionId)) {
97
+ if (!excluded(row.item_id)) continue;
98
+ removeTerms.run(row.id);
99
+ removeDocument.run(row.id);
72
100
  }
73
- const message = entry.type === "message" ? entry.message : undefined;
74
- if (
75
- (entry.type === "custom" &&
76
- entry.customType === "notes-compaction:pruned:v1") ||
77
- (["user", "assistant"].includes(message?.role) &&
78
- !visibleText(message.content))
79
- )
80
- source.excluded.add(entry.id);
81
- }
82
- pending = pending.slice(start);
101
+ }).immediate();
83
102
  }
84
- // Only complete lines from the opened inode count. A concurrent append's
85
- // incomplete suffix is new history, never an old pruned conversation.
86
- if (!source) throw new Error("History source header is missing");
87
- const excluded = source.excluded;
88
- const removeTerms = db.prepare(
89
- "DELETE FROM history_terms WHERE rowid = ?",
90
- );
91
- const removeDocument = db.prepare(
92
- "DELETE FROM history_documents WHERE id = ?",
93
- );
94
- /** @type {import("./sqlite.mjs").Statement<[string], {id:number; item_id:string}>} */
95
- const documents = db.prepare(
96
- "SELECT id, item_id FROM history_documents WHERE session_id = ?",
97
- );
98
- db.transaction(() => {
99
- for (const row of documents.all(sessionId)) {
100
- if (!excluded.has(row.item_id)) continue;
101
- removeTerms.run(row.id);
102
- removeDocument.run(row.id);
103
- }
104
- }).immediate();
105
103
  cached = source;
106
104
  return excluded;
107
105
  } finally {
108
- stream?.destroy();
109
106
  await input.close();
110
107
  }
111
108
  };
112
109
  }
113
110
 
111
+ /** @param {import("node:fs/promises").FileHandle} input @param {number} start @param {number} size */
112
+ async function* records(input, start, size) {
113
+ const buffer = Buffer.alloc(64 * 1024);
114
+ const decoder = new StringDecoder("utf8");
115
+ let pending = "";
116
+ for (let position = start; position < size; ) {
117
+ const { bytesRead } = await input.read(
118
+ buffer,
119
+ 0,
120
+ Math.min(buffer.length, size - position),
121
+ position,
122
+ );
123
+ if (!bytesRead)
124
+ throw new Error("History source changed during reconciliation");
125
+ position += bytesRead;
126
+ pending += decoder.write(buffer.subarray(0, bytesRead));
127
+ let offset = 0;
128
+ let end;
129
+ while ((end = pending.indexOf("\n", offset)) >= 0) {
130
+ yield JSON.parse(pending.slice(offset, end));
131
+ offset = end + 1;
132
+ }
133
+ pending = pending.slice(offset);
134
+ }
135
+ pending += decoder.end();
136
+ if (pending.length)
137
+ throw new Error(
138
+ "History source has an incomplete record; retry after the turn completes",
139
+ );
140
+ }
141
+
142
+ /** @param {PrunedHistory} source */
143
+ function exclusion(source) {
144
+ /** @param {string} id */
145
+ return (id) => !source.surviving.has(id) || source.excluded.has(id);
146
+ }
147
+
114
148
  /** @param {unknown} content */
115
149
  function visibleText(content) {
116
150
  return typeof content === "string"
@@ -97,7 +97,7 @@ async function index(request) {
97
97
  }
98
98
  }
99
99
  for (const item of request.items) {
100
- if (excluded.has(item.item_id)) continue;
100
+ if (excluded(item.item_id)) continue;
101
101
  const fingerprint = createHash("sha256")
102
102
  .update(item.content)
103
103
  .digest("hex");
@@ -3,6 +3,7 @@ import type {
3
3
  ExtensionAPI,
4
4
  ExtensionContext,
5
5
  } from "@earendil-works/pi-coding-agent";
6
+ import type { Schema } from "@earendil-works/pi-schema";
6
7
  import type { NotesActivation } from "./activation.js";
7
8
  import type { NotesLifecycle } from "./lifecycle.js";
8
9
  import {
@@ -54,6 +55,7 @@ export async function registerNotesToolIntegrations(
54
55
  throw error;
55
56
  }
56
57
  let refreshNested = () => {};
58
+ const noteProperties = NOTES_SCHEMA["properties"] as Record<string, Schema>;
57
59
  try {
58
60
  const { adaptToolForCodeMode, registerCodeModeExtensionTools } =
59
61
  await import("@howaboua/pi-codex-conversion/code-mode");
@@ -72,14 +74,15 @@ export async function registerNotesToolIntegrations(
72
74
  ? { resultValue: historyResultValue }
73
75
  : {}),
74
76
  }),
75
- // Code checks inputs before Pi can normalise this body alias.
77
+ // Code checks inputs before Pi can normalise these aliases.
76
78
  ...(tool.name === "notes"
77
79
  ? {
78
80
  inputSchema: {
79
81
  ...NOTES_SCHEMA,
80
82
  properties: {
81
- ...NOTES_SCHEMA.properties,
82
- content: NOTES_SCHEMA.properties.text,
83
+ ...noteProperties,
84
+ content: noteProperties["text"],
85
+ end_line: noteProperties["stop_line"],
83
86
  },
84
87
  },
85
88
  }