@uniqbit/mate-core 0.16.0 → 0.17.0-canary.10

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.
Files changed (49) hide show
  1. package/package.json +2 -2
  2. package/src/cli/commands/companion/companion.ts +8 -0
  3. package/src/cli/commands/companion/prepare.ts +76 -0
  4. package/src/cli/commands/companion/register.ts +47 -0
  5. package/src/cli/commands/launch/claude.ts +4 -3
  6. package/src/cli/commands/launch/opencode.ts +4 -3
  7. package/src/cli/commands/launch/shared.ts +41 -28
  8. package/src/cli/commands/shared/companion-selection.ts +3 -1
  9. package/src/cli/commands/studio/index.ts +85 -6
  10. package/src/cli/commands/studio/routes.ts +1 -1
  11. package/src/cli/commands/studio/selection.ts +11 -2
  12. package/src/cli/commands/studio/server.ts +212 -17
  13. package/src/cli/commands/studio/vault.ts +607 -0
  14. package/src/cli/commands/studio/views/client.ts +141 -1
  15. package/src/cli/commands/studio/views/companion-selector.tsx +1 -1
  16. package/src/cli/commands/studio/views/document.tsx +137 -3
  17. package/src/cli/commands/studio/views/model.ts +13 -0
  18. package/src/cli/commands/studio/views/styles.ts +17 -0
  19. package/src/cli/commands/studio/views/workflow/steps.ts +10 -3
  20. package/src/cli/commands/update.ts +6 -6
  21. package/src/cli/main.ts +56 -4
  22. package/src/cli/usage.ts +6 -3
  23. package/src/index.ts +1 -0
  24. package/src/lib/context-mode-package.ts +7 -4
  25. package/src/lib/node-engine-version.ts +15 -0
  26. package/src/lib/opencode-plugin-package.ts +10 -4
  27. package/src/lib/orchestrator/adapters/base.ts +65 -10
  28. package/src/lib/orchestrator/adapters/opencode.ts +27 -2
  29. package/src/lib/orchestrator/companion-registration.ts +73 -0
  30. package/src/lib/orchestrator/framework-context.ts +29 -3
  31. package/src/lib/orchestrator/launcher.ts +46 -22
  32. package/src/lib/orchestrator/projection-record.ts +24 -0
  33. package/src/lib/orchestrator/types.ts +11 -0
  34. package/src/lib/package-root.ts +43 -0
  35. package/src/lib/prebuilt-workspace-prepare.ts +152 -0
  36. package/src/lib/prebuilt-workspace.ts +246 -0
  37. package/src/lib/preinstalled-plugins.ts +106 -0
  38. package/src/lib/update-checker.ts +39 -0
  39. package/src/opencode/companion-hooks.ts +45 -20
  40. package/src/playbooks/companion-guidance.ts +1 -0
  41. package/src/runtime/companion-guidance.ts +61 -15
  42. package/src/runtime/env.ts +3 -3
  43. package/src/runtime/index.ts +1 -0
  44. package/src/templates/capabilities/openspec-cap/mate-minimal/schema.yaml +2 -1
  45. package/src/tools/setup/__snapshots__/runtime-surface-golden.test.ts.snap +127 -77
  46. package/src/tools/setup/capabilities/context-mode.ts +34 -2
  47. package/src/tools/setup/capabilities/openspec.ts +12 -2
  48. package/src/tools/setup/plugin.ts +7 -1
  49. package/src/tools/setup/providers/opencode.ts +24 -5
@@ -3,6 +3,7 @@ import path from "node:path";
3
3
 
4
4
  import {
5
5
  CONTEXT_MODE_PACKAGE_NAME,
6
+ CONTEXT_MODE_VERSION,
6
7
  getContextModeInstallDir,
7
8
  getContextModePackageReference,
8
9
  installContextModePackage,
@@ -10,6 +11,7 @@ import {
10
11
  validateContextModePackage,
11
12
  } from "../../../lib/context-mode-package";
12
13
  import { warmOpenCodePackageCache } from "../../../lib/opencode-plugin-package";
14
+ import { installedVersionAt, isPreinstalledPluginPath } from "../../../lib/preinstalled-plugins";
13
15
  import type {
14
16
  CapabilityPlugin,
15
17
  LaunchPreflightContext,
@@ -69,17 +71,43 @@ async function assertNoMcpConflict(ctx: SetupContext, provider: "claude" | "open
69
71
  }
70
72
  }
71
73
 
74
+ /**
75
+ * Both spellings of a current reference are accepted, because the Runtime
76
+ * Surface writes either one: the published spec on an ordinary workstation, and
77
+ * an absolute path into the machine-local workspace where the distribution
78
+ * supplied an installed copy. Accepting only the first would refuse the launch
79
+ * on exactly the deployments preinstalled binding exists for.
80
+ *
81
+ * Staleness is still caught in both cases — a published reference by its
82
+ * version, a bound one by the version of the copy it points at — so this is not
83
+ * the looser check it might look like.
84
+ */
72
85
  async function validateOpenCodeReferences(ctx: LaunchPreflightContext): Promise<string[]> {
73
86
  const expected = getContextModePackageReference();
74
87
  const diagnostics: string[] = [];
75
88
  for (const name of ["opencode.json", "tui.json"]) {
76
89
  const configPath = path.join(ctx.companionPath, ".opencode", name);
77
90
  const { config } = await readOpenCodeConfig(configPath);
78
- if (!getOpenCodePluginReferences(config).includes(expected)) {
91
+ const references = getOpenCodePluginReferences(config);
92
+ if (references.includes(expected)) continue;
93
+
94
+ const bound = references.find(
95
+ (reference): reference is string =>
96
+ typeof reference === "string" &&
97
+ isPreinstalledPluginPath(reference, CONTEXT_MODE_PACKAGE_NAME),
98
+ );
99
+ if (bound !== undefined) {
100
+ const version = await installedVersionAt(bound);
101
+ if (version === CONTEXT_MODE_VERSION) continue;
79
102
  diagnostics.push(
80
- `Missing or stale context-mode package reference in ${configPath}; expected ${expected}.`,
103
+ `Stale context-mode package reference in ${configPath}; it points at ${bound}, which is ${version ?? "not installed"} rather than ${CONTEXT_MODE_VERSION}.`,
81
104
  );
105
+ continue;
82
106
  }
107
+
108
+ diagnostics.push(
109
+ `Missing or stale context-mode package reference in ${configPath}; expected ${expected}.`,
110
+ );
83
111
  }
84
112
  return diagnostics;
85
113
  }
@@ -117,6 +145,10 @@ export function createContextModePlugin(deps: ContextModePluginDeps = {}): Capab
117
145
  reference: getContextModePackageReference(),
118
146
  isManagedReference: isContextModePackageReference,
119
147
  configFiles: ["opencode.json", "tui.json"],
148
+ preinstalled: {
149
+ packageName: CONTEXT_MODE_PACKAGE_NAME,
150
+ version: CONTEXT_MODE_VERSION,
151
+ },
120
152
  },
121
153
  ],
122
154
  },
@@ -6,7 +6,7 @@ import { promisify } from "node:util";
6
6
  import { getOpenSpecSchemaSelection } from "../../../lib/orchestrator/setup-compatibilities";
7
7
  import { getWrapperBinPath } from "../../../lib/package-paths";
8
8
  import { fetchPublicPackageVersion } from "../../../lib/public-npm";
9
- import { isNewer } from "../../../lib/update-checker";
9
+ import { isNewer, isPinnedDeployment } from "../../../lib/update-checker";
10
10
  import { FRAMEWORK_NAME } from "../../../framework";
11
11
  import { confirm } from "../../../cli/confirm";
12
12
  import type { CapabilityPlugin, RuntimeContributionsByRuntime, SetupContext } from "../plugin";
@@ -63,6 +63,7 @@ export interface OpenSpecPluginDeps {
63
63
  wrapperBinPath?: () => string;
64
64
  getInstalledVersion?: (pathValue: string) => Promise<string | undefined>;
65
65
  fetchLatestVersion?: () => Promise<string | undefined>;
66
+ isPinnedDeployment?: () => boolean;
66
67
  }
67
68
 
68
69
  const OPEN_SPEC_SUPPORTED_TOOLS = Object.keys(OPENSPEC_TOOL_DIRS) as OpenSpecTool[];
@@ -170,10 +171,17 @@ async function updateOpenSpecIfOutdated(
170
171
  deps: Required<
171
172
  Pick<
172
173
  OpenSpecPluginDeps,
173
- "installCommand" | "pathValue" | "getInstalledVersion" | "fetchLatestVersion"
174
+ | "installCommand"
175
+ | "pathValue"
176
+ | "getInstalledVersion"
177
+ | "fetchLatestVersion"
178
+ | "isPinnedDeployment"
174
179
  >
175
180
  >,
176
181
  ): Promise<void> {
182
+ /** Pinned artifacts change tool versions by replacement, never reconciliation. */
183
+ if (deps.isPinnedDeployment()) return;
184
+
177
185
  const installed = await deps.getInstalledVersion(deps.pathValue());
178
186
  if (!installed) return;
179
187
 
@@ -204,6 +212,7 @@ async function ensureOpenSpecInstalled(
204
212
  | "pathValue"
205
213
  | "getInstalledVersion"
206
214
  | "fetchLatestVersion"
215
+ | "isPinnedDeployment"
207
216
  >
208
217
  >,
209
218
  ): Promise<boolean> {
@@ -326,6 +335,7 @@ export function createOpenspecPlugin(deps: OpenSpecPluginDeps = {}): CapabilityP
326
335
  wrapperBinPath: deps.wrapperBinPath ?? getWrapperBinPath,
327
336
  getInstalledVersion: deps.getInstalledVersion ?? defaultGetInstalledVersion,
328
337
  fetchLatestVersion: deps.fetchLatestVersion ?? defaultFetchLatestVersion,
338
+ isPinnedDeployment: deps.isPinnedDeployment ?? (() => isPinnedDeployment()),
329
339
  };
330
340
 
331
341
  return {
@@ -35,7 +35,7 @@ export interface SetupContext {
35
35
  export interface LaunchPreflightContext {
36
36
  companionPath: string;
37
37
  config: FrameworkConfig;
38
- repository: LinkedRepository;
38
+ repository?: LinkedRepository;
39
39
  providerId: string;
40
40
  }
41
41
 
@@ -164,6 +164,12 @@ export interface PluginReferenceContribution {
164
164
  isManagedReference(entry: unknown): boolean;
165
165
  /** Config files to reconcile, relative to the runtime dir. Defaults to both OpenCode configs. */
166
166
  configFiles?: string[];
167
+ /**
168
+ * The published package behind `reference`. Where the distribution supplies
169
+ * an installed copy of exactly this package, the owning Runtime Surface binds
170
+ * the contribution to those files instead of the published reference.
171
+ */
172
+ preinstalled?: { packageName: string; version: string };
167
173
  }
168
174
 
169
175
  /**
@@ -19,6 +19,8 @@ import {
19
19
  } from "../context-services";
20
20
  import type { CapabilityContributionInput, ProviderPlugin, SetupContext } from "../plugin";
21
21
  import { surfaceRoot } from "../surface-target";
22
+ import { resolvePreinstalledPluginReference } from "../../../lib/preinstalled-plugins";
23
+ import { getCurrentVersion } from "../../../lib/update-checker";
22
24
  import { mergeDir, pruneEmptyAncestors } from "../utils";
23
25
  import {
24
26
  getOpenCodePluginReferences,
@@ -268,7 +270,14 @@ async function syncOpenCodeRuntimeFiles(
268
270
  const dest = path.join(companionPath, ".opencode");
269
271
  await fs.mkdir(dest, { recursive: true });
270
272
 
271
- const pluginReference = getOpenCodePluginPackageReference();
273
+ // Mate's own plugin binds to an installed copy the same way a Capability's
274
+ // does: the Runtime Surface writes the reference, so it is what changes it.
275
+ const pluginReference =
276
+ (await resolvePreinstalledPluginReference(
277
+ companionPath,
278
+ OPENCODE_PLUGIN_PACKAGE_NAME,
279
+ getCurrentVersion(),
280
+ )) ?? getOpenCodePluginPackageReference();
272
281
 
273
282
  await syncOpenCodeConfigFile(
274
283
  path.join(src, "opencode.json"),
@@ -439,6 +448,19 @@ export async function reconcileOpenCodeContributions(
439
448
 
440
449
  for (const input of inputs) {
441
450
  for (const pluginReference of input.contributions.pluginReferences ?? []) {
451
+ // The Runtime Surface owns the reference it writes, so it is also what
452
+ // binds one to an installed copy. Absent a copy, the published reference
453
+ // is written exactly as before.
454
+ const preinstalled = pluginReference.preinstalled;
455
+ const installedPath =
456
+ input.enabled && preinstalled
457
+ ? await resolvePreinstalledPluginReference(
458
+ ctx.companionPath,
459
+ preinstalled.packageName,
460
+ preinstalled.version,
461
+ )
462
+ : null;
463
+ const reference = installedPath ?? pluginReference.reference;
442
464
  const configFiles = pluginReference.configFiles ?? OPENCODE_CONTRIBUTION_CONFIG_FILES;
443
465
  for (const name of configFiles) {
444
466
  const configPath = path.join(root, ".opencode", name);
@@ -447,10 +469,7 @@ export async function reconcileOpenCodeContributions(
447
469
  const preserved = getOpenCodePluginReferences(config).filter(
448
470
  (entry) => !pluginReference.isManagedReference(entry),
449
471
  );
450
- setOpenCodePluginReferences(
451
- config,
452
- input.enabled ? [...preserved, pluginReference.reference] : preserved,
453
- );
472
+ setOpenCodePluginReferences(config, input.enabled ? [...preserved, reference] : preserved);
454
473
  await writeOpenCodeConfig(configPath, config);
455
474
  }
456
475
  }