feat(scripts): build the folder OpenCode loads from /etc #269

Merged
claudiomaradonna merged 4 commits from feat/opencode-system-directory into main 2026-12-02 11:00:26 +01:00
Collaborator

Why

Agent Foundry reaches a repository only by adoption, which copies the
policy, skills, subagents, and hooks into it, so every change to the
source needs a foundry-upgrade in each repository. An operator who
launches OpenCode bots through Azkaban on repositories that must stay
free of agent files can instead mount one read-only folder at
/etc/opencode, OpenCode's system directory on Linux. This adds a build
that lays the foundry out as that folder, as a first form loaded from
outside the repository, with a shared part laid out so Claude Code and
Codex can join later as targets of their own.

Closes #268

What changed

scripts/build-form.sh <target> <commit> <folder> builds from one
commit of the source. The target shared writes skills/ and, beside
it, agent-foundry/ with the policy, briefs, scripts, templates, hooks,
and the commit built. The target opencode, with --mount
(/etc/opencode unless given), adds opencode.json, whose
instructions name the policy, a location file, and the project's
AGENTS.local.md, plus the subagent adapters and the hook plugins.

The source's AGENTS.md, skills, and adapters stay as they are. The
passages that differ for a mounted folder live in
scripts/forms/shared/, each beside the source text it replaces, and
the build fails, naming the passage, when the commit no longer holds
that text once. In the built policy the project's facts come from the
project's own AGENTS.md or git-ignored AGENTS.local.md; the project
keeps .plans/ and .worktrees/ out of Git its own way, and an agent
that finds them not ignored stops; reviewers read the policy and briefs
from the folder; foundry-upgrade is left out, since a newer source
arrives by a rebuild.

A rebuild replaces only an earlier build, listed in a manifest at the
folder's root, and refuses any other non-empty folder untouched. The
build refuses a commit holding a symbolic link among the files it reads.
docs/INSTALL.md gains the section Folder for OpenCode's system
directory, which the README's Quick start points to.

How to verify

Base main at 7f979bd, branch feat/opencode-system-directory at
249629c. Build the folder from a clone:

git fetch origin feat/opencode-system-directory
git switch feat/opencode-system-directory
scripts/build-form.sh opencode HEAD ~/agent-foundry-forms/opencode
cat ~/agent-foundry-forms/opencode/agent-foundry/commit

Expected: the build prints built opencode of 249629c... and the commit
file holds that hash; ~/agent-foundry-forms/opencode holds
opencode.json, agents/, plugins/, lib/, skills/, and
agent-foundry/.

Untested here, the run on OpenCode: opencode is not on the
workstation the change was made on. Mounted read-only at /etc/opencode
on OpenCode 2.x, in a repository holding no foundry file, a session is
expected to quote the policy without a tool call, list the skills
without foundry-upgrade, launch each subagent, and refuse an edit in
the main checkout with "main-checkout guard:". The checks and their
expected results are in docs/INSTALL.md § Checking a mounted folder;
whether the system directory loads agents/ and plugins/, and plugins
importing lib/ from beside them, is what that run settles.

Checks run on 249629c: bash tests/verify-agent-config.sh, 391 tests
passed with none skipped; bash tests/check-work-folder.sh, 46 passed;
.agents/hooks/shellcheck.sh repo, 53 files clean;
prettier --check '**/*.md'; scripts/verify-agent-config.sh, valid in
template state; git diff --check main. The new area
tests/agent-config/build-form.sh, 29 tests, fails on main where it
calls the script the change adds; opencode-plugins.sh passes on both
revisions with the shared Node runner moved into lib.sh.

Considerations

  • The built text in scripts/forms/ is a second version of a few
    passages of AGENTS.md and two skills; the area fails when the
    source's passage changes, so its replacement is read again.
  • The build keeps its own copy of the awk rules of
    evals/install-policy.sh that strip the template state, set aside so
    that file stays untouched here.
  • docs/INSTALL.md says Bash 4 or later, where an empty array under
    set -u needs 4.4; and --mount takes only a plain absolute path,
    which excludes macOS and Windows system directories. Both were set
    aside as low.
  • The guard against a script at the same relative path in the working
    directory is a rule the agent follows, in the built run-sandboxed
    step and the location file, not a mechanism.

https://claude.ai/code/session_012wUN2eKSj9s2vRHJdFPNk3

## Why Agent Foundry reaches a repository only by adoption, which copies the policy, skills, subagents, and hooks into it, so every change to the source needs a `foundry-upgrade` in each repository. An operator who launches OpenCode bots through Azkaban on repositories that must stay free of agent files can instead mount one read-only folder at `/etc/opencode`, OpenCode's system directory on Linux. This adds a build that lays the foundry out as that folder, as a first form loaded from outside the repository, with a shared part laid out so Claude Code and Codex can join later as targets of their own. Closes #268 ## What changed `scripts/build-form.sh <target> <commit> <folder>` builds from one commit of the source. The target `shared` writes `skills/` and, beside it, `agent-foundry/` with the policy, briefs, scripts, templates, hooks, and the commit built. The target `opencode`, with `--mount` (`/etc/opencode` unless given), adds `opencode.json`, whose `instructions` name the policy, a location file, and the project's `AGENTS.local.md`, plus the subagent adapters and the hook plugins. The source's `AGENTS.md`, skills, and adapters stay as they are. The passages that differ for a mounted folder live in `scripts/forms/shared/`, each beside the source text it replaces, and the build fails, naming the passage, when the commit no longer holds that text once. In the built policy the project's facts come from the project's own `AGENTS.md` or git-ignored `AGENTS.local.md`; the project keeps `.plans/` and `.worktrees/` out of Git its own way, and an agent that finds them not ignored stops; reviewers read the policy and briefs from the folder; `foundry-upgrade` is left out, since a newer source arrives by a rebuild. A rebuild replaces only an earlier build, listed in a manifest at the folder's root, and refuses any other non-empty folder untouched. The build refuses a commit holding a symbolic link among the files it reads. `docs/INSTALL.md` gains the section Folder for OpenCode's system directory, which the README's Quick start points to. ## How to verify Base `main` at `7f979bd`, branch `feat/opencode-system-directory` at `249629c`. Build the folder from a clone: ```bash git fetch origin feat/opencode-system-directory git switch feat/opencode-system-directory scripts/build-form.sh opencode HEAD ~/agent-foundry-forms/opencode cat ~/agent-foundry-forms/opencode/agent-foundry/commit ``` Expected: the build prints `built opencode of 249629c...` and the commit file holds that hash; `~/agent-foundry-forms/opencode` holds `opencode.json`, `agents/`, `plugins/`, `lib/`, `skills/`, and `agent-foundry/`. **Untested here, the run on OpenCode:** `opencode` is not on the workstation the change was made on. Mounted read-only at `/etc/opencode` on OpenCode 2.x, in a repository holding no foundry file, a session is expected to quote the policy without a tool call, list the skills without `foundry-upgrade`, launch each subagent, and refuse an edit in the main checkout with "main-checkout guard:". The checks and their expected results are in `docs/INSTALL.md` § Checking a mounted folder; whether the system directory loads `agents/` and `plugins/`, and plugins importing `lib/` from beside them, is what that run settles. Checks run on `249629c`: `bash tests/verify-agent-config.sh`, 391 tests passed with none skipped; `bash tests/check-work-folder.sh`, 46 passed; `.agents/hooks/shellcheck.sh repo`, 53 files clean; `prettier --check '**/*.md'`; `scripts/verify-agent-config.sh`, valid in template state; `git diff --check main`. The new area `tests/agent-config/build-form.sh`, 29 tests, fails on `main` where it calls the script the change adds; `opencode-plugins.sh` passes on both revisions with the shared Node runner moved into `lib.sh`. ## Considerations - The built text in `scripts/forms/` is a second version of a few passages of `AGENTS.md` and two skills; the area fails when the source's passage changes, so its replacement is read again. - The build keeps its own copy of the `awk` rules of `evals/install-policy.sh` that strip the template state, set aside so that file stays untouched here. - `docs/INSTALL.md` says Bash 4 or later, where an empty array under `set -u` needs 4.4; and `--mount` takes only a plain absolute path, which excludes macOS and Windows system directories. Both were set aside as low. - The guard against a script at the same relative path in the working directory is a rule the agent follows, in the built `run-sandboxed` step and the location file, not a mechanism. https://claude.ai/code/session_012wUN2eKSj9s2vRHJdFPNk3
A client that loads Agent Foundry from outside the repository needs the
policy, skills, briefs, scripts, templates, and hooks in a folder that
names no file under .agents/. build-form.sh lays that part out from one
commit, so every client's form shares it and a rebuild leaves nothing
of the build before.

The source stays as it is: each passage that differs sits in
scripts/forms/shared/ beside the source text it replaces, and the build
fails, naming it, when the commit no longer holds that text once, which
brings its replacement up for review.
OpenCode loads opencode.json, agents/, skills/, and plugins/ from its
system directory, so this target puts around the shared part what only
OpenCode reads. opencode.json hands over the policy, a location file
saying where agent-foundry/ paths sit, and AGENTS.local.md for a
repository whose facts live there.

--mount is held to a plain absolute path, since the build writes it
into commands and configuration as it is; the shared part stays the
same byte for byte whatever the mount.
docs(maintenance): say a quoted passage fails the build test
Some checks failed
Maintenance / checks (pull_request) Failing after 3m52s
Maintenance / checks (push) Failing after 3m47s
249629ccc9
The build of a form replaces passages of AGENTS.md and two skills, and
its area fails when a commit changes one of them, so that the text
replacing it is looked at too. A maintainer editing such a passage
needs to know to update its source.md and reread its replacement.md.
claudiomaradonna deleted branch feat/opencode-system-directory 2026-12-02 11:00:34 +01:00
First-time contributor

Command failed

The agent did not complete this command, so nothing came of it. A person should look at this thread.

The run failed at step "aoe_purge". The operator reads the job logs in the Windmill editor, or finds the run with: wmill job list --path f/agents/bot_commands

## Command failed The agent did not complete this command, so nothing came of it. A person should look at this thread. The run failed at step "aoe_purge". The operator reads the job logs in the Windmill editor, or finds the run with: `wmill job list --path f/agents/bot_commands`
Sign in to join this conversation.
No description provided.