@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.
- package/LICENSE +21 -0
- package/README.md +11 -2
- package/package.json +16 -4
- package/texContract/aboutLines.cjs +117 -0
- package/texContract/aboutLines.d.cts +14 -0
- package/texContract/aboutNoteLimits.cjs +41 -0
- package/texContract/aboutNoteLimits.d.cts +5 -0
- package/texContract/actionManual.cjs +104 -0
- package/texContract/activityHint.cjs +40 -0
- package/texContract/activityHint.d.cts +4 -0
- package/texContract/asks.cjs +16 -0
- package/texContract/asks.d.cts +6 -0
- package/texContract/asksToFile.cjs +20 -0
- package/texContract/asksToFile.d.cts +2 -0
- package/texContract/attention.cjs +138 -0
- package/texContract/attention.d.cts +20 -0
- package/texContract/browserHandback.cjs +13 -0
- package/texContract/browserHandback.d.cts +3 -0
- package/texContract/browserOwner.cjs +31 -0
- package/texContract/browserOwner.d.cts +2 -0
- package/texContract/bytes.cjs +12 -0
- package/texContract/chatHistoryPath.cjs +38 -0
- package/texContract/chatHistoryPath.d.cts +5 -0
- package/texContract/chatLedger.cjs +91 -0
- package/texContract/chatLedger.d.cts +21 -0
- package/texContract/computerTool.cjs +102 -0
- package/texContract/computerTool.d.cts +16 -0
- package/texContract/consentYes.cjs +22 -0
- package/texContract/consentYes.d.cts +5 -0
- package/texContract/contextGateway.cjs +52 -0
- package/texContract/contextGateway.d.cts +19 -0
- package/texContract/deskEligible.cjs +20 -0
- package/texContract/deskEligible.d.cts +3 -0
- package/texContract/downloads.cjs +129 -0
- package/texContract/downloads.d.cts +15 -0
- package/texContract/egressLedger.cjs +114 -0
- package/texContract/egressLedger.d.cts +14 -0
- package/texContract/emailRead.cjs +38 -0
- package/texContract/emailRead.d.cts +5 -0
- package/texContract/eventWords.cjs +35 -0
- package/texContract/eventWords.d.cts +4 -0
- package/texContract/fileParts.cjs +43 -0
- package/texContract/fileParts.d.cts +6 -0
- package/texContract/fileTables.cjs +243 -0
- package/texContract/fileWords.cjs +169 -0
- package/texContract/folded.cjs +16 -0
- package/texContract/folded.d.cts +3 -0
- package/texContract/googleAiAccess.cjs +12 -0
- package/texContract/googleAiAccess.d.cts +2 -0
- package/texContract/graphWires.cjs +18 -0
- package/texContract/graphWires.d.cts +5 -0
- package/texContract/groupSession.cjs +28 -0
- package/texContract/groupSession.d.cts +7 -0
- package/texContract/guestNames.cjs +136 -0
- package/texContract/guestNames.d.cts +35 -0
- package/texContract/heard.cjs +19 -0
- package/texContract/heard.d.cts +4 -0
- package/texContract/heldOffer.cjs +57 -0
- package/texContract/heldOffer.d.cts +8 -0
- package/texContract/helperCallers.cjs +29 -0
- package/texContract/helperCallers.d.cts +4 -0
- package/texContract/identity.cjs +179 -0
- package/texContract/identity.d.cts +8 -0
- package/texContract/jobLogEntries.cjs +93 -0
- package/texContract/jobLogEntries.d.cts +12 -0
- package/texContract/judgedActions.cjs +20 -0
- package/texContract/judgedActions.d.cts +4 -0
- package/texContract/labSandboxGate.cjs +63 -0
- package/texContract/labSandboxGate.d.cts +9 -0
- package/texContract/ledgerReadChars.cjs +4 -0
- package/texContract/ledgerReadChars.d.cts +3 -0
- package/texContract/mailCheck.cjs +90 -0
- package/texContract/mailCheck.d.cts +12 -0
- package/texContract/mailEntries.cjs +64 -0
- package/texContract/mailEntries.d.cts +13 -0
- package/texContract/mailHealth.cjs +60 -0
- package/texContract/mailHealth.d.cts +10 -0
- package/texContract/notePath.cjs +99 -0
- package/texContract/notePath.d.cts +4 -0
- package/texContract/noteRunFacts.cjs +136 -0
- package/texContract/noteRunFacts.d.cts +32 -0
- package/texContract/objectEtag.cjs +84 -0
- package/texContract/objectEtag.d.cts +4 -0
- package/texContract/objectPlace.cjs +32 -0
- package/texContract/objectPlace.d.cts +5 -0
- package/texContract/pageJobs.cjs +226 -0
- package/texContract/pageJobs.d.cts +13 -0
- package/texContract/pdfLinks.cjs +135 -0
- package/texContract/pdfLinks.d.cts +4 -0
- package/texContract/personHub.cjs +38 -0
- package/texContract/personHub.d.cts +5 -0
- package/texContract/personNameText.cjs +18 -0
- package/texContract/personNameText.d.cts +3 -0
- package/texContract/pinnedContext.cjs +12 -0
- package/texContract/pinnedContext.d.cts +3 -0
- package/texContract/quietHoursWindow.cjs +36 -0
- package/texContract/quietHoursWindow.d.cts +3 -0
- package/texContract/scopeClamp.cjs +117 -0
- package/texContract/scopeClamp.d.cts +5 -0
- package/texContract/scopes.cjs +29 -0
- package/texContract/scopes.d.cts +7 -0
- package/texContract/searchSettings.cjs +54 -0
- package/texContract/searchSettings.d.cts +6 -0
- package/texContract/settingHabits.cjs +87 -0
- package/texContract/settingHabits.d.cts +20 -0
- package/texContract/settingsNotes.cjs +217 -0
- package/texContract/settingsNotes.d.cts +26 -0
- package/texContract/shownEmail.cjs +181 -0
- package/texContract/texClients.cjs +53 -0
- package/texContract/texClients.d.cts +12 -0
- package/texContract/texGraph.cjs +593 -0
- package/texContract/texGraph.d.cts +55 -0
- package/texContract/texKeys.cjs +100 -0
- package/texContract/texKeys.d.cts +13 -0
- package/texContract/texOwnSources.cjs +9 -0
- package/texContract/texOwnSources.d.cts +3 -0
- package/texContract/texStoreNames.cjs +26 -0
- package/texContract/texStoreNames.d.cts +12 -0
- package/texContract/texStoreWire.cjs +306 -0
- package/texContract/texStoreWire.d.cts +32 -0
- package/texContract/threadsFold.cjs +75 -0
- package/texContract/threadsFold.d.cts +22 -0
- package/texContract/toolActions.cjs +253 -0
- package/texContract/toolCatalog.cjs +49 -0
- package/texContract/toolCatalog.generated.json +90 -0
- package/texContract/toolContract.cjs +52 -0
- package/texContract/toolContract.d.cts +12 -0
- package/texContract/toolShapes.cjs +14 -0
- package/texContract/transcription.cjs +101 -0
- package/texContract/transcription.d.cts +3 -0
- package/texContract/treeJobs.cjs +31 -0
- package/texContract/treeJobs.d.cts +3 -0
- package/texContract/turnSession.cjs +90 -0
- package/texContract/turnSession.d.cts +19 -0
- package/texContract/turnWords.cjs +90 -0
- package/texContract/turnWords.d.cts +9 -0
- package/texContract/uploadImages.cjs +131 -0
- package/texContract/uploadImages.d.cts +13 -0
- package/texContract/v2Names.cjs +41 -0
- package/texContract/v2SearchFetch.cjs +316 -0
- package/texContract/v2Translate.cjs +123 -0
- package/texContract/vaultTools.cjs +112 -0
- package/texContract/vaultTools.d.cts +15 -0
- package/texContract/yesWords.cjs +91 -0
- package/texShared/argumentCoercion.cjs +93 -0
- package/texShared/cellComments.cjs +122 -0
- package/texShared/cellComments.d.cts +21 -0
- package/texShared/comments.cjs +586 -0
- package/texShared/comments.d.cts +115 -0
- package/texShared/contentTypes.cjs +85 -0
- package/texShared/fileKinds.cjs +123 -0
- package/texShared/flags.cjs +124 -0
- package/texShared/flags.d.cts +21 -0
- package/texShared/folderJobInfo.cjs +301 -0
- package/texShared/folderJobInfo.d.cts +40 -0
- package/texShared/folderRoles.cjs +512 -0
- package/texShared/folderRoles.d.cts +73 -0
- package/texShared/githubOidc.ts +98 -0
- package/texShared/groupRunQuestions.cjs +98 -0
- package/texShared/groupRunQuestions.d.cts +4 -0
- package/texShared/inboxFolders.cjs +49 -0
- package/texShared/inboxFolders.d.cts +5 -0
- package/texShared/ink/drawing.cjs +474 -0
- package/texShared/ink/texFigure.cjs +252 -0
- package/texShared/ink/texFigure.d.cts +36 -0
- package/texShared/ink/texPoses.cjs +180 -0
- package/texShared/ink/texPoses.d.cts +20 -0
- package/texShared/jobPartEnd.cjs +133 -0
- package/texShared/jobPartEnd.d.cts +13 -0
- package/texShared/jobResume.cjs +31 -0
- package/texShared/jobResume.d.cts +5 -0
- package/texShared/jobSplit.cjs +90 -0
- package/texShared/jobSplit.d.cts +6 -0
- package/texShared/jobStart.cjs +56 -0
- package/texShared/jobStart.d.cts +9 -0
- package/texShared/mail.cjs +400 -0
- package/texShared/mail.d.cts +56 -0
- package/texShared/messageAnchors.cjs +38 -0
- package/texShared/models/aiKeys.cjs +137 -0
- package/texShared/models/aiKeys.d.cts +42 -0
- package/texShared/models/aiKeys.json +56 -0
- package/texShared/models/creditRest.cjs +269 -0
- package/texShared/models/promptBudget.cjs +295 -0
- package/texShared/models/promptSections.cjs +29 -0
- package/texShared/noteAppLink.cjs +23 -0
- package/texShared/notePreview.cjs +219 -0
- package/texShared/notePreview.d.cts +21 -0
- package/texShared/pages/blocks.cjs +215 -0
- package/texShared/pages/cover.cjs +164 -0
- package/texShared/pages/css.cjs +181 -0
- package/texShared/pages/cssBlocks.cjs +264 -0
- package/texShared/pages/draw.cjs +212 -0
- package/texShared/pages/drawRich.cjs +232 -0
- package/texShared/pages/html.cjs +168 -0
- package/texShared/pages/inline.cjs +251 -0
- package/texShared/pages/layout.cjs +76 -0
- package/texShared/pages/parse.cjs +418 -0
- package/texShared/pages/render.cjs +200 -0
- package/texShared/pages/skill.cjs +147 -0
- package/texShared/pages/skill.d.cts +5 -0
- package/texShared/pages/templates.cjs +336 -0
- package/texShared/r2Store.cjs +163 -0
- package/texShared/remoteImage.cjs +177 -0
- package/texShared/routines.cjs +656 -0
- package/texShared/routines.d.cts +86 -0
- package/texShared/servedListing.cjs +250 -0
- package/texShared/servedListing.d.cts +17 -0
- package/texShared/sheetCsv.cjs +566 -0
- package/texShared/sheetCsv.d.cts +91 -0
- package/texShared/storageLayout.cjs +88 -0
- package/texShared/storeKeys.cjs +144 -0
- package/texShared/toolArguments.cjs +323 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Supa Media
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @supa-media/tex-contract
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The contract between [Context](https://github.com/Supa-Media/context) and Tex, the texting assistant. Tex is an MCP client of Context like any other. This package holds what both sides read the same way:
|
|
4
|
+
|
|
5
|
+
- `texContract/`: the tool names and the catalog snapshot, the wire formats of Context's door, and the six tools' translation.
|
|
6
|
+
- `texShared/`: the shared helpers Tex takes with it, such as file kinds, sheets and message anchors.
|
|
7
|
+
|
|
8
|
+
It is plain CommonJS with no dependencies, and it holds no secrets and no vault code.
|
|
9
|
+
|
|
10
|
+
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.
|
|
11
|
+
|
|
12
|
+
MIT licensed.
|
package/package.json
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@supa-media/tex-contract",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.7",
|
|
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
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/Supa-Media/context.git",
|
|
9
|
+
"directory": "packages/shared/src"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/Supa-Media/context/blob/main/docs/decisions/texting-assistant/tex-service.md",
|
|
12
|
+
"files": ["texContract", "texShared", "README.md", "LICENSE"],
|
|
13
|
+
"exports": {
|
|
14
|
+
"./texContract/*": "./texContract/*",
|
|
15
|
+
"./texShared/*": "./texShared/*",
|
|
16
|
+
"./package.json": "./package.json"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The lines of an "about" note — the person's `tex/about.md` (or its old name
|
|
3
|
+
* `tex/about-me.md`) and a group chat's `tex/groups/<id>/about.md` — read the
|
|
4
|
+
* one way both the Tex page (`apps/mcp/src/http/texPage/notes.js`) and the note's writer
|
|
5
|
+
* (`apps/mcp/src/tools/notes/write.js`) read them.
|
|
6
|
+
*
|
|
7
|
+
* Each line may end with a marker naming who it came from and when:
|
|
8
|
+
* `- Prefers short texts (you said so, 2026-11-02)`. The page shows the
|
|
9
|
+
* source and the date beside the line. Tex writes the source (`you said so`,
|
|
10
|
+
* `<name> said so`); the date is added on save by `stampAboutLines`, so it is
|
|
11
|
+
* the day the line was written and never a date a model guessed.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const BULLET = /^\s*(?:[-*+]|\d+[.)])\s+/;
|
|
15
|
+
const TRAILING = /\s*[(\[]([^()[\]]{1,160})[)\]]\s*$/;
|
|
16
|
+
|
|
17
|
+
const ABOUT_PATH = /^(?:tex\/about\.md|tex\/about-me\.md|tex\/groups\/[A-Za-z0-9][A-Za-z0-9_-]{0,80}\/about\.md)$/;
|
|
18
|
+
|
|
19
|
+
/** Whether `path` is an about note: the person's own, or a group chat's. */
|
|
20
|
+
function isAboutNotePath(path) {
|
|
21
|
+
return typeof path === "string" && ABOUT_PATH.test(path) && !path.includes("..");
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** A trailing marker's words: a source label and a date, when it carries either. Null otherwise. */
|
|
25
|
+
function markerOf(content) {
|
|
26
|
+
let source = null;
|
|
27
|
+
let at;
|
|
28
|
+
for (const raw of content.split(/[,;·|]/)) {
|
|
29
|
+
const part = raw.trim();
|
|
30
|
+
const date = /^(\d{4})-(\d{2})-(\d{2})$/.exec(part);
|
|
31
|
+
if (date) {
|
|
32
|
+
at = Date.UTC(Number(date[1]), Number(date[2]) - 1, Number(date[3]));
|
|
33
|
+
} else if (/^you said so$/i.test(part)) {
|
|
34
|
+
source = "You said so";
|
|
35
|
+
} else if (/^from your texts$/i.test(part)) {
|
|
36
|
+
source = "From your texts";
|
|
37
|
+
} else if (/^tex noticed$/i.test(part)) {
|
|
38
|
+
source = "Tex noticed";
|
|
39
|
+
} else if (/^tex rechecked$/i.test(part)) {
|
|
40
|
+
source = "Tex rechecked";
|
|
41
|
+
} else if (/^.{1,60} said so$/i.test(part)) {
|
|
42
|
+
source = `${part.slice(0, -" said so".length).trim()} said so`;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return source === null && at === undefined ? null : { source: source ?? "Tex noticed", at };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** The first line of the note after its front matter, where the body starts. */
|
|
49
|
+
function bodyStart(lines) {
|
|
50
|
+
if (lines[0]?.trim() !== "---") return 0;
|
|
51
|
+
for (let i = 1; i < lines.length; i++) {
|
|
52
|
+
const line = lines[i].trim();
|
|
53
|
+
if (line === "---" || line === "...") return i + 1;
|
|
54
|
+
}
|
|
55
|
+
return 0;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** A line as an about item (`null` for a blank line, a heading, a comment, a rule). */
|
|
59
|
+
function itemOf(raw) {
|
|
60
|
+
const trimmed = raw.trim();
|
|
61
|
+
if (trimmed === "" || /^#{1,6}(\s|$)/.test(trimmed) || /^<!--/.test(trimmed) || /^-{3,}$/.test(trimmed)) return null;
|
|
62
|
+
const bullet = BULLET.exec(raw)?.[0] ?? "";
|
|
63
|
+
const rest = raw.slice(bullet.length).trim();
|
|
64
|
+
const found = TRAILING.exec(rest);
|
|
65
|
+
const marker = found ? markerOf(found[1]) : null;
|
|
66
|
+
const text = marker ? rest.slice(0, found.index).trim() : rest;
|
|
67
|
+
if (text === "") return null;
|
|
68
|
+
return { bullet, text, marker: marker ? found[0] : "", source: marker?.source ?? "Tex noticed", at: marker?.at };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const sameText = (text) => text.replace(/\s+/g, " ").trim().toLowerCase();
|
|
72
|
+
const dayOf = (ms) => new Date(ms).toISOString().slice(0, 10);
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* `content` with every about line given a dated marker, for a save at `now`.
|
|
76
|
+
*
|
|
77
|
+
* - A line that already has a dated marker is left as it is.
|
|
78
|
+
* - A line the stored note (`storedBody`, null for a new note) already had,
|
|
79
|
+
* word for word, keeps the stored line's marker, or its date: rewriting the
|
|
80
|
+
* whole note does not make an old line new. One the stored note had with no
|
|
81
|
+
* date stays undated, since the day it was written is not known.
|
|
82
|
+
* - Any other line is dated today, keeping the source it names (`(you said
|
|
83
|
+
* so)`), or `Tex noticed` when it names none.
|
|
84
|
+
*
|
|
85
|
+
* Front matter, headings, comments, rules and blank lines are left alone.
|
|
86
|
+
*/
|
|
87
|
+
function stampAboutLines(content, storedBody, now) {
|
|
88
|
+
if (typeof content !== "string") return content;
|
|
89
|
+
const stored = new Map();
|
|
90
|
+
if (typeof storedBody === "string") {
|
|
91
|
+
const lines = storedBody.replace(/^\uFEFF/, "").split("\n");
|
|
92
|
+
for (let i = bodyStart(lines); i < lines.length; i++) {
|
|
93
|
+
const entry = itemOf(lines[i]);
|
|
94
|
+
if (entry !== null && (entry.at !== undefined || !stored.has(sameText(entry.text)))) stored.set(sameText(entry.text), entry);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
const today = dayOf(now);
|
|
98
|
+
const lines = content.split("\n");
|
|
99
|
+
for (let i = bodyStart(lines); i < lines.length; i++) {
|
|
100
|
+
const raw = lines[i];
|
|
101
|
+
const entry = itemOf(raw);
|
|
102
|
+
if (entry === null || entry.at !== undefined) continue;
|
|
103
|
+
const cr = raw.endsWith("\r") ? "\r" : "";
|
|
104
|
+
const line = raw.replace(/\s+$/, "");
|
|
105
|
+
const before = stored.get(sameText(entry.text));
|
|
106
|
+
if (before !== undefined && before.at === undefined) continue; // an old line nobody dated: when it was written is not known
|
|
107
|
+
if (entry.marker === "") {
|
|
108
|
+
lines[i] = before ? `${line}${before.marker.replace(/\s+$/, "")}${cr}` : `${line} (Tex noticed, ${today})${cr}`;
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
const found = TRAILING.exec(line);
|
|
112
|
+
lines[i] = `${line.slice(0, found.index)} (${found[1].trim()}, ${before ? dayOf(before.at) : today})${cr}`;
|
|
113
|
+
}
|
|
114
|
+
return lines.join("\n");
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
module.exports = { BULLET, TRAILING, isAboutNotePath, markerOf, bodyStart, itemOf, stampAboutLines };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const BULLET: RegExp;
|
|
2
|
+
export const TRAILING: RegExp;
|
|
3
|
+
export interface AboutItem {
|
|
4
|
+
bullet: string;
|
|
5
|
+
text: string;
|
|
6
|
+
marker: string;
|
|
7
|
+
source: string;
|
|
8
|
+
at: number | undefined;
|
|
9
|
+
}
|
|
10
|
+
export function isAboutNotePath(path: unknown): boolean;
|
|
11
|
+
export function markerOf(content: string): { source: string; at: number | undefined } | null;
|
|
12
|
+
export function bodyStart(lines: string[]): number;
|
|
13
|
+
export function itemOf(raw: string): AboutItem | null;
|
|
14
|
+
export function stampAboutLines<T>(content: T, storedBody: string | null | undefined, now: number): T;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
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
|
|
4
|
+
* held to (`apps/mcp/src/tools/notes/write.js`, which `remember` also goes
|
|
5
|
+
* through).
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const ABOUT_ME_PATH = "tex/about.md";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Its name until 2026-11-01, when a person's and a group chat's Tex folders
|
|
12
|
+
* took the same names (`docs/decisions/texting-assistant/tex-folders.md`).
|
|
13
|
+
* Read only when the new name has nothing, until the rename has run
|
|
14
|
+
* everywhere (`apps/convex/functions/texFolderNames.ts`).
|
|
15
|
+
*/
|
|
16
|
+
const OLD_ABOUT_ME_PATH = "tex/about-me.md";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The note's hard size, in lines (the owner, 2026-10-14: "it doesn't need to
|
|
20
|
+
* be more than 500 lines"). Every write to it is refused past this, from any
|
|
21
|
+
* writer (`apps/mcp/src/tools/notes/write.js`, which `remember` also goes
|
|
22
|
+
* through), so the prompt always carries the whole note.
|
|
23
|
+
*/
|
|
24
|
+
const MAX_ABOUT_ME_LINES = 500;
|
|
25
|
+
|
|
26
|
+
/** A bound on characters too, so 500 very long lines can't stand in for a book. */
|
|
27
|
+
const MAX_ABOUT_ME_CHARS = 40_000;
|
|
28
|
+
|
|
29
|
+
/** Why a write of `content` to `path` is refused, or null. */
|
|
30
|
+
function aboutMeTooLong(path, content) {
|
|
31
|
+
if ((path !== ABOUT_ME_PATH && path !== OLD_ABOUT_ME_PATH) || typeof content !== "string") return null;
|
|
32
|
+
const lines = content.replace(/\n$/, "").split("\n").length;
|
|
33
|
+
if (lines <= MAX_ABOUT_ME_LINES && content.length <= MAX_ABOUT_ME_CHARS) return null;
|
|
34
|
+
return (
|
|
35
|
+
`too long: ${ABOUT_ME_PATH} holds at most ${MAX_ABOUT_ME_LINES} lines and ${MAX_ABOUT_ME_CHARS} characters ` +
|
|
36
|
+
`(this is ${lines} lines, ${content.length} characters). Nothing was written. ` +
|
|
37
|
+
"Condense it: merge repeated facts, drop what's stale, keep one short line per fact."
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
module.exports = { ABOUT_ME_PATH, OLD_ABOUT_ME_PATH, MAX_ABOUT_ME_LINES, MAX_ABOUT_ME_CHARS, aboutMeTooLong };
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* An action's argument line, as orient's manual says it and Tex's six-tool turn writes a call out: read from the
|
|
4
|
+
* action's own table entry (`toolActions.cjs`) and the schema of the tool that carries it. Pure over its inputs; the
|
|
5
|
+
* gateway (`orient/manual.js`) passes its live carrier, Tex the one its catalog holds (`toolCatalog.cjs`).
|
|
6
|
+
*/
|
|
7
|
+
const { ACTIONS } = require("./toolActions.cjs");
|
|
8
|
+
|
|
9
|
+
/** A JSON Schema property as a short type: `string`, `"a"|"b"`, `string[]`, `{a, b}`. */
|
|
10
|
+
function typeOf(schema) {
|
|
11
|
+
if (!schema || typeof schema !== "object") return "any";
|
|
12
|
+
if (Array.isArray(schema.enum)) return schema.enum.map((value) => JSON.stringify(value)).join("|");
|
|
13
|
+
const options = schema.oneOf || schema.anyOf;
|
|
14
|
+
if (Array.isArray(options)) return [...new Set(options.map(typeOf))].join("|");
|
|
15
|
+
const types = Array.isArray(schema.type) ? schema.type : [schema.type];
|
|
16
|
+
return types
|
|
17
|
+
.map((type) => {
|
|
18
|
+
if (type === "array") return `${typeOf(schema.items)}[]`;
|
|
19
|
+
if (type === "object" && schema.properties && Object.keys(schema.properties).length) {
|
|
20
|
+
const required = new Set(schema.required || []);
|
|
21
|
+
const keys = Object.keys(schema.properties).map((key) => (required.has(key) ? `${key}*` : key));
|
|
22
|
+
return `{${keys.join(", ")}}`;
|
|
23
|
+
}
|
|
24
|
+
return type || "any";
|
|
25
|
+
})
|
|
26
|
+
.join("|");
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* A property list as `name*: type · name: type`, `*` marking the required ones.
|
|
31
|
+
* Shared by the tool lines below and orient's manual of actions.
|
|
32
|
+
*
|
|
33
|
+
* @param {Record<string, object>} properties
|
|
34
|
+
* @param {string[]} [required]
|
|
35
|
+
* @param {string[]} [skip] names left out
|
|
36
|
+
*/
|
|
37
|
+
function argumentsLine(properties = {}, required = [], skip = []) {
|
|
38
|
+
const needed = new Set(required);
|
|
39
|
+
const left = new Set(skip);
|
|
40
|
+
const args = Object.entries(properties)
|
|
41
|
+
.filter(([name]) => !left.has(name))
|
|
42
|
+
.map(([name, schema]) => `${name}${needed.has(name) ? "*" : ""}: ${typeOf(schema)}`);
|
|
43
|
+
return args.length ? args.join(" · ") : "none";
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Top-level fields of a `write` call that name a note. */
|
|
47
|
+
const NOTE_FIELDS = ["path", "content", "expected_etag"];
|
|
48
|
+
|
|
49
|
+
/** Fields every tool takes that are addressing, not an action's own argument. */
|
|
50
|
+
const ADDRESSING = ["context", "mailbox"];
|
|
51
|
+
|
|
52
|
+
/** A probe call, to read which top-level fields and nested argument an action's `take` produces. */
|
|
53
|
+
const PROBE = { path: "p", content: "c", expected_etag: "e", args: {} };
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* What an action's `take` puts where, read by running it once on a probe.
|
|
57
|
+
* A `nested` action (comment, mail, upload, website, api) returns its own
|
|
58
|
+
* arguments under one key; a note action keeps the note fields at the top;
|
|
59
|
+
* a plain one returns its arguments unchanged.
|
|
60
|
+
*/
|
|
61
|
+
function shapeOf(entry, carrier = null) {
|
|
62
|
+
const produced = entry.take(PROBE) || {};
|
|
63
|
+
const keys = Object.keys(produced);
|
|
64
|
+
// A note field the carrying tool does not take is not one to send at all.
|
|
65
|
+
const takes = carrier?.inputSchema?.properties || {};
|
|
66
|
+
return {
|
|
67
|
+
note: NOTE_FIELDS.filter((field) => keys.includes(field) && Object.hasOwn(takes, field)),
|
|
68
|
+
nested: keys.find((key) => !NOTE_FIELDS.includes(key)) ?? null,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Every nested argument key any action uses: they are sub-objects, never top-level tool arguments. */
|
|
73
|
+
const NESTED_KEYS = new Set(
|
|
74
|
+
Object.values(ACTIONS).flatMap((table) =>
|
|
75
|
+
Object.values(table)
|
|
76
|
+
.map((entry) => shapeOf(entry).nested)
|
|
77
|
+
.filter(Boolean)
|
|
78
|
+
)
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* The argument list an action takes, from its carrying tool's schema: the
|
|
83
|
+
* advertised one, or `carrier` where the caller holds its own definition
|
|
84
|
+
* (the texting assistant's, `agent/sixTools.js`).
|
|
85
|
+
*/
|
|
86
|
+
function actionArguments(entry, carrier = entry.carrier ?? null) {
|
|
87
|
+
const schema = carrier?.inputSchema || {};
|
|
88
|
+
const { nested } = shapeOf(entry, carrier);
|
|
89
|
+
if (nested) {
|
|
90
|
+
const sub = schema.properties?.[nested];
|
|
91
|
+
// A list (upload's files) travels as `args.files`, see `tools/v2/actions.js`.
|
|
92
|
+
if (sub?.type === "array") return argumentsLine({ files: sub }, ["files"]);
|
|
93
|
+
return argumentsLine(sub?.properties || {}, sub?.required || []);
|
|
94
|
+
}
|
|
95
|
+
// Fields the action keeps at the top level are said there, not here; a
|
|
96
|
+
// `manage` action has no top level, so its path is one of its args.
|
|
97
|
+
return argumentsLine(schema.properties || {}, schema.required || [], [
|
|
98
|
+
...ADDRESSING,
|
|
99
|
+
...shapeOf(entry, carrier).note,
|
|
100
|
+
...NESTED_KEYS,
|
|
101
|
+
]);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
module.exports = { ADDRESSING, NESTED_KEYS, NOTE_FIELDS, actionArguments, argumentsLine, shapeOf, typeOf };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a finished tool call tells the workspace activity feed, beside its
|
|
3
|
+
* answer rather than inside it.
|
|
4
|
+
*
|
|
5
|
+
* The feed (`agentActivity.js`) is told about a call after it returns, and
|
|
6
|
+
* until the live map it only needed the path, which it took from the call's
|
|
7
|
+
* arguments. A map needs two facts the arguments cannot give: whether a
|
|
8
|
+
* `write_note` *created* the note or changed one that was there, and which
|
|
9
|
+
* notes a move actually moved (a folder move names a folder; the feed wants
|
|
10
|
+
* the notes inside it, as they were renamed). Only the handler knows either.
|
|
11
|
+
*
|
|
12
|
+
* So the handler attaches them to its result under a Symbol. A Symbol-keyed
|
|
13
|
+
* property is invisible to `JSON.stringify` and `structuredClone`, so it
|
|
14
|
+
* never reaches the MCP client and never changes a tool's text. It is
|
|
15
|
+
* enumerable, so a wrapper that spreads the result (`{ ...result, sources }`)
|
|
16
|
+
* carries it on: Tex's page floor reads "created" from it, and when a texting
|
|
17
|
+
* wrapper's spread lost it, an overwrite of their note read as a new note,
|
|
18
|
+
* was sent back to be a page, and the note was archived (owner, 2026-10-30,
|
|
19
|
+
* `agent/theirNotes.js`). A wrapper that builds a new result from nothing
|
|
20
|
+
* still loses it; a reader then treats the write as a change, never as new.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
const ACTIVITY_HINT = Symbol("context.activityHint");
|
|
24
|
+
|
|
25
|
+
/** Attach `hint` to `result` and return `result`. */
|
|
26
|
+
function withActivityHint(result, hint) {
|
|
27
|
+
if (result && typeof result === "object" && hint && typeof hint === "object") {
|
|
28
|
+
Object.defineProperty(result, ACTIVITY_HINT, { value: hint, enumerable: true });
|
|
29
|
+
}
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** The hint a handler attached, or `null`. */
|
|
34
|
+
function activityHintOf(result) {
|
|
35
|
+
const hint = result && typeof result === "object" ? result[ACTIVITY_HINT] : undefined;
|
|
36
|
+
return hint && typeof hint === "object" ? hint : null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
module.exports = { withActivityHint, activityHintOf };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Held asks, as both sides name them: the gateway keeps them (`apps/mcp/src/tools/approvals.js`) and settles them
|
|
3
|
+
* (`apps/mcp/src/tools/texAsks.js`); Tex reads and answers them only through the `tex_asks` action
|
|
4
|
+
* (`packages/tex/gateway/asks.js`).
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/** The Context-side action Tex settles, arms and disarms its held asks with. Never advertised, never a model's. */
|
|
8
|
+
const TEX_ASKS_TOOL = "tex_asks";
|
|
9
|
+
/** A texted ask listens for a yes at most this long (`approvals.js` `TEXTING_TTL_MS`). */
|
|
10
|
+
const TEXTING_TTL_MS = 12 * 60 * 60 * 1000;
|
|
11
|
+
/** A texted listing that reaches every chat (`approvals.js` `listPending`): what only the sweeping disarms ask for. */
|
|
12
|
+
const EVERY_CHAT = Symbol.for("context.asks.every_chat");
|
|
13
|
+
/** A card's payment ask (`apps/mcp/src/vault/pay.js`). */
|
|
14
|
+
const VAULT_PAY = "vault_pay";
|
|
15
|
+
|
|
16
|
+
module.exports = { TEX_ASKS_TOOL, TEXTING_TTL_MS, EVERY_CHAT, VAULT_PAY };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether the person's own words ask for a bug to be filed (`apps/mcp/src/tools/reportGate.js`). A pure text check, so the
|
|
3
|
+
* gateway's report gate and Tex's bug check read the same phrases. Plain CommonJS with no imports.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/** "file a bug", "send a bug report to the team", "report this to the developers". */
|
|
7
|
+
const ASKS_TO_FILE = [
|
|
8
|
+
/\b(?:file|send|submit|open|log|raise|write up|make)\b[^.?!\n]{0,30}?\b(?:bug|issue|ticket|bug report)\b/i,
|
|
9
|
+
// "File the fact that you can't see your own diagram as a bug report" (Tex Devs group, 2026-10-26).
|
|
10
|
+
/\b(?:file|submit|log|raise|report)\b[^?!\n]{0,160}?\b(?:as|into)\s+(?:an?\s+)?(?:bug|issue|ticket)s?\b/i,
|
|
11
|
+
/\breport\s+(?:it|this|that)\b[^.?!\n]{0,20}\b(?:team|devs?|developers?|engineers?)\b/i,
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
/** Whether the person's own text, this turn, asks for a bug to be filed. */
|
|
15
|
+
function asksToFile(words) {
|
|
16
|
+
const said = String(words ?? "");
|
|
17
|
+
return ASKS_TO_FILE.some((pattern) => pattern.test(said));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
module.exports = { asksToFile };
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The pure half of getting the person's attention (`agent/attention.js`; docs/decisions/texting-assistant/attention.md):
|
|
3
|
+
* the settings in `tex/attention.md`, whether a ping is held, and how one is logged in `tex/attention/YYYY-MM-DD.md`.
|
|
4
|
+
* The gateway's `notify_me` (`tools/attention.js`) and Tex's check-in delivery both read and write the log by these,
|
|
5
|
+
* so neither imports the other.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const { clock, dayOf, longDate } = require("./jobLogEntries.cjs");
|
|
9
|
+
|
|
10
|
+
const ATTENTION_FOLDER = "tex/attention";
|
|
11
|
+
const ATTENTION_SETTINGS_PATH = "tex/attention.md";
|
|
12
|
+
|
|
13
|
+
const MAX_MUTED = 30;
|
|
14
|
+
|
|
15
|
+
const URGENCIES = ["emergency", "asked", "fyi"];
|
|
16
|
+
/**
|
|
17
|
+
* How much the person wants to hear, from least to most. `emergencies`: only
|
|
18
|
+
* those. `strict` (the default): emergencies and what they asked to be told.
|
|
19
|
+
* `relaxed`: anything an agent thinks they would want.
|
|
20
|
+
*/
|
|
21
|
+
const TOLERANCES = ["emergencies", "strict", "relaxed"];
|
|
22
|
+
const DEFAULT_TOLERANCE = "strict";
|
|
23
|
+
|
|
24
|
+
const LETS_THROUGH = {
|
|
25
|
+
emergencies: new Set(["emergency"]),
|
|
26
|
+
strict: new Set(["emergency", "asked"]),
|
|
27
|
+
relaxed: new Set(["emergency", "asked", "fyi"]),
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const MAX_MESSAGE_CHARS = 300;
|
|
31
|
+
const MAX_WHY_CHARS = 200;
|
|
32
|
+
function unquote(value) {
|
|
33
|
+
return value.trim().replace(/^["']|["']$/g, "").trim();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** `[a, b]` or `a, b` as a list of lowercased words. */
|
|
37
|
+
function listOf(value) {
|
|
38
|
+
const inner = value.trim().replace(/^\[|\]$/g, "");
|
|
39
|
+
return inner
|
|
40
|
+
.split(",")
|
|
41
|
+
.map((word) => unquote(word).toLowerCase())
|
|
42
|
+
.filter((word) => word !== "" && word.length <= 60)
|
|
43
|
+
.slice(0, MAX_MUTED);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* `tex/attention.md` read as settings. A note that is missing, unreadable or
|
|
48
|
+
* says something unknown is the defaults: strict, nothing muted, not paused.
|
|
49
|
+
*/
|
|
50
|
+
function readAttentionSettings(text) {
|
|
51
|
+
const raw = typeof text === "string" ? text.replace(/^\ufeff/, "") : "";
|
|
52
|
+
const lines = raw.split(/\r?\n/);
|
|
53
|
+
const settings = { tolerance: DEFAULT_TOLERANCE, mute: [], paused: false };
|
|
54
|
+
if (lines[0]?.trim() !== "---") return settings;
|
|
55
|
+
const end = lines.findIndex((line, i) => i > 0 && (line.trim() === "---" || line.trim() === "..."));
|
|
56
|
+
if (end < 0) return settings;
|
|
57
|
+
for (const line of lines.slice(1, end)) {
|
|
58
|
+
const match = /^\s*(tolerance|mute|paused)\s*:\s*(.*?)\s*$/i.exec(line);
|
|
59
|
+
if (!match) continue;
|
|
60
|
+
const key = match[1].toLowerCase();
|
|
61
|
+
const value = match[2];
|
|
62
|
+
if (key === "tolerance" && TOLERANCES.includes(unquote(value).toLowerCase())) settings.tolerance = unquote(value).toLowerCase();
|
|
63
|
+
if (key === "mute") settings.mute = listOf(value);
|
|
64
|
+
if (key === "paused") settings.paused = /^(true|yes|on)$/i.test(unquote(value));
|
|
65
|
+
}
|
|
66
|
+
return settings;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** The muted word a ping contains, or null. Whole words only, so "ci" never mutes "decision". */
|
|
70
|
+
function mutedWord(settings, ...texts) {
|
|
71
|
+
const haystack = ` ${texts.filter(Boolean).join(" ").toLowerCase().replace(/[^\p{L}\p{N}]+/gu, " ")} `;
|
|
72
|
+
for (const word of settings.mute) {
|
|
73
|
+
const needle = ` ${word.replace(/[^\p{L}\p{N}]+/gu, " ").trim()} `;
|
|
74
|
+
if (needle.trim() !== "" && haystack.includes(needle)) return word;
|
|
75
|
+
}
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Why a ping is held rather than texted, or null when it goes. Decided here
|
|
81
|
+
* from the person's own settings, never by the agent asking.
|
|
82
|
+
*/
|
|
83
|
+
function heldBecause(settings, { urgency, message, why, from }) {
|
|
84
|
+
if (settings.paused) return "paused";
|
|
85
|
+
if (!LETS_THROUGH[settings.tolerance].has(urgency)) return `held: ${settings.tolerance}`;
|
|
86
|
+
if (urgency !== "emergency") {
|
|
87
|
+
const word = mutedWord(settings, message, why, from);
|
|
88
|
+
if (word !== null) return `muted: ${word}`;
|
|
89
|
+
}
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** One line, no Markdown that could fake a log line, within `max`. */
|
|
94
|
+
function oneLine(text, max) {
|
|
95
|
+
const flat = String(text ?? "")
|
|
96
|
+
.replace(/[\u0000-\u001f\u007f\u200b-\u200f\u202a-\u202e\u2066-\u2069]/g, " ")
|
|
97
|
+
.replace(/\s+/g, " ")
|
|
98
|
+
.replace(/\*\*/g, "")
|
|
99
|
+
.trim();
|
|
100
|
+
return flat.length > max ? `${flat.slice(0, max - 1)}…` : flat;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** A short id for one ping: what the log marks texted. */
|
|
104
|
+
function pingId() {
|
|
105
|
+
const bytes = crypto.getRandomValues(new Uint8Array(6));
|
|
106
|
+
return `p_${[...bytes].map((b) => b.toString(16).padStart(2, "0")).join("")}`;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** Today's log: `tex/attention/2026-10-17.md`, dated in their zone. */
|
|
110
|
+
function attentionPath(now, timeZone) {
|
|
111
|
+
return `${ATTENTION_FOLDER}/${dayOf(now, timeZone)}.md`;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function attentionHeading(now, timeZone) {
|
|
115
|
+
return (
|
|
116
|
+
`# Agents asking for your attention, ${longDate(now, timeZone)}\n\n` +
|
|
117
|
+
"Every time one of your agents asked Tex to text you, and what became of it. " +
|
|
118
|
+
`Change how much you hear in \`${ATTENTION_SETTINGS_PATH}\` (\`tolerance: emergencies\`, \`strict\` or \`relaxed\`, ` +
|
|
119
|
+
"`mute:` words, `paused: true`), or just tell Tex.\n"
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** What became of a ping, as the log says it. `waiting` is the one delivery looks for. */
|
|
124
|
+
const WAITING = "waiting";
|
|
125
|
+
|
|
126
|
+
/** One ping's part of the day's log. */
|
|
127
|
+
function attentionEntry({ id, now, timeZone, from, urgency, message, why, status }) {
|
|
128
|
+
const lines = [
|
|
129
|
+
`## ${clock(now, timeZone)} · ${oneLine(from, 60)}`,
|
|
130
|
+
"",
|
|
131
|
+
`**Ping:** ${id} · ${urgency} · ${status}`,
|
|
132
|
+
`**Message:** ${message}`,
|
|
133
|
+
];
|
|
134
|
+
if (why) lines.push(`**Why:** ${why}`);
|
|
135
|
+
return `${lines.join("\n")}\n`;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
module.exports = { ATTENTION_FOLDER, ATTENTION_SETTINGS_PATH, URGENCIES, TOLERANCES, DEFAULT_TOLERANCE, MAX_MESSAGE_CHARS, MAX_WHY_CHARS, readAttentionSettings, mutedWord, heldBecause, oneLine, pingId, attentionPath, attentionHeading, WAITING, attentionEntry };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Types for `attention.cjs`; see that file. */
|
|
2
|
+
|
|
3
|
+
export type AttentionSettings = { tolerance: string; mute: string[]; paused: boolean };
|
|
4
|
+
|
|
5
|
+
export declare const ATTENTION_FOLDER: string;
|
|
6
|
+
export declare const ATTENTION_SETTINGS_PATH: string;
|
|
7
|
+
export declare const URGENCIES: string[];
|
|
8
|
+
export declare const TOLERANCES: string[];
|
|
9
|
+
export declare const DEFAULT_TOLERANCE: string;
|
|
10
|
+
export declare const MAX_MESSAGE_CHARS: number;
|
|
11
|
+
export declare const MAX_WHY_CHARS: number;
|
|
12
|
+
export declare const WAITING: string;
|
|
13
|
+
export declare function readAttentionSettings(text: unknown): AttentionSettings;
|
|
14
|
+
export declare function mutedWord(settings: AttentionSettings, ...texts: unknown[]): string | null;
|
|
15
|
+
export declare function heldBecause(settings: AttentionSettings, ping: { urgency: string; message?: string; why?: string; from?: string }): string | null;
|
|
16
|
+
export declare function oneLine(text: unknown, max: number): string;
|
|
17
|
+
export declare function pingId(): string;
|
|
18
|
+
export declare function attentionPath(now: number, timeZone: string): string;
|
|
19
|
+
export declare function attentionHeading(now: number, timeZone: string): string;
|
|
20
|
+
export declare function attentionEntry(entry: { id: string; now: number; timeZone: string; from: string; urgency: string; message: string; why?: string; status: string }): string;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The hash a take-over link's browser is watched by (`handback.js`): a SHA-256 of the browser's tag under its own
|
|
3
|
+
* prefix, so the watch names nobody. The Worker and the gateway both derive it from this one function.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/** The hex SHA-256 of a browser's tag, or null for anything that isn't one. */
|
|
7
|
+
async function browserHash(tag) {
|
|
8
|
+
if (typeof tag !== "string" || !/^[0-9a-f]{64}$/.test(tag)) return null;
|
|
9
|
+
const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(`browser-handback:${tag}`));
|
|
10
|
+
return [...new Uint8Array(digest)].map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
module.exports = { browserHash };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TEX'S BROWSER TAGS: which Browserbase browser is whose.
|
|
3
|
+
*
|
|
4
|
+
* Tex finds a person's (or a group chat's) browser again by this tag, and
|
|
5
|
+
* Context checks it before typing a saved login or card into that browser
|
|
6
|
+
* (`apps/mcp/src/tools/vaultType.js`), so both sides make it the same way.
|
|
7
|
+
* Made from the person's id and the deployment's `GATEWAY_SECRET`, never
|
|
8
|
+
* from a request; never sent to a model.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/** The person's browser tag, or null when this deployment cannot make one. */
|
|
12
|
+
async function browserOwner(env, userId) {
|
|
13
|
+
const secret = typeof env?.GATEWAY_SECRET === "string" ? env.GATEWAY_SECRET : "";
|
|
14
|
+
if (!secret || typeof userId !== "string" || !userId) return null;
|
|
15
|
+
const key = await crypto.subtle.importKey("raw", new TextEncoder().encode(secret), { name: "HMAC", hash: "SHA-256" }, false, ["sign"]);
|
|
16
|
+
const mac = await crypto.subtle.sign("HMAC", key, new TextEncoder().encode(`tex-browser:${userId}`));
|
|
17
|
+
return [...new Uint8Array(mac)].map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* A group chat's browser tag (the owner, 2026-10-24): one browser per chat and
|
|
22
|
+
* set of people in it, so a sign-in code texted after Tex asks for it lands in
|
|
23
|
+
* the same browser, and somebody added to the chat gets a new one. Its own
|
|
24
|
+
* label, so it never equals any person's tag.
|
|
25
|
+
*/
|
|
26
|
+
async function groupBrowserOwner(env, group) {
|
|
27
|
+
if (typeof group?.key !== "string" || !group.key || typeof group?.members !== "string" || !group.members) return null;
|
|
28
|
+
return await browserOwner(env, `group:${group.key}:${group.members}`);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
module.exports = { browserOwner, groupBrowserOwner };
|