@kadaliao/dsh-bots 0.7.0 → 0.8.0

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/memory.mjs CHANGED
@@ -251,6 +251,43 @@ export function reflectionPrompt({ bot, notes, team, transcript, trigger }) {
251
251
  };
252
252
  }
253
253
 
254
+ /**
255
+ * Tickets (tasks) whose title or one of whose reports contains every word of
256
+ * `query` (case-insensitive, as `search` matches notes), most recently changed
257
+ * first. A title hit wins over a report hit; a report hit carries the newest
258
+ * matching report's status and a short snippet around the first word.
259
+ * @param {string} query
260
+ * @param {object[]} tickets - tickets in the shape of docs/PLAN-0.8.md §10
261
+ * @param {{limit?: number}} [opts]
262
+ * @returns {Array<{ticket: object, where: 'title'|'report', status?: string, snippet?: string}>}
263
+ */
264
+ export function searchTickets(query, tickets, { limit = 10 } = {}) {
265
+ const words = String(query ?? '').toLowerCase().split(/\s+/).filter(Boolean);
266
+ if (words.length === 0) return [];
267
+ const hit = (text) => {
268
+ const s = String(text ?? '').toLowerCase();
269
+ return words.every((w) => s.includes(w));
270
+ };
271
+ const snippet = (text) => {
272
+ const s = String(text ?? '').replace(/\s+/g, ' ').trim();
273
+ const at = Math.max(0, s.toLowerCase().indexOf(words[0]) - 60);
274
+ const cut = s.slice(at, at + 200);
275
+ return `${at > 0 ? '…' : ''}${cut}${at + 200 < s.length ? '…' : ''}`;
276
+ };
277
+ const out = [];
278
+ for (const t of [...(tickets ?? [])].sort((a, b) => (Number(b?.updatedAt) || 0) - (Number(a?.updatedAt) || 0))) {
279
+ if (!t?.id) continue;
280
+ if (hit(t.title)) {
281
+ out.push({ ticket: t, where: 'title' });
282
+ } else {
283
+ const report = [...(Array.isArray(t.reports) ? t.reports : [])].reverse().find((r) => hit(r?.text));
284
+ if (report) out.push({ ticket: t, where: 'report', status: report.status, snippet: snippet(report.text) });
285
+ }
286
+ if (out.length >= limit) break;
287
+ }
288
+ return out;
289
+ }
290
+
254
291
  /** Once a day per bot: tidy the notes with the last days of its journal. */
255
292
  export function dreamBotPrompt({ bot, notes, journal, tz = 0 }) {
256
293
  return {
package/lib/prompt.mjs CHANGED
@@ -1,24 +1,98 @@
1
1
  /**
2
- * What a bot's model reads: its persona section, the DM framing, and the
3
- * timing builder its schedule tool uses. Pure functions, no Harness.
2
+ * What a bot's model reads: its persona section (hands-on dispatcher, router
3
+ * dispatcher, or worker in a ticket session), the DM framing, the timing
4
+ * builder its schedule tool uses, and the router's tool limits. Pure
5
+ * functions, no Harness.
4
6
  *
5
7
  * @module @kadaliao/dsh-bots/lib/prompt
6
8
  */
7
9
 
10
+ import { ABILITIES } from './abilities.mjs';
11
+
8
12
  /** One roster line: `@handle — Name (dispatcher): bio`. */
9
13
  export function rosterLine(bot, selfId) {
10
14
  const tags = [bot.role === 'primary' ? 'dispatcher' : '', bot.id === selfId ? 'you' : ''].filter(Boolean);
11
15
  return `- @${bot.handle} — ${bot.name}${tags.length ? ` (${tags.join(', ')})` : ''}${bot.bio ? `: ${bot.bio}` : ''}`;
12
16
  }
13
17
 
18
+ const LANGUAGE_LINE = '- Write to the user in the language they use (Chinese or English). Between bots, use the language of the task you were given.';
19
+ const MANAGE_LINE = '- `bot_list` shows the team with each bot\'s skills and apps; `bot_create`, `bot_update` and `bot_delete` manage bots when the user asks for it or a new specialist is clearly needed.';
20
+ const SCHEDULE_NOTICE_LINE = '- Ignore "[SCHEDULE CHANGE]" notices: they need no reply.';
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
+
23
+ /** "Working with other bots" as a hands-on bot reads it (0.7 text). */
24
+ const HANDS_ON_TEAM = [
25
+ '- 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.',
26
+ '- A message that starts with "Bot message from @…" was sent by that bot, not by the user. Answer it with `bot_send_message` when it asks for something; do not answer pure acknowledgements or thanks, so conversations end.',
27
+ '- Keep messages self-contained: the other bot cannot see your conversation.',
28
+ '- When you are working on a bot message, your answer goes back through `bot_send_message`; after sending it, end your turn without a summary — nobody reads it.',
29
+ SCHEDULE_NOTICE_LINE,
30
+ LANGUAGE_LINE,
31
+ MANAGE_LINE,
32
+ ];
33
+
34
+ /** "Working with other bots" as a router dispatcher reads it. */
35
+ const ROUTER_TEAM = [
36
+ '- Hand work to another bot with `bot_send_message` (to: its @handle). Each message opens a task (ticket) for that bot, which works on it 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, pass `ticket` (its id) instead of `to`.',
37
+ '- Keep messages self-contained: the other bot cannot see your conversation.',
38
+ SCHEDULE_NOTICE_LINE,
39
+ LANGUAGE_LINE,
40
+ MANAGE_LINE,
41
+ ];
42
+
43
+ /** "Working with other bots" as a bot's own home reads it when delegating opens tasks (router mode), the dispatcher aside. */
44
+ const HOME_TICKETS_TEAM = [
45
+ '- 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, and its answer comes back to you as a "Report from @… on task …" message. Never wait or poll for it. To add to a task you opened, pass `ticket` (its id) instead of `to`.',
46
+ '- 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).',
47
+ '- Keep messages self-contained: the other bot cannot see your conversation.',
48
+ SCHEDULE_NOTICE_LINE,
49
+ LANGUAGE_LINE,
50
+ MANAGE_LINE,
51
+ ];
52
+
53
+ /** "Working with other bots" as a worker in a ticket session reads it. */
54
+ const TICKET_TEAM = [
55
+ '- Ask another bot for help with `bot_send_message` (to: its @handle). That opens a sub-task for it, and its report comes back to this conversation by itself; do not wait or poll for it.',
56
+ '- Keep messages self-contained: the other bot cannot see your conversation.',
57
+ '- A message that starts with "Bot message from @…" or "Report from @…" was sent by that bot, not by the user.',
58
+ SCHEDULE_NOTICE_LINE,
59
+ LANGUAGE_LINE,
60
+ MANAGE_LINE,
61
+ ];
62
+
63
+ /** Who asked for a ticket, as a worker reads it: `@atlas`, `task t… (@coder)`, `the user`. */
64
+ function requesterPhrase(ticket, roster) {
65
+ const r = ticket.requester ?? {};
66
+ const bot = r.botId ? roster.find((b) => b.id === r.botId) : undefined;
67
+ const handle = bot ? `@${bot.handle}` : '';
68
+ const parent = ticket.parentId ?? r.ticketId;
69
+ if (parent) return `task ${parent}${handle ? ` (${handle})` : ''}`;
70
+ if (r.kind === 'user' || !handle) return 'the user';
71
+ return handle;
72
+ }
73
+
74
+ /** `, for Kada on Slack` from a ticket's origin, or ''. */
75
+ function originPhrase(ticket) {
76
+ const { who, via } = ticket.origin ?? {};
77
+ if (!who && !via) return '';
78
+ return `, for ${who || 'someone'}${via ? ` on ${via}` : ''}`;
79
+ }
80
+
14
81
  /**
15
82
  * The persona section of one bot. It replaces the deployment persona for that
16
83
  * bot's conversation only.
17
84
  * @param {object} bot
18
85
  * @param {object[]} roster - every bot, the bot itself included.
19
- * @param {{skillsInline?: boolean, apps?: string[], skillNames?: object, channels?: string[]}} [extra] - `channels`: chat apps the team is reachable from ('Telegram').
86
+ * @param {{skillsInline?: boolean, apps?: string[], skillNames?: object, channels?: string[], dispatcher?: 'router'|'hands-on', tickets?: boolean, ticket?: object}} [extra]
87
+ * `channels`: chat apps the team is reachable from ('Telegram').
88
+ * `dispatcher`: how the dispatcher (role 'primary') works in its home conversation; 'hands-on' (default) is the 0.7 text, 'router' only understands, hands out and reports. Ignored for other bots.
89
+ * `tickets`: delegating from a home opens a task whose answer arrives as a report (router mode); a non-dispatcher bot's home then says so. Without it (hands-on) the 0.7 text stands.
90
+ * `ticket`: the ticket (see PLAN-0.8 §10) when this conversation is that ticket's session; the text then frames the conversation as one task, whatever the bot's role.
20
91
  */
21
92
  export function personaText(bot, roster, extra = {}) {
93
+ const ticket = extra.ticket ?? null;
94
+ const router = !ticket && bot.role === 'primary' && extra.dispatcher === 'router';
95
+ const homeTickets = !ticket && !router && bot.role !== 'primary' && extra.tickets === true;
22
96
  const lines = [];
23
97
  lines.push(`You are ${bot.name} (@${bot.handle}), one of the user's bots in DeepSeek Harness.`);
24
98
  if (bot.persona.trim()) lines.push('', '## Your persona', bot.persona.trim());
@@ -26,26 +100,41 @@ export function personaText(bot, roster, extra = {}) {
26
100
  lines.push('', '## The bot team');
27
101
  lines.push(roster.length > 1 ? 'These bots work for the same user and can message each other:' : 'You are the only bot so far.');
28
102
  if (roster.length > 1) for (const b of roster) lines.push(rosterLine(b, bot.id));
29
- lines.push(
30
- '',
31
- '## Working with other bots',
32
- '- 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
- '- A message that starts with "Bot message from @…" was sent by that bot, not by the user. Answer it with `bot_send_message` when it asks for something; do not answer pure acknowledgements or thanks, so conversations end.',
34
- '- Keep messages self-contained: the other bot cannot see your conversation.',
35
- '- When you are working on a bot message, your answer goes back through `bot_send_message`; after sending it, end your turn without a summary — nobody reads it.',
36
- '- Ignore "[SCHEDULE CHANGE]" notices: they need no reply.',
37
- '- Write to the user in the language they use (Chinese or English). Between bots, use the language of the task you were given.',
38
- '- `bot_list` shows the team with each bot\'s skills and apps; `bot_create`, `bot_update` and `bot_delete` manage bots when the user asks for it or a new specialist is clearly needed.',
39
- );
40
- if (bot.role === 'primary') {
103
+ lines.push('', '## Working with other bots', ...(ticket ? TICKET_TEAM : router ? ROUTER_TEAM : homeTickets ? HOME_TICKETS_TEAM : HANDS_ON_TEAM));
104
+ if (ticket) {
105
+ lines.push(
106
+ '',
107
+ '## This conversation is one task',
108
+ `It is task ${ticket.id}: "${String(ticket.title ?? '').trim()}", asked by ${requesterPhrase(ticket, roster)}${originPhrase(ticket)}. Its first message says what to do.`,
109
+ '- Report to whoever asked with `bot_send_message`: leave out `to` and give a `status`, which is required — `progress` for an update worth keeping, `done` with the result when you are finished, `blocked` when you cannot go on, `question` when you need an answer.',
110
+ '- 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.',
111
+ '- Asking another bot opens a sub-task; its report comes back here by itself.',
112
+ '- Messages from the person about this task may arrive here directly. Take them into account and answer them in a report.',
113
+ `- \`bot_recall\` reads this task (\`ticket/${ticket.id}\`), its parent and sub-tasks, and the threads it belongs to.`,
114
+ );
115
+ } else if (router) {
116
+ lines.push(
117
+ '',
118
+ '## You are the dispatcher',
119
+ 'The user treats you as the main bot, and you run the team. You do three things: understand what the person wants, hand the work out, and report back. Do not do the work yourself, not even small tasks: your own tools are for reading and looking things up. When no bot fits a recurring kind of work, propose creating one.',
120
+ '- 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, tell the person in one line who is on it, and end your turn.',
121
+ '- Reports ("Report from @…"), follow-up notices ("[follow_up]") and new messages arrive by themselves. Never wait, sleep or poll for them: end your turn, and you are woken when something arrives.',
122
+ '- When a report arrives, pass the result on to whoever asked. A `question` or `blocked` report needs an answer: give it with `bot_send_message` (ticket: its id), or ask the person. A follow-up notice needs no reply: the message already went to the task; stop the task only if the person asks.',
123
+ '- When a turn involves more than one chat, answer each with `bot_reply` (ticket or thread, and text) so every answer reaches its own chat; plain text then stays in the panel.',
124
+ '- Use `bot_recall` to look up tasks and threads (`tickets`, `ticket/<id>`, `thread/<key>`, `bot/<handle>`) instead of guessing.',
125
+ '- Keep chat replies short: 100 words at most, no tables.',
126
+ SCHEDULE_LINE,
127
+ );
128
+ } else if (bot.role === 'primary') {
41
129
  lines.push(
42
130
  '',
43
131
  '## You are the dispatcher',
44
132
  'The user treats you as the main bot. For a task that fits another bot\'s role, delegate it with `bot_send_message`, possibly to several bots in parallel, then combine their answers for the user. Do small or general tasks yourself. When no bot fits a recurring kind of work, propose creating one.',
45
133
  'While teammates are still answering, stay quiet: when a reply arrives and others are still outstanding, end your turn without writing to the user. Report once, when everything you asked for is in (or when something is blocked).',
46
- '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.',
134
+ SCHEDULE_LINE,
47
135
  );
48
- } else if (others.some((b) => b.role === 'primary')) {
136
+ }
137
+ if (bot.role !== 'primary' && others.some((b) => b.role === 'primary')) {
49
138
  const p = others.find((b) => b.role === 'primary');
50
139
  lines.push('', `@${p.handle} is the dispatcher. When work you receive needs a skill another bot has, you may message that bot directly.`);
51
140
  }
@@ -63,10 +152,13 @@ export function personaText(bot, roster, extra = {}) {
63
152
  if (extra.apps?.length) lines.push('', '## Your apps', `Tools from these connected apps are yours: ${extra.apps.join(', ')} (named \`mcp__<app>__<tool>\`).`);
64
153
  if (extra.channels?.length) {
65
154
  const first = extra.channels[0];
155
+ const how = ticket
156
+ ? 'It is a follow-up about this task. Your plain text does not reach that chat: answer in a report, and the requester passes it on.'
157
+ : 'Treat it like any request from the user: your reply is sent back to that chat as plain text, so keep it short, skip tables, and say plainly what you did or who is on it.';
66
158
  lines.push(
67
159
  '',
68
160
  '## Chat apps',
69
- `The user can also reach the team from ${extra.channels.join(' and ')}. A message that starts with "[${first} · Name]" was sent from that chat app by someone the user paired (usually the user). Treat it like any request from the user: your reply is sent back to that chat as plain text, so keep it short, skip tables, and say plainly what you did or who is on it.`,
161
+ `The user can also reach the team from ${extra.channels.join(' and ')}. A message that starts with "[${first} · Name]" was sent from that chat app by someone the user paired (usually the user). ${how}`,
70
162
  );
71
163
  }
72
164
  return lines.join('\n');
@@ -176,7 +268,91 @@ export function textOf(content) {
176
268
  if (typeof content === 'string') return content;
177
269
  return (Array.isArray(content) ? content : [])
178
270
  .filter((b) => b && b.type === 'text' && typeof b.text === 'string')
179
- .map((b) => b.text)
180
- .join('\n')
271
+ .map((b, i, all) => (i < all.length - 1 && !b.text.endsWith('\n') ? `${b.text}\n` : b.text))
272
+ .join('')
181
273
  .trim();
182
274
  }
275
+
276
+ const abilityTools = (id) => ABILITIES.find((a) => a.id === id)?.tools ?? [];
277
+
278
+ /**
279
+ * Harness tools that run commands or change files outside the abilities'
280
+ * lists: PowerShell, the persistent terminals, and the other file editors.
281
+ */
282
+ const OTHER_WORK_TOOLS = ['pwsh', 'terminal_open', 'terminal_send', 'terminal_read', 'terminal_signal', 'terminal_close', 'terminal_list', 'apply_patch', 'str_replace_editor'];
283
+
284
+ /**
285
+ * Tools a router dispatcher is denied by default: running commands (and the
286
+ * job tools that go with them; `pwsh` and the terminals too), writing and
287
+ * editing files (`apply_patch` and `str_replace_editor` too), sub-agents and
288
+ * workflows, image generation and Office tools. It keeps `read`,
289
+ * `read_image`, `glob`, `grep`, `skill`, `web_search` and `web_fetch`.
290
+ */
291
+ export const ROUTER_DENY = Object.freeze([
292
+ ...new Set([...abilityTools('code'), 'write', 'edit', ...abilityTools('delegate'), ...abilityTools('images'), ...abilityTools('office'), ...OTHER_WORK_TOOLS]),
293
+ ]);
294
+
295
+ /** Longest `bash` / `pwsh` timeout a router may ask for, in ms. */
296
+ export const ROUTER_MAX_COMMAND_MS = 30_000;
297
+ /** The timeout Harness gives a command that names none (`dsh-bash-local`), in ms. */
298
+ export const DEFAULT_COMMAND_MS = 120_000;
299
+ /** Longest `job_output` wait a router may ask for, in ms (Harness waits 30 s when `wait` has no `timeout_ms`). */
300
+ export const ROUTER_MAX_JOB_WAIT_MS = 5_000;
301
+
302
+ const NO_WAIT = 'The dispatcher does not wait: reports and messages arrive by themselves. End your turn instead.';
303
+
304
+ /** Shell words that may stand before the command they run. */
305
+ const PREFIX_WORDS = new Set(['!', 'if', 'then', 'else', 'elif', 'do', 'while', 'until', 'time', 'command', 'builtin', 'exec', 'nohup', 'nice', 'sudo', 'xargs']);
306
+
307
+ /** Does a shell command run `sleep` at a command position (`sleep 5`, `x && sleep 1`, `do sleep 2; done`, `FOO=1 sleep 3`, `$(sleep 1)`)? */
308
+ export function runsSleep(command) {
309
+ const code = String(command ?? '')
310
+ .replace(/'[^']*'/g, "''")
311
+ .replace(/"(?:[^"\\$`]|\\.)*"/g, '""')
312
+ .replace(/(^|\s)#[^\n]*/g, '$1');
313
+ for (const segment of code.split(/\|\||&&|\$\(|[;&|\n(){}`]/)) {
314
+ const words = segment.trim().split(/\s+/).filter(Boolean);
315
+ let i = 0;
316
+ while (i < words.length) {
317
+ const w = words[i];
318
+ if (/^[A-Za-z_][A-Za-z0-9_]*=/.test(w) || PREFIX_WORDS.has(w)) i += 1;
319
+ else if (w === 'env' || w === 'timeout') {
320
+ i += 1;
321
+ while (i < words.length && (words[i].startsWith('-') || /^[A-Za-z_][A-Za-z0-9_]*=/.test(words[i]) || (w === 'timeout' && /^\d/.test(words[i])))) i += 1;
322
+ } else break;
323
+ }
324
+ const first = (words[i] ?? '').replace(/^\\/, '');
325
+ if (first.split('/').pop() === 'sleep') return true;
326
+ }
327
+ return false;
328
+ }
329
+
330
+ /**
331
+ * A guard for a router's tool calls (the shape of Harness `tools.guard`):
332
+ * the refusal reason for a call that would make the dispatcher wait, else
333
+ * undefined. Refused: `bash` or `pwsh` running `sleep`, or in the foreground
334
+ * without a `timeoutMs` of at most 30 s (none given means Harness's 120 s: the
335
+ * cap, not the shell text, is what bounds a wait such as `read -t` or
336
+ * `tail -f`); `run_in_background` returns at once and is allowed. And
337
+ * `job_output` waits above 5 s.
338
+ * @param {{name: string, arguments?: object}} call
339
+ * @returns {string|undefined}
340
+ */
341
+ export function noWaitReason(call) {
342
+ const name = call?.name;
343
+ const args = call?.arguments && typeof call.arguments === 'object' ? call.arguments : {};
344
+ if (name === 'bash' || name === 'pwsh') {
345
+ if (runsSleep(args.command)) return `Refused: no sleep. ${NO_WAIT}`;
346
+ if (args.run_in_background === true) return undefined;
347
+ const given = args.timeoutMs ?? args.timeout_ms;
348
+ const timeout = given === undefined || given === null || given === '' ? DEFAULT_COMMAND_MS : Number(given);
349
+ if (!(timeout > 0 && timeout <= ROUTER_MAX_COMMAND_MS)) {
350
+ return `Refused: a command here must finish within ${ROUTER_MAX_COMMAND_MS / 1000} s. Pass timeoutMs (at most ${ROUTER_MAX_COMMAND_MS}; left out it is ${DEFAULT_COMMAND_MS / 1000} s), hand long work to a bot with bot_send_message, or run it with run_in_background. ${NO_WAIT}`;
351
+ }
352
+ }
353
+ if (name === 'job_output' && args.wait === true) {
354
+ const timeout = args.timeout_ms === undefined ? Infinity : Number(args.timeout_ms);
355
+ if (!(timeout <= ROUTER_MAX_JOB_WAIT_MS)) return `Refused: job waits above ${ROUTER_MAX_JOB_WAIT_MS / 1000} s are not allowed here (pass timeout_ms up to ${ROUTER_MAX_JOB_WAIT_MS}, or read without wait). ${NO_WAIT}`;
356
+ }
357
+ return undefined;
358
+ }
package/lib/settings.mjs CHANGED
@@ -1,7 +1,9 @@
1
1
  /**
2
2
  * Team-wide settings of the bots plugin, kept in `settings.json` beside the
3
- * roster: when a bot starts a new topic by itself, how memory is written and
4
- * consolidated, and the prices the usage view counts with.
3
+ * roster: how the dispatcher works, how many tasks (tickets) run at once and
4
+ * when they are judged stalled or archived, when a bot starts a new topic by
5
+ * itself, how memory is written and consolidated, the prices the usage
6
+ * view counts with, and how the panel shows what bots say to each other.
5
7
  *
6
8
  * @module @kadaliao/dsh-bots/lib/settings
7
9
  */
@@ -10,6 +12,24 @@ import { mkdirSync, readFileSync, renameSync, statSync, writeFileSync } from 'no
10
12
  import { join } from 'node:path';
11
13
 
12
14
  export const DEFAULTS = Object.freeze({
15
+ /**
16
+ * How the dispatcher works in its home conversation: 'router' only understands, hands out
17
+ * (each delegation is a ticket with its own conversation) and reports; 'hands-on' is 0.7.
18
+ */
19
+ dispatcher: 'router',
20
+ tickets: Object.freeze({
21
+ /** Tickets whose conversations run at once; past this they queue (a person's follow-up may take one more). */
22
+ maxWorking: 4,
23
+ /** Minutes a working ticket may stay quiet before the watchdog asks for a report, and again before it is stalled. */
24
+ stallMinutes: 20,
25
+ /** Hours an ended ticket keeps its conversation before it is archived; 0 = at the next upkeep. */
26
+ archiveHours: 24,
27
+ }),
28
+ /**
29
+ * The one-time panel notice that an upgraded team now runs in router mode: 'pending' until the
30
+ * user dismisses it (or picks a mode), 'dismissed' after; null before the first run of 0.8 decided.
31
+ */
32
+ routerNotice: null,
13
33
  topics: Object.freeze({
14
34
  /** A conversation quiet for this many hours starts a new topic before its next task; 0 = never. */
15
35
  idleHours: 6,
@@ -30,8 +50,18 @@ export const DEFAULTS = Object.freeze({
30
50
  prices: Object.freeze({}),
31
51
  /** Keep a ChatGPT login borrowed from the Codex CLI in sync with ~/.codex/auth.json. */
32
52
  codex: Object.freeze({ sync: false, route: false }),
53
+ display: Object.freeze({
54
+ /**
55
+ * Messages between bots in a chat (delegations, reports, DMs): 'line' (who to whom, the task or
56
+ * first sentence, its stage and time), 'short' (that and two lines of the text), 'full' (all of it).
57
+ */
58
+ botMessages: 'line',
59
+ }),
33
60
  });
34
61
 
62
+ /** The levels of `display.botMessages`, least to most. */
63
+ export const BOT_MESSAGE_LEVELS = Object.freeze(['line', 'short', 'full']);
64
+
35
65
  const num = (v, d, min, max) => {
36
66
  const n = Number(v);
37
67
  return Number.isFinite(n) ? Math.min(max, Math.max(min, n)) : d;
@@ -67,6 +97,7 @@ export function normalizeSettings(input) {
67
97
  const s = input && typeof input === 'object' ? input : {};
68
98
  const t = s.topics ?? {};
69
99
  const m = s.memory ?? {};
100
+ const tk = s.tickets ?? {};
70
101
  const prices = {};
71
102
  if (s.prices && typeof s.prices === 'object') {
72
103
  for (const [k, v] of Object.entries(s.prices).slice(0, 300)) {
@@ -77,6 +108,13 @@ export function normalizeSettings(input) {
77
108
  }
78
109
  const model = m.model && typeof m.model === 'object' && typeof m.model.provider === 'string' && m.model.provider && typeof m.model.model === 'string' && m.model.model ? { provider: m.model.provider.slice(0, 200), model: m.model.model.slice(0, 200) } : null;
79
110
  return {
111
+ dispatcher: s.dispatcher === 'hands-on' ? 'hands-on' : 'router',
112
+ tickets: {
113
+ maxWorking: Math.round(num(tk.maxWorking, DEFAULTS.tickets.maxWorking, 1, 32)),
114
+ stallMinutes: Math.round(num(tk.stallMinutes, DEFAULTS.tickets.stallMinutes, 1, 24 * 60)),
115
+ archiveHours: num(tk.archiveHours, DEFAULTS.tickets.archiveHours, 0, 24 * 30),
116
+ },
117
+ routerNotice: s.routerNotice === 'pending' || s.routerNotice === 'dismissed' ? s.routerNotice : null,
80
118
  topics: {
81
119
  idleHours: num(t.idleHours, DEFAULTS.topics.idleHours, 0, 24 * 30),
82
120
  maxContextK: Math.round(num(t.maxContextK, DEFAULTS.topics.maxContextK, 0, 4096)),
@@ -89,6 +127,7 @@ export function normalizeSettings(input) {
89
127
  },
90
128
  prices,
91
129
  codex: { sync: s.codex?.sync === true, route: s.codex?.route === true },
130
+ display: { botMessages: BOT_MESSAGE_LEVELS.includes(s.display?.botMessages) ? s.display.botMessages : DEFAULTS.display.botMessages },
92
131
  };
93
132
  }
94
133
 
package/lib/store.mjs CHANGED
@@ -196,6 +196,10 @@ export function normalizeBot(input, prev, seed = 0) {
196
196
  const skills = capSkillsOn(dedupeSkills((Array.isArray(b.skills) ? b.skills : []).map(normalizeSkill).filter(Boolean)).slice(0, MAX_SKILLS), prev?.skills);
197
197
  const apps = (Array.isArray(b.apps) ? b.apps : []).map(normalizeApp).filter(Boolean).slice(0, 20);
198
198
  const deny = Array.isArray(b.tools?.deny) ? [...new Set(b.tools.deny.map(String).filter(Boolean))].slice(0, 200) : [];
199
+ // Tools a router dispatcher keeps although router mode denies them by default. An update whose
200
+ // `tools` leaves the list out (a panel that only edits `deny`) keeps the stored one.
201
+ const allowIn = Array.isArray(b.tools?.routerAllow) ? b.tools.routerAllow : input?.tools && typeof input.tools === 'object' && !('routerAllow' in input.tools) ? prev?.tools?.routerAllow : undefined;
202
+ const routerAllow = Array.isArray(allowIn) ? [...new Set(allowIn.map(String).filter(Boolean))].slice(0, 200) : [];
199
203
  const model =
200
204
  b.model && typeof b.model === 'object' && str(b.model.provider) && str(b.model.model)
201
205
  ? { provider: str(b.model.provider, 200), model: str(b.model.model, 200), ...(/^[a-z0-9_-]{1,32}$/.test(str(b.model.reasoningEffort)) ? { reasoningEffort: b.model.reasoningEffort } : {}) }
@@ -210,7 +214,7 @@ export function normalizeBot(input, prev, seed = 0) {
210
214
  persona: str(b.persona, 20_000),
211
215
  skills,
212
216
  apps,
213
- tools: { deny },
217
+ tools: { deny, ...(routerAllow.length ? { routerAllow } : {}) },
214
218
  model,
215
219
  sessionId: typeof b.sessionId === 'string' && b.sessionId !== '' ? b.sessionId : null,
216
220
  createdAt: prev?.createdAt ?? now,