@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,397 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one secret-file pattern set every guardrail layer reads: guidance,
|
|
3
|
+
* projected deny rules, hook and middleware enforcement, indexer exclusion and
|
|
4
|
+
* the publish scan. Keeping it in one module is what stops the layers from
|
|
5
|
+
* disagreeing about what a secret file is.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export const DEFAULT_SECRET_DENY_PATTERNS: readonly string[] = [
|
|
9
|
+
".env",
|
|
10
|
+
".env.*",
|
|
11
|
+
"*.pem",
|
|
12
|
+
"*.key",
|
|
13
|
+
"*.p12",
|
|
14
|
+
"*.pfx",
|
|
15
|
+
"id_rsa",
|
|
16
|
+
"id_ecdsa",
|
|
17
|
+
"id_ed25519",
|
|
18
|
+
".netrc",
|
|
19
|
+
".pgpass",
|
|
20
|
+
".npmrc",
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
/** Example files that document which variables exist; they never hold values. */
|
|
24
|
+
export const DEFAULT_SECRET_ALLOW_PATTERNS: readonly string[] = [
|
|
25
|
+
".env.example",
|
|
26
|
+
".env.sample",
|
|
27
|
+
".env.template",
|
|
28
|
+
".env.dist",
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
export interface SecretPolicy {
|
|
32
|
+
/** False only when the companion explicitly opts out. */
|
|
33
|
+
guardrails: boolean;
|
|
34
|
+
/** Defaults plus the companion's extra `secrets.deny` patterns. */
|
|
35
|
+
deny: string[];
|
|
36
|
+
/** Defaults plus the companion's extra `secrets.allow` patterns. */
|
|
37
|
+
allow: string[];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const defaultSecretPolicy = (): SecretPolicy => ({
|
|
41
|
+
guardrails: true,
|
|
42
|
+
deny: [...DEFAULT_SECRET_DENY_PATTERNS],
|
|
43
|
+
allow: [...DEFAULT_SECRET_ALLOW_PATTERNS],
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
function patternList(value: unknown): string[] {
|
|
47
|
+
if (!Array.isArray(value)) return [];
|
|
48
|
+
return value.filter((entry): entry is string => typeof entry === "string" && entry.trim() !== "");
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Parses the `secrets` block of `framework.yaml`. Anything that is not an
|
|
53
|
+
* object yields the defaults with guardrails on, and only a literal `false`
|
|
54
|
+
* turns them off: a broken config never disables protection.
|
|
55
|
+
*/
|
|
56
|
+
export function parseSecretsConfig(value: unknown): SecretPolicy {
|
|
57
|
+
const policy = defaultSecretPolicy();
|
|
58
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return policy;
|
|
59
|
+
const block = value as Record<string, unknown>;
|
|
60
|
+
return {
|
|
61
|
+
guardrails: block.guardrails !== false,
|
|
62
|
+
deny: [...policy.deny, ...patternList(block.deny)],
|
|
63
|
+
allow: [...policy.allow, ...patternList(block.allow)],
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Evaluate as `new RegExp(source, flags)` against `subject`; mate matches with the same rules, so consumers never differ. */
|
|
68
|
+
export interface SecretRule {
|
|
69
|
+
/** The pattern as configured, for messages. */
|
|
70
|
+
pattern: string;
|
|
71
|
+
source: string;
|
|
72
|
+
/** Regular expression flags; `i`, since macOS and Windows ignore letter case. */
|
|
73
|
+
flags: string;
|
|
74
|
+
/** `name` tests the file name; `path` tests the `/`-separated path. */
|
|
75
|
+
subject: "name" | "path";
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** A secret policy compiled into rules, as the launch policy carries it. */
|
|
79
|
+
export interface SecretRules {
|
|
80
|
+
guardrails: boolean;
|
|
81
|
+
deny: SecretRule[];
|
|
82
|
+
allow: SecretRule[];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const compiled = new Map<string, { rule: SecretRule; regExp: RegExp }>();
|
|
86
|
+
|
|
87
|
+
/** POSIX bracket classes, as gitignore's matcher knows them; letter case is ignored anyway. */
|
|
88
|
+
const POSIX_CLASSES: Readonly<Record<string, string>> = {
|
|
89
|
+
alnum: "a-z0-9",
|
|
90
|
+
alpha: "a-z",
|
|
91
|
+
blank: " \\t",
|
|
92
|
+
cntrl: "\\x00-\\x1f\\x7f",
|
|
93
|
+
digit: "0-9",
|
|
94
|
+
graph: "!-~",
|
|
95
|
+
lower: "a-z",
|
|
96
|
+
print: " -~",
|
|
97
|
+
punct: "!-\\/:-@\\[-`{-~",
|
|
98
|
+
space: "\\s",
|
|
99
|
+
upper: "a-z",
|
|
100
|
+
xdigit: "0-9a-f",
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const escapeRegExp = (char: string) => char.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
104
|
+
|
|
105
|
+
/** Regex source never matching `/`, and the closing `]` index; null when unclosed, so `[` is literal. */
|
|
106
|
+
function bracket(body: string, start: number): { source: string; end: number } | null {
|
|
107
|
+
let i = start + 1;
|
|
108
|
+
const negated = body[i] === "!" || body[i] === "^";
|
|
109
|
+
if (negated) i++;
|
|
110
|
+
let members = "";
|
|
111
|
+
for (let first = true; i < body.length; i++, first = false) {
|
|
112
|
+
const char = body[i];
|
|
113
|
+
if (char === "]" && !first) {
|
|
114
|
+
return { source: negated ? `[^/${members}]` : `(?!/)[${members}]`, end: i };
|
|
115
|
+
}
|
|
116
|
+
if (char === "[" && body[i + 1] === ":") {
|
|
117
|
+
const close = body.indexOf(":]", i + 2);
|
|
118
|
+
const named = close === -1 ? undefined : POSIX_CLASSES[body.slice(i + 2, close)];
|
|
119
|
+
if (named === undefined) return null;
|
|
120
|
+
members += named;
|
|
121
|
+
i = close + 1;
|
|
122
|
+
} else if (char === "\\" && i + 1 < body.length) {
|
|
123
|
+
/** An escaped `-` is a member, never a range. */
|
|
124
|
+
const escaped = body[++i];
|
|
125
|
+
members += escaped === "-" ? "\\-" : escapeRegExp(escaped);
|
|
126
|
+
} else {
|
|
127
|
+
members += escapeRegExp(char);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* gitignore syntax, case-insensitive. A trailing `/` matches the folder and
|
|
135
|
+
* everything in it; without one only files match. A leading `!` is literal
|
|
136
|
+
* (list allowed files under `allow`).
|
|
137
|
+
*/
|
|
138
|
+
function compile(pattern: string): { rule: SecretRule; regExp: RegExp } {
|
|
139
|
+
const cached = compiled.get(pattern);
|
|
140
|
+
if (cached) return cached;
|
|
141
|
+
let source = "";
|
|
142
|
+
const folder = /[^/]\/+$/.test(pattern);
|
|
143
|
+
const body = pattern.replace(/^\/+/, "").replace(/\/+$/, "");
|
|
144
|
+
for (let i = 0; i < body.length; i++) {
|
|
145
|
+
const char = body[i];
|
|
146
|
+
const set = char === "[" ? bracket(body, i) : null;
|
|
147
|
+
if (set) {
|
|
148
|
+
source += set.source;
|
|
149
|
+
i = set.end;
|
|
150
|
+
} else if (char === "*" && body[i + 1] === "*") {
|
|
151
|
+
// `**/` matches zero or more whole segments; a bare `**` matches anything.
|
|
152
|
+
/** `[\s\S]`, not `.`, so a name holding a line break is crossed too. */
|
|
153
|
+
if (body[i + 2] === "/") {
|
|
154
|
+
source += "(?:[\\s\\S]*/)?";
|
|
155
|
+
i += 2;
|
|
156
|
+
} else {
|
|
157
|
+
source += "[\\s\\S]*";
|
|
158
|
+
i += 1;
|
|
159
|
+
}
|
|
160
|
+
} else if (char === "*") {
|
|
161
|
+
source += "[^/]*";
|
|
162
|
+
} else if (char === "?") {
|
|
163
|
+
source += "[^/]";
|
|
164
|
+
} else if (char === "\\" && i + 1 < body.length) {
|
|
165
|
+
source += escapeRegExp(body[++i]);
|
|
166
|
+
} else {
|
|
167
|
+
source += escapeRegExp(char);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* A slash-free pattern matches the file name; one with a slash, or naming a folder, matches
|
|
172
|
+
* the trailing segments of the path, since the repository root is not known here.
|
|
173
|
+
*/
|
|
174
|
+
const subject = folder || body.includes("/") ? "path" : "name";
|
|
175
|
+
let anchored: string;
|
|
176
|
+
if (body === "") anchored = "(?!)";
|
|
177
|
+
else if (folder) anchored = `(?:^|/)${source}(?:/[\\s\\S]*)?$`;
|
|
178
|
+
else if (subject === "path") anchored = `(?:^|/)${source}$`;
|
|
179
|
+
else anchored = `^${source}$`;
|
|
180
|
+
const rule: SecretRule = { pattern, source: anchored, flags: "i", subject };
|
|
181
|
+
const entry = { rule, regExp: new RegExp(rule.source, rule.flags) };
|
|
182
|
+
compiled.set(pattern, entry);
|
|
183
|
+
return entry;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export function secretRule(pattern: string): SecretRule {
|
|
187
|
+
return { ...compile(pattern).rule };
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export function secretRules(policy: SecretPolicy): SecretRules {
|
|
191
|
+
return {
|
|
192
|
+
guardrails: policy.guardrails,
|
|
193
|
+
deny: policy.deny.map(secretRule),
|
|
194
|
+
allow: policy.allow.map(secretRule),
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export interface SecretPathOptions {
|
|
199
|
+
/**
|
|
200
|
+
* Whether `\\` separates folders, as on Windows; elsewhere it is part of a
|
|
201
|
+
* name, so `public\\server.key` is one file, not `public/server.key`.
|
|
202
|
+
* Defaults to the platform Mate runs on.
|
|
203
|
+
*/
|
|
204
|
+
windows?: boolean;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const IS_WINDOWS = process.platform === "win32";
|
|
208
|
+
|
|
209
|
+
function normalizePath(filePath: string, { windows = IS_WINDOWS }: SecretPathOptions): string {
|
|
210
|
+
return (windows ? filePath.replaceAll("\\", "/") : filePath).replace(/\/+$/, "");
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export function matchesSecretPattern(
|
|
214
|
+
filePath: string,
|
|
215
|
+
patterns: readonly string[],
|
|
216
|
+
options: SecretPathOptions = {},
|
|
217
|
+
): boolean {
|
|
218
|
+
const normalized = normalizePath(filePath, options);
|
|
219
|
+
if (!normalized) return false;
|
|
220
|
+
const name = normalized.slice(normalized.lastIndexOf("/") + 1);
|
|
221
|
+
return patterns.some((pattern) => {
|
|
222
|
+
const { rule, regExp } = compile(pattern);
|
|
223
|
+
return regExp.test(rule.subject === "name" ? name : normalized);
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/** A path is a secret file when it matches a deny pattern and no allow pattern. */
|
|
228
|
+
export function isSecretFile(
|
|
229
|
+
filePath: string,
|
|
230
|
+
policy: SecretPolicy,
|
|
231
|
+
options: SecretPathOptions = {},
|
|
232
|
+
): boolean {
|
|
233
|
+
return (
|
|
234
|
+
matchesSecretPattern(filePath, policy.deny, options) &&
|
|
235
|
+
!matchesSecretPattern(filePath, policy.allow, options)
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Narrower stand-ins for a default deny pattern that also matches an allowed
|
|
241
|
+
* file. Runtime deny rules are evaluated before allow rules, so `.env.*` there
|
|
242
|
+
* would deny `.env.example` too; these cover the common environment files.
|
|
243
|
+
*/
|
|
244
|
+
const ALLOW_SAFE_EXPANSIONS: Readonly<Record<string, readonly string[]>> = {
|
|
245
|
+
".env.*": [".env.local", ".env.development", ".env.production", ".env.test", ".env.*.local"],
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* The default deny patterns a runtime's own deny rules may carry: every
|
|
250
|
+
* default that can't match an allow-listed file, with an overlapping pattern
|
|
251
|
+
* replaced by its narrower stand-ins. Extra `secrets.deny` patterns are never
|
|
252
|
+
* projected: once removed from config, nothing would mark their rules as Mate's.
|
|
253
|
+
*/
|
|
254
|
+
export function projectableSecretDenyPatterns(): string[] {
|
|
255
|
+
const overlapsAllow = (pattern: string) =>
|
|
256
|
+
DEFAULT_SECRET_ALLOW_PATTERNS.some((allowed) => matchesSecretPattern(allowed, [pattern]));
|
|
257
|
+
return DEFAULT_SECRET_DENY_PATTERNS.flatMap((pattern) =>
|
|
258
|
+
overlapsAllow(pattern) ? (ALLOW_SAFE_EXPANSIONS[pattern] ?? []) : [pattern],
|
|
259
|
+
).filter((pattern) => !overlapsAllow(pattern));
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/** Ordinary files a broad glob also matches; a glob matching one is not aimed at secrets. */
|
|
263
|
+
const ORDINARY_SAMPLES = ["index.ts", "README.md", "config.json"];
|
|
264
|
+
|
|
265
|
+
/** Most alternatives a search glob's `{a,b}` groups may expand to; a glob with more is refused unchecked. */
|
|
266
|
+
export const BRACE_LIMIT = 64;
|
|
267
|
+
|
|
268
|
+
const capAlternatives = (count: number) => Math.min(count, BRACE_LIMIT + 1);
|
|
269
|
+
|
|
270
|
+
/** Glob text, or the branches of one `{a,b}` group. */
|
|
271
|
+
type BracePart = string | BraceSequence[];
|
|
272
|
+
type BraceSequence = BracePart[];
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* A glob's `{a,b}` groups as ripgrep reads them: a `[...]` set or an escaped
|
|
276
|
+
* character is text, `{a}` is a group too, groups nest, and an unclosed group
|
|
277
|
+
* closes at the end. On Windows ripgrep reads `**\` as `**\/`. Null when groups
|
|
278
|
+
* nest deeper than {@link BRACE_LIMIT}.
|
|
279
|
+
*/
|
|
280
|
+
function parseBraces(
|
|
281
|
+
glob: string,
|
|
282
|
+
{ windows = IS_WINDOWS }: SecretPathOptions,
|
|
283
|
+
): BraceSequence | null {
|
|
284
|
+
const source = windows ? glob.replaceAll("**\\", "**/") : glob;
|
|
285
|
+
let i = 0;
|
|
286
|
+
const sequence = (depth: number): BraceSequence | null => {
|
|
287
|
+
const parts: BraceSequence = [];
|
|
288
|
+
while (i < source.length) {
|
|
289
|
+
const char = source[i];
|
|
290
|
+
if (depth > 0 && (char === "," || char === "}")) break;
|
|
291
|
+
if (char === "{") {
|
|
292
|
+
if (depth === BRACE_LIMIT) return null;
|
|
293
|
+
const branches: BraceSequence[] = [];
|
|
294
|
+
do {
|
|
295
|
+
i++;
|
|
296
|
+
const branch = sequence(depth + 1);
|
|
297
|
+
if (!branch) return null;
|
|
298
|
+
branches.push(branch);
|
|
299
|
+
} while (source[i] === ",");
|
|
300
|
+
i++;
|
|
301
|
+
parts.push(branches);
|
|
302
|
+
continue;
|
|
303
|
+
}
|
|
304
|
+
const set = char === "[" ? bracket(source, i) : null;
|
|
305
|
+
const end = set ? set.end + 1 : char === "\\" ? i + 2 : i + 1;
|
|
306
|
+
const last = parts.at(-1);
|
|
307
|
+
if (typeof last === "string") parts[parts.length - 1] = last + source.slice(i, end);
|
|
308
|
+
else parts.push(source.slice(i, end));
|
|
309
|
+
i = end;
|
|
310
|
+
}
|
|
311
|
+
return parts;
|
|
312
|
+
};
|
|
313
|
+
return sequence(0);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
function alternativeCount(sequence: BraceSequence): number {
|
|
317
|
+
return sequence.reduce<number>((count, part) => {
|
|
318
|
+
if (typeof part === "string") return count;
|
|
319
|
+
const branches = part.reduce(
|
|
320
|
+
(sum, branch) => capAlternatives(sum + alternativeCount(branch)),
|
|
321
|
+
0,
|
|
322
|
+
);
|
|
323
|
+
return capAlternatives(count * branches);
|
|
324
|
+
}, 1);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
function expandBraces(sequence: BraceSequence): string[] {
|
|
328
|
+
return sequence.reduce<string[]>(
|
|
329
|
+
(prefixes, part) => {
|
|
330
|
+
const options = typeof part === "string" ? [part] : part.flatMap(expandBraces);
|
|
331
|
+
return prefixes.flatMap((prefix) => options.map((option) => prefix + option));
|
|
332
|
+
},
|
|
333
|
+
[""],
|
|
334
|
+
);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Whether a glob's `{a,b}` groups expand to more than {@link BRACE_LIMIT}
|
|
339
|
+
* alternatives. Counts without expanding, so a long glob can't stall the check.
|
|
340
|
+
*/
|
|
341
|
+
export function exceedsBraceLimit(glob: string, options: SecretPathOptions = {}): boolean {
|
|
342
|
+
const parsed = parseBraces(glob, options);
|
|
343
|
+
return !parsed || alternativeCount(parsed) > BRACE_LIMIT;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/** A file name a glob or pattern matches: each wildcard filled with `x`, a set with its first member. */
|
|
347
|
+
function sampleName(glob: string): string {
|
|
348
|
+
let sample = "";
|
|
349
|
+
for (let i = 0; i < glob.length; i++) {
|
|
350
|
+
const char = glob[i];
|
|
351
|
+
const set = char === "[" ? bracket(glob, i) : null;
|
|
352
|
+
if (set) {
|
|
353
|
+
const negated = glob[i + 1] === "!" || glob[i + 1] === "^";
|
|
354
|
+
const first = glob[i + (negated ? 2 : 1)];
|
|
355
|
+
sample += negated || first === "[" || first === "\\" ? "x" : first;
|
|
356
|
+
i = set.end;
|
|
357
|
+
} else if (char === "*" || char === "?") {
|
|
358
|
+
while (glob[i + 1] === "*") i++;
|
|
359
|
+
sample += "x";
|
|
360
|
+
} else if (char === "\\" && i + 1 < glob.length) {
|
|
361
|
+
sample += glob[++i];
|
|
362
|
+
} else {
|
|
363
|
+
sample += char;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
return sample;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* Heuristic for search tools. An `{a,b}` alternative is aimed at secrets when
|
|
371
|
+
* it matches no ordinary file and, wildcards filled in, names a secret file or
|
|
372
|
+
* matches a deny pattern's sample name. `**\/*`, `*.ts` and `!` exclusions are not.
|
|
373
|
+
* A glob past {@link BRACE_LIMIT} counts as aimed at secrets.
|
|
374
|
+
*/
|
|
375
|
+
export function globTargetsSecretFiles(
|
|
376
|
+
glob: string,
|
|
377
|
+
policy: SecretPolicy,
|
|
378
|
+
options: SecretPathOptions = {},
|
|
379
|
+
): boolean {
|
|
380
|
+
const pattern = glob.trim();
|
|
381
|
+
if (!pattern || pattern.startsWith("!")) return false;
|
|
382
|
+
const parsed = parseBraces(pattern, options);
|
|
383
|
+
if (!parsed || alternativeCount(parsed) > BRACE_LIMIT) return true;
|
|
384
|
+
return expandBraces(parsed).some((alternative) => {
|
|
385
|
+
if (ORDINARY_SAMPLES.some((sample) => matchesSecretPattern(sample, [alternative]))) {
|
|
386
|
+
return false;
|
|
387
|
+
}
|
|
388
|
+
if (isSecretFile(sampleName(alternative), policy)) return true;
|
|
389
|
+
return policy.deny.some((deny) => {
|
|
390
|
+
const trimmed = deny.replace(/\/+$/, "");
|
|
391
|
+
const sample = sampleName(trimmed.slice(trimmed.lastIndexOf("/") + 1));
|
|
392
|
+
return (
|
|
393
|
+
sample !== "" && isSecretFile(sample, policy) && matchesSecretPattern(sample, [alternative])
|
|
394
|
+
);
|
|
395
|
+
});
|
|
396
|
+
});
|
|
397
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
import type { lintSource as LintSourceFn } from "@secretlint/core";
|
|
5
|
+
import type { SecretLintCoreConfig } from "@secretlint/types";
|
|
6
|
+
|
|
7
|
+
/** One secretlint finding. Deliberately carries no message: messages quote the value. */
|
|
8
|
+
export interface SecretFinding {
|
|
9
|
+
path: string;
|
|
10
|
+
line: number;
|
|
11
|
+
ruleId: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
type LintSource = typeof LintSourceFn;
|
|
15
|
+
|
|
16
|
+
let engine: Promise<{ lintSource: LintSource; config: SecretLintCoreConfig }> | undefined;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Loaded on first use only, so hook calls that never scan don't pay for it.
|
|
20
|
+
* The config is fixed in memory: the recommended preset and nothing else. No
|
|
21
|
+
* `.secretlintrc` is ever read, so a repository can't weaken the scan.
|
|
22
|
+
*/
|
|
23
|
+
function loadEngine() {
|
|
24
|
+
engine ??= (async () => {
|
|
25
|
+
const [{ lintSource }, { creator }] = await Promise.all([
|
|
26
|
+
import("@secretlint/core"),
|
|
27
|
+
import("@secretlint/secretlint-rule-preset-recommend"),
|
|
28
|
+
]);
|
|
29
|
+
const config: SecretLintCoreConfig = {
|
|
30
|
+
rules: [{ id: "@secretlint/secretlint-rule-preset-recommend", rule: creator }],
|
|
31
|
+
};
|
|
32
|
+
return { lintSource, config };
|
|
33
|
+
})();
|
|
34
|
+
return engine;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Scans in-memory content. Throws when the engine fails, so callers can fail closed. */
|
|
38
|
+
export async function scanContent(filePath: string, content: string): Promise<SecretFinding[]> {
|
|
39
|
+
const { lintSource, config } = await loadEngine();
|
|
40
|
+
const result = await lintSource({
|
|
41
|
+
source: { content, filePath, contentType: "text" },
|
|
42
|
+
options: { config, maskSecrets: true, noPhysicFilePath: true },
|
|
43
|
+
});
|
|
44
|
+
return result.messages.map((message) => ({
|
|
45
|
+
path: filePath,
|
|
46
|
+
line: message.loc.start.line,
|
|
47
|
+
ruleId: message.ruleId,
|
|
48
|
+
}));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Every file under a path, in name order; a path that doesn't exist yields none. */
|
|
52
|
+
export async function listFiles(target: string): Promise<string[]> {
|
|
53
|
+
let stat;
|
|
54
|
+
try {
|
|
55
|
+
stat = await fs.stat(target);
|
|
56
|
+
} catch {
|
|
57
|
+
return [];
|
|
58
|
+
}
|
|
59
|
+
if (stat.isFile()) return [target];
|
|
60
|
+
if (!stat.isDirectory()) return [];
|
|
61
|
+
const entries = await fs.readdir(target, { withFileTypes: true });
|
|
62
|
+
const nested = await Promise.all(
|
|
63
|
+
entries
|
|
64
|
+
.toSorted((a, b) => a.name.localeCompare(b.name))
|
|
65
|
+
.map((entry) => listFiles(path.join(target, entry.name))),
|
|
66
|
+
);
|
|
67
|
+
return nested.flat();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Scans files and directories on disk; paths that don't exist are skipped. */
|
|
71
|
+
export async function scanFiles(targets: readonly string[]): Promise<SecretFinding[]> {
|
|
72
|
+
const findings: SecretFinding[] = [];
|
|
73
|
+
for (const target of targets) {
|
|
74
|
+
// oxlint-disable-next-line no-await-in-loop -- findings keep the caller's order
|
|
75
|
+
for (const file of await listFiles(target)) {
|
|
76
|
+
// oxlint-disable-next-line no-await-in-loop -- one file at a time bounds memory
|
|
77
|
+
const content = await fs.readFile(file, "utf8");
|
|
78
|
+
// oxlint-disable-next-line no-await-in-loop -- see above
|
|
79
|
+
findings.push(...(await scanContent(file, content)));
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return findings;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** One line per finding, for refusal messages: never the value. Line 0 means the whole file. */
|
|
86
|
+
export function describeSecretFindings(findings: readonly SecretFinding[]): string[] {
|
|
87
|
+
return findings.map(
|
|
88
|
+
(finding) => `${finding.path}${finding.line > 0 ? `:${finding.line}` : ""} (${finding.ruleId})`,
|
|
89
|
+
);
|
|
90
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { isDirectory, mainWorktreeOf, readGitLayout } from "./git-layout";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The other Checkout whose Claude wrap serves sessions in the Checkout at
|
|
5
|
+
* `root` (design Decisions 1 and 12), or null when it serves itself. Claude
|
|
6
|
+
* Code reads a linked worktree's hooks, skills and MCP servers from its main
|
|
7
|
+
* worktree as well as from the worktree, so a non-bare clone's main worktree
|
|
8
|
+
* serves its linked worktrees. On Windows, in a bare clone's worktrees, in a
|
|
9
|
+
* main worktree and outside Git, the Checkout serves itself. File reads only.
|
|
10
|
+
*/
|
|
11
|
+
export function otherServingClaudeWrapRoot(
|
|
12
|
+
root: string,
|
|
13
|
+
platform: NodeJS.Platform = process.platform,
|
|
14
|
+
): string | null {
|
|
15
|
+
if (platform === "win32") return null;
|
|
16
|
+
const layout = readGitLayout(root);
|
|
17
|
+
if (layout?.kind !== "linked") return null;
|
|
18
|
+
const main = mainWorktreeOf(layout.commonDir);
|
|
19
|
+
return main && isDirectory(main) ? main : null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** The Checkout whose Claude wrap serves the one at `root`: another, else `root` itself. */
|
|
23
|
+
export function servingClaudeWrapRoot(
|
|
24
|
+
root: string,
|
|
25
|
+
platform: NodeJS.Platform = process.platform,
|
|
26
|
+
): string {
|
|
27
|
+
return otherServingClaudeWrapRoot(root, platform) ?? root;
|
|
28
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
|
|
3
|
+
import { FRAMEWORK_NAME } from "./framework";
|
|
4
|
+
import { physicalPath } from "./physical-path";
|
|
5
|
+
import { policyDocument, readCompanionPolicy } from "./policy";
|
|
6
|
+
import { projectionCheckout, resolveProjection } from "./projection";
|
|
7
|
+
|
|
8
|
+
/** Readers reject any other version, so a changed reply fails closed instead of being misread. */
|
|
9
|
+
export const SESSION_CONTEXT_PROTOCOL = 1;
|
|
10
|
+
|
|
11
|
+
export type SessionContextErrorCode =
|
|
12
|
+
| "not-wrapped"
|
|
13
|
+
| "companion-missing"
|
|
14
|
+
| "companion-not-registered"
|
|
15
|
+
| "repository-not-linked";
|
|
16
|
+
|
|
17
|
+
export interface SessionContext {
|
|
18
|
+
/** The companion's real path. */
|
|
19
|
+
companionPath: string;
|
|
20
|
+
/** The real path of the checkout whose projection answered, which the link check validates. */
|
|
21
|
+
repositoryPath: string;
|
|
22
|
+
repositoryId: string;
|
|
23
|
+
/** The `MATE_POLICY_JSON` document a launch would carry for this companion. */
|
|
24
|
+
policyJson: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface SessionContextError {
|
|
28
|
+
code: SessionContextErrorCode;
|
|
29
|
+
message: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export type SessionContextResult =
|
|
33
|
+
| {
|
|
34
|
+
ok: true;
|
|
35
|
+
context: SessionContext;
|
|
36
|
+
/** Where the projection was found; its own `repositoryPath` is only a claim, so the caller checks this against the registry. */
|
|
37
|
+
checkoutRoot: string;
|
|
38
|
+
}
|
|
39
|
+
| { ok: false; error: SessionContextError };
|
|
40
|
+
|
|
41
|
+
export function sessionContextFailure(
|
|
42
|
+
code: SessionContextErrorCode,
|
|
43
|
+
message: string,
|
|
44
|
+
): SessionContextResult {
|
|
45
|
+
return { ok: false, error: { code, message } };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Not `fs.realpathSync`, which normalises `link/..` away first and would name a decoy folder. */
|
|
49
|
+
function realDirectory(target: string): string | null {
|
|
50
|
+
try {
|
|
51
|
+
const real = physicalPath(target);
|
|
52
|
+
return fs.statSync(real).isDirectory() ? real : null;
|
|
53
|
+
} catch {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Read-only: never repairs, prunes, projects or locks, and ignores the launch
|
|
60
|
+
* environment, since only a session without one asks. Does not judge trust;
|
|
61
|
+
* the caller checks the companion's registration before reporting it.
|
|
62
|
+
*/
|
|
63
|
+
export function resolveSessionContext(dir: string): SessionContextResult {
|
|
64
|
+
const projection = resolveProjection(dir);
|
|
65
|
+
if (!projection?.companionPath) {
|
|
66
|
+
return sessionContextFailure(
|
|
67
|
+
"not-wrapped",
|
|
68
|
+
`no ${FRAMEWORK_NAME} projection covers ${dir}. Run \`${FRAMEWORK_NAME} wrap\` in the repository.`,
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const companionPath = realDirectory(projection.companionPath);
|
|
73
|
+
if (!companionPath) {
|
|
74
|
+
return sessionContextFailure(
|
|
75
|
+
"companion-missing",
|
|
76
|
+
`the companion ${projection.companionPath} named by ${projection.repoRoot} does not exist.`,
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const policy = readCompanionPolicy(companionPath);
|
|
81
|
+
const checkoutRoot = projectionCheckout(projection);
|
|
82
|
+
return {
|
|
83
|
+
ok: true,
|
|
84
|
+
checkoutRoot,
|
|
85
|
+
context: {
|
|
86
|
+
companionPath,
|
|
87
|
+
repositoryPath: realDirectory(checkoutRoot) ?? checkoutRoot,
|
|
88
|
+
repositoryId: projection.repositoryId,
|
|
89
|
+
policyJson: policyDocument(policy),
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** The one JSON object `mate session context --json` prints. */
|
|
95
|
+
export function sessionContextReply(result: SessionContextResult): Record<string, unknown> {
|
|
96
|
+
return result.ok
|
|
97
|
+
? { protocol: SESSION_CONTEXT_PROTOCOL, ...result.context }
|
|
98
|
+
: { protocol: SESSION_CONTEXT_PROTOCOL, error: result.error };
|
|
99
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The kind of session a prepare or a delivery plan answers for, shared by every
|
|
3
|
+
* Agent Runtime. `managed-repo`: a managed launch with a Working Repository; its
|
|
4
|
+
* prepare just reconciled the wrap, which the launcher asserts.
|
|
5
|
+
* `managed-companion`: a companion-scoped managed launch. `unmanaged`: a
|
|
6
|
+
* session with no launch environment.
|
|
7
|
+
*/
|
|
8
|
+
export type SessionKind = "managed-repo" | "managed-companion" | "unmanaged";
|
|
9
|
+
|
|
10
|
+
/** A managed launch's kind: with a Working Repository, or companion-scoped. */
|
|
11
|
+
export function managedSessionKind(withRepository: boolean): SessionKind {
|
|
12
|
+
return withRepository ? "managed-repo" : "managed-companion";
|
|
13
|
+
}
|