Repository navigation
Conversation
micode 0.11.0 is a v1 plugin: it exports a named OpenCodeConfigPlugin, returns
a v1 hooks object, and mutates the host config directly. v2 requires a default
Plugin.define({id, setup}) and exposes no config mutation, so no released
version loads on v2 — upstream main is still pinned to the v1 plugin package.
v2-adapter/ is a shim that runs the published plugin unchanged and translates
its v1 API surface into v2: agents via ctx.agent.transform, commands and tools
via their editors, MCP via ctx.mcp.transform, permissions via a
ctx.permission evaluate hook, and the v1 hooks onto ctx.session.hook /
ctx.tool.hook / ctx.event.subscribe.
Two v2 gaps shape the design:
- SessionDomain is a Pick that omits compact and remove, so a plugin cannot
request a compaction. micode's Auto-Compact is disarmed by withholding the
token counts it triggers on — session.usage.updated carries cumulative
session usage, which is not what its per-request ratio expects — and
summarize() rejects rather than parking the hook in a two-minute wait.
OpenCode's own compaction.auto does the compacting.
- ctx.session.prompt admits and returns a receipt in v2, where v1 returned the
reply synchronously. The client shim waits and re-reads context so
spawn_agent and octto's probe agents still receive a reply.
Verified on 2.0.21: no load errors, 26 agents, 4 commands, 41 tools, the
context7 MCP server and 6 bridged hooks all present in the live registries, and
subagent spawning works end to end with a live model.
npm test runs the real upstream plugin against a stand-in host in both
directions: 11 assertions, no server required.
There was a problem hiding this comment.
All reported issues were addressed across 17 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Parallel subagent execution never ran. The tool's schema takes a single
{ agents: [...] } array, but the executor, planner and project-initializer
prompts still taught the flat call:
spawn_agent(agent="implementer", prompt="...", description="...")
f5fd6bf switched the tool to the array form and touched only
src/tools/spawn-agent.ts; the prompts were last rewritten by 1555746 three
days earlier and were never reconciled. Every flat call fails schema
validation and returns "No agents specified", so each batched spawn spawned
nothing. Only mm-orchestrator had been updated, which is why /mindmodel's
parallel phases worked while executor, /init research and planner were
silently serialised down to zero agents.
Rewrites the prompts around the array form: ONE spawn_agent call per phase
carrying every agent, since the array is what produces the Promise.all.
Also drops the misleading "call multiple spawn_agent tools in ONE message"
framing.
Adds tests/tools/spawn-agent-contract.test.ts, which derives the expected
shape from the tool's own args and asserts (a) no prompt teaches the flat
form and (b) one call actually overlaps every agent (3 concurrent sessions).
The old prompt tests asserted toContain("spawn_agent tool") and, in the
planner's case, asserted the buggy flat string was present - which is why
the drift went unnoticed.
There was a problem hiding this comment.
All reported issues were addressed across 6 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Correctness:
- tool.execute.after now re-throws micode's ConstraintViolationError instead
of logging it. It is the constraint reviewer's enforcement verdict after the
retry limit, so swallowing it returned the blocked Write/Edit's original
successful result and the model carried on as if it had passed. Matched by
`name`, since the published bundle does not export the class.
- The context hook fed the mindmodel injector `toV2Messages(event.messages)`,
but `event.messages` is already the v2 flat union, so every message became
{role:"user", content:[]} and injection never fired. Converted with
toV1Messages instead; removes the now-unused toV2Messages.
- session.create forwards parentID, so spawned sessions nest under their
spawner again instead of appearing as loose top-level sessions.
- The system transform no longer rebuilds every part as text: text parts keep
their original objects and metadata such as cache hints, non-text parts
survive, and an unchanged transform leaves event.system alone.
- create() command templates substitute $ARGUMENTS through a callback, so `$&`,
`$'` and `` $` `` in user arguments are inserted literally rather than being
treated as substitution patterns.
- stringToResult rewrites every text part instead of only the first, leaving no
stale text visible in a multi-part tool result.
- The event bridge resubscribes with backoff. A stream reset or server restart
previously killed all six bridged event hooks for the plugin's lifetime.
- session.deleted falls back to data.sessionID, which is what v2 sends, keeping
the data.info path as a fallback.
Permissions:
- Each agent seeds the rules for the actions micode allows globally, plus
subagent which spawn_agent needs, instead of a blanket `*:allow`. Actions
micode never allows now keep the host default rather than being
auto-approved. The base is derived from the same config.permission the global
hook reads, so the two cannot drift.
- ACTION_ALIASES is exported once from permissions.js and shared with agents.js.
- registerPermissions returns its registration, which setup now disposes.
Robustness:
- session.wait is bounded by a 5 minute race, so a stalled child session can no
longer hang spawn_agent or octto's probes indefinitely. Dropped the
waitForReply state field, which was always true, making its branch dead.
- Features are parsed with jsonc-parser rather than regexes that could not span
nested braces, could match inside a comment, and failed silently to leave
octtoTools enabled against a documented kill-switch.
- Log writes are queued and flushed on a timer and on exit, instead of a
synchronous mkdir+append per call on the host's event loop.
- MCP and tool registration counts reflect what actually landed, and
schema-conversion failures are reported as skips rather than counted as
registered.
Tests and docs:
- harness `on()` took four parameters but was called with three, so every hook
was stored under its handler with an undefined value. Fixed to
(registry, name, handler), which also cleared the unused-parameter lint error.
- auto-compact.test.js treats a missing log as empty so it runs on a clean HOME.
- Declare zod (v4) and jsonc-parser explicitly rather than relying on micode's
transitive resolution; z.toJSONSchema is a zod v4 API.
- README installs into ~/.micode-v2, which is what its test and upgrade commands
already referenced.
- Em dashes removed from code comments and test output, per CLAUDE.md.
- Exclude v2-adapter from the root biome/eslint configs. It is a separately
published package built against @opencode/plugin with its own `npm test`, and
three rules conflict with what the v2 plugin API requires. This also makes
`bun run check` green for the first time: the pre-existing formatting failures
were all in this directory.
The pinned 2.5.6 schema made every `biome check` report a version mismatch against the 2.5.14 CLI in devDependencies.
…examples
- Each fake session now captures its own id before awaiting, so three concurrent
tasks get three distinct sessions instead of all reading the same one, and the
test asserts the prompted and read ids are distinct and that each result is
attributed to the session that produced it.
- Adds a contract assertion that every documented `{agent, prompt, description}`
element is complete. `description` is required by the schema, so an example
omitting it documents a call that spawns nothing, which is the exact failure
this suite exists to catch. Verified it fails when a description is removed.
- Adds the missing `description` to the three planner bad-example calls.
There was a problem hiding this comment.
All reported issues were addressed across 19 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
pjotrvv
left a comment
There was a problem hiding this comment.
Addressed the review in 86a9257, b1394ce and 01d5fcc.
Correctness. tool.execute.after re-throws ConstraintViolationError instead of logging it, so a blocked Write/Edit no longer returns its original successful result (matched on error.name, since the published bundle does not export the class). The context hook was calling toV2Messages(event.messages), but event.messages is already the v2 flat union, so every message became {role:"user", content:[]} and mindmodel injection never fired; it now uses toV1Messages. session.create forwards parentID. The system transform preserves the original part objects and their metadata instead of rebuilding everything as text. $ARGUMENTS is substituted through a callback, so $&/$\``/$'in arguments are literal.stringToResult` rewrites every text part, not just the first. The event bridge resubscribes with backoff instead of dying on a stream reset.
Permissions. Each agent now seeds only the actions micode allows globally plus subagent, instead of a blanket *:allow, so actions micode never allows keep the host default. The base comes from the same config.permission the global hook reads. ACTION_ALIASES is exported once and shared.
Robustness. session.wait is bounded by a 5 minute race. Features are parsed with jsonc-parser instead of regexes. Log writes are queued and flushed on a timer and on exit. MCP and tool counts reflect what actually landed. registerPermissions returns its registration and setup disposes it.
Tests. The harness on() helper took four parameters but was called with three, so every hook was stored under its handler with an undefined value; that is fixed and it also cleared a pre-existing lint error. auto-compact.test.js tolerates a missing log. The spawn_agent contract test now gives each fake session its own id and measures overlap across the full create/prompt/messages lifecycle, and a new assertion rejects any documented example that omits the required description.
Two notes:
-
One finding was based on a wrong premise. For
session.deleted, the v2 payload is{ sessionID }, not adata.inforecord (@opencode/client/dist/effect/api/api.d.ts, and the client reducer readsevent.data.sessionID). The existing code was already correct. I addeddata.info?.idwithdata.sessionIDas the fallback so either shape works, and left the behaviour otherwise unchanged. -
bun run checkis green for the first time. Every pre-existing failure was inv2-adapter, a separately published npm package built against@opencode/pluginwith its ownnpm test. Three root rules conflict with what the v2 plugin API requires (export default, the literal${ARGUMENTS}token, imports relative to the package root), so the adapter is now excluded from the root biome/eslint configs with a comment explaining why. I also synced the biome schema URL, which was pinned at 2.5.6 against a 2.5.14 CLI.
Verification: bun run check exits 0 (525 tests, biome, eslint, tsc) and npm test in the adapter passes 11/11.
Seeding the base rules into the same map as the agent's own rules, behind a first-write-wins guard, silently dropped every per-agent deny on an action the base already contained. Read-only agents ended up with `edit: allow`, `shell: allow` and `subagent: allow` instead of their denies: codebase-locator came out as edit allow, shell allow, subagent allow, write deny. A user's own `edit: "ask"` was ignored the same way. The base is now applied first and the agent's rules are layered on afterwards, so they win; v2 takes the last matching rule, which is what makes the ordering decide it. `subagent` is the one action no agent declares, so it stays in effect. Verified: codebase-locator now resolves to edit deny, shell deny, subagent deny, write deny, and implementer/executor keep their allows. Also removes the abort listener in the event bridge's backoff `sleep` when the timer fires, not just when the controller aborts. Fifty consecutive retries previously left fifty closures attached to the signal for the plugin's lifetime.
There was a problem hiding this comment.
4 issues found across 21 files (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="v2-adapter/lib/log.js">
<violation number="1" location="v2-adapter/lib/log.js:33">
P3: If the log directory is removed after the first flush, `directoryReady` remains true and this catch silently drops every later file batch without recreating it. Reset the flag on write failure so a subsequent flush can recreate the directory.</violation>
</file>
<file name="v2-adapter/lib/messages.js">
<violation number="1" location="v2-adapter/lib/messages.js:142">
P2: This loop treats raw string system entries as non-text, even though `systemPartsToStrings` exposes them to the transform; edits then leave the original string in place and append the replacement. Empty text parts also shift the positional mapping. Map each extracted string back to its original part index so edits update the intended system text.</violation>
</file>
<file name="v2-adapter/README.md">
<violation number="1" location="v2-adapter/README.md:227">
P2: This plugin entry points at the clone root, not the adapter package. `~/.micode-v2` is the root of the micode repo, whose package.json has `main`/`module: "dist/index.js"`; `dist/` is gitignored and `npm install` at the root only runs `lefthook install` (`prepare`), so the resolved module is missing — and if built, it is the v1 plugin with no default `Plugin.define` export, which fails with exactly the "Plugin must export a default definition" error this README warns about below. The adapter lives in `~/.micode-v2/v2-adapter/` with its own package.json (`main: index.js`) default-exporting the v2 plugin. Point the entry at `~/.micode-v2/v2-adapter` (previous text correctly used the v2-adapter directory). Also note OpenCode's docs document local entries as `./plugins/local`-style paths or `file:///…` absolute URLs; tilde expansion in plugin entries is not documented, so verify `~` is expanded on 2.0.21 or use an absolute path.</violation>
</file>
<file name="eslint.config.js">
<violation number="1" location="eslint.config.js:29">
P2: This batch removes v2-adapter from both repo linters, but nothing in the repo gate runs the adapter's own test suite. `bun run check` covers biome, eslint, tsc, and `bun test tests`; the adapter's tests live in `v2-adapter/test/` and only run via its `npm test` script, which CI (`quality-gate.yml`, `release.yml`) and pre-commit never invoke. The `npm test` coverage described in the PR therefore never executes in CI or pre-commit. Add the adapter test to the gate, e.g. a final step in the `check` script.</violation>
</file>
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
| let cursor = 0; | ||
|
|
||
| for (const part of parts ?? []) { | ||
| if (part?.type !== "text") { |
There was a problem hiding this comment.
P2: This loop treats raw string system entries as non-text, even though systemPartsToStrings exposes them to the transform; edits then leave the original string in place and append the replacement. Empty text parts also shift the positional mapping. Map each extracted string back to its original part index so edits update the intended system text.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At v2-adapter/lib/messages.js, line 142:
<comment>This loop treats raw string system entries as non-text, even though `systemPartsToStrings` exposes them to the transform; edits then leave the original string in place and append the replacement. Empty text parts also shift the positional mapping. Map each extracted string back to its original part index so edits update the intended system text.</comment>
<file context>
@@ -85,76 +85,115 @@ export function toV1Messages(messages, sessionID) {
+ let cursor = 0;
+
+ for (const part of parts ?? []) {
+ if (part?.type !== "text") {
+ out.push(part);
+ continue;
</file context>
|
|
||
| ```json | ||
| { | ||
| "plugins": ["~/.micode-v2"] |
There was a problem hiding this comment.
P2: This plugin entry points at the clone root, not the adapter package. ~/.micode-v2 is the root of the micode repo, whose package.json has main/module: "dist/index.js"; dist/ is gitignored and npm install at the root only runs lefthook install (prepare), so the resolved module is missing — and if built, it is the v1 plugin with no default Plugin.define export, which fails with exactly the "Plugin must export a default definition" error this README warns about below. The adapter lives in ~/.micode-v2/v2-adapter/ with its own package.json (main: index.js) default-exporting the v2 plugin. Point the entry at ~/.micode-v2/v2-adapter (previous text correctly used the v2-adapter directory). Also note OpenCode's docs document local entries as ./plugins/local-style paths or file:///… absolute URLs; tilde expansion in plugin entries is not documented, so verify ~ is expanded on 2.0.21 or use an absolute path.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At v2-adapter/README.md, line 227:
<comment>This plugin entry points at the clone root, not the adapter package. `~/.micode-v2` is the root of the micode repo, whose package.json has `main`/`module: "dist/index.js"`; `dist/` is gitignored and `npm install` at the root only runs `lefthook install` (`prepare`), so the resolved module is missing — and if built, it is the v1 plugin with no default `Plugin.define` export, which fails with exactly the "Plugin must export a default definition" error this README warns about below. The adapter lives in `~/.micode-v2/v2-adapter/` with its own package.json (`main: index.js`) default-exporting the v2 plugin. Point the entry at `~/.micode-v2/v2-adapter` (previous text correctly used the v2-adapter directory). Also note OpenCode's docs document local entries as `./plugins/local`-style paths or `file:///…` absolute URLs; tilde expansion in plugin entries is not documented, so verify `~` is expanded on 2.0.21 or use an absolute path.</comment>
<file context>
@@ -213,15 +213,18 @@ consider:
```json
{
- "plugins": ["/absolute/path/to/micode/v2-adapter"]
+ "plugins": ["~/.micode-v2"]
}
</file context>
</details>
```suggestion
"plugins": ["~/.micode-v2/v2-adapter"]
| // TypeScript sources these rules are written for, and several rules | ||
| // conflict with what the v2 plugin API requires (`export default`, a | ||
| // literal `${ARGUMENTS}` token, imports relative to the package root). | ||
| "v2-adapter/**", |
There was a problem hiding this comment.
P2: This batch removes v2-adapter from both repo linters, but nothing in the repo gate runs the adapter's own test suite. bun run check covers biome, eslint, tsc, and bun test tests; the adapter's tests live in v2-adapter/test/ and only run via its npm test script, which CI (quality-gate.yml, release.yml) and pre-commit never invoke. The npm test coverage described in the PR therefore never executes in CI or pre-commit. Add the adapter test to the gate, e.g. a final step in the check script.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At eslint.config.js, line 29:
<comment>This batch removes v2-adapter from both repo linters, but nothing in the repo gate runs the adapter's own test suite. `bun run check` covers biome, eslint, tsc, and `bun test tests`; the adapter's tests live in `v2-adapter/test/` and only run via its `npm test` script, which CI (`quality-gate.yml`, `release.yml`) and pre-commit never invoke. The `npm test` coverage described in the PR therefore never executes in CI or pre-commit. Add the adapter test to the gate, e.g. a final step in the `check` script.</comment>
<file context>
@@ -21,6 +21,12 @@ export default [
+ // TypeScript sources these rules are written for, and several rules
+ // conflict with what the v2 plugin API requires (`export default`, a
+ // literal `${ARGUMENTS}` token, imports relative to the package root).
+ "v2-adapter/**",
],
},
</file context>
| } catch { | ||
| // A log that cannot be written must not take the plugin down with it. | ||
| } |
There was a problem hiding this comment.
P3: If the log directory is removed after the first flush, directoryReady remains true and this catch silently drops every later file batch without recreating it. Reset the flag on write failure so a subsequent flush can recreate the directory.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At v2-adapter/lib/log.js, line 33:
<comment>If the log directory is removed after the first flush, `directoryReady` remains true and this catch silently drops every later file batch without recreating it. Reset the flag on write failure so a subsequent flush can recreate the directory.</comment>
<file context>
@@ -1,34 +1,76 @@
+ directoryReady = true;
+ }
+ appendFileSync(LOG_FILE, batch);
+ } catch {
+ // A log that cannot be written must not take the plugin down with it.
+ }
</file context>
| } catch { | |
| // A log that cannot be written must not take the plugin down with it. | |
| } | |
| } catch { | |
| directoryReady = false; | |
| // A log that cannot be written must not take the plugin down with it. | |
| } |
2.0.21 types the event's data as { sessionID }, so the existing read was
correct, but reading data.info?.id first means a build that wraps the session
record in info also clears per-session state. The sessionID fallback is kept.
7d219a8 corrected the spawn_agent prompts to the tool's array schema and 01d5fcc hardened the contract test. Both are in src/. Neither could reach a running agent, because the adapter resolves `import ... from "micode"` to node_modules, and node_modules holds the published 0.11.0 bundle — still the pre-7d219a8 prompts. The contract tests passed throughout, because they test src/. What a model reads is whichever copy the loaded bundle carries, and agent prompts are data: the stale executor prompt taught `spawn_agent(agent, prompt, description)`, every such call failed schema validation and returned "No agents specified", and a 10-20-way batch spawned nothing while reporting no error. Same shape as the extension that shipped with no toolbar button behind 22 green tests: a gate that cannot fail is not a gate. lib/micode.js resolves the implementation at setup: the repo's dist/ when it exists, node_modules otherwise. dist/ is gitignored, so a clone without a build resolves exactly as before and `npm update micode` still works. The local build is self-contained — only `buffer` and `process` — so nothing else moves. Verified both branches by moving dist/ aside: local build -> /home/pjotrvv/micode/dist/index.js no dist/ -> node_modules/micode, resolves and exports the plugin Setup logs which copy won, so this is never a silent choice again. pretest runs `bun run build`, so `npm test` cannot pass against a stale dist/. test/local-build.test.js asserts the resolution order and that the loaded bundle teaches the array form; it fails if the local build stops winning or dist/ drifts back to the flat call. bun run check 525 pass, 0 fail (1 pre-existing biome warning) npm test 5/5 local-build, 7/7 auto-compact, 4/4 summarize
mindmodel_lookup reported "No .mindmodel/ directory found in this project"
for a directory holding six constraint files. The directory existed, the files
were readable, and every agent ran without them.
loadMindmodel passes access() on .mindmodel/, then readFile()s manifest.yaml.
ENOENT is caught by the same handler as a malformed manifest and collapses to
null, and the tool renders null as "no directory found". So a hand-written
.mindmodel/ — flat constraints.md, patterns.md, overview.md, no manifest — was
indistinguishable from an empty project, and the model's instruction was to
proceed without constraints while the constraints sat unread.
ENOENT now takes a different path from a broken manifest. Absent manifest, so
derive categories from the markdown on disk: description from each file's H1,
recursing into subdirectories. A malformed manifest still fails loudly, because
inferring around one would hide a mistake the user can fix. Derivation is logged
at info — a silent fallback is indistinguishable from a real manifest.
Fixed the second bug the probe then exposed. matchCategories required
query.includes(keyword), testing only whether the query contained a description
word. Against this repository's real files, "hard rules", "firefox extension"
and "conftest sys.path" all matched nothing: `## Hard rules` is the second
heading of a file titled "Architecture Constraints", and no description word
appears in those queries. Matching is now symmetric over the file's path,
description and headings, which are a short curated index of what a file covers.
Body prose is still not searched, or every query would match most files and the
tool would inject the whole directory.
Both callers (the tool and the injector hook) matched and then loaded separately,
so they had to load files before they could match. Each now reads the category
files once and matches against what it actually read, which also keeps matching
and loading in agreement about what exists.
Verified against /home/pjotrvv/Documents/html2text:
before 6 files, 0 categories, three reasonable queries all "no match"
after 6 categories derived; hard rules -> constraints.md,
firefox extension permissions -> sibling-projects.md,
conftest sys.path -> patterns.md
"kubernetes helm chart" -> no match, as it should
The tool's "not found" message now says what it looked for, so a directory that
exists but cannot be read is distinguishable from an empty one.
bun run check 542 pass, 0 fail (1 pre-existing biome warning in pty/manager)
npm test 5/5 local-build, 7/7 auto-compact, 4/4 summarize
There was a problem hiding this comment.
7 issues found across 11 files (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="tests/tools/mindmodel-lookup.test.ts">
<violation number="1" location="tests/tools/mindmodel-lookup.test.ts:82">
P3: The schema requires `description`, so the loader cannot produce this category; the cast only tests malformed input. Reword this as defensive malformed-input coverage, or make the schema optional if omission is supported.</violation>
</file>
<file name="src/mindmodel/loader.ts">
<violation number="1" location="src/mindmodel/loader.ts:79">
P2: This regex indexes heading-shaped lines inside fenced code blocks, so code comments such as `# install dependencies` can make unrelated queries select this category. Ignore fenced code when extracting headings.</violation>
</file>
<file name="src/tools/mindmodel-lookup.ts">
<violation number="1" location="src/tools/mindmodel-lookup.ts:56">
P2: This tokenizer discards every non-ASCII letter, so categories and queries written in Cyrillic, Greek, or other scripts cannot match. Split on Unicode letters and numbers instead.</violation>
<violation number="2" location="src/tools/mindmodel-lookup.ts:110">
P2: `loadMindmodel` also returns `null` for malformed or unreadable manifests, so this message falsely says there is no manifest or readable Markdown when constraints may exist. Use a cause-neutral message or surface the loader error so users are not told the project has no patterns.</violation>
</file>
<file name="v2-adapter/test/local-build.test.js">
<violation number="1" location="v2-adapter/test/local-build.test.js:29">
P2: This does not verify which bundle `loadMicode()` actually imports: it only checks the path helper and reads the local file directly. An unconditional `import("micode")` regression would still pass; assert that `loadMicode()` returns the export from the local build.</violation>
</file>
<file name="src/hooks/mindmodel-injector.ts">
<violation number="1" location="src/hooks/mindmodel-injector.ts:103">
P2: This rereads every category file for each uncached task, and `loadExamples` reads them sequentially. Cache the loaded examples per mindmodel so every new prompt does not pay for all of this I/O.</violation>
</file>
<file name="tests/mindmodel/loader.test.ts">
<violation number="1" location="tests/mindmodel/loader.test.ts:22">
P2: These unconditional reads make unexpected `console.error` and unasserted `console.log` output pass silently in every test. Assert expected derivation notices in the tests that produce them, and leave unexpected channels unread.</violation>
</file>
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
| * human-curated index of the file, so they are a far better signal than prose. | ||
| */ | ||
| export function headingsOf(content: string): string[] { | ||
| return [...content.matchAll(/^#{1,6}\s+(.+)$/gm)].map((match) => match[1].trim()); |
There was a problem hiding this comment.
P2: This regex indexes heading-shaped lines inside fenced code blocks, so code comments such as # install dependencies can make unrelated queries select this category. Ignore fenced code when extracting headings.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At src/mindmodel/loader.ts, line 79:
<comment>This regex indexes heading-shaped lines inside fenced code blocks, so code comments such as `# install dependencies` can make unrelated queries select this category. Ignore fenced code when extracting headings.</comment>
<file context>
@@ -31,6 +33,111 @@ function warnNonMarkdownCategories(manifest: MindmodelManifest): void {
+ * human-curated index of the file, so they are a far better signal than prose.
+ */
+export function headingsOf(content: string): string[] {
+ return [...content.matchAll(/^#{1,6}\s+(.+)$/gm)].map((match) => match[1].trim());
+}
+
</file context>
| // returned when the directory existed but could not be read, which | ||
| // tells the model to carry on without constraints while constraint | ||
| // files sit unread on disk. | ||
| return "No usable .mindmodel/ found in this project (no manifest.yaml and no readable markdown files). Proceed without specific patterns."; |
There was a problem hiding this comment.
P2: loadMindmodel also returns null for malformed or unreadable manifests, so this message falsely says there is no manifest or readable Markdown when constraints may exist. Use a cause-neutral message or surface the loader error so users are not told the project has no patterns.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At src/tools/mindmodel-lookup.ts, line 110:
<comment>`loadMindmodel` also returns `null` for malformed or unreadable manifests, so this message falsely says there is no manifest or readable Markdown when constraints may exist. Use a cause-neutral message or surface the loader error so users are not told the project has no patterns.</comment>
<file context>
@@ -53,22 +103,27 @@ Returns relevant code examples and patterns to follow.`,
+ // returned when the directory existed but could not be read, which
+ // tells the model to carry on without constraints while constraint
+ // files sit unread on disk.
+ return "No usable .mindmodel/ found in this project (no manifest.yaml and no readable markdown files). Proceed without specific patterns.";
}
</file context>
| return "No usable .mindmodel/ found in this project (no manifest.yaml and no readable markdown files). Proceed without specific patterns."; | |
| return "No usable .mindmodel/ could be loaded. Proceed without specific patterns."; |
| function words(text: string): string[] { | ||
| return text | ||
| .toLowerCase() | ||
| .split(/[^a-z0-9]+/) |
There was a problem hiding this comment.
P2: This tokenizer discards every non-ASCII letter, so categories and queries written in Cyrillic, Greek, or other scripts cannot match. Split on Unicode letters and numbers instead.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At src/tools/mindmodel-lookup.ts, line 56:
<comment>This tokenizer discards every non-ASCII letter, so categories and queries written in Cyrillic, Greek, or other scripts cannot match. Split on Unicode letters and numbers instead.</comment>
<file context>
@@ -2,35 +2,85 @@
+function words(text: string): string[] {
+ return text
+ .toLowerCase()
+ .split(/[^a-z0-9]+/)
+ .filter((word) => word.length >= MIN_KEYWORD_LENGTH);
+}
</file context>
| .split(/[^a-z0-9]+/) | |
| .split(/[^\p{L}\p{N}\p{M}]+/u) |
|
|
||
| check( | ||
| "a local build is found", | ||
| localBuildPath() === LOCAL_BUILD, |
There was a problem hiding this comment.
P2: This does not verify which bundle loadMicode() actually imports: it only checks the path helper and reads the local file directly. An unconditional import("micode") regression would still pass; assert that loadMicode() returns the export from the local build.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At v2-adapter/test/local-build.test.js, line 29:
<comment>This does not verify which bundle `loadMicode()` actually imports: it only checks the path helper and reads the local file directly. An unconditional `import("micode")` regression would still pass; assert that `loadMicode()` returns the export from the local build.</comment>
<file context>
@@ -0,0 +1,73 @@
+
+check(
+ "a local build is found",
+ localBuildPath() === LOCAL_BUILD,
+ `no build at ${LOCAL_BUILD}; run \`bun run build\` in the repo root`,
+);
</file context>
| } | ||
|
|
||
| const categories = matchCategories(task, mindmodel.manifest); | ||
| const all = await loadExamples( |
There was a problem hiding this comment.
P2: This rereads every category file for each uncached task, and loadExamples reads them sequentially. Cache the loaded examples per mindmodel so every new prompt does not pay for all of this I/O.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At src/hooks/mindmodel-injector.ts, line 103:
<comment>This rereads every category file for each uncached task, and `loadExamples` reads them sequentially. Cache the loaded examples per mindmodel so every new prompt does not pay for all of this I/O.</comment>
<file context>
@@ -94,13 +100,21 @@ async function resolveInjection(
}
- const categories = matchCategories(task, mindmodel.manifest);
+ const all = await loadExamples(
+ mindmodel,
+ mindmodel.manifest.categories.map((category) => category.path),
</file context>
| afterEach(() => { | ||
| // Only `warn` is asserted on throughout; `info` and `error` are read here so | ||
| // the derivation notice counts as inspected rather than as stray output. | ||
| void logs.info; |
There was a problem hiding this comment.
P2: These unconditional reads make unexpected console.error and unasserted console.log output pass silently in every test. Assert expected derivation notices in the tests that produce them, and leave unexpected channels unread.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At tests/mindmodel/loader.test.ts, line 22:
<comment>These unconditional reads make unexpected `console.error` and unasserted `console.log` output pass silently in every test. Assert expected derivation notices in the tests that produce them, and leave unexpected channels unread.</comment>
<file context>
@@ -17,6 +17,10 @@ describe("mindmodel loader", () => {
afterEach(() => {
+ // Only `warn` is asserted on throughout; `info` and `error` are read here so
+ // the derivation notice counts as inspected rather than as stray output.
+ void logs.info;
+ void logs.error;
const stray = logs.unread();
</file context>
| const withoutDescription: LoadedMindmodel["manifest"] = { | ||
| name: "test", | ||
| version: 1, | ||
| // `description` is optional in the schema, so a manifest can carry one. |
There was a problem hiding this comment.
P3: The schema requires description, so the loader cannot produce this category; the cast only tests malformed input. Reword this as defensive malformed-input coverage, or make the schema optional if omission is supported.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At tests/tools/mindmodel-lookup.test.ts, line 82:
<comment>The schema requires `description`, so the loader cannot produce this category; the cast only tests malformed input. Reword this as defensive malformed-input coverage, or make the schema optional if omission is supported.</comment>
<file context>
@@ -0,0 +1,88 @@
+ const withoutDescription: LoadedMindmodel["manifest"] = {
+ name: "test",
+ version: 1,
+ // `description` is optional in the schema, so a manifest can carry one.
+ categories: [{ path: "notes.md" } as LoadedMindmodel["manifest"]["categories"][number]],
+ };
</file context>
micode 0.11.0 is a v1 plugin: it exports a named OpenCodeConfigPlugin, returns a v1 hooks object, and mutates the host config directly. v2 requires a default Plugin.define({id, setup}) and exposes no config mutation, so no released version loads on v2 — upstream main is still pinned to the v1 plugin package.
v2-adapter/ is a shim that runs the published plugin unchanged and translates its v1 API surface into v2: agents via ctx.agent.transform, commands and tools via their editors, MCP via ctx.mcp.transform, permissions via a ctx.permission evaluate hook, and the v1 hooks onto ctx.session.hook / ctx.tool.hook / ctx.event.subscribe.
Two v2 gaps shape the design:
SessionDomain is a Pick that omits compact and remove, so a plugin cannot request a compaction. micode's Auto-Compact is disarmed by withholding the token counts it triggers on — session.usage.updated carries cumulative session usage, which is not what its per-request ratio expects — and summarize() rejects rather than parking the hook in a two-minute wait. OpenCode's own compaction.auto does the compacting.
ctx.session.prompt admits and returns a receipt in v2, where v1 returned the reply synchronously. The client shim waits and re-reads context so spawn_agent and octto's probe agents still receive a reply.
Verified on 2.0.21: no load errors, 26 agents, 4 commands, 41 tools, the context7 MCP server and 6 bridged hooks all present in the live registries, and subagent spawning works end to end with a live model.
npm test runs the real upstream plugin against a stand-in host in both directions: 11 assertions, no server required.
What
Brief description of the change.
Why
What problem does this solve? Link to related issue if applicable.
Checklist
bun run checkpassesSummary by cubic
Adds
v2-adapter/, a shim that runs the published micode 0.11.0 plugin on OpenCode v2 despite its v1 plugin API, and fixes the bugs that fix exposed.v2-adapter
ctx.agent.transform, commands and tools via their editors, MCP viactx.mcp.transform, permissions via actx.permissionhook, and v1 hooks ontoctx.session.hook/ctx.tool.hook/ctx.event.subscribe.session.compact/remove(Auto-Compact disarmed by withholding the token counts it triggers on), andctx.session.promptreturning a receipt instead of a reply (client shim waits and re-reads context).ConstraintViolationError, resubscribes the event bridge with backoff, seeds agent permissions fromconfig.permissionplussubagent(per-agent denies layer over the base), boundssession.waitwith a 5-minute race, parses features withjsonc-parser, queues log writes on a timer, and readssession.deleted's id from both the 2.0.21 and fallback shapes.dist/build over the published bundle, so prompt fixes actually reach running agents;local-build.test.jsasserts the resolution order and that the loaded bundle teaches the array-form call.npm testruns the real upstream plugin against a stand-in host (16 assertions, no server).Related fixes
spawn_agent's single{ agents: [...] }array schema; batched spawns previously failed validation and spawned nothing. The contract test pins prompts to the schema, verifies one call overlaps all agents concurrently, and asserts every element is complete.mindmodellookup: a manifest-less.mindmodel/no longer loads as null, and matching is now symmetric over a file's path, description, and headings instead of only the description.v2-adapterfrom the root biome/eslint configs (makingbun run checkgreen) and syncs the biome schema URL with the installed CLI.Written for commit 2469fea. Summary will update on new commits.