code-anchored-context 0.1.0 → 0.1.1
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.
- package/AGENTS.md +2 -0
- package/Development/_templates/initiative/README.md +9 -5
- package/Development/_templates/planned-initiative/README.md +9 -5
- package/Development/code-anchored-context-structure.md +4 -3
- package/Development/giving-ai-agents-context-around-code.md +5 -5
- package/Documentation/Welcome.md +5 -0
- package/Documentation/_authoring/README.md +2 -1
- package/Documentation/_authoring/areas/_template.md +15 -1
- package/Documentation/_authoring/workflow.md +95 -8
- package/Documentation/_templates/area/README.md +38 -0
- package/Documentation/_templates/area/features/feature-template.md +43 -1
- package/Documentation/releases/index.md +2 -0
- package/bin/code-anchored-context.js +94 -12
- package/package.json +1 -1
package/AGENTS.md
CHANGED
|
@@ -27,6 +27,8 @@ Touch `Documentation/` only when:
|
|
|
27
27
|
|
|
28
28
|
- A human explicitly asks you to refresh the docs for a release, typically
|
|
29
29
|
after a release tag is cut and QA has signed off.
|
|
30
|
+
- A human explicitly asks you to create or refresh baseline documentation for
|
|
31
|
+
an existing project.
|
|
30
32
|
- A human explicitly asks you to update a specific page.
|
|
31
33
|
- A human asks you to fix a demonstrable error in an existing page, such as a
|
|
32
34
|
broken link or factual inaccuracy.
|
|
@@ -12,11 +12,15 @@ produce.
|
|
|
12
12
|
|
|
13
13
|
## Touched Areas
|
|
14
14
|
|
|
15
|
-
- `
|
|
16
|
-
- `
|
|
17
|
-
- `
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
- Product or runtime code: `path/to/...`
|
|
16
|
+
- Interfaces, APIs, or contracts: `path/to/...`
|
|
17
|
+
- Tests or verification: `path/to/...`
|
|
18
|
+
- Delivery, CI/CD, build, or artifacts: `path/to/...`
|
|
19
|
+
- Infrastructure, IaC, or environment config: `path/to/...`
|
|
20
|
+
- Documentation or release notes: `path/to/...`
|
|
21
|
+
|
|
22
|
+
Remove entries that do not apply and add the real paths. Prefer naming the
|
|
23
|
+
delivery concern over assuming a specific folder layout.
|
|
20
24
|
|
|
21
25
|
## Current Source Of Truth
|
|
22
26
|
|
|
@@ -14,11 +14,15 @@ and what outcome it should produce.
|
|
|
14
14
|
|
|
15
15
|
## Touched Areas
|
|
16
16
|
|
|
17
|
-
- `
|
|
18
|
-
- `
|
|
19
|
-
- `
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
- Product or runtime code: `path/to/...`
|
|
18
|
+
- Interfaces, APIs, or contracts: `path/to/...`
|
|
19
|
+
- Tests or verification: `path/to/...`
|
|
20
|
+
- Delivery, CI/CD, build, or artifacts: `path/to/...`
|
|
21
|
+
- Infrastructure, IaC, or environment config: `path/to/...`
|
|
22
|
+
- Documentation or release notes: `path/to/...`
|
|
23
|
+
|
|
24
|
+
Remove entries that do not apply and add the real paths. Prefer naming the
|
|
25
|
+
delivery concern over assuming a specific folder layout.
|
|
22
26
|
|
|
23
27
|
## Current Source Of Truth
|
|
24
28
|
|
|
@@ -6,9 +6,10 @@ context is laid out so both humans and agents can navigate it.
|
|
|
6
6
|
|
|
7
7
|
## Denormalize Navigation, Not Knowledge
|
|
8
8
|
|
|
9
|
-
Agents and IDEs do not always open from the repo root
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
Agents and IDEs do not always open from the repo root. They may start in
|
|
10
|
+
product code, CI/CD config, infrastructure code, generated artifacts, or a
|
|
11
|
+
nested app. If all guidance lives at the top, it gets missed. If each area
|
|
12
|
+
keeps its own plans, cross-project work fragments.
|
|
12
13
|
|
|
13
14
|
> Denormalize navigation, not knowledge.
|
|
14
15
|
|
|
@@ -74,8 +74,8 @@ flowchart LR
|
|
|
74
74
|
## The Navigation Problem
|
|
75
75
|
|
|
76
76
|
In large repositories, agents and IDEs do not always open the workspace from
|
|
77
|
-
the root. They may start in
|
|
78
|
-
nested project folder.
|
|
77
|
+
the root. They may start in product code, CI/CD config, infrastructure code,
|
|
78
|
+
generated artifacts, a specific application, or a nested project folder.
|
|
79
79
|
|
|
80
80
|
If all guidance lives at the top, it may be missed. But if each area keeps its
|
|
81
81
|
own plans, cross-project work becomes fragmented.
|
|
@@ -91,9 +91,9 @@ infrastructure context should live centrally under `Development/`.
|
|
|
91
91
|
```mermaid
|
|
92
92
|
flowchart TD
|
|
93
93
|
Root["Repository root"]
|
|
94
|
-
AreaA["
|
|
95
|
-
AreaB["
|
|
96
|
-
AreaC["
|
|
94
|
+
AreaA["product area AGENTS.md<br/>local signpost"]
|
|
95
|
+
AreaB["delivery area AGENTS.md<br/>local signpost"]
|
|
96
|
+
AreaC["nested project AGENTS.md<br/>local signpost"]
|
|
97
97
|
Dev["Development/<br/>central working context"]
|
|
98
98
|
Initiative["Release initiative<br/>single delivery story"]
|
|
99
99
|
|
package/Documentation/Welcome.md
CHANGED
|
@@ -35,8 +35,13 @@ Every documented area should have:
|
|
|
35
35
|
## Contributing
|
|
36
36
|
|
|
37
37
|
- Refresh docs only when explicitly asked.
|
|
38
|
+
- For existing projects with no docs, create baseline documentation only when
|
|
39
|
+
explicitly asked; otherwise document touched behavior during future release
|
|
40
|
+
refreshes.
|
|
38
41
|
- Write for non-developer technical readers unless the project states
|
|
39
42
|
otherwise.
|
|
43
|
+
- Write from behavior outward: product-readable first, technically anchored
|
|
44
|
+
where details affect shipped behavior, operations, or support.
|
|
40
45
|
- Describe behavior, inputs, outputs, permissions, errors, business rules, and
|
|
41
46
|
operational expectations in domain language.
|
|
42
47
|
- Prefer Mermaid diagrams for flows, architecture, and relationships.
|
|
@@ -23,7 +23,8 @@ Documentation/_authoring/areas/<area-slug>.md
|
|
|
23
23
|
|
|
24
24
|
Each area guide should identify:
|
|
25
25
|
|
|
26
|
-
- the
|
|
26
|
+
- the source locations that own the behavior, such as product code,
|
|
27
|
+
interfaces, tests, CI/CD, generated artifacts, infrastructure, or config
|
|
27
28
|
- the documentation root under `Documentation/`
|
|
28
29
|
- feature pages that should exist
|
|
29
30
|
- behavior that matters at release time
|
|
@@ -2,12 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
## Scope
|
|
4
4
|
|
|
5
|
-
-
|
|
5
|
+
- Source orientation: `path/to/runtime-or-product-code`, `path/to/contracts`,
|
|
6
|
+
`path/to/tests`, `path/to/ci-or-delivery`, `path/to/infra-or-config`
|
|
6
7
|
- Documentation root: `Documentation/<Area>/`
|
|
7
8
|
- Owner or reviewer: TBD
|
|
8
9
|
|
|
9
10
|
Describe what this area owns and what it intentionally does not own.
|
|
10
11
|
|
|
12
|
+
## Audience And Depth
|
|
13
|
+
|
|
14
|
+
State any area-specific audience or depth rules. By default, write for
|
|
15
|
+
Product Owners, QA, support, operators, customer engineers, and technical
|
|
16
|
+
readers who need behavior, rules, data effects, permissions, errors, and
|
|
17
|
+
operational expectations without private implementation detail.
|
|
18
|
+
|
|
11
19
|
## Feature Inventory
|
|
12
20
|
|
|
13
21
|
| Feature | Documentation page | Notes |
|
|
@@ -41,6 +49,12 @@ Ignore changes that do not alter released behavior:
|
|
|
41
49
|
List the files, folders, entry points, or search terms that help an agent map a
|
|
42
50
|
release diff to documentation pages.
|
|
43
51
|
|
|
52
|
+
## Baseline Discovery Notes
|
|
53
|
+
|
|
54
|
+
Use this section when creating first-pass documentation for an existing
|
|
55
|
+
project. List stable workflows, important entry points, source references,
|
|
56
|
+
known gaps, and questions that should not yet appear in product-facing docs.
|
|
57
|
+
|
|
44
58
|
## Terminology
|
|
45
59
|
|
|
46
60
|
List area-specific terms or link to `Documentation/_authoring/terminology.md`.
|
|
@@ -11,6 +11,9 @@ work. Humans or agents touch `Documentation/` only when:
|
|
|
11
11
|
|
|
12
12
|
- A human explicitly asks for a release-time refresh, typically after the
|
|
13
13
|
release tag is cut and QA has signed off.
|
|
14
|
+
- A human explicitly asks for baseline documentation for an existing project,
|
|
15
|
+
such as "document this repo baseline" or "create initial docs for the current
|
|
16
|
+
system."
|
|
14
17
|
- A human explicitly asks to update a specific page.
|
|
15
18
|
- A human asks to fix a demonstrable error in an existing page, such as a
|
|
16
19
|
broken link or factual inaccuracy.
|
|
@@ -24,15 +27,56 @@ outdated, leave it alone. Flag the staleness in your summary or add it to the
|
|
|
24
27
|
initiative's `release-doc-notes.md`, but do not edit the doc as part of the
|
|
25
28
|
current change unless explicitly asked.
|
|
26
29
|
|
|
30
|
+
## Documentation Modes
|
|
31
|
+
|
|
32
|
+
There are two valid ways to introduce or maintain `Documentation/`.
|
|
33
|
+
|
|
34
|
+
### Baseline Documentation
|
|
35
|
+
|
|
36
|
+
Use this mode only when a human explicitly asks to document the current system
|
|
37
|
+
as a starting point. This is common when adopting the template in an existing
|
|
38
|
+
project that has little or no product documentation.
|
|
39
|
+
|
|
40
|
+
When creating a baseline:
|
|
41
|
+
|
|
42
|
+
1. Confirm the scope: whole repo, one product area, one feature family, or one
|
|
43
|
+
operational surface.
|
|
44
|
+
2. Create or update the matching area guide under
|
|
45
|
+
`Documentation/_authoring/areas/` before writing product-facing pages.
|
|
46
|
+
3. Document stable, currently accepted behavior from the current branch,
|
|
47
|
+
current tag, or explicit reference point named by the human.
|
|
48
|
+
4. Prefer broad, accurate coverage over exhaustive implementation detail.
|
|
49
|
+
5. Record the baseline reference in `Documentation/releases/index.md`. If
|
|
50
|
+
there is no release tag yet, use the commit, branch, date, or human-named
|
|
51
|
+
baseline label that was used as the source.
|
|
52
|
+
6. Leave uncertain or future behavior out of `Documentation/`. Capture open
|
|
53
|
+
questions in `Development/` or in the area authoring guide.
|
|
54
|
+
|
|
55
|
+
Baseline docs are a snapshot of the system as adopted; they are not a promise
|
|
56
|
+
that every undocumented behavior is unimportant.
|
|
57
|
+
|
|
58
|
+
### Release-Forward Documentation
|
|
59
|
+
|
|
60
|
+
Use this mode when the team chooses not to create a full baseline. In this
|
|
61
|
+
mode, `Documentation/` may start sparse. Agents capture documentation impact
|
|
62
|
+
in initiative `release-doc-notes.md` during development, then update product
|
|
63
|
+
docs only at explicit release-refresh time.
|
|
64
|
+
|
|
65
|
+
This is valid when a full baseline would be too expensive. The documentation
|
|
66
|
+
becomes complete incrementally around behavior the team changes and releases.
|
|
67
|
+
|
|
27
68
|
## Cadence And Versioning
|
|
28
69
|
|
|
29
|
-
Docs live under `Documentation
|
|
30
|
-
git-tag time, after release acceptance.
|
|
31
|
-
the docs at tag `release/v1_2_3`
|
|
70
|
+
Docs live under `Documentation/`. After any explicit baseline pass, they are
|
|
71
|
+
refreshed once per release, at git-tag time, after release acceptance. Release
|
|
72
|
+
docs are anchored to the release tag; the docs at tag `release/v1_2_3`
|
|
73
|
+
describe the behavior of that release.
|
|
32
74
|
|
|
33
75
|
Default tag names follow the convention `release/vMAJOR_MINOR_PATCH` and match
|
|
34
76
|
the release branch name. If a project uses a different release convention,
|
|
35
|
-
document it here before the first refresh.
|
|
77
|
+
document it here before the first refresh. If the first documentation pass is
|
|
78
|
+
a baseline without a tag, record the baseline reference in
|
|
79
|
+
`Documentation/releases/index.md`.
|
|
36
80
|
|
|
37
81
|
## Audience
|
|
38
82
|
|
|
@@ -47,6 +91,31 @@ Adjust this only when the project explicitly defines a different audience.
|
|
|
47
91
|
- For readers who need more depth than the docs provide, link to the source
|
|
48
92
|
rather than replicating the implementation in prose.
|
|
49
93
|
|
|
94
|
+
## Writing Focus
|
|
95
|
+
|
|
96
|
+
Write from behavior outward.
|
|
97
|
+
|
|
98
|
+
Start with what a user, Product Owner, operator, API consumer, support person,
|
|
99
|
+
or business process can observe. Add technical detail only when it affects
|
|
100
|
+
released behavior, configuration, permissions, data, integrations, errors,
|
|
101
|
+
support, operations, or auditability.
|
|
102
|
+
|
|
103
|
+
Documentation should be product-readable first and technically anchored
|
|
104
|
+
second. It can feed release notes, but it is more durable than release notes:
|
|
105
|
+
release notes summarize what changed, while `Documentation/` describes what
|
|
106
|
+
the accepted system does as of a release or baseline.
|
|
107
|
+
|
|
108
|
+
Use progressive depth:
|
|
109
|
+
|
|
110
|
+
1. Summary and purpose in product or domain language.
|
|
111
|
+
2. Workflows, roles, permissions, and business rules.
|
|
112
|
+
3. Inputs, outputs, data effects, integrations, errors, and edge cases.
|
|
113
|
+
4. Operational expectations, configuration, and dependencies when relevant.
|
|
114
|
+
5. Source references for verification, not as a substitute for explanation.
|
|
115
|
+
|
|
116
|
+
Do not document private implementation structure unless it is needed to
|
|
117
|
+
explain released behavior or support a reader's operational task.
|
|
118
|
+
|
|
50
119
|
## Two Levels Of Detail
|
|
51
120
|
|
|
52
121
|
Every documented area has two layers:
|
|
@@ -105,11 +174,29 @@ When invoked to refresh docs for a release:
|
|
|
105
174
|
1. Work from the diff `<previous-release-tag>..HEAD`, scoped to one area at a
|
|
106
175
|
time.
|
|
107
176
|
2. Read the matching area guide in `Documentation/_authoring/areas/`.
|
|
108
|
-
3.
|
|
109
|
-
|
|
110
|
-
|
|
177
|
+
3. Read relevant initiative `release-doc-notes.md` files under
|
|
178
|
+
`Development/releases/<release>/initiatives/`.
|
|
179
|
+
4. Update the area's `README.md` if the high-level picture changed.
|
|
180
|
+
5. Update feature pages for behavior that changed.
|
|
181
|
+
6. Ignore pure refactors, internal renames, test-only changes, formatting,
|
|
111
182
|
lint fixes, and dependency bumps with no behavior change.
|
|
112
|
-
|
|
183
|
+
7. Append one row to `Documentation/releases/index.md`.
|
|
184
|
+
|
|
185
|
+
## Source Order
|
|
186
|
+
|
|
187
|
+
For release refreshes, start from release-owned context before falling back to
|
|
188
|
+
source inspection:
|
|
189
|
+
|
|
190
|
+
1. Previous release tag to current release diff.
|
|
191
|
+
2. Relevant initiative `release-doc-notes.md` files.
|
|
192
|
+
3. Matching area guide under `Documentation/_authoring/areas/`.
|
|
193
|
+
4. Existing product documentation.
|
|
194
|
+
5. Source code, tests, config, CI/CD, infrastructure, and generated artifacts
|
|
195
|
+
only as needed to verify shipped behavior.
|
|
196
|
+
|
|
197
|
+
For baseline documentation, start from the explicit baseline scope and
|
|
198
|
+
reference point named by the human. If no reference is named, use the current
|
|
199
|
+
working tree and say so in the release index row.
|
|
113
200
|
|
|
114
201
|
## What Not To Document
|
|
115
202
|
|
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
Briefly describe what this area does, who uses it, and why it exists.
|
|
4
4
|
|
|
5
|
+
## Reader Summary
|
|
6
|
+
|
|
7
|
+
Explain the area in product or domain language. A Product Owner should be able
|
|
8
|
+
to understand the purpose, scope, and user or business value from this section.
|
|
9
|
+
|
|
10
|
+
## Primary Workflows
|
|
11
|
+
|
|
12
|
+
- TBD
|
|
13
|
+
|
|
5
14
|
## Architecture At A Glance
|
|
6
15
|
|
|
7
16
|
```mermaid
|
|
@@ -15,6 +24,35 @@ flowchart LR
|
|
|
15
24
|
|
|
16
25
|
- TBD
|
|
17
26
|
|
|
27
|
+
## Data And State
|
|
28
|
+
|
|
29
|
+
Describe the important records, files, queues, external state, or generated
|
|
30
|
+
artifacts this area creates, reads, or changes.
|
|
31
|
+
|
|
32
|
+
- TBD
|
|
33
|
+
|
|
34
|
+
## Configuration And Dependencies
|
|
35
|
+
|
|
36
|
+
List configuration, environment assumptions, external systems, scheduled jobs,
|
|
37
|
+
or infrastructure this area depends on.
|
|
38
|
+
|
|
39
|
+
- TBD
|
|
40
|
+
|
|
41
|
+
## Operational Expectations
|
|
42
|
+
|
|
43
|
+
Describe support, observability, recovery, audit, or routine operational
|
|
44
|
+
expectations that matter to readers.
|
|
45
|
+
|
|
46
|
+
- TBD
|
|
47
|
+
|
|
48
|
+
## Source References
|
|
49
|
+
|
|
50
|
+
Optional links to source files, generated references, dashboards, runbooks, or
|
|
51
|
+
release context that help technical readers verify behavior. Keep explanation
|
|
52
|
+
in this page instead of replacing it with links.
|
|
53
|
+
|
|
54
|
+
- TBD
|
|
55
|
+
|
|
18
56
|
## Feature Pages
|
|
19
57
|
|
|
20
58
|
- [Feature Name](features/feature-template.md)
|
|
@@ -1,25 +1,59 @@
|
|
|
1
1
|
# Feature Name
|
|
2
2
|
|
|
3
|
-
Describe the shipped behavior in domain language.
|
|
3
|
+
Describe the shipped behavior in product or domain language. Start with what a
|
|
4
|
+
Product Owner, QA reader, support person, operator, or API consumer can
|
|
5
|
+
observe.
|
|
6
|
+
|
|
7
|
+
## Reader Summary
|
|
8
|
+
|
|
9
|
+
Explain what the feature does, why it matters, and the outcome it provides.
|
|
4
10
|
|
|
5
11
|
## Who Uses It
|
|
6
12
|
|
|
7
13
|
- TBD
|
|
8
14
|
|
|
15
|
+
## Entry Points
|
|
16
|
+
|
|
17
|
+
Describe where the feature is triggered: UI, API, CLI, scheduled job,
|
|
18
|
+
integration, import/export, or operator workflow.
|
|
19
|
+
|
|
20
|
+
- TBD
|
|
21
|
+
|
|
9
22
|
## Behavior
|
|
10
23
|
|
|
11
24
|
- TBD
|
|
12
25
|
|
|
26
|
+
## Business Rules
|
|
27
|
+
|
|
28
|
+
Describe rules, limits, lifecycle states, timing, or decision logic in
|
|
29
|
+
reader-facing language.
|
|
30
|
+
|
|
31
|
+
- TBD
|
|
32
|
+
|
|
13
33
|
## Inputs And Outputs
|
|
14
34
|
|
|
15
35
|
| Input or output | Description |
|
|
16
36
|
| --- | --- |
|
|
17
37
|
| TBD | TBD |
|
|
18
38
|
|
|
39
|
+
## Data And State Changes
|
|
40
|
+
|
|
41
|
+
Describe important records, files, generated artifacts, messages, or external
|
|
42
|
+
state this feature creates, reads, updates, deletes, or retains.
|
|
43
|
+
|
|
44
|
+
- TBD
|
|
45
|
+
|
|
19
46
|
## Permissions And Validation
|
|
20
47
|
|
|
21
48
|
- TBD
|
|
22
49
|
|
|
50
|
+
## Configuration And Dependencies
|
|
51
|
+
|
|
52
|
+
List flags, settings, environment requirements, external systems, or
|
|
53
|
+
infrastructure dependencies that affect this feature.
|
|
54
|
+
|
|
55
|
+
- TBD
|
|
56
|
+
|
|
23
57
|
## Errors And Edge Cases
|
|
24
58
|
|
|
25
59
|
- TBD
|
|
@@ -27,3 +61,11 @@ Describe the shipped behavior in domain language.
|
|
|
27
61
|
## Operational Notes
|
|
28
62
|
|
|
29
63
|
- TBD
|
|
64
|
+
|
|
65
|
+
## Source References
|
|
66
|
+
|
|
67
|
+
Optional links to source files, generated references, runbooks, dashboards, or
|
|
68
|
+
release context that help technical readers verify behavior. Do not use this
|
|
69
|
+
section for private implementation detail that has no reader-visible impact.
|
|
70
|
+
|
|
71
|
+
- TBD
|
|
@@ -11,6 +11,8 @@ Docs at a given tag describe the behavior of that release.
|
|
|
11
11
|
|
|
12
12
|
## Notes For Future Release Rows
|
|
13
13
|
|
|
14
|
+
- For an explicit baseline documentation pass, the tag may be a commit,
|
|
15
|
+
branch, date, or human-named baseline label when no release tag exists yet.
|
|
14
16
|
- The first row may be a bootstrap refresh. Subsequent rows should describe
|
|
15
17
|
incremental refreshes from `<previous-tag>..HEAD`.
|
|
16
18
|
- "Areas refreshed" lists only areas with material behavior changes.
|
|
@@ -212,6 +212,7 @@ class Installer {
|
|
|
212
212
|
this.force = force;
|
|
213
213
|
this.dryRun = dryRun;
|
|
214
214
|
this.actions = [];
|
|
215
|
+
this.agentsFilePath = path.join(targetRoot, 'AGENTS.md');
|
|
215
216
|
}
|
|
216
217
|
|
|
217
218
|
async init({ includeDocumentation }) {
|
|
@@ -232,10 +233,13 @@ class Installer {
|
|
|
232
233
|
}
|
|
233
234
|
|
|
234
235
|
async installAgentsFile() {
|
|
235
|
-
const targetFile =
|
|
236
|
+
const targetFile = await this.findAgentsFile();
|
|
237
|
+
const targetDisplay = path.basename(targetFile);
|
|
238
|
+
this.agentsFilePath = targetFile;
|
|
236
239
|
|
|
237
240
|
if (!await exists(targetFile)) {
|
|
238
241
|
await this.copyTemplatePath('AGENTS.md', 'AGENTS.md');
|
|
242
|
+
this.agentsFilePath = path.join(this.targetRoot, 'AGENTS.md');
|
|
239
243
|
return;
|
|
240
244
|
}
|
|
241
245
|
|
|
@@ -249,16 +253,16 @@ class Installer {
|
|
|
249
253
|
);
|
|
250
254
|
|
|
251
255
|
if (updated === current) {
|
|
252
|
-
this.note(
|
|
256
|
+
this.note(`${targetDisplay} already has Code-Anchored Context guidance`);
|
|
253
257
|
return;
|
|
254
258
|
}
|
|
255
259
|
|
|
256
|
-
await this.writeFile(targetFile, updated,
|
|
260
|
+
await this.writeFile(targetFile, updated, `update ${targetDisplay} Code-Anchored Context section`);
|
|
257
261
|
return;
|
|
258
262
|
}
|
|
259
263
|
|
|
260
264
|
if (current.includes('.agents/skills/development-initiative-context/SKILL.md')) {
|
|
261
|
-
this.note(
|
|
265
|
+
this.note(`${targetDisplay} already points to the development initiative skill`);
|
|
262
266
|
return;
|
|
263
267
|
}
|
|
264
268
|
|
|
@@ -266,10 +270,33 @@ class Installer {
|
|
|
266
270
|
await this.writeFile(
|
|
267
271
|
targetFile,
|
|
268
272
|
`${current}${separator}${section}\n`,
|
|
269
|
-
|
|
273
|
+
`append Code-Anchored Context guidance to ${targetDisplay}`
|
|
270
274
|
);
|
|
271
275
|
}
|
|
272
276
|
|
|
277
|
+
async findAgentsFile() {
|
|
278
|
+
const canonicalPath = path.join(this.targetRoot, 'AGENTS.md');
|
|
279
|
+
|
|
280
|
+
let entries;
|
|
281
|
+
|
|
282
|
+
try {
|
|
283
|
+
entries = await readdir(this.targetRoot, { withFileTypes: true });
|
|
284
|
+
} catch {
|
|
285
|
+
return canonicalPath;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
if (entries.some((entry) => entry.isFile() && entry.name === 'AGENTS.md')) {
|
|
289
|
+
return canonicalPath;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
const match = entries
|
|
293
|
+
.filter((entry) => entry.isFile() && entry.name.toLowerCase() === 'agents.md')
|
|
294
|
+
.map((entry) => entry.name)
|
|
295
|
+
.sort((left, right) => left.localeCompare(right))[0];
|
|
296
|
+
|
|
297
|
+
return match ? path.join(this.targetRoot, match) : canonicalPath;
|
|
298
|
+
}
|
|
299
|
+
|
|
273
300
|
renderAgentSection() {
|
|
274
301
|
return `${agentSectionStart}
|
|
275
302
|
## Code-Anchored Context
|
|
@@ -291,7 +318,13 @@ ${agentSectionEnd}`;
|
|
|
291
318
|
`.agents/skills/${skillName}`
|
|
292
319
|
);
|
|
293
320
|
|
|
294
|
-
const
|
|
321
|
+
const readmeTarget = await this.findExistingTargetPath('.agents/skills/README.md');
|
|
322
|
+
const readmePath = readmeTarget.exists
|
|
323
|
+
? readmeTarget.path
|
|
324
|
+
: path.join(this.targetRoot, '.agents/skills/README.md');
|
|
325
|
+
const readmeDisplay = readmeTarget.exists
|
|
326
|
+
? readmeTarget.display
|
|
327
|
+
: '.agents/skills/README.md';
|
|
295
328
|
|
|
296
329
|
if (!await exists(readmePath)) {
|
|
297
330
|
await this.copyTemplatePath('.agents/skills/README.md', '.agents/skills/README.md');
|
|
@@ -301,7 +334,7 @@ ${agentSectionEnd}`;
|
|
|
301
334
|
const current = await readFile(readmePath, 'utf8');
|
|
302
335
|
|
|
303
336
|
if (current.includes(skillName)) {
|
|
304
|
-
this.note(
|
|
337
|
+
this.note(`${readmeDisplay} already lists the development initiative skill`);
|
|
305
338
|
return;
|
|
306
339
|
}
|
|
307
340
|
|
|
@@ -316,26 +349,75 @@ ${agentSectionEnd}`;
|
|
|
316
349
|
await this.writeFile(
|
|
317
350
|
readmePath,
|
|
318
351
|
`${current.trimEnd()}\n${entry}`,
|
|
319
|
-
|
|
352
|
+
`append development initiative skill to ${readmeDisplay}`
|
|
320
353
|
);
|
|
321
354
|
}
|
|
322
355
|
|
|
323
356
|
async copyTemplatePath(sourceRelative, targetRelative) {
|
|
324
357
|
const sourcePath = path.join(packageRoot, sourceRelative);
|
|
358
|
+
const targetInfo = await this.findExistingTargetPath(targetRelative);
|
|
325
359
|
const targetPath = path.join(this.targetRoot, targetRelative);
|
|
326
360
|
|
|
327
|
-
if (
|
|
361
|
+
if (targetInfo.exists) {
|
|
362
|
+
const variantNote = targetInfo.caseVariant ? ` at ${targetInfo.display}` : '';
|
|
363
|
+
|
|
328
364
|
if (!this.force) {
|
|
329
|
-
this.note(`skip ${targetRelative} (already exists; use --force to replace)`);
|
|
365
|
+
this.note(`skip ${targetRelative} (already exists${variantNote}; use --force to replace)`);
|
|
330
366
|
return;
|
|
331
367
|
}
|
|
332
368
|
|
|
333
|
-
await this.removePath(
|
|
369
|
+
await this.removePath(targetInfo.path, `replace ${targetInfo.display}`);
|
|
334
370
|
}
|
|
335
371
|
|
|
336
372
|
await this.copyRecursive(sourcePath, targetPath, targetRelative);
|
|
337
373
|
}
|
|
338
374
|
|
|
375
|
+
async findExistingTargetPath(targetRelative) {
|
|
376
|
+
const parts = targetRelative.split('/').filter(Boolean);
|
|
377
|
+
let currentPath = this.targetRoot;
|
|
378
|
+
const displayParts = [];
|
|
379
|
+
|
|
380
|
+
for (const part of parts) {
|
|
381
|
+
let entries;
|
|
382
|
+
|
|
383
|
+
try {
|
|
384
|
+
entries = await readdir(currentPath, { withFileTypes: true });
|
|
385
|
+
} catch {
|
|
386
|
+
return this.missingTargetPath(targetRelative);
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
const exactMatch = entries.find((entry) => entry.name === part);
|
|
390
|
+
const caseMatch = exactMatch ?? entries.find(
|
|
391
|
+
(entry) => entry.name.toLowerCase() === part.toLowerCase()
|
|
392
|
+
);
|
|
393
|
+
|
|
394
|
+
if (!caseMatch) {
|
|
395
|
+
return this.missingTargetPath(targetRelative);
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
currentPath = path.join(currentPath, caseMatch.name);
|
|
399
|
+
displayParts.push(caseMatch.name);
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
const display = displayParts.join('/');
|
|
403
|
+
|
|
404
|
+
return {
|
|
405
|
+
caseVariant: display !== targetRelative,
|
|
406
|
+
display,
|
|
407
|
+
exists: true,
|
|
408
|
+
path: currentPath
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
missingTargetPath(targetRelative) {
|
|
413
|
+
return {
|
|
414
|
+
caseVariant: false,
|
|
415
|
+
display: targetRelative,
|
|
416
|
+
exists: false,
|
|
417
|
+
path: path.join(this.targetRoot, targetRelative)
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
|
|
339
421
|
async copyRecursive(sourcePath, targetPath, displayPath) {
|
|
340
422
|
if (this.shouldSkipTemplatePath(displayPath)) {
|
|
341
423
|
this.note(`skip ${displayPath} (template repository context)`);
|
|
@@ -533,7 +615,7 @@ No initiatives registered yet.
|
|
|
533
615
|
console.log(`${prefix}Code-Anchored Context ready for ${this.projectName}.`);
|
|
534
616
|
|
|
535
617
|
if (!this.dryRun) {
|
|
536
|
-
console.log(`Next: ask your agent to read ${
|
|
618
|
+
console.log(`Next: ask your agent to read ${this.agentsFilePath}.`);
|
|
537
619
|
}
|
|
538
620
|
}
|
|
539
621
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "code-anchored-context",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Install repo-local agent context, development initiatives, and release-anchored documentation scaffolding into an existing project.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|