barry-cache 0.2.2

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.
Files changed (4) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +343 -0
  3. package/dist/cli.js +3863 -0
  4. package/package.json +28 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,343 @@
1
+ # Barry Cache
2
+
3
+ <p align="center">
4
+ <img src="assets/barry-cache.png" alt="Barry Cache" width="420">
5
+ </p>
6
+
7
+ Barry Cache remembers your repo.
8
+
9
+ It creates source-backed context files for coding agents, validates them, and gives agents a deterministic CLI for loading the smallest useful slice of project knowledge.
10
+
11
+ ## Reasoning
12
+
13
+ Barry Cache exists because coding agents need durable project context that is shared, reviewable, and smaller than the whole repository. Private assistant memory, ad hoc chat history, and vendor-specific instruction files drift apart; Barry keeps the source of truth in the repo and lets every agent load the same facts.
14
+
15
+ The structure is intentionally layered: canonical context lives in `docs/context/`, operational continuity lives in `.context-state/`, and generated retrieval data lives in `.context-cache/`. Canonical facts stay source-backed and validated, while `route`, `search`, `load`, and `resume` project only the relevant feature pack into an agent session.
16
+
17
+ That gives Barry three core advantages: it is agent-agnostic, because adapters point to one canonical context; auditable, because facts carry stable IDs and source references; and context-efficient, because agents start from a small routed slice instead of rereading the whole codebase.
18
+
19
+ ## Quick Start
20
+
21
+ ```bash
22
+ npx barry-cache init
23
+ ```
24
+
25
+ This bootstraps Barry Cache in the current repository. It creates `docs/context/`, patches agent instruction files, adds npm scripts when a `package.json` exists, and creates ignored runtime folders for handoffs and caches.
26
+
27
+ By default, `init` writes instruction files for all supported agents. To keep the repo focused on one agent, pass `--agents`. For example, Codex-only setup writes `AGENTS.md` but skips Copilot, Cursor, Claude, Gemini, and `llms.txt` adapters:
28
+
29
+ ```bash
30
+ npx barry-cache init --agents codex
31
+ ```
32
+
33
+ For non-interactive setup, use:
34
+
35
+ ```bash
36
+ npx barry-cache init --yes
37
+ ```
38
+
39
+ To preview the setup without writing files, use:
40
+
41
+ ```bash
42
+ npx barry-cache init --dry-run
43
+ ```
44
+
45
+ ## Command Reference
46
+
47
+ ### `barry-cache init`
48
+
49
+ Creates or updates the Barry Cache project structure.
50
+
51
+ ```bash
52
+ barry-cache init
53
+ barry-cache init --yes
54
+ barry-cache init --dry-run
55
+ barry-cache init --agents codex
56
+ ```
57
+
58
+ It writes the canonical context directory, schemas, selected agent instruction files, and the managed `.gitignore` block.
59
+
60
+ Use this when adding Barry Cache to a repo for the first time or regenerating adapter files after an upgrade.
61
+
62
+ Flags:
63
+ - `--yes`: run with conservative defaults.
64
+ - `--dry-run`: report planned writes and updates without changing files.
65
+ - `--agents <list>`: choose instruction adapters to generate. Use `all` (default), `none`, or a comma-separated list from `codex`, `cursor`, `copilot`, `claude`, `gemini`, and `llms`.
66
+
67
+ ### `barry-cache validate`
68
+
69
+ Checks whether the repo context is structurally valid.
70
+
71
+ ```bash
72
+ barry-cache validate
73
+ ```
74
+
75
+ It verifies required context files exist and validates every fact row in `docs/context/features/*/FACTS.jsonl`.
76
+
77
+ Use this after editing context files, importing memory, or before committing Barry Cache changes.
78
+
79
+ ### `barry-cache doctor`
80
+
81
+ Runs the same health check as `validate`, but phrases the result as a setup health report.
82
+
83
+ ```bash
84
+ barry-cache doctor
85
+ ```
86
+
87
+ Use this when you want to know whether Barry Cache is installed correctly in the repository.
88
+
89
+ ### `barry-cache route`
90
+
91
+ Scores feature context packs against a task and returns the most relevant routes.
92
+
93
+ ```bash
94
+ barry-cache route --task "fix playback drift"
95
+ ```
96
+
97
+ It reads `docs/context/features/*` and matches the task against feature README text, ID maps, graph edges, and facts.
98
+
99
+ Use this when deciding which context pack an agent should load before doing work.
100
+
101
+ ### `barry-cache search`
102
+
103
+ Searches feature packs and facts for a query.
104
+
105
+ ```bash
106
+ barry-cache search --query "transport clock"
107
+ ```
108
+
109
+ It returns matching feature packs and fact records with route, score, source, and text.
110
+
111
+ Use this when you know a term, file, component, or concept and want to find the relevant memory.
112
+
113
+ ### `barry-cache load`
114
+
115
+ Loads one feature context pack.
116
+
117
+ ```bash
118
+ barry-cache load --route renderer-runtime
119
+ ```
120
+
121
+ It returns the feature README, facts, and source file list for `docs/context/features/<route>/`.
122
+
123
+ Use this after `route` or `search` selects a specific feature.
124
+
125
+ ### `barry-cache resume`
126
+
127
+ Builds an agent startup brief for a task.
128
+
129
+ ```bash
130
+ barry-cache resume --task "fix playback drift"
131
+ ```
132
+
133
+ It routes the task, selects the top context packs, and returns an execution contract with the first action, edit scope, and validation commands.
134
+
135
+ Use this at the start of a Codex, Claude, Cursor, Copilot, Gemini, or other coding-agent session.
136
+
137
+ ### `barry-cache finalize`
138
+
139
+ Records the outcome of a work session.
140
+
141
+ ```bash
142
+ barry-cache finalize --status success --summary "Updated renderer clock context"
143
+ ```
144
+
145
+ ```bash
146
+ barry-cache finalize --status partial --summary "Found root cause but did not patch"
147
+ ```
148
+
149
+ It appends a JSONL handoff record to `.context-state/handoffs/handoffs.jsonl`.
150
+
151
+ Use this before ending a meaningful work session so the next agent can recover what happened.
152
+
153
+ Statuses:
154
+ - `success`: the task was completed.
155
+ - `partial`: some useful progress was made.
156
+ - `blocked`: the task cannot proceed without external input.
157
+ - `failed`: the attempted approach did not work.
158
+
159
+ ### `barry-cache review`
160
+
161
+ Opens a local browser tool for inspecting memory.
162
+
163
+ ```bash
164
+ barry-cache review
165
+ barry-cache review --port 8787
166
+ barry-cache review --open
167
+ barry-cache review --json
168
+ ```
169
+
170
+ Browser mode serves a feature-first relational tree explorer and inspector at `http://127.0.0.1:8787` by default. The tree supports feature selection, grouping, related-fact activation, local expansion, and zoom/pan for larger memory sets.
171
+
172
+ JSON mode exports the same graph/list/timeline/tree model without starting a long-running server.
173
+
174
+ Use this when you want to audit what Barry Cache currently knows.
175
+
176
+ ### `barry-cache import`
177
+
178
+ Imports memory from another system.
179
+
180
+ ```bash
181
+ barry-cache import --source pulpcut-kb --from /path/to/pulpcut-frontend
182
+ ```
183
+
184
+ ```bash
185
+ barry-cache import --source pulpcut-kb --from /path/to/pulpcut-frontend --dry-run --json
186
+ ```
187
+
188
+ Currently supported source:
189
+ - `pulpcut-kb`: imports old PulpCut KB folders from `docs/<feature>/`.
190
+
191
+ The PulpCut importer converts:
192
+ - `docs/KB_INDEX.md` into feature README route context.
193
+ - `docs/<feature>/IDMAP.md` into `docs/context/features/<feature>/IDMAP.md`.
194
+ - `docs/<feature>/KG.adj` into `docs/context/features/<feature>/KG.adj`.
195
+ - `docs/<feature>/FACTS.jsonl` old `{id,s,p,o,src}` records into Barry `{id,subject,predicate,object,src,status,kind,updated_at}` facts.
196
+
197
+ Use `--dry-run --json` first when importing a large memory base.
198
+
199
+ ### `barry-cache generate-adapters`
200
+
201
+ Reports that adapter generation is handled by `init`.
202
+
203
+ ```bash
204
+ barry-cache generate-adapters
205
+ ```
206
+
207
+ This command exists as a stable placeholder for future explicit adapter regeneration. For now, run `barry-cache init` to regenerate agent adapter files.
208
+
209
+ ### `barry-cache lint-wiki`
210
+
211
+ Runs wiki lint checks.
212
+
213
+ ```bash
214
+ barry-cache lint-wiki
215
+ ```
216
+
217
+ This is currently a lightweight placeholder and returns success. It is reserved for future checks over generated or maintained wiki-style context pages.
218
+
219
+ ## Common Workflows
220
+
221
+ ### Add Barry Cache To A Repo
222
+
223
+ Run this once from the repository root:
224
+
225
+ ```bash
226
+ npx barry-cache init
227
+ ```
228
+
229
+ After this, Barry Cache writes short instructions into agent-facing files such as `AGENTS.md`, `CLAUDE.md`, `GEMINI.md`, `.cursor/rules/barry-cache.mdc`, and `.github/copilot-instructions.md`.
230
+
231
+ For a Codex-only repo, use:
232
+
233
+ ```bash
234
+ npx barry-cache init --agents codex
235
+ ```
236
+
237
+ Those generated files tell coding agents how to use Barry before they edit the repo.
238
+
239
+ ### Ask An Agent To Work On A Task
240
+
241
+ Usually, you do not need to run `barry-cache resume` yourself.
242
+
243
+ Ask your coding agent normally:
244
+
245
+ ```text
246
+ Fix playback drift in the editor.
247
+ ```
248
+
249
+ Because `barry-cache init` added instructions to the repo, the agent should run this before non-trivial work:
250
+
251
+ ```bash
252
+ barry-cache resume --task "fix playback drift in the editor"
253
+ ```
254
+
255
+ The agent then uses the returned routes to load focused context:
256
+
257
+ ```bash
258
+ barry-cache load --route editor-media-runtime
259
+ ```
260
+
261
+ This keeps the agent from reading every context file in the repo.
262
+
263
+ If an agent ignores the repo instructions, prompt it explicitly:
264
+
265
+ ```text
266
+ Before editing, follow Barry Cache protocol:
267
+ 1. Run barry-cache resume --task "<my task>".
268
+ 2. Load the returned route context.
269
+ 3. Do the work.
270
+ 4. Run validation.
271
+ 5. Finalize the session if useful.
272
+ ```
273
+
274
+ ### Inspect Context Yourself
275
+
276
+ Use these commands when you want to see what Barry would give an agent:
277
+
278
+ ```bash
279
+ barry-cache route --task "fix playback drift"
280
+ barry-cache search --query "transport clock"
281
+ barry-cache load --route editor-media-runtime
282
+ ```
283
+
284
+ Use the browser review tool for a broader overview:
285
+
286
+ ```bash
287
+ barry-cache review
288
+ ```
289
+
290
+ ### Save Agent Sessions
291
+
292
+ At the end of a meaningful session, ask the agent:
293
+
294
+ ```text
295
+ Save this session to Barry Cache.
296
+
297
+ Rules:
298
+ 1. Record the session outcome with barry-cache finalize.
299
+ 2. Promote only source-backed implementation facts into docs/context/features/*/FACTS.jsonl.
300
+ 3. Put uncertain notes, blockers, and next steps in operational memory, not canonical facts.
301
+ 4. Update IDMAP.md or KG.adj only when new source IDs or relationships are needed.
302
+ 5. Run barry-cache validate before finishing.
303
+ ```
304
+
305
+ The minimum useful save is:
306
+
307
+ ```bash
308
+ barry-cache finalize --status success --summary "Short session outcome"
309
+ ```
310
+
311
+ This writes an operational handoff into `.context-state/handoffs/handoffs.jsonl`. It does not automatically turn chat content into canonical facts.
312
+
313
+ ### Import And Review Old Memory
314
+
315
+ When migrating an old PulpCut KB, preview the import first:
316
+
317
+ ```bash
318
+ barry-cache import --source pulpcut-kb --from /path/to/pulpcut-frontend --dry-run --json
319
+ ```
320
+
321
+ If the result looks right, apply it and validate:
322
+
323
+ ```bash
324
+ barry-cache import --source pulpcut-kb --from /path/to/pulpcut-frontend
325
+ barry-cache validate
326
+ ```
327
+
328
+ Then inspect the imported memory:
329
+
330
+ ```bash
331
+ barry-cache review
332
+ ```
333
+
334
+ ## Development
335
+
336
+ ```bash
337
+ bun install
338
+ bun test
339
+ bun run typecheck
340
+ bun run build
341
+ ```
342
+
343
+ The repository uses Bun for development and builds a Node-compatible CLI for npm distribution.