docbridge 0.7.0 → 0.8.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.
@@ -13,6 +13,8 @@ Use the narrowest command for the question you need to answer.
13
13
  The first argument selects a command. Global `--help` and `--version` are
14
14
  handled before project scanning, while each command validates its own options.
15
15
 
16
+ <!-- @code src/core/resolver.ts#check -->
17
+
16
18
  ### `check`: validate the project
17
19
 
18
20
  Run `docbridge check` before committing and in CI. It validates configuration,
@@ -20,6 +22,8 @@ annotations, targets, and reciprocal links. Add `--audit` to include warnings
20
22
  for undocumented code declarations and unlinked Markdown sections. Add
21
23
  `--json` for machine-readable diagnostics.
22
24
 
25
+ <!-- @code src/core/related.ts#related -->
26
+
23
27
  ### `related`: find counterpart files
24
28
 
25
29
  Pass changed paths to learn which linked files may also need attention:
@@ -32,6 +36,8 @@ git diff --name-only | docbridge related --stdin
32
36
  set. It identifies review obligations; it does not decide whether the
33
37
  counterpart actually needs an edit.
34
38
 
39
+ <!-- @code src/core/context.ts#context -->
40
+
35
41
  ### `context`: read counterpart content
36
42
 
37
43
  Use `context` when a human or agent needs the linked sections themselves:
@@ -43,6 +49,8 @@ docbridge context src/auth.ts
43
49
  The default Markdown output is suitable for an agent prompt. `--json` returns
44
50
  structured contexts, diagnostics, and a summary.
45
51
 
52
+ <!-- @code src/core/graph-output.ts#graph -->
53
+
46
54
  ### `graph`: inspect link structure
47
55
 
48
56
  Use `graph` for endpoints, edges, reciprocal pairs, and unresolved links across
@@ -36,6 +36,15 @@ Declare documentation patterns and at least one supported code language:
36
36
  Supported language keys are `typescript`, `swift`, `dart`, and `rust`. A project can
37
37
  enable more than one language, each with its own patterns.
38
38
 
39
+ Each language accepts an optional `visibility` array. Omitting it uses the
40
+ scanner default: TypeScript `public` and `protected` members, Swift `public`
41
+ and `open`, Dart `public` only, Rust unrestricted `pub`. A declaration
42
+ excluded by visibility is not an endpoint; an `@doc` on one is
43
+ `unsupported_declaration`. See `docbridge docs show annotations` for the
44
+ per-language rules, including Dart's leading-underscore privacy.
45
+
46
+ <!-- @code src/core/glob.ts#collectFiles -->
47
+
39
48
  ## Excluded files
40
49
 
41
50
  The configuration has no `exclude` property. Narrow the include patterns when
@@ -30,7 +30,7 @@ npx docbridge init --dry-run
30
30
 
31
31
  Then run `npx docbridge init` interactively, or use `--yes` when the detected
32
32
  scope is unambiguous. The command can create `docbridge.config.json` and install
33
- the distributable DocBridge skills for Codex, Claude Code, or both. It never
33
+ the distributable `docbridge` skill for Codex, Claude Code, or both. It never
34
34
  overwrites an existing configuration.
35
35
 
36
36
  If a coding agent should choose the documentation and code scope, use:
@@ -67,5 +67,9 @@ A clean graph exits `0`. Broken links and invalid configuration exit `1`.
67
67
 
68
68
  - Read `docbridge docs show configuration` before narrowing scan scope.
69
69
  - Read `docbridge docs show annotations` for link target rules.
70
+ - Read `docbridge docs show linking-workflow` to choose sections and propose
71
+ candidates.
72
+ - Read `docbridge docs show link-review` to audit existing links for meaning.
70
73
  - Read `docbridge docs show commands` to choose an inspection command.
74
+ - Read `docbridge docs show troubleshooting` when `check` reports a diagnostic.
71
75
  - Add `docbridge check` to CI after the local graph passes.
@@ -0,0 +1,53 @@
1
+ ---
2
+ description: Audit existing links for semantic correctness, not just resolution.
3
+ ---
4
+
5
+ # Link Review
6
+
7
+ Audit the semantic validity of the entire DocBridge graph. This is not a
8
+ change-set or pull-request review, and it is not `related --gate` triage. It
9
+ checks whether valid links actually connect a docs section to the code symbol
10
+ that implements or represents that specification.
11
+
12
+ `docbridge check` proves link mechanics. This review judges meaning. Do not
13
+ rubber-stamp a link because the target resolves.
14
+
15
+ ## Procedure
16
+
17
+ 1. Build the graph:
18
+
19
+ ```sh
20
+ docbridge graph --json --include-content
21
+ ```
22
+
23
+ Read `diagnostics` first. Mechanical failures from `docbridge check`
24
+ should be fixed or acknowledged before relying on semantic findings.
25
+
26
+ 2. Batch by docs file. Review all links, but process them in batches:
27
+ - the docs file is the default batch boundary
28
+ - split a batch further when it contains too many sections or links
29
+ - keep notes so repeated patterns are applied consistently across batches
30
+
31
+ 3. Read both sides.
32
+ - For docs nodes, use the graph range to read the full Markdown section.
33
+ - For code nodes, start with graph content: documentation comment plus
34
+ signature. Read the implementation only when necessary to judge the
35
+ relationship.
36
+ - Compare behavior, contract, input/output, constraints, and design
37
+ intent.
38
+
39
+ 4. Classify findings.
40
+ - High: clearly wrong link, stale docs fixed in place by a link, or a
41
+ link to a section that is not a specification.
42
+ - Medium: partial overlap, unclear representative symbol, overly broad
43
+ section, or multiple linked symbols with ambiguous roles.
44
+ - Low: cleanup opportunity, duplicate docs, excessive links, or missing
45
+ explanation of why multiple links are needed.
46
+
47
+ 5. Report findings. For each finding include severity, the doc endpoint, the
48
+ code endpoint, evidence from both sides, and a recommended fix.
49
+
50
+ Do not edit annotations automatically. Prefer fewer, clearer links over
51
+ broad many-to-many links without explicit roles. Do not delete annotations
52
+ merely to silence uncertainty; explain the uncertainty and ask for a
53
+ decision.
@@ -0,0 +1,70 @@
1
+ ---
2
+ description: Choose what to link and propose candidates docs-first.
3
+ ---
4
+
5
+ # Linking Workflow
6
+
7
+ Choose Markdown sections that look like specifications, then propose supported
8
+ code declarations that implement or represent each section. Add annotations
9
+ only after a section-level decision.
10
+
11
+ ## What to link
12
+
13
+ Prefer sections that state behavior, contracts, inputs/outputs, constraints,
14
+ user-visible behavior, or design decisions.
15
+
16
+ Treat README files, changelogs, contribution docs, runbooks, logs, and
17
+ release notes as exclusions by default unless a specific section is identified
18
+ as a specification.
19
+
20
+ Prefer supported public API declarations as link targets. TypeScript starts
21
+ with top-level exported declarations; Swift, Dart, and Rust also support
22
+ member endpoints. Use the scanner-produced canonical ID exactly; see
23
+ `docbridge docs show annotations`.
24
+
25
+ Do not decide project workflow policy such as branch or pull-request
26
+ strategy.
27
+
28
+ ## Propose candidates
29
+
30
+ 1. Confirm docs scope first. Inspect the repository and agree the
31
+ documentation directories before proposing links.
32
+ 2. Find section candidates. Prioritize unlinked sections. Include already
33
+ linked sections at lower priority when an additional link may be justified.
34
+ Ignore prose-only sections, changelog entries, runbook steps, and project
35
+ process unless they are specifications.
36
+ 3. For each candidate section, propose at most three code symbols. Rank them
37
+ from heading text and section body, exported symbol names, existing
38
+ documentation comments, file paths, and the implementation body only when
39
+ that surrounding information is insufficient. For each symbol, state why it
40
+ may match and what remains uncertain.
41
+ 4. Present 5–10 section candidates per round. For each section, choose:
42
+ - adopt: select one or more code symbols to link
43
+ - exclude: do not link this section
44
+ - hold: keep undecided for later
45
+
46
+ A symbol that is not in the proposed top three may still be named.
47
+
48
+ 5. Classify no-match sections instead of forcing a link:
49
+ - not implemented yet
50
+ - spans multiple symbols without a clear public representative
51
+ - likely stale docs
52
+ - not a specification section
53
+ - target appears internal or not exported
54
+
55
+ ## After confirmation
56
+
57
+ Add `@code` directly above the Markdown heading and `@doc` on the chosen
58
+ declaration. If the declaration has no documentation comment, create a
59
+ minimal one containing only `@doc`. If one side already exists, show it and
60
+ add the missing backlink after confirmation. Preserve existing annotations;
61
+ do not replace or clean up suspicious links in this pass.
62
+
63
+ Do not split Markdown sections or rename headings. If a section is too broad
64
+ or ambiguous, classify it as held or no-match. Multiple code symbols may link
65
+ to one docs section when each role is clear. One code symbol may link to
66
+ multiple docs sections when each section covers a distinct specification
67
+ aspect. Do not link solely because names are similar.
68
+
69
+ Verify with `docbridge check`, then inspect the affected links with
70
+ `docbridge context` or `docbridge graph --json --include-content`.
@@ -14,31 +14,39 @@ stderr. Use `docbridge <command> --help` for invocation errors and
14
14
  does not match the schema. Run `docbridge init --dry-run` when the file is
15
15
  missing. When it exists, repair or remove it before running `check` again.
16
16
 
17
- Confirm that include patterns match real files relative to the selected
18
- `--root`, language keys are supported, and excludes do not remove an intended
19
- link target.
17
+ `config_unknown_key` and `config_invalid_value` mean a present file has a key
18
+ or value the schema rejects. Confirm that include patterns match real files
19
+ relative to the selected `--root`, language keys are supported, and excludes
20
+ do not remove an intended link target.
20
21
 
21
22
  ## Scanner errors
22
23
 
23
- Swift, Dart, and Rust use packaged scanner workers. A `scanner_unavailable` diagnostic
24
- usually means the installed package lacks a binary for the current platform or
25
- the binary cannot execute. Reinstall the package first. If the platform is not
26
- supported, run DocBridge in a supported environment or build the scanner from
27
- the repository.
28
-
29
- `scanner_failed` diagnostics contain the worker failure rather than converting
30
- it into a broken link. Check that the source parses with the project's own
31
- toolchain, then reproduce with the smallest configured file set.
32
-
33
- ## Parsing and target errors
34
-
35
- - A missing documentation file or anchor means the `@doc` path or normalized
36
- heading anchor does not resolve.
37
- - A missing code file or symbol means the `@code` path or canonical symbol ID
38
- does not resolve.
39
- - A missing backlink means one direction resolves but the counterpart lacks
40
- the reciprocal annotation.
41
- - A malformed annotation means the comment syntax or target shape is invalid.
24
+ Swift, Dart, and Rust use packaged scanner workers. A
25
+ `code_scanner_unavailable` diagnostic usually means the installed package
26
+ lacks a binary for the current platform or the binary cannot execute.
27
+ Reinstall the package first. If the platform is not supported, run DocBridge
28
+ in a supported environment or build the scanner from the repository.
29
+
30
+ `code_scanner_failed` diagnostics contain the worker failure rather than
31
+ converting it into a broken link. Check that the source parses with the
32
+ project's own toolchain, then reproduce with the smallest configured file
33
+ set.
34
+
35
+ ## Link-authoring errors
36
+
37
+ These codes appear while writing `@doc` / `@code` pairs:
38
+
39
+ | Diagnostic | Meaning | Usual fix |
40
+ | ---------------------------------------------------- | ---------------------------------------- | ----------------------------------------------------- |
41
+ | `doc_file_not_found` / `code_file_not_found` | target file not in the managed set | fix the path, or extend `docbridge.config.json` globs |
42
+ | `doc_anchor_not_found` | file found, anchor wrong | regenerate the anchor from the exact heading text |
43
+ | `doc_backlink_not_found` / `code_backlink_not_found` | one direction missing | add the missing `@code` or `@doc` side |
44
+ | `unsupported_declaration` | `@doc` on an unsupported declaration | move the tag to a supported declaration |
45
+ | `dangling_code_annotation` | text between `@code` and the heading | move the comment directly above the heading |
46
+ | `invalid_link_target` | malformed `file#fragment` | rewrite the target; see `docs show annotations` |
47
+ | `duplicate_doc_anchor` | two headings share an anchor in one file | rename one heading so anchors stay unique |
48
+ | `duplicate_code_symbol` | two annotated declarations share an ID | keep one `@doc` per canonical ID in that file |
49
+ | `duplicate_link` | the same source repeats the same target | remove the extra annotation |
42
50
 
43
51
  Use `docbridge graph --json` to inspect resolved and one-way edges. Use
44
52
  `docbridge context <file>` to confirm which counterpart content DocBridge can
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "docbridge",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "description": "A CLI that links Markdown specifications and code declarations. Runs on Node.js and Bun.",
5
5
  "keywords": [
6
6
  "bun",
@@ -1,34 +1,27 @@
1
1
  # DocBridge skill templates
2
2
 
3
- Distributable agent skills for projects that use DocBridge. Prefer
3
+ Distributable agent skill for projects that use DocBridge. Prefer
4
4
  `docbridge init` for CLI-driven setup or `docbridge init-with-agent` for
5
- agent-guided adoption. `init-with-agent` installs `docbridge-adopt` first;
6
- `docbridge-adopt` installs the companion skills after scope is confirmed.
7
- Manual copy-based installation remains available: copy a
8
- skill directory into your repository's skill location (`.claude/skills/` for
9
- Claude Code or `.agents/skills/` for Codex-style project skills) and adjust
10
- nothing unless your DocBridge invocation differs from the examples inside.
5
+ agent-guided adoption. Both commands install the same `docbridge` skill.
6
+ Manual copy-based installation remains available: copy the skill directory
7
+ into your repository's skill location (`.claude/skills/` for Claude Code or
8
+ `.agents/skills/` for Codex-style project skills).
11
9
 
12
- - [`docbridge-annotate`](docbridge-annotate/SKILL.md) — create correct
13
- `@doc`/`@code` link pairs and verify them with `docbridge check`.
14
- - [`docbridge-sync`](docbridge-sync/SKILL.md) — triage `related --gate`
15
- findings: fetch the flagged counterpart content with `docbridge context`,
16
- then update the counterpart or justify leaving it unchanged.
17
- - [`docbridge-adopt`](docbridge-adopt/SKILL.md) — adopt DocBridge in an existing
18
- TypeScript, Swift, Dart, or Rust project by confirming docs/code scope, creating
19
- or improving config, installing companion skills, and handling simple CI or
20
- Git-hook setup.
21
- - [`docbridge-link`](docbridge-link/SKILL.md) — link existing docs sections to
22
- existing supported code declarations through docs-first candidate discovery
23
- and section-level confirmation.
24
- - [`docbridge-review`](docbridge-review/SKILL.md) — review the whole DocBridge
25
- graph for semantic validity using `docbridge graph --json --include-content`.
10
+ - [`docbridge`](docbridge/SKILL.md) — route adopt, discover-and-link, annotate,
11
+ review, and sync work. Facts about the binary live in
12
+ `docbridge docs show`, not in this file.
26
13
 
27
- This repository dogfoods the distributable DocBridge skills from both
14
+ This repository dogfoods the distributable DocBridge skill from both
28
15
  `.claude/skills/` and `.agents/skills/` as skill-level symlinks to this
29
16
  directory. The template is the source of truth; do not edit the symlinked
30
17
  copies in place. In-repository dogfood links require symlink-capable checkouts;
31
18
  external projects should use the copy-based installation above.
32
19
 
33
- The Git-hook and CI integration that complements these skills is described
20
+ Existing installs may still have the five legacy skill directories
21
+ (`docbridge-adopt`, `docbridge-annotate`, `docbridge-link`,
22
+ `docbridge-review`, `docbridge-sync`). `docbridge init --force` removes those
23
+ copied directories after you review local edits. Symlinked skill directories
24
+ are reported and left untouched.
25
+
26
+ The Git-hook and CI integration that complements this skill is described
34
27
  under [`docs/integrations/`](../../docs/integrations/).
@@ -0,0 +1,126 @@
1
+ ---
2
+ name: docbridge
3
+ description: Adopt or introduce DocBridge, choose docs and code scope, create or improve docbridge.config.json, add @doc and @code annotations, fix link diagnostics, triage related --gate findings, and review existing links for stale docs or semantic validity.
4
+ ---
5
+
6
+ # docbridge
7
+
8
+ Route DocBridge work, then apply the matching judgment. Facts about the binary
9
+ — annotation syntax, supported declarations, the anchor algorithm, diagnostic
10
+ codes — live in packaged docs, not in this skill. Read them with
11
+ `docbridge docs show`. Invocation is documented in
12
+ `docbridge docs show agent-integration`.
13
+
14
+ An agent with no DocBridge skill can still finish the job from
15
+ `docbridge --help` plus `docbridge docs list` / `docbridge docs show`.
16
+
17
+ ## Task router
18
+
19
+ Pick **one** job before editing. The first matching question wins:
20
+
21
+ | Job | Ask this | Not this |
22
+ | ----------------- | ------------------------------------------------------------------------------ | --------------------------------------------- |
23
+ | Adopt | Introduce DocBridge, choose docs/code scope, or write `docbridge.config.json`? | Linking existing files |
24
+ | Discover and link | Choose what to link in existing docs, docs-first? | A known pair already confirmed |
25
+ | Annotate | Add or fix a `@doc` / `@code` pair, or clear link diagnostics? | Deciding _whether_ a section should be linked |
26
+ | Review | Check whether the docs still match the code, with no change set? | Gate findings on a diff |
27
+ | Sync | A Git hook, CI comment, or `related --gate` flagged unchanged counterparts? | Auditing the whole graph |
28
+
29
+ **Review versus sync.** Whole graph, no change set → **review**. A change set's
30
+ flagged counterparts → **sync**. "Check whether the docs still match the code"
31
+ is review. "These counterparts were not updated in this diff" is sync.
32
+
33
+ ## Adopt
34
+
35
+ Survey the repo: existing config, likely specification directories, public API
36
+ locations, existing annotations, scripts, CI, and Git hooks.
37
+
38
+ Recommend docs scope, code scope, and whether to wire simple CI or hooks now.
39
+ Show the tradeoff, then wait for confirmation. Create or improve
40
+ `docbridge.config.json` only after that. Use the language-keyed `include.code`
41
+ object, never the old array form. Never replace a user-authored config blindly.
42
+
43
+ Handle CI and Git hooks conservatively: implement a simple confirmed setup;
44
+ otherwise provide a patch plan. Prefer a non-blocking gate early in adoption.
45
+
46
+ Verify with `docbridge check`. A clean zero-link result is acceptable. Then
47
+ continue into discover-and-link.
48
+
49
+ Read `docbridge docs show getting-started` and `configuration`.
50
+
51
+ ## Discover and link
52
+
53
+ Work docs-first. Confirm docs scope, then follow
54
+ `docbridge docs show linking-workflow`: prioritize unlinked specification
55
+ sections, propose at most three symbols per section with why/uncertain, present
56
+ 5–10 sections per round, collect adopt/exclude/hold, and classify no-matches
57
+ instead of forcing a link.
58
+
59
+ Add annotations only after section-level confirmation. Then follow Annotate.
60
+
61
+ ## Annotate
62
+
63
+ Create both sides of a pair, or add the missing backlink. Read
64
+ `docbridge docs show annotations` for syntax, supported declarations, anchors,
65
+ and target grammar. Read `docbridge docs show troubleshooting` for diagnostic
66
+ codes and fixes.
67
+
68
+ Procedure: identify the declaration and the heading; add `@doc` on the
69
+ declaration (create a minimal doc comment if missing); add `@code` directly
70
+ above the heading; verify with `docbridge check`. The pair is correct only when
71
+ no diagnostic mentions either endpoint.
72
+
73
+ Do not split or rename headings in this job. Preserve existing annotations
74
+ unless the user asked to fix a wrong link.
75
+
76
+ ## Sync
77
+
78
+ A `related --gate` violation means nobody has decided yet, not that the
79
+ counterpart must change. Read `docbridge docs show agent-integration` for the
80
+ three-way judgment.
81
+
82
+ 1. Collect violations from the hook, CI comment, or
83
+ `git diff --name-only HEAD | docbridge related --stdin --gate`.
84
+ 2. Fetch counterpart content with `docbridge context` over the changed files.
85
+ 3. Per counterpart: update it when the documented contract diverged; leave it
86
+ unchanged with a written justification that cites the counterpart content;
87
+ or fix the annotation pair when the link itself is wrong.
88
+ 4. Re-run the gate. Report every decision.
89
+
90
+ Never detach a link to silence the gate. Do not rubber-stamp: unread
91
+ counterpart content is not a judgment. When a code change contradicts an
92
+ explicit documented promise, surface that instead of quietly rewriting the
93
+ promise.
94
+
95
+ ## Review
96
+
97
+ Audit meaning across the whole graph, not a diff. Follow
98
+ `docbridge docs show link-review`.
99
+
100
+ Requires `docbridge graph --json --include-content`. Read `diagnostics` first.
101
+ Batch by docs file. Read both sides. Classify High / Medium / Low. Report
102
+ severity, endpoints, evidence, and a recommended fix. Do not edit annotations
103
+ automatically.
104
+
105
+ `check` proves mechanics; this job reviews meaning. Do not rubber-stamp a
106
+ resolving link. Prefer fewer, clearer links. Do not delete annotations to
107
+ silence uncertainty.
108
+
109
+ ## Shared guardrails
110
+
111
+ - Confirm scope and section-level decisions with the user before writing links.
112
+ - Do not decide branch or pull-request policy.
113
+ - Prefer public API declarations as link targets.
114
+ - After edits, re-run `docbridge check` (and `related --gate` for sync).
115
+
116
+ ## Read more
117
+
118
+ - `docbridge docs list` — the full menu
119
+ - `docbridge docs show agent-integration` — invocation, gate judgment, hooks, CI
120
+ - `docbridge docs show annotations` — `@doc` / `@code` rules
121
+ - `docbridge docs show linking-workflow` — docs-first candidate discovery
122
+ - `docbridge docs show link-review` — semantic audit
123
+ - `docbridge docs show troubleshooting` — diagnostic codes and fixes
124
+ - `docbridge docs show getting-started` — first-time setup
125
+ - `docbridge docs show configuration` — `docbridge.config.json`
126
+ - `docbridge docs show commands` — check, related, context, graph
@@ -1,96 +0,0 @@
1
- ---
2
- name: docbridge-adopt
3
- description: Adopt DocBridge in an existing TypeScript, Swift, Dart, or Rust project. Use when asked to introduce DocBridge into a repository, choose docs/code scope, create or improve docbridge.config.json, and optionally wire simple CI or Git hooks.
4
- ---
5
-
6
- # docbridge-adopt
7
-
8
- Adopt DocBridge in an existing project. This skill assumes it is already
9
- installed in the agent environment through `docbridge init-with-agent`,
10
- `docbridge init`, or a manual copy into `.agents/skills/` or
11
- `.claude/skills/`.
12
-
13
- The goal is to make the repository ready for DocBridge links, then continue
14
- into an initial docs-first link-candidate pass. Do not assume a pull request.
15
-
16
- Run DocBridge with the project's native invocation: `docbridge` on `PATH`, a
17
- repo recipe such as `just check`, or
18
- `bun run /path/to/docbridge/src/cli/index.ts`.
19
-
20
- ## Procedure
21
-
22
- 1. **Survey the repository.** Inspect:
23
- - existing `docbridge.config.json`
24
- - Markdown docs structure and likely specification directories
25
- - TypeScript, Swift, Dart, or Rust source structure and public API locations
26
- - existing `@doc` / `@code` annotations
27
- - package scripts, CI files, and Git hooks
28
-
29
- 2. **Recommend scope, then ask for confirmation.** Present concise options and
30
- your recommendation for:
31
- - docs scope: directories/files whose sections are likely specifications,
32
- contracts, behavior, constraints, or design decisions
33
- - code scope: language-keyed TypeScript, Swift, Dart, or Rust directories/files
34
- whose supported declarations should be linkable
35
- - CI/Git-hook mode: if any integration should be added now
36
-
37
- Do not ask the user to rediscover obvious facts from the repository. Show
38
- your recommendation and the tradeoff, then wait for confirmation.
39
-
40
- 3. **Create or improve config.**
41
- - If no config exists, create `docbridge.config.json` with the confirmed
42
- `include.code` and `include.docs` globs.
43
- - Use the language-keyed `include.code` object. Do not write the old
44
- array form; for example, use `{ "typescript": { "patterns": [...] } }`,
45
- `{ "swift": { "patterns": [...] } }`, `{ "dart": { "patterns": [...] } }`,
46
- or `{ "rust": { "patterns": [...] } }`.
47
- - If config exists, read it, explain the current scope, propose any
48
- improvement, and edit only after confirmation.
49
- - Never replace a user-authored config blindly.
50
-
51
- 4. **Install companion DocBridge skills.**
52
- - After scope is confirmed and `docbridge.config.json` exists or has been
53
- intentionally left unchanged, install the rest of the distributable
54
- DocBridge skills for the same agent target.
55
- - Prefer the project-native DocBridge invocation. From the project root, run
56
- `docbridge init --yes --agent-target codex` for Codex,
57
- `docbridge init --yes --agent-target claude` for Claude Code, or
58
- `docbridge init --yes --agent-target both` for both. Use the target that
59
- matches the existing `.agents/` and/or `.claude/` setup.
60
- - This command should leave an existing `docbridge.config.json` unchanged
61
- and copy any missing `docbridge-annotate`, `docbridge-link`,
62
- `docbridge-review`, and `docbridge-sync` skill directories. Do not use
63
- `--force` unless the user explicitly asks to overwrite installed skills.
64
- - If the command is unavailable, explain the blocker and provide the manual
65
- copy target paths from `templates/skills/docbridge-*` instead of silently
66
- skipping this step.
67
-
68
- 5. **Handle CI and Git hooks conservatively.**
69
- - If the existing setup is simple and the user confirmed the mode, implement
70
- it.
71
- - If the setup is complex or ambiguous, provide a concrete patch plan or
72
- snippet instead of editing.
73
- - Prefer non-blocking awareness early in adoption unless the user requests a
74
- hard gate.
75
-
76
- 6. **Verify the setup.** Run `docbridge check` or the repository's equivalent.
77
- If the project intentionally has no links yet, a clean zero-link result is
78
- acceptable. Surface config or scanning diagnostics before proceeding.
79
-
80
- 7. **Continue into initial candidate discovery.** After setup, inspect the
81
- confirmed docs scope and present 5-10 high-value section candidates using
82
- the `docbridge-link` rules. Candidate discovery may continue in the same
83
- turn, but annotation edits still require section-level user confirmation.
84
-
85
- ## Scope Rules
86
-
87
- - Prefer docs sections that state behavior, contracts, inputs/outputs,
88
- constraints, user-visible behavior, or design decisions.
89
- - Treat README, changelogs, contribution docs, runbooks, logs, and release
90
- notes as exclusions by default unless the user identifies specific sections
91
- as specifications.
92
- - Prefer supported public API declarations as link targets. TypeScript starts
93
- with top-level exported declarations; Swift, Dart, and Rust also support member
94
- endpoints with scanner-produced canonical IDs.
95
- - Do not decide project workflow policy such as branch or PR strategy. Mention
96
- only what affects DocBridge adoption.
@@ -1,99 +0,0 @@
1
- ---
2
- name: docbridge-annotate
3
- description: Create bidirectional DocBridge links between supported code declarations and Markdown sections. Use when asked to link code to its specification, add @doc or @code annotations, annotate new code with docs, or fix DocBridge link diagnostics.
4
- ---
5
-
6
- # docbridge-annotate
7
-
8
- Create a DocBridge link pair: a `@doc` tag in the code documentation comment
9
- and a `@code` comment above the Markdown heading. A link is valid only when
10
- both directions exist and point at each other.
11
-
12
- Run DocBridge with the project's native invocation: `docbridge` on `PATH`, a
13
- repo recipe such as `just check`, or
14
- `bun run /path/to/docbridge/src/cli/index.ts`.
15
-
16
- ## Link anatomy
17
-
18
- Code side — a `@doc` tag in the documentation comment of a supported
19
- declaration:
20
-
21
- ```ts
22
- /**
23
- * @doc docs/auth.md#login-spec
24
- */
25
- export async function login() {}
26
- ```
27
-
28
- ```swift
29
- /// @doc docs/auth.md#login-spec
30
- public struct AuthService {
31
- public func login(email: String, password: String) {}
32
- }
33
- ```
34
-
35
- Markdown side — a standalone HTML comment directly above the heading of the
36
- section:
37
-
38
- ```md
39
- <!-- @code src/auth/login.ts#login -->
40
-
41
- ## Login Spec
42
- ```
43
-
44
- Both targets are `file#fragment`: the file path is project-root-relative with
45
- `/` separators (no `./`, `../`, or absolute paths), and the fragment is
46
- required. Optional text after the target is allowed and ignored
47
- (`@doc docs/auth.md#login-spec human note`).
48
-
49
- ## Rules that decide whether the link resolves
50
-
51
- - `@doc` works only on top-level exported declarations: `function`, `class`,
52
- `abstract class`, `interface`, `type`, `enum`, `const enum`, `const` with a
53
- single declarator, named default `function`/`class`, and their `declare`
54
- forms. Anything else (anonymous default exports, multi-declarator `const`,
55
- namespaces, re-exports, non-exported declarations) produces
56
- `unsupported_declaration`.
57
- - Swift `@doc` works on supported public/open declarations and configured
58
- internal declarations. Member endpoints are type-qualified and include
59
- argument labels, for example `AuthService.login(email:password:)`.
60
- - Dart `@doc` works on supported public declarations. Member endpoints are
61
- type-qualified without parameter signatures, for example
62
- `AuthService.login`; setters carry a trailing `=`.
63
- - The code-side fragment is the scanner-produced canonical ID.
64
- - The doc-side fragment is the anchor generated from the ATX heading
65
- (`#`–`######`): lowercase via JavaScript `toLowerCase()`, Unicode letters
66
- and numbers preserved, whitespace and punctuation runs collapsed to `-`,
67
- leading/trailing `-` removed. Example: `## Login Spec (v2)` →
68
- `#login-spec-v2`. Setext headings have no anchors.
69
- - The `@code` comment must be standalone, indented at most 3 spaces, with the
70
- body starting with `@code`. Blank lines between the comment and its heading
71
- are fine; any other text in between makes it `dangling_code_annotation`.
72
- - One declaration may carry multiple `@doc` tags and one heading multiple
73
- `@code` comments; each pair is an independent link.
74
- - Anchors must be unique within one Markdown file; symbols must be unique
75
- among annotated declarations in one TypeScript file.
76
-
77
- ## Procedure
78
-
79
- 1. Identify the two endpoints: the exported declaration and the Markdown
80
- section. If the section does not exist yet, write it first — the heading
81
- text fixes the anchor.
82
- 2. Add the `@doc` tag to the declaration's documentation comment (create the
83
- documentation comment if missing), pointing at the doc file and the
84
- generated heading anchor.
85
- 3. Add the `@code` comment directly above the heading, pointing back at the
86
- code file and the scanner-produced canonical ID.
87
- 4. Verify with `docbridge check`. The link is correct only when no diagnostic
88
- mentions either endpoint.
89
-
90
- ## Diagnosing check failures
91
-
92
- | Diagnostic | Meaning | Usual fix |
93
- | ---------------------------------------------------- | ------------------------------------ | ----------------------------------------------------- |
94
- | `doc_file_not_found` / `code_file_not_found` | target file not in the managed set | fix the path, or extend `docbridge.config.json` globs |
95
- | `doc_anchor_not_found` | file found, anchor wrong | regenerate the anchor from the exact heading text |
96
- | `doc_backlink_not_found` / `code_backlink_not_found` | one direction missing | add the missing `@code` or `@doc` side |
97
- | `unsupported_declaration` | `@doc` on an unsupported declaration | move the tag to a supported declaration |
98
- | `dangling_code_annotation` | text between `@code` and the heading | move the comment directly above the heading |
99
- | `invalid_link_target` | malformed `file#fragment` | rewrite the target per the rules above |