@mrdrmccoy/xerj-opencode-plugin 0.0.0-stage → 0.4.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/LICENSE +201 -0
- package/README.md +284 -2
- package/package.json +47 -4
- package/src/binary/detect.ts +55 -0
- package/src/binary/manager.ts +348 -0
- package/src/binary/release.ts +64 -0
- package/src/config.ts +381 -0
- package/src/hooks/session.ts +165 -0
- package/src/index/brain.ts +225 -0
- package/src/index/corpus.ts +164 -0
- package/src/index/hidden.ts +318 -0
- package/src/index/watcher.ts +333 -0
- package/src/index.ts +723 -0
- package/src/log.ts +88 -0
- package/src/memory/capture.ts +72 -0
- package/src/memory/store.ts +116 -0
- package/src/node/client.ts +361 -0
- package/src/node/supervisor.ts +267 -0
- package/src/paths.ts +202 -0
- package/src/platform.ts +88 -0
- package/src/remote/shell.ts +338 -0
- package/src/remote/spool.ts +217 -0
- package/src/rpc.ts +250 -0
- package/src/search/brains.ts +306 -0
- package/src/search/rank.ts +61 -0
- package/src/search/service.ts +589 -0
- package/src/semver.ts +117 -0
- package/src/stats/counters.ts +55 -0
- package/src/stats/ledger.ts +344 -0
- package/src/telemetry/anomaly.ts +211 -0
- package/src/tools/search.ts +384 -0
- package/src/tui.tsx +362 -0
- package/src/ui/format.ts +234 -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
CHANGED
|
@@ -1,3 +1,285 @@
|
|
|
1
|
-
#
|
|
1
|
+
# XERJ for OpenCode
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Local code and documentation search, agent memory, and retrieval accounting
|
|
4
|
+
for OpenCode V2, backed by [XERJ](https://github.com/xerj-org/xerj).
|
|
5
|
+
|
|
6
|
+
The plugin downloads and manages a XERJ binary, runs a private node on loopback,
|
|
7
|
+
keeps a project index current with a filesystem watcher, and gives the model
|
|
8
|
+
cited passages instead of whole files. Nothing leaves the machine.
|
|
9
|
+
|
|
10
|
+
## What it does
|
|
11
|
+
|
|
12
|
+
- **Search.** `xerj_search` returns passages with `path:line` citations, not
|
|
13
|
+
file listings. `xerj_def` finds a declaration by symbol.
|
|
14
|
+
- **Context injection.** Once per prompt, relevant passages and memories are
|
|
15
|
+
spliced into the system context for that turn. It has a hard token budget
|
|
16
|
+
and a deadline; a slow retrieval injects nothing rather than stalling.
|
|
17
|
+
- **Memory.** `xerj_remember`, `xerj_recall`, and `xerj_forget` keep durable
|
|
18
|
+
project facts across sessions.
|
|
19
|
+
- **Remote ingest.** Pages fetched during a session are spooled and indexed, so
|
|
20
|
+
a URL read today is searchable tomorrow. Any shell command that references
|
|
21
|
+
a file outside the project also indexes it.
|
|
22
|
+
- **Hidden trees.** `index.hidden` indexes folders that `autoindex` skips, such
|
|
23
|
+
as `.agents` or `.github`, as plain searchable documents.
|
|
24
|
+
- **Second brain.** Opt in with `index.brain` to build a graph over a docs
|
|
25
|
+
folder. Hits expand one hop along citation and sequence edges.
|
|
26
|
+
- **Accounting.** `xerj_status` reports queries, hit rate, bytes returned, and
|
|
27
|
+
measured token savings. The sidebar and `/xerj` panel show the same numbers.
|
|
28
|
+
- **Anomaly scoring.** `xerj_anomaly` flags spikes in a numeric metric series
|
|
29
|
+
using XERJ's on-demand detector. It is batch scoring, not monitoring.
|
|
30
|
+
|
|
31
|
+
## Requirements
|
|
32
|
+
|
|
33
|
+
- OpenCode V2 with plugin support.
|
|
34
|
+
- Linux x86_64/aarch64, macOS x86_64/arm64, or Windows x86_64/arm64.
|
|
35
|
+
- No XERJ install needed: the plugin manages its own binary under
|
|
36
|
+
`~/.local/share/opencode/xerj/` (or `%LOCALAPPDATA%` on Windows).
|
|
37
|
+
- Linux installs use the static musl build by default.
|
|
38
|
+
|
|
39
|
+
Only Linux x86_64 has been exercised end to end. The other release targets are
|
|
40
|
+
selected, downloaded, and probed for execution, but not tested in CI.
|
|
41
|
+
|
|
42
|
+
## Install
|
|
43
|
+
|
|
44
|
+
The plugin is published as `@mrdrmccoy/xerj-opencode-plugin`. Add it to any
|
|
45
|
+
OpenCode config file, global or project:
|
|
46
|
+
|
|
47
|
+
```jsonc
|
|
48
|
+
// ~/.config/opencode/opencode.jsonc (all projects)
|
|
49
|
+
// or <project>/opencode.json (one project)
|
|
50
|
+
{
|
|
51
|
+
"plugins": [
|
|
52
|
+
{
|
|
53
|
+
"package": "@mrdrmccoy/xerj-opencode-plugin",
|
|
54
|
+
"options": {
|
|
55
|
+
"index": { "hidden": [".agents"] }
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
]
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
The host fetches the package on first load and caches it under
|
|
63
|
+
`~/.cache/opencode/`. No separate install command is needed.
|
|
64
|
+
|
|
65
|
+
### From a local checkout
|
|
66
|
+
|
|
67
|
+
A checkout works the same way. Clone it, install its dev dependencies, and
|
|
68
|
+
point `package` at the directory:
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
git clone https://github.com/xerj-org/xerj-opencode-plugin.git \
|
|
72
|
+
~/src/xerj-opencode-plugin
|
|
73
|
+
cd ~/src/xerj-opencode-plugin
|
|
74
|
+
bun install # dev dependencies; the host supplies @opencode/plugin
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
```jsonc
|
|
78
|
+
// ~/.config/opencode/opencode.jsonc (all projects)
|
|
79
|
+
// or <project>/opencode.json (one project)
|
|
80
|
+
{
|
|
81
|
+
"plugins": [
|
|
82
|
+
{
|
|
83
|
+
"package": "/home/you/src/xerj-opencode-plugin",
|
|
84
|
+
"options": {
|
|
85
|
+
"index": { "hidden": [".agents"] }
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
]
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Use an absolute path. A relative `package` resolves against the project holding
|
|
93
|
+
the config, not against the checkout, so `"./"` works only when the config and
|
|
94
|
+
the checkout share a directory. That is what this repository does in its own
|
|
95
|
+
`opencode.json`.
|
|
96
|
+
|
|
97
|
+
There is no build step in either form: the entry points are TypeScript sources
|
|
98
|
+
that the host compiles when it loads them.
|
|
99
|
+
|
|
100
|
+
After adding the entry, restart OpenCode once. The first start downloads XERJ,
|
|
101
|
+
creates a data root, and builds the project index in the background.
|
|
102
|
+
`xerj_status` reports when it is ready. `opencode debug config` lists the
|
|
103
|
+
config files that were read, which is the quickest way to confirm the entry was
|
|
104
|
+
picked up.
|
|
105
|
+
|
|
106
|
+
## Where the config goes
|
|
107
|
+
|
|
108
|
+
OpenCode reads two config documents and applies them in order:
|
|
109
|
+
|
|
110
|
+
| Scope | Path | Notes |
|
|
111
|
+
|---|---|---|
|
|
112
|
+
| Global | `~/.config/opencode/opencode.jsonc` | Applies to every project. `$XDG_CONFIG_HOME` replaces `~/.config` when set. |
|
|
113
|
+
| Project | `<project>/opencode.json` | Applies to that project only. |
|
|
114
|
+
|
|
115
|
+
Each directory holds one document: when both `opencode.json` and
|
|
116
|
+
`opencode.jsonc` exist, `opencode.json` wins. In a directory without
|
|
117
|
+
`opencode.json`, `opencode.jsonc` is read instead. The same rule applies in the
|
|
118
|
+
global config directory, which is why the examples above name
|
|
119
|
+
`opencode.jsonc` there. This is what `opencode debug config` reports:
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
opencode debug config # prints every config source with its path
|
|
123
|
+
opencode debug paths # prints the global config, data, cache, state dirs
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Configuration
|
|
127
|
+
|
|
128
|
+
Options go under the plugin entry, inside `options`. Never at the document
|
|
129
|
+
root: a top-level `context` key is ignored by the plugin.
|
|
130
|
+
|
|
131
|
+
Every option has a default, so the file only needs the keys that differ. A
|
|
132
|
+
malformed value warns and falls back instead of failing plugin load. Nested
|
|
133
|
+
objects merge per key, so `{"context": {"maxTokens": 800}}` keeps the other
|
|
134
|
+
context defaults.
|
|
135
|
+
|
|
136
|
+
This is the complete set with its defaults, in
|
|
137
|
+
`~/.config/opencode/opencode.jsonc` (all projects) or `<project>/opencode.json`
|
|
138
|
+
(one project):
|
|
139
|
+
|
|
140
|
+
```jsonc
|
|
141
|
+
{
|
|
142
|
+
"plugins": [
|
|
143
|
+
{
|
|
144
|
+
"package": "@mrdrmccoy/xerj-opencode-plugin",
|
|
145
|
+
"options": {
|
|
146
|
+
"binary": { "version": "auto", "path": null, "target": null,
|
|
147
|
+
"libc": "musl" },
|
|
148
|
+
"node": { "url": null, "port": 9200, "dataDir": null },
|
|
149
|
+
"index": { "auto": true, "watch": true, "debounceMs": 800,
|
|
150
|
+
"periodicMs": 900000, "workers": null, "brain": [],
|
|
151
|
+
"hidden": [], "hiddenMaxBytes": 262144,
|
|
152
|
+
"semantic": true, "maxBytes": 2147483648,
|
|
153
|
+
"maxMinutes": 10 },
|
|
154
|
+
"remote": { "enabled": true, "maxBytes": 2000000 },
|
|
155
|
+
"context": { "enabled": true, "maxTokens": 1500, "memoryTokens": 400,
|
|
156
|
+
"maxPassages": 4, "timeoutMs": 400 },
|
|
157
|
+
"memory": { "enabled": true },
|
|
158
|
+
"stats": { "enabled": true, "bytesPerToken": 4,
|
|
159
|
+
"maxBaselineBytes": 131072 },
|
|
160
|
+
"telemetry": { "anomaly": false }
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
]
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
The same entry works with a checkout path instead of the package name; see
|
|
168
|
+
[Install](#install).
|
|
169
|
+
|
|
170
|
+
| Key | Meaning |
|
|
171
|
+
|---|---|
|
|
172
|
+
| `binary.version` | `auto` tracks the latest release; any other value pins it. |
|
|
173
|
+
| `binary.path` | Use this binary; skip download, upgrade, and platform checks. |
|
|
174
|
+
| `binary.target` | Explicit release triple, e.g. `aarch64-apple-darwin`. |
|
|
175
|
+
| `binary.libc` | `musl` (default) or `gnu` on Linux. |
|
|
176
|
+
| `node.url` | Attach to this node and never spawn one. |
|
|
177
|
+
| `node.port` | Preferred port. The supervisor advances it if taken. |
|
|
178
|
+
| `index.auto` | Run project, hidden, and brain indexing on startup. |
|
|
179
|
+
| `index.watch` | Keep a resident `autoindex --watch` process. |
|
|
180
|
+
| `index.brain` | Folders to index as second brains, e.g. `[".agents"]`. |
|
|
181
|
+
| `index.hidden` | Hidden folders to index as plain documents, e.g. `[".agents"]`. |
|
|
182
|
+
| `index.hiddenMaxBytes` | Per-file ceiling for hidden documents. |
|
|
183
|
+
| `index.semantic` | Include the semantic retrieval leg. |
|
|
184
|
+
| `remote.enabled` | Spool and index fetched pages. |
|
|
185
|
+
| `context.enabled` | Inject retrieved context; the kill switch. |
|
|
186
|
+
| `context.maxTokens` | Ceiling for injected passages. |
|
|
187
|
+
| `context.memoryTokens` | Ceiling for injected memories. |
|
|
188
|
+
| `context.timeoutMs` | Retrieval deadline; miss it and inject nothing. |
|
|
189
|
+
| `stats.maxBaselineBytes` | Cap on the baseline credited per cited file. |
|
|
190
|
+
| `telemetry.anomaly` | Reserved; background telemetry is not implemented. |
|
|
191
|
+
|
|
192
|
+
## Tools
|
|
193
|
+
|
|
194
|
+
| Tool | Input | Use |
|
|
195
|
+
|---|---|---|
|
|
196
|
+
| `xerj_search` | `query`, `k?`, `max_tokens?` | Find passages before reading files. |
|
|
197
|
+
| `xerj_def` | `symbol`, `k?` | Find a declaration by name. |
|
|
198
|
+
| `xerj_status` | — | Node, index, memory, and accounting state. |
|
|
199
|
+
| `xerj_remember` | `text`, `kind?`, `topic?` | Store a durable fact. |
|
|
200
|
+
| `xerj_recall` | `query`, `k?` | Retrieve memories by meaning. |
|
|
201
|
+
| `xerj_forget` | `id` | Retract a memory. |
|
|
202
|
+
| `xerj_index` | `url?` or `path?` | Index a page or external file now. |
|
|
203
|
+
| `xerj_anomaly` | `index`, `time_field?`, `function?`, `field?`, `bucket_span?`, `threshold?` | Score a metric series and return flagged buckets. |
|
|
204
|
+
|
|
205
|
+
## TUI
|
|
206
|
+
|
|
207
|
+
- Sidebar: docs and size, hit rate, tokens saved, freshness.
|
|
208
|
+
- `/xerj`: open the details panel. Also accepts `status`, `reindex`,
|
|
209
|
+
`remember <text>`, and `search <query>`.
|
|
210
|
+
- `/xerj-reindex`, `/xerj-remember`, `/xerj-search`: direct commands.
|
|
211
|
+
|
|
212
|
+
## How retrieval works
|
|
213
|
+
|
|
214
|
+
1. A lexical leg queries `body`, which is the field that produces a passage.
|
|
215
|
+
2. A semantic leg runs when the index mapping is `semantic_text`.
|
|
216
|
+
3. The two legs are fused with reciprocal rank fusion in the plugin. The
|
|
217
|
+
engine refuses passages on a server-side hybrid query, so fusion happens
|
|
218
|
+
client-side.
|
|
219
|
+
4. Results are cut to the token budget and formatted with `path:line`
|
|
220
|
+
citations.
|
|
221
|
+
5. Brain hits get one hop of neighbors, using only `pathcite` and `sequence`
|
|
222
|
+
edges, capped and budgeted separately.
|
|
223
|
+
6. Brain paths are rewritten to project-relative paths before line resolution.
|
|
224
|
+
A hidden whole-file hit is dropped when a brain section covers that path, so
|
|
225
|
+
one file is cited from the precise section index.
|
|
226
|
+
|
|
227
|
+
Savings are measured, not asserted: the baseline is each cited file's size
|
|
228
|
+
capped at `stats.maxBaselineBytes`, counted once per session. Reading a file
|
|
229
|
+
subtracts the bytes actually read, so a partial read only removes what it
|
|
230
|
+
covered.
|
|
231
|
+
|
|
232
|
+
## Data locations
|
|
233
|
+
|
|
234
|
+
```
|
|
235
|
+
~/.local/share/opencode/xerj/bin/<version>-<target>/xerj
|
|
236
|
+
~/.local/share/opencode/xerj/data/ engine storage
|
|
237
|
+
~/.local/share/opencode/xerj/state/<prefix>/ autoindex journals
|
|
238
|
+
~/.local/share/opencode/xerj/spool/<prefix>/ fetched pages
|
|
239
|
+
<project>/.xerj/ marker and gitignore
|
|
240
|
+
~/.local/share/opencode/xerj/data/node.pid detached node
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
The node is detached and outlives OpenCode; indexing and memory survive
|
|
244
|
+
restarts. The plugin never kills it on unload.
|
|
245
|
+
|
|
246
|
+
## Limitations
|
|
247
|
+
|
|
248
|
+
- XERJ is pre-1.0. The plugin pins a release and isolates every call behind
|
|
249
|
+
`node/client.ts`; upgrades require the same major and never downgrade.
|
|
250
|
+
- `autoindex` skips hidden paths. `index.hidden` covers configured folders
|
|
251
|
+
(`.agents`, `.github`) through a separate `_bulk` index. `.git`, `.xerj`,
|
|
252
|
+
build output, virtualenvs, and secret-shaped files are always skipped.
|
|
253
|
+
- External files are indexed as plain text through `_bulk`; no AST or symbol
|
|
254
|
+
extraction.
|
|
255
|
+
- Shell references are detected heuristically: every literal argument of a
|
|
256
|
+
shell command that resolves to an existing regular file is indexed. Short
|
|
257
|
+
option values, variables, globs, tilde paths, and redirection targets are
|
|
258
|
+
not resolved, and `cd` is followed only within a simple
|
|
259
|
+
`cd dir && ...` chain.
|
|
260
|
+
- `autoindex` cannot watch a graph, so brains reindex on startup and on
|
|
261
|
+
`/xerj-reindex`, not on every edit.
|
|
262
|
+
- Anomaly scoring has no datafeed, timer, or alerting.
|
|
263
|
+
|
|
264
|
+
## Development
|
|
265
|
+
|
|
266
|
+
```bash
|
|
267
|
+
bun install
|
|
268
|
+
bun test test/unit # pure functions, no node needed
|
|
269
|
+
bun test test/integration # real node on a scratch data root (~5 s)
|
|
270
|
+
bun scripts/smoke.ts # download, spawn, attach, stop
|
|
271
|
+
bun run typecheck
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
Integration tests need a XERJ binary once; it is cached in
|
|
275
|
+
`~/.cache/opencode/xerj-int` (override with `XERJ_CACHE`, or point `XERJ_BIN`
|
|
276
|
+
at an existing build). CI runs the unit suite on Ubuntu and the integration
|
|
277
|
+
suite inside a container, preferring podman and falling back to docker.
|
|
278
|
+
|
|
279
|
+
The repo dogfoods its own plugin through `opencode.json`: `.agents` is indexed
|
|
280
|
+
both as a hidden corpus and as the example brain, which exercises the
|
|
281
|
+
duplicate-collapse path in retrieval.
|
|
282
|
+
|
|
283
|
+
## License
|
|
284
|
+
|
|
285
|
+
Apache-2.0.
|
package/package.json
CHANGED
|
@@ -1,6 +1,49 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mrdrmccoy/xerj-opencode-plugin",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "XERJ integration for OpenCode: local code and docs search, agent memory, and retrieval accounting.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./src/index.ts",
|
|
9
|
+
"./rpc": "./src/rpc.ts",
|
|
10
|
+
"./tui": "./src/tui.tsx"
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"src"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"typecheck": "tsc --noEmit",
|
|
17
|
+
"test": "bun test test/unit",
|
|
18
|
+
"test:unit": "bun test test/unit",
|
|
19
|
+
"test:integration": "bun test test/integration"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@opencode/plugin": "^2.2.5"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@opencode/theme": "^2.2.5",
|
|
26
|
+
"@opentui/core": "^0.8.0",
|
|
27
|
+
"@opentui/solid": "^0.8.0",
|
|
28
|
+
"@types/bun": "^1.4.3",
|
|
29
|
+
"@types/node": "^22.10.0",
|
|
30
|
+
"solid-js": "^1.9.17",
|
|
31
|
+
"typescript": "^5.7.0"
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"@opentui/core": ">=0.8.0",
|
|
35
|
+
"@opentui/solid": ">=0.8.0",
|
|
36
|
+
"solid-js": ">=1.9.0"
|
|
37
|
+
},
|
|
38
|
+
"peerDependenciesMeta": {
|
|
39
|
+
"@opentui/core": {
|
|
40
|
+
"optional": true
|
|
41
|
+
},
|
|
42
|
+
"@opentui/solid": {
|
|
43
|
+
"optional": true
|
|
44
|
+
},
|
|
45
|
+
"solid-js": {
|
|
46
|
+
"optional": true
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// Runtime detection. Everything that needs the host rather than the config
|
|
2
|
+
// lives here, so the release selection itself stays pure and testable.
|
|
3
|
+
|
|
4
|
+
import { execFile } from "node:child_process";
|
|
5
|
+
import { promisify } from "node:util";
|
|
6
|
+
import {
|
|
7
|
+
effectiveArch,
|
|
8
|
+
isRosetta,
|
|
9
|
+
platformInfoForTarget,
|
|
10
|
+
releaseTarget,
|
|
11
|
+
type Libc,
|
|
12
|
+
type PlatformInfo,
|
|
13
|
+
} from "../platform.ts";
|
|
14
|
+
|
|
15
|
+
const execFileAsync = promisify(execFile);
|
|
16
|
+
const SYSCTL_TIMEOUT_MS = 2_000;
|
|
17
|
+
|
|
18
|
+
export interface RuntimeTarget {
|
|
19
|
+
readonly platform: NodeJS.Platform;
|
|
20
|
+
readonly arch: string;
|
|
21
|
+
readonly rosetta: boolean;
|
|
22
|
+
readonly info: PlatformInfo | null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface DetectOptions {
|
|
26
|
+
readonly libc: Libc;
|
|
27
|
+
readonly target: string | null;
|
|
28
|
+
readonly env?: Readonly<Record<string, string | undefined>>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export async function detectRuntime(options: DetectOptions): Promise<RuntimeTarget> {
|
|
32
|
+
const platform = process.platform;
|
|
33
|
+
const rosetta = platform === "darwin" ? await detectRosetta() : false;
|
|
34
|
+
const arch = effectiveArch(platform, process.arch, options.env ?? process.env, rosetta);
|
|
35
|
+
|
|
36
|
+
const info = options.target
|
|
37
|
+
? platformInfoForTarget(options.target, platform)
|
|
38
|
+
: releaseTarget(platform, arch, rosetta, options.libc);
|
|
39
|
+
|
|
40
|
+
return { platform, arch, rosetta, info };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Apple Silicon running an x86_64 process under Rosetta 2. */
|
|
44
|
+
export async function detectRosetta(): Promise<boolean> {
|
|
45
|
+
if (process.platform !== "darwin") return false;
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
const { stdout } = await execFileAsync("sysctl", ["-n", "sysctl.proc_translated"], {
|
|
49
|
+
timeout: SYSCTL_TIMEOUT_MS,
|
|
50
|
+
});
|
|
51
|
+
return isRosetta(stdout);
|
|
52
|
+
} catch {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
}
|