Skip to content

The agent that grows with you

fix(bot-mode): group-chat command approvals surface in the room too — same hidden-session class

Teknium1179f148e436
diff --git a/apps/desktop/src/plugins/hermes-bots/plugin.js b/apps/desktop/src/plugins/hermes-bots/plugin.js
index f363b2e62f1..3117b52b3f6 100644
--- a/apps/desktop/src/plugins/hermes-bots/plugin.js
+++ b/apps/desktop/src/plugins/hermes-bots/plugin.js
@@ -205,12 +205,13 @@ const $groupChats = atom({})
const $groupChatWorkspace = atom(null)
/** Groups whose latest room activity mentions @user — the needs-you badge. */
const $groupNeedsYou = atom({})
-// Pending clarify questions raised inside hidden group-member sessions,
-// keyed `${group}::${memberKey}` (#90694). Members run in invisible plumbing
-// sessions, so a member's clarify tool used to block server-side with no
-// surface to answer it — the user saw "is thinking…" until the clarify
-// timeout. The turn poll mirrors each member's `pending_clarify` resume
-// field in here; the room renders answer cards from it.
+// Pending prompts (clarify questions AND command approvals) raised inside
+// hidden group-member sessions, keyed `${group}::${memberKey}` (#90694).
+// Members run in invisible plumbing sessions, so a member's blocking prompt
+// used to park server-side with no surface to answer it — the user saw
+// "is thinking…" until the prompt timeout. The turn poll mirrors each
+// member's `pending_clarify` / `pending_approval` resume fields in here;
+// the room renders answer cards from it.
const $groupClarify = atom({})
// ── group activity feed ─────────────────────────────────────────────────────
@@ -4359,15 +4360,20 @@ const GROUP_TURN_POLL_MS = 2000
// reached the room (db's Aug 2026 report).
const GROUP_TURN_HARD_CAP_MS = 20 * 60000
-/** Mirror a member's pending clarify (if any) from its resume snapshot into
- * the room store, keyed `${group}::${memberKey}` (#90694). Returns true
- * while a question is blocking, so the turn poll can extend its deadline —
- * a waiting question must not be eaten by the group-turn timeout. Feature-
- * detected: older backends without `pending_clarify` in the resume payload
- * always sync to "no question". */
+/** Mirror a member's pending prompt — clarify question OR command approval —
+ * from its resume snapshot into the room store, keyed
+ * `${group}::${memberKey}` (#90694). Returns true while a prompt is
+ * blocking, so the turn poll can extend its deadline — a waiting prompt
+ * must not be eaten by the group-turn timeout. Feature-detected: older
+ * backends without `pending_clarify`/`pending_approval` in the resume
+ * payload always sync to "no prompt". Clarify wins when both are somehow
+ * present (approvals resolve inside tool batches; clarify is the outer
+ * blocker). */
function syncGroupClarify(group, member, state) {
const key = `${group}::${groupMemberKey(member)}`
- const pending = state && typeof state.pending_clarify === 'object' ? state.pending_clarify : null
+ const clarify = state && typeof state.pending_clarify === 'object' ? state.pending_clarify : null
+ const approval = state && typeof state.pending_approval === 'object' ? state.pending_approval : null
+ const pending = clarify || approval
const requestId = pending?.request_id || null
const all = $groupClarify.get()
const current = all[key]
@@ -4388,21 +4394,43 @@ function syncGroupClarify(group, member, state) {
return true
}
+ const base = {
+ requestId,
+ group,
+ member: member.name,
+ memberKey: groupMemberKey(member),
+ // approval.respond keys on the session, not just the request — carry the
+ // runtime id the snapshot came from.
+ sessionId: state?.session_id || null,
+ at: Date.now()
+ }
+
$groupClarify.set({
...all,
- [key]: {
- requestId,
- group,
- member: member.name,
- memberKey: groupMemberKey(member),
- question: typeof pending.question === 'string' ? pending.question : '',
- choices: Array.isArray(pending.choices) ? pending.choices.filter(c => typeof c === 'string' && c) : [],
- multiSelect: Boolean(pending.multi_select),
- // Batch clarifies carry `questions`; the room card answers them
- // one wire call per question, mirroring the 1:1 batch contract.
- questions: Array.isArray(pending.questions) ? pending.questions : null,
- at: Date.now()
- }
+ [key]: clarify
+ ? {
+ ...base,
+ kind: 'clarify',
+ question: typeof clarify.question === 'string' ? clarify.question : '',
+ choices: Array.isArray(clarify.choices) ? clarify.choices.filter(c => typeof c === 'string' && c) : [],
+ multiSelect: Boolean(clarify.multi_select),
+ // Batch clarifies carry `questions`; the room card answers them
+ // one wire call per question, mirroring the 1:1 batch contract.
+ questions: Array.isArray(clarify.questions) ? clarify.questions : null
+ }
+ : {
+ ...base,
+ kind: 'approval',
+ question: typeof approval.description === 'string' ? approval.description : '',
+ command: typeof approval.command === 'string' ? approval.command : '',
+ // The server precomputes the choice set from allow_permanent
+ // (once/session/always/deny); fall back to the minimal pair.
+ choices: Array.isArray(approval.choices) && approval.choices.length
+ ? approval.choices.filter(c => typeof c === 'string' && c)
+ : ['once', 'deny'],
+ multiSelect: false,
+ questions: null
+ }
})
// A blocked member is a question for the human — badge the room.
$groupNeedsYou.set({ ...$groupNeedsYou.get(), [group]: true })
@@ -4429,14 +4457,23 @@ function clearGroupClarify(group) {
}
}
-/** Answer a member's pending clarify from the room. Routes clarify.respond
- * to the member's OWN source (requestForBot), so cross-connection members
- * work. Batch questions send one respond per question, sequentially — the
- * LAST lock resolves the blocked tool server-side (same contract as the
- * 1:1 batch card). allow_expired server-side makes racing the timeout
- * harmless. */
+/** Answer a member's pending prompt from the room. Routes to the member's
+ * OWN source (requestForBot), so cross-connection members work.
+ * - clarify: `clarify.respond`; batch questions send one respond per
+ * question, sequentially — the LAST lock resolves the blocked tool
+ * server-side (same contract as the 1:1 batch card). allow_expired
+ * server-side makes racing the timeout harmless.
+ * - approval: `approval.respond` with the choice (once/session/always/deny),
+ * keyed by session + request_id — the same wire the 1:1 approval card
+ * and native notifications use. */
async function answerGroupClarify(entry, member, answers) {
- if (entry.questions && entry.questions.length) {
+ if (entry.kind === 'approval') {
+ await requestForBot(member, 'approval.respond', {
+ session_id: entry.sessionId || undefined,
+ request_id: entry.requestId,
+ choice: typeof answers === 'string' && answers ? answers : 'deny'
+ })
+ } else if (entry.questions && entry.questions.length) {
for (const question of entry.questions) {
const qid = question?.qid ?? question?.id
await requestForBot(member, 'clarify.respond', {
@@ -8887,12 +8924,16 @@ function GroupMentionInput({ members, onChange, value, ...inputProps }) {
})
}
-/** One member's pending question, rendered in the room (#90694). Choices
- * render as tap buttons (multi-select stages; single-select stages one);
- * free text always available; Answer sends via the member's own source.
- * Batch clarifies render every sub-question with its own input. */
+/** One member's pending prompt, rendered in the room (#90694).
+ * - clarify: choices as tap buttons (multi-select stages; single-select
+ * stages one), free text always available, batch sub-questions each get
+ * their own input.
+ * - approval: the command in a code row plus the server's choice set
+ * (once/session/always/deny) as buttons — no free text; approvals are a
+ * closed choice. Answer sends via the member's own source. */
function GroupClarifyCard({ entry, members }) {
const { group } = entry
+ const isApproval = entry.kind === 'approval'
const member = members.find(m => groupMemberKey(m) === entry.memberKey) || members.find(m => m.name === entry.member)
const [drafts, setDrafts] = useState({})
const [picked, setPicked] = useState({})
@@ -8913,7 +8954,7 @@ function GroupClarifyCard({ entry, members }) {
return q.multiSelect ? JSON.stringify(chosen) : chosen[0]
}
- return (drafts[q.qid] || '').trim()
+ return isApproval ? '' : (drafts[q.qid] || '').trim()
}
const allAnswered = questions.every(q => answerFor(q))
@@ -8926,7 +8967,9 @@ function GroupClarifyCard({ entry, members }) {
setSending(true)
try {
- if (entry.questions && entry.questions.length) {
+ if (isApproval || !(entry.questions && entry.questions.length)) {
+ await answerGroupClarify(entry, member, answerFor(questions[0]))
+ } else {
const answers = {}
for (const q of questions) {
@@ -8934,14 +8977,14 @@ function GroupClarifyCard({ entry, members }) {
}
await answerGroupClarify(entry, member, answers)
- } else {
- await answerGroupClarify(entry, member, answerFor(questions[0]))
}
// Echo the exchange into the room log so the thread reads complete.
- const summary = questions
- .map(q => (questions.length > 1 ? `${q.question}: ${answerFor(q)}` : answerFor(q)))
- .join('\n')
+ const summary = isApproval
+ ? `${answerFor(questions[0])} — ${entry.command || entry.question || 'command approval'}`
+ : questions
+ .map(q => (questions.length > 1 ? `${q.question}: ${answerFor(q)}` : answerFor(q)))
+ .join('\n')
appendGroupChatEntry(group, { kind: 'user', name: 'You' }, summary, entry.thread || 'legacy')
} catch (err) {
host.notify({ kind: 'error', message: `Could not send the answer to @${botHandle(entry.member, member)}: ${err?.message || err}` })
@@ -8957,10 +9000,22 @@ function GroupClarifyCard({ entry, members }) {
jsxs('div', {
className: 'flex items-center gap-1.5 text-xs font-medium',
children: [
- jsx(Codicon, { name: 'question', className: 'shrink-0 text-(--ui-accent,#4f9cf9)' }),
- `@${botHandle(entry.member, member)} asks:`
+ jsx(Codicon, {
+ name: isApproval ? 'shield' : 'question',
+ className: 'shrink-0 text-(--ui-accent,#4f9cf9)'
+ }),
+ isApproval
+ ? `@${botHandle(entry.member, member)} wants to run a command:`
+ : `@${botHandle(entry.member, member)} asks:`
]
}),
+ isApproval && entry.command
+ ? jsx('code', {
+ className:
+ 'block overflow-x-auto rounded bg-(--ui-bg-secondary,rgba(0,0,0,0.25)) px-2 py-1 font-mono text-[0.7rem] whitespace-pre-wrap break-all',
+ children: entry.command
+ })
+ : null,
...questions.map(q =>
jsxs('div', {
className: 'grid gap-1',
@@ -8977,7 +9032,10 @@ function GroupClarifyCard({ entry, members }) {
return jsx(Button, {
size: 'sm',
variant: chosen ? 'default' : 'secondary',
- className: 'h-6 px-2 text-[0.7rem]',
+ className: cn(
+ 'h-6 px-2 text-[0.7rem]',
+ isApproval && choice === 'deny' && !chosen && 'text-destructive'
+ ),
onClick: () => {
setDrafts(prev => ({ ...prev, [q.qid]: '' }))
setPicked(prev => {
@@ -8998,23 +9056,26 @@ function GroupClarifyCard({ entry, members }) {
})
})
: null,
- jsx(Input, {
- 'aria-label': `Answer @${entry.member}`,
- placeholder: q.choices.length ? 'Or type your own answer…' : 'Type your answer…',
- value: drafts[q.qid] || '',
- onChange: event => {
- const value = event.target.value
- setPicked(prev => ({ ...prev, [q.qid]: [] }))
- setDrafts(prev => ({ ...prev, [q.qid]: value }))
- },
- onKeyDown: event => {
- if (event.key === 'Enter' && questions.length === 1) {
- event.preventDefault()
- void submit()
- }
- },
- className: 'h-7 text-xs'
- }, `input:${q.qid}`)
+ // Approvals are a closed choice set — no free-text input.
+ isApproval
+ ? null
+ : jsx(Input, {
+ 'aria-label': `Answer @${entry.member}`,
+ placeholder: q.choices.length ? 'Or type your own answer…' : 'Type your answer…',
+ value: drafts[q.qid] || '',
+ onChange: event => {
+ const value = event.target.value
+ setPicked(prev => ({ ...prev, [q.qid]: [] }))
+ setDrafts(prev => ({ ...prev, [q.qid]: value }))
+ },
+ onKeyDown: event => {
+ if (event.key === 'Enter' && questions.length === 1) {
+ event.preventDefault()
+ void submit()
+ }
+ },
+ className: 'h-7 text-xs'
+ }, `input:${q.qid}`)
]
}, `q:${q.qid}`)
),
@@ -9024,7 +9085,7 @@ function GroupClarifyCard({ entry, members }) {
size: 'sm',
disabled: sending || !allAnswered || !member,
onClick: () => void submit(),
- children: sending ? 'Sending…' : 'Answer'
+ children: sending ? 'Sending…' : isApproval ? 'Respond' : 'Answer'
})
})
]
diff --git a/apps/desktop/src/plugins/hermes-bots/tests/group-chat.test.mjs b/apps/desktop/src/plugins/hermes-bots/tests/group-chat.test.mjs
index bb979b80a23..06701894757 100644
--- a/apps/desktop/src/plugins/hermes-bots/tests/group-chat.test.mjs
+++ b/apps/desktop/src/plugins/hermes-bots/tests/group-chat.test.mjs
@@ -8,7 +8,7 @@ const pluginSource = readFileSync(new URL('../plugin.js', import.meta.url), 'utf
/** Load the plugin in a vm with a scripted cli.exec so member turns are
* deterministic. `turnScript(profile, prompt)` returns the member's reply
* text (or throws to simulate a failed turn). */
-function load(turnScript, { busyUntilResumeCall, clarifyUntilResumeCall } = {}) {
+function load(turnScript, { busyUntilResumeCall, clarifyUntilResumeCall, approvalUntilResumeCall } = {}) {
const values = new Map()
const atom = initial => {
const slot = { get: () => values.get(slot), set: value => values.set(slot, value) }
@@ -17,6 +17,7 @@ function load(turnScript, { busyUntilResumeCall, clarifyUntilResumeCall } = {})
}
const calls = []
const clarifyResponds = []
+ const approvalResponds = []
const sessions = new Map()
const runtimeToStored = new Map()
const titleToStored = new Map()
@@ -69,6 +70,9 @@ function load(turnScript, { busyUntilResumeCall, clarifyUntilResumeCall } = {})
// simulating a member blocked on its clarify tool (#90694).
const clarify = clarifyUntilResumeCall && clarifyUntilResumeCall[profile]
const pendingClarify = clarify && seen <= clarify.until ? clarify.payload : null
+ // Same window shape for pending command approvals (#90694 class).
+ const approval = approvalUntilResumeCall && approvalUntilResumeCall[profile]
+ const pendingApproval = approval && seen <= approval.until ? approval.payload : null
return {
session_id: session.runtime,
session_key: session.stored,
@@ -76,7 +80,8 @@ function load(turnScript, { busyUntilResumeCall, clarifyUntilResumeCall } = {})
messages: [...session.messages],
inflight: busy,
running: busy,
- ...(pendingClarify ? { pending_clarify: pendingClarify } : {})
+ ...(pendingClarify ? { pending_clarify: pendingClarify } : {}),
+ ...(pendingApproval ? { pending_approval: pendingApproval } : {})
}
}
if (method === 'prompt.submit') {
@@ -100,6 +105,10 @@ function load(turnScript, { busyUntilResumeCall, clarifyUntilResumeCall } = {})
clarifyResponds.push({ ...params })
return { ok: true }
}
+ if (method === 'approval.respond') {
+ approvalResponds.push({ ...params })
+ return { resolved: true }
+ }
return {}
},
state: { profile: { get: () => 'default', listen: () => undefined }, gateway: { listen: () => undefined } },
@@ -123,7 +132,7 @@ function load(turnScript, { busyUntilResumeCall, clarifyUntilResumeCall } = {})
storage: { get: () => null, set: (key, value) => storageWrites.set(key, value) },
register: () => undefined
})
- return { ...context.__gc, calls, clarifyResponds, host: context.host, sessions, storageWrites }
+ return { ...context.__gc, approvalResponds, calls, clarifyResponds, host: context.host, sessions, storageWrites }
}
const MEMBERS = [{ name: 'research', title: '' }, { name: 'builder', title: '' }, { name: 'ops', title: 'The Ops' }]
@@ -1022,3 +1031,96 @@ test('source contract: room renders clarify cards and the poll gates on them', (
assert.match(pluginSource, /roomClarifies\.map\(entry =>/)
assert.match(pluginSource, /'clarify\.respond'/)
})
+
+// ── group approvals: same hidden-session class as clarify (#90694) ─────────
+
+const APPROVAL_PAYLOAD = {
+ request_id: 'req-approval-1',
+ command: 'rm -rf ./build',
+ description: 'Clean the build directory',
+ choices: ['once', 'session', 'deny']
+}
+
+test('a member blocked on a command approval surfaces an approval card and holds the turn', async () => {
+ const gc = load(() => 'build cleaned', {
+ approvalUntilResumeCall: { research: { payload: APPROVAL_PAYLOAD, until: 3 } }
+ })
+
+ const thread = gc.sendToGroupChat('Core', [MEMBERS[0]], '@research clean up', null, [])
+ await new Promise(resolve => setTimeout(resolve, 0))
+ await new Promise(resolve => setTimeout(resolve, 0))
+
+ const log = gc.$groupChats.get().Core.log.filter(e => e.thread === thread)
+ const replies = log.filter(e => e.from.kind === 'member')
+
+ assert.equal(replies.length, 1, 'the finished reply still lands after the approval clears')
+ assert.equal(replies[0].text, 'build cleaned')
+ assert.equal(Object.keys(gc.$groupClarify.get()).length, 0)
+ assert.equal(gc.$groupNeedsYou.get().Core, true, 'the blocking approval badged the room')
+})
+
+test('syncGroupClarify mirrors an approval with kind, command, and server choices', () => {
+ const gc = load(() => '(pass)')
+ const member = { name: 'research', title: '' }
+
+ const blocked = gc.syncGroupClarify('Core', member, {
+ session_id: 'rt-research-1',
+ pending_approval: APPROVAL_PAYLOAD
+ })
+ assert.equal(blocked, true)
+
+ const entry = Object.values(gc.$groupClarify.get())[0]
+ assert.equal(entry.kind, 'approval')
+ assert.equal(entry.command, 'rm -rf ./build')
+ assert.equal(entry.question, 'Clean the build directory')
+ assert.equal(JSON.stringify(entry.choices), JSON.stringify(['once', 'session', 'deny']))
+ assert.equal(entry.sessionId, 'rt-research-1')
+})
+
+test('an approval without a server choice set falls back to once/deny', () => {
+ const gc = load(() => '(pass)')
+
+ gc.syncGroupClarify('Core', { name: 'research' }, {
+ pending_approval: { request_id: 'req-a2', command: 'ls' }
+ })
+
+ const entry = Object.values(gc.$groupClarify.get())[0]
+ assert.equal(JSON.stringify(entry.choices), JSON.stringify(['once', 'deny']))
+})
+
+test('answerGroupClarify routes approvals through approval.respond with session + choice', async () => {
+ const gc = load(() => '(pass)')
+ const member = { name: 'research', title: '' }
+
+ gc.syncGroupClarify('Core', member, { session_id: 'rt-research-1', pending_approval: APPROVAL_PAYLOAD })
+ const entry = Object.values(gc.$groupClarify.get())[0]
+
+ await gc.answerGroupClarify(entry, member, 'once')
+
+ assert.equal(
+ JSON.stringify(gc.approvalResponds),
+ JSON.stringify([{ session_id: 'rt-research-1', request_id: 'req-approval-1', choice: 'once' }])
+ )
+ assert.equal(gc.clarifyResponds.length, 0, 'approvals never touch the clarify wire')
+ assert.equal(Object.keys(gc.$groupClarify.get()).length, 0)
+})
+
+test('clarify outranks approval when a snapshot carries both', () => {
+ const gc = load(() => '(pass)')
+
+ gc.syncGroupClarify('Core', { name: 'research' }, {
+ pending_clarify: CLARIFY_PAYLOAD,
+ pending_approval: APPROVAL_PAYLOAD
+ })
+
+ const entry = Object.values(gc.$groupClarify.get())[0]
+ assert.equal(entry.kind, 'clarify')
+ assert.equal(entry.requestId, 'req-clarify-1')
+})
+
+test('source contract: approval card renders the command and routes approval.respond', () => {
+ assert.match(pluginSource, /pending_approval/)
+ assert.match(pluginSource, /'approval\.respond'/)
+ assert.match(pluginSource, /kind: 'approval'/)
+ assert.match(pluginSource, /wants to run a command/)
+})