fix(ai): resolve engine aliases for ai({ engine }) - #62
Merged
Conversation
`ai(prompt, { engine: "cc" })` failed with "ai() needs an installed engine"
even with Claude installed, because pickAiEngine() matched raw ENGINES keys and
never consulted ALIASES — while /agents, start and upgrade all resolve aliases
(README: "name any; alias ok"). Under --dry-run it was worse: the raw alias
reached aiExecArgs() and threw "no headless mode", though a dry run is meant to
narrate without requiring an installed engine.
Resolve the preference through resolveEngine() and let the dry-run fallback do
the same. An unknown name still yields null, and a named-but-not-installed
engine still refuses to fall back to another one.
clawedassistant26
force-pushed
the
fix/ai-engine-alias
branch
from
July 29, 2026 17:24
0f3aa92 to
022deac
Compare
Contributor
Author
|
Rebased on main to clear the conflict with #74. The clash was in pickAiEngine: #74 added privacycode to the default order, this PR changed the preferred branch to resolve aliases first. Resolved so both hold, alias resolution on the preferred path and privacycode kept in the default order. Full suite green after the rebase, 206 tests across 6 suites, 0 failures, and CI is passing. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
ai(prompt, { engine: "cc" })fails withmoshscript: ai() needs an installed engine — try install("claude")even when Claude Code is installed and on PATH.pickAiEngine()matched rawENGINESkeys only, so it never consultedALIASES— while every other engine surface does resolve them viaresolveEngine():Under
--dry-runit fails differently and worse. The fallback handed the raw alias toaiExecArgs(), which throws:That contradicts the intent stated on the line above it — "narrate without requiring an installed engine". A dry run should never need an engine to be present.
Repro (executed against
dfcb8c1, not reasoned)A stub
claudeon PATH, andalias.mosh:The fix
src/engines.mjs— resolve the preference through the existingresolveEngine()(which already guards againstObject.prototypenames, per fix(resolve): stop an Object.prototype name resolving as an engine or tool #48).src/cli.mjs— the dry-run fallback resolves the alias too, so narration works with nothing installed.Deliberately unchanged:
null(pickAiEngine("definitely-not-an-engine"),pickAiEngine("constructor"));pickAiEngine("gemini")→nullwhen Gemini is absent);claude, codex, opencode, gemini, aiderorder;aiExecArgs()stays strict, so a genuinely unknown engine name still throws in a dry run.After the fix:
Tests
Two added, both fail before / pass after (stash-verified with
git stash push -- src/: 50 pass / 2 fail unpatched, 52/52 with the fix):test/engines.test.mjs—pickAiEngineresolvesccandclaude-codetoclaudeagainst a stub engine on PATH, and still returnsnullfor an unknown name.test/cli.test.mjs— a dry-runai()with{ engine: "cc" }narrateswould run: claude -pinstead of throwing.Full suite
npm test: 199 tests / 199 pass / 0 fail (197 before this change).