opencode-memoir 1.0.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.
Potentially problematic release.
This version of opencode-memoir might be problematic. Click here for more details.
- package/LICENSE +201 -0
- package/README.md +175 -0
- package/dist/capture.d.ts +32 -0
- package/dist/capture.d.ts.map +1 -0
- package/dist/capture.js +232 -0
- package/dist/capture.js.map +1 -0
- package/dist/debug.d.ts +6 -0
- package/dist/debug.d.ts.map +1 -0
- package/dist/debug.js +11 -0
- package/dist/debug.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +464 -0
- package/dist/index.js.map +1 -0
- package/dist/recall-gate.d.ts +23 -0
- package/dist/recall-gate.d.ts.map +1 -0
- package/dist/recall-gate.js +65 -0
- package/dist/recall-gate.js.map +1 -0
- package/dist/store.d.ts +77 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +304 -0
- package/dist/store.js.map +1 -0
- package/package.json +54 -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,175 @@
|
|
|
1
|
+
# opencode-memoir
|
|
2
|
+
|
|
3
|
+
OpenCode plugin for [Memoir](https://github.com/zhangfengcdt/memoir): git-versioned, taxonomy-structured memory for coding agents.
|
|
4
|
+
|
|
5
|
+
The OpenCode counterpart to the Claude Code and Codex Memoir plugins. Derives a per-project store under `~/.memoir/<path-slug>`, resolves the `memoir` CLI with `uvx` fallback, and exposes commands/tools for status, recall, remember, and UI launch.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
Add to your OpenCode config (`~/.config/opencode/opencode.jsonc`):
|
|
10
|
+
|
|
11
|
+
```jsonc
|
|
12
|
+
{
|
|
13
|
+
"plugin": [
|
|
14
|
+
"npm:opencode-memoir"
|
|
15
|
+
]
|
|
16
|
+
}
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
OpenCode resolves the package via npm automatically; no manual download needed.
|
|
20
|
+
|
|
21
|
+
### Alternative: global install
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install -g opencode-memoir
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Then reference it by path in your config:
|
|
28
|
+
|
|
29
|
+
```jsonc
|
|
30
|
+
{
|
|
31
|
+
"plugin": [
|
|
32
|
+
"opencode-memoir"
|
|
33
|
+
]
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
The plugin auto-resolves the `memoir` CLI: first from `PATH`, then via `uvx --from memoir-ai==<pin> memoir` (no separate install needed).
|
|
38
|
+
|
|
39
|
+
## Quick start
|
|
40
|
+
|
|
41
|
+
1. Install the plugin (see above)
|
|
42
|
+
2. Run `/memoir:status` in any project to verify the store was created
|
|
43
|
+
3. Start saving memories with `/memoir:remember` or let the agent auto-capture
|
|
44
|
+
|
|
45
|
+
## Store configuration
|
|
46
|
+
|
|
47
|
+
The plugin uses the same environment variable as the Claude Code plugin:
|
|
48
|
+
|
|
49
|
+
| Source | Description |
|
|
50
|
+
|---|---|
|
|
51
|
+
| plugin option `store` | Highest-priority override when the plugin is loaded from `plugin[]` |
|
|
52
|
+
| `MEMOIR_STORE` | Portable global/project override |
|
|
53
|
+
| auto-derived path | `~/.memoir/<slug>`, where slug = git root (or resolved cwd) with `/` and `.` replaced by `-`; all worktrees share one store |
|
|
54
|
+
|
|
55
|
+
Example when loading through `plugin[]`:
|
|
56
|
+
|
|
57
|
+
```jsonc
|
|
58
|
+
{
|
|
59
|
+
"plugin": [
|
|
60
|
+
["npm:opencode-memoir", { "store": "/custom/store/path" }]
|
|
61
|
+
]
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Environment variables
|
|
66
|
+
|
|
67
|
+
All variables are optional. Capture and sanitization are on by default.
|
|
68
|
+
|
|
69
|
+
| Variable | Effect |
|
|
70
|
+
|---|---|
|
|
71
|
+
| `MEMOIR_STORE` | Override the derived store path (see above). |
|
|
72
|
+
| `MEMOIR_DEBUG=1` | Emit diagnostic logs to stderr (prefixed `[memoir]`). All internal errors are logged here instead of failing silently. Off by default. |
|
|
73
|
+
| `MEMOIR_NO_CAPTURE=1` | Disable all capture — no metrics, no code-change tracking, no branch auto-match flush. Superset switch. |
|
|
74
|
+
| `MEMOIR_NO_METRICS=1` | Disable per-tool metrics only (`metrics.turn.<branch>`). Code-change tracking still runs. |
|
|
75
|
+
| `MEMOIR_NO_CODE_SUMMARY=1` | Disable code-change tracking only (`metrics.code.<branch>`). Metrics still run. |
|
|
76
|
+
| `MEMOIR_SANITIZE_SECRETS=0` | Disable the secret-pattern guard on `memoir_remember`. Sanitization is **on** by default; set to `0` only if the guard produces false positives you understand. |
|
|
77
|
+
|
|
78
|
+
Capture guards are checked at the collection point (`tool.execute.after`) and the flush point (`chat.message`), so setting them mid-session takes effect on the next turn.
|
|
79
|
+
|
|
80
|
+
## Commands
|
|
81
|
+
|
|
82
|
+
| Command | Description |
|
|
83
|
+
|---|---|
|
|
84
|
+
| `/memoir:status` | Show status for the current project store, including project git branch metadata |
|
|
85
|
+
| `/memoir:ui` | Launch or reopen the Memoir web UI |
|
|
86
|
+
| `/memoir:remember <memory>` | Ask the agent to save an explicit durable memory with a semantic path |
|
|
87
|
+
| `/memoir:recall <topic>` | Ask the agent to list and use relevant stored memories |
|
|
88
|
+
| `/memoir:onboard` | Populate or refresh the project onboarding snapshot |
|
|
89
|
+
| `/memoir:unmerged` | List memoir branches that have diverged from `main` |
|
|
90
|
+
|
|
91
|
+
## Tools
|
|
92
|
+
|
|
93
|
+
| Tool | Description |
|
|
94
|
+
|---|---|
|
|
95
|
+
| `memoir_status` | Run the status helper |
|
|
96
|
+
| `memoir_remember` | Save explicit content to one or more semantic paths; refuses secret-like content |
|
|
97
|
+
| `memoir_recall` | List memory keys via `summarize` for relevance selection |
|
|
98
|
+
| `memoir_get` | Fetch selected exact keys after `memoir_recall` |
|
|
99
|
+
|
|
100
|
+
## Hooks
|
|
101
|
+
|
|
102
|
+
The plugin registers eight OpenCode hooks, mirroring the Claude Code plugin's lifecycle:
|
|
103
|
+
|
|
104
|
+
| Hook | Purpose |
|
|
105
|
+
|---|---|
|
|
106
|
+
| `config` | Registers slash commands |
|
|
107
|
+
| `command.execute.before` | Handles `/memoir:status`, `/memoir:ui`, `/memoir:unmerged` |
|
|
108
|
+
| `shell.env` | Injects `MEMOIR_STORE` into shell env |
|
|
109
|
+
| `event` | On `session.created`, fetches the taxonomy overview in the background |
|
|
110
|
+
| `tool.execute.after` | Accumulates per-tool metrics + file edits for code change audit |
|
|
111
|
+
| `chat.message` | Auto-matches memoir branch to git branch, flushes capture, runs recall gate |
|
|
112
|
+
| `experimental.chat.system.transform` | Injects taxonomy context + recall instruction |
|
|
113
|
+
| `dispose` | Flushes remaining data, prunes session state |
|
|
114
|
+
|
|
115
|
+
See the [Memoir docs](https://zhangfengcdt.github.io/memoir/) for detailed hook behaviour.
|
|
116
|
+
|
|
117
|
+
## Memoir CLI resolution
|
|
118
|
+
|
|
119
|
+
1. `memoir` on `PATH`
|
|
120
|
+
2. `uvx --from memoir-ai==<pin> memoir` — ephemeral, pinned
|
|
121
|
+
3. `uv tool run --from memoir-ai==<pin> memoir` — pinned fallback
|
|
122
|
+
|
|
123
|
+
Every command passes an explicit `-s <store>` to keep the project git and Memoir store separate.
|
|
124
|
+
|
|
125
|
+
## Development
|
|
126
|
+
|
|
127
|
+
### Prerequisites
|
|
128
|
+
|
|
129
|
+
- Node.js >= 20
|
|
130
|
+
- `memoir` CLI somewhere accessible, OR `uv` installed (the plugin falls back to `uvx`)
|
|
131
|
+
|
|
132
|
+
### Setup
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
npm install
|
|
136
|
+
npm run build # typecheck + emit dist
|
|
137
|
+
npm test # run the test suite (69 tests)
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### Source layout
|
|
141
|
+
|
|
142
|
+
| File | Responsibility |
|
|
143
|
+
|---|---|
|
|
144
|
+
| `src/store.ts` | CLI resolution + runner, git/worktree helpers, store-path derivation, branch management |
|
|
145
|
+
| `src/capture.ts` | Edit tracking, per-tool metrics, `flushCapture` (read-merge-write of `metrics.*`) |
|
|
146
|
+
| `src/recall-gate.ts` | Secret pattern + sanitization toggle, recall-gate trigger logic |
|
|
147
|
+
| `src/index.ts` | Plugin wiring — tool definitions, hooks, command registration |
|
|
148
|
+
| `src/debug.ts` | Shared debug logger |
|
|
149
|
+
|
|
150
|
+
### Tests
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
npm test
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
69 tests across 5 files. Run with `tsx --test` (handles `.js` → `.ts` resolution under NodeNext).
|
|
157
|
+
|
|
158
|
+
To debug hooks locally, run OpenCode with `MEMOIR_DEBUG=1` and watch stderr for `[memoir]` lines.
|
|
159
|
+
|
|
160
|
+
## Publishing
|
|
161
|
+
|
|
162
|
+
```bash
|
|
163
|
+
# Log in to npm (one-time)
|
|
164
|
+
npm login
|
|
165
|
+
|
|
166
|
+
# Bump version, build, test, publish
|
|
167
|
+
npm version patch # minor | major
|
|
168
|
+
npm publish
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
The `prepublishOnly` script runs `build` + `test` automatically. Published files are limited to `dist/` and `README.md` (see `files` in `package.json`).
|
|
172
|
+
|
|
173
|
+
## License
|
|
174
|
+
|
|
175
|
+
Apache-2.0
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export declare const EDIT_TOOLS: Set<string>;
|
|
2
|
+
export interface EditRecord {
|
|
3
|
+
tool: string;
|
|
4
|
+
filePath: string;
|
|
5
|
+
snippet: string;
|
|
6
|
+
timestamp: number;
|
|
7
|
+
}
|
|
8
|
+
export interface ToolMetrics {
|
|
9
|
+
calls: number;
|
|
10
|
+
errors: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Maximum entries retained in metrics.code.<branch>.
|
|
14
|
+
* Mirrors MEMOIR_METRICS_CODE_MAX from plugins/claude-code/hooks/stop.sh.
|
|
15
|
+
*/
|
|
16
|
+
export declare const METRICS_CODE_MAX = 1000;
|
|
17
|
+
export declare function getCachedBranch(sessionID: string): string;
|
|
18
|
+
export declare function setCachedBranch(sessionID: string, branch: string): void;
|
|
19
|
+
/** Record an edit for a specific session. */
|
|
20
|
+
export declare function recordEdit(sessionID: string, edit: EditRecord): void;
|
|
21
|
+
/** Accumulate tool metrics for a specific session (adds to previous values). */
|
|
22
|
+
export declare function recordToolMetrics(sessionID: string, tool: string, metrics: ToolMetrics): void;
|
|
23
|
+
/** Peek at a session's pending edits (test helper, read-only). */
|
|
24
|
+
export declare function getPendingEdits(sessionID: string): readonly EditRecord[];
|
|
25
|
+
/** Peek at a session's tool metrics (test helper, read-only). */
|
|
26
|
+
export declare function getToolMetrics(sessionID: string): ReadonlyMap<string, ToolMetrics>;
|
|
27
|
+
/** Clear all state for a session (test helper). */
|
|
28
|
+
export declare function clearSession(sessionID: string): void;
|
|
29
|
+
export declare function parseTurnMetrics(text: string): Map<string, ToolMetrics>;
|
|
30
|
+
export declare function serializeTurnMetrics(map: Map<string, ToolMetrics>): string;
|
|
31
|
+
export declare function flushCapture(store?: string, branch?: string, sessionID?: string): Promise<void>;
|
|
32
|
+
//# sourceMappingURL=capture.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capture.d.ts","sourceRoot":"","sources":["../src/capture.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,U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M,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAiIrG"}
|
package/dist/capture.js
ADDED
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import { deriveStorePath, ensureStore, getCurrentBranch, readMemoirValue, runMemoir } from './store.js';
|
|
2
|
+
import { debugLog } from './debug.js';
|
|
3
|
+
// ---------------------------------------------------------------------------
|
|
4
|
+
// Types
|
|
5
|
+
// ---------------------------------------------------------------------------
|
|
6
|
+
export const EDIT_TOOLS = new Set(['Edit', 'Write', 'MultiEdit', 'NotebookEdit', 'apply_patch', 'ApplyPatch', 'MultiFileEdit']);
|
|
7
|
+
/**
|
|
8
|
+
* Maximum entries retained in metrics.code.<branch>.
|
|
9
|
+
* Mirrors MEMOIR_METRICS_CODE_MAX from plugins/claude-code/hooks/stop.sh.
|
|
10
|
+
*/
|
|
11
|
+
export const METRICS_CODE_MAX = 1000;
|
|
12
|
+
// ---------------------------------------------------------------------------
|
|
13
|
+
// Per-session state
|
|
14
|
+
// ---------------------------------------------------------------------------
|
|
15
|
+
const pendingEditsBySession = new Map();
|
|
16
|
+
const toolMetricsBySession = new Map();
|
|
17
|
+
const cachedBranchBySession = new Map();
|
|
18
|
+
export function getCachedBranch(sessionID) {
|
|
19
|
+
return cachedBranchBySession.get(sessionID) ?? 'unknown';
|
|
20
|
+
}
|
|
21
|
+
export function setCachedBranch(sessionID, branch) {
|
|
22
|
+
cachedBranchBySession.set(sessionID, branch);
|
|
23
|
+
}
|
|
24
|
+
/** Record an edit for a specific session. */
|
|
25
|
+
export function recordEdit(sessionID, edit) {
|
|
26
|
+
let edits = pendingEditsBySession.get(sessionID);
|
|
27
|
+
if (!edits) {
|
|
28
|
+
edits = [];
|
|
29
|
+
pendingEditsBySession.set(sessionID, edits);
|
|
30
|
+
}
|
|
31
|
+
edits.push(edit);
|
|
32
|
+
}
|
|
33
|
+
/** Accumulate tool metrics for a specific session (adds to previous values). */
|
|
34
|
+
export function recordToolMetrics(sessionID, tool, metrics) {
|
|
35
|
+
let sessionMetrics = toolMetricsBySession.get(sessionID);
|
|
36
|
+
if (!sessionMetrics) {
|
|
37
|
+
sessionMetrics = new Map();
|
|
38
|
+
toolMetricsBySession.set(sessionID, sessionMetrics);
|
|
39
|
+
}
|
|
40
|
+
const prev = sessionMetrics.get(tool) ?? { calls: 0, errors: 0 };
|
|
41
|
+
sessionMetrics.set(tool, {
|
|
42
|
+
calls: prev.calls + metrics.calls,
|
|
43
|
+
errors: prev.errors + metrics.errors,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
/** Peek at a session's pending edits (test helper, read-only). */
|
|
47
|
+
export function getPendingEdits(sessionID) {
|
|
48
|
+
return pendingEditsBySession.get(sessionID) ?? [];
|
|
49
|
+
}
|
|
50
|
+
/** Peek at a session's tool metrics (test helper, read-only). */
|
|
51
|
+
export function getToolMetrics(sessionID) {
|
|
52
|
+
return toolMetricsBySession.get(sessionID) ?? new Map();
|
|
53
|
+
}
|
|
54
|
+
/** Clear all state for a session (test helper). */
|
|
55
|
+
export function clearSession(sessionID) {
|
|
56
|
+
pendingEditsBySession.delete(sessionID);
|
|
57
|
+
toolMetricsBySession.delete(sessionID);
|
|
58
|
+
cachedBranchBySession.delete(sessionID);
|
|
59
|
+
}
|
|
60
|
+
// ---------------------------------------------------------------------------
|
|
61
|
+
// parse / serialize
|
|
62
|
+
// ---------------------------------------------------------------------------
|
|
63
|
+
export function parseTurnMetrics(text) {
|
|
64
|
+
const result = new Map();
|
|
65
|
+
if (!text)
|
|
66
|
+
return result;
|
|
67
|
+
const parts = text.split('|');
|
|
68
|
+
for (const part of parts) {
|
|
69
|
+
const trimmed = part.trim();
|
|
70
|
+
if (!trimmed)
|
|
71
|
+
continue;
|
|
72
|
+
const [tool, callsStr, errorsStr] = trimmed.split(':');
|
|
73
|
+
if (!tool)
|
|
74
|
+
continue;
|
|
75
|
+
result.set(tool, {
|
|
76
|
+
calls: parseInt(callsStr, 10) || 0,
|
|
77
|
+
errors: parseInt(errorsStr, 10) || 0,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
return result;
|
|
81
|
+
}
|
|
82
|
+
export function serializeTurnMetrics(map) {
|
|
83
|
+
return [...map.entries()]
|
|
84
|
+
.map(([tool, m]) => `${tool}:${m.calls}:${m.errors}`)
|
|
85
|
+
.join(' | ');
|
|
86
|
+
}
|
|
87
|
+
// ---------------------------------------------------------------------------
|
|
88
|
+
// Per-store mutex
|
|
89
|
+
// ---------------------------------------------------------------------------
|
|
90
|
+
const flushQueues = new Map();
|
|
91
|
+
async function acquireFlushLock(store) {
|
|
92
|
+
const prev = flushQueues.get(store) ?? Promise.resolve();
|
|
93
|
+
let release;
|
|
94
|
+
const next = new Promise(resolve => { release = resolve; });
|
|
95
|
+
flushQueues.set(store, next);
|
|
96
|
+
await prev;
|
|
97
|
+
return () => {
|
|
98
|
+
release();
|
|
99
|
+
if (flushQueues.get(store) === next)
|
|
100
|
+
flushQueues.delete(store);
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
// ---------------------------------------------------------------------------
|
|
104
|
+
// ---------------------------------------------------------------------------
|
|
105
|
+
// flushCapture — flushes one session, or all if no sessionID
|
|
106
|
+
// ---------------------------------------------------------------------------
|
|
107
|
+
export async function flushCapture(store, branch, sessionID) {
|
|
108
|
+
// Determine which sessions to flush
|
|
109
|
+
const targets = sessionID
|
|
110
|
+
? [sessionID]
|
|
111
|
+
: [...pendingEditsBySession.keys()]; // dispose: flush all sessions
|
|
112
|
+
if (targets.length === 0)
|
|
113
|
+
return;
|
|
114
|
+
try {
|
|
115
|
+
store = store ?? deriveStorePath();
|
|
116
|
+
if (!store)
|
|
117
|
+
return;
|
|
118
|
+
await ensureStore(store);
|
|
119
|
+
// Acquire store-level mutex before touching per-session state.
|
|
120
|
+
// Prevents C1 (cross-session interleave) and C2-RACE (data arriving
|
|
121
|
+
// between snapshot and drain).
|
|
122
|
+
const releaseLock = await acquireFlushLock(store);
|
|
123
|
+
try {
|
|
124
|
+
const perSession = [];
|
|
125
|
+
const swappedSids = new Map(); // sid → index in perSession for rollback
|
|
126
|
+
for (const sid of targets) {
|
|
127
|
+
const idx = perSession.length;
|
|
128
|
+
const edits = pendingEditsBySession.get(sid) ?? [];
|
|
129
|
+
pendingEditsBySession.set(sid, []);
|
|
130
|
+
const metrics = toolMetricsBySession.get(sid) ?? new Map();
|
|
131
|
+
toolMetricsBySession.set(sid, new Map());
|
|
132
|
+
const sb = branch ?? cachedBranchBySession.get(sid);
|
|
133
|
+
perSession.push({ edits, metrics, sessionBranch: sb ?? 'unknown' });
|
|
134
|
+
swappedSids.set(sid, idx);
|
|
135
|
+
}
|
|
136
|
+
// Skip if nothing to flush
|
|
137
|
+
if (!perSession.some(p => p.edits.length > 0 || p.metrics.size > 0))
|
|
138
|
+
return;
|
|
139
|
+
// Wrap I/O in inner try — if it fails, restore swapped data before
|
|
140
|
+
// propagating the error so the next flush retries it.
|
|
141
|
+
try {
|
|
142
|
+
// Resolve 'unknown' branches (read-only I/O, safe inside lock —
|
|
143
|
+
// the lock serializes per-store CLI access)
|
|
144
|
+
for (const p of perSession) {
|
|
145
|
+
if (p.sessionBranch === 'unknown' || !p.sessionBranch) {
|
|
146
|
+
p.sessionBranch = await getCurrentBranch(store);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
// For each session, read-merge-write sequentially.
|
|
150
|
+
for (const p of perSession) {
|
|
151
|
+
const { edits, metrics, sessionBranch: branchKey } = p;
|
|
152
|
+
if (edits.length === 0 && metrics.size === 0)
|
|
153
|
+
continue;
|
|
154
|
+
const [prevCodeRaw, prevTurnRaw] = await Promise.all([
|
|
155
|
+
edits.length > 0 ? readMemoirValue(store, `metrics.code.${branchKey}`) : Promise.resolve(''),
|
|
156
|
+
metrics.size > 0 ? readMemoirValue(store, `metrics.turn.${branchKey}`) : Promise.resolve(''),
|
|
157
|
+
]);
|
|
158
|
+
let codeWrite;
|
|
159
|
+
if (edits.length > 0) {
|
|
160
|
+
const files = [...new Set(edits.map(e => e.filePath))];
|
|
161
|
+
const entry = {
|
|
162
|
+
timestamp: Date.now() / 1000,
|
|
163
|
+
summary: `Changed ${edits.length} block(s) across ${files.length} file(s): ${files.join(', ')}`,
|
|
164
|
+
files,
|
|
165
|
+
};
|
|
166
|
+
let acc = {
|
|
167
|
+
schema_version: 2, entries: [],
|
|
168
|
+
};
|
|
169
|
+
if (prevCodeRaw) {
|
|
170
|
+
try {
|
|
171
|
+
const parsed = JSON.parse(prevCodeRaw);
|
|
172
|
+
if (parsed?.entries && Array.isArray(parsed.entries)) {
|
|
173
|
+
acc = parsed;
|
|
174
|
+
if (acc.schema_version < 2)
|
|
175
|
+
acc.schema_version = 2;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
catch (e) {
|
|
179
|
+
debugLog('flushCapture: failed to parse existing code metrics, starting fresh:', e instanceof Error ? e.message : String(e));
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
acc.entries.push(entry);
|
|
183
|
+
if (acc.entries.length > METRICS_CODE_MAX)
|
|
184
|
+
acc.entries = acc.entries.slice(-METRICS_CODE_MAX);
|
|
185
|
+
codeWrite = runMemoir(['-s', store, 'remember', '--replace', JSON.stringify(acc), '-p', `metrics.code.${branchKey}`], { cwd: store });
|
|
186
|
+
}
|
|
187
|
+
let turnWrite;
|
|
188
|
+
if (metrics.size > 0) {
|
|
189
|
+
const existing = parseTurnMetrics(prevTurnRaw);
|
|
190
|
+
for (const [tool, current] of metrics) {
|
|
191
|
+
const prev = existing.get(tool) ?? { calls: 0, errors: 0 };
|
|
192
|
+
existing.set(tool, { calls: prev.calls + current.calls, errors: prev.errors + current.errors });
|
|
193
|
+
}
|
|
194
|
+
turnWrite = runMemoir(['-s', store, 'remember', '--replace', serializeTurnMetrics(existing), '-p', `metrics.turn.${branchKey}`], { cwd: store });
|
|
195
|
+
}
|
|
196
|
+
// Check writes for this session's pair
|
|
197
|
+
const results = await Promise.all([codeWrite, turnWrite].filter(Boolean));
|
|
198
|
+
for (const result of results) {
|
|
199
|
+
if (typeof result === 'string' && result.startsWith('Memoir command failed')) {
|
|
200
|
+
throw new Error(`Memoir write failed: ${result}`);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
catch (e) {
|
|
206
|
+
// Restore swapped data into pending maps so the next flush retries it.
|
|
207
|
+
// Entries accumulated during I/O by concurrent recordEdit/recordToolMetrics
|
|
208
|
+
// are preserved: we prepend the original entries, so ordering is maintained.
|
|
209
|
+
for (const [sid, idx] of swappedSids) {
|
|
210
|
+
const p = perSession[idx];
|
|
211
|
+
const currentEdits = pendingEditsBySession.get(sid) ?? [];
|
|
212
|
+
pendingEditsBySession.set(sid, [...p.edits, ...currentEdits]);
|
|
213
|
+
const merged = toolMetricsBySession.get(sid) ?? new Map();
|
|
214
|
+
for (const [tool, m] of p.metrics) {
|
|
215
|
+
const prev = merged.get(tool) ?? { calls: 0, errors: 0 };
|
|
216
|
+
merged.set(tool, { calls: prev.calls + m.calls, errors: prev.errors + m.errors });
|
|
217
|
+
}
|
|
218
|
+
toolMetricsBySession.set(sid, merged);
|
|
219
|
+
}
|
|
220
|
+
// Re-throw so the outer catch logs it
|
|
221
|
+
throw e;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
finally {
|
|
225
|
+
releaseLock();
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
catch (e) {
|
|
229
|
+
debugLog('flushCapture: failed:', e instanceof Error ? e.message : String(e));
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
//# sourceMappingURL=capture.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capture.js","sourceRoot":"","sources":["../src/capture.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,gBAAgB,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACxG,OAAO,EAAE,QAAQ,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