Skip to content

coi: npm .bin/coi shim silently exits 0 — main2() gate checks basename(argv[1]) #7

Description

@ragoneg

Summary

@dataforxyz/agent-intercom-codex@0.10.0 declares "bin": { "coi": "dist/coi.mjs" }, but the npm-installed .bin/coi shim never executes the CLI entrypoint: the coi.mjs top-level guard only calls main2() when basename(process.argv[1]) is coi.ts or coi.mjs. The shim's basename is coi, so the process exits 0 silently with no socket, no broker peer registration, and no output.

Minimal reproduction

npm install @dataforxyz/agent-intercom-codex@0.10.0

# A) npm shim -> silent exit 0, main() never runs
./node_modules/.bin/coi --help
echo "exit=$? bytes=$(wc -c < <(./node_modules/.bin/coi --help))"
# -> exit=0 bytes=0

# B) direct entrypoint -> works
node ./node_modules/@dataforxyz/agent-intercom-codex/dist/coi.mjs --help
echo "exit=$? bytes=$(wc -c < <(node ./node_modules/@dataforxyz/agent-intercom-codex/dist/coi.mjs --help))"
# -> exit=0 bytes=5728  (Codex CLI help)

Observed on Linux, codex-cli 0.148.0, node v24.

Root cause

dist/coi.mjs (0.10.0) ends with:

if (process.argv[1] && (basename(process.argv[1]) === "coi.ts" || basename(process.argv[1]) === "coi.mjs")) {
  void main2().catch((error) => { ... });
}

The npm-generated shim for a bin named coi passes the shim path (basename coi) as process.argv[1], so the guard is false and the process exits 0 without doing anything.

Suggested fix

Do not gate the entrypoint on argv[1] basename. Either:

  • remove the guard and always run main2() when the module is the main entry (import.meta.main / process.argv[1] === fileURLToPath(import.meta.url), not basename); or
  • keep the guard but compare the resolved realpath of argv[1] against the module path, so the npm shim symlink still resolves to coi.mjs.

Related observation (same launch path)

After fixing the launcher, coi invokes codex app-server -c "mcp_servers.codex-intercom.env.*=..." --listen unix://.... If the user config does not already define [mcp_servers.codex-intercom], codex rejects the implicit entry with invalid transport in mcp_servers.codex-intercom. The package ships a correct .mcp.json (command: node, args: ["./dist/codex-server.mjs"]) but it is not auto-loaded, so the user must add the server stanza via codex mcp add before coi can start the worker. Consider auto-registering the MCP server entry (or documenting the required codex mcp add step) as part of the launch path.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions