@myrialabs/clopen 0.4.44 → 0.4.46
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/backend/artifacts/project/bridge.ts +218 -0
- package/backend/artifacts/project/edit.ts +243 -0
- package/backend/artifacts/project/index.ts +38 -0
- package/backend/artifacts/project/project.test.ts +181 -0
- package/backend/artifacts/project/scan.ts +368 -0
- package/backend/artifacts/project/sources.ts +100 -0
- package/backend/artifacts/sync.ts +1 -1
- package/backend/auth/permissions.ts +15 -0
- package/backend/chat/stream-manager.ts +20 -3
- package/backend/database/migrations/083_create_project_mcp_trust.ts +32 -0
- package/backend/database/migrations/index.ts +7 -0
- package/backend/database/queries/index.ts +2 -0
- package/backend/database/queries/project-mcp-trust-queries.ts +43 -0
- package/backend/engine/adapters/claude/models.test.ts +49 -0
- package/backend/engine/adapters/claude/models.ts +81 -562
- package/backend/engine/adapters/claude/stream.ts +32 -5
- package/backend/engine/adapters/cline/credential.ts +42 -18
- package/backend/engine/adapters/cline/mcp-tools.ts +26 -4
- package/backend/engine/adapters/cline/message-converter.ts +31 -1
- package/backend/engine/adapters/cline/models.test.ts +77 -0
- package/backend/engine/adapters/cline/models.ts +89 -3
- package/backend/engine/adapters/cline/presets.ts +5 -0
- package/backend/engine/adapters/cline/stream.ts +29 -8
- package/backend/engine/adapters/codex/message-converter.ts +1 -1
- package/backend/engine/adapters/codex/models.ts +54 -31
- package/backend/engine/adapters/codex/patch-rollout.test.ts +36 -1
- package/backend/engine/adapters/codex/patch-rollout.ts +60 -29
- package/backend/engine/adapters/codex/session-fork.ts +5 -0
- package/backend/engine/adapters/codex/stream.ts +29 -11
- package/backend/engine/adapters/copilot/models.test.ts +40 -0
- package/backend/engine/adapters/copilot/models.ts +51 -24
- package/backend/engine/adapters/copilot/permissions.test.ts +47 -0
- package/backend/engine/adapters/copilot/permissions.ts +72 -0
- package/backend/engine/adapters/copilot/stream.ts +83 -70
- package/backend/engine/adapters/cursor/stream.ts +27 -12
- package/backend/engine/adapters/opencode/server.ts +14 -4
- package/backend/engine/adapters/opencode/stream.ts +18 -3
- package/backend/engine/adapters/pi/credential.test.ts +83 -0
- package/backend/engine/adapters/pi/credential.ts +68 -12
- package/backend/engine/adapters/pi/environment.ts +9 -5
- package/backend/engine/adapters/pi/mcp.test.ts +194 -0
- package/backend/engine/adapters/pi/mcp.ts +88 -0
- package/backend/engine/adapters/pi/message-converter.ts +6 -4
- package/backend/engine/adapters/pi/presets.ts +10 -5
- package/backend/engine/adapters/pi/stream.ts +77 -41
- package/backend/engine/adapters/qwen/environment.ts +39 -2
- package/backend/engine/adapters/qwen/message-converter.test.ts +64 -0
- package/backend/engine/adapters/qwen/message-converter.ts +40 -23
- package/backend/engine/adapters/qwen/models.test.ts +25 -0
- package/backend/engine/adapters/qwen/models.ts +42 -5
- package/backend/engine/adapters/qwen/session-store.test.ts +39 -0
- package/backend/engine/adapters/qwen/session-store.ts +66 -0
- package/backend/engine/adapters/qwen/stream.ts +118 -87
- package/backend/engine/artifact-sync.ts +12 -5
- package/backend/engine/docs/adapter-contract.md +7 -4
- package/backend/engine/docs/lessons-learned.md +405 -62
- package/backend/engine/docs/quick-reference.md +2 -2
- package/backend/engine/docs/stack.md +17 -4
- package/backend/engine/docs/websocket-routes.md +5 -5
- package/backend/engine/install-recipes.test.ts +105 -5
- package/backend/engine/install-recipes.ts +102 -42
- package/backend/engine/install-runner.ts +56 -2
- package/backend/engine/stack-project.ts +71 -1
- package/backend/files/file-watcher.test.ts +77 -0
- package/backend/files/file-watcher.ts +92 -60
- package/backend/files/watch-ignore.test.ts +182 -0
- package/backend/files/watch-ignore.ts +244 -0
- package/backend/git/git-executor.ts +14 -4
- package/backend/index.ts +16 -1
- package/backend/instructions/service.ts +5 -3
- package/backend/instructions/sync.ts +10 -27
- package/backend/mcp/README.md +2 -2
- package/backend/mcp/external/config.ts +83 -23
- package/backend/mcp/external/project.ts +124 -0
- package/backend/mcp/external/proxy.ts +65 -11
- package/backend/mcp/index.ts +22 -9
- package/backend/mcp/internal/config.ts +42 -3
- package/backend/mcp/internal/remote-server.ts +11 -1
- package/backend/memory/embedding/install.ts +29 -1
- package/backend/skills/marketplace.ts +1 -1
- package/backend/snapshot/blob-store.ts +9 -5
- package/backend/snapshot/git-attribution.test.ts +42 -0
- package/backend/snapshot/git-attribution.ts +306 -0
- package/backend/snapshot/gitignore.test.ts +62 -0
- package/backend/snapshot/gitignore.ts +158 -78
- package/backend/snapshot/snapshot-service.test.ts +270 -0
- package/backend/snapshot/snapshot-service.ts +412 -136
- package/backend/snapshot/turn-activity.test.ts +52 -0
- package/backend/snapshot/turn-activity.ts +83 -0
- package/backend/snapshot/turn-changes.test.ts +58 -1
- package/backend/snapshot/turn-changes.ts +66 -0
- package/backend/utils/keyed-lock.test.ts +33 -0
- package/backend/utils/keyed-lock.ts +17 -0
- package/backend/utils/port-utils.test.ts +29 -0
- package/backend/utils/port-utils.ts +19 -0
- package/backend/worktrees/tree.ts +1 -1
- package/backend/ws/chat/composer.ts +504 -0
- package/backend/ws/chat/index.ts +3 -1
- package/backend/ws/chat/stream.ts +252 -440
- package/backend/ws/engine/cline/accounts.ts +26 -6
- package/backend/ws/engine/codex/accounts.test.ts +49 -0
- package/backend/ws/engine/codex/accounts.ts +17 -13
- package/backend/ws/engine/pi/accounts.ts +61 -6
- package/backend/ws/index.ts +4 -0
- package/backend/ws/project-artifacts/index.ts +236 -0
- package/backend/ws/snapshot/changes.ts +66 -31
- package/dist/assets/{index-DX5OwLOc.js → index-BTcR1byF.js} +1 -1
- package/dist/assets/{index-BWyhqUi5.js → index-CwuKQelV.js} +1 -1
- package/dist/assets/main-BiDNMWb3.css +1 -0
- package/dist/assets/main-BlhKWz2B.js +1241 -0
- package/dist/index.html +2 -2
- package/package.json +19 -15
- package/shared/types/stores/settings.ts +5 -0
- package/shared/types/unified/message.ts +2 -0
- package/backend/engine/adapters/pi/mcp-tools.ts +0 -131
- package/backend/engine/adapters/qwen/session-fork.ts +0 -109
- package/dist/assets/main-DOkwqXRU.js +0 -1215
- package/dist/assets/main-DzCY0n-j.css +0 -1
|
@@ -23,6 +23,9 @@
|
|
|
23
23
|
* a file change, made clients reload every few seconds with nothing actually
|
|
24
24
|
* changing. So on Linux we walk the tree ourselves and never watch an ignored
|
|
25
25
|
* directory, which removes the overwhelming majority of the watch descriptors.
|
|
26
|
+
*
|
|
27
|
+
* What counts as ignored — by name, by manifest, by signature — lives in
|
|
28
|
+
* `watch-ignore.ts`.
|
|
26
29
|
*/
|
|
27
30
|
|
|
28
31
|
/** Whether the platform's recursive `fs.watch` is a single cheap OS handle. */
|
|
@@ -30,7 +33,7 @@ const USE_NATIVE_RECURSIVE_WATCH = process.platform !== 'linux';
|
|
|
30
33
|
|
|
31
34
|
import { watch, type FSWatcher, existsSync } from 'node:fs';
|
|
32
35
|
import { stat, readdir } from 'node:fs/promises';
|
|
33
|
-
import { join, relative, normalize, sep } from 'node:path';
|
|
36
|
+
import { basename, dirname, join, relative, normalize, sep } from 'node:path';
|
|
34
37
|
import { ws } from '$backend/utils/ws';
|
|
35
38
|
import { debug } from '$shared/utils/logger';
|
|
36
39
|
import { isScopeOfProject, scopeProjectId } from '$shared/utils/workspace-scope';
|
|
@@ -42,6 +45,13 @@ import {
|
|
|
42
45
|
notifyPathChanged
|
|
43
46
|
} from '$backend/git/nested-repos';
|
|
44
47
|
import type { FileChange } from '$shared/types/filesystem';
|
|
48
|
+
import {
|
|
49
|
+
GeneratedDirClassifier,
|
|
50
|
+
isIgnoredPath,
|
|
51
|
+
isMarkableDirName,
|
|
52
|
+
isOutputMarker,
|
|
53
|
+
isSignatureEntry
|
|
54
|
+
} from './watch-ignore';
|
|
45
55
|
|
|
46
56
|
/**
|
|
47
57
|
* Debounce configuration
|
|
@@ -63,39 +73,6 @@ const RESTART_DELAYS_MS = [1000, 2000, 4000, 8000];
|
|
|
63
73
|
/** How long a rebuilt watcher must survive before its fault count is forgiven. */
|
|
64
74
|
const FAULT_FORGIVENESS_MS = 60_000;
|
|
65
75
|
|
|
66
|
-
/**
|
|
67
|
-
* Directories to ignore when watching
|
|
68
|
-
*/
|
|
69
|
-
const IGNORED_DIRS = new Set([
|
|
70
|
-
'node_modules',
|
|
71
|
-
'.git',
|
|
72
|
-
'.svelte-kit',
|
|
73
|
-
'dist',
|
|
74
|
-
'build',
|
|
75
|
-
'.next',
|
|
76
|
-
'.nuxt',
|
|
77
|
-
'.output',
|
|
78
|
-
'__pycache__',
|
|
79
|
-
'.pytest_cache',
|
|
80
|
-
'coverage',
|
|
81
|
-
'.nyc_output',
|
|
82
|
-
'.turbo',
|
|
83
|
-
'.cache',
|
|
84
|
-
'.temp',
|
|
85
|
-
'.tmp',
|
|
86
|
-
'vendor'
|
|
87
|
-
]);
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Files to ignore
|
|
91
|
-
*/
|
|
92
|
-
const IGNORED_FILES = new Set([
|
|
93
|
-
'.DS_Store',
|
|
94
|
-
'Thumbs.db',
|
|
95
|
-
'.gitkeep',
|
|
96
|
-
'.gitignore~'
|
|
97
|
-
]);
|
|
98
|
-
|
|
99
76
|
/**
|
|
100
77
|
* Entries inside a git directory that never change what the Git panel renders.
|
|
101
78
|
*
|
|
@@ -185,6 +162,8 @@ interface ProjectWatcher {
|
|
|
185
162
|
faults: number;
|
|
186
163
|
/** Flipped by stopWatching so in-flight async tree walks bail out. */
|
|
187
164
|
closed: boolean;
|
|
165
|
+
/** Cached "is this directory generated output" decisions (see watch-ignore). */
|
|
166
|
+
generated: GeneratedDirClassifier;
|
|
188
167
|
/**
|
|
189
168
|
* Every known git directory -> the working tree it belongs to. Covers the
|
|
190
169
|
* project's own repo and each sub-repo, and is the attribution table for
|
|
@@ -228,15 +207,25 @@ class FileWatcherManager {
|
|
|
228
207
|
|
|
229
208
|
/**
|
|
230
209
|
* Per-project dirty file tracking for snapshot system.
|
|
231
|
-
* Accumulates changed file relative paths between snapshot captures
|
|
210
|
+
* Accumulates changed file relative paths between snapshot captures, with
|
|
211
|
+
* the time of each path's latest event.
|
|
232
212
|
*/
|
|
233
|
-
private dirtyFiles = new Map<string,
|
|
213
|
+
private dirtyFiles = new Map<string, Map<string, number>>();
|
|
234
214
|
|
|
235
215
|
/**
|
|
236
216
|
* Get dirty files accumulated since last clear for a project.
|
|
237
217
|
*/
|
|
238
218
|
getDirtyFiles(projectId: string): Set<string> {
|
|
239
|
-
return this.dirtyFiles.get(projectId)
|
|
219
|
+
return new Set(this.dirtyFiles.get(projectId)?.keys() ?? []);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* When the watcher last saw a path change (epoch ms), or undefined when it
|
|
224
|
+
* saw nothing — the only record of WHEN a file was deleted, since a deleted
|
|
225
|
+
* file has no mtime left to read.
|
|
226
|
+
*/
|
|
227
|
+
getLastChangeAt(projectId: string, relativePath: string): number | undefined {
|
|
228
|
+
return this.dirtyFiles.get(projectId)?.get(relativePath);
|
|
240
229
|
}
|
|
241
230
|
|
|
242
231
|
/**
|
|
@@ -251,9 +240,9 @@ class FileWatcherManager {
|
|
|
251
240
|
*/
|
|
252
241
|
private trackDirtyFile(projectId: string, relativePath: string): void {
|
|
253
242
|
if (!this.dirtyFiles.has(projectId)) {
|
|
254
|
-
this.dirtyFiles.set(projectId, new
|
|
243
|
+
this.dirtyFiles.set(projectId, new Map());
|
|
255
244
|
}
|
|
256
|
-
this.dirtyFiles.get(projectId)!.
|
|
245
|
+
this.dirtyFiles.get(projectId)!.set(relativePath, Date.now());
|
|
257
246
|
}
|
|
258
247
|
|
|
259
248
|
/**
|
|
@@ -347,6 +336,7 @@ class FileWatcherManager {
|
|
|
347
336
|
truncated: false,
|
|
348
337
|
faults,
|
|
349
338
|
closed: false,
|
|
339
|
+
generated: new GeneratedDirClassifier(normalizedPath),
|
|
350
340
|
gitDirOwners: new Map(),
|
|
351
341
|
gitWatchers: new Map(),
|
|
352
342
|
rejectedGitDirs: new Set(),
|
|
@@ -502,6 +492,7 @@ class FileWatcherManager {
|
|
|
502
492
|
} catch {
|
|
503
493
|
return; // Directory vanished or is unreadable — nothing to watch.
|
|
504
494
|
}
|
|
495
|
+
const names = entries.map((entry) => entry.name);
|
|
505
496
|
|
|
506
497
|
for (const entry of entries) {
|
|
507
498
|
if (pw.closed) return;
|
|
@@ -509,12 +500,16 @@ class FileWatcherManager {
|
|
|
509
500
|
|
|
510
501
|
const childPath = join(dir, entry.name);
|
|
511
502
|
const relativePath = relative(pw.projectPath, childPath).replace(/\\/g, '/');
|
|
512
|
-
if (
|
|
503
|
+
if (isIgnoredPath(relativePath)) {
|
|
513
504
|
if (announceGitDirs && entry.name === '.git') {
|
|
514
505
|
this.routeGitEvent(pw, relativePath, childPath);
|
|
515
506
|
}
|
|
516
507
|
continue;
|
|
517
508
|
}
|
|
509
|
+
// Output that is only recognisable by its manifest or its own contents
|
|
510
|
+
// (`target/` beside `Cargo.toml`, a virtualenv under any name).
|
|
511
|
+
if (await pw.generated.isGenerated(childPath, names)) continue;
|
|
512
|
+
if (pw.closed) return;
|
|
518
513
|
|
|
519
514
|
if (!this.watchDir(pw, childPath)) {
|
|
520
515
|
// Ceiling reached — stop descending entirely rather than watching an
|
|
@@ -641,19 +636,29 @@ class FileWatcherManager {
|
|
|
641
636
|
if (relativePath.startsWith('..')) return;
|
|
642
637
|
|
|
643
638
|
// Git metadata is not a working-tree change — it drives the Git panel
|
|
644
|
-
// instead. This runs BEFORE `
|
|
639
|
+
// instead. This runs BEFORE `isIgnoredPath`, which discards every `.git`
|
|
645
640
|
// path: where the root watch is recursive it is the only thing that sees
|
|
646
641
|
// a sub-repo's git dir, so dropping it here is what left a commit made
|
|
647
642
|
// inside a nested repo completely unreported.
|
|
648
643
|
// Tell sub-repo discovery before anything below filters the path away.
|
|
649
644
|
// It decides for itself what a path means: `routeGitEvent` swallows every
|
|
650
|
-
// `.git` path
|
|
651
|
-
//
|
|
645
|
+
// `.git` path, so `.git/info/exclude` — which moves the reported repo set
|
|
646
|
+
// just like `.gitignore` — would otherwise never reach it.
|
|
652
647
|
notifyPathChanged(projectWatcher.projectPath, fullPath);
|
|
653
648
|
|
|
654
649
|
if (this.routeGitEvent(projectWatcher, relativePath, fullPath)) return;
|
|
655
650
|
|
|
656
|
-
if (
|
|
651
|
+
if (isIgnoredPath(relativePath)) return;
|
|
652
|
+
|
|
653
|
+
// A signature or manifest appearing or vanishing changes what counts as
|
|
654
|
+
// generated, so re-decide before judging this very event by it.
|
|
655
|
+
const entryName = basename(fullPath);
|
|
656
|
+
if (isSignatureEntry(entryName) || isOutputMarker(entryName)) {
|
|
657
|
+
this.reclassify(projectWatcher, entryName, dirname(fullPath));
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
if (await projectWatcher.generated.isInsideGenerated(relativePath)) return;
|
|
661
|
+
if (projectWatcher.closed) return;
|
|
657
662
|
|
|
658
663
|
// Determine change type
|
|
659
664
|
let changeType: 'created' | 'modified' | 'deleted';
|
|
@@ -676,7 +681,7 @@ class FileWatcherManager {
|
|
|
676
681
|
// descendants' watchers so they can't leak.
|
|
677
682
|
if (!USE_NATIVE_RECURSIVE_WATCH) {
|
|
678
683
|
if (isDirectory && changeType === 'created') {
|
|
679
|
-
if (this.watchDir(projectWatcher, fullPath)) {
|
|
684
|
+
if (!(await projectWatcher.generated.isGenerated(fullPath)) && this.watchDir(projectWatcher, fullPath)) {
|
|
680
685
|
// Announce pruned git dirs: this subtree existed before we could
|
|
681
686
|
// watch it, so anything already inside it emitted no event.
|
|
682
687
|
void this.watchSubtree(projectWatcher, fullPath, true);
|
|
@@ -685,6 +690,7 @@ class FileWatcherManager {
|
|
|
685
690
|
this.unwatchDir(projectWatcher, fullPath);
|
|
686
691
|
}
|
|
687
692
|
}
|
|
693
|
+
if (changeType === 'deleted') projectWatcher.generated.forgetTree(fullPath);
|
|
688
694
|
|
|
689
695
|
// Track dirty file for snapshot system
|
|
690
696
|
this.trackDirtyFile(projectId, relativePath);
|
|
@@ -710,25 +716,51 @@ class FileWatcherManager {
|
|
|
710
716
|
}
|
|
711
717
|
|
|
712
718
|
/**
|
|
713
|
-
*
|
|
719
|
+
* Re-decide the directories a signature or manifest describes: its parent
|
|
720
|
+
* for a signature (`CACHEDIR.TAG`, `pyvenv.cfg`), the output-named siblings
|
|
721
|
+
* for a manifest (`Cargo.toml` → `target/`). The cached decisions are dropped
|
|
722
|
+
* synchronously so the triggering event is already judged by the new state.
|
|
723
|
+
*
|
|
724
|
+
* Where recursion is emulated the watch set follows: a directory that just
|
|
725
|
+
* became generated releases its handles, and one that stopped being generated
|
|
726
|
+
* (its manifest was deleted) is walked and watched like a new directory.
|
|
714
727
|
*/
|
|
715
|
-
private
|
|
716
|
-
const
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
if (
|
|
725
|
-
|
|
728
|
+
private reclassify(pw: ProjectWatcher, entryName: string, parentDir: string): void {
|
|
729
|
+
const signature = isSignatureEntry(entryName);
|
|
730
|
+
if (signature) pw.generated.forget(parentDir);
|
|
731
|
+
const manifest = isOutputMarker(entryName);
|
|
732
|
+
if (manifest) pw.generated.forgetMarkableChildren(parentDir);
|
|
733
|
+
if (USE_NATIVE_RECURSIVE_WATCH) return;
|
|
734
|
+
|
|
735
|
+
void (async () => {
|
|
736
|
+
const dirs: string[] = signature ? [parentDir] : [];
|
|
737
|
+
if (manifest) {
|
|
738
|
+
try {
|
|
739
|
+
const entries = await readdir(parentDir, { withFileTypes: true });
|
|
740
|
+
for (const entry of entries) {
|
|
741
|
+
if (entry.isDirectory() && isMarkableDirName(entry.name)) dirs.push(join(parentDir, entry.name));
|
|
742
|
+
}
|
|
743
|
+
} catch {
|
|
744
|
+
// The directory went away; its own deletion event cleans up.
|
|
745
|
+
}
|
|
726
746
|
}
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
return false;
|
|
747
|
+
for (const dir of dirs) await this.syncWatchState(pw, dir);
|
|
748
|
+
})();
|
|
730
749
|
}
|
|
731
750
|
|
|
751
|
+
/** Linux only: make `dir`'s watch match its current generated decision. */
|
|
752
|
+
private async syncWatchState(pw: ProjectWatcher, dir: string): Promise<void> {
|
|
753
|
+
if (dir === pw.projectPath) return;
|
|
754
|
+
const generated = await pw.generated.isGenerated(dir);
|
|
755
|
+
if (pw.closed) return;
|
|
756
|
+
if (generated) {
|
|
757
|
+
if (pw.dirWatchers.has(dir)) this.unwatchDir(pw, dir);
|
|
758
|
+
return;
|
|
759
|
+
}
|
|
760
|
+
const relativePath = relative(pw.projectPath, dir).replace(/\\/g, '/');
|
|
761
|
+
if (pw.dirWatchers.has(dir) || !pw.dirWatchers.has(dirname(dir)) || isIgnoredPath(relativePath)) return;
|
|
762
|
+
if (this.watchDir(pw, dir)) void this.watchSubtree(pw, dir, true);
|
|
763
|
+
}
|
|
732
764
|
|
|
733
765
|
/**
|
|
734
766
|
* Flush pending changes to clients
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Watch ignore policy tests.
|
|
3
|
+
*
|
|
4
|
+
* The negative cases matter as much as the positive ones: a name ignored in
|
|
5
|
+
* the wrong ecosystem hides real source from the explorer (Clopen's own `bin/`
|
|
6
|
+
* is source), and a dot-directory ignored by default is the stale-panel bug
|
|
7
|
+
* this policy replaced.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { describe, expect, test, afterEach } from 'bun:test';
|
|
11
|
+
import { mkdtemp, mkdir, rm, writeFile } from 'node:fs/promises';
|
|
12
|
+
import { tmpdir } from 'node:os';
|
|
13
|
+
import { join } from 'node:path';
|
|
14
|
+
import {
|
|
15
|
+
GeneratedDirClassifier,
|
|
16
|
+
isIgnoredName,
|
|
17
|
+
isIgnoredPath,
|
|
18
|
+
isMarkedOutputDir,
|
|
19
|
+
hasGeneratedSignature,
|
|
20
|
+
isOutputMarker,
|
|
21
|
+
isSignatureEntry
|
|
22
|
+
} from './watch-ignore';
|
|
23
|
+
|
|
24
|
+
const tempRoots: string[] = [];
|
|
25
|
+
|
|
26
|
+
async function makeProject(): Promise<string> {
|
|
27
|
+
const dir = await mkdtemp(join(tmpdir(), 'clopen-ignore-'));
|
|
28
|
+
tempRoots.push(dir);
|
|
29
|
+
return dir;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
afterEach(async () => {
|
|
33
|
+
await Promise.all(tempRoots.splice(0).map((dir) => rm(dir, { recursive: true, force: true })));
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe('isIgnoredPath (by name)', () => {
|
|
37
|
+
test('ignores dependency stores, build output and caches at any depth', () => {
|
|
38
|
+
for (const path of [
|
|
39
|
+
'node_modules/pkg/index.js',
|
|
40
|
+
'packages/web/node_modules/x',
|
|
41
|
+
'.git/HEAD',
|
|
42
|
+
'.venv/lib/site.py',
|
|
43
|
+
'app/.dart_tool/package_config.json',
|
|
44
|
+
'ios/.build/debug',
|
|
45
|
+
'.stack-work/dist',
|
|
46
|
+
'cmake-build-debug/CMakeCache.txt',
|
|
47
|
+
'.zig-cache/o'
|
|
48
|
+
]) {
|
|
49
|
+
expect(isIgnoredPath(path)).toBe(true);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test('watches dot-directories people and agents edit', () => {
|
|
54
|
+
for (const path of [
|
|
55
|
+
'.agents/skills/demo/SKILL.md',
|
|
56
|
+
'.agents/mcp.json',
|
|
57
|
+
'.claude/settings.json',
|
|
58
|
+
'.github/workflows/ci.yml',
|
|
59
|
+
'.vscode/settings.json',
|
|
60
|
+
'.env.local',
|
|
61
|
+
'.gitignore'
|
|
62
|
+
]) {
|
|
63
|
+
expect(isIgnoredPath(path)).toBe(false);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test('does not ignore names that are source in some ecosystem', () => {
|
|
68
|
+
for (const name of ['bin', 'obj', 'target', 'out', 'deps', '_build', 'Library', 'Pods', 'env', 'venv']) {
|
|
69
|
+
expect(isIgnoredName(name)).toBe(false);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test('ignores noise files but not their look-alikes', () => {
|
|
74
|
+
expect(isIgnoredPath('src/.DS_Store')).toBe(true);
|
|
75
|
+
expect(isIgnoredPath('.eslintcache')).toBe(true);
|
|
76
|
+
expect(isIgnoredPath('src/.notes.md.swp')).toBe(true);
|
|
77
|
+
expect(isIgnoredPath('src/notes.swp')).toBe(false);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
describe('isMarkedOutputDir (by manifest)', () => {
|
|
82
|
+
test('treats an ambiguous name as output only beside its manifest', () => {
|
|
83
|
+
expect(isMarkedOutputDir('target', ['Cargo.toml', 'src'])).toBe(true);
|
|
84
|
+
expect(isMarkedOutputDir('target', ['pom.xml'])).toBe(true);
|
|
85
|
+
expect(isMarkedOutputDir('target', ['package.json'])).toBe(false);
|
|
86
|
+
|
|
87
|
+
expect(isMarkedOutputDir('bin', ['App.csproj'])).toBe(true);
|
|
88
|
+
expect(isMarkedOutputDir('obj', ['Lib.fsproj'])).toBe(true);
|
|
89
|
+
expect(isMarkedOutputDir('bin', ['package.json', 'bunfig.toml'])).toBe(false);
|
|
90
|
+
|
|
91
|
+
expect(isMarkedOutputDir('_build', ['mix.exs'])).toBe(true);
|
|
92
|
+
expect(isMarkedOutputDir('deps', ['mix.exs'])).toBe(true);
|
|
93
|
+
expect(isMarkedOutputDir('deps', ['package.json'])).toBe(false);
|
|
94
|
+
|
|
95
|
+
expect(isMarkedOutputDir('out', ['next.config.mjs'])).toBe(true);
|
|
96
|
+
expect(isMarkedOutputDir('out', ['vite.config.ts'])).toBe(false);
|
|
97
|
+
|
|
98
|
+
expect(isMarkedOutputDir('Pods', ['Podfile'])).toBe(true);
|
|
99
|
+
expect(isMarkedOutputDir('Library', ['ProjectSettings', 'Assets'])).toBe(true);
|
|
100
|
+
expect(isMarkedOutputDir('Library', ['Sources'])).toBe(false);
|
|
101
|
+
expect(isMarkedOutputDir('Intermediate', ['Game.uproject'])).toBe(true);
|
|
102
|
+
expect(isMarkedOutputDir('bazel-out', ['MODULE.bazel'])).toBe(true);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test('knows which entries re-decide their siblings', () => {
|
|
106
|
+
expect(isOutputMarker('Cargo.toml')).toBe(true);
|
|
107
|
+
expect(isOutputMarker('App.csproj')).toBe(true);
|
|
108
|
+
expect(isOutputMarker('README.md')).toBe(false);
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
describe('hasGeneratedSignature (by contents)', () => {
|
|
113
|
+
test('recognises cache dirs and environments whatever they are called', () => {
|
|
114
|
+
expect(hasGeneratedSignature(['CACHEDIR.TAG', 'debug'])).toBe(true);
|
|
115
|
+
expect(hasGeneratedSignature(['bin', 'lib', 'pyvenv.cfg'])).toBe(true);
|
|
116
|
+
expect(hasGeneratedSignature(['conda-meta', 'lib'])).toBe(true);
|
|
117
|
+
expect(hasGeneratedSignature(['index.ts', 'utils'])).toBe(false);
|
|
118
|
+
expect(isSignatureEntry('pyvenv.cfg')).toBe(true);
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
describe('GeneratedDirClassifier', () => {
|
|
123
|
+
test('classifies from the disk by manifest and by signature', async () => {
|
|
124
|
+
const root = await makeProject();
|
|
125
|
+
await writeFile(join(root, 'Cargo.toml'), '[package]');
|
|
126
|
+
await mkdir(join(root, 'target', 'debug'), { recursive: true });
|
|
127
|
+
await mkdir(join(root, 'myenv', 'lib'), { recursive: true });
|
|
128
|
+
await writeFile(join(root, 'myenv', 'pyvenv.cfg'), 'home = /usr/bin');
|
|
129
|
+
await mkdir(join(root, 'bin'), { recursive: true });
|
|
130
|
+
|
|
131
|
+
const classifier = new GeneratedDirClassifier(root);
|
|
132
|
+
expect(await classifier.isGenerated(join(root, 'target'))).toBe(true);
|
|
133
|
+
expect(await classifier.isGenerated(join(root, 'myenv'))).toBe(true);
|
|
134
|
+
expect(await classifier.isGenerated(join(root, 'bin'))).toBe(false);
|
|
135
|
+
expect(await classifier.isGenerated(root)).toBe(false);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
test('judges ancestors only, so a new output folder itself is still reported', async () => {
|
|
139
|
+
const root = await makeProject();
|
|
140
|
+
await writeFile(join(root, 'Cargo.toml'), '[package]');
|
|
141
|
+
await mkdir(join(root, 'target', 'debug'), { recursive: true });
|
|
142
|
+
|
|
143
|
+
const classifier = new GeneratedDirClassifier(root);
|
|
144
|
+
expect(await classifier.isInsideGenerated('target')).toBe(false);
|
|
145
|
+
expect(await classifier.isInsideGenerated('target/debug/app')).toBe(true);
|
|
146
|
+
expect(await classifier.isInsideGenerated('src/main.rs')).toBe(false);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
test('re-reads the disk once told a manifest or signature moved', async () => {
|
|
150
|
+
const root = await makeProject();
|
|
151
|
+
await mkdir(join(root, 'bin'), { recursive: true });
|
|
152
|
+
await mkdir(join(root, 'env'), { recursive: true });
|
|
153
|
+
|
|
154
|
+
const classifier = new GeneratedDirClassifier(root);
|
|
155
|
+
expect(await classifier.isGenerated(join(root, 'bin'))).toBe(false);
|
|
156
|
+
expect(await classifier.isGenerated(join(root, 'env'))).toBe(false);
|
|
157
|
+
|
|
158
|
+
await writeFile(join(root, 'Tool.csproj'), '<Project />');
|
|
159
|
+
await writeFile(join(root, 'env', 'pyvenv.cfg'), 'home = /usr/bin');
|
|
160
|
+
// Cached until told otherwise…
|
|
161
|
+
expect(await classifier.isGenerated(join(root, 'bin'))).toBe(false);
|
|
162
|
+
|
|
163
|
+
classifier.forgetMarkableChildren(root);
|
|
164
|
+
classifier.forget(join(root, 'env'));
|
|
165
|
+
expect(await classifier.isGenerated(join(root, 'bin'))).toBe(true);
|
|
166
|
+
expect(await classifier.isGenerated(join(root, 'env'))).toBe(true);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
test('forgets a removed directory and everything under it', async () => {
|
|
170
|
+
const root = await makeProject();
|
|
171
|
+
await mkdir(join(root, 'env', 'lib'), { recursive: true });
|
|
172
|
+
await writeFile(join(root, 'env', 'pyvenv.cfg'), 'home = /usr/bin');
|
|
173
|
+
|
|
174
|
+
const classifier = new GeneratedDirClassifier(root);
|
|
175
|
+
expect(await classifier.isGenerated(join(root, 'env'))).toBe(true);
|
|
176
|
+
|
|
177
|
+
await rm(join(root, 'env'), { recursive: true, force: true });
|
|
178
|
+
await mkdir(join(root, 'env'), { recursive: true });
|
|
179
|
+
classifier.forgetTree(join(root, 'env'));
|
|
180
|
+
expect(await classifier.isGenerated(join(root, 'env'))).toBe(false);
|
|
181
|
+
});
|
|
182
|
+
});
|