Repository navigation
Register squad agents through the plugin API instead of agent files (#85) - #86
Merged
Merged
Conversation
The roster lives in squad.json (src/squad-store.js); src/squad-agents.js registers its agents with an early and a late agent transform. No agent file is written, pruned or migrated. Legacy generated files are imported once and hidden; a hand-authored agent with a roster id is left alone. Unit tests run against a throwaway config dir (tests/setup-isolation.js). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…son (#85) tests-integration/squad-agents.test.js runs the real plugin on OpenCode 2.1.3 with a global allow-all: drill tools are read-only, rm is refused, a dropped legacy agent is not dispatchable, squad_patch is live on the next dispatch, and a hand-authored agent with a squad id is left alone. The directory argument is gone from the tool schemas. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Without squad.json, the legacy squad on disk is the current roster: a patch that drops an agent is a deletion, and an unreadable legacy file makes dump say the squad is unknown and patch refuse. - Ours = fenced, or a marker-verified legacy file of the global agent dir (pre-fence files and worker-* included). Only those are hidden when the roster drops them; generated-looking agents from elsewhere are noted. - A hand-authored agent on an unchanged entry no longer blocks a patch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 19, 2026
Closed
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… alone (#87, #88) The early transform now creates one throwaway probe agent (primary, hidden, deny-all) instead of the squad's agents. The late transform reads the user's global rules off it, removes it, and builds each squad agent from a fresh default with the role rules last. Until the late transform runs a squad agent does not exist, so a request for it fails instead of running with a permissive tool catalog. The late transform is registered on plugin.updated, in the prompt hook (before the host selects the agent, child sessions included) and in the context hook. On a squad agent's request the context hook checks that the role rules are still last, moves the late transform back to the end if the config plugin's was re-registered behind it, and drops the tools the role denies from the request's catalog. A legacy file proves ownership of the file, not the id: an agent at a legacy or roster id is taken over or hidden only when it is that file (same prompt and model). Any other agent there is left exactly as the host built it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`p/m-1` and `p/m.1` both become `grunt-p-m-1`. squad_patch now refuses such a roster before writing; a stored roster registers neither entry and squad_dump names both; the legacy import refuses files that would collide. The file writer had this check (#52) and #86 dropped it with the writer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
squad_dump prints a `revision` (a hash of squad.json's bytes, read in the same read as the roster) and squad_patch requires it back. A patch whose base is no longer current is refused, so two edits of one dump cannot silently undo each other and the deletion guard always compares against the roster actually replaced. The handler finishes every await (variants, the host's agent list) before it reads the roster; read, check, plan and write then run synchronously under an exclusive squad.json.lock, which keeps other OpenCode processes sharing the config dir out. A held lock is refused with "retry", one older than 30 s is taken over. The legacy import takes the same lock. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
) One contract for startup, reloads and squad_patch. The plugin keeps the settings it last read without a problem for the life of the instance; with none read yet, each squad agent's description says the owner's rules are unknown and to ask the user before giving it secrets. squad_dump and the patch report name the file. squad_patch no longer refuses over it: the roster write never carried the rules, and refusing there while registration went ahead was the inconsistency the ticket describes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
README and squad-draft: squad_dump prints a revision that squad_patch needs back, a stale one is refused; colliding model ids are refused; an agent of the user's at a squad id keeps its whole definition; a legacy file is taken over only when it is the agent OpenCode loaded; squad agents exist only once OpenCode's config is applied; what an unreadable model_data.json does to descriptions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The per-request check picked squad agents by their prompt fence, so a stray fenced file of a project's own, or a legacy agent left live while squad.json is unreadable, had its tools cut and set off a re-registration on every request. It now covers only the ids the late transform built. squad_patch's ownership test matches registration: an agent at an added or changed id is the user's unless the plugin built it or it is our own legacy file. A fenced file of someone else's no longer passes as ours, which reported "+1 added" for an entry that was then not registered. A failed re-registration no longer leaves a disposed handle behind. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An existsSync check followed by a write to the same path is a js/file-system-race finding even in a test. An exclusive create both checks that the lock was released and plays the other holder. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
#92) The reload decision compared mtime:size, while patches identify a roster by the hash of its bytes. An equally long roster with the old timestamp left a running process on the previous roster until some later write. The context hook now compares the content revision; storeSignature is gone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Stale-lock recovery removed the lock by path, so a process that saw an abandoned lock could delete the fresh one another process had just taken, and both writers committed. A lock someone else holds is now never removed, however old: the patch is refused, and a lock older than 30 s is named with its holder for the user to delete. Release removes the lock only if it still carries this call's token. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…field for field (#88) Model and prompt equality could not tell the generated file from a project agent that copied them and changed its description or variant, so an empty roster hid the user's agent. The live agent must now equal what the host builds from the file alone: the host's fresh-agent defaults (seen by the early transform), the file's fields, and the rules (as a multiset: later transforms such as the browser plugin's append after the file's own). Only the last generator's format is modelled; any other file is never treated as the live agent and the dump says to delete it. The probe's id is now random per plugin instance, so a user's agent named opencode-squad-probe is no longer merged into it and removed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…deQL, tsc) Release no longer reads the lock back by path: the descriptor it was created with still being linked means it is still ours at the path. The holder is read through one descriptor, so its age and owner are of the same file. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #85. Closes #52. Closes #87. Closes #88. Closes #89. Closes #90. Closes #91. Closes #92.
The squad no longer exists as agent files. The roster lives in
squad.jsonin the OpenCode config dir, and the plugin registers its agents through the OpenCode 2 agent API. With no agent file written, pruned or migrated, the whole class of filesystem bugs is gone: aliasing (#52), ownership markers (#51), damaged headers (#16) and dangling links. The design and both spike rounds are in #85; the review findings on this PR are #87–#92.How it works
src/squad-store.js: one roster file the plugin owns.squad_patch.squad_dumpreports it, andsquad_patchrefuses.revision, a hash of the bytes it was read from.src/squad-agents.js: agents built after OpenCode's config is applied. Agent transforms run in registration order, and a plugin's setup-time transform runs before the built-in config-agent plugin, which appends the user's global rules to every existing agent. So:plugin.updated, in theprompthook (before the host selects the agent; child sessions included) and in thecontexthook. It runs after the config plugin. It reads the global rules off the probe and removes it, then builds each squad agent from a fresh default: base, global rules, role rules last. With last-match evaluation a drill stays read-only under a global allow-all, and the host hides its denied tools.contexthook checks the role rules are still last. If the host re-activated plugins and the config plugin's transform landed behind ours, late is re-registered at the end, and the request's tool catalog (built before the hook) is cut to what the role allows.Which agents are the squad's. One the late transform built, or a file an earlier version generated in the global agent dir, verified by its marker, and only when the agent OpenCode loaded at that id is exactly that file: equal, field for field, to what the host builds from the file alone (host defaults, the file's fields, its rules). Only the last generator's format is modelled; an older file is never treated as the live agent, and the dump says to delete it. A verified file proves ownership of the file, not of the id (Agent registration changes the effective configuration of a hand-authored agent sharing its ID #88). Every other agent at a squad id is the user's:
squad_dumpnotes it;squad_patchrefuses to add or change that entry.squad_patchuses the same test as registration.Colliding ids (Distinct roster model IDs can silently collapse into one registered agent #90). Model ids that map to one agent id (
p/m-1,p/m.1) are refused bysquad_patchand by the legacy import. A stored roster registers neither entry andsquad_dumpnames both.squad_patch(Concurrent squad_patch calls can silently erase successful roster changes #89).squad.json.lock, it reads the roster and checks therevisionthe caller got fromsquad_dump. A stale revision is refused and nothing is written.model_data.jsonthat cannot be read (An unreadable model_data.json removes owner rules from live Squad agents #91). One contract for startup, reloads and patches:squad_dumpand the patch report name the file.Migration.
grunt-*/drill-*/worker-*files in the global agent dir is imported intosquad.jsononce.squad_dumplists them as deletable.Breaking changes
directoryargument ofsquad_dump/squad_patchis removed and refused with an explanation.squad_patchrequires therevisionfromsquad_dump.agentsentry in anopencode.json, or an agent file, at a squad id makes that agent the user's. It no longer tunes the squad agent; usesquad_patch.squad_patchno longer refuses whilemodel_data.jsonis unreadable. It writes the roster and names the file instead.squad.jsonthere instead.Version bumped to 0.6.0: merging this PR cuts the release.
Removed
AGENT_SOURCESmirroring the loader, dangling/damaged refusals);agentMarkdown;model_data.json;Tests
Unit (374):
squad-store: revision; the lock is never taken over, old or live holder; release only of our own;squad-agents: probe, late build order, ownership, collisions,deniedTools,endsWithRoleRules;squad-apply;runtime-model-data: the describer contract, collision import;plugin-entry: a host stub that orders early, config plugin and late like the host, can re-register the config plugin behind late, and counts reloads.Isolation. Unit tests never touch the real OpenCode config (
tests/setup-isolation.js). During development a test run wrote asquad.jsoninto the developer's real config dir before this guard existed; it was removed.Integration (14), on real OpenCode 2.1.3 with TestLLM and the user's global rule
* allow:squad-agents.test.js:rmrejected,git logruns;worker-*included;squad-review.test.js, each reviewer scenario as reported:rmis rejected;opencode-squad-probeis left intact;model_data.jsonunreadable, the live description says the owner rules are unknown;Mutation. Each change below makes the named test fail:
plugin.updatedoff instead, A drill’s first direct request exposes tools outside its read-only policy #87 still passes through the prompt hookCoverage 98%. Lint, knip and typecheck pass.
Not covered
plugin.updated).🤖 Generated with Claude Code