Files
multica/packages/core/runtimes/cli-version.ts
Naiyuan Qing f0d6d88069 fix(views): resolve handoff-note version gate locally for direct agent assigns (#4585)
The run-confirm interception box gated its handoff-note field on the
preview round-trip's `handoff_supported`, so every open showed a
"checking…" wait before the note box could even be used — to learn
something the client already holds. For a concrete agent assignee the
target runtime is exactly that agent's, and its CLI version is already
warm in the prefetched agent + runtime caches, so the box can settle
synchronously, the same way the quick-create version gate does.

Add a frontend `handoffSupported` mirror of the server's
MinHandoffCLIVersion gate, resolve the agent → runtime → cli_version
locally, and drive the note box from that verdict without waiting on
loading. Squad / batch-status / unresolved-agent paths — whose resolved
trigger set is only known server-side — keep falling back to the
preview's `handoff_supported`, unchanged.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>
2026-06-26 09:21:09 +08:00

105 lines
4.6 KiB
TypeScript

/**
* Frontend mirror of the server's MinQuickCreateCLIVersion gate. The
* agent-create flow (Quick Create modal) requires the daemon's bundled
* multica CLI to be at least this version — older daemons either
* double-create issues on partial CLI failures, drop quick-create attachment
* bindings, or mishandle pasted screenshot URLs (see PR #1851 / MUL-1496).
*
* Both the frontend pre-validation in the modal and the server's
* `/api/issues/quick-create` handler enforce this; the server is the
* authoritative trust boundary, the frontend just lets us tell the user
* "your daemon needs an upgrade" before they hit submit.
*/
export const MIN_QUICK_CREATE_CLI_VERSION = "0.2.21";
export type CliVersionState = "ok" | "too_old" | "missing";
export interface CliVersionCheck {
state: CliVersionState;
/** What the daemon reported, or empty if missing/unparsable. */
current: string;
/** The hard minimum we gate on. */
min: string;
}
const SEMVER_RE = /v?(\d+)\.(\d+)\.(\d+)/;
// Matches the `git describe --tags --always --dirty` output for a build past
// the latest tag, e.g. `v0.2.15-235-gdaf0e935` or `v0.2.15-235-gdaf0e935-dirty`.
// Daemons built from source (Makefile `make build` / `make daemon`) report this
// shape; tagged releases are bare semver. Treating dev-described daemons as OK
// is what keeps `pnpm dev:desktop` + `make daemon` unblocked without weakening
// the gate for staging or production users running stale stable releases.
const DEV_DESCRIBE_RE = /^v?\d+\.\d+\.\d+-\d+-g[0-9a-fA-F]+/;
function parseSemver(raw: string): [number, number, number] | null {
const m = SEMVER_RE.exec(raw.trim());
if (!m) return null;
return [Number(m[1]), Number(m[2]), Number(m[3])];
}
function lessThan(a: [number, number, number], b: [number, number, number]) {
if (a[0] !== b[0]) return a[0] < b[0];
if (a[1] !== b[1]) return a[1] < b[1];
return a[2] < b[2];
}
/**
* Check a daemon-reported CLI version string against the minimum. Returns
* `"missing"` for empty/unparsable input (fail closed — same policy as the
* server) and `"too_old"` for a parsable version below the threshold.
* Dev-built daemons (git-describe shape) are always OK — the version string
* itself is the shared signal, so frontend and server agree by construction.
*/
export function checkQuickCreateCliVersion(detected: string | undefined | null): CliVersionCheck {
const current = (detected ?? "").trim();
if (DEV_DESCRIBE_RE.test(current)) {
return { state: "ok", current, min: MIN_QUICK_CREATE_CLI_VERSION };
}
const parsed = current ? parseSemver(current) : null;
if (!parsed) {
return { state: "missing", current, min: MIN_QUICK_CREATE_CLI_VERSION };
}
const min = parseSemver(MIN_QUICK_CREATE_CLI_VERSION)!;
if (lessThan(parsed, min)) {
return { state: "too_old", current, min: MIN_QUICK_CREATE_CLI_VERSION };
}
return { state: "ok", current, min: MIN_QUICK_CREATE_CLI_VERSION };
}
/** Pull `cli_version` off a runtime row's loosely-typed metadata bag. */
export function readRuntimeCliVersion(metadata: Record<string, unknown> | undefined): string {
const v = metadata?.cli_version;
return typeof v === "string" ? v : "";
}
/**
* Frontend mirror of the server's `MinHandoffCLIVersion` soft gate
* (`server/pkg/agent/version.go`). The assignment handoff note is only rendered
* into the run's opening prompt by daemons at or above this multica CLI version
* (MUL-3375); older daemons silently drop it. Unlike the quick-create gate this
* never blocks the assignment — the UI just grays out the note box and warns.
*
* Keep in lockstep with the server constant; the two are enforced independently
* (the server is authoritative) but must agree so the warning matches reality.
*/
export const MIN_HANDOFF_CLI_VERSION = "0.3.28";
/**
* Whether a daemon-reported CLI version is new enough to render a handoff note.
* Mirrors server `agent.HandoffSupported`: missing / unparsable / below-minimum
* all degrade to `false`, and dev-built daemons (git-describe shape) always
* pass — the version string is the shared signal, so frontend and server agree
* by construction. Pure and synchronous, so the note box can settle from the
* already-warm runtime cache instead of waiting on the trigger-preview
* round-trip, exactly like the quick-create version gate.
*/
export function handoffSupported(detected: string | undefined | null): boolean {
const current = (detected ?? "").trim();
if (!current) return false;
if (DEV_DESCRIBE_RE.test(current)) return true;
const parsed = parseSemver(current);
if (!parsed) return false;
return !lessThan(parsed, parseSemver(MIN_HANDOFF_CLI_VERSION)!);
}