@skillcdn/console 0.4.1 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (271) hide show
  1. package/README.md +19 -2
  2. package/SKILLCDN.md +7 -5
  3. package/dist/api.d.ts +4 -3
  4. package/dist/api.d.ts.map +1 -1
  5. package/dist/api.js +4 -3
  6. package/dist/api.js.map +1 -1
  7. package/dist/cli/cli.d.ts.map +1 -1
  8. package/dist/cli/cli.js +543 -34
  9. package/dist/cli/cli.js.map +1 -1
  10. package/dist/cli/format.d.ts +34 -3
  11. package/dist/cli/format.d.ts.map +1 -1
  12. package/dist/cli/format.js +277 -6
  13. package/dist/cli/format.js.map +1 -1
  14. package/dist/cli/help.d.ts.map +1 -1
  15. package/dist/cli/help.js +35 -2
  16. package/dist/cli/help.js.map +1 -1
  17. package/dist/cli/plugin-check.d.ts +21 -0
  18. package/dist/cli/plugin-check.d.ts.map +1 -0
  19. package/dist/cli/plugin-check.js +374 -0
  20. package/dist/cli/plugin-check.js.map +1 -0
  21. package/dist/cli/plugin-cli.d.ts +20 -0
  22. package/dist/cli/plugin-cli.d.ts.map +1 -0
  23. package/dist/cli/plugin-cli.js +123 -0
  24. package/dist/cli/plugin-cli.js.map +1 -0
  25. package/dist/cli/plugin-init.d.ts +20 -0
  26. package/dist/cli/plugin-init.d.ts.map +1 -0
  27. package/dist/cli/plugin-init.js +74 -0
  28. package/dist/cli/plugin-init.js.map +1 -0
  29. package/dist/cli/plugin-main.d.ts +3 -0
  30. package/dist/cli/plugin-main.d.ts.map +1 -0
  31. package/dist/cli/plugin-main.js +28 -0
  32. package/dist/cli/plugin-main.js.map +1 -0
  33. package/dist/client.d.ts +97 -1
  34. package/dist/client.d.ts.map +1 -1
  35. package/dist/client.js +63 -2
  36. package/dist/client.js.map +1 -1
  37. package/dist/compat.d.ts +1 -1
  38. package/dist/compat.js +2 -2
  39. package/dist/components/board.d.ts +8 -0
  40. package/dist/components/board.d.ts.map +1 -1
  41. package/dist/components/board.js +59 -15
  42. package/dist/components/board.js.map +1 -1
  43. package/dist/components/event-feed.d.ts +1 -1
  44. package/dist/components/event-feed.d.ts.map +1 -1
  45. package/dist/components/event-feed.js +33 -1
  46. package/dist/components/event-feed.js.map +1 -1
  47. package/dist/components/plugin-frame.d.ts +52 -0
  48. package/dist/components/plugin-frame.d.ts.map +1 -0
  49. package/dist/components/plugin-frame.js +314 -0
  50. package/dist/components/plugin-frame.js.map +1 -0
  51. package/dist/components/plugin-settings.d.ts +38 -0
  52. package/dist/components/plugin-settings.d.ts.map +1 -0
  53. package/dist/components/plugin-settings.js +348 -0
  54. package/dist/components/plugin-settings.js.map +1 -0
  55. package/dist/components/shell.d.ts +2 -0
  56. package/dist/components/shell.d.ts.map +1 -1
  57. package/dist/components/shell.js +26 -1
  58. package/dist/components/shell.js.map +1 -1
  59. package/dist/components/workspace.d.ts +7 -1
  60. package/dist/components/workspace.d.ts.map +1 -1
  61. package/dist/components/workspace.js +1 -1
  62. package/dist/components/workspace.js.map +1 -1
  63. package/dist/console.css +327 -0
  64. package/dist/console.d.ts.map +1 -1
  65. package/dist/console.js +136 -26
  66. package/dist/console.js.map +1 -1
  67. package/dist/data.d.ts +7 -1
  68. package/dist/data.d.ts.map +1 -1
  69. package/dist/data.js +19 -2
  70. package/dist/data.js.map +1 -1
  71. package/dist/i18n/en.d.ts +149 -0
  72. package/dist/i18n/en.d.ts.map +1 -1
  73. package/dist/i18n/en.js +160 -0
  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 +144 -0
  77. package/dist/i18n/ko.js.map +1 -1
  78. package/dist/index.d.ts +3 -1
  79. package/dist/index.d.ts.map +1 -1
  80. package/dist/index.js +3 -1
  81. package/dist/index.js.map +1 -1
  82. package/dist/plugin/args.d.ts +148 -0
  83. package/dist/plugin/args.d.ts.map +1 -0
  84. package/dist/plugin/args.js +369 -0
  85. package/dist/plugin/args.js.map +1 -0
  86. package/dist/plugin/bridge.d.ts +146 -0
  87. package/dist/plugin/bridge.d.ts.map +1 -0
  88. package/dist/plugin/bridge.js +125 -0
  89. package/dist/plugin/bridge.js.map +1 -0
  90. package/dist/plugin/capabilities.d.ts +20 -0
  91. package/dist/plugin/capabilities.d.ts.map +1 -0
  92. package/dist/plugin/capabilities.js +133 -0
  93. package/dist/plugin/capabilities.js.map +1 -0
  94. package/dist/plugin/context.d.ts +374 -0
  95. package/dist/plugin/context.d.ts.map +1 -0
  96. package/dist/plugin/context.js +2 -0
  97. package/dist/plugin/context.js.map +1 -0
  98. package/dist/plugin/define.d.ts +208 -0
  99. package/dist/plugin/define.d.ts.map +1 -0
  100. package/dist/plugin/define.js +482 -0
  101. package/dist/plugin/define.js.map +1 -0
  102. package/dist/plugin/definition-error.d.ts +11 -0
  103. package/dist/plugin/definition-error.d.ts.map +1 -0
  104. package/dist/plugin/definition-error.js +17 -0
  105. package/dist/plugin/definition-error.js.map +1 -0
  106. package/dist/plugin/limits.d.ts +67 -0
  107. package/dist/plugin/limits.d.ts.map +1 -0
  108. package/dist/plugin/limits.js +70 -0
  109. package/dist/plugin/limits.js.map +1 -0
  110. package/dist/plugin/load-worker.d.ts +7 -0
  111. package/dist/plugin/load-worker.d.ts.map +1 -0
  112. package/dist/plugin/load-worker.js +41 -0
  113. package/dist/plugin/load-worker.js.map +1 -0
  114. package/dist/plugin/load.d.ts +18 -0
  115. package/dist/plugin/load.d.ts.map +1 -0
  116. package/dist/plugin/load.js +62 -0
  117. package/dist/plugin/load.js.map +1 -0
  118. package/dist/plugin/manifest.d.ts +237 -0
  119. package/dist/plugin/manifest.d.ts.map +1 -0
  120. package/dist/plugin/manifest.js +411 -0
  121. package/dist/plugin/manifest.js.map +1 -0
  122. package/dist/plugin/refusals.d.ts +49 -0
  123. package/dist/plugin/refusals.d.ts.map +1 -0
  124. package/dist/plugin/refusals.js +79 -0
  125. package/dist/plugin/refusals.js.map +1 -0
  126. package/dist/plugin/rest-schemas.d.ts +556 -0
  127. package/dist/plugin/rest-schemas.d.ts.map +1 -0
  128. package/dist/plugin/rest-schemas.js +262 -0
  129. package/dist/plugin/rest-schemas.js.map +1 -0
  130. package/dist/plugin/sandbox.d.ts +23 -0
  131. package/dist/plugin/sandbox.d.ts.map +1 -0
  132. package/dist/plugin/sandbox.js +99 -0
  133. package/dist/plugin/sandbox.js.map +1 -0
  134. package/dist/plugin/testing.d.ts +45 -0
  135. package/dist/plugin/testing.d.ts.map +1 -0
  136. package/dist/plugin/testing.js +420 -0
  137. package/dist/plugin/testing.js.map +1 -0
  138. package/dist/plugin/web-react.d.ts +11 -0
  139. package/dist/plugin/web-react.d.ts.map +1 -0
  140. package/dist/plugin/web-react.js +34 -0
  141. package/dist/plugin/web-react.js.map +1 -0
  142. package/dist/plugin/web.d.ts +95 -0
  143. package/dist/plugin/web.d.ts.map +1 -0
  144. package/dist/plugin/web.js +245 -0
  145. package/dist/plugin/web.js.map +1 -0
  146. package/dist/plugin-nav.d.ts +29 -0
  147. package/dist/plugin-nav.d.ts.map +1 -0
  148. package/dist/plugin-nav.js +92 -0
  149. package/dist/plugin-nav.js.map +1 -0
  150. package/dist/plugin-testing.d.ts +2 -0
  151. package/dist/plugin-testing.d.ts.map +1 -0
  152. package/dist/plugin-testing.js +4 -0
  153. package/dist/plugin-testing.js.map +1 -0
  154. package/dist/plugin-web-react.d.ts +3 -0
  155. package/dist/plugin-web-react.d.ts.map +1 -0
  156. package/dist/plugin-web-react.js +3 -0
  157. package/dist/plugin-web-react.js.map +1 -0
  158. package/dist/plugin-web.d.ts +4 -0
  159. package/dist/plugin-web.d.ts.map +1 -0
  160. package/dist/plugin-web.js +5 -0
  161. package/dist/plugin-web.js.map +1 -0
  162. package/dist/plugin.d.ts +11 -0
  163. package/dist/plugin.d.ts.map +1 -0
  164. package/dist/plugin.js +15 -0
  165. package/dist/plugin.js.map +1 -0
  166. package/dist/router.d.ts +28 -0
  167. package/dist/router.d.ts.map +1 -1
  168. package/dist/router.js +47 -0
  169. package/dist/router.js.map +1 -1
  170. package/dist/routes.d.ts +4 -0
  171. package/dist/routes.d.ts.map +1 -1
  172. package/dist/routes.js +6 -0
  173. package/dist/routes.js.map +1 -1
  174. package/dist/schemas.d.ts +117 -0
  175. package/dist/schemas.d.ts.map +1 -1
  176. package/dist/schemas.js +40 -1
  177. package/dist/schemas.js.map +1 -1
  178. package/dist/tokens.d.ts +2 -0
  179. package/dist/tokens.d.ts.map +1 -0
  180. package/dist/tokens.js +101 -0
  181. package/dist/tokens.js.map +1 -0
  182. package/dist/vocabulary.d.ts +11 -1
  183. package/dist/vocabulary.d.ts.map +1 -1
  184. package/dist/vocabulary.js +24 -0
  185. package/dist/vocabulary.js.map +1 -1
  186. package/dist/web.d.ts.map +1 -1
  187. package/dist/web.js +2 -0
  188. package/dist/web.js.map +1 -1
  189. package/docs/specs/cli.md +11 -4
  190. package/docs/specs/plugins.md +487 -0
  191. package/docs/specs/rest.md +3 -2
  192. package/package.json +20 -2
  193. package/skills/building-a-console/SKILL.md +25 -26
  194. package/skills/building-a-console/references/configuring.md +40 -0
  195. package/skills/building-a-console/references/the-default-console.md +1 -1
  196. package/skills/building-a-console/references/the-look-from-a-website.md +5 -5
  197. package/skills/building-a-plugin/SKILL.md +137 -0
  198. package/skills/deploying-a-console/SKILL.md +24 -26
  199. package/skills/deploying-a-console/references/access.md +13 -9
  200. package/skills/deploying-a-console/references/resources.md +25 -10
  201. package/skills/deploying-a-console/references/running-it-again.md +15 -0
  202. package/skills/deploying-a-console/references/sizing.md +2 -0
  203. package/skills/planning-the-board/SKILL.md +96 -0
  204. package/skills/planning-the-board/references/a-task.md +36 -0
  205. package/skills/planning-the-board/references/setting-up.md +44 -0
  206. package/skills/working-the-board/SKILL.md +43 -34
  207. package/skills/working-the-board/references/the-pack.md +19 -0
  208. package/src/api.ts +8 -0
  209. package/src/cli/cli.ts +697 -33
  210. package/src/cli/format.ts +356 -9
  211. package/src/cli/help.ts +41 -2
  212. package/src/cli/plugin-check.ts +470 -0
  213. package/src/cli/plugin-cli.ts +148 -0
  214. package/src/cli/plugin-init.ts +90 -0
  215. package/src/cli/plugin-main.ts +30 -0
  216. package/src/client.ts +294 -0
  217. package/src/compat.ts +2 -2
  218. package/src/components/board.tsx +62 -14
  219. package/src/components/event-feed.tsx +42 -1
  220. package/src/components/plugin-frame.tsx +437 -0
  221. package/src/components/plugin-settings.tsx +1111 -0
  222. package/src/components/shell.tsx +82 -14
  223. package/src/components/workspace.tsx +18 -0
  224. package/src/console.tsx +286 -19
  225. package/src/data.ts +27 -2
  226. package/src/i18n/en.ts +168 -0
  227. package/src/i18n/ko.ts +148 -0
  228. package/src/index.ts +12 -0
  229. package/src/plugin/args.ts +526 -0
  230. package/src/plugin/bridge.ts +314 -0
  231. package/src/plugin/capabilities.ts +150 -0
  232. package/src/plugin/context.ts +416 -0
  233. package/src/plugin/define.ts +792 -0
  234. package/src/plugin/definition-error.ts +19 -0
  235. package/src/plugin/limits.ts +70 -0
  236. package/src/plugin/load-worker.ts +50 -0
  237. package/src/plugin/load.ts +82 -0
  238. package/src/plugin/manifest.ts +561 -0
  239. package/src/plugin/refusals.ts +94 -0
  240. package/src/plugin/rest-schemas.ts +354 -0
  241. package/src/plugin/sandbox.ts +123 -0
  242. package/src/plugin/testing.ts +612 -0
  243. package/src/plugin/web-react.ts +45 -0
  244. package/src/plugin/web.ts +403 -0
  245. package/src/plugin-nav.ts +132 -0
  246. package/src/plugin-testing.ts +10 -0
  247. package/src/plugin-web-react.ts +4 -0
  248. package/src/plugin-web.ts +35 -0
  249. package/src/plugin.ts +126 -0
  250. package/src/router.ts +73 -0
  251. package/src/routes.ts +7 -0
  252. package/src/schemas.ts +43 -0
  253. package/src/styles/console.css +327 -0
  254. package/src/tokens.ts +101 -0
  255. package/src/vocabulary.ts +30 -0
  256. package/src/web.ts +2 -0
  257. package/template/plugin/.gitignore +2 -0
  258. package/template/plugin/README.md +26 -0
  259. package/template/plugin/SKILLCDN.md +13 -0
  260. package/template/plugin/build.mjs +40 -0
  261. package/template/plugin/console-plugin.json +50 -0
  262. package/template/plugin/package.json +27 -0
  263. package/template/plugin/skills/__key__/SKILL.md +23 -0
  264. package/template/plugin/src/check.test.ts +34 -0
  265. package/template/plugin/src/server/index.test.ts +41 -0
  266. package/template/plugin/src/server/index.ts +72 -0
  267. package/template/plugin/src/web/index.css +51 -0
  268. package/template/plugin/src/web/index.ts +115 -0
  269. package/template/plugin/tsconfig.json +17 -0
  270. package/skills/working-the-board/references/setting-up.md +0 -3
  271. /package/skills/{working-the-board → planning-the-board}/references/project-rules.md +0 -0
package/src/cli/cli.ts CHANGED
@@ -5,6 +5,7 @@ import {
5
5
  type ConsoleClient,
6
6
  createClient,
7
7
  type FetchLike,
8
+ type PluginClient,
8
9
  type ProjectClient,
9
10
  } from "../client.js";
10
11
  import {
@@ -20,6 +21,8 @@ import {
20
21
  } from "../compat.js";
21
22
  import { addDays, dayOf as dayOfDate, firstDayOfWeek, isDay, weekOf } from "../dates.js";
22
23
  import { DEFAULT_PAGE_LIMIT, LIST_LIMIT, MAX_OPTIONS, MIN_OPTIONS } from "../limits.js";
24
+ import { capabilityWords } from "../plugin/capabilities.js";
25
+ import { PLUGIN_LIST_LIMIT } from "../plugin/limits.js";
23
26
  import { fillRules, RULES_PATH, RULES_TITLE } from "../rules.js";
24
27
  import {
25
28
  hostOfLogin,
@@ -28,6 +31,10 @@ import {
28
31
  type RestMember,
29
32
  type RestPackConnectStarted,
30
33
  type RestPerson,
34
+ type RestPluginDetail,
35
+ type RestPluginEnableInput,
36
+ type RestPluginGrantInput,
37
+ type RestPluginInvocation,
31
38
  type RestSkillBrowse,
32
39
  type RestSkillFile,
33
40
  type RestSkillLoad,
@@ -78,12 +85,21 @@ import {
78
85
  formatDocuments,
79
86
  formatGoal,
80
87
  formatGoalLine,
88
+ formatInvocation,
81
89
  formatListingLine,
82
90
  formatMemberLine,
83
91
  formatMore,
84
92
  formatOptions,
85
93
  formatPersonLine,
86
94
  formatPersonWork,
95
+ formatPlugin,
96
+ formatPluginGrantLine,
97
+ formatPluginHelp,
98
+ formatPluginRecord,
99
+ formatPluginRecords,
100
+ formatPluginRecordVersions,
101
+ formatPluginSettingLine,
102
+ formatPlugins,
87
103
  formatProject,
88
104
  formatProjectLine,
89
105
  formatRules,
@@ -95,6 +111,7 @@ import {
95
111
  formatVersionLine,
96
112
  formatWork,
97
113
  formatWorkspace,
114
+ localized,
98
115
  moment,
99
116
  setMomentZone,
100
117
  } from "./format.js";
@@ -1107,20 +1124,55 @@ const MAX_FIND_LIMIT = 25;
1107
1124
 
1108
1125
  /** The pack of the project as the console lists it, and what its reads are rendered at; none when the pack did not answer. */
1109
1126
  async function packOf(
1110
- project: ProjectClient,
1127
+ reader: PackReader,
1111
1128
  ): Promise<{ readonly listing: RestSkills; readonly summary: PackSummary | undefined }> {
1112
- const listing = await project.skills();
1129
+ const listing = await reader.skills();
1113
1130
  return { listing, summary: summaryOf(listing) };
1114
1131
  }
1115
1132
 
1116
- const skills: Command = async (args, io) => {
1117
- const { values, positionals } = parse(args, {
1118
- search: { type: "string" },
1119
- limit: { type: "string" },
1120
- cursor: { type: "string" },
1121
- });
1133
+ /** What reads a pack: a project's client, or a plugin's, whose skills are a pack of their own. */
1134
+ type PackReader = Pick<
1135
+ ProjectClient,
1136
+ "skills" | "skill" | "skillFile" | "skillBrowse" | "skillFind"
1137
+ >;
1138
+
1139
+ const SKILLS_OPTIONS: OptionSpec = {
1140
+ search: { type: "string" },
1141
+ limit: { type: "string" },
1142
+ cursor: { type: "string" },
1143
+ };
1144
+
1145
+ const SKILL_OPTIONS: OptionSpec = {
1146
+ file: { type: "string" },
1147
+ offset: { type: "string" },
1148
+ limit: { type: "string" },
1149
+ };
1150
+
1151
+ /** The line `console skills` ends with: where the plugins' own skills are. */
1152
+ const PLUGIN_SKILLS_LINE =
1153
+ "The plugins of this console have skills of their own: console plugins lists the plugins, console plugin <key> skills the skills of one.";
1154
+
1155
+ /**
1156
+ * The pack as the words say: whole, a folder of it, a file's outline, or what words find; for
1157
+ * the project's pack as `console skills`, and for a plugin's as `console plugin <key> skills`.
1158
+ */
1159
+ async function readSkills(
1160
+ io: CliIo,
1161
+ session: Session,
1162
+ reader: PackReader,
1163
+ values: Values,
1164
+ positionals: readonly string[],
1165
+ extras: {
1166
+ /** The command these words came after, for what is said when they are not understood. */
1167
+ readonly command: string;
1168
+ /** Where the console's own skills are on this machine, said with the project's pack. */
1169
+ readonly own?: string | undefined;
1170
+ /** A line after the listing whole. */
1171
+ readonly afterwards?: string | undefined;
1172
+ },
1173
+ ): Promise<number> {
1122
1174
  if (positionals.length > 1) {
1123
- throw misuse("Say one folder: console skills [<folder>] [--search <words>]");
1175
+ throw misuse(`Say one folder: ${extras.command} [<folder>] [--search <words>]`);
1124
1176
  }
1125
1177
  // The root of the pack is the mounted folder, which the deployment reads as no path at all.
1126
1178
  const given = positionals[0];
@@ -1130,7 +1182,7 @@ const skills: Command = async (args, io) => {
1130
1182
  const cursor = text(values, "cursor");
1131
1183
  if (words === undefined && (limit !== undefined || cursor !== undefined)) {
1132
1184
  throw misuse(
1133
- "--limit and --cursor go with --search: console skills --search <words> [--limit <n>] [--cursor <cursor>]",
1185
+ `--limit and --cursor go with --search: ${extras.command} --search <words> [--limit <n>] [--cursor <cursor>]`,
1134
1186
  );
1135
1187
  }
1136
1188
  const atMost = limit === undefined ? undefined : Number(limit);
@@ -1140,17 +1192,19 @@ const skills: Command = async (args, io) => {
1140
1192
  ) {
1141
1193
  throw misuse(`Not a number of results, 1 to ${MAX_FIND_LIMIT}: ${limit}`);
1142
1194
  }
1143
- const session = await open(io, values);
1144
- const project = await session.project();
1145
- const { listing, summary } = await packOf(project);
1195
+ const { listing, summary } = await packOf(reader);
1146
1196
  // The pack as it stands; or why it does not answer, which a folder or a search would meet too.
1147
1197
  if (summary === undefined || (words === undefined && given === undefined)) {
1148
- answer(io, session, listing, () => formatSkills(listing, io.skillsDir));
1198
+ answer(io, session, listing, () =>
1199
+ [formatSkills(listing, extras.own), extras.afterwards]
1200
+ .filter((part): part is string => part !== undefined)
1201
+ .join("\n"),
1202
+ );
1149
1203
  return EXIT.ok;
1150
1204
  }
1151
1205
  if (words !== undefined) {
1152
1206
  // One page of what the words find; more is said, and asked for with --cursor.
1153
- const found = await project.skillFind(words, { path: folder, limit: atMost, cursor });
1207
+ const found = await reader.skillFind(words, { path: folder, limit: atMost, cursor });
1154
1208
  answer(io, session, found, () => formatSkillFind(found, summary));
1155
1209
  return EXIT.ok;
1156
1210
  }
@@ -1159,7 +1213,7 @@ const skills: Command = async (args, io) => {
1159
1213
  let next: string | undefined;
1160
1214
  let last: RestSkillBrowse | undefined;
1161
1215
  for (let n = 0; n < MAX_SKILL_PAGES; n += 1) {
1162
- last = await project.skillBrowse({ path: folder, cursor: next });
1216
+ last = await reader.skillBrowse({ path: folder, cursor: next });
1163
1217
  if (last.read?.status !== "ready") {
1164
1218
  break;
1165
1219
  }
@@ -1178,6 +1232,17 @@ const skills: Command = async (args, io) => {
1178
1232
  formatSkillBrowse(browsed, whole),
1179
1233
  );
1180
1234
  return EXIT.ok;
1235
+ }
1236
+
1237
+ const skills: Command = async (args, io) => {
1238
+ const { values, positionals } = parse(args, SKILLS_OPTIONS);
1239
+ const session = await open(io, values);
1240
+ const project = await session.project();
1241
+ return readSkills(io, session, project, values, positionals, {
1242
+ command: "console skills",
1243
+ own: io.skillsDir,
1244
+ afterwards: PLUGIN_SKILLS_LINE,
1245
+ });
1181
1246
  };
1182
1247
 
1183
1248
  /** The most characters one read of a file asks for: what the console's API allows on one page. */
@@ -1205,18 +1270,24 @@ function countOf(
1205
1270
  return count;
1206
1271
  }
1207
1272
 
1208
- const skill: Command = async (args, io) => {
1209
- const { values, positionals } = parse(args, {
1210
- file: { type: "string" },
1211
- offset: { type: "string" },
1212
- limit: { type: "string" },
1213
- });
1273
+ /**
1274
+ * One skill of the pack whole, a file of it, or one page of a file; for the project's pack as
1275
+ * `console skill`, and for a plugin's as `console plugin <key> skill`.
1276
+ */
1277
+ async function readSkill(
1278
+ io: CliIo,
1279
+ session: Session,
1280
+ reader: PackReader,
1281
+ values: Values,
1282
+ positionals: readonly string[],
1283
+ command: string,
1284
+ ): Promise<number> {
1214
1285
  const file = text(values, "file");
1215
1286
  // A file is read by its own path from the repository's root; a skill's path beside it would be
1216
1287
  // ignored, which reads as if it mattered, so the two together are not understood.
1217
1288
  if (file !== undefined && positionals.length > 0) {
1218
1289
  throw misuse(
1219
- "Say one: console skill <path of its SKILL.md> for a skill, or console skill --file <path> for a file of the pack.",
1290
+ `Say one: ${command} <path of its SKILL.md> for a skill, or ${command} --file <path> for a file of the pack.`,
1220
1291
  );
1221
1292
  }
1222
1293
  // A section is a page of a file read as asked (SkillCDN 0.4): the flags mean nothing without one.
@@ -1225,14 +1296,12 @@ const skill: Command = async (args, io) => {
1225
1296
  (text(values, "offset") !== undefined || text(values, "limit") !== undefined)
1226
1297
  ) {
1227
1298
  throw misuse(
1228
- "--offset and --limit go with --file: console skill --file <path> [--offset <n>] [--limit <n>]",
1299
+ `--offset and --limit go with --file: ${command} --file <path> [--offset <n>] [--limit <n>]`,
1229
1300
  );
1230
1301
  }
1231
1302
  const offset = countOf(text(values, "offset"), "offset", { least: 0 });
1232
1303
  const limit = countOf(text(values, "limit"), "limit", { least: 1, most: MAX_FILE_LIMIT });
1233
- const session = await open(io, values);
1234
- const project = await session.project();
1235
- const { listing, summary } = await packOf(project);
1304
+ const { listing, summary } = await packOf(reader);
1236
1305
  if (summary === undefined) {
1237
1306
  answer(io, session, listing, () => formatSkills(listing, io.skillsDir));
1238
1307
  return EXIT.ok;
@@ -1240,7 +1309,7 @@ const skill: Command = async (args, io) => {
1240
1309
  if (file !== undefined && (offset !== undefined || limit !== undefined)) {
1241
1310
  // One page as asked, the section a search or an outline named; the result says where the
1242
1311
  // file continues, and asks for nothing.
1243
- const page = await project.skillFile(file, { offset, limit });
1312
+ const page = await reader.skillFile(file, { offset, limit });
1244
1313
  const section = page.read === null ? undefined : joinFile([page], summary, limit);
1245
1314
  answer(io, session, { ...page, read: section === undefined ? null : bodyOfFile(section) }, () =>
1246
1315
  formatSkillFile(page, section),
@@ -1253,7 +1322,7 @@ const skill: Command = async (args, io) => {
1253
1322
  let offset: number | undefined;
1254
1323
  let last: RestSkillFile | undefined;
1255
1324
  for (let n = 0; n < MAX_SKILL_PAGES; n += 1) {
1256
- last = await project.skillFile(file, offset === undefined ? {} : { offset });
1325
+ last = await reader.skillFile(file, offset === undefined ? {} : { offset });
1257
1326
  if (last.read === null) {
1258
1327
  break;
1259
1328
  }
@@ -1276,7 +1345,7 @@ const skill: Command = async (args, io) => {
1276
1345
  const wanted = skillPathIn(
1277
1346
  theOne(
1278
1347
  positionals,
1279
- "Say which skill: console skill <path of its SKILL.md>, or console skill --file <path> for a file of the pack",
1348
+ `Say which skill: ${command} <path of its SKILL.md>, or ${command} --file <path> for a file of the pack`,
1280
1349
  ),
1281
1350
  listing.address,
1282
1351
  );
@@ -1288,7 +1357,7 @@ const skill: Command = async (args, io) => {
1288
1357
  let cursor: string | undefined;
1289
1358
  let last: RestSkillLoad | undefined;
1290
1359
  for (let n = 0; n < MAX_SKILL_PAGES; n += 1) {
1291
- last = await project.skill(wanted.path, cursor);
1360
+ last = await reader.skill(wanted.path, cursor);
1292
1361
  if (last.read?.status !== "ready") {
1293
1362
  break;
1294
1363
  }
@@ -1307,8 +1376,599 @@ const skill: Command = async (args, io) => {
1307
1376
  formatSkillLoad(loaded, whole),
1308
1377
  );
1309
1378
  return EXIT.ok;
1379
+ }
1380
+
1381
+ const skill: Command = async (args, io) => {
1382
+ const { values, positionals } = parse(args, SKILL_OPTIONS);
1383
+ const session = await open(io, values);
1384
+ const project = await session.project();
1385
+ return readSkill(io, session, project, values, positionals, "console skill");
1386
+ };
1387
+
1388
+ // ---- The plugins (docs/specs/plugins.md, "The command") ----
1389
+ // `console plugins` and `console plugin <key> ...` are the two entries: the command sends the
1390
+ // words as typed and renders the console's generic shapes, and knows nothing of any plugin.
1391
+
1392
+ const plugins: Command = async (args, io) => {
1393
+ const { values } = parse(args, {}, false);
1394
+ const session = await open(io, values);
1395
+ const [listed, me] = await Promise.all([session.client.plugins(), session.client.me()]);
1396
+ answer(io, session, listed, () => formatPlugins(listed, me.language));
1397
+ return EXIT.ok;
1398
+ };
1399
+
1400
+ /** The flags of the command's own on `console plugin ...`, wherever they stand among the words. */
1401
+ const PLUGIN_GLOBAL_FLAGS: Readonly<Record<string, "string" | "boolean">> = {
1402
+ json: "boolean",
1403
+ url: "string",
1404
+ account: "string",
1405
+ project: "string",
1406
+ };
1407
+
1408
+ /** The flags of the command's own on a plugin's command: the file it uploads first, the run it is for. */
1409
+ const PLUGIN_COMMAND_FLAGS: Readonly<Record<string, "string" | "boolean">> = {
1410
+ file: "string",
1411
+ run: "string",
1412
+ };
1413
+
1414
+ /**
1415
+ * The words with the flags named in `own` taken out, wherever they stand: the rest is the
1416
+ * plugin's, and goes to the console as typed. `--` ends the flags, and stays among the words.
1417
+ */
1418
+ function splitWords(
1419
+ args: readonly string[],
1420
+ own: Readonly<Record<string, "string" | "boolean">>,
1421
+ ): { readonly values: Record<string, string | boolean>; readonly words: string[] } {
1422
+ const values: Record<string, string | boolean> = {};
1423
+ const words: string[] = [];
1424
+ let ended = false;
1425
+ for (let index = 0; index < args.length; index += 1) {
1426
+ const word = args[index] ?? "";
1427
+ if (ended || !word.startsWith("--") || word.length === 2) {
1428
+ ended = ended || word === "--";
1429
+ words.push(word);
1430
+ continue;
1431
+ }
1432
+ const equals = word.indexOf("=");
1433
+ const name = equals < 0 ? word.slice(2) : word.slice(2, equals);
1434
+ const type = Object.hasOwn(own, name) ? own[name] : undefined;
1435
+ if (type === undefined) {
1436
+ words.push(word);
1437
+ continue;
1438
+ }
1439
+ if (type === "boolean") {
1440
+ if (equals >= 0) {
1441
+ throw misuse(`--${name} takes no value`);
1442
+ }
1443
+ values[name] = true;
1444
+ continue;
1445
+ }
1446
+ if (equals >= 0) {
1447
+ values[name] = word.slice(equals + 1);
1448
+ continue;
1449
+ }
1450
+ const next = args[index + 1];
1451
+ if (next === undefined) {
1452
+ throw misuse(`--${name} needs a value`);
1453
+ }
1454
+ values[name] = next;
1455
+ index += 1;
1456
+ }
1457
+ return { values, words };
1458
+ }
1459
+
1460
+ const PLUGIN_USAGE =
1461
+ "console plugin <key> [help [<command>] | <command> [args] | records <collection> | skills | skill <path> | enable | disable | settings | secret <name> | grant <role> | revoke <id>]. console plugins lists the plugins.";
1462
+
1463
+ const plugin: Command = async (args, io) => {
1464
+ const { values, words } = splitWords(args, PLUGIN_GLOBAL_FLAGS);
1465
+ const [key, verb, ...rest] = words;
1466
+ if (key === undefined || key.startsWith("-")) {
1467
+ throw misuse(`Say which plugin: ${PLUGIN_USAGE}`);
1468
+ }
1469
+ const session = await open(io, values);
1470
+ const client = session.client.plugin(key);
1471
+ switch (verb) {
1472
+ case undefined: {
1473
+ const [detail, me] = await Promise.all([client.get(), session.client.me()]);
1474
+ answer(io, session, detail, () => formatPlugin(detail, me.language));
1475
+ return EXIT.ok;
1476
+ }
1477
+ case "help": {
1478
+ if (rest.length > 1) {
1479
+ throw misuse(`Say one command: console plugin ${key} help [<command>]`);
1480
+ }
1481
+ const name = rest[0];
1482
+ const detail = await client.get();
1483
+ const operation =
1484
+ name === undefined
1485
+ ? undefined
1486
+ : detail.operations.find((candidate) => candidate.name === name);
1487
+ if (name !== undefined && operation === undefined) {
1488
+ throw misuse(
1489
+ `Not a command or a query of ${key} you may run: ${name}. console plugin ${key} lists them.`,
1490
+ );
1491
+ }
1492
+ answer(io, session, operation ?? detail.operations, () => formatPluginHelp(detail, name));
1493
+ return EXIT.ok;
1494
+ }
1495
+ case "records":
1496
+ return pluginRecords(io, session, client, rest, text(values, "project"));
1497
+ case "skills": {
1498
+ const parsed = parse(rest, SKILLS_OPTIONS);
1499
+ return readSkills(io, session, client, parsed.values, parsed.positionals, {
1500
+ command: `console plugin ${key} skills`,
1501
+ });
1502
+ }
1503
+ case "skill": {
1504
+ const parsed = parse(rest, SKILL_OPTIONS);
1505
+ return readSkill(
1506
+ io,
1507
+ session,
1508
+ client,
1509
+ parsed.values,
1510
+ parsed.positionals,
1511
+ `console plugin ${key} skill`,
1512
+ );
1513
+ }
1514
+ case "enable":
1515
+ return pluginEnable(io, session, client, rest);
1516
+ case "disable": {
1517
+ parse(rest, {}, false);
1518
+ const detail = await client.disable();
1519
+ answer(
1520
+ io,
1521
+ session,
1522
+ detail,
1523
+ () =>
1524
+ `Disabled ${detail.key}: its commands are refused until it is enabled again; what the console kept of it stays.`,
1525
+ );
1526
+ return EXIT.ok;
1527
+ }
1528
+ case "settings":
1529
+ return pluginSettings(io, session, client, rest);
1530
+ case "secret":
1531
+ return pluginSecret(io, session, client, rest);
1532
+ case "grant":
1533
+ return pluginGrant(io, session, client, rest, text(values, "project"));
1534
+ case "revoke": {
1535
+ const { positionals } = parse(rest, {});
1536
+ const id = theOne(positionals, `Say which grant: console plugin ${key} revoke <grant id>`);
1537
+ const revoked = await client.revoke(id);
1538
+ answer(io, session, revoked, () => `Revoked: ${formatPluginGrantLine(revoked)}`);
1539
+ return EXIT.ok;
1540
+ }
1541
+ default:
1542
+ return pluginInvoke(io, session, client, verb, rest);
1543
+ }
1310
1544
  };
1311
1545
 
1546
+ /** A query's answer that is a file, as the console carries one: its name, its type, its bytes as base64. */
1547
+ function queryFileOf(
1548
+ result: RestPluginInvocation,
1549
+ ): { readonly name: string; readonly type: string; readonly bytes: Uint8Array } | undefined {
1550
+ if (result.kind !== "query" || typeof result.data !== "object" || result.data === null) {
1551
+ return undefined;
1552
+ }
1553
+ const file = (result.data as { file?: unknown }).file;
1554
+ if (
1555
+ typeof file !== "object" ||
1556
+ file === null ||
1557
+ typeof (file as { name?: unknown }).name !== "string" ||
1558
+ typeof (file as { type?: unknown }).type !== "string" ||
1559
+ typeof (file as { base64?: unknown }).base64 !== "string"
1560
+ ) {
1561
+ return undefined;
1562
+ }
1563
+ const named = file as { name: string; type: string; base64: string };
1564
+ return {
1565
+ name: basename(named.name) || "answer",
1566
+ type: named.type,
1567
+ bytes: Uint8Array.from(Buffer.from(named.base64, "base64")),
1568
+ };
1569
+ }
1570
+
1571
+ /**
1572
+ * A command or a query of the plugin, by the words as typed: a file named with --file, or read
1573
+ * from standard input for -, is uploaded first and goes as a handle; the console parses the rest.
1574
+ */
1575
+ async function pluginInvoke(
1576
+ io: CliIo,
1577
+ session: Session,
1578
+ client: PluginClient,
1579
+ name: string,
1580
+ rest: readonly string[],
1581
+ ): Promise<number> {
1582
+ const { values, words } = splitWords(rest, PLUGIN_COMMAND_FLAGS);
1583
+ const stdin = words.includes("-");
1584
+ const filePath = text(values, "file");
1585
+ if (filePath !== undefined && stdin) {
1586
+ throw misuse("Say one file: --file <path>, or - for standard input.");
1587
+ }
1588
+ const files: string[] = [];
1589
+ if (filePath !== undefined) {
1590
+ let bytes: Uint8Array;
1591
+ try {
1592
+ bytes = await io.readBytes(filePath);
1593
+ } catch {
1594
+ throw misuse(`The file could not be read: ${filePath}`);
1595
+ }
1596
+ const fileName = basename(filePath);
1597
+ const uploaded = await client.upload({
1598
+ name: fileName,
1599
+ bytes,
1600
+ contentType: CONTENT_TYPES[extname(fileName).toLowerCase()] ?? "application/octet-stream",
1601
+ });
1602
+ files.push(uploaded.handle);
1603
+ } else if (stdin) {
1604
+ const uploaded = await client.upload({
1605
+ name: "stdin.txt",
1606
+ bytes: new TextEncoder().encode(await io.readStdin()),
1607
+ contentType: "text/plain",
1608
+ });
1609
+ files.push(uploaded.handle);
1610
+ }
1611
+ const project = await session.projectKey();
1612
+ const run = text(values, "run");
1613
+ const result = await client.invoke({
1614
+ argv: [name, ...words.filter((word) => word !== "-")],
1615
+ ...(files.length === 0 ? {} : { files }),
1616
+ ...(project === undefined ? {} : { project }),
1617
+ ...(run === undefined ? {} : { run }),
1618
+ });
1619
+ // A query that answers a file: saved under its name in the working directory, as console file saves one.
1620
+ const file = queryFileOf(result);
1621
+ let saved: string | undefined;
1622
+ if (file !== undefined && !session.json) {
1623
+ try {
1624
+ saved = await io.writeBytes(file.name, file.bytes, file.name);
1625
+ } catch {
1626
+ throw failed(`The file could not be written at ${file.name}.`);
1627
+ }
1628
+ }
1629
+ answer(io, session, result, () =>
1630
+ file !== undefined && saved !== undefined
1631
+ ? `Saved ${file.name} (${file.bytes.byteLength} bytes, ${file.type}) at ${saved}`
1632
+ : formatInvocation(result),
1633
+ );
1634
+ return result.waiting === null ? EXIT.ok : EXIT.waiting;
1635
+ }
1636
+
1637
+ /** A condition's value as typed: a number, true, false and null read as such; JSON where it begins as JSON; text otherwise. */
1638
+ function whereValueOf(word: string): unknown {
1639
+ if (word === "true") {
1640
+ return true;
1641
+ }
1642
+ if (word === "false") {
1643
+ return false;
1644
+ }
1645
+ if (word === "null") {
1646
+ return null;
1647
+ }
1648
+ if (/^-?\d+(?:\.\d+)?$/.test(word)) {
1649
+ return Number(word);
1650
+ }
1651
+ if (word.startsWith("{") || word.startsWith("[")) {
1652
+ try {
1653
+ return JSON.parse(word);
1654
+ } catch {
1655
+ return word;
1656
+ }
1657
+ }
1658
+ return word;
1659
+ }
1660
+
1661
+ /** The records of a collection one may read, a page of them; or one record, or its versions. */
1662
+ async function pluginRecords(
1663
+ io: CliIo,
1664
+ session: Session,
1665
+ client: PluginClient,
1666
+ rest: readonly string[],
1667
+ project: string | undefined,
1668
+ ): Promise<number> {
1669
+ const { values, positionals } = parse(rest, {
1670
+ where: { type: "string", multiple: true },
1671
+ search: { type: "string" },
1672
+ order: { type: "string" },
1673
+ limit: { type: "string" },
1674
+ after: { type: "string" },
1675
+ archived: { type: "boolean" },
1676
+ versions: { type: "boolean" },
1677
+ });
1678
+ const [collection, id, ...more] = positionals;
1679
+ if (collection === undefined || more.length > 0) {
1680
+ throw misuse(
1681
+ `Say which collection: console plugin ${client.key} records <collection> [<id>] [--where <field>=<value>]... [--search <words>] [--order <field>[:desc]] [--limit <n>] [--after <cursor>] [--archived] [--versions]`,
1682
+ );
1683
+ }
1684
+ if (id !== undefined) {
1685
+ if (on(values, "versions")) {
1686
+ const versions = await client.recordVersions(collection, id);
1687
+ answer(io, session, versions, () => formatPluginRecordVersions(versions));
1688
+ return EXIT.ok;
1689
+ }
1690
+ const record = await client.record(collection, id);
1691
+ answer(io, session, record, () => formatPluginRecord(record));
1692
+ return EXIT.ok;
1693
+ }
1694
+ if (on(values, "versions")) {
1695
+ throw misuse(
1696
+ "--versions goes with a record's id: console plugin <key> records <collection> <id> --versions",
1697
+ );
1698
+ }
1699
+ const where: Record<string, unknown> = {};
1700
+ for (const pair of texts(values, "where")) {
1701
+ const equals = pair.indexOf("=");
1702
+ if (equals <= 0) {
1703
+ throw misuse(`Not a condition, as <field>=<value>: ${pair}`);
1704
+ }
1705
+ where[pair.slice(0, equals)] = whereValueOf(pair.slice(equals + 1));
1706
+ }
1707
+ const order = text(values, "order");
1708
+ const page = await client.records(collection, {
1709
+ ...(Object.keys(where).length === 0 ? {} : { where }),
1710
+ q: text(values, "search"),
1711
+ order:
1712
+ order === undefined ? undefined : order.endsWith(":desc") ? `-${order.slice(0, -5)}` : order,
1713
+ limit: countOf(text(values, "limit"), "limit", { least: 1, most: PLUGIN_LIST_LIMIT }),
1714
+ after: text(values, "after"),
1715
+ project,
1716
+ archived: on(values, "archived") ? true : undefined,
1717
+ });
1718
+ answer(io, session, page, () => formatPluginRecords(page));
1719
+ return EXIT.ok;
1720
+ }
1721
+
1722
+ /** The values `--set <key>=<value>` give, each read as its setting's type; an empty value clears one. */
1723
+ function settingValuesOf(
1724
+ pairs: readonly string[],
1725
+ detail: RestPluginDetail,
1726
+ ): Record<string, unknown> {
1727
+ const values: Record<string, unknown> = {};
1728
+ const read = (type: string, word: string, key: string): unknown => {
1729
+ switch (type) {
1730
+ case "number": {
1731
+ const value = Number(word);
1732
+ if (!Number.isFinite(value) || word.trim().length === 0) {
1733
+ throw misuse(`Not a number for the setting ${key}: ${word}`);
1734
+ }
1735
+ return value;
1736
+ }
1737
+ case "boolean":
1738
+ if (word !== "true" && word !== "false") {
1739
+ throw misuse(`The setting ${key} is true or false: ${word}`);
1740
+ }
1741
+ return word === "true";
1742
+ default:
1743
+ return word;
1744
+ }
1745
+ };
1746
+ for (const pair of pairs) {
1747
+ const equals = pair.indexOf("=");
1748
+ if (equals <= 0) {
1749
+ throw misuse(`Not a setting, as <key>=<value>: ${pair}`);
1750
+ }
1751
+ const key = pair.slice(0, equals);
1752
+ const word = pair.slice(equals + 1);
1753
+ const setting = detail.settings.find((candidate) => candidate.key === key);
1754
+ if (setting === undefined) {
1755
+ throw misuse(
1756
+ `Not a setting of ${detail.key}: ${key}. Its settings: ${detail.settings.map((candidate) => candidate.key).join(", ") || "none"}`,
1757
+ );
1758
+ }
1759
+ if (setting.type === "secret") {
1760
+ throw misuse(
1761
+ `${key} is a secret: console plugin ${detail.key} secret ${key} reads it from standard input.`,
1762
+ );
1763
+ }
1764
+ if (word.length === 0) {
1765
+ values[key] = null;
1766
+ } else if (setting.type === "list") {
1767
+ values[key] = word
1768
+ .split(",")
1769
+ .map((item) => item.trim())
1770
+ .filter((item) => item.length > 0)
1771
+ .map((item) => read(setting.of ?? "text", item, key));
1772
+ } else {
1773
+ values[key] = read(setting.type, word, key);
1774
+ }
1775
+ }
1776
+ return values;
1777
+ }
1778
+
1779
+ /** The capabilities a plugin asks, each with what it opens and what it risks, for the administrator to read before consenting. */
1780
+ function capabilityLines(capabilities: readonly string[]): string[] {
1781
+ return capabilities.map((capability) => {
1782
+ const words = capabilityWords(capability);
1783
+ return words === undefined
1784
+ ? ` ${capability}: a capability this command does not know`
1785
+ : ` ${capability}: opens ${words.opens}; a malicious plugin reaches ${words.reach}`;
1786
+ });
1787
+ }
1788
+
1789
+ /** Enables a plugin, with consent to every capability it asks, named again; an administrator's. */
1790
+ async function pluginEnable(
1791
+ io: CliIo,
1792
+ session: Session,
1793
+ client: PluginClient,
1794
+ rest: readonly string[],
1795
+ ): Promise<number> {
1796
+ const { values, positionals } = parse(rest, {
1797
+ consent: { type: "string", multiple: true },
1798
+ board: { type: "string" },
1799
+ projects: { type: "string", multiple: true },
1800
+ set: { type: "string", multiple: true },
1801
+ });
1802
+ if (positionals.length > 0) {
1803
+ throw misuse(
1804
+ `Nothing follows enable but its flags: console plugin ${client.key} enable [--consent <capability>,...] [--board new|<key>] [--projects all|<key>,...] [--set <key>=<value>]...`,
1805
+ );
1806
+ }
1807
+ const [detail, me] = await Promise.all([client.get(), session.client.me()]);
1808
+ const asked = detail.capabilities;
1809
+ const consent = texts(values, "consent")
1810
+ .flatMap((value) => value.split(","))
1811
+ .map((capability) => capability.trim())
1812
+ .filter((capability) => capability.length > 0);
1813
+ if (asked.length > 0 && !session.json) {
1814
+ io.stdout(
1815
+ `${detail.key} asks ${asked.length === 1 ? "one capability" : `${asked.length} capabilities`}:\n${capabilityLines(asked).join("\n")}\n`,
1816
+ );
1817
+ }
1818
+ const missing = asked.filter((capability) => !consent.includes(capability));
1819
+ if (missing.length > 0) {
1820
+ throw misuse(
1821
+ `Enabling ${detail.key} needs consent to every capability it asks, named again: --consent ${asked.join(",")}. Not named: ${missing.join(", ")}.`,
1822
+ );
1823
+ }
1824
+ const boardFlag = text(values, "board");
1825
+ let board: RestPluginEnableInput["board"] = null;
1826
+ if (boardFlag === "new") {
1827
+ if (detail.boardDefaults === null) {
1828
+ throw misuse(
1829
+ `${detail.key} names no defaults for a board project: choose one with --board <key>.`,
1830
+ );
1831
+ }
1832
+ board = {
1833
+ create: {
1834
+ key: detail.boardDefaults.key,
1835
+ name: localized(detail.boardDefaults.name, me.language),
1836
+ description: localized(detail.boardDefaults.description, me.language),
1837
+ },
1838
+ };
1839
+ } else if (boardFlag !== undefined) {
1840
+ board = { project: boardFlag };
1841
+ }
1842
+ const named = texts(values, "projects")
1843
+ .flatMap((value) => value.split(","))
1844
+ .map((key) => key.trim())
1845
+ .filter((key) => key.length > 0);
1846
+ const settings = settingValuesOf(texts(values, "set"), detail);
1847
+ const enabled = await client.enable({
1848
+ consent,
1849
+ board,
1850
+ projects: named.length === 0 || named.includes("all") ? "all" : named,
1851
+ ...(Object.keys(settings).length === 0 ? {} : { settings }),
1852
+ });
1853
+ answer(io, session, enabled, () =>
1854
+ [
1855
+ `Enabled ${enabled.key}${enabled.board === null ? "" : `, with the board project ${enabled.board.key}`}; on ${enabled.projects === "all" || enabled.projects === null ? "every project" : enabled.projects.join(", ") || "no project"}.`,
1856
+ ...(enabled.settings.length === 0
1857
+ ? []
1858
+ : [
1859
+ "Settings:",
1860
+ ...enabled.settings.map((setting) => formatPluginSettingLine(setting, me.language)),
1861
+ ]),
1862
+ ].join("\n"),
1863
+ );
1864
+ return EXIT.ok;
1865
+ }
1866
+
1867
+ /** The settings as they stand, or changed as `--set` says; an administrator's. */
1868
+ async function pluginSettings(
1869
+ io: CliIo,
1870
+ session: Session,
1871
+ client: PluginClient,
1872
+ rest: readonly string[],
1873
+ ): Promise<number> {
1874
+ const { values, positionals } = parse(rest, { set: { type: "string", multiple: true } });
1875
+ if (positionals.length > 0) {
1876
+ throw misuse(
1877
+ `Nothing follows settings but --set: console plugin ${client.key} settings [--set <key>=<value>]...`,
1878
+ );
1879
+ }
1880
+ const [detail, me] = await Promise.all([client.get(), session.client.me()]);
1881
+ const sets = texts(values, "set");
1882
+ if (sets.length === 0) {
1883
+ answer(io, session, detail.settings, () =>
1884
+ detail.settings.length === 0
1885
+ ? `${detail.key} has no settings.`
1886
+ : [
1887
+ `Settings of ${detail.key}:`,
1888
+ ...detail.settings.map((setting) => formatPluginSettingLine(setting, me.language)),
1889
+ ].join("\n"),
1890
+ );
1891
+ return EXIT.ok;
1892
+ }
1893
+ const changed = await client.updateSettings({ values: settingValuesOf(sets, detail) });
1894
+ answer(io, session, changed.settings, () =>
1895
+ [
1896
+ `Changed the settings of ${changed.key}:`,
1897
+ ...changed.settings.map((setting) => formatPluginSettingLine(setting, me.language)),
1898
+ ].join("\n"),
1899
+ );
1900
+ return EXIT.ok;
1901
+ }
1902
+
1903
+ /** Seals a secret of the plugin, read from standard input and shown never; or takes it away. */
1904
+ async function pluginSecret(
1905
+ io: CliIo,
1906
+ session: Session,
1907
+ client: PluginClient,
1908
+ rest: readonly string[],
1909
+ ): Promise<number> {
1910
+ const { values, positionals } = parse(rest, { remove: { type: "boolean" } });
1911
+ const name = theOne(
1912
+ positionals,
1913
+ `Say which secret: console plugin ${client.key} secret <name> [--remove]; the value is read from standard input.`,
1914
+ );
1915
+ if (on(values, "remove")) {
1916
+ await client.removeSecret(name);
1917
+ answer(io, session, { name, set: false }, () => `Removed the secret ${name} of ${client.key}.`);
1918
+ return EXIT.ok;
1919
+ }
1920
+ const value = (await io.readStdin()).replace(/\r?\n$/, "");
1921
+ if (value.length === 0) {
1922
+ throw misuse(
1923
+ `Pipe the value in: console plugin ${client.key} secret ${name} < file. It is sealed by the console and shown never.`,
1924
+ );
1925
+ }
1926
+ await client.setSecret(name, value);
1927
+ answer(
1928
+ io,
1929
+ session,
1930
+ { name, set: true },
1931
+ () => `Set the secret ${name} of ${client.key}: sealed, and shown by nothing from now on.`,
1932
+ );
1933
+ return EXIT.ok;
1934
+ }
1935
+
1936
+ /** Grants a role of the plugin to a person, to the members of a project, or to everyone; an administrator's. */
1937
+ async function pluginGrant(
1938
+ io: CliIo,
1939
+ session: Session,
1940
+ client: PluginClient,
1941
+ rest: readonly string[],
1942
+ projectKey: string | undefined,
1943
+ ): Promise<number> {
1944
+ const { values, positionals } = parse(rest, {
1945
+ person: { type: "string" },
1946
+ everyone: { type: "boolean" },
1947
+ });
1948
+ const usage = `console plugin ${client.key} grant <role> --person <login> | --project <key> | --everyone`;
1949
+ const role = theOne(positionals, `Say which role: ${usage}`);
1950
+ const login = text(values, "person");
1951
+ const everyone = on(values, "everyone");
1952
+ if ([login !== undefined, projectKey !== undefined, everyone].filter(Boolean).length !== 1) {
1953
+ throw misuse(`Say whom, one of the three: ${usage}`);
1954
+ }
1955
+ let input: RestPluginGrantInput;
1956
+ if (login !== undefined) {
1957
+ const person = await session.client.findPerson(login);
1958
+ if (person === undefined) {
1959
+ throw failed(`No person has the login ${login} among those you may see.`);
1960
+ }
1961
+ input = { role, person: person.id };
1962
+ } else if (projectKey !== undefined) {
1963
+ input = { role, project: projectKey };
1964
+ } else {
1965
+ input = { role, everyone: true };
1966
+ }
1967
+ const granted = await client.grant(input);
1968
+ answer(io, session, granted, () => `Granted: ${formatPluginGrantLine(granted)}`);
1969
+ return EXIT.ok;
1970
+ }
1971
+
1312
1972
  /** A version number given as a flag, or nothing; anything else is not understood. */
1313
1973
  function versionOf(given: string | undefined): number | undefined {
1314
1974
  if (given === undefined) {
@@ -1400,9 +2060,10 @@ const rules: Command = async (args, io) => {
1400
2060
  ? {
1401
2061
  workspace: forPerson(found.workspace, me.language),
1402
2062
  project: forPerson(found.project, me.language),
2063
+ ...(found.plugins === undefined ? {} : { plugins: found.plugins }),
1403
2064
  }
1404
2065
  : forPerson(found, me.language);
1405
- answer(io, session, read, () => formatRules(read));
2066
+ answer(io, session, read, () => formatRules(read, me.language));
1406
2067
  return EXIT.ok;
1407
2068
  };
1408
2069
 
@@ -1730,6 +2391,7 @@ const take: Command = async (args, io) => {
1730
2391
  const rules = {
1731
2392
  workspace: forPerson(ruling.workspace, me.language),
1732
2393
  project: forPerson(ruling.project, me.language),
2394
+ ...(ruling.plugins === undefined ? {} : { plugins: ruling.plugins }),
1733
2395
  };
1734
2396
  answer(io, session, { run, task: taken, comments: comments.items, rules }, () =>
1735
2397
  [
@@ -1740,7 +2402,7 @@ const take: Command = async (args, io) => {
1740
2402
  "",
1741
2403
  formatTask(taken, undefined, undefined, comments.items),
1742
2404
  "",
1743
- formatRules(rules),
2405
+ formatRules(rules, me.language),
1744
2406
  "",
1745
2407
  'Say how it goes: console report "<what you found or did>". Hand in what you make: console hand-in <https url | file path>.',
1746
2408
  '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>".',
@@ -2980,6 +3642,8 @@ const COMMANDS: Readonly<Record<string, Command>> = {
2980
3642
  skills,
2981
3643
  skill,
2982
3644
  rules,
3645
+ plugins,
3646
+ plugin,
2983
3647
  people,
2984
3648
  person,
2985
3649
  workspace,