@uniqbit/mate-core 0.18.5 → 0.21.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/claude-capability-plugins/companion-mentions/.claude-plugin/marketplace.json +14 -0
- package/claude-capability-plugins/companion-mentions/.claude-plugin/plugin.json +8 -0
- package/claude-capability-plugins/companion-mentions/hooks/companion.ts +457 -0
- package/claude-capability-plugins/companion-mentions/hooks/hooks.json +1 -0
- package/claude-capability-plugins/companion-mentions/hooks/register.ts +403 -0
- package/claude-plugin/hooks/companion-instructions.mjs +9 -0
- package/claude-plugin/hooks/hooks.json +50 -2
- package/claude-plugin/hooks/rtk-worktree-git.mjs +58 -0
- package/claude-plugin/hooks/session-attention.mjs +10 -0
- package/claude-plugin/hooks/session-end.mjs +9 -0
- package/claude-plugin/hooks/session-guidance.mjs +1 -1
- package/claude-plugin/hooks/tokensave-route.mjs +52 -0
- package/opencode-plugin/src/server.ts +25 -3
- package/opencode-plugin/src/tui.tsx +3 -1
- package/opencode-plugin/tui.tsx +4 -1
- package/package.json +53 -15
- package/src/brand/art.generated.ts +69 -0
- package/src/brand/index.ts +12 -0
- package/src/brand/palette.ts +19 -0
- package/src/brand/svg.generated.ts +8 -0
- package/src/brand/terminal.ts +88 -0
- package/src/brand/types.ts +33 -0
- package/src/cli/commands/artifact/apply-context.ts +275 -0
- package/src/cli/commands/artifact/artifact.ts +12 -0
- package/src/cli/commands/artifact/delivery/archive.ts +125 -0
- package/src/cli/commands/artifact/delivery/branch-flags.ts +55 -0
- package/src/cli/commands/artifact/delivery/environment.ts +147 -0
- package/src/cli/commands/artifact/delivery/link.ts +210 -0
- package/src/cli/commands/artifact/delivery/output.ts +104 -0
- package/src/cli/commands/artifact/finish/command.ts +83 -8
- package/src/cli/commands/artifact/finish/engine.ts +91 -14
- package/src/cli/commands/artifact/finish/finisher.ts +10 -0
- package/src/cli/commands/artifact/finish/git.ts +132 -19
- package/src/cli/commands/artifact/finish/openspec.ts +180 -138
- package/src/cli/commands/artifact/finish/secret-scan.ts +43 -0
- package/src/cli/commands/artifact/finish/worktree-cleanup.ts +92 -0
- package/src/cli/commands/artifact/pending/command.ts +31 -3
- package/src/cli/commands/artifact/pending/discovery.ts +21 -57
- package/src/cli/commands/cap/graphify.ts +52 -3
- package/src/cli/commands/cap/index-cmd.ts +71 -15
- package/src/cli/commands/cap/openspec.ts +13 -25
- package/src/cli/commands/cap/tokensave.ts +7 -5
- package/src/cli/commands/companion/companion.ts +1 -1
- package/src/cli/commands/companion/link.ts +50 -5
- package/src/cli/commands/companion/open.ts +101 -51
- package/src/cli/commands/companion/sync.ts +10 -0
- package/src/cli/commands/companion/tui.ts +17 -7
- package/src/cli/commands/companion/update.ts +144 -66
- package/src/cli/commands/doctor.ts +317 -7
- package/src/cli/commands/factory/factory.ts +311 -0
- package/src/cli/commands/install.ts +180 -45
- package/src/cli/commands/launch/claude.ts +2 -0
- package/src/cli/commands/launch/shared.ts +48 -16
- package/src/cli/commands/plugin/install.ts +36 -15
- package/src/cli/commands/plugin/plugin.ts +3 -2
- package/src/cli/commands/report/adapter.ts +11 -2
- package/src/cli/commands/report/contract.ts +21 -0
- package/src/cli/commands/report/highlight.ts +34 -4
- package/src/cli/commands/report/index.ts +186 -171
- package/src/cli/commands/report/markdown.ts +105 -0
- package/src/cli/commands/report/palette.ts +118 -0
- package/src/cli/commands/report/renderer.ts +456 -153
- package/src/cli/commands/report/types.ts +16 -0
- package/src/cli/commands/session/context.ts +102 -0
- package/src/cli/commands/session/prepare.ts +32 -4
- package/src/cli/commands/session/registry.ts +90 -0
- package/src/cli/commands/setup.ts +50 -24
- package/src/cli/commands/shared/companion-selection.ts +3 -1
- package/src/cli/commands/studio/access.ts +6 -14
- package/src/cli/commands/studio/areas.ts +112 -33
- package/src/cli/commands/studio/companion-add.ts +87 -0
- package/src/cli/commands/studio/companion-removal.ts +86 -0
- package/src/cli/commands/studio/factory-credential.ts +35 -0
- package/src/cli/commands/studio/factory-git-tokens.ts +40 -0
- package/src/cli/commands/studio/factory-relay.ts +18 -0
- package/src/cli/commands/studio/graph-model.ts +61 -0
- package/src/cli/commands/studio/graph.ts +336 -0
- package/src/cli/commands/studio/index.ts +33 -6
- package/src/cli/commands/studio/mate-inventory.ts +1 -1
- package/src/cli/commands/studio/openspec-cli.ts +10 -58
- package/src/cli/commands/studio/payload.ts +292 -20
- package/src/cli/commands/studio/repository-add.ts +116 -0
- package/src/cli/commands/studio/routes.ts +47 -6
- package/src/cli/commands/studio/selection.ts +170 -17
- package/src/cli/commands/studio/server.ts +552 -327
- package/src/cli/commands/studio/services.ts +120 -0
- package/src/cli/commands/studio/skill-files.ts +133 -0
- package/src/cli/commands/studio/studio-app.ts +67 -0
- package/src/cli/commands/studio/terminal-assets.ts +21 -33
- package/src/cli/commands/studio/terminal.ts +128 -16
- package/src/cli/commands/studio/vault.ts +218 -44
- package/src/cli/commands/studio/views/model.ts +13 -0
- package/src/cli/commands/studio/views/vault/markdown-tree.ts +599 -0
- package/src/cli/commands/studio/views/vault/view.ts +185 -0
- package/src/cli/commands/studio/workset-session.ts +164 -0
- package/src/cli/commands/unwrap.ts +19 -0
- package/src/cli/commands/update.ts +55 -9
- package/src/cli/commands/vscode/release-vsix.json +4 -0
- package/src/cli/commands/vscode/setup.ts +213 -0
- package/src/cli/commands/vscode/vsix.ts +114 -0
- package/src/cli/commands/working/cleanup.ts +83 -18
- package/src/cli/commands/working/link.ts +76 -0
- package/src/cli/commands/working/working.ts +10 -0
- package/src/cli/commands/working/worktree.ts +547 -0
- package/src/cli/commands/wrap.ts +38 -20
- package/src/cli/companion-link-wizard.tsx +2 -0
- package/src/cli/companion-selector.tsx +2 -0
- package/src/cli/confirm.ts +2 -0
- package/src/cli/install-plan.tsx +127 -160
- package/src/cli/launch-selector.tsx +2 -0
- package/src/cli/main.ts +48 -5
- package/src/cli/parse-flags.ts +32 -6
- package/src/cli/repo-list-table.tsx +2 -0
- package/src/cli/setup-selector.tsx +86 -151
- package/src/cli/usage.ts +20 -1
- package/src/create-mate.ts +5 -4
- package/src/hooks/companion-instructions.ts +198 -0
- package/src/hooks/hook-io.ts +78 -0
- package/src/hooks/rtk-worktree-git.ts +48 -0
- package/src/hooks/session-banner.ts +24 -30
- package/src/hooks/session-end.ts +10 -0
- package/src/hooks/session-guidance.ts +18 -22
- package/src/hooks/session-prepare.ts +137 -34
- package/src/hooks/session-register.ts +199 -0
- package/src/hooks/tokensave-route.ts +30 -0
- package/src/hooks/validate-artifact-path.ts +121 -25
- package/src/index.ts +4 -0
- package/src/lib/apply-context/fingerprint.ts +174 -0
- package/src/lib/apply-context/protocol.ts +193 -0
- package/src/lib/change-layout.ts +154 -0
- package/src/lib/components/confirm-prompt.tsx +21 -9
- package/src/lib/components/select-menu.tsx +10 -3
- package/src/lib/components/spinner.tsx +4 -2
- package/src/lib/components/startup-progress.tsx +227 -41
- package/src/lib/components/text-input-display.tsx +2 -0
- package/src/lib/components/wizard-footer.tsx +2 -0
- package/src/lib/components/wizard-header.tsx +16 -12
- package/src/lib/context-mode-package.ts +24 -11
- package/src/lib/delivery/archive-change.ts +165 -0
- package/src/lib/delivery/branch-template.ts +122 -0
- package/src/lib/delivery/branches.ts +152 -0
- package/src/lib/delivery/checkout.ts +102 -0
- package/src/lib/delivery/environment.ts +37 -0
- package/src/lib/delivery/forge.ts +279 -0
- package/src/lib/delivery/merge-git.ts +273 -0
- package/src/lib/delivery/overlap.ts +209 -0
- package/src/lib/delivery/record-delivery.ts +392 -0
- package/src/lib/delivery/record.ts +417 -0
- package/src/lib/delivery/refresh.ts +288 -0
- package/src/lib/delivery/repository-access.ts +141 -0
- package/src/lib/delivery/resolve-branch.ts +430 -0
- package/src/lib/delivery/stages.ts +111 -0
- package/src/lib/delivery/token.ts +24 -0
- package/src/lib/factory/attach-client.ts +123 -0
- package/src/lib/factory/attach.ts +178 -0
- package/src/lib/factory/broker.ts +187 -0
- package/src/lib/factory/bun-commands.ts +39 -0
- package/src/lib/factory/client.ts +113 -0
- package/src/lib/factory/clone-url.ts +39 -0
- package/src/lib/factory/command.ts +77 -0
- package/src/lib/factory/credential-store.ts +153 -0
- package/src/lib/factory/frames.ts +77 -0
- package/src/lib/factory/git-auth.ts +61 -0
- package/src/lib/factory/git-credential-store.ts +181 -0
- package/src/lib/factory/ids.ts +68 -0
- package/src/lib/factory/keyed-serial.ts +27 -0
- package/src/lib/factory/outcomes/actions.ts +130 -0
- package/src/lib/factory/outcomes/index.ts +457 -0
- package/src/lib/factory/outcomes/lifecycle.ts +212 -0
- package/src/lib/factory/outcomes/runs.ts +81 -0
- package/src/lib/factory/outcomes/sessions.ts +60 -0
- package/src/lib/factory/prepare.ts +55 -0
- package/src/lib/factory/pty.ts +103 -0
- package/src/lib/factory/runner/companion-context.ts +178 -0
- package/src/lib/factory/runner/control.ts +92 -0
- package/src/lib/factory/runner/harness-agent.ts +250 -0
- package/src/lib/factory/runner/live.ts +159 -0
- package/src/lib/factory/runner/questions.ts +22 -0
- package/src/lib/factory/runner/rank.ts +26 -0
- package/src/lib/factory/runner/run-policy.ts +12 -0
- package/src/lib/factory/runner/run.ts +199 -0
- package/src/lib/factory/runner/scheduler.ts +498 -0
- package/src/lib/factory/runner/state.ts +233 -0
- package/src/lib/factory/runner/workflow.ts +546 -0
- package/src/lib/factory/runtime.ts +1081 -0
- package/src/lib/factory/sandbox.ts +292 -0
- package/src/lib/factory/worktree-branch.ts +17 -0
- package/src/lib/frontmatter.ts +18 -0
- package/src/lib/install.ts +66 -14
- package/src/lib/live-progress.ts +36 -0
- package/src/lib/member-choices.ts +67 -0
- package/src/lib/opencode-plugin-package.ts +5 -5
- package/src/lib/opencode-server.ts +238 -0
- package/src/lib/openspec-cli.ts +116 -0
- package/src/lib/openspec-scopes.ts +86 -0
- package/src/lib/orchestrator/adapters/base.ts +55 -22
- package/src/lib/orchestrator/adapters/claude-args.ts +50 -0
- package/src/lib/orchestrator/adapters/claude.ts +201 -43
- package/src/lib/orchestrator/adapters/opencode.ts +55 -2
- package/src/lib/orchestrator/checkout-adoption.ts +125 -0
- package/src/lib/orchestrator/companion-hub.ts +6 -1
- package/src/lib/orchestrator/companion-registry-store.ts +6 -2
- package/src/lib/orchestrator/config-store.ts +3 -2
- package/src/lib/orchestrator/editor.ts +32 -26
- package/src/lib/orchestrator/engine-floor.ts +48 -0
- package/src/lib/orchestrator/framework-context.ts +26 -14
- package/src/lib/orchestrator/global-config-store.ts +11 -0
- package/src/lib/orchestrator/launcher.ts +49 -3
- package/src/lib/orchestrator/openspec-store.ts +14 -54
- package/src/lib/orchestrator/projection-claude-commands.ts +36 -0
- package/src/lib/orchestrator/projection-claude-entry.ts +42 -21
- package/src/lib/orchestrator/projection-claude-links.ts +230 -0
- package/src/lib/orchestrator/projection-claude-skills.ts +39 -131
- package/src/lib/orchestrator/projection-companion-link.ts +12 -1
- package/src/lib/orchestrator/projection-entries.ts +121 -51
- package/src/lib/orchestrator/projection-opencode-copies.ts +93 -32
- package/src/lib/orchestrator/projection-openspec-store.ts +54 -9
- package/src/lib/orchestrator/projection-runtime-documents.ts +81 -49
- package/src/lib/orchestrator/projection-types.ts +63 -1
- package/src/lib/orchestrator/refresh-working-claude-links.ts +89 -0
- package/src/lib/orchestrator/registry-checkouts.ts +177 -0
- package/src/lib/orchestrator/repository-link.ts +216 -57
- package/src/lib/orchestrator/serving-claude-wrap.ts +43 -0
- package/src/lib/orchestrator/session-context-link.ts +73 -0
- package/src/lib/orchestrator/session-prepare.ts +87 -12
- package/src/lib/orchestrator/setup-compatibilities.ts +56 -70
- package/src/lib/orchestrator/types.ts +16 -2
- package/src/lib/orchestrator/umbrella-checkouts.ts +102 -0
- package/src/lib/orchestrator/working-repo-projection.ts +73 -10
- package/src/lib/orchestrator/workspace-document.ts +105 -0
- package/src/lib/orchestrator/workspace-inventory.ts +5 -1
- package/src/lib/orchestrator/wrap-pass.ts +23 -1
- package/src/lib/package-paths.ts +37 -0
- package/src/lib/public-npm.ts +105 -43
- package/src/lib/runtime-directory-refresh.ts +17 -1
- package/src/lib/session-attribution.ts +52 -0
- package/src/lib/session-state.ts +355 -0
- package/src/lib/session-stop.ts +64 -0
- package/src/lib/update-checker.ts +7 -1
- package/src/lib/usage/aggregate.ts +202 -0
- package/src/lib/usage/cache.ts +87 -0
- package/src/lib/usage/claude-pricing.ts +71 -0
- package/src/lib/usage/claude.ts +189 -0
- package/src/lib/usage/collect.ts +56 -0
- package/src/lib/usage/opencode.ts +188 -0
- package/src/lib/usage/records.ts +80 -0
- package/src/lib/usage/rtk-database.ts +72 -0
- package/src/lib/usage/savings.ts +209 -0
- package/src/lib/usage/scope.ts +182 -0
- package/src/lib/usage/source.ts +102 -0
- package/src/lib/usage/types.ts +143 -0
- package/src/lib/usage/window.ts +37 -0
- package/src/lib/workset/factory-local.ts +157 -0
- package/src/lib/workset/record.ts +547 -0
- package/src/lib/workset/repositories.ts +148 -0
- package/src/lib/workset/stage.ts +148 -0
- package/src/lib/workset/stages.ts +113 -0
- package/src/lib/workset/worktree-include.ts +161 -0
- package/src/lib/workset/worktree-index.ts +120 -0
- package/src/lib/workset/worktree.ts +1388 -0
- package/src/opencode/background-server.ts +145 -0
- package/src/opencode/companion-hooks.ts +151 -9
- package/src/opencode/companion-policy.ts +54 -22
- package/src/opencode/enter-worktree.ts +320 -0
- package/src/opencode/projected-guidance.ts +6 -2
- package/src/opencode/session-prepare.ts +2 -1
- package/src/opencode/session-register.ts +176 -0
- package/src/opencode/tui.tsx +24 -27
- package/src/plugins.ts +1 -0
- package/src/runtime/artifact-refusal.ts +63 -0
- package/src/runtime/claude-bg-isolation.ts +138 -0
- package/src/runtime/claude-delivery-plan.ts +121 -11
- package/src/runtime/commit-attribution-guard.ts +181 -0
- package/src/runtime/companion-git.ts +62 -12
- package/src/runtime/companion-guidance.ts +37 -12
- package/src/runtime/companion-instructions.ts +340 -0
- package/src/runtime/companion-lock.ts +30 -7
- package/src/runtime/current-branch.ts +24 -0
- package/src/runtime/entered-worktree.ts +24 -0
- package/src/runtime/env.ts +59 -8
- package/src/runtime/error-message.ts +4 -0
- package/src/runtime/git-layout.ts +366 -0
- package/src/runtime/git-tracked.ts +60 -0
- package/src/runtime/index.ts +29 -0
- package/src/runtime/launch-env-guard.ts +65 -0
- package/src/runtime/managed-block.ts +117 -0
- package/src/runtime/markdown-scan.ts +266 -0
- package/src/runtime/opencode-server-record.ts +136 -0
- package/src/runtime/physical-path.ts +111 -0
- package/src/runtime/policy.ts +50 -2
- package/src/runtime/projected-flag.ts +7 -0
- package/src/runtime/projected-guidance.ts +1 -0
- package/src/runtime/projection.ts +40 -6
- package/src/runtime/repo-destination.ts +72 -0
- package/src/runtime/repo-local.ts +29 -2
- package/src/runtime/rtk-git-guard.ts +66 -0
- package/src/runtime/runtime-directory.ts +5 -0
- package/src/runtime/runtime-document-manifest.ts +290 -29
- package/src/runtime/runtime-document-manifest.typecheck.ts +10 -0
- package/src/runtime/secret-guard.ts +169 -0
- package/src/runtime/secret-patterns.ts +397 -0
- package/src/runtime/secret-policy-weakening.ts +122 -0
- package/src/runtime/secret-scan.ts +90 -0
- package/src/runtime/serving-claude-wrap.ts +41 -0
- package/src/runtime/session-context.ts +99 -0
- package/src/runtime/session-kind.ts +13 -0
- package/src/runtime/session-registry.ts +434 -0
- package/src/runtime/shell-heredoc.ts +81 -0
- package/src/runtime/tokensave-route.ts +157 -0
- package/src/runtime/umbrella-folder.ts +56 -0
- package/src/runtime/wrap-state.ts +80 -15
- package/src/runtime/write-atomic.ts +64 -0
- package/src/studio.ts +163 -0
- package/src/templates/capabilities/openspec-cap/mate-minimal/schema.yaml +14 -10
- package/src/templates/capabilities/openspec-cap/mate-minimal/templates/spec.md +3 -5
- package/src/templates/capabilities/openspec-cap/mate-v1/schema.yaml +18 -102
- package/src/templates/capabilities/openspec-cap/mate-v1/templates/spec.md +3 -5
- package/src/templates/capabilities/openspec-cap/openspec-conventions.yaml +20 -14
- package/src/templates/mate-skills/THIRD-PARTY-NOTICES.md +40 -0
- package/src/templates/mate-skills/agents/mate-apply-change/SKILL.md +217 -0
- package/src/templates/mate-skills/agents/mate-apply-change/references/mate-compact-apply.md +47 -0
- package/src/templates/mate-skills/agents/mate-apply-change/references/openspec-apply-change.md +200 -0
- package/src/templates/mate-skills/agents/mate-archive-change/SKILL.md +81 -0
- package/src/templates/mate-skills/agents/{mate-openspec-backfill → mate-backfill-spec}/SKILL.md +11 -4
- package/src/templates/mate-skills/agents/mate-clarify-intent/SKILL.md +110 -0
- package/src/templates/mate-skills/agents/mate-explore-change/SKILL.md +70 -0
- package/src/templates/mate-skills/agents/mate-explore-change/references/openspec-explore.md +350 -0
- package/src/templates/mate-skills/agents/mate-grill-me/SKILL.md +11 -4
- package/src/templates/mate-skills/agents/mate-grill-with-docs/SKILL.md +2 -2
- package/src/templates/mate-skills/agents/mate-interview-me/SKILL.md +12 -5
- package/src/templates/mate-skills/agents/mate-propose-change/SKILL.md +106 -0
- package/src/templates/mate-skills/agents/mate-propose-change/references/mate-revise.md +45 -0
- package/src/templates/mate-skills/agents/mate-propose-change/references/openspec-propose.md +169 -0
- package/src/templates/mate-skills/agents/mate-propose-change/references/openspec-update-change.md +103 -0
- package/src/templates/mate-skills/agents/mate-publish-artifact/SKILL.md +271 -0
- package/src/templates/mate-skills/{claude/mate-artifact-publish → agents/mate-publish-artifact}/references/openspec.md +8 -5
- package/src/templates/mate-skills/agents/mate-show-me/SKILL.md +105 -20
- package/src/templates/mate-skills/agents/mate-simplify-code/SKILL.md +91 -68
- package/src/templates/mate-skills/claude/mate-apply-change/SKILL.md +217 -0
- package/src/templates/mate-skills/claude/mate-apply-change/references/mate-compact-apply.md +47 -0
- package/src/templates/mate-skills/claude/mate-apply-change/references/openspec-apply-change.md +200 -0
- package/src/templates/mate-skills/claude/mate-archive-change/SKILL.md +81 -0
- package/src/templates/mate-skills/claude/{mate-openspec-backfill → mate-backfill-spec}/SKILL.md +11 -4
- package/src/templates/mate-skills/claude/mate-clarify-intent/SKILL.md +110 -0
- package/src/templates/mate-skills/claude/mate-explore-change/SKILL.md +70 -0
- package/src/templates/mate-skills/claude/mate-explore-change/references/openspec-explore.md +350 -0
- package/src/templates/mate-skills/claude/mate-grill-me/SKILL.md +11 -4
- package/src/templates/mate-skills/claude/mate-grill-with-docs/SKILL.md +2 -2
- package/src/templates/mate-skills/claude/mate-interview-me/SKILL.md +12 -5
- package/src/templates/mate-skills/claude/mate-propose-change/SKILL.md +106 -0
- package/src/templates/mate-skills/claude/mate-propose-change/references/mate-revise.md +45 -0
- package/src/templates/mate-skills/claude/mate-propose-change/references/openspec-propose.md +169 -0
- package/src/templates/mate-skills/claude/mate-propose-change/references/openspec-update-change.md +103 -0
- package/src/templates/mate-skills/claude/mate-publish-artifact/SKILL.md +271 -0
- package/src/templates/mate-skills/{agents/mate-artifact-publish → claude/mate-publish-artifact}/references/openspec.md +8 -5
- package/src/templates/mate-skills/claude/mate-show-me/SKILL.md +105 -20
- package/src/templates/mate-skills/claude/mate-simplify-code/SKILL.md +91 -68
- package/src/templates/mate-skills/openspec-references.ts +142 -0
- package/src/templates/root/TEMPLATE_AGENTS.md +2 -2
- package/src/tools/setup/__snapshots__/runtime-surface-golden.test.ts.snap +4581 -397
- package/src/tools/setup/capabilities/companion-mentions.ts +27 -0
- package/src/tools/setup/capabilities/context-mode.ts +56 -7
- package/src/tools/setup/capabilities/graphify-gate.ts +31 -0
- package/src/tools/setup/capabilities/graphify-secrets.ts +243 -0
- package/src/tools/setup/capabilities/graphify.ts +46 -7
- package/src/tools/setup/capabilities/openspec.ts +163 -272
- package/src/tools/setup/capabilities/react-doctor.ts +8 -1
- package/src/tools/setup/capabilities/rtk.ts +97 -1
- package/src/tools/setup/capabilities/tokensave.ts +113 -71
- package/src/tools/setup/context-services.ts +9 -17
- package/src/tools/setup/dynamic-plugins/audiences.ts +65 -21
- package/src/tools/setup/dynamic-plugins/frozen.ts +32 -13
- package/src/tools/setup/dynamic-plugins/hydrate.ts +8 -7
- package/src/tools/setup/dynamic-plugins/install.ts +46 -48
- package/src/tools/setup/dynamic-plugins/loader.ts +11 -7
- package/src/tools/setup/dynamic-plugins/paths.ts +30 -10
- package/src/tools/setup/dynamic-plugins/verify.ts +10 -7
- package/src/tools/setup/dynamic-plugins/workspaces.ts +153 -0
- package/src/tools/setup/engine.ts +100 -23
- package/src/tools/setup/install-contract.ts +8 -0
- package/src/tools/setup/managed-output.ts +51 -0
- package/src/tools/setup/mate-skill-copies.ts +51 -0
- package/src/tools/setup/mate.ts +88 -13
- package/src/tools/setup/package-managers/uv.ts +73 -11
- package/src/tools/setup/plugin.ts +40 -0
- package/src/tools/setup/plugins/gitignore.ts +15 -9
- package/src/tools/setup/plugins/guidance.ts +7 -4
- package/src/tools/setup/providers/agent-file-sections.ts +4 -2
- package/src/tools/setup/providers/claude-attribution.ts +65 -0
- package/src/tools/setup/providers/claude-plugin-folders.ts +625 -0
- package/src/tools/setup/providers/claude-plugin-hooks.ts +89 -19
- package/src/tools/setup/providers/claude-worktree-plugins.ts +122 -0
- package/src/tools/setup/providers/claude.ts +332 -8
- package/src/tools/setup/providers/opencode.ts +180 -1
- package/src/tools/setup/utils.ts +22 -6
- package/src/tools/setup/working-repo-cleanup.ts +30 -2
- package/src/tools/setup/working-repo-local-state.ts +252 -75
- package/src/tools/setup.ts +196 -28
- package/studio-dist/client/assets/app-D9cw6szy.css +2 -0
- package/studio-dist/client/assets/artifacts-WD2ZXYrx.js +1 -0
- package/studio-dist/client/assets/button-Br0O1sXw.js +1 -0
- package/studio-dist/client/assets/combobox-DA7RAUUZ.js +1 -0
- package/studio-dist/client/assets/companion-view-CrabvxS8.js +1 -0
- package/studio-dist/client/assets/dist-Dm7MtyHc.js +5 -0
- package/studio-dist/client/assets/factory-DGS0E16C.js +6 -0
- package/studio-dist/client/assets/fields-6aXBpFhJ.js +1 -0
- package/studio-dist/client/assets/getting-started-Clde4w6P.js +1 -0
- package/studio-dist/client/assets/getting-started-D6kgWwWZ.js +1 -0
- package/studio-dist/client/assets/getting-started._topic-BiunccbT.js +1 -0
- package/studio-dist/client/assets/getting-started.index-DpiNoGw8.js +1 -0
- package/studio-dist/client/assets/graph-B_TCBVbu.js +2 -0
- package/studio-dist/client/assets/graph-canvas-Ba37Y5AE.js +3242 -0
- package/studio-dist/client/assets/guides-Du_RtJxP.js +1 -0
- package/studio-dist/client/assets/index-Df8L1LQa.js +40 -0
- package/studio-dist/client/assets/jsx-runtime-MZURdZre.js +1 -0
- package/studio-dist/client/assets/markdown-view-BOX6x0rL.js +1 -0
- package/studio-dist/client/assets/panel-dbmCx7Mx.js +1 -0
- package/studio-dist/client/assets/preload-helper-BLdHbfdN.js +1 -0
- package/studio-dist/client/assets/queries-RvHeXY12.js +1 -0
- package/studio-dist/client/assets/react-3QStrcDO.js +27 -0
- package/studio-dist/client/assets/report-url-XRL0x1SY.js +1 -0
- package/studio-dist/client/assets/reports-r3IK7Doz.js +1 -0
- package/studio-dist/client/assets/routes-C0A5LTFc.js +1 -0
- package/studio-dist/client/assets/select-CnaMd617.js +1 -0
- package/studio-dist/client/assets/skills-CzjzHpBT.js +1 -0
- package/studio-dist/client/assets/specs-B0ldF_6J.js +1 -0
- package/studio-dist/client/assets/specs-view-BnCLA0gW.js +1 -0
- package/studio-dist/client/assets/spinner-Dcm3fqK1.js +1 -0
- package/studio-dist/client/assets/steps-C0p2N1Pb.js +1 -0
- package/studio-dist/client/assets/store-Dw34catY.js +1 -0
- package/studio-dist/client/assets/studio-Cpz_HRHp.js +100 -0
- package/studio-dist/client/assets/studio-queries-ibmpFo6R.js +2 -0
- package/studio-dist/client/assets/terminal-eU5fzQzv.css +1 -0
- package/studio-dist/client/assets/usage-C2QJ_0IZ.js +55 -0
- package/studio-dist/client/assets/useAnchoredPopupScrollLock-Bj-FWb8z.js +1 -0
- package/studio-dist/client/assets/useMutation-aAr2uiay.js +1 -0
- package/studio-dist/client/assets/useSelector-AYcH7lB0.js +2 -0
- package/studio-dist/client/assets/vault-BGcxkSIY.js +1 -0
- package/studio-dist/client/assets/warnings-R1cE1rLf.js +1 -0
- package/studio-dist/client/assets/wasm-inline-C2en61B5.js +1 -0
- package/studio-dist/client/assets/workflow-C2qTrMDH.js +1 -0
- package/studio-dist/server/assets/__23tanstack-start-server-fn-resolver-Bn896ZYj.js +122 -0
- package/studio-dist/server/assets/_tanstack-start-manifest_v.js +162 -0
- package/studio-dist/server/assets/actions-D8erOphH.js +44 -0
- package/studio-dist/server/assets/actions-DYSv-9VV.js +60 -0
- package/studio-dist/server/assets/artifacts-DnF9L3dZ.js +216 -0
- package/studio-dist/server/assets/button-CgOIVdmD.js +10240 -0
- package/studio-dist/server/assets/combobox-DV_s9W0s.js +483 -0
- package/studio-dist/server/assets/companion-view-BKVXD3TO.js +39 -0
- package/studio-dist/server/assets/companions-C7fctnU9.js +31 -0
- package/studio-dist/server/assets/createServerRpc-bFKFpGFG.js +11 -0
- package/studio-dist/server/assets/dist-DpJWKyCm.js +5582 -0
- package/studio-dist/server/assets/empty-plugin-adapters-Cipd4ZH4.js +4 -0
- package/studio-dist/server/assets/factory-C7Ybg0xG.js +3075 -0
- package/studio-dist/server/assets/factory-Df5uAHjb.js +116 -0
- package/studio-dist/server/assets/fields-BbieQTD0.js +1190 -0
- package/studio-dist/server/assets/getting-started-B136TP57.js +4 -0
- package/studio-dist/server/assets/getting-started-CRxMWorQ.js +67 -0
- package/studio-dist/server/assets/getting-started._topic-DJKQAzYl.js +13 -0
- package/studio-dist/server/assets/getting-started.index-D84gec1t.js +13 -0
- package/studio-dist/server/assets/graph-CSje3029.js +801 -0
- package/studio-dist/server/assets/graph-DDZzXM1L.js +16 -0
- package/studio-dist/server/assets/graph-canvas-22bWB5-2.js +21066 -0
- package/studio-dist/server/assets/graph-wire-BdSUx0G5.js +58 -0
- package/studio-dist/server/assets/guides-D9dk1Frq.js +13 -0
- package/studio-dist/server/assets/guides-IE-19POz.js +5 -0
- package/studio-dist/server/assets/guides.server-vcYRY5wx.js +66 -0
- package/studio-dist/server/assets/jsx-runtime-Bt0s0YKS.js +451 -0
- package/studio-dist/server/assets/markdown-view-BR8dJ7aR.js +105 -0
- package/studio-dist/server/assets/model-PyPALjii.js +18 -0
- package/studio-dist/server/assets/panel-BR_t9iMM.js +169 -0
- package/studio-dist/server/assets/queries-DWoTin-q.js +32 -0
- package/studio-dist/server/assets/react-CdqSUhaL.js +89 -0
- package/studio-dist/server/assets/redirect-BaZ_QyqF.js +39 -0
- package/studio-dist/server/assets/report-url-BUXPcE_8.js +9 -0
- package/studio-dist/server/assets/reports-CQ9qQ1-n.js +141 -0
- package/studio-dist/server/assets/reports-dYDEoBeq.js +18 -0
- package/studio-dist/server/assets/router-DkRHNTpE.js +11638 -0
- package/studio-dist/server/assets/routes-B6GfOew4.js +473 -0
- package/studio-dist/server/assets/search-BJnWLfkG.js +55 -0
- package/studio-dist/server/assets/select-Af7Wibii.js +1609 -0
- package/studio-dist/server/assets/shell-Hq-hXgnT.js +53 -0
- package/studio-dist/server/assets/skills-B7nEuVbx.js +267 -0
- package/studio-dist/server/assets/skills-B_YYL7q8.js +28 -0
- package/studio-dist/server/assets/specs-BpLUFntA.js +51 -0
- package/studio-dist/server/assets/specs-view-0peMVd22.js +426 -0
- package/studio-dist/server/assets/spinner-CdwJW4VB.js +20 -0
- package/studio-dist/server/assets/start-h3ICWwd2.js +36 -0
- package/studio-dist/server/assets/steps-D56DApvK.js +181 -0
- package/studio-dist/server/assets/store-Cs17okNG.js +280 -0
- package/studio-dist/server/assets/studio-CAcKp3bM.js +10340 -0
- package/studio-dist/server/assets/studio-queries-BtRGzDdh.js +1451 -0
- package/studio-dist/server/assets/usage-COdjd1gD.js +25570 -0
- package/studio-dist/server/assets/usage-f6pqE1tm.js +24 -0
- package/studio-dist/server/assets/useAnchoredPopupScrollLock-DlBKHRw7.js +756 -0
- package/studio-dist/server/assets/useMutation-DzTZGenE.js +690 -0
- package/studio-dist/server/assets/useSelector-DUmCUXAs.js +3387 -0
- package/studio-dist/server/assets/utils-C9CX1kcy.js +221 -0
- package/studio-dist/server/assets/vault-BDuIUq0F.js +1035 -0
- package/studio-dist/server/assets/vault-BVLp6zu3.js +85 -0
- package/studio-dist/server/assets/views-flRUr21z.js +80 -0
- package/studio-dist/server/assets/warnings-CDy9pdgL.js +24 -0
- package/studio-dist/server/assets/wasm-inline-CNeBKGwC.js +3 -0
- package/studio-dist/server/assets/workflow-D9GKI2EV.js +680 -0
- package/studio-dist/server/server.js +16640 -0
- package/wrappers/bin/graphify +52 -4
- package/wrappers/bin/openspec +33 -9
- package/wrappers/lib/graphify-gate.mjs +8 -0
- package/src/cli/commands/report/collector.ts +0 -288
- package/src/cli/commands/studio/views/client.ts +0 -654
- package/src/cli/commands/studio/views/companion-picker.tsx +0 -95
- package/src/cli/commands/studio/views/companion-selector.tsx +0 -94
- package/src/cli/commands/studio/views/dashboard/changes.tsx +0 -107
- package/src/cli/commands/studio/views/dashboard/index.tsx +0 -19
- package/src/cli/commands/studio/views/document.tsx +0 -842
- package/src/cli/commands/studio/views/error.tsx +0 -20
- package/src/cli/commands/studio/views/reports/index.tsx +0 -49
- package/src/cli/commands/studio/views/selection-fields.tsx +0 -14
- package/src/cli/commands/studio/views/skills/index.tsx +0 -87
- package/src/cli/commands/studio/views/specs/index.tsx +0 -157
- package/src/cli/commands/studio/views/styles.ts +0 -519
- package/src/cli/commands/studio/views/terminal.tsx +0 -484
- package/src/cli/commands/studio/views/vault/state.ts +0 -43
- package/src/cli/commands/studio/views/warnings.tsx +0 -21
- package/src/cli/commands/studio/views/workflow/index.tsx +0 -21
- package/src/cli/commands/studio/views/workflow/steps.ts +0 -337
- package/src/cli/commands/studio/views/workflow/transcript.tsx +0 -190
- package/src/lib/components/theme.ts +0 -2
- package/src/templates/mate-skills/agents/mate-artifact-publish/SKILL.md +0 -185
- package/src/templates/mate-skills/claude/mate-artifact-publish/SKILL.md +0 -185
- package/src/tools/setup/git-utils.ts +0 -30
- package/src/tools/setup/runtime-documents.ts +0 -291
|
@@ -0,0 +1,599 @@
|
|
|
1
|
+
import { type Token, type Tokens, Lexer } from "marked";
|
|
2
|
+
import { parse as parseYaml } from "yaml";
|
|
3
|
+
|
|
4
|
+
import { highlightNodes } from "../../../report/highlight";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A rendered markdown file as plain data: text, or an element the browser builds from a fixed
|
|
8
|
+
* set of tags and attributes. Parsing, highlighting and link resolution happen on the server,
|
|
9
|
+
* and no part of the file is ever inserted as markup.
|
|
10
|
+
*/
|
|
11
|
+
export type MdNode = string | MdElement;
|
|
12
|
+
|
|
13
|
+
export interface MdElement {
|
|
14
|
+
t: MdTag;
|
|
15
|
+
a?: MdAttributes;
|
|
16
|
+
c?: MdNode[];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type MdTag =
|
|
20
|
+
| "h1"
|
|
21
|
+
| "h2"
|
|
22
|
+
| "h3"
|
|
23
|
+
| "h4"
|
|
24
|
+
| "h5"
|
|
25
|
+
| "h6"
|
|
26
|
+
| "p"
|
|
27
|
+
| "pre"
|
|
28
|
+
| "code"
|
|
29
|
+
| "span"
|
|
30
|
+
| "blockquote"
|
|
31
|
+
| "hr"
|
|
32
|
+
| "ol"
|
|
33
|
+
| "ul"
|
|
34
|
+
| "li"
|
|
35
|
+
| "input"
|
|
36
|
+
| "div"
|
|
37
|
+
| "dl"
|
|
38
|
+
| "dt"
|
|
39
|
+
| "dd"
|
|
40
|
+
| "table"
|
|
41
|
+
| "thead"
|
|
42
|
+
| "tbody"
|
|
43
|
+
| "tr"
|
|
44
|
+
| "th"
|
|
45
|
+
| "td"
|
|
46
|
+
| "strong"
|
|
47
|
+
| "em"
|
|
48
|
+
| "del"
|
|
49
|
+
| "br"
|
|
50
|
+
| "a";
|
|
51
|
+
|
|
52
|
+
export interface MdAttributes {
|
|
53
|
+
className?: string;
|
|
54
|
+
start?: number;
|
|
55
|
+
checked?: boolean;
|
|
56
|
+
align?: "left" | "right" | "center";
|
|
57
|
+
/** Only an absolute `http`/`https` address; opened without access to the vault page. */
|
|
58
|
+
href?: string;
|
|
59
|
+
/** A companion-relative markdown path the link opens in the vault. */
|
|
60
|
+
note?: string;
|
|
61
|
+
/** An allowlisted Studio guide route or fragment. */
|
|
62
|
+
guide?: string;
|
|
63
|
+
id?: string;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const MARKDOWN_TARGET = /\.(md|markdown)$/i;
|
|
67
|
+
const SCHEME = /^[a-z][a-z0-9+.-]*:/i;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* A relative link as a companion-relative markdown path, or `null` when it is anything
|
|
71
|
+
* else. Textual only: nothing is looked up on disk, so a missing note is the vault's to refuse.
|
|
72
|
+
*/
|
|
73
|
+
export function resolveNoteLink(target: string, openPath: string): string | null {
|
|
74
|
+
if (!target || SCHEME.test(target) || target.startsWith("//") || target.startsWith("#")) {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
let pathname = target.split(/[?#]/, 1)[0] ?? "";
|
|
78
|
+
try {
|
|
79
|
+
pathname = decodeURIComponent(pathname);
|
|
80
|
+
} catch {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
if (pathname.includes("\\") || !MARKDOWN_TARGET.test(pathname)) return null;
|
|
84
|
+
const folder = pathname.startsWith("/") ? [] : openPath.split("/").filter(Boolean).slice(0, -1);
|
|
85
|
+
for (const part of pathname.split("/")) {
|
|
86
|
+
if (part === "" || part === ".") continue;
|
|
87
|
+
if (part === "..") {
|
|
88
|
+
if (folder.length === 0) return null;
|
|
89
|
+
folder.pop();
|
|
90
|
+
} else {
|
|
91
|
+
folder.push(part);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return folder.length > 0 ? folder.join("/") : null;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const el = (t: MdTag, c?: MdNode[], a?: MdAttributes): MdElement => ({
|
|
98
|
+
t,
|
|
99
|
+
...(a ? { a } : {}),
|
|
100
|
+
...(c ? { c } : {}),
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
function plainText(tokens: Token[] | undefined, fallback: string): string {
|
|
104
|
+
if (!tokens) return fallback;
|
|
105
|
+
return tokens
|
|
106
|
+
.map((token) => ("tokens" in token && token.tokens ? plainText(token.tokens, "") : token.raw))
|
|
107
|
+
.join("");
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function highlighted(code: string, language: string | undefined): MdNode[] {
|
|
111
|
+
const map = (node: ReturnType<typeof highlightNodes>[number]): MdNode =>
|
|
112
|
+
node.type === "text"
|
|
113
|
+
? node.value
|
|
114
|
+
: el("span", node.children.map(map), { className: node.classNames.join(" ") });
|
|
115
|
+
return highlightNodes(code, language).map(map);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const SECTION_PREFIX = /^(Requirement|Scenario):\s*/i;
|
|
119
|
+
const STEP_KEYWORDS = new Set(["GIVEN", "WHEN", "THEN", "AND", "BUT"]);
|
|
120
|
+
const NORMATIVE = /\b(SHALL NOT|SHALL|MUST NOT|MUST)\b/g;
|
|
121
|
+
|
|
122
|
+
/** OpenSpec's `Requirement:` (level 3) and `Scenario:` (level 4) headings open a section. */
|
|
123
|
+
function sectionKind(heading: Tokens.Heading): "requirement" | "scenario" | null {
|
|
124
|
+
const match = SECTION_PREFIX.exec(heading.text);
|
|
125
|
+
if (!match) return null;
|
|
126
|
+
const word = match[1]!.toLowerCase();
|
|
127
|
+
if (word === "requirement" && heading.depth === 3) return "requirement";
|
|
128
|
+
if (word === "scenario" && heading.depth >= 3) return "scenario";
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** A `- **WHEN** …` item as its keyword and the inline tokens after it. */
|
|
133
|
+
function stepOf(item: Tokens.ListItem): { keyword: string; rest: Token[] } | null {
|
|
134
|
+
const first = item.tokens[0];
|
|
135
|
+
if (item.task || first?.type !== "text") return null;
|
|
136
|
+
const inline = (first as Tokens.Text).tokens ?? [];
|
|
137
|
+
const lead = inline[0];
|
|
138
|
+
if (lead?.type !== "strong") return null;
|
|
139
|
+
const keyword = (lead as Tokens.Strong).text.trim().replace(/:$/, "").toUpperCase();
|
|
140
|
+
if (!STEP_KEYWORDS.has(keyword)) return null;
|
|
141
|
+
const rest = inline.slice(1);
|
|
142
|
+
const next = rest[0];
|
|
143
|
+
if (next?.type === "text") {
|
|
144
|
+
const text = next as Tokens.Text;
|
|
145
|
+
const trimmed = text.text.replace(/^[\s:]+/, "");
|
|
146
|
+
rest[0] = { ...text, raw: trimmed, text: trimmed, tokens: undefined };
|
|
147
|
+
}
|
|
148
|
+
return { keyword, rest };
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const headingTag = (heading: Tokens.Heading): MdTag =>
|
|
152
|
+
`h${Math.min(Math.max(heading.depth, 1), 6)}` as MdTag;
|
|
153
|
+
|
|
154
|
+
/** SHALL and MUST in a requirement's own paragraphs, so the obligation reads at a glance. */
|
|
155
|
+
function markNormative(node: MdNode): MdNode {
|
|
156
|
+
if (typeof node === "string" || node.t !== "p" || !node.c) return node;
|
|
157
|
+
return {
|
|
158
|
+
...node,
|
|
159
|
+
c: node.c.flatMap((child) =>
|
|
160
|
+
typeof child === "string"
|
|
161
|
+
? child
|
|
162
|
+
.split(NORMATIVE)
|
|
163
|
+
.filter((part) => part !== "")
|
|
164
|
+
.map((part) =>
|
|
165
|
+
/^(SHALL|MUST)( NOT)?$/.test(part)
|
|
166
|
+
? el("strong", [part], { className: "md-shall" })
|
|
167
|
+
: part,
|
|
168
|
+
)
|
|
169
|
+
: [child],
|
|
170
|
+
),
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** The same mapping the server-rendered vault used, producing data instead of markup. */
|
|
175
|
+
class TreeMapper {
|
|
176
|
+
constructor(
|
|
177
|
+
private readonly path: string,
|
|
178
|
+
private readonly guide?: GuideContext,
|
|
179
|
+
) {}
|
|
180
|
+
|
|
181
|
+
blocks(tokens: Token[] | undefined): MdNode[] {
|
|
182
|
+
const list = tokens ?? [];
|
|
183
|
+
const nodes: MdNode[] = [];
|
|
184
|
+
for (let index = 0; index < list.length; index += 1) {
|
|
185
|
+
const token = list[index]!;
|
|
186
|
+
const kind =
|
|
187
|
+
!this.guide && token.type === "heading" ? sectionKind(token as Tokens.Heading) : null;
|
|
188
|
+
if (!kind) {
|
|
189
|
+
nodes.push(...this.block(token));
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
// An OpenSpec section runs to the next heading at its own depth or above.
|
|
193
|
+
const heading = token as Tokens.Heading;
|
|
194
|
+
let end = index + 1;
|
|
195
|
+
while (end < list.length) {
|
|
196
|
+
const next = list[end]!;
|
|
197
|
+
if (next.type === "heading" && (next as Tokens.Heading).depth <= heading.depth) break;
|
|
198
|
+
end += 1;
|
|
199
|
+
}
|
|
200
|
+
const body = list.slice(index + 1, end);
|
|
201
|
+
nodes.push(
|
|
202
|
+
kind === "scenario" ? this.scenario(heading, body) : this.requirement(heading, body),
|
|
203
|
+
);
|
|
204
|
+
index = end - 1;
|
|
205
|
+
}
|
|
206
|
+
return nodes;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** `### Requirement: …`: the heading with its label, then its text, SHALL marked. */
|
|
210
|
+
private requirement(heading: Tokens.Heading, body: Token[]): MdElement {
|
|
211
|
+
return el(
|
|
212
|
+
"div",
|
|
213
|
+
[
|
|
214
|
+
el(
|
|
215
|
+
headingTag(heading),
|
|
216
|
+
[
|
|
217
|
+
el("span", ["Requirement"], { className: "md-section-label" }),
|
|
218
|
+
...this.titleOf(heading),
|
|
219
|
+
],
|
|
220
|
+
{ className: "md-requirement-title" },
|
|
221
|
+
),
|
|
222
|
+
...this.blocks(body).map(markNormative),
|
|
223
|
+
],
|
|
224
|
+
{ className: "md-requirement" },
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/** `#### Scenario: …` as one card; its `**WHEN**`-style list items become steps. */
|
|
229
|
+
private scenario(heading: Tokens.Heading, body: Token[]): MdElement {
|
|
230
|
+
return el(
|
|
231
|
+
"div",
|
|
232
|
+
[
|
|
233
|
+
el(
|
|
234
|
+
"p",
|
|
235
|
+
[el("span", ["Scenario"], { className: "md-section-label" }), ...this.titleOf(heading)],
|
|
236
|
+
{ className: "md-scenario-title" },
|
|
237
|
+
),
|
|
238
|
+
...body.flatMap((token) =>
|
|
239
|
+
token.type === "list"
|
|
240
|
+
? [this.steps(token as Tokens.List) ?? this.list(token as Tokens.List)]
|
|
241
|
+
: this.block(token),
|
|
242
|
+
),
|
|
243
|
+
],
|
|
244
|
+
{ className: "md-scenario" },
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/** A section heading's text without its `Requirement:` or `Scenario:` prefix. */
|
|
249
|
+
private titleOf(heading: Tokens.Heading): MdNode[] {
|
|
250
|
+
const tokens = heading.tokens ?? [];
|
|
251
|
+
const first = tokens[0];
|
|
252
|
+
if (first?.type !== "text") return this.inline(tokens, heading.text);
|
|
253
|
+
const text = (first as Tokens.Text).text.replace(SECTION_PREFIX, "");
|
|
254
|
+
return [text, ...tokens.slice(1).map((token) => this.span(token))].filter(
|
|
255
|
+
(node) => node !== "",
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
inline(tokens: Token[] | undefined, fallback = ""): MdNode[] {
|
|
260
|
+
if (!tokens) return [fallback];
|
|
261
|
+
return tokens.map((token) => this.span(token));
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
private block(token: Token): MdNode[] {
|
|
265
|
+
switch (token.type) {
|
|
266
|
+
case "space":
|
|
267
|
+
case "def":
|
|
268
|
+
return [];
|
|
269
|
+
case "heading": {
|
|
270
|
+
const heading = token as Tokens.Heading;
|
|
271
|
+
return [
|
|
272
|
+
el(
|
|
273
|
+
headingTag(heading),
|
|
274
|
+
this.inline(heading.tokens, heading.text),
|
|
275
|
+
this.guide ? { id: this.guide.heading(heading.text) } : undefined,
|
|
276
|
+
),
|
|
277
|
+
];
|
|
278
|
+
}
|
|
279
|
+
case "paragraph": {
|
|
280
|
+
const paragraph = token as Tokens.Paragraph;
|
|
281
|
+
return [el("p", this.inline(paragraph.tokens, paragraph.text))];
|
|
282
|
+
}
|
|
283
|
+
case "text": {
|
|
284
|
+
const text = token as Tokens.Text;
|
|
285
|
+
return [el("p", this.inline(text.tokens, text.text))];
|
|
286
|
+
}
|
|
287
|
+
case "code": {
|
|
288
|
+
const code = token as Tokens.Code;
|
|
289
|
+
const language = code.lang?.trim().split(/\s+/, 1)[0] || undefined;
|
|
290
|
+
return [
|
|
291
|
+
el("pre", [el("code", highlighted(code.text, language))], { className: "md-fence" }),
|
|
292
|
+
];
|
|
293
|
+
}
|
|
294
|
+
case "blockquote":
|
|
295
|
+
return [el("blockquote", this.blocks((token as Tokens.Blockquote).tokens))];
|
|
296
|
+
case "hr":
|
|
297
|
+
return [el("hr")];
|
|
298
|
+
case "list":
|
|
299
|
+
return [this.list(token as Tokens.List)];
|
|
300
|
+
case "table":
|
|
301
|
+
return [this.table(token as Tokens.Table)];
|
|
302
|
+
case "html":
|
|
303
|
+
// Raw markup is shown as the text it is, never inserted.
|
|
304
|
+
return [el("p", [(token as Tokens.HTML).raw.trim()], { className: "md-raw" })];
|
|
305
|
+
default:
|
|
306
|
+
return [el("p", [token.raw])];
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/** A scenario's list as keyword steps, or `null` unless every item is a step. */
|
|
311
|
+
private steps(list: Tokens.List): MdElement | null {
|
|
312
|
+
const steps = list.items.map(stepOf);
|
|
313
|
+
if (!steps.every((step) => step !== null)) return null;
|
|
314
|
+
return el(
|
|
315
|
+
"ul",
|
|
316
|
+
steps.map(({ keyword, rest }) =>
|
|
317
|
+
el(
|
|
318
|
+
"li",
|
|
319
|
+
[
|
|
320
|
+
el("span", [keyword], { className: `md-step-key md-key-${keyword.toLowerCase()}` }),
|
|
321
|
+
el("span", this.inline(rest)),
|
|
322
|
+
],
|
|
323
|
+
{ className: "md-step" },
|
|
324
|
+
),
|
|
325
|
+
),
|
|
326
|
+
{ className: "md-steps" },
|
|
327
|
+
);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
private list(list: Tokens.List): MdElement {
|
|
331
|
+
const start =
|
|
332
|
+
list.ordered && typeof list.start === "number" && list.start !== 1 ? list.start : undefined;
|
|
333
|
+
return el(
|
|
334
|
+
list.ordered ? "ol" : "ul",
|
|
335
|
+
list.items.map((item) => {
|
|
336
|
+
const body = item.tokens.filter((token) => token.type !== "checkbox");
|
|
337
|
+
const content = item.loose ? this.blocks(body) : this.tight(body);
|
|
338
|
+
return el(
|
|
339
|
+
"li",
|
|
340
|
+
item.task ? [el("input", undefined, { checked: !!item.checked }), ...content] : content,
|
|
341
|
+
item.task ? { className: "md-task" } : undefined,
|
|
342
|
+
);
|
|
343
|
+
}),
|
|
344
|
+
start !== undefined ? { start } : undefined,
|
|
345
|
+
);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/** A tight item's text sits in the item, not in a paragraph of its own. */
|
|
349
|
+
private tight(tokens: Token[]): MdNode[] {
|
|
350
|
+
return tokens.flatMap((token) =>
|
|
351
|
+
token.type === "text"
|
|
352
|
+
? this.inline((token as Tokens.Text).tokens, (token as Tokens.Text).text)
|
|
353
|
+
: this.block(token),
|
|
354
|
+
);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
private table(table: Tokens.Table): MdElement {
|
|
358
|
+
const cell = (tag: "th" | "td", value: Tokens.TableCell) =>
|
|
359
|
+
el(
|
|
360
|
+
tag,
|
|
361
|
+
this.inline(value.tokens, value.text),
|
|
362
|
+
value.align ? { align: value.align } : undefined,
|
|
363
|
+
);
|
|
364
|
+
return el(
|
|
365
|
+
"div",
|
|
366
|
+
[
|
|
367
|
+
el("table", [
|
|
368
|
+
el("thead", [
|
|
369
|
+
el(
|
|
370
|
+
"tr",
|
|
371
|
+
table.header.map((value) => cell("th", value)),
|
|
372
|
+
),
|
|
373
|
+
]),
|
|
374
|
+
el(
|
|
375
|
+
"tbody",
|
|
376
|
+
table.rows.map((row) =>
|
|
377
|
+
el(
|
|
378
|
+
"tr",
|
|
379
|
+
row.map((value) => cell("td", value)),
|
|
380
|
+
),
|
|
381
|
+
),
|
|
382
|
+
),
|
|
383
|
+
]),
|
|
384
|
+
],
|
|
385
|
+
{ className: "md-table" },
|
|
386
|
+
);
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
private span(token: Token): MdNode {
|
|
390
|
+
switch (token.type) {
|
|
391
|
+
case "text": {
|
|
392
|
+
const text = token as Tokens.Text;
|
|
393
|
+
return text.tokens ? el("span", this.inline(text.tokens)) : text.text;
|
|
394
|
+
}
|
|
395
|
+
case "escape":
|
|
396
|
+
return (token as Tokens.Escape).text;
|
|
397
|
+
case "strong":
|
|
398
|
+
return el("strong", this.inline((token as Tokens.Strong).tokens));
|
|
399
|
+
case "em":
|
|
400
|
+
return el("em", this.inline((token as Tokens.Em).tokens));
|
|
401
|
+
case "del":
|
|
402
|
+
return el("del", this.inline((token as Tokens.Del).tokens));
|
|
403
|
+
case "codespan":
|
|
404
|
+
return el("code", [(token as Tokens.Codespan).text]);
|
|
405
|
+
case "br":
|
|
406
|
+
return el("br");
|
|
407
|
+
case "link":
|
|
408
|
+
return this.link(token as Tokens.Link);
|
|
409
|
+
case "image": {
|
|
410
|
+
// Not requested or shown: only what the author said the image is.
|
|
411
|
+
const image = token as Tokens.Image;
|
|
412
|
+
return image.text || plainText(image.tokens, "");
|
|
413
|
+
}
|
|
414
|
+
case "html":
|
|
415
|
+
return (token as Tokens.HTML).raw;
|
|
416
|
+
default:
|
|
417
|
+
return token.raw;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
private link(link: Tokens.Link): MdNode {
|
|
422
|
+
const label = this.inline(link.tokens, link.text);
|
|
423
|
+
if (/^https?:\/\//i.test(link.href)) return el("a", label, { href: link.href });
|
|
424
|
+
if (this.guide) return el("a", label, this.guide.link(link.href));
|
|
425
|
+
const note = resolveNoteLink(link.href, this.path);
|
|
426
|
+
return note === null ? el("span", label) : el("a", label, { note });
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
interface GuideContext {
|
|
431
|
+
heading(text: string): string;
|
|
432
|
+
link(target: string): { guide: string } | { href: string };
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
/**
|
|
436
|
+
* Bundled Markdown only; rejects constructs the reader cannot faithfully render.
|
|
437
|
+
* A `routes` value that is an `https:` URL links out instead of to a guide topic.
|
|
438
|
+
*/
|
|
439
|
+
export function guideTree(
|
|
440
|
+
source: string,
|
|
441
|
+
path: string,
|
|
442
|
+
routes: Readonly<Record<string, string>>,
|
|
443
|
+
): MdNode[] {
|
|
444
|
+
const body = source.replace(FRONTMATTER, "");
|
|
445
|
+
const tokens = new Lexer({ gfm: true }).lex(body);
|
|
446
|
+
const fail = (value: string): never => {
|
|
447
|
+
throw new Error(`${path}: ${value}`);
|
|
448
|
+
};
|
|
449
|
+
const validate = (items: Token[]): void => {
|
|
450
|
+
for (const token of items) {
|
|
451
|
+
if (token.type === "code" || token.type === "codespan" || token.type === "escape") continue;
|
|
452
|
+
if (token.type === "html" || token.type === "image")
|
|
453
|
+
fail(`unsupported ${token.type}: ${token.raw}`);
|
|
454
|
+
if (
|
|
455
|
+
token.type === "text" &&
|
|
456
|
+
!("tokens" in token && token.tokens) &&
|
|
457
|
+
/[{}]|^\s*(?:import|export)\s/m.test(token.raw)
|
|
458
|
+
)
|
|
459
|
+
fail(`unsupported MDX: ${token.raw}`);
|
|
460
|
+
if ("tokens" in token && token.tokens) validate(token.tokens);
|
|
461
|
+
if (token.type === "list")
|
|
462
|
+
for (const item of (token as Tokens.List).items) {
|
|
463
|
+
if (item.task) fail("unsupported task list");
|
|
464
|
+
validate(item.tokens);
|
|
465
|
+
}
|
|
466
|
+
if (token.type === "table") {
|
|
467
|
+
const table = token as Tokens.Table;
|
|
468
|
+
for (const cell of [...table.header, ...table.rows.flat()]) validate(cell.tokens);
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
};
|
|
472
|
+
validate(tokens);
|
|
473
|
+
const counts = new Map<string, number>();
|
|
474
|
+
return new TreeMapper(path, {
|
|
475
|
+
heading(text) {
|
|
476
|
+
const slug = text
|
|
477
|
+
.toLowerCase()
|
|
478
|
+
.replace(/[^\p{L}\p{N}_\s-]/gu, "")
|
|
479
|
+
.replace(/\s/g, "-");
|
|
480
|
+
const count = counts.get(slug) ?? 0;
|
|
481
|
+
counts.set(slug, count + 1);
|
|
482
|
+
return count ? `${slug}-${count}` : slug;
|
|
483
|
+
},
|
|
484
|
+
link(target) {
|
|
485
|
+
if (target.startsWith("#")) return { guide: target };
|
|
486
|
+
const [page, fragment] = target.split("#");
|
|
487
|
+
const hash = fragment === undefined ? "" : `#${fragment}`;
|
|
488
|
+
const route = page && Object.hasOwn(routes, page) ? routes[page] : undefined;
|
|
489
|
+
if (!route) return fail(`unresolved or unsafe guide link: ${target}`);
|
|
490
|
+
return route.startsWith("https://")
|
|
491
|
+
? { href: `${route}${hash}` }
|
|
492
|
+
: { guide: `${route}${hash}` };
|
|
493
|
+
},
|
|
494
|
+
}).blocks(tokens);
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
/** A markdown file as data the browser renders; `path` is where its relative links start. */
|
|
498
|
+
export function markdownTree(source: string, path: string): MdNode[] {
|
|
499
|
+
const match = FRONTMATTER.exec(source);
|
|
500
|
+
const body = match ? source.slice(match[0].length) : source;
|
|
501
|
+
const nodes = new TreeMapper(path).blocks(new Lexer({ gfm: true }).lex(body));
|
|
502
|
+
return match ? [frontmatter(match[1] ?? match[2] ?? ""), ...nodes] : nodes;
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
/** A text file that is not markdown as one highlighted block; `language` may be an extension. */
|
|
506
|
+
export function codeTree(source: string, language: string | undefined): MdNode[] {
|
|
507
|
+
return [el("pre", [el("code", highlighted(source, language))], { className: "md-fence" })];
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
/** `---` YAML, or the `<!-- mate:delta … -->` header Mate writes atop a change's spec delta. */
|
|
511
|
+
const FRONTMATTER =
|
|
512
|
+
/^(?:---[ \t]*\r?\n([\s\S]*?)\r?\n---|<!--[ \t]*mate:delta[ \t]*\r?\n([\s\S]*?)\r?\n[ \t]*-->)[ \t]*(?:\r?\n|$)/;
|
|
513
|
+
/** Nesting shown as fields; deeper values fall back to their JSON text. */
|
|
514
|
+
const FIELD_DEPTH = 2;
|
|
515
|
+
|
|
516
|
+
/** A file's leading YAML block as fields; text that is not a mapping is shown as written. */
|
|
517
|
+
function frontmatter(yaml: string): MdElement {
|
|
518
|
+
let data: unknown;
|
|
519
|
+
try {
|
|
520
|
+
data = parseYaml(yaml);
|
|
521
|
+
} catch {
|
|
522
|
+
data = undefined;
|
|
523
|
+
}
|
|
524
|
+
const fields = isRecord(data)
|
|
525
|
+
? fieldList(data, 0)
|
|
526
|
+
: el("pre", [el("code", [yaml])], { className: "md-fence" });
|
|
527
|
+
return el("div", [fields], { className: "md-frontmatter" });
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
const isRecord = (value: unknown): value is Record<string, unknown> =>
|
|
531
|
+
typeof value === "object" && value !== null && !Array.isArray(value);
|
|
532
|
+
|
|
533
|
+
/** Only scalar values, so the mapping fits on one chip. */
|
|
534
|
+
const flat = (record: Record<string, unknown>): boolean =>
|
|
535
|
+
Object.values(record).every((entry) => entry === null || typeof entry !== "object");
|
|
536
|
+
|
|
537
|
+
interface Scope {
|
|
538
|
+
repository: string;
|
|
539
|
+
area: string;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
/** A `scopes` entry: exactly a repository and one of its Areas. */
|
|
543
|
+
const isScope = (value: unknown): value is Scope =>
|
|
544
|
+
isRecord(value) &&
|
|
545
|
+
Object.keys(value).length === 2 &&
|
|
546
|
+
typeof value.repository === "string" &&
|
|
547
|
+
typeof value.area === "string";
|
|
548
|
+
|
|
549
|
+
/** Scopes grouped by repository, in first-seen order, each Area a chip; `.` is its root. */
|
|
550
|
+
function scopeGroups(scopes: Scope[]): MdNode[] {
|
|
551
|
+
const areasByRepository = new Map<string, string[]>();
|
|
552
|
+
for (const { repository, area } of scopes) {
|
|
553
|
+
areasByRepository.set(repository, [...(areasByRepository.get(repository) ?? []), area]);
|
|
554
|
+
}
|
|
555
|
+
return [...areasByRepository].map(([repository, areas]) =>
|
|
556
|
+
el(
|
|
557
|
+
"div",
|
|
558
|
+
[
|
|
559
|
+
el("span", [repository], { className: "md-scope-repo" }),
|
|
560
|
+
...areas.map((area) =>
|
|
561
|
+
area === "."
|
|
562
|
+
? el("span", ["root"], { className: "md-chip md-chip-root" })
|
|
563
|
+
: el("span", [area], { className: "md-chip" }),
|
|
564
|
+
),
|
|
565
|
+
],
|
|
566
|
+
{ className: "md-scope" },
|
|
567
|
+
),
|
|
568
|
+
);
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
function fieldList(data: Record<string, unknown>, depth: number): MdElement {
|
|
572
|
+
return el(
|
|
573
|
+
"dl",
|
|
574
|
+
Object.entries(data).flatMap(([name, value]) => [
|
|
575
|
+
el("dt", [name]),
|
|
576
|
+
el("dd", fieldValue(value, depth)),
|
|
577
|
+
]),
|
|
578
|
+
);
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
function fieldValue(value: unknown, depth: number): MdNode[] {
|
|
582
|
+
if (value === null || value === undefined || value === "") {
|
|
583
|
+
return [el("span", ["empty"], { className: "md-field-empty" })];
|
|
584
|
+
}
|
|
585
|
+
if (value instanceof Date) return [value.toISOString().slice(0, 10)];
|
|
586
|
+
if (Array.isArray(value) && value.every((item) => !isRecord(item) && !Array.isArray(item))) {
|
|
587
|
+
return value.map((item) => el("span", [String(item)], { className: "md-chip" }));
|
|
588
|
+
}
|
|
589
|
+
if (Array.isArray(value) && value.length > 0 && value.every(isScope)) return scopeGroups(value);
|
|
590
|
+
// A list of small mappings reads as one chip per item.
|
|
591
|
+
if (Array.isArray(value) && value.every((item) => isRecord(item) && flat(item))) {
|
|
592
|
+
return value.map((item) =>
|
|
593
|
+
el("span", [Object.values(item).map(String).join(" · ")], { className: "md-chip" }),
|
|
594
|
+
);
|
|
595
|
+
}
|
|
596
|
+
if (isRecord(value) && depth < FIELD_DEPTH) return [fieldList(value, depth + 1)];
|
|
597
|
+
if (typeof value === "object") return [el("code", [JSON.stringify(value)])];
|
|
598
|
+
return [String(value)];
|
|
599
|
+
}
|