notesoup 0.53.2 → 0.54.1

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 (186) hide show
  1. package/README.md +6 -4
  2. package/dist/plugins/claude/src/helper.d.ts +2 -1
  3. package/dist/plugins/claude/src/helper.js +21 -24
  4. package/dist/plugins/claude/src/history.d.ts +3 -14
  5. package/dist/plugins/claude/src/history.js +2 -298
  6. package/dist/plugins/claude/src/text.d.ts +0 -1
  7. package/dist/plugins/claude/src/text.js +0 -1
  8. package/dist/plugins/codex/src/history.d.ts +3 -8
  9. package/dist/plugins/codex/src/history.js +2 -238
  10. package/dist/plugins/codex/src/hooks.js +1 -1
  11. package/dist/plugins/codex/src/identity.d.ts +1 -1
  12. package/dist/plugins/codex/src/identity.js +3 -3
  13. package/dist/plugins/codex/src/mcp.js +9 -8
  14. package/dist/plugins/codex/src/text.d.ts +1 -1
  15. package/dist/plugins/codex/src/text.js +2 -2
  16. package/dist/plugins/codex/src/transcript.d.ts +3 -39
  17. package/dist/plugins/codex/src/transcript.js +2 -313
  18. package/dist/plugins/dsh/engine.js +2 -2
  19. package/dist/plugins/dsh/history.d.ts +3 -0
  20. package/dist/plugins/dsh/history.js +15 -0
  21. package/dist/plugins/dsh/tools.js +12 -12
  22. package/dist/plugins/dsh/window.d.ts +1 -0
  23. package/dist/plugins/dsh/window.js +7 -3
  24. package/dist/plugins/pi/history-tools.d.ts +1 -1
  25. package/dist/plugins/pi/history-tools.js +9 -5
  26. package/dist/plugins/pi/history.d.ts +2 -3
  27. package/dist/plugins/pi/history.js +4 -147
  28. package/dist/plugins/pi/notes/tools.js +8 -6
  29. package/dist/plugins/pi/render.js +7 -4
  30. package/dist/plugins/pi/runtime.js +2 -2
  31. package/dist/plugins/pi/window.js +21 -7
  32. package/dist/src/boot/render.js +9 -11
  33. package/dist/src/boot/snapshot.d.ts +7 -7
  34. package/dist/src/boot/snapshot.js +17 -17
  35. package/dist/src/boot/text.d.ts +5 -3
  36. package/dist/src/boot/text.js +18 -10
  37. package/dist/src/dream/git.d.ts +2 -11
  38. package/dist/src/dream/git.js +6 -23
  39. package/dist/src/dream/lock.d.ts +2 -2
  40. package/dist/src/dream/lock.js +3 -3
  41. package/dist/src/history/claude.d.ts +16 -0
  42. package/dist/src/history/claude.js +336 -0
  43. package/dist/src/history/codex-transcript.d.ts +39 -0
  44. package/dist/src/history/codex-transcript.js +315 -0
  45. package/dist/src/history/codex.d.ts +8 -0
  46. package/dist/src/history/codex.js +238 -0
  47. package/dist/src/history/corpus.d.ts +35 -0
  48. package/dist/src/history/corpus.js +54 -0
  49. package/dist/src/history/history.d.ts +4 -8
  50. package/dist/src/history/history.js +3 -11
  51. package/dist/src/history/local.d.ts +17 -0
  52. package/dist/src/history/local.js +101 -0
  53. package/dist/src/history/pi.d.ts +36 -0
  54. package/dist/src/history/pi.js +202 -0
  55. package/dist/src/history/query.d.ts +15 -5
  56. package/dist/src/history/query.js +42 -13
  57. package/dist/src/index.d.ts +6 -3
  58. package/dist/src/index.js +6 -4
  59. package/dist/src/notes/address.d.ts +8 -8
  60. package/dist/src/notes/address.js +13 -13
  61. package/dist/src/notes/errors.d.ts +1 -1
  62. package/dist/src/notes/frontmatter.js +2 -2
  63. package/dist/src/notes/index.d.ts +1 -1
  64. package/dist/src/notes/index.js +1 -1
  65. package/dist/src/notes/paths.d.ts +6 -6
  66. package/dist/src/notes/paths.js +9 -9
  67. package/dist/src/notes/{project-home.d.ts → project-namespace.d.ts} +7 -7
  68. package/dist/src/notes/{project-home.js → project-namespace.js} +67 -25
  69. package/dist/src/notes/store.d.ts +4 -4
  70. package/dist/src/notes/store.js +55 -52
  71. package/dist/src/tools/dream.d.ts +21 -3
  72. package/dist/src/tools/dream.js +54 -16
  73. package/dist/src/tools/history.d.ts +7 -19
  74. package/dist/src/tools/history.js +80 -93
  75. package/dist/src/tools/notes-context.d.ts +10 -0
  76. package/dist/src/tools/notes-context.js +27 -0
  77. package/dist/src/tools/notes.d.ts +69 -20
  78. package/dist/src/tools/notes.js +40 -31
  79. package/dist/test/boot.integration.test.js +2 -3
  80. package/dist/test/claude-history.test.js +47 -34
  81. package/dist/test/claude-mod.test.js +96 -50
  82. package/dist/test/codex-history.test.js +4 -10
  83. package/dist/test/codex-plugin.test.js +50 -12
  84. package/dist/test/context-edit-budget.test.js +121 -0
  85. package/dist/test/dependencies.test.js +73 -6
  86. package/dist/test/dream-tools.test.js +153 -8
  87. package/dist/test/dsh.test.js +88 -19
  88. package/dist/test/helpers/dsh.d.ts +4 -1
  89. package/dist/test/helpers/dsh.js +20 -4
  90. package/dist/test/helpers/extension.d.ts +5 -1
  91. package/dist/test/helpers/extension.js +33 -2
  92. package/dist/test/helpers/history-corpus.d.ts +7 -0
  93. package/dist/test/helpers/history-corpus.js +26 -0
  94. package/dist/test/history-corpus.test.js +307 -0
  95. package/dist/test/history.integration.test.js +40 -48
  96. package/dist/test/host-neutral.test.js +20 -33
  97. package/dist/test/model-facing-text.test.js +14 -8
  98. package/dist/test/notes-cwd.test.d.ts +1 -0
  99. package/dist/test/notes-cwd.test.js +114 -0
  100. package/dist/test/notes-library.test.js +4 -4
  101. package/dist/test/notes-query-namespaces.test.d.ts +1 -0
  102. package/dist/test/{notes-query-homes.test.js → notes-query-namespaces.test.js} +13 -13
  103. package/dist/test/notes.integration.test.js +73 -24
  104. package/dist/test/notes.test.js +51 -21
  105. package/dist/test/pi-render.test.js +33 -1
  106. package/dist/test/project-namespace.test.d.ts +1 -0
  107. package/dist/test/project-namespace.test.js +324 -0
  108. package/docs/architecture.md +19 -12
  109. package/docs/claude-code-mod.md +7 -5
  110. package/docs/codex.md +6 -6
  111. package/docs/dsh.md +9 -9
  112. package/docs/history-sessions.md +52 -0
  113. package/docs/notes-library.md +9 -5
  114. package/docs/skills.md +3 -3
  115. package/docs/tool-results.md +14 -8
  116. package/package.json +4 -6
  117. package/playbook.md +6 -6
  118. package/plugins/claude/.claude-plugin/plugin.json +1 -1
  119. package/plugins/claude/dist/claude/helper.js +2164 -1341
  120. package/plugins/claude/hooks/register.ts +19 -11
  121. package/plugins/claude/playbook.md +6 -6
  122. package/plugins/claude/skills/memory/SKILL.md +9 -7
  123. package/plugins/claude/src/helper.ts +22 -25
  124. package/plugins/claude/src/history.ts +3 -257
  125. package/plugins/claude/src/text.ts +0 -1
  126. package/plugins/codex/README.md +1 -1
  127. package/plugins/codex/dist/codex/notesoup.js +1582 -969
  128. package/plugins/codex/src/history.ts +3 -193
  129. package/plugins/codex/src/hooks.ts +1 -1
  130. package/plugins/codex/src/identity.ts +3 -3
  131. package/plugins/codex/src/mcp.ts +9 -8
  132. package/plugins/codex/src/text.ts +2 -2
  133. package/plugins/codex/src/transcript.ts +3 -275
  134. package/plugins/dsh/engine.ts +2 -2
  135. package/plugins/dsh/history.ts +17 -0
  136. package/plugins/dsh/tools.ts +12 -12
  137. package/plugins/dsh/window.ts +8 -3
  138. package/plugins/paseo/OVERVIEW.md +4 -4
  139. package/plugins/paseo/README.md +1 -1
  140. package/plugins/paseo/client/brain-empty-card.tsx +3 -4
  141. package/plugins/paseo/client/markdown.tsx +159 -0
  142. package/plugins/paseo/client/notes-op-card.tsx +35 -34
  143. package/plugins/paseo/client/notes-op-transformer.ts +17 -68
  144. package/plugins/paseo/client/paper-card.tsx +8 -19
  145. package/plugins/paseo/client/paper-palette.ts +40 -0
  146. package/plugins/paseo/client/sticky-card.tsx +6 -4
  147. package/plugins/paseo/package.json +3 -0
  148. package/plugins/paseo/paseo-plugin.json +2 -2
  149. package/plugins/paseo/shared/notes-op.ts +13 -9
  150. package/plugins/paseo/test/notes-op.test.ts +52 -73
  151. package/plugins/paseo/test/paper-palette.test.ts +54 -0
  152. package/plugins/pi/history-tools.ts +11 -5
  153. package/plugins/pi/history.ts +8 -157
  154. package/plugins/pi/notes/tools.ts +8 -6
  155. package/plugins/pi/render.ts +6 -4
  156. package/plugins/pi/runtime.ts +2 -2
  157. package/plugins/pi/window.ts +22 -7
  158. package/skills/memory/SKILL.md +9 -7
  159. package/src/boot/render.ts +10 -13
  160. package/src/boot/snapshot.ts +20 -20
  161. package/src/boot/text.ts +18 -10
  162. package/src/dream/git.ts +7 -24
  163. package/src/dream/lock.ts +3 -3
  164. package/src/history/claude.ts +286 -0
  165. package/src/history/codex-transcript.ts +276 -0
  166. package/src/history/codex.ts +193 -0
  167. package/src/history/corpus.ts +69 -0
  168. package/src/history/history.ts +5 -12
  169. package/src/history/local.ts +93 -0
  170. package/src/history/pi.ts +199 -0
  171. package/src/history/query.ts +45 -15
  172. package/src/index.ts +8 -5
  173. package/src/notes/address.ts +13 -13
  174. package/src/notes/errors.ts +1 -1
  175. package/src/notes/frontmatter.ts +2 -2
  176. package/src/notes/index.ts +1 -1
  177. package/src/notes/paths.ts +9 -9
  178. package/src/notes/{project-home.ts → project-namespace.ts} +59 -28
  179. package/src/notes/store.ts +61 -58
  180. package/src/tools/dream.ts +63 -16
  181. package/src/tools/history.ts +71 -101
  182. package/src/tools/notes-context.ts +29 -0
  183. package/src/tools/notes.ts +39 -29
  184. package/dist/test/project-home.test.js +0 -134
  185. /package/dist/test/{notes-query-homes.test.d.ts → context-edit-budget.test.d.ts} +0 -0
  186. /package/dist/test/{project-home.test.d.ts → history-corpus.test.d.ts} +0 -0
@@ -1,238 +1,2 @@
1
- /** Codex-owned decoding; selection, pairing, paging and budgets belong to shared history/tools. */
2
- import { projectHistory } from "../../../src/history/history.js";
3
- import { nativeObject as obj, nativeString as str, readCodexTranscript } from "./transcript.js";
4
- const DISPLAY_COPIES = new Set(["user_message", "agent_message", "agent_reasoning", "agent_reasoning_raw_content", "context_compacted", "web_search_end", "image_generation_end"]);
5
- const ITEM_COPIES = new Set(["UserMessage", "AgentMessage", "Reasoning", "ContextCompaction", "WebSearch", "ImageGeneration", "HookPrompt"]);
6
- // protocol.rs serializes v1 task_* spellings; turn_* are explicit serde aliases.
7
- const HOST_EVENTS = new Set(["token_count", "thread_goal_updated", "task_started", "task_complete", "turn_started", "turn_complete", "turn_aborted", "thread_settings_applied", "entered_review_mode", "exited_review_mode", "patch_apply_end", "sub_agent_activity"]);
8
- const HOST_ITEMS = new Set(["Plan", "FileChange", "CollabAgentToolCall", "SubAgentActivity", "ImageView", "Extension", "EnteredReviewMode", "ExitedReviewMode"]);
9
- const OPAQUE_RESPONSES = new Set(["reasoning", "compaction", "compaction_summary", "context_compaction", "image_generation_call"]);
10
- const HOST_RESPONSES = new Set(["configuration_update", "tool_search_call", "tool_search_output", "web_search_call"]);
11
- function optionalString(value, field) { return value == null ? undefined : str(value, field); }
12
- function array(value, field) {
13
- if (!Array.isArray(value))
14
- throw new Error(`Invalid Codex ${field}: expected an array`);
15
- return value;
16
- }
17
- /** No image/audio decoding, opaque plaintext recovery, or stringification disguised as message text. */
18
- function textContent(value) {
19
- return array(value, "content").map((value) => {
20
- const part = obj(value, "content part");
21
- switch (part.type) {
22
- case "input_text":
23
- case "output_text": return str(part.text, "content text");
24
- case "input_image": return "[Codex image content omitted]";
25
- case "input_audio": return "[Codex audio content omitted]";
26
- case "encrypted_content": return "[Codex encrypted content unavailable]";
27
- default: throw new Error(`Unsupported Codex content part: ${String(part.type)}`);
28
- }
29
- }).join("\n");
30
- }
31
- function output(value) { return typeof value === "string" ? value : textContent(value); }
32
- function argumentsOf(raw) {
33
- // Custom/invalid/non-object JSON cannot fit the shared object field. Keep the
34
- // original wire string under an explicit raw label rather than lose it.
35
- try {
36
- const parsed = JSON.parse(raw);
37
- if (parsed !== null && typeof parsed === "object" && !Array.isArray(parsed))
38
- return parsed;
39
- }
40
- catch { /* Native tool calls may persist unparseable model arguments. */ }
41
- return { raw_arguments: raw };
42
- }
43
- function callKey(record, callId) { return `${record.owner}:${callId}`; }
44
- function context(record, text) {
45
- if (!record.windowId)
46
- throw new Error(`Unavailable Codex history: native window identity missing at seq ${record.seq}; cannot assign a stable window address`);
47
- return { seq: record.seq, windowId: record.windowId, role: "system", text, createdAt: record.timestamp };
48
- }
49
- function host(record, kind, payload) { return context(record, `Codex ${kind}\n${JSON.stringify(payload)}`); }
50
- /** Presentation records contribute OUTCOME evidence, never duplicate raw tool dialogue. */
51
- function fact(item) {
52
- if (item.type === "CommandExecution") {
53
- const status = str(item.status, "CommandExecution.status");
54
- if (!["completed", "failed", "declined", "in_progress"].includes(status))
55
- throw new Error(`Unsupported Codex command status: ${status}`);
56
- return { error: status === "failed" || status === "declined" || (typeof item.exit_code === "number" && item.exit_code !== 0), text: optionalString(item.formatted_output, "formatted_output") };
57
- }
58
- if (item.type === "McpToolCall") {
59
- const result = item.result == null ? undefined : obj(item.result, "MCP result");
60
- if (result?.isError != null && typeof result.isError !== "boolean")
61
- throw new Error("Invalid Codex MCP isError");
62
- return { error: item.status === "failed" || item.error != null || result?.isError === true, ...(result === undefined ? {} : { text: JSON.stringify(result) }) };
63
- }
64
- if (item.type === "DynamicToolCall")
65
- return { error: item.success === false || item.status === "failed" || item.error != null };
66
- if (item.type === "FileChange" || item.type === "CollabAgentToolCall")
67
- return { error: item.status === "failed" || item.status === "declined" || item.status === "interrupted" };
68
- return {};
69
- }
70
- function toolDisplay(item) {
71
- return ["CommandExecution", "McpToolCall", "DynamicToolCall", "CollabAgentToolCall", "FileChange", "ImageView", "Extension"].includes(String(item.type));
72
- }
73
- function response(record, facts) {
74
- const p = record.payload, type = str(p.type, "response_item.type"), base = context(record, "");
75
- if (type === "message") {
76
- if (!["user", "assistant", "system", "developer"].includes(str(p.role, "message.role")))
77
- throw new Error(`Unsupported Codex message role: ${String(p.role)}`);
78
- return { ...base, role: record.metadata?.compaction_output === true ? "system" : p.role, text: textContent(p.content) };
79
- }
80
- if (type === "function_call" || type === "custom_tool_call" || type === "local_shell_call") {
81
- const callId = optionalString(p.call_id, "call_id") ?? (type === "local_shell_call" ? optionalString(p.id, "local shell id") : undefined);
82
- if (!callId)
83
- throw new Error("Invalid Codex tool call: missing native call ID");
84
- const name = type === "local_shell_call" ? "local_shell" : str(p.name, "tool name");
85
- const args = type === "local_shell_call" ? obj(p.action, "local shell action") : type === "custom_tool_call" ? { input: str(p.input, "custom tool input") } : argumentsOf(str(p.arguments, "function arguments"));
86
- return { ...base, role: "tool_call", toolName: p.namespace ? `${str(p.namespace, "namespace")}.${name}` : name, toolCallId: callKey(record, callId), arguments: args };
87
- }
88
- if (type === "function_call_output" || type === "custom_tool_call_output") {
89
- const callId = optionalString(p.call_id, "output.call_id"), recorded = callId ? facts.get(callKey(record, callId)) : undefined;
90
- return { ...base, role: "tool", text: output(p.output), ...(callId ? { toolCallId: callKey(record, callId) } : {}), ...(p.name == null ? {} : { toolName: str(p.name, "output.name") }), ...(recorded?.error === undefined ? {} : { toolError: recorded.error }) };
91
- }
92
- if (type === "agent_message")
93
- return host(record, "agent_message", { author: p.author, recipient: p.recipient, text: textContent(p.content) });
94
- if (OPAQUE_RESPONSES.has(type)) {
95
- // Preserve recorded summaries and available metadata, not encrypted blobs or image bytes.
96
- const { encrypted_content: _encrypted, result: _image, ...readable } = p;
97
- return host(record, `${type} (opaque content omitted; not recovered plaintext)`, readable);
98
- }
99
- if (HOST_RESPONSES.has(type))
100
- return host(record, type, p);
101
- throw new Error(`Unsupported Codex response item: ${type}`);
102
- }
103
- /** One display record without a raw equivalent (e.g. user-shell command). */
104
- function standaloneTool(record, item) {
105
- const base = context(record, ""), recorded = fact(item);
106
- if (item.type === "CommandExecution") {
107
- array(item.command, "command").forEach((part) => str(part, "command argument"));
108
- return { ...base, role: "tool", toolName: "terminal", arguments: { command: item.command, cwd: item.cwd, source: item.source, ...(item.interaction_input == null ? {} : { interaction_input: item.interaction_input }) }, text: recorded.text ?? JSON.stringify({ stdout: item.stdout, stderr: item.stderr, aggregated_output: item.aggregated_output }), recordedStatus: item.status === "in_progress" ? "unfinished" : recorded.error ? "error" : "ok" };
109
- }
110
- const name = `${str(item.server, "MCP server")}/${str(item.tool, "MCP tool")}`;
111
- return { ...base, role: "tool", toolName: name, arguments: obj(item.arguments, "MCP arguments"), text: recorded.text ?? (item.error == null ? "" : JSON.stringify(item.error)), recordedStatus: item.status === "inProgress" ? "unfinished" : recorded.error ? "error" : "ok" };
112
- }
113
- export async function readCodexHistory(source) {
114
- const { state, records, highestSeq } = await readCodexTranscript(source);
115
- const facts = new Map(), callsSeen = new Set(), responseIdsSeen = new Set();
116
- const windows = new Map(), branchSeqs = new Set();
117
- const addWindow = (nativeId, createdAt) => {
118
- const windowId = `codex:${source.threadId}:${nativeId}`;
119
- let window = windows.get(windowId);
120
- if (!window) {
121
- window = { windowId, createdAt, items: [] };
122
- windows.set(windowId, window);
123
- }
124
- return window;
125
- };
126
- // Outcome inventory can enrich the raw result even when ItemCompleted follows it.
127
- for (const record of records) {
128
- const p = record.payload;
129
- if (record.type === "event_msg" && p.type === "item_completed") {
130
- if (p.thread_id !== record.owner)
131
- throw new Error("Invalid Codex ItemCompleted thread identity");
132
- const item = obj(p.item, "ItemCompleted.item");
133
- if (toolDisplay(item))
134
- facts.set(callKey(record, str(item.id, "TurnItem.id")), fact(item));
135
- }
136
- else if (record.type === "event_msg" && p.type === "patch_apply_end") {
137
- if (typeof p.success !== "boolean")
138
- throw new Error("Invalid Codex patch_apply_end.success");
139
- facts.set(callKey(record, str(p.call_id, "patch call_id")), { error: !p.success });
140
- }
141
- else if (record.type === "event_msg" && p.type === "mcp_tool_call_end") {
142
- const result = obj(p.result, "MCP Result envelope");
143
- const ok = result.Ok == null ? undefined : obj(result.Ok, "MCP Result.Ok");
144
- if (ok === undefined && typeof result.Err !== "string")
145
- throw new Error("Invalid Codex MCP Result: expected Ok or Err");
146
- facts.set(callKey(record, str(p.call_id, "MCP call_id")), { error: result.Err != null || ok?.isError === true, text: JSON.stringify(result) });
147
- }
148
- }
149
- for (const record of records) {
150
- branchSeqs.add(record.seq);
151
- if (record.windowId)
152
- addWindow(record.windowId, record.type === "session_meta" || record.type === "compacted" ? record.timestamp : undefined);
153
- const p = record.payload;
154
- let item;
155
- switch (record.type) {
156
- case "session_meta":
157
- if (p.subagent_history_start_ordinal != null)
158
- item = context(record, `Codex copied subagent inference prefix omitted: child-local history starts at native ordinal ${String(p.subagent_history_start_ordinal)}. Copied model context does not prove original parent event addresses.`);
159
- break;
160
- case "response_item": {
161
- item = response(record, facts);
162
- if (p.id != null)
163
- responseIdsSeen.add(callKey(record, str(p.id, "response item id")));
164
- if (item.role === "tool_call" && item.toolCallId) {
165
- if (callsSeen.has(item.toolCallId))
166
- throw new Error(`Unavailable Codex history: duplicate native call ID ${item.toolCallId}`);
167
- callsSeen.add(item.toolCallId);
168
- }
169
- break;
170
- }
171
- case "compacted":
172
- item = context(record, `Codex compaction boundary\n${JSON.stringify({ message: p.message, window_number: p.window_number, first_window_id: p.first_window_id, previous_window_id: p.previous_window_id, window_id: p.window_id, replacement_history_items: Array.isArray(p.replacement_history) ? p.replacement_history.length : null })}\nreplacement_history is an inference checkpoint, not new conversation events.`);
173
- break;
174
- case "event_msg": {
175
- const type = str(p.type, "event_msg.type");
176
- if (DISPLAY_COPIES.has(type))
177
- break;
178
- // A rollback changes the native selected window retrospectively. Until its
179
- // turn semantics are decoded, don't return stale-but-plausible boot facts.
180
- if (type === "thread_rolled_back")
181
- throw new Error("Unavailable Codex history: thread_rolled_back selection is not supported");
182
- if (type === "patch_apply_end" && callsSeen.has(callKey(record, str(p.call_id, "patch call_id"))))
183
- break;
184
- if (type === "mcp_tool_call_end") {
185
- const call = callKey(record, str(p.call_id, "MCP call_id"));
186
- if (!callsSeen.has(call))
187
- item = host(record, "MCP completion without a recorded raw call", p);
188
- break;
189
- }
190
- if (type === "item_completed") {
191
- const display = obj(p.item, "ItemCompleted.item"), kind = str(display.type, "TurnItem.type");
192
- if (ITEM_COPIES.has(kind))
193
- break;
194
- if (toolDisplay(display) && callsSeen.has(callKey(record, str(display.id, "TurnItem.id"))))
195
- break;
196
- if (kind === "CommandExecution" || kind === "McpToolCall") {
197
- item = standaloneTool(record, display);
198
- }
199
- else if (kind === "FunctionCallOutput") {
200
- // hook_runtime.rs record_pending_input persists raw output FIRST,
201
- // then emits this presentation copy with the SAME response-item ID.
202
- if (!responseIdsSeen.has(callKey(record, str(display.id, "FunctionCallOutput.id"))))
203
- item = host(record, "FunctionCallOutput display without raw output", display);
204
- }
205
- else if (HOST_ITEMS.has(kind) || kind === "DynamicToolCall")
206
- item = host(record, kind, display);
207
- else
208
- throw new Error(`Unsupported Codex TurnItem: ${kind}`);
209
- }
210
- else if (HOST_EVENTS.has(type)) {
211
- // Lifecycle's repeated final answer isn't a second assistant message.
212
- const { last_agent_message: _displayCopy, ...facts } = p;
213
- item = host(record, type, facts);
214
- }
215
- else
216
- throw new Error(`Unsupported Codex persisted event: ${type}`);
217
- break;
218
- }
219
- case "turn_context":
220
- case "token_usage_record":
221
- case "security_risk_score":
222
- case "inter_agent_communication_metadata": break;
223
- case "world_state":
224
- item = context(record, "Codex world_state snapshot/patch omitted from the text projection; not a newly spoken message.");
225
- break;
226
- case "inter_agent_communication":
227
- item = host(record, "inter-agent communication", { author: p.author, recipient: p.recipient, content: p.encrypted_content == null ? p.content : "[encrypted content unavailable]", trigger_turn: p.trigger_turn });
228
- break;
229
- case "retained_context":
230
- case "realtime_item":
231
- item = context(record, `Codex ${record.type} omitted from text projection; native structured/retained context is not newly spoken dialogue.`);
232
- break;
233
- }
234
- if (item)
235
- addWindow(record.windowId).items.push({ ...item, windowId: `codex:${source.threadId}:${record.windowId}` });
236
- }
237
- return { ...state, projection: projectHistory([...windows.values()], highestSeq, branchSeqs) };
238
- }
1
+ /** Codex's SDK-facing entry; the local corpus uses the same persisted wire decoder. */
2
+ export { readCodexHistory } from "../../../src/history/codex.js";
@@ -27,7 +27,7 @@ export function bootWithinCap(boot) {
27
27
  const bytes = Buffer.byteLength(boot, "utf8");
28
28
  return bytes <= MAX_BOOT_BYTES
29
29
  ? undefined
30
- : `notesoup: this window's boot is ${bytes} bytes, over the ${MAX_BOOT_BYTES}-byte cap. No truncated or spilled boot was injected; slim the home MAPs and restart/resume the thread.`;
30
+ : `notesoup: this window's boot is ${bytes} bytes, over the ${MAX_BOOT_BYTES}-byte cap. No truncated or spilled boot was injected; slim the notebook MAPs and restart/resume the thread.`;
31
31
  }
32
32
  export async function readHookInput(stream) {
33
33
  return await new Promise((resolveInput, reject) => {
@@ -23,7 +23,7 @@ export declare function safeThreadId(value: unknown, field?: string): string;
23
23
  /** The portable server and the hook must share this root; Codex injects it into both. */
24
24
  export declare function pluginDataRoot(env?: NodeJS.ProcessEnv): string;
25
25
  export declare function notesHome(env?: NodeJS.ProcessEnv): string;
26
- /** Native ids arrive provider-prefixed; @model is the last segment, slugged like every other home. */
26
+ /** Native ids arrive provider-prefixed; @model is the last segment, slugged like every other notebook. */
27
27
  export declare function modelSlug(value: unknown): string | undefined;
28
28
  /** Validate every field before it becomes an identity; a corrupt binding never half-applies. */
29
29
  export declare function readBinding(root: string, threadId: string): Promise<ThreadBinding>;
@@ -24,7 +24,7 @@ export function safeThreadId(value, field = "threadId") {
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)) {
27
- throw new CodexIdentityError("missing_plugin_data", "PLUGIN_DATA is unavailable. Install notesoup as a Codex plugin (or set PLUGIN_DATA for a standalone test) so hook bindings have one mutable home.");
27
+ throw new CodexIdentityError("missing_plugin_data", "PLUGIN_DATA is unavailable. Install notesoup as a Codex plugin (or set PLUGIN_DATA for a standalone test) so hook bindings have one mutable data directory.");
28
28
  }
29
29
  return resolve(value);
30
30
  }
@@ -32,7 +32,7 @@ export function notesHome(env = process.env) {
32
32
  const value = env.NOTESOUP_HOME;
33
33
  return value !== undefined && value.trim() !== "" ? resolve(value) : join(homedir(), ".agents", "notes");
34
34
  }
35
- /** Native ids arrive provider-prefixed; @model is the last segment, slugged like every other home. */
35
+ /** Native ids arrive provider-prefixed; @model is the last segment, slugged like every other notebook. */
36
36
  export function modelSlug(value) {
37
37
  if (typeof value !== "string")
38
38
  return undefined;
@@ -126,7 +126,7 @@ export function turnModel(meta) {
126
126
  const model = typeof value === "object" && value !== null ? value.model : undefined;
127
127
  const slug = modelSlug(model);
128
128
  if (slug === undefined)
129
- throw new CodexIdentityError("missing_model", "Codex did not supply this turn's model in MCP metadata, so notesoup cannot choose an @model home. Update Codex, or call notes from a model turn.");
129
+ throw new CodexIdentityError("missing_model", "Codex did not supply this turn's model in MCP metadata, so notesoup cannot choose an @model notebook. Update Codex, or call notes from a model turn.");
130
130
  return slug;
131
131
  }
132
132
  export function rootSessionIdOf(meta) {
@@ -4,11 +4,13 @@ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"
4
4
  import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
5
5
  import { Check, Errors } from "typebox/value";
6
6
  import { notesList, notesRead, notesSearch, notesUpdate, notesWrite } from "../../../src/tools/notes.js";
7
- import { historyList, historyRead, historyWindows } from "../../../src/tools/history.js";
7
+ import { historyList, historyRead } from "../../../src/tools/history.js";
8
8
  import { wireResult } from "../../../src/tools/result.js";
9
9
  import { CodexIdentityError, notesIdentityFor, pluginDataRoot, readBinding, rootSessionIdOf, safeThreadId, turnModel } from "./identity.js";
10
10
  import { readCodexHistory } from "./history.js";
11
+ import { localHistoryCorpus } from "../../../src/history/local.js";
11
12
  import { readStartState } from "./state.js";
13
+ import { notesToolContext } from "../../../src/tools/notes-context.js";
12
14
  const OPERATIONS = {
13
15
  notes_write: { operation: notesWrite, history: false },
14
16
  notes_update: { operation: notesUpdate, history: false },
@@ -17,7 +19,6 @@ const OPERATIONS = {
17
19
  notes_search: { operation: notesSearch, history: false },
18
20
  history_list: { operation: historyList, history: true },
19
21
  history_read: { operation: historyRead, history: true },
20
- history_windows: { operation: historyWindows, history: true },
21
22
  };
22
23
  function shellFree(reason) {
23
24
  const value = reason instanceof Error ? reason.message : String(reason);
@@ -117,15 +118,15 @@ export async function callTool(name, args, meta, env = process.env) {
117
118
  return failure("invalid_params", `invalid ${name} parameters: ${paramProblem(bound.operation.parameters, params)}`);
118
119
  try {
119
120
  const { binding, rootSessionId, model } = await identityFor(meta, env);
120
- const native = await readNative(binding, rootSessionId, bound.history, meta, env);
121
+ const targetedHistory = bound.history && params.session !== undefined;
122
+ const native = await readNative(binding, rootSessionId, bound.history && !targetedHistory, meta, env);
121
123
  if (!bound.history) {
122
- const outcome = await bound.operation.execute(params, notesIdentityFor(binding, model));
124
+ const outcome = await bound.operation.execute(params, notesToolContext(notesIdentityFor(binding, model), binding.cwd));
123
125
  return successFor(bound, outcome);
124
126
  }
125
- const projection = native.projection;
126
- const outcome = name === "history_windows"
127
- ? await bound.operation.execute(params, projection, binding.threadId)
128
- : await bound.operation.execute(params, projection);
127
+ const current = async () => (await readNative(binding, rootSessionId, true, meta, env)).projection;
128
+ const context = targetedHistory ? { current, corpus: localHistoryCorpus({ env, current: { harness: "codex", id: binding.threadId, load: async () => ({ projection: await current() }) } }) } : native.projection;
129
+ const outcome = await bound.operation.execute(params, context);
129
130
  return successFor(bound, outcome);
130
131
  }
131
132
  catch (error) {
@@ -10,5 +10,5 @@ export declare const CODEX_PRE_RESET_HINTS: string;
10
10
  export declare const CODEX_SETUP_HINT = "Enable and trust the notesoup plugin in Codex, then start or resume the thread. notesoup binds identities from hooks and never from the MCP server's cwd.";
11
11
  export declare function unsupportedChildCompaction(): string;
12
12
  export declare function missingNativeFacts(reason: string): string;
13
- /** A boot can still identify itself when the note store itself refused; it must not pretend homes are empty. */
13
+ /** A boot can still identify itself when the note store itself refused; it must not pretend notebooks are empty. */
14
14
  export declare function notesFailureBoot(reason: string): string;
@@ -19,7 +19,7 @@ export function unsupportedChildCompaction() {
19
19
  export function missingNativeFacts(reason) {
20
20
  return `notesoup: no boot injected because Codex's native window facts could not be read (${reason}). ${CODEX_SETUP_HINT} notesoup supports Codex 0.160.1 transcripts.`;
21
21
  }
22
- /** A boot can still identify itself when the note store itself refused; it must not pretend homes are empty. */
22
+ /** A boot can still identify itself when the note store itself refused; it must not pretend notebooks are empty. */
23
23
  export function notesFailureBoot(reason) {
24
- return `notesoup: your notes did not load this time (${reason}). Try the notes_list tool; if it fails too, tell the human. Do not assume a home is empty from this failure.`;
24
+ return `notesoup: your notes did not load this time (${reason}). Try the notes_list tool; if it fails too, tell the human. Do not assume a notebook is empty from this failure.`;
25
25
  }
@@ -1,39 +1,3 @@
1
- export type CodexTranscriptSource = {
2
- transcriptPath: string;
3
- threadId: string;
4
- };
5
- export type CodexTranscriptState = {
6
- threadId: string;
7
- rootSessionId: string;
8
- cliVersion: string;
9
- cwd: string;
10
- model?: string;
11
- /** Native, UNPREFIXED identities, also used by MCP _meta.windowId. */
12
- currentWindowId?: string;
13
- currentWindowNumber?: number;
14
- firstWindowId?: string;
15
- previousWindowId?: string;
16
- };
17
- export type NativeObject = Record<string, unknown>;
18
- export type CodexRecord = {
19
- type: string;
20
- payload: NativeObject;
21
- metadata?: NativeObject;
22
- timestamp: string;
23
- /** One record owns one seq, including records omitted from presentation. */
24
- seq: number;
25
- /** Metadata belongs to its physical segment, not the root-scoped session_id. */
26
- owner: string;
27
- /** Native window at this point, absent only when the producer did not persist it. */
28
- windowId?: string;
29
- };
30
- export declare function nativeObject(value: unknown, field: string): NativeObject;
31
- export declare function nativeString(value: unknown, field: string): string;
32
- /** Internal shared read: both boot facts and history use exactly this lineage and window owner. */
33
- export declare function readCodexTranscript(source: CodexTranscriptSource): Promise<{
34
- state: CodexTranscriptState;
35
- records: CodexRecord[];
36
- highestSeq: number;
37
- }>;
38
- /** Same decoder and ownership as history; no independently guessed boot window. */
39
- export declare function readCodexTranscriptState(source: CodexTranscriptSource): Promise<CodexTranscriptState>;
1
+ /** Codex wire-format entry shared by boot/state and cross-harness history. */
2
+ export { nativeObject, nativeString, readCodexTranscript, readCodexTranscriptState } from "../../../src/history/codex-transcript.js";
3
+ export type { CodexTranscriptSource, CodexTranscriptState, CodexRecord, NativeObject } from "../../../src/history/codex-transcript.js";