agent-directives 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/README.md +385 -0
  2. package/directives/adaptive-routing.md +361 -0
  3. package/directives/architecture-boundaries.md +223 -0
  4. package/directives/codebase-navigation.md +325 -0
  5. package/directives/context-handoff.md +220 -0
  6. package/directives/error-memory.md +169 -0
  7. package/directives/exploration-mode.md +266 -0
  8. package/directives/session-decisions.md +193 -0
  9. package/directives/specification-driven-development.md +278 -0
  10. package/directives/task-framing.md +154 -0
  11. package/directives/test-driven-development.md +305 -0
  12. package/directives/type-driven-development.md +173 -0
  13. package/directives/verification.md +266 -0
  14. package/directives/workspace-isolation.md +219 -0
  15. package/dist/cli.d.ts +3 -0
  16. package/dist/cli.d.ts.map +1 -0
  17. package/dist/cli.js +232 -0
  18. package/dist/cli.js.map +1 -0
  19. package/dist/context-audit.d.ts +30 -0
  20. package/dist/context-audit.d.ts.map +1 -0
  21. package/dist/context-audit.js +75 -0
  22. package/dist/context-audit.js.map +1 -0
  23. package/dist/install.d.ts +18 -0
  24. package/dist/install.d.ts.map +1 -0
  25. package/dist/install.js +28 -0
  26. package/dist/install.js.map +1 -0
  27. package/dist/manifest.d.ts +25 -0
  28. package/dist/manifest.d.ts.map +1 -0
  29. package/dist/manifest.js +29 -0
  30. package/dist/manifest.js.map +1 -0
  31. package/dist/prompt.d.ts +3 -0
  32. package/dist/prompt.d.ts.map +1 -0
  33. package/dist/prompt.js +29 -0
  34. package/dist/prompt.js.map +1 -0
  35. package/dist/targets.d.ts +10 -0
  36. package/dist/targets.d.ts.map +1 -0
  37. package/dist/targets.js +32 -0
  38. package/dist/targets.js.map +1 -0
  39. package/manifest.json +387 -0
  40. package/package.json +74 -0
  41. package/skills/architecture-boundary-reviewer/SKILL.md +228 -0
  42. package/skills/code-reviewer/SKILL.md +77 -0
  43. package/skills/codebase-health-reviewer/SKILL.md +234 -0
  44. package/skills/harness-hooks-reviewer/SKILL.md +159 -0
  45. package/skills/implementation-task-planner/SKILL.md +205 -0
  46. package/skills/mcp-integration-reviewer/SKILL.md +157 -0
  47. package/skills/product-requirements-writer/SKILL.md +205 -0
  48. package/skills/production-readiness-reviewer/SKILL.md +240 -0
  49. package/skills/self-audit/SKILL.md +134 -0
  50. package/skills/spec-reviewer/SKILL.md +304 -0
  51. package/skills/subagent-driven-development/SKILL.md +236 -0
  52. package/skills/systematic-debugging/SKILL.md +313 -0
  53. package/skills/test-reviewer/SKILL.md +293 -0
  54. package/templates/AGENTS.md +120 -0
  55. package/templates/CLAUDE.md +115 -0
  56. package/templates/copilot-instructions.md +116 -0
  57. package/templates/decision-log.md +44 -0
@@ -0,0 +1,361 @@
1
+ ---
2
+ name: adaptive-routing
3
+ description: Selects the lightest safe workflow path, relevant directives/skills, and handoff requirements based on task intent, risk, and touched surfaces.
4
+ version: 1.3.0
5
+ required: true
6
+ category: workflow
7
+ tools:
8
+ - claude
9
+ - copilot
10
+ - codex
11
+ - cursor
12
+ triggers:
13
+ - every-task
14
+ - workflow-selection
15
+ - directive-selection
16
+ routing:
17
+ load: first
18
+ applies_to:
19
+ - implementation
20
+ - debugging
21
+ - review
22
+ - exploration
23
+ - policy-change
24
+ ---
25
+
26
+ # Adaptive Workflow Routing Directive
27
+
28
+ **When to load:** Load this directive first for every task, before task framing,
29
+ implementation, debugging, review, or exploration.
30
+
31
+ The router selects the lightest workflow that still proves safety. Do not load
32
+ every directive by default. Load the directives and skills required by the task
33
+ intent, risk level, and touched surfaces.
34
+
35
+ ---
36
+
37
+ ## Router Output
38
+
39
+ After routing, briefly display the active workflow path and directive/skill files
40
+ being used so reviewers can verify the agent loaded the expected guidance. Keep
41
+ this as routing evidence, not ceremony. When a harness or runtime provides logs,
42
+ treat its loaded-file manifest as authoritative for which directive files were
43
+ actually presented; the agent's route disclosure is useful self-report, not proof
44
+ of internal model attention.
45
+
46
+ For tiny low-risk edits, one sentence is enough:
47
+
48
+ ```md
49
+ Route: Light Path; using `directives/adaptive-routing.md`; no additional directives or skills required.
50
+ ```
51
+
52
+ Before major edits, output a short route decision:
53
+
54
+ ```md
55
+ ## Workflow Route
56
+
57
+ - Intent: <feature | bug-fix | refactor | docs | review | exploration | policy-change | mechanical>
58
+ - Path: <Light | Full | Debugging | Boundary | Workspace Isolation | Review | Exploration | Policy> or combined paths
59
+ - Risk: <low | medium | high> with reason
60
+ - Required directives: <paths>
61
+ - Required skills: <paths, if any>
62
+ - Evidence required: <tests/checks/proofs>
63
+ - Handoff required: <yes/no and why>
64
+ - Confirmation needed: <yes/no and why>
65
+ ```
66
+
67
+ For any non-trivial, ambiguous, high-risk, or cross-cutting task, use the full
68
+ block.
69
+
70
+ ---
71
+
72
+ ## Core Routing Rules
73
+
74
+ 1. **Start with project instructions.** Load project-level instructions first
75
+ (`AGENTS.md`, `CLAUDE.md`, `.github/copilot-instructions.md`, or equivalent).
76
+ 2. **Pick the lightest safe path.** Do not apply Full Path ceremony to purely
77
+ mechanical or docs-only work.
78
+ 3. **Escalate by risk.** User requests like "quickly" or "just" do not downgrade
79
+ safety for behavior, security, data, public API, or boundary changes.
80
+ 4. **Combine paths when needed.** A bug fix that changes imports uses Debugging
81
+ Path plus Boundary Path. A policy change with docs edits uses Policy Path plus
82
+ Light Path gates. Mutable work from a shared checkout may add Workspace
83
+ Isolation to the base path.
84
+ 5. **Prefer evidence over ritual.** Do not emit boilerplate sections with no
85
+ information. Show the proof that matches the selected path.
86
+ 6. **Compact context at boundaries.** Use `directives/context-handoff.md` when
87
+ switching major phases, handing work to another session/agent, or continuing
88
+ long-running work where stale context could drift.
89
+ 7. **Ask only when necessary.** If classification is uncertain and affects safety
90
+ or scope, ask one concise clarifying question. Otherwise choose the safer path
91
+ and state the assumption.
92
+ 8. **Bound the implementation.** Prefer the smallest safe change that satisfies
93
+ the task. Do not expand scope, rewrite adjacent code, introduce abstractions,
94
+ apply drive-by formatting, perform whole-file rewrites, or fix unrelated
95
+ issues unless current evidence requires it or the user explicitly requests it.
96
+
97
+ ---
98
+
99
+ ## Skill Discovery Map
100
+
101
+ Use this map after selecting the workflow path. Do not rely on inference when a
102
+ listed situation matches: load every matching skill before performing work it
103
+ covers. The path column shows where the situation commonly appears; it is not a
104
+ filter that prevents loading a matched skill when paths are combined or escalated.
105
+ If no row matches, state that no specialist skill is required.
106
+
107
+ | Situation / intent | Common path(s) | Required skill |
108
+ | --- | --- | --- |
109
+ | Vague feature idea, product request, or unclear requirement needs a PRD/spec | Exploration / Full / Policy | `skills/product-requirements-writer/SKILL.md` |
110
+ | PRD, issue, spec, or acceptance criteria needs implementation tasks | Exploration / Full / Policy | `skills/implementation-task-planner/SKILL.md` |
111
+ | Executing an existing implementation plan with multiple mostly independent tasks using delegated subagents or isolated worker sessions | Full / Debugging / Policy | `skills/subagent-driven-development/SKILL.md` |
112
+ | Bug, regression, failing test, failing CI/build/lint/type-check, or unexpected behavior | Debugging | `skills/systematic-debugging/SKILL.md` |
113
+ | Reviewing a PR, branch, diff, or local changes | Review | `skills/code-reviewer/SKILL.md` |
114
+ | Writing, changing, or reviewing tests/eval scenarios | Full / Review | `skills/test-reviewer/SKILL.md` |
115
+ | Implementation must be checked against a written spec/PRD | Full / Review | `skills/spec-reviewer/SKILL.md` |
116
+ | Imports, exports, package boundaries, folders, services, shared utilities, or dependency direction change | Boundary / Review | `skills/architecture-boundary-reviewer/SKILL.md` |
117
+ | TypeScript/JavaScript refactor, cleanup, shared utilities, dead-code, duplication, complexity, or static-analysis health concern | Full / Review | `skills/codebase-health-reviewer/SKILL.md` |
118
+ | Persistence, external services, async jobs, auth/security/privacy, infra/config/deploy, critical user paths, performance/scale, or cross-service compatibility | Full / Debugging / Review | `skills/production-readiness-reviewer/SKILL.md` |
119
+ | Agent harness hooks, start/stop hooks, pre-action hooks, post-change automation, or deterministic agent workflow scripts are added or reviewed | Full / Review / Policy | `skills/harness-hooks-reviewer/SKILL.md` |
120
+ | MCP servers/tools, agent-accessible internal APIs, structured search, docs/ticketing/analytics connectors, tool schemas, or write-capable agent tools are added or reviewed | Full / Review / Policy | `skills/mcp-integration-reviewer/SKILL.md` |
121
+ | Full Path work reaches post-REFACTOR pre-verification checkpoint | Full | `skills/self-audit/SKILL.md` |
122
+
123
+ ---
124
+
125
+ ## Workflow Paths
126
+
127
+ ### Light Path
128
+
129
+ Use for low-risk, non-behavioral changes:
130
+
131
+ - typo fixes
132
+ - docs wording edits
133
+ - comments
134
+ - formatting-only changes
135
+ - metadata changes that do not affect runtime, build, tests, packaging, or public API
136
+
137
+ Required:
138
+
139
+ - minimal orientation
140
+ - make the change
141
+ - run the relevant project quality gate when available
142
+ - provide concise verification
143
+ - skip handoff unless work will continue in another session or the user requests it
144
+
145
+ Do **not** use Light Path for bug fixes, behavior changes, public API changes,
146
+ dependency changes, boundary changes, or security/data/auth work.
147
+
148
+ ### Full Path
149
+
150
+ Use for normal implementation work:
151
+
152
+ - new features
153
+ - behavior changes
154
+ - meaningful refactors
155
+ - tests added or changed for behavior
156
+ - type/API changes
157
+
158
+ Required directives:
159
+
160
+ - `directives/codebase-navigation.md`
161
+ - `directives/task-framing.md` when non-trivial, ambiguous, high-risk, or cross-cutting
162
+ - `directives/type-driven-development.md` for typed projects or public contracts
163
+ - `directives/test-driven-development.md` for behavior-changing code
164
+ - `directives/verification.md`
165
+ - `directives/context-handoff.md` when switching major phases or handing off work
166
+
167
+ Required skills:
168
+
169
+ - `skills/product-requirements-writer/SKILL.md` when turning a feature idea or vague request into a PRD/spec before planning
170
+ - `skills/implementation-task-planner/SKILL.md` when turning a PRD/spec/issue into an implementation task list
171
+ - `skills/subagent-driven-development/SKILL.md` when executing an existing implementation plan through delegated subagents or isolated worker sessions
172
+ - `skills/self-audit/SKILL.md` after REFACTOR for Full Path work
173
+ - `skills/test-reviewer/SKILL.md` when tests are added or substantially changed
174
+ - `skills/spec-reviewer/SKILL.md` when reviewing implementation against a written spec or preparing spec-governed work for merge
175
+ - `skills/production-readiness-reviewer/SKILL.md` before merge/review when a change touches persistence, external services, async jobs, auth/security/privacy, infra/config/deploy, critical user paths, performance/scale, or cross-service compatibility
176
+ - `skills/harness-hooks-reviewer/SKILL.md` when the implementation adds or changes agent harness hooks or deterministic agent automation
177
+ - `skills/mcp-integration-reviewer/SKILL.md` when the implementation adds or changes MCP servers/tools, agent tool schemas, or agent-accessible internal API bridges
178
+
179
+ ### Debugging Path
180
+
181
+ Use for:
182
+
183
+ - bugs
184
+ - failing tests
185
+ - failing CI/build/lint/type-check
186
+ - regressions
187
+ - flaky or unexpected behavior
188
+
189
+ Required:
190
+
191
+ - `skills/systematic-debugging/SKILL.md`
192
+ - reproduce the failure before changing code
193
+ - add or identify a failing regression test when behavior changed
194
+ - use `directives/test-driven-development.md` for the fix when production behavior changes
195
+ - use `directives/verification.md` for fix proof and no-regression evidence
196
+ - use `directives/context-handoff.md` after reproduction, before a risky fix, or before resuming in a new session
197
+
198
+ ### Boundary Path
199
+
200
+ Add this path whenever the task touches:
201
+
202
+ - imports or exports
203
+ - folder/module/package moves
204
+ - public entry points
205
+ - shared utilities
206
+ - service/package boundaries
207
+ - dependency direction or architecture rules
208
+
209
+ Required:
210
+
211
+ - `directives/architecture-boundaries.md`
212
+ - `skills/architecture-boundary-reviewer/SKILL.md` before merge/review
213
+ - boundary proof in `directives/verification.md`
214
+ - compact changed dependency-edge evidence with `directives/context-handoff.md` before boundary review or session transfer
215
+
216
+ ### Workspace Isolation Path
217
+
218
+ Add this path whenever the task will mutate a git-backed repository from a
219
+ checkout that may be shared or unsafe to edit in place, especially when:
220
+
221
+ - the current branch is `main`, `master`, `trunk`, or another protected/default branch
222
+ - the working tree has unrelated local changes
223
+ - the user asks to protect the current workspace
224
+ - a native workspace tool or `git worktree` can provide clean isolation
225
+
226
+ Required:
227
+
228
+ - `directives/workspace-isolation.md`
229
+ - detect existing isolation before creating anything
230
+ - prefer native workspace tools over manual `git worktree`
231
+ - ask before creating a new isolated workspace when preference is unknown
232
+ - show either isolated-workspace proof or an explicit fallback reason before editing
233
+
234
+ ### Review Path
235
+
236
+ Use when the user asks to review a PR, branch, diff, or local changes.
237
+
238
+ Required skills:
239
+
240
+ - `skills/code-reviewer/SKILL.md` for baseline PR/branch/diff/local-change review
241
+ - `skills/test-reviewer/SKILL.md` for tests
242
+ - `skills/spec-reviewer/SKILL.md` for spec-backed work
243
+ - `skills/architecture-boundary-reviewer/SKILL.md` for imports/exports/packages/shared code
244
+ - `skills/codebase-health-reviewer/SKILL.md` for TypeScript/JavaScript refactors, cleanup, shared utilities, or Fallow-relevant changes
245
+ - `skills/production-readiness-reviewer/SKILL.md` for production-sensitive changes involving persistence, external services, async jobs, auth/security/privacy, infra/config/deploy, critical user paths, performance/scale, or cross-service compatibility
246
+ - `skills/harness-hooks-reviewer/SKILL.md` for agent harness hooks or deterministic agent automation
247
+ - `skills/mcp-integration-reviewer/SKILL.md` for MCP servers/tools, agent tool schemas, or agent-accessible internal API bridges
248
+
249
+ Do not edit code during Review Path unless the user asks for fixes. Use `directives/context-handoff.md` for compact PR/review handoffs when review findings will be fixed later or transferred to another session.
250
+
251
+ ### Exploration Path
252
+
253
+ Use when the user asks to investigate, compare options, explain, research, or
254
+ think through an approach.
255
+
256
+ Required:
257
+
258
+ - `directives/exploration-mode.md`
259
+ - `directives/codebase-navigation.md` when repo context is needed
260
+ - `skills/product-requirements-writer/SKILL.md` when the exploration output is a PRD/spec
261
+ - `skills/implementation-task-planner/SKILL.md` when the exploration output is an implementation task list
262
+
263
+ Do not edit files during Exploration Path unless the user explicitly switches to
264
+ implementation. Use `directives/context-handoff.md` when exploration produces decisions, constraints, or risks that an implementation session should inherit.
265
+
266
+ ### Policy Path
267
+
268
+ Use for changes to:
269
+
270
+ - directives or skills
271
+ - repo workflow
272
+ - contributor instructions
273
+ - architecture policy
274
+ - cross-cutting conventions
275
+
276
+ Required:
277
+
278
+ - `directives/task-framing.md`
279
+ - proposal before major edits when tradeoffs exist
280
+ - bump the frontmatter `version` for every existing `directives/*.md` or `skills/*/SKILL.md` file changed in the PR; use patch for wording/behavior tightening, minor for new heuristics/routing/evidence coverage, and major for incompatible routing/schema/path changes; raw deletions are rejected, so deprecate with a major version bump before deletion
281
+ - `directives/session-decisions.md` if the accepted change establishes or changes durable policy
282
+ - `directives/verification.md` before PR
283
+ - `directives/context-handoff.md` for multi-phase directive/workflow changes or new-session handoff
284
+ - `skills/harness-hooks-reviewer/SKILL.md` when policy changes affect agent harness hooks or deterministic automation
285
+ - `skills/mcp-integration-reviewer/SKILL.md` when policy changes affect MCP/tool surfaces exposed to agents
286
+
287
+ ---
288
+
289
+ ## Risk Escalation
290
+
291
+ Escalate to Full Path or add a specialized path when any of these are true:
292
+
293
+ | Risk trigger | Add |
294
+ | --- | --- |
295
+ | Auth, permissions, security, privacy, payments, data loss | Full Path + Production Readiness Review + stronger verification |
296
+ | Database schema, migrations, persistence, queues | Full Path + Production Readiness Review + explicit rollback/edge-case proof |
297
+ | External services, async jobs, infra/config/deploy, critical user paths, performance/scale, or cross-service compatibility | Full Path + Production Readiness Review |
298
+ | Agent harness hooks or deterministic agent automation | Policy/Full/Review Path + Harness Hooks Review |
299
+ | MCP servers/tools, agent-accessible APIs, or write-capable agent tools | Policy/Full/Review Path + MCP Integration Review; add Production Readiness Review for sensitive production systems |
300
+ | Public API, exported types, package entry points | Full Path + Integration Proof + Boundary Path |
301
+ | Imports, shared utilities, packages, folders, services | Boundary Path |
302
+ | Shared/default checkout, unrelated local changes, or explicit request for isolation before repo edits | Workspace Isolation Path |
303
+ | Failing CI/test/build/lint/type-check | Debugging Path |
304
+ | Cross-cutting policy or workflow | Policy Path |
305
+ | Large diff or broad refactor | Full Path + Self-Audit + Codebase Health Review + Context Handoff |
306
+
307
+ ---
308
+
309
+ ## Tool Feedback Handling
310
+
311
+ Run project-native quality gates selected by the route. Treat lint, type-check,
312
+ build, test, static-analysis, and review-bot output as implementation feedback.
313
+ Fix root causes rather than suppressing rules, weakening config, or making
314
+ superficial edits. If a finding is pre-existing or outside scope, document that
315
+ classification and avoid making the current change worse.
316
+
317
+ ---
318
+
319
+ ## Override Rules
320
+
321
+ - User may request a lighter or heavier workflow.
322
+ - Honor explicit user workflow preferences unless they would skip necessary
323
+ safety evidence for high-risk work.
324
+ - If the user asks for a quick fix to a risky area, keep the route safe and make
325
+ the implementation small.
326
+ - If the router chooses a heavier path than requested, state why in one sentence.
327
+
328
+ ---
329
+
330
+ ## Forbidden Patterns
331
+
332
+ | Pattern | Why Forbidden |
333
+ | --- | --- |
334
+ | Loading every directive by default | Wastes context and creates compliance theater |
335
+ | Using Light Path for behavior or bug fixes | Skips necessary proof |
336
+ | Treating "quick" as permission to skip safety | Risk depends on impact, not wording |
337
+ | Producing boilerplate verification with no evidence | Ritual is not proof |
338
+ | Appending active handoffs forever | Recreates context drift under a different filename |
339
+ | Ignoring lint/type/test/build feedback as "just tooling" | Tool output is implementation feedback |
340
+ | Adding cross-cutting tooling/config as a drive-by change | Policy changes need explicit review |
341
+ | Opportunistic refactors or cleanup outside the task | Increases review surface and hides behavior risk |
342
+ | Adding abstractions for hypothetical future use | Produces unnecessary code and weakens local fit |
343
+ | Printing or rewriting whole files when a targeted patch would work | Wastes context and increases accidental churn |
344
+
345
+ ---
346
+
347
+ ## Quick Reference
348
+
349
+ | Intent | Default path | Evidence |
350
+ | --- | --- | --- |
351
+ | Docs/typo/comment only | Light | diff + relevant gate |
352
+ | New feature | Full | RED/GREEN, functional proof, gates |
353
+ | Bug/regression | Debugging + TDD | reproduction, failing test/command, fix proof |
354
+ | Refactor | Full | no-behavior-change proof, tests, gates |
355
+ | Import/export/package/shared change | Boundary + relevant base path | boundary proof |
356
+ | Repo edits from shared/default checkout | relevant base path + Workspace Isolation | isolation proof or explicit fallback |
357
+ | PR/diff review | Review | structured findings |
358
+ | PRD/spec writing | Exploration | product requirements writer, essential questions, no code edits |
359
+ | PRD/spec/issue to task list | Exploration | implementation task planner, repo-grounded file/test/validation tasks, no code edits |
360
+ | Investigation/explanation | Exploration | repo evidence, no edits |
361
+ | Directive/workflow/policy change | Policy | proposal/tradeoffs, verification, handoff for multi-phase work, decision log if durable |
@@ -0,0 +1,223 @@
1
+ ---
2
+ name: architecture-boundaries
3
+ description: Preserves architecture DAG boundaries for imports, exports, packages, services, shared code, and dependency direction.
4
+ version: 1.0.0
5
+ required: false
6
+ category: architecture
7
+ tools:
8
+ - claude
9
+ - copilot
10
+ - codex
11
+ - cursor
12
+ triggers:
13
+ - imports
14
+ - exports
15
+ - packages
16
+ - architecture
17
+ - shared-code
18
+ - dependency-direction
19
+ routing:
20
+ load: conditional
21
+ ---
22
+
23
+ # Architecture Boundaries Directive
24
+
25
+ **When to load:** Load this directive before modifying imports, exports, module
26
+ structure, feature folders, shared utilities, service/package boundaries, or any
27
+ code whose correctness depends on dependency direction.
28
+
29
+ Passing tests is not enough if the change introduces an illegal dependency edge.
30
+ The agent must preserve the project's directed architecture graph.
31
+
32
+ ---
33
+
34
+ ## Core Rule: Preserve the DAG
35
+
36
+ Before implementation, identify the boundary context for every touched file:
37
+
38
+ 1. **Zone** — Which architectural layer, package, feature, service, or module owns it?
39
+ 2. **Allowed dependencies** — Which zones may this file import from?
40
+ 3. **New edges** — What imports, exports, call paths, or package references will change?
41
+ 4. **Forbidden edges** — Would any edge point upward, sideways, or across an internal boundary?
42
+
43
+ Forbidden by default unless the project explicitly allows it:
44
+
45
+ - Domain/core code importing UI, framework, infrastructure, or application code
46
+ - Shared/common utilities importing feature-specific or application-specific code
47
+ - Feature modules importing another feature's internals instead of its public API
48
+ - Presentation/UI importing database, filesystem, network, or infrastructure directly
49
+ - Tests or test helpers becoming production dependencies
50
+ - New circular dependencies between files, packages, layers, or services
51
+ - Cross-package imports that bypass the package's declared public entry point
52
+
53
+ If the project has explicit boundary rules, those override these defaults. If the
54
+ project has no explicit rules, infer the likely DAG from directory names,
55
+ package boundaries, and existing import patterns; document the inference before
56
+ changing code. If the inferred boundary materially changes the implementation
57
+ approach, ask the human or propose the inferred rule before coding.
58
+
59
+ ---
60
+
61
+ ## Boundary Discovery
62
+
63
+ Use progressive disclosure. Do not bulk-read the repository.
64
+
65
+ ### 1. Find explicit rules first
66
+
67
+ Look for project-owned boundary definitions before inferring your own:
68
+
69
+ - `AGENTS.md`, `CLAUDE.md`, `.github/copilot-instructions.md`
70
+ - architecture docs, ADRs, decision logs, or contribution docs
71
+ - `package.json` workspaces and package `exports`
72
+ - `tsconfig.json` path aliases / project references
73
+ - lint rules such as `import/no-restricted-paths`, `boundaries`, `dependency-cruiser`, `nx`, or monorepo constraints
74
+ - Fallow config (`.fallowrc.json`, `.fallowrc.toml`, `fallow` config)
75
+
76
+ ### 2. Classify touched files
77
+
78
+ For each file you expect to modify, record:
79
+
80
+ ```md
81
+ - `path/to/file.ts`
82
+ - Zone: `domain` / `application` / `ui` / `shared` / feature/package name
83
+ - Public API: yes/no; entry point if yes
84
+ - Allowed imports: list or inferred rule
85
+ - Existing dependents: known callers/importers
86
+ ```
87
+
88
+ ### 3. Identify changed edges
89
+
90
+ Treat these as boundary-relevant changes:
91
+
92
+ - adding or changing an `import` / `require` / dynamic import
93
+ - moving a file between directories/packages
94
+ - exporting a symbol from a public entry point
95
+ - importing from a deep internal path such as `feature-x/internal/*`
96
+ - adding a package dependency or workspace reference
97
+ - introducing callbacks, dependency injection, or runtime registration across layers
98
+
99
+ ---
100
+
101
+ ## Tool-Assisted Boundary Checks
102
+
103
+ Tools accelerate discovery, but the rule is portable: if a tool is unavailable,
104
+ fall back to inspecting config, imports, and dependents manually.
105
+
106
+ ### Fallow for TypeScript/JavaScript enforcement
107
+
108
+ If Fallow is available in a TypeScript/JavaScript project, prefer it for boundary
109
+ evidence:
110
+
111
+ ```bash
112
+ npx fallow list --boundaries
113
+ npx fallow dead-code --boundary-violations
114
+ npx fallow dead-code --circular-deps
115
+ ```
116
+
117
+ Useful presets include:
118
+
119
+ ```jsonc
120
+ { "boundaries": { "preset": "layered" } } // presentation → application → domain
121
+ { "boundaries": { "preset": "hexagonal" } } // adapters → ports → domain
122
+ { "boundaries": { "preset": "feature-sliced" } } // app > pages > widgets > features > entities > shared
123
+ { "boundaries": { "preset": "bulletproof" } } // app → features → shared/server
124
+ ```
125
+
126
+ If the project has no Fallow boundary config, do not silently add one during an
127
+ unrelated task. Either infer boundaries for the current change only, or propose a
128
+ separate issue/PR to introduce explicit enforcement.
129
+
130
+ ### GitNexus for graph-backed orientation
131
+
132
+ If GitNexus is available, use it to understand dependency and call-chain impact
133
+ before cross-cutting changes:
134
+
135
+ ```bash
136
+ gitnexus analyze
137
+ gitnexus wiki
138
+ gitnexus serve
139
+ ```
140
+
141
+ Use GitNexus graph/MCP context to answer:
142
+
143
+ - What imports or calls this file/symbol?
144
+ - Which functional cluster or service owns it?
145
+ - Which execution flows are affected?
146
+ - Does the proposed change cross a service/package/feature boundary?
147
+
148
+ GitNexus is best treated as boundary intelligence. Use project rules or a
149
+ checker such as Fallow/lint/CI for enforcement unless the project has explicit
150
+ GitNexus graph queries for boundary violations.
151
+
152
+ ---
153
+
154
+ ## Boundary Design Patterns
155
+
156
+ When a needed dependency would violate the DAG, do not punch through the boundary.
157
+ Use one of these instead:
158
+
159
+ | Problem | Prefer |
160
+ | --- | --- |
161
+ | Domain needs infrastructure behavior | Define a domain/application port; implement it in infrastructure |
162
+ | UI needs data access | Call application/use-case layer; do not import database/client directly |
163
+ | Feature A needs Feature B behavior | Depend on Feature B's public API or move shared behavior to shared/domain |
164
+ | Shared utility needs feature config | Pass config as data; do not import feature code |
165
+ | Lower layer needs upper-layer callback | Invert dependency with an interface, event, or injected function |
166
+ | Cross-package import reaches internals | Export through the package entry point or add an explicit public module |
167
+
168
+ ---
169
+
170
+ ## Boundary Verification Output
171
+
172
+ Before final gates, include a boundary section in the verification summary for
173
+ any Full Path task that touches imports, exports, folders, packages, or shared
174
+ code:
175
+
176
+ ```md
177
+ ### Architecture Boundaries
178
+
179
+ - Modified zones:
180
+ - `src/features/auth/**` → `feature/auth`
181
+ - `src/shared/validation.ts` → `shared`
182
+ - Changed dependency edges:
183
+ - `feature/auth` imports `shared/validation`
184
+ - Checks:
185
+ - [x] No upward imports
186
+ - [x] No sibling feature internal imports
187
+ - [x] No production imports from tests
188
+ - [x] No new circular dependency
189
+ - [x] Boundary tool/lint check passed, or unavailable with reason
190
+ - Tool evidence:
191
+ - `npx fallow dead-code --boundary-violations` → 0 violations
192
+ ```
193
+
194
+ If a violation is found, the implementation is not ready. Either fix the design
195
+ or ask the human before proceeding.
196
+
197
+ ---
198
+
199
+ ## Forbidden Patterns
200
+
201
+ | Pattern | Why Forbidden |
202
+ | --- | --- |
203
+ | "Tests pass, so the import is fine" | Tests do not prove architectural validity |
204
+ | Importing across a forbidden layer to save time | Creates coupling that future changes pay for |
205
+ | Deep-importing another feature's internals | Bypasses the public contract and breaks encapsulation |
206
+ | Adding boundary config as a drive-by change | Boundary policy is cross-cutting and needs explicit review |
207
+ | Ignoring cycles because runtime still works | Cycles degrade build, test, and refactor reliability |
208
+ | Moving code to `shared` without checking dependents | `shared` can become a dumping ground and reverse the DAG |
209
+
210
+ ---
211
+
212
+ ## Quick Reference
213
+
214
+ | Phase | Action | Evidence |
215
+ | --- | --- | --- |
216
+ | ORIENT | Load project rules and classify touched files | Zone + allowed imports |
217
+ | PLAN | Identify changed dependency edges | Edge list |
218
+ | IMPLEMENT | Use ports/public APIs instead of forbidden imports | No illegal import added |
219
+ | SELF-AUDIT | Ask what boundary assumption could collapse | Jenga entry if uncertain |
220
+ | VERIFY | Run boundary checks or document manual proof | Boundary section in PR |
221
+
222
+ _This directive complements type-first development, TDD, and verification: types
223
+ prove shapes, tests prove behavior, and boundary checks prove architectural fit._