claude-code-acp: init
Some checks failed
checks / checks (push) Has been cancelled

This commit is contained in:
2025-10-17 21:09:27 +00:00
parent b26187ae7d
commit 27a4764e00
3 changed files with 118 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
{
"version": "0.6.7",
"srcHash": "sha256-v32Q02ALWw6Upd4rrHGZH7Vt25+xSnKJCNGJob/irgM=",
"npmDepsHash": "sha256-oUAHkB4EPuo8YCxi9Y/Lc8cipjJQ05o51MpdUsCjiiQ="
}

View File

@@ -0,0 +1,36 @@
{
lib,
buildNpmPackage,
fetchFromGitHub,
}:
let
info = lib.importJSON ./info.json;
in
buildNpmPackage {
pname = "claude-code-acp";
version = info.version;
src = fetchFromGitHub {
owner = "zed-industries";
repo = "claude-code-acp";
rev = "v${info.version}";
hash = info.srcHash;
};
npmDepsHash = info.npmDepsHash;
# The package uses TypeScript and builds before publishing
npmBuildScript = "build";
passthru = {
updateScript = ./update.mjs;
};
meta = {
description = "Use Claude Code from any ACP client such as Zed";
homepage = "https://github.com/zed-industries/claude-code-acp";
license = lib.licenses.asl20;
maintainers = with lib.maintainers; [ ];
mainProgram = "claude-code-acp";
};
}

View File

@@ -0,0 +1,77 @@
#! /usr/bin/env nix-shell
/*
#! nix-shell -i zx -p nix-prefetch-github -p zx
*/
import { readFileSync, writeFileSync } from "fs";
import { dirname, join } from "path";
import { fileURLToPath } from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
// GitHub API endpoint for latest release
const GITHUB_API = "https://api.github.com/repos/zed-industries/claude-code-acp/releases/latest";
// Read current info.json
const infoPath = join(__dirname, "info.json");
const currentInfo = JSON.parse(readFileSync(infoPath, "utf-8"));
console.log(`Current version: ${currentInfo.version}`);
// Fetch latest release from GitHub
console.log("Fetching latest release from GitHub...");
const response = await fetch(GITHUB_API);
const release = await response.json();
const latestVersion = release.tag_name.replace(/^v/, ""); // Remove 'v' prefix
console.log(`Latest version: ${latestVersion}`);
if (currentInfo.version === latestVersion) {
console.log("Already up to date!");
process.exit(0);
}
// Update version
currentInfo.version = latestVersion;
// Prefetch source hash
console.log("Prefetching source hash...");
const srcHashOutput = await $`nix-prefetch-github zed-industries claude-code-acp --rev v${latestVersion}`;
const srcPrefetch = JSON.parse(srcHashOutput.stdout);
currentInfo.srcHash = srcPrefetch.hash;
console.log(`Source hash: ${currentInfo.srcHash}`);
// Write temporary info.json to get npmDepsHash
writeFileSync(infoPath, JSON.stringify(currentInfo, null, 2) + "\n");
// Prefetch npm dependencies hash
console.log("Prefetching npm dependencies hash...");
try {
// This will fail with the expected hash in the error message
await $`nix build .#claude-code-acp`;
} catch (error) {
// Extract hash from error message
const errorOutput = error.stderr;
const hashMatch = errorOutput.match(/got:\s+(sha256-[A-Za-z0-9+/=]+)/);
if (hashMatch) {
currentInfo.npmDepsHash = hashMatch[1];
console.log(`npm deps hash: ${currentInfo.npmDepsHash}`);
} else {
console.error("Failed to extract npmDepsHash from build output");
console.error("You may need to update it manually by running:");
console.error(` nix-build -A claude-code-acp`);
console.error("and copying the hash from the error message");
}
}
// Write final info.json
writeFileSync(infoPath, JSON.stringify(currentInfo, null, 2) + "\n");
console.log("\nUpdate complete!");
console.log(`Version: ${currentInfo.version}`);
console.log(`Source hash: ${currentInfo.srcHash}`);
console.log(`npm deps hash: ${currentInfo.npmDepsHash}`);