@skillcdn/console 0.6.2 → 0.6.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 (179) hide show
  1. package/README.md +13 -6
  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 +40 -3
  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 +4 -3
  12. package/dist/api.d.ts.map +1 -1
  13. package/dist/api.js +4 -3
  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 +304 -130
  18. package/dist/cli/cli.js.map +1 -1
  19. package/dist/cli/format.d.ts +13 -4
  20. package/dist/cli/format.d.ts.map +1 -1
  21. package/dist/cli/format.js +43 -9
  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 +780 -318
  26. package/dist/cli/help.js.map +1 -1
  27. package/dist/cli/pack.d.ts +2 -2
  28. package/dist/cli/pack.d.ts.map +1 -1
  29. package/dist/cli/pack.js +6 -4
  30. package/dist/cli/pack.js.map +1 -1
  31. package/dist/cli/runner-files.d.ts +16 -0
  32. package/dist/cli/runner-files.d.ts.map +1 -0
  33. package/dist/cli/runner-files.js +110 -0
  34. package/dist/cli/runner-files.js.map +1 -0
  35. package/dist/cli/runner-host.d.ts +7 -0
  36. package/dist/cli/runner-host.d.ts.map +1 -1
  37. package/dist/cli/runner-host.js +40 -2
  38. package/dist/cli/runner-host.js.map +1 -1
  39. package/dist/client.d.ts +16 -1
  40. package/dist/client.d.ts.map +1 -1
  41. package/dist/client.js +6 -1
  42. package/dist/client.js.map +1 -1
  43. package/dist/components/agent-page.d.ts +28 -3
  44. package/dist/components/agent-page.d.ts.map +1 -1
  45. package/dist/components/agent-page.js +48 -3
  46. package/dist/components/agent-page.js.map +1 -1
  47. package/dist/components/agents.d.ts +3 -2
  48. package/dist/components/agents.d.ts.map +1 -1
  49. package/dist/components/agents.js +9 -3
  50. package/dist/components/agents.js.map +1 -1
  51. package/dist/console.d.ts.map +1 -1
  52. package/dist/console.js +1 -1
  53. package/dist/console.js.map +1 -1
  54. package/dist/feed-words.d.ts.map +1 -1
  55. package/dist/feed-words.js +12 -1
  56. package/dist/feed-words.js.map +1 -1
  57. package/dist/i18n/en.d.ts +45 -1
  58. package/dist/i18n/en.d.ts.map +1 -1
  59. package/dist/i18n/en.js +36 -1
  60. package/dist/i18n/en.js.map +1 -1
  61. package/dist/i18n/ko.d.ts.map +1 -1
  62. package/dist/i18n/ko.js +28 -0
  63. package/dist/i18n/ko.js.map +1 -1
  64. package/dist/limits.d.ts +10 -0
  65. package/dist/limits.d.ts.map +1 -1
  66. package/dist/limits.js +10 -0
  67. package/dist/limits.js.map +1 -1
  68. package/dist/plugin/context.d.ts +39 -7
  69. package/dist/plugin/context.d.ts.map +1 -1
  70. package/dist/runner/acp.d.ts.map +1 -1
  71. package/dist/runner/acp.js +9 -3
  72. package/dist/runner/acp.js.map +1 -1
  73. package/dist/runner/claude.d.ts.map +1 -1
  74. package/dist/runner/claude.js +5 -1
  75. package/dist/runner/claude.js.map +1 -1
  76. package/dist/runner/codex.d.ts.map +1 -1
  77. package/dist/runner/codex.js +14 -2
  78. package/dist/runner/codex.js.map +1 -1
  79. package/dist/runner/config.d.ts +18 -0
  80. package/dist/runner/config.d.ts.map +1 -1
  81. package/dist/runner/config.js +77 -1
  82. package/dist/runner/config.js.map +1 -1
  83. package/dist/runner/desk.d.ts +7 -0
  84. package/dist/runner/desk.d.ts.map +1 -1
  85. package/dist/runner/desk.js +9 -0
  86. package/dist/runner/desk.js.map +1 -1
  87. package/dist/runner/message.d.ts +16 -22
  88. package/dist/runner/message.d.ts.map +1 -1
  89. package/dist/runner/message.js +72 -120
  90. package/dist/runner/message.js.map +1 -1
  91. package/dist/runner/runner.d.ts +25 -1
  92. package/dist/runner/runner.d.ts.map +1 -1
  93. package/dist/runner/runner.js +404 -19
  94. package/dist/runner/runner.js.map +1 -1
  95. package/dist/runner/slack-status.d.ts +19 -0
  96. package/dist/runner/slack-status.d.ts.map +1 -0
  97. package/dist/runner/slack-status.js +332 -0
  98. package/dist/runner/slack-status.js.map +1 -0
  99. package/dist/runner/slack.d.ts.map +1 -1
  100. package/dist/runner/slack.js +245 -57
  101. package/dist/runner/slack.js.map +1 -1
  102. package/dist/runner/types.d.ts +109 -15
  103. package/dist/runner/types.d.ts.map +1 -1
  104. package/dist/runner/types.js.map +1 -1
  105. package/dist/runner/usage.d.ts +6 -1
  106. package/dist/runner/usage.d.ts.map +1 -1
  107. package/dist/runner/usage.js +9 -2
  108. package/dist/runner/usage.js.map +1 -1
  109. package/dist/runner.d.ts +2 -2
  110. package/dist/runner.d.ts.map +1 -1
  111. package/dist/runner.js.map +1 -1
  112. package/dist/schemas.d.ts +160 -1
  113. package/dist/schemas.d.ts.map +1 -1
  114. package/dist/schemas.js +82 -5
  115. package/dist/schemas.js.map +1 -1
  116. package/dist/vocabulary.d.ts +7 -0
  117. package/dist/vocabulary.d.ts.map +1 -1
  118. package/dist/vocabulary.js +6 -0
  119. package/dist/vocabulary.js.map +1 -1
  120. package/dist/wake-text.d.ts +43 -0
  121. package/dist/wake-text.d.ts.map +1 -0
  122. package/dist/wake-text.js +115 -0
  123. package/dist/wake-text.js.map +1 -0
  124. package/docs/specs/cli.md +19 -11
  125. package/docs/specs/plugins.md +5 -5
  126. package/docs/specs/rest.md +10 -3
  127. package/docs/specs/runner.md +96 -20
  128. package/docs/start.md +26 -5
  129. package/package.json +3 -3
  130. package/skills/building-a-plugin/SKILL.md +2 -2
  131. package/skills/deploying-a-console/SKILL.md +3 -3
  132. package/skills/deploying-a-console/references/access.md +15 -1
  133. package/skills/deploying-a-console/references/resources.md +2 -2
  134. package/skills/deploying-a-console/scripts/github-app.mjs +593 -0
  135. package/skills/running-an-agent/SKILL.md +13 -10
  136. package/skills/running-an-agent/references/preparing-the-machine.md +1 -1
  137. package/skills/running-an-agent/references/slack-app.md +25 -8
  138. package/skills/running-an-agent/references/the-account-and-the-invitation.md +1 -1
  139. package/skills/running-an-agent/references/what-was-not-seen-run-yet.md +1 -1
  140. package/skills/running-an-agent/references/when-the-agent-could-not-go-on.md +1 -1
  141. package/skills/running-an-agent/references/your-first-task.md +7 -2
  142. package/skills/trying-a-console/SKILL.md +136 -0
  143. package/skills/trying-a-console/references/when-it-does-not-go.md +30 -0
  144. package/skills/working-the-board/SKILL.md +3 -3
  145. package/skills/working-the-board/references/the-pack.md +3 -3
  146. package/skills/working-the-board/references/what-they-were-told.md +1 -1
  147. package/src/agent-page.tsx +92 -1
  148. package/src/agent-state.ts +33 -0
  149. package/src/api.ts +16 -0
  150. package/src/cli/cli.ts +359 -137
  151. package/src/cli/format.ts +49 -9
  152. package/src/cli/help.ts +904 -359
  153. package/src/cli/pack.ts +6 -4
  154. package/src/cli/runner-files.ts +120 -0
  155. package/src/cli/runner-host.ts +48 -2
  156. package/src/client.ts +53 -0
  157. package/src/components/agent-page.tsx +150 -3
  158. package/src/components/agents.tsx +20 -5
  159. package/src/console.tsx +1 -0
  160. package/src/feed-words.ts +14 -1
  161. package/src/i18n/en.ts +39 -1
  162. package/src/i18n/ko.ts +32 -0
  163. package/src/limits.ts +10 -0
  164. package/src/plugin/context.ts +40 -7
  165. package/src/runner/acp.ts +9 -3
  166. package/src/runner/claude.ts +5 -1
  167. package/src/runner/codex.ts +14 -2
  168. package/src/runner/config.ts +114 -1
  169. package/src/runner/desk.ts +10 -0
  170. package/src/runner/message.ts +88 -126
  171. package/src/runner/runner.ts +487 -22
  172. package/src/runner/slack-status.ts +423 -0
  173. package/src/runner/slack.ts +293 -61
  174. package/src/runner/types.ts +108 -13
  175. package/src/runner/usage.ts +16 -3
  176. package/src/runner.ts +4 -0
  177. package/src/schemas.ts +97 -3
  178. package/src/vocabulary.ts +9 -0
  179. package/src/wake-text.ts +133 -0
package/src/cli/pack.ts CHANGED
@@ -216,8 +216,10 @@ function listingOf(
216
216
  commit: mount.commit,
217
217
  items: items.slice(from, end),
218
218
  diagnostics: index.diagnostics,
219
- // The counts stand in the instructions above the first page.
220
- totals: null,
219
+ // The listing the command prints is of the skills alone (SkillCDN 0.6.3): the documents
220
+ // outside them are counted from these, with what reads them, and a page that ends before
221
+ // the skills do says how many are left.
222
+ totals: { skills: index.skills.length, documents: index.documents.length },
221
223
  nextCursor: end < items.length ? listingCursor(end, mount.commit) : null,
222
224
  };
223
225
  }
@@ -399,8 +401,8 @@ export function consolePack(
399
401
 
400
402
  /**
401
403
  * 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,
404
+ * skillcdn command prints for it, what a client is told on connect and then every skill, the
405
+ * documents counted, between the lines of the console's own: where the pack is and how it answered,
404
406
  * where a person connects an agent of their own, and where the console's own skills are on this
405
407
  * machine. Where it did not, why, with that last line still.
406
408
  */
@@ -0,0 +1,120 @@
1
+ import type { KeptBySource, RunnerState } from "../runner/runner.js";
2
+
3
+ // The runner's own files under the desk's `work/`, as `console runner` reads them back and
4
+ // writes them (ADR-0085, ADR-0166): its state between its own restarts, and what each wake
5
+ // source keeps. A file of the desk may hold anything, whatever wrote it: what is read of one is
6
+ // data, bounded, and nothing where it does not read.
7
+
8
+ /** What the runner keeps between its own restarts, as its file says it; nothing for a file that does not read. */
9
+ export function runnerStateOf(text: string | undefined): RunnerState | undefined {
10
+ if (text === undefined) {
11
+ return undefined;
12
+ }
13
+ let json: unknown;
14
+ try {
15
+ json = JSON.parse(text);
16
+ } catch {
17
+ return undefined;
18
+ }
19
+ if (typeof json !== "object" || json === null) {
20
+ return undefined;
21
+ }
22
+ const delivered = "delivered" in json ? json.delivered : undefined;
23
+ const conversation = "conversation" in json ? json.conversation : undefined;
24
+ const driver = "driver" in json ? json.driver : undefined;
25
+ const limited = "limited" in json ? json.limited : undefined;
26
+ const kept: unknown = "kept" in json ? json.kept : undefined;
27
+ const began: unknown = "began" in json ? json.began : undefined;
28
+ if (typeof delivered !== "number" || !Number.isSafeInteger(delivered) || delivered < 0) {
29
+ return undefined;
30
+ }
31
+ /**
32
+ * A moment in milliseconds since the epoch, or nothing for anything else: a number past what
33
+ * a date holds would fail the runner at every start, where it says the moment in words.
34
+ */
35
+ const momentOf = (value: unknown): number | undefined =>
36
+ typeof value === "number" && Number.isSafeInteger(value) && value > 0 && value < 1e14
37
+ ? value
38
+ : undefined;
39
+ const since =
40
+ typeof limited === "object" && limited !== null && "since" in limited
41
+ ? momentOf(limited.since)
42
+ : undefined;
43
+ return {
44
+ delivered,
45
+ conversation:
46
+ typeof conversation === "string" && conversation.length > 0 && conversation.length <= 200
47
+ ? conversation
48
+ : undefined,
49
+ // The driver the conversation was begun under, as a registry spells one.
50
+ driver:
51
+ typeof driver === "string" && /^[a-z][a-z0-9-]{0,39}$/.test(driver) ? driver : undefined,
52
+ // The usage limit the agent is not back from (ADR-0150): since when, and until when where the product said.
53
+ ...(since === undefined || typeof limited !== "object" || limited === null
54
+ ? {}
55
+ : {
56
+ limited: {
57
+ since,
58
+ until: "until" in limited ? momentOf(limited.until) : undefined,
59
+ },
60
+ }),
61
+ // The signals the record has as delivered that the agent never read: taken from the stream once more.
62
+ ...(Array.isArray(kept)
63
+ ? {
64
+ kept: kept
65
+ .filter((number): number is number => momentOf(number) !== undefined)
66
+ .slice(0, 50),
67
+ }
68
+ : {}),
69
+ // When the conversation kept began (ADR-0166): nothing for a file of before, or a number that
70
+ // is none. One ahead of the machine's clock is the runner's to hold to it, which knows the time.
71
+ ...(momentOf(began) === undefined ? {} : { began: momentOf(began) }),
72
+ };
73
+ }
74
+
75
+ /** How many names a wake source's file holds at the most, and how long a name and what stands under it may be. */
76
+ export const MAX_KEPT_NAMES = 2000;
77
+ const MAX_KEPT_LENGTH = 200;
78
+
79
+ /**
80
+ * What a wake source kept under a runner before this one (ADR-0166), as its file says it: the
81
+ * names it keeps with what stands under each, the oldest first, and nothing for a file that
82
+ * does not read. Read as data: a pair that is none, or longer than a name is, is left out, and
83
+ * no more is read than a source keeps. What a name and what stands under it mean is the
84
+ * source's own, which holds each to its shape when it starts.
85
+ */
86
+ export function keptBySourceOf(text: string | undefined): KeptBySource | undefined {
87
+ if (text === undefined) {
88
+ return undefined;
89
+ }
90
+ let json: unknown;
91
+ try {
92
+ json = JSON.parse(text);
93
+ } catch {
94
+ return undefined;
95
+ }
96
+ if (!Array.isArray(json)) {
97
+ return undefined;
98
+ }
99
+ const kept: [string, string][] = [];
100
+ for (const pair of json.slice(-MAX_KEPT_NAMES)) {
101
+ if (!Array.isArray(pair) || pair.length !== 2) {
102
+ continue;
103
+ }
104
+ const [name, value]: unknown[] = pair;
105
+ if (
106
+ typeof name === "string" &&
107
+ typeof value === "string" &&
108
+ name.length > 0 &&
109
+ name.length <= MAX_KEPT_LENGTH &&
110
+ value.length <= MAX_KEPT_LENGTH
111
+ ) {
112
+ kept.push([name, value]);
113
+ }
114
+ }
115
+ return kept;
116
+ }
117
+
118
+ /** What a wake source keeps, as its file holds it: the latest names, no more than are read back. */
119
+ export const keptFileOf = (kept: KeptBySource): string =>
120
+ `${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
  },
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,
@@ -163,6 +167,8 @@ import {
163
167
  restAgentProposalsSchema,
164
168
  restAgentSchema,
165
169
  restAgentSecretAccessesSchema,
170
+ restAgentSecretOfferSchema,
171
+ restAgentSecretOffersSchema,
166
172
  restAgentSecretSchema,
167
173
  restAgentSecretsSchema,
168
174
  restAgentSecretValueSchema,
@@ -798,6 +804,21 @@ export interface ConsoleClient {
798
804
  input: RestAgentSecretInput,
799
805
  ): Promise<RestAgentSecret>;
800
806
  removeAgentSecret(handle: string, name: string): Promise<void>;
807
+ /**
808
+ * A secret offered to an agent account (ADR-0169), by any member who sees it: kept sealed
809
+ * apart from its store until the account takes it or leaves it, and answered to nobody. The
810
+ * answer is the offer as its listing says it, never the value.
811
+ */
812
+ offerAgentSecret(handle: string, input: RestAgentSecretOfferInput): Promise<RestAgentSecretOffer>;
813
+ /** The account's record of what it was offered, the newest first, for a supervisor: never a value. */
814
+ agentSecretOffers(handle: string, signal?: AbortSignal): Promise<RestAgentSecretOffers>;
815
+ /**
816
+ * What the account itself was offered and has not taken or left, on a session of its own; one
817
+ * taken into its store, under the name offered or another; one left.
818
+ */
819
+ secretOffers(signal?: AbortSignal): Promise<RestAgentSecretOffers>;
820
+ takeSecretOffer(id: string, input?: RestAgentSecretOfferTakeInput): Promise<RestAgentSecret>;
821
+ leaveSecretOffer(id: string): Promise<void>;
801
822
  /** The invitation that leads a machine to an agent account (ADR-0088), as it stands; for a supervisor. */
802
823
  agentInvitation(handle: string, signal?: AbortSignal): Promise<RestAgentInvitationState>;
803
824
  /** Makes the invitation, in place of the one there was: the code this once, and the command to run with it. */
@@ -1742,6 +1763,38 @@ export function createClient(options: ClientOptions = {}): ConsoleClient {
1742
1763
  request("PUT", `${base}${agentPath(handle, "secrets", name)}`, input, restAgentSecretSchema),
1743
1764
  removeAgentSecret: (handle, name) =>
1744
1765
  request("DELETE", `${base}${agentPath(handle, "secrets", name)}`, undefined, undefined),
1766
+ offerAgentSecret: (handle, input) =>
1767
+ request(
1768
+ "POST",
1769
+ `${base}${agentPath(handle, "secret-offers")}`,
1770
+ input,
1771
+ restAgentSecretOfferSchema,
1772
+ ),
1773
+ agentSecretOffers: (handle, signal) =>
1774
+ request(
1775
+ "GET",
1776
+ `${base}${agentPath(handle, "secret-offers")}`,
1777
+ undefined,
1778
+ restAgentSecretOffersSchema,
1779
+ signal,
1780
+ ),
1781
+ secretOffers: (signal) =>
1782
+ request(
1783
+ "GET",
1784
+ `${base}${agentPath("me", "secret-offers")}`,
1785
+ undefined,
1786
+ restAgentSecretOffersSchema,
1787
+ signal,
1788
+ ),
1789
+ takeSecretOffer: (id, input) =>
1790
+ request(
1791
+ "POST",
1792
+ `${base}${agentPath("me", "secret-offers", id, "take")}`,
1793
+ input ?? {},
1794
+ restAgentSecretSchema,
1795
+ ),
1796
+ leaveSecretOffer: (id) =>
1797
+ request("DELETE", `${base}${agentPath("me", "secret-offers", id)}`, undefined, undefined),
1745
1798
  agentSecretAccesses: (handle, query, signal) =>
1746
1799
  request(
1747
1800
  "GET",
@@ -9,20 +9,26 @@ import {
9
9
  useRef,
10
10
  useState,
11
11
  } from "react";
12
+ import { reasonMoment } from "../agent-state.js";
12
13
  import {
13
14
  type AgentState,
14
15
  type FileUpload,
16
+ isSecretName,
17
+ MAX_AGENT_SECRET_NAME_LENGTH,
15
18
  MAX_FILE_BYTES,
19
+ MAX_SECRET_OFFER_NOTE_LENGTH,
16
20
  MAX_SIGNAL_ATTACHMENTS,
17
21
  MAX_SIGNAL_LENGTH,
18
22
  type RestAgent,
19
23
  type RestAgentRunner,
20
24
  type RestAgentSecret,
25
+ type RestAgentSecretOffer,
21
26
  type RestAgentSession,
22
27
  type RestAgentUsageWindow,
23
28
  type RestPerson,
24
29
  type RestSignal,
25
30
  type RestTranscriptEvent,
31
+ SECRET_OFFER_DAYS,
26
32
  usageNear,
27
33
  usageSaidTogether,
28
34
  usedHundredths,
@@ -123,10 +129,14 @@ export function AgentUsage(props: {
123
129
  );
124
130
  }
125
131
 
126
- /** The state of an agent account as a badge: the word, and why and since when where there is room. */
132
+ /**
133
+ * The state of an agent account as a badge: the word, and where there is room since when it
134
+ * stands so, right after the word it is the moment of, then why, with when that was said where
135
+ * it is another moment than the state's.
136
+ */
127
137
  export function AgentStateBadge(props: {
128
138
  readonly state: RestAgent["state"];
129
- /** With why it stands so, since when, and when its runner was last heard from. */
139
+ /** With since when it stands so, why, and when its runner was last heard from. */
130
140
  readonly full?: boolean | undefined;
131
141
  }) {
132
142
  const words = useWords().agents.page.state;
@@ -145,6 +155,7 @@ export function AgentStateBadge(props: {
145
155
  }
146
156
  const reasons: Readonly<Record<string, string>> = words.reasons;
147
157
  const reason = state.reason === null ? undefined : (reasons[state.reason] ?? state.reason);
158
+ const said = reasonMoment(state);
148
159
  const badge = (
149
160
  <Badge
150
161
  tone={STATE_TONES[state.state]}
@@ -162,7 +173,6 @@ export function AgentStateBadge(props: {
162
173
  <span className="sc-agent-state">
163
174
  {badge}
164
175
  <span className="sc-note">
165
- {reason !== undefined && `${reason} · `}
166
176
  {words.since.before}
167
177
  <Time iso={state.since} precision="clock" />
168
178
  {words.since.after}
@@ -174,6 +184,19 @@ export function AgentStateBadge(props: {
174
184
  {words.until.after}
175
185
  </>
176
186
  )}
187
+ {reason !== undefined && (
188
+ <>
189
+ {" · "}
190
+ {reason}
191
+ {said !== undefined && (
192
+ <>
193
+ {words.reasonAt.before}
194
+ <Time iso={said} precision="clock" />
195
+ {words.reasonAt.after}
196
+ </>
197
+ )}
198
+ </>
199
+ )}
177
200
  {state.heardAt !== null && (
178
201
  <>
179
202
  {" · "}
@@ -2603,6 +2626,130 @@ export function AgentElsewhereList(props: {
2603
2626
  );
2604
2627
  }
2605
2628
 
2629
+ export interface AgentSecretOfferListProps {
2630
+ readonly offers: readonly RestAgentSecretOffer[];
2631
+ }
2632
+
2633
+ /** What a secret offered to an account stands as, in the tone a badge says it in. */
2634
+ const OFFER_TONES = {
2635
+ waiting: "accent",
2636
+ taken: "success",
2637
+ left: "neutral",
2638
+ lapsed: "neutral",
2639
+ } as const;
2640
+
2641
+ /**
2642
+ * The secrets offered to an agent account (ADR-0169), a row each: the name proposed, who offers
2643
+ * it and when, and how the offer stands. Never a value.
2644
+ */
2645
+ export function AgentSecretOfferList(props: AgentSecretOfferListProps) {
2646
+ const words = useWords().agents.page.offers;
2647
+ return (
2648
+ <ul className="sc-divided sc-agent-secret-list" aria-label={words.title}>
2649
+ {props.offers.map((offer) => (
2650
+ <li key={offer.id} className="sc-small sc-agent-secret">
2651
+ <code>{offer.name}</code>
2652
+ <span className="sc-muted">
2653
+ {offer.by === null ? words.someone : personName(offer.by)}
2654
+ {" · "}
2655
+ <Time iso={offer.at} precision="day" />
2656
+ {offer.takenAs !== null && offer.takenAs !== offer.name && (
2657
+ <>
2658
+ {" · "}
2659
+ {words.takenAs(offer.takenAs)}
2660
+ </>
2661
+ )}
2662
+ </span>
2663
+ <Badge tone={OFFER_TONES[offer.state]} kind="state">
2664
+ {words.state[offer.state]}
2665
+ </Badge>
2666
+ </li>
2667
+ ))}
2668
+ </ul>
2669
+ );
2670
+ }
2671
+
2672
+ export interface AgentSecretOfferFormProps {
2673
+ /** What the account is called, for the line that says what becomes of an offer. */
2674
+ readonly account: string;
2675
+ readonly busy?: boolean | undefined;
2676
+ /** Offers a secret: the account takes it or leaves it, and nobody reads the value back. */
2677
+ readonly onOffer: (offer: {
2678
+ readonly name: string;
2679
+ readonly value: string;
2680
+ readonly note: string | undefined;
2681
+ }) => void;
2682
+ }
2683
+
2684
+ /** The way a member offers an agent account a secret (ADR-0169): its name, its value, typed unseen, and what it is for. */
2685
+ export function AgentSecretOfferForm(props: AgentSecretOfferFormProps) {
2686
+ const words = useWords().agents.page.offers;
2687
+ const [name, setName] = useState("");
2688
+ const [value, setValue] = useState("");
2689
+ const [note, setNote] = useState("");
2690
+ const busy = props.busy === true;
2691
+ const ready = isSecretName(name.trim()) && value.length > 0;
2692
+ const submit = (event: FormEvent) => {
2693
+ event.preventDefault();
2694
+ if (!ready || busy) {
2695
+ return;
2696
+ }
2697
+ props.onOffer({
2698
+ name: name.trim(),
2699
+ value,
2700
+ note: note.trim().length === 0 ? undefined : note.trim(),
2701
+ });
2702
+ setName("");
2703
+ setValue("");
2704
+ setNote("");
2705
+ };
2706
+ return (
2707
+ <form className="sc-form" aria-label={words.offerAria} onSubmit={submit}>
2708
+ <div className="sc-field-row">
2709
+ <label className="sc-field">
2710
+ <span className="sc-field-label">{words.name}</span>
2711
+ <input
2712
+ className="sc-input"
2713
+ placeholder={words.namePlaceholder}
2714
+ value={name}
2715
+ maxLength={MAX_AGENT_SECRET_NAME_LENGTH}
2716
+ autoComplete="off"
2717
+ spellCheck={false}
2718
+ aria-invalid={name.trim() !== "" && !isSecretName(name.trim())}
2719
+ onChange={(event) => setName(event.target.value.toLowerCase())}
2720
+ />
2721
+ </label>
2722
+ <label className="sc-field">
2723
+ <span className="sc-field-label">{words.value}</span>
2724
+ <input
2725
+ className="sc-input"
2726
+ type="password"
2727
+ value={value}
2728
+ autoComplete="new-password"
2729
+ onChange={(event) => setValue(event.target.value)}
2730
+ />
2731
+ </label>
2732
+ </div>
2733
+ <label className="sc-field">
2734
+ <span className="sc-field-label">{words.note}</span>
2735
+ <input
2736
+ className="sc-input"
2737
+ value={note}
2738
+ maxLength={MAX_SECRET_OFFER_NOTE_LENGTH}
2739
+ autoComplete="off"
2740
+ onChange={(event) => setNote(event.target.value)}
2741
+ />
2742
+ </label>
2743
+ <p className="sc-field-hint">{words.intro(props.account, SECRET_OFFER_DAYS)}</p>
2744
+ <div className="sc-form-actions">
2745
+ <Button type="submit" variant="primary" disabled={busy || !ready}>
2746
+ {words.offer}
2747
+ </Button>
2748
+ </div>
2749
+ </form>
2750
+ );
2751
+ }
2752
+
2606
2753
  export interface AgentSecretListProps {
2607
2754
  readonly secrets: readonly RestAgentSecret[];
2608
2755
  readonly busy?: boolean | undefined;
@@ -1,4 +1,5 @@
1
1
  import { type FormEvent, useContext, useEffect, useState } from "react";
2
+ import { reasonMoment } from "../agent-state.js";
2
3
  import {
3
4
  hostOfLogin,
4
5
  isHandle,
@@ -122,8 +123,9 @@ export interface AgentAccountListProps {
122
123
 
123
124
  /**
124
125
  * Agent accounts, a card each, for whoever looks after several: the picture, the name with the
125
- * handle and what it does, and across from them how it stands; then what it is doing now and
126
- * since when, what it runs, and whom it reports to where that is someone else. Rows of one
126
+ * handle and what it does, and across from them how it stands; then why it stands so, with
127
+ * when that was said where it is another moment than the state's, and under it the state with
128
+ * since when it stands; what it runs, and whom it reports to where that is someone else. Rows of one
127
129
  * shape, so that the cards read alike down a column. The whole card leads to the account's
128
130
  * page; what is kept of the account, the login it signs in with among it, is said there.
129
131
  */
@@ -144,6 +146,10 @@ export function AgentAccountList(props: AgentAccountListProps) {
144
146
  const invited = person.invited === true;
145
147
  const title = person.title ?? "";
146
148
  const state = agent.state ?? null;
149
+ // The reason has a moment of its own where it was said under a state that stayed; the
150
+ // state's moment is said with the state's word, so that neither reads as the other's.
151
+ const said = state === null ? undefined : reasonMoment(state);
152
+ const stood = state === null ? undefined : states.sinceAs(states[state.state]);
147
153
  const product = agent.runner?.product ?? null;
148
154
  const usage = usageStanding(agent.usage, props.now ?? Date.now());
149
155
  const model = agent.runner?.running?.model ?? agent.runner?.settings.model ?? null;
@@ -192,12 +198,21 @@ export function AgentAccountList(props: AgentAccountListProps) {
192
198
  ) : (
193
199
  <span className="sc-agent-card-now">
194
200
  {state.reason !== null && (
195
- <span>{reasons[state.reason] ?? state.reason}</span>
201
+ <span>
202
+ {reasons[state.reason] ?? state.reason}
203
+ {said !== undefined && (
204
+ <span className="sc-muted">
205
+ {states.reasonAt.before}
206
+ <Time iso={said} precision="clock" />
207
+ {states.reasonAt.after}
208
+ </span>
209
+ )}
210
+ </span>
196
211
  )}
197
212
  <span className="sc-muted">
198
- {states.since.before}
213
+ {stood?.before}
199
214
  <Time iso={state.since} precision="clock" />
200
- {states.since.after}
215
+ {stood?.after}
201
216
  {state.until !== undefined && state.until !== null && (
202
217
  <>
203
218
  {" · "}
package/src/console.tsx CHANGED
@@ -3586,6 +3586,7 @@ function WorkspacePage(props: {
3586
3586
  client={client}
3587
3587
  viaToken={holdsToken(data)}
3588
3588
  providers={data.me?.signIn}
3589
+ me={data.me?.person?.id}
3589
3590
  work={(agent) => (
3590
3591
  <AgentWork agent={agent} data={data} components={components} week={route.week} />
3591
3592
  )}
package/src/feed-words.ts CHANGED
@@ -1,10 +1,17 @@
1
1
  import { en, type Messages } from "./i18n/en.js";
2
2
  import type { RestEvent } from "./schemas.js";
3
+ import type { AgentState, AgentStateReason } from "./vocabulary.js";
3
4
 
4
5
  // What an event of the feed says, as a sentence a person reads at a glance, in a language's
5
6
  // words (ADR-0012). Apart from the component that shows the feed, which is a page's, so that
6
7
  // the command says an event in the same sentence and loads nothing of a page for it.
7
8
 
9
+ /** The reason that says no more than the sentence of its state does, and is not said after it. */
10
+ const SAID_BY_THE_STATE: Readonly<Partial<Record<AgentState, AgentStateReason>>> = {
11
+ refused: "model_refused",
12
+ unheard: "no_heartbeat",
13
+ };
14
+
8
15
  /** What an event says, without its actor: the words after the name, in the words given; a board's event a plugin caused says so (ADR-0052). */
9
16
  export function describeEvent(event: RestEvent, words: Messages = en): string {
10
17
  const sentence = sentenceOf(event, words);
@@ -99,7 +106,13 @@ function sentenceOf(event: RestEvent, words: Messages): string {
99
106
  : data.state === "unheard"
100
107
  ? feed.event.agentUnheard(agent)
101
108
  : feed.event.agentRunning(agent);
102
- return data.detail === undefined ? said : `${said}: ${data.detail}`;
109
+ if (data.detail === undefined || data.detail === SAID_BY_THE_STATE[data.state ?? "running"]) {
110
+ return said;
111
+ }
112
+ // Why, in the language's words; one the list has no word for is said as it came.
113
+ const reasons: Readonly<Record<string, string>> = words.agents.page.state.reasons;
114
+ const why = Object.hasOwn(reasons, data.detail) ? reasons[data.detail] : data.detail;
115
+ return `${said}: ${why}`;
103
116
  }
104
117
  case "team.created":
105
118
  return feed.event.teamCreated(data.team ?? feed.aTeam);
package/src/i18n/en.ts CHANGED
@@ -233,6 +233,12 @@ export const en = {
233
233
  "The value cannot be opened with this deployment's key. Whoever has it sets it again.",
234
234
  "secret.own_session":
235
235
  "The secret store is read by the account itself, signed in, not with a token it made.",
236
+ "secret.exists":
237
+ "The account keeps a secret of that name already. It takes the offer under another name, or in its place where it says so.",
238
+ "secret.offer_not_found": "No such offer waits for the account.",
239
+ "secret.too_many_offers":
240
+ "As many offers wait for the account as may. One is taken, left or runs out first.",
241
+ "secret.offer_own": "An account sets a secret of its own itself.",
236
242
  "agent.own_command":
237
243
  "This is asked by the account itself: its runner, on the command signed in as the account.",
238
244
  "signal.not_offered": "The model or the effort is none of those the agent's product offers.",
@@ -2072,6 +2078,23 @@ export const en = {
2072
2078
  title: "No such agent account",
2073
2079
  body: "It is not there, or it is not yours to see.",
2074
2080
  },
2081
+ offers: {
2082
+ title: "Offered secrets",
2083
+ offerTitle: "Offer a secret",
2084
+ offerAria: "Offer a secret",
2085
+ intro: (name: string, days: number) =>
2086
+ `${name} is told, and takes it or leaves it. The value is typed here once and shown to nobody; an offer not taken is gone after ${days} days.`,
2087
+ waits: (name: string) => `${name} takes each or leaves it. Never a value.`,
2088
+ own: "Take one or leave one with your command: console secrets --offered",
2089
+ name: "Name",
2090
+ namePlaceholder: "mail.password",
2091
+ value: "Value",
2092
+ note: "What it is for",
2093
+ offer: "Offer",
2094
+ someone: "Someone who is gone",
2095
+ takenAs: (name: string) => `as ${name}`,
2096
+ state: { waiting: "Waiting", taken: "Taken", left: "Left", lapsed: "Ran out" },
2097
+ },
2075
2098
  notSupervised: {
2076
2099
  title: "For its supervisors",
2077
2100
  body: "What an agent is doing is read by whom it reports to, those above them, and the administrators.",
@@ -2084,8 +2107,15 @@ export const en = {
2084
2107
  refused: "Refused",
2085
2108
  failed: "Failed",
2086
2109
  unheard: "Not heard from",
2087
- /** What stands before and after the moment a state began: "since 14:02". */
2110
+ /** What stands before and after the moment a state began, beside the state's badge: "since 14:02". */
2088
2111
  since: { before: "since ", after: "" },
2112
+ /**
2113
+ * The same where no badge stands beside the moment, with the state's own word, so that
2114
+ * the moment reads as the state's and not the reason's: "running since 14:02".
2115
+ */
2116
+ sinceAs: (state: string) => ({ before: `${state.toLowerCase()} since `, after: "" }),
2117
+ /** What stands before and after the moment a reason was said, after the reason: "a turn completed (14:02)". */
2118
+ reasonAt: { before: " (", after: ")" },
2089
2119
  /** What stands before and after the moment a state ends by itself, as when a usage limit resets: "until 03:30". */
2090
2120
  until: { before: "until ", after: "" },
2091
2121
  heard: "runner last heard from",
@@ -2446,6 +2476,14 @@ export const en = {
2446
2476
  submit: "Add the agent account",
2447
2477
  },
2448
2478
  },
2479
+ // What an agent account's status says at a messenger while it works (ADR-0170): the
2480
+ // runner's words, shown there and on no page. `{time}` stands for the moment it is back.
2481
+ status: {
2482
+ thinking: "Thinking",
2483
+ working: "Working · a reply may take a while",
2484
+ limited: "Out of usage",
2485
+ back: "back at {time}",
2486
+ },
2449
2487
  },
2450
2488
 
2451
2489
  sessions: {