Skip to content

[Bug] CLI crashes on startup: duplicate option registration in export.js and import.js #53

@tianhaocui

Description

@tianhaocui

Description

After installing gitagent v0.1.0 via npm i -g @open-gitagent/gitagent, every CLI command fails (not just export or import — even gitagent init and gitagent info crash) because the duplicate option registration error is thrown during module loading.

Environment

  • gitagent: 0.1.0
  • Node.js: v23.7.0
  • OS: macOS (Darwin 24.0.0)

Error

Error: Cannot add option '-f, --format <format>' to command 'export' due to conflicting flag '--format'
-  already used by option '-f, --format <format>'
    at Command._registerOption (commander/lib/command.js:602:13)

After patching export.js, a second identical error appears in import.js:

Error: Cannot add option '--from <format>' to command 'import' due to conflicting flag '--from'
-  already used by option '--from <format>'

Root Cause

Two bugs in the compiled output, both following the same pattern:

1. Duplicate .requiredOption() calls

dist/commands/export.js (lines 9-10):

.requiredOption('-f, --format <format>', '...gemini)')
.requiredOption('-f, --format <format>', '...codex)')  // duplicate — crashes commander

dist/commands/import.js (lines 453-454):

.requiredOption('--from <format>', '...gemini)')
.requiredOption('--from <format>', '...codex)')  // duplicate — crashes commander

2. case 'codex' falls through from default

In both files, case 'codex' is placed inside the default branch (after error() and before process.exit(1)), so it can never be matched correctly:

default:
    error(`Unknown format: ${options.format}`);
    info('Supported formats: ...');
case 'codex':                          // falls through from default
    result = exportToCodexString(dir);
    process.exit(1);                   // always exits

Fix

For both export.js and import.js:

  1. Merge the two .requiredOption() calls into one, listing all formats including both gemini and codex.
  2. Move case 'codex' out of default as an independent case with its own break.

export.js diff:

- .requiredOption('-f, --format <format>', 'Export format (...gemini)')
- .requiredOption('-f, --format <format>', 'Export format (...codex)')
+ .requiredOption('-f, --format <format>', 'Export format (...gemini, codex)')
- default:
-     error(`Unknown format: ${options.format}`);
-     info('Supported formats: ...gemini');
- case 'codex':
-     result = exportToCodexString(dir);
-     info('Supported formats: ...codex');
-     process.exit(1);
+ case 'codex':
+     result = exportToCodexString(dir);
+     break;
+ default:
+     error(`Unknown format: ${options.format}`);
+     info('Supported formats: ...gemini, codex');
+     process.exit(1);

Same pattern applies to import.js.

Workaround

Manually patch the two files in node_modules/@open-gitagent/gitagent/dist/commands/ as described above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions