@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
@@ -2,6 +2,7 @@ import * as z from "zod/mini";
2
2
  import { MAX_SIGNAL_LENGTH } from "../limits.js";
3
3
  import { withoutForbiddenCodePoints } from "../text.js";
4
4
  import { wakeTextOf } from "./message.js";
5
+ import { KEPT_STATUS, keptStatusFits, showSlackStatus, slackStatusNote, slackStatusNoted, } from "./slack-status.js";
5
6
  // The `slack` wake source (ADR-0085): one app for one agent account, which receives over its
6
7
  // Socket Mode connection the events the agent's own member of the workspace can see, and raises
7
8
  // a wake for what is said to the agent: a direct message, a message of a group conversation, a
@@ -18,6 +19,9 @@ import { wakeTextOf } from "./message.js";
18
19
  // on. With the member's own token, where the account keeps it, the source reads what was said
19
20
  // in the conversation before the message, and the wake carries what the agent missed of it,
20
21
  // who else there writes as an agent account does, and what to judge by whether to answer.
22
+ // What the source brought the agent it keeps by ids and moments, from one runner to the next,
23
+ // and counts for as long as the agent's conversation holds it (ADR-0166): a conversation begun
24
+ // since, at a reset say, is carried what led up to the message, the agent's own words among it.
21
25
  // Written from the messenger's own documentation of Socket Mode, of the Events API, of its
22
26
  // blocks and of the two methods that read a conversation; what an event or an answer holds is
23
27
  // read by schema, bounded, and never run.
@@ -50,6 +54,21 @@ const MAX_UNDER = 5;
50
54
  const MAX_BEFORE = 10;
51
55
  const MAX_BEFORE_TEXT = 500;
52
56
  const MAX_BEFORE_LENGTH = 3000;
57
+ /**
58
+ * The most of one earlier message where few are carried (ADR-0166): they share what a wake holds
59
+ * of them, so that one long message is read whole in its wake and not fetched again, and each of
60
+ * many is still cut at `MAX_BEFORE_TEXT`.
61
+ */
62
+ const MAX_BEFORE_MOST = 2000;
63
+ /** What a line that leads an earlier message takes of that share, about. */
64
+ const BEFORE_LINE = 200;
65
+ /**
66
+ * How many earlier messages a wake carries where the agent's conversation holds nothing of the
67
+ * place (ADR-0166): the last few, whoever wrote them, to take up what was being said.
68
+ */
69
+ const MAX_BEFORE_ANEW = 5;
70
+ /** How many members a wake's first line names of those a message names beside the agent. */
71
+ const MAX_NAMED = 5;
53
72
  /** How many messages a wake reads of a conversation, and of a thread: a page of so many, so many pages. */
54
73
  const READ_MESSAGES = 50;
55
74
  const READ_THREAD_PAGE = 200;
@@ -332,7 +351,13 @@ function blockOf(block) {
332
351
  return [leftOut(block.type)];
333
352
  }
334
353
  }
335
- /** A mark for each file of a message, by its name on one line: the first few, and how many more. */
354
+ /** A file's id, as the messenger spells one. */
355
+ const FILE_ID = /^F[A-Z0-9]{1,23}$/;
356
+ /**
357
+ * A mark for each file of a message, by its name on one line and the id the messenger reads it
358
+ * by (ADR-0166), so that the agent opens it with the messenger's own tool without looking the
359
+ * message up again: the first few, and how many more.
360
+ */
336
361
  function filesOf(files) {
337
362
  const all = listOf(files).filter(isObject);
338
363
  const marks = all.slice(0, MAX_FILES_NAMED).map((file) => {
@@ -340,7 +365,11 @@ function filesOf(files) {
340
365
  .replaceAll(/[\r\n\]]+/g, " ")
341
366
  .trim()
342
367
  .slice(0, MAX_FILE_NAME);
343
- return `[file${name === "" ? "" : ` ${name}`}, not carried in this wake]`;
368
+ const id = textOf(file.id);
369
+ const named = [name, id !== undefined && FILE_ID.test(id) ? `(${id})` : ""]
370
+ .filter((part) => part !== "")
371
+ .join(" ");
372
+ return `[file${named === "" ? "" : ` ${named}`}, not carried in this wake]`;
344
373
  });
345
374
  const more = all.length - marks.length;
346
375
  return more > 0 ? [...marks, `[${more} more files, not carried in this wake]`] : marks;
@@ -452,6 +481,32 @@ const partsOf = (said) => [
452
481
  * typed that only looks like one arrives escaped, and is none.
453
482
  */
454
483
  const EVERYONE_CALLED = /<!(here|channel|everyone)(?:\|[^<>]{0,40})?>/;
484
+ /**
485
+ * How the messenger writes a member's name in a message's `text`, with what it shows for it
486
+ * after a bar where it says so. What a person typed that only looks like one arrives escaped.
487
+ */
488
+ const MEMBER_NAMED = /<@([UW][A-Z0-9]{1,23})(?:\|[^<>]{0,80})?>/g;
489
+ /**
490
+ * How the messenger writes a call of a group of members in a message's `text`, by the group's
491
+ * id, with what it shows for it after a bar where it says so. Who is in the group, nothing in a
492
+ * message says.
493
+ */
494
+ const GROUP_CALLED = /<!subteam\^[A-Z0-9]{1,23}(?:\|[^<>]{0,80})?>/;
495
+ /**
496
+ * Whom a message names: the members by their ids, each once, in the order it names them, in
497
+ * whichever of its two ways the messenger wrote a name, and whether it calls a group of members,
498
+ * which may hold anyone. The one reading of who is named, for the agent as for the others.
499
+ */
500
+ function namedIn(text) {
501
+ const members = [];
502
+ for (const found of text.matchAll(MEMBER_NAMED)) {
503
+ const id = found[1];
504
+ if (id !== undefined && !members.includes(id)) {
505
+ members.push(id);
506
+ }
507
+ }
508
+ return { members, group: GROUP_CALLED.test(text) };
509
+ }
455
510
  /**
456
511
  * Who wrote a message, as a line of the source's says it: the account by the id the messenger
457
512
  * gives it, its workspace where the message says that it is another than the agent's own, and
@@ -497,12 +552,15 @@ async function unlessEnded(until, answer) {
497
552
  const LOGIN = /^[A-Za-z0-9][A-Za-z0-9._@+-]{0,99}$/;
498
553
  /**
499
554
  * The account a message names as its writer, as the console is asked of it: with the workspace
500
- * the message itself says the account is of, and none where it says none. The agent's own
501
- * workspace is never taken for it: the same id at another workspace is another account, and an
502
- * account whose workspace nothing says is nobody the console knows.
555
+ * the message itself says the account is of. Where it says none, a message with a file say, the
556
+ * workspace is `home`, the agent's own, which is given only for a conversation the messenger
557
+ * says in so many words is shared with no other organization (ADR-0166): everyone who writes
558
+ * there is an account of the agent's own organization, where an id is one account. Anywhere
559
+ * else the agent's own workspace is never taken for it: the same id at another organization is
560
+ * another account, and an account whose workspace nothing says is nobody the console knows.
503
561
  */
504
- function accountOf(message) {
505
- const workspace = workspaceOf(message.user_team) ?? workspaceOf(message.team);
562
+ function accountOf(message, home) {
563
+ const workspace = workspaceOf(message.user_team) ?? workspaceOf(message.team) ?? home;
506
564
  return message.user === undefined || workspace === undefined
507
565
  ? undefined
508
566
  : { workspace, account: message.user };
@@ -544,8 +602,9 @@ function standsOf(member) {
544
602
  * with how, its manager, anyone above its manager or an administrator, and of anyone below
545
603
  * the agent in its line that they report to it, themselves or through others (`standsOf`);
546
604
  * - that it is no member the console knows, where the console is told the accounts of that
547
- * workspace and not this one: what it is told may be short of one, so a supervisor's tell that
548
- * names the account still tells whose it is;
605
+ * workspace and not this one: what it is told may be short of one, so a supervisor's own word
606
+ * that names the account, a tell or a message in an account known to be a supervisor's
607
+ * (ADR-0173), still tells whose it is;
549
608
  * - nothing, where the console is told no account of that workspace, where it does not answer
550
609
  * before the signal ends, or where it is older than the question: the line is then as the
551
610
  * messenger alone has it. Where the signal has ended already, the console is not asked.
@@ -555,11 +614,11 @@ function standsOf(member) {
555
614
  * is left out. An agent takes a supervisor's own word at the messenger as an instruction
556
615
  * (ADR-0160), and this is how a wake says that one wrote.
557
616
  */
558
- async function whoOf(host, messages, until) {
617
+ async function whoOf(host, messages, until, home) {
559
618
  const keyOf = (one) => `${one.workspace} ${one.account}`;
560
619
  const asked = new Map();
561
620
  for (const message of messages) {
562
- const one = accountOf(message);
621
+ const one = accountOf(message, home);
563
622
  if (one !== undefined && asked.size < MAX_WRITERS_ASKED) {
564
623
  asked.set(keyOf(one), one);
565
624
  }
@@ -588,7 +647,7 @@ async function whoOf(host, messages, until) {
588
647
  : ` (${named}${member.kind === "agent" ? ", an agent account" : ""}, ${standsOf(member)})`);
589
648
  }
590
649
  return (message) => {
591
- const one = accountOf(message);
650
+ const one = accountOf(message, home);
592
651
  return one === undefined ? "" : (known.get(keyOf(one)) ?? "");
593
652
  };
594
653
  }
@@ -626,10 +685,11 @@ function heardOf(payload, channels) {
626
685
  return undefined;
627
686
  }
628
687
  const direct = event.channel_type === "im";
629
- // A mention is told by the message's `text`, where the messenger writes one in its own way and
630
- // escapes what a person typed that only looks like one.
631
- const mentioned = event.type === "app_mention" ||
632
- (member !== undefined && (event.text ?? "").includes(`<@${member}>`));
688
+ // A mention is told by the message's `text`, where the messenger writes one in its own ways and
689
+ // escapes what a person typed that only looks like one: read once, for the agent and for
690
+ // whoever else the message names.
691
+ const named = namedIn(event.text ?? "");
692
+ const mentioned = event.type === "app_mention" || (member !== undefined && named.members.includes(member));
633
693
  const group = event.channel_type === "mpim";
634
694
  // Where nobody named the agent, only a person's own words wake it: what an app posts in a
635
695
  // conversation the agent listens to is not said to it, and would wake it at every post.
@@ -661,11 +721,25 @@ function heardOf(payload, channels) {
661
721
  // A conversation shared with another organization is said to be one, whoever wrote in it:
662
722
  // what is said there, people outside read.
663
723
  const shared = parsed.data.is_ext_shared_channel === true ? "externally shared " : "";
724
+ // Whom a message names where it does not name the agent (ADR-0166): where several are in a
725
+ // conversation, that is whom it was said to, and the agent reads so before it reads on. Not
726
+ // in a direct conversation, where whatever is said is said to the agent, nor in a call of
727
+ // everyone, which calls the agent with the rest, nor where a group of members is called,
728
+ // which the agent may be in: nobody is said not to be named who may have been.
729
+ const others = direct || mentioned || called !== undefined || named.group || member === undefined
730
+ ? []
731
+ : named.members.filter((one) => one !== member && one !== event.user);
732
+ const naming = others.length === 0
733
+ ? ""
734
+ : `, naming ${others.slice(0, MAX_NAMED).join(", ")}${others.length > MAX_NAMED ? ` and ${others.length - MAX_NAMED} more` : ""} and not you`;
664
735
  const whole = saidOf(event);
665
736
  const saying = (who) => {
666
- const from = `from ${writerOf(event, own, who)}`;
737
+ const from = `from ${writerOf(event, own, who)}${naming}`;
738
+ // A message of a channel that is in no thread is said to be in none (ADR-0166), with the
739
+ // thread a reply to it goes in, which is its own: named as a thread alone, it read as a
740
+ // reply in one.
667
741
  const first = where === undefined
668
- ? `${mentioned ? "A mention" : called !== undefined ? `A call of everyone (@${called})` : "A message"} in the ${shared}channel ${event.channel} at Slack, ${from}, in the thread ${thread}`
742
+ ? `${mentioned ? "A mention" : called !== undefined ? `A call of everyone (@${called})` : "A message"} in the ${shared}channel ${event.channel} at Slack, ${from}, ${event.thread_ts === undefined ? `outside any thread: a reply begins the thread ${thread}` : `in the thread ${thread}`}`
669
743
  : event.thread_ts === undefined
670
744
  ? `${where}, ${from}, in the ${shared}conversation ${event.channel}`
671
745
  : `${where}, ${from}, in the thread ${thread} of the ${shared}conversation ${event.channel}`;
@@ -705,6 +779,7 @@ function heardOf(payload, channels) {
705
779
  team: event.team,
706
780
  user_team: event.user_team,
707
781
  },
782
+ home: parsed.data.is_ext_shared_channel === false ? workspaceOf(installed?.team_id) : undefined,
708
783
  };
709
784
  }
710
785
  /**
@@ -889,7 +964,7 @@ const readWith = (channel, thread, after) => `console agent messages slack:${cha
889
964
  * long before, in a line of the source's own, and its writer's own words, so much of them. What
890
965
  * hangs under it is marked in the words and not carried: the agent reads it with the command.
891
966
  */
892
- function earlierOf(message, heard, who = NOBODY) {
967
+ function earlierOf(message, heard, who = NOBODY, most = MAX_BEFORE_TEXT) {
893
968
  const said = saidOf(message);
894
969
  const words = [
895
970
  said.words,
@@ -897,14 +972,16 @@ function earlierOf(message, heard, who = NOBODY) {
897
972
  ]
898
973
  .filter((part) => part !== "")
899
974
  .join("\n");
900
- const cut = words.length > MAX_BEFORE_TEXT
901
- ? `, cut after ${MAX_BEFORE_TEXT} of its ${words.length} characters`
902
- : "";
975
+ const cut = words.length > most ? `, cut after ${most} of its ${words.length} characters` : "";
976
+ // The agent's own message, carried where its conversation holds it no more, is said as its own.
977
+ const from = message.user !== undefined && message.user === heard.member
978
+ ? "you"
979
+ : writerOf(message, heard.own, who);
903
980
  return [
904
981
  {
905
- says: `${stretchOf(secondsOf(heard.ts) - secondsOf(message.ts))} before it, from ${writerOf(message, heard.own, who)}${cut}`,
982
+ says: `${stretchOf(secondsOf(heard.ts) - secondsOf(message.ts))} before it, from ${from}${cut}`,
906
983
  },
907
- { words: cut === "" ? words : `${firstOf(words, MAX_BEFORE_TEXT)}…` },
984
+ { words: cut === "" ? words : `${firstOf(words, most)}…` },
908
985
  ];
909
986
  }
910
987
  /** How many names the source keeps, of the messages its wakes carried and of where they were raised: the latest. */
@@ -913,6 +990,31 @@ const MAX_KEPT = 2000;
913
990
  const broughtOf = (heard) => `brought:${heard.channel}:${heard.thread ?? ""}`;
914
991
  /** The name the source keeps a message a wake carried under: `woke`, or `said` among what was said before another. */
915
992
  const carriedAs = (channel, ts) => `carried:${channel}:${ts}`;
993
+ /** The name the source keeps the moment under at which a wake last said, of a conversation or a thread, what to judge by whether to answer. */
994
+ const judgedOf = (heard) => `judged:${heard.channel}:${heard.thread ?? ""}`;
995
+ /** A place the source keeps a moment under, and a message it keeps a word under, as it names them. */
996
+ const KEPT_PLACE = /^(?:brought|judged):[A-Z0-9]{1,24}:(?:[0-9]{1,12}\.[0-9]{1,9})?$/;
997
+ const KEPT_MESSAGE = /^carried:[A-Z0-9]{1,24}:[0-9]{1,12}\.[0-9]{1,9}$/;
998
+ const KEPT_MOMENT = /^[0-9]{1,12}\.[0-9]{1,9}$/;
999
+ /**
1000
+ * Holds what the source kept to its own shapes (ADR-0166): a moment of the messenger's under a
1001
+ * place, `woke` or `said` under a message. It is read back from a file of the desk, where
1002
+ * anything may stand, and compared as it is: a moment that is none, a number without end say,
1003
+ * would count everything said in a place as brought, for good. Anything else is nothing kept
1004
+ * for that name. Beside them, until when a status of the source's own stands (ADR-0170).
1005
+ */
1006
+ function ownShapes(kept) {
1007
+ for (const [name, value] of [...kept]) {
1008
+ const fits = name === KEPT_STATUS
1009
+ ? keptStatusFits(value)
1010
+ : KEPT_PLACE.test(name)
1011
+ ? KEPT_MOMENT.test(value)
1012
+ : KEPT_MESSAGE.test(name) && (value === "woke" || value === "said");
1013
+ if (!fits) {
1014
+ kept.delete(name);
1015
+ }
1016
+ }
1017
+ }
916
1018
  /** Keeps a name as the latest, and lets go of the oldest past the most. */
917
1019
  function keep(kept, name, value) {
918
1020
  kept.delete(name);
@@ -925,21 +1027,27 @@ function keep(kept, name, value) {
925
1027
  }
926
1028
  }
927
1029
  /**
928
- * What a wake carries of the conversation it was raised in, after the message itself (ADR-0163),
929
- * read with the member's own token where the account keeps it:
1030
+ * What a wake carries of the conversation it was raised in, after the message itself (ADR-0163,
1031
+ * ADR-0166), read with the member's own token where the account keeps it:
930
1032
  *
931
1033
  * - what was said there before the message and since the later of two: the agent's own last
932
1034
  * message there, and the last message a wake already brought it from there, and of that what
933
1035
  * no wake carried, in a thread the message that began it say; so that an agent that stays
934
1036
  * silent is handed each message once. The oldest first, each behind a line that says who wrote
935
- * it and how long before: the last few, so much of each, and where there was more, how many
936
- * and the command that reads them. An agent account's message wakes no other unless it names
937
- * it, so this is where an agent reads what another answered. It is information, whoever wrote
938
- * it;
1037
+ * it and how long before: the last few, so much of each as their number leaves room for, and
1038
+ * where there was more, how many and the command that reads them. An agent account's message
1039
+ * wakes no other unless it names it, so this is where an agent reads what another answered.
1040
+ * It is information, whoever wrote it;
1041
+ * - each of the two counts only where the agent's conversation still holds it: one that began
1042
+ * since, at a reset say (`WakeHost.began`), holds nothing of what the agent wrote or was
1043
+ * brought before. The first wake of a place in such a conversation carries the last few
1044
+ * messages before it, whoever wrote them, the agent's own said as its own, so that what was
1045
+ * being said is taken up from the wake and not from a memory of it;
939
1046
  * - who else there writes through an app, as an agent account does, the last to write first,
940
1047
  * and with them what the agent judges by whether to answer: said in every conversation but
941
1048
  * a direct one where such an account was read, since one message wakes each of them and
942
- * none sees what another is about to say.
1049
+ * none sees what another is about to say. The sentence is said once for a place in a
1050
+ * conversation of the agent's; after that the line names them and the command, and no more.
943
1051
  *
944
1052
  * Where the account keeps no token to read with, nothing is added, and the wake is as it was;
945
1053
  * where the messenger refuses the read or does not answer, a line says so, with why in a short
@@ -951,7 +1059,12 @@ async function beforeOf(host, heard, writer, until) {
951
1059
  if (token === undefined) {
952
1060
  return { parts: [], read: false, carried: [] };
953
1061
  }
954
- const upTo = host.kept.get(broughtOf(heard));
1062
+ // What was written or brought before the agent's conversation began, that conversation holds
1063
+ // no more: a moment of the messenger's is held only from then on.
1064
+ const began = host.began?.() ?? 0;
1065
+ const held = (moment) => Number(moment) * 1000 >= began;
1066
+ const mark = host.kept.get(broughtOf(heard));
1067
+ const upTo = mark !== undefined && held(mark) ? mark : undefined;
955
1068
  const read = heard.thread === undefined
956
1069
  ? await conversationOf(host, token, heard.channel, { limit: READ_MESSAGES, before: heard.ts }, until)
957
1070
  : await threadOf(host, token, heard.channel, heard.thread, { after: upTo, beginning: true }, until);
@@ -994,18 +1107,22 @@ async function beforeOf(host, heard, writer, until) {
994
1107
  const shown = heard.direct || heard.member === undefined || others.length === 0
995
1108
  ? []
996
1109
  : writers.slice(0, MAX_OTHERS + 1);
997
- const wrote = heard.member === undefined
1110
+ const own = heard.member === undefined
998
1111
  ? -1
999
1112
  : earlier.findLastIndex((message) => message.user === heard.member);
1113
+ const wrote = own !== -1 && held(earlier[own]?.ts ?? "0") ? own : -1;
1000
1114
  // What a wake already brought of this conversation, as the message that woke or among what
1001
1115
  // was said before it, is not carried again: the agent has it, whether or not it answered. Nor
1002
1116
  // is what a wake brought from elsewhere, the message that began this thread from its channel.
1003
1117
  const brought = upTo === undefined ? -1 : earlier.findLastIndex((message) => !before(upTo, message.ts));
1004
1118
  const last = Math.max(wrote, brought);
1119
+ // Nothing of the place is in the agent's conversation, and something was said there before
1120
+ // that conversation began: what is carried is what leads up to the message, whoever wrote it.
1121
+ const anew = last === -1 && earlier.some((message) => !held(message.ts));
1005
1122
  const since = earlier
1006
1123
  .slice(last + 1)
1007
- .filter((message) => !host.kept.has(carriedAs(heard.channel, message.ts)));
1008
- const latest = since.toReversed().slice(0, MAX_BEFORE);
1124
+ .filter((message) => !(held(message.ts) && host.kept.has(carriedAs(heard.channel, message.ts))));
1125
+ const latest = since.toReversed().slice(0, anew ? MAX_BEFORE_ANEW : MAX_BEFORE);
1009
1126
  // Who wrote each, as the console says it (ADR-0164), asked at once for all whose account is
1010
1127
  // another than that of the message that woke, which is asked of beside the read: said of an
1011
1128
  // earlier message as of the one that woke, and information all the same, whoever wrote it;
@@ -1019,11 +1136,13 @@ async function beforeOf(host, heard, writer, until) {
1019
1136
  }
1020
1137
  }
1021
1138
  const first = await writer;
1022
- const known = accountOf(heard.from);
1139
+ const known = accountOf(heard.from, heard.home);
1023
1140
  const rest = await whoOf(host, [...latest, ...theirs.values()].filter((message) => {
1024
- const one = accountOf(message);
1025
- return one?.account !== known?.account || one?.workspace !== known?.workspace;
1026
- }), until);
1141
+ const one = accountOf(message, heard.home);
1142
+ // The agent's own account is said as its own, and asked of nobody.
1143
+ return (message.user !== heard.member &&
1144
+ (one?.account !== known?.account || one?.workspace !== known?.workspace));
1145
+ }), until, heard.home);
1027
1146
  const who = (message) => first(message) || rest(message);
1028
1147
  const named = shown
1029
1148
  .map((one) => {
@@ -1031,17 +1150,23 @@ async function beforeOf(host, heard, writer, until) {
1031
1150
  return one === heard.member ? "you" : `${one}${written === undefined ? "" : who(written)}`;
1032
1151
  })
1033
1152
  .join(", ");
1153
+ // What to judge by is said once for a place in a conversation of the agent's (ADR-0166):
1154
+ // where a wake said it there since that conversation began, the line names who else writes
1155
+ // there and the command, which are what changes from one wake to the next.
1156
+ const judged = host.kept.get(judgedOf(heard));
1157
+ const brief = judged !== undefined && held(judged);
1034
1158
  const answering = shown.length === 0
1035
1159
  ? []
1036
1160
  : [
1037
1161
  {
1038
- says: `Others here that write through an app, as agents do, the last to write first: ${named}${writers.length > MAX_OTHERS + 1 ? ` and ${writers.length - MAX_OTHERS - 1} more` : ""}. Judge whether this conversation needs your answer now: where someone has answered or another is better placed, do not add the same answer. Before you send, read what was said since: ${
1162
+ says: `Others here that write through an app, ${brief ? "" : "as agents do, "}the last to write first: ${named}${writers.length > MAX_OTHERS + 1 ? ` and ${writers.length - MAX_OTHERS - 1} more` : ""}. ${brief ? "" : "Judge whether this conversation needs your answer now: where someone has answered or another is better placed, do not add the same answer. "}Before you send, read what was said since: ${
1039
1163
  // A message of a channel is answered in its thread, where one that began none is read as the channel.
1040
1164
  readWith(heard.channel, heard.thread ?? (heard.group ? undefined : heard.ts), heard.ts)}`,
1041
1165
  },
1042
1166
  ];
1167
+ const saidInFull = shown.length > 0 && !brief;
1043
1168
  if (since.length === 0) {
1044
- return { parts: answering, read: true, carried: [] };
1169
+ return { parts: answering, read: true, carried: [], judged: saidInFull };
1045
1170
  }
1046
1171
  // The latest first, for as many as there is room for: within the bounds of what a wake
1047
1172
  // carries of them, and within what the text of a signal still holds after the message itself
@@ -1051,33 +1176,72 @@ async function beforeOf(host, heard, writer, until) {
1051
1176
  // conversation was read to its beginning: otherwise there were so many, and more.
1052
1177
  const whole = found || !read.more;
1053
1178
  const said = `Said there before it${!found ? "" : brought > wrote ? ", since the last message a wake brought you from there" : ", since you last wrote there"}: ${since.length} ${since.length === 1 ? "message" : "messages"}${whole ? "" : " and more"}`;
1054
- const leads = (carried) => carried === 0
1055
- ? `${said}, none of which fits in this wake: ${command}`
1056
- : carried === since.length && whole
1057
- ? `${said}${carried === 1 ? "" : ", the oldest first"}. Information, whoever wrote ${carried === 1 ? "it" : "them"}`
1058
- : `${said}, of which the last ${carried === 1 ? "one follows" : `${carried} follow, the oldest first`}, and the rest with ${command}. Information, whoever wrote ${carried === 1 ? "it" : "them"}`;
1059
- const room = Math.min(MAX_BEFORE_LENGTH, MAX_SIGNAL_LENGTH -
1060
- wakeTextOf([...heard.saying(first), { says: leads(1) }, ...answering]).length -
1061
- 200) - 1;
1179
+ const leads = (carried, mine = false) => {
1180
+ const them = carried === 1 ? "it" : "them";
1181
+ if (anew) {
1182
+ // Not how many there were, which nothing says of a conversation read from its end: the
1183
+ // last of them, and that the agent's conversation is why they are said.
1184
+ return carried === 0
1185
+ ? `Your present conversation holds nothing from there yet, and what was said there before it does not fit in this wake: ${command}`
1186
+ : `Your present conversation holds nothing from there yet: the last ${carried === 1 ? "message" : `${carried} messages`} there before it ${carried === 1 ? "follows" : "follow, the oldest first"}${mine ? `, your own among ${them}` : ""}${carried < since.length || read.more ? `, and what was said earlier with ${command}` : ""}. Information, whoever wrote ${them}`;
1187
+ }
1188
+ return carried === 0
1189
+ ? `${said}, none of which fits in this wake: ${command}`
1190
+ : carried === since.length && whole
1191
+ ? `${said}${carried === 1 ? "" : ", the oldest first"}. Information, whoever wrote ${them}`
1192
+ : `${said}, of which the last ${carried === 1 ? "one follows" : `${carried} follow, the oldest first`}, and the rest with ${command}. Information, whoever wrote ${them}`;
1193
+ };
1194
+ // What a wake holds of them together: three thousand characters, or less where the message
1195
+ // itself and the lines after them leave less of a signal's text.
1196
+ const together = Math.min(MAX_BEFORE_LENGTH, MAX_SIGNAL_LENGTH -
1197
+ wakeTextOf([...heard.saying(first), { says: leads(1, true) }, ...answering]).length -
1198
+ 200);
1199
+ const room = together - 1;
1200
+ // Few share it among them, so that one long message is read whole where it is the only one:
1201
+ // of each, that much divided by how many are carried, less the line that leads it. Each of
1202
+ // five and more is cut at the least a message is carried of.
1203
+ const most = Math.max(MAX_BEFORE_TEXT, Math.min(MAX_BEFORE_MOST, Math.floor(together / Math.max(1, latest.length)) - BEFORE_LINE));
1062
1204
  const carried = [];
1205
+ const one = (message, parts) => ({
1206
+ ts: message.ts,
1207
+ mine: message.user !== undefined && message.user === heard.member,
1208
+ parts,
1209
+ });
1063
1210
  let length = 0;
1064
1211
  for (const message of latest) {
1065
- const parts = earlierOf(message, heard, who);
1212
+ const parts = earlierOf(message, heard, who, most);
1066
1213
  const takes = wakeTextOf(parts).length + 1;
1067
1214
  if (length + takes > room) {
1068
1215
  break;
1069
1216
  }
1070
- carried.unshift({ ts: message.ts, parts });
1217
+ carried.unshift(one(message, parts));
1071
1218
  length += takes;
1072
1219
  }
1220
+ // A message takes more of a wake than its characters where its lines are many, each begun as
1221
+ // a signal's text begins one. The latest is cut shorter until it fits, down to the least a
1222
+ // message is carried of, rather than left out where it is all there is to carry.
1223
+ const newest = latest[0];
1224
+ for (let less = Math.floor(most / 2); carried.length === 0 && newest !== undefined && most > MAX_BEFORE_TEXT; less = Math.floor(less / 2)) {
1225
+ const cut = Math.max(MAX_BEFORE_TEXT, less);
1226
+ const parts = earlierOf(newest, heard, who, cut);
1227
+ if (wakeTextOf(parts).length + 1 <= room) {
1228
+ carried.push(one(newest, parts));
1229
+ }
1230
+ if (cut === MAX_BEFORE_TEXT) {
1231
+ break;
1232
+ }
1233
+ }
1073
1234
  return {
1074
1235
  parts: [
1075
- { says: leads(carried.length) },
1236
+ {
1237
+ says: leads(carried.length, carried.some((one) => one.mine)),
1238
+ },
1076
1239
  ...carried.flatMap((one) => [...one.parts]),
1077
1240
  ...answering,
1078
1241
  ],
1079
1242
  read: true,
1080
1243
  carried: carried.map((one) => one.ts),
1244
+ judged: saidInFull,
1081
1245
  };
1082
1246
  }
1083
1247
  /**
@@ -1091,9 +1255,13 @@ async function beforeOf(host, heard, writer, until) {
1091
1255
  * said to the agent instructs it only where it is what woke it;
1092
1256
  * - the moment of the message, as far as the agent was brought what is said there: only where
1093
1257
  * what was said before it was read, so that a wake that carried nothing of it leaves the next
1094
- * to.
1258
+ * to;
1259
+ * - the moment at which a wake said in full, of that place, what the agent judges by whether to
1260
+ * answer.
1095
1261
  *
1096
- * The moment of a message is kept, and where it was written, never a word of one.
1262
+ * The moment of a message is kept, and where it was written, never a word of one. It is kept
1263
+ * from one runner to the next where the machine keeps it, and counts for as long as the
1264
+ * agent's conversation holds what it stands for (ADR-0166).
1097
1265
  */
1098
1266
  async function raiseOf(host, heard, reading) {
1099
1267
  const message = carriedAs(heard.channel, heard.ts);
@@ -1103,7 +1271,7 @@ async function raiseOf(host, heard, reading) {
1103
1271
  const { parts, prior } = await within(host, reading, async (until) => {
1104
1272
  // Who wrote, as the console says it (ADR-0164), is asked beside the read of the conversation
1105
1273
  // and not after it: a messenger that does not answer costs the wake's first line nothing.
1106
- const writer = whoOf(host, [heard.from], until);
1274
+ const writer = whoOf(host, [heard.from], until, heard.home);
1107
1275
  // A read that fails in a way of its own costs the wake nothing: it goes as it stands.
1108
1276
  const prior = await beforeOf(host, heard, writer, until).catch(() => ({
1109
1277
  parts: [{ says: "What was said there before it could not be read (failed)" }],
@@ -1112,8 +1280,14 @@ async function raiseOf(host, heard, reading) {
1112
1280
  }));
1113
1281
  return { parts: heard.saying(await writer), prior };
1114
1282
  });
1283
+ // Why the agent's status is not shown, where the messenger refused it (ADR-0170): said to
1284
+ // the agent once, as a line of the source's own in a wake that has room for it.
1285
+ const carried = [...parts, ...prior.parts];
1286
+ const note = slackStatusNote(host);
1287
+ const withNote = note === undefined ? undefined : [...carried, { says: note }];
1288
+ const noted = withNote !== undefined && wakeTextOf(withNote).length <= MAX_SIGNAL_LENGTH;
1115
1289
  const taken = await host
1116
- .raise({ key: heard.key, parts: [...parts, ...prior.parts] })
1290
+ .raise({ key: heard.key, parts: noted ? withNote : carried })
1117
1291
  .catch((error) => {
1118
1292
  host.log(`a wake from slack was not raised (${error instanceof Error ? error.name : "error"})`);
1119
1293
  return false;
@@ -1121,10 +1295,20 @@ async function raiseOf(host, heard, reading) {
1121
1295
  if (!taken) {
1122
1296
  return;
1123
1297
  }
1298
+ if (noted) {
1299
+ slackStatusNoted(host);
1300
+ }
1124
1301
  for (const ts of prior.carried) {
1125
- keep(host.kept, carriedAs(heard.channel, ts), "said");
1302
+ // One that woke stays one that woke, though it is carried again among what led up to this
1303
+ // message, in a conversation begun since: its own event, come again, wakes nobody twice.
1304
+ const name = carriedAs(heard.channel, ts);
1305
+ keep(host.kept, name, host.kept.get(name) === "woke" ? "woke" : "said");
1126
1306
  }
1127
1307
  keep(host.kept, message, "woke");
1308
+ if (prior.judged === true) {
1309
+ // What to judge by was said in full: the next wake there says it short (ADR-0166).
1310
+ keep(host.kept, judgedOf(heard), heard.ts);
1311
+ }
1128
1312
  if (prior.read) {
1129
1313
  const place = broughtOf(heard);
1130
1314
  const was = host.kept.get(place);
@@ -1291,6 +1475,9 @@ async function listen(host, token, hear, signal) {
1291
1475
  export const slack = {
1292
1476
  name: "slack",
1293
1477
  async run(host, signal) {
1478
+ // What a runner before this one kept comes from a file: held to the source's own shapes
1479
+ // before anything is compared with it.
1480
+ ownShapes(host.kept);
1294
1481
  const token = await host.secret(SLACK_APP_TOKEN);
1295
1482
  if (token === undefined) {
1296
1483
  host.log(`the slack wake source finds no ${SLACK_APP_TOKEN} in the account's store`);
@@ -1331,5 +1518,6 @@ export const slack = {
1331
1518
  }
1332
1519
  },
1333
1520
  read: (host, where, options) => readOf(host, where, options),
1521
+ show: (host, status, options) => showSlackStatus(host, SLACK_USER_TOKEN, status, options),
1334
1522
  };
1335
1523
  //# sourceMappingURL=slack.js.map