notesoup 0.61.0 → 0.62.0

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 (200) hide show
  1. package/.agents/plugins/marketplace.json +15 -0
  2. package/README.md +14 -11
  3. package/dist/plugins/antigravity/src/cli.d.ts +1 -0
  4. package/dist/plugins/antigravity/src/cli.js +23 -0
  5. package/dist/plugins/antigravity/src/hooks.d.ts +18 -0
  6. package/dist/plugins/antigravity/src/hooks.js +53 -0
  7. package/dist/plugins/antigravity/src/identity.d.ts +26 -0
  8. package/dist/plugins/antigravity/src/identity.js +129 -0
  9. package/dist/plugins/claude/src/helper.js +2 -1
  10. package/dist/plugins/codex/src/hooks.js +1 -0
  11. package/dist/plugins/codex/src/identity.d.ts +6 -1
  12. package/dist/plugins/codex/src/identity.js +13 -1
  13. package/dist/plugins/codex/src/mcp.d.ts +35 -7
  14. package/dist/plugins/codex/src/mcp.js +26 -88
  15. package/dist/plugins/codex/src/text.js +3 -3
  16. package/dist/plugins/dsh/tools.js +8 -4
  17. package/dist/plugins/mcp/operations.d.ts +15 -0
  18. package/dist/plugins/mcp/operations.js +43 -0
  19. package/dist/plugins/mcp/server.d.ts +14 -0
  20. package/dist/plugins/mcp/server.js +13 -0
  21. package/dist/plugins/pi/budget.d.ts +1 -1
  22. package/dist/plugins/pi/budget.js +3 -2
  23. package/dist/plugins/pi/entries.d.ts +1 -0
  24. package/dist/plugins/pi/entries.js +1 -0
  25. package/dist/plugins/pi/history-tools.js +2 -1
  26. package/dist/plugins/pi/history.js +18 -1
  27. package/dist/plugins/pi/notes/tools.js +7 -3
  28. package/dist/plugins/pi/render.d.ts +7 -1
  29. package/dist/plugins/pi/render.js +2 -2
  30. package/dist/plugins/pi/reset/lifecycle.d.ts +1 -1
  31. package/dist/plugins/pi/reset/lifecycle.js +8 -9
  32. package/dist/plugins/pi/runtime.js +102 -61
  33. package/dist/plugins/pi/tool-result.js +7 -7
  34. package/dist/plugins/pi/window.d.ts +33 -3
  35. package/dist/plugins/pi/window.js +209 -9
  36. package/dist/src/boot/render.js +18 -15
  37. package/dist/src/boot/text.d.ts +3 -1
  38. package/dist/src/boot/text.js +22 -20
  39. package/dist/src/budget/text.d.ts +2 -2
  40. package/dist/src/budget/text.js +13 -13
  41. package/dist/src/history/claude.d.ts +2 -0
  42. package/dist/src/history/claude.js +46 -0
  43. package/dist/src/history/codex-transcript.js +7 -5
  44. package/dist/src/history/codex.js +3 -0
  45. package/dist/src/history/corpus.d.ts +28 -1
  46. package/dist/src/history/corpus.js +40 -0
  47. package/dist/src/history/history.d.ts +37 -46
  48. package/dist/src/history/history.js +21 -40
  49. package/dist/src/history/local.js +67 -32
  50. package/dist/src/history/pi.d.ts +2 -1
  51. package/dist/src/history/pi.js +122 -48
  52. package/dist/src/history/prefilter.js +76 -19
  53. package/dist/src/history/query.d.ts +28 -49
  54. package/dist/src/history/query.js +83 -68
  55. package/dist/src/history/summary-cache.d.ts +8 -1
  56. package/dist/src/history/summary-cache.js +138 -12
  57. package/dist/src/index.d.ts +1 -1
  58. package/dist/src/index.js +1 -1
  59. package/dist/src/notes/errors.d.ts +1 -1
  60. package/dist/src/notes/frontmatter.d.ts +0 -2
  61. package/dist/src/notes/frontmatter.js +0 -2
  62. package/dist/src/notes/index.d.ts +1 -1
  63. package/dist/src/notes/index.js +1 -1
  64. package/dist/src/notes/policy.d.ts +15 -1
  65. package/dist/src/notes/policy.js +46 -5
  66. package/dist/src/notes/store.d.ts +12 -0
  67. package/dist/src/notes/store.js +16 -20
  68. package/dist/src/text-match.d.ts +10 -1
  69. package/dist/src/text-match.js +42 -3
  70. package/dist/src/tools/dream.d.ts +22 -93
  71. package/dist/src/tools/dream.js +30 -27
  72. package/dist/src/tools/history.d.ts +33 -26
  73. package/dist/src/tools/history.js +257 -163
  74. package/dist/src/tools/notes.d.ts +51 -163
  75. package/dist/src/tools/notes.js +146 -100
  76. package/dist/src/tools/output.d.ts +2 -1
  77. package/dist/src/tools/output.js +2 -1
  78. package/dist/src/tools/result.d.ts +4 -7
  79. package/dist/src/tools/result.js +8 -9
  80. package/dist/src/tools/schema.d.ts +4 -1
  81. package/dist/src/tools/schema.js +25 -1
  82. package/dist/test/agent-loop.test.js +198 -16
  83. package/dist/test/antigravity-live.test.d.ts +1 -0
  84. package/dist/test/antigravity-live.test.js +142 -0
  85. package/dist/test/antigravity-plugin.test.d.ts +1 -0
  86. package/dist/test/antigravity-plugin.test.js +101 -0
  87. package/dist/test/boot.integration.test.js +133 -14
  88. package/dist/test/claude-history.test.js +14 -13
  89. package/dist/test/claude-mod.test.js +9 -6
  90. package/dist/test/codex-history.test.js +15 -3
  91. package/dist/test/codex-plugin.test.js +76 -38
  92. package/dist/test/dependencies.test.js +7 -3
  93. package/dist/test/dream-skill.test.js +3 -3
  94. package/dist/test/dream-tools.test.js +101 -56
  95. package/dist/test/dsh.test.js +34 -19
  96. package/dist/test/helpers/dependency-graph.js +2 -2
  97. package/dist/test/helpers/extension.d.ts +65 -2
  98. package/dist/test/helpers/extension.js +72 -3
  99. package/dist/test/history-corpus.test.js +79 -77
  100. package/dist/test/history-summary-cache.test.js +97 -9
  101. package/dist/test/history.integration.test.js +234 -168
  102. package/dist/test/host-neutral.test.js +69 -19
  103. package/dist/test/marker.test.js +1 -1
  104. package/dist/test/note-policy.test.js +96 -77
  105. package/dist/test/notes.integration.test.js +212 -94
  106. package/dist/test/notes.test.js +184 -113
  107. package/dist/test/pi-render.test.js +20 -12
  108. package/dist/test/project-namespace.test.js +3 -2
  109. package/dist/test/reset-lifecycle.test.js +2 -2
  110. package/docs/antigravity.md +44 -0
  111. package/docs/architecture.md +6 -4
  112. package/docs/claude-code-mod.md +2 -2
  113. package/docs/codex.md +36 -38
  114. package/docs/dsh.md +3 -3
  115. package/docs/history-sessions.md +28 -50
  116. package/docs/notes-library.md +4 -4
  117. package/docs/skills.md +3 -3
  118. package/docs/tool-results.md +47 -28
  119. package/package.json +3 -2
  120. package/playbook.md +1 -1
  121. package/plugins/antigravity/dist/antigravity/notesoup.js +26886 -0
  122. package/plugins/antigravity/hooks.json +7 -0
  123. package/plugins/antigravity/mcp_config.json +8 -0
  124. package/plugins/antigravity/plugin.json +6 -0
  125. package/plugins/antigravity/src/cli.ts +22 -0
  126. package/plugins/antigravity/src/hooks.ts +51 -0
  127. package/plugins/antigravity/src/identity.ts +127 -0
  128. package/plugins/claude/.claude-plugin/plugin.json +1 -1
  129. package/plugins/claude/dist/claude/helper.js +1059 -534
  130. package/plugins/claude/hooks/register.ts +2 -2
  131. package/plugins/claude/playbook.md +1 -1
  132. package/plugins/claude/skills/dream/SKILL.md +1 -1
  133. package/plugins/claude/skills/notesoup/SKILL.md +92 -0
  134. package/plugins/claude/src/helper.ts +2 -1
  135. package/plugins/codex/.codex-plugin/plugin.json +8 -0
  136. package/plugins/codex/.mcp.json +11 -0
  137. package/plugins/codex/README.md +5 -21
  138. package/plugins/codex/dist/codex/notesoup.js +18480 -17946
  139. package/plugins/codex/src/hooks.ts +1 -0
  140. package/plugins/codex/src/identity.ts +14 -1
  141. package/plugins/codex/src/mcp.ts +28 -98
  142. package/plugins/codex/src/text.ts +3 -3
  143. package/plugins/dsh/tools.ts +8 -4
  144. package/plugins/mcp/operations.ts +50 -0
  145. package/plugins/mcp/server.ts +23 -0
  146. package/plugins/paseo/README.md +5 -10
  147. package/plugins/paseo/client/brain-empty-card.tsx +3 -3
  148. package/plugins/paseo/client/markdown.tsx +50 -38
  149. package/plugins/paseo/client/notes-op-card.tsx +12 -9
  150. package/plugins/paseo/client/paper-card.tsx +6 -5
  151. package/plugins/paseo/client/paper-palette.ts +2 -9
  152. package/plugins/paseo/client/sticky-card.tsx +2 -2
  153. package/plugins/paseo/client/tool-result.ts +7 -14
  154. package/plugins/paseo/package-lock.json +3406 -0
  155. package/plugins/paseo/package.json +1 -0
  156. package/plugins/paseo/test/markdown-core.test.ts +73 -66
  157. package/plugins/pi/budget.ts +3 -3
  158. package/plugins/pi/entries.ts +1 -0
  159. package/plugins/pi/history-tools.ts +2 -1
  160. package/plugins/pi/history.ts +30 -1
  161. package/plugins/pi/notes/tools.ts +7 -3
  162. package/plugins/pi/render.ts +6 -6
  163. package/plugins/pi/reset/lifecycle.ts +9 -10
  164. package/plugins/pi/runtime.ts +96 -60
  165. package/plugins/pi/tool-result.ts +8 -8
  166. package/plugins/pi/window.ts +198 -9
  167. package/skills/dream/SKILL.md +1 -1
  168. package/skills/notesoup/SKILL.md +92 -0
  169. package/src/boot/render.ts +18 -15
  170. package/src/boot/text.ts +23 -19
  171. package/src/budget/text.ts +13 -13
  172. package/src/history/claude.ts +41 -0
  173. package/src/history/codex-transcript.ts +6 -4
  174. package/src/history/codex.ts +2 -0
  175. package/src/history/corpus.ts +51 -2
  176. package/src/history/history.ts +35 -44
  177. package/src/history/local.ts +67 -27
  178. package/src/history/pi.ts +113 -35
  179. package/src/history/prefilter.ts +73 -15
  180. package/src/history/query.ts +93 -73
  181. package/src/history/summary-cache.ts +142 -17
  182. package/src/index.ts +1 -1
  183. package/src/notes/errors.ts +1 -1
  184. package/src/notes/frontmatter.ts +0 -3
  185. package/src/notes/index.ts +1 -1
  186. package/src/notes/policy.ts +44 -5
  187. package/src/notes/store.ts +17 -20
  188. package/src/text-match.ts +46 -4
  189. package/src/tools/dream.ts +29 -31
  190. package/src/tools/history.ts +249 -142
  191. package/src/tools/notes.ts +145 -113
  192. package/src/tools/output.ts +2 -1
  193. package/src/tools/result.ts +12 -11
  194. package/src/tools/schema.ts +24 -1
  195. package/plugins/claude/skills/memory/SKILL.md +0 -69
  196. package/plugins/codex/mcp.json +0 -10
  197. package/plugins/codex/plugin.json +0 -6
  198. package/plugins/paseo/client/markdown-core.tsx +0 -189
  199. package/plugins/paseo/client/typography.ts +0 -24
  200. package/skills/memory/SKILL.md +0 -69
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "notesoup",
3
+ "interface": {
4
+ "displayName": "notesoup"
5
+ },
6
+ "plugins": [
7
+ {
8
+ "name": "notesoup",
9
+ "source": {
10
+ "source": "local",
11
+ "path": "./plugins/codex"
12
+ }
13
+ }
14
+ ]
15
+ }
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Your agent's memory gets wiped when the context fills. notesoup makes that survivable: the agent writes itself a checkpoint before the wipe, wakes up in a fresh window, and digs up whatever it still needs from the old conversation. For you it's mostly invisible — an occasional notification, `/fresh-window` to force a fresh window, `/notesoup` to toggle.
4
4
 
5
- The architecture — durable context windows, model-authored notes, searchable history — is the one OpenAI prototyped in Codex's `context_management` experiment and switched off ten days later, because it was welded to their backend. notesoup is the same architecture running entirely on your machine, built only on [Pi](https://github.com/earendil-works/pi)'s public extension APIs. No backend, no subscription gate, no server that can 404 at the worst possible moment. It can't be switched off from far away, because there is no far away.
5
+ The architecture — durable context windows, model-authored notes, searchable history — is the one OpenAI prototyped in Codex's `context_management` experiment and switched off ten days later, because it was welded to their backend. notesoup is the same architecture running entirely on your machine, with a shared local store and host-specific plugins. No backend, no subscription gate, no server that can 404 at the worst possible moment. It can't be switched off from far away, because there is no far away.
6
6
 
7
7
  ## Renamed from pi-context
8
8
 
@@ -32,23 +32,23 @@ pi -e npm:notesoup
32
32
  - **A boot block at every window head.** Pi keeps the window identity and notes snapshot in a hidden user-role boot; its fixed recovery protocol and pinned-page teaching live in a named system section. Every note body, including `@human` pins, stays user-role data. Claude, Codex and dsh keep their existing combined boot injection.
33
33
  - **`get_context_remaining`** — how much room the brain has left before the hard-reserve wipe, including the warning runway.
34
34
  - **Notes:** `notes_list` browses current notebooks by default. Add `glob` to select notebooks or paths and `query` for literal, case-insensitive matches with lines and read offsets. Open a page with `notes_read`, create or replace one with `notes_write`, and edit, move or crumple it with `notes_update`.
35
- - **History:** `history_list` browses or searches with `query`. Page with exclusive `after` / `before` seqs or ISO 8601 times; add `context` to see neighboring events around hits. `history_read` opens one event by seq.
36
- - **Cross-session history:** both history tools accept `session: "<id-or-prefix>"` or `"<harness>:<id>"` (`pi`, `claude`, `codex`, `dsh`). `history_list({ session: "*", query: "phrase" })` searches local transcripts across harnesses; hits carry the session to copy into `history_read`. Omit `session` to use the current session. See [cross-session history](docs/history-sessions.md) for discovery roots, refusals and offline limits.
35
+ - **History:** `history_list` browses one timeline with exclusive integer `after` / `before` seqs (and optional ISO 8601 `since` / `until`), or lists recent sessions when given a wildcard `session`. `history_search` finds passages by required `query`, optionally with `context` around hits and ISO 8601 `since` / `until` bounds. `history_read` opens one event by seq.
36
+ - **Cross-session history:** all three tools accept a session ID or prefix (optionally qualified with `pi:`, `claude:`, `codex:` or `dsh:`). `history_list({ session: "*" })` gives a session overview (one representative event per session), and `history_search({ session: "*", query: "phrase" })` searches across local sessions. Copy the session heading, seq and any preview offset into `history_read`. Omit `session` for the current session. See [cross-session history](docs/history-sessions.md).
37
37
 
38
38
  - **Runtime toggle** — `/notesoup off` stops new automatic resets; `/notesoup on` re-enables them; bare `/notesoup` reports the state.
39
39
  - **Context cap (Pi and Claude)** — `/notesoup cap 100k` limits the capacity used by notesoup's budget to `min(model window, 100000)`. Existing reserves and warning margins are deducted from that capacity; 100k is not the used-token reset point. `/notesoup cap` shows the configured cap and `/notesoup cap off` removes it. Whole tokens and decimal `k`/`m` suffixes are accepted; caps too small for the host's reserves are refused. The cap applies only to the running session, survives notesoup resets and model changes, and is lost on reload/restart/session switch. It never writes host settings or environment variables, changes the provider's advertised model window, or enables disabled automatic resets.
40
40
 
41
41
  ## Per-note policy
42
42
 
43
- Notes have optional `pinned`, `budget`, `readonly`, and `description` frontmatter fields, also settable through `notes_write` and `notes_update`:
43
+ Notes have optional `pinned`, `readonly`, and `description` fields settable through `notes_write` and `notes_update` (and `budget` in frontmatter for manual overrides):
44
44
 
45
45
  ```json
46
- { "address": "@project/decisions.md", "pinned": true, "budget": 3000, "readonly": false, "description": "Architecture choices and why they stand." }
46
+ { "address": "@project/decisions.md", "pinned": true, "readonly": false, "description": "Architecture choices and why they stand." }
47
47
  ```
48
48
 
49
- - **Pinned** notes are injected **in full** at boot. Root `CHEATSHEET.md` defaults to pinned; every other page defaults to unpinned. Explicit `pinned: false` overrides even a default page. Each notebook allows **five live pins**, including its default `CHEATSHEET.md`; crumpled notes do not count. A sixth pin, restore or move that exceeds the cap refuses without changing either note. Manually over-cap notebooks get a boot warning naming the omitted pins, with default pages shown first. Unpinned live notes appear in a bounded auto-generated per-shelf index at boot (sorted by recency, up to 25 entries / 4096 chars per shelf).
50
- - **Budget** defaults to **4096 Unicode code points for ordinary pages**, and **2048 for root `CHEATSHEET.md`**. Any positive safe integer is allowed. Over-budget writes and updates succeed with a visible warning; pinned bodies are never truncated to their budget. This advisory budget is separate from the existing hard serialized-file byte limit. Tool results/read metadata/list/search expose effective policy and budget warnings.
51
- - **Description** is an optional single-line summary (up to **160 Unicode code points**; whitespace is collapsed and an empty string clears it). It is rendered in the boot shelf index (falling back to the first heading/line when absent) as well as `notes_read` metadata and `notes_list` rows.
49
+ - **Pinned** notes are injected at boot, truncated to their UTF-8 byte budget on a character boundary if oversized (with `[truncated at X/Y; offset_chars=X]`). Root `CHEATSHEET.md` defaults to pinned; every other page defaults to unpinned, and explicit `pinned: false` overrides even a default page. Live pins per notebook are capped (crumpled notes do not count); writes, restores, or moves that would exceed the cap refuse without mutating either note, and manually over-cap notebooks get a boot warning naming the omitted pins. Unpinned live notes appear in a bounded auto-generated per-shelf index at boot (sorted by recency).
50
+ - **Budget** is a per-note UTF-8 byte budget (default **4096 bytes** for root `CHEATSHEET.md`, **8192 bytes** for ordinary notes; overridable in frontmatter). Over-budget writes and updates still save whole with a `<notesoup:warning>` notice; boot truncates over-budget pinned bodies. Tool results, read metadata, and list/search expose effective policy and warnings.
51
+ - **Description** is an optional single-line summary (whitespace is collapsed and an empty string clears it). Oversized descriptions still save with a warning and truncate in the boot shelf index. It is rendered in the boot shelf index (falling back to the first heading/line when absent) as well as `notes_read` metadata and `notes_list` rows.
52
52
  - **Readonly** defaults to false. `readonly: true` is a **soft lock**, not security: mutations refuse until explicitly unlocked with `readonly: false`, either by itself or in the same call as the requested changes. A write can create and lock a note together. Reads still record access metadata; direct filesystem edits can bypass the lock.
53
53
 
54
54
  Absent fields stay absent on disk. On move/rename, implicit pin defaults follow the new root path; explicit true/false values travel with the note. The original origin, other metadata, and unknown frontmatter are preserved. See the [library API](docs/notes-library.md#per-note-policy) for details.
@@ -94,8 +94,9 @@ Environment variables:
94
94
  - [Standalone notes library](docs/notes-library.md) — use the notes store from Node, no Pi required
95
95
  - [DeepSeek Harness](docs/dsh.md) — adapter and profile patch for dsh 0.2.1-alpha.2
96
96
  - [Claude Code Mod](docs/claude-code-mod.md) — early-access notes and persisted-session history tools for Claude Code
97
- - [Codex plugin](docs/codex.md) — native notes boot, persisted history and native `new_context` for Codex 0.160.1
98
- - [Skills and dream](docs/skills.md) — `/skill:memory`, `/skill:dream`, the `dream_*` tools and the dream lock
97
+ - [Codex plugin](docs/codex.md) — native notes boot and persisted history; compatibility is determined from host data, not a CLI version number
98
+ - [Antigravity plugin](docs/antigravity.md) — automatic startup notes and the four notes tools over stdio MCP
99
+ - [Skills and dream](docs/skills.md) — `/skill:notesoup`, `/skill:dream`, the `dream_*` tools and the dream lock
99
100
 
100
101
  ## Development
101
102
 
@@ -115,7 +116,9 @@ The repository splits host-neutral code from host plugins:
115
116
  | `plugins/pi/` | The Pi extension (`plugins/pi/index.ts` is what `pi.extensions` loads from source). |
116
117
  | `plugins/claude/` | The self-contained Claude Code plugin (`.claude-plugin/`, `hooks/`, bundled `dist/claude/helper.js`, skills and playbook), with its adapter sources in `plugins/claude/src/`. |
117
118
  | `plugins/dsh/` | The Cordis rows published as `notesoup/dsh` and `notesoup/dsh/engine`. |
118
- | `plugins/codex/` | The Agent Plugins package for Codex 0.160.1: manifests, hooks, and the bundled `dist/codex/notesoup.js` MCP/hook helper. |
119
+ | `plugins/codex/` | The native Codex plugin: manifests, hooks, and the bundled `dist/codex/notesoup.js` MCP/hook helper. |
120
+
121
+ `plugins/mcp/` exposes the core tool schemas and results over stdio; `plugins/antigravity/` and `plugins/codex/` supply per-call identity and their own lifecycle hooks. Pi keeps using its native tool API.
119
122
 
120
123
  Each plugin owns its host's words — Pi's pre-reset hints and `last_word` nudge live in `plugins/pi/text.ts`, Claude's reset and missing-history prose in `plugins/claude/src/text.ts` — while the shared boot, protocol and warning bodies stay in `src/boot/text.ts` and `src/budget/text.ts`.
121
124
 
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,23 @@
1
+ import { runToolServer } from "../../mcp/server.js";
2
+ import { createNoteTools } from "../../mcp/operations.js";
3
+ import { preInvocation } from "./hooks.js";
4
+ import { resolveContext } from "./identity.js";
5
+ async function main() {
6
+ if (process.argv[2] === "mcp") {
7
+ await runToolServer({ name: "notesoup", ...createNoteTools(meta => resolveContext(meta)) });
8
+ return;
9
+ }
10
+ if (process.argv[2] !== "pre-invocation")
11
+ throw new Error("Expected mcp or pre-invocation.");
12
+ let raw = "";
13
+ for await (const chunk of process.stdin) {
14
+ raw += chunk;
15
+ if (Buffer.byteLength(raw) > 1024 * 1024)
16
+ throw new Error("Hook input exceeds 1 MiB.");
17
+ }
18
+ const value = JSON.parse(raw);
19
+ if (typeof value !== "object" || value === null || Array.isArray(value))
20
+ throw new Error("Expected a hook object.");
21
+ process.stdout.write(JSON.stringify(await preInvocation(value)) + "\n");
22
+ }
23
+ main().catch(error => { process.stderr.write(`notesoup: ${error instanceof Error ? error.message : String(error)}\n`); process.exitCode = 1; });
@@ -0,0 +1,18 @@
1
+ type InjectedStep = {
2
+ systemMessage: {
3
+ systemMessage: string;
4
+ };
5
+ } | {
6
+ userMessage: string;
7
+ } | {
8
+ errorMessage: {
9
+ userMessage: string;
10
+ };
11
+ };
12
+ type HookOutput = {
13
+ injectSteps?: InjectedStep[];
14
+ terminationBehavior?: "terminate";
15
+ };
16
+ /** PreInvocation is the host's model boundary, for both a new conversation and subsequent invocations. */
17
+ export declare function preInvocation(payload: Record<string, unknown>, env?: NodeJS.ProcessEnv): Promise<HookOutput>;
18
+ export {};
@@ -0,0 +1,53 @@
1
+ import { renderBootContext } from "../../../src/boot/render.js";
2
+ import { loadNotesSnapshot } from "../../../src/boot/snapshot.js";
3
+ import { DEFAULT_BOOT_TOOL_NAMES, MAPS_BLOCK, renderProtocolBlock } from "../../../src/boot/text.js";
4
+ import { AntigravityIdentityError, bindingFromHook, contextForBinding, invalidateBinding, readBinding, writeBinding } from "./identity.js";
5
+ const TOOLS = {
6
+ ...DEFAULT_BOOT_TOOL_NAMES,
7
+ historySentence: "Notesoup has no Antigravity history tool. Record important details in notes rather than relying on a Notesoup history index.",
8
+ budgetParagraph: "Notesoup has no Antigravity context-budget or reset tool. The host manages its own conversation context; this plugin does not promise recovery after native context compaction.",
9
+ };
10
+ const MAX_BOOT_BYTES = 128 * 1024;
11
+ function inject(message) { return { injectSteps: [{ systemMessage: { systemMessage: message } }] }; }
12
+ /** PreInvocation is the host's model boundary, for both a new conversation and subsequent invocations. */
13
+ export async function preInvocation(payload, env = process.env) {
14
+ let binding;
15
+ try {
16
+ if (payload.hookEventName !== "PreInvocation")
17
+ throw new Error("Unexpected hook event.");
18
+ binding = bindingFromHook(payload, env);
19
+ const existing = await readBinding(env, binding.conversationId);
20
+ if (existing && ((existing.rootConversationId !== undefined && binding.rootConversationId !== undefined && existing.rootConversationId !== binding.rootConversationId) || (existing.parentConversationId !== undefined && binding.parentConversationId !== undefined && existing.parentConversationId !== binding.parentConversationId)))
21
+ throw new Error("Conversation ancestry changed; refusing to overwrite an existing binding.");
22
+ // Retain known ancestry through later hooks that omit these optional fields.
23
+ binding = { ...binding, bootEmitted: existing?.bootEmitted ?? false, ...(existing?.rootConversationId === undefined ? {} : { rootConversationId: existing.rootConversationId }), ...(existing?.parentConversationId === undefined ? {} : { parentConversationId: existing.parentConversationId }) };
24
+ await writeBinding(env, binding);
25
+ }
26
+ catch (error) {
27
+ if (!(error instanceof AntigravityIdentityError && error.code === "mismatched_home"))
28
+ await invalidateBinding(env, payload.conversationId).catch(() => { });
29
+ // Never let a failed identity refresh continue the invocation with an older model/cwd.
30
+ return { injectSteps: [{ errorMessage: { userMessage: `Notesoup: could not establish this invocation (${error instanceof Error ? error.message : String(error)}).` } }], terminationBehavior: "terminate" };
31
+ }
32
+ // The first PreInvocation is a model boundary for both root and child conversations.
33
+ if (binding.bootEmitted)
34
+ return {};
35
+ try {
36
+ const { identity } = contextForBinding(binding);
37
+ const notes = await loadNotesSnapshot(identity, Date.now());
38
+ const protocol = `${renderProtocolBlock(TOOLS, identity.agent)}\n\n${MAPS_BLOCK}`;
39
+ const boot = renderBootContext({
40
+ agentName: identity.agent, modelName: binding.model, notes, tools: TOOLS,
41
+ tree: { trunk: `Antigravity conversation ${binding.conversationId}`, windows: [{ shortName: "conversation", isCurrent: true }] },
42
+ });
43
+ if (Buffer.byteLength(protocol + boot, "utf8") > MAX_BOOT_BYTES)
44
+ throw new Error("Boot exceeds 128 KiB; slim the pinned notes. No partial boot was injected.");
45
+ await writeBinding(env, { ...binding, bootEmitted: true });
46
+ return { injectSteps: [{ systemMessage: { systemMessage: protocol } }, { userMessage: boot }] };
47
+ }
48
+ catch (error) {
49
+ // Do not place diagnostics derived from note contents into a trusted message.
50
+ process.stderr.write(`notesoup: boot failed: ${error instanceof Error ? error.message : String(error)}\n`);
51
+ return inject("Notesoup: could not render the notes boot. No partial boot was injected; use notes_list to inspect the library.");
52
+ }
53
+ }
@@ -0,0 +1,26 @@
1
+ import { type NotesToolContext } from "../../../src/tools/notes-context.js";
2
+ export declare class AntigravityIdentityError extends Error {
3
+ readonly code: string;
4
+ constructor(code: string, message: string);
5
+ }
6
+ export declare function conversationId(value: unknown): string;
7
+ export declare function notesHome(env: NodeJS.ProcessEnv): string;
8
+ export type ConversationBinding = Readonly<{
9
+ conversationId: string;
10
+ rootConversationId?: string;
11
+ parentConversationId?: string;
12
+ cwd: string;
13
+ model: string;
14
+ /** Absent in many native hooks, including 1.5.17's dynamically defined subagents. */
15
+ agent?: string;
16
+ home: string;
17
+ bootEmitted: boolean;
18
+ }>;
19
+ export declare function bindingFromHook(payload: Record<string, unknown>, env: NodeJS.ProcessEnv): ConversationBinding;
20
+ export declare function contextForBinding(binding: ConversationBinding, agent?: string): NotesToolContext;
21
+ export declare function readBinding(env: NodeJS.ProcessEnv, id: string): Promise<ConversationBinding | undefined>;
22
+ export declare function writeBinding(env: NodeJS.ProcessEnv, binding: ConversationBinding): Promise<void>;
23
+ /** A hook lacking current model/cwd facts must not leave a usable older binding. */
24
+ export declare function invalidateBinding(env: NodeJS.ProcessEnv, id: unknown): Promise<void>;
25
+ /** Never fall back to root ID, MCP process cwd, a previous call, or model-supplied arguments. */
26
+ export declare function resolveContext(meta: Record<string, unknown>, env?: NodeJS.ProcessEnv): Promise<NotesToolContext>;
@@ -0,0 +1,129 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { mkdir, readFile, rename, unlink, writeFile } from "node:fs/promises";
3
+ import { homedir } from "node:os";
4
+ import { dirname, isAbsolute, join, resolve } from "node:path";
5
+ import { projectKey, slugify, snapshotNotesIdentity } from "../../../src/notes/index.js";
6
+ import { NAMELESS_AGENT } from "../../../src/boot/text.js";
7
+ import { notesToolContext } from "../../../src/tools/notes-context.js";
8
+ const PREFIX = "antigravity.google/";
9
+ const UUID = /^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i;
10
+ export class AntigravityIdentityError extends Error {
11
+ code;
12
+ constructor(code, message) {
13
+ super(message);
14
+ this.code = code;
15
+ }
16
+ }
17
+ function text(value) {
18
+ return typeof value === "string" && value.trim() !== "" ? value.trim() : undefined;
19
+ }
20
+ export function conversationId(value) {
21
+ if (typeof value !== "string" || !UUID.test(value))
22
+ throw new AntigravityIdentityError("invalid_conversation", "Antigravity did not supply a valid native conversation ID.");
23
+ return value;
24
+ }
25
+ function modelName(value) {
26
+ const id = text(value)?.split("/").pop();
27
+ if (!id || !/[a-z0-9]/i.test(id) || /^(?:auto|default)$/i.test(id))
28
+ throw new AntigravityIdentityError("missing_model", "The Antigravity hook did not name a concrete model; select a specific model before using Notesoup.");
29
+ return slugify(id);
30
+ }
31
+ function absolute(value, field) {
32
+ if (typeof value !== "string" || !isAbsolute(value) || value.includes("\0"))
33
+ throw new AntigravityIdentityError("invalid_identity", `Antigravity ${field} is not an absolute path.`);
34
+ return resolve(value);
35
+ }
36
+ export function notesHome(env) {
37
+ return env.NOTESOUP_HOME === undefined ? join(homedir(), ".agents", "notes") : absolute(env.NOTESOUP_HOME, "NOTESOUP_HOME");
38
+ }
39
+ export function bindingFromHook(payload, env) {
40
+ const id = conversationId(payload.conversationId);
41
+ const parent = text(payload.parentConversationId);
42
+ const root = text(payload.rootConversationId);
43
+ if (parent !== undefined)
44
+ conversationId(parent);
45
+ if (root !== undefined)
46
+ conversationId(root);
47
+ if (parent === id || (root === id && parent !== undefined))
48
+ throw new AntigravityIdentityError("invalid_identity", "The Antigravity hook's conversation ancestry is inconsistent.");
49
+ const agent = text(payload.agentName);
50
+ return {
51
+ conversationId: id, ...(root === undefined ? {} : { rootConversationId: root }), ...(parent === undefined ? {} : { parentConversationId: parent }),
52
+ cwd: absolute(payload.cwd, "hook cwd"), model: modelName(payload.modelName),
53
+ ...(agent === undefined ? {} : { agent: slugify(agent) }), home: notesHome(env), bootEmitted: false,
54
+ };
55
+ }
56
+ function bindingPath(env, id) {
57
+ return join(absolute(env.PLUGIN_DATA, "PLUGIN_DATA"), "conversations", `${conversationId(id)}.json`);
58
+ }
59
+ export function contextForBinding(binding, agent = binding.agent ?? NAMELESS_AGENT) {
60
+ return notesToolContext(snapshotNotesIdentity({
61
+ home: binding.home, sessionId: binding.conversationId, projectKey: projectKey(binding.cwd, binding.home),
62
+ agent, model: binding.model,
63
+ }), binding.cwd);
64
+ }
65
+ export async function readBinding(env, id) {
66
+ let content;
67
+ try {
68
+ content = await readFile(bindingPath(env, id), "utf8");
69
+ }
70
+ catch (error) {
71
+ if (error.code === "ENOENT")
72
+ return undefined;
73
+ throw error;
74
+ }
75
+ const row = JSON.parse(content);
76
+ if (!row || row.conversationId !== id || typeof row.bootEmitted !== "boolean" || typeof row.model !== "string" || slugify(row.model) !== row.model ||
77
+ (row.agent !== undefined && (typeof row.agent !== "string" || slugify(row.agent) !== row.agent)))
78
+ throw new AntigravityIdentityError("invalid_binding", "Antigravity's saved conversation binding is invalid.");
79
+ if (row.rootConversationId !== undefined)
80
+ conversationId(row.rootConversationId);
81
+ if (row.parentConversationId !== undefined)
82
+ conversationId(row.parentConversationId);
83
+ if (row.parentConversationId === id || (row.rootConversationId === id && row.parentConversationId !== undefined))
84
+ throw new AntigravityIdentityError("invalid_binding", "Antigravity's saved conversation ancestry is inconsistent.");
85
+ absolute(row.cwd, "saved cwd");
86
+ if (absolute(row.home, "saved notes home") !== notesHome(env))
87
+ throw new AntigravityIdentityError("mismatched_home", "The conversation binding belongs to another NOTESOUP_HOME. Start a new conversation with the intended home.");
88
+ return row;
89
+ }
90
+ export async function writeBinding(env, binding) {
91
+ const path = bindingPath(env, binding.conversationId);
92
+ await mkdir(dirname(path), { recursive: true, mode: 0o700 });
93
+ const temp = `${path}.${randomUUID()}.tmp`;
94
+ try {
95
+ await writeFile(temp, `${JSON.stringify(binding)}\n`, { mode: 0o600 });
96
+ await rename(temp, path);
97
+ }
98
+ finally {
99
+ await unlink(temp).catch(() => { });
100
+ }
101
+ }
102
+ /** A hook lacking current model/cwd facts must not leave a usable older binding. */
103
+ export async function invalidateBinding(env, id) {
104
+ try {
105
+ await unlink(bindingPath(env, conversationId(id)));
106
+ }
107
+ catch (error) {
108
+ if (error.code !== "ENOENT")
109
+ throw error;
110
+ }
111
+ }
112
+ /** Never fall back to root ID, MCP process cwd, a previous call, or model-supplied arguments. */
113
+ export async function resolveContext(meta, env = process.env) {
114
+ const id = conversationId(meta[`${PREFIX}conversation_id`]);
115
+ const root = conversationId(meta[`${PREFIX}root_conversation_id`]);
116
+ const binding = await readBinding(env, id);
117
+ if (!binding)
118
+ throw new AntigravityIdentityError("unknown_conversation", "No Notesoup hook binding exists for this Antigravity conversation. Enable the plugin hooks and start a model invocation in this conversation.");
119
+ const parent = text(meta[`${PREFIX}parent_conversation_id`]);
120
+ const agent = text(meta[`${PREFIX}agent_name`]);
121
+ if (parent !== undefined)
122
+ conversationId(parent);
123
+ if ((binding.rootConversationId !== undefined && binding.rootConversationId !== root) ||
124
+ (binding.parentConversationId !== undefined && parent !== undefined && parent !== binding.parentConversationId) ||
125
+ (binding.agent !== undefined && agent !== undefined && slugify(agent) !== binding.agent) || parent === id || (parent !== undefined && root === id)) {
126
+ throw new AntigravityIdentityError("mismatched_conversation", "The Antigravity call disagrees with its own hook identity; no notes were accessed.");
127
+ }
128
+ return contextForBinding(binding, agent === undefined ? binding.agent : slugify(agent));
129
+ }
@@ -3,7 +3,7 @@ import { pathToFileURL } from "node:url";
3
3
  import { Check } from "typebox/value";
4
4
  import { paramProblem } from "../../../src/tools/schema.js";
5
5
  import { notesList, notesRead, notesUpdate, notesWrite } from "../../../src/tools/notes.js";
6
- import { historyList, historyRead } from "../../../src/tools/history.js";
6
+ import { historyList, historySearch, historyRead } from "../../../src/tools/history.js";
7
7
  import { localHistoryCorpus } from "../../../src/history/local.js";
8
8
  import { readClaudeHistory } from "./history.js";
9
9
  import { loadNotesSnapshot } from "../../../src/boot/snapshot.js";
@@ -41,6 +41,7 @@ const OPERATIONS = {
41
41
  };
42
42
  const HISTORY_OPERATIONS = {
43
43
  history_list: boundOperation(historyList),
44
+ history_search: boundOperation(historySearch),
44
45
  history_read: boundOperation(historyRead),
45
46
  };
46
47
  function historySource(value, sessionId) {
@@ -122,6 +122,7 @@ async function startHook(event, payload, env) {
122
122
  home: notesHome(env),
123
123
  transcriptPath,
124
124
  windowId: native.state.currentWindowId,
125
+ windowNumber: native.state.currentWindowNumber,
125
126
  ...(target.agentType === undefined ? {} : { agentType: target.agentType }),
126
127
  boundAt: new Date().toISOString(),
127
128
  };
@@ -16,12 +16,17 @@ export type ThreadBinding = Readonly<{
16
16
  transcriptPath: string;
17
17
  /** Native window at bind time; a later MCP call must name this same window. */
18
18
  windowId: string;
19
+ /** The same native window's monotonic number, used in newer MCP metadata. */
20
+ windowNumber?: number;
19
21
  agentType?: string;
20
22
  boundAt: string;
21
23
  }>;
22
24
  export declare function safeThreadId(value: unknown, field?: string): string;
23
- /** The portable server and the hook must share this root; Codex injects it into both. */
25
+ /** The hook receives the native plugin's data directory directly from Codex. */
24
26
  export declare function pluginDataRoot(env?: NodeJS.ProcessEnv): string;
27
+ /** Native Codex MCP launches don't inject PLUGIN_DATA (0.171.0). The installed
28
+ * notesoup@notesoup package has a fixed native data path under CODEX_HOME. */
29
+ export declare function mcpPluginDataRoot(env?: NodeJS.ProcessEnv): string;
25
30
  export declare function notesHome(env?: NodeJS.ProcessEnv): string;
26
31
  /** Native ids arrive provider-prefixed; @model is the last segment, slugged like every other notebook. */
27
32
  export declare function modelSlug(value: unknown): string | undefined;
@@ -20,7 +20,7 @@ export function safeThreadId(value, field = "threadId") {
20
20
  }
21
21
  return value;
22
22
  }
23
- /** The portable server and the hook must share this root; Codex injects it into both. */
23
+ /** The hook receives the native plugin's data directory directly from Codex. */
24
24
  export function pluginDataRoot(env = process.env) {
25
25
  const value = env.PLUGIN_DATA;
26
26
  if (typeof value !== "string" || value.trim() === "" || !isAbsolute(value)) {
@@ -28,6 +28,14 @@ export function pluginDataRoot(env = process.env) {
28
28
  }
29
29
  return resolve(value);
30
30
  }
31
+ /** Native Codex MCP launches don't inject PLUGIN_DATA (0.171.0). The installed
32
+ * notesoup@notesoup package has a fixed native data path under CODEX_HOME. */
33
+ export function mcpPluginDataRoot(env = process.env) {
34
+ if (env.PLUGIN_DATA !== undefined)
35
+ return pluginDataRoot(env);
36
+ const home = env.CODEX_HOME?.trim() || join(homedir(), ".codex");
37
+ return resolve(home, "plugins", "data", "notesoup-notesoup");
38
+ }
31
39
  export function notesHome(env = process.env) {
32
40
  const value = env.NOTESOUP_HOME;
33
41
  return value !== undefined && value.trim() !== "" ? resolve(value) : join(homedir(), ".agents", "notes");
@@ -79,6 +87,9 @@ export async function readBinding(root, threadId) {
79
87
  const cwd = required(row.cwd, "cwd");
80
88
  const transcriptPath = required(row.transcriptPath, "transcriptPath");
81
89
  const windowId = required(row.windowId, "windowId");
90
+ const windowNumber = row.windowNumber;
91
+ if (windowNumber !== undefined && (typeof windowNumber !== "number" || !Number.isSafeInteger(windowNumber) || windowNumber < 0))
92
+ throw new CodexIdentityError("invalid_binding", "Stored notesoup binding has an invalid native window number.");
82
93
  if (!isAbsolute(home) || !isAbsolute(cwd) || !isAbsolute(transcriptPath))
83
94
  throw new CodexIdentityError("invalid_binding", "The stored notesoup binding contains a non-absolute path.");
84
95
  return {
@@ -91,6 +102,7 @@ export async function readBinding(root, threadId) {
91
102
  home,
92
103
  transcriptPath,
93
104
  windowId,
105
+ ...(windowNumber === undefined ? {} : { windowNumber }),
94
106
  ...(typeof row.agentType === "string" && row.agentType.length > 0 ? { agentType: row.agentType } : {}),
95
107
  boundAt: required(row.boundAt, "boundAt"),
96
108
  };
@@ -1,7 +1,35 @@
1
- /** The portable stdio MCP server: shared notes/history operations over host-owned tool names. */
2
- import { Server } from "@modelcontextprotocol/sdk/server/index.js";
3
- import { type CallToolResult, type Tool } from "@modelcontextprotocol/sdk/types.js";
4
- export declare function callTool(name: string, args: unknown, meta: Record<string, unknown>, env?: NodeJS.ProcessEnv): Promise<CallToolResult>;
5
- export declare function tools(): Tool[];
6
- export declare function createServer(env?: NodeJS.ProcessEnv): Server;
7
- export declare function runMcp(env?: NodeJS.ProcessEnv): Promise<void>;
1
+ export declare const createServer: (env?: NodeJS.ProcessEnv) => import("@modelcontextprotocol/sdk/server").Server<{
2
+ method: string;
3
+ params?: {
4
+ [x: string]: unknown;
5
+ _meta?: {
6
+ [x: string]: unknown;
7
+ progressToken?: string | number | undefined;
8
+ "io.modelcontextprotocol/related-task"?: {
9
+ taskId: string;
10
+ } | undefined;
11
+ } | undefined;
12
+ } | undefined;
13
+ }, {
14
+ method: string;
15
+ params?: {
16
+ [x: string]: unknown;
17
+ _meta?: {
18
+ [x: string]: unknown;
19
+ progressToken?: string | number | undefined;
20
+ "io.modelcontextprotocol/related-task"?: {
21
+ taskId: string;
22
+ } | undefined;
23
+ } | undefined;
24
+ } | undefined;
25
+ }, {
26
+ [x: string]: unknown;
27
+ _meta?: {
28
+ [x: string]: unknown;
29
+ progressToken?: string | number | undefined;
30
+ "io.modelcontextprotocol/related-task"?: {
31
+ taskId: string;
32
+ } | undefined;
33
+ } | undefined;
34
+ }>;
35
+ export declare const runMcp: (env?: NodeJS.ProcessEnv) => Promise<void>;