Skip to content

cli: validate --thinking values against THINKING_LEVELS - #496

Open
DawnofGenX wants to merge 1 commit into
Observal:mainfrom
DawnofGenX:fix-thinking-level-validation
Open

DawnofGenX wants to merge 1 commit into
Observal:mainfrom
DawnofGenX:fix-thinking-level-validation

Conversation

@DawnofGenX

@DawnofGenX DawnofGenX commented Oct 14, 2026 •

Copy link
Copy Markdown

Purpose

axl --thinking <level> accepted any string. The value was cast straight to ThinkingLevel without a check, so a typo like axl --thinking hgih was not caught while arguments were parsed. Other options with a fixed value set, such as --profile and --sandbox, already fail fast with a clear message.

Fixes

Fixes #421

Approach

In parseArguments (packages/cli/src/main.ts), check the --thinking value against THINKING_LEVELS from @axl/protocol. On a bad value, throw in the same style as --profile: Unknown thinking level hgih; expected off, minimal, low, medium, high, xhigh, or max. No compatibility or security impact; the check runs before any credential or daemon work.

How was this tested?

  • pnpm --filter @axl/cli test — 55 pass, 0 fail (3 skipped).
  • New test rejects invalid thinking level arguments asserts axl --thinking hgih exits non-zero with the expected message.
  • Regression check: reverting the main.ts change makes the new test fail (1 fail); restoring it makes it pass.
  • pnpm --filter @axl/cli typecheck clean.

Learning

The --profile validation was the existing pattern to mirror, so the error message and throw site stay consistent.

Checklist

  • I reviewed the complete diff.
  • I added or updated the smallest relevant test for behavior changes.
  • I ran the relevant formatting, lint, type-check, test, boundary, and license checks.
  • Every new file has SPDX metadata, directly or through REUSE.toml.
  • Every commit has a matching DCO Signed-off-by trailer.
  • UI changes include screenshots attached to the pull request, not committed to the repository.

AI assistance

  • Generative AI materially assisted this change. Tool and model/version: Hermes Agent (Nous Research), model qwen3.8-flash.
  • I manually reviewed, understood, and tested the generated work.

Summary by CodeRabbit

  • Bug Fixes
    • The CLI rejects unrecognized --thinking values and reports the accepted levels.

@DawnofGenX
DawnofGenX requested a review from Haz3-jolt as a code owner October 14, 2026 21:31
@coderabbitai

coderabbitai Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 724965ec-d65b-4e1e-8209-91c0ebf988bc
📥 Commits

Reviewing files that changed from the base of the PR and between 77cafc4 and a1b73f3.

📒 Files selected for processing: 1
  • packages/cli/src/main.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 1 remain after this review.

📝 Walkthrough

The CLI now validates --thinking values against THINKING_LEVELS. Unknown values produce an error listing the accepted levels. A test checks the exit code and error message for an invalid value.

Changes: Thinking level validation

Layer / File(s) Summary
Validate --thinking arguments
packages/cli/src/main.ts, packages/cli/test/unsafe-cli.test.ts
parseArguments checks supplied values against THINKING_LEVELS and reports the accepted levels for unknown values. The test verifies that an unknown value exits with code 1 and lists the accepted levels.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Suggested reviewers: kaushik-kumar-ceg

Merge Risk: ⚪ Minimal · up to a1b73

Unknown --thinking values now fail before credential or daemon work, while recognized levels are accepted. No concrete merge-blocking risk remains.

Pre-merge checks: Passed 5
Passed Passed checks: 5 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: validation of CLI --thinking values against THINKING_LEVELS.
Description check Passed The description includes all required sections, explains the problem and approach, links the fixing issue, documents tests and results, and records checklist and AI-assistance details. The reported va…
Linked Issues check Passed Issue [#421] has coding requirements, and the reviewed head satisfies them. packages/cli/src/main.ts imports THINKING_LEVELS from @axl/protocol and validates --thinking before assigning the va…
Out of Scope Changes check Passed The change summary identifies only packages/cli/src/main.ts and packages/cli/test/unsafe-cli.test.ts. The source change implements [#421] validation, and the test verifies that behavior. No unrela…
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔇 Additional comments: 2
packages/cli/test/unsafe-cli.test.ts: 1

128-135: LGTM!

packages/cli/src/main.ts: 1

241-248: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

⚠️ Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.

Replace the as ThinkingLevel assertions with a type guard.

The code uses level as ThinkingLevel twice. The first use is only there to satisfy includes on a readonly ThinkingLevel[]. The second use trusts the earlier check. Both assertions bypass the compiler. Use one type guard so the compiler narrows level.

The message builder also has a one-element branch. THINKING_LEVELS has seven entries, so that branch never runs. Keep the list formatting simple.

Proposed fix
-      if (!THINKING_LEVELS.includes(level as ThinkingLevel)) {
-        const expected =
-          THINKING_LEVELS.length > 1
-            ? `${THINKING_LEVELS.slice(0, -1).join(", ")}, or ${THINKING_LEVELS[THINKING_LEVELS.length - 1]}`
-            : THINKING_LEVELS[0];
-        throw new Error(`Unknown thinking level ${level}; expected ${expected}`);
-      }
-      parsed.thinking = level as ThinkingLevel;
+      const known = THINKING_LEVELS.find((candidate) => candidate === level);
+      if (known === undefined) {
+        const expected = `${THINKING_LEVELS.slice(0, -1).join(", ")}, or ${THINKING_LEVELS.at(-1)}`;
+        throw new Error(`Unknown thinking level ${level}; expected ${expected}`);
+      }
+      parsed.thinking = known;

Based on learnings: in TypeScript, prefer type narrowing over as assertions and use runtime checks instead.

Source: Learnings


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5c2e7488-3c96-4e80-b0ef-462452e3304b
📥 Commits

Reviewing files that changed from the base of the PR and between 4393da4 and 77cafc4.

📒 Files selected for processing: 2
  • packages/cli/src/main.ts
  • packages/cli/test/unsafe-cli.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

Check the value against THINKING_LEVELS from @axl/protocol and throw
an error in the same style as --profile when an invalid level is
provided. Add a test for the invalid case.

Fixes Observal#421

Signed-off-by: Priyansh <pkansara0412@gmail.com>
@DawnofGenX
DawnofGenX force-pushed the fix-thinking-level-validation branch from 77cafc4 to a1b73f3 Compare October 14, 2026 22:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Validate --thinking values in the CLI

1 participant