Skip to content

feat(instructions)!: generate targets from instructions files - #37

Merged
showxu merged 18 commits into
masterfrom
feat/instruction-units
Oct 27, 2026
Merged

showxu merged 18 commits into
masterfrom
feat/instruction-units

Conversation

@showxu

@showxu showxu commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Instruction targets are now generated in full from instructions files, replacing the managed block that was spliced into hand-written files.

  • An instructions file has front matter (description, optional paths globs) and a body that starts with one heading at any level; every other heading is deeper.
  • Sources keep files in instructions/ or .agents/instructions/, including subdirectories; a file's name is its container-relative path. A project's own files in .agent/instructions/ are selected by bare name, read from the working tree and locked by hash.
  • A target is a notice line followed by the sections in declared order. A section with paths gets an "Applies when working on files matching …" line and, in project scope, goes to the AGENTS.md or GEMINI.md of the directory its patterns share.
  • A file is owned when it is blank or starts with the notice. Writing over any other file, including a 0.1.2 target that kept custom content, needs replace. Local links must resolve to a file in the checkout being written.
  • InstructionOperations.export(projectRoots:environment:) maps locked targets to their sections without writing.
  • Doctor's Codex size check counts only the project chain, as Codex does, and reports Claude files that keep Claude Code from reading a generated nested AGENTS.md.
  • initializeInstructions(named:environment:) creates .agent/instructions/<name>.md.
  • A declaration may omit sources, and operations rewrite agents.json only when its content changes.
  • The lock keeps its 0.1.2 field names, so earlier readers of user state keep working.

Breaking changes are listed under Unreleased in CHANGELOG.md. The version bump is left to release preparation.

Validation

  • swift build: pass
  • env -u CODEX_HOME -u CLAUDE_CONFIG_DIR -u XDG_CONFIG_HOME -u XDG_STATE_HOME -u XDG_CACHE_HOME swift test: 366 tests pass
  • swift build -c release: pass
  • swift format lint --strict --configuration .swift-format --recursive Package.swift Sources Tests: clean
  • End to end with agents-tools/cli built on this commit, in temporary homes: user-scope Claude Code and Codex files generated from 14 real instructions files are byte-identical and doctor reports no problems; a Swift package's AGENTS.md generated from its own and organization-shared files matches the expected content and keeps the committed declaration's bytes; skill 0.3.1 still reads and writes the resulting user state.
  • Two independent reviews from different model families; their findings are fixed on this branch.

Documentation

Documentation/Proposals/AgentInstructions.md, Documentation/Architecture/Instructions.md, State.md, Package.md, Watch.md, README.md and CHANGELOG.md describe the new behavior.

Consumer: agents-tools/cli#30 builds on this branch.

Instruction files carry front matter with a required description and
optional paths, may sit in subdirectories, and are named by their
container-relative path. A project's own files in .agent/instructions
are read from the working tree and selected by bare name.

Targets are generated in full from the selected sections: a notice line
followed by the bodies as written. Sections with paths are scoped by a
line after their first heading and, in project scope, written to the
AGENTS.md of the directory their patterns share. Managed blocks, title
detection, heading offsets and adoption are removed; writing over a file
agents did not generate requires replace. Local links must resolve in the
checkout being written.

Doctor reports hand-written targets, changed own files and broken links,
and its Codex size check now budgets only the project chain. Export maps
locked targets to their sections.
- Doctor reports any difference from a locked target as drift; the lock
  owns the file whether or not the notice line remains.
- Restoring a lock stops with InstructionError.ownChanged when a
  project's own instructions file changed since the lock.
- initializeInstructions(named:environment:) creates
  .agent/instructions/<name>.md under the project's state lock instead of
  writing into an arbitrary directory with its own lock.
- A file is owned when it is blank or starts with the notice; a lock
  entry alone no longer is, so a 0.1.2 target with custom content needs
  replace, and install, remove and doctor treat it as foreign.
- Install restores the locked targets and Claude import files instead of
  recomputing forwarding.
- Nested target directories cannot be symbolic links, .git, or inside
  another repository; local links resolve symbolic links before '..'.
- Own instructions are read by name for resolution and restore; a
  symbolic link at or below a search path is an error; discovery skips
  AGENTS.md and GEMINI.md.
- Removing a name equal to a declared reference removes that reference.
- Doctor covers own files used only by prompts, checks root forwarding
  only for a root Claude target, and reports Claude files that hide a
  nested AGENTS.md.
- Export places user sections without their content.
- A declaration may omit sources, and an unchanged declaration is not
  rewritten.
- Adding named own files reads only those files.
- Install leaves a deleted locked Claude import file deleted.
- Watch skips AGENTS.md and GEMINI.md in containers, as discovery does.
- State which containers cannot hold targets, and keep a retired target
  that differs from its lock without writing over it.
showxu added 14 commits October 26, 2026 18:52
Declare this repository's guide with the agents-tools shared package route
and test isolation units, and track the declaration and lock.
A committed link to an uncommitted file made materialization reject the
whole source, because Foundation resolves dangling links inconsistently.
Links are now checked with the kernel's resolution and lexical targets:
one that leaves the tree or resolves outside it is rejected, a dangling
one inside is kept. Copied subtrees use the same rule.
Lexical normalization treated 'here/..' as a no-op even when 'here' is
a link, so a dangling link such as 'here/here/../../settings.json' in a
skill passed validation and, once copied, read a file above the
installed skill. Links are now resolved component by component from
their directory, following links inside the root: a step above the
root, an absolute destination or a loop is rejected, and reaching a
missing entry, which the tree lacks wherever it is placed, is safe.
…arents

Splitting a destination into Swift characters let a prepended Unicode
mark join a following slash, hiding a separator from validation.
Components are now split and compared as UTF-8 bytes. A missing entry
ends resolution only when no '..' follows it, because a filesystem that
looks names up by case or normalization can resolve that entry to
another one in the same directory.
agents.json and agents.resolved were written in Foundation's layout,
which `prettier --check` rejects. They now use Prettier's default layout:
two-space indentation, "key": value, expanded objects, {} and [] for
empty containers, and arrays on one line when they fit in 80 columns.
Any operation that writes state rewrites a file in another layout even
when its content is unchanged. Empty lock sections stay because skill
0.3.1 requires them; journals, watch state and content hashes keep the
encoder's fixed bytes. This repository's own state is rewritten.
@showxu
showxu merged commit 65df60e into master Oct 27, 2026
10 checks passed
@showxu
showxu deleted the feat/instruction-units branch October 27, 2026 03:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant