@uniqbit/mate-core 1.0.0-canary.0 → 1.0.0-canary.2
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/hooks.json +10 -1
- package/claude-plugin/hooks/tokensave-route.mjs +52 -0
- package/opencode-plugin/src/server.ts +4 -0
- package/opencode-plugin/src/tui.tsx +2 -0
- package/opencode-plugin/tui.tsx +2 -0
- package/package.json +45 -16
- package/src/brand/terminal.ts +5 -0
- package/src/cli/commands/artifact/apply-context.ts +275 -0
- package/src/cli/commands/artifact/artifact.ts +4 -0
- package/src/cli/commands/artifact/delivery/archive.ts +13 -5
- package/src/cli/commands/artifact/delivery/environment.ts +36 -13
- package/src/cli/commands/artifact/delivery/link.ts +35 -15
- package/src/cli/commands/artifact/delivery/output.ts +31 -0
- package/src/cli/commands/artifact/finish/command.ts +50 -5
- package/src/cli/commands/artifact/finish/engine.ts +44 -11
- package/src/cli/commands/artifact/finish/git.ts +132 -19
- package/src/cli/commands/artifact/finish/openspec.ts +6 -1
- package/src/cli/commands/artifact/finish/worktree-cleanup.ts +92 -0
- package/src/cli/commands/cap/index-cmd.ts +64 -15
- package/src/cli/commands/cap/tokensave.ts +7 -5
- package/src/cli/commands/companion/link.ts +14 -1
- package/src/cli/commands/companion/open.ts +16 -11
- 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 +74 -12
- package/src/cli/commands/doctor.ts +20 -5
- 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/report/index.ts +20 -1
- package/src/cli/commands/session/context.ts +102 -0
- package/src/cli/commands/setup.ts +44 -10
- package/src/cli/commands/studio/factory-credential.ts +49 -0
- package/src/cli/commands/studio/index.ts +29 -2
- package/src/cli/commands/studio/payload.ts +249 -15
- package/src/cli/commands/studio/routes.ts +41 -8
- package/src/cli/commands/studio/selection.ts +142 -16
- package/src/cli/commands/studio/server.ts +403 -364
- package/src/cli/commands/studio/services.ts +60 -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/views/model.ts +18 -0
- package/src/cli/commands/studio/views/vault/markdown-tree.ts +267 -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 +8 -0
- package/src/cli/commands/update.ts +27 -1
- package/src/cli/commands/working/cleanup.ts +10 -1
- 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 +356 -0
- 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 +18 -0
- package/src/cli/parse-flags.ts +9 -1
- package/src/cli/repo-list-table.tsx +2 -0
- package/src/cli/setup-selector.tsx +79 -20
- package/src/cli/usage.ts +11 -1
- package/src/create-mate.ts +5 -4
- package/src/hooks/tokensave-route.ts +26 -0
- package/src/lib/apply-context/fingerprint.ts +174 -0
- package/src/lib/apply-context/protocol.ts +193 -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 +13 -11
- package/src/lib/delivery/archive-change.ts +14 -2
- package/src/lib/delivery/branches.ts +29 -5
- package/src/lib/delivery/environment.ts +7 -1
- package/src/lib/delivery/forge.ts +2 -2
- package/src/lib/delivery/merge-git.ts +261 -0
- package/src/lib/delivery/overlap.ts +11 -4
- package/src/lib/delivery/record-delivery.ts +97 -10
- package/src/lib/delivery/record.ts +67 -7
- package/src/lib/delivery/refresh.ts +104 -10
- package/src/lib/delivery/repository-access.ts +46 -2
- package/src/lib/delivery/resolve-branch.ts +162 -0
- package/src/lib/delivery/token.ts +7 -41
- 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 +381 -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 +972 -0
- package/src/lib/factory/sandbox.ts +292 -0
- package/src/lib/factory/worktree-branch.ts +17 -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/orchestrator/adapters/base.ts +55 -22
- package/src/lib/orchestrator/adapters/claude.ts +6 -1
- package/src/lib/orchestrator/config-store.ts +3 -2
- package/src/lib/orchestrator/editor.ts +29 -23
- package/src/lib/orchestrator/projection-entries.ts +56 -21
- 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-types.ts +33 -1
- package/src/lib/orchestrator/session-context-link.ts +67 -0
- package/src/lib/orchestrator/setup-compatibilities.ts +55 -12
- package/src/lib/orchestrator/types.ts +5 -0
- package/src/lib/orchestrator/working-repo-projection.ts +50 -7
- package/src/lib/orchestrator/workspace-document.ts +105 -0
- package/src/lib/package-paths.ts +29 -0
- package/src/lib/runtime-directory-refresh.ts +17 -1
- package/src/lib/workset/record.ts +513 -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 +830 -0
- package/src/opencode/companion-hooks.ts +45 -2
- package/src/opencode/enter-worktree.ts +72 -0
- package/src/opencode/tui.tsx +9 -4
- package/src/plugins.ts +1 -0
- package/src/runtime/claude-delivery-plan.ts +22 -5
- package/src/runtime/companion-git.ts +52 -10
- package/src/runtime/companion-guidance.ts +7 -7
- package/src/runtime/companion-lock.ts +30 -7
- package/src/runtime/env.ts +48 -3
- package/src/runtime/git-layout.ts +219 -0
- package/src/runtime/index.ts +24 -0
- package/src/runtime/physical-path.ts +111 -0
- package/src/runtime/policy.ts +36 -2
- package/src/runtime/runtime-directory.ts +5 -0
- package/src/runtime/secret-guard.ts +19 -5
- package/src/runtime/secret-patterns.ts +267 -34
- package/src/runtime/session-context.ts +98 -0
- package/src/runtime/tokensave-route.ts +152 -0
- package/src/runtime/wrap-state.ts +24 -16
- package/src/studio.ts +124 -0
- package/src/templates/capabilities/openspec-cap/mate-minimal/schema.yaml +10 -8
- package/src/templates/capabilities/openspec-cap/mate-v1/schema.yaml +16 -98
- package/src/templates/capabilities/openspec-cap/openspec-conventions.yaml +10 -2
- package/src/templates/mate-skills/agents/mate-apply-change/SKILL.md +76 -18
- 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 +2 -0
- package/src/templates/mate-skills/agents/mate-archive-change/SKILL.md +32 -5
- package/src/templates/mate-skills/agents/mate-backfill-spec/SKILL.md +8 -1
- package/src/templates/mate-skills/agents/mate-clarify-intent/SKILL.md +16 -1
- package/src/templates/mate-skills/agents/mate-explore-change/SKILL.md +22 -6
- package/src/templates/mate-skills/agents/mate-explore-change/references/openspec-explore.md +2 -0
- package/src/templates/mate-skills/agents/mate-grill-me/SKILL.md +8 -1
- 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 +7 -0
- package/src/templates/mate-skills/agents/mate-propose-change/SKILL.md +55 -50
- package/src/templates/mate-skills/agents/mate-propose-change/references/mate-revise.md +47 -0
- package/src/templates/mate-skills/agents/mate-propose-change/references/openspec-propose.md +2 -0
- package/src/templates/mate-skills/agents/mate-propose-change/references/openspec-update-change.md +2 -0
- package/src/templates/mate-skills/agents/mate-publish-artifact/SKILL.md +29 -10
- package/src/templates/mate-skills/agents/mate-publish-artifact/references/openspec.md +4 -2
- package/src/templates/mate-skills/agents/mate-show-me/SKILL.md +21 -0
- package/src/templates/mate-skills/agents/mate-simplify-code/SKILL.md +13 -0
- package/src/templates/mate-skills/claude/mate-apply-change/SKILL.md +76 -18
- 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 +2 -0
- package/src/templates/mate-skills/claude/mate-archive-change/SKILL.md +32 -5
- package/src/templates/mate-skills/claude/mate-backfill-spec/SKILL.md +8 -1
- package/src/templates/mate-skills/claude/mate-clarify-intent/SKILL.md +16 -1
- package/src/templates/mate-skills/claude/mate-explore-change/SKILL.md +22 -6
- package/src/templates/mate-skills/claude/mate-explore-change/references/openspec-explore.md +2 -0
- package/src/templates/mate-skills/claude/mate-grill-me/SKILL.md +8 -1
- 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 +7 -0
- package/src/templates/mate-skills/claude/mate-propose-change/SKILL.md +55 -50
- package/src/templates/mate-skills/claude/mate-propose-change/references/mate-revise.md +47 -0
- package/src/templates/mate-skills/claude/mate-propose-change/references/openspec-propose.md +2 -0
- package/src/templates/mate-skills/claude/mate-propose-change/references/openspec-update-change.md +2 -0
- package/src/templates/mate-skills/claude/mate-publish-artifact/SKILL.md +29 -10
- package/src/templates/mate-skills/claude/mate-publish-artifact/references/openspec.md +4 -2
- package/src/templates/mate-skills/claude/mate-show-me/SKILL.md +21 -0
- package/src/templates/mate-skills/claude/mate-simplify-code/SKILL.md +13 -0
- package/src/templates/mate-skills/openspec-references.ts +2 -0
- package/src/tools/setup/__snapshots__/runtime-surface-golden.test.ts.snap +364 -224
- package/src/tools/setup/capabilities/companion-mentions.ts +27 -0
- package/src/tools/setup/capabilities/context-mode.ts +34 -5
- package/src/tools/setup/capabilities/graphify-secrets.ts +2 -14
- package/src/tools/setup/capabilities/graphify.ts +34 -7
- package/src/tools/setup/capabilities/openspec.ts +12 -2
- 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 +77 -68
- package/src/tools/setup/engine.ts +3 -2
- package/src/tools/setup/install-contract.ts +8 -0
- package/src/tools/setup/mate-skill-copies.ts +51 -0
- package/src/tools/setup/package-managers/uv.ts +73 -11
- package/src/tools/setup/plugin.ts +5 -0
- package/src/tools/setup/providers/claude-plugin-hooks.ts +12 -0
- package/src/tools/setup/providers/claude-worktree-plugins.ts +122 -0
- package/src/tools/setup/providers/claude.ts +11 -5
- package/src/tools/setup/utils.ts +4 -0
- 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 +57 -16
- package/studio-dist/client/assets/companion-view-Csva26Ir.js +1 -0
- package/studio-dist/client/assets/delivery-path-DJMpRmiY.js +1 -0
- package/studio-dist/client/assets/dist-Dm7MtyHc.js +5 -0
- package/studio-dist/client/assets/factory-B7l9ZQyx.js +4 -0
- package/studio-dist/client/assets/index-n6uo_92S.js +40 -0
- package/studio-dist/client/assets/preload-helper-BLdHbfdN.js +1 -0
- package/studio-dist/client/assets/prepaint-CD5OpmTM.js +24 -0
- package/studio-dist/client/assets/queries-CN3JwMBX.js +1 -0
- package/studio-dist/client/assets/react-CabXf2Ds.js +1 -0
- package/studio-dist/client/assets/report-time-Dc-KOqQu.js +1 -0
- package/studio-dist/client/assets/reports-C01RsnMA.js +1 -0
- package/studio-dist/client/assets/rolldown-runtime-WkwZ5CU-.js +1 -0
- package/studio-dist/client/assets/routes-4pbC-2Hj.js +1 -0
- package/studio-dist/client/assets/skills-CihQganl.js +1 -0
- package/studio-dist/client/assets/spec-areas-C2L48N4C.js +1 -0
- package/studio-dist/client/assets/specs-D24_35_K.js +1 -0
- package/studio-dist/client/assets/studio-DKxfi691.css +1 -0
- package/studio-dist/client/assets/studio-queries-rvbJupCy.js +3 -0
- package/studio-dist/client/assets/terminal-eU5fzQzv.css +1 -0
- package/studio-dist/client/assets/vault-Bd4CQiTK.js +1 -0
- package/studio-dist/client/assets/warnings-V_Ys51wJ.js +1 -0
- package/studio-dist/client/assets/wasm-inline-C2en61B5.js +1 -0
- package/studio-dist/client/assets/workflow-BJejeVwQ.js +1 -0
- package/studio-dist/server/assets/__23tanstack-start-server-fn-resolver-BQKuMdJW.js +3881 -0
- package/studio-dist/server/assets/_tanstack-start-manifest_v.js +85 -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/companion-view-aBady57v.js +33 -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-BkKNjgkf.js +778 -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-D6xnjedJ.js +2385 -0
- package/studio-dist/server/assets/factory-DT3UzHlh.js +68 -0
- package/studio-dist/server/assets/model-PyPALjii.js +18 -0
- package/studio-dist/server/assets/prepaint-BMke0fo1.js +41 -0
- package/studio-dist/server/assets/queries-Ag2iL8q2.js +107 -0
- package/studio-dist/server/assets/react-COs0LHn-.js +51 -0
- package/studio-dist/server/assets/report-time-DAfzln-N.js +8 -0
- package/studio-dist/server/assets/reports-BnUNJVtx.js +126 -0
- package/studio-dist/server/assets/rolldown-runtime-DYf_mQCB.js +34 -0
- package/studio-dist/server/assets/router-BH--drIx.js +4298 -0
- package/studio-dist/server/assets/routes-khSDK1bV.js +361 -0
- package/studio-dist/server/assets/search-JAKurDNh.js +36 -0
- package/studio-dist/server/assets/shell-CboT2f66.js +51 -0
- package/studio-dist/server/assets/skills-MWYnWoKs.js +106 -0
- package/studio-dist/server/assets/spec-areas-DcnO6vW-.js +16 -0
- package/studio-dist/server/assets/specs-DE3w8hZP.js +155 -0
- package/studio-dist/server/assets/start-BW5ovN0k.js +33 -0
- package/studio-dist/server/assets/studio-BeltxxKt.js +216 -0
- package/studio-dist/server/assets/studio-queries-CLnP9kGu.js +3365 -0
- package/studio-dist/server/assets/utils-C9CX1kcy.js +221 -0
- package/studio-dist/server/assets/vault-BGulVoNh.js +70 -0
- package/studio-dist/server/assets/vault-CuyyhLyB.js +832 -0
- package/studio-dist/server/assets/views-Bd7cRr27.js +82 -0
- package/studio-dist/server/assets/warnings-BH05rOuG.js +15 -0
- package/studio-dist/server/assets/wasm-inline-CNeBKGwC.js +3 -0
- package/studio-dist/server/assets/workflow-BSuIKWqH.js +42 -0
- package/studio-dist/server/server.js +16220 -0
- package/src/cli/commands/studio/client-asset.ts +0 -16
- package/src/cli/commands/studio/views/client.ts +0 -44
- 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 -102
- package/src/cli/commands/studio/views/dashboard/index.tsx +0 -19
- package/src/cli/commands/studio/views/document.tsx +0 -910
- package/src/cli/commands/studio/views/error.tsx +0 -20
- package/src/cli/commands/studio/views/markdown.tsx +0 -250
- package/src/cli/commands/studio/views/palette.ts +0 -134
- package/src/cli/commands/studio/views/reports/index.tsx +0 -44
- package/src/cli/commands/studio/views/selection-fields.tsx +0 -14
- package/src/cli/commands/studio/views/skills/index.tsx +0 -68
- package/src/cli/commands/studio/views/specs/index.tsx +0 -149
- package/src/cli/commands/studio/views/studio-client/actions.ts +0 -51
- package/src/cli/commands/studio/views/studio-client/companion.ts +0 -13
- package/src/cli/commands/studio/views/studio-client/index.ts +0 -32
- package/src/cli/commands/studio/views/studio-client/keys.ts +0 -3
- package/src/cli/commands/studio/views/studio-client/main.ts +0 -3
- package/src/cli/commands/studio/views/studio-client/page.ts +0 -146
- package/src/cli/commands/studio/views/studio-client/panels.ts +0 -57
- package/src/cli/commands/studio/views/studio-client/reports.ts +0 -122
- package/src/cli/commands/studio/views/studio-client/theme.ts +0 -63
- package/src/cli/commands/studio/views/studio-client/vault-editor.ts +0 -166
- package/src/cli/commands/studio/views/studio-client/vault-pane.ts +0 -202
- package/src/cli/commands/studio/views/studio-client/vault-tree.ts +0 -258
- package/src/cli/commands/studio/views/studio-client.generated.ts +0 -2
- package/src/cli/commands/studio/views/styles.ts +0 -530
- package/src/cli/commands/studio/views/terminal.tsx +0 -484
- package/src/cli/commands/studio/views/vault/state.ts +0 -41
- package/src/cli/commands/studio/views/warnings.tsx +0 -21
- package/src/cli/commands/studio/views/workflow/delivery-path.tsx +0 -370
- package/src/cli/commands/studio/views/workflow/graph.ts +0 -220
- package/src/cli/commands/studio/views/workflow/index.tsx +0 -20
- package/src/cli/commands/studio/views/workflow/steps.ts +0 -278
- package/src/lib/components/theme.ts +0 -2
- package/src/tools/setup/git-utils.ts +0 -30
|
@@ -64,60 +64,175 @@ export function parseSecretsConfig(value: unknown): SecretPolicy {
|
|
|
64
64
|
};
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
|
|
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
|
+
}
|
|
68
132
|
|
|
69
|
-
/**
|
|
70
|
-
|
|
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 } {
|
|
71
139
|
const cached = compiled.get(pattern);
|
|
72
140
|
if (cached) return cached;
|
|
73
141
|
let source = "";
|
|
74
|
-
const
|
|
142
|
+
const folder = /[^/]\/+$/.test(pattern);
|
|
143
|
+
const body = pattern.replace(/^\/+/, "").replace(/\/+$/, "");
|
|
75
144
|
for (let i = 0; i < body.length; i++) {
|
|
76
145
|
const char = body[i];
|
|
77
|
-
|
|
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] === "*") {
|
|
78
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. */
|
|
79
153
|
if (body[i + 2] === "/") {
|
|
80
|
-
source += "(
|
|
154
|
+
source += "(?:[\\s\\S]*/)?";
|
|
81
155
|
i += 2;
|
|
82
156
|
} else {
|
|
83
|
-
source += "
|
|
157
|
+
source += "[\\s\\S]*";
|
|
84
158
|
i += 1;
|
|
85
159
|
}
|
|
86
160
|
} else if (char === "*") {
|
|
87
161
|
source += "[^/]*";
|
|
88
162
|
} else if (char === "?") {
|
|
89
163
|
source += "[^/]";
|
|
164
|
+
} else if (char === "\\" && i + 1 < body.length) {
|
|
165
|
+
source += escapeRegExp(body[++i]);
|
|
90
166
|
} else {
|
|
91
|
-
source += char
|
|
167
|
+
source += escapeRegExp(char);
|
|
92
168
|
}
|
|
93
169
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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;
|
|
99
184
|
}
|
|
100
185
|
|
|
101
|
-
function
|
|
102
|
-
return
|
|
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(/\/+$/, "");
|
|
103
211
|
}
|
|
104
212
|
|
|
105
|
-
export function matchesSecretPattern(
|
|
106
|
-
|
|
213
|
+
export function matchesSecretPattern(
|
|
214
|
+
filePath: string,
|
|
215
|
+
patterns: readonly string[],
|
|
216
|
+
options: SecretPathOptions = {},
|
|
217
|
+
): boolean {
|
|
218
|
+
const normalized = normalizePath(filePath, options);
|
|
107
219
|
if (!normalized) return false;
|
|
108
|
-
const
|
|
220
|
+
const name = normalized.slice(normalized.lastIndexOf("/") + 1);
|
|
109
221
|
return patterns.some((pattern) => {
|
|
110
|
-
const regExp =
|
|
111
|
-
return
|
|
112
|
-
? regExp.test(normalized)
|
|
113
|
-
: regExp.test(basename);
|
|
222
|
+
const { rule, regExp } = compile(pattern);
|
|
223
|
+
return regExp.test(rule.subject === "name" ? name : normalized);
|
|
114
224
|
});
|
|
115
225
|
}
|
|
116
226
|
|
|
117
227
|
/** A path is a secret file when it matches a deny pattern and no allow pattern. */
|
|
118
|
-
export function isSecretFile(
|
|
228
|
+
export function isSecretFile(
|
|
229
|
+
filePath: string,
|
|
230
|
+
policy: SecretPolicy,
|
|
231
|
+
options: SecretPathOptions = {},
|
|
232
|
+
): boolean {
|
|
119
233
|
return (
|
|
120
|
-
matchesSecretPattern(filePath, policy.deny) &&
|
|
234
|
+
matchesSecretPattern(filePath, policy.deny, options) &&
|
|
235
|
+
!matchesSecretPattern(filePath, policy.allow, options)
|
|
121
236
|
);
|
|
122
237
|
}
|
|
123
238
|
|
|
@@ -147,18 +262,136 @@ export function projectableSecretDenyPatterns(): string[] {
|
|
|
147
262
|
/** Ordinary files a broad glob also matches; a glob matching one is not aimed at secrets. */
|
|
148
263
|
const ORDINARY_SAMPLES = ["index.ts", "README.md", "config.json"];
|
|
149
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
|
+
|
|
150
274
|
/**
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
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}.
|
|
155
279
|
*/
|
|
156
|
-
|
|
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 {
|
|
157
380
|
const pattern = glob.trim();
|
|
158
|
-
if (!pattern) return false;
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
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
|
+
});
|
|
163
396
|
});
|
|
164
397
|
}
|
|
@@ -0,0 +1,98 @@
|
|
|
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 { 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
|
+
return {
|
|
82
|
+
ok: true,
|
|
83
|
+
checkoutRoot: projection.repoRoot,
|
|
84
|
+
context: {
|
|
85
|
+
companionPath,
|
|
86
|
+
repositoryPath: realDirectory(projection.repoRoot) ?? projection.repoRoot,
|
|
87
|
+
repositoryId: projection.repositoryId,
|
|
88
|
+
policyJson: policyDocument(policy),
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** The one JSON object `mate session context --json` prints. */
|
|
94
|
+
export function sessionContextReply(result: SessionContextResult): Record<string, unknown> {
|
|
95
|
+
return result.ok
|
|
96
|
+
? { protocol: SESSION_CONTEXT_PROTOCOL, ...result.context }
|
|
97
|
+
: { protocol: SESSION_CONTEXT_PROTOCOL, error: result.error };
|
|
98
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
|
|
5
|
+
import { checkoutRootOf, isSameClone, readGitLayout } from "./git-layout";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Routes tokensave tool calls to a linked worktree's own index. The MCP server
|
|
9
|
+
* stays bound to the checkout the session started in; a per-call `graph_root`
|
|
10
|
+
* is tokensave's own way to query another initialised project, read-only.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/** The tokensave store's database, relative to a checkout root. */
|
|
14
|
+
export const TOKENSAVE_DB = path.join(".tokensave", "tokensave.db");
|
|
15
|
+
|
|
16
|
+
/** Touched when routing last synced a worktree's index; its mtime throttles the next sync. */
|
|
17
|
+
export const ROUTE_SYNC_MARKER = path.join(".tokensave", "mate-route-synced");
|
|
18
|
+
|
|
19
|
+
/** At most one routed sync per worktree in this window. */
|
|
20
|
+
const SYNC_INTERVAL_MS = 30_000;
|
|
21
|
+
const SYNC_TIMEOUT_MS = 10_000;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Graph query tools that take `graph_root`. Edit, git, memory, branch and
|
|
25
|
+
* config tools do not: they keep acting on the served checkout.
|
|
26
|
+
*/
|
|
27
|
+
const GRAPH_ROOT_TOOLS = new Set([
|
|
28
|
+
"annotations",
|
|
29
|
+
"ambiguous_calls",
|
|
30
|
+
"body",
|
|
31
|
+
"by_qualified_name",
|
|
32
|
+
"call_chain",
|
|
33
|
+
"callees",
|
|
34
|
+
"callers",
|
|
35
|
+
"callers_for",
|
|
36
|
+
"circular",
|
|
37
|
+
"complexity",
|
|
38
|
+
"constructors",
|
|
39
|
+
"context",
|
|
40
|
+
"coupling",
|
|
41
|
+
"dead_code",
|
|
42
|
+
"dependency_depth",
|
|
43
|
+
"derives",
|
|
44
|
+
"distribution",
|
|
45
|
+
"doc",
|
|
46
|
+
"doc_coverage",
|
|
47
|
+
"dsm",
|
|
48
|
+
"entities",
|
|
49
|
+
"field_sites",
|
|
50
|
+
"file_dependents",
|
|
51
|
+
"files",
|
|
52
|
+
"find_exact_symbol",
|
|
53
|
+
"gini",
|
|
54
|
+
"god_class",
|
|
55
|
+
"health",
|
|
56
|
+
"hotspots",
|
|
57
|
+
"impact",
|
|
58
|
+
"implementations",
|
|
59
|
+
"impls",
|
|
60
|
+
"imports",
|
|
61
|
+
"inheritance_depth",
|
|
62
|
+
"largest",
|
|
63
|
+
"module_api",
|
|
64
|
+
"node",
|
|
65
|
+
"rank",
|
|
66
|
+
"read",
|
|
67
|
+
"recursion",
|
|
68
|
+
"search",
|
|
69
|
+
"signature",
|
|
70
|
+
"signature_search",
|
|
71
|
+
"similar",
|
|
72
|
+
"status",
|
|
73
|
+
"test_coverage",
|
|
74
|
+
"test_map",
|
|
75
|
+
"test_risk",
|
|
76
|
+
"todos",
|
|
77
|
+
"type_hierarchy",
|
|
78
|
+
"unsafe_patterns",
|
|
79
|
+
"unused_imports",
|
|
80
|
+
]);
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* True for a tokensave graph query that takes `graph_root`, by the name Claude
|
|
84
|
+
* (`mcp__tokensave__tokensave_<tool>`) or OpenCode (`tokensave_tokensave_<tool>`) gives it.
|
|
85
|
+
*/
|
|
86
|
+
export function isRoutableTokensaveTool(tool: string): boolean {
|
|
87
|
+
const match = /^(?:mcp__tokensave__|tokensave_)tokensave_([a-z_]+)$/.exec(tool);
|
|
88
|
+
return match !== null && GRAPH_ROOT_TOOLS.has(match[1]!);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export interface RouteDeps {
|
|
92
|
+
/** Brings the worktree's index up to date; the default runs `tokensave sync`, throttled. */
|
|
93
|
+
refresh?: (root: string) => void;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Runs `tokensave sync` in `root` unless it ran within {@link SYNC_INTERVAL_MS}. Nothing
|
|
98
|
+
* else keeps a worktree's index fresh: the MCP server watches only the served checkout.
|
|
99
|
+
* Bounded and silent; a failure leaves the index as it was.
|
|
100
|
+
*/
|
|
101
|
+
export function refreshWorktreeIndex(root: string): void {
|
|
102
|
+
const marker = path.join(root, ROUTE_SYNC_MARKER);
|
|
103
|
+
const last = fs.statSync(marker, { throwIfNoEntry: false })?.mtimeMs ?? 0;
|
|
104
|
+
if (Date.now() - last < SYNC_INTERVAL_MS) return;
|
|
105
|
+
// Touched first, so a failing or slow sync is not retried on every call.
|
|
106
|
+
fs.writeFileSync(marker, "");
|
|
107
|
+
spawnSync("tokensave", ["sync"], { cwd: root, stdio: "ignore", timeout: SYNC_TIMEOUT_MS });
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* `input` with `graph_root` set to the linked worktree containing `directory`,
|
|
112
|
+
* when `tool` takes `graph_root`, that worktree holds a tokensave index and
|
|
113
|
+
* `input` names no `graph_root`; the index is refreshed first. Otherwise, and
|
|
114
|
+
* on any error, `undefined`: the call passes unchanged.
|
|
115
|
+
*/
|
|
116
|
+
export function routeTokensaveInput(
|
|
117
|
+
tool: string,
|
|
118
|
+
directory: string,
|
|
119
|
+
input: unknown,
|
|
120
|
+
deps: RouteDeps = {},
|
|
121
|
+
): Record<string, unknown> | undefined {
|
|
122
|
+
try {
|
|
123
|
+
if (!isRoutableTokensaveTool(tool)) return undefined;
|
|
124
|
+
// A tool with no arguments sends none; anything else must be an arguments object.
|
|
125
|
+
const given = input === undefined ? {} : input;
|
|
126
|
+
if (given === null || typeof given !== "object" || Array.isArray(given)) return undefined;
|
|
127
|
+
const args = given as Record<string, unknown>;
|
|
128
|
+
if (args.graph_root !== undefined && args.graph_root !== null) return undefined;
|
|
129
|
+
const root = checkoutRootOf(directory);
|
|
130
|
+
if (!root || readGitLayout(root)?.kind !== "linked") return undefined;
|
|
131
|
+
if (!fs.statSync(path.join(root, TOKENSAVE_DB), { throwIfNoEntry: false })?.isFile())
|
|
132
|
+
return undefined;
|
|
133
|
+
try {
|
|
134
|
+
(deps.refresh ?? refreshWorktreeIndex)(root);
|
|
135
|
+
} catch {
|
|
136
|
+
// A stale index still answers better than the main checkout's.
|
|
137
|
+
}
|
|
138
|
+
return { ...args, graph_root: root };
|
|
139
|
+
} catch {
|
|
140
|
+
return undefined;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* The checkout a tokensave index command acts on: the one containing `cwd`
|
|
146
|
+
* when it belongs to the Working Repository's clone, so a session moved into a
|
|
147
|
+
* worktree indexes the worktree whatever `MATE_REPO_PATH` names; else `repoPath`.
|
|
148
|
+
*/
|
|
149
|
+
export function tokensaveCheckout(cwd: string, repoPath: string): string {
|
|
150
|
+
const root = checkoutRootOf(cwd);
|
|
151
|
+
return root && isSameClone(root, repoPath) ? root : repoPath;
|
|
152
|
+
}
|
|
@@ -30,12 +30,20 @@ export interface WrapState {
|
|
|
30
30
|
readonly runtimes: ReadonlySet<WrapRuntime>;
|
|
31
31
|
readonly carriedClaudeHookGroups: readonly ClaudeHookGroup[];
|
|
32
32
|
carriesClaudeHookGroup(group: ClaudeHookGroup): boolean;
|
|
33
|
+
/** Capability plugin IDs and directory marketplaces the Wrap recorded. */
|
|
34
|
+
readonly carriedClaudePlugins: readonly WrappedClaudePlugin[];
|
|
33
35
|
/** Capability plugin folders the wrap enables through a `directory` marketplace, as recorded. */
|
|
34
36
|
readonly carriedClaudePluginDirectories: readonly string[];
|
|
35
37
|
/** MCP server names the wrap declared in `.opencode/opencode.json`; user servers are not listed. */
|
|
36
38
|
readonly openCodeMcpServers: readonly string[];
|
|
37
39
|
}
|
|
38
40
|
|
|
41
|
+
export interface WrappedClaudePlugin {
|
|
42
|
+
readonly id: string;
|
|
43
|
+
readonly marketplace: string;
|
|
44
|
+
readonly directory: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
39
47
|
export const WRAP_RUNTIMES: readonly WrapRuntime[] = ["claude", "opencode"];
|
|
40
48
|
|
|
41
49
|
/** Wrapped for a runtime: a document, a copy or a link is recorded for it. */
|
|
@@ -48,27 +56,23 @@ function wrappedFor(manifest: Manifest, runtime: WrapRuntime): boolean {
|
|
|
48
56
|
}
|
|
49
57
|
|
|
50
58
|
/**
|
|
51
|
-
*
|
|
52
|
-
*
|
|
59
|
+
* Each enabled plugin of a recorded `directory` marketplace: a marketplace
|
|
60
|
+
* without an enabled plugin loads nothing.
|
|
53
61
|
*/
|
|
54
|
-
function
|
|
62
|
+
function carriedPlugins(manifest: Manifest): WrappedClaudePlugin[] {
|
|
55
63
|
const marketplaces = recordedMapEntries(manifest, CLAUDE_SETTINGS_DOCUMENT, [
|
|
56
64
|
"extraKnownMarketplaces",
|
|
57
65
|
]);
|
|
58
66
|
const enabled = recordedMapEntries(manifest, CLAUDE_SETTINGS_DOCUMENT, ["enabledPlugins"]);
|
|
59
|
-
|
|
60
|
-
Object.entries(enabled)
|
|
61
|
-
.filter(([, value]) => value === true)
|
|
62
|
-
.map(([id]) => id.slice(id.lastIndexOf("@") + 1)),
|
|
63
|
-
);
|
|
64
|
-
return Object.entries(marketplaces).flatMap(([name, entry]) => {
|
|
67
|
+
return Object.entries(marketplaces).flatMap(([marketplace, entry]) => {
|
|
65
68
|
const source = isRecord(entry) ? entry.source : undefined;
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
69
|
+
if (!isRecord(source) || source.source !== "directory" || typeof source.path !== "string") {
|
|
70
|
+
return [];
|
|
71
|
+
}
|
|
72
|
+
const directory = source.path;
|
|
73
|
+
return Object.entries(enabled)
|
|
74
|
+
.filter(([id, value]) => value === true && id.slice(id.lastIndexOf("@") + 1) === marketplace)
|
|
75
|
+
.map(([id]) => ({ id, marketplace, directory }));
|
|
72
76
|
});
|
|
73
77
|
}
|
|
74
78
|
|
|
@@ -85,11 +89,15 @@ export function wrapStateOf(manifest: Manifest): WrapState {
|
|
|
85
89
|
isHookGroup,
|
|
86
90
|
);
|
|
87
91
|
const carriedKeys = new Set(carried.map(hookGroupKey));
|
|
92
|
+
const plugins = carriedPlugins(manifest);
|
|
88
93
|
return {
|
|
89
94
|
runtimes: new Set(WRAP_RUNTIMES.filter((runtime) => wrappedFor(manifest, runtime))),
|
|
90
95
|
carriedClaudeHookGroups: carried,
|
|
91
96
|
carriesClaudeHookGroup: (group) => carriedKeys.has(hookGroupKey(group)),
|
|
92
|
-
|
|
97
|
+
carriedClaudePlugins: plugins,
|
|
98
|
+
carriedClaudePluginDirectories: [
|
|
99
|
+
...new Map(plugins.map(({ marketplace, directory }) => [marketplace, directory])).values(),
|
|
100
|
+
],
|
|
93
101
|
openCodeMcpServers: recordedMapKeys(
|
|
94
102
|
manifest,
|
|
95
103
|
OPENCODE_CONFIG_DOCUMENT,
|