@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,31 @@
1
+ /**
2
+ * Job restart: whether a background job that ended can be picked back up (Dev2, 2026-11-27, "Stop Tex parts drifting
3
+ * out of sync"). One rule, read by every part that decides or describes it.
4
+ *
5
+ * Three parts held their own copy of this. The job's object keeps its run for two hours after it ended, or two hours
6
+ * past the restart of a job paused at the daily limit (`packages/tex/worker/jobRun.ts`); the chat's inbox picks a job
7
+ * back up when it is neither running nor done (`packages/tex/worker/jobs.ts` `resumeJobs`); and the gateway offered
8
+ * "restart_job" for any job neither running nor done (`packages/tex/gateway/agent/background.js`), with no window. A
9
+ * test chat kept an ended job a day (`jobsKept`), so Tex told a chat it was "restarting" a job whose run had already
10
+ * gone, and the inbox then refused it. Now the window and the states are here, and all three read them.
11
+ *
12
+ * Plain CommonJS with no imports, so the gateway and the texting Worker read the same rule.
13
+ */
14
+
15
+ /** How long an ended job's run is kept, so how long it can be picked back up: also how long every turn is shown it. */
16
+ const RESUME_MS = 2 * 60 * 60 * 1000;
17
+
18
+ /** When an ended job's run is let go: two hours after it ended, or after the restart of one paused at the limit. */
19
+ function resumeEndsAt(entry) {
20
+ const from = [entry?.resumeAt, entry?.finishedAt, entry?.startedAt].find((n) => Number.isFinite(n) && n > 0);
21
+ return from === undefined ? 0 : from + RESUME_MS;
22
+ }
23
+
24
+ /** True when a job ended without finishing and its run is still kept, so "restart it" can pick it up where it stopped. */
25
+ function canResume(entry, now) {
26
+ if (!entry || typeof entry !== "object") return false;
27
+ if (entry.state === "running" || entry.state === "done") return false;
28
+ return Number.isFinite(now) && now <= resumeEndsAt(entry);
29
+ }
30
+
31
+ module.exports = { RESUME_MS, canResume, resumeEndsAt };
@@ -0,0 +1,5 @@
1
+ /** Types for `jobResume.cjs`; see that file for the rule and the reasons. */
2
+ export interface ResumableEntry { state?: string; startedAt?: number | null; finishedAt?: number | null; resumeAt?: number | null }
3
+ export declare const RESUME_MS: number;
4
+ export declare function resumeEndsAt(entry: ResumableEntry | null | undefined): number;
5
+ export declare function canResume(entry: ResumableEntry | null | undefined, now: number): boolean;
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Split job: one job that owns several parts at once (Architect item #7, option C of
3
+ * `@supa products/tex/research/split-jobs-one-job-2026-11-24.md`, decided by Grok Bot for Seyi, 2026-11-28).
4
+ *
5
+ * `plan_big_ask` splits a big ask into parts that run side by side, each on a named worker (the cloud, a paired
6
+ * computer), all on the project overview's mail. Each part still runs in a `job:<id>` object of its own and takes a
7
+ * slot of its own, so the three-job cap and each computer's slots hold as before. What makes them one job is the
8
+ * split they carry: the overview note's path is its id, and the plan's title its name. With it:
9
+ *
10
+ * - the chat's list shows the split as one job with its parts under it (`groupedJobs`);
11
+ * - "try again" on any part, or on the split's title, picks back up every unfinished part (`restartSet`): 2026-11-06,
12
+ * a split's "try again" resumed only the part that had ended, and the computer ran alone for twelve minutes
13
+ * waiting on a partner that never started;
14
+ * - a part that ends waiting sleeps until mail or a text wakes it, instead of ending or using up parts
15
+ * (`packages/shared/src/jobPartEnd.cjs` `sleep`, `packages/tex/worker/jobSleep.ts`).
16
+ *
17
+ * Plain CommonJS, needing only `fileKinds.cjs`, so the gateway and the texting Worker read the same rules. This is the config's
18
+ * Split job node (`split`): its code, as `jobPartEnd.cjs` is Part end's.
19
+ */
20
+
21
+ const { isNotePath } = require("./fileKinds.cjs");
22
+
23
+ const MAX_TITLE = 80;
24
+ const MAX_PATH = 1024;
25
+
26
+ /** A split read strictly: `{ id, title }`, the overview note's path and the plan's title, or null. */
27
+ function splitOf(value) {
28
+ if (!value || typeof value !== "object" || Array.isArray(value)) return null;
29
+ const id = typeof value.id === "string" ? value.id.trim() : "";
30
+ const title = typeof value.title === "string" ? value.title.replace(/\s+/g, " ").trim().slice(0, MAX_TITLE) : "";
31
+ if (id === "" || id.length > MAX_PATH || /[\u0000-\u001f]/.test(id) || !isNotePath(id) || title === "") return null;
32
+ return { id, title };
33
+ }
34
+
35
+ const lower = (value) => String(value ?? "").toLowerCase();
36
+
37
+ /**
38
+ * What a restart picks back up: the jobs it picked, then every other part of a split one of them is in, or whose
39
+ * title one of `names` is, that `resumable` says can still be picked up. A done part stays done. In the order of
40
+ * `entries`, each once.
41
+ *
42
+ * @param {Array<{ id: string, title: string, split?: { id: string, title: string } | null }>} entries the chat's jobs
43
+ * @param {Array<{ id: string }>} picked the jobs the restart matched by their own titles
44
+ * @param {(entry: object) => boolean} resumable whether a job can still be picked back up
45
+ * @param {string[]} [names] the titles the restart named
46
+ */
47
+ function restartSet(entries, picked, resumable, names = []) {
48
+ const named = new Set(names.map(lower));
49
+ const splits = new Set();
50
+ for (const entry of entries) {
51
+ const split = splitOf(entry.split);
52
+ if (split === null) continue;
53
+ if (picked.some((each) => each.id === entry.id) || named.has(lower(split.title))) splits.add(split.id);
54
+ }
55
+ const ids = new Set(picked.map((each) => each.id));
56
+ return entries.filter((entry) => ids.has(entry.id) || (splits.has(splitOf(entry.split)?.id) && resumable(entry)));
57
+ }
58
+
59
+ /**
60
+ * The chat's jobs as its list shows them: a job on its own as `{ job }`, a split as `{ split, parts }` at the place
61
+ * of its first part, its parts in their order.
62
+ */
63
+ function groupedJobs(entries) {
64
+ const out = [];
65
+ const at = new Map();
66
+ for (const entry of entries) {
67
+ const split = splitOf(entry.split);
68
+ if (split === null) {
69
+ out.push({ job: entry });
70
+ continue;
71
+ }
72
+ if (!at.has(split.id)) {
73
+ at.set(split.id, out.length);
74
+ out.push({ split, parts: [] });
75
+ }
76
+ out[at.get(split.id)].parts.push(entry);
77
+ }
78
+ return out;
79
+ }
80
+
81
+ /** The Split job node's answer for one restart (`packages/tex/gateway/agent/graph/nodes/split.js`): the ids to pick back up. */
82
+ function decideSplit(input) {
83
+ const entries = Array.isArray(input?.entries) ? input.entries : [];
84
+ const picked = Array.isArray(input?.picked) ? input.picked : [];
85
+ const resumable = new Set(Array.isArray(input?.resumable) ? input.resumable : []);
86
+ const names = Array.isArray(input?.names) ? input.names.filter((name) => typeof name === "string") : [];
87
+ return { restart: restartSet(entries, picked, (entry) => resumable.has(entry.id), names).map((entry) => entry.id) };
88
+ }
89
+
90
+ module.exports = { splitOf, restartSet, groupedJobs, decideSplit };
@@ -0,0 +1,6 @@
1
+ /** Types for `jobSplit.cjs`; see that file for the rules and the reasons. */
2
+ export interface JobSplit { id: string; title: string }
3
+ export declare function splitOf(value: unknown): JobSplit | null;
4
+ export declare function restartSet<T extends { id: string; title: string; split?: JobSplit | null }>(entries: readonly T[], picked: readonly { id: string }[], resumable: (entry: T) => boolean, names?: readonly string[]): T[];
5
+ export declare function groupedJobs<T extends { split?: JobSplit | null }>(entries: readonly T[]): Array<{ job: T } | { split: JobSplit; parts: T[] }>;
6
+ export declare function decideSplit(input: { entries?: unknown[]; picked?: unknown[]; resumable?: string[]; names?: string[] }): { restart: string[] };
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Job start: whether a background job Tex asks for starts now (Dev2, 2026-11-17, "jobs as config", step 7).
3
+ *
4
+ * The front door starts a job with `start_background_job`. Whether it may (a title and a brief, not the same job as
5
+ * one already running, a free slot where it would run) and the limits behind it (three cloud jobs a chat, at most
6
+ * eight on one computer) were code inside the gateway's job tool (`packages/tex/gateway/agent/background.js`). Here the choice
7
+ * is one pure function, the Job start node's code (`packages/tex/gateway/agent/graph/nodes/jobStart.js`), and the limits are
8
+ * that node's config (`limits`), so the Lab shows, tests and changes both.
9
+ *
10
+ * "already" is the steering choice: the ask is a job already running, so its words go to that job, not a second one.
11
+ *
12
+ * Plain CommonJS with no imports, so the gateway and the texting Worker read the same rules.
13
+ */
14
+
15
+ /** The limits when the config names none: today's numbers, so wiring this changes nothing. */
16
+ const DEFAULT_LIMITS = Object.freeze({ cloudSlots: 3, machineSlots: 8 });
17
+
18
+ const whole = (value, fallback) => (Number.isInteger(value) && value > 0 ? value : fallback);
19
+
20
+ /** The limits a node's config gives, each falling back to today's number. */
21
+ function limitsOf(config) {
22
+ const given = config && typeof config === "object" ? config : {};
23
+ return { cloudSlots: whole(given.cloudSlots, DEFAULT_LIMITS.cloudSlots), machineSlots: whole(given.machineSlots, DEFAULT_LIMITS.machineSlots) };
24
+ }
25
+
26
+ /** The Job start node's limits in a whole config (`texConfig.json`), today's numbers while it names none. */
27
+ function configStartLimits(config) {
28
+ const node = Array.isArray(config?.nodes) ? config.nodes.find((n) => n && n.id === "jobStart") : null;
29
+ return limitsOf(node?.limits);
30
+ }
31
+
32
+ /** A computer's own slots: its owner's count, one when it names none, never over the limit. */
33
+ function slotsOn(computer, limits) {
34
+ const slots = computer?.slots;
35
+ return Number.isSafeInteger(slots) && slots > 0 ? Math.min(slots, limits.machineSlots) : 1;
36
+ }
37
+
38
+ /**
39
+ * What follows an ask to start a job. `input`: `hasTitle`, `hasBrief`, `already` (the running job it is the same as,
40
+ * `{ title, startedAt?, status? }`, or null), `computer` (`{ id, slots }` where it would run, or null for the cloud),
41
+ * `cloudBusy` and `machineBusy` (jobs already running there, this turn's starts included).
42
+ * Answers `{ to: "start" | "already" | "full" | "refuse", ... }`.
43
+ */
44
+ function decideStart(input, config) {
45
+ const limits = limitsOf(config);
46
+ if (input?.hasTitle !== true || input?.hasBrief !== true) return { to: "refuse", why: "a job needs a title and a brief" };
47
+ const already = input.already && typeof input.already === "object" && typeof input.already.title === "string" ? input.already : null;
48
+ if (already !== null) return { to: "already", title: already.title, ...(Number.isFinite(already.startedAt) ? { startedAt: already.startedAt } : {}), ...(typeof already.status === "string" && already.status ? { status: already.status } : {}) };
49
+ const computer = input.computer && typeof input.computer === "object" && typeof input.computer.id === "string" ? input.computer : null;
50
+ const busy = Number.isInteger(computer ? input.machineBusy : input.cloudBusy) ? (computer ? input.machineBusy : input.cloudBusy) : 0;
51
+ const room = computer ? slotsOn(computer, limits) : limits.cloudSlots;
52
+ if (busy >= room) return { to: "full", where: computer ? "computer" : "cloud", slots: room };
53
+ return { to: "start", where: computer ? "computer" : "cloud", slots: room };
54
+ }
55
+
56
+ module.exports = { DEFAULT_LIMITS, configStartLimits, decideStart, limitsOf, slotsOn };
@@ -0,0 +1,9 @@
1
+ /** Types for `jobStart.cjs`; see that file for the rules and the reasons. */
2
+ export interface StartLimits { cloudSlots: number; machineSlots: number }
3
+ export interface StartInput { hasTitle: boolean; hasBrief: boolean; already?: { title: string; startedAt?: number; status?: string } | null; computer?: { id: string; slots?: number } | null; cloudBusy?: number; machineBusy?: number }
4
+ export interface StartChoice { to: "start" | "already" | "full" | "refuse"; where?: "cloud" | "computer"; slots?: number; title?: string; startedAt?: number; status?: string; why?: string }
5
+ export declare const DEFAULT_LIMITS: Readonly<StartLimits>;
6
+ export declare function limitsOf(config?: Partial<StartLimits> | null): StartLimits;
7
+ export declare function configStartLimits(config?: { nodes?: readonly { id: string; limits?: unknown }[] } | null): StartLimits;
8
+ export declare function slotsOn(computer: { slots?: number } | null, limits: StartLimits): number;
9
+ export declare function decideStart(input: StartInput, config?: Partial<StartLimits> | null): StartChoice;
@@ -0,0 +1,400 @@
1
+ /**
2
+ * Mail on a note: messages agents (and people) working on one note leave for
3
+ * each other, kept in the note's own file.
4
+ *
5
+ * Decided with the owner, 2026-10-15 (docs/decisions/note-mail.md). Agents
6
+ * cannot be woken by a server, so this is mail, not chat: an orchestrator sets
7
+ * how often everyone checks, and every Context answer to an agent that joined
8
+ * says how many messages are new for it.
9
+ *
10
+ * ## The format
11
+ *
12
+ * One fenced block with the info string `mail`, append-only, one entry per
13
+ * line:
14
+ *
15
+ * ```mail
16
+ * - 2026-10-15T18:20:00.000Z lead (Claude) joined
17
+ * - 2026-10-15T18:21:04.512Z lead (Claude) to everyone: Plan is above. We check mail every 10 minutes.
18
+ * - 2026-10-15T18:25:40.001Z builder (Codex) to lead: Pricing page done.
19
+ * A second line is indented four spaces.
20
+ * - 2026-10-15T18:26:00.000Z @seyi to everyone: Keep the launch on Tuesday.
21
+ * ```
22
+ *
23
+ * A sender is a name an agent chose when it joined (`[a-z0-9-]`, up to 24) with
24
+ * its app in brackets, or a person's `@handle`. A recipient is `everyone` or a
25
+ * name. Later lines of a message are indented four spaces, deeper than a
26
+ * closing fence may be, so no message can end the block.
27
+ *
28
+ * A message may carry a kind tag right after the recipient: `[ask]` (it wants
29
+ * an answer) or `[interrupt]` (it should be read now). No tag is a `note`, and
30
+ * a note is never written with one, so every line from before the tag existed
31
+ * reads the same. Any other bracketed word is not a tag: the line is skipped,
32
+ * as it always was.
33
+ *
34
+ * After the kind tag a bot may say how much of its weekly usage the work it is
35
+ * answering took: `[used 3%]`, a whole percent from 0 to 100 (the owner,
36
+ * 2026-11-25: an area's budget is a share of its bot's week, and Context can't
37
+ * read a bot's own meter, so the bot says). It is part of the line, so anyone
38
+ * reading the mail sees it; `workspaceStore/botMail.js` adds it up per area and
39
+ * week (`docs/decisions/app-and-console/area-routines.md`).
40
+ *
41
+ * Last, a reply names the message it answers by that message's time: `[re
42
+ * 2026-11-28T17:49:00.000Z]`. The replies to one message are its thread, read
43
+ * beside the conversation as in Slack, one level deep (Dev2, 2026-11-28: "The
44
+ * thread should live inside of the chat, sort of like a Slack thread").
45
+ *
46
+ * ## Why append-only, and why here
47
+ *
48
+ * Every write is an insertion at the end of the block, which the collaborative
49
+ * editor merges without losing anybody's line, and nothing here edits or
50
+ * removes one. The block is plain Markdown in the note (non-negotiable #3),
51
+ * so, as with comments, anybody who may write the note may also edit it by
52
+ * hand; the tools never do. It is hidden wherever comments are (share links,
53
+ * websites, search: `stripComments` removes both), and does not count
54
+ * towards a note's length.
55
+ */
56
+
57
+ "use strict";
58
+
59
+ const comments = require("./comments.cjs");
60
+
61
+ const MAIL_INFO = "mail";
62
+ const EVERYONE = "everyone";
63
+ const NAME = "[a-z0-9][a-z0-9-]{0,23}";
64
+ const NAME_RE = new RegExp(`^${NAME}$`);
65
+ const PERSON = "@[a-z0-9][a-z0-9-]{0,63}";
66
+ const MAIL_KINDS = ["note", "ask", "interrupt"];
67
+ /** The kinds written with a tag; a note is written without one. */
68
+ const TAGGED_KINDS = ["ask", "interrupt"];
69
+ const LINE_RE = new RegExp(
70
+ `^- (\\S+) (${NAME}|${PERSON})(?: \\(([^()\\n]{1,40})\\))? (?:(joined)|to (${NAME})(?: \\[(ask|interrupt)\\])?(?: \\[used (\\d{1,3})%\\])?(?: \\[re (\\S+?)\\])?: ?(.*))$`
71
+ );
72
+ /** The most a `[used N%]` tag says: a bot's whole week. */
73
+ const MAX_USED = 100;
74
+ const CONTINUATION = " ";
75
+ /** Longest message kept, in characters. */
76
+ const MAX_TEXT = 4000;
77
+ /** The deepest chain of asks; a judge on the sender side reads it, nothing here refuses. */
78
+ const MAX_ASK_DEPTH = 3;
79
+ /** Messages one sender may send one recipient in an hour; a limit for the caller to apply. */
80
+ const MAX_PER_PAIR_PER_HOUR = 20;
81
+
82
+ /** The note's mail block: the last closed ```mail fence, or null. */
83
+ function findMailBlock(text) {
84
+ const blocks = comments.fencedBlocks(typeof text === "string" ? text : "").filter((b) => b.info === MAIL_INFO && b.closed);
85
+ return blocks.length ? blocks[blocks.length - 1] : null;
86
+ }
87
+
88
+ /**
89
+ * Every entry, oldest first: `{ at, from, app, kind: "joined" | "mail", to,
90
+ * mailKind, text, start, end }`, where `mailKind` is `"note" | "ask" |
91
+ * "interrupt"` on a mail and null on a join. Lines the parser does not
92
+ * recognise are skipped: people may edit the file by hand.
93
+ */
94
+ function parseMail(text) {
95
+ const source = typeof text === "string" ? text : "";
96
+ const block = findMailBlock(source);
97
+ if (!block) return { block: null, events: [] };
98
+ const events = [];
99
+ let last = null;
100
+ // Blank lines inside a message, held until the next line says whether the message goes on (2026-11-06: a blank
101
+ // line was written empty, and everything after it in a spec was dropped from the mail view).
102
+ let blanks = 0;
103
+ for (const row of comments.lines(source.slice(block.bodyStart, block.bodyEnd))) {
104
+ if (block.bodyStart + row.start >= block.bodyEnd) break;
105
+ if (last && last.kind === "mail" && row.text.trim() === "") {
106
+ blanks += 1;
107
+ continue;
108
+ }
109
+ const match = LINE_RE.exec(row.text);
110
+ if (match && Number.isFinite(Date.parse(match[1]))) {
111
+ blanks = 0;
112
+ last = {
113
+ at: match[1],
114
+ from: match[2],
115
+ app: match[3] ?? null,
116
+ kind: match[4] ? "joined" : "mail",
117
+ to: match[4] ? null : match[5],
118
+ mailKind: match[4] ? null : match[6] ?? "note",
119
+ used: match[4] || match[7] === undefined || Number(match[7]) > MAX_USED ? null : Number(match[7]),
120
+ replyTo: match[4] || match[8] === undefined || !Number.isFinite(Date.parse(match[8])) ? null : match[8],
121
+ text: match[4] ? "" : match[9],
122
+ start: block.bodyStart + row.start,
123
+ end: block.bodyStart + row.next,
124
+ };
125
+ events.push(last);
126
+ continue;
127
+ }
128
+ if (last && last.kind === "mail" && row.text.startsWith(CONTINUATION)) {
129
+ last.text += `${"\n".repeat(blanks + 1)}${row.text.slice(CONTINUATION.length)}`;
130
+ last.end = block.bodyStart + row.next;
131
+ blanks = 0;
132
+ continue;
133
+ }
134
+ blanks = 0;
135
+ last = null;
136
+ }
137
+ return { block, events };
138
+ }
139
+
140
+ /**
141
+ * A name an agent may join as: lower case, spaces become dashes, anything
142
+ * else dropped; `null` when nothing usable is left or it is `everyone`.
143
+ */
144
+ function mailName(raw) {
145
+ const name = String(raw ?? "")
146
+ .trim()
147
+ .toLowerCase()
148
+ .replace(/[\s_]+/g, "-")
149
+ .replace(/[^a-z0-9-]/g, "")
150
+ .replace(/^-+/, "")
151
+ .slice(0, 24)
152
+ .replace(/-+$/, "");
153
+ if (!NAME_RE.test(name) || name === EVERYONE) return null;
154
+ return name;
155
+ }
156
+
157
+ /** An app's name as it may appear in brackets: no brackets, colons or line breaks. */
158
+ function appName(raw) {
159
+ const cleaned = String(raw ?? "")
160
+ .replace(/[\u0000-\u001f\u007f\u2028\u2029()]/g, " ")
161
+ .replace(/:/g, "")
162
+ .replace(/\s+/g, " ")
163
+ .trim()
164
+ .slice(0, 40)
165
+ .trim();
166
+ return cleaned || null;
167
+ }
168
+
169
+ /** Between an app and the `@handle` of the person whose app it is, in a sender's brackets: `builder (Claude Code · @seyi)`. */
170
+ const OWNER_MARK = " · ";
171
+ const OWNER_RE = /^(.*) · (@[a-z0-9][a-z0-9-]{0,63})$/;
172
+
173
+ /**
174
+ * The app a line is signed with, and whose it is: `Claude Code · @seyi`, the app cut short so the person always fits
175
+ * in the 40 characters an app may take (Dev, 2026-11-26: mail from Claude should say whose Claude it is). With no
176
+ * person, the app alone, as every line before this was signed.
177
+ */
178
+ function appWithOwner(raw, owner) {
179
+ const app = appName(raw);
180
+ if (app === null) return null;
181
+ if (typeof owner !== "string" || !/^@[a-z0-9][a-z0-9-]{0,63}$/.test(owner) || owner.length > 30) return app;
182
+ const room = 40 - OWNER_MARK.length - owner.length;
183
+ return `${app.slice(0, room).trim()}${OWNER_MARK}${owner}`;
184
+ }
185
+
186
+ /** `{app, owner}` from a signed app; `owner` is null on a line signed without one. */
187
+ function splitApp(signed) {
188
+ if (typeof signed !== "string" || signed === "") return { app: null, owner: null };
189
+ const match = OWNER_RE.exec(signed);
190
+ return match ? { app: match[1], owner: match[2] } : { app: signed, owner: null };
191
+ }
192
+
193
+ /** A message as log lines: the first after the colon, the rest indented. */
194
+ function formatText(text) {
195
+ const rows = String(text ?? "")
196
+ .replace(/\r\n?/g, "\n")
197
+ .replace(/[\u2028\u2029]/g, "\n")
198
+ .replace(/[\u0000-\u0008\u000b-\u001f\u007f]/g, "")
199
+ .trim()
200
+ .split("\n");
201
+ return rows.map((row, i) => (i === 0 ? row : row ? `${CONTINUATION}${row}` : CONTINUATION)).join("\n");
202
+ }
203
+
204
+ /**
205
+ * Append one entry. Returns `{ changes }` against `text` (apply them with
206
+ * `applyChanges`), or `{ error }`. `entry` is `{ at, from, app, kind, to,
207
+ * text, mailKind, used?, replyTo? }`; `from` is a joined name or an `@handle`; `mailKind` is
208
+ * `"note"` (the default), `"ask"` or `"interrupt"`.
209
+ */
210
+ function appendMail(text, entry) {
211
+ const source = typeof text === "string" ? text : "";
212
+ const at = typeof entry?.at === "string" && Number.isFinite(Date.parse(entry.at)) ? entry.at : new Date().toISOString();
213
+ const from = String(entry?.from ?? "");
214
+ if (!new RegExp(`^(${NAME}|${PERSON})$`).test(from)) return { error: "mail needs a sender name" };
215
+ const mailKind = entry?.mailKind === undefined ? "note" : entry.mailKind;
216
+ if (!MAIL_KINDS.includes(mailKind)) return { error: 'mail.kind must be "note", "ask" or "interrupt"' };
217
+ const app = entry?.app ? appName(entry.app) : null;
218
+ const who = app ? `${from} (${app})` : from;
219
+ let line;
220
+ if (entry?.kind === "joined") {
221
+ line = `- ${at} ${who} joined`;
222
+ } else {
223
+ const to = entry?.to ?? EVERYONE;
224
+ if (!NAME_RE.test(to)) return { error: `mail.to must be "${EVERYONE}" or a name that joined` };
225
+ const body = formatText(entry?.text);
226
+ if (!body) return { error: "mail.text is empty" };
227
+ if (body.length > MAX_TEXT) return { error: `mail.text is too long; keep a message under ${MAX_TEXT} characters` };
228
+ const tag = TAGGED_KINDS.includes(mailKind) ? ` [${mailKind}]` : "";
229
+ let usedTag = "";
230
+ if (entry?.used !== undefined && entry?.used !== null) {
231
+ const used = Number(entry.used);
232
+ if (!Number.isFinite(used) || used < 0 || used > MAX_USED) return { error: `mail.used is a whole percent of your weekly usage, 0 to ${MAX_USED}` };
233
+ usedTag = ` [used ${Math.round(used)}%]`;
234
+ }
235
+ let reTag = "";
236
+ if (entry?.replyTo !== undefined && entry?.replyTo !== null) {
237
+ if (typeof entry.replyTo !== "string" || /\s|\]/.test(entry.replyTo) || !Number.isFinite(Date.parse(entry.replyTo))) {
238
+ return { error: "mail.reply_to is the time of the message you answer, as read_note lists it" };
239
+ }
240
+ reTag = ` [re ${entry.replyTo}]`;
241
+ }
242
+ line = `- ${at} ${who} to ${to}${tag}${usedTag}${reTag}: ${body}`;
243
+ }
244
+ const block = findMailBlock(source);
245
+ if (block) {
246
+ // Before the closing fence. `bodyEnd` is where that fence line starts.
247
+ const before = source.slice(block.bodyStart, block.bodyEnd);
248
+ const insert = before === "" || before.endsWith("\n") ? `${line}\n` : `\n${line}\n`;
249
+ return { changes: [{ from: block.bodyEnd, to: block.bodyEnd, insert }] };
250
+ }
251
+ const lead = source === "" ? "" : source.endsWith("\n\n") ? "" : source.endsWith("\n") ? "\n" : "\n\n";
252
+ return { changes: [{ from: source.length, to: source.length, insert: `${lead}\`\`\`${MAIL_INFO}\n${line}\n\`\`\`\n` }] };
253
+ }
254
+
255
+ /**
256
+ * A whole-note rewrite that left out the stored note's mail block, with that
257
+ * block put back at its end; `null` when there is nothing to put back (the
258
+ * stored note has no mail, or the rewrite kept a mail block of its own). The
259
+ * mail is a record the agents on the note share: a save of the note's text is
260
+ * never a reason to lose it (2026-11-06: a reviewer's whole-note save wiped a
261
+ * split job's mail, and every join with it).
262
+ */
263
+ /** A note's mail block as written, for comparing one save against another; null when it has none. */
264
+ function mailBlockText(text) {
265
+ const source = typeof text === "string" ? text : "";
266
+ const block = findMailBlock(source);
267
+ return block === null ? null : source.slice(block.start, block.end).replace(/\s+$/, "");
268
+ }
269
+
270
+ /**
271
+ * Whether a whole-note save would write the note's mail itself. Only `write action mail` adds a line, where the name
272
+ * comes from the joined mailbox or the caller's own identity and the loop guards run (`tools/notes/mail.js`); the
273
+ * workspace hands that name to a bot whose folder the note sits in (`workspaceStore/botMail.js`), so a save that
274
+ * carries a line nobody sent would put another person's name on an ask. A save that leaves the block out is not this:
275
+ * `keepMailBlock` gives it back.
276
+ */
277
+ function mailBlockWritten(stored, next) {
278
+ const now = mailBlockText(next);
279
+ return now !== null && now !== mailBlockText(stored);
280
+ }
281
+
282
+ function keepMailBlock(stored, next) {
283
+ const block = findMailBlock(stored);
284
+ if (!block || typeof next !== "string" || findMailBlock(next)) return null;
285
+ const kept = stored.slice(block.start, block.end).replace(/\n*$/, "\n");
286
+ const body = next.replace(/\s+$/, "");
287
+ return `${body}${body === "" ? "" : "\n\n"}${kept}`;
288
+ }
289
+
290
+ /** The note without its mail block, and the blank lines that led up to it. */
291
+ function stripMail(text) {
292
+ const source = typeof text === "string" ? text : "";
293
+ const block = findMailBlock(source);
294
+ if (!block) return source;
295
+ let start = block.start;
296
+ while (start > 0 && source[start - 1] === "\n") start -= 1;
297
+ const tail = source.slice(block.end).replace(/^\n+/, "");
298
+ return source.slice(0, start) + (start > 0 ? "\n" : "") + tail;
299
+ }
300
+
301
+ /**
302
+ * The messages that are new for one member: after `since` (an ISO time),
303
+ * addressed to them or to everyone, and not their own.
304
+ */
305
+ function newFor(events, name, since) {
306
+ const after = Number.isFinite(Date.parse(since)) ? Date.parse(since) : -Infinity;
307
+ return events.filter(
308
+ (event) =>
309
+ event.kind === "mail" &&
310
+ Date.parse(event.at) > after &&
311
+ event.from !== name &&
312
+ (event.to === EVERYONE || event.to === name)
313
+ );
314
+ }
315
+
316
+ /** One entry as an agent reads it. */
317
+ function describeEntry(event) {
318
+ const who = event.app ? `${event.from} (${event.app})` : event.from;
319
+ if (event.kind === "joined") return `- ${event.at} ${who} joined`;
320
+ const body = event.text.split("\n").join(`\n${CONTINUATION}`);
321
+ const tag = TAGGED_KINDS.includes(event.mailKind) ? ` [${event.mailKind}]` : "";
322
+ const used = typeof event.used === "number" ? ` [used ${event.used}%]` : "";
323
+ const re = typeof event.replyTo === "string" ? ` [re ${event.replyTo}]` : "";
324
+ return `- ${event.at} ${who} to ${event.to}${tag}${used}${re}: ${body}`;
325
+ }
326
+
327
+ /** Mail from `from` to `to` (a name or everyone) in the `windowMs` (an hour) before `nowMs`. */
328
+ function pairCount(events, from, to, nowMs, windowMs = 60 * 60 * 1000) {
329
+ return events.filter(
330
+ (event) => event.kind === "mail" && event.from === from && event.to === to && Date.parse(event.at) > nowMs - windowMs
331
+ ).length;
332
+ }
333
+
334
+ /**
335
+ * The depth a new ask from `from` would have now. An ask is open for X when it
336
+ * went to X, or to everyone from someone other than X, and X has sent no mail
337
+ * of any kind to its sender (or to everyone) since. An ask sent by S has depth
338
+ * 1 + the deepest ask open for S when it was sent, or 1 when none was. Walks
339
+ * the events oldest first and returns 1 + the deepest ask open for `from`, or 1.
340
+ */
341
+ function askDepth(events, from) {
342
+ const asks = [];
343
+ const openFor = (ask, who) => ask.from !== who && (ask.to === who || ask.to === EVERYONE) && !ask.answeredBy.has(who);
344
+ const deepestOpenFor = (who) => asks.reduce((max, ask) => (openFor(ask, who) ? Math.max(max, ask.depth) : max), 0);
345
+ for (const event of events) {
346
+ if (event.kind !== "mail") continue;
347
+ const sender = event.from;
348
+ // The depth comes from what was open when the ask was sent, so it is read before this message closes anything.
349
+ const depth = 1 + deepestOpenFor(sender);
350
+ for (const ask of asks) {
351
+ if (openFor(ask, sender) && (event.to === ask.from || event.to === EVERYONE)) ask.answeredBy.add(sender);
352
+ }
353
+ if ((event.mailKind ?? "note") === "ask") asks.push({ from: sender, to: event.to, depth, answeredBy: new Set() });
354
+ }
355
+ return 1 + deepestOpenFor(from);
356
+ }
357
+
358
+ /**
359
+ * The newest ask still waiting for an answer, as `{at, from, to}`, or null (Agent Mail's Waiting state; Dev,
360
+ * 2026-11-28). An ask to a name waits until that name writes to its sender or to everyone; an ask to everyone waits
361
+ * until anybody else writes. Only the note's own lines decide it, as `askDepth` does.
362
+ */
363
+ function openAsk(events) {
364
+ const open = [];
365
+ for (const event of events) {
366
+ if (event.kind !== "mail") continue;
367
+ for (let index = open.length - 1; index >= 0; index -= 1) {
368
+ const ask = open[index];
369
+ const fromAsked = ask.to === EVERYONE ? event.from !== ask.from : event.from === ask.to;
370
+ if (fromAsked && (event.to === ask.from || event.to === EVERYONE)) open.splice(index, 1);
371
+ }
372
+ if ((event.mailKind ?? "note") === "ask") open.push({ at: event.at, from: event.from, to: event.to });
373
+ }
374
+ return open.length === 0 ? null : open[open.length - 1];
375
+ }
376
+
377
+ module.exports = {
378
+ openAsk,
379
+ MAIL_INFO,
380
+ EVERYONE,
381
+ MAIL_KINDS,
382
+ MAX_ASK_DEPTH,
383
+ MAX_PER_PAIR_PER_HOUR,
384
+ MAX_USED,
385
+ findMailBlock,
386
+ parseMail,
387
+ mailName,
388
+ appName,
389
+ appWithOwner,
390
+ splitApp,
391
+ appendMail,
392
+ stripMail,
393
+ keepMailBlock,
394
+ mailBlockText,
395
+ mailBlockWritten,
396
+ newFor,
397
+ describeEntry,
398
+ pairCount,
399
+ askDepth,
400
+ };
@@ -0,0 +1,56 @@
1
+ /** Types for `mail.cjs`; see that file for the format and the reasons. */
2
+
3
+ import type { CommentChange, CommentsBlock } from "./comments.cjs";
4
+
5
+ export type MailKind = "note" | "ask" | "interrupt";
6
+
7
+ export interface MailEvent {
8
+ at: string;
9
+ /** A joined name, or a person's `@handle`. */
10
+ from: string;
11
+ /** The app an agent wrote from, or null for a person. */
12
+ app: string | null;
13
+ kind: "joined" | "mail";
14
+ /** `everyone` or a joined name; null for a join. */
15
+ to: string | null;
16
+ /** `note` when untagged; null for a join. */
17
+ mailKind: MailKind | null;
18
+ /** The share of its sender's weekly usage the work took, `[used N%]`; null when the line says none. */
19
+ used: number | null;
20
+ /** The time of the message this one answers, `[re <at>]`: its thread's root; null when it answers nobody. */
21
+ replyTo: string | null;
22
+ text: string;
23
+ /** The entry's lines in the file, `[start, end)`. */
24
+ start: number;
25
+ end: number;
26
+ }
27
+
28
+ export declare const MAIL_INFO: "mail";
29
+ export declare const EVERYONE: "everyone";
30
+ export declare const MAIL_KINDS: readonly ["note", "ask", "interrupt"];
31
+ export declare const MAX_ASK_DEPTH: 3;
32
+ export declare const MAX_PER_PAIR_PER_HOUR: 20;
33
+ export declare const MAX_USED: 100;
34
+ export declare function findMailBlock(text: string): CommentsBlock | null;
35
+ export declare function parseMail(text: string): { block: CommentsBlock | null; events: MailEvent[] };
36
+ export declare function mailName(raw: unknown): string | null;
37
+ export declare function appName(raw: unknown): string | null;
38
+ export declare function appWithOwner(raw: unknown, owner: unknown): string | null;
39
+ export declare function splitApp(signed: unknown): { app: string | null; owner: string | null };
40
+ export declare function appendMail(
41
+ text: string,
42
+ entry: { at?: string; from: string; app?: string | null; kind: "joined" | "mail"; to?: string; text?: string; mailKind?: MailKind; used?: number | null; replyTo?: string | null },
43
+ ): { changes: CommentChange[]; error?: undefined } | { error: string; changes?: undefined };
44
+ export declare function stripMail(text: string): string;
45
+ export declare function newFor(events: MailEvent[], name: string, since: string | null): MailEvent[];
46
+ export declare function describeEntry(event: MailEvent): string;
47
+ export declare function pairCount(
48
+ events: MailEvent[],
49
+ from: string,
50
+ to: string,
51
+ nowMs: number,
52
+ windowMs?: number,
53
+ ): number;
54
+ export declare function askDepth(events: MailEvent[], from: string): number;
55
+ /** The newest ask still waiting for an answer, or null. */
56
+ export declare function openAsk(events: readonly MailEvent[]): { at: string; from: string; to: string } | null;