@dreamlake/dreamlake-cli 0.104.7 → 0.105.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.
- package/dist/api/content.d.ts +4 -3
- package/dist/api/index.d.ts +33 -23
- package/dist/api/index.js +25 -16
- package/dist/api/memo-character-plan.d.ts +2 -0
- package/dist/api/memo-character-plan.js +2 -0
- package/dist/api/memo-editing.d.ts +2 -0
- package/dist/api/memo-editing.js +2 -0
- package/dist/api/memo-edits.d.ts +63 -0
- package/dist/api/memo-edits.js +206 -0
- package/dist/api/memo-events.d.ts +44 -0
- package/dist/api/memo-events.js +65 -0
- package/dist/api/memo-facade.d.ts +294 -0
- package/dist/api/memo-facade.js +382 -0
- package/dist/api/memo-files.d.ts +111 -0
- package/dist/api/memo-files.js +110 -0
- package/dist/api/memo-html-read.d.ts +2 -0
- package/dist/api/memo-html-read.js +2 -0
- package/dist/api/memo-html.d.ts +2 -0
- package/dist/api/memo-html.js +2 -0
- package/dist/api/memo-linger.d.ts +85 -0
- package/dist/api/memo-linger.js +271 -0
- package/dist/api/memo-presence.d.ts +109 -0
- package/dist/api/memo-presence.js +75 -0
- package/dist/api/memo-reading.d.ts +55 -0
- package/dist/api/memo-reading.js +43 -0
- package/dist/api/memo-toc.d.ts +2 -0
- package/dist/api/memo-toc.js +2 -0
- package/dist/api/memo-write.d.ts +119 -0
- package/dist/api/memo-write.js +221 -0
- package/dist/api/memos.d.ts +344 -0
- package/dist/api/memos.js +231 -0
- package/dist/api/note-character-plan.d.ts +2 -2
- package/dist/api/note-character-plan.js +2 -2
- package/dist/api/note-editing.d.ts +2 -2
- package/dist/api/note-editing.js +2 -2
- package/dist/api/note-edits.d.ts +2 -59
- package/dist/api/note-edits.js +2 -205
- package/dist/api/note-events.d.ts +2 -41
- package/dist/api/note-events.js +2 -64
- package/dist/api/note-facade.d.ts +2 -268
- package/dist/api/note-facade.js +2 -376
- package/dist/api/note-files.d.ts +2 -102
- package/dist/api/note-files.js +2 -107
- package/dist/api/note-html-read.d.ts +2 -2
- package/dist/api/note-html-read.js +2 -2
- package/dist/api/note-html.d.ts +2 -2
- package/dist/api/note-html.js +2 -2
- package/dist/api/note-linger.d.ts +2 -83
- package/dist/api/note-linger.js +2 -270
- package/dist/api/note-presence.d.ts +2 -100
- package/dist/api/note-presence.js +2 -73
- package/dist/api/note-reading.d.ts +2 -51
- package/dist/api/note-reading.js +2 -42
- package/dist/api/note-toc.d.ts +2 -2
- package/dist/api/note-toc.js +2 -2
- package/dist/api/note-write.d.ts +2 -110
- package/dist/api/note-write.js +2 -217
- package/dist/api/notes.d.ts +2 -335
- package/dist/api/notes.js +2 -230
- package/dist/api/open-resources.js +3 -3
- package/dist/api/workspace.d.ts +3 -2
- package/dist/api/workspace.js +7 -6
- package/dist/cli/artifact/index.js +3 -3
- package/dist/cli/folders/index.d.ts +1 -1
- package/dist/cli/folders/index.js +4 -4
- package/dist/cli/help-examples.generated.js +1 -1
- package/dist/cli/index.js +2 -2
- package/dist/cli/{notes → memos}/api-transport.d.ts +1 -1
- package/dist/cli/{notes → memos}/api-transport.js +1 -1
- package/dist/cli/{notes → memos}/archive-command.d.ts +1 -1
- package/dist/cli/{notes → memos}/archive-command.js +5 -5
- package/dist/cli/{notes → memos}/character-plan.d.ts +3 -1
- package/dist/cli/{notes → memos}/character-plan.js +7 -5
- package/dist/cli/{notes → memos}/document.d.ts +9 -9
- package/dist/cli/{notes → memos}/document.js +12 -12
- package/dist/cli/{notes → memos}/edit-commands.d.ts +8 -8
- package/dist/cli/{notes → memos}/edit-commands.js +14 -14
- package/dist/cli/{notes → memos}/events.d.ts +3 -3
- package/dist/cli/{notes → memos}/events.js +2 -2
- package/dist/cli/{notes → memos}/files-commands.d.ts +2 -2
- package/dist/cli/{notes → memos}/files-commands.js +5 -5
- package/dist/cli/{notes → memos}/index.d.ts +16 -16
- package/dist/cli/{notes → memos}/index.js +53 -53
- package/dist/cli/{notes → memos}/linger.d.ts +3 -3
- package/dist/cli/{notes → memos}/linger.js +5 -5
- package/dist/cli/{notes → memos}/move-command.d.ts +5 -5
- package/dist/cli/{notes → memos}/move-command.js +6 -6
- package/dist/cli/{notes → memos}/rm-command.d.ts +2 -2
- package/dist/cli/{notes → memos}/rm-command.js +2 -2
- package/dist/cli/{notes → memos}/select-command.d.ts +1 -1
- package/dist/cli/{notes → memos}/select-command.js +4 -4
- package/dist/cli/{notes → memos}/suggest-diff.d.ts +1 -1
- package/dist/cli/{notes → memos}/suggest-diff.js +2 -2
- package/dist/cli/{notes → memos}/transfer-command.d.ts +2 -2
- package/dist/cli/{notes → memos}/transfer-command.js +2 -2
- package/dist/cli/share.d.ts +1 -1
- package/dist/cli/share.js +10 -6
- package/dist/cli/update/index.js +3 -3
- package/dist/cli/version.d.ts +1 -1
- package/dist/cli/version.js +1 -1
- package/package.json +9 -9
- /package/dist/cli/{notes → memos}/editing.d.ts +0 -0
- /package/dist/cli/{notes → memos}/editing.js +0 -0
- /package/dist/cli/{notes → memos}/html-read.d.ts +0 -0
- /package/dist/cli/{notes → memos}/html-read.js +0 -0
- /package/dist/cli/{notes → memos}/html.d.ts +0 -0
- /package/dist/cli/{notes → memos}/html.js +0 -0
- /package/dist/cli/{notes → memos}/media-commands.d.ts +0 -0
- /package/dist/cli/{notes → memos}/media-commands.js +0 -0
- /package/dist/cli/{notes → memos}/toc.d.ts +0 -0
- /package/dist/cli/{notes → memos}/toc.js +0 -0
- /package/dist/cli/{notes → memos}/version-commands.d.ts +0 -0
- /package/dist/cli/{notes → memos}/version-commands.js +0 -0
package/dist/api/content.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { type VersionedContentStore } from "./storage.js";
|
|
2
2
|
import { type Transport } from "./client.js";
|
|
3
3
|
import { type JsonObject, type Query } from "./common.js";
|
|
4
|
+
import { type ArtifactVisibility } from "./workspace.js";
|
|
4
5
|
export declare function artifactsApi(t: Transport, namespace: string): {
|
|
5
6
|
publish: (id: string, input: {
|
|
6
7
|
content: Uint8Array;
|
|
7
8
|
title: string;
|
|
8
9
|
kind: string;
|
|
9
10
|
description?: string;
|
|
10
|
-
visibility?:
|
|
11
|
+
visibility?: ArtifactVisibility;
|
|
11
12
|
share?: boolean;
|
|
12
13
|
}, store: VersionedContentStore) => Promise<{
|
|
13
14
|
version: number;
|
|
@@ -29,7 +30,7 @@ export declare function artifactsApi(t: Transport, namespace: string): {
|
|
|
29
30
|
version: number;
|
|
30
31
|
title?: string;
|
|
31
32
|
description?: string;
|
|
32
|
-
visibility?:
|
|
33
|
+
visibility?: ArtifactVisibility;
|
|
33
34
|
share?: boolean;
|
|
34
35
|
}) => Promise<unknown>;
|
|
35
36
|
delete: (id: string, permanent?: boolean) => Promise<unknown>;
|
|
@@ -42,7 +43,7 @@ export declare function artifactsApi(t: Transport, namespace: string): {
|
|
|
42
43
|
get: () => Promise<Record<string, unknown>>;
|
|
43
44
|
create: (role?: "read" | "write") => Promise<unknown>;
|
|
44
45
|
revoke: (revokeAccepted?: boolean) => Promise<unknown>;
|
|
45
|
-
visibility: (visibility:
|
|
46
|
+
visibility: (visibility: ArtifactVisibility) => Promise<unknown>;
|
|
46
47
|
access: () => Promise<unknown>;
|
|
47
48
|
remove: (userId: string) => Promise<unknown>;
|
|
48
49
|
};
|
package/dist/api/index.d.ts
CHANGED
|
@@ -17,15 +17,15 @@ export * from "./workspace.js";
|
|
|
17
17
|
export * from "./content.js";
|
|
18
18
|
export * from "./execution.js";
|
|
19
19
|
export * from "./ownership.js";
|
|
20
|
-
export * from "./
|
|
21
|
-
export * from "./
|
|
22
|
-
export * from "./
|
|
20
|
+
export * from "./memo-files.js";
|
|
21
|
+
export * from "./memo-presence.js";
|
|
22
|
+
export * from "./memo-linger.js";
|
|
23
23
|
export * from "./jobs.js";
|
|
24
24
|
export * from "./infra.js";
|
|
25
25
|
import { type ClientOptions, type Transport } from "./client.js";
|
|
26
26
|
export * from "./client.js";
|
|
27
27
|
export * from "./sessions.js";
|
|
28
|
-
export * from "./
|
|
28
|
+
export * from "./memos.js";
|
|
29
29
|
export * from "./agent.js";
|
|
30
30
|
export * from "./skills.js";
|
|
31
31
|
/** TypeScript operations use an explicit transport; importing does not execute CLI startup. */
|
|
@@ -568,7 +568,9 @@ export declare function createApi(transport: Transport): {
|
|
|
568
568
|
}) => Promise<unknown>;
|
|
569
569
|
managed: (id: string, action: "status" | "start" | "reconnect" | "stop", input: Record<string, unknown>) => Promise<unknown>;
|
|
570
570
|
};
|
|
571
|
-
|
|
571
|
+
memos: import("./memo-facade.js").MemosFacade;
|
|
572
|
+
/** @deprecated Use memos. */
|
|
573
|
+
notes: import("./memo-facade.js").MemosFacade;
|
|
572
574
|
skills: {
|
|
573
575
|
list: () => Promise<import("./skills.js").SkillsList>;
|
|
574
576
|
skill: (name: string) => Promise<import("./skills.js").SkillDetail>;
|
|
@@ -763,7 +765,7 @@ export declare function createApi(transport: Transport): {
|
|
|
763
765
|
title: string;
|
|
764
766
|
kind: string;
|
|
765
767
|
description?: string;
|
|
766
|
-
visibility?: "
|
|
768
|
+
visibility?: import("./workspace.js").ArtifactVisibility;
|
|
767
769
|
share?: boolean;
|
|
768
770
|
}, store: import("./storage.js").VersionedContentStore) => Promise<{
|
|
769
771
|
version: number;
|
|
@@ -785,7 +787,7 @@ export declare function createApi(transport: Transport): {
|
|
|
785
787
|
version: number;
|
|
786
788
|
title?: string;
|
|
787
789
|
description?: string;
|
|
788
|
-
visibility?:
|
|
790
|
+
visibility?: import("./workspace.js").ArtifactVisibility;
|
|
789
791
|
share?: boolean;
|
|
790
792
|
}) => Promise<unknown>;
|
|
791
793
|
delete: (id: string, permanent?: boolean) => Promise<unknown>;
|
|
@@ -798,7 +800,7 @@ export declare function createApi(transport: Transport): {
|
|
|
798
800
|
get: () => Promise<Record<string, unknown>>;
|
|
799
801
|
create: (role?: "read" | "write") => Promise<unknown>;
|
|
800
802
|
revoke: (revokeAccepted?: boolean) => Promise<unknown>;
|
|
801
|
-
visibility: (visibility: "
|
|
803
|
+
visibility: (visibility: import("./workspace.js").ArtifactVisibility) => Promise<unknown>;
|
|
802
804
|
access: () => Promise<unknown>;
|
|
803
805
|
remove: (userId: string) => Promise<unknown>;
|
|
804
806
|
};
|
|
@@ -1659,7 +1661,9 @@ export declare function createClient(options: ClientOptions): {
|
|
|
1659
1661
|
}) => Promise<unknown>;
|
|
1660
1662
|
managed: (id: string, action: "status" | "start" | "reconnect" | "stop", input: Record<string, unknown>) => Promise<unknown>;
|
|
1661
1663
|
};
|
|
1662
|
-
|
|
1664
|
+
memos: import("./memo-facade.js").MemosFacade;
|
|
1665
|
+
/** @deprecated Use memos. */
|
|
1666
|
+
notes: import("./memo-facade.js").MemosFacade;
|
|
1663
1667
|
skills: {
|
|
1664
1668
|
list: () => Promise<import("./skills.js").SkillsList>;
|
|
1665
1669
|
skill: (name: string) => Promise<import("./skills.js").SkillDetail>;
|
|
@@ -1854,7 +1858,7 @@ export declare function createClient(options: ClientOptions): {
|
|
|
1854
1858
|
title: string;
|
|
1855
1859
|
kind: string;
|
|
1856
1860
|
description?: string;
|
|
1857
|
-
visibility?: "
|
|
1861
|
+
visibility?: import("./workspace.js").ArtifactVisibility;
|
|
1858
1862
|
share?: boolean;
|
|
1859
1863
|
}, store: import("./storage.js").VersionedContentStore) => Promise<{
|
|
1860
1864
|
version: number;
|
|
@@ -1876,7 +1880,7 @@ export declare function createClient(options: ClientOptions): {
|
|
|
1876
1880
|
version: number;
|
|
1877
1881
|
title?: string;
|
|
1878
1882
|
description?: string;
|
|
1879
|
-
visibility?:
|
|
1883
|
+
visibility?: import("./workspace.js").ArtifactVisibility;
|
|
1880
1884
|
share?: boolean;
|
|
1881
1885
|
}) => Promise<unknown>;
|
|
1882
1886
|
delete: (id: string, permanent?: boolean) => Promise<unknown>;
|
|
@@ -1889,7 +1893,7 @@ export declare function createClient(options: ClientOptions): {
|
|
|
1889
1893
|
get: () => Promise<Record<string, unknown>>;
|
|
1890
1894
|
create: (role?: "read" | "write") => Promise<unknown>;
|
|
1891
1895
|
revoke: (revokeAccepted?: boolean) => Promise<unknown>;
|
|
1892
|
-
visibility: (visibility: "
|
|
1896
|
+
visibility: (visibility: import("./workspace.js").ArtifactVisibility) => Promise<unknown>;
|
|
1893
1897
|
access: () => Promise<unknown>;
|
|
1894
1898
|
remove: (userId: string) => Promise<unknown>;
|
|
1895
1899
|
};
|
|
@@ -2138,16 +2142,22 @@ export declare function createClient(options: ClientOptions): {
|
|
|
2138
2142
|
};
|
|
2139
2143
|
};
|
|
2140
2144
|
export * from "./layout.js";
|
|
2141
|
-
export * as
|
|
2142
|
-
|
|
2143
|
-
export * as
|
|
2144
|
-
export * from "./
|
|
2145
|
-
|
|
2145
|
+
export * as memoEditing from "./memo-editing.js";
|
|
2146
|
+
/** @deprecated Use memoEditing. */
|
|
2147
|
+
export * as noteEditing from "./memo-editing.js";
|
|
2148
|
+
export * as memoOutline from "./memo-toc.js";
|
|
2149
|
+
/** @deprecated Use memoOutline. */
|
|
2150
|
+
export * as noteOutline from "./memo-toc.js";
|
|
2151
|
+
export * as memoHtml from "./memo-html.js";
|
|
2152
|
+
/** @deprecated Use memoHtml. */
|
|
2153
|
+
export * as noteHtml from "./memo-html.js";
|
|
2154
|
+
export * from "./memo-html-read.js";
|
|
2155
|
+
export { characterDiff, MemoPatchError, NotePatchError, PATCH_LIMITS, } from "./memo-character-plan.js";
|
|
2146
2156
|
export * from "./presigned-transfer.js";
|
|
2147
|
-
export * from "./
|
|
2148
|
-
export * from "./
|
|
2149
|
-
export { documentEdits, documentInsertion } from "./
|
|
2150
|
-
export * from "./
|
|
2151
|
-
export type { NoteReadingOptions, NoteReadingPage, NoteFocusedRead } from "./
|
|
2152
|
-
export { lineRange, focusedRead, InvalidLineRange } from "./
|
|
2157
|
+
export * from "./memo-events.js";
|
|
2158
|
+
export * from "./memo-write.js";
|
|
2159
|
+
export { documentEdits, documentInsertion } from "./memo-edits.js";
|
|
2160
|
+
export * from "./memo-facade.js";
|
|
2161
|
+
export type { MemoReadingOptions, MemoReadingPage, MemoFocusedRead, NoteReadingOptions, NoteReadingPage, NoteFocusedRead } from "./memo-reading.js";
|
|
2162
|
+
export { lineRange, focusedRead, InvalidLineRange } from "./memo-reading.js";
|
|
2153
2163
|
export type { HostMovePreview, HostMoveRequest, HostMoveReceipt, HostMoveRetainedSessions, HostMoveRetainedRuns } from "./host-moves.js";
|
package/dist/api/index.js
CHANGED
|
@@ -30,9 +30,9 @@ export * from "./workspace.js";
|
|
|
30
30
|
export * from "./content.js";
|
|
31
31
|
export * from "./execution.js";
|
|
32
32
|
export * from "./ownership.js";
|
|
33
|
-
export * from "./
|
|
34
|
-
export * from "./
|
|
35
|
-
export * from "./
|
|
33
|
+
export * from "./memo-files.js";
|
|
34
|
+
export * from "./memo-presence.js";
|
|
35
|
+
export * from "./memo-linger.js";
|
|
36
36
|
export * from "./jobs.js";
|
|
37
37
|
export * from "./infra.js";
|
|
38
38
|
/** `@dreamlake/dreamlake-cli/api` — the DreamLake TypeScript API.
|
|
@@ -48,16 +48,17 @@ export * from "./infra.js";
|
|
|
48
48
|
*/
|
|
49
49
|
import { agentApi, projectToolsApi } from "./agent.js";
|
|
50
50
|
import { createTransport, } from "./client.js";
|
|
51
|
-
import {
|
|
51
|
+
import { memosFacade } from "./memo-facade.js";
|
|
52
52
|
import { sessionsApi } from "./sessions.js";
|
|
53
53
|
import { skillsApi } from "./skills.js";
|
|
54
54
|
export * from "./client.js";
|
|
55
55
|
export * from "./sessions.js";
|
|
56
|
-
export * from "./
|
|
56
|
+
export * from "./memos.js";
|
|
57
57
|
export * from "./agent.js";
|
|
58
58
|
export * from "./skills.js";
|
|
59
59
|
/** TypeScript operations use an explicit transport; importing does not execute CLI startup. */
|
|
60
60
|
export function createApi(transport) {
|
|
61
|
+
const memos = memosFacade(transport);
|
|
61
62
|
return {
|
|
62
63
|
transport,
|
|
63
64
|
openResources: openResourcesApi(transport),
|
|
@@ -77,7 +78,9 @@ export function createApi(transport) {
|
|
|
77
78
|
teams: teamsApi(transport),
|
|
78
79
|
sessions: (namespace) => sessionsApi(transport, namespace),
|
|
79
80
|
terminal: (namespace) => terminalApi(transport, namespace),
|
|
80
|
-
|
|
81
|
+
memos,
|
|
82
|
+
/** @deprecated Use memos. */
|
|
83
|
+
notes: memos,
|
|
81
84
|
skills: skillsApi(transport),
|
|
82
85
|
projects: (namespace) => projectsApi(transport, namespace),
|
|
83
86
|
nodes: nodesApi(transport),
|
|
@@ -113,14 +116,20 @@ export function createClient(options) {
|
|
|
113
116
|
};
|
|
114
117
|
}
|
|
115
118
|
export * from "./layout.js";
|
|
116
|
-
export * as
|
|
117
|
-
|
|
118
|
-
export * as
|
|
119
|
-
export * from "./
|
|
120
|
-
|
|
119
|
+
export * as memoEditing from "./memo-editing.js";
|
|
120
|
+
/** @deprecated Use memoEditing. */
|
|
121
|
+
export * as noteEditing from "./memo-editing.js";
|
|
122
|
+
export * as memoOutline from "./memo-toc.js";
|
|
123
|
+
/** @deprecated Use memoOutline. */
|
|
124
|
+
export * as noteOutline from "./memo-toc.js";
|
|
125
|
+
export * as memoHtml from "./memo-html.js";
|
|
126
|
+
/** @deprecated Use memoHtml. */
|
|
127
|
+
export * as noteHtml from "./memo-html.js";
|
|
128
|
+
export * from "./memo-html-read.js";
|
|
129
|
+
export { characterDiff, MemoPatchError, NotePatchError, PATCH_LIMITS, } from "./memo-character-plan.js";
|
|
121
130
|
export * from "./presigned-transfer.js";
|
|
122
|
-
export * from "./
|
|
123
|
-
export * from "./
|
|
124
|
-
export { documentEdits, documentInsertion } from "./
|
|
125
|
-
export * from "./
|
|
126
|
-
export { lineRange, focusedRead, InvalidLineRange } from "./
|
|
131
|
+
export * from "./memo-events.js";
|
|
132
|
+
export * from "./memo-write.js";
|
|
133
|
+
export { documentEdits, documentInsertion } from "./memo-edits.js";
|
|
134
|
+
export * from "./memo-facade.js";
|
|
135
|
+
export { lineRange, focusedRead, InvalidLineRange } from "./memo-reading.js";
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/** Unicode code-point edits against one retained Notes v2 baseline. */
|
|
2
|
+
export interface MemoSource {
|
|
3
|
+
note: string;
|
|
4
|
+
content: string;
|
|
5
|
+
hash: string;
|
|
6
|
+
revision: string;
|
|
7
|
+
}
|
|
8
|
+
export interface SourceEdit {
|
|
9
|
+
start: number;
|
|
10
|
+
end: number;
|
|
11
|
+
text: string;
|
|
12
|
+
}
|
|
13
|
+
export interface MemoEdit extends SourceEdit {
|
|
14
|
+
expected?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface MemoPatch {
|
|
17
|
+
format: "inline-dff" | "diff";
|
|
18
|
+
patch: string;
|
|
19
|
+
baseRevision: string;
|
|
20
|
+
mode: "merge" | "exact";
|
|
21
|
+
}
|
|
22
|
+
/** The CLI's names for the same shapes; `src/cli/memos/document.ts` re-exports them. */
|
|
23
|
+
export type SourceSnapshot = MemoSource;
|
|
24
|
+
export type DocumentPatchPayload = MemoPatch;
|
|
25
|
+
/** Generated reading-view annotations are never saved as source. What is
|
|
26
|
+
* forbidden is NEW text that carries the generated header line
|
|
27
|
+
* (`<!-- notes-reading-view revision=… hash=…`). Deleting such a line, keeping
|
|
28
|
+
* one the note already has, or mentioning the marker in prose or a code block
|
|
29
|
+
* is allowed. Checked on raw inserted text before compilation (escaping would
|
|
30
|
+
* hide it) and on the insertion payloads of a caller-supplied patch. */
|
|
31
|
+
export declare const READING_VIEW_MARKER = "<!-- notes-reading-view";
|
|
32
|
+
export declare const READING_VIEW_HEADER: RegExp;
|
|
33
|
+
export declare class ReadingViewMarkerRefused extends Error {
|
|
34
|
+
constructor(what: string);
|
|
35
|
+
}
|
|
36
|
+
/** Inserted or replacement text only, never deletions or unchanged context. */
|
|
37
|
+
export declare function refuseReadingView(text: string, what: string): void;
|
|
38
|
+
/** Whole-body replacement: only lines that are new relative to the baseline count, so a header the note already holds survives a write. */
|
|
39
|
+
export declare function refuseNewReadingViewLines(baseline: string, content: string, what: string): void;
|
|
40
|
+
/** Apply the inline-dff subset this client emits (`@@ chars s:e @@` + one `~` line of `[-old-]`/`{+new+}`
|
|
41
|
+
* segments) to a baseline. null when the patch is outside that subset or its old text does not match. */
|
|
42
|
+
export declare function applyInlineDff(baseline: string, patch: string): string | null;
|
|
43
|
+
/** Apply a unified diff to a baseline, verifying context and removed lines. null when it does not apply cleanly. */
|
|
44
|
+
export declare function applyUnifiedDiff(baseline: string, patch: string): string | null;
|
|
45
|
+
/** A caller-supplied patch. With the baseline it was written against, the target is reconstructed and
|
|
46
|
+
* checked like a whole-body write (so a header split across hunks is seen assembled, and one the note
|
|
47
|
+
* already has may be re-added). Without a baseline, or when the patch does not apply to it, the check is
|
|
48
|
+
* BEST-EFFORT on the insertion payloads: inline-dff `{+…+}` (escapes decoded), concatenated across hunks
|
|
49
|
+
* that are adjacent in the original (one's end offset is the next's start, so no baseline text lies
|
|
50
|
+
* between them), or unified-diff `+` lines. Authoritative enforcement belongs to the server. */
|
|
51
|
+
export declare function refuseReadingViewPatch(patch: string, format: "inline-dff" | "diff", baseline?: string): void;
|
|
52
|
+
/** Exact original-source spans, with untouched gaps omitted from the PATCH. The target the edits
|
|
53
|
+
* produce is reconstructed and checked against the baseline, so a generated header assembled from
|
|
54
|
+
* several spans is refused exactly as a whole-body write would be. */
|
|
55
|
+
export declare function documentEdits(source: SourceSnapshot, edits: SourceEdit[], exact?: boolean): DocumentPatchPayload;
|
|
56
|
+
/** One literal insertion at an original-source Unicode code-point boundary. */
|
|
57
|
+
export declare function documentInsertion(source: SourceSnapshot, at: number, text: string, exact?: boolean): DocumentPatchPayload;
|
|
58
|
+
/** Validate optional expected text, then use the same source-span compiler. */
|
|
59
|
+
export declare function memoEdits(source: MemoSource, edits: MemoEdit[], mode?: "merge" | "exact"): MemoPatch;
|
|
60
|
+
export type { MemoSource as NoteSource };
|
|
61
|
+
export type { MemoEdit as NoteEdit };
|
|
62
|
+
export type { MemoPatch as NotePatch };
|
|
63
|
+
export { memoEdits as noteEdits };
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
/** Generated reading-view annotations are never saved as source. What is
|
|
2
|
+
* forbidden is NEW text that carries the generated header line
|
|
3
|
+
* (`<!-- notes-reading-view revision=… hash=…`). Deleting such a line, keeping
|
|
4
|
+
* one the note already has, or mentioning the marker in prose or a code block
|
|
5
|
+
* is allowed. Checked on raw inserted text before compilation (escaping would
|
|
6
|
+
* hide it) and on the insertion payloads of a caller-supplied patch. */
|
|
7
|
+
export const READING_VIEW_MARKER = "<!-- notes-reading-view";
|
|
8
|
+
export const READING_VIEW_HEADER = /^\s*<!-- notes-reading-view revision=/m;
|
|
9
|
+
export class ReadingViewMarkerRefused extends Error {
|
|
10
|
+
constructor(what) {
|
|
11
|
+
super(`${what} adds a generated reading-view marker header ("${READING_VIEW_MARKER} revision=…"); generated annotations are never saved as source`);
|
|
12
|
+
this.name = "ReadingViewMarkerRefused";
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/** Inserted or replacement text only, never deletions or unchanged context. */
|
|
16
|
+
export function refuseReadingView(text, what) {
|
|
17
|
+
if (READING_VIEW_HEADER.test(text))
|
|
18
|
+
throw new ReadingViewMarkerRefused(what);
|
|
19
|
+
}
|
|
20
|
+
/** Whole-body replacement: only lines that are new relative to the baseline count, so a header the note already holds survives a write. */
|
|
21
|
+
export function refuseNewReadingViewLines(baseline, content, what) {
|
|
22
|
+
const kept = new Set(baseline.split("\n"));
|
|
23
|
+
for (const line of content.split("\n"))
|
|
24
|
+
if (READING_VIEW_HEADER.test(line) && !kept.has(line))
|
|
25
|
+
throw new ReadingViewMarkerRefused(what);
|
|
26
|
+
}
|
|
27
|
+
/** inline-dff escapes only (`\\ \n \r \t \[ \] \{ \} \+ \-`); anything else keeps its backslash. Never applied to unified-diff lines. */
|
|
28
|
+
const INLINE_ESCAPES = { "\\": "\\", n: "\n", r: "\r", t: "\t", "[": "[", "]": "]", "{": "{", "}": "}", "+": "+", "-": "-" };
|
|
29
|
+
const decodeInline = (text) => text.replace(/\\(.)/g, (whole, char) => INLINE_ESCAPES[char] ?? whole);
|
|
30
|
+
/** Apply the inline-dff subset this client emits (`@@ chars s:e @@` + one `~` line of `[-old-]`/`{+new+}`
|
|
31
|
+
* segments) to a baseline. null when the patch is outside that subset or its old text does not match. */
|
|
32
|
+
export function applyInlineDff(baseline, patch) {
|
|
33
|
+
const points = Array.from(baseline), lines = patch.split("\n");
|
|
34
|
+
let out = "", cursor = 0;
|
|
35
|
+
for (let i = 0; i < lines.length;) {
|
|
36
|
+
if (lines[i] === "") {
|
|
37
|
+
i++;
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
const header = /^@@ chars (\d+):(\d+) @@$/.exec(lines[i]), body = lines[i + 1];
|
|
41
|
+
if (!header || body === undefined || !body.startsWith("~ "))
|
|
42
|
+
return null;
|
|
43
|
+
const start = Number(header[1]), end = Number(header[2]);
|
|
44
|
+
if (start < cursor || end < start || end > points.length)
|
|
45
|
+
return null;
|
|
46
|
+
let rest = body.slice(2), old = "", added = "";
|
|
47
|
+
while (rest) {
|
|
48
|
+
const segment = /^(?:\[-((?:\\.|[^\\])*?)-\]|\{\+((?:\\.|[^\\])*?)\+\})/.exec(rest);
|
|
49
|
+
if (!segment)
|
|
50
|
+
return null;
|
|
51
|
+
if (segment[1] !== undefined)
|
|
52
|
+
old += decodeInline(segment[1]);
|
|
53
|
+
else
|
|
54
|
+
added += decodeInline(segment[2]);
|
|
55
|
+
rest = rest.slice(segment[0].length);
|
|
56
|
+
}
|
|
57
|
+
if (points.slice(start, end).join("") !== old)
|
|
58
|
+
return null;
|
|
59
|
+
out += points.slice(cursor, start).join("") + added;
|
|
60
|
+
cursor = end;
|
|
61
|
+
i += 2;
|
|
62
|
+
}
|
|
63
|
+
return out + points.slice(cursor).join("");
|
|
64
|
+
}
|
|
65
|
+
/** Apply a unified diff to a baseline, verifying context and removed lines. null when it does not apply cleanly. */
|
|
66
|
+
export function applyUnifiedDiff(baseline, patch) {
|
|
67
|
+
const src = baseline.split("\n"), lines = patch.split("\n"), out = [];
|
|
68
|
+
let at = 0, i = 0;
|
|
69
|
+
while (i < lines.length && (lines[i].startsWith("--- ") || lines[i].startsWith("+++ ")))
|
|
70
|
+
i++;
|
|
71
|
+
while (i < lines.length) {
|
|
72
|
+
if (lines[i] === "" && i === lines.length - 1)
|
|
73
|
+
break;
|
|
74
|
+
const hunk = /^@@ -(\d+)(?:,(\d+))? \+\d+(?:,\d+)? @@/.exec(lines[i]);
|
|
75
|
+
if (!hunk)
|
|
76
|
+
return null;
|
|
77
|
+
const index = hunk[2] === "0" ? Number(hunk[1]) : Number(hunk[1]) - 1;
|
|
78
|
+
if (index < at || index > src.length)
|
|
79
|
+
return null;
|
|
80
|
+
out.push(...src.slice(at, index));
|
|
81
|
+
at = index;
|
|
82
|
+
i++;
|
|
83
|
+
while (i < lines.length && !lines[i].startsWith("@@")) {
|
|
84
|
+
const line = lines[i++];
|
|
85
|
+
if (line.startsWith("\\"))
|
|
86
|
+
continue;
|
|
87
|
+
if (line === "") {
|
|
88
|
+
if (i === lines.length)
|
|
89
|
+
break;
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
const tag = line[0], text = line.slice(1);
|
|
93
|
+
if (tag === " " || tag === "-") {
|
|
94
|
+
if (src[at] !== text)
|
|
95
|
+
return null;
|
|
96
|
+
if (tag === " ")
|
|
97
|
+
out.push(text);
|
|
98
|
+
at++;
|
|
99
|
+
}
|
|
100
|
+
else if (tag === "+")
|
|
101
|
+
out.push(text);
|
|
102
|
+
else
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
out.push(...src.slice(at));
|
|
107
|
+
return out.join("\n");
|
|
108
|
+
}
|
|
109
|
+
/** Insertion payloads of an inline-dff patch, hunk by hunk with their original spans; null outside the parseable subset. */
|
|
110
|
+
function inlineInsertions(patch) {
|
|
111
|
+
const lines = patch.split("\n"), hunks = [];
|
|
112
|
+
for (let i = 0; i < lines.length;) {
|
|
113
|
+
if (lines[i] === "") {
|
|
114
|
+
i++;
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
const header = /^@@ chars (\d+):(\d+) @@$/.exec(lines[i]), body = lines[i + 1];
|
|
118
|
+
if (!header || body === undefined || !body.startsWith("~ "))
|
|
119
|
+
return null;
|
|
120
|
+
let rest = body.slice(2), added = "";
|
|
121
|
+
while (rest) {
|
|
122
|
+
const segment = /^(?:\[-((?:\\.|[^\\])*?)-\]|\{\+((?:\\.|[^\\])*?)\+\})/.exec(rest);
|
|
123
|
+
if (!segment)
|
|
124
|
+
return null;
|
|
125
|
+
if (segment[2] !== undefined)
|
|
126
|
+
added += decodeInline(segment[2]);
|
|
127
|
+
rest = rest.slice(segment[0].length);
|
|
128
|
+
}
|
|
129
|
+
hunks.push({ start: Number(header[1]), end: Number(header[2]), added });
|
|
130
|
+
i += 2;
|
|
131
|
+
}
|
|
132
|
+
return hunks;
|
|
133
|
+
}
|
|
134
|
+
/** A caller-supplied patch. With the baseline it was written against, the target is reconstructed and
|
|
135
|
+
* checked like a whole-body write (so a header split across hunks is seen assembled, and one the note
|
|
136
|
+
* already has may be re-added). Without a baseline, or when the patch does not apply to it, the check is
|
|
137
|
+
* BEST-EFFORT on the insertion payloads: inline-dff `{+…+}` (escapes decoded), concatenated across hunks
|
|
138
|
+
* that are adjacent in the original (one's end offset is the next's start, so no baseline text lies
|
|
139
|
+
* between them), or unified-diff `+` lines. Authoritative enforcement belongs to the server. */
|
|
140
|
+
export function refuseReadingViewPatch(patch, format, baseline) {
|
|
141
|
+
if (baseline !== undefined) {
|
|
142
|
+
const target = format === "diff" ? applyUnifiedDiff(baseline, patch) : applyInlineDff(baseline, patch);
|
|
143
|
+
if (target !== null) {
|
|
144
|
+
refuseNewReadingViewLines(baseline, target, "the patch");
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (format === "diff") {
|
|
149
|
+
for (const line of patch.split("\n"))
|
|
150
|
+
if (line.startsWith("+") && !line.startsWith("+++ "))
|
|
151
|
+
refuseReadingView(line.slice(1), "the patch");
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
const hunks = inlineInsertions(patch);
|
|
155
|
+
if (hunks === null) {
|
|
156
|
+
for (const match of patch.matchAll(/\{\+((?:\\[\s\S]|[^\\])*?)\+\}/g))
|
|
157
|
+
refuseReadingView(decodeInline(match[1]), "the patch");
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
let run = "", previousEnd = -1;
|
|
161
|
+
for (const hunk of hunks) {
|
|
162
|
+
run = hunk.start === previousEnd ? run + hunk.added : hunk.added;
|
|
163
|
+
previousEnd = hunk.end;
|
|
164
|
+
refuseReadingView(run, "the patch");
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
function inlineLiteral(text) {
|
|
168
|
+
return text.replace(/[\\\n\r\t\[\]{}+\-]/g, char => char === "\n" ? "\\n" : char === "\r" ? "\\r" : char === "\t" ? "\\t" : `\\${char}`);
|
|
169
|
+
}
|
|
170
|
+
/** Exact original-source spans, with untouched gaps omitted from the PATCH. The target the edits
|
|
171
|
+
* produce is reconstructed and checked against the baseline, so a generated header assembled from
|
|
172
|
+
* several spans is refused exactly as a whole-body write would be. */
|
|
173
|
+
export function documentEdits(source, edits, exact = false) {
|
|
174
|
+
const points = Array.from(source.content);
|
|
175
|
+
let lastEnd = 0, lastStart = -1, target = "";
|
|
176
|
+
const hunks = [];
|
|
177
|
+
for (const edit of edits) {
|
|
178
|
+
if (!Number.isSafeInteger(edit.start) || !Number.isSafeInteger(edit.end) || edit.start < lastEnd
|
|
179
|
+
|| edit.start <= lastStart || edit.end < edit.start || edit.end > points.length) {
|
|
180
|
+
throw new Error("Edit spans must be ordered and disjoint within the original source");
|
|
181
|
+
}
|
|
182
|
+
target += points.slice(lastEnd, edit.start).join("") + edit.text;
|
|
183
|
+
lastStart = edit.start;
|
|
184
|
+
lastEnd = edit.end;
|
|
185
|
+
const old = points.slice(edit.start, edit.end).join("");
|
|
186
|
+
if (old === edit.text)
|
|
187
|
+
continue;
|
|
188
|
+
hunks.push(`@@ chars ${edit.start}:${edit.end} @@\n~ ${old ? `[-${inlineLiteral(old)}-]` : ""}${edit.text ? `{+${inlineLiteral(edit.text)}+}` : ""}\n`);
|
|
189
|
+
}
|
|
190
|
+
refuseNewReadingViewLines(source.content, target + points.slice(lastEnd).join(""), "the edit");
|
|
191
|
+
return { format: "inline-dff", patch: hunks.join(""), baseRevision: source.revision, mode: exact ? "exact" : "merge" };
|
|
192
|
+
}
|
|
193
|
+
/** One literal insertion at an original-source Unicode code-point boundary. */
|
|
194
|
+
export function documentInsertion(source, at, text, exact = false) {
|
|
195
|
+
return documentEdits(source, [{ start: at, end: at, text }], exact);
|
|
196
|
+
}
|
|
197
|
+
/** Validate optional expected text, then use the same source-span compiler. */
|
|
198
|
+
export function memoEdits(source, edits, mode = "exact") {
|
|
199
|
+
const points = Array.from(source.content);
|
|
200
|
+
for (const edit of edits) {
|
|
201
|
+
if (edit.expected !== undefined && edit.expected !== points.slice(edit.start, edit.end).join(""))
|
|
202
|
+
throw new Error("Edit does not match the original source");
|
|
203
|
+
}
|
|
204
|
+
return documentEdits(source, edits, mode === "exact");
|
|
205
|
+
}
|
|
206
|
+
export { memoEdits as noteEdits };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export type MemoEventRequest = (url: string, options: {
|
|
2
|
+
token?: string | null;
|
|
3
|
+
headers?: Record<string, string>;
|
|
4
|
+
signal?: AbortSignal;
|
|
5
|
+
followRedirects?: boolean;
|
|
6
|
+
}) => Promise<Response>;
|
|
7
|
+
export type Selection = null | {
|
|
8
|
+
status: 'unresolved';
|
|
9
|
+
} | {
|
|
10
|
+
status: 'resolved';
|
|
11
|
+
anchor: number;
|
|
12
|
+
head: number;
|
|
13
|
+
start: number;
|
|
14
|
+
end: number;
|
|
15
|
+
unit: 'unicode-code-point';
|
|
16
|
+
text: string;
|
|
17
|
+
truncated: boolean;
|
|
18
|
+
};
|
|
19
|
+
export interface Participant {
|
|
20
|
+
client: string;
|
|
21
|
+
user: {
|
|
22
|
+
id: string;
|
|
23
|
+
name: string;
|
|
24
|
+
kind: 'human' | 'agent';
|
|
25
|
+
owner?: {
|
|
26
|
+
id: string;
|
|
27
|
+
name: string;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
selection?: Selection;
|
|
31
|
+
}
|
|
32
|
+
export interface MemoEvent {
|
|
33
|
+
type: 'observation';
|
|
34
|
+
note: string;
|
|
35
|
+
hash: string;
|
|
36
|
+
observedAt: number;
|
|
37
|
+
participants: Participant[];
|
|
38
|
+
activityVersion: string;
|
|
39
|
+
}
|
|
40
|
+
/** Explicit-token adapter: no login files, telemetry or process state. */
|
|
41
|
+
export declare function readMemoEvents(url: string, token: string, note: string, signal: AbortSignal, receive: (event: MemoEvent) => void, request?: MemoEventRequest): Promise<void>;
|
|
42
|
+
export type { MemoEventRequest as NoteEventRequest };
|
|
43
|
+
export type { MemoEvent as NoteEvent };
|
|
44
|
+
export { readMemoEvents as readNoteEvents };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/** Notes SSE parser over an injected request; the CLI supplies its own `requestRaw`. */
|
|
2
|
+
import { httpResponse, HttpError } from "./http.js";
|
|
3
|
+
/** Fetch SSE with auth headers, abort/idle bounds, and no automatic replay across gaps. */
|
|
4
|
+
async function readEvents(url, token, note, signal, receive, request) {
|
|
5
|
+
const idle = new AbortController();
|
|
6
|
+
let timer;
|
|
7
|
+
const touch = () => { clearTimeout(timer); timer = setTimeout(() => idle.abort(new Error('Memos event stream timed out')), 45000); };
|
|
8
|
+
touch();
|
|
9
|
+
let reader;
|
|
10
|
+
try {
|
|
11
|
+
const res = await request(url, { token, headers: { Accept: 'text/event-stream' },
|
|
12
|
+
signal: AbortSignal.any([signal, idle.signal]), followRedirects: false });
|
|
13
|
+
if (!/^text\/event-stream(?:;|$)/i.test(res.headers.get('content-type') ?? '') || !res.body)
|
|
14
|
+
throw new Error('server does not support Memos events; upgrade the server');
|
|
15
|
+
reader = res.body.getReader();
|
|
16
|
+
const decoder = new TextDecoder('utf-8', { fatal: true });
|
|
17
|
+
let buffer = '', data = [], frameSize = 0;
|
|
18
|
+
while (!signal.aborted) {
|
|
19
|
+
const { done, value } = await reader.read();
|
|
20
|
+
if (done)
|
|
21
|
+
throw new Error('Memos event stream disconnected; run --linger again for a fresh snapshot');
|
|
22
|
+
touch();
|
|
23
|
+
buffer += decoder.decode(value, { stream: true });
|
|
24
|
+
if (buffer.length > 4_000_000)
|
|
25
|
+
throw new Error('Memos event frame exceeds limit');
|
|
26
|
+
let newline;
|
|
27
|
+
while ((newline = buffer.indexOf('\n')) >= 0) {
|
|
28
|
+
const line = buffer.slice(0, newline).replace(/\r$/, '');
|
|
29
|
+
buffer = buffer.slice(newline + 1);
|
|
30
|
+
if (line.startsWith('data:')) {
|
|
31
|
+
const part = line.slice(5).replace(/^ /, '');
|
|
32
|
+
frameSize += part.length;
|
|
33
|
+
if (frameSize > 4_000_000)
|
|
34
|
+
throw new Error('Memos event frame exceeds limit');
|
|
35
|
+
data.push(part);
|
|
36
|
+
}
|
|
37
|
+
else if (!line && data.length) {
|
|
38
|
+
const event = JSON.parse(data.join('\n'));
|
|
39
|
+
data = [];
|
|
40
|
+
frameSize = 0;
|
|
41
|
+
if (event.type === 'error')
|
|
42
|
+
throw new Error(`Memos event stream ended (${String(event.error)})`);
|
|
43
|
+
if (event.type !== 'observation' || event.note !== note || !/^sha256:[a-f0-9]{64}$/.test(event.hash) ||
|
|
44
|
+
!Array.isArray(event.participants) || typeof event.activityVersion !== 'string')
|
|
45
|
+
throw new Error('invalid Memos event response');
|
|
46
|
+
receive(event);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
finally {
|
|
52
|
+
clearTimeout(timer);
|
|
53
|
+
await reader?.cancel().catch(() => { });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/** Explicit-token adapter: no login files, telemetry or process state. */
|
|
57
|
+
export function readMemoEvents(url, token, note, signal, receive, request) {
|
|
58
|
+
return readEvents(url, token, note, signal, receive, request ?? (async (url, options = {}) => {
|
|
59
|
+
const response = await httpResponse(url, { token: options.token, headers: options.headers, signal: options.signal, redirect: "manual" });
|
|
60
|
+
if (!response.ok)
|
|
61
|
+
throw new HttpError(response.status, await response.text());
|
|
62
|
+
return response;
|
|
63
|
+
}));
|
|
64
|
+
}
|
|
65
|
+
export { readMemoEvents as readNoteEvents };
|