@verevoir/context 0.1.0 → 0.2.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/CHANGELOG.md CHANGED
@@ -1,5 +1,38 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.0 — 2026-05-23
4
+
5
+ **Breaking restructure** — replaces `@verevoir/context/sources` with a per-source subpath pattern + a generic `wrapWithCache` primitive.
6
+
7
+ ```ts
8
+ // 0.1.x
9
+ import { cachedReadFile } from '@verevoir/context/sources';
10
+ await cachedReadFile(env, repoUrl, path);
11
+
12
+ // 0.2.x — convenience subpath
13
+ import { readFile } from '@verevoir/context/github';
14
+ await readFile(env, repoUrl, path);
15
+
16
+ // 0.2.x — custom adapter via the generic decorator
17
+ import { wrapWithCache } from '@verevoir/context';
18
+ import { mySource } from 'my-source-pkg';
19
+ const cached = wrapWithCache(mySource);
20
+ await cached.readFile(env, sourceUrl, path);
21
+ ```
22
+
23
+ **The model** (per Adam's substrate framing): a cache implements the same contract as the source it wraps. So `@verevoir/context/github` is a drop-in replacement for `@verevoir/sources/github` — same `SourceAdapter` shape, plus caching. Same for `@verevoir/context/fs`.
24
+
25
+ **Two new subpaths**:
26
+
27
+ - `@verevoir/context/github` = `wrapWithCache(github)` from `@verevoir/sources/github`. Optional peer dep on `@verevoir/sources`.
28
+ - `@verevoir/context/fs` = `wrapWithCache(fs)` from `@verevoir/sources/fs`. Optional peer dep on `@verevoir/sources`.
29
+
30
+ **New export at the root**: `wrapWithCache(source, { store? })` — decorator that adds read-through caching to any SourceAdapter. For custom adapter implementations that aren't shipped as a convenience subpath.
31
+
32
+ Behaviour: `readFile` caches; `writeFile` passes through and populates the cache with the just-written content; everything else is pass-through at v0. Per-method caching (listFiles, getRepoTree) can layer in later if profiling shows it matters.
33
+
34
+ **Removed**: `@verevoir/context/sources` (the generic adapter-pluggable bridge that 0.1.x exposed). The per-source convenience + the generic `wrapWithCache` together cover the use cases more cleanly.
35
+
3
36
  ## 0.1.0 — 2026-05-23
4
37
 
5
38
  Initial release.
package/README.md CHANGED
@@ -10,9 +10,10 @@ Pairs naturally with [`@verevoir/sources`](https://github.com/verevoir/sources)
10
10
 
11
11
  ## Subpaths
12
12
 
13
- - `@verevoir/context` — core `ContextStore` (content + symbol cache), `grep` over cached content, `IndexKey` + `SymbolEntry` types. No external dependencies.
14
- - `@verevoir/context/code` — tree-sitter symbol extraction (`parseSymbols`, `detectLanguage`) + `findSymbols` over the store. Optional peer deps on `tree-sitter`, `tree-sitter-typescript`, `tree-sitter-javascript`.
15
- - `@verevoir/context/sources` — `cachedReadFile` bridge that pairs the store with `@verevoir/sources/github`. Optional peer dep on `@verevoir/sources`.
13
+ - `@verevoir/context` — core `ContextStore` (content + symbol cache), `grep` over cached content, `wrapWithCache` decorator that adds read-through caching to any `@verevoir/sources` adapter, `IndexKey` + `SymbolEntry` types. No external dependencies; the decorator type-checks against `@verevoir/sources` but doesn't import it at runtime unless you call it.
14
+ - `@verevoir/context/code` — tree-sitter symbol extraction (`parseSymbols`, `detectLanguage`) + `findSymbols` over the store. Optional peer deps on tree-sitter packages.
15
+ - `@verevoir/context/github` — cached GitHub source. Drop-in replacement for `@verevoir/sources/github` that adds read-through caching. Identical contract.
16
+ - `@verevoir/context/fs` — cached local-filesystem source. Drop-in replacement for `@verevoir/sources/fs` that adds read-through caching. Identical contract.
16
17
 
17
18
  ## Install
18
19
 
@@ -65,21 +66,53 @@ const hits = findSymbols('auth', {
65
66
  // → [{ name: 'AuthHandler', kind: 'class', ... }, { name: 'authenticate', kind: 'method', ... }]
66
67
  ```
67
68
 
68
- ### Cached reads against `@verevoir/sources`
69
+ ### Cached source convenience subpaths
70
+
71
+ Drop-in replacements for `@verevoir/sources/<kind>` that add read-through caching. Same `SourceAdapter` contract; consumers swap the import path to gain caching, no other code changes.
69
72
 
70
73
  ```ts
71
74
  import { envFromProcessEnv } from '@verevoir/sources';
72
- import { cachedReadFile } from '@verevoir/context/sources';
75
+ import { readFile, writeFile } from '@verevoir/context/github';
73
76
 
74
77
  const env = envFromProcessEnv();
75
78
  if (!env) throw new Error('GITHUB_TOKEN not set');
76
79
 
77
- // First call fetches and caches; second call hits the cache.
78
- const a = await cachedReadFile(env, 'https://github.com/acme/charts', 'README.md');
79
- const b = await cachedReadFile(env, 'https://github.com/acme/charts', 'README.md');
80
- // `b` came from cache; only one HTTP call was made.
80
+ // First call hits the GitHub API; second call serves from cache.
81
+ const a = await readFile(env, 'https://github.com/acme/charts', 'README.md');
82
+ const b = await readFile(env, 'https://github.com/acme/charts', 'README.md');
83
+
84
+ // Writes pass through and populate the cache.
85
+ await writeFile(
86
+ env,
87
+ 'https://github.com/acme/charts',
88
+ 'docs/notes.md',
89
+ '# Notes\n',
90
+ 'feature/notes',
91
+ 'Add notes'
92
+ );
81
93
  ```
82
94
 
95
+ ```ts
96
+ import { readFile } from '@verevoir/context/fs';
97
+ const env = { token: '', forkOrg: '' }; // fs adapter ignores both
98
+
99
+ const r = await readFile(env, '/path/to/project', 'src/index.ts');
100
+ ```
101
+
102
+ ### Cached source — custom adapters
103
+
104
+ Bring your own SourceAdapter implementation; wrap it once to get the same caching behaviour.
105
+
106
+ ```ts
107
+ import { wrapWithCache } from '@verevoir/context';
108
+ import { mySource } from 'my-source-pkg'; // implements @verevoir/sources's SourceAdapter
109
+
110
+ const cached = wrapWithCache(mySource);
111
+ const r = await cached.readFile(env, sourceUrl, path);
112
+ ```
113
+
114
+ `wrapWithCache(source, { store? })` returns a `SourceAdapter`-shaped facade. Cache hits return `sha: ''` (the source's sha is not preserved across cache rounds; callers that need a real sha should re-fetch from cache-miss or call the underlying source).
115
+
83
116
  ## Key shape
84
117
 
85
118
  The cache key is `(sourceId, version, itemId)`:
@@ -105,7 +138,7 @@ interface SymbolEntry {
105
138
 
106
139
  ## Per-instance + singleton
107
140
 
108
- The default singleton `contextStore` is shared across imports of the same module. Tests and multi-tenant consumers can call `createContextStore()` to get an isolated instance and pass it via the `store` option on `grep`, `findSymbols`, and `cachedReadFile`.
141
+ The default singleton `contextStore` is shared across imports of the same module. Tests and multi-tenant consumers can call `createContextStore()` to get an isolated instance and pass it via the `store` option on `grep`, `findSymbols`, and `wrapWithCache`.
109
142
 
110
143
  ## What this is NOT
111
144
 
@@ -0,0 +1,10 @@
1
+ export declare const fs: import("@verevoir/sources").SourceAdapter;
2
+ export declare const readFile: (env: import("@verevoir/sources").SourceEnv, repoUrl: string, path: string, ref?: string) => Promise<import("@verevoir/sources").ReadFileResult>;
3
+ export declare const listFiles: (env: import("@verevoir/sources").SourceEnv, repoUrl: string, prefix: string, ref?: string) => Promise<import("@verevoir/sources").DirEntry[]>;
4
+ export declare const getRepoTree: (env: import("@verevoir/sources").SourceEnv, repoUrl: string, ref?: string) => Promise<import("@verevoir/sources").RepoTree>;
5
+ export declare const writeFile: (env: import("@verevoir/sources").SourceEnv, repoUrl: string, path: string, content: string, branch: string, commitMessage: string) => Promise<void>;
6
+ export declare const ensureBranch: (env: import("@verevoir/sources").SourceEnv, repoUrl: string, branch: string) => Promise<void>;
7
+ export declare const ensureFork: (env: import("@verevoir/sources").SourceEnv, upstreamUrl: string) => Promise<string>;
8
+ export declare const openPullRequest: (env: import("@verevoir/sources").SourceEnv, targetUrl: string, head: string, base: string, title: string, body: string) => Promise<string>;
9
+ export declare const getDefaultBranch: (env: import("@verevoir/sources").SourceEnv, repoUrl: string) => Promise<string>;
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/fs/index.ts"],"names":[],"mappings":"AAcA,eAAO,MAAM,EAAE,2CAAuB,CAAC;AAEvC,eAAO,MAAM,QAAQ,kJAAuB,CAAC;AAC7C,eAAO,MAAM,SAAS,gJAAwB,CAAC;AAC/C,eAAO,MAAM,WAAW,8HAA0B,CAAC;AACnD,eAAO,MAAM,SAAS,sJAAwB,CAAC;AAC/C,eAAO,MAAM,YAAY,gGAA2B,CAAC;AACrD,eAAO,MAAM,UAAU,sFAAyB,CAAC;AACjD,eAAO,MAAM,eAAe,6IAA8B,CAAC;AAC3D,eAAO,MAAM,gBAAgB,kFAA+B,CAAC"}
@@ -0,0 +1,22 @@
1
+ // @verevoir/context/fs — cached local-filesystem source.
2
+ //
3
+ // Drop-in replacement for `@verevoir/sources/fs` that adds
4
+ // read-through caching via the root `ContextStore`. SourceAdapter
5
+ // contract identical; consumers swap the import path to add
6
+ // caching, no other code changes.
7
+ //
8
+ // All caching logic lives in `wrapWithCache` at the root — this
9
+ // file is just the wiring. Per Adam's substrate framing
10
+ // (2026-05-23): "specific cache == cache + specific source".
11
+ import { fs as rawFs } from '@verevoir/sources/fs';
12
+ import { wrapWithCache } from '../index.js';
13
+ export const fs = wrapWithCache(rawFs);
14
+ export const readFile = fs.readFile.bind(fs);
15
+ export const listFiles = fs.listFiles.bind(fs);
16
+ export const getRepoTree = fs.getRepoTree.bind(fs);
17
+ export const writeFile = fs.writeFile.bind(fs);
18
+ export const ensureBranch = fs.ensureBranch.bind(fs);
19
+ export const ensureFork = fs.ensureFork.bind(fs);
20
+ export const openPullRequest = fs.openPullRequest.bind(fs);
21
+ export const getDefaultBranch = fs.getDefaultBranch.bind(fs);
22
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/fs/index.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,EAAE;AACF,2DAA2D;AAC3D,kEAAkE;AAClE,4DAA4D;AAC5D,kCAAkC;AAClC,EAAE;AACF,gEAAgE;AAChE,wDAAwD;AACxD,6DAA6D;AAE7D,OAAO,EAAE,EAAE,IAAI,KAAK,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,MAAM,CAAC,MAAM,EAAE,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;AAEvC,MAAM,CAAC,MAAM,QAAQ,GAAG,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC7C,MAAM,CAAC,MAAM,SAAS,GAAG,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC/C,MAAM,CAAC,MAAM,WAAW,GAAG,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACnD,MAAM,CAAC,MAAM,SAAS,GAAG,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC/C,MAAM,CAAC,MAAM,YAAY,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACrD,MAAM,CAAC,MAAM,UAAU,GAAG,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACjD,MAAM,CAAC,MAAM,eAAe,GAAG,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC3D,MAAM,CAAC,MAAM,gBAAgB,GAAG,EAAE,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC"}
@@ -0,0 +1,10 @@
1
+ export declare const github: import("@verevoir/sources").SourceAdapter;
2
+ export declare const readFile: (env: import("@verevoir/sources").SourceEnv, repoUrl: string, path: string, ref?: string) => Promise<import("@verevoir/sources").ReadFileResult>;
3
+ export declare const listFiles: (env: import("@verevoir/sources").SourceEnv, repoUrl: string, prefix: string, ref?: string) => Promise<import("@verevoir/sources").DirEntry[]>;
4
+ export declare const getRepoTree: (env: import("@verevoir/sources").SourceEnv, repoUrl: string, ref?: string) => Promise<import("@verevoir/sources").RepoTree>;
5
+ export declare const writeFile: (env: import("@verevoir/sources").SourceEnv, repoUrl: string, path: string, content: string, branch: string, commitMessage: string) => Promise<void>;
6
+ export declare const ensureBranch: (env: import("@verevoir/sources").SourceEnv, repoUrl: string, branch: string) => Promise<void>;
7
+ export declare const ensureFork: (env: import("@verevoir/sources").SourceEnv, upstreamUrl: string) => Promise<string>;
8
+ export declare const openPullRequest: (env: import("@verevoir/sources").SourceEnv, targetUrl: string, head: string, base: string, title: string, body: string) => Promise<string>;
9
+ export declare const getDefaultBranch: (env: import("@verevoir/sources").SourceEnv, repoUrl: string) => Promise<string>;
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/github/index.ts"],"names":[],"mappings":"AAcA,eAAO,MAAM,MAAM,2CAA2B,CAAC;AAK/C,eAAO,MAAM,QAAQ,kJAA+B,CAAC;AACrD,eAAO,MAAM,SAAS,gJAAgC,CAAC;AACvD,eAAO,MAAM,WAAW,8HAAkC,CAAC;AAC3D,eAAO,MAAM,SAAS,sJAAgC,CAAC;AACvD,eAAO,MAAM,YAAY,gGAAmC,CAAC;AAC7D,eAAO,MAAM,UAAU,sFAAiC,CAAC;AACzD,eAAO,MAAM,eAAe,6IAAsC,CAAC;AACnE,eAAO,MAAM,gBAAgB,kFAAuC,CAAC"}
@@ -0,0 +1,25 @@
1
+ // @verevoir/context/github — cached GitHub source.
2
+ //
3
+ // Drop-in replacement for `@verevoir/sources/github` that adds
4
+ // read-through caching via the root `ContextStore`. The
5
+ // SourceAdapter contract is identical; consumers swap the import
6
+ // path to add caching, no other code changes.
7
+ //
8
+ // All caching logic lives in `wrapWithCache` at the root — this
9
+ // file is just the wiring. Per Adam's substrate framing
10
+ // (2026-05-23): "specific cache == cache + specific source".
11
+ import { github as rawGithub } from '@verevoir/sources/github';
12
+ import { wrapWithCache } from '../index.js';
13
+ export const github = wrapWithCache(rawGithub);
14
+ // Re-export the individual functions for ergonomic destructured
15
+ // imports. Same shape as `@verevoir/sources/github` — only the
16
+ // behaviour (cache-hit / cache-populate) differs.
17
+ export const readFile = github.readFile.bind(github);
18
+ export const listFiles = github.listFiles.bind(github);
19
+ export const getRepoTree = github.getRepoTree.bind(github);
20
+ export const writeFile = github.writeFile.bind(github);
21
+ export const ensureBranch = github.ensureBranch.bind(github);
22
+ export const ensureFork = github.ensureFork.bind(github);
23
+ export const openPullRequest = github.openPullRequest.bind(github);
24
+ export const getDefaultBranch = github.getDefaultBranch.bind(github);
25
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/github/index.ts"],"names":[],"mappings":"AAAA,mDAAmD;AACnD,EAAE;AACF,+DAA+D;AAC/D,wDAAwD;AACxD,iEAAiE;AACjE,8CAA8C;AAC9C,EAAE;AACF,gEAAgE;AAChE,wDAAwD;AACxD,6DAA6D;AAE7D,OAAO,EAAE,MAAM,IAAI,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,MAAM,CAAC,MAAM,MAAM,GAAG,aAAa,CAAC,SAAS,CAAC,CAAC;AAE/C,gEAAgE;AAChE,+DAA+D;AAC/D,kDAAkD;AAClD,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AACrD,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AACvD,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAC3D,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AACvD,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAC7D,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AACzD,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AACnE,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC,gBAAgB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC"}
package/dist/index.d.ts CHANGED
@@ -88,4 +88,33 @@ export interface GrepOptions {
88
88
  * the consumer has fetched into the store — does not fan out to
89
89
  * the underlying source. Pure local lookup. */
90
90
  export declare function grep(pattern: string, scope: GrepScope, options?: GrepOptions): GrepHit[];
91
+ import type { SourceAdapter } from '@verevoir/sources';
92
+ export interface WrapWithCacheOptions {
93
+ /** Store to read/write. Defaults to the module's singleton. */
94
+ store?: ContextStore;
95
+ }
96
+ /** Returns a `SourceAdapter`-shaped facade that reads through the
97
+ * ContextStore. A drop-in replacement for the underlying source:
98
+ * the contract is identical, the wrapping is invisible to callers.
99
+ *
100
+ * - `readFile` checks the cache; on miss, fetches via the source
101
+ * and populates the cache. Cache hits return `sha: ''` (the
102
+ * source's sha is not preserved across cache rounds; callers
103
+ * that need a real sha should go to the source directly or
104
+ * re-fetch from cache-miss).
105
+ * - `writeFile` passes through, then populates the cache with the
106
+ * just-written content so subsequent reads see it without a
107
+ * refetch.
108
+ * - All other methods are pure pass-throughs at v0; the symbol
109
+ * cache and grep operate on what the cache already holds, fed
110
+ * primarily by `readFile`. Per-method caching (listFiles tree
111
+ * memoisation, etc.) can layer in later if profiling shows it
112
+ * matters.
113
+ *
114
+ * Per Adam's substrate model (2026-05-23): a specific cache IS a
115
+ * specific source — same contract — so the consumer just imports
116
+ * `@verevoir/context/<kind>` and gets caching for free, without
117
+ * having to thread the adapter through every call site.
118
+ */
119
+ export declare function wrapWithCache(source: SourceAdapter, options?: WrapWithCacheOptions): SourceAdapter;
91
120
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAoBA;;2CAE2C;AAC3C,MAAM,MAAM,UAAU,GAAG,UAAU,GAAG,OAAO,GAAG,QAAQ,GAAG,WAAW,GAAG,MAAM,GAAG,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AC;IACxB,4DAA4D;IAC5D,YAAY,EAAE,MAAM,EAAE,CAAC;CACxB;AAED,MAAM,WAAW,WAAW;IAC1B,6CAA6C;IAC7C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,wEAAwE;IACxE,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,2DAA2D;IAC3D,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,2DAA2D;IAC3D,KAAK,CAAC,EAAE,YAAY,CAAC;CACtB;AAKD;;+CAE+C;AAC/C,wBAAgB,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,GAAE,WAAgB,GAAG,OAAO,EAAE,CA+B5F;AAMD,OAAO,KAAK,EACV,aAAa,EAKd,MAAM,mBAAmB,CAAC;AAE3B,MAAM,WAAW,oBAAoB;IACnC,+DAA+D;IAC/D,KAAK,CAAC,EAAE,YAAY,CAAC;CACtB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,aAAa,EACrB,OAAO,GAAE,oBAAyB,GACjC,aAAa,CAiEf"}
package/dist/index.js CHANGED
@@ -10,9 +10,11 @@
10
10
  // payload is code; populated lazily by the `/code` subpath)
11
11
  //
12
12
  // Pure in-memory. No I/O — the cache holds what consumers put in it.
13
- // Bridges to actual sources live in subpaths (`/code` for tree-sitter
14
- // symbol extraction; `/sources` for the cached-read helper that pairs
15
- // with `@verevoir/sources`).
13
+ // `wrapWithCache(source)` here returns a SourceAdapter-shaped facade
14
+ // that reads through the cache; per-source convenience wrappers live
15
+ // in subpaths (`@verevoir/context/github` = wrap-cache + github,
16
+ // `@verevoir/context/fs` = wrap-cache + fs). Tree-sitter symbol
17
+ // extraction lives in `/code`.
16
18
  //
17
19
  // Scope: per-process. A Cloud Run instance, a long-running worker,
18
20
  // a CLI invocation — each holds its own. Cross-instance share lands
@@ -124,4 +126,69 @@ export function grep(pattern, scope, options = {}) {
124
126
  }
125
127
  return hits;
126
128
  }
129
+ /** Returns a `SourceAdapter`-shaped facade that reads through the
130
+ * ContextStore. A drop-in replacement for the underlying source:
131
+ * the contract is identical, the wrapping is invisible to callers.
132
+ *
133
+ * - `readFile` checks the cache; on miss, fetches via the source
134
+ * and populates the cache. Cache hits return `sha: ''` (the
135
+ * source's sha is not preserved across cache rounds; callers
136
+ * that need a real sha should go to the source directly or
137
+ * re-fetch from cache-miss).
138
+ * - `writeFile` passes through, then populates the cache with the
139
+ * just-written content so subsequent reads see it without a
140
+ * refetch.
141
+ * - All other methods are pure pass-throughs at v0; the symbol
142
+ * cache and grep operate on what the cache already holds, fed
143
+ * primarily by `readFile`. Per-method caching (listFiles tree
144
+ * memoisation, etc.) can layer in later if profiling shows it
145
+ * matters.
146
+ *
147
+ * Per Adam's substrate model (2026-05-23): a specific cache IS a
148
+ * specific source — same contract — so the consumer just imports
149
+ * `@verevoir/context/<kind>` and gets caching for free, without
150
+ * having to thread the adapter through every call site.
151
+ */
152
+ export function wrapWithCache(source, options = {}) {
153
+ const store = options.store ?? contextStore;
154
+ return {
155
+ async readFile(env, sourceUrl, path, ref) {
156
+ const version = ref ?? '';
157
+ const key = { sourceId: sourceUrl, version, itemId: path };
158
+ const cached = store.getContent(key);
159
+ if (cached !== undefined) {
160
+ return { content: cached, sha: '' };
161
+ }
162
+ const result = await source.readFile(env, sourceUrl, path, ref);
163
+ store.setContent(key, result.content);
164
+ return result;
165
+ },
166
+ async listFiles(env, sourceUrl, prefix, ref) {
167
+ return source.listFiles(env, sourceUrl, prefix, ref);
168
+ },
169
+ async getRepoTree(env, sourceUrl, ref) {
170
+ return source.getRepoTree(env, sourceUrl, ref);
171
+ },
172
+ async writeFile(env, sourceUrl, path, content, branch, commitMessage) {
173
+ await source.writeFile(env, sourceUrl, path, content, branch, commitMessage);
174
+ // Populate cache with the just-written content. `setContent`
175
+ // invalidates any cached symbols for the same key, so
176
+ // downstream find_symbol re-parses on the next query.
177
+ const key = { sourceId: sourceUrl, version: branch, itemId: path };
178
+ store.setContent(key, content);
179
+ },
180
+ async ensureBranch(env, sourceUrl, branch) {
181
+ return source.ensureBranch(env, sourceUrl, branch);
182
+ },
183
+ async ensureFork(env, upstreamUrl) {
184
+ return source.ensureFork(env, upstreamUrl);
185
+ },
186
+ async openPullRequest(env, targetUrl, head, base, title, body) {
187
+ return source.openPullRequest(env, targetUrl, head, base, title, body);
188
+ },
189
+ async getDefaultBranch(env, sourceUrl) {
190
+ return source.getDefaultBranch(env, sourceUrl);
191
+ },
192
+ };
193
+ }
127
194
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,mBAAmB;AACnB,EAAE;AACF,0DAA0D;AAC1D,gEAAgE;AAChE,8BAA8B;AAC9B,EAAE;AACF,8DAA8D;AAC9D,kEAAkE;AAClE,gEAAgE;AAChE,EAAE;AACF,qEAAqE;AACrE,sEAAsE;AACtE,sEAAsE;AACtE,6BAA6B;AAC7B,EAAE;AACF,mEAAmE;AACnE,oEAAoE;AACpE,oDAAoD;AAiCpD,mEAAmE;AACnE,sDAAsD;AACtD,mEAAmE;AACnE,oCAAoC;AACpC,MAAM,GAAG,GAAG,MAAM,CAAC;AACnB,SAAS,OAAO,CAAC,GAAa;IAC5B,OAAO,GAAG,GAAG,CAAC,QAAQ,GAAG,GAAG,GAAG,GAAG,CAAC,OAAO,GAAG,GAAG,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC;AAClE,CAAC;AACD,SAAS,aAAa,CAAC,QAAgB,EAAE,OAAe;IACtD,OAAO,GAAG,QAAQ,GAAG,GAAG,GAAG,OAAO,GAAG,GAAG,EAAE,CAAC;AAC7C,CAAC;AA4BD,MAAM,UAAU,kBAAkB;IAChC,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAkB,CAAC;IAC3C,MAAM,OAAO,GAAG,IAAI,GAAG,EAAy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Q,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;YACnE,KAAK,CAAC,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QACjC,CAAC;QACD,KAAK,CAAC,YAAY,CAAC,GAAc,EAAE,SAAiB,EAAE,MAAc;YAClE,OAAO,MAAM,CAAC,YAAY,CAAC,GAAG,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;QACrD,CAAC;QACD,KAAK,CAAC,UAAU,CAAC,GAAc,EAAE,WAAmB;YAClD,OAAO,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;QAC7C,CAAC;QACD,KAAK,CAAC,eAAe,CACnB,GAAc,EACd,SAAiB,EACjB,IAAY,EACZ,IAAY,EACZ,KAAa,EACb,IAAY;YAEZ,OAAO,MAAM,CAAC,eAAe,CAAC,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;QACzE,CAAC;QACD,KAAK,CAAC,gBAAgB,CAAC,GAAc,EAAE,SAAiB;YACtD,OAAO,MAAM,CAAC,gBAAgB,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;QACjD,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -1,5 +1,12 @@
1
- import { type SourceEnv } from '@verevoir/sources';
1
+ import { type SourceEnv, type ReadFileResult } from '@verevoir/sources';
2
2
  import { type ContextStore } from '../index.js';
3
+ /** Minimal shape an adapter must satisfy to be cached. Any
4
+ * `@verevoir/sources/<kind>` subpath's `readFile` matches; full
5
+ * `SourceAdapter` matches by construction. Keeps the bridge usable
6
+ * with read-only adapters that don't implement the write half. */
7
+ export interface CachedReadAdapter {
8
+ readFile(env: SourceEnv, sourceUrl: string, path: string, ref?: string): Promise<ReadFileResult>;
9
+ }
3
10
  export interface CachedReadOptions {
4
11
  /** Source version to use as the cache key. Defaults to the empty
5
12
  * string — the canonical "default branch / latest" sentinel. */
@@ -7,16 +14,25 @@ export interface CachedReadOptions {
7
14
  /** Store to read/write. Defaults to the module's singleton. */
8
15
  store?: ContextStore;
9
16
  }
10
- /** Read a file from a GitHub repo via `@verevoir/sources/github`,
11
- * with an in-process cache layered on top via `ContextStore`. Misses
12
- * fetch and populate the store; hits return immediately.
17
+ /** Read a file via any `SourceAdapter`'s `readFile`, with an
18
+ * in-process cache layered on top via `ContextStore`. Misses fetch
19
+ * and populate the store; hits return immediately.
13
20
  *
14
- * The cache key is `(repoUrl, version, path)` — the empty-string
21
+ * The cache key is `(sourceUrl, version, path)` — the empty-string
15
22
  * version sentinel keeps default-branch reads in a stable slot so
16
23
  * different call sites reading the same file at default share the
17
24
  * cache.
18
25
  *
19
- * For non-GitHub sources, callers can implement an equivalent bridge
20
- * using their adapter's `readFile` and the same store. */
21
- export declare function cachedReadFile(env: SourceEnv, repoUrl: string, path: string, options?: CachedReadOptions): Promise<string>;
26
+ * Usage:
27
+ *
28
+ * ```ts
29
+ * import { github } from '@verevoir/sources/github';
30
+ * import { fs } from '@verevoir/sources/fs';
31
+ * import { cachedReadFile } from '@verevoir/context/sources';
32
+ *
33
+ * await cachedReadFile(github, env, repoUrl, path);
34
+ * await cachedReadFile(fs, env, '/local/path', 'README.md');
35
+ * ```
36
+ */
37
+ export declare function cachedReadFile(adapter: CachedReadAdapter, env: SourceEnv, sourceUrl: string, path: string, options?: CachedReadOptions): Promise<string>;
22
38
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sources/index.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD,OAAO,EAAuC,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AAErF,MAAM,WAAW,iBAAiB;IAChC;oEACgE;IAChE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,+DAA+D;IAC/D,KAAK,CAAC,EAAE,YAAY,CAAC;CACtB;AAED;;;;;;;;;;0DAU0D;AAC1D,wBAAsB,cAAc,CAClC,GAAG,EAAE,SAAS,EACd,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,iBAAsB,GAC9B,OAAO,CAAC,MAAM,CAAC,CAWjB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sources/index.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACxE,OAAO,EAAuC,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AAErF;;;kEAGkE;AAClE,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,GAAG,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;CAClG;AAED,MAAM,WAAW,iBAAiB;IAChC;oEACgE;IAChE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,+DAA+D;IAC/D,KAAK,CAAC,EAAE,YAAY,CAAC;CACtB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,cAAc,CAClC,OAAO,EAAE,iBAAiB,EAC1B,GAAG,EAAE,SAAS,EACd,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,iBAAsB,GAC9B,OAAO,CAAC,MAAM,CAAC,CAWjB"}
@@ -5,33 +5,48 @@
5
5
  // for a given `(sourceId, version, itemId)` triggers the adapter
6
6
  // fetch; subsequent calls return cached content without re-fetching.
7
7
  //
8
+ // Adapter-agnostic since 0.2.0 — pass any `SourceAdapter`-shaped
9
+ // object with at least `readFile`. Lets the same store/cache layer
10
+ // front GitHub reads (via `@verevoir/sources/github`), local-FS
11
+ // reads (via `@verevoir/sources/fs`), or any other adapter that
12
+ // matches the contract. The store doesn't care about the source
13
+ // kind; the cache key is opaque text either way.
14
+ //
8
15
  // Peer dep on `@verevoir/sources` is optional in the package
9
16
  // manifest — consumers using `@verevoir/context` purely as an
10
17
  // in-memory cache (writing their own values via `setContent`) don't
11
18
  // need to install it.
12
- import { readFile } from '@verevoir/sources/github';
13
19
  import { contextStore as defaultContextStore } from '../index.js';
14
- /** Read a file from a GitHub repo via `@verevoir/sources/github`,
15
- * with an in-process cache layered on top via `ContextStore`. Misses
16
- * fetch and populate the store; hits return immediately.
20
+ /** Read a file via any `SourceAdapter`'s `readFile`, with an
21
+ * in-process cache layered on top via `ContextStore`. Misses fetch
22
+ * and populate the store; hits return immediately.
17
23
  *
18
- * The cache key is `(repoUrl, version, path)` — the empty-string
24
+ * The cache key is `(sourceUrl, version, path)` — the empty-string
19
25
  * version sentinel keeps default-branch reads in a stable slot so
20
26
  * different call sites reading the same file at default share the
21
27
  * cache.
22
28
  *
23
- * For non-GitHub sources, callers can implement an equivalent bridge
24
- * using their adapter's `readFile` and the same store. */
25
- export async function cachedReadFile(env, repoUrl, path, options = {}) {
29
+ * Usage:
30
+ *
31
+ * ```ts
32
+ * import { github } from '@verevoir/sources/github';
33
+ * import { fs } from '@verevoir/sources/fs';
34
+ * import { cachedReadFile } from '@verevoir/context/sources';
35
+ *
36
+ * await cachedReadFile(github, env, repoUrl, path);
37
+ * await cachedReadFile(fs, env, '/local/path', 'README.md');
38
+ * ```
39
+ */
40
+ export async function cachedReadFile(adapter, env, sourceUrl, path, options = {}) {
26
41
  const version = options.version ?? '';
27
42
  const store = options.store ?? defaultContextStore;
28
- const key = { sourceId: repoUrl, version, itemId: path };
43
+ const key = { sourceId: sourceUrl, version, itemId: path };
29
44
  const cached = store.getContent(key);
30
45
  if (cached !== undefined)
31
46
  return cached;
32
47
  // Map empty-string sentinel back to "no ref" for the adapter.
33
48
  const ref = version === '' ? undefined : version;
34
- const { content } = await readFile(env, repoUrl, path, ref);
49
+ const { content } = await adapter.readFile(env, sourceUrl, path, ref);
35
50
  store.setContent(key, content);
36
51
  return content;
37
52
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/sources/index.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,6CAA6C;AAC7C,EAAE;AACF,oEAAoE;AACpE,iEAAiE;AACjE,qEAAqE;AACrE,EAAE;AACF,6DAA6D;AAC7D,8DAA8D;AAC9D,oEAAoE;AACpE,sBAAsB;AAGtB,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,YAAY,IAAI,mBAAmB,EAAqB,MAAM,aAAa,CAAC;AAUrF;;;;;;;;;;0DAU0D;AAC1D,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,GAAc,EACd,OAAe,EACf,IAAY,EACZ,UAA6B,EAAE;IAE/B,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC;IACtC,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,mBAAmB,CAAC;IACnD,MAAM,GAAG,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;IACzD,MAAM,MAAM,GAAG,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IACrC,IAAI,MAAM,KAAK,SAAS;QAAE,OAAO,MAAM,CAAC;IACxC,8DAA8D;IAC9D,MAAM,GAAG,GAAG,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC;IACjD,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,QAAQ,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;IAC5D,KAAK,CAAC,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IAC/B,OAAO,OAAO,CAAC;AACjB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/sources/index.ts"],"names":[],"mappings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0",
4
4
  "description": "In-process content + symbol cache for LLM context windows. Keyed (source, version, item). Tree-sitter symbol extraction + grep + cached-read bridge as subpath imports.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -15,9 +15,13 @@
15
15
  "types": "./dist/code/index.d.ts",
16
16
  "import": "./dist/code/index.js"
17
17
  },
18
- "./sources": {
19
- "types": "./dist/sources/index.d.ts",
20
- "import": "./dist/sources/index.js"
18
+ "./github": {
19
+ "types": "./dist/github/index.d.ts",
20
+ "import": "./dist/github/index.js"
21
+ },
22
+ "./fs": {
23
+ "types": "./dist/fs/index.d.ts",
24
+ "import": "./dist/fs/index.js"
21
25
  }
22
26
  },
23
27
  "files": [
@@ -57,7 +61,7 @@
57
61
  },
58
62
  "devDependencies": {
59
63
  "@types/node": "^25.8.0",
60
- "@verevoir/sources": "^0.1.0",
64
+ "@verevoir/sources": "^0.2.0",
61
65
  "prettier": "^3",
62
66
  "tree-sitter": "^0.21.1",
63
67
  "tree-sitter-javascript": "^0.23.1",