Skip to content

fix(explain): warn on an unknown or ambiguous command inside [ … ] (#572) - #680

Draft
mobileskyfi wants to merge 2 commits into
mainfrom
fix/572-bracket-subcommand-diagnostics
Draft

mobileskyfi wants to merge 2 commits into
mainfrom
fix/572-bracket-subcommand-diagnostics

Conversation

@mobileskyfi

@mobileskyfi mobileskyfi commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #572.

Change

:put [/ip/address/nosuchverb], :put [nosuchcmd] and :local varID [nosuchcmd where name=x] returned pass with no diagnostics. The same text at the top level warned, because the unresolved-statement and ambiguous-statement warnings were only emitted per statement. Now a […] subcommand that the verb reader read gets the same warning, spanned on the substitution. It is still a warning and never an error; offline still abstains.

Scope (revised after review): a bracket warns unless it has no command in it. The silent brackets are those where Q3 finds no command head (path === null and no tokens): a [$f] call, a [($a . $b)] expression, or a pasted CLI prompt. The device accepts these, and the corrected-anchor rows trailing-selector* pin pass. A bracket Q3 refuses that still has a command head now warns like its statement form. That covers a variable path segment ([/ip/$menu/x]) and a relative command whose context was lost. An escaped \$[…] in a string is now read as text (scanInterpolations skips escaped characters). Before this, it produced a phantom substitution.

Corpus census

The run covered the pinned 948-script corpus (lsp-routeros-ts/test-data/corpus.sqlite, sibling copy matching the pin). The device oracle is parseObservations over the four recorded sessions: long-term 7.23.8, stable 7.24.5, testing 7.25rc2 and development 7.26beta1.

pass → warn device rejects (all versions) device accepts
A: every unknown bracket 123 9 114
B: verb-read brackets only (first head) 14 3 11
C: every bracket with a command head (this PR) 14 3 11

No other verdict changes. The variable-path and lost-context warnings that C adds land only in scripts that already warned. In the 875-case wiresage-conformance set, 3 cases move from pass to warn, and test/fixtures/explain/conformance.json is re-adopted for them: parameters-and-flags/r20 (all four versions reject [nope]), and colon-prefix/p3 and colon-prefix/p12 (accepted; colon-less builtins).

  • The 3 true rejections: [../find disabled=no], a broken …fd print as-value]], and a bare [fetch url=…].
  • The 11 device-accepted ones are shapes the offline reader can't place at the top level either, so they are parity rather than new false readings:
    • colon-less builtins: [typeof $b], [tostr $1], [pick …], [len …], [toip6 …] (5 scripts)
    • [/terminal/inkey] (4)
    • [/system/script/run staticUrl] (1)
    • [monitor $ups once as-value] (1)

I added three matrix nits: one for the non-ASCII bracket spans that widen to the whole statement (see the review thread), and two for the verb-reader gaps behind these: colon-less builtins, and the operand after run being read as a path. Fixing them would lower the warning count at both levels.

Tests

🤖 Generated with Claude Code

)

`:put [/ip/address/nosuchverb]` and `:local v [nosuchcmd where name=x]`
passed silently while the same text at the top level warned. The
unresolved/ambiguous warnings were emitted per statement only. A bracket the
verb reader read now gets the same abstention warning, spanned on the
substitution. A bracket with no command head ([$f], [(…)]) stays silent: the
device accepts those (corrected-anchors rows trailing-selector*).

Corpus (948 scripts, pinned): 14 move pass -> warn; 3 are rejected by every
recorded RouterOS version, 11 accepted and unreadable offline at the top level
too (recorded as two matrix nits).

Session: 4f3a1170-9bf0-4eac-97bd-7c9c9d0e6bbd
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 27, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • 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

@mobileskyfi mobileskyfi left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reviewer: codex/gpt-6.2-sol · head 2eb8da7 · session 01a21a6c-1619-7f52-b36e-70d0c2b35d5c

I found four issues, detailed inline. The GitHub Corpus census job fails at this head, and bun run explain:conformance:check reproduces the failure locally.

Against pinned snapshot e12d5d4e58a4, I compared 0cc371c and 2eb8da7. In the 948-script population, only 14 verdicts change, all pass → warn. All four recorded versions accept 11 of those scripts and reject 3. Removing the eligibility filter reproduces the wider variant's 123 changes, with 114 accepted and 9 rejected by all four versions. The accepted colon-less builtins also include [toarray "$2"].

bun test test/unit passed (5,559 passed, 9 skipped), and bun run lint:ci passed. The #572 controls, nested brackets and do={…} produced the expected warnings on exact ASCII spans, including after Unicode on a preceding line and with CRLF. Each new diagnostic cited the published e5 entry. The execute offline gate accepts these warnings as abstentions and proceeds to device validation. Live explain still probes and recomputes the verdict over the combined diagnostics. Offline exit codes for error, warning and never were 0, 2 and 0 for the warning control.

Comment thread src/explain.ts Resolved
Comment thread src/explain.ts Resolved
Comment thread src/explain.ts Resolved
…xt (#572)

Review on #680:
- A bracket Q3 refused but that still has a command head (a variable path
  segment, a relative command under a lost context) warns like its statement
  form. Only a bracket with no command in it ([$f], [(…)], a pasted prompt)
  stays silent. Corpus verdict moves are unchanged (14).
- scanInterpolations skipped no escapes, so `:put "\$[x]"` produced a phantom
  substitution and now a warning. An escaped character is skipped.
- Re-adopt the conformance fixture: 3 of 875 cases move pass -> warn.
- Matrix nit for the non-ASCII bracket-span widening.

Session: 4f3a1170-9bf0-4eac-97bd-7c9c9d0e6bbd
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Approval should wait for human confirmation of the claimed four-version CHR behavior and corpus census, which static review cannot independently verify for these parser and diagnostic changes.

No open issues 🎉

What changed in this PR

This PR updates offline explain analysis so command-bearing bracket substitutions emit the same unknown or ambiguous-command warnings as equivalent top-level statements, while preserving silent handling for expressions, function calls, and escaped interpolation text.

Changes:

  • Adds span-aware warnings for unresolved or ambiguous bracketed commands.
  • Skips escaped \$[…] sequences during interpolation scanning and keeps command-less brackets silent.
  • Updates regression tests, conformance expectations, corpus documentation, glossary entries, and the changelog.
File Description
test/​unit/​explain-structure.test.ts Adds regression coverage for bracket warnings, spans, nested and variable-path cases, escaped interpolations, and silent expressions.
test/​unit/​explain-corrected-anchors.test.ts Updates the corrected-anchor expectation for the unknown bracket command from pass to warn.
test/​fixtures/​explain/​conformance.json Records the updated conformance verdict and census expectations.
src/​explain/​pathresolve.ts Distinguishes command-less brackets and skips escaped characters while scanning interpolations.
src/​explain.ts Classifies bracket readings and emits substitution-scoped diagnostics for command-bearing brackets.
GLOSSARY.txt Adds the RouterOS inkey vocabulary term.
docs/​MATRIX.md Documents known offline-reader limitations identified by the corpus census.
CHANGELOG.md Documents the new bracketed-command warning behavior and its corpus impact.

Review effort: Lite

This branch has not been deployed

No deployments
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.

explain: an unknown or ambiguous command inside [ … ] passes silently; the same text at top level warns

3 participants