docbridge 0.6.1 → 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.
Files changed (32) hide show
  1. package/CHANGELOG.md +132 -1
  2. package/README.md +78 -42
  3. package/dist/bin/darwin-arm64/SHA256SUMS +3 -2
  4. package/dist/bin/darwin-arm64/docbridge-rust-scanner +0 -0
  5. package/dist/bin/darwin-arm64/docbridge-swift-scanner +0 -0
  6. package/dist/bin/darwin-arm64/docbridge_dart_scanner +0 -0
  7. package/dist/bin/linux-x64/SHA256SUMS +3 -2
  8. package/dist/bin/linux-x64/docbridge-rust-scanner +0 -0
  9. package/dist/bin/linux-x64/docbridge-swift-scanner +0 -0
  10. package/dist/bin/linux-x64/docbridge_dart_scanner +0 -0
  11. package/dist/index.js +8599 -987
  12. package/docs/user/agent-integration.md +96 -0
  13. package/docs/user/annotations.md +173 -0
  14. package/docs/user/commands.md +64 -0
  15. package/docs/user/configuration.md +77 -0
  16. package/docs/user/getting-started.md +75 -0
  17. package/docs/user/link-review.md +53 -0
  18. package/docs/user/linking-workflow.md +70 -0
  19. package/docs/user/troubleshooting.md +61 -0
  20. package/package.json +4 -2
  21. package/schemas/common-output.schema.json +56 -0
  22. package/schemas/context-output.schema.json +2 -32
  23. package/schemas/docbridge.schema.json +77 -7
  24. package/schemas/graph-output.schema.json +6 -52
  25. package/schemas/scanner-worker.schema.json +122 -0
  26. package/templates/skills/README.md +17 -25
  27. package/templates/skills/docbridge/SKILL.md +126 -0
  28. package/templates/skills/docbridge-adopt/SKILL.md +0 -96
  29. package/templates/skills/docbridge-annotate/SKILL.md +0 -99
  30. package/templates/skills/docbridge-link/SKILL.md +0 -80
  31. package/templates/skills/docbridge-review/SKILL.md +0 -62
  32. package/templates/skills/docbridge-sync/SKILL.md +0 -68
@@ -1,96 +0,0 @@
1
- ---
2
- name: docbridge-adopt
3
- description: Adopt DocBridge in an existing TypeScript, Swift, or Dart 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 agent 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, or Dart source structure and public API locations
26
- - existing `@doc` / `@code` annotations
27
- - package scripts, CI files, git hooks, and agent 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, or Dart directories/files
34
- whose supported declarations should be linkable
35
- - CI/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": [...] } }`, or
46
- `{ "dart": { "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/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 and Dart 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 |
@@ -1,80 +0,0 @@
1
- ---
2
- name: docbridge-link
3
- description: Link existing Markdown specification sections to existing supported code declarations. Use for docs-first candidate discovery, section-level confirmation, and adding @doc/@code annotations to existing projects.
4
- ---
5
-
6
- # docbridge-link
7
-
8
- Create DocBridge annotations for existing docs and code. Work docs-first: choose
9
- Markdown sections that look like specifications, then propose supported
10
- TypeScript, Swift, or Dart declarations that implement or represent each
11
- section.
12
-
13
- Run DocBridge with the project's native invocation: `docbridge` on `PATH`, a
14
- repo recipe such as `just check`, or
15
- `bun run /path/to/docbridge/src/cli/index.ts`.
16
-
17
- ## Procedure
18
-
19
- 1. **Determine docs scope.** Use the scope confirmed by `docbridge-adopt` when
20
- available. Otherwise, inspect the repository and ask the user to confirm the
21
- docs directories/files before proposing links.
22
-
23
- 2. **Find section candidates.**
24
- - Prioritize unlinked sections.
25
- - Include already linked sections at lower priority when an additional link
26
- may be justified.
27
- - Ignore sections that are clearly prose-only, changelog entries, runbook
28
- steps, or project process unless the user says they are specifications.
29
-
30
- 3. **For each candidate section, propose up to three code symbols.** Base the
31
- ranking on:
32
- - heading text and section body
33
- - exported symbol names
34
- - existing JSDoc and nearby comments
35
- - file paths and directory names
36
- - implementation body only when the surrounding information is insufficient
37
-
38
- Include both:
39
- - why the symbol may match
40
- - what remains uncertain
41
-
42
- 4. **Ask for section-level decisions.** Present 5-10 section candidates at a
43
- time. For each section the user can choose:
44
- - adopt: select one or more code symbols to link
45
- - exclude: do not link this section
46
- - hold: keep undecided for later
47
-
48
- The user may also name a symbol not in the proposed top three.
49
-
50
- 5. **Classify no-match sections.** If no reasonable exported symbol exists,
51
- report the likely reason instead of forcing a link:
52
- - not implemented yet
53
- - spans multiple symbols without a clear public representative
54
- - likely stale docs
55
- - not a specification section
56
- - target appears internal or not exported
57
-
58
- 6. **Add annotations only after confirmation.**
59
- - Add `@code` directly above the Markdown heading, as the nearest comment
60
- to the heading.
61
- - Add `@doc` to the code declaration's documentation comment.
62
- - If the declaration has no documentation comment, create a minimal one
63
- containing only `@doc`, using the language's documentation comment form.
64
- - If the pair already exists on one side, show it and, after confirmation,
65
- add the missing backlink.
66
- - Preserve existing annotations; do not replace or clean up suspicious links
67
- in this skill.
68
-
69
- 7. **Verify.** Run `docbridge check`, then inspect the affected links with
70
- `docbridge context` or `docbridge graph --json --include-content` for the
71
- changed files. Report any remaining diagnostics or semantic uncertainty.
72
-
73
- ## Boundaries
74
-
75
- - Do not split Markdown sections or rename headings. If a section is too broad
76
- or ambiguous, classify it as held or no-match.
77
- - Multiple code symbols may link to one docs section when each role is clear.
78
- - One code symbol may link to multiple docs sections when each section covers a
79
- distinct specification aspect.
80
- - Do not link solely because names are similar.
@@ -1,62 +0,0 @@
1
- ---
2
- name: docbridge-review
3
- description: Review all existing DocBridge links for semantic validity. Use after adoption or periodically to find valid-but-wrong links, stale docs, excessive links, or ambiguous docs/code relationships.
4
- ---
5
-
6
- # docbridge-review
7
-
8
- Review the semantic validity of the entire DocBridge graph. This is not a
9
- change-set or pull-request review. It checks whether valid links actually
10
- connect a docs section to the code symbol that implements or represents that
11
- specification.
12
-
13
- This skill requires `docbridge graph --json --include-content`.
14
-
15
- ## Procedure
16
-
17
- 1. **Build the graph.**
18
-
19
- ```sh
20
- docbridge graph --json --include-content
21
- ```
22
-
23
- If the repository uses a wrapper, use the native invocation instead. Read
24
- `diagnostics` first. Mechanical failures from `docbridge check` should be
25
- fixed or acknowledged before relying on semantic findings.
26
-
27
- 2. **Batch by docs file.** Review all links, but process them in batches:
28
- - docs file is the default batch boundary
29
- - split a batch further when it contains too many sections or links
30
- - keep notes so repeated patterns are applied consistently across batches
31
-
32
- 3. **Read both sides.**
33
- - For docs nodes, use the graph range to read the full Markdown section.
34
- - For code nodes, start with graph content: JSDoc plus signature. Read the
35
- implementation only when necessary to judge the relationship.
36
- - Compare behavior, contract, input/output, constraints, and design intent.
37
-
38
- 4. **Classify findings.**
39
- - High: clearly wrong link, stale docs fixed in place by a link, or a link
40
- to a section that is not a specification.
41
- - Medium: partial overlap, unclear representative symbol, overly broad
42
- section, or multiple linked symbols with ambiguous roles.
43
- - Low: cleanup opportunity, duplicate docs, excessive links, or missing
44
- explanation of why multiple links are needed.
45
-
46
- 5. **Report findings and fixes.** For each finding include:
47
- - severity
48
- - doc endpoint and code endpoint
49
- - evidence from both sides
50
- - recommended fix
51
-
52
- Do not edit annotations automatically. If the user approves a fix, use
53
- `docbridge-link` or `docbridge-annotate` rules to make the change.
54
-
55
- ## Principles
56
-
57
- - `docbridge check` proves link mechanics; this skill reviews meaning.
58
- - Do not rubber-stamp links because the target resolves.
59
- - Do not delete annotations merely to silence uncertainty. Explain the
60
- uncertainty and ask for a decision.
61
- - Prefer fewer, clearer links over broad many-to-many links without explicit
62
- roles.
@@ -1,68 +0,0 @@
1
- ---
2
- name: docbridge-sync
3
- description: Triage DocBridge related-gate findings — linked counterparts of changed files that were not themselves updated. Use when a Stop-hook message, CI comment, or docbridge related --gate run flags unchanged counterparts, to judge divergence with docbridge context and then update or justify each one.
4
- ---
5
-
6
- # docbridge-sync
7
-
8
- Resolve `docbridge related --gate` findings. A gate violation means a changed
9
- file has a linked counterpart that nobody updated — it does **not** mean the
10
- counterpart must change; it means nobody has decided yet. This skill makes
11
- that decision explicit, per counterpart.
12
-
13
- Run DocBridge with the project's native invocation: `docbridge` on `PATH`, a
14
- repo recipe such as `just related-gate`, or
15
- `bun run /path/to/docbridge/src/cli/index.ts`.
16
-
17
- ## Procedure
18
-
19
- 1. **Collect the violations.** Use the gate report you were given (Stop-hook
20
- message, CI comment), or produce one over the change set:
21
-
22
- ```sh
23
- git diff --name-only HEAD | docbridge related --stdin --gate
24
- ```
25
-
26
- Each violation names a changed endpoint and its unchanged counterpart
27
- endpoint.
28
-
29
- 2. **Fetch the counterpart content.** If the report did not include it, run
30
- the context command over the changed files; its output is the counterparts'
31
- content:
32
-
33
- ```sh
34
- git diff --name-only HEAD | docbridge context --stdin
35
- ```
36
-
37
- Read the block for each flagged counterpart: the full spec section for a
38
- doc counterpart, the full declaration including JSDoc for a code one.
39
-
40
- 3. **Judge divergence, per counterpart.** Compare what the counterpart says
41
- with what the change did:
42
- - Behavior, contract, format, or constraint described by the counterpart no
43
- longer matches → **update the counterpart** in the same change set.
44
- - The change is internal (refactoring, comments, test-only, formatting) and
45
- every documented statement still holds → **no update**, with a written
46
- justification.
47
- - The link itself is wrong (points at the wrong section or symbol) → fix
48
- the annotation pair instead; follow the `docbridge-annotate` skill.
49
-
50
- 4. **Re-run the gate** after updates. Counterparts you edited leave the
51
- violation list; what remains must be covered by justifications.
52
-
53
- 5. **Report every decision.** In the final response (and the PR description
54
- when one exists), list each flagged counterpart with either the update made
55
- or the justification. A justification must reference the counterpart's
56
- actual content ("the section documents the exit codes, which this change
57
- does not alter"), not just assert irrelevance.
58
-
59
- ## Principles
60
-
61
- - Never silence a violation by deleting or rewriting annotations to detach
62
- the link; that defeats the graph the gate protects.
63
- - Do not rubber-stamp: if the counterpart content was not read, the judgment
64
- has no basis.
65
- - Updating a spec section to match changed code is a _decision about the
66
- contract_, not bookkeeping — when the change contradicts an explicit
67
- documented promise, surface it to the user instead of quietly rewriting the
68
- promise.