@skillcdn/console 0.6.2 → 0.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (253) hide show
  1. package/README.md +16 -9
  2. package/SKILLCDN.md +3 -2
  3. package/dist/agent-page.d.ts +2 -0
  4. package/dist/agent-page.d.ts.map +1 -1
  5. package/dist/agent-page.js +46 -5
  6. package/dist/agent-page.js.map +1 -1
  7. package/dist/agent-state.d.ts +9 -0
  8. package/dist/agent-state.d.ts.map +1 -0
  9. package/dist/agent-state.js +28 -0
  10. package/dist/agent-state.js.map +1 -0
  11. package/dist/api.d.ts +6 -4
  12. package/dist/api.d.ts.map +1 -1
  13. package/dist/api.js +6 -4
  14. package/dist/api.js.map +1 -1
  15. package/dist/cli/cli.d.ts +2 -0
  16. package/dist/cli/cli.d.ts.map +1 -1
  17. package/dist/cli/cli.js +948 -252
  18. package/dist/cli/cli.js.map +1 -1
  19. package/dist/cli/format.d.ts +44 -7
  20. package/dist/cli/format.d.ts.map +1 -1
  21. package/dist/cli/format.js +168 -13
  22. package/dist/cli/format.js.map +1 -1
  23. package/dist/cli/help.d.ts +82 -9
  24. package/dist/cli/help.d.ts.map +1 -1
  25. package/dist/cli/help.js +855 -331
  26. package/dist/cli/help.js.map +1 -1
  27. package/dist/cli/pack.d.ts +13 -12
  28. package/dist/cli/pack.d.ts.map +1 -1
  29. package/dist/cli/pack.js +33 -45
  30. package/dist/cli/pack.js.map +1 -1
  31. package/dist/cli/plugin-cli.d.ts.map +1 -1
  32. package/dist/cli/plugin-cli.js +8 -5
  33. package/dist/cli/plugin-cli.js.map +1 -1
  34. package/dist/cli/runner-files.d.ts +16 -0
  35. package/dist/cli/runner-files.d.ts.map +1 -0
  36. package/dist/cli/runner-files.js +125 -0
  37. package/dist/cli/runner-files.js.map +1 -0
  38. package/dist/cli/runner-host.d.ts +7 -0
  39. package/dist/cli/runner-host.d.ts.map +1 -1
  40. package/dist/cli/runner-host.js +40 -2
  41. package/dist/cli/runner-host.js.map +1 -1
  42. package/dist/cli/skill-path.d.ts +11 -0
  43. package/dist/cli/skill-path.d.ts.map +1 -0
  44. package/dist/cli/skill-path.js +44 -0
  45. package/dist/cli/skill-path.js.map +1 -0
  46. package/dist/client.d.ts +32 -1
  47. package/dist/client.d.ts.map +1 -1
  48. package/dist/client.js +15 -1
  49. package/dist/client.js.map +1 -1
  50. package/dist/components/agent-page.d.ts +93 -6
  51. package/dist/components/agent-page.d.ts.map +1 -1
  52. package/dist/components/agent-page.js +202 -10
  53. package/dist/components/agent-page.js.map +1 -1
  54. package/dist/components/agents.d.ts +6 -6
  55. package/dist/components/agents.d.ts.map +1 -1
  56. package/dist/components/agents.js +16 -9
  57. package/dist/components/agents.js.map +1 -1
  58. package/dist/components/people.d.ts.map +1 -1
  59. package/dist/components/people.js +7 -2
  60. package/dist/components/people.js.map +1 -1
  61. package/dist/components/picker.d.ts +16 -0
  62. package/dist/components/picker.d.ts.map +1 -1
  63. package/dist/components/picker.js +69 -4
  64. package/dist/components/picker.js.map +1 -1
  65. package/dist/console.css +40 -0
  66. package/dist/console.js +2 -2
  67. package/dist/console.js.map +1 -1
  68. package/dist/feed-words.d.ts.map +1 -1
  69. package/dist/feed-words.js +12 -1
  70. package/dist/feed-words.js.map +1 -1
  71. package/dist/i18n/en.d.ts +64 -6
  72. package/dist/i18n/en.d.ts.map +1 -1
  73. package/dist/i18n/en.js +59 -10
  74. package/dist/i18n/en.js.map +1 -1
  75. package/dist/i18n/ko.d.ts.map +1 -1
  76. package/dist/i18n/ko.js +49 -9
  77. package/dist/i18n/ko.js.map +1 -1
  78. package/dist/limits.d.ts +26 -0
  79. package/dist/limits.d.ts.map +1 -1
  80. package/dist/limits.js +26 -0
  81. package/dist/limits.js.map +1 -1
  82. package/dist/onboarding.d.ts +18 -6
  83. package/dist/onboarding.d.ts.map +1 -1
  84. package/dist/onboarding.js +42 -7
  85. package/dist/onboarding.js.map +1 -1
  86. package/dist/plugin/args.d.ts +24 -2
  87. package/dist/plugin/args.d.ts.map +1 -1
  88. package/dist/plugin/args.js +20 -2
  89. package/dist/plugin/args.js.map +1 -1
  90. package/dist/plugin/context.d.ts +39 -7
  91. package/dist/plugin/context.d.ts.map +1 -1
  92. package/dist/plugin/define.d.ts.map +1 -1
  93. package/dist/plugin/define.js +12 -3
  94. package/dist/plugin/define.js.map +1 -1
  95. package/dist/plugin/rest-schemas.d.ts +2 -0
  96. package/dist/plugin/rest-schemas.d.ts.map +1 -1
  97. package/dist/plugin/rest-schemas.js +1 -0
  98. package/dist/plugin/rest-schemas.js.map +1 -1
  99. package/dist/routes.d.ts +2 -0
  100. package/dist/routes.d.ts.map +1 -1
  101. package/dist/routes.js +2 -0
  102. package/dist/routes.js.map +1 -1
  103. package/dist/rules.d.ts +4 -1
  104. package/dist/rules.d.ts.map +1 -1
  105. package/dist/rules.js +5 -2
  106. package/dist/rules.js.map +1 -1
  107. package/dist/runner/acp.d.ts.map +1 -1
  108. package/dist/runner/acp.js +9 -3
  109. package/dist/runner/acp.js.map +1 -1
  110. package/dist/runner/claude.d.ts.map +1 -1
  111. package/dist/runner/claude.js +53 -1
  112. package/dist/runner/claude.js.map +1 -1
  113. package/dist/runner/codex.d.ts.map +1 -1
  114. package/dist/runner/codex.js +18 -3
  115. package/dist/runner/codex.js.map +1 -1
  116. package/dist/runner/config.d.ts +18 -0
  117. package/dist/runner/config.d.ts.map +1 -1
  118. package/dist/runner/config.js +77 -1
  119. package/dist/runner/config.js.map +1 -1
  120. package/dist/runner/desk.d.ts +7 -0
  121. package/dist/runner/desk.d.ts.map +1 -1
  122. package/dist/runner/desk.js +14 -4
  123. package/dist/runner/desk.js.map +1 -1
  124. package/dist/runner/message.d.ts +16 -22
  125. package/dist/runner/message.d.ts.map +1 -1
  126. package/dist/runner/message.js +72 -120
  127. package/dist/runner/message.js.map +1 -1
  128. package/dist/runner/runner.d.ts +41 -1
  129. package/dist/runner/runner.d.ts.map +1 -1
  130. package/dist/runner/runner.js +557 -23
  131. package/dist/runner/runner.js.map +1 -1
  132. package/dist/runner/slack-status.d.ts +19 -0
  133. package/dist/runner/slack-status.d.ts.map +1 -0
  134. package/dist/runner/slack-status.js +332 -0
  135. package/dist/runner/slack-status.js.map +1 -0
  136. package/dist/runner/slack.d.ts.map +1 -1
  137. package/dist/runner/slack.js +258 -59
  138. package/dist/runner/slack.js.map +1 -1
  139. package/dist/runner/types.d.ts +128 -15
  140. package/dist/runner/types.d.ts.map +1 -1
  141. package/dist/runner/types.js.map +1 -1
  142. package/dist/runner/usage.d.ts +6 -1
  143. package/dist/runner/usage.d.ts.map +1 -1
  144. package/dist/runner/usage.js +9 -2
  145. package/dist/runner/usage.js.map +1 -1
  146. package/dist/runner.d.ts +2 -2
  147. package/dist/runner.d.ts.map +1 -1
  148. package/dist/runner.js.map +1 -1
  149. package/dist/schemas.d.ts +635 -6
  150. package/dist/schemas.d.ts.map +1 -1
  151. package/dist/schemas.js +197 -15
  152. package/dist/schemas.js.map +1 -1
  153. package/dist/secret-file.d.ts +21 -0
  154. package/dist/secret-file.d.ts.map +1 -0
  155. package/dist/secret-file.js +59 -0
  156. package/dist/secret-file.js.map +1 -0
  157. package/dist/services.d.ts.map +1 -1
  158. package/dist/services.js +3 -2
  159. package/dist/services.js.map +1 -1
  160. package/dist/setup-guide.d.ts +2 -2
  161. package/dist/setup-guide.d.ts.map +1 -1
  162. package/dist/setup-guide.js +6 -5
  163. package/dist/setup-guide.js.map +1 -1
  164. package/dist/vocabulary.d.ts +17 -2
  165. package/dist/vocabulary.d.ts.map +1 -1
  166. package/dist/vocabulary.js +15 -2
  167. package/dist/vocabulary.js.map +1 -1
  168. package/dist/wake-text.d.ts +43 -0
  169. package/dist/wake-text.d.ts.map +1 -0
  170. package/dist/wake-text.js +115 -0
  171. package/dist/wake-text.js.map +1 -0
  172. package/docs/specs/cli.md +39 -25
  173. package/docs/specs/plugins.md +10 -9
  174. package/docs/specs/rest.md +34 -15
  175. package/docs/specs/runner.md +108 -25
  176. package/docs/start.md +28 -6
  177. package/package.json +3 -3
  178. package/skills/building-a-plugin/SKILL.md +2 -2
  179. package/skills/deploying-a-console/SKILL.md +3 -3
  180. package/skills/deploying-a-console/references/access.md +15 -1
  181. package/skills/deploying-a-console/references/resources.md +2 -2
  182. package/skills/deploying-a-console/scripts/github-app.mjs +593 -0
  183. package/skills/keeping-the-pack/SKILL.md +87 -0
  184. package/skills/planning-the-board/SKILL.md +6 -6
  185. package/skills/planning-the-board/references/a-task.md +1 -1
  186. package/skills/planning-the-board/references/setting-up.md +9 -5
  187. package/skills/running-an-agent/SKILL.md +21 -17
  188. package/skills/running-an-agent/references/preparing-the-machine.md +4 -3
  189. package/skills/running-an-agent/references/several-tasks.md +8 -2
  190. package/skills/running-an-agent/references/slack-app.md +31 -8
  191. package/skills/running-an-agent/references/the-account-and-the-invitation.md +1 -1
  192. package/skills/running-an-agent/references/what-was-not-seen-run-yet.md +3 -1
  193. package/skills/running-an-agent/references/when-the-agent-could-not-go-on.md +4 -4
  194. package/skills/running-an-agent/references/your-first-task.md +11 -5
  195. package/skills/trying-a-console/SKILL.md +136 -0
  196. package/skills/trying-a-console/references/when-it-does-not-go.md +30 -0
  197. package/skills/working-the-board/SKILL.md +6 -6
  198. package/skills/working-the-board/references/terms.md +3 -1
  199. package/skills/working-the-board/references/the-pack.md +14 -7
  200. package/skills/working-the-board/references/what-they-were-told.md +1 -1
  201. package/src/agent-page.tsx +111 -4
  202. package/src/agent-state.ts +33 -0
  203. package/src/api.ts +43 -0
  204. package/src/cli/cli.ts +1190 -313
  205. package/src/cli/format.ts +207 -13
  206. package/src/cli/help.ts +991 -372
  207. package/src/cli/pack.ts +55 -62
  208. package/src/cli/plugin-cli.ts +8 -5
  209. package/src/cli/runner-files.ts +137 -0
  210. package/src/cli/runner-host.ts +48 -2
  211. package/src/cli/skill-path.ts +51 -0
  212. package/src/client.ts +103 -0
  213. package/src/components/agent-page.tsx +446 -20
  214. package/src/components/agents.tsx +27 -28
  215. package/src/components/people.tsx +7 -3
  216. package/src/components/picker.tsx +79 -5
  217. package/src/console.tsx +1 -1
  218. package/src/feed-words.ts +14 -1
  219. package/src/i18n/en.ts +64 -11
  220. package/src/i18n/ko.ts +55 -9
  221. package/src/limits.ts +26 -0
  222. package/src/onboarding.ts +60 -21
  223. package/src/plugin/args.ts +29 -3
  224. package/src/plugin/context.ts +40 -7
  225. package/src/plugin/define.ts +18 -3
  226. package/src/plugin/rest-schemas.ts +3 -0
  227. package/src/routes.ts +2 -0
  228. package/src/rules.ts +5 -2
  229. package/src/runner/acp.ts +9 -3
  230. package/src/runner/claude.ts +58 -1
  231. package/src/runner/codex.ts +18 -3
  232. package/src/runner/config.ts +114 -1
  233. package/src/runner/desk.ts +15 -4
  234. package/src/runner/message.ts +88 -126
  235. package/src/runner/runner.ts +682 -27
  236. package/src/runner/slack-status.ts +423 -0
  237. package/src/runner/slack.ts +310 -67
  238. package/src/runner/types.ts +124 -13
  239. package/src/runner/usage.ts +16 -3
  240. package/src/runner.ts +4 -0
  241. package/src/schemas.ts +245 -13
  242. package/src/secret-file.ts +76 -0
  243. package/src/services.ts +3 -2
  244. package/src/setup-guide.ts +6 -5
  245. package/src/styles/README.md +1 -1
  246. package/src/styles/pages/agents.css +40 -0
  247. package/src/vocabulary.ts +21 -2
  248. package/src/wake-text.ts +133 -0
  249. package/dist/cli/command-words.d.ts +0 -20
  250. package/dist/cli/command-words.d.ts.map +0 -1
  251. package/dist/cli/command-words.js +0 -51
  252. package/dist/cli/command-words.js.map +0 -1
  253. package/src/cli/command-words.ts +0 -56
package/src/cli/pack.ts CHANGED
@@ -7,23 +7,20 @@ import {
7
7
  type Pack,
8
8
  PackError,
9
9
  type RowsPage,
10
+ shellLine,
10
11
  } from "@skillcdn/cli";
11
- import {
12
- isReadmePath,
13
- parseAddress,
14
- parseRepoPath,
15
- parseSkillUri,
16
- type RestBrowse,
17
- type RestFile,
18
- type RestFind,
19
- type RestMount,
20
- type RestSkill as RestSkillPage,
21
- type ToolWords,
22
- } from "@skillcdn/core";
12
+ import { isReadmePath, type ToolWords } from "@skillcdn/core";
13
+ import { parseAddress, parseRepoPath } from "@skillcdn/core/address";
14
+ import type {
15
+ RestBrowse,
16
+ RestFile,
17
+ RestFind,
18
+ RestMount,
19
+ RestSkill as RestSkillPage,
20
+ } from "@skillcdn/core/rest";
23
21
  import type { PackClient } from "../client.js";
24
22
  import type { RestSkills } from "../schemas.js";
25
23
  import type { SkillsStatus } from "../vocabulary.js";
26
- import { commandLine, NO_LINE_TO_RUN } from "./command-words.js";
27
24
 
28
25
  // The pack of the project, as the command prints it (ADR-0028, ADR-0031, ADR-0124): the console
29
26
  // answers what the pack's REST API answered, in the shapes of @skillcdn/core, and the command
@@ -33,6 +30,44 @@ import { commandLine, NO_LINE_TO_RUN } from "./command-words.js";
33
30
  // comes with its next version. What is here is the console's own: the pack made of the console's
34
31
  // answers, the lines around a listing, and the words of a pack the console could not read,
35
32
  // which is a project's or the organization's and whose token is the console's to hold.
33
+ //
34
+ // This module is the one place of the command that imports @skillcdn/cli and the main entry
35
+ // point of @skillcdn/core, and the command loads it only where a pack is read (ADR-0179):
36
+ // importing either loads the whole of the main repository's library, a quarter of a second
37
+ // every other command would pay for nothing. What the command takes of the library for a read
38
+ // it takes from here.
39
+
40
+ export {
41
+ PackError,
42
+ ReadMisuse,
43
+ readNumber,
44
+ readPack,
45
+ wroteLine,
46
+ } from "@skillcdn/cli";
47
+ export {
48
+ BROWSE_MAX_LIMIT,
49
+ FIND_MAX_LIMIT,
50
+ READ_FILE_MAX_LIMIT,
51
+ utf8Length,
52
+ } from "@skillcdn/core";
53
+
54
+ /**
55
+ * Words as one line printed for a person or an agent to run, after `command`, the command's own
56
+ * words: each spelled by the skillcdn command's own rule (`shellLine` of @skillcdn/cli), so that
57
+ * bash, zsh and PowerShell all take it whole as it is. Nothing where one of them has no such
58
+ * spelling: what to run is then said in a sentence, and no line is printed.
59
+ */
60
+ export function commandLine(command: string, words: readonly string[]): string | undefined {
61
+ const spelled = shellLine(words);
62
+ if (spelled === undefined) {
63
+ return undefined;
64
+ }
65
+ return spelled.length === 0 ? command : `${command} ${spelled}`;
66
+ }
67
+
68
+ /** Why a line is not printed for a person or an agent to run, said in its place. */
69
+ export const NO_LINE_TO_RUN =
70
+ "No line is printed to run: a word of it has no one spelling that bash, zsh and PowerShell all take whole.";
36
71
 
37
72
  /** How the results name the four reads of a pack read with `skills` and `skill`, so that an agent is told the command and not a tool. */
38
73
  export const packWords = (skills: string, skill: string): ToolWords => ({
@@ -216,8 +251,10 @@ function listingOf(
216
251
  commit: mount.commit,
217
252
  items: items.slice(from, end),
218
253
  diagnostics: index.diagnostics,
219
- // The counts stand in the instructions above the first page.
220
- totals: null,
254
+ // The listing the command prints is of the skills alone (SkillCDN 0.6.3): the documents
255
+ // outside them are counted from these, with what reads them, and a page that ends before
256
+ // the skills do says how many are left.
257
+ totals: { skills: index.skills.length, documents: index.documents.length },
221
258
  nextCursor: end < items.length ? listingCursor(end, mount.commit) : null,
222
259
  };
223
260
  }
@@ -253,7 +290,7 @@ function listingStart(cursor: string | undefined, commit: string, count: number)
253
290
  * A document's outline with the reads of its tables and its code blocks named as commands
254
291
  * (ADR-0100): where the console said an address of its own for one, the command that reads it,
255
292
  * `command` being the one the pack is read with, so that an agent is told what to run. Where the
256
- * path has no spelling both shells take whole, what to run is said in words, with why.
293
+ * path has no spelling every shell takes whole, what to run is said in words, with why.
257
294
  */
258
295
  function withDataCommands(read: Ready<RestBrowse>, command: string): Ready<RestBrowse> {
259
296
  const outline = read.outline;
@@ -399,8 +436,8 @@ export function consolePack(
399
436
 
400
437
  /**
401
438
  * The listing of a pack as the command prints it. Where the pack answered, `text` is what the
402
- * skillcdn command prints for it, what a client is told on connect and then every skill and
403
- * document, between the lines of the console's own: where the pack is and how it answered,
439
+ * skillcdn command prints for it, what a client is told on connect and then every skill, the
440
+ * documents counted, between the lines of the console's own: where the pack is and how it answered,
404
441
  * where a person connects an agent of their own, and where the console's own skills are on this
405
442
  * machine. Where it did not, why, with that last line still.
406
443
  */
@@ -452,50 +489,6 @@ export function skillsAround(
452
489
  };
453
490
  }
454
491
 
455
- /**
456
- * The `SKILL.md` a path names: the path itself where it names one, else the one in the folder
457
- * it names, since a skill is its folder and a listing cut short shows the folder alone; the
458
- * root's own for the dot, as the root is everywhere.
459
- */
460
- function skillFileOf(given: string): string {
461
- const path = given.replace(/\/+$/, "");
462
- if (path === "" || path === ".") {
463
- return "SKILL.md";
464
- }
465
- return path === "SKILL.md" || path.endsWith("/SKILL.md") ? path : `${path}/SKILL.md`;
466
- }
467
-
468
- /**
469
- * A skill's path as given, or taken out of the URI the listing names it by
470
- * (`skill://<host>/<owner>/<name>/<path>`); a URI of another pack would read this pack's skill
471
- * at the same path, or nothing, so it is said instead.
472
- */
473
- export function skillPathIn(
474
- given: string,
475
- packAddress: string | null,
476
- ): { readonly path: string } | { readonly error: string } {
477
- const uri = parseSkillUri(given);
478
- if (uri === undefined) {
479
- return given.startsWith("skill://")
480
- ? {
481
- error: `Not a skill's URI the console knows: ${given}. Say the path of its SKILL.md from the repository's root, or the URI console skills lists.`,
482
- }
483
- : { path: skillFileOf(given) };
484
- }
485
- const pack = packAddress === null ? undefined : parseAddress(packAddress);
486
- if (
487
- pack?.ok === true &&
488
- (uri.address.host !== pack.value.host ||
489
- uri.address.owner !== pack.value.owner ||
490
- uri.address.repo !== pack.value.repo)
491
- ) {
492
- return {
493
- error: `That URI is of another pack, /${uri.address.host}/${uri.address.owner}/${uri.address.repo}; this project's pack is at ${packAddress}. Say the path of the SKILL.md, or a URI console skills lists.`,
494
- };
495
- }
496
- return { path: uri.path };
497
- }
498
-
499
492
  /** Whether a read of data held nothing, by what the read says it holds: no table, or no code block. */
500
493
  export const holdsNothing = (holds: string | undefined): boolean =>
501
494
  holds !== undefined && /(^| )0 (tables|code blocks)$/.test(holds);
@@ -6,7 +6,6 @@ import { parseArgs } from "node:util";
6
6
  import type { ServerLoad } from "../plugin/load.js";
7
7
  import { isPluginKey, RESERVED_PLUGIN_KEYS } from "../plugin/manifest.js";
8
8
  import { lineRangeFrom, versionOfDependency } from "../plugin/semver.js";
9
- import { commandWord, NO_LINE_TO_RUN } from "./command-words.js";
10
9
  import { checkPlugin, MAX_CHECKED_FILE_BYTES, readConsoleClasses } from "./plugin-check.js";
11
10
  import { LANGUAGE_TAG, nameFromKey, PACKAGE_NAME, writePluginFromTemplate } from "./plugin-init.js";
12
11
 
@@ -204,11 +203,15 @@ async function init(args: readonly string[], io: PluginCliIo): Promise<number> {
204
203
  languages,
205
204
  });
206
205
  io.stdout(`Wrote the plugin ${key} into ${target}: ${written.length} files.\n`);
207
- // The folder as bash and PowerShell both take it whole; where it has no such spelling, it is
208
- // named above, and no line is printed to run.
209
- const into = commandWord(dir);
206
+ // The folder as every shell takes it whole, by the skillcdn command's own rule, whose
207
+ // library is loaded here and by nothing else of this command; where it has no such
208
+ // spelling, it is named above, and no line is printed to run. The plugin is written by
209
+ // then: where the library does not load, that is said all the same, the folder by name.
210
+ const reads = await import("./pack.js").catch(() => undefined);
211
+ const into = reads?.commandLine("", [dir])?.trim();
212
+ const noLine = reads === undefined || into !== undefined ? "" : ` ${reads.NO_LINE_TO_RUN}`;
210
213
  io.stdout(
211
- `Next: ${into === undefined ? "go into that folder" : `cd ${into}`}, install the dependencies (npm install), build (npm run build), run the tests (npm test), and check it as a console would (npm run check). The contract is docs/specs/plugins.md in node_modules/@skillcdn/console/.${into === undefined ? ` ${NO_LINE_TO_RUN}` : ""}\n`,
214
+ `Next: ${into === undefined ? "go into that folder" : `cd ${into}`}, install the dependencies (npm install), build (npm run build), run the tests (npm test), and check it as a console would (npm run check). The contract is docs/specs/plugins.md in node_modules/@skillcdn/console/.${noLine}\n`,
212
215
  );
213
216
  return PLUGIN_EXIT.ok;
214
217
  } catch (error) {
@@ -0,0 +1,137 @@
1
+ import { parseVersion } from "../compat.js";
2
+ import type { KeptBySource, RunnerState } from "../runner/runner.js";
3
+
4
+ // The runner's own files under the desk's `work/`, as `console runner` reads them back and
5
+ // writes them (ADR-0085, ADR-0166): its state between its own restarts, and what each wake
6
+ // source keeps. A file of the desk may hold anything, whatever wrote it: what is read of one is
7
+ // data, bounded, and nothing where it does not read.
8
+
9
+ /** What the runner keeps between its own restarts, as its file says it; nothing for a file that does not read. */
10
+ export function runnerStateOf(text: string | undefined): RunnerState | undefined {
11
+ if (text === undefined) {
12
+ return undefined;
13
+ }
14
+ let json: unknown;
15
+ try {
16
+ json = JSON.parse(text);
17
+ } catch {
18
+ return undefined;
19
+ }
20
+ if (typeof json !== "object" || json === null) {
21
+ return undefined;
22
+ }
23
+ const delivered = "delivered" in json ? json.delivered : undefined;
24
+ const conversation = "conversation" in json ? json.conversation : undefined;
25
+ const driver = "driver" in json ? json.driver : undefined;
26
+ const limited = "limited" in json ? json.limited : undefined;
27
+ const kept: unknown = "kept" in json ? json.kept : undefined;
28
+ const began: unknown = "began" in json ? json.began : undefined;
29
+ const unknown: unknown = "unknown" in json ? json.unknown : undefined;
30
+ const newer: unknown = "newer" in json ? json.newer : undefined;
31
+ if (typeof delivered !== "number" || !Number.isSafeInteger(delivered) || delivered < 0) {
32
+ return undefined;
33
+ }
34
+ /**
35
+ * A moment in milliseconds since the epoch, or nothing for anything else: a number past what
36
+ * a date holds would fail the runner at every start, where it says the moment in words.
37
+ */
38
+ const momentOf = (value: unknown): number | undefined =>
39
+ typeof value === "number" && Number.isSafeInteger(value) && value > 0 && value < 1e14
40
+ ? value
41
+ : undefined;
42
+ const since =
43
+ typeof limited === "object" && limited !== null && "since" in limited
44
+ ? momentOf(limited.since)
45
+ : undefined;
46
+ return {
47
+ delivered,
48
+ conversation:
49
+ typeof conversation === "string" && conversation.length > 0 && conversation.length <= 200
50
+ ? conversation
51
+ : undefined,
52
+ // The driver the conversation was begun under, as a registry spells one.
53
+ driver:
54
+ typeof driver === "string" && /^[a-z][a-z0-9-]{0,39}$/.test(driver) ? driver : undefined,
55
+ // The usage limit the agent is not back from (ADR-0150): since when, and until when where the product said.
56
+ ...(since === undefined || typeof limited !== "object" || limited === null
57
+ ? {}
58
+ : {
59
+ limited: {
60
+ since,
61
+ until: "until" in limited ? momentOf(limited.until) : undefined,
62
+ },
63
+ }),
64
+ // The signals the record has as delivered that the agent never read: taken from the stream once more.
65
+ ...(Array.isArray(kept)
66
+ ? {
67
+ kept: kept
68
+ .filter((number): number is number => momentOf(number) !== undefined)
69
+ .slice(0, 50),
70
+ }
71
+ : {}),
72
+ // When the conversation kept began (ADR-0166): nothing for a file of before, or a number that
73
+ // is none. One ahead of the machine's clock is the runner's to hold to it, which knows the time.
74
+ ...(momentOf(began) === undefined ? {} : { began: momentOf(began) }),
75
+ // The kinds of output a driver had no reading for that a record says already (ADR-0182):
76
+ // each a line of the driver's own words, of printable ASCII, a few dozen at the most.
77
+ ...(Array.isArray(unknown)
78
+ ? {
79
+ unknown: unknown
80
+ .filter(
81
+ (what): what is string => typeof what === "string" && /^[ -~]{1,80}$/.test(what),
82
+ )
83
+ .slice(0, 32),
84
+ }
85
+ : {}),
86
+ // The console's version the agent was told a newer command exists for (ADR-0182): a version
87
+ // as the package spells one, or nothing.
88
+ ...(typeof newer === "string" && parseVersion(newer) !== undefined ? { newer } : {}),
89
+ };
90
+ }
91
+
92
+ /** How many names a wake source's file holds at the most, and how long a name and what stands under it may be. */
93
+ export const MAX_KEPT_NAMES = 2000;
94
+ const MAX_KEPT_LENGTH = 200;
95
+
96
+ /**
97
+ * What a wake source kept under a runner before this one (ADR-0166), as its file says it: the
98
+ * names it keeps with what stands under each, the oldest first, and nothing for a file that
99
+ * does not read. Read as data: a pair that is none, or longer than a name is, is left out, and
100
+ * no more is read than a source keeps. What a name and what stands under it mean is the
101
+ * source's own, which holds each to its shape when it starts.
102
+ */
103
+ export function keptBySourceOf(text: string | undefined): KeptBySource | undefined {
104
+ if (text === undefined) {
105
+ return undefined;
106
+ }
107
+ let json: unknown;
108
+ try {
109
+ json = JSON.parse(text);
110
+ } catch {
111
+ return undefined;
112
+ }
113
+ if (!Array.isArray(json)) {
114
+ return undefined;
115
+ }
116
+ const kept: [string, string][] = [];
117
+ for (const pair of json.slice(-MAX_KEPT_NAMES)) {
118
+ if (!Array.isArray(pair) || pair.length !== 2) {
119
+ continue;
120
+ }
121
+ const [name, value]: unknown[] = pair;
122
+ if (
123
+ typeof name === "string" &&
124
+ typeof value === "string" &&
125
+ name.length > 0 &&
126
+ name.length <= MAX_KEPT_LENGTH &&
127
+ value.length <= MAX_KEPT_LENGTH
128
+ ) {
129
+ kept.push([name, value]);
130
+ }
131
+ }
132
+ return kept;
133
+ }
134
+
135
+ /** What a wake source keeps, as its file holds it: the latest names, no more than are read back. */
136
+ export const keptFileOf = (kept: KeptBySource): string =>
137
+ `${JSON.stringify(kept.slice(-MAX_KEPT_NAMES))}\n`;
@@ -1,5 +1,5 @@
1
- import { randomInt } from "node:crypto";
2
- import { chmod, mkdir, readFile, rm, writeFile } from "node:fs/promises";
1
+ import { randomBytes, randomInt } from "node:crypto";
2
+ import { chmod, mkdir, readFile, rename, rm, writeFile } from "node:fs/promises";
3
3
  import { type as osType, release, userInfo } from "node:os";
4
4
  import { dirname, isAbsolute, join, relative, resolve } from "node:path";
5
5
  import process from "node:process";
@@ -24,6 +24,13 @@ export interface RunnerHost {
24
24
  readText(path: string): Promise<string | undefined>;
25
25
  /** Writes a file under the desk for its owner alone, its folders made on the way: a text, or bytes as they are. */
26
26
  writePrivate(path: string, value: string | Uint8Array): Promise<void>;
27
+ /**
28
+ * Puts a text in place of a file under the desk, for its owner alone, whole or not at all:
29
+ * written beside the file first and then given its name, so that a write cut short, by a
30
+ * crash or a machine that went down, leaves the file there was. For what the runner reads
31
+ * back when it starts: its state, and what each wake source keeps (ADR-0166).
32
+ */
33
+ replacePrivate(path: string, text: string): Promise<void>;
27
34
  /** Removes a file under the desk; one that is not there is removed already. */
28
35
  remove(path: string): Promise<void>;
29
36
  /** Opens a socket for a wake source: the messages of text it carries, until it closes. */
@@ -65,6 +72,31 @@ function alive(pid: number): boolean {
65
72
  }
66
73
  }
67
74
 
75
+ /** How many times a file is given its name where the system says the one there is in use, and how long between. */
76
+ const RENAME_TRIES = 5;
77
+ const RENAME_PAUSE_MS = 20;
78
+
79
+ /**
80
+ * Gives a file the name of another, in its place. On Windows the system refuses while anything
81
+ * else has the file there open, a scanner or the same write a moment before: tried again a few
82
+ * times, since such a hold lasts a moment.
83
+ */
84
+ async function takeName(from: string, to: string): Promise<void> {
85
+ for (let tries = 1; ; tries += 1) {
86
+ try {
87
+ await rename(from, to);
88
+ return;
89
+ } catch (error) {
90
+ const code =
91
+ typeof error === "object" && error !== null && "code" in error ? error.code : undefined;
92
+ if (tries >= RENAME_TRIES || (code !== "EPERM" && code !== "EBUSY" && code !== "EACCES")) {
93
+ throw error;
94
+ }
95
+ await new Promise((resolve) => setTimeout(resolve, RENAME_PAUSE_MS * tries));
96
+ }
97
+ }
98
+ }
99
+
68
100
  /**
69
101
  * The runner's host on this machine, in `cwd`, with `env` as what a product's process begins
70
102
  * from, and where a keeper names itself (`CONSOLE_RUNNER_KEEPER`).
@@ -117,6 +149,20 @@ export function createRunnerHost(
117
149
  // A file that was there keeps the mode it had: say it again.
118
150
  await chmod(full, 0o600);
119
151
  },
152
+ async replacePrivate(path, text) {
153
+ const full = under(path);
154
+ await mkdir(dirname(full), { recursive: true });
155
+ // Beside the file, so that giving it the name moves nothing from one volume to another;
156
+ // under a name of its own, so that two writes at once never share one.
157
+ const beside = `${full}.${randomBytes(6).toString("hex")}.tmp`;
158
+ try {
159
+ await writeFile(beside, text, { mode: 0o600, flag: "wx" });
160
+ await takeName(beside, full);
161
+ } catch (error) {
162
+ await rm(beside, { force: true }).catch(() => undefined);
163
+ throw error;
164
+ }
165
+ },
120
166
  async remove(path) {
121
167
  await rm(under(path), { force: true });
122
168
  },
@@ -0,0 +1,51 @@
1
+ import { parseAddress, parseSkillUri } from "@skillcdn/core/address";
2
+
3
+ // How a skill of a pack is named on the command line: by the path of its `SKILL.md`, by its
4
+ // folder, or by the URI the pack names it by. Apart from the pack the command prints
5
+ // (`pack.ts`), since a note on a skill names one too and reads no pack: this module takes the
6
+ // address scheme alone of the main repository's library, which loads next to nothing
7
+ // (ADR-0179).
8
+
9
+ /**
10
+ * The `SKILL.md` a path names: the path itself where it names one, else the one in the folder
11
+ * it names, since a skill is its folder and a listing cut short shows the folder alone; the
12
+ * root's own for the dot, as the root is everywhere.
13
+ */
14
+ function skillFileOf(given: string): string {
15
+ const path = given.replace(/\/+$/, "");
16
+ if (path === "" || path === ".") {
17
+ return "SKILL.md";
18
+ }
19
+ return path === "SKILL.md" || path.endsWith("/SKILL.md") ? path : `${path}/SKILL.md`;
20
+ }
21
+
22
+ /**
23
+ * A skill's path as given, or taken out of the URI the listing names it by
24
+ * (`skill://<host>/<owner>/<name>/<path>`); a URI of another pack would read this pack's skill
25
+ * at the same path, or nothing, so it is said instead.
26
+ */
27
+ export function skillPathIn(
28
+ given: string,
29
+ packAddress: string | null,
30
+ ): { readonly path: string } | { readonly error: string } {
31
+ const uri = parseSkillUri(given);
32
+ if (uri === undefined) {
33
+ return given.startsWith("skill://")
34
+ ? {
35
+ error: `Not a skill's URI the console knows: ${given}. Say the path of its SKILL.md from the repository's root, or the URI console skills lists.`,
36
+ }
37
+ : { path: skillFileOf(given) };
38
+ }
39
+ const pack = packAddress === null ? undefined : parseAddress(packAddress);
40
+ if (
41
+ pack?.ok === true &&
42
+ (uri.address.host !== pack.value.host ||
43
+ uri.address.owner !== pack.value.owner ||
44
+ uri.address.repo !== pack.value.repo)
45
+ ) {
46
+ return {
47
+ error: `That URI is of another pack, /${uri.address.host}/${uri.address.owner}/${uri.address.repo}; this project's pack is at ${packAddress}. Say the path of the SKILL.md, or a URI console skills lists.`,
48
+ };
49
+ }
50
+ return { path: uri.path };
51
+ }
package/src/client.ts CHANGED
@@ -24,6 +24,10 @@ import {
24
24
  type RestAgentSecret,
25
25
  type RestAgentSecretAccesses,
26
26
  type RestAgentSecretInput,
27
+ type RestAgentSecretOffer,
28
+ type RestAgentSecretOfferInput,
29
+ type RestAgentSecretOffers,
30
+ type RestAgentSecretOfferTakeInput,
27
31
  type RestAgentSecrets,
28
32
  type RestAgentSecretValue,
29
33
  type RestAgentSession,
@@ -79,6 +83,11 @@ import {
79
83
  type RestOwnWakes,
80
84
  type RestPackConnect,
81
85
  type RestPackConnectStarted,
86
+ type RestPackNote,
87
+ type RestPackNoteCloseInput,
88
+ type RestPackNoteInput,
89
+ type RestPackNoteLeft,
90
+ type RestPackNotes,
82
91
  type RestPackTokenInput,
83
92
  type RestPeople,
84
93
  type RestPerson,
@@ -163,6 +172,8 @@ import {
163
172
  restAgentProposalsSchema,
164
173
  restAgentSchema,
165
174
  restAgentSecretAccessesSchema,
175
+ restAgentSecretOfferSchema,
176
+ restAgentSecretOffersSchema,
166
177
  restAgentSecretSchema,
167
178
  restAgentSecretsSchema,
168
179
  restAgentSecretValueSchema,
@@ -199,6 +210,9 @@ import {
199
210
  restOwnWakesSchema,
200
211
  restPackConnectSchema,
201
212
  restPackConnectStartedSchema,
213
+ restPackNoteLeftSchema,
214
+ restPackNoteSchema,
215
+ restPackNotesSchema,
202
216
  restPeopleSchema,
203
217
  restPersonSchema,
204
218
  restPersonWorkBriefSchema,
@@ -798,6 +812,40 @@ export interface ConsoleClient {
798
812
  input: RestAgentSecretInput,
799
813
  ): Promise<RestAgentSecret>;
800
814
  removeAgentSecret(handle: string, name: string): Promise<void>;
815
+ /**
816
+ * A secret offered to an agent account (ADR-0169), by any member who sees it: kept sealed
817
+ * apart from its store until the account takes it or leaves it, and answered to nobody. The
818
+ * answer is the offer as its listing says it, never the value.
819
+ */
820
+ offerAgentSecret(handle: string, input: RestAgentSecretOfferInput): Promise<RestAgentSecretOffer>;
821
+ /** The account's record of what it was offered, the newest first, for a supervisor: never a value. */
822
+ agentSecretOffers(handle: string, signal?: AbortSignal): Promise<RestAgentSecretOffers>;
823
+ /**
824
+ * What the account itself was offered and has not taken or left, on a session of its own; one
825
+ * taken into its store, under the name offered or another; one left.
826
+ */
827
+ secretOffers(signal?: AbortSignal): Promise<RestAgentSecretOffers>;
828
+ takeSecretOffer(id: string, input?: RestAgentSecretOfferTakeInput): Promise<RestAgentSecret>;
829
+ leaveSecretOffer(id: string): Promise<void>;
830
+ /**
831
+ * The notes on the pack (ADR-0178). One left, by any member, for whoever keeps the pack: on a
832
+ * skill or a page by its path, or with no path for a job no skill fit. The notes the asker
833
+ * reads: everyone's for the keeper and an administrator, their own for anyone else. One
834
+ * closed, with what became of it: by the keeper or an administrator, or by its author, who
835
+ * takes it back.
836
+ */
837
+ leavePackNote(input: RestPackNoteInput): Promise<RestPackNoteLeft>;
838
+ packNotes(
839
+ query?: {
840
+ readonly state?: "open" | "all" | undefined;
841
+ readonly mine?: boolean | undefined;
842
+ readonly path?: string | undefined;
843
+ readonly limit?: number | undefined;
844
+ readonly offset?: number | undefined;
845
+ },
846
+ signal?: AbortSignal,
847
+ ): Promise<RestPackNotes>;
848
+ closePackNote(id: string, input: RestPackNoteCloseInput): Promise<RestPackNote>;
801
849
  /** The invitation that leads a machine to an agent account (ADR-0088), as it stands; for a supervisor. */
802
850
  agentInvitation(handle: string, signal?: AbortSignal): Promise<RestAgentInvitationState>;
803
851
  /** Makes the invitation, in place of the one there was: the code this once, and the command to run with it. */
@@ -1742,6 +1790,61 @@ export function createClient(options: ClientOptions = {}): ConsoleClient {
1742
1790
  request("PUT", `${base}${agentPath(handle, "secrets", name)}`, input, restAgentSecretSchema),
1743
1791
  removeAgentSecret: (handle, name) =>
1744
1792
  request("DELETE", `${base}${agentPath(handle, "secrets", name)}`, undefined, undefined),
1793
+ offerAgentSecret: (handle, input) =>
1794
+ request(
1795
+ "POST",
1796
+ `${base}${agentPath(handle, "secret-offers")}`,
1797
+ input,
1798
+ restAgentSecretOfferSchema,
1799
+ ),
1800
+ agentSecretOffers: (handle, signal) =>
1801
+ request(
1802
+ "GET",
1803
+ `${base}${agentPath(handle, "secret-offers")}`,
1804
+ undefined,
1805
+ restAgentSecretOffersSchema,
1806
+ signal,
1807
+ ),
1808
+ secretOffers: (signal) =>
1809
+ request(
1810
+ "GET",
1811
+ `${base}${agentPath("me", "secret-offers")}`,
1812
+ undefined,
1813
+ restAgentSecretOffersSchema,
1814
+ signal,
1815
+ ),
1816
+ takeSecretOffer: (id, input) =>
1817
+ request(
1818
+ "POST",
1819
+ `${base}${agentPath("me", "secret-offers", id, "take")}`,
1820
+ input ?? {},
1821
+ restAgentSecretSchema,
1822
+ ),
1823
+ leaveSecretOffer: (id) =>
1824
+ request("DELETE", `${base}${agentPath("me", "secret-offers", id)}`, undefined, undefined),
1825
+ leavePackNote: (input) =>
1826
+ request("POST", `${base}${REST_ROUTES.packNotes}`, input, restPackNoteLeftSchema),
1827
+ packNotes: (query, signal) =>
1828
+ request(
1829
+ "GET",
1830
+ withQuery(REST_ROUTES.packNotes, {
1831
+ state: query?.state,
1832
+ mine: query?.mine === true ? "true" : undefined,
1833
+ path: query?.path,
1834
+ limit: query?.limit === undefined ? undefined : String(query.limit),
1835
+ offset: query?.offset === undefined ? undefined : String(query.offset),
1836
+ }),
1837
+ undefined,
1838
+ restPackNotesSchema,
1839
+ signal,
1840
+ ),
1841
+ closePackNote: (id, input) =>
1842
+ request(
1843
+ "POST",
1844
+ `${base}${REST_ROUTES.packNotes}/${encodeURIComponent(id)}/close`,
1845
+ input,
1846
+ restPackNoteSchema,
1847
+ ),
1745
1848
  agentSecretAccesses: (handle, query, signal) =>
1746
1849
  request(
1747
1850
  "GET",