@uniqbit/mate-core 0.20.0 → 0.21.1
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/plugin.json +1 -1
- package/claude-capability-plugins/companion-mentions/hooks/register.ts +1 -1
- package/claude-plugin/hooks/hooks.json +10 -1
- package/claude-plugin/hooks/rtk-worktree-git.mjs +58 -0
- package/opencode-plugin/src/server.ts +9 -2
- package/package.json +2 -1
- package/src/cli/commands/artifact/delivery/environment.ts +28 -8
- package/src/cli/commands/artifact/delivery/link.ts +28 -9
- package/src/cli/commands/artifact/delivery/output.ts +7 -0
- package/src/cli/commands/companion/update.ts +2 -19
- package/src/cli/commands/factory/factory.ts +11 -1
- package/src/cli/commands/install.ts +47 -36
- package/src/cli/commands/launch/claude.ts +2 -0
- package/src/cli/commands/launch/shared.ts +33 -6
- package/src/cli/commands/plugin/install.ts +27 -11
- package/src/cli/commands/report/index.ts +180 -184
- package/src/cli/commands/report/markdown.ts +67 -72
- package/src/cli/commands/shared/companion-selection.ts +3 -1
- package/src/cli/commands/studio/access.ts +6 -14
- package/src/cli/commands/studio/areas.ts +112 -33
- package/src/cli/commands/studio/companion-add.ts +87 -0
- package/src/cli/commands/studio/companion-removal.ts +15 -8
- package/src/cli/commands/studio/factory-credential.ts +1 -15
- package/src/cli/commands/studio/factory-git-tokens.ts +40 -0
- package/src/cli/commands/studio/factory-relay.ts +18 -0
- package/src/cli/commands/studio/graph-model.ts +61 -0
- package/src/cli/commands/studio/graph.ts +336 -0
- package/src/cli/commands/studio/index.ts +4 -4
- package/src/cli/commands/studio/payload.ts +42 -15
- package/src/cli/commands/studio/repository-add.ts +116 -0
- package/src/cli/commands/studio/routes.ts +6 -0
- package/src/cli/commands/studio/selection.ts +12 -3
- package/src/cli/commands/studio/server.ts +127 -5
- package/src/cli/commands/studio/services.ts +40 -0
- package/src/cli/commands/studio/terminal.ts +45 -3
- package/src/cli/commands/studio/views/vault/markdown-tree.ts +84 -3
- package/src/cli/commands/studio/workset-session.ts +47 -14
- package/src/cli/commands/unwrap.ts +3 -0
- package/src/cli/commands/update.ts +2 -0
- package/src/cli/commands/vscode/release-vsix.json +4 -0
- package/src/cli/commands/vscode/setup.ts +71 -13
- package/src/cli/commands/vscode/vsix.ts +48 -7
- package/src/cli/commands/working/cleanup.ts +40 -8
- package/src/cli/commands/working/worktree.ts +176 -35
- package/src/cli/main.ts +17 -2
- package/src/cli/usage.ts +1 -1
- package/src/hooks/rtk-worktree-git.ts +48 -0
- package/src/hooks/validate-artifact-path.ts +38 -7
- package/src/lib/delivery/branch-template.ts +122 -0
- package/src/lib/delivery/branches.ts +21 -16
- package/src/lib/delivery/checkout.ts +102 -0
- package/src/lib/delivery/environment.ts +2 -0
- package/src/lib/delivery/merge-git.ts +13 -1
- package/src/lib/delivery/record-delivery.ts +83 -29
- package/src/lib/delivery/record.ts +15 -3
- package/src/lib/delivery/resolve-branch.ts +157 -110
- package/src/lib/factory/attach-client.ts +11 -1
- package/src/lib/factory/broker.ts +37 -40
- package/src/lib/factory/client.ts +22 -1
- package/src/lib/factory/clone-url.ts +39 -0
- package/src/lib/factory/command.ts +21 -5
- package/src/lib/factory/git-auth.ts +61 -0
- package/src/lib/factory/git-credential-store.ts +181 -0
- package/src/lib/factory/ids.ts +12 -2
- package/src/lib/factory/outcomes/actions.ts +20 -4
- package/src/lib/factory/outcomes/index.ts +77 -11
- package/src/lib/factory/outcomes/lifecycle.ts +9 -2
- package/src/lib/factory/outcomes/sessions.ts +23 -1
- package/src/lib/factory/prepare.ts +9 -3
- package/src/lib/factory/runner/scheduler.ts +96 -14
- package/src/lib/factory/runner/workflow.ts +5 -1
- package/src/lib/factory/runtime.ts +143 -43
- package/src/lib/orchestrator/companion-hub.ts +6 -1
- package/src/lib/orchestrator/engine-floor.ts +48 -0
- package/src/lib/orchestrator/launcher.ts +34 -1
- package/src/lib/orchestrator/projection-claude-commands.ts +2 -2
- package/src/lib/orchestrator/projection-claude-entry.ts +42 -21
- package/src/lib/orchestrator/projection-claude-links.ts +32 -8
- package/src/lib/orchestrator/projection-claude-skills.ts +2 -2
- package/src/lib/orchestrator/projection-entries.ts +22 -18
- package/src/lib/orchestrator/projection-opencode-copies.ts +65 -21
- package/src/lib/orchestrator/projection-runtime-documents.ts +66 -43
- package/src/lib/orchestrator/projection-types.ts +28 -1
- package/src/lib/orchestrator/refresh-working-claude-links.ts +3 -1
- package/src/lib/orchestrator/session-prepare.ts +6 -1
- package/src/lib/orchestrator/setup-compatibilities.ts +1 -1
- package/src/lib/orchestrator/types.ts +4 -0
- package/src/lib/orchestrator/umbrella-checkouts.ts +102 -0
- package/src/lib/orchestrator/working-repo-projection.ts +24 -4
- package/src/lib/orchestrator/wrap-pass.ts +1 -0
- package/src/lib/public-npm.ts +95 -50
- package/src/lib/session-state.ts +72 -2
- package/src/lib/update-checker.ts +7 -1
- package/src/lib/usage/aggregate.ts +202 -0
- package/src/lib/usage/cache.ts +87 -0
- package/src/lib/usage/claude-pricing.ts +71 -0
- package/src/lib/usage/claude.ts +189 -0
- package/src/lib/usage/collect.ts +56 -0
- package/src/lib/usage/opencode.ts +188 -0
- package/src/lib/usage/records.ts +80 -0
- package/src/lib/usage/rtk-database.ts +72 -0
- package/src/lib/usage/savings.ts +209 -0
- package/src/lib/usage/scope.ts +182 -0
- package/src/lib/usage/source.ts +102 -0
- package/src/lib/usage/types.ts +143 -0
- package/src/lib/usage/window.ts +37 -0
- package/src/lib/workset/factory-local.ts +157 -0
- package/src/lib/workset/record.ts +25 -11
- package/src/lib/workset/repositories.ts +118 -25
- package/src/lib/workset/worktree-include.ts +161 -0
- package/src/lib/workset/worktree-index.ts +6 -2
- package/src/lib/workset/worktree.ts +591 -101
- package/src/opencode/companion-hooks.ts +46 -8
- package/src/opencode/companion-policy.ts +18 -5
- package/src/opencode/enter-worktree.ts +254 -6
- package/src/opencode/session-register.ts +2 -2
- package/src/runtime/claude-bg-isolation.ts +138 -0
- package/src/runtime/companion-git.ts +10 -2
- package/src/runtime/companion-guidance.ts +17 -4
- package/src/runtime/current-branch.ts +16 -2
- package/src/runtime/entered-worktree.ts +24 -0
- package/src/runtime/git-tracked.ts +60 -0
- package/src/runtime/repo-destination.ts +72 -0
- package/src/runtime/repo-local.ts +25 -3
- package/src/runtime/rtk-git-guard.ts +66 -0
- package/src/runtime/runtime-document-manifest.ts +229 -19
- package/src/runtime/runtime-document-manifest.typecheck.ts +10 -0
- package/src/runtime/secret-guard.ts +9 -2
- package/src/runtime/secret-policy-weakening.ts +122 -0
- package/src/runtime/serving-claude-wrap.ts +15 -2
- package/src/runtime/umbrella-folder.ts +56 -0
- package/src/runtime/wrap-state.ts +5 -13
- package/src/studio.ts +37 -0
- package/src/templates/mate-skills/agents/mate-apply-change/SKILL.md +61 -6
- package/src/templates/mate-skills/agents/mate-explore-change/SKILL.md +8 -4
- package/src/templates/mate-skills/agents/mate-propose-change/SKILL.md +9 -5
- package/src/templates/mate-skills/agents/mate-publish-artifact/SKILL.md +5 -4
- package/src/templates/mate-skills/agents/mate-show-me/SKILL.md +10 -4
- package/src/templates/mate-skills/agents/mate-simplify-code/SKILL.md +5 -1
- package/src/templates/mate-skills/claude/mate-apply-change/SKILL.md +61 -6
- package/src/templates/mate-skills/claude/mate-explore-change/SKILL.md +8 -4
- package/src/templates/mate-skills/claude/mate-propose-change/SKILL.md +9 -5
- package/src/templates/mate-skills/claude/mate-publish-artifact/SKILL.md +5 -4
- package/src/templates/mate-skills/claude/mate-show-me/SKILL.md +10 -4
- package/src/templates/mate-skills/claude/mate-simplify-code/SKILL.md +5 -1
- package/src/tools/setup/__snapshots__/runtime-surface-golden.test.ts.snap +307 -42
- package/src/tools/setup/capabilities/rtk.ts +93 -1
- package/src/tools/setup/dynamic-plugins/audiences.ts +65 -21
- package/src/tools/setup/dynamic-plugins/frozen.ts +32 -13
- package/src/tools/setup/dynamic-plugins/hydrate.ts +4 -4
- package/src/tools/setup/dynamic-plugins/install.ts +24 -22
- package/src/tools/setup/dynamic-plugins/loader.ts +11 -7
- package/src/tools/setup/dynamic-plugins/paths.ts +30 -10
- package/src/tools/setup/dynamic-plugins/verify.ts +10 -7
- package/src/tools/setup/dynamic-plugins/workspaces.ts +153 -0
- package/src/tools/setup/mate.ts +3 -3
- package/src/tools/setup/plugins/gitignore.ts +15 -9
- package/src/tools/setup/providers/claude-plugin-hooks.ts +12 -0
- package/src/tools/setup/providers/claude.ts +25 -3
- package/src/tools/setup/utils.ts +4 -2
- package/src/tools/setup/working-repo-cleanup.ts +2 -2
- package/src/tools/setup/working-repo-local-state.ts +2 -0
- package/src/tools/setup.ts +25 -14
- package/studio-dist/client/assets/app-D9cw6szy.css +2 -0
- package/studio-dist/client/assets/artifacts-WD2ZXYrx.js +1 -0
- package/studio-dist/client/assets/button-Br0O1sXw.js +1 -0
- package/studio-dist/client/assets/combobox-DA7RAUUZ.js +1 -0
- package/studio-dist/client/assets/companion-view-CrabvxS8.js +1 -0
- package/studio-dist/client/assets/factory-DGS0E16C.js +6 -0
- package/studio-dist/client/assets/fields-6aXBpFhJ.js +1 -0
- package/studio-dist/client/assets/getting-started-Clde4w6P.js +1 -0
- package/studio-dist/client/assets/getting-started-D6kgWwWZ.js +1 -0
- package/studio-dist/client/assets/getting-started._topic-BiunccbT.js +1 -0
- package/studio-dist/client/assets/getting-started.index-DpiNoGw8.js +1 -0
- package/studio-dist/client/assets/graph-B_TCBVbu.js +2 -0
- package/studio-dist/client/assets/graph-canvas-Ba37Y5AE.js +3242 -0
- package/studio-dist/client/assets/guides-Du_RtJxP.js +1 -0
- package/studio-dist/client/assets/index-Df8L1LQa.js +40 -0
- package/studio-dist/client/assets/jsx-runtime-MZURdZre.js +1 -0
- package/studio-dist/client/assets/markdown-view-BOX6x0rL.js +1 -0
- package/studio-dist/client/assets/panel-dbmCx7Mx.js +1 -0
- package/studio-dist/client/assets/queries-RvHeXY12.js +1 -0
- package/studio-dist/client/assets/react-3QStrcDO.js +27 -0
- package/studio-dist/client/assets/report-url-XRL0x1SY.js +1 -0
- package/studio-dist/client/assets/reports-r3IK7Doz.js +1 -0
- package/studio-dist/client/assets/routes-C0A5LTFc.js +1 -0
- package/studio-dist/client/assets/select-CnaMd617.js +1 -0
- package/studio-dist/client/assets/skills-CzjzHpBT.js +1 -0
- package/studio-dist/client/assets/specs-B0ldF_6J.js +1 -0
- package/studio-dist/client/assets/specs-view-BnCLA0gW.js +1 -0
- package/studio-dist/client/assets/spinner-Dcm3fqK1.js +1 -0
- package/studio-dist/client/assets/steps-C0p2N1Pb.js +1 -0
- package/studio-dist/client/assets/store-Dw34catY.js +1 -0
- package/studio-dist/client/assets/studio-Cpz_HRHp.js +100 -0
- package/studio-dist/client/assets/studio-queries-ibmpFo6R.js +2 -0
- package/studio-dist/client/assets/usage-C2QJ_0IZ.js +55 -0
- package/studio-dist/client/assets/useAnchoredPopupScrollLock-Bj-FWb8z.js +1 -0
- package/studio-dist/client/assets/useMutation-aAr2uiay.js +1 -0
- package/studio-dist/client/assets/useSelector-AYcH7lB0.js +2 -0
- package/studio-dist/client/assets/vault-BGcxkSIY.js +1 -0
- package/studio-dist/client/assets/warnings-R1cE1rLf.js +1 -0
- package/studio-dist/client/assets/workflow-C2qTrMDH.js +1 -0
- package/studio-dist/server/assets/__23tanstack-start-server-fn-resolver-Bn896ZYj.js +122 -0
- package/studio-dist/server/assets/_tanstack-start-manifest_v.js +102 -35
- package/studio-dist/server/assets/{actions-Bvgj9eb8.js → actions-DYSv-9VV.js} +10 -4
- package/studio-dist/server/assets/artifacts-DnF9L3dZ.js +216 -0
- package/studio-dist/server/assets/{button-CIJqAhni.js → button-CgOIVdmD.js} +13 -1702
- package/studio-dist/server/assets/combobox-DV_s9W0s.js +483 -0
- package/studio-dist/server/assets/{companion-view-DISASvdJ.js → companion-view-BKVXD3TO.js} +3 -3
- package/studio-dist/server/assets/companions-C7fctnU9.js +31 -0
- package/studio-dist/server/assets/{createServerRpc-tK2lE9R2.js → createServerRpc-bFKFpGFG.js} +1 -1
- package/studio-dist/server/assets/{factory-DUTa0eDs.js → factory-C7Ybg0xG.js} +1256 -353
- package/studio-dist/server/assets/{factory-DGPmNGbo.js → factory-Df5uAHjb.js} +53 -6
- package/studio-dist/server/assets/fields-BbieQTD0.js +1190 -0
- package/studio-dist/server/assets/getting-started-B136TP57.js +4 -0
- package/studio-dist/server/assets/getting-started-CRxMWorQ.js +67 -0
- package/studio-dist/server/assets/getting-started._topic-DJKQAzYl.js +13 -0
- package/studio-dist/server/assets/getting-started.index-D84gec1t.js +13 -0
- package/studio-dist/server/assets/graph-CSje3029.js +801 -0
- package/studio-dist/server/assets/graph-DDZzXM1L.js +16 -0
- package/studio-dist/server/assets/graph-canvas-22bWB5-2.js +21066 -0
- package/studio-dist/server/assets/graph-wire-BdSUx0G5.js +58 -0
- package/studio-dist/server/assets/guides-D9dk1Frq.js +13 -0
- package/studio-dist/server/assets/guides-IE-19POz.js +5 -0
- package/studio-dist/server/assets/guides.server-vcYRY5wx.js +66 -0
- package/studio-dist/server/assets/jsx-runtime-Bt0s0YKS.js +451 -0
- package/studio-dist/server/assets/{markdown-view-Bn7xPdks.js → markdown-view-BR8dJ7aR.js} +28 -9
- package/studio-dist/server/assets/{panel-3Jmn4awF.js → panel-BR_t9iMM.js} +4 -4
- package/studio-dist/server/assets/queries-DWoTin-q.js +32 -0
- package/studio-dist/server/assets/react-CdqSUhaL.js +89 -0
- package/studio-dist/server/assets/redirect-BaZ_QyqF.js +39 -0
- package/studio-dist/server/assets/report-url-BUXPcE_8.js +9 -0
- package/studio-dist/server/assets/{reports-D6YMqhnO.js → reports-CQ9qQ1-n.js} +9 -10
- package/studio-dist/server/assets/{reports-C06RXVE2.js → reports-dYDEoBeq.js} +3 -3
- package/studio-dist/server/assets/{router-C8MGqlAY.js → router-DkRHNTpE.js} +787 -2862
- package/studio-dist/server/assets/{routes-BcFgvqf7.js → routes-B6GfOew4.js} +22 -171
- package/studio-dist/server/assets/{search-JAKurDNh.js → search-BJnWLfkG.js} +21 -2
- package/studio-dist/server/assets/select-Af7Wibii.js +1609 -0
- package/studio-dist/server/assets/{shell-DS3wUexh.js → shell-Hq-hXgnT.js} +6 -5
- package/studio-dist/server/assets/{skills-BEnOxiDl.js → skills-B7nEuVbx.js} +9 -8
- package/studio-dist/server/assets/{skills-CtrBAtX3.js → skills-B_YYL7q8.js} +3 -3
- package/studio-dist/server/assets/specs-BpLUFntA.js +51 -0
- package/studio-dist/server/assets/specs-view-0peMVd22.js +426 -0
- package/studio-dist/server/assets/spinner-CdwJW4VB.js +20 -0
- package/studio-dist/server/assets/{steps-Dq_CwY_s.js → steps-D56DApvK.js} +1 -1
- package/studio-dist/server/assets/store-Cs17okNG.js +280 -0
- package/studio-dist/server/assets/studio-CAcKp3bM.js +10340 -0
- package/studio-dist/server/assets/studio-queries-BtRGzDdh.js +1451 -0
- package/studio-dist/server/assets/usage-COdjd1gD.js +25570 -0
- package/studio-dist/server/assets/usage-f6pqE1tm.js +24 -0
- package/studio-dist/server/assets/useAnchoredPopupScrollLock-DlBKHRw7.js +756 -0
- package/studio-dist/server/assets/useMutation-DzTZGenE.js +690 -0
- package/studio-dist/server/assets/{__23tanstack-start-server-fn-resolver-M2GBs8s3.js → useSelector-DUmCUXAs.js} +4 -668
- package/studio-dist/server/assets/{vault-Fvxt2Tzl.js → vault-BDuIUq0F.js} +8 -5
- package/studio-dist/server/assets/{vault-BmWnryh3.js → vault-BVLp6zu3.js} +3 -3
- package/studio-dist/server/assets/{views-BgYa-za2.js → views-flRUr21z.js} +4 -4
- package/studio-dist/server/assets/{warnings-DzR6fyZh.js → warnings-CDy9pdgL.js} +3 -2
- package/studio-dist/server/assets/{delivery-path-C29fBynY.js → workflow-D9GKI2EV.js} +132 -106
- package/studio-dist/server/server.js +582 -8
- package/src/cli/commands/report/collector.ts +0 -288
- package/studio-dist/client/assets/app-CdPiFv59.css +0 -2
- package/studio-dist/client/assets/button-BIIHE0EQ.js +0 -3
- package/studio-dist/client/assets/companion-view-DM6YyXaR.js +0 -1
- package/studio-dist/client/assets/delivery-path-DELxj0Av.js +0 -1
- package/studio-dist/client/assets/factory-BZy0E8ty.js +0 -4
- package/studio-dist/client/assets/index-B3wkMzjA.js +0 -40
- package/studio-dist/client/assets/markdown-view-pQ2Qp_i5.js +0 -1
- package/studio-dist/client/assets/panel-CbajlC3p.js +0 -1
- package/studio-dist/client/assets/prepaint-CwSrpdFA.js +0 -27
- package/studio-dist/client/assets/react-CN2GSx7x.js +0 -1
- package/studio-dist/client/assets/reports-DllhYQ5_.js +0 -1
- package/studio-dist/client/assets/rolldown-runtime-WkwZ5CU-.js +0 -1
- package/studio-dist/client/assets/routes-COm-G3mK.js +0 -1
- package/studio-dist/client/assets/skills-DmWAy-jZ.js +0 -1
- package/studio-dist/client/assets/specs-BG3Wi3ln.js +0 -1
- package/studio-dist/client/assets/steps-DFsH3Neu.js +0 -1
- package/studio-dist/client/assets/vault-B2q1nBY5.js +0 -1
- package/studio-dist/client/assets/warnings-BSXIyuSQ.js +0 -1
- package/studio-dist/client/assets/workflow-DlsQD6Hc.js +0 -1
- package/studio-dist/server/assets/companions-BYbHWKOZ.js +0 -15
- package/studio-dist/server/assets/createServerFn-F5sAOF8V.js +0 -459
- package/studio-dist/server/assets/prepaint-DJfTQ_VH.js +0 -45
- package/studio-dist/server/assets/react-Ce6dj15C.js +0 -46
- package/studio-dist/server/assets/rolldown-runtime-DYf_mQCB.js +0 -34
- package/studio-dist/server/assets/specs-C8rv34-5.js +0 -211
- package/studio-dist/server/assets/studio-BeltxxKt.js +0 -216
- package/studio-dist/server/assets/workflow-liRYecHk.js +0 -73
|
@@ -11,9 +11,17 @@ import {
|
|
|
11
11
|
type ClaudeSettings,
|
|
12
12
|
} from "../../tools/setup/providers/claude-format";
|
|
13
13
|
import { isMateGuardHookGroup } from "../../tools/setup/providers/claude-plugin-hooks";
|
|
14
|
+
import { repoDestination } from "../../runtime/repo-destination";
|
|
15
|
+
import { CLAUDE_SETTINGS_DOCUMENT } from "../../runtime/runtime-document-manifest";
|
|
14
16
|
import { readWrapState, type WrapState } from "../../runtime/wrap-state";
|
|
17
|
+
import { writeAtomic } from "../../runtime/write-atomic";
|
|
15
18
|
import { pruneEmptyAncestors } from "../../tools/setup/utils";
|
|
16
19
|
import { GlobalConfigStore } from "./global-config-store";
|
|
20
|
+
import {
|
|
21
|
+
removalWithWarnings,
|
|
22
|
+
type ProjectionRemovalReport,
|
|
23
|
+
type ProjectionWriteReport,
|
|
24
|
+
} from "./projection-types";
|
|
17
25
|
|
|
18
26
|
/**
|
|
19
27
|
* The working-repo half of the Claude Runtime Surface, as one Managed Projection
|
|
@@ -25,12 +33,19 @@ import { GlobalConfigStore } from "./global-config-store";
|
|
|
25
33
|
export const CLAUDE_WORKING_SETTINGS_PATH = path.join(".claude", "settings.local.json");
|
|
26
34
|
export const LEGACY_TOKENSAVE_CLAUDE_MD_PATH = "CLAUDE.md";
|
|
27
35
|
|
|
28
|
-
|
|
29
|
-
|
|
36
|
+
/** Inside the repository with no symlinked `.claude`, or the warning that refuses it. */
|
|
37
|
+
function settingsPath(repoPath: string): { path: string; root: string } | { warning: string } {
|
|
38
|
+
return repoDestination(repoPath, CLAUDE_SETTINGS_DOCUMENT);
|
|
30
39
|
}
|
|
31
40
|
|
|
32
|
-
|
|
33
|
-
|
|
41
|
+
/** A symlinked `CLAUDE.md` is another file's, the user's global one included: read as absent. */
|
|
42
|
+
async function readClaudeMd(repoPath: string): Promise<{ path: string; content: string } | null> {
|
|
43
|
+
const destination = repoDestination(repoPath, LEGACY_TOKENSAVE_CLAUDE_MD_PATH);
|
|
44
|
+
if ("warning" in destination) return null;
|
|
45
|
+
const stat = await fs.lstat(destination.path).catch(() => null);
|
|
46
|
+
if (!stat?.isFile()) return null;
|
|
47
|
+
const content = await readRaw(destination.path);
|
|
48
|
+
return content === null ? null : { path: destination.path, content };
|
|
34
49
|
}
|
|
35
50
|
|
|
36
51
|
async function readRaw(filePath: string): Promise<string | null> {
|
|
@@ -86,8 +101,10 @@ export async function syncWorkingRepoClaudeAdditionalDirectories(
|
|
|
86
101
|
repoPath: string,
|
|
87
102
|
companionPath: string,
|
|
88
103
|
globalConfigStore: GlobalConfigStore = new GlobalConfigStore(),
|
|
89
|
-
): Promise<"written" | "current"> {
|
|
90
|
-
const
|
|
104
|
+
): Promise<"written" | "current" | ProjectionWriteReport> {
|
|
105
|
+
const destination = settingsPath(repoPath);
|
|
106
|
+
if ("warning" in destination) return { state: "skipped", warnings: [destination.warning] };
|
|
107
|
+
const target = destination.path;
|
|
91
108
|
const raw = await readRaw(target);
|
|
92
109
|
const existing = withoutForeignManagedHookGroups(
|
|
93
110
|
parseSettings(raw),
|
|
@@ -125,7 +142,8 @@ export async function syncWorkingRepoClaudeAdditionalDirectories(
|
|
|
125
142
|
if (next === raw) return "current";
|
|
126
143
|
|
|
127
144
|
await fs.mkdir(path.dirname(target), { recursive: true });
|
|
128
|
-
|
|
145
|
+
/** A rename replaces a symlinked leaf instead of writing through it. */
|
|
146
|
+
await writeAtomic(target, next);
|
|
129
147
|
return "written";
|
|
130
148
|
}
|
|
131
149
|
|
|
@@ -137,8 +155,10 @@ export async function syncWorkingRepoClaudeAdditionalDirectories(
|
|
|
137
155
|
export async function removeWorkingRepoClaudeSettings(
|
|
138
156
|
repoPath: string,
|
|
139
157
|
registeredCompanionPaths: string[] = [],
|
|
140
|
-
): Promise<"removed" | "absent"> {
|
|
141
|
-
const
|
|
158
|
+
): Promise<"removed" | "absent" | ProjectionRemovalReport> {
|
|
159
|
+
const destination = settingsPath(repoPath);
|
|
160
|
+
if ("warning" in destination) return removalWithWarnings("absent", [destination.warning]);
|
|
161
|
+
const target = destination.path;
|
|
142
162
|
const raw = await readRaw(target);
|
|
143
163
|
if (raw === null) return "absent";
|
|
144
164
|
|
|
@@ -168,16 +188,18 @@ export async function removeWorkingRepoClaudeSettings(
|
|
|
168
188
|
if (JSON.stringify(settings) === JSON.stringify(existing)) return "absent";
|
|
169
189
|
if (Object.keys(settings).length === 0) {
|
|
170
190
|
await fs.unlink(target);
|
|
171
|
-
await pruneEmptyAncestors(path.dirname(target),
|
|
191
|
+
await pruneEmptyAncestors(path.dirname(target), destination.root);
|
|
172
192
|
return "removed";
|
|
173
193
|
}
|
|
174
|
-
await
|
|
194
|
+
await writeAtomic(target, serializeClaudeSettings(settings));
|
|
175
195
|
return "removed";
|
|
176
196
|
}
|
|
177
197
|
|
|
178
198
|
/** Present when Mate's own key is in the document, not merely when it exists. */
|
|
179
199
|
export async function workingRepoClaudeSettingsPresent(repoPath: string): Promise<boolean> {
|
|
180
|
-
const
|
|
200
|
+
const destination = settingsPath(repoPath);
|
|
201
|
+
if ("warning" in destination) return false;
|
|
202
|
+
const settings = parseSettings(await readRaw(destination.path));
|
|
181
203
|
return Array.isArray(settings.permissions?.additionalDirectories);
|
|
182
204
|
}
|
|
183
205
|
|
|
@@ -189,21 +211,20 @@ export async function workingRepoClaudeSettingsPresent(repoPath: string): Promis
|
|
|
189
211
|
export async function stripTokensaveClaudeMdAppend(
|
|
190
212
|
repoPath: string,
|
|
191
213
|
): Promise<"removed" | "absent"> {
|
|
192
|
-
const
|
|
193
|
-
|
|
194
|
-
if (content === null) return "absent";
|
|
214
|
+
const claudeMd = await readClaudeMd(repoPath);
|
|
215
|
+
if (claudeMd === null) return "absent";
|
|
195
216
|
|
|
196
|
-
const stripped = cutFromMarker(content, TOKENSAVE_CLAUDE_MD_MARKER);
|
|
197
|
-
if (stripped === content) return "absent";
|
|
217
|
+
const stripped = cutFromMarker(claudeMd.content, TOKENSAVE_CLAUDE_MD_MARKER);
|
|
218
|
+
if (stripped === claudeMd.content) return "absent";
|
|
198
219
|
if (stripped.length > 0) {
|
|
199
|
-
await
|
|
220
|
+
await writeAtomic(claudeMd.path, stripped);
|
|
200
221
|
} else {
|
|
201
|
-
await fs.unlink(
|
|
222
|
+
await fs.unlink(claudeMd.path);
|
|
202
223
|
}
|
|
203
224
|
return "removed";
|
|
204
225
|
}
|
|
205
226
|
|
|
206
227
|
export async function legacyTokensaveClaudeMdPresent(repoPath: string): Promise<boolean> {
|
|
207
|
-
const
|
|
208
|
-
return
|
|
228
|
+
const claudeMd = await readClaudeMd(repoPath);
|
|
229
|
+
return claudeMd !== null && claudeMd.content.includes(TOKENSAVE_CLAUDE_MD_MARKER);
|
|
209
230
|
}
|
|
@@ -2,6 +2,7 @@ import fs from "node:fs/promises";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
|
|
4
4
|
import { readProjectionFile } from "../../runtime/projection";
|
|
5
|
+
import { repoDirectory } from "../../runtime/repo-destination";
|
|
5
6
|
import { realLinkTarget, realOrResolved } from "../fs-utils";
|
|
6
7
|
import {
|
|
7
8
|
links,
|
|
@@ -11,6 +12,12 @@ import {
|
|
|
11
12
|
type LinkRecord,
|
|
12
13
|
} from "../../runtime/runtime-document-manifest";
|
|
13
14
|
import { pruneEmptyAncestors } from "../../tools/setup/utils";
|
|
15
|
+
import {
|
|
16
|
+
removalWithWarnings,
|
|
17
|
+
type ProjectionRemovalReport,
|
|
18
|
+
type ProjectionWriteReport,
|
|
19
|
+
type ProjectionWriteState,
|
|
20
|
+
} from "./projection-types";
|
|
14
21
|
|
|
15
22
|
/**
|
|
16
23
|
* A `.claude/<dir>` folder whose companion entries Mate links one by one into
|
|
@@ -67,6 +74,14 @@ async function registeredRoots(
|
|
|
67
74
|
return [...new Set(roots)];
|
|
68
75
|
}
|
|
69
76
|
|
|
77
|
+
/** The root's folder inside the repository, or the warning that refuses it. */
|
|
78
|
+
function targetRootOf(
|
|
79
|
+
root: ClaudeLinkRoot,
|
|
80
|
+
repoPath: string,
|
|
81
|
+
): { path: string; root: string } | { warning: string } {
|
|
82
|
+
return repoDirectory(repoPath, `.claude/${root.dir}`);
|
|
83
|
+
}
|
|
84
|
+
|
|
70
85
|
async function createDirectoryLink(target: string, link: string): Promise<void> {
|
|
71
86
|
await fs.symlink(target, link, process.platform === "win32" ? "junction" : "dir");
|
|
72
87
|
}
|
|
@@ -75,7 +90,8 @@ async function createDirectoryLink(target: string, link: string): Promise<void>
|
|
|
75
90
|
* Recorded link: Mate's while it resolves to its recorded target. Unrecorded:
|
|
76
91
|
* adopted only when it resolves into a registered, current or projected
|
|
77
92
|
* companion. Records follow the filesystem, so a partial failure re-adopts.
|
|
78
|
-
* Only this root's records are read and replaced.
|
|
93
|
+
* Only this root's records are read and replaced. A refused folder is not
|
|
94
|
+
* touched at all: nothing in it is read, unlinked, created or pruned.
|
|
79
95
|
*/
|
|
80
96
|
export async function reconcileClaudeLinks(
|
|
81
97
|
root: ClaudeLinkRoot,
|
|
@@ -83,12 +99,14 @@ export async function reconcileClaudeLinks(
|
|
|
83
99
|
companionPath: string | null,
|
|
84
100
|
enabled: boolean,
|
|
85
101
|
registeredCompanionPaths: string[] = [],
|
|
86
|
-
): Promise<
|
|
102
|
+
): Promise<ProjectionWriteState | ProjectionWriteReport> {
|
|
103
|
+
const folder = targetRootOf(root, repoPath);
|
|
104
|
+
if ("warning" in folder) return { state: "skipped", warnings: [folder.warning] };
|
|
105
|
+
const targetRoot = folder.path;
|
|
87
106
|
const scope = { prefix: keyPrefix(root) };
|
|
88
107
|
const recordKey = (name: string): string => `${scope.prefix}${name}`;
|
|
89
108
|
const currentRoot = companionPath ? path.resolve(companionPath, rootPath(root)) : null;
|
|
90
109
|
const roots = await registeredRoots(root, repoPath, companionPath, registeredCompanionPaths);
|
|
91
|
-
const targetRoot = path.join(path.resolve(repoPath), rootPath(root));
|
|
92
110
|
const recorded = links(await readManifest(repoPath), "claude", scope);
|
|
93
111
|
const existing = await fs.readdir(targetRoot, { withFileTypes: true }).catch(() => []);
|
|
94
112
|
const sourceNames: Set<string> =
|
|
@@ -127,7 +145,7 @@ export async function reconcileClaudeLinks(
|
|
|
127
145
|
}
|
|
128
146
|
|
|
129
147
|
if (changed || !enabled) {
|
|
130
|
-
await pruneEmptyAncestors(targetRoot,
|
|
148
|
+
await pruneEmptyAncestors(targetRoot, folder.root);
|
|
131
149
|
}
|
|
132
150
|
if (JSON.stringify(sortedEntries(records)) !== JSON.stringify(sortedEntries(recorded))) {
|
|
133
151
|
await updateManifest(repoPath, (manifest) => withLinks(manifest, "claude", records, scope));
|
|
@@ -162,7 +180,7 @@ export async function carriesClaudeLinks(root: ClaudeLinkRoot, repoPath: string)
|
|
|
162
180
|
/**
|
|
163
181
|
* `root`'s folder in the Working Repository is missing or holds only Mate's
|
|
164
182
|
* links: recorded ones, or ones resolving into a registered, current or
|
|
165
|
-
* projected companion.
|
|
183
|
+
* projected companion. A refused folder is not read and answers `false`.
|
|
166
184
|
*/
|
|
167
185
|
export async function holdsOnlyMateLinks(
|
|
168
186
|
root: ClaudeLinkRoot,
|
|
@@ -170,7 +188,9 @@ export async function holdsOnlyMateLinks(
|
|
|
170
188
|
companionPath: string | null,
|
|
171
189
|
registeredCompanionPaths: string[],
|
|
172
190
|
): Promise<boolean> {
|
|
173
|
-
const
|
|
191
|
+
const folder = targetRootOf(root, repoPath);
|
|
192
|
+
if ("warning" in folder) return false;
|
|
193
|
+
const targetRoot = folder.path;
|
|
174
194
|
const existing = await fs.readdir(targetRoot, { withFileTypes: true }).catch(() => []);
|
|
175
195
|
if (existing.length === 0) return true;
|
|
176
196
|
const roots = await registeredRoots(root, repoPath, companionPath, registeredCompanionPaths);
|
|
@@ -200,7 +220,11 @@ export async function removeClaudeLinks(
|
|
|
200
220
|
root: ClaudeLinkRoot,
|
|
201
221
|
repoPath: string,
|
|
202
222
|
registeredCompanionPaths: string[] = [],
|
|
203
|
-
): Promise<"removed" | "absent"> {
|
|
223
|
+
): Promise<"removed" | "absent" | ProjectionRemovalReport> {
|
|
204
224
|
const result = await reconcileClaudeLinks(root, repoPath, null, false, registeredCompanionPaths);
|
|
205
|
-
|
|
225
|
+
const state = typeof result === "string" ? result : result.state;
|
|
226
|
+
return removalWithWarnings(
|
|
227
|
+
state === "written" ? "removed" : "absent",
|
|
228
|
+
typeof result === "string" ? [] : (result.warnings ?? []),
|
|
229
|
+
);
|
|
206
230
|
}
|
|
@@ -46,7 +46,7 @@ export async function reconcileWorkingRepoClaudeSkillLinks(
|
|
|
46
46
|
companionPath: string | null,
|
|
47
47
|
enabled: boolean,
|
|
48
48
|
registeredCompanionPaths: string[] = [],
|
|
49
|
-
):
|
|
49
|
+
): ReturnType<typeof reconcileClaudeLinks> {
|
|
50
50
|
const placed =
|
|
51
51
|
enabled && !(await servedByMainWorktree(repoPath, companionPath, registeredCompanionPaths));
|
|
52
52
|
return reconcileClaudeLinks(SKILLS, repoPath, companionPath, placed, registeredCompanionPaths);
|
|
@@ -55,6 +55,6 @@ export async function reconcileWorkingRepoClaudeSkillLinks(
|
|
|
55
55
|
export function removeWorkingRepoClaudeSkillLinks(
|
|
56
56
|
repoPath: string,
|
|
57
57
|
registeredCompanionPaths: string[] = [],
|
|
58
|
-
):
|
|
58
|
+
): ReturnType<typeof removeClaudeLinks> {
|
|
59
59
|
return removeClaudeLinks(SKILLS, repoPath, registeredCompanionPaths);
|
|
60
60
|
}
|
|
@@ -14,9 +14,11 @@ import {
|
|
|
14
14
|
repoLocalRegistryPath,
|
|
15
15
|
} from "../../runtime/repo-local";
|
|
16
16
|
import {
|
|
17
|
+
RUNTIME_DOCUMENTS,
|
|
17
18
|
documentRuntime,
|
|
18
19
|
documents as recordedDocuments,
|
|
19
20
|
readManifest,
|
|
21
|
+
type RuntimeDocumentPath,
|
|
20
22
|
} from "../../runtime/runtime-document-manifest";
|
|
21
23
|
import { TOKENSAVE_WORKING_REPO_EXCLUDE_ENTRIES } from "../../tools/setup/capabilities/tokensave-shared";
|
|
22
24
|
import {
|
|
@@ -66,6 +68,7 @@ import {
|
|
|
66
68
|
CLAUDE_MCP_DOCUMENT,
|
|
67
69
|
CLAUDE_SETTINGS_DOCUMENT,
|
|
68
70
|
OPENCODE_CONFIG_DOCUMENT,
|
|
71
|
+
asWrite,
|
|
69
72
|
isExternalDocument,
|
|
70
73
|
placeRuntimeDocument,
|
|
71
74
|
removeRuntimeDocument,
|
|
@@ -78,6 +81,7 @@ import {
|
|
|
78
81
|
} from "./repo-local-store";
|
|
79
82
|
import {
|
|
80
83
|
excludeRemovalReport,
|
|
84
|
+
writeWithWarnings,
|
|
81
85
|
type ProjectionEntry,
|
|
82
86
|
type ProjectionInput,
|
|
83
87
|
type ProjectionWriteReport,
|
|
@@ -120,6 +124,13 @@ async function pathExists(candidatePath: string): Promise<boolean> {
|
|
|
120
124
|
}
|
|
121
125
|
}
|
|
122
126
|
|
|
127
|
+
/** A newly declared runtime document needs an entry id here, or the build fails. */
|
|
128
|
+
const RUNTIME_DOCUMENT_ENTRY_IDS = {
|
|
129
|
+
[CLAUDE_SETTINGS_DOCUMENT]: "claude-runtime-document",
|
|
130
|
+
[CLAUDE_LOCAL_CONFIG_DOCUMENT]: "claude-local-mcp-document",
|
|
131
|
+
[OPENCODE_CONFIG_DOCUMENT]: "opencode-runtime-document",
|
|
132
|
+
} as const satisfies Record<RuntimeDocumentPath, ProjectionEntry["id"]>;
|
|
133
|
+
|
|
123
134
|
/** Present when Mate recorded regions for it, not merely when the file exists. */
|
|
124
135
|
async function runtimeDocumentRecorded(repoPath: string, documentPath: string): Promise<boolean> {
|
|
125
136
|
return recordedDocuments(await readManifest(repoPath)).includes(documentPath);
|
|
@@ -163,21 +174,22 @@ async function writeRuntimeDocumentEntry(
|
|
|
163
174
|
input: ProjectionInput,
|
|
164
175
|
documentPath: string,
|
|
165
176
|
): Promise<ProjectionWriteState | ProjectionWriteReport> {
|
|
166
|
-
const
|
|
177
|
+
const placed = await placeRuntimeDocument(input.repoPath, documentPath, input.runtimeDocuments);
|
|
178
|
+
const state = typeof placed === "string" ? placed : placed.state;
|
|
167
179
|
const rendered = input.runtimeDocuments?.some((document) => document.path === documentPath);
|
|
168
|
-
if (state !== "written" || !rendered || isExternalDocument(documentPath)) return
|
|
180
|
+
if (state !== "written" || !rendered || isExternalDocument(documentPath)) return placed;
|
|
169
181
|
const repositoryId = input.repository?.id ?? path.basename(path.resolve(input.repoPath));
|
|
170
|
-
return
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
182
|
+
return writeWithWarnings(
|
|
183
|
+
placed,
|
|
184
|
+
await trackedDocumentWarnings(input.repoPath, documentPath, repositoryId),
|
|
185
|
+
);
|
|
174
186
|
}
|
|
175
187
|
|
|
176
188
|
/** Links a companion `.claude/` folder's entries when the companion allows Claude. */
|
|
177
189
|
async function writeClaudeLinkEntry(
|
|
178
190
|
input: ProjectionInput,
|
|
179
191
|
reconcile: typeof reconcileWorkingRepoClaudeSkillLinks,
|
|
180
|
-
): Promise<ProjectionWriteState> {
|
|
192
|
+
): Promise<ProjectionWriteState | ProjectionWriteReport> {
|
|
181
193
|
if (!input.config) return "skipped";
|
|
182
194
|
const registeredCompanionPaths = input.globalConfigStore
|
|
183
195
|
? await input.globalConfigStore.list()
|
|
@@ -493,23 +505,15 @@ function buildEntries(): readonly ProjectionEntry[] {
|
|
|
493
505
|
scopes: ["launch", "wrap"],
|
|
494
506
|
runtime: "claude",
|
|
495
507
|
write: async (input) =>
|
|
496
|
-
(await removeRuntimeDocument(input.repoPath, CLAUDE_MCP_DOCUMENT))
|
|
497
|
-
? "written"
|
|
498
|
-
: "current",
|
|
508
|
+
asWrite(await removeRuntimeDocument(input.repoPath, CLAUDE_MCP_DOCUMENT)),
|
|
499
509
|
removal: {
|
|
500
510
|
by: "self",
|
|
501
511
|
remove: (input) => removeRuntimeDocument(input.repoPath, CLAUDE_MCP_DOCUMENT),
|
|
502
512
|
},
|
|
503
513
|
present: (repoPath) => runtimeDocumentRecorded(repoPath, CLAUDE_MCP_DOCUMENT),
|
|
504
514
|
},
|
|
505
|
-
...(
|
|
506
|
-
[
|
|
507
|
-
["claude-runtime-document", CLAUDE_SETTINGS_DOCUMENT],
|
|
508
|
-
["claude-local-mcp-document", CLAUDE_LOCAL_CONFIG_DOCUMENT],
|
|
509
|
-
["opencode-runtime-document", OPENCODE_CONFIG_DOCUMENT],
|
|
510
|
-
] as const
|
|
511
|
-
).map(([id, documentPath]) => ({
|
|
512
|
-
id,
|
|
515
|
+
...RUNTIME_DOCUMENTS.map((documentPath) => ({
|
|
516
|
+
id: RUNTIME_DOCUMENT_ENTRY_IDS[documentPath],
|
|
513
517
|
kind: "merged" as const,
|
|
514
518
|
path: documentPath.split("/").join(path.sep),
|
|
515
519
|
scopes: ["launch", "wrap"] as const,
|
|
@@ -3,8 +3,10 @@ import type { Dirent } from "node:fs";
|
|
|
3
3
|
import fs from "node:fs/promises";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
|
|
6
|
+
import { refusedDestinationWarning, repoDestination } from "../../runtime/repo-destination";
|
|
6
7
|
import {
|
|
7
8
|
copies,
|
|
9
|
+
isPlaceableCopyKey,
|
|
8
10
|
readManifest,
|
|
9
11
|
updateManifest,
|
|
10
12
|
withCopies,
|
|
@@ -15,6 +17,7 @@ import { pruneEmptyAncestors } from "../../tools/setup/utils";
|
|
|
15
17
|
import { reconcileWorkingRepoCopyExcludes } from "../../tools/setup/working-repo-local-state";
|
|
16
18
|
import {
|
|
17
19
|
excludeRemovalReport,
|
|
20
|
+
removalWithWarnings,
|
|
18
21
|
type ProjectionSelfRemoval,
|
|
19
22
|
type ProjectionWriteReport,
|
|
20
23
|
} from "./projection-types";
|
|
@@ -75,8 +78,15 @@ async function companionSources(companionPath: string): Promise<Map<string, Copy
|
|
|
75
78
|
return sources;
|
|
76
79
|
}
|
|
77
80
|
|
|
78
|
-
|
|
79
|
-
|
|
81
|
+
/** Inside the repository with no symlinked parent, or the warning that refuses it. */
|
|
82
|
+
function destination(
|
|
83
|
+
repoPath: string,
|
|
84
|
+
relativePath: string,
|
|
85
|
+
): { path: string; root: string } | { warning: string } {
|
|
86
|
+
if (!isPlaceableCopyKey(relativePath)) {
|
|
87
|
+
return { warning: refusedDestinationWarning(relativePath, "it is not a valid copy path") };
|
|
88
|
+
}
|
|
89
|
+
return repoDestination(repoPath, relativePath);
|
|
80
90
|
}
|
|
81
91
|
|
|
82
92
|
/** `null` when absent; a directory or other non-file reads as a foreign entry. */
|
|
@@ -92,16 +102,21 @@ async function writeCopy(target: string, content: Buffer): Promise<void> {
|
|
|
92
102
|
await writeAtomic(target, content);
|
|
93
103
|
}
|
|
94
104
|
|
|
95
|
-
|
|
105
|
+
/** The refusal warning when the copy may not be touched; it is then left as it is. */
|
|
106
|
+
async function deleteCopy(repoPath: string, relativePath: string): Promise<string | null> {
|
|
96
107
|
const target = destination(repoPath, relativePath);
|
|
97
|
-
|
|
98
|
-
await
|
|
108
|
+
if ("warning" in target) return target.warning;
|
|
109
|
+
await fs.rm(target.path, { force: true });
|
|
110
|
+
await pruneEmptyAncestors(path.dirname(target.path), target.root);
|
|
111
|
+
return null;
|
|
99
112
|
}
|
|
100
113
|
|
|
101
114
|
interface CopyPlan {
|
|
102
|
-
write: Array<{ relativePath: string; source: CopySource; warning?: string }>;
|
|
115
|
+
write: Array<{ relativePath: string; target: string; source: CopySource; warning?: string }>;
|
|
103
116
|
remove: string[];
|
|
104
117
|
shadowed: Array<{ relativePath: string; source: CopySource }>;
|
|
118
|
+
/** Refusal warnings; a refused copy is neither written nor deleted, and its record is dropped. */
|
|
119
|
+
refused: string[];
|
|
105
120
|
records: Record<string, CopyRecord>;
|
|
106
121
|
previous: Record<string, CopyRecord>;
|
|
107
122
|
}
|
|
@@ -109,12 +124,24 @@ interface CopyPlan {
|
|
|
109
124
|
async function planCopies(repoPath: string, companionPath: string): Promise<CopyPlan> {
|
|
110
125
|
const previous = copies(await readManifest(repoPath), "opencode");
|
|
111
126
|
const sources = await companionSources(companionPath);
|
|
112
|
-
const plan: CopyPlan = {
|
|
127
|
+
const plan: CopyPlan = {
|
|
128
|
+
write: [],
|
|
129
|
+
remove: [],
|
|
130
|
+
shadowed: [],
|
|
131
|
+
refused: [],
|
|
132
|
+
records: {},
|
|
133
|
+
previous,
|
|
134
|
+
};
|
|
113
135
|
|
|
114
136
|
for (const [relativePath, source] of sources) {
|
|
115
137
|
const owned = previous[relativePath];
|
|
138
|
+
const target = destination(repoPath, relativePath);
|
|
139
|
+
if ("warning" in target) {
|
|
140
|
+
plan.refused.push(target.warning);
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
116
143
|
// oxlint-disable-next-line no-await-in-loop -- one stat per file
|
|
117
|
-
const current = await readDestination(
|
|
144
|
+
const current = await readDestination(target.path);
|
|
118
145
|
if (current === "foreign" || (!owned && current !== null)) {
|
|
119
146
|
plan.shadowed.push({ relativePath, source });
|
|
120
147
|
continue;
|
|
@@ -126,6 +153,7 @@ async function planCopies(repoPath: string, companionPath: string): Promise<Copy
|
|
|
126
153
|
if (currentSha !== source.sha256 && !keepEdit) {
|
|
127
154
|
plan.write.push({
|
|
128
155
|
relativePath,
|
|
156
|
+
target: target.path,
|
|
129
157
|
source,
|
|
130
158
|
warning: edited
|
|
131
159
|
? `${relativePath} was edited locally; the edit was replaced from the companion. Edit ${source.absolute} instead.`
|
|
@@ -135,7 +163,10 @@ async function planCopies(repoPath: string, companionPath: string): Promise<Copy
|
|
|
135
163
|
plan.records[relativePath] = { runtime: "opencode", sha256: source.sha256 };
|
|
136
164
|
}
|
|
137
165
|
for (const relativePath of Object.keys(previous)) {
|
|
138
|
-
if (
|
|
166
|
+
if (sources.has(relativePath)) continue;
|
|
167
|
+
const target = destination(repoPath, relativePath);
|
|
168
|
+
if ("warning" in target) plan.refused.push(target.warning);
|
|
169
|
+
else plan.remove.push(relativePath);
|
|
139
170
|
}
|
|
140
171
|
return plan;
|
|
141
172
|
}
|
|
@@ -163,9 +194,10 @@ export async function reconcileCompanionCopies(
|
|
|
163
194
|
companionPath: string,
|
|
164
195
|
): Promise<ProjectionWriteReport> {
|
|
165
196
|
const plan = await planCopies(repoPath, companionPath);
|
|
166
|
-
const warnings =
|
|
167
|
-
shadowWarning(relativePath, source),
|
|
168
|
-
|
|
197
|
+
const warnings = [
|
|
198
|
+
...plan.shadowed.map(({ relativePath, source }) => shadowWarning(relativePath, source)),
|
|
199
|
+
...plan.refused,
|
|
200
|
+
];
|
|
169
201
|
|
|
170
202
|
const covering = [...new Set([...Object.keys(plan.previous), ...Object.keys(plan.records)])];
|
|
171
203
|
const excludesWidened = (
|
|
@@ -177,9 +209,9 @@ export async function reconcileCompanionCopies(
|
|
|
177
209
|
await updateManifest(repoPath, (manifest) => withCopies(manifest, "opencode", interim));
|
|
178
210
|
}
|
|
179
211
|
|
|
180
|
-
for (const {
|
|
212
|
+
for (const { target, source, warning } of plan.write) {
|
|
181
213
|
// oxlint-disable-next-line no-await-in-loop -- bounded by the companion folder
|
|
182
|
-
await writeCopy(
|
|
214
|
+
await writeCopy(target, source.content);
|
|
183
215
|
if (warning) warnings.push(warning);
|
|
184
216
|
}
|
|
185
217
|
for (const relativePath of plan.remove) {
|
|
@@ -216,29 +248,41 @@ export async function reconcileCompanionCopies(
|
|
|
216
248
|
* without the line that hides it.
|
|
217
249
|
*/
|
|
218
250
|
async function withdraw(repoPath: string) {
|
|
219
|
-
const
|
|
220
|
-
|
|
251
|
+
const recorded = await recordedCopiesOf(repoPath);
|
|
252
|
+
const owned: string[] = [];
|
|
253
|
+
const warnings: string[] = [];
|
|
254
|
+
for (const relativePath of recorded) {
|
|
221
255
|
// oxlint-disable-next-line no-await-in-loop
|
|
222
|
-
await deleteCopy(repoPath, relativePath);
|
|
256
|
+
const refused = await deleteCopy(repoPath, relativePath);
|
|
257
|
+
if (refused === null) owned.push(relativePath);
|
|
258
|
+
else warnings.push(refused);
|
|
223
259
|
}
|
|
224
|
-
|
|
260
|
+
/** A refused copy's record goes too: it was never provably Mate's to keep. */
|
|
261
|
+
if (recorded.length > 0) {
|
|
225
262
|
await updateManifest(repoPath, (manifest) => withCopies(manifest, "opencode", {}));
|
|
226
263
|
}
|
|
227
264
|
const excludes = await reconcileWorkingRepoCopyExcludes(repoPath, [], recordedCopiesOf);
|
|
228
265
|
/** Deleted copies count as a change too: kept lines make a removal `retained` only when nothing else went. */
|
|
229
|
-
return {
|
|
266
|
+
return {
|
|
267
|
+
...excludes,
|
|
268
|
+
owned,
|
|
269
|
+
warnings,
|
|
270
|
+
changed: recorded.length > 0 || excludes.changed,
|
|
271
|
+
};
|
|
230
272
|
}
|
|
231
273
|
|
|
232
274
|
export async function withdrawCompanionCopies(repoPath: string): Promise<ProjectionWriteReport> {
|
|
233
|
-
const { owned, changed } = await withdraw(repoPath);
|
|
275
|
+
const { owned, changed, warnings } = await withdraw(repoPath);
|
|
234
276
|
return {
|
|
235
277
|
state: changed ? "written" : "current",
|
|
278
|
+
...(warnings.length > 0 ? { warnings } : {}),
|
|
236
279
|
changed: { written: [], removed: owned },
|
|
237
280
|
};
|
|
238
281
|
}
|
|
239
282
|
|
|
240
283
|
export async function removeCompanionCopies(repoPath: string): Promise<ProjectionSelfRemoval> {
|
|
241
|
-
|
|
284
|
+
const withdrawn = await withdraw(repoPath);
|
|
285
|
+
return removalWithWarnings(excludeRemovalReport(withdrawn), withdrawn.warnings);
|
|
242
286
|
}
|
|
243
287
|
|
|
244
288
|
/** Whether any owned copy is recorded. */
|