@skillcdn/console 0.5.1 → 0.5.2

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 (288) hide show
  1. package/README.md +20 -2
  2. package/dist/agent-page.d.ts.map +1 -1
  3. package/dist/agent-page.js +4 -4
  4. package/dist/agent-page.js.map +1 -1
  5. package/dist/api.d.ts +5 -4
  6. package/dist/api.d.ts.map +1 -1
  7. package/dist/api.js +5 -4
  8. package/dist/api.js.map +1 -1
  9. package/dist/cli/cli.d.ts +32 -0
  10. package/dist/cli/cli.d.ts.map +1 -1
  11. package/dist/cli/cli.js +442 -93
  12. package/dist/cli/cli.js.map +1 -1
  13. package/dist/cli/format.d.ts +6 -2
  14. package/dist/cli/format.d.ts.map +1 -1
  15. package/dist/cli/format.js +25 -3
  16. package/dist/cli/format.js.map +1 -1
  17. package/dist/cli/help.d.ts.map +1 -1
  18. package/dist/cli/help.js +10 -5
  19. package/dist/cli/help.js.map +1 -1
  20. package/dist/cli/machine-check.d.ts +36 -0
  21. package/dist/cli/machine-check.d.ts.map +1 -0
  22. package/dist/cli/machine-check.js +151 -0
  23. package/dist/cli/machine-check.js.map +1 -0
  24. package/dist/cli/runner-host.d.ts +7 -0
  25. package/dist/cli/runner-host.d.ts.map +1 -1
  26. package/dist/cli/runner-host.js +2 -0
  27. package/dist/cli/runner-host.js.map +1 -1
  28. package/dist/cli/secret-notes.d.ts +8 -0
  29. package/dist/cli/secret-notes.d.ts.map +1 -0
  30. package/dist/cli/secret-notes.js +48 -0
  31. package/dist/cli/secret-notes.js.map +1 -0
  32. package/dist/client.d.ts +7 -1
  33. package/dist/client.d.ts.map +1 -1
  34. package/dist/client.js +6 -1
  35. package/dist/client.js.map +1 -1
  36. package/dist/components/agent-page.d.ts +106 -13
  37. package/dist/components/agent-page.d.ts.map +1 -1
  38. package/dist/components/agent-page.js +391 -102
  39. package/dist/components/agent-page.js.map +1 -1
  40. package/dist/components/agents.d.ts.map +1 -1
  41. package/dist/components/agents.js +1 -1
  42. package/dist/components/agents.js.map +1 -1
  43. package/dist/components/board.d.ts.map +1 -1
  44. package/dist/components/board.js +3 -2
  45. package/dist/components/board.js.map +1 -1
  46. package/dist/components/categories.js +1 -1
  47. package/dist/components/categories.js.map +1 -1
  48. package/dist/components/decision-list.d.ts.map +1 -1
  49. package/dist/components/decision-list.js +1 -1
  50. package/dist/components/decision-list.js.map +1 -1
  51. package/dist/components/event-feed.d.ts.map +1 -1
  52. package/dist/components/event-feed.js +3 -2
  53. package/dist/components/event-feed.js.map +1 -1
  54. package/dist/components/goals.d.ts +2 -0
  55. package/dist/components/goals.d.ts.map +1 -1
  56. package/dist/components/goals.js +1 -1
  57. package/dist/components/goals.js.map +1 -1
  58. package/dist/components/home.d.ts.map +1 -1
  59. package/dist/components/home.js +12 -6
  60. package/dist/components/home.js.map +1 -1
  61. package/dist/components/icon.d.ts +31 -0
  62. package/dist/components/icon.d.ts.map +1 -0
  63. package/dist/components/icon.js +169 -0
  64. package/dist/components/icon.js.map +1 -0
  65. package/dist/components/markdown.d.ts +6 -0
  66. package/dist/components/markdown.d.ts.map +1 -1
  67. package/dist/components/markdown.js +10 -2
  68. package/dist/components/markdown.js.map +1 -1
  69. package/dist/components/people.js +1 -1
  70. package/dist/components/people.js.map +1 -1
  71. package/dist/components/plugin-frame.d.ts.map +1 -1
  72. package/dist/components/plugin-frame.js +7 -0
  73. package/dist/components/plugin-frame.js.map +1 -1
  74. package/dist/components/projects.d.ts +17 -4
  75. package/dist/components/projects.d.ts.map +1 -1
  76. package/dist/components/projects.js +25 -6
  77. package/dist/components/projects.js.map +1 -1
  78. package/dist/components/sessions.d.ts.map +1 -1
  79. package/dist/components/sessions.js +3 -2
  80. package/dist/components/sessions.js.map +1 -1
  81. package/dist/components/setup.d.ts.map +1 -1
  82. package/dist/components/setup.js +2 -2
  83. package/dist/components/setup.js.map +1 -1
  84. package/dist/components/shell.d.ts.map +1 -1
  85. package/dist/components/shell.js +3 -2
  86. package/dist/components/shell.js.map +1 -1
  87. package/dist/components/tokens.js +1 -1
  88. package/dist/components/tokens.js.map +1 -1
  89. package/dist/components/ui.d.ts +5 -2
  90. package/dist/components/ui.d.ts.map +1 -1
  91. package/dist/components/ui.js +10 -7
  92. package/dist/components/ui.js.map +1 -1
  93. package/dist/connect-page.js +1 -1
  94. package/dist/connect-page.js.map +1 -1
  95. package/dist/console.css +473 -77
  96. package/dist/console.d.ts.map +1 -1
  97. package/dist/console.js +38 -31
  98. package/dist/console.js.map +1 -1
  99. package/dist/home-tiles.d.ts +9 -0
  100. package/dist/home-tiles.d.ts.map +1 -1
  101. package/dist/home-tiles.js +105 -23
  102. package/dist/home-tiles.js.map +1 -1
  103. package/dist/i18n/en.d.ts +48 -1
  104. package/dist/i18n/en.d.ts.map +1 -1
  105. package/dist/i18n/en.js +125 -2
  106. package/dist/i18n/en.js.map +1 -1
  107. package/dist/i18n/ko.d.ts.map +1 -1
  108. package/dist/i18n/ko.js +197 -79
  109. package/dist/i18n/ko.js.map +1 -1
  110. package/dist/i18n/particles.d.ts +7 -0
  111. package/dist/i18n/particles.d.ts.map +1 -0
  112. package/dist/i18n/particles.js +72 -0
  113. package/dist/i18n/particles.js.map +1 -0
  114. package/dist/icons/glyphs.d.ts +605 -0
  115. package/dist/icons/glyphs.d.ts.map +1 -0
  116. package/dist/icons/glyphs.js +104 -0
  117. package/dist/icons/glyphs.js.map +1 -0
  118. package/dist/icons/index.d.ts +59 -0
  119. package/dist/icons/index.d.ts.map +1 -0
  120. package/dist/icons/index.js +157 -0
  121. package/dist/icons/index.js.map +1 -0
  122. package/dist/index.d.ts +1 -0
  123. package/dist/index.d.ts.map +1 -1
  124. package/dist/index.js +1 -0
  125. package/dist/index.js.map +1 -1
  126. package/dist/limits.d.ts +9 -0
  127. package/dist/limits.d.ts.map +1 -1
  128. package/dist/limits.js +9 -0
  129. package/dist/limits.js.map +1 -1
  130. package/dist/marks.d.ts +9 -0
  131. package/dist/marks.d.ts.map +1 -1
  132. package/dist/marks.js +9 -0
  133. package/dist/marks.js.map +1 -1
  134. package/dist/onboarding.js +3 -3
  135. package/dist/onboarding.js.map +1 -1
  136. package/dist/plugin/web.d.ts +3 -0
  137. package/dist/plugin/web.d.ts.map +1 -1
  138. package/dist/plugin/web.js +5 -1
  139. package/dist/plugin/web.js.map +1 -1
  140. package/dist/runner/acp.d.ts.map +1 -1
  141. package/dist/runner/acp.js +2 -2
  142. package/dist/runner/acp.js.map +1 -1
  143. package/dist/runner/awake.d.ts +35 -0
  144. package/dist/runner/awake.d.ts.map +1 -0
  145. package/dist/runner/awake.js +95 -0
  146. package/dist/runner/awake.js.map +1 -0
  147. package/dist/runner/claude.d.ts.map +1 -1
  148. package/dist/runner/claude.js +19 -7
  149. package/dist/runner/claude.js.map +1 -1
  150. package/dist/runner/codex.d.ts.map +1 -1
  151. package/dist/runner/codex.js +2 -2
  152. package/dist/runner/codex.js.map +1 -1
  153. package/dist/runner/config.d.ts +5 -0
  154. package/dist/runner/config.d.ts.map +1 -1
  155. package/dist/runner/config.js +9 -0
  156. package/dist/runner/config.js.map +1 -1
  157. package/dist/runner/desk.d.ts.map +1 -1
  158. package/dist/runner/desk.js +5 -6
  159. package/dist/runner/desk.js.map +1 -1
  160. package/dist/runner/runner.d.ts +13 -2
  161. package/dist/runner/runner.d.ts.map +1 -1
  162. package/dist/runner/runner.js +141 -22
  163. package/dist/runner/runner.js.map +1 -1
  164. package/dist/runner/slack.d.ts.map +1 -1
  165. package/dist/runner/slack.js +10 -4
  166. package/dist/runner/slack.js.map +1 -1
  167. package/dist/runner/types.d.ts +15 -0
  168. package/dist/runner/types.d.ts.map +1 -1
  169. package/dist/runner/types.js +9 -0
  170. package/dist/runner/types.js.map +1 -1
  171. package/dist/schemas.d.ts +94 -1
  172. package/dist/schemas.d.ts.map +1 -1
  173. package/dist/schemas.js +81 -5
  174. package/dist/schemas.js.map +1 -1
  175. package/dist/services.d.ts.map +1 -1
  176. package/dist/services.js +9 -5
  177. package/dist/services.js.map +1 -1
  178. package/dist/setup-guide.d.ts +14 -3
  179. package/dist/setup-guide.d.ts.map +1 -1
  180. package/dist/setup-guide.js +41 -37
  181. package/dist/setup-guide.js.map +1 -1
  182. package/dist/tokens.d.ts.map +1 -1
  183. package/dist/tokens.js +5 -1
  184. package/dist/tokens.js.map +1 -1
  185. package/dist/vocabulary.d.ts +7 -0
  186. package/dist/vocabulary.d.ts.map +1 -1
  187. package/dist/vocabulary.js +6 -0
  188. package/dist/vocabulary.js.map +1 -1
  189. package/docs/specs/cli.md +10 -7
  190. package/docs/specs/plugins.md +17 -6
  191. package/docs/specs/rest.md +10 -8
  192. package/docs/specs/runner.md +26 -8
  193. package/package.json +7 -3
  194. package/skills/building-a-console/SKILL.md +2 -2
  195. package/skills/building-a-plugin/SKILL.md +2 -2
  196. package/skills/keeping-a-desk/SKILL.md +2 -2
  197. package/skills/running-an-agent/SKILL.md +47 -57
  198. package/skills/working-the-board/SKILL.md +5 -4
  199. package/skills/working-the-board/references/the-pack.md +1 -1
  200. package/src/agent-page.tsx +13 -1
  201. package/src/api.ts +32 -1
  202. package/src/cli/cli.ts +530 -106
  203. package/src/cli/format.ts +31 -3
  204. package/src/cli/help.ts +12 -4
  205. package/src/cli/machine-check.ts +223 -0
  206. package/src/cli/runner-host.ts +8 -0
  207. package/src/cli/secret-notes.ts +63 -0
  208. package/src/client.ts +23 -0
  209. package/src/components/agent-page.tsx +629 -112
  210. package/src/components/agents.tsx +9 -5
  211. package/src/components/board.tsx +3 -15
  212. package/src/components/categories.tsx +2 -2
  213. package/src/components/decision-list.tsx +11 -7
  214. package/src/components/event-feed.tsx +7 -2
  215. package/src/components/goals.tsx +33 -25
  216. package/src/components/home.tsx +30 -6
  217. package/src/components/icon.tsx +337 -0
  218. package/src/components/markdown.tsx +22 -2
  219. package/src/components/people.tsx +1 -1
  220. package/src/components/plugin-frame.tsx +7 -0
  221. package/src/components/projects.tsx +39 -5
  222. package/src/components/sessions.tsx +2 -13
  223. package/src/components/setup.tsx +2 -2
  224. package/src/components/shell.tsx +3 -20
  225. package/src/components/tokens.tsx +1 -1
  226. package/src/components/ui.tsx +16 -8
  227. package/src/connect-page.tsx +1 -1
  228. package/src/console.tsx +87 -53
  229. package/src/home-tiles.ts +127 -23
  230. package/src/i18n/en.ts +127 -2
  231. package/src/i18n/ko.ts +200 -79
  232. package/src/i18n/particles.ts +79 -0
  233. package/src/icons/glyphs.ts +112 -0
  234. package/src/icons/index.ts +195 -0
  235. package/src/index.ts +7 -0
  236. package/src/limits.ts +9 -0
  237. package/src/marks.ts +12 -0
  238. package/src/onboarding.ts +3 -3
  239. package/src/plugin/web.ts +9 -2
  240. package/src/runner/acp.ts +2 -1
  241. package/src/runner/awake.ts +135 -0
  242. package/src/runner/claude.ts +19 -4
  243. package/src/runner/codex.ts +2 -1
  244. package/src/runner/config.ts +9 -0
  245. package/src/runner/desk.ts +5 -6
  246. package/src/runner/runner.ts +183 -23
  247. package/src/runner/slack.ts +10 -4
  248. package/src/runner/types.ts +20 -0
  249. package/src/schemas.ts +94 -3
  250. package/src/services.ts +9 -5
  251. package/src/setup-guide.ts +43 -38
  252. package/src/styles/README.md +5 -4
  253. package/src/styles/base.css +17 -0
  254. package/src/styles/console.css +1 -0
  255. package/src/styles/drawn-by-pages.json +1 -1
  256. package/src/styles/pages/agents.css +103 -1
  257. package/src/styles/pages/board.css +0 -10
  258. package/src/styles/pages/calendar.css +1 -1
  259. package/src/styles/pages/connect.css +0 -10
  260. package/src/styles/pages/decisions.css +3 -1
  261. package/src/styles/pages/feed.css +5 -2
  262. package/src/styles/pages/home.css +5 -0
  263. package/src/styles/pages/roadmap.css +2 -2
  264. package/src/styles/pages/settings.css +11 -0
  265. package/src/styles/pages/task.css +0 -20
  266. package/src/styles/pages/thread.css +1 -1
  267. package/src/styles/parts/calendar.css +1 -1
  268. package/src/styles/parts/callout.css +1 -0
  269. package/src/styles/parts/detail.css +22 -0
  270. package/src/styles/parts/empty.css +2 -0
  271. package/src/styles/parts/eyebrow.css +1 -1
  272. package/src/styles/parts/facts.css +1 -1
  273. package/src/styles/parts/figures.css +1 -1
  274. package/src/styles/parts/form.css +2 -1
  275. package/src/styles/parts/icon.css +191 -0
  276. package/src/styles/parts/input.css +14 -4
  277. package/src/styles/parts/mark.css +36 -0
  278. package/src/styles/parts/menu.css +1 -7
  279. package/src/styles/parts/page.css +1 -1
  280. package/src/styles/parts/panel.css +10 -0
  281. package/src/styles/parts/person.css +5 -2
  282. package/src/styles/parts/progress.css +5 -2
  283. package/src/styles/parts/rows.css +1 -0
  284. package/src/styles/parts/settings.css +5 -0
  285. package/src/styles/parts/stat.css +1 -1
  286. package/src/styles/tokens.css +22 -7
  287. package/src/tokens.ts +5 -1
  288. package/src/vocabulary.ts +9 -0
package/dist/cli/cli.js CHANGED
@@ -8,16 +8,18 @@ import { ApiError, createClient, } from "../client.js";
8
8
  import { CLIENT_RANGE_HEADER, CONSOLE_AT_LEAST, consoleRange, formatRange, judgeClient, judgeConsole, parseVersion, VERSION_HEADER, formatVersion as versionText, } from "../compat.js";
9
9
  import { normalizeConnectCode } from "../connect.js";
10
10
  import { addDays, dayOf as dayOfDate, firstDayOfWeek, isDay, weekOf } from "../dates.js";
11
- import { DEFAULT_PAGE_LIMIT, EVENTS_PAGE_LIMIT, LIST_LIMIT, MAX_DECIDERS, MAX_OPTIONS, MAX_RUNNER_LINE_LENGTH, MAX_SIGNALS_PAGE_LIMIT, MIN_OPTIONS, } from "../limits.js";
11
+ import { ICON_NAMES, isIconName } from "../icons/index.js";
12
+ import { DEFAULT_PAGE_LIMIT, EVENTS_PAGE_LIMIT, LIST_LIMIT, MAX_DECIDERS, MAX_OPTIONS, MAX_OWN_WAKE_DAYS, MAX_RUNNER_LINE_LENGTH, MAX_SIGNALS_PAGE_LIMIT, MIN_OPTIONS, OWN_WAKE_KEY, } from "../limits.js";
13
+ import { onboardingTitle } from "../onboarding.js";
12
14
  import { capabilityWords } from "../plugin/capabilities.js";
13
15
  import { PLUGIN_LIST_LIMIT } from "../plugin/limits.js";
14
16
  import { checkRecords, RECORDS_DIR, RECORDS_INDEX_FILE } from "../records.js";
15
- import { decisionHref, docHref, myDecisionHref, taskHref } from "../router.js";
17
+ import { agentHref, decisionHref, docHref, myDecisionHref, taskHref } from "../router.js";
16
18
  import { fillRules, RULES_PATH, RULES_TITLE } from "../rules.js";
17
19
  import { DEFAULT_RUNNER_CONFIG, parseRunnerConfig } from "../runner/config.js";
18
20
  import { DESK_FOLDER, deskFiles, deskServicesOf, deskWebTitleOf, personDeskFiles, } from "../runner/desk.js";
19
21
  import { ownRunnerModules } from "../runner/modules.js";
20
- import { createRunner, GIT_TOKEN_SECRET } from "../runner/runner.js";
22
+ import { createRunner, GIT_TOKEN_SECRET, } from "../runner/runner.js";
21
23
  import { hostOfLogin, } from "../schemas.js";
22
24
  import { agentLoginOf, deskRemoteOf } from "../services.js";
23
25
  import { setupGuideOf, setupGuideText, setupSentenceOf } from "../setup-guide.js";
@@ -26,11 +28,13 @@ import { loadWebRoot, WebRootError } from "../web.js";
26
28
  import { commandLine, commandWord, NO_LINE_TO_RUN } from "./command-words.js";
27
29
  import { CredentialsError, EMPTY_CREDENTIALS, fitsFile, keepsNothing, lasts, loginsAt, pendingAt, resolveLogin, withLogin, withoutLogin, withoutPending, withPending, } from "./credentials.js";
28
30
  import { DIRECTORY_FILE, THE_SENTENCE, } from "./directory.js";
29
- import { calledOf, deciderLogins, formatAgent, formatAgentLine, formatAnswer, formatCategoryLine, formatComment, formatDecision, formatDecisionLine, formatDocument, formatDocuments, formatGoal, formatGoalLine, formatInvocation, formatListingLine, formatMemberLine, formatMore, formatOptions, formatPersonLine, formatPersonWork, formatPlugin, formatPluginAsks, formatPluginEvents, formatPluginGrantLine, formatPluginHelp, formatPluginRecord, formatPluginRecords, formatPluginRecordVersions, formatPluginSettingLine, formatPlugins, formatProject, formatProjectLine, formatRules, formatRulesChanged, formatRulesLeftOut, formatRun, formatRunLine, formatSecretLine, formatSignalLine, formatTask, formatTaskLine, formatTeamLine, formatVersion, formatVersionLine, formatWork, formatWorkspace, localized, moment, pageLine, rulesMark, setMomentZone, } from "./format.js";
31
+ import { calledOf, deciderLogins, formatAgent, formatAgentLine, formatAnswer, formatCategoryLine, formatComment, formatDecision, formatDecisionLine, formatDocument, formatDocuments, formatGoal, formatGoalLine, formatInvocation, formatListingLine, formatMemberLine, formatMore, formatOptions, formatOwnWakeLine, formatPersonLine, formatPersonWork, formatPlugin, formatPluginAsks, formatPluginEvents, formatPluginGrantLine, formatPluginHelp, formatPluginRecord, formatPluginRecords, formatPluginRecordVersions, formatPluginSettingLine, formatPlugins, formatProject, formatProjectLine, formatRules, formatRulesChanged, formatRulesLeftOut, formatRun, formatRunLine, formatSecretLine, formatSignalLine, formatTask, formatTaskLine, formatTeamLine, formatVersion, formatVersionLine, formatWork, formatWorkspace, localized, moment, pageLine, rulesMark, setMomentZone, } from "./format.js";
30
32
  import { COMMAND_HELP, helpFor, ownSkillPath, usage } from "./help.js";
31
33
  import { describeInstall, updateCommandFor } from "./install.js";
34
+ import { awakeWords, heldAwake, lookAtMachine } from "./machine-check.js";
32
35
  import { consolePack, formatSkills, holdsNothing, ORGANIZATION_PACK_LINE, PackRefusal, packWords, refusalWords, skillPathIn, } from "./pack.js";
33
36
  import { workPath } from "./runner-host.js";
37
+ import { secretNotes } from "./secret-notes.js";
34
38
  import { createServeHandler, DEFAULT_SERVE_PORT, loadRecordsRoot, RecordsRootError, } from "./serve.js";
35
39
  // The `console` command (docs/specs/cli.md): the agent's side of the console. A thin client of
36
40
  // the REST API with no logic of its own: every command is one or two requests and the words to
@@ -3440,6 +3444,10 @@ const serve = async (args, io) => {
3440
3444
  throw error;
3441
3445
  }
3442
3446
  }
3447
+ // Whether the records are there is asked before anything listens: the line says what the
3448
+ // command found when it began. Asked after, a directory made in the moment between, by a
3449
+ // session that began keeping something as the pages came up, read as there all along.
3450
+ const recordsThere = records === undefined ? false : await records.there();
3443
3451
  const listening = await listen((bound) => createServeHandler({
3444
3452
  upstream: session.url,
3445
3453
  token: session.token,
@@ -3452,7 +3460,7 @@ const serve = async (args, io) => {
3452
3460
  // nothing is kept there, and that what comes to be is served with no restart.
3453
3461
  const served = kept === undefined || records === undefined
3454
3462
  ? ""
3455
- : (await records.there())
3463
+ : recordsThere
3456
3464
  ? ` The records in ${kept} are at ${listening.url}records/, read as they are when they are asked for.`
3457
3465
  : ` Nothing is kept in ${kept} yet: what comes to be kept there is at ${listening.url}records/ from then on, with no restart.`;
3458
3466
  io.stdout(web === undefined
@@ -3503,6 +3511,41 @@ const machineLine = (text) => {
3503
3511
  .slice(0, MAX_RUNNER_LINE_LENGTH);
3504
3512
  return line.length === 0 ? "unknown" : line;
3505
3513
  };
3514
+ /**
3515
+ * Keeps a runner going across its `runner.json` (ADR-0144): a runner that ended for its file is
3516
+ * followed by another, begun with the file as it is now, in this process. Where the file stopped
3517
+ * reading in between, the agent having written it again in the turn that was under way, the next
3518
+ * runner begins with the file as it last read, so that there is always one: it then says what is
3519
+ * wrong with the file to the agent, whose session it is the only way to. Answers how the last
3520
+ * runner ended, once one ended for anything else or whoever runs the command asked it to stop.
3521
+ */
3522
+ export async function keepRunning(input) {
3523
+ let good = input.first;
3524
+ let running = input.start(good);
3525
+ let asked = false;
3526
+ void input.stopped.then(() => {
3527
+ asked = true;
3528
+ running.stop();
3529
+ });
3530
+ for (;;) {
3531
+ const how = await running.run();
3532
+ if (how !== "changed" || asked) {
3533
+ return how;
3534
+ }
3535
+ const next = await input.read();
3536
+ if (next.ok) {
3537
+ good = next.config;
3538
+ }
3539
+ else {
3540
+ input.say(`${next.problem}: the runner starts again with the runner.json it last read`);
3541
+ }
3542
+ running = input.start(good);
3543
+ // Asked to stop while the file was read: the runner just begun ends at once.
3544
+ if (asked) {
3545
+ running.stop();
3546
+ }
3547
+ }
3548
+ }
3506
3549
  // The runner of an agent account (ADR-0085, docs/specs/runner.md): started in the account's
3507
3550
  // desk, on the command signed in as the account itself. It keeps the agent's session going,
3508
3551
  // feeds it what the console sends and reports what it does, until it is stopped.
@@ -3523,22 +3566,35 @@ const runner = async (args, io) => {
3523
3566
  if (me.person.kind !== "agent" || me.session?.kind !== "command") {
3524
3567
  throw failed("A runner is an agent account's own, on the command signed in as the account itself: console login --self, approved in a browser signed in as the account.");
3525
3568
  }
3526
- const written = await host.readText("runner.json");
3527
- const read = written === undefined
3528
- ? { ok: true, config: DEFAULT_RUNNER_CONFIG }
3529
- : parseRunnerConfig(written);
3530
- if (!read.ok) {
3531
- throw failed(`${read.problem}. Nothing of it is used: put it right, or remove it to run with the defaults.`);
3532
- }
3533
3569
  const modules = ownRunnerModules({ user: host.user });
3534
- const driverOf = modules.drivers.get(read.config.driver);
3535
- if (driverOf === undefined) {
3536
- throw failed(`runner.json names the driver ${read.config.driver}, which this command does not have. It has: ${modules.drivers.names().join(", ")}.`);
3537
- }
3538
- const unknown = read.config.wake.find((name) => modules.wakeSources.get(name) === undefined);
3539
- if (unknown !== undefined) {
3540
- throw failed(`runner.json names the wake source ${unknown}, which this command does not have. It has: ${modules.wakeSources.names().join(", ")}.`);
3541
- }
3570
+ /**
3571
+ * The desk's runner.json as it stands: its text, what it says, and the driver it names; or
3572
+ * what is wrong with it in a few words. No file is the defaults.
3573
+ */
3574
+ const readConfig = async () => {
3575
+ const written = await host.readText("runner.json");
3576
+ const parsed = written === undefined
3577
+ ? { ok: true, config: DEFAULT_RUNNER_CONFIG }
3578
+ : parseRunnerConfig(written);
3579
+ if (!parsed.ok) {
3580
+ return { ok: false, problem: parsed.problem };
3581
+ }
3582
+ const driverOf = modules.drivers.get(parsed.config.driver);
3583
+ if (driverOf === undefined) {
3584
+ return {
3585
+ ok: false,
3586
+ problem: `runner.json names the driver ${parsed.config.driver}, which this command does not have. It has: ${modules.drivers.names().join(", ")}`,
3587
+ };
3588
+ }
3589
+ const unknown = parsed.config.wake.find((name) => modules.wakeSources.get(name) === undefined);
3590
+ if (unknown !== undefined) {
3591
+ return {
3592
+ ok: false,
3593
+ problem: `runner.json names the wake source ${unknown}, which this command does not have. It has: ${modules.wakeSources.names().join(", ")}`,
3594
+ };
3595
+ }
3596
+ return { ok: true, config: parsed.config, driverOf, text: written ?? "" };
3597
+ };
3542
3598
  // A header says the hour and the minute in the workspace's zone, or the machine's where it has none.
3543
3599
  const zone = me.workspace.timeZone ?? undefined;
3544
3600
  let clock;
@@ -3558,70 +3614,100 @@ const runner = async (args, io) => {
3558
3614
  });
3559
3615
  }
3560
3616
  const statePath = workPath("runner-state.json");
3561
- const running = createRunner({
3562
- client: session.client,
3563
- driver: driverOf({
3564
- spawn: host.spawn,
3565
- cwd: host.cwd,
3566
- command: read.config.product?.command,
3567
- args: read.config.product?.args,
3568
- version: io.version,
3569
- }),
3570
- config: read.config,
3571
- cwd: host.cwd,
3572
- machine: {
3573
- name: machineLine(io.hostname ?? ""),
3574
- os: machineLine(host.os),
3575
- user: machineLine(modules.boundaries.get("os-user")?.user() ?? host.user),
3576
- },
3577
- version: io.version ?? "0.0.0",
3578
- // A runner whose own version is not known has nothing to hold the package's against.
3579
- installed: io.version === undefined ? undefined : io.installedVersion,
3580
- // What installs the console's version here, the way this command was installed.
3581
- updateCommand: () => updateWords(io, io.consoleVersion?.()),
3582
- now: io.now,
3583
- random: host.random,
3584
- time: (iso) => clock.format(new Date(iso)),
3585
- files: {
3586
- write: (path, text) => host.writePrivate(workPath(path), text),
3587
- remove: (path) => host.remove(workPath(path)),
3588
- },
3589
- state: {
3590
- load: async () => runnerStateOf(await host.readText(statePath)),
3591
- save: (state) => host.writePrivate(statePath, `${JSON.stringify(state)}\n`),
3592
- },
3593
- log: (line) => io.stdout(`${new Date(io.now()).toISOString()} ${line}\n`),
3594
- // The autosave's git: in the desk, asking nobody at a terminal, its words read and let go.
3595
- // A step that reaches the git host is handed the account's token for it, as the clone of
3596
- // the desk was: answered from the environment of that one command, and only to the host
3597
- // the workspace keeps its desks at.
3598
- git: async (args, handed) => {
3599
- const origin = gitOriginOf(deskRemoteOf(me.workspace, me.person?.handle ?? ""));
3600
- const child = host.spawn("git", args, {
3617
+ const person = me.person;
3618
+ /** A runner for the desk's runner.json as it is read now: begun again whenever the file changed (ADR-0144). */
3619
+ const runnerOf = (read) => {
3620
+ const { driverOf } = read;
3621
+ return createRunner({
3622
+ client: session.client,
3623
+ driver: driverOf({
3624
+ spawn: host.spawn,
3601
3625
  cwd: host.cwd,
3602
- env: handed?.token === undefined || origin === undefined
3603
- ? { GIT_TERMINAL_PROMPT: "0" }
3604
- : gitTokenEnv(handed.token, origin),
3605
- });
3606
- child.end();
3607
- for await (const _ of child.lines) {
3608
- // Nothing of what git prints is kept.
3609
- }
3610
- return (await child.exited).code;
3611
- },
3612
- // The wake sources the desk names beside the console's own stream, which the runner listens to itself.
3613
- wakes: {
3614
- sources: read.config.wake.flatMap((name) => {
3615
- const source = modules.wakeSources.get(name);
3616
- return source === undefined || source.run === undefined ? [] : [source];
3626
+ command: read.config.product?.command,
3627
+ args: read.config.product?.args,
3628
+ version: io.version,
3617
3629
  }),
3618
- fetch: (url, init) => io.fetch(url, { ...init, headers: { ...init.headers } }),
3619
- socket: (url) => host.socket(url),
3630
+ config: read.config,
3631
+ reconfigured: async () => {
3632
+ const now = await readConfig();
3633
+ return !now.ok ? { problem: now.problem } : now.text === read.text ? "same" : "changed";
3634
+ },
3635
+ cwd: host.cwd,
3636
+ machine: {
3637
+ name: machineLine(io.hostname ?? ""),
3638
+ os: machineLine(host.os),
3639
+ user: machineLine(modules.boundaries.get("os-user")?.user() ?? host.user),
3640
+ },
3641
+ version: io.version ?? "0.0.0",
3642
+ // A runner whose own version is not known has nothing to hold the package's against.
3643
+ installed: io.version === undefined ? undefined : io.installedVersion,
3644
+ // What installs the console's version here, the way this command was installed.
3645
+ updateCommand: () => updateWords(io, io.consoleVersion?.()),
3646
+ now: io.now,
3647
+ random: host.random,
3648
+ time: (iso) => clock.format(new Date(iso)),
3649
+ files: {
3650
+ write: (path, text) => host.writePrivate(workPath(path), text),
3651
+ remove: (path) => host.remove(workPath(path)),
3652
+ },
3653
+ state: {
3654
+ load: async () => runnerStateOf(await host.readText(statePath)),
3655
+ save: (state) => host.writePrivate(statePath, `${JSON.stringify(state)}\n`),
3656
+ },
3657
+ log: (line) => io.stdout(`${new Date(io.now()).toISOString()} ${line}\n`),
3658
+ // The autosave's git: in the desk, asking nobody at a terminal, its words read and let go.
3659
+ // A step that reaches the git host is handed the account's token for it, as the clone of
3660
+ // the desk was: answered from the environment of that one command, and only to the host
3661
+ // the workspace keeps its desks at.
3662
+ git: async (args, handed) => {
3663
+ const origin = gitOriginOf(deskRemoteOf(me.workspace, me.person?.handle ?? ""));
3664
+ const child = host.spawn("git", args, {
3665
+ cwd: host.cwd,
3666
+ env: handed?.token === undefined || origin === undefined
3667
+ ? { GIT_TERMINAL_PROMPT: "0" }
3668
+ : gitTokenEnv(handed.token, origin),
3669
+ });
3670
+ child.end();
3671
+ for await (const _ of child.lines) {
3672
+ // Nothing of what git prints is kept.
3673
+ }
3674
+ return (await child.exited).code;
3675
+ },
3676
+ // The wake sources the desk names beside the console's own stream, which the runner listens to itself.
3677
+ wakes: {
3678
+ sources: read.config.wake.flatMap((name) => {
3679
+ const source = modules.wakeSources.get(name);
3680
+ return source === undefined || source.run === undefined ? [] : [source];
3681
+ }),
3682
+ fetch: (url, init) => io.fetch(url, { ...init, headers: { ...init.headers } }),
3683
+ socket: (url) => host.socket(url),
3684
+ },
3685
+ });
3686
+ };
3687
+ const first = await readConfig();
3688
+ if (!first.ok) {
3689
+ throw failed(`${first.problem}. Nothing of it is used: put it right, or remove it to run with the defaults.`);
3690
+ }
3691
+ io.stdout(`The runner of @${person.handle ?? person.login} at ${me.workspace.name} (${session.url}) starts in ${host.cwd}. Stop with Ctrl+C.\n`);
3692
+ // The machine is held awake while the runner runs, where the system has a way that needs no
3693
+ // administrator (ADR-0140): said in the runner's own lines, either way.
3694
+ const said = (line) => io.stdout(`${new Date(io.now()).toISOString()} ${line}\n`);
3695
+ void host
3696
+ .keepAwake?.()
3697
+ .then((awake) => said("by" in awake
3698
+ ? `the machine is kept from sleeping while the runner runs (${awake.by})`
3699
+ : `the machine is not kept from sleeping by the runner (${awake.problem}): set it never to sleep when idle`));
3700
+ const how = await keepRunning({
3701
+ first,
3702
+ read: async () => {
3703
+ const next = await readConfig();
3704
+ return next.ok ? { ok: true, config: next } : next;
3620
3705
  },
3706
+ start: runnerOf,
3707
+ stopped: host.untilStopped(),
3708
+ say: said,
3621
3709
  });
3622
- io.stdout(`The runner of @${me.person.handle ?? me.person.login} at ${me.workspace.name} (${session.url}) starts in ${host.cwd}. Stop with Ctrl+C.\n`);
3623
- void host.untilStopped().then(() => running.stop());
3624
- if ((await running.run()) === "updated") {
3710
+ if (how === "updated") {
3625
3711
  // The service that keeps a runner starts it again whenever it ends; one started by hand is
3626
3712
  // started again by hand.
3627
3713
  io.stdout("The command was updated: the runner ended, and the service that keeps it starts it again with the new one. Started by hand: console runner\n");
@@ -3773,6 +3859,13 @@ async function secretValue(io, values, prompt) {
3773
3859
  }
3774
3860
  return value;
3775
3861
  }
3862
+ /**
3863
+ * The kind of git host the workspace names, where it names one: what a token for git is held to
3864
+ * the shape of. Asked for the secret that is one alone, since no other is held to a host's shape.
3865
+ */
3866
+ const gitHostFor = async (client, name) => name === GIT_TOKEN_SECRET
3867
+ ? ((await client.me().catch(() => undefined))?.workspace.services?.git?.kind ?? undefined)
3868
+ : undefined;
3776
3869
  const SECRET_FLAGS = {
3777
3870
  set: { type: "boolean" },
3778
3871
  remove: { type: "boolean" },
@@ -3804,11 +3897,13 @@ const secret = async (args, io) => {
3804
3897
  if (on(values, "set")) {
3805
3898
  const expiresOn = expiryOf(io, values);
3806
3899
  const value = await secretValue(io, values, `Value of ${name} (typed unseen; Enter ends it): `);
3900
+ const host = await gitHostFor(session.client, name);
3807
3901
  const kept = await session.client.setSecret(name, {
3808
3902
  value,
3809
3903
  ...(expiresOn === undefined ? {} : { expiresOn }),
3810
3904
  });
3811
- answer(io, session, kept, () => `Kept: ${formatSecretLine(kept)}`);
3905
+ const notes = secretNotes(name, value, host);
3906
+ answer(io, session, kept, () => [`Kept: ${formatSecretLine(kept)}`, ...notes].join("\n"));
3812
3907
  return EXIT.ok;
3813
3908
  }
3814
3909
  // The value alone, for whatever reads it next; the reading is on the account's record.
@@ -3854,11 +3949,125 @@ const agentSecret = async (args, io) => {
3854
3949
  }
3855
3950
  const expiresOn = expiryOf(io, values);
3856
3951
  const value = await secretValue(io, values, `Value of ${name} for @${handle} (typed unseen; Enter ends it): `);
3952
+ const host = await gitHostFor(session.client, name);
3857
3953
  const kept = await session.client.seedAgentSecret(handle, name, {
3858
3954
  value,
3859
3955
  ...(expiresOn === undefined ? {} : { expiresOn }),
3860
3956
  });
3861
- answer(io, session, kept, () => `Seeded for @${handle}, which alone reads it back: ${formatSecretLine(kept)}`);
3957
+ const notes = secretNotes(name, value, host);
3958
+ answer(io, session, kept, () => [`Seeded for @${handle}, which alone reads it back: ${formatSecretLine(kept)}`, ...notes].join("\n"));
3959
+ return EXIT.ok;
3960
+ };
3961
+ const OWN_WAKE_FLAGS = {
3962
+ file: { type: "string" },
3963
+ in: { type: "string" },
3964
+ at: { type: "string" },
3965
+ key: { type: "string" },
3966
+ cancel: { type: "boolean" },
3967
+ };
3968
+ const OWN_WAKE_USAGE = 'Say when, or nothing for now: console agent wake me ["<words>"] [--in <minutes> | --at <HH:MM>] [--key <name>] | agent wake me --cancel [--key <name>]';
3969
+ /** The hour and the minute it is in a time zone, as minutes of its day; in the machine's own where the zone names none. */
3970
+ function minutesOfDayIn(zone, now) {
3971
+ let parts;
3972
+ try {
3973
+ parts = new Intl.DateTimeFormat("en-GB", {
3974
+ hour: "2-digit",
3975
+ minute: "2-digit",
3976
+ hourCycle: "h23",
3977
+ ...(zone === undefined ? {} : { timeZone: zone }),
3978
+ }).formatToParts(now);
3979
+ }
3980
+ catch {
3981
+ parts = new Intl.DateTimeFormat("en-GB", {
3982
+ hour: "2-digit",
3983
+ minute: "2-digit",
3984
+ hourCycle: "h23",
3985
+ }).formatToParts(now);
3986
+ }
3987
+ const of = (type) => Number(parts.find((part) => part.type === type)?.value ?? "0");
3988
+ return of("hour") * 60 + of("minute");
3989
+ }
3990
+ /**
3991
+ * When a wake for later is raised, as the flags say it: so many minutes from now, or the next
3992
+ * time the workspace's clock says an hour and a minute; nothing where neither flag is given.
3993
+ */
3994
+ export function ownWakeMoment(given, zone, now) {
3995
+ if (given.in !== undefined && given.at !== undefined) {
3996
+ throw misuse(OWN_WAKE_USAGE);
3997
+ }
3998
+ if (given.in !== undefined) {
3999
+ const minutes = Number(given.in);
4000
+ if (!Number.isInteger(minutes) || minutes < 1 || minutes > MAX_OWN_WAKE_DAYS * 24 * 60) {
4001
+ throw misuse(`Not a number of minutes, from 1 to ${MAX_OWN_WAKE_DAYS * 24 * 60}: ${given.in}`);
4002
+ }
4003
+ return new Date(now.getTime() + minutes * 60_000);
4004
+ }
4005
+ if (given.at !== undefined) {
4006
+ const clock = /^([01]?[0-9]|2[0-3]):([0-5][0-9])$/.exec(given.at);
4007
+ if (clock === null) {
4008
+ throw misuse(`Not an hour and a minute, as 14:30: ${given.at}`);
4009
+ }
4010
+ const wanted = Number(clock[1]) * 60 + Number(clock[2]);
4011
+ // The next time the clock says so: later today, or tomorrow where that hour has passed.
4012
+ const day = 24 * 60;
4013
+ const ahead = (wanted - minutesOfDayIn(zone, now) + day) % day || day;
4014
+ const at = new Date(now.getTime() + ahead * 60_000);
4015
+ at.setSeconds(0, 0);
4016
+ // Where the zone's clock is put forward or back before then, the moment is off by that
4017
+ // much: moved by what the clock says there, once, where the clock then says the hour asked
4018
+ // for and the moment is still to come. An hour the clock skips that night is no hour of
4019
+ // that day: the moment stays the one counted, just past it.
4020
+ const off = ((wanted - minutesOfDayIn(zone, at) + day + day / 2) % day) - day / 2;
4021
+ const moved = new Date(at.getTime() + off * 60_000);
4022
+ return off !== 0 && moved.getTime() > now.getTime() && minutesOfDayIn(zone, moved) === wanted
4023
+ ? moved
4024
+ : at;
4025
+ }
4026
+ return undefined;
4027
+ }
4028
+ // A wake an agent account raises for itself (ADR-0145), by its own command: now, for whoever
4029
+ // prepared its machine or signed something in there to say so and for the agent to go on; or
4030
+ // kept for a moment to come, for an agent that has something to look at again.
4031
+ const ownWake = async (args, io) => {
4032
+ const { values, positionals } = parse(args, OWN_WAKE_FLAGS);
4033
+ const [, words, ...rest] = positionals;
4034
+ if (rest.length > 0) {
4035
+ throw misuse(OWN_WAKE_USAGE);
4036
+ }
4037
+ const key = text(values, "key");
4038
+ if (key !== undefined && !/^[a-z0-9][a-z0-9-]{0,39}$/.test(key)) {
4039
+ throw misuse(`Not a name for a wake, which is up to 40 lowercase letters, digits and hyphens: ${key}`);
4040
+ }
4041
+ const session = await open(io, values);
4042
+ /** A console of before knows no such route: said as what it is. */
4043
+ const asked = async (ask) => {
4044
+ try {
4045
+ return await ask();
4046
+ }
4047
+ catch (error) {
4048
+ if (error instanceof ApiError && error.status === 404 && error.code === "not_found") {
4049
+ throw failed("This console does not take an account's own wake yet: it does from 0.5.2 on.");
4050
+ }
4051
+ throw error;
4052
+ }
4053
+ };
4054
+ if (on(values, "cancel")) {
4055
+ const named = key ?? OWN_WAKE_KEY;
4056
+ await asked(() => session.client.cancelOwnWake(named));
4057
+ answer(io, session, { cancelled: named }, () => `The wake ${named} is taken away.`);
4058
+ return EXIT.ok;
4059
+ }
4060
+ const said = ((await bodyOf(io, values, words)) ?? "").trim();
4061
+ const me = await session.client.me();
4062
+ const at = ownWakeMoment({ in: text(values, "in"), at: text(values, "at") }, me.workspace.timeZone ?? undefined, new Date(io.now()));
4063
+ const raised = await asked(() => session.client.raiseOwnWake({
4064
+ ...(said.length === 0 ? {} : { text: said }),
4065
+ ...(at === undefined ? {} : { at: at.toISOString() }),
4066
+ ...(key === undefined ? {} : { key }),
4067
+ }));
4068
+ answer(io, session, raised, () => raised.kept === null
4069
+ ? `Raised, as signal #${raised.signal?.number ?? "?"} of your record: your runner takes it as it takes any wake.`
4070
+ : `Kept: ${formatOwnWakeLine(raised.kept)}\nTake it away: console agent wake me --cancel${raised.kept.key === OWN_WAKE_KEY ? "" : ` --key ${raised.kept.key}`}. A second under the same name takes its place.`);
3862
4071
  return EXIT.ok;
3863
4072
  };
3864
4073
  /** The kinds of signal a supervisor sends with words: which need them, and which take them. */
@@ -3875,6 +4084,20 @@ const WORDED_SIGNALS = {
3875
4084
  // with the same conversation or with a new one, a wake; in their own name, on the account's
3876
4085
  // record. What it says is given as words, or with --file, or on standard input as `-`.
3877
4086
  const agentSignal = async (kind, args, io) => {
4087
+ // An account's own wake is another command under the same word: console agent wake me,
4088
+ // wherever `me` stands among its flags.
4089
+ if (kind === "wake") {
4090
+ let whom;
4091
+ try {
4092
+ whom = parse(args, OWN_WAKE_FLAGS).positionals[0];
4093
+ }
4094
+ catch {
4095
+ whom = undefined;
4096
+ }
4097
+ if (whom === "me") {
4098
+ return ownWake(args, io);
4099
+ }
4100
+ }
3878
4101
  const { values, positionals } = parse(args, { file: { type: "string" } });
3879
4102
  const [given, words, ...rest] = positionals;
3880
4103
  const needs = WORDED_SIGNALS[kind]?.needs === true;
@@ -3944,10 +4167,19 @@ const agentSignals = async (args, io) => {
3944
4167
  ...(limit === undefined ? {} : { limit: Number(limit) }),
3945
4168
  ...(before === undefined ? {} : { before: Number(before) }),
3946
4169
  });
3947
- answer(io, session, found, () => found.items.length === 0
4170
+ // What the account keeps for later (ADR-0145) stands over the record's first page: it is no
4171
+ // signal yet. A console of before keeps none, and says nothing of it.
4172
+ const kept = before === undefined
4173
+ ? await session.client
4174
+ .ownWakes(handle)
4175
+ .then((wakes) => wakes.items)
4176
+ .catch(() => [])
4177
+ : [];
4178
+ answer(io, session, kept.length === 0 ? found : { ...found, kept }, () => found.items.length === 0 && kept.length === 0
3948
4179
  ? "No signal yet."
3949
4180
  : [
3950
- ...found.items.map(formatSignalLine),
4181
+ ...kept.map(formatOwnWakeLine),
4182
+ ...found.items.map((signal) => formatSignalLine(signal, found.delivered)),
3951
4183
  ...(found.more
3952
4184
  ? [
3953
4185
  `More before: console agent signals ${handle} --before ${found.items.at(-1)?.number}`,
@@ -3993,6 +4225,8 @@ const SETUP_FLAGS = {
3993
4225
  refresh: { type: "boolean" },
3994
4226
  "new-desk": { type: "boolean" },
3995
4227
  "no-service": { type: "boolean" },
4228
+ driver: { type: "string" },
4229
+ "no-browser": { type: "boolean" },
3996
4230
  };
3997
4231
  /** The end of what a program said, for a refusal to carry: one line, bounded. */
3998
4232
  function lastWords(ran) {
@@ -4075,7 +4309,9 @@ async function deskOf(machine, values) {
4075
4309
  * host where the account keeps the token that reads it there, which is an account that pushed a
4076
4310
  * desk before; written from the template otherwise, and no file that is there is written over.
4077
4311
  */
4078
- async function settleDesk(io, machine, client, person, workspace, url, values) {
4312
+ async function settleDesk(io, machine, client, person, workspace, url, values,
4313
+ /** What a look at the machine found, for a setup that looked: the driver and the browser a new desk names. */
4314
+ look) {
4079
4315
  const desk = await deskOf(machine, values);
4080
4316
  const handle = person.handle ?? "";
4081
4317
  if ((await machine.exists(machine.path(desk, "runner.json"))) ||
@@ -4098,6 +4334,7 @@ async function settleDesk(io, machine, client, person, workspace, url, values) {
4098
4334
  throw failed(`The desk could not be cloned from ${remote}: ${lastWords(cloned)}. Put that right and run this again; or begin a new desk here with --new-desk, where the account never pushed one.`);
4099
4335
  }
4100
4336
  io.stdout(`The desk is cloned from ${remote} into ${desk}.\n`);
4337
+ await settleDeskGit(io, machine, desk, url, person.login, deskRemoteOf(workspace, handle));
4101
4338
  return desk;
4102
4339
  }
4103
4340
  const written = [];
@@ -4105,6 +4342,14 @@ async function settleDesk(io, machine, client, person, workspace, url, values) {
4105
4342
  agent: { name: person.name ?? handle, handle, title: person.title ?? null },
4106
4343
  console: { url, workspace: workspace.name },
4107
4344
  services: deskServicesOf(workspace, handle),
4345
+ // The product found on the machine, and its browser: what the runner starts with.
4346
+ runner: look === undefined
4347
+ ? undefined
4348
+ : {
4349
+ ...DEFAULT_RUNNER_CONFIG,
4350
+ ...(look.driver === undefined ? {} : { driver: look.driver }),
4351
+ ...(look.browser === undefined ? {} : { browser: look.browser }),
4352
+ },
4108
4353
  })) {
4109
4354
  const file = machine.path(desk, path);
4110
4355
  if (!(await machine.exists(file))) {
@@ -4112,9 +4357,48 @@ async function settleDesk(io, machine, client, person, workspace, url, values) {
4112
4357
  written.push(path);
4113
4358
  }
4114
4359
  }
4115
- io.stdout(`A new desk is written at ${desk} (${written.join(", ")}). It is the agent's from now on: to edit, to make a repository of, and to push to its git host.\n`);
4360
+ io.stdout(`A new desk is written at ${desk} (${written.join(", ")}). It is the agent's from now on: to edit and to push to its git host.\n`);
4361
+ await settleDeskGit(io, machine, desk, url, person.login, deskRemoteOf(workspace, handle));
4116
4362
  return desk;
4117
4363
  }
4364
+ /**
4365
+ * The desk's own git settings (ADR-0140): a repository where it is none yet, and for the host
4366
+ * the workspace keeps its desks at, a credential helper that reads the account's token from its
4367
+ * store when git asks, in place of whatever the machine has configured. The agent then pushes
4368
+ * with nothing typed, and no copy of the token is left in a keychain or a file. Nothing where
4369
+ * the workspace names no git host, the command does not know how it was started, or git is not
4370
+ * there; what did not succeed is said and the setup goes on.
4371
+ */
4372
+ async function settleDeskGit(io, machine, desk, url, login, remote) {
4373
+ const origin = gitOriginOf(remote);
4374
+ if (origin === undefined || machine.self === undefined) {
4375
+ return;
4376
+ }
4377
+ const git = (args) => machine.run("git", ["-C", desk, ...args]);
4378
+ if (!(await machine.exists(machine.path(desk, ".git")))) {
4379
+ if ((await git(["init", "--quiet"])).code !== 0) {
4380
+ return;
4381
+ }
4382
+ }
4383
+ // The helper as git's own shell runs it: every word in single quotes, a path with its
4384
+ // slashes forward, which that shell takes on every system.
4385
+ const word = (text) => `'${text.replaceAll("\\", "/").replaceAll("'", "'\\''")}'`;
4386
+ const read = [...machine.self, "secret", GIT_TOKEN_SECRET, "--url", url, "--account", login]
4387
+ .map(word)
4388
+ .join(" ");
4389
+ const helper = `!f() { test "$1" = get && printf 'username=x-access-token\\npassword=%s\\n' "$(${read})"; }; f`;
4390
+ const key = `credential.${origin}.helper`;
4391
+ const kept = await git(["config", "--local", "--get-all", key]);
4392
+ if (kept.code === 0 && kept.out.includes(GIT_TOKEN_SECRET)) {
4393
+ return;
4394
+ }
4395
+ // An empty helper first: whatever the machine has configured for that host is left out.
4396
+ const cleared = await git(["config", "--local", "--replace-all", key, ""]);
4397
+ const added = cleared.code === 0 ? await git(["config", "--local", "--add", key, helper]) : cleared;
4398
+ io.stdout(added.code === 0
4399
+ ? `The desk's git reads the account's ${GIT_TOKEN_SECRET} from its store when ${origin} asks: nothing is typed, and no copy is kept elsewhere.\n`
4400
+ : `The desk's git was not set to read the account's token from its store (${lastWords(added)}); the agent hands it to git itself.\n`);
4401
+ }
4118
4402
  /**
4119
4403
  * The service that keeps the runner running (ADR-0085), by the module of this platform: its
4120
4404
  * files written and, for a first setup, its commands run; answers where the runner's own lines
@@ -4265,11 +4549,48 @@ async function awaitRunner(io, client, handle, heardBefore, log) {
4265
4549
  const heard = found?.state?.heardAt ?? null;
4266
4550
  const said = found?.runner?.machine ?? null;
4267
4551
  if (heard !== null && heard !== heardBefore && said !== null) {
4268
- io.stdout(`The runner is heard from: ${said.name}, ${said.os}, OS account ${said.user}. @${handle} is set up on this machine, and its page shows it.\n`);
4269
- return;
4552
+ io.stdout(`The runner is heard from: ${said.name}, ${said.os}, OS account ${said.user}. @${handle} is set up on this machine.\n`);
4553
+ return true;
4554
+ }
4555
+ }
4556
+ io.stdout(`The runner is not heard from yet. Its own lines are in ${log}: read them, since they say what it lacks; the account's page says when it is heard from.\n`);
4557
+ return false;
4558
+ }
4559
+ /** How often, and how many times, a setup looks whether the agent's first session has begun. */
4560
+ const FIRST_SESSION_PAUSE_MS = 2000;
4561
+ const FIRST_SESSION_TRIES = 30;
4562
+ /**
4563
+ * What a setup ends with (ADR-0140): whether the agent's first session has begun, where to
4564
+ * watch it, and that the machine's part ends here, since everything after is the agent's own.
4565
+ */
4566
+ async function handOver(io, machine, client, url, handle,
4567
+ /** Where the runner's own lines are. */
4568
+ log) {
4569
+ let began = false;
4570
+ for (let tries = 0; tries < FIRST_SESSION_TRIES && !began; tries += 1) {
4571
+ const found = await client.agent(handle).catch(() => undefined);
4572
+ began = (found?.runner?.session ?? null) !== null;
4573
+ if (!began) {
4574
+ await io.sleep(FIRST_SESSION_PAUSE_MS);
4270
4575
  }
4271
4576
  }
4272
- io.stdout(`The runner is not heard from yet. Its own lines are in ${log}; the account's page says when it is.\n`);
4577
+ const plate = await client.work().catch(() => undefined);
4578
+ const first = plate?.tasks.find((one) => one.task.title === onboardingTitle(handle));
4579
+ const lines = [
4580
+ began
4581
+ ? `@${handle}'s session has begun: the agent is at work.`
4582
+ : `No session has begun yet: one begins when something wakes @${handle}.`,
4583
+ `Watch it: ${url}${agentHref(handle)}`,
4584
+ ...(first === undefined
4585
+ ? []
4586
+ : [
4587
+ `Its first task: #${first.task.number} "${first.task.title}" in ${first.project.key}, ${url}${taskHref(first.project.key, first.task.number)}`,
4588
+ ]),
4589
+ `That is the machine prepared: stop here. What comes next, its sign-ins, its tokens, its desk's repository, its profile and its messenger, is @${handle}'s own, done in its own session: do none of it for it.`,
4590
+ `What you change on this machine afterwards, say to it: console agent wake me "<what changed>"`,
4591
+ awakeWords(machine.platform, await heldAwake(machine), log),
4592
+ ];
4593
+ io.stdout(`${lines.join("\n")}\n`);
4273
4594
  }
4274
4595
  // Derives a machine again (ADR-0088): by the account's own command, in its desk, when the
4275
4596
  // services or the account changed. It writes what is missing of the desk and the service where
@@ -4342,20 +4663,32 @@ const agentSetup = async (args, io) => {
4342
4663
  }
4343
4664
  const { handle } = setup.account;
4344
4665
  io.stdout(`\nSetting this machine up for @${handle}, in the OS account ${machine.user}${io.hostname === undefined ? "" : ` on ${io.hostname}`}.\n`);
4666
+ // The machine first (ADR-0140): everything that is missing is said at once, before anyone is
4667
+ // asked to sign in, and nothing is set up on a machine the runner could not work on.
4668
+ const driver = text(values, "driver");
4669
+ if (driver !== undefined &&
4670
+ ownRunnerModules({ user: machine.user }).drivers.get(driver) === undefined) {
4671
+ throw misuse(`Not a driver this command has: ${driver}. It has: ${ownRunnerModules({ user: machine.user }).drivers.names().join(", ")}.`);
4672
+ }
4673
+ const look = await lookAtMachine(machine, { driver, browser: !on(values, "no-browser") });
4674
+ if (look.missing.length > 0) {
4675
+ throw failed(`This machine lacks what the setup needs. Install each yourself, without asking, and run the line again:\n${look.missing.map((line) => `- ${line}`).join("\n")}`);
4676
+ }
4677
+ io.stdout(`The machine has what the setup needs: git${look.product === undefined ? "" : `, ${look.product}`}${look.browser === undefined ? "" : ", Google Chrome"}.\n${look.notes.map((line) => `${line}\n`).join("")}`);
4345
4678
  const client = await signInAsAccount(io, machine, url, setup);
4346
4679
  const me = await client.me();
4347
4680
  if (me.person === null) {
4348
4681
  throw failed("The console does not know this sign-in any more. Run the line again.");
4349
4682
  }
4350
4683
  const heardBefore = (await client.agent(handle).catch(() => undefined))?.state?.heardAt ?? null;
4351
- const desk = await settleDesk(io, machine, client, me.person, me.workspace, url, values);
4684
+ const desk = await settleDesk(io, machine, client, me.person, me.workspace, url, values, look);
4352
4685
  if (on(values, "no-service")) {
4353
4686
  io.stdout(`No service is written, as asked. Start the runner yourself and keep it running: ${runnerByHand(desk, url, me.person.login, machine.platform)}\n`);
4354
4687
  return EXIT.ok;
4355
4688
  }
4356
4689
  const log = await settleService(io, machine, desk, url, me.person.login, "load");
4357
- if (log !== undefined) {
4358
- await awaitRunner(io, client, handle, heardBefore, log);
4690
+ if (log !== undefined && (await awaitRunner(io, client, handle, heardBefore, log))) {
4691
+ await handOver(io, machine, client, url, handle, log);
4359
4692
  }
4360
4693
  return EXIT.ok;
4361
4694
  };
@@ -4890,7 +5223,21 @@ const PROJECT_FIELDS = {
4890
5223
  skills: { type: "string" },
4891
5224
  color: { type: "string" },
4892
5225
  symbol: { type: "string" },
5226
+ glyph: { type: "string" },
4893
5227
  };
5228
+ /** An icon of the pack as a flag names it, `null` for `none`; a name that is none of the pack's is answered with the pack's names. */
5229
+ function glyphOrNoneOf(value) {
5230
+ if (value === undefined) {
5231
+ return undefined;
5232
+ }
5233
+ if (value === "none") {
5234
+ return null;
5235
+ }
5236
+ if (!isIconName(value)) {
5237
+ throw misuse(`No icon of the pack is called ${value}. The pack's icons: ${ICON_NAMES.join(", ")}; none takes the icon away.`);
5238
+ }
5239
+ return value;
5240
+ }
4894
5241
  /** What the flags say of a project; `none` clears what may be cleared. */
4895
5242
  async function projectFieldsOf(io, values) {
4896
5243
  const description = await bodyOf(io, values, text(values, "description"));
@@ -4898,6 +5245,7 @@ async function projectFieldsOf(io, values) {
4898
5245
  const skills = orNone(text(values, "skills"));
4899
5246
  const color = colorOrNoneOf(text(values, "color"));
4900
5247
  const symbol = orNone(text(values, "symbol"));
5248
+ const glyph = glyphOrNoneOf(text(values, "glyph"));
4901
5249
  return {
4902
5250
  ...(description === undefined
4903
5251
  ? {}
@@ -4906,6 +5254,7 @@ async function projectFieldsOf(io, values) {
4906
5254
  ...(skills === undefined ? {} : { skillsAddress: skills }),
4907
5255
  ...(color === undefined ? {} : { color }),
4908
5256
  ...(symbol === undefined ? {} : { symbol }),
5257
+ ...(glyph === undefined ? {} : { glyph }),
4909
5258
  };
4910
5259
  }
4911
5260
  const newProject = async (args, io) => {
@@ -4923,7 +5272,7 @@ const editProject = async (args, io) => {
4923
5272
  const name = text(values, "name");
4924
5273
  const patch = { ...(name === undefined ? {} : { name }), ...(await projectFieldsOf(io, values)) };
4925
5274
  if (Object.keys(patch).length === 0) {
4926
- throw misuse("Say what to change: --name, --description, --visibility, --skills, --color or --symbol; none clears the description, the skills address, the colour or the symbol.");
5275
+ throw misuse("Say what to change: --name, --description, --visibility, --skills, --color, --symbol or --glyph; none clears the description, the skills address, the colour, the symbol or the icon.");
4927
5276
  }
4928
5277
  const session = await open(io, values);
4929
5278
  const changed = await session.client.project(key).update(patch);