@skillcdn/console 0.6.1 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (147) hide show
  1. package/README.md +2 -2
  2. package/dist/agent-page.d.ts.map +1 -1
  3. package/dist/agent-page.js +38 -28
  4. package/dist/agent-page.js.map +1 -1
  5. package/dist/agent-usage.d.ts +9 -6
  6. package/dist/agent-usage.d.ts.map +1 -1
  7. package/dist/agent-usage.js +38 -8
  8. package/dist/agent-usage.js.map +1 -1
  9. package/dist/api.d.ts +1 -1
  10. package/dist/api.d.ts.map +1 -1
  11. package/dist/api.js +1 -1
  12. package/dist/api.js.map +1 -1
  13. package/dist/cli/cli.d.ts.map +1 -1
  14. package/dist/cli/cli.js +65 -0
  15. package/dist/cli/cli.js.map +1 -1
  16. package/dist/cli/help.js +3 -3
  17. package/dist/cli/help.js.map +1 -1
  18. package/dist/client.d.ts +7 -1
  19. package/dist/client.d.ts.map +1 -1
  20. package/dist/client.js +2 -1
  21. package/dist/client.js.map +1 -1
  22. package/dist/components/agent-page.d.ts +33 -8
  23. package/dist/components/agent-page.d.ts.map +1 -1
  24. package/dist/components/agent-page.js +98 -32
  25. package/dist/components/agent-page.js.map +1 -1
  26. package/dist/components/calendar.d.ts +24 -4
  27. package/dist/components/calendar.d.ts.map +1 -1
  28. package/dist/components/calendar.js +78 -35
  29. package/dist/components/calendar.js.map +1 -1
  30. package/dist/console.d.ts.map +1 -1
  31. package/dist/console.js +39 -11
  32. package/dist/console.js.map +1 -1
  33. package/dist/data.d.ts +2 -0
  34. package/dist/data.d.ts.map +1 -1
  35. package/dist/data.js +4 -0
  36. package/dist/data.js.map +1 -1
  37. package/dist/desk-page.js +5 -5
  38. package/dist/desk-page.js.map +1 -1
  39. package/dist/feed-words.js +6 -0
  40. package/dist/feed-words.js.map +1 -1
  41. package/dist/i18n/en.d.ts +6 -0
  42. package/dist/i18n/en.d.ts.map +1 -1
  43. package/dist/i18n/en.js +8 -1
  44. package/dist/i18n/en.js.map +1 -1
  45. package/dist/i18n/ko.d.ts.map +1 -1
  46. package/dist/i18n/ko.js +24 -17
  47. package/dist/i18n/ko.js.map +1 -1
  48. package/dist/index.d.ts +1 -1
  49. package/dist/index.d.ts.map +1 -1
  50. package/dist/index.js +1 -1
  51. package/dist/index.js.map +1 -1
  52. package/dist/plugin/capabilities.d.ts +1 -1
  53. package/dist/plugin/capabilities.d.ts.map +1 -1
  54. package/dist/plugin/capabilities.js +6 -1
  55. package/dist/plugin/capabilities.js.map +1 -1
  56. package/dist/plugin/context.d.ts +62 -1
  57. package/dist/plugin/context.d.ts.map +1 -1
  58. package/dist/plugin/limits.d.ts +7 -0
  59. package/dist/plugin/limits.d.ts.map +1 -1
  60. package/dist/plugin/limits.js +7 -0
  61. package/dist/plugin/limits.js.map +1 -1
  62. package/dist/plugin/testing.d.ts +2 -0
  63. package/dist/plugin/testing.d.ts.map +1 -1
  64. package/dist/plugin/testing.js +2 -0
  65. package/dist/plugin/testing.js.map +1 -1
  66. package/dist/rules.js +1 -1
  67. package/dist/rules.js.map +1 -1
  68. package/dist/runner/claude.d.ts.map +1 -1
  69. package/dist/runner/claude.js +138 -9
  70. package/dist/runner/claude.js.map +1 -1
  71. package/dist/runner/desk.d.ts.map +1 -1
  72. package/dist/runner/desk.js +11 -4
  73. package/dist/runner/desk.js.map +1 -1
  74. package/dist/runner/message.d.ts +32 -2
  75. package/dist/runner/message.d.ts.map +1 -1
  76. package/dist/runner/message.js +163 -27
  77. package/dist/runner/message.js.map +1 -1
  78. package/dist/runner/runner.d.ts +15 -1
  79. package/dist/runner/runner.d.ts.map +1 -1
  80. package/dist/runner/runner.js +131 -15
  81. package/dist/runner/runner.js.map +1 -1
  82. package/dist/runner/slack.d.ts +17 -11
  83. package/dist/runner/slack.d.ts.map +1 -1
  84. package/dist/runner/slack.js +1007 -105
  85. package/dist/runner/slack.js.map +1 -1
  86. package/dist/runner/types.d.ts +110 -5
  87. package/dist/runner/types.d.ts.map +1 -1
  88. package/dist/runner/types.js.map +1 -1
  89. package/dist/runner.d.ts +4 -4
  90. package/dist/runner.d.ts.map +1 -1
  91. package/dist/runner.js +3 -3
  92. package/dist/runner.js.map +1 -1
  93. package/dist/schemas.d.ts +103 -0
  94. package/dist/schemas.d.ts.map +1 -1
  95. package/dist/schemas.js +55 -0
  96. package/dist/schemas.js.map +1 -1
  97. package/docs/specs/cli.md +2 -1
  98. package/docs/specs/plugins.md +7 -2
  99. package/docs/specs/rest.md +4 -2
  100. package/docs/specs/runner.md +50 -19
  101. package/package.json +1 -1
  102. package/skills/building-a-plugin/SKILL.md +3 -3
  103. package/skills/planning-the-board/references/setting-up.md +1 -1
  104. package/skills/running-an-agent/SKILL.md +10 -67
  105. package/skills/running-an-agent/references/preparing-the-machine.md +17 -0
  106. package/skills/running-an-agent/references/several-tasks.md +1 -1
  107. package/skills/running-an-agent/references/slack-app.md +36 -6
  108. package/skills/running-an-agent/references/the-account-and-the-invitation.md +5 -0
  109. package/skills/running-an-agent/references/what-was-not-seen-run-yet.md +3 -0
  110. package/skills/running-an-agent/references/when-the-agent-could-not-go-on.md +16 -0
  111. package/skills/running-an-agent/references/your-first-task.md +14 -0
  112. package/skills/working-the-board/SKILL.md +9 -13
  113. package/skills/working-the-board/references/a-pack-skills-questions.md +3 -0
  114. package/skills/working-the-board/references/a-plugins-commands.md +3 -0
  115. package/skills/working-the-board/references/a-review.md +3 -0
  116. package/skills/working-the-board/references/an-open-run.md +3 -0
  117. package/skills/working-the-board/references/requirements.md +7 -0
  118. package/skills/working-the-board/references/what-they-were-told.md +3 -0
  119. package/skills/working-the-board/references/work-given-in-chat.md +5 -0
  120. package/src/agent-page.tsx +41 -40
  121. package/src/agent-usage.ts +55 -12
  122. package/src/api.ts +7 -0
  123. package/src/cli/cli.ts +84 -0
  124. package/src/cli/help.ts +3 -3
  125. package/src/client.ts +11 -0
  126. package/src/components/agent-page.tsx +114 -36
  127. package/src/components/calendar.tsx +92 -36
  128. package/src/console.tsx +46 -10
  129. package/src/data.ts +6 -0
  130. package/src/desk-page.tsx +5 -5
  131. package/src/feed-words.ts +6 -0
  132. package/src/i18n/en.ts +11 -1
  133. package/src/i18n/ko.ts +30 -17
  134. package/src/index.ts +2 -0
  135. package/src/plugin/capabilities.ts +8 -1
  136. package/src/plugin/context.ts +63 -0
  137. package/src/plugin/limits.ts +7 -0
  138. package/src/plugin/testing.ts +4 -0
  139. package/src/rules.ts +1 -1
  140. package/src/runner/claude.ts +154 -9
  141. package/src/runner/desk.ts +13 -4
  142. package/src/runner/message.ts +176 -29
  143. package/src/runner/runner.ts +173 -15
  144. package/src/runner/slack.ts +1273 -124
  145. package/src/runner/types.ts +102 -2
  146. package/src/runner.ts +16 -1
  147. package/src/schemas.ts +64 -0
@@ -2,7 +2,7 @@ import { ApiError } from "../client.js";
2
2
  import { MAX_RUNNER_LINE_LENGTH, MAX_RUNNER_OFFERS, MAX_TRANSCRIPT_ATTACHMENTS, MAX_TRANSCRIPT_BATCH, MAX_TRANSCRIPT_BATCH_BYTES, MAX_TRANSCRIPT_FACT_LENGTH, MAX_TRANSCRIPT_FACT_NAME_LENGTH, MAX_TRANSCRIPT_FACTS, MAX_TRANSCRIPT_TEXT_BYTES, } from "../limits.js";
3
3
  import { RUNNER_CHOICE } from "../schemas.js";
4
4
  import { hasForbiddenCodePoint } from "../text.js";
5
- import { composeSignals, deskName, GROUP_WINDOW_MS, introOf, makeMark, sleptOf, } from "./message.js";
5
+ import { composeSignals, deskName, GROUP_WINDOW_MS, introOf, makeMark, sleptOf, wakeTextOf, } from "./message.js";
6
6
  import { cutShown, cutShownEnd, redactorOf } from "./redact.js";
7
7
  import { limitWords, noteUsage, RESET_MARGIN_MS, runnerSays, usageSaid, usageToTell, usageWords, } from "./usage.js";
8
8
  // The runner (ADR-0085, docs/specs/runner.md): one process per agent account on its machine. It
@@ -25,6 +25,18 @@ export const BATCH_MS = 1000;
25
25
  /** How long what arrives by itself waits after the agent could not go on: at first, and at most, twice as long after each try that ends the same way. */
26
26
  export const COOL_DOWN_MS = 15 * 60_000;
27
27
  export const MAX_COOL_DOWN_MS = 4 * 60 * 60_000;
28
+ /**
29
+ * How long the runner holds an ending that waits for the agent's turn, a model chosen, the
30
+ * account's own reset, an update or a `runner.json` that changed, for the sub-agents at work
31
+ * in the background of the session (ADR-0162): counted from when it first held one for them.
32
+ */
33
+ export const SUBAGENTS_MS = 60 * 60_000;
34
+ /**
35
+ * How long a session that had sub-agents in the background is not taken for idle after one
36
+ * ended or a turn did: the product hands the agent a sub-agent's report in a turn it starts
37
+ * itself, a moment after.
38
+ */
39
+ export const REPORT_MS = 10_000;
28
40
  /** How long the runner waits before it asks for its stream of signals again. */
29
41
  export const RECONNECT_MS = 5000;
30
42
  /** What an autosave's commit says: the runner's, and never the agent's own words. */
@@ -82,6 +94,11 @@ const FILE_ID_BYTES = 48;
82
94
  const LEAST_CUT_BYTES = 1024;
83
95
  /** The name of the secret an account keeps its git host's token under (ADR-0088): what the autosave's push is handed. */
84
96
  export const GIT_TOKEN_SECRET = "git.token";
97
+ /** What an ending is for, as the record says it of one that waits for sub-agents (ADR-0162). */
98
+ const FOR_UPDATE = "for an update of the command the runner runs from";
99
+ const FOR_CHANGE = "for the desk's runner.json, which changed";
100
+ const FOR_CHOICE = "for the model or the effort chosen";
101
+ const FOR_RESET = "for the account's own reset";
85
102
  /** What an event takes of a batch as the console counts one: its JSON, and the ids of its pictures. */
86
103
  const sentBytes = (event) => Buffer.byteLength(JSON.stringify({
87
104
  n: event.n,
@@ -159,6 +176,8 @@ export function createRunner(options) {
159
176
  holdMs: HOLD_MS,
160
177
  maxHoldMs: MAX_HOLD_MS,
161
178
  resetMarginMs: RESET_MARGIN_MS,
179
+ subagentsMs: SUBAGENTS_MS,
180
+ reportMs: REPORT_MS,
162
181
  ...options.timing,
163
182
  };
164
183
  /** How long what an hour's bound refused is held back: the first time, and twice as long each time after. */
@@ -588,6 +607,43 @@ export function createRunner(options) {
588
607
  flushing = false;
589
608
  }
590
609
  };
610
+ /** Whether something goes on in a session with no turn of the runner's under way: sub-agents in the background, or a turn the product started or is about to. */
611
+ const goesOn = (target) => target.background > 0 || target.own || options.now() < target.reportBy;
612
+ /**
613
+ * Whether an ending is held still for what goes on in the session (ADR-0162): for as long as
614
+ * the runner waits for it, counted from when it first held an ending so, and said on the
615
+ * record once where sub-agents are what it waits for, and once more where it waited in vain.
616
+ */
617
+ const within = (target, why) => {
618
+ const now = options.now();
619
+ target.heldSince ??= now;
620
+ const waits = now - target.heldSince < timing.subagentsMs;
621
+ const word = waits ? "waits" : "over";
622
+ if (target.background > 0 && target.heldSaid !== word) {
623
+ target.heldSaid = word;
624
+ const many = `${target.background} ${target.background === 1 ? "sub-agent" : "sub-agents"} at work in the background`;
625
+ const most = `${Math.round(timing.subagentsMs / 60_000)} minutes`;
626
+ record(target, "status", waits
627
+ ? `The session is to end ${why}, with ${many}: the runner waits until none is at work, ${most} at most.`
628
+ : `The runner waited ${most} for the sub-agents in the background, and waits no longer: the session ends ${why}, with ${many}.`);
629
+ log(`session ${target.id} is to end ${why}, with ${many}: the runner ${waits ? "waits for them" : "waited for long enough"}`);
630
+ }
631
+ return waits;
632
+ };
633
+ /**
634
+ * Whether a session is at work, for an ending that waits until it is not: a turn is under
635
+ * way, or sub-agents work on in the background, or the product started a turn of its own,
636
+ * the last two for as long as the runner waits for them. What a supervisor ends, a stop, a
637
+ * restart or a reset, asks nothing of it.
638
+ */
639
+ const busy = (target, why) => target !== undefined && (target.turn || (goesOn(target) && within(target, why)));
640
+ /**
641
+ * Whether the runner is to end for an update and hands nothing more over (ADR-0101). Not
642
+ * while it waits for sub-agents in the background: that may take an hour, in which the agent
643
+ * goes on reading what it is sent.
644
+ */
645
+ const closing = () => updatedTo !== undefined &&
646
+ !(session !== undefined && session.background > 0 && within(session, FOR_UPDATE));
591
647
  /** Reads what the product does: the blocks are numbered and kept as they arrive, its own words go to the queue. */
592
648
  const pump = async (target) => {
593
649
  try {
@@ -604,7 +660,15 @@ export function createRunner(options) {
604
660
  }
605
661
  record(target, event.kind, event.text, event.data, event.pictures);
606
662
  }
663
+ else if (event.type === "background") {
664
+ target.background = event.agents;
665
+ target.reportBy = options.now() + timing.reportMs;
666
+ }
667
+ else if (event.type === "turn_started") {
668
+ target.own = true;
669
+ }
607
670
  else if (event.type === "cannot_go_on") {
671
+ target.own = false;
608
672
  // Counted here, in the order the product wrote: the queue is behind what is read.
609
673
  push({ t: "driver", session: target, event, unread: target.unread });
610
674
  }
@@ -614,6 +678,11 @@ export function createRunner(options) {
614
678
  }
615
679
  else if (event.type === "turn_completed") {
616
680
  target.unread = 0;
681
+ target.own = false;
682
+ // A report that came while the turn was under way is read in the next.
683
+ if (target.reportBy > 0) {
684
+ target.reportBy = options.now() + timing.reportMs;
685
+ }
617
686
  }
618
687
  push({ t: "driver", session: target, event });
619
688
  }
@@ -706,6 +775,9 @@ export function createRunner(options) {
706
775
  taken: [],
707
776
  unread: 0,
708
777
  returning: false,
778
+ background: 0,
779
+ own: false,
780
+ reportBy: 0,
709
781
  n: 0,
710
782
  outbox: [],
711
783
  waiting: 0,
@@ -828,7 +900,7 @@ export function createRunner(options) {
828
900
  deliverAt = undefined;
829
901
  // Nothing more is handed over once the runner is to end for an update: what waits is sent
830
902
  // again by the console, in order, to the runner started after.
831
- if (held || updatedTo !== undefined) {
903
+ if (held || closing()) {
832
904
  return;
833
905
  }
834
906
  // An agent its usage limit stopped is brought back by the runner itself, with nothing to
@@ -861,7 +933,12 @@ export function createRunner(options) {
861
933
  (config.conversation !== "continuous" && signal.key === "week")));
862
934
  // An agent that is back from a usage limit goes on in the conversation it was stopped in:
863
935
  // what it was doing is there, and the day after begins the next one.
864
- if (anew && session?.turn !== true && limited === undefined) {
936
+ // Not with sub-agents at work in its background either (ADR-0162): the conversation they
937
+ // report to goes on, as it does under a turn.
938
+ if (anew &&
939
+ session?.turn !== true &&
940
+ (session === undefined || !goesOn(session)) &&
941
+ limited === undefined) {
865
942
  await end("restarted");
866
943
  conversation = undefined;
867
944
  }
@@ -1311,9 +1388,9 @@ export function createRunner(options) {
1311
1388
  }
1312
1389
  await account(signal);
1313
1390
  if (session !== undefined && !(await session.driver.set(settings))) {
1314
- // Taken when the product starts: the session ends when no turn is under way, and the next has it.
1391
+ // Taken when the product starts: the session ends when it is not at work, and the next has it.
1315
1392
  renew = true;
1316
- if (!session.turn) {
1393
+ if (!busy(session, FOR_CHOICE)) {
1317
1394
  await end("restarted");
1318
1395
  }
1319
1396
  }
@@ -1332,7 +1409,7 @@ export function createRunner(options) {
1332
1409
  }
1333
1410
  // Nothing is handed over once the runner is to end for an update: the turn is
1334
1411
  // stopped all the same, and what waits is sent again to the runner started after.
1335
- if (pending.length > 0 && updatedTo === undefined) {
1412
+ if (pending.length > 0 && !closing()) {
1336
1413
  if (stops) {
1337
1414
  await deliver("now");
1338
1415
  }
@@ -1347,7 +1424,7 @@ export function createRunner(options) {
1347
1424
  return;
1348
1425
  }
1349
1426
  pending.push(signal);
1350
- if (stops && updatedTo !== undefined && session !== undefined) {
1427
+ if (stops && closing() && session !== undefined) {
1351
1428
  // Its words are not handed to a runner that is to end: the turn is stopped, the
1352
1429
  // runner ends for the update, and the console sends them again to the one after.
1353
1430
  await stopTurn(session);
@@ -1549,7 +1626,7 @@ export function createRunner(options) {
1549
1626
  waits = undefined;
1550
1627
  setState("running", "completed");
1551
1628
  }
1552
- if (renew) {
1629
+ if (renew && !busy(target, FOR_CHOICE)) {
1553
1630
  await end("restarted");
1554
1631
  }
1555
1632
  if (pending.length > 0) {
@@ -1925,10 +2002,14 @@ export function createRunner(options) {
1925
2002
  // past that, what the sources raise is let go for a while, longer each time, and said
1926
2003
  // once, so that a source that repeats itself costs the console nothing more.
1927
2004
  if (wakesHeld !== undefined && options.now() < wakesHeld.until) {
1928
- return;
2005
+ return false;
1929
2006
  }
2007
+ // Written in parts whatever the source handed over (ADR-0163): its own lines apart from
2008
+ // what someone else wrote, and a text with no line of the source's as words whole, so
2009
+ // that no word of a message reads as a line of the source's when the signal returns.
2010
+ const text = wakeTextOf("parts" in raised ? raised.parts : [{ words: raised.text }]);
1930
2011
  try {
1931
- await client.raiseWake({ source: "messenger", key: raised.key, text: raised.text });
2012
+ await client.raiseWake({ source: "messenger", key: raised.key, text });
1932
2013
  }
1933
2014
  catch (error) {
1934
2015
  if (codeOf(error) !== "signal.too_many") {
@@ -1937,18 +2018,29 @@ export function createRunner(options) {
1937
2018
  const pause = heldFor(wakesHeld);
1938
2019
  wakesHeld = { until: options.now() + pause, pause };
1939
2020
  sayOnce("wakes", "the console takes no more wakes of this runner's within the hour (signal.too_many); what its wake sources raise is let go for a while");
1940
- return;
2021
+ return false;
1941
2022
  }
1942
2023
  if (wakesHeld !== undefined) {
1943
2024
  wakesHeld = undefined;
1944
2025
  sayOver("wakes", "the console takes the wakes of this runner's wake sources again");
1945
2026
  }
2027
+ return true;
1946
2028
  },
2029
+ kept: new Map(),
1947
2030
  log,
1948
2031
  stands: (state, why) => sourceStands(source.name, state, why),
1949
2032
  fetch: wakes.fetch,
1950
2033
  socket: wakes.socket,
1951
2034
  wait: pause,
2035
+ // Who wrote, as the console answers the account's own sign-in (ADR-0164), of the
2036
+ // messenger the source is named for. A console that does not know the question, or does
2037
+ // not answer, says nothing, and the source says of an account what the messenger does.
2038
+ ...(client.writers === undefined
2039
+ ? {}
2040
+ : {
2041
+ writers: async (accounts, signal) => (await client.writers?.({ messenger: source.name, accounts: [...accounts] }, signal))
2042
+ ?.items ?? [],
2043
+ }),
1952
2044
  };
1953
2045
  sourceStands(source.name, "waiting");
1954
2046
  let wait = timing.reconnectMs;
@@ -2105,8 +2197,10 @@ export function createRunner(options) {
2105
2197
  try {
2106
2198
  for (;;) {
2107
2199
  // An update is taken between two turns, and at once where none is under way; so is
2108
- // a runner.json that changed.
2109
- if ((updatedTo !== undefined || reconfigure) && session?.turn !== true) {
2200
+ // a runner.json that changed. Neither while sub-agents work on in the background of
2201
+ // the session, for as long as the runner waits for them (ADR-0162).
2202
+ if ((updatedTo !== undefined || reconfigure) &&
2203
+ !busy(session, updatedTo !== undefined ? FOR_UPDATE : FOR_CHANGE)) {
2110
2204
  how = updatedTo !== undefined ? "updated" : "changed";
2111
2205
  if (session !== undefined) {
2112
2206
  record(session, "status", updatedTo !== undefined
@@ -2160,11 +2254,33 @@ export function createRunner(options) {
2160
2254
  // model having refused or a usage limit standing, waits as it would without it,
2161
2255
  // and the reset is taken once a turn completed again.
2162
2256
  if (ownReset !== undefined &&
2163
- session?.turn !== true &&
2164
2257
  waits === undefined &&
2165
- limited === undefined) {
2258
+ limited === undefined &&
2259
+ !busy(session, FOR_RESET)) {
2166
2260
  await beginAnew(ownReset);
2167
2261
  }
2262
+ // A model or an effort the product takes only when it starts, held for what went
2263
+ // on in the session: it ends once nothing does. Not where the agent could not go
2264
+ // on, which keeps its session as it does under a turn.
2265
+ if (renew &&
2266
+ session !== undefined &&
2267
+ stands.state === "running" &&
2268
+ !busy(session, FOR_CHOICE)) {
2269
+ await end("restarted");
2270
+ if (pending.length > 0) {
2271
+ scheduleDeliver();
2272
+ }
2273
+ }
2274
+ // Nothing waits to end the session: the next thing that does counts from its own
2275
+ // moment how long it waits for the sub-agents.
2276
+ if (session !== undefined &&
2277
+ !renew &&
2278
+ ownReset === undefined &&
2279
+ updatedTo === undefined &&
2280
+ !reconfigure) {
2281
+ session.heldSince = undefined;
2282
+ session.heldSaid = undefined;
2283
+ }
2168
2284
  }
2169
2285
  catch (error) {
2170
2286
  log(`the runner could not do what it was about to (${codeOf(error)}); it goes on`);