@mathew-cf/opencode-memory 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +126 -0
- package/dist/config.d.ts +47 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/constants.d.ts +31 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/hooks/guard.d.ts +78 -0
- package/dist/hooks/guard.d.ts.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13555 -0
- package/dist/lib/db.d.ts +32 -0
- package/dist/lib/db.d.ts.map +1 -0
- package/dist/lib/frontmatter.d.ts +49 -0
- package/dist/lib/frontmatter.d.ts.map +1 -0
- package/dist/lib/paths.d.ts +48 -0
- package/dist/lib/paths.d.ts.map +1 -0
- package/dist/lib/rag.d.ts +79 -0
- package/dist/lib/rag.d.ts.map +1 -0
- package/dist/lib/ripgrep.d.ts +32 -0
- package/dist/lib/ripgrep.d.ts.map +1 -0
- package/dist/lib/search-terms.d.ts +61 -0
- package/dist/lib/search-terms.d.ts.map +1 -0
- package/dist/tools/memory.d.ts +84 -0
- package/dist/tools/memory.d.ts.map +1 -0
- package/dist/tools/session.d.ts +103 -0
- package/dist/tools/session.d.ts.map +1 -0
- package/package.json +47 -0
- package/skills/opencode-memory/SKILL.md +295 -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,126 @@
|
|
|
1
|
+
# @mathew-cf/opencode-memory
|
|
2
|
+
|
|
3
|
+
Persistent cross-session memory for [OpenCode](https://opencode.ai).
|
|
4
|
+
|
|
5
|
+
This plugin gives the agent a durable knowledge base rooted at `~/opencode-memory/` — a git-tracked tree of markdown notes — plus read access to its own past sessions. A hybrid keyword + semantic search layer surfaces relevant notes before work starts, and a guard hook nudges the agent to save reusable discoveries as it goes.
|
|
6
|
+
|
|
7
|
+
## Why
|
|
8
|
+
|
|
9
|
+
LLM agents forget everything between sessions. That means rediscovering the same repo structure, tool quirks, and gotchas over and over. This plugin gives them a place to put that knowledge and a strong enough social contract (tool-call tracking, compaction-time retrospectives) that they actually use it.
|
|
10
|
+
|
|
11
|
+
## What you get
|
|
12
|
+
|
|
13
|
+
| Category | Additions |
|
|
14
|
+
| ------------------ | ------------------------------------------------------------------------- |
|
|
15
|
+
| **Memory tools** | `memory_search`, `memory_list`, `memory_save`, `memory_access`, `memory_setup` |
|
|
16
|
+
| **Session tools** | `session_search`, `session_read`, `session_list` |
|
|
17
|
+
| **Hooks** | Search-first nudge at 8 tool calls; discovery nudge on subagent outputs; retrospective reminder at compaction time |
|
|
18
|
+
| **Skill** | `opencode-memory` (auto-registered via the `skills.paths` config) |
|
|
19
|
+
| **Agent prompts** | Built-in subagents (`general`, `explore`, `research`, `review`, `investigator`) get a memory-aware prompt prepended non-destructively |
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
```jsonc
|
|
24
|
+
// opencode.jsonc
|
|
25
|
+
{
|
|
26
|
+
"plugin": ["@mathew-cf/opencode-memory@0.2.0"]
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
The plugin auto-registers:
|
|
31
|
+
|
|
32
|
+
- its bundled skill under `config.skills.paths`
|
|
33
|
+
- edit + external-directory permissions for `~/opencode-memory/**`
|
|
34
|
+
- memory-aware prompt prefixes on the five built-in subagents (only when their prompt isn't already set)
|
|
35
|
+
|
|
36
|
+
### Search backends
|
|
37
|
+
|
|
38
|
+
`memory_search` combines two complementary signals:
|
|
39
|
+
|
|
40
|
+
| Backend | Package | Purpose |
|
|
41
|
+
| ---------------------- | --------------------------- | ------------------------------------ |
|
|
42
|
+
| **Keyword (ripgrep)** | `@vscode/ripgrep` | Exact-match + phrase lookup over files |
|
|
43
|
+
| **Semantic (rag-cli)** | `@mathew-cf/rag-cli` | Similarity search via local embeddings |
|
|
44
|
+
|
|
45
|
+
Both are declared as **required dependencies**: installing the plugin pulls in prebuilt binaries for your platform automatically (macOS ARM64/x64, Linux x64/ARM64; ripgrep additionally covers Windows and FreeBSD). No Rust toolchain, no `brew install`, no `$PATH` plumbing.
|
|
46
|
+
|
|
47
|
+
Pre-cache the embedding model once (~90MB) to make the first semantic search instant:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
rag download
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
If either dependency fails to install (unusual — usually indicates an unsupported platform), the plugin transparently degrades. `memory_setup` reports which backends are resolvable and prints targeted install guidance for each.
|
|
54
|
+
|
|
55
|
+
## Usage
|
|
56
|
+
|
|
57
|
+
### First-time setup
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
mkdir -p ~/opencode-memory
|
|
61
|
+
cd ~/opencode-memory && git init
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Categories are conventional directories under the root — `preferences/`, `repos/`, `technical/`, `people/`, `workflows/`, `snippets/`, `notes/`. They're advisory, not enforced.
|
|
65
|
+
|
|
66
|
+
### Writing memory
|
|
67
|
+
|
|
68
|
+
Memory files are plain markdown with a small frontmatter block:
|
|
69
|
+
|
|
70
|
+
```markdown
|
|
71
|
+
---
|
|
72
|
+
title: Framework uses custom error hierarchy
|
|
73
|
+
tags: [framework, error-handling]
|
|
74
|
+
summary: All errors must extend AppError; plain Error bypasses formatting
|
|
75
|
+
created: 2025-01-15
|
|
76
|
+
updated: 2025-01-15
|
|
77
|
+
importance: high
|
|
78
|
+
source: Code inspection of src/errors/
|
|
79
|
+
source_date: 2025-01-15
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
All errors in `src/errors/` must extend `AppError`. Throwing plain `Error`
|
|
83
|
+
bypasses the error formatter → raw 500s. Gotcha: `AuthError` must include a
|
|
84
|
+
`realm` field or auth middleware silently ignores it.
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
After writing or editing files, call `memory_save` — it runs `git add -A` + commit and kicks off a background `rag index` re-build.
|
|
88
|
+
|
|
89
|
+
### Searching
|
|
90
|
+
|
|
91
|
+
```
|
|
92
|
+
memory_search("retry jitter") # hybrid rg + rag
|
|
93
|
+
memory_search("auth", category="repos") # filter to a category
|
|
94
|
+
memory_list() # browse categories + counts
|
|
95
|
+
memory_list("technical") # list files in one category
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
See the bundled skill (`skills/opencode-memory/SKILL.md`) for the full protocol.
|
|
99
|
+
|
|
100
|
+
## How the guard hook works
|
|
101
|
+
|
|
102
|
+
The plugin installs two hooks:
|
|
103
|
+
|
|
104
|
+
### `tool.execute.after`
|
|
105
|
+
Tracks tool usage per session and injects short reminders into tool output when:
|
|
106
|
+
|
|
107
|
+
- **8 tool calls deep with no search**: reminds the agent to call `memory_search` and `session_search` before going further.
|
|
108
|
+
- **A subagent's output contains "Discoveries worth saving"**: reminds the parent to actually save them, not defer to session end.
|
|
109
|
+
|
|
110
|
+
Reminders fire at most once per session each to avoid spam.
|
|
111
|
+
|
|
112
|
+
### `experimental.session.compacting`
|
|
113
|
+
Injects memory-specific preservation rules so references to saved files and search results survive summarization. If the session is >10 tool calls and never called `memory_save`, adds a retrospective reminder.
|
|
114
|
+
|
|
115
|
+
## Development
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
bun install
|
|
119
|
+
bun run typecheck # tsc --noEmit
|
|
120
|
+
bun test # 118 tests across 7 files
|
|
121
|
+
bun run build # bundle to dist/
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## License
|
|
125
|
+
|
|
126
|
+
Apache-2.0 — see [LICENSE](LICENSE).
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Config hook: registers the skill path, sets agent prompts, and adds
|
|
3
|
+
* permission rules so the memory tools can actually touch the memory dir.
|
|
4
|
+
*
|
|
5
|
+
* Everything here is **additive and non-destructive**: if the user has
|
|
6
|
+
* already set a value (e.g. a custom `agent.general.prompt`), we prepend
|
|
7
|
+
* or leave their value alone rather than overwriting. That lets users
|
|
8
|
+
* layer this plugin on top of their own config without surprises.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* The snippet appended to subagent prompts. Captured in one place so
|
|
12
|
+
* tests can snapshot it and users can `Edit` it locally if they want a
|
|
13
|
+
* different emphasis.
|
|
14
|
+
*/
|
|
15
|
+
export declare const MEMORY_PROMPT_APPENDIX = "## Memory & Sessions\n\n1. **Before work:** call `memory_search` and `session_search` with your topic. Read results \u2014 don't just glance at summaries.\n2. **When something is unfamiliar mid-task** (tool, API, pattern, build system): search both `memory_search` and `session_search` BEFORE attempting. Use previous sessions to inform your approach \u2014 don't try first, search first.\n3. **When you discover something reusable:** write to ~/opencode-memory/{category}/{filename}.md and `memory_save` immediately. Never defer, never ask.\n\nIf you can't write to memory, end your response with:\n## Discoveries worth saving\n- [list findings that took >1 min to figure out]\n\n## Ground in code\n\nNEVER answer questions about a codebase from training data. Always open the actual files first.";
|
|
16
|
+
/**
|
|
17
|
+
* Subagents that should get the memory prompt appendix. These are the
|
|
18
|
+
* built-in subagent names used by OpenCode — custom agents are left alone.
|
|
19
|
+
*/
|
|
20
|
+
export declare const TARGET_AGENTS: readonly ["general", "explore", "research", "review", "investigator"];
|
|
21
|
+
/**
|
|
22
|
+
* Explore needs explicit permission to call memory_search/session_search
|
|
23
|
+
* because its built-in allowlist doesn't include them.
|
|
24
|
+
*/
|
|
25
|
+
export declare const EXPLORE_PERMISSIONS: Record<string, string>;
|
|
26
|
+
interface ConfigLike {
|
|
27
|
+
agent?: Record<string, unknown>;
|
|
28
|
+
skills?: {
|
|
29
|
+
paths?: string[];
|
|
30
|
+
urls?: string[];
|
|
31
|
+
};
|
|
32
|
+
permission?: {
|
|
33
|
+
edit?: Record<string, unknown> | string;
|
|
34
|
+
external_directory?: Record<string, unknown> | string;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Apply the plugin's config additions to a raw config object. Exported
|
|
39
|
+
* separately from the plugin entry so tests can feed a plain object in
|
|
40
|
+
* and assert on the result without constructing a full plugin context.
|
|
41
|
+
*/
|
|
42
|
+
export declare function applyConfig(config: ConfigLike, options: {
|
|
43
|
+
skillsDir?: string;
|
|
44
|
+
memoryDir?: string;
|
|
45
|
+
}): void;
|
|
46
|
+
export {};
|
|
47
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,kyBAY6D,CAAC;AAEjG;;;GAGG;AACH,eAAO,MAAM,aAAa,uEAMhB,CAAC;AAEX;;;GAGG;AACH,eAAO,MAAM,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAOtD,CAAC;AAEF,UAAU,UAAU;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,MAAM,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC;IAC/C,UAAU,CAAC,EAAE;QACX,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC;QACxC,kBAAkB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC;KACvD,CAAC;CACH;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,UAAU,EAClB,OAAO,EAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,GAClD,IAAI,CA6DN"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared constants for the opencode-memory plugin.
|
|
3
|
+
*
|
|
4
|
+
* Kept in one place so tests can import the same canonical values.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Categories are the top-level folders under the memory directory. They are
|
|
8
|
+
* advisory — users are free to create additional categories — but the search
|
|
9
|
+
* and list tools surface these by default, so they also double as the shape
|
|
10
|
+
* of the knowledge base we document and nudge agents toward.
|
|
11
|
+
*/
|
|
12
|
+
export declare const CATEGORIES: readonly ["preferences", "repos", "technical", "people", "workflows", "snippets", "notes"];
|
|
13
|
+
export type Category = (typeof CATEGORIES)[number];
|
|
14
|
+
/**
|
|
15
|
+
* Default directory, relative to the user's home, where memory files live.
|
|
16
|
+
* The `MEMORY_DIR` env var overrides this (primarily for tests).
|
|
17
|
+
*/
|
|
18
|
+
export declare const DEFAULT_MEMORY_SUBDIR = "opencode-memory";
|
|
19
|
+
/**
|
|
20
|
+
* Name of the ripgrep-invisible subdirectory used to store the semantic search
|
|
21
|
+
* index (if `rag` is installed). Bundled inside the memory root so that the
|
|
22
|
+
* index travels with whatever sync mechanism backs the knowledge base.
|
|
23
|
+
*/
|
|
24
|
+
export declare const RAG_INDEX_SUBDIR = ".rag";
|
|
25
|
+
/**
|
|
26
|
+
* Short words filtered out of search queries so a stray "the" doesn't
|
|
27
|
+
* dominate ranking. Intentionally minimal — better to let the user decide
|
|
28
|
+
* what's meaningful than to over-filter.
|
|
29
|
+
*/
|
|
30
|
+
export declare const STOP_WORDS: Set<string>;
|
|
31
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;GAKG;AACH,eAAO,MAAM,UAAU,4FAQb,CAAC;AAEX,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC;AAEnD;;;GAGG;AACH,eAAO,MAAM,qBAAqB,oBAAoB,CAAC;AAEvD;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,SAAS,CAAC;AAEvC;;;;GAIG;AACH,eAAO,MAAM,UAAU,aAYrB,CAAC"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory Guard — nudge agents to follow the memory protocol.
|
|
3
|
+
*
|
|
4
|
+
* Responsibilities:
|
|
5
|
+
* 1. Track `memory_search`, `session_search`, and `memory_save` calls per session.
|
|
6
|
+
* 2. After tool calls, inject contextual reminders:
|
|
7
|
+
* - If >8 tool calls without any `memory_search` or `session_search`,
|
|
8
|
+
* remind the agent to search before going deeper.
|
|
9
|
+
* - If a subagent's output contains "Discoveries worth saving",
|
|
10
|
+
* remind the parent to actually save them.
|
|
11
|
+
* 3. On session compaction, inject memory-specific context preservation
|
|
12
|
+
* rules and a retrospective reminder if no memory saves have happened.
|
|
13
|
+
*
|
|
14
|
+
* This file is plain logic — the tool name matching is by default suffix
|
|
15
|
+
* so it works whether the tool is registered as `memory_search` (plugin
|
|
16
|
+
* export), `opencode-memory_memory_search` (custom-tool filename), or some
|
|
17
|
+
* other variant. That gives us one hook file that's robust to renames.
|
|
18
|
+
*/
|
|
19
|
+
export interface SessionState {
|
|
20
|
+
toolCalls: number;
|
|
21
|
+
memorySearched: boolean;
|
|
22
|
+
sessionSearched: boolean;
|
|
23
|
+
memorySaved: boolean;
|
|
24
|
+
saveCount: number;
|
|
25
|
+
discoveryNudged: boolean;
|
|
26
|
+
searchNudged: boolean;
|
|
27
|
+
}
|
|
28
|
+
/** Initial state for a fresh session. Exported so tests can compare. */
|
|
29
|
+
export declare function makeInitialState(): SessionState;
|
|
30
|
+
/**
|
|
31
|
+
* Normalized check for whether a tool name matches one of the memory/session
|
|
32
|
+
* tools. Accepts both bare names (`memory_search`) and namespaced variants
|
|
33
|
+
* (`opencode-memory.memory_search` or similar). Exported for tests.
|
|
34
|
+
*/
|
|
35
|
+
export declare function matchesToolName(toolName: string, candidates: string[]): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* After-tool-call reducer. Updates state and returns any reminder text to
|
|
38
|
+
* append to the tool's output. Returns `null` if no reminder should fire.
|
|
39
|
+
*
|
|
40
|
+
* Kept as a pure function on `(state, input) -> reminder | null` so tests
|
|
41
|
+
* can reason about the nudge timing without plumbing through a full plugin
|
|
42
|
+
* context.
|
|
43
|
+
*/
|
|
44
|
+
export declare function afterToolUpdate(state: SessionState, input: {
|
|
45
|
+
tool: string;
|
|
46
|
+
output: string;
|
|
47
|
+
}): string | null;
|
|
48
|
+
/**
|
|
49
|
+
* Build the compaction context that should survive a session summarization
|
|
50
|
+
* so the next post-compaction turn still knows about memory pointers and
|
|
51
|
+
* unfinished retrospectives. Pure function, easy to snapshot in tests.
|
|
52
|
+
*/
|
|
53
|
+
export declare function buildCompactionContext(state: SessionState): string;
|
|
54
|
+
/**
|
|
55
|
+
* Factory that returns the two hook callbacks (`tool.execute.after` and
|
|
56
|
+
* `experimental.session.compacting`) plus the backing state map. The map
|
|
57
|
+
* is returned so tests can introspect per-session state directly.
|
|
58
|
+
*/
|
|
59
|
+
export declare function createGuardHooks(): {
|
|
60
|
+
sessions: Map<string, SessionState>;
|
|
61
|
+
getState: (sessionId: string) => SessionState;
|
|
62
|
+
toolAfter: (input: {
|
|
63
|
+
tool: string;
|
|
64
|
+
args: unknown;
|
|
65
|
+
sessionID?: string;
|
|
66
|
+
}, output: {
|
|
67
|
+
title?: string;
|
|
68
|
+
output?: string;
|
|
69
|
+
metadata?: unknown;
|
|
70
|
+
}) => Promise<void>;
|
|
71
|
+
compacting: (input: {
|
|
72
|
+
sessionID: string;
|
|
73
|
+
}, output: {
|
|
74
|
+
context: string[];
|
|
75
|
+
prompt?: string;
|
|
76
|
+
}) => Promise<void>;
|
|
77
|
+
};
|
|
78
|
+
//# sourceMappingURL=guard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guard.d.ts","sourceRoot":"","sources":["../../src/hooks/guard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,OAAO,CAAC;IACxB,eAAe,EAAE,OAAO,CAAC;IACzB,WAAW,EAAE,OAAO,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,EAAE,OAAO,CAAC;IACzB,YAAY,EAAE,OAAO,CAAC;CACvB;AAED,wEAAwE;AACxE,wBAAgB,gBAAgB,IAAI,YAAY,CAU/C;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAAE,GACnB,OAAO,CAGT;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,YAAY,EACnB,KAAK,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GACtC,MAAM,GAAG,IAAI,CAmDf;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,YAAY,GAAG,MAAM,CAwBlE;AAID;;;;GAIG;AACH,wBAAgB,gBAAgB;;0BAGD,MAAM,KAAG,YAAY;uBAavC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,OAAO,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,UAClD;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE;wBAaxD;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,UACpB;QAAE,OAAO,EAAE,MAAM,EAAE,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE;EAOnD"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenCode Memory Plugin — persistent cross-session memory.
|
|
3
|
+
*
|
|
4
|
+
* Wires up:
|
|
5
|
+
* - 4 memory tools (search / list / save / access / setup)
|
|
6
|
+
* - 3 session tools (search / read / list)
|
|
7
|
+
* - 2 hooks (tool.execute.after guard + compaction context injection)
|
|
8
|
+
* - Config modifications (skill path, agent prompts, permission rules)
|
|
9
|
+
*/
|
|
10
|
+
import type { Plugin } from "@opencode-ai/plugin";
|
|
11
|
+
declare const MemoryPlugin: Plugin;
|
|
12
|
+
export default MemoryPlugin;
|
|
13
|
+
export { applyConfig, MEMORY_PROMPT_APPENDIX, TARGET_AGENTS } from "./config";
|
|
14
|
+
export { afterToolUpdate, buildCompactionContext, createGuardHooks, makeInitialState, matchesToolName, type SessionState, } from "./hooks/guard";
|
|
15
|
+
export * as memoryTools from "./tools/memory";
|
|
16
|
+
export * as sessionTools from "./tools/session";
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AA6BlD,QAAA,MAAM,YAAY,EAAE,MA+BnB,CAAC;AAEF,eAAe,YAAY,CAAC;AAG5B,OAAO,EAAE,WAAW,EAAE,sBAAsB,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAC9E,OAAO,EACL,eAAe,EACf,sBAAsB,EACtB,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,EACf,KAAK,YAAY,GAClB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,WAAW,MAAM,gBAAgB,CAAC;AAC9C,OAAO,KAAK,YAAY,MAAM,iBAAiB,CAAC"}
|