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

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 (212) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +11 -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/chatHistoryPath.cjs +38 -0
  23. package/texContract/chatHistoryPath.d.cts +5 -0
  24. package/texContract/chatLedger.cjs +91 -0
  25. package/texContract/chatLedger.d.cts +21 -0
  26. package/texContract/computerTool.cjs +102 -0
  27. package/texContract/computerTool.d.cts +16 -0
  28. package/texContract/consentYes.cjs +22 -0
  29. package/texContract/consentYes.d.cts +5 -0
  30. package/texContract/contextGateway.cjs +52 -0
  31. package/texContract/contextGateway.d.cts +19 -0
  32. package/texContract/deskEligible.cjs +20 -0
  33. package/texContract/deskEligible.d.cts +3 -0
  34. package/texContract/downloads.cjs +129 -0
  35. package/texContract/downloads.d.cts +15 -0
  36. package/texContract/egressLedger.cjs +114 -0
  37. package/texContract/egressLedger.d.cts +14 -0
  38. package/texContract/emailRead.cjs +38 -0
  39. package/texContract/emailRead.d.cts +5 -0
  40. package/texContract/eventWords.cjs +35 -0
  41. package/texContract/eventWords.d.cts +4 -0
  42. package/texContract/fileParts.cjs +43 -0
  43. package/texContract/fileParts.d.cts +6 -0
  44. package/texContract/fileTables.cjs +243 -0
  45. package/texContract/fileWords.cjs +169 -0
  46. package/texContract/folded.cjs +16 -0
  47. package/texContract/folded.d.cts +3 -0
  48. package/texContract/googleAiAccess.cjs +12 -0
  49. package/texContract/googleAiAccess.d.cts +2 -0
  50. package/texContract/graphWires.cjs +18 -0
  51. package/texContract/graphWires.d.cts +5 -0
  52. package/texContract/groupSession.cjs +28 -0
  53. package/texContract/groupSession.d.cts +7 -0
  54. package/texContract/guestNames.cjs +136 -0
  55. package/texContract/guestNames.d.cts +35 -0
  56. package/texContract/heard.cjs +19 -0
  57. package/texContract/heard.d.cts +4 -0
  58. package/texContract/heldOffer.cjs +57 -0
  59. package/texContract/heldOffer.d.cts +8 -0
  60. package/texContract/helperCallers.cjs +29 -0
  61. package/texContract/helperCallers.d.cts +4 -0
  62. package/texContract/identity.cjs +179 -0
  63. package/texContract/identity.d.cts +8 -0
  64. package/texContract/jobLogEntries.cjs +93 -0
  65. package/texContract/jobLogEntries.d.cts +12 -0
  66. package/texContract/judgedActions.cjs +20 -0
  67. package/texContract/judgedActions.d.cts +4 -0
  68. package/texContract/labSandboxGate.cjs +63 -0
  69. package/texContract/labSandboxGate.d.cts +9 -0
  70. package/texContract/ledgerReadChars.cjs +4 -0
  71. package/texContract/ledgerReadChars.d.cts +3 -0
  72. package/texContract/mailCheck.cjs +90 -0
  73. package/texContract/mailCheck.d.cts +12 -0
  74. package/texContract/mailEntries.cjs +64 -0
  75. package/texContract/mailEntries.d.cts +13 -0
  76. package/texContract/mailHealth.cjs +60 -0
  77. package/texContract/mailHealth.d.cts +10 -0
  78. package/texContract/notePath.cjs +99 -0
  79. package/texContract/notePath.d.cts +4 -0
  80. package/texContract/noteRunFacts.cjs +136 -0
  81. package/texContract/noteRunFacts.d.cts +32 -0
  82. package/texContract/objectEtag.cjs +84 -0
  83. package/texContract/objectEtag.d.cts +4 -0
  84. package/texContract/objectPlace.cjs +32 -0
  85. package/texContract/objectPlace.d.cts +5 -0
  86. package/texContract/pageJobs.cjs +226 -0
  87. package/texContract/pageJobs.d.cts +13 -0
  88. package/texContract/pdfLinks.cjs +135 -0
  89. package/texContract/pdfLinks.d.cts +4 -0
  90. package/texContract/personHub.cjs +38 -0
  91. package/texContract/personHub.d.cts +5 -0
  92. package/texContract/personNameText.cjs +18 -0
  93. package/texContract/personNameText.d.cts +3 -0
  94. package/texContract/pinnedContext.cjs +12 -0
  95. package/texContract/pinnedContext.d.cts +3 -0
  96. package/texContract/quietHoursWindow.cjs +36 -0
  97. package/texContract/quietHoursWindow.d.cts +3 -0
  98. package/texContract/scopeClamp.cjs +117 -0
  99. package/texContract/scopeClamp.d.cts +5 -0
  100. package/texContract/scopes.cjs +29 -0
  101. package/texContract/scopes.d.cts +7 -0
  102. package/texContract/searchSettings.cjs +54 -0
  103. package/texContract/searchSettings.d.cts +6 -0
  104. package/texContract/settingHabits.cjs +87 -0
  105. package/texContract/settingHabits.d.cts +20 -0
  106. package/texContract/settingsNotes.cjs +217 -0
  107. package/texContract/settingsNotes.d.cts +26 -0
  108. package/texContract/shownEmail.cjs +181 -0
  109. package/texContract/texClients.cjs +53 -0
  110. package/texContract/texClients.d.cts +12 -0
  111. package/texContract/texGraph.cjs +593 -0
  112. package/texContract/texGraph.d.cts +55 -0
  113. package/texContract/texKeys.cjs +100 -0
  114. package/texContract/texKeys.d.cts +13 -0
  115. package/texContract/texOwnSources.cjs +9 -0
  116. package/texContract/texOwnSources.d.cts +3 -0
  117. package/texContract/texStoreNames.cjs +26 -0
  118. package/texContract/texStoreNames.d.cts +12 -0
  119. package/texContract/texStoreWire.cjs +306 -0
  120. package/texContract/texStoreWire.d.cts +32 -0
  121. package/texContract/threadsFold.cjs +75 -0
  122. package/texContract/threadsFold.d.cts +22 -0
  123. package/texContract/toolActions.cjs +253 -0
  124. package/texContract/toolCatalog.cjs +49 -0
  125. package/texContract/toolCatalog.generated.json +90 -0
  126. package/texContract/toolContract.cjs +52 -0
  127. package/texContract/toolContract.d.cts +12 -0
  128. package/texContract/toolShapes.cjs +14 -0
  129. package/texContract/transcription.cjs +101 -0
  130. package/texContract/transcription.d.cts +3 -0
  131. package/texContract/treeJobs.cjs +31 -0
  132. package/texContract/treeJobs.d.cts +3 -0
  133. package/texContract/turnSession.cjs +90 -0
  134. package/texContract/turnSession.d.cts +19 -0
  135. package/texContract/turnWords.cjs +90 -0
  136. package/texContract/turnWords.d.cts +9 -0
  137. package/texContract/uploadImages.cjs +131 -0
  138. package/texContract/uploadImages.d.cts +13 -0
  139. package/texContract/v2Names.cjs +41 -0
  140. package/texContract/v2SearchFetch.cjs +316 -0
  141. package/texContract/v2Translate.cjs +123 -0
  142. package/texContract/vaultTools.cjs +112 -0
  143. package/texContract/vaultTools.d.cts +15 -0
  144. package/texContract/yesWords.cjs +91 -0
  145. package/texShared/argumentCoercion.cjs +93 -0
  146. package/texShared/cellComments.cjs +122 -0
  147. package/texShared/cellComments.d.cts +21 -0
  148. package/texShared/comments.cjs +586 -0
  149. package/texShared/comments.d.cts +115 -0
  150. package/texShared/contentTypes.cjs +85 -0
  151. package/texShared/fileKinds.cjs +123 -0
  152. package/texShared/flags.cjs +124 -0
  153. package/texShared/flags.d.cts +21 -0
  154. package/texShared/folderJobInfo.cjs +301 -0
  155. package/texShared/folderJobInfo.d.cts +40 -0
  156. package/texShared/folderRoles.cjs +512 -0
  157. package/texShared/folderRoles.d.cts +73 -0
  158. package/texShared/githubOidc.ts +98 -0
  159. package/texShared/groupRunQuestions.cjs +98 -0
  160. package/texShared/groupRunQuestions.d.cts +4 -0
  161. package/texShared/inboxFolders.cjs +49 -0
  162. package/texShared/inboxFolders.d.cts +5 -0
  163. package/texShared/ink/drawing.cjs +474 -0
  164. package/texShared/ink/texFigure.cjs +252 -0
  165. package/texShared/ink/texFigure.d.cts +36 -0
  166. package/texShared/ink/texPoses.cjs +180 -0
  167. package/texShared/ink/texPoses.d.cts +20 -0
  168. package/texShared/jobPartEnd.cjs +133 -0
  169. package/texShared/jobPartEnd.d.cts +13 -0
  170. package/texShared/jobResume.cjs +31 -0
  171. package/texShared/jobResume.d.cts +5 -0
  172. package/texShared/jobSplit.cjs +90 -0
  173. package/texShared/jobSplit.d.cts +6 -0
  174. package/texShared/jobStart.cjs +56 -0
  175. package/texShared/jobStart.d.cts +9 -0
  176. package/texShared/mail.cjs +400 -0
  177. package/texShared/mail.d.cts +56 -0
  178. package/texShared/messageAnchors.cjs +38 -0
  179. package/texShared/models/aiKeys.cjs +137 -0
  180. package/texShared/models/aiKeys.d.cts +42 -0
  181. package/texShared/models/aiKeys.json +56 -0
  182. package/texShared/models/creditRest.cjs +269 -0
  183. package/texShared/models/promptBudget.cjs +295 -0
  184. package/texShared/models/promptSections.cjs +29 -0
  185. package/texShared/noteAppLink.cjs +23 -0
  186. package/texShared/notePreview.cjs +219 -0
  187. package/texShared/notePreview.d.cts +21 -0
  188. package/texShared/pages/blocks.cjs +215 -0
  189. package/texShared/pages/cover.cjs +164 -0
  190. package/texShared/pages/css.cjs +181 -0
  191. package/texShared/pages/cssBlocks.cjs +264 -0
  192. package/texShared/pages/draw.cjs +212 -0
  193. package/texShared/pages/drawRich.cjs +232 -0
  194. package/texShared/pages/html.cjs +168 -0
  195. package/texShared/pages/inline.cjs +251 -0
  196. package/texShared/pages/layout.cjs +76 -0
  197. package/texShared/pages/parse.cjs +418 -0
  198. package/texShared/pages/render.cjs +200 -0
  199. package/texShared/pages/skill.cjs +147 -0
  200. package/texShared/pages/skill.d.cts +5 -0
  201. package/texShared/pages/templates.cjs +336 -0
  202. package/texShared/r2Store.cjs +163 -0
  203. package/texShared/remoteImage.cjs +177 -0
  204. package/texShared/routines.cjs +656 -0
  205. package/texShared/routines.d.cts +86 -0
  206. package/texShared/servedListing.cjs +250 -0
  207. package/texShared/servedListing.d.cts +17 -0
  208. package/texShared/sheetCsv.cjs +566 -0
  209. package/texShared/sheetCsv.d.cts +91 -0
  210. package/texShared/storageLayout.cjs +88 -0
  211. package/texShared/storeKeys.cjs +144 -0
  212. package/texShared/toolArguments.cjs +323 -0
@@ -0,0 +1,512 @@
1
+ /**
2
+ * Built-in folders: the five every workspace has, and the extras a workspace
3
+ * can add. One module, read by the gateway, the control plane, the app and
4
+ * the router, so "which folder is the archive" has one answer.
5
+ *
6
+ * ## A folder's job lives on its row, and starts from its name
7
+ *
8
+ * Each built-in folder's tree row carries its job in `role`, under the job's
9
+ * original name (`inbox`, `projects`, ... `website`, `meetings`), so the
10
+ * folder keeps its job when it is renamed or moved (decided by the owner,
11
+ * 2026-10-18; `docs/decisions/app-and-console/folder-jobs.md`). A row is given
12
+ * its job when it is made at the root under a job's name, or the first time a
13
+ * folder that plays one by name is moved. Until then the name decides:
14
+ * `projects`, `1-projects` and `2-Projects` all play the projects role, the
15
+ * number only sorts (`folderRole`). `folderJobs` reads both.
16
+ *
17
+ * ## No number in front
18
+ *
19
+ * New workspaces get plain names (`inbox`, `projects`, ... `archive`), and
20
+ * the numbers older workspaces were given are dropped by a one-time rename
21
+ * (owner, 2026-10-21; `plainFolderName`, `functions/dropFolderNumbers.ts`).
22
+ * Order comes from the job and the row's `order`, never from a number. A
23
+ * number in front of a role's word still plays the role, so a writer or an
24
+ * AI client that names `0-inbox/` lands in the Inbox wherever it is now.
25
+ *
26
+ * ## The five main folders cannot be removed; extras can
27
+ *
28
+ * Inbox, Projects, Areas, Resources and Archive are what every system prompt
29
+ * and `archive_note` rely on, so they cannot be archived, trashed or deleted.
30
+ * In a workspace whose notes are kept by id they can be renamed, moved and
31
+ * nested like any folder (owner, 2026-10-18, replacing the 2026-10-08 lock).
32
+ * Extras (Clients, Teams, Products) can be removed like any folder.
33
+ *
34
+ * ## Order
35
+ *
36
+ * A folder's `order` on its row, when somebody has set one; otherwise Inbox,
37
+ * Projects, Areas, Data, Resources, extras, Website, the person's own folders by
38
+ * name, and Archive last, whatever the numbers say.
39
+ */
40
+
41
+ const MAIN_ROLES = Object.freeze(["inbox", "projects", "areas", "resources", "archive"]);
42
+ const EXTRA_ROLES = Object.freeze(["clients", "teams", "products"]);
43
+
44
+ /**
45
+ * The name a new workspace gets for each role: the role's own word, with no
46
+ * number in front (owner, 2026-10-21). Fixed, so it never drifts.
47
+ */
48
+ const DEFAULT_FOLDER = Object.freeze({
49
+ inbox: "inbox",
50
+ projects: "projects",
51
+ areas: "areas",
52
+ resources: "resources",
53
+ clients: "clients",
54
+ teams: "teams",
55
+ products: "products",
56
+ archive: "archive",
57
+ });
58
+
59
+ /** The folder names a new workspace starts with, in order. */
60
+ const MAIN_FOLDERS = Object.freeze(MAIN_ROLES.map((role) => DEFAULT_FOLDER[role]));
61
+
62
+ const ROLE_LABEL = Object.freeze({
63
+ inbox: "Inbox",
64
+ projects: "Projects",
65
+ areas: "Areas",
66
+ resources: "Resources",
67
+ archive: "Archive",
68
+ clients: "Clients",
69
+ teams: "Teams",
70
+ products: "Products",
71
+ });
72
+
73
+ /**
74
+ * One line per role: what belongs there, in the third person, because a
75
+ * shared workspace has no single reader. It becomes the folder's README and its
76
+ * line in `index.md`, which is what an AI reads when deciding where to file.
77
+ */
78
+ const ROLE_DESCRIPTION = Object.freeze({
79
+ inbox:
80
+ "Unfiled captures. Anything that arrives before somebody has decided where it belongs. Empty it by moving notes out, not by deleting them.",
81
+ projects:
82
+ "Active work with a finish line, one folder per project. When a project is done it moves to Archive.",
83
+ areas:
84
+ "Ongoing responsibilities with no finish line, such as health, money or a team somebody runs.",
85
+ resources:
86
+ "Reference material worth finding again: how things work, decisions and why, notes on things read.",
87
+ archive:
88
+ "Finished, cancelled or superseded. Move things here rather than deleting them.",
89
+ clients:
90
+ "One folder per client or customer: who they are, what they need, what was promised and what happened.",
91
+ teams:
92
+ "One folder per team or function: what it owns, how it runs, and what somebody joining it needs.",
93
+ products:
94
+ "One folder per product made or sold: what it is, who it is for, and where it is going.",
95
+ });
96
+
97
+ /** Order in which roles are drawn; own folders sit between extras and archive. */
98
+ const ROLE_RANK = Object.freeze({
99
+ inbox: 0,
100
+ projects: 1,
101
+ areas: 2,
102
+ resources: 3,
103
+ clients: 4,
104
+ teams: 5,
105
+ products: 6,
106
+ archive: 9,
107
+ });
108
+ const OWN_FOLDER_RANK = 8;
109
+
110
+ const ROLE_PATTERN = /^(?:\d+-)?([a-z]+)$/i;
111
+
112
+ /**
113
+ * The jobs a folder ROW can carry in `role`: the eight built-ins, the website
114
+ * folder, the meetings folder, Tex's folder and the data folder, always under
115
+ * these original names.
116
+ */
117
+ const ROW_ROLES = Object.freeze([...MAIN_ROLES, ...EXTRA_ROLES, "website", "meetings", "tex", "data", "bots"]);
118
+
119
+ /** The website folder's name when nothing has moved it (`DEFAULT_WEBSITE_ROOT`). */
120
+ const WEBSITE_FOLDER = "website";
121
+
122
+ /**
123
+ * Tex's folder's name when nothing has moved it: what Tex reads and writes
124
+ * (`tex/about-me.md`, `tex/routines/`), carried to wherever the folder doing
125
+ * the job is now by `jobPath` (owner, 2026-10-18).
126
+ */
127
+ const TEX_FOLDER = "tex";
128
+
129
+ /**
130
+ * The data folder's name when nothing has moved it: a workspace's data
131
+ * sources and the metrics worked out from them (`data/metrics/`), made the
132
+ * first time a source or metric is added and carried to wherever the folder
133
+ * doing the job is now by `jobPath`, as `website/...` and `tex/...` are
134
+ * (`docs/decisions/app-and-console/folder-jobs.md`).
135
+ */
136
+ const DATA_FOLDER = "data";
137
+
138
+ /**
139
+ * The bots folder's name when nothing has moved it: one folder per bot beside the
140
+ * Areas folder, its card `bots/<bot>/about.md` and its mail `bots/<bot>/mail/`
141
+ * (the owner, 2026-11-25: "top level bots yes"), made the first time a bot is
142
+ * added and drawn with its own icon like the other built-in folders (2026-11-26).
143
+ */
144
+ const BOTS_FOLDER = "bots";
145
+
146
+ /**
147
+ * What a row's `role` holds once a person took a job away from it, or gave it
148
+ * to another folder: a folder that does no job even though its name says one,
149
+ * so a root `clients` the person said is not their Clients folder stays theirs
150
+ * (owner, 2026-10-18, `docs/decisions/app-and-console/folder-jobs.md`).
151
+ */
152
+ const NO_JOB = "none";
153
+
154
+ const JOB_LABEL = Object.freeze({ ...ROLE_LABEL, website: "Website", meetings: "Meetings", tex: "Tex", data: "Data", bots: "Bots" });
155
+
156
+ /** Where each job is drawn among its siblings when no `order` is set, in steps of ten. */
157
+ /** Data draws between Areas and Resources, as the data sources boards draw it: the areas read their metrics from it. */
158
+ /** Bots draws right after Areas, whose work they hold. */
159
+ const JOB_RANK = Object.freeze({ ...ROLE_RANK, website: 7, meetings: 7, tex: OWN_FOLDER_RANK, data: 2.5, bots: 2.2 });
160
+
161
+ function isRowRole(value) {
162
+ return typeof value === "string" && ROW_ROLES.includes(value);
163
+ }
164
+
165
+ /**
166
+ * The job a top-level folder NAME plays: a built-in role (`folderRole`), or
167
+ * `website`, `tex`, `data` and `bots` for those folders' own names.
168
+ */
169
+ function jobOfName(name) {
170
+ if (name === WEBSITE_FOLDER) return "website";
171
+ if (name === TEX_FOLDER) return "tex";
172
+ if (name === DATA_FOLDER) return "data";
173
+ if (name === BOTS_FOLDER) return "bots";
174
+ return folderRole(name);
175
+ }
176
+
177
+ /**
178
+ * The role a top-level folder name plays, or null. Takes a NAME, not a path:
179
+ * pass the first segment. `Archive`, `archive`, `4-archive` and `9-archive`
180
+ * are all `"archive"`; `old-archive` and `archive-2024` are nobody's.
181
+ */
182
+ function folderRole(name) {
183
+ if (typeof name !== "string") return null;
184
+ const match = ROLE_PATTERN.exec(name);
185
+ if (!match) return null;
186
+ const word = match[1].toLowerCase();
187
+ return Object.prototype.hasOwnProperty.call(ROLE_RANK, word) ? word : null;
188
+ }
189
+
190
+ /**
191
+ * A built-in folder's name without its sort number, or null when there is
192
+ * nothing to drop: `1-projects` is `projects`, `2-Areas` is `Areas` (the word
193
+ * as it was typed), and `projects`, `1-plan` and `2026-plans` are null. Only
194
+ * a name that plays a role (`folderRole`) is changed, so a person's own
195
+ * numbered folders keep their numbers.
196
+ */
197
+ function plainFolderName(name) {
198
+ if (typeof name !== "string") return null;
199
+ const match = /^\d+-([a-z]+)$/i.exec(name);
200
+ if (match === null || folderRole(name) === null) return null;
201
+ return match[1];
202
+ }
203
+
204
+ /** The role of the folder a path names, when that folder is top-level. */
205
+ function topLevelRole(path) {
206
+ if (typeof path !== "string") return null;
207
+ const trimmed = path.replace(/^\/+|\/+$/g, "");
208
+ if (trimmed === "" || trimmed.includes("/")) return null;
209
+ return folderRole(trimmed);
210
+ }
211
+
212
+ /**
213
+ * Is this path one of the five protected folders itself (not something in
214
+ * it)? `1-projects` and `1-projects/` are; `1-projects/foo` is not.
215
+ */
216
+ function isMainFolder(path) {
217
+ const role = topLevelRole(path);
218
+ return role !== null && MAIN_ROLES.includes(role);
219
+ }
220
+
221
+ function isExtraRole(role) {
222
+ return EXTRA_ROLES.includes(role);
223
+ }
224
+
225
+ /** Where a top-level folder is drawn among its siblings. */
226
+ function folderRank(name) {
227
+ const job = jobOfName(name);
228
+ return job === null ? OWN_FOLDER_RANK : JOB_RANK[job];
229
+ }
230
+
231
+ /**
232
+ * Sort comparator for top-level folder NAMES: role order, then name. Use it
233
+ * only on the workspace root; below it, folders are plain names.
234
+ */
235
+ function compareTopLevelFolders(a, b) {
236
+ const rank = folderRank(a) - folderRank(b);
237
+ if (rank !== 0) return rank;
238
+ return a.localeCompare(b);
239
+ }
240
+
241
+ /**
242
+ * The one order a folder listing is drawn in, for every surface that sorts
243
+ * one (the server, the offline mirror, optimistic rows): folders before files,
244
+ * by name, except at the workspace root (`parent === ""`), where folders take
245
+ * their role order and Archive goes last. Two surfaces that disagreed would be
246
+ * a row that jumps when the refresh arrives.
247
+ */
248
+ function compareListingEntries(parent, a, b) {
249
+ if (a.kind !== b.kind) return a.kind === "folder" ? -1 : 1;
250
+ if (a.kind === "folder") {
251
+ const rank = listingRank(parent, a) - listingRank(parent, b);
252
+ if (rank !== 0 && !Number.isNaN(rank)) return rank;
253
+ }
254
+ return a.name.localeCompare(b.name);
255
+ }
256
+
257
+ /**
258
+ * Where a folder entry is drawn: its row's `order` when set, else its job's
259
+ * rank (the row's `role`, or at the root its name's), else own folders at the
260
+ * root after the extras and below it by name alone.
261
+ */
262
+ function listingRank(parent, entry) {
263
+ if (typeof entry.order === "number" && Number.isFinite(entry.order)) return entry.order;
264
+ const job = isRowRole(entry.role) ? entry.role : parent === "" ? jobOfName(entry.name) : null;
265
+ if (job !== null) return JOB_RANK[job] * 10;
266
+ return parent === "" ? OWN_FOLDER_RANK * 10 : Number.MAX_SAFE_INTEGER;
267
+ }
268
+
269
+ /**
270
+ * The first top-level folder of each role among `names`, or null. When two
271
+ * folders claim one role (`4-archive` and `9-archive`), the one sorting first
272
+ * by name wins, so the answer does not depend on listing order.
273
+ */
274
+ function rolesIn(names) {
275
+ const roles = {};
276
+ for (const role of Object.keys(ROLE_RANK)) roles[role] = null;
277
+ for (const name of [...names].sort()) {
278
+ const role = folderRole(name);
279
+ if (role !== null && roles[role] === null) roles[role] = name;
280
+ }
281
+ return roles;
282
+ }
283
+
284
+ /**
285
+ * Is this path the protected folder for its role, given the workspace's
286
+ * top-level folder names?
287
+ *
288
+ * One folder per main role is protected: the one `rolesIn` picks, which is
289
+ * the one orient and `archive_note` file into. A second folder
290
+ * claiming the same role (an agent's `projects` beside `Projects`, a
291
+ * `9-archive` beside `4-archive`) is an ordinary folder, so it can be emptied
292
+ * into the real one and removed (decided by the owner, 2026-10-14).
293
+ *
294
+ * `names` should be what the caller can see. A role-mate the caller cannot
295
+ * see is left out, which only ever keeps a folder protected: the safe side.
296
+ */
297
+ function isProtectedFolder(path, names) {
298
+ if (!isMainFolder(path)) return false;
299
+ const name = path.replace(/^\/+|\/+$/g, "");
300
+ const role = topLevelRole(name);
301
+ return rolesIn([...names, name])[role] === name;
302
+ }
303
+
304
+ /**
305
+ * Characters that draw as nothing: zero-width spaces and joiners, the soft
306
+ * hyphen, the byte-order mark, and the direction marks and isolates
307
+ * (`displayText.cjs` adds isolates around names it draws).
308
+ */
309
+ const INVISIBLE = /[\u00AD\u200B-\u200F\u202A-\u202E\u2060-\u2064\u2066-\u2069\uFEFF]/g;
310
+
311
+ /**
312
+ * Dashes that draw as a hyphen: the Unicode hyphens (an AI client writing
313
+ * "kings‑1" with a non-breaking hyphen is the case that found this,
314
+ * 2026-10-14), the figure, en and em dashes, the minus sign, and their
315
+ * small and fullwidth forms.
316
+ */
317
+ const DASHES = /[\u2010-\u2015\u2212\uFE58\uFE63\uFF0D]/g;
318
+
319
+ /**
320
+ * How sibling names are compared: as a person reads them. Case-blind, blind
321
+ * to how an accent was typed, blind to compatibility forms (fullwidth
322
+ * letters), to characters that draw as nothing, and to which dash was used.
323
+ * Two names that fold alike look like one name in the tree, and the second is
324
+ * refused (`siblingTwin`).
325
+ */
326
+ function foldName(name) {
327
+ return String(name).normalize("NFKC").replace(INVISIBLE, "").replace(DASHES, "-").toLowerCase();
328
+ }
329
+
330
+ /**
331
+ * The existing sibling a new name would sit beside as a twin, or null.
332
+ *
333
+ * Two names in one folder that differ only by case read as one folder to a
334
+ * person and are two to the bucket, so the second is refused (decided by the
335
+ * owner, 2026-10-14). At the workspace root a new folder also may not claim a
336
+ * built-in role another folder already plays: `1-projects` beside `Projects`
337
+ * is the same twin by its other spelling. The name itself never twins itself.
338
+ *
339
+ * @param {string} name the new name (one segment)
340
+ * @param {Iterable<string>} siblings names already in that folder
341
+ * @param {{ topLevelFolder?: boolean }} [options] the new name is a folder at the root
342
+ */
343
+ function siblingTwin(name, siblings, options = {}) {
344
+ const folded = foldName(name);
345
+ const role = options.topLevelFolder ? folderRole(name) : null;
346
+ for (const sibling of siblings) {
347
+ if (sibling === name) continue;
348
+ if (foldName(sibling) === folded) return sibling;
349
+ if (role !== null && folderRole(sibling) === role) return sibling;
350
+ }
351
+ return null;
352
+ }
353
+
354
+ /**
355
+ * The refusal both engines give a twin, so an agent reads one rule whichever
356
+ * door it used: what is already there, and the path to write instead.
357
+ */
358
+ function twinMessage(name, twin, instead, topLevel) {
359
+ const role = topLevel ? folderRole(twin) : null;
360
+ if (role !== null && foldName(name) !== foldName(twin)) {
361
+ return `${twin} is already this workspace's ${ROLE_LABEL[role]} folder, so use ${instead} instead of making ${name}.`;
362
+ }
363
+ return `${twin} is already here, and names in one folder can't differ only by case. Use ${instead} instead.`;
364
+ }
365
+
366
+ /**
367
+ * Which folder does each job, from folder rows `{path, name, role?, top}`
368
+ * (`top`: the row sits at the root): `{jobs, roots}`, where `jobs[job]` is
369
+ * the path of the folder doing it, or null, and `roots` the root's folder
370
+ * names. A row's own `role` wins wherever the folder now is; a job no row
371
+ * claims falls to the root folder named for it (`rolesIn`, plus `website`).
372
+ * Two rows claiming one job (never written by us) resolve to the first path.
373
+ */
374
+ function folderJobs(rows) {
375
+ const jobs = {};
376
+ for (const job of ROW_ROLES) jobs[job] = null;
377
+ const sorted = [...rows].sort((a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0));
378
+ for (const row of sorted) {
379
+ if (isRowRole(row.role) && jobs[row.role] === null) jobs[row.role] = row.path;
380
+ }
381
+ // A row that says it does no job (`NO_JOB`) is claimed too: its name gives it none.
382
+ const claimed = new Set(sorted.filter((row) => isRowRole(row.role) || row.role === NO_JOB).map((row) => row.path));
383
+ const unclaimedRoots = sorted.filter((row) => row.top && !claimed.has(row.path)).map((row) => row.name);
384
+ const byName = rolesIn(unclaimedRoots);
385
+ for (const role of Object.keys(byName)) {
386
+ if (jobs[role] === null && byName[role] !== null) jobs[role] = byName[role];
387
+ }
388
+ if (jobs.website === null && unclaimedRoots.includes(WEBSITE_FOLDER)) jobs.website = WEBSITE_FOLDER;
389
+ if (jobs.tex === null && unclaimedRoots.includes(TEX_FOLDER)) jobs.tex = TEX_FOLDER;
390
+ if (jobs.data === null && unclaimedRoots.includes(DATA_FOLDER)) jobs.data = DATA_FOLDER;
391
+ if (jobs.bots === null && unclaimedRoots.includes(BOTS_FOLDER)) jobs.bots = BOTS_FOLDER;
392
+ return { jobs, roots: sorted.filter((row) => row.top).map((row) => row.name) };
393
+ }
394
+
395
+ /** The job the folder at `path` does, given `folderJobs`'s answer, or null. */
396
+ function jobAt(folderJobsAnswer, path) {
397
+ if (!folderJobsAnswer || typeof path !== "string") return null;
398
+ const clean = path.replace(/^\/+|\/+$/g, "");
399
+ for (const job of ROW_ROLES) if (folderJobsAnswer.jobs[job] === clean) return job;
400
+ return null;
401
+ }
402
+
403
+ /**
404
+ * A path written under a job's name, carried to the folder doing that job
405
+ * now: `0-inbox/memories/a.md` is `Capture/memories/a.md` once the Inbox is
406
+ * called Capture. Only the first segment is read, only when it names a job
407
+ * (`jobOfName`), and never when a root folder really has that name, so a
408
+ * folder somebody made wins over the rule. Everything else is returned as
409
+ * given. This is what keeps every writer that names a built-in folder by its
410
+ * default name (email, meetings, memories, sessions) and every AI client that
411
+ * guesses `0-inbox/` landing in the real folder after a rename.
412
+ */
413
+ function jobPath(folderJobsAnswer, path) {
414
+ if (!folderJobsAnswer || typeof path !== "string" || path === "") return path;
415
+ const slash = path.indexOf("/");
416
+ const first = slash < 0 ? path : path.slice(0, slash);
417
+ const job = jobOfName(first);
418
+ if (job === null) return path;
419
+ if (folderJobsAnswer.roots.includes(first)) return path;
420
+ const home = folderJobsAnswer.jobs[job];
421
+ if (typeof home !== "string" || home === "" || home === first) return path;
422
+ return slash < 0 ? home : `${home}${path.slice(slash)}`;
423
+ }
424
+
425
+ /** The main roles a workspace's top-level folders do not cover yet. */
426
+ function missingMainRoles(names) {
427
+ const roles = rolesIn(names);
428
+ return MAIN_ROLES.filter((role) => roles[role] === null);
429
+ }
430
+
431
+ /**
432
+ * Which notes a search index fills first (decided by the owner, 2026-10-08;
433
+ * the admin console names them T0, T1, T2):
434
+ * everything else is 1, the Inbox 2 because it changes so much, the Archive 3,
435
+ * "whenever we can get to it". Read from the note's TOP-LEVEL folder, so
436
+ * `0-inbox/a.md` is 2 and `1-projects/inbox/a.md` is 1; a note at the root is 1.
437
+ * It decides order and the per-priority counts the admin console shows, never
438
+ * whether a note is indexed at all.
439
+ */
440
+ const INDEXING_PRIORITIES = Object.freeze([1, 2, 3]);
441
+
442
+ function indexingPriority(path) {
443
+ if (typeof path !== "string") return 1;
444
+ const slash = path.indexOf("/");
445
+ if (slash <= 0) return 1;
446
+ const role = folderRole(path.slice(0, slash));
447
+ if (role === "inbox") return 2;
448
+ if (role === "archive") return 3;
449
+ return 1;
450
+ }
451
+
452
+ /** Indexing order: priority, then path, so a walk resumes where it stopped. */
453
+ function compareIndexingOrder(a, b) {
454
+ const rank = indexingPriority(a) - indexingPriority(b);
455
+ if (rank !== 0) return rank;
456
+ return a < b ? -1 : a > b ? 1 : 0;
457
+ }
458
+
459
+ /**
460
+ * Notes counted per priority: `[{priority, indexed, pending}]`, one entry for
461
+ * each priority in order. `isIndexed(path)` decides a census path's column;
462
+ * `extraPending` (removals not yet applied, say) are counted by their own path.
463
+ */
464
+ function countByIndexingPriority(paths, isIndexed, extraPending = []) {
465
+ const counts = INDEXING_PRIORITIES.map((priority) => ({ priority, indexed: 0, pending: 0 }));
466
+ for (const path of paths) {
467
+ const entry = counts[indexingPriority(path) - 1];
468
+ if (isIndexed(path)) entry.indexed += 1;
469
+ else entry.pending += 1;
470
+ }
471
+ for (const path of extraPending) counts[indexingPriority(path) - 1].pending += 1;
472
+ return counts;
473
+ }
474
+
475
+ module.exports = {
476
+ ROW_ROLES,
477
+ WEBSITE_FOLDER,
478
+ TEX_FOLDER,
479
+ DATA_FOLDER,
480
+ BOTS_FOLDER,
481
+ NO_JOB,
482
+ JOB_LABEL,
483
+ isRowRole,
484
+ jobOfName,
485
+ folderJobs,
486
+ jobAt,
487
+ jobPath,
488
+ MAIN_ROLES,
489
+ EXTRA_ROLES,
490
+ DEFAULT_FOLDER,
491
+ MAIN_FOLDERS,
492
+ ROLE_LABEL,
493
+ ROLE_DESCRIPTION,
494
+ folderRole,
495
+ plainFolderName,
496
+ topLevelRole,
497
+ isMainFolder,
498
+ isExtraRole,
499
+ folderRank,
500
+ compareTopLevelFolders,
501
+ compareListingEntries,
502
+ rolesIn,
503
+ missingMainRoles,
504
+ isProtectedFolder,
505
+ foldName,
506
+ siblingTwin,
507
+ twinMessage,
508
+ INDEXING_PRIORITIES,
509
+ indexingPriority,
510
+ compareIndexingOrder,
511
+ countByIndexingPriority,
512
+ };
@@ -0,0 +1,73 @@
1
+ /** Types for `folderRoles.cjs`; see that file for the rules and the reasons. */
2
+
3
+ export type MainRole = "inbox" | "projects" | "areas" | "resources" | "archive";
4
+ export type ExtraRole = "clients" | "teams" | "products";
5
+ export type FolderRole = MainRole | ExtraRole;
6
+ /** A job a folder row can carry in `role`. */
7
+ export type RowRole = FolderRole | "website" | "meetings" | "tex" | "data" | "bots";
8
+
9
+ /** Which folder does each job (`folderJobs`). */
10
+ export interface FolderJobs {
11
+ jobs: Record<RowRole, string | null>;
12
+ roots: string[];
13
+ }
14
+
15
+ export declare const ROW_ROLES: readonly RowRole[];
16
+ export declare const WEBSITE_FOLDER: "website";
17
+ export declare const TEX_FOLDER: "tex";
18
+ export declare const DATA_FOLDER: "data";
19
+ export declare const BOTS_FOLDER: "bots";
20
+ export declare const NO_JOB: "none";
21
+ export declare const JOB_LABEL: Readonly<Record<RowRole, string>>;
22
+ export declare function isRowRole(value: unknown): value is RowRole;
23
+ export declare function jobOfName(name: string): RowRole | null;
24
+ export declare function folderJobs(
25
+ rows: Iterable<{ path: string; name: string; role?: string | null; top: boolean }>,
26
+ ): FolderJobs;
27
+ export declare function jobAt(jobs: FolderJobs | null | undefined, path: string): RowRole | null;
28
+ export declare function jobPath(jobs: FolderJobs | null | undefined, path: string): string;
29
+
30
+ export declare const MAIN_ROLES: readonly MainRole[];
31
+ export declare const EXTRA_ROLES: readonly ExtraRole[];
32
+ export declare const DEFAULT_FOLDER: Readonly<Record<FolderRole, string>>;
33
+ export declare const MAIN_FOLDERS: readonly string[];
34
+ export declare const ROLE_LABEL: Readonly<Record<FolderRole, string>>;
35
+ export declare const ROLE_DESCRIPTION: Readonly<Record<FolderRole, string>>;
36
+
37
+ export declare function folderRole(name: string): FolderRole | null;
38
+ export declare function plainFolderName(name: string | undefined | null): string | null;
39
+ export declare function topLevelRole(path: string): FolderRole | null;
40
+ export declare function isMainFolder(path: string): boolean;
41
+ export declare function isExtraRole(role: FolderRole | null): role is ExtraRole;
42
+ export declare function folderRank(name: string): number;
43
+ export declare function compareTopLevelFolders(a: string, b: string): number;
44
+ export declare function compareListingEntries(
45
+ parent: string,
46
+ a: { kind: string; name: string; role?: string | null; order?: number | null },
47
+ b: { kind: string; name: string; role?: string | null; order?: number | null },
48
+ ): number;
49
+ export declare function rolesIn(names: Iterable<string>): Record<FolderRole, string | null>;
50
+ export declare function missingMainRoles(names: Iterable<string>): MainRole[];
51
+ export declare function isProtectedFolder(path: string, names: Iterable<string>): boolean;
52
+ export declare function foldName(name: string): string;
53
+ export declare function siblingTwin(
54
+ name: string,
55
+ siblings: Iterable<string>,
56
+ options?: { topLevelFolder?: boolean },
57
+ ): string | null;
58
+ export declare function twinMessage(name: string, twin: string, instead: string, topLevel: boolean): string;
59
+
60
+ export type IndexingPriority = 1 | 2 | 3;
61
+ export interface IndexingPriorityCount {
62
+ priority: IndexingPriority;
63
+ indexed: number;
64
+ pending: number;
65
+ }
66
+ export declare const INDEXING_PRIORITIES: readonly IndexingPriority[];
67
+ export declare function indexingPriority(path: string): IndexingPriority;
68
+ export declare function compareIndexingOrder(a: string, b: string): number;
69
+ export declare function countByIndexingPriority(
70
+ paths: Iterable<string>,
71
+ isIndexed: (path: string) => boolean,
72
+ extraPending?: Iterable<string>,
73
+ ): IndexingPriorityCount[];
@@ -0,0 +1,98 @@
1
+ /**
2
+ * GitHub Actions OIDC: the only way a run reaches the Test Set (`infra/tex-eval`) or the Lab runner
3
+ * (`infra/tex-runner`). A workflow job with `id-token: write` asks GitHub for a token naming the service as its
4
+ * audience; GitHub signs it, and its claims say which repository, which workflow file at which ref, and which run
5
+ * asked. Each service checks the signature against GitHub's published keys and then the claims, so only main's own
6
+ * workflow for that door gets in. There is no secret to keep: a branch can dispatch `tex-test-set.yml` on itself,
7
+ * but then its token names `@refs/heads/<branch>`, and is refused.
8
+ */
9
+
10
+ export const ISSUER = "https://token.actions.githubusercontent.com";
11
+ export const AUDIENCE = "context-tex-eval";
12
+ export const REPOSITORY = "Supa-Media/context";
13
+ const JWKS_URL = `${ISSUER}/.well-known/jwks`;
14
+
15
+ /** The workflows each door takes, as GitHub writes `job_workflow_ref`: the file on main and nowhere else. */
16
+ export const WORKFLOWS = {
17
+ run: `${REPOSITORY}/.github/workflows/tex-test-set.yml@refs/heads/main`,
18
+ seed: `${REPOSITORY}/.github/workflows/tex-test-set-seed.yml@refs/heads/main`,
19
+ "search-run": `${REPOSITORY}/.github/workflows/search-test-set.yml@refs/heads/main`,
20
+ "search-seed": `${REPOSITORY}/.github/workflows/search-test-set-seed.yml@refs/heads/main`,
21
+ // Not a door of this service: the Lab runner (infra/tex-runner) checks its own audience with this same code.
22
+ "lab-runner": `${REPOSITORY}/.github/workflows/tex-lab-sandbox.yml@refs/heads/main`,
23
+ } as const;
24
+ export type Door = keyof typeof WORKFLOWS;
25
+
26
+ export interface Claims {
27
+ iss: string;
28
+ aud: string | string[];
29
+ exp: number;
30
+ iat: number;
31
+ nbf?: number;
32
+ repository: string;
33
+ ref: string;
34
+ job_workflow_ref: string;
35
+ run_id: string;
36
+ run_attempt?: string;
37
+ actor?: string;
38
+ [k: string]: unknown;
39
+ }
40
+
41
+ export class Refused extends Error {
42
+ constructor(message: string) {
43
+ super(message);
44
+ this.name = "Refused";
45
+ }
46
+ }
47
+
48
+ type Jwk = JsonWebKey & { kid?: string };
49
+ export type KeySource = () => Promise<Jwk[]>;
50
+
51
+ let cached: { at: number; keys: Jwk[] } | null = null;
52
+ /** GitHub's signing keys, kept ten minutes. */
53
+ export const githubKeys: KeySource = async () => {
54
+ if (cached && Date.now() - cached.at < 600_000) return cached.keys;
55
+ const res = await fetch(JWKS_URL);
56
+ if (!res.ok) throw new Refused("GitHub's signing keys could not be read");
57
+ const body = (await res.json()) as { keys?: Jwk[] };
58
+ cached = { at: Date.now(), keys: body.keys ?? [] };
59
+ return cached.keys;
60
+ };
61
+
62
+ const b64url = (s: string) => {
63
+ const pad = s.replace(/-/g, "+").replace(/_/g, "/") + "===".slice((s.length + 3) % 4);
64
+ return Uint8Array.from(atob(pad), (c) => c.charCodeAt(0));
65
+ };
66
+ const decode = <T>(s: string): T => JSON.parse(new TextDecoder().decode(b64url(s))) as T;
67
+
68
+ /** The bearer token's claims when GitHub signed it for this door; else throws `Refused` with the reason. */
69
+ export async function verify(authorization: string | null, door: Door, keys: KeySource = githubKeys, now = Date.now(), audience: string = AUDIENCE): Promise<Claims> {
70
+ const token = /^Bearer\s+(\S+)$/i.exec(authorization ?? "")?.[1];
71
+ if (!token) throw new Refused("no token");
72
+ const parts = token.split(".");
73
+ if (parts.length !== 3) throw new Refused("not a signed token");
74
+ let header: { alg?: string; kid?: string };
75
+ let claims: Claims;
76
+ try {
77
+ header = decode(parts[0]);
78
+ claims = decode(parts[1]);
79
+ } catch {
80
+ throw new Refused("not a signed token");
81
+ }
82
+ if (header.alg !== "RS256") throw new Refused("not signed the way GitHub signs");
83
+ const jwk = (await keys()).find((k) => k.kid === header.kid);
84
+ if (!jwk) throw new Refused("signed by a key GitHub does not publish");
85
+ const key = await crypto.subtle.importKey("jwk", { kty: jwk.kty, n: jwk.n, e: jwk.e, alg: "RS256", ext: true }, { name: "RSASSA-PKCS1-v1_5", hash: "SHA-256" }, false, ["verify"]);
86
+ const good = await crypto.subtle.verify("RSASSA-PKCS1-v1_5", key, b64url(parts[2]), new TextEncoder().encode(`${parts[0]}.${parts[1]}`));
87
+ if (!good) throw new Refused("the signature does not hold");
88
+ const s = Math.floor(now / 1000);
89
+ if (claims.iss !== ISSUER) throw new Refused("not issued by GitHub Actions");
90
+ const aud = Array.isArray(claims.aud) ? claims.aud : [claims.aud];
91
+ if (!aud.includes(audience)) throw new Refused("not meant for this service");
92
+ if (!(claims.exp > s)) throw new Refused("expired");
93
+ if (typeof claims.nbf === "number" && claims.nbf > s + 60) throw new Refused("not valid yet");
94
+ if (claims.repository !== REPOSITORY) throw new Refused("not this repository");
95
+ if (claims.job_workflow_ref !== WORKFLOWS[door] || claims.ref !== "refs/heads/main") throw new Refused(`only ${WORKFLOWS[door]} may use this door`);
96
+ if (!/^\d+$/.test(String(claims.run_id ?? ""))) throw new Refused("no run named");
97
+ return claims;
98
+ }