clavarium-parley 0.13.3 → 0.14.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 CHANGED
@@ -54,6 +54,7 @@ arrived. See [docs/protocol.md](docs/protocol.md).
54
54
  | `agent-status` | `working`, `waiting` or `done`, and a note | show it; ring a phone on `waiting` |
55
55
  | `agent-doing` | one line: what it is doing now | show it while it works; nothing more |
56
56
  | `person-reacted` | the reaction, and whether the set says it wakes (`false`, `true`, `'now'`) | tell the agent now, later, or with the next message |
57
+ | `history-changed` | with a keep folder: the lines kept that changed or went in the bridge folder, or were slipped in | nothing: the screen says it; alert someone, or log it |
57
58
 
58
59
  | Action | Does |
59
60
  |---|---|
@@ -84,6 +85,7 @@ are, changes, or does not use.
84
85
  const parley = new Parley('/path/to/work/.parley', {
85
86
  on: (event) => { /* person-wrote: get WAKE to the agent, your way; agent-asked: alert, or not */ },
86
87
  reach: (path) => (path.startsWith('/work/') ? path : null), // what the person can open
88
+ keep: '/path/to/state/chat-copy', // optional: your own copy of the thread, out of the agent's reach
87
89
  });
88
90
  parley.listen();
89
91
  typeInTheAgentsTerminal(parley.invite('fr', { install: 'npm install -g /path/to/clavarium-parley-0.10.0.tgz', shared: '/work' }));
@@ -94,6 +96,13 @@ and in a page:
94
96
  mount(element, { load, send, words: texts('fr', operatorsOwn), open, terminal, view: 'simple',
95
97
  voice: yourDictation, replies: yourReadyAnswers });
96
98
 
99
+ The agent can write in its folder, the person's lines too. Given `keep`, a
100
+ folder of its own that the agent cannot reach, the application's side keeps
101
+ every line there as it reads it (the person's as it writes them), shows that
102
+ copy, and notes any line kept that changed or went in the bridge folder:
103
+ the screen says "History changed here: original shown" where it happened.
104
+ See [the protocol](docs/protocol.md#the-applications-own-copy).
105
+
97
106
  The command is installed from the archive `npm pack` makes, by the
98
107
  application or by the agent: `npm install -g clavarium-parley-0.10.0.tgz`,
99
108
  then `parley --help`. Installing it runs no script of its own. It finds
package/docs/protocol.md CHANGED
@@ -14,6 +14,8 @@ Parley is three small things that agree on one folder.
14
14
 
15
15
  The two `.jsonl` files only grow. Nothing is edited, nothing is deleted. There is no
16
16
  address, no port and no key: whoever can read and write the folder is a side.
17
+ The agent can still rewrite them: an application that must not trust that keeps
18
+ its own copy (see "The application's own copy").
17
19
 
18
20
  The command finds the folder as git finds a repository: `--dir`, else
19
21
  `$PARLEY_DIR`, else the nearest `.parley` from where the agent stands.
@@ -132,6 +134,7 @@ finds it. An answer may therefore come two minutes or two days later.
132
134
  | `agent-doing` | the agent ran `doing` | `message` (its `text`: one line) |
133
135
  | `agent-closed` | the agent ran `close` | `message` (`answers`: the question; `text`: the answer it understood) |
134
136
  | `person-reacted` | `react()` wrote a reaction | `message` (the line), `reaction` (null: taken back), `wakes` (`false`, `true` or `'now'`: the set's hint), `unread` |
137
+ | `history-changed` | with a keep folder: a line kept changed or went in the bridge folder, or one was slipped in | `altered`: what was noted, as in `read()` |
135
138
 
136
139
  Events of the agent are announced by `listen()`, each line once, once it is
137
140
  whole, from the moment it was started: what was posted before is in
@@ -143,6 +146,7 @@ whole, from the moment it was started: what was posted before is in
143
146
  | `react(to, reaction)` | a reaction of the set (`REACTIONS`) on a message of the agent, or `null` to take it back; what `read()` gives |
144
147
  | `read()` | `messages` (each of the person's says `seen`, and `seenAt` when known, `via` when dictated; each of the agent's may carry `short`, `reaction` (`{id, at, seen}`, the one standing), `files` for a gallery (`[{path, title, open}]`), and `refs`: the paths it cites that `reach` opens; a question it closed, `closed: {text, at}`), `waiting` (questions neither answered nor closed), `status`, `steps` (every `status` and `doing`, in order: `{id, kind, state, note, at}`), `files` (every file shown, and every one cited that can be opened, `cited: true`), `unread`, `pulse` |
145
148
  | `invite(lang, {install?, shared?})` | the invitation, a text |
149
+ | `read().altered` | with a keep folder only: what changed in the bridge folder after it was kept, oldest first (see below) |
146
150
  | `unread()` | how many of the person's messages the agent has not read |
147
151
 
148
152
  `reach(path)`, given by the application, says how the person opens a file
@@ -172,6 +176,40 @@ calls `act(id, line)`; the rest stays text. A line of
172
176
  the application takes no step and does not hide that the person's last
173
177
  message is not read yet.
174
178
 
179
+ ## The application's own copy
180
+
181
+ The bridge folder is the agent's: it can rewrite or delete any line of both
182
+ files, the person's included, and nothing in the folder shows it. An
183
+ application that must not trust that gives the host a folder of its own, out
184
+ of the agent's reach: `new Parley(dir, { keep })`, one per bridge folder.
185
+
186
+ - Each whole line of `from-agent.jsonl` is copied there, as written, the
187
+ first time it is read (`keep/from-agent.jsonl`); each line of
188
+ `to-agent.jsonl` as the host writes it (`keep/to-agent.jsonl`): those are
189
+ the person's, and a line there that the host never wrote is none of theirs.
190
+ The first time, with no copy yet, the bridge is taken as it is: a thread
191
+ begun before it was kept.
192
+ - What is kept is what `read()` gives, what `unread()` counts, what
193
+ `listen()` announces (each line once, by its place in the copy). Nothing
194
+ kept is ever rewritten: a correction is a new line.
195
+ - At each read the copy is compared with the bridge file: each line kept is
196
+ looked for again, in order. A line kept that is not found is `changed` (a line of
197
+ its id stands there instead) or `gone`; a line found among them that is not
198
+ kept is `added` (slipped in, or a forged line of the person). After the last
199
+ line found again, what is new is the agent's next lines, taken as usual --
200
+ but a line repeating the id of one kept, which is a change.
201
+ - Each is noted once, in `keep/altered.jsonl`, and announced
202
+ (`history-changed`). `read().altered`: `[{side: "agent"|"person", kind:
203
+ "changed"|"gone"|"added", line, id, was, at}]` -- `line` its place in the
204
+ copy (from 1; null when added), `was` the time the line says (where it
205
+ happened), `at` when it was noticed.
206
+ - The screen puts one line in the thread after the last message at or before
207
+ `was`, in the person's words (`history-changed`: "History changed here:
208
+ original shown"); several side by side are one line.
209
+
210
+ Without `keep`, nothing of this: the bridge folder is all there is.
211
+ `pulse.json`, `read.json` and the files the person attached are not copied.
212
+
175
213
  ## What the screen makes of the states
176
214
 
177
215
  `waiting` and `done` are no steps. Each is said once, at the end of the
@@ -17,6 +17,7 @@
17
17
  * agent-doing {message}
18
18
  * agent-closed {message} (a question it closed, answered another way)
19
19
  * person-reacted {message, reaction, wakes, unread} react(to, reaction)
20
+ * history-changed {altered} (with a keep folder: a line kept changed or went)
20
21
  *
21
22
  * The pulse of the agent's tool (pulse.json) is not announced: read() gives it.
22
23
  *
@@ -30,7 +31,7 @@
30
31
  * as text. Showing it as text, never building it, is the application's part.
31
32
  */
32
33
  import { appendFileSync, readFileSync, writeFileSync, mkdirSync, copyFileSync, existsSync, statSync, lstatSync, openSync, readSync, closeSync, readdirSync } from 'node:fs';
33
- import { randomUUID } from 'node:crypto';
34
+ import { randomUUID, createHash } from 'node:crypto';
34
35
  import { fileURLToPath } from 'node:url';
35
36
 
36
37
  export const TEXT_MAX = 16000;
@@ -168,6 +169,95 @@ function pulseOf(dir, now) {
168
169
  }
169
170
  function lineCount(file) { try { if (lstatSync(file).isSymbolicLink()) return 0; return readFileSync(file, 'utf8').split('\n').filter(Boolean).length; } catch { return 0; } }
170
171
 
172
+ /* THE APPLICATION'S OWN COPY: `keep`, a folder the agent cannot reach. The
173
+ bridge folder is the agent's own: it can rewrite any line there, the
174
+ person's too, and a screen that reads only that folder would show the new
175
+ words as if they had always been said. With a keep folder, each line is
176
+ copied there once it is whole and read (the agent's), or as it is written
177
+ (the person's: this side writes them, so a line of theirs that this side
178
+ did not write is no line of theirs). What is kept is what is shown. A line
179
+ kept that changed or went from the bridge folder, or one slipped in among
180
+ lines already kept, is noted once, with when it was noticed. Nothing kept
181
+ is rewritten: a correction is a new line. */
182
+ const KEPT = new Map();
183
+ const statOf = (st) => `${st.size}:${st.mtimeMs}:${st.ctimeMs}:${st.ino}`;
184
+ const keptStat = (file) => { try { return statOf(statSync(file)); } catch { return null; } };
185
+ /* A file of the keep folder: { lines, ids, seen }, or null when there is none yet. Read once,
186
+ then from memory while the file is as this process left it. `seen`: how the bridge file
187
+ was when last compared, so that a bridge file that did not move is not read again. */
188
+ function kept(file) {
189
+ const stamp = keptStat(file);
190
+ if (stamp === null) { KEPT.delete(file); return null; }
191
+ const known = KEPT.get(file);
192
+ if (known?.stamp === stamp) return known;
193
+ let text;
194
+ try { text = readFileSync(file, 'utf8'); } catch { return null; }
195
+ const entry = { stamp, lines: text.split('\n').filter(Boolean), ids: null, seen: null };
196
+ KEPT.set(file, entry);
197
+ return entry;
198
+ }
199
+ function keep(file, add, { whole = false } = {}) {
200
+ const before = whole ? null : kept(file);
201
+ if (whole) writeFileSync(file, add.map((l) => `${l}\n`).join(''));
202
+ else if (add.length) appendFileSync(file, add.map((l) => `${l}\n`).join(''));
203
+ const entry = { stamp: keptStat(file), lines: [...(before?.lines ?? []), ...add], ids: null, seen: before?.seen ?? null };
204
+ KEPT.set(file, entry);
205
+ return entry;
206
+ }
207
+ const idsOf = (entry) => (entry.ids ??= new Set(entry.lines.map(idOf).filter(Boolean)));
208
+ /* The whole lines of a bridge file, as written (a line not ended yet waits): none when it is
209
+ gone, or is a link (all it held is gone from there); null when too big to compare, or when
210
+ it is as it was when last compared (`seen`). */
211
+ function bridgeLines(file, seen) {
212
+ try {
213
+ const st = lstatSync(file);
214
+ if (st.isSymbolicLink() || !st.isFile()) return seen === 'none' ? null : { lines: [], stamp: 'none' };
215
+ const stamp = statOf(st);
216
+ if (stamp === seen || st.size > 16 * FILE_MAX) return null;
217
+ const text = readFileSync(file, 'utf8');
218
+ return { lines: text.slice(0, text.lastIndexOf('\n') + 1).split('\n').filter(Boolean), stamp };
219
+ } catch { return seen === 'none' ? null : { lines: [], stamp: 'none' }; }
220
+ }
221
+ const idOf = (line) => { const id = parsed(line)?.id; return typeof id === 'string' ? id : ''; };
222
+ const atOf = (line) => { const at = parsed(line)?.at; return typeof at === 'string' ? at : ''; };
223
+ const hashOf = (line) => createHash('sha256').update(line).digest('hex').slice(0, 16);
224
+ /* The newest lines kept, FILE_MAX characters of them, parsed: what lines() gives of a bridge file. */
225
+ function tail(list) {
226
+ let size = 0, from = list.length;
227
+ while (from > 0 && size + list[from - 1].length + 1 <= FILE_MAX) size += list[--from].length + 1;
228
+ return list.slice(from).map(parsed).filter(Boolean);
229
+ }
230
+ /* What changed in a bridge file, against what is kept of it: the lines kept that are not
231
+ there in their order any more (`lost`, by place; `changed` when a line of the same id
232
+ stands there instead), the lines that are new at its end (`fresh`, taken: the agent's
233
+ side only), and the lines that are neither (`added`: slipped in, or the person's that
234
+ this side never wrote). A line kept is found again in order, even after a line before it
235
+ went: what follows it is still in place. */
236
+ function compare(entry, now, { takes }) {
237
+ const lines = entry.lines, ids = idsOf(entry);
238
+ const out = { lost: [], changed: new Set(), fresh: [], added: [] };
239
+ let from = lines.length;
240
+ if (!(now.length >= lines.length && lines.every((l, i) => now[i] === l))) {
241
+ const where = new Map();
242
+ now.forEach((l, k) => { if (!where.has(l)) where.set(l, []); where.get(l).push(k); });
243
+ const used = new Set();
244
+ let j = 0;
245
+ lines.forEach((l, i) => { const k = where.get(l)?.find((x) => x >= j); if (k === undefined) out.lost.push(i); else { used.add(k); j = k + 1; } });
246
+ const lostIds = new Map(out.lost.map((i) => [idOf(lines[i]), i]).filter(([id]) => id));
247
+ now.forEach((l, k) => {
248
+ if (used.has(k) || k >= j) return;
249
+ const id = idOf(l);
250
+ if (lostIds.has(id)) out.changed.add(lostIds.get(id)); else out.added.push(l);
251
+ });
252
+ from = j;
253
+ for (const l of now.slice(from)) { const id = idOf(l); if (lostIds.has(id)) { out.changed.add(lostIds.get(id)); continue; } (takes && !(id && ids.has(id)) ? out.fresh : out.added).push(l); }
254
+ return out;
255
+ }
256
+ /* Only grown: what is new is the agent's; a line repeating the id of one kept is not new. */
257
+ for (const l of now.slice(from)) { const id = idOf(l); (takes && !(id && ids.has(id)) ? out.fresh : out.added).push(l); }
258
+ return out;
259
+ }
260
+
171
261
  /* Puts the bridge in `dir`: the two files, and the MCP server for an agent
172
262
  that is given it that way. Resolves with how that server is declared to an
173
263
  agent. `as`: where that folder is seen FROM THE AGENT, when that is not
@@ -180,15 +270,18 @@ export function install(dir, { as = dir } = {}) {
180
270
  }
181
271
 
182
272
  export class Parley {
183
- #dir; #on; #reach; #now; #reactions;
273
+ #dir; #on; #reach; #now; #reactions; #keep;
184
274
 
185
275
  /* `on(event)`: told what happens (see the top of this file).
186
276
  `reach(path)`: how the person opens a file the agent showed -- a
187
277
  reference of the application's (a link, a path) or null when it
188
278
  cannot be opened from their screen. Every path, by default. */
189
279
  /* `reactions`: the set offered, [{ id, wakes }] (REACTIONS by default). */
190
- constructor(dir, { on, reach = (path) => path, now = () => new Date(), reactions = REACTIONS } = {}) {
191
- this.#dir = dir; this.#on = on; this.#reach = reach; this.#now = now;
280
+ /* `keep`: a folder of the application's, out of the agent's reach, where
281
+ the thread is kept as it was read (see THE APPLICATION'S OWN COPY);
282
+ one per bridge folder. Without it, the bridge folder is all there is. */
283
+ constructor(dir, { on, reach = (path) => path, now = () => new Date(), reactions = REACTIONS, keep } = {}) {
284
+ this.#dir = dir; this.#on = on; this.#reach = reach; this.#now = now; this.#keep = typeof keep === 'string' && keep ? keep : null;
192
285
  this.#reactions = (Array.isArray(reactions) ? reactions : REACTIONS).filter((r) => r && REACTION_ID.test(r.id));
193
286
  }
194
287
 
@@ -228,8 +321,58 @@ export class Parley {
228
321
  });
229
322
  }
230
323
 
324
+ /* With a keep folder: compares one bridge file with what is kept of it,
325
+ keeps what is new (the agent's lines only: the person's are kept as
326
+ they are written), notes once what changed (history-changed), and gives
327
+ the lines kept, as written. */
328
+ #sync(name) {
329
+ const own = `${this.#keep}/${name}`;
330
+ let entry = kept(own);
331
+ if (entry === null) {
332
+ /* First sight: the bridge is taken as it is (a thread begun before it was kept). */
333
+ mkdirSync(this.#keep, { recursive: true });
334
+ const now = bridgeLines(`${this.#dir}/${name}`);
335
+ entry = keep(own, now?.lines ?? [], { whole: true });
336
+ entry.seen = now?.stamp ?? null;
337
+ return entry.lines;
338
+ }
339
+ const now = bridgeLines(`${this.#dir}/${name}`, entry.seen);
340
+ if (now === null) return entry.lines;
341
+ const side = name === 'from-agent.jsonl' ? 'agent' : 'person';
342
+ const found = compare(entry, now.lines, { takes: side === 'agent' });
343
+ if (found.fresh.length) entry = keep(own, found.fresh);
344
+ entry.seen = now.stamp;
345
+ const at = this.#now().toISOString();
346
+ const notes = [
347
+ ...found.lost.map((i) => ({ key: `${side}:${i}`, side, kind: found.changed.has(i) ? 'changed' : 'gone', line: i + 1, id: idOf(entry.lines[i]), was: atOf(entry.lines[i]), at })),
348
+ ...found.added.map((l) => ({ key: `${side}+${hashOf(l)}`, side, kind: 'added', line: null, id: idOf(l), was: atOf(l), at })),
349
+ ];
350
+ if (notes.length) this.#note(notes);
351
+ return entry.lines;
352
+ }
353
+ /* Each change noted once, in the keep folder: what the screen says, where it happened. */
354
+ #note(notes) {
355
+ const file = `${this.#keep}/altered.jsonl`;
356
+ const known = new Set((kept(file)?.lines ?? []).map((l) => parsed(l)?.key));
357
+ const added = notes.filter((n) => !known.has(n.key) && known.add(n.key));
358
+ if (!added.length) return;
359
+ keep(file, added.map((n) => JSON.stringify(n)));
360
+ this.#tell({ type: 'history-changed', altered: added.map(({ key, ...n }) => n) });
361
+ }
362
+ /* What was noted: [{side, kind, line, id, was, at}], oldest first. */
363
+ #altered() { return (kept(`${this.#keep}/altered.jsonl`)?.lines ?? []).map(parsed).filter(Boolean).map(({ key, ...n }) => n); }
364
+ /* The lines of one side, parsed: what is kept, with a keep folder; the bridge file, without. */
365
+ #lines(name) { return this.#keep ? tail(this.#sync(name)) : lines(`${this.#dir}/${name}`); }
366
+ /* A line of the person's, written: kept first, so that a bridge refusing it says so. */
367
+ #write(list) {
368
+ const text = list.map((l) => JSON.stringify(l));
369
+ if (this.#keep) { this.#sync('to-agent.jsonl'); keep(`${this.#keep}/to-agent.jsonl`, text); }
370
+ mkdirSync(this.#dir, { recursive: true });
371
+ appendFileSync(`${this.#dir}/to-agent.jsonl`, text.map((l) => `${l}\n`).join(''));
372
+ }
373
+
231
374
  /* How many messages of the person the agent has not read. */
232
- unread() { return Math.max(0, lineCount(`${this.#dir}/to-agent.jsonl`) - readCount(this.#dir)); }
375
+ unread() { return Math.max(0, (this.#keep ? this.#sync('to-agent.jsonl').length : lineCount(`${this.#dir}/to-agent.jsonl`)) - readCount(this.#dir)); }
233
376
 
234
377
  /* Both sides, in the order they were written; how many questions wait;
235
378
  where the agent says it is; its steps -- every state it said and every
@@ -238,11 +381,11 @@ export class Parley {
238
381
  not read (each says `seen`). Saying what it does means it works: a
239
382
  `doing` after "done" or "waiting" makes the status "working" again. */
240
383
  read() {
241
- const all = lines(`${this.#dir}/from-agent.jsonl`).map((m) => this.#fromAgent(m));
384
+ const all = this.#lines('from-agent.jsonl').map((m) => this.#fromAgent(m));
242
385
  const agent = all.filter((m) => m.kind !== 'close');
243
386
  const closes = new Map(all.filter((m) => m.kind === 'close').map((m) => [m.answers, { text: m.text, at: m.at }]));
244
387
  const unread = this.unread();
245
- const written = lines(`${this.#dir}/to-agent.jsonl`);
388
+ const written = this.#lines('to-agent.jsonl');
246
389
  /* When each of the person's messages was read: the first read that reached it. */
247
390
  const reads = readTimes(this.#dir);
248
391
  const seenAt = (i) => reads.find((r) => r.lines > i)?.at ?? null;
@@ -280,6 +423,8 @@ export class Parley {
280
423
  files: [...shown, ...cites].sort((a, b) => String(a.at).localeCompare(String(b.at))).slice(-LISTED_MAX),
281
424
  unread,
282
425
  pulse: pulseOf(this.#dir, this.#now()),
426
+ /* With a keep folder: what changed in the bridge folder after it was kept. */
427
+ ...(this.#keep ? { altered: this.#altered() } : {}),
283
428
  };
284
429
  }
285
430
 
@@ -304,8 +449,7 @@ export class Parley {
304
449
  if (asked?.kind === 'ask') { entry.answers = asked.id; entry.question = oneLine(asked.text, 300); }
305
450
  else if (asked) { entry.re = asked.id; entry.quote = oneLine(asked.text || asked.path, 300); }
306
451
  }
307
- mkdirSync(this.#dir, { recursive: true });
308
- appendFileSync(`${this.#dir}/to-agent.jsonl`, `${JSON.stringify(entry)}\n`);
452
+ this.#write([entry]);
309
453
  const now = this.read();
310
454
  this.#tell({ type: 'person-wrote', message: now.messages.find((m) => m.id === entry.id) ?? { from: 'person', ...entry }, unread: now.unread });
311
455
  return now;
@@ -328,8 +472,7 @@ export class Parley {
328
472
  /* Another one replaces it: the one standing is taken back first, said so. */
329
473
  if (standing !== null && kind === null) lines2.push({ id: randomUUID(), ...base, reaction: standing, removed: true });
330
474
  if (kind !== null) lines2.push({ id: randomUUID(), ...base, reaction: kind });
331
- mkdirSync(this.#dir, { recursive: true });
332
- appendFileSync(`${this.#dir}/to-agent.jsonl`, lines2.map((l) => `${JSON.stringify(l)}\n`).join(''));
475
+ this.#write(lines2);
333
476
  const now = this.read();
334
477
  const set = this.#reactions.find((r) => r.id === (kind ?? standing));
335
478
  this.#tell({ type: 'person-reacted', message: lines2.at(-1), reaction: kind, wakes: kind === null ? false : set?.wakes ?? false, unread: now.unread });
@@ -351,6 +494,19 @@ export class Parley {
351
494
  let offset = size();
352
495
  let rest = Buffer.alloc(0);
353
496
  const TYPES = { say: 'agent-said', ask: 'agent-asked', show: 'agent-showed', status: 'agent-status', doing: 'agent-doing', close: 'agent-closed' };
497
+ const tell = (m) => { const message = this.#fromAgent(m); this.#tell({ type: TYPES[message.kind], message }); };
498
+ if (this.#keep) {
499
+ /* Kept: each line once it is kept, by its place in the copy, which only grows -- whatever the agent does to its file. */
500
+ let known = this.#sync('from-agent.jsonl').length;
501
+ const timer = setInterval(() => {
502
+ let all;
503
+ try { all = this.#sync('from-agent.jsonl'); } catch { return; }
504
+ for (const line of all.slice(known)) { const m = parsed(line); if (m) tell(m); }
505
+ known = all.length;
506
+ }, every);
507
+ timer.unref?.();
508
+ return () => clearInterval(timer);
509
+ }
354
510
  const look = () => {
355
511
  const now = size();
356
512
  if (now < offset) { offset = 0; rest = Buffer.alloc(0); } /* the file was started again */
@@ -367,9 +523,7 @@ export class Parley {
367
523
  rest = all.subarray(end + 1);
368
524
  for (const line of all.subarray(0, end).toString('utf8').split('\n')) {
369
525
  const m = line ? parsed(line) : undefined;
370
- if (!m) continue;
371
- const message = this.#fromAgent(m);
372
- this.#tell({ type: TYPES[message.kind], message });
526
+ if (m) tell(m);
373
527
  }
374
528
  };
375
529
  const timer = setInterval(look, every);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clavarium-parley",
3
- "version": "0.13.3",
3
+ "version": "0.14.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "description": "A bridge between a command-line agent and a screen of its own: a command and an MCP server of five verbs, and a small library that shows the exchange.",
@@ -33,7 +33,7 @@ import { fileURLToPath } from 'node:url';
33
33
  import { randomUUID } from 'node:crypto';
34
34
  import { createInterface } from 'node:readline';
35
35
 
36
- export const VERSION = '0.13.3';
36
+ export const VERSION = '0.14.0';
37
37
  /* A message may be long: the screen folds it, and shows its short version first. */
38
38
  export const TEXT_MAX = 16000;
39
39
  /* Its short version: a title of one or two lines. */
package/ui/parley-ui.js CHANGED
@@ -180,7 +180,7 @@ export const KEYS = Object.freeze(['send', 'placeholder', 'empty', 'view', 'simp
180
180
  'zoom-in', 'zoom-out', 'zoom-actual', 'zoom-fit', 'zoom-actual-short', 'zoom-fit-short', 'close', 'previous', 'next', 'search', 'found', 'newest', 'dictation', 'auto-send-off',
181
181
  'react', 'react-remove', 'react-agree', 'react-go', 'react-disagree', 'react-unclear', 'react-stop', 'react-redo', 'react-later', 'react-love',
182
182
  'react-agree-hint', 'react-go-hint', 'react-disagree-hint', 'react-unclear-hint', 'react-stop-hint', 'react-redo-hint', 'react-later-hint', 'react-love-hint',
183
- 'decide', 'media', 'media-pictures', 'media-files', 'media-none', 'see-in-thread', 'done-end', 'done-end-note', 'dictated', 'side-now', 'side-machine', 'side-nothing']);
183
+ 'decide', 'media', 'media-pictures', 'media-files', 'media-none', 'see-in-thread', 'done-end', 'done-end-note', 'dictated', 'side-now', 'side-machine', 'side-nothing', 'history-changed']);
184
184
  /* THE REACTIONS offered by default, each with its Lucide icon; their words
185
185
  are "react-<id>" (shown under the icon) and "react-<id>-hint" (on hover).
186
186
  The same ids as REACTIONS of parley-host.mjs, which says which wake. */
@@ -468,6 +468,16 @@ export function view(data, { words = {}, view: as = 'simple', now = Date.now(),
468
468
  const answered = new Set(all.filter((m) => m.from === 'person').map((m) => m.answers).filter(Boolean));
469
469
  /* Simple shows nothing the person cannot act on: a file that cannot be opened, a trace, are in the detailed view only. */
470
470
  const messages = all.filter((m) => detailed || !((m.kind === 'show' && (Array.isArray(m.files) && m.files.length ? !m.files.some((f) => f && typeof f.open === 'string') : typeof m.open !== 'string')) || (m.from === 'system' && levelOf(m.level) === 'trace')));
471
+ /* WHAT CHANGED IN THE BRIDGE FOLDER after the application kept it (read().altered): the copy
472
+ kept is what is shown, and one line says so where it happened -- two changes side by side, one line. */
473
+ for (const a of (Array.isArray(data?.altered) ? data.altered : []).filter((x) => x && typeof x === 'object')) {
474
+ const t = stamp(a.was) ?? stamp(a.at);
475
+ if (t === null) continue;
476
+ let i = messages.findIndex((m) => (stamp(m.at) ?? -Infinity) > t);
477
+ if (i < 0) i = messages.length;
478
+ if (messages[i - 1]?.altered || messages[i]?.altered) continue;
479
+ messages.splice(i, 0, { from: 'system', kind: 'system', altered: true, id: `altered:${String(a.side ?? '')}:${String(a.line ?? a.was ?? '')}`, at: new Date(t).toISOString(), text: said(words, 'history-changed'), level: 'news', tone: 'warn', actions: [] });
480
+ }
471
481
  const status = data?.status ?? null;
472
482
  const state = (s) => said(words, ['working', 'waiting', 'done'].includes(s) ? s : 'working');
473
483
  /* A state of waiting, or done, is not a step: it is said once, at the end. */
package/ui/texts/en.json CHANGED
@@ -142,5 +142,6 @@
142
142
  "dictated": "Dictated",
143
143
  "side-now": "Now",
144
144
  "side-machine": "Its machine",
145
- "side-nothing": "Nothing under way."
145
+ "side-nothing": "Nothing under way.",
146
+ "history-changed": "History changed here: original shown"
146
147
  }
package/ui/texts/fr.json CHANGED
@@ -142,5 +142,6 @@
142
142
  "dictated": "Dicté",
143
143
  "side-now": "En cours",
144
144
  "side-machine": "Sa machine",
145
- "side-nothing": "Rien en cours."
145
+ "side-nothing": "Rien en cours.",
146
+ "history-changed": "Historique modifié ici : original affiché"
146
147
  }