@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
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import fs from "node:fs/promises";
|
|
2
2
|
|
|
3
|
+
import { currentSession } from "../runtime/session-id";
|
|
3
4
|
import {
|
|
4
5
|
patchSession,
|
|
5
6
|
type RegisteredSession,
|
|
@@ -12,15 +13,10 @@ import {
|
|
|
12
13
|
* agent session, or for an unregistered id, nothing changes. Never throws.
|
|
13
14
|
*/
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
const SESSION_ID_VARIABLES = ["CLAUDE_CODE_SESSION_ID", "OPENCODE_SESSION_ID"] as const;
|
|
16
|
+
export { currentSession };
|
|
17
17
|
|
|
18
18
|
export function currentSessionId(env: Record<string, string | undefined>): string | null {
|
|
19
|
-
|
|
20
|
-
const value = env[name]?.trim();
|
|
21
|
-
if (value) return value;
|
|
22
|
-
}
|
|
23
|
-
return null;
|
|
19
|
+
return currentSession(env)?.id ?? null;
|
|
24
20
|
}
|
|
25
21
|
|
|
26
22
|
export interface Attribution {
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
|
|
5
|
+
import { runCommand } from "../tools/setup/utils";
|
|
6
|
+
import { bundledCliCommand } from "./openspec-cli";
|
|
7
|
+
|
|
8
|
+
const require = createRequire(import.meta.url);
|
|
9
|
+
const MISSING = "the skills CLI that Mate pins is missing. Reinstall Mate to restore it.";
|
|
10
|
+
|
|
11
|
+
export type SkillsCliLocation = { bin: string; version: string } | { missing: string };
|
|
12
|
+
|
|
13
|
+
function resolveSkillsCli(): SkillsCliLocation {
|
|
14
|
+
try {
|
|
15
|
+
const manifestPath = require.resolve("skills/package.json");
|
|
16
|
+
const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8")) as {
|
|
17
|
+
version?: string;
|
|
18
|
+
bin?: Record<string, string>;
|
|
19
|
+
};
|
|
20
|
+
if (!manifest.version || !manifest.bin?.skills) return { missing: MISSING };
|
|
21
|
+
const bin = path.resolve(path.dirname(manifestPath), manifest.bin.skills);
|
|
22
|
+
return fs.existsSync(bin) ? { bin, version: manifest.version } : { missing: MISSING };
|
|
23
|
+
} catch {
|
|
24
|
+
return { missing: MISSING };
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const skillsCliDeps = {
|
|
29
|
+
locate: resolveSkillsCli,
|
|
30
|
+
run: runCommand,
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export function runSkillsCli(args: string[], cwd: string): Promise<void> {
|
|
34
|
+
const location = skillsCliDeps.locate();
|
|
35
|
+
if ("missing" in location) return Promise.reject(new Error(location.missing));
|
|
36
|
+
const [command, commandArgs] = bundledCliCommand(location.bin, args);
|
|
37
|
+
return skillsCliDeps.run(command, commandArgs, { cwd });
|
|
38
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
import semver from "semver";
|
|
5
|
+
import { parse } from "yaml";
|
|
6
|
+
|
|
7
|
+
import { mateVersion } from "../runtime/install";
|
|
8
|
+
|
|
9
|
+
const TOOL_MANIFEST_FILE = path.resolve(import.meta.dirname, "../../tool-manifest.yaml");
|
|
10
|
+
|
|
11
|
+
interface ToolManifest {
|
|
12
|
+
schema: number;
|
|
13
|
+
tools: Record<string, { version: string } & Record<string, unknown>>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
let cached: ToolManifest | undefined;
|
|
17
|
+
|
|
18
|
+
export function readToolManifest(): ToolManifest {
|
|
19
|
+
cached ??= parse(fs.readFileSync(TOOL_MANIFEST_FILE, "utf8")) as ToolManifest;
|
|
20
|
+
return cached;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** The exact version Mate pins for `name`; throws for a tool the manifest does not name. */
|
|
24
|
+
export function toolVersion(name: string): string {
|
|
25
|
+
const version = readToolManifest().tools?.[name]?.version;
|
|
26
|
+
if (!version) throw new Error(`tool manifest names no version for ${name}`);
|
|
27
|
+
return version;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
let heldNotices: string[] | undefined;
|
|
31
|
+
|
|
32
|
+
/** Writes a tool notice to stderr, or holds it while {@link holdToolNotices} is in effect. */
|
|
33
|
+
export function toolNotice(line: string): void {
|
|
34
|
+
if (heldNotices) heldNotices.push(line);
|
|
35
|
+
else process.stderr.write(line);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Holds tool notices until the returned function runs: a write under a live Ink view
|
|
40
|
+
* garbles its frames. Call that function once the view is unmounted.
|
|
41
|
+
*/
|
|
42
|
+
export function holdToolNotices(): () => void {
|
|
43
|
+
heldNotices ??= [];
|
|
44
|
+
return () => {
|
|
45
|
+
const lines = heldNotices ?? [];
|
|
46
|
+
heldNotices = undefined;
|
|
47
|
+
for (const line of lines) process.stderr.write(line);
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Warns when a readable installed version differs from the pin, older or newer:
|
|
53
|
+
* Mate reviewed only the pinned one. Never throws (install-contract `update`).
|
|
54
|
+
* `binary` is the installed file: the warning names it, because `command` may install elsewhere.
|
|
55
|
+
*/
|
|
56
|
+
export function warnOnVersionDrift(
|
|
57
|
+
tool: string,
|
|
58
|
+
installed: string | null | undefined,
|
|
59
|
+
command: string,
|
|
60
|
+
binary?: string | null,
|
|
61
|
+
): void {
|
|
62
|
+
const parsed = installed
|
|
63
|
+
? semver.valid(semver.coerce(installed, { includePrerelease: true }))
|
|
64
|
+
: null;
|
|
65
|
+
const pinned = toolVersion(tool);
|
|
66
|
+
if (!parsed || parsed === pinned) return;
|
|
67
|
+
toolNotice(
|
|
68
|
+
`${tool} ${parsed} is installed${binary ? ` at ${binary}` : ""}; Mate ${mateVersion()} pins ${pinned}. Install it with: ${command}\n` +
|
|
69
|
+
(binary
|
|
70
|
+
? ` The first ${tool} on PATH wins: if the pinned one installs elsewhere, remove ${binary} or put the new directory first.\n`
|
|
71
|
+
: ""),
|
|
72
|
+
);
|
|
73
|
+
}
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
|
|
5
|
+
import { FRAMEWORK_NAME } from "../../framework";
|
|
6
|
+
import {
|
|
7
|
+
companionFilter,
|
|
8
|
+
findReports,
|
|
9
|
+
readFriction,
|
|
10
|
+
type FrictionEvent,
|
|
11
|
+
type FrictionReport,
|
|
12
|
+
} from "../../runtime/friction-log";
|
|
13
|
+
import { formatCommand } from "../../runtime/command-arg";
|
|
14
|
+
import { scanContent } from "../../runtime/secret-scan";
|
|
15
|
+
import { FrictionRefusal } from "../friction/fields";
|
|
16
|
+
import type { FrictionTarget } from "../friction/mark";
|
|
17
|
+
import { joinFrictionStates } from "../friction/view/read";
|
|
18
|
+
import { TRIAGE_AGENT_NAMES, TRIAGE_AGENTS, type FoundAgent } from "./launch";
|
|
19
|
+
|
|
20
|
+
const FRICTION_SNAPSHOT_DAYS = 30;
|
|
21
|
+
const FRICTION_EVENTS_FILE = "friction-events.jsonl";
|
|
22
|
+
const FRICTION_REPORTS_FILE = "friction-reports.jsonl";
|
|
23
|
+
const FRICTION_STATES_FILE = "friction-states.json";
|
|
24
|
+
|
|
25
|
+
interface FrictionSnapshot {
|
|
26
|
+
/** The companion the records were scoped to; none means nothing was copied. */
|
|
27
|
+
companion: string | null;
|
|
28
|
+
/** The current folder's companion, when the snapshot's is another. */
|
|
29
|
+
mismatch?: { current: string | null };
|
|
30
|
+
target?: FrictionTarget;
|
|
31
|
+
/** Friction Events of a fingerprint target in other companions; they are not copied. */
|
|
32
|
+
elsewhere?: { companion: string; events: number }[];
|
|
33
|
+
events: number;
|
|
34
|
+
reports: number;
|
|
35
|
+
/** Copied fingerprints and Free Reports that have a Friction State. */
|
|
36
|
+
states: number;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** The target's companions, one entry per real path, with their record counts. */
|
|
40
|
+
function companionCounts(target: FrictionTarget): { companion: string; events: number }[] {
|
|
41
|
+
const raw = new Map<string, number>();
|
|
42
|
+
const companions =
|
|
43
|
+
target.kind === "report"
|
|
44
|
+
? [target.report.companion]
|
|
45
|
+
: target.events.map((event) => event.companion);
|
|
46
|
+
for (const companion of companions) raw.set(companion, (raw.get(companion) ?? 0) + 1);
|
|
47
|
+
const counts: { companion: string; events: number }[] = [];
|
|
48
|
+
for (const [companion, events] of raw) {
|
|
49
|
+
const same = companionFilter(companion);
|
|
50
|
+
const entry = counts.find((other) => same(other.companion));
|
|
51
|
+
if (entry) entry.events += events;
|
|
52
|
+
else counts.push({ companion, events });
|
|
53
|
+
}
|
|
54
|
+
return counts;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The snapshot's companion: the current folder's when it holds the target, else the target's only
|
|
59
|
+
* companion. Throws a `FrictionRefusal` when several other companions hold it.
|
|
60
|
+
*/
|
|
61
|
+
export function chooseSnapshotCompanion(
|
|
62
|
+
current: string | null,
|
|
63
|
+
target: FrictionTarget | undefined,
|
|
64
|
+
): string | null {
|
|
65
|
+
if (!target) return current;
|
|
66
|
+
const companions = companionCounts(target).map((entry) => entry.companion);
|
|
67
|
+
if (current && companions.some(companionFilter(current))) return current;
|
|
68
|
+
if (companions.length === 1) return companions[0]!;
|
|
69
|
+
throw new FrictionRefusal(
|
|
70
|
+
"several-companions",
|
|
71
|
+
`${target.id} is recorded in several companions: ${companions.join(", ")}. Run this command again in a repository of one of them; nothing was written.`,
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function targetRecords(
|
|
76
|
+
target: FrictionTarget,
|
|
77
|
+
companion: string,
|
|
78
|
+
homeDir?: string,
|
|
79
|
+
): { events: FrictionEvent[]; reports: FrictionReport[] } {
|
|
80
|
+
// chooseSnapshotCompanion picked a companion that holds a report target.
|
|
81
|
+
if (target.kind === "report") return { events: [], reports: [target.report] };
|
|
82
|
+
const inCompanion = companionFilter(companion);
|
|
83
|
+
const events = target.events.filter((event) => inCompanion(event.companion));
|
|
84
|
+
const ids = new Set(events.map((event) => event.id));
|
|
85
|
+
const reports = findReports((report) => report.eventId !== null && ids.has(report.eventId), {
|
|
86
|
+
homeDir,
|
|
87
|
+
});
|
|
88
|
+
return { events, reports };
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function eventsElsewhere(
|
|
92
|
+
target: FrictionTarget | undefined,
|
|
93
|
+
companion: string,
|
|
94
|
+
): { companion: string; events: number }[] {
|
|
95
|
+
if (target?.kind !== "fingerprint") return [];
|
|
96
|
+
const inCompanion = companionFilter(companion);
|
|
97
|
+
return companionCounts(target).filter((entry) => !inCompanion(entry.companion));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function mergeById<T extends { id: string; at: string }>(base: T[], extra: T[]): T[] {
|
|
101
|
+
const seen = new Set(base.map((record) => record.id));
|
|
102
|
+
const added = extra.filter((record) => !seen.has(record.id));
|
|
103
|
+
return added.length === 0
|
|
104
|
+
? base
|
|
105
|
+
: [...base, ...added].toSorted((a, b) => (a.at < b.at ? -1 : a.at > b.at ? 1 : 0));
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const EVIDENCE_FIELDS = ["message", "command", "errorText", "paths", "flags"] as const;
|
|
109
|
+
|
|
110
|
+
async function withoutFlaggedEvidence(
|
|
111
|
+
events: FrictionEvent[],
|
|
112
|
+
scan: typeof scanContent,
|
|
113
|
+
): Promise<FrictionEvent[]> {
|
|
114
|
+
const lines = events.map((event) => JSON.stringify(event));
|
|
115
|
+
let flagged: Map<number, string[]> | null = new Map();
|
|
116
|
+
try {
|
|
117
|
+
for (const finding of await scan(FRICTION_EVENTS_FILE, lines.join("\n"))) {
|
|
118
|
+
const index = finding.line - 1;
|
|
119
|
+
flagged.set(index, [...(flagged.get(index) ?? []), finding.ruleId]);
|
|
120
|
+
}
|
|
121
|
+
} catch {
|
|
122
|
+
flagged = null;
|
|
123
|
+
}
|
|
124
|
+
return events.map((event, index) => {
|
|
125
|
+
const rules = flagged ? flagged.get(index) : ["scan-failed"];
|
|
126
|
+
if (!rules) return event;
|
|
127
|
+
const detail = { ...event.detail };
|
|
128
|
+
for (const field of EVIDENCE_FIELDS) {
|
|
129
|
+
if (field in detail) detail[field] = `[withheld: ${[...new Set(rules)].join(", ")}]`;
|
|
130
|
+
}
|
|
131
|
+
return { ...event, detail };
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Copies the companion's records of the window into the session; a family without records gets
|
|
137
|
+
* no file. Only that companion's: the copy feeds a public issue draft.
|
|
138
|
+
*/
|
|
139
|
+
export async function writeFrictionSnapshot(
|
|
140
|
+
sessionDir: string,
|
|
141
|
+
options: {
|
|
142
|
+
companion: string | null;
|
|
143
|
+
/** The current folder's companion; a target may choose another one. */
|
|
144
|
+
current?: string | null;
|
|
145
|
+
target?: FrictionTarget;
|
|
146
|
+
homeDir?: string;
|
|
147
|
+
now?: Date;
|
|
148
|
+
scan?: typeof scanContent;
|
|
149
|
+
},
|
|
150
|
+
): Promise<FrictionSnapshot> {
|
|
151
|
+
const { companion, target, current = null, homeDir } = options;
|
|
152
|
+
if (!companion) return { companion: null, events: 0, reports: 0, states: 0 };
|
|
153
|
+
const elsewhere = eventsElsewhere(target, companion);
|
|
154
|
+
const facts = {
|
|
155
|
+
companion,
|
|
156
|
+
...(target ? { target } : {}),
|
|
157
|
+
...(elsewhere.length > 0 ? { elsewhere } : {}),
|
|
158
|
+
...(target && !(current && companionFilter(companion)(current))
|
|
159
|
+
? { mismatch: { current } }
|
|
160
|
+
: {}),
|
|
161
|
+
};
|
|
162
|
+
const recent = readFriction(
|
|
163
|
+
{ companion },
|
|
164
|
+
{ sinceDays: FRICTION_SNAPSHOT_DAYS, homeDir, now: options.now },
|
|
165
|
+
);
|
|
166
|
+
const own = target ? targetRecords(target, companion, homeDir) : { events: [], reports: [] };
|
|
167
|
+
const {
|
|
168
|
+
events: recorded,
|
|
169
|
+
reports,
|
|
170
|
+
states,
|
|
171
|
+
} = joinFrictionStates(
|
|
172
|
+
mergeById(recent.events, own.events),
|
|
173
|
+
mergeById(recent.reports, own.reports),
|
|
174
|
+
homeDir,
|
|
175
|
+
);
|
|
176
|
+
const events = await withoutFlaggedEvidence(recorded, options.scan ?? scanContent);
|
|
177
|
+
const write = (name: string, records: object[]) => {
|
|
178
|
+
if (records.length === 0) return;
|
|
179
|
+
const lines = records.map((record) => `${JSON.stringify(record)}\n`).join("");
|
|
180
|
+
fs.writeFileSync(path.join(sessionDir, name), lines, "utf8");
|
|
181
|
+
};
|
|
182
|
+
write(FRICTION_EVENTS_FILE, events);
|
|
183
|
+
write(FRICTION_REPORTS_FILE, reports);
|
|
184
|
+
if (events.length === 0 && reports.length === 0) {
|
|
185
|
+
return { ...facts, events: 0, reports: 0, states: 0 };
|
|
186
|
+
}
|
|
187
|
+
fs.writeFileSync(
|
|
188
|
+
path.join(sessionDir, FRICTION_STATES_FILE),
|
|
189
|
+
`${JSON.stringify({ v: 1, ...states }, null, 2)}\n`,
|
|
190
|
+
"utf8",
|
|
191
|
+
);
|
|
192
|
+
return {
|
|
193
|
+
...facts,
|
|
194
|
+
events: events.length,
|
|
195
|
+
reports: reports.length,
|
|
196
|
+
states: Object.keys(states.fingerprints).length + Object.keys(states.reports).length,
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
interface TriageContextInput {
|
|
201
|
+
now: Date;
|
|
202
|
+
version: string;
|
|
203
|
+
argv: string[];
|
|
204
|
+
cwd: string;
|
|
205
|
+
sessionDir: string;
|
|
206
|
+
issueRepository: string | undefined;
|
|
207
|
+
agents: FoundAgent[];
|
|
208
|
+
friction: FrictionSnapshot;
|
|
209
|
+
doctor: { report: unknown } | { error: string };
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function runtimeVersion(): string {
|
|
213
|
+
return process.versions.bun ? `Bun ${process.versions.bun}` : `Node.js ${process.versions.node}`;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function agentLines(agents: FoundAgent[]): string[] {
|
|
217
|
+
return TRIAGE_AGENTS.map((id) => {
|
|
218
|
+
const found = agents.find((agent) => agent.agent === id);
|
|
219
|
+
if (!found) return `- ${TRIAGE_AGENT_NAMES[id]} (\`${id}\`): not found`;
|
|
220
|
+
return `- ${TRIAGE_AGENT_NAMES[id]} (\`${id}\`): ${found.version ?? "version unknown"}, at ${found.binary}`;
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function count(n: number, noun: string): string {
|
|
225
|
+
return `${n} ${noun}${n === 1 ? "" : "s"}`;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function targetLines(friction: FrictionSnapshot): string[] {
|
|
229
|
+
const { target, mismatch, elsewhere } = friction;
|
|
230
|
+
if (!target) return [];
|
|
231
|
+
const kind = target.kind === "fingerprint" ? "a fingerprint" : "a Free Report";
|
|
232
|
+
const lines = [`Triage Target: \`${target.id}\`, ${kind}. Start from it.`, ""];
|
|
233
|
+
if (mismatch) {
|
|
234
|
+
const current = mismatch.current ? `companion ${mismatch.current}` : "no companion";
|
|
235
|
+
lines.push(
|
|
236
|
+
`The snapshot holds the friction of companion ${friction.companion}, which holds the Triage Target. The folder the command ran in belongs to ${current}; the doctor report describes that folder.`,
|
|
237
|
+
"",
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
if (elsewhere) {
|
|
241
|
+
const list = elsewhere.map((other) => `${other.companion} (${other.events})`).join(", ");
|
|
242
|
+
lines.push(
|
|
243
|
+
`The Triage Target also has Friction Events in other companions, not copied here: ${list}.`,
|
|
244
|
+
"",
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
return lines;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function frictionLines(friction: FrictionSnapshot): string[] {
|
|
251
|
+
if (!friction.companion) {
|
|
252
|
+
return [
|
|
253
|
+
`No friction was copied: this folder belongs to no companion. To include it, run \`${FRAMEWORK_NAME} triage\` in the affected repository.`,
|
|
254
|
+
];
|
|
255
|
+
}
|
|
256
|
+
const lines = targetLines(friction);
|
|
257
|
+
if (friction.events === 0 && friction.reports === 0) {
|
|
258
|
+
return [
|
|
259
|
+
...lines,
|
|
260
|
+
`No friction was recorded for ${friction.companion} in the last ${FRICTION_SNAPSHOT_DAYS} days.`,
|
|
261
|
+
];
|
|
262
|
+
}
|
|
263
|
+
const older = friction.target ? ", plus the Triage Target's own records whatever their age" : "";
|
|
264
|
+
lines.push(
|
|
265
|
+
`Records for ${friction.companion} from the last ${FRICTION_SNAPSHOT_DAYS} days${older}, one JSON object per line:`,
|
|
266
|
+
);
|
|
267
|
+
if (friction.events > 0) {
|
|
268
|
+
lines.push(`- \`${FRICTION_EVENTS_FILE}\`: ${count(friction.events, "Friction Event")}`);
|
|
269
|
+
}
|
|
270
|
+
if (friction.reports > 0) {
|
|
271
|
+
lines.push(`- \`${FRICTION_REPORTS_FILE}\`: ${count(friction.reports, "agent report")}`);
|
|
272
|
+
}
|
|
273
|
+
lines.push(
|
|
274
|
+
`- \`${FRICTION_STATES_FILE}\`: ${count(friction.states, "Friction State")}, by fingerprint and Free Report id; an item without one is open`,
|
|
275
|
+
);
|
|
276
|
+
return lines;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/** Holds no environment value: the doctor report and the facts below carry none. */
|
|
280
|
+
export function renderTriageContext(input: TriageContextInput): string {
|
|
281
|
+
const doctor =
|
|
282
|
+
"report" in input.doctor
|
|
283
|
+
? ["```json", JSON.stringify(input.doctor.report, null, 2), "```"]
|
|
284
|
+
: [`The doctor report could not be built: ${input.doctor.error}`];
|
|
285
|
+
return [
|
|
286
|
+
`# ${FRAMEWORK_NAME} triage context`,
|
|
287
|
+
"",
|
|
288
|
+
`- Written: ${input.now.toISOString()}`,
|
|
289
|
+
`- ${FRAMEWORK_NAME} version: ${input.version}`,
|
|
290
|
+
`- Invoked as: \`${formatCommand([FRAMEWORK_NAME, "triage", ...input.argv])}\``,
|
|
291
|
+
`- Executable: ${process.execPath}`,
|
|
292
|
+
`- Entry point: ${process.argv[1] ?? "unknown"}`,
|
|
293
|
+
`- Operating system: ${os.type()} ${os.release()} (${process.platform}, ${process.arch})`,
|
|
294
|
+
`- JavaScript runtime: ${runtimeVersion()}`,
|
|
295
|
+
`- Folder the command ran in: ${input.cwd}`,
|
|
296
|
+
`- Triage session: ${input.sessionDir}`,
|
|
297
|
+
`- Issue repository: ${input.issueRepository ?? "none set"}`,
|
|
298
|
+
"",
|
|
299
|
+
"## Agent Runtimes",
|
|
300
|
+
"",
|
|
301
|
+
...agentLines(input.agents),
|
|
302
|
+
"",
|
|
303
|
+
"## Friction",
|
|
304
|
+
"",
|
|
305
|
+
...frictionLines(input.friction),
|
|
306
|
+
"",
|
|
307
|
+
`## Doctor report for ${input.cwd}`,
|
|
308
|
+
"",
|
|
309
|
+
...doctor,
|
|
310
|
+
"",
|
|
311
|
+
].join("\n");
|
|
312
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
2
|
+
|
|
3
|
+
import { resolveCommandOnPath } from "../../tools/setup/utils";
|
|
4
|
+
import { withoutMateWrapperDirs } from "../package-paths";
|
|
5
|
+
|
|
6
|
+
export const TRIAGE_AGENTS = ["claude", "opencode"] as const;
|
|
7
|
+
export type TriageAgent = (typeof TRIAGE_AGENTS)[number];
|
|
8
|
+
|
|
9
|
+
export const TRIAGE_AGENT_NAMES: Record<TriageAgent, string> = {
|
|
10
|
+
claude: "Claude Code",
|
|
11
|
+
opencode: "OpenCode",
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export interface FoundAgent {
|
|
15
|
+
agent: TriageAgent;
|
|
16
|
+
binary: string;
|
|
17
|
+
/** First line of `--version`, or null when it fails. */
|
|
18
|
+
version: string | null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function probeVersion(binary: string): string | null {
|
|
22
|
+
const result = spawnSync(binary, ["--version"], { encoding: "utf8", timeout: 5_000 });
|
|
23
|
+
if (result.status !== 0) return null;
|
|
24
|
+
return result.stdout.trim().split("\n")[0]?.trim() || null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function findAgents(pathValue: string): FoundAgent[] {
|
|
28
|
+
const searchPath = withoutMateWrapperDirs(pathValue);
|
|
29
|
+
return TRIAGE_AGENTS.flatMap((agent) => {
|
|
30
|
+
const binary = resolveCommandOnPath(agent, searchPath);
|
|
31
|
+
return binary ? [{ agent, binary, version: probeVersion(binary) }] : [];
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Verified against Claude Code 2.1 (`claude [prompt]`) and OpenCode 2.2 (`opencode --prompt`). */
|
|
36
|
+
function agentArgs(agent: TriageAgent, prompt: string): string[] {
|
|
37
|
+
return agent === "claude" ? [prompt] : ["--prompt", prompt];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Starts the agent's own CLI, never a Mate launch: triage must work when that launch is broken. */
|
|
41
|
+
export function launchAgent(
|
|
42
|
+
options: Pick<FoundAgent, "agent" | "binary"> & { sessionDir: string; prompt: string },
|
|
43
|
+
): Promise<number> {
|
|
44
|
+
return new Promise((resolve, reject) => {
|
|
45
|
+
const child = spawn(options.binary, agentArgs(options.agent, options.prompt), {
|
|
46
|
+
cwd: options.sessionDir,
|
|
47
|
+
stdio: "inherit",
|
|
48
|
+
});
|
|
49
|
+
child.on("error", reject);
|
|
50
|
+
child.on("close", (code, signal) => resolve(code ?? (signal ? 1 : 0)));
|
|
51
|
+
});
|
|
52
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
import { getActiveDistribution } from "../../distribution";
|
|
5
|
+
import { FRAMEWORK_NAME } from "../../framework";
|
|
6
|
+
import { errorMessage } from "../../runtime/error-message";
|
|
7
|
+
import { getTriagePlaybookPath } from "../package-paths";
|
|
8
|
+
import { maskSecretValues } from "../../runtime/secret-values";
|
|
9
|
+
import { lookupFrictionTarget } from "../friction/mark";
|
|
10
|
+
import { chooseSnapshotCompanion, renderTriageContext, writeFrictionSnapshot } from "./context";
|
|
11
|
+
import { findAgents, type FoundAgent } from "./launch";
|
|
12
|
+
import { createTriageSession } from "./session";
|
|
13
|
+
|
|
14
|
+
export interface TriageSessionFiles {
|
|
15
|
+
dir: string;
|
|
16
|
+
context: string;
|
|
17
|
+
playbook: string;
|
|
18
|
+
prompt: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface PrepareTriageOptions {
|
|
22
|
+
argv: string[];
|
|
23
|
+
cwd: string;
|
|
24
|
+
homeDir: string | undefined;
|
|
25
|
+
now: Date;
|
|
26
|
+
pathValue: string;
|
|
27
|
+
env: Record<string, string | undefined>;
|
|
28
|
+
/** Builds the doctor report for `cwd`; a throw is recorded in place of the report. */
|
|
29
|
+
collectDoctor: (cwd: string) => Promise<unknown>;
|
|
30
|
+
/** A fingerprint or Free Report id to start from. */
|
|
31
|
+
target?: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function seedPrompt(): string {
|
|
35
|
+
return [
|
|
36
|
+
`You are triaging a problem with ${FRAMEWORK_NAME} on this machine.`,
|
|
37
|
+
"Read PLAYBOOK.md in this folder and follow it step by step.",
|
|
38
|
+
"The machine facts and the recorded friction are described in context.md.",
|
|
39
|
+
].join(" ");
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async function doctorSection(
|
|
43
|
+
cwd: string,
|
|
44
|
+
collect: (cwd: string) => Promise<unknown>,
|
|
45
|
+
): Promise<{ report: unknown } | { error: string }> {
|
|
46
|
+
try {
|
|
47
|
+
return { report: await collect(cwd) };
|
|
48
|
+
} catch (error) {
|
|
49
|
+
return { error: errorMessage(error) };
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function companionOf(doctor: { report: unknown } | { error: string }): string | null {
|
|
54
|
+
if (!("report" in doctor) || !doctor.report || typeof doctor.report !== "object") return null;
|
|
55
|
+
const { companionPath } = doctor.report as { companionPath?: unknown };
|
|
56
|
+
return typeof companionPath === "string" && companionPath ? companionPath : null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Writes a fresh triage session; nothing is written outside its folder except pruning old ones.
|
|
61
|
+
* Throws a `FrictionRefusal`, writing nothing, for an unknown target or one held by several
|
|
62
|
+
* other companions.
|
|
63
|
+
*/
|
|
64
|
+
export async function prepareTriageSession(
|
|
65
|
+
options: PrepareTriageOptions,
|
|
66
|
+
): Promise<{ files: TriageSessionFiles; agents: FoundAgent[] }> {
|
|
67
|
+
const { now, cwd } = options;
|
|
68
|
+
// The target lookup and the companion rule may refuse, so they run before the session folder exists.
|
|
69
|
+
const target = options.target
|
|
70
|
+
? lookupFrictionTarget(options.target, { homeDir: options.homeDir, verb: "Triage" })
|
|
71
|
+
: undefined;
|
|
72
|
+
const doctor = await doctorSection(cwd, options.collectDoctor);
|
|
73
|
+
const current = companionOf(doctor);
|
|
74
|
+
const companion = chooseSnapshotCompanion(current, target);
|
|
75
|
+
const dir = createTriageSession({ homeDir: options.homeDir, now });
|
|
76
|
+
const files: TriageSessionFiles = {
|
|
77
|
+
dir,
|
|
78
|
+
context: path.join(dir, "context.md"),
|
|
79
|
+
playbook: path.join(dir, "PLAYBOOK.md"),
|
|
80
|
+
prompt: path.join(dir, "prompt.md"),
|
|
81
|
+
};
|
|
82
|
+
const agents = findAgents(options.pathValue);
|
|
83
|
+
const friction = await writeFrictionSnapshot(dir, {
|
|
84
|
+
companion,
|
|
85
|
+
current,
|
|
86
|
+
target,
|
|
87
|
+
homeDir: options.homeDir,
|
|
88
|
+
now,
|
|
89
|
+
});
|
|
90
|
+
const { config } = getActiveDistribution();
|
|
91
|
+
fs.writeFileSync(
|
|
92
|
+
files.context,
|
|
93
|
+
maskSecretValues(
|
|
94
|
+
renderTriageContext({
|
|
95
|
+
now,
|
|
96
|
+
version: config.version,
|
|
97
|
+
argv: options.argv,
|
|
98
|
+
cwd,
|
|
99
|
+
sessionDir: dir,
|
|
100
|
+
issueRepository: config.issueRepository,
|
|
101
|
+
agents,
|
|
102
|
+
friction,
|
|
103
|
+
doctor,
|
|
104
|
+
}),
|
|
105
|
+
options.env,
|
|
106
|
+
),
|
|
107
|
+
"utf8",
|
|
108
|
+
);
|
|
109
|
+
fs.copyFileSync(getTriagePlaybookPath(), files.playbook);
|
|
110
|
+
fs.writeFileSync(files.prompt, `${seedPrompt()}\n`, "utf8");
|
|
111
|
+
return { files, agents };
|
|
112
|
+
}
|