@uniqbit/mate-core 0.18.5 → 0.20.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 +41 -2
- 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 +17 -2
- package/opencode-plugin/src/tui.tsx +3 -1
- package/opencode-plugin/tui.tsx +4 -1
- package/package.json +52 -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 +127 -0
- package/src/cli/commands/artifact/delivery/link.ts +191 -0
- package/src/cli/commands/artifact/delivery/output.ts +97 -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 +143 -48
- package/src/cli/commands/doctor.ts +317 -7
- package/src/cli/commands/factory/factory.ts +301 -0
- package/src/cli/commands/install.ts +133 -9
- package/src/cli/commands/launch/shared.ts +16 -11
- package/src/cli/commands/plugin/install.ts +9 -4
- 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 +20 -1
- package/src/cli/commands/report/markdown.ts +110 -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/studio/companion-removal.ts +79 -0
- package/src/cli/commands/studio/factory-credential.ts +49 -0
- package/src/cli/commands/studio/index.ts +29 -2
- 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 +260 -15
- package/src/cli/commands/studio/routes.ts +41 -6
- package/src/cli/commands/studio/selection.ts +161 -17
- package/src/cli/commands/studio/server.ts +429 -326
- package/src/cli/commands/studio/services.ts +80 -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 +85 -15
- 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 +518 -0
- package/src/cli/commands/studio/views/vault/view.ts +185 -0
- package/src/cli/commands/studio/workset-session.ts +131 -0
- package/src/cli/commands/unwrap.ts +16 -0
- package/src/cli/commands/update.ts +53 -9
- package/src/cli/commands/vscode/setup.ts +155 -0
- package/src/cli/commands/vscode/vsix.ts +73 -0
- package/src/cli/commands/working/cleanup.ts +44 -11
- 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 +406 -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 +31 -3
- 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/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 +90 -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/branches.ts +147 -0
- package/src/lib/delivery/environment.ts +35 -0
- package/src/lib/delivery/forge.ts +279 -0
- package/src/lib/delivery/merge-git.ts +261 -0
- package/src/lib/delivery/overlap.ts +209 -0
- package/src/lib/delivery/record-delivery.ts +338 -0
- package/src/lib/delivery/record.ts +405 -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 +383 -0
- package/src/lib/delivery/stages.ts +111 -0
- package/src/lib/delivery/token.ts +24 -0
- package/src/lib/factory/attach-client.ts +113 -0
- package/src/lib/factory/attach.ts +178 -0
- package/src/lib/factory/broker.ts +190 -0
- package/src/lib/factory/bun-commands.ts +39 -0
- package/src/lib/factory/client.ts +92 -0
- package/src/lib/factory/command.ts +61 -0
- package/src/lib/factory/credential-store.ts +153 -0
- package/src/lib/factory/frames.ts +77 -0
- package/src/lib/factory/ids.ts +58 -0
- package/src/lib/factory/keyed-serial.ts +27 -0
- package/src/lib/factory/outcomes/actions.ts +114 -0
- package/src/lib/factory/outcomes/index.ts +391 -0
- package/src/lib/factory/outcomes/lifecycle.ts +205 -0
- package/src/lib/factory/outcomes/runs.ts +81 -0
- package/src/lib/factory/outcomes/sessions.ts +38 -0
- package/src/lib/factory/prepare.ts +49 -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 +416 -0
- package/src/lib/factory/runner/state.ts +233 -0
- package/src/lib/factory/runner/workflow.ts +542 -0
- package/src/lib/factory/runtime.ts +981 -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-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/framework-context.ts +26 -14
- package/src/lib/orchestrator/global-config-store.ts +11 -0
- package/src/lib/orchestrator/launcher.ts +15 -2
- 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-links.ts +206 -0
- package/src/lib/orchestrator/projection-claude-skills.ts +37 -129
- package/src/lib/orchestrator/projection-companion-link.ts +12 -1
- package/src/lib/orchestrator/projection-entries.ts +100 -34
- package/src/lib/orchestrator/projection-opencode-copies.ts +32 -15
- package/src/lib/orchestrator/projection-openspec-store.ts +54 -9
- package/src/lib/orchestrator/projection-runtime-documents.ts +15 -6
- package/src/lib/orchestrator/projection-types.ts +36 -1
- package/src/lib/orchestrator/refresh-working-claude-links.ts +87 -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 +81 -11
- package/src/lib/orchestrator/setup-compatibilities.ts +56 -70
- package/src/lib/orchestrator/types.ts +12 -2
- package/src/lib/orchestrator/working-repo-projection.ts +50 -7
- 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 +22 -1
- package/src/lib/package-paths.ts +37 -0
- package/src/lib/public-npm.ts +17 -0
- package/src/lib/runtime-directory-refresh.ts +17 -1
- package/src/lib/session-attribution.ts +52 -0
- package/src/lib/session-state.ts +285 -0
- package/src/lib/session-stop.ts +64 -0
- package/src/lib/workset/record.ts +533 -0
- package/src/lib/workset/repositories.ts +55 -0
- package/src/lib/workset/stage.ts +148 -0
- package/src/lib/workset/stages.ts +113 -0
- package/src/lib/workset/worktree-index.ts +116 -0
- package/src/lib/workset/worktree.ts +898 -0
- package/src/opencode/background-server.ts +145 -0
- package/src/opencode/companion-hooks.ts +111 -7
- package/src/opencode/companion-policy.ts +39 -20
- package/src/opencode/enter-worktree.ts +72 -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-delivery-plan.ts +121 -11
- package/src/runtime/commit-attribution-guard.ts +181 -0
- package/src/runtime/companion-git.ts +52 -10
- package/src/runtime/companion-guidance.ts +20 -8
- package/src/runtime/companion-instructions.ts +340 -0
- package/src/runtime/companion-lock.ts +30 -7
- package/src/runtime/current-branch.ts +10 -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/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-local.ts +6 -1
- package/src/runtime/runtime-directory.ts +5 -0
- package/src/runtime/runtime-document-manifest.ts +62 -11
- package/src/runtime/secret-guard.ts +162 -0
- package/src/runtime/secret-patterns.ts +397 -0
- package/src/runtime/secret-scan.ts +90 -0
- package/src/runtime/serving-claude-wrap.ts +28 -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/wrap-state.ts +75 -2
- package/src/runtime/write-atomic.ts +64 -0
- package/src/studio.ts +126 -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 +162 -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/{claude/mate-openspec-backfill → agents/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 +66 -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 +102 -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-artifact-publish → mate-publish-artifact}/SKILL.md +109 -24
- 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 +95 -16
- package/src/templates/mate-skills/agents/mate-simplify-code/SKILL.md +87 -68
- package/src/templates/mate-skills/claude/mate-apply-change/SKILL.md +162 -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/{agents/mate-openspec-backfill → claude/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 +66 -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 +102 -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-artifact-publish → mate-publish-artifact}/SKILL.md +109 -24
- 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 +95 -16
- package/src/templates/mate-skills/claude/mate-simplify-code/SKILL.md +87 -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 +4340 -419
- 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 +4 -0
- package/src/tools/setup/capabilities/tokensave.ts +113 -71
- package/src/tools/setup/context-services.ts +9 -17
- package/src/tools/setup/dynamic-plugins/hydrate.ts +4 -3
- package/src/tools/setup/dynamic-plugins/install.ts +24 -28
- 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 +86 -11
- package/src/tools/setup/package-managers/uv.ts +73 -11
- package/src/tools/setup/plugin.ts +40 -0
- 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 +77 -19
- package/src/tools/setup/providers/claude-worktree-plugins.ts +122 -0
- package/src/tools/setup/providers/claude.ts +310 -8
- package/src/tools/setup/providers/opencode.ts +180 -1
- package/src/tools/setup/utils.ts +18 -4
- package/src/tools/setup/working-repo-cleanup.ts +29 -1
- package/src/tools/setup/working-repo-local-state.ts +252 -75
- package/src/tools/setup.ts +183 -26
- package/studio-dist/client/assets/app-CdPiFv59.css +2 -0
- package/studio-dist/client/assets/button-BIIHE0EQ.js +3 -0
- package/studio-dist/client/assets/companion-view-DM6YyXaR.js +1 -0
- package/studio-dist/client/assets/delivery-path-DELxj0Av.js +1 -0
- package/studio-dist/client/assets/dist-Dm7MtyHc.js +5 -0
- package/studio-dist/client/assets/factory-BZy0E8ty.js +4 -0
- package/studio-dist/client/assets/index-B3wkMzjA.js +40 -0
- package/studio-dist/client/assets/markdown-view-pQ2Qp_i5.js +1 -0
- package/studio-dist/client/assets/panel-CbajlC3p.js +1 -0
- package/studio-dist/client/assets/preload-helper-BLdHbfdN.js +1 -0
- package/studio-dist/client/assets/prepaint-CwSrpdFA.js +27 -0
- package/studio-dist/client/assets/react-CN2GSx7x.js +1 -0
- package/studio-dist/client/assets/reports-DllhYQ5_.js +1 -0
- package/studio-dist/client/assets/rolldown-runtime-WkwZ5CU-.js +1 -0
- package/studio-dist/client/assets/routes-COm-G3mK.js +1 -0
- package/studio-dist/client/assets/skills-DmWAy-jZ.js +1 -0
- package/studio-dist/client/assets/specs-BG3Wi3ln.js +1 -0
- package/studio-dist/client/assets/steps-DFsH3Neu.js +1 -0
- package/studio-dist/client/assets/terminal-eU5fzQzv.css +1 -0
- package/studio-dist/client/assets/vault-B2q1nBY5.js +1 -0
- package/studio-dist/client/assets/warnings-BSXIyuSQ.js +1 -0
- package/studio-dist/client/assets/wasm-inline-C2en61B5.js +1 -0
- package/studio-dist/client/assets/workflow-DlsQD6Hc.js +1 -0
- package/studio-dist/server/assets/__23tanstack-start-server-fn-resolver-M2GBs8s3.js +4051 -0
- package/studio-dist/server/assets/_tanstack-start-manifest_v.js +95 -0
- package/studio-dist/server/assets/actions-Bvgj9eb8.js +54 -0
- package/studio-dist/server/assets/actions-D8erOphH.js +44 -0
- package/studio-dist/server/assets/button-CIJqAhni.js +11929 -0
- package/studio-dist/server/assets/companion-view-DISASvdJ.js +39 -0
- package/studio-dist/server/assets/companions-BYbHWKOZ.js +15 -0
- package/studio-dist/server/assets/createServerFn-F5sAOF8V.js +459 -0
- package/studio-dist/server/assets/createServerRpc-tK2lE9R2.js +11 -0
- package/studio-dist/server/assets/delivery-path-C29fBynY.js +654 -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-DGPmNGbo.js +69 -0
- package/studio-dist/server/assets/factory-DUTa0eDs.js +2172 -0
- package/studio-dist/server/assets/markdown-view-Bn7xPdks.js +86 -0
- package/studio-dist/server/assets/model-PyPALjii.js +18 -0
- package/studio-dist/server/assets/panel-3Jmn4awF.js +169 -0
- package/studio-dist/server/assets/prepaint-DJfTQ_VH.js +45 -0
- package/studio-dist/server/assets/react-Ce6dj15C.js +46 -0
- package/studio-dist/server/assets/reports-C06RXVE2.js +18 -0
- package/studio-dist/server/assets/reports-D6YMqhnO.js +142 -0
- package/studio-dist/server/assets/rolldown-runtime-DYf_mQCB.js +34 -0
- package/studio-dist/server/assets/router-C8MGqlAY.js +13713 -0
- package/studio-dist/server/assets/routes-BcFgvqf7.js +622 -0
- package/studio-dist/server/assets/search-JAKurDNh.js +36 -0
- package/studio-dist/server/assets/shell-DS3wUexh.js +52 -0
- package/studio-dist/server/assets/skills-BEnOxiDl.js +266 -0
- package/studio-dist/server/assets/skills-CtrBAtX3.js +28 -0
- package/studio-dist/server/assets/specs-C8rv34-5.js +211 -0
- package/studio-dist/server/assets/start-h3ICWwd2.js +36 -0
- package/studio-dist/server/assets/steps-Dq_CwY_s.js +181 -0
- package/studio-dist/server/assets/studio-BeltxxKt.js +216 -0
- package/studio-dist/server/assets/utils-C9CX1kcy.js +221 -0
- package/studio-dist/server/assets/vault-BmWnryh3.js +85 -0
- package/studio-dist/server/assets/vault-Fvxt2Tzl.js +1032 -0
- package/studio-dist/server/assets/views-BgYa-za2.js +80 -0
- package/studio-dist/server/assets/warnings-DzR6fyZh.js +23 -0
- package/studio-dist/server/assets/wasm-inline-CNeBKGwC.js +3 -0
- package/studio-dist/server/assets/workflow-liRYecHk.js +73 -0
- package/studio-dist/server/server.js +16066 -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/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/tools/setup/git-utils.ts +0 -30
- package/src/tools/setup/runtime-documents.ts +0 -291
|
@@ -0,0 +1,518 @@
|
|
|
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
|
+
}
|
|
62
|
+
|
|
63
|
+
const MARKDOWN_TARGET = /\.(md|markdown)$/i;
|
|
64
|
+
const SCHEME = /^[a-z][a-z0-9+.-]*:/i;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* A relative link as a companion-relative markdown path, or `null` when it is anything
|
|
68
|
+
* else. Textual only: nothing is looked up on disk, so a missing note is the vault's to refuse.
|
|
69
|
+
*/
|
|
70
|
+
export function resolveNoteLink(target: string, openPath: string): string | null {
|
|
71
|
+
if (!target || SCHEME.test(target) || target.startsWith("//") || target.startsWith("#")) {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
let pathname = target.split(/[?#]/, 1)[0] ?? "";
|
|
75
|
+
try {
|
|
76
|
+
pathname = decodeURIComponent(pathname);
|
|
77
|
+
} catch {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
if (pathname.includes("\\") || !MARKDOWN_TARGET.test(pathname)) return null;
|
|
81
|
+
const folder = pathname.startsWith("/") ? [] : openPath.split("/").filter(Boolean).slice(0, -1);
|
|
82
|
+
for (const part of pathname.split("/")) {
|
|
83
|
+
if (part === "" || part === ".") continue;
|
|
84
|
+
if (part === "..") {
|
|
85
|
+
if (folder.length === 0) return null;
|
|
86
|
+
folder.pop();
|
|
87
|
+
} else {
|
|
88
|
+
folder.push(part);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return folder.length > 0 ? folder.join("/") : null;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const el = (t: MdTag, c?: MdNode[], a?: MdAttributes): MdElement => ({
|
|
95
|
+
t,
|
|
96
|
+
...(a ? { a } : {}),
|
|
97
|
+
...(c ? { c } : {}),
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
function plainText(tokens: Token[] | undefined, fallback: string): string {
|
|
101
|
+
if (!tokens) return fallback;
|
|
102
|
+
return tokens
|
|
103
|
+
.map((token) => ("tokens" in token && token.tokens ? plainText(token.tokens, "") : token.raw))
|
|
104
|
+
.join("");
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function highlighted(code: string, language: string | undefined): MdNode[] {
|
|
108
|
+
const map = (node: ReturnType<typeof highlightNodes>[number]): MdNode =>
|
|
109
|
+
node.type === "text"
|
|
110
|
+
? node.value
|
|
111
|
+
: el("span", node.children.map(map), { className: node.classNames.join(" ") });
|
|
112
|
+
return highlightNodes(code, language).map(map);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const SECTION_PREFIX = /^(Requirement|Scenario):\s*/i;
|
|
116
|
+
const STEP_KEYWORDS = new Set(["GIVEN", "WHEN", "THEN", "AND", "BUT"]);
|
|
117
|
+
const NORMATIVE = /\b(SHALL NOT|SHALL|MUST NOT|MUST)\b/g;
|
|
118
|
+
|
|
119
|
+
/** OpenSpec's `Requirement:` (level 3) and `Scenario:` (level 4) headings open a section. */
|
|
120
|
+
function sectionKind(heading: Tokens.Heading): "requirement" | "scenario" | null {
|
|
121
|
+
const match = SECTION_PREFIX.exec(heading.text);
|
|
122
|
+
if (!match) return null;
|
|
123
|
+
const word = match[1]!.toLowerCase();
|
|
124
|
+
if (word === "requirement" && heading.depth === 3) return "requirement";
|
|
125
|
+
if (word === "scenario" && heading.depth >= 3) return "scenario";
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** A `- **WHEN** …` item as its keyword and the inline tokens after it. */
|
|
130
|
+
function stepOf(item: Tokens.ListItem): { keyword: string; rest: Token[] } | null {
|
|
131
|
+
const first = item.tokens[0];
|
|
132
|
+
if (item.task || first?.type !== "text") return null;
|
|
133
|
+
const inline = (first as Tokens.Text).tokens ?? [];
|
|
134
|
+
const lead = inline[0];
|
|
135
|
+
if (lead?.type !== "strong") return null;
|
|
136
|
+
const keyword = (lead as Tokens.Strong).text.trim().replace(/:$/, "").toUpperCase();
|
|
137
|
+
if (!STEP_KEYWORDS.has(keyword)) return null;
|
|
138
|
+
const rest = inline.slice(1);
|
|
139
|
+
const next = rest[0];
|
|
140
|
+
if (next?.type === "text") {
|
|
141
|
+
const text = next as Tokens.Text;
|
|
142
|
+
const trimmed = text.text.replace(/^[\s:]+/, "");
|
|
143
|
+
rest[0] = { ...text, raw: trimmed, text: trimmed, tokens: undefined };
|
|
144
|
+
}
|
|
145
|
+
return { keyword, rest };
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const headingTag = (heading: Tokens.Heading): MdTag =>
|
|
149
|
+
`h${Math.min(Math.max(heading.depth, 1), 6)}` as MdTag;
|
|
150
|
+
|
|
151
|
+
/** SHALL and MUST in a requirement's own paragraphs, so the obligation reads at a glance. */
|
|
152
|
+
function markNormative(node: MdNode): MdNode {
|
|
153
|
+
if (typeof node === "string" || node.t !== "p" || !node.c) return node;
|
|
154
|
+
return {
|
|
155
|
+
...node,
|
|
156
|
+
c: node.c.flatMap((child) =>
|
|
157
|
+
typeof child === "string"
|
|
158
|
+
? child
|
|
159
|
+
.split(NORMATIVE)
|
|
160
|
+
.filter((part) => part !== "")
|
|
161
|
+
.map((part) =>
|
|
162
|
+
/^(SHALL|MUST)( NOT)?$/.test(part)
|
|
163
|
+
? el("strong", [part], { className: "md-shall" })
|
|
164
|
+
: part,
|
|
165
|
+
)
|
|
166
|
+
: [child],
|
|
167
|
+
),
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** The same mapping the server-rendered vault used, producing data instead of markup. */
|
|
172
|
+
class TreeMapper {
|
|
173
|
+
constructor(private readonly path: string) {}
|
|
174
|
+
|
|
175
|
+
blocks(tokens: Token[] | undefined): MdNode[] {
|
|
176
|
+
const list = tokens ?? [];
|
|
177
|
+
const nodes: MdNode[] = [];
|
|
178
|
+
for (let index = 0; index < list.length; index += 1) {
|
|
179
|
+
const token = list[index]!;
|
|
180
|
+
const kind = token.type === "heading" ? sectionKind(token as Tokens.Heading) : null;
|
|
181
|
+
if (!kind) {
|
|
182
|
+
nodes.push(...this.block(token));
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
// An OpenSpec section runs to the next heading at its own depth or above.
|
|
186
|
+
const heading = token as Tokens.Heading;
|
|
187
|
+
let end = index + 1;
|
|
188
|
+
while (end < list.length) {
|
|
189
|
+
const next = list[end]!;
|
|
190
|
+
if (next.type === "heading" && (next as Tokens.Heading).depth <= heading.depth) break;
|
|
191
|
+
end += 1;
|
|
192
|
+
}
|
|
193
|
+
const body = list.slice(index + 1, end);
|
|
194
|
+
nodes.push(
|
|
195
|
+
kind === "scenario" ? this.scenario(heading, body) : this.requirement(heading, body),
|
|
196
|
+
);
|
|
197
|
+
index = end - 1;
|
|
198
|
+
}
|
|
199
|
+
return nodes;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/** `### Requirement: …`: the heading with its label, then its text, SHALL marked. */
|
|
203
|
+
private requirement(heading: Tokens.Heading, body: Token[]): MdElement {
|
|
204
|
+
return el(
|
|
205
|
+
"div",
|
|
206
|
+
[
|
|
207
|
+
el(
|
|
208
|
+
headingTag(heading),
|
|
209
|
+
[
|
|
210
|
+
el("span", ["Requirement"], { className: "md-section-label" }),
|
|
211
|
+
...this.titleOf(heading),
|
|
212
|
+
],
|
|
213
|
+
{ className: "md-requirement-title" },
|
|
214
|
+
),
|
|
215
|
+
...this.blocks(body).map(markNormative),
|
|
216
|
+
],
|
|
217
|
+
{ className: "md-requirement" },
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/** `#### Scenario: …` as one card; its `**WHEN**`-style list items become steps. */
|
|
222
|
+
private scenario(heading: Tokens.Heading, body: Token[]): MdElement {
|
|
223
|
+
return el(
|
|
224
|
+
"div",
|
|
225
|
+
[
|
|
226
|
+
el(
|
|
227
|
+
"p",
|
|
228
|
+
[el("span", ["Scenario"], { className: "md-section-label" }), ...this.titleOf(heading)],
|
|
229
|
+
{ className: "md-scenario-title" },
|
|
230
|
+
),
|
|
231
|
+
...body.flatMap((token) =>
|
|
232
|
+
token.type === "list"
|
|
233
|
+
? [this.steps(token as Tokens.List) ?? this.list(token as Tokens.List)]
|
|
234
|
+
: this.block(token),
|
|
235
|
+
),
|
|
236
|
+
],
|
|
237
|
+
{ className: "md-scenario" },
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/** A section heading's text without its `Requirement:` or `Scenario:` prefix. */
|
|
242
|
+
private titleOf(heading: Tokens.Heading): MdNode[] {
|
|
243
|
+
const tokens = heading.tokens ?? [];
|
|
244
|
+
const first = tokens[0];
|
|
245
|
+
if (first?.type !== "text") return this.inline(tokens, heading.text);
|
|
246
|
+
const text = (first as Tokens.Text).text.replace(SECTION_PREFIX, "");
|
|
247
|
+
return [text, ...tokens.slice(1).map((token) => this.span(token))].filter(
|
|
248
|
+
(node) => node !== "",
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
inline(tokens: Token[] | undefined, fallback = ""): MdNode[] {
|
|
253
|
+
if (!tokens) return [fallback];
|
|
254
|
+
return tokens.map((token) => this.span(token));
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
private block(token: Token): MdNode[] {
|
|
258
|
+
switch (token.type) {
|
|
259
|
+
case "space":
|
|
260
|
+
case "def":
|
|
261
|
+
return [];
|
|
262
|
+
case "heading": {
|
|
263
|
+
const heading = token as Tokens.Heading;
|
|
264
|
+
return [el(headingTag(heading), this.inline(heading.tokens, heading.text))];
|
|
265
|
+
}
|
|
266
|
+
case "paragraph": {
|
|
267
|
+
const paragraph = token as Tokens.Paragraph;
|
|
268
|
+
return [el("p", this.inline(paragraph.tokens, paragraph.text))];
|
|
269
|
+
}
|
|
270
|
+
case "text": {
|
|
271
|
+
const text = token as Tokens.Text;
|
|
272
|
+
return [el("p", this.inline(text.tokens, text.text))];
|
|
273
|
+
}
|
|
274
|
+
case "code": {
|
|
275
|
+
const code = token as Tokens.Code;
|
|
276
|
+
const language = code.lang?.trim().split(/\s+/, 1)[0] || undefined;
|
|
277
|
+
return [
|
|
278
|
+
el("pre", [el("code", highlighted(code.text, language))], { className: "md-fence" }),
|
|
279
|
+
];
|
|
280
|
+
}
|
|
281
|
+
case "blockquote":
|
|
282
|
+
return [el("blockquote", this.blocks((token as Tokens.Blockquote).tokens))];
|
|
283
|
+
case "hr":
|
|
284
|
+
return [el("hr")];
|
|
285
|
+
case "list":
|
|
286
|
+
return [this.list(token as Tokens.List)];
|
|
287
|
+
case "table":
|
|
288
|
+
return [this.table(token as Tokens.Table)];
|
|
289
|
+
case "html":
|
|
290
|
+
// Raw markup is shown as the text it is, never inserted.
|
|
291
|
+
return [el("p", [(token as Tokens.HTML).raw.trim()], { className: "md-raw" })];
|
|
292
|
+
default:
|
|
293
|
+
return [el("p", [token.raw])];
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/** A scenario's list as keyword steps, or `null` unless every item is a step. */
|
|
298
|
+
private steps(list: Tokens.List): MdElement | null {
|
|
299
|
+
const steps = list.items.map(stepOf);
|
|
300
|
+
if (!steps.every((step) => step !== null)) return null;
|
|
301
|
+
return el(
|
|
302
|
+
"ul",
|
|
303
|
+
steps.map(({ keyword, rest }) =>
|
|
304
|
+
el(
|
|
305
|
+
"li",
|
|
306
|
+
[
|
|
307
|
+
el("span", [keyword], { className: `md-step-key md-key-${keyword.toLowerCase()}` }),
|
|
308
|
+
el("span", this.inline(rest)),
|
|
309
|
+
],
|
|
310
|
+
{ className: "md-step" },
|
|
311
|
+
),
|
|
312
|
+
),
|
|
313
|
+
{ className: "md-steps" },
|
|
314
|
+
);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
private list(list: Tokens.List): MdElement {
|
|
318
|
+
const start =
|
|
319
|
+
list.ordered && typeof list.start === "number" && list.start !== 1 ? list.start : undefined;
|
|
320
|
+
return el(
|
|
321
|
+
list.ordered ? "ol" : "ul",
|
|
322
|
+
list.items.map((item) => {
|
|
323
|
+
const body = item.tokens.filter((token) => token.type !== "checkbox");
|
|
324
|
+
const content = item.loose ? this.blocks(body) : this.tight(body);
|
|
325
|
+
return el(
|
|
326
|
+
"li",
|
|
327
|
+
item.task ? [el("input", undefined, { checked: !!item.checked }), ...content] : content,
|
|
328
|
+
item.task ? { className: "md-task" } : undefined,
|
|
329
|
+
);
|
|
330
|
+
}),
|
|
331
|
+
start !== undefined ? { start } : undefined,
|
|
332
|
+
);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/** A tight item's text sits in the item, not in a paragraph of its own. */
|
|
336
|
+
private tight(tokens: Token[]): MdNode[] {
|
|
337
|
+
return tokens.flatMap((token) =>
|
|
338
|
+
token.type === "text"
|
|
339
|
+
? this.inline((token as Tokens.Text).tokens, (token as Tokens.Text).text)
|
|
340
|
+
: this.block(token),
|
|
341
|
+
);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
private table(table: Tokens.Table): MdElement {
|
|
345
|
+
const cell = (tag: "th" | "td", value: Tokens.TableCell) =>
|
|
346
|
+
el(
|
|
347
|
+
tag,
|
|
348
|
+
this.inline(value.tokens, value.text),
|
|
349
|
+
value.align ? { align: value.align } : undefined,
|
|
350
|
+
);
|
|
351
|
+
return el(
|
|
352
|
+
"div",
|
|
353
|
+
[
|
|
354
|
+
el("table", [
|
|
355
|
+
el("thead", [
|
|
356
|
+
el(
|
|
357
|
+
"tr",
|
|
358
|
+
table.header.map((value) => cell("th", value)),
|
|
359
|
+
),
|
|
360
|
+
]),
|
|
361
|
+
el(
|
|
362
|
+
"tbody",
|
|
363
|
+
table.rows.map((row) =>
|
|
364
|
+
el(
|
|
365
|
+
"tr",
|
|
366
|
+
row.map((value) => cell("td", value)),
|
|
367
|
+
),
|
|
368
|
+
),
|
|
369
|
+
),
|
|
370
|
+
]),
|
|
371
|
+
],
|
|
372
|
+
{ className: "md-table" },
|
|
373
|
+
);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
private span(token: Token): MdNode {
|
|
377
|
+
switch (token.type) {
|
|
378
|
+
case "text": {
|
|
379
|
+
const text = token as Tokens.Text;
|
|
380
|
+
return text.tokens ? el("span", this.inline(text.tokens)) : text.text;
|
|
381
|
+
}
|
|
382
|
+
case "escape":
|
|
383
|
+
return (token as Tokens.Escape).text;
|
|
384
|
+
case "strong":
|
|
385
|
+
return el("strong", this.inline((token as Tokens.Strong).tokens));
|
|
386
|
+
case "em":
|
|
387
|
+
return el("em", this.inline((token as Tokens.Em).tokens));
|
|
388
|
+
case "del":
|
|
389
|
+
return el("del", this.inline((token as Tokens.Del).tokens));
|
|
390
|
+
case "codespan":
|
|
391
|
+
return el("code", [(token as Tokens.Codespan).text]);
|
|
392
|
+
case "br":
|
|
393
|
+
return el("br");
|
|
394
|
+
case "link":
|
|
395
|
+
return this.link(token as Tokens.Link);
|
|
396
|
+
case "image": {
|
|
397
|
+
// Not requested or shown: only what the author said the image is.
|
|
398
|
+
const image = token as Tokens.Image;
|
|
399
|
+
return image.text || plainText(image.tokens, "");
|
|
400
|
+
}
|
|
401
|
+
case "html":
|
|
402
|
+
return (token as Tokens.HTML).raw;
|
|
403
|
+
default:
|
|
404
|
+
return token.raw;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
private link(link: Tokens.Link): MdNode {
|
|
409
|
+
const label = this.inline(link.tokens, link.text);
|
|
410
|
+
if (/^https?:\/\//i.test(link.href)) return el("a", label, { href: link.href });
|
|
411
|
+
const note = resolveNoteLink(link.href, this.path);
|
|
412
|
+
return note === null ? el("span", label) : el("a", label, { note });
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/** A markdown file as data the browser renders; `path` is where its relative links start. */
|
|
417
|
+
export function markdownTree(source: string, path: string): MdNode[] {
|
|
418
|
+
const match = FRONTMATTER.exec(source);
|
|
419
|
+
const body = match ? source.slice(match[0].length) : source;
|
|
420
|
+
const nodes = new TreeMapper(path).blocks(new Lexer({ gfm: true }).lex(body));
|
|
421
|
+
return match ? [frontmatter(match[1] ?? match[2] ?? ""), ...nodes] : nodes;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
/** A text file that is not markdown as one highlighted block; `language` may be an extension. */
|
|
425
|
+
export function codeTree(source: string, language: string | undefined): MdNode[] {
|
|
426
|
+
return [el("pre", [el("code", highlighted(source, language))], { className: "md-fence" })];
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/** `---` YAML, or the `<!-- mate:delta … -->` header Mate writes atop a change's spec delta. */
|
|
430
|
+
const FRONTMATTER =
|
|
431
|
+
/^(?:---[ \t]*\r?\n([\s\S]*?)\r?\n---|<!--[ \t]*mate:delta[ \t]*\r?\n([\s\S]*?)\r?\n[ \t]*-->)[ \t]*(?:\r?\n|$)/;
|
|
432
|
+
/** Nesting shown as fields; deeper values fall back to their JSON text. */
|
|
433
|
+
const FIELD_DEPTH = 2;
|
|
434
|
+
|
|
435
|
+
/** A file's leading YAML block as fields; text that is not a mapping is shown as written. */
|
|
436
|
+
function frontmatter(yaml: string): MdElement {
|
|
437
|
+
let data: unknown;
|
|
438
|
+
try {
|
|
439
|
+
data = parseYaml(yaml);
|
|
440
|
+
} catch {
|
|
441
|
+
data = undefined;
|
|
442
|
+
}
|
|
443
|
+
const fields = isRecord(data)
|
|
444
|
+
? fieldList(data, 0)
|
|
445
|
+
: el("pre", [el("code", [yaml])], { className: "md-fence" });
|
|
446
|
+
return el("div", [fields], { className: "md-frontmatter" });
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
const isRecord = (value: unknown): value is Record<string, unknown> =>
|
|
450
|
+
typeof value === "object" && value !== null && !Array.isArray(value);
|
|
451
|
+
|
|
452
|
+
/** Only scalar values, so the mapping fits on one chip. */
|
|
453
|
+
const flat = (record: Record<string, unknown>): boolean =>
|
|
454
|
+
Object.values(record).every((entry) => entry === null || typeof entry !== "object");
|
|
455
|
+
|
|
456
|
+
interface Scope {
|
|
457
|
+
repository: string;
|
|
458
|
+
area: string;
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
/** A `scopes` entry: exactly a repository and one of its Areas. */
|
|
462
|
+
const isScope = (value: unknown): value is Scope =>
|
|
463
|
+
isRecord(value) &&
|
|
464
|
+
Object.keys(value).length === 2 &&
|
|
465
|
+
typeof value.repository === "string" &&
|
|
466
|
+
typeof value.area === "string";
|
|
467
|
+
|
|
468
|
+
/** Scopes grouped by repository, in first-seen order, each Area a chip; `.` is its root. */
|
|
469
|
+
function scopeGroups(scopes: Scope[]): MdNode[] {
|
|
470
|
+
const areasByRepository = new Map<string, string[]>();
|
|
471
|
+
for (const { repository, area } of scopes) {
|
|
472
|
+
areasByRepository.set(repository, [...(areasByRepository.get(repository) ?? []), area]);
|
|
473
|
+
}
|
|
474
|
+
return [...areasByRepository].map(([repository, areas]) =>
|
|
475
|
+
el(
|
|
476
|
+
"div",
|
|
477
|
+
[
|
|
478
|
+
el("span", [repository], { className: "md-scope-repo" }),
|
|
479
|
+
...areas.map((area) =>
|
|
480
|
+
area === "."
|
|
481
|
+
? el("span", ["root"], { className: "md-chip md-chip-root" })
|
|
482
|
+
: el("span", [area], { className: "md-chip" }),
|
|
483
|
+
),
|
|
484
|
+
],
|
|
485
|
+
{ className: "md-scope" },
|
|
486
|
+
),
|
|
487
|
+
);
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
function fieldList(data: Record<string, unknown>, depth: number): MdElement {
|
|
491
|
+
return el(
|
|
492
|
+
"dl",
|
|
493
|
+
Object.entries(data).flatMap(([name, value]) => [
|
|
494
|
+
el("dt", [name]),
|
|
495
|
+
el("dd", fieldValue(value, depth)),
|
|
496
|
+
]),
|
|
497
|
+
);
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
function fieldValue(value: unknown, depth: number): MdNode[] {
|
|
501
|
+
if (value === null || value === undefined || value === "") {
|
|
502
|
+
return [el("span", ["empty"], { className: "md-field-empty" })];
|
|
503
|
+
}
|
|
504
|
+
if (value instanceof Date) return [value.toISOString().slice(0, 10)];
|
|
505
|
+
if (Array.isArray(value) && value.every((item) => !isRecord(item) && !Array.isArray(item))) {
|
|
506
|
+
return value.map((item) => el("span", [String(item)], { className: "md-chip" }));
|
|
507
|
+
}
|
|
508
|
+
if (Array.isArray(value) && value.length > 0 && value.every(isScope)) return scopeGroups(value);
|
|
509
|
+
// A list of small mappings reads as one chip per item.
|
|
510
|
+
if (Array.isArray(value) && value.every((item) => isRecord(item) && flat(item))) {
|
|
511
|
+
return value.map((item) =>
|
|
512
|
+
el("span", [Object.values(item).map(String).join(" · ")], { className: "md-chip" }),
|
|
513
|
+
);
|
|
514
|
+
}
|
|
515
|
+
if (isRecord(value) && depth < FIELD_DEPTH) return [fieldList(value, depth + 1)];
|
|
516
|
+
if (typeof value === "object") return [el("code", [JSON.stringify(value)])];
|
|
517
|
+
return [String(value)];
|
|
518
|
+
}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { errorMessage } from "../../../../../runtime/error-message";
|
|
2
|
+
import type { VaultManager, VaultTreeNode } from "../../vault";
|
|
3
|
+
import { markdownTree, type MdNode } from "./markdown-tree";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A tree entry as the browser gets it: a folder carries its entries only when it is on the
|
|
7
|
+
* open path, so what crosses to the page depends on the entries shown, not on the
|
|
8
|
+
* repository's size.
|
|
9
|
+
*/
|
|
10
|
+
export interface VaultEntry {
|
|
11
|
+
name: string;
|
|
12
|
+
/** Companion-relative, `/`-separated. */
|
|
13
|
+
path: string;
|
|
14
|
+
kind: "file" | "directory";
|
|
15
|
+
/** Present only for an expanded folder. */
|
|
16
|
+
children?: VaultEntry[];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface VaultOpenFile {
|
|
20
|
+
path: string;
|
|
21
|
+
content: string;
|
|
22
|
+
token: string;
|
|
23
|
+
/** The content rendered on the server; links already resolved. */
|
|
24
|
+
markdown: MdNode[];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface VaultView {
|
|
28
|
+
/** `null` while the listing still runs; the page asks again with `wait`. */
|
|
29
|
+
tree: VaultEntry[] | null;
|
|
30
|
+
generation: number | null;
|
|
31
|
+
watching: boolean;
|
|
32
|
+
warning: string | null;
|
|
33
|
+
failure: string | null;
|
|
34
|
+
/** The requested folder, or `null` when none was named or the tree does not hold it. */
|
|
35
|
+
dir: string | null;
|
|
36
|
+
/** Whether a named folder was missing from the listed tree. */
|
|
37
|
+
dirMissing: boolean;
|
|
38
|
+
open: VaultOpenFile | null;
|
|
39
|
+
refusal: string | null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface VaultViewRequest {
|
|
43
|
+
path?: string;
|
|
44
|
+
dir?: string;
|
|
45
|
+
refresh?: boolean;
|
|
46
|
+
/** Waits for the listing instead of answering without it. */
|
|
47
|
+
wait?: boolean;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Most matches a filter shows; the rest are counted, not sent. */
|
|
51
|
+
export const VAULT_FILTER_LIMIT = 200;
|
|
52
|
+
|
|
53
|
+
const segments = (relative: string): string[] => relative.split(/[\\/]/).filter(Boolean);
|
|
54
|
+
const key = (relative: string): string => segments(relative).join("/");
|
|
55
|
+
|
|
56
|
+
function byKindThenName(a: VaultTreeNode, b: VaultTreeNode): number {
|
|
57
|
+
if (a.kind !== b.kind) return a.kind === "directory" ? -1 : 1;
|
|
58
|
+
return a.name.localeCompare(b.name);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Folders on the path to the open file (not the file itself) and to the open folder. */
|
|
62
|
+
function expandedPaths(path: string | null, dir: string | null): Set<string> {
|
|
63
|
+
const expanded = new Set<string>();
|
|
64
|
+
const add = (relative: string, includeLast: boolean) => {
|
|
65
|
+
const parts = segments(relative);
|
|
66
|
+
const count = includeLast ? parts.length : parts.length - 1;
|
|
67
|
+
for (let index = 1; index <= count; index += 1) expanded.add(parts.slice(0, index).join("/"));
|
|
68
|
+
};
|
|
69
|
+
if (path) add(path, false);
|
|
70
|
+
if (dir) add(dir, true);
|
|
71
|
+
return expanded;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Sorted entries, folders first; only expanded folders keep theirs. */
|
|
75
|
+
function pruneTree(nodes: VaultTreeNode[], expanded: Set<string>): VaultEntry[] {
|
|
76
|
+
return nodes.toSorted(byKindThenName).map((node) => {
|
|
77
|
+
const path = key(node.path);
|
|
78
|
+
const entry: VaultEntry = { name: node.name, path, kind: node.kind };
|
|
79
|
+
if (node.kind === "directory" && expanded.has(path)) {
|
|
80
|
+
entry.children = pruneTree(node.children ?? [], expanded);
|
|
81
|
+
}
|
|
82
|
+
return entry;
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Walks node names, so a requested folder is only ever one the listed tree holds. */
|
|
87
|
+
function findDirectory(tree: VaultTreeNode[], relative: string): VaultTreeNode | null {
|
|
88
|
+
let level = tree;
|
|
89
|
+
let found: VaultTreeNode | null = null;
|
|
90
|
+
for (const name of segments(relative)) {
|
|
91
|
+
found = level.find((node) => node.kind === "directory" && node.name === name) ?? null;
|
|
92
|
+
if (!found) return null;
|
|
93
|
+
level = found.children ?? [];
|
|
94
|
+
}
|
|
95
|
+
return found;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** An open file with its rendered form, or the vault's refusal. */
|
|
99
|
+
export async function vaultFile(
|
|
100
|
+
manager: VaultManager,
|
|
101
|
+
companionPath: string,
|
|
102
|
+
path: string,
|
|
103
|
+
): Promise<{ open: VaultOpenFile | null; refusal: string | null }> {
|
|
104
|
+
try {
|
|
105
|
+
const file = await manager.open(companionPath, path);
|
|
106
|
+
const relative = key(file.path);
|
|
107
|
+
return {
|
|
108
|
+
open: { ...file, path: relative, markdown: markdownTree(file.content, relative) },
|
|
109
|
+
refusal: null,
|
|
110
|
+
};
|
|
111
|
+
} catch (error) {
|
|
112
|
+
return { open: null, refusal: errorMessage(error) };
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** One vault page's state: the bounded tree, the open folder or file. */
|
|
117
|
+
export async function vaultView(
|
|
118
|
+
manager: VaultManager,
|
|
119
|
+
companionPath: string,
|
|
120
|
+
request: VaultViewRequest,
|
|
121
|
+
): Promise<VaultView> {
|
|
122
|
+
const path = request.path ? key(request.path) : null;
|
|
123
|
+
const dir = request.dir ? key(request.dir) : null;
|
|
124
|
+
let failure: string | null = null;
|
|
125
|
+
let listed: Awaited<ReturnType<VaultManager["tree"]>> | null = null;
|
|
126
|
+
try {
|
|
127
|
+
listed = request.wait
|
|
128
|
+
? await manager.tree(companionPath, request.refresh)
|
|
129
|
+
: await manager.prefetch(companionPath, request.refresh);
|
|
130
|
+
} catch (error) {
|
|
131
|
+
failure = errorMessage(error);
|
|
132
|
+
}
|
|
133
|
+
const file = path ? await vaultFile(manager, companionPath, path) : { open: null, refusal: null };
|
|
134
|
+
const found = listed && dir ? findDirectory(listed.tree, dir) : null;
|
|
135
|
+
return {
|
|
136
|
+
tree: listed ? pruneTree(listed.tree, expandedPaths(path, dir)) : null,
|
|
137
|
+
generation: listed?.generation ?? null,
|
|
138
|
+
watching: listed?.watching ?? false,
|
|
139
|
+
warning: listed?.warning ?? null,
|
|
140
|
+
failure,
|
|
141
|
+
dir: found ? dir : null,
|
|
142
|
+
dirMissing: Boolean(listed && dir && !found),
|
|
143
|
+
...file,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** A folder's entries when the viewer first expands it; `null` when the listed tree lacks it. */
|
|
148
|
+
export async function vaultChildren(
|
|
149
|
+
manager: VaultManager,
|
|
150
|
+
companionPath: string,
|
|
151
|
+
dir: string,
|
|
152
|
+
): Promise<{ entries: VaultEntry[]; generation: number } | null> {
|
|
153
|
+
const listed = await manager.tree(companionPath);
|
|
154
|
+
const folder = findDirectory(listed.tree, dir);
|
|
155
|
+
if (!folder) return null;
|
|
156
|
+
return { entries: pruneTree(folder.children ?? [], new Set()), generation: listed.generation };
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** Files whose path contains `query`, over the whole listed tree, bounded; never touches the disk. */
|
|
160
|
+
export async function vaultMatches(
|
|
161
|
+
manager: VaultManager,
|
|
162
|
+
companionPath: string,
|
|
163
|
+
query: string,
|
|
164
|
+
): Promise<{ shown: VaultEntry[]; total: number; generation: number }> {
|
|
165
|
+
const listed = await manager.tree(companionPath);
|
|
166
|
+
const needle = query.trim().toLowerCase();
|
|
167
|
+
const shown: VaultEntry[] = [];
|
|
168
|
+
let total = 0;
|
|
169
|
+
if (!needle) return { shown, total, generation: listed.generation };
|
|
170
|
+
const stack = listed.tree.toReversed();
|
|
171
|
+
while (stack.length > 0) {
|
|
172
|
+
const node = stack.pop()!;
|
|
173
|
+
if (node.kind === "directory") {
|
|
174
|
+
for (let index = (node.children?.length ?? 0) - 1; index >= 0; index -= 1) {
|
|
175
|
+
stack.push(node.children![index]!);
|
|
176
|
+
}
|
|
177
|
+
} else if (key(node.path).toLowerCase().includes(needle)) {
|
|
178
|
+
total += 1;
|
|
179
|
+
if (shown.length < VAULT_FILTER_LIMIT) {
|
|
180
|
+
shown.push({ name: node.name, path: key(node.path), kind: "file" });
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return { shown, total, generation: listed.generation };
|
|
185
|
+
}
|