@fnclaude/cli 1.0.0 → 1.0.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/main.ts +36 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fnclaude/cli",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "fnclaude CLI implementation (TypeScript rewrite, in progress)",
5
5
  "license": "MIT",
6
6
  "repository": {
package/src/main.ts CHANGED
@@ -145,6 +145,41 @@ export interface RunDeps {
145
145
  data?: RunConfig;
146
146
  }
147
147
 
148
+ /**
149
+ * Read the user's argv, preferring `FNC_ARGS_JSON` over `process.argv`.
150
+ *
151
+ * The umbrella shim (packages/fnclaude/bin/fnc.js) sets `FNC_ARGS_JSON`
152
+ * on the env it spawns Bun with, because Bun strips the first `--`
153
+ * from a script's argv (confirmed empirically across `bun script.js`,
154
+ * `bun --`, `bun run`, and shebang invocations). Passing user args via
155
+ * the env var sidesteps that — Bun never sees them as its own argv.
156
+ *
157
+ * We DELETE the var after consumption so any child processes the cli
158
+ * spawns (claude, gh, the relaunch chain) don't inherit a stale value.
159
+ *
160
+ * Defensive: malformed or wrong-shape values fall through to
161
+ * `process.argv.slice(2)` rather than throwing — a corrupted env var
162
+ * shouldn't break the cli, just degrade to the pre-fix behaviour.
163
+ */
164
+ function readArgvFromEnvOrProcess(): readonly string[] {
165
+ const envArgs = process.env.FNC_ARGS_JSON;
166
+ if (envArgs !== undefined) {
167
+ delete process.env.FNC_ARGS_JSON;
168
+ try {
169
+ const parsed: unknown = JSON.parse(envArgs);
170
+ if (
171
+ Array.isArray(parsed) &&
172
+ parsed.every((x): x is string => typeof x === 'string')
173
+ ) {
174
+ return parsed;
175
+ }
176
+ } catch {
177
+ // Fall through to process.argv.
178
+ }
179
+ }
180
+ return process.argv.slice(2);
181
+ }
182
+
148
183
  function lookupClaudeFromPath(name: string): string | undefined {
149
184
  // Bun's PATH lookup: Bun.which() returns null when not found. Coerce to
150
185
  // undefined to keep the absent-value sentinel consistent with the rest of
@@ -174,7 +209,7 @@ export async function run(deps: RunDeps = {}): Promise<number> {
174
209
  const io = deps.io ?? {};
175
210
  const data = deps.data ?? {};
176
211
 
177
- const argv = io.argv ?? process.argv.slice(2);
212
+ const argv = io.argv ?? readArgvFromEnvOrProcess();
178
213
  const stdout = io.stdout ?? process.stdout;
179
214
  const stderr = io.stderr ?? process.stderr;
180
215
  const home = io.home ?? process.env.HOME ?? homedir();