@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
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tex's own settings notes in a person's `tex/` folder (`tex/heartbeat.md`, `tex/housekeeping.md`, `tex/dreams.md`,
|
|
3
|
+
* `tex/attention.md`, ...), read and changed through one door: `call(name, args)`, an MCP tool call
|
|
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.
|
|
6
|
+
* Note text is never returned in an error: an error is one fixed word.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const { frontMatter } = require("../texShared/routines.cjs");
|
|
10
|
+
|
|
11
|
+
/** Switches off Tex's daily tidy of their workspace. */
|
|
12
|
+
const HOUSEKEEPING_SETTINGS_PATH = "tex/housekeeping.md";
|
|
13
|
+
/** Switches off the nightly rewrite of About me; the summaries of their days still run. */
|
|
14
|
+
const DREAMS_SETTINGS_PATH = "tex/dreams.md";
|
|
15
|
+
|
|
16
|
+
/** Whether a settings note's front matter says `paused: yes` (or true, on). A note without front matter is on. */
|
|
17
|
+
function switchedOff(text) {
|
|
18
|
+
const lines = String(text ?? "").replace(/^\uFEFF/, "").split(/\r?\n/);
|
|
19
|
+
if (lines[0]?.trim() !== "---") return false;
|
|
20
|
+
for (const line of lines.slice(1)) {
|
|
21
|
+
if (line.trim() === "---" || line.trim() === "...") return false;
|
|
22
|
+
const match = /^\s*paused\s*:\s*(.+?)\s*$/i.exec(line);
|
|
23
|
+
if (match) return /^(true|yes|on)$/i.test(match[1].replace(/^["']|["']$/g, ""));
|
|
24
|
+
}
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** The person's own check-in settings (`agent/checkIns.js`). */
|
|
29
|
+
const HEARTBEAT_SETTINGS_PATH = "tex/heartbeat.md";
|
|
30
|
+
|
|
31
|
+
const fail = (error) => ({ ok: false, error });
|
|
32
|
+
|
|
33
|
+
/** `@slug` for a context name, as the gateway's tools address one. */
|
|
34
|
+
function atName(name) {
|
|
35
|
+
const text = String(name ?? "").trim();
|
|
36
|
+
return text.startsWith("@") ? text : `@${text}`;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** The `context` argument for a call, or nothing for the caller's own workspace. */
|
|
40
|
+
function ctx(context) {
|
|
41
|
+
return typeof context === "string" && context !== "" ? { context: atName(context) } : {};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function textOf(result) {
|
|
45
|
+
return (Array.isArray(result?.content) ? result.content : [])
|
|
46
|
+
.map((part) => (typeof part?.text === "string" ? part.text : ""))
|
|
47
|
+
.join("\n");
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** A write's refusal as one fixed word. Its own text (a conflict carries the note) is never passed on. */
|
|
51
|
+
function refusalOf(result) {
|
|
52
|
+
const head = textOf(result).split(/[:\n(]/, 1)[0].trim().toLowerCase();
|
|
53
|
+
if (head.startsWith("conflict")) return "changed";
|
|
54
|
+
if (head.startsWith("permission denied")) return "denied";
|
|
55
|
+
return "failed";
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* A note read through the door: `{ etag, note, moved }`, where `note` is the
|
|
60
|
+
* whole note below the header lines. Null when it can't be read, is missing,
|
|
61
|
+
* or has moved (a moved note is not the one that was asked for).
|
|
62
|
+
*/
|
|
63
|
+
async function readNote(call, path, context) {
|
|
64
|
+
let result;
|
|
65
|
+
try {
|
|
66
|
+
result = await call("read_note", { path, ...ctx(context) });
|
|
67
|
+
} catch {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
if (result?.isError === true) return null;
|
|
71
|
+
const text = textOf(result);
|
|
72
|
+
const split = text.indexOf("\n\n");
|
|
73
|
+
const header = split === -1 ? text : text.slice(0, split);
|
|
74
|
+
if (/^moved_from:/m.test(header)) return null;
|
|
75
|
+
const etag = /^etag: (.+)$/m.exec(header)?.[1]?.trim() || null;
|
|
76
|
+
return { etag, note: split === -1 ? "" : text.slice(split + 2) };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Write `content` to `path`, refusing a stale etag. `expectedEtag` null creates a new note. */
|
|
80
|
+
async function writeNote(call, path, content, expectedEtag, context) {
|
|
81
|
+
const args = { path, content, ...(expectedEtag ? { expected_etag: expectedEtag } : {}), ...ctx(context) };
|
|
82
|
+
let result;
|
|
83
|
+
try {
|
|
84
|
+
result = await call("write_note", args);
|
|
85
|
+
} catch {
|
|
86
|
+
return fail("failed");
|
|
87
|
+
}
|
|
88
|
+
return result?.isError === true ? fail(refusalOf(result)) : { ok: true };
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Retract a note into the archive, the gateway's removal (`archive_note`, as `routine.js` `stopRoutine` uses it). */
|
|
92
|
+
async function archiveNote(call, path, expectedEtag, context) {
|
|
93
|
+
let result;
|
|
94
|
+
try {
|
|
95
|
+
result = await call("archive_note", { path, expected_etag: expectedEtag, ...ctx(context) });
|
|
96
|
+
} catch {
|
|
97
|
+
return fail("failed");
|
|
98
|
+
}
|
|
99
|
+
return result?.isError === true ? fail(refusalOf(result)) : { ok: true };
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** A note split into its front matter lines (null when it has none) and its body. */
|
|
103
|
+
function splitNote(text) {
|
|
104
|
+
const raw = String(text ?? "").replace(/^\uFEFF/, "");
|
|
105
|
+
const lines = raw.split("\n");
|
|
106
|
+
if (lines[0]?.trim() === "---") {
|
|
107
|
+
for (let i = 1; i < lines.length; i++) {
|
|
108
|
+
const line = lines[i].trim();
|
|
109
|
+
if (line === "---" || line === "...") return { front: lines.slice(1, i), body: lines.slice(i + 1).join("\n") };
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return { front: null, body: raw };
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function joinNote(front, body) {
|
|
116
|
+
return front === null || front.length === 0 ? body : `---\n${front.join("\n")}\n---\n${body}`;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** The front matter lines with `key` set to `value` (replacing it in place), or removed when `value` is null. */
|
|
120
|
+
function setKey(front, key, value) {
|
|
121
|
+
const same = new RegExp(`^${key}\\s*:`, "i");
|
|
122
|
+
const out = [];
|
|
123
|
+
let placed = false;
|
|
124
|
+
for (const line of front) {
|
|
125
|
+
if (!same.test(line.trim())) {
|
|
126
|
+
out.push(line);
|
|
127
|
+
} else if (value !== null && !placed) {
|
|
128
|
+
out.push(`${key}: ${value}`);
|
|
129
|
+
placed = true;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (value !== null && !placed) out.push(`${key}: ${value}`);
|
|
133
|
+
return out;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** The note's text with one front matter key set (or removed); a note with no front matter gains one. */
|
|
137
|
+
function withFrontKey(text, key, value) {
|
|
138
|
+
const note = splitNote(text);
|
|
139
|
+
return joinNote(setKey(note.front ?? [], key, value), note.body);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** The check-in settings (`tex/heartbeat.md`): paused, looks at, quiet hours. Defaults when the note is missing. */
|
|
143
|
+
async function readCheckinSettings(call) {
|
|
144
|
+
const read = await readNote(call, HEARTBEAT_SETTINGS_PATH, null);
|
|
145
|
+
if (read === null) return { looksAt: [], paused: false };
|
|
146
|
+
const fields = frontMatter(read.note);
|
|
147
|
+
const paused = /^(true|yes|on)$/i.test(String(fields.paused ?? "").replace(/^["']|["']$/g, "").trim());
|
|
148
|
+
const looks = fields["looks-at"] ?? fields.looks ?? fields.looks_at;
|
|
149
|
+
const looksAt = typeof looks === "string" ? looks.replace(/^\[|\]$/g, "").split(/\s*,\s*/).map((word) => word.trim()).filter(Boolean) : [];
|
|
150
|
+
const quiet = fields["quiet-hours"] ?? fields.quiet ?? fields.quiet_hours;
|
|
151
|
+
return { looksAt, paused, ...(typeof quiet === "string" && quiet.trim() !== "" ? { quietHours: quiet.trim() } : {}) };
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Tex's own jobs the person can switch off (`agent/texSwitches.js`): the daily
|
|
156
|
+
* tidy and the nightly rewrite of About me, each on unless its note says
|
|
157
|
+
* `paused: yes`. The same switch Tex flips from a text.
|
|
158
|
+
*/
|
|
159
|
+
const SWITCH_PATHS = Object.freeze({ housekeeping: HOUSEKEEPING_SETTINGS_PATH, dreams: DREAMS_SETTINGS_PATH });
|
|
160
|
+
|
|
161
|
+
/** `{ housekeeping, dreams }`, each true when on. A note that is missing or can't be read is on. */
|
|
162
|
+
async function readSwitches(call) {
|
|
163
|
+
const on = async (path) => !switchedOff((await readNote(call, path, null))?.note ?? "");
|
|
164
|
+
const [housekeeping, dreams] = await Promise.all([on(SWITCH_PATHS.housekeeping), on(SWITCH_PATHS.dreams)]);
|
|
165
|
+
return { housekeeping, dreams };
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** Switch one of Tex's own jobs on or off: `paused: no` or `yes` in its note, made when it is missing. */
|
|
169
|
+
async function switchSet(call, name, on) {
|
|
170
|
+
const path = Object.hasOwn(SWITCH_PATHS, name) ? SWITCH_PATHS[name] : null;
|
|
171
|
+
if (path === null || typeof on !== "boolean") return fail("invalid");
|
|
172
|
+
return await frontSet(call, path, "paused", on ? "no" : "yes");
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* One front matter key of one of Tex's own settings notes in the person's `tex/` folder (`tex/heartbeat.md`,
|
|
177
|
+
* `tex/attention.md`, ...), set to `value` or removed with null; the note is made when it is missing. For the Tex page's
|
|
178
|
+
* switches and for a setting changed by text (`agent/settingsTools.js`).
|
|
179
|
+
*/
|
|
180
|
+
async function frontSet(call, path, key, value) {
|
|
181
|
+
if (typeof path !== "string" || !/^tex\/[a-z-]+\.md$/.test(path)) return fail("invalid");
|
|
182
|
+
let result;
|
|
183
|
+
try {
|
|
184
|
+
result = await call("read_note", { path });
|
|
185
|
+
} catch {
|
|
186
|
+
return fail("failed");
|
|
187
|
+
}
|
|
188
|
+
const missing = result?.isError === true && /^not found\b/i.test(textOf(result).trim());
|
|
189
|
+
if (result?.isError === true && !missing) return fail("failed");
|
|
190
|
+
const read = missing ? { etag: null, note: "" } : await readNote(call, path, null);
|
|
191
|
+
if (read === null || (!missing && !read.etag)) return fail("no_etag");
|
|
192
|
+
return writeNote(call, path, withFrontKey(read.note, key, value), read.etag, null);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
module.exports = {
|
|
196
|
+
HEARTBEAT_SETTINGS_PATH,
|
|
197
|
+
HOUSEKEEPING_SETTINGS_PATH,
|
|
198
|
+
DREAMS_SETTINGS_PATH,
|
|
199
|
+
SWITCH_PATHS,
|
|
200
|
+
switchedOff,
|
|
201
|
+
fail,
|
|
202
|
+
atName,
|
|
203
|
+
ctx,
|
|
204
|
+
textOf,
|
|
205
|
+
refusalOf,
|
|
206
|
+
readNote,
|
|
207
|
+
writeNote,
|
|
208
|
+
archiveNote,
|
|
209
|
+
splitNote,
|
|
210
|
+
joinNote,
|
|
211
|
+
setKey,
|
|
212
|
+
withFrontKey,
|
|
213
|
+
readCheckinSettings,
|
|
214
|
+
readSwitches,
|
|
215
|
+
switchSet,
|
|
216
|
+
frontSet,
|
|
217
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** Types for `settingsNotes.cjs`; see that file. */
|
|
2
|
+
|
|
3
|
+
type Call = (name: string, args: Record<string, unknown>) => Promise<any>;
|
|
4
|
+
type Done = { ok: true } | { ok: false; error: string };
|
|
5
|
+
|
|
6
|
+
export declare const HEARTBEAT_SETTINGS_PATH: string;
|
|
7
|
+
export declare const HOUSEKEEPING_SETTINGS_PATH: string;
|
|
8
|
+
export declare const DREAMS_SETTINGS_PATH: string;
|
|
9
|
+
export declare const SWITCH_PATHS: Readonly<{ housekeeping: string; dreams: string }>;
|
|
10
|
+
export declare function switchedOff(text: unknown): boolean;
|
|
11
|
+
export declare function fail(error: string): { ok: false; error: string };
|
|
12
|
+
export declare function atName(name: unknown): string;
|
|
13
|
+
export declare function ctx(context: unknown): { context?: string };
|
|
14
|
+
export declare function textOf(result: unknown): string;
|
|
15
|
+
export declare function refusalOf(result: unknown): string;
|
|
16
|
+
export declare function readNote(call: Call, path: string, context: string | null): Promise<{ etag: string | null; note: string } | null>;
|
|
17
|
+
export declare function writeNote(call: Call, path: string, content: string, expectedEtag: string | null, context: string | null): Promise<Done>;
|
|
18
|
+
export declare function archiveNote(call: Call, path: string, expectedEtag: string, context: string | null): Promise<Done>;
|
|
19
|
+
export declare function splitNote(text: unknown): { front: string[] | null; body: string };
|
|
20
|
+
export declare function joinNote(front: string[] | null, body: string): string;
|
|
21
|
+
export declare function setKey(front: string[], key: string, value: string | null): string[];
|
|
22
|
+
export declare function withFrontKey(text: string, key: string, value: string | null): string;
|
|
23
|
+
export declare function readCheckinSettings(call: Call): Promise<{ looksAt: string[]; paused: boolean; quietHours?: string }>;
|
|
24
|
+
export declare function readSwitches(call: Call): Promise<{ housekeeping: boolean; dreams: boolean }>;
|
|
25
|
+
export declare function switchSet(call: Call, name: string, on: boolean): Promise<Done>;
|
|
26
|
+
export declare function frontSet(call: Call, path: string, key: string, value: string | null): Promise<Done>;
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* "SEND" TO AN EMAIL TEX SHOWED IS THE YES TO THAT COPY (Training, trial-hire 123, 2026-11-19).
|
|
4
|
+
*
|
|
5
|
+
* Tex showed John the whole email in its text and asked "Send?"; John said "send". Two things went wrong, both here:
|
|
6
|
+
*
|
|
7
|
+
* - "Send?" was not read as an offer (`claimCheck.js` `offersAHeldChange` knows "Want me to send it?", "Say yes and
|
|
8
|
+
* I'll send it", a To:/Subject: preview), so John's "send" agreed to nothing (`session.egress.liked` stayed unset)
|
|
9
|
+
* and the email could only be held for a second 👍. `lastShownSend` reads such a text as the words they agreed to.
|
|
10
|
+
* - Tex then wrote the email again in other words before calling send_email, and the Mail checker, reading John's
|
|
11
|
+
* "send" against a copy he had never seen, refused it. Their yes covers the copy they read and nothing else, so a
|
|
12
|
+
* rewrite is sent back to Tex once with the copy they saw (`shownCopyOf`), to call again with exactly that.
|
|
13
|
+
*
|
|
14
|
+
* And the recipient: Tex named it in an earlier text of the same ask ("Send to bram.visser@example.com on his
|
|
15
|
+
* thread?"), and later showed only the reworded body. `recipientsShown` finds every recipient in Tex's own recent
|
|
16
|
+
* texts; the email then goes at once only when the Mail checker, reading the same texts, says they asked for it, and
|
|
17
|
+
* Tex's own texts lately held the body word for word (`emailShown`, below; 2026-11-26).
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
const { folded } = require("./folded.cjs");
|
|
21
|
+
|
|
22
|
+
/** A text that ends by asking whether to send: "Send?", "Send it? 👍 or 👎?", "Send to bram@x.com on his thread?". */
|
|
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
|
+
|
|
25
|
+
/** Whether Tex's text ends by asking whether to send what it showed. */
|
|
26
|
+
function asksToSend(text) {
|
|
27
|
+
return SEND_ASK.test(String(text ?? "").trimEnd());
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Tex's last text when it ends by asking "Send?" (`asksToSend`); null otherwise. */
|
|
31
|
+
function lastShownSend(history) {
|
|
32
|
+
const said = (Array.isArray(history) ? history : []).filter((turn) => turn?.role === "assistant" && typeof turn.text === "string").at(-1)?.text;
|
|
33
|
+
return typeof said === "string" && asksToSend(said) ? said : null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const wordsOf = (text) => folded(String(text ?? "")).split(" ").filter(Boolean);
|
|
37
|
+
|
|
38
|
+
/** The share of either text's distinct words the other has too, the smaller of the two. */
|
|
39
|
+
function overlap(a, b) {
|
|
40
|
+
const [x, y] = [new Set(wordsOf(a)), new Set(wordsOf(b))];
|
|
41
|
+
if (x.size === 0 || y.size === 0) return 0;
|
|
42
|
+
const both = [...x].filter((word) => y.has(word)).length;
|
|
43
|
+
return Math.min(both / x.size, both / y.size);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** At least this much of a shown copy must be the email's own words for it to be the same email. */
|
|
47
|
+
const SAME_EMAIL = 0.6;
|
|
48
|
+
/** A copy shorter than this is not an email anybody approved by reading it. */
|
|
49
|
+
const MIN_COPY = 40;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The copy of this email they were shown, when it differs from `body`: the lines of `liked` from the one that opens
|
|
53
|
+
* as the body opens (its first three words) to the one that ends as it ends (its last two), when those lines share
|
|
54
|
+
* most of their words with the body. Null when they saw this body word for word, or nothing like it.
|
|
55
|
+
*/
|
|
56
|
+
function shownCopyOf(liked, body) {
|
|
57
|
+
if (typeof liked !== "string" || typeof body !== "string") return null;
|
|
58
|
+
const words = wordsOf(body);
|
|
59
|
+
if (words.length < 5) return null;
|
|
60
|
+
const opens = words.slice(0, 3).join(" ");
|
|
61
|
+
const ends = words.slice(-2).join(" ");
|
|
62
|
+
const lines = liked.split("\n");
|
|
63
|
+
const start = lines.findIndex((line) => wordsOf(line).join(" ").startsWith(opens));
|
|
64
|
+
if (start === -1) return null;
|
|
65
|
+
let end = -1;
|
|
66
|
+
// The first line that ends as it ends: a text showing two emails never runs one into the next.
|
|
67
|
+
for (let i = start; i < lines.length && end === -1; i += 1) if (` ${wordsOf(lines[i]).join(" ")}`.endsWith(` ${ends}`)) end = i;
|
|
68
|
+
if (end === -1) return null;
|
|
69
|
+
const shown = lines.slice(start, end + 1).join("\n").trim();
|
|
70
|
+
if (shown.length < MIN_COPY || overlap(shown, body) < SAME_EMAIL) return null;
|
|
71
|
+
return wordsOf(shown).join(" ") === words.join(" ") ? null : shown;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** How many of the latest history turns are read for a recipient Tex named: the Mail checker's own window. */
|
|
75
|
+
const SHOWN_TURNS = 12;
|
|
76
|
+
|
|
77
|
+
/** Whether Tex itself named every recipient in its texts among the latest `SHOWN_TURNS` turns. */
|
|
78
|
+
function recipientsShown(history, recipients) {
|
|
79
|
+
const said = (Array.isArray(history) ? history : [])
|
|
80
|
+
.slice(-SHOWN_TURNS)
|
|
81
|
+
.filter((turn) => turn?.role === "assistant" && typeof turn.text === "string")
|
|
82
|
+
.map((turn) => turn.text.toLowerCase())
|
|
83
|
+
.join("\n");
|
|
84
|
+
const list = Array.isArray(recipients) ? recipients.map((r) => String(r).trim().toLowerCase()).filter(Boolean) : [];
|
|
85
|
+
// Whole addresses only: "ram@example.com" is not named by "bram@example.com".
|
|
86
|
+
const named = (address) => new RegExp(`(?<![a-z0-9._%+-])${address.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}(?![a-z0-9._%+-]*[a-z0-9])`).test(said);
|
|
87
|
+
return list.length > 0 && list.every(named);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/*
|
|
91
|
+
THE BODY TEX SHOWED, WHATEVER IT ASKED AROUND IT (Sayo's group email to SupaSounds, 2026-11-26). Tex showed the draft
|
|
92
|
+
and asked which Gmail to send it from; "send it from my supa email. draft is good. go ahead" agreed to nothing,
|
|
93
|
+
because only a text worded as an offer ("Send?", "Want me to send it?") counted as the words they agreed to, so the
|
|
94
|
+
gateway held the email and asked again. Whether they asked for it is the Mail checker's to say, reading their own
|
|
95
|
+
words; what was shown is a fact read here: the whole body, word for word, in one of Tex's own texts lately.
|
|
96
|
+
*/
|
|
97
|
+
/*
|
|
98
|
+
IN A GROUP, ONLY WHAT TEX SHOWED THE TAGGER (2026-11-27). The tagger's own account sends, so a copy Tex showed
|
|
99
|
+
in answer to somebody else, or put to another member by name (an offer to @cy), was never shown to them to send: a
|
|
100
|
+
text counts only when it answered the tagger's own turn (its question's last line is theirs, `groupTurn.js`
|
|
101
|
+
`groupQuestionLine`, `groupLedgerHistory.js`) and names no other member unless it names the tagger too.
|
|
102
|
+
*/
|
|
103
|
+
/*
|
|
104
|
+
WHOSE TURN IT WAS IS NOT THEIRS TO WRITE (2026-11-27). A kept group question is the chatter block, a blank line, then
|
|
105
|
+
the text that tagged Tex, each text prefixed `@who: ` (`groupLedgerHistory.js` `groupQuestion`). Reading the
|
|
106
|
+
question's last line made that prefix something a member could write: a text of @kim's ending in a line of its own,
|
|
107
|
+
`@sayo: send it`, read as @sayo's turn, so a draft Tex showed @kim counted as shown to @sayo. The prefix is the
|
|
108
|
+
first line of the last block instead, which nothing inside a text can reach. A tagging text with a blank line of its
|
|
109
|
+
own reads as nobody's and is asked about, the answer this was before a shown copy counted at all.
|
|
110
|
+
*/
|
|
111
|
+
function askedBy(question, from) {
|
|
112
|
+
const text = String(question ?? "").trimEnd();
|
|
113
|
+
const at = text.lastIndexOf("\n\n");
|
|
114
|
+
const first = (at === -1 ? text : text.slice(at + 2)).split("\n")[0] ?? "";
|
|
115
|
+
return first.startsWith(`@${from}:`) || first.startsWith(`@${from} (`);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** Whether a text names this handle whole: "@jo" is not named by "@joan". */
|
|
119
|
+
const namesHandle = (text, who) => new RegExp(`(?:^|[^a-z0-9-])@${who.replace(/[^a-z0-9-]/gi, "")}(?![a-z0-9-])`, "i").test(text);
|
|
120
|
+
|
|
121
|
+
/** Tex's texts among the latest `SHOWN_TURNS` turns that showed the person this email; in a group, only those shown to the tagger. */
|
|
122
|
+
function texTexts(history, group) {
|
|
123
|
+
const turns = (Array.isArray(history) ? history : []).slice(-SHOWN_TURNS);
|
|
124
|
+
return turns
|
|
125
|
+
.map((turn, at) => ({ turn, asked: turns.slice(0, at).findLast((before) => before?.role === "user") }))
|
|
126
|
+
.filter(({ turn }) => turn?.role === "assistant" && typeof turn.text === "string")
|
|
127
|
+
.filter(({ turn, asked }) => {
|
|
128
|
+
if (!group?.from) return true;
|
|
129
|
+
if (!askedBy(asked?.text, group.from)) return false;
|
|
130
|
+
const others = (Array.isArray(group.people) ? group.people : []).filter((who) => typeof who === "string" && who !== group.from);
|
|
131
|
+
return namesHandle(turn.text, group.from) || !others.some((who) => namesHandle(turn.text, who));
|
|
132
|
+
})
|
|
133
|
+
.map(({ turn }) => turn.text);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** A text's words with a space each side, so a run of words is found whole. */
|
|
137
|
+
const runOf = (text) => ` ${wordsOf(text).join(" ")} `;
|
|
138
|
+
|
|
139
|
+
/** The opening and closing words that name which email a later copy of it is, as `shownCopyOf` anchors on. */
|
|
140
|
+
const OPENS_WORDS = 3;
|
|
141
|
+
const ENDS_WORDS = 2;
|
|
142
|
+
|
|
143
|
+
/*
|
|
144
|
+
A LATER COPY REPLACES THE ONE IT CHANGED (2026-11-27). Tex showed a draft, they asked for its last sentence out, Tex
|
|
145
|
+
showed the shorter copy, and they said "yes send it": their go-ahead is about the copy they were shown last, and the
|
|
146
|
+
one they had just turned down is not theirs to send. The Mail checker reads a cut sentence as no contradiction, so
|
|
147
|
+
nothing else holds it. A body is therefore shown only until Tex shows the same email in other words: a text that
|
|
148
|
+
opens as the body opens and does not hold it whole.
|
|
149
|
+
*/
|
|
150
|
+
function replacedIn(texts, body, words) {
|
|
151
|
+
const said = wordsOf(body);
|
|
152
|
+
const anchors = [said.slice(0, OPENS_WORDS).join(" "), said.slice(-ENDS_WORDS).join(" ")].filter((anchor) => anchor !== "");
|
|
153
|
+
if (anchors.length === 0) return false;
|
|
154
|
+
// Either anchor: a copy may change the opening ("Dear Bram", not "Hi Bram") as readily as the words between.
|
|
155
|
+
return texts.some((text) => !runOf(text).includes(` ${words} `) && anchors.some((anchor) => runOf(text).includes(` ${anchor} `)));
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Whether one of Tex's texts among the latest `SHOWN_TURNS` turns holds this body whole, word for word, with no later
|
|
160
|
+
* text of its own showing the same email in other words (`replacedIn`).
|
|
161
|
+
*/
|
|
162
|
+
function bodyShown(history, body, group = null) {
|
|
163
|
+
if (typeof body !== "string" || body.trim().length < MIN_COPY) return false;
|
|
164
|
+
const words = wordsOf(body).join(" ");
|
|
165
|
+
if (words === "") return false;
|
|
166
|
+
const texts = texTexts(history, group);
|
|
167
|
+
const last = texts.findLastIndex((text) => runOf(text).includes(` ${words} `));
|
|
168
|
+
if (last === -1) return false;
|
|
169
|
+
return !replacedIn(texts.slice(last + 1), body, words);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Whether Tex itself showed this email lately: every recipient named and the whole body, in its own texts; in a group
|
|
174
|
+
* (`group`: `{ from, people }`), in texts that answered the tagger and were not put to somebody else.
|
|
175
|
+
*/
|
|
176
|
+
function emailShown(history, recipients, body, group = null) {
|
|
177
|
+
const shown = group?.from ? texTexts(history, group).map((text) => ({ role: "assistant", text })) : history;
|
|
178
|
+
return recipientsShown(shown, recipients) && bodyShown(history, body, group);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
module.exports = { asksToSend, lastShownSend, shownCopyOf, SHOWN_TURNS, recipientsShown, bodyShown, emailShown };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The texting clients, as the control plane names them, and how long a texting token lives.
|
|
3
|
+
*
|
|
4
|
+
* The gateway's routing and Tex both compare a session's client against these, so they are one copy for both.
|
|
5
|
+
* `machines/reach.js` and `workspaceStore/personTexting.js` re-export them.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/** The texting client, as the control plane names it (`TEXTS_CLIENT_ID`). */
|
|
9
|
+
const TEXTS_CLIENT_ID = "context_texts";
|
|
10
|
+
/** The group texting client, kept with the group predicates (`groupSession.cjs`). */
|
|
11
|
+
const { TEXTS_GROUP_CLIENT_ID } = require("./groupSession.cjs");
|
|
12
|
+
/** How long a texting token lives, as the control plane's `TEXTS_GRANT_TTL_MS`. */
|
|
13
|
+
const TEXTING_TOKEN_MS = 15 * 60 * 1000;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Tex's background runs' first-party clients, as the control plane names them (`apps/convex/functions/lib/dreams`,
|
|
17
|
+
* `heartbeats`, and the housekeeping loop). Decided by the grant. The gateway's routing tells each run's session by
|
|
18
|
+
* them, and Tex's runs are made under them, so they are one copy for both.
|
|
19
|
+
*/
|
|
20
|
+
const DREAMS_CLIENT_ID = "context_dreams";
|
|
21
|
+
const HEARTBEAT_CLIENT_ID = "context_heartbeat";
|
|
22
|
+
const HOUSEKEEPING_CLIENT_ID = "context_housekeeping";
|
|
23
|
+
|
|
24
|
+
/** Routines' runs' client, as the control plane names it (`apps/convex/functions/lib/routines/model.ts`). */
|
|
25
|
+
const ROUTINES_CLIENT_ID = "context_routines";
|
|
26
|
+
|
|
27
|
+
/**
|
|
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
|
|
30
|
+
* itself "Tex" signed as the person's Tex and held their Tex's seat on the note.
|
|
31
|
+
*/
|
|
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
|
+
|
|
34
|
+
/** The names on every job note besides its jobs (`packages/tex/gateway/agent/jobNote.js`): Tex and the advisor. */
|
|
35
|
+
const MAIL_ROSTER_NAMES = Object.freeze(["tex", "advisor"]);
|
|
36
|
+
|
|
37
|
+
/** Whether a grant's client is one of Tex's own, by the id the control plane issued. */
|
|
38
|
+
function isTexOwnClient(clientId) {
|
|
39
|
+
return typeof clientId === "string" && TEX_OWN_CLIENT_IDS.includes(clientId);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
module.exports = {
|
|
43
|
+
TEXTS_CLIENT_ID,
|
|
44
|
+
TEXTS_GROUP_CLIENT_ID,
|
|
45
|
+
TEXTING_TOKEN_MS,
|
|
46
|
+
DREAMS_CLIENT_ID,
|
|
47
|
+
HEARTBEAT_CLIENT_ID,
|
|
48
|
+
HOUSEKEEPING_CLIENT_ID,
|
|
49
|
+
ROUTINES_CLIENT_ID,
|
|
50
|
+
TEX_OWN_CLIENT_IDS,
|
|
51
|
+
MAIL_ROSTER_NAMES,
|
|
52
|
+
isTexOwnClient,
|
|
53
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Types for `texClients.cjs`; see that file for the reasons. */
|
|
2
|
+
|
|
3
|
+
export declare const TEXTS_CLIENT_ID: "context_texts";
|
|
4
|
+
export declare const TEXTS_GROUP_CLIENT_ID: "context_texts_group";
|
|
5
|
+
export declare const TEXTING_TOKEN_MS: number;
|
|
6
|
+
export declare const DREAMS_CLIENT_ID: "context_dreams";
|
|
7
|
+
export declare const HEARTBEAT_CLIENT_ID: "context_heartbeat";
|
|
8
|
+
export declare const HOUSEKEEPING_CLIENT_ID: "context_housekeeping";
|
|
9
|
+
export declare const ROUTINES_CLIENT_ID: "context_routines";
|
|
10
|
+
export declare const TEX_OWN_CLIENT_IDS: readonly string[];
|
|
11
|
+
export declare const MAIL_ROSTER_NAMES: readonly ["tex", "advisor"];
|
|
12
|
+
export declare function isTexOwnClient(clientId: unknown): boolean;
|