copilot-operator 0.1.59 → 0.1.62

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 (60) hide show
  1. package/dist/src/api/operator.controller.js +78 -1
  2. package/dist/src/api/operator.service.js +254 -3
  3. package/dist/src/cli.js +3 -0
  4. package/dist/src/config/exportHome.js +78 -0
  5. package/dist/src/config/schema.js +22 -0
  6. package/dist/src/orchestrator/taskRunner.js +15 -4
  7. package/dist/src/plan/systemGuide.js +326 -0
  8. package/dist/src/queue/queue.js +160 -0
  9. package/dist/src/transport/copilotTransport.js +263 -131
  10. package/dist/src/transport/locators.js +119 -33
  11. package/dist/src/util/zip.js +80 -0
  12. package/dist/src/vcs/taskVcs.js +25 -1
  13. package/dist/web/404.html +2 -2
  14. package/dist/web/_next/static/PJs9xZLAnUDPOFvGV0T_M/_buildManifest.js +1 -0
  15. package/dist/web/_next/static/chunks/1077.42a0502bfe3f2014.js +1 -0
  16. package/dist/web/_next/static/chunks/1548.dbf0648a1239382e.js +1 -0
  17. package/dist/web/_next/static/chunks/2163.dbdeebeb0c069d62.js +1 -0
  18. package/dist/web/_next/static/chunks/714.6472121643f99452.js +1 -0
  19. package/dist/web/_next/static/chunks/7220.391debd1191fc29a.js +1 -0
  20. package/dist/web/_next/static/chunks/7921-0549a0038e591e42.js +1 -0
  21. package/dist/web/_next/static/chunks/8124-5458b17433987fab.js +1 -0
  22. package/dist/web/_next/static/chunks/8197-e2fcb43f38a2b4a7.js +1 -0
  23. package/dist/web/_next/static/chunks/8584.4432f14f0cd88188.js +1 -0
  24. package/dist/web/_next/static/chunks/9067.841d6d2f4726f9c2.js +1 -0
  25. package/dist/web/_next/static/chunks/9747.1a7337320eccdc8a.js +1 -0
  26. package/dist/web/_next/static/chunks/app/layout-9201c637ca24b2c9.js +1 -0
  27. package/dist/web/_next/static/chunks/app/{page-c3c50d426109e8c5.js → page-ea0a60db75dac546.js} +1 -1
  28. package/dist/web/_next/static/chunks/app/queue/page-f86936d39121ade8.js +1 -0
  29. package/dist/web/_next/static/chunks/app/settings/page-1833ace66fc9eb0e.js +1 -0
  30. package/dist/web/_next/static/chunks/app/system/page-3466496814a70b62.js +1 -0
  31. package/dist/web/_next/static/chunks/{webpack-d210ad961e7a9237.js → webpack-4665fed2f4b06052.js} +1 -1
  32. package/dist/web/_next/static/css/5ec15fce93be8cbe.css +1 -0
  33. package/dist/web/defaults.html +2 -2
  34. package/dist/web/defaults.txt +8 -8
  35. package/dist/web/index.html +3 -3
  36. package/dist/web/index.txt +9 -9
  37. package/dist/web/queue.html +14 -0
  38. package/dist/web/queue.txt +26 -0
  39. package/dist/web/settings.html +2 -2
  40. package/dist/web/settings.txt +9 -9
  41. package/dist/web/system.html +2 -2
  42. package/dist/web/system.txt +9 -9
  43. package/package.json +5 -2
  44. package/dist/web/_next/static/Gan_sPghz9GR_aVaCL2ah/_buildManifest.js +0 -1
  45. package/dist/web/_next/static/chunks/1077.34c33df752c793fd.js +0 -1
  46. package/dist/web/_next/static/chunks/1548.9bd3216f2e2ed40a.js +0 -1
  47. package/dist/web/_next/static/chunks/2163.c764c5ddf04e8f3c.js +0 -1
  48. package/dist/web/_next/static/chunks/3134-b6a7bc1f267c39aa.js +0 -1
  49. package/dist/web/_next/static/chunks/4512-bf72c643d4a4db71.js +0 -1
  50. package/dist/web/_next/static/chunks/714.ce1d54a2c2b5474f.js +0 -1
  51. package/dist/web/_next/static/chunks/7220.07100b580a566f9c.js +0 -1
  52. package/dist/web/_next/static/chunks/7921-97fcfd1f6aff2774.js +0 -1
  53. package/dist/web/_next/static/chunks/8584.d863bb44ea78998d.js +0 -1
  54. package/dist/web/_next/static/chunks/9067.3d3d65b5fb1c6a61.js +0 -1
  55. package/dist/web/_next/static/chunks/9747.af530d25cd7cc8fb.js +0 -1
  56. package/dist/web/_next/static/chunks/app/layout-9cd9b0b0587f4882.js +0 -1
  57. package/dist/web/_next/static/chunks/app/settings/page-e485720f199e3194.js +0 -1
  58. package/dist/web/_next/static/chunks/app/system/page-176448acb2c8baa6.js +0 -1
  59. package/dist/web/_next/static/css/e544b477e4b4b108.css +0 -1
  60. /package/dist/web/_next/static/{Gan_sPghz9GR_aVaCL2ah → PJs9xZLAnUDPOFvGV0T_M}/_ssgManifest.js +0 -0
@@ -64,6 +64,14 @@ export const SYSTEM_GUIDE = [
64
64
  doesEn: 'Opens the chat, with the project\'s files beside it.',
65
65
  doesBg: 'Отваря чата, с файловете на проекта до него.',
66
66
  },
67
+ {
68
+ key: 'nav.queue',
69
+ kind: 'link',
70
+ en: 'Queue',
71
+ bg: 'Опашка',
72
+ doesEn: 'Opens the queue of tasks: written beforehand, run one after another, each in a new chat on its own model.',
73
+ doesBg: 'Отваря опашката от задачи: написани предварително, изпълнявани една след друга, всяка в нов чат със свой модел.',
74
+ },
67
75
  {
68
76
  key: 'nav.defaults',
69
77
  kind: 'link',
@@ -1370,6 +1378,237 @@ export const SYSTEM_GUIDE = [
1370
1378
  },
1371
1379
  ],
1372
1380
  },
1381
+ {
1382
+ route: '/queue',
1383
+ nameEn: 'Queue',
1384
+ nameBg: 'Опашка',
1385
+ purposeEn: 'Tasks written beforehand and run one after another while the operator is away, each in a new chat on its own model, in the folder as it is or on a new branch from main; a task may depend on earlier ones, and is skipped when one of them did not end done, while the others still run.',
1386
+ purposeBg: 'Задачи, написани предварително и изпълнявани една след друга, докато операторът го няма, всяка в нов чат със свой модел, в папката както е или на нов бранч от main; задача може да зависи от по-ранни и се прескача, ако някоя от тях не е завършила, а другите се изпълняват.',
1387
+ sections: [
1388
+ {
1389
+ headingKey: 'q.title',
1390
+ en: 'Queue of tasks',
1391
+ bg: 'Опашка от задачи',
1392
+ controls: [
1393
+ {
1394
+ key: 'q.run',
1395
+ kind: 'button',
1396
+ en: 'Run the queue',
1397
+ bg: 'Пусни опашката',
1398
+ doesEn: 'Runs the waiting tasks one after another, each in a new chat; it becomes "Stop the queue" while they run.',
1399
+ doesBg: 'Изпълнява чакащите задачи една след друга, всяка в нов чат; докато вървят, става „Спри опашката“.',
1400
+ },
1401
+ {
1402
+ key: 'q.stop',
1403
+ kind: 'button',
1404
+ en: 'Stop the queue',
1405
+ bg: 'Спри опашката',
1406
+ doesEn: 'Stops the task at work, as the chat\'s Stop does; the rest wait.',
1407
+ doesBg: 'Спира задачата, която работи, както Спри в чата; останалите чакат.',
1408
+ },
1409
+ {
1410
+ key: 'q.graph',
1411
+ kind: 'note',
1412
+ en: 'How the queue runs',
1413
+ bg: 'Как върви опашката',
1414
+ doesEn: 'A picture over the list: a dot a task, left to right as they run, a thread from a task to each one that depends on it; pointing at a dot shows its name, "Show all names" shows them all.',
1415
+ doesBg: 'Графика над списъка: точка за задача, отляво надясно, както се изпълняват, нишка от задача към всяка, която зависи от нея; посочена точка показва името си, „Покажи всички имена“ ги показва всички.',
1416
+ },
1417
+ {
1418
+ key: 'q.openChat',
1419
+ kind: 'link',
1420
+ en: 'Open the chat',
1421
+ bg: 'Отвори чата',
1422
+ doesEn: 'Opens the chat a task ran in.',
1423
+ doesBg: 'Отваря чата, в който е работила задачата.',
1424
+ },
1425
+ {
1426
+ key: 'q.again',
1427
+ kind: 'button',
1428
+ en: 'Run again',
1429
+ bg: 'Пусни отново',
1430
+ doesEn: 'Puts a task that ended back to wait, for the next run of the queue.',
1431
+ doesBg: 'Връща завършила задача да чака следващото пускане на опашката.',
1432
+ },
1433
+ {
1434
+ key: 'q.edit',
1435
+ kind: 'button',
1436
+ en: 'Edit',
1437
+ bg: 'Редактирай',
1438
+ doesEn: 'Opens a waiting task in the form below, to change it.',
1439
+ doesBg: 'Отваря чакаща задача във формата отдолу, за да се промени.',
1440
+ },
1441
+ {
1442
+ key: 'q.up',
1443
+ kind: 'button',
1444
+ en: 'Move up',
1445
+ bg: 'Нагоре',
1446
+ doesEn: 'The ↑ beside a task: it runs one place earlier. A task stays after the tasks it depends on.',
1447
+ doesBg: '↑ до задача: изпълнява се едно място по-рано. Задачата остава след задачите, от които зависи.',
1448
+ },
1449
+ {
1450
+ key: 'q.down',
1451
+ kind: 'button',
1452
+ en: 'Move down',
1453
+ bg: 'Надолу',
1454
+ doesEn: 'The ↓ beside a task: it runs one place later.',
1455
+ doesBg: '↓ до задача: изпълнява се едно място по-късно.',
1456
+ },
1457
+ {
1458
+ key: 'q.byHandLink',
1459
+ kind: 'link',
1460
+ en: 'Change it in Settings',
1461
+ bg: 'Променете го в Settings',
1462
+ doesEn: 'Shown when Settings choose the model by hand: opens "Model for the worker" there, to turn it off.',
1463
+ doesBg: 'Показва се, когато в Settings моделът се избира ръчно: отваря „Модел за изпълнителя“ там, за да се изключи.',
1464
+ },
1465
+ {
1466
+ key: 'q.remove',
1467
+ kind: 'button',
1468
+ en: 'Remove',
1469
+ bg: 'Махни',
1470
+ doesEn: 'Takes a task out of the queue; the tasks that depended on it no longer do.',
1471
+ doesBg: 'Маха задача от опашката; задачите, които са зависели от нея, вече не зависят.',
1472
+ },
1473
+ ],
1474
+ },
1475
+ {
1476
+ headingKey: 'q.addTitle',
1477
+ en: 'Add a task',
1478
+ bg: 'Добави задача',
1479
+ controls: [
1480
+ {
1481
+ key: 'q.name',
1482
+ kind: 'field',
1483
+ en: 'Name',
1484
+ bg: 'Име',
1485
+ doesEn: 'What the list and the picture call the task; empty, its first line.',
1486
+ doesBg: 'Как списъкът и графиката наричат задачата; празно — първият ѝ ред.',
1487
+ },
1488
+ {
1489
+ key: 'q.lead',
1490
+ kind: 'checkbox',
1491
+ en: 'Two chats',
1492
+ bg: 'Два чата',
1493
+ doesEn: 'A lead and a worker for the task, as "Two chats" under the chat\'s box; the lead judges, so there is no review.',
1494
+ doesBg: 'Ръководител и изпълнител за задачата, както „Два чата“ под полето на чата; ръководителят преценява, затова няма рецензия.',
1495
+ },
1496
+ {
1497
+ key: 'q.leadModel',
1498
+ kind: 'select',
1499
+ en: 'Model for the lead',
1500
+ bg: 'Модел за ръководителя',
1501
+ doesEn: 'With "Two chats": the lead\'s model, in the place of "Model".',
1502
+ doesBg: 'С „Два чата“: моделът на ръководителя, на мястото на „Модел“.',
1503
+ },
1504
+ {
1505
+ key: 'q.workerModel',
1506
+ kind: 'select',
1507
+ en: 'Model for the worker',
1508
+ bg: 'Модел за изпълнителя',
1509
+ doesEn: 'With "Two chats": the model of the second chat, the worker.',
1510
+ doesBg: 'С „Два чата“: моделът на втория чат, изпълнителя.',
1511
+ },
1512
+ {
1513
+ key: 'q.reviewModel',
1514
+ kind: 'select',
1515
+ en: 'Model for the review',
1516
+ bg: 'Модел за рецензията',
1517
+ doesEn: 'With "Review" ticked: the review\'s model; "Settings\' model" is "Model for the review".',
1518
+ doesBg: 'С отметната „Рецензия“: моделът на рецензията; „Моделът от Settings“ е „Модел за рецензията“.',
1519
+ },
1520
+ {
1521
+ key: 'q.editTitle',
1522
+ kind: 'note',
1523
+ en: 'Task {n}',
1524
+ bg: 'Задача {n}',
1525
+ doesEn: 'The form\'s heading while a task of the queue is edited, with its number.',
1526
+ doesBg: 'Заглавието на формата, докато се редактира задача от опашката, с номера ѝ.',
1527
+ },
1528
+ {
1529
+ key: 'q.prompt',
1530
+ kind: 'field',
1531
+ en: 'What the task is to do',
1532
+ bg: 'Какво трябва да направи задачата',
1533
+ doesEn: 'The task, as a message to the chat would say it; its first line is its name in the list.',
1534
+ doesBg: 'Задачата, както би я казало съобщение в чата; първият ѝ ред е името ѝ в списъка.',
1535
+ },
1536
+ {
1537
+ key: 'q.branchFolder',
1538
+ kind: 'select',
1539
+ en: 'The folder as it is',
1540
+ bg: 'Папката както е',
1541
+ doesEn: 'Of "Where it works": the task works on the branch the folder is on when it starts.',
1542
+ doesBg: 'От „Къде работи“: задачата работи на бранча, на който е папката, когато започне.',
1543
+ },
1544
+ {
1545
+ key: 'q.branchMain',
1546
+ kind: 'select',
1547
+ en: 'New branch from main',
1548
+ bg: 'Нов бранч от main',
1549
+ doesEn: 'Of "Where it works": a branch of its own made from main, where its work is committed.',
1550
+ doesBg: 'От „Къде работи“: свой бранч, направен от main, на който се commit-ва работата ѝ.',
1551
+ },
1552
+ {
1553
+ key: 'q.review',
1554
+ kind: 'checkbox',
1555
+ en: 'Review',
1556
+ bg: 'Рецензия',
1557
+ doesEn: 'A second conversation checks the task\'s work when it says it is done.',
1558
+ doesBg: 'Втори разговор проверява работата на задачата, когато тя каже, че е готова.',
1559
+ },
1560
+ {
1561
+ key: 'q.save',
1562
+ kind: 'button',
1563
+ en: 'Save',
1564
+ bg: 'Запиши',
1565
+ doesEn: 'Saves the task being edited.',
1566
+ doesBg: 'Записва редактираната задача.',
1567
+ },
1568
+ {
1569
+ key: 'q.cancel',
1570
+ kind: 'button',
1571
+ en: 'Cancel',
1572
+ bg: 'Отказ',
1573
+ doesEn: 'Leaves the task as it was and empties the form.',
1574
+ doesBg: 'Оставя задачата както е и изпразва формата.',
1575
+ },
1576
+ {
1577
+ key: 'q.model',
1578
+ kind: 'select',
1579
+ en: 'Model',
1580
+ bg: 'Модел',
1581
+ doesEn: 'The model the task\'s chat runs on, chosen by the bot; "Settings\' model" is "Model for the worker".',
1582
+ doesBg: 'Моделът, на който работи чатът на задачата, избиран от бота; „Моделът от Settings“ е „Модел за изпълнителя“.',
1583
+ },
1584
+ {
1585
+ key: 'q.branch',
1586
+ kind: 'select',
1587
+ en: 'Where it works',
1588
+ bg: 'Къде работи',
1589
+ doesEn: '"The folder as it is", or "New branch from main": a branch of its own from main, fetched from the server when that needs no password, else the local main.',
1590
+ doesBg: '„Папката както е“ или „Нов бранч от main“: свой бранч от main, взет от сървъра, ако това не иска парола, иначе от локалния main.',
1591
+ },
1592
+ {
1593
+ key: 'q.dependsOn',
1594
+ kind: 'checkbox',
1595
+ en: 'Depends on',
1596
+ bg: 'Зависи от',
1597
+ doesEn: 'The earlier tasks this one needs: when one of them fails, this one is skipped.',
1598
+ doesBg: 'По-ранните задачи, които тази изисква: ако някоя от тях се провали, тази се прескача.',
1599
+ },
1600
+ {
1601
+ key: 'q.add',
1602
+ kind: 'button',
1603
+ en: 'Add to the queue',
1604
+ bg: 'Добави в опашката',
1605
+ doesEn: 'Puts the task at the end of the queue, waiting.',
1606
+ doesBg: 'Слага задачата в края на опашката, да чака.',
1607
+ },
1608
+ ],
1609
+ },
1610
+ ],
1611
+ },
1373
1612
  {
1374
1613
  route: '/settings',
1375
1614
  nameEn: 'Settings',
@@ -1720,6 +1959,77 @@ export const SYSTEM_GUIDE = [
1720
1959
  },
1721
1960
  ],
1722
1961
  },
1962
+ {
1963
+ headingKey: 'loc.title',
1964
+ en: "The model menu's locators",
1965
+ bg: 'Локатори на менюто за модели',
1966
+ controls: [
1967
+ {
1968
+ key: 'loc.howTitle',
1969
+ kind: 'disclosure',
1970
+ en: 'How to find a locator',
1971
+ bg: 'Как да намерите локатор',
1972
+ doesEn: 'Opens the steps: open Copilot\'s model menu in Edge, F12, Elements, Ctrl+F, try the locator until it finds 1 of 1, then put {$model_name} or {$provider_name} where the name is.',
1973
+ doesBg: 'Отваря стъпките: менюто за модели на Copilot в Edge, F12, Elements, Ctrl+F, локаторът се пробва, докато намери 1 of 1, после на мястото на името се слага {$model_name} или {$provider_name}.',
1974
+ },
1975
+ {
1976
+ key: 'loc.button',
1977
+ kind: 'field',
1978
+ en: 'The model button',
1979
+ bg: 'Бутонът за модел',
1980
+ doesEn: 'How the bot finds the button that opens the model menu; empty is the default, button#gptModeSwitcher.',
1981
+ doesBg: 'Как ботът намира бутона, който отваря менюто за модели; празно е стойността по подразбиране, button#gptModeSwitcher.',
1982
+ },
1983
+ {
1984
+ key: 'loc.rows',
1985
+ kind: 'field',
1986
+ en: 'The rows of the menu',
1987
+ bg: 'Редовете на менюто',
1988
+ doesEn: 'The rows "Read the list from Copilot" reads the names of the models and the providers from.',
1989
+ doesBg: 'Редовете, от които „Прочети списъка от Copilot“ чете имената на моделите и на provider-ите.',
1990
+ },
1991
+ {
1992
+ key: 'loc.model',
1993
+ kind: 'field',
1994
+ en: 'A model of the main menu',
1995
+ bg: 'Модел от основното меню',
1996
+ doesEn: 'The template for a model of the main menu (Auto, Think deeper…), with {$model_name} where the name goes.',
1997
+ doesBg: 'Шаблонът за модел от основното меню (Auto, Think deeper…), с {$model_name} на мястото на името.',
1998
+ },
1999
+ {
2000
+ key: 'loc.provider',
2001
+ kind: 'field',
2002
+ en: 'A provider',
2003
+ bg: 'Provider',
2004
+ doesEn: 'The template for a provider\'s row that opens its own menu (Claude, GPT…), with {$provider_name} where the name goes.',
2005
+ doesBg: 'Шаблонът за реда на provider, който отваря свое меню (Claude, GPT…), с {$provider_name} на мястото на името.',
2006
+ },
2007
+ {
2008
+ key: 'loc.providerModel',
2009
+ kind: 'field',
2010
+ en: 'A model of a provider',
2011
+ bg: 'Модел от provider',
2012
+ doesEn: 'The template for a model in a provider\'s menu (Opus 5.5…), with {$model_name} where the name goes.',
2013
+ doesBg: 'Шаблонът за модел в менюто на provider (Opus 5.5…), с {$model_name} на мястото на името.',
2014
+ },
2015
+ {
2016
+ key: 'loc.default',
2017
+ kind: 'button',
2018
+ en: 'Default',
2019
+ bg: 'По подразбиране',
2020
+ doesEn: 'Empties the field beside it: the default is used again.',
2021
+ doesBg: 'Изпразва полето до него: отново се ползва стойността по подразбиране.',
2022
+ },
2023
+ {
2024
+ key: 'loc.steps',
2025
+ kind: 'checkbox',
2026
+ en: 'Keep a picture of every step of choosing a model',
2027
+ bg: 'Пази снимка на всяка стъпка от избора на модел',
2028
+ doesEn: 'Keeps a picture of the page and the menu\'s HTML at every step of choosing a model, in the folders named under it; a failed choice keeps models-select-failed.* always.',
2029
+ doesBg: 'Пази снимка на страницата и HTML на менюто на всяка стъпка от избора на модел, в папките, посочени под него; неуспешен избор винаги пази models-select-failed.*.',
2030
+ },
2031
+ ],
2032
+ },
1723
2033
  {
1724
2034
  headingKey: 'exec.title',
1725
2035
  en: 'Execution',
@@ -2005,6 +2315,22 @@ export const SYSTEM_GUIDE = [
2005
2315
  doesEn: 'Under "This machine": the latest lines the bot\'s console printed, with their times, as a text file — what to ask for when something went wrong and nothing on the pages says why.',
2006
2316
  doesBg: 'Под „Тази машина“: последните редове, отпечатани от конзолата на бота, с часовете им, като текстов файл — това се иска, когато нещо се е объркало и нищо по страниците не казва защо.',
2007
2317
  },
2318
+ {
2319
+ key: 'sys.export',
2320
+ kind: 'note',
2321
+ en: 'Export everything the bot keeps',
2322
+ bg: 'Експорт на всичко, което ботът пази',
2323
+ doesEn: 'Under "This machine": one .zip of the bot\'s folder — settings, conversations, skills, level 2 templates, logs — with a checkbox for every run\'s records too; the API\'s key and the Edge profile (the Microsoft 365 sign-in) are never in it, and its manifest.json says so.',
2324
+ doesBg: 'Под „Тази машина“: един .zip на папката на бота — настройки, разговори, skill-ове, шаблони за ниво 2, дневници — с отметка и за записите на всички изпълнения; ключът на API-то и профилът в Edge (входът в Microsoft 365) никога не влизат, и manifest.json го казва.',
2325
+ },
2326
+ {
2327
+ key: 'sys.exportButton',
2328
+ kind: 'link',
2329
+ en: 'Export (.zip)',
2330
+ bg: 'Експорт (.zip)',
2331
+ doesEn: 'Downloads that .zip, named copilot-operator-export-<date>-<time>.zip.',
2332
+ doesBg: 'Сваля този .zip с име copilot-operator-export-<дата>-<час>.zip.',
2333
+ },
2008
2334
  {
2009
2335
  key: 'sys.home',
2010
2336
  kind: 'note',
@@ -0,0 +1,160 @@
1
+ /**
2
+ * The queue of tasks (operator, 2026-10-24: "an option to prepare several tasks that run in a queue"): tasks written
3
+ * beforehand, each with its own model, run one after another while nobody watches, each in a new chat.
4
+ *
5
+ * The operator's rules, as they asked for them:
6
+ *
7
+ * - each task in a new chat, on its own model (empty: "Model for the worker" in Settings), chosen by the bot;
8
+ * - a task may depend on earlier ones, chosen task by task. When one fails, every task that depends on it — or on a
9
+ * task skipped for it — is skipped, and the queue goes on with the next one that does not;
10
+ * - a task works in the folder as it is, or on a new branch made from main. The server's main is fetched without a
11
+ * password or a key's passphrase, which nobody is there to type; when it cannot be, the local main is used, and the
12
+ * chat is told which it was.
13
+ *
14
+ * Kept as `data/queue.json` (see `OperatorService.queue`). This module is the part that needs no browser: the shape,
15
+ * the checks of an edit, and which task is next.
16
+ */
17
+ import { branchExists } from '../vcs/git.js';
18
+ export const MAX_QUEUE_ITEMS = 50;
19
+ export function emptyQueue() {
20
+ return { items: [], running: false, updatedAt: new Date().toISOString() };
21
+ }
22
+ /** A task's name, or its first line where it has none. */
23
+ export function itemTitle(item) {
24
+ return item.name?.trim() || item.prompt.split(/\r?\n/)[0].trim().slice(0, 80) || 'task';
25
+ }
26
+ export const MAX_QUEUE_NAME = 80;
27
+ /** An edit of the list as the page sends it, held to the rules, or the sentence that says why it cannot be. */
28
+ export function checkItems(items, maxPromptChars) {
29
+ if (!Array.isArray(items))
30
+ return { problem: 'The queue comes as a list of tasks.' };
31
+ if (items.length > MAX_QUEUE_ITEMS)
32
+ return { problem: `A queue holds at most ${MAX_QUEUE_ITEMS} tasks.` };
33
+ const seen = new Set();
34
+ const out = [];
35
+ for (const [i, raw] of items.entries()) {
36
+ const x = (raw ?? {});
37
+ const n = i + 1;
38
+ const id = String(x.id ?? '').trim();
39
+ if (!/^[a-z0-9-]{1,40}$/i.test(id))
40
+ return { problem: `Task ${n} has no id the queue can keep.` };
41
+ if (seen.has(id))
42
+ return { problem: `Two tasks have the id "${id}".` };
43
+ const prompt = String(x.prompt ?? '').trim();
44
+ if (!prompt)
45
+ return { problem: `Task ${n} says nothing: write what it is to do.` };
46
+ if (prompt.length > maxPromptChars)
47
+ return { problem: `Task ${n} is ${prompt.length} characters; a task can be at most ${maxPromptChars}.` };
48
+ const dependsOn = Array.isArray(x.dependsOn) ? [...new Set(x.dependsOn.map((d) => String(d)))] : [];
49
+ // On earlier tasks only: they run first, so a task never waits for one after it, and never for itself.
50
+ const late = dependsOn.find((d) => !seen.has(d));
51
+ if (late)
52
+ return { problem: `Task ${n} depends on ${items.some((o) => o?.id === late) ? 'a task after it' : `"${late}", which is not in the queue`}: a task can depend only on tasks before it.` };
53
+ const branch = x.branch === 'main' ? 'main' : 'folder';
54
+ const status = typeof x.status === 'string' && ['waiting', 'running', 'done', 'failed', 'skipped', 'stopped'].includes(x.status) ? x.status : undefined;
55
+ const text = (v) => String(v ?? '').trim();
56
+ const name = text(x.name);
57
+ if (name.length > MAX_QUEUE_NAME)
58
+ return { problem: `The name of task ${n} is longer than ${MAX_QUEUE_NAME} characters.` };
59
+ const lead = x.lead === true;
60
+ out.push({
61
+ id,
62
+ ...(name ? { name } : {}),
63
+ prompt,
64
+ model: text(x.model),
65
+ dependsOn,
66
+ branch,
67
+ // With two chats the lead judges the worker's reports: no review of its own, as in the chat.
68
+ review: !lead && x.review !== false,
69
+ ...(!lead && text(x.reviewModel) ? { reviewModel: text(x.reviewModel) } : {}),
70
+ ...(lead ? { lead: true } : {}),
71
+ ...(lead && text(x.workerModel) ? { workerModel: text(x.workerModel) } : {}),
72
+ ...(status ? { status } : {}),
73
+ });
74
+ seen.add(id);
75
+ }
76
+ return { items: out };
77
+ }
78
+ /**
79
+ * The list as edited, onto the queue as it is: a task already there keeps what the runs gave it — its status, why,
80
+ * its chat — unless it is being put back to wait ("Run again"); a task that is running is kept as it is, whatever
81
+ * the edit says; a new one waits.
82
+ */
83
+ export function mergeItems(current, edited) {
84
+ const before = new Map(current.map((x) => [x.id, x]));
85
+ const running = current.find((x) => x.status === 'running');
86
+ if (running && !edited.some((x) => x.id === running.id))
87
+ return { problem: `"${itemTitle(running)}" is running: stop the queue before taking it out.` };
88
+ const items = edited.map((x) => {
89
+ const was = before.get(x.id);
90
+ if (was?.status === 'running')
91
+ return was;
92
+ if (!was)
93
+ return { ...x, status: 'waiting' };
94
+ const again = x.status === 'waiting' && was.status !== 'waiting';
95
+ const given = asGiven(x);
96
+ if (again)
97
+ return { ...given, status: 'waiting' };
98
+ // What the runs gave it stays; what the operator gives it is the edit's, a field left out of it gone.
99
+ const kept = { ...was };
100
+ for (const key of GIVEN)
101
+ delete kept[key];
102
+ return { ...kept, ...given, status: was.status };
103
+ });
104
+ return { items };
105
+ }
106
+ /** What the operator gives a task, apart from what its runs give it. */
107
+ const GIVEN = ['id', 'name', 'prompt', 'model', 'dependsOn', 'branch', 'review', 'reviewModel', 'lead', 'workerModel'];
108
+ function asGiven(x) {
109
+ const out = {};
110
+ for (const key of GIVEN)
111
+ if (x[key] !== undefined)
112
+ out[key] = x[key];
113
+ return out;
114
+ }
115
+ /**
116
+ * Which of a task's conversations would wait for a model to be chosen by hand, and nobody is there to: its own (the
117
+ * lead's, with two chats) with no model of its own and none in Settings, and its review with none of its own and no
118
+ * "Model for the review" in Settings — a chat that names no model is asked for it by hand (`modelByHand`). The worker
119
+ * of two chats never does: with no model of its own or in Settings, it is on the lead's.
120
+ */
121
+ export function waitsByHand(item, copilot) {
122
+ const set = (v) => !!v?.trim();
123
+ const settingsModel = item.lead ? set(copilot.defaultLeadModel) || set(copilot.defaultModel) : set(copilot.defaultModel);
124
+ return [
125
+ ...(!set(item.model) && !settingsModel ? ['model'] : []),
126
+ ...(!item.lead && item.review && !set(item.reviewModel) && !set(copilot.defaultReviewModel) ? ['review'] : []),
127
+ ];
128
+ }
129
+ /**
130
+ * What the queue does next: run the first task that waits, or skip it when a task it depends on did not end done
131
+ * (failed, was skipped, was stopped); nothing when no task waits.
132
+ */
133
+ export function nextStep(items) {
134
+ const byId = new Map(items.map((x) => [x.id, x]));
135
+ for (const item of items) {
136
+ if (item.status !== 'waiting')
137
+ continue;
138
+ const blocker = item.dependsOn.map((d) => byId.get(d)).find((d) => !d || d.status !== 'done');
139
+ if (blocker)
140
+ return { skip: item, because: blocker };
141
+ return { run: item };
142
+ }
143
+ return null;
144
+ }
145
+ /** Why a task is skipped, in a sentence. */
146
+ export function skippedBecause(because) {
147
+ const what = because.status === 'failed' ? 'failed' : because.status === 'stopped' ? 'was stopped' : because.status === 'skipped' ? 'was skipped' : `has not run (${because.status})`;
148
+ return `it depends on "${itemTitle(because)}", which ${what}`;
149
+ }
150
+ /** A task's status from how its message ended. */
151
+ export function statusOfTask(taskStatus) {
152
+ return taskStatus === 'done' ? 'done' : taskStatus === 'aborted' ? 'stopped' : 'failed';
153
+ }
154
+ /** The branch a task "on a new branch from main" starts from: `main`, else `master`, as the repository has it. */
155
+ export async function mainBranchOf(dir) {
156
+ for (const name of ['main', 'master'])
157
+ if (await branchExists(dir, name))
158
+ return name;
159
+ return null;
160
+ }