@almadar/workspace 0.2.6 → 0.4.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/__tests__/list-workspaces.test.d.ts +1 -0
- package/dist/__tests__/watch.test.d.ts +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +92 -23
- package/dist/index.js.map +1 -1
- package/dist/internal/backends/local.d.ts +1 -0
- package/dist/internal/backends/memory.d.ts +1 -0
- package/dist/internal/types.d.ts +9 -0
- package/dist/list-workspaces.d.ts +14 -0
- package/dist/service.d.ts +2 -1
- package/dist/types.d.ts +49 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
* `src/internal/`.
|
|
8
8
|
*/
|
|
9
9
|
export { openWorkspace } from './open-workspace.js';
|
|
10
|
+
export { listWorkspaces } from './list-workspaces.js';
|
|
10
11
|
export { openAccount } from './account.js';
|
|
11
|
-
export type { WorkspaceService, WorkspaceObserver, WorkspaceWriteEvent, OpenWorkspaceOptions, RestoreBackend, GitHubConfig, GitStatusInfo, FileTreeNode, AccountService, AccountConfig, ProviderCredential, AccountIdentity, OpenAccountOptions, } from './types.js';
|
|
12
|
+
export type { WorkspaceService, WorkspaceObserver, WorkspaceWriteEvent, WorkspaceWatchEvent, OpenWorkspaceOptions, ListWorkspacesOptions, WorkspaceSummary, RestoreBackend, GitHubConfig, GitStatusInfo, FileTreeNode, AccountService, AccountConfig, ProviderCredential, AccountIdentity, OpenAccountOptions, } from './types.js';
|
|
12
13
|
export type { WorkspaceIndex, EmbedderPort, ResolveResult, ResolveOptions, TraitRefEmit, WorkspaceIndexStats, OrbitalIndexEntry, ExtraTraitIdentity, RetrievalResult, RetrievalOptions, RecentlyEditedOptions, EventEdge, EntityBinding, RuleBinding, RecencyEntry, IntentMaps, ComposedMaps, BM25Document, BM25Table, BM25Options, WorkspaceIndexManifest, } from './workspace-index/types.js';
|
|
13
14
|
export { DEFAULT_COERCION_THRESHOLD, DEFAULT_RETRIEVAL_TOP_K, RRF_K, WORKSPACE_INDEX_SCHEMA_VERSION, } from './workspace-index/types.js';
|
package/dist/index.js
CHANGED
|
@@ -50,6 +50,24 @@ var LocalBackend = class {
|
|
|
50
50
|
async chmod(absPath, mode) {
|
|
51
51
|
await fs.promises.chmod(absPath, mode);
|
|
52
52
|
}
|
|
53
|
+
watch(absPath, onChange) {
|
|
54
|
+
let watcher;
|
|
55
|
+
let timer;
|
|
56
|
+
try {
|
|
57
|
+
watcher = fs.watch(absPath, (eventType) => {
|
|
58
|
+
if (timer) clearTimeout(timer);
|
|
59
|
+
timer = setTimeout(() => {
|
|
60
|
+
timer = void 0;
|
|
61
|
+
onChange(eventType === "rename" ? "rename" : "change");
|
|
62
|
+
}, 75);
|
|
63
|
+
});
|
|
64
|
+
} catch {
|
|
65
|
+
}
|
|
66
|
+
return () => {
|
|
67
|
+
if (timer) clearTimeout(timer);
|
|
68
|
+
watcher?.close();
|
|
69
|
+
};
|
|
70
|
+
}
|
|
53
71
|
};
|
|
54
72
|
|
|
55
73
|
// src/internal/backends/memory.ts
|
|
@@ -150,6 +168,10 @@ var MemoryBackend = class {
|
|
|
150
168
|
}
|
|
151
169
|
async chmod() {
|
|
152
170
|
}
|
|
171
|
+
watch() {
|
|
172
|
+
return () => {
|
|
173
|
+
};
|
|
174
|
+
}
|
|
153
175
|
// Test helpers
|
|
154
176
|
getAll() {
|
|
155
177
|
return new Map(this.files);
|
|
@@ -738,8 +760,8 @@ function tokenizeSpec(spec) {
|
|
|
738
760
|
for (const p of pages) {
|
|
739
761
|
const obj = asJsonObject2(p);
|
|
740
762
|
if (!obj) continue;
|
|
741
|
-
const
|
|
742
|
-
if (typeof
|
|
763
|
+
const path11 = obj["path"];
|
|
764
|
+
if (typeof path11 === "string") pushTokens(tokens, path11);
|
|
743
765
|
}
|
|
744
766
|
}
|
|
745
767
|
const ruleOverlay = asJsonObject2(params["ruleOverlay"]);
|
|
@@ -2049,6 +2071,10 @@ var WorkspaceServiceImpl = class {
|
|
|
2049
2071
|
subscribe(observer) {
|
|
2050
2072
|
return this.sinks.subscribe(observer);
|
|
2051
2073
|
}
|
|
2074
|
+
watch(relPath, onChange) {
|
|
2075
|
+
const abs = sandboxedPath(this.workDir, relPath);
|
|
2076
|
+
return this.backend.watch(abs, (kind) => onChange({ relPath, kind }));
|
|
2077
|
+
}
|
|
2052
2078
|
// === Disposal ===
|
|
2053
2079
|
async dispose() {
|
|
2054
2080
|
const pending = Array.from(this.writeQueue.values());
|
|
@@ -2166,28 +2192,31 @@ async function openWorkspaceInternal(opts) {
|
|
|
2166
2192
|
const backend = opts.backend === "memory" ? new MemoryBackend() : new LocalBackend();
|
|
2167
2193
|
const sinks = new SinkManager();
|
|
2168
2194
|
const resolved = await resolveLifecycle(backend, opts);
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
backend,
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
if (
|
|
2180
|
-
const
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2195
|
+
const bare = opts.bare === true && opts.adopt !== void 0;
|
|
2196
|
+
if (!bare) {
|
|
2197
|
+
await ensureSkeleton(backend, resolved.workDir);
|
|
2198
|
+
await writeMintTemplatesIfMissing(
|
|
2199
|
+
backend,
|
|
2200
|
+
resolved.workDir,
|
|
2201
|
+
opts.userId,
|
|
2202
|
+
opts.projectName ?? "Untitled",
|
|
2203
|
+
resolved.appId
|
|
2204
|
+
);
|
|
2205
|
+
if (resolved.appId !== void 0) {
|
|
2206
|
+
const existing = readAppMarker(backend, resolved.workDir);
|
|
2207
|
+
if (!existing || existing.appId !== resolved.appId) {
|
|
2208
|
+
const marker = {
|
|
2209
|
+
appId: resolved.appId,
|
|
2210
|
+
userId: opts.userId,
|
|
2211
|
+
createdAt: existing?.createdAt ?? Date.now()
|
|
2212
|
+
};
|
|
2213
|
+
if (opts.github?.repoUrl) marker.repoUrl = opts.github.repoUrl;
|
|
2214
|
+
await writeAppMarker(backend, resolved.workDir, marker);
|
|
2215
|
+
}
|
|
2187
2216
|
}
|
|
2188
2217
|
}
|
|
2189
2218
|
let git;
|
|
2190
|
-
if (opts.github && opts.backend !== "memory") {
|
|
2219
|
+
if (!bare && opts.github && opts.backend !== "memory") {
|
|
2191
2220
|
git = await ensureGitInit(backend, resolved.workDir);
|
|
2192
2221
|
}
|
|
2193
2222
|
const service = new WorkspaceServiceImpl({
|
|
@@ -2199,7 +2228,9 @@ async function openWorkspaceInternal(opts) {
|
|
|
2199
2228
|
git,
|
|
2200
2229
|
github: opts.github
|
|
2201
2230
|
});
|
|
2202
|
-
|
|
2231
|
+
if (!bare) {
|
|
2232
|
+
await service.index.warm();
|
|
2233
|
+
}
|
|
2203
2234
|
return service;
|
|
2204
2235
|
}
|
|
2205
2236
|
async function resolveLifecycle(backend, opts) {
|
|
@@ -2231,6 +2262,44 @@ async function resolveLifecycle(backend, opts) {
|
|
|
2231
2262
|
const workDir = mintSessionDir(opts.root, opts.userId);
|
|
2232
2263
|
return { workDir, appId: opts.appId };
|
|
2233
2264
|
}
|
|
2265
|
+
async function listWorkspaces(opts) {
|
|
2266
|
+
const backend = opts.backend === "memory" ? new MemoryBackend() : new LocalBackend();
|
|
2267
|
+
const userDir = path2.join(opts.root, opts.userId);
|
|
2268
|
+
if (!backend.exists(userDir)) return [];
|
|
2269
|
+
let entries;
|
|
2270
|
+
try {
|
|
2271
|
+
entries = await backend.readdir(userDir);
|
|
2272
|
+
} catch {
|
|
2273
|
+
return [];
|
|
2274
|
+
}
|
|
2275
|
+
const out = [];
|
|
2276
|
+
for (const entry of entries) {
|
|
2277
|
+
const workDir = path2.join(userDir, entry);
|
|
2278
|
+
try {
|
|
2279
|
+
if (!(await backend.stat(workDir)).isDirectory) continue;
|
|
2280
|
+
} catch {
|
|
2281
|
+
continue;
|
|
2282
|
+
}
|
|
2283
|
+
const marker = readAppMarker(backend, workDir);
|
|
2284
|
+
if (!marker) continue;
|
|
2285
|
+
const summary = { appId: marker.appId, workDir, updatedAt: marker.createdAt };
|
|
2286
|
+
const sf = schemaFile(workDir);
|
|
2287
|
+
if (backend.exists(sf)) {
|
|
2288
|
+
try {
|
|
2289
|
+
const parsed = JSON.parse(backend.readFileSync(sf));
|
|
2290
|
+
if (typeof parsed.name === "string") summary.name = parsed.name;
|
|
2291
|
+
} catch {
|
|
2292
|
+
}
|
|
2293
|
+
try {
|
|
2294
|
+
summary.updatedAt = (await backend.stat(sf)).mtimeMs;
|
|
2295
|
+
} catch {
|
|
2296
|
+
}
|
|
2297
|
+
}
|
|
2298
|
+
out.push(summary);
|
|
2299
|
+
}
|
|
2300
|
+
out.sort((a, b) => (b.updatedAt ?? 0) - (a.updatedAt ?? 0));
|
|
2301
|
+
return out;
|
|
2302
|
+
}
|
|
2234
2303
|
var ACCOUNT_DIR = ".almadar";
|
|
2235
2304
|
var CONFIG_FILE = "config.json";
|
|
2236
2305
|
var CREDENTIALS_FILE = "credentials.json";
|
|
@@ -2314,6 +2383,6 @@ async function openAccount(opts = {}) {
|
|
|
2314
2383
|
};
|
|
2315
2384
|
}
|
|
2316
2385
|
|
|
2317
|
-
export { DEFAULT_COERCION_THRESHOLD, DEFAULT_RETRIEVAL_TOP_K, RRF_K, WORKSPACE_INDEX_SCHEMA_VERSION, openAccount, openWorkspace };
|
|
2386
|
+
export { DEFAULT_COERCION_THRESHOLD, DEFAULT_RETRIEVAL_TOP_K, RRF_K, WORKSPACE_INDEX_SCHEMA_VERSION, listWorkspaces, openAccount, openWorkspace };
|
|
2318
2387
|
//# sourceMappingURL=index.js.map
|
|
2319
2388
|
//# sourceMappingURL=index.js.map
|