@almadar/workspace 0.4.0 → 0.5.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__/open-create-false.test.d.ts +1 -0
- package/dist/delete-workspace.d.ts +14 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +37 -3
- package/dist/index.js.map +1 -1
- package/dist/internal/backends/local.d.ts +3 -0
- package/dist/internal/backends/memory.d.ts +3 -0
- package/dist/internal/types.d.ts +8 -0
- package/dist/open-workspace.d.ts +3 -0
- package/dist/types.d.ts +10 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `deleteWorkspace` — remove a user's app-workspace dir by appId.
|
|
3
|
+
*
|
|
4
|
+
* Locates the workspace via its `app-marker.json` (reuse `findLocalWorkspaceDir`)
|
|
5
|
+
* and removes the tree. Idempotent: returns `false` if no matching workspace.
|
|
6
|
+
* Keeps workspace lifecycle inside the package (consumers don't fs-scan/rm the
|
|
7
|
+
* layout themselves).
|
|
8
|
+
*
|
|
9
|
+
* @packageDocumentation
|
|
10
|
+
*/
|
|
11
|
+
import type { ListWorkspacesOptions } from './types.js';
|
|
12
|
+
export declare function deleteWorkspace(opts: ListWorkspacesOptions & {
|
|
13
|
+
appId: string;
|
|
14
|
+
}): Promise<boolean>;
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
export { openWorkspace } from './open-workspace.js';
|
|
10
10
|
export { listWorkspaces } from './list-workspaces.js';
|
|
11
|
+
export { deleteWorkspace } from './delete-workspace.js';
|
|
11
12
|
export { openAccount } from './account.js';
|
|
12
13
|
export type { WorkspaceService, WorkspaceObserver, WorkspaceWriteEvent, WorkspaceWatchEvent, OpenWorkspaceOptions, ListWorkspacesOptions, WorkspaceSummary, RestoreBackend, GitHubConfig, GitStatusInfo, FileTreeNode, AccountService, AccountConfig, ProviderCredential, AccountIdentity, OpenAccountOptions, } from './types.js';
|
|
13
14
|
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';
|
package/dist/index.js
CHANGED
|
@@ -50,6 +50,9 @@ var LocalBackend = class {
|
|
|
50
50
|
async chmod(absPath, mode) {
|
|
51
51
|
await fs.promises.chmod(absPath, mode);
|
|
52
52
|
}
|
|
53
|
+
async rm(absPath, opts) {
|
|
54
|
+
await fs.promises.rm(absPath, { recursive: opts?.recursive ?? false, force: true });
|
|
55
|
+
}
|
|
53
56
|
watch(absPath, onChange) {
|
|
54
57
|
let watcher;
|
|
55
58
|
let timer;
|
|
@@ -172,6 +175,15 @@ var MemoryBackend = class {
|
|
|
172
175
|
return () => {
|
|
173
176
|
};
|
|
174
177
|
}
|
|
178
|
+
async rm(absPath, opts) {
|
|
179
|
+
this.files.delete(absPath);
|
|
180
|
+
this.dirs.delete(absPath);
|
|
181
|
+
if (opts?.recursive) {
|
|
182
|
+
const prefix = absPath.endsWith("/") ? absPath : absPath + "/";
|
|
183
|
+
for (const k of [...this.files.keys()]) if (k.startsWith(prefix)) this.files.delete(k);
|
|
184
|
+
for (const d of [...this.dirs]) if (d.startsWith(prefix)) this.dirs.delete(d);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
175
187
|
// Test helpers
|
|
176
188
|
getAll() {
|
|
177
189
|
return new Map(this.files);
|
|
@@ -2171,13 +2183,18 @@ function openWorkspaceCacheKey(opts) {
|
|
|
2171
2183
|
return `${backendTag}:${opts.userId}:${opts.appId}`;
|
|
2172
2184
|
}
|
|
2173
2185
|
async function openWorkspace(opts) {
|
|
2186
|
+
if (opts.create === false) {
|
|
2187
|
+
return openWorkspaceInternal(opts);
|
|
2188
|
+
}
|
|
2174
2189
|
const key = openWorkspaceCacheKey(opts);
|
|
2175
2190
|
if (key !== null) {
|
|
2176
2191
|
const cached = openWorkspaceInFlight.get(key);
|
|
2177
2192
|
if (cached) return cached;
|
|
2178
2193
|
const pending = (async () => {
|
|
2179
2194
|
try {
|
|
2180
|
-
|
|
2195
|
+
const ws = await openWorkspaceInternal(opts);
|
|
2196
|
+
if (ws === null) throw new Error("openWorkspace: null resolution without create:false");
|
|
2197
|
+
return ws;
|
|
2181
2198
|
} catch (err) {
|
|
2182
2199
|
openWorkspaceInFlight.delete(key);
|
|
2183
2200
|
throw err;
|
|
@@ -2192,6 +2209,7 @@ async function openWorkspaceInternal(opts) {
|
|
|
2192
2209
|
const backend = opts.backend === "memory" ? new MemoryBackend() : new LocalBackend();
|
|
2193
2210
|
const sinks = new SinkManager();
|
|
2194
2211
|
const resolved = await resolveLifecycle(backend, opts);
|
|
2212
|
+
if (resolved === null) return null;
|
|
2195
2213
|
const bare = opts.bare === true && opts.adopt !== void 0;
|
|
2196
2214
|
if (!bare) {
|
|
2197
2215
|
await ensureSkeleton(backend, resolved.workDir);
|
|
@@ -2234,6 +2252,7 @@ async function openWorkspaceInternal(opts) {
|
|
|
2234
2252
|
return service;
|
|
2235
2253
|
}
|
|
2236
2254
|
async function resolveLifecycle(backend, opts) {
|
|
2255
|
+
const noCreate = opts.create === false;
|
|
2237
2256
|
if (opts.adopt) {
|
|
2238
2257
|
const workDir2 = path2.resolve(opts.adopt);
|
|
2239
2258
|
const marker = readAppMarker(backend, workDir2);
|
|
@@ -2251,14 +2270,20 @@ async function resolveLifecycle(backend, opts) {
|
|
|
2251
2270
|
if (opts.appId && opts.restore) {
|
|
2252
2271
|
const workDir2 = mintSessionDir(opts.root, opts.userId);
|
|
2253
2272
|
await backend.mkdir(workDir2, { recursive: true });
|
|
2254
|
-
await restoreWorkspace(backend, workDir2, opts.restore);
|
|
2273
|
+
const result = await restoreWorkspace(backend, workDir2, opts.restore);
|
|
2274
|
+
if (noCreate && result.filesRestored === 0) {
|
|
2275
|
+
await backend.rm(workDir2, { recursive: true });
|
|
2276
|
+
return null;
|
|
2277
|
+
}
|
|
2255
2278
|
return { workDir: workDir2, appId: opts.appId };
|
|
2256
2279
|
}
|
|
2257
2280
|
if (opts.appId && opts.github && opts.github.repoUrl) {
|
|
2281
|
+
if (noCreate) return null;
|
|
2258
2282
|
const workDir2 = mintSessionDir(opts.root, opts.userId);
|
|
2259
2283
|
await backend.mkdir(workDir2, { recursive: true });
|
|
2260
2284
|
return { workDir: workDir2, appId: opts.appId };
|
|
2261
2285
|
}
|
|
2286
|
+
if (noCreate) return null;
|
|
2262
2287
|
const workDir = mintSessionDir(opts.root, opts.userId);
|
|
2263
2288
|
return { workDir, appId: opts.appId };
|
|
2264
2289
|
}
|
|
@@ -2300,6 +2325,15 @@ async function listWorkspaces(opts) {
|
|
|
2300
2325
|
out.sort((a, b) => (b.updatedAt ?? 0) - (a.updatedAt ?? 0));
|
|
2301
2326
|
return out;
|
|
2302
2327
|
}
|
|
2328
|
+
|
|
2329
|
+
// src/delete-workspace.ts
|
|
2330
|
+
async function deleteWorkspace(opts) {
|
|
2331
|
+
const backend = opts.backend === "memory" ? new MemoryBackend() : new LocalBackend();
|
|
2332
|
+
const workDir = await findLocalWorkspaceDir(backend, opts.root, opts.userId, opts.appId);
|
|
2333
|
+
if (!workDir) return false;
|
|
2334
|
+
await backend.rm(workDir, { recursive: true });
|
|
2335
|
+
return true;
|
|
2336
|
+
}
|
|
2303
2337
|
var ACCOUNT_DIR = ".almadar";
|
|
2304
2338
|
var CONFIG_FILE = "config.json";
|
|
2305
2339
|
var CREDENTIALS_FILE = "credentials.json";
|
|
@@ -2383,6 +2417,6 @@ async function openAccount(opts = {}) {
|
|
|
2383
2417
|
};
|
|
2384
2418
|
}
|
|
2385
2419
|
|
|
2386
|
-
export { DEFAULT_COERCION_THRESHOLD, DEFAULT_RETRIEVAL_TOP_K, RRF_K, WORKSPACE_INDEX_SCHEMA_VERSION, listWorkspaces, openAccount, openWorkspace };
|
|
2420
|
+
export { DEFAULT_COERCION_THRESHOLD, DEFAULT_RETRIEVAL_TOP_K, RRF_K, WORKSPACE_INDEX_SCHEMA_VERSION, deleteWorkspace, listWorkspaces, openAccount, openWorkspace };
|
|
2387
2421
|
//# sourceMappingURL=index.js.map
|
|
2388
2422
|
//# sourceMappingURL=index.js.map
|