visualproof 0.5.0 → 0.7.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 +2 -2
- package/dist/assets/tips/phone-fingers.light.mp4 +0 -0
- package/dist/assets/tips/phone-fingers.light.webp +0 -0
- package/dist/assets/tips/tour-agent.webp +0 -0
- package/dist/assets/tips/tour-arrange.webp +0 -0
- package/dist/assets/tips/tour-artwork.webp +0 -0
- package/dist/assets/tips/tour-checks.webp +0 -0
- package/dist/assets/tips/tour-keys.webp +0 -0
- package/dist/assets/tips/tour-library.webp +0 -0
- package/dist/assets/tips/tour-project.webp +0 -0
- package/dist/assets/tips/tour-review.webp +0 -0
- package/dist/assets/tips/tour-share.webp +0 -0
- package/dist/assets/tips/tour-source.webp +0 -0
- package/dist/assets/tips/tour-target.webp +0 -0
- package/dist/assets/tips/tour-view.webp +0 -0
- package/dist/assets/tips/tour.json +125 -115
- package/dist/assets/tips/tour.webp +0 -0
- package/dist/extractor/Extract.lean +13 -3
- package/dist/mcp/visualproof-mcp.mjs +20 -9
- package/dist/server/access.js +28 -0
- package/dist/server/agent.js +130 -2819
- package/dist/server/agentactivity.js +72 -0
- package/dist/server/agentadvice.js +115 -0
- package/dist/server/agentdocs.js +1 -1
- package/dist/server/agententry.js +180 -0
- package/dist/server/agentexport.js +469 -0
- package/dist/server/agentfollow.js +384 -0
- package/dist/server/agentgraph.js +128 -0
- package/dist/server/agentlean.js +144 -0
- package/dist/server/agentlibrary.js +1 -1
- package/dist/server/agentplaces.js +242 -0
- package/dist/server/agentread.js +569 -0
- package/dist/server/agenttalk.js +282 -0
- package/dist/server/agenttcb.js +378 -0
- package/dist/server/agentviews.js +2 -2
- package/dist/server/app.js +377 -0
- package/dist/server/appaccess.js +127 -0
- package/dist/server/appagent.js +110 -0
- package/dist/server/appgraph.js +176 -0
- package/dist/server/appshare.js +179 -0
- package/dist/server/appsite.js +120 -0
- package/dist/server/apptalk.js +178 -0
- package/dist/server/artcmd.js +1 -1
- package/dist/server/askfollow.js +1 -1
- package/dist/server/deploy.js +204 -53
- package/dist/server/events.js +1 -1
- package/dist/server/history.js +51 -3
- package/dist/server/historyapi.js +34 -2
- package/dist/server/hover.js +11 -7
- package/dist/server/identity.js +1 -1
- package/dist/server/invites.js +113 -20
- package/dist/server/libraryroute.js +3 -3
- package/dist/server/live.js +186 -30
- package/dist/server/main.js +31 -1613
- package/dist/server/mcptools.js +33 -20
- package/dist/server/options.js +350 -0
- package/dist/server/outside.js +311 -0
- package/dist/server/pastdoc.js +22 -3
- package/dist/server/presence.js +3 -3
- package/dist/server/project.js +28 -4
- package/dist/server/prompt.js +8 -3
- package/dist/server/readonlygate.js +4 -4
- package/dist/server/reviewapi.js +51 -17
- package/dist/server/send.js +259 -0
- package/dist/server/talk.js +238 -116
- package/dist/server/tokens.js +13 -5
- package/dist/server/view.js +3 -1
- package/dist/server/views.js +1 -1
- package/dist/shared/artrecipe.js +3 -3
- package/dist/shared/build.js +35 -1
- package/dist/shared/collab.js +9 -1
- package/dist/shared/comment.js +1 -1
- package/dist/shared/doc/build.js +30 -14
- package/dist/shared/doc/latex.js +7 -2
- package/dist/shared/doc/model.js +4 -2
- package/dist/shared/doc/sections.js +21 -4
- package/dist/shared/keys.js +66 -37
- package/dist/shared/lostfound.js +1 -0
- package/dist/shared/mentions.js +83 -0
- package/dist/shared/outside.js +16 -0
- package/dist/shared/pastgraph.js +11 -2
- package/dist/shared/query.js +13 -4
- package/dist/shared/review.js +91 -21
- package/dist/shared/reviewqueue.js +6 -1
- package/dist/shared/scope.js +1 -1
- package/dist/web/bundle/app.js +51289 -49853
- package/dist/web/index.html +45 -9
- package/dist/web/src/reviewqueue.js +52 -19
- package/dist/web/src/selection.js +1 -1
- package/dist/web/src/theme.js +1 -1
- package/dist/web/src/trust.js +271 -0
- package/dist/web/src/visitors.js +1 -1
- package/dist/web/style.css +181 -70
- package/docs/agent-api/README.md +13 -11
- package/docs/agent-api/advice.md +8 -2
- package/docs/agent-api/export.md +9 -6
- package/docs/agent-api/following.md +11 -12
- package/docs/agent-api/history.md +6 -3
- package/docs/agent-api/mcp.md +15 -15
- package/docs/agent-api/notes.md +1 -1
- package/docs/agent-api/reading.md +10 -4
- package/docs/agent-api/requests.md +12 -15
- package/docs/agent-api/talking.md +60 -55
- package/docs/agent-api/tcb.md +21 -21
- package/docs/agent-api/views.md +3 -4
- package/docs/agent-api/words.md +8 -8
- package/package.json +2 -1
package/dist/server/talk.js
CHANGED
|
@@ -1,41 +1,55 @@
|
|
|
1
|
-
// Talking
|
|
2
|
-
//
|
|
3
|
-
// it
|
|
1
|
+
// Talking in the page (CollabSpec decision 13, AgentSpec decision 8; the owner's decisions of
|
|
2
|
+
// 2026-10-19): the public channel, where everyone with a name and every agent with a token talk; each
|
|
3
|
+
// agent's private channel, between it and the person who made its token (its maker, AgentSpec
|
|
4
|
+
// decision 7); the agent's inbox, which it waits on; and its state, inferred from what it does.
|
|
4
5
|
//
|
|
5
6
|
// Nothing is pushed to an agent: it listens by waiting on its inbox (GET /api/agent/inbox?wait=<s>,
|
|
6
7
|
// which the wait_for_message tool of VisualProof's MCP server, mcp/visualproof-mcp.mjs, holds open
|
|
7
|
-
// for it), so that any agent able to make an HTTP request can be talked to. A wait answers as soon
|
|
8
|
-
//
|
|
9
|
-
// with none once its time is up.
|
|
8
|
+
// for it), so that any agent able to make an HTTP request can be talked to. A wait answers as soon as
|
|
9
|
+
// something is handed to the agent, with everything handed since the last answer, in order, each
|
|
10
|
+
// saying its channel; or with none once its time is up. Handed to it: its maker's messages in its
|
|
11
|
+
// private channel, and a person's message in the public channel that mentions it (shared/mentions.ts).
|
|
12
|
+
// Nothing else of the public channel: it reads the channel when it wants (GET /api/agent/channel). An
|
|
13
|
+
// agent's mention of an agent is shown and never handed, so that no two agents talk on without a
|
|
14
|
+
// person. What comes while no wait is open waits for the next one.
|
|
10
15
|
//
|
|
11
16
|
// The state each agent is shown in comes from what it does, not from what it says: *listening*
|
|
12
17
|
// while a wait is open; *thinking* from the moment messages were handed to it until it replies, with
|
|
13
|
-
// what its requests show it doing (server/
|
|
18
|
+
// what its requests show it doing (server/agenttalk.ts, doingOf) and the line it may set itself;
|
|
14
19
|
// *working* when it makes requests with nothing to answer; *offline* once it has had no wait open
|
|
15
20
|
// and made no request for its longest wait plus a minute — the time an agent that listens takes at
|
|
16
|
-
// most to come back.
|
|
21
|
+
// most to come back. An offline agent's private channel cannot be written to (409); a mention of it
|
|
22
|
+
// in the public channel is written, and handed to it when it comes back.
|
|
17
23
|
//
|
|
18
|
-
//
|
|
19
|
-
//
|
|
20
|
-
//
|
|
24
|
+
// The channels live apart from the review's logs, in `<site>/chat/`: the public one in `public.jsonl`
|
|
25
|
+
// for 90 days, as the timeline is kept; each private one in `<token id>.jsonl` for 30 days; one
|
|
26
|
+
// message per line. A message is at most a few thousand characters, and each sender may send only so
|
|
27
|
+
// many a minute. A person's message in the public channel keeps the tokens of the agents it is handed
|
|
28
|
+
// to (`to`, the agents it mentions that were listed as it was written), which is told to nobody.
|
|
29
|
+
// Revoking a token, or its expiry, ends its wait at once. Who may read and write which channel is
|
|
30
|
+
// server/apptalk.ts's to check (shared/collab.ts, madeBy), and which page is sent which message
|
|
31
|
+
// server/live.ts's.
|
|
21
32
|
//
|
|
22
|
-
// A session that replaces another knows nothing of
|
|
23
|
-
//
|
|
24
|
-
//
|
|
25
|
-
//
|
|
26
|
-
//
|
|
27
|
-
// handed as a notice to disregard what came before, and before which a later
|
|
28
|
-
// nothing.
|
|
33
|
+
// A session that replaces another knows nothing of what the page still shows (the owner's decisions
|
|
34
|
+
// of 2026-10-11). So the first wait after the agent was offline — it left, or went offline by the
|
|
35
|
+
// rule, or another session of its MCP server waits now — answers at once with one entry marked as
|
|
36
|
+
// earlier, before anything new: its private channel so far, and the mentions of it that came while it
|
|
37
|
+
// was away. Its maker can start a new conversation in its private channel: a divider in the same
|
|
38
|
+
// file, which the agent is handed as a notice to disregard what came before, and before which a later
|
|
39
|
+
// session is told nothing. The public channel has no dividers.
|
|
29
40
|
import { appendFileSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync, renameSync } from "node:fs";
|
|
30
41
|
import { join } from "node:path";
|
|
31
42
|
import { utc } from "./mcptools.js";
|
|
32
|
-
/** how long a message is kept */
|
|
43
|
+
/** how long a private channel's message is kept, and the public channel's (as the timeline) */
|
|
33
44
|
export const KEEP_MS = 30 * 24 * 3600 * 1000;
|
|
34
|
-
|
|
45
|
+
export const KEEP_PUBLIC_MS = 90 * 24 * 3600 * 1000;
|
|
46
|
+
/** the longest message a person may send, and an agent's (it may explain at length) */
|
|
35
47
|
export const MAX_PERSON = 4000;
|
|
36
48
|
export const MAX_AGENT = 10_000;
|
|
37
|
-
/** what a page or an agent is given of a
|
|
49
|
+
/** what a page or an agent is given of a channel at once */
|
|
38
50
|
export const THREAD = 200;
|
|
51
|
+
/** what the server holds of a channel in memory: what pages may page back through */
|
|
52
|
+
const HELD = 2000;
|
|
39
53
|
/** the longest one wait may last, in seconds: Claude Code gives up on a stdio tool call idle for 30
|
|
40
54
|
* minutes (progress resets it), and an agent that splits a longer wait asks again */
|
|
41
55
|
export const MAX_WAIT_S = 1800;
|
|
@@ -47,17 +61,27 @@ export const EARLIER_MESSAGES = 50;
|
|
|
47
61
|
export const EARLIER_CHARS = 20_000;
|
|
48
62
|
/** a sender's messages: a burst of BURST, then one every REFILL_MS (people), or faster (agents) */
|
|
49
63
|
const RATE = { person: { burst: 5, refillMs: 6000 }, agent: { burst: 10, refillMs: 2000 } };
|
|
64
|
+
/** the public channel's key, where a private channel's is its token's id (ten hex digits) */
|
|
65
|
+
export const PUBLIC = "public";
|
|
50
66
|
const TIMING = { slackMs: 60_000, graceMs: 15_000, tickMs: 1000 };
|
|
51
67
|
export class Talk {
|
|
52
68
|
dir;
|
|
53
69
|
timing;
|
|
54
70
|
threads = new Map();
|
|
71
|
+
/** each channel's last id in this server's life: a channel whose messages all expired goes on
|
|
72
|
+
* counting from there, so that no agent's place in it (`read`) passes what comes next */
|
|
73
|
+
lastIds = new Map();
|
|
74
|
+
/** the order messages were written in here, which their times (to the millisecond) may not tell:
|
|
75
|
+
* what is handed to an agent from both channels at once is in that order (`inOrder`) */
|
|
76
|
+
written = new WeakMap();
|
|
77
|
+
writes = 0;
|
|
55
78
|
agents = new Map();
|
|
56
79
|
buckets = new Map();
|
|
57
80
|
ticks = 0;
|
|
58
81
|
/** told when an agent's state, what it does or its line changes (presence lists it so) */
|
|
59
82
|
onState = () => { };
|
|
60
|
-
/** told of every new message,
|
|
83
|
+
/** told of every new message, by its channel (`public`, or the token whose private channel it
|
|
84
|
+
* is): server/live.ts sends it to the pages that may read it */
|
|
61
85
|
onMessage = () => { };
|
|
62
86
|
/** whether a token is still in force, looked at while its agent waits (an expiry between the
|
|
63
87
|
* minutes the tokens are looked at ends the wait) */
|
|
@@ -78,11 +102,15 @@ export class Talk {
|
|
|
78
102
|
agent(token) {
|
|
79
103
|
let a = this.agents.get(token);
|
|
80
104
|
if (!a) {
|
|
81
|
-
// what was written before the
|
|
82
|
-
// new, and an agent that was offline meanwhile is handed it as
|
|
105
|
+
// what was written before the agent was first known here counts as read: it is never handed
|
|
106
|
+
// over as new, and an agent that was offline meanwhile is handed it as what came before. Each
|
|
107
|
+
// token in force is known as the server starts, and a new one as it is made (server/live.ts,
|
|
108
|
+
// presence), so that a mention of it written before its first request is handed to it
|
|
83
109
|
const used = this.lastUsed(token);
|
|
84
110
|
a = {
|
|
85
|
-
wait: null, waitMs: 0, lastRequest: 0, lastSeen: null, graceUntil: 0,
|
|
111
|
+
wait: null, waitMs: 0, lastRequest: 0, lastSeen: null, graceUntil: 0,
|
|
112
|
+
read: this.load(token).at(-1)?.id ?? 0, readPublic: this.load(PUBLIC).at(-1)?.id ?? 0, lastChannel: "private",
|
|
113
|
+
thinkingSince: null, doing: null, status: null, told: null,
|
|
86
114
|
away: false, before: used ? Date.parse(used) : null, session: null,
|
|
87
115
|
};
|
|
88
116
|
this.agents.set(token, a);
|
|
@@ -118,6 +146,7 @@ export class Talk {
|
|
|
118
146
|
doing: busy ? a.doing : null,
|
|
119
147
|
status: busy ? a.status : null,
|
|
120
148
|
read: a.read,
|
|
149
|
+
readPublic: a.readPublic,
|
|
121
150
|
lastSeen: a.lastSeen === null ? null : new Date(a.lastSeen).toISOString(),
|
|
122
151
|
};
|
|
123
152
|
}
|
|
@@ -125,13 +154,18 @@ export class Talk {
|
|
|
125
154
|
state(token, now = Date.now()) {
|
|
126
155
|
return this.talk(token, now).state;
|
|
127
156
|
}
|
|
157
|
+
/** Where its reply goes when it names no channel: the channel of the last message handed to it
|
|
158
|
+
* that it was to answer, its private one before any. */
|
|
159
|
+
lastChannel(token) {
|
|
160
|
+
return this.agent(token).lastChannel;
|
|
161
|
+
}
|
|
128
162
|
/** Tell presence when what pages show of the agent changed (not when it was last seen alone). */
|
|
129
163
|
update(token, now = Date.now()) {
|
|
130
164
|
const a = this.agent(token);
|
|
131
165
|
const t = this.talk(token, now);
|
|
132
166
|
const was = a.told;
|
|
133
167
|
a.told = t;
|
|
134
|
-
if (!was || was.state !== t.state || was.since !== t.since || was.doing !== t.doing || was.status !== t.status || was.read !== t.read)
|
|
168
|
+
if (!was || was.state !== t.state || was.since !== t.since || was.doing !== t.doing || was.status !== t.status || was.read !== t.read || was.readPublic !== t.readPublic)
|
|
135
169
|
this.onState(token, t);
|
|
136
170
|
}
|
|
137
171
|
/** States change with time alone (the grace after a wait, going offline); and a token that ended
|
|
@@ -188,9 +222,10 @@ export class Talk {
|
|
|
188
222
|
}
|
|
189
223
|
/** The agent waits for messages, at most `ms`; `maxMs` is the longest it waits in all where it
|
|
190
224
|
* splits a long wait into shorter requests. The answer comes at once with what is waiting, as
|
|
191
|
-
* soon as
|
|
192
|
-
* The first wait after the agent was offline starts with
|
|
193
|
-
* at once where there is any; `session` is the one its MCP server says it is, where it
|
|
225
|
+
* soon as something is handed to it, or with nothing at the end; `signal` says the one waiting
|
|
226
|
+
* went away. The first wait after the agent was offline starts with what came before, and so
|
|
227
|
+
* answers at once where there is any; `session` is the one its MCP server says it is, where it
|
|
228
|
+
* says. */
|
|
194
229
|
wait(token, ms, opts = {}, now = Date.now()) {
|
|
195
230
|
const a = this.agent(token);
|
|
196
231
|
this.contact(a, now);
|
|
@@ -214,14 +249,13 @@ export class Talk {
|
|
|
214
249
|
if (opts.signal?.aborted)
|
|
215
250
|
return Promise.resolve({ gone: true });
|
|
216
251
|
const queued = this.queued(token);
|
|
217
|
-
let handed = queued;
|
|
252
|
+
let handed = queued.map(outward);
|
|
218
253
|
if (a.away) {
|
|
219
|
-
// once per return: the waits after it are as any
|
|
254
|
+
// once per return: the waits after it are as any. What was queued is accounted for, the
|
|
255
|
+
// dividers it was not handed among it: they are behind what it is told
|
|
220
256
|
a.away = false;
|
|
221
257
|
handed = this.rejoin(token, queued, now);
|
|
222
|
-
|
|
223
|
-
if (!handed.length && queued.length)
|
|
224
|
-
a.read = queued.at(-1).id;
|
|
258
|
+
this.mark(a, queued);
|
|
225
259
|
}
|
|
226
260
|
if (handed.length || ms <= 0) {
|
|
227
261
|
const r = this.hand(token, queued, handed, 0, now);
|
|
@@ -253,38 +287,64 @@ export class Talk {
|
|
|
253
287
|
this.update(token, now);
|
|
254
288
|
});
|
|
255
289
|
}
|
|
256
|
-
/**
|
|
290
|
+
/** What is to be handed to the agent and was not yet, in order: its private channel's messages
|
|
291
|
+
* but its own (its maker's and the dividers), and the people's messages of the public channel
|
|
292
|
+
* handed to it (`to`). */
|
|
257
293
|
queued(token) {
|
|
258
294
|
const a = this.agent(token);
|
|
259
|
-
|
|
295
|
+
const mine = this.load(token).filter((m) => m.kind !== "agent" && m.id > a.read);
|
|
296
|
+
const named = this.load(PUBLIC).filter((m) => m.id > a.readPublic && m.kind === "person" && !!m.to?.includes(token));
|
|
297
|
+
return inOrder(mine, named, (m) => this.written.get(m) ?? 0);
|
|
298
|
+
}
|
|
299
|
+
/** What `queued` holds is the agent's from now on: what comes after it is handed next. */
|
|
300
|
+
mark(a, queued) {
|
|
301
|
+
for (const m of queued) {
|
|
302
|
+
if (m.channel === "public")
|
|
303
|
+
a.readPublic = Math.max(a.readPublic, m.id);
|
|
304
|
+
else
|
|
305
|
+
a.read = Math.max(a.read, m.id);
|
|
306
|
+
}
|
|
260
307
|
}
|
|
261
|
-
/** What the first wait after the agent was offline hands over:
|
|
262
|
-
* divider
|
|
263
|
-
*
|
|
308
|
+
/** What the first wait after the agent was offline hands over: its private channel since its last
|
|
309
|
+
* divider that it was handed before, and the mentions of it it was not handed (they came while it
|
|
310
|
+
* was away), as one entry; then its maker's messages since that divider not handed over yet. A
|
|
311
|
+
* new session needs no notice of a divider: nothing before it is told. */
|
|
264
312
|
rejoin(token, queued, now) {
|
|
265
313
|
const thread = this.load(token);
|
|
266
314
|
const since = thread.slice(thread.findLastIndex((m) => m.kind === "divider") + 1);
|
|
267
|
-
const fresh = new Set(queued.map((m) => m.id));
|
|
315
|
+
const fresh = new Set(queued.filter((m) => m.channel === "private").map((m) => m.id));
|
|
268
316
|
const news = since.filter((m) => fresh.has(m.id));
|
|
269
317
|
const told = since.filter((m) => !fresh.has(m.id));
|
|
270
|
-
const
|
|
271
|
-
|
|
318
|
+
const missed = queued.filter((m) => m.channel === "public");
|
|
319
|
+
const earlier = earlierOf(inOrder(told, missed, (m) => this.written.get(m) ?? 0), news.length > 0, now);
|
|
320
|
+
return earlier ? [earlier, ...news.map(outward)] : news.map(outward);
|
|
272
321
|
}
|
|
273
|
-
/** Hand over what a wait answers with: what is queued is the agent's from now on
|
|
274
|
-
* messages among it it thinks about from now until it replies,
|
|
275
|
-
* from now (a request made while it waited, by another
|
|
276
|
-
*
|
|
322
|
+
/** Hand over what a wait answers with: what is queued is the agent's from now on; people's
|
|
323
|
+
* messages among it it thinks about from now until it replies, in the channel of the last of
|
|
324
|
+
* them, and what it does is what it does from now (a request made while it waited, by another
|
|
325
|
+
* of its clients, is not). What came before and a divider's notice need no answer. */
|
|
277
326
|
hand(token, queued, handed, waitedMs, now) {
|
|
278
327
|
const a = this.agent(token);
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
if (
|
|
328
|
+
this.mark(a, queued);
|
|
329
|
+
const asked = handed.filter((m) => m.kind === "person");
|
|
330
|
+
if (asked.length) {
|
|
282
331
|
a.thinkingSince = now;
|
|
332
|
+
a.lastChannel = asked.at(-1).channel;
|
|
283
333
|
a.doing = null;
|
|
284
334
|
a.status = null;
|
|
285
335
|
}
|
|
286
336
|
return { messages: handed, waitedMs };
|
|
287
337
|
}
|
|
338
|
+
/** Hand what is queued for the agent to its open wait, if it has one; else it waits for the next. */
|
|
339
|
+
wake(token, now) {
|
|
340
|
+
const a = this.agents.get(token);
|
|
341
|
+
const w = a?.wait;
|
|
342
|
+
if (!w)
|
|
343
|
+
return;
|
|
344
|
+
const q = this.queued(token);
|
|
345
|
+
if (q.length)
|
|
346
|
+
w.end(this.hand(token, q, q.map(outward), now - w.at, now));
|
|
347
|
+
}
|
|
288
348
|
/** End a token's wait: it was revoked, or expired; and forget its agent. */
|
|
289
349
|
close(token, why) {
|
|
290
350
|
const a = this.agents.get(token);
|
|
@@ -301,42 +361,55 @@ export class Talk {
|
|
|
301
361
|
n++;
|
|
302
362
|
return n;
|
|
303
363
|
}
|
|
304
|
-
// ---------------------------------------------------------------- the
|
|
305
|
-
/** A
|
|
306
|
-
|
|
307
|
-
|
|
364
|
+
// ---------------------------------------------------------------- the channels
|
|
365
|
+
/** A channel's messages (`public`, or a token's private channel): the last `limit` of those before
|
|
366
|
+
* message `before` (all, where it is left out), dividers among them. */
|
|
367
|
+
thread(channel, limit = THREAD, before = null) {
|
|
368
|
+
const t = this.load(channel);
|
|
369
|
+
const upTo = before === null ? t : t.filter((m) => m.id < before);
|
|
370
|
+
return upTo.slice(-limit).map(outward);
|
|
308
371
|
}
|
|
309
|
-
/** The
|
|
310
|
-
*
|
|
311
|
-
|
|
372
|
+
/** The public channel after message `since`, as an agent reads it (GET /api/agent/channel): at most
|
|
373
|
+
* the newest `limit`. */
|
|
374
|
+
since(since, limit = THREAD) {
|
|
375
|
+
return this.load(PUBLIC).filter((m) => m.id > since).slice(-limit).map(outward);
|
|
376
|
+
}
|
|
377
|
+
/** The private channel as the agent reads it (GET /api/agent/conversation): the last `limit`
|
|
378
|
+
* messages since its last divider, with that divider and how many messages came before it; `all`,
|
|
379
|
+
* the last `limit` whatever conversation they were in, dividers among them. */
|
|
312
380
|
conversation(token, limit = THREAD, all = false) {
|
|
313
381
|
const thread = this.load(token);
|
|
314
382
|
const k = thread.findLastIndex((m) => m.kind === "divider");
|
|
315
383
|
return {
|
|
316
|
-
messages: (all ? thread : thread.slice(k + 1)).slice(-limit),
|
|
317
|
-
divider: k < 0 ? null : thread[k],
|
|
384
|
+
messages: (all ? thread : thread.slice(k + 1)).slice(-limit).map(outward),
|
|
385
|
+
divider: k < 0 ? null : outward(thread[k]),
|
|
318
386
|
before: thread.slice(0, Math.max(k, 0)).filter((m) => m.kind !== "divider").length,
|
|
319
387
|
};
|
|
320
388
|
}
|
|
321
|
-
/** Whether nothing was said since
|
|
322
|
-
* divide nothing. */
|
|
389
|
+
/** Whether nothing was said in a private channel since its conversation last began (or ever): a
|
|
390
|
+
* divider then would divide nothing. */
|
|
323
391
|
fresh(token) {
|
|
324
392
|
const last = this.load(token).at(-1);
|
|
325
393
|
return !last || last.kind === "divider";
|
|
326
394
|
}
|
|
327
|
-
/** Start a new conversation (the owner's decision of 2026-10-11): a divider,
|
|
328
|
-
*
|
|
329
|
-
* listens, as a notice to disregard what came before; a later session
|
|
330
|
-
* after it. An offline agent's conversation is started anew too, so that
|
|
331
|
-
* clean. Null, and nothing written, where it is new already. */
|
|
395
|
+
/** Start a new conversation in a private channel (the owner's decision of 2026-10-11): a divider,
|
|
396
|
+
* written and sent to the maker's pages as a message is, which the agent is handed at its next
|
|
397
|
+
* wait, or at once where it listens, as a notice to disregard what came before; a later session
|
|
398
|
+
* is told only what comes after it. An offline agent's conversation is started anew too, so that
|
|
399
|
+
* its next session starts clean. Null, and nothing written, where it is new already. */
|
|
332
400
|
restart(token, from, now = Date.now()) {
|
|
333
401
|
if (this.fresh(token))
|
|
334
402
|
return null;
|
|
335
|
-
return this.post(token, { from, kind: "divider", text: `${from} started a new conversation: disregard what came before.`, where: null }, now);
|
|
403
|
+
return this.post(token, { from, kind: "divider", text: `${from} started a new conversation: disregard what came before.`, where: null }, null, now);
|
|
336
404
|
}
|
|
337
405
|
/** Whether `sender` (kind and name) may send now; if not, the seconds to wait. Taking one. */
|
|
338
406
|
allow(kind, sender, now = Date.now()) {
|
|
339
407
|
const r = RATE[kind];
|
|
408
|
+
// the senders whose bursts are full again are forgotten, so that the buckets stay few
|
|
409
|
+
if (this.buckets.size > 2000)
|
|
410
|
+
for (const [k, b] of this.buckets)
|
|
411
|
+
if (b.at + RATE[k.startsWith("agent") ? "agent" : "person"].burst * RATE[k.startsWith("agent") ? "agent" : "person"].refillMs < now)
|
|
412
|
+
this.buckets.delete(k);
|
|
340
413
|
const key = `${kind}\u0000${sender}`;
|
|
341
414
|
const b = this.buckets.get(key) ?? { tokens: r.burst, at: now };
|
|
342
415
|
b.tokens = Math.min(r.burst, b.tokens + (now - b.at) / r.refillMs);
|
|
@@ -347,46 +420,61 @@ export class Talk {
|
|
|
347
420
|
b.tokens -= 1;
|
|
348
421
|
return 0;
|
|
349
422
|
}
|
|
350
|
-
/**
|
|
351
|
-
*
|
|
352
|
-
*
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
423
|
+
/** Write a message in a channel (`public`, or a token's private channel), and send it to the pages
|
|
424
|
+
* that read it. In a private channel, its maker's message or a divider goes to the agent's open
|
|
425
|
+
* wait, if it has one, else waits for the next; in the public channel, a person's message goes so
|
|
426
|
+
* to each agent it is handed to (`to`). An agent's message — the agent is `by`, its token, in the
|
|
427
|
+
* public channel — answers what it was thinking about. */
|
|
428
|
+
post(channel, m, by = null, now = Date.now()) {
|
|
429
|
+
const thread = this.load(channel);
|
|
430
|
+
const { to, ...rest } = m;
|
|
431
|
+
const id = Math.max(thread.at(-1)?.id ?? 0, this.lastIds.get(channel) ?? 0) + 1;
|
|
432
|
+
this.lastIds.set(channel, id);
|
|
433
|
+
const msg = { id, at: new Date(now).toISOString(), ...rest, channel: channel === PUBLIC ? "public" : "private", ...(to?.length ? { to } : {}) };
|
|
356
434
|
thread.push(msg);
|
|
357
|
-
|
|
358
|
-
|
|
435
|
+
this.written.set(msg, ++this.writes);
|
|
436
|
+
if (thread.length > 2 * HELD)
|
|
437
|
+
thread.splice(0, thread.length - HELD);
|
|
359
438
|
mkdirSync(this.dir, { recursive: true });
|
|
360
|
-
appendFileSync(this.file(
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
if (
|
|
366
|
-
|
|
367
|
-
w.end(this.hand(token, q, q, now - w.at, now));
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
else {
|
|
371
|
-
this.contact(a, now);
|
|
372
|
-
a.lastRequest = now;
|
|
373
|
-
a.lastSeen = now;
|
|
374
|
-
a.thinkingSince = null;
|
|
375
|
-
a.status = null;
|
|
376
|
-
a.doing = null;
|
|
377
|
-
this.update(token, now);
|
|
439
|
+
appendFileSync(this.file(channel), JSON.stringify(msg) + "\n");
|
|
440
|
+
const out = outward(msg);
|
|
441
|
+
this.onMessage(channel, out);
|
|
442
|
+
const writer = channel === PUBLIC ? by : channel;
|
|
443
|
+
if (msg.kind === "agent") {
|
|
444
|
+
if (writer)
|
|
445
|
+
this.replied(writer, now);
|
|
378
446
|
}
|
|
379
|
-
|
|
447
|
+
else if (channel !== PUBLIC)
|
|
448
|
+
this.wake(channel, now);
|
|
449
|
+
// an agent's mention of an agent is shown, never handed (AgentSpec decision 8): only a
|
|
450
|
+
// person's message is handed to anyone
|
|
451
|
+
else if (msg.kind === "person")
|
|
452
|
+
for (const t of msg.to ?? [])
|
|
453
|
+
this.wake(t, now);
|
|
454
|
+
return out;
|
|
455
|
+
}
|
|
456
|
+
/** The agent wrote: it is not offline, and what it was thinking about is answered. */
|
|
457
|
+
replied(token, now) {
|
|
458
|
+
const a = this.agent(token);
|
|
459
|
+
this.contact(a, now);
|
|
460
|
+
a.lastRequest = now;
|
|
461
|
+
a.lastSeen = now;
|
|
462
|
+
a.thinkingSince = null;
|
|
463
|
+
a.status = null;
|
|
464
|
+
a.doing = null;
|
|
465
|
+
this.update(token, now);
|
|
380
466
|
}
|
|
381
|
-
file(
|
|
382
|
-
return join(this.dir, `${
|
|
467
|
+
file(channel) {
|
|
468
|
+
return join(this.dir, channel === PUBLIC ? "public.jsonl" : `${channel.replace(/[^0-9a-f]/g, "")}.jsonl`);
|
|
383
469
|
}
|
|
384
|
-
/** A
|
|
385
|
-
* written again without it. */
|
|
386
|
-
load(
|
|
387
|
-
|
|
470
|
+
/** A channel as it is kept, read once: what is older than it keeps is left out, and the file
|
|
471
|
+
* written again without it. A line from before channels (0.5.0) is its file's channel's. */
|
|
472
|
+
load(channel) {
|
|
473
|
+
const keep = channel === PUBLIC ? KEEP_PUBLIC_MS : KEEP_MS;
|
|
474
|
+
const kind = channel === PUBLIC ? "public" : "private";
|
|
475
|
+
let t = this.threads.get(channel);
|
|
388
476
|
if (t) {
|
|
389
|
-
const old = t.findIndex((m) => Date.now() - Date.parse(m.at) <
|
|
477
|
+
const old = t.findIndex((m) => Date.now() - Date.parse(m.at) < keep);
|
|
390
478
|
if (old > 0)
|
|
391
479
|
t.splice(0, old);
|
|
392
480
|
else if (old < 0)
|
|
@@ -394,37 +482,44 @@ export class Talk {
|
|
|
394
482
|
return t;
|
|
395
483
|
}
|
|
396
484
|
t = [];
|
|
397
|
-
const f = this.file(
|
|
485
|
+
const f = this.file(channel);
|
|
398
486
|
if (existsSync(f)) {
|
|
399
487
|
for (const line of readFileSync(f, "utf8").split("\n")) {
|
|
400
488
|
if (!line.trim())
|
|
401
489
|
continue;
|
|
402
490
|
try {
|
|
403
|
-
t.push(JSON.parse(line));
|
|
491
|
+
t.push({ ...JSON.parse(line), channel: kind });
|
|
404
492
|
}
|
|
405
493
|
catch {
|
|
406
494
|
// a line cut short (the server stopped while writing): left out
|
|
407
495
|
}
|
|
408
496
|
}
|
|
409
|
-
const kept = t.filter((m) => Date.now() - Date.parse(m.at) <
|
|
497
|
+
const kept = t.filter((m) => Date.now() - Date.parse(m.at) < keep);
|
|
410
498
|
if (kept.length !== t.length) {
|
|
411
499
|
t = kept;
|
|
412
500
|
rewrite(f, kept);
|
|
413
501
|
}
|
|
502
|
+
if (t.length > HELD)
|
|
503
|
+
t = t.slice(-HELD);
|
|
414
504
|
}
|
|
415
|
-
|
|
505
|
+
const last = t.at(-1)?.id ?? 0;
|
|
506
|
+
if (last > (this.lastIds.get(channel) ?? 0))
|
|
507
|
+
this.lastIds.set(channel, last);
|
|
508
|
+
this.threads.set(channel, t);
|
|
416
509
|
return t;
|
|
417
510
|
}
|
|
418
|
-
/**
|
|
511
|
+
/** Channels nobody wrote in for as long as they are kept go; the others lose what is older (when
|
|
512
|
+
* read). */
|
|
419
513
|
sweep(now = Date.now()) {
|
|
420
514
|
if (!existsSync(this.dir))
|
|
421
515
|
return;
|
|
422
516
|
for (const name of readdirSync(this.dir)) {
|
|
423
517
|
const f = join(this.dir, name);
|
|
518
|
+
const channel = name.replace(/\.jsonl$/, "");
|
|
424
519
|
try {
|
|
425
|
-
if (now - statSync(f).mtimeMs > KEEP_MS) {
|
|
520
|
+
if (now - statSync(f).mtimeMs > (channel === PUBLIC ? KEEP_PUBLIC_MS : KEEP_MS)) {
|
|
426
521
|
rmSync(f, { force: true });
|
|
427
|
-
this.threads.delete(
|
|
522
|
+
this.threads.delete(channel);
|
|
428
523
|
}
|
|
429
524
|
}
|
|
430
525
|
catch {
|
|
@@ -433,10 +528,30 @@ export class Talk {
|
|
|
433
528
|
}
|
|
434
529
|
}
|
|
435
530
|
}
|
|
436
|
-
/**
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
531
|
+
/** A message as pages and agents are told it: without whom it is handed to. */
|
|
532
|
+
function outward(m) {
|
|
533
|
+
const { to: _to, ...rest } = m;
|
|
534
|
+
return rest;
|
|
535
|
+
}
|
|
536
|
+
/** A message as a page is told it (CollabSpec decision 13): where its writer was is handed to agents
|
|
537
|
+
* and never drawn, so a page is not sent it. */
|
|
538
|
+
export function forPages(m) {
|
|
539
|
+
const { where: _where, ...rest } = m;
|
|
540
|
+
return rest;
|
|
541
|
+
}
|
|
542
|
+
/** Two channels' messages as one list, in the order they were written: by their times, and those of
|
|
543
|
+
* one millisecond by `written` (what was read from disk, 0, keeps the order it is given in). */
|
|
544
|
+
function inOrder(a, b, written) {
|
|
545
|
+
if (!b.length)
|
|
546
|
+
return a;
|
|
547
|
+
if (!a.length)
|
|
548
|
+
return b;
|
|
549
|
+
return [...a, ...b].sort((x, y) => (x.at < y.at ? -1 : x.at > y.at ? 1 : written(x) - written(y)));
|
|
550
|
+
}
|
|
551
|
+
/** What came before as the entry a returning agent is handed first, or null where there is none: the
|
|
552
|
+
* newest of `told`, at most EARLIER_MESSAGES and EARLIER_CHARS characters of text, each with who
|
|
553
|
+
* wrote it (the agent's own as its own), where they were and when — the mentions of it in the public
|
|
554
|
+
* channel said so; then what to do, as `news` says whether anything new comes after it. */
|
|
440
555
|
export function earlierOf(told, news, now = Date.now()) {
|
|
441
556
|
let k = told.length;
|
|
442
557
|
let chars = 0;
|
|
@@ -448,18 +563,25 @@ export function earlierOf(told, news, now = Date.now()) {
|
|
|
448
563
|
const each = kept.map((m) => {
|
|
449
564
|
const who = m.kind === "agent" ? `You (${m.from})` : m.from;
|
|
450
565
|
const where = m.where?.inWords ? `, on ${m.where.inWords.replace(/\.$/, "")}` : "";
|
|
451
|
-
|
|
566
|
+
const pub = m.channel === "public";
|
|
567
|
+
return `— ${who}${pub ? " in the public channel, mentioning you while you were away" : ""}${where}, ${utc(m.at)} (${pub ? "public " : ""}message ${m.id}):\n${m.text}`;
|
|
452
568
|
});
|
|
453
|
-
const
|
|
454
|
-
const
|
|
569
|
+
const omitted = k;
|
|
570
|
+
const cut = omitted ? ` (its last ${kept.length} messages; the conversation tool, GET /api/agent/conversation, gives the ${omitted} before them)` : "";
|
|
571
|
+
const away = kept.filter((m) => m.channel === "public").length;
|
|
572
|
+
const missed = away
|
|
573
|
+
? "Those in the public channel came while you were away and were never handed to you: answer one there (reply with channel public) only where it still asks something of you. "
|
|
574
|
+
: "";
|
|
575
|
+
const then = news ? "What came since follows: answer that." : missed ? "Nothing else came since: listen again after that." : "Nothing came since: there is nothing to answer. Listen again.";
|
|
455
576
|
return {
|
|
456
577
|
id: 0,
|
|
457
578
|
at: new Date(now).toISOString(),
|
|
458
579
|
from: "VisualProof",
|
|
459
580
|
kind: "earlier",
|
|
460
|
-
text: `Earlier in this conversation, before you joined${cut} — read it as context, and do not answer it again:\n\n${each.join("\n\n")}\n\nEnd of the earlier messages. ${then}`,
|
|
581
|
+
text: `Earlier in this conversation, before you joined${cut} — read it as context, and do not answer it again:\n\n${each.join("\n\n")}\n\nEnd of the earlier messages. ${missed}${then}`,
|
|
461
582
|
count: kept.length,
|
|
462
|
-
omitted
|
|
583
|
+
omitted,
|
|
584
|
+
...(away ? { missed: away } : {}),
|
|
463
585
|
};
|
|
464
586
|
}
|
|
465
587
|
/** An agent's state at `now`, from what it did: a wait open (or one that ended at its time just
|
package/dist/server/tokens.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Agent tokens (AgentSpec decision 7): sharing with an AI agent hands it a credential of its own,
|
|
2
2
|
// never the server's key. A person makes one from Share for one agent; the token fixes the agent's
|
|
3
|
-
// name and what it may do, lasts a few days, reaches the agents' API only (server/
|
|
3
|
+
// name and what it may do, lasts a few days, reaches the agents' API only (server/app.ts), and can
|
|
4
4
|
// be revoked from Share by anyone with a name.
|
|
5
5
|
//
|
|
6
6
|
// A token is `vpa_<id>_<secret>`: the prefix makes one recognisable wherever it is pasted or leaks
|
|
@@ -12,6 +12,11 @@
|
|
|
12
12
|
// of their own. Tokens made before the secret was kept (only test tokens) are dropped when the file
|
|
13
13
|
// is read.
|
|
14
14
|
//
|
|
15
|
+
// Its maker is the person who made it: their personal link, where an invited person did, else the
|
|
16
|
+
// name they gave (shared/collab.ts, madeBy). Only they are shown its prompt again and read its
|
|
17
|
+
// private channel (the owner's decisions of 2026-10-19): whoever holds the token reads that channel.
|
|
18
|
+
// Revoking it stays anyone's with a name, so that anyone can stop an agent at once.
|
|
19
|
+
//
|
|
15
20
|
// The identity is the token's, not the request's: the name is the one the person gave, "<their
|
|
16
21
|
// name>'s AI" unless they wrote another, and stays the same for the token's life, being the name
|
|
17
22
|
// its advice is logged under (shared/review.ts, logFileName). Among the tokens in force no two have
|
|
@@ -86,8 +91,9 @@ export class AgentTokens {
|
|
|
86
91
|
}
|
|
87
92
|
}
|
|
88
93
|
/** Make a token for an agent: the token (for its prompt) and its record. The name and level are
|
|
89
|
-
* checked by the caller (server/
|
|
90
|
-
* force has it already; `by` is a person's name
|
|
94
|
+
* checked by the caller (server/appshare.ts); the name is used as given, numbered when an agent in
|
|
95
|
+
* force has it already; `by` is a person's name, and `person` their personal link's id where an
|
|
96
|
+
* invited person makes it (`makerPerson`: who its maker is, AgentSpec decision 7). */
|
|
91
97
|
create(o) {
|
|
92
98
|
const now = o.now ?? Date.now();
|
|
93
99
|
this.expire(now);
|
|
@@ -101,6 +107,7 @@ export class AgentTokens {
|
|
|
101
107
|
name: uniqueName(o.name, this.inForce(now).map((r) => r.name)),
|
|
102
108
|
level: o.level,
|
|
103
109
|
by: o.by,
|
|
110
|
+
...(o.person ? { makerPerson: o.person } : {}),
|
|
104
111
|
created: new Date(now).toISOString(),
|
|
105
112
|
expires: new Date(now + o.days * 24 * 3600 * 1000).toISOString(),
|
|
106
113
|
revoked: null,
|
|
@@ -112,7 +119,7 @@ export class AgentTokens {
|
|
|
112
119
|
this.onChanged();
|
|
113
120
|
return { token: tokenOf(record), record };
|
|
114
121
|
}
|
|
115
|
-
/** A token in force, whole, for its prompt to be shown again (server/
|
|
122
|
+
/** A token in force, whole, for its prompt to be shown again (server/appshare.ts); null when there is
|
|
116
123
|
* no such token in force — an ended one is never shown. */
|
|
117
124
|
token(id, now = Date.now()) {
|
|
118
125
|
const r = this.inForce(now).find((x) => x.id === id);
|
|
@@ -217,5 +224,6 @@ export function invalidAgentName(s) {
|
|
|
217
224
|
function isRecord(x) {
|
|
218
225
|
const r = x;
|
|
219
226
|
return !!r && typeof r === "object" && typeof r.id === "string" && ID.test(r.id) && typeof r.secret === "string" && SECRET.test(r.secret) &&
|
|
220
|
-
typeof r.name === "string" && typeof r.by === "string" && typeof r.expires === "string" && ["read", "advise", "full"].includes(r.level)
|
|
227
|
+
typeof r.name === "string" && typeof r.by === "string" && typeof r.expires === "string" && ["read", "advise", "full"].includes(r.level) &&
|
|
228
|
+
(r.makerPerson === undefined || typeof r.makerPerson === "string");
|
|
221
229
|
}
|
package/dist/server/view.js
CHANGED
|
@@ -63,8 +63,10 @@ function viewParts(p, ex) {
|
|
|
63
63
|
v.proofs = n.proofs;
|
|
64
64
|
return v;
|
|
65
65
|
});
|
|
66
|
+
// an outside declaration's doc and place in its package's source, which the source window shows
|
|
67
|
+
// (ReviewSpec, "The source window", the owner's decision of 2026-10-20)
|
|
66
68
|
for (const e of g.externals)
|
|
67
|
-
nodes.push({ name: e.name, kind: e.kind, module: e.module, ax: e.ax, ext: true });
|
|
69
|
+
nodes.push({ name: e.name, kind: e.kind, module: e.module, ax: e.ax, ext: true, ...(e.doc ? { doc: e.doc } : {}), ...(e.range ? { range: e.range } : {}) });
|
|
68
70
|
notationStatements(p, nodes);
|
|
69
71
|
const edges = new Int32Array(g.edges.length * 3);
|
|
70
72
|
g.edges.forEach(([s, d, m], i) => {
|