clavarium 0.2.450-next.1 → 0.2.451-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.450-next.1",
3
+ "version": "0.2.451-next.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "clavarium",
9
- "version": "0.2.450-next.1",
9
+ "version": "0.2.451-next.1",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@xterm/addon-fit": "^0.11.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.450-next.1",
3
+ "version": "0.2.451-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.",
package/server/api.mjs CHANGED
@@ -27,7 +27,7 @@
27
27
  * POST /api/conversations/<name>/erase {confirm: <its name>}: deleted for good -- its machine and its work files
28
28
  * POST /api/conversations/<name>/into-machine {machine, machineMb?}: moved into a shared machine (#221), its tool's state along (202);
29
29
  * {} (no machine): out of its shared machine, into one of its own (15-11)
30
- * POST /api/conversations/<name>/copy {title?, machine?, machineMb?}: a copy -- its work, its tool's state, its accesses; it untouched (202)
30
+ * POST /api/conversations/<name>/copy {title?, machine?, machineMb?, reminders?}: a copy -- its work, its tool's state, its accesses (its reminders and wake-ups when asked); it untouched (202)
31
31
  * POST /api/conversations/<name>/rebuild {reset?, confirm?}: built again; reset (confirm: its name) for a working one too
32
32
  * POST /api/conversations/<name>/ask-first {on}: its tool asks before acting (true), or acts without asking in its machine (false, the default), from its next start
33
33
  * POST /api/conversations/<name>/resume {on}: its tool takes up its last session when it starts (true), or starts fresh
@@ -1041,7 +1041,7 @@ export async function handleApi(request, response, conversations, headers, resou
1041
1041
  if (copying) {
1042
1042
  const machineMb = body?.machineMb === undefined ? undefined : Number(body.machineMb);
1043
1043
  const machine = typeof body?.machine === 'string' && body.machine ? body.machine : undefined;
1044
- return send(202, await conversations.copy(decodeURIComponent(copying[1]), { title: body?.title, machine, machineMb })), true;
1044
+ return send(202, await conversations.copy(decodeURIComponent(copying[1]), { title: body?.title, machine, machineMb, reminders: body?.reminders === true })), true;
1045
1045
  }
1046
1046
  const again = /^\/api\/conversations\/([^/]+)\/rebuild$/.exec(pathname);
1047
1047
  if (again) {
@@ -1103,11 +1103,11 @@ export class Conversations {
1103
1103
 
1104
1104
  /* A COPY OF A CONVERSATION (#221, 13-11, its owner's ask: safer than a move -- nothing is destroyed). A new
1105
1105
  conversation, in a machine of its own or a shared one, with what its original has: its work folder (its
1106
- chat with it), its tool's state (the AI's memory), its settings, and the accesses it was given. Its devices,
1107
- its reminders and its pending asks are NOT copied: one of the two answers them, the original. Its original is
1106
+ chat with it), its tool's state (the AI's memory), its settings, and the accesses it was given; its reminders
1107
+ and wake-ups only when asked (`reminders`, 15-11). Its devices and its pending asks are NOT copied: one of the two answers them, the original. Its original is
1108
1108
  not touched; asleep, its machine is woken the time to read its tool's state, then put to sleep again.
1109
1109
  -> the copy's record, at once; `this.copied`: the end of it. */
1110
- async copy(name, { title, machine, machineMb } = {}) {
1110
+ async copy(name, { title, machine, machineMb, reminders = false } = {}) {
1111
1111
  const c = this.#store.get(name);
1112
1112
  if (!c) throw new Refusal(404, 'No such conversation.');
1113
1113
  if (c.phase !== 'ready') throw new Refusal(409, 'It is busy: copy it once it is ready.');
@@ -1127,11 +1127,11 @@ export class Conversations {
1127
1127
  this.#holding.add(made.name);
1128
1128
  this.#store.patch(made.name, { copyOf: name });
1129
1129
  const building = this.built;
1130
- this.copied = this.#copying(name, made.name, c, tool, building, open);
1130
+ this.copied = this.#copying(name, made.name, c, tool, building, open, reminders === true);
1131
1131
  return this.#store.get(made.name);
1132
1132
  }
1133
1133
 
1134
- async #copying(from, to, c, tool, building, open = () => {}) {
1134
+ async #copying(from, to, c, tool, building, open = () => {}, reminders = false) {
1135
1135
  const dir = mkdtempSync(join(tmpdir(), 'clv-copy-'));
1136
1136
  const carried = join(dir, 'state.tar.gz');
1137
1137
  let woke = false; let putBack = 'sleep';
@@ -1240,6 +1240,8 @@ export class Conversations {
1240
1240
  }
1241
1241
  this.#store.patch(to, { step: 'Giving it the same accesses' });
1242
1242
  await this.copyRights(from, to);
1243
+ /* Its reminders and wake-ups too, when asked (15-11): an unticked box on the copy's last screen. */
1244
+ if (reminders && typeof this.copyReminders === 'function') await Promise.resolve().then(() => this.copyReminders(from, to)).catch(() => {});
1243
1245
  this.#holding.delete(to);
1244
1246
  if (!this.#store.get(to)) return undefined;
1245
1247
  this.#store.patch(to, { phase: 'ready', step: undefined, progress: undefined, buildingSince: undefined, error: undefined });
@@ -24,12 +24,28 @@
24
24
  * The folder is the work folder's .docket, beside .parley: the tool writes
25
25
  * there, so nothing in it is trusted (the library bounds and cleans it).
26
26
  */
27
- import { mkdirSync, lstatSync } from 'node:fs';
27
+ import { mkdirSync, lstatSync, readFileSync, writeFileSync } from 'node:fs';
28
+ import { join } from 'node:path';
28
29
  import { Docket, WAKE } from 'clavarium-docket/host';
29
30
  import { verbs } from 'clavarium-docket/server';
30
31
 
31
32
  export { WAKE };
32
33
  export const FOLDER = '.docket';
34
+
35
+ /* A COPY'S REMINDERS (15-11, asked when it is copied): the reminders its original's tool set (plans.jsonl in its
36
+ docket folder), those still to come -- a repeating one, or one due later -- written in the copy's; one taken
37
+ back, or past, is not. Its events and their answers stay the original's. -> how many. */
38
+ export function copyPlans(fromWork, toWork, now = Date.now()) {
39
+ const lines = (file) => { try { return readFileSync(join(fromWork, FOLDER, file), 'utf8').split('\n').filter(Boolean).map((l) => { try { return JSON.parse(l); } catch { return null; } }).filter(Boolean); } catch { return []; } };
40
+ const off = new Set(lines('plans-off.jsonl').map((o) => o.plan));
41
+ const kept = lines('plans.jsonl').filter((p) => p.kind === 'plan' && !off.has(p.id) && (p.cron || (p.due && Date.parse(p.due) > now)));
42
+ if (!kept.length) return 0;
43
+ mkdirSync(join(toWork, FOLDER), { recursive: true });
44
+ let zone = null; try { zone = readFileSync(join(fromWork, FOLDER, 'zone'), 'utf8'); } catch { /* none */ }
45
+ if (zone !== null) writeFileSync(join(toWork, FOLDER, 'zone'), zone);
46
+ writeFileSync(join(toWork, FOLDER, 'plans.jsonl'), kept.map((p) => JSON.stringify(p)).join('\n') + '\n', { flag: 'a' });
47
+ return kept.length;
48
+ }
33
49
  export const TICK_MS = 5000;
34
50
  /* An event not acknowledged is told again after this long, the tool idle... */
35
51
  export const AGAIN_MS = 30 * 60_000;
package/server/main.mjs CHANGED
@@ -41,7 +41,7 @@ import { Secrets, RUNNER } from './secrets.mjs';
41
41
  import { scan, secretRef } from './secret-scan.mjs';
42
42
  import { Network } from './network.mjs';
43
43
  import { Answerer, answererConfig } from './answerer.mjs';
44
- import { Dockets } from './dockets.mjs';
44
+ import { Dockets, copyPlans } from './dockets.mjs';
45
45
  import { PULSE_MS } from 'clavarium-parley/ui';
46
46
  import { Wakeups, TypingWatch, CALL_PATH } from './wakeups.mjs';
47
47
  import { Alerts } from './alerts.mjs';
@@ -680,6 +680,8 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
680
680
  all.copyWork = (from, to, onProgress) => copyWorkFolder(folders.workFolder(from), folders.workFolder(to), onProgress);
681
681
  /* Where a conversation's work folder is on this side: a copy reads its tool's memory through it (14-11). */
682
682
  all.workFolder = (name) => folders.workFolder(name);
683
+ /* Its reminders and wake-ups, when the copy asked for them (15-11). */
684
+ all.copyReminders = (from, to) => { copyPlans(folders.workFolder(from), folders.workFolder(to)); wakeups.copyTo(from, to); };
683
685
  all.copyRights = async (from, to) => {
684
686
  for (const r of folders.of(from)) {
685
687
  if (r.access === 'write') gitKeeper?.beforeWriter(r.name, to, true);
@@ -179,7 +179,7 @@ export const SETTINGS_WORDS_FR = {
179
179
  'set-cm-own-to': 'sa propre machine', 'set-cm-copy-to': 'Copier {t} vers {where}', 'set-cm-move-to': 'Déplacer {t} dans {where}',
180
180
  'set-cm-new-line': 'Nouvelle machine partagée · {size}', 'set-cm-copy-name': 'Nom de la copie',
181
181
  'set-cm-goes-work': 'Son dossier de travail', 'set-cm-goes-memory': 'La mémoire de son IA', 'set-cm-goes-access': 'Ses accès',
182
- 'set-cm-not': 'Ni ses appareils, ni ses rappels', 'set-cm-untouched': 'Celle-ci intacte : lue, puis remise en l\'état',
182
+ 'set-cm-reminders': 'Ses rappels et réveils aussi', 'set-cm-not-devices': 'Pas ses appareils', 'set-cm-untouched': 'Celle-ci intacte : lue, puis remise en l\'état',
183
183
  'set-cm-stay': 'Vous restez ici · « Ouvrir » une fois prête', 'set-cm-stops': 'Son outil s\'arrête environ une minute',
184
184
  'set-cm-deleted': 'Sa propre machine est supprimée', 'set-cm-stops-out': 'Son outil s\'arrête quelques minutes', 'set-cm-shared-deleted': 'La machine partagée « {m} » est supprimée', 'set-cm-place-deleted': 'Sa place dans « {m} » est supprimée', 'set-cm-back': 'Retour', 'set-cm-copy-go': 'La copier', 'set-cm-move-go': 'La déplacer',
185
185
  'set-cm-ready': 'Copie prête', 'set-cm-open': 'Ouvrir', 'set-cm-failed': 'Pas copiée', 'set-cm-see-why': 'Voir pourquoi',
@@ -234,6 +234,18 @@ export class Wakeups {
234
234
  return once ? { ...this.of(name), address: `${CALL_PATH}${once}` } : this.of(name);
235
235
  }
236
236
 
237
+ /* A COPY'S WAKE-UPS (15-11, asked when it is copied): its original's, each its own again (a new id, its clock
238
+ counted from now); a call from outside is not -- its address is the original's, said once and never again. */
239
+ copyTo(from, to) {
240
+ this.#known(from); this.#known(to);
241
+ const was = this.#record(from);
242
+ const now = this.#now().toISOString();
243
+ const items = was.items.filter((i) => i.kind !== 'call').map(({ last, ...i }) => ({ ...i, id: randomUUID(), made: now, last: null, ...(i.fired !== undefined ? { fired: now } : {}) }));
244
+ const r = this.#record(to);
245
+ this.#store.put({ ...r, perHour: was.perHour, items: [...r.items, ...items].slice(0, ITEMS_MAX) });
246
+ return this.of(to);
247
+ }
248
+
237
249
  #change(name, id, change) {
238
250
  this.#known(name);
239
251
  const r = this.#record(name);
package/web/app.js CHANGED
@@ -3321,6 +3321,7 @@
3321
3321
  Object.assign(cm, { of: here.name, kind, place: kind === 'copy' || here.sharedMachine ? '' : (sharedMachines().find((m) => m.name !== here.sharedMachine)?.name ?? 'new') });
3322
3322
  $('machine-names').replaceChildren(...sharedMachines().map((m) => Object.assign(document.createElement('option'), { value: m.name })));
3323
3323
  $('cm-copy-title').value = `${here.title ?? here.name} (copy)`;
3324
+ $('cm-reminders').checked = false;
3324
3325
  /* Its sheep: two for a copy (the second slides out of the first), one walking for a move. */
3325
3326
  if (!$('cm-sheep').childElementCount) $('cm-sheep').innerHTML = `<div class="mascot cm-one">${MASCOTS[MASCOT]()}</div><div class="mascot cm-one">${MASCOTS[MASCOT]()}</div>`;
3326
3327
  $('cm-choose').hidden = false; $('cm-check').hidden = true;
@@ -3376,7 +3377,7 @@
3376
3377
  }
3377
3378
  const title = $('cm-copy-title').value.trim() || `${here.title ?? here.name} (copy)`;
3378
3379
  try {
3379
- const made = await post(`${API}/conversations/${encodeURIComponent(name)}/copy`, { title, ...goes.body });
3380
+ const made = await post(`${API}/conversations/${encodeURIComponent(name)}/copy`, { title, ...goes.body, ...($('cm-reminders').checked ? { reminders: true } : {}) });
3380
3381
  if (made?.name) copiesWatched.add(made.name);
3381
3382
  await refresh();
3382
3383
  } catch (error) { cmToast(`✗ ${error.message}`, 'bad'); }
package/web/index.html CHANGED
@@ -1515,7 +1515,8 @@
1515
1515
  <label class="cm-label" for="cm-copy-title" data-said="set-cm-copy-name">Name of the copy</label>
1516
1516
  <input id="cm-copy-title" maxlength="60">
1517
1517
  <ul class="cm-goes"><li data-said="set-cm-goes-work">Its work folder</li><li data-said="set-cm-goes-memory">Its AI's memory</li><li data-said="set-cm-goes-access">Its accesses</li></ul>
1518
- <p class="cm-not" data-said="set-cm-not">Not its devices, nor its reminders</p>
1518
+ <label class="cm-tick"><input type="checkbox" id="cm-reminders"> <span data-said="set-cm-reminders">Its reminders and wake-ups too</span></label>
1519
+ <p class="cm-not" data-said="set-cm-not-devices">Not its devices</p>
1519
1520
  <p class="cm-box" data-said="set-cm-untouched">This one: untouched (woken or started to read it, then put back as it was)</p>
1520
1521
  <p class="cm-box" data-said="set-cm-stay">You stay here · « Open it » when it is ready</p>
1521
1522
  </div>
package/web/style.css CHANGED
@@ -500,7 +500,7 @@ details.chapter.reached { outline: 2px solid var(--brass); outline-offset: 2px;
500
500
  .facts dd { margin: 0; overflow-wrap: anywhere; }
501
501
  #machine-size, #shared-size { display: flex; flex-direction: column; gap: 6px; max-width: 30rem; }
502
502
  #machine-size label, #shared-size label { font-size: .8125rem; color: var(--ink2); }
503
- #machine-size select, #shared-size select, #cm :is(select, input) { width: 100%; min-height: 40px; font: .875rem var(--sans); color: var(--ink); background-color: var(--bg); border: 1px solid var(--line); border-radius: 7px; padding: 6px 8px; }
503
+ #machine-size select, #shared-size select, #cm :is(select, input:not([type=checkbox])) { width: 100%; min-height: 40px; font: .875rem var(--sans); color: var(--ink); background-color: var(--bg); border: 1px solid var(--line); border-radius: 7px; padding: 6px 8px; }
504
504
  .health-lines { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
505
505
  .health-lines li { padding-left: 1.3em; position: relative; }
506
506
  .health-lines li::before { content: ""; position: absolute; left: .2em; top: .45em; width: .55em; height: .55em; border-radius: 50%; background: var(--ok); }
@@ -3122,6 +3122,8 @@ a.button[aria-disabled] { opacity: .5; pointer-events: none; }
3122
3122
  .cm-goes { list-style: none; margin: 2px 0 0; padding: 0; font-size: .875rem; color: var(--ok); }
3123
3123
  .cm-goes li::before { content: "\2713\00a0"; }
3124
3124
  .cm-not { margin: 0; font-size: .75rem; color: var(--ink2); }
3125
+ .cm-tick { display: flex; align-items: center; justify-content: flex-start; gap: .5rem; font-size: .85rem; cursor: pointer; }
3126
+ #cm .cm-tick input { width: 18px; height: 18px; flex: none; margin: 0; accent-color: var(--brass); }
3125
3127
  .cm-box { margin: 0; padding: 8px 11px; font-size: .875rem; border: 1px solid var(--line); border-radius: 8px; }
3126
3128
  .cm-box.cm-danger { color: var(--danger); border-color: var(--danger); font-weight: 600; }
3127
3129
  .cm-acts { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }