@cairn-tool/cairn 2.0.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.
- package/.markdownlintrc +7 -0
- package/LICENSE +21 -0
- package/README.md +1431 -0
- package/dist/agent/audit/baseline.d.ts +69 -0
- package/dist/agent/audit/baseline.js +128 -0
- package/dist/agent/audit/baseline.js.map +1 -0
- package/dist/agent/audit/index.d.ts +126 -0
- package/dist/agent/audit/index.js +625 -0
- package/dist/agent/audit/index.js.map +1 -0
- package/dist/agent/import/detect.d.ts +49 -0
- package/dist/agent/import/detect.js +159 -0
- package/dist/agent/import/detect.js.map +1 -0
- package/dist/agent/import/normalize.d.ts +72 -0
- package/dist/agent/import/normalize.js +475 -0
- package/dist/agent/import/normalize.js.map +1 -0
- package/dist/agent/install/index.d.ts +211 -0
- package/dist/agent/install/index.js +907 -0
- package/dist/agent/install/index.js.map +1 -0
- package/dist/agent/manifest.d.ts +75 -0
- package/dist/agent/manifest.js +210 -0
- package/dist/agent/manifest.js.map +1 -0
- package/dist/agent/marketplace/index.d.ts +69 -0
- package/dist/agent/marketplace/index.js +212 -0
- package/dist/agent/marketplace/index.js.map +1 -0
- package/dist/agent/marketplace/spec.d.ts +48 -0
- package/dist/agent/marketplace/spec.js +237 -0
- package/dist/agent/marketplace/spec.js.map +1 -0
- package/dist/agent/output.d.ts +36 -0
- package/dist/agent/output.js +56 -0
- package/dist/agent/output.js.map +1 -0
- package/dist/agent/overlays.d.ts +38 -0
- package/dist/agent/overlays.js +223 -0
- package/dist/agent/overlays.js.map +1 -0
- package/dist/agent/package/index.d.ts +105 -0
- package/dist/agent/package/index.js +339 -0
- package/dist/agent/package/index.js.map +1 -0
- package/dist/agent/package/tar.d.ts +36 -0
- package/dist/agent/package/tar.js +137 -0
- package/dist/agent/package/tar.js.map +1 -0
- package/dist/agent/parser.d.ts +13 -0
- package/dist/agent/parser.js +559 -0
- package/dist/agent/parser.js.map +1 -0
- package/dist/agent/render.d.ts +16 -0
- package/dist/agent/render.js +721 -0
- package/dist/agent/render.js.map +1 -0
- package/dist/agent/sarif.d.ts +18 -0
- package/dist/agent/sarif.js +56 -0
- package/dist/agent/sarif.js.map +1 -0
- package/dist/agent/scaffold.d.ts +86 -0
- package/dist/agent/scaffold.js +250 -0
- package/dist/agent/scaffold.js.map +1 -0
- package/dist/agent/targets/antigravity.d.ts +17 -0
- package/dist/agent/targets/antigravity.js +218 -0
- package/dist/agent/targets/antigravity.js.map +1 -0
- package/dist/agent/targets/claude-code.d.ts +2 -0
- package/dist/agent/targets/claude-code.js +220 -0
- package/dist/agent/targets/claude-code.js.map +1 -0
- package/dist/agent/targets/codex.d.ts +2 -0
- package/dist/agent/targets/codex.js +212 -0
- package/dist/agent/targets/codex.js.map +1 -0
- package/dist/agent/targets/cursor.d.ts +2 -0
- package/dist/agent/targets/cursor.js +210 -0
- package/dist/agent/targets/cursor.js.map +1 -0
- package/dist/agent/targets/index.d.ts +31 -0
- package/dist/agent/targets/index.js +64 -0
- package/dist/agent/targets/index.js.map +1 -0
- package/dist/agent/targets/opencode.d.ts +15 -0
- package/dist/agent/targets/opencode.js +215 -0
- package/dist/agent/targets/opencode.js.map +1 -0
- package/dist/agent/targets/schema.d.ts +315 -0
- package/dist/agent/targets/schema.js +179 -0
- package/dist/agent/targets/schema.js.map +1 -0
- package/dist/agent/test/assert.d.ts +46 -0
- package/dist/agent/test/assert.js +288 -0
- package/dist/agent/test/assert.js.map +1 -0
- package/dist/agent/test/index.d.ts +73 -0
- package/dist/agent/test/index.js +181 -0
- package/dist/agent/test/index.js.map +1 -0
- package/dist/agent/test/schema.d.ts +81 -0
- package/dist/agent/test/schema.js +235 -0
- package/dist/agent/test/schema.js.map +1 -0
- package/dist/agent/types.d.ts +204 -0
- package/dist/agent/types.js +11 -0
- package/dist/agent/types.js.map +1 -0
- package/dist/agent/upgrade.d.ts +29 -0
- package/dist/agent/upgrade.js +72 -0
- package/dist/agent/upgrade.js.map +1 -0
- package/dist/agent/writer.d.ts +30 -0
- package/dist/agent/writer.js +73 -0
- package/dist/agent/writer.js.map +1 -0
- package/dist/archive/db.d.ts +20 -0
- package/dist/archive/db.js +98 -0
- package/dist/archive/db.js.map +1 -0
- package/dist/archive/progress.d.ts +62 -0
- package/dist/archive/progress.js +151 -0
- package/dist/archive/progress.js.map +1 -0
- package/dist/archive/query.d.ts +86 -0
- package/dist/archive/query.js +241 -0
- package/dist/archive/query.js.map +1 -0
- package/dist/archive/run.d.ts +91 -0
- package/dist/archive/run.js +331 -0
- package/dist/archive/run.js.map +1 -0
- package/dist/archive/segments.d.ts +89 -0
- package/dist/archive/segments.js +144 -0
- package/dist/archive/segments.js.map +1 -0
- package/dist/archive/sets.d.ts +58 -0
- package/dist/archive/sets.js +344 -0
- package/dist/archive/sets.js.map +1 -0
- package/dist/archive/tar-read.d.ts +35 -0
- package/dist/archive/tar-read.js +90 -0
- package/dist/archive/tar-read.js.map +1 -0
- package/dist/audit-baseline.d.ts +66 -0
- package/dist/audit-baseline.js +124 -0
- package/dist/audit-baseline.js.map +1 -0
- package/dist/automation.d.ts +16 -0
- package/dist/automation.js +38 -0
- package/dist/automation.js.map +1 -0
- package/dist/backlinks.d.ts +15 -0
- package/dist/backlinks.js +30 -0
- package/dist/backlinks.js.map +1 -0
- package/dist/checkers/katex.d.ts +3 -0
- package/dist/checkers/katex.js +71 -0
- package/dist/checkers/katex.js.map +1 -0
- package/dist/checkers/markdown-lint.d.ts +28 -0
- package/dist/checkers/markdown-lint.js +53 -0
- package/dist/checkers/markdown-lint.js.map +1 -0
- package/dist/checkers/mermaid.d.ts +6 -0
- package/dist/checkers/mermaid.js +53 -0
- package/dist/checkers/mermaid.js.map +1 -0
- package/dist/checkers/references.d.ts +3 -0
- package/dist/checkers/references.js +55 -0
- package/dist/checkers/references.js.map +1 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +1117 -0
- package/dist/cli.js.map +1 -0
- package/dist/command-result.d.ts +6 -0
- package/dist/command-result.js +13 -0
- package/dist/command-result.js.map +1 -0
- package/dist/commands/agent-audit.d.ts +21 -0
- package/dist/commands/agent-audit.js +119 -0
- package/dist/commands/agent-audit.js.map +1 -0
- package/dist/commands/agent-doctor.d.ts +25 -0
- package/dist/commands/agent-doctor.js +217 -0
- package/dist/commands/agent-doctor.js.map +1 -0
- package/dist/commands/agent-import.d.ts +21 -0
- package/dist/commands/agent-import.js +212 -0
- package/dist/commands/agent-import.js.map +1 -0
- package/dist/commands/agent-install.d.ts +18 -0
- package/dist/commands/agent-install.js +59 -0
- package/dist/commands/agent-install.js.map +1 -0
- package/dist/commands/agent-installed.d.ts +6 -0
- package/dist/commands/agent-installed.js +17 -0
- package/dist/commands/agent-installed.js.map +1 -0
- package/dist/commands/agent-marketplace.d.ts +11 -0
- package/dist/commands/agent-marketplace.js +178 -0
- package/dist/commands/agent-marketplace.js.map +1 -0
- package/dist/commands/agent-package.d.ts +16 -0
- package/dist/commands/agent-package.js +159 -0
- package/dist/commands/agent-package.js.map +1 -0
- package/dist/commands/agent-scaffold.d.ts +17 -0
- package/dist/commands/agent-scaffold.js +181 -0
- package/dist/commands/agent-scaffold.js.map +1 -0
- package/dist/commands/agent-specs.d.ts +7 -0
- package/dist/commands/agent-specs.js +20 -0
- package/dist/commands/agent-specs.js.map +1 -0
- package/dist/commands/agent-test.d.ts +21 -0
- package/dist/commands/agent-test.js +50 -0
- package/dist/commands/agent-test.js.map +1 -0
- package/dist/commands/agent-uninstall.d.ts +6 -0
- package/dist/commands/agent-uninstall.js +45 -0
- package/dist/commands/agent-uninstall.js.map +1 -0
- package/dist/commands/agent-upgrade.d.ts +5 -0
- package/dist/commands/agent-upgrade.js +105 -0
- package/dist/commands/agent-upgrade.js.map +1 -0
- package/dist/commands/agent.d.ts +27 -0
- package/dist/commands/agent.js +549 -0
- package/dist/commands/agent.js.map +1 -0
- package/dist/commands/archive.d.ts +47 -0
- package/dist/commands/archive.js +311 -0
- package/dist/commands/archive.js.map +1 -0
- package/dist/commands/audit.d.ts +25 -0
- package/dist/commands/audit.js +325 -0
- package/dist/commands/audit.js.map +1 -0
- package/dist/commands/check-snippets.d.ts +58 -0
- package/dist/commands/check-snippets.js +247 -0
- package/dist/commands/check-snippets.js.map +1 -0
- package/dist/commands/check-urls.d.ts +52 -0
- package/dist/commands/check-urls.js +205 -0
- package/dist/commands/check-urls.js.map +1 -0
- package/dist/commands/code-blocks.d.ts +8 -0
- package/dist/commands/code-blocks.js +66 -0
- package/dist/commands/code-blocks.js.map +1 -0
- package/dist/commands/completion.d.ts +15 -0
- package/dist/commands/completion.js +20 -0
- package/dist/commands/completion.js.map +1 -0
- package/dist/commands/context.d.ts +16 -0
- package/dist/commands/context.js +131 -0
- package/dist/commands/context.js.map +1 -0
- package/dist/commands/describe.d.ts +12 -0
- package/dist/commands/describe.js +62 -0
- package/dist/commands/describe.js.map +1 -0
- package/dist/commands/diff.d.ts +11 -0
- package/dist/commands/diff.js +185 -0
- package/dist/commands/diff.js.map +1 -0
- package/dist/commands/fix.d.ts +59 -0
- package/dist/commands/fix.js +173 -0
- package/dist/commands/fix.js.map +1 -0
- package/dist/commands/frontmatter.d.ts +7 -0
- package/dist/commands/frontmatter.js +84 -0
- package/dist/commands/frontmatter.js.map +1 -0
- package/dist/commands/graph.d.ts +12 -0
- package/dist/commands/graph.js +122 -0
- package/dist/commands/graph.js.map +1 -0
- package/dist/commands/headers.d.ts +7 -0
- package/dist/commands/headers.js +48 -0
- package/dist/commands/headers.js.map +1 -0
- package/dist/commands/index.d.ts +8 -0
- package/dist/commands/index.js +32 -0
- package/dist/commands/index.js.map +1 -0
- package/dist/commands/links.d.ts +9 -0
- package/dist/commands/links.js +123 -0
- package/dist/commands/links.js.map +1 -0
- package/dist/commands/lint-dir.d.ts +15 -0
- package/dist/commands/lint-dir.js +156 -0
- package/dist/commands/lint-dir.js.map +1 -0
- package/dist/commands/lint.d.ts +14 -0
- package/dist/commands/lint.js +45 -0
- package/dist/commands/lint.js.map +1 -0
- package/dist/commands/orphans.d.ts +10 -0
- package/dist/commands/orphans.js +74 -0
- package/dist/commands/orphans.js.map +1 -0
- package/dist/commands/outline.d.ts +7 -0
- package/dist/commands/outline.js +54 -0
- package/dist/commands/outline.js.map +1 -0
- package/dist/commands/query.d.ts +18 -0
- package/dist/commands/query.js +341 -0
- package/dist/commands/query.js.map +1 -0
- package/dist/commands/refs-to.d.ts +8 -0
- package/dist/commands/refs-to.js +65 -0
- package/dist/commands/refs-to.js.map +1 -0
- package/dist/commands/refs.d.ts +10 -0
- package/dist/commands/refs.js +103 -0
- package/dist/commands/refs.js.map +1 -0
- package/dist/commands/rename-file.d.ts +16 -0
- package/dist/commands/rename-file.js +215 -0
- package/dist/commands/rename-file.js.map +1 -0
- package/dist/commands/rename-heading.d.ts +10 -0
- package/dist/commands/rename-heading.js +182 -0
- package/dist/commands/rename-heading.js.map +1 -0
- package/dist/commands/schema.d.ts +10 -0
- package/dist/commands/schema.js +34 -0
- package/dist/commands/schema.js.map +1 -0
- package/dist/commands/scripts.d.ts +59 -0
- package/dist/commands/scripts.js +222 -0
- package/dist/commands/scripts.js.map +1 -0
- package/dist/commands/section.d.ts +9 -0
- package/dist/commands/section.js +49 -0
- package/dist/commands/section.js.map +1 -0
- package/dist/commands/serve.d.ts +6 -0
- package/dist/commands/serve.js +48 -0
- package/dist/commands/serve.js.map +1 -0
- package/dist/commands/stats.d.ts +6 -0
- package/dist/commands/stats.js +109 -0
- package/dist/commands/stats.js.map +1 -0
- package/dist/commands/structure.d.ts +6 -0
- package/dist/commands/structure.js +130 -0
- package/dist/commands/structure.js.map +1 -0
- package/dist/commands/tables.d.ts +8 -0
- package/dist/commands/tables.js +77 -0
- package/dist/commands/tables.js.map +1 -0
- package/dist/commands/tasks.d.ts +8 -0
- package/dist/commands/tasks.js +59 -0
- package/dist/commands/tasks.js.map +1 -0
- package/dist/commands/toc.d.ts +18 -0
- package/dist/commands/toc.js +105 -0
- package/dist/commands/toc.js.map +1 -0
- package/dist/commands/update-check.d.ts +36 -0
- package/dist/commands/update-check.js +119 -0
- package/dist/commands/update-check.js.map +1 -0
- package/dist/commands/usage.d.ts +56 -0
- package/dist/commands/usage.js +883 -0
- package/dist/commands/usage.js.map +1 -0
- package/dist/commands/validate-frontmatter.d.ts +13 -0
- package/dist/commands/validate-frontmatter.js +34 -0
- package/dist/commands/validate-frontmatter.js.map +1 -0
- package/dist/completion/model.d.ts +49 -0
- package/dist/completion/model.js +194 -0
- package/dist/completion/model.js.map +1 -0
- package/dist/completion/shells.d.ts +2 -0
- package/dist/completion/shells.js +280 -0
- package/dist/completion/shells.js.map +1 -0
- package/dist/config-schema.d.ts +15 -0
- package/dist/config-schema.js +44 -0
- package/dist/config-schema.js.map +1 -0
- package/dist/config.d.ts +102 -0
- package/dist/config.js +614 -0
- package/dist/config.js.map +1 -0
- package/dist/context.d.ts +106 -0
- package/dist/context.js +202 -0
- package/dist/context.js.map +1 -0
- package/dist/contract/describe.d.ts +84 -0
- package/dist/contract/describe.js +104 -0
- package/dist/contract/describe.js.map +1 -0
- package/dist/contract/registry.d.ts +2 -0
- package/dist/contract/registry.js +622 -0
- package/dist/contract/registry.js.map +1 -0
- package/dist/contract/schemas/agent.d.ts +2 -0
- package/dist/contract/schemas/agent.js +572 -0
- package/dist/contract/schemas/agent.js.map +1 -0
- package/dist/contract/schemas/archive.d.ts +3 -0
- package/dist/contract/schemas/archive.js +227 -0
- package/dist/contract/schemas/archive.js.map +1 -0
- package/dist/contract/schemas/index.d.ts +11 -0
- package/dist/contract/schemas/index.js +49 -0
- package/dist/contract/schemas/index.js.map +1 -0
- package/dist/contract/schemas/markdown.d.ts +15 -0
- package/dist/contract/schemas/markdown.js +1035 -0
- package/dist/contract/schemas/markdown.js.map +1 -0
- package/dist/contract/schemas/meta.d.ts +5 -0
- package/dist/contract/schemas/meta.js +233 -0
- package/dist/contract/schemas/meta.js.map +1 -0
- package/dist/contract/schemas/scripts.d.ts +4 -0
- package/dist/contract/schemas/scripts.js +183 -0
- package/dist/contract/schemas/scripts.js.map +1 -0
- package/dist/contract/schemas/shared.d.ts +11 -0
- package/dist/contract/schemas/shared.js +26 -0
- package/dist/contract/schemas/shared.js.map +1 -0
- package/dist/contract/schemas/usage.d.ts +6 -0
- package/dist/contract/schemas/usage.js +489 -0
- package/dist/contract/schemas/usage.js.map +1 -0
- package/dist/contract/types.d.ts +63 -0
- package/dist/contract/types.js +2 -0
- package/dist/contract/types.js.map +1 -0
- package/dist/contract/version.d.ts +20 -0
- package/dist/contract/version.js +21 -0
- package/dist/contract/version.js.map +1 -0
- package/dist/diff.d.ts +156 -0
- package/dist/diff.js +500 -0
- package/dist/diff.js.map +1 -0
- package/dist/edit-plan.d.ts +133 -0
- package/dist/edit-plan.js +245 -0
- package/dist/edit-plan.js.map +1 -0
- package/dist/fix/markdownlint-fixer.d.ts +34 -0
- package/dist/fix/markdownlint-fixer.js +125 -0
- package/dist/fix/markdownlint-fixer.js.map +1 -0
- package/dist/fix/registry.d.ts +48 -0
- package/dist/fix/registry.js +28 -0
- package/dist/fix/registry.js.map +1 -0
- package/dist/fix/relative-links-fixer.d.ts +21 -0
- package/dist/fix/relative-links-fixer.js +96 -0
- package/dist/fix/relative-links-fixer.js.map +1 -0
- package/dist/fix/snippets-fixer.d.ts +2 -0
- package/dist/fix/snippets-fixer.js +64 -0
- package/dist/fix/snippets-fixer.js.map +1 -0
- package/dist/fix/toc-fixer.d.ts +2 -0
- package/dist/fix/toc-fixer.js +94 -0
- package/dist/fix/toc-fixer.js.map +1 -0
- package/dist/formats.d.ts +22 -0
- package/dist/formats.js +34 -0
- package/dist/formats.js.map +1 -0
- package/dist/formatters.d.ts +11 -0
- package/dist/formatters.js +48 -0
- package/dist/formatters.js.map +1 -0
- package/dist/frontmatter-validation.d.ts +11 -0
- package/dist/frontmatter-validation.js +188 -0
- package/dist/frontmatter-validation.js.map +1 -0
- package/dist/git.d.ts +40 -0
- package/dist/git.js +124 -0
- package/dist/git.js.map +1 -0
- package/dist/graph.d.ts +50 -0
- package/dist/graph.js +200 -0
- package/dist/graph.js.map +1 -0
- package/dist/input-selection.d.ts +9 -0
- package/dist/input-selection.js +122 -0
- package/dist/input-selection.js.map +1 -0
- package/dist/input.d.ts +2 -0
- package/dist/input.js +32 -0
- package/dist/input.js.map +1 -0
- package/dist/link-target.d.ts +39 -0
- package/dist/link-target.js +68 -0
- package/dist/link-target.js.map +1 -0
- package/dist/lint.d.ts +13 -0
- package/dist/lint.js +27 -0
- package/dist/lint.js.map +1 -0
- package/dist/markdown-ast.d.ts +73 -0
- package/dist/markdown-ast.js +187 -0
- package/dist/markdown-ast.js.map +1 -0
- package/dist/object-path.d.ts +14 -0
- package/dist/object-path.js +14 -0
- package/dist/object-path.js.map +1 -0
- package/dist/option-utils.d.ts +13 -0
- package/dist/option-utils.js +25 -0
- package/dist/option-utils.js.map +1 -0
- package/dist/outline.d.ts +16 -0
- package/dist/outline.js +32 -0
- package/dist/outline.js.map +1 -0
- package/dist/query/entities.d.ts +60 -0
- package/dist/query/entities.js +219 -0
- package/dist/query/entities.js.map +1 -0
- package/dist/query/execute.d.ts +22 -0
- package/dist/query/execute.js +0 -0
- package/dist/query/execute.js.map +1 -0
- package/dist/query/plan.d.ts +76 -0
- package/dist/query/plan.js +183 -0
- package/dist/query/plan.js.map +1 -0
- package/dist/query/render.d.ts +3 -0
- package/dist/query/render.js +39 -0
- package/dist/query/render.js.map +1 -0
- package/dist/refs.d.ts +19 -0
- package/dist/refs.js +10 -0
- package/dist/refs.js.map +1 -0
- package/dist/result.d.ts +49 -0
- package/dist/result.js +47 -0
- package/dist/result.js.map +1 -0
- package/dist/runtime.d.ts +35 -0
- package/dist/runtime.js +77 -0
- package/dist/runtime.js.map +1 -0
- package/dist/sarif.d.ts +36 -0
- package/dist/sarif.js +30 -0
- package/dist/sarif.js.map +1 -0
- package/dist/scripts/execute.d.ts +65 -0
- package/dist/scripts/execute.js +235 -0
- package/dist/scripts/execute.js.map +1 -0
- package/dist/scripts/registry.d.ts +55 -0
- package/dist/scripts/registry.js +103 -0
- package/dist/scripts/registry.js.map +1 -0
- package/dist/scripts/resolve.d.ts +90 -0
- package/dist/scripts/resolve.js +288 -0
- package/dist/scripts/resolve.js.map +1 -0
- package/dist/sections.d.ts +53 -0
- package/dist/sections.js +100 -0
- package/dist/sections.js.map +1 -0
- package/dist/serve/errors.d.ts +25 -0
- package/dist/serve/errors.js +45 -0
- package/dist/serve/errors.js.map +1 -0
- package/dist/serve/paths.d.ts +32 -0
- package/dist/serve/paths.js +71 -0
- package/dist/serve/paths.js.map +1 -0
- package/dist/serve/server.d.ts +31 -0
- package/dist/serve/server.js +123 -0
- package/dist/serve/server.js.map +1 -0
- package/dist/serve/tools.d.ts +19 -0
- package/dist/serve/tools.js +597 -0
- package/dist/serve/tools.js.map +1 -0
- package/dist/snippets.d.ts +184 -0
- package/dist/snippets.js +454 -0
- package/dist/snippets.js.map +1 -0
- package/dist/sqlite-store.d.ts +62 -0
- package/dist/sqlite-store.js +104 -0
- package/dist/sqlite-store.js.map +1 -0
- package/dist/sqlite.d.ts +59 -0
- package/dist/sqlite.js +51 -0
- package/dist/sqlite.js.map +1 -0
- package/dist/toc.d.ts +58 -0
- package/dist/toc.js +83 -0
- package/dist/toc.js.map +1 -0
- package/dist/types.d.ts +7 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/update-notifier.d.ts +95 -0
- package/dist/update-notifier.js +301 -0
- package/dist/update-notifier.js.map +1 -0
- package/dist/url-cache.d.ts +14 -0
- package/dist/url-cache.js +70 -0
- package/dist/url-cache.js.map +1 -0
- package/dist/usage/aggregate.d.ts +107 -0
- package/dist/usage/aggregate.js +435 -0
- package/dist/usage/aggregate.js.map +1 -0
- package/dist/usage/db/index.d.ts +49 -0
- package/dist/usage/db/index.js +118 -0
- package/dist/usage/db/index.js.map +1 -0
- package/dist/usage/db/migrations.d.ts +29 -0
- package/dist/usage/db/migrations.js +38 -0
- package/dist/usage/db/migrations.js.map +1 -0
- package/dist/usage/db/open.d.ts +33 -0
- package/dist/usage/db/open.js +37 -0
- package/dist/usage/db/open.js.map +1 -0
- package/dist/usage/db/schema.d.ts +18 -0
- package/dist/usage/db/schema.js +147 -0
- package/dist/usage/db/schema.js.map +1 -0
- package/dist/usage/db/store.d.ts +74 -0
- package/dist/usage/db/store.js +280 -0
- package/dist/usage/db/store.js.map +1 -0
- package/dist/usage/events.d.ts +202 -0
- package/dist/usage/events.js +243 -0
- package/dist/usage/events.js.map +1 -0
- package/dist/usage/filter.d.ts +43 -0
- package/dist/usage/filter.js +97 -0
- package/dist/usage/filter.js.map +1 -0
- package/dist/usage/providers/antigravity.d.ts +2 -0
- package/dist/usage/providers/antigravity.js +431 -0
- package/dist/usage/providers/antigravity.js.map +1 -0
- package/dist/usage/providers/claude-code.d.ts +2 -0
- package/dist/usage/providers/claude-code.js +400 -0
- package/dist/usage/providers/claude-code.js.map +1 -0
- package/dist/usage/providers/codex.d.ts +2 -0
- package/dist/usage/providers/codex.js +387 -0
- package/dist/usage/providers/codex.js.map +1 -0
- package/dist/usage/providers/gemini-cli.d.ts +2 -0
- package/dist/usage/providers/gemini-cli.js +466 -0
- package/dist/usage/providers/gemini-cli.js.map +1 -0
- package/dist/usage/providers/index.d.ts +23 -0
- package/dist/usage/providers/index.js +46 -0
- package/dist/usage/providers/index.js.map +1 -0
- package/dist/usage/providers/opencode.d.ts +2 -0
- package/dist/usage/providers/opencode.js +422 -0
- package/dist/usage/providers/opencode.js.map +1 -0
- package/dist/usage/providers/protobuf.d.ts +35 -0
- package/dist/usage/providers/protobuf.js +125 -0
- package/dist/usage/providers/protobuf.js.map +1 -0
- package/dist/usage/providers/types.d.ts +74 -0
- package/dist/usage/providers/types.js +2 -0
- package/dist/usage/providers/types.js.map +1 -0
- package/dist/usage/scan.d.ts +54 -0
- package/dist/usage/scan.js +216 -0
- package/dist/usage/scan.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +8 -0
- package/dist/version.js.map +1 -0
- package/dist/workspace-index.d.ts +39 -0
- package/dist/workspace-index.js +265 -0
- package/dist/workspace-index.js.map +1 -0
- package/dist/workspace.d.ts +89 -0
- package/dist/workspace.js +219 -0
- package/dist/workspace.js.map +1 -0
- package/package.json +92 -0
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { parse as parseYaml } from "yaml";
|
|
4
|
+
import { configIn, findConfig } from "../config.js";
|
|
5
|
+
import { isInside, object } from "../config-schema.js";
|
|
6
|
+
import { repositoryFor } from "../git.js";
|
|
7
|
+
import { emptyRegistry, parseScriptsBlock } from "./registry.js";
|
|
8
|
+
/**
|
|
9
|
+
* Resolves a script name to the definition that wins for a given working
|
|
10
|
+
* directory.
|
|
11
|
+
*
|
|
12
|
+
* The walk here is deliberately not `findConfig`, which returns the nearest
|
|
13
|
+
* `.cairn.yml` and stops. A nested configuration that exists but does not
|
|
14
|
+
* define the requested name must not shadow an ancestor that does, so every file
|
|
15
|
+
* from the invocation directory up to the boundary is consulted and the nearest
|
|
16
|
+
* *definition of the name* wins.
|
|
17
|
+
*/
|
|
18
|
+
/** A registry file larger than this is not one anybody wrote by hand. */
|
|
19
|
+
const MAX_REGISTRY_BYTES = 1024 * 1024;
|
|
20
|
+
/** Enough of the head to catch a binary file mistakenly named `.cairn.yml`. */
|
|
21
|
+
const NUL_PROBE_BYTES = 8 * 1024;
|
|
22
|
+
/** Byte comparison; never `localeCompare`, which is ICU-build dependent. */
|
|
23
|
+
function byteOrder(left, right) {
|
|
24
|
+
return left < right ? -1 : left > right ? 1 : 0;
|
|
25
|
+
}
|
|
26
|
+
function realpath(target) {
|
|
27
|
+
try {
|
|
28
|
+
return fs.realpathSync(target);
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return path.resolve(target);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function hasNodeModules(directory) {
|
|
35
|
+
return directory.split(path.sep).includes("node_modules");
|
|
36
|
+
}
|
|
37
|
+
export function resolveBoundary(options = {}) {
|
|
38
|
+
const invokedFrom = realpath(path.resolve(options.cwd ?? process.cwd()));
|
|
39
|
+
const selection = options.selection;
|
|
40
|
+
if (selection?.disabled)
|
|
41
|
+
return { directory: invokedFrom, kind: "disabled" };
|
|
42
|
+
if (selection?.explicitPath) {
|
|
43
|
+
return { directory: path.dirname(realpath(selection.explicitPath)), kind: "single-config" };
|
|
44
|
+
}
|
|
45
|
+
const candidates = [];
|
|
46
|
+
if (options.root) {
|
|
47
|
+
const root = realpath(path.resolve(options.root));
|
|
48
|
+
if (!isInside(root, invokedFrom)) {
|
|
49
|
+
throw new Error(`--root is not an ancestor of the working directory: ${options.root}`);
|
|
50
|
+
}
|
|
51
|
+
candidates.push({ directory: root, kind: "explicit-root" });
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
candidates.push({ directory: repositoryFor(invokedFrom).root, kind: "git-root" });
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
// Not a repository, or git is not on PATH. Both are ordinary here.
|
|
58
|
+
}
|
|
59
|
+
if (candidates.length > 0) {
|
|
60
|
+
// The deeper of the two stops the walk sooner, so it is the safer reading of
|
|
61
|
+
// "whichever is found first" while ascending.
|
|
62
|
+
return candidates.reduce((deepest, candidate) => candidate.directory.length > deepest.directory.length ? candidate : deepest);
|
|
63
|
+
}
|
|
64
|
+
const nearest = findConfig(invokedFrom);
|
|
65
|
+
return {
|
|
66
|
+
directory: nearest ? path.dirname(realpath(nearest)) : invokedFrom,
|
|
67
|
+
kind: "nearest-config",
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Reads one candidate registry file.
|
|
72
|
+
*
|
|
73
|
+
* The guards mirror `readSnippetSource` in `src/snippets.ts`: realpath first,
|
|
74
|
+
* then containment, then a regular-file check — a FIFO would block the read
|
|
75
|
+
* forever and wedge a hook with no output — then a size cap and a NUL probe.
|
|
76
|
+
*/
|
|
77
|
+
function readRegistry(file, boundary, distance) {
|
|
78
|
+
const directory = path.dirname(file);
|
|
79
|
+
const base = { file, directory, distance, status: "skipped", names: [] };
|
|
80
|
+
let real;
|
|
81
|
+
try {
|
|
82
|
+
real = fs.realpathSync(file);
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
return { consulted: { ...base, reason: "Unreadable" } };
|
|
86
|
+
}
|
|
87
|
+
if (!isInside(boundary, real)) {
|
|
88
|
+
return { consulted: { ...base, reason: "Resolves outside the boundary" } };
|
|
89
|
+
}
|
|
90
|
+
let stat;
|
|
91
|
+
try {
|
|
92
|
+
stat = fs.lstatSync(real);
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
return { consulted: { ...base, reason: "Unreadable" } };
|
|
96
|
+
}
|
|
97
|
+
if (!stat.isFile()) {
|
|
98
|
+
return { consulted: { ...base, reason: "Not a regular file" } };
|
|
99
|
+
}
|
|
100
|
+
if (stat.size > MAX_REGISTRY_BYTES) {
|
|
101
|
+
return { consulted: { ...base, reason: `Larger than ${MAX_REGISTRY_BYTES} bytes` } };
|
|
102
|
+
}
|
|
103
|
+
let contents;
|
|
104
|
+
try {
|
|
105
|
+
const buffer = fs.readFileSync(real);
|
|
106
|
+
if (buffer.subarray(0, NUL_PROBE_BYTES).includes(0)) {
|
|
107
|
+
return { consulted: { ...base, reason: "Not a text file" } };
|
|
108
|
+
}
|
|
109
|
+
contents = buffer.toString("utf-8");
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
return { consulted: { ...base, reason: "Unreadable" } };
|
|
113
|
+
}
|
|
114
|
+
let registry;
|
|
115
|
+
try {
|
|
116
|
+
const parsed = object(parseYaml(contents), "configuration");
|
|
117
|
+
if (parsed.scripts === undefined) {
|
|
118
|
+
return {
|
|
119
|
+
consulted: { ...base, status: "no-scripts" },
|
|
120
|
+
registry: emptyRegistry(file, directory),
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
registry = parseScriptsBlock(parsed.scripts, { file, directory });
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
const reason = error.message.split("\n")[0];
|
|
127
|
+
return { consulted: { ...base, status: "invalid", reason } };
|
|
128
|
+
}
|
|
129
|
+
const names = [...registry.scripts.keys()].sort(byteOrder);
|
|
130
|
+
return { consulted: { ...base, status: "declares", names }, registry };
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Walks from the invocation directory to the boundary, inclusive, nearest first.
|
|
134
|
+
*
|
|
135
|
+
* Only the `scripts:` block of each file is validated. An ancestor belongs to a
|
|
136
|
+
* different project, and a malformed `urls:` block there is none of this
|
|
137
|
+
* command's business — failing on it would make one broken package configuration
|
|
138
|
+
* break `scripts run` for every sibling.
|
|
139
|
+
*/
|
|
140
|
+
function walk(boundary, options) {
|
|
141
|
+
if (boundary.kind === "disabled")
|
|
142
|
+
return [];
|
|
143
|
+
if (boundary.kind === "single-config") {
|
|
144
|
+
const file = realpath(options.selection?.explicitPath ?? "");
|
|
145
|
+
if (!fs.existsSync(file)) {
|
|
146
|
+
throw new Error(`Configuration file not found: ${options.selection?.explicitPath}`);
|
|
147
|
+
}
|
|
148
|
+
return [readRegistry(file, boundary.directory, 0)];
|
|
149
|
+
}
|
|
150
|
+
const invokedFrom = realpath(path.resolve(options.cwd ?? process.cwd()));
|
|
151
|
+
const steps = [];
|
|
152
|
+
let current = invokedFrom;
|
|
153
|
+
let distance = 0;
|
|
154
|
+
while (true) {
|
|
155
|
+
// A vendored package that ships a `.cairn.yml` would otherwise win over
|
|
156
|
+
// the project's own registry for any invocation inside it.
|
|
157
|
+
if (!hasNodeModules(current)) {
|
|
158
|
+
// `configIn` stops at the first name it finds, so a directory holding both
|
|
159
|
+
// the current and the legacy filename contributes one step rather than two
|
|
160
|
+
// — the legacy file must not read as a registry the new one shadows.
|
|
161
|
+
const candidate = configIn(current);
|
|
162
|
+
if (candidate)
|
|
163
|
+
steps.push(readRegistry(candidate, boundary.directory, distance));
|
|
164
|
+
}
|
|
165
|
+
if (current === boundary.directory)
|
|
166
|
+
break;
|
|
167
|
+
const parent = path.dirname(current);
|
|
168
|
+
if (parent === current)
|
|
169
|
+
break;
|
|
170
|
+
current = parent;
|
|
171
|
+
distance++;
|
|
172
|
+
}
|
|
173
|
+
return steps;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* The directory a script runs in.
|
|
177
|
+
*
|
|
178
|
+
* Containment is checked on the *resolved* directory, not on the spelling: `cwd`
|
|
179
|
+
* decides where the script's own relative paths land, which makes it the more
|
|
180
|
+
* attractive escape of the two paths this module resolves.
|
|
181
|
+
*/
|
|
182
|
+
function workingDirectoryFor(definition, registry, invokedFrom, boundary) {
|
|
183
|
+
const target = definition.cwd.kind === "registry"
|
|
184
|
+
? registry.directory
|
|
185
|
+
: definition.cwd.kind === "invocation"
|
|
186
|
+
? invokedFrom
|
|
187
|
+
: path.resolve(registry.directory, definition.cwd.value);
|
|
188
|
+
const resolved = realpath(target);
|
|
189
|
+
if (boundary.kind !== "disabled" && !isInside(boundary.directory, resolved)) {
|
|
190
|
+
throw new Error(`Script '${definition.name}' resolves a working directory outside the boundary: ${resolved}`);
|
|
191
|
+
}
|
|
192
|
+
if (!fs.existsSync(resolved) || !fs.statSync(resolved).isDirectory()) {
|
|
193
|
+
throw new Error(`Script '${definition.name}' has a working directory that does not exist: ${resolved}`);
|
|
194
|
+
}
|
|
195
|
+
return resolved;
|
|
196
|
+
}
|
|
197
|
+
export function resolveScript(name, options = {}) {
|
|
198
|
+
const invokedFrom = realpath(path.resolve(options.cwd ?? process.cwd()));
|
|
199
|
+
const boundary = resolveBoundary(options);
|
|
200
|
+
const steps = walk(boundary, options);
|
|
201
|
+
const consulted = [];
|
|
202
|
+
const definitions = [];
|
|
203
|
+
for (const step of steps) {
|
|
204
|
+
const declares = step.registry?.scripts.has(name) ?? false;
|
|
205
|
+
consulted.push(declares ? { ...step.consulted, status: "defines" } : step.consulted);
|
|
206
|
+
if (declares && step.registry) {
|
|
207
|
+
definitions.push({ definition: step.registry.scripts.get(name), registry: step.registry });
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
const resolution = {
|
|
211
|
+
name,
|
|
212
|
+
boundary,
|
|
213
|
+
invokedFrom,
|
|
214
|
+
consulted,
|
|
215
|
+
shadowed: definitions.slice(1).map(({ registry, definition }) => ({
|
|
216
|
+
file: registry.file,
|
|
217
|
+
directory: registry.directory,
|
|
218
|
+
...(definition.description ? { description: definition.description } : {}),
|
|
219
|
+
})),
|
|
220
|
+
};
|
|
221
|
+
const nearest = definitions[0];
|
|
222
|
+
if (nearest) {
|
|
223
|
+
resolution.winner = {
|
|
224
|
+
definition: nearest.definition,
|
|
225
|
+
registry: nearest.registry,
|
|
226
|
+
workingDirectory: workingDirectoryFor(nearest.definition, nearest.registry, invokedFrom, boundary),
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
return resolution;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* The first invalid file that could have changed the answer, if any.
|
|
233
|
+
*
|
|
234
|
+
* A file farther from the invocation directory than the winner cannot have won,
|
|
235
|
+
* so it must not break the run. A nearer one might have defined the name, and
|
|
236
|
+
* running the wrong script is precisely the failure this design exists to
|
|
237
|
+
* prevent.
|
|
238
|
+
*/
|
|
239
|
+
export function shadowingFailure(resolution) {
|
|
240
|
+
const winnerDistance = resolution.consulted.find((file) => file.status === "defines")?.distance;
|
|
241
|
+
return resolution.consulted.find((file) => file.status === "invalid" && (winnerDistance === undefined || file.distance < winnerDistance));
|
|
242
|
+
}
|
|
243
|
+
export function listScripts(options = {}) {
|
|
244
|
+
const invokedFrom = realpath(path.resolve(options.cwd ?? process.cwd()));
|
|
245
|
+
const boundary = resolveBoundary(options);
|
|
246
|
+
const steps = walk(boundary, options);
|
|
247
|
+
const entries = new Map();
|
|
248
|
+
for (const step of steps) {
|
|
249
|
+
if (!step.registry)
|
|
250
|
+
continue;
|
|
251
|
+
for (const [name, definition] of step.registry.scripts) {
|
|
252
|
+
const existing = entries.get(name);
|
|
253
|
+
if (existing) {
|
|
254
|
+
// Nearest wins; a farther definition only records that it was shadowed.
|
|
255
|
+
existing.shadows.push(step.registry.file);
|
|
256
|
+
continue;
|
|
257
|
+
}
|
|
258
|
+
let workingDirectory;
|
|
259
|
+
try {
|
|
260
|
+
workingDirectory = workingDirectoryFor(definition, step.registry, invokedFrom, boundary);
|
|
261
|
+
}
|
|
262
|
+
catch {
|
|
263
|
+
// `list` reports what is declared; a bad `cwd` is `run`'s problem to
|
|
264
|
+
// refuse, and hiding the entry here would make it harder to diagnose.
|
|
265
|
+
workingDirectory = step.registry.directory;
|
|
266
|
+
}
|
|
267
|
+
entries.set(name, {
|
|
268
|
+
name,
|
|
269
|
+
...(definition.description ? { description: definition.description } : {}),
|
|
270
|
+
form: definition.run !== undefined ? "run" : "exec",
|
|
271
|
+
...(definition.run !== undefined ? { run: definition.run } : {}),
|
|
272
|
+
...(definition.exec !== undefined ? { exec: definition.exec } : {}),
|
|
273
|
+
...(definition.shell !== undefined ? { shell: definition.shell } : {}),
|
|
274
|
+
file: step.registry.file,
|
|
275
|
+
directory: step.registry.directory,
|
|
276
|
+
workingDirectory,
|
|
277
|
+
shadows: [],
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
return {
|
|
282
|
+
boundary,
|
|
283
|
+
invokedFrom,
|
|
284
|
+
consulted: steps.map((step) => step.consulted),
|
|
285
|
+
scripts: [...entries.values()].sort((left, right) => byteOrder(left.name, right.name)),
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
//# sourceMappingURL=resolve.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve.js","sourceRoot":"","sources":["../../src/scripts/resolve.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,MAA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AAE,UAAU,CAAC,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM;gBACnD,GAAG,CAAC,UAAU,CAAC,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,UAAU,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBAChE,GAAG,CAAC,UAAU,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBACnE,GAAG,CAAC,UAAU,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,UAAU,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBACtE,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI;gBACxB,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,SAAS;gBAClC,gBAAgB;gBAChB,OAAO,EAAE,EAAE;aACZ,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,OAAO;QACL,QAAQ;QACR,WAAW;QACX,SAAS,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC;QAC9C,OAAO,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;KACvF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { type MdHeading } from "./markdown-ast.js";
|
|
2
|
+
import type { MarkdownDocument } from "./workspace.js";
|
|
3
|
+
export interface DocumentSection {
|
|
4
|
+
file: string;
|
|
5
|
+
/** Null for the content preceding the first heading. */
|
|
6
|
+
heading: MdHeading | null;
|
|
7
|
+
/** Heading depth; 0 for the preamble. */
|
|
8
|
+
depth: number;
|
|
9
|
+
/** 1-indexed, inclusive. */
|
|
10
|
+
startLine: number;
|
|
11
|
+
/** 1-indexed, inclusive. Less than `startLine` for an empty section. */
|
|
12
|
+
endLine: number;
|
|
13
|
+
content: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Line number of a document's closing frontmatter fence, or 0 when there is none.
|
|
17
|
+
*
|
|
18
|
+
* `Workspace.document` parses with `parseMarkdown`, which has no frontmatter
|
|
19
|
+
* extension, so a short frontmatter block whose body is one paragraph-shaped run
|
|
20
|
+
* becomes a setext heading: `---\ntitle: X\n---` yields a phantom depth-2
|
|
21
|
+
* heading. Callers that reason about document structure filter on this rather
|
|
22
|
+
* than inheriting the phantom.
|
|
23
|
+
*/
|
|
24
|
+
export declare function frontmatterEndLine(content: string): number;
|
|
25
|
+
/**
|
|
26
|
+
* The flat partition of a document: every heading owns the lines up to the next
|
|
27
|
+
* heading of any depth, and the preamble owns whatever precedes the first one.
|
|
28
|
+
*
|
|
29
|
+
* Non-overlapping and exhaustive, which is what makes byte accounting over the
|
|
30
|
+
* result exact. Nested sections are deliberately absent — a `--children` view
|
|
31
|
+
* would double-count every ancestor's bytes.
|
|
32
|
+
*/
|
|
33
|
+
export declare function documentSections(document: MarkdownDocument): DocumentSection[];
|
|
34
|
+
/** A section located by name, which therefore always has a heading. */
|
|
35
|
+
export interface MatchedSection extends DocumentSection {
|
|
36
|
+
heading: MdHeading;
|
|
37
|
+
}
|
|
38
|
+
/** Position in `sections` of the section named by `heading`, or -1. */
|
|
39
|
+
export declare function matchSectionIndex(sections: readonly DocumentSection[], heading: string): number;
|
|
40
|
+
export interface FindSectionOptions {
|
|
41
|
+
/** Extend the section through headings deeper than the match. Defaults to true. */
|
|
42
|
+
children?: boolean;
|
|
43
|
+
/** Include the heading line itself. Defaults to true. */
|
|
44
|
+
includeHeading?: boolean;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Locates one section by heading text or slug.
|
|
48
|
+
*
|
|
49
|
+
* Reproduces `md section`'s rule exactly, including its use of the unfiltered
|
|
50
|
+
* heading list — that command predates `frontmatterEndLine` and its output is
|
|
51
|
+
* published.
|
|
52
|
+
*/
|
|
53
|
+
export declare function findSection(document: MarkdownDocument, heading: string, options?: FindSectionOptions): MatchedSection | undefined;
|
package/dist/sections.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { slugify } from "./markdown-ast.js";
|
|
2
|
+
/**
|
|
3
|
+
* Line number of a document's closing frontmatter fence, or 0 when there is none.
|
|
4
|
+
*
|
|
5
|
+
* `Workspace.document` parses with `parseMarkdown`, which has no frontmatter
|
|
6
|
+
* extension, so a short frontmatter block whose body is one paragraph-shaped run
|
|
7
|
+
* becomes a setext heading: `---\ntitle: X\n---` yields a phantom depth-2
|
|
8
|
+
* heading. Callers that reason about document structure filter on this rather
|
|
9
|
+
* than inheriting the phantom.
|
|
10
|
+
*/
|
|
11
|
+
export function frontmatterEndLine(content) {
|
|
12
|
+
if (!content.startsWith("---\n") && !content.startsWith("---\r\n"))
|
|
13
|
+
return 0;
|
|
14
|
+
const match = content.match(/^---\r?\n([\s\S]*?)\r?\n(?:---|\.\.\.)[ \t]*(?:\r?\n|$)/);
|
|
15
|
+
if (!match)
|
|
16
|
+
return 0;
|
|
17
|
+
return match[0].replace(/\r?\n$/, "").split(/\r?\n/).length;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The flat partition of a document: every heading owns the lines up to the next
|
|
21
|
+
* heading of any depth, and the preamble owns whatever precedes the first one.
|
|
22
|
+
*
|
|
23
|
+
* Non-overlapping and exhaustive, which is what makes byte accounting over the
|
|
24
|
+
* result exact. Nested sections are deliberately absent — a `--children` view
|
|
25
|
+
* would double-count every ancestor's bytes.
|
|
26
|
+
*/
|
|
27
|
+
export function documentSections(document) {
|
|
28
|
+
const lines = document.content.split("\n");
|
|
29
|
+
const frontmatterEnd = frontmatterEndLine(document.content);
|
|
30
|
+
const headings = document.headings.filter((heading) => heading.line > frontmatterEnd);
|
|
31
|
+
const slice = (start, end) => end >= start ? lines.slice(start - 1, end).join("\n") : "";
|
|
32
|
+
const sections = [];
|
|
33
|
+
const preambleStart = frontmatterEnd + 1;
|
|
34
|
+
const preambleEnd = (headings.length ? headings[0].line : lines.length + 1) - 1;
|
|
35
|
+
if (preambleEnd >= preambleStart) {
|
|
36
|
+
sections.push({
|
|
37
|
+
file: document.path,
|
|
38
|
+
heading: null,
|
|
39
|
+
depth: 0,
|
|
40
|
+
startLine: preambleStart,
|
|
41
|
+
endLine: preambleEnd,
|
|
42
|
+
content: slice(preambleStart, preambleEnd),
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
for (let index = 0; index < headings.length; index++) {
|
|
46
|
+
const startLine = headings[index].line;
|
|
47
|
+
const endLine = index + 1 < headings.length ? headings[index + 1].line - 1 : lines.length;
|
|
48
|
+
sections.push({
|
|
49
|
+
file: document.path,
|
|
50
|
+
heading: headings[index],
|
|
51
|
+
depth: headings[index].depth,
|
|
52
|
+
startLine,
|
|
53
|
+
endLine,
|
|
54
|
+
content: slice(startLine, endLine),
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
return sections;
|
|
58
|
+
}
|
|
59
|
+
/** The shared heading lookup rule: case-insensitive text, or slug. */
|
|
60
|
+
function matches(heading, query) {
|
|
61
|
+
return heading.text.toLowerCase() === query.toLowerCase() || heading.slug === slugify(query);
|
|
62
|
+
}
|
|
63
|
+
/** Position in `sections` of the section named by `heading`, or -1. */
|
|
64
|
+
export function matchSectionIndex(sections, heading) {
|
|
65
|
+
return sections.findIndex((section) => section.heading !== null && matches(section.heading, heading));
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Locates one section by heading text or slug.
|
|
69
|
+
*
|
|
70
|
+
* Reproduces `md section`'s rule exactly, including its use of the unfiltered
|
|
71
|
+
* heading list — that command predates `frontmatterEndLine` and its output is
|
|
72
|
+
* published.
|
|
73
|
+
*/
|
|
74
|
+
export function findSection(document, heading, options = {}) {
|
|
75
|
+
const children = options.children ?? true;
|
|
76
|
+
const includeHeading = options.includeHeading ?? true;
|
|
77
|
+
const headings = document.headings;
|
|
78
|
+
const matchIndex = headings.findIndex((candidate) => matches(candidate, heading));
|
|
79
|
+
if (matchIndex === -1)
|
|
80
|
+
return undefined;
|
|
81
|
+
const matched = headings[matchIndex];
|
|
82
|
+
const lines = document.content.split("\n");
|
|
83
|
+
let endLine = lines.length;
|
|
84
|
+
for (let index = matchIndex + 1; index < headings.length; index++) {
|
|
85
|
+
if (!children || headings[index].depth <= matched.depth) {
|
|
86
|
+
endLine = headings[index].line - 1;
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const startLine = includeHeading ? matched.line : matched.line + 1;
|
|
91
|
+
return {
|
|
92
|
+
file: document.path,
|
|
93
|
+
heading: matched,
|
|
94
|
+
depth: matched.depth,
|
|
95
|
+
startLine,
|
|
96
|
+
endLine,
|
|
97
|
+
content: endLine >= startLine ? lines.slice(startLine - 1, endLine).join("\n") : "",
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=sections.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sections.js","sourceRoot":"","sources":["../src/sections.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAkB,MAAM,mBAAmB,CAAC;AAgB5D;;;;;;;;GAQG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAAe;IAChD,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,SAAS,CAAC;QAAE,OAAO,CAAC,CAAC;IAC7E,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,yDAAyD,CAAC,CAAC;IACvF,IAAI,CAAC,KAAK;QAAE,OAAO,CAAC,CAAC;IACrB,OAAO,K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AC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE;KACpF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Rewrites absolute paths out of a message before it reaches the client.
|
|
4
|
+
*
|
|
5
|
+
* Paths under the served root become root-relative, which is the form every
|
|
6
|
+
* tool result already uses. Anything still absolute is replaced outright rather
|
|
7
|
+
* than shortened: those are the paths a confinement failure refused to serve,
|
|
8
|
+
* and echoing one back in the error would disclose exactly what was withheld.
|
|
9
|
+
*/
|
|
10
|
+
export declare function scrub(message: string, root: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* Maps a thrown error to a tool result the model can act on.
|
|
13
|
+
*
|
|
14
|
+
* Workspace-layer failures — a missing file, an unmatched heading, a malformed
|
|
15
|
+
* query, a rejected path — are the model's to correct, so they come back as
|
|
16
|
+
* `isError` content rather than as JSON-RPC errors. Protocol-level mistakes
|
|
17
|
+
* (an unknown tool, arguments that fail their schema) are raised as `McpError`
|
|
18
|
+
* by the caller instead and never reach here.
|
|
19
|
+
*
|
|
20
|
+
* `CommandExit` is caught defensively: no tool calls a command action, but a
|
|
21
|
+
* stray call into `src/input.ts` would otherwise surface as an internal error.
|
|
22
|
+
*/
|
|
23
|
+
export declare function toolFailure(error: unknown, root: string): CallToolResult;
|
|
24
|
+
/** Whether `error` came from confinement, which callers may want to log distinctly. */
|
|
25
|
+
export declare function isRejection(error: unknown): boolean;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { CommandExit } from "../command-result.js";
|
|
3
|
+
import { PathRejected } from "./paths.js";
|
|
4
|
+
/** Any `/`- or drive-rooted run of non-whitespace, once root-relative paths are out of the way. */
|
|
5
|
+
const ABSOLUTE = /(?:[A-Za-z]:)?[/\\][^\s"'`,;)]+/g;
|
|
6
|
+
/**
|
|
7
|
+
* Rewrites absolute paths out of a message before it reaches the client.
|
|
8
|
+
*
|
|
9
|
+
* Paths under the served root become root-relative, which is the form every
|
|
10
|
+
* tool result already uses. Anything still absolute is replaced outright rather
|
|
11
|
+
* than shortened: those are the paths a confinement failure refused to serve,
|
|
12
|
+
* and echoing one back in the error would disclose exactly what was withheld.
|
|
13
|
+
*/
|
|
14
|
+
export function scrub(message, root) {
|
|
15
|
+
const withRoot = message.split(`${root}${path.sep}`).join("").split(root).join(".");
|
|
16
|
+
return withRoot.replace(ABSOLUTE, "<path outside root>");
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Maps a thrown error to a tool result the model can act on.
|
|
20
|
+
*
|
|
21
|
+
* Workspace-layer failures — a missing file, an unmatched heading, a malformed
|
|
22
|
+
* query, a rejected path — are the model's to correct, so they come back as
|
|
23
|
+
* `isError` content rather than as JSON-RPC errors. Protocol-level mistakes
|
|
24
|
+
* (an unknown tool, arguments that fail their schema) are raised as `McpError`
|
|
25
|
+
* by the caller instead and never reach here.
|
|
26
|
+
*
|
|
27
|
+
* `CommandExit` is caught defensively: no tool calls a command action, but a
|
|
28
|
+
* stray call into `src/input.ts` would otherwise surface as an internal error.
|
|
29
|
+
*/
|
|
30
|
+
export function toolFailure(error, root) {
|
|
31
|
+
const message = error instanceof CommandExit
|
|
32
|
+
? `Command exited with status ${error.exitCode}`
|
|
33
|
+
: error instanceof Error
|
|
34
|
+
? error.message
|
|
35
|
+
: String(error);
|
|
36
|
+
return {
|
|
37
|
+
content: [{ type: "text", text: scrub(message, root) }],
|
|
38
|
+
isError: true,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/** Whether `error` came from confinement, which callers may want to log distinctly. */
|
|
42
|
+
export function isRejection(error) {
|
|
43
|
+
return error instanceof PathRejected;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/serve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ute path: a rejected traversal names precisely the location
|
|
5
|
+
* the server declined to disclose.
|
|
6
|
+
*/
|
|
7
|
+
export declare class PathRejected extends Error {
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Resolves `root` through any symlinks, so comparisons against it are physical.
|
|
11
|
+
*
|
|
12
|
+
* Called once at startup. A root that does not exist is a startup failure, not
|
|
13
|
+
* a per-call one.
|
|
14
|
+
*/
|
|
15
|
+
export declare function resolveRoot(root: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* The real path `value` names, once confined to `root`.
|
|
18
|
+
*
|
|
19
|
+
* Confinement is physical rather than lexical. `Workspace.inside` compares with
|
|
20
|
+
* `path.relative` alone, and `Workspace.markdownFiles` admits symlinked *files*
|
|
21
|
+
* even though it skips symlinked directories — so a `.md` symlink inside the
|
|
22
|
+
* root pointing outside it would otherwise be served. Resolving both sides also
|
|
23
|
+
* makes the comparison correct on macOS, where `/tmp` is a symlink to
|
|
24
|
+
* `/private/tmp`.
|
|
25
|
+
*
|
|
26
|
+
* The nearest existing ancestor is resolved rather than the target itself, so a
|
|
27
|
+
* path that simply does not exist reports as missing by the caller's own check
|
|
28
|
+
* instead of being reported as a confinement failure.
|
|
29
|
+
*/
|
|
30
|
+
export declare function confine(root: string, value: string, label?: string): string;
|
|
31
|
+
/** Renders an absolute path relative to `root`, which is what tool results carry. */
|
|
32
|
+
export declare function relativeTo(root: string, target: string): string;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
/**
|
|
4
|
+
* A path argument that failed confinement, or otherwise cannot be served.
|
|
5
|
+
*
|
|
6
|
+
* Carries no absolute path: a rejected traversal names precisely the location
|
|
7
|
+
* the server declined to disclose.
|
|
8
|
+
*/
|
|
9
|
+
export class PathRejected extends Error {
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Resolves `root` through any symlinks, so comparisons against it are physical.
|
|
13
|
+
*
|
|
14
|
+
* Called once at startup. A root that does not exist is a startup failure, not
|
|
15
|
+
* a per-call one.
|
|
16
|
+
*/
|
|
17
|
+
export function resolveRoot(root) {
|
|
18
|
+
const absolute = path.resolve(root);
|
|
19
|
+
if (!fs.existsSync(absolute) || !fs.statSync(absolute).isDirectory()) {
|
|
20
|
+
throw new Error(`Root directory not found: ${absolute}`);
|
|
21
|
+
}
|
|
22
|
+
return fs.realpathSync(absolute);
|
|
23
|
+
}
|
|
24
|
+
/** Whether `target` is `root` or lies beneath it, compared lexically. */
|
|
25
|
+
function within(root, target) {
|
|
26
|
+
const relative = path.relative(root, target);
|
|
27
|
+
return relative === "" || (!relative.startsWith(`..${path.sep}`) && relative !== "..");
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The real path `value` names, once confined to `root`.
|
|
31
|
+
*
|
|
32
|
+
* Confinement is physical rather than lexical. `Workspace.inside` compares with
|
|
33
|
+
* `path.relative` alone, and `Workspace.markdownFiles` admits symlinked *files*
|
|
34
|
+
* even though it skips symlinked directories — so a `.md` symlink inside the
|
|
35
|
+
* root pointing outside it would otherwise be served. Resolving both sides also
|
|
36
|
+
* makes the comparison correct on macOS, where `/tmp` is a symlink to
|
|
37
|
+
* `/private/tmp`.
|
|
38
|
+
*
|
|
39
|
+
* The nearest existing ancestor is resolved rather than the target itself, so a
|
|
40
|
+
* path that simply does not exist reports as missing by the caller's own check
|
|
41
|
+
* instead of being reported as a confinement failure.
|
|
42
|
+
*/
|
|
43
|
+
export function confine(root, value, label = "path") {
|
|
44
|
+
if (value === "-") {
|
|
45
|
+
// On a stdio server fd 0 is the JSON-RPC channel. `requireFile("-")` would
|
|
46
|
+
// read it and deadlock the transport, so "-" never reaches the workspace.
|
|
47
|
+
throw new PathRejected(`A ${label} of "-" is not available over MCP`);
|
|
48
|
+
}
|
|
49
|
+
if (value.includes("\0"))
|
|
50
|
+
throw new PathRejected(`Invalid ${label}`);
|
|
51
|
+
const absolute = path.resolve(root, value);
|
|
52
|
+
let existing = absolute;
|
|
53
|
+
while (!fs.existsSync(existing)) {
|
|
54
|
+
const parent = path.dirname(existing);
|
|
55
|
+
if (parent === existing)
|
|
56
|
+
break;
|
|
57
|
+
existing = parent;
|
|
58
|
+
}
|
|
59
|
+
const real = fs.existsSync(existing)
|
|
60
|
+
? path.join(fs.realpathSync(existing), path.relative(existing, absolute))
|
|
61
|
+
: absolute;
|
|
62
|
+
if (!within(root, real))
|
|
63
|
+
throw new PathRejected(`The ${label} is outside the served root`);
|
|
64
|
+
return real;
|
|
65
|
+
}
|
|
66
|
+
/** Renders an absolute path relative to `root`, which is what tool results carry. */
|
|
67
|
+
export function relativeTo(root, target) {
|
|
68
|
+
const relative = path.relative(root, target);
|
|
69
|
+
return (relative === "" ? "." : relative).split(path.sep).join("/");
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=paths.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.js","sourceRoot":"","sources":["../../src/serve/paths.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B;;;;;GAKG;AACH,MAAM,OAAO,YAAa,SAAQ,KAAK;CAAG;AAE1C;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,IAAY;IACtC,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACpC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC;QACrE,MAAM,IAAI,KAAK,CAAC,6BAA6B,QAAQ,EAAE,CAAC,CAAC;IAC3D,CAAC;IACD,OAAO,EAAE,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;AACnC,CAAC;AAED,yEAAyE;AACzE,SAAS,MAAM,CAAC,IAAY,EAAE,MAAc;IAC1C,MAAM,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