@uniqbit/mate-core 0.18.1-canary.0 → 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 +13 -6
- package/src/cli/commands/artifact/finish/engine.ts +1 -1
- package/src/cli/commands/artifact/finish/git.ts +75 -51
- package/src/cli/commands/companion/hub.ts +1 -1
- package/src/cli/commands/companion/link.ts +13 -59
- package/src/cli/commands/doctor.ts +30 -4
- package/src/cli/commands/install.ts +17 -1
- 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/terminal-launch.ts +1 -51
- package/src/cli/commands/studio/terminal.ts +2 -13
- 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 +29 -93
- package/src/lib/orchestrator/companion-hub.ts +71 -110
- package/src/lib/orchestrator/repo-local-registry.ts +0 -21
- package/src/lib/orchestrator/types.ts +0 -6
- 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 +327 -84
- package/src/runtime/companion-sync.ts +34 -43
- 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/frozen.ts +24 -3
- package/src/tools/setup/dynamic-plugins/loader.ts +16 -0
- package/src/tools/setup/dynamic-plugins/policy.ts +55 -0
- package/src/tools/setup/dynamic-plugins/staging.ts +55 -0
- package/src/tools/setup/dynamic-plugins/verify.ts +22 -18
- 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 -29
|
@@ -1,37 +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
|
-
resolveUpstreamTargetWith,
|
|
14
11
|
type GitResult,
|
|
12
|
+
type UpstreamTarget,
|
|
15
13
|
} from "../../runtime/companion-git";
|
|
16
14
|
import { recordCompanionSync } from "../../runtime/companion-git-state";
|
|
17
15
|
import { LaunchPreflightError } from "./types";
|
|
18
16
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
/** Bounded but far above any diagnostic output; default 1 MiB kills git mid-merge on large trees. */
|
|
22
|
-
const GIT_MAX_BUFFER = 64 * 1024 * 1024;
|
|
23
|
-
|
|
24
|
-
export type GitCommandResult = GitResult;
|
|
17
|
+
type GitCommandResult = GitResult;
|
|
25
18
|
|
|
26
19
|
export { describeGitFailure };
|
|
27
20
|
|
|
28
|
-
export
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
cwd: string,
|
|
33
|
-
mode?: GitExecutionMode,
|
|
34
|
-
) => Promise<GitCommandResult>;
|
|
21
|
+
export interface CompanionGitSyncOptions {
|
|
22
|
+
/** Environment Git runs with. */
|
|
23
|
+
env?: Record<string, string | undefined>;
|
|
24
|
+
}
|
|
35
25
|
|
|
36
26
|
export interface CompanionGitSyncResult {
|
|
37
27
|
skipped: boolean;
|
|
@@ -81,66 +71,9 @@ export class CompanionGitSyncError extends LaunchPreflightError {
|
|
|
81
71
|
}
|
|
82
72
|
}
|
|
83
73
|
|
|
84
|
-
export const companionGitSyncDeps: { runGit: GitRunner } = {
|
|
85
|
-
runGit: async (args, cwd, mode = "captured") => {
|
|
86
|
-
const captured = gitEnvironment(process.env);
|
|
87
|
-
const { GIT_TERMINAL_PROMPT: _prompt, ...interactive } = captured;
|
|
88
|
-
const env = mode === "captured" ? captured : interactive;
|
|
89
|
-
|
|
90
|
-
if (mode === "interactive") {
|
|
91
|
-
return new Promise((resolve) => {
|
|
92
|
-
let settled = false;
|
|
93
|
-
const finish = (result: GitCommandResult) => {
|
|
94
|
-
if (settled) return;
|
|
95
|
-
settled = true;
|
|
96
|
-
resolve(result);
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
const child = spawnChild("git", [...args], {
|
|
100
|
-
cwd,
|
|
101
|
-
env,
|
|
102
|
-
stdio: "inherit",
|
|
103
|
-
});
|
|
104
|
-
child.once("error", (error) => {
|
|
105
|
-
finish({ status: 1, stdout: "", stderr: error.message });
|
|
106
|
-
});
|
|
107
|
-
child.once("close", (status) => {
|
|
108
|
-
finish({ status: status ?? 1, stdout: "", stderr: "" });
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
try {
|
|
114
|
-
const result = await execFile("git", [...args], {
|
|
115
|
-
cwd,
|
|
116
|
-
encoding: "utf8",
|
|
117
|
-
env,
|
|
118
|
-
maxBuffer: GIT_MAX_BUFFER,
|
|
119
|
-
});
|
|
120
|
-
return { status: 0, stdout: String(result.stdout), stderr: String(result.stderr) };
|
|
121
|
-
} catch (error) {
|
|
122
|
-
const commandError = error as {
|
|
123
|
-
code?: number | string;
|
|
124
|
-
stdout?: string;
|
|
125
|
-
stderr?: string;
|
|
126
|
-
message?: string;
|
|
127
|
-
};
|
|
128
|
-
return {
|
|
129
|
-
status: typeof commandError.code === "number" ? commandError.code : 1,
|
|
130
|
-
stdout: commandError.stdout ?? "",
|
|
131
|
-
stderr: commandError.stderr ?? commandError.message ?? "",
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
},
|
|
135
|
-
};
|
|
136
|
-
|
|
137
74
|
const MANAGED_ROOTS = [".mate", ".opencode", ".claude", ".agents", ".graphify"];
|
|
138
75
|
|
|
139
|
-
|
|
140
|
-
remote: string;
|
|
141
|
-
branch: string;
|
|
142
|
-
ref: string;
|
|
143
|
-
}
|
|
76
|
+
type SyncTarget = UpstreamTarget;
|
|
144
77
|
|
|
145
78
|
function isManagedPath(filePath: string): boolean {
|
|
146
79
|
const normalized = filePath.replaceAll("\\", "/").replace(/^\.\//, "");
|
|
@@ -148,7 +81,7 @@ function isManagedPath(filePath: string): boolean {
|
|
|
148
81
|
}
|
|
149
82
|
|
|
150
83
|
export class CompanionGitSync {
|
|
151
|
-
constructor(private readonly
|
|
84
|
+
constructor(private readonly options: CompanionGitSyncOptions = {}) {}
|
|
152
85
|
|
|
153
86
|
async sync(
|
|
154
87
|
companionPath: string,
|
|
@@ -172,11 +105,7 @@ export class CompanionGitSync {
|
|
|
172
105
|
}
|
|
173
106
|
const dirty = outputLines(before.stdout).length > 0;
|
|
174
107
|
|
|
175
|
-
const fetch = await this.
|
|
176
|
-
companionPath,
|
|
177
|
-
["fetch", target.remote, target.branch],
|
|
178
|
-
interactiveGit ? "interactive" : undefined,
|
|
179
|
-
);
|
|
108
|
+
const fetch = await this.fetch(companionPath, target, interactiveGit);
|
|
180
109
|
if (fetch.status !== 0) {
|
|
181
110
|
const authenticationFailure = isAuthenticationFailure(fetch);
|
|
182
111
|
const recovery = interactiveGit
|
|
@@ -248,6 +177,18 @@ export class CompanionGitSync {
|
|
|
248
177
|
};
|
|
249
178
|
}
|
|
250
179
|
|
|
180
|
+
/** Only this fetch may prompt, and only when the caller is interactive. */
|
|
181
|
+
private fetch(
|
|
182
|
+
companionPath: string,
|
|
183
|
+
target: SyncTarget,
|
|
184
|
+
interactiveGit: boolean,
|
|
185
|
+
): Promise<GitCommandResult> {
|
|
186
|
+
return companionGit(companionPath, {
|
|
187
|
+
prompt: interactiveGit ? "if-terminal" : "never",
|
|
188
|
+
env: this.options.env,
|
|
189
|
+
}).fetch([target.remote, target.branch]);
|
|
190
|
+
}
|
|
191
|
+
|
|
251
192
|
private async mergeAndRestore(
|
|
252
193
|
companionPath: string,
|
|
253
194
|
target: SyncTarget,
|
|
@@ -358,7 +299,10 @@ export class CompanionGitSync {
|
|
|
358
299
|
* must never disagree about which upstream they mean.
|
|
359
300
|
*/
|
|
360
301
|
private async resolveSyncTarget(companionPath: string): Promise<SyncTarget> {
|
|
361
|
-
const target = await
|
|
302
|
+
const target = await companionGit(companionPath, {
|
|
303
|
+
prompt: "never",
|
|
304
|
+
env: this.options.env,
|
|
305
|
+
}).upstreamTarget();
|
|
362
306
|
if (target) return target;
|
|
363
307
|
|
|
364
308
|
throw this.failure(
|
|
@@ -465,12 +409,8 @@ export class CompanionGitSync {
|
|
|
465
409
|
}
|
|
466
410
|
}
|
|
467
411
|
|
|
468
|
-
private
|
|
469
|
-
companionPath:
|
|
470
|
-
args: readonly string[],
|
|
471
|
-
mode?: GitExecutionMode,
|
|
472
|
-
): Promise<GitCommandResult> {
|
|
473
|
-
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);
|
|
474
414
|
}
|
|
475
415
|
|
|
476
416
|
private detail(result: GitCommandResult): string {
|
|
@@ -492,9 +432,5 @@ export async function syncCompanionGit(
|
|
|
492
432
|
workingRepoPath?: string,
|
|
493
433
|
interactiveGit = false,
|
|
494
434
|
): Promise<CompanionGitSyncResult> {
|
|
495
|
-
return new CompanionGitSync(
|
|
496
|
-
companionPath,
|
|
497
|
-
workingRepoPath,
|
|
498
|
-
interactiveGit,
|
|
499
|
-
);
|
|
435
|
+
return new CompanionGitSync().sync(companionPath, workingRepoPath, interactiveGit);
|
|
500
436
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { spawnSync } from "node:child_process";
|
|
2
1
|
import fs from "node:fs/promises";
|
|
3
2
|
import path from "node:path";
|
|
4
3
|
|
|
@@ -17,15 +16,13 @@ import {
|
|
|
17
16
|
import { hydrateDynamicPlugins } from "../../tools/setup/dynamic-plugins/hydrate";
|
|
18
17
|
import { applySetupCompatibilities } from "../../tools/setup";
|
|
19
18
|
import { findRepoLocalRegistryFile } from "./repo-local-registry";
|
|
19
|
+
import { companionGit, describeGitFailure, type CompanionGit } from "../../runtime/companion-git";
|
|
20
20
|
|
|
21
|
-
export interface
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
stderr: string;
|
|
21
|
+
export interface HubGitOptions {
|
|
22
|
+
/** Environment Git runs with. */
|
|
23
|
+
env?: Record<string, string | undefined>;
|
|
25
24
|
}
|
|
26
25
|
|
|
27
|
-
export type GitCommand = (cwd: string, args: string[]) => GitCommandResult;
|
|
28
|
-
|
|
29
26
|
export interface HubSource {
|
|
30
27
|
kind: "git" | "local";
|
|
31
28
|
path?: string;
|
|
@@ -46,16 +43,15 @@ export interface HubPluginSyncDeps {
|
|
|
46
43
|
setup?: (companionPath: string, config: FrameworkConfig, mode: "setup" | "sync") => Promise<void>;
|
|
47
44
|
}
|
|
48
45
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
};
|
|
46
|
+
/** Hub work is operator-driven, so it may prompt when a terminal is attached. */
|
|
47
|
+
function hubGit(cwd: string, options: HubGitOptions = {}): CompanionGit {
|
|
48
|
+
return companionGit(cwd, { prompt: "if-terminal", env: options.env });
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async function gitOutput(git: CompanionGit, args: string[]): Promise<string | null> {
|
|
52
|
+
const result = await git.run(args);
|
|
53
|
+
const stdout = result.stdout.trim();
|
|
54
|
+
return result.status === 0 && stdout ? stdout : null;
|
|
59
55
|
}
|
|
60
56
|
|
|
61
57
|
function isInsideDir(parent: string, candidate: string): boolean {
|
|
@@ -137,32 +133,36 @@ export async function initializeCompanionHub(
|
|
|
137
133
|
return hubPath;
|
|
138
134
|
}
|
|
139
135
|
|
|
140
|
-
export function discoverGitSource(
|
|
136
|
+
export async function discoverGitSource(
|
|
141
137
|
sourcePath: string,
|
|
142
|
-
|
|
143
|
-
): HubSource {
|
|
144
|
-
const
|
|
145
|
-
if (
|
|
146
|
-
|
|
147
|
-
const remote = git(sourcePath, ["config", "--get", "remote.origin.url"]);
|
|
148
|
-
if (remote.status !== 0 || !remote.stdout)
|
|
138
|
+
options: HubGitOptions = {},
|
|
139
|
+
): Promise<HubSource> {
|
|
140
|
+
const git = companionGit(sourcePath, { prompt: "never", env: options.env });
|
|
141
|
+
if (!(await gitOutput(git, ["rev-parse", "--show-toplevel"]))) {
|
|
149
142
|
return { kind: "local", path: path.resolve(sourcePath) };
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const remote = await gitOutput(git, ["config", "--get", "remote.origin.url"]);
|
|
146
|
+
if (!remote) return { kind: "local", path: path.resolve(sourcePath) };
|
|
150
147
|
|
|
151
|
-
const branch = git
|
|
148
|
+
const branch = await gitOutput(git, ["symbolic-ref", "--short", "HEAD"]);
|
|
152
149
|
return {
|
|
153
150
|
kind: "git",
|
|
154
151
|
path: path.resolve(sourcePath),
|
|
155
|
-
url: remote
|
|
156
|
-
ref: branch
|
|
152
|
+
url: remote,
|
|
153
|
+
ref: branch ?? undefined,
|
|
157
154
|
};
|
|
158
155
|
}
|
|
159
156
|
|
|
160
|
-
export function discoverHubSource(
|
|
157
|
+
export async function discoverHubSource(
|
|
158
|
+
source: string,
|
|
159
|
+
options: HubGitOptions = {},
|
|
160
|
+
): Promise<HubSource> {
|
|
161
161
|
const trimmed = source.trim();
|
|
162
162
|
if (/^(?:https?|ssh|git):\/\//i.test(trimmed) || trimmed.startsWith("git@")) {
|
|
163
163
|
return { kind: "git", url: trimmed };
|
|
164
164
|
}
|
|
165
|
-
return discoverGitSource(path.resolve(trimmed),
|
|
165
|
+
return discoverGitSource(path.resolve(trimmed), options);
|
|
166
166
|
}
|
|
167
167
|
|
|
168
168
|
function sourceForManifest(source: HubSource, fallbackPath: string): HubMemberSource {
|
|
@@ -172,15 +172,6 @@ function sourceForManifest(source: HubSource, fallbackPath: string): HubMemberSo
|
|
|
172
172
|
return { kind: "local", path: source.path ?? fallbackPath };
|
|
173
173
|
}
|
|
174
174
|
|
|
175
|
-
function gitOutputOrThrow(result: GitCommandResult, operation: string): string {
|
|
176
|
-
if (result.status !== 0) {
|
|
177
|
-
throw new Error(
|
|
178
|
-
`${operation} failed: ${result.stderr || result.stdout || "unknown Git error"}`,
|
|
179
|
-
);
|
|
180
|
-
}
|
|
181
|
-
return result.stdout;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
175
|
async function copyWithoutGit(sourcePath: string, destination: string): Promise<void> {
|
|
185
176
|
await fs.cp(sourcePath, destination, {
|
|
186
177
|
recursive: true,
|
|
@@ -197,16 +188,19 @@ async function assertMaterializedCompanion(memberPath: string): Promise<void> {
|
|
|
197
188
|
}
|
|
198
189
|
}
|
|
199
190
|
|
|
200
|
-
async function currentCommit(memberPath: string,
|
|
201
|
-
|
|
191
|
+
async function currentCommit(memberPath: string, options: HubGitOptions): Promise<string> {
|
|
192
|
+
const head = await hubGit(memberPath, options).run(["rev-parse", "HEAD"]);
|
|
193
|
+
if (head.status !== 0) {
|
|
194
|
+
throw new Error(`Reading ${memberPath} commit failed: ${describeGitFailure(head)}`);
|
|
195
|
+
}
|
|
196
|
+
return head.stdout.trim();
|
|
202
197
|
}
|
|
203
198
|
|
|
204
199
|
export async function materializeHubMember(
|
|
205
200
|
hubPath: string,
|
|
206
201
|
source: HubSource,
|
|
207
|
-
options: { id?: string; memberPath?: string
|
|
202
|
+
options: { id?: string; memberPath?: string } & HubGitOptions = {},
|
|
208
203
|
): Promise<HubMember> {
|
|
209
|
-
const git = options.git ?? defaultGitCommand;
|
|
210
204
|
const sourceName = source.url ?? source.path ?? "companion";
|
|
211
205
|
const id = normalizeHubMemberId(options.id ?? path.basename(sourceName));
|
|
212
206
|
const relativePath = options.memberPath ?? memberPathForId(id);
|
|
@@ -217,10 +211,12 @@ export async function materializeHubMember(
|
|
|
217
211
|
await fs.mkdir(path.dirname(destination), { recursive: true });
|
|
218
212
|
try {
|
|
219
213
|
if (source.kind === "git") {
|
|
220
|
-
const
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
214
|
+
const clone = await hubGit(hubPath, options).clone(source.url!, destination, {
|
|
215
|
+
branch: source.ref,
|
|
216
|
+
});
|
|
217
|
+
if (clone.status !== 0) {
|
|
218
|
+
throw new Error(`Cloning ${source.url} failed: ${describeGitFailure(clone)}`);
|
|
219
|
+
}
|
|
224
220
|
} else {
|
|
225
221
|
await copyWithoutGit(source.path!, destination);
|
|
226
222
|
}
|
|
@@ -231,7 +227,9 @@ export async function materializeHubMember(
|
|
|
231
227
|
path: relativePath,
|
|
232
228
|
source: sourceForManifest(source, source.path ?? relativePath),
|
|
233
229
|
};
|
|
234
|
-
if (source.kind === "git")
|
|
230
|
+
if (source.kind === "git") {
|
|
231
|
+
member.materializedCommit = await currentCommit(destination, options);
|
|
232
|
+
}
|
|
235
233
|
return member;
|
|
236
234
|
} catch (error) {
|
|
237
235
|
await fs.rm(destination, { recursive: true, force: true });
|
|
@@ -242,7 +240,7 @@ export async function materializeHubMember(
|
|
|
242
240
|
export async function addHubMember(
|
|
243
241
|
hubPath: string,
|
|
244
242
|
source: HubSource,
|
|
245
|
-
options: { id?: string; memberPath?: string
|
|
243
|
+
options: { id?: string; memberPath?: string } & HubGitOptions = {},
|
|
246
244
|
): Promise<HubMember> {
|
|
247
245
|
const { config, store } = await assertHubRoot(hubPath);
|
|
248
246
|
const member = await materializeHubMember(hubPath, source, options);
|
|
@@ -255,94 +253,57 @@ export async function addHubMember(
|
|
|
255
253
|
return member;
|
|
256
254
|
}
|
|
257
255
|
|
|
258
|
-
function syncTarget(memberPath: string, git: GitCommand): string | null {
|
|
259
|
-
const upstream = git(memberPath, [
|
|
260
|
-
"rev-parse",
|
|
261
|
-
"--abbrev-ref",
|
|
262
|
-
"--symbolic-full-name",
|
|
263
|
-
"@{upstream}",
|
|
264
|
-
]);
|
|
265
|
-
if (upstream.status !== 0 || !upstream.stdout) return null;
|
|
266
|
-
return upstream.stdout;
|
|
267
|
-
}
|
|
268
|
-
|
|
269
256
|
async function syncHubMember(
|
|
270
257
|
hubPath: string,
|
|
271
258
|
member: HubMember,
|
|
272
|
-
|
|
259
|
+
options: HubGitOptions,
|
|
273
260
|
): Promise<HubSyncResult> {
|
|
274
261
|
const memberPath = path.resolve(hubPath, member.path);
|
|
275
262
|
if (member.source.kind === "local") {
|
|
276
263
|
return { id: member.id, status: "local-only", message: "local-only child has no Git source" };
|
|
277
264
|
}
|
|
265
|
+
const git = hubGit(memberPath, options);
|
|
266
|
+
const failed = (message: string): HubSyncResult => ({ id: member.id, status: "failed", message });
|
|
278
267
|
|
|
279
|
-
const dirty = git(
|
|
280
|
-
if (dirty.status !== 0)
|
|
281
|
-
|
|
282
|
-
id: member.id,
|
|
283
|
-
status: "failed",
|
|
284
|
-
message: dirty.stderr || "unable to inspect Git state",
|
|
285
|
-
};
|
|
286
|
-
}
|
|
287
|
-
if (dirty.stdout) {
|
|
268
|
+
const dirty = await git.run(["status", "--porcelain=v1", "--untracked-files=all"]);
|
|
269
|
+
if (dirty.status !== 0) return failed(dirty.stderr.trim() || "unable to inspect Git state");
|
|
270
|
+
if (dirty.stdout.trim()) {
|
|
288
271
|
return { id: member.id, status: "dirty", message: "local changes must be resolved first" };
|
|
289
272
|
}
|
|
290
273
|
|
|
291
|
-
const fetch = git(
|
|
292
|
-
if (fetch.status !== 0)
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
const
|
|
296
|
-
if (!
|
|
297
|
-
|
|
298
|
-
}
|
|
299
|
-
const counts = git(memberPath, ["rev-list", "--left-right", "--count", `HEAD...${target}`]);
|
|
300
|
-
if (counts.status !== 0) {
|
|
301
|
-
return {
|
|
302
|
-
id: member.id,
|
|
303
|
-
status: "failed",
|
|
304
|
-
message: counts.stderr || "unable to compare branches",
|
|
305
|
-
};
|
|
306
|
-
}
|
|
307
|
-
const [ahead, behind] = counts.stdout.split(/\s+/).map(Number);
|
|
308
|
-
if (ahead > 0 && behind > 0) {
|
|
274
|
+
const fetch = await git.fetch(["origin"]);
|
|
275
|
+
if (fetch.status !== 0) return failed(fetch.stderr.trim() || "fetch failed");
|
|
276
|
+
const target = await git.upstreamTarget();
|
|
277
|
+
if (!target) return failed("no synchronization target resolves");
|
|
278
|
+
const fork = await git.forkState(target.ref);
|
|
279
|
+
if (!fork) return failed("unable to compare branches");
|
|
280
|
+
if (fork.forked) {
|
|
309
281
|
return {
|
|
310
282
|
id: member.id,
|
|
311
283
|
status: "divergent",
|
|
312
284
|
message: "local and remote branches have diverged",
|
|
313
285
|
};
|
|
314
286
|
}
|
|
315
|
-
if (behind === 0) {
|
|
316
|
-
const commit = await currentCommit(memberPath, git);
|
|
287
|
+
if (fork.behind === 0) {
|
|
317
288
|
return {
|
|
318
289
|
id: member.id,
|
|
319
290
|
status: "up-to-date",
|
|
320
291
|
message: "already up to date",
|
|
321
|
-
materializedCommit:
|
|
292
|
+
materializedCommit: await currentCommit(memberPath, options),
|
|
322
293
|
};
|
|
323
294
|
}
|
|
324
295
|
|
|
325
|
-
const readTree = git(
|
|
296
|
+
const readTree = await git.run(["read-tree", "-u", "-m", target.ref]);
|
|
326
297
|
if (readTree.status !== 0) {
|
|
327
|
-
return
|
|
328
|
-
id: member.id,
|
|
329
|
-
status: "failed",
|
|
330
|
-
message: readTree.stderr || "fast-forward worktree update failed",
|
|
331
|
-
};
|
|
298
|
+
return failed(readTree.stderr.trim() || "fast-forward worktree update failed");
|
|
332
299
|
}
|
|
333
|
-
const branch = git
|
|
334
|
-
if (branch
|
|
335
|
-
|
|
336
|
-
}
|
|
337
|
-
const updateRef = git(memberPath, ["update-ref", `refs/heads/${branch.stdout}`, target, "HEAD"]);
|
|
300
|
+
const branch = await gitOutput(git, ["symbolic-ref", "--quiet", "--short", "HEAD"]);
|
|
301
|
+
if (!branch) return failed("cannot advance a detached HEAD");
|
|
302
|
+
const updateRef = await git.run(["update-ref", `refs/heads/${branch}`, target.ref, "HEAD"]);
|
|
338
303
|
if (updateRef.status !== 0) {
|
|
339
|
-
return
|
|
340
|
-
id: member.id,
|
|
341
|
-
status: "failed",
|
|
342
|
-
message: updateRef.stderr || "fast-forward ref update failed",
|
|
343
|
-
};
|
|
304
|
+
return failed(updateRef.stderr.trim() || "fast-forward ref update failed");
|
|
344
305
|
}
|
|
345
|
-
const commit = await currentCommit(memberPath,
|
|
306
|
+
const commit = await currentCommit(memberPath, options);
|
|
346
307
|
return {
|
|
347
308
|
id: member.id,
|
|
348
309
|
status: "updated",
|
|
@@ -353,12 +314,12 @@ async function syncHubMember(
|
|
|
353
314
|
|
|
354
315
|
export async function syncHub(
|
|
355
316
|
hubPath: string,
|
|
356
|
-
|
|
317
|
+
options: HubGitOptions = {},
|
|
357
318
|
): Promise<HubSyncResult[]> {
|
|
358
319
|
const { config, store } = await assertHubRoot(hubPath);
|
|
359
320
|
const results: HubSyncResult[] = [];
|
|
360
321
|
for (const member of config.hub!.companions) {
|
|
361
|
-
const result = await syncHubMember(hubPath, member,
|
|
322
|
+
const result = await syncHubMember(hubPath, member, options);
|
|
362
323
|
results.push(result);
|
|
363
324
|
if (result.materializedCommit && result.status === "updated") {
|
|
364
325
|
member.materializedCommit = result.materializedCommit;
|
|
@@ -75,27 +75,6 @@ export async function findRepoLocalLinkedRepository(cwd: string): Promise<Linked
|
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
/** Returns other companion paths this repo is locally linked to, excluding `excludePath`. */
|
|
79
|
-
export async function listOtherRepoLocalCompanionPaths(
|
|
80
|
-
repoPath: string,
|
|
81
|
-
excludePath: string,
|
|
82
|
-
): Promise<string[]> {
|
|
83
|
-
const resolvedExclude = path.resolve(excludePath);
|
|
84
|
-
try {
|
|
85
|
-
const raw = await fs.readFile(repoLocalRegistryPath(repoPath), "utf8");
|
|
86
|
-
const parsed = parse(raw) as Partial<RepoLocalRegistry> | null;
|
|
87
|
-
if (!parsed || !Array.isArray(parsed.companions)) return [];
|
|
88
|
-
const paths: string[] = [];
|
|
89
|
-
for (const pointer of parsed.companions) {
|
|
90
|
-
const resolvedPath = path.resolve(pointer.path);
|
|
91
|
-
if (resolvedPath !== resolvedExclude) paths.push(resolvedPath);
|
|
92
|
-
}
|
|
93
|
-
return paths;
|
|
94
|
-
} catch {
|
|
95
|
-
return [];
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
78
|
/** Walks up from `cwd` looking for the nearest ancestor holding a repo-local registry file. */
|
|
100
79
|
export async function findRepoLocalRegistryFile(
|
|
101
80
|
cwd: string,
|
|
@@ -120,11 +120,6 @@ export interface PluginDeclaration {
|
|
|
120
120
|
config?: unknown;
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
export interface StudioTerminalConfig {
|
|
124
|
-
/** Persona selected with `--agent` when Studio's terminal starts a provider. */
|
|
125
|
-
agent?: string;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
123
|
export interface FrameworkConfig {
|
|
129
124
|
type?: FrameworkType;
|
|
130
125
|
git?: GitModeProfile;
|
|
@@ -136,7 +131,6 @@ export interface FrameworkConfig {
|
|
|
136
131
|
cliTools?: CliToolConfig[];
|
|
137
132
|
packageManagers?: string[];
|
|
138
133
|
engines?: EngineConstraints;
|
|
139
|
-
studio?: { terminal?: StudioTerminalConfig };
|
|
140
134
|
}
|
|
141
135
|
|
|
142
136
|
export interface CompanionRegistryConfig {
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
1
2
|
import fs from "node:fs/promises";
|
|
2
3
|
import path from "node:path";
|
|
4
|
+
import { promisify } from "node:util";
|
|
3
5
|
|
|
4
6
|
import { FRAMEWORK_NAME } from "../../framework";
|
|
7
|
+
import { gitEnvironment } from "../../runtime/companion-git";
|
|
5
8
|
import { readProjectionFile } from "../../runtime/projection";
|
|
6
9
|
import { repoLocalDirPath } from "../../runtime/repo-local";
|
|
7
|
-
import { companionGitSyncDeps } from "./companion-git-sync";
|
|
8
10
|
import type { GlobalConfigStore } from "./global-config-store";
|
|
9
11
|
import { projectionEntries } from "./projection-entries";
|
|
10
12
|
import {
|
|
@@ -27,6 +29,8 @@ import {
|
|
|
27
29
|
} from "./projection-types";
|
|
28
30
|
import type { FrameworkConfig, LinkedRepository } from "./types";
|
|
29
31
|
|
|
32
|
+
const execFileAsync = promisify(execFile);
|
|
33
|
+
|
|
30
34
|
/**
|
|
31
35
|
* The owner of the Managed Projection: every path Mate places inside a Working
|
|
32
36
|
* Repository is written and removed from here, through the declarations in
|
|
@@ -189,8 +193,7 @@ export type RuntimeDocumentsResult =
|
|
|
189
193
|
| { kind: "failed"; document: string; error: Error };
|
|
190
194
|
|
|
191
195
|
/**
|
|
192
|
-
* Which of the given repo-relative paths Git already has in its index.
|
|
193
|
-
* through the same runner the companion sync uses rather than a second spawn.
|
|
196
|
+
* Which of the given repo-relative paths Git already has in its index.
|
|
194
197
|
* Best-effort by construction: a directory that is no repository, a Git that is
|
|
195
198
|
* not installed, and a `ls-files` that fails for any other reason all answer
|
|
196
199
|
* "nothing tracked" — this feeds a warning, and a warning may not fail a wrap.
|
|
@@ -198,12 +201,13 @@ export type RuntimeDocumentsResult =
|
|
|
198
201
|
async function trackedDocuments(repoPath: string, documentPaths: string[]): Promise<string[]> {
|
|
199
202
|
if (documentPaths.length === 0) return [];
|
|
200
203
|
try {
|
|
201
|
-
const
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
204
|
+
const { stdout } = await execFileAsync("git", ["ls-files", "-z", "--", ...documentPaths], {
|
|
205
|
+
cwd: path.resolve(repoPath),
|
|
206
|
+
encoding: "utf8",
|
|
207
|
+
env: gitEnvironment(),
|
|
208
|
+
maxBuffer: 64 * 1024 * 1024,
|
|
209
|
+
});
|
|
210
|
+
return stdout.split("\0").filter(Boolean);
|
|
207
211
|
} catch {
|
|
208
212
|
return [];
|
|
209
213
|
}
|
package/src/lib/package-paths.ts
CHANGED
|
@@ -55,6 +55,38 @@ export function validateClaudePluginAssets(pluginRoot = getClaudePluginRoot()):
|
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
/**
|
|
59
|
+
* Resolved bundled OpenCode plugin root: a distribution asset root that ships
|
|
60
|
+
* `opencode-plugin/` wins over core's bundled default. Machine-local, so it
|
|
61
|
+
* reaches OpenCode only through the launch overlay and the git-excluded
|
|
62
|
+
* projection, never a committed config.
|
|
63
|
+
*/
|
|
64
|
+
export function getOpenCodePluginRoot(): string {
|
|
65
|
+
for (const root of getActiveDistribution().config.assetRoots ?? []) {
|
|
66
|
+
const candidate = path.join(root, "opencode-plugin");
|
|
67
|
+
if (fs.existsSync(candidate)) return candidate;
|
|
68
|
+
}
|
|
69
|
+
return path.resolve(import.meta.dirname, "../../opencode-plugin");
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Root entries OpenCode resolves for a plugin referenced by directory path. */
|
|
73
|
+
const OPENCODE_PLUGIN_ENTRIES = ["server.ts", "tui.tsx"] as const;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Verify the bundled OpenCode plugin entries exist. Throws naming the missing
|
|
77
|
+
* entries; `companion setup` cannot restore package files, so the fix is a reinstall.
|
|
78
|
+
*/
|
|
79
|
+
export function validateOpenCodePluginAssets(pluginRoot = getOpenCodePluginRoot()): void {
|
|
80
|
+
const missing = OPENCODE_PLUGIN_ENTRIES.filter(
|
|
81
|
+
(entry) => !fs.existsSync(path.join(pluginRoot, entry)),
|
|
82
|
+
);
|
|
83
|
+
if (missing.length > 0) {
|
|
84
|
+
throw new Error(
|
|
85
|
+
`bundled OpenCode plugin at ${pluginRoot} is missing: ${missing.join(", ")}. Reinstall Mate to restore it.`,
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
58
90
|
export function getReactDoctorBinPath(): string {
|
|
59
91
|
try {
|
|
60
92
|
const entryPath = require.resolve("react-doctor");
|
|
@@ -3,8 +3,6 @@ import path from "node:path";
|
|
|
3
3
|
|
|
4
4
|
import semver from "semver";
|
|
5
5
|
|
|
6
|
-
import { OPENCODE_PLUGIN_PACKAGE_NAME } from "./opencode-plugin-package";
|
|
7
|
-
import { getCurrentVersion } from "./update-checker";
|
|
8
6
|
import {
|
|
9
7
|
CONTEXT_MODE_NODE_REQUIREMENT,
|
|
10
8
|
CONTEXT_MODE_PACKAGE_NAME,
|
|
@@ -20,7 +18,6 @@ import { getLocalWorkspaceDir } from "./preinstalled-plugins";
|
|
|
20
18
|
function getDistributionLocalDependencies(): Record<string, string> {
|
|
21
19
|
return {
|
|
22
20
|
[CONTEXT_MODE_PACKAGE_NAME]: CONTEXT_MODE_VERSION,
|
|
23
|
-
[OPENCODE_PLUGIN_PACKAGE_NAME]: getCurrentVersion(),
|
|
24
21
|
};
|
|
25
22
|
}
|
|
26
23
|
|