@codegrammer/co-od 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3 @@
1
+ import type { AgentAdapter } from "./base.js";
2
+ export declare function getAdapter(provider: string): AgentAdapter;
3
+ export declare const PROVIDER_LIST = "claude|codex|openclaw";
@@ -0,0 +1,17 @@
1
+ import { ClaudeAdapter } from "./claude.js";
2
+ import { CodexAdapter } from "./codex.js";
3
+ import { OpenClawAdapter } from "./openclaw.js";
4
+ const adapters = {
5
+ claude: () => new ClaudeAdapter(),
6
+ codex: () => new CodexAdapter(),
7
+ openclaw: () => new OpenClawAdapter(),
8
+ zeroclaw: () => new OpenClawAdapter(),
9
+ };
10
+ export function getAdapter(provider) {
11
+ const factory = adapters[provider.toLowerCase()];
12
+ if (factory)
13
+ return factory();
14
+ // Default to claude
15
+ return new ClaudeAdapter();
16
+ }
17
+ export const PROVIDER_LIST = "claude|codex|openclaw";
@@ -0,0 +1,6 @@
1
+ import type { AgentAdapter, ExecuteOptions, ExecuteResult } from "./base.js";
2
+ export declare class OpenClawAdapter implements AgentAdapter {
3
+ name: string;
4
+ available(): Promise<boolean>;
5
+ execute(goal: string, options: ExecuteOptions): Promise<ExecuteResult>;
6
+ }
@@ -0,0 +1,88 @@
1
+ import { spawn } from "node:child_process";
2
+ /**
3
+ * OpenClaw / ZeroClaw adapter.
4
+ *
5
+ * Supports both the legacy `openclaw` CLI and the newer `zeroclaw` CLI.
6
+ * Sends tasks via `zeroclaw agent -m <goal>` (non-interactive single-shot mode).
7
+ * Falls back to the HTTP gateway if running as a daemon.
8
+ */
9
+ const ZEROCLAW_BIN = process.env.ZEROCLAW_BIN || "zeroclaw";
10
+ const OPENCLAW_BIN = process.env.OPENCLAW_BIN || "openclaw";
11
+ async function findBinary() {
12
+ for (const [bin, variant] of [
13
+ [ZEROCLAW_BIN, "zeroclaw"],
14
+ [OPENCLAW_BIN, "openclaw"],
15
+ ]) {
16
+ try {
17
+ const child = spawn("sh", ["-lc", `command -v ${bin}`], { stdio: "pipe" });
18
+ const ok = await new Promise((resolve) => {
19
+ child.on("close", (code) => resolve(code === 0));
20
+ child.on("error", () => resolve(false));
21
+ });
22
+ if (ok)
23
+ return { bin, variant };
24
+ }
25
+ catch {
26
+ continue;
27
+ }
28
+ }
29
+ return null;
30
+ }
31
+ export class OpenClawAdapter {
32
+ name = "openclaw";
33
+ async available() {
34
+ const found = await findBinary();
35
+ return found !== null;
36
+ }
37
+ async execute(goal, options) {
38
+ const found = await findBinary();
39
+ if (!found) {
40
+ return {
41
+ exitCode: 127,
42
+ stdout: "",
43
+ stderr: "Neither zeroclaw nor openclaw CLI found on PATH. Install: brew install zeroclaw",
44
+ };
45
+ }
46
+ const { bin } = found;
47
+ // zeroclaw agent -m "goal" — single-shot non-interactive mode
48
+ const args = ["agent", "-m", goal];
49
+ return new Promise((resolve) => {
50
+ const child = spawn(bin, args, {
51
+ cwd: options.workDir,
52
+ env: { ...process.env },
53
+ stdio: ["pipe", "pipe", "pipe"],
54
+ });
55
+ if (options.signal) {
56
+ options.signal.addEventListener("abort", () => {
57
+ child.kill("SIGTERM");
58
+ });
59
+ }
60
+ let stdout = "";
61
+ let stderr = "";
62
+ child.stdout?.setEncoding("utf-8");
63
+ child.stderr?.setEncoding("utf-8");
64
+ child.stdout?.on("data", (chunk) => {
65
+ stdout += chunk;
66
+ options.onOutput?.(chunk);
67
+ });
68
+ child.stderr?.on("data", (chunk) => {
69
+ stderr += chunk;
70
+ options.onOutput?.(chunk);
71
+ });
72
+ child.on("error", (err) => {
73
+ resolve({
74
+ exitCode: 127,
75
+ stdout,
76
+ stderr: stderr || err.message,
77
+ });
78
+ });
79
+ child.on("close", (code) => {
80
+ resolve({
81
+ exitCode: code ?? 1,
82
+ stdout,
83
+ stderr,
84
+ });
85
+ });
86
+ });
87
+ }
88
+ }
@@ -1,6 +1,5 @@
1
+ import { getAdapter, PROVIDER_LIST } from "../adapters/index.js";
1
2
  import * as api from "../api-client.js";
2
- import { ClaudeAdapter } from "../adapters/claude.js";
3
- import { CodexAdapter } from "../adapters/codex.js";
4
3
  function parseArgs(args) {
5
4
  const parsed = {
6
5
  provider: "claude",
@@ -47,22 +46,13 @@ function parseArgs(args) {
47
46
  }
48
47
  return parsed;
49
48
  }
50
- function getAdapter(provider) {
51
- switch (provider) {
52
- case "codex":
53
- return new CodexAdapter();
54
- case "claude":
55
- default:
56
- return new ClaudeAdapter();
57
- }
58
- }
59
49
  function timestamp() {
60
50
  return new Date().toISOString().slice(11, 19);
61
51
  }
62
52
  export async function run(args) {
63
53
  const parsed = parseArgs(args);
64
54
  if (!parsed.roomId) {
65
- console.error("Usage: co-od daemon <room-id> [--as <name>] [--role <role>] [--provider claude|codex] [--watch <events>] [--auto-execute] [--max-concurrent <n>]");
55
+ console.error(`Usage: co-od daemon <room-id> [--as <name>] [--role <role>] [--provider ${PROVIDER_LIST}] [--watch <events>] [--auto-execute] [--max-concurrent <n>]`);
66
56
  process.exit(1);
67
57
  }
68
58
  if (parsed.server) {
@@ -1,6 +1,5 @@
1
+ import { getAdapter, PROVIDER_LIST } from "../adapters/index.js";
1
2
  import * as api from "../api-client.js";
2
- import { ClaudeAdapter } from "../adapters/claude.js";
3
- import { CodexAdapter } from "../adapters/codex.js";
4
3
  function parseArgs(args) {
5
4
  const parsed = {
6
5
  provider: "claude",
@@ -29,19 +28,10 @@ function parseArgs(args) {
29
28
  parsed.goal = positional.slice(1).join(" ");
30
29
  return parsed;
31
30
  }
32
- function getAdapter(provider) {
33
- switch (provider) {
34
- case "codex":
35
- return new CodexAdapter();
36
- case "claude":
37
- default:
38
- return new ClaudeAdapter();
39
- }
40
- }
41
31
  export async function run(args) {
42
32
  const parsed = parseArgs(args);
43
33
  if (!parsed.roomId) {
44
- console.error("Usage: co-od run <room-id> <goal> [--provider claude|codex] [--dir <path>] [--json]");
34
+ console.error(`Usage: co-od run <room-id> <goal> [--provider ${PROVIDER_LIST}] [--dir <path>] [--json]`);
45
35
  process.exit(1);
46
36
  }
47
37
  if (!parsed.goal) {
@@ -1,6 +1,5 @@
1
+ import { getAdapter } from "../adapters/index.js";
1
2
  import * as api from "../api-client.js";
2
- import { ClaudeAdapter } from "../adapters/claude.js";
3
- import { CodexAdapter } from "../adapters/codex.js";
4
3
  function parseArgs(args) {
5
4
  const parsed = {
6
5
  provider: "claude",
@@ -19,15 +18,6 @@ function parseArgs(args) {
19
18
  }
20
19
  return parsed;
21
20
  }
22
- function getAdapter(provider) {
23
- switch (provider) {
24
- case "codex":
25
- return new CodexAdapter();
26
- case "claude":
27
- default:
28
- return new ClaudeAdapter();
29
- }
30
- }
31
21
  function timestamp() {
32
22
  return new Date().toISOString().slice(11, 19);
33
23
  }
package/dist/index.js CHANGED
@@ -4,10 +4,10 @@ const VERSION = "0.1.0";
4
4
  const COMMANDS = {
5
5
  login: { desc: "Authenticate with co-ode", usage: "co-od login [--token <t>]" },
6
6
  rooms: { desc: "List your rooms", usage: "co-od rooms [--json]" },
7
- run: { desc: "Execute a single task in a room", usage: "co-od run <room> <goal> [--provider claude|codex] [--dir <path>] [--json]" },
7
+ run: { desc: "Execute a single task in a room", usage: "co-od run <room> <goal> [--provider claude|codex|openclaw] [--dir <path>] [--json]" },
8
8
  join: { desc: "Join a room as an interactive agent", usage: "co-od join <room> [--invite-token <tok>] [--dir <path>]" },
9
9
  daemon: { desc: "Autonomous watch mode for a room", usage: "co-od daemon <room> [--as <name>] [--auto-execute] [--watch <events>]" },
10
- share: { desc: "Generate a relay code for teammates", usage: "co-od share [--provider claude|codex]" },
10
+ share: { desc: "Generate a relay code for teammates", usage: "co-od share [--provider claude|codex|openclaw]" },
11
11
  connect: { desc: "Connect to a relay via code", usage: "co-od connect <code>" },
12
12
  status: { desc: "Show current login and running state", usage: "co-od status [--json]" },
13
13
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codegrammer/co-od",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "CLI for co-ode — run AI agents in shared rooms from the command line",
5
5
  "type": "module",
6
6
  "bin": {