@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/src/cli/cli.ts CHANGED
@@ -40,20 +40,24 @@ import {
40
40
  } from "../compat.js";
41
41
  import { normalizeConnectCode } from "../connect.js";
42
42
  import { addDays, dayOf as dayOfDate, firstDayOfWeek, isDay, weekOf } from "../dates.js";
43
+ import { ICON_NAMES, type IconName, isIconName } from "../icons/index.js";
43
44
  import {
44
45
  DEFAULT_PAGE_LIMIT,
45
46
  EVENTS_PAGE_LIMIT,
46
47
  LIST_LIMIT,
47
48
  MAX_DECIDERS,
48
49
  MAX_OPTIONS,
50
+ MAX_OWN_WAKE_DAYS,
49
51
  MAX_RUNNER_LINE_LENGTH,
50
52
  MAX_SIGNALS_PAGE_LIMIT,
51
53
  MIN_OPTIONS,
54
+ OWN_WAKE_KEY,
52
55
  } from "../limits.js";
56
+ import { onboardingTitle } from "../onboarding.js";
53
57
  import { capabilityWords } from "../plugin/capabilities.js";
54
58
  import { PLUGIN_LIST_LIMIT } from "../plugin/limits.js";
55
59
  import { checkRecords, RECORDS_DIR, RECORDS_INDEX_FILE, type RecordsFiles } from "../records.js";
56
- import { decisionHref, docHref, myDecisionHref, taskHref } from "../router.js";
60
+ import { agentHref, decisionHref, docHref, myDecisionHref, taskHref } from "../router.js";
57
61
  import { fillRules, RULES_PATH, RULES_TITLE } from "../rules.js";
58
62
  import { DEFAULT_RUNNER_CONFIG, parseRunnerConfig } from "../runner/config.js";
59
63
  import {
@@ -64,7 +68,13 @@ import {
64
68
  personDeskFiles,
65
69
  } from "../runner/desk.js";
66
70
  import { ownRunnerModules } from "../runner/modules.js";
67
- import { createRunner, GIT_TOKEN_SECRET, type RunnerState } from "../runner/runner.js";
71
+ import {
72
+ createRunner,
73
+ GIT_TOKEN_SECRET,
74
+ type Runner,
75
+ type RunnerEnd,
76
+ type RunnerState,
77
+ } from "../runner/runner.js";
68
78
  import type { ServiceCommand } from "../runner/types.js";
69
79
  import {
70
80
  hostOfLogin,
@@ -156,6 +166,7 @@ import {
156
166
  formatMemberLine,
157
167
  formatMore,
158
168
  formatOptions,
169
+ formatOwnWakeLine,
159
170
  formatPersonLine,
160
171
  formatPersonWork,
161
172
  formatPlugin,
@@ -192,6 +203,7 @@ import {
192
203
  } from "./format.js";
193
204
  import { COMMAND_HELP, helpFor, ownSkillPath, usage } from "./help.js";
194
205
  import { describeInstall, type Install, updateCommandFor } from "./install.js";
206
+ import { awakeWords, heldAwake, lookAtMachine, type MachineLook } from "./machine-check.js";
195
207
  import type { NoticeStore } from "./notices.js";
196
208
  import {
197
209
  type ConsolePack,
@@ -206,6 +218,7 @@ import {
206
218
  skillPathIn,
207
219
  } from "./pack.js";
208
220
  import { type RunnerHost, workPath } from "./runner-host.js";
221
+ import { secretNotes } from "./secret-notes.js";
209
222
  import {
210
223
  createServeHandler,
211
224
  DEFAULT_SERVE_PORT,
@@ -4555,6 +4568,10 @@ const serve: Command = async (args, io) => {
4555
4568
  throw error;
4556
4569
  }
4557
4570
  }
4571
+ // Whether the records are there is asked before anything listens: the line says what the
4572
+ // command found when it began. Asked after, a directory made in the moment between, by a
4573
+ // session that began keeping something as the pages came up, read as there all along.
4574
+ const recordsThere = records === undefined ? false : await records.there();
4558
4575
  const listening = await listen(
4559
4576
  (bound) =>
4560
4577
  createServeHandler({
@@ -4572,7 +4589,7 @@ const serve: Command = async (args, io) => {
4572
4589
  const served =
4573
4590
  kept === undefined || records === undefined
4574
4591
  ? ""
4575
- : (await records.there())
4592
+ : recordsThere
4576
4593
  ? ` The records in ${kept} are at ${listening.url}records/, read as they are when they are asked for.`
4577
4594
  : ` Nothing is kept in ${kept} yet: what comes to be kept there is at ${listening.url}records/ from then on, with no restart.`;
4578
4595
  io.stdout(
@@ -4629,6 +4646,52 @@ const machineLine = (text: string): string => {
4629
4646
  return line.length === 0 ? "unknown" : line;
4630
4647
  };
4631
4648
 
4649
+ /**
4650
+ * Keeps a runner going across its `runner.json` (ADR-0144): a runner that ended for its file is
4651
+ * followed by another, begun with the file as it is now, in this process. Where the file stopped
4652
+ * reading in between, the agent having written it again in the turn that was under way, the next
4653
+ * runner begins with the file as it last read, so that there is always one: it then says what is
4654
+ * wrong with the file to the agent, whose session it is the only way to. Answers how the last
4655
+ * runner ended, once one ended for anything else or whoever runs the command asked it to stop.
4656
+ */
4657
+ export async function keepRunning<Config>(input: {
4658
+ readonly first: Config;
4659
+ /** The desk's file as it stands now, or what is wrong with it in a few words. */
4660
+ readonly read: () => Promise<
4661
+ | { readonly ok: true; readonly config: Config }
4662
+ | { readonly ok: false; readonly problem: string }
4663
+ >;
4664
+ readonly start: (config: Config) => Pick<Runner, "run" | "stop">;
4665
+ /** Resolves when whoever runs the command asks it to stop. */
4666
+ readonly stopped: Promise<void>;
4667
+ readonly say: (line: string) => void;
4668
+ }): Promise<RunnerEnd> {
4669
+ let good = input.first;
4670
+ let running = input.start(good);
4671
+ let asked = false;
4672
+ void input.stopped.then(() => {
4673
+ asked = true;
4674
+ running.stop();
4675
+ });
4676
+ for (;;) {
4677
+ const how = await running.run();
4678
+ if (how !== "changed" || asked) {
4679
+ return how;
4680
+ }
4681
+ const next = await input.read();
4682
+ if (next.ok) {
4683
+ good = next.config;
4684
+ } else {
4685
+ input.say(`${next.problem}: the runner starts again with the runner.json it last read`);
4686
+ }
4687
+ running = input.start(good);
4688
+ // Asked to stop while the file was read: the runner just begun ends at once.
4689
+ if (asked) {
4690
+ running.stop();
4691
+ }
4692
+ }
4693
+ }
4694
+
4632
4695
  // The runner of an agent account (ADR-0085, docs/specs/runner.md): started in the account's
4633
4696
  // desk, on the command signed in as the account itself. It keeps the agent's session going,
4634
4697
  // feeds it what the console sends and reports what it does, until it is stopped.
@@ -4651,29 +4714,36 @@ const runner: Command = async (args, io) => {
4651
4714
  "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.",
4652
4715
  );
4653
4716
  }
4654
- const written = await host.readText("runner.json");
4655
- const read =
4656
- written === undefined
4657
- ? { ok: true as const, config: DEFAULT_RUNNER_CONFIG }
4658
- : parseRunnerConfig(written);
4659
- if (!read.ok) {
4660
- throw failed(
4661
- `${read.problem}. Nothing of it is used: put it right, or remove it to run with the defaults.`,
4662
- );
4663
- }
4664
4717
  const modules = ownRunnerModules({ user: host.user });
4665
- const driverOf = modules.drivers.get(read.config.driver);
4666
- if (driverOf === undefined) {
4667
- throw failed(
4668
- `runner.json names the driver ${read.config.driver}, which this command does not have. It has: ${modules.drivers.names().join(", ")}.`,
4669
- );
4670
- }
4671
- const unknown = read.config.wake.find((name) => modules.wakeSources.get(name) === undefined);
4672
- if (unknown !== undefined) {
4673
- throw failed(
4674
- `runner.json names the wake source ${unknown}, which this command does not have. It has: ${modules.wakeSources.names().join(", ")}.`,
4675
- );
4676
- }
4718
+ /**
4719
+ * The desk's runner.json as it stands: its text, what it says, and the driver it names; or
4720
+ * what is wrong with it in a few words. No file is the defaults.
4721
+ */
4722
+ const readConfig = async () => {
4723
+ const written = await host.readText("runner.json");
4724
+ const parsed =
4725
+ written === undefined
4726
+ ? { ok: true as const, config: DEFAULT_RUNNER_CONFIG }
4727
+ : parseRunnerConfig(written);
4728
+ if (!parsed.ok) {
4729
+ return { ok: false as const, problem: parsed.problem };
4730
+ }
4731
+ const driverOf = modules.drivers.get(parsed.config.driver);
4732
+ if (driverOf === undefined) {
4733
+ return {
4734
+ ok: false as const,
4735
+ problem: `runner.json names the driver ${parsed.config.driver}, which this command does not have. It has: ${modules.drivers.names().join(", ")}`,
4736
+ };
4737
+ }
4738
+ const unknown = parsed.config.wake.find((name) => modules.wakeSources.get(name) === undefined);
4739
+ if (unknown !== undefined) {
4740
+ return {
4741
+ ok: false as const,
4742
+ problem: `runner.json names the wake source ${unknown}, which this command does not have. It has: ${modules.wakeSources.names().join(", ")}`,
4743
+ };
4744
+ }
4745
+ return { ok: true as const, config: parsed.config, driverOf, text: written ?? "" };
4746
+ };
4677
4747
  // A header says the hour and the minute in the workspace's zone, or the machine's where it has none.
4678
4748
  const zone = me.workspace.timeZone ?? undefined;
4679
4749
  let clock: Intl.DateTimeFormat;
@@ -4692,73 +4762,109 @@ const runner: Command = async (args, io) => {
4692
4762
  });
4693
4763
  }
4694
4764
  const statePath = workPath("runner-state.json");
4695
- const running = createRunner({
4696
- client: session.client,
4697
- driver: driverOf({
4698
- spawn: host.spawn,
4699
- cwd: host.cwd,
4700
- command: read.config.product?.command,
4701
- args: read.config.product?.args,
4702
- version: io.version,
4703
- }),
4704
- config: read.config,
4705
- cwd: host.cwd,
4706
- machine: {
4707
- name: machineLine(io.hostname ?? ""),
4708
- os: machineLine(host.os),
4709
- user: machineLine(modules.boundaries.get("os-user")?.user() ?? host.user),
4710
- },
4711
- version: io.version ?? "0.0.0",
4712
- // A runner whose own version is not known has nothing to hold the package's against.
4713
- installed: io.version === undefined ? undefined : io.installedVersion,
4714
- // What installs the console's version here, the way this command was installed.
4715
- updateCommand: () => updateWords(io, io.consoleVersion?.()),
4716
- now: io.now,
4717
- random: host.random,
4718
- time: (iso) => clock.format(new Date(iso)),
4719
- files: {
4720
- write: (path, text) => host.writePrivate(workPath(path), text),
4721
- remove: (path) => host.remove(workPath(path)),
4722
- },
4723
- state: {
4724
- load: async () => runnerStateOf(await host.readText(statePath)),
4725
- save: (state) => host.writePrivate(statePath, `${JSON.stringify(state)}\n`),
4726
- },
4727
- log: (line) => io.stdout(`${new Date(io.now()).toISOString()} ${line}\n`),
4728
- // The autosave's git: in the desk, asking nobody at a terminal, its words read and let go.
4729
- // A step that reaches the git host is handed the account's token for it, as the clone of
4730
- // the desk was: answered from the environment of that one command, and only to the host
4731
- // the workspace keeps its desks at.
4732
- git: async (args, handed) => {
4733
- const origin = gitOriginOf(deskRemoteOf(me.workspace, me.person?.handle ?? ""));
4734
- const child = host.spawn("git", args, {
4765
+ const person = me.person;
4766
+ /** A runner for the desk's runner.json as it is read now: begun again whenever the file changed (ADR-0144). */
4767
+ const runnerOf = (read: Extract<Awaited<ReturnType<typeof readConfig>>, { ok: true }>) => {
4768
+ const { driverOf } = read;
4769
+ return createRunner({
4770
+ client: session.client,
4771
+ driver: driverOf({
4772
+ spawn: host.spawn,
4735
4773
  cwd: host.cwd,
4736
- env:
4737
- handed?.token === undefined || origin === undefined
4738
- ? { GIT_TERMINAL_PROMPT: "0" }
4739
- : gitTokenEnv(handed.token, origin),
4740
- });
4741
- child.end();
4742
- for await (const _ of child.lines) {
4743
- // Nothing of what git prints is kept.
4744
- }
4745
- return (await child.exited).code;
4746
- },
4747
- // The wake sources the desk names beside the console's own stream, which the runner listens to itself.
4748
- wakes: {
4749
- sources: read.config.wake.flatMap((name) => {
4750
- const source = modules.wakeSources.get(name);
4751
- return source === undefined || source.run === undefined ? [] : [source];
4774
+ command: read.config.product?.command,
4775
+ args: read.config.product?.args,
4776
+ version: io.version,
4752
4777
  }),
4753
- fetch: (url, init) => io.fetch(url, { ...init, headers: { ...init.headers } }),
4754
- socket: (url) => host.socket(url),
4755
- },
4756
- });
4778
+ config: read.config,
4779
+ reconfigured: async () => {
4780
+ const now = await readConfig();
4781
+ return !now.ok ? { problem: now.problem } : now.text === read.text ? "same" : "changed";
4782
+ },
4783
+ cwd: host.cwd,
4784
+ machine: {
4785
+ name: machineLine(io.hostname ?? ""),
4786
+ os: machineLine(host.os),
4787
+ user: machineLine(modules.boundaries.get("os-user")?.user() ?? host.user),
4788
+ },
4789
+ version: io.version ?? "0.0.0",
4790
+ // A runner whose own version is not known has nothing to hold the package's against.
4791
+ installed: io.version === undefined ? undefined : io.installedVersion,
4792
+ // What installs the console's version here, the way this command was installed.
4793
+ updateCommand: () => updateWords(io, io.consoleVersion?.()),
4794
+ now: io.now,
4795
+ random: host.random,
4796
+ time: (iso) => clock.format(new Date(iso)),
4797
+ files: {
4798
+ write: (path, text) => host.writePrivate(workPath(path), text),
4799
+ remove: (path) => host.remove(workPath(path)),
4800
+ },
4801
+ state: {
4802
+ load: async () => runnerStateOf(await host.readText(statePath)),
4803
+ save: (state) => host.writePrivate(statePath, `${JSON.stringify(state)}\n`),
4804
+ },
4805
+ log: (line) => io.stdout(`${new Date(io.now()).toISOString()} ${line}\n`),
4806
+ // The autosave's git: in the desk, asking nobody at a terminal, its words read and let go.
4807
+ // A step that reaches the git host is handed the account's token for it, as the clone of
4808
+ // the desk was: answered from the environment of that one command, and only to the host
4809
+ // the workspace keeps its desks at.
4810
+ git: async (args, handed) => {
4811
+ const origin = gitOriginOf(deskRemoteOf(me.workspace, me.person?.handle ?? ""));
4812
+ const child = host.spawn("git", args, {
4813
+ cwd: host.cwd,
4814
+ env:
4815
+ handed?.token === undefined || origin === undefined
4816
+ ? { GIT_TERMINAL_PROMPT: "0" }
4817
+ : gitTokenEnv(handed.token, origin),
4818
+ });
4819
+ child.end();
4820
+ for await (const _ of child.lines) {
4821
+ // Nothing of what git prints is kept.
4822
+ }
4823
+ return (await child.exited).code;
4824
+ },
4825
+ // The wake sources the desk names beside the console's own stream, which the runner listens to itself.
4826
+ wakes: {
4827
+ sources: read.config.wake.flatMap((name) => {
4828
+ const source = modules.wakeSources.get(name);
4829
+ return source === undefined || source.run === undefined ? [] : [source];
4830
+ }),
4831
+ fetch: (url, init) => io.fetch(url, { ...init, headers: { ...init.headers } }),
4832
+ socket: (url) => host.socket(url),
4833
+ },
4834
+ });
4835
+ };
4836
+ const first = await readConfig();
4837
+ if (!first.ok) {
4838
+ throw failed(
4839
+ `${first.problem}. Nothing of it is used: put it right, or remove it to run with the defaults.`,
4840
+ );
4841
+ }
4757
4842
  io.stdout(
4758
- `The runner of @${me.person.handle ?? me.person.login} at ${me.workspace.name} (${session.url}) starts in ${host.cwd}. Stop with Ctrl+C.\n`,
4843
+ `The runner of @${person.handle ?? person.login} at ${me.workspace.name} (${session.url}) starts in ${host.cwd}. Stop with Ctrl+C.\n`,
4759
4844
  );
4760
- void host.untilStopped().then(() => running.stop());
4761
- if ((await running.run()) === "updated") {
4845
+ // The machine is held awake while the runner runs, where the system has a way that needs no
4846
+ // administrator (ADR-0140): said in the runner's own lines, either way.
4847
+ const said = (line: string): void => io.stdout(`${new Date(io.now()).toISOString()} ${line}\n`);
4848
+ void host
4849
+ .keepAwake?.()
4850
+ .then((awake) =>
4851
+ said(
4852
+ "by" in awake
4853
+ ? `the machine is kept from sleeping while the runner runs (${awake.by})`
4854
+ : `the machine is not kept from sleeping by the runner (${awake.problem}): set it never to sleep when idle`,
4855
+ ),
4856
+ );
4857
+ const how = await keepRunning({
4858
+ first,
4859
+ read: async () => {
4860
+ const next = await readConfig();
4861
+ return next.ok ? { ok: true, config: next } : next;
4862
+ },
4863
+ start: runnerOf,
4864
+ stopped: host.untilStopped(),
4865
+ say: said,
4866
+ });
4867
+ if (how === "updated") {
4762
4868
  // The service that keeps a runner starts it again whenever it ends; one started by hand is
4763
4869
  // started again by hand.
4764
4870
  io.stdout(
@@ -4942,6 +5048,15 @@ async function secretValue(io: CliIo, values: Values, prompt: string): Promise<s
4942
5048
  return value;
4943
5049
  }
4944
5050
 
5051
+ /**
5052
+ * The kind of git host the workspace names, where it names one: what a token for git is held to
5053
+ * the shape of. Asked for the secret that is one alone, since no other is held to a host's shape.
5054
+ */
5055
+ const gitHostFor = async (client: ConsoleClient, name: string): Promise<string | undefined> =>
5056
+ name === GIT_TOKEN_SECRET
5057
+ ? ((await client.me().catch(() => undefined))?.workspace.services?.git?.kind ?? undefined)
5058
+ : undefined;
5059
+
4945
5060
  const SECRET_FLAGS: OptionSpec = {
4946
5061
  set: { type: "boolean" },
4947
5062
  remove: { type: "boolean" },
@@ -4979,11 +5094,13 @@ const secret: Command = async (args, io) => {
4979
5094
  if (on(values, "set")) {
4980
5095
  const expiresOn = expiryOf(io, values);
4981
5096
  const value = await secretValue(io, values, `Value of ${name} (typed unseen; Enter ends it): `);
5097
+ const host = await gitHostFor(session.client, name);
4982
5098
  const kept = await session.client.setSecret(name, {
4983
5099
  value,
4984
5100
  ...(expiresOn === undefined ? {} : { expiresOn }),
4985
5101
  });
4986
- answer(io, session, kept, () => `Kept: ${formatSecretLine(kept)}`);
5102
+ const notes = secretNotes(name, value, host);
5103
+ answer(io, session, kept, () => [`Kept: ${formatSecretLine(kept)}`, ...notes].join("\n"));
4987
5104
  return EXIT.ok;
4988
5105
  }
4989
5106
  // The value alone, for whatever reads it next; the reading is on the account's record.
@@ -5046,15 +5163,151 @@ const agentSecret = async (args: readonly string[], io: CliIo): Promise<number>
5046
5163
  values,
5047
5164
  `Value of ${name} for @${handle} (typed unseen; Enter ends it): `,
5048
5165
  );
5166
+ const host = await gitHostFor(session.client, name);
5049
5167
  const kept = await session.client.seedAgentSecret(handle, name, {
5050
5168
  value,
5051
5169
  ...(expiresOn === undefined ? {} : { expiresOn }),
5052
5170
  });
5053
- answer(
5054
- io,
5055
- session,
5056
- kept,
5057
- () => `Seeded for @${handle}, which alone reads it back: ${formatSecretLine(kept)}`,
5171
+ const notes = secretNotes(name, value, host);
5172
+ answer(io, session, kept, () =>
5173
+ [`Seeded for @${handle}, which alone reads it back: ${formatSecretLine(kept)}`, ...notes].join(
5174
+ "\n",
5175
+ ),
5176
+ );
5177
+ return EXIT.ok;
5178
+ };
5179
+
5180
+ const OWN_WAKE_FLAGS: OptionSpec = {
5181
+ file: { type: "string" },
5182
+ in: { type: "string" },
5183
+ at: { type: "string" },
5184
+ key: { type: "string" },
5185
+ cancel: { type: "boolean" },
5186
+ };
5187
+
5188
+ const OWN_WAKE_USAGE =
5189
+ 'Say when, or nothing for now: console agent wake me ["<words>"] [--in <minutes> | --at <HH:MM>] [--key <name>] | agent wake me --cancel [--key <name>]';
5190
+
5191
+ /** 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. */
5192
+ function minutesOfDayIn(zone: string | undefined, now: Date): number {
5193
+ let parts: Intl.DateTimeFormatPart[];
5194
+ try {
5195
+ parts = new Intl.DateTimeFormat("en-GB", {
5196
+ hour: "2-digit",
5197
+ minute: "2-digit",
5198
+ hourCycle: "h23",
5199
+ ...(zone === undefined ? {} : { timeZone: zone }),
5200
+ }).formatToParts(now);
5201
+ } catch {
5202
+ parts = new Intl.DateTimeFormat("en-GB", {
5203
+ hour: "2-digit",
5204
+ minute: "2-digit",
5205
+ hourCycle: "h23",
5206
+ }).formatToParts(now);
5207
+ }
5208
+ const of = (type: string): number =>
5209
+ Number(parts.find((part) => part.type === type)?.value ?? "0");
5210
+ return of("hour") * 60 + of("minute");
5211
+ }
5212
+
5213
+ /**
5214
+ * When a wake for later is raised, as the flags say it: so many minutes from now, or the next
5215
+ * time the workspace's clock says an hour and a minute; nothing where neither flag is given.
5216
+ */
5217
+ export function ownWakeMoment(
5218
+ given: { readonly in?: string | undefined; readonly at?: string | undefined },
5219
+ zone: string | undefined,
5220
+ now: Date,
5221
+ ): Date | undefined {
5222
+ if (given.in !== undefined && given.at !== undefined) {
5223
+ throw misuse(OWN_WAKE_USAGE);
5224
+ }
5225
+ if (given.in !== undefined) {
5226
+ const minutes = Number(given.in);
5227
+ if (!Number.isInteger(minutes) || minutes < 1 || minutes > MAX_OWN_WAKE_DAYS * 24 * 60) {
5228
+ throw misuse(
5229
+ `Not a number of minutes, from 1 to ${MAX_OWN_WAKE_DAYS * 24 * 60}: ${given.in}`,
5230
+ );
5231
+ }
5232
+ return new Date(now.getTime() + minutes * 60_000);
5233
+ }
5234
+ if (given.at !== undefined) {
5235
+ const clock = /^([01]?[0-9]|2[0-3]):([0-5][0-9])$/.exec(given.at);
5236
+ if (clock === null) {
5237
+ throw misuse(`Not an hour and a minute, as 14:30: ${given.at}`);
5238
+ }
5239
+ const wanted = Number(clock[1]) * 60 + Number(clock[2]);
5240
+ // The next time the clock says so: later today, or tomorrow where that hour has passed.
5241
+ const day = 24 * 60;
5242
+ const ahead = (wanted - minutesOfDayIn(zone, now) + day) % day || day;
5243
+ const at = new Date(now.getTime() + ahead * 60_000);
5244
+ at.setSeconds(0, 0);
5245
+ // Where the zone's clock is put forward or back before then, the moment is off by that
5246
+ // much: moved by what the clock says there, once, where the clock then says the hour asked
5247
+ // for and the moment is still to come. An hour the clock skips that night is no hour of
5248
+ // that day: the moment stays the one counted, just past it.
5249
+ const off = ((wanted - minutesOfDayIn(zone, at) + day + day / 2) % day) - day / 2;
5250
+ const moved = new Date(at.getTime() + off * 60_000);
5251
+ return off !== 0 && moved.getTime() > now.getTime() && minutesOfDayIn(zone, moved) === wanted
5252
+ ? moved
5253
+ : at;
5254
+ }
5255
+ return undefined;
5256
+ }
5257
+
5258
+ // A wake an agent account raises for itself (ADR-0145), by its own command: now, for whoever
5259
+ // prepared its machine or signed something in there to say so and for the agent to go on; or
5260
+ // kept for a moment to come, for an agent that has something to look at again.
5261
+ const ownWake = async (args: readonly string[], io: CliIo): Promise<number> => {
5262
+ const { values, positionals } = parse(args, OWN_WAKE_FLAGS);
5263
+ const [, words, ...rest] = positionals;
5264
+ if (rest.length > 0) {
5265
+ throw misuse(OWN_WAKE_USAGE);
5266
+ }
5267
+ const key = text(values, "key");
5268
+ if (key !== undefined && !/^[a-z0-9][a-z0-9-]{0,39}$/.test(key)) {
5269
+ throw misuse(
5270
+ `Not a name for a wake, which is up to 40 lowercase letters, digits and hyphens: ${key}`,
5271
+ );
5272
+ }
5273
+ const session = await open(io, values);
5274
+ /** A console of before knows no such route: said as what it is. */
5275
+ const asked = async <T>(ask: () => Promise<T>): Promise<T> => {
5276
+ try {
5277
+ return await ask();
5278
+ } catch (error) {
5279
+ if (error instanceof ApiError && error.status === 404 && error.code === "not_found") {
5280
+ throw failed(
5281
+ "This console does not take an account's own wake yet: it does from 0.5.2 on.",
5282
+ );
5283
+ }
5284
+ throw error;
5285
+ }
5286
+ };
5287
+ if (on(values, "cancel")) {
5288
+ const named = key ?? OWN_WAKE_KEY;
5289
+ await asked(() => session.client.cancelOwnWake(named));
5290
+ answer(io, session, { cancelled: named }, () => `The wake ${named} is taken away.`);
5291
+ return EXIT.ok;
5292
+ }
5293
+ const said = ((await bodyOf(io, values, words)) ?? "").trim();
5294
+ const me = await session.client.me();
5295
+ const at = ownWakeMoment(
5296
+ { in: text(values, "in"), at: text(values, "at") },
5297
+ me.workspace.timeZone ?? undefined,
5298
+ new Date(io.now()),
5299
+ );
5300
+ const raised = await asked(() =>
5301
+ session.client.raiseOwnWake({
5302
+ ...(said.length === 0 ? {} : { text: said }),
5303
+ ...(at === undefined ? {} : { at: at.toISOString() }),
5304
+ ...(key === undefined ? {} : { key }),
5305
+ }),
5306
+ );
5307
+ answer(io, session, raised, () =>
5308
+ raised.kept === null
5309
+ ? `Raised, as signal #${raised.signal?.number ?? "?"} of your record: your runner takes it as it takes any wake.`
5310
+ : `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.`,
5058
5311
  );
5059
5312
  return EXIT.ok;
5060
5313
  };
@@ -5078,6 +5331,19 @@ const agentSignal = async (
5078
5331
  args: readonly string[],
5079
5332
  io: CliIo,
5080
5333
  ): Promise<number> => {
5334
+ // An account's own wake is another command under the same word: console agent wake me,
5335
+ // wherever `me` stands among its flags.
5336
+ if (kind === "wake") {
5337
+ let whom: string | undefined;
5338
+ try {
5339
+ whom = parse(args, OWN_WAKE_FLAGS).positionals[0];
5340
+ } catch {
5341
+ whom = undefined;
5342
+ }
5343
+ if (whom === "me") {
5344
+ return ownWake(args, io);
5345
+ }
5346
+ }
5081
5347
  const { values, positionals } = parse(args, { file: { type: "string" } });
5082
5348
  const [given, words, ...rest] = positionals;
5083
5349
  const needs = WORDED_SIGNALS[kind]?.needs === true;
@@ -5159,11 +5425,21 @@ const agentSignals = async (args: readonly string[], io: CliIo): Promise<number>
5159
5425
  ...(limit === undefined ? {} : { limit: Number(limit) }),
5160
5426
  ...(before === undefined ? {} : { before: Number(before) }),
5161
5427
  });
5162
- answer(io, session, found, () =>
5163
- found.items.length === 0
5428
+ // What the account keeps for later (ADR-0145) stands over the record's first page: it is no
5429
+ // signal yet. A console of before keeps none, and says nothing of it.
5430
+ const kept =
5431
+ before === undefined
5432
+ ? await session.client
5433
+ .ownWakes(handle)
5434
+ .then((wakes) => wakes.items)
5435
+ .catch(() => [])
5436
+ : [];
5437
+ answer(io, session, kept.length === 0 ? found : { ...found, kept }, () =>
5438
+ found.items.length === 0 && kept.length === 0
5164
5439
  ? "No signal yet."
5165
5440
  : [
5166
- ...found.items.map(formatSignalLine),
5441
+ ...kept.map(formatOwnWakeLine),
5442
+ ...found.items.map((signal) => formatSignalLine(signal, found.delivered)),
5167
5443
  ...(found.more
5168
5444
  ? [
5169
5445
  `More before: console agent signals ${handle} --before ${found.items.at(-1)?.number}`,
@@ -5224,6 +5500,8 @@ const SETUP_FLAGS: OptionSpec = {
5224
5500
  refresh: { type: "boolean" },
5225
5501
  "new-desk": { type: "boolean" },
5226
5502
  "no-service": { type: "boolean" },
5503
+ driver: { type: "string" },
5504
+ "no-browser": { type: "boolean" },
5227
5505
  };
5228
5506
 
5229
5507
  type Me = Awaited<ReturnType<ConsoleClient["me"]>>;
@@ -5323,6 +5601,8 @@ async function settleDesk(
5323
5601
  workspace: Me["workspace"],
5324
5602
  url: string,
5325
5603
  values: Values,
5604
+ /** What a look at the machine found, for a setup that looked: the driver and the browser a new desk names. */
5605
+ look?: Pick<MachineLook, "driver" | "browser"> | undefined,
5326
5606
  ): Promise<string> {
5327
5607
  const desk = await deskOf(machine, values);
5328
5608
  const handle = person.handle ?? "";
@@ -5354,6 +5634,7 @@ async function settleDesk(
5354
5634
  );
5355
5635
  }
5356
5636
  io.stdout(`The desk is cloned from ${remote} into ${desk}.\n`);
5637
+ await settleDeskGit(io, machine, desk, url, person.login, deskRemoteOf(workspace, handle));
5357
5638
  return desk;
5358
5639
  }
5359
5640
  const written: string[] = [];
@@ -5361,6 +5642,15 @@ async function settleDesk(
5361
5642
  agent: { name: person.name ?? handle, handle, title: person.title ?? null },
5362
5643
  console: { url, workspace: workspace.name },
5363
5644
  services: deskServicesOf(workspace, handle),
5645
+ // The product found on the machine, and its browser: what the runner starts with.
5646
+ runner:
5647
+ look === undefined
5648
+ ? undefined
5649
+ : {
5650
+ ...DEFAULT_RUNNER_CONFIG,
5651
+ ...(look.driver === undefined ? {} : { driver: look.driver }),
5652
+ ...(look.browser === undefined ? {} : { browser: look.browser }),
5653
+ },
5364
5654
  })) {
5365
5655
  const file = machine.path(desk, path);
5366
5656
  if (!(await machine.exists(file))) {
@@ -5369,11 +5659,61 @@ async function settleDesk(
5369
5659
  }
5370
5660
  }
5371
5661
  io.stdout(
5372
- `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`,
5662
+ `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`,
5373
5663
  );
5664
+ await settleDeskGit(io, machine, desk, url, person.login, deskRemoteOf(workspace, handle));
5374
5665
  return desk;
5375
5666
  }
5376
5667
 
5668
+ /**
5669
+ * The desk's own git settings (ADR-0140): a repository where it is none yet, and for the host
5670
+ * the workspace keeps its desks at, a credential helper that reads the account's token from its
5671
+ * store when git asks, in place of whatever the machine has configured. The agent then pushes
5672
+ * with nothing typed, and no copy of the token is left in a keychain or a file. Nothing where
5673
+ * the workspace names no git host, the command does not know how it was started, or git is not
5674
+ * there; what did not succeed is said and the setup goes on.
5675
+ */
5676
+ async function settleDeskGit(
5677
+ io: CliIo,
5678
+ machine: SetupMachine,
5679
+ desk: string,
5680
+ url: string,
5681
+ login: string,
5682
+ remote: string | undefined,
5683
+ ): Promise<void> {
5684
+ const origin = gitOriginOf(remote);
5685
+ if (origin === undefined || machine.self === undefined) {
5686
+ return;
5687
+ }
5688
+ const git = (args: readonly string[]): Promise<Ran> => machine.run("git", ["-C", desk, ...args]);
5689
+ if (!(await machine.exists(machine.path(desk, ".git")))) {
5690
+ if ((await git(["init", "--quiet"])).code !== 0) {
5691
+ return;
5692
+ }
5693
+ }
5694
+ // The helper as git's own shell runs it: every word in single quotes, a path with its
5695
+ // slashes forward, which that shell takes on every system.
5696
+ const word = (text: string): string => `'${text.replaceAll("\\", "/").replaceAll("'", "'\\''")}'`;
5697
+ const read = [...machine.self, "secret", GIT_TOKEN_SECRET, "--url", url, "--account", login]
5698
+ .map(word)
5699
+ .join(" ");
5700
+ const helper = `!f() { test "$1" = get && printf 'username=x-access-token\\npassword=%s\\n' "$(${read})"; }; f`;
5701
+ const key = `credential.${origin}.helper`;
5702
+ const kept = await git(["config", "--local", "--get-all", key]);
5703
+ if (kept.code === 0 && kept.out.includes(GIT_TOKEN_SECRET)) {
5704
+ return;
5705
+ }
5706
+ // An empty helper first: whatever the machine has configured for that host is left out.
5707
+ const cleared = await git(["config", "--local", "--replace-all", key, ""]);
5708
+ const added =
5709
+ cleared.code === 0 ? await git(["config", "--local", "--add", key, helper]) : cleared;
5710
+ io.stdout(
5711
+ added.code === 0
5712
+ ? `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`
5713
+ : `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`,
5714
+ );
5715
+ }
5716
+
5377
5717
  /**
5378
5718
  * The service that keeps the runner running (ADR-0085), by the module of this platform: its
5379
5719
  * files written and, for a first setup, its commands run; answers where the runner's own lines
@@ -5556,7 +5896,7 @@ async function awaitRunner(
5556
5896
  handle: string,
5557
5897
  heardBefore: string | null,
5558
5898
  log: string,
5559
- ): Promise<void> {
5899
+ ): Promise<boolean> {
5560
5900
  for (let tries = 0; tries < RUNNER_HEARD_TRIES; tries += 1) {
5561
5901
  await io.sleep(RUNNER_HEARD_PAUSE_MS);
5562
5902
  const found = await client.agent(handle).catch(() => undefined);
@@ -5564,14 +5904,59 @@ async function awaitRunner(
5564
5904
  const said = found?.runner?.machine ?? null;
5565
5905
  if (heard !== null && heard !== heardBefore && said !== null) {
5566
5906
  io.stdout(
5567
- `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`,
5907
+ `The runner is heard from: ${said.name}, ${said.os}, OS account ${said.user}. @${handle} is set up on this machine.\n`,
5568
5908
  );
5569
- return;
5909
+ return true;
5570
5910
  }
5571
5911
  }
5572
5912
  io.stdout(
5573
- `The runner is not heard from yet. Its own lines are in ${log}; the account's page says when it is.\n`,
5913
+ `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`,
5574
5914
  );
5915
+ return false;
5916
+ }
5917
+
5918
+ /** How often, and how many times, a setup looks whether the agent's first session has begun. */
5919
+ const FIRST_SESSION_PAUSE_MS = 2000;
5920
+ const FIRST_SESSION_TRIES = 30;
5921
+
5922
+ /**
5923
+ * What a setup ends with (ADR-0140): whether the agent's first session has begun, where to
5924
+ * watch it, and that the machine's part ends here, since everything after is the agent's own.
5925
+ */
5926
+ async function handOver(
5927
+ io: CliIo,
5928
+ machine: SetupMachine,
5929
+ client: ConsoleClient,
5930
+ url: string,
5931
+ handle: string,
5932
+ /** Where the runner's own lines are. */
5933
+ log: string,
5934
+ ): Promise<void> {
5935
+ let began = false;
5936
+ for (let tries = 0; tries < FIRST_SESSION_TRIES && !began; tries += 1) {
5937
+ const found = await client.agent(handle).catch(() => undefined);
5938
+ began = (found?.runner?.session ?? null) !== null;
5939
+ if (!began) {
5940
+ await io.sleep(FIRST_SESSION_PAUSE_MS);
5941
+ }
5942
+ }
5943
+ const plate = await client.work().catch(() => undefined);
5944
+ const first = plate?.tasks.find((one) => one.task.title === onboardingTitle(handle));
5945
+ const lines = [
5946
+ began
5947
+ ? `@${handle}'s session has begun: the agent is at work.`
5948
+ : `No session has begun yet: one begins when something wakes @${handle}.`,
5949
+ `Watch it: ${url}${agentHref(handle)}`,
5950
+ ...(first === undefined
5951
+ ? []
5952
+ : [
5953
+ `Its first task: #${first.task.number} "${first.task.title}" in ${first.project.key}, ${url}${taskHref(first.project.key, first.task.number)}`,
5954
+ ]),
5955
+ `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.`,
5956
+ `What you change on this machine afterwards, say to it: console agent wake me "<what changed>"`,
5957
+ awakeWords(machine.platform, await heldAwake(machine), log),
5958
+ ];
5959
+ io.stdout(`${lines.join("\n")}\n`);
5575
5960
  }
5576
5961
 
5577
5962
  // Derives a machine again (ADR-0088): by the account's own command, in its desk, when the
@@ -5666,13 +6051,33 @@ const agentSetup = async (args: readonly string[], io: CliIo): Promise<number> =
5666
6051
  io.stdout(
5667
6052
  `\nSetting this machine up for @${handle}, in the OS account ${machine.user}${io.hostname === undefined ? "" : ` on ${io.hostname}`}.\n`,
5668
6053
  );
6054
+ // The machine first (ADR-0140): everything that is missing is said at once, before anyone is
6055
+ // asked to sign in, and nothing is set up on a machine the runner could not work on.
6056
+ const driver = text(values, "driver");
6057
+ if (
6058
+ driver !== undefined &&
6059
+ ownRunnerModules({ user: machine.user }).drivers.get(driver) === undefined
6060
+ ) {
6061
+ throw misuse(
6062
+ `Not a driver this command has: ${driver}. It has: ${ownRunnerModules({ user: machine.user }).drivers.names().join(", ")}.`,
6063
+ );
6064
+ }
6065
+ const look = await lookAtMachine(machine, { driver, browser: !on(values, "no-browser") });
6066
+ if (look.missing.length > 0) {
6067
+ throw failed(
6068
+ `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")}`,
6069
+ );
6070
+ }
6071
+ io.stdout(
6072
+ `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("")}`,
6073
+ );
5669
6074
  const client = await signInAsAccount(io, machine, url, setup);
5670
6075
  const me = await client.me();
5671
6076
  if (me.person === null) {
5672
6077
  throw failed("The console does not know this sign-in any more. Run the line again.");
5673
6078
  }
5674
6079
  const heardBefore = (await client.agent(handle).catch(() => undefined))?.state?.heardAt ?? null;
5675
- const desk = await settleDesk(io, machine, client, me.person, me.workspace, url, values);
6080
+ const desk = await settleDesk(io, machine, client, me.person, me.workspace, url, values, look);
5676
6081
  if (on(values, "no-service")) {
5677
6082
  io.stdout(
5678
6083
  `No service is written, as asked. Start the runner yourself and keep it running: ${runnerByHand(desk, url, me.person.login, machine.platform)}\n`,
@@ -5680,8 +6085,8 @@ const agentSetup = async (args: readonly string[], io: CliIo): Promise<number> =
5680
6085
  return EXIT.ok;
5681
6086
  }
5682
6087
  const log = await settleService(io, machine, desk, url, me.person.login, "load");
5683
- if (log !== undefined) {
5684
- await awaitRunner(io, client, handle, heardBefore, log);
6088
+ if (log !== undefined && (await awaitRunner(io, client, handle, heardBefore, log))) {
6089
+ await handOver(io, machine, client, url, handle, log);
5685
6090
  }
5686
6091
  return EXIT.ok;
5687
6092
  };
@@ -6320,8 +6725,25 @@ const PROJECT_FIELDS: OptionSpec = {
6320
6725
  skills: { type: "string" },
6321
6726
  color: { type: "string" },
6322
6727
  symbol: { type: "string" },
6728
+ glyph: { type: "string" },
6323
6729
  };
6324
6730
 
6731
+ /** 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. */
6732
+ function glyphOrNoneOf(value: string | undefined): IconName | null | undefined {
6733
+ if (value === undefined) {
6734
+ return undefined;
6735
+ }
6736
+ if (value === "none") {
6737
+ return null;
6738
+ }
6739
+ if (!isIconName(value)) {
6740
+ throw misuse(
6741
+ `No icon of the pack is called ${value}. The pack's icons: ${ICON_NAMES.join(", ")}; none takes the icon away.`,
6742
+ );
6743
+ }
6744
+ return value;
6745
+ }
6746
+
6325
6747
  /** What the flags say of a project; `none` clears what may be cleared. */
6326
6748
  async function projectFieldsOf(io: CliIo, values: Values) {
6327
6749
  const description = await bodyOf(io, values, text(values, "description"));
@@ -6329,6 +6751,7 @@ async function projectFieldsOf(io: CliIo, values: Values) {
6329
6751
  const skills = orNone(text(values, "skills"));
6330
6752
  const color = colorOrNoneOf(text(values, "color"));
6331
6753
  const symbol = orNone(text(values, "symbol"));
6754
+ const glyph = glyphOrNoneOf(text(values, "glyph"));
6332
6755
  return {
6333
6756
  ...(description === undefined
6334
6757
  ? {}
@@ -6337,6 +6760,7 @@ async function projectFieldsOf(io: CliIo, values: Values) {
6337
6760
  ...(skills === undefined ? {} : { skillsAddress: skills }),
6338
6761
  ...(color === undefined ? {} : { color }),
6339
6762
  ...(symbol === undefined ? {} : { symbol }),
6763
+ ...(glyph === undefined ? {} : { glyph }),
6340
6764
  };
6341
6765
  }
6342
6766
 
@@ -6369,7 +6793,7 @@ const editProject: Command = async (args, io) => {
6369
6793
  const patch = { ...(name === undefined ? {} : { name }), ...(await projectFieldsOf(io, values)) };
6370
6794
  if (Object.keys(patch).length === 0) {
6371
6795
  throw misuse(
6372
- "Say what to change: --name, --description, --visibility, --skills, --color or --symbol; none clears the description, the skills address, the colour or the symbol.",
6796
+ "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.",
6373
6797
  );
6374
6798
  }
6375
6799
  const session = await open(io, values);