@skillcdn/console 0.6.2 → 0.6.4

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 (253) hide show
  1. package/README.md +16 -9
  2. package/SKILLCDN.md +3 -2
  3. package/dist/agent-page.d.ts +2 -0
  4. package/dist/agent-page.d.ts.map +1 -1
  5. package/dist/agent-page.js +46 -5
  6. package/dist/agent-page.js.map +1 -1
  7. package/dist/agent-state.d.ts +9 -0
  8. package/dist/agent-state.d.ts.map +1 -0
  9. package/dist/agent-state.js +28 -0
  10. package/dist/agent-state.js.map +1 -0
  11. package/dist/api.d.ts +6 -4
  12. package/dist/api.d.ts.map +1 -1
  13. package/dist/api.js +6 -4
  14. package/dist/api.js.map +1 -1
  15. package/dist/cli/cli.d.ts +2 -0
  16. package/dist/cli/cli.d.ts.map +1 -1
  17. package/dist/cli/cli.js +948 -252
  18. package/dist/cli/cli.js.map +1 -1
  19. package/dist/cli/format.d.ts +44 -7
  20. package/dist/cli/format.d.ts.map +1 -1
  21. package/dist/cli/format.js +168 -13
  22. package/dist/cli/format.js.map +1 -1
  23. package/dist/cli/help.d.ts +82 -9
  24. package/dist/cli/help.d.ts.map +1 -1
  25. package/dist/cli/help.js +855 -331
  26. package/dist/cli/help.js.map +1 -1
  27. package/dist/cli/pack.d.ts +13 -12
  28. package/dist/cli/pack.d.ts.map +1 -1
  29. package/dist/cli/pack.js +33 -45
  30. package/dist/cli/pack.js.map +1 -1
  31. package/dist/cli/plugin-cli.d.ts.map +1 -1
  32. package/dist/cli/plugin-cli.js +8 -5
  33. package/dist/cli/plugin-cli.js.map +1 -1
  34. package/dist/cli/runner-files.d.ts +16 -0
  35. package/dist/cli/runner-files.d.ts.map +1 -0
  36. package/dist/cli/runner-files.js +125 -0
  37. package/dist/cli/runner-files.js.map +1 -0
  38. package/dist/cli/runner-host.d.ts +7 -0
  39. package/dist/cli/runner-host.d.ts.map +1 -1
  40. package/dist/cli/runner-host.js +40 -2
  41. package/dist/cli/runner-host.js.map +1 -1
  42. package/dist/cli/skill-path.d.ts +11 -0
  43. package/dist/cli/skill-path.d.ts.map +1 -0
  44. package/dist/cli/skill-path.js +44 -0
  45. package/dist/cli/skill-path.js.map +1 -0
  46. package/dist/client.d.ts +32 -1
  47. package/dist/client.d.ts.map +1 -1
  48. package/dist/client.js +15 -1
  49. package/dist/client.js.map +1 -1
  50. package/dist/components/agent-page.d.ts +93 -6
  51. package/dist/components/agent-page.d.ts.map +1 -1
  52. package/dist/components/agent-page.js +202 -10
  53. package/dist/components/agent-page.js.map +1 -1
  54. package/dist/components/agents.d.ts +6 -6
  55. package/dist/components/agents.d.ts.map +1 -1
  56. package/dist/components/agents.js +16 -9
  57. package/dist/components/agents.js.map +1 -1
  58. package/dist/components/people.d.ts.map +1 -1
  59. package/dist/components/people.js +7 -2
  60. package/dist/components/people.js.map +1 -1
  61. package/dist/components/picker.d.ts +16 -0
  62. package/dist/components/picker.d.ts.map +1 -1
  63. package/dist/components/picker.js +69 -4
  64. package/dist/components/picker.js.map +1 -1
  65. package/dist/console.css +40 -0
  66. package/dist/console.js +2 -2
  67. package/dist/console.js.map +1 -1
  68. package/dist/feed-words.d.ts.map +1 -1
  69. package/dist/feed-words.js +12 -1
  70. package/dist/feed-words.js.map +1 -1
  71. package/dist/i18n/en.d.ts +64 -6
  72. package/dist/i18n/en.d.ts.map +1 -1
  73. package/dist/i18n/en.js +59 -10
  74. package/dist/i18n/en.js.map +1 -1
  75. package/dist/i18n/ko.d.ts.map +1 -1
  76. package/dist/i18n/ko.js +49 -9
  77. package/dist/i18n/ko.js.map +1 -1
  78. package/dist/limits.d.ts +26 -0
  79. package/dist/limits.d.ts.map +1 -1
  80. package/dist/limits.js +26 -0
  81. package/dist/limits.js.map +1 -1
  82. package/dist/onboarding.d.ts +18 -6
  83. package/dist/onboarding.d.ts.map +1 -1
  84. package/dist/onboarding.js +42 -7
  85. package/dist/onboarding.js.map +1 -1
  86. package/dist/plugin/args.d.ts +24 -2
  87. package/dist/plugin/args.d.ts.map +1 -1
  88. package/dist/plugin/args.js +20 -2
  89. package/dist/plugin/args.js.map +1 -1
  90. package/dist/plugin/context.d.ts +39 -7
  91. package/dist/plugin/context.d.ts.map +1 -1
  92. package/dist/plugin/define.d.ts.map +1 -1
  93. package/dist/plugin/define.js +12 -3
  94. package/dist/plugin/define.js.map +1 -1
  95. package/dist/plugin/rest-schemas.d.ts +2 -0
  96. package/dist/plugin/rest-schemas.d.ts.map +1 -1
  97. package/dist/plugin/rest-schemas.js +1 -0
  98. package/dist/plugin/rest-schemas.js.map +1 -1
  99. package/dist/routes.d.ts +2 -0
  100. package/dist/routes.d.ts.map +1 -1
  101. package/dist/routes.js +2 -0
  102. package/dist/routes.js.map +1 -1
  103. package/dist/rules.d.ts +4 -1
  104. package/dist/rules.d.ts.map +1 -1
  105. package/dist/rules.js +5 -2
  106. package/dist/rules.js.map +1 -1
  107. package/dist/runner/acp.d.ts.map +1 -1
  108. package/dist/runner/acp.js +9 -3
  109. package/dist/runner/acp.js.map +1 -1
  110. package/dist/runner/claude.d.ts.map +1 -1
  111. package/dist/runner/claude.js +53 -1
  112. package/dist/runner/claude.js.map +1 -1
  113. package/dist/runner/codex.d.ts.map +1 -1
  114. package/dist/runner/codex.js +18 -3
  115. package/dist/runner/codex.js.map +1 -1
  116. package/dist/runner/config.d.ts +18 -0
  117. package/dist/runner/config.d.ts.map +1 -1
  118. package/dist/runner/config.js +77 -1
  119. package/dist/runner/config.js.map +1 -1
  120. package/dist/runner/desk.d.ts +7 -0
  121. package/dist/runner/desk.d.ts.map +1 -1
  122. package/dist/runner/desk.js +14 -4
  123. package/dist/runner/desk.js.map +1 -1
  124. package/dist/runner/message.d.ts +16 -22
  125. package/dist/runner/message.d.ts.map +1 -1
  126. package/dist/runner/message.js +72 -120
  127. package/dist/runner/message.js.map +1 -1
  128. package/dist/runner/runner.d.ts +41 -1
  129. package/dist/runner/runner.d.ts.map +1 -1
  130. package/dist/runner/runner.js +557 -23
  131. package/dist/runner/runner.js.map +1 -1
  132. package/dist/runner/slack-status.d.ts +19 -0
  133. package/dist/runner/slack-status.d.ts.map +1 -0
  134. package/dist/runner/slack-status.js +332 -0
  135. package/dist/runner/slack-status.js.map +1 -0
  136. package/dist/runner/slack.d.ts.map +1 -1
  137. package/dist/runner/slack.js +258 -59
  138. package/dist/runner/slack.js.map +1 -1
  139. package/dist/runner/types.d.ts +128 -15
  140. package/dist/runner/types.d.ts.map +1 -1
  141. package/dist/runner/types.js.map +1 -1
  142. package/dist/runner/usage.d.ts +6 -1
  143. package/dist/runner/usage.d.ts.map +1 -1
  144. package/dist/runner/usage.js +9 -2
  145. package/dist/runner/usage.js.map +1 -1
  146. package/dist/runner.d.ts +2 -2
  147. package/dist/runner.d.ts.map +1 -1
  148. package/dist/runner.js.map +1 -1
  149. package/dist/schemas.d.ts +635 -6
  150. package/dist/schemas.d.ts.map +1 -1
  151. package/dist/schemas.js +197 -15
  152. package/dist/schemas.js.map +1 -1
  153. package/dist/secret-file.d.ts +21 -0
  154. package/dist/secret-file.d.ts.map +1 -0
  155. package/dist/secret-file.js +59 -0
  156. package/dist/secret-file.js.map +1 -0
  157. package/dist/services.d.ts.map +1 -1
  158. package/dist/services.js +3 -2
  159. package/dist/services.js.map +1 -1
  160. package/dist/setup-guide.d.ts +2 -2
  161. package/dist/setup-guide.d.ts.map +1 -1
  162. package/dist/setup-guide.js +6 -5
  163. package/dist/setup-guide.js.map +1 -1
  164. package/dist/vocabulary.d.ts +17 -2
  165. package/dist/vocabulary.d.ts.map +1 -1
  166. package/dist/vocabulary.js +15 -2
  167. package/dist/vocabulary.js.map +1 -1
  168. package/dist/wake-text.d.ts +43 -0
  169. package/dist/wake-text.d.ts.map +1 -0
  170. package/dist/wake-text.js +115 -0
  171. package/dist/wake-text.js.map +1 -0
  172. package/docs/specs/cli.md +39 -25
  173. package/docs/specs/plugins.md +10 -9
  174. package/docs/specs/rest.md +34 -15
  175. package/docs/specs/runner.md +108 -25
  176. package/docs/start.md +28 -6
  177. package/package.json +3 -3
  178. package/skills/building-a-plugin/SKILL.md +2 -2
  179. package/skills/deploying-a-console/SKILL.md +3 -3
  180. package/skills/deploying-a-console/references/access.md +15 -1
  181. package/skills/deploying-a-console/references/resources.md +2 -2
  182. package/skills/deploying-a-console/scripts/github-app.mjs +593 -0
  183. package/skills/keeping-the-pack/SKILL.md +87 -0
  184. package/skills/planning-the-board/SKILL.md +6 -6
  185. package/skills/planning-the-board/references/a-task.md +1 -1
  186. package/skills/planning-the-board/references/setting-up.md +9 -5
  187. package/skills/running-an-agent/SKILL.md +21 -17
  188. package/skills/running-an-agent/references/preparing-the-machine.md +4 -3
  189. package/skills/running-an-agent/references/several-tasks.md +8 -2
  190. package/skills/running-an-agent/references/slack-app.md +31 -8
  191. package/skills/running-an-agent/references/the-account-and-the-invitation.md +1 -1
  192. package/skills/running-an-agent/references/what-was-not-seen-run-yet.md +3 -1
  193. package/skills/running-an-agent/references/when-the-agent-could-not-go-on.md +4 -4
  194. package/skills/running-an-agent/references/your-first-task.md +11 -5
  195. package/skills/trying-a-console/SKILL.md +136 -0
  196. package/skills/trying-a-console/references/when-it-does-not-go.md +30 -0
  197. package/skills/working-the-board/SKILL.md +6 -6
  198. package/skills/working-the-board/references/terms.md +3 -1
  199. package/skills/working-the-board/references/the-pack.md +14 -7
  200. package/skills/working-the-board/references/what-they-were-told.md +1 -1
  201. package/src/agent-page.tsx +111 -4
  202. package/src/agent-state.ts +33 -0
  203. package/src/api.ts +43 -0
  204. package/src/cli/cli.ts +1190 -313
  205. package/src/cli/format.ts +207 -13
  206. package/src/cli/help.ts +991 -372
  207. package/src/cli/pack.ts +55 -62
  208. package/src/cli/plugin-cli.ts +8 -5
  209. package/src/cli/runner-files.ts +137 -0
  210. package/src/cli/runner-host.ts +48 -2
  211. package/src/cli/skill-path.ts +51 -0
  212. package/src/client.ts +103 -0
  213. package/src/components/agent-page.tsx +446 -20
  214. package/src/components/agents.tsx +27 -28
  215. package/src/components/people.tsx +7 -3
  216. package/src/components/picker.tsx +79 -5
  217. package/src/console.tsx +1 -1
  218. package/src/feed-words.ts +14 -1
  219. package/src/i18n/en.ts +64 -11
  220. package/src/i18n/ko.ts +55 -9
  221. package/src/limits.ts +26 -0
  222. package/src/onboarding.ts +60 -21
  223. package/src/plugin/args.ts +29 -3
  224. package/src/plugin/context.ts +40 -7
  225. package/src/plugin/define.ts +18 -3
  226. package/src/plugin/rest-schemas.ts +3 -0
  227. package/src/routes.ts +2 -0
  228. package/src/rules.ts +5 -2
  229. package/src/runner/acp.ts +9 -3
  230. package/src/runner/claude.ts +58 -1
  231. package/src/runner/codex.ts +18 -3
  232. package/src/runner/config.ts +114 -1
  233. package/src/runner/desk.ts +15 -4
  234. package/src/runner/message.ts +88 -126
  235. package/src/runner/runner.ts +682 -27
  236. package/src/runner/slack-status.ts +423 -0
  237. package/src/runner/slack.ts +310 -67
  238. package/src/runner/types.ts +124 -13
  239. package/src/runner/usage.ts +16 -3
  240. package/src/runner.ts +4 -0
  241. package/src/schemas.ts +245 -13
  242. package/src/secret-file.ts +76 -0
  243. package/src/services.ts +3 -2
  244. package/src/setup-guide.ts +6 -5
  245. package/src/styles/README.md +1 -1
  246. package/src/styles/pages/agents.css +40 -0
  247. package/src/vocabulary.ts +21 -2
  248. package/src/wake-text.ts +133 -0
  249. package/dist/cli/command-words.d.ts +0 -20
  250. package/dist/cli/command-words.d.ts.map +0 -1
  251. package/dist/cli/command-words.js +0 -51
  252. package/dist/cli/command-words.js.map +0 -1
  253. package/src/cli/command-words.ts +0 -56
package/src/cli/cli.ts CHANGED
@@ -1,22 +1,8 @@
1
1
  import { basename, extname, isAbsolute } from "node:path";
2
2
  import { parseArgs } from "node:util";
3
3
  import { deflateSync } from "node:zlib";
4
- import {
5
- PackError,
6
- type PackRead,
7
- ReadMisuse,
8
- type ReadOutput,
9
- readNumber,
10
- readPack,
11
- wroteLine,
12
- } from "@skillcdn/cli";
13
- import {
14
- BROWSE_MAX_LIMIT,
15
- FIND_MAX_LIMIT,
16
- READ_FILE_MAX_LIMIT,
17
- type ToolWords,
18
- utf8Length,
19
- } from "@skillcdn/core";
4
+ import type { PackRead, ReadOutput } from "@skillcdn/cli";
5
+ import type { ToolWords } from "@skillcdn/core";
20
6
  import { avatarScanlines, MAX_AVATAR_PIXELS, pngFile } from "../avatar.js";
21
7
  import {
22
8
  ApiError,
@@ -47,12 +33,18 @@ import {
47
33
  EVENTS_PAGE_LIMIT,
48
34
  LIST_LIMIT,
49
35
  MAX_DECIDERS,
36
+ MAX_OPTION_LABEL_LENGTH,
50
37
  MAX_OPTIONS,
51
38
  MAX_OWN_WAKE_DAYS,
39
+ MAX_PACK_NOTE_LENGTH,
40
+ MAX_PACK_NOTE_OUTCOME_LENGTH,
41
+ MAX_PACK_NOTES_PAGE_LIMIT,
42
+ MAX_QUESTION_LENGTH,
52
43
  MAX_RUNNER_LINE_LENGTH,
53
44
  MAX_SIGNALS_PAGE_LIMIT,
54
45
  MIN_OPTIONS,
55
46
  OWN_WAKE_KEY,
47
+ PACK_NOTES_PAGE_LIMIT,
56
48
  } from "../limits.js";
57
49
  import {
58
50
  MAX_NOTIFICATIONS_PAGE,
@@ -76,16 +68,12 @@ import {
76
68
  } from "../runner/desk.js";
77
69
  import { quotedLines } from "../runner/message.js";
78
70
  import { ownRunnerModules } from "../runner/modules.js";
79
- import {
80
- createRunner,
81
- GIT_TOKEN_SECRET,
82
- type Runner,
83
- type RunnerEnd,
84
- type RunnerState,
85
- } from "../runner/runner.js";
71
+ import { createRunner, GIT_TOKEN_SECRET, type Runner, type RunnerEnd } from "../runner/runner.js";
86
72
  import type { ServiceCommand } from "../runner/types.js";
87
73
  import {
88
74
  hostOfLogin,
75
+ isPackNotePath,
76
+ type RestAgentInput,
89
77
  type RestAgentSetup,
90
78
  type RestAnswerInput,
91
79
  type RestClaim,
@@ -104,7 +92,9 @@ import {
104
92
  type RestSignal,
105
93
  type RestTask,
106
94
  type RestTaskPatch,
95
+ type RestWorkspace,
107
96
  } from "../schemas.js";
97
+ import { secretOfText } from "../secret-file.js";
108
98
  import { agentLoginOf, deskRemoteOf } from "../services.js";
109
99
  import { setupGuideOf, setupGuideText, setupSentenceOf } from "../setup-guide.js";
110
100
  import {
@@ -132,7 +122,6 @@ import {
132
122
  WEEK_STARTS,
133
123
  } from "../vocabulary.js";
134
124
  import { loadWebRoot, type WebRoot, WebRootError } from "../web.js";
135
- import { commandLine, commandWord, NO_LINE_TO_RUN } from "./command-words.js";
136
125
  import {
137
126
  type CredentialStore,
138
127
  type Credentials,
@@ -179,6 +168,9 @@ import {
179
168
  formatNotifications,
180
169
  formatOptions,
181
170
  formatOwnWakeLine,
171
+ formatPackNoteClosed,
172
+ formatPackNoteLeft,
173
+ formatPackNotes,
182
174
  formatPersonLine,
183
175
  formatPersonWork,
184
176
  formatPlugin,
@@ -199,6 +191,7 @@ import {
199
191
  formatRun,
200
192
  formatRunLine,
201
193
  formatSecretLine,
194
+ formatSecretOffer,
202
195
  formatSignalLine,
203
196
  formatTask,
204
197
  formatTaskFollow,
@@ -208,13 +201,22 @@ import {
208
201
  formatVersionLine,
209
202
  formatWork,
210
203
  formatWorkspace,
204
+ type KeeperCalled,
211
205
  localized,
212
206
  moment,
213
207
  pageLine,
214
208
  rulesMark,
215
209
  setMomentZone,
216
210
  } from "./format.js";
217
- import { COMMAND_HELP, helpFor, ownSkillPath, usage } from "./help.js";
211
+ import {
212
+ COMMAND_ALIASES,
213
+ formTyped,
214
+ held,
215
+ helpFor,
216
+ nearestCommands,
217
+ ownSkillPath,
218
+ usage,
219
+ } from "./help.js";
218
220
  import { describeInstall, type Install, updateCommandFor } from "./install.js";
219
221
  import {
220
222
  awakeWords,
@@ -225,19 +227,8 @@ import {
225
227
  standsInTheWay,
226
228
  } from "./machine-check.js";
227
229
  import type { NoticeStore } from "./notices.js";
228
- import {
229
- type ConsolePack,
230
- consolePack,
231
- formatSkills,
232
- holdsNothing,
233
- ORGANIZATION_PACK_LINE,
234
- type PackOwner,
235
- PackRefusal,
236
- packWords,
237
- refusalWords,
238
- skillPathIn,
239
- skillsAround,
240
- } from "./pack.js";
230
+ import type { ConsolePack, PackOwner } from "./pack.js";
231
+ import { keptBySourceOf, keptFileOf, runnerStateOf } from "./runner-files.js";
241
232
  import { type RunnerHost, workPath } from "./runner-host.js";
242
233
  import { secretNotes } from "./secret-notes.js";
243
234
  import {
@@ -249,6 +240,7 @@ import {
249
240
  RecordsRootError,
250
241
  } from "./serve.js";
251
242
  import type { Ran, SetupMachine } from "./setup-machine.js";
243
+ import { skillPathIn } from "./skill-path.js";
252
244
 
253
245
  // The `console` command (docs/specs/cli.md): the agent's side of the console. A thin client of
254
246
  // the REST API with no logic of its own: every command is one or two requests and the words to
@@ -415,10 +407,71 @@ function parse(args: readonly string[], options: OptionSpec, allowPositionals =
415
407
  options: { ...GLOBAL_OPTIONS, ...options },
416
408
  allowPositionals,
417
409
  strict: true,
410
+ // The words in the order they were typed, for a search, whose words are every bare word.
411
+ tokens: true,
418
412
  });
419
413
  } catch (error) {
420
- throw misuse(error instanceof Error ? error.message : "The arguments were not understood.");
414
+ throw misuse(refusedByParser(error, options));
415
+ }
416
+ }
417
+
418
+ /**
419
+ * The words of a search as they were typed (ADR-0179): what `--search` was given and every
420
+ * bare word, in their order, as the skillcdn command takes every word after `find` as the
421
+ * query. So `--search card news` asks for two words, where the second was once read as a
422
+ * folder and the search, of one word in a folder nobody named, found nothing. Nothing where no
423
+ * `--search` was typed: a bare word is then the command's own to read.
424
+ */
425
+ function searchTyped(parsed: ReturnType<typeof parse>): string | undefined {
426
+ if (typeof parsed.values.search !== "string") {
427
+ return undefined;
421
428
  }
429
+ const typed: string[] = [];
430
+ for (const token of parsed.tokens) {
431
+ if (token.kind === "positional") {
432
+ typed.push(token.value);
433
+ } else if (token.kind === "option" && token.name === "search" && token.value !== undefined) {
434
+ typed.push(token.value);
435
+ }
436
+ }
437
+ return typed.join(" ").trim();
438
+ }
439
+
440
+ /**
441
+ * What the parser refused, in the command's own words (ADR-0167): an option that is none of
442
+ * the command's is answered with those it takes, so that the next try needs no page of help;
443
+ * what the parser says of a value is said as it says it, without its advice on other things.
444
+ */
445
+ function refusedByParser(error: unknown, options: OptionSpec): string {
446
+ if (!(error instanceof Error)) {
447
+ return "The arguments were not understood.";
448
+ }
449
+ const code = "code" in error ? String(error.code) : "";
450
+ // What was typed is between the parser's first quote and the one its sentence goes on
451
+ // after: a word may hold a quote of its own (`it's`), and is said whole.
452
+ const ADVICE = ". To specify a positional argument ";
453
+ const named =
454
+ (code === "ERR_PARSE_ARGS_UNKNOWN_OPTION"
455
+ ? /^Unknown option '(.*?)'(?:\. To specify a positional argument .*)?$/s
456
+ : /^Unexpected argument '(.*)'\. This command does not take positional arguments$/s
457
+ ).exec(error.message)?.[1] ??
458
+ /'([^']*)'/.exec(error.message)?.[1] ??
459
+ "";
460
+ if (code === "ERR_PARSE_ARGS_UNKNOWN_OPTION") {
461
+ const own = Object.keys(options).map((name) => `--${name}`);
462
+ const takes = own.length === 0 ? "It takes none of its own" : `Its own are ${own.join(", ")}`;
463
+ // A word of a report or a title may begin with a dash, and is then no option at all:
464
+ // said where the command takes a word, and what was typed does not read as an option.
465
+ const dashed =
466
+ !error.message.includes(ADVICE) || /^--[a-z][a-z0-9-]*$/.test(named)
467
+ ? ""
468
+ : " A word that begins with - and is no option goes after --.";
469
+ return `Not an option of this command: ${named}. ${takes}; --json, --project, --url and --account go with every command.${dashed}`;
470
+ }
471
+ if (code === "ERR_PARSE_ARGS_UNEXPECTED_POSITIONAL") {
472
+ return `This command takes no word beside its options: ${named}.`;
473
+ }
474
+ return error.message;
422
475
  }
423
476
 
424
477
  type Values = ReturnType<typeof parse>["values"];
@@ -1608,7 +1661,7 @@ const whoami: Command = async (args, io) => {
1608
1661
  // agent here for where the skill is, and the workspace has rules whatever the project.
1609
1662
  // The skill's path stands last, with nothing after it, to be copied as it is.
1610
1663
  io.skillsDir === undefined
1611
- ? "Before the first task, read console rules and the skill working-the-board (console skills says where it is); for one command's flags, console help <command>."
1664
+ ? "Before the first task, read console rules and the skill working-the-board (in the skills folder of the package @skillcdn/console, which this build has none of beside it); for one command's flags, console help <command>."
1612
1665
  : `Before the first task, read console rules and the skill working-the-board; for one command's flags, console help <command>. The skill: ${ownSkillPath(io.skillsDir)}`,
1613
1666
  `This command is ${io.version ?? "of a version it does not know"}${io.install === undefined ? "" : `, ${describeInstall(io.install)}`}; ${consoleWords}.`,
1614
1667
  ...(verdict === "behind"
@@ -1632,11 +1685,15 @@ const projects: Command = async (args, io) => {
1632
1685
  const { values } = parse(args, {}, false);
1633
1686
  const session = await open(io, values);
1634
1687
  const found = await session.client.projects();
1635
- answer(io, session, found, () =>
1688
+ // In none: an administrator makes one, and anyone else is listed in one by an administrator.
1689
+ // Asked only then, so that a listing costs no request more.
1690
+ const none =
1636
1691
  found.items.length === 0
1637
- ? 'No projects you may work in. Make one: console project new <key> "<name>"'
1638
- : found.items.map(formatProjectLine).join("\n"),
1639
- );
1692
+ ? (await session.client.me()).person?.role === "admin"
1693
+ ? 'No projects you may work in. Make one: console project new <key> "<name>"'
1694
+ : "No projects you may work in. An administrator lists you in one, or opens one to the workspace, which has everyone in it."
1695
+ : undefined;
1696
+ answer(io, session, found, () => none ?? found.items.map(formatProjectLine).join("\n"));
1640
1697
  return EXIT.ok;
1641
1698
  };
1642
1699
 
@@ -1696,23 +1753,40 @@ async function endOfWeek(io: CliIo, session: Session, today: string): Promise<st
1696
1753
  return weekOf(today, firstDayOfWeek(language, me.workspace.weekStart ?? "auto")).at(-1) ?? today;
1697
1754
  }
1698
1755
 
1756
+ /**
1757
+ * The words a listing is searched by (ADR-0179): what `--search` was given and every bare word,
1758
+ * in the order typed, for a listing that takes no word of its own. A bare word without
1759
+ * `--search` is not understood, and the answer says where the words of a search go.
1760
+ */
1761
+ function listingSearch(parsed: ReturnType<typeof parse>, command: string): string | undefined {
1762
+ const search = searchTyped(parsed);
1763
+ if (search === undefined && parsed.positionals.length > 0) {
1764
+ throw misuse(
1765
+ `This command takes no word beside its options: ${parsed.positionals[0]}. The words of a search go after --search: ${command} --search "<words>"`,
1766
+ );
1767
+ }
1768
+ if (search === "") {
1769
+ throw misuse(`Say what to search for: ${command} --search "<words>"`);
1770
+ }
1771
+ return search;
1772
+ }
1773
+
1699
1774
  const tasks: Command = async (args, io) => {
1700
- const { values } = parse(
1701
- args,
1702
- {
1703
- state: { type: "string" },
1704
- open: { type: "boolean" },
1705
- mine: { type: "boolean" },
1706
- unassigned: { type: "boolean" },
1707
- category: { type: "string" },
1708
- goal: { type: "string" },
1709
- due: { type: "string" },
1710
- search: { type: "string" },
1711
- archived: { type: "boolean" },
1712
- ...PAGE_OPTIONS,
1713
- },
1714
- false,
1715
- );
1775
+ const parsed = parse(args, {
1776
+ state: { type: "string" },
1777
+ open: { type: "boolean" },
1778
+ mine: { type: "boolean" },
1779
+ unassigned: { type: "boolean" },
1780
+ category: { type: "string" },
1781
+ goal: { type: "string" },
1782
+ due: { type: "string" },
1783
+ search: { type: "string" },
1784
+ archived: { type: "boolean" },
1785
+ ...PAGE_OPTIONS,
1786
+ });
1787
+ const { values } = parsed;
1788
+ // Every bare word is of the search where --search was typed, and no word goes without it.
1789
+ const search = listingSearch(parsed, "console tasks");
1716
1790
  const state = stateOf(text(values, "state"));
1717
1791
  if (on(values, "mine") && on(values, "unassigned")) {
1718
1792
  throw misuse(
@@ -1734,10 +1808,6 @@ const tasks: Command = async (args, io) => {
1734
1808
  ? await endOfWeek(io, session, today)
1735
1809
  : (dayOf(io, due) ?? undefined);
1736
1810
  const worker = on(values, "mine") ? ((await personIdOf(session, "me")) ?? undefined) : undefined;
1737
- const search = text(values, "search")?.trim();
1738
- if (search === "") {
1739
- throw misuse("Say what to search for: console tasks --search <words>");
1740
- }
1741
1811
  const filter = {
1742
1812
  ...(state === undefined ? {} : { state }),
1743
1813
  ...(on(values, "open") || due === "overdue" ? { open: true } : {}),
@@ -1800,13 +1870,41 @@ const categories: Command = async (args, io) => {
1800
1870
  /** What reads a pack: a project's client, a plugin's, whose skills are a pack of their own, or the console's for the organization's. */
1801
1871
  type PackReader = PackClient;
1802
1872
 
1873
+ /**
1874
+ * The reads of a pack, with the skillcdn command's own library behind them (ADR-0124), loaded
1875
+ * by the commands that read a pack and by no other (ADR-0179): importing it loads the whole of
1876
+ * @skillcdn/cli and @skillcdn/core, a quarter of a second that a report, a take or a page of
1877
+ * help would pay for nothing.
1878
+ */
1879
+ type PackReads = typeof import("./pack.js");
1880
+ const packReads = (): Promise<PackReads> => import("./pack.js");
1881
+
1882
+ /**
1883
+ * The reads of a pack where only a word is to be spelled, after an act that is done: nothing
1884
+ * where the library does not load, so that what was done is said all the same and the words
1885
+ * are named in a sentence, never a line, as where a word has no spelling every shell takes.
1886
+ */
1887
+ async function packReadsAfter(): Promise<PackReads | undefined> {
1888
+ try {
1889
+ return await packReads();
1890
+ } catch {
1891
+ return undefined;
1892
+ }
1893
+ }
1894
+
1895
+ /** The flags `whereGiven` names, said in words: `--project and --url`. */
1896
+ const flagNamesOf = (given: readonly string[]): string =>
1897
+ given.filter((_, index) => index % 2 === 0).join(" and ");
1898
+
1803
1899
  const SKILLS_OPTIONS: OptionSpec = {
1804
1900
  search: { type: "string" },
1805
1901
  path: { type: "string" },
1902
+ full: { type: "boolean" },
1806
1903
  limit: { type: "string" },
1807
1904
  cursor: { type: "string" },
1808
1905
  rows: { type: "boolean" },
1809
1906
  code: { type: "boolean" },
1907
+ kinds: { type: "boolean" },
1810
1908
  heading: { type: "string" },
1811
1909
  format: { type: "string" },
1812
1910
  grep: { type: "string" },
@@ -1820,6 +1918,7 @@ const SKILLS_OPTIONS: OptionSpec = {
1820
1918
  * the status. Thrown by the caller, so that nothing follows it.
1821
1919
  */
1822
1920
  function refusedRead(
1921
+ reads: PackReads,
1823
1922
  io: CliIo,
1824
1923
  session: Session,
1825
1924
  owner: PackOwner,
@@ -1829,7 +1928,7 @@ function refusedRead(
1829
1928
  if (session.json) {
1830
1929
  io.stdout(`${JSON.stringify(answered, null, 2)}\n`);
1831
1930
  }
1832
- return failed(owner === "organization" ? `${ORGANIZATION_PACK_LINE}\n${words}` : words);
1931
+ return failed(owner === "organization" ? `${reads.ORGANIZATION_PACK_LINE}\n${words}` : words);
1833
1932
  }
1834
1933
 
1835
1934
  /** A whole number a flag carries, within its bounds; nothing when it is not given. */
@@ -1858,11 +1957,16 @@ function countOf(
1858
1957
  * A number a read of a pack takes, checked as the skillcdn command checks it and said in its
1859
1958
  * words, before anything is asked of the console.
1860
1959
  */
1861
- function checkedNumber(given: string | undefined, name: string, most: number): void {
1960
+ function checkedNumber(
1961
+ reads: PackReads,
1962
+ given: string | undefined,
1963
+ name: string,
1964
+ most: number,
1965
+ ): void {
1862
1966
  try {
1863
- readNumber(given, name, most);
1967
+ reads.readNumber(given, name, most);
1864
1968
  } catch (error) {
1865
- throw error instanceof ReadMisuse ? misuse(error.message) : error;
1969
+ throw error instanceof reads.ReadMisuse ? misuse(error.message) : error;
1866
1970
  }
1867
1971
  }
1868
1972
 
@@ -1888,6 +1992,7 @@ function whereGiven(values: Readonly<Record<string, unknown>>): readonly string[
1888
1992
  * the whole output is one a host shows whole.
1889
1993
  */
1890
1994
  async function readThrough(
1995
+ reads: PackReads,
1891
1996
  io: CliIo,
1892
1997
  session: Session,
1893
1998
  owner: PackOwner,
@@ -1896,25 +2001,31 @@ async function readThrough(
1896
2001
  options: {
1897
2002
  readonly words: ToolWords;
1898
2003
  readonly nextPart?: ((cursor: string) => string) | undefined;
2004
+ readonly browseFolder?: ((path: string) => string) | undefined;
2005
+ readonly readFile?: ((path: string) => string) | undefined;
2006
+ readonly loadFound?: string | undefined;
1899
2007
  readonly data?: boolean | undefined;
1900
2008
  readonly beside?: readonly (string | undefined)[] | undefined;
1901
2009
  },
1902
2010
  ): Promise<ReadOutput> {
1903
2011
  try {
1904
- return await readPack(pack, read, {
2012
+ return await reads.readPack(pack, read, {
1905
2013
  words: options.words,
1906
2014
  json: session.json,
1907
2015
  nextPart: options.nextPart,
1908
- room: roomFor(owner, options.beside ?? []),
2016
+ browseFolder: options.browseFolder,
2017
+ readFile: options.readFile,
2018
+ loadFound: options.loadFound,
2019
+ room: roomFor(reads, owner, options.beside ?? []),
1909
2020
  });
1910
2021
  } catch (error) {
1911
- if (error instanceof ReadMisuse) {
2022
+ if (error instanceof reads.ReadMisuse) {
1912
2023
  throw misuse(error.message);
1913
2024
  }
1914
2025
  const refusal =
1915
- error instanceof PackRefusal
1916
- ? { answer: error.answer, words: refusalWords(error.what, error.answer, owner) }
1917
- : error instanceof PackError
2026
+ error instanceof reads.PackRefusal
2027
+ ? { answer: error.answer, words: reads.refusalWords(error.what, error.answer, owner) }
2028
+ : error instanceof reads.PackError
1918
2029
  ? { answer: pack.answered(), words: `${error.code}: ${error.message}` }
1919
2030
  : undefined;
1920
2031
  if (refusal === undefined) {
@@ -1922,7 +2033,7 @@ async function readThrough(
1922
2033
  }
1923
2034
  throw options.data === true || refusal.answer === undefined
1924
2035
  ? failed(refusal.words)
1925
- : refusedRead(io, session, owner, refusal.answer, refusal.words);
2036
+ : refusedRead(reads, io, session, owner, refusal.answer, refusal.words);
1926
2037
  }
1927
2038
  }
1928
2039
 
@@ -1931,10 +2042,14 @@ async function readThrough(
1931
2042
  * its own with the break that sets it apart, and the line that says the pack is the
1932
2043
  * organization's where it is.
1933
2044
  */
1934
- function roomFor(owner: PackOwner, beside: readonly (string | undefined)[]): number {
1935
- const lines = [owner === "organization" ? ORGANIZATION_PACK_LINE : undefined, ...beside];
2045
+ function roomFor(
2046
+ reads: PackReads,
2047
+ owner: PackOwner,
2048
+ beside: readonly (string | undefined)[],
2049
+ ): number {
2050
+ const lines = [owner === "organization" ? reads.ORGANIZATION_PACK_LINE : undefined, ...beside];
1936
2051
  return lines.reduce(
1937
- (bytes, line) => (line === undefined ? bytes : bytes + utf8Length(line) + 1),
2052
+ (bytes, line) => (line === undefined ? bytes : bytes + reads.utf8Length(line) + 1),
1938
2053
  0,
1939
2054
  );
1940
2055
  }
@@ -1954,6 +2069,7 @@ function jsonOfRead(session: Session, pack: ConsolePack, output: ReadOutput): un
1954
2069
  * refusal: a read the pack refused fails with why.
1955
2070
  */
1956
2071
  async function readData(
2072
+ reads: PackReads,
1957
2073
  io: CliIo,
1958
2074
  session: Session,
1959
2075
  pack: ConsolePack,
@@ -1965,12 +2081,12 @@ async function readData(
1965
2081
  },
1966
2082
  ): Promise<number> {
1967
2083
  const { read } = asked;
1968
- const output = await readThrough(io, session, asked.owner, pack, read, {
2084
+ const output = await readThrough(reads, io, session, asked.owner, pack, read, {
1969
2085
  words: asked.words,
1970
2086
  data: true,
1971
2087
  });
1972
2088
  // Nothing is printed for nothing, which a program takes as it is; a line beside it says so.
1973
- if (holdsNothing(output.holds) && asked.out === undefined && !session.json) {
2089
+ if (reads.holdsNothing(output.holds) && asked.out === undefined && !session.json) {
1974
2090
  io.stderr(
1975
2091
  `No ${read.read === "rows" ? "tables" : "code blocks"} in ${read.path ?? "the pack"}${read.heading === undefined ? "" : " under that heading"}.\n`,
1976
2092
  );
@@ -1991,7 +2107,7 @@ async function readData(
1991
2107
  } catch {
1992
2108
  throw failed(`The file could not be written at ${asked.out}.`);
1993
2109
  }
1994
- io.stdout(`${wroteLine(output.holds ?? "", saved)}\n`);
2110
+ io.stdout(`${reads.wroteLine(output.holds ?? "", saved)}\n`);
1995
2111
  return EXIT.ok;
1996
2112
  }
1997
2113
 
@@ -2007,17 +2123,28 @@ const PLUGIN_SKILLS_LINE =
2007
2123
  "The plugins of this console have skills of their own: console plugins lists the plugins, console plugin <key> skills the skills of one.";
2008
2124
 
2009
2125
  /**
2010
- * The pack as the words say: whole, a page of a folder or of a file's outline, or what words
2011
- * find; for the project's pack as `console skills`, and for a plugin's as
2012
- * `console plugin <key> skills`. Each as the skillcdn command reads it, through its own reads
2013
- * (ADR-0124).
2126
+ * What stands in place of the line that reads on from a cursor where a word of it has no
2127
+ * spelling every shell takes: the cursor, and what to give it to. Its reader ran the command,
2128
+ * so it has the other words.
2129
+ */
2130
+ const readOnWithoutLine = (reads: PackReads, cursor: string): string =>
2131
+ `the command you ran, with --cursor ${reads.commandLine("", [cursor])?.trim() ?? JSON.stringify(cursor)} in place of any it had, each word quoted for your shell. ${reads.NO_LINE_TO_RUN}`;
2132
+
2133
+ /** A folder or a file of a pack as it was typed, without the slashes it may end with: `design/` is `design`, and `/` the root. */
2134
+ const folderOf = (typed: string | undefined): string | undefined => typed?.replace(/\/+$/, "");
2135
+
2136
+ /**
2137
+ * The pack as the words say: whole, its kinds of work, a page of a folder or of a file's
2138
+ * outline, or what words find; for the project's pack as `console skills`, and for a plugin's
2139
+ * as `console plugin <key> skills`. Each as the skillcdn command reads it, through its own reads
2140
+ * (ADR-0124), and asked for by that command's own arguments after the flag that names the read
2141
+ * (ADR-0179): with `--search`, every bare word is of the query and a folder is `--path`.
2014
2142
  */
2015
2143
  async function readSkills(
2016
2144
  io: CliIo,
2017
2145
  session: Session,
2018
2146
  reader: PackReader,
2019
- values: Values,
2020
- positionals: readonly string[],
2147
+ parsed: ReturnType<typeof parse>,
2021
2148
  extras: {
2022
2149
  /** The command these words came after, for what is said when they are not understood. */
2023
2150
  readonly command: string;
@@ -2031,31 +2158,58 @@ async function readSkills(
2031
2158
  readonly again?: readonly string[] | undefined;
2032
2159
  },
2033
2160
  ): Promise<number> {
2161
+ const { values, positionals } = parsed;
2162
+ const reads = await packReads();
2034
2163
  const owner = extras.owner ?? "project";
2164
+ const again = extras.again ?? [];
2035
2165
  const say = (value: unknown, words: () => string): void =>
2036
- answerPack(io, session, owner, value, words);
2166
+ answerPack(reads, io, session, owner, value, words);
2037
2167
  // The reads by the names of this pack's own commands: a plugin's are not the project's.
2038
2168
  const skillCommand = extras.command.replace(/skills$/, "skill");
2039
- const toolWords = packWords(extras.command, skillCommand);
2040
- // How a skill is loaded, said after a listing and after what a search found: the pack's own
2041
- // words there name how a section is read, and a skill read as a file comes without its rules.
2169
+ const toolWords = reads.packWords(extras.command, skillCommand);
2170
+ // How a skill is loaded, said after a listing: the pack's own words there name how a section
2171
+ // is read, and a skill read as a file comes without its rules. A search says its next step
2172
+ // itself, once (`loadFound`).
2042
2173
  const loading = `A skill is loaded, its rules first, with ${skillCommand} <the path of its SKILL.md>, a long one in parts; --file reads a file of the pack as it is, without the rules.`;
2043
- if (positionals.length > 1) {
2044
- throw misuse(`Say one folder: ${extras.command} [<folder>] [--search <words>]`);
2045
- }
2046
- // The root of the pack is the mounted folder, which the deployment reads as no path at all.
2047
- const given = positionals[0];
2048
- const words = text(values, "search");
2049
- const within = text(values, "path");
2174
+ const words = searchTyped(parsed);
2175
+ // A folder is taken as the pack prints it, `design/`, and as it is named, `design`, as a
2176
+ // folder of the documents is: the deployment refuses a path that ends with a slash.
2177
+ const within = folderOf(text(values, "path"));
2178
+ const full = on(values, "full");
2050
2179
  const limit = text(values, "limit");
2051
2180
  const cursor = text(values, "cursor");
2052
2181
  const rows = on(values, "rows");
2053
2182
  const code = on(values, "code");
2183
+ const kinds = on(values, "kinds");
2054
2184
  const heading = text(values, "heading");
2055
2185
  const out = text(values, "out");
2056
2186
  const format = text(values, "format");
2057
2187
  const grep = text(values, "grep");
2188
+ const searchUsage = `${extras.command} --search "<words>" [--path <folder>] [--full] [--limit <n>]`;
2189
+ // With --search every bare word is of the query; without it, the one bare word is a folder
2190
+ // or a file of the pack.
2191
+ if (words === undefined && positionals.length > 1) {
2192
+ throw misuse(
2193
+ `Say one folder, or the words of a search after --search: ${extras.command} [<folder>], or ${searchUsage}`,
2194
+ );
2195
+ }
2196
+ if (words !== undefined && words.length === 0) {
2197
+ throw misuse(`Say what to search for: ${searchUsage}`);
2198
+ }
2199
+ // The root of the pack is the mounted folder, which the deployment reads as no path at all.
2200
+ const given = words === undefined ? folderOf(positionals[0]) : undefined;
2058
2201
  const dataUsage = `${extras.command} --rows|--code [<folder|file>] [--heading <words>] [--out <path>]`;
2202
+ // The kinds of work are of the pack whole, and are said in a few lines: nothing narrows them.
2203
+ if (
2204
+ kinds &&
2205
+ (given !== undefined ||
2206
+ rows ||
2207
+ code ||
2208
+ full ||
2209
+ [words, within, limit, cursor, heading, out, format, grep].some((one) => one !== undefined))
2210
+ ) {
2211
+ throw misuse(`--kinds goes alone: ${extras.command} --kinds`);
2212
+ }
2059
2213
  if (rows && code) {
2060
2214
  throw misuse(`Say one: --rows for the tables, or --code for the code blocks: ${dataUsage}`);
2061
2215
  }
@@ -2080,20 +2234,18 @@ async function readSkills(
2080
2234
  `--grep goes with --code: ${extras.command} --code [<folder|file>] [--grep <pattern>]`,
2081
2235
  );
2082
2236
  }
2083
- // The folder a search keeps to is said once: after the words, or with --path as the
2084
- // skillcdn command takes it.
2237
+ // The folder a search keeps to is said with --path, as the skillcdn command takes it, and
2238
+ // everything a search prints of a result with --full.
2085
2239
  if (within !== undefined && words === undefined) {
2086
2240
  throw misuse(
2087
- `--path goes with --search; a folder is read with ${extras.command} <folder>: ${extras.command} --search <words> [--path <folder>]`,
2241
+ `--path goes with --search; a folder is read with ${extras.command} <folder>: ${searchUsage}`,
2088
2242
  );
2089
2243
  }
2090
- if (within !== undefined && given !== undefined) {
2091
- throw misuse(
2092
- `Say the folder once: after the words, or with --path: ${extras.command} --search <words> [<folder>]`,
2093
- );
2244
+ if (full && words === undefined) {
2245
+ throw misuse(`--full goes with --search: ${searchUsage}`);
2094
2246
  }
2095
2247
  const named = given ?? within;
2096
- const folder = named === undefined || named === "/" || named === "." ? undefined : named;
2248
+ const folder = named === undefined || named === "" || named === "." ? undefined : named;
2097
2249
  // The listing is as long as one read prints, and goes on from the cursor its page ended with.
2098
2250
  if (words === undefined && given === undefined && limit !== undefined) {
2099
2251
  throw misuse(
@@ -2101,20 +2253,25 @@ async function readSkills(
2101
2253
  );
2102
2254
  }
2103
2255
  // A page of what words find, or of what a folder holds: the bounds of each, as the pack has them.
2104
- checkedNumber(limit, "limit", words === undefined ? BROWSE_MAX_LIMIT : FIND_MAX_LIMIT);
2256
+ checkedNumber(
2257
+ reads,
2258
+ limit,
2259
+ "limit",
2260
+ words === undefined ? reads.BROWSE_MAX_LIMIT : reads.FIND_MAX_LIMIT,
2261
+ );
2105
2262
  const listing = await reader.skills();
2106
2263
  // With --json the console's own addresses stay in a document's outline; in words, the
2107
2264
  // commands that read its tables and its code blocks.
2108
- const pack = consolePack(reader, listing, {
2265
+ const pack = reads.consolePack(reader, listing, {
2109
2266
  url: session.url,
2110
2267
  dataCommand: session.json ? undefined : extras.command,
2111
2268
  });
2112
2269
  // As data: a read the pack refused fails with why, and nothing is printed.
2113
2270
  if (rows || code) {
2114
2271
  if (pack === undefined) {
2115
- throw failed(refusalWords(rows ? "tables" : "code blocks", listing, owner));
2272
+ throw failed(reads.refusalWords(rows ? "tables" : "code blocks", listing, owner));
2116
2273
  }
2117
- return readData(io, session, pack, {
2274
+ return readData(reads, io, session, pack, {
2118
2275
  read: rows
2119
2276
  ? { read: "rows", path: folder, heading, format }
2120
2277
  : { read: "code", path: folder, heading, grep },
@@ -2126,15 +2283,50 @@ async function readSkills(
2126
2283
  // A pack that does not answer: said as that, which a folder or a search would meet too.
2127
2284
  if (pack === undefined) {
2128
2285
  throw refusedRead(
2286
+ reads,
2129
2287
  io,
2130
2288
  session,
2131
2289
  owner,
2132
2290
  listing,
2133
- [formatSkills(listing, undefined, extras.own, owner, toolWords), extras.afterwards]
2291
+ [reads.formatSkills(listing, undefined, extras.own, owner, toolWords), extras.afterwards]
2134
2292
  .filter((part): part is string => part !== undefined)
2135
2293
  .join("\n"),
2136
2294
  );
2137
2295
  }
2296
+ // A file of the pack is named by the line that reads it, whole, asked as this read was
2297
+ // (SkillCDN 0.6.4): the page a pack says to start from, an overview, the manifest.
2298
+ const readFile = (path: string): string =>
2299
+ reads.commandLine(skillCommand, ["--file", path, ...again]) ??
2300
+ `${skillCommand} --file with this file's path, quoted for your shell. ${reads.NO_LINE_TO_RUN}`;
2301
+ if (kinds) {
2302
+ // The kinds of work the pack has skills for (ADR-0176), as the skillcdn command reads them
2303
+ // (ADR-0179): its lines, its bound and its closing sentence, in the words of this pack's
2304
+ // commands, made of the one answer the console already has. Read once in a conversation.
2305
+ // --json is the kinds as that command prints them as data. The search and the load it
2306
+ // names are asked where this read was: without --project a desk reads the organization's
2307
+ // pack, which may be another than the one these kinds are of.
2308
+ const where = again.length === 0 ? "" : reads.commandLine("", again);
2309
+ const told = await readThrough(
2310
+ reads,
2311
+ io,
2312
+ session,
2313
+ owner,
2314
+ pack,
2315
+ { read: "kinds" },
2316
+ {
2317
+ words:
2318
+ where === undefined
2319
+ ? {
2320
+ ...toolWords,
2321
+ search: `${extras.command} --search, asked with ${flagNamesOf(again)} as this read was and quoted for your shell,`,
2322
+ load: `${skillCommand}, asked so too,`,
2323
+ }
2324
+ : reads.packWords(`${extras.command}${where}`, `${skillCommand}${where}`),
2325
+ },
2326
+ );
2327
+ say(session.json ? JSON.parse(told.text) : undefined, () => told.text);
2328
+ return EXIT.ok;
2329
+ }
2138
2330
  if (words === undefined && given === undefined) {
2139
2331
  // --json is the console's listing as it answered it, whole; the words are the pack's own,
2140
2332
  // read once more from that answer, a listing longer than one read prints in pages.
@@ -2144,7 +2336,7 @@ async function readSkills(
2144
2336
  }
2145
2337
  // The console's own lines stand around the first page, and the read keeps room for them
2146
2338
  // and for the empty lines that set them apart.
2147
- const around = skillsAround(listing, extras.own, toolWords);
2339
+ const around = reads.skillsAround(listing, extras.own, toolWords);
2148
2340
  const own = [
2149
2341
  ...around.host,
2150
2342
  ...around.own,
@@ -2152,6 +2344,7 @@ async function readSkills(
2152
2344
  ...(extras.afterwards === undefined ? [] : [extras.afterwards]),
2153
2345
  ];
2154
2346
  const told = await readThrough(
2347
+ reads,
2155
2348
  io,
2156
2349
  session,
2157
2350
  owner,
@@ -2160,9 +2353,10 @@ async function readSkills(
2160
2353
  {
2161
2354
  words: toolWords,
2162
2355
  beside: cursor === undefined ? [around.head, ...own, "", "", ""] : [],
2356
+ readFile,
2163
2357
  nextPart: (next) =>
2164
- commandLine(extras.command, ["--cursor", next, ...(extras.again ?? [])]) ??
2165
- `${extras.command} with --cursor ${commandWord(next) ?? JSON.stringify(next)}, each word quoted for your shell. ${NO_LINE_TO_RUN}`,
2358
+ reads.commandLine(extras.command, ["--cursor", next, ...again]) ??
2359
+ `${extras.command} with --cursor ${reads.commandLine("", [next])?.trim() ?? JSON.stringify(next)}, each word quoted for your shell. ${reads.NO_LINE_TO_RUN}`,
2166
2360
  },
2167
2361
  );
2168
2362
  say(listing, () => {
@@ -2176,7 +2370,7 @@ async function readSkills(
2176
2370
  // lines stand above the listing then, and after it where it is whole.
2177
2371
  return told.next === undefined
2178
2372
  ? [
2179
- formatSkills(listing, told.text, extras.own, owner, toolWords),
2373
+ reads.formatSkills(listing, told.text, extras.own, owner, toolWords),
2180
2374
  loading,
2181
2375
  ...(extras.afterwards === undefined ? [] : [extras.afterwards]),
2182
2376
  ].join("\n")
@@ -2184,28 +2378,65 @@ async function readSkills(
2184
2378
  });
2185
2379
  return EXIT.ok;
2186
2380
  }
2381
+ // The command that reads the next page of a folder or of a search (SkillCDN 0.6.3): this
2382
+ // one again, asked as it was, with the cursor the page ended on. Where a word of it has no
2383
+ // spelling every shell takes, the command that was run is run again, and the line says why.
2384
+ const nextPage =
2385
+ (asked: readonly string[]) =>
2386
+ (next: string): string =>
2387
+ reads.commandLine(extras.command, [
2388
+ ...asked,
2389
+ ...(limit === undefined ? [] : ["--limit", limit]),
2390
+ ...(full ? ["--full"] : []),
2391
+ "--cursor",
2392
+ next,
2393
+ ...again,
2394
+ ]) ?? readOnWithoutLine(reads, next);
2187
2395
  if (words !== undefined) {
2188
- // One page of what the words find; more is said, and asked for with --cursor.
2396
+ // One page of what the words find, as the skillcdn command prints it (ADR-0179): each
2397
+ // result with what choosing needs and how it matches, and, where a skill was found, the
2398
+ // next step once, the command that loads it, asked as this search was. A page that ends
2399
+ // before the results do ends with the command that reads the next: the words as one word
2400
+ // of the line, which every version of the command reads as the query, the folder as --path.
2401
+ const where = reads.commandLine("", again);
2189
2402
  const found = await readThrough(
2403
+ reads,
2190
2404
  io,
2191
2405
  session,
2192
2406
  owner,
2193
2407
  pack,
2194
- { read: "find", words, path: folder, cursor, limit },
2195
- { words: toolWords, beside: [loading] },
2408
+ { read: "find", words, path: folder, cursor, limit, full },
2409
+ {
2410
+ words: toolWords,
2411
+ readFile,
2412
+ loadFound:
2413
+ where === undefined
2414
+ ? `${skillCommand} with its path and where this pack is read, each quoted for your shell. ${reads.NO_LINE_TO_RUN}`
2415
+ : `${skillCommand} <its path>${where}`,
2416
+ nextPart: nextPage([
2417
+ "--search",
2418
+ words,
2419
+ ...(folder === undefined ? [] : ["--path", folder]),
2420
+ ]),
2421
+ },
2196
2422
  );
2197
- say(jsonOfRead(session, pack, found), () => `${found.text}\n${loading}`);
2423
+ say(jsonOfRead(session, pack, found), () => found.text);
2198
2424
  return EXIT.ok;
2199
2425
  }
2200
2426
  // One page of the folder, or of a file's outline, as the skillcdn command browses: a page
2201
- // that ends before the folder does names the cursor that continues it.
2427
+ // that ends before the folder does ends with the command that reads the next.
2202
2428
  const browsed = await readThrough(
2429
+ reads,
2203
2430
  io,
2204
2431
  session,
2205
2432
  owner,
2206
2433
  pack,
2207
2434
  { read: "browse", path: folder, cursor, limit },
2208
- { words: toolWords },
2435
+ {
2436
+ words: toolWords,
2437
+ readFile,
2438
+ nextPart: nextPage(folder === undefined ? [] : [folder]),
2439
+ },
2209
2440
  );
2210
2441
  say(jsonOfRead(session, pack, browsed), () => browsed.text);
2211
2442
  return EXIT.ok;
@@ -2229,6 +2460,7 @@ async function packNamed(
2229
2460
  * the line that says so. `--json` stays what the console answered.
2230
2461
  */
2231
2462
  function answerPack(
2463
+ reads: PackReads,
2232
2464
  io: CliIo,
2233
2465
  session: Session,
2234
2466
  owner: PackOwner,
@@ -2236,15 +2468,158 @@ function answerPack(
2236
2468
  words: () => string,
2237
2469
  ): void {
2238
2470
  answer(io, session, value, () =>
2239
- owner === "organization" ? `${ORGANIZATION_PACK_LINE}\n${words()}` : words(),
2471
+ owner === "organization" ? `${reads.ORGANIZATION_PACK_LINE}\n${words()}` : words(),
2240
2472
  );
2241
2473
  }
2242
2474
 
2475
+ /**
2476
+ * What the console answers of the notes on the pack (ADR-0178), where it has them: one of
2477
+ * before answers their path as nothing, which is said as what it is, with where the finding
2478
+ * goes meanwhile, since a skill's load named the command whatever the console is.
2479
+ */
2480
+ async function ofPackNotes<T>(io: CliIo, asked: Promise<T>): Promise<T> {
2481
+ try {
2482
+ return await asked;
2483
+ } catch (error) {
2484
+ if (noSuchRoute(error)) {
2485
+ const version = io.consoleVersion?.();
2486
+ throw failed(
2487
+ `This console${version === undefined ? "" : `, ${version},`} takes no notes on the pack yet: it is older than the command. Say what the run showed where the work is reported.`,
2488
+ );
2489
+ }
2490
+ throw error;
2491
+ }
2492
+ }
2493
+
2494
+ /** What `console skills --notes` takes beside what a read of the pack takes. */
2495
+ const SKILLS_NOTES_OPTIONS: OptionSpec = {
2496
+ notes: { type: "boolean" },
2497
+ all: { type: "boolean" },
2498
+ mine: { type: "boolean" },
2499
+ offset: { type: "string" },
2500
+ };
2501
+ const SKILLS_NOTES_USAGE =
2502
+ "console skills --notes [<folder|path>] [--all] [--mine] [--limit <n>] [--offset <n>]";
2503
+
2504
+ /** How a keeper closes a note, and how an author takes one back: said under a list of them. */
2505
+ const NOTE_CLOSING =
2506
+ 'Close one with what became of it: console skill note <id> --done "<what changed, and where>", or --drop "<why nothing was>".';
2507
+ const NOTE_TAKING_BACK =
2508
+ 'These are your own; whoever keeps the skills reads everyone\'s. Take one back: console skill note <id> --drop "<why>".';
2509
+
2510
+ /**
2511
+ * The notes on the pack (ADR-0178), as the asker reads them: everyone's for whoever keeps the
2512
+ * skills and for an administrator, their own for anyone else. To whoever keeps them, the list
2513
+ * ends with how one is closed and where a keeper's work is written, the skill keeping-the-pack
2514
+ * with its place on this machine: a keeper woken for a round reads it from here, and nobody
2515
+ * else pays for a word of it.
2516
+ */
2517
+ async function listNotes(
2518
+ io: CliIo,
2519
+ session: Session,
2520
+ values: Values,
2521
+ positionals: readonly string[],
2522
+ ): Promise<number> {
2523
+ if (positionals.length > 1) {
2524
+ throw misuse(`Say one folder or path: ${SKILLS_NOTES_USAGE}`);
2525
+ }
2526
+ if (
2527
+ ["search", "path", "cursor", "heading", "format", "grep", "out"].some(
2528
+ (name) => text(values, name) !== undefined,
2529
+ ) ||
2530
+ ["rows", "code", "kinds", "full"].some((name) => on(values, name))
2531
+ ) {
2532
+ throw misuse(
2533
+ `--notes lists the notes on the pack, and reads nothing of it: ${SKILLS_NOTES_USAGE}`,
2534
+ );
2535
+ }
2536
+ const limit = numberOf(text(values, "limit"), "limit", 1, MAX_PACK_NOTES_PAGE_LIMIT);
2537
+ const offset = numberOf(text(values, "offset"), "offset", 0, 1_000_000);
2538
+ const all = on(values, "all");
2539
+ const page = { limit: limit ?? PACK_NOTES_PAGE_LIMIT, offset: offset ?? 0, all };
2540
+ const found = await ofPackNotes(
2541
+ io,
2542
+ session.client.packNotes({
2543
+ state: all ? "all" : "open",
2544
+ mine: on(values, "mine"),
2545
+ path: positionals[0] === undefined ? undefined : notePathOf(positionals[0]),
2546
+ limit: page.limit,
2547
+ offset: page.offset,
2548
+ }),
2549
+ );
2550
+ const closing = found.everyones
2551
+ ? [
2552
+ NOTE_CLOSING,
2553
+ `What whoever keeps the skills changes alone, what waits for a person and what a round may spend is the skill keeping-the-pack, shipped with this command${io.skillsDir === undefined ? " (in the skills folder of the package @skillcdn/console, which this build has none of beside it)." : `: ${ownSkillPath(io.skillsDir, "keeping-the-pack")}`}`,
2554
+ ]
2555
+ : found.items.length === 0
2556
+ ? []
2557
+ : [NOTE_TAKING_BACK];
2558
+ answer(io, session, found, () => formatPackNotes(found, page, closing));
2559
+ return EXIT.ok;
2560
+ }
2561
+
2562
+ /** A whole number a flag names, within its bounds; nothing where the flag was not given. */
2563
+ function numberOf(
2564
+ given: string | undefined,
2565
+ name: string,
2566
+ least: number,
2567
+ most: number,
2568
+ ): number | undefined {
2569
+ if (given === undefined) {
2570
+ return undefined;
2571
+ }
2572
+ const value = Number(given);
2573
+ if (!/^\d+$/.test(given) || value < least || value > most) {
2574
+ throw misuse(`--${name} is a whole number from ${least} to ${most}: ${given}`);
2575
+ }
2576
+ return value;
2577
+ }
2578
+
2579
+ /**
2580
+ * A path of the pack as a note names it: from the root, with no slash at either end, and a
2581
+ * skill by its folder, which is what a skill is called, whether its `SKILL.md` or its folder
2582
+ * was said. A URI the pack names a skill by is its path.
2583
+ */
2584
+ function notePathOf(given: string): string {
2585
+ const named = skillPathIn(given, null);
2586
+ if ("error" in named) {
2587
+ throw misuse(named.error);
2588
+ }
2589
+ const from = (given.startsWith("skill://") ? named.path : given)
2590
+ .trim()
2591
+ .replace(/^(?:\.\/)+/, "")
2592
+ .replace(/^\/+|\/+$/g, "");
2593
+ // A pack that is one skill has it at its root, which the load's own line calls `.`.
2594
+ if (from === "." || from === "SKILL.md") {
2595
+ return ".";
2596
+ }
2597
+ const path = from.replace(/\/SKILL\.md$/, "");
2598
+ if (path.length === 0) {
2599
+ throw misuse(
2600
+ 'Say which skill or page the note is on, by its path in the pack; for a job no skill fit: console skill note --none "<the job, and the words searched>"',
2601
+ );
2602
+ }
2603
+ if (!isPackNotePath(path)) {
2604
+ throw misuse(
2605
+ `Not a path of the pack: ${given}. Say the skill's folder or the page's path from the pack's root, as console skills lists it, with no . or .. among its parts.`,
2606
+ );
2607
+ }
2608
+ return path;
2609
+ }
2610
+
2243
2611
  const skills: Command = async (args, io) => {
2244
- const { values, positionals } = parse(args, SKILLS_OPTIONS);
2612
+ const parsed = parse(args, { ...SKILLS_OPTIONS, ...SKILLS_NOTES_OPTIONS });
2613
+ const { values, positionals } = parsed;
2614
+ if (on(values, "notes")) {
2615
+ return listNotes(io, await open(io, values), values, positionals);
2616
+ }
2617
+ if (on(values, "all") || on(values, "mine") || text(values, "offset") !== undefined) {
2618
+ throw misuse(`--all, --mine and --offset go with --notes: ${SKILLS_NOTES_USAGE}`);
2619
+ }
2245
2620
  const session = await open(io, values);
2246
2621
  const { reader, owner } = await packNamed(session);
2247
- return readSkills(io, session, reader, values, positionals, {
2622
+ return readSkills(io, session, reader, parsed, {
2248
2623
  command: "console skills",
2249
2624
  own: io.skillsDir,
2250
2625
  afterwards: PLUGIN_SKILLS_LINE,
@@ -2271,9 +2646,10 @@ async function readSkill(
2271
2646
  owner: PackOwner = "project",
2272
2647
  again: readonly string[] = [],
2273
2648
  ): Promise<number> {
2649
+ const reads = await packReads();
2274
2650
  const say = (value: unknown, words: () => string): void =>
2275
- answerPack(io, session, owner, value, words);
2276
- const toolWords = packWords(`${command}s`, command);
2651
+ answerPack(reads, io, session, owner, value, words);
2652
+ const toolWords = reads.packWords(`${command}s`, command);
2277
2653
  const file = text(values, "file");
2278
2654
  const cursor = text(values, "cursor");
2279
2655
  // A file is read by its own path from the repository's root; a skill's path beside it would be
@@ -2298,29 +2674,36 @@ async function readSkill(
2298
2674
  `--cursor reads the next part of a skill; a file reads on from --offset: ${command} --file <path> [--offset <n>] [--limit <n>]`,
2299
2675
  );
2300
2676
  }
2301
- checkedNumber(text(values, "offset"), "offset", Number.MAX_SAFE_INTEGER);
2302
- checkedNumber(text(values, "limit"), "limit", READ_FILE_MAX_LIMIT);
2677
+ checkedNumber(reads, text(values, "offset"), "offset", Number.MAX_SAFE_INTEGER);
2678
+ checkedNumber(reads, text(values, "limit"), "limit", reads.READ_FILE_MAX_LIMIT);
2303
2679
  const listing = await reader.skills();
2304
- const pack = consolePack(reader, listing, { url: session.url });
2680
+ const pack = reads.consolePack(reader, listing, { url: session.url });
2305
2681
  if (pack === undefined) {
2306
2682
  throw refusedRead(
2683
+ reads,
2307
2684
  io,
2308
2685
  session,
2309
2686
  owner,
2310
2687
  listing,
2311
- formatSkills(listing, undefined, io.skillsDir, owner, toolWords),
2688
+ reads.formatSkills(listing, undefined, io.skillsDir, owner, toolWords),
2312
2689
  );
2313
2690
  }
2691
+ // A file of the pack is named by the line that reads it, whole, asked as this read was
2692
+ // (SkillCDN 0.6.4): the source a skill names, and what a folder read as a file holds.
2693
+ const readFile = (path: string): string =>
2694
+ reads.commandLine(command, ["--file", path, ...again]) ??
2695
+ `${command} --file with this file's path, quoted for your shell. ${reads.NO_LINE_TO_RUN}`;
2314
2696
  if (file !== undefined) {
2315
2697
  // A page of the file, as the skillcdn command reads one: from --offset, as long as a host
2316
2698
  // shows whole where --limit says nothing, and where the next begins when the file goes on.
2317
2699
  const page = await readThrough(
2700
+ reads,
2318
2701
  io,
2319
2702
  session,
2320
2703
  owner,
2321
2704
  pack,
2322
2705
  { read: "file", path: file, offset: text(values, "offset"), limit: text(values, "limit") },
2323
- { words: toolWords },
2706
+ { words: toolWords, readFile },
2324
2707
  );
2325
2708
  say(jsonOfRead(session, pack, page), () => page.text);
2326
2709
  return EXIT.ok;
@@ -2337,26 +2720,151 @@ async function readSkill(
2337
2720
  // the cursor. A part says how many pages of the skill follow it and ends with the command
2338
2721
  // that reads the next, asked as this one was, and the last says that it is the last: the
2339
2722
  // words are the skillcdn command's own (SkillCDN 0.6.2), and only the line is made here.
2723
+ // What a load of the project's or the organization's pack ends with (ADR-0178): the command
2724
+ // that leaves a note on this skill, with its folder in it, read by whoever is about to use
2725
+ // the skill and nobody else. A plugin's pack is its package's, and takes no note here.
2726
+ const noting =
2727
+ command === "console skill" && !session.json
2728
+ ? noteLineFor(reads, skillFolderOf(wanted.path), again)
2729
+ : undefined;
2340
2730
  const loaded = await readThrough(
2731
+ reads,
2341
2732
  io,
2342
2733
  session,
2343
2734
  owner,
2344
2735
  pack,
2345
2736
  { read: "skill", path: wanted.path, cursor },
2346
2737
  {
2738
+ beside: [noting],
2347
2739
  words: toolWords,
2348
- // Spelled so that bash and PowerShell run it as it is; where a word has no such spelling,
2349
- // the command that was run is run again, with the cursor, and the line says why.
2740
+ readFile,
2741
+ // Spelled so that every shell runs it as it is; where a word has no such spelling, the
2742
+ // command that was run is run again, with the cursor, and the line says why.
2350
2743
  nextPart: (next) =>
2351
- commandLine(command, [given, "--cursor", next, ...again]) ??
2352
- `the command you ran, with --cursor ${commandWord(next) ?? JSON.stringify(next)} in place of any it had, each word quoted for your shell. ${NO_LINE_TO_RUN}`,
2744
+ reads.commandLine(command, [given, "--cursor", next, ...again]) ??
2745
+ readOnWithoutLine(reads, next),
2746
+ // The skill's own folder, where it does not list every file of it, as the command that
2747
+ // lists a folder of this pack (SkillCDN 0.6.3): the dot for the root, since the command
2748
+ // without a folder is the listing.
2749
+ browseFolder: (path) =>
2750
+ reads.commandLine(`${command}s`, [path.length === 0 ? "." : path, ...again]) ??
2751
+ `${command}s with this skill's folder, quoted for your shell. ${reads.NO_LINE_TO_RUN}`,
2353
2752
  },
2354
2753
  );
2355
- say(jsonOfRead(session, pack, loaded), () => loaded.text);
2754
+ // After the last part alone: a part that is not the last ends with the command for the next.
2755
+ say(jsonOfRead(session, pack, loaded), () =>
2756
+ noting === undefined || loaded.next !== undefined
2757
+ ? loaded.text
2758
+ : `${loaded.text.replace(/\n+$/, "")}\n${noting}`,
2759
+ );
2760
+ return EXIT.ok;
2761
+ }
2762
+
2763
+ /** A skill's folder, which is what a skill is called, from the path of its `SKILL.md`. */
2764
+ const skillFolderOf = (path: string): string => path.replace(/(?:^|\/)SKILL\.md$/, "") || ".";
2765
+
2766
+ /**
2767
+ * The line a skill's load ends with: where a run shows the skill wrong or lacking, the command
2768
+ * that says so to whoever keeps the pack, asked as this load was. The words are a placeholder,
2769
+ * so the line is printed whole only where the folder has a spelling every shell takes.
2770
+ */
2771
+ function noteLineFor(reads: PackReads, folder: string, again: readonly string[]): string {
2772
+ const line = reads.commandLine("console skill note", [folder]);
2773
+ const where = reads.commandLine("", again)?.trim() ?? "";
2774
+ return `Where a run shows this skill wrong or lacking, say so for whoever keeps the pack, as behavior and without the run's own material: ${line ?? "console skill note <this skill's folder>"} "<what the run showed>"${where.length === 0 ? "" : ` ${where}`}`;
2775
+ }
2776
+
2777
+ const SKILL_NOTE_USAGE =
2778
+ 'console skill note <path> "<what a run showed>" | console skill note --none "<the job, and the words searched>" | console skill note <id> --done "<what changed>" | console skill note <id> --drop "<why nothing was>"';
2779
+ const NOTE_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
2780
+
2781
+ /** What a note says, given as a word or, as `-`, on standard input: something, after its edges are trimmed. */
2782
+ async function noteWords(io: CliIo, given: string): Promise<string> {
2783
+ const words = (given === "-" ? await io.readStdin() : given).trim();
2784
+ if (words.length === 0) {
2785
+ throw misuse(`A note says something: ${SKILL_NOTE_USAGE}`);
2786
+ }
2787
+ if (words.length > MAX_PACK_NOTE_LENGTH) {
2788
+ throw misuse(
2789
+ `A note is at most ${MAX_PACK_NOTE_LENGTH} characters, and this is ${words.length}: say what the run showed in a few sentences, as behavior, without the run's own material.`,
2790
+ );
2791
+ }
2792
+ return words;
2793
+ }
2794
+
2795
+ /**
2796
+ * A note on the pack (ADR-0178): left on a skill or a page of it, or with `--none` for a job no
2797
+ * skill fit, by anyone who works through the console; and closed, by its id, with what became
2798
+ * of it, by whoever keeps the skills, or taken back by its author. It is left on the pack the
2799
+ * command reads: the project's where one is named, else the organization's.
2800
+ */
2801
+ async function skillNote(args: readonly string[], io: CliIo): Promise<number> {
2802
+ const { values, positionals } = parse(args, {
2803
+ none: { type: "boolean" },
2804
+ done: { type: "string" },
2805
+ drop: { type: "string" },
2806
+ });
2807
+ const done = text(values, "done");
2808
+ const drop = text(values, "drop");
2809
+ const none = on(values, "none");
2810
+ if (done !== undefined || drop !== undefined) {
2811
+ if ((done !== undefined && drop !== undefined) || none) {
2812
+ throw misuse(`Say one of --done and --drop, with the note's id: ${SKILL_NOTE_USAGE}`);
2813
+ }
2814
+ const id = theOne(
2815
+ positionals,
2816
+ `Say which note, by its id as console skills --notes lists it: ${SKILL_NOTE_USAGE}`,
2817
+ );
2818
+ if (!NOTE_ID.test(id)) {
2819
+ throw misuse(
2820
+ `Not a note's id: ${id}. console skills --notes lists the notes with their ids.`,
2821
+ );
2822
+ }
2823
+ const outcome = (done ?? drop ?? "").trim();
2824
+ if (outcome.length === 0 || outcome.length > MAX_PACK_NOTE_OUTCOME_LENGTH) {
2825
+ throw misuse(
2826
+ `Say what became of the note, in up to ${MAX_PACK_NOTE_OUTCOME_LENGTH} characters: ${SKILL_NOTE_USAGE}`,
2827
+ );
2828
+ }
2829
+ const session = await open(io, values);
2830
+ const closed = await ofPackNotes(
2831
+ io,
2832
+ session.client.closePackNote(id, {
2833
+ state: done === undefined ? "dropped" : "done",
2834
+ outcome,
2835
+ }),
2836
+ );
2837
+ answer(io, session, closed, () => formatPackNoteClosed(closed));
2838
+ return EXIT.ok;
2839
+ }
2840
+ // `console skill note` alone read, before this form, as the load of a skill whose folder is
2841
+ // called note: that load is still there, by the path of its file, and the sentence says so.
2842
+ const [path, words] = none
2843
+ ? [undefined, theOne(positionals, `Say the job no skill fit: ${SKILL_NOTE_USAGE}`)]
2844
+ : theTwo(
2845
+ positionals,
2846
+ `Say what the note is on, and what it says: ${SKILL_NOTE_USAGE}${positionals.length === 0 ? " | a skill in a folder called note is loaded by its file: console skill note/SKILL.md" : ""}`,
2847
+ );
2848
+ const body = await noteWords(io, words);
2849
+ const on_ = path === undefined ? undefined : notePathOf(path);
2850
+ const session = await open(io, values);
2851
+ const project = await session.projectKey();
2852
+ const left = await ofPackNotes(
2853
+ io,
2854
+ session.client.leavePackNote({
2855
+ ...(on_ === undefined ? {} : { path: on_ }),
2856
+ body,
2857
+ ...(project === undefined ? {} : { project }),
2858
+ }),
2859
+ );
2860
+ answer(io, session, left, () => formatPackNoteLeft(left));
2356
2861
  return EXIT.ok;
2357
2862
  }
2358
2863
 
2359
2864
  const skill: Command = async (args, io) => {
2865
+ if (args[0] === "note") {
2866
+ return skillNote(args.slice(1), io);
2867
+ }
2360
2868
  const { values, positionals } = parse(args, SKILL_OPTIONS);
2361
2869
  const session = await open(io, values);
2362
2870
  const { reader, owner } = await packNamed(session);
@@ -2484,8 +2992,7 @@ const plugin: Command = async (args, io) => {
2484
2992
  case "events":
2485
2993
  return pluginEvents(io, session, client, rest);
2486
2994
  case "skills": {
2487
- const parsed = parse(rest, SKILLS_OPTIONS);
2488
- return readSkills(io, session, client, parsed.values, parsed.positionals, {
2995
+ return readSkills(io, session, client, parse(rest, SKILLS_OPTIONS), {
2489
2996
  command: `console plugin ${key} skills`,
2490
2997
  again: whereGiven(values),
2491
2998
  });
@@ -2704,10 +3211,18 @@ async function pluginRecords(
2704
3211
  const [collection, id, ...more] = positionals;
2705
3212
  if (collection === undefined || more.length > 0) {
2706
3213
  throw misuse(
2707
- `Say which collection: console plugin ${client.key} records <collection> [<id>] [--where <field>=<value>]... [--search <words>] [--order <field>[:desc]] [--limit <n>] [--after <cursor>] [--archived] [--versions]`,
3214
+ `Say which collection: console plugin ${client.key} records <collection> [<id>] [--where <field>=<value>]... [--search "<words>"] [--order <field>[:desc]] [--limit <n>] [--after <cursor>] [--archived] [--versions]`,
2708
3215
  );
2709
3216
  }
2710
3217
  if (id !== undefined) {
3218
+ // A second word is a record's id, and a record is read alone: a search beside it would be
3219
+ // dropped without a line, and the second word of a search was read so (`--search annual
3220
+ // leave` read the record "leave"). Here the words of a search are one word (ADR-0179).
3221
+ if (text(values, "search") !== undefined) {
3222
+ throw misuse(
3223
+ `A record is read by its id alone, and ${id} was read as one: --search goes with a collection, its words as one word in quotes: console plugin ${client.key} records ${collection} --search "<words>"`,
3224
+ );
3225
+ }
2711
3226
  if (on(values, "versions")) {
2712
3227
  const versions = await client.recordVersions(collection, id);
2713
3228
  answer(io, session, versions, () => formatPluginRecordVersions(versions));
@@ -3464,6 +3979,9 @@ const task: Command = async (args, io) => {
3464
3979
  if (args[0] === "restore") {
3465
3980
  return taskRestore(args.slice(1), io);
3466
3981
  }
3982
+ if (args[0] === "follow" || args[0] === "mute") {
3983
+ return following(args[0] === "follow")(args.slice(1), io);
3984
+ }
3467
3985
  const { values, positionals } = parse(args, {});
3468
3986
  const ref = theOne(positionals, "Say which task: console task <number|id>");
3469
3987
  const session = await open(io, values);
@@ -3656,8 +4174,8 @@ const notify: Command = async (args, io) => {
3656
4174
  );
3657
4175
  };
3658
4176
 
3659
- // Whether one task tells a member anything (ADR-0157): `follow` turns its notifications on,
3660
- // `mute` off. A task turned on that their settings would be silent of tells them of
4177
+ // Whether one task tells a member anything (ADR-0157): `task follow` turns its notifications
4178
+ // on, `task mute` off. A task turned on that their settings would be silent of tells them of
3661
4179
  // everything on it; one turned to what their settings say already is told by their kinds.
3662
4180
  const following =
3663
4181
  (turned: boolean): Command =>
@@ -3665,7 +4183,7 @@ const following =
3665
4183
  const { values, positionals } = parse(args, {});
3666
4184
  const ref = theOne(
3667
4185
  positionals,
3668
- `Say which task: console ${turned ? "follow" : "mute"} <number|id>`,
4186
+ `Say which task: console task ${turned ? "follow" : "mute"} <number|id>`,
3669
4187
  );
3670
4188
  const session = await open(io, values);
3671
4189
  const project = await session.project();
@@ -3784,6 +4302,27 @@ interface Taking {
3784
4302
  words: () => string;
3785
4303
  }
3786
4304
 
4305
+ /**
4306
+ * What a take says first of what to do next (ADR-0176): the job's skill, before anything is
4307
+ * made. The rules say that a job begins with its skill; a take says the two commands, at the
4308
+ * moment the work begins and at every take, a later one of a session that left the rules out
4309
+ * among them. The one the task names is loaded; where it names none, the search is the
4310
+ * agent's, by words it chooses for the job, and a take runs none itself: a title is not the
4311
+ * words a skill is found by, and every take would pay for the read. The reads are of the
4312
+ * project the take named: where the pack is read is said as it was given, since without it a
4313
+ * desk reads the organization's pack, which may be another. Those words are spelled by the
4314
+ * skillcdn command's own rule, whose library a take loads only where it has a word to spell
4315
+ * (ADR-0179).
4316
+ */
4317
+ async function skillStep(values: Values): Promise<string> {
4318
+ const given = whereGiven(values);
4319
+ const where = given.length === 0 ? "" : (await packReadsAfter())?.commandLine("", given);
4320
+ if (where === undefined) {
4321
+ return `First, the job's skill: console skill <path> for the one the task names; else console skills --kinds says whether the pack has skills for a job of this kind, and how one is found; each asked with ${flagNamesOf(given)} as this take was, quoted for your shell. Of another kind, or where none fits, go on.`;
4322
+ }
4323
+ return `First, the job's skill: console skill <path>${where} for the one the task names; else console skills --kinds${where} says whether the pack has skills for a job of this kind, and how one is found. Of another kind, or where none fits, go on.`;
4324
+ }
4325
+
3787
4326
  /** Begins a run on a task, as the agent `--agent` names where it is said: the take itself. */
3788
4327
  function runOn(project: ProjectClient, found: RestTask, values: Values): Promise<RestRun> {
3789
4328
  const agent = text(values, "agent");
@@ -3847,6 +4386,7 @@ async function taking(
3847
4386
  held === undefined ? [] : [held === mark ? formatRulesLeftOut(mark) : formatRulesChanged(held)];
3848
4387
  const ruled = held === mark ? [] : [formatRules(rules, language), ""];
3849
4388
  const page = await taskPage(session, taken.number);
4389
+ const first = await skillStep(values);
3850
4390
  return {
3851
4391
  value: { run, task: taken, comments: comments.items, rules: { ...rules, mark } },
3852
4392
  words: () =>
@@ -3860,6 +4400,7 @@ async function taking(
3860
4400
  formatTask(taken, undefined, undefined, comments.items, page),
3861
4401
  "",
3862
4402
  ...ruled,
4403
+ first,
3863
4404
  'Say how it goes: console report "<what you found or did>". Hand in what you make: console hand-in <https url | file path>.',
3864
4405
  'Ask when a person must decide: console ask "<question>" --option "..." --option "...". A word for the task\'s people that is not a report: console comment <number> "<markdown>". End with: console finish --summary "<what was done, what is left>".',
3865
4406
  ].join("\n"),
@@ -4008,6 +4549,18 @@ const ask: Command = async (args, io) => {
4008
4549
  if (options.length < MIN_OPTIONS || options.length > MAX_OPTIONS) {
4009
4550
  throw misuse(`Give ${MIN_OPTIONS} to ${MAX_OPTIONS} options, one --option each.`);
4010
4551
  }
4552
+ // Said before the console is asked, with where the rest goes: its refusal names a field.
4553
+ if (question.length > MAX_QUESTION_LENGTH) {
4554
+ throw misuse(
4555
+ `The question is ${question.length} characters, and one is at most ${MAX_QUESTION_LENGTH}: ask it in a line, and put what the person needs to know, the exact values among it, in --body or --file, which take Markdown.`,
4556
+ );
4557
+ }
4558
+ const long = options.find((label) => label.length > MAX_OPTION_LABEL_LENGTH);
4559
+ if (long !== undefined) {
4560
+ throw misuse(
4561
+ `An option is ${long.length} characters, and one is at most ${MAX_OPTION_LABEL_LENGTH}: name it in a few words, and say what it means in --body or --file.`,
4562
+ );
4563
+ }
4011
4564
  const seconds = secondsOf(text(values, "wait"), DEFAULT_ASK_WAIT_SECONDS);
4012
4565
  const body = await bodyOf(io, values, text(values, "body"));
4013
4566
  // The files put on the decision (ADR-0055): a picture of what is to be chosen between, for one.
@@ -4264,32 +4817,67 @@ const decision: Command = async (args, io) => {
4264
4817
  };
4265
4818
 
4266
4819
  const docs: Command = async (args, io) => {
4267
- const { values, positionals } = parse(args, {
4820
+ const parsed = parse(args, {
4268
4821
  search: { type: "string" },
4269
4822
  archived: { type: "boolean" },
4270
4823
  });
4271
- if (positionals.length > 1) {
4272
- throw misuse("Say one folder: console docs [<folder>] [--search <words>] [--archived]");
4824
+ const { values, positionals } = parsed;
4825
+ // A search is of every page of the project, and every bare word is of it (ADR-0179): a
4826
+ // folder beside the words narrowed nothing, and its word was dropped without a line.
4827
+ const search = searchTyped(parsed);
4828
+ if (search === undefined && positionals.length > 1) {
4829
+ throw misuse(
4830
+ 'Say one folder, or the words of a search after --search: console docs [<folder>] [--archived], or console docs --search "<words>"',
4831
+ );
4832
+ }
4833
+ if (search === "") {
4834
+ throw misuse('Say what to search for: console docs --search "<words>"');
4273
4835
  }
4274
- const search = text(values, "search");
4275
4836
  const session = await open(io, values);
4276
4837
  const project = await session.project();
4277
4838
  // A folder is taken as the listing prints it, `guides/`, and as it is named, `guides`.
4278
- const folder = positionals[0]?.replace(/\/+$/, "");
4839
+ const folder = search === undefined ? positionals[0]?.replace(/\/+$/, "") : undefined;
4279
4840
  const found = await project.documents({
4280
4841
  ...(folder === undefined || folder === "" ? {} : { folder }),
4281
4842
  ...(search === undefined ? {} : { q: search }),
4282
4843
  ...(on(values, "archived") ? { archived: true } : {}),
4283
4844
  });
4284
- answer(io, session, found, () => formatDocuments(found));
4845
+ // A search that finds nothing says what it looked for, as one of the tasks does: a word
4846
+ // typed as a folder is a word of the search, and every word must be on a page.
4847
+ answer(io, session, found, () =>
4848
+ search !== undefined && found.folders.length === 0 && found.items.length === 0
4849
+ ? /\s/.test(search.trim())
4850
+ ? `No pages: none holds every word of "${search.trim()}". A search is of every page of the project, whatever its folder, and fewer words find more.`
4851
+ : `No pages: none holds "${search.trim()}".`
4852
+ : formatDocuments(found),
4853
+ );
4285
4854
  return EXIT.ok;
4286
4855
  };
4287
4856
 
4857
+ /** What a read of one page takes beside its path. */
4858
+ const DOC_READ_FLAGS: OptionSpec = {
4859
+ version: { type: "string" },
4860
+ versions: { type: "boolean" },
4861
+ };
4862
+
4863
+ /** Whether the words are a read of one page: one path, and no flag but a read's own. */
4864
+ function readsOnePage(args: readonly string[]): boolean {
4865
+ try {
4866
+ return parse(args, DOC_READ_FLAGS).positionals.length === 1;
4867
+ } catch {
4868
+ return false;
4869
+ }
4870
+ }
4871
+
4288
4872
  const doc: Command = async (args, io) => {
4289
- const { values, positionals } = parse(args, {
4290
- version: { type: "string" },
4291
- versions: { type: "boolean" },
4292
- });
4873
+ // A page may be called by a form's word, `write`, and is read as any page is (ADR-0167):
4874
+ // the word is the form wherever more follows it than a read of one page takes, a path or a
4875
+ // flag of the form's own, before the path as after it.
4876
+ const form = held(DOC_FORMS, args[0]);
4877
+ if (form !== undefined && !readsOnePage(args)) {
4878
+ return form(args.slice(1), io);
4879
+ }
4880
+ const { values, positionals } = parse(args, DOC_READ_FLAGS);
4293
4881
  const path = theOne(positionals, "Say which page: console doc <path> [--version <n>|--versions]");
4294
4882
  const session = await open(io, values);
4295
4883
  const project = await session.project();
@@ -4324,7 +4912,7 @@ const write: Command = async (args, io) => {
4324
4912
  });
4325
4913
  const path = theOne(
4326
4914
  positionals,
4327
- 'Say which page: console write <path> --title "<title>" --body <markdown>|--file <path>',
4915
+ 'Say which page: console doc write <path> --title "<title>" --body <markdown>|--file <path>',
4328
4916
  );
4329
4917
  const body = await bodyOf(io, values, text(values, "body"));
4330
4918
  if (body === undefined) {
@@ -4373,7 +4961,7 @@ const attach: Command = async (args, io) => {
4373
4961
  const { values, positionals } = parse(args, { label: { type: "string" } });
4374
4962
  const [path, file] = positionals;
4375
4963
  if (path === undefined || file === undefined || positionals.length > 2) {
4376
- throw misuse("Say the page and the file: console attach <path> <file> [--label <words>]");
4964
+ throw misuse("Say the page and the file: console doc attach <path> <file> [--label <words>]");
4377
4965
  }
4378
4966
  const label = text(values, "label");
4379
4967
  const session = await open(io, values);
@@ -4404,7 +4992,7 @@ const attach: Command = async (args, io) => {
4404
4992
 
4405
4993
  const archive: Command = async (args, io) => {
4406
4994
  const { values, positionals } = parse(args, {});
4407
- const path = theOne(positionals, "Say which page: console archive <path>");
4995
+ const path = theOne(positionals, "Say which page: console doc archive <path>");
4408
4996
  const session = await open(io, values);
4409
4997
  const project = await session.project();
4410
4998
  const put = await project.archiveDocument(path);
@@ -4420,7 +5008,7 @@ const archive: Command = async (args, io) => {
4420
5008
 
4421
5009
  const restore: Command = async (args, io) => {
4422
5010
  const { values, positionals } = parse(args, {});
4423
- const path = theOne(positionals, "Say which page: console restore <path>");
5011
+ const path = theOne(positionals, "Say which page: console doc restore <path>");
4424
5012
  const session = await open(io, values);
4425
5013
  const project = await session.project();
4426
5014
  const back = await project.restoreDocument(path);
@@ -4428,23 +5016,21 @@ const restore: Command = async (args, io) => {
4428
5016
  return EXIT.ok;
4429
5017
  };
4430
5018
 
5019
+ /** The forms of `console doc` that change a page, by the word that picks each. */
5020
+ const DOC_FORMS: Readonly<Record<string, Command>> = { write, attach, archive, restore };
5021
+
4431
5022
  const goals: Command = async (args, io) => {
4432
- const { values } = parse(
4433
- args,
4434
- {
4435
- category: { type: "string" },
4436
- state: { type: "string" },
4437
- search: { type: "string" },
4438
- ...PAGE_OPTIONS,
4439
- },
4440
- false,
4441
- );
5023
+ const parsed = parse(args, {
5024
+ category: { type: "string" },
5025
+ state: { type: "string" },
5026
+ search: { type: "string" },
5027
+ ...PAGE_OPTIONS,
5028
+ });
5029
+ const { values } = parsed;
4442
5030
  const state = goalStateOf(text(values, "state"));
4443
5031
  const category = text(values, "category");
4444
- const search = text(values, "search")?.trim();
4445
- if (search === "") {
4446
- throw misuse("Say what to search for: console goals --search <words>");
4447
- }
5032
+ // Every bare word is of the search where --search was typed, and no word goes without it.
5033
+ const search = listingSearch(parsed, "console goals");
4448
5034
  const page = pageOf(values);
4449
5035
  const session = await open(io, values);
4450
5036
  const project = await session.project();
@@ -4830,69 +5416,6 @@ const serve: Command = async (args, io) => {
4830
5416
  return EXIT.ok;
4831
5417
  };
4832
5418
 
4833
- /** What the runner keeps between its own restarts, as its file says it; nothing for a file that does not read. */
4834
- function runnerStateOf(text: string | undefined): RunnerState | undefined {
4835
- if (text === undefined) {
4836
- return undefined;
4837
- }
4838
- let json: unknown;
4839
- try {
4840
- json = JSON.parse(text);
4841
- } catch {
4842
- return undefined;
4843
- }
4844
- if (typeof json !== "object" || json === null) {
4845
- return undefined;
4846
- }
4847
- const delivered = "delivered" in json ? json.delivered : undefined;
4848
- const conversation = "conversation" in json ? json.conversation : undefined;
4849
- const driver = "driver" in json ? json.driver : undefined;
4850
- const limited = "limited" in json ? json.limited : undefined;
4851
- const kept: unknown = "kept" in json ? json.kept : undefined;
4852
- if (typeof delivered !== "number" || !Number.isSafeInteger(delivered) || delivered < 0) {
4853
- return undefined;
4854
- }
4855
- /**
4856
- * A moment in milliseconds since the epoch, or nothing for anything else: a number past what
4857
- * a date holds would fail the runner at every start, where it says the moment in words.
4858
- */
4859
- const momentOf = (value: unknown): number | undefined =>
4860
- typeof value === "number" && Number.isSafeInteger(value) && value > 0 && value < 1e14
4861
- ? value
4862
- : undefined;
4863
- const since =
4864
- typeof limited === "object" && limited !== null && "since" in limited
4865
- ? momentOf(limited.since)
4866
- : undefined;
4867
- return {
4868
- delivered,
4869
- conversation:
4870
- typeof conversation === "string" && conversation.length > 0 && conversation.length <= 200
4871
- ? conversation
4872
- : undefined,
4873
- // The driver the conversation was begun under, as a registry spells one.
4874
- driver:
4875
- typeof driver === "string" && /^[a-z][a-z0-9-]{0,39}$/.test(driver) ? driver : undefined,
4876
- // The usage limit the agent is not back from (ADR-0150): since when, and until when where the product said.
4877
- ...(since === undefined || typeof limited !== "object" || limited === null
4878
- ? {}
4879
- : {
4880
- limited: {
4881
- since,
4882
- until: "until" in limited ? momentOf(limited.until) : undefined,
4883
- },
4884
- }),
4885
- // The signals the record has as delivered that the agent never read: taken from the stream once more.
4886
- ...(Array.isArray(kept)
4887
- ? {
4888
- kept: kept
4889
- .filter((number): number is number => momentOf(number) !== undefined)
4890
- .slice(0, 50),
4891
- }
4892
- : {}),
4893
- };
4894
- }
4895
-
4896
5419
  /** A line a runner says of its machine, within what the console takes one in. */
4897
5420
  const machineLine = (text: string): string => {
4898
5421
  const line = [...text]
@@ -5022,6 +5545,9 @@ const runner: Command = async (args, io) => {
5022
5545
  });
5023
5546
  }
5024
5547
  const statePath = workPath("runner-state.json");
5548
+ // A wake source is named as a registry spells one, which is a file's name as it stands.
5549
+ const keptPath = (source: string): string =>
5550
+ workPath(`runner-kept-${source.replaceAll(/[^a-z0-9-]/g, "_")}.json`);
5025
5551
  const person = me.person;
5026
5552
  /** A runner for the desk's runner.json as it is read now: begun again whenever the file changed (ADR-0144). */
5027
5553
  const runnerOf = (read: Extract<Awaited<ReturnType<typeof readConfig>>, { ok: true }>) => {
@@ -5053,9 +5579,15 @@ const runner: Command = async (args, io) => {
5053
5579
  installed: io.version === undefined ? undefined : io.installedVersion,
5054
5580
  // What installs the console's version here, the way this command was installed.
5055
5581
  updateCommand: () => updateWords(io, io.consoleVersion?.()),
5582
+ // What the console said its version is, on the answers the runner gets anyway: where it
5583
+ // is newer than this command, the agent is told once (ADR-0182). A runner whose own
5584
+ // version is not known has nothing to hold it against.
5585
+ consoleVersion: io.version === undefined ? undefined : io.consoleVersion,
5056
5586
  now: io.now,
5057
5587
  random: host.random,
5058
5588
  time: (iso) => clock.format(new Date(iso)),
5589
+ // What a wake source shows of the agent at its messenger is in the workspace's language (ADR-0170).
5590
+ language: me.workspace.language ?? undefined,
5059
5591
  // A moment that may be on another day, a stretch the runner did not run in or when a
5060
5592
  // usage limit resets, is said as the command prints any moment: with its day, in the
5061
5593
  // workspace's zone where the login kept one.
@@ -5066,7 +5598,7 @@ const runner: Command = async (args, io) => {
5066
5598
  },
5067
5599
  state: {
5068
5600
  load: async () => runnerStateOf(await host.readText(statePath)),
5069
- save: (state) => host.writePrivate(statePath, `${JSON.stringify(state)}\n`),
5601
+ save: (state) => host.replacePrivate(statePath, `${JSON.stringify(state)}\n`),
5070
5602
  },
5071
5603
  log: (line) => io.stdout(`${new Date(io.now()).toISOString()} ${line}\n`),
5072
5604
  // The autosave's git: in the desk, asking nobody at a terminal, its words read and let go.
@@ -5096,6 +5628,12 @@ const runner: Command = async (args, io) => {
5096
5628
  }),
5097
5629
  fetch: (url, init) => io.fetch(url, { ...init, headers: { ...init.headers } }),
5098
5630
  socket: (url) => host.socket(url),
5631
+ // What a source keeps of what it brought the agent, ids and moments and never a word,
5632
+ // in a file of its own beside the runner's state: a runner started again reads it.
5633
+ kept: {
5634
+ load: async (source) => keptBySourceOf(await host.readText(keptPath(source))),
5635
+ save: (source, kept) => host.replacePrivate(keptPath(source), keptFileOf(kept)),
5636
+ },
5099
5637
  },
5100
5638
  });
5101
5639
  };
@@ -5183,7 +5721,7 @@ const manager: Command = async (args, io) => {
5183
5721
  if (found.manager === null || found.manager.status !== "active") {
5184
5722
  lines.push(
5185
5723
  found.administrators.length === 0
5186
- ? "No administrator is in."
5724
+ ? "No administrator stands in."
5187
5725
  : "The administrators, who stand in:",
5188
5726
  ...found.administrators.map((person) => ` ${formatPersonLine(person)}`),
5189
5727
  );
@@ -5210,12 +5748,29 @@ const agents: Command = async (args, io) => {
5210
5748
  };
5211
5749
 
5212
5750
  const AGENT_USAGE =
5213
- 'Say what to do: console agent <handle> [--avatar <file>] | console agent new <handle> [--login <login>] [--project <key>] [--name "<name>"] [--title "<title>"] [--manager <login|me>] [--host gh|google] [--seed <seed>] [--convert]';
5751
+ "Say which agent account, or what to do: console agent <handle>, or console agent new|tell|interrupt|stop|restart|reset|wake|set|signals|messages|secrets|secret|invite|setup ...";
5752
+
5753
+ /**
5754
+ * Whether a console refused an agent account for the project it was not sent: one before 0.6.4,
5755
+ * which made an account in a project (ADR-0088) where a console now makes it in none
5756
+ * (ADR-0181), and says so as any body it cannot read, by the field's name.
5757
+ */
5758
+ /** The console's version as a sentence names it, `, 0.6.3,`, where it said one. */
5759
+ const consoleNamed = (io: CliIo): string => {
5760
+ const version = io.consoleVersion?.();
5761
+ return version === undefined ? "" : `, ${version},`;
5762
+ };
5763
+
5764
+ const asksForProject = (error: unknown): boolean =>
5765
+ error instanceof ApiError &&
5766
+ error.status === 400 &&
5767
+ error.code === "request.invalid" &&
5768
+ error.message.startsWith("project:");
5214
5769
 
5215
5770
  // An administrator makes an agent account with flags, where the pages make one from a form
5216
5771
  // (ADR-0084): the member's row at once, its login let in. What is left out is proposed: the
5217
5772
  // name is the handle's, capitalized, and the console rolls the avatar from the seed, or from one
5218
- // of its own.
5773
+ // of its own. It is made in no project (ADR-0181), and the console leaves it its first message.
5219
5774
  const agentNew = async (args: readonly string[], io: CliIo): Promise<number> => {
5220
5775
  const { values, positionals } = parse(args, {
5221
5776
  login: { type: "string" },
@@ -5239,21 +5794,15 @@ const agentNew = async (args: readonly string[], io: CliIo): Promise<number> =>
5239
5794
  const login = text(values, "login") ?? derived?.login;
5240
5795
  if (login === undefined) {
5241
5796
  throw misuse(
5242
- `Say the account it will sign in with: console agent new ${handle} --login <login> --project <key>`,
5797
+ `Say the account it will sign in with: console agent new ${handle} --login <login>`,
5243
5798
  );
5244
5799
  }
5245
5800
  const chosen = text(values, "host");
5246
5801
  const host = chosen === undefined ? (derived?.host ?? hostOfLogin(login)) : providerOf(chosen);
5247
- const project = await session.projectKey();
5248
- if (project === undefined) {
5249
- throw misuse(
5250
- `Say the project it starts in: console agent new ${handle} --login ${login} --project <key>`,
5251
- );
5252
- }
5253
5802
  const manager = text(values, "manager");
5254
5803
  const seed = text(values, "seed");
5255
5804
  const title = text(values, "title");
5256
- const made = await session.client.createAgent({
5805
+ const input: RestAgentInput = {
5257
5806
  host,
5258
5807
  login,
5259
5808
  handle,
@@ -5263,9 +5812,26 @@ const agentNew = async (args: readonly string[], io: CliIo): Promise<number> =>
5263
5812
  ...(manager === undefined || manager === "me"
5264
5813
  ? {}
5265
5814
  : { managerId: (await personOf(session, manager)).id }),
5266
- project,
5267
5815
  // A member who carries the login becomes the account only where that is said (ADR-0104).
5268
5816
  ...(on(values, "convert") ? { convert: true } : {}),
5817
+ };
5818
+ /** The project a console of before made the account in, with a task for its setup. */
5819
+ let before: string | undefined;
5820
+ const made = await session.client.createAgent(input).catch(async (error: unknown) => {
5821
+ if (!asksForProject(error)) {
5822
+ throw error;
5823
+ }
5824
+ // A console of before, which made nothing of what it refused: it is sent the project this
5825
+ // directory or --project names, and does with it what it did; where none is named, the
5826
+ // answer says what to type.
5827
+ const project = await session.projectKey();
5828
+ before = project;
5829
+ if (project === undefined) {
5830
+ throw failed(
5831
+ `This console${consoleNamed(io)} is older than the command and makes an agent account in a project. Name one: console agent new ${handle} --login ${login} --project <key>`,
5832
+ );
5833
+ }
5834
+ return session.client.createAgent({ ...input, project });
5269
5835
  });
5270
5836
  answer(io, session, made, () =>
5271
5837
  [
@@ -5281,11 +5847,24 @@ const agentNew = async (args: readonly string[], io: CliIo): Promise<number> =>
5281
5847
  : `It is a member now, and work can be assigned to it. It signs in as ${made.person.login}: not confirmed, since this console reads no organization at the git host. That account has to be the organization's own at the git host already, since until its first sign-in binds it here the console lets in whoever holds that login.`
5282
5848
  : `It is a member now, and work can be assigned to it. It signs in as ${made.person.login}: that account is made at the provider before its machine is set up, and its first sign-in with it binds it here.`
5283
5849
  : `${made.person.login} is an agent account from now on, with everything it did.`,
5284
- ...(made.onboarding === null || made.onboarding === undefined
5850
+ // What setting it up takes: a console of now left it as its first message to the
5851
+ // account, made in no project; one of before wrote a task, which it answers where it did.
5852
+ // A console of before lists the account in the project named here, a private one too:
5853
+ // said, since nothing was asked of a project.
5854
+ ...(before === undefined
5285
5855
  ? []
5286
5856
  : [
5287
- `Its first task is #${made.onboarding.number} in ${made.onboarding.project}, with what setting it up takes; its runner is woken with it when it first starts.`,
5857
+ `This console${consoleNamed(io)} is older than the command and makes an agent account in a project: it is in ${before}, ${typeof values.project === "string" ? "which --project names" : "the project named here"}. Where it is not to work there: console member remove ${made.person.login} --project ${before}`,
5288
5858
  ]),
5859
+ ...(made.onboarding !== null && made.onboarding !== undefined
5860
+ ? [
5861
+ `Its first task is #${made.onboarding.number} in ${made.onboarding.project}, with what setting it up takes; its runner is woken with it when it first starts.`,
5862
+ ]
5863
+ : before !== undefined
5864
+ ? []
5865
+ : [
5866
+ `What setting it up takes waits on its record as the console's first message to it, which its runner hands it when it first starts. It is made in no project, and a private one lists it as any member: console member add ${made.person.login} --project <key>`,
5867
+ ]),
5289
5868
  `Next, a machine: console agent invite ${handle} makes the invitation that leads one to it.`,
5290
5869
  ].join("\n"),
5291
5870
  );
@@ -5307,7 +5886,8 @@ async function secretValue(io: CliIo, values: Values, prompt: string): Promise<s
5307
5886
  const value =
5308
5887
  file === undefined
5309
5888
  ? await secretGiven(io, prompt)
5310
- : (await io.readFile(file)).replace(/\r?\n$/, "");
5889
+ : // What a file comes to as a value is said once, for the command and the pages (ADR-0184).
5890
+ secretOfText(await io.readFile(file));
5311
5891
  if (value.length === 0) {
5312
5892
  throw failed("No value was given.");
5313
5893
  }
@@ -5330,11 +5910,24 @@ const SECRET_FLAGS: OptionSpec = {
5330
5910
  expires: { type: "string" },
5331
5911
  };
5332
5912
 
5913
+ /** What ends the listing of the offers that wait: the two things the account does with one. */
5914
+ const OFFERED_NEXT =
5915
+ "Take one into your store: console secret --accept <offer id> [--as <name>] [--replace] | leave one: console secret --decline <offer id>";
5916
+
5333
5917
  // An agent account's own secret store (ADR-0087): the names it keeps, for the account itself,
5334
- // signed in as itself.
5918
+ // signed in as itself; and, with --offered, what members offered it that waits (ADR-0169).
5335
5919
  const secrets: Command = async (args, io) => {
5336
- const { values } = parse(args, {}, false);
5920
+ const { values } = parse(args, { offered: { type: "boolean" } }, false);
5337
5921
  const session = await open(io, values);
5922
+ if (on(values, "offered")) {
5923
+ const offered = await session.client.secretOffers();
5924
+ answer(io, session, offered, () =>
5925
+ offered.items.length === 0
5926
+ ? "No offered secret waits for you."
5927
+ : [...offered.items.map((item) => formatSecretOffer(item)), OFFERED_NEXT].join("\n"),
5928
+ );
5929
+ return EXIT.ok;
5930
+ }
5338
5931
  const found = await session.client.secrets();
5339
5932
  answer(io, session, found, () =>
5340
5933
  found.items.length === 0
@@ -5346,10 +5939,65 @@ const secrets: Command = async (args, io) => {
5346
5939
 
5347
5940
  const SECRET_USAGE =
5348
5941
  "Say which secret: console secret <name> | secret <name> --set [--file <path>] [--expires <day|none>] | secret <name> --remove";
5942
+ const OFFER_USAGE =
5943
+ "Say which offer, by its id as console secrets --offered lists it: console secret --accept <offer id> [--as <name>] [--replace] | secret --decline <offer id>";
5944
+
5945
+ /**
5946
+ * An offer the account takes into its store or leaves (ADR-0169): named by its id, since the
5947
+ * name an offerer proposed is theirs to choose and two may propose the same.
5948
+ */
5949
+ async function offeredSecret(io: CliIo, values: Values, positionals: readonly string[]) {
5950
+ const taking = on(values, "accept");
5951
+ if ((taking && on(values, "decline")) || on(values, "set") || on(values, "remove")) {
5952
+ throw misuse("Say one of --accept, --decline, --set and --remove.");
5953
+ }
5954
+ const as = text(values, "as");
5955
+ if (!taking && (as !== undefined || on(values, "replace"))) {
5956
+ throw misuse(
5957
+ "--as and --replace go with --accept: an offer that is left is kept under no name.",
5958
+ );
5959
+ }
5960
+ const id = theOne(positionals, OFFER_USAGE);
5961
+ const session = await open(io, values);
5962
+ if (!taking) {
5963
+ await session.client.leaveSecretOffer(id);
5964
+ answer(io, session, { left: id }, () => `The offer ${id} is left, and its value is gone.`);
5965
+ return EXIT.ok;
5966
+ }
5967
+ let kept: Awaited<ReturnType<ConsoleClient["takeSecretOffer"]>>;
5968
+ try {
5969
+ kept = await session.client.takeSecretOffer(id, {
5970
+ ...(as === undefined ? {} : { as }),
5971
+ ...(on(values, "replace") ? { replace: true } : {}),
5972
+ });
5973
+ } catch (error) {
5974
+ if (error instanceof ApiError && error.code === "secret.exists") {
5975
+ throw failed(
5976
+ `secret.exists: you keep a secret ${as === undefined ? "of the name it was offered under" : `named ${as}`} already, and the offer still waits. Take it under another name with --as <name>, or in the place of the one you keep with --replace.`,
5977
+ );
5978
+ }
5979
+ throw error;
5980
+ }
5981
+ answer(io, session, kept, () => `Taken into your store: ${formatSecretLine(kept)}`);
5982
+ return EXIT.ok;
5983
+ }
5349
5984
 
5350
5985
  // One secret of the account's own: its value, read and noted; or set, typed unseen; or removed.
5986
+ // And one offered to it, taken or left.
5351
5987
  const secret: Command = async (args, io) => {
5352
- const { values, positionals } = parse(args, SECRET_FLAGS);
5988
+ const { values, positionals } = parse(args, {
5989
+ ...SECRET_FLAGS,
5990
+ accept: { type: "boolean" },
5991
+ decline: { type: "boolean" },
5992
+ as: { type: "string" },
5993
+ replace: { type: "boolean" },
5994
+ });
5995
+ if (on(values, "accept") || on(values, "decline")) {
5996
+ return offeredSecret(io, values, positionals);
5997
+ }
5998
+ if (text(values, "as") !== undefined || on(values, "replace")) {
5999
+ throw misuse(`--as and --replace go with --accept. ${OFFER_USAGE}`);
6000
+ }
5353
6001
  const name = theOne(positionals, SECRET_USAGE);
5354
6002
  const session = await open(io, values);
5355
6003
  if (on(values, "remove")) {
@@ -5378,9 +6026,22 @@ const secret: Command = async (args, io) => {
5378
6026
  // A supervisor's part of an agent account's store (ADR-0087): the names; a secret seeded,
5379
6027
  // write-only, which only the account reads back; one removed. Never a value.
5380
6028
  const agentSecrets = async (args: readonly string[], io: CliIo): Promise<number> => {
5381
- const { values, positionals } = parse(args, {});
5382
- const handle = handleOf(theOne(positionals, "Say whose: console agent secrets <handle>"));
6029
+ const { values, positionals } = parse(args, { offered: { type: "boolean" } });
6030
+ const handle = handleOf(
6031
+ theOne(positionals, "Say whose: console agent secrets <handle> [--offered]"),
6032
+ );
5383
6033
  const session = await open(io, values);
6034
+ if (on(values, "offered")) {
6035
+ // What the account was offered (ADR-0169): its record whole for a supervisor, and for any
6036
+ // other member what they offered it themselves.
6037
+ const offered = await session.client.agentSecretOffers(handle);
6038
+ answer(io, session, offered, () =>
6039
+ offered.items.length === 0
6040
+ ? `Nothing was offered to @${handle} that is yours to read.`
6041
+ : offered.items.map((item) => formatSecretOffer(item)).join("\n"),
6042
+ );
6043
+ return EXIT.ok;
6044
+ }
5384
6045
  let found: Awaited<ReturnType<ConsoleClient["agentSecrets"]>>;
5385
6046
  try {
5386
6047
  found = await session.client.agentSecrets(handle);
@@ -5406,13 +6067,48 @@ const agentSecrets = async (args: readonly string[], io: CliIo): Promise<number>
5406
6067
  };
5407
6068
 
5408
6069
  const agentSecret = async (args: readonly string[], io: CliIo): Promise<number> => {
5409
- const { values, positionals } = parse(args, SECRET_FLAGS);
6070
+ const { values, positionals } = parse(args, {
6071
+ ...SECRET_FLAGS,
6072
+ offer: { type: "boolean" },
6073
+ note: { type: "string" },
6074
+ });
5410
6075
  const [given, name] = theTwo(
5411
6076
  positionals,
5412
- "Say whose and which: console agent secret <handle> <name> [--file <path>] [--expires <day|none>] | agent secret <handle> <name> --remove",
6077
+ 'Say whose and which: console agent secret <handle> <name> [--file <path>] [--expires <day|none>] | agent secret <handle> <name> --offer [--note "<what it is for>"] [--file <path>] [--expires <day|none>] | agent secret <handle> <name> --remove',
5413
6078
  );
5414
6079
  const handle = handleOf(given);
6080
+ const offering = on(values, "offer");
6081
+ const said = text(values, "note")?.trim();
6082
+ if (offering && on(values, "remove")) {
6083
+ throw misuse("Say one of --offer and --remove.");
6084
+ }
6085
+ if (said !== undefined && !offering) {
6086
+ throw misuse("--note says what an offered secret is for, and goes with --offer.");
6087
+ }
5415
6088
  const session = await open(io, values);
6089
+ if (offering) {
6090
+ // Any member's (ADR-0169): the value waits, sealed, for the account to take or leave, and
6091
+ // nothing of what the account keeps changes.
6092
+ const expiresOn = expiryOf(io, values);
6093
+ const value = await secretValue(
6094
+ io,
6095
+ values,
6096
+ `Value of ${name} to offer @${handle} (typed unseen; Enter ends it): `,
6097
+ );
6098
+ const offered = await session.client.offerAgentSecret(handle, {
6099
+ name,
6100
+ value,
6101
+ ...(said === undefined || said === "" ? {} : { note: said }),
6102
+ ...(expiresOn === undefined ? {} : { expiresOn }),
6103
+ });
6104
+ answer(io, session, offered, () =>
6105
+ [
6106
+ `Offered to @${handle}, which is told and takes it into its store or leaves it: ${formatSecretOffer(offered)}`,
6107
+ `Nothing @${handle} keeps changed, and nobody is answered the value. How it stands: console agent secrets ${handle} --offered`,
6108
+ ].join("\n"),
6109
+ );
6110
+ return EXIT.ok;
6111
+ }
5416
6112
  if (on(values, "remove")) {
5417
6113
  await session.client.removeAgentSecret(handle, name);
5418
6114
  answer(
@@ -5430,10 +6126,21 @@ const agentSecret = async (args: readonly string[], io: CliIo): Promise<number>
5430
6126
  `Value of ${name} for @${handle} (typed unseen; Enter ends it): `,
5431
6127
  );
5432
6128
  const host = await gitHostFor(session.client, name);
5433
- const kept = await session.client.seedAgentSecret(handle, name, {
5434
- value,
5435
- ...(expiresOn === undefined ? {} : { expiresOn }),
5436
- });
6129
+ let kept: Awaited<ReturnType<ConsoleClient["seedAgentSecret"]>>;
6130
+ try {
6131
+ kept = await session.client.seedAgentSecret(handle, name, {
6132
+ value,
6133
+ ...(expiresOn === undefined ? {} : { expiresOn }),
6134
+ });
6135
+ } catch (error) {
6136
+ // Whoever supervises the account not is told what is theirs to do in its place.
6137
+ if (error instanceof ApiError && error.code === "auth.forbidden") {
6138
+ throw failed(
6139
+ `auth.forbidden: only a supervisor of @${handle} sets a secret in its store. Any member may offer one, which @${handle} takes or leaves itself: say the same again with --offer, and with --note "<what it is for>".`,
6140
+ );
6141
+ }
6142
+ throw error;
6143
+ }
5437
6144
  const notes = secretNotes(name, value, host);
5438
6145
  answer(io, session, kept, () =>
5439
6146
  [`Seeded for @${handle}, which alone reads it back: ${formatSecretLine(kept)}`, ...notes].join(
@@ -5602,6 +6309,41 @@ const ownReset = async (args: readonly string[], io: CliIo): Promise<number> =>
5602
6309
  return EXIT.ok;
5603
6310
  };
5604
6311
 
6312
+ /**
6313
+ * What an account is told that asks of itself what its supervisors do (ADR-0180): a tell, an
6314
+ * interruption, a stop, a start, a setting, an invitation. Said before anything is sent where it
6315
+ * names itself `me`, which no such form takes, and where the console refused it by its handle.
6316
+ */
6317
+ const NOBODY_SUPERVISES_THEMSELVES =
6318
+ 'Nobody supervises themselves (ADR-0180): a tell, an interruption, a stop, a start, a setting and an invitation are an account\'s supervisors\', never its own, whatever its role. What you raise for yourself is a wake, console agent wake me ["<words>"], and a new conversation, console agent reset me "<why>".';
6319
+
6320
+ /** Whether a word names the account itself where a supervisor's form wants a handle. */
6321
+ const namesItself = (word: string | undefined): boolean => word === "me" || word === "@me";
6322
+
6323
+ /**
6324
+ * A supervisor's act on an agent account (ADR-0084), refused as what it is. The console's
6325
+ * refusal says that only a supervisor may, and the hint after it would say the step is an
6326
+ * administrator's: of the account's own handle, the account is told that nobody supervises
6327
+ * themselves, which an account that administers is not told otherwise; of another's, whose the
6328
+ * step is. `me` is asked only on a refusal, so that the act costs no request more.
6329
+ */
6330
+ async function supervising<T>(session: Session, handle: string, act: () => Promise<T>): Promise<T> {
6331
+ try {
6332
+ return await act();
6333
+ } catch (error) {
6334
+ if (!(error instanceof ApiError) || error.code !== "auth.forbidden") {
6335
+ throw error;
6336
+ }
6337
+ const me = await session.client.me().catch(() => undefined);
6338
+ if (me?.person?.handle === handle) {
6339
+ throw failed(`auth.forbidden: ${NOBODY_SUPERVISES_THEMSELVES}`);
6340
+ }
6341
+ throw failed(
6342
+ `auth.forbidden: ${error.message}\nWhat a supervisor does to an agent account is its manager's, whoever is above them in the reporting line and the administrators': hand the step to one of them.`,
6343
+ );
6344
+ }
6345
+ }
6346
+
5605
6347
  /** The kinds of signal a supervisor sends with words: which need them, and which take them. */
5606
6348
  const WORDED_SIGNALS: Readonly<Record<string, { readonly needs: boolean }>> = {
5607
6349
  tell: { needs: true },
@@ -5613,6 +6355,21 @@ const WORDED_SIGNALS: Readonly<Record<string, { readonly needs: boolean }>> = {
5613
6355
  wake: { needs: false },
5614
6356
  };
5615
6357
 
6358
+ /**
6359
+ * Whether the words after `agent wake` or `agent reset` are the account's own form: `me` where
6360
+ * the handle stands, wherever that is among the form's flags. Read without refusing a word, so
6361
+ * that a mistake among them is answered by the form that was typed, and not by the other's.
6362
+ */
6363
+ function isOwnForm(args: readonly string[], flags: OptionSpec): boolean {
6364
+ const { positionals } = parseArgs({
6365
+ args: [...args],
6366
+ options: { ...GLOBAL_OPTIONS, ...flags },
6367
+ allowPositionals: true,
6368
+ strict: false,
6369
+ });
6370
+ return positionals[0] === "me";
6371
+ }
6372
+
5616
6373
  // A supervisor's signal to an agent account (ADR-0085): a tell, an interruption, a stop, a start
5617
6374
  // with the same conversation or with a new one, a wake; in their own name, on the account's
5618
6375
  // record. What it says is given as words, or with --file, or on standard input as `-`.
@@ -5623,33 +6380,20 @@ const agentSignal = async (
5623
6380
  ): Promise<number> => {
5624
6381
  // An account's own wake is another command under the same word: console agent wake me,
5625
6382
  // wherever `me` stands among its flags.
5626
- if (kind === "wake") {
5627
- let whom: string | undefined;
5628
- try {
5629
- whom = parse(args, OWN_WAKE_FLAGS).positionals[0];
5630
- } catch {
5631
- whom = undefined;
5632
- }
5633
- if (whom === "me") {
5634
- return ownWake(args, io);
5635
- }
6383
+ if (kind === "wake" && isOwnForm(args, OWN_WAKE_FLAGS)) {
6384
+ return ownWake(args, io);
5636
6385
  }
5637
6386
  // And so is its own reset: console agent reset me.
5638
- if (kind === "reset") {
5639
- let whom: string | undefined;
5640
- try {
5641
- whom = parse(args, { file: { type: "string" } }).positionals[0];
5642
- } catch {
5643
- whom = undefined;
5644
- }
5645
- if (whom === "me") {
5646
- return ownReset(args, io);
5647
- }
6387
+ if (kind === "reset" && isOwnForm(args, { file: { type: "string" } })) {
6388
+ return ownReset(args, io);
5648
6389
  }
5649
6390
  const { values, positionals } = parse(args, { file: { type: "string" } });
5650
6391
  const [given, words, ...rest] = positionals;
5651
6392
  const needs = WORDED_SIGNALS[kind]?.needs === true;
5652
6393
  const usage = `Say whom${needs ? " and what" : ""}: console agent ${kind} <handle> ${needs ? '"<words>"' : '["<words>"]'} [--file <path>]`;
6394
+ if (namesItself(given)) {
6395
+ throw misuse(NOBODY_SUPERVISES_THEMSELVES);
6396
+ }
5653
6397
  if (given === undefined || rest.length > 0) {
5654
6398
  throw misuse(usage);
5655
6399
  }
@@ -5659,10 +6403,12 @@ const agentSignal = async (
5659
6403
  }
5660
6404
  const handle = handleOf(given);
5661
6405
  const session = await open(io, values);
5662
- const sent = await session.client.sendSignal(handle, {
5663
- kind,
5664
- ...(said.length === 0 ? {} : { text: said }),
5665
- });
6406
+ const sent = await supervising(session, handle, () =>
6407
+ session.client.sendSignal(handle, {
6408
+ kind,
6409
+ ...(said.length === 0 ? {} : { text: said }),
6410
+ }),
6411
+ );
5666
6412
  answer(io, session, sent, () => `Sent to @${handle}: ${formatSignalLine(sent)}`);
5667
6413
  return EXIT.ok;
5668
6414
  };
@@ -5676,6 +6422,9 @@ const agentSet = async (args: readonly string[], io: CliIo): Promise<number> =>
5676
6422
  });
5677
6423
  const usage =
5678
6424
  "Say whom and what: console agent set <handle> [--model <name|none>] [--effort <level|none>]";
6425
+ if (namesItself(positionals[0])) {
6426
+ throw misuse(NOBODY_SUPERVISES_THEMSELVES);
6427
+ }
5679
6428
  const handle = handleOf(theOne(positionals, usage));
5680
6429
  const model = orNone(text(values, "model"));
5681
6430
  const effort = orNone(text(values, "effort"));
@@ -5683,13 +6432,15 @@ const agentSet = async (args: readonly string[], io: CliIo): Promise<number> =>
5683
6432
  throw misuse(usage);
5684
6433
  }
5685
6434
  const session = await open(io, values);
5686
- const sent = await session.client.sendSignal(handle, {
5687
- kind: "set",
5688
- set: {
5689
- ...(model === undefined ? {} : { model }),
5690
- ...(effort === undefined ? {} : { effort }),
5691
- },
5692
- });
6435
+ const sent = await supervising(session, handle, () =>
6436
+ session.client.sendSignal(handle, {
6437
+ kind: "set",
6438
+ set: {
6439
+ ...(model === undefined ? {} : { model }),
6440
+ ...(effort === undefined ? {} : { effort }),
6441
+ },
6442
+ }),
6443
+ );
5693
6444
  answer(io, session, sent, () => `Sent to @${handle}: ${formatSignalLine(sent)}`);
5694
6445
  return EXIT.ok;
5695
6446
  };
@@ -5844,6 +6595,9 @@ const agentInvite = async (args: readonly string[], io: CliIo): Promise<number>
5844
6595
  revoke: { type: "boolean" },
5845
6596
  out: { type: "string" },
5846
6597
  });
6598
+ if (namesItself(positionals[0])) {
6599
+ throw misuse(NOBODY_SUPERVISES_THEMSELVES);
6600
+ }
5847
6601
  const handle = handleOf(
5848
6602
  theOne(positionals, "Say whose: console agent invite <handle> [--out <path>] | --revoke"),
5849
6603
  );
@@ -5855,7 +6609,7 @@ const agentInvite = async (args: readonly string[], io: CliIo): Promise<number>
5855
6609
  }
5856
6610
  const session = await open(io, values);
5857
6611
  if (on(values, "revoke")) {
5858
- await session.client.revokeAgentInvitation(handle);
6612
+ await supervising(session, handle, () => session.client.revokeAgentInvitation(handle));
5859
6613
  answer(
5860
6614
  io,
5861
6615
  session,
@@ -5880,7 +6634,7 @@ const agentInvite = async (args: readonly string[], io: CliIo): Promise<number>
5880
6634
  );
5881
6635
  }
5882
6636
  }
5883
- const made = await session.client.inviteAgent(handle);
6637
+ const made = await supervising(session, handle, () => session.client.inviteAgent(handle));
5884
6638
  const until = `good until ${moment(made.invitation.expiresAt)} or until its command has signed in`;
5885
6639
  const guide = `${session.url}/setup/${made.code}`;
5886
6640
  if (file === undefined) {
@@ -5917,8 +6671,11 @@ const agentInvite = async (args: readonly string[], io: CliIo): Promise<number>
5917
6671
  `The invitation of @${handle} is made, and its line could not be written at ${file}, so nobody has it. Make the invitation again with a path that can be written: it takes the place of this one.`,
5918
6672
  );
5919
6673
  }
5920
- // The path as both shells take it whole; where it has no such spelling, it is named in words.
5921
- const path = commandWord(written) ?? "<the file's path, quoted for your shell>";
6674
+ // The path as every shell takes it whole, by the skillcdn command's own rule; where it has
6675
+ // no such spelling, it is named in words.
6676
+ const path =
6677
+ (await packReadsAfter())?.commandLine("", [written])?.trim() ??
6678
+ "<the file's path, quoted for your shell>";
5922
6679
  answer(io, session, { handle, invitation: made.invitation, file: written }, () =>
5923
6680
  [
5924
6681
  `An invitation for @${handle}, ${until}. Its line is written to ${written} and is not shown here: it carries the code, which is shown nowhere else.`,
@@ -6410,6 +7167,8 @@ async function handOver(
6410
7167
  await io.sleep(FIRST_SESSION_PAUSE_MS);
6411
7168
  }
6412
7169
  }
7170
+ // The task for its setup, where its plate holds one: an account a console before 0.6.4 made
7171
+ // has the one that console wrote, and keeps it (ADR-0181).
6413
7172
  const plate = await client.work().catch(() => undefined);
6414
7173
  const first = plate?.tasks.find((one) => one.task.title === onboardingTitle(handle));
6415
7174
  const inTheWay = await standsInTheWay(machine);
@@ -6593,7 +7352,7 @@ const DESK_USAGE = "Say at most one directory: console desk [<directory>] [--web
6593
7352
  function deskNext(web: boolean, skillsDir: string | undefined): [string, string] {
6594
7353
  return [
6595
7354
  `Set this desk up as a repository of mine${web ? " and bring its pages up" : ""}, with the skill for it in the organization's pack where it has one: console skills --search "desk setup" --limit 5`,
6596
- `Ask me what I want to keep and to see here, and shape the desk to it, as the skill keeping-a-desk says, shipped with the console command${skillsDir === undefined ? " (console skills says where it is)" : `: ${ownSkillPath(skillsDir, "keeping-a-desk")}`}`,
7355
+ `Ask me what I want to keep and to see here, and shape the desk to it, as the skill keeping-a-desk says, shipped with the console command${skillsDir === undefined ? " (in the skills folder of the package @skillcdn/console, which this build has none of beside it)" : `: ${ownSkillPath(skillsDir, "keeping-a-desk")}`}`,
6597
7356
  ];
6598
7357
  }
6599
7358
 
@@ -7008,7 +7767,28 @@ function serviceOf(word: string): {
7008
7767
  }
7009
7768
  return { role: role as ServiceRole, service };
7010
7769
  }
7011
- const WORKSPACE_USAGE = `Say what to do: console workspace | console workspace edit [${WORKSPACE_FLAGS.replaceAll(", ", "] [")}] | console workspace pack-token --connect|--stdin|--remove`;
7770
+ const PACK_KEEPER_USAGE =
7771
+ "console workspace pack-keeper <login|none> [--round <HH:MM|none>] | console workspace pack-keeper --round <HH:MM|none>";
7772
+ const WORKSPACE_USAGE = `Say what to do: console workspace | console workspace edit [${WORKSPACE_FLAGS.replaceAll(", ", "] [")}] | console workspace pack-token --connect|--stdin|--remove | ${PACK_KEEPER_USAGE}`;
7773
+
7774
+ /**
7775
+ * What the member who keeps the organization's skills is called (ADR-0178), and whether they
7776
+ * are out, for the line that says who does: looked up among the people the asker sees, and
7777
+ * nothing where the workspace names nobody, or somebody the asker does not see.
7778
+ */
7779
+ async function keeperOf(
7780
+ session: Session,
7781
+ workspace: RestWorkspace,
7782
+ ): Promise<KeeperCalled | undefined> {
7783
+ const id = workspace.skills.keeperId;
7784
+ if (typeof id !== "string") {
7785
+ return undefined;
7786
+ }
7787
+ const keeper = (await session.client.people()).items.find((one) => one.id === id);
7788
+ return keeper === undefined
7789
+ ? undefined
7790
+ : { called: calledOf(keeper), away: keeper.status !== "active" };
7791
+ }
7012
7792
 
7013
7793
  const workspace: Command = async (args, io) => {
7014
7794
  const [verb, ...rest] = args;
@@ -7017,7 +7797,56 @@ const workspace: Command = async (args, io) => {
7017
7797
  const session = await open(io, values);
7018
7798
  const me = await session.client.me();
7019
7799
  await rememberZone(io, session, me.workspace.timeZone ?? undefined);
7020
- answer(io, session, me.workspace, () => formatWorkspace(me.workspace));
7800
+ const keeper = session.json ? undefined : await keeperOf(session, me.workspace);
7801
+ answer(io, session, me.workspace, () => formatWorkspace(me.workspace, keeper));
7802
+ return EXIT.ok;
7803
+ }
7804
+ if (verb === "pack-keeper") {
7805
+ // Who keeps the organization's skills, and the hour of their round (ADR-0178): an
7806
+ // administrator's to say, as the workspace's other settings are.
7807
+ const { values, positionals } = parse(rest, { round: { type: "string" } });
7808
+ const round = text(values, "round");
7809
+ if (positionals.length > 1 || (positionals.length === 0 && round === undefined)) {
7810
+ throw misuse(
7811
+ `Say who keeps the organization's skills, or the hour of their round: ${PACK_KEEPER_USAGE}`,
7812
+ );
7813
+ }
7814
+ if (
7815
+ round !== undefined &&
7816
+ round !== "none" &&
7817
+ !/^(?:[01][0-9]|2[0-3]):[0-5][0-9]$/.test(round)
7818
+ ) {
7819
+ throw misuse(`Not an hour of the day: ${round}. Say --round <HH:MM>, as 03:00, or none.`);
7820
+ }
7821
+ const session = await open(io, values);
7822
+ const [login] = positionals;
7823
+ const keeperId =
7824
+ login === undefined
7825
+ ? undefined
7826
+ : login === "none"
7827
+ ? null
7828
+ : (await personOf(session, login)).id;
7829
+ const changed = await session.client
7830
+ .updateWorkspace({
7831
+ ...(keeperId === undefined ? {} : { packKeeperId: keeperId }),
7832
+ ...(round === undefined ? {} : { packRoundAt: round === "none" ? null : round }),
7833
+ })
7834
+ .catch((error: unknown) => {
7835
+ // A console of before reads neither setting, and answers the change as one of nothing.
7836
+ if (
7837
+ error instanceof ApiError &&
7838
+ error.code === "request.invalid" &&
7839
+ error.message.startsWith("The patch names nothing to change")
7840
+ ) {
7841
+ const version = io.consoleVersion?.();
7842
+ throw failed(
7843
+ `This console${version === undefined ? "" : `, ${version},`} names nobody who keeps the organization's skills yet: it is older than the command.`,
7844
+ );
7845
+ }
7846
+ throw error;
7847
+ });
7848
+ const keeper = session.json ? undefined : await keeperOf(session, changed);
7849
+ answer(io, session, changed, () => formatWorkspace(changed, keeper));
7021
7850
  return EXIT.ok;
7022
7851
  }
7023
7852
  if (verb === "edit") {
@@ -7671,23 +8500,58 @@ const COMMANDS: Readonly<Record<string, Command>> = {
7671
8500
  run,
7672
8501
  docs,
7673
8502
  doc,
8503
+ // The words of before (COMMAND_ALIASES, ADR-0167): they run as they did, and no list names them.
7674
8504
  write,
7675
8505
  attach,
7676
8506
  archive,
7677
8507
  restore,
7678
8508
  };
7679
8509
 
7680
- function help(io: CliIo, name: string | undefined): number {
7681
- if (name === undefined) {
8510
+ /** The words the dispatch takes: what a test holds to the pages of help and to the words of before. */
8511
+ export const COMMAND_WORDS: readonly string[] = Object.keys(COMMANDS);
8512
+
8513
+ /** What a word that is no command is answered with: the nearest there are, and where all are listed. */
8514
+ function notCommand(word: string, near: readonly string[] = nearestCommands(word)): CliExit {
8515
+ return misuse(
8516
+ `Not a command: ${word}.${near.length === 0 ? "" : ` Nearest: ${near.join(", ")}.`} console help lists the commands.`,
8517
+ );
8518
+ }
8519
+
8520
+ /**
8521
+ * The help the words ask for (ADR-0167): the table of the commands for none, else the page of
8522
+ * a command, or of one of its forms. Flags among the words are left unread.
8523
+ */
8524
+ function help(io: CliIo, words: readonly string[]): number {
8525
+ const named = words.filter((word) => !word.startsWith("-"));
8526
+ // Help asked of help is the table too.
8527
+ if (named.length === 0 || (named.length === 1 && named[0] === "help")) {
7682
8528
  io.stdout(usage(io.version, io.skillsDir));
7683
8529
  return EXIT.ok;
7684
8530
  }
7685
- const found = helpFor(name, io.skillsDir);
7686
- if (found === undefined) {
7687
- throw misuse(`Not a command: ${name}. The commands: ${Object.keys(COMMAND_HELP).join(", ")}`);
8531
+ const found = helpFor(named, io.skillsDir);
8532
+ if ("page" in found) {
8533
+ io.stdout(found.page);
8534
+ return EXIT.ok;
7688
8535
  }
7689
- io.stdout(found);
7690
- return EXIT.ok;
8536
+ if ("notCommand" in found) {
8537
+ throw notCommand(found.notCommand, found.near);
8538
+ }
8539
+ throw misuse(
8540
+ `Not a form of console ${found.command}: ${found.notForm}. Its forms with a page: ${found.forms.join(", ")}. console help ${found.command} says each in a line.`,
8541
+ );
8542
+ }
8543
+
8544
+ /**
8545
+ * The line after a command that was not understood (ADR-0167): where its forms and flags are,
8546
+ * the page of the form that was tried where it has one. Nothing where the words say it already.
8547
+ */
8548
+ function helpPointer(name: string, rest: readonly string[], said: string): string {
8549
+ if (said.includes("console help")) {
8550
+ return "";
8551
+ }
8552
+ const [command, aliased] = held(COMMAND_ALIASES, name) ?? [name, undefined];
8553
+ const form = aliased ?? formTyped(command, rest);
8554
+ return `Its forms and flags: console help ${command}${form === undefined ? "" : ` ${form}`}\n`;
7691
8555
  }
7692
8556
 
7693
8557
  /**
@@ -7807,11 +8671,11 @@ function hintFor(error: ApiError, io: CliIo, seen: ConsoleSeen): string {
7807
8671
  case "project.not_found":
7808
8672
  return "No project has this key, or it is not yours to see. console projects lists the projects you may work in.\n";
7809
8673
  case "document.not_found":
7810
- return "No page has this path, in this project. console docs lists the pages of a folder; console write <path> writes one.\n";
8674
+ return "No page has this path, in this project. console docs lists the pages of a folder; console doc write <path> writes one.\n";
7811
8675
  case "document.conflict":
7812
8676
  return "The page has moved on since the version you started from. Read it again, and write from there.\n";
7813
8677
  case "document.archived":
7814
- return "The page is archived. console restore <path> brings it back first.\n";
8678
+ return "The page is archived. console doc restore <path> brings it back first.\n";
7815
8679
  case "task.invalid_category":
7816
8680
  return "No category has that key. console categories lists them.\n";
7817
8681
  case "task.invalid_goal":
@@ -7859,7 +8723,7 @@ function hintFor(error: ApiError, io: CliIo, seen: ConsoleSeen): string {
7859
8723
  case "category.in_use":
7860
8724
  return "Tasks are sorted into the category. Move them out first: console task edit <number> --category <other|none>\n";
7861
8725
  case "person.last_admin":
7862
- return "The board keeps at least one administrator in. Make another one first.\n";
8726
+ return "The board keeps at least one administrator in who is a person. Make another person one first.\n";
7863
8727
  case "person.of_organization":
7864
8728
  return "The organization says who is in: a person it let in comes and goes with it, and is listed by login to stay.\n";
7865
8729
  case "agent.login_is_member":
@@ -7909,14 +8773,22 @@ export async function runCli(argv: readonly string[], io: CliIo): Promise<number
7909
8773
  return EXIT.ok;
7910
8774
  }
7911
8775
  if (name === undefined || name === "help" || name === "--help" || name === "-h") {
7912
- return help(io, rest[0]);
8776
+ return help(io, rest);
7913
8777
  }
7914
8778
  if (rest.includes("--help") || rest.includes("-h")) {
7915
- return help(io, name);
8779
+ // The page of the form that was being typed, where it has one.
8780
+ const [command, aliased] = held(COMMAND_ALIASES, name) ?? [name, undefined];
8781
+ const form =
8782
+ aliased ??
8783
+ formTyped(
8784
+ command,
8785
+ rest.filter((word) => word !== "--help" && word !== "-h"),
8786
+ );
8787
+ return help(io, form === undefined ? [command] : [command, form]);
7916
8788
  }
7917
- const command = COMMANDS[name];
8789
+ const command = held(COMMANDS, name);
7918
8790
  if (command === undefined) {
7919
- throw misuse(`Not a command: ${name}. Run: console help`);
8791
+ throw notCommand(name);
7920
8792
  }
7921
8793
  const exit = await command(rest, watched);
7922
8794
  if (name !== "whoami") {
@@ -7925,7 +8797,12 @@ export async function runCli(argv: readonly string[], io: CliIo): Promise<number
7925
8797
  return exit;
7926
8798
  } catch (error) {
7927
8799
  if (error instanceof CliExit) {
7928
- io.stderr(`${error.message}\n`);
8800
+ // A command that was not understood says where its forms and flags are, in a line.
8801
+ const pointer =
8802
+ error.exit === EXIT.usage && name !== undefined && held(COMMANDS, name) !== undefined
8803
+ ? helpPointer(name, rest, error.message)
8804
+ : "";
8805
+ io.stderr(`${error.message}\n${pointer}`);
7929
8806
  return error.exit;
7930
8807
  }
7931
8808
  if (error instanceof UnseenProject) {