@supa-media/tex-contract 0.4.0 → 0.9.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.
- package/README.md +16 -0
- package/package.json +1 -1
- package/texContract/aboutNoteLimits.cjs +1 -1
- package/texContract/asks.cjs +1 -1
- package/texContract/capabilities.cjs +1 -1
- package/texContract/computerTool.cjs +1 -1
- package/texContract/contextGateway.cjs +1 -1
- package/texContract/deskEligible.cjs +1 -1
- package/texContract/doorBatch.cjs +27 -0
- package/texContract/doorBatch.d.cts +6 -0
- package/texContract/eventWords.cjs +2 -2
- package/texContract/graphWires.cjs +1 -1
- package/texContract/guestNames.cjs +1 -1
- package/texContract/heard.cjs +1 -1
- package/texContract/identity.cjs +2 -1
- package/texContract/judgedActions.cjs +1 -1
- package/texContract/labLedger.cjs +37 -0
- package/texContract/labLedger.d.cts +5 -0
- package/texContract/mailCheck.cjs +1 -1
- package/texContract/membersSeal.cjs +202 -0
- package/texContract/membersSeal.d.cts +13 -0
- package/texContract/noteRunFacts.cjs +1 -1
- package/texContract/pageJobs.cjs +3 -3
- package/texContract/quietHoursWindow.cjs +1 -1
- package/texContract/reactEmoji.cjs +1 -1
- package/texContract/settingHabits.cjs +1 -1
- package/texContract/settingsNotes.cjs +1 -1
- package/texContract/shownEmail.cjs +1 -1
- package/texContract/texClients.cjs +2 -2
- package/texContract/texGraph.cjs +1 -1
- package/texContract/texNumber.cjs +1 -1
- package/texContract/texSettings.cjs +1 -1
- package/texContract/texStateFiles.cjs +1 -1
- package/texContract/texStoreWire.cjs +1 -1
- package/texContract/threadsFold.cjs +1 -1
- package/texContract/toolCatalog.generated.json +5 -5
- package/texContract/transcription.cjs +1 -1
- package/texContract/uploadImages.cjs +1 -1
- package/texContract/v2Translate.cjs +1 -1
- package/texContract/yesWords.cjs +1 -1
- package/texShared/githubOidc.ts +3 -3
- package/texShared/groupRunQuestions.cjs +2 -2
- package/texShared/jobPartEnd.cjs +4 -4
- package/texShared/jobResume.cjs +3 -3
- package/texShared/jobSplit.cjs +2 -2
- package/texShared/jobStart.cjs +2 -2
- package/texShared/mail.cjs +7 -1
- package/texShared/models/creditRest.cjs +1 -1
- package/texShared/models/promptBudget.cjs +132 -11
- package/texShared/noteAppLink.cjs +1 -1
- package/texShared/pages/blocks.cjs +1 -1
- package/texShared/pages/draw.cjs +1 -1
- package/texShared/searchConfig.cjs +1 -1
package/README.md
CHANGED
|
@@ -22,6 +22,22 @@ Since 0.4.0:
|
|
|
22
22
|
|
|
23
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.
|
|
24
24
|
|
|
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
|
+
Since 0.7.0:
|
|
30
|
+
|
|
31
|
+
- `texShared/models/promptBudget.cjs` keeps a reserved share for the newest history (`HISTORY_RESERVE`) so a system prompt over the cut no longer drops every earlier turn.
|
|
32
|
+
|
|
33
|
+
Since 0.8.0:
|
|
34
|
+
|
|
35
|
+
- `texContract/membersSeal.cjs` (with its types) reads a group chat's members log from its ledger's `members` steps (`membersSnapshot`) and seals what readers outside a turn see (`roomSealOf`, `sealedAnswer`, `sealedThreadIds`). It leaves out anything said while someone in the chat now was away, unless a member released it to them, and strips the plain hashes `from.who` and `people`.
|
|
36
|
+
|
|
37
|
+
Since 0.9.0:
|
|
38
|
+
|
|
39
|
+
- `texContract/doorBatch.cjs` (with its types) names the door's batch: `BATCH_PATH` (`/tex-mcp/batch`), `BATCH_METHOD`, `MAX_BATCH_CALLS` (16) and `NOT_BATCHED`. Several calls of one turn go in one request, so the door resolves the token, opens the storage binding and opens and saves the turn once for all of them. Each entry answers `{ result }` or `{ error: { status, code } }`; a call to an outside service answers `not_batched` and goes alone, and a gateway without the path answers 404.
|
|
40
|
+
|
|
25
41
|
The contract carries facts, never Tex's wording, and Tex's titles, lines and judge questions stay in Tex.
|
|
26
42
|
|
|
27
43
|
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.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@supa-media/tex-contract",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.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
|
-
* (
|
|
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
|
*/
|
package/texContract/asks.cjs
CHANGED
|
@@ -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
|
-
* (
|
|
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 (
|
|
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 (
|
|
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
|
|
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
|
-
* (
|
|
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
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Several calls to Context's door in one request (`apps/mcp/src/http/texMcpBatch.js`): how Tex's Worker sends the calls
|
|
3
|
+
* one turn makes together, so the door resolves the token, opens the storage binding and opens and saves the turn once
|
|
4
|
+
* for all of them instead of once each.
|
|
5
|
+
*
|
|
6
|
+
* `POST BATCH_PATH` on the `TexMcp` binding, the person's own grant token in `Authorization: Bearer`, body
|
|
7
|
+
* `{ jsonrpc: "2.0", id, method: BATCH_METHOD, params: { calls, _meta } }`:
|
|
8
|
+
*
|
|
9
|
+
* - `calls`: 1 to `MAX_BATCH_CALLS` entries, each `{ kind: "call", name, arguments, legacy? }` (a tool, as
|
|
10
|
+
* `/tex-mcp/call`), `{ kind: "action", name, arguments }` (a Tex action, as `/tex-mcp/action`) or
|
|
11
|
+
* `{ kind: "list", shape? }` (`tools/list`).
|
|
12
|
+
* - `_meta`: the batch's one turn meta (`turn`, `ownRun`, `mailTurn`, `search`), as a single call carries it.
|
|
13
|
+
*
|
|
14
|
+
* The answer is `{ result: { answers } }`, one per entry in order: `{ result }`, or `{ error: { status, code } }` with
|
|
15
|
+
* the status and code that entry's single request would have been refused with. `not_batched` (400) means send that
|
|
16
|
+
* call alone (a call to an outside service). A refusal of the whole request (no token, no read scope, a bad body) is
|
|
17
|
+
* an HTTP status as on the single paths; a gateway without this path answers 404, and the caller sends each call alone.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
"use strict";
|
|
21
|
+
|
|
22
|
+
const BATCH_PATH = "/tex-mcp/batch";
|
|
23
|
+
const BATCH_METHOD = "tools/batch";
|
|
24
|
+
const MAX_BATCH_CALLS = 16;
|
|
25
|
+
const NOT_BATCHED = "not_batched";
|
|
26
|
+
|
|
27
|
+
module.exports = { BATCH_PATH, BATCH_METHOD, MAX_BATCH_CALLS, NOT_BATCHED };
|
|
@@ -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 (
|
|
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 (
|
|
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 (
|
|
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
|
-
*
|
|
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.
|
package/texContract/heard.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* What the transcription service heard, read the same way by Tex's turn (
|
|
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
|
|
package/texContract/identity.cjs
CHANGED
|
@@ -166,7 +166,8 @@ function contextsFor(session) {
|
|
|
166
166
|
current: entry.workspaceId === session.workspaceId,
|
|
167
167
|
canWrite: reach.canWrite,
|
|
168
168
|
grantWrites: reach.grantWrites,
|
|
169
|
-
tier
|
|
169
|
+
// A group asker's own personal workspace reads at the grant's tier and opens none of its notes to the chat (P-8).
|
|
170
|
+
tier: reach.tier,
|
|
170
171
|
...(entry.askerOwn === true ? { askerOwn: true } : {}),
|
|
171
172
|
};
|
|
172
173
|
});
|
|
@@ -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 (
|
|
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 (
|
|
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.
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WHAT A GROUP CHAT'S PEOPLE MAY READ OF ITS HISTORY OUTSIDE A TURN: nothing said while someone in the chat now was
|
|
3
|
+
* away from it, unless a member who was there released it to them, and never a plain hash of anyone's number.
|
|
4
|
+
*
|
|
5
|
+
* The chat's members log is kept by Tex's texting Worker in the chat's own object, as keyed ids and times only, and
|
|
6
|
+
* mirrored into the chat's ledger as `members` steps: one snapshot `{snap, part, of, started, members: {w: spans},
|
|
7
|
+
* releases}` split into parts. A turn reads the chat under its own seal; every other reader of a group chat's ledger
|
|
8
|
+
* (its history and conversations files, the Tex page, a person's Download as folders, the Lab) reads it through
|
|
9
|
+
* this one, with no asker: a text is shown only when everyone here now was here when it was said, or was released
|
|
10
|
+
* it. Decided by the owner's security review, 2026-11-30.
|
|
11
|
+
*
|
|
12
|
+
* - A chat whose ledger holds no `members` step has no log, and reads as before.
|
|
13
|
+
* - A `members` step that can't be read as a whole snapshot, or a snapshot read that fails, seals everything but the
|
|
14
|
+
* log's own steps (fail closed).
|
|
15
|
+
* - A day summary is sealed when any sealed time falls within a day either side of its day; a thread when any of its
|
|
16
|
+
* texts, or its start, is sealed, and then every one of its entries is.
|
|
17
|
+
* - Every entry kept loses `from.who` and `people`: plain hashes of numbers, never shown outside a turn.
|
|
18
|
+
*
|
|
19
|
+
* Pure, with no imports: the gateway's object (synchronously) and its Workers (over the wire) read it alike.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
const MEMBERS_STEP = "members";
|
|
23
|
+
const RELEASE_STEP = "release";
|
|
24
|
+
const MEMBER_ID = /^[0-9a-f]{32}$/;
|
|
25
|
+
const RELEASE_ID = /^r[0-9a-z]{8,32}$/;
|
|
26
|
+
const MAX_SPANS = 64;
|
|
27
|
+
const DAY_MS = 86_400_000;
|
|
28
|
+
const DAY_ID = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
29
|
+
const TIME_IN_ID = /^\D*(\d{13})/;
|
|
30
|
+
|
|
31
|
+
/** The read that finds a chat's newest snapshot: its `members` steps, newest first. */
|
|
32
|
+
const MEMBERS_SNAPSHOT_READ = Object.freeze({ kinds: ["step"], steps: [MEMBERS_STEP], before: Number.MAX_SAFE_INTEGER, limit: 200 });
|
|
33
|
+
|
|
34
|
+
const finite = (value) => typeof value === "number" && Number.isFinite(value);
|
|
35
|
+
const endOf = (value) => (value === null ? null : finite(value) ? value : undefined);
|
|
36
|
+
|
|
37
|
+
function spansOf(value) {
|
|
38
|
+
if (!Array.isArray(value) || value.length > MAX_SPANS) return null;
|
|
39
|
+
const spans = [];
|
|
40
|
+
for (const span of value) {
|
|
41
|
+
if (!Array.isArray(span) || span.length !== 2) return null;
|
|
42
|
+
const [from, to] = [endOf(span[0]), endOf(span[1])];
|
|
43
|
+
if (from === undefined || to === undefined || (from !== null && to !== null && from >= to)) return null;
|
|
44
|
+
spans.push([from, to]);
|
|
45
|
+
}
|
|
46
|
+
return spans;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function releaseOf(value) {
|
|
50
|
+
if (value === null || typeof value !== "object") return null;
|
|
51
|
+
const spans = spansOf(value.spans);
|
|
52
|
+
if (typeof value.id !== "string" || !RELEASE_ID.test(value.id) || !MEMBER_ID.test(String(value.by)) || !MEMBER_ID.test(String(value.to)) || spans === null || !finite(value.at)) return null;
|
|
53
|
+
return { to: value.to, spans, stopped: finite(value.stopped) ? value.stopped : null };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const isLogStep = (entry) => entry?.kind === "step" && (entry.step === MEMBERS_STEP || entry.step === RELEASE_STEP);
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The newest whole snapshot in `entries` (a chat's `members` steps, any order): `{started, members: Map<w, spans>,
|
|
60
|
+
* releases}`, `null` when there is no `members` step at all, or `{broken: true}` when there is one but no whole,
|
|
61
|
+
* readable snapshot.
|
|
62
|
+
*/
|
|
63
|
+
function membersSnapshot(entries) {
|
|
64
|
+
const parts = new Map();
|
|
65
|
+
let seen = false;
|
|
66
|
+
for (const entry of Array.isArray(entries) ? entries : []) {
|
|
67
|
+
if (entry?.kind !== "step" || entry.step !== MEMBERS_STEP) continue;
|
|
68
|
+
seen = true;
|
|
69
|
+
const out = entry.output;
|
|
70
|
+
if (out === null || typeof out !== "object" || typeof out.snap !== "string" || !Number.isSafeInteger(out.part) || !Number.isSafeInteger(out.of) || out.of < 1 || out.part < 0 || out.part >= out.of) continue;
|
|
71
|
+
const held = parts.get(out.snap) ?? { at: 0, of: out.of, got: new Map() };
|
|
72
|
+
held.got.set(out.part, out);
|
|
73
|
+
held.at = Math.max(held.at, finite(entry.at) ? entry.at : 0);
|
|
74
|
+
parts.set(out.snap, held);
|
|
75
|
+
}
|
|
76
|
+
if (!seen) return null;
|
|
77
|
+
const whole = [...parts.values()].filter((held) => held.got.size === held.of).sort((a, b) => b.at - a.at);
|
|
78
|
+
if (whole.length === 0) return { broken: true };
|
|
79
|
+
const members = new Map();
|
|
80
|
+
const releases = [];
|
|
81
|
+
let started = null;
|
|
82
|
+
for (const out of whole[0].got.values()) {
|
|
83
|
+
if (finite(out.started)) started = out.started;
|
|
84
|
+
for (const [w, raw] of Object.entries(out.members ?? {})) {
|
|
85
|
+
const spans = spansOf(raw);
|
|
86
|
+
if (!MEMBER_ID.test(w) || spans === null) return { broken: true };
|
|
87
|
+
members.set(w, spans);
|
|
88
|
+
}
|
|
89
|
+
for (const raw of Array.isArray(out.releases) ? out.releases : []) {
|
|
90
|
+
const release = releaseOf(raw);
|
|
91
|
+
if (release !== null) releases.push(release);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return started === null || members.size === 0 ? { broken: true } : { started, members, releases };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** `[from, to)` windows (null open) not covered by `spans`, from the beginning of time to the end. */
|
|
98
|
+
function gapsOf(spans) {
|
|
99
|
+
const sorted = spans.map(([from, to]) => [from ?? -Infinity, to ?? Infinity]).sort((a, b) => a[0] - b[0]);
|
|
100
|
+
const gaps = [];
|
|
101
|
+
let cursor = -Infinity;
|
|
102
|
+
for (const [from, to] of sorted) {
|
|
103
|
+
if (from > cursor) gaps.push([cursor, from]);
|
|
104
|
+
cursor = Math.max(cursor, to);
|
|
105
|
+
}
|
|
106
|
+
if (cursor < Infinity) gaps.push([cursor, Infinity]);
|
|
107
|
+
return gaps;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** `windows` with `spans` taken out. */
|
|
111
|
+
function without(windows, spans) {
|
|
112
|
+
let out = windows;
|
|
113
|
+
for (const [rawFrom, rawTo] of spans) {
|
|
114
|
+
const [from, to] = [rawFrom ?? -Infinity, rawTo ?? Infinity];
|
|
115
|
+
out = out.flatMap(([a, b]) => (to <= a || from >= b ? [[a, b]] : [...(a < from ? [[a, from]] : []), ...(to < b ? [[to, b]] : [])]));
|
|
116
|
+
}
|
|
117
|
+
return out;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* The seal a group chat's history is read under, from its `members` steps (`MEMBERS_SNAPSHOT_READ`), or null when it
|
|
122
|
+
* keeps no log. `{sealedAt(at), sealedEntry(entry), broken}`: the windows when someone here now was away, less what a
|
|
123
|
+
* member released to them and has not stopped.
|
|
124
|
+
*/
|
|
125
|
+
function roomSealOf(snapshotEntries) {
|
|
126
|
+
const snapshot = membersSnapshot(snapshotEntries);
|
|
127
|
+
if (snapshot === null) return null;
|
|
128
|
+
if (snapshot.broken) return brokenSeal();
|
|
129
|
+
const windows = [];
|
|
130
|
+
for (const [w, spans] of snapshot.members) {
|
|
131
|
+
// Only someone here now: a member who left reads nothing here.
|
|
132
|
+
if (!spans.some(([, to]) => to === null)) continue;
|
|
133
|
+
const released = snapshot.releases.filter((release) => release.to === w && release.stopped === null).flatMap((release) => release.spans);
|
|
134
|
+
windows.push(...without(gapsOf(spans), released).filter(([from, to]) => from < to));
|
|
135
|
+
}
|
|
136
|
+
const sealedAt = (at) => !finite(at) || windows.some(([from, to]) => at >= from && at < to);
|
|
137
|
+
const overlaps = (lo, hi) => windows.some(([from, to]) => from < hi && to > lo);
|
|
138
|
+
const sealedEntry = (entry) => {
|
|
139
|
+
if (isLogStep(entry)) return false;
|
|
140
|
+
if (entry?.kind === "day") {
|
|
141
|
+
const day = typeof entry.day === "string" ? DAY_ID.exec(entry.day) : null;
|
|
142
|
+
if (day === null) return true;
|
|
143
|
+
const midnight = Date.UTC(Number(day[1]), Number(day[2]) - 1, Number(day[3]));
|
|
144
|
+
// A day is in its chat's own time zone: a day either side of UTC covers every one.
|
|
145
|
+
return !finite(midnight) || overlaps(midnight - DAY_MS, midnight + 2 * DAY_MS);
|
|
146
|
+
}
|
|
147
|
+
if (Array.isArray(entry?.texts) && entry.texts.some((id) => sealedAt(timeOfId(id)))) return true;
|
|
148
|
+
return sealedAt(entry?.at);
|
|
149
|
+
};
|
|
150
|
+
return { broken: false, sealedAt, sealedEntry, windows: windows.length };
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function brokenSeal() {
|
|
154
|
+
return { broken: true, sealedAt: () => true, sealedEntry: (entry) => !isLogStep(entry), windows: 1 };
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** The time a text's id carries (its first 13 digits), or NaN. */
|
|
158
|
+
function timeOfId(id) {
|
|
159
|
+
const found = TIME_IN_ID.exec(String(id ?? ""));
|
|
160
|
+
return found === null ? Number.NaN : Number(found[1]);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** An entry as a reader outside a turn may see it: no plain hash of anyone's number. */
|
|
164
|
+
function shownEntry(entry) {
|
|
165
|
+
if (entry === null || typeof entry !== "object") return entry;
|
|
166
|
+
const { people: _people, ...rest } = entry;
|
|
167
|
+
if (rest.from && typeof rest.from === "object" && "who" in rest.from) {
|
|
168
|
+
const { who: _who, ...from } = rest.from;
|
|
169
|
+
rest.from = from;
|
|
170
|
+
}
|
|
171
|
+
return rest;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* `answer` (a ledger read's `{entries, ...}`) as a reader outside a turn may see it, under `seal` (`roomSealOf`, null
|
|
176
|
+
* for a chat with no log): sealed entries left out and counted in `sealed`, every kept entry without plain hashes.
|
|
177
|
+
* `threadIds`, for a chat's threads ledger: the threads sealed whole (`sealedThreadIds`).
|
|
178
|
+
*/
|
|
179
|
+
function sealedAnswer(answer, seal, { threadIds = null } = {}) {
|
|
180
|
+
const entries = Array.isArray(answer?.entries) ? answer.entries : [];
|
|
181
|
+
const kept = [];
|
|
182
|
+
let sealed = 0;
|
|
183
|
+
for (const entry of entries) {
|
|
184
|
+
const out = seal !== null && (seal.sealedEntry(entry) || (threadIds !== null && typeof entry?.thread === "string" && threadIds.has(entry.thread)));
|
|
185
|
+
if (out) sealed += 1;
|
|
186
|
+
else kept.push(shownEntry(entry));
|
|
187
|
+
}
|
|
188
|
+
return { ...(answer && typeof answer === "object" ? answer : {}), entries: kept, ...(seal !== null ? { sealed } : {}) };
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** Of a threads ledger's entries (all of them, any order), the thread ids sealed whole: any entry of theirs sealed. */
|
|
192
|
+
function sealedThreadIds(threadEntries, seal) {
|
|
193
|
+
const ids = new Set();
|
|
194
|
+
if (seal === null) return ids;
|
|
195
|
+
for (const entry of Array.isArray(threadEntries) ? threadEntries : []) {
|
|
196
|
+
if (entry?.kind !== "thread" || typeof entry.thread !== "string") continue;
|
|
197
|
+
if (seal.broken || seal.sealedEntry(entry)) ids.add(entry.thread);
|
|
198
|
+
}
|
|
199
|
+
return ids;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
module.exports = { MEMBERS_STEP, RELEASE_STEP, MEMBERS_SNAPSHOT_READ, membersSnapshot, roomSealOf, brokenSeal, sealedAnswer, sealedThreadIds, shownEntry, timeOfId };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare const MEMBERS_STEP: "members";
|
|
2
|
+
export declare const RELEASE_STEP: "release";
|
|
3
|
+
export declare const MEMBERS_SNAPSHOT_READ: Readonly<{ kinds: string[]; steps: string[]; before: number; limit: number }>;
|
|
4
|
+
export type Span = [number | null, number | null];
|
|
5
|
+
export type MembersSnapshot = { started: number; members: Map<string, Span[]>; releases: { to: string; spans: Span[]; stopped: number | null }[] } | { broken: true } | null;
|
|
6
|
+
export declare function membersSnapshot(entries: unknown): MembersSnapshot;
|
|
7
|
+
export type RoomSeal = { broken: boolean; sealedAt(at: unknown): boolean; sealedEntry(entry: unknown): boolean; windows: number };
|
|
8
|
+
export declare function roomSealOf(snapshotEntries: unknown): RoomSeal | null;
|
|
9
|
+
export declare function brokenSeal(): RoomSeal;
|
|
10
|
+
export declare function sealedAnswer<T extends { entries?: unknown[] }>(answer: T, seal: RoomSeal | null, options?: { threadIds?: Set<string> | null }): T & { entries: unknown[]; sealed?: number };
|
|
11
|
+
export declare function sealedThreadIds(threadEntries: unknown, seal: RoomSeal | null): Set<string>;
|
|
12
|
+
export declare function shownEntry<T>(entry: T): T;
|
|
13
|
+
export declare function timeOfId(id: unknown): number;
|
|
@@ -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 (
|
|
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
|
*/
|
package/texContract/pageJobs.cjs
CHANGED
|
@@ -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
|
-
*
|
|
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`,
|
|
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:
|
|
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 (
|
|
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
|
-
*
|
|
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 (
|
|
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 (
|
|
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
|
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
|
|
20
20
|
const { folded } = require("./folded.cjs");
|
|
21
21
|
|
|
22
|
-
/** A text that ends by asking whether to send: "Send?", "Send it? 👍 or 👎?", "Send to bram@
|
|
22
|
+
/** A text that ends by asking whether to send: "Send?", "Send it? 👍 or 👎?", "Send to bram@example.com on his thread?". */
|
|
23
23
|
const SEND_ASK = /(?:^|\n)\s*(?:(?:ok(?:ay)?\s+to|should\s+I|shall\s+I)\s+)?send(?:\s+(?:it|this|that|the email|the reply))?(?:\s+(?:to|on|as)\b[^?\n]{0,160})?\s*\?[\s\u{1F44D}\u{1F44E}or?]*$/iu;
|
|
24
24
|
|
|
25
25
|
/** Whether Tex's text ends by asking whether to send what it showed. */
|
|
@@ -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
|
|
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 (
|
|
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. */
|
package/texContract/texGraph.cjs
CHANGED
|
@@ -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 (
|
|
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
|
|
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
|
-
*
|
|
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
|
|
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
|
|
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
|
-
* (
|
|
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
|
*/
|