clavarium 0.2.328-next.1 → 0.2.330-next.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.
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.328-next.1",
3
+ "version": "0.2.330-next.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "clavarium",
9
- "version": "0.2.328-next.1",
9
+ "version": "0.2.330-next.1",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@xterm/addon-fit": "^0.11.0",
@@ -14,7 +14,7 @@
14
14
  "clavarium-binder": "0.1.60-next.1",
15
15
  "clavarium-docket": "0.1.2-next.2",
16
16
  "clavarium-parley": "0.17.70-next.1",
17
- "clavarium-tether": "0.1.0-next.49",
17
+ "clavarium-tether": "0.1.0-next.53",
18
18
  "mammoth": "1.13.0",
19
19
  "mermaid": "11.17.2",
20
20
  "node-pty": "^1.1.0",
@@ -800,9 +800,9 @@
800
800
  }
801
801
  },
802
802
  "node_modules/clavarium-tether": {
803
- "version": "0.1.0-next.49",
804
- "resolved": "https://registry.npmjs.org/clavarium-tether/-/clavarium-tether-0.1.0-next.49.tgz",
805
- "integrity": "sha512-r2TNj/eC6U5drx4GDxo05iZKPwJ8M4cgq4l6IQhMDdys61x9Q1TKp9gTY7WFa4TOVQ1k8prRwChgvFB9kOWAXA==",
803
+ "version": "0.1.0-next.53",
804
+ "resolved": "https://registry.npmjs.org/clavarium-tether/-/clavarium-tether-0.1.0-next.53.tgz",
805
+ "integrity": "sha512-kFSGOQs0bNaURU4SG+IFO7C7zRmLavefZZ/BXvjceuTHM2WP5A58q8H8xkWb1HrHDrj74DqQXYl4TF3kKSNkiA==",
806
806
  "license": "MIT",
807
807
  "bin": {
808
808
  "tether": "bin/cli.mjs",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.328-next.1",
3
+ "version": "0.2.330-next.1",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "description": "A conversation is a VM with a terminal in it. Everything else is a folder.",
@@ -47,7 +47,7 @@
47
47
  "clavarium-binder": "0.1.60-next.1",
48
48
  "clavarium-docket": "0.1.2-next.2",
49
49
  "clavarium-parley": "0.17.70-next.1",
50
- "clavarium-tether": "0.1.0-next.49",
50
+ "clavarium-tether": "0.1.0-next.53",
51
51
  "mammoth": "1.13.0",
52
52
  "mermaid": "11.17.2",
53
53
  "node-pty": "^1.1.0",
@@ -104,8 +104,11 @@ export function demandeView(q) {
104
104
  if (c.action === 'delete') v.irreversible = true;
105
105
  } else if (c.kind === 'contacts') {
106
106
  const who = (x) => (x ? String(x) : w('req-a-contact'));
107
- v.title = c.action === 'create' ? w('req-contact-add', { who: who(c.name || c.email) }) : c.action === 'update' ? w('req-contact-update', { who: who(c.name) }) : c.action === 'delete' ? w('req-contact-delete', { who: who(c.name) }) : c.action === 'attach' ? w('req-contact-photo', { who: who(c.name) }) : raw(c.action ?? 'contacts');
108
- if (c.name && c.action !== 'create') v.facts.push(fact('name', String(c.name)));
107
+ v.title = c.action === 'create' ? w('req-contact-add', { who: who(c.name || c.email) }) : c.action === 'update' ? w('req-contact-update', { who: who(about.name || c.name) }) : c.action === 'delete' ? w('req-contact-delete', { who: who(about.name || c.name) }) : c.action === 'attach' ? w('req-contact-photo', { who: who(about.name || c.name) }) : raw(c.action ?? 'contacts');
108
+ /* Who it is now (Tether reads the contact before a change or a delete, 05-11), then what changes. */
109
+ if (about.name && c.action !== 'create') v.facts.push(fact('name', String(about.name)));
110
+ if (about.email && c.action !== 'create' && about.email !== c.email) v.facts.push(fact('email', String(about.email)));
111
+ if (c.name && c.action !== 'create' && c.name !== about.name) v.facts.push(fact('name', String(c.name)));
109
112
  if (c.email) v.facts.push(fact('email', String(c.email)));
110
113
  if (c.phone) v.facts.push(fact('phone', String(c.phone)));
111
114
  if (where) sub.push(where);
package/server/main.mjs CHANGED
@@ -459,7 +459,7 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
459
459
  mailbox, a calendar, an address book -- held here with their secrets read from
460
460
  the vault by name, never in a machine: see tethers.mjs. */
461
461
  /* Voice boxes are Tether targets too (boxes.mjs): their connector reaches them through `boxes`, made below. */
462
- const tethers = new Tethers({ dataDir, resources: folders, conversations: () => all.list().map((c) => c.name), secrets, connectors: { voicebox: { run: (...a) => voiceboxConnector(boxes).run(...a) } } });
462
+ const tethers = new Tethers({ dataDir, resources: folders, conversations: () => all.list().map((c) => c.name), secrets, dockets, connectors: { voicebox: { run: (...a) => voiceboxConnector(boxes).run(...a) } } });
463
463
  const stopTethers = tethers.start();
464
464
  /* Connecting a mailbox, calendar or address book by token: the consent happens
465
465
  in the owner's browser, the refresh token is kept host-only (never in a
package/server/talk.mjs CHANGED
@@ -166,6 +166,9 @@ export const EVENT_LEVELS = Object.freeze({
166
166
  Assets, or by the agent) is a trace that carries the call's id, so the buttons close with it. */
167
167
  'tether-demande': 'needs-you',
168
168
  'tether-done': 'trace',
169
+ /* Something that happened later to what its agent did (a mail that came back, an invitation declined):
170
+ news, raised to needs-you when it failed or was refused (tethers.mjs). */
171
+ 'tether-notice': 'news',
169
172
  });
170
173
  const TONES = ['warn', 'bad'];
171
174
  /* Bounds of a line: its text, its group (topic), what the grouped line says of it (brief), its buttons. */
@@ -29,19 +29,43 @@ export const FOLDER = '.tether';
29
29
  export const PUMP_MS = 1000;
30
30
  const AGENT = 'conversation:';
31
31
  export const USB_DEVICE = 'usb-device';
32
+ /* Accepted calls whose result is awaited, at most (an act that never ends is forgotten after these). */
33
+ const ACTING_MAX = 200;
34
+ /* Notices already said (their ids), at most: each said once, across restarts. */
35
+ const NOTICES_MAX = 1000;
36
+
37
+ /* SOMETHING THAT HAPPENED LATER to what an agent did (Tether's notices: a mail that came back, a scheduled
38
+ send that failed, an invitation declined). One short head per kind, said before Tether's own sentence;
39
+ a failure, a bounce, a decline is a warning (needs the person), a delay or a late send is news. */
40
+ const NOTICE_HEADS = {
41
+ 'mail.bounced': 'Mail came back',
42
+ 'mail.delayed': 'Mail delayed',
43
+ 'mail.send-failed': 'Mail not sent',
44
+ 'mail.later-failed': 'Scheduled mail not sent',
45
+ 'mail.later-unsure': 'Scheduled mail maybe sent',
46
+ 'mail.later-late': 'Scheduled mail sent late',
47
+ 'mail.sent-late': 'Mail sent late',
48
+ 'mail.later-draft-kept': 'Scheduled mail sent, draft kept',
49
+ 'calendar.declined': 'Invitation declined',
50
+ };
51
+ const NOTICE_INFO = /\.(delayed|later-late|sent-late)$/;
52
+ export const noticeHead = (kind) => NOTICE_HEADS[kind] ?? 'Later news';
53
+ export const noticeWarns = (kind) => !NOTICE_INFO.test(String(kind ?? ''));
32
54
 
33
55
  export class Tethers {
34
- #keeper; #resources; #conversations; #secrets; #timers = []; #changes = 0; #seen = new Map(); #offered; #ended = new Map();
56
+ #keeper; #resources; #conversations; #secrets; #dockets; #timers = []; #changes = 0; #seen = new Map(); #offered; #noticed; #ended = new Map(); #acting = [];
35
57
  /* Set by the server once the thread is ready (main.mjs): (name, event) => talk.event(...).
36
58
  A call waiting for the owner is said in its conversation's thread when there is one. */
37
59
  announce = null;
38
60
 
39
61
  /* `resources`: Resources (workFolder). `conversations()`: the names of the conversations.
40
- `secrets`: the vault, read by name for a connector only (reveal). */
41
- constructor({ dataDir, resources, conversations, secrets, connectors, now = () => Date.now() }) {
42
- this.#resources = resources; this.#conversations = conversations; this.#secrets = secrets;
62
+ `secrets`: the vault, read by name for a connector only (reveal). `dockets`: { on(name), post(name,
63
+ {kind, text, data}) } (dockets.mjs): what wakes an agent told of a notice. `make`: the keeper (tests). */
64
+ constructor({ dataDir, resources, conversations, secrets, connectors, dockets = null, now = () => Date.now(), make = keeper }) {
65
+ this.#resources = resources; this.#conversations = conversations; this.#secrets = secrets; this.#dockets = dockets;
43
66
  this.#offered = new JsonFile(`${dataDir}/tether-offered.json`, []);
44
- this.#keeper = keeper(`${dataDir}/tether`, { sides: () => this.#sides(), secrets: (name) => this.#reveal(name), now, ...(connectors ? { connectors } : {}) });
67
+ this.#noticed = new JsonFile(`${dataDir}/tether-notices-seen.json`, []);
68
+ this.#keeper = make(`${dataDir}/tether`, { sides: () => this.#sides(), secrets: (name) => this.#reveal(name), notify: (n) => this.#notified(n), now, ...(connectors ? { connectors } : {}) });
45
69
  /* Every change a page shows -- a new approval waiting, one decided, the targets,
46
70
  the journal -- bumps the counter the client watches, so the approvals screen
47
71
  sees them all at once, not only when a store change happens to wake it. */
@@ -50,6 +74,9 @@ export class Tethers {
50
74
  const end = what?.approvals;
51
75
  if (end?.op === 'end' && end.id) this.#ended.set(end.id, String(end.decision ?? ''));
52
76
  this.#changes++; this.#tellNew();
77
+ /* An accepted call is said again once it was done, with how it went: Tether journals each act
78
+ when it ends (ok, or its error). */
79
+ if (what?.journal) this.#tellResult(what.journal);
53
80
  });
54
81
  /* A device plugged into the owner's computer: one target, always there, flashed from the
55
82
  owner's browser (Tether's device connector). The owner gives it to a conversation as any other. */
@@ -73,7 +100,7 @@ export class Tethers {
73
100
  const who = r.agent?.id ?? '';
74
101
  if (!who.startsWith(AGENT)) continue;
75
102
  const name = who.slice(AGENT.length);
76
- this.#seen.set(r.id, { name, verb: r.verb ?? 'action' });
103
+ this.#seen.set(r.id, { name, verb: r.verb ?? 'action', agent: who, target: r.target?.id ?? '' });
77
104
  const what = [r.verb ?? 'action', r.detail].filter(Boolean).join(' ');
78
105
  const text = [what, r.target?.title ? `(${r.target.title})` : '', r.why ? `-- ${r.why}` : ''].filter(Boolean).join(' ');
79
106
  /* `request`: the card Parley draws (demandes.mjs); the text and its buttons stay for an older screen. */
@@ -98,11 +125,61 @@ export class Tethers {
98
125
  this.#seen.delete(id);
99
126
  const outcome = this.#ended.get(id) ?? '';
100
127
  this.#ended.delete(id);
101
- try { this.announce(info.name, { kind: 'tether-done', text: `Request handled: ${info.verb}${outcome ? ` (${outcome})` : ''}`, topic: 'Demande', brief: id, ...(outcome ? { outcome } : {}) }); } catch { /* its chat is off */ }
128
+ /* Accepted is not done (05-11: "Request handled (yes)" was said before the act, which could still
129
+ fail): said as being done, and its result said when Tether journals it (#tellResult). */
130
+ const accepted = outcome === 'yes' || outcome === 'always';
131
+ if (accepted) { this.#acting.push({ id, ...info }); if (this.#acting.length > ACTING_MAX) this.#acting.shift(); }
132
+ const text = accepted ? `Accepted: ${info.verb} — being done` : `Request handled: ${info.verb}${outcome ? ` (${outcome})` : ''}`;
133
+ try { this.announce(info.name, { kind: 'tether-done', text, topic: 'Demande', brief: id, ...(outcome ? { outcome } : {}) }); } catch { /* its chat is off */ }
102
134
  }
103
135
  for (const id of [...this.#ended.keys()]) if (!this.#seen.has(id)) this.#ended.delete(id);
104
136
  }
105
137
 
138
+ /* AN ACCEPTED CALL, DONE OR FAILED: the journal line of the act (it carries ok, or its error). Matched by
139
+ the request's id where Tether writes it in the line (0.1.0-next.52 on), else by who, which target and
140
+ which verb -- the oldest accepted call of that kind still waiting for its result. Said in its thread:
141
+ done, a trace; failed, it needs the person, with the reason. */
142
+ #tellResult(l) {
143
+ if (!this.announce || !l || l.op || l.ok === undefined || !(l.decision === 'yes' || l.decision === 'always')) return;
144
+ const i = l.request ? this.#acting.findIndex((x) => x.id === l.request)
145
+ : this.#acting.findIndex((x) => x.agent === l.agent?.id && x.target === (l.target?.id ?? '') && x.verb === l.verb);
146
+ if (i < 0) return;
147
+ const [call] = this.#acting.splice(i, 1);
148
+ const failed = l.ok === false;
149
+ const text = failed ? `Failed: ${call.verb}${l.error ? ` — ${l.error}` : ''}` : `Done: ${call.verb}`;
150
+ try { this.announce(call.name, { kind: 'tether-done', text, topic: 'Demande', ...(failed ? { tone: 'bad', level: 'needs-you' } : {}) }); } catch { /* its chat is off */ }
151
+ }
152
+
153
+ /* A NOTICE (Tether calls `notify`): said once in the thread of the conversation whose agent did it,
154
+ and that agent woken through its docket where its chat is on (elsewhere its next Tether call
155
+ tells it: Tether puts what is new first in its answer). Each notice id kept, so a notice handed
156
+ twice -- or again after a restart -- is said once. An agent that is no conversation of this server: nothing. */
157
+ #notified(n) {
158
+ const id = String(n?.id ?? '');
159
+ const who = String(n?.agent ?? '');
160
+ if (!id || !who.startsWith(AGENT)) return;
161
+ const name = who.slice(AGENT.length);
162
+ let names;
163
+ try { names = this.#conversations(); } catch { return; }
164
+ if (!name || !names.includes(name)) return;
165
+ const seen = this.#noticed.get();
166
+ if (!Array.isArray(seen) || seen.includes(id)) return;
167
+ try { this.#noticed.set([...seen, id].slice(-NOTICES_MAX)); } catch { /* said anyway, this once */ }
168
+ const kind = String(n.kind ?? '');
169
+ const head = noticeHead(kind);
170
+ const warns = noticeWarns(kind);
171
+ const said = String(n.text ?? '').trim();
172
+ const where = n.target?.title ? ` (${n.target.title})` : '';
173
+ const text = `${head}${where}${said ? `: ${said}` : ''}`;
174
+ try { this.announce?.(name, { kind: 'tether-notice', text, topic: 'Notice', ...(warns ? { tone: 'warn', level: 'needs-you' } : {}) }); } catch { /* its chat is off */ }
175
+ try {
176
+ if (this.#dockets?.on(name)) {
177
+ this.#dockets.post(name, { kind: 'tether-notice', text: `${text}${/[.!?]$/.test(text) ? '' : '.'} See more: tether notices.`,
178
+ data: { notice: id, kind, ...(n.ref ? { ref: String(n.ref) } : {}), ...(n.target?.id ? { target: String(n.target.id) } : {}) } });
179
+ }
180
+ } catch { /* its docket: its next Tether call tells it */ }
181
+ }
182
+
106
183
  /* A secret's value for a connector, by name, from this server's vault; never seen by the agent.
107
184
  An unknown or expired secret is a plain refusal the connector turns into "Refused". */
108
185
  async #reveal(name) {
package/web/app.js CHANGED
@@ -3387,6 +3387,7 @@
3387
3387
  ['docket-failed', 'Could not be handled', 'Said failed by the tool, with why'],
3388
3388
  ['docket-unhandled', 'Not handled', 'Told three times, never said done'],
3389
3389
  ['docket-reminder', 'Reminder set', 'A reminder the tool set itself'],
3390
+ ['tether-notice', 'Later news', 'A mail came back, an invitation was declined'],
3390
3391
  ['machine-problem', 'Machine in trouble', 'Memory, disk, no answer, a failed restart'],
3391
3392
  ['machine-ok', 'Machine well again', 'What was wrong with it went away'],
3392
3393
  ['restarted', 'Machine restarted', 'Restarted or built again'],