@supa-media/tex-contract 0.0.0-stage → 0.3.0

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 (227) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +33 -2
  3. package/package.json +16 -4
  4. package/texContract/aboutLines.cjs +117 -0
  5. package/texContract/aboutLines.d.cts +14 -0
  6. package/texContract/aboutNoteLimits.cjs +41 -0
  7. package/texContract/aboutNoteLimits.d.cts +5 -0
  8. package/texContract/actionManual.cjs +104 -0
  9. package/texContract/activityHint.cjs +40 -0
  10. package/texContract/activityHint.d.cts +4 -0
  11. package/texContract/asks.cjs +16 -0
  12. package/texContract/asks.d.cts +6 -0
  13. package/texContract/asksToFile.cjs +20 -0
  14. package/texContract/asksToFile.d.cts +2 -0
  15. package/texContract/attention.cjs +138 -0
  16. package/texContract/attention.d.cts +20 -0
  17. package/texContract/browserHandback.cjs +13 -0
  18. package/texContract/browserHandback.d.cts +3 -0
  19. package/texContract/browserOwner.cjs +31 -0
  20. package/texContract/browserOwner.d.cts +2 -0
  21. package/texContract/bytes.cjs +12 -0
  22. package/texContract/capabilities.cjs +47 -0
  23. package/texContract/capabilities.d.cts +27 -0
  24. package/texContract/capabilities.generated.json +77 -0
  25. package/texContract/chatHistoryPath.cjs +38 -0
  26. package/texContract/chatHistoryPath.d.cts +5 -0
  27. package/texContract/chatLedger.cjs +91 -0
  28. package/texContract/chatLedger.d.cts +21 -0
  29. package/texContract/computerTool.cjs +102 -0
  30. package/texContract/computerTool.d.cts +16 -0
  31. package/texContract/consentYes.cjs +22 -0
  32. package/texContract/consentYes.d.cts +5 -0
  33. package/texContract/contextGateway.cjs +52 -0
  34. package/texContract/contextGateway.d.cts +19 -0
  35. package/texContract/deskEligible.cjs +20 -0
  36. package/texContract/deskEligible.d.cts +3 -0
  37. package/texContract/downloads.cjs +129 -0
  38. package/texContract/downloads.d.cts +15 -0
  39. package/texContract/egressLedger.cjs +114 -0
  40. package/texContract/egressLedger.d.cts +14 -0
  41. package/texContract/emailRead.cjs +38 -0
  42. package/texContract/emailRead.d.cts +5 -0
  43. package/texContract/eventWords.cjs +35 -0
  44. package/texContract/eventWords.d.cts +4 -0
  45. package/texContract/fileParts.cjs +43 -0
  46. package/texContract/fileParts.d.cts +6 -0
  47. package/texContract/fileTables.cjs +243 -0
  48. package/texContract/fileWords.cjs +169 -0
  49. package/texContract/folded.cjs +16 -0
  50. package/texContract/folded.d.cts +3 -0
  51. package/texContract/googleAiAccess.cjs +12 -0
  52. package/texContract/googleAiAccess.d.cts +2 -0
  53. package/texContract/graphWires.cjs +18 -0
  54. package/texContract/graphWires.d.cts +5 -0
  55. package/texContract/groupSession.cjs +28 -0
  56. package/texContract/groupSession.d.cts +7 -0
  57. package/texContract/guestNames.cjs +136 -0
  58. package/texContract/guestNames.d.cts +35 -0
  59. package/texContract/heard.cjs +19 -0
  60. package/texContract/heard.d.cts +4 -0
  61. package/texContract/heldOffer.cjs +57 -0
  62. package/texContract/heldOffer.d.cts +8 -0
  63. package/texContract/helperCallers.cjs +29 -0
  64. package/texContract/helperCallers.d.cts +4 -0
  65. package/texContract/identity.cjs +179 -0
  66. package/texContract/identity.d.cts +8 -0
  67. package/texContract/jobLogEntries.cjs +93 -0
  68. package/texContract/jobLogEntries.d.cts +12 -0
  69. package/texContract/judgedActions.cjs +20 -0
  70. package/texContract/judgedActions.d.cts +4 -0
  71. package/texContract/labSandboxGate.cjs +63 -0
  72. package/texContract/labSandboxGate.d.cts +9 -0
  73. package/texContract/ledgerReadChars.cjs +4 -0
  74. package/texContract/ledgerReadChars.d.cts +3 -0
  75. package/texContract/mailCheck.cjs +90 -0
  76. package/texContract/mailCheck.d.cts +12 -0
  77. package/texContract/mailEntries.cjs +64 -0
  78. package/texContract/mailEntries.d.cts +13 -0
  79. package/texContract/mailHealth.cjs +60 -0
  80. package/texContract/mailHealth.d.cts +10 -0
  81. package/texContract/notePath.cjs +99 -0
  82. package/texContract/notePath.d.cts +4 -0
  83. package/texContract/noteRunFacts.cjs +136 -0
  84. package/texContract/noteRunFacts.d.cts +32 -0
  85. package/texContract/objectEtag.cjs +84 -0
  86. package/texContract/objectEtag.d.cts +4 -0
  87. package/texContract/objectPlace.cjs +32 -0
  88. package/texContract/objectPlace.d.cts +5 -0
  89. package/texContract/pageJobs.cjs +226 -0
  90. package/texContract/pageJobs.d.cts +13 -0
  91. package/texContract/pdfLinks.cjs +135 -0
  92. package/texContract/pdfLinks.d.cts +4 -0
  93. package/texContract/personHub.cjs +38 -0
  94. package/texContract/personHub.d.cts +5 -0
  95. package/texContract/personNameText.cjs +18 -0
  96. package/texContract/personNameText.d.cts +3 -0
  97. package/texContract/pinnedContext.cjs +12 -0
  98. package/texContract/pinnedContext.d.cts +3 -0
  99. package/texContract/quietHoursWindow.cjs +36 -0
  100. package/texContract/quietHoursWindow.d.cts +3 -0
  101. package/texContract/reactEmoji.cjs +79 -0
  102. package/texContract/reactEmoji.d.cts +2 -0
  103. package/texContract/scopeClamp.cjs +117 -0
  104. package/texContract/scopeClamp.d.cts +5 -0
  105. package/texContract/scopes.cjs +29 -0
  106. package/texContract/scopes.d.cts +7 -0
  107. package/texContract/searchSettings.cjs +54 -0
  108. package/texContract/searchSettings.d.cts +6 -0
  109. package/texContract/settingHabits.cjs +87 -0
  110. package/texContract/settingHabits.d.cts +20 -0
  111. package/texContract/settingsNotes.cjs +217 -0
  112. package/texContract/settingsNotes.d.cts +26 -0
  113. package/texContract/shownEmail.cjs +181 -0
  114. package/texContract/texClients.cjs +53 -0
  115. package/texContract/texClients.d.cts +12 -0
  116. package/texContract/texGraph.cjs +593 -0
  117. package/texContract/texGraph.d.cts +55 -0
  118. package/texContract/texKeys.cjs +100 -0
  119. package/texContract/texKeys.d.cts +13 -0
  120. package/texContract/texNumber.cjs +20 -0
  121. package/texContract/texNumber.d.cts +3 -0
  122. package/texContract/texOwnSources.cjs +9 -0
  123. package/texContract/texOwnSources.d.cts +3 -0
  124. package/texContract/texSettings.cjs +22 -0
  125. package/texContract/texSettings.d.cts +20 -0
  126. package/texContract/texSettings.generated.json +25 -0
  127. package/texContract/texStateFiles.cjs +22 -0
  128. package/texContract/texStateFiles.d.cts +9 -0
  129. package/texContract/texSteps.cjs +27 -0
  130. package/texContract/texSteps.d.cts +14 -0
  131. package/texContract/texSteps.generated.json +41 -0
  132. package/texContract/texStoreNames.cjs +26 -0
  133. package/texContract/texStoreNames.d.cts +12 -0
  134. package/texContract/texStoreWire.cjs +306 -0
  135. package/texContract/texStoreWire.d.cts +32 -0
  136. package/texContract/threadsFold.cjs +75 -0
  137. package/texContract/threadsFold.d.cts +22 -0
  138. package/texContract/toolActions.cjs +253 -0
  139. package/texContract/toolCatalog.cjs +49 -0
  140. package/texContract/toolCatalog.generated.json +90 -0
  141. package/texContract/toolContract.cjs +52 -0
  142. package/texContract/toolContract.d.cts +12 -0
  143. package/texContract/toolShapes.cjs +14 -0
  144. package/texContract/transcription.cjs +101 -0
  145. package/texContract/transcription.d.cts +3 -0
  146. package/texContract/treeJobs.cjs +31 -0
  147. package/texContract/treeJobs.d.cts +3 -0
  148. package/texContract/turnSession.cjs +90 -0
  149. package/texContract/turnSession.d.cts +19 -0
  150. package/texContract/turnWords.cjs +90 -0
  151. package/texContract/turnWords.d.cts +9 -0
  152. package/texContract/uploadImages.cjs +131 -0
  153. package/texContract/uploadImages.d.cts +13 -0
  154. package/texContract/v2Names.cjs +41 -0
  155. package/texContract/v2SearchFetch.cjs +316 -0
  156. package/texContract/v2Translate.cjs +123 -0
  157. package/texContract/vaultTools.cjs +112 -0
  158. package/texContract/vaultTools.d.cts +15 -0
  159. package/texContract/yesWords.cjs +91 -0
  160. package/texShared/argumentCoercion.cjs +93 -0
  161. package/texShared/cellComments.cjs +122 -0
  162. package/texShared/cellComments.d.cts +21 -0
  163. package/texShared/comments.cjs +586 -0
  164. package/texShared/comments.d.cts +115 -0
  165. package/texShared/contentTypes.cjs +85 -0
  166. package/texShared/fileKinds.cjs +123 -0
  167. package/texShared/flags.cjs +159 -0
  168. package/texShared/flags.d.cts +23 -0
  169. package/texShared/folderJobInfo.cjs +301 -0
  170. package/texShared/folderJobInfo.d.cts +40 -0
  171. package/texShared/folderRoles.cjs +512 -0
  172. package/texShared/folderRoles.d.cts +73 -0
  173. package/texShared/githubOidc.ts +98 -0
  174. package/texShared/groupRunQuestions.cjs +98 -0
  175. package/texShared/groupRunQuestions.d.cts +4 -0
  176. package/texShared/inboxFolders.cjs +49 -0
  177. package/texShared/inboxFolders.d.cts +5 -0
  178. package/texShared/ink/drawing.cjs +474 -0
  179. package/texShared/ink/texFigure.cjs +252 -0
  180. package/texShared/ink/texFigure.d.cts +36 -0
  181. package/texShared/ink/texPoses.cjs +180 -0
  182. package/texShared/ink/texPoses.d.cts +20 -0
  183. package/texShared/jobPartEnd.cjs +133 -0
  184. package/texShared/jobPartEnd.d.cts +13 -0
  185. package/texShared/jobResume.cjs +31 -0
  186. package/texShared/jobResume.d.cts +5 -0
  187. package/texShared/jobSplit.cjs +90 -0
  188. package/texShared/jobSplit.d.cts +6 -0
  189. package/texShared/jobStart.cjs +56 -0
  190. package/texShared/jobStart.d.cts +9 -0
  191. package/texShared/mail.cjs +400 -0
  192. package/texShared/mail.d.cts +56 -0
  193. package/texShared/messageAnchors.cjs +38 -0
  194. package/texShared/models/aiKeys.cjs +137 -0
  195. package/texShared/models/aiKeys.d.cts +42 -0
  196. package/texShared/models/aiKeys.json +56 -0
  197. package/texShared/models/creditRest.cjs +269 -0
  198. package/texShared/models/promptBudget.cjs +295 -0
  199. package/texShared/models/promptSections.cjs +29 -0
  200. package/texShared/noteAppLink.cjs +23 -0
  201. package/texShared/notePreview.cjs +219 -0
  202. package/texShared/notePreview.d.cts +21 -0
  203. package/texShared/pages/blocks.cjs +215 -0
  204. package/texShared/pages/cover.cjs +164 -0
  205. package/texShared/pages/css.cjs +181 -0
  206. package/texShared/pages/cssBlocks.cjs +264 -0
  207. package/texShared/pages/draw.cjs +212 -0
  208. package/texShared/pages/drawRich.cjs +232 -0
  209. package/texShared/pages/html.cjs +168 -0
  210. package/texShared/pages/inline.cjs +251 -0
  211. package/texShared/pages/layout.cjs +76 -0
  212. package/texShared/pages/parse.cjs +418 -0
  213. package/texShared/pages/render.cjs +200 -0
  214. package/texShared/pages/skill.cjs +147 -0
  215. package/texShared/pages/skill.d.cts +5 -0
  216. package/texShared/pages/templates.cjs +336 -0
  217. package/texShared/r2Store.cjs +163 -0
  218. package/texShared/remoteImage.cjs +177 -0
  219. package/texShared/routines.cjs +656 -0
  220. package/texShared/routines.d.cts +86 -0
  221. package/texShared/servedListing.cjs +250 -0
  222. package/texShared/servedListing.d.cts +17 -0
  223. package/texShared/sheetCsv.cjs +566 -0
  224. package/texShared/sheetCsv.d.cts +91 -0
  225. package/texShared/storageLayout.cjs +88 -0
  226. package/texShared/storeKeys.cjs +144 -0
  227. package/texShared/toolArguments.cjs +323 -0
@@ -0,0 +1,181 @@
1
+ "use strict";
2
+ /**
3
+ * "SEND" TO AN EMAIL TEX SHOWED IS THE YES TO THAT COPY (Training, trial-hire 123, 2026-11-19).
4
+ *
5
+ * Tex showed John the whole email in its text and asked "Send?"; John said "send". Two things went wrong, both here:
6
+ *
7
+ * - "Send?" was not read as an offer (`claimCheck.js` `offersAHeldChange` knows "Want me to send it?", "Say yes and
8
+ * I'll send it", a To:/Subject: preview), so John's "send" agreed to nothing (`session.egress.liked` stayed unset)
9
+ * and the email could only be held for a second 👍. `lastShownSend` reads such a text as the words they agreed to.
10
+ * - Tex then wrote the email again in other words before calling send_email, and the Mail checker, reading John's
11
+ * "send" against a copy he had never seen, refused it. Their yes covers the copy they read and nothing else, so a
12
+ * rewrite is sent back to Tex once with the copy they saw (`shownCopyOf`), to call again with exactly that.
13
+ *
14
+ * And the recipient: Tex named it in an earlier text of the same ask ("Send to bram.visser@example.com on his
15
+ * thread?"), and later showed only the reworded body. `recipientsShown` finds every recipient in Tex's own recent
16
+ * texts; the email then goes at once only when the Mail checker, reading the same texts, says they asked for it, and
17
+ * Tex's own texts lately held the body word for word (`emailShown`, below; 2026-11-26).
18
+ */
19
+
20
+ const { folded } = require("./folded.cjs");
21
+
22
+ /** A text that ends by asking whether to send: "Send?", "Send it? 👍 or 👎?", "Send to bram@x.com on his thread?". */
23
+ const SEND_ASK = /(?:^|\n)\s*(?:(?:ok(?:ay)?\s+to|should\s+I|shall\s+I)\s+)?send(?:\s+(?:it|this|that|the email|the reply))?(?:\s+(?:to|on|as)\b[^?\n]{0,160})?\s*\?[\s\u{1F44D}\u{1F44E}or?]*$/iu;
24
+
25
+ /** Whether Tex's text ends by asking whether to send what it showed. */
26
+ function asksToSend(text) {
27
+ return SEND_ASK.test(String(text ?? "").trimEnd());
28
+ }
29
+
30
+ /** Tex's last text when it ends by asking "Send?" (`asksToSend`); null otherwise. */
31
+ function lastShownSend(history) {
32
+ const said = (Array.isArray(history) ? history : []).filter((turn) => turn?.role === "assistant" && typeof turn.text === "string").at(-1)?.text;
33
+ return typeof said === "string" && asksToSend(said) ? said : null;
34
+ }
35
+
36
+ const wordsOf = (text) => folded(String(text ?? "")).split(" ").filter(Boolean);
37
+
38
+ /** The share of either text's distinct words the other has too, the smaller of the two. */
39
+ function overlap(a, b) {
40
+ const [x, y] = [new Set(wordsOf(a)), new Set(wordsOf(b))];
41
+ if (x.size === 0 || y.size === 0) return 0;
42
+ const both = [...x].filter((word) => y.has(word)).length;
43
+ return Math.min(both / x.size, both / y.size);
44
+ }
45
+
46
+ /** At least this much of a shown copy must be the email's own words for it to be the same email. */
47
+ const SAME_EMAIL = 0.6;
48
+ /** A copy shorter than this is not an email anybody approved by reading it. */
49
+ const MIN_COPY = 40;
50
+
51
+ /**
52
+ * The copy of this email they were shown, when it differs from `body`: the lines of `liked` from the one that opens
53
+ * as the body opens (its first three words) to the one that ends as it ends (its last two), when those lines share
54
+ * most of their words with the body. Null when they saw this body word for word, or nothing like it.
55
+ */
56
+ function shownCopyOf(liked, body) {
57
+ if (typeof liked !== "string" || typeof body !== "string") return null;
58
+ const words = wordsOf(body);
59
+ if (words.length < 5) return null;
60
+ const opens = words.slice(0, 3).join(" ");
61
+ const ends = words.slice(-2).join(" ");
62
+ const lines = liked.split("\n");
63
+ const start = lines.findIndex((line) => wordsOf(line).join(" ").startsWith(opens));
64
+ if (start === -1) return null;
65
+ let end = -1;
66
+ // The first line that ends as it ends: a text showing two emails never runs one into the next.
67
+ for (let i = start; i < lines.length && end === -1; i += 1) if (` ${wordsOf(lines[i]).join(" ")}`.endsWith(` ${ends}`)) end = i;
68
+ if (end === -1) return null;
69
+ const shown = lines.slice(start, end + 1).join("\n").trim();
70
+ if (shown.length < MIN_COPY || overlap(shown, body) < SAME_EMAIL) return null;
71
+ return wordsOf(shown).join(" ") === words.join(" ") ? null : shown;
72
+ }
73
+
74
+ /** How many of the latest history turns are read for a recipient Tex named: the Mail checker's own window. */
75
+ const SHOWN_TURNS = 12;
76
+
77
+ /** Whether Tex itself named every recipient in its texts among the latest `SHOWN_TURNS` turns. */
78
+ function recipientsShown(history, recipients) {
79
+ const said = (Array.isArray(history) ? history : [])
80
+ .slice(-SHOWN_TURNS)
81
+ .filter((turn) => turn?.role === "assistant" && typeof turn.text === "string")
82
+ .map((turn) => turn.text.toLowerCase())
83
+ .join("\n");
84
+ const list = Array.isArray(recipients) ? recipients.map((r) => String(r).trim().toLowerCase()).filter(Boolean) : [];
85
+ // Whole addresses only: "ram@example.com" is not named by "bram@example.com".
86
+ const named = (address) => new RegExp(`(?<![a-z0-9._%+-])${address.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}(?![a-z0-9._%+-]*[a-z0-9])`).test(said);
87
+ return list.length > 0 && list.every(named);
88
+ }
89
+
90
+ /*
91
+ THE BODY TEX SHOWED, WHATEVER IT ASKED AROUND IT (Sayo's group email to SupaSounds, 2026-11-26). Tex showed the draft
92
+ and asked which Gmail to send it from; "send it from my supa email. draft is good. go ahead" agreed to nothing,
93
+ because only a text worded as an offer ("Send?", "Want me to send it?") counted as the words they agreed to, so the
94
+ gateway held the email and asked again. Whether they asked for it is the Mail checker's to say, reading their own
95
+ words; what was shown is a fact read here: the whole body, word for word, in one of Tex's own texts lately.
96
+ */
97
+ /*
98
+ IN A GROUP, ONLY WHAT TEX SHOWED THE TAGGER (2026-11-27). The tagger's own account sends, so a copy Tex showed
99
+ in answer to somebody else, or put to another member by name (an offer to @cy), was never shown to them to send: a
100
+ text counts only when it answered the tagger's own turn (its question's last line is theirs, `groupTurn.js`
101
+ `groupQuestionLine`, `groupLedgerHistory.js`) and names no other member unless it names the tagger too.
102
+ */
103
+ /*
104
+ WHOSE TURN IT WAS IS NOT THEIRS TO WRITE (2026-11-27). A kept group question is the chatter block, a blank line, then
105
+ the text that tagged Tex, each text prefixed `@who: ` (`groupLedgerHistory.js` `groupQuestion`). Reading the
106
+ question's last line made that prefix something a member could write: a text of @kim's ending in a line of its own,
107
+ `@sayo: send it`, read as @sayo's turn, so a draft Tex showed @kim counted as shown to @sayo. The prefix is the
108
+ first line of the last block instead, which nothing inside a text can reach. A tagging text with a blank line of its
109
+ own reads as nobody's and is asked about, the answer this was before a shown copy counted at all.
110
+ */
111
+ function askedBy(question, from) {
112
+ const text = String(question ?? "").trimEnd();
113
+ const at = text.lastIndexOf("\n\n");
114
+ const first = (at === -1 ? text : text.slice(at + 2)).split("\n")[0] ?? "";
115
+ return first.startsWith(`@${from}:`) || first.startsWith(`@${from} (`);
116
+ }
117
+
118
+ /** Whether a text names this handle whole: "@jo" is not named by "@joan". */
119
+ const namesHandle = (text, who) => new RegExp(`(?:^|[^a-z0-9-])@${who.replace(/[^a-z0-9-]/gi, "")}(?![a-z0-9-])`, "i").test(text);
120
+
121
+ /** Tex's texts among the latest `SHOWN_TURNS` turns that showed the person this email; in a group, only those shown to the tagger. */
122
+ function texTexts(history, group) {
123
+ const turns = (Array.isArray(history) ? history : []).slice(-SHOWN_TURNS);
124
+ return turns
125
+ .map((turn, at) => ({ turn, asked: turns.slice(0, at).findLast((before) => before?.role === "user") }))
126
+ .filter(({ turn }) => turn?.role === "assistant" && typeof turn.text === "string")
127
+ .filter(({ turn, asked }) => {
128
+ if (!group?.from) return true;
129
+ if (!askedBy(asked?.text, group.from)) return false;
130
+ const others = (Array.isArray(group.people) ? group.people : []).filter((who) => typeof who === "string" && who !== group.from);
131
+ return namesHandle(turn.text, group.from) || !others.some((who) => namesHandle(turn.text, who));
132
+ })
133
+ .map(({ turn }) => turn.text);
134
+ }
135
+
136
+ /** A text's words with a space each side, so a run of words is found whole. */
137
+ const runOf = (text) => ` ${wordsOf(text).join(" ")} `;
138
+
139
+ /** The opening and closing words that name which email a later copy of it is, as `shownCopyOf` anchors on. */
140
+ const OPENS_WORDS = 3;
141
+ const ENDS_WORDS = 2;
142
+
143
+ /*
144
+ A LATER COPY REPLACES THE ONE IT CHANGED (2026-11-27). Tex showed a draft, they asked for its last sentence out, Tex
145
+ showed the shorter copy, and they said "yes send it": their go-ahead is about the copy they were shown last, and the
146
+ one they had just turned down is not theirs to send. The Mail checker reads a cut sentence as no contradiction, so
147
+ nothing else holds it. A body is therefore shown only until Tex shows the same email in other words: a text that
148
+ opens as the body opens and does not hold it whole.
149
+ */
150
+ function replacedIn(texts, body, words) {
151
+ const said = wordsOf(body);
152
+ const anchors = [said.slice(0, OPENS_WORDS).join(" "), said.slice(-ENDS_WORDS).join(" ")].filter((anchor) => anchor !== "");
153
+ if (anchors.length === 0) return false;
154
+ // Either anchor: a copy may change the opening ("Dear Bram", not "Hi Bram") as readily as the words between.
155
+ return texts.some((text) => !runOf(text).includes(` ${words} `) && anchors.some((anchor) => runOf(text).includes(` ${anchor} `)));
156
+ }
157
+
158
+ /**
159
+ * Whether one of Tex's texts among the latest `SHOWN_TURNS` turns holds this body whole, word for word, with no later
160
+ * text of its own showing the same email in other words (`replacedIn`).
161
+ */
162
+ function bodyShown(history, body, group = null) {
163
+ if (typeof body !== "string" || body.trim().length < MIN_COPY) return false;
164
+ const words = wordsOf(body).join(" ");
165
+ if (words === "") return false;
166
+ const texts = texTexts(history, group);
167
+ const last = texts.findLastIndex((text) => runOf(text).includes(` ${words} `));
168
+ if (last === -1) return false;
169
+ return !replacedIn(texts.slice(last + 1), body, words);
170
+ }
171
+
172
+ /**
173
+ * Whether Tex itself showed this email lately: every recipient named and the whole body, in its own texts; in a group
174
+ * (`group`: `{ from, people }`), in texts that answered the tagger and were not put to somebody else.
175
+ */
176
+ function emailShown(history, recipients, body, group = null) {
177
+ const shown = group?.from ? texTexts(history, group).map((text) => ({ role: "assistant", text })) : history;
178
+ return recipientsShown(shown, recipients) && bodyShown(history, body, group);
179
+ }
180
+
181
+ module.exports = { asksToSend, lastShownSend, shownCopyOf, SHOWN_TURNS, recipientsShown, bodyShown, emailShown };
@@ -0,0 +1,53 @@
1
+ /**
2
+ * The texting clients, as the control plane names them, and how long a texting token lives.
3
+ *
4
+ * The gateway's routing and Tex both compare a session's client against these, so they are one copy for both.
5
+ * `machines/reach.js` and `workspaceStore/personTexting.js` re-export them.
6
+ */
7
+
8
+ /** The texting client, as the control plane names it (`TEXTS_CLIENT_ID`). */
9
+ const TEXTS_CLIENT_ID = "context_texts";
10
+ /** The group texting client, kept with the group predicates (`groupSession.cjs`). */
11
+ const { TEXTS_GROUP_CLIENT_ID } = require("./groupSession.cjs");
12
+ /** How long a texting token lives, as the control plane's `TEXTS_GRANT_TTL_MS`. */
13
+ const TEXTING_TOKEN_MS = 15 * 60 * 1000;
14
+
15
+ /**
16
+ * Tex's background runs' first-party clients, as the control plane names them (`apps/convex/functions/lib/dreams`,
17
+ * `heartbeats`, and the housekeeping loop). Decided by the grant. The gateway's routing tells each run's session by
18
+ * them, and Tex's runs are made under them, so they are one copy for both.
19
+ */
20
+ const DREAMS_CLIENT_ID = "context_dreams";
21
+ const HEARTBEAT_CLIENT_ID = "context_heartbeat";
22
+ const HOUSEKEEPING_CLIENT_ID = "context_housekeeping";
23
+
24
+ /** Routines' runs' client, as the control plane names it (`apps/convex/functions/lib/routines/model.ts`). */
25
+ const ROUTINES_CLIENT_ID = "context_routines";
26
+
27
+ /**
28
+ * Tex's own clients: the only connections that may speak in note mail under a roster name (`tex`, `advisor`), joined
29
+ * or not (#4543). A client's registered name is text it asserted and never one of these; an AI client that called
30
+ * itself "Tex" signed as the person's Tex and held their Tex's seat on the note.
31
+ */
32
+ const TEX_OWN_CLIENT_IDS = Object.freeze([TEXTS_CLIENT_ID, TEXTS_GROUP_CLIENT_ID, DREAMS_CLIENT_ID, HEARTBEAT_CLIENT_ID, HOUSEKEEPING_CLIENT_ID, ROUTINES_CLIENT_ID]);
33
+
34
+ /** The names on every job note besides its jobs (`packages/tex/gateway/agent/jobNote.js`): Tex and the advisor. */
35
+ const MAIL_ROSTER_NAMES = Object.freeze(["tex", "advisor"]);
36
+
37
+ /** Whether a grant's client is one of Tex's own, by the id the control plane issued. */
38
+ function isTexOwnClient(clientId) {
39
+ return typeof clientId === "string" && TEX_OWN_CLIENT_IDS.includes(clientId);
40
+ }
41
+
42
+ module.exports = {
43
+ TEXTS_CLIENT_ID,
44
+ TEXTS_GROUP_CLIENT_ID,
45
+ TEXTING_TOKEN_MS,
46
+ DREAMS_CLIENT_ID,
47
+ HEARTBEAT_CLIENT_ID,
48
+ HOUSEKEEPING_CLIENT_ID,
49
+ ROUTINES_CLIENT_ID,
50
+ TEX_OWN_CLIENT_IDS,
51
+ MAIL_ROSTER_NAMES,
52
+ isTexOwnClient,
53
+ };
@@ -0,0 +1,12 @@
1
+ /** Types for `texClients.cjs`; see that file for the reasons. */
2
+
3
+ export declare const TEXTS_CLIENT_ID: "context_texts";
4
+ export declare const TEXTS_GROUP_CLIENT_ID: "context_texts_group";
5
+ export declare const TEXTING_TOKEN_MS: number;
6
+ export declare const DREAMS_CLIENT_ID: "context_dreams";
7
+ export declare const HEARTBEAT_CLIENT_ID: "context_heartbeat";
8
+ export declare const HOUSEKEEPING_CLIENT_ID: "context_housekeeping";
9
+ export declare const ROUTINES_CLIENT_ID: "context_routines";
10
+ export declare const TEX_OWN_CLIENT_IDS: readonly string[];
11
+ export declare const MAIL_ROSTER_NAMES: readonly ["tex", "advisor"];
12
+ export declare function isTexOwnClient(clientId: unknown): boolean;