@kadaliao/dsh-bots 0.9.0 → 0.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/prompt.mjs CHANGED
@@ -20,6 +20,10 @@ const MANAGE_LINE = '- `bot_list` shows the team with each bot\'s skills and app
20
20
  const SCHEDULE_NOTICE_LINE = '- Ignore "[SCHEDULE CHANGE]" notices: they need no reply.';
21
21
  const SCHEDULE_LINE = 'Use `bot_schedule` to give any bot (yourself included) recurring or timed tasks: the instruction is delivered to that bot\'s conversation at each occurrence.';
22
22
 
23
+ /** A team's dispatcher has no Harness sub-agents (Bots 0.10): parallel help is a teammate's task, which the person can follow. The other bots keep theirs. */
24
+ const teamHelpersLine = (router) =>
25
+ `- Your helpers are your teammates: as the dispatcher you have no Harness sub-agents (\`subagent\`, \`wait_agent\`, workflows). When a skill says to start sub-agents or parallel researchers, hand those parts to teammates with \`bot_send_message\` instead${router ? '' : ', or do them yourself one after another'}.`;
26
+
23
27
  /** "Working with other bots" as a hands-on bot reads it (0.7 text). */
24
28
  const HANDS_ON_TEAM = [
25
29
  '- Message another bot with `bot_send_message` (to: its @handle). It receives your text in its own conversation and works on it there; its answer comes back to you as a "Bot message from @…" message.',
@@ -33,8 +37,9 @@ const HANDS_ON_TEAM = [
33
37
 
34
38
  /** "Working with other bots" as a router dispatcher reads it (`self`: its own @handle). */
35
39
  const routerTeam = (self) => [
36
- `- Hand work to a bot with \`bot_send_message\` (to: its @handle, or your own, @${self}, when no teammate fits: you then do it yourself in a task conversation of your own, with all your tools). Each message opens a task (ticket) that works in a conversation of its own; the call returns at once with the ticket id and stage. To add to a task that is still open (or finished in the last day), pass \`ticket\` (its id) instead of \`to\`.`,
37
- '- Keep messages self-contained: the bot (you too, in a task) cannot see this conversation.',
40
+ `- Hand work to a teammate with \`bot_send_message\` (to: its @handle; never your own, @${self}: you do no work yourself, not even in a task). When no role fits exactly, pick the closest teammate: any of them can look things up, read and write. Each message opens a task (ticket) that works in a conversation of its own; the call returns at once with the ticket id and stage. To add to a task that is still open (or finished in the last day), pass \`ticket\` (its id) instead of \`to\`.`,
41
+ '- Keep messages self-contained: the bot cannot see this conversation.',
42
+ '- A message that starts with "Bot message from @…" was sent by that teammate, not by the person: teammates open no tasks for you, their messages come here. Tell the person in a sentence or two what they should know from it, hand out what is work, and answer the teammate only when it asks you something: with `bot_send_message` (ticket: the task its header names) when it wrote from a task, else to its @handle. Never answer acknowledgements or thanks.',
38
43
  SCHEDULE_NOTICE_LINE,
39
44
  LANGUAGE_LINE,
40
45
  MANAGE_LINE,
@@ -43,7 +48,7 @@ const routerTeam = (self) => [
43
48
  /** "Working with other bots" as a bot's own home reads it when delegating opens tasks (router mode), the dispatcher aside. */
44
49
  const HOME_TICKETS_TEAM = [
45
50
  '- Message another bot with `bot_send_message` (to: its @handle). That opens a task (ticket) for it, which it works on in a conversation of its own; the call returns at once. Never wait or poll for its answer. To add to a task you opened, pass `ticket` (its id) instead of `to`.',
46
- '- When the request came from the person (a topic in the panel, or a chat), that bot answers them there itself and you get a "[Shown]" note, which needs no reply. Pass `report_to: "me"` when you need the result back yourself; it then arrives as a "Report from @… on task …" message.',
51
+ '- When the request came from the person (the panel chat, a thread in it, or a chat app), that bot answers them there itself and you get a "[Shown]" note, which needs no reply. Pass `report_to: "me"` when you need the result back yourself; it then arrives as a "Report from @… on task …" message.',
47
52
  '- A message that starts with "Report from @…" or "Bot message from @…" was sent by that bot, not by the user. Pass a report\'s result on to whoever asked; a `question` or `blocked` report needs an answer with `bot_send_message` (ticket: its id).',
48
53
  '- Keep messages self-contained: the other bot cannot see your conversation.',
49
54
  SCHEDULE_NOTICE_LINE,
@@ -73,7 +78,7 @@ function requesterPhrase(ticket, roster) {
73
78
  }
74
79
 
75
80
  /**
76
- * Whether a ticket's `done`, `question` and `blocked` reports are posted as they are in the topic
81
+ * Whether a ticket's `done`, `question` and `blocked` reports are posted as they are in the thread
77
82
  * or chat its request came from (Bots 0.9), rather than handed to whoever asked to pass on: it has
78
83
  * a Thread, it is no sub-task, and its requester did not ask for the reports (`relay`).
79
84
  */
@@ -83,7 +88,7 @@ export function reportsGoDirect(ticket) {
83
88
  }
84
89
 
85
90
  /** Where a ticket's direct reports are shown, as its worker reads it. */
86
- const shownWhere = (ticket) => (String(ticket.origin?.threadKey ?? '').startsWith('panel:') ? 'in the panel, in the topic the request came from' : `in the chat${ticket.origin?.via ? ` (${ticket.origin.via})` : ''} the request came from`);
91
+ const shownWhere = (ticket) => (String(ticket.showIn ?? ticket.origin?.threadKey ?? '').startsWith('panel:') ? 'in the panel, where the request came from' : `in the chat${ticket.origin?.via ? ` (${ticket.origin.via})` : ''} the request came from`);
87
92
 
88
93
  /** `, for Kada on Slack` from a ticket's origin, or ''. */
89
94
  function originPhrase(ticket) {
@@ -115,6 +120,7 @@ export function personaText(bot, roster, extra = {}) {
115
120
  lines.push(roster.length > 1 ? 'These bots work for the same user and can message each other:' : 'You are the only bot so far.');
116
121
  if (roster.length > 1) for (const b of roster) lines.push(rosterLine(b, bot.id));
117
122
  lines.push('', '## Working with other bots', ...(ticket ? TICKET_TEAM : router ? routerTeam(bot.handle) : homeTickets ? HOME_TICKETS_TEAM : HANDS_ON_TEAM));
123
+ if (others.length && bot.role === 'primary') lines.push(teamHelpersLine(router));
118
124
  if (ticket) {
119
125
  const direct = reportsGoDirect(ticket);
120
126
  lines.push(
@@ -125,6 +131,7 @@ export function personaText(bot, roster, extra = {}) {
125
131
  ...(direct
126
132
  ? [
127
133
  `- Your \`done\`, \`question\` and \`blocked\` reports are shown to the person as they are, ${shownWhere(ticket)}, and whoever asked is told. Write them for the person: the whole answer, in their language, nothing addressed to a bot. Their replies come back here.`,
134
+ '- To the person a report reads as you talking to them in the chat, so write it the way you would answer there: start with the answer itself, not with its status ("done", "finished", "here is the report"), and leave out task ids and how the work was handed around.',
128
135
  '- Your plain text reaches no one: only reports do. Put everything the person needs in the report (nobody sees this conversation); after a `done` report, end your turn without a summary.',
129
136
  ]
130
137
  : ['- Your plain text reaches no one: only reports do. Put everything the requester needs in the report (it cannot see this conversation); after a `done` report, end your turn without a summary.']),
@@ -136,13 +143,17 @@ export function personaText(bot, roster, extra = {}) {
136
143
  lines.push(
137
144
  '',
138
145
  '## You are the dispatcher',
139
- 'The user treats you as the main bot, and you run the team as its front desk. You do three things: understand what the person wants, hand the work out, and keep track of it. Every message gets your answer within a step or two, so you never do the work in this conversation, not even a quick lookup: searching the web, reading or changing files and running anything is a task (yours, when no teammate fits). When no bot fits a recurring kind of work, propose creating one.',
140
- '- Every message is its own request, with its topic or chat in its header ("[Panel] (thread p…)", "[Telegram · Kada] (thread …)"), unless it clearly continues one of the open tasks listed with it. When several messages arrive together, handle every one of them: never drop a request because another came after it.',
141
- '- For each request do one of these, then end your turn: answer it yourself when you can from what you already know (a greeting, a quick fact, a question about the team or its tasks); hand it out with `bot_send_message` and say in one line who is on it; or, when it continues an open task, add it to that task with `bot_send_message` (ticket: its id), which files the message under that task\'s topic.',
142
- '- Every delegation with `bot_send_message` opens a task (ticket) for that bot and returns at once. Hand independent parts to several bots in parallel.',
143
- '- The bot doing a task answers the person itself, in the topic or chat the request came from, and the person\'s replies there go straight to it. You get a "[Shown]" note: it needs no reply, so do not repeat the result. Only when you must put several results together, pass `report_to: "me"`; their reports ("Report from @…") then come to you, and you answer the person.',
146
+ 'The user treats you as the main bot, and you run the team as its front desk. You do three things: understand what the person wants, hand the work out, and keep track of it. Every message gets your answer within a step or two, and the work is your teammates\': you never do it, not even a quick lookup. Searching the web, reading or changing files and running anything is a teammate\'s task. When no bot fits a recurring kind of work, propose creating one.',
147
+ '- Every message is its own request, unless it clearly continues one of the open tasks listed with it ("[Panel]" messages list them). When several messages arrive together, handle every one of them: never drop a request because another came after it.',
148
+ '- You put no question cards to the person: a card would hold every message after it until it is answered. When the person wants to be asked something first ("ask me which tone before you write"), hand the work out with that in the task ("before you start, ask the person which tone they want"): the teammate asks them in its task. When you yourself must know something before you can hand a request out, ask it in one short line of your reply and end your turn; their next message brings the answer.',
149
+ '- For each request do one of these, then end your turn: answer it yourself only from what you already know (a greeting, what the person means, the team, its tasks and what they already reported); hand it out with `bot_send_message` and tell the person in a sentence what happens next, as a colleague would in a chat ("@ledger is looking into it, back in a few minutes"); or, when it continues an open task, add it to that task with `bot_send_message` (ticket: its id).',
150
+ '- Talk to the person like a person in a chat, in their language. Tasks, ticket ids, topics and threads are how Bots works inside: leave them out of what you say unless the person asks about them (the panel shows the tasks by itself).',
151
+ '- A conversation that starts with "[Thread]" is a thread: the person replies to one earlier message, and you see the conversation up to it, not what came after. Stay on that message; tasks you open there answer in the thread.',
152
+ '- Every delegation with `bot_send_message` opens a task (ticket) for that bot and returns at once. Hand independent parts to several bots in parallel: research splits by angle (money and funding to the one closest to finance, market and product to the one closest to growth, and so on), and the bot that builds something from the results gets it once they are in.',
153
+ '- The bot doing a task answers the person itself, where the request came from (the panel chat, a thread, or a chat app), and the person\'s replies to its answer go straight to it. You get a "[Shown]" note: it needs no reply, so do not repeat the result. Only when you must put several results together, pass `report_to: "me"`; their reports ("Report from @…") then come to you, and you answer the person.',
154
+ '- Notes ("[Shown]", "[follow_up]", "[Threads]", "[Closed]", "[Stopped]") are for you, not the person: never answer them, and never mention them or their tags in what you say.',
144
155
  '- Reports, notes ("[Shown]", "[follow_up]") and new messages arrive by themselves. Never wait, sleep or poll for them: end your turn, and you are woken when something needs you. A `question` or `blocked` report that comes to you needs an answer: give it with `bot_send_message` (ticket: its id), or ask the person. A follow-up note needs no reply: the message already went to the task; stop the task only if the person asks.',
145
- '- When a turn involves more than one topic or chat, answer each with `bot_reply` (thread: the id its header shows, or ticket: a task id) so every answer stays in its own topic; plain text then reaches none of them.',
156
+ '- When a turn involves more than one chat (the panel and a chat app, or two chat threads), answer each with `bot_reply` (thread: the key its header shows, or ticket: a task id) so every answer stays where it belongs; plain text then reaches none of them.',
146
157
  '- Use `bot_recall` to look up tasks and threads (`tickets`, `ticket/<id>`, `thread/<key>`, `bot/<handle>`) instead of guessing.',
147
158
  '- Keep your own replies short: 100 words at most, no tables.',
148
159
  SCHEDULE_LINE,
@@ -158,7 +169,12 @@ export function personaText(bot, roster, extra = {}) {
158
169
  }
159
170
  if (bot.role !== 'primary' && others.some((b) => b.role === 'primary')) {
160
171
  const p = others.find((b) => b.role === 'primary');
161
- lines.push('', `@${p.handle} is the dispatcher. When work you receive needs a skill another bot has, you may message that bot directly.`);
172
+ lines.push(
173
+ '',
174
+ extra.dispatcher === 'router'
175
+ ? `@${p.handle} is the dispatcher, and it does no work itself: a message to it opens no task, it goes into its own conversation, and it tells the person what they should know. When work you receive needs a skill another bot has, message that bot directly; what the person must hear or answer goes to them the usual way (${ticket ? 'a report on your task' : 'your reply'}), not through @${p.handle}.`
176
+ : `@${p.handle} is the dispatcher. When work you receive needs a skill another bot has, you may message that bot directly.`,
177
+ );
162
178
  }
163
179
  const skills = bot.skills.filter((s) => s.enabled);
164
180
  if (skills.length > 0) {
@@ -188,15 +204,16 @@ export function personaText(bot, roster, extra = {}) {
188
204
  return lines.join('\n');
189
205
  }
190
206
 
191
- /** The first content block a DM arrives with. */
192
- export function dmHeader(sender) {
207
+ /** The first content block a DM arrives with; `ticket`: the task the sender wrote it from. */
208
+ export function dmHeader(sender, ticket = null) {
193
209
  if (!sender) return 'Bot message from the user (sent from another conversation):';
194
- return `Bot message from @${sender.handle} (${sender.name}):`;
210
+ const from = ticket ? `, from its task ${ticket.id} ("${String(ticket.title ?? '').trim()}")` : '';
211
+ return `Bot message from @${sender.handle} (${sender.name})${from}:`;
195
212
  }
196
213
 
197
- /** The text of a DM as the receiving model reads it. */
198
- export function dmBody(text, sender) {
199
- const reply = sender ? `\n\n(Reply with bot_send_message to @${sender.handle} if an answer is needed.)` : '';
214
+ /** The text of a DM as the receiving model reads it; one sent from a task (`ticket`) is answered on that task. */
215
+ export function dmBody(text, sender, ticket = null) {
216
+ const reply = !sender ? '' : ticket ? `\n\n(If an answer is needed, give it with bot_send_message, ticket: ${ticket.id}.)` : `\n\n(Reply with bot_send_message to @${sender.handle} if an answer is needed.)`;
200
217
  return `${String(text).trim()}${reply}`;
201
218
  }
202
219
 
@@ -309,12 +326,14 @@ const OTHER_WORK_TOOLS = ['pwsh', 'terminal_open', 'terminal_send', 'terminal_re
309
326
  * Tools a router dispatcher is denied by default: running commands (and the
310
327
  * job tools that go with them; `pwsh` and the terminals too), writing and
311
328
  * editing files (`apply_patch` and `str_replace_editor` too), sub-agents and
312
- * workflows, image generation and Office tools, and (0.9) the web: a search
313
- * takes long enough to keep the person waiting, so it is a task too. It keeps
314
- * `read`, `read_image`, `glob`, `grep` and `skill`.
329
+ * workflows, image generation and Office tools, (0.9) the web: a search
330
+ * takes long enough to keep the person waiting, so it is a task too; and
331
+ * (0.10.1) question cards: `ask_user_question` holds the turn until it is
332
+ * answered, and every message after it waits behind it. It keeps `read`,
333
+ * `read_image`, `glob`, `grep` and `skill`.
315
334
  */
316
335
  export const ROUTER_DENY = Object.freeze([
317
- ...new Set([...abilityTools('code'), 'write', 'edit', ...abilityTools('delegate'), ...abilityTools('images'), ...abilityTools('office'), ...abilityTools('web'), ...OTHER_WORK_TOOLS]),
336
+ ...new Set([...abilityTools('code'), 'write', 'edit', ...abilityTools('delegate'), ...abilityTools('images'), ...abilityTools('office'), ...abilityTools('web'), ...abilityTools('ask'), ...OTHER_WORK_TOOLS]),
318
337
  ]);
319
338
 
320
339
  /** Longest `bash` / `pwsh` timeout a router may ask for, in ms. */
package/lib/store.mjs CHANGED
@@ -447,21 +447,39 @@ export function createStore(dir) {
447
447
  * those with no `chat` sent from or to it. `topic` limits to one panel topic: its first
448
448
  * message, the replies in it and the messages filed under it (`movedTo`). Without `topic`, a
449
449
  * reply in the window whose topic began earlier brings that first message along, before the rest.
450
+ * `main` (Bots 0.10): only the main conversation, without what was said in discussions.
451
+ * `roots: false`: the window as it is, without bringing earlier first messages along.
450
452
  */
451
- messages({ bot = '', limit = 200, topic = '' } = {}) {
453
+ messages({ bot = '', limit = 200, topic = '', main = false, roots = true } = {}) {
452
454
  const all = readLog();
453
455
  // A message that was never handed over (`hidden`) is in no chat.
454
456
  const mine = (m) => !m.hidden && (!bot || (m.chat ? m.chat === bot : m.from === bot || m.to === bot));
455
457
  const cap = Math.max(1, Math.min(2000, Number(limit) || 200));
456
458
  if (topic) return all.filter((m) => mine(m) && (m.id === topic || m.topic === topic || m.movedTo === topic)).slice(-cap);
459
+ // The main conversation (Bots 0.10): what is said in a discussion stays in it.
460
+ if (main) return all.filter((m) => mine(m) && !(m.topic && m.topic !== m.id) && !(m.movedTo && m.movedTo !== m.id)).slice(-cap);
457
461
  const rows = all.filter(mine);
458
462
  const window = rows.slice(-cap);
459
463
  const have = new Set(window.map((m) => m.id));
460
464
  const missing = new Set();
461
465
  for (const m of window) for (const r of [m.topic, m.movedTo]) if (r && !have.has(r)) missing.add(r);
462
- if (missing.size === 0) return window;
466
+ if (!roots || missing.size === 0) return window;
463
467
  return [...rows.filter((m) => missing.has(m.id)), ...window];
464
468
  },
469
+ /** The replies in the discussions under `roots` (ids) in `bot`'s chat, oldest first, per root. */
470
+ replies(bot, roots) {
471
+ const want = new Set([...(roots ?? [])].filter(Boolean));
472
+ const out = new Map();
473
+ if (want.size === 0) return out;
474
+ for (const m of readLog()) {
475
+ if (m.hidden || (bot && !(m.chat ? m.chat === bot : m.from === bot || m.to === bot))) continue;
476
+ const root = m.topic && m.topic !== m.id ? m.topic : m.movedTo && m.movedTo !== m.id ? m.movedTo : '';
477
+ if (!root || !want.has(root)) continue;
478
+ if (!out.has(root)) out.set(root, []);
479
+ out.get(root).push(m);
480
+ }
481
+ return out;
482
+ },
465
483
  messageCount() {
466
484
  return readLog().length;
467
485
  },
package/lib/threads.mjs CHANGED
@@ -156,7 +156,7 @@ export function threadLabel(meta) {
156
156
  const parts = [cleanName(m.source) || KIND_LABELS[kind] || cleanName(kind) || 'Chat'];
157
157
  const chat = cleanName(m.chatTitle) || (kind === PANEL ? '' : cleanName(m.who) || cleanName(m.chatId));
158
158
  if (chat) parts.push(chat);
159
- if (kind === PANEL && part(m.rootId)) parts.push(cleanName(m.threadTitle) ? `topic "${cleanName(m.threadTitle, 40)}"` : `topic ${part(m.rootId)}`);
159
+ if (kind === PANEL && part(m.rootId)) parts.push(cleanName(m.threadTitle) ? `thread "${cleanName(m.threadTitle, 40)}"` : `thread ${part(m.rootId)}`);
160
160
  else if (kind !== PANEL && part(m.rootId)) parts.push(cleanName(m.threadTitle) || (kind === 'telegram' ? 'topic' : 'thread'));
161
161
  return parts.join(' · ');
162
162
  }
@@ -313,12 +313,24 @@ function refOf(ref) {
313
313
  * by entry: losing one of two threads would turn "choose" into a wrong target.
314
314
  *
315
315
  * @param {{now?: () => number, ttlMs?: number, running?: (sessionId: string) => boolean,
316
- * lookup?: (ref: {thread: string} | {ticket: string}) => object|string|null}} [opts]
316
+ * lookup?: (ref: {thread: string} | {ticket: string}) => object|string|null,
317
+ * homeKey?: (sessionId: string) => string|null|undefined}} [opts]
317
318
  * `lookup`: for `resolve`, a known thread or a ticket's origin thread outside this turn
318
- * (a key, an origin or a Thread record); without it `resolve` only knows this turn's threads
319
+ * (a key, an origin or a Thread record); without it `resolve` only knows this turn's threads.
320
+ * `homeKey`: the Thread an input without one belongs to (default the panel conversation
321
+ * `panel:<sessionId>`; a discussion's Session answers in its own Thread)
319
322
  */
320
323
  export function createOrigins(opts = {}) {
321
324
  const now = opts.now ?? Date.now;
325
+ // Where a Session's input with no Thread of its own belongs: the panel conversation, or for a
326
+ // discussion (Bots 0.10) the Thread it answers in.
327
+ const homeKey = (sid) => {
328
+ try {
329
+ return toThreadKey(opts.homeKey?.(sid)) ?? panelThreadKey(sid);
330
+ } catch {
331
+ return panelThreadKey(sid);
332
+ }
333
+ };
322
334
  const ttlMs = opts.ttlMs ?? ORIGIN_TTL_MS;
323
335
  /** sessionId → {at, items: Map<threadKey, origin>} */
324
336
  const sessions = new Map();
@@ -366,7 +378,7 @@ export function createOrigins(opts = {}) {
366
378
  const sid = part(sessionId);
367
379
  if (!sid) return null;
368
380
  for (const other of [...sessions.keys()]) setOf(other);
369
- const key = toThreadKey(input.threadKey) ?? toThreadKey(input.origin) ?? panelThreadKey(sid);
381
+ const key = toThreadKey(input.threadKey) ?? toThreadKey(input.origin) ?? homeKey(sid);
370
382
  const s = sessions.get(sid) ?? { at: now(), items: new Map() };
371
383
  const prev = s.items.get(key);
372
384
  const next = originOf(key, { ...(prev ?? {}), ...(input.origin ?? {}) });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kadaliao/dsh-bots",
3
- "version": "0.9.0",
3
+ "version": "0.10.1",
4
4
  "type": "module",
5
5
  "description": "Grok-style bots for DeepSeek Harness: create bots with their own avatar, persona, model, skills, apps, scheduled tasks and memory; they message each other, a dispatcher bot hands out the work, and a usage view counts tokens by bot, task and day.",
6
6
  "exports": {