clavarium 0.2.407-next.1 → 0.2.409-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.
package/deploy/git-read CHANGED
@@ -67,8 +67,15 @@ format=$(g rev-parse --show-object-format) || failed $? "GIT COULD NOT OPEN THE
67
67
 
68
68
  refs=$(g for-each-ref --format='%(objectname) %(refname)' refs/heads/) || failed $? "GIT COULD NOT LIST THE BRANCHES"
69
69
  listed=$(printf '%s\n' "$refs" | sed -n 's|^[0-9a-f]\{40\} ||p' | sort -u)
70
+ # A file or folder whose name starts with a dot is no ref, for git either: no
71
+ # ref name may have a part that starts with one (check-ref-format), so git
72
+ # can never make it and never lists it. Such files do appear on their own:
73
+ # a folder shared into a machine (sshfs, FUSE) keeps a ref file that was
74
+ # replaced while something still had it open as .fuse_hidden<number>, beside
75
+ # the new one, until it is closed. Counted, it refused healthy repositories
76
+ # as "broken or changing".
70
77
  on_disk=$( {
71
- [ -d .git/refs/heads ] && find -L .git/refs/heads -type f ! -name '*.lock' -printf 'refs/heads/%P\n'
78
+ [ -d .git/refs/heads ] && find -L .git/refs/heads -mindepth 1 -name '.*' -prune -o -type f ! -name '*.lock' -printf 'refs/heads/%P\n'
72
79
  [ -f .git/packed-refs ] && sed -n 's|^[0-9a-f]\{40\} \(refs/heads/.*\)$|\1|p' .git/packed-refs
73
80
  } | sort -u)
74
81
  [ "$listed" = "$on_disk" ] || { echo "BROKEN OR CHANGING REFS" >&2; exit 66; }
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.407-next.1",
3
+ "version": "0.2.409-next.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "clavarium",
9
- "version": "0.2.407-next.1",
9
+ "version": "0.2.409-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.407-next.1",
3
+ "version": "0.2.409-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.",
@@ -369,12 +369,9 @@ export class GitReview {
369
369
  const pick = branch === undefined || branch === null || branch === '' ? undefined : asBranch(branch);
370
370
  const remote = this.#remoteOf(r) ?? null;
371
371
  const nothing = nothingOut(remote);
372
- if (remote) {
373
- const fresh = await this.refresh(r.name, { waitMs: REVIEW_WAIT_MS });
374
- if (!fresh.ok) return { ...nothing, state: 'unreachable', branch: pick ?? null, target: asked ?? null, message: `The remote did not answer as expected: ${fresh.message}` };
375
- }
376
- let got;
377
- try { got = await this.#read(r); } catch (error) {
372
+ const { fresh, got, error } = await this.#refreshAndRead(r, remote);
373
+ if (fresh && !fresh.ok) return { ...nothing, state: 'unreachable', branch: pick ?? null, target: asked ?? null, message: `The remote did not answer as expected: ${fresh.message}` };
374
+ if (error) {
378
375
  if (error instanceof GitFailure && error.kind === 'empty') return { ...nothing, state: 'empty', branch: null, target: asked ?? null, message: 'Nothing has been committed on a branch in this repository yet.' };
379
376
  throw error;
380
377
  }
@@ -387,6 +384,23 @@ export class GitReview {
387
384
  } finally { got.remove(); }
388
385
  }
389
386
 
387
+ /* A review's two slow steps AT THE SAME TIME: the fetch from the remote
388
+ (a trip over the network) and the read of the agent's repository (the
389
+ host program's sandbox). Neither needs the other: the read never
390
+ touches the reference, which is lent to its workspace only after,
391
+ under the reference's lock. One after the other, a page of ten
392
+ repositories waited for the sum of both, ten times over.
393
+ { fresh, got, error }: `fresh` the refresh's outcome (none without a
394
+ remote); `got` the read, or `error` why it failed. A read made for a
395
+ remote that did not answer is deleted here. */
396
+ async #refreshAndRead(r, remote) {
397
+ const reading = this.#read(r).then((got) => ({ got }), (error) => ({ error }));
398
+ const fresh = remote ? await this.refresh(r.name, { waitMs: REVIEW_WAIT_MS }).catch((error) => { void reading.then(({ got }) => got?.remove()); throw error; }) : null;
399
+ const read = await reading;
400
+ if (fresh && !fresh.ok) { read.got?.remove(); return { fresh }; }
401
+ return { fresh, ...read };
402
+ }
403
+
390
404
  /* TO SEND, A WHOLE REPOSITORY AT ONCE: one fetch (shared with any on
391
405
  its way), ONE read of the agent's repository, then each of its
392
406
  branches that moved last (up to 1 + `more`) compared in that same
@@ -401,12 +415,9 @@ export class GitReview {
401
415
  const r = this.#repository(name);
402
416
  const remote = this.#remoteOf(r) ?? null;
403
417
  const base = { remote, agentBranches: [], dropped: [], rows: [], more: 0, asOf: this.#now().toISOString() };
404
- if (remote) {
405
- const fresh = await this.refresh(r.name, { waitMs: REVIEW_WAIT_MS });
406
- if (!fresh.ok) return { ...base, state: 'unreachable', message: `The remote did not answer as expected: ${fresh.message}` };
407
- }
408
- let got;
409
- try { got = await this.#read(r); } catch (error) {
418
+ const { fresh, got, error } = await this.#refreshAndRead(r, remote);
419
+ if (fresh && !fresh.ok) return { ...base, state: 'unreachable', message: `The remote did not answer as expected: ${fresh.message}` };
420
+ if (error) {
410
421
  if (error instanceof GitFailure && error.kind === 'empty') return { ...base, state: 'empty', message: 'Nothing has been committed on a branch in this repository yet.' };
411
422
  throw error;
412
423
  }
@@ -497,13 +508,17 @@ export class GitReview {
497
508
  const remoteTip = remoteTips.get(to) ?? null;
498
509
  let shown; let behind = null; let inRemote = false; let containsRemote = true;
499
510
  if (remoteTip) {
500
- shown = await this.#compare(ws, { head, base: remoteTip, range: [head], negatives: [remoteTip] });
501
511
  /* The state rests on ancestry, asked directly, never on a
502
512
  count: a count that failed must not read as 0, "already
503
- there", nor as "nothing behind". */
504
- inRemote = await this.#ancestry(ws, head, remoteTip);
505
- containsRemote = await this.#ancestry(ws, remoteTip, head);
506
- const b = await this.#runner.in(ws, ['rev-list', '--count', '--end-of-options', remoteTip, `^${head}`], { deadlineMs: 120_000 });
513
+ there", nor as "nothing behind". Asked at the same time as
514
+ the comparison: none needs another's answer. */
515
+ const asked = [this.#compare(ws, { head, base: remoteTip, range: [head], negatives: [remoteTip] }), this.#ancestry(ws, head, remoteTip), this.#ancestry(ws, remoteTip, head),
516
+ this.#runner.in(ws, ['rev-list', '--count', '--end-of-options', remoteTip, `^${head}`], { deadlineMs: 120_000 })];
517
+ await Promise.allSettled(asked);
518
+ shown = await asked[0];
519
+ inRemote = await asked[1];
520
+ containsRemote = await asked[2];
521
+ const b = await asked[3];
507
522
  const text = b.stdout.toString('latin1').trim();
508
523
  behind = b.code === 0 && !b.killed && /^\d+$/.test(text) ? Number(text) : null;
509
524
  } else {
@@ -619,11 +634,29 @@ export class GitReview {
619
634
  const incomplete = [];
620
635
  const failed = (r) => r.code !== 0 || Boolean(r.killed) || Boolean(r.signal);
621
636
  const stopped = (r) => (r.killed === 'size' ? 'too long to read whole' : r.killed === 'deadline' ? 'stopped by its time limit' : 'git failed');
622
- const counted = await inWs(['rev-list', '--count', '--stdin', '--end-of-options'], { input: revs });
637
+ const compare = ['--text', '--no-ext-diff', '--no-textconv', '--no-color', '--end-of-options', base, head];
638
+ /* Every git below reads the same workspace and none needs another's
639
+ answer (but the weighing, which needs the list of objects): they
640
+ run at once, and what each says is taken in the same order as
641
+ before. One after the other, a branch waited for ten git processes
642
+ in a row, and To send for that, branch after branch. */
643
+ const running = {
644
+ counted: inWs(['rev-list', '--count', '--stdin', '--end-of-options'], { input: revs }),
645
+ log: inWs(['log', `--max-count=${COMMITS_MAX}`, '-z', '--format=%H%x00%P%x00%an%x00%ae%x00%aI%x00%B', '--stdin', '--end-of-options'], { input: revs, maxBytes: 8 * 1024 * 1024 }),
646
+ statRun: inWs(['diff', '--stat=100', ...compare], { maxBytes: 1024 * 1024 }),
647
+ whole: inWs(['diff', ...compare], { maxBytes: DIFF_MAX + 1 }),
648
+ sizeRun: inWs(['rev-list', '--objects', '--disk-usage', '--stdin', '--end-of-options'], { input: revs }),
649
+ objects: inWs(['rev-list', '--objects', '--stdin', '--end-of-options'], { input: revs, maxBytes: 32 * 1024 * 1024 }),
650
+ touchedRun: inWs(['log', '--name-only', '-z', '--format=', '--stdin', '--end-of-options'], { input: revs, maxBytes: 16 * 1024 * 1024 }),
651
+ netRun: inWs(['diff', '--name-only', '-z', '--no-renames', ...compare], { maxBytes: 16 * 1024 * 1024 }),
652
+ };
653
+ /* All of them settled before any answer is used: none is left running behind a failure. */
654
+ await Promise.allSettled(Object.values(running));
655
+ const counted = await running.counted;
623
656
  const countText = counted.stdout.toString('latin1').trim();
624
657
  const count = !failed(counted) && /^\d+$/.test(countText) ? Number(countText) : null;
625
658
  if (count === null) incomplete.push(`The commits could not be counted (${stopped(counted)}).`);
626
- const log = await inWs(['log', `--max-count=${COMMITS_MAX}`, '-z', '--format=%H%x00%P%x00%an%x00%ae%x00%aI%x00%B', '--stdin', '--end-of-options'], { input: revs, maxBytes: 8 * 1024 * 1024 });
659
+ const log = await running.log;
627
660
  const fields = log.stdout.toString('utf8').split('\0');
628
661
  /* Cut short: the last record may be a part of a commit. Not listed as if whole. */
629
662
  const records = failed(log) ? Math.floor((fields.length - 1) / 6) * 6 : fields.length;
@@ -638,22 +671,21 @@ export class GitReview {
638
671
  if (cutMessages > 0) incomplete.push(`${cutMessages} commit message(s) are longer than ${MESSAGE_MAX} characters: only their start is shown.`);
639
672
  if (failed(log)) incomplete.push(`The list of commits is not whole (${stopped(log)}): ${commits.length} listed.`);
640
673
  else if (count !== null && commits.length < Math.min(count, COMMITS_MAX)) incomplete.push(`Only ${commits.length} of ${count} commits could be listed.`);
641
- const compare = ['--text', '--no-ext-diff', '--no-textconv', '--no-color', '--end-of-options', base, head];
642
- const statRun = await inWs(['diff', '--stat=100', ...compare], { maxBytes: 1024 * 1024 });
674
+ const statRun = await running.statRun;
643
675
  if (failed(statRun)) incomplete.push(`The list of changed files is not whole (${stopped(statRun)}).`);
644
676
  const stat = escaped(statRun.stdout.toString('utf8'));
645
- const whole = await inWs(['diff', ...compare], { maxBytes: DIFF_MAX + 1 });
677
+ const whole = await running.whole;
646
678
  /* Cut by its size, or stopped for any other reason: either way not all of it is shown. */
647
679
  const cut = failed(whole) || whole.stdout.length > DIFF_MAX;
648
680
  if (failed(whole) && whole.killed !== 'size') incomplete.push(`The changes could not be shown whole (${stopped(whole)}).`);
649
681
  const diff = escaped(whole.stdout.subarray(0, DIFF_MAX).toString('utf8'));
650
682
  /* AGAINST HISTORY THE DIFF CANNOT SHOW: a file added then removed,
651
683
  a huge blob, more commits than a page lists. */
652
- const sizeRun = await inWs(['rev-list', '--objects', '--disk-usage', '--stdin', '--end-of-options'], { input: revs });
684
+ const sizeRun = await running.sizeRun;
653
685
  const sizeText = sizeRun.stdout.toString('latin1').trim();
654
686
  const newBytes = !failed(sizeRun) && /^\d+$/.test(sizeText) ? Number(sizeText) : null;
655
687
  if (newBytes === null) incomplete.push(`The size of the new data could not be measured (${stopped(sizeRun)}).`);
656
- const objects = await inWs(['rev-list', '--objects', '--stdin', '--end-of-options'], { input: revs, maxBytes: 32 * 1024 * 1024 });
688
+ const objects = await running.objects;
657
689
  if (failed(objects)) incomplete.push(`Not every new file could be weighed (${stopped(objects)}).`);
658
690
  const pathOf = new Map();
659
691
  for (const line of objects.stdout.toString('utf8').split('\n')) { const sp = line.indexOf(' '); if (sp === 40) pathOf.set(line.slice(0, 40), line.slice(41)); }
@@ -665,8 +697,8 @@ export class GitReview {
665
697
  .map(([id, , size]) => ({ id, size: Number(size), path: escaped(pathOf.get(id) ?? '').slice(0, 300) }))
666
698
  .sort((a, b) => b.size - a.size).slice(0, LARGEST);
667
699
  }
668
- const touchedRun = await inWs(['log', '--name-only', '-z', '--format=', '--stdin', '--end-of-options'], { input: revs, maxBytes: 16 * 1024 * 1024 });
669
- const netRun = await inWs(['diff', '--name-only', '-z', '--no-renames', ...compare], { maxBytes: 16 * 1024 * 1024 });
700
+ const touchedRun = await running.touchedRun;
701
+ const netRun = await running.netRun;
670
702
  if (failed(touchedRun) || failed(netRun)) incomplete.push(`The files changed and changed back could not all be found (${stopped(failed(touchedRun) ? touchedRun : netRun)}).`);
671
703
  const touched = new Set(touchedRun.stdout.toString('utf8').split('\0').map((p) => p.replace(/^\n+/, '')).filter(Boolean));
672
704
  const net = new Set(netRun.stdout.toString('utf8').split('\0').filter(Boolean));
package/web/index.html CHANGED
@@ -1446,7 +1446,7 @@
1446
1446
  <span class="sub-head">Where it lives</span>
1447
1447
  <div id="newconv-where" class="pick two" role="radiogroup" aria-label="Where it lives">
1448
1448
  <button type="button" role="radio" data-where="own" aria-checked="true"><b>Its own machine</b><small>All to itself</small></button>
1449
- <button type="button" role="radio" data-where="shared" aria-checked="false"><b>A shared machine</b><small>Lighter. For assistants</small></button>
1449
+ <button type="button" role="radio" data-where="shared" aria-checked="false"><b>A shared machine</b><small>Trial · lighter, for assistants</small></button>
1450
1450
  </div>
1451
1451
  <div class="set-row" id="newconv-machine-row" hidden><div class="set-what"><label for="newconv-machine">Machine</label><small>An existing one, or a new name</small><span id="newconv-machine-error" class="err" role="alert" hidden></span></div><div class="set-control"><input id="newconv-machine" maxlength="32" list="machine-names" placeholder="assistants" spellcheck="false" autocapitalize="off" autocomplete="off"><datalist id="machine-names"></datalist></div></div>
1452
1452
  <div class="set-row" id="newconv-machine-mb-row" hidden><div class="set-what"><label for="newconv-machine-mb">Its memory</label><small>Shared by the conversations in it</small></div><div class="set-control"><select id="newconv-machine-mb"><option value="2048">2 GB</option><option value="4096" selected>4 GB</option><option value="6144">6 GB</option><option value="8192">8 GB</option><option value="12288">12 GB</option><option value="16384">16 GB</option></select></div></div>