@uniqbit/mate-core 1.0.0-canary.6 → 1.0.0-canary.8
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/package.json +6 -3
- package/src/cli/commands/artifact/delivery/submit.ts +6 -4
- package/src/cli/commands/artifact/finish/command.ts +28 -11
- package/src/cli/commands/artifact/pending/command.ts +71 -7
- package/src/cli/commands/cap/tokensave.ts +2 -2
- package/src/cli/commands/companion/update.ts +2 -3
- package/src/cli/commands/doctor.ts +67 -4
- package/src/cli/commands/friction.ts +558 -0
- package/src/cli/commands/install.ts +8 -4
- package/src/cli/commands/plugin/install.ts +82 -35
- package/src/cli/commands/studio/connection.ts +53 -0
- package/src/cli/commands/studio/routes.ts +3 -0
- package/src/cli/commands/studio/selection.ts +10 -1
- package/src/cli/commands/studio/server.ts +31 -0
- package/src/cli/commands/studio/service-host.ts +3 -0
- package/src/cli/commands/studio/services.ts +25 -0
- package/src/cli/commands/triage.ts +172 -0
- package/src/cli/commands/vscode/release-vsix.json +2 -2
- package/src/cli/install-plan.tsx +3 -0
- package/src/cli/main.ts +85 -19
- package/src/cli/plugin-commands.ts +6 -1
- package/src/cli/usage.ts +12 -2
- package/src/create-mate.ts +11 -5
- package/src/distribution.ts +2 -0
- package/src/factory-host.ts +6 -0
- package/src/hooks/validate-artifact-path.ts +64 -14
- package/src/index.ts +1 -0
- package/src/lib/delivery/merge-git.ts +31 -7
- package/src/lib/delivery/overlap.ts +14 -1
- package/src/lib/delivery/repository-access.ts +11 -6
- package/src/lib/delivery/staging/apply-chain.ts +25 -7
- package/src/lib/delivery/staging/linked-merges.ts +175 -0
- package/src/lib/delivery/staging/naming.ts +3 -0
- package/src/lib/delivery/staging/openspec-type.ts +38 -7
- package/src/lib/delivery/staging/pending.ts +153 -11
- package/src/lib/delivery/staging/preflight.ts +239 -0
- package/src/lib/delivery/staging/project.ts +243 -104
- package/src/lib/delivery/staging/replay.ts +5 -3
- package/src/lib/delivery/staging/settle-linked.ts +5 -119
- package/src/lib/delivery/staging/submit.ts +139 -18
- package/src/lib/delivery/submit-change.ts +163 -37
- package/src/lib/friction/describe.ts +42 -0
- package/src/lib/friction/fields.ts +60 -0
- package/src/lib/friction/mark.ts +194 -0
- package/src/lib/friction/view/model.ts +67 -0
- package/src/lib/friction/view/read.ts +145 -0
- package/src/lib/friction/view/select.ts +54 -0
- package/src/lib/openspec-cli.ts +10 -5
- package/src/lib/orchestrator/adapters/claude.ts +5 -4
- package/src/lib/orchestrator/adapters/opencode.ts +2 -0
- package/src/lib/orchestrator/root-context.ts +23 -6
- package/src/lib/package-paths.ts +23 -15
- package/src/lib/session-attribution.ts +3 -7
- package/src/lib/skills-cli.ts +38 -0
- package/src/lib/tool-manifest.ts +73 -0
- package/src/lib/triage/context.ts +312 -0
- package/src/lib/triage/launch.ts +52 -0
- package/src/lib/triage/prepare.ts +112 -0
- package/src/lib/triage/session.ts +126 -0
- package/src/opencode/companion-hooks.ts +53 -5
- package/src/opencode/projected-guidance.ts +2 -0
- package/src/playbooks/companion-guidance.ts +2 -2
- package/src/plugin-api.ts +6 -0
- package/src/runtime/command-arg.ts +15 -0
- package/src/runtime/command-friction.ts +97 -0
- package/src/runtime/companion-guidance.ts +33 -16
- package/src/runtime/friction-fingerprint.ts +35 -0
- package/src/runtime/friction-log.ts +376 -0
- package/src/runtime/friction-recorder.ts +212 -0
- package/src/runtime/friction-retention.ts +1 -0
- package/src/runtime/friction-state.ts +110 -0
- package/src/runtime/friction-switch.ts +26 -0
- package/src/runtime/friction-vocabulary.ts +42 -0
- package/src/runtime/git-tracked.ts +13 -2
- package/src/runtime/projected-guidance.ts +2 -1
- package/src/runtime/secret-values.ts +16 -0
- package/src/runtime/session-id.ts +24 -0
- package/src/runtime/session-prepare-runner.ts +3 -0
- package/src/runtime/workflow/next-handoff-process.ts +2 -1
- package/src/studio.ts +47 -1
- package/src/templates/capabilities/openspec-cap/mate-minimal/schema.yaml +5 -1
- package/src/templates/capabilities/react-doctor/mate-react-doctor/SKILL.md +28 -0
- package/src/templates/mate-skills/agents/mate-apply-change/SKILL.md +42 -4
- package/src/templates/mate-skills/agents/mate-archive-change/SKILL.md +27 -2
- package/src/templates/mate-skills/agents/mate-backfill-spec/SKILL.md +23 -1
- package/src/templates/mate-skills/agents/mate-clarify-intent/SKILL.md +26 -1
- package/src/templates/mate-skills/agents/mate-domain-modeling/SKILL.md +28 -0
- package/src/templates/mate-skills/agents/mate-explore-change/SKILL.md +28 -3
- package/src/templates/mate-skills/agents/mate-grill-me/SKILL.md +28 -0
- package/src/templates/mate-skills/agents/mate-grill-with-docs/SKILL.md +28 -0
- package/src/templates/mate-skills/agents/mate-grilling/SKILL.md +25 -0
- package/src/templates/mate-skills/agents/mate-interview-me/SKILL.md +28 -0
- package/src/templates/mate-skills/agents/mate-propose-change/SKILL.md +28 -3
- package/src/templates/mate-skills/agents/mate-publish-artifact/SKILL.md +28 -6
- package/src/templates/mate-skills/agents/mate-show-me/SKILL.md +27 -2
- package/src/templates/mate-skills/agents/mate-simplify-code/SKILL.md +28 -0
- package/src/templates/mate-skills/agents/mate-submit-change/SKILL.md +24 -2
- package/src/templates/mate-skills/claude/mate-apply-change/SKILL.md +42 -4
- package/src/templates/mate-skills/claude/mate-archive-change/SKILL.md +27 -2
- package/src/templates/mate-skills/claude/mate-backfill-spec/SKILL.md +23 -1
- package/src/templates/mate-skills/claude/mate-clarify-intent/SKILL.md +26 -1
- package/src/templates/mate-skills/claude/mate-domain-modeling/SKILL.md +28 -0
- package/src/templates/mate-skills/claude/mate-explore-change/SKILL.md +28 -3
- package/src/templates/mate-skills/claude/mate-grill-me/SKILL.md +28 -0
- package/src/templates/mate-skills/claude/mate-grill-with-docs/SKILL.md +28 -0
- package/src/templates/mate-skills/claude/mate-grilling/SKILL.md +25 -0
- package/src/templates/mate-skills/claude/mate-interview-me/SKILL.md +28 -0
- package/src/templates/mate-skills/claude/mate-propose-change/SKILL.md +28 -3
- package/src/templates/mate-skills/claude/mate-publish-artifact/SKILL.md +28 -6
- package/src/templates/mate-skills/claude/mate-show-me/SKILL.md +27 -2
- package/src/templates/mate-skills/claude/mate-simplify-code/SKILL.md +28 -0
- package/src/templates/mate-skills/claude/mate-submit-change/SKILL.md +24 -2
- package/src/templates/triage/PLAYBOOK.md +120 -0
- package/src/tools/setup/__snapshots__/runtime-surface-golden.test.ts.snap +108 -108
- package/src/tools/setup/capabilities/graphify.ts +23 -1
- package/src/tools/setup/capabilities/rtk.ts +46 -94
- package/src/tools/setup/capabilities/tokensave.ts +76 -54
- package/src/tools/setup/dynamic-plugins/audiences.ts +28 -14
- package/src/tools/setup/dynamic-plugins/hydrate.ts +32 -14
- package/src/tools/setup/dynamic-plugins/install.ts +2 -0
- package/src/tools/setup/dynamic-plugins/installed.ts +73 -0
- package/src/tools/setup/dynamic-plugins/loader.ts +12 -10
- package/src/tools/setup/dynamic-plugins/local.ts +492 -0
- package/src/tools/setup/dynamic-plugins/paths.ts +34 -6
- package/src/tools/setup/dynamic-plugins/verify.ts +34 -14
- package/src/tools/setup/dynamic-plugins/workspaces.ts +17 -8
- package/src/tools/setup/mate.ts +26 -1
- package/src/tools/setup/plugin.ts +5 -0
- package/src/tools/setup/plugins/gitignore.ts +45 -12
- package/src/tools/setup/service.ts +12 -0
- package/src/tools/setup/utils.ts +10 -1
- package/src/tools/setup.ts +16 -2
- package/studio-dist/client/assets/app-ggXJ_QVh.css +2 -0
- package/studio-dist/client/assets/button-amJ3g5oD.js +1 -0
- package/studio-dist/client/assets/cn-BQPKiwI4.js +1 -0
- package/studio-dist/client/assets/combobox-CJ7aGFid.js +1 -0
- package/studio-dist/client/assets/{companion-view-BVaZNtiI.js → companion-view-C_N237bf.js} +1 -1
- package/studio-dist/client/assets/fields-BAiGkJ5N.js +1 -0
- package/studio-dist/client/assets/friction-DqOU59v7.js +1 -0
- package/studio-dist/client/assets/getting-started-djaQeWlu.js +1 -0
- package/studio-dist/client/assets/getting-started-yp42dj5S.js +1 -0
- package/studio-dist/client/assets/getting-started._topic-C9zVXz_m.js +1 -0
- package/studio-dist/client/assets/getting-started.index-DWbDKICP.js +1 -0
- package/studio-dist/client/assets/graph-BYaD_5Bq.js +2 -0
- package/studio-dist/client/assets/{graph-canvas-DDuzsNSx.js → graph-canvas-ySGKMhmk.js} +1 -1
- package/studio-dist/client/assets/guides-D6T6W_jV.js +1 -0
- package/studio-dist/client/assets/index-Qx7reRPD.js +40 -0
- package/studio-dist/client/assets/markdown-view-jMiaBTSO.js +1 -0
- package/studio-dist/client/assets/panel-C4bf_h2W.js +1 -0
- package/studio-dist/client/assets/plugins._service._view-y6f2FDAB.js +1 -0
- package/studio-dist/client/assets/prepaint-CKsXyJOR.js +27 -0
- package/studio-dist/client/assets/{queries-axYk2u9L.js → queries-Dfp5deWj.js} +1 -1
- package/studio-dist/client/assets/react-BYUSgtBs.js +1 -0
- package/studio-dist/client/assets/reports-JFSwSueq.js +1 -0
- package/studio-dist/client/assets/routes-BdOWSgzK.js +1 -0
- package/studio-dist/client/assets/search-CXosfvYh.js +1 -0
- package/studio-dist/client/assets/select-BHYYWPhK.js +1 -0
- package/studio-dist/client/assets/skills-Bo9FLsBd.js +1 -0
- package/studio-dist/client/assets/{specs-DU1kqcp5.js → specs-BrCOjOch.js} +1 -1
- package/studio-dist/client/assets/specs-view-CdE2rlli.js +1 -0
- package/studio-dist/client/assets/{steps-DhIFuAZy.js → steps-CKUno4lh.js} +1 -1
- package/studio-dist/client/assets/store-C3vJq8Wj.js +1 -0
- package/studio-dist/client/assets/{studio-BR9j15J0.js → studio-0ueISxwP.js} +8 -8
- package/studio-dist/client/assets/{studio-queries-CFP_yTpr.js → studio-queries-BflKt9va.js} +2 -2
- package/studio-dist/client/assets/{usage-CHmwtkoM.js → usage-BLsLy0nN.js} +16 -16
- package/studio-dist/client/assets/useAnchoredPopupScrollLock-DC7f8GOp.js +1 -0
- package/studio-dist/client/assets/useMutation-uJUrejsi.js +1 -0
- package/studio-dist/client/assets/vault-BB1B_OhR.js +1 -0
- package/studio-dist/client/assets/warnings-CqOOGlPD.js +1 -0
- package/studio-dist/client/assets/workflow-BFzmI-06.js +1 -0
- package/studio-dist/server/assets/{__23tanstack-start-server-fn-resolver-DAbZ6fzY.js → __23tanstack-start-server-fn-resolver-gVfW5vIV.js} +30 -14
- package/studio-dist/server/assets/_tanstack-start-manifest_v.js +66 -50
- package/studio-dist/server/assets/{button-BfoNadNR.js → button-D6bvrFmm.js} +226 -3478
- package/studio-dist/server/assets/cn-FXJAM0KO.js +5528 -0
- package/studio-dist/server/assets/combobox-D2MbYV1O.js +484 -0
- package/studio-dist/server/assets/{companion-view-DHUjPpA0.js → companion-view-Mf1ANbMb.js} +2 -2
- package/studio-dist/server/assets/{companions-kBrJZAd6.js → companions-Dr6IpNAb.js} +1 -1
- package/studio-dist/server/assets/{fields-BD_c65T1.js → fields-B4mAPETz.js} +2 -1
- package/studio-dist/server/assets/friction-9a5S1m7U.js +943 -0
- package/studio-dist/server/assets/friction-CWOTjpCV.js +62 -0
- package/studio-dist/server/assets/{getting-started-7P0oyWaM.js → getting-started-RU6tYU2Q.js} +2 -2
- package/studio-dist/server/assets/{getting-started._topic-B1mV0kGz.js → getting-started._topic-C02HGrC6.js} +2 -2
- package/studio-dist/server/assets/{getting-started.index-CeGtvUsm.js → getting-started.index-EzLRosbb.js} +2 -2
- package/studio-dist/server/assets/{graph-BWtmJOH2.js → graph-B11ITte0.js} +1 -1
- package/studio-dist/server/assets/{graph-DSDVEELZ.js → graph-CZ2H9Fzr.js} +8 -8
- package/studio-dist/server/assets/{graph-canvas-CID9Nksc.js → graph-canvas-rP5TT14Z.js} +2 -2
- package/studio-dist/server/assets/{guides-Bm3RbUB-.js → guides-B8HdeK_C.js} +1 -1
- package/studio-dist/server/assets/{guides-BLJenHwQ.js → guides-BGftp4wf.js} +1 -1
- package/studio-dist/server/assets/{guides.server-rHHqRuzV.js → guides.server-DqFQAStf.js} +1 -1
- package/studio-dist/server/assets/{markdown-view-D3v9x-cM.js → markdown-view-CArpV-CS.js} +1 -1
- package/studio-dist/server/assets/{panel-yqOl5GMU.js → panel-DR0iq46J.js} +4 -3
- package/studio-dist/server/assets/{plugins._service._view-DwqJX7s9.js → plugins._service._view-n7u2k5dF.js} +11 -6
- package/studio-dist/server/assets/prepaint-B28ClcPN.js +45 -0
- package/studio-dist/server/assets/{queries-DYmGrhNO.js → queries-D-yVP9i0.js} +1 -1
- package/studio-dist/server/assets/react-CiBZPDs8.js +45 -0
- package/studio-dist/server/assets/{reports-C4Y_Jd-x.js → reports-B9k98oE6.js} +1 -1
- package/studio-dist/server/assets/{reports-7yaPz7aP.js → reports-C2SmTgqh.js} +7 -7
- package/studio-dist/server/assets/{router-Dnoq5auE.js → router-CPt0TAk_.js} +654 -1565
- package/studio-dist/server/assets/{routes-Cok4p3mK.js → routes-CwH8LEy2.js} +8 -8
- package/studio-dist/server/assets/{search-DUK7Jl6f.js → search-b-yQesv3.js} +25 -2
- package/studio-dist/server/assets/{combobox-oxUI6r4V.js → select-C3i6TTX-.js} +35 -514
- package/studio-dist/server/assets/{shell-DNVXedgE.js → shell-CagqZZMZ.js} +4 -3
- package/studio-dist/server/assets/{skills-D8qdXSku.js → skills-C21Mg_8-.js} +8 -8
- package/studio-dist/server/assets/{skills-pKmuAs0F.js → skills-DGg0mWDM.js} +1 -1
- package/studio-dist/server/assets/{specs-DeHYUNFp.js → specs-DetoMiaB.js} +4 -4
- package/studio-dist/server/assets/{specs-view-BGn-5Ik_.js → specs-view-CmbfLDwN.js} +10 -9
- package/studio-dist/server/assets/{steps-CV7Yk7L7.js → steps-D1tYAyWZ.js} +1 -1
- package/studio-dist/server/assets/store-aC-I6f6o.js +93 -0
- package/studio-dist/server/assets/{studio-CB94np48.js → studio-qRvQjRpz.js} +47 -2
- package/studio-dist/server/assets/{studio-queries-BqZGBE70.js → studio-queries-Dqf-3nzj.js} +66 -8
- package/studio-dist/server/assets/{usage-M6Gi6Km7.js → usage-CS4CBK9D.js} +13 -44
- package/studio-dist/server/assets/{usage-j5jR9gX9.js → usage-Cwle9-xY.js} +1 -1
- package/studio-dist/server/assets/useAnchoredPopupScrollLock-BjMNgXv9.js +756 -0
- package/studio-dist/server/assets/useMutation-DpBIuWXt.js +690 -0
- package/studio-dist/server/assets/{vault-lBlvSyD4.js → vault-CEBBRLMb.js} +1 -1
- package/studio-dist/server/assets/{vault-PqVmssmW.js → vault-DVQidlId.js} +6 -6
- package/studio-dist/server/assets/{views-CsFp1i1G.js → views-UgO0Qz_g.js} +2 -2
- package/studio-dist/server/assets/{warnings-BDs34j_m.js → warnings-C7hgXpdk.js} +2 -2
- package/studio-dist/server/assets/{workflow-T0eEldsa.js → workflow-6dZZ1ofw.js} +9 -9
- package/studio-dist/server/server.js +2 -2
- package/tool-manifest.yaml +85 -0
- package/studio-dist/client/assets/app-BFVyWHGo.css +0 -2
- package/studio-dist/client/assets/button-D6LrRkOG.js +0 -1
- package/studio-dist/client/assets/combobox-Dk2MMZWE.js +0 -1
- package/studio-dist/client/assets/fields-D_FYhxQr.js +0 -1
- package/studio-dist/client/assets/getting-started-ByWRg7hC.js +0 -1
- package/studio-dist/client/assets/getting-started-DZSjYC-b.js +0 -1
- package/studio-dist/client/assets/getting-started._topic-C6OyQ4G6.js +0 -1
- package/studio-dist/client/assets/getting-started.index-BkmPHdEm.js +0 -1
- package/studio-dist/client/assets/graph-7jm2XzyL.js +0 -2
- package/studio-dist/client/assets/guides-D9VTjWXP.js +0 -1
- package/studio-dist/client/assets/index-BBmFpG4y.js +0 -40
- package/studio-dist/client/assets/markdown-view-RL5YvfZg.js +0 -1
- package/studio-dist/client/assets/panel-B8F8sOKQ.js +0 -1
- package/studio-dist/client/assets/plugins._service._view-CynxTbMx.js +0 -1
- package/studio-dist/client/assets/react-r45OnJCw.js +0 -27
- package/studio-dist/client/assets/reports-BCAyXh6p.js +0 -1
- package/studio-dist/client/assets/routes-BFPqq89E.js +0 -1
- package/studio-dist/client/assets/skills-DTks_uBx.js +0 -1
- package/studio-dist/client/assets/specs-view-omrd_5P3.js +0 -1
- package/studio-dist/client/assets/store-DJ5cncKA.js +0 -1
- package/studio-dist/client/assets/useBaseQuery-BlC-AZ35.js +0 -1
- package/studio-dist/client/assets/vault-DRg8MScm.js +0 -1
- package/studio-dist/client/assets/warnings-UHFy6HAp.js +0 -1
- package/studio-dist/client/assets/workflow-Bv9vSfVV.js +0 -1
- package/studio-dist/server/assets/react-BO0uMhpm.js +0 -89
- package/studio-dist/server/assets/store-CWDGIp6x.js +0 -280
- package/studio-dist/server/assets/useBaseQuery-Tv_QJt9r.js +0 -2051
package/src/cli/main.ts
CHANGED
|
@@ -12,6 +12,7 @@ import { runCompanionCommand } from "./commands/companion/companion";
|
|
|
12
12
|
import { runHubCommand } from "./commands/companion/hub";
|
|
13
13
|
import { runConfigCommand } from "./commands/config";
|
|
14
14
|
import { runDoctorCommand } from "./commands/doctor";
|
|
15
|
+
import { runFrictionCommand } from "./commands/friction";
|
|
15
16
|
import { runLaunchClaudeCommand } from "./commands/launch/claude";
|
|
16
17
|
import { runLaunchOpenCodeCommand } from "./commands/launch/opencode";
|
|
17
18
|
import { runPluginCommand } from "./commands/plugin/plugin";
|
|
@@ -19,13 +20,14 @@ import { runReportCommand } from "./commands/report";
|
|
|
19
20
|
import { runSessionContextCommand } from "./commands/session/context";
|
|
20
21
|
import { runSessionCommand } from "./commands/session/prepare";
|
|
21
22
|
import { runStudioCommand } from "./commands/studio";
|
|
23
|
+
import { runTriageCommand } from "./commands/triage";
|
|
22
24
|
import { runUpdateCommand } from "./commands/update";
|
|
23
25
|
import { runUnwrapCommand } from "./commands/unwrap";
|
|
24
26
|
import { runVscodeCommand } from "./commands/vscode/setup";
|
|
25
27
|
import { parseWrapArgs, runWrapCommand } from "./commands/wrap";
|
|
26
28
|
import { runWorkingCommand } from "./commands/working/working";
|
|
27
29
|
import { runWorkflowCommand } from "./commands/workflow/workflow";
|
|
28
|
-
import { runInstallCommand } from "./commands/install";
|
|
30
|
+
import { isFrozenPluginInstall, runInstallCommand } from "./commands/install";
|
|
29
31
|
import { parseDirectLaunchArgs } from "./commands/launch/shared";
|
|
30
32
|
import {
|
|
31
33
|
inspectInstallPreflight,
|
|
@@ -78,20 +80,74 @@ const mainDeps: MainDeps = {
|
|
|
78
80
|
refreshRuntimeDirectory,
|
|
79
81
|
};
|
|
80
82
|
|
|
83
|
+
function printPreflightErrorDocument(message: string): void {
|
|
84
|
+
console.log(
|
|
85
|
+
JSON.stringify({ kind: "error", version: 1, error: { code: "PREFLIGHT_FAILED", message } }),
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Built-in commands whose `--help` or `-h` main answers with the usage before any gate.
|
|
91
|
+
* `workflow` and `plugin install` print their own usage, `cap` its plugin's, and `claude` and
|
|
92
|
+
* `opencode` pass it to the agent.
|
|
93
|
+
*/
|
|
94
|
+
const MAIN_ANSWERS_HELP = new Set([
|
|
95
|
+
"install",
|
|
96
|
+
"plugin",
|
|
97
|
+
"artifact",
|
|
98
|
+
"companion",
|
|
99
|
+
"hub",
|
|
100
|
+
"report",
|
|
101
|
+
"studio",
|
|
102
|
+
"config",
|
|
103
|
+
"doctor",
|
|
104
|
+
"friction",
|
|
105
|
+
"update",
|
|
106
|
+
"working",
|
|
107
|
+
"wrap",
|
|
108
|
+
"session",
|
|
109
|
+
"vscode",
|
|
110
|
+
"unwrap",
|
|
111
|
+
"triage",
|
|
112
|
+
]);
|
|
113
|
+
|
|
114
|
+
/** True when `args` ask for help before a `--`, which passes what follows on untouched. */
|
|
115
|
+
function asksForHelp(command: string, args: readonly string[]): boolean {
|
|
116
|
+
if (!MAIN_ANSWERS_HELP.has(command) || (command === "plugin" && args[0] === "install")) {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
const end = args.indexOf("--");
|
|
120
|
+
return (end < 0 ? args : args.slice(0, end)).some((arg) => arg === "--help" || arg === "-h");
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const FRICTION_GATE_NEEDS = new Map<string | undefined, GateNeeds>([
|
|
124
|
+
["list", { updateGuard: true, companion: true, install: true }],
|
|
125
|
+
["report", { companion: true }],
|
|
126
|
+
]);
|
|
127
|
+
|
|
81
128
|
export async function main(argv = process.argv, deps: MainDeps = mainDeps): Promise<void> {
|
|
82
129
|
const [, , command, subcommand, ...rest] = argv;
|
|
130
|
+
const helpRequest = command !== undefined && asksForHelp(command, argv.slice(3));
|
|
83
131
|
|
|
84
132
|
/**
|
|
85
133
|
* A Claude plugin asks this on every mention of a plain session. It changes
|
|
86
134
|
* nothing and prints only its answer, so it skips the runtime refresh,
|
|
87
135
|
* plugin loading, the update checks and every gate.
|
|
88
136
|
*/
|
|
89
|
-
if (command === "session" && subcommand === "context") {
|
|
137
|
+
if (command === "session" && subcommand === "context" && !helpRequest) {
|
|
90
138
|
await runSessionContextCommand(rest);
|
|
91
139
|
return;
|
|
92
140
|
}
|
|
93
141
|
|
|
94
|
-
if (
|
|
142
|
+
if (command === "triage" && !helpRequest) {
|
|
143
|
+
await runTriageCommand(argv.slice(3));
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Help needs no runtime paths, so a failed refresh only warns, as for `mate help`.
|
|
148
|
+
if (
|
|
149
|
+
!(await ensureRuntimeDirectory(helpRequest ? "help" : command, deps.refreshRuntimeDirectory))
|
|
150
|
+
) {
|
|
95
151
|
process.exitCode = 1;
|
|
96
152
|
return;
|
|
97
153
|
}
|
|
@@ -105,10 +161,16 @@ export async function main(argv = process.argv, deps: MainDeps = mainDeps): Prom
|
|
|
105
161
|
// text is printed, so their commands route like compiled-in ones
|
|
106
162
|
// (including MCP servers whose command is their own cap subcommand) and
|
|
107
163
|
// show up in `mate help`. Diagnostics stay on stderr; a missing or
|
|
108
|
-
// ambiguous companion makes this a no-op.
|
|
109
|
-
|
|
164
|
+
// ambiguous companion makes this a no-op. A frozen verification ignores
|
|
165
|
+
// local plugins.
|
|
166
|
+
const ignoresLocalPlugins = command === "doctor" && isFrozenPluginInstall(argv);
|
|
167
|
+
// A package registers once per process, so a load here would pin the
|
|
168
|
+
// pre-install version for the install's own sync; both installs load after their plugin step.
|
|
169
|
+
if (!(command === "install" || (command === "plugin" && subcommand === "install"))) {
|
|
170
|
+
await deps.hydrateDynamicPlugins({ includeLocal: !ignoresLocalPlugins });
|
|
171
|
+
}
|
|
110
172
|
|
|
111
|
-
if (!command || command === "help" || command === "--help" || command === "-h") {
|
|
173
|
+
if (!command || command === "help" || command === "--help" || command === "-h" || helpRequest) {
|
|
112
174
|
console.log(usage());
|
|
113
175
|
return;
|
|
114
176
|
}
|
|
@@ -123,10 +185,9 @@ export async function main(argv = process.argv, deps: MainDeps = mainDeps): Prom
|
|
|
123
185
|
// scheduleBackgroundCheck() has been observed to race a large final stdout
|
|
124
186
|
// write against process exit, truncating it.
|
|
125
187
|
const ownsStdout = isPluginCommand;
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
const skipsBackgroundCheck = ownsStdout || command === "report" || command === "workflow";
|
|
188
|
+
const printsJsonContract =
|
|
189
|
+
command === "report" || command === "friction" || command === "workflow";
|
|
190
|
+
const skipsBackgroundCheck = ownsStdout || printsJsonContract;
|
|
130
191
|
|
|
131
192
|
// Every dispatch case opens with a gate() call declaring what the command
|
|
132
193
|
// needs before it may run. Declared gates run in fixed order — update
|
|
@@ -287,15 +348,8 @@ export async function main(argv = process.argv, deps: MainDeps = mainDeps): Prom
|
|
|
287
348
|
return;
|
|
288
349
|
case "report":
|
|
289
350
|
if (!(await gate({ updateGuard: true, install: true }))) {
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
kind: "error",
|
|
293
|
-
version: 1,
|
|
294
|
-
error: {
|
|
295
|
-
code: "PREFLIGHT_FAILED",
|
|
296
|
-
message: "Mate must be updated or installed before reporting; see stderr",
|
|
297
|
-
},
|
|
298
|
-
}),
|
|
351
|
+
printPreflightErrorDocument(
|
|
352
|
+
"Mate must be updated or installed before reporting; see stderr",
|
|
299
353
|
);
|
|
300
354
|
return;
|
|
301
355
|
}
|
|
@@ -317,6 +371,18 @@ export async function main(argv = process.argv, deps: MainDeps = mainDeps): Prom
|
|
|
317
371
|
if (!(await gate({}))) return;
|
|
318
372
|
await runDoctorCommand(argv.slice(3));
|
|
319
373
|
return;
|
|
374
|
+
case "friction": {
|
|
375
|
+
if (!(await gate(FRICTION_GATE_NEEDS.get(subcommand) ?? {}))) {
|
|
376
|
+
if (rest.includes("--json")) {
|
|
377
|
+
printPreflightErrorDocument(
|
|
378
|
+
"Mate must be updated, installed or given one companion; see stderr",
|
|
379
|
+
);
|
|
380
|
+
}
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
await runFrictionCommand(subcommand, rest);
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
320
386
|
case "cap":
|
|
321
387
|
if (!(await gate({ updateGuard: true, companion: true, install: true }))) return;
|
|
322
388
|
await runCapCommand(subcommand, rest);
|
|
@@ -18,7 +18,7 @@ function pluginForNamespace(namespace: string): Plugin | undefined {
|
|
|
18
18
|
* Dispatch `<distribution> cap <namespace> <name>` to a plugin-declared CLI
|
|
19
19
|
* command. Returns true when the namespace belongs to a plugin that declares
|
|
20
20
|
* CLI commands (the invocation is then fully handled here, including
|
|
21
|
-
* unknown-subcommand errors); false when no plugin claims the namespace so
|
|
21
|
+
* `--help`/`-h` and unknown-subcommand errors); false when no plugin claims the namespace so
|
|
22
22
|
* the caller can report an unknown command. Framework `cap` subcommands are
|
|
23
23
|
* dispatched before this is consulted, so they can never be shadowed.
|
|
24
24
|
*
|
|
@@ -35,6 +35,11 @@ export async function runPluginCliCommand(
|
|
|
35
35
|
const commands = plugin?.cliCommands;
|
|
36
36
|
if (!plugin || !commands || commands.length === 0) return false;
|
|
37
37
|
|
|
38
|
+
if (commandName === "--help" || commandName === "-h") {
|
|
39
|
+
console.log(usageFor(plugin));
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
|
|
38
43
|
const command = findPluginCliCommand(namespace, commandName);
|
|
39
44
|
if (!command) {
|
|
40
45
|
console.error(
|
package/src/cli/usage.ts
CHANGED
|
@@ -40,7 +40,7 @@ export function usage(): string {
|
|
|
40
40
|
` ${n} artifact publish <group|change|anchor>|--specs [<path>...]|--all [--refresh]`,
|
|
41
41
|
" [--confirm-merged|--confirm-open|--confirm-dropped] [--type openspec] [--no-push] [--json]",
|
|
42
42
|
" target: a Delivery Group or submitted change, or a dated archive anchor of an earlier Mate",
|
|
43
|
-
` ${n} artifact pending [--json]`,
|
|
43
|
+
` ${n} artifact pending [--no-merge-check] [--json]`,
|
|
44
44
|
` ${n} artifact link <change>... [--repository <org/repo>] [--branch <b> [--direct]]`,
|
|
45
45
|
" [--not-applicable <reason>] [--pr <url>] [--ticket <KEY>] [--refresh]",
|
|
46
46
|
" [--confirm-merged|--confirm-open|--confirm-dropped] [--spec-base] [--json]",
|
|
@@ -58,6 +58,16 @@ export function usage(): string {
|
|
|
58
58
|
` ${n} workflow next <change> [--after <skill>] [--json] the stage a change is at and its next actions`,
|
|
59
59
|
` ${n} workflow trust [--json] approve the run: commands the companion's workflow declares`,
|
|
60
60
|
` ${n} doctor`,
|
|
61
|
+
` ${n} friction on record Mate's friction on this machine (off by default)`,
|
|
62
|
+
` ${n} friction off stop recording; the records stay`,
|
|
63
|
+
` ${n} friction status [--json]`,
|
|
64
|
+
` ${n} friction list [--days N] [--all] [--state open|handled|all] [--json]`,
|
|
65
|
+
` ${n} friction report [<event-id>] --kind <bug|unclear|missing> --expected <text>`,
|
|
66
|
+
" [--cost <blocker|detour|papercut>] [--subject <type>[:<name>]] [--evidence <text>]",
|
|
67
|
+
" [--workaround <text>] [--json]",
|
|
68
|
+
` ${n} friction mark <fingerprint|report-id> --state <open|fixed|reported|dismissed>`,
|
|
69
|
+
" [--note <text>] [--link <url>] [--json]",
|
|
70
|
+
` ${n} triage ["<fingerprint|report-id>"] [--agent <claude|opencode>] [--no-launch]`,
|
|
61
71
|
` ${n} report [--days N] [--input FILE|-] [--json]`,
|
|
62
72
|
` ${n} studio [--writable] [--terminal] [--detach-timeout <minutes>]`,
|
|
63
73
|
` ${n} studio serve --port <port> [--host <host>] [--writable] [--terminal]`,
|
|
@@ -72,7 +82,7 @@ export function usage(): string {
|
|
|
72
82
|
` ${n} cap openspec <subcommand> [args...]`,
|
|
73
83
|
` ${n} cap graphify <subcommand> [args...]`,
|
|
74
84
|
` ${n} cap index [--graphify] [--tokensave]`,
|
|
75
|
-
` ${n} plugin install <package>[@version]`,
|
|
85
|
+
` ${n} plugin install [--local] <package>[@version]`,
|
|
76
86
|
...pluginCliCommandLines(),
|
|
77
87
|
` ${n} update`,
|
|
78
88
|
` ${n} update --check`,
|
package/src/create-mate.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { main } from "./cli/main";
|
|
2
2
|
import { setActiveDistribution, type DistributionConfig } from "./distribution";
|
|
3
3
|
import { FRAMEWORK_NAME } from "./framework";
|
|
4
|
+
import { currentSession } from "./lib/session-attribution";
|
|
5
|
+
import { runRecordingFailure } from "./runtime/command-friction";
|
|
4
6
|
import { createBunPlugin } from "./tools/setup/package-managers/bun";
|
|
5
7
|
import { createUvPlugin } from "./tools/setup/package-managers/uv";
|
|
6
8
|
import type { PluginRegistration } from "./tools/setup/plugin";
|
|
@@ -39,10 +41,14 @@ export function createMate({ config, plugins, main: runMain = main }: CreateMate
|
|
|
39
41
|
return {
|
|
40
42
|
config,
|
|
41
43
|
registry,
|
|
42
|
-
run: (argv = process.argv) =>
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
run: async (argv = process.argv) =>
|
|
45
|
+
runRecordingFailure(
|
|
46
|
+
{
|
|
47
|
+
args: argv.slice(2),
|
|
48
|
+
session: currentSession(process.env),
|
|
49
|
+
mateVersion: config.version,
|
|
50
|
+
},
|
|
51
|
+
() => runMain(argv),
|
|
52
|
+
),
|
|
47
53
|
};
|
|
48
54
|
}
|
package/src/distribution.ts
CHANGED
|
@@ -22,6 +22,8 @@ export interface DistributionConfig {
|
|
|
22
22
|
assetRoots?: string[];
|
|
23
23
|
/** Optional update source; defaults to `@uniqbit/mate` on public npm. */
|
|
24
24
|
update?: DistributionUpdateConfig;
|
|
25
|
+
/** GitHub repository (`owner/name`) that `mate triage` files issues against; none ends triage with a local report. */
|
|
26
|
+
issueRepository?: string;
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
export interface ActiveDistribution {
|
package/src/factory-host.ts
CHANGED
|
@@ -65,5 +65,11 @@ export { readWorksetStages, type WorksetWithStage } from "./lib/workset/stages";
|
|
|
65
65
|
export { buildCompanionGuidance } from "./playbooks/companion-guidance";
|
|
66
66
|
export { errorMessage } from "./runtime/error-message";
|
|
67
67
|
export { resolveSecretPolicy } from "./runtime/policy";
|
|
68
|
+
export {
|
|
69
|
+
installedPluginPackages,
|
|
70
|
+
type InstalledPluginPackage,
|
|
71
|
+
type InstalledPluginsOptions,
|
|
72
|
+
} from "./tools/setup/dynamic-plugins/installed";
|
|
73
|
+
export type { PluginOrigin } from "./tools/setup/dynamic-plugins/paths";
|
|
68
74
|
export { deployReactDoctorSkill } from "./tools/setup/capabilities/react-doctor";
|
|
69
75
|
export { applyMateSkills, MATE_SKILLS } from "./tools/setup/mate";
|
|
@@ -17,6 +17,8 @@ import { checkCommitAttribution } from "../runtime/commit-attribution-guard";
|
|
|
17
17
|
import { gitEnvironment } from "../runtime/companion-git";
|
|
18
18
|
import { companionForkRefusal } from "../runtime/companion-sync";
|
|
19
19
|
import { readCompanionRuntimeContext } from "../runtime/env";
|
|
20
|
+
import { recordRefusal } from "../runtime/friction-recorder";
|
|
21
|
+
import type { FrictionCheck } from "../runtime/friction-fingerprint";
|
|
20
22
|
import { guardLaunchEnvironment } from "../runtime/launch-env-guard";
|
|
21
23
|
import { companionLinkPath } from "../runtime/repo-local";
|
|
22
24
|
import { checkSecretAccess, type SecretToolCall } from "../runtime/secret-guard";
|
|
@@ -26,6 +28,8 @@ import { hookFolder, type HookEnv } from "./hook-io";
|
|
|
26
28
|
export interface HookOutcome {
|
|
27
29
|
exitCode: number;
|
|
28
30
|
stderr: string;
|
|
31
|
+
/** The check that refused; set only on a refusal. */
|
|
32
|
+
check?: FrictionCheck;
|
|
29
33
|
}
|
|
30
34
|
|
|
31
35
|
const KNOWN_ARTIFACT_BASENAMES = new Set([
|
|
@@ -188,7 +192,7 @@ function blockWrite(target: string, resolved: string, ctx: GuardContext): HookOu
|
|
|
188
192
|
companion: ctx.companion,
|
|
189
193
|
repoRoot: ctx.repoRoot,
|
|
190
194
|
});
|
|
191
|
-
return { exitCode: 2, stderr: `${refusal}\n
|
|
195
|
+
return { exitCode: 2, stderr: `${refusal}\n`, check: "artifact" };
|
|
192
196
|
}
|
|
193
197
|
|
|
194
198
|
function checkFilePath(
|
|
@@ -234,7 +238,7 @@ async function checkForkedCompanion(
|
|
|
234
238
|
if (!isCompanionPath(resolveArtifactTarget(filePath, ctx.repoRoot), ctx)) return null;
|
|
235
239
|
|
|
236
240
|
const refusal = await companionForkRefusal(ctx.env, ctx.companion);
|
|
237
|
-
return refusal ? { exitCode: 2, stderr: `${refusal}\n
|
|
241
|
+
return refusal ? { exitCode: 2, stderr: `${refusal}\n`, check: "fork" } : null;
|
|
238
242
|
}
|
|
239
243
|
|
|
240
244
|
/** Heredoc bodies are what a command writes, not what it runs: they are not scanned. */
|
|
@@ -330,26 +334,72 @@ function secretToolCall(
|
|
|
330
334
|
}
|
|
331
335
|
}
|
|
332
336
|
|
|
337
|
+
interface ToolCall {
|
|
338
|
+
sessionId: string;
|
|
339
|
+
toolName: string;
|
|
340
|
+
toolInput: Record<string, unknown>;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
function toolCall(payload: unknown): ToolCall {
|
|
344
|
+
const input = payload && typeof payload === "object" ? (payload as Record<string, unknown>) : {};
|
|
345
|
+
return {
|
|
346
|
+
sessionId: typeof input.session_id === "string" ? input.session_id : "",
|
|
347
|
+
toolName: typeof input.tool_name === "string" ? input.tool_name : "",
|
|
348
|
+
toolInput:
|
|
349
|
+
input.tool_input && typeof input.tool_input === "object"
|
|
350
|
+
? (input.tool_input as Record<string, unknown>)
|
|
351
|
+
: {},
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
function recordHookRefusal(
|
|
356
|
+
check: FrictionCheck,
|
|
357
|
+
stderr: string,
|
|
358
|
+
call: ToolCall,
|
|
359
|
+
ctx: GuardContext,
|
|
360
|
+
): string | null {
|
|
361
|
+
const { toolName, toolInput } = call;
|
|
362
|
+
const command = toolName === "Bash" ? stringOrEmpty(toolInput.command) : "";
|
|
363
|
+
const paths = command
|
|
364
|
+
? commandMatches(command)
|
|
365
|
+
: [toolInput.file_path, toolInput.notebook_path, toolInput.path].map(stringOrEmpty);
|
|
366
|
+
return recordRefusal({
|
|
367
|
+
check,
|
|
368
|
+
toolKind: secretToolCall(toolName, toolInput, ctx)?.kind ?? "other",
|
|
369
|
+
message: stderr,
|
|
370
|
+
paths,
|
|
371
|
+
companionPath: ctx.companion,
|
|
372
|
+
repositoryPath: ctx.repoRoot,
|
|
373
|
+
runtime: "claude",
|
|
374
|
+
sessionId: call.sessionId,
|
|
375
|
+
env: ctx.env,
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
|
|
333
379
|
/**
|
|
334
380
|
* Fails open only when no Mate context resolves from either source; in a
|
|
335
|
-
* wrapped Working Repository the guard runs without a launch.
|
|
381
|
+
* wrapped Working Repository the guard runs without a launch. A refusal is
|
|
382
|
+
* recorded as friction after the verdict; an allowed call records nothing.
|
|
383
|
+
* A session's first refusal of a kind ends with the nudge line.
|
|
336
384
|
*/
|
|
337
385
|
export async function evaluate(
|
|
338
386
|
payload: unknown,
|
|
339
387
|
env: HookEnv,
|
|
340
388
|
cwd: string = process.cwd(),
|
|
341
389
|
): Promise<HookOutcome> {
|
|
342
|
-
const allow: HookOutcome = { exitCode: 0, stderr: "" };
|
|
343
|
-
|
|
344
390
|
const ctx = guardContext(env, cwd);
|
|
345
|
-
if (!ctx) return
|
|
391
|
+
if (!ctx) return { exitCode: 0, stderr: "" };
|
|
392
|
+
const call = toolCall(payload);
|
|
393
|
+
const outcome = await decide(call, ctx);
|
|
394
|
+
if (!outcome.check) return outcome;
|
|
395
|
+
const nudge = recordHookRefusal(outcome.check, outcome.stderr, call, ctx);
|
|
396
|
+
return nudge
|
|
397
|
+
? { ...outcome, stderr: `${outcome.stderr.replace(/\n?$/, "\n")}${nudge}\n` }
|
|
398
|
+
: outcome;
|
|
399
|
+
}
|
|
346
400
|
|
|
347
|
-
|
|
348
|
-
const
|
|
349
|
-
const toolInput =
|
|
350
|
-
input.tool_input && typeof input.tool_input === "object"
|
|
351
|
-
? (input.tool_input as Record<string, unknown>)
|
|
352
|
-
: {};
|
|
401
|
+
async function decide({ toolName, toolInput }: ToolCall, ctx: GuardContext): Promise<HookOutcome> {
|
|
402
|
+
const allow: HookOutcome = { exitCode: 0, stderr: "" };
|
|
353
403
|
|
|
354
404
|
/** Secrets first: a secret refusal wins over every artifact-placement verdict. */
|
|
355
405
|
const secretCall = secretToolCall(toolName, toolInput, ctx);
|
|
@@ -358,7 +408,7 @@ export async function evaluate(
|
|
|
358
408
|
companionPath: ctx.companion,
|
|
359
409
|
isCompanionPath: (target) => isCompanionPath(target, ctx),
|
|
360
410
|
});
|
|
361
|
-
if (refusal) return { exitCode: 2, stderr: `${refusal}\n
|
|
411
|
+
if (refusal) return { exitCode: 2, stderr: `${refusal}\n`, check: "secret" };
|
|
362
412
|
}
|
|
363
413
|
|
|
364
414
|
if (toolName === "Write" || toolName === "Edit" || toolName === "MultiEdit") {
|
|
@@ -371,7 +421,7 @@ export async function evaluate(
|
|
|
371
421
|
if (toolName === "Bash") {
|
|
372
422
|
const command = String(toolInput.command ?? "");
|
|
373
423
|
const attribution = checkCommitAttribution(command);
|
|
374
|
-
if (attribution) return { exitCode: 2, stderr: `${attribution}\n
|
|
424
|
+
if (attribution) return { exitCode: 2, stderr: `${attribution}\n`, check: "attribution" };
|
|
375
425
|
|
|
376
426
|
const targets = commandMatches(command);
|
|
377
427
|
for (const target of targets) {
|
package/src/index.ts
CHANGED
|
@@ -21,6 +21,7 @@ export {
|
|
|
21
21
|
type NormalizedRegistration,
|
|
22
22
|
} from "./tools/setup/registry";
|
|
23
23
|
export { ensureCapabilityEnabled, type EnsureCapabilityEnabledDeps } from "./cli/plugin-commands";
|
|
24
|
+
export { toolVersion } from "./lib/tool-manifest";
|
|
24
25
|
// Dynamic plugin authors: import from this package as TYPES ONLY. Runtime
|
|
25
26
|
// imports resolve a second, uninitialized copy of mate-core inside the
|
|
26
27
|
// plugin's own node_modules; all runtime behavior flows through PluginHost.
|
|
@@ -22,7 +22,14 @@ export interface ProcessResult {
|
|
|
22
22
|
export type SpawnProcess = (
|
|
23
23
|
command: string,
|
|
24
24
|
args: readonly string[],
|
|
25
|
-
options: {
|
|
25
|
+
options: {
|
|
26
|
+
cwd: string;
|
|
27
|
+
env: NodeJS.ProcessEnv;
|
|
28
|
+
input?: string;
|
|
29
|
+
timeoutMs?: number;
|
|
30
|
+
/** Kills the process once aborted; the result then counts as timed out. */
|
|
31
|
+
signal?: AbortSignal;
|
|
32
|
+
},
|
|
26
33
|
) => Promise<ProcessResult>;
|
|
27
34
|
|
|
28
35
|
export interface PatchMatch {
|
|
@@ -134,6 +141,8 @@ export interface MergeGitDeps {
|
|
|
134
141
|
containmentLimit?: number;
|
|
135
142
|
/** Wall time one containment search may take; 5 s by default. */
|
|
136
143
|
containmentBudgetMs?: number;
|
|
144
|
+
/** Once aborted, running Git commands are killed and new ones fail at once. */
|
|
145
|
+
signal?: AbortSignal;
|
|
137
146
|
}
|
|
138
147
|
|
|
139
148
|
/** Upstream commits compared by patch identity at most; more is asked instead. */
|
|
@@ -179,12 +188,20 @@ export const spawnProcess: SpawnProcess = (command, args, options) =>
|
|
|
179
188
|
env: options.env,
|
|
180
189
|
stdio: ["pipe", "pipe", "pipe"],
|
|
181
190
|
timeout: options.timeoutMs,
|
|
191
|
+
...(options.signal ? { signal: options.signal } : {}),
|
|
182
192
|
});
|
|
183
193
|
const stdout: Buffer[] = [];
|
|
184
194
|
const stderr: Buffer[] = [];
|
|
185
195
|
child.stdout.on("data", (chunk: Buffer) => stdout.push(chunk));
|
|
186
196
|
child.stderr.on("data", (chunk: Buffer) => stderr.push(chunk));
|
|
187
|
-
child.on("error", (error) =>
|
|
197
|
+
child.on("error", (error) =>
|
|
198
|
+
resolve({
|
|
199
|
+
code: -1,
|
|
200
|
+
stdout: "",
|
|
201
|
+
stderr: error.message,
|
|
202
|
+
...(options.signal?.aborted ? { timedOut: true } : {}),
|
|
203
|
+
}),
|
|
204
|
+
);
|
|
188
205
|
child.on("close", (code, signal) =>
|
|
189
206
|
resolve({
|
|
190
207
|
code: code ?? -1,
|
|
@@ -229,7 +246,10 @@ export function localGitEnv(env: NodeJS.ProcessEnv = process.env): NodeJS.Proces
|
|
|
229
246
|
}
|
|
230
247
|
|
|
231
248
|
export function mergeGit(repoPath: string, deps: MergeGitDeps = {}): MergeGit {
|
|
232
|
-
const
|
|
249
|
+
const baseSpawn = deps.spawn ?? spawnProcess;
|
|
250
|
+
const spawnFn: SpawnProcess = deps.signal
|
|
251
|
+
? (command, args, options) => baseSpawn(command, args, { ...options, signal: deps.signal })
|
|
252
|
+
: baseSpawn;
|
|
233
253
|
const base = gitEnvironment(deps.env ?? process.env) as NodeJS.ProcessEnv;
|
|
234
254
|
const promptless = promptlessEnv(base);
|
|
235
255
|
const localEnv: NodeJS.ProcessEnv = { ...promptless, GIT_NO_LAZY_FETCH: "1" };
|
|
@@ -247,10 +267,14 @@ export function mergeGit(repoPath: string, deps: MergeGitDeps = {}): MergeGit {
|
|
|
247
267
|
(await value("config", "--get", "extensions.partialClone")) !== null;
|
|
248
268
|
|
|
249
269
|
const supportsContainment = (): Promise<boolean> => {
|
|
250
|
-
let known = containmentSupport.get(
|
|
270
|
+
let known = containmentSupport.get(baseSpawn);
|
|
251
271
|
if (!known) {
|
|
252
|
-
known = git(["version"]).then((result) =>
|
|
253
|
-
|
|
272
|
+
known = git(["version"]).then((result) => {
|
|
273
|
+
// A killed probe proves nothing about this Git.
|
|
274
|
+
if (result.timedOut) containmentSupport.delete(baseSpawn);
|
|
275
|
+
return result.code === 0 && hasWriteTree(result.stdout);
|
|
276
|
+
});
|
|
277
|
+
containmentSupport.set(baseSpawn, known);
|
|
254
278
|
}
|
|
255
279
|
return known;
|
|
256
280
|
};
|
|
@@ -392,7 +416,7 @@ export function mergeGit(repoPath: string, deps: MergeGitDeps = {}): MergeGit {
|
|
|
392
416
|
if (!(await supportsContainment())) return "unknown";
|
|
393
417
|
const upstream = remoteRef(defaultBranch);
|
|
394
418
|
const tip = await verify(upstream);
|
|
395
|
-
const notContained = notContainedMemo(
|
|
419
|
+
const notContained = notContainedMemo(baseSpawn);
|
|
396
420
|
const key = `${repoPath}\0${head}\0${tip}`;
|
|
397
421
|
// Unchanged head and default tip: a repeated refresh does not test every candidate again.
|
|
398
422
|
if (tip && notContained.has(key)) return "none";
|
|
@@ -44,13 +44,26 @@ export type CountedWarning = {
|
|
|
44
44
|
message: string;
|
|
45
45
|
};
|
|
46
46
|
|
|
47
|
+
/**
|
|
48
|
+
* - `preflight-skipped`: submit could not archive the change's Delivery Group as publication
|
|
49
|
+
* would, or only against the last fetched refs
|
|
50
|
+
* - `preflight-blocked`: publication will block the group on the stale delta of `change` until it
|
|
51
|
+
* is resolved on the pending branch
|
|
52
|
+
*/
|
|
53
|
+
export type PreflightWarning = {
|
|
54
|
+
kind: "preflight-skipped" | "preflight-blocked";
|
|
55
|
+
change: string;
|
|
56
|
+
message: string;
|
|
57
|
+
};
|
|
58
|
+
|
|
47
59
|
export type SubmitWarning =
|
|
48
60
|
| { kind: "overlap"; change: string; capability: string; requirement: string; message: string }
|
|
49
61
|
| DependencyWarning
|
|
50
62
|
| PlanningWarning
|
|
51
63
|
| GroupWarning
|
|
52
64
|
| StageWarning
|
|
53
|
-
| CountedWarning
|
|
65
|
+
| CountedWarning
|
|
66
|
+
| PreflightWarning;
|
|
54
67
|
|
|
55
68
|
const SECTION = /^##\s+(ADDED|MODIFIED|REMOVED|RENAMED)\s+Requirements\s*$/;
|
|
56
69
|
const REQUIREMENT = /^###\s+Requirement:\s*(.+?)\s*$/;
|
|
@@ -22,11 +22,16 @@ export interface Checkout {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
export interface RepositoryAccessDeps {
|
|
25
|
-
openCheckout?: (path: string) => Checkout;
|
|
25
|
+
openCheckout?: (path: string, signal?: AbortSignal) => Checkout;
|
|
26
|
+
/** Once aborted, the checkouts' merge queries and fetches are killed. */
|
|
27
|
+
signal?: AbortSignal;
|
|
26
28
|
}
|
|
27
29
|
|
|
28
|
-
function defaultOpenCheckout(path: string): Checkout {
|
|
29
|
-
return {
|
|
30
|
+
function defaultOpenCheckout(path: string, signal?: AbortSignal): Checkout {
|
|
31
|
+
return {
|
|
32
|
+
git: mergeGit(path, signal ? { signal } : {}),
|
|
33
|
+
defaultBranch: () => workingRepoGit(path).defaultBranch(),
|
|
34
|
+
};
|
|
30
35
|
}
|
|
31
36
|
|
|
32
37
|
/**
|
|
@@ -48,7 +53,7 @@ export function repositoryAccessFor(
|
|
|
48
53
|
const working = slug && sameRepository(slug, repository) ? environment.workingRepo : null;
|
|
49
54
|
let localAccess: Promise<LocalMergeAccess | null> | undefined;
|
|
50
55
|
const local = (): Promise<LocalMergeAccess | null> =>
|
|
51
|
-
(localAccess ??= openLocal(environment, repository, deps
|
|
56
|
+
(localAccess ??= openLocal(environment, repository, deps));
|
|
52
57
|
let otherDefault: Promise<string> | undefined;
|
|
53
58
|
const defaultBranch = working
|
|
54
59
|
? () => working.git.defaultBranch()
|
|
@@ -72,11 +77,11 @@ export function repositoryAccessFor(
|
|
|
72
77
|
async function openLocal(
|
|
73
78
|
environment: DeliveryEnvironment,
|
|
74
79
|
repository: string,
|
|
75
|
-
|
|
80
|
+
deps: RepositoryAccessDeps,
|
|
76
81
|
): Promise<LocalMergeAccess | null> {
|
|
77
82
|
const path = await environment.checkoutOf?.(repository);
|
|
78
83
|
if (!path) return null;
|
|
79
|
-
const checkout = (
|
|
84
|
+
const checkout = (deps.openCheckout ?? defaultOpenCheckout)(path, deps.signal);
|
|
80
85
|
if (!(await checkout.git.isRepository())) return null;
|
|
81
86
|
const defaultBranch = await checkout.defaultBranch();
|
|
82
87
|
const fetched = new Map<string, Promise<FetchResult>>();
|
|
@@ -127,9 +127,11 @@ export function describeFailure(failure: ChainFailure, defaultBranch: string): s
|
|
|
127
127
|
if (failure.kind === "stale") {
|
|
128
128
|
return `${change}: "${inboxText(failure.failure.requirement)}" in ${inboxText(failure.failure.capability)} changed on ${defaultBranch} since the delta was written`;
|
|
129
129
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
130
|
+
if (!failure.failure) {
|
|
131
|
+
return `${change}: it no longer applies to ${defaultBranch} (${inboxText(failure.detail)})`;
|
|
132
|
+
}
|
|
133
|
+
const { capability, requirement, reason } = failure.failure;
|
|
134
|
+
return `${change}: its ${inboxText(capability)} delta for "${inboxText(requirement)}" no longer applies to ${defaultBranch}${reason ? ` (${inboxText(reason)})` : ""}`;
|
|
133
135
|
}
|
|
134
136
|
|
|
135
137
|
/** `value` as one POSIX shell word: names come from teammates' specs. */
|
|
@@ -137,8 +139,16 @@ function shellQuote(value: string): string {
|
|
|
137
139
|
return `'${value.replaceAll("'", `'\\''`)}'`;
|
|
138
140
|
}
|
|
139
141
|
|
|
140
|
-
/**
|
|
141
|
-
|
|
142
|
+
/** `mate artifact submit` for `names`, each quoted as one shell word. */
|
|
143
|
+
function submitCommand(names: readonly string[]): string {
|
|
144
|
+
return `\`mate artifact submit${names.map((name) => ` ${shellQuote(name)}`).join("")}\``;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* How to get past a failure. With `resubmit`, the changes a submit named, the remedy ends with
|
|
149
|
+
* submitting them again instead of publishing: submit's pre-flight found the failure.
|
|
150
|
+
*/
|
|
151
|
+
export function failureRemedy(failure: ChainFailure, resubmit?: readonly string[]): string {
|
|
142
152
|
const versions = failure.kind === "stale" ? failure.failure.versions : undefined;
|
|
143
153
|
// A name that does not print as it is cannot be passed on a command line.
|
|
144
154
|
const printable =
|
|
@@ -153,12 +163,20 @@ export function failureRemedy(failure: ChainFailure): string {
|
|
|
153
163
|
versions.ours !== null &&
|
|
154
164
|
versions.theirs !== null
|
|
155
165
|
) {
|
|
156
|
-
|
|
166
|
+
const next = resubmit ? `run ${submitCommand(resubmit)} again` : "publish again";
|
|
167
|
+
return `Resolve it from any machine: write the requirement's body as it should read (without its \`### Requirement:\` heading) to a file, run \`mate artifact resolve ${shellQuote(failure.change)} --capability ${shellQuote(failure.failure.capability)} --requirement ${shellQuote(failure.failure.requirement)} --file <file>\` (one triple per requirement it reports unresolved), then ${next}.`;
|
|
157
168
|
}
|
|
158
169
|
const change = failure.change === null ? "the change that changes it" : inboxText(failure.change);
|
|
159
170
|
const keep =
|
|
160
171
|
failure.kind === "stale" && failure.failure.overwrites === false && versions?.ours === null
|
|
161
172
|
? " To keep it as it is, submit it again unchanged: that accepts the conflict."
|
|
162
173
|
: "";
|
|
163
|
-
|
|
174
|
+
// Submitting the fixed change runs the pre-flight again; only other named changes need a rerun.
|
|
175
|
+
const others = resubmit?.filter((name) => name !== failure.change) ?? [];
|
|
176
|
+
const next = !resubmit
|
|
177
|
+
? ", then publish again"
|
|
178
|
+
: others.length > 0
|
|
179
|
+
? `, then run ${submitCommand(others)} again`
|
|
180
|
+
: "";
|
|
181
|
+
return `Fix the delta spec of ${change}, submit it again with \`mate artifact submit\`${next}.${keep}`;
|
|
164
182
|
}
|