contextsliver 0.1.2 → 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/README.md +4 -0
- package/dist/watcher/index.d.ts.map +1 -1
- package/dist/watcher/index.js +65 -18
- package/dist/watcher/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
> On-demand context management for AI coding agents. Stop reading whole files — ask for the connected subgraph instead.
|
|
4
4
|
|
|
5
|
+
<p align="center">
|
|
6
|
+
<img src="assets/hero-banner.jpg" alt="ContextSliver — from chaos to clarity: on-demand code context for AI agents" width="800">
|
|
7
|
+
</p>
|
|
8
|
+
|
|
5
9
|
[](https://github.com/DevMuneeb/contextsliver/actions/workflows/ci.yml)
|
|
6
10
|
[](https://opensource.org/licenses/MIT)
|
|
7
11
|
[](https://www.npmjs.com/package/contextsliver)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/watcher/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/watcher/index.ts"],"names":[],"mappings":"AAaA,OAAiB,EAAE,KAAK,SAAS,EAAE,MAAM,UAAU,CAAC;AAGpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAyDpD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,GAAG,SAAS,CAqD9E"}
|
package/dist/watcher/index.js
CHANGED
|
@@ -6,8 +6,13 @@
|
|
|
6
6
|
//
|
|
7
7
|
// The watcher must NEVER throw into the event loop (it's a background process). All errors are
|
|
8
8
|
// caught and logged to stderr. It also never touches stdout.
|
|
9
|
+
//
|
|
10
|
+
// IMPORTANT (chokidar v4): the `ignored` option does NOT support glob patterns (that was removed
|
|
11
|
+
// in v4). It must be a function. We use a path-segment matcher so `node_modules` is excluded
|
|
12
|
+
// everywhere — this is what prevents the EMFILE ("too many open files") errors that a naive
|
|
13
|
+
// glob-based ignore would cause on large repos with thousands of dependency files.
|
|
9
14
|
import chokidar from 'chokidar';
|
|
10
|
-
import { relative, resolve } from 'node:path';
|
|
15
|
+
import { relative, resolve, sep } from 'node:path';
|
|
11
16
|
import { existsSync, readFileSync } from 'node:fs';
|
|
12
17
|
import { hashFile, isDirty } from './hasher.js';
|
|
13
18
|
import { indexFile } from '../parser/index.js';
|
|
@@ -15,21 +20,55 @@ import { pluginForFile } from '../parser/languages/registry.js';
|
|
|
15
20
|
import { toPosix } from '../utils/paths.js';
|
|
16
21
|
import { log } from '../utils/logger.js';
|
|
17
22
|
const DEBOUNCE_MS = 300;
|
|
18
|
-
/**
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
'
|
|
24
|
-
'
|
|
25
|
-
'
|
|
26
|
-
'
|
|
27
|
-
'
|
|
28
|
-
'
|
|
29
|
-
'
|
|
30
|
-
'
|
|
31
|
-
'
|
|
32
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Directory names whose entire subtree is ignored by the watcher. We match by PATH SEGMENT
|
|
25
|
+
* (anywhere in the path), which is what makes node_modules exclusion work under chokidar v4.
|
|
26
|
+
*/
|
|
27
|
+
const IGNORED_DIR_SEGMENTS = new Set([
|
|
28
|
+
'node_modules',
|
|
29
|
+
'.git',
|
|
30
|
+
'.sliver',
|
|
31
|
+
'dist',
|
|
32
|
+
'build',
|
|
33
|
+
'out',
|
|
34
|
+
'__pycache__',
|
|
35
|
+
'.next',
|
|
36
|
+
'.nuxt',
|
|
37
|
+
'coverage',
|
|
38
|
+
'.cache',
|
|
39
|
+
'.turbo',
|
|
40
|
+
]);
|
|
41
|
+
/** File suffixes that are never worth indexing (minified, sourcemaps). */
|
|
42
|
+
const IGNORED_SUFFIXES = ['.min.js', '.min.css', '.map'];
|
|
43
|
+
/**
|
|
44
|
+
* chokidar v4 `ignored` matcher. Returns true if the path should be IGNORED.
|
|
45
|
+
*
|
|
46
|
+
* We check each path segment against the ignored-dir set (so any path containing a
|
|
47
|
+
* `node_modules` segment anywhere is dropped), and the filename against ignored suffixes.
|
|
48
|
+
* Matching is on the raw path — both absolute and relative forms work because we split on the
|
|
49
|
+
* OS separator and also handle posix-style.
|
|
50
|
+
*/
|
|
51
|
+
function isIgnored(absOrRelPath) {
|
|
52
|
+
if (!absOrRelPath)
|
|
53
|
+
return false;
|
|
54
|
+
// Normalize to posix segments so the matcher is platform-independent.
|
|
55
|
+
const segments = absOrRelPath.split(sep).join('/').split('/');
|
|
56
|
+
for (const seg of segments) {
|
|
57
|
+
if (IGNORED_DIR_SEGMENTS.has(seg))
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
for (const suffix of IGNORED_SUFFIXES) {
|
|
61
|
+
if (absOrRelPath.endsWith(suffix))
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
// Hidden directories (dot-prefixed) other than the ones we explicitly allow.
|
|
65
|
+
// (We already handle .git/.sliver above; this catches .vscode, .idea, etc.)
|
|
66
|
+
for (const seg of segments) {
|
|
67
|
+
if (seg.length > 1 && seg.startsWith('.'))
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
33
72
|
/**
|
|
34
73
|
* Start watching the project root for changes. Returns the chokidar watcher
|
|
35
74
|
* (call .close() to stop). Reads from the GraphStore to detect unchanged files (hash dedup)
|
|
@@ -39,15 +78,23 @@ export function startWatcher(store, projectRoot) {
|
|
|
39
78
|
const root = resolve(projectRoot);
|
|
40
79
|
const timers = new Map();
|
|
41
80
|
const watcher = chokidar.watch(root, {
|
|
42
|
-
ignored:
|
|
81
|
+
ignored: isIgnored,
|
|
43
82
|
persistent: true,
|
|
44
83
|
ignoreInitial: true, // don't fire for files present at startup (already indexed)
|
|
84
|
+
// If the OS file-descriptor limit is still exceeded (very unusual now that node_modules is
|
|
85
|
+
// excluded), cap inotify/interval polling so we don't crash with EMFILE.
|
|
86
|
+
usePolling: false,
|
|
87
|
+
interval: 2000,
|
|
45
88
|
});
|
|
46
89
|
const relOf = (abs) => toPosix(relative(root, abs));
|
|
47
90
|
const handleChange = (absPath) => {
|
|
48
91
|
const rel = relOf(absPath);
|
|
49
92
|
if (!pluginForFile(rel))
|
|
50
|
-
return; // unsupported extension
|
|
93
|
+
return; // unsupported extension — don't index
|
|
94
|
+
// Defensive: the `ignored` matcher should already have filtered this, but re-check on the
|
|
95
|
+
// relative path in case of edge cases (e.g. symlinked dirs).
|
|
96
|
+
if (isIgnored(rel))
|
|
97
|
+
return;
|
|
51
98
|
// Debounce: collapse rapid saves into one re-index.
|
|
52
99
|
const existing = timers.get(rel);
|
|
53
100
|
if (existing)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/watcher/index.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,EAAE;AACF,6FAA6F;AAC7F,iGAAiG;AACjG,2DAA2D;AAC3D,EAAE;AACF,+FAA+F;AAC/F,6DAA6D;AAC7D,OAAO,QAA4B,MAAM,UAAU,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/watcher/index.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,EAAE;AACF,6FAA6F;AAC7F,iGAAiG;AACjG,2DAA2D;AAC3D,EAAE;AACF,+FAA+F;AAC/F,6DAA6D;AAC7D,EAAE;AACF,iGAAiG;AACjG,6FAA6F;AAC7F,4FAA4F;AAC5F,mFAAmF;AACnF,OAAO,QAA4B,MAAM,UAAU,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MA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