@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,115 @@
1
+ /** Types for `comments.cjs`; see that file for the format and the reasons. */
2
+
3
+ export interface CommentChange {
4
+ from: number;
5
+ to: number;
6
+ insert: string;
7
+ }
8
+
9
+ export interface CommentEvent {
10
+ at: string;
11
+ author: string;
12
+ /**
13
+ * `suggestion` is Tex's proposed replacement for the anchored words (its
14
+ * `text`); `kept` and `undid` answer the pending one.
15
+ */
16
+ kind: "comment" | "resolved" | "reopened" | "suggestion" | "kept" | "undid";
17
+ text: string;
18
+ /** The event's lines in the file, `[start, end)`. */
19
+ start: number;
20
+ end: number;
21
+ }
22
+
23
+ export interface CommentThread {
24
+ id: string;
25
+ quote: string;
26
+ events: CommentEvent[];
27
+ status: "open" | "resolved";
28
+ /** The suggestion still waiting for Keep or Undo, or null. `index` is its place in `events`. */
29
+ pending: { text: string; at: string; author: string; index: number } | null;
30
+ anchored: boolean;
31
+ headerStart: number;
32
+ end: number;
33
+ }
34
+
35
+ export interface CommentAnchor {
36
+ id: string;
37
+ /** Where the opening marker starts. */
38
+ openStart: number;
39
+ /** The highlighted words, `[from, to)`. */
40
+ from: number;
41
+ to: number;
42
+ /** Where the closing marker ends. */
43
+ closeEnd: number;
44
+ }
45
+
46
+ export interface CommentsBlock {
47
+ start: number;
48
+ end: number;
49
+ info: string;
50
+ bodyStart: number;
51
+ bodyEnd: number;
52
+ closed: boolean;
53
+ }
54
+
55
+ export declare const COMMENTS_INFO: "comments";
56
+ export declare const MARKER_RE: RegExp;
57
+ export declare function openMarker(id: string): string;
58
+ export declare function closeMarker(id: string): string;
59
+ export declare function findBlock(text: string): CommentsBlock | null;
60
+ export declare function findAnchors(text: string): Map<string, CommentAnchor>;
61
+ export declare function parseComments(text: string): {
62
+ block: CommentsBlock | null;
63
+ threads: CommentThread[];
64
+ anchors: Map<string, CommentAnchor>;
65
+ };
66
+ export declare function sanitizeAuthor(name: string): string;
67
+ export declare function newThreadId(text: string, random?: () => number): string;
68
+ export declare function locateQuote(
69
+ text: string,
70
+ quote: string,
71
+ occurrence?: number,
72
+ ): { from: number; to: number; error?: undefined } | { error: string };
73
+ export declare function addThread(
74
+ text: string,
75
+ options: {
76
+ quote?: string;
77
+ occurrence?: number;
78
+ from?: number;
79
+ to?: number;
80
+ author: string;
81
+ body: string;
82
+ at?: Date | string;
83
+ id?: string;
84
+ random?: () => number;
85
+ /** Allow `from === to`: a thread at the caret with no words highlighted. */
86
+ point?: boolean;
87
+ },
88
+ ): { id: string; changes: CommentChange[]; error?: undefined } | { error: string };
89
+ export declare function appendEvent(
90
+ text: string,
91
+ options: {
92
+ thread: string;
93
+ kind: "comment" | "resolved" | "reopened" | "suggestion" | "kept" | "undid";
94
+ author: string;
95
+ body?: string;
96
+ at?: Date | string;
97
+ },
98
+ ): { changes: CommentChange[]; error?: undefined } | { error: string };
99
+ export declare function keepSuggestion(
100
+ text: string,
101
+ options: { thread: string; author: string; at?: Date | string },
102
+ ): { changes: CommentChange[]; error?: undefined } | { error: string };
103
+ export declare function deleteComment(
104
+ text: string,
105
+ options: {
106
+ thread: string;
107
+ /** Which comment, counting the thread's comments from 0; 0 deletes the thread. */
108
+ index: number;
109
+ /** The comment as the reader saw it; a mismatch is refused. */
110
+ expect?: { at: string; author: string };
111
+ },
112
+ ): { changes: CommentChange[]; error?: undefined } | { error: string };
113
+ export declare function applyChanges(text: string, changes: readonly CommentChange[]): string;
114
+ export declare function stripComments(text: string): string;
115
+ export declare function describeComments(text: string): string | null;
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ /**
3
+ * The content types a stored object may be written as. The store's adapters on both sides use them, so they live in
4
+ * the shared code Tex's tree takes with it; `apps/mcp/src/store/contentTypes.js` and `store/index.js` re-export them.
5
+ */
6
+
7
+ /**
8
+ * What a stored object may be written as.
9
+ *
10
+ * **An enumeration, never free text, and that is a security property rather
11
+ * than tidiness.** The chosen value is interpolated straight into S3's
12
+ * `content-type` request header, so a caller-supplied string is header
13
+ * injection by the same route `assertSafeEtag` exists to close one function
14
+ * above. An allow-list means there is no string an attacker can reach this
15
+ * with at all.
16
+ *
17
+ * Markdown is the default and stays the default: a `put` that names nothing
18
+ * behaves exactly as every `put` in this codebase did before this map existed,
19
+ * so adding it changes no existing write.
20
+ *
21
+ * The image types are the ones `read_image` will hand back
22
+ * (`IMAGE_MIME_TYPES` in `src/index.js`). Writing a type the gateway cannot
23
+ * serve would put bytes in a customer's bucket that nothing can ever read out
24
+ * — and **SVG is deliberately absent from both**: it is a script container, and
25
+ * the gateway refuses to serve one for that reason. A store that would accept
26
+ * it is a store that makes the refusal moot.
27
+ *
28
+ * `application/octet-stream` is the one entry that is not "the gateway can
29
+ * serve this back inline" — it is "a browser will never execute this
30
+ * inline", which is the property a fetched email attachment needs. An
31
+ * attachment's real MIME type is sender-chosen text, exactly as untrusted as
32
+ * its filename, and writing it verbatim as the stored `content-type` would
33
+ * mean a customer's own tooling that later serves their bucket over HTTP
34
+ * (a browser extension, a static file server pointed at it, anything that
35
+ * trusts the object's declared type) could be handed `text/html` or
36
+ * `image/svg+xml` from a stranger and render it as a page rather than
37
+ * download it — the exact class of attack SVG's absence above already
38
+ * guards against, reached from the other direction. So every attachment this
39
+ * product stores is written as `application/octet-stream` regardless of what
40
+ * Gmail reports the part's `mimeType` as; the real type is preserved as text
41
+ * in the channel-day note (`**Attachments**: name — type, size`), which is
42
+ * metadata, never a header a client's transport trusts.
43
+ */
44
+ const MARKDOWN_CONTENT_TYPE = "text/markdown; charset=utf-8";
45
+ const ATTACHMENT_CONTENT_TYPE = "application/octet-stream";
46
+ const LOGICAL_DELETE_CONTENT_TYPE = "application/x-context-logical-tombstone";
47
+
48
+ const WRITABLE_CONTENT_TYPES = new Set([
49
+ MARKDOWN_CONTENT_TYPE,
50
+ "image/png",
51
+ "image/jpeg",
52
+ "image/gif",
53
+ "image/webp",
54
+ "image/heic",
55
+ "image/heif",
56
+ // A cast scene's uploaded sounds, kept beside images in the asset store and
57
+ // read back only through a note that names them. Their bytes are checked to
58
+ // be the format named before they reach here (`sceneSounds.ts`).
59
+ "audio/mpeg",
60
+ "audio/wav",
61
+ "audio/ogg",
62
+ "audio/mp4",
63
+ ATTACHMENT_CONTENT_TYPE,
64
+ LOGICAL_DELETE_CONTENT_TYPE,
65
+ ]);
66
+
67
+ /**
68
+ * The content type for a write, or a throw.
69
+ *
70
+ * Absent means markdown, which is what every caller predating this meant.
71
+ * Anything not in the set is refused rather than sanitised: a sanitiser is a
72
+ * guess about a header grammar, and there is no reason to accept a type the
73
+ * gateway could not serve back.
74
+ */
75
+ function assertWritableContentType(value) {
76
+ if (value === undefined || value === null) return MARKDOWN_CONTENT_TYPE;
77
+ if (typeof value !== "string" || !WRITABLE_CONTENT_TYPES.has(value)) {
78
+ throw new Error(
79
+ "unsupported content type: a stored object must be markdown or an image type the gateway can serve",
80
+ );
81
+ }
82
+ return value;
83
+ }
84
+
85
+ module.exports = { MARKDOWN_CONTENT_TYPE, ATTACHMENT_CONTENT_TYPE, LOGICAL_DELETE_CONTENT_TYPE, WRITABLE_CONTENT_TYPES, assertWritableContentType };
@@ -0,0 +1,123 @@
1
+ /**
2
+ * What kind of file a path names, decided in one place.
3
+ *
4
+ * Context keeps two kinds of file as text it reads and writes itself: a note
5
+ * (`.md`, Markdown) and a sheet (`.csv`, a table with typed headers,
6
+ * `docs/decisions/sheets.md`). Everything else (a picture, a PDF, a sound) is
7
+ * a file: bytes Context stores and shows but never opens as text. A path's
8
+ * kind is its last extension in any case, so `Budget.CSV` is a sheet.
9
+ *
10
+ * One question is asked exactly: whether a path may carry its own visibility
11
+ * (`takesExactOverride`). The privacy engine's exact-note parser
12
+ * (`apps/mcp/src/privacy/engine.js`) matches `.md` and `.csv` as written, and
13
+ * one line it refuses makes the whole manifest unreadable, so a gate that
14
+ * writes an override must not hand it a `.CSV`.
15
+ *
16
+ * Before this list, about 150 places asked `path.endsWith(".md")` on their
17
+ * own, and every new text type had to be added to each of them by hand; the
18
+ * ones that were (`|| .csv`) already disagreed with each other. Ask here
19
+ * instead, and add a new text type with one line in `TEXT_KINDS`
20
+ * (`docs/decisions/file-kinds.md`). `scripts/check-file-kinds.mjs` fails a
21
+ * pull request that adds a hard-coded extension test anywhere else.
22
+ *
23
+ * A check that means Markdown on purpose (a form, a `.page.md`, front matter,
24
+ * a routine, live co-editing) asks `isNotePath`. A check that means "text
25
+ * Context reads and writes" (listing, search, visibility, saving) asks
26
+ * `isTextFilePath`.
27
+ *
28
+ * Dependency-free CommonJS, so the gateway, Convex, the app and Tex all read
29
+ * the same copy.
30
+ */
31
+
32
+ const NOTE = "note";
33
+ const SHEET = "sheet";
34
+ const FILE = "file";
35
+
36
+ /** The text kinds, by lowercased extension. One line adds one. */
37
+ const TEXT_KINDS = Object.freeze({
38
+ ".md": NOTE,
39
+ ".csv": SHEET,
40
+ });
41
+
42
+ /** The extensions Context reads and writes as text, in `TEXT_KINDS` order. */
43
+ const TEXT_EXTENSIONS = Object.freeze(Object.keys(TEXT_KINDS));
44
+
45
+ /**
46
+ * A path's last extension, lowercased, with its dot: `a/b.CSV` → `.csv`.
47
+ * A name with no dot after its first character has none (`""`), so a
48
+ * dot-file such as `.gitignore` is not an extension.
49
+ *
50
+ * @param {unknown} path
51
+ * @returns {string}
52
+ */
53
+ function extensionOf(path) {
54
+ return writtenExtensionOf(path).toLowerCase();
55
+ }
56
+
57
+ /** The last extension as written, with its dot: `a/b.CSV` → `.CSV`. @param {unknown} path */
58
+ function writtenExtensionOf(path) {
59
+ if (typeof path !== "string") return "";
60
+ const name = path.slice(path.lastIndexOf("/") + 1);
61
+ const dot = name.lastIndexOf(".");
62
+ return dot > 0 ? name.slice(dot) : "";
63
+ }
64
+
65
+ /**
66
+ * `note`, `sheet` or `file`. A folder path, or anything that is not a string,
67
+ * is `file`: callers decide folders by the row, never by the name.
68
+ *
69
+ * @param {unknown} path
70
+ * @returns {"note" | "sheet" | "file"}
71
+ */
72
+ function kindOf(path) {
73
+ const extension = extensionOf(path);
74
+ return Object.prototype.hasOwnProperty.call(TEXT_KINDS, extension) ? TEXT_KINDS[extension] : FILE;
75
+ }
76
+
77
+ /** A Markdown note (`.md`). @param {unknown} path */
78
+ function isNotePath(path) {
79
+ return kindOf(path) === NOTE;
80
+ }
81
+
82
+ /** A sheet (`.csv`). @param {unknown} path */
83
+ function isSheetPath(path) {
84
+ return kindOf(path) === SHEET;
85
+ }
86
+
87
+ /** Text Context reads and writes itself: a note or a sheet. @param {unknown} path */
88
+ function isTextFilePath(path) {
89
+ return kindOf(path) !== FILE;
90
+ }
91
+
92
+ /**
93
+ * A name without its text extension: `readings.csv` → `readings`,
94
+ * `Plan.MD` → `Plan`. Any other name is returned as it is, so `photo.png`
95
+ * keeps its `.png`. @param {string} name
96
+ */
97
+ function withoutTextExtension(name) {
98
+ return isTextFilePath(name) ? name.slice(0, -extensionOf(name).length) : name;
99
+ }
100
+
101
+ /**
102
+ * Text whose extension is written exactly as `TEXT_KINDS` lists it, the only
103
+ * paths the privacy parsers take an exact override for. `Budget.CSV` is a
104
+ * sheet, but it takes its folder's visibility. @param {unknown} path
105
+ */
106
+ function takesExactOverride(path) {
107
+ return Object.prototype.hasOwnProperty.call(TEXT_KINDS, writtenExtensionOf(path));
108
+ }
109
+
110
+ module.exports = {
111
+ NOTE,
112
+ SHEET,
113
+ FILE,
114
+ TEXT_KINDS,
115
+ TEXT_EXTENSIONS,
116
+ extensionOf,
117
+ kindOf,
118
+ isNotePath,
119
+ isSheetPath,
120
+ isTextFilePath,
121
+ takesExactOverride,
122
+ withoutTextExtension,
123
+ };
@@ -0,0 +1,124 @@
1
+ /**
2
+ * Every feature flag: one id per feature that is built and on production but
3
+ * not yet open to everyone (decided by the owner, 2026-11-08; the design is
4
+ * `docs/decisions/app-and-console/feature-flags.md`).
5
+ *
6
+ * Who has a flag is not here. Staff choose it in the console's Features tab
7
+ * (`apps/convex/functions/featureFlags.ts`): off, a list of people, or
8
+ * everyone. This repository is public, and who is testing what is theirs.
9
+ *
10
+ * ## Every flag expires
11
+ *
12
+ * The owner, 2026-11-08: "put expiration dates on flags, either remove the
13
+ * feature or launch it". `expires` is at most `MAX_FLAG_DAYS` after `added`,
14
+ * and once it has passed, `flagProblems` names the flag and the Convex suite
15
+ * fails (`apps/convex/__tests__/featureFlags.test.ts`) until a pull request
16
+ * launches it (deletes the flag and keeps the code) or removes the feature
17
+ * (deletes both). Moving `expires` later is allowed only within the same
18
+ * limit from `added`, so a flag cannot be kept forever by editing its date.
19
+ *
20
+ * ## Ids
21
+ *
22
+ * `area.name`, lower case words joined by hyphens (`tex.conversation-threads`).
23
+ * An id is never reused once its flag is gone: a person's list from the old
24
+ * flag must not switch on the new one.
25
+ *
26
+ * Read by the control plane, the gateway and the app, so it is CommonJS with
27
+ * its types beside it (`flags.d.cts`), as `folderJobInfo.cjs` is.
28
+ */
29
+
30
+ /** The longest a flag may live, from `added` to `expires`. */
31
+ const MAX_FLAG_DAYS = 90;
32
+ /** How soon before `expires` the console shows a flag as due. */
33
+ const FLAG_DUE_DAYS = 14;
34
+
35
+ const FLAG_ID = /^[a-z0-9]+(?:-[a-z0-9]+)*\.[a-z0-9]+(?:-[a-z0-9]+)*$/;
36
+ const DAY = /^\d{4}-\d{2}-\d{2}$/;
37
+
38
+ /**
39
+ * The flags. Add one as
40
+ *
41
+ * "tex.conversation-threads": {
42
+ * label: "Conversation threads",
43
+ * description: "Tex sorts texts into threads before it answers.",
44
+ * added: "2026-11-08",
45
+ * expires: "2026-12-08",
46
+ * },
47
+ */
48
+ const FLAGS = Object.freeze({
49
+ "mail.in-notes": {
50
+ label: "Mail in notes",
51
+ description: "Gmail is copied into the person's notes again, so new mail starts a Tex check-in at once.",
52
+ added: "2026-11-08",
53
+ expires: "2027-02-06",
54
+ },
55
+ "files.app-saves-in-objects": {
56
+ label: "App saves in objects",
57
+ description: "The app saves whole notes through the gateway into the workspace object, not through Convex.",
58
+ added: "2026-11-24",
59
+ expires: "2027-02-21",
60
+ },
61
+ "files.app-reads-in-objects": {
62
+ label: "App reads in objects",
63
+ description: "The app's previews, peeks, mail and admin note reads go through the gateway to the workspace object, not through Convex.",
64
+ added: "2026-11-29",
65
+ expires: "2027-02-26",
66
+ },
67
+ "shares.shared-with-me-in-objects": {
68
+ label: "Shared with me from objects",
69
+ description: "The app's Shared with me list follows the person's own object instead of holding a live Convex query.",
70
+ added: "2026-11-29",
71
+ expires: "2027-02-26",
72
+ },
73
+ });
74
+
75
+ const FLAG_MODES = Object.freeze(["off", "people", "everyone"]);
76
+
77
+ function isFlagId(value) {
78
+ return typeof value === "string" && Object.prototype.hasOwnProperty.call(FLAGS, value);
79
+ }
80
+
81
+ /** Milliseconds at midnight UTC of a `YYYY-MM-DD` day, or NaN. */
82
+ function dayMs(day) {
83
+ if (typeof day !== "string" || !DAY.test(day)) return NaN;
84
+ const ms = Date.parse(`${day}T00:00:00Z`);
85
+ return Number.isFinite(ms) && new Date(ms).toISOString().slice(0, 10) === day ? ms : NaN;
86
+ }
87
+
88
+ /** Whole days from `today` (a `YYYY-MM-DD`) to the flag's `expires`: 0 on the day, negative after. */
89
+ function daysLeft(flag, today) {
90
+ return Math.round((dayMs(flag.expires) - dayMs(today)) / 86_400_000);
91
+ }
92
+
93
+ /** Today in UTC as `YYYY-MM-DD`. */
94
+ function todayOf(now = Date.now()) {
95
+ return new Date(now).toISOString().slice(0, 10);
96
+ }
97
+
98
+ /**
99
+ * Everything wrong with a registry on `today`, one sentence each; empty when
100
+ * it is fine. An expired flag is one of them, on purpose.
101
+ */
102
+ function flagProblems(flags, today) {
103
+ const problems = [];
104
+ for (const [id, flag] of Object.entries(flags)) {
105
+ if (!FLAG_ID.test(id)) problems.push(`${id}: an id is area.name in lower case words joined by hyphens.`);
106
+ if (!flag || typeof flag !== "object") {
107
+ problems.push(`${id}: needs label, description, added and expires.`);
108
+ continue;
109
+ }
110
+ if (typeof flag.label !== "string" || flag.label.trim() === "") problems.push(`${id}: needs a label.`);
111
+ if (typeof flag.description !== "string" || flag.description.trim() === "") problems.push(`${id}: needs a description.`);
112
+ const added = dayMs(flag.added);
113
+ const expires = dayMs(flag.expires);
114
+ if (Number.isNaN(added)) problems.push(`${id}: added must be a YYYY-MM-DD day.`);
115
+ if (Number.isNaN(expires)) problems.push(`${id}: expires must be a YYYY-MM-DD day.`);
116
+ if (Number.isNaN(added) || Number.isNaN(expires)) continue;
117
+ if (expires <= added) problems.push(`${id}: expires must come after added.`);
118
+ if (expires - added > MAX_FLAG_DAYS * 86_400_000) problems.push(`${id}: expires is more than ${MAX_FLAG_DAYS} days after added.`);
119
+ if (daysLeft(flag, today) < 0) problems.push(`${id}: expired on ${flag.expires}. Launch it (delete the flag, keep the code) or remove the feature.`);
120
+ }
121
+ return problems;
122
+ }
123
+
124
+ module.exports = { FLAGS, FLAG_MODES, MAX_FLAG_DAYS, FLAG_DUE_DAYS, isFlagId, daysLeft, todayOf, flagProblems };
@@ -0,0 +1,21 @@
1
+ /** Types for `flags.cjs`; see that file for the rules and the reasons. */
2
+
3
+ export type FlagMode = "off" | "people" | "everyone";
4
+
5
+ export interface FlagInfo {
6
+ label: string;
7
+ description: string;
8
+ /** `YYYY-MM-DD`, the day the flag was added. */
9
+ added: string;
10
+ /** `YYYY-MM-DD`, at most `MAX_FLAG_DAYS` after `added`. */
11
+ expires: string;
12
+ }
13
+
14
+ export declare const FLAGS: Readonly<Record<string, FlagInfo>>;
15
+ export declare const FLAG_MODES: readonly FlagMode[];
16
+ export declare const MAX_FLAG_DAYS: number;
17
+ export declare const FLAG_DUE_DAYS: number;
18
+ export declare function isFlagId(value: unknown): value is string;
19
+ export declare function daysLeft(flag: Pick<FlagInfo, "expires">, today: string): number;
20
+ export declare function todayOf(now?: number): string;
21
+ export declare function flagProblems(flags: Readonly<Record<string, unknown>>, today: string): string[];