refactor: deduplicate PkgVersionSchema to shared/parse.ts (#2357)

Move the PkgVersionSchema (v.object({ version: v.string() })) from its
duplicate definitions in commands/shared.ts and update-check.ts into the
shared parse module. Both consumers now import from the single source.

Bump CLI version to 0.15.22.

Co-authored-by: spawn-qa-bot <qa@openrouter.ai>
Co-authored-by: L <6723574+louisgv@users.noreply.github.com>
This commit is contained in:
A 2026-03-08 18:45:51 -07:00 committed by GitHub
parent 8bc5581e62
commit 62e1df9be5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 9 additions and 13 deletions

View file

@ -1,6 +1,6 @@
{
"name": "@openrouter/spawn",
"version": "0.15.21",
"version": "0.15.22",
"type": "module",
"bin": {
"spawn": "cli.js"

View file

@ -4,10 +4,10 @@ import type { Manifest } from "../manifest.js";
import * as fs from "node:fs";
import * as p from "@clack/prompts";
import pc from "picocolors";
import * as v from "valibot";
import pkg from "../../package.json" with { type: "json" };
import { agentKeys, cloudKeys, isStaleCache, loadManifest, matrixStatus } from "../manifest.js";
import { validateIdentifier, validatePrompt } from "../security.js";
import { PkgVersionSchema } from "../shared/parse.js";
import { getErrorMessage, isString } from "../shared/type-guards.js";
import { getSpawnCloudConfigPath } from "../shared/ui.js";
@ -17,9 +17,7 @@ export const VERSION = pkg.version;
export const FETCH_TIMEOUT = 10_000; // 10 seconds
export const NAME_COLUMN_WIDTH = 18;
export const PkgVersionSchema = v.object({
version: v.string(),
});
export { PkgVersionSchema };
// ── Helpers ──────────────────────────────────────────────────────────────────

View file

@ -17,6 +17,11 @@ export function parseJsonWith<T extends v.BaseSchema<unknown, unknown, v.BaseIss
}
}
/** Schema for responses containing a `version` field (npm registry, GitHub releases). */
export const PkgVersionSchema = v.object({
version: v.string(),
});
/**
* Parse a JSON string and return it as a Record<string, unknown> or null.
* Rejects non-object results (arrays, primitives).

View file

@ -6,10 +6,9 @@ import fs from "node:fs";
import { homedir } from "node:os";
import path from "node:path";
import pc from "picocolors";
import * as v from "valibot";
import pkg from "../package.json" with { type: "json" };
import { RAW_BASE, SPAWN_CDN, VERSION_URL } from "./manifest.js";
import { parseJsonWith } from "./shared/parse";
import { PkgVersionSchema, parseJsonWith } from "./shared/parse";
import { hasStatus } from "./shared/type-guards";
const VERSION = pkg.version;
@ -24,12 +23,6 @@ export const executor = {
const FETCH_TIMEOUT = 10000; // 10 seconds
const UPDATE_BACKOFF_MS = 60 * 60 * 1000; // 1 hour
// ── Schemas ──────────────────────────────────────────────────────────────────
const PkgVersionSchema = v.object({
version: v.string(),
});
// Use ASCII-safe symbols when unicode is disabled (SSH, dumb terminals)
const isAscii = process.env.TERM === "linux";
const CHECK_MARK = isAscii ? "*" : "\u2713";