scrivener-mcp 0.1.4
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/LICENSE +21 -0
- package/README.md +109 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +796 -0
- package/dist/index.js.map +1 -0
- package/dist/rtf-handler.d.ts +121 -0
- package/dist/rtf-handler.d.ts.map +1 -0
- package/dist/rtf-handler.js +583 -0
- package/dist/rtf-handler.js.map +1 -0
- package/dist/scrivener-project.d.ts +199 -0
- package/dist/scrivener-project.d.ts.map +1 -0
- package/dist/scrivener-project.js +855 -0
- package/dist/scrivener-project.js.map +1 -0
- package/dist/types/internal.d.ts +86 -0
- package/dist/types/internal.d.ts.map +1 -0
- package/dist/types/internal.js +7 -0
- package/dist/types/internal.js.map +1 -0
- package/package.json +82 -0
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import type { RTFContent } from './rtf-handler.js';
|
|
2
|
+
export interface ScrivenerDocument {
|
|
3
|
+
id: string;
|
|
4
|
+
title: string;
|
|
5
|
+
type: 'Text' | 'Folder' | 'Other';
|
|
6
|
+
path: string;
|
|
7
|
+
content?: string;
|
|
8
|
+
synopsis?: string;
|
|
9
|
+
notes?: string;
|
|
10
|
+
label?: string;
|
|
11
|
+
status?: string;
|
|
12
|
+
includeInCompile?: boolean;
|
|
13
|
+
children?: ScrivenerDocument[];
|
|
14
|
+
customMetadata?: Record<string, string>;
|
|
15
|
+
keywords?: string[];
|
|
16
|
+
}
|
|
17
|
+
export interface ScrivenerMetadata {
|
|
18
|
+
title?: string;
|
|
19
|
+
author?: string;
|
|
20
|
+
keywords?: string[];
|
|
21
|
+
projectTargets?: {
|
|
22
|
+
draft?: number;
|
|
23
|
+
session?: number;
|
|
24
|
+
deadline?: string;
|
|
25
|
+
};
|
|
26
|
+
customFields?: Record<string, string>;
|
|
27
|
+
}
|
|
28
|
+
export declare class ScrivenerProject {
|
|
29
|
+
private projectPath;
|
|
30
|
+
private scrivxPath;
|
|
31
|
+
private projectStructure?;
|
|
32
|
+
private rtfHandler;
|
|
33
|
+
private documentCache;
|
|
34
|
+
private cacheTimestamps;
|
|
35
|
+
/**
|
|
36
|
+
* Constructs a new ScrivenerProject instance.
|
|
37
|
+
* @param projectPath The absolute path to the `.scriv` project directory.
|
|
38
|
+
*/
|
|
39
|
+
constructor(projectPath: string);
|
|
40
|
+
/**
|
|
41
|
+
* Loads the Scrivener project's main `.scrivx` file into memory.
|
|
42
|
+
* @throws {Error} If the project file cannot be read or parsed.
|
|
43
|
+
*/
|
|
44
|
+
loadProject(): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Saves the current project structure back to the `.scrivx` file.
|
|
47
|
+
* @throws {Error} If no project is currently loaded.
|
|
48
|
+
*/
|
|
49
|
+
saveProject(): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Retrieves the hierarchical structure of the entire project binder.
|
|
52
|
+
* @returns A promise that resolves to an array of ScrivenerDocument objects.
|
|
53
|
+
*/
|
|
54
|
+
getProjectStructure(): Promise<ScrivenerDocument[]>;
|
|
55
|
+
/**
|
|
56
|
+
* Reads the plain text content of a specific document.
|
|
57
|
+
* Uses caching to improve performance for repeated reads.
|
|
58
|
+
* @param documentId The UUID of the document.
|
|
59
|
+
* @returns A promise that resolves to the document's plain text content.
|
|
60
|
+
* @throws {Error} If the document file cannot be read.
|
|
61
|
+
*/
|
|
62
|
+
readDocument(documentId: string): Promise<string>;
|
|
63
|
+
/**
|
|
64
|
+
* Reads the rich text formatted content of a specific document.
|
|
65
|
+
* Uses caching to improve performance for repeated reads.
|
|
66
|
+
* Cache entries expire after 5 minutes to balance performance with freshness.
|
|
67
|
+
* @param documentId The UUID of the document.
|
|
68
|
+
* @returns A promise that resolves to an RTFContent object.
|
|
69
|
+
* @throws {Error} If the document file cannot be read.
|
|
70
|
+
*/
|
|
71
|
+
readDocumentFormatted(documentId: string): Promise<RTFContent>;
|
|
72
|
+
/**
|
|
73
|
+
* Writes content to a specific document.
|
|
74
|
+
* Invalidates the cache for the modified document.
|
|
75
|
+
* @param documentId The UUID of the document.
|
|
76
|
+
* @param content The plain text or RTFContent object to write.
|
|
77
|
+
* @throws {Error} If the document file cannot be written.
|
|
78
|
+
*/
|
|
79
|
+
writeDocument(documentId: string, content: string | RTFContent): Promise<void>;
|
|
80
|
+
/**
|
|
81
|
+
* Creates a new document or folder and adds it to the project.
|
|
82
|
+
* @param parentId The UUID of the parent folder, or null to add to the root.
|
|
83
|
+
* @param title The title of the new item.
|
|
84
|
+
* @param type The type of item to create ('Text' or 'Folder').
|
|
85
|
+
* @returns A promise that resolves to the UUID of the newly created item.
|
|
86
|
+
* @throws {Error} If the parent document is not found.
|
|
87
|
+
*/
|
|
88
|
+
createDocument(parentId: string | null, title: string, type?: 'Text' | 'Folder'): Promise<string>;
|
|
89
|
+
/**
|
|
90
|
+
* Deletes a document or folder from the project.
|
|
91
|
+
* @param documentId The UUID of the item to delete.
|
|
92
|
+
* @throws {Error} If the document is not found.
|
|
93
|
+
*/
|
|
94
|
+
deleteDocument(documentId: string): Promise<void>;
|
|
95
|
+
/**
|
|
96
|
+
* Renames a document in the binder.
|
|
97
|
+
* @param documentId The UUID of the document to rename.
|
|
98
|
+
* @param newTitle The new title for the document.
|
|
99
|
+
* @throws {Error} If the document is not found.
|
|
100
|
+
*/
|
|
101
|
+
renameDocument(documentId: string, newTitle: string): Promise<void>;
|
|
102
|
+
/**
|
|
103
|
+
* Moves a document or folder to a new parent folder.
|
|
104
|
+
* @param documentId The UUID of the item to move.
|
|
105
|
+
* @param newParentId The UUID of the new parent folder, or null to move to the root.
|
|
106
|
+
* @throws {Error} If the document or new parent is not found.
|
|
107
|
+
*/
|
|
108
|
+
moveDocument(documentId: string, newParentId: string | null): Promise<void>;
|
|
109
|
+
/**
|
|
110
|
+
* Refreshes the in-memory project state by reloading the .scrivx file.
|
|
111
|
+
* WARNING: This will overwrite any unsaved in-memory changes.
|
|
112
|
+
* Also clears the document cache to ensure fresh reads.
|
|
113
|
+
*/
|
|
114
|
+
refreshProject(): Promise<void>;
|
|
115
|
+
/**
|
|
116
|
+
* Checks if the project file has been modified since last load.
|
|
117
|
+
* @returns True if the project file has been modified externally.
|
|
118
|
+
*/
|
|
119
|
+
isProjectModified(): Promise<boolean>;
|
|
120
|
+
/**
|
|
121
|
+
* Clears the document cache for a specific document or all documents.
|
|
122
|
+
* @param documentId Optional document ID to clear. If not provided, clears all.
|
|
123
|
+
*/
|
|
124
|
+
clearCache(documentId?: string): void;
|
|
125
|
+
/**
|
|
126
|
+
* Updates the metadata for a specific document.
|
|
127
|
+
* @param documentId The UUID of the document.
|
|
128
|
+
* @param metadata The partial metadata object to update.
|
|
129
|
+
* @throws {Error} If the document is not found.
|
|
130
|
+
*/
|
|
131
|
+
updateMetadata(documentId: string, metadata: Partial<ScrivenerMetadata>): Promise<void>;
|
|
132
|
+
/**
|
|
133
|
+
* Retrieves the combined word and character count for a specific document or the entire project.
|
|
134
|
+
* @param documentId The UUID of the document. If not provided, the entire project is counted.
|
|
135
|
+
* @returns An object with `words` and `characters` counts.
|
|
136
|
+
*/
|
|
137
|
+
getWordCount(documentId?: string): Promise<{
|
|
138
|
+
words: number;
|
|
139
|
+
characters: number;
|
|
140
|
+
}>;
|
|
141
|
+
/**
|
|
142
|
+
* Compiles the content of multiple documents into a single string or formatted object.
|
|
143
|
+
* @param documentIds An array of UUIDs for the documents to compile.
|
|
144
|
+
* @param separator The string to use between documents.
|
|
145
|
+
* @param outputFormat The desired output format ('text', 'markdown', or 'html').
|
|
146
|
+
* @returns A promise that resolves to the compiled content.
|
|
147
|
+
*/
|
|
148
|
+
compileDocuments(documentIds: string[], separator?: string, outputFormat?: 'text' | 'markdown' | 'html' | 'latex' | 'json'): Promise<string | RTFContent>;
|
|
149
|
+
searchContent(query: string, options?: {
|
|
150
|
+
caseSensitive?: boolean;
|
|
151
|
+
regex?: boolean;
|
|
152
|
+
searchMetadata?: boolean;
|
|
153
|
+
}): Promise<Array<{
|
|
154
|
+
documentId: string;
|
|
155
|
+
title: string;
|
|
156
|
+
matches: string[];
|
|
157
|
+
}>>;
|
|
158
|
+
private findMatches;
|
|
159
|
+
private parseBinderItems;
|
|
160
|
+
private parseBinderItem;
|
|
161
|
+
private getDocumentPath;
|
|
162
|
+
/**
|
|
163
|
+
* Helper function to safely add an item to a BinderContainer
|
|
164
|
+
*/
|
|
165
|
+
private addToBinderContainer;
|
|
166
|
+
/**
|
|
167
|
+
* Helper function to find a binder item by its UUID.
|
|
168
|
+
*/
|
|
169
|
+
private findBinderItem;
|
|
170
|
+
/**
|
|
171
|
+
* Helper function to extract and return a binder item by its UUID,
|
|
172
|
+
* removing it from its current location.
|
|
173
|
+
*/
|
|
174
|
+
private extractBinderItem;
|
|
175
|
+
/**
|
|
176
|
+
* Helper function to delete a binder item by its UUID.
|
|
177
|
+
*/
|
|
178
|
+
private deleteBinderItem;
|
|
179
|
+
/**
|
|
180
|
+
* Helper function to get a flat list of all documents in the project.
|
|
181
|
+
*/
|
|
182
|
+
getAllDocuments(): Promise<ScrivenerDocument[]>;
|
|
183
|
+
/**
|
|
184
|
+
* Helper function to update the modification date of an item.
|
|
185
|
+
*/
|
|
186
|
+
private updateModifiedDate;
|
|
187
|
+
/**
|
|
188
|
+
* Gets Scrivener annotations from a document.
|
|
189
|
+
* @param documentId The UUID of the document.
|
|
190
|
+
* @returns A Map of annotation IDs to their content.
|
|
191
|
+
*/
|
|
192
|
+
getDocumentAnnotations(documentId: string): Promise<Map<string, string>>;
|
|
193
|
+
/**
|
|
194
|
+
* Gets project-level metadata.
|
|
195
|
+
* @returns Project metadata including title, author, and targets.
|
|
196
|
+
*/
|
|
197
|
+
getProjectMetadata(): Promise<ScrivenerMetadata>;
|
|
198
|
+
}
|
|
199
|
+
//# sourceMappingURL=scrivener-project.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scrivener-project.d.ts","sourceRoot":"","sources":["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