{"record":{"id":"acaf42d10a7c6efe","repo":"can1357/oh-my-pi","slug":"packages-coding-agent-package-json-has-no-valid-ve","errorCode":null,"errorMessage":"packages/coding-agent/package.json has no valid version","messagePattern":"packages/coding-agent/package\\.json has no valid version","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/metaharness/src/tb/agent.ts","lineNumber":56,"sourceCode":"\t\tfor (const [entry, file] of await archive.files()) {\n\t\t\tconst name = path.posix.basename(entry);\n\t\t\tif (!name.startsWith(`pi_natives.linux-${arch}`) || !name.endsWith(\".node\")) continue;\n\t\t\tawait Bun.write(path.join(NATIVES_DIR, name), file);\n\t\t\textracted++;\n\t\t}\n\t\tif (extracted === 0) throw new Error(`@oh-my-pi/${pkg}@${version} tarball contained no .node files`);\n\t}\n}\n\n/** Build and cache self-contained omp binaries for the selected guest architectures. */\nexport async function prepareAgentBinaries(opts: {\n\tarches: GuestArch[];\n\tcacheDir: string;\n\trebuild: boolean;\n}): Promise<AgentBinaries> {\n\tconst manifest = (await Bun.file(path.join(CODING_AGENT_DIR, \"package.json\")).json()) as { version?: unknown };\n\tif (typeof manifest.version !== \"string\" || manifest.version.length === 0) {\n\t\tthrow new Error(\"packages/coding-agent/package.json has no valid version\");\n\t}\n\n\tconst arches = [...new Set(opts.arches)];\n\tconst cached: Partial<Record<GuestArch, string>> = {};\n\tfor (const arch of arches) {\n\t\tcached[arch] = path.join(opts.cacheDir, `omp-linux-${arch}-${manifest.version}`);\n\t}\n\tconst missing: GuestArch[] = [];\n\tfor (const arch of arches) {\n\t\tif (opts.rebuild || !(await Bun.file(cached[arch]!).exists())) missing.push(arch);\n\t}\n\n\tif (missing.length > 0) {\n\t\tawait fs.mkdir(opts.cacheDir, { recursive: true });\n\t\tawait refreshCrossNatives(missing, manifest.version);\n\t\tconst targets = missing.map(arch => `linux-${arch}`).join(\",\");\n\t\tawait run([\"bun\", \"scripts/ci-release-build-binaries.ts\", \"--targets\", targets], REPO_ROOT);\n\t\tfor (const arch of missing) {","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/metaharness/src/tb/agent.ts#L38-L74","documentation":"prepareAgentBinaries reads `packages/coding-agent/package.json` to learn the agent version used for binary naming and caching, and throws this error when the parsed manifest has no non-empty string `version` field. It treats a missing/invalid version as fatal because binaries are cached under `omp-linux-<arch>-<version>` and cross natives are fetched at that version.","triggerScenarios":"Calling `prepareAgentBinaries` (or the `binaries` entrypoint) when the coding-agent package.json is missing its version, has `version: \"\"`, or the file is malformed/unparseable so `manifest.version` is undefined.","commonSituations":"Running from a workspace where the package was stripped or renamed; a generated/hand-edited package.json missing the version field; pointing CODING_AGENT_DIR at the wrong directory; corrupted checkout.","solutions":["Ensure `packages/coding-agent/package.json` contains a valid non-empty `\"version\"` string","Verify CODING_AGENT_DIR points at the real packages/coding-agent directory","Restore the file if corrupted: `git checkout -- packages/coding-agent/package.json`","Validate the JSON parses (`bun -e 'await Bun.file(...).json()'`) if the file looks wrong"],"exampleFix":"// before\n{ \"name\": \"@oh-my-pi/coding-agent\" } // no version → throws\n// after\n{ \"name\": \"@oh-my-pi/coding-agent\", \"version\": \"1.2.3\" }","handlingStrategy":"type-guard","validationCode":"const manifest = await Bun.file(path.join(CODING_AGENT_DIR, \"package.json\")).json();\nif (typeof manifest.version !== \"string\" || manifest.version.length === 0) {\n  throw new Error(\"coding-agent package.json is missing a valid version\");\n}","typeGuard":"function hasVersion(m: unknown): m is { version: string } {\n  return typeof m === \"object\" && m !== null &&\n    typeof (m as { version?: unknown }).version === \"string\" &&\n    (m as { version: string }).version.length > 0;\n}","tryCatchPattern":"let manifest: { version?: unknown };\ntry {\n  manifest = await Bun.file(path.join(CODING_AGENT_DIR, \"package.json\")).json();\n} catch (err) {\n  throw new Error(`cannot read coding-agent package.json: ${err}`);\n}\nif (!hasVersion(manifest)) throw new Error(\"coding-agent package.json has no valid version\");","preventionTips":["Never hand-edit or strip the version field from package.json","Verify CODING_AGENT_DIR points at the real package directory","Restore the manifest from git if corrupted","Validate package.json parses in CI before binary builds"],"tags":["config","validation","package-json"],"backgroundTag":"missing-package-version","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}