docbridge 0.6.0 → 0.7.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.
@@ -0,0 +1,70 @@
1
+ ---
2
+ description: Wire DocBridge into coding agents, Git hooks, and CI.
3
+ ---
4
+
5
+ # Agent Integration
6
+
7
+ DocBridge gives coding agents deterministic link data instead of asking them
8
+ to infer documentation relationships from filenames.
9
+
10
+ <!-- @code src/cli/init.ts#runInitWithAgent -->
11
+
12
+ ## Install agent skills
13
+
14
+ `docbridge init` can install the distributable skills while creating project
15
+ configuration. To let an agent decide the scope, run:
16
+
17
+ ```sh
18
+ docbridge init-with-agent --agent-target codex
19
+ ```
20
+
21
+ Use `claude` or `both` for other supported targets. The command installs the
22
+ adoption skill and prints the next command or prompt; it does not launch an
23
+ agent process.
24
+
25
+ ## Editing workflow
26
+
27
+ Before changing a linked file, provide its counterpart content:
28
+
29
+ ```sh
30
+ docbridge context path/to/changed-file
31
+ ```
32
+
33
+ After editing, inspect the change set:
34
+
35
+ ```sh
36
+ git diff --name-only | docbridge related --stdin --gate
37
+ ```
38
+
39
+ For every reported counterpart, update it when behavior diverged or record why
40
+ no documentation or code change is necessary.
41
+
42
+ ## Hooks
43
+
44
+ Put the automation in Git hooks rather than in one agent's configuration, so
45
+ it covers every contributor and every tool. A `pre-commit` hook can run
46
+ `docbridge check` as a hard gate, then report `related --gate` over the staged
47
+ files:
48
+
49
+ ```sh
50
+ git diff --cached --name-only | docbridge related --stdin --gate
51
+ ```
52
+
53
+ When an agent runs `git commit` through a shell, the hook's output lands in the
54
+ tool result and therefore in the agent's context, so the counterpart findings
55
+ reach it without any agent-specific wiring. Attach the counterparts' content
56
+ with `docbridge context --stdin` to make the finding actionable in place.
57
+
58
+ Keep the gate stage non-blocking while the link graph is still sparse: a
59
+ blocking gate on a staged subset mostly trains `--no-verify`. Hooks must not
60
+ silently rewrite files or replace the repository's mandatory checks.
61
+
62
+ Git hooks cannot signal before an edit, and they are skipped by `--no-verify`
63
+ and by some GUI clients, so the pull request stays the enforcement point.
64
+
65
+ ## CI
66
+
67
+ Run `docbridge check` over the whole project as the hard link-validity gate. A
68
+ pull-request workflow can additionally pass the base-to-head changed file list
69
+ to `related --stdin --gate` and attach `context` output for reviewers. Ensure
70
+ the checkout includes both commits needed for the diff.
@@ -0,0 +1,52 @@
1
+ ---
2
+ description: Write @doc and @code annotations and valid link targets.
3
+ ---
4
+
5
+ # Annotations
6
+
7
+ DocBridge links supported code declarations to Markdown headings. A complete
8
+ pair has `@doc` on the declaration and `@code` immediately before the heading.
9
+
10
+ ## Code to documentation
11
+
12
+ Use a documentation path and heading anchor in a declaration's documentation
13
+ comment:
14
+
15
+ ```ts
16
+ /**
17
+ * @doc docs/auth.md#login-flow
18
+ */
19
+ export function login(): void {}
20
+ ```
21
+
22
+ Swift, Dart, and Rust use their normal documentation comment syntax with the same
23
+ target format. Paths are relative to the configured project root.
24
+
25
+ <!-- @code src/core/markdown.ts#scanMarkdown -->
26
+
27
+ ## Documentation to code
28
+
29
+ Place an HTML comment immediately before the linked heading:
30
+
31
+ ```md
32
+ <!-- @code src/auth.ts#login -->
33
+
34
+ ## Login Flow
35
+ ```
36
+
37
+ The code fragment is the canonical symbol ID emitted by the language scanner.
38
+ Top-level functions and types normally use their declaration name. Members use
39
+ their type-qualified identity. TypeScript member IDs omit parameter signatures,
40
+ Swift member IDs include argument labels, Dart member IDs omit parameter
41
+ signatures, and Rust member IDs use `::` path qualification.
42
+
43
+ ## Anchors and reciprocity
44
+
45
+ Markdown anchors use the normalized heading text, such as `# Login Flow`
46
+ becoming `#login-flow`. Duplicate headings receive the same numeric suffixes
47
+ used by GitHub-style Markdown anchors.
48
+
49
+ Each direction is validated independently. A target can resolve while still
50
+ reporting a missing reciprocal annotation. Run `docbridge check` to validate
51
+ targets and pair completeness, and `docbridge graph --json` when you need the
52
+ resolved endpoints and edges.
@@ -0,0 +1,56 @@
1
+ ---
2
+ description: Choose between check, related, context, and graph.
3
+ ---
4
+
5
+ # Commands
6
+
7
+ Use the narrowest command for the question you need to answer.
8
+
9
+ <!-- @code src/cli/index.ts#run -->
10
+
11
+ ## Command dispatch
12
+
13
+ The first argument selects a command. Global `--help` and `--version` are
14
+ handled before project scanning, while each command validates its own options.
15
+
16
+ ### `check`: validate the project
17
+
18
+ Run `docbridge check` before committing and in CI. It validates configuration,
19
+ annotations, targets, and reciprocal links. Add `--audit` to include warnings
20
+ for undocumented code declarations and unlinked Markdown sections. Add
21
+ `--json` for machine-readable diagnostics.
22
+
23
+ ### `related`: find counterpart files
24
+
25
+ Pass changed paths to learn which linked files may also need attention:
26
+
27
+ ```sh
28
+ git diff --name-only | docbridge related --stdin
29
+ ```
30
+
31
+ `--gate` exits `1` when a linked counterpart is absent from the supplied change
32
+ set. It identifies review obligations; it does not decide whether the
33
+ counterpart actually needs an edit.
34
+
35
+ ### `context`: read counterpart content
36
+
37
+ Use `context` when a human or agent needs the linked sections themselves:
38
+
39
+ ```sh
40
+ docbridge context src/auth.ts
41
+ ```
42
+
43
+ The default Markdown output is suitable for an agent prompt. `--json` returns
44
+ structured contexts, diagnostics, and a summary.
45
+
46
+ ### `graph`: inspect link structure
47
+
48
+ Use `graph` for endpoints, edges, reciprocal pairs, and unresolved links across
49
+ the project. Passing file paths scopes the result to those files and their
50
+ direct counterparts. `--include-content` is available only with `--json`.
51
+
52
+ ## Common options
53
+
54
+ The project commands accept `--root <path>` when invoked outside the project
55
+ root. Run `docbridge <command> --help` for the exact options and exit behavior
56
+ of a command.
@@ -0,0 +1,68 @@
1
+ ---
2
+ description: "Configure docbridge.config.json: roots, includes, excludes, languages."
3
+ ---
4
+
5
+ # Configuration
6
+
7
+ DocBridge loads `docbridge.config.json` from the project root supplied by
8
+ `--root`, or from the current directory by default. Paths and glob patterns are
9
+ interpreted relative to that root.
10
+
11
+ <!-- @code src/core/config.ts#loadConfig -->
12
+
13
+ ## Loading configuration
14
+
15
+ The configuration loader requires the file, validates its schema, and rejects
16
+ source files claimed by more than one configured language.
17
+
18
+ ## Minimal configuration
19
+
20
+ Declare documentation patterns and at least one supported code language:
21
+
22
+ ```json
23
+ {
24
+ "$schema": "./node_modules/docbridge/schemas/docbridge.schema.json",
25
+ "include": {
26
+ "code": {
27
+ "typescript": {
28
+ "patterns": ["src/**/*.ts"]
29
+ }
30
+ },
31
+ "docs": ["docs/**/*.md"]
32
+ }
33
+ }
34
+ ```
35
+
36
+ Supported language keys are `typescript`, `swift`, `dart`, and `rust`. A project can
37
+ enable more than one language, each with its own patterns.
38
+
39
+ ## Excluded files
40
+
41
+ The configuration has no `exclude` property. Narrow the include patterns when
42
+ tests, fixtures, generated files, or general documentation should stay outside
43
+ the graph:
44
+
45
+ ```json
46
+ {
47
+ "include": {
48
+ "code": {
49
+ "typescript": {
50
+ "patterns": ["src/domain/**/*.ts", "src/services/**/*.ts"]
51
+ }
52
+ },
53
+ "docs": ["docs/specs/**/*.md"]
54
+ }
55
+ }
56
+ ```
57
+
58
+ DocBridge always ignores dependency directories, Git metadata, dot-prefixed
59
+ path segments, symbolic links, and TypeScript declaration files (`.d.ts`).
60
+ Keep patterns narrow enough that `docbridge check --audit` reports useful
61
+ coverage gaps rather than every implementation detail or general prose file.
62
+
63
+ ## Validate changes
64
+
65
+ Run `docbridge check` after editing configuration. A missing, malformed, or
66
+ schema-invalid configuration produces `config_file_invalid`. Use
67
+ `docbridge init --dry-run` to inspect a safe generated starting point without
68
+ overwriting an existing file.
@@ -0,0 +1,71 @@
1
+ ---
2
+ description: Set up DocBridge in an existing TypeScript, Swift, Dart, or Rust project.
3
+ ---
4
+
5
+ # Getting Started
6
+
7
+ DocBridge checks that Markdown documentation and supported code declarations
8
+ link to each other. It scans only the files selected by
9
+ `docbridge.config.json`; it does not send source or documentation anywhere.
10
+
11
+ ## Install
12
+
13
+ Add DocBridge to a project with the package manager used by that project:
14
+
15
+ ```sh
16
+ npm install --save-dev docbridge
17
+ ```
18
+
19
+ The CLI supports Node.js 22 or later and Bun 1.1.31 or later.
20
+
21
+ <!-- @code src/cli/init.ts#runInit -->
22
+
23
+ ## Set up a project
24
+
25
+ Preview the files DocBridge would create:
26
+
27
+ ```sh
28
+ npx docbridge init --dry-run
29
+ ```
30
+
31
+ Then run `npx docbridge init` interactively, or use `--yes` when the detected
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
34
+ overwrites an existing configuration.
35
+
36
+ If a coding agent should choose the documentation and code scope, use:
37
+
38
+ ```sh
39
+ npx docbridge init-with-agent
40
+ ```
41
+
42
+ ## Add the first reciprocal link
43
+
44
+ Add `@doc` to a supported declaration and `@code` before the matching Markdown
45
+ heading. Both targets are relative to the project root:
46
+
47
+ ```ts
48
+ /** @doc docs/auth.md#login-flow */
49
+ export function login(): void {}
50
+ ```
51
+
52
+ ```md
53
+ <!-- @code src/auth.ts#login -->
54
+
55
+ ## Login Flow
56
+ ```
57
+
58
+ Run the quality gate:
59
+
60
+ ```sh
61
+ npx docbridge check
62
+ ```
63
+
64
+ A clean graph exits `0`. Broken links and invalid configuration exit `1`.
65
+
66
+ ## Next steps
67
+
68
+ - Read `docbridge docs show configuration` before narrowing scan scope.
69
+ - Read `docbridge docs show annotations` for link target rules.
70
+ - Read `docbridge docs show commands` to choose an inspection command.
71
+ - Add `docbridge check` to CI after the local graph passes.
@@ -0,0 +1,53 @@
1
+ ---
2
+ description: Diagnose configuration, scanner, parsing, and broken-link errors.
3
+ ---
4
+
5
+ # Troubleshooting
6
+
7
+ Start with the first error line, then follow any recovery guidance printed on
8
+ stderr. Use `docbridge <command> --help` for invocation errors and
9
+ `docbridge check --json` when a tool needs stable diagnostic fields.
10
+
11
+ ## Configuration errors
12
+
13
+ `config_file_invalid` means `docbridge.config.json` is missing, malformed, or
14
+ does not match the schema. Run `docbridge init --dry-run` when the file is
15
+ missing. When it exists, repair or remove it before running `check` again.
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.
20
+
21
+ ## Scanner errors
22
+
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.
42
+
43
+ Use `docbridge graph --json` to inspect resolved and one-way edges. Use
44
+ `docbridge context <file>` to confirm which counterpart content DocBridge can
45
+ currently resolve.
46
+
47
+ <!-- @code src/cli/errors.ts#formatCliError -->
48
+
49
+ ## CLI invocation errors
50
+
51
+ Unknown commands, unknown options, missing values, invalid roots, and missing
52
+ required inputs exit `1`, write to stderr, and leave stdout empty. These are not
53
+ included in diagnostic JSON because the project scan did not run.
package/package.json CHANGED
@@ -1,50 +1,54 @@
1
1
  {
2
2
  "name": "docbridge",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "A CLI that links Markdown specifications and code declarations. Runs on Node.js and Bun.",
5
- "license": "MIT",
6
- "type": "module",
7
- "bin": {
8
- "docbridge": "./dist/index.js"
9
- },
10
- "repository": {
11
- "type": "git",
12
- "url": "git+https://github.com/salan70/docbridge.git"
13
- },
14
- "bugs": {
15
- "url": "https://github.com/salan70/docbridge/issues"
16
- },
17
- "homepage": "https://github.com/salan70/docbridge#readme",
18
5
  "keywords": [
6
+ "bun",
7
+ "cli",
19
8
  "documentation",
9
+ "lsp",
20
10
  "markdown",
21
- "specification",
22
- "cli",
23
11
  "node",
24
- "bun",
25
- "lsp"
12
+ "specification"
26
13
  ],
27
- "engines": {
28
- "node": ">=22",
29
- "bun": ">=1.1.31"
14
+ "homepage": "https://github.com/salan70/docbridge#readme",
15
+ "bugs": {
16
+ "url": "https://github.com/salan70/docbridge/issues"
17
+ },
18
+ "license": "MIT",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/salan70/docbridge.git"
22
+ },
23
+ "bin": {
24
+ "docbridge": "./dist/index.js"
30
25
  },
31
26
  "files": [
32
27
  "dist",
28
+ "docs/user",
33
29
  "schemas",
34
30
  "templates/skills",
35
31
  "README.md",
36
32
  "CHANGELOG.md",
37
33
  "LICENSE"
38
34
  ],
35
+ "type": "module",
39
36
  "scripts": {
40
37
  "docbridge": "bun run src/cli/index.ts",
41
38
  "check": "bun run src/cli/index.ts check",
42
39
  "check:example": "bun run src/cli/index.ts check --root examples/typescript",
43
40
  "test": "bun test",
44
- "build": "bun build src/cli/index.ts --outdir dist --target bun"
41
+ "build": "bun build src/cli/index.ts --outdir dist --target node"
45
42
  },
46
43
  "devDependencies": {
47
44
  "@types/bun": "^1.3.14",
45
+ "ajv": "^8.20.0",
46
+ "oxfmt": "0.57.0",
47
+ "oxlint": "1.73.0",
48
48
  "typescript": "^5.9.0"
49
+ },
50
+ "engines": {
51
+ "bun": ">=1.1.31",
52
+ "node": ">=22"
49
53
  }
50
54
  }
@@ -0,0 +1,56 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "common-output.schema.json",
4
+ "title": "DocBridge Common Output Definitions",
5
+ "$defs": {
6
+ "location": {
7
+ "type": "object",
8
+ "additionalProperties": false,
9
+ "required": ["filePath", "line", "column"],
10
+ "properties": {
11
+ "filePath": { "type": "string" },
12
+ "line": { "type": "integer", "minimum": 1 },
13
+ "column": { "type": "integer", "minimum": 1 }
14
+ }
15
+ },
16
+ "position": {
17
+ "type": "object",
18
+ "additionalProperties": false,
19
+ "required": ["line", "column"],
20
+ "properties": {
21
+ "line": { "type": "integer", "minimum": 1 },
22
+ "column": { "type": "integer", "minimum": 1 }
23
+ }
24
+ },
25
+ "range": {
26
+ "type": "object",
27
+ "additionalProperties": false,
28
+ "required": ["start", "end"],
29
+ "properties": {
30
+ "start": { "$ref": "#/$defs/position" },
31
+ "end": { "$ref": "#/$defs/position" }
32
+ }
33
+ },
34
+ "diagnostic": {
35
+ "type": "object",
36
+ "additionalProperties": false,
37
+ "required": ["severity", "code", "target", "message"],
38
+ "properties": {
39
+ "severity": {
40
+ "type": "string",
41
+ "enum": ["error", "warning"]
42
+ },
43
+ "code": { "type": "string" },
44
+ "target": { "type": "string" },
45
+ "language": {
46
+ "type": "string",
47
+ "enum": ["typescript", "swift", "dart", "rust"]
48
+ },
49
+ "source": { "type": "string" },
50
+ "message": { "type": "string" },
51
+ "location": { "$ref": "#/$defs/location" },
52
+ "range": { "$ref": "#/$defs/range" }
53
+ }
54
+ }
55
+ }
56
+ }
@@ -11,7 +11,15 @@
11
11
  "items": {
12
12
  "type": "object",
13
13
  "additionalProperties": false,
14
- "required": ["endpoint", "kind", "filePath", "startLine", "endLine", "linkedFrom", "content"],
14
+ "required": [
15
+ "endpoint",
16
+ "kind",
17
+ "filePath",
18
+ "startLine",
19
+ "endLine",
20
+ "linkedFrom",
21
+ "content"
22
+ ],
15
23
  "properties": {
16
24
  "endpoint": {
17
25
  "type": "string",
@@ -27,7 +35,7 @@
27
35
  },
28
36
  "language": {
29
37
  "type": "string",
30
- "enum": ["typescript", "swift", "dart"],
38
+ "enum": ["typescript", "swift", "dart", "rust"],
31
39
  "description": "Code language for code context blocks."
32
40
  },
33
41
  "startLine": {
@@ -58,37 +66,7 @@
58
66
  "diagnostics": {
59
67
  "type": "array",
60
68
  "description": "Check diagnostics located in the input files, in check order.",
61
- "items": {
62
- "type": "object",
63
- "required": ["severity", "code", "target", "message"],
64
- "properties": {
65
- "severity": {
66
- "type": "string",
67
- "enum": ["error", "warning"]
68
- },
69
- "code": {
70
- "type": "string"
71
- },
72
- "target": {
73
- "type": "string"
74
- },
75
- "source": {
76
- "type": "string"
77
- },
78
- "message": {
79
- "type": "string"
80
- },
81
- "location": {
82
- "type": "object",
83
- "required": ["filePath", "line", "column"],
84
- "properties": {
85
- "filePath": { "type": "string" },
86
- "line": { "type": "integer", "minimum": 1 },
87
- "column": { "type": "integer", "minimum": 1 }
88
- }
89
- }
90
- }
91
- }
69
+ "items": { "$ref": "common-output.schema.json#/$defs/diagnostic" }
92
70
  },
93
71
  "summary": {
94
72
  "type": "object",
@@ -18,23 +18,25 @@
18
18
  "additionalProperties": false,
19
19
  "minProperties": 1,
20
20
  "properties": {
21
- "typescript": { "$ref": "#/$defs/codeLanguageEntry" },
22
- "swift": { "$ref": "#/$defs/codeLanguageEntry" },
23
- "dart": { "$ref": "#/$defs/codeLanguageEntry" }
21
+ "typescript": { "$ref": "#/$defs/typescriptEntry" },
22
+ "swift": { "$ref": "#/$defs/swiftEntry" },
23
+ "dart": { "$ref": "#/$defs/dartEntry" },
24
+ "rust": { "$ref": "#/$defs/rustEntry" }
24
25
  }
25
26
  },
26
27
  "docs": {
27
28
  "type": "array",
28
29
  "minItems": 1,
29
30
  "items": {
30
- "type": "string"
31
+ "type": "string",
32
+ "pattern": "\\.md$"
31
33
  }
32
34
  }
33
35
  }
34
36
  }
35
37
  },
36
38
  "$defs": {
37
- "codeLanguageEntry": {
39
+ "typescriptEntry": {
38
40
  "type": "object",
39
41
  "additionalProperties": false,
40
42
  "required": ["patterns"],
@@ -43,13 +45,81 @@
43
45
  "type": "array",
44
46
  "minItems": 1,
45
47
  "items": {
46
- "type": "string"
48
+ "type": "string",
49
+ "pattern": "^(?!.*\\.d\\.ts$).*\\.ts$"
47
50
  }
48
51
  },
49
52
  "visibility": {
50
53
  "type": "array",
51
54
  "items": {
52
- "type": "string"
55
+ "type": "string",
56
+ "enum": ["public", "protected", "private"]
57
+ }
58
+ }
59
+ }
60
+ },
61
+ "swiftEntry": {
62
+ "type": "object",
63
+ "additionalProperties": false,
64
+ "required": ["patterns"],
65
+ "properties": {
66
+ "patterns": {
67
+ "type": "array",
68
+ "minItems": 1,
69
+ "items": {
70
+ "type": "string",
71
+ "pattern": "\\.swift$"
72
+ }
73
+ },
74
+ "visibility": {
75
+ "type": "array",
76
+ "items": {
77
+ "type": "string",
78
+ "enum": ["public", "open", "internal"]
79
+ }
80
+ }
81
+ }
82
+ },
83
+ "dartEntry": {
84
+ "type": "object",
85
+ "additionalProperties": false,
86
+ "required": ["patterns"],
87
+ "properties": {
88
+ "patterns": {
89
+ "type": "array",
90
+ "minItems": 1,
91
+ "items": {
92
+ "type": "string",
93
+ "pattern": "\\.dart$"
94
+ }
95
+ },
96
+ "visibility": {
97
+ "type": "array",
98
+ "items": {
99
+ "type": "string",
100
+ "enum": ["public"]
101
+ }
102
+ }
103
+ }
104
+ },
105
+ "rustEntry": {
106
+ "type": "object",
107
+ "additionalProperties": false,
108
+ "required": ["patterns"],
109
+ "properties": {
110
+ "patterns": {
111
+ "type": "array",
112
+ "minItems": 1,
113
+ "items": {
114
+ "type": "string",
115
+ "pattern": "\\.rs$"
116
+ }
117
+ },
118
+ "visibility": {
119
+ "type": "array",
120
+ "items": {
121
+ "type": "string",
122
+ "enum": ["pub", "private"]
53
123
  }
54
124
  }
55
125
  }