Repository navigation
feat(agent): add AgentSession.submit for host-agnostic input - #363
Merged
Merged
Conversation
A command is not a message: prompt() dispatches it before it looks at the
run, which is why a host cannot queue or steer one. That rule lived only in
steer()'s guard, so every host re-derived it, and one that queued a command
sent the literal line to the model instead.
- submit(text, { duringRun }): the entry a host calls. Commands run on the
spot during or between runs; text starts a turn or joins the running one.
- isCommandInput(text): the same question without side effects, for a host
that keeps its own editable queue.
- The guard now covers the session's own /clm family, which prompt()
dispatches itself and no extension registers. steer("/clm status") used to
reach the model as text.
- One name split (slashCommandNameOf) and one predicate (_isCommandName)
behind prompt(), submit(), isCommandInput() and the guard.
The CLI drops its own isExtensionCommand copy and submits through submit().
liuedcson
requested review from
MelodyVAR,
Uking-xxx and
ZouR-Ma
as code owners
November 19, 2026 04:15
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.
背景
内核里"用户输入要先命令分发、再排队"这条语义只以
steer()里一句throw的形式存在,于是每个宿主都得自己重新推导一遍,漏一个入口就出错:session.steer())或回车(宿主自己的队列)发/compact、/goal、插件命令,前者命中Extension command "..." cannot be queued,后者把命令当普通消息排进队列;裸/btw也进了队列,回合结束才回 usage。/clm更糟:它由_handleLiveContextCommand在prompt()内部处理,不在扩展注册表里,所以_throwIfExtensionCommand拦不住 —— 排队后模型收到的是字面量/clm status。isExtensionCommand纯函数副本。实现
1. 会话给出唯一入口与唯一判据(
packages/coding-agent/src/core/agent-session.ts)submit(text, { duringRun = "steer", ...rest }):内部委托给prompt(),命令先分发、其余按duringRun入队。宿主不再需要先看isStreaming。isCommandInput(text):纯判据,命中 live-context 命令或已注册扩展命令;prompt 模板与/skill:明确不算(展开后仍是消息)。宿主自己的可编辑队列用它决定"不要把这行停在队列里"。_isCommandName()抽出一处判定,prompt()的分发顺序(live-context → 扩展命令)与守卫共用,避免两套。_throwIfExtensionCommand改名_throwIfCommand,把/clm、/clm-compact也纳入;报错文案改为Command "/x" cannot be queued as a message. Use prompt() or submit() to run it, during or between runs.LIVE_CONTEXT_COMMAND_NAMES常量替代_handleLiveContextCommand里的字面量比较,slashCommandNameOf()替代三处重复的indexOf(" ")切分。2. CLI 删除重复的判断(
apps/cli/)isExtensionCommand纯函数与RuntimeContext.isExtensionCommand删除,改用session.isCommandInput();四处 streaming 提交从prompt(text, { streamingBehavior })改为submit(text, { duringRun })。CLI 行为不变,只是不再自己维护一份命令识别的副本。3. 文档(
packages/coding-agent/docs/sdk.md、docs/rpc.md、CHANGELOG.md)sdk.md写清"命令不是消息"、submit()优先于steer()、isCommandInput()的用途,以及仍归宿主的边界:compaction 期间任何 prompt 都会被拒,宿主要在 compaction 结束后自己调用submit()。验证
test/suite/agent-session-submit.test.ts(7 条):命令在运行中立即执行且不进两个队列;默认 steer、duringRun: "followUp"两种文本入队;空闲时直接开 turn;isCommandInput对/testcmd/clm/skill:x/usr/local/bin/的判定;steer("/clm status")被拒且不污染队列。packages/coding-agent定向:agent-session-submit+agent-session-queue22 passed;apps/cli全量 93 文件 762 passed。./test.sh:本机git是依赖$HOME的 shim,test.sh 清空 HOME 后所有 spawn git 的用例都会失败(与本次改动无关,env -i HOME=/tmp/x git --version即可复现)。换用不依赖 HOME 的 shim 后全量通过。tsgo --noEmit与biome check --error-on-warnings干净。边界
steer()/followUp()保留:已经决定"这是消息"的宿主仍可直接用。apps/web)改用submit()/isCommandInput()是后续独立改动,走内场。