@leemour/max-cli 0.1.0 → 0.3.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 +28 -12
- package/dist/cache/index.d.ts.map +1 -1
- package/dist/cache/index.js +3 -0
- package/dist/cache/index.js.map +1 -1
- package/dist/cache/schema.d.ts +13 -1
- package/dist/cache/schema.d.ts.map +1 -1
- package/dist/cache/schema.js +159 -8
- package/dist/cache/schema.js.map +1 -1
- package/dist/cache/store.d.ts +115 -4
- package/dist/cache/store.d.ts.map +1 -1
- package/dist/cache/store.js +248 -27
- package/dist/cache/store.js.map +1 -1
- package/dist/client.d.ts +91 -9
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +371 -33
- package/dist/client.js.map +1 -1
- package/dist/commands/chats.d.ts.map +1 -1
- package/dist/commands/chats.js +25 -8
- package/dist/commands/chats.js.map +1 -1
- package/dist/commands/contacts.d.ts.map +1 -1
- package/dist/commands/contacts.js +51 -5
- package/dist/commands/contacts.js.map +1 -1
- package/dist/commands/context.d.ts +4 -1
- package/dist/commands/context.d.ts.map +1 -1
- package/dist/commands/context.js +4 -2
- package/dist/commands/context.js.map +1 -1
- package/dist/commands/login.d.ts +15 -0
- package/dist/commands/login.d.ts.map +1 -0
- package/dist/commands/login.js +43 -0
- package/dist/commands/login.js.map +1 -0
- package/dist/commands/logout.d.ts +10 -0
- package/dist/commands/logout.d.ts.map +1 -0
- package/dist/commands/logout.js +22 -0
- package/dist/commands/logout.js.map +1 -0
- package/dist/commands/me.d.ts +3 -0
- package/dist/commands/me.d.ts.map +1 -0
- package/dist/commands/me.js +18 -0
- package/dist/commands/me.js.map +1 -0
- package/dist/commands/messages.d.ts.map +1 -1
- package/dist/commands/messages.js +82 -3
- package/dist/commands/messages.js.map +1 -1
- package/dist/commands/paging.d.ts +41 -0
- package/dist/commands/paging.d.ts.map +1 -0
- package/dist/commands/paging.js +54 -0
- package/dist/commands/paging.js.map +1 -0
- package/dist/commands/send.d.ts +10 -0
- package/dist/commands/send.d.ts.map +1 -0
- package/dist/commands/send.js +30 -0
- package/dist/commands/send.js.map +1 -0
- package/dist/commands/session.d.ts.map +1 -1
- package/dist/commands/session.js +3 -3
- package/dist/commands/session.js.map +1 -1
- package/dist/config.d.ts +16 -2
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +15 -1
- package/dist/config.js.map +1 -1
- package/dist/domain/map.d.ts +1 -0
- package/dist/domain/map.d.ts.map +1 -1
- package/dist/domain/map.js +44 -3
- package/dist/domain/map.js.map +1 -1
- package/dist/domain/models.d.ts +54 -0
- package/dist/domain/models.d.ts.map +1 -1
- package/dist/generated/operations.generated.d.ts +1 -0
- package/dist/generated/operations.generated.d.ts.map +1 -1
- package/dist/output.d.ts +7 -4
- package/dist/output.d.ts.map +1 -1
- package/dist/output.js +8 -11
- package/dist/output.js.map +1 -1
- package/dist/program.d.ts.map +1 -1
- package/dist/program.js +4 -2
- package/dist/program.js.map +1 -1
- package/dist/protocol/connection.d.ts +10 -0
- package/dist/protocol/connection.d.ts.map +1 -1
- package/dist/protocol/connection.js +11 -3
- package/dist/protocol/connection.js.map +1 -1
- package/dist/protocol/session.d.ts +54 -0
- package/dist/protocol/session.d.ts.map +1 -0
- package/dist/protocol/session.js +57 -0
- package/dist/protocol/session.js.map +1 -0
- package/dist/rendering/messages.d.ts +19 -0
- package/dist/rendering/messages.d.ts.map +1 -0
- package/dist/rendering/messages.js +137 -0
- package/dist/rendering/messages.js.map +1 -0
- package/dist/runs/events.d.ts +1 -1
- package/dist/runs/recording.d.ts +2 -2
- package/dist/runs/recording.d.ts.map +1 -1
- package/dist/runs/recording.js +3 -3
- package/dist/runs/recording.js.map +1 -1
- package/dist/session/adopt.d.ts +22 -0
- package/dist/session/adopt.d.ts.map +1 -0
- package/dist/session/adopt.js +29 -0
- package/dist/session/adopt.js.map +1 -0
- package/dist/session/handshake.d.ts +14 -1
- package/dist/session/handshake.d.ts.map +1 -1
- package/dist/session/handshake.js +5 -5
- package/dist/session/handshake.js.map +1 -1
- package/dist/spec/operations/auth.d.ts +42 -0
- package/dist/spec/operations/auth.d.ts.map +1 -0
- package/dist/spec/operations/session.d.ts +16 -0
- package/dist/spec/operations/session.d.ts.map +1 -1
- package/dist/spec/operations/session.js +21 -1
- package/dist/spec/operations/session.js.map +1 -1
- package/dist/testing/sandbox.d.ts +2 -0
- package/dist/testing/sandbox.d.ts.map +1 -0
- package/dist/testing/sandbox.js +24 -0
- package/dist/testing/sandbox.js.map +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +9 -5
package/dist/cache/store.js
CHANGED
|
@@ -1,6 +1,43 @@
|
|
|
1
1
|
import { migrate } from "./schema.js";
|
|
2
2
|
export const openStore = ({ database, now = () => Date.now() }) => {
|
|
3
3
|
migrate(database);
|
|
4
|
+
/**
|
|
5
|
+
* **What the person typed is data, not a query.** FTS5 reads its argument as an expression, so
|
|
6
|
+
* `O'Brien` is a syntax error, `a-b` is a column that does not exist and a bare `"` never
|
|
7
|
+
* terminates — a chat whose name has an apostrophe would take the command down with it.
|
|
8
|
+
*
|
|
9
|
+
* Wrapping in double quotes makes the whole thing one literal phrase, and doubling any quote
|
|
10
|
+
* inside keeps it that way. This is the only place a MATCH argument is built; nowhere else
|
|
11
|
+
* concatenates one.
|
|
12
|
+
*/
|
|
13
|
+
const phrase = (query) => `"${query.replace(/"/g, '""')}"`;
|
|
14
|
+
/**
|
|
15
|
+
* The `WHERE` for a chat listing, built once and handed to both the page and its count.
|
|
16
|
+
*
|
|
17
|
+
* ⚠ They have to come from the same function. A page that filters and a count that does not is
|
|
18
|
+
* a `hasMore` that lies, and it lies quietly — the reader simply never sees the last page.
|
|
19
|
+
*/
|
|
20
|
+
const chatWhere = ({ query, kind }) => {
|
|
21
|
+
const clauses = [];
|
|
22
|
+
const values = [];
|
|
23
|
+
if (query !== undefined) {
|
|
24
|
+
clauses.push("c.rowid IN (SELECT rowid FROM chats_fts WHERE chats_fts MATCH ?)");
|
|
25
|
+
values.push(phrase(query));
|
|
26
|
+
}
|
|
27
|
+
if (kind !== undefined) {
|
|
28
|
+
clauses.push("c.kind = ?");
|
|
29
|
+
values.push(kind);
|
|
30
|
+
}
|
|
31
|
+
return { sql: clauses.length === 0 ? "" : ` WHERE ${clauses.join(" AND ")}`, values };
|
|
32
|
+
};
|
|
33
|
+
const peopleWhere = ({ query }) => {
|
|
34
|
+
if (query === undefined)
|
|
35
|
+
return { sql: "", values: [] };
|
|
36
|
+
return {
|
|
37
|
+
sql: " AND p.rowid IN (SELECT rowid FROM people_fts WHERE people_fts MATCH ?)",
|
|
38
|
+
values: [phrase(query)],
|
|
39
|
+
};
|
|
40
|
+
};
|
|
4
41
|
const markFetched = database.prepare("INSERT INTO fetched (kind, at) VALUES (?, ?) ON CONFLICT(kind) DO UPDATE SET at = excluded.at");
|
|
5
42
|
const fetchedAt = database.prepare("SELECT at FROM fetched WHERE kind = ?");
|
|
6
43
|
const isFresh = (kind, freshForMs) => {
|
|
@@ -14,11 +51,86 @@ export const openStore = ({ database, now = () => Date.now() }) => {
|
|
|
14
51
|
title = excluded.title, kind = excluded.kind, unread_count = excluded.unread_count,
|
|
15
52
|
last_message_at = excluded.last_message_at, participants_count = excluded.participants_count,
|
|
16
53
|
fetched_at = excluded.fetched_at, generation = chats.generation + 1`);
|
|
17
|
-
|
|
18
|
-
|
|
54
|
+
/**
|
|
55
|
+
* **`COALESCE`, not assignment, for the three names.** The same person arrives from several
|
|
56
|
+
* places — the login, `CONTACT_INFO`, a group's participant list — and not all of them carry a
|
|
57
|
+
* description or a username. Overwriting with what the latest one happened to omit would blank
|
|
58
|
+
* a name we already had, which is the one thing this table exists to prevent.
|
|
59
|
+
*/
|
|
60
|
+
const putPerson = database.prepare(`
|
|
61
|
+
INSERT INTO people (id, name, username, description, last_messaged_at, source, fetched_at)
|
|
62
|
+
VALUES (?, ?, ?, ?, NULL, ?, ?)
|
|
19
63
|
ON CONFLICT(id) DO UPDATE SET
|
|
20
|
-
name = excluded.name,
|
|
21
|
-
|
|
64
|
+
name = coalesce(excluded.name, people.name),
|
|
65
|
+
username = coalesce(excluded.username, people.username),
|
|
66
|
+
description = coalesce(excluded.description, people.description),
|
|
67
|
+
source = excluded.source, fetched_at = excluded.fetched_at`);
|
|
68
|
+
const toContact = (row) => ({
|
|
69
|
+
id: String(row.id),
|
|
70
|
+
name: row.name === null ? null : String(row.name),
|
|
71
|
+
username: row.username === null ? null : String(row.username),
|
|
72
|
+
description: row.description === null ? null : String(row.description),
|
|
73
|
+
lastMessagedAt: row.last_messaged_at === null ? null : new Date(Number(row.last_messaged_at)).toISOString(),
|
|
74
|
+
});
|
|
75
|
+
/**
|
|
76
|
+
* `NULLS LAST` spelled out as a sort key rather than as syntax: it arrived in SQLite 3.30 and
|
|
77
|
+
* this runs on whatever `node:sqlite` and `bun:sqlite` were built against.
|
|
78
|
+
*/
|
|
79
|
+
const ORDER = {
|
|
80
|
+
recent: "p.last_messaged_at IS NULL, p.last_messaged_at DESC, p.name IS NULL, p.name",
|
|
81
|
+
name: "p.name IS NULL, p.name",
|
|
82
|
+
};
|
|
83
|
+
/** People a *dialog* exists with. The join is the definition of "contact" (`NEED-105`). */
|
|
84
|
+
const CONTACTS_FROM = `
|
|
85
|
+
FROM people p
|
|
86
|
+
JOIN chat_members m ON m.person_id = p.id
|
|
87
|
+
JOIN chats c ON c.id = m.chat_id AND c.kind = 'dialog'`;
|
|
88
|
+
/**
|
|
89
|
+
* The default order, derived from the dialogs rather than accumulated as they arrive.
|
|
90
|
+
*
|
|
91
|
+
* It has to be a recompute rather than "raise it as each chat lands": a person's row often does
|
|
92
|
+
* not exist yet when their chat does, because the login names six people and the other sixteen
|
|
93
|
+
* come back from a request sent afterwards. An `UPDATE` at that moment reaches nobody.
|
|
94
|
+
*
|
|
95
|
+
* Derived from what we hold, so it is correct however the writes interleave, and cheap — one
|
|
96
|
+
* indexed join over the people who are in a dialog, once per write rather than per listing.
|
|
97
|
+
*/
|
|
98
|
+
const refreshRecency = () => {
|
|
99
|
+
database.exec(`
|
|
100
|
+
UPDATE people SET last_messaged_at = (
|
|
101
|
+
SELECT MAX(c.last_message_at) FROM chat_members m
|
|
102
|
+
JOIN chats c ON c.id = m.chat_id AND c.kind = 'dialog'
|
|
103
|
+
WHERE m.person_id = people.id
|
|
104
|
+
)
|
|
105
|
+
WHERE id IN (
|
|
106
|
+
SELECT m.person_id FROM chat_members m
|
|
107
|
+
JOIN chats c ON c.id = m.chat_id AND c.kind = 'dialog'
|
|
108
|
+
)`);
|
|
109
|
+
};
|
|
110
|
+
const upsertPeople = (people, source, at) => {
|
|
111
|
+
for (const person of people) {
|
|
112
|
+
if (!person.id)
|
|
113
|
+
continue;
|
|
114
|
+
putPerson.run(person.id, person.name, person.username, person.description, source, at);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* SQLite has no nested transactions and this is the only writer that needs one, so a plain
|
|
119
|
+
* `BEGIN` is enough. The rollback is what item 4 of the plan turns on: a marker saved over rows
|
|
120
|
+
* that were never written makes the next login ask for changes since data we do not have, and
|
|
121
|
+
* nothing downstream ever notices.
|
|
122
|
+
*/
|
|
123
|
+
const inTransaction = (body) => {
|
|
124
|
+
database.exec("BEGIN");
|
|
125
|
+
try {
|
|
126
|
+
body();
|
|
127
|
+
database.exec("COMMIT");
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
database.exec("ROLLBACK");
|
|
131
|
+
throw error;
|
|
132
|
+
}
|
|
133
|
+
};
|
|
22
134
|
/**
|
|
23
135
|
* **Compares MAX's clock, never ours.** `update_time` is what MAX sets on an edit and is `NULL`
|
|
24
136
|
* on a message nobody has changed (measured 2026-09-20).
|
|
@@ -33,11 +145,12 @@ export const openStore = ({ database, now = () => Date.now() }) => {
|
|
|
33
145
|
* the point of it.
|
|
34
146
|
*/
|
|
35
147
|
const putMessage = database.prepare(`
|
|
36
|
-
INSERT INTO messages (chat_id, id, sender_id, sender_name, time, update_time, text, outgoing, attachments, fetched_at)
|
|
37
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
148
|
+
INSERT INTO messages (chat_id, id, sender_id, sender_name, time, update_time, text, outgoing, attachments, link, fetched_at)
|
|
149
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
38
150
|
ON CONFLICT(chat_id, id) DO UPDATE SET
|
|
39
151
|
sender_name = excluded.sender_name, update_time = excluded.update_time, text = excluded.text,
|
|
40
|
-
outgoing = excluded.outgoing, attachments = excluded.attachments,
|
|
152
|
+
outgoing = excluded.outgoing, attachments = excluded.attachments, link = excluded.link,
|
|
153
|
+
fetched_at = excluded.fetched_at
|
|
41
154
|
WHERE coalesce(excluded.update_time, 0) >= coalesce(messages.update_time, 0)`);
|
|
42
155
|
const toChat = (row) => ({
|
|
43
156
|
id: String(row.id),
|
|
@@ -57,6 +170,11 @@ export const openStore = ({ database, now = () => Date.now() }) => {
|
|
|
57
170
|
text: String(row.text),
|
|
58
171
|
outgoing: row.outgoing === null ? null : row.outgoing === 1,
|
|
59
172
|
attachments: JSON.parse(String(row.attachments)),
|
|
173
|
+
replyTo: null,
|
|
174
|
+
forwardedFrom: null,
|
|
175
|
+
...(row.link === null || row.link === undefined
|
|
176
|
+
? {}
|
|
177
|
+
: JSON.parse(String(row.link))),
|
|
60
178
|
});
|
|
61
179
|
const epoch = (iso) => (iso === null ? null : new Date(iso).getTime());
|
|
62
180
|
return {
|
|
@@ -66,6 +184,18 @@ export const openStore = ({ database, now = () => Date.now() }) => {
|
|
|
66
184
|
return undefined;
|
|
67
185
|
return database.prepare("SELECT * FROM chats ORDER BY last_message_at DESC").all().map(toChat);
|
|
68
186
|
},
|
|
187
|
+
page: ({ limit, offset, query, kind }) => {
|
|
188
|
+
const where = chatWhere({ query, kind });
|
|
189
|
+
return database
|
|
190
|
+
.prepare(`SELECT c.* FROM chats c${where.sql} ORDER BY c.last_message_at DESC LIMIT ? OFFSET ?`)
|
|
191
|
+
.all(...where.values, limit, offset)
|
|
192
|
+
.map(toChat);
|
|
193
|
+
},
|
|
194
|
+
count: ({ query, kind } = {}) => {
|
|
195
|
+
const where = chatWhere({ query, kind });
|
|
196
|
+
const row = database.prepare(`SELECT COUNT(*) AS n FROM chats c${where.sql}`).get(...where.values);
|
|
197
|
+
return Number(row?.n ?? 0);
|
|
198
|
+
},
|
|
69
199
|
write: (chats) => {
|
|
70
200
|
const at = now();
|
|
71
201
|
for (const chat of chats) {
|
|
@@ -74,27 +204,73 @@ export const openStore = ({ database, now = () => Date.now() }) => {
|
|
|
74
204
|
markFetched.run("chats", at);
|
|
75
205
|
},
|
|
76
206
|
},
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
return undefined;
|
|
207
|
+
people: {
|
|
208
|
+
contacts: ({ order, limit, offset, query }) => {
|
|
209
|
+
const where = peopleWhere({ query });
|
|
81
210
|
return database
|
|
82
|
-
.prepare(
|
|
83
|
-
.all()
|
|
84
|
-
.map(
|
|
85
|
-
id: String(row.id),
|
|
86
|
-
name: row.name === null ? null : String(row.name),
|
|
87
|
-
username: row.username === null ? null : String(row.username),
|
|
88
|
-
description: row.description === null ? null : String(row.description),
|
|
89
|
-
}));
|
|
211
|
+
.prepare(`SELECT DISTINCT p.* ${CONTACTS_FROM}${where.sql} ORDER BY ${ORDER[order]} LIMIT ? OFFSET ?`)
|
|
212
|
+
.all(...where.values, limit, offset)
|
|
213
|
+
.map(toContact);
|
|
90
214
|
},
|
|
91
|
-
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
215
|
+
countContacts: ({ query } = {}) => {
|
|
216
|
+
const where = peopleWhere({ query });
|
|
217
|
+
const row = database
|
|
218
|
+
.prepare(`SELECT COUNT(DISTINCT p.id) AS n ${CONTACTS_FROM}${where.sql}`)
|
|
219
|
+
.get(...where.values);
|
|
220
|
+
return Number(row?.n ?? 0);
|
|
97
221
|
},
|
|
222
|
+
page: ({ order, limit, offset }) => database
|
|
223
|
+
.prepare(`SELECT p.* FROM people p ORDER BY ${ORDER[order]} LIMIT ? OFFSET ?`)
|
|
224
|
+
.all(limit, offset)
|
|
225
|
+
.map(toContact),
|
|
226
|
+
upsert: (people, source) => upsertPeople(people, source, now()),
|
|
227
|
+
refreshRecency,
|
|
228
|
+
count: () => Number(database.prepare("SELECT COUNT(*) AS n FROM people").get()?.n ?? 0),
|
|
229
|
+
chatsWith: (personId) => database
|
|
230
|
+
.prepare("SELECT chat_id FROM chat_members WHERE person_id = ?")
|
|
231
|
+
.all(personId)
|
|
232
|
+
.map((row) => String(row.chat_id)),
|
|
233
|
+
},
|
|
234
|
+
syncMarker: () => database.prepare("SELECT marker FROM sync_marker WHERE id = 1").get()
|
|
235
|
+
?.marker,
|
|
236
|
+
mergeDelta: ({ chats, people, members, marker }) => {
|
|
237
|
+
const at = now();
|
|
238
|
+
const summary = { known: 0, added: 0, changed: 0 };
|
|
239
|
+
inTransaction(() => {
|
|
240
|
+
const known = database.prepare("SELECT 1 FROM people WHERE id = ?");
|
|
241
|
+
for (const person of people) {
|
|
242
|
+
if (!person.id)
|
|
243
|
+
continue;
|
|
244
|
+
if (known.get(person.id))
|
|
245
|
+
summary.changed += 1;
|
|
246
|
+
else
|
|
247
|
+
summary.added += 1;
|
|
248
|
+
}
|
|
249
|
+
for (const chat of chats) {
|
|
250
|
+
putChat.run(chat.id, chat.title, chat.kind, chat.unreadCount, epoch(chat.lastMessageAt), chat.participantsCount, at);
|
|
251
|
+
}
|
|
252
|
+
upsertPeople(people, "login", at);
|
|
253
|
+
// Replaced per chat, never globally: MAX restates a chat's whole membership whenever it
|
|
254
|
+
// sends that chat, so a member missing from it has left — while a *person* missing from a
|
|
255
|
+
// delta is merely unchanged, which after the first login is every person we know.
|
|
256
|
+
for (const [chatId, personIds] of members) {
|
|
257
|
+
database.prepare("DELETE FROM chat_members WHERE chat_id = ?").run(chatId);
|
|
258
|
+
for (const personId of personIds) {
|
|
259
|
+
database
|
|
260
|
+
.prepare("INSERT OR IGNORE INTO chat_members (chat_id, person_id) VALUES (?, ?)")
|
|
261
|
+
.run(chatId, personId);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
refreshRecency();
|
|
265
|
+
database
|
|
266
|
+
.prepare("INSERT INTO sync_marker (id, marker) VALUES (1, ?) ON CONFLICT(id) DO UPDATE SET marker = excluded.marker")
|
|
267
|
+
.run(marker);
|
|
268
|
+
summary.known = Number(database.prepare("SELECT COUNT(*) AS n FROM people").get()?.n ?? 0);
|
|
269
|
+
});
|
|
270
|
+
return summary;
|
|
271
|
+
},
|
|
272
|
+
forgetSyncMarker: () => {
|
|
273
|
+
database.exec("DELETE FROM sync_marker");
|
|
98
274
|
},
|
|
99
275
|
messages: {
|
|
100
276
|
read: (chatId, limit, freshForMs) => {
|
|
@@ -117,7 +293,9 @@ export const openStore = ({ database, now = () => Date.now() }) => {
|
|
|
117
293
|
return;
|
|
118
294
|
const at = now();
|
|
119
295
|
for (const message of messages) {
|
|
120
|
-
putMessage.run(chatId, message.id, message.senderId, message.senderName, epoch(message.timestamp) ?? 0, epoch(message.editedAt), message.text, message.outgoing === null ? null : Number(message.outgoing), JSON.stringify(message.attachments),
|
|
296
|
+
putMessage.run(chatId, message.id, message.senderId, message.senderName, epoch(message.timestamp) ?? 0, epoch(message.editedAt), message.text, message.outgoing === null ? null : Number(message.outgoing), JSON.stringify(message.attachments), message.replyTo || message.forwardedFrom
|
|
297
|
+
? JSON.stringify({ replyTo: message.replyTo, forwardedFrom: message.forwardedFrom })
|
|
298
|
+
: null, at);
|
|
121
299
|
}
|
|
122
300
|
const times = messages.map((message) => epoch(message.timestamp) ?? 0);
|
|
123
301
|
database
|
|
@@ -129,6 +307,40 @@ export const openStore = ({ database, now = () => Date.now() }) => {
|
|
|
129
307
|
invalidate: (chatId) => {
|
|
130
308
|
database.prepare("DELETE FROM fetched WHERE kind = ?").run(`messages:${chatId}`);
|
|
131
309
|
},
|
|
310
|
+
search: ({ query, chatId, limit, offset }) => {
|
|
311
|
+
const values = [phrase(query)];
|
|
312
|
+
let sql = `SELECT m.*, c.title AS chat_title FROM messages_fts f
|
|
313
|
+
JOIN messages m ON m.rowid = f.rowid
|
|
314
|
+
LEFT JOIN chats c ON c.id = m.chat_id
|
|
315
|
+
WHERE messages_fts MATCH ?`;
|
|
316
|
+
if (chatId !== undefined) {
|
|
317
|
+
sql += " AND m.chat_id = ?";
|
|
318
|
+
values.push(chatId);
|
|
319
|
+
}
|
|
320
|
+
sql += " ORDER BY m.time DESC LIMIT ? OFFSET ?";
|
|
321
|
+
values.push(limit, offset);
|
|
322
|
+
return database
|
|
323
|
+
.prepare(sql)
|
|
324
|
+
.all(...values)
|
|
325
|
+
.map((row) => ({
|
|
326
|
+
...toMessage(row),
|
|
327
|
+
chatTitle: row.chat_title === null || row.chat_title === undefined ? null : String(row.chat_title),
|
|
328
|
+
}));
|
|
329
|
+
},
|
|
330
|
+
countSearch: ({ query, chatId }) => {
|
|
331
|
+
const values = [phrase(query)];
|
|
332
|
+
let sql = `SELECT COUNT(*) AS n FROM messages_fts f JOIN messages m ON m.rowid = f.rowid
|
|
333
|
+
WHERE messages_fts MATCH ?`;
|
|
334
|
+
if (chatId !== undefined) {
|
|
335
|
+
sql += " AND m.chat_id = ?";
|
|
336
|
+
values.push(chatId);
|
|
337
|
+
}
|
|
338
|
+
return Number(database.prepare(sql).get(...values)?.n ?? 0);
|
|
339
|
+
},
|
|
340
|
+
timeOf: (id) => {
|
|
341
|
+
const row = database.prepare("SELECT time FROM messages WHERE id = ? LIMIT 1").get(id);
|
|
342
|
+
return row?.time === undefined ? undefined : Number(row.time);
|
|
343
|
+
},
|
|
132
344
|
},
|
|
133
345
|
claim: (chatId, anchor, holder, forMs) => {
|
|
134
346
|
const at = now();
|
|
@@ -143,7 +355,16 @@ export const openStore = ({ database, now = () => Date.now() }) => {
|
|
|
143
355
|
database.prepare("DELETE FROM fetch_lease WHERE chat_id = ? AND anchor = ?").run(chatId, anchor);
|
|
144
356
|
},
|
|
145
357
|
clear: () => {
|
|
146
|
-
for (const table of [
|
|
358
|
+
for (const table of [
|
|
359
|
+
"messages",
|
|
360
|
+
"chats",
|
|
361
|
+
"people",
|
|
362
|
+
"chat_members",
|
|
363
|
+
"sync_marker",
|
|
364
|
+
"ranges",
|
|
365
|
+
"fetched",
|
|
366
|
+
"fetch_lease",
|
|
367
|
+
]) {
|
|
147
368
|
database.exec(`DELETE FROM ${table}`);
|
|
148
369
|
}
|
|
149
370
|
},
|
package/dist/cache/store.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/cache/store.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAgCrC,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,EAAE,QAAQ,EAAE,GAAG,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,EAAgB,EAAc,EAAE;IAC1F,OAAO,CAAC,QAAQ,CAAC,CAAA;IAEjB,MAAM,WAAW,GAAG,QAAQ,CAAC,OAAO,CAClC,+FAA+F,CAChG,CAAA;IACD,MAAM,SAAS,GAAG,QAAQ,CAAC,OAAO,CAAC,uCAAuC,CAAC,CAAA;IAE3E,MAAM,OAAO,GAAG,CAAC,IAAY,EAAE,UAAkB,EAAW,EAAE;QAC5D,MAAM,EAAE,GAAI,SAAS,CAAC,GAAG,CAAC,IAAI,CAAiC,EAAE,EAAE,CAAA;QACnE,OAAO,EAAE,KAAK,SAAS,IAAI,GAAG,EAAE,GAAG,EAAE,IAAI,UAAU,CAAA;IACrD,CAAC,CAAA;IAED,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC;;;;;;0EAMuC,CAAC,CAAA;IAEzE,MAAM,UAAU,GAAG,QAAQ,CAAC,OAAO,CAAC;;;;2EAIqC,CAAC,CAAA;IAE1E;;;;;;;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E,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE;YAC1B,QAAQ,CAAC,OAAO,CAAC,0DAA0D,CAAC,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;QAClG,CAAC;QAED,KAAK,EAAE,GAAG,EAAE;YACV,KAAK,MAAM,KAAK,IAAI;gBAClB,UAAU;gBACV,OAAO;gBACP,QAAQ;gBACR,cAAc;gBACd,aAAa;gBACb,QAAQ;gBACR,SAAS;gBACT,aAAa;aACd,EAAE,CAAC;gBACF,QAAQ,CAAC,IAAI,CAAC,eAAe,KAAK,EAAE,CAAC,CAAA;YACvC,CAAC;QACH,CAAC;QAED,KAAK,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,KAAK,EAAE;KAC9B,CAAA;AACH,CAAC,CAAA"}
|
package/dist/client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { CacheStore } from "./cache/store.js";
|
|
2
|
-
import type { Chat, Contact, Id, Message, Profile } from "./domain/models.js";
|
|
1
|
+
import type { CacheStore, PersonOrder, SyncSummary } from "./cache/store.js";
|
|
2
|
+
import type { Chat, ChatKind, Contact, Id, Message, MessageHit, Page, Profile } from "./domain/models.js";
|
|
3
3
|
import { Connection } from "./protocol/connection.js";
|
|
4
4
|
import { type DiagnosticEvent } from "./runs/events.js";
|
|
5
5
|
import type { SessionStore } from "./session/store.js";
|
|
@@ -57,7 +57,7 @@ export declare class MaxClient {
|
|
|
57
57
|
* time, and the name is filled in. Without this, `max chats` shows a column of blanks for
|
|
58
58
|
* exactly the chats a person recognises by name.
|
|
59
59
|
*/
|
|
60
|
-
list: (
|
|
60
|
+
list: (options?: PageRequest) => Promise<Page<Chat>>;
|
|
61
61
|
/**
|
|
62
62
|
* Turns what the person typed into a chat id.
|
|
63
63
|
*
|
|
@@ -68,11 +68,79 @@ export declare class MaxClient {
|
|
|
68
68
|
resolve: (reference: string) => Promise<Id>;
|
|
69
69
|
};
|
|
70
70
|
readonly contacts: {
|
|
71
|
-
/**
|
|
72
|
-
|
|
71
|
+
/**
|
|
72
|
+
* The people this account has a one-to-one chat with, named, newest conversation first.
|
|
73
|
+
*
|
|
74
|
+
* **It answers from the store**, which the login has just brought up to date (`#mergeLogin`),
|
|
75
|
+
* so the order and the paging happen in SQL over every person we know rather than over the
|
|
76
|
+
* handful this particular login mentioned. A delta carries almost nothing after the first run;
|
|
77
|
+
* rendering the response instead of the store would show an empty list on the second command.
|
|
78
|
+
*
|
|
79
|
+
* ⚠ **A group member is not in this answer** and nothing marks them as excluded: the query
|
|
80
|
+
* asks for people a *dialog* exists with, and they are outside it (`NEED-105`). They are in
|
|
81
|
+
* the store, with the chats they share with us, for the commands that will want them.
|
|
82
|
+
*/
|
|
83
|
+
list: (options?: PageRequest) => Promise<Page<Contact>>;
|
|
84
|
+
/**
|
|
85
|
+
* **Start again from zero**: forget the marker, so this login asks for the whole collection
|
|
86
|
+
* rather than for what changed, and name everybody it mentions.
|
|
87
|
+
*
|
|
88
|
+
* It is a repair tool, not the way contacts arrive. The delta rides on the login every command
|
|
89
|
+
* already performs, so there is nothing to schedule and no budget to spend — what this is for
|
|
90
|
+
* is a store that has drifted, or a full re-take after a schema rebuild threw the rows away.
|
|
91
|
+
* It is also the only thing that could ever prune somebody MAX has stopped returning, which is
|
|
92
|
+
* the second reason it exists.
|
|
93
|
+
*/
|
|
94
|
+
sync: () => Promise<SyncSummary & {
|
|
95
|
+
full: true;
|
|
96
|
+
}>;
|
|
73
97
|
};
|
|
74
98
|
readonly messages: {
|
|
75
|
-
|
|
99
|
+
/**
|
|
100
|
+
* **Searches what this machine has read, and never asks MAX.**
|
|
101
|
+
*
|
|
102
|
+
* MAX has no search operation in our registry — nine opcodes, none of them a query — so there
|
|
103
|
+
* is nothing to ask. That makes this the one read that is local by nature rather than by
|
|
104
|
+
* choice, and it is the opposite of the rule every other read follows (`df6792a`: the record
|
|
105
|
+
* does not answer a read).
|
|
106
|
+
*
|
|
107
|
+
* ⚠ **So it finds what has been read, not what exists.** A chat nobody has opened contributes
|
|
108
|
+
* nothing, and there is no way for the answer to know that. The command says so on stderr
|
|
109
|
+
* rather than leaving the reader to infer it from a short list, and `max messages list <chat>`
|
|
110
|
+
* is what fills the gap.
|
|
111
|
+
*
|
|
112
|
+
* It opens no connection at all, which also means it costs no login (`RISK-2`).
|
|
113
|
+
*/
|
|
114
|
+
search: (query: string, options?: {
|
|
115
|
+
chatId?: Id;
|
|
116
|
+
limit?: number;
|
|
117
|
+
offset?: number;
|
|
118
|
+
}) => Promise<Page<MessageHit>>;
|
|
119
|
+
/**
|
|
120
|
+
* **Paged backwards through time, not by page number.** MAX's history is already anchored —
|
|
121
|
+
* it takes a moment and answers with what came before it — so `--before` is exact where a page
|
|
122
|
+
* number over a live conversation would repeat and skip rows.
|
|
123
|
+
*
|
|
124
|
+
* `hasMore` here is a claim about the copy we hold, never about the chat: a full page back is
|
|
125
|
+
* the only evidence there is that another page exists.
|
|
126
|
+
*/
|
|
127
|
+
list: (chatId: Id, options?: {
|
|
128
|
+
limit?: number;
|
|
129
|
+
before?: number;
|
|
130
|
+
}) => Promise<Page<Message>>;
|
|
131
|
+
/**
|
|
132
|
+
* Turns what `--before` was given into a moment.
|
|
133
|
+
*
|
|
134
|
+
* **ISO 8601 is a time; a bare integer is a message id.** Both a millisecond timestamp and a
|
|
135
|
+
* message id are runs of digits — 13 and 18 of them on this account — and deciding between
|
|
136
|
+
* them by length is a trap that fires the first time either changes size. So the rule is what
|
|
137
|
+
* the string looks like, not how big it is.
|
|
138
|
+
*
|
|
139
|
+
* An id we have never stored is exactly what a deleted message looks like, because it is gone
|
|
140
|
+
* from the history MAX returns too. That is a refusal naming the way round it rather than a
|
|
141
|
+
* guess: read as milliseconds, an 18-digit id points six hundred million years from now.
|
|
142
|
+
*/
|
|
143
|
+
before: (reference: string) => number;
|
|
76
144
|
/**
|
|
77
145
|
* Sends one message, retrying **only with the same `cid`**.
|
|
78
146
|
*
|
|
@@ -84,7 +152,7 @@ export declare class MaxClient {
|
|
|
84
152
|
* So one retry, same `cid`, and nothing beyond that. What is still unmeasured is how long the
|
|
85
153
|
* server remembers a `cid`; the two probes were seconds apart. If the retry also fails the
|
|
86
154
|
* answer is `outcome_unknown` — never failed, never sent — and it names the `cid`, because
|
|
87
|
-
* `max send --cid <n>` can then repeat the attempt without risking a second message.
|
|
155
|
+
* `max messages send … --cid <n>` can then repeat the attempt without risking a second message.
|
|
88
156
|
*/
|
|
89
157
|
send: (chatId: Id, text: string, options?: {
|
|
90
158
|
cid?: number;
|
|
@@ -92,12 +160,26 @@ export declare class MaxClient {
|
|
|
92
160
|
}) => Promise<Message>;
|
|
93
161
|
};
|
|
94
162
|
/**
|
|
95
|
-
* Opens the connection and logs in with the stored token.
|
|
163
|
+
* Opens the connection and logs in with the stored token, or with one offered for trial.
|
|
96
164
|
*
|
|
97
165
|
* The login response carries the profile, the chats, the contacts and recent messages, so most
|
|
98
166
|
* commands need no further request — measured against MAX on 2026-09-19.
|
|
167
|
+
*
|
|
168
|
+
* **A candidate token is tried and not stored**, which is what lets `adoptToken` write to the
|
|
169
|
+
* keyring only after MAX has accepted it. Nothing here writes a token; see `session/adopt.ts`.
|
|
99
170
|
*/
|
|
100
|
-
connect(
|
|
171
|
+
connect({ token: candidate }?: {
|
|
172
|
+
token?: string;
|
|
173
|
+
}): Promise<void>;
|
|
101
174
|
close(): Promise<void>;
|
|
102
175
|
}
|
|
176
|
+
/** What every listing takes. Absent means "the caller did not say", never a number chosen here. */
|
|
177
|
+
export interface PageRequest {
|
|
178
|
+
order?: PersonOrder;
|
|
179
|
+
limit?: number;
|
|
180
|
+
offset?: number;
|
|
181
|
+
/** Part of a name. Refused below three characters — see `checkedQuery`. */
|
|
182
|
+
query?: string;
|
|
183
|
+
kind?: ChatKind;
|
|
184
|
+
}
|
|
103
185
|
//# sourceMappingURL=client.d.ts.map
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAE5E,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AAGzG,OAAO,EAAE,UAAU,EAAiB,MAAM,0BAA0B,CAAA;AAEpE,OAAO,EAAY,KAAK,eAAe,EAAS,MAAM,kBAAkB,CAAA;AAExE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAGtD,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,YAAY,CAAA;IACnB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,kEAAkE;IAClE,UAAU,CAAC,EAAE,UAAU,CAAA;IACvB;;;OAGG;IACH,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAA;IAChC,gFAAgF;IAChF,KAAK,CAAC,EAAE,UAAU,CAAA;IAClB;;;;;;;OAOG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB;;;OAGG;IACH,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI,CAAA;CAC1C;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,SAAS;;gBAcR,EAAE,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,EAAE,OAAe,EAAE,MAAM,EAAE,EAAE,gBAAgB;IASpG,QAAQ,CAAC,OAAO;kBACN,OAAO;MAChB;IAED,QAAQ,CAAC,KAAK;QACZ;;;;;;;WAOG;yBACmB,WAAW,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