@mnmal-ai/cortext-opencode 0.0.0-stage → 1.0.0-alpha.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 +202 -0
- package/README.md +120 -2
- package/commands/substrate-setup.md +217 -0
- package/dist/plugin.js +6327 -0
- package/instructions/substrate-conventions.md +192 -0
- package/package.json +43 -3
- package/skills/council/SKILL.md +42 -0
- package/skills/todos/SKILL.md +42 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,121 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @mnmal-ai/cortext-opencode — Cortext for OpenCode
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The OpenCode skin for the [Cortext](../cortext/README.md) coordination
|
|
4
|
+
capability: the same synoptic cold-start (Concepts, Agent Memory, Open Work,
|
|
5
|
+
Agent Rules, Inbox) the Claude Code skin injects, delivered through a
|
|
6
|
+
`context` session hook on first dispatch per session (OpenCode 2.x
|
|
7
|
+
`Plugin.define({ id, setup })`; a V1 `server()` entrypoint is bundled for
|
|
8
|
+
OpenCode 1.x compat).
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
1. Plugin entry in the repo's `opencode.json`. The object form carries
|
|
13
|
+
per-project identity — `options.kid` / `options.key` win over the
|
|
14
|
+
`SUBSTRATE_AGENT_*` env pair:
|
|
15
|
+
|
|
16
|
+
```json
|
|
17
|
+
{
|
|
18
|
+
"$schema": "https://opencode.ai/config.json",
|
|
19
|
+
"plugins": [
|
|
20
|
+
{
|
|
21
|
+
"package": "@mnmal-ai/cortext-opencode",
|
|
22
|
+
"options": {
|
|
23
|
+
"kid": "synoptic-opencode@YourHost",
|
|
24
|
+
"key": "/home/you/.config/substrate/keys/synoptic-opencode.key"
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
]
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
The plain string form (`"plugins": ["@mnmal-ai/cortext-opencode"]`) also
|
|
32
|
+
works — identity then comes from the env pair. **Keep exactly one entry
|
|
33
|
+
per package**: as of opencode v2.0.24 the `plugins`
|
|
34
|
+
arrays concatenate across global + project config and loads dedupe only
|
|
35
|
+
by exact source string, so a global string entry plus a project object
|
|
36
|
+
entry for the same package load the plugin twice and double-inject the
|
|
37
|
+
cold-start. When adding the object entry, remove the global string entry.
|
|
38
|
+
|
|
39
|
+
npm plugins install automatically via Bun at startup. This package is
|
|
40
|
+
public on npmjs.com, as is the `@mnmal-ai/substrate` dep; no token needed.
|
|
41
|
+
|
|
42
|
+
2. MCP server — merge into the same `opencode.json` (see
|
|
43
|
+
`commands/substrate-setup.md` Step 4 for the full procedure). **The MCP server
|
|
44
|
+
must sign as the same identity as the plugin**: the plugin shows
|
|
45
|
+
mail for its `options.kid`, and only that kid may ack it. With
|
|
46
|
+
`options.kid`/`options.key`, give the MCP `environment` the same kid and
|
|
47
|
+
key, as literals in a user-level config rather than `{env:…}` refs that a
|
|
48
|
+
GUI launch leaves empty:
|
|
49
|
+
|
|
50
|
+
```json
|
|
51
|
+
{
|
|
52
|
+
"mcp": {
|
|
53
|
+
"servers": {
|
|
54
|
+
"substrate": {
|
|
55
|
+
"type": "local",
|
|
56
|
+
"command": ["npx", "-y", "@mnmal-ai/substrate", "mcp"],
|
|
57
|
+
"codemode": false,
|
|
58
|
+
"environment": {
|
|
59
|
+
"SUBSTRATE_URL": "https://substrate.example.com:3100",
|
|
60
|
+
"SUBSTRATE_AGENT_KEY_PATH": "{env:SUBSTRATE_AGENT_KEY_PATH}",
|
|
61
|
+
"SUBSTRATE_AGENT_KEY_ID": "{env:SUBSTRATE_AGENT_KEY_ID}"
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
`"codemode": false` matters: OpenCode 2.x otherwise hides the
|
|
70
|
+
server's tools behind its `execute` tool, so the agent never sees
|
|
71
|
+
them and cannot ack mail. With it off they arrive prefixed by the server
|
|
72
|
+
name: `substrate_query`, `substrate_whoami`, and so on. On OpenCode 1.x use bare `mcp.substrate`
|
|
73
|
+
without `codemode`.
|
|
74
|
+
|
|
75
|
+
3. Conventions — nothing to do. The plugin injects the conventions from its
|
|
76
|
+
own package on every dispatch, so they always match the installed
|
|
77
|
+
version. An older hand-copied `.opencode/substrate-conventions.md` is named in
|
|
78
|
+
the session context as stale; delete it and its `"instructions"` entry.
|
|
79
|
+
|
|
80
|
+
4. Restart opencode (config loads once at startup). Or run `/substrate-setup`
|
|
81
|
+
(copy `commands/substrate-setup.md` to `.opencode/commands/`) for the guided
|
|
82
|
+
version of all of the above plus capability probing, AgentRule seeding,
|
|
83
|
+
identity provisioning, and the first anchor.
|
|
84
|
+
|
|
85
|
+
## Environment
|
|
86
|
+
|
|
87
|
+
| Var | Meaning | Default |
|
|
88
|
+
|---|---|---|
|
|
89
|
+
| `SUBSTRATE_URL` | Substrate base URL (required for live context) | — (offline note) |
|
|
90
|
+
| `SUBSTRATE_NAMESPACE` | Coordinator namespace | `cortext` |
|
|
91
|
+
| `SYNOPTIC_PROJECT_SCOPE=all` | Cross-project scope (omit project filter) | repo basename |
|
|
92
|
+
| `SUBSTRATE_AGENT_KEY_PATH` / `SUBSTRATE_AGENT_KEY_ID` | Ed25519 identity for signed reads + mail | anonymous |
|
|
93
|
+
| plugin-config `options.kid` / `options.key` | V2 object plugin entry identity — wins over the env pair, per-project, survives GUI launch where shell env does not. **All or nothing**: setting either uses the options pair only, never half from env | falls back to the env pair |
|
|
94
|
+
| plugin-config `options.url` / `options.ns` | Override `SUBSTRATE_URL` / `SUBSTRATE_NAMESPACE` for the plugin, for a launch whose process env carries neither | the env values |
|
|
95
|
+
| `MEMORY_*` / `RULE_SALIENCE` | Recall tunables, same as the Claude hooks | host defaults |
|
|
96
|
+
| `SYNOPTIC_INBOX_PUSH` | `off` disables mid-turn push (V2); the prompt and end-of-turn seams carry on | on |
|
|
97
|
+
| `SYNOPTIC_INBOX_WAKE` | `on` lets new mail start a turn in an idle session (6 per hour, 2 per thread) | off |
|
|
98
|
+
| `SYNOPTIC_INBOX_URGENT_FROM` | Comma-separated kids whose `priority:urgent` mail may interrupt a turn (3 per hour, 20 s grace for a running tool) | unset |
|
|
99
|
+
|
|
100
|
+
## How it maps to the Claude skin
|
|
101
|
+
|
|
102
|
+
| Claude (`cortext-plugin`) | OpenCode (this package) |
|
|
103
|
+
|---|---|
|
|
104
|
+
| `SessionStart` hook → `hooks/cold-start.mjs` | `prompt` prewarm + `context` session-hook inject (once per session, cached; V1 compat via `experimental.chat.system.transform`) |
|
|
105
|
+
| `UserPromptSubmit` inbox re-check | V2: each prompt after the first re-reads unread mail, and every dispatch of that turn carries the same summary line. `SYNOPTIC_INBOX_PROMPT_CHECK=off` disables it |
|
|
106
|
+
| `Stop` inbox check (blocks once) | V2: a `session.execution.succeeded` event with unread mail queues one synthetic message carrying the same reason, with `resume: true`. Each message id nudges once. `SYNOPTIC_INBOX_STOP_CHECK=off` disables it |
|
|
107
|
+
| Mid-turn push (`inbox-bridge`) | V2: the watcher runs in-process; new mail is steered into every busy session, allowlisted urgent mail preempts the most recently prompted session, and idle wake is opt-in. While the watcher is live the per-prompt summary is skipped; the end-of-turn nudge stays |
|
|
108
|
+
| `skills/{council,todos}` | `skills/{council,todos}` — byte-identical pointer bodies (`test/skills-sync.test.ts` enforces) |
|
|
109
|
+
| `fragments/substrate-conventions.md` | `instructions/substrate-conventions.md` — shared body, own marker (`test/instructions-sync.test.ts` enforces) |
|
|
110
|
+
| `/substrate-setup` skill | `commands/substrate-setup.md` — opencode paths + MCP dialect |
|
|
111
|
+
| SessionStart `compact` re-run | `compaction` session hook: drops the cache (next dispatch rebuilds) + leaves a pointer in the summary |
|
|
112
|
+
| Fragment-drift watchdog | **Deferred** — the check reads the `.claude/` install path; see `src/plugin.ts` header |
|
|
113
|
+
|
|
114
|
+
## Build
|
|
115
|
+
|
|
116
|
+
`dist/plugin.js` is a committed, byte-deterministic tsdown bundle with zero
|
|
117
|
+
runtime deps (same convention as `cortext-plugin/hooks/*.mjs`): `pnpm build
|
|
118
|
+
&& git diff --stat dist/` must return empty. The `@opencode-ai/plugin`
|
|
119
|
+
import is type-only; `@opencode/plugin` is imported from its dependency-free
|
|
120
|
+
`promise/plugin` deep module (`define` is an identity function), so the
|
|
121
|
+
bundle stays self-contained.
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Onboard this repo as a Cortext consumer under OpenCode. Probes the target Substrate, wires the substrate MCP server in opencode.json (identity-ready), installs the conventions instructions, and seeds baseline AgentRules. Run once per repo.
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# /substrate-setup (OpenCode) — onboard a cortext-opencode consumer
|
|
6
|
+
|
|
7
|
+
Run these steps in order. This command is **idempotent** — re-running it never duplicates config entries or rules.
|
|
8
|
+
|
|
9
|
+
Steps 2, 5, 6, 8 are transport-agnostic and identical to the Claude skin's
|
|
10
|
+
`/substrate-setup`; only the file paths and the MCP dialect differ. Where this
|
|
11
|
+
document says "same as", it means it — do not improvise a second procedure.
|
|
12
|
+
|
|
13
|
+
## Step 1 — get SUBSTRATE_URL + identity env
|
|
14
|
+
|
|
15
|
+
Ask the user for their Substrate base URL (e.g. `https://substrate.example.com:3100`)
|
|
16
|
+
unless it is already exported in their shell.
|
|
17
|
+
|
|
18
|
+
The OpenCode skin reads `SUBSTRATE_URL`, `SUBSTRATE_NAMESPACE` (default `cortext`),
|
|
19
|
+
`SUBSTRATE_AGENT_KEY_PATH` and `SUBSTRATE_AGENT_KEY_ID` from the **opencode process
|
|
20
|
+
environment** — both for cold-start injection and, via `{env:VAR}` refs, for
|
|
21
|
+
the MCP server below. The recommended arrangement is one block above all
|
|
22
|
+
repos (same as the Claude skin's Step 7.2):
|
|
23
|
+
|
|
24
|
+
```toml
|
|
25
|
+
[env]
|
|
26
|
+
SUBSTRATE_URL = "https://substrate.example.com:3100"
|
|
27
|
+
SUBSTRATE_AGENT_KEY_ID = "{{ cwd | basename }}-opencode@YourHost"
|
|
28
|
+
SUBSTRATE_AGENT_KEY_PATH = "{{ env.HOME }}/.config/substrate/keys/{{ cwd | basename }}-opencode.key"
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
With `mise activate` in the shell rc, every repo gets a derived kid and the
|
|
32
|
+
opencode.json below stays portable. GUI-launched opencode (no shell env) gets
|
|
33
|
+
no identity — same caveat as the Claude skin's npx note; prefer terminal
|
|
34
|
+
launch when identity matters. **Exception:** the V2 skin also takes identity
|
|
35
|
+
from plugin config — the object plugin entry's `options.kid` / `options.key`
|
|
36
|
+
(Step 3) win over the env pair and survive GUI launch, since they ride in the
|
|
37
|
+
config file instead of the process env.
|
|
38
|
+
|
|
39
|
+
## Step 2 — probe capability
|
|
40
|
+
|
|
41
|
+
Using the `substrate` MCP tools (or `curl -sfk` as fallback), check each of the
|
|
42
|
+
following and report it as ✓/✗:
|
|
43
|
+
|
|
44
|
+
1. **Reachable:** `GET <SUBSTRATE_URL>/health` → 200.
|
|
45
|
+
2. **Coordinator present (hard prerequisite):** `schema` includes the
|
|
46
|
+
coordinator namespace — `cortext` by default, or whatever `SUBSTRATE_NAMESPACE`
|
|
47
|
+
names (look for `cortext/AgentRule`, `cortext/Todo`). If absent,
|
|
48
|
+
**STOP**: "The cortext coordinator isn't loaded on this Substrate. Install it
|
|
49
|
+
server-side before onboarding."
|
|
50
|
+
- The legacy `claude` namespace is **retired** — `unknown_namespace`.
|
|
51
|
+
3. **Recall capability:** `GET <SUBSTRATE_URL>/substrate/v1/embed-stats` → `enabled`.
|
|
52
|
+
`true` = hybrid cold-start; `false` = structural-only (degrades cleanly).
|
|
53
|
+
4. **MCP package resolvable** (only if Step 4 uses the npx server form):
|
|
54
|
+
`npm view @mnmal-ai/substrate version`. It is public on npmjs.com, so a
|
|
55
|
+
failure here is a network or registry-mirror problem, not missing auth.
|
|
56
|
+
|
|
57
|
+
Print a capability summary block.
|
|
58
|
+
|
|
59
|
+
## Step 3 — install the plugin + conventions instructions
|
|
60
|
+
|
|
61
|
+
1. Add the plugin to the repo's `opencode.json` (create it if absent; never
|
|
62
|
+
clobber existing keys). Prefer the object form — it carries the per-project
|
|
63
|
+
identity through `options`, which wins over the Step-1 env pair:
|
|
64
|
+
|
|
65
|
+
```json
|
|
66
|
+
{
|
|
67
|
+
"$schema": "https://opencode.ai/config.json",
|
|
68
|
+
"plugins": [
|
|
69
|
+
{
|
|
70
|
+
"package": "@mnmal-ai/cortext-opencode",
|
|
71
|
+
"options": {
|
|
72
|
+
"kid": "<the Step-1 kid>",
|
|
73
|
+
"key": "<the Step-1 key file>"
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
]
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
The plain string form (`"plugins": ["@mnmal-ai/cortext-opencode"]`) also
|
|
81
|
+
works — identity then comes from the env pair. **Keep exactly one entry
|
|
82
|
+
per package**: as of opencode v2.0.24 the `plugins`
|
|
83
|
+
arrays concatenate across global + project config and loads dedupe only
|
|
84
|
+
by exact source string, so a global string entry plus a project object
|
|
85
|
+
entry for the same package load the plugin twice and double-inject the
|
|
86
|
+
cold-start. If the plugin is already in the global config as a string
|
|
87
|
+
entry, remove that entry when adding the project object entry.
|
|
88
|
+
|
|
89
|
+
npm plugins install automatically via Bun at startup (cached under
|
|
90
|
+
`~/.cache/opencode/`). No registry auth is needed.
|
|
91
|
+
|
|
92
|
+
2. Conventions need no step: the plugin injects them from its own package
|
|
93
|
+
on every dispatch, so they track the installed version. If the
|
|
94
|
+
repo has an older `.opencode/substrate-conventions.md` copy, delete it and its
|
|
95
|
+
`"instructions"` entry; the session context names it while it is stale.
|
|
96
|
+
(`AGENTS.md` needs no import line: opencode auto-loads it, and nothing in
|
|
97
|
+
this setup writes to it.)
|
|
98
|
+
|
|
99
|
+
## Step 4 — wire the substrate MCP server (opencode.json, identity-ready)
|
|
100
|
+
|
|
101
|
+
Unlike the Claude skin (project `.mcp.json`), OpenCode servers live in
|
|
102
|
+
`opencode.json` under `mcp.servers` — same file as the plugin entry. Merge
|
|
103
|
+
this in (never clobber other servers).
|
|
104
|
+
|
|
105
|
+
**Sign the MCP server as the plugin's identity**. The plugin shows
|
|
106
|
+
mail for its identity and only that kid may ack it, so a mismatch shows mail
|
|
107
|
+
the session cannot close. If Step 3 used `options.kid` / `options.key`, put
|
|
108
|
+
the same kid and key in this server's `environment` as literals, in a
|
|
109
|
+
user-level config, instead of the `{env:…}` refs below, which a GUI launch
|
|
110
|
+
leaves empty:
|
|
111
|
+
|
|
112
|
+
```json
|
|
113
|
+
{
|
|
114
|
+
"mcp": {
|
|
115
|
+
"servers": {
|
|
116
|
+
"substrate": {
|
|
117
|
+
"type": "local",
|
|
118
|
+
"command": ["npx", "-y", "@mnmal-ai/substrate", "mcp"],
|
|
119
|
+
"codemode": false,
|
|
120
|
+
"environment": {
|
|
121
|
+
"SUBSTRATE_URL": "<the url>",
|
|
122
|
+
"SUBSTRATE_AGENT_KEY_PATH": "{env:SUBSTRATE_AGENT_KEY_PATH}",
|
|
123
|
+
"SUBSTRATE_AGENT_KEY_ID": "{env:SUBSTRATE_AGENT_KEY_ID}"
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
**`"codemode": false` is required.** OpenCode 2.x defaults a local
|
|
132
|
+
server to code mode, which hides its tools behind the generic `execute` tool:
|
|
133
|
+
the server connects, but the model never sees `substrate_*` by name, so an agent
|
|
134
|
+
following the conventions reports that it has no substrate tools and cannot ack
|
|
135
|
+
its mail. OpenCode prefixes each tool with its server name, so they reach the
|
|
136
|
+
model as `substrate_query`, `substrate_mutate`, `substrate_whoami` and so
|
|
137
|
+
on. Confirm after a restart (bounce `opencode serve --service`, not just the
|
|
138
|
+
TUI) that the session calls `substrate_whoami` directly and gets its kid.
|
|
139
|
+
|
|
140
|
+
Dialect notes that bite Claude migrants: servers go under `mcp.servers`, not
|
|
141
|
+
`mcpServers` (OpenCode 1.x used bare `mcp.<name>`, which 2.x still migrates;
|
|
142
|
+
on 1.x, drop the `servers` level and the `codemode` key); `type: "local"` is
|
|
143
|
+
required; `command` is an **array**; env
|
|
144
|
+
rides under `environment`; interpolation is `{env:VAR}`, **not** `${VAR}`
|
|
145
|
+
(which is passed through literally). The `{env:}` refs resolve against the
|
|
146
|
+
Step-1 environment and stay inert until identity exists.
|
|
147
|
+
|
|
148
|
+
- **Operator box** (local `@mnmal-ai/substrate` install): prefer
|
|
149
|
+
`"command": ["/abs/.../node", "/abs/.../substrate.js", "mcp"]` — no registry
|
|
150
|
+
dependency at session start. A committed file holding absolute paths is
|
|
151
|
+
machine-specific: gitignore `opencode.json` in that case, as with the
|
|
152
|
+
Claude skin's operator-box rule.
|
|
153
|
+
- **Restart opencode** after writing: config loads once at startup.
|
|
154
|
+
|
|
155
|
+
## Step 5 — seed baseline AgentRules (coverage-first, deselectable)
|
|
156
|
+
|
|
157
|
+
Same catalogue and same procedure as the Claude skin:
|
|
158
|
+
|
|
159
|
+
1. Query `<ns>/AgentRule` (active, `project: null` and this project) and read
|
|
160
|
+
the existing `rule` texts. There is no `key` field; compare **substance**,
|
|
161
|
+
not text equality — mature stores already cover these with richer wording.
|
|
162
|
+
2. Baselines (universal tier → `project: null`): `mcp-call-style` (never echo
|
|
163
|
+
MCP payloads in chat), `concise-responses` (no trailing summaries),
|
|
164
|
+
`git-feature-branch` (PRs, never main), `mcp-first` (MCP tools, HTTP only
|
|
165
|
+
when unreachable), `cold-start-adherence` (read the injected context
|
|
166
|
+
before acting).
|
|
167
|
+
3. Report coverage; ask only about the remainder; batch-create with
|
|
168
|
+
`<ns>/createAgentRule` in one mutation.
|
|
169
|
+
|
|
170
|
+
## Step 6 — recall degradation notice
|
|
171
|
+
|
|
172
|
+
If Step 2 found recall **disabled**, tell the user plainly: cold-start runs
|
|
173
|
+
**structural-only** (recency/importance ordering) and **auto-upgrades** to
|
|
174
|
+
hybrid recall when an embedder comes online — no re-run needed.
|
|
175
|
+
|
|
176
|
+
## Step 7 — agent identity: DETECT first, provision only if needed
|
|
177
|
+
|
|
178
|
+
`GET <SUBSTRATE_URL>/substrate/v1/whoami` from a signed shell (or `substrate-admin list`
|
|
179
|
+
from the operator box, which reads postgres directly). If the Step-1 kid
|
|
180
|
+
resolves to a registered row with a present key file, say so and skip.
|
|
181
|
+
|
|
182
|
+
Otherwise — consent-gated, generate → register → restart as ONE unit (a
|
|
183
|
+
generated-but-unregistered key 401s every read, strictly worse than none):
|
|
184
|
+
|
|
185
|
+
```bash
|
|
186
|
+
mkdir -p ~/.config/substrate/keys && chmod 700 ~/.config/substrate/keys
|
|
187
|
+
KID="$(basename "$(git rev-parse --show-toplevel)")-opencode@$(hostname -s)"
|
|
188
|
+
KEYFILE=~/.config/substrate/keys/$(basename "$(git rev-parse --show-toplevel)")-opencode.key
|
|
189
|
+
if [ ! -f "$KEYFILE" ]; then
|
|
190
|
+
openssl genpkey -algorithm ed25519 -out "$KEYFILE"
|
|
191
|
+
chmod 600 "$KEYFILE"
|
|
192
|
+
openssl pkey -in "$KEYFILE" -pubout -out "${KEYFILE%.key}.pub"
|
|
193
|
+
fi
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
Register (operator, admin — not via MCP tools): `substrate-admin register
|
|
197
|
+
"$KID" --pubkey "${KEYFILE%.key}.pub" --ns "<ns>,recall"
|
|
198
|
+
--caps read,mutate`, restart the binary, then seed the directory row
|
|
199
|
+
(`<ns>/createAgentIdentity`) so the agent is routable for mail. Verify with
|
|
200
|
+
a write and read its `_metadata.createdBy` — must be `{kind:'agent',
|
|
201
|
+
id:'<KID>'}`.
|
|
202
|
+
|
|
203
|
+
## Step 8 — write the first anchor, then confirm
|
|
204
|
+
|
|
205
|
+
Onboarding does not seed an `AnchorIntent`, and a repo without one ranks its
|
|
206
|
+
rules **structurally** (no semantic half). Write one real intent — never a
|
|
207
|
+
placeholder (`"onboarded this repo"` is semantic noise aimed at the rule
|
|
208
|
+
set):
|
|
209
|
+
|
|
210
|
+
```
|
|
211
|
+
<ns>/createAnchorIntent { project: "<project>", synopsis: "<what this repo is for and what is being worked on right now>" }
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
Then summarise: SUBSTRATE_URL source, plugin entry, instructions copy, MCP
|
|
215
|
+
server form, rules created vs skipped, recall tier, identity (per-project
|
|
216
|
+
kid vs fleet default). Tell the user to restart opencode — config loads once
|
|
217
|
+
at startup, and the cold-start injects on the first dispatch after that.
|