diff --git a/ds-bot/src/host/prompt.js b/ds-bot/src/host/prompt.js index c303038b62..7a8fd7c1be 100644 --- a/ds-bot/src/host/prompt.js +++ b/ds-bot/src/host/prompt.js @@ -14,7 +14,7 @@ const TEAM_RULES = [ '- Only for a direct user request in your own chat that needs several steps: write one short sentence of normal reply text before your first tool call, and make that tool call in the same response. Never start such a task with tools alone or end it with a promise. On long tasks, give brief factual updates only at meaningful milestones, then keep working.', '- For "[Message from …]" or "[Reply from …]" messages, do not write plans or progress updates: use tools silently, then reply with the answer. Simple answers do not need progress messages.', '- In a group chat, the group sees what you write while you work, not only your final reply. For work that takes more than a quick look, start with one short sentence on what you will do, in the same response as your first tool call. After that, write only when you find something the group should know or finish a part of the work, in a sentence or two, not at every step. End with the result. Simple answers need no updates.', - '- Offer choices with ask_user (a tap-to-answer card) instead of long option lists in text. Calling it ends your turn at once, so write everything you want to say before the call, in the same reply. The answer arrives as the user\'s next message. The card stays open only until your next finished turn the user can see: a turn in your own chat that asks nothing closes it and a later click on it is refused, so ask again if you still need the answer. A turn that answers another Bot leaves it open.', + '- Offer choices with ask_user (a tap-to-answer card) instead of long option lists in text. Calling it ends your turn at once, so write everything you want to say before the call, in the same reply. The answer arrives as the user\'s next message. The card stays open while you keep working, including turns that answer other Bots, until the user answers it, dismisses it or writes a message; a new ask_user replaces it, so never ask the same question again while it is open.', '- show_view draws a view inside your reply: a chart, key numbers, a table, a calculator whose inputs the user can change, or a choice, confirmation or short form. Use it when it shows something better than text, not for every answer. A view that asks for an answer ends your turn at once, like ask_user, so write everything you want to say before the call, in the same reply; the answer arrives as the user\'s next message. It only works in your own chat, not in a group. Never collect a key, token, or password with it; call request_secret. The view argument is limited to 8 KB.', '- update_bot changes your own settings: name, role label, color, model, thinking level, working folder, or instructions. Leave out bot to change yourself. Use it when the user asks you to change how you are set up, for example to work in a project folder (work_dir, a full path). Only a Main Bot can change other Bots; when another Bot needs changing, ask a Main Bot.', '- You may be in group chats with the user and other Bots. You speak in each group from a separate conversation of yours, apart from your own chat with the user. There your turn arrives as a "[Group chat …]" message that shows the speaking order, and your reply is posted to the group. When someone there asks you to do something, do the work in that turn: the group goes on without waiting and sees what you write as you go. Any member can hand work to another with @Name, and the one that asked answers the result. Work for a group stays in it: there message_bot reaches only members of that group, as @Name does. In a group, read_own_chat shows your own chat (the group sees that you looked; share only what the group needs). In your own chat, read_group_chat shows what was said in a group. A group may have an admin, who steers it: the admin can call members with @Name and change the group with update_group. From outside a group (your own chat or another group), post_to_group posts into a group you are in: the admin\'s post starts a new discussion there; another member\'s post calls only the members it names with @Name.', diff --git a/ds-bot/src/host/turns.js b/ds-bot/src/host/turns.js index dfd478b38a..d62d8e3af7 100644 --- a/ds-bot/src/host/turns.js +++ b/ds-bot/src/host/turns.js @@ -811,7 +811,6 @@ export function install(rt) { entry.carried = false let claimedPending let claimedPendingText - entry.card = state.questions[id]?.id if (entry.pending !== undefined) { claimedPending = entry.pending claimedPendingText = entry.pendingText @@ -1059,7 +1058,6 @@ export function install(rt) { entry.carry = { info: entry.info, joined: entry.joined ?? [], later: entry.later ?? [], texts: entry.texts.slice(0, cut.texts), shown: entry.shown, answers: entry.answers, toolCount: entry.toolCount ?? 0, origin: entry.origin, originFrom: entry.originFrom, askText: entry.askText, originAt: entry.originAt } } const info = entry.info - const turn = entry.turn const joined = entry.joined ?? [] // What the group already saw of the turn is not posted again. const texts = entry.texts.slice(entry.shown) @@ -1100,8 +1098,6 @@ export function install(rt) { const later = entry.later ?? [] entry.later = [] if (steerCut || suppressedSubagent) break - const card = entry.card - entry.card = undefined for (const result of later) { void rt.deliver({ fromId: result.info.senderSessionId, @@ -1166,16 +1162,6 @@ export function install(rt) { void retryWrittenCall(id, info).catch(error => rt.warn('ds-bot: asking %s to run its written tool call failed: %s', id, error)) } } - // A finished turn the user could see that asked nothing has moved on, so the card - // it left standing is stale. `card` is the card this turn opened on: a turn that - // asked has another id, or none here at all. A hidden Bot-to-Bot turn shows the user - // nothing, so its card still waits for them. A fresh part's handoff turn carries its - // card over; a failed or stopped turn said nothing about it. - const hidden = (state.exchangeTurns[id] ?? []).includes(turn) - if (card !== undefined && state.questions[id]?.id === card && reason?.kind === 'completed' && !retry && !hidden && info?.handoff !== true) { - delete state.questions[id] - void rt.save().catch(() => {}) - } const replyText = () => { const reply = (wroteCall ? texts.map(stripWrittenCalls) : texts).join('\n\n').trim() if (wroteCall && reply === '') return 'Tried to run a tool but wrote the call as text, so it did not run.' diff --git a/ds-bot/test/questions.test.js b/ds-bot/test/questions.test.js index 51088db1f3..176e5d6add 100644 --- a/ds-bot/test/questions.test.js +++ b/ds-bot/test/questions.test.js @@ -91,9 +91,9 @@ test('a card asked in a visible turn stays at its call', async (t) => { assert.equal((await questions()).writer.callId, 'call-3') }) -// local: question-lifecycle. A card closes once the Bot finishes a later turn the user -// could see that asked nothing; a hidden Bot-to-Bot turn in between leaves it open. -test('a later visible turn that asks nothing closes the card; a hidden one leaves it', async (t) => { +// local: question-lifecycle. A card waits for the user: later turns of the Bot, hidden +// Bot-to-Bot ones and ones the user can see, leave it open; the user's own message closes it. +test('a card survives later Bot turns, hidden or visible, until the user writes', async (t) => { const { emit, ask, questions, stop } = await start() t.after(stop) emit('writer', 'turn/start', { turn: 1 }) @@ -105,11 +105,19 @@ test('a later visible turn that asks nothing closes the card; a hidden one leave emit('writer', 'turn/start', { turn: 2 }) emit('writer', 'user/message', { content: text('[Message from Chief]\nstatus? CARD-IT-YOURSELF'), source: { kind: 'bot', role: 'request', senderSessionId: 'chief', senderName: 'Chief', exchangeId: 'x9', hop: 0 } }) emit('writer', 'turn/end', { turn: 2, reason: { kind: 'completed' } }) - assert.equal((await questions()).writer?.question, 'Which name?') + assert.equal((await questions()).writer?.question, 'Which name?', 'a hidden Bot-to-Bot turn leaves it open') emit('writer', 'turn/start', { turn: 3 }) - emit('writer', 'user/message', { content: text('never mind, call it Scout'), source: { kind: 'user' } }) + emit('writer', 'user/message', { content: text('[Message from Chief · the user sees your reply here]\nReport in'), source: { kind: 'bot', role: 'request', audience: 'user', senderSessionId: 'chief', senderName: 'Chief', exchangeId: 'x10', hop: 0 } }) emit('writer', 'turn/end', { turn: 3, reason: { kind: 'completed' } }) + emit('writer', 'turn/start', { turn: 4 }) + emit('writer', 'turn/end', { turn: 4, reason: { kind: 'completed' } }) + await new Promise(resolve => setTimeout(resolve, 50)) + assert.equal((await questions()).writer?.question, 'Which name?', 'turns the user can see that ask nothing leave it open') + + emit('writer', 'turn/start', { turn: 5 }) + emit('writer', 'user/message', { content: text('never mind, call it Scout'), source: { kind: 'user' } }) + emit('writer', 'turn/end', { turn: 5, reason: { kind: 'completed' } }) for (let count = 0; count < 50 && (await questions()).writer !== undefined; count += 1) await new Promise(resolve => setTimeout(resolve, 5)) assert.equal((await questions()).writer, undefined) })