notesoup 0.60.1 → 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 -10
  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.d.ts +5 -0
  37. package/dist/src/boot/render.js +60 -28
  38. package/dist/src/boot/text.d.ts +3 -3
  39. package/dist/src/boot/text.js +27 -26
  40. package/dist/src/budget/text.d.ts +2 -2
  41. package/dist/src/budget/text.js +13 -13
  42. package/dist/src/history/claude.d.ts +2 -0
  43. package/dist/src/history/claude.js +46 -0
  44. package/dist/src/history/codex-transcript.js +7 -5
  45. package/dist/src/history/codex.js +3 -0
  46. package/dist/src/history/corpus.d.ts +28 -1
  47. package/dist/src/history/corpus.js +40 -0
  48. package/dist/src/history/history.d.ts +37 -46
  49. package/dist/src/history/history.js +21 -40
  50. package/dist/src/history/local.js +67 -32
  51. package/dist/src/history/pi.d.ts +2 -1
  52. package/dist/src/history/pi.js +122 -48
  53. package/dist/src/history/prefilter.js +76 -19
  54. package/dist/src/history/query.d.ts +28 -49
  55. package/dist/src/history/query.js +83 -68
  56. package/dist/src/history/summary-cache.d.ts +8 -1
  57. package/dist/src/history/summary-cache.js +138 -12
  58. package/dist/src/index.d.ts +1 -1
  59. package/dist/src/index.js +1 -1
  60. package/dist/src/notes/frontmatter.d.ts +4 -0
  61. package/dist/src/notes/frontmatter.js +15 -1
  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 +47 -6
  66. package/dist/src/notes/store.d.ts +14 -0
  67. package/dist/src/notes/store.js +33 -12
  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 -91
  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 +58 -160
  75. package/dist/src/tools/notes.js +151 -99
  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 +189 -56
  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 +4 -4
  115. package/docs/history-sessions.md +28 -50
  116. package/docs/notes-library.md +6 -6
  117. package/docs/reset-lifecycle.md +1 -1
  118. package/docs/skills.md +3 -3
  119. package/docs/tool-results.md +47 -28
  120. package/package.json +3 -2
  121. package/playbook.md +3 -3
  122. package/plugins/antigravity/dist/antigravity/notesoup.js +26886 -0
  123. package/plugins/antigravity/hooks.json +7 -0
  124. package/plugins/antigravity/mcp_config.json +8 -0
  125. package/plugins/antigravity/plugin.json +6 -0
  126. package/plugins/antigravity/src/cli.ts +22 -0
  127. package/plugins/antigravity/src/hooks.ts +51 -0
  128. package/plugins/antigravity/src/identity.ts +127 -0
  129. package/plugins/claude/.claude-plugin/plugin.json +1 -1
  130. package/plugins/claude/dist/claude/helper.js +1129 -549
  131. package/plugins/claude/hooks/register.ts +2 -2
  132. package/plugins/claude/playbook.md +3 -3
  133. package/plugins/claude/skills/dream/SKILL.md +2 -2
  134. package/plugins/claude/skills/notesoup/SKILL.md +92 -0
  135. package/plugins/claude/src/helper.ts +2 -1
  136. package/plugins/codex/.codex-plugin/plugin.json +8 -0
  137. package/plugins/codex/.mcp.json +11 -0
  138. package/plugins/codex/README.md +5 -21
  139. package/plugins/codex/dist/codex/notesoup.js +18494 -17905
  140. package/plugins/codex/src/hooks.ts +1 -0
  141. package/plugins/codex/src/identity.ts +14 -1
  142. package/plugins/codex/src/mcp.ts +28 -98
  143. package/plugins/codex/src/text.ts +3 -3
  144. package/plugins/dsh/tools.ts +8 -4
  145. package/plugins/mcp/operations.ts +50 -0
  146. package/plugins/mcp/server.ts +23 -0
  147. package/plugins/paseo/README.md +5 -10
  148. package/plugins/paseo/client/brain-empty-card.tsx +3 -3
  149. package/plugins/paseo/client/markdown.tsx +50 -38
  150. package/plugins/paseo/client/notes-op-card.tsx +12 -9
  151. package/plugins/paseo/client/paper-card.tsx +6 -5
  152. package/plugins/paseo/client/paper-palette.ts +2 -9
  153. package/plugins/paseo/client/sticky-card.tsx +2 -2
  154. package/plugins/paseo/client/tool-result.ts +7 -14
  155. package/plugins/paseo/package-lock.json +3406 -0
  156. package/plugins/paseo/package.json +1 -0
  157. package/plugins/paseo/test/markdown-core.test.ts +73 -66
  158. package/plugins/pi/budget.ts +3 -3
  159. package/plugins/pi/entries.ts +1 -0
  160. package/plugins/pi/history-tools.ts +2 -1
  161. package/plugins/pi/history.ts +30 -1
  162. package/plugins/pi/notes/tools.ts +7 -3
  163. package/plugins/pi/render.ts +6 -6
  164. package/plugins/pi/reset/lifecycle.ts +9 -10
  165. package/plugins/pi/runtime.ts +96 -60
  166. package/plugins/pi/tool-result.ts +8 -8
  167. package/plugins/pi/window.ts +198 -9
  168. package/skills/dream/SKILL.md +2 -2
  169. package/skills/notesoup/SKILL.md +92 -0
  170. package/src/boot/render.ts +59 -25
  171. package/src/boot/text.ts +30 -27
  172. package/src/budget/text.ts +13 -13
  173. package/src/history/claude.ts +41 -0
  174. package/src/history/codex-transcript.ts +6 -4
  175. package/src/history/codex.ts +2 -0
  176. package/src/history/corpus.ts +51 -2
  177. package/src/history/history.ts +35 -44
  178. package/src/history/local.ts +67 -27
  179. package/src/history/pi.ts +113 -35
  180. package/src/history/prefilter.ts +73 -15
  181. package/src/history/query.ts +93 -73
  182. package/src/history/summary-cache.ts +142 -17
  183. package/src/index.ts +1 -1
  184. package/src/notes/frontmatter.ts +16 -1
  185. package/src/notes/index.ts +1 -1
  186. package/src/notes/policy.ts +45 -6
  187. package/src/notes/store.ts +30 -15
  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 +150 -112
  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
@@ -32,6 +32,45 @@ export function prefixFit(text, fits) {
32
32
  }
33
33
  return chars.slice(0, low).join("");
34
34
  }
35
+ /** Compile literal Unicode case-insensitive patterns once per search operation. */
36
+ export function compileSearchQueries(queries) {
37
+ return queries.map((query) => new RegExp(query.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "iu"));
38
+ }
39
+ /** Count Unicode code points in `text.slice(0, utf16End)` without allocating an array. */
40
+ export function codePointCount(text, utf16End = text.length) {
41
+ let count = utf16End;
42
+ for (let i = 0; i < utf16End - 1; i++) {
43
+ const code = text.charCodeAt(i);
44
+ if (code >= 0xd800 && code <= 0xdbff) {
45
+ const next = text.charCodeAt(i + 1);
46
+ if (next >= 0xdc00 && next <= 0xdfff) {
47
+ count--;
48
+ i++;
49
+ }
50
+ }
51
+ }
52
+ return count;
53
+ }
54
+ /** Slice `[start, start + limit)` code points without splitting the entire string into an array. */
55
+ export function sliceCodePoints(text, start, limit) {
56
+ const len = text.length;
57
+ let utf16Start = 0;
58
+ let cp = 0;
59
+ while (cp < start && utf16Start < len) {
60
+ const code = text.charCodeAt(utf16Start);
61
+ utf16Start += code >= 0xd800 && code <= 0xdbff && utf16Start + 1 < len && text.charCodeAt(utf16Start + 1) >= 0xdc00 && text.charCodeAt(utf16Start + 1) <= 0xdfff ? 2 : 1;
62
+ cp++;
63
+ }
64
+ let utf16End = utf16Start;
65
+ let taken = 0;
66
+ while (taken < limit && utf16End < len) {
67
+ const code = text.charCodeAt(utf16End);
68
+ utf16End += code >= 0xd800 && code <= 0xdbff && utf16End + 1 < len && text.charCodeAt(utf16End + 1) >= 0xdc00 && text.charCodeAt(utf16End + 1) <= 0xdfff ? 2 : 1;
69
+ taken++;
70
+ }
71
+ const truncated = start > 0 || utf16End < len;
72
+ return { text: truncated ? text.slice(utf16Start, utf16End) : text, truncated };
73
+ }
35
74
  /**
36
75
  * Code-point offset of the earliest case-insensitive literal match, or -1 when
37
76
  * none occurs. Match against the original text so Unicode casing cannot shift offsets.
@@ -39,12 +78,12 @@ export function prefixFit(text, fits) {
39
78
  export function earliestMatchOffsetChars(text, queries) {
40
79
  let earliest = -1;
41
80
  for (const query of queries) {
42
- const literal = query.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
43
- const index = new RegExp(literal, "iu").exec(text)?.index ?? -1;
81
+ const pattern = typeof query === "string" ? new RegExp(query.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "iu") : query;
82
+ const index = pattern.exec(text)?.index ?? -1;
44
83
  if (index < 0)
45
84
  continue;
46
85
  if (earliest < 0 || index < earliest)
47
86
  earliest = index;
48
87
  }
49
- return earliest < 0 ? -1 : Array.from(text.slice(0, earliest)).length;
88
+ return earliest < 0 ? -1 : codePointCount(text, earliest);
50
89
  }
@@ -1,6 +1,9 @@
1
1
  import { Type, type Static } from "typebox";
2
- import { type NotesIdentity } from "../notes/index.js";
2
+ import { noteIdentity, type NotesIdentity } from "../notes/index.js";
3
+ import { type ProjectReceipt } from "../notes/project-namespace.js";
3
4
  import { type Outcome } from "../result.js";
5
+ import { type ListedFile, type Snapshot } from "./notes.js";
6
+ import { type NotesToolContext } from "./notes-context.js";
4
7
  /** The one open dream per session; the host owns where it lives. */
5
8
  type DreamOpening = {
6
9
  project: string;
@@ -18,121 +21,49 @@ export declare function abandonDream(state: DreamState): void;
18
21
  /** The identity a store uses while `state` holds an open dream. */
19
22
  export declare function dreamingIdentity(identity: NotesIdentity, state: DreamState): NotesIdentity;
20
23
  export declare const dreamBeginParameters: Type.TObject<{
21
- project: Type.TOptional<Type.TString>;
24
+ cwd: Type.TOptional<Type.TString>;
22
25
  }>;
23
- export declare const DreamBeginDataSchema: Type.TObject<{
24
- more: Type.TInteger;
25
- namespaces_unavailable: Type.TArray<Type.TString>;
26
- project: Type.TString;
27
- baseline: Type.TString;
28
- files: Type.TArray<Type.TObject<{
29
- last_accessed: Type.TString;
30
- updated_at: Type.TString;
31
- crumpled_at: Type.TOptional<Type.TString>;
32
- warnings: Type.TArray<Type.TString>;
33
- pinned: Type.TBoolean;
34
- budget: Type.TInteger;
35
- readonly: Type.TBoolean;
36
- project_root: Type.TOptional<Type.TString>;
37
- project_siblings: Type.TOptional<Type.TArray<Type.TObject<{
38
- name: Type.TString;
39
- path: Type.TString;
40
- }>>>;
41
- address: Type.TString;
42
- project_key: Type.TOptional<Type.TString>;
43
- }>>;
44
- }>;
45
- export type DreamBeginData = Static<typeof DreamBeginDataSchema>;
26
+ export type DreamBeginData = Snapshot<ListedFile & {
27
+ last_accessed: string;
28
+ }> & {
29
+ project: string;
30
+ baseline: string;
31
+ } & ProjectReceipt;
46
32
  export declare const dreamBegin: {
47
33
  readonly name: "dream_begin";
48
34
  readonly label: "Dream begin";
49
- readonly description: "Spread one project's pages across the table — its project shelf, every session page born there, crumpled balls included. Until `dream_end` your pen works on all of them; other sessions' pages can be rewritten, not added to.";
35
+ readonly description: "Open a project's notes and its session notes for consolidation after committing a Git baseline; unlocks writes until `dream_end`.";
50
36
  readonly parameters: Type.TObject<{
51
- project: Type.TOptional<Type.TString>;
37
+ cwd: Type.TOptional<Type.TString>;
52
38
  }>;
53
- readonly outputSchema: Type.TUnion<[Type.TObject<{
54
- more: Type.TInteger;
55
- namespaces_unavailable: Type.TArray<Type.TString>;
56
- project: Type.TString;
57
- baseline: Type.TString;
58
- files: Type.TArray<Type.TObject<{
59
- last_accessed: Type.TString;
60
- updated_at: Type.TString;
61
- crumpled_at: Type.TOptional<Type.TString>;
62
- warnings: Type.TArray<Type.TString>;
63
- pinned: Type.TBoolean;
64
- budget: Type.TInteger;
65
- readonly: Type.TBoolean;
66
- project_root: Type.TOptional<Type.TString>;
67
- project_siblings: Type.TOptional<Type.TArray<Type.TObject<{
68
- name: Type.TString;
69
- path: Type.TString;
70
- }>>>;
71
- address: Type.TString;
72
- project_key: Type.TOptional<Type.TString>;
73
- }>>;
74
- }>, Type.TObject<{
75
- error: Type.TString;
76
- code: Type.TString;
77
- }>]>;
78
- readonly execute: (params: Static<typeof dreamBeginParameters>, identity: NotesIdentity, state: DreamState) => Promise<Outcome<DreamBeginData>>;
39
+ readonly execute: (params: Static<typeof dreamBeginParameters>, context: NotesToolContext, state: DreamState) => Promise<Outcome<DreamBeginData>>;
79
40
  readonly render: (result: Outcome<DreamBeginData>) => string;
80
41
  };
81
42
  export declare const dreamForgetParameters: Type.TObject<{
82
43
  address: Type.TString;
83
44
  }>;
84
- export declare const DreamForgetDataSchema: Type.TObject<{
85
- project_root: Type.TOptional<Type.TString>;
86
- project_siblings: Type.TOptional<Type.TArray<Type.TObject<{
87
- name: Type.TString;
88
- path: Type.TString;
89
- }>>>;
90
- address: Type.TString;
91
- project_key: Type.TOptional<Type.TString>;
92
- }>;
93
- export type DreamForgetData = Static<typeof DreamForgetDataSchema>;
45
+ export type DreamForgetData = ReturnType<typeof noteIdentity>;
94
46
  export declare const dreamForget: {
95
47
  readonly name: "dream_forget";
96
48
  readonly label: "Dream forget";
97
- readonly description: "Throw a crumpled page in the bin for good. Only crumpled pages go.";
49
+ readonly description: "Permanently delete a crumpled note in the open dream.";
98
50
  readonly parameters: Type.TObject<{
99
51
  address: Type.TString;
100
52
  }>;
101
- readonly outputSchema: Type.TUnion<[Type.TObject<{
102
- project_root: Type.TOptional<Type.TString>;
103
- project_siblings: Type.TOptional<Type.TArray<Type.TObject<{
104
- name: Type.TString;
105
- path: Type.TString;
106
- }>>>;
107
- address: Type.TString;
108
- project_key: Type.TOptional<Type.TString>;
109
- }>, Type.TObject<{
110
- error: Type.TString;
111
- code: Type.TString;
112
- }>]>;
113
53
  readonly execute: (params: Static<typeof dreamForgetParameters>, identity: NotesIdentity, state: DreamState) => Promise<Outcome<DreamForgetData>>;
114
54
  readonly render: (result: Outcome<DreamForgetData>) => string;
115
55
  };
116
56
  export declare const dreamEndParameters: Type.TObject<{}>;
117
- export declare const DreamEndDataSchema: Type.TObject<{
118
- project: Type.TString;
119
- commit: Type.TOptional<Type.TString>;
120
- audit_error: Type.TOptional<Type.TString>;
121
- }>;
122
- export type DreamEndData = Static<typeof DreamEndDataSchema>;
57
+ export type DreamEndData = {
58
+ project: string;
59
+ commit?: string;
60
+ audit_error?: string;
61
+ };
123
62
  export declare const dreamEnd: {
124
63
  readonly name: "dream_end";
125
64
  readonly label: "Dream end";
126
- readonly description: "Stack the pages, file them, close the drawer.";
65
+ readonly description: "Commit dream changes to the notes Git repo and close the open dream.";
127
66
  readonly parameters: Type.TObject<{}>;
128
- readonly outputSchema: Type.TUnion<[Type.TObject<{
129
- project: Type.TString;
130
- commit: Type.TOptional<Type.TString>;
131
- audit_error: Type.TOptional<Type.TString>;
132
- }>, Type.TObject<{
133
- error: Type.TString;
134
- code: Type.TString;
135
- }>]>;
136
67
  readonly execute: (_params: Static<typeof dreamEndParameters>, identity: NotesIdentity, state: DreamState) => Promise<Outcome<DreamEndData>>;
137
68
  readonly render: (result: Outcome<DreamEndData>) => string;
138
69
  };
@@ -2,13 +2,14 @@
2
2
  import { join } from "node:path";
3
3
  import { Type } from "typebox";
4
4
  import { localIso } from "../notes/frontmatter.js";
5
- import { createNotesStore, noteIdentity } from "../notes/index.js";
6
- import { projectNamespaces } from "../notes/project-namespace.js";
5
+ import { compareNoteRows, createNotesStore, noteIdentity } from "../notes/index.js";
6
+ import { projectReceipt } from "../notes/project-namespace.js";
7
7
  import { gitCommit } from "../dream/git.js";
8
8
  import { trySqliteLock } from "../sqlite-lock.js";
9
9
  import { failure, success } from "../result.js";
10
- import { renderOutcome, resultSchema } from "./result.js";
11
- import { failureOf, listedFile, ListedFileSchema, NoteIdentitySchema, renderListData, snapshot, SnapshotSchema } from "./notes.js";
10
+ import { renderOutcome } from "./result.js";
11
+ import { failureOf, listedFile, renderListData, snapshot } from "./notes.js";
12
+ import { notesIdentityForCall } from "./notes-context.js";
12
13
  function currentOpening(state, opening) {
13
14
  return state.pending === opening && state.generation === opening.generation;
14
15
  }
@@ -43,29 +44,31 @@ export function dreamingIdentity(identity, state) {
43
44
  }
44
45
  const NOT_DREAMING = "No dream is open; call dream_begin first.";
45
46
  export const dreamBeginParameters = Type.Object({
46
- project: Type.Optional(Type.String({ description: "Which project's pages; leave it out for this one." })),
47
- }, { additionalProperties: false });
48
- export const DreamBeginDataSchema = Type.Object({
49
- project: Type.String(), baseline: Type.String(),
50
- files: Type.Array(Type.Object({ ...ListedFileSchema.properties, last_accessed: Type.String() }, { additionalProperties: false })),
51
- ...SnapshotSchema,
47
+ cwd: Type.Optional(Type.String({ minLength: 1, description: "Treat this directory's project as current." })),
52
48
  }, { additionalProperties: false });
53
49
  function renderBeginData(data) {
54
- return `dreaming over ${data.project} (baseline ${data.baseline})\n${renderListData(data)}`;
50
+ const header = `dreaming over ${data.project} (baseline ${data.baseline}${data.project_root === undefined ? "" : `, project_root ${data.project_root}`})`;
51
+ const siblings = data.project_siblings === undefined ? "" : `\n Same-basename projects: ${data.project_siblings.map(sibling => `${sibling.name} (${sibling.path})`).join(", ")}`;
52
+ return `${header}${siblings}\n${renderListData(data, undefined, { omitNamedProjectContext: true })}`;
55
53
  }
56
54
  export const dreamBegin = {
57
55
  name: "dream_begin", label: "Dream begin",
58
- description: "Spread one project's pages across the table — its project shelf, every session page born there, crumpled balls included. Until `dream_end` your pen works on all of them; other sessions' pages can be rewritten, not added to.",
59
- parameters: dreamBeginParameters, outputSchema: resultSchema(DreamBeginDataSchema),
60
- async execute(params, identity, state) {
56
+ description: "Open a project's notes and its session notes for consolidation after committing a Git baseline; unlocks writes until `dream_end`.",
57
+ parameters: dreamBeginParameters,
58
+ async execute(params, context, state) {
61
59
  if (state.project !== undefined || state.pending !== undefined) {
62
60
  const project = state.project ?? state.pending?.project;
63
61
  return failure("already_dreaming", `Already dreaming over ${project}; call dream_end before opening another project.`);
64
62
  }
65
- const project = params.project ?? identity.projectKey;
66
- if (project !== identity.projectKey && !projectNamespaces(identity.home).some(namespace => namespace.name === project)) {
67
- return failure("not_found", `No project named ${JSON.stringify(project)}; notes_list with glob @projects/*/** shows the names.`);
63
+ let identity;
64
+ try {
65
+ identity = notesIdentityForCall(context, params.cwd);
66
+ }
67
+ catch (error) {
68
+ return failureOf(error);
68
69
  }
70
+ const project = identity.projectKey;
71
+ const receipt = projectReceipt(identity.home, project);
69
72
  const release = trySqliteLock(join(identity.home, ".dream.lock.sqlite"), 0);
70
73
  if (!release)
71
74
  return failure("already_dreaming", "Another dream is open in this notes home.");
@@ -85,8 +88,10 @@ export const dreamBegin = {
85
88
  unavailable.push(...result.status.namespacesUnavailable);
86
89
  }
87
90
  }
88
- rows.sort((a, b) => b.meta.updatedAt - a.meta.updatedAt || a.address.localeCompare(b.address));
89
- const listed = snapshot(rows.map(row => ({ ...listedFile(row, identity), last_accessed: localIso(row.meta.lastAccessed) })), undefined, { namespacesUnavailable: unavailable }, renderListData);
91
+ rows.sort(compareNoteRows);
92
+ const listed = snapshot(rows.map(row => ({ ...listedFile(row, identity), last_accessed: localIso(row.meta.lastAccessed) })), undefined, { namespacesUnavailable: unavailable },
93
+ // Reserve the header before committing; Git object IDs are at most 64 hex digits.
94
+ (data) => renderBeginData({ ...data, project, baseline: "0".repeat(64), ...receipt }));
90
95
  if (!listed.ok) {
91
96
  releaseOpening(state, opening);
92
97
  return listed;
@@ -103,7 +108,7 @@ export const dreamBegin = {
103
108
  state.project = opening.project;
104
109
  state.release = opening.release;
105
110
  delete state.pending;
106
- return success({ project, baseline: baseline.commit, ...listed.data });
111
+ return success({ project, baseline: baseline.commit, ...receipt, ...listed.data });
107
112
  }
108
113
  catch (error) {
109
114
  if (!currentOpening(state, opening))
@@ -114,12 +119,11 @@ export const dreamBegin = {
114
119
  },
115
120
  render: (result) => renderOutcome(result, renderBeginData),
116
121
  };
117
- export const dreamForgetParameters = Type.Object({ address: Type.String({ description: "Which crumpled page goes in the bin." }) }, { additionalProperties: false });
118
- export const DreamForgetDataSchema = Type.Object({ ...NoteIdentitySchema }, { additionalProperties: false });
122
+ export const dreamForgetParameters = Type.Object({ address: Type.String({ description: "Address of the crumpled note to delete." }) }, { additionalProperties: false });
119
123
  export const dreamForget = {
120
124
  name: "dream_forget", label: "Dream forget",
121
- description: "Throw a crumpled page in the bin for good. Only crumpled pages go.",
122
- parameters: dreamForgetParameters, outputSchema: resultSchema(DreamForgetDataSchema),
125
+ description: "Permanently delete a crumpled note in the open dream.",
126
+ parameters: dreamForgetParameters,
123
127
  async execute(params, identity, state) {
124
128
  if (state.project === undefined)
125
129
  return failure("not_dreaming", NOT_DREAMING);
@@ -135,11 +139,10 @@ export const dreamForget = {
135
139
  render: (result) => renderOutcome(result, data => `forgot ${data.address}`),
136
140
  };
137
141
  export const dreamEndParameters = Type.Object({}, { additionalProperties: false });
138
- export const DreamEndDataSchema = Type.Object({ project: Type.String(), commit: Type.Optional(Type.String()), audit_error: Type.Optional(Type.String()) }, { additionalProperties: false });
139
142
  export const dreamEnd = {
140
143
  name: "dream_end", label: "Dream end",
141
- description: "Stack the pages, file them, close the drawer.",
142
- parameters: dreamEndParameters, outputSchema: resultSchema(DreamEndDataSchema),
144
+ description: "Commit dream changes to the notes Git repo and close the open dream.",
145
+ parameters: dreamEndParameters,
143
146
  async execute(_params, identity, state) {
144
147
  const project = state.project;
145
148
  if (project === undefined)
@@ -1,41 +1,48 @@
1
- /** Host-neutral history operations: one bounded payload for text and structured results. */
1
+ /** Host-neutral history operations: bounded plain-text output. */
2
2
  import { Type, type Static } from "typebox";
3
- import { type Operation } from "./result.js";
3
+ import { type TextWindow, type Operation } from "./result.js";
4
4
  import { type HistoryPage } from "../history/query.js";
5
5
  import { type HistoryContext } from "../history/corpus.js";
6
+ import { type HistoryRole, type NestedCallSummary, type ToolSummary } from "../history/history.js";
6
7
  /** One read: identity, tool summary and a flat document slice. */
7
- declare const HistoryReadDataSchema: Type.TObject<{
8
- text: Type.TString;
9
- total_chars: Type.TInteger;
10
- next_offset_chars: Type.TUnion<[Type.TInteger, Type.TNull]>;
11
- nested_calls: Type.TOptional<Type.TObject<{
12
- call_count: Type.TInteger;
13
- complete: Type.TBoolean;
14
- }>>;
15
- tool: Type.TOptional<Type.TString>;
16
- tool_status: Type.TOptional<Type.TUnion<[Type.TLiteral<"ok">, Type.TLiteral<"error">, Type.TLiteral<"unfinished">]>>;
17
- output_truncated: Type.TOptional<Type.TLiteral<true>>;
18
- full_output_path: Type.TOptional<Type.TString>;
19
- session: Type.TOptional<Type.TString>;
20
- notice: Type.TOptional<Type.TString>;
21
- seq: Type.TInteger;
22
- role: Type.TUnion<[Type.TLiteral<"user">, Type.TLiteral<"assistant">, Type.TLiteral<"tool">, Type.TLiteral<"context">]>;
23
- created_at: Type.TUnion<[Type.TString, Type.TNull]>;
24
- }>;
25
- type HistoryReadData = Static<typeof HistoryReadDataSchema>;
8
+ type HistoryReadData = ToolSummary & TextWindow & {
9
+ session?: string;
10
+ notice?: string;
11
+ seq: number;
12
+ role: HistoryRole;
13
+ created_at: string | null;
14
+ nested_calls?: NestedCallSummary;
15
+ };
16
+ type TimelinePage = HistoryPage & {
17
+ paging: Omit<Static<typeof historyListParameters>, "after" | "before">;
18
+ };
19
+ type SearchPage = HistoryPage & {
20
+ session?: string;
21
+ };
26
22
  /** Pure host decoration, measured during selection and applied unchanged by the caller at delivery. */
27
23
  export type HistoryTextWrapper = (text: string) => string;
28
24
  export declare const historyListParameters: Type.TObject<{
29
25
  session: Type.TOptional<Type.TString>;
30
- roles: Type.TOptional<Type.TArray<Type.TUnion<[Type.TLiteral<"user">, Type.TLiteral<"assistant">, Type.TLiteral<"tool">, Type.TLiteral<"context">]>>>;
31
- query: Type.TOptional<Type.TUnion<[Type.TString, Type.TArray<Type.TString>]>>;
32
- after: Type.TOptional<Type.TUnion<[Type.TString, Type.TNumber]>>;
33
- before: Type.TOptional<Type.TUnion<[Type.TString, Type.TNumber]>>;
26
+ roles: Type.TOptional<Type.TArray<Type.TUnsafe<"user" | "assistant" | "tool" | "context">>>;
27
+ after: Type.TOptional<Type.TInteger>;
28
+ before: Type.TOptional<Type.TInteger>;
29
+ since: Type.TOptional<Type.TString>;
30
+ until: Type.TOptional<Type.TString>;
31
+ limit: Type.TOptional<Type.TInteger>;
32
+ max_chars_per_item: Type.TOptional<Type.TInteger>;
33
+ }>;
34
+ export declare const historyList: Operation<typeof historyListParameters, TimelinePage | SearchPage, [HistoryContext, HistoryTextWrapper?]>;
35
+ export declare const historySearchParameters: Type.TObject<{
36
+ session: Type.TOptional<Type.TString>;
37
+ query: Type.TUnion<[Type.TString, Type.TArray<Type.TString>]>;
38
+ since: Type.TOptional<Type.TString>;
39
+ until: Type.TOptional<Type.TString>;
40
+ roles: Type.TOptional<Type.TArray<Type.TUnsafe<"user" | "assistant" | "tool" | "context">>>;
34
41
  context: Type.TOptional<Type.TInteger>;
35
42
  limit: Type.TOptional<Type.TInteger>;
36
43
  max_chars_per_item: Type.TOptional<Type.TInteger>;
37
44
  }>;
38
- export declare const historyList: Operation<typeof historyListParameters, HistoryPage, [HistoryContext, HistoryTextWrapper?]>;
45
+ export declare const historySearch: Operation<typeof historySearchParameters, SearchPage, [HistoryContext, HistoryTextWrapper?]>;
39
46
  export declare const historyReadParameters: Type.TObject<{
40
47
  offset_chars: Type.TOptional<Type.TInteger>;
41
48
  max_chars: Type.TOptional<Type.TInteger>;