@supa-media/tex-contract 0.3.1 → 0.6.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 (48) hide show
  1. package/README.md +13 -17
  2. package/package.json +1 -1
  3. package/texContract/aboutNoteLimits.cjs +1 -1
  4. package/texContract/asks.cjs +1 -1
  5. package/texContract/capabilities.cjs +1 -1
  6. package/texContract/computerTool.cjs +1 -1
  7. package/texContract/contextGateway.cjs +1 -1
  8. package/texContract/deskEligible.cjs +1 -1
  9. package/texContract/eventWords.cjs +2 -2
  10. package/texContract/graphWires.cjs +1 -1
  11. package/texContract/guestNames.cjs +1 -1
  12. package/texContract/heard.cjs +1 -1
  13. package/texContract/judgedActions.cjs +1 -1
  14. package/texContract/labLedger.cjs +37 -0
  15. package/texContract/labLedger.d.cts +5 -0
  16. package/texContract/mailCheck.cjs +1 -1
  17. package/texContract/noteRunFacts.cjs +1 -1
  18. package/texContract/pageJobs.cjs +3 -3
  19. package/texContract/quietHoursWindow.cjs +1 -1
  20. package/texContract/reactEmoji.cjs +1 -1
  21. package/texContract/settingHabits.cjs +1 -1
  22. package/texContract/settingsNotes.cjs +1 -1
  23. package/texContract/staffData.cjs +56 -0
  24. package/texContract/staffData.d.cts +72 -0
  25. package/texContract/texClients.cjs +2 -2
  26. package/texContract/texGraph.cjs +1 -1
  27. package/texContract/texNumber.cjs +1 -1
  28. package/texContract/texSettings.cjs +1 -1
  29. package/texContract/texStateFiles.cjs +1 -1
  30. package/texContract/texStoreWire.cjs +1 -1
  31. package/texContract/threadsFold.cjs +1 -1
  32. package/texContract/toolCatalog.generated.json +5 -5
  33. package/texContract/transcription.cjs +1 -1
  34. package/texContract/uploadImages.cjs +1 -1
  35. package/texContract/v2Translate.cjs +1 -1
  36. package/texContract/yesWords.cjs +1 -1
  37. package/texShared/githubOidc.ts +3 -3
  38. package/texShared/groupRunQuestions.cjs +2 -2
  39. package/texShared/jobPartEnd.cjs +4 -4
  40. package/texShared/jobResume.cjs +3 -3
  41. package/texShared/jobSplit.cjs +2 -2
  42. package/texShared/jobStart.cjs +2 -2
  43. package/texShared/mail.cjs +7 -1
  44. package/texShared/models/creditRest.cjs +1 -1
  45. package/texShared/noteAppLink.cjs +1 -1
  46. package/texShared/pages/blocks.cjs +1 -1
  47. package/texShared/pages/draw.cjs +1 -1
  48. package/texShared/searchConfig.cjs +1 -1
package/README.md CHANGED
@@ -9,33 +9,29 @@ It is plain CommonJS with no dependencies, and it holds no secrets and no vault
9
9
 
10
10
  ## What 0.3.0 replaces
11
11
 
12
- Since 0.3.0 the contract holds everything Context took from Tex's own source, so no Context file needs `packages/tex` or `packages/lab` (the clean split, 2026-11-29). In Context, import from `packages/shared/src/texContract/` (`@context/shared/src/texContract/...`); in Tex, from `@supa-media/tex-contract/texContract/...`.
13
-
14
- | Was | Now |
15
- | --- | --- |
16
- | `packages/tex/src/texNumber.cjs` (`TEX_NUMBER`, `formatNumber`) | `texContract/texNumber.cjs`: `formatNumber`, and `readTexNumber(env.TEX_NUMBER)`; the number is each deployment's `TEX_NUMBER` setting, so this public repository holds no real line |
17
- | `packages/tex/src/aiKeys.cjs` | `texShared/models/aiKeys.cjs` (it already re-exported it) |
18
- | `packages/tex/src/texSteps.cjs` (`TEX_STEPS`, `texStepForModel`) | `texContract/texSteps.cjs`, from `texSteps.generated.json` |
19
- | `packages/tex/src/texSettings.cjs` | `texContract/texSettings.cjs`, from `texSettings.generated.json`: the rows as data (key, section, where, byText, via, appPath), without their titles and lines |
20
- | `packages/tex/src/toolRules.cjs` `TEX_STATE_FILES`, `stateFileOf` | `texContract/texStateFiles.cjs` (file and action) |
21
- | `packages/tex/src/textDecide.cjs` `REACT_EMOJI` | `texContract/reactEmoji.cjs`: name to `{ emoji }`, without when each fits |
22
- | `packages/tex/gateway/agent/capabilities.js` (the agent-first rule's list) | `texContract/capabilities.cjs`, from `capabilities.generated.json`: names, actions, app routes and can'ts, without the words Tex is told |
12
+ Since 0.3.0 the contract holds everything Context needs from Tex's source, so no Context file imports Tex's code (the clean split, 2026-11-29). In Context, import from `packages/shared/src/texContract/` (`@context/shared/src/texContract/...`); in Tex, from `@supa-media/tex-contract/texContract/...`.
23
13
 
24
14
  Since 0.3.1:
25
15
 
26
- - `texShared/searchConfig.cjs` (with its `.json` and types) is a copy of `apps/mcp/src/search/config/searchConfig.cjs`, for the Lab's search drafts.
16
+ - `texShared/searchConfig.cjs` (with its `.json` and types) is a copy of `apps/mcp/src/search/config/searchConfig.cjs`.
27
17
  - `texShared/displayText.cjs` is a copy of `packages/shared/src/displayText.cjs`.
28
18
  - `parity.test.mjs` keeps both copies equal to their sources, so a search config change in Context bumps the contract.
29
- - `texShared/githubOidc.ts` lets each OIDC door take its workflow from `Supa-Media/tex`'s main as well as Context's. It still refuses a token whose repository and workflow disagree (`githubOidc.test.mjs`).
19
+ - `texShared/githubOidc.ts` lets each OIDC door take its workflow from Tex's repository's main as well as Context's. It still refuses a token whose repository and workflow disagree (`githubOidc.test.mjs`).
30
20
 
31
- The contract carries facts, never Tex's wording: `scripts/tex-wording-check.mjs` reads `texContract/`, and Tex's titles, lines and judge questions stay in Tex.
21
+ Since 0.4.0:
32
22
 
33
- Not carried, because their readers leave Context with Tex: `toolRules.cjs`'s size limits and `rateError` (the Lab's tool stats), the judge's questions and Training (`textDecide.cjs` `decideRequest` and `recheckRequest`, whose control-plane routes nothing calls), `texConfig.cjs`, `texConfigStamp.cjs`, `texExamples.cjs` and `texTraining.generated.json` (the Lab and its tables), `packages/lab/**` (the Lab, its sandbox, bench and `tex_dev`) and the finished migrations' `packages/tex/gateway/agent/*` helpers.
23
+ - `texContract/staffData.cjs` (with its types) holds the calls Context's staff console and Settings → Feedback make of Tex's Worker, through the gateway: `STAFF_DATA_PATH` (`stats`, `spend`, `review_scores`, on the person's own control-plane sign-in, which Tex checks is staff) and `FEEDBACK_SHARING_PATH` (on the console's grant). Tex's figures and each person's sharing yes are Tex's data and leave Context's control plane.
34
24
 
35
- The snapshots are written by `node scripts/tex-contract/snapshot.mjs [--tex <Supa-Media/tex checkout>]`, and `--check` fails when they are stale. When Tex adds a model step or changes what a person can get it to do, it runs the snapshot against its checkout and a Context pull request bumps the contract. `scripts/tex-contract/parity.test.mjs` proves each copy reads as Tex's own while Tex's source is still in Context.
25
+ Since 0.5.0:
26
+
27
+ - `texContract/labLedger.cjs` (with its types) names the Lab's read-only ledger door, `tex_lab_ledger`: one op, `read`, with `owner` (`{ person }` or `{ chat }`) and that owner's own `chat` (`labLedgerChatOf`). It reaches the chats the Lab page shows the developer, their own, their group chats and the ones shared with developers, which `tex_ledger` cannot, and the gateway asks the control plane on the caller's token before it opens one.
28
+
29
+ The contract carries facts, never Tex's wording, and Tex's titles, lines and judge questions stay in Tex.
30
+
31
+ The snapshots are written by `node scripts/tex-contract/snapshot.mjs [--tex <Tex checkout>]`, and `--check` fails when they are stale. When Tex adds a model step or changes what a person can get it to do, it runs the snapshot against its checkout and a Context pull request bumps the contract.
36
32
 
37
33
  ## How each side reads it
38
34
 
39
- Context's gateway imports the same files from its own source (`packages/shared/src/`). Tex pins a version of this package. A contract change keeps working with the previous release, and Tex bumps the version when it is ready. See `docs/decisions/texting-assistant/tex-service.md` in the Context repository.
35
+ Context's gateway imports the same files from its own source (`packages/shared/src/`). Tex pins a version of this package. A contract change keeps working with the previous release, and Tex bumps the version when it is ready.
40
36
 
41
37
  MIT licensed.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@supa-media/tex-contract",
3
- "version": "0.3.1",
3
+ "version": "0.6.0",
4
4
  "description": "The contract Context's gateway and Tex both keep: tool names, the MCP catalog snapshot, wire formats and the shared readings Tex takes with it",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * The person's about note's names and hard size, which Tex reads and keeps
3
- * (`packages/tex/gateway/agent/aboutMe.js`) and every write to the note is
3
+ * (in Tex's repository) and every write to the note is
4
4
  * held to (`apps/mcp/src/tools/notes/write.js`, which `remember` also goes
5
5
  * through).
6
6
  */
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Held asks, as both sides name them: the gateway keeps them (`apps/mcp/src/tools/approvals.js`) and settles them
3
3
  * (`apps/mcp/src/tools/texAsks.js`); Tex reads and answers them only through the `tex_asks` action
4
- * (`packages/tex/gateway/asks.js`).
4
+ * (in Tex's repository).
5
5
  */
6
6
 
7
7
  /** The Context-side action Tex settles, arms and disarms its held asks with. Never advertised, never a model's. */
@@ -5,7 +5,7 @@
5
5
  * Each capability names the actions and app routes it covers, and what Tex can't do yet with the way around it (an
6
6
  * agent prompt, an app path, a vault entry, a link, or words). Context's CI checks every action and app route against
7
7
  * this list, so a feature added to Context without a line here fails there. The words Tex is told about each
8
- * capability are Tex's own (`packages/tex/gateway/agent/capabilities.js` in Supa-Media/tex) and are not in the
8
+ * capability are Tex's own (Tex's copy in Supa-Media/tex) and are not in the
9
9
  * contract.
10
10
  *
11
11
  * Data only, written by `scripts/tex-contract/snapshot.mjs` into `capabilities.generated.json`.
@@ -3,7 +3,7 @@
3
3
  * (docs/decisions/texting-assistant/machines.md, computer-setup.md).
4
4
  *
5
5
  * The work is the gateway's (`apps/mcp/src/machines/texActions.js`, `forJobs.js`, `forTurn.js`, `groupAsk.js`),
6
- * reached by Tex over MCP like any tool (`packages/tex/gateway/agent/machineDoor.js`):
6
+ * reached by Tex over MCP like any tool (in Tex's repository):
7
7
  *
8
8
  * - `tex_computers`: the tool the model calls, `send` action `computers`;
9
9
  * - `tex_machines`: the computers a chat turn may name (`list`), how a job picks one (`pick`), and the turn's
@@ -6,7 +6,7 @@
6
6
  * in-process: an MCP `tools/call` as one person, a call of an action only Tex's own code makes, marking a turn's egress ledger for a read, the privacy engine's
7
7
  * answers about a key, the egress judge, the control-plane client, and a session's tool list (and the plugin switches it
8
8
  * reads) when Tex runs in-process, without the `CONTEXT_MCP` binding. The gateway connects them here once, when its dispatcher loads
9
- * (`apps/mcp/src/tools/session.js`), and Tex reaches them only through `packages/tex/gateway/contextMcp.js`, so Tex's
9
+ * (`apps/mcp/src/tools/session.js`), and Tex reaches them only through Tex's code, so Tex's
10
10
  * code imports no gateway module and each of these is one named seam to swap for MCP when it moves.
11
11
  *
12
12
  * Nothing here decides anything: each function is the gateway's own, unchanged, so every gate and privacy rule still
@@ -4,7 +4,7 @@
4
4
  * the private tier.
5
5
  *
6
6
  * Tex reads its desk's notes by key only on such a connection
7
- * (`packages/tex/gateway/agent/texDesk.js`, which re-exports this), and
7
+ * (Tex's code, which re-exports this), and
8
8
  * Context reads the person's history file straight from their ledger on it
9
9
  * (`apps/mcp/src/tools/notes/historyRead.js`): that connection sees every
10
10
  * note there, so neither shows anything `read_note` would not. One rule, so
@@ -1,5 +1,5 @@
1
1
  /**
2
- * One chat event's words as a line, as every reader of a chat shows them: Tex's (`packages/tex/gateway/agent/logRender.js`
2
+ * One chat event's words as a line, as every reader of a chat shows them: Tex's (in Tex's repository
3
3
  * `words`) and Context's door, which reads a chat's ledger for a turn's history (`turnWords.cjs` `chatTurnsIn`). Pure.
4
4
  */
5
5
 
@@ -26,7 +26,7 @@ function eventLine(event, text) {
26
26
  case "delivery":
27
27
  return text ? `(delivery) ${text}` : "(delivery)";
28
28
  default:
29
- // A person's edit of an earlier text (`packages/tex/worker/editStep.ts`): its new words, marked by the Worker's field, never by them.
29
+ // A person's edit of an earlier text (in Tex's repository): its new words, marked by the Worker's field, never by them.
30
30
  if (event.unsent === true) return "(unsent an earlier text)";
31
31
  return event.edited === true ? `(edited an earlier text to) ${text}` : text;
32
32
  }
@@ -1,5 +1,5 @@
1
1
  /**
2
- * What a wire between two steps may be, for the schema (`packages/tex/src/texConfigSchema.cjs`, which checks a config
2
+ * What a wire between two steps may be, for the schema (Tex's code, which checks a config
3
3
  * against it) and the runner (`texGraph.cjs`, which runs Tex's graph and the gateway's search graph).
4
4
  */
5
5
 
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * A group chat's roster of names for its guests and members, as kept in the chat's own ledger (Dev2, 2026-11-12;
3
- * `packages/tex/gateway/agent/groupGuestNames.js` says why and keeps them from a text): `name` entries
3
+ * Tex's code says why and keeps them from a text): `name` entries
4
4
  * `{guest|member, name, by?}` and `numbers` entries `{guests: [{guest, phone}]}`. The entries, how they fold into names,
5
5
  * and their reads through the chat's ledger handle (`ledger.read`) live here, with no imports but the name cleaner, so
6
6
  * the Tex page's contacts (`apps/mcp/src/http/texPage/contacts.js`) reads and writes them as Tex does.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * What the transcription service heard, read the same way by Tex's turn (`packages/tex/gateway/agent/attachments.js`)
2
+ * What the transcription service heard, read the same way by Tex's turn (in Tex's repository)
3
3
  * and by Context's hearing door for a group's voice message (`apps/mcp/src/http/textsHear.js`), so the two never drift.
4
4
  */
5
5
 
@@ -2,7 +2,7 @@
2
2
  * THE ACTIONS THE SHARING JUDGE IS ASKED ABOUT FOR A CHANGE THE CONTROL PLANE MAKES, NAMED ONCE FOR BOTH SIDES
3
3
  * (`docs/decisions/texting-assistant/tex-service.md`, "The main texted turn in Tex's Worker").
4
4
  *
5
- * Tex's vault tool (`packages/tex/gateway/agent/settingsTools.js`) asks the judge before it shares a login, and
5
+ * Tex's vault tool (in Tex's repository) asks the judge before it shares a login, and
6
6
  * Context judges the same action again inside `tex_control`'s `vaultText` (`apps/mcp/src/tools/texControl.js`), so a
7
7
  * share is judged on the person's kept words whoever sends it. One copy, so the two never ask about different things.
8
8
  */
@@ -0,0 +1,37 @@
1
+ /**
2
+ * The Lab's read-only ledger door (`apps/mcp/src/tools/texLabLedger.js`): how `tex_dev` in Tex's Worker reads a
3
+ * chat's history the Lab page shows its developer, the chats shared with developers and their group chats included,
4
+ * which `tex_ledger` (the session's own store only) cannot reach.
5
+ *
6
+ * One action, `tex_lab_ledger`, one op, `read`: `{ op: "read", owner, chat, options }`. `owner` is `{ person }` (a
7
+ * personal workspace's id, for that person's 1:1) or `{ chat }` (a group chat's 64-hex key); `chat` is the ledger's
8
+ * name for it (`labLedgerChatOf`). The answer is `{ value }`, what the ledger's `read` answered.
9
+ */
10
+
11
+ "use strict";
12
+
13
+ const { ONE_TO_ONE_CHAT } = require("./texStoreNames.cjs");
14
+
15
+ const TEX_LAB_LEDGER_ACTION = "tex_lab_ledger";
16
+ const LAB_LEDGER_OPS = Object.freeze(["read"]);
17
+ const OWNER_ID = /^[A-Za-z0-9_-]{1,64}$/;
18
+ const GROUP_KEY = /^[0-9a-f]{64}$/;
19
+
20
+ /** `{ person }` or `{ chat }`, exactly one, each a bounded id (a chat's a group key); null for anything else. */
21
+ function labLedgerOwner(value) {
22
+ if (value === null || typeof value !== "object" || Array.isArray(value)) return null;
23
+ const keys = Object.keys(value);
24
+ if (keys.length !== 1) return null;
25
+ const id = value[keys[0]];
26
+ if (typeof id !== "string") return null;
27
+ if (keys[0] === "person" && OWNER_ID.test(id)) return { person: id };
28
+ if (keys[0] === "chat" && GROUP_KEY.test(id)) return { chat: id };
29
+ return null;
30
+ }
31
+
32
+ /** The ledger's name for an owner's chat: the person's 1:1, or the group's key. */
33
+ function labLedgerChatOf(owner) {
34
+ return owner?.person ? ONE_TO_ONE_CHAT : owner?.chat ?? null;
35
+ }
36
+
37
+ module.exports = { TEX_LAB_LEDGER_ACTION, LAB_LEDGER_OPS, labLedgerOwner, labLedgerChatOf };
@@ -0,0 +1,5 @@
1
+ export declare const TEX_LAB_LEDGER_ACTION: "tex_lab_ledger";
2
+ export declare const LAB_LEDGER_OPS: readonly ["read"];
3
+ export type LabLedgerOwner = { person: string } | { chat: string };
4
+ export declare function labLedgerOwner(value: unknown): LabLedgerOwner | null;
5
+ export declare function labLedgerChatOf(owner: LabLedgerOwner | null | undefined): string | null;
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * What the Mail checker is shown and how its answer is read (decided by the owner, 2026-10-17;
3
- * `apps/mcp/src/tools/emailGate.js`): the same for the in-process turn (`packages/tex/gateway/agent/mailChecker.js`,
3
+ * `apps/mcp/src/tools/emailGate.js`): the same for the in-process turn (Tex's code,
4
4
  * which adds Tex's architecture and Training to the prompt) and for a turn over Tex's MCP door, whose checker is
5
5
  * Context's own (`apps/mcp/src/tools/doorMailChecker.js`), on the chat's turns Context read from its own ledger.
6
6
  * Pure: no model call here.
@@ -3,7 +3,7 @@
3
3
  * (`docs/decisions/texting-assistant/tex-service.md`, "Tex in a note and in mail").
4
4
  *
5
5
  * Context's routes (`apps/mcp/src/http/noteRunDoor.js`, `mailRunDoor.js`) check who asks and read the note as the
6
- * person, then hand Tex's Worker the facts; the Lab's run (`packages/tex/gateway/agent/noteRunLab.js`) checks them the
6
+ * person, then hand Tex's Worker the facts; the Lab's run (in Tex's repository) checks them the
7
7
  * same way in-process. Pure: a body's shape, the workspace a session reaches, a `read_note` answer read as a note, and
8
8
  * the key a note's run log is kept under.
9
9
  */
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * A chat's background jobs, for its Tex page: read from the chat's inbox in
3
3
  * the texting Worker over the `TEXTING` binding (`TexRoutines.pageJobs`,
4
- * `packages/tex/worker/texPage.ts`), and shaped as the page shows them. Used by the
4
+ * Tex's code), and shaped as the page shows them. Used by the
5
5
  * page's routes and by the chat's Tex object while a page is open
6
6
  * (`texStore/pageLive.js`), so both say the same thing.
7
7
  *
@@ -9,7 +9,7 @@
9
9
  * target, never a note's text).
10
10
  */
11
11
 
12
- /** How many jobs run at once (`MAX_RUNNING_JOBS`, `packages/tex/worker/jobs.ts`): the page's minion slots. */
12
+ /** How many jobs run at once (`MAX_RUNNING_JOBS`, Tex's code): the page's minion slots. */
13
13
  const SLOTS = 3;
14
14
  /** The finished jobs the overview shows under "Earlier today". */
15
15
  const EARLIER_SHOWN = 2;
@@ -106,7 +106,7 @@ const MACHINE_SLOTS = 8;
106
106
  /**
107
107
  * Which slot each live job holds, numbered from 1 in the place it runs: Tex's
108
108
  * cloud's three, or each computer's own (a job on a computer never takes a
109
- * cloud slot: `packages/tex/worker/jobs.ts`), numbered oldest first, as they were
109
+ * cloud slot: Tex's code), numbered oldest first, as they were
110
110
  * started. When a place has more live jobs than slots, running ones get them
111
111
  * before ones waiting on the person: Tex counts only running jobs against its
112
112
  * limit (`fits`), so a waiting one must never hide a job that is running.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * A `quiet-hours:` value read as a window (`packages/tex/gateway/agent/quietHours.js` says what quiet hours hold), with
2
+ * A `quiet-hours:` value read as a window (Tex's code says what quiet hours hold), with
3
3
  * no imports: Tex's check-ins and its settings by text, and the Tex page's settings (`settingHabits.cjs`), read the
4
4
  * same words.
5
5
  */
@@ -2,7 +2,7 @@
2
2
  * The 64 emoji Tex may react with, by the short name its judge picks (Dev2, 2026-10-27: a curated set, since one typed
3
3
  * question offers at most 64 options). Never ✅ and never a gendered person. Context's control plane keeps them as an
4
4
  * allowlist (`apps/convex/functions/lib/reactEmoji.ts`); Tex's own copy, with when each fits, is
5
- * `packages/tex/src/textDecide.cjs` in Supa-Media/tex, and a test on each side pins the list.
5
+ * Tex's copy in Supa-Media/tex, and a test on each side pins the list.
6
6
  */
7
7
  "use strict";
8
8
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * The `setting` switches Tex changes by text (`packages/tex/gateway/agent/settingsTools.js`; Dev2, 2026-11-12,
2
+ * The `setting` switches Tex changes by text (Tex's code; Dev2, 2026-11-12,
3
3
  * `docs/decisions/texting-assistant/settings-by-text.md`), read and set through one door, `call(name, args)`, an MCP
4
4
  * tool call as the person. Tex's `tex_setting_set` and the Tex page's Settings (`apps/mcp/src/http/texPage/serve.js`)
5
5
  * both use these setters, so a value the chat would refuse is refused on the page too, and both read the same notes.
@@ -2,7 +2,7 @@
2
2
  * Tex's own settings notes in a person's `tex/` folder (`tex/heartbeat.md`, `tex/housekeeping.md`, `tex/dreams.md`,
3
3
  * `tex/attention.md`, ...), read and changed through one door: `call(name, args)`, an MCP tool call
4
4
  * (`read_note`, `write_note`, `archive_note`) as the person. Shared by the Tex page (`apps/mcp/src/http/texPage/notes.js`)
5
- * and Tex's settings changed by text (`packages/tex/gateway/agent/settingsTools.js`), so both read and write alike.
5
+ * and Tex's settings changed by text (in Tex's repository), so both read and write alike.
6
6
  * Note text is never returned in an error: an error is one fixed word.
7
7
  */
8
8
 
@@ -0,0 +1,56 @@
1
+ /**
2
+ * TEX'S STAFF FIGURES AND THE FEEDBACK SWITCH, ASKED OF TEX'S OWN WORKER (the Tex/Context split, 2026-11-30).
3
+ *
4
+ * Tex's figures (texts in and out, people and chats, notes made, spend, conversation scores) and each person's yes to
5
+ * sharing their finished conversations with the team used to be answered by Context's control plane. They are Tex's
6
+ * data, so Tex's Worker answers them, and Context's staff console and Settings → Feedback ask it through the gateway,
7
+ * which hands each call to Tex over its `TEXTING` binding:
8
+ *
9
+ * - `POST STAFF_DATA_PATH` `{ op, ...args }`, the bearer the person's own control-plane sign-in token (the console's
10
+ * session token). The gateway passes the token on untouched and decides nothing; Tex's Worker asks the control
11
+ * plane whether that sign-in is staff (`functions/admin:amIAdmin`, a public query, answered for its caller alone)
12
+ * and answers only when it is. Ops: `stats` `{ from?, to? }`, `spend` `{ days? }`, `review_scores` `{ days? }`.
13
+ * - `POST FEEDBACK_SHARING_PATH` `{ share? }` on the console's own grant (`context_console`, a personal workspace's
14
+ * owner). The gateway hands Tex the grant's person and nothing from the body but `share`; absent only asks.
15
+ *
16
+ * Answers are `{ status: "ok", data }`, `{ status: "refused" }` (not staff, or not the console's own grant) or
17
+ * `{ status: "unavailable" }` (Tex's Worker unreachable). Facts and numbers only, never a person, a chat or a word.
18
+ */
19
+
20
+ const STAFF_DATA_PATH = "/tex/staff-data";
21
+ const FEEDBACK_SHARING_PATH = "/tex/feedback-sharing";
22
+ const STAFF_DATA_OPS = Object.freeze(["stats", "spend", "review_scores"]);
23
+ /** The longest bearer passed on; a control-plane sign-in token is far shorter. */
24
+ const MAX_TOKEN_CHARS = 4096;
25
+
26
+ const finiteOrUndefined = (value) => (typeof value === "number" && Number.isFinite(value) ? value : undefined);
27
+
28
+ /** A staff call read strictly: `{ op, from?, to?, days? }` with only the fields its op takes, or null. */
29
+ function staffDataRequest(body) {
30
+ if (body === null || typeof body !== "object" || Array.isArray(body)) return null;
31
+ const op = body.op;
32
+ if (!STAFF_DATA_OPS.includes(op)) return null;
33
+ if (op === "stats") {
34
+ const from = finiteOrUndefined(body.from);
35
+ const to = finiteOrUndefined(body.to);
36
+ return { op, ...(from === undefined ? {} : { from }), ...(to === undefined ? {} : { to }) };
37
+ }
38
+ const days = finiteOrUndefined(body.days);
39
+ return { op, ...(days === undefined ? {} : { days }) };
40
+ }
41
+
42
+ /** The Feedback switch's call: `{ share? }`, or null for anything else. */
43
+ function sharingRequest(body) {
44
+ if (body === null || typeof body !== "object" || Array.isArray(body)) return null;
45
+ if (body.share === undefined) return {};
46
+ return typeof body.share === "boolean" ? { share: body.share } : null;
47
+ }
48
+
49
+ /** The bearer of an `Authorization` header, when it is one plausible token; otherwise null. */
50
+ function bearerOf(header) {
51
+ if (typeof header !== "string") return null;
52
+ const match = /^Bearer ([A-Za-z0-9._~+/=-]+)$/.exec(header.trim());
53
+ return match !== null && match[1].length <= MAX_TOKEN_CHARS ? match[1] : null;
54
+ }
55
+
56
+ module.exports = { STAFF_DATA_PATH, FEEDBACK_SHARING_PATH, STAFF_DATA_OPS, MAX_TOKEN_CHARS, staffDataRequest, sharingRequest, bearerOf };
@@ -0,0 +1,72 @@
1
+ /** Types for `staffData.cjs`; see that file for the reasons. The answer shapes are Tex's Worker's (`worker/stats`). */
2
+
3
+ export declare const STAFF_DATA_PATH: "/tex/staff-data";
4
+ export declare const FEEDBACK_SHARING_PATH: "/tex/feedback-sharing";
5
+ export declare const STAFF_DATA_OPS: readonly ["stats", "spend", "review_scores"];
6
+ export declare const MAX_TOKEN_CHARS: number;
7
+
8
+ export type StaffDataOp = (typeof STAFF_DATA_OPS)[number];
9
+ export type StaffDataRequest = { op: "stats"; from?: number; to?: number } | { op: "spend"; days?: number } | { op: "review_scores"; days?: number };
10
+ export declare function staffDataRequest(body: unknown): StaffDataRequest | null;
11
+ export declare function sharingRequest(body: unknown): { share?: boolean } | null;
12
+ export declare function bearerOf(header: unknown): string | null;
13
+
14
+ export type TexDataAnswer<T> = { status: "ok"; data: T } | { status: "refused" } | { status: "unavailable" };
15
+
16
+ export type TexStatsPoint = { at: number; people: number; textsIn: number; textsOut: number; usd: number; notesCreated: number; notesEdited: number };
17
+
18
+ /** `op: "stats"`: the staff console's basics for a window. */
19
+ export type TexStats =
20
+ | { configured: false }
21
+ | {
22
+ configured: true;
23
+ from: number;
24
+ to: number;
25
+ bucket: "hour" | "day";
26
+ errors: { texts: string | null; notes: string | null; cost: string | null };
27
+ people: { one: number; group: number; any: number };
28
+ dailyActive: number;
29
+ texts: { inOne: number; inGroup: number; heardGroup: number; outOne: number; outGroup: number };
30
+ chats?: { one: number; group: number; groupAsked: number; groupHeardOnly: number; any: number; countedSince: number };
31
+ notes: { created: number; edited: number; saves: number };
32
+ cost: { totalUsd: number; testsUsd: number };
33
+ costPerTextUsd: number | null;
34
+ countedSince: number;
35
+ series: TexStatsPoint[];
36
+ };
37
+
38
+ /** `op: "spend"`: Tex's spend by day, model and job, as Cloudflare's AI gateway priced it. */
39
+ export type TexSpend =
40
+ | { configured: false }
41
+ | {
42
+ configured: true;
43
+ error: string | null;
44
+ totalUsd: number;
45
+ testsUsd: number;
46
+ keptFrom: string;
47
+ days: Array<{ day: string; usd: number; requests: number }>;
48
+ models: Array<{ model: string; requests: number; usd: number; freshInputTokens: number; cacheReadTokens: number; cacheWriteTokens: number; outputTokens: number }>;
49
+ jobs: Array<{ job: string; usd: number; requests: number }>;
50
+ };
51
+
52
+ /** One finished conversation's scores (`op: "review_scores"`), naming nobody. */
53
+ export type TexReviewScore = {
54
+ at: number;
55
+ kind: "one" | "group";
56
+ reason: string;
57
+ goal: number;
58
+ independence: number;
59
+ turns: number;
60
+ friendly: number;
61
+ calm: number;
62
+ task: string | null;
63
+ signals: string[];
64
+ texts: number | null;
65
+ who: "staff" | "new" | "other" | null;
66
+ costMicroUsd: number | null;
67
+ thought: boolean | null;
68
+ };
69
+ export type TexReviewScores = { truncated: boolean; reviews: TexReviewScore[] };
70
+
71
+ /** The Feedback switch's answer: whether the person shares, and whether this call changed it. */
72
+ export type FeedbackSharing = { sharing: boolean; changed: boolean };
@@ -26,12 +26,12 @@ const ROUTINES_CLIENT_ID = "context_routines";
26
26
 
27
27
  /**
28
28
  * Tex's own clients: the only connections that may speak in note mail under a roster name (`tex`, `advisor`), joined
29
- * or not (#4543). A client's registered name is text it asserted and never one of these; an AI client that called
29
+ * or not. A client's registered name is text it asserted and never one of these; an AI client that called
30
30
  * itself "Tex" signed as the person's Tex and held their Tex's seat on the note.
31
31
  */
32
32
  const TEX_OWN_CLIENT_IDS = Object.freeze([TEXTS_CLIENT_ID, TEXTS_GROUP_CLIENT_ID, DREAMS_CLIENT_ID, HEARTBEAT_CLIENT_ID, HOUSEKEEPING_CLIENT_ID, ROUTINES_CLIENT_ID]);
33
33
 
34
- /** The names on every job note besides its jobs (`packages/tex/gateway/agent/jobNote.js`): Tex and the advisor. */
34
+ /** The names on every job note besides its jobs (in Tex's repository): Tex and the advisor. */
35
35
  const MAIL_ROSTER_NAMES = Object.freeze(["tex", "advisor"]);
36
36
 
37
37
  /** Whether a grant's client is one of Tex's own, by the id the control plane issued. */
@@ -56,7 +56,7 @@
56
56
  "use strict";
57
57
 
58
58
  // The wire modes and a provisional run's allows (reads only, or reads and writes that can be undone, the default) are
59
- // the schema's (`packages/tex/src/texConfigSchema.cjs`), shared from `graphWires.cjs`.
59
+ // the schema's (in Tex's repository), shared from `graphWires.cjs`.
60
60
  const { MODES, ALLOW, START_FACTS } = require("./graphWires.cjs");
61
61
  const MAX_LOG_CHARS = 3_500;
62
62
 
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Tex's number: the one line people are told to text. It is configuration, not code: each deployment reads it from its
3
3
  * own `TEX_NUMBER` setting (an E.164 number), so this public repository carries no real line and moving Tex to a new
4
- * line changes no source. Tex's own copy is `packages/tex/src/texNumber.cjs` in Supa-Media/tex.
4
+ * line changes no source. Tex keeps its own copy in Supa-Media/tex.
5
5
  */
6
6
  "use strict";
7
7
 
@@ -3,7 +3,7 @@
3
3
  * as data: where it applies, whether Tex changes it from a text and with which `send` action, or where in the app it
4
4
  * changes. The app's settings page has a switch for each `setting` row. The rows are `texSettings.generated.json`,
5
5
  * written by `scripts/tex-contract/snapshot.mjs`; Tex's own copy, with each row's title and line, is
6
- * `packages/tex/src/texSettings.cjs` in Supa-Media/tex.
6
+ * Tex's copy in Supa-Media/tex.
7
7
  */
8
8
  "use strict";
9
9
 
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Tex's state files in a person's workspace, and the action that writes each (rule 3 of Tex's tool rules). The control
3
3
  * plane keeps only these names on a turn's record (`apps/convex/functions/agentTurns.ts`). Data only: Tex's own copy,
4
- * with what each holds, is `packages/tex/src/toolRules.cjs` in Supa-Media/tex.
4
+ * with what each holds, is Tex's copy in Supa-Media/tex.
5
5
  */
6
6
  "use strict";
7
7
 
@@ -4,7 +4,7 @@
4
4
  * and a body's bytes as the body, so a note is never base64'd or JSON-escaped on the way.
5
5
  *
6
6
  * The objects and their answering side (`serveTexStore`) are Context's (`apps/mcp/src/texStore/wire.js`, which
7
- * re-exports this file). Tex's code keeps one client of them, `packages/tex/gateway/texStoreClient.js`. Pure, with no
7
+ * re-exports this file). Tex's code keeps one client of them. Pure, with no
8
8
  * imports: the stub maker and the store over a bucket take the two gateway pieces they need (`objectByName`, `R2Store`)
9
9
  * as arguments.
10
10
  */
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * A chat's conversation threads folded from its threads ledger, with no imports: the classifier
3
- * (`packages/tex/gateway/agent/conversationThreads.js`), the conversations view (`apps/mcp/src/texStore/historyView.js`)
3
+ * (in Tex's repository), the conversations view (`apps/mcp/src/texStore/historyView.js`)
4
4
  * and the Tex page's conversations (`apps/mcp/src/http/texPage/conversations.js`) all read threads this way, and the
5
5
  * view is bundled by Workers (the email Worker among them) that must not pull in the classifier's model calls.
6
6
  */