Allow for the package to be used as a dependency, while preserving existing behavior when run (#124)

This change will allow for this package to be used directly, without
launching a subprocess and communicating over stdio.

---------

Co-authored-by: Ben Brandt <benjamin.j.brandt@gmail.com>
This commit is contained in:
Guillaume Sabran
2025-10-27 04:10:41 -07:00
committed by GitHub
parent 17aad5b7a1
commit 5491bb8dcc
4 changed files with 52 additions and 27 deletions

2
package-lock.json generated
View File

@@ -19,7 +19,7 @@
"uuid": "13.0.0"
},
"bin": {
"claude-code-acp": "dist/index.js"
"claude-code-acp": "dist/cli.js"
},
"devDependencies": {
"@anthropic-ai/sdk": "0.67.0",

View File

@@ -4,7 +4,7 @@
"access": "public"
},
"bin": {
"claude-code-acp": "./dist/index.js"
"claude-code-acp": "./dist/cli.js"
},
"version": "0.6.10",
"description": "An ACP-compatible coding agent powered by the Claude Code SDK (TypeScript)",

26
src/cli.ts Normal file
View File

@@ -0,0 +1,26 @@
#!/usr/bin/env node
// Load managed settings and apply environment variables
import { loadManagedSettings, applyEnvironmentSettings } from "./utils.js";
const managedSettings = loadManagedSettings();
if (managedSettings) {
applyEnvironmentSettings(managedSettings);
}
// stdout is used to send messages to the client
// we redirect everything else to stderr to make sure it doesn't interfere with ACP
console.log = console.error;
console.info = console.error;
console.warn = console.error;
console.debug = console.error;
process.on("unhandledRejection", (reason, promise) => {
console.error("Unhandled Rejection at:", promise, "reason:", reason);
});
import { runAcp } from "./acp-agent.js";
runAcp();
// Keep process alive
process.stdin.resume();

View File

@@ -1,26 +1,25 @@
#!/usr/bin/env node
// Export the main agent class and utilities for library usage
export {
ClaudeAcpAgent,
runAcp,
toAcpNotifications,
streamEventToAcpNotifications,
} from "./acp-agent.js";
export {
loadManagedSettings,
applyEnvironmentSettings,
nodeToWebReadable,
nodeToWebWritable,
Pushable,
unreachable,
} from "./utils.js";
export {
createMcpServer,
createPermissionMcpServer,
PERMISSION_TOOL_NAME,
toolNames,
} from "./mcp-server.js";
export { toolInfoFromToolUse, planEntries, toolUpdateFromToolResult } from "./tools.js";
// Load managed settings and apply environment variables
import { loadManagedSettings, applyEnvironmentSettings } from "./utils.js";
const managedSettings = loadManagedSettings();
if (managedSettings) {
applyEnvironmentSettings(managedSettings);
}
// stdout is used to send messages to the client
// we redirect everything else to stderr to make sure it doesn't interfere with ACP
console.log = console.error;
console.info = console.error;
console.warn = console.error;
console.debug = console.error;
process.on("unhandledRejection", (reason, promise) => {
console.error("Unhandled Rejection at:", promise, "reason:", reason);
});
import { runAcp as runAcp } from "./acp-agent.js";
runAcp();
// Keep process alive
process.stdin.resume();
// Export types
export type { ClaudePlanEntry } from "./tools.js";