@gmickel/gno 0.25.2 → 0.27.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/README.md +5 -3
- package/assets/skill/SKILL.md +5 -0
- package/assets/skill/cli-reference.md +8 -6
- package/package.json +1 -1
- package/src/cli/commands/get.ts +21 -0
- package/src/cli/commands/skill/install.ts +2 -2
- package/src/cli/commands/skill/paths.ts +26 -4
- package/src/cli/commands/skill/uninstall.ts +2 -2
- package/src/cli/program.ts +18 -12
- package/src/core/document-capabilities.ts +113 -0
- package/src/mcp/tools/get.ts +10 -0
- package/src/mcp/tools/index.ts +434 -110
- package/src/sdk/documents.ts +12 -0
- package/src/serve/doc-events.ts +69 -0
- package/src/serve/public/app.tsx +81 -24
- package/src/serve/public/components/CaptureModal.tsx +138 -3
- package/src/serve/public/components/QuickSwitcher.tsx +248 -0
- package/src/serve/public/components/ShortcutHelpModal.tsx +1 -0
- package/src/serve/public/components/ai-elements/code-block.tsx +74 -26
- package/src/serve/public/components/editor/CodeMirrorEditor.tsx +51 -0
- package/src/serve/public/components/ui/command.tsx +2 -2
- package/src/serve/public/hooks/use-doc-events.ts +34 -0
- package/src/serve/public/hooks/useCaptureModal.tsx +12 -3
- package/src/serve/public/hooks/useKeyboardShortcuts.ts +2 -2
- package/src/serve/public/lib/deep-links.ts +68 -0
- package/src/serve/public/lib/document-availability.ts +22 -0
- package/src/serve/public/lib/local-history.ts +44 -0
- package/src/serve/public/lib/wiki-link.ts +36 -0
- package/src/serve/public/pages/Browse.tsx +11 -0
- package/src/serve/public/pages/Dashboard.tsx +2 -2
- package/src/serve/public/pages/DocView.tsx +241 -18
- package/src/serve/public/pages/DocumentEditor.tsx +399 -9
- package/src/serve/public/pages/Search.tsx +20 -1
- package/src/serve/routes/api.ts +359 -28
- package/src/serve/server.ts +48 -1
- package/src/serve/watch-service.ts +149 -0
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { watch, type FSWatcher } from "node:fs";
|
|
2
|
+
import { join, normalize, sep } from "node:path";
|
|
3
|
+
|
|
4
|
+
import type { Collection } from "../config/types";
|
|
5
|
+
import type { SqliteAdapter } from "../store/sqlite/adapter";
|
|
6
|
+
import type { DocumentEvent, DocumentEventBus } from "./doc-events";
|
|
7
|
+
import type { EmbedScheduler } from "./embed-scheduler";
|
|
8
|
+
|
|
9
|
+
import { defaultSyncService } from "../ingestion";
|
|
10
|
+
|
|
11
|
+
interface CollectionWatchServiceOptions {
|
|
12
|
+
collections: Collection[];
|
|
13
|
+
store: SqliteAdapter;
|
|
14
|
+
scheduler: EmbedScheduler | null;
|
|
15
|
+
eventBus: DocumentEventBus;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export class CollectionWatchService {
|
|
19
|
+
readonly #collections: Collection[];
|
|
20
|
+
readonly #store: SqliteAdapter;
|
|
21
|
+
readonly #scheduler: EmbedScheduler | null;
|
|
22
|
+
readonly #eventBus: DocumentEventBus;
|
|
23
|
+
readonly #watchers: FSWatcher[] = [];
|
|
24
|
+
readonly #pendingByCollection = new Map<string, Set<string>>();
|
|
25
|
+
readonly #timers = new Map<string, ReturnType<typeof setTimeout>>();
|
|
26
|
+
readonly #syncing = new Set<string>();
|
|
27
|
+
readonly #suppressedPaths = new Map<string, number>();
|
|
28
|
+
|
|
29
|
+
constructor(options: CollectionWatchServiceOptions) {
|
|
30
|
+
this.#collections = options.collections;
|
|
31
|
+
this.#store = options.store;
|
|
32
|
+
this.#scheduler = options.scheduler;
|
|
33
|
+
this.#eventBus = options.eventBus;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
start(): void {
|
|
37
|
+
for (const collection of this.#collections) {
|
|
38
|
+
try {
|
|
39
|
+
const watcher = watch(
|
|
40
|
+
collection.path,
|
|
41
|
+
{ recursive: true },
|
|
42
|
+
(_eventType, filename) => {
|
|
43
|
+
if (!filename) return;
|
|
44
|
+
const relPath = filename.toString().replaceAll("\\", "/");
|
|
45
|
+
const fullPath = normalize(join(collection.path, relPath));
|
|
46
|
+
const suppressedUntil = this.#suppressedPaths.get(fullPath);
|
|
47
|
+
if (suppressedUntil && suppressedUntil > Date.now()) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
this.#queueChange(collection.name, relPath);
|
|
51
|
+
}
|
|
52
|
+
);
|
|
53
|
+
this.#watchers.push(watcher);
|
|
54
|
+
} catch {
|
|
55
|
+
// Best-effort watch support; unsupported platforms can still rely on manual sync.
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
suppress(absPath: string, ms = 5_000): void {
|
|
61
|
+
this.#suppressedPaths.set(normalize(absPath), Date.now() + ms);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
dispose(): void {
|
|
65
|
+
for (const timer of this.#timers.values()) {
|
|
66
|
+
clearTimeout(timer);
|
|
67
|
+
}
|
|
68
|
+
for (const watcher of this.#watchers) {
|
|
69
|
+
watcher.close();
|
|
70
|
+
}
|
|
71
|
+
this.#timers.clear();
|
|
72
|
+
this.#watchers.length = 0;
|
|
73
|
+
this.#pendingByCollection.clear();
|
|
74
|
+
this.#syncing.clear();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
#queueChange(collectionName: string, relPath: string): void {
|
|
78
|
+
const pending =
|
|
79
|
+
this.#pendingByCollection.get(collectionName) ?? new Set<string>();
|
|
80
|
+
pending.add(relPath);
|
|
81
|
+
this.#pendingByCollection.set(collectionName, pending);
|
|
82
|
+
|
|
83
|
+
const existingTimer = this.#timers.get(collectionName);
|
|
84
|
+
if (existingTimer) {
|
|
85
|
+
clearTimeout(existingTimer);
|
|
86
|
+
}
|
|
87
|
+
this.#timers.set(
|
|
88
|
+
collectionName,
|
|
89
|
+
setTimeout(() => {
|
|
90
|
+
void this.#flushCollection(collectionName);
|
|
91
|
+
}, 300)
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async #flushCollection(collectionName: string): Promise<void> {
|
|
96
|
+
const pending = this.#pendingByCollection.get(collectionName);
|
|
97
|
+
if (!pending || pending.size === 0) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
if (this.#syncing.has(collectionName)) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const collection = this.#collections.find(
|
|
105
|
+
(entry) => entry.name === collectionName
|
|
106
|
+
);
|
|
107
|
+
if (!collection) {
|
|
108
|
+
this.#pendingByCollection.delete(collectionName);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const relPaths = [...pending];
|
|
113
|
+
this.#pendingByCollection.set(collectionName, new Set<string>());
|
|
114
|
+
this.#syncing.add(collectionName);
|
|
115
|
+
|
|
116
|
+
try {
|
|
117
|
+
await defaultSyncService.syncCollection(collection, this.#store, {
|
|
118
|
+
runUpdateCmd: false,
|
|
119
|
+
});
|
|
120
|
+
this.#afterSync(collection, relPaths);
|
|
121
|
+
} finally {
|
|
122
|
+
this.#syncing.delete(collectionName);
|
|
123
|
+
const remaining = this.#pendingByCollection.get(collectionName);
|
|
124
|
+
if (remaining && remaining.size > 0) {
|
|
125
|
+
void this.#flushCollection(collectionName);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
#afterSync(collection: Collection, relPaths: string[]): void {
|
|
131
|
+
if (relPaths.length === 0) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
this.#scheduler?.notifySyncComplete(relPaths);
|
|
136
|
+
|
|
137
|
+
for (const relPath of relPaths) {
|
|
138
|
+
const event: DocumentEvent = {
|
|
139
|
+
type: "document-changed",
|
|
140
|
+
uri: `gno://${collection.name}/${relPath.split(sep).join("/")}`,
|
|
141
|
+
collection: collection.name,
|
|
142
|
+
relPath,
|
|
143
|
+
origin: "watcher",
|
|
144
|
+
changedAt: new Date().toISOString(),
|
|
145
|
+
};
|
|
146
|
+
this.#eventBus.emit(event);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|