Skip to content

bug: CLI exits silently when run via global symlink or npx due to unresolved symlink path in isDirectRun #102

Description

@leandrosilvaferreira

Issue Description

Describe the bug

When running ag-kit commands (like ag-kit init or npx @vudovn/ag-kit init), the CLI exits silently with no output and does not perform any actions.

This happens because the CLI checks if it is executed directly (isDirectRun) by comparing process.argv[1] to import.meta.url. However, when installed globally or run via npx, Node.js executes the script through a symlink. Since path.resolve does not resolve symlinks, the comparison fails, resulting in isDirectRun being false.

To Reproduce

  1. Install the CLI globally: npm install -g @vudovn/ag-kit (or run via npx: npx @vudovn/ag-kit init)
  2. Run ag-kit init in a directory.
  3. The command finishes immediately with exit code 0 but produces no terminal output and does not create the .agents folder.

Root Cause

In bin/index.js (line 431):

const isDirectRun = process.argv[1]
    && pathToFileURL(path.resolve(process.argv[1])).href === import.meta.url;

When run via symlink:

  • pathToFileURL(path.resolve(process.argv[1])).href yields: file:///path/to/global/bin/ag-kit
  • import.meta.url yields: file:///path/to/global/lib/node_modules/@vudovn/ag-kit/bin/index.js

Since these paths do not match, the CLI commands never parse/execute.

Suggested Fix

Resolve the symlink using fs.realpathSync before checking if the CLI is being run directly:

import fs from "node:fs";

// Resolve symlink of argv[1] if it exists
const resolvedArgv = process.argv[1] ? fs.realpathSync(process.argv[1]) : "";

const isDirectRun = resolvedArgv
    && pathToFileURL(resolvedArgv).href === import.meta.url;

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