@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,235 @@
|
|
|
1
|
+
import os from "node:os";
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
3
|
+
/**
|
|
4
|
+
* Runs a resolved script.
|
|
5
|
+
*
|
|
6
|
+
* This is the only module in the tool that executes anything, and the shape of
|
|
7
|
+
* both forms is chosen to keep argument content out of anything that gets
|
|
8
|
+
* re-parsed. `exec:` hands an argv array straight to `execve`. `run:` passes the
|
|
9
|
+
* body to `sh -c` and the forwarded arguments as *separate* argv entries, which
|
|
10
|
+
* the shell binds to `$1…$n` without ever lexing them as source — so an argument
|
|
11
|
+
* containing `; rm -rf ~` is one inert positional parameter. Building a command
|
|
12
|
+
* line by interpolating arguments into the body, or reaching for
|
|
13
|
+
* `spawn(cmd, { shell: true })`, would give that guarantee away.
|
|
14
|
+
*/
|
|
15
|
+
/** POSIX default. Not `$SHELL`: a login shell may be fish or csh, neither of
|
|
16
|
+
* which binds positional parameters for `-c`, which would make a registry
|
|
17
|
+
* behave differently on different machines — the exact problem this feature
|
|
18
|
+
* exists to solve. */
|
|
19
|
+
const DEFAULT_SHELL = "/bin/sh";
|
|
20
|
+
/** Captured output past this is dropped, but still drained. */
|
|
21
|
+
const MAX_CAPTURE_BYTES = 8 * 1024 * 1024;
|
|
22
|
+
/** Deep enough for real composition, shallow enough to stop a runaway. */
|
|
23
|
+
export const MAX_SCRIPT_DEPTH = 8;
|
|
24
|
+
const DEPTH_VARIABLE = "CAIRN_SCRIPT_DEPTH";
|
|
25
|
+
const STACK_VARIABLE = "CAIRN_SCRIPT_STACK";
|
|
26
|
+
const LEGACY_DEPTH_VARIABLE = "CLAUDE_CLI_SCRIPT_DEPTH";
|
|
27
|
+
const LEGACY_STACK_VARIABLE = "CLAUDE_CLI_SCRIPT_STACK";
|
|
28
|
+
/** `$1`, `${1}`, `$@`, `$*` — any reference to a positional parameter. */
|
|
29
|
+
const POSITIONAL_PARAMETER = /\$\{?[0-9@*]/;
|
|
30
|
+
// Both spellings are read as well as written. A script from before the rename
|
|
31
|
+
// may re-export only the legacy variable, and reading just the current one there
|
|
32
|
+
// would reset the counter to zero and defeat the recursion guard entirely.
|
|
33
|
+
function currentDepth(env = process.env) {
|
|
34
|
+
const parsed = Number.parseInt(env[DEPTH_VARIABLE] ?? env[LEGACY_DEPTH_VARIABLE] ?? "0", 10);
|
|
35
|
+
return Number.isFinite(parsed) && parsed > 0 ? parsed : 0;
|
|
36
|
+
}
|
|
37
|
+
function currentStack(env = process.env) {
|
|
38
|
+
const raw = env[STACK_VARIABLE] ?? env[LEGACY_STACK_VARIABLE];
|
|
39
|
+
return raw ? raw.split("\n").filter(Boolean) : [];
|
|
40
|
+
}
|
|
41
|
+
function frameFor(execution) {
|
|
42
|
+
return `${execution.registry.file}#${execution.definition.name}`;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The child's environment.
|
|
46
|
+
*
|
|
47
|
+
* Every variable is exported under both the current and the pre-rename spelling.
|
|
48
|
+
* A script is user code this tool does not get to edit, so one already reading
|
|
49
|
+
* `CLAUDE_CLI_SCRIPT_ROOT` has to keep working; duplicating six variables is the
|
|
50
|
+
* cheap half of that bargain.
|
|
51
|
+
*/
|
|
52
|
+
export function scriptEnvironment(execution) {
|
|
53
|
+
const depth = String(currentDepth() + 1);
|
|
54
|
+
const stack = [...currentStack(), frameFor(execution)].join("\n");
|
|
55
|
+
return {
|
|
56
|
+
...process.env,
|
|
57
|
+
CAIRN_SCRIPT_NAME: execution.definition.name,
|
|
58
|
+
CAIRN_SCRIPT_ROOT: execution.registry.directory,
|
|
59
|
+
CAIRN_SCRIPT_REGISTRY: execution.registry.file,
|
|
60
|
+
CAIRN_INVOKED_FROM: execution.invokedFrom,
|
|
61
|
+
[DEPTH_VARIABLE]: depth,
|
|
62
|
+
[STACK_VARIABLE]: stack,
|
|
63
|
+
CLAUDE_CLI_SCRIPT_NAME: execution.definition.name,
|
|
64
|
+
CLAUDE_CLI_SCRIPT_ROOT: execution.registry.directory,
|
|
65
|
+
CLAUDE_CLI_SCRIPT_REGISTRY: execution.registry.file,
|
|
66
|
+
CLAUDE_CLI_INVOKED_FROM: execution.invokedFrom,
|
|
67
|
+
[LEGACY_DEPTH_VARIABLE]: depth,
|
|
68
|
+
[LEGACY_STACK_VARIABLE]: stack,
|
|
69
|
+
// A nested `cairn` must not write an update notice into a stream the outer
|
|
70
|
+
// hook is capturing. The argv gate in src/update-notifier.ts covers this
|
|
71
|
+
// invocation; this covers every one the script makes.
|
|
72
|
+
CAIRN_NO_UPDATE_NOTIFIER: "1",
|
|
73
|
+
CLAUDE_CLI_NO_UPDATE_NOTIFIER: "1",
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Refuses a script that is already running.
|
|
78
|
+
*
|
|
79
|
+
* This is a footgun guard, not a security control — a script can clear either
|
|
80
|
+
* variable. It exists so a self-referential definition fails immediately instead
|
|
81
|
+
* of forking until something else gives out.
|
|
82
|
+
*/
|
|
83
|
+
export function checkRecursionDepth(execution) {
|
|
84
|
+
if (currentStack().includes(frameFor(execution))) {
|
|
85
|
+
throw new Error(`Script recursion detected: '${execution.definition.name}' is already running from ${execution.registry.file}`);
|
|
86
|
+
}
|
|
87
|
+
if (currentDepth() >= MAX_SCRIPT_DEPTH) {
|
|
88
|
+
throw new Error(`Script recursion limit exceeded (${MAX_SCRIPT_DEPTH}): '${execution.definition.name}'`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* The program and argv for one script.
|
|
93
|
+
*
|
|
94
|
+
* Exported for the unit tests, which assert the exact argv rather than
|
|
95
|
+
* inspecting behavior through a child process.
|
|
96
|
+
*/
|
|
97
|
+
export function spawnPlan(execution) {
|
|
98
|
+
const { definition, args } = execution;
|
|
99
|
+
if (definition.exec) {
|
|
100
|
+
return { command: definition.exec[0], argv: [...definition.exec.slice(1), ...args] };
|
|
101
|
+
}
|
|
102
|
+
const body = definition.run;
|
|
103
|
+
if (process.platform === "win32") {
|
|
104
|
+
// cmd.exe has no positional-parameter mechanism, and emulating one means
|
|
105
|
+
// splicing caller-supplied text into a command line.
|
|
106
|
+
if (args.length > 0) {
|
|
107
|
+
throw new Error(`Script '${definition.name}' uses run: and cannot forward arguments on Windows; use exec:`);
|
|
108
|
+
}
|
|
109
|
+
const shell = definition.shell ?? process.env.ComSpec ?? "cmd.exe";
|
|
110
|
+
return { command: shell, argv: ["/d", "/s", "/c", body] };
|
|
111
|
+
}
|
|
112
|
+
if (args.length > 0 && !POSITIONAL_PARAMETER.test(body)) {
|
|
113
|
+
throw new Error(`scripts.${definition.name}.run takes no positional parameters; add "$@" to forward arguments`);
|
|
114
|
+
}
|
|
115
|
+
// `$0` is the script name rather than `sh`, so `set -u` and syntax errors name
|
|
116
|
+
// the script a reader can find.
|
|
117
|
+
return {
|
|
118
|
+
command: definition.shell ?? DEFAULT_SHELL,
|
|
119
|
+
argv: ["-c", body, definition.name, ...args],
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
function collect(stream, onDone) {
|
|
123
|
+
const chunks = [];
|
|
124
|
+
let size = 0;
|
|
125
|
+
let truncated = false;
|
|
126
|
+
stream.on("data", (chunk) => {
|
|
127
|
+
// Past the cap the data is dropped but the stream keeps flowing: pausing it
|
|
128
|
+
// fills the OS pipe buffer and deadlocks the child.
|
|
129
|
+
if (size < MAX_CAPTURE_BYTES) {
|
|
130
|
+
chunks.push(chunk);
|
|
131
|
+
size += chunk.length;
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
truncated = true;
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
stream.on("end", () => onDone(Buffer.concat(chunks).toString("utf-8"), truncated));
|
|
138
|
+
}
|
|
139
|
+
export async function executeScript(execution) {
|
|
140
|
+
checkRecursionDepth(execution);
|
|
141
|
+
const plan = spawnPlan(execution);
|
|
142
|
+
const capture = execution.mode === "capture";
|
|
143
|
+
const started = Date.now();
|
|
144
|
+
return await new Promise((resolve) => {
|
|
145
|
+
// stdin is inherited in both modes: a hook piping a payload into a script is
|
|
146
|
+
// ordinary, and stdin is never part of the captured output.
|
|
147
|
+
const child = spawn(plan.command, plan.argv, {
|
|
148
|
+
cwd: execution.workingDirectory,
|
|
149
|
+
env: scriptEnvironment(execution),
|
|
150
|
+
stdio: capture ? ["inherit", "pipe", "pipe"] : ["inherit", "inherit", "inherit"],
|
|
151
|
+
shell: false,
|
|
152
|
+
windowsHide: true,
|
|
153
|
+
});
|
|
154
|
+
let stdout = "";
|
|
155
|
+
let stderr = "";
|
|
156
|
+
let truncatedOut = false;
|
|
157
|
+
let truncatedErr = false;
|
|
158
|
+
let pending = 0;
|
|
159
|
+
let closed;
|
|
160
|
+
let settled = false;
|
|
161
|
+
// Forwarded without exiting, so the parent survives long enough to write its
|
|
162
|
+
// payload. `once` means a second interrupt reaches Node's default handler,
|
|
163
|
+
// so a child that ignores SIGINT cannot make this process unkillable.
|
|
164
|
+
const forward = (signal) => () => child.kill(signal);
|
|
165
|
+
const onInterrupt = forward("SIGINT");
|
|
166
|
+
const onTerminate = forward("SIGTERM");
|
|
167
|
+
process.once("SIGINT", onInterrupt);
|
|
168
|
+
process.once("SIGTERM", onTerminate);
|
|
169
|
+
const settle = (outcome) => {
|
|
170
|
+
if (settled)
|
|
171
|
+
return;
|
|
172
|
+
settled = true;
|
|
173
|
+
process.removeListener("SIGINT", onInterrupt);
|
|
174
|
+
process.removeListener("SIGTERM", onTerminate);
|
|
175
|
+
resolve({ ...outcome, durationMs: Date.now() - started });
|
|
176
|
+
};
|
|
177
|
+
const finish = () => {
|
|
178
|
+
if (!closed || pending > 0)
|
|
179
|
+
return;
|
|
180
|
+
settle({
|
|
181
|
+
code: closed.code,
|
|
182
|
+
signal: closed.signal,
|
|
183
|
+
...(capture
|
|
184
|
+
? { stdout, stderr, truncated: { stdout: truncatedOut, stderr: truncatedErr } }
|
|
185
|
+
: {}),
|
|
186
|
+
});
|
|
187
|
+
};
|
|
188
|
+
if (capture && child.stdout && child.stderr) {
|
|
189
|
+
pending = 2;
|
|
190
|
+
collect(child.stdout, (text, truncated) => {
|
|
191
|
+
stdout = text;
|
|
192
|
+
truncatedOut = truncated;
|
|
193
|
+
pending--;
|
|
194
|
+
finish();
|
|
195
|
+
});
|
|
196
|
+
collect(child.stderr, (text, truncated) => {
|
|
197
|
+
stderr = text;
|
|
198
|
+
truncatedErr = truncated;
|
|
199
|
+
pending--;
|
|
200
|
+
finish();
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
// ENOENT, EACCES, or a rejected argument. Both `error` and `close` can fire;
|
|
204
|
+
// `settled` keeps the first one authoritative.
|
|
205
|
+
child.on("error", (error) => {
|
|
206
|
+
settle({
|
|
207
|
+
code: null,
|
|
208
|
+
signal: null,
|
|
209
|
+
startupError: error.message,
|
|
210
|
+
...(capture ? { stdout, stderr, truncated: { stdout: false, stderr: false } } : {}),
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
child.on("close", (code, signal) => {
|
|
214
|
+
closed = { code, signal };
|
|
215
|
+
finish();
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* The status this process exits with when it passes the child's through.
|
|
221
|
+
*
|
|
222
|
+
* A bare `code & 0xff` would map 256 to 0, reporting success for a child that
|
|
223
|
+
* failed, so an out-of-range code that truncates to zero becomes 1 instead.
|
|
224
|
+
*/
|
|
225
|
+
export function exitStatusFor(outcome) {
|
|
226
|
+
if (outcome.startupError)
|
|
227
|
+
return 1;
|
|
228
|
+
if (outcome.signal)
|
|
229
|
+
return 128 + (os.constants.signals[outcome.signal] ?? 0);
|
|
230
|
+
const code = outcome.code ?? 1;
|
|
231
|
+
if (code >= 0 && code <= 255)
|
|
232
|
+
return code;
|
|
233
|
+
return code & 0xff || 1;
|
|
234
|
+
}
|
|
235
|
+
//# sourceMappingURL=execute.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execute.js","sourceRoot":"","sources":["../../src/scripts/execute.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAG3C;;;;;;;;;;;GAWG;AAEH;;;sBAGsB;AACtB,MAAM,aAAa,GAAG,SAAS,CAAC;AAEhC,+DAA+D;AAC/D,MAAM,iBAAiB,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;AAE1C,0EAA0E;AAC1E,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAElC,MAAM,cAAc,GAAG,oBAAoB,CAAC;AAC5C,MAAM,cAAc,GAAG,oBAAoB,CAAC;AAC5C,MAAM,qBAAqB,GAAG,yBAAyB,CAAC;AACxD,MAAM,qBAAqB,GAAG,yBAAyB,CAAC;AAExD,0EAA0E;AAC1E,MAAM,oBAAoB,GAAG,cAAc,CAAC;AA0B5C,8EAA8E;AAC9E,iFAAiF;AACjF,2EAA2E;AAC3E,SAAS,YAAY,CAAC,MAAyB,OAAO,CAAC,GAAG;IACxD,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,GAAG,CAAC,qBAAqB,CAAC,IAAI,GAAG,EAAE,EAAE,CAAC,CAAC;IAC7F,OAAO,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AAC5D,CAAC;AAED,SAAS,YAAY,CAAC,MAAyB,OAAO,CAAC,GAAG;IACxD,MAAM,GAAG,GAAG,GAAG,CAAC,cAAc,CAAC,IAAI,GAAG,CAAC,qBAAqB,CAAC,CAAC;IAC9D,OAA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2
|
+
* Parsing and validation for the `scripts:` block of a `.cairn.yml` file.
|
|
3
|
+
*
|
|
4
|
+
* This module is deliberately pure — no filesystem access, no child process, no
|
|
5
|
+
* knowledge of how a configuration file is discovered. That seam is what lets
|
|
6
|
+
* `loadConfig`, which reads only the nearest file, and the chain walk in
|
|
7
|
+
* `./resolve.ts`, which reads several, share one validator. It also keeps
|
|
8
|
+
* `node:child_process` off the import path of every command that merely loads
|
|
9
|
+
* configuration.
|
|
10
|
+
*/
|
|
11
|
+
/** Where the child process runs. `path` is registry-relative. */
|
|
12
|
+
export type ScriptCwd = {
|
|
13
|
+
kind: "registry";
|
|
14
|
+
} | {
|
|
15
|
+
kind: "invocation";
|
|
16
|
+
} | {
|
|
17
|
+
kind: "path";
|
|
18
|
+
value: string;
|
|
19
|
+
};
|
|
20
|
+
export interface ScriptDefinition {
|
|
21
|
+
name: string;
|
|
22
|
+
description?: string;
|
|
23
|
+
/** Exactly one of `run` and `exec` is set; the parser guarantees the xor. */
|
|
24
|
+
run?: string;
|
|
25
|
+
exec?: readonly string[];
|
|
26
|
+
/** Shell for `run`, defaulting to `/bin/sh`. Ignored for `exec`. */
|
|
27
|
+
shell?: string;
|
|
28
|
+
cwd: ScriptCwd;
|
|
29
|
+
}
|
|
30
|
+
export interface ScriptRegistry {
|
|
31
|
+
/** Absolute path of the `.cairn.yml` that declared these scripts. */
|
|
32
|
+
file: string;
|
|
33
|
+
/** Directory of that file; the default working directory for its scripts. */
|
|
34
|
+
directory: string;
|
|
35
|
+
/** Declaration order preserved. */
|
|
36
|
+
scripts: ReadonlyMap<string, ScriptDefinition>;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Names are restricted to what reads unambiguously on a command line and in a
|
|
40
|
+
* hook definition: no path separators, no `..`, no shell metacharacters, no
|
|
41
|
+
* leading or trailing punctuation.
|
|
42
|
+
*/
|
|
43
|
+
export declare const SCRIPT_NAME: RegExp;
|
|
44
|
+
export declare const MAX_SCRIPT_NAME_LENGTH = 64;
|
|
45
|
+
export declare function emptyRegistry(file: string, directory: string): ScriptRegistry;
|
|
46
|
+
/**
|
|
47
|
+
* Validates an already-parsed `scripts:` value.
|
|
48
|
+
*
|
|
49
|
+
* An absent block yields an empty registry rather than throwing, so a
|
|
50
|
+
* configuration file with no scripts is not a special case at either call site.
|
|
51
|
+
*/
|
|
52
|
+
export declare function parseScriptsBlock(value: unknown, context: {
|
|
53
|
+
file: string;
|
|
54
|
+
directory: string;
|
|
55
|
+
}): ScriptRegistry;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { knownKeys, object, optionalString } from "../config-schema.js";
|
|
2
|
+
/**
|
|
3
|
+
* Names are restricted to what reads unambiguously on a command line and in a
|
|
4
|
+
* hook definition: no path separators, no `..`, no shell metacharacters, no
|
|
5
|
+
* leading or trailing punctuation.
|
|
6
|
+
*/
|
|
7
|
+
export const SCRIPT_NAME = /^[a-z0-9](?:[a-z0-9._:-]*[a-z0-9])?$/;
|
|
8
|
+
export const MAX_SCRIPT_NAME_LENGTH = 64;
|
|
9
|
+
const SCRIPT_KEYS = new Set(["run", "exec", "shell", "cwd", "description"]);
|
|
10
|
+
/** Reserved `cwd:` values; anything else is a registry-relative path. */
|
|
11
|
+
const CWD_REGISTRY = "registry";
|
|
12
|
+
const CWD_INVOCATION = "invocation";
|
|
13
|
+
export function emptyRegistry(file, directory) {
|
|
14
|
+
return { file, directory, scripts: new Map() };
|
|
15
|
+
}
|
|
16
|
+
function execArgv(value, name) {
|
|
17
|
+
if (!Array.isArray(value) || value.some((item) => typeof item !== "string")) {
|
|
18
|
+
throw new Error(`${name} must be a list of strings`);
|
|
19
|
+
}
|
|
20
|
+
const argv = [...value];
|
|
21
|
+
if (argv.length === 0)
|
|
22
|
+
throw new Error(`${name} must be a non-empty list of strings`);
|
|
23
|
+
if (argv[0].length === 0)
|
|
24
|
+
throw new Error(`${name}[0] must be a non-empty program name`);
|
|
25
|
+
// A NUL byte makes `spawn` throw a TypeError from deep inside libuv rather
|
|
26
|
+
// than reporting which script is at fault.
|
|
27
|
+
if (argv.some((item) => item.includes("\0"))) {
|
|
28
|
+
throw new Error(`${name} must not contain NUL bytes`);
|
|
29
|
+
}
|
|
30
|
+
return argv;
|
|
31
|
+
}
|
|
32
|
+
function scriptCwd(value, name) {
|
|
33
|
+
const raw = optionalString(value, name);
|
|
34
|
+
if (raw === undefined || raw === CWD_REGISTRY)
|
|
35
|
+
return { kind: "registry" };
|
|
36
|
+
if (raw === CWD_INVOCATION)
|
|
37
|
+
return { kind: "invocation" };
|
|
38
|
+
if (raw.length === 0)
|
|
39
|
+
throw new Error(`${name} must be a non-empty string`);
|
|
40
|
+
// Containment of the resolved directory is enforced in `./resolve.ts`; this
|
|
41
|
+
// only rejects the spelling that could never be meant relatively.
|
|
42
|
+
if (raw.startsWith("/") || /^[a-zA-Z]:[\\/]/.test(raw)) {
|
|
43
|
+
throw new Error(`${name} must be relative to the registry`);
|
|
44
|
+
}
|
|
45
|
+
return { kind: "path", value: raw };
|
|
46
|
+
}
|
|
47
|
+
function scriptDefinition(name, value) {
|
|
48
|
+
const label = `scripts.${name}`;
|
|
49
|
+
const entry = object(value, label);
|
|
50
|
+
knownKeys(entry, SCRIPT_KEYS, label);
|
|
51
|
+
const hasRun = entry.run !== undefined;
|
|
52
|
+
const hasExec = entry.exec !== undefined;
|
|
53
|
+
if (hasRun === hasExec) {
|
|
54
|
+
throw new Error(`${label} must set exactly one of run or exec`);
|
|
55
|
+
}
|
|
56
|
+
const definition = {
|
|
57
|
+
name,
|
|
58
|
+
cwd: scriptCwd(entry.cwd, `${label}.cwd`),
|
|
59
|
+
};
|
|
60
|
+
const description = optionalString(entry.description, `${label}.description`);
|
|
61
|
+
if (description !== undefined)
|
|
62
|
+
definition.description = description;
|
|
63
|
+
if (hasRun) {
|
|
64
|
+
const run = optionalString(entry.run, `${label}.run`);
|
|
65
|
+
if (!run || run.trim().length === 0) {
|
|
66
|
+
throw new Error(`${label}.run must be a non-empty string`);
|
|
67
|
+
}
|
|
68
|
+
definition.run = run;
|
|
69
|
+
const shell = optionalString(entry.shell, `${label}.shell`);
|
|
70
|
+
if (shell !== undefined) {
|
|
71
|
+
if (shell.length === 0)
|
|
72
|
+
throw new Error(`${label}.shell must be a non-empty string`);
|
|
73
|
+
definition.shell = shell;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
if (entry.shell !== undefined) {
|
|
78
|
+
throw new Error(`${label}.shell applies to run, not exec`);
|
|
79
|
+
}
|
|
80
|
+
definition.exec = execArgv(entry.exec, `${label}.exec`);
|
|
81
|
+
}
|
|
82
|
+
return definition;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Validates an already-parsed `scripts:` value.
|
|
86
|
+
*
|
|
87
|
+
* An absent block yields an empty registry rather than throwing, so a
|
|
88
|
+
* configuration file with no scripts is not a special case at either call site.
|
|
89
|
+
*/
|
|
90
|
+
export function parseScriptsBlock(value, context) {
|
|
91
|
+
if (value === undefined)
|
|
92
|
+
return emptyRegistry(context.file, context.directory);
|
|
93
|
+
const block = object(value, "scripts");
|
|
94
|
+
const scripts = new Map();
|
|
95
|
+
for (const [name, entry] of Object.entries(block)) {
|
|
96
|
+
if (name.length > MAX_SCRIPT_NAME_LENGTH || !SCRIPT_NAME.test(name)) {
|
|
97
|
+
throw new Error(`Invalid script name: ${name}`);
|
|
98
|
+
}
|
|
99
|
+
scripts.set(name, scriptDefinition(name, entry));
|
|
100
|
+
}
|
|
101
|
+
return { file: context.file, directory: context.directory, scripts };
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/scripts/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAqCxE;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,G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AAS;QAAE,OAAO,aAAa,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;IAE/E,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;IACvC,MAAM,OAAO,GAAG,IAAI,GAAG,EAA4B,CAAC;IACpD,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAClD,IAAI,IAAI,CAAC,MAAM,GAAG,sBAAsB,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YACpE,MAAM,IAAI,KAAK,CAAC,wBAAwB,IAAI,EAAE,CAAC,CAAC;QAClD,CAAC;QACD,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,gBAAgB,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;IACnD,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,OAAO,EAAE,CAAC;AACvE,CAAC"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { ConfigSelection } from "../config.js";
|
|
2
|
+
import type { ScriptDefinition, ScriptRegistry } from "./registry.js";
|
|
3
|
+
export type ScriptBoundaryKind = "explicit-root" | "git-root" | "nearest-config" | "single-config" | "disabled";
|
|
4
|
+
export interface ScriptBoundary {
|
|
5
|
+
/** Absolute and symlink-resolved. The walk never reads above this directory. */
|
|
6
|
+
directory: string;
|
|
7
|
+
kind: ScriptBoundaryKind;
|
|
8
|
+
}
|
|
9
|
+
export interface ScriptsWalkOptions {
|
|
10
|
+
/** Invocation directory; defaults to the process working directory. */
|
|
11
|
+
cwd?: string;
|
|
12
|
+
/** `--root <dir>`, resolved against `cwd` by the caller. */
|
|
13
|
+
root?: string;
|
|
14
|
+
/** `--config` / `--no-config`, as parsed by `selectConfig`. */
|
|
15
|
+
selection?: ConfigSelection;
|
|
16
|
+
}
|
|
17
|
+
export type ConsultedStatus =
|
|
18
|
+
/** Declares the requested name — the winner, or a shadowed definition. */
|
|
19
|
+
"defines"
|
|
20
|
+
/** Parsed and has a `scripts:` block, but not the requested name. */
|
|
21
|
+
| "declares"
|
|
22
|
+
/** Parsed, with no `scripts:` block at all. */
|
|
23
|
+
| "no-scripts"
|
|
24
|
+
/** Unreadable YAML, or a `scripts:` block that failed validation. */
|
|
25
|
+
| "invalid"
|
|
26
|
+
/** Failed a read guard, or sits under `node_modules`. */
|
|
27
|
+
| "skipped";
|
|
28
|
+
export interface ConsultedFile {
|
|
29
|
+
file: string;
|
|
30
|
+
directory: string;
|
|
31
|
+
/** Directory levels above the invocation directory; 0 is the directory itself. */
|
|
32
|
+
distance: number;
|
|
33
|
+
status: ConsultedStatus;
|
|
34
|
+
/** Set for `invalid` and `skipped`. */
|
|
35
|
+
reason?: string;
|
|
36
|
+
/** Script names the file declares, sorted. Empty unless it parsed. */
|
|
37
|
+
names: string[];
|
|
38
|
+
}
|
|
39
|
+
export interface ScriptWinner {
|
|
40
|
+
definition: ScriptDefinition;
|
|
41
|
+
registry: ScriptRegistry;
|
|
42
|
+
/** Absolute, resolved, and already checked against the boundary. */
|
|
43
|
+
workingDirectory: string;
|
|
44
|
+
}
|
|
45
|
+
export interface ShadowedDefinition {
|
|
46
|
+
file: string;
|
|
47
|
+
directory: string;
|
|
48
|
+
description?: string;
|
|
49
|
+
}
|
|
50
|
+
export interface ScriptResolution {
|
|
51
|
+
name: string;
|
|
52
|
+
boundary: ScriptBoundary;
|
|
53
|
+
invokedFrom: string;
|
|
54
|
+
/** Nearest first — exactly the files the walk opened. */
|
|
55
|
+
consulted: ConsultedFile[];
|
|
56
|
+
winner?: ScriptWinner;
|
|
57
|
+
/** Files that also define the name but lost, nearest first. */
|
|
58
|
+
shadowed: ShadowedDefinition[];
|
|
59
|
+
}
|
|
60
|
+
export interface ScriptListingEntry {
|
|
61
|
+
name: string;
|
|
62
|
+
description?: string;
|
|
63
|
+
form: "run" | "exec";
|
|
64
|
+
run?: string;
|
|
65
|
+
exec?: readonly string[];
|
|
66
|
+
shell?: string;
|
|
67
|
+
file: string;
|
|
68
|
+
directory: string;
|
|
69
|
+
workingDirectory: string;
|
|
70
|
+
/** Files whose same-named definition this one shadows. */
|
|
71
|
+
shadows: string[];
|
|
72
|
+
}
|
|
73
|
+
export interface ScriptListing {
|
|
74
|
+
boundary: ScriptBoundary;
|
|
75
|
+
invokedFrom: string;
|
|
76
|
+
consulted: ConsultedFile[];
|
|
77
|
+
scripts: ScriptListingEntry[];
|
|
78
|
+
}
|
|
79
|
+
export declare function resolveBoundary(options?: ScriptsWalkOptions): ScriptBoundary;
|
|
80
|
+
export declare function resolveScript(name: string, options?: ScriptsWalkOptions): ScriptResolution;
|
|
81
|
+
/**
|
|
82
|
+
* The first invalid file that could have changed the answer, if any.
|
|
83
|
+
*
|
|
84
|
+
* A file farther from the invocation directory than the winner cannot have won,
|
|
85
|
+
* so it must not break the run. A nearer one might have defined the name, and
|
|
86
|
+
* running the wrong script is precisely the failure this design exists to
|
|
87
|
+
* prevent.
|
|
88
|
+
*/
|
|
89
|
+
export declare function shadowingFailure(resolution: ScriptResolution): ConsultedFile | undefined;
|
|
90
|
+
export declare function listScripts(options?: ScriptsWalkOptions): ScriptListing;
|