Skip to content

Commit 7e5da99

Browse files
committed
feat: multi directory AGENT.md support
1 parent 0bf2d2e commit 7e5da99

8 files changed

Lines changed: 157 additions & 35 deletions

File tree

AGENTS.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ It stores strict project rules that define architecture policy including:
99
- code patterns
1010
- custom strict rules
1111

12-
Based on the target project, stack modules are combined into a single root `AGENTS.md` via the appropriate skill. It assembles project-specific rules while preserving shared conventions.
12+
Based on the target project, stack modules are combined into root and nested `AGENTS.md` files via the appropriate skill when subprojects need more specific policy. It assembles project-specific rules while preserving shared conventions.
1313

1414
# Folder Structure
1515
Current repository layout:
@@ -28,6 +28,8 @@ Current repository layout:
2828
SKILL.md
2929
modules/ # stack-specific guidance
3030
<module-name>/doc.md
31+
<subproject>/
32+
AGENTS.md # nested policy for a specific app/service/package
3133
```
3234

3335
# Root AGENTS.md rules
@@ -41,12 +43,18 @@ Current repository layout:
4143
- `doc.md` must include references to all baseline and stack modules.
4244
- `doc.md` must provide a canonical table with short stack key, full stack name, module path, and `load_when`.
4345
- `doc.md` must instruct agents to always load baseline modules and load project-specific stacks by `load_when` signals.
46+
- `doc.md` must define when to create nested `AGENTS.md` files and how parent/child precedence works.
4447
- `doc.md` must define section semantics: `Strict rules` for technical constraints, and `Working Agreements` for user-agent interaction protocol.
4548
- `doc.md` must define how to load and enforce `awesome/index.md` and matching awesome files.
4649
- Changes to module paths or routing signals must update `doc.md` in the same change.
4750
- When adding a new stack, update `doc.md` with both the short stack key and full stack name.
4851
- Root `doc.md` should contain only routing/composition logic and helpers to assemble target `AGENTS.md`.
4952

53+
## Target Output
54+
- Target repositories may contain a root `AGENTS.md` plus nested `AGENTS.md` files for subprojects with distinct stack, runtime, or ownership boundaries.
55+
- Root `AGENTS.md` should stay repository-wide; nested `AGENTS.md` files should narrow rules for their subtree.
56+
- Nested `AGENTS.md` files should be created only for meaningful architecture boundaries such as apps, services, or packages with distinct tooling.
57+
5058
## Stack
5159
- Stack-specific guidance is maintained in `modules/*/doc.md`.
5260
- Enforced stack or capability libraries/utilities are maintained in `awesome/*`.
@@ -57,6 +65,7 @@ Current repository layout:
5765
## Skills
5866
- Skills are maintained in `skills/<skill-name>/SKILL.md`.
5967
- Skills must treat `doc.md` and `awesome/index.md` as the source of truth and must not introduce alternate router filenames.
68+
- Skills must support root and nested `AGENTS.md` output when the repository contains multiple app or service boundaries.
6069
- Skills that initialize from scratch or refactor existing repositories must run an architecture interview before selecting modules or refactoring code.
6170
- Skills must wait for explicit `Accept` before writing `AGENTS.md` or performing architecture-driven refactors.
6271
- Skills that mutate an existing codebase must propose a phased plan before editing files.

README.md

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,25 @@ Central source for shared AGENTS policies of [RevoTale](https://revotale.com).
1919
- `modules/<stack>/doc.md`: stack-specific modules.
2020
- `skills/<skill-name>/SKILL.md`: operational skills for greenfield init, AGENTS refresh, and guided refactors.
2121

22+
## Nested AGENTS.md
23+
24+
Target repositories may use a root `AGENTS.md` plus nested `AGENTS.md` files when different subprojects need more specific stack rules.
25+
26+
Example:
27+
28+
```text
29+
<repo-root>/
30+
AGENTS.md
31+
frontend/
32+
AGENTS.md
33+
package.json
34+
backend/
35+
AGENTS.md
36+
go.mod
37+
```
38+
39+
Use nested files for meaningful architecture boundaries such as apps, services, or packages with distinct tooling. The nearest `AGENTS.md` should apply to the active subtree, while parent files stay additive for shared rules.
40+
2241
## Skill Workflows
2342

2443
Use the skill that matches the repository stage.
@@ -28,21 +47,21 @@ Use the skill that matches the repository stage.
2847
Skill path: `skills/init-project-from-agent-docs/SKILL.md`
2948

3049
Example request:
31-
`Use https://github.com/RevoTale/agent-docs/skills/init-project-from-agent-docs skill to design the initial AGENTS.md for this new repository.`
50+
`Use https://github.com/RevoTale/agent-docs/skills/init-project-from-agent-docs skill to design the initial root and nested AGENTS.md files for this new repository.`
3251

3352
### Existing Repo AGENTS Refresh
3453

3554
Skill path: `skills/refresh-project-agents-from-agent-docs/SKILL.md`
3655

3756
Example request:
38-
`Use https://github.com/RevoTale/agent-docs/skills/refresh-project-agents-from-agent-docs skill to refresh AGENTS.md for this repository.`
57+
`Use https://github.com/RevoTale/agent-docs/skills/refresh-project-agents-from-agent-docs skill to refresh the root and nested AGENTS.md files for this repository.`
3958

4059
### Existing Repo Refactor
4160

4261
Skill path: `skills/refactor-project-to-agent-docs/SKILL.md`
4362

4463
Example request:
45-
`Use https://github.com/RevoTale/agent-docs/skills/refactor-project-to-agent-docs skill to align this repository with the recommended stack after an architecture interview.`
64+
`Use https://github.com/RevoTale/agent-docs/skills/refactor-project-to-agent-docs skill to align this repository and its nested subprojects with the recommended stack after an architecture interview.`
4665

4766
## Update Manually
4867

doc.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Overview
22
This file is the universal AGENTS router and composition contract.
3-
It defines which module files to load and how to merge them into a target repository `AGENTS.md`.
3+
It defines which module files to load and how to merge them into target repository `AGENTS.md` files.
44

55
# Canonical Module Registry
66
Use this table as the single source of truth for module routing.
@@ -21,6 +21,16 @@ Use this table as the single source of truth for module routing.
2121
3. If multiple modules match, load all matched modules.
2222
4. Any module add/remove/rename or signal change must update this table in the same change.
2323

24+
# Nested AGENTS.md Output
25+
- MUST create a root `AGENTS.md` for repository-wide topology, shared workflows, and cross-project constraints.
26+
- MUST create nested `AGENTS.md` files for deployable apps, backend services, frontend apps, packages, or subprojects with distinct stack signals, runtime boundaries, or policy needs.
27+
- MUST detect boundaries such as `frontend/`, `backend/`, `apps/*`, `services/*`, `packages/*`, or equivalent user-declared subprojects.
28+
- MUST select modules and matching awesome files independently for each nested subproject.
29+
- MUST apply the nearest `AGENTS.md` to files in its subtree.
30+
- MUST keep parent `AGENTS.md` files additive for shared rules.
31+
- MUST let the more specific nested `AGENTS.md` override parent rules when stack-specific or subtree-specific rules conflict.
32+
- MUST NOT create nested `AGENTS.md` files for ordinary folders that do not introduce distinct architecture, tooling, runtime, or ownership rules.
33+
2434
# Awesome Registry
2535
Use `awesome/index.md` as the entrypoint for enforced utility/library choices by stack or capability.
2636

@@ -91,6 +101,18 @@ When merging two project structures, produce a union of paths and preserve `OR`
91101
|bun.lock|bun.lockb
92102
```
93103

104+
#### Example of nested project structures
105+
```text
106+
<monorepo-root>/
107+
|AGENTS.md
108+
|frontend/
109+
| |AGENTS.md
110+
| |package.json
111+
|backend/
112+
| |AGENTS.md
113+
| |go.mod
114+
```
115+
94116
### Strict rules
95117
- MUST merge compatible requirements additively.
96118
- MUST treat stack modules as higher priority than baseline modules when strict rules conflict.

scripts/validate-agent-docs.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,21 @@ func parseSkillDoc(path string) (skillDoc, error) {
238238
return doc, nil
239239
}
240240

241+
func checkRequiredSubstrings(v *validator, path string, required ...string) {
242+
lines, err := readLines(path)
243+
if err != nil {
244+
v.failf("%s cannot be read: %v", path, err)
245+
return
246+
}
247+
248+
fullText := strings.Join(lines, "\n")
249+
for _, needle := range required {
250+
if !strings.Contains(fullText, needle) {
251+
v.failf("%s must mention %q", path, needle)
252+
}
253+
}
254+
}
255+
241256
func checkNormativeBullets(v *validator, filePath string, sectionTitle string) {
242257
lines, err := readLines(filePath)
243258
if err != nil {
@@ -403,20 +418,32 @@ func checkSkillFile(v *validator, skillPath string) {
403418
if !strings.Contains(lowerText, "interview") {
404419
v.failf("%s must require an architecture interview", skillPath)
405420
}
421+
if !strings.Contains(lowerText, "nested") {
422+
v.failf("%s must describe nested AGENTS.md creation", skillPath)
423+
}
406424
if !strings.Contains(fullText, "Accept") {
407425
v.failf("%s must require explicit Accept before writing", skillPath)
408426
}
409427
case "refresh-project-agents-from-agent-docs":
410428
if !strings.Contains(lowerText, "signal") {
411429
v.failf("%s must describe repository-signal based selection", skillPath)
412430
}
431+
if !strings.Contains(lowerText, "nested") {
432+
v.failf("%s must describe nested AGENTS.md refresh", skillPath)
433+
}
434+
if !strings.Contains(lowerText, "frontend/") && !strings.Contains(lowerText, "apps/*") {
435+
v.failf("%s must describe nested app or service boundaries", skillPath)
436+
}
413437
if !strings.Contains(fullText, "Accept") {
414438
v.failf("%s must require explicit Accept before writing", skillPath)
415439
}
416440
case "refactor-project-to-agent-docs":
417441
if !strings.Contains(lowerText, "interview") {
418442
v.failf("%s must require an architecture interview", skillPath)
419443
}
444+
if !strings.Contains(lowerText, "subtree") && !strings.Contains(lowerText, "subproject") {
445+
v.failf("%s must describe per-subtree or per-subproject refactoring", skillPath)
446+
}
420447
if !strings.Contains(lowerText, "plan") {
421448
v.failf("%s must require a refactor plan before edits", skillPath)
422449
}
@@ -535,6 +562,10 @@ func main() {
535562
checkSkillFile(v, skillPath)
536563
}
537564

565+
checkRequiredSubstrings(v, routerDocPath, "nested `AGENTS.md`", "nearest `AGENTS.md`", "root `AGENTS.md`")
566+
checkRequiredSubstrings(v, rootPolicyPath, "nested `AGENTS.md`", "subprojects", "multiple app or service boundaries")
567+
checkRequiredSubstrings(v, "README.md", "nested `AGENTS.md`", "frontend/", "backend/")
568+
538569
filesToCheck := make([]string, 0, len(moduleDocs)+2)
539570
filesToCheck = append(filesToCheck, rootPolicyPath, routerDocPath)
540571
filesToCheck = append(filesToCheck, moduleDocs...)

scripts/validate-agent-docs_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,35 @@ Ask for explicit Accept before writing files.
155155
t.Fatalf("expected interview requirement failure, got none")
156156
}
157157
}
158+
159+
func TestCheckRequiredSubstringsFailsWhenTextIsMissing(t *testing.T) {
160+
path := writeTempDoc(t, `# Overview
161+
Root policy only.
162+
`)
163+
164+
v := &validator{}
165+
checkRequiredSubstrings(v, path, "nested `AGENTS.md`")
166+
167+
if len(v.failures) == 0 {
168+
t.Fatalf("expected required substring failure, got none")
169+
}
170+
}
171+
172+
func TestCheckSkillFileRequiresNestedSupportForRefreshSkill(t *testing.T) {
173+
path := writeTempFile(t, "skills/refresh-project-agents-from-agent-docs/SKILL.md", `---
174+
name: refresh-project-agents-from-agent-docs
175+
description: Refresh AGENTS for an existing repository.
176+
---
177+
178+
# Skill
179+
180+
Use repository signals and ask for explicit Accept before writing files.
181+
`)
182+
183+
v := &validator{}
184+
checkSkillFile(v, path)
185+
186+
if len(v.failures) == 0 {
187+
t.Fatalf("expected nested support failure, got none")
188+
}
189+
}

skills/init-project-from-agent-docs/SKILL.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,37 +10,41 @@ Use this skill when the repository is empty or early-stage and the user wants th
1010
## Workflow
1111

1212
1. Run a short architecture interview.
13-
- Ask only the questions needed to choose architecture: app purpose, user-facing surfaces, runtime shape (`web app`, `API`, `worker`, `CLI`), data and storage, auth and identity, key integrations, deployment constraints, and any mandated technologies.
13+
- Ask only the questions needed to choose architecture: app purpose, whether the repository is single-app or multi-app, user-facing surfaces, runtime shape (`web app`, `API`, `worker`, `CLI`), data and storage, auth and identity, key integrations, deployment constraints, and any mandated technologies.
1414
- If an answer is missing but a safe default exists, state the assumption explicitly instead of blocking.
1515
- If the repository already has substantial code or tooling, switch to `refresh-project-agents-from-agent-docs` or `refactor-project-to-agent-docs`.
1616

1717
2. Load the current policy source of truth.
1818
- Resolve `doc.md` first, then `awesome/index.md`.
1919
- Load always-on modules from `doc.md`.
20-
- Load stack modules whose `load_when` conditions match the interview answers or any existing repository signals.
21-
- Load matching awesome files by stack and capability.
20+
- Detect meaningful subproject boundaries such as `frontend/`, `backend/`, `apps/*`, `services/*`, `packages/*`, or user-declared app and service directories.
21+
- Load stack modules whose `load_when` conditions match the interview answers or the signals for each subproject boundary.
22+
- Load matching awesome files by stack and capability for the root and each nested subproject.
2223
- Do not hardcode technology names when the router or awesome registry can decide them.
2324

2425
3. Propose the initial architecture before writing.
2526
- Summarize the project brief in 3-6 bullets.
26-
- Show selected modules and why they match.
27-
- Show selected awesome capabilities and the required libraries they imply.
28-
- Draft the target `AGENTS.md` structure with `Overview`, `Base Policy Links (Load First)`, and `Local Details`.
27+
- Show the proposed repository topology, including whether nested `AGENTS.md` files are needed.
28+
- Show selected modules and why they match for the root and each nested subproject.
29+
- Show selected awesome capabilities and the required libraries they imply for each boundary.
30+
- Draft the target `AGENTS.md` structure for the root and any nested subprojects with `Overview`, `Base Policy Links (Load First)`, and `Local Details`.
31+
- Explain that the nearest `AGENTS.md` applies to a subtree while parent files stay additive for shared rules.
2932
- Call out assumptions, open questions, and non-default choices.
3033

3134
4. Wait for explicit approval.
3235
- Ask for explicit `Accept` before creating or updating `AGENTS.md` or suggesting code scaffolding.
3336
- If the user changes scope, revise the proposal and ask again.
3437

35-
5. Write the initial `AGENTS.md`.
36-
- Create a repository-specific `Overview`.
37-
- Add links to `doc.md`, `awesome/index.md`, always-on modules, and matched stack modules.
38+
5. Write the initial `AGENTS.md` files.
39+
- Create a repository-specific root `Overview`.
40+
- Add links to `doc.md`, `awesome/index.md`, always-on modules, and matched stack modules for the root and each nested subproject.
3841
- Use latest default-branch links unless the user asked for commit-pinned links.
39-
- Keep `Local Details` limited to project-specific constraints, decisions, and approved exceptions.
42+
- Keep root `Local Details` focused on shared constraints and keep nested `Local Details` focused on subtree-specific constraints, decisions, and approved exceptions.
4043
- Do not inline module policy text when links are sufficient.
4144
- Do not copy awesome registry tables into the target `AGENTS.md`.
4245

4346
6. Validate and report.
4447
- Confirm every linked file exists in the selected `agent-docs` revision.
45-
- Report which router, module, and awesome files were selected and why.
48+
- Report which root and nested `AGENTS.md` files were created and why those boundaries were chosen.
49+
- Report which router, module, and awesome files were selected for each boundary.
4650
- Report any assumptions that still need user confirmation.

skills/refactor-project-to-agent-docs/SKILL.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,36 +20,38 @@ Use this workflow when the goal is to align an existing project with `agent-docs
2020
## Workflow
2121

2222
1. Run the architecture interview.
23-
- Capture app purpose, critical flows, runtime surfaces, data and storage, auth and identity, integrations, deployment constraints, mandated technologies, and allowed migration risk.
23+
- Capture app purpose, whether the repository is single-app or multi-app, critical flows, runtime surfaces, data and storage, auth and identity, integrations, deployment constraints, mandated technologies, and allowed migration risk.
2424
- Separate what may change now from what must stay stable.
2525
- If the repository intent is already documented, confirm it instead of re-asking everything.
2626

2727
2. Load the current `agent-docs` source of truth.
2828
- Resolve `doc.md` first, then `awesome/index.md`.
29-
- Load always-on modules, matched stack modules, and matching awesome files.
30-
- Use repository signals and interview answers together to choose the target architecture.
29+
- Detect app and service boundaries such as `frontend/`, `backend/`, `apps/*`, `services/*`, `packages/*`, or equivalent user-declared subprojects.
30+
- Load always-on modules, matched stack modules, and matching awesome files for the root and each subtree.
31+
- Use repository signals and interview answers together to choose the target architecture for each subtree.
3132
- Treat the current repository `AGENTS.md` as local input to preserve valid repository-specific exceptions, not as the router source of truth.
3233

3334
3. Audit the target project against policy.
34-
- Inspect structure, dependency and runtime setup, task runner config, lint and format config, tests, build entrypoints, and major code patterns.
35-
- Identify mismatches between current project state and loaded policy rules.
35+
- Inspect structure, dependency and runtime setup, task runner config, lint and format config, tests, build entrypoints, and major code patterns for the root and each subtree.
36+
- Identify mismatches between current project state and loaded policy rules per subtree.
3637
- Capture baseline command results for lint, test, and build when those commands exist.
3738

3839
4. Propose the target architecture and plan.
39-
- Summarize selected modules, awesome capabilities, and required library or tooling changes.
40+
- Summarize selected modules, awesome capabilities, and required library or tooling changes for the root and each nested subproject.
41+
- Explain where nested `AGENTS.md` files are required and how nearest-file precedence applies to each subtree.
4042
- Output an ordered phase plan with goals, impacted files, risks, validations, and rollback notes for risky steps.
41-
- Cover at minimum: structure, task runner/tasks, linting/formatting, code-style normalization, dependency alignment, and `AGENTS.md` updates.
43+
- Cover at minimum: structure, task runner/tasks, linting/formatting, code-style normalization, dependency alignment, and root plus nested `AGENTS.md` updates.
4244
- Ask for explicit `Accept` before editing.
4345

4446
5. Execute by phase.
4547
- Refactor structure to the approved policy-aligned layout and naming.
4648
- Refactor automation and tasking to match expected workflow patterns.
4749
- Refactor lint, format, and dependency setup to the approved stack and capability choices.
48-
- Refactor code style and architecture incrementally while preserving approved behavior.
49-
- Update `AGENTS.md` and developer documentation so commands and rules remain accurate.
50+
- Refactor code style and architecture incrementally per subtree while preserving approved behavior.
51+
- Update root and nested `AGENTS.md` files and developer documentation so commands and rules remain accurate.
5052

5153
6. Verify `agent-docs` compliance.
52-
- Build a rule-by-rule checklist from the loaded modules and awesome files.
54+
- Build a rule-by-rule checklist from the loaded modules and awesome files for the root and each subtree.
5355
- Mark each rule as `pass`, `fail`, or `not-applicable` with file or command evidence.
5456
- Fix `fail` items that are in scope.
5557

0 commit comments

Comments
 (0)