clavarium-parley 0.10.0 → 0.10.1

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.
@@ -32,8 +32,11 @@ import { randomUUID } from 'node:crypto';
32
32
  import { fileURLToPath } from 'node:url';
33
33
 
34
34
  export const TEXT_MAX = 16000;
35
- /* The short version of a message: a title of one or two lines. */
35
+ /* The short version of a message: a title of one or two lines, shown cut beyond SHORT_MAX
36
+ (at a word, with "…"). Kept whole up to SHORT_KEPT: an agent that wrote more than a title
37
+ loses none of it -- the screen shows it all once the message is opened. */
36
38
  export const SHORT_MAX = 200;
39
+ export const SHORT_KEPT = 1000;
37
40
  /* Paths a message cites, looked up for the screen, at most. */
38
41
  export const REFS_MAX = 20;
39
42
  export const SHOWN_MAX = 200;
@@ -181,7 +184,7 @@ export class Parley {
181
184
  #fromAgent(m) {
182
185
  const kind = KINDS.includes(m.kind) ? m.kind : 'say';
183
186
  const entry = { from: 'agent', id: String(m.id ?? ''), at: String(m.at ?? ''), kind, text: clean(m.text), choices: kind === 'ask' && Array.isArray(m.choices) ? m.choices.slice(0, 8).map((x) => oneLine(x, 200)).filter(Boolean) : [] };
184
- if ((kind === 'say' || kind === 'ask') && typeof m.short === 'string' && oneLine(m.short, SHORT_MAX)) entry.short = oneLine(m.short, SHORT_MAX);
187
+ if ((kind === 'say' || kind === 'ask') && typeof m.short === 'string' && oneLine(m.short, SHORT_KEPT)) entry.short = oneLine(m.short, SHORT_KEPT);
185
188
  if (kind === 'say' || kind === 'ask') {
186
189
  /* The paths it cites that the person can open: a link, or a picture, on the screen. */
187
190
  const refs = cited(`${entry.text}\n${entry.short ?? ''}`).map((path) => ({ path, open: this.#open(path) })).filter((r) => r.open !== null);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clavarium-parley",
3
- "version": "0.10.0",
3
+ "version": "0.10.1",
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.",
@@ -32,11 +32,13 @@ import { fileURLToPath } from 'node:url';
32
32
  import { randomUUID } from 'node:crypto';
33
33
  import { createInterface } from 'node:readline';
34
34
 
35
- export const VERSION = '0.10.0';
35
+ export const VERSION = '0.10.1';
36
36
  /* A message may be long: the screen folds it, and shows its short version first. */
37
37
  export const TEXT_MAX = 16000;
38
38
  /* Its short version: a title of one or two lines. */
39
39
  export const SHORT_MAX = 200;
40
+ /* Kept whole up to this (see SHORT_KEPT in the host): the screen cuts it, never the agent's words. */
41
+ export const SHORT_KEPT = 1000;
40
42
  /* What it is doing now is one short line: a screen shows it while it works. */
41
43
  export const DOING_MAX = 200;
42
44
  export const CHOICES_MAX = 8;
@@ -77,7 +79,7 @@ const reacted = (m) => {
77
79
  if (m.removed === true) return `They took back their reaction "${name}" to ${target}.`;
78
80
  return `Reaction to ${target}: ${REACTION_MEANINGS[name] ?? `"${name}"`}`;
79
81
  };
80
- const brief = (short) => { const line = plain(short, SHORT_MAX * 2).replace(/\s+/g, ' ').trim().slice(0, SHORT_MAX); return line ? { short: line } : {}; };
82
+ const brief = (short) => { const line = plain(short, SHORT_KEPT * 2).replace(/\s+/g, ' ').trim().slice(0, SHORT_KEPT); return line ? { short: line } : {}; };
81
83
  /* So many characters of a question's id are shown, and enough to close it. */
82
84
  export const ID_SHOWN = 8;
83
85
  /* How many reads are remembered, with their time: the screen says when each message was read. */
package/ui/parley-ui.js CHANGED
@@ -247,7 +247,15 @@ function dayText(t, now, words, locale) {
247
247
  if (dayKey(t) === dayKey(before.getTime())) return said(words, 'yesterday');
248
248
  return format(t, locale, new Date(t).getFullYear() === new Date(now).getFullYear() ? { weekday: 'long', day: 'numeric', month: 'long' } : { weekday: 'long', day: 'numeric', month: 'long', year: 'numeric' });
249
249
  }
250
- const cut = (text, n) => { const one = String(text ?? '').replace(/\s+/g, ' ').trim(); return one.length > n ? `${one.slice(0, n - 1)}…` : one; };
250
+ /* One line of at most n characters: cut at the end of a word (never inside one, unless it is
251
+ the only word), and "…" says that more follows. */
252
+ const cut = (text, n) => {
253
+ const one = String(text ?? '').replace(/\s+/g, ' ').trim();
254
+ if (one.length <= n) return one;
255
+ const head = one.slice(0, n - 1);
256
+ const space = head.lastIndexOf(' ');
257
+ return `${(space > n / 2 ? head.slice(0, space) : head).replace(/[\s,;:.\-–—]+$/, '')}…`;
258
+ };
251
259
 
252
260
  /* ---- MARKDOWN, READ INTO PLAIN DATA ----
253
261
  Blocks: { t: 'p'|'h'|'hr'|'code'|'quote'|'alert'|'list'|'table', ... }.
@@ -497,7 +505,9 @@ export function view(data, { words = {}, view: as = 'simple', now = Date.now(),
497
505
  type: 'message', key: `m:${String(m.id ?? '')}`,
498
506
  id: String(m.id ?? ''), from: person ? 'person' : 'agent', kind: String(m.kind ?? 'say'),
499
507
  text: show ? String(m.text || nameOf(m.path)) : String(m.text ?? ''),
500
- short: !person && typeof m.short === 'string' ? cut(m.short, 200) : '',
508
+ /* Whole, as the agent wrote it; `shortCut` is what a folded message shows. */
509
+ short: !person && typeof m.short === 'string' ? String(m.short).replace(/\s+/g, ' ').trim() : '',
510
+ shortCut: !person && typeof m.short === 'string' ? cut(m.short, 200) : '',
501
511
  refs: (Array.isArray(m.refs) ? m.refs : []).filter((r) => r && typeof r.path === 'string' && typeof r.open === 'string').slice(0, 20).map((r) => ({ path: r.path, open: r.open })),
502
512
  time: clock(t, locale), when: whole(t, locale), at: t,
503
513
  label: open ? said(words, 'asks') : '',
@@ -1347,7 +1357,8 @@ export function mount(root, { load, send, words = {}, open, terminal, remind, vi
1347
1357
  const paint2 = painter({ words, refs, open, picture: picture ? pictureUrl : null, pictureUrl, diagram, highlight, cache, urls, zoom: zoomFrom });
1348
1358
  const blocks = markdown(item.text);
1349
1359
  const whole2 = () => paint2.blocks(blocks, el('div', 'parley-md'));
1350
- const shortLine = () => paint2.inlines(inline(item.short), el('p', 'parley-short'));
1360
+ /* Folded: the short version cut to a title; opened: all of it, nothing lost. */
1361
+ const shortLine = (all = true) => paint2.inlines(inline(all ? item.short : item.shortCut || item.short), el('p', 'parley-short'));
1351
1362
  const important = (list) => list.filter((b) => b.t === 'alert' && b.kind === 'important');
1352
1363
  const more = (key, open2) => { const b = button(said(words, open2 ? 'see-less' : key), 'parley-unfold', () => { if (open2) expanded.delete(item.id); else expanded.add(item.id); repaint(); }); b.setAttribute('aria-expanded', String(open2)); return b; };
1353
1364
  /* A question is never folded; the detailed view and a search unfold everything. */
@@ -1356,7 +1367,7 @@ export function mount(root, { load, send, words = {}, open, terminal, remind, vi
1356
1367
  const isOpen = expanded.has(item.id);
1357
1368
  if (item.short) {
1358
1369
  if (isOpen) return [shortLine(), whole2(), more('see-details', true)];
1359
- return [shortLine(), ...important(blocks).map((b) => paint2.blocks([b], el('div', 'parley-md'))), more('see-details', false)];
1370
+ return [shortLine(false), ...important(blocks).map((b) => paint2.blocks([b], el('div', 'parley-md'))), more('see-details', false)];
1360
1371
  }
1361
1372
  if (linesOf(item.text) > FOLD_LINES + 2) {
1362
1373
  if (isOpen) return [whole2(), more('see-more', true)];