@skillcdn/console 0.4.1 → 0.4.3

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 (299) hide show
  1. package/README.md +19 -2
  2. package/SKILLCDN.md +7 -5
  3. package/dist/api.d.ts +5 -4
  4. package/dist/api.d.ts.map +1 -1
  5. package/dist/api.js +5 -4
  6. package/dist/api.js.map +1 -1
  7. package/dist/cli/cli.d.ts.map +1 -1
  8. package/dist/cli/cli.js +569 -48
  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 +283 -7
  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 +44 -7
  16. package/dist/cli/help.js.map +1 -1
  17. package/dist/cli/plugin-check.d.ts +26 -0
  18. package/dist/cli/plugin-check.d.ts.map +1 -0
  19. package/dist/cli/plugin-check.js +396 -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 +189 -0
  24. package/dist/cli/plugin-cli.js.map +1 -0
  25. package/dist/cli/plugin-init.d.ts +37 -0
  26. package/dist/cli/plugin-init.d.ts.map +1 -0
  27. package/dist/cli/plugin-init.js +206 -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 +100 -3
  34. package/dist/client.d.ts.map +1 -1
  35. package/dist/client.js +79 -7
  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/comments.d.ts.map +1 -1
  44. package/dist/components/comments.js +1 -1
  45. package/dist/components/comments.js.map +1 -1
  46. package/dist/components/decision-form.d.ts +2 -1
  47. package/dist/components/decision-form.d.ts.map +1 -1
  48. package/dist/components/decision-form.js +36 -4
  49. package/dist/components/decision-form.js.map +1 -1
  50. package/dist/components/decision-list.d.ts +4 -0
  51. package/dist/components/decision-list.d.ts.map +1 -1
  52. package/dist/components/decision-list.js +29 -3
  53. package/dist/components/decision-list.js.map +1 -1
  54. package/dist/components/event-feed.d.ts +1 -1
  55. package/dist/components/event-feed.d.ts.map +1 -1
  56. package/dist/components/event-feed.js +33 -1
  57. package/dist/components/event-feed.js.map +1 -1
  58. package/dist/components/my-decisions.d.ts +2 -0
  59. package/dist/components/my-decisions.d.ts.map +1 -1
  60. package/dist/components/my-decisions.js +2 -2
  61. package/dist/components/my-decisions.js.map +1 -1
  62. package/dist/components/plugin-frame.d.ts +52 -0
  63. package/dist/components/plugin-frame.d.ts.map +1 -0
  64. package/dist/components/plugin-frame.js +314 -0
  65. package/dist/components/plugin-frame.js.map +1 -0
  66. package/dist/components/plugin-settings.d.ts +38 -0
  67. package/dist/components/plugin-settings.d.ts.map +1 -0
  68. package/dist/components/plugin-settings.js +348 -0
  69. package/dist/components/plugin-settings.js.map +1 -0
  70. package/dist/components/shell.d.ts +2 -0
  71. package/dist/components/shell.d.ts.map +1 -1
  72. package/dist/components/shell.js +26 -1
  73. package/dist/components/shell.js.map +1 -1
  74. package/dist/components/task-view.d.ts +2 -1
  75. package/dist/components/task-view.d.ts.map +1 -1
  76. package/dist/components/task-view.js.map +1 -1
  77. package/dist/components/workspace.d.ts +7 -1
  78. package/dist/components/workspace.d.ts.map +1 -1
  79. package/dist/components/workspace.js +1 -1
  80. package/dist/components/workspace.js.map +1 -1
  81. package/dist/console.css +330 -1
  82. package/dist/console.d.ts.map +1 -1
  83. package/dist/console.js +152 -41
  84. package/dist/console.js.map +1 -1
  85. package/dist/data.d.ts +9 -2
  86. package/dist/data.d.ts.map +1 -1
  87. package/dist/data.js +45 -9
  88. package/dist/data.js.map +1 -1
  89. package/dist/i18n/en.d.ts +155 -0
  90. package/dist/i18n/en.d.ts.map +1 -1
  91. package/dist/i18n/en.js +166 -0
  92. package/dist/i18n/en.js.map +1 -1
  93. package/dist/i18n/ko.d.ts.map +1 -1
  94. package/dist/i18n/ko.js +150 -0
  95. package/dist/i18n/ko.js.map +1 -1
  96. package/dist/index.d.ts +3 -1
  97. package/dist/index.d.ts.map +1 -1
  98. package/dist/index.js +3 -1
  99. package/dist/index.js.map +1 -1
  100. package/dist/limits.d.ts +2 -0
  101. package/dist/limits.d.ts.map +1 -1
  102. package/dist/limits.js +2 -0
  103. package/dist/limits.js.map +1 -1
  104. package/dist/plugin/args.d.ts +148 -0
  105. package/dist/plugin/args.d.ts.map +1 -0
  106. package/dist/plugin/args.js +369 -0
  107. package/dist/plugin/args.js.map +1 -0
  108. package/dist/plugin/bridge.d.ts +146 -0
  109. package/dist/plugin/bridge.d.ts.map +1 -0
  110. package/dist/plugin/bridge.js +125 -0
  111. package/dist/plugin/bridge.js.map +1 -0
  112. package/dist/plugin/capabilities.d.ts +20 -0
  113. package/dist/plugin/capabilities.d.ts.map +1 -0
  114. package/dist/plugin/capabilities.js +133 -0
  115. package/dist/plugin/capabilities.js.map +1 -0
  116. package/dist/plugin/context.d.ts +380 -0
  117. package/dist/plugin/context.d.ts.map +1 -0
  118. package/dist/plugin/context.js +2 -0
  119. package/dist/plugin/context.js.map +1 -0
  120. package/dist/plugin/define.d.ts +208 -0
  121. package/dist/plugin/define.d.ts.map +1 -0
  122. package/dist/plugin/define.js +482 -0
  123. package/dist/plugin/define.js.map +1 -0
  124. package/dist/plugin/definition-error.d.ts +11 -0
  125. package/dist/plugin/definition-error.d.ts.map +1 -0
  126. package/dist/plugin/definition-error.js +17 -0
  127. package/dist/plugin/definition-error.js.map +1 -0
  128. package/dist/plugin/limits.d.ts +67 -0
  129. package/dist/plugin/limits.d.ts.map +1 -0
  130. package/dist/plugin/limits.js +70 -0
  131. package/dist/plugin/limits.js.map +1 -0
  132. package/dist/plugin/load-worker.d.ts +7 -0
  133. package/dist/plugin/load-worker.d.ts.map +1 -0
  134. package/dist/plugin/load-worker.js +41 -0
  135. package/dist/plugin/load-worker.js.map +1 -0
  136. package/dist/plugin/load.d.ts +18 -0
  137. package/dist/plugin/load.d.ts.map +1 -0
  138. package/dist/plugin/load.js +62 -0
  139. package/dist/plugin/load.js.map +1 -0
  140. package/dist/plugin/manifest.d.ts +237 -0
  141. package/dist/plugin/manifest.d.ts.map +1 -0
  142. package/dist/plugin/manifest.js +411 -0
  143. package/dist/plugin/manifest.js.map +1 -0
  144. package/dist/plugin/refusals.d.ts +49 -0
  145. package/dist/plugin/refusals.d.ts.map +1 -0
  146. package/dist/plugin/refusals.js +79 -0
  147. package/dist/plugin/refusals.js.map +1 -0
  148. package/dist/plugin/rest-schemas.d.ts +556 -0
  149. package/dist/plugin/rest-schemas.d.ts.map +1 -0
  150. package/dist/plugin/rest-schemas.js +262 -0
  151. package/dist/plugin/rest-schemas.js.map +1 -0
  152. package/dist/plugin/sandbox.d.ts +23 -0
  153. package/dist/plugin/sandbox.d.ts.map +1 -0
  154. package/dist/plugin/sandbox.js +99 -0
  155. package/dist/plugin/sandbox.js.map +1 -0
  156. package/dist/plugin/testing.d.ts +45 -0
  157. package/dist/plugin/testing.d.ts.map +1 -0
  158. package/dist/plugin/testing.js +420 -0
  159. package/dist/plugin/testing.js.map +1 -0
  160. package/dist/plugin/web-react.d.ts +11 -0
  161. package/dist/plugin/web-react.d.ts.map +1 -0
  162. package/dist/plugin/web-react.js +34 -0
  163. package/dist/plugin/web-react.js.map +1 -0
  164. package/dist/plugin/web.d.ts +95 -0
  165. package/dist/plugin/web.d.ts.map +1 -0
  166. package/dist/plugin/web.js +245 -0
  167. package/dist/plugin/web.js.map +1 -0
  168. package/dist/plugin-nav.d.ts +29 -0
  169. package/dist/plugin-nav.d.ts.map +1 -0
  170. package/dist/plugin-nav.js +92 -0
  171. package/dist/plugin-nav.js.map +1 -0
  172. package/dist/plugin-testing.d.ts +2 -0
  173. package/dist/plugin-testing.d.ts.map +1 -0
  174. package/dist/plugin-testing.js +4 -0
  175. package/dist/plugin-testing.js.map +1 -0
  176. package/dist/plugin-web-react.d.ts +3 -0
  177. package/dist/plugin-web-react.d.ts.map +1 -0
  178. package/dist/plugin-web-react.js +3 -0
  179. package/dist/plugin-web-react.js.map +1 -0
  180. package/dist/plugin-web.d.ts +4 -0
  181. package/dist/plugin-web.d.ts.map +1 -0
  182. package/dist/plugin-web.js +5 -0
  183. package/dist/plugin-web.js.map +1 -0
  184. package/dist/plugin.d.ts +11 -0
  185. package/dist/plugin.d.ts.map +1 -0
  186. package/dist/plugin.js +15 -0
  187. package/dist/plugin.js.map +1 -0
  188. package/dist/router.d.ts +28 -0
  189. package/dist/router.d.ts.map +1 -1
  190. package/dist/router.js +47 -0
  191. package/dist/router.js.map +1 -1
  192. package/dist/routes.d.ts +4 -0
  193. package/dist/routes.d.ts.map +1 -1
  194. package/dist/routes.js +6 -0
  195. package/dist/routes.js.map +1 -1
  196. package/dist/schemas.d.ts +194 -9
  197. package/dist/schemas.d.ts.map +1 -1
  198. package/dist/schemas.js +98 -17
  199. package/dist/schemas.js.map +1 -1
  200. package/dist/tokens.d.ts +2 -0
  201. package/dist/tokens.d.ts.map +1 -0
  202. package/dist/tokens.js +101 -0
  203. package/dist/tokens.js.map +1 -0
  204. package/dist/vocabulary.d.ts +11 -1
  205. package/dist/vocabulary.d.ts.map +1 -1
  206. package/dist/vocabulary.js +24 -0
  207. package/dist/vocabulary.js.map +1 -1
  208. package/dist/web.d.ts.map +1 -1
  209. package/dist/web.js +2 -0
  210. package/dist/web.js.map +1 -1
  211. package/docs/specs/cli.md +12 -5
  212. package/docs/specs/plugins.md +488 -0
  213. package/docs/specs/rest.md +11 -9
  214. package/package.json +26 -8
  215. package/skills/building-a-console/SKILL.md +25 -26
  216. package/skills/building-a-console/references/configuring.md +40 -0
  217. package/skills/building-a-console/references/the-default-console.md +1 -1
  218. package/skills/building-a-console/references/the-look-from-a-website.md +5 -5
  219. package/skills/building-a-plugin/SKILL.md +137 -0
  220. package/skills/deploying-a-console/SKILL.md +24 -26
  221. package/skills/deploying-a-console/references/access.md +13 -9
  222. package/skills/deploying-a-console/references/resources.md +25 -10
  223. package/skills/deploying-a-console/references/running-it-again.md +15 -0
  224. package/skills/deploying-a-console/references/sizing.md +2 -0
  225. package/skills/planning-the-board/SKILL.md +96 -0
  226. package/skills/planning-the-board/references/a-task.md +36 -0
  227. package/skills/planning-the-board/references/setting-up.md +44 -0
  228. package/skills/working-the-board/SKILL.md +43 -34
  229. package/skills/working-the-board/references/the-pack.md +19 -0
  230. package/src/api.ts +12 -0
  231. package/src/cli/cli.ts +737 -55
  232. package/src/cli/format.ts +368 -10
  233. package/src/cli/help.ts +50 -6
  234. package/src/cli/plugin-check.ts +497 -0
  235. package/src/cli/plugin-cli.ts +237 -0
  236. package/src/cli/plugin-init.ts +257 -0
  237. package/src/cli/plugin-main.ts +30 -0
  238. package/src/client.ts +322 -9
  239. package/src/compat.ts +2 -2
  240. package/src/components/board.tsx +62 -14
  241. package/src/components/comments.tsx +1 -0
  242. package/src/components/decision-form.tsx +92 -11
  243. package/src/components/decision-list.tsx +71 -2
  244. package/src/components/event-feed.tsx +42 -1
  245. package/src/components/my-decisions.tsx +4 -1
  246. package/src/components/plugin-frame.tsx +437 -0
  247. package/src/components/plugin-settings.tsx +1111 -0
  248. package/src/components/shell.tsx +82 -14
  249. package/src/components/task-view.tsx +2 -1
  250. package/src/components/workspace.tsx +18 -0
  251. package/src/console.tsx +304 -31
  252. package/src/data.ts +59 -11
  253. package/src/i18n/en.ts +175 -0
  254. package/src/i18n/ko.ts +155 -0
  255. package/src/index.ts +12 -0
  256. package/src/limits.ts +2 -0
  257. package/src/plugin/args.ts +526 -0
  258. package/src/plugin/bridge.ts +314 -0
  259. package/src/plugin/capabilities.ts +150 -0
  260. package/src/plugin/context.ts +421 -0
  261. package/src/plugin/define.ts +792 -0
  262. package/src/plugin/definition-error.ts +19 -0
  263. package/src/plugin/limits.ts +70 -0
  264. package/src/plugin/load-worker.ts +50 -0
  265. package/src/plugin/load.ts +82 -0
  266. package/src/plugin/manifest.ts +561 -0
  267. package/src/plugin/refusals.ts +94 -0
  268. package/src/plugin/rest-schemas.ts +354 -0
  269. package/src/plugin/sandbox.ts +123 -0
  270. package/src/plugin/testing.ts +612 -0
  271. package/src/plugin/web-react.ts +45 -0
  272. package/src/plugin/web.ts +403 -0
  273. package/src/plugin-nav.ts +132 -0
  274. package/src/plugin-testing.ts +10 -0
  275. package/src/plugin-web-react.ts +4 -0
  276. package/src/plugin-web.ts +35 -0
  277. package/src/plugin.ts +126 -0
  278. package/src/router.ts +73 -0
  279. package/src/routes.ts +7 -0
  280. package/src/schemas.ts +115 -18
  281. package/src/styles/console.css +330 -1
  282. package/src/tokens.ts +101 -0
  283. package/src/vocabulary.ts +30 -0
  284. package/src/web.ts +2 -0
  285. package/template/plugin/.gitignore +2 -0
  286. package/template/plugin/README.md +26 -0
  287. package/template/plugin/SKILLCDN.md +13 -0
  288. package/template/plugin/build.mjs +40 -0
  289. package/template/plugin/console-plugin.json +50 -0
  290. package/template/plugin/package.json +27 -0
  291. package/template/plugin/skills/__key__/SKILL.md +23 -0
  292. package/template/plugin/src/check.test.ts +34 -0
  293. package/template/plugin/src/server/index.test.ts +41 -0
  294. package/template/plugin/src/server/index.ts +72 -0
  295. package/template/plugin/src/web/index.css +51 -0
  296. package/template/plugin/src/web/index.ts +115 -0
  297. package/template/plugin/tsconfig.json +17 -0
  298. package/skills/working-the-board/references/setting-up.md +0 -3
  299. /package/skills/{working-the-board → planning-the-board}/references/project-rules.md +0 -0
@@ -0,0 +1,262 @@
1
+ // The REST shapes of the plugins' routes (docs/specs/plugins.md, "REST"): what the console
2
+ // answers about its plugins and what an administrator sends to enable, configure and grant. In
3
+ // the mini build of zod, as every REST schema is, and part of the snapshot the contract is held
4
+ // to (ADR-0043). What a plugin's own command or query carries is the plugin's, and not here.
5
+ import * as z from "zod/mini";
6
+ import { MAX_PROJECT_DESCRIPTION_LENGTH, MAX_PROJECT_KEY_LENGTH, MAX_PROJECT_NAME_LENGTH, } from "../limits.js";
7
+ import { PLUGIN_STATES } from "../vocabulary.js";
8
+ import { ARG_TYPES } from "./args.js";
9
+ import { MAX_PLUGIN_ARGV_WORD_LENGTH, MAX_PLUGIN_ARGV_WORDS, MAX_PLUGIN_COMMAND_FILES, } from "./limits.js";
10
+ import { PLUGIN_BOARD_NEEDS, PLUGIN_KEY_PATTERN, PLUGIN_PAGE_LEVELS, PLUGIN_SETTING_TYPES, PLUGIN_WIDGET_PLACES, PLUGIN_WIDGET_SIZES, SETTING_KEY_PATTERN, } from "./manifest.js";
11
+ /** How long a secret an administrator sets for a plugin may be. */
12
+ export const MAX_PLUGIN_SECRET_LENGTH = 4096;
13
+ /** How many grants one plugin holds. */
14
+ export const MAX_PLUGIN_GRANTS = 1000;
15
+ const uuid = z.uuid();
16
+ const instant = z.iso.datetime();
17
+ const pluginKey = z.string().check(z.regex(PLUGIN_KEY_PATTERN));
18
+ const settingKey = z.string().check(z.regex(SETTING_KEY_PATTERN));
19
+ const projectKey = z.string().check(z.minLength(1), z.maxLength(MAX_PROJECT_KEY_LENGTH));
20
+ /** A text per language, as the manifest has it. */
21
+ const localized = z.record(z.string(), z.string());
22
+ /** An argument of a command or a query, as the console describes it for help and forms. */
23
+ export const restPluginArgSchema = z.object({
24
+ type: z.enum(ARG_TYPES),
25
+ about: z.optional(z.string()),
26
+ optional: z.boolean(),
27
+ positional: z.boolean(),
28
+ secret: z.optional(z.boolean()),
29
+ max: z.optional(z.number()),
30
+ min: z.optional(z.number()),
31
+ integer: z.optional(z.boolean()),
32
+ options: z.optional(z.array(z.string())),
33
+ collection: z.optional(z.string()),
34
+ get of() {
35
+ return z.optional(restPluginArgSchema);
36
+ },
37
+ });
38
+ /** A command or a query of a plugin, as `GET /api/v1/plugins/<key>` lists them. */
39
+ export const restPluginOperationSchema = z.object({
40
+ name: z.string(),
41
+ kind: z.enum(["command", "query"]),
42
+ about: z.string(),
43
+ args: z.record(z.string(), restPluginArgSchema),
44
+ /** The roles that may run it, or `null` for every member. */
45
+ roles: z.nullable(z.array(z.string())),
46
+ });
47
+ export const restPluginPageSchema = z.object({
48
+ key: z.string(),
49
+ name: localized,
50
+ level: z.enum(PLUGIN_PAGE_LEVELS),
51
+ wide: z.boolean(),
52
+ });
53
+ export const restPluginWidgetSchema = z.object({
54
+ key: z.string(),
55
+ name: localized,
56
+ place: z.enum(PLUGIN_WIDGET_PLACES),
57
+ size: z.enum(PLUGIN_WIDGET_SIZES),
58
+ });
59
+ /** A plugin as a member may know of it: what it is, how it stands, and what the member may do with it. */
60
+ export const restPluginSchema = z.object({
61
+ key: z.string(),
62
+ name: localized,
63
+ description: localized,
64
+ /** The sentence agents read with the rules, or `null` for the description. */
65
+ agentNote: z.nullable(localized),
66
+ version: z.string(),
67
+ state: z.enum(PLUGIN_STATES),
68
+ /** Why the plugin failed, or waits for consent; empty otherwise. */
69
+ problems: z.array(z.string()),
70
+ /** The asker's roles in the plugin; every role for an administrator. */
71
+ roles: z.array(z.string()),
72
+ /** The roles the plugin declares, by key, with their names. */
73
+ declaredRoles: z.array(z.object({ key: z.string(), name: localized, description: localized })),
74
+ /** The role every member holds without a grant, or `null` where the manifest names none. */
75
+ defaultRole: z.nullable(z.string()),
76
+ menu: z.nullable(z.object({ group: z.string(), order: z.int(), name: z.nullable(localized) })),
77
+ /** The pages and widgets the asker may see. */
78
+ pages: z.array(restPluginPageSchema),
79
+ widgets: z.array(restPluginWidgetSchema),
80
+ /** The board project, or `null` for none. */
81
+ board: z.nullable(z.object({ key: z.string(), name: z.string() })),
82
+ boardNeeds: z.enum(PLUGIN_BOARD_NEEDS),
83
+ /** What the plugin asks, and what was consented to; `consent` is `null` to a member. */
84
+ capabilities: z.array(z.string()),
85
+ consent: z.nullable(z.array(z.string())),
86
+ /** The projects the plugin is on: all, their keys, or `null` to a member. */
87
+ projects: z.nullable(z.union([z.literal("all"), z.array(z.string())])),
88
+ requires: z.record(z.string(), z.string()),
89
+ dataVersion: z.int(),
90
+ enabledAt: z.nullable(instant),
91
+ });
92
+ export const restPluginsSchema = z.object({
93
+ items: z.array(restPluginSchema),
94
+ /** Whether this deployment can give a plugin a schema of its own (`storage:sql`). */
95
+ sql: z.boolean(),
96
+ });
97
+ /** A setting as the pages draw its form: the manifest's declaration, and whether and what it holds. */
98
+ export const restPluginSettingSchema = z.object({
99
+ key: z.string(),
100
+ type: z.enum(PLUGIN_SETTING_TYPES),
101
+ name: localized,
102
+ description: z.nullable(localized),
103
+ required: z.boolean(),
104
+ default: z.nullable(z.unknown()),
105
+ min: z.nullable(z.number()),
106
+ max: z.nullable(z.number()),
107
+ options: z.nullable(z.array(z.object({ value: z.string(), name: localized }))),
108
+ of: z.nullable(z.string()),
109
+ /** Whether a value is set; a secret's value is never here. */
110
+ set: z.boolean(),
111
+ value: z.nullable(z.unknown()),
112
+ /** When a secret was set, or `null`. */
113
+ setAt: z.nullable(instant),
114
+ });
115
+ /** A grant of a role: to a person, to the members of a project, or to everyone. */
116
+ export const restPluginGrantSchema = z.object({
117
+ id: uuid,
118
+ role: z.string(),
119
+ person: z.nullable(z.object({ id: uuid, login: z.string(), name: z.nullable(z.string()) })),
120
+ project: z.nullable(z.object({ key: z.string(), name: z.string() })),
121
+ everyone: z.boolean(),
122
+ createdAt: instant,
123
+ });
124
+ export const restPluginGrantsSchema = z.object({ items: z.array(restPluginGrantSchema) });
125
+ /** One plugin whole, for `GET /api/v1/plugins/<key>`: the listing's fields, and what agents and administrators need. */
126
+ export const restPluginDetailSchema = z.extend(restPluginSchema, {
127
+ operations: z.array(restPluginOperationSchema),
128
+ /** Where the plugin's skills are read, or `null` for none. */
129
+ skills: z.nullable(z.string()),
130
+ /** The board project the manifest proposes, for an administrator who makes it; `null` where it proposes none. */
131
+ boardDefaults: z.nullable(z.object({ key: z.string(), name: localized, description: localized })),
132
+ settings: z.array(restPluginSettingSchema),
133
+ /** The grants, to an administrator; `null` to a member. */
134
+ grants: z.nullable(z.array(restPluginGrantSchema)),
135
+ /** The plugin's own events are at this path. */
136
+ events: z.string(),
137
+ });
138
+ /** What `POST /api/v1/plugins/<key>/enable` is sent. */
139
+ export const restPluginEnableInputSchema = z.object({
140
+ /** Every capability the manifest asks, named again: consent. */
141
+ consent: z.array(z.string().check(z.maxLength(300))).check(z.maxLength(50)),
142
+ /** The board project: one to make, one that exists, or none. */
143
+ board: z.nullable(z.union([
144
+ z.object({
145
+ create: z.object({
146
+ key: z.string().check(z.minLength(1), z.maxLength(MAX_PROJECT_KEY_LENGTH)),
147
+ name: z.string().check(z.minLength(1), z.maxLength(MAX_PROJECT_NAME_LENGTH)),
148
+ description: z.string().check(z.maxLength(MAX_PROJECT_DESCRIPTION_LENGTH)),
149
+ }),
150
+ }),
151
+ z.object({ project: projectKey }),
152
+ ])),
153
+ /** The projects the plugin is on. */
154
+ projects: z.union([z.literal("all"), z.array(projectKey).check(z.maxLength(500))]),
155
+ /** The settings' values, without secrets. */
156
+ settings: z.optional(z.record(settingKey, z.unknown())),
157
+ });
158
+ /** What `PATCH /api/v1/plugins/<key>/settings` is sent: the values that change; `null` clears one. */
159
+ export const restPluginSettingsPatchSchema = z.object({
160
+ values: z.record(settingKey, z.unknown()),
161
+ });
162
+ /** What `PUT /api/v1/plugins/<key>/secrets/<name>` is sent. */
163
+ export const restPluginSecretInputSchema = z.object({
164
+ value: z.string().check(z.minLength(1), z.maxLength(MAX_PLUGIN_SECRET_LENGTH)),
165
+ });
166
+ /** What `POST /api/v1/plugins/<key>/grants` is sent: a role, and exactly one of whom. */
167
+ export const restPluginGrantInputSchema = z
168
+ .object({
169
+ role: pluginKey,
170
+ person: z.optional(uuid),
171
+ project: z.optional(projectKey),
172
+ everyone: z.optional(z.literal(true)),
173
+ })
174
+ .check(z.refine((input) => [input.person !== undefined, input.project !== undefined, input.everyone === true].filter(Boolean).length === 1, "names a person, a project or everyone, one of the three"));
175
+ /** A file a person uploaded for a command (`POST .../files`): the handle a `file` argument takes, good for an hour. */
176
+ export const restPluginFileHandleSchema = z.object({
177
+ handle: z.string(),
178
+ name: z.string(),
179
+ type: z.string(),
180
+ bytes: z.int(),
181
+ });
182
+ /** A handle as a command line names one: what `POST .../files` answered. */
183
+ const handle = z.string().check(z.minLength(1), z.maxLength(254));
184
+ /**
185
+ * What `POST /api/v1/plugins/<key>/invoke` is sent: the words as typed, the command's or the
186
+ * query's name first, the handles of the files uploaded for it, the project the call is on, and
187
+ * the run it is for where the caller has several open.
188
+ */
189
+ export const restPluginInvokeInputSchema = z.object({
190
+ argv: z
191
+ .array(z.string().check(z.maxLength(MAX_PLUGIN_ARGV_WORD_LENGTH)))
192
+ .check(z.minLength(1), z.maxLength(MAX_PLUGIN_ARGV_WORDS)),
193
+ files: z.optional(z.array(handle).check(z.maxLength(MAX_PLUGIN_COMMAND_FILES))),
194
+ project: z.optional(projectKey),
195
+ run: z.optional(uuid),
196
+ });
197
+ /** What `POST /api/v1/plugins/<key>/commands/<name>` is sent: the arguments as JSON, by name. */
198
+ export const restPluginCommandInputSchema = z.object({
199
+ args: z.record(z.string(), z.unknown()),
200
+ project: z.optional(projectKey),
201
+ run: z.optional(uuid),
202
+ });
203
+ /**
204
+ * What a command or a query answered: `text` is what the command prints, `data` what `--json`
205
+ * prints (a query's whole answer), `waiting` the id of a decision the caller now waits for.
206
+ */
207
+ export const restPluginInvocationSchema = z.object({
208
+ kind: z.enum(["command", "query"]),
209
+ text: z.string(),
210
+ data: z.unknown(),
211
+ waiting: z.nullable(z.string()),
212
+ });
213
+ /** A record of a plugin's collection, as `GET .../records/<collection>` lists them. */
214
+ export const restPluginRecordSchema = z.object({
215
+ id: uuid,
216
+ collection: z.string(),
217
+ /** The id of the project the record is linked to, or `null`. */
218
+ project: z.nullable(z.string()),
219
+ /** The id of the person the record is about, where the collection has an owner. */
220
+ owner: z.nullable(z.string()),
221
+ data: z.record(z.string(), z.unknown()),
222
+ version: z.int(),
223
+ createdAt: instant,
224
+ updatedAt: instant,
225
+ createdBy: z.nullable(z.string()),
226
+ updatedBy: z.nullable(z.string()),
227
+ archivedAt: z.nullable(instant),
228
+ });
229
+ /** A page of records, and the cursor `after` continues with, or `null` on the last. */
230
+ export const restPluginRecordPageSchema = z.object({
231
+ items: z.array(restPluginRecordSchema),
232
+ after: z.nullable(z.string()),
233
+ });
234
+ /** One version of a record, as it was. */
235
+ export const restPluginRecordVersionSchema = z.object({
236
+ version: z.int(),
237
+ data: z.record(z.string(), z.unknown()),
238
+ at: instant,
239
+ by: z.nullable(z.string()),
240
+ });
241
+ /** What `GET .../records/<collection>/<id>[?version=]` answers: the record, or one version of it. */
242
+ export const restPluginRecordReadSchema = z.union([
243
+ restPluginRecordSchema,
244
+ restPluginRecordVersionSchema,
245
+ ]);
246
+ export const restPluginRecordVersionsSchema = z.object({
247
+ items: z.array(restPluginRecordVersionSchema),
248
+ });
249
+ /** An event a plugin emitted (`ctx.events.emit`), as `GET .../plugin-events?after=` lists them for its frames: its number in the stream, its kind, its data, when. */
250
+ export const restPluginEventSchema = z.object({
251
+ id: z.int(),
252
+ kind: z.string(),
253
+ data: z.unknown(),
254
+ at: instant,
255
+ });
256
+ export const restPluginEventsSchema = z.object({
257
+ items: z.array(restPluginEventSchema),
258
+ more: z.boolean(),
259
+ });
260
+ /** What `POST /api/v1/plugins/<key>/purge` is sent: the key again. */
261
+ export const restPluginPurgeInputSchema = z.object({ confirm: pluginKey });
262
+ //# sourceMappingURL=rest-schemas.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rest-schemas.js","sourceRoot":"","sources":["../../src/plugin/rest-schemas.ts"],"names":[],"mappings":"AAAA,2FAA2F;AAC3F,+FAA+F;AAC/F,gGAAgG;AAChG,6F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,EAAE,CAAC,CAAC,KAAK,CAAC,qBAAqB,CAAC;IACrC,IAAI,EAAE,CAAC,CAAC,OAAO,EAAE;CAClB,CAAC,CAAC;AAGH,sEAAsE;AACtE,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC"}
@@ -0,0 +1,23 @@
1
+ /** The built-in modules a plugin's thread may not load, with or without the `node:` prefix. */
2
+ export declare const FORBIDDEN_BUILTINS: readonly string[];
3
+ /** The globals a plugin's thread does without: the network, and the way under the module system. */
4
+ export declare const REMOVED_GLOBALS: readonly string[];
5
+ /** True when a module specifier names a built-in the host refuses. */
6
+ export declare function isForbiddenBuiltin(specifier: string): boolean;
7
+ /** The built-ins a bundle's text imports or requires that the host refuses, each once, as written. */
8
+ export declare function forbiddenImportsIn(source: string): string[];
9
+ /** The removed globals a bundle's text calls, each once; a plugin that calls them fails at runtime. */
10
+ export declare function removedGlobalsIn(source: string): string[];
11
+ /** What the thread looks like after hardening, for a test to assert on. */
12
+ export interface HardenedThread {
13
+ readonly removed: readonly string[];
14
+ }
15
+ /** The module hook: refuses the forbidden built-ins and lets everything else resolve as it would. */
16
+ export declare function forbiddingResolve<C, R>(specifier: string, context: C, nextResolve: (specifier: string, context: C) => R): R;
17
+ /**
18
+ * Hardens the current thread: refuses the forbidden built-ins through the module hooks, removes
19
+ * the globals, empties the environment, and blocks `process.binding`. Call it in a worker thread
20
+ * before importing plugin code; it reaches nothing outside that thread.
21
+ */
22
+ export declare function hardenThread(moduleApi: Pick<typeof import("node:module"), "registerHooks">): HardenedThread;
23
+ //# sourceMappingURL=sandbox.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sandbox.d.ts","sourceRoot":"","sources":["../../src/plugin/sandbox.ts"],"names":[],"mappings":"AAKA,+FAA+F;AAC/F,eAAO,MAAM,kBAAkB,EAAE,SAAS,MAAM,EAkB/C,CAAC;AAEF,oGAAoG;AACpG,eAAO,MAAM,eAAe,EAAE,SAAS,MAAM,EAA0C,CAAC;AAExF,sEAAsE;AACtE,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAI7D;AAKD,sGAAsG;AACtG,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAS3D;AAID,uGAAuG;AACvG,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAQzD;AAED,2EAA2E;AAC3E,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;CACrC;AAED,qGAAqG;AACrG,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,CAAC,EACpC,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,CAAC,EACV,WAAW,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,KAAK,CAAC,GAChD,CAAC,CASH;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAC1B,SAAS,EAAE,IAAI,CAAC,cAAc,aAAa,CAAC,EAAE,eAAe,CAAC,GAC7D,cAAc,CA8BhB"}
@@ -0,0 +1,99 @@
1
+ // The hardening of a thread that runs plugin code (docs/specs/plugins.md, "The host"): the
2
+ // built-ins the host refuses, the globals it removes, and a scan of a bundle's text for the same,
3
+ // so that `console-plugin check` says before the host does. Defence in depth: the permission model
4
+ // of the host process is the first line; this is the second.
5
+ /** The built-in modules a plugin's thread may not load, with or without the `node:` prefix. */
6
+ export const FORBIDDEN_BUILTINS = [
7
+ "net",
8
+ "http",
9
+ "https",
10
+ "http2",
11
+ "tls",
12
+ "dgram",
13
+ "dns",
14
+ "dns/promises",
15
+ "child_process",
16
+ "cluster",
17
+ "worker_threads",
18
+ "vm",
19
+ "inspector",
20
+ "inspector/promises",
21
+ "repl",
22
+ "wasi",
23
+ "v8",
24
+ ];
25
+ /** The globals a plugin's thread does without: the network, and the way under the module system. */
26
+ export const REMOVED_GLOBALS = ["fetch", "WebSocket", "EventSource"];
27
+ /** True when a module specifier names a built-in the host refuses. */
28
+ export function isForbiddenBuiltin(specifier) {
29
+ return FORBIDDEN_BUILTINS.includes(specifier.startsWith("node:") ? specifier.slice(5) : specifier);
30
+ }
31
+ const IMPORT_OR_REQUIRE = /(?:\bfrom\s*|\bimport\s*\(?\s*|\brequire\s*\(\s*|\bprocess\.getBuiltinModule\s*\(\s*)["'`](node:)?([a-z_/]+)["'`]/g;
32
+ /** The built-ins a bundle's text imports or requires that the host refuses, each once, as written. */
33
+ export function forbiddenImportsIn(source) {
34
+ const found = new Set();
35
+ for (const match of source.matchAll(IMPORT_OR_REQUIRE)) {
36
+ const specifier = `${match[1] ?? ""}${match[2] ?? ""}`;
37
+ if (isForbiddenBuiltin(specifier)) {
38
+ found.add(specifier);
39
+ }
40
+ }
41
+ return [...found];
42
+ }
43
+ const GLOBAL_USES = /\b(fetch|WebSocket|EventSource|process\.binding|process\.dlopen)\s*\(/g;
44
+ /** The removed globals a bundle's text calls, each once; a plugin that calls them fails at runtime. */
45
+ export function removedGlobalsIn(source) {
46
+ const found = new Set();
47
+ for (const match of source.matchAll(GLOBAL_USES)) {
48
+ if (match[1] !== undefined) {
49
+ found.add(match[1]);
50
+ }
51
+ }
52
+ return [...found];
53
+ }
54
+ /** The module hook: refuses the forbidden built-ins and lets everything else resolve as it would. */
55
+ export function forbiddingResolve(specifier, context, nextResolve) {
56
+ if (isForbiddenBuiltin(specifier)) {
57
+ const error = new Error(`the host refuses ${specifier}: a plugin reaches the console through ctx alone`);
58
+ error.code = "ERR_PLUGIN_FORBIDDEN_BUILTIN";
59
+ throw error;
60
+ }
61
+ return nextResolve(specifier, context);
62
+ }
63
+ /**
64
+ * Hardens the current thread: refuses the forbidden built-ins through the module hooks, removes
65
+ * the globals, empties the environment, and blocks `process.binding`. Call it in a worker thread
66
+ * before importing plugin code; it reaches nothing outside that thread.
67
+ */
68
+ export function hardenThread(moduleApi) {
69
+ moduleApi.registerHooks({ resolve: forbiddingResolve });
70
+ const removed = [];
71
+ const global = globalThis;
72
+ for (const name of REMOVED_GLOBALS) {
73
+ if (name in global) {
74
+ Object.defineProperty(global, name, {
75
+ value: undefined,
76
+ writable: false,
77
+ configurable: false,
78
+ });
79
+ removed.push(name);
80
+ }
81
+ }
82
+ const proc = global.process;
83
+ if (proc !== undefined) {
84
+ const refuse = () => {
85
+ throw new Error("the host refuses process.binding");
86
+ };
87
+ for (const name of ["binding", "_linkedBinding", "dlopen"]) {
88
+ Object.defineProperty(proc, name, { value: refuse, writable: false, configurable: false });
89
+ }
90
+ const env = proc.env;
91
+ if (env !== undefined) {
92
+ for (const key of Object.keys(env)) {
93
+ delete env[key];
94
+ }
95
+ }
96
+ }
97
+ return { removed };
98
+ }
99
+ //# sourceMappingURL=sandbox.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sandbox.js","sourceRoot":"","sources":["../../src/plugin/sandbox.ts"],"names":[],"mappings":"AAAA,2FAA2F;AAC3F,kGAAkG;AAClG,mGAAmG;AACnG,6DAA6D;AAE7D,+FAA+F;AAC/F,MAAM,CAAC,MAAM,kBAAkB,GAAsB;IACnD,KAAK;IACL,MAAM;IACN,OAAO;IACP,OAAO;IACP,KAAK;IACL,OAAO;IACP,KAAK;IACL,cAAc;IACd,eAAe;IACf,SAAS;IACT,gBAAgB;IAChB,IAAI;IACJ,WAAW;IACX,oBAAoB;IACpB,MAAM;IACN,MAAM;IACN,IAAI;CACL,CAAC;AAEF,oGAAoG;AACpG,MAAM,CAAC,MAAM,eAAe,GAAsB,CAAC,OAAO,EAAE,WAAW,EAAE,aAAa,CAAC,CAAC;AAExF,sEAAsE;AACtE,MAAM,UAAU,kBAAkB,CAAC,SAAiB;IAClD,OAAO,kBAAkB,CAAC,QAAQ,CAChC,SAAS,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC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AAG,CAAC,GAAG,CAAC,CAAC;YAClB,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,EAAE,OAAO,EAAE,CAAC;AACrB,CAAC"}
@@ -0,0 +1,45 @@
1
+ import type { CollectionDefinition, OtherPlugin, PluginCaller, PluginConsole, PluginContext, PluginFetchInit, PluginFetchResponse, PluginInfo, PluginRecord, PluginSql } from "./context.js";
2
+ export interface TestConsoleOptions {
3
+ readonly workspace?: PluginConsole["workspace"];
4
+ readonly people?: Partial<PluginConsole["people"]>;
5
+ readonly projects?: Partial<PluginConsole["projects"]>;
6
+ readonly tasks?: Partial<PluginConsole["tasks"]>;
7
+ readonly decisions?: Partial<PluginConsole["decisions"]>;
8
+ readonly documents?: Partial<PluginConsole["documents"]>;
9
+ readonly runs?: Partial<PluginConsole["runs"]>;
10
+ }
11
+ export interface TestContextOptions {
12
+ readonly plugin?: Partial<PluginInfo>;
13
+ readonly caller?: PluginCaller;
14
+ /** The collections, so that writes are checked against their schemas and `where` against their indexes. */
15
+ readonly collections?: readonly CollectionDefinition[];
16
+ /** What the console answers; what is left out is refused as `plugin.forbidden`. */
17
+ readonly console?: TestConsoleOptions;
18
+ readonly sql?: PluginSql;
19
+ readonly fetch?: (url: string, init?: PluginFetchInit) => Promise<PluginFetchResponse>;
20
+ /** The secrets by name; `sign` and `verify` use them, and never hand them over. */
21
+ readonly secrets?: Readonly<Record<string, string>>;
22
+ readonly plugins?: Readonly<Record<string, OtherPlugin>>;
23
+ readonly now?: () => Date;
24
+ readonly language?: string;
25
+ }
26
+ export interface LoggedLine {
27
+ readonly level: "info" | "warn" | "error";
28
+ readonly message: string;
29
+ readonly fields: Readonly<Record<string, unknown>> | undefined;
30
+ }
31
+ export interface TestContext extends PluginContext {
32
+ /** What the plugin emitted with `ctx.events.emit`, in order. */
33
+ readonly emitted: readonly {
34
+ readonly kind: string;
35
+ readonly data: unknown;
36
+ }[];
37
+ readonly logged: readonly LoggedLine[];
38
+ /** Every record of a collection, archived ones included, for assertions. */
39
+ all(collection: string): readonly PluginRecord[];
40
+ /** The same store, as another caller. */
41
+ as(caller: PluginCaller): TestContext;
42
+ }
43
+ /** A context for a plugin's tests: records in memory, the console refusing what is not given. */
44
+ export declare function createTestContext(options?: TestContextOptions): TestContext;
45
+ //# sourceMappingURL=testing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../../src/plugin/testing.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,oBAAoB,EAEpB,WAAW,EACX,YAAY,EACZ,aAAa,EACb,aAAa,EACb,eAAe,EACf,mBAAmB,EACnB,UAAU,EACV,YAAY,EAEZ,SAAS,EAYV,MAAM,cAAc,CAAC;AAStB,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,SAAS,CAAC,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC;IAChD,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,CAAC;IACnD,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC;IACvD,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC;IACjD,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC,CAAC;IACzD,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC,CAAC;IACzD,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC;CAChD;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;IACtC,QAAQ,CAAC,MAAM,CAAC,EAAE,YAAY,CAAC;IAC/B,2GAA2G;IAC3G,QAAQ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