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.
- package/README.md +6 -4
- package/dist/plugins/claude/src/helper.d.ts +2 -1
- package/dist/plugins/claude/src/helper.js +21 -24
- package/dist/plugins/claude/src/history.d.ts +3 -14
- package/dist/plugins/claude/src/history.js +2 -298
- package/dist/plugins/claude/src/text.d.ts +0 -1
- package/dist/plugins/claude/src/text.js +0 -1
- package/dist/plugins/codex/src/history.d.ts +3 -8
- package/dist/plugins/codex/src/history.js +2 -238
- package/dist/plugins/codex/src/hooks.js +1 -1
- package/dist/plugins/codex/src/identity.d.ts +1 -1
- package/dist/plugins/codex/src/identity.js +3 -3
- package/dist/plugins/codex/src/mcp.js +9 -8
- package/dist/plugins/codex/src/text.d.ts +1 -1
- package/dist/plugins/codex/src/text.js +2 -2
- package/dist/plugins/codex/src/transcript.d.ts +3 -39
- package/dist/plugins/codex/src/transcript.js +2 -313
- package/dist/plugins/dsh/engine.js +2 -2
- package/dist/plugins/dsh/history.d.ts +3 -0
- package/dist/plugins/dsh/history.js +15 -0
- package/dist/plugins/dsh/tools.js +12 -12
- package/dist/plugins/dsh/window.d.ts +1 -0
- package/dist/plugins/dsh/window.js +7 -3
- package/dist/plugins/pi/history-tools.d.ts +1 -1
- package/dist/plugins/pi/history-tools.js +9 -5
- package/dist/plugins/pi/history.d.ts +2 -3
- package/dist/plugins/pi/history.js +4 -147
- package/dist/plugins/pi/notes/tools.js +8 -6
- package/dist/plugins/pi/render.js +7 -4
- package/dist/plugins/pi/runtime.js +2 -2
- package/dist/plugins/pi/window.js +21 -7
- package/dist/src/boot/render.js +9 -11
- package/dist/src/boot/snapshot.d.ts +7 -7
- package/dist/src/boot/snapshot.js +17 -17
- package/dist/src/boot/text.d.ts +5 -3
- package/dist/src/boot/text.js +18 -10
- package/dist/src/dream/git.d.ts +2 -11
- package/dist/src/dream/git.js +6 -23
- package/dist/src/dream/lock.d.ts +2 -2
- package/dist/src/dream/lock.js +3 -3
- package/dist/src/history/claude.d.ts +16 -0
- package/dist/src/history/claude.js +336 -0
- package/dist/src/history/codex-transcript.d.ts +39 -0
- package/dist/src/history/codex-transcript.js +315 -0
- package/dist/src/history/codex.d.ts +8 -0
- package/dist/src/history/codex.js +238 -0
- package/dist/src/history/corpus.d.ts +35 -0
- package/dist/src/history/corpus.js +54 -0
- package/dist/src/history/history.d.ts +4 -8
- package/dist/src/history/history.js +3 -11
- package/dist/src/history/local.d.ts +17 -0
- package/dist/src/history/local.js +101 -0
- package/dist/src/history/pi.d.ts +36 -0
- package/dist/src/history/pi.js +202 -0
- package/dist/src/history/query.d.ts +15 -5
- package/dist/src/history/query.js +42 -13
- package/dist/src/index.d.ts +6 -3
- package/dist/src/index.js +6 -4
- package/dist/src/notes/address.d.ts +8 -8
- package/dist/src/notes/address.js +13 -13
- package/dist/src/notes/errors.d.ts +1 -1
- package/dist/src/notes/frontmatter.js +2 -2
- package/dist/src/notes/index.d.ts +1 -1
- package/dist/src/notes/index.js +1 -1
- package/dist/src/notes/paths.d.ts +6 -6
- package/dist/src/notes/paths.js +9 -9
- package/dist/src/notes/{project-home.d.ts → project-namespace.d.ts} +7 -7
- package/dist/src/notes/{project-home.js → project-namespace.js} +67 -25
- package/dist/src/notes/store.d.ts +4 -4
- package/dist/src/notes/store.js +55 -52
- package/dist/src/tools/dream.d.ts +21 -3
- package/dist/src/tools/dream.js +54 -16
- package/dist/src/tools/history.d.ts +7 -19
- package/dist/src/tools/history.js +80 -93
- package/dist/src/tools/notes-context.d.ts +10 -0
- package/dist/src/tools/notes-context.js +27 -0
- package/dist/src/tools/notes.d.ts +69 -20
- package/dist/src/tools/notes.js +40 -31
- package/dist/test/boot.integration.test.js +2 -3
- package/dist/test/claude-history.test.js +47 -34
- package/dist/test/claude-mod.test.js +96 -50
- package/dist/test/codex-history.test.js +4 -10
- package/dist/test/codex-plugin.test.js +50 -12
- package/dist/test/context-edit-budget.test.js +121 -0
- package/dist/test/dependencies.test.js +73 -6
- package/dist/test/dream-tools.test.js +153 -8
- package/dist/test/dsh.test.js +88 -19
- package/dist/test/helpers/dsh.d.ts +4 -1
- package/dist/test/helpers/dsh.js +20 -4
- package/dist/test/helpers/extension.d.ts +5 -1
- package/dist/test/helpers/extension.js +33 -2
- package/dist/test/helpers/history-corpus.d.ts +7 -0
- package/dist/test/helpers/history-corpus.js +26 -0
- package/dist/test/history-corpus.test.js +307 -0
- package/dist/test/history.integration.test.js +40 -48
- package/dist/test/host-neutral.test.js +20 -33
- package/dist/test/model-facing-text.test.js +14 -8
- package/dist/test/notes-cwd.test.d.ts +1 -0
- package/dist/test/notes-cwd.test.js +114 -0
- package/dist/test/notes-library.test.js +4 -4
- package/dist/test/notes-query-namespaces.test.d.ts +1 -0
- package/dist/test/{notes-query-homes.test.js → notes-query-namespaces.test.js} +13 -13
- package/dist/test/notes.integration.test.js +73 -24
- package/dist/test/notes.test.js +51 -21
- package/dist/test/pi-render.test.js +33 -1
- package/dist/test/project-namespace.test.d.ts +1 -0
- package/dist/test/project-namespace.test.js +324 -0
- package/docs/architecture.md +19 -12
- package/docs/claude-code-mod.md +7 -5
- package/docs/codex.md +6 -6
- package/docs/dsh.md +9 -9
- package/docs/history-sessions.md +52 -0
- package/docs/notes-library.md +9 -5
- package/docs/skills.md +3 -3
- package/docs/tool-results.md +14 -8
- package/package.json +4 -6
- package/playbook.md +6 -6
- package/plugins/claude/.claude-plugin/plugin.json +1 -1
- package/plugins/claude/dist/claude/helper.js +2164 -1341
- package/plugins/claude/hooks/register.ts +19 -11
- package/plugins/claude/playbook.md +6 -6
- package/plugins/claude/skills/memory/SKILL.md +9 -7
- package/plugins/claude/src/helper.ts +22 -25
- package/plugins/claude/src/history.ts +3 -257
- package/plugins/claude/src/text.ts +0 -1
- package/plugins/codex/README.md +1 -1
- package/plugins/codex/dist/codex/notesoup.js +1582 -969
- package/plugins/codex/src/history.ts +3 -193
- package/plugins/codex/src/hooks.ts +1 -1
- package/plugins/codex/src/identity.ts +3 -3
- package/plugins/codex/src/mcp.ts +9 -8
- package/plugins/codex/src/text.ts +2 -2
- package/plugins/codex/src/transcript.ts +3 -275
- package/plugins/dsh/engine.ts +2 -2
- package/plugins/dsh/history.ts +17 -0
- package/plugins/dsh/tools.ts +12 -12
- package/plugins/dsh/window.ts +8 -3
- package/plugins/paseo/OVERVIEW.md +4 -4
- package/plugins/paseo/README.md +1 -1
- package/plugins/paseo/client/brain-empty-card.tsx +3 -4
- package/plugins/paseo/client/markdown.tsx +159 -0
- package/plugins/paseo/client/notes-op-card.tsx +35 -34
- package/plugins/paseo/client/notes-op-transformer.ts +17 -68
- package/plugins/paseo/client/paper-card.tsx +8 -19
- package/plugins/paseo/client/paper-palette.ts +40 -0
- package/plugins/paseo/client/sticky-card.tsx +6 -4
- package/plugins/paseo/package.json +3 -0
- package/plugins/paseo/paseo-plugin.json +2 -2
- package/plugins/paseo/shared/notes-op.ts +13 -9
- package/plugins/paseo/test/notes-op.test.ts +52 -73
- package/plugins/paseo/test/paper-palette.test.ts +54 -0
- package/plugins/pi/history-tools.ts +11 -5
- package/plugins/pi/history.ts +8 -157
- package/plugins/pi/notes/tools.ts +8 -6
- package/plugins/pi/render.ts +6 -4
- package/plugins/pi/runtime.ts +2 -2
- package/plugins/pi/window.ts +22 -7
- package/skills/memory/SKILL.md +9 -7
- package/src/boot/render.ts +10 -13
- package/src/boot/snapshot.ts +20 -20
- package/src/boot/text.ts +18 -10
- package/src/dream/git.ts +7 -24
- package/src/dream/lock.ts +3 -3
- package/src/history/claude.ts +286 -0
- package/src/history/codex-transcript.ts +276 -0
- package/src/history/codex.ts +193 -0
- package/src/history/corpus.ts +69 -0
- package/src/history/history.ts +5 -12
- package/src/history/local.ts +93 -0
- package/src/history/pi.ts +199 -0
- package/src/history/query.ts +45 -15
- package/src/index.ts +8 -5
- package/src/notes/address.ts +13 -13
- package/src/notes/errors.ts +1 -1
- package/src/notes/frontmatter.ts +2 -2
- package/src/notes/index.ts +1 -1
- package/src/notes/paths.ts +9 -9
- package/src/notes/{project-home.ts → project-namespace.ts} +59 -28
- package/src/notes/store.ts +61 -58
- package/src/tools/dream.ts +63 -16
- package/src/tools/history.ts +71 -101
- package/src/tools/notes-context.ts +29 -0
- package/src/tools/notes.ts +39 -29
- package/dist/test/project-home.test.js +0 -134
- /package/dist/test/{notes-query-homes.test.d.ts → context-edit-budget.test.d.ts} +0 -0
- /package/dist/test/{project-home.test.d.ts → history-corpus.test.d.ts} +0 -0
|
@@ -30,14 +30,17 @@ function resolveTimeBounds(params) {
|
|
|
30
30
|
}
|
|
31
31
|
/** The params to merge into the previous call to continue toward older events. */
|
|
32
32
|
export const HistoryOlderSchema = Type.Object({
|
|
33
|
+
session: Type.Optional(Type.String()),
|
|
33
34
|
before_seq: Type.Integer({ minimum: 1 }),
|
|
34
35
|
}, { additionalProperties: false });
|
|
35
36
|
/** The params to merge into the previous call to continue toward newer events. */
|
|
36
37
|
export const HistoryNewerSchema = Type.Object({
|
|
38
|
+
session: Type.Optional(Type.String()),
|
|
37
39
|
after_seq: Type.Integer({ minimum: 1 }),
|
|
38
40
|
from: Type.Literal("oldest"),
|
|
39
41
|
}, { additionalProperties: false });
|
|
40
42
|
export const HistoryPageSchema = Type.Object({
|
|
43
|
+
notice: Type.Optional(Type.String()),
|
|
41
44
|
items: Type.Array(Type.Union([HistoryPageItemSchema, HistoryFoldedRowSchema])),
|
|
42
45
|
page_older: Type.Union([HistoryOlderSchema, Type.Null()]),
|
|
43
46
|
page_newer: Type.Union([HistoryNewerSchema, Type.Null()]),
|
|
@@ -60,7 +63,7 @@ function truncateHistoryItem(item, fits) {
|
|
|
60
63
|
return fits(withoutName) ? withoutName : shrinkContent(withoutName);
|
|
61
64
|
}
|
|
62
65
|
/** Summarize one already ordered gap; omitted tool names never change its exact count. */
|
|
63
|
-
function foldedRun(events) {
|
|
66
|
+
function foldedRun(events, session) {
|
|
64
67
|
if (events.length === 0)
|
|
65
68
|
return undefined;
|
|
66
69
|
const counts = new Map();
|
|
@@ -73,7 +76,7 @@ function foldedRun(events) {
|
|
|
73
76
|
const entries = [...counts].filter(([name]) => name.length <= MAX_FOLD_TOOL_NAME_CHARS).slice(0, MAX_FOLD_TOOL_NAMES);
|
|
74
77
|
// fromEntries preserves __proto__ as an ordinary key without mutating the prototype.
|
|
75
78
|
const tools = Object.fromEntries(entries);
|
|
76
|
-
return { folded: true, first_seq: events[0].seq, last_seq: events.at(-1).seq, count: events.length, tools };
|
|
79
|
+
return { ...(session === undefined ? {} : { session }), folded: true, first_seq: events[0].seq, last_seq: events.at(-1).seq, count: events.length, tools };
|
|
77
80
|
}
|
|
78
81
|
/** Filter and order once. Conversation candidates own the folded gap immediately before them. */
|
|
79
82
|
function prepareSelection(projection, params) {
|
|
@@ -91,48 +94,73 @@ function prepareSelection(projection, params) {
|
|
|
91
94
|
const matchOffset = params.query === undefined ? undefined : earliestMatchOffsetChars(eventDocument(event), params.query);
|
|
92
95
|
if (matchOffset !== undefined && matchOffset < 0)
|
|
93
96
|
continue;
|
|
94
|
-
candidates.push({ event, matchOffset, before: foldedRun(run) });
|
|
97
|
+
candidates.push({ event, ...(params.session === undefined ? {} : { session: params.session }), matchOffset, before: foldedRun(run, params.session) });
|
|
95
98
|
run = [];
|
|
96
99
|
}
|
|
97
|
-
return { candidates, tail: foldedRun(run) };
|
|
100
|
+
return { candidates, session: params.session, tail: foldedRun(run, params.session) };
|
|
98
101
|
}
|
|
99
102
|
/** Assemble only the admitted interval. Edge folds belong only to a page reaching that edge. */
|
|
100
103
|
function pageData(prepared, start, end, maxChars, preview) {
|
|
101
104
|
const { candidates, tail } = prepared;
|
|
105
|
+
const identity = prepared.session === undefined ? {} : { session: prepared.session };
|
|
102
106
|
const items = [];
|
|
103
107
|
for (let index = start; index < end; index++) {
|
|
104
108
|
const candidate = candidates[index];
|
|
105
109
|
if (candidate.before && (index > start || start === 0))
|
|
106
110
|
items.push(candidate.before);
|
|
107
|
-
items.push(preview ?? (candidate.preview ??= visibleItem(candidate.event, maxChars, candidate.matchOffset)));
|
|
111
|
+
items.push(preview ?? (candidate.preview ??= { ...visibleItem(candidate.event, maxChars, candidate.matchOffset), ...(candidate.session === undefined ? {} : { session: candidate.session }) }));
|
|
108
112
|
}
|
|
109
113
|
if (end === candidates.length && tail)
|
|
110
114
|
items.push(tail);
|
|
111
115
|
return {
|
|
112
116
|
items,
|
|
113
|
-
page_older: start > 0 && start < end ? { before_seq: candidates[start].event.seq } : null,
|
|
114
|
-
page_newer: end < candidates.length && start < end ? { after_seq: candidates[end - 1].event.seq, from: "oldest" } : null,
|
|
117
|
+
page_older: !prepared.multi && start > 0 && start < end ? { ...identity, before_seq: candidates[start].event.seq } : null,
|
|
118
|
+
page_newer: !prepared.multi && end < candidates.length && start < end ? { ...identity, after_seq: candidates[end - 1].event.seq, from: "oldest" } : null,
|
|
115
119
|
};
|
|
116
120
|
}
|
|
117
121
|
/**
|
|
118
122
|
* Resolve the time bounds once, then filter and fold against the same [sinceMs, untilMs) window.
|
|
119
123
|
* Grow the page in selection order; shorten the first preview only when no full row fits.
|
|
120
124
|
*/
|
|
121
|
-
|
|
125
|
+
function resolveSelection(params) {
|
|
122
126
|
const bounds = resolveTimeBounds(params);
|
|
123
127
|
if (!bounds.ok)
|
|
124
128
|
return bounds;
|
|
125
|
-
let queries;
|
|
126
129
|
try {
|
|
127
|
-
queries = searchQueries(params.query);
|
|
130
|
+
const queries = searchQueries(params.query);
|
|
131
|
+
return success({ ...params, ...bounds.data, query: queries.length ? queries : undefined });
|
|
128
132
|
}
|
|
129
133
|
catch (error) {
|
|
130
134
|
if (error instanceof InvalidQueryError)
|
|
131
135
|
return failure("invalid_query", error.message);
|
|
132
136
|
throw error;
|
|
133
137
|
}
|
|
134
|
-
|
|
135
|
-
|
|
138
|
+
}
|
|
139
|
+
export function selectPage(projection, params, fits, maxChars) {
|
|
140
|
+
const scoped = resolveSelection(params);
|
|
141
|
+
if (!scoped.ok)
|
|
142
|
+
return scoped;
|
|
143
|
+
return selectPrepared(prepareSelection(projection, scoped.data), scoped.data, fits, maxChars);
|
|
144
|
+
}
|
|
145
|
+
/** Validate before corpus discovery or I/O: per-session seqs cannot bound a multi-session search. */
|
|
146
|
+
export function corpusSelection(params) {
|
|
147
|
+
const scoped = resolveSelection(params);
|
|
148
|
+
if (!scoped.ok)
|
|
149
|
+
return scoped;
|
|
150
|
+
if (scoped.data.query === undefined)
|
|
151
|
+
return failure("missing_query", "Wildcard session search requires a non-empty `query`.");
|
|
152
|
+
if (params.before_seq !== undefined || params.after_seq !== undefined)
|
|
153
|
+
return failure("invalid_bounds", "`before_seq` and `after_seq` are per-session; omit them for wildcard session search.");
|
|
154
|
+
return scoped;
|
|
155
|
+
}
|
|
156
|
+
/** Merge events, never folds or per-session cursors. Equal timestamps have a stable identity tie-break. */
|
|
157
|
+
export function selectCorpusPage(sessions, scoped, fits, maxChars) {
|
|
158
|
+
const candidates = sessions.flatMap(({ session, projection }) => prepareSelection(projection, { ...scoped, session }).candidates);
|
|
159
|
+
const time = (event) => event.createdAt === undefined || Number.isNaN(Date.parse(event.createdAt)) ? -Infinity : Date.parse(event.createdAt);
|
|
160
|
+
candidates.sort((a, b) => (time(a.event) - time(b.event) || a.session.localeCompare(b.session) || a.event.seq - b.event.seq));
|
|
161
|
+
return selectPrepared({ candidates, multi: true }, scoped, fits, maxChars);
|
|
162
|
+
}
|
|
163
|
+
function selectPrepared(prepared, scoped, fits, maxChars) {
|
|
136
164
|
const { candidates } = prepared;
|
|
137
165
|
// Grow a contiguous interval from the requested end; even a byte-limited newest page stays ascending.
|
|
138
166
|
const newest = scoped.from !== "oldest";
|
|
@@ -157,7 +185,8 @@ export function selectPage(projection, params, fits, maxChars) {
|
|
|
157
185
|
}
|
|
158
186
|
const page = pageData(prepared, start, end, maxChars);
|
|
159
187
|
if (!fits(page)) {
|
|
160
|
-
|
|
188
|
+
const narrow = prepared.multi ? "narrow the session pattern, query, roles or `since`/`until`, or read one session/seq with `history_read`" : "narrow with `before_seq`/`after_seq` or `since`/`until`, pass `roles` to skip folding, or `history_read` one seq";
|
|
189
|
+
return failure("page_too_large", `Even trimmed to their shortest, these ${page.items.length} rows${prepared.multi ? "" : " and their folded runs"} fill the ${TOOL_OUTPUT_LIMIT} a call can carry; ${narrow}.`);
|
|
161
190
|
}
|
|
162
191
|
return success(page);
|
|
163
192
|
}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
* Host-neutral core entry.
|
|
3
3
|
*
|
|
4
4
|
* Everything under `src/` is independent of any host SDK: notes, boot, history, budget and the
|
|
5
|
-
* shared operations
|
|
5
|
+
* shared operations use explicit facts, not live Pi, Claude Code or dsh services. History's
|
|
6
|
+
* read-only wire decoders understand persisted formats without importing those hosts. Each plugin under `plugins/`
|
|
6
7
|
* composes these domains into that host's registration and owns that host's text, lifecycle and
|
|
7
8
|
* SDK types. Nothing here imports a plugin.
|
|
8
9
|
*
|
|
@@ -13,15 +14,17 @@
|
|
|
13
14
|
export { createNotesStore, noteIdentity, projectKey, slugify, NoteError } from "./notes/index.js";
|
|
14
15
|
export type { NoteEditResult, NoteMatch, NoteMeta, NoteReadResult, NoteRenameResult, NoteRow, NoteSearchRow, NotesIdentity, NotesQuery, NotesStore, NoteWriteResult, Origin, Scope, } from "./notes/index.js";
|
|
15
16
|
export { loadNotesSnapshot, unavailableNotesSnapshot } from "./boot/snapshot.js";
|
|
16
|
-
export type {
|
|
17
|
+
export type { NotesNamespace, NotesSnapshot } from "./boot/snapshot.js";
|
|
17
18
|
export { renderBootBlock } from "./boot/render.js";
|
|
18
19
|
export type { BootRenderData, BootWindowTree } from "./boot/render.js";
|
|
19
20
|
export { DEFAULT_BOOT_TOOL_NAMES, renderProtocolBlock } from "./boot/text.js";
|
|
20
21
|
export type { BootToolNames } from "./boot/text.js";
|
|
21
22
|
export { notesList, notesRead, notesSearch, notesUpdate, notesWrite } from "./tools/notes.js";
|
|
22
|
-
export {
|
|
23
|
+
export { notesIdentityForCall, notesToolContext, type NotesToolContext } from "./tools/notes-context.js";
|
|
24
|
+
export { historyList, historyRead } from "./tools/history.js";
|
|
23
25
|
export { projectHistory } from "./history/history.js";
|
|
24
26
|
export type { HistoryProjection } from "./history/history.js";
|
|
27
|
+
export type { HistoryContext, HistoryCorpus, HistoryHarness, HistorySession, HistorySessionData } from "./history/corpus.js";
|
|
25
28
|
export type { Operation, OperationError, Outcome, Renderer, TextWindow } from "./tools/result.js";
|
|
26
29
|
export { deriveThresholds, remainingBudget } from "./budget/policy.js";
|
|
27
30
|
export type { ResolvedThresholds } from "./budget/policy.js";
|
package/dist/src/index.js
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
* Host-neutral core entry.
|
|
3
3
|
*
|
|
4
4
|
* Everything under `src/` is independent of any host SDK: notes, boot, history, budget and the
|
|
5
|
-
* shared operations
|
|
5
|
+
* shared operations use explicit facts, not live Pi, Claude Code or dsh services. History's
|
|
6
|
+
* read-only wire decoders understand persisted formats without importing those hosts. Each plugin under `plugins/`
|
|
6
7
|
* composes these domains into that host's registration and owns that host's text, lifecycle and
|
|
7
8
|
* SDK types. Nothing here imports a plugin.
|
|
8
9
|
*
|
|
@@ -12,14 +13,15 @@
|
|
|
12
13
|
*/
|
|
13
14
|
// Notes: the standalone filesystem library, addressed by an explicit identity.
|
|
14
15
|
export { createNotesStore, noteIdentity, projectKey, slugify, NoteError } from "./notes/index.js";
|
|
15
|
-
// Boot: five
|
|
16
|
+
// Boot: five notebooks captured once, rendered from explicit logical tool names.
|
|
16
17
|
export { loadNotesSnapshot, unavailableNotesSnapshot } from "./boot/snapshot.js";
|
|
17
18
|
export { renderBootBlock } from "./boot/render.js";
|
|
18
19
|
export { DEFAULT_BOOT_TOOL_NAMES, renderProtocolBlock } from "./boot/text.js";
|
|
19
20
|
// Operations: the schemas and typed outcomes a host registers as its own tools, over a
|
|
20
|
-
// host-supplied notes
|
|
21
|
+
// host-supplied notes tool context or decoded history projection/lazy corpus context.
|
|
21
22
|
export { notesList, notesRead, notesSearch, notesUpdate, notesWrite } from "./tools/notes.js";
|
|
22
|
-
export {
|
|
23
|
+
export { notesIdentityForCall, notesToolContext } from "./tools/notes-context.js";
|
|
24
|
+
export { historyList, historyRead } from "./tools/history.js";
|
|
23
25
|
export { projectHistory } from "./history/history.js";
|
|
24
26
|
// Budget: pure thresholds and the approved reset prose.
|
|
25
27
|
export { deriveThresholds, remainingBudget } from "./budget/policy.js";
|
|
@@ -5,11 +5,11 @@ export type NoteAddress = {
|
|
|
5
5
|
path: string;
|
|
6
6
|
who?: string;
|
|
7
7
|
};
|
|
8
|
-
export declare const ADDRESS_FORMS = "Use <path> for this session, or @project/, @human/, @self/, or @model/ followed by a path; @projects/<name>/<path> and @sessions/<id>/<path> read named
|
|
9
|
-
/** The one
|
|
10
|
-
export declare const
|
|
8
|
+
export declare const ADDRESS_FORMS = "Use <path> for this session, or @project/, @human/, @self/, or @model/ followed by a path; @projects/<name>/<path> and @sessions/<id>/<path> read named notebooks.";
|
|
9
|
+
/** The one namespace-head vocabulary: the scope each public `@head` names, and the directory family a head with `dir` lists. */
|
|
10
|
+
export declare const NAMESPACE_HEADS: ReadonlyMap<string, {
|
|
11
11
|
readonly scope: Scope;
|
|
12
|
-
readonly
|
|
12
|
+
readonly dir?: "sessions" | "project" | "agents" | "models";
|
|
13
13
|
}>;
|
|
14
14
|
/**
|
|
15
15
|
* Minimal glob over virtual note paths: `*` matches any run within a segment (never
|
|
@@ -22,15 +22,15 @@ export declare function globToRegExp(pattern: string): RegExp;
|
|
|
22
22
|
/** Glob patterns are not virtual paths (`*` is legal), so they get their own guard. */
|
|
23
23
|
export declare function assertGlobPattern(value: unknown): string | undefined;
|
|
24
24
|
/**
|
|
25
|
-
* Decode one public note address into its physical
|
|
25
|
+
* Decode one public note address into its physical namespace and virtual path. @self and @model
|
|
26
26
|
* are relative; projects/agents/models name a canonical slug, sessions a directory component.
|
|
27
27
|
*/
|
|
28
28
|
export declare function assertAddress(value: unknown): NoteAddress;
|
|
29
29
|
/** Render a virtual path in its one unambiguous address form, used to match patterns. */
|
|
30
30
|
export declare function canonicalAddressFor(identity: NotesIdentity, scope: Scope, path: string, who?: string): string;
|
|
31
31
|
/**
|
|
32
|
-
* Render the address a caller sees. The current agent and model
|
|
33
|
-
* @model/. Current session and project
|
|
34
|
-
* named session/project
|
|
32
|
+
* Render the address a caller sees. The current agent and model notebooks read as @self/ and
|
|
33
|
+
* @model/. Current session and project notebooks retain bare paths and @project/; explicitly
|
|
34
|
+
* named session/project notebooks keep their read-only addresses, even for the current identity.
|
|
35
35
|
*/
|
|
36
36
|
export declare function addressFor(identity: NotesIdentity, scope: Scope, path: string, who?: string): string;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { NoteError, shown } from "./errors.js";
|
|
2
2
|
import { assertVirtualPath, isSessionId, SLUG_PATTERN } from "./paths.js";
|
|
3
|
-
export const ADDRESS_FORMS = "Use <path> for this session, or @project/, @human/, @self/, or @model/ followed by a path; @projects/<name>/<path> and @sessions/<id>/<path> read named
|
|
4
|
-
/** The one
|
|
5
|
-
export const
|
|
3
|
+
export const ADDRESS_FORMS = "Use <path> for this session, or @project/, @human/, @self/, or @model/ followed by a path; @projects/<name>/<path> and @sessions/<id>/<path> read named notebooks.";
|
|
4
|
+
/** The one namespace-head vocabulary: the scope each public `@head` names, and the directory family a head with `dir` lists. */
|
|
5
|
+
export const NAMESPACE_HEADS = new Map([
|
|
6
6
|
["project", { scope: "project" }],
|
|
7
7
|
["human", { scope: "human" }],
|
|
8
8
|
["self", { scope: "agent" }],
|
|
9
9
|
["model", { scope: "model" }],
|
|
10
|
-
["sessions", { scope: "session",
|
|
11
|
-
["projects", { scope: "project",
|
|
12
|
-
["agents", { scope: "agent",
|
|
13
|
-
["models", { scope: "model",
|
|
10
|
+
["sessions", { scope: "session", dir: "sessions" }],
|
|
11
|
+
["projects", { scope: "project", dir: "project" }],
|
|
12
|
+
["agents", { scope: "agent", dir: "agents" }],
|
|
13
|
+
["models", { scope: "model", dir: "models" }],
|
|
14
14
|
]);
|
|
15
15
|
/**
|
|
16
16
|
* Minimal glob over virtual note paths: `*` matches any run within a segment (never
|
|
@@ -53,7 +53,7 @@ export function assertGlobPattern(value) {
|
|
|
53
53
|
return value;
|
|
54
54
|
}
|
|
55
55
|
/**
|
|
56
|
-
* Decode one public note address into its physical
|
|
56
|
+
* Decode one public note address into its physical namespace and virtual path. @self and @model
|
|
57
57
|
* are relative; projects/agents/models name a canonical slug, sessions a directory component.
|
|
58
58
|
*/
|
|
59
59
|
export function assertAddress(value) {
|
|
@@ -64,11 +64,11 @@ export function assertAddress(value) {
|
|
|
64
64
|
let who;
|
|
65
65
|
if (value.startsWith("@")) {
|
|
66
66
|
const [rawHead, ...tail] = value.slice(1).split("/");
|
|
67
|
-
const head =
|
|
67
|
+
const head = NAMESPACE_HEADS.get(rawHead);
|
|
68
68
|
if (head === undefined)
|
|
69
69
|
throw new NoteError("invalid_address", `${shown(value)} isn't a note address. ${ADDRESS_FORMS}`);
|
|
70
70
|
scope = head.scope;
|
|
71
|
-
if (head.
|
|
71
|
+
if (head.dir === undefined)
|
|
72
72
|
path = tail.join("/");
|
|
73
73
|
else {
|
|
74
74
|
who = tail[0] ?? "";
|
|
@@ -97,9 +97,9 @@ export function canonicalAddressFor(identity, scope, path, who) {
|
|
|
97
97
|
return `@models/${who ?? identity.model}/${path}`;
|
|
98
98
|
}
|
|
99
99
|
/**
|
|
100
|
-
* Render the address a caller sees. The current agent and model
|
|
101
|
-
* @model/. Current session and project
|
|
102
|
-
* named session/project
|
|
100
|
+
* Render the address a caller sees. The current agent and model notebooks read as @self/ and
|
|
101
|
+
* @model/. Current session and project notebooks retain bare paths and @project/; explicitly
|
|
102
|
+
* named session/project notebooks keep their read-only addresses, even for the current identity.
|
|
103
103
|
*/
|
|
104
104
|
export function addressFor(identity, scope, path, who) {
|
|
105
105
|
if (scope === "session" && who === undefined)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type NoteErrorCode = "not_found" | "already_exists" | "ambiguous_edit" | "no_match" | "invalid_edit" | "nothing_to_do" | "not_crumpled" | "too_large" | "invalid_scope" | "invalid_origin" | "invalid_address" | "invalid_pattern" | "invalid_query" | "invalid_offset" | "io_error" | "internal_error";
|
|
1
|
+
export type NoteErrorCode = "not_found" | "already_exists" | "ambiguous_edit" | "no_match" | "invalid_edit" | "nothing_to_do" | "not_crumpled" | "too_large" | "invalid_scope" | "invalid_origin" | "invalid_address" | "invalid_pattern" | "invalid_query" | "invalid_offset" | "invalid_cwd" | "io_error" | "internal_error";
|
|
2
2
|
/** Typed store refusal. Edit locations are exposed in camelCase. */
|
|
3
3
|
export declare class NoteError extends Error {
|
|
4
4
|
readonly code: NoteErrorCode;
|
|
@@ -98,7 +98,7 @@ function parseFrontmatter(raw) {
|
|
|
98
98
|
export function parseNote(raw, now = Date.now()) {
|
|
99
99
|
const { fields, body } = parseFrontmatter(raw);
|
|
100
100
|
const meta = { ...fields };
|
|
101
|
-
// scope is a legacy on-disk field: store callers derive it from the file's
|
|
101
|
+
// scope is a legacy on-disk field: store callers derive it from the file's notebook and
|
|
102
102
|
// overwrite it after parsing, so an absent or outdated value just falls back.
|
|
103
103
|
meta.scope = isScope(meta.scope) ? meta.scope : "session";
|
|
104
104
|
meta.origin = isOrigin(meta.origin) ? meta.origin : "self";
|
|
@@ -143,7 +143,7 @@ export function serializeNote(meta, body) {
|
|
|
143
143
|
lines.push(`${key}: ${yamlScalar(value)}`);
|
|
144
144
|
}
|
|
145
145
|
for (const key of Object.keys(meta)) {
|
|
146
|
-
// scope is a legacy on-disk field. Store callers derive it from the
|
|
146
|
+
// scope is a legacy on-disk field. Store callers derive it from the notebook's location,
|
|
147
147
|
// but serialization intentionally drops it on the next write.
|
|
148
148
|
if (key === "scope" || KNOWN_KEYS.includes(key))
|
|
149
149
|
continue;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { createNotesStore, noteIdentity } from "./store.js";
|
|
2
2
|
export { NoteError, type NoteErrorCode } from "./errors.js";
|
|
3
|
-
export { projectKey } from "./project-
|
|
3
|
+
export { projectKey } from "./project-namespace.js";
|
|
4
4
|
export { slugify } from "./paths.js";
|
|
5
5
|
export { snapshotNotesIdentity, type NotesIdentity } from "./identity.js";
|
|
6
6
|
export { isFilesystemError } from "./fs-error.js";
|
package/dist/src/notes/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { createNotesStore, noteIdentity } from "./store.js";
|
|
2
2
|
export { NoteError } from "./errors.js";
|
|
3
|
-
export { projectKey } from "./project-
|
|
3
|
+
export { projectKey } from "./project-namespace.js";
|
|
4
4
|
export { slugify } from "./paths.js";
|
|
5
5
|
export { snapshotNotesIdentity } from "./identity.js";
|
|
6
6
|
export { isFilesystemError } from "./fs-error.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { NotesIdentity } from "./identity.js";
|
|
2
2
|
export type Scope = "session" | "project" | "human" | "agent" | "model";
|
|
3
|
-
/** The one legal
|
|
3
|
+
/** The one legal namespace-name shape: lowercase [a-z0-9-] runs separated by single dashes. */
|
|
4
4
|
export declare const SLUG_PATTERN: RegExp;
|
|
5
5
|
/** Session identities use the same single-directory-component grammar as NotesIdentity, not slugs. */
|
|
6
6
|
export declare function isSessionId(value: string): boolean;
|
|
@@ -9,15 +9,15 @@ export declare function slugify(value: string): string;
|
|
|
9
9
|
/**
|
|
10
10
|
* The one virtual-path grammar: a relative, `/`-separated path with no empty, `.` or `..`
|
|
11
11
|
* segment. Both the address decoder and the physical-path builder enforce it here, so a
|
|
12
|
-
* caller that reaches a path without going through an address still cannot escape a
|
|
12
|
+
* caller that reaches a path without going through an address still cannot escape a namespace.
|
|
13
13
|
*/
|
|
14
14
|
export declare function assertVirtualPath(value: unknown): string;
|
|
15
|
-
/** Absolute directory holding the per-session note
|
|
16
|
-
export declare function
|
|
15
|
+
/** Absolute directory holding the per-session note namespaces. */
|
|
16
|
+
export declare function sessionNamespacesRoot(home: string): string;
|
|
17
17
|
/** Absolute directory holding one scope's notes. The identity's home is already resolved. */
|
|
18
18
|
export declare function scopeDir(scope: Scope, identity: NotesIdentity, who?: string): string;
|
|
19
|
-
/** Every addressable
|
|
20
|
-
export declare function namespaceSlugs(
|
|
19
|
+
/** Every addressable directory of a namespace family; sessions keep their original identity spelling. */
|
|
20
|
+
export declare function namespaceSlugs(family: "sessions" | "project" | "agents" | "models", home: string): Promise<string[]>;
|
|
21
21
|
/**
|
|
22
22
|
* Notes are markdown files: a virtual path without an `.md` suffix gains one, an explicit
|
|
23
23
|
* `.md` is kept as-is, so `a/b` and `a/b.md` name the same physical file.
|
package/dist/src/notes/paths.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { readdir } from "node:fs/promises";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { NoteError, shown } from "./errors.js";
|
|
4
|
-
/** The one legal
|
|
4
|
+
/** The one legal namespace-name shape: lowercase [a-z0-9-] runs separated by single dashes. */
|
|
5
5
|
export const SLUG_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
6
6
|
/** Session identities use the same single-directory-component grammar as NotesIdentity, not slugs. */
|
|
7
7
|
export function isSessionId(value) {
|
|
@@ -15,7 +15,7 @@ export function slugify(value) {
|
|
|
15
15
|
/**
|
|
16
16
|
* The one virtual-path grammar: a relative, `/`-separated path with no empty, `.` or `..`
|
|
17
17
|
* segment. Both the address decoder and the physical-path builder enforce it here, so a
|
|
18
|
-
* caller that reaches a path without going through an address still cannot escape a
|
|
18
|
+
* caller that reaches a path without going through an address still cannot escape a namespace.
|
|
19
19
|
*/
|
|
20
20
|
export function assertVirtualPath(value) {
|
|
21
21
|
if (typeof value !== "string" || value.length === 0)
|
|
@@ -27,8 +27,8 @@ export function assertVirtualPath(value) {
|
|
|
27
27
|
throw new NoteError("invalid_address", `${shown(value)}: a note path can't have empty, ".", or ".." folder names.`);
|
|
28
28
|
return value;
|
|
29
29
|
}
|
|
30
|
-
/** Absolute directory holding the per-session note
|
|
31
|
-
export function
|
|
30
|
+
/** Absolute directory holding the per-session note namespaces. */
|
|
31
|
+
export function sessionNamespacesRoot(home) {
|
|
32
32
|
return join(home, "pi", "session");
|
|
33
33
|
}
|
|
34
34
|
/** Absolute directory holding one scope's notes. The identity's home is already resolved. */
|
|
@@ -45,14 +45,14 @@ export function scopeDir(scope, identity, who) {
|
|
|
45
45
|
return join(identity.home, "agents", who ?? identity.agent);
|
|
46
46
|
if (scope === "model")
|
|
47
47
|
return join(identity.home, "models", who ?? identity.model);
|
|
48
|
-
return join(
|
|
48
|
+
return join(sessionNamespacesRoot(identity.home), who ?? identity.sessionId);
|
|
49
49
|
}
|
|
50
|
-
/** Every addressable
|
|
51
|
-
export async function namespaceSlugs(
|
|
52
|
-
const root =
|
|
50
|
+
/** Every addressable directory of a namespace family; sessions keep their original identity spelling. */
|
|
51
|
+
export async function namespaceSlugs(family, home) {
|
|
52
|
+
const root = family === "sessions" ? sessionNamespacesRoot(home) : join(home, family);
|
|
53
53
|
try {
|
|
54
54
|
return (await readdir(root, { withFileTypes: true }))
|
|
55
|
-
.filter((entry) => entry.isDirectory() && (
|
|
55
|
+
.filter((entry) => entry.isDirectory() && (family === "sessions" ? isSessionId(entry.name) : SLUG_PATTERN.test(entry.name)))
|
|
56
56
|
.map((entry) => entry.name)
|
|
57
57
|
.sort();
|
|
58
58
|
}
|
|
@@ -2,16 +2,16 @@ export type ProjectMarker = {
|
|
|
2
2
|
id: string;
|
|
3
3
|
path: string;
|
|
4
4
|
};
|
|
5
|
-
export type
|
|
5
|
+
export type ProjectNamespace = ProjectMarker & {
|
|
6
6
|
name: string;
|
|
7
7
|
dir: string;
|
|
8
8
|
};
|
|
9
9
|
/** Normalize the small set of Git remote spellings used by ordinary repositories. */
|
|
10
10
|
export declare function normalizeRemote(value: string): string;
|
|
11
|
-
/** Read marked project
|
|
12
|
-
export declare function
|
|
13
|
-
/** Resolve and claim the readable
|
|
14
|
-
export declare function
|
|
11
|
+
/** Read marked project notebooks. Unmarked legacy directories are deliberately omitted. */
|
|
12
|
+
export declare function projectNamespaces(home: string): ProjectNamespace[];
|
|
13
|
+
/** Resolve and claim the readable notebook for one repository identity. */
|
|
14
|
+
export declare function resolveProjectNamespace(cwd: string, home: string): ProjectNamespace;
|
|
15
15
|
export type ProjectReceipt = {
|
|
16
16
|
project_root?: string;
|
|
17
17
|
project_siblings?: Array<{
|
|
@@ -19,7 +19,7 @@ export type ProjectReceipt = {
|
|
|
19
19
|
path: string;
|
|
20
20
|
}>;
|
|
21
21
|
};
|
|
22
|
-
/** Display-only context for an explicitly named project
|
|
22
|
+
/** Display-only context for an explicitly named project notebook. */
|
|
23
23
|
export declare function projectReceipt(home: string, name: string): ProjectReceipt;
|
|
24
|
-
/** Names a project
|
|
24
|
+
/** Names a project notebook, claiming it when the notes store has not seen this identity. */
|
|
25
25
|
export declare function projectKey(cwd: string, home: string): string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
|
-
import { existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, renameSync, rmdirSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { basename, dirname, join, resolve, sep } from "node:path";
|
|
4
4
|
import { slugify } from "./paths.js";
|
|
5
5
|
function errno(error) {
|
|
@@ -94,19 +94,19 @@ function readMarker(dir) {
|
|
|
94
94
|
}
|
|
95
95
|
try {
|
|
96
96
|
const value = JSON.parse(raw);
|
|
97
|
-
if (typeof value.id !== "string" || value.id.length === 0 || typeof value.path !== "string" || value.path.length === 0)
|
|
98
|
-
|
|
97
|
+
if (!value || typeof value.id !== "string" || value.id.length === 0 || typeof value.path !== "string" || value.path.length === 0)
|
|
98
|
+
throw new Error("Expected non-empty id and path");
|
|
99
99
|
return { name: basename(dir), dir, id: value.id, path: value.path };
|
|
100
100
|
}
|
|
101
|
-
catch {
|
|
102
|
-
|
|
101
|
+
catch (cause) {
|
|
102
|
+
throw new Error(`Invalid project marker at ${join(dir, ".project")}`, { cause });
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
function projectRoot(home) {
|
|
106
106
|
return join(home, "project");
|
|
107
107
|
}
|
|
108
|
-
/** Read marked project
|
|
109
|
-
export function
|
|
108
|
+
/** Read marked project notebooks. Unmarked legacy directories are deliberately omitted. */
|
|
109
|
+
export function projectNamespaces(home) {
|
|
110
110
|
const root = projectRoot(home);
|
|
111
111
|
let entries;
|
|
112
112
|
try {
|
|
@@ -119,8 +119,8 @@ export function projectHomes(home) {
|
|
|
119
119
|
}
|
|
120
120
|
return entries.filter(entry => entry.isDirectory()).map(entry => readMarker(join(root, entry.name))).filter((entry) => entry !== undefined).sort((a, b) => a.name.localeCompare(b.name));
|
|
121
121
|
}
|
|
122
|
-
function updateMarker(
|
|
123
|
-
const markerPath = join(
|
|
122
|
+
function updateMarker(namespace, marker) {
|
|
123
|
+
const markerPath = join(namespace.dir, ".project");
|
|
124
124
|
const temp = `${markerPath}.${process.pid}.${randomUUID()}.tmp`;
|
|
125
125
|
try {
|
|
126
126
|
writeFileSync(temp, JSON.stringify(marker));
|
|
@@ -133,19 +133,55 @@ function updateMarker(home, marker) {
|
|
|
133
133
|
catch { /* Preserve the marker update failure. */ }
|
|
134
134
|
throw error;
|
|
135
135
|
}
|
|
136
|
-
return { ...
|
|
136
|
+
return { ...namespace, ...marker };
|
|
137
|
+
}
|
|
138
|
+
const claimSleep = new Int32Array(new SharedArrayBuffer(4));
|
|
139
|
+
function awaitClaim(path, attempt) {
|
|
140
|
+
const deadline = performance.now() + 5_000;
|
|
141
|
+
for (;;) {
|
|
142
|
+
const result = attempt();
|
|
143
|
+
if (result !== undefined)
|
|
144
|
+
return result;
|
|
145
|
+
const remaining = deadline - performance.now();
|
|
146
|
+
if (remaining <= 0)
|
|
147
|
+
throw new Error(`Timed out waiting for project claim at ${path}`);
|
|
148
|
+
Atomics.wait(claimSleep, 0, 0, Math.min(10, remaining));
|
|
149
|
+
}
|
|
137
150
|
}
|
|
138
|
-
/** Resolve and claim the readable
|
|
139
|
-
export function
|
|
151
|
+
/** Resolve and claim the readable notebook for one repository identity. */
|
|
152
|
+
export function resolveProjectNamespace(cwd, home) {
|
|
153
|
+
mkdirSync(projectRoot(home), { recursive: true });
|
|
154
|
+
// Serialize the scan as well as publication: an unmarked directory seen under
|
|
155
|
+
// this lock is legacy, not another resolver between mkdir and marker write.
|
|
156
|
+
const lock = join(home, ".project-claim");
|
|
157
|
+
awaitClaim(lock, () => {
|
|
158
|
+
try {
|
|
159
|
+
mkdirSync(lock);
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
162
|
+
catch (error) {
|
|
163
|
+
if (errno(error) === "EEXIST")
|
|
164
|
+
return undefined;
|
|
165
|
+
throw error;
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
try {
|
|
169
|
+
return claimProjectNamespace(cwd, home);
|
|
170
|
+
}
|
|
171
|
+
finally {
|
|
172
|
+
rmdirSync(lock);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
function claimProjectNamespace(cwd, home) {
|
|
140
176
|
const root = canonicalRoot(cwd);
|
|
141
177
|
const remote = originRemote(root);
|
|
142
178
|
const id = remote ?? root;
|
|
143
179
|
const markerRoot = projectRoot(home);
|
|
144
180
|
mkdirSync(markerRoot, { recursive: true });
|
|
145
|
-
const
|
|
146
|
-
let found =
|
|
181
|
+
const namespaces = projectNamespaces(home);
|
|
182
|
+
let found = namespaces.find(candidate => candidate.id === id);
|
|
147
183
|
if (!found && remote) {
|
|
148
|
-
found =
|
|
184
|
+
found = namespaces.find(candidate => candidate.id === root);
|
|
149
185
|
if (found)
|
|
150
186
|
found = updateMarker(found, { id: remote, path: root });
|
|
151
187
|
}
|
|
@@ -155,7 +191,7 @@ export function resolveProjectHome(cwd, home) {
|
|
|
155
191
|
return found;
|
|
156
192
|
}
|
|
157
193
|
const base = slugify(basename(root));
|
|
158
|
-
//
|
|
194
|
+
// The claim lock makes this a stable snapshot of legacy, unmarked names.
|
|
159
195
|
const taken = new Set(readdirSync(markerRoot));
|
|
160
196
|
for (let suffix = 0;; suffix++) {
|
|
161
197
|
const name = suffix === 0 ? base : `${base}-${suffix}`;
|
|
@@ -163,15 +199,21 @@ export function resolveProjectHome(cwd, home) {
|
|
|
163
199
|
continue;
|
|
164
200
|
const dir = join(markerRoot, name);
|
|
165
201
|
try {
|
|
166
|
-
mkdirSync(dir
|
|
167
|
-
writeFileSync(join(dir, ".project"), JSON.stringify({ id, path: root }), { flag: "wx" });
|
|
168
|
-
return { name, dir, id, path: root };
|
|
202
|
+
mkdirSync(dir);
|
|
169
203
|
}
|
|
170
204
|
catch (error) {
|
|
171
|
-
if (errno(error)
|
|
205
|
+
if (errno(error) !== "EEXIST")
|
|
206
|
+
throw error;
|
|
207
|
+
// A writer outside this protocol may have won after the snapshot.
|
|
208
|
+
// Never mistake its incomplete publication for a different identity.
|
|
209
|
+
let winner = awaitClaim(join(dir, ".project"), () => readMarker(dir));
|
|
210
|
+
if (winner.id !== id && !(remote && winner.id === root))
|
|
172
211
|
continue;
|
|
173
|
-
|
|
212
|
+
if (winner.id !== id || winner.path !== root)
|
|
213
|
+
winner = updateMarker(winner, { id, path: root });
|
|
214
|
+
return winner;
|
|
174
215
|
}
|
|
216
|
+
return updateMarker({ name, dir, id, path: root }, { id, path: root });
|
|
175
217
|
}
|
|
176
218
|
}
|
|
177
219
|
/** Existing root discovery, including linked worktrees, without invoking Git. */
|
|
@@ -213,19 +255,19 @@ function repositoryRoot(dir) {
|
|
|
213
255
|
const common = parts.slice(0, worktrees).join(sep);
|
|
214
256
|
return basename(common) === ".git" ? dirname(common) : dir;
|
|
215
257
|
}
|
|
216
|
-
/** Display-only context for an explicitly named project
|
|
258
|
+
/** Display-only context for an explicitly named project notebook. */
|
|
217
259
|
export function projectReceipt(home, name) {
|
|
218
260
|
const project = readMarker(join(projectRoot(home), name));
|
|
219
261
|
if (!project)
|
|
220
262
|
return {};
|
|
221
263
|
const base = slugify(basename(project.path));
|
|
222
|
-
const siblings =
|
|
264
|
+
const siblings = projectNamespaces(home).filter(candidate => candidate.name !== name && slugify(basename(candidate.path)) === base);
|
|
223
265
|
return {
|
|
224
266
|
project_root: project.path,
|
|
225
267
|
...(siblings.length === 0 ? {} : { project_siblings: siblings.map(({ name, path }) => ({ name, path })) }),
|
|
226
268
|
};
|
|
227
269
|
}
|
|
228
|
-
/** Names a project
|
|
270
|
+
/** Names a project notebook, claiming it when the notes store has not seen this identity. */
|
|
229
271
|
export function projectKey(cwd, home) {
|
|
230
|
-
return
|
|
272
|
+
return resolveProjectNamespace(cwd, home).name;
|
|
231
273
|
}
|