@uniqbit/mate-core 1.0.0-canary.6 → 1.0.0-canary.7
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 +1 -1
- package/src/cli/commands/doctor.ts +51 -0
- package/src/cli/commands/friction.ts +558 -0
- 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/services.ts +25 -0
- package/src/cli/commands/triage.ts +151 -0
- package/src/cli/commands/vscode/release-vsix.json +2 -2
- package/src/cli/main.ts +35 -13
- package/src/cli/plugin-commands.ts +6 -1
- package/src/cli/usage.ts +10 -0
- package/src/create-mate.ts +11 -5
- package/src/distribution.ts +2 -0
- package/src/hooks/validate-artifact-path.ts +64 -14
- package/src/lib/friction/describe.ts +42 -0
- package/src/lib/friction/fields.ts +60 -0
- package/src/lib/friction/mark.ts +156 -0
- package/src/lib/friction/view/model.ts +67 -0
- package/src/lib/friction/view/read.ts +136 -0
- package/src/lib/friction/view/select.ts +54 -0
- 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/triage/context.ts +186 -0
- package/src/lib/triage/launch.ts +52 -0
- package/src/lib/triage/prepare.ts +97 -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 +5 -0
- package/src/runtime/command-friction.ts +97 -0
- package/src/runtime/companion-guidance.ts +32 -15
- package/src/runtime/friction-fingerprint.ts +35 -0
- package/src/runtime/friction-log.ts +352 -0
- package/src/runtime/friction-recorder.ts +199 -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/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 +41 -0
- package/src/templates/triage/PLAYBOOK.md +112 -0
- package/src/tools/setup/capabilities/rtk.ts +19 -8
- package/src/tools/setup/plugin.ts +5 -0
- package/src/tools/setup/service.ts +4 -0
- package/src/tools/setup.ts +16 -2
- package/studio-dist/client/assets/app-aIwDxf48.css +2 -0
- package/studio-dist/client/assets/button-CX0sWAJl.js +1 -0
- package/studio-dist/client/assets/combobox-BmA8RjOc.js +1 -0
- package/studio-dist/client/assets/{companion-view-BVaZNtiI.js → companion-view-DINdPF-b.js} +1 -1
- package/studio-dist/client/assets/fields-BobQ7zRF.js +1 -0
- package/studio-dist/client/assets/friction-YdYd3zaz.js +1 -0
- package/studio-dist/client/assets/getting-started-CY7NEtTw.js +1 -0
- package/studio-dist/client/assets/getting-started-djaQeWlu.js +1 -0
- package/studio-dist/client/assets/getting-started._topic-DVB8e5R9.js +1 -0
- package/studio-dist/client/assets/getting-started.index-DQvLHEr1.js +1 -0
- package/studio-dist/client/assets/graph-DbNnR884.js +2 -0
- package/studio-dist/client/assets/{graph-canvas-DDuzsNSx.js → graph-canvas-DIcAqwtK.js} +1 -1
- package/studio-dist/client/assets/guides-D6T6W_jV.js +1 -0
- package/studio-dist/client/assets/index-CysBCSxM.js +40 -0
- package/studio-dist/client/assets/markdown-view-jMiaBTSO.js +1 -0
- package/studio-dist/client/assets/{panel-B8F8sOKQ.js → panel-Csr49lBo.js} +1 -1
- package/studio-dist/client/assets/plugins._service._view-CEA_CcPe.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-CLdgxxkg.js +1 -0
- package/studio-dist/client/assets/routes-DGilWbDE.js +1 -0
- package/studio-dist/client/assets/search-CXosfvYh.js +1 -0
- package/studio-dist/client/assets/select-DdebbX7K.js +1 -0
- package/studio-dist/client/assets/skills-C3zNkU8g.js +1 -0
- package/studio-dist/client/assets/{specs-DU1kqcp5.js → specs-Dl8HfGlU.js} +1 -1
- package/studio-dist/client/assets/specs-view-B_n0Pekv.js +1 -0
- package/studio-dist/client/assets/{steps-DhIFuAZy.js → steps-CKUno4lh.js} +1 -1
- package/studio-dist/client/assets/store-DyXbi6o9.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-Blcl8kA_.js} +16 -16
- package/studio-dist/client/assets/useAnchoredPopupScrollLock-BBXJpX5L.js +1 -0
- package/studio-dist/client/assets/{useBaseQuery-BlC-AZ35.js → useBaseQuery-C2cjmeH2.js} +1 -1
- package/studio-dist/client/assets/useMutation-DI6LbvVa.js +1 -0
- package/studio-dist/client/assets/vault-Cb9DmM1i.js +1 -0
- package/studio-dist/client/assets/warnings-B-rvoW8q.js +1 -0
- package/studio-dist/client/assets/workflow-DN5T19jd.js +1 -0
- package/studio-dist/server/assets/{__23tanstack-start-server-fn-resolver-DAbZ6fzY.js → __23tanstack-start-server-fn-resolver-JoHQ5ihx.js} +30 -14
- package/studio-dist/server/assets/_tanstack-start-manifest_v.js +66 -50
- package/studio-dist/server/assets/{button-BfoNadNR.js → button-B7e1fRyW.js} +228 -3
- package/studio-dist/server/assets/combobox--S_OmUfh.js +483 -0
- package/studio-dist/server/assets/{companion-view-DHUjPpA0.js → companion-view-D-vGM55e.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-B4qM2ZwC.js} +1 -1
- package/studio-dist/server/assets/friction-CWOTjpCV.js +62 -0
- package/studio-dist/server/assets/friction-sLxaWY-H.js +903 -0
- package/studio-dist/server/assets/{getting-started-7P0oyWaM.js → getting-started-Cq5Pcnsr.js} +2 -2
- package/studio-dist/server/assets/{getting-started._topic-B1mV0kGz.js → getting-started._topic-CmWdl3u3.js} +2 -2
- package/studio-dist/server/assets/{getting-started.index-CeGtvUsm.js → getting-started.index-AB8xpTFY.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-C_Hn-Wf_.js} +7 -8
- package/studio-dist/server/assets/{graph-canvas-CID9Nksc.js → graph-canvas-BthrSmPS.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-BVQ4pt5B.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-rwiiVcPC.js} +1 -1
- package/studio-dist/server/assets/{panel-yqOl5GMU.js → panel-CUxRIpYL.js} +3 -3
- package/studio-dist/server/assets/{plugins._service._view-DwqJX7s9.js → plugins._service._view-BSvGnlhU.js} +6 -4
- package/studio-dist/server/assets/prepaint-B28ClcPN.js +45 -0
- package/studio-dist/server/assets/{queries-DYmGrhNO.js → queries-S_Pl90IG.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-CJpAItPk.js} +6 -7
- package/studio-dist/server/assets/{router-Dnoq5auE.js → router-DF0etoNa.js} +627 -1563
- package/studio-dist/server/assets/{routes-Cok4p3mK.js → routes-6ylCLkyg.js} +7 -8
- package/studio-dist/server/assets/{search-DUK7Jl6f.js → search-b-yQesv3.js} +25 -2
- package/studio-dist/server/assets/{combobox-oxUI6r4V.js → select-CjuKScan.js} +34 -514
- package/studio-dist/server/assets/{shell-DNVXedgE.js → shell-DLkP7wG9.js} +2 -2
- package/studio-dist/server/assets/{skills-pKmuAs0F.js → skills-DGg0mWDM.js} +1 -1
- package/studio-dist/server/assets/{skills-D8qdXSku.js → skills-zeU80A9S.js} +7 -8
- package/studio-dist/server/assets/{specs-DeHYUNFp.js → specs-DDBNT_v1.js} +4 -4
- package/studio-dist/server/assets/{specs-view-BGn-5Ik_.js → specs-view-exvmWdg0.js} +9 -9
- package/studio-dist/server/assets/{steps-CV7Yk7L7.js → steps-D1tYAyWZ.js} +1 -1
- package/studio-dist/server/assets/store-kS7zk0Hr.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-qOXOYoPt.js} +66 -8
- package/studio-dist/server/assets/{usage-M6Gi6Km7.js → usage-C2um7YiV.js} +12 -43
- package/studio-dist/server/assets/{usage-j5jR9gX9.js → usage-Cwle9-xY.js} +1 -1
- package/studio-dist/server/assets/useAnchoredPopupScrollLock-kQBB3y_b.js +756 -0
- package/studio-dist/server/assets/{useBaseQuery-Tv_QJt9r.js → useBaseQuery--iH3rd-T.js} +1 -1
- package/studio-dist/server/assets/useMutation-C-WO6hCM.js +690 -0
- package/studio-dist/server/assets/{vault-PqVmssmW.js → vault-B8vgVIH9.js} +6 -6
- package/studio-dist/server/assets/{vault-lBlvSyD4.js → vault-CEBBRLMb.js} +1 -1
- package/studio-dist/server/assets/{views-CsFp1i1G.js → views-UgO0Qz_g.js} +2 -2
- package/studio-dist/server/assets/{warnings-BDs34j_m.js → warnings-BxK4VfV5.js} +1 -2
- package/studio-dist/server/assets/{workflow-T0eEldsa.js → workflow-BrTK632u.js} +8 -9
- package/studio-dist/server/server.js +2 -2
- 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/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/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
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The page's connection to Studio's server. Browser-safe: plugin view bundles import it,
|
|
3
|
+
* so it imports nothing from Node.
|
|
4
|
+
*/
|
|
5
|
+
import { STUDIO_PING_ROUTE } from "./routes";
|
|
6
|
+
|
|
7
|
+
export type StudioConnectionState =
|
|
8
|
+
| "online"
|
|
9
|
+
| "offline"
|
|
10
|
+
| "signed-out"
|
|
11
|
+
| "expired"
|
|
12
|
+
| "host-refused";
|
|
13
|
+
|
|
14
|
+
/** A connection problem; any other state of a request is an answer of Studio's. */
|
|
15
|
+
export type StudioConnectionProblem = Exclude<StudioConnectionState, "online">;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The connection problem a request's outcome (its response, or what it threw) shows.
|
|
19
|
+
* `null` for any answer Studio itself gave, a refusal included, and for an abort.
|
|
20
|
+
*/
|
|
21
|
+
export function connectionStateOf(outcome: unknown): StudioConnectionProblem | null {
|
|
22
|
+
if (outcome instanceof TypeError) return "offline";
|
|
23
|
+
if (!(outcome instanceof Response)) return null;
|
|
24
|
+
// A redirect `redirect: "manual"` stopped: an auth proxy in front of Studio.
|
|
25
|
+
if (outcome.type === "opaqueredirect") return "signed-out";
|
|
26
|
+
if (outcome.status === 401) return "expired";
|
|
27
|
+
if (outcome.status === 421) return "host-refused";
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Pings Studio. Never carries the token, so the token exchange's 303 cannot answer it. */
|
|
32
|
+
export async function probeStudio(fetchImpl: typeof fetch = fetch): Promise<StudioConnectionState> {
|
|
33
|
+
let outcome: unknown;
|
|
34
|
+
try {
|
|
35
|
+
outcome = await fetchImpl(STUDIO_PING_ROUTE, {
|
|
36
|
+
redirect: "manual",
|
|
37
|
+
credentials: "same-origin",
|
|
38
|
+
cache: "no-store",
|
|
39
|
+
});
|
|
40
|
+
} catch (error) {
|
|
41
|
+
outcome = error;
|
|
42
|
+
}
|
|
43
|
+
return connectionStateOf(outcome) ?? "online";
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Studio's connection state, shared with the plugin views it mounts. */
|
|
47
|
+
export interface StudioConnection {
|
|
48
|
+
state(): StudioConnectionState;
|
|
49
|
+
/** A request failed; Studio probes unless a probe is running. Only the probe changes the state. */
|
|
50
|
+
suspect(): void;
|
|
51
|
+
/** Calls `listener` with each new state; returns the unsubscribe. */
|
|
52
|
+
subscribe(listener: (state: StudioConnectionState) => void): () => void;
|
|
53
|
+
}
|
|
@@ -15,6 +15,9 @@ export const SERVICE_ROUTE_PREFIX = "/api/plugins/";
|
|
|
15
15
|
/** A service plugin's view modules: `/studio/plugins/<service id>/<view id>/<file>`. */
|
|
16
16
|
export const SERVICE_ASSET_PREFIX = "/studio/plugins/";
|
|
17
17
|
|
|
18
|
+
/** Answers 204 to any reader; the page probes its connection here. */
|
|
19
|
+
export const STUDIO_PING_ROUTE = "/api/ping";
|
|
20
|
+
|
|
18
21
|
/** One event stream per page: board, reports and markdown tree changes for a companion. */
|
|
19
22
|
export const STUDIO_EVENTS_ROUTE = "/api/events";
|
|
20
23
|
|
|
@@ -11,6 +11,7 @@ export type StudioView =
|
|
|
11
11
|
| "vault"
|
|
12
12
|
| "reports"
|
|
13
13
|
| "usage"
|
|
14
|
+
| "friction"
|
|
14
15
|
| "graph";
|
|
15
16
|
|
|
16
17
|
export const STUDIO_VIEWS: readonly StudioView[] = [
|
|
@@ -22,6 +23,7 @@ export const STUDIO_VIEWS: readonly StudioView[] = [
|
|
|
22
23
|
"vault",
|
|
23
24
|
"reports",
|
|
24
25
|
"usage",
|
|
26
|
+
"friction",
|
|
25
27
|
"graph",
|
|
26
28
|
];
|
|
27
29
|
|
|
@@ -38,7 +40,14 @@ export const MODE_VIEWS: Readonly<Record<StudioMode, readonly StudioView[]>> = {
|
|
|
38
40
|
};
|
|
39
41
|
|
|
40
42
|
/** Views every mode is offered, in navigation order. */
|
|
41
|
-
export const SHARED_VIEWS: readonly StudioView[] = [
|
|
43
|
+
export const SHARED_VIEWS: readonly StudioView[] = [
|
|
44
|
+
"vault",
|
|
45
|
+
"specs",
|
|
46
|
+
"reports",
|
|
47
|
+
"graph",
|
|
48
|
+
"usage",
|
|
49
|
+
"friction",
|
|
50
|
+
];
|
|
42
51
|
|
|
43
52
|
/** Where a mode lands when its URL names no view, or one it is not offered. */
|
|
44
53
|
export const LANDING_VIEW: Readonly<Record<StudioMode, StudioView>> = {
|
|
@@ -38,6 +38,7 @@ import {
|
|
|
38
38
|
SERVICE_ROUTE_PREFIX,
|
|
39
39
|
STUDIO_EVENTS_ROUTE,
|
|
40
40
|
STUDIO_HOSTNAME,
|
|
41
|
+
STUDIO_PING_ROUTE,
|
|
41
42
|
type StudioEvent,
|
|
42
43
|
TERMINAL_ASSET_PREFIX,
|
|
43
44
|
TERMINAL_SESSIONS_END_ROUTE,
|
|
@@ -141,6 +142,8 @@ export interface StudioServerDeps {
|
|
|
141
142
|
vault?: VaultManager;
|
|
142
143
|
reports?: ReportStore;
|
|
143
144
|
usage?: UsageCache;
|
|
145
|
+
/** Where the Friction Log and Switch live; the user's home when absent. */
|
|
146
|
+
homeDir?: string;
|
|
144
147
|
terminal?: Partial<TerminalRegistryOptions>;
|
|
145
148
|
launchableAgents?: typeof launchableAgents;
|
|
146
149
|
/** The plugin services Studio mounts; the registered plugins' when absent. */
|
|
@@ -611,6 +614,30 @@ export function createStudioFetch(
|
|
|
611
614
|
});
|
|
612
615
|
return (await usage).read(companionPath, request);
|
|
613
616
|
},
|
|
617
|
+
friction: async (digest, { days }) => {
|
|
618
|
+
const companionPath = await companionPathOf(digest);
|
|
619
|
+
const { readFrictionView } = await import("../../../lib/friction/view/read");
|
|
620
|
+
return readFrictionView({ companion: companionPath }, { days, homeDir: deps.homeDir });
|
|
621
|
+
},
|
|
622
|
+
frictionRecording: async () => {
|
|
623
|
+
const { readFrictionSwitch } = await import("../../../runtime/friction-switch");
|
|
624
|
+
return { recording: readFrictionSwitch(deps.homeDir) };
|
|
625
|
+
},
|
|
626
|
+
setFrictionRecording: async (recording) => {
|
|
627
|
+
const { writeFrictionSwitch } = await import("../../../runtime/friction-switch");
|
|
628
|
+
writeFrictionSwitch(recording, deps.homeDir);
|
|
629
|
+
return { recording };
|
|
630
|
+
},
|
|
631
|
+
markFriction: async (target, state, { note, link }) => {
|
|
632
|
+
const { markFriction } = await import("../../../lib/friction/mark");
|
|
633
|
+
const marked = await markFriction(
|
|
634
|
+
target,
|
|
635
|
+
state,
|
|
636
|
+
{ note, link, by: "studio" },
|
|
637
|
+
{ homeDir: deps.homeDir },
|
|
638
|
+
);
|
|
639
|
+
return marked.ok ? { ok: true, state: marked.state } : { ok: false, reason: marked.reason };
|
|
640
|
+
},
|
|
614
641
|
skillPreview: async (digest, agent, name, file) => {
|
|
615
642
|
const { readSkillPreview } = await import("./skill-files");
|
|
616
643
|
return readSkillPreview(await companionPathOf(digest), agent, name, file);
|
|
@@ -718,6 +745,10 @@ export function createStudioFetch(
|
|
|
718
745
|
const refusal = refusalFor(route, request, url, acceptedOrigin);
|
|
719
746
|
if (refusal) return respond(refusal);
|
|
720
747
|
|
|
748
|
+
if (url.pathname === STUDIO_PING_ROUTE) {
|
|
749
|
+
return respond(new Response(null, { status: 204, headers: { "cache-control": "no-store" } }));
|
|
750
|
+
}
|
|
751
|
+
|
|
721
752
|
if (url.pathname === REPORTS_ROUTE) {
|
|
722
753
|
const digest = url.searchParams.get(COMPANION_PARAM) ?? "";
|
|
723
754
|
if (!COMPANION_DIGEST_PATTERN.test(digest)) {
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { FrictionView, FrictionViewDays } from "../../../lib/friction/view/model";
|
|
2
|
+
import type { FrictionState, MarkState } from "../../../runtime/friction-vocabulary";
|
|
1
3
|
import type { UsageRequest } from "../../../lib/usage/cache";
|
|
2
4
|
import type { UsageResponse } from "../../../lib/usage/types";
|
|
3
5
|
import type { StudioSpecGraph } from "./graph";
|
|
@@ -63,6 +65,25 @@ export interface StudioServices {
|
|
|
63
65
|
reports(companionDigest: string): Promise<StoredReport[]>;
|
|
64
66
|
/** Read-only, explicitly refreshed usage; never collected for unrelated views. */
|
|
65
67
|
usage(companionDigest: string, request: UsageRequest): Promise<UsageResponse>;
|
|
68
|
+
/** The friction recorded for a registered companion on this machine; read-only. */
|
|
69
|
+
friction(companionDigest: string, request: { days: FrictionViewDays }): Promise<FrictionView>;
|
|
70
|
+
/** This machine's Friction Switch alone: reads no Friction Log and writes nothing. */
|
|
71
|
+
frictionRecording(): Promise<{ recording: boolean }>;
|
|
72
|
+
/**
|
|
73
|
+
* Sets this machine's Friction Switch. Needs no `writable`: it writes only the switch's
|
|
74
|
+
* settings file, never a companion, repository, registry or log.
|
|
75
|
+
*/
|
|
76
|
+
setFrictionRecording(recording: boolean): Promise<{ recording: boolean }>;
|
|
77
|
+
/**
|
|
78
|
+
* Sets or, with `open`, clears a fingerprint's or Free Report's Friction State, as
|
|
79
|
+
* `mate friction mark` does, by `studio`. Needs no `writable`: it writes only the state file.
|
|
80
|
+
* A refusal is an answer, not an error.
|
|
81
|
+
*/
|
|
82
|
+
markFriction(
|
|
83
|
+
target: string,
|
|
84
|
+
state: MarkState,
|
|
85
|
+
input: { note?: string; link?: string },
|
|
86
|
+
): Promise<FrictionMarkResult>;
|
|
66
87
|
/** One installed skill's files and one of them rendered (SKILL.md by default); read-only. */
|
|
67
88
|
skillPreview(
|
|
68
89
|
companionDigest: string,
|
|
@@ -86,6 +107,10 @@ export interface StudioServices {
|
|
|
86
107
|
addCompanion(input: CompanionAddInput): Promise<CompanionAddResult>;
|
|
87
108
|
}
|
|
88
109
|
|
|
110
|
+
export type FrictionMarkResult =
|
|
111
|
+
| { ok: true; state: FrictionState | null }
|
|
112
|
+
| { ok: false; reason: string };
|
|
113
|
+
|
|
89
114
|
export type CompanionAddInput = { kind: "url"; url: string } | { kind: "path"; path: string };
|
|
90
115
|
|
|
91
116
|
export type CompanionAddResult =
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import readline from "node:readline/promises";
|
|
2
|
+
|
|
3
|
+
import { FRAMEWORK_NAME } from "../../framework";
|
|
4
|
+
import {
|
|
5
|
+
launchAgent,
|
|
6
|
+
TRIAGE_AGENT_NAMES,
|
|
7
|
+
TRIAGE_AGENTS,
|
|
8
|
+
type FoundAgent,
|
|
9
|
+
type TriageAgent,
|
|
10
|
+
} from "../../lib/triage/launch";
|
|
11
|
+
import {
|
|
12
|
+
prepareTriageSession,
|
|
13
|
+
seedPrompt,
|
|
14
|
+
type TriageSessionFiles,
|
|
15
|
+
} from "../../lib/triage/prepare";
|
|
16
|
+
import { recordTriageLauncher } from "../../lib/triage/session";
|
|
17
|
+
import { currentSession } from "../../runtime/session-id";
|
|
18
|
+
import { collectDoctorReport } from "./doctor";
|
|
19
|
+
|
|
20
|
+
interface TriageArgs {
|
|
21
|
+
agent: TriageAgent | null;
|
|
22
|
+
launch: boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const TRIAGE_USAGE = `Usage: ${FRAMEWORK_NAME} triage [--agent <${TRIAGE_AGENTS.join("|")}>] [--no-launch]`;
|
|
26
|
+
|
|
27
|
+
function parseTriageArgs(argv: string[]): TriageArgs | { error: string } {
|
|
28
|
+
const args: TriageArgs = { agent: null, launch: true };
|
|
29
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
30
|
+
const arg = argv[index]!;
|
|
31
|
+
const [flag, inline] = arg.startsWith("--") && arg.includes("=") ? arg.split(/=(.*)/s) : [arg];
|
|
32
|
+
if (flag === "--no-launch" && inline === undefined) {
|
|
33
|
+
args.launch = false;
|
|
34
|
+
} else if (flag === "--agent") {
|
|
35
|
+
const value = inline ?? argv[++index];
|
|
36
|
+
if (!TRIAGE_AGENTS.includes(value as TriageAgent)) {
|
|
37
|
+
return { error: `--agent must be one of: ${TRIAGE_AGENTS.join(", ")}` };
|
|
38
|
+
}
|
|
39
|
+
args.agent = value as TriageAgent;
|
|
40
|
+
} else {
|
|
41
|
+
return { error: `unknown triage option: ${arg}` };
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return args;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface TriageDeps {
|
|
48
|
+
cwd?: string;
|
|
49
|
+
env?: Record<string, string | undefined>;
|
|
50
|
+
now?: Date;
|
|
51
|
+
/** Asks which agent to start; null when no terminal can ask. Defaults to a prompt on a TTY stdin. */
|
|
52
|
+
ask?: AskAgent | null;
|
|
53
|
+
collectDoctor?: (cwd: string) => Promise<unknown>;
|
|
54
|
+
launch?: typeof launchAgent;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
type AskAgent = (choices: TriageAgent[]) => Promise<TriageAgent | null>;
|
|
58
|
+
|
|
59
|
+
const askAgent: AskAgent = async (choices) => {
|
|
60
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
61
|
+
try {
|
|
62
|
+
const answer = await rl.question(`Start which agent? (${choices.join("/")}) `);
|
|
63
|
+
const picked = answer.trim().toLowerCase();
|
|
64
|
+
return choices.find((choice) => choice === picked) ?? null;
|
|
65
|
+
} finally {
|
|
66
|
+
rl.close();
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
async function chooseAgent(
|
|
71
|
+
requested: TriageAgent | null,
|
|
72
|
+
agents: FoundAgent[],
|
|
73
|
+
ask: AskAgent | null,
|
|
74
|
+
): Promise<{ found: FoundAgent } | { error: string }> {
|
|
75
|
+
const pick = (id: TriageAgent | null, error: string) => {
|
|
76
|
+
const found = agents.find((agent) => agent.agent === id);
|
|
77
|
+
return found ? { found } : { error };
|
|
78
|
+
};
|
|
79
|
+
if (requested) return pick(requested, `${TRIAGE_AGENT_NAMES[requested]} was not found on PATH.`);
|
|
80
|
+
if (agents.length === 0) {
|
|
81
|
+
return {
|
|
82
|
+
error: `No agent was found: install ${TRIAGE_AGENTS.map((id) => TRIAGE_AGENT_NAMES[id]).join(" or ")}, or start your own agent with the prompt in prompt.md.`,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
if (agents.length === 1) return { found: agents[0]! };
|
|
86
|
+
const flags = agents.map((agent) => `--agent ${agent.agent}`).join(" or ");
|
|
87
|
+
if (!ask) return { error: `Several agents are installed; choose one with ${flags}.` };
|
|
88
|
+
const picked = await ask(agents.map((agent) => agent.agent));
|
|
89
|
+
return pick(picked, `No agent chosen; choose one with ${flags}.`);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function printPaths(files: TriageSessionFiles): void {
|
|
93
|
+
console.log(`Triage session: ${files.dir}`);
|
|
94
|
+
console.log(` context: ${files.context}`);
|
|
95
|
+
console.log(` playbook: ${files.playbook}`);
|
|
96
|
+
console.log(` prompt: ${files.prompt}`);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* @command mate triage
|
|
101
|
+
* @description Writes a triage session under Mate's home (machine facts, the
|
|
102
|
+
* shipped playbook, a seed prompt and a 30-day friction snapshot) and starts
|
|
103
|
+
* Claude Code or OpenCode in it, directly and not through a Mate launch.
|
|
104
|
+
* Runs before every gate, so it works when Mate itself does not.
|
|
105
|
+
* `--no-launch` only prints the session paths.
|
|
106
|
+
*/
|
|
107
|
+
export async function runTriageCommand(argv: string[] = [], deps: TriageDeps = {}): Promise<void> {
|
|
108
|
+
const args = parseTriageArgs(argv);
|
|
109
|
+
if ("error" in args) {
|
|
110
|
+
console.error(`${FRAMEWORK_NAME}: ${args.error}`);
|
|
111
|
+
console.error(TRIAGE_USAGE);
|
|
112
|
+
process.exitCode = 1;
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const env = deps.env ?? process.env;
|
|
116
|
+
const { files, agents } = await prepareTriageSession({
|
|
117
|
+
argv,
|
|
118
|
+
cwd: deps.cwd ?? process.cwd(),
|
|
119
|
+
homeDir: env.HOME,
|
|
120
|
+
now: deps.now ?? new Date(),
|
|
121
|
+
pathValue: env.PATH ?? "",
|
|
122
|
+
env,
|
|
123
|
+
collectDoctor: deps.collectDoctor ?? ((cwd) => collectDoctorReport({ cwd, write: false })),
|
|
124
|
+
});
|
|
125
|
+
printPaths(files);
|
|
126
|
+
if (!args.launch) return;
|
|
127
|
+
if (currentSession(env)) {
|
|
128
|
+
console.log(
|
|
129
|
+
`No agent started: this is an agent session. Run \`${FRAMEWORK_NAME} triage\` in your own terminal.`,
|
|
130
|
+
);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const ask = deps.ask === undefined ? (process.stdin.isTTY ? askAgent : null) : deps.ask;
|
|
135
|
+
const choice = await chooseAgent(args.agent, agents, ask);
|
|
136
|
+
if ("error" in choice) {
|
|
137
|
+
console.error(`${FRAMEWORK_NAME}: ${choice.error}`);
|
|
138
|
+
process.exitCode = 1;
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
const release = recordTriageLauncher(files.dir);
|
|
142
|
+
try {
|
|
143
|
+
process.exitCode = await (deps.launch ?? launchAgent)({
|
|
144
|
+
...choice.found,
|
|
145
|
+
sessionDir: files.dir,
|
|
146
|
+
prompt: seedPrompt(),
|
|
147
|
+
});
|
|
148
|
+
} finally {
|
|
149
|
+
release();
|
|
150
|
+
}
|
|
151
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.0.0-canary.
|
|
3
|
-
"sha512": "sha512-
|
|
2
|
+
"version": "1.0.0-canary.7",
|
|
3
|
+
"sha512": "sha512-U8mQKQBKZcgFCeZgNdNEVa7xNaOi00D/PC6OZo82FWTlucUkmgw1LhLc3XsqircmbC0NQwIQ09YvTnfyqv4sgA=="
|
|
4
4
|
}
|
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,6 +20,7 @@ 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";
|
|
@@ -78,6 +80,17 @@ 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
|
+
const FRICTION_GATE_NEEDS = new Map<string | undefined, GateNeeds>([
|
|
90
|
+
["list", { updateGuard: true, companion: true, install: true }],
|
|
91
|
+
["report", { companion: true }],
|
|
92
|
+
]);
|
|
93
|
+
|
|
81
94
|
export async function main(argv = process.argv, deps: MainDeps = mainDeps): Promise<void> {
|
|
82
95
|
const [, , command, subcommand, ...rest] = argv;
|
|
83
96
|
|
|
@@ -91,6 +104,11 @@ export async function main(argv = process.argv, deps: MainDeps = mainDeps): Prom
|
|
|
91
104
|
return;
|
|
92
105
|
}
|
|
93
106
|
|
|
107
|
+
if (command === "triage") {
|
|
108
|
+
await runTriageCommand(argv.slice(3));
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
|
|
94
112
|
if (!(await ensureRuntimeDirectory(command, deps.refreshRuntimeDirectory))) {
|
|
95
113
|
process.exitCode = 1;
|
|
96
114
|
return;
|
|
@@ -123,10 +141,9 @@ export async function main(argv = process.argv, deps: MainDeps = mainDeps): Prom
|
|
|
123
141
|
// scheduleBackgroundCheck() has been observed to race a large final stdout
|
|
124
142
|
// write against process exit, truncating it.
|
|
125
143
|
const ownsStdout = isPluginCommand;
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
const skipsBackgroundCheck = ownsStdout || command === "report" || command === "workflow";
|
|
144
|
+
const printsJsonContract =
|
|
145
|
+
command === "report" || command === "friction" || command === "workflow";
|
|
146
|
+
const skipsBackgroundCheck = ownsStdout || printsJsonContract;
|
|
130
147
|
|
|
131
148
|
// Every dispatch case opens with a gate() call declaring what the command
|
|
132
149
|
// needs before it may run. Declared gates run in fixed order — update
|
|
@@ -287,15 +304,8 @@ export async function main(argv = process.argv, deps: MainDeps = mainDeps): Prom
|
|
|
287
304
|
return;
|
|
288
305
|
case "report":
|
|
289
306
|
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
|
-
}),
|
|
307
|
+
printPreflightErrorDocument(
|
|
308
|
+
"Mate must be updated or installed before reporting; see stderr",
|
|
299
309
|
);
|
|
300
310
|
return;
|
|
301
311
|
}
|
|
@@ -317,6 +327,18 @@ export async function main(argv = process.argv, deps: MainDeps = mainDeps): Prom
|
|
|
317
327
|
if (!(await gate({}))) return;
|
|
318
328
|
await runDoctorCommand(argv.slice(3));
|
|
319
329
|
return;
|
|
330
|
+
case "friction": {
|
|
331
|
+
if (!(await gate(FRICTION_GATE_NEEDS.get(subcommand) ?? {}))) {
|
|
332
|
+
if (rest.includes("--json")) {
|
|
333
|
+
printPreflightErrorDocument(
|
|
334
|
+
"Mate must be updated, installed or given one companion; see stderr",
|
|
335
|
+
);
|
|
336
|
+
}
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
await runFrictionCommand(subcommand, rest);
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
320
342
|
case "cap":
|
|
321
343
|
if (!(await gate({ updateGuard: true, companion: true, install: true }))) return;
|
|
322
344
|
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
|
@@ -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 [--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]`,
|
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 {
|
|
@@ -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) {
|