@lemoncat7/dsh-knowledge 1.1.5 → 2.0.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 (128) hide show
  1. package/README.md +24 -4
  2. package/docs/architecture.md +32 -6
  3. package/docs/requirements.md +10 -0
  4. package/lib/api.d.ts +2 -0
  5. package/lib/api.d.ts.map +1 -1
  6. package/lib/api.js +235 -13
  7. package/lib/api.js.map +1 -1
  8. package/lib/atomic-file.d.ts +16 -0
  9. package/lib/atomic-file.d.ts.map +1 -0
  10. package/lib/atomic-file.js +92 -0
  11. package/lib/atomic-file.js.map +1 -0
  12. package/lib/client.d.ts.map +1 -1
  13. package/lib/client.js +38 -35
  14. package/lib/client.js.map +2 -2
  15. package/lib/config.d.ts.map +1 -1
  16. package/lib/config.js +2 -5
  17. package/lib/config.js.map +1 -1
  18. package/lib/connection.d.ts.map +1 -1
  19. package/lib/connection.js +5 -15
  20. package/lib/connection.js.map +1 -1
  21. package/lib/content-safety.d.ts +12 -0
  22. package/lib/content-safety.d.ts.map +1 -0
  23. package/lib/content-safety.js +38 -0
  24. package/lib/content-safety.js.map +1 -0
  25. package/lib/documents/projection-queue.d.ts +10 -0
  26. package/lib/documents/projection-queue.d.ts.map +1 -0
  27. package/lib/documents/projection-queue.js +21 -0
  28. package/lib/documents/projection-queue.js.map +1 -0
  29. package/lib/documents/store.d.ts +4 -2
  30. package/lib/documents/store.d.ts.map +1 -1
  31. package/lib/documents/store.js +54 -73
  32. package/lib/documents/store.js.map +1 -1
  33. package/lib/domain.d.ts +13 -0
  34. package/lib/domain.d.ts.map +1 -1
  35. package/lib/domain.js.map +1 -1
  36. package/lib/extraction.d.ts.map +1 -1
  37. package/lib/extraction.js +18 -4
  38. package/lib/extraction.js.map +1 -1
  39. package/lib/index.d.ts +1 -0
  40. package/lib/index.d.ts.map +1 -1
  41. package/lib/index.js +91 -32
  42. package/lib/index.js.map +1 -1
  43. package/lib/knowledge-merge.d.ts +8 -0
  44. package/lib/knowledge-merge.d.ts.map +1 -0
  45. package/lib/knowledge-merge.js +19 -0
  46. package/lib/knowledge-merge.js.map +1 -0
  47. package/lib/local-provider.d.ts +26 -1
  48. package/lib/local-provider.d.ts.map +1 -1
  49. package/lib/local-provider.js +402 -63
  50. package/lib/local-provider.js.map +1 -1
  51. package/lib/management-proxy.d.ts.map +1 -1
  52. package/lib/management-proxy.js +22 -13
  53. package/lib/management-proxy.js.map +1 -1
  54. package/lib/note-reference-handle.d.ts +15 -0
  55. package/lib/note-reference-handle.d.ts.map +1 -0
  56. package/lib/note-reference-handle.js +54 -0
  57. package/lib/note-reference-handle.js.map +1 -0
  58. package/lib/note-reference-tools.d.ts +6 -0
  59. package/lib/note-reference-tools.d.ts.map +1 -0
  60. package/lib/note-reference-tools.js +119 -0
  61. package/lib/note-reference-tools.js.map +1 -0
  62. package/lib/note-tools.d.ts +6 -0
  63. package/lib/note-tools.d.ts.map +1 -0
  64. package/lib/note-tools.js +283 -0
  65. package/lib/note-tools.js.map +1 -0
  66. package/lib/notes/domain.d.ts +44 -0
  67. package/lib/notes/domain.d.ts.map +1 -0
  68. package/lib/notes/domain.js +38 -0
  69. package/lib/notes/domain.js.map +1 -0
  70. package/lib/notes/store.d.ts +39 -0
  71. package/lib/notes/store.d.ts.map +1 -0
  72. package/lib/notes/store.js +407 -0
  73. package/lib/notes/store.js.map +1 -0
  74. package/lib/provider.d.ts +17 -0
  75. package/lib/provider.d.ts.map +1 -1
  76. package/lib/remote-provider.d.ts +19 -0
  77. package/lib/remote-provider.d.ts.map +1 -1
  78. package/lib/remote-provider.js +172 -14
  79. package/lib/remote-provider.js.map +1 -1
  80. package/lib/remote-url.d.ts +2 -0
  81. package/lib/remote-url.d.ts.map +1 -0
  82. package/lib/remote-url.js +14 -0
  83. package/lib/remote-url.js.map +1 -0
  84. package/lib/runtime.d.ts +1 -0
  85. package/lib/runtime.d.ts.map +1 -1
  86. package/lib/runtime.js.map +1 -1
  87. package/lib/service-settings.d.ts.map +1 -1
  88. package/lib/service-settings.js +3 -10
  89. package/lib/service-settings.js.map +1 -1
  90. package/lib/theme-bridge.js +12 -12
  91. package/lib/theme-bridge.js.map +1 -1
  92. package/lib/tool-authorization.d.ts +14 -0
  93. package/lib/tool-authorization.d.ts.map +1 -0
  94. package/lib/tool-authorization.js +124 -0
  95. package/lib/tool-authorization.js.map +1 -0
  96. package/lib/tool-input.d.ts +6 -0
  97. package/lib/tool-input.d.ts.map +1 -0
  98. package/lib/tool-input.js +27 -0
  99. package/lib/tool-input.js.map +1 -0
  100. package/lib/tools.d.ts +2 -1
  101. package/lib/tools.d.ts.map +1 -1
  102. package/lib/tools.js +70 -177
  103. package/lib/tools.js.map +1 -1
  104. package/lib/tracking.d.ts +29 -0
  105. package/lib/tracking.d.ts.map +1 -0
  106. package/lib/tracking.js +141 -0
  107. package/lib/tracking.js.map +1 -0
  108. package/lib/web-change-review.d.ts +34 -0
  109. package/lib/web-change-review.d.ts.map +1 -0
  110. package/lib/web-change-review.js +147 -0
  111. package/lib/web-change-review.js.map +1 -0
  112. package/lib/web-markdown-preview.d.ts.map +1 -1
  113. package/lib/web-markdown-preview.js +10 -0
  114. package/lib/web-markdown-preview.js.map +1 -1
  115. package/lib/web-note-editor.d.ts +44 -0
  116. package/lib/web-note-editor.d.ts.map +1 -0
  117. package/lib/web-note-editor.js +118 -0
  118. package/lib/web-note-editor.js.map +1 -0
  119. package/lib/web.d.ts.map +1 -1
  120. package/lib/web.js +3 -1
  121. package/lib/web.js.map +1 -1
  122. package/package.json +12 -1
  123. package/web/app.js +1888 -154
  124. package/web/change-review.js +5 -0
  125. package/web/index.html +2 -0
  126. package/web/markdown-preview.js +8 -8
  127. package/web/note-editor.js +220 -0
  128. package/web/styles.css +599 -170
@@ -0,0 +1,119 @@
1
+ import { readMountedKnowledge } from './retrieval.js';
2
+ import { assertExplicitKnowledgeNoteReferenceRequest, assertExplicitKnowledgeNoteRequest } from './tool-authorization.js';
3
+ import { optionalToolInteger, requiredToolString, requireToolAgent, toolRecord } from './tool-input.js';
4
+ const textOutput = {
5
+ schema: { type: 'string' },
6
+ render: (_args, value) => [{ type: 'text', text: String(value) }],
7
+ };
8
+ export function registerKnowledgeNoteReferenceTools(ctx, provider, knowledgeCodec, noteCodec) {
9
+ ctx.tools.register(searchNotesTool(provider, noteCodec));
10
+ ctx.tools.register(manageNoteReferencesTool(provider, knowledgeCodec, noteCodec));
11
+ }
12
+ function searchNotesTool(provider, codec) {
13
+ return {
14
+ name: 'knowledge_note_search',
15
+ description: 'Search note-document and editable-file metadata when the current user explicitly asks to inspect, edit, organize, or reference notes. This never reads note content. Pass exact returned handles to knowledge_note_read/update/move/delete or knowledge_note_references; never invent a handle.',
16
+ parameters: {
17
+ type: 'object', additionalProperties: false,
18
+ properties: {
19
+ query: { type: 'string', description: 'A focused note filename or title query.' },
20
+ limit: { type: 'integer', description: 'Maximum results, default 10 and maximum 20.' },
21
+ },
22
+ required: ['query'],
23
+ },
24
+ output: textOutput,
25
+ isConcurrencySafe: () => true,
26
+ async execute(raw, exec) {
27
+ const agent = requireToolAgent(exec, 'knowledge note tools');
28
+ assertExplicitKnowledgeNoteRequest(agent, 'inspect');
29
+ const args = toolRecord(raw);
30
+ const query = requiredToolString(args.query, 'query', 1000);
31
+ const limit = optionalToolInteger(args.limit, 'limit', 1, 20) ?? 10;
32
+ const notes = await provider.searchNotes(query, limit, exec.signal);
33
+ if (notes.length === 0)
34
+ return `No note document matches ${JSON.stringify(query)}.`;
35
+ return [
36
+ `${notes.length} note document(s) match ${JSON.stringify(query)} (metadata only):`,
37
+ ...notes.map(note => `- ${note.name} (${note.kind === 'document' ? 'note document' : note.mediaType ?? 'file'}, handle: ${codec.encode(agent.session.id, note.id)})`),
38
+ ].join('\n');
39
+ },
40
+ };
41
+ }
42
+ function manageNoteReferencesTool(provider, knowledgeCodec, noteCodec) {
43
+ return {
44
+ name: 'knowledge_note_references',
45
+ description: 'Inspect, add, or remove the structured note references of one knowledge document only when the current user explicitly asks. The knowledge handle must come from knowledge_search and note handles from knowledge_note_search or this tool. References are metadata relationships and never modify the Markdown body. Add/remove requires a currently writable mounted knowledge base and an open document.',
46
+ parameters: {
47
+ type: 'object', additionalProperties: false,
48
+ properties: {
49
+ knowledgeHandle: { type: 'string', description: 'Exact signed knowledge handle returned by knowledge_search.' },
50
+ operation: { type: 'string', enum: ['list', 'add', 'remove'] },
51
+ noteHandles: { type: 'array', items: { type: 'string' }, maxItems: 16, description: 'Exact note handles. Required for add/remove; omitted for list.' },
52
+ },
53
+ required: ['knowledgeHandle', 'operation'],
54
+ },
55
+ output: textOutput,
56
+ isConcurrencySafe: args => toolRecord(args).operation === 'list',
57
+ async execute(raw, exec) {
58
+ const agent = requireToolAgent(exec, 'knowledge note tools');
59
+ const args = toolRecord(raw);
60
+ const operation = parseOperation(args.operation);
61
+ assertExplicitKnowledgeNoteReferenceRequest(agent, operation === 'list' ? 'inspect' : operation);
62
+ const knowledgeHandle = requiredToolString(args.knowledgeHandle, 'knowledgeHandle', 4096);
63
+ const { entry, mount } = await readMountedKnowledge(provider, agent, knowledgeHandle, knowledgeCodec, exec.signal);
64
+ if (operation !== 'list' && mount.writeMode === 'none') {
65
+ throw new Error('the knowledge document is mounted read-only in this session');
66
+ }
67
+ const noteHandles = parseNoteHandles(args.noteHandles, operation);
68
+ const noteIds = [...new Set(noteHandles.map(handle => noteCodec.decode(handle, agent.session.id).noteId))];
69
+ let changed = 0;
70
+ if (operation === 'add') {
71
+ const before = new Set((await provider.listKnowledgeNoteReferences(entry.id, exec.signal)).map(reference => reference.note.id));
72
+ for (const noteId of noteIds) {
73
+ await provider.addKnowledgeNoteReference(entry.id, noteId, 'agent', agent.session.id, exec.signal);
74
+ if (!before.has(noteId))
75
+ changed += 1;
76
+ }
77
+ }
78
+ if (operation === 'remove') {
79
+ const current = new Set((await provider.listKnowledgeNoteReferences(entry.id, exec.signal)).map(reference => reference.note.id));
80
+ for (const noteId of noteIds) {
81
+ if (!current.has(noteId))
82
+ continue;
83
+ await provider.deleteKnowledgeNoteReference(entry.id, noteId, exec.signal);
84
+ changed += 1;
85
+ }
86
+ }
87
+ const references = await provider.listKnowledgeNoteReferences(entry.id, exec.signal);
88
+ return JSON.stringify({
89
+ storage: provider.mode,
90
+ operation,
91
+ changed,
92
+ knowledgeDocument: { id: entry.id, title: entry.title, knowledgeBaseId: entry.knowledgeBaseId },
93
+ references: references.map(reference => ({
94
+ name: reference.note.name,
95
+ kind: reference.note.kind,
96
+ mediaType: reference.note.mediaType,
97
+ handle: noteCodec.encode(agent.session.id, reference.note.id),
98
+ })),
99
+ }, null, 2);
100
+ },
101
+ };
102
+ }
103
+ function parseOperation(value) {
104
+ if (value !== 'list' && value !== 'add' && value !== 'remove')
105
+ throw new Error('operation must be list, add, or remove');
106
+ return value;
107
+ }
108
+ function parseNoteHandles(value, operation) {
109
+ if (operation === 'list') {
110
+ if (value !== undefined)
111
+ throw new Error('noteHandles must be omitted when operation is list');
112
+ return [];
113
+ }
114
+ if (!Array.isArray(value) || value.length === 0 || value.length > 16) {
115
+ throw new Error('noteHandles must contain 1-16 signed handles for add/remove');
116
+ }
117
+ return value.map((handle, index) => requiredToolString(handle, `noteHandles[${index}]`, 4096));
118
+ }
119
+ //# sourceMappingURL=note-reference-tools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"note-reference-tools.js","sourceRoot":"","sources":["../src/note-reference-tools.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAA6B,MAAM,gBAAgB,CAAA;AAGhF,OAAO,EAAE,2CAA2C,EAAE,kCAAkC,EAAE,MAAM,yBAAyB,CAAA;AACzH,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAEvG,MAAM,UAAU,GAAG;IACjB,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;IAC1B,MAAM,EAAE,CAAC,KAAc,EAAE,KAAc,EAAE,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,CAAC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,GAAG,EAAE,EAAE,CAAC;QACrE,MAAM,IAAI,KAAK,CAAC,6DAA6D,CAAC,CAAA;IAChF,CAAC;IACD,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC,kBAAkB,CAAC,MAAM,EAAE,eAAe,KAAK,GAAG,EAAE,IAAI,CAAC,CAAC,CAAA;AAChG,CAAC"}
@@ -0,0 +1,6 @@
1
+ import type { KnowledgeProvider } from './provider.js';
2
+ import { KnowledgeNoteHandleCodec } from './note-reference-handle.js';
3
+ import type { RuntimeContextLike } from './runtime.js';
4
+ /** AI-facing note workspace operations. Every mutation requires a direct user request and signed session handles. */
5
+ export declare function registerKnowledgeNoteTools(ctx: RuntimeContextLike, provider: KnowledgeProvider, codec: KnowledgeNoteHandleCodec): void;
6
+ //# sourceMappingURL=note-tools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"note-tools.d.ts","sourceRoot":"","sources":["../src/note-tools.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AAEtD,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAA;AACrE,OAAO,KAAK,EAAE,kBAAkB,EAA0C,MAAM,cAAc,CAAA;AAW9F,qHAAqH;AACrH,wBAAgB,0BAA0B,CACxC,GAAG,EAAE,kBAAkB,EACvB,QAAQ,EAAE,iBAAiB,EAC3B,KAAK,EAAE,wBAAwB,GAC9B,IAAI,CAON"}
@@ -0,0 +1,283 @@
1
+ import { assertExplicitKnowledgeNoteRequest } from './tool-authorization.js';
2
+ import { optionalToolInteger, requiredToolString, requireToolAgent, toolRecord } from './tool-input.js';
3
+ const MAX_TOOL_NOTE_CONTENT = 200_000;
4
+ const textOutput = {
5
+ schema: { type: 'string' },
6
+ render: (_args, value) => [{ type: 'text', text: String(value) }],
7
+ };
8
+ /** AI-facing note workspace operations. Every mutation requires a direct user request and signed session handles. */
9
+ export function registerKnowledgeNoteTools(ctx, provider, codec) {
10
+ ctx.tools.register(listNotesTool(provider, codec));
11
+ ctx.tools.register(readNoteTool(provider, codec));
12
+ ctx.tools.register(createNoteTool(provider, codec));
13
+ ctx.tools.register(updateNoteTool(provider, codec));
14
+ ctx.tools.register(moveNoteTool(provider, codec));
15
+ ctx.tools.register(deleteNoteTool(provider, codec));
16
+ }
17
+ function listNotesTool(provider, codec) {
18
+ return {
19
+ name: 'knowledge_note_list',
20
+ description: 'Browse one folder in the independent note workspace, or search note and folder names. Use this when the user explicitly asks to inspect, create, organize, or edit notes. Omit folderHandle to browse the root. Handles are session-bound; pass exact returned handles to other knowledge_note tools.',
21
+ parameters: {
22
+ type: 'object', additionalProperties: false,
23
+ properties: {
24
+ folderHandle: { type: 'string', description: 'Exact signed folder handle returned by this tool. Omit for the note-workspace root.' },
25
+ query: { type: 'string', description: 'Optional name search across the whole note workspace. Cannot be combined with folderHandle.' },
26
+ limit: { type: 'integer', description: 'Maximum results, default 50 and maximum 100.' },
27
+ },
28
+ },
29
+ output: textOutput,
30
+ isConcurrencySafe: () => true,
31
+ async execute(raw, exec) {
32
+ const agent = requireToolAgent(exec, 'knowledge note tools');
33
+ assertExplicitKnowledgeNoteRequest(agent, 'inspect');
34
+ const args = toolRecord(raw);
35
+ const query = optionalText(args.query, 'query', 1000);
36
+ const folderHandle = optionalText(args.folderHandle, 'folderHandle', 4096);
37
+ if (query !== undefined && folderHandle !== undefined)
38
+ throw new Error('query and folderHandle cannot be combined');
39
+ const limit = optionalToolInteger(args.limit, 'limit', 1, 100) ?? 50;
40
+ let parentId = null;
41
+ let folder;
42
+ if (folderHandle !== undefined) {
43
+ folder = await resolveNoteHandle(provider, codec, agent.session.id, folderHandle, exec.signal);
44
+ if (folder.kind !== 'folder')
45
+ throw new Error('folderHandle must identify a note folder');
46
+ parentId = folder.id;
47
+ }
48
+ const nodes = await provider.listNotes(query === undefined ? { parentId, limit } : { query, limit }, exec.signal);
49
+ return JSON.stringify({
50
+ storage: provider.mode,
51
+ scope: query === undefined ? { folder: folder?.name ?? 'root' } : { query },
52
+ items: nodes.map(node => noteView(node, codec.encode(agent.session.id, node.id))),
53
+ }, null, 2);
54
+ },
55
+ };
56
+ }
57
+ function readNoteTool(provider, codec) {
58
+ return {
59
+ name: 'knowledge_note_read',
60
+ description: 'Read a bounded chunk from an editable text or Markdown note after knowledge_note_list/search returned its exact handle. This never reads folders or binary attachments. Use offset and maxChars to continue long notes.',
61
+ parameters: {
62
+ type: 'object', additionalProperties: false,
63
+ properties: {
64
+ noteHandle: { type: 'string', description: 'Exact signed note handle returned by knowledge_note_list or knowledge_note_search.' },
65
+ offset: { type: 'integer', description: 'Character offset, default 0.' },
66
+ maxChars: { type: 'integer', description: 'Maximum returned characters, default 20000 and maximum 80000.' },
67
+ },
68
+ required: ['noteHandle'],
69
+ },
70
+ output: textOutput,
71
+ isConcurrencySafe: () => true,
72
+ async execute(raw, exec) {
73
+ const agent = requireToolAgent(exec, 'knowledge note tools');
74
+ assertExplicitKnowledgeNoteRequest(agent, 'inspect');
75
+ const args = toolRecord(raw);
76
+ const handle = requiredToolString(args.noteHandle, 'noteHandle', 4096);
77
+ const offset = optionalToolInteger(args.offset, 'offset', 0, 50_000_000) ?? 0;
78
+ const maxChars = optionalToolInteger(args.maxChars, 'maxChars', 1, 80_000) ?? 20_000;
79
+ const node = await resolveNoteHandle(provider, codec, agent.session.id, handle, exec.signal);
80
+ if (!node.editable || node.kind === 'folder')
81
+ throw new Error('knowledge_note_read only supports editable text and Markdown notes');
82
+ const { content } = await provider.readNote(node.id, exec.signal);
83
+ const text = decodeTextNote(content);
84
+ const chunk = text.slice(offset, offset + maxChars);
85
+ return JSON.stringify({
86
+ storage: provider.mode,
87
+ note: noteView(node, handle),
88
+ offset,
89
+ content: chunk,
90
+ nextOffset: offset + chunk.length < text.length ? offset + chunk.length : null,
91
+ totalChars: text.length,
92
+ }, null, 2);
93
+ },
94
+ };
95
+ }
96
+ function createNoteTool(provider, codec) {
97
+ return {
98
+ name: 'knowledge_note_create',
99
+ description: 'Create a Markdown note or folder in the active local or remote note workspace only when the current user explicitly asks. Omit parentFolderHandle to create at the root. The tool follows the active provider and never copies or synchronizes between local and remote storage.',
100
+ parameters: {
101
+ type: 'object', additionalProperties: false,
102
+ properties: {
103
+ kind: { type: 'string', enum: ['document', 'folder'] },
104
+ name: { type: 'string', description: 'Document title/filename or folder name.' },
105
+ parentFolderHandle: { type: 'string', description: 'Exact signed folder handle returned by knowledge_note_list. Omit for root.' },
106
+ content: { type: 'string', description: 'Initial Markdown content for a document. Omit for a folder.' },
107
+ },
108
+ required: ['kind', 'name'],
109
+ },
110
+ output: textOutput,
111
+ async execute(raw, exec) {
112
+ const agent = requireToolAgent(exec, 'knowledge note tools');
113
+ assertExplicitKnowledgeNoteRequest(agent, 'create');
114
+ const args = toolRecord(raw);
115
+ const kind = noteKind(args.kind);
116
+ const name = requiredToolString(args.name, 'name', 255);
117
+ const content = optionalContent(args.content, 'content') ?? '';
118
+ if (kind === 'folder' && args.content !== undefined)
119
+ throw new Error('content must be omitted when creating a folder');
120
+ const parentId = await resolveOptionalFolderId(provider, codec, agent.session.id, args.parentFolderHandle, 'parentFolderHandle', exec.signal);
121
+ const node = kind === 'folder'
122
+ ? await provider.createNoteFolder(name, parentId, exec.signal)
123
+ : await provider.createNoteDocument(name, parentId, content, exec.signal);
124
+ return mutationResult(provider, 'created', node, codec.encode(agent.session.id, node.id));
125
+ },
126
+ };
127
+ }
128
+ function updateNoteTool(provider, codec) {
129
+ return {
130
+ name: 'knowledge_note_update',
131
+ description: 'Rename or change one existing note only when the user explicitly asks. Use an exact signed handle. replace_content replaces the complete body; append_content preserves the existing body and appends value exactly; rename changes only the visible name.',
132
+ parameters: {
133
+ type: 'object', additionalProperties: false,
134
+ properties: {
135
+ noteHandle: { type: 'string', description: 'Exact signed handle returned by knowledge_note_list or knowledge_note_search.' },
136
+ operation: { type: 'string', enum: ['rename', 'replace_content', 'append_content'] },
137
+ value: { type: 'string', description: 'New name or content, according to operation.' },
138
+ },
139
+ required: ['noteHandle', 'operation', 'value'],
140
+ },
141
+ output: textOutput,
142
+ async execute(raw, exec) {
143
+ const agent = requireToolAgent(exec, 'knowledge note tools');
144
+ assertExplicitKnowledgeNoteRequest(agent, 'update');
145
+ const args = toolRecord(raw);
146
+ const handle = requiredToolString(args.noteHandle, 'noteHandle', 4096);
147
+ const operation = updateOperation(args.operation);
148
+ const node = await resolveNoteHandle(provider, codec, agent.session.id, handle, exec.signal);
149
+ let updated;
150
+ if (operation === 'rename') {
151
+ updated = await provider.renameNote(node.id, requiredToolString(args.value, 'value', 255), exec.signal);
152
+ }
153
+ else {
154
+ if (!node.editable || node.kind === 'folder')
155
+ throw new Error('only editable text and Markdown notes support content updates');
156
+ const value = requiredContent(args.value, 'value');
157
+ const content = operation === 'append_content'
158
+ ? `${decodeTextNote((await provider.readNote(node.id, exec.signal)).content)}${value}`
159
+ : value;
160
+ updated = await provider.updateNoteContent(node.id, new TextEncoder().encode(content), exec.signal);
161
+ }
162
+ return mutationResult(provider, 'updated', updated, codec.encode(agent.session.id, updated.id));
163
+ },
164
+ };
165
+ }
166
+ function moveNoteTool(provider, codec) {
167
+ return {
168
+ name: 'knowledge_note_move',
169
+ description: 'Move a note or folder only when the user explicitly asks. Use exact signed handles. Omit targetFolderHandle to move the item to the note-workspace root.',
170
+ parameters: {
171
+ type: 'object', additionalProperties: false,
172
+ properties: {
173
+ noteHandle: { type: 'string' },
174
+ targetFolderHandle: { type: 'string', description: 'Exact destination-folder handle; omit for root.' },
175
+ },
176
+ required: ['noteHandle'],
177
+ },
178
+ output: textOutput,
179
+ async execute(raw, exec) {
180
+ const agent = requireToolAgent(exec, 'knowledge note tools');
181
+ assertExplicitKnowledgeNoteRequest(agent, 'move');
182
+ const args = toolRecord(raw);
183
+ const handle = requiredToolString(args.noteHandle, 'noteHandle', 4096);
184
+ const node = await resolveNoteHandle(provider, codec, agent.session.id, handle, exec.signal);
185
+ const parentId = await resolveOptionalFolderId(provider, codec, agent.session.id, args.targetFolderHandle, 'targetFolderHandle', exec.signal);
186
+ const moved = await provider.moveNote(node.id, parentId, exec.signal);
187
+ return mutationResult(provider, 'moved', moved, codec.encode(agent.session.id, moved.id));
188
+ },
189
+ };
190
+ }
191
+ function deleteNoteTool(provider, codec) {
192
+ return {
193
+ name: 'knowledge_note_delete',
194
+ description: 'Permanently delete one note or folder only when the current user explicitly asks. Requires an exact signed handle. Referenced notes are protected; remote deletion also requires an admin-capable token.',
195
+ parameters: {
196
+ type: 'object', additionalProperties: false,
197
+ properties: { noteHandle: { type: 'string', description: 'Exact signed handle returned by knowledge_note_list or knowledge_note_search.' } },
198
+ required: ['noteHandle'],
199
+ },
200
+ output: textOutput,
201
+ async execute(raw, exec) {
202
+ const agent = requireToolAgent(exec, 'knowledge note tools');
203
+ assertExplicitKnowledgeNoteRequest(agent, 'delete');
204
+ const args = toolRecord(raw);
205
+ const handle = requiredToolString(args.noteHandle, 'noteHandle', 4096);
206
+ const node = await resolveNoteHandle(provider, codec, agent.session.id, handle, exec.signal);
207
+ await provider.deleteNote(node.id, exec.signal);
208
+ return JSON.stringify({ storage: provider.mode, operation: 'deleted', note: { name: node.name, kind: node.kind } }, null, 2);
209
+ },
210
+ };
211
+ }
212
+ async function resolveNoteHandle(provider, codec, sessionId, handle, signal) {
213
+ const { noteId } = codec.decode(handle, sessionId);
214
+ const node = await provider.getNote(noteId, signal);
215
+ if (node === undefined)
216
+ throw new Error('the note handle points to a note that no longer exists');
217
+ return node;
218
+ }
219
+ async function resolveOptionalFolderId(provider, codec, sessionId, value, label, signal) {
220
+ if (value === undefined)
221
+ return null;
222
+ const handle = requiredToolString(value, label, 4096);
223
+ const node = await resolveNoteHandle(provider, codec, sessionId, handle, signal);
224
+ if (node.kind !== 'folder')
225
+ throw new Error('the parent handle must identify a note folder');
226
+ return node.id;
227
+ }
228
+ function noteView(node, handle) {
229
+ return {
230
+ handle,
231
+ name: node.name,
232
+ kind: node.kind,
233
+ mediaType: node.mediaType,
234
+ editable: node.editable,
235
+ size: node.size,
236
+ updatedAt: node.updatedAt,
237
+ };
238
+ }
239
+ function mutationResult(provider, operation, node, handle) {
240
+ return JSON.stringify({ storage: provider.mode, operation, note: noteView(node, handle) }, null, 2);
241
+ }
242
+ function optionalText(value, name, maxLength) {
243
+ if (value === undefined)
244
+ return undefined;
245
+ return requiredToolString(value, name, maxLength);
246
+ }
247
+ function optionalContent(value, name) {
248
+ if (value === undefined)
249
+ return undefined;
250
+ return noteContent(value, name);
251
+ }
252
+ function requiredContent(value, name) {
253
+ if (typeof value !== 'string')
254
+ throw new Error(`${name} must be a string`);
255
+ return noteContent(value, name);
256
+ }
257
+ function noteContent(value, name) {
258
+ if (typeof value !== 'string')
259
+ throw new Error(`${name} must be a string`);
260
+ if (value.length > MAX_TOOL_NOTE_CONTENT)
261
+ throw new Error(`${name} must contain at most ${MAX_TOOL_NOTE_CONTENT} characters`);
262
+ return value;
263
+ }
264
+ function noteKind(value) {
265
+ if (value !== 'document' && value !== 'folder')
266
+ throw new Error('kind must be document or folder');
267
+ return value;
268
+ }
269
+ function updateOperation(value) {
270
+ if (value !== 'rename' && value !== 'replace_content' && value !== 'append_content') {
271
+ throw new Error('operation must be rename, replace_content, or append_content');
272
+ }
273
+ return value;
274
+ }
275
+ function decodeTextNote(content) {
276
+ try {
277
+ return new TextDecoder('utf-8', { fatal: true }).decode(content);
278
+ }
279
+ catch {
280
+ throw new Error('the note content is not valid UTF-8 text');
281
+ }
282
+ }
283
+ //# sourceMappingURL=note-tools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"note-tools.js","sourceRoot":"","sources":["../src/note-tools.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,kCAAkC,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,gBAAgB,EAA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AAC;AACH,CAAC"}
@@ -0,0 +1,44 @@
1
+ export type NoteNodeKind = 'folder' | 'document' | 'file';
2
+ export interface NoteNode {
3
+ id: string;
4
+ parentId: string | null;
5
+ kind: NoteNodeKind;
6
+ name: string;
7
+ mediaType: string | null;
8
+ editable: boolean;
9
+ size: number;
10
+ sha256: string | null;
11
+ createdAt: string;
12
+ updatedAt: string;
13
+ }
14
+ export interface NoteReference {
15
+ noteId: string;
16
+ knowledgeBaseId: string;
17
+ documentId: string;
18
+ documentTitle: string;
19
+ }
20
+ export type KnowledgeNoteReferenceSource = 'user' | 'agent' | 'legacy';
21
+ export interface KnowledgeNoteReference {
22
+ knowledgeId: string;
23
+ knowledgeBaseId: string;
24
+ documentTitle: string;
25
+ note: NoteNode;
26
+ source: KnowledgeNoteReferenceSource;
27
+ sourceSessionId?: string;
28
+ createdAt: string;
29
+ }
30
+ export interface NoteListRequest {
31
+ parentId?: string | null;
32
+ query?: string;
33
+ limit?: number;
34
+ }
35
+ export interface NoteFileUpload {
36
+ parentId?: string | null;
37
+ name: string;
38
+ mediaType: string;
39
+ content: Uint8Array;
40
+ }
41
+ export declare function isNoteId(value: string): boolean;
42
+ export declare function isEditableNoteNode(node: Pick<NoteNode, 'kind' | 'name' | 'mediaType'>): boolean;
43
+ export declare function noteReferenceMarkdown(node: Pick<NoteNode, 'id' | 'name'>): string;
44
+ //# sourceMappingURL=domain.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"domain.d.ts","sourceRoot":"","sources":["../../src/notes/domain.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,UAAU,GAAG,MAAM,CAAA;AAEzD,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAA;IACV,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,IAAI,EAAE,YAAY,CAAA;IAClB,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;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AC,GAAG,MAAM,CAEjF"}
@@ -0,0 +1,38 @@
1
+ const EDITABLE_NOTE_MEDIA_TYPES = new Set([
2
+ 'application/json',
3
+ 'application/ld+json',
4
+ 'application/toml',
5
+ 'application/xml',
6
+ 'application/x-javascript',
7
+ 'application/x-yaml',
8
+ 'application/yaml',
9
+ ]);
10
+ const EDITABLE_NOTE_EXTENSIONS = new Set([
11
+ 'bash', 'c', 'cjs', 'conf', 'cpp', 'css', 'csv', 'env', 'fish', 'go', 'h', 'hpp',
12
+ 'htm', 'html', 'ini', 'java', 'js', 'json', 'jsonc', 'jsx', 'less', 'log', 'markdown',
13
+ 'md', 'mjs', 'properties', 'py', 'rb', 'rs', 'scss', 'sh', 'sql', 'svelte', 'toml',
14
+ 'ts', 'tsv', 'tsx', 'txt', 'vue', 'xml', 'yaml', 'yml', 'zsh',
15
+ ]);
16
+ const NOTE_ID_PATTERN = /^note_[a-f0-9]{32}$/;
17
+ export function isNoteId(value) {
18
+ return NOTE_ID_PATTERN.test(value);
19
+ }
20
+ export function isEditableNoteNode(node) {
21
+ if (node.kind === 'document')
22
+ return true;
23
+ if (node.kind !== 'file')
24
+ return false;
25
+ const mediaType = node.mediaType?.toLocaleLowerCase() ?? '';
26
+ if (mediaType.startsWith('text/') || EDITABLE_NOTE_MEDIA_TYPES.has(mediaType))
27
+ return true;
28
+ const name = node.name.toLocaleLowerCase();
29
+ const dot = name.lastIndexOf('.');
30
+ return EDITABLE_NOTE_EXTENSIONS.has(dot >= 0 ? name.slice(dot + 1) : name);
31
+ }
32
+ export function noteReferenceMarkdown(node) {
33
+ return `@[${escapeMarkdownLabel(node.name)}](note://${node.id})`;
34
+ }
35
+ function escapeMarkdownLabel(value) {
36
+ return value.replaceAll('\\', '\\\\').replaceAll('[', '\\[').replaceAll(']', '\\]');
37
+ }
38
+ //# sourceMappingURL=domain.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"domain.js","sourceRoot":"","sources":["../../src/notes/domain.ts"],"names":[],"mapp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S,CAAC;QAAE,OAAO,IAAI,CAAA;IAC1F,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAA;IAC1C,MAAM,GAAG,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAA;IACjC,OAAO,wBAAwB,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAA;AAC5E,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,IAAmC;IACvE,OAAO,KAAK,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,IAAI,CAAC,EAAE,GAAG,CAAA;AAClE,CAAC;AAED,SAAS,mBAAmB,CAAC,KAAa;IACxC,OAAO,KAAK,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;AACrF,CAAC"}
@@ -0,0 +1,39 @@
1
+ import { type NoteFileUpload, type NoteListRequest, type NoteNode } from './domain.js';
2
+ export declare class NoteStore {
3
+ private readonly rootPath;
4
+ private readonly removeOnClose;
5
+ private readonly db;
6
+ private readonly objectsPath;
7
+ private closed;
8
+ constructor(rootPath: string, removeOnClose?: boolean);
9
+ list(request?: NoteListRequest): NoteNode[];
10
+ get(id: string): NoteNode | undefined;
11
+ subtree(id: string): NoteNode[];
12
+ createFolder(name: string, parentId?: string | null): Promise<NoteNode>;
13
+ createDocument(name: string, parentId?: string | null, content?: string): Promise<NoteNode>;
14
+ upload(upload: NoteFileUpload): Promise<NoteNode>;
15
+ read(id: string): Promise<{
16
+ node: NoteNode;
17
+ content: Buffer;
18
+ }>;
19
+ updateContent(id: string, content: Uint8Array): Promise<NoteNode>;
20
+ rename(id: string, name: string): NoteNode;
21
+ move(id: string, parentId: string | null): NoteNode;
22
+ copy(id: string, parentId?: string | null, requestedName?: string): Promise<NoteNode>;
23
+ delete(id: string): Promise<void>;
24
+ close(): Promise<void>;
25
+ private createNode;
26
+ private copyNode;
27
+ private availableCopyName;
28
+ private requireNode;
29
+ private children;
30
+ private assertFolder;
31
+ private assertNameAvailable;
32
+ private nameExists;
33
+ private isDescendant;
34
+ private migrate;
35
+ private objectPath;
36
+ private assertOpen;
37
+ }
38
+ export declare function normalizeNoteName(value: string): string;
39
+ //# sourceMappingURL=store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/notes/store.ts"],"names":[],"mappings":"AAMA,OAAO,EAGL,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,QAAQ,EAEd,MAAM,aAAa,CAAA;AAOpB,qBAAa,SAAS;IAKR,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAAU,OAAO,CAAC,QAAQ,CAAC,aAAa;IAJ7E,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAc;IACjC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAQ;IACpC,OAAO,CAAC,MAAM,CAAQ;gBAEO,QAAQ,EAAE,MAAM,EAAmB,aAAa,UAAQ;IAQrF,IAAI,CAAC,OAAO,GAAE,eAAoB,GAAG,QAAQ,EAAE;IAwB/C,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS;IAOrC,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,QAAQ,EAAE;IAezB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAM,GAAG,IAAW,GAAG,OAAO,CAAC,QAAQ,CAAC;IAI7E,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAM,GAAG,IAAW,EAAE,OAAO,SAAK,GAAG,OAAO,CAAC,QAAQ,CAAC;IAK7F,MAAM,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,QA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