From 1199897edb7a8f28c304b6c341b83dfb3358dada Mon Sep 17 00:00:00 2001 From: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Fri, 23 Oct 2026 07:47:58 -0400 Subject: [PATCH 1/2] fix(cli): reject unknown --flags with exit 2 instead of silently ignoring them Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- README.md | 1 + changelog.d/fixed-346.md | 1 + src/cli.ts | 13 +++++++++++++ test/cli-error-paths.test.js | 13 +++++++++++++ 4 files changed, 28 insertions(+) create mode 100644 changelog.d/fixed-346.md diff --git a/README.md b/README.md index ac78191..bff6b1b 100644 --- a/README.md +++ b/README.md @@ -147,6 +147,7 @@ tell a healthy quiet session from one that is repeatedly failing, add `--diagnostics[=secs]` (default every 60 s); the value must be a positive number of seconds (at most 2147483, the `setInterval` limit), or omitted to use the default—anything else is rejected with exit 2. +Unknown or misspelled `--flags` also exit 2 (`unknown flag --name`) instead of being ignored. It writes one JSON line per period, plus a final one on exit, to **stderr** — stdout stays pure event JSONL: diff --git a/changelog.d/fixed-346.md b/changelog.d/fixed-346.md new file mode 100644 index 0000000..764ce18 --- /dev/null +++ b/changelog.d/fixed-346.md @@ -0,0 +1 @@ +- `pluk` now rejects unknown or misspelled `--flags` (e.g. `--captur=50`, `--entr`) with an error (exit 2) instead of silently ignoring them. diff --git a/src/cli.ts b/src/cli.ts index 07ab9db..d7f7be5 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -69,6 +69,17 @@ const BOOL_FLAGS = new Set([ 'no-open', 'dangerous', 'json', 'enter', 'literal', ]); +const KNOWN_FLAGS = new Set([ + 'help', 'h', ...VALUE_FLAGS, ...BOOL_FLAGS, 'capture', 'diagnostics', +]); + +function rejectUnknownFlag(name: string): void { + if (!KNOWN_FLAGS.has(name)) { + console.error(`${paintStderr(ANSI_RED, 'Error:')} unknown flag --${name} (see pluk --help)`); + process.exit(2); + } +} + function parseArgs(args: string[]): { positional: string[]; flags: Record } { const positional: string[] = []; const flags: Record = {}; @@ -79,6 +90,7 @@ function parseArgs(args: string[]): { positional: string[]; flags: Record 0) { const name = arg.slice(2, eqIdx); const value = arg.slice(eqIdx + 1); + rejectUnknownFlag(name); if (BOOL_FLAGS.has(name) && value !== 'true' && value !== 'false') { console.error(`${paintStderr(ANSI_RED, 'Error:')} --${name} is a boolean flag: use --${name} or --${name}=false`); process.exit(2); @@ -86,6 +98,7 @@ function parseArgs(args: string[]): { positional: string[]; flags: Record`); process.exit(2); diff --git a/test/cli-error-paths.test.js b/test/cli-error-paths.test.js index 5e50b9a..f544e99 100644 --- a/test/cli-error-paths.test.js +++ b/test/cli-error-paths.test.js @@ -346,3 +346,16 @@ test('bare boolean switches are still accepted', () => { assert.equal(r.status, 0); assert.doesNotMatch(r.stderr, /requires a value/); }); + +test('unknown or misspelled --flags exit 2 with an unknown-flag error', () => { + for (const [args, flag] of [ + [['watch', 's', '--captur=50'], 'captur'], + [['send', 's', '--text=hi', '--entr'], 'entr'], + [['watch', 's', '--'], ''], + [['watch', 's', '--=x'], ''], + ]) { + const r = spawnSync(process.execPath, [CLI, ...args], { encoding: 'utf8' }); + assert.equal(r.status, 2, args.join(' ')); + assert.match(r.stderr, new RegExp(`unknown flag --${flag}`)); + } +}); From ae13852247d6c5dfe65f5a3bcccff3d9eb2d875f Mon Sep 17 00:00:00 2001 From: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Fri, 23 Oct 2026 08:04:07 -0400 Subject: [PATCH 2/2] fix(cli): drop undocumented --h from KNOWN_FLAGS; move unknown-flag README note Review follow-ups for #347: - remove 'h' from KNOWN_FLAGS so `--h` is rejected like any other unknown flag (help is only --help / -h) - move the unknown-flag exit-2 note from the diagnostics subsection to the CLI Commands section where the other global exit-2 notes live Hive-Fix-Attempt: 1/6 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- README.md | 3 ++- src/cli.ts | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bff6b1b..5096015 100644 --- a/README.md +++ b/README.md @@ -107,6 +107,8 @@ tmux attach -t my-agent | `pluk patterns --cli=claude` | Show loaded patterns for a CLI | | `pluk --help` / `-h` | Show usage (works after any subcommand) | +Unknown or misspelled `--flags` on any command exit 2 (`unknown flag --name`) instead of being silently ignored. + ### Attach Flags | Flag | What it does | @@ -147,7 +149,6 @@ tell a healthy quiet session from one that is repeatedly failing, add `--diagnostics[=secs]` (default every 60 s); the value must be a positive number of seconds (at most 2147483, the `setInterval` limit), or omitted to use the default—anything else is rejected with exit 2. -Unknown or misspelled `--flags` also exit 2 (`unknown flag --name`) instead of being ignored. It writes one JSON line per period, plus a final one on exit, to **stderr** — stdout stays pure event JSONL: diff --git a/src/cli.ts b/src/cli.ts index d7f7be5..6c932f0 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -70,7 +70,7 @@ const BOOL_FLAGS = new Set([ ]); const KNOWN_FLAGS = new Set([ - 'help', 'h', ...VALUE_FLAGS, ...BOOL_FLAGS, 'capture', 'diagnostics', + 'help', ...VALUE_FLAGS, ...BOOL_FLAGS, 'capture', 'diagnostics', ]); function rejectUnknownFlag(name: string): void {