@uniqbit/mate-core 1.0.0-canary.0 → 1.0.0-canary.3
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 +3 -1
- package/opencode-plugin/tui.tsx +4 -1
- 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 +21 -26
- 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
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@mate:<path>` names a file or folder in the mate Companion Repository.
|
|
3
|
+
* `mate claude` hands over the companion ($MATE_ARTIFACT_PATH) and its secret policy
|
|
4
|
+
* ($MATE_POLICY_JSON); a plain `claude` session asks `mate session context` instead.
|
|
5
|
+
* Without a companion and a readable policy, the mod offers no rows and attaches nothing.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { EngineInterface, FsEntry, Register } from "claude-code";
|
|
9
|
+
import {
|
|
10
|
+
NO_COMPANION,
|
|
11
|
+
PREFIX,
|
|
12
|
+
UPDATE_MATE,
|
|
13
|
+
type ContextFailure,
|
|
14
|
+
type Entry,
|
|
15
|
+
type Query,
|
|
16
|
+
type SecretPolicy,
|
|
17
|
+
type SessionContext,
|
|
18
|
+
baseName,
|
|
19
|
+
folderNote,
|
|
20
|
+
isAbsolute,
|
|
21
|
+
isInside,
|
|
22
|
+
joinPath,
|
|
23
|
+
launcherFolder,
|
|
24
|
+
launcherPath,
|
|
25
|
+
parseContext,
|
|
26
|
+
parseMention,
|
|
27
|
+
parsePolicy,
|
|
28
|
+
queryOf,
|
|
29
|
+
rank,
|
|
30
|
+
relativeInside,
|
|
31
|
+
rowText,
|
|
32
|
+
secretMatch,
|
|
33
|
+
toEntries,
|
|
34
|
+
} from "./companion.ts";
|
|
35
|
+
|
|
36
|
+
/** How long the menu reuses Mate's answer, and a companion's file list is kept. */
|
|
37
|
+
const REFRESH_MS = 30_000;
|
|
38
|
+
const CONTEXT_TIMEOUT_MS = 5_000;
|
|
39
|
+
/** Most companion matches for a search, after the engine's own rows. */
|
|
40
|
+
const ROWS = 15;
|
|
41
|
+
/** Top-level folders offered after a bare `@`. */
|
|
42
|
+
const BARE_ROWS = 4;
|
|
43
|
+
/** Most files and folders the walk visits when git cannot list them. */
|
|
44
|
+
const WALK_LIMIT = 20_000;
|
|
45
|
+
/** Most names a folder mention lists. */
|
|
46
|
+
const FOLDER_LIMIT = 200;
|
|
47
|
+
const SKIPPED = new Set([".git", "node_modules"]);
|
|
48
|
+
|
|
49
|
+
type Context = SessionContext | ContextFailure;
|
|
50
|
+
|
|
51
|
+
let parsed: { json: string | undefined; result: ReturnType<typeof parsePolicy> } | undefined;
|
|
52
|
+
let asked: { sessionRoot: string; answer: Promise<Context>; at: number } | undefined;
|
|
53
|
+
let listed: { root: string; policyJson: string; entries: Entry[]; at: number } | undefined;
|
|
54
|
+
|
|
55
|
+
/** A clock that went back counts as stale. */
|
|
56
|
+
function isFresh(at: number, now: number): boolean {
|
|
57
|
+
return now >= at && now - at < REFRESH_MS;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** `path`'s real location, links followed, or undefined when nothing is there. */
|
|
61
|
+
async function realPath($: EngineInterface, path: string) {
|
|
62
|
+
const stat = await $.fs.stat(path, { resolve: true }).catch(() => undefined);
|
|
63
|
+
return stat === undefined ? undefined : { kind: stat.kind, path: stat.realPath ?? path };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async function realFolder($: EngineInterface, path: string): Promise<string | undefined> {
|
|
67
|
+
if (!isAbsolute(path)) return undefined;
|
|
68
|
+
const found = await realPath($, path);
|
|
69
|
+
return found?.kind === "dir" ? found.path : undefined;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* A launch is authoritative: a path that names no folder or a missing policy
|
|
74
|
+
* is a failure, never a reason to ask Mate.
|
|
75
|
+
*/
|
|
76
|
+
async function launchContext($: EngineInterface): Promise<Context | undefined> {
|
|
77
|
+
const path = await $.env.get("MATE_ARTIFACT_PATH");
|
|
78
|
+
if (path === undefined) return undefined;
|
|
79
|
+
const root = await realFolder($, path);
|
|
80
|
+
if (root === undefined) return { reason: NO_COMPANION };
|
|
81
|
+
const json = await $.env.get("MATE_POLICY_JSON");
|
|
82
|
+
if (parsed === undefined || parsed.json !== json) parsed = { json, result: parsePolicy(json) };
|
|
83
|
+
const { result } = parsed;
|
|
84
|
+
if ("error" in result) return { reason: `${result.error}, ${UPDATE_MATE}` };
|
|
85
|
+
return { root, policyJson: json!, policy: result.policy };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function errorText(error: unknown): string {
|
|
89
|
+
if (typeof error === "object" && error !== null && "message" in error) {
|
|
90
|
+
return String((error as { message: unknown }).message);
|
|
91
|
+
}
|
|
92
|
+
return String(error);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Runs from the launcher's folder, never the session's (see `launcherFolder`). */
|
|
96
|
+
async function askMate($: EngineInterface, sessionRoot: string): Promise<Context> {
|
|
97
|
+
const home = (await $.env.get("HOME")) ?? (await $.env.get("USERPROFILE"));
|
|
98
|
+
if (!home) return { reason: `no home folder is set to find mate's launcher in, ${UPDATE_MATE}` };
|
|
99
|
+
if (!isAbsolute(sessionRoot)) {
|
|
100
|
+
return {
|
|
101
|
+
reason: `the session folder ${sessionRoot} is not an absolute path to ask mate about`,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
const launcher = launcherPath(home);
|
|
105
|
+
let stdout: string;
|
|
106
|
+
let exitCode: number;
|
|
107
|
+
try {
|
|
108
|
+
({ stdout, exitCode } = await $.process.run(
|
|
109
|
+
[launcher, "session", "context", "--repo", sessionRoot, "--json"],
|
|
110
|
+
{ cwd: launcherFolder(home), timeoutMs: CONTEXT_TIMEOUT_MS },
|
|
111
|
+
));
|
|
112
|
+
} catch (error) {
|
|
113
|
+
const message = errorText(error);
|
|
114
|
+
return {
|
|
115
|
+
reason: /tim(?:e|ed)[ -]?out|ETIMEDOUT/i.test(message)
|
|
116
|
+
? `\`mate session context\` did not answer within ${CONTEXT_TIMEOUT_MS / 1000} seconds, so mate's secret policy is unknown. \`mate doctor\` checks the installation`
|
|
117
|
+
: `mate's launcher ${launcher} could not run (${message}), ${UPDATE_MATE}`,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
const answer = parseContext(stdout);
|
|
121
|
+
if ("reason" in answer) return answer;
|
|
122
|
+
/** Mate exits 0 on every answer it stands by; a failure after printing one voids it. */
|
|
123
|
+
if (exitCode !== 0) {
|
|
124
|
+
return {
|
|
125
|
+
reason: `\`mate session context\` named a companion but exited with status ${exitCode}, so its answer is not used. \`mate doctor\` checks the installation`,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
const root = await realFolder($, answer.root);
|
|
129
|
+
return root === undefined ? { reason: NO_COMPANION } : { ...answer, root };
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Shares Mate's answer, pending or not, for REFRESH_MS, failures included, so a
|
|
134
|
+
* slow or missing Mate costs one run per window, not per keystroke. A failure
|
|
135
|
+
* that arrives after the asking lookup was cancelled may be the cancel's own,
|
|
136
|
+
* so it is not kept.
|
|
137
|
+
*/
|
|
138
|
+
async function menuContext($: EngineInterface, signal: AbortSignal): Promise<Context> {
|
|
139
|
+
const launch = await launchContext($);
|
|
140
|
+
if (launch !== undefined) return launch;
|
|
141
|
+
const sessionRoot = await $.session.root();
|
|
142
|
+
const now = await $.clock.now();
|
|
143
|
+
let entry = asked;
|
|
144
|
+
if (entry === undefined || entry.sessionRoot !== sessionRoot || !isFresh(entry.at, now)) {
|
|
145
|
+
const started = { sessionRoot, answer: askMate($, sessionRoot), at: now };
|
|
146
|
+
const forget = () => {
|
|
147
|
+
if (asked === started) asked = undefined;
|
|
148
|
+
};
|
|
149
|
+
started.answer.then((answer) => {
|
|
150
|
+
if ("reason" in answer && signal.aborted) forget();
|
|
151
|
+
}, forget);
|
|
152
|
+
asked = entry = started;
|
|
153
|
+
}
|
|
154
|
+
const answer = await entry.answer;
|
|
155
|
+
signal.throwIfAborted();
|
|
156
|
+
return answer;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** A sent mention asks Mate afresh, never reusing the menu's answer. */
|
|
160
|
+
async function mentionContext($: EngineInterface): Promise<Context> {
|
|
161
|
+
return (await launchContext($)) ?? askMate($, await $.session.root());
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** Links count as files, as in git. */
|
|
165
|
+
async function walk($: EngineInterface, root: string, signal: AbortSignal): Promise<string[]> {
|
|
166
|
+
const files: string[] = [];
|
|
167
|
+
const folders = [""];
|
|
168
|
+
for (let i = 0; i < folders.length && files.length < WALK_LIMIT; i++) {
|
|
169
|
+
const rel = folders[i]!;
|
|
170
|
+
// oxlint-disable-next-line no-await-in-loop -- breadth first: each folder's children decide what to list next.
|
|
171
|
+
const children = await $.fs.list(joinPath(root, rel)).catch(() => []);
|
|
172
|
+
signal.throwIfAborted();
|
|
173
|
+
for (const child of children) {
|
|
174
|
+
if (SKIPPED.has(child.name)) continue;
|
|
175
|
+
if (child.kind === "dir") {
|
|
176
|
+
if (folders.length < WALK_LIMIT) folders.push(`${rel}${child.name}/`);
|
|
177
|
+
} else if (child.kind === "file" || child.isLink) {
|
|
178
|
+
files.push(rel + child.name);
|
|
179
|
+
if (files.length >= WALK_LIMIT) break;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return files;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* The companion's files, from git so gitignored files stay out (deleted ones
|
|
188
|
+
* too), else from a folder walk. git lists nothing for a companion that is no
|
|
189
|
+
* repository of its own inside one that ignores it, so an empty list is walked
|
|
190
|
+
* too. Throws when the dispatch was abandoned, so a cut-short list is never kept.
|
|
191
|
+
*/
|
|
192
|
+
async function listFiles($: EngineInterface, root: string, signal: AbortSignal): Promise<string[]> {
|
|
193
|
+
try {
|
|
194
|
+
const run = (args: string[]) =>
|
|
195
|
+
$.process.run(["git", "ls-files", "-z", ...args], { cwd: root, timeoutMs: 10_000 });
|
|
196
|
+
const [present, deleted] = await Promise.all([
|
|
197
|
+
run(["--cached", "--others", "--exclude-standard"]),
|
|
198
|
+
run(["--deleted"]),
|
|
199
|
+
]);
|
|
200
|
+
if (present.exitCode === 0) {
|
|
201
|
+
const files = present.stdout.split("\0");
|
|
202
|
+
if (present.isStdoutTruncated) files.pop(); // cut mid-path
|
|
203
|
+
const gone = new Set(deleted.exitCode === 0 ? deleted.stdout.split("\0") : []);
|
|
204
|
+
const paths = files.filter((file) => file !== "" && !gone.has(file));
|
|
205
|
+
if (paths.length > 0) return paths;
|
|
206
|
+
}
|
|
207
|
+
} catch {
|
|
208
|
+
signal.throwIfAborted();
|
|
209
|
+
/** git could not run (not installed, timed out): walk below. */
|
|
210
|
+
}
|
|
211
|
+
return walk($, root, signal);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** The companion's rows to rank, kept for REFRESH_MS per companion and policy. */
|
|
215
|
+
async function entriesOf(
|
|
216
|
+
$: EngineInterface,
|
|
217
|
+
context: SessionContext,
|
|
218
|
+
signal: AbortSignal,
|
|
219
|
+
): Promise<readonly Entry[]> {
|
|
220
|
+
const { root, policyJson } = context;
|
|
221
|
+
const now = await $.clock.now();
|
|
222
|
+
if (listed?.root === root && listed.policyJson === policyJson && isFresh(listed.at, now)) {
|
|
223
|
+
return listed.entries;
|
|
224
|
+
}
|
|
225
|
+
const entries = toEntries(await listFiles($, root, signal), context.policy);
|
|
226
|
+
listed = { root, policyJson, entries, at: now };
|
|
227
|
+
return entries;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Whether the menu may offer an entry, as a mention would attach it: it is
|
|
232
|
+
* still a file or folder, it leads to no place outside the companion, and its
|
|
233
|
+
* real location is no secret file or folder. The listed path was checked already.
|
|
234
|
+
*/
|
|
235
|
+
async function isOfferable(
|
|
236
|
+
$: EngineInterface,
|
|
237
|
+
root: string,
|
|
238
|
+
policy: SecretPolicy,
|
|
239
|
+
entry: Entry,
|
|
240
|
+
): Promise<boolean> {
|
|
241
|
+
const target = await $.fs
|
|
242
|
+
.stat(joinPath(root, entry.rel), { resolve: true })
|
|
243
|
+
.catch(() => undefined);
|
|
244
|
+
if (target?.realPath === undefined) return false;
|
|
245
|
+
const realRel = relativeInside(target.realPath, root);
|
|
246
|
+
if (realRel === undefined) return false;
|
|
247
|
+
if (target.kind !== "dir" && target.kind !== "file") return false;
|
|
248
|
+
return secretMatch(policy, realRel, target.kind === "dir") === undefined;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/** The first `limit` of the ranked entries the menu may offer, checked a batch at a time. */
|
|
252
|
+
async function offerable(
|
|
253
|
+
$: EngineInterface,
|
|
254
|
+
root: string,
|
|
255
|
+
policy: SecretPolicy,
|
|
256
|
+
ranked: readonly Entry[],
|
|
257
|
+
limit: number,
|
|
258
|
+
signal: AbortSignal,
|
|
259
|
+
): Promise<Entry[]> {
|
|
260
|
+
const kept: Entry[] = [];
|
|
261
|
+
for (let at = 0; at < ranked.length && kept.length < limit; at += limit) {
|
|
262
|
+
const batch = ranked.slice(at, at + limit);
|
|
263
|
+
// oxlint-disable-next-line no-await-in-loop -- the next batch is checked only when this one left room.
|
|
264
|
+
const isKept = await Promise.all(batch.map((entry) => isOfferable($, root, policy, entry)));
|
|
265
|
+
signal.throwIfAborted();
|
|
266
|
+
kept.push(...batch.filter((_, i) => isKept[i]));
|
|
267
|
+
}
|
|
268
|
+
return kept.slice(0, limit);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
async function companionRows($: EngineInterface, query: Query, signal: AbortSignal) {
|
|
272
|
+
const context = await menuContext($, signal);
|
|
273
|
+
if ("reason" in context) return [];
|
|
274
|
+
const { root, policy } = context;
|
|
275
|
+
const sessionRoot = await $.session.root();
|
|
276
|
+
const session = (await realPath($, sessionRoot))?.path ?? sessionRoot;
|
|
277
|
+
if (isInside(session, root)) return [];
|
|
278
|
+
|
|
279
|
+
const entries = await entriesOf($, context, signal);
|
|
280
|
+
const ranked = rank(entries, query, entries.length);
|
|
281
|
+
const limit = !query.isExplicit && query.query === "" ? BARE_ROWS : ROWS;
|
|
282
|
+
const offered = await offerable($, root, policy, ranked, limit, signal);
|
|
283
|
+
const description = `${baseName(root)} (mate companion)`;
|
|
284
|
+
const rows = offered.flatMap((entry) => {
|
|
285
|
+
const text = rowText(entry);
|
|
286
|
+
return text === undefined ? [] : [{ text, label: PREFIX + entry.rel, description }];
|
|
287
|
+
});
|
|
288
|
+
if (!query.isExplicit && PREFIX.startsWith(query.query.toLowerCase())) {
|
|
289
|
+
rows.unshift({ text: `@${PREFIX}`, label: PREFIX, description });
|
|
290
|
+
}
|
|
291
|
+
return rows;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
function under(rel: string, name: string): string {
|
|
295
|
+
return rel === "" ? name : `${rel}/${name}`;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/** What a mention attaches instead of a file: a note for Claude. */
|
|
299
|
+
function note(text: string) {
|
|
300
|
+
return { type: null, context: [text] };
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
export const register: Register = (on) => {
|
|
304
|
+
on("prompt.autocomplete", { token: /^@/ }, async ($, e, next) => {
|
|
305
|
+
const result = await next(e);
|
|
306
|
+
const query = queryOf(e.token);
|
|
307
|
+
if (query === undefined) return result;
|
|
308
|
+
const rows = await companionRows($, query, next.signal).catch(() => []);
|
|
309
|
+
return rows.length === 0
|
|
310
|
+
? result
|
|
311
|
+
: { ...result, suggestions: [...result.suggestions, ...rows] };
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
on("prompt.mention", { mention: /^mate:/i }, async ($, e, next) => {
|
|
315
|
+
const named = parseMention(e.mention);
|
|
316
|
+
if (named === undefined) return next(e);
|
|
317
|
+
if ("refused" in named) return note(`@${e.mention} was not attached: ${named.refused}.`);
|
|
318
|
+
|
|
319
|
+
const context = await mentionContext($);
|
|
320
|
+
if ("reason" in context) return note(`@${e.mention} was not attached: ${context.reason}.`);
|
|
321
|
+
const { root, policy } = context;
|
|
322
|
+
|
|
323
|
+
const shown = `@${PREFIX}${named.rel}`;
|
|
324
|
+
const path = joinPath(root, named.rel);
|
|
325
|
+
const target = await $.fs.stat(path, { resolve: true }).catch(() => undefined);
|
|
326
|
+
if (target === undefined) {
|
|
327
|
+
return note(`${shown} was not found in the mate companion repo (${root}).`);
|
|
328
|
+
}
|
|
329
|
+
if (target.realPath === undefined) {
|
|
330
|
+
return note(`${shown} was not attached: ${path} is a link that leads nowhere.`);
|
|
331
|
+
}
|
|
332
|
+
const realRel = relativeInside(target.realPath, root);
|
|
333
|
+
if (realRel === undefined) {
|
|
334
|
+
return note(
|
|
335
|
+
`${shown} was not attached: ${path} is a link to ${target.realPath}, outside the mate companion repo.`,
|
|
336
|
+
);
|
|
337
|
+
}
|
|
338
|
+
/** Both the path named and where it leads count; folders above the companion never match. */
|
|
339
|
+
const secretOf = (namedRel: string, landedRel: string, isDir: boolean) =>
|
|
340
|
+
secretMatch(policy, namedRel, isDir) ?? secretMatch(policy, landedRel, isDir);
|
|
341
|
+
if (target.kind === "dir") {
|
|
342
|
+
const secretFolder = secretOf(named.rel, realRel, true);
|
|
343
|
+
if (secretFolder !== undefined) {
|
|
344
|
+
return note(
|
|
345
|
+
`${shown} was not attached: mate keeps secret folders (\`${secretFolder}\`) away from Claude.`,
|
|
346
|
+
);
|
|
347
|
+
}
|
|
348
|
+
/** List where the checks looked: a link repointed since would list another folder. */
|
|
349
|
+
const landedFolder = target.realPath;
|
|
350
|
+
const children = await $.fs.list(landedFolder);
|
|
351
|
+
/** A linked entry is judged where it leads, as a mention of it would be. */
|
|
352
|
+
const judged = await Promise.all(
|
|
353
|
+
children.map(async (child: FsEntry) => {
|
|
354
|
+
if (child.name === ".git") return undefined;
|
|
355
|
+
const namedRel = under(named.rel, child.name);
|
|
356
|
+
if (!child.isLink) {
|
|
357
|
+
const isDir = child.kind === "dir";
|
|
358
|
+
const isSecret = secretOf(namedRel, under(realRel, child.name), isDir) !== undefined;
|
|
359
|
+
return isSecret ? undefined : { name: child.name, isDir };
|
|
360
|
+
}
|
|
361
|
+
const landed = await $.fs
|
|
362
|
+
.stat(joinPath(landedFolder, child.name), { resolve: true })
|
|
363
|
+
.catch(() => undefined);
|
|
364
|
+
const landedRel =
|
|
365
|
+
landed?.realPath === undefined ? undefined : relativeInside(landed.realPath, root);
|
|
366
|
+
if (landed === undefined || landedRel === undefined) return undefined;
|
|
367
|
+
const isDir = landed.kind === "dir";
|
|
368
|
+
return secretOf(namedRel, landedRel, isDir) === undefined
|
|
369
|
+
? { name: child.name, isDir }
|
|
370
|
+
: undefined;
|
|
371
|
+
}),
|
|
372
|
+
);
|
|
373
|
+
const shownChildren = judged.filter((child) => child !== undefined);
|
|
374
|
+
return note(folderNote(shown, path, shownChildren, FOLDER_LIMIT));
|
|
375
|
+
}
|
|
376
|
+
if (target.kind !== "file") {
|
|
377
|
+
return note(`${shown} was not attached: ${path} is not a file or folder.`);
|
|
378
|
+
}
|
|
379
|
+
const secret = secretOf(named.rel, realRel, false);
|
|
380
|
+
if (secret !== undefined) {
|
|
381
|
+
return note(
|
|
382
|
+
`${shown} was not attached: mate keeps secret files (\`${secret}\`) away from Claude.`,
|
|
383
|
+
);
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/** Read where the checks looked, not through the link, which could change. */
|
|
387
|
+
const read = await next({ ...e, path: target.realPath });
|
|
388
|
+
if (read.deny !== undefined) return read;
|
|
389
|
+
return {
|
|
390
|
+
...read,
|
|
391
|
+
context: [
|
|
392
|
+
...(read.context ?? []),
|
|
393
|
+
`${shown} is the file ${target.realPath} in the mate companion repo.`,
|
|
394
|
+
],
|
|
395
|
+
};
|
|
396
|
+
}).catch(($, e, next) =>
|
|
397
|
+
next.called
|
|
398
|
+
? next(e)
|
|
399
|
+
: note(
|
|
400
|
+
`@${e.mention} was not attached: looking it up in the mate companion repo failed (${next.error.message ?? next.error.kind}).`,
|
|
401
|
+
),
|
|
402
|
+
);
|
|
403
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"description": "Mate hooks \u2014 PreToolUse artifact-path and secret guardrail, SessionStart banner, companion guidance, session prepare then companion instructions, SubagentStart companion instructions",
|
|
2
|
+
"description": "Mate hooks \u2014 PreToolUse artifact-path and secret guardrail, PreToolUse tokensave worktree routing, SessionStart banner, companion guidance, session prepare then companion instructions, SubagentStart companion instructions",
|
|
3
3
|
"hooks": {
|
|
4
4
|
"PreToolUse": [
|
|
5
5
|
{
|
|
@@ -10,6 +10,15 @@
|
|
|
10
10
|
"command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/validate-artifact-path.mjs\""
|
|
11
11
|
}
|
|
12
12
|
]
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"matcher": "mcp__tokensave__.*",
|
|
16
|
+
"hooks": [
|
|
17
|
+
{
|
|
18
|
+
"type": "command",
|
|
19
|
+
"command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/tokensave-route.mjs\""
|
|
20
|
+
}
|
|
21
|
+
]
|
|
13
22
|
}
|
|
14
23
|
],
|
|
15
24
|
"SessionStart": [
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Thin shim for src/hooks/tokensave-route.ts, loaded through ts-loader.mjs: the
|
|
4
|
+
* installed plugin sits inside node_modules, where node's native type stripping is off.
|
|
5
|
+
* Runs on every tokensave call, so it answers outside a linked worktree (a `.git`
|
|
6
|
+
* file, not a folder) before loading any TypeScript.
|
|
7
|
+
*/
|
|
8
|
+
import fs from "node:fs";
|
|
9
|
+
import path from "node:path";
|
|
10
|
+
|
|
11
|
+
async function readInput() {
|
|
12
|
+
if (process.stdin.isTTY) return null;
|
|
13
|
+
const chunks = [];
|
|
14
|
+
for await (const chunk of process.stdin) chunks.push(Buffer.from(chunk));
|
|
15
|
+
try {
|
|
16
|
+
return JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
17
|
+
} catch {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** True when the nearest `.git` at or above `directory` is a file: a linked worktree. */
|
|
23
|
+
function inLinkedWorktree(directory) {
|
|
24
|
+
try {
|
|
25
|
+
let current = fs.realpathSync(directory);
|
|
26
|
+
for (;;) {
|
|
27
|
+
const dotGit = fs.statSync(path.join(current, ".git"), { throwIfNoEntry: false });
|
|
28
|
+
if (dotGit) return dotGit.isFile();
|
|
29
|
+
const parent = path.dirname(current);
|
|
30
|
+
if (parent === current) return false;
|
|
31
|
+
current = parent;
|
|
32
|
+
}
|
|
33
|
+
} catch {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
try {
|
|
39
|
+
const input = await readInput();
|
|
40
|
+
if (typeof input?.cwd === "string" && inLinkedWorktree(input.cwd)) {
|
|
41
|
+
await import("./ts-loader.mjs");
|
|
42
|
+
const { buildTokensaveRoute } = await import("../../src/hooks/tokensave-route.ts");
|
|
43
|
+
const { stdout } = buildTokensaveRoute(input);
|
|
44
|
+
if (stdout) {
|
|
45
|
+
process.stdout.on("error", () => {});
|
|
46
|
+
process.stdout.write(stdout);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
} catch {
|
|
50
|
+
// Any failure passes the call unchanged.
|
|
51
|
+
}
|
|
52
|
+
process.exitCode = 0;
|
|
@@ -2,9 +2,11 @@ import { Plugin } from "@opencode/plugin";
|
|
|
2
2
|
import type { Context } from "@opencode/plugin/promise/plugin";
|
|
3
3
|
import {
|
|
4
4
|
registerCompanionHooks,
|
|
5
|
+
registerTokensaveRouting,
|
|
5
6
|
repositoryWrappedForOpenCode,
|
|
6
7
|
} from "../../src/opencode/companion-hooks";
|
|
7
8
|
import { readContext } from "../../src/opencode/companion-policy";
|
|
9
|
+
import { registerEnterWorktree } from "../../src/opencode/enter-worktree";
|
|
8
10
|
import { registerSessionPrepare } from "../../src/opencode/session-prepare";
|
|
9
11
|
import { hasLaunchEnvironment } from "../../src/runtime/env";
|
|
10
12
|
import { spawnPrepareRunner } from "../../src/runtime/session-prepare-runner";
|
|
@@ -53,7 +55,9 @@ export const MateOpenCodePlugin = Plugin.define({
|
|
|
53
55
|
|
|
54
56
|
await registerCompanionAccess(api, context.companionPath);
|
|
55
57
|
await registerCompanionHooks(api, context, env);
|
|
58
|
+
await registerTokensaveRouting(api);
|
|
56
59
|
await registerCompanion(api, context, env);
|
|
60
|
+
await registerEnterWorktree(api, context);
|
|
57
61
|
/** Last: the guardrails above are live while the local phase holds `setup`. */
|
|
58
62
|
const prepareCleanup = await registerPrepare(api, context.companionPath, env);
|
|
59
63
|
return async () => {
|
package/opencode-plugin/tui.tsx
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
|
+
/** @jsxRuntime automatic */
|
|
2
|
+
/** @jsxImportSource @opentui/solid */
|
|
1
3
|
/** Root entry for a plugin bound by directory path; see `server.ts`. */
|
|
2
|
-
|
|
4
|
+
// Explicit extensions let OpenTUI prescan the re-export chain in node_modules.
|
|
5
|
+
export { default } from "./src/tui.tsx";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniqbit/mate-core",
|
|
3
|
-
"version": "1.0.0-canary.
|
|
3
|
+
"version": "1.0.0-canary.3",
|
|
4
4
|
"description": "Core framework and plugin APIs for Mate.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -10,12 +10,17 @@
|
|
|
10
10
|
},
|
|
11
11
|
"files": [
|
|
12
12
|
"src/",
|
|
13
|
+
"studio-dist/",
|
|
13
14
|
"wrappers/",
|
|
14
15
|
"claude-plugin/",
|
|
15
16
|
"opencode-plugin/",
|
|
17
|
+
"claude-capability-plugins/",
|
|
16
18
|
"!src/**/*.test.ts",
|
|
17
19
|
"!src/**/*.test.tsx",
|
|
18
|
-
"!opencode-plugin/**/*.test.ts"
|
|
20
|
+
"!opencode-plugin/**/*.test.ts",
|
|
21
|
+
"!claude-capability-plugins/*/tests/",
|
|
22
|
+
"!claude-capability-plugins/*/tsconfig.json",
|
|
23
|
+
"!claude-capability-plugins/*/.claude-plugin/types/"
|
|
19
24
|
],
|
|
20
25
|
"type": "module",
|
|
21
26
|
"exports": {
|
|
@@ -25,53 +30,77 @@
|
|
|
25
30
|
"./opencode": "./src/opencode/index.ts",
|
|
26
31
|
"./opencode/tui": "./src/opencode/tui.tsx",
|
|
27
32
|
"./tui": "./src/tui.ts",
|
|
28
|
-
"./brand": "./src/brand/index.ts"
|
|
33
|
+
"./brand": "./src/brand/index.ts",
|
|
34
|
+
"./studio": "./src/studio.ts"
|
|
29
35
|
},
|
|
30
36
|
"publishConfig": {
|
|
31
37
|
"access": "public",
|
|
32
38
|
"registry": "https://registry.npmjs.org/"
|
|
33
39
|
},
|
|
34
40
|
"scripts": {
|
|
35
|
-
"
|
|
36
|
-
"test
|
|
41
|
+
"prepack": "bun ../../scripts/studio-app/pack.ts",
|
|
42
|
+
"test": "CI=1 bun ../../test/run-isolated.ts --path-ignore-patterns='claude-capability-plugins/*/tests/{autocomplete,companion-root,mention}.test.ts'",
|
|
43
|
+
"test:unit": "CI=1 bun ../../test/run-isolated.ts --suite=unit --path-ignore-patterns='claude-capability-plugins/*/tests/{autocomplete,companion-root,mention}.test.ts'",
|
|
44
|
+
"test:hooks": "claude plugin validate --strict claude-capability-plugins/companion-mentions && claude plugin test claude-capability-plugins/companion-mentions",
|
|
37
45
|
"test:integration": "CI=1 bun ../../test/run-isolated.ts --suite=integration",
|
|
38
46
|
"typecheck": "bunx tsc --noEmit -p ../../tsconfig.json",
|
|
39
|
-
"lint": "oxlint src/ opencode-plugin/",
|
|
40
|
-
"lint:fix": "oxlint src/ opencode-plugin/ --fix",
|
|
41
|
-
"format": "oxfmt src/ opencode-plugin/ \"!**/*.generated.*\"",
|
|
42
|
-
"format:check": "oxfmt src/ opencode-plugin/ \"!**/*.generated.*\" --check"
|
|
47
|
+
"lint": "oxlint src/ opencode-plugin/ claude-capability-plugins/*/hooks/",
|
|
48
|
+
"lint:fix": "oxlint src/ opencode-plugin/ claude-capability-plugins/*/hooks/ --fix",
|
|
49
|
+
"format": "oxfmt src/ opencode-plugin/ claude-capability-plugins/ \"!**/*.generated.*\"",
|
|
50
|
+
"format:check": "oxfmt src/ opencode-plugin/ claude-capability-plugins/ \"!**/*.generated.*\" --check"
|
|
43
51
|
},
|
|
44
52
|
"dependencies": {
|
|
53
|
+
"@ai-sdk/harness": "1.0.167",
|
|
54
|
+
"@ai-sdk/harness-claude-code": "1.0.171",
|
|
45
55
|
"@fission-ai/openspec": "1.15.0",
|
|
46
56
|
"@opencode/plugin": "^2.0.23",
|
|
47
|
-
"@opentui/core": "^0.5.14",
|
|
48
|
-
"@opentui/keymap": "^0.5.14",
|
|
49
|
-
"@opentui/solid": "^0.5.14",
|
|
50
57
|
"@secretlint/core": "13.0.7",
|
|
51
58
|
"@secretlint/secretlint-rule-preset-recommend": "13.0.7",
|
|
52
59
|
"@secretlint/types": "13.0.7",
|
|
53
60
|
"@tanstack/highlight": "0.0.10",
|
|
61
|
+
"@wterm/core": "0.5.7",
|
|
54
62
|
"@xterm/addon-clipboard": "^0.2.0",
|
|
55
63
|
"@xterm/addon-fit": "^0.11.0",
|
|
56
64
|
"@xterm/addon-unicode11": "^0.9.0",
|
|
57
65
|
"@xterm/addon-web-links": "^0.12.0",
|
|
58
66
|
"@xterm/xterm": "^6.0.0",
|
|
59
|
-
"
|
|
67
|
+
"ai": "7.0.156",
|
|
60
68
|
"ink": "^7.1.0",
|
|
69
|
+
"jsonc-parser": "^3.3.1",
|
|
61
70
|
"marked": "^18.1.1",
|
|
62
71
|
"react": "^19.2.7",
|
|
63
72
|
"react-doctor": "0.9.13",
|
|
64
73
|
"semver": "^7.8.5",
|
|
65
|
-
"yaml": "^2.9.0"
|
|
74
|
+
"yaml": "^2.9.0",
|
|
75
|
+
"zod": "4.6.7"
|
|
66
76
|
},
|
|
67
77
|
"devDependencies": {
|
|
78
|
+
"@opentui/core": "^0.5.14",
|
|
79
|
+
"@opentui/keymap": "^0.5.14",
|
|
80
|
+
"@opentui/solid": "^0.5.14",
|
|
68
81
|
"@types/bun": "^1.3.14",
|
|
69
82
|
"@types/node": "^26.0.1",
|
|
70
83
|
"@types/react": "^19.2.17",
|
|
71
84
|
"@types/semver": "^7.7.1"
|
|
72
85
|
},
|
|
86
|
+
"peerDependencies": {
|
|
87
|
+
"@opentui/core": ">=0.5.14",
|
|
88
|
+
"@opentui/keymap": ">=0.5.14",
|
|
89
|
+
"@opentui/solid": ">=0.5.14"
|
|
90
|
+
},
|
|
91
|
+
"peerDependenciesMeta": {
|
|
92
|
+
"@opentui/core": {
|
|
93
|
+
"optional": true
|
|
94
|
+
},
|
|
95
|
+
"@opentui/keymap": {
|
|
96
|
+
"optional": true
|
|
97
|
+
},
|
|
98
|
+
"@opentui/solid": {
|
|
99
|
+
"optional": true
|
|
100
|
+
}
|
|
101
|
+
},
|
|
73
102
|
"engines": {
|
|
74
|
-
"node": ">=
|
|
103
|
+
"node": ">=22.19.0"
|
|
75
104
|
},
|
|
76
|
-
"packageManager": "bun@1.
|
|
105
|
+
"packageManager": "bun@1.4.4"
|
|
77
106
|
}
|
package/src/brand/terminal.ts
CHANGED
|
@@ -63,6 +63,11 @@ function hexToRgb(hex: string): string {
|
|
|
63
63
|
const NOTE_ON = `\x1b[38;2;${hexToRgb(BRAND_COLORS.mateGreen.hex)}m`;
|
|
64
64
|
const NOTE_OFF = "\x1b[39m";
|
|
65
65
|
|
|
66
|
+
/** `text` in the brand accent; callers check {@link colorEnabled} first. */
|
|
67
|
+
export function accentText(text: string): string {
|
|
68
|
+
return `${NOTE_ON}${text}${NOTE_OFF}`;
|
|
69
|
+
}
|
|
70
|
+
|
|
66
71
|
/** Renders the logo as a string ready to write to a stream, rows separated by newlines. */
|
|
67
72
|
export function renderLogo(options: LogoOptions): string {
|
|
68
73
|
const choice = chooseLogo(options);
|