@uniqbit/mate-core 0.18.1-canary.1 → 0.18.1-canary.2
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-plugin/hooks/session-banner.mjs +1 -1
- package/opencode-plugin/server.ts +5 -0
- package/opencode-plugin/src/add-dir.ts +118 -0
- package/opencode-plugin/src/companion.ts +180 -0
- package/opencode-plugin/src/server.ts +26 -0
- package/opencode-plugin/src/tui.tsx +1 -0
- package/opencode-plugin/tui.tsx +2 -0
- package/package.json +8 -6
- package/src/cli/commands/artifact/finish/engine.ts +1 -1
- package/src/cli/commands/artifact/finish/git.ts +74 -59
- package/src/cli/commands/companion/hub.ts +1 -1
- package/src/cli/commands/companion/link.ts +13 -43
- package/src/cli/commands/doctor.ts +30 -4
- package/src/cli/commands/plugin/plugin.ts +0 -4
- package/src/cli/commands/report/formatter.ts +0 -4
- package/src/cli/commands/studio/selection.ts +3 -0
- package/src/cli/commands/studio/vault.ts +5 -3
- package/src/cli/commands/studio/views/workflow/steps.ts +5 -4
- package/src/cli/commands/update.ts +4 -20
- package/src/cli/commands/working/cleanup.ts +4 -1
- package/src/cli/launch-selector.tsx +0 -318
- package/src/cli/main.ts +0 -29
- package/src/cli/setup-selector.tsx +1 -1
- package/src/cli/usage.ts +0 -1
- package/src/hooks/session-banner.ts +7 -5
- package/src/hooks/validate-artifact-path.ts +17 -6
- package/src/lib/opencode-plugin-package.ts +7 -28
- package/src/lib/orchestrator/adapters/opencode.ts +28 -67
- package/src/lib/orchestrator/companion-git-sync.ts +22 -104
- package/src/lib/orchestrator/companion-hub.ts +70 -119
- package/src/lib/orchestrator/repo-local-registry.ts +0 -21
- package/src/lib/orchestrator/working-repo-projection.ts +13 -9
- package/src/lib/package-paths.ts +32 -0
- package/src/lib/prebuilt-workspace.ts +0 -3
- package/src/opencode/companion-hooks.ts +15 -10
- package/src/runtime/companion-git.ts +279 -102
- package/src/runtime/companion-sync.ts +34 -44
- package/src/runtime/index.ts +7 -5
- package/src/templates/mate-skills/agents/mate-domain-modeling/SKILL.md +2 -2
- package/src/templates/mate-skills/agents/mate-grill-me/SKILL.md +25 -0
- package/src/templates/mate-skills/agents/mate-grilling/SKILL.md +9 -7
- package/src/templates/mate-skills/agents/mate-interview-me/SKILL.md +34 -4
- package/src/templates/mate-skills/claude/mate-domain-modeling/SKILL.md +2 -2
- package/src/templates/mate-skills/claude/mate-grill-me/SKILL.md +25 -0
- package/src/templates/mate-skills/claude/mate-grilling/SKILL.md +9 -7
- package/src/templates/mate-skills/claude/mate-interview-me/SKILL.md +34 -4
- package/src/tools/setup/__snapshots__/runtime-surface-golden.test.ts.snap +68 -77
- package/src/tools/setup/capabilities/graphify.ts +0 -4
- package/src/tools/setup/dynamic-plugins/staging.ts +3 -1
- package/src/tools/setup/providers/opencode-format.ts +4 -0
- package/src/tools/setup/providers/opencode.ts +9 -65
- package/src/tools/setup/runtime-documents.ts +8 -9
- package/src/cli/commands/plugin/verify.ts +0 -25
package/src/cli/main.ts
CHANGED
|
@@ -200,12 +200,6 @@ export async function main(argv = process.argv, deps: MainDeps = mainDeps): Prom
|
|
|
200
200
|
case "prepare":
|
|
201
201
|
if (!(await gate({ updateGuard: true }))) return;
|
|
202
202
|
break;
|
|
203
|
-
// Hub commands establish and operate on a local hub root directly;
|
|
204
|
-
// they must not require a linked working repository or installation —
|
|
205
|
-
// but companions are never hubs.
|
|
206
|
-
case "hub":
|
|
207
|
-
if (!(await gate({ updateGuard: true, notCompanionRoot: true }))) return;
|
|
208
|
-
break;
|
|
209
203
|
// open/tui/sync/update consume a companion context.
|
|
210
204
|
case "open":
|
|
211
205
|
case "tui":
|
|
@@ -252,29 +246,6 @@ export async function main(argv = process.argv, deps: MainDeps = mainDeps): Prom
|
|
|
252
246
|
return;
|
|
253
247
|
await runLaunchOpenCodeCommand(argv.slice(3), { directPassthrough: true });
|
|
254
248
|
return;
|
|
255
|
-
case "launch": {
|
|
256
|
-
const launchArgs = argv.slice(4);
|
|
257
|
-
const companion = parseDirectLaunchArgs(launchArgs).scope === "companion";
|
|
258
|
-
if (subcommand !== "claude" && subcommand !== "opencode") {
|
|
259
|
-
console.error(`${FRAMEWORK_NAME}: expected launch claude or launch opencode.`);
|
|
260
|
-
process.exitCode = 1;
|
|
261
|
-
return;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
const launchCommand =
|
|
265
|
-
subcommand === "claude" ? runLaunchClaudeCommand : runLaunchOpenCodeCommand;
|
|
266
|
-
if (
|
|
267
|
-
!(await gate({
|
|
268
|
-
updateGuard: true,
|
|
269
|
-
companion: companion ? { persistSelection: false } : true,
|
|
270
|
-
install: true,
|
|
271
|
-
}))
|
|
272
|
-
)
|
|
273
|
-
return;
|
|
274
|
-
|
|
275
|
-
await launchCommand(launchArgs, { directPassthrough: true });
|
|
276
|
-
return;
|
|
277
|
-
}
|
|
278
249
|
case "report":
|
|
279
250
|
if (!(await gate({ updateGuard: true, install: true }))) return;
|
|
280
251
|
await runReportCommand(argv.slice(3));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Box, Text, render as inkRender } from "ink";
|
|
2
|
-
import
|
|
2
|
+
import { useEffect } from "react";
|
|
3
3
|
|
|
4
4
|
import { SelectMenu, type SelectMenuItem } from "../lib/components/select-menu";
|
|
5
5
|
import { WizardFooter } from "../lib/components/wizard-footer";
|
package/src/cli/usage.ts
CHANGED
|
@@ -42,7 +42,6 @@ export function usage(): string {
|
|
|
42
42
|
` ${n} cap graphify <subcommand> [args...]`,
|
|
43
43
|
` ${n} cap index [--graphify] [--tokensave]`,
|
|
44
44
|
` ${n} plugin install <package>[@version]`,
|
|
45
|
-
` ${n} plugin verify`,
|
|
46
45
|
...pluginCliCommandLines(),
|
|
47
46
|
` ${n} update`,
|
|
48
47
|
` ${n} update --check`,
|
|
@@ -30,12 +30,12 @@ export const PROJECTED_BANNER_FLAG = "--projected";
|
|
|
30
30
|
* With `mate doctor` out of scope this is one of only two surfaces where a
|
|
31
31
|
* drifted wrap becomes visible, so staleness is reported, never suppressed.
|
|
32
32
|
*/
|
|
33
|
-
export function buildBanner(
|
|
33
|
+
export async function buildBanner(
|
|
34
34
|
env: HookEnv,
|
|
35
35
|
cwd: string = process.cwd(),
|
|
36
36
|
argv: readonly string[] = [],
|
|
37
37
|
syncOptions: UnattendedSyncOptions = {},
|
|
38
|
-
): BannerOutcome {
|
|
38
|
+
): Promise<BannerOutcome> {
|
|
39
39
|
if (argv.includes(PROJECTED_BANNER_FLAG) && hasLaunchEnvironment(env)) {
|
|
40
40
|
return { exitCode: 0, stdout: "" };
|
|
41
41
|
}
|
|
@@ -52,7 +52,9 @@ export function buildBanner(
|
|
|
52
52
|
*/
|
|
53
53
|
const gitNotes = hasLaunchEnvironment(env)
|
|
54
54
|
? []
|
|
55
|
-
: unattendedSyncStalenessLines(
|
|
55
|
+
: unattendedSyncStalenessLines(
|
|
56
|
+
await syncCompanionUnattended(context.companionPath, syncOptions),
|
|
57
|
+
);
|
|
56
58
|
|
|
57
59
|
const lines = [
|
|
58
60
|
`mate v${env.MATE_VERSION || mateVersion()}`,
|
|
@@ -71,8 +73,8 @@ export function buildBanner(
|
|
|
71
73
|
}
|
|
72
74
|
|
|
73
75
|
// Plugin-shim entry.
|
|
74
|
-
export function run(argv: readonly string[] = process.argv.slice(2)): number {
|
|
75
|
-
const outcome = buildBanner(process.env, process.cwd(), argv);
|
|
76
|
+
export async function run(argv: readonly string[] = process.argv.slice(2)): Promise<number> {
|
|
77
|
+
const outcome = await buildBanner(process.env, process.cwd(), argv);
|
|
76
78
|
if (outcome.stdout) process.stdout.write(outcome.stdout);
|
|
77
79
|
return outcome.exitCode;
|
|
78
80
|
}
|
|
@@ -12,6 +12,7 @@ import fs from "node:fs";
|
|
|
12
12
|
import os from "node:os";
|
|
13
13
|
import path from "node:path";
|
|
14
14
|
|
|
15
|
+
import { gitEnvironment } from "../runtime/companion-git";
|
|
15
16
|
import { companionForkRefusal } from "../runtime/companion-sync";
|
|
16
17
|
import { readCompanionRuntimeContext } from "../runtime/env";
|
|
17
18
|
import { companionLinkPath } from "../runtime/repo-local";
|
|
@@ -143,6 +144,7 @@ function isGitignored(target: string, ctx: GuardContext): boolean {
|
|
|
143
144
|
const relPath = path.relative(root, target);
|
|
144
145
|
const result = spawnSync("git", ["-C", root, "check-ignore", "--no-index", "-q", "--", relPath], {
|
|
145
146
|
stdio: "ignore",
|
|
147
|
+
env: gitEnvironment(),
|
|
146
148
|
});
|
|
147
149
|
return result.status === 0;
|
|
148
150
|
}
|
|
@@ -156,6 +158,7 @@ function isGitTracked(target: string, ctx: GuardContext): boolean {
|
|
|
156
158
|
const relPath = path.relative(root, target);
|
|
157
159
|
const result = spawnSync("git", ["-C", root, "ls-files", "--error-unmatch", "--", relPath], {
|
|
158
160
|
stdio: "ignore",
|
|
161
|
+
env: gitEnvironment(),
|
|
159
162
|
});
|
|
160
163
|
return result.status === 0;
|
|
161
164
|
}
|
|
@@ -226,11 +229,14 @@ function checkFilePath(
|
|
|
226
229
|
* gated on the absence of a launch environment, and the path refusal keeps its
|
|
227
230
|
* input-only verdict and its double-load tolerance untouched.
|
|
228
231
|
*/
|
|
229
|
-
function checkForkedCompanion(
|
|
232
|
+
async function checkForkedCompanion(
|
|
233
|
+
filePath: string,
|
|
234
|
+
ctx: GuardContext,
|
|
235
|
+
): Promise<HookOutcome | null> {
|
|
230
236
|
if (!filePath || !artifactLikePath(filePath)) return null;
|
|
231
237
|
if (!isCompanionPath(normalizePath(filePath, ctx), ctx)) return null;
|
|
232
238
|
|
|
233
|
-
const refusal = companionForkRefusal(ctx.env, ctx.companion);
|
|
239
|
+
const refusal = await companionForkRefusal(ctx.env, ctx.companion);
|
|
234
240
|
return refusal ? { exitCode: 2, stderr: `${refusal}\n` } : null;
|
|
235
241
|
}
|
|
236
242
|
|
|
@@ -250,7 +256,11 @@ export function commandMatches(command: string): string[] {
|
|
|
250
256
|
* Fails open only when no Mate context resolves from either source; in a
|
|
251
257
|
* wrapped Working Repository the guard runs without a launch.
|
|
252
258
|
*/
|
|
253
|
-
export function evaluate(
|
|
259
|
+
export async function evaluate(
|
|
260
|
+
payload: unknown,
|
|
261
|
+
env: HookEnv,
|
|
262
|
+
cwd: string = process.cwd(),
|
|
263
|
+
): Promise<HookOutcome> {
|
|
254
264
|
const allow: HookOutcome = { exitCode: 0, stderr: "" };
|
|
255
265
|
|
|
256
266
|
const ctx = guardContext(env, cwd);
|
|
@@ -267,7 +277,7 @@ export function evaluate(payload: unknown, env: HookEnv, cwd: string = process.c
|
|
|
267
277
|
const filePath = String(toolInput.file_path ?? "");
|
|
268
278
|
/** The path refusal wins when both apply: its message is not replaced. */
|
|
269
279
|
const outcome = checkFilePath(filePath, ctx, toolName === "Edit" || toolName === "MultiEdit");
|
|
270
|
-
return outcome ?? checkForkedCompanion(filePath, ctx) ?? allow;
|
|
280
|
+
return outcome ?? (await checkForkedCompanion(filePath, ctx)) ?? allow;
|
|
271
281
|
}
|
|
272
282
|
|
|
273
283
|
if (toolName === "Bash") {
|
|
@@ -278,7 +288,8 @@ export function evaluate(payload: unknown, env: HookEnv, cwd: string = process.c
|
|
|
278
288
|
if (outcome) return outcome;
|
|
279
289
|
}
|
|
280
290
|
for (const target of targets) {
|
|
281
|
-
|
|
291
|
+
// oxlint-disable-next-line no-await-in-loop -- the first refusal wins
|
|
292
|
+
const outcome = await checkForkedCompanion(target, ctx);
|
|
282
293
|
if (outcome) return outcome;
|
|
283
294
|
}
|
|
284
295
|
return allow;
|
|
@@ -303,7 +314,7 @@ export async function run(): Promise<number> {
|
|
|
303
314
|
} catch {
|
|
304
315
|
payload = {};
|
|
305
316
|
}
|
|
306
|
-
const outcome = evaluate(payload, process.env);
|
|
317
|
+
const outcome = await evaluate(payload, process.env);
|
|
307
318
|
if (outcome.stderr) process.stderr.write(outcome.stderr);
|
|
308
319
|
return outcome.exitCode;
|
|
309
320
|
}
|
|
@@ -5,24 +5,18 @@ import path from "node:path";
|
|
|
5
5
|
|
|
6
6
|
import { isPreinstalledPluginPath } from "./preinstalled-plugins";
|
|
7
7
|
import { PUBLIC_NPM_REGISTRY } from "./public-npm";
|
|
8
|
-
import { getCurrentVersion } from "./update-checker";
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
/** The retired plugin package, bundled into mate-core as `opencode-plugin/`. */
|
|
10
|
+
const OPENCODE_PLUGIN_PACKAGE_NAME = "@uniqbit/mate-opencode-plugin";
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* compatibility range.
|
|
13
|
+
* Matches a reference to the retired plugin package: the published spec,
|
|
14
|
+
* a versioned spec, or a path bound to an installed copy. Only for stripping
|
|
15
|
+
* entries older releases wrote into committed config.
|
|
17
16
|
*/
|
|
18
|
-
export function
|
|
19
|
-
return `${OPENCODE_PLUGIN_PACKAGE_NAME}@${version}`;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/** Matches the published reference and a reference bound to an installed copy alike. */
|
|
23
|
-
export function isMateOpenCodePluginReference(value: unknown): boolean {
|
|
17
|
+
export function isLegacyMateOpenCodePluginReference(value: unknown): boolean {
|
|
24
18
|
if (typeof value === "object" && value !== null && !Array.isArray(value) && "package" in value) {
|
|
25
|
-
return
|
|
19
|
+
return isLegacyMateOpenCodePluginReference(value.package);
|
|
26
20
|
}
|
|
27
21
|
if (typeof value !== "string") return false;
|
|
28
22
|
if (
|
|
@@ -85,18 +79,3 @@ export async function warmOpenCodePackageCache(
|
|
|
85
79
|
return { ok: false, detail: (error as Error).message };
|
|
86
80
|
}
|
|
87
81
|
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Pre-fetch the pinned plugin package into OpenCode's npm plugin environment
|
|
91
|
-
* (`<cache>/packages/<spec>/`), mirroring OpenCode's own on-demand install
|
|
92
|
-
* layout, so the first managed launch after a setup or update does not depend
|
|
93
|
-
* on registry access. Best effort: failures are reported, never thrown.
|
|
94
|
-
*/
|
|
95
|
-
export async function warmOpenCodePluginCache(
|
|
96
|
-
version: string = getCurrentVersion(),
|
|
97
|
-
env: NodeJS.ProcessEnv = process.env,
|
|
98
|
-
registry = PUBLIC_NPM_REGISTRY,
|
|
99
|
-
): Promise<WarmPluginCacheResult> {
|
|
100
|
-
const reference = getOpenCodePluginPackageReference(version);
|
|
101
|
-
return warmOpenCodePackageCache(OPENCODE_PLUGIN_PACKAGE_NAME, reference, env, registry);
|
|
102
|
-
}
|
|
@@ -7,14 +7,8 @@ const path = await import("node:path");
|
|
|
7
7
|
import { MATE_ENV } from "../../../runtime/env";
|
|
8
8
|
import { validateGuidanceData, type MateGuidanceFile } from "../../../runtime/guidance";
|
|
9
9
|
|
|
10
|
+
import { getOpenCodePluginRoot, validateOpenCodePluginAssets } from "../../package-paths";
|
|
10
11
|
import {
|
|
11
|
-
getOpenCodePluginPackageReference,
|
|
12
|
-
isMateOpenCodePluginReference,
|
|
13
|
-
OPENCODE_PLUGIN_PACKAGE_NAME,
|
|
14
|
-
} from "../../opencode-plugin-package";
|
|
15
|
-
import { installedVersionAt, isPreinstalledPluginPath } from "../../preinstalled-plugins";
|
|
16
|
-
import {
|
|
17
|
-
getOpenCodePluginReferences,
|
|
18
12
|
mergeOpenCodeConfigContent,
|
|
19
13
|
readOpenCodeConfig,
|
|
20
14
|
} from "../../../tools/setup/providers/opencode-format";
|
|
@@ -86,6 +80,7 @@ export class OpenCodeAdapter extends LaunchAdapter {
|
|
|
86
80
|
OPENCODE_CONFIG_CONTENT: mergeOpenCodeConfigContent(
|
|
87
81
|
{
|
|
88
82
|
permissions: renderCompanionExternalDirectoryPermissions(context.companionPath),
|
|
83
|
+
plugins: [getOpenCodePluginRoot()],
|
|
89
84
|
references: {
|
|
90
85
|
mate: context.companionPath,
|
|
91
86
|
},
|
|
@@ -130,75 +125,41 @@ export class OpenCodeAdapter extends LaunchAdapter {
|
|
|
130
125
|
);
|
|
131
126
|
}
|
|
132
127
|
|
|
133
|
-
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
path.join(".opencode", "opencode.json"),
|
|
138
|
-
expectedPluginReference,
|
|
139
|
-
)),
|
|
128
|
+
/** Asset errors carry their own reinstall hint; only companion errors are repaired by setup. */
|
|
129
|
+
const assetErrors = this.validatePluginAssets();
|
|
130
|
+
const companionErrors = [
|
|
131
|
+
...(await this.validateConfigReadable(context)),
|
|
140
132
|
...this.validateGuidance(context),
|
|
141
133
|
];
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
134
|
+
const errors = [...assetErrors, ...companionErrors];
|
|
135
|
+
if (errors.length === 0) return;
|
|
136
|
+
|
|
137
|
+
const lines = [
|
|
138
|
+
"OpenCode companion runtime is invalid.",
|
|
139
|
+
...errors.map((error) => `- ${error}`),
|
|
140
|
+
];
|
|
141
|
+
if (companionErrors.length > 0) {
|
|
142
|
+
lines.push(
|
|
143
|
+
"Repair the companion runtime by re-running `mate companion setup` in the companion repository or `mate opencode` from the working repository.",
|
|
150
144
|
);
|
|
151
145
|
}
|
|
146
|
+
throw new LaunchPreflightError(lines.join("\n"));
|
|
152
147
|
}
|
|
153
148
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
const { present, config } = await readOpenCodeConfig(configPath);
|
|
162
|
-
if (!present) {
|
|
163
|
-
return [`Unreadable OpenCode configuration: ${configPath}`];
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
const mateReferences = getOpenCodePluginReferences(config).filter(
|
|
167
|
-
isMateOpenCodePluginReference,
|
|
168
|
-
) as string[];
|
|
149
|
+
/** Launch-time sync leaves unparseable user config untouched; OpenCode would fail on it at startup. */
|
|
150
|
+
private async validateConfigReadable(context: AdapterContext): Promise<string[]> {
|
|
151
|
+
const configPath = path.join(context.companionPath, ".opencode", "opencode.json");
|
|
152
|
+
const { present } = await readOpenCodeConfig(configPath);
|
|
153
|
+
return present ? [] : [`Unreadable OpenCode configuration: ${configPath}`];
|
|
154
|
+
}
|
|
169
155
|
|
|
170
|
-
|
|
156
|
+
private validatePluginAssets(): string[] {
|
|
157
|
+
try {
|
|
158
|
+
validateOpenCodePluginAssets();
|
|
171
159
|
return [];
|
|
160
|
+
} catch (error) {
|
|
161
|
+
return [(error as Error).message];
|
|
172
162
|
}
|
|
173
|
-
|
|
174
|
-
// Setup writes one of two spellings, and both are current: the published
|
|
175
|
-
// spec on an ordinary workstation, and an absolute path into the
|
|
176
|
-
// machine-local workspace where the distribution supplied an installed
|
|
177
|
-
// copy. Comparing only against the spec would refuse the launch on exactly
|
|
178
|
-
// the deployments preinstalled binding exists for.
|
|
179
|
-
//
|
|
180
|
-
// A bound reference carries its version in the package it points at rather
|
|
181
|
-
// than in the string, so staleness is read off disk. It is still caught,
|
|
182
|
-
// and now names the version actually installed.
|
|
183
|
-
const expectedVersion = expectedPluginReference.slice(OPENCODE_PLUGIN_PACKAGE_NAME.length + 1);
|
|
184
|
-
const bound = mateReferences.find((reference) =>
|
|
185
|
-
isPreinstalledPluginPath(reference, OPENCODE_PLUGIN_PACKAGE_NAME),
|
|
186
|
-
);
|
|
187
|
-
if (bound !== undefined) {
|
|
188
|
-
const version = await installedVersionAt(bound);
|
|
189
|
-
if (version === expectedVersion) return [];
|
|
190
|
-
return [
|
|
191
|
-
`Stale Mate plugin package reference in ${configFile}: it points at ${bound}, which is ${version ?? "not installed"} rather than ${expectedVersion}.`,
|
|
192
|
-
];
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
if (mateReferences.length > 0) {
|
|
196
|
-
return [
|
|
197
|
-
`Stale Mate plugin package reference in ${configFile}: found ${mateReferences.join(", ")}.`,
|
|
198
|
-
];
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
return [`Missing Mate plugin package reference in ${configFile}.`];
|
|
202
163
|
}
|
|
203
164
|
|
|
204
165
|
// Self-check the guidance payload this launch is about to inject so a
|
|
@@ -1,40 +1,27 @@
|
|
|
1
1
|
// Git index and merge operations must remain sequential.
|
|
2
2
|
// oxlint-disable no-await-in-loop
|
|
3
|
-
import { execFile as execFileCallback, spawn as spawnChild } from "node:child_process";
|
|
4
3
|
import fs from "node:fs/promises";
|
|
5
4
|
import path from "node:path";
|
|
6
|
-
import { promisify } from "node:util";
|
|
7
5
|
|
|
8
6
|
import {
|
|
7
|
+
companionGit,
|
|
9
8
|
describeGitFailure,
|
|
10
|
-
gitEnvironment,
|
|
11
9
|
isAuthenticationFailure,
|
|
12
10
|
outputLines,
|
|
13
|
-
REMOTE_URLS_QUERY,
|
|
14
|
-
resolveUpstreamTargetWith,
|
|
15
|
-
shouldRetryWithoutSsh,
|
|
16
|
-
sshRewriteArgs,
|
|
17
11
|
type GitResult,
|
|
12
|
+
type UpstreamTarget,
|
|
18
13
|
} from "../../runtime/companion-git";
|
|
19
14
|
import { recordCompanionSync } from "../../runtime/companion-git-state";
|
|
20
15
|
import { LaunchPreflightError } from "./types";
|
|
21
16
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
/** Bounded but far above any diagnostic output; default 1 MiB kills git mid-merge on large trees. */
|
|
25
|
-
const GIT_MAX_BUFFER = 64 * 1024 * 1024;
|
|
26
|
-
|
|
27
|
-
export type GitCommandResult = GitResult;
|
|
17
|
+
type GitCommandResult = GitResult;
|
|
28
18
|
|
|
29
19
|
export { describeGitFailure };
|
|
30
20
|
|
|
31
|
-
export
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
cwd: string,
|
|
36
|
-
mode?: GitExecutionMode,
|
|
37
|
-
) => Promise<GitCommandResult>;
|
|
21
|
+
export interface CompanionGitSyncOptions {
|
|
22
|
+
/** Environment Git runs with. */
|
|
23
|
+
env?: Record<string, string | undefined>;
|
|
24
|
+
}
|
|
38
25
|
|
|
39
26
|
export interface CompanionGitSyncResult {
|
|
40
27
|
skipped: boolean;
|
|
@@ -84,66 +71,9 @@ export class CompanionGitSyncError extends LaunchPreflightError {
|
|
|
84
71
|
}
|
|
85
72
|
}
|
|
86
73
|
|
|
87
|
-
export const companionGitSyncDeps: { runGit: GitRunner } = {
|
|
88
|
-
runGit: async (args, cwd, mode = "captured") => {
|
|
89
|
-
const captured = gitEnvironment(process.env);
|
|
90
|
-
const { GIT_TERMINAL_PROMPT: _prompt, ...interactive } = captured;
|
|
91
|
-
const env = mode === "captured" ? captured : interactive;
|
|
92
|
-
|
|
93
|
-
if (mode === "interactive") {
|
|
94
|
-
return new Promise((resolve) => {
|
|
95
|
-
let settled = false;
|
|
96
|
-
const finish = (result: GitCommandResult) => {
|
|
97
|
-
if (settled) return;
|
|
98
|
-
settled = true;
|
|
99
|
-
resolve(result);
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
const child = spawnChild("git", [...args], {
|
|
103
|
-
cwd,
|
|
104
|
-
env,
|
|
105
|
-
stdio: "inherit",
|
|
106
|
-
});
|
|
107
|
-
child.once("error", (error) => {
|
|
108
|
-
finish({ status: 1, stdout: "", stderr: error.message });
|
|
109
|
-
});
|
|
110
|
-
child.once("close", (status) => {
|
|
111
|
-
finish({ status: status ?? 1, stdout: "", stderr: "" });
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
try {
|
|
117
|
-
const result = await execFile("git", [...args], {
|
|
118
|
-
cwd,
|
|
119
|
-
encoding: "utf8",
|
|
120
|
-
env,
|
|
121
|
-
maxBuffer: GIT_MAX_BUFFER,
|
|
122
|
-
});
|
|
123
|
-
return { status: 0, stdout: String(result.stdout), stderr: String(result.stderr) };
|
|
124
|
-
} catch (error) {
|
|
125
|
-
const commandError = error as {
|
|
126
|
-
code?: number | string;
|
|
127
|
-
stdout?: string;
|
|
128
|
-
stderr?: string;
|
|
129
|
-
message?: string;
|
|
130
|
-
};
|
|
131
|
-
return {
|
|
132
|
-
status: typeof commandError.code === "number" ? commandError.code : 1,
|
|
133
|
-
stdout: commandError.stdout ?? "",
|
|
134
|
-
stderr: commandError.stderr ?? commandError.message ?? "",
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
},
|
|
138
|
-
};
|
|
139
|
-
|
|
140
74
|
const MANAGED_ROOTS = [".mate", ".opencode", ".claude", ".agents", ".graphify"];
|
|
141
75
|
|
|
142
|
-
|
|
143
|
-
remote: string;
|
|
144
|
-
branch: string;
|
|
145
|
-
ref: string;
|
|
146
|
-
}
|
|
76
|
+
type SyncTarget = UpstreamTarget;
|
|
147
77
|
|
|
148
78
|
function isManagedPath(filePath: string): boolean {
|
|
149
79
|
const normalized = filePath.replaceAll("\\", "/").replace(/^\.\//, "");
|
|
@@ -151,7 +81,7 @@ function isManagedPath(filePath: string): boolean {
|
|
|
151
81
|
}
|
|
152
82
|
|
|
153
83
|
export class CompanionGitSync {
|
|
154
|
-
constructor(private readonly
|
|
84
|
+
constructor(private readonly options: CompanionGitSyncOptions = {}) {}
|
|
155
85
|
|
|
156
86
|
async sync(
|
|
157
87
|
companionPath: string,
|
|
@@ -247,23 +177,16 @@ export class CompanionGitSync {
|
|
|
247
177
|
};
|
|
248
178
|
}
|
|
249
179
|
|
|
250
|
-
/**
|
|
251
|
-
|
|
252
|
-
* still prompts for passphrases or host keys on the terminal itself.
|
|
253
|
-
*/
|
|
254
|
-
private async fetch(
|
|
180
|
+
/** Only this fetch may prompt, and only when the caller is interactive. */
|
|
181
|
+
private fetch(
|
|
255
182
|
companionPath: string,
|
|
256
183
|
target: SyncTarget,
|
|
257
184
|
interactiveGit: boolean,
|
|
258
185
|
): Promise<GitCommandResult> {
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
const overSsh = await this.command(companionPath, [...rewrite, ...args]);
|
|
264
|
-
if (!shouldRetryWithoutSsh(overSsh)) return overSsh;
|
|
265
|
-
}
|
|
266
|
-
return this.command(companionPath, args, interactiveGit ? "interactive" : undefined);
|
|
186
|
+
return companionGit(companionPath, {
|
|
187
|
+
prompt: interactiveGit ? "if-terminal" : "never",
|
|
188
|
+
env: this.options.env,
|
|
189
|
+
}).fetch([target.remote, target.branch]);
|
|
267
190
|
}
|
|
268
191
|
|
|
269
192
|
private async mergeAndRestore(
|
|
@@ -376,7 +299,10 @@ export class CompanionGitSync {
|
|
|
376
299
|
* must never disagree about which upstream they mean.
|
|
377
300
|
*/
|
|
378
301
|
private async resolveSyncTarget(companionPath: string): Promise<SyncTarget> {
|
|
379
|
-
const target = await
|
|
302
|
+
const target = await companionGit(companionPath, {
|
|
303
|
+
prompt: "never",
|
|
304
|
+
env: this.options.env,
|
|
305
|
+
}).upstreamTarget();
|
|
380
306
|
if (target) return target;
|
|
381
307
|
|
|
382
308
|
throw this.failure(
|
|
@@ -483,12 +409,8 @@ export class CompanionGitSync {
|
|
|
483
409
|
}
|
|
484
410
|
}
|
|
485
411
|
|
|
486
|
-
private
|
|
487
|
-
companionPath:
|
|
488
|
-
args: readonly string[],
|
|
489
|
-
mode?: GitExecutionMode,
|
|
490
|
-
): Promise<GitCommandResult> {
|
|
491
|
-
return mode ? this.runGit(args, companionPath, mode) : this.runGit(args, companionPath);
|
|
412
|
+
private command(companionPath: string, args: readonly string[]): Promise<GitCommandResult> {
|
|
413
|
+
return companionGit(companionPath, { prompt: "never", env: this.options.env }).run(args);
|
|
492
414
|
}
|
|
493
415
|
|
|
494
416
|
private detail(result: GitCommandResult): string {
|
|
@@ -510,9 +432,5 @@ export async function syncCompanionGit(
|
|
|
510
432
|
workingRepoPath?: string,
|
|
511
433
|
interactiveGit = false,
|
|
512
434
|
): Promise<CompanionGitSyncResult> {
|
|
513
|
-
return new CompanionGitSync(
|
|
514
|
-
companionPath,
|
|
515
|
-
workingRepoPath,
|
|
516
|
-
interactiveGit,
|
|
517
|
-
);
|
|
435
|
+
return new CompanionGitSync().sync(companionPath, workingRepoPath, interactiveGit);
|
|
518
436
|
}
|