@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,35 @@
1
+ /** Types for `guestNames.cjs`; see that file. */
2
+
3
+ export interface GuestName {
4
+ guest: string;
5
+ name: string;
6
+ aliases?: string[];
7
+ }
8
+ export interface MemberAliases {
9
+ member: string;
10
+ aliases: string[];
11
+ }
12
+ export interface GuestNumber {
13
+ guest: string;
14
+ phone: string;
15
+ }
16
+ export interface NameEntryOptions {
17
+ by?: string;
18
+ turn?: string | null;
19
+ at?: number;
20
+ }
21
+ export interface NamesLedger {
22
+ read(chat: string, options: { before: number; kinds: string[]; limit: number }): Promise<{ entries?: unknown[] } | null | undefined>;
23
+ }
24
+ export declare const GUEST: RegExp;
25
+ export declare const PHONE: RegExp;
26
+ export declare const HANDLE: RegExp;
27
+ export declare const MAX_NAMES: number;
28
+ export declare const MAX_ALIASES: number;
29
+ export declare function guestNameEntry(guest: string, name: string, options?: NameEntryOptions): Record<string, unknown>;
30
+ export declare function guestNamesFrom(entries: unknown): GuestName[];
31
+ export declare function memberNameEntry(member: string, name: string, options?: NameEntryOptions): Record<string, unknown>;
32
+ export declare function memberAliasesFrom(entries: unknown): MemberAliases[];
33
+ export declare function readChatNames(ledger: NamesLedger | null | undefined, chat: string): Promise<{ guests: GuestName[]; members: MemberAliases[] }>;
34
+ export declare function readGuestNames(ledger: NamesLedger | null | undefined, chat: string): Promise<GuestName[]>;
35
+ export declare function readGuestNumbers(ledger: NamesLedger | null | undefined, chat: string): Promise<GuestNumber[] | null>;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * What the transcription service heard, read the same way by Tex's turn (`packages/tex/gateway/agent/attachments.js`)
3
+ * and by Context's hearing door for a group's voice message (`apps/mcp/src/http/textsHear.js`), so the two never drift.
4
+ */
5
+
6
+ /** A voice message's largest size, in bytes. */
7
+ const MAX_AUDIO_BYTES = 8 * 1024 * 1024;
8
+
9
+ /** What the transcription service heard, as one paragraph, or "" for nothing. */
10
+ function heardText(payload) {
11
+ if (typeof payload?.text === "string" && payload.text.trim()) return payload.text.replace(/\s+/g, " ").trim();
12
+ const segments = Array.isArray(payload?.segments) ? payload.segments : [];
13
+ return segments
14
+ .map((segment) => (typeof segment?.text === "string" ? segment.text.trim() : ""))
15
+ .filter(Boolean)
16
+ .join(" ");
17
+ }
18
+
19
+ module.exports = { MAX_AUDIO_BYTES, heardText };
@@ -0,0 +1,4 @@
1
+ /** Types for `heard.cjs`; see that file for the reasons. */
2
+
3
+ export declare const MAX_AUDIO_BYTES: number;
4
+ export declare function heardText(payload: unknown): string;
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Whether an answer offers a held change: a calendar change, an email, a Slack message or a bug report, asked in the
3
+ * answer's own words, which only a yes may make. `claimCheck.js` holds its notice on it (`offerNotice`) and the
4
+ * gateway's liked-preview check (`tools/likedPreview.js`) reads it the same way, so both sides name one offer alike.
5
+ */
6
+
7
+ /*
8
+ An offer to make a change only a yes may make: a question to them about
9
+ adding, moving or cancelling something at a day or time or on their
10
+ calendar, or about sending, forwarding or replying to an email.
11
+ */
12
+ const OFFER = /\b(?:want me to|shall I|should I|do you want me to|would you like me to|ok(?:ay)? (?:if I|to))\b([^?]{0,200})\?/gi;
13
+ const CALENDAR_CHANGE = /\b(?:add|put|schedule|book|block|move|reschedule|cancel)\b/i;
14
+ const WHEN =
15
+ /\b(?:calendar|today|tonight|tomorrow|monday|tuesday|wednesday|thursday|friday|saturday|sunday|\d{1,2}(?::\d{2})?\s*(?:am|pm)|\d{1,2}(?::\d{2})?\s*(?:to|-|\u2013)\s*\d{1,2})\b/i;
16
+ /** Their own list or notes, which take no yes: "add a to-do for Friday". */
17
+ const NOT_CALENDAR = /\b(?:to-?dos?|list|notes?|reminders?)\b/i;
18
+ const EMAIL_SEND = /\b(?:email|e-mail|forward|reply to|write back|file (?:a|the|it|that)|send (?:it|that|this|the (?:email|reply|note)|(?:an? )?(?:email|reply))|send \w+ (?:an? )?(?:email|note|reply))\b/i;
19
+
20
+ /** An email laid out in the answer's own words: "To: …", "Subject: …", "Forward of: …". */
21
+ const PREVIEW_LINE = /^\s*(?:to|cc|subject|forward(?:ing)? of|fwd)\s*:/im;
22
+ /** Asking for their yes or 👍 in the answer's own words. */
23
+ // "Say the word and I'll send it", "just say go", "let me know and I'll post it" (2026-10-22: a 👍 on each reached nothing).
24
+ // "Text me yourself with a yes and I'll send it" (2026-11-26, a group's shared mailbox: nothing held, so a yes sent nothing).
25
+ const YES_ASK = /\b(?:say|reply|text|answer|send)\s+(?:yes|ok|okay|go)\b|\bsay the word\b|\bjust say\b|\blet me know (?:and|if)\b|\bgive (?:it|this|me) a\b|\bwith\s+(?:a|your|their|his|her)\s+(?:yes|ok|okay)\b|\b(?:gives?|sends?)\s+(?:a|your|their|his|her|me)\s+(?:yes|ok|okay|go-ahead)\b|\u{1F44D}/iu;
26
+ /** What a yes or 👍 might be asked about that only a held call can make: "sending it again" too. */
27
+ const HELD_THING = /\b(?:send(?:ing)?|email(?:ing)?|forward(?:ing)?|calendar|schedul(?:e|ing)|book(?:ing)?|fil(?:e|ing)|bug|report|slack|chat|dm|post(?:ing)?)\b/i;
28
+ /*
29
+ A calendar change asked for in the answer's own words: "Sunday, November 1,
30
+ 3 to 5 pm, at Bethesda. Say yes and I'll add it." (2026-10-22 5:04 PM). The
31
+ verb was "add", which `HELD_THING` doesn't name, so nothing was held, their
32
+ "yes" reached a model that only then raised the hold, and they were asked a
33
+ second time for a 👍. "Add" with a day or time is a calendar change unless
34
+ it names their own list or notes.
35
+ */
36
+ const CALENDAR_ASK = {
37
+ test: (said) => CALENDAR_CHANGE.test(said) && WHEN.test(said) && (/\bcalendar\b/i.test(said) || !NOT_CALENDAR.test(said)),
38
+ };
39
+ /**
40
+ * A Slack message offered in the answer's own words (2026-10-22: "I'd DM Jo
41
+ * on Acme Slack: …", with nothing held, so the 👍 on it reached nothing).
42
+ */
43
+ const SLACK_OFFER =
44
+ /\b(?:I['’]d|I would|I['’]ll|I will|want me to|shall I|should I|do you want me to)\s+(?:DM|message|post|send|reply)\b[^\n]{0,160}?\b(?:Slack|DM)\b/i;
45
+
46
+ /** Whether an answer offers a calendar change, an email or a bug report: as a question, a preview, or a request for their yes. */
47
+ function offersAHeldChange(answer) {
48
+ const said = String(answer ?? "");
49
+ if (PREVIEW_LINE.test(said) || SLACK_OFFER.test(said)) return true;
50
+ if (YES_ASK.test(said) && (HELD_THING.test(said) || CALENDAR_ASK.test(said))) return true;
51
+ for (const [, offered] of said.matchAll(OFFER)) {
52
+ if ((CALENDAR_CHANGE.test(offered) && WHEN.test(offered) && (/\bcalendar\b/i.test(offered) || !NOT_CALENDAR.test(offered))) || EMAIL_SEND.test(offered)) return true;
53
+ }
54
+ return false;
55
+ }
56
+
57
+ module.exports = { offersAHeldChange, PREVIEW_LINE, SLACK_OFFER, CALENDAR_CHANGE, WHEN };
@@ -0,0 +1,8 @@
1
+ /** Types for `heldOffer.cjs`; see that file. */
2
+
3
+ export declare const PREVIEW_LINE: RegExp;
4
+ export declare const SLACK_OFFER: RegExp;
5
+ export declare const CALENDAR_CHANGE: RegExp;
6
+ export declare const WHEN: RegExp;
7
+
8
+ export declare function offersAHeldChange(answer: unknown): boolean;
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Who may call a helper agent, from its note's `callers:` in the pinned workspace (`ai/agents/<key>.md`, the AI
3
+ * tab's "who may call it" switches). The gateway's email gate (`tools/emailGate.js`) reads the Mail checker's this
4
+ * way; the note is Tex's setup, read by Context through the caller's own reach (`orient/globalNote.js`
5
+ * `readPinnedSetupNote`).
6
+ */
7
+
8
+ const FRONT_MATTER = /^---\r?\n([\s\S]*?)\r?\n---[ \t]*(?:\r?\n|$)/;
9
+ const KEY = /^[a-z][a-z0-9-]{0,40}$/;
10
+
11
+ /** The note a helper's setup is in, or `null` for a key that is not one. */
12
+ function helperNotePath(key) {
13
+ return typeof key === "string" && KEY.test(key) ? `ai/agents/${key}.md` : null;
14
+ }
15
+
16
+ /** `callers: [a, b]` or `callers: a, b` in a note's front matter, or `null`. */
17
+ function helperCallersOf(raw) {
18
+ const front = typeof raw === "string" ? FRONT_MATTER.exec(raw) : null;
19
+ if (!front) return null;
20
+ const line = front[1].split(/\r?\n/).find((entry) => /^callers:/.test(entry));
21
+ if (line === undefined) return null;
22
+ const value = line.slice("callers:".length).trim().replace(/^\[(.*)\]$/, "$1");
23
+ return value
24
+ .split(",")
25
+ .map((item) => item.trim().replace(/^["']|["']$/g, ""))
26
+ .filter((item) => KEY.test(item));
27
+ }
28
+
29
+ module.exports = { helperNotePath, helperCallersOf };
@@ -0,0 +1,4 @@
1
+ /** Types for `helperCallers.cjs`; see that file. */
2
+
3
+ export declare function helperNotePath(key: unknown): string | null;
4
+ export declare function helperCallersOf(raw: unknown): string[] | null;
@@ -0,0 +1,179 @@
1
+ /**
2
+ * Who is acting and which contexts a session reaches: the audit actor, a
3
+ * personal context's display name, the reachable-context list, and a
4
+ * context's addressable name. Read off the session alone, so the gateway
5
+ * (`apps/mcp/src/context/identity.js`, which re-exports these) and Tex hold one copy.
6
+ */
7
+
8
+ const { reachForRole } = require("./scopeClamp.cjs");
9
+
10
+ /**
11
+ * The pinned workspace, addressed as a tool call would address it. The same value as `PINNED_CONTEXT_NAME` in
12
+ * `apps/mcp/src/orient/globalNote.js`; `apps/mcp/test/texContractIdentity.test.mjs` holds the two together.
13
+ */
14
+ const PINNED_CONTEXT_NAME = "@context-lc";
15
+
16
+ /* --------------------------------- MCP ---------------------------------- */
17
+
18
+ /**
19
+ * Who a write in this context is recorded as.
20
+ *
21
+ * One function rather than two literals, because a cross-context call builds a
22
+ * second store and the audit line on it must name the context it was written
23
+ * in. Two copies of this object is how a note filed into somebody's workspace ends
24
+ * up stamped with the workspace the client happened to connect to.
25
+ */
26
+
27
+ function actorFor(session) {
28
+ return {
29
+ workspaceId: session.workspaceId,
30
+ workspaceKind: session.workspaceKind,
31
+ // The workspace's @name, for an answer that tells an agent the context: to pass back (`botBind.js` `toolSetupBot`).
32
+ workspaceSlug: typeof session.workspaceSlug === "string" ? session.workspaceSlug : null,
33
+ userId: session.actorUserId,
34
+ clientId: session.actorClientId,
35
+ // The name the client registered: display text for the opens log (`search/opens.js`), never read for a decision.
36
+ clientName: typeof session.actorClientName === "string" ? session.actorClientName : null,
37
+ grantId: session.grantId,
38
+ // A grant made for a Tex group chat, under any client: a run on a computer started from a group is the group's
39
+ // still, and the vault gives it only the group's keys (`vault/access.js` `workspaceOnly`).
40
+ ...(typeof session.texChatId === "string" && session.texChatId !== "" ? { groupChat: true, chat: session.texChatId, ...(typeof session.texTaggerId === "string" && session.texTaggerId !== "" ? { taggerId: session.texTaggerId } : {}) } : {}),
41
+ // The two the form tools need, carried the same way and for the same
42
+ // reason: a form response records *who*, and a form's `submit` policy is
43
+ // compared against the caller's role in the context the call was routed
44
+ // to. Both are already on the session `actorFor` is built from, and both
45
+ // are ids and slugs — never a credential.
46
+ role: session.role,
47
+ // A bot's helper: its name, its bot and its note (`sessionPayload.js`), so its mail, its caret and its activity say
48
+ // "Claude via Grok Bot" (`tools/notes/botHelpers.js`). Display and signing only; it decides no access.
49
+ ...(session.helper !== undefined && session.helper !== null ? { helper: session.helper } : {}),
50
+ /**
51
+ * The `@names` this grant reaches in this workspace (its groups, and the
52
+ * person's own handles), for a vault key given to a group
53
+ * (`vault/access.js`). Names only, the set `canSee` already reads.
54
+ */
55
+ groups: [...(session.grantedGroups ?? [])],
56
+ name: personalNameFor(session),
57
+ /**
58
+ * The person's former usernames, still theirs (`docs/decisions/identity-and-access/username-changes.md`), so a
59
+ * card or a folder written under the old name (`belongs_to: "@old"`, `bots/old/`) is still theirs
60
+ * (`botFolders.cjs`; bots grouped by owner, 2026-11-28).
61
+ */
62
+ formerNames: personalAliasesFor(session),
63
+ /**
64
+ * The client's own name, for the one reader who is a person.
65
+ *
66
+ * `clientId` is an opaque registration id and says nothing to anybody; the
67
+ * activity file is a document somebody opens, and "@sayo's Claude added
68
+ * three notes" is the sentence the feature exists to produce. It is the
69
+ * name the client asserted at registration, so it is display text and
70
+ * never an identity — every authorization decision still reads
71
+ * `clientId`, which is the one the control plane issued.
72
+ */
73
+ client: typeof session.actorClientName === "string" ? session.actorClientName : null,
74
+ /** When this connection last fetched our tool list; see `tools/news.js`. */
75
+ toolsListedAt: Number.isFinite(session.toolsListedAt) ? session.toolsListedAt : null,
76
+ };
77
+ }
78
+
79
+ /**
80
+ * The caller's username — their own workspace's slug, with the `@`.
81
+ *
82
+ * A response says who wrote it, and the only name that means anything across
83
+ * contexts is the one in the global username namespace. It is read off the
84
+ * connection's covered contexts rather than passed in, so a submission cannot
85
+ * claim to be from somebody else: `submitted_by` is stamped here, never taken
86
+ * from an argument.
87
+ *
88
+ * **All three clauses are load-bearing, and `role === "owner"` is the one that
89
+ * is easy to leave out.** `session.workspaces` is every context this connection
90
+ * may address, so a personal context in it is *not* evidence that it is this
91
+ * person's: a personal workspace "may gain more members when that person shares
92
+ * it" (`schema.ts`), and `contextsForGrant` puts the context the grant was
93
+ * approved against at the head of the set. A guest who connected to
94
+ * `/@alice/mcp` therefore has Alice's personal context first in their own
95
+ * covered set, and a copy of this predicate missing the role clause named that
96
+ * guest `@alice` — in Alice's note, to Alice. The role settles it because the
97
+ * control plane writes `role: "owner"` in exactly one place, when a workspace
98
+ * is created, for its creator, and an invitation can confer `editor` or
99
+ * `member` and nothing else: one member of a personal context is its owner, and
100
+ * that owner is the person its slug names.
101
+ *
102
+ * `kind === "personal"` is load-bearing for the same reason in the other
103
+ * direction. Usernames and workspace slugs are one global namespace, so a
104
+ * shared context's slug on a caret or a signature reads as a person who does
105
+ * not exist.
106
+ *
107
+ * `null` for a connection whose person has no personal context — which is not
108
+ * a state the product produces, but is one a self-hosted deployment or a stale
109
+ * grant can, and the callers refuse or fall back rather than invent a name.
110
+ * Never `@null`: an absent slug is a missing handle, not a handle spelled
111
+ * "null", in a namespace where that is a word somebody could hold.
112
+ */
113
+ /** The caller's former usernames, each with the `@`; empty when they never changed it. */
114
+ function personalAliasesFor(session) {
115
+ const own = (session?.workspaces || []).find((entry) => entry.kind === "personal" && entry.role === "owner" && entry.slug);
116
+ return Array.isArray(own?.aliases) ? own.aliases.filter((name) => typeof name === "string" && name !== "").map((name) => `@${name}`) : [];
117
+ }
118
+
119
+ function personalNameFor(session) {
120
+ const own = (session?.workspaces || []).find(
121
+ (entry) => entry.kind === "personal" && entry.role === "owner" && entry.slug
122
+ );
123
+ return own ? `@${own.slug}` : null;
124
+ }
125
+
126
+ /**
127
+ * Whether this connection's person edits the pinned workspace `@context-lc`
128
+ * (its AI setup and its shared notes): an owner or an editor there, as the
129
+ * gateway's session says. A member or a reader, a session that does not reach
130
+ * it, and a self-hosted deployment with no pinned workspace are all `false`.
131
+ * The control plane decides again wherever it matters (`tryIt.js`, `runModel.js`).
132
+ */
133
+ function editsPinnedContext(session) {
134
+ const pinned = contextsFor(session).find((entry) => entry.name === PINNED_CONTEXT_NAME);
135
+ return pinned !== undefined && (pinned.role === "owner" || pinned.role === "editor");
136
+ }
137
+
138
+ /**
139
+ * The contexts this connection can address, as `orient` needs to name them.
140
+ *
141
+ * Request-scoped metadata on the store, like `store.actor`, because the tool
142
+ * layer takes a store and a scope and nothing else — and a reach an agent is
143
+ * never told about is a reach nobody uses.
144
+ *
145
+ * A covered context with no slug is dropped rather than listed: the name is how
146
+ * a tool call addresses one, so an entry nothing can be passed as would be an
147
+ * offer that refuses.
148
+ */
149
+ function contextsFor(session) {
150
+ return (session.workspaces || [])
151
+ .filter((entry) => typeof entry.slug === "string" && entry.slug !== "")
152
+ .map((entry) => {
153
+ /*
154
+ The role is what this connection's person holds there; the reach is what
155
+ *this connection* may do with it, which is the role intersected with the
156
+ grant's own scopes. Both travel, because orientation describes contexts
157
+ it does not open — the ones past the fan-out cap, and every one of them
158
+ when `orient` was itself addressed elsewhere — and a description drawn
159
+ from the role alone is wrong in both directions.
160
+ */
161
+ const reach = reachForRole(session, entry.role);
162
+ return {
163
+ name: `@${entry.slug}`,
164
+ role: entry.role,
165
+ kind: entry.kind,
166
+ current: entry.workspaceId === session.workspaceId,
167
+ canWrite: reach.canWrite,
168
+ grantWrites: reach.grantWrites,
169
+ tier: entry.askerOwn === true ? "private" : reach.tier,
170
+ ...(entry.askerOwn === true ? { askerOwn: true } : {}),
171
+ };
172
+ });
173
+ }
174
+
175
+ function contextNameFor(session) {
176
+ return `@${session?.workspaceSlug || session?.workspaceId || "context"}`;
177
+ }
178
+
179
+ module.exports = { actorFor, personalNameFor, editsPinnedContext, contextsFor, contextNameFor, PINNED_CONTEXT_NAME };
@@ -0,0 +1,8 @@
1
+ /** Types for `identity.cjs`; see that file. */
2
+
3
+ export declare const PINNED_CONTEXT_NAME: "@context-lc";
4
+ export declare function actorFor(session: any): Record<string, unknown>;
5
+ export declare function personalNameFor(session: any): string | null;
6
+ export declare function editsPinnedContext(session: any): boolean;
7
+ export declare function contextsFor(session: any): { name: string; role: string; kind: string; current: boolean; canWrite: boolean; grantWrites: boolean; tier: string; askerOwn?: true }[];
8
+ export declare function contextNameFor(session: any): string;
@@ -0,0 +1,93 @@
1
+ /**
2
+ * The day's job-log writes (`jobLog.js`): each takes the tool dispatcher as an argument and holds no Tex state, so the
3
+ * gateway's attention tool (`tools/attention.js`) writes a log the same way the scheduled turns do.
4
+ */
5
+
6
+ const { wallClock } = require("../texShared/routines.cjs");
7
+
8
+ const pad = (value) => String(value).padStart(2, "0");
9
+
10
+ /** `YYYY-MM-DD` of `now` in `timeZone`. */
11
+ function dayOf(now, timeZone) {
12
+ const w = wallClock(now, timeZone);
13
+ return `${w.year}-${pad(w.month)}-${pad(w.day)}`;
14
+ }
15
+
16
+ const MONTHS = [
17
+ "January", "February", "March", "April", "May", "June",
18
+ "July", "August", "September", "October", "November", "December",
19
+ ];
20
+
21
+ /** `October 17, 2026` of `now` in `timeZone`. */
22
+ function longDate(now, timeZone) {
23
+ const w = wallClock(now, timeZone);
24
+ return `${MONTHS[w.month - 1]} ${w.day}, ${w.year}`;
25
+ }
26
+
27
+ /** `3:05 am` of `now` in `timeZone`. */
28
+ function clock(now, timeZone) {
29
+ const w = wallClock(now, timeZone);
30
+ const h = w.hour % 12 === 0 ? 12 : w.hour % 12;
31
+ return `${h}:${pad(w.minute)} ${w.hour < 12 ? "am" : "pm"}`;
32
+ }
33
+
34
+ /** `{ etag, body }`, `{ missing: true }`, or null when the note could not be read. */
35
+ async function readWithEtag(dispatch, path) {
36
+ try {
37
+ const result = await dispatch("read_note", { path });
38
+ const text = (Array.isArray(result?.content) ? result.content : []).map((part) => part?.text ?? "").join("\n");
39
+ if (result?.isError === true) return /^not found\b/i.test(text.trim()) ? { missing: true } : null;
40
+ const split = text.indexOf("\n\n");
41
+ if (split === -1) return null;
42
+ const etag = /^etag: (.+)$/m.exec(text.slice(0, split))?.[1]?.trim();
43
+ return etag ? { etag, body: text.slice(split + 2) } : null;
44
+ } catch {
45
+ return null;
46
+ }
47
+ }
48
+
49
+ /** A tool refusal's leading words ("conflict", "permission denied"): never the note text a conflict carries. */
50
+ function refusalWords(result) {
51
+ const text = (Array.isArray(result?.content) ? result.content : []).map((part) => part?.text ?? "").join("\n");
52
+ return text.split(/[:\n(]/, 1)[0].trim().slice(0, 60) || "refused";
53
+ }
54
+
55
+ /**
56
+ * Write `entry` after whatever the day's log already holds, starting it with
57
+ * `heading` when it does not exist. Best effort; a log that can't be read is
58
+ * never overwritten. A read or write that fails is tried once more, and a log
59
+ * that still could not be written says why in the Worker's log (`job_log`),
60
+ * never with the entry's or the note's words.
61
+ */
62
+ async function appendLogEntry(dispatch, path, entry, heading, extra = {}) {
63
+ return (await appendLogEntryWhy(dispatch, path, entry, heading, extra)) === null;
64
+ }
65
+
66
+ /** `appendLogEntry`, answering null when the entry landed and otherwise why it didn't, in the refusal's leading words. */
67
+ async function appendLogEntryWhy(dispatch, path, entry, heading, { images = null } = {}) {
68
+ let why = "unreadable";
69
+ for (let attempt = 0; attempt < 2; attempt += 1) {
70
+ const current = await readWithEtag(dispatch, path);
71
+ if (current === null) {
72
+ why = "unreadable";
73
+ continue;
74
+ }
75
+ const before = current.missing ? heading : current.body;
76
+ let threw = null;
77
+ const written = await dispatch("write_note", {
78
+ path,
79
+ content: `${before.replace(/\n*$/, "\n\n")}${entry}`,
80
+ ...(current.missing ? {} : { expected_etag: current.etag }),
81
+ ...(Array.isArray(images) && images.length > 0 ? { images } : {}),
82
+ }).catch((error) => {
83
+ threw = error;
84
+ return null;
85
+ });
86
+ if (written && written.isError !== true) return null;
87
+ why = threw !== null ? `threw ${threw?.name ?? "error"}` : written ? refusalWords(written) : "no answer";
88
+ }
89
+ console.log(JSON.stringify({ event: "job_log", outcome: "not_written", folder: path.split("/").slice(0, -1).join("/"), why }));
90
+ return why;
91
+ }
92
+
93
+ module.exports = { dayOf, longDate, clock, readWithEtag, refusalWords, appendLogEntry, appendLogEntryWhy };
@@ -0,0 +1,12 @@
1
+ /** Types for `jobLogEntries.cjs`; see that file. */
2
+
3
+ export type JobLogDispatch = (name: string, args: Record<string, unknown>) => Promise<unknown>;
4
+ export type JobLogRead = { etag: string; body: string } | { missing: true } | null;
5
+
6
+ export declare function dayOf(now: number, timeZone: string): string;
7
+ export declare function longDate(now: number, timeZone: string): string;
8
+ export declare function clock(now: number, timeZone: string): string;
9
+ export declare function readWithEtag(dispatch: JobLogDispatch, path: string): Promise<JobLogRead>;
10
+ export declare function refusalWords(result: unknown): string;
11
+ export declare function appendLogEntry(dispatch: JobLogDispatch, path: string, entry: string, heading: string, extra?: { images?: unknown[] | null }): Promise<boolean>;
12
+ export declare function appendLogEntryWhy(dispatch: JobLogDispatch, path: string, entry: string, heading: string, options?: { images?: unknown[] | null }): Promise<string | null>;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * THE ACTIONS THE SHARING JUDGE IS ASKED ABOUT FOR A CHANGE THE CONTROL PLANE MAKES, NAMED ONCE FOR BOTH SIDES
3
+ * (`docs/decisions/texting-assistant/tex-service.md`, "The main texted turn in Tex's Worker").
4
+ *
5
+ * Tex's vault tool (`packages/tex/gateway/agent/settingsTools.js`) asks the judge before it shares a login, and
6
+ * Context judges the same action again inside `tex_control`'s `vaultText` (`apps/mcp/src/tools/texControl.js`), so a
7
+ * share is judged on the person's kept words whoever sends it. One copy, so the two never ask about different things.
8
+ */
9
+
10
+ "use strict";
11
+
12
+ /** Sharing one of the person's saved logins, keys or cards. */
13
+ const VAULT_SHARE_ACTION = "let more people (or a group chat) use one of the person's saved logins, keys or cards through their AIs";
14
+
15
+ /** Sharing an answer held from a group chat, in the chat `chat` (its name, or "the group"). */
16
+ function heldShareAction(chat) {
17
+ return `share ${chat}'s held answer`;
18
+ }
19
+
20
+ module.exports = { VAULT_SHARE_ACTION, heldShareAction };
@@ -0,0 +1,4 @@
1
+ /** Types for `judgedActions.cjs`; see that file. */
2
+
3
+ export declare const VAULT_SHARE_ACTION: string;
4
+ export declare function heldShareAction(chat: string): string;
@@ -0,0 +1,63 @@
1
+ /**
2
+ * A Lab test chat's gate, as Tex and the gateway both read it (docs/decisions/texting-assistant/lab-sandbox.md).
3
+ *
4
+ * A test turn's env carries its gate under `LAB_SANDBOX_KEY`; a real request's never does. What a test turn may
5
+ * reach is the gateway's call (`apps/mcp/src/labSandbox/policy.js`): every MCP tool call passes it there
6
+ * (`tools/session.js`), and the tools Tex runs itself are answered by `sandboxedTool` below, which hands the call
7
+ * to the answer the gateway's policy registers when it loads (`answerSandboxedWith`). With a gate and no answer
8
+ * registered, nothing runs: a test turn never reaches a real tool by default.
9
+ */
10
+
11
+ const LAB_SANDBOX_KEY = "LAB_SANDBOX_GATE";
12
+
13
+ /** The gate a request's env carries, or null on every real request. */
14
+ function sandboxGateOf(env) {
15
+ const gate = env?.[LAB_SANDBOX_KEY];
16
+ return gate && typeof gate === "object" && typeof gate.record === "function" ? gate : null;
17
+ }
18
+
19
+ /**
20
+ * Tools that need a browser or one of the person's computers, which a test chat never has (`policy.js` `toolAnswer`
21
+ * refuses them).
22
+ */
23
+ const NO_MACHINE = /^(browse|fill_login|make_login|fill_card|sign_out_browser|delegate)$|computer|machine/;
24
+
25
+ /**
26
+ * Whether a Lab test chat refuses this tool for wanting a browser or a computer. The turn's tool list leaves such a
27
+ * tool out (`turnWeb.js`), so what the turn is told it can do is what the gateway's check lets it do.
28
+ */
29
+ function sandboxRefusesTool(env, name) {
30
+ return sandboxGateOf(env) !== null && typeof name === "string" && NO_MACHINE.test(name);
31
+ }
32
+
33
+ /**
34
+ * A consent-gated tool's own check (`commandTools.js` `precheck`) in a test chat: the tool itself is answered as done
35
+ * without running, so its check runs here first and a refusal stands, as it would in a real chat (Dev2,
36
+ * 2026-11-22: the Lab never showed the judge refusing a share). Null on every real turn and when the check passes.
37
+ */
38
+ async function sandboxPrecheck(env, precheck, args) {
39
+ if (typeof precheck !== "function" || sandboxGateOf(env) === null) return null;
40
+ const refused = await precheck(args);
41
+ if (refused) sandboxGateOf(env).record({ kind: "Refused", summary: "consent check refused the change", tool: "consent" });
42
+ return refused ?? null;
43
+ }
44
+
45
+ let answer = null;
46
+
47
+ /** The gateway's policy registers its answer for a test turn's tool (`policy.js`), once, as it loads. */
48
+ function answerSandboxedWith(answerer) {
49
+ answer = typeof answerer === "function" ? answerer : null;
50
+ }
51
+
52
+ const NOT_RUN = Object.freeze({ content: [Object.freeze({ type: "text", text: "Not run." })], isError: true });
53
+
54
+ /**
55
+ * A tool Tex runs itself, on a turn's env: null on every real turn, whose env carries no gate (`agent/turn.js`), and
56
+ * otherwise the gateway's answer for a test chat (`policy.js` `sandboxedTool`).
57
+ */
58
+ async function sandboxedTool(env, call) {
59
+ if (sandboxGateOf(env) === null) return null;
60
+ return typeof answer === "function" ? await answer(env, call) : NOT_RUN;
61
+ }
62
+
63
+ module.exports = { LAB_SANDBOX_KEY, sandboxGateOf, NO_MACHINE, sandboxRefusesTool, sandboxPrecheck, answerSandboxedWith, sandboxedTool };
@@ -0,0 +1,9 @@
1
+ /** Types for `labSandboxGate.cjs`; see that file. */
2
+
3
+ export declare const LAB_SANDBOX_KEY: "LAB_SANDBOX_GATE";
4
+ export declare function sandboxGateOf(env: unknown): ({ record: (entry: object) => void } & Record<string, unknown>) | null;
5
+ export declare const NO_MACHINE: RegExp;
6
+ export declare function sandboxRefusesTool(env: unknown, name: unknown): boolean;
7
+ export declare function sandboxPrecheck(env: unknown, precheck: unknown, args: unknown): Promise<unknown>;
8
+ export declare function answerSandboxedWith(answerer: ((env: unknown, call: unknown) => Promise<unknown>) | null): void;
9
+ export declare function sandboxedTool(env: unknown, call: unknown): Promise<unknown>;
@@ -0,0 +1,4 @@
1
+ /** How many characters one read of a chat's ledger returns (`log.js`). The gateway's ledger page reads with the same budget. */
2
+ const READ_CHARS = 120_000;
3
+
4
+ module.exports = { READ_CHARS };
@@ -0,0 +1,3 @@
1
+ /** Types for `ledgerReadChars.cjs`; see that file. */
2
+
3
+ export declare const READ_CHARS: number;