@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/dist/cli/cli.js CHANGED
@@ -1,15 +1,13 @@
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 { PackError, ReadMisuse, readNumber, readPack, wroteLine, } from "@skillcdn/cli";
5
- import { BROWSE_MAX_LIMIT, FIND_MAX_LIMIT, READ_FILE_MAX_LIMIT, utf8Length, } from "@skillcdn/core";
6
4
  import { avatarScanlines, MAX_AVATAR_PIXELS, pngFile } from "../avatar.js";
7
5
  import { ApiError, createClient, } from "../client.js";
8
6
  import { CLIENT_RANGE_HEADER, CONSOLE_AT_LEAST, consoleRange, formatRange, judgeClient, judgeConsole, parseVersion, VERSION_HEADER, formatVersion as versionText, } from "../compat.js";
9
7
  import { normalizeConnectCode } from "../connect.js";
10
8
  import { addDays, dayOf as dayOfDate, firstDayOfWeek, isDay, weekOf } from "../dates.js";
11
9
  import { ICON_NAMES, isIconName } from "../icons/index.js";
12
- import { DEFAULT_PAGE_LIMIT, EVENTS_PAGE_LIMIT, LIST_LIMIT, MAX_DECIDERS, MAX_OPTIONS, MAX_OWN_WAKE_DAYS, MAX_RUNNER_LINE_LENGTH, MAX_SIGNALS_PAGE_LIMIT, MIN_OPTIONS, OWN_WAKE_KEY, } from "../limits.js";
10
+ import { DEFAULT_PAGE_LIMIT, EVENTS_PAGE_LIMIT, LIST_LIMIT, MAX_DECIDERS, MAX_OPTION_LABEL_LENGTH, MAX_OPTIONS, MAX_OWN_WAKE_DAYS, MAX_PACK_NOTE_LENGTH, MAX_PACK_NOTE_OUTCOME_LENGTH, MAX_PACK_NOTES_PAGE_LIMIT, MAX_QUESTION_LENGTH, MAX_RUNNER_LINE_LENGTH, MAX_SIGNALS_PAGE_LIMIT, MIN_OPTIONS, OWN_WAKE_KEY, PACK_NOTES_PAGE_LIMIT, } from "../limits.js";
13
11
  import { MAX_NOTIFICATIONS_PAGE, NOTIFICATION_KINDS, NOTIFICATIONS_PAGE, } from "../notifications.js";
14
12
  import { onboardingTitle } from "../onboarding.js";
15
13
  import { capabilityWords } from "../plugin/capabilities.js";
@@ -22,23 +20,24 @@ import { DEFAULT_RUNNER_CONFIG, parseRunnerConfig } from "../runner/config.js";
22
20
  import { DESK_FOLDER, deskFiles, deskServicesOf, deskWebTitleOf, personDeskFiles, } from "../runner/desk.js";
23
21
  import { quotedLines } from "../runner/message.js";
24
22
  import { ownRunnerModules } from "../runner/modules.js";
25
- import { createRunner, GIT_TOKEN_SECRET, } from "../runner/runner.js";
26
- import { hostOfLogin, } from "../schemas.js";
23
+ import { createRunner, GIT_TOKEN_SECRET } from "../runner/runner.js";
24
+ import { hostOfLogin, isPackNotePath, } from "../schemas.js";
25
+ import { secretOfText } from "../secret-file.js";
27
26
  import { agentLoginOf, deskRemoteOf } from "../services.js";
28
27
  import { setupGuideOf, setupGuideText, setupSentenceOf } from "../setup-guide.js";
29
28
  import { COLOR_NAMES, CONSOLE_LANGUAGES, GOAL_STATES, PEOPLE_VISIBILITIES, PERSON_ROLES, PROJECT_ROLES, PROJECT_VISIBILITIES, PROVIDER_KEYS, SERVICE_ROLES, TASK_PRIORITIES, TASK_STATES, WEEK_STARTS, } from "../vocabulary.js";
30
29
  import { loadWebRoot, WebRootError } from "../web.js";
31
- import { commandLine, commandWord, NO_LINE_TO_RUN } from "./command-words.js";
32
30
  import { CredentialsError, EMPTY_CREDENTIALS, fitsFile, keepsNothing, lasts, loginsAt, pendingAt, resolveLogin, withLogin, withoutLogin, withoutPending, withPending, } from "./credentials.js";
33
31
  import { DIRECTORY_FILE, THE_SENTENCE, } from "./directory.js";
34
- import { calledOf, deciderLogins, formatAgent, formatAgentLine, formatAnswer, formatCategoryLine, formatComment, formatDecision, formatDecisionLine, formatDocument, formatDocuments, formatGoal, formatGoalLine, formatInvocation, formatListingLine, formatMemberLine, formatMore, formatNotificationSettings, formatNotifications, formatOptions, formatOwnWakeLine, formatPersonLine, formatPersonWork, formatPlugin, formatPluginAsks, formatPluginEvents, formatPluginGrantLine, formatPluginHelp, formatPluginRecord, formatPluginRecords, formatPluginRecordVersions, formatPluginSettingLine, formatPlugins, formatProject, formatProjectLine, formatRules, formatRulesChanged, formatRulesLeftOut, formatRun, formatRunLine, formatSecretLine, formatSignalLine, formatTask, formatTaskFollow, formatTaskLine, formatTeamLine, formatVersion, formatVersionLine, formatWork, formatWorkspace, localized, moment, pageLine, rulesMark, setMomentZone, } from "./format.js";
35
- import { COMMAND_HELP, helpFor, ownSkillPath, usage } from "./help.js";
32
+ import { calledOf, deciderLogins, formatAgent, formatAgentLine, formatAnswer, formatCategoryLine, formatComment, formatDecision, formatDecisionLine, formatDocument, formatDocuments, formatGoal, formatGoalLine, formatInvocation, formatListingLine, formatMemberLine, formatMore, formatNotificationSettings, formatNotifications, formatOptions, formatOwnWakeLine, formatPackNoteClosed, formatPackNoteLeft, formatPackNotes, formatPersonLine, formatPersonWork, formatPlugin, formatPluginAsks, formatPluginEvents, formatPluginGrantLine, formatPluginHelp, formatPluginRecord, formatPluginRecords, formatPluginRecordVersions, formatPluginSettingLine, formatPlugins, formatProject, formatProjectLine, formatRules, formatRulesChanged, formatRulesLeftOut, formatRun, formatRunLine, formatSecretLine, formatSecretOffer, formatSignalLine, formatTask, formatTaskFollow, formatTaskLine, formatTeamLine, formatVersion, formatVersionLine, formatWork, formatWorkspace, localized, moment, pageLine, rulesMark, setMomentZone, } from "./format.js";
33
+ import { COMMAND_ALIASES, formTyped, held, helpFor, nearestCommands, ownSkillPath, usage, } from "./help.js";
36
34
  import { describeInstall, updateCommandFor } from "./install.js";
37
35
  import { awakeWords, heldAwake, lookAtMachine, standsInTheWay, } from "./machine-check.js";
38
- import { consolePack, formatSkills, holdsNothing, ORGANIZATION_PACK_LINE, PackRefusal, packWords, refusalWords, skillPathIn, skillsAround, } from "./pack.js";
36
+ import { keptBySourceOf, keptFileOf, runnerStateOf } from "./runner-files.js";
39
37
  import { workPath } from "./runner-host.js";
40
38
  import { secretNotes } from "./secret-notes.js";
41
39
  import { createServeHandler, DEFAULT_SERVE_PORT, loadRecordsRoot, RecordsRootError, } from "./serve.js";
40
+ import { skillPathIn } from "./skill-path.js";
42
41
  // The `console` command (docs/specs/cli.md): the agent's side of the console. A thin client of
43
42
  // the REST API with no logic of its own: every command is one or two requests and the words to
44
43
  // say what came back. It takes what it needs from `CliIo`, so that tests run it whole, against
@@ -104,12 +103,69 @@ function parse(args, options, allowPositionals = true) {
104
103
  options: { ...GLOBAL_OPTIONS, ...options },
105
104
  allowPositionals,
106
105
  strict: true,
106
+ // The words in the order they were typed, for a search, whose words are every bare word.
107
+ tokens: true,
107
108
  });
108
109
  }
109
110
  catch (error) {
110
- throw misuse(error instanceof Error ? error.message : "The arguments were not understood.");
111
+ throw misuse(refusedByParser(error, options));
111
112
  }
112
113
  }
114
+ /**
115
+ * The words of a search as they were typed (ADR-0179): what `--search` was given and every
116
+ * bare word, in their order, as the skillcdn command takes every word after `find` as the
117
+ * query. So `--search card news` asks for two words, where the second was once read as a
118
+ * folder and the search, of one word in a folder nobody named, found nothing. Nothing where no
119
+ * `--search` was typed: a bare word is then the command's own to read.
120
+ */
121
+ function searchTyped(parsed) {
122
+ if (typeof parsed.values.search !== "string") {
123
+ return undefined;
124
+ }
125
+ const typed = [];
126
+ for (const token of parsed.tokens) {
127
+ if (token.kind === "positional") {
128
+ typed.push(token.value);
129
+ }
130
+ else if (token.kind === "option" && token.name === "search" && token.value !== undefined) {
131
+ typed.push(token.value);
132
+ }
133
+ }
134
+ return typed.join(" ").trim();
135
+ }
136
+ /**
137
+ * What the parser refused, in the command's own words (ADR-0167): an option that is none of
138
+ * the command's is answered with those it takes, so that the next try needs no page of help;
139
+ * what the parser says of a value is said as it says it, without its advice on other things.
140
+ */
141
+ function refusedByParser(error, options) {
142
+ if (!(error instanceof Error)) {
143
+ return "The arguments were not understood.";
144
+ }
145
+ const code = "code" in error ? String(error.code) : "";
146
+ // What was typed is between the parser's first quote and the one its sentence goes on
147
+ // after: a word may hold a quote of its own (`it's`), and is said whole.
148
+ const ADVICE = ". To specify a positional argument ";
149
+ const named = (code === "ERR_PARSE_ARGS_UNKNOWN_OPTION"
150
+ ? /^Unknown option '(.*?)'(?:\. To specify a positional argument .*)?$/s
151
+ : /^Unexpected argument '(.*)'\. This command does not take positional arguments$/s).exec(error.message)?.[1] ??
152
+ /'([^']*)'/.exec(error.message)?.[1] ??
153
+ "";
154
+ if (code === "ERR_PARSE_ARGS_UNKNOWN_OPTION") {
155
+ const own = Object.keys(options).map((name) => `--${name}`);
156
+ const takes = own.length === 0 ? "It takes none of its own" : `Its own are ${own.join(", ")}`;
157
+ // A word of a report or a title may begin with a dash, and is then no option at all:
158
+ // said where the command takes a word, and what was typed does not read as an option.
159
+ const dashed = !error.message.includes(ADVICE) || /^--[a-z][a-z0-9-]*$/.test(named)
160
+ ? ""
161
+ : " A word that begins with - and is no option goes after --.";
162
+ return `Not an option of this command: ${named}. ${takes}; --json, --project, --url and --account go with every command.${dashed}`;
163
+ }
164
+ if (code === "ERR_PARSE_ARGS_UNEXPECTED_POSITIONAL") {
165
+ return `This command takes no word beside its options: ${named}.`;
166
+ }
167
+ return error.message;
168
+ }
113
169
  const text = (values, name) => {
114
170
  const value = values[name];
115
171
  return typeof value === "string" ? value : undefined;
@@ -1057,7 +1113,7 @@ const whoami = async (args, io) => {
1057
1113
  // agent here for where the skill is, and the workspace has rules whatever the project.
1058
1114
  // The skill's path stands last, with nothing after it, to be copied as it is.
1059
1115
  io.skillsDir === undefined
1060
- ? "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>."
1116
+ ? "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>."
1061
1117
  : `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)}`,
1062
1118
  `This command is ${io.version ?? "of a version it does not know"}${io.install === undefined ? "" : `, ${describeInstall(io.install)}`}; ${consoleWords}.`,
1063
1119
  ...(verdict === "behind"
@@ -1079,9 +1135,14 @@ const projects = async (args, io) => {
1079
1135
  const { values } = parse(args, {}, false);
1080
1136
  const session = await open(io, values);
1081
1137
  const found = await session.client.projects();
1082
- answer(io, session, found, () => found.items.length === 0
1083
- ? 'No projects you may work in. Make one: console project new <key> "<name>"'
1084
- : found.items.map(formatProjectLine).join("\n"));
1138
+ // In none: an administrator makes one, and anyone else is listed in one by an administrator.
1139
+ // Asked only then, so that a listing costs no request more.
1140
+ const none = found.items.length === 0
1141
+ ? (await session.client.me()).person?.role === "admin"
1142
+ ? 'No projects you may work in. Make one: console project new <key> "<name>"'
1143
+ : "No projects you may work in. An administrator lists you in one, or opens one to the workspace, which has everyone in it."
1144
+ : undefined;
1145
+ answer(io, session, found, () => none ?? found.items.map(formatProjectLine).join("\n"));
1085
1146
  return EXIT.ok;
1086
1147
  };
1087
1148
  const use = async (args, io) => {
@@ -1128,8 +1189,23 @@ async function endOfWeek(io, session, today) {
1128
1189
  const language = me.language ?? io.locale ?? me.workspace.language ?? "en";
1129
1190
  return weekOf(today, firstDayOfWeek(language, me.workspace.weekStart ?? "auto")).at(-1) ?? today;
1130
1191
  }
1192
+ /**
1193
+ * The words a listing is searched by (ADR-0179): what `--search` was given and every bare word,
1194
+ * in the order typed, for a listing that takes no word of its own. A bare word without
1195
+ * `--search` is not understood, and the answer says where the words of a search go.
1196
+ */
1197
+ function listingSearch(parsed, command) {
1198
+ const search = searchTyped(parsed);
1199
+ if (search === undefined && parsed.positionals.length > 0) {
1200
+ throw misuse(`This command takes no word beside its options: ${parsed.positionals[0]}. The words of a search go after --search: ${command} --search "<words>"`);
1201
+ }
1202
+ if (search === "") {
1203
+ throw misuse(`Say what to search for: ${command} --search "<words>"`);
1204
+ }
1205
+ return search;
1206
+ }
1131
1207
  const tasks = async (args, io) => {
1132
- const { values } = parse(args, {
1208
+ const parsed = parse(args, {
1133
1209
  state: { type: "string" },
1134
1210
  open: { type: "boolean" },
1135
1211
  mine: { type: "boolean" },
@@ -1140,7 +1216,10 @@ const tasks = async (args, io) => {
1140
1216
  search: { type: "string" },
1141
1217
  archived: { type: "boolean" },
1142
1218
  ...PAGE_OPTIONS,
1143
- }, false);
1219
+ });
1220
+ const { values } = parsed;
1221
+ // Every bare word is of the search where --search was typed, and no word goes without it.
1222
+ const search = listingSearch(parsed, "console tasks");
1144
1223
  const state = stateOf(text(values, "state"));
1145
1224
  if (on(values, "mine") && on(values, "unassigned")) {
1146
1225
  throw misuse("Say one: --mine for the tasks you work on, or --unassigned for those nobody works on");
@@ -1159,10 +1238,6 @@ const tasks = async (args, io) => {
1159
1238
  ? await endOfWeek(io, session, today)
1160
1239
  : (dayOf(io, due) ?? undefined);
1161
1240
  const worker = on(values, "mine") ? ((await personIdOf(session, "me")) ?? undefined) : undefined;
1162
- const search = text(values, "search")?.trim();
1163
- if (search === "") {
1164
- throw misuse("Say what to search for: console tasks --search <words>");
1165
- }
1166
1241
  const filter = {
1167
1242
  ...(state === undefined ? {} : { state }),
1168
1243
  ...(on(values, "open") || due === "overdue" ? { open: true } : {}),
@@ -1214,13 +1289,31 @@ const categories = async (args, io) => {
1214
1289
  answer(io, session, found, () => found.items.length === 0 ? "No categories." : found.items.map(formatCategoryLine).join("\n"));
1215
1290
  return EXIT.ok;
1216
1291
  };
1292
+ const packReads = () => import("./pack.js");
1293
+ /**
1294
+ * The reads of a pack where only a word is to be spelled, after an act that is done: nothing
1295
+ * where the library does not load, so that what was done is said all the same and the words
1296
+ * are named in a sentence, never a line, as where a word has no spelling every shell takes.
1297
+ */
1298
+ async function packReadsAfter() {
1299
+ try {
1300
+ return await packReads();
1301
+ }
1302
+ catch {
1303
+ return undefined;
1304
+ }
1305
+ }
1306
+ /** The flags `whereGiven` names, said in words: `--project and --url`. */
1307
+ const flagNamesOf = (given) => given.filter((_, index) => index % 2 === 0).join(" and ");
1217
1308
  const SKILLS_OPTIONS = {
1218
1309
  search: { type: "string" },
1219
1310
  path: { type: "string" },
1311
+ full: { type: "boolean" },
1220
1312
  limit: { type: "string" },
1221
1313
  cursor: { type: "string" },
1222
1314
  rows: { type: "boolean" },
1223
1315
  code: { type: "boolean" },
1316
+ kinds: { type: "boolean" },
1224
1317
  heading: { type: "string" },
1225
1318
  format: { type: "string" },
1226
1319
  grep: { type: "string" },
@@ -1232,11 +1325,11 @@ const SKILLS_OPTIONS = {
1232
1325
  * printed as if it were the read. `--json` still prints what the console answered, which says
1233
1326
  * the status. Thrown by the caller, so that nothing follows it.
1234
1327
  */
1235
- function refusedRead(io, session, owner, answered, words) {
1328
+ function refusedRead(reads, io, session, owner, answered, words) {
1236
1329
  if (session.json) {
1237
1330
  io.stdout(`${JSON.stringify(answered, null, 2)}\n`);
1238
1331
  }
1239
- return failed(owner === "organization" ? `${ORGANIZATION_PACK_LINE}\n${words}` : words);
1332
+ return failed(owner === "organization" ? `${reads.ORGANIZATION_PACK_LINE}\n${words}` : words);
1240
1333
  }
1241
1334
  /** A whole number a flag carries, within its bounds; nothing when it is not given. */
1242
1335
  function countOf(given, name, bounds) {
@@ -1255,12 +1348,12 @@ function countOf(given, name, bounds) {
1255
1348
  * A number a read of a pack takes, checked as the skillcdn command checks it and said in its
1256
1349
  * words, before anything is asked of the console.
1257
1350
  */
1258
- function checkedNumber(given, name, most) {
1351
+ function checkedNumber(reads, given, name, most) {
1259
1352
  try {
1260
- readNumber(given, name, most);
1353
+ reads.readNumber(given, name, most);
1261
1354
  }
1262
1355
  catch (error) {
1263
- throw error instanceof ReadMisuse ? misuse(error.message) : error;
1356
+ throw error instanceof reads.ReadMisuse ? misuse(error.message) : error;
1264
1357
  }
1265
1358
  }
1266
1359
  /**
@@ -1283,22 +1376,25 @@ function whereGiven(values) {
1283
1376
  * lines the command prints of its own around the text, which the read keeps room for, so that
1284
1377
  * the whole output is one a host shows whole.
1285
1378
  */
1286
- async function readThrough(io, session, owner, pack, read, options) {
1379
+ async function readThrough(reads, io, session, owner, pack, read, options) {
1287
1380
  try {
1288
- return await readPack(pack, read, {
1381
+ return await reads.readPack(pack, read, {
1289
1382
  words: options.words,
1290
1383
  json: session.json,
1291
1384
  nextPart: options.nextPart,
1292
- room: roomFor(owner, options.beside ?? []),
1385
+ browseFolder: options.browseFolder,
1386
+ readFile: options.readFile,
1387
+ loadFound: options.loadFound,
1388
+ room: roomFor(reads, owner, options.beside ?? []),
1293
1389
  });
1294
1390
  }
1295
1391
  catch (error) {
1296
- if (error instanceof ReadMisuse) {
1392
+ if (error instanceof reads.ReadMisuse) {
1297
1393
  throw misuse(error.message);
1298
1394
  }
1299
- const refusal = error instanceof PackRefusal
1300
- ? { answer: error.answer, words: refusalWords(error.what, error.answer, owner) }
1301
- : error instanceof PackError
1395
+ const refusal = error instanceof reads.PackRefusal
1396
+ ? { answer: error.answer, words: reads.refusalWords(error.what, error.answer, owner) }
1397
+ : error instanceof reads.PackError
1302
1398
  ? { answer: pack.answered(), words: `${error.code}: ${error.message}` }
1303
1399
  : undefined;
1304
1400
  if (refusal === undefined) {
@@ -1306,7 +1402,7 @@ async function readThrough(io, session, owner, pack, read, options) {
1306
1402
  }
1307
1403
  throw options.data === true || refusal.answer === undefined
1308
1404
  ? failed(refusal.words)
1309
- : refusedRead(io, session, owner, refusal.answer, refusal.words);
1405
+ : refusedRead(reads, io, session, owner, refusal.answer, refusal.words);
1310
1406
  }
1311
1407
  }
1312
1408
  /**
@@ -1314,9 +1410,9 @@ async function readThrough(io, session, owner, pack, read, options) {
1314
1410
  * its own with the break that sets it apart, and the line that says the pack is the
1315
1411
  * organization's where it is.
1316
1412
  */
1317
- function roomFor(owner, beside) {
1318
- const lines = [owner === "organization" ? ORGANIZATION_PACK_LINE : undefined, ...beside];
1319
- return lines.reduce((bytes, line) => (line === undefined ? bytes : bytes + utf8Length(line) + 1), 0);
1413
+ function roomFor(reads, owner, beside) {
1414
+ const lines = [owner === "organization" ? reads.ORGANIZATION_PACK_LINE : undefined, ...beside];
1415
+ return lines.reduce((bytes, line) => (line === undefined ? bytes : bytes + reads.utf8Length(line) + 1), 0);
1320
1416
  }
1321
1417
  /**
1322
1418
  * What `--json` prints for a read: the console's answer, with the pack's own in it as the
@@ -1331,14 +1427,14 @@ function jsonOfRead(session, pack, output) {
1331
1427
  * the blocks as written, or written to a file with `--out`. What a program takes is never a
1332
1428
  * refusal: a read the pack refused fails with why.
1333
1429
  */
1334
- async function readData(io, session, pack, asked) {
1430
+ async function readData(reads, io, session, pack, asked) {
1335
1431
  const { read } = asked;
1336
- const output = await readThrough(io, session, asked.owner, pack, read, {
1432
+ const output = await readThrough(reads, io, session, asked.owner, pack, read, {
1337
1433
  words: asked.words,
1338
1434
  data: true,
1339
1435
  });
1340
1436
  // Nothing is printed for nothing, which a program takes as it is; a line beside it says so.
1341
- if (holdsNothing(output.holds) && asked.out === undefined && !session.json) {
1437
+ if (reads.holdsNothing(output.holds) && asked.out === undefined && !session.json) {
1342
1438
  io.stderr(`No ${read.read === "rows" ? "tables" : "code blocks"} in ${read.path ?? "the pack"}${read.heading === undefined ? "" : " under that heading"}.\n`);
1343
1439
  }
1344
1440
  const made = session.json
@@ -1357,7 +1453,7 @@ async function readData(io, session, pack, asked) {
1357
1453
  catch {
1358
1454
  throw failed(`The file could not be written at ${asked.out}.`);
1359
1455
  }
1360
- io.stdout(`${wroteLine(output.holds ?? "", saved)}\n`);
1456
+ io.stdout(`${reads.wroteLine(output.holds ?? "", saved)}\n`);
1361
1457
  return EXIT.ok;
1362
1458
  }
1363
1459
  const SKILL_OPTIONS = {
@@ -1369,36 +1465,68 @@ const SKILL_OPTIONS = {
1369
1465
  /** The line `console skills` ends with: where the plugins' own skills are. */
1370
1466
  const PLUGIN_SKILLS_LINE = "The plugins of this console have skills of their own: console plugins lists the plugins, console plugin <key> skills the skills of one.";
1371
1467
  /**
1372
- * The pack as the words say: whole, a page of a folder or of a file's outline, or what words
1373
- * find; for the project's pack as `console skills`, and for a plugin's as
1374
- * `console plugin <key> skills`. Each as the skillcdn command reads it, through its own reads
1375
- * (ADR-0124).
1468
+ * What stands in place of the line that reads on from a cursor where a word of it has no
1469
+ * spelling every shell takes: the cursor, and what to give it to. Its reader ran the command,
1470
+ * so it has the other words.
1376
1471
  */
1377
- async function readSkills(io, session, reader, values, positionals, extras) {
1472
+ const readOnWithoutLine = (reads, cursor) => `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}`;
1473
+ /** 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. */
1474
+ const folderOf = (typed) => typed?.replace(/\/+$/, "");
1475
+ /**
1476
+ * The pack as the words say: whole, its kinds of work, a page of a folder or of a file's
1477
+ * outline, or what words find; for the project's pack as `console skills`, and for a plugin's
1478
+ * as `console plugin <key> skills`. Each as the skillcdn command reads it, through its own reads
1479
+ * (ADR-0124), and asked for by that command's own arguments after the flag that names the read
1480
+ * (ADR-0179): with `--search`, every bare word is of the query and a folder is `--path`.
1481
+ */
1482
+ async function readSkills(io, session, reader, parsed, extras) {
1483
+ const { values, positionals } = parsed;
1484
+ const reads = await packReads();
1378
1485
  const owner = extras.owner ?? "project";
1379
- const say = (value, words) => answerPack(io, session, owner, value, words);
1486
+ const again = extras.again ?? [];
1487
+ const say = (value, words) => answerPack(reads, io, session, owner, value, words);
1380
1488
  // The reads by the names of this pack's own commands: a plugin's are not the project's.
1381
1489
  const skillCommand = extras.command.replace(/skills$/, "skill");
1382
- const toolWords = packWords(extras.command, skillCommand);
1383
- // How a skill is loaded, said after a listing and after what a search found: the pack's own
1384
- // words there name how a section is read, and a skill read as a file comes without its rules.
1490
+ const toolWords = reads.packWords(extras.command, skillCommand);
1491
+ // How a skill is loaded, said after a listing: the pack's own words there name how a section
1492
+ // is read, and a skill read as a file comes without its rules. A search says its next step
1493
+ // itself, once (`loadFound`).
1385
1494
  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.`;
1386
- if (positionals.length > 1) {
1387
- throw misuse(`Say one folder: ${extras.command} [<folder>] [--search <words>]`);
1388
- }
1389
- // The root of the pack is the mounted folder, which the deployment reads as no path at all.
1390
- const given = positionals[0];
1391
- const words = text(values, "search");
1392
- const within = text(values, "path");
1495
+ const words = searchTyped(parsed);
1496
+ // A folder is taken as the pack prints it, `design/`, and as it is named, `design`, as a
1497
+ // folder of the documents is: the deployment refuses a path that ends with a slash.
1498
+ const within = folderOf(text(values, "path"));
1499
+ const full = on(values, "full");
1393
1500
  const limit = text(values, "limit");
1394
1501
  const cursor = text(values, "cursor");
1395
1502
  const rows = on(values, "rows");
1396
1503
  const code = on(values, "code");
1504
+ const kinds = on(values, "kinds");
1397
1505
  const heading = text(values, "heading");
1398
1506
  const out = text(values, "out");
1399
1507
  const format = text(values, "format");
1400
1508
  const grep = text(values, "grep");
1509
+ const searchUsage = `${extras.command} --search "<words>" [--path <folder>] [--full] [--limit <n>]`;
1510
+ // With --search every bare word is of the query; without it, the one bare word is a folder
1511
+ // or a file of the pack.
1512
+ if (words === undefined && positionals.length > 1) {
1513
+ throw misuse(`Say one folder, or the words of a search after --search: ${extras.command} [<folder>], or ${searchUsage}`);
1514
+ }
1515
+ if (words !== undefined && words.length === 0) {
1516
+ throw misuse(`Say what to search for: ${searchUsage}`);
1517
+ }
1518
+ // The root of the pack is the mounted folder, which the deployment reads as no path at all.
1519
+ const given = words === undefined ? folderOf(positionals[0]) : undefined;
1401
1520
  const dataUsage = `${extras.command} --rows|--code [<folder|file>] [--heading <words>] [--out <path>]`;
1521
+ // The kinds of work are of the pack whole, and are said in a few lines: nothing narrows them.
1522
+ if (kinds &&
1523
+ (given !== undefined ||
1524
+ rows ||
1525
+ code ||
1526
+ full ||
1527
+ [words, within, limit, cursor, heading, out, format, grep].some((one) => one !== undefined))) {
1528
+ throw misuse(`--kinds goes alone: ${extras.command} --kinds`);
1529
+ }
1402
1530
  if (rows && code) {
1403
1531
  throw misuse(`Say one: --rows for the tables, or --code for the code blocks: ${dataUsage}`);
1404
1532
  }
@@ -1415,35 +1543,35 @@ async function readSkills(io, session, reader, values, positionals, extras) {
1415
1543
  if (grep !== undefined && !code) {
1416
1544
  throw misuse(`--grep goes with --code: ${extras.command} --code [<folder|file>] [--grep <pattern>]`);
1417
1545
  }
1418
- // The folder a search keeps to is said once: after the words, or with --path as the
1419
- // skillcdn command takes it.
1546
+ // The folder a search keeps to is said with --path, as the skillcdn command takes it, and
1547
+ // everything a search prints of a result with --full.
1420
1548
  if (within !== undefined && words === undefined) {
1421
- throw misuse(`--path goes with --search; a folder is read with ${extras.command} <folder>: ${extras.command} --search <words> [--path <folder>]`);
1549
+ throw misuse(`--path goes with --search; a folder is read with ${extras.command} <folder>: ${searchUsage}`);
1422
1550
  }
1423
- if (within !== undefined && given !== undefined) {
1424
- throw misuse(`Say the folder once: after the words, or with --path: ${extras.command} --search <words> [<folder>]`);
1551
+ if (full && words === undefined) {
1552
+ throw misuse(`--full goes with --search: ${searchUsage}`);
1425
1553
  }
1426
1554
  const named = given ?? within;
1427
- const folder = named === undefined || named === "/" || named === "." ? undefined : named;
1555
+ const folder = named === undefined || named === "" || named === "." ? undefined : named;
1428
1556
  // The listing is as long as one read prints, and goes on from the cursor its page ended with.
1429
1557
  if (words === undefined && given === undefined && limit !== undefined) {
1430
1558
  throw misuse(`--limit goes with a folder or with --search: ${extras.command} <folder> [--limit <n>] [--cursor <cursor>]`);
1431
1559
  }
1432
1560
  // A page of what words find, or of what a folder holds: the bounds of each, as the pack has them.
1433
- checkedNumber(limit, "limit", words === undefined ? BROWSE_MAX_LIMIT : FIND_MAX_LIMIT);
1561
+ checkedNumber(reads, limit, "limit", words === undefined ? reads.BROWSE_MAX_LIMIT : reads.FIND_MAX_LIMIT);
1434
1562
  const listing = await reader.skills();
1435
1563
  // With --json the console's own addresses stay in a document's outline; in words, the
1436
1564
  // commands that read its tables and its code blocks.
1437
- const pack = consolePack(reader, listing, {
1565
+ const pack = reads.consolePack(reader, listing, {
1438
1566
  url: session.url,
1439
1567
  dataCommand: session.json ? undefined : extras.command,
1440
1568
  });
1441
1569
  // As data: a read the pack refused fails with why, and nothing is printed.
1442
1570
  if (rows || code) {
1443
1571
  if (pack === undefined) {
1444
- throw failed(refusalWords(rows ? "tables" : "code blocks", listing, owner));
1572
+ throw failed(reads.refusalWords(rows ? "tables" : "code blocks", listing, owner));
1445
1573
  }
1446
- return readData(io, session, pack, {
1574
+ return readData(reads, io, session, pack, {
1447
1575
  read: rows
1448
1576
  ? { read: "rows", path: folder, heading, format }
1449
1577
  : { read: "code", path: folder, heading, grep },
@@ -1454,10 +1582,34 @@ async function readSkills(io, session, reader, values, positionals, extras) {
1454
1582
  }
1455
1583
  // A pack that does not answer: said as that, which a folder or a search would meet too.
1456
1584
  if (pack === undefined) {
1457
- throw refusedRead(io, session, owner, listing, [formatSkills(listing, undefined, extras.own, owner, toolWords), extras.afterwards]
1585
+ throw refusedRead(reads, io, session, owner, listing, [reads.formatSkills(listing, undefined, extras.own, owner, toolWords), extras.afterwards]
1458
1586
  .filter((part) => part !== undefined)
1459
1587
  .join("\n"));
1460
1588
  }
1589
+ // A file of the pack is named by the line that reads it, whole, asked as this read was
1590
+ // (SkillCDN 0.6.4): the page a pack says to start from, an overview, the manifest.
1591
+ const readFile = (path) => reads.commandLine(skillCommand, ["--file", path, ...again]) ??
1592
+ `${skillCommand} --file with this file's path, quoted for your shell. ${reads.NO_LINE_TO_RUN}`;
1593
+ if (kinds) {
1594
+ // The kinds of work the pack has skills for (ADR-0176), as the skillcdn command reads them
1595
+ // (ADR-0179): its lines, its bound and its closing sentence, in the words of this pack's
1596
+ // commands, made of the one answer the console already has. Read once in a conversation.
1597
+ // --json is the kinds as that command prints them as data. The search and the load it
1598
+ // names are asked where this read was: without --project a desk reads the organization's
1599
+ // pack, which may be another than the one these kinds are of.
1600
+ const where = again.length === 0 ? "" : reads.commandLine("", again);
1601
+ const told = await readThrough(reads, io, session, owner, pack, { read: "kinds" }, {
1602
+ words: where === undefined
1603
+ ? {
1604
+ ...toolWords,
1605
+ search: `${extras.command} --search, asked with ${flagNamesOf(again)} as this read was and quoted for your shell,`,
1606
+ load: `${skillCommand}, asked so too,`,
1607
+ }
1608
+ : reads.packWords(`${extras.command}${where}`, `${skillCommand}${where}`),
1609
+ });
1610
+ say(session.json ? JSON.parse(told.text) : undefined, () => told.text);
1611
+ return EXIT.ok;
1612
+ }
1461
1613
  if (words === undefined && given === undefined) {
1462
1614
  // --json is the console's listing as it answered it, whole; the words are the pack's own,
1463
1615
  // read once more from that answer, a listing longer than one read prints in pages.
@@ -1467,18 +1619,19 @@ async function readSkills(io, session, reader, values, positionals, extras) {
1467
1619
  }
1468
1620
  // The console's own lines stand around the first page, and the read keeps room for them
1469
1621
  // and for the empty lines that set them apart.
1470
- const around = skillsAround(listing, extras.own, toolWords);
1622
+ const around = reads.skillsAround(listing, extras.own, toolWords);
1471
1623
  const own = [
1472
1624
  ...around.host,
1473
1625
  ...around.own,
1474
1626
  loading,
1475
1627
  ...(extras.afterwards === undefined ? [] : [extras.afterwards]),
1476
1628
  ];
1477
- const told = await readThrough(io, session, owner, pack, { read: "skills", cursor }, {
1629
+ const told = await readThrough(reads, io, session, owner, pack, { read: "skills", cursor }, {
1478
1630
  words: toolWords,
1479
1631
  beside: cursor === undefined ? [around.head, ...own, "", "", ""] : [],
1480
- nextPart: (next) => commandLine(extras.command, ["--cursor", next, ...(extras.again ?? [])]) ??
1481
- `${extras.command} with --cursor ${commandWord(next) ?? JSON.stringify(next)}, each word quoted for your shell. ${NO_LINE_TO_RUN}`,
1632
+ readFile,
1633
+ nextPart: (next) => reads.commandLine(extras.command, ["--cursor", next, ...again]) ??
1634
+ `${extras.command} with --cursor ${reads.commandLine("", [next])?.trim() ?? JSON.stringify(next)}, each word quoted for your shell. ${reads.NO_LINE_TO_RUN}`,
1482
1635
  });
1483
1636
  say(listing, () => {
1484
1637
  // A page read from a cursor is the pack's own words alone: what stands around the
@@ -1491,7 +1644,7 @@ async function readSkills(io, session, reader, values, positionals, extras) {
1491
1644
  // lines stand above the listing then, and after it where it is whole.
1492
1645
  return told.next === undefined
1493
1646
  ? [
1494
- formatSkills(listing, told.text, extras.own, owner, toolWords),
1647
+ reads.formatSkills(listing, told.text, extras.own, owner, toolWords),
1495
1648
  loading,
1496
1649
  ...(extras.afterwards === undefined ? [] : [extras.afterwards]),
1497
1650
  ].join("\n")
@@ -1499,15 +1652,46 @@ async function readSkills(io, session, reader, values, positionals, extras) {
1499
1652
  });
1500
1653
  return EXIT.ok;
1501
1654
  }
1655
+ // The command that reads the next page of a folder or of a search (SkillCDN 0.6.3): this
1656
+ // one again, asked as it was, with the cursor the page ended on. Where a word of it has no
1657
+ // spelling every shell takes, the command that was run is run again, and the line says why.
1658
+ const nextPage = (asked) => (next) => reads.commandLine(extras.command, [
1659
+ ...asked,
1660
+ ...(limit === undefined ? [] : ["--limit", limit]),
1661
+ ...(full ? ["--full"] : []),
1662
+ "--cursor",
1663
+ next,
1664
+ ...again,
1665
+ ]) ?? readOnWithoutLine(reads, next);
1502
1666
  if (words !== undefined) {
1503
- // One page of what the words find; more is said, and asked for with --cursor.
1504
- const found = await readThrough(io, session, owner, pack, { read: "find", words, path: folder, cursor, limit }, { words: toolWords, beside: [loading] });
1505
- say(jsonOfRead(session, pack, found), () => `${found.text}\n${loading}`);
1667
+ // One page of what the words find, as the skillcdn command prints it (ADR-0179): each
1668
+ // result with what choosing needs and how it matches, and, where a skill was found, the
1669
+ // next step once, the command that loads it, asked as this search was. A page that ends
1670
+ // before the results do ends with the command that reads the next: the words as one word
1671
+ // of the line, which every version of the command reads as the query, the folder as --path.
1672
+ const where = reads.commandLine("", again);
1673
+ const found = await readThrough(reads, io, session, owner, pack, { read: "find", words, path: folder, cursor, limit, full }, {
1674
+ words: toolWords,
1675
+ readFile,
1676
+ loadFound: where === undefined
1677
+ ? `${skillCommand} with its path and where this pack is read, each quoted for your shell. ${reads.NO_LINE_TO_RUN}`
1678
+ : `${skillCommand} <its path>${where}`,
1679
+ nextPart: nextPage([
1680
+ "--search",
1681
+ words,
1682
+ ...(folder === undefined ? [] : ["--path", folder]),
1683
+ ]),
1684
+ });
1685
+ say(jsonOfRead(session, pack, found), () => found.text);
1506
1686
  return EXIT.ok;
1507
1687
  }
1508
1688
  // One page of the folder, or of a file's outline, as the skillcdn command browses: a page
1509
- // that ends before the folder does names the cursor that continues it.
1510
- const browsed = await readThrough(io, session, owner, pack, { read: "browse", path: folder, cursor, limit }, { words: toolWords });
1689
+ // that ends before the folder does ends with the command that reads the next.
1690
+ const browsed = await readThrough(reads, io, session, owner, pack, { read: "browse", path: folder, cursor, limit }, {
1691
+ words: toolWords,
1692
+ readFile,
1693
+ nextPart: nextPage(folder === undefined ? [] : [folder]),
1694
+ });
1511
1695
  say(jsonOfRead(session, pack, browsed), () => browsed.text);
1512
1696
  return EXIT.ok;
1513
1697
  }
@@ -1525,14 +1709,124 @@ async function packNamed(session) {
1525
1709
  * Prints a read of a pack: as `answer` does, and, where the pack is the organization's, under
1526
1710
  * the line that says so. `--json` stays what the console answered.
1527
1711
  */
1528
- function answerPack(io, session, owner, value, words) {
1529
- answer(io, session, value, () => owner === "organization" ? `${ORGANIZATION_PACK_LINE}\n${words()}` : words());
1712
+ function answerPack(reads, io, session, owner, value, words) {
1713
+ answer(io, session, value, () => owner === "organization" ? `${reads.ORGANIZATION_PACK_LINE}\n${words()}` : words());
1714
+ }
1715
+ /**
1716
+ * What the console answers of the notes on the pack (ADR-0178), where it has them: one of
1717
+ * before answers their path as nothing, which is said as what it is, with where the finding
1718
+ * goes meanwhile, since a skill's load named the command whatever the console is.
1719
+ */
1720
+ async function ofPackNotes(io, asked) {
1721
+ try {
1722
+ return await asked;
1723
+ }
1724
+ catch (error) {
1725
+ if (noSuchRoute(error)) {
1726
+ const version = io.consoleVersion?.();
1727
+ throw failed(`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.`);
1728
+ }
1729
+ throw error;
1730
+ }
1731
+ }
1732
+ /** What `console skills --notes` takes beside what a read of the pack takes. */
1733
+ const SKILLS_NOTES_OPTIONS = {
1734
+ notes: { type: "boolean" },
1735
+ all: { type: "boolean" },
1736
+ mine: { type: "boolean" },
1737
+ offset: { type: "string" },
1738
+ };
1739
+ const SKILLS_NOTES_USAGE = "console skills --notes [<folder|path>] [--all] [--mine] [--limit <n>] [--offset <n>]";
1740
+ /** How a keeper closes a note, and how an author takes one back: said under a list of them. */
1741
+ const NOTE_CLOSING = 'Close one with what became of it: console skill note <id> --done "<what changed, and where>", or --drop "<why nothing was>".';
1742
+ const NOTE_TAKING_BACK = 'These are your own; whoever keeps the skills reads everyone\'s. Take one back: console skill note <id> --drop "<why>".';
1743
+ /**
1744
+ * The notes on the pack (ADR-0178), as the asker reads them: everyone's for whoever keeps the
1745
+ * skills and for an administrator, their own for anyone else. To whoever keeps them, the list
1746
+ * ends with how one is closed and where a keeper's work is written, the skill keeping-the-pack
1747
+ * with its place on this machine: a keeper woken for a round reads it from here, and nobody
1748
+ * else pays for a word of it.
1749
+ */
1750
+ async function listNotes(io, session, values, positionals) {
1751
+ if (positionals.length > 1) {
1752
+ throw misuse(`Say one folder or path: ${SKILLS_NOTES_USAGE}`);
1753
+ }
1754
+ if (["search", "path", "cursor", "heading", "format", "grep", "out"].some((name) => text(values, name) !== undefined) ||
1755
+ ["rows", "code", "kinds", "full"].some((name) => on(values, name))) {
1756
+ throw misuse(`--notes lists the notes on the pack, and reads nothing of it: ${SKILLS_NOTES_USAGE}`);
1757
+ }
1758
+ const limit = numberOf(text(values, "limit"), "limit", 1, MAX_PACK_NOTES_PAGE_LIMIT);
1759
+ const offset = numberOf(text(values, "offset"), "offset", 0, 1_000_000);
1760
+ const all = on(values, "all");
1761
+ const page = { limit: limit ?? PACK_NOTES_PAGE_LIMIT, offset: offset ?? 0, all };
1762
+ const found = await ofPackNotes(io, session.client.packNotes({
1763
+ state: all ? "all" : "open",
1764
+ mine: on(values, "mine"),
1765
+ path: positionals[0] === undefined ? undefined : notePathOf(positionals[0]),
1766
+ limit: page.limit,
1767
+ offset: page.offset,
1768
+ }));
1769
+ const closing = found.everyones
1770
+ ? [
1771
+ NOTE_CLOSING,
1772
+ `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")}`}`,
1773
+ ]
1774
+ : found.items.length === 0
1775
+ ? []
1776
+ : [NOTE_TAKING_BACK];
1777
+ answer(io, session, found, () => formatPackNotes(found, page, closing));
1778
+ return EXIT.ok;
1779
+ }
1780
+ /** A whole number a flag names, within its bounds; nothing where the flag was not given. */
1781
+ function numberOf(given, name, least, most) {
1782
+ if (given === undefined) {
1783
+ return undefined;
1784
+ }
1785
+ const value = Number(given);
1786
+ if (!/^\d+$/.test(given) || value < least || value > most) {
1787
+ throw misuse(`--${name} is a whole number from ${least} to ${most}: ${given}`);
1788
+ }
1789
+ return value;
1790
+ }
1791
+ /**
1792
+ * A path of the pack as a note names it: from the root, with no slash at either end, and a
1793
+ * skill by its folder, which is what a skill is called, whether its `SKILL.md` or its folder
1794
+ * was said. A URI the pack names a skill by is its path.
1795
+ */
1796
+ function notePathOf(given) {
1797
+ const named = skillPathIn(given, null);
1798
+ if ("error" in named) {
1799
+ throw misuse(named.error);
1800
+ }
1801
+ const from = (given.startsWith("skill://") ? named.path : given)
1802
+ .trim()
1803
+ .replace(/^(?:\.\/)+/, "")
1804
+ .replace(/^\/+|\/+$/g, "");
1805
+ // A pack that is one skill has it at its root, which the load's own line calls `.`.
1806
+ if (from === "." || from === "SKILL.md") {
1807
+ return ".";
1808
+ }
1809
+ const path = from.replace(/\/SKILL\.md$/, "");
1810
+ if (path.length === 0) {
1811
+ throw misuse('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>"');
1812
+ }
1813
+ if (!isPackNotePath(path)) {
1814
+ throw misuse(`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.`);
1815
+ }
1816
+ return path;
1530
1817
  }
1531
1818
  const skills = async (args, io) => {
1532
- const { values, positionals } = parse(args, SKILLS_OPTIONS);
1819
+ const parsed = parse(args, { ...SKILLS_OPTIONS, ...SKILLS_NOTES_OPTIONS });
1820
+ const { values, positionals } = parsed;
1821
+ if (on(values, "notes")) {
1822
+ return listNotes(io, await open(io, values), values, positionals);
1823
+ }
1824
+ if (on(values, "all") || on(values, "mine") || text(values, "offset") !== undefined) {
1825
+ throw misuse(`--all, --mine and --offset go with --notes: ${SKILLS_NOTES_USAGE}`);
1826
+ }
1533
1827
  const session = await open(io, values);
1534
1828
  const { reader, owner } = await packNamed(session);
1535
- return readSkills(io, session, reader, values, positionals, {
1829
+ return readSkills(io, session, reader, parsed, {
1536
1830
  command: "console skills",
1537
1831
  own: io.skillsDir,
1538
1832
  afterwards: PLUGIN_SKILLS_LINE,
@@ -1549,8 +1843,9 @@ const skills = async (args, io) => {
1549
1843
  * part.
1550
1844
  */
1551
1845
  async function readSkill(io, session, reader, values, positionals, command, owner = "project", again = []) {
1552
- const say = (value, words) => answerPack(io, session, owner, value, words);
1553
- const toolWords = packWords(`${command}s`, command);
1846
+ const reads = await packReads();
1847
+ const say = (value, words) => answerPack(reads, io, session, owner, value, words);
1848
+ const toolWords = reads.packWords(`${command}s`, command);
1554
1849
  const file = text(values, "file");
1555
1850
  const cursor = text(values, "cursor");
1556
1851
  // A file is read by its own path from the repository's root; a skill's path beside it would be
@@ -1567,17 +1862,21 @@ async function readSkill(io, session, reader, values, positionals, command, owne
1567
1862
  if (file !== undefined && cursor !== undefined) {
1568
1863
  throw misuse(`--cursor reads the next part of a skill; a file reads on from --offset: ${command} --file <path> [--offset <n>] [--limit <n>]`);
1569
1864
  }
1570
- checkedNumber(text(values, "offset"), "offset", Number.MAX_SAFE_INTEGER);
1571
- checkedNumber(text(values, "limit"), "limit", READ_FILE_MAX_LIMIT);
1865
+ checkedNumber(reads, text(values, "offset"), "offset", Number.MAX_SAFE_INTEGER);
1866
+ checkedNumber(reads, text(values, "limit"), "limit", reads.READ_FILE_MAX_LIMIT);
1572
1867
  const listing = await reader.skills();
1573
- const pack = consolePack(reader, listing, { url: session.url });
1868
+ const pack = reads.consolePack(reader, listing, { url: session.url });
1574
1869
  if (pack === undefined) {
1575
- throw refusedRead(io, session, owner, listing, formatSkills(listing, undefined, io.skillsDir, owner, toolWords));
1870
+ throw refusedRead(reads, io, session, owner, listing, reads.formatSkills(listing, undefined, io.skillsDir, owner, toolWords));
1576
1871
  }
1872
+ // A file of the pack is named by the line that reads it, whole, asked as this read was
1873
+ // (SkillCDN 0.6.4): the source a skill names, and what a folder read as a file holds.
1874
+ const readFile = (path) => reads.commandLine(command, ["--file", path, ...again]) ??
1875
+ `${command} --file with this file's path, quoted for your shell. ${reads.NO_LINE_TO_RUN}`;
1577
1876
  if (file !== undefined) {
1578
1877
  // A page of the file, as the skillcdn command reads one: from --offset, as long as a host
1579
1878
  // shows whole where --limit says nothing, and where the next begins when the file goes on.
1580
- const page = await readThrough(io, session, owner, pack, { read: "file", path: file, offset: text(values, "offset"), limit: text(values, "limit") }, { words: toolWords });
1879
+ const page = await readThrough(reads, io, session, owner, pack, { read: "file", path: file, offset: text(values, "offset"), limit: text(values, "limit") }, { words: toolWords, readFile });
1581
1880
  say(jsonOfRead(session, pack, page), () => page.text);
1582
1881
  return EXIT.ok;
1583
1882
  }
@@ -1590,17 +1889,113 @@ async function readSkill(io, session, reader, values, positionals, command, owne
1590
1889
  // the cursor. A part says how many pages of the skill follow it and ends with the command
1591
1890
  // that reads the next, asked as this one was, and the last says that it is the last: the
1592
1891
  // words are the skillcdn command's own (SkillCDN 0.6.2), and only the line is made here.
1593
- const loaded = await readThrough(io, session, owner, pack, { read: "skill", path: wanted.path, cursor }, {
1892
+ // What a load of the project's or the organization's pack ends with (ADR-0178): the command
1893
+ // that leaves a note on this skill, with its folder in it, read by whoever is about to use
1894
+ // the skill and nobody else. A plugin's pack is its package's, and takes no note here.
1895
+ const noting = command === "console skill" && !session.json
1896
+ ? noteLineFor(reads, skillFolderOf(wanted.path), again)
1897
+ : undefined;
1898
+ const loaded = await readThrough(reads, io, session, owner, pack, { read: "skill", path: wanted.path, cursor }, {
1899
+ beside: [noting],
1594
1900
  words: toolWords,
1595
- // Spelled so that bash and PowerShell run it as it is; where a word has no such spelling,
1596
- // the command that was run is run again, with the cursor, and the line says why.
1597
- nextPart: (next) => commandLine(command, [given, "--cursor", next, ...again]) ??
1598
- `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}`,
1901
+ readFile,
1902
+ // Spelled so that every shell runs it as it is; where a word has no such spelling, the
1903
+ // command that was run is run again, with the cursor, and the line says why.
1904
+ nextPart: (next) => reads.commandLine(command, [given, "--cursor", next, ...again]) ??
1905
+ readOnWithoutLine(reads, next),
1906
+ // The skill's own folder, where it does not list every file of it, as the command that
1907
+ // lists a folder of this pack (SkillCDN 0.6.3): the dot for the root, since the command
1908
+ // without a folder is the listing.
1909
+ browseFolder: (path) => reads.commandLine(`${command}s`, [path.length === 0 ? "." : path, ...again]) ??
1910
+ `${command}s with this skill's folder, quoted for your shell. ${reads.NO_LINE_TO_RUN}`,
1599
1911
  });
1600
- say(jsonOfRead(session, pack, loaded), () => loaded.text);
1912
+ // After the last part alone: a part that is not the last ends with the command for the next.
1913
+ say(jsonOfRead(session, pack, loaded), () => noting === undefined || loaded.next !== undefined
1914
+ ? loaded.text
1915
+ : `${loaded.text.replace(/\n+$/, "")}\n${noting}`);
1916
+ return EXIT.ok;
1917
+ }
1918
+ /** A skill's folder, which is what a skill is called, from the path of its `SKILL.md`. */
1919
+ const skillFolderOf = (path) => path.replace(/(?:^|\/)SKILL\.md$/, "") || ".";
1920
+ /**
1921
+ * The line a skill's load ends with: where a run shows the skill wrong or lacking, the command
1922
+ * that says so to whoever keeps the pack, asked as this load was. The words are a placeholder,
1923
+ * so the line is printed whole only where the folder has a spelling every shell takes.
1924
+ */
1925
+ function noteLineFor(reads, folder, again) {
1926
+ const line = reads.commandLine("console skill note", [folder]);
1927
+ const where = reads.commandLine("", again)?.trim() ?? "";
1928
+ 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}`}`;
1929
+ }
1930
+ const SKILL_NOTE_USAGE = '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>"';
1931
+ const NOTE_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
1932
+ /** What a note says, given as a word or, as `-`, on standard input: something, after its edges are trimmed. */
1933
+ async function noteWords(io, given) {
1934
+ const words = (given === "-" ? await io.readStdin() : given).trim();
1935
+ if (words.length === 0) {
1936
+ throw misuse(`A note says something: ${SKILL_NOTE_USAGE}`);
1937
+ }
1938
+ if (words.length > MAX_PACK_NOTE_LENGTH) {
1939
+ throw misuse(`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.`);
1940
+ }
1941
+ return words;
1942
+ }
1943
+ /**
1944
+ * A note on the pack (ADR-0178): left on a skill or a page of it, or with `--none` for a job no
1945
+ * skill fit, by anyone who works through the console; and closed, by its id, with what became
1946
+ * of it, by whoever keeps the skills, or taken back by its author. It is left on the pack the
1947
+ * command reads: the project's where one is named, else the organization's.
1948
+ */
1949
+ async function skillNote(args, io) {
1950
+ const { values, positionals } = parse(args, {
1951
+ none: { type: "boolean" },
1952
+ done: { type: "string" },
1953
+ drop: { type: "string" },
1954
+ });
1955
+ const done = text(values, "done");
1956
+ const drop = text(values, "drop");
1957
+ const none = on(values, "none");
1958
+ if (done !== undefined || drop !== undefined) {
1959
+ if ((done !== undefined && drop !== undefined) || none) {
1960
+ throw misuse(`Say one of --done and --drop, with the note's id: ${SKILL_NOTE_USAGE}`);
1961
+ }
1962
+ const id = theOne(positionals, `Say which note, by its id as console skills --notes lists it: ${SKILL_NOTE_USAGE}`);
1963
+ if (!NOTE_ID.test(id)) {
1964
+ throw misuse(`Not a note's id: ${id}. console skills --notes lists the notes with their ids.`);
1965
+ }
1966
+ const outcome = (done ?? drop ?? "").trim();
1967
+ if (outcome.length === 0 || outcome.length > MAX_PACK_NOTE_OUTCOME_LENGTH) {
1968
+ throw misuse(`Say what became of the note, in up to ${MAX_PACK_NOTE_OUTCOME_LENGTH} characters: ${SKILL_NOTE_USAGE}`);
1969
+ }
1970
+ const session = await open(io, values);
1971
+ const closed = await ofPackNotes(io, session.client.closePackNote(id, {
1972
+ state: done === undefined ? "dropped" : "done",
1973
+ outcome,
1974
+ }));
1975
+ answer(io, session, closed, () => formatPackNoteClosed(closed));
1976
+ return EXIT.ok;
1977
+ }
1978
+ // `console skill note` alone read, before this form, as the load of a skill whose folder is
1979
+ // called note: that load is still there, by the path of its file, and the sentence says so.
1980
+ const [path, words] = none
1981
+ ? [undefined, theOne(positionals, `Say the job no skill fit: ${SKILL_NOTE_USAGE}`)]
1982
+ : theTwo(positionals, `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" : ""}`);
1983
+ const body = await noteWords(io, words);
1984
+ const on_ = path === undefined ? undefined : notePathOf(path);
1985
+ const session = await open(io, values);
1986
+ const project = await session.projectKey();
1987
+ const left = await ofPackNotes(io, session.client.leavePackNote({
1988
+ ...(on_ === undefined ? {} : { path: on_ }),
1989
+ body,
1990
+ ...(project === undefined ? {} : { project }),
1991
+ }));
1992
+ answer(io, session, left, () => formatPackNoteLeft(left));
1601
1993
  return EXIT.ok;
1602
1994
  }
1603
1995
  const skill = async (args, io) => {
1996
+ if (args[0] === "note") {
1997
+ return skillNote(args.slice(1), io);
1998
+ }
1604
1999
  const { values, positionals } = parse(args, SKILL_OPTIONS);
1605
2000
  const session = await open(io, values);
1606
2001
  const { reader, owner } = await packNamed(session);
@@ -1705,8 +2100,7 @@ const plugin = async (args, io) => {
1705
2100
  case "events":
1706
2101
  return pluginEvents(io, session, client, rest);
1707
2102
  case "skills": {
1708
- const parsed = parse(rest, SKILLS_OPTIONS);
1709
- return readSkills(io, session, client, parsed.values, parsed.positionals, {
2103
+ return readSkills(io, session, client, parse(rest, SKILLS_OPTIONS), {
1710
2104
  command: `console plugin ${key} skills`,
1711
2105
  again: whereGiven(values),
1712
2106
  });
@@ -1883,9 +2277,15 @@ async function pluginRecords(io, session, client, rest, project) {
1883
2277
  });
1884
2278
  const [collection, id, ...more] = positionals;
1885
2279
  if (collection === undefined || more.length > 0) {
1886
- throw misuse(`Say which collection: console plugin ${client.key} records <collection> [<id>] [--where <field>=<value>]... [--search <words>] [--order <field>[:desc]] [--limit <n>] [--after <cursor>] [--archived] [--versions]`);
2280
+ throw misuse(`Say which collection: console plugin ${client.key} records <collection> [<id>] [--where <field>=<value>]... [--search "<words>"] [--order <field>[:desc]] [--limit <n>] [--after <cursor>] [--archived] [--versions]`);
1887
2281
  }
1888
2282
  if (id !== undefined) {
2283
+ // A second word is a record's id, and a record is read alone: a search beside it would be
2284
+ // dropped without a line, and the second word of a search was read so (`--search annual
2285
+ // leave` read the record "leave"). Here the words of a search are one word (ADR-0179).
2286
+ if (text(values, "search") !== undefined) {
2287
+ throw misuse(`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>"`);
2288
+ }
1889
2289
  if (on(values, "versions")) {
1890
2290
  const versions = await client.recordVersions(collection, id);
1891
2291
  answer(io, session, versions, () => formatPluginRecordVersions(versions));
@@ -2497,6 +2897,9 @@ const task = async (args, io) => {
2497
2897
  if (args[0] === "restore") {
2498
2898
  return taskRestore(args.slice(1), io);
2499
2899
  }
2900
+ if (args[0] === "follow" || args[0] === "mute") {
2901
+ return following(args[0] === "follow")(args.slice(1), io);
2902
+ }
2500
2903
  const { values, positionals } = parse(args, {});
2501
2904
  const ref = theOne(positionals, "Say which task: console task <number|id>");
2502
2905
  const session = await open(io, values);
@@ -2646,12 +3049,12 @@ const notify = async (args, io) => {
2646
3049
  ...(ownAgents === undefined ? {} : { ownAgents }),
2647
3050
  })));
2648
3051
  };
2649
- // Whether one task tells a member anything (ADR-0157): `follow` turns its notifications on,
2650
- // `mute` off. A task turned on that their settings would be silent of tells them of
3052
+ // Whether one task tells a member anything (ADR-0157): `task follow` turns its notifications
3053
+ // on, `task mute` off. A task turned on that their settings would be silent of tells them of
2651
3054
  // everything on it; one turned to what their settings say already is told by their kinds.
2652
3055
  const following = (turned) => async (args, io) => {
2653
3056
  const { values, positionals } = parse(args, {});
2654
- const ref = theOne(positionals, `Say which task: console ${turned ? "follow" : "mute"} <number|id>`);
3057
+ const ref = theOne(positionals, `Say which task: console task ${turned ? "follow" : "mute"} <number|id>`);
2655
3058
  const session = await open(io, values);
2656
3059
  const project = await session.project();
2657
3060
  const found = await project.task(ref);
@@ -2744,6 +3147,26 @@ const file = async (args, io) => {
2744
3147
  }, () => `Saved ${read.name} (${read.bytes.byteLength} bytes, ${read.contentType}) at ${saved}`);
2745
3148
  return EXIT.ok;
2746
3149
  };
3150
+ /**
3151
+ * What a take says first of what to do next (ADR-0176): the job's skill, before anything is
3152
+ * made. The rules say that a job begins with its skill; a take says the two commands, at the
3153
+ * moment the work begins and at every take, a later one of a session that left the rules out
3154
+ * among them. The one the task names is loaded; where it names none, the search is the
3155
+ * agent's, by words it chooses for the job, and a take runs none itself: a title is not the
3156
+ * words a skill is found by, and every take would pay for the read. The reads are of the
3157
+ * project the take named: where the pack is read is said as it was given, since without it a
3158
+ * desk reads the organization's pack, which may be another. Those words are spelled by the
3159
+ * skillcdn command's own rule, whose library a take loads only where it has a word to spell
3160
+ * (ADR-0179).
3161
+ */
3162
+ async function skillStep(values) {
3163
+ const given = whereGiven(values);
3164
+ const where = given.length === 0 ? "" : (await packReadsAfter())?.commandLine("", given);
3165
+ if (where === undefined) {
3166
+ 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.`;
3167
+ }
3168
+ 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.`;
3169
+ }
2747
3170
  /** Begins a run on a task, as the agent `--agent` names where it is said: the take itself. */
2748
3171
  function runOn(project, found, values) {
2749
3172
  const agent = text(values, "agent");
@@ -2796,6 +3219,7 @@ async function taking(session, project, found, ref, run, values) {
2796
3219
  const answered = held === undefined ? [] : [held === mark ? formatRulesLeftOut(mark) : formatRulesChanged(held)];
2797
3220
  const ruled = held === mark ? [] : [formatRules(rules, language), ""];
2798
3221
  const page = await taskPage(session, taken.number);
3222
+ const first = await skillStep(values);
2799
3223
  return {
2800
3224
  value: { run, task: taken, comments: comments.items, rules: { ...rules, mark } },
2801
3225
  words: () => [
@@ -2808,6 +3232,7 @@ async function taking(session, project, found, ref, run, values) {
2808
3232
  formatTask(taken, undefined, undefined, comments.items, page),
2809
3233
  "",
2810
3234
  ...ruled,
3235
+ first,
2811
3236
  'Say how it goes: console report "<what you found or did>". Hand in what you make: console hand-in <https url | file path>.',
2812
3237
  '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>".',
2813
3238
  ].join("\n"),
@@ -2926,6 +3351,14 @@ const ask = async (args, io) => {
2926
3351
  if (options.length < MIN_OPTIONS || options.length > MAX_OPTIONS) {
2927
3352
  throw misuse(`Give ${MIN_OPTIONS} to ${MAX_OPTIONS} options, one --option each.`);
2928
3353
  }
3354
+ // Said before the console is asked, with where the rest goes: its refusal names a field.
3355
+ if (question.length > MAX_QUESTION_LENGTH) {
3356
+ throw misuse(`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.`);
3357
+ }
3358
+ const long = options.find((label) => label.length > MAX_OPTION_LABEL_LENGTH);
3359
+ if (long !== undefined) {
3360
+ throw misuse(`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.`);
3361
+ }
2929
3362
  const seconds = secondsOf(text(values, "wait"), DEFAULT_ASK_WAIT_SECONDS);
2930
3363
  const body = await bodyOf(io, values, text(values, "body"));
2931
3364
  // The files put on the decision (ADR-0055): a picture of what is to be chosen between, for one.
@@ -3150,31 +3583,61 @@ const decision = async (args, io) => {
3150
3583
  return settle(io, session, waiter, found, seconds, false, wakes);
3151
3584
  };
3152
3585
  const docs = async (args, io) => {
3153
- const { values, positionals } = parse(args, {
3586
+ const parsed = parse(args, {
3154
3587
  search: { type: "string" },
3155
3588
  archived: { type: "boolean" },
3156
3589
  });
3157
- if (positionals.length > 1) {
3158
- throw misuse("Say one folder: console docs [<folder>] [--search <words>] [--archived]");
3590
+ const { values, positionals } = parsed;
3591
+ // A search is of every page of the project, and every bare word is of it (ADR-0179): a
3592
+ // folder beside the words narrowed nothing, and its word was dropped without a line.
3593
+ const search = searchTyped(parsed);
3594
+ if (search === undefined && positionals.length > 1) {
3595
+ throw misuse('Say one folder, or the words of a search after --search: console docs [<folder>] [--archived], or console docs --search "<words>"');
3596
+ }
3597
+ if (search === "") {
3598
+ throw misuse('Say what to search for: console docs --search "<words>"');
3159
3599
  }
3160
- const search = text(values, "search");
3161
3600
  const session = await open(io, values);
3162
3601
  const project = await session.project();
3163
3602
  // A folder is taken as the listing prints it, `guides/`, and as it is named, `guides`.
3164
- const folder = positionals[0]?.replace(/\/+$/, "");
3603
+ const folder = search === undefined ? positionals[0]?.replace(/\/+$/, "") : undefined;
3165
3604
  const found = await project.documents({
3166
3605
  ...(folder === undefined || folder === "" ? {} : { folder }),
3167
3606
  ...(search === undefined ? {} : { q: search }),
3168
3607
  ...(on(values, "archived") ? { archived: true } : {}),
3169
3608
  });
3170
- answer(io, session, found, () => formatDocuments(found));
3609
+ // A search that finds nothing says what it looked for, as one of the tasks does: a word
3610
+ // typed as a folder is a word of the search, and every word must be on a page.
3611
+ answer(io, session, found, () => search !== undefined && found.folders.length === 0 && found.items.length === 0
3612
+ ? /\s/.test(search.trim())
3613
+ ? `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.`
3614
+ : `No pages: none holds "${search.trim()}".`
3615
+ : formatDocuments(found));
3171
3616
  return EXIT.ok;
3172
3617
  };
3618
+ /** What a read of one page takes beside its path. */
3619
+ const DOC_READ_FLAGS = {
3620
+ version: { type: "string" },
3621
+ versions: { type: "boolean" },
3622
+ };
3623
+ /** Whether the words are a read of one page: one path, and no flag but a read's own. */
3624
+ function readsOnePage(args) {
3625
+ try {
3626
+ return parse(args, DOC_READ_FLAGS).positionals.length === 1;
3627
+ }
3628
+ catch {
3629
+ return false;
3630
+ }
3631
+ }
3173
3632
  const doc = async (args, io) => {
3174
- const { values, positionals } = parse(args, {
3175
- version: { type: "string" },
3176
- versions: { type: "boolean" },
3177
- });
3633
+ // A page may be called by a form's word, `write`, and is read as any page is (ADR-0167):
3634
+ // the word is the form wherever more follows it than a read of one page takes, a path or a
3635
+ // flag of the form's own, before the path as after it.
3636
+ const form = held(DOC_FORMS, args[0]);
3637
+ if (form !== undefined && !readsOnePage(args)) {
3638
+ return form(args.slice(1), io);
3639
+ }
3640
+ const { values, positionals } = parse(args, DOC_READ_FLAGS);
3178
3641
  const path = theOne(positionals, "Say which page: console doc <path> [--version <n>|--versions]");
3179
3642
  const session = await open(io, values);
3180
3643
  const project = await session.project();
@@ -3204,7 +3667,7 @@ const write = async (args, io) => {
3204
3667
  file: { type: "string" },
3205
3668
  base: { type: "string" },
3206
3669
  });
3207
- const path = theOne(positionals, 'Say which page: console write <path> --title "<title>" --body <markdown>|--file <path>');
3670
+ const path = theOne(positionals, 'Say which page: console doc write <path> --title "<title>" --body <markdown>|--file <path>');
3208
3671
  const body = await bodyOf(io, values, text(values, "body"));
3209
3672
  if (body === undefined) {
3210
3673
  throw misuse("Say what the page is to say: --body <markdown>, --file <path>, or --body - to read standard input.");
@@ -3244,7 +3707,7 @@ const attach = async (args, io) => {
3244
3707
  const { values, positionals } = parse(args, { label: { type: "string" } });
3245
3708
  const [path, file] = positionals;
3246
3709
  if (path === undefined || file === undefined || positionals.length > 2) {
3247
- throw misuse("Say the page and the file: console attach <path> <file> [--label <words>]");
3710
+ throw misuse("Say the page and the file: console doc attach <path> <file> [--label <words>]");
3248
3711
  }
3249
3712
  const label = text(values, "label");
3250
3713
  const session = await open(io, values);
@@ -3269,7 +3732,7 @@ const attach = async (args, io) => {
3269
3732
  };
3270
3733
  const archive = async (args, io) => {
3271
3734
  const { values, positionals } = parse(args, {});
3272
- const path = theOne(positionals, "Say which page: console archive <path>");
3735
+ const path = theOne(positionals, "Say which page: console doc archive <path>");
3273
3736
  const session = await open(io, values);
3274
3737
  const project = await session.project();
3275
3738
  const put = await project.archiveDocument(path);
@@ -3278,26 +3741,27 @@ const archive = async (args, io) => {
3278
3741
  };
3279
3742
  const restore = async (args, io) => {
3280
3743
  const { values, positionals } = parse(args, {});
3281
- const path = theOne(positionals, "Say which page: console restore <path>");
3744
+ const path = theOne(positionals, "Say which page: console doc restore <path>");
3282
3745
  const session = await open(io, values);
3283
3746
  const project = await session.project();
3284
3747
  const back = await project.restoreDocument(path);
3285
3748
  answer(io, session, back, () => `Restored ${back.path} (${back.title}).`);
3286
3749
  return EXIT.ok;
3287
3750
  };
3751
+ /** The forms of `console doc` that change a page, by the word that picks each. */
3752
+ const DOC_FORMS = { write, attach, archive, restore };
3288
3753
  const goals = async (args, io) => {
3289
- const { values } = parse(args, {
3754
+ const parsed = parse(args, {
3290
3755
  category: { type: "string" },
3291
3756
  state: { type: "string" },
3292
3757
  search: { type: "string" },
3293
3758
  ...PAGE_OPTIONS,
3294
- }, false);
3759
+ });
3760
+ const { values } = parsed;
3295
3761
  const state = goalStateOf(text(values, "state"));
3296
3762
  const category = text(values, "category");
3297
- const search = text(values, "search")?.trim();
3298
- if (search === "") {
3299
- throw misuse("Say what to search for: console goals --search <words>");
3300
- }
3763
+ // Every bare word is of the search where --search was typed, and no word goes without it.
3764
+ const search = listingSearch(parsed, "console goals");
3301
3765
  const page = pageOf(values);
3302
3766
  const session = await open(io, values);
3303
3767
  const project = await session.project();
@@ -3627,65 +4091,6 @@ const serve = async (args, io) => {
3627
4091
  await listening.closed;
3628
4092
  return EXIT.ok;
3629
4093
  };
3630
- /** What the runner keeps between its own restarts, as its file says it; nothing for a file that does not read. */
3631
- function runnerStateOf(text) {
3632
- if (text === undefined) {
3633
- return undefined;
3634
- }
3635
- let json;
3636
- try {
3637
- json = JSON.parse(text);
3638
- }
3639
- catch {
3640
- return undefined;
3641
- }
3642
- if (typeof json !== "object" || json === null) {
3643
- return undefined;
3644
- }
3645
- const delivered = "delivered" in json ? json.delivered : undefined;
3646
- const conversation = "conversation" in json ? json.conversation : undefined;
3647
- const driver = "driver" in json ? json.driver : undefined;
3648
- const limited = "limited" in json ? json.limited : undefined;
3649
- const kept = "kept" in json ? json.kept : undefined;
3650
- if (typeof delivered !== "number" || !Number.isSafeInteger(delivered) || delivered < 0) {
3651
- return undefined;
3652
- }
3653
- /**
3654
- * A moment in milliseconds since the epoch, or nothing for anything else: a number past what
3655
- * a date holds would fail the runner at every start, where it says the moment in words.
3656
- */
3657
- const momentOf = (value) => typeof value === "number" && Number.isSafeInteger(value) && value > 0 && value < 1e14
3658
- ? value
3659
- : undefined;
3660
- const since = typeof limited === "object" && limited !== null && "since" in limited
3661
- ? momentOf(limited.since)
3662
- : undefined;
3663
- return {
3664
- delivered,
3665
- conversation: typeof conversation === "string" && conversation.length > 0 && conversation.length <= 200
3666
- ? conversation
3667
- : undefined,
3668
- // The driver the conversation was begun under, as a registry spells one.
3669
- driver: typeof driver === "string" && /^[a-z][a-z0-9-]{0,39}$/.test(driver) ? driver : undefined,
3670
- // The usage limit the agent is not back from (ADR-0150): since when, and until when where the product said.
3671
- ...(since === undefined || typeof limited !== "object" || limited === null
3672
- ? {}
3673
- : {
3674
- limited: {
3675
- since,
3676
- until: "until" in limited ? momentOf(limited.until) : undefined,
3677
- },
3678
- }),
3679
- // The signals the record has as delivered that the agent never read: taken from the stream once more.
3680
- ...(Array.isArray(kept)
3681
- ? {
3682
- kept: kept
3683
- .filter((number) => momentOf(number) !== undefined)
3684
- .slice(0, 50),
3685
- }
3686
- : {}),
3687
- };
3688
- }
3689
4094
  /** A line a runner says of its machine, within what the console takes one in. */
3690
4095
  const machineLine = (text) => {
3691
4096
  const line = [...text]
@@ -3801,6 +4206,8 @@ const runner = async (args, io) => {
3801
4206
  });
3802
4207
  }
3803
4208
  const statePath = workPath("runner-state.json");
4209
+ // A wake source is named as a registry spells one, which is a file's name as it stands.
4210
+ const keptPath = (source) => workPath(`runner-kept-${source.replaceAll(/[^a-z0-9-]/g, "_")}.json`);
3804
4211
  const person = me.person;
3805
4212
  /** A runner for the desk's runner.json as it is read now: begun again whenever the file changed (ADR-0144). */
3806
4213
  const runnerOf = (read) => {
@@ -3832,9 +4239,15 @@ const runner = async (args, io) => {
3832
4239
  installed: io.version === undefined ? undefined : io.installedVersion,
3833
4240
  // What installs the console's version here, the way this command was installed.
3834
4241
  updateCommand: () => updateWords(io, io.consoleVersion?.()),
4242
+ // What the console said its version is, on the answers the runner gets anyway: where it
4243
+ // is newer than this command, the agent is told once (ADR-0182). A runner whose own
4244
+ // version is not known has nothing to hold it against.
4245
+ consoleVersion: io.version === undefined ? undefined : io.consoleVersion,
3835
4246
  now: io.now,
3836
4247
  random: host.random,
3837
4248
  time: (iso) => clock.format(new Date(iso)),
4249
+ // What a wake source shows of the agent at its messenger is in the workspace's language (ADR-0170).
4250
+ language: me.workspace.language ?? undefined,
3838
4251
  // A moment that may be on another day, a stretch the runner did not run in or when a
3839
4252
  // usage limit resets, is said as the command prints any moment: with its day, in the
3840
4253
  // workspace's zone where the login kept one.
@@ -3845,7 +4258,7 @@ const runner = async (args, io) => {
3845
4258
  },
3846
4259
  state: {
3847
4260
  load: async () => runnerStateOf(await host.readText(statePath)),
3848
- save: (state) => host.writePrivate(statePath, `${JSON.stringify(state)}\n`),
4261
+ save: (state) => host.replacePrivate(statePath, `${JSON.stringify(state)}\n`),
3849
4262
  },
3850
4263
  log: (line) => io.stdout(`${new Date(io.now()).toISOString()} ${line}\n`),
3851
4264
  // The autosave's git: in the desk, asking nobody at a terminal, its words read and let go.
@@ -3874,6 +4287,12 @@ const runner = async (args, io) => {
3874
4287
  }),
3875
4288
  fetch: (url, init) => io.fetch(url, { ...init, headers: { ...init.headers } }),
3876
4289
  socket: (url) => host.socket(url),
4290
+ // What a source keeps of what it brought the agent, ids and moments and never a word,
4291
+ // in a file of its own beside the runner's state: a runner started again reads it.
4292
+ kept: {
4293
+ load: async (source) => keptBySourceOf(await host.readText(keptPath(source))),
4294
+ save: (source, kept) => host.replacePrivate(keptPath(source), keptFileOf(kept)),
4295
+ },
3877
4296
  },
3878
4297
  });
3879
4298
  };
@@ -3941,7 +4360,7 @@ const manager = async (args, io) => {
3941
4360
  // The administrators stand in where there is no manager, or the manager is out.
3942
4361
  if (found.manager === null || found.manager.status !== "active") {
3943
4362
  lines.push(found.administrators.length === 0
3944
- ? "No administrator is in."
4363
+ ? "No administrator stands in."
3945
4364
  : "The administrators, who stand in:", ...found.administrators.map((person) => ` ${formatPersonLine(person)}`));
3946
4365
  }
3947
4366
  return lines.join("\n");
@@ -3960,11 +4379,25 @@ const agents = async (args, io) => {
3960
4379
  : found.items.map(formatAgentLine).join("\n"));
3961
4380
  return EXIT.ok;
3962
4381
  };
3963
- const AGENT_USAGE = '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]';
4382
+ const AGENT_USAGE = "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 ...";
4383
+ /**
4384
+ * Whether a console refused an agent account for the project it was not sent: one before 0.6.4,
4385
+ * which made an account in a project (ADR-0088) where a console now makes it in none
4386
+ * (ADR-0181), and says so as any body it cannot read, by the field's name.
4387
+ */
4388
+ /** The console's version as a sentence names it, `, 0.6.3,`, where it said one. */
4389
+ const consoleNamed = (io) => {
4390
+ const version = io.consoleVersion?.();
4391
+ return version === undefined ? "" : `, ${version},`;
4392
+ };
4393
+ const asksForProject = (error) => error instanceof ApiError &&
4394
+ error.status === 400 &&
4395
+ error.code === "request.invalid" &&
4396
+ error.message.startsWith("project:");
3964
4397
  // An administrator makes an agent account with flags, where the pages make one from a form
3965
4398
  // (ADR-0084): the member's row at once, its login let in. What is left out is proposed: the
3966
4399
  // name is the handle's, capitalized, and the console rolls the avatar from the seed, or from one
3967
- // of its own.
4400
+ // of its own. It is made in no project (ADR-0181), and the console leaves it its first message.
3968
4401
  const agentNew = async (args, io) => {
3969
4402
  const { values, positionals } = parse(args, {
3970
4403
  login: { type: "string" },
@@ -3986,18 +4419,14 @@ const agentNew = async (args, io) => {
3986
4419
  const derived = asked === undefined ? undefined : agentLoginOf(asked.workspace, handle);
3987
4420
  const login = text(values, "login") ?? derived?.login;
3988
4421
  if (login === undefined) {
3989
- throw misuse(`Say the account it will sign in with: console agent new ${handle} --login <login> --project <key>`);
4422
+ throw misuse(`Say the account it will sign in with: console agent new ${handle} --login <login>`);
3990
4423
  }
3991
4424
  const chosen = text(values, "host");
3992
4425
  const host = chosen === undefined ? (derived?.host ?? hostOfLogin(login)) : providerOf(chosen);
3993
- const project = await session.projectKey();
3994
- if (project === undefined) {
3995
- throw misuse(`Say the project it starts in: console agent new ${handle} --login ${login} --project <key>`);
3996
- }
3997
4426
  const manager = text(values, "manager");
3998
4427
  const seed = text(values, "seed");
3999
4428
  const title = text(values, "title");
4000
- const made = await session.client.createAgent({
4429
+ const input = {
4001
4430
  host,
4002
4431
  login,
4003
4432
  handle,
@@ -4007,9 +4436,24 @@ const agentNew = async (args, io) => {
4007
4436
  ...(manager === undefined || manager === "me"
4008
4437
  ? {}
4009
4438
  : { managerId: (await personOf(session, manager)).id }),
4010
- project,
4011
4439
  // A member who carries the login becomes the account only where that is said (ADR-0104).
4012
4440
  ...(on(values, "convert") ? { convert: true } : {}),
4441
+ };
4442
+ /** The project a console of before made the account in, with a task for its setup. */
4443
+ let before;
4444
+ const made = await session.client.createAgent(input).catch(async (error) => {
4445
+ if (!asksForProject(error)) {
4446
+ throw error;
4447
+ }
4448
+ // A console of before, which made nothing of what it refused: it is sent the project this
4449
+ // directory or --project names, and does with it what it did; where none is named, the
4450
+ // answer says what to type.
4451
+ const project = await session.projectKey();
4452
+ before = project;
4453
+ if (project === undefined) {
4454
+ throw failed(`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>`);
4455
+ }
4456
+ return session.client.createAgent({ ...input, project });
4013
4457
  });
4014
4458
  answer(io, session, made, () => [
4015
4459
  formatAgentLine(made),
@@ -4024,11 +4468,24 @@ const agentNew = async (args, io) => {
4024
4468
  : `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.`
4025
4469
  : `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.`
4026
4470
  : `${made.person.login} is an agent account from now on, with everything it did.`,
4027
- ...(made.onboarding === null || made.onboarding === undefined
4471
+ // What setting it up takes: a console of now left it as its first message to the
4472
+ // account, made in no project; one of before wrote a task, which it answers where it did.
4473
+ // A console of before lists the account in the project named here, a private one too:
4474
+ // said, since nothing was asked of a project.
4475
+ ...(before === undefined
4028
4476
  ? []
4029
4477
  : [
4030
- `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.`,
4478
+ `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}`,
4031
4479
  ]),
4480
+ ...(made.onboarding !== null && made.onboarding !== undefined
4481
+ ? [
4482
+ `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.`,
4483
+ ]
4484
+ : before !== undefined
4485
+ ? []
4486
+ : [
4487
+ `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>`,
4488
+ ]),
4032
4489
  `Next, a machine: console agent invite ${handle} makes the invitation that leads one to it.`,
4033
4490
  ].join("\n"));
4034
4491
  return EXIT.ok;
@@ -4046,7 +4503,8 @@ async function secretValue(io, values, prompt) {
4046
4503
  const file = text(values, "file");
4047
4504
  const value = file === undefined
4048
4505
  ? await secretGiven(io, prompt)
4049
- : (await io.readFile(file)).replace(/\r?\n$/, "");
4506
+ : // What a file comes to as a value is said once, for the command and the pages (ADR-0184).
4507
+ secretOfText(await io.readFile(file));
4050
4508
  if (value.length === 0) {
4051
4509
  throw failed("No value was given.");
4052
4510
  }
@@ -4065,11 +4523,20 @@ const SECRET_FLAGS = {
4065
4523
  file: { type: "string" },
4066
4524
  expires: { type: "string" },
4067
4525
  };
4526
+ /** What ends the listing of the offers that wait: the two things the account does with one. */
4527
+ const OFFERED_NEXT = "Take one into your store: console secret --accept <offer id> [--as <name>] [--replace] | leave one: console secret --decline <offer id>";
4068
4528
  // An agent account's own secret store (ADR-0087): the names it keeps, for the account itself,
4069
- // signed in as itself.
4529
+ // signed in as itself; and, with --offered, what members offered it that waits (ADR-0169).
4070
4530
  const secrets = async (args, io) => {
4071
- const { values } = parse(args, {}, false);
4531
+ const { values } = parse(args, { offered: { type: "boolean" } }, false);
4072
4532
  const session = await open(io, values);
4533
+ if (on(values, "offered")) {
4534
+ const offered = await session.client.secretOffers();
4535
+ answer(io, session, offered, () => offered.items.length === 0
4536
+ ? "No offered secret waits for you."
4537
+ : [...offered.items.map((item) => formatSecretOffer(item)), OFFERED_NEXT].join("\n"));
4538
+ return EXIT.ok;
4539
+ }
4073
4540
  const found = await session.client.secrets();
4074
4541
  answer(io, session, found, () => found.items.length === 0
4075
4542
  ? "No secret is kept yet: console secret <name> --set keeps one."
@@ -4077,9 +4544,59 @@ const secrets = async (args, io) => {
4077
4544
  return EXIT.ok;
4078
4545
  };
4079
4546
  const SECRET_USAGE = "Say which secret: console secret <name> | secret <name> --set [--file <path>] [--expires <day|none>] | secret <name> --remove";
4547
+ const OFFER_USAGE = "Say which offer, by its id as console secrets --offered lists it: console secret --accept <offer id> [--as <name>] [--replace] | secret --decline <offer id>";
4548
+ /**
4549
+ * An offer the account takes into its store or leaves (ADR-0169): named by its id, since the
4550
+ * name an offerer proposed is theirs to choose and two may propose the same.
4551
+ */
4552
+ async function offeredSecret(io, values, positionals) {
4553
+ const taking = on(values, "accept");
4554
+ if ((taking && on(values, "decline")) || on(values, "set") || on(values, "remove")) {
4555
+ throw misuse("Say one of --accept, --decline, --set and --remove.");
4556
+ }
4557
+ const as = text(values, "as");
4558
+ if (!taking && (as !== undefined || on(values, "replace"))) {
4559
+ throw misuse("--as and --replace go with --accept: an offer that is left is kept under no name.");
4560
+ }
4561
+ const id = theOne(positionals, OFFER_USAGE);
4562
+ const session = await open(io, values);
4563
+ if (!taking) {
4564
+ await session.client.leaveSecretOffer(id);
4565
+ answer(io, session, { left: id }, () => `The offer ${id} is left, and its value is gone.`);
4566
+ return EXIT.ok;
4567
+ }
4568
+ let kept;
4569
+ try {
4570
+ kept = await session.client.takeSecretOffer(id, {
4571
+ ...(as === undefined ? {} : { as }),
4572
+ ...(on(values, "replace") ? { replace: true } : {}),
4573
+ });
4574
+ }
4575
+ catch (error) {
4576
+ if (error instanceof ApiError && error.code === "secret.exists") {
4577
+ throw failed(`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.`);
4578
+ }
4579
+ throw error;
4580
+ }
4581
+ answer(io, session, kept, () => `Taken into your store: ${formatSecretLine(kept)}`);
4582
+ return EXIT.ok;
4583
+ }
4080
4584
  // One secret of the account's own: its value, read and noted; or set, typed unseen; or removed.
4585
+ // And one offered to it, taken or left.
4081
4586
  const secret = async (args, io) => {
4082
- const { values, positionals } = parse(args, SECRET_FLAGS);
4587
+ const { values, positionals } = parse(args, {
4588
+ ...SECRET_FLAGS,
4589
+ accept: { type: "boolean" },
4590
+ decline: { type: "boolean" },
4591
+ as: { type: "string" },
4592
+ replace: { type: "boolean" },
4593
+ });
4594
+ if (on(values, "accept") || on(values, "decline")) {
4595
+ return offeredSecret(io, values, positionals);
4596
+ }
4597
+ if (text(values, "as") !== undefined || on(values, "replace")) {
4598
+ throw misuse(`--as and --replace go with --accept. ${OFFER_USAGE}`);
4599
+ }
4083
4600
  const name = theOne(positionals, SECRET_USAGE);
4084
4601
  const session = await open(io, values);
4085
4602
  if (on(values, "remove")) {
@@ -4107,9 +4624,18 @@ const secret = async (args, io) => {
4107
4624
  // A supervisor's part of an agent account's store (ADR-0087): the names; a secret seeded,
4108
4625
  // write-only, which only the account reads back; one removed. Never a value.
4109
4626
  const agentSecrets = async (args, io) => {
4110
- const { values, positionals } = parse(args, {});
4111
- const handle = handleOf(theOne(positionals, "Say whose: console agent secrets <handle>"));
4627
+ const { values, positionals } = parse(args, { offered: { type: "boolean" } });
4628
+ const handle = handleOf(theOne(positionals, "Say whose: console agent secrets <handle> [--offered]"));
4112
4629
  const session = await open(io, values);
4630
+ if (on(values, "offered")) {
4631
+ // What the account was offered (ADR-0169): its record whole for a supervisor, and for any
4632
+ // other member what they offered it themselves.
4633
+ const offered = await session.client.agentSecretOffers(handle);
4634
+ answer(io, session, offered, () => offered.items.length === 0
4635
+ ? `Nothing was offered to @${handle} that is yours to read.`
4636
+ : offered.items.map((item) => formatSecretOffer(item)).join("\n"));
4637
+ return EXIT.ok;
4638
+ }
4113
4639
  let found;
4114
4640
  try {
4115
4641
  found = await session.client.agentSecrets(handle);
@@ -4131,10 +4657,39 @@ const agentSecrets = async (args, io) => {
4131
4657
  return EXIT.ok;
4132
4658
  };
4133
4659
  const agentSecret = async (args, io) => {
4134
- const { values, positionals } = parse(args, SECRET_FLAGS);
4135
- const [given, name] = theTwo(positionals, "Say whose and which: console agent secret <handle> <name> [--file <path>] [--expires <day|none>] | agent secret <handle> <name> --remove");
4660
+ const { values, positionals } = parse(args, {
4661
+ ...SECRET_FLAGS,
4662
+ offer: { type: "boolean" },
4663
+ note: { type: "string" },
4664
+ });
4665
+ const [given, name] = theTwo(positionals, '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');
4136
4666
  const handle = handleOf(given);
4667
+ const offering = on(values, "offer");
4668
+ const said = text(values, "note")?.trim();
4669
+ if (offering && on(values, "remove")) {
4670
+ throw misuse("Say one of --offer and --remove.");
4671
+ }
4672
+ if (said !== undefined && !offering) {
4673
+ throw misuse("--note says what an offered secret is for, and goes with --offer.");
4674
+ }
4137
4675
  const session = await open(io, values);
4676
+ if (offering) {
4677
+ // Any member's (ADR-0169): the value waits, sealed, for the account to take or leave, and
4678
+ // nothing of what the account keeps changes.
4679
+ const expiresOn = expiryOf(io, values);
4680
+ const value = await secretValue(io, values, `Value of ${name} to offer @${handle} (typed unseen; Enter ends it): `);
4681
+ const offered = await session.client.offerAgentSecret(handle, {
4682
+ name,
4683
+ value,
4684
+ ...(said === undefined || said === "" ? {} : { note: said }),
4685
+ ...(expiresOn === undefined ? {} : { expiresOn }),
4686
+ });
4687
+ answer(io, session, offered, () => [
4688
+ `Offered to @${handle}, which is told and takes it into its store or leaves it: ${formatSecretOffer(offered)}`,
4689
+ `Nothing @${handle} keeps changed, and nobody is answered the value. How it stands: console agent secrets ${handle} --offered`,
4690
+ ].join("\n"));
4691
+ return EXIT.ok;
4692
+ }
4138
4693
  if (on(values, "remove")) {
4139
4694
  await session.client.removeAgentSecret(handle, name);
4140
4695
  answer(io, session, { handle, removed: name }, () => `The secret ${name} of @${handle} is removed.`);
@@ -4143,10 +4698,20 @@ const agentSecret = async (args, io) => {
4143
4698
  const expiresOn = expiryOf(io, values);
4144
4699
  const value = await secretValue(io, values, `Value of ${name} for @${handle} (typed unseen; Enter ends it): `);
4145
4700
  const host = await gitHostFor(session.client, name);
4146
- const kept = await session.client.seedAgentSecret(handle, name, {
4147
- value,
4148
- ...(expiresOn === undefined ? {} : { expiresOn }),
4149
- });
4701
+ let kept;
4702
+ try {
4703
+ kept = await session.client.seedAgentSecret(handle, name, {
4704
+ value,
4705
+ ...(expiresOn === undefined ? {} : { expiresOn }),
4706
+ });
4707
+ }
4708
+ catch (error) {
4709
+ // Whoever supervises the account not is told what is theirs to do in its place.
4710
+ if (error instanceof ApiError && error.code === "auth.forbidden") {
4711
+ throw failed(`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>".`);
4712
+ }
4713
+ throw error;
4714
+ }
4150
4715
  const notes = secretNotes(name, value, host);
4151
4716
  answer(io, session, kept, () => [`Seeded for @${handle}, which alone reads it back: ${formatSecretLine(kept)}`, ...notes].join("\n"));
4152
4717
  return EXIT.ok;
@@ -4280,6 +4845,36 @@ const ownReset = async (args, io) => {
4280
4845
  answer(io, session, sent, () => `Asked, as signal #${sent.number} of your record: when this turn is over, your session ends and a new conversation begins with these words. Nothing else of this one goes with it: put what must be kept on the board, in your desk or in your product's memory before the turn ends.`);
4281
4846
  return EXIT.ok;
4282
4847
  };
4848
+ /**
4849
+ * What an account is told that asks of itself what its supervisors do (ADR-0180): a tell, an
4850
+ * interruption, a stop, a start, a setting, an invitation. Said before anything is sent where it
4851
+ * names itself `me`, which no such form takes, and where the console refused it by its handle.
4852
+ */
4853
+ const NOBODY_SUPERVISES_THEMSELVES = '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>".';
4854
+ /** Whether a word names the account itself where a supervisor's form wants a handle. */
4855
+ const namesItself = (word) => word === "me" || word === "@me";
4856
+ /**
4857
+ * A supervisor's act on an agent account (ADR-0084), refused as what it is. The console's
4858
+ * refusal says that only a supervisor may, and the hint after it would say the step is an
4859
+ * administrator's: of the account's own handle, the account is told that nobody supervises
4860
+ * themselves, which an account that administers is not told otherwise; of another's, whose the
4861
+ * step is. `me` is asked only on a refusal, so that the act costs no request more.
4862
+ */
4863
+ async function supervising(session, handle, act) {
4864
+ try {
4865
+ return await act();
4866
+ }
4867
+ catch (error) {
4868
+ if (!(error instanceof ApiError) || error.code !== "auth.forbidden") {
4869
+ throw error;
4870
+ }
4871
+ const me = await session.client.me().catch(() => undefined);
4872
+ if (me?.person?.handle === handle) {
4873
+ throw failed(`auth.forbidden: ${NOBODY_SUPERVISES_THEMSELVES}`);
4874
+ }
4875
+ throw failed(`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.`);
4876
+ }
4877
+ }
4283
4878
  /** The kinds of signal a supervisor sends with words: which need them, and which take them. */
4284
4879
  const WORDED_SIGNALS = {
4285
4880
  tell: { needs: true },
@@ -4290,41 +4885,40 @@ const WORDED_SIGNALS = {
4290
4885
  reset: { needs: false },
4291
4886
  wake: { needs: false },
4292
4887
  };
4888
+ /**
4889
+ * Whether the words after `agent wake` or `agent reset` are the account's own form: `me` where
4890
+ * the handle stands, wherever that is among the form's flags. Read without refusing a word, so
4891
+ * that a mistake among them is answered by the form that was typed, and not by the other's.
4892
+ */
4893
+ function isOwnForm(args, flags) {
4894
+ const { positionals } = parseArgs({
4895
+ args: [...args],
4896
+ options: { ...GLOBAL_OPTIONS, ...flags },
4897
+ allowPositionals: true,
4898
+ strict: false,
4899
+ });
4900
+ return positionals[0] === "me";
4901
+ }
4293
4902
  // A supervisor's signal to an agent account (ADR-0085): a tell, an interruption, a stop, a start
4294
4903
  // with the same conversation or with a new one, a wake; in their own name, on the account's
4295
4904
  // record. What it says is given as words, or with --file, or on standard input as `-`.
4296
4905
  const agentSignal = async (kind, args, io) => {
4297
4906
  // An account's own wake is another command under the same word: console agent wake me,
4298
4907
  // wherever `me` stands among its flags.
4299
- if (kind === "wake") {
4300
- let whom;
4301
- try {
4302
- whom = parse(args, OWN_WAKE_FLAGS).positionals[0];
4303
- }
4304
- catch {
4305
- whom = undefined;
4306
- }
4307
- if (whom === "me") {
4308
- return ownWake(args, io);
4309
- }
4908
+ if (kind === "wake" && isOwnForm(args, OWN_WAKE_FLAGS)) {
4909
+ return ownWake(args, io);
4310
4910
  }
4311
4911
  // And so is its own reset: console agent reset me.
4312
- if (kind === "reset") {
4313
- let whom;
4314
- try {
4315
- whom = parse(args, { file: { type: "string" } }).positionals[0];
4316
- }
4317
- catch {
4318
- whom = undefined;
4319
- }
4320
- if (whom === "me") {
4321
- return ownReset(args, io);
4322
- }
4912
+ if (kind === "reset" && isOwnForm(args, { file: { type: "string" } })) {
4913
+ return ownReset(args, io);
4323
4914
  }
4324
4915
  const { values, positionals } = parse(args, { file: { type: "string" } });
4325
4916
  const [given, words, ...rest] = positionals;
4326
4917
  const needs = WORDED_SIGNALS[kind]?.needs === true;
4327
4918
  const usage = `Say whom${needs ? " and what" : ""}: console agent ${kind} <handle> ${needs ? '"<words>"' : '["<words>"]'} [--file <path>]`;
4919
+ if (namesItself(given)) {
4920
+ throw misuse(NOBODY_SUPERVISES_THEMSELVES);
4921
+ }
4328
4922
  if (given === undefined || rest.length > 0) {
4329
4923
  throw misuse(usage);
4330
4924
  }
@@ -4334,10 +4928,10 @@ const agentSignal = async (kind, args, io) => {
4334
4928
  }
4335
4929
  const handle = handleOf(given);
4336
4930
  const session = await open(io, values);
4337
- const sent = await session.client.sendSignal(handle, {
4931
+ const sent = await supervising(session, handle, () => session.client.sendSignal(handle, {
4338
4932
  kind,
4339
4933
  ...(said.length === 0 ? {} : { text: said }),
4340
- });
4934
+ }));
4341
4935
  answer(io, session, sent, () => `Sent to @${handle}: ${formatSignalLine(sent)}`);
4342
4936
  return EXIT.ok;
4343
4937
  };
@@ -4349,6 +4943,9 @@ const agentSet = async (args, io) => {
4349
4943
  effort: { type: "string" },
4350
4944
  });
4351
4945
  const usage = "Say whom and what: console agent set <handle> [--model <name|none>] [--effort <level|none>]";
4946
+ if (namesItself(positionals[0])) {
4947
+ throw misuse(NOBODY_SUPERVISES_THEMSELVES);
4948
+ }
4352
4949
  const handle = handleOf(theOne(positionals, usage));
4353
4950
  const model = orNone(text(values, "model"));
4354
4951
  const effort = orNone(text(values, "effort"));
@@ -4356,13 +4953,13 @@ const agentSet = async (args, io) => {
4356
4953
  throw misuse(usage);
4357
4954
  }
4358
4955
  const session = await open(io, values);
4359
- const sent = await session.client.sendSignal(handle, {
4956
+ const sent = await supervising(session, handle, () => session.client.sendSignal(handle, {
4360
4957
  kind: "set",
4361
4958
  set: {
4362
4959
  ...(model === undefined ? {} : { model }),
4363
4960
  ...(effort === undefined ? {} : { effort }),
4364
4961
  },
4365
- });
4962
+ }));
4366
4963
  answer(io, session, sent, () => `Sent to @${handle}: ${formatSignalLine(sent)}`);
4367
4964
  return EXIT.ok;
4368
4965
  };
@@ -4484,6 +5081,9 @@ const agentInvite = async (args, io) => {
4484
5081
  revoke: { type: "boolean" },
4485
5082
  out: { type: "string" },
4486
5083
  });
5084
+ if (namesItself(positionals[0])) {
5085
+ throw misuse(NOBODY_SUPERVISES_THEMSELVES);
5086
+ }
4487
5087
  const handle = handleOf(theOne(positionals, "Say whose: console agent invite <handle> [--out <path>] | --revoke"));
4488
5088
  const out = text(values, "out");
4489
5089
  if (on(values, "revoke") && out !== undefined) {
@@ -4491,7 +5091,7 @@ const agentInvite = async (args, io) => {
4491
5091
  }
4492
5092
  const session = await open(io, values);
4493
5093
  if (on(values, "revoke")) {
4494
- await session.client.revokeAgentInvitation(handle);
5094
+ await supervising(session, handle, () => session.client.revokeAgentInvitation(handle));
4495
5095
  answer(io, session, { handle, revoked: true }, () => `The invitation of @${handle} is taken away: its code opens nothing now.`);
4496
5096
  return EXIT.ok;
4497
5097
  }
@@ -4510,7 +5110,7 @@ const agentInvite = async (args, io) => {
4510
5110
  throw failed(`Nothing can be written at ${out}, so no invitation was made and the one before stands. Say a path that can be written.`);
4511
5111
  }
4512
5112
  }
4513
- const made = await session.client.inviteAgent(handle);
5113
+ const made = await supervising(session, handle, () => session.client.inviteAgent(handle));
4514
5114
  const until = `good until ${moment(made.invitation.expiresAt)} or until its command has signed in`;
4515
5115
  const guide = `${session.url}/setup/${made.code}`;
4516
5116
  if (file === undefined) {
@@ -4544,8 +5144,10 @@ const agentInvite = async (args, io) => {
4544
5144
  // The code came this once and went nowhere: the invitation stands and nobody holds its line.
4545
5145
  throw failed(`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.`);
4546
5146
  }
4547
- // The path as both shells take it whole; where it has no such spelling, it is named in words.
4548
- const path = commandWord(written) ?? "<the file's path, quoted for your shell>";
5147
+ // The path as every shell takes it whole, by the skillcdn command's own rule; where it has
5148
+ // no such spelling, it is named in words.
5149
+ const path = (await packReadsAfter())?.commandLine("", [written])?.trim() ??
5150
+ "<the file's path, quoted for your shell>";
4549
5151
  answer(io, session, { handle, invitation: made.invitation, file: written }, () => [
4550
5152
  `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.`,
4551
5153
  `Hand the file on unread to whoever prepares the machine: as the body of a decision for them (console ask "<question>" --option "<one>" --option "<another>" --file ${path} --to <login>), attached to a comment on a task (console comment <number> "<a line for them>" --attach ${path}), or as a file at the messenger. Never as a comment's own words (--file there): the command prints them back. A decision read with the command afterwards shows the line. Remove the file once it is handed on: one left in a desk outside work/ is committed and pushed with it.`,
@@ -4937,6 +5539,8 @@ log) {
4937
5539
  await io.sleep(FIRST_SESSION_PAUSE_MS);
4938
5540
  }
4939
5541
  }
5542
+ // The task for its setup, where its plate holds one: an account a console before 0.6.4 made
5543
+ // has the one that console wrote, and keeps it (ADR-0181).
4940
5544
  const plate = await client.work().catch(() => undefined);
4941
5545
  const first = plate?.tasks.find((one) => one.task.title === onboardingTitle(handle));
4942
5546
  const inTheWay = await standsInTheWay(machine);
@@ -5084,7 +5688,7 @@ const DESK_USAGE = "Say at most one directory: console desk [<directory>] [--web
5084
5688
  function deskNext(web, skillsDir) {
5085
5689
  return [
5086
5690
  `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`,
5087
- `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")}`}`,
5691
+ `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")}`}`,
5088
5692
  ];
5089
5693
  }
5090
5694
  /** The files of the shell of a desk's pages as they are written: the two words the template leaves filled in. */
@@ -5433,7 +6037,23 @@ function serviceOf(word) {
5433
6037
  }
5434
6038
  return { role: role, service };
5435
6039
  }
5436
- const WORKSPACE_USAGE = `Say what to do: console workspace | console workspace edit [${WORKSPACE_FLAGS.replaceAll(", ", "] [")}] | console workspace pack-token --connect|--stdin|--remove`;
6040
+ const PACK_KEEPER_USAGE = "console workspace pack-keeper <login|none> [--round <HH:MM|none>] | console workspace pack-keeper --round <HH:MM|none>";
6041
+ 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}`;
6042
+ /**
6043
+ * What the member who keeps the organization's skills is called (ADR-0178), and whether they
6044
+ * are out, for the line that says who does: looked up among the people the asker sees, and
6045
+ * nothing where the workspace names nobody, or somebody the asker does not see.
6046
+ */
6047
+ async function keeperOf(session, workspace) {
6048
+ const id = workspace.skills.keeperId;
6049
+ if (typeof id !== "string") {
6050
+ return undefined;
6051
+ }
6052
+ const keeper = (await session.client.people()).items.find((one) => one.id === id);
6053
+ return keeper === undefined
6054
+ ? undefined
6055
+ : { called: calledOf(keeper), away: keeper.status !== "active" };
6056
+ }
5437
6057
  const workspace = async (args, io) => {
5438
6058
  const [verb, ...rest] = args;
5439
6059
  if (verb === undefined || verb.startsWith("--")) {
@@ -5441,7 +6061,47 @@ const workspace = async (args, io) => {
5441
6061
  const session = await open(io, values);
5442
6062
  const me = await session.client.me();
5443
6063
  await rememberZone(io, session, me.workspace.timeZone ?? undefined);
5444
- answer(io, session, me.workspace, () => formatWorkspace(me.workspace));
6064
+ const keeper = session.json ? undefined : await keeperOf(session, me.workspace);
6065
+ answer(io, session, me.workspace, () => formatWorkspace(me.workspace, keeper));
6066
+ return EXIT.ok;
6067
+ }
6068
+ if (verb === "pack-keeper") {
6069
+ // Who keeps the organization's skills, and the hour of their round (ADR-0178): an
6070
+ // administrator's to say, as the workspace's other settings are.
6071
+ const { values, positionals } = parse(rest, { round: { type: "string" } });
6072
+ const round = text(values, "round");
6073
+ if (positionals.length > 1 || (positionals.length === 0 && round === undefined)) {
6074
+ throw misuse(`Say who keeps the organization's skills, or the hour of their round: ${PACK_KEEPER_USAGE}`);
6075
+ }
6076
+ if (round !== undefined &&
6077
+ round !== "none" &&
6078
+ !/^(?:[01][0-9]|2[0-3]):[0-5][0-9]$/.test(round)) {
6079
+ throw misuse(`Not an hour of the day: ${round}. Say --round <HH:MM>, as 03:00, or none.`);
6080
+ }
6081
+ const session = await open(io, values);
6082
+ const [login] = positionals;
6083
+ const keeperId = login === undefined
6084
+ ? undefined
6085
+ : login === "none"
6086
+ ? null
6087
+ : (await personOf(session, login)).id;
6088
+ const changed = await session.client
6089
+ .updateWorkspace({
6090
+ ...(keeperId === undefined ? {} : { packKeeperId: keeperId }),
6091
+ ...(round === undefined ? {} : { packRoundAt: round === "none" ? null : round }),
6092
+ })
6093
+ .catch((error) => {
6094
+ // A console of before reads neither setting, and answers the change as one of nothing.
6095
+ if (error instanceof ApiError &&
6096
+ error.code === "request.invalid" &&
6097
+ error.message.startsWith("The patch names nothing to change")) {
6098
+ const version = io.consoleVersion?.();
6099
+ throw failed(`This console${version === undefined ? "" : `, ${version},`} names nobody who keeps the organization's skills yet: it is older than the command.`);
6100
+ }
6101
+ throw error;
6102
+ });
6103
+ const keeper = session.json ? undefined : await keeperOf(session, changed);
6104
+ answer(io, session, changed, () => formatWorkspace(changed, keeper));
5445
6105
  return EXIT.ok;
5446
6106
  }
5447
6107
  if (verb === "edit") {
@@ -5959,22 +6619,50 @@ const COMMANDS = {
5959
6619
  run,
5960
6620
  docs,
5961
6621
  doc,
6622
+ // The words of before (COMMAND_ALIASES, ADR-0167): they run as they did, and no list names them.
5962
6623
  write,
5963
6624
  attach,
5964
6625
  archive,
5965
6626
  restore,
5966
6627
  };
5967
- function help(io, name) {
5968
- if (name === undefined) {
6628
+ /** The words the dispatch takes: what a test holds to the pages of help and to the words of before. */
6629
+ export const COMMAND_WORDS = Object.keys(COMMANDS);
6630
+ /** What a word that is no command is answered with: the nearest there are, and where all are listed. */
6631
+ function notCommand(word, near = nearestCommands(word)) {
6632
+ return misuse(`Not a command: ${word}.${near.length === 0 ? "" : ` Nearest: ${near.join(", ")}.`} console help lists the commands.`);
6633
+ }
6634
+ /**
6635
+ * The help the words ask for (ADR-0167): the table of the commands for none, else the page of
6636
+ * a command, or of one of its forms. Flags among the words are left unread.
6637
+ */
6638
+ function help(io, words) {
6639
+ const named = words.filter((word) => !word.startsWith("-"));
6640
+ // Help asked of help is the table too.
6641
+ if (named.length === 0 || (named.length === 1 && named[0] === "help")) {
5969
6642
  io.stdout(usage(io.version, io.skillsDir));
5970
6643
  return EXIT.ok;
5971
6644
  }
5972
- const found = helpFor(name, io.skillsDir);
5973
- if (found === undefined) {
5974
- throw misuse(`Not a command: ${name}. The commands: ${Object.keys(COMMAND_HELP).join(", ")}`);
6645
+ const found = helpFor(named, io.skillsDir);
6646
+ if ("page" in found) {
6647
+ io.stdout(found.page);
6648
+ return EXIT.ok;
5975
6649
  }
5976
- io.stdout(found);
5977
- return EXIT.ok;
6650
+ if ("notCommand" in found) {
6651
+ throw notCommand(found.notCommand, found.near);
6652
+ }
6653
+ throw misuse(`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.`);
6654
+ }
6655
+ /**
6656
+ * The line after a command that was not understood (ADR-0167): where its forms and flags are,
6657
+ * the page of the form that was tried where it has one. Nothing where the words say it already.
6658
+ */
6659
+ function helpPointer(name, rest, said) {
6660
+ if (said.includes("console help")) {
6661
+ return "";
6662
+ }
6663
+ const [command, aliased] = held(COMMAND_ALIASES, name) ?? [name, undefined];
6664
+ const form = aliased ?? formTyped(command, rest);
6665
+ return `Its forms and flags: console help ${command}${form === undefined ? "" : ` ${form}`}\n`;
5978
6666
  }
5979
6667
  /**
5980
6668
  * A client of the console at `url`, naming the command on every request (ADR-0025). A redirect
@@ -6074,11 +6762,11 @@ function hintFor(error, io, seen) {
6074
6762
  case "project.not_found":
6075
6763
  return "No project has this key, or it is not yours to see. console projects lists the projects you may work in.\n";
6076
6764
  case "document.not_found":
6077
- return "No page has this path, in this project. console docs lists the pages of a folder; console write <path> writes one.\n";
6765
+ return "No page has this path, in this project. console docs lists the pages of a folder; console doc write <path> writes one.\n";
6078
6766
  case "document.conflict":
6079
6767
  return "The page has moved on since the version you started from. Read it again, and write from there.\n";
6080
6768
  case "document.archived":
6081
- return "The page is archived. console restore <path> brings it back first.\n";
6769
+ return "The page is archived. console doc restore <path> brings it back first.\n";
6082
6770
  case "task.invalid_category":
6083
6771
  return "No category has that key. console categories lists them.\n";
6084
6772
  case "task.invalid_goal":
@@ -6126,7 +6814,7 @@ function hintFor(error, io, seen) {
6126
6814
  case "category.in_use":
6127
6815
  return "Tasks are sorted into the category. Move them out first: console task edit <number> --category <other|none>\n";
6128
6816
  case "person.last_admin":
6129
- return "The board keeps at least one administrator in. Make another one first.\n";
6817
+ return "The board keeps at least one administrator in who is a person. Make another person one first.\n";
6130
6818
  case "person.of_organization":
6131
6819
  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";
6132
6820
  case "agent.login_is_member":
@@ -6171,14 +6859,18 @@ export async function runCli(argv, io) {
6171
6859
  return EXIT.ok;
6172
6860
  }
6173
6861
  if (name === undefined || name === "help" || name === "--help" || name === "-h") {
6174
- return help(io, rest[0]);
6862
+ return help(io, rest);
6175
6863
  }
6176
6864
  if (rest.includes("--help") || rest.includes("-h")) {
6177
- return help(io, name);
6865
+ // The page of the form that was being typed, where it has one.
6866
+ const [command, aliased] = held(COMMAND_ALIASES, name) ?? [name, undefined];
6867
+ const form = aliased ??
6868
+ formTyped(command, rest.filter((word) => word !== "--help" && word !== "-h"));
6869
+ return help(io, form === undefined ? [command] : [command, form]);
6178
6870
  }
6179
- const command = COMMANDS[name];
6871
+ const command = held(COMMANDS, name);
6180
6872
  if (command === undefined) {
6181
- throw misuse(`Not a command: ${name}. Run: console help`);
6873
+ throw notCommand(name);
6182
6874
  }
6183
6875
  const exit = await command(rest, watched);
6184
6876
  if (name !== "whoami") {
@@ -6188,7 +6880,11 @@ export async function runCli(argv, io) {
6188
6880
  }
6189
6881
  catch (error) {
6190
6882
  if (error instanceof CliExit) {
6191
- io.stderr(`${error.message}\n`);
6883
+ // A command that was not understood says where its forms and flags are, in a line.
6884
+ const pointer = error.exit === EXIT.usage && name !== undefined && held(COMMANDS, name) !== undefined
6885
+ ? helpPointer(name, rest, error.message)
6886
+ : "";
6887
+ io.stderr(`${error.message}\n${pointer}`);
6192
6888
  return error.exit;
6193
6889
  }
6194
6890
  if (error instanceof UnseenProject) {