copilot-operator 0.1.45 → 0.1.47

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.
Files changed (42) hide show
  1. package/dist/src/api/operator.controller.js +1 -0
  2. package/dist/src/api/operator.service.js +17 -3
  3. package/dist/src/api/server.js +6 -4
  4. package/dist/src/config/schema.js +3 -1
  5. package/dist/src/orchestrator/taskRunner.js +93 -28
  6. package/dist/src/transport/chatSession.js +37 -0
  7. package/dist/src/transport/copilotTransport.js +152 -25
  8. package/dist/web/404.html +2 -2
  9. package/dist/web/_next/static/chunks/{549-13aab16a40600608.js → 549-8732dd2c1339bc5d.js} +1 -1
  10. package/dist/web/_next/static/chunks/867-7fb52be342fa64e5.js +1 -0
  11. package/dist/web/_next/static/chunks/app/defaults/page-614be29d185a2947.js +1 -0
  12. package/dist/web/_next/static/chunks/app/layout-485ce9395cb17998.js +1 -0
  13. package/dist/web/_next/static/chunks/app/page-ed6a5a2ff1b6285e.js +1 -0
  14. package/dist/web/_next/static/chunks/app/sessions/view/page-835d3533fdc63082.js +1 -0
  15. package/dist/web/appearance.html +2 -2
  16. package/dist/web/appearance.txt +9 -9
  17. package/dist/web/defaults.html +2 -2
  18. package/dist/web/defaults.txt +9 -9
  19. package/dist/web/history.html +2 -2
  20. package/dist/web/history.txt +9 -9
  21. package/dist/web/import.html +2 -2
  22. package/dist/web/import.txt +9 -9
  23. package/dist/web/index.html +2 -2
  24. package/dist/web/index.txt +9 -9
  25. package/dist/web/level1.html +2 -2
  26. package/dist/web/level1.txt +9 -9
  27. package/dist/web/presets.html +2 -2
  28. package/dist/web/presets.txt +9 -9
  29. package/dist/web/sessions/view.html +2 -2
  30. package/dist/web/sessions/view.txt +9 -9
  31. package/dist/web/sessions.html +2 -2
  32. package/dist/web/sessions.txt +9 -9
  33. package/dist/web/system.html +2 -2
  34. package/dist/web/system.txt +9 -9
  35. package/package.json +1 -1
  36. package/dist/web/_next/static/chunks/867-88233b4570638286.js +0 -1
  37. package/dist/web/_next/static/chunks/app/defaults/page-56134fbb8cc7554f.js +0 -1
  38. package/dist/web/_next/static/chunks/app/layout-12f138ee04d33c1e.js +0 -1
  39. package/dist/web/_next/static/chunks/app/page-b51630404f5eba03.js +0 -1
  40. package/dist/web/_next/static/chunks/app/sessions/view/page-afc235a9171535d8.js +0 -1
  41. /package/dist/web/_next/static/{L6g_c8hW3p_AUNzreQ3Sj → HT6yqFoDPOXChAZVDxshC}/_buildManifest.js +0 -0
  42. /package/dist/web/_next/static/{L6g_c8hW3p_AUNzreQ3Sj → HT6yqFoDPOXChAZVDxshC}/_ssgManifest.js +0 -0
@@ -549,6 +549,7 @@ let OperatorController = class OperatorController {
549
549
  text: body.text,
550
550
  ...(typeof body.threadId === 'string' && body.threadId ? { threadId: body.threadId } : {}),
551
551
  ...(typeof body.model === 'string' && body.model.trim() ? { model: body.model } : {}),
552
+ ...(body.manualModel === true ? { manualModel: true } : {}),
552
553
  })
553
554
  .catch(fail);
554
555
  }
@@ -429,6 +429,7 @@ let OperatorService = class OperatorService {
429
429
  throw new Error('This session is running; its status can be changed once it has stopped.');
430
430
  }
431
431
  return await this.store.updateSession(id, (s) => {
432
+ const before = { model: s.model, manualModel: s.manualModel };
432
433
  if (patch.name !== undefined)
433
434
  s.name = patch.name.trim() || s.name;
434
435
  if (patch.active === true)
@@ -443,6 +444,16 @@ let OperatorService = class OperatorService {
443
444
  // Chosen on the session's page: the operator's own word, which outranks Settings.
444
445
  s.modelSource = s.model ? 'operator' : undefined;
445
446
  }
447
+ if (typeof patch.manualModel === 'boolean') {
448
+ if (patch.manualModel)
449
+ s.manualModel = true;
450
+ else
451
+ delete s.manualModel;
452
+ }
453
+ // Another choice of model: what was set by hand in the conversation is not what is asked for any more.
454
+ if ((patch.model !== undefined || typeof patch.manualModel === 'boolean') && (s.model !== before.model || !!s.manualModel !== !!before.manualModel)) {
455
+ delete s.modelByHand;
456
+ }
446
457
  // The same for the group: clearing it gives this session its conversation back. It does
447
458
  // not move the conversation it is already in; that history is where it is.
448
459
  if (patch.conversationGroup !== undefined)
@@ -1479,8 +1490,9 @@ let OperatorService = class OperatorService {
1479
1490
  await this.store.updateSession(sessionId, (s) => {
1480
1491
  s.status = 'stopping';
1481
1492
  });
1482
- // The running step is cut off, not waited for: said as it is (live run 2026-10-03).
1483
- this.bus.publish({ sessionId, type: 'stop-requested', level: 'warn', message: 'stopping now: nothing more is sent, and a step still running is cut off' });
1493
+ // The running step is cut off, not waited for: said as it is (live run 2026-10-03). An answer the chat is writing
1494
+ // is waited for, so the conversation is left whole; the choice of model and the sign-in end at once (2026-10-17).
1495
+ this.bus.publish({ sessionId, type: 'stop-requested', level: 'warn', message: 'stopping now: nothing more is sent, a step still running is cut off, and an answer Copilot is writing is waited for first' });
1484
1496
  return { stopping: true };
1485
1497
  }
1486
1498
  // --- running several sessions in turn -------------------------------------------------
@@ -2314,7 +2326,9 @@ let OperatorService = class OperatorService {
2314
2326
  s.vcs = { ...(s.vcs ?? DEFAULT_VCS), enabled: false, repoDir: '' };
2315
2327
  s.projectDir = ws.dir;
2316
2328
  // The model chosen in the chat for this conversation: the operator's word, which outranks Settings.
2317
- if (input.model?.trim()) {
2329
+ if (input.manualModel)
2330
+ s.manualModel = true;
2331
+ else if (input.model?.trim()) {
2318
2332
  s.model = input.model.trim();
2319
2333
  s.modelSource = 'operator';
2320
2334
  }
@@ -111,14 +111,16 @@ export async function startApi(opts = {}) {
111
111
  /*
112
112
  * A page whose name is also a folder of pages: `/sessions` is `sessions.html`, and `sessions/` holds
113
113
  * `view.html` (2026-10-14, when the list moved there). The static server finds the folder first and
114
- * redirects to it, where there is no page; the page is served instead.
114
+ * redirects to it, where there is no page; the page is served instead. Named from the interface's own
115
+ * folder: a whole path is refused (404) when any folder in it starts with a dot, as one under
116
+ * `.claude\worktrees` or pnpm's `node_modules\.pnpm` does (2026-10-17).
115
117
  */
116
118
  const root = webDir;
117
119
  app.use((req, res, next) => {
118
120
  if ((req.method === 'GET' || req.method === 'HEAD') && /^\/[a-z0-9-]+$/i.test(req.path)) {
119
- const page = join(root, `${req.path.slice(1)}.html`);
120
- if (existsSync(page) && existsSync(join(root, req.path.slice(1)))) {
121
- res.sendFile(page);
121
+ const name = req.path.slice(1);
122
+ if (existsSync(join(root, `${name}.html`)) && existsSync(join(root, name))) {
123
+ res.sendFile(`${name}.html`, { root });
122
124
  return;
123
125
  }
124
126
  }
@@ -119,8 +119,10 @@ export const RunConfigSchema = z.object({
119
119
  * Choose the model by hand (operator's workaround, 2026-10-06): at the start of a run, and of a review's
120
120
  * conversation, the runner does not touch the picker; a card in the UI asks the operator to choose the
121
121
  * model in the Copilot window and press "Ready". A conversation already on the model is not asked about.
122
+ * On by default since 2026-10-17 (operator: "leave the automatic choice for now; make it work with the
123
+ * user choosing it by hand, and test the bot itself"); off, the runner chooses the model itself.
122
124
  */
123
- manualModel: z.boolean().default(false),
125
+ manualModel: z.boolean().default(true),
124
126
  replyTimeoutSec: z.number().int().positive().default(900),
125
127
  signInTimeoutSec: z.number().int().positive().default(900),
126
128
  humanWaitSec: z.number().int().positive().default(900),
@@ -13,7 +13,7 @@
13
13
  import { createHash } from 'node:crypto';
14
14
  import { readFile, mkdir, writeFile, appendFile } from 'node:fs/promises';
15
15
  import { join, resolve } from 'node:path';
16
- import { buttonShows } from '../transport/modelMatch.js';
16
+ import { buttonShows, normModel } from '../transport/modelMatch.js';
17
17
  import { createTransport, isReplyTimeout } from '../transport/chatTransport.js';
18
18
  import { buildChatName, chatCode, loadPointer, savePointer } from '../transport/chatSession.js';
19
19
  import { parseReply, formatErrorMessage, findLikelyDamage, damageGuidance } from '../protocol/parser.js';
@@ -313,7 +313,9 @@ export function speakFor(transport, sessionId) {
313
313
  if (speaker)
314
314
  speaker.id = sessionId;
315
315
  }
316
- export async function openBrowser(cfg, bus, transportDir, sessionId) {
316
+ export async function openBrowser(cfg, bus, transportDir, sessionId,
317
+ /** The run's Stop: a sign-in still awaited ends with it. */
318
+ signal) {
317
319
  const speaker = { id: sessionId };
318
320
  const transport = createTransport({
319
321
  profileDir: cfg.resolved.profileDir,
@@ -358,7 +360,7 @@ export async function openBrowser(cfg, bus, transportDir, sessionId) {
358
360
  */
359
361
  try {
360
362
  await transport.open();
361
- await transport.ensureSignedIn();
363
+ await transport.ensureSignedIn(undefined, { signal });
362
364
  }
363
365
  catch (e) {
364
366
  await transport.close().catch(() => undefined);
@@ -500,8 +502,8 @@ async function joinGroupConversation(store, session, bus) {
500
502
  return updated;
501
503
  }
502
504
  /** The old shape, kept for the terminal path: open a browser and enter the conversation. */
503
- export async function openSessionTransport(cfg, session, bus, runsDir) {
504
- const transport = await openBrowser(cfg, bus, join(runsDir, '_browser'), session.id);
505
+ export async function openSessionTransport(cfg, session, bus, runsDir, signal) {
506
+ const transport = await openBrowser(cfg, bus, join(runsDir, '_browser'), session.id, signal);
505
507
  await enterSessionConversation(transport, session, { closeOnFailure: true });
506
508
  return transport;
507
509
  }
@@ -529,14 +531,32 @@ export async function openSessionTransport(cfg, session, bus, runsDir) {
529
531
  */
530
532
  export function effectiveModels(session, cfg) {
531
533
  const pick = (own, source, settings) => own && source === 'operator' ? [own, 'session'] : settings ? [settings, 'settings'] : own ? [own, 'plan'] : ['', 'none'];
532
- const [model, modelFrom] = pick((session.model ?? '').trim(), session.modelSource, (cfg.copilot.defaultModel ?? '').trim());
534
+ // Set by hand in the Copilot window: no name is asked for, neither the session's nor the one in Settings.
535
+ const [model, modelFrom] = session.manualModel ? ['', 'none'] : pick((session.model ?? '').trim(), session.modelSource, (cfg.copilot.defaultModel ?? '').trim());
533
536
  const [reviewModel, reviewModelFrom] = pick((session.review?.model ?? '').trim(), session.reviewModelSource, (cfg.copilot.defaultReviewModel ?? '').trim());
534
537
  return { model, reviewModel, modelFrom, reviewModelFrom };
535
538
  }
536
- async function applySessionModel(transport, session, bus, cfg, store, hooks) {
539
+ /**
540
+ * Whether the model of this session's conversation is chosen by hand in the Copilot window: Settings say so for
541
+ * every run, the session says so ("Set the model by hand" in the chat's picker), or it is a chat that names no
542
+ * model and has none from Settings either — its picker shows "by hand" for that, and what it shows is what happens.
543
+ */
544
+ export function modelByHand(session, cfg) {
545
+ if (cfg.copilot.manualModel || session.manualModel)
546
+ return true;
547
+ return session.kind === 'chat' && !effectiveModels(session, cfg).model;
548
+ }
549
+ async function applySessionModel(transport, session, bus, cfg, store, hooks,
550
+ /** Whether the conversation was opened new for this run, rather than one the session already had. */
551
+ fresh = true,
552
+ /** The run's Stop: the picker's waits end with it, and nothing is sent. */
553
+ signal) {
554
+ const stopped = { refused: 'Stopped by the operator while the model was being chosen. Nothing was sent; the tasks stay queued.' };
555
+ if (signal?.aborted)
556
+ return stopped;
537
557
  const { model: wanted, modelFrom } = effectiveModels(session, cfg);
538
558
  const fromSettings = modelFrom === 'settings';
539
- const manual = !!cfg.copilot.manualModel && !!hooks?.askHelp;
559
+ const manual = modelByHand(session, cfg) && !!hooks?.askHelp;
540
560
  if (!wanted && !manual)
541
561
  return {};
542
562
  let result;
@@ -546,18 +566,42 @@ async function applySessionModel(transport, session, bus, cfg, store, hooks) {
546
566
  * on the model — the chat keeps its model — is not asked about; otherwise the card asks for it.
547
567
  */
548
568
  const shown = await transport.currentModel().catch(() => null);
569
+ /*
570
+ * The conversation is "on the model" when the operator set it by hand in it before, for the same name or for
571
+ * none: asked once, at its first run, not at every one (2026-10-17) — the picker button's text could not be
572
+ * relied on at work to say so. A new conversation is asked again, and so is another name asked for.
573
+ */
574
+ const setBefore = session.modelByHand;
575
+ if (!fresh && setBefore && normModel(setBefore.asked ?? '') === normModel(wanted)) {
576
+ bus.publish({ sessionId: session.id, type: 'model-kept-by-hand', level: 'info',
577
+ message: `model: set by hand in this conversation (the picker shows "${shown ?? 'nothing'}"); not asked again`,
578
+ data: { shown, setAt: setBefore.at, shownThen: setBefore.shown, asked: wanted } });
579
+ await store?.updateSession(session.id, (s) => { s.modelInUse = shown ?? undefined; }).catch(() => undefined);
580
+ return { current: shown ?? undefined };
581
+ }
582
+ const why = cfg.copilot.manualModel ? 'Settings ask for the model to be chosen by hand' : 'the session asks for the model to be set by hand';
549
583
  const hand = wanted && buttonShows(shown, wanted)
550
584
  ? { result: { ok: true, current: wanted, by: 'already' }, goOnAsItIs: false }
551
- : await withOperatorHand(transport, wanted, { ok: false, current: shown, reason: 'Settings ask for the model to be chosen by hand' }, hooks, session.id, bus, true);
585
+ : await withOperatorHand(transport, wanted, { ok: false, current: shown, reason: why }, hooks, session.id, bus, true);
552
586
  if (!wanted) {
553
587
  const now = await transport.currentModel().catch(() => null);
554
588
  if (hand.result.ok || hand.goOnAsItIs) {
555
- await store?.updateSession(session.id, (s) => { s.modelInUse = now ?? undefined; }).catch(() => undefined);
589
+ await store
590
+ ?.updateSession(session.id, (s) => {
591
+ s.modelInUse = now ?? undefined;
592
+ s.modelByHand = { at: new Date().toISOString(), shown: now };
593
+ })
594
+ .catch(() => undefined);
556
595
  return { current: now ?? undefined };
557
596
  }
558
597
  return { refused: 'The model was to be chosen by hand, and the operator stopped the run. Nothing was sent.' };
559
598
  }
560
599
  result = hand.result;
600
+ // Set by hand in this conversation: the next run that comes back to it is not asked again.
601
+ if (result.ok || hand.goOnAsItIs) {
602
+ const now = await transport.currentModel().catch(() => null);
603
+ await store?.updateSession(session.id, (s) => { s.modelByHand = { at: new Date().toISOString(), shown: now, asked: wanted }; }).catch(() => undefined);
604
+ }
561
605
  if (hand.goOnAsItIs) {
562
606
  bus.publish({ sessionId: session.id, type: 'model-selected', level: 'warn', message: `model: ${result.current ?? 'unknown'} (chosen by hand; not "${wanted}")`, data: { asked: wanted, current: result.current, ok: false, by: 'hand' } });
563
607
  return { current: result.current ?? undefined };
@@ -565,11 +609,16 @@ async function applySessionModel(transport, session, bus, cfg, store, hooks) {
565
609
  }
566
610
  else {
567
611
  const locator = await hooks?.locate?.(wanted).catch(() => undefined);
568
- result = await transport.selectModel(wanted, { locator }).catch((e) => ({
612
+ result = await transport.selectModel(wanted, { locator, signal }).catch((e) => ({
569
613
  ok: false,
570
614
  current: null,
571
615
  reason: e.message,
572
616
  }));
617
+ // Not put to the operator on a card: they asked for the run to stop.
618
+ if (signal?.aborted) {
619
+ bus.publish({ sessionId: session.id, type: 'model-not-selected', level: 'info', message: `stopped by the operator while "${wanted}" was being chosen; nothing was sent`, data: { asked: wanted, stopped: true } });
620
+ return stopped;
621
+ }
573
622
  }
574
623
  const hand = await withOperatorHand(transport, wanted, result, hooks, session.id, bus, false);
575
624
  result = hand.result;
@@ -710,17 +759,19 @@ export async function runTask(transport, session, task, deps) {
710
759
  if ((await target.currentChatId().catch(() => null)) !== chat.chatId)
711
760
  return;
712
761
  nameTries += 1;
713
- const named = await target.nameChat(chat.chatId, chat.name, { waitMs: 5_000 }).catch(() => false);
714
- if (!named)
762
+ const saved = await target.nameChat(chat.chatId, chat.name, { waitMs: 5_000 }).catch(() => false);
763
+ if (!saved)
715
764
  return;
716
- const { named: _was, ...done } = chat;
765
+ // The name Copilot took, which may be a shorter form of the one asked for: it is what the chat is found by.
766
+ const { named: _was, ...rest } = chat;
767
+ const done = { ...rest, name: saved };
717
768
  session.chat = done;
718
769
  await store.updateSession(session.id, (s) => {
719
770
  if (s.chat?.chatId === chat.chatId)
720
- s.chat = { ...s.chat, named: undefined };
771
+ s.chat = { ...s.chat, named: undefined, name: saved };
721
772
  }).catch(() => undefined);
722
773
  await savePointer(log.path('chat.json'), done).catch(() => undefined);
723
- sink.event('chat-named-later', { chatId: chat.chatId, name: chat.name, tries: nameTries }, `chat named "${chat.name}" in Copilot's sidebar, now that it is there`);
774
+ sink.event('chat-named-later', { chatId: chat.chatId, name: saved, tries: nameTries }, `chat named "${saved}" in Copilot's sidebar, now that it is there`);
724
775
  };
725
776
  const chatOf = transport;
726
777
  transport = new Proxy(chatOf, {
@@ -1433,7 +1484,7 @@ export async function runTask(transport, session, task, deps) {
1433
1484
  * record would go on naming the model the session asked for. Applied again here, as the
1434
1485
  * fresh-chat retry in `runSession` does for the same reason.
1435
1486
  */
1436
- const modelNow = await applySessionModel(transport, session, bus, cfg, store, deps.models);
1487
+ const modelNow = await applySessionModel(transport, session, bus, cfg, store, deps.models, !chat, deps.signal);
1437
1488
  if (effectiveModels(session, cfg).model) {
1438
1489
  await store.updateSession(session.id, (s) => {
1439
1490
  s.modelInUse = modelNow.current;
@@ -1534,8 +1585,11 @@ export async function runTask(transport, session, task, deps) {
1534
1585
  if (chatId) {
1535
1586
  // A fresh-chat retry, or any later attempt, says so in the name: the abandoned chat had the same one (live run 2026-10-03).
1536
1587
  // Only a retry in a fresh chat is named apart; a first conversation is not, whatever the attempt number.
1537
- const name = buildChatName(`${chatCode(session.id)}${task.freshRetry ? `/a${attempt}` : ''}`, session.name);
1538
- const named = await transport.nameChat(chatId, name).catch(() => false);
1588
+ const asked = buildChatName(`${chatCode(session.id)}${task.freshRetry ? `/a${attempt}` : ''}`, session.name);
1589
+ const saved = await transport.nameChat(chatId, asked).catch(() => false);
1590
+ const named = saved !== false;
1591
+ // The name Copilot took, which may be a shorter form of the one asked for (see `chatNameForms`).
1592
+ const name = saved || asked;
1539
1593
  const chat = {
1540
1594
  chatId,
1541
1595
  url: `${cfg.copilot.url.replace(/\/chat.*$/, '')}/chat/conversation/${chatId}?es=SSR`,
@@ -1923,7 +1977,7 @@ export async function runTask(transport, session, task, deps) {
1923
1977
  }
1924
1978
  else {
1925
1979
  const reviewLocator = await deps.models?.locate?.(model).catch(() => undefined);
1926
- picked = await transport.selectModel(model, { locator: reviewLocator }).catch((e) => ({ ok: false, current: null, reason: e.message }));
1980
+ picked = await transport.selectModel(model, { locator: reviewLocator, signal }).catch((e) => ({ ok: false, current: null, reason: e.message }));
1927
1981
  }
1928
1982
  const renamed = await followPageModels('review', model, picked, session, store, deps.models, effectiveModels(session, cfg).reviewModelFrom);
1929
1983
  if (renamed)
@@ -2935,19 +2989,21 @@ export async function runSession(sessionId, deps) {
2935
2989
  }
2936
2990
  else {
2937
2991
  await deps.beforeBrowser?.();
2938
- transport = await openSessionTransport(cfg, session, bus, sessionRunsDir);
2992
+ transport = await openSessionTransport(cfg, session, bus, sessionRunsDir, deps.signal);
2939
2993
  }
2940
2994
  const chat = transport;
2941
2995
  // The picker belongs to the conversation, so the session's choice is applied once, here,
2942
- // before the first task goes out. What the chat ended up on is recorded either way.
2943
- const modelInUse = await applySessionModel(chat, session, bus, cfg, store, deps.models);
2996
+ // before the first task goes out. What the chat ended up on is recorded either way. A conversation
2997
+ // the session already had was reopened above; one it did not have was opened new.
2998
+ const modelInUse = await applySessionModel(chat, session, bus, cfg, store, deps.models, !session.chat, deps.signal);
2944
2999
  if (effectiveModels(session, cfg).model) {
2945
3000
  await store.updateSession(sessionId, (s) => {
2946
3001
  s.modelInUse = modelInUse.current;
2947
3002
  });
2948
3003
  }
2949
- // Refused before a task is marked started: its tasks stay queued, and the run says why.
2950
- if (modelInUse.refused)
3004
+ // Refused before a task is marked started: its tasks stay queued, and the run says why. Stopped, the loop
3005
+ // below ends before its first task.
3006
+ if (modelInUse.refused && !deps.signal?.aborted)
2951
3007
  throw new Error(modelInUse.refused);
2952
3008
  for (const queuedTask of queued) {
2953
3009
  if (deps.signal?.aborted)
@@ -3063,7 +3119,7 @@ export async function runSession(sessionId, deps) {
3063
3119
  * it was the model the session asked for. The review has always done this for its own
3064
3120
  * fresh conversations a few hundred lines up; this path simply never did.
3065
3121
  */
3066
- const freshModel = await applySessionModel(chat, session, bus, cfg, store, deps.models);
3122
+ const freshModel = await applySessionModel(chat, session, bus, cfg, store, deps.models, true, deps.signal);
3067
3123
  if (effectiveModels(session, cfg).model) {
3068
3124
  session = await store.updateSession(sessionId, (s) => {
3069
3125
  s.modelInUse = freshModel.current;
@@ -3127,8 +3183,17 @@ export async function runSession(sessionId, deps) {
3127
3183
  }
3128
3184
  }
3129
3185
  catch (e) {
3130
- bus.publish({ sessionId, type: 'session-error', level: 'error', message: e.message });
3131
- throw e;
3186
+ /*
3187
+ * Stopped while the browser was opening, the sign-in awaited or the model chosen: what the operator asked for,
3188
+ * not a failure. Said as a stop, and the tasks stay queued (2026-10-17).
3189
+ */
3190
+ if (deps.signal?.aborted && ran === 0) {
3191
+ bus.publish({ sessionId, type: 'session-stopped', level: 'info', message: `stopped by the operator before the first task was sent; the tasks stay queued (${e.message})` });
3192
+ }
3193
+ else {
3194
+ bus.publish({ sessionId, type: 'session-error', level: 'error', message: e.message });
3195
+ throw e;
3196
+ }
3132
3197
  }
3133
3198
  finally {
3134
3199
  // A borrowed window belongs to whoever opened it and stays open for the next session.
@@ -60,6 +60,43 @@ export function buildChatName(runId, label) {
60
60
  .slice(0, room);
61
61
  return (prefix + clean).replace(/\/$/, '').slice(0, MAX_CHAT_NAME);
62
62
  }
63
+ /**
64
+ * The forms of a chat name to offer Copilot's rename dialog, longest first, each shorter than the one before.
65
+ *
66
+ * The dialog refuses a name it counts as longer than 50 characters, and its count is not always this file's: the
67
+ * operator saw the bot try to save a longer one (2026-09-30, again 2026-10-17), while every name made here is 50
68
+ * UTF-16 units at most. A counter of UTF-8 bytes takes a Cyrillic letter as two, so a Bulgarian session's name of 50
69
+ * letters is a hundred to it. Rather than guess which count the page keeps, the dialog is offered these in turn and
70
+ * the first it takes is the chat's name (see `nameChat`): 50 letters, cut whole (a letter outside the BMP is not
71
+ * split in two); 50 bytes of UTF-8; the same in ASCII alone; the prefix and the session code alone, `op/<code>`,
72
+ * which is what makes the chat findable and which every count agrees is short.
73
+ */
74
+ export function chatNameForms(name) {
75
+ const forms = [];
76
+ const add = (form) => {
77
+ const tidy = form.replace(/[-._/]+$/, '');
78
+ if (tidy && !forms.includes(tidy))
79
+ forms.push(tidy);
80
+ };
81
+ const letters = (s, n) => Array.from(s).slice(0, n).join('');
82
+ const bytes = (s, n) => {
83
+ let out = '';
84
+ for (const ch of s) {
85
+ if (Buffer.byteLength(out + ch, 'utf8') > n)
86
+ break;
87
+ out += ch;
88
+ }
89
+ return out;
90
+ };
91
+ const ascii = name.normalize('NFKD').replace(/[^\x20-\x7e]/g, '').replace(/-{2,}/g, '-').replace(/\/-+/g, '/');
92
+ add(letters(name, MAX_CHAT_NAME));
93
+ add(bytes(name, MAX_CHAT_NAME));
94
+ add(bytes(ascii, MAX_CHAT_NAME));
95
+ const code = /^op\/[a-z0-9]+(?:\/a\d+)?/i.exec(name)?.[0];
96
+ if (code)
97
+ add(code);
98
+ return forms;
99
+ }
63
100
  /** Compact run id, e.g. `20260917-1912`. Stable, sortable, short enough to fit the name. */
64
101
  export function makeRunId(now = new Date()) {
65
102
  const p = (n) => String(n).padStart(2, '0');