clavarium 0.2.56-beta.1 → 0.2.57-beta.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.56-beta.1",
3
+ "version": "0.2.57-beta.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "clavarium",
9
- "version": "0.2.56-beta.1",
9
+ "version": "0.2.57-beta.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.56-beta.1",
3
+ "version": "0.2.57-beta.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.",
@@ -211,9 +211,15 @@ const seeCommits = (name, head, base, n) => (short(head) && short(base) && Numbe
211
211
  long a finished run is kept for the request that asks again just after. */
212
212
  export const CHECK_WAIT_MS = 20_000;
213
213
  export const CHECK_KEEP_MS = 60_000;
214
+ /* A send (the push to the remote) runs in the background, like a check: one
215
+ request waits at most this long, then hears { status: 'sending' } and asks
216
+ again (join), so a long push never outruns the proxy. The push itself is
217
+ already bounded (PUSH_MS); a finished send is kept this long for the asking. */
218
+ export const SENDING_WAIT_MS = 20_000;
219
+ export const SENDING_KEEP_MS = 60_000;
214
220
 
215
221
  export class GitKeeper {
216
- #store; #review; #resources; #checks; #alerts; #now; #tellAgent; #thread; #last; #held = new Map(); #results = new Map(); #running = new Set(); #telling = new Map(); #inFlight = new Map();
222
+ #store; #review; #resources; #checks; #alerts; #now; #tellAgent; #thread; #last; #held = new Map(); #results = new Map(); #running = new Set(); #telling = new Map(); #inFlight = new Map(); #sending = new Map();
217
223
 
218
224
  /* `review`: GitReview (reads, the reference, Send). `checks`: GitChecks.
219
225
  `alerts`: what tells the owner's phone. `tellAgent(repository, line,
@@ -556,7 +562,30 @@ export class GitKeeper {
556
562
 
557
563
  /* Send, from the page: as GitReview.push, and refused when the owner
558
564
  requires passing checks and none passed for this commit and branch. */
565
+ /* The push runs in the background; the request waits at most SENDING_WAIT_MS,
566
+ then returns { status: 'sending' } and the page asks again with `join: true`
567
+ until it ends -- so a slow push never blocks the request past the proxy's
568
+ patience. The push itself is still bounded (PUSH_MS), so it cannot run on
569
+ for hours. A send already going is joined; one just ended is re-run only
570
+ on a fresh click (no `join`), and re-sending the same commit is a no-op. */
559
571
  async send(name, body) {
572
+ const r = this.#repository(name);
573
+ const key = `${r.name}\n${body?.head ?? ''}\n${body?.target ?? ''}`;
574
+ let entry = this.#sending.get(key);
575
+ if (!entry || (entry.done && body?.join !== true)) {
576
+ const made = { done: false, result: undefined, error: undefined };
577
+ made.run = this.#doSend(r.name, body)
578
+ .then((result) => { made.result = result; }, (error) => { made.error = error; })
579
+ .finally(() => { made.done = true; setTimeout(() => { if (this.#sending.get(key) === made) this.#sending.delete(key); }, SENDING_KEEP_MS).unref?.(); });
580
+ entry = made; this.#sending.set(key, made);
581
+ }
582
+ const ms = Number.isFinite(body?.wait) ? Math.max(0, Math.min(body.wait, SENDING_WAIT_MS)) : SENDING_WAIT_MS;
583
+ await Promise.race([entry.run, new Promise((res) => { setTimeout(res, ms).unref?.(); })]);
584
+ if (!entry.done) return { status: 'sending' };
585
+ if (entry.error) throw entry.error;
586
+ return entry.result;
587
+ }
588
+ async #doSend(name, body) {
560
589
  const r = this.#repository(name);
561
590
  if (this.settings(r.name).requireForSend) {
562
591
  const target = body?.target || undefined;
package/web/app.js CHANGED
@@ -3815,7 +3815,16 @@
3815
3815
  for (const r of p) {
3816
3816
  r.sending = true; paint();
3817
3817
  try {
3818
- const sent = await post(`${API}/git/${r.name}/push`, { head: r.out.head, target: r.out.target, ...(r.out.guards?.confirm ? { sure: true } : {}) });
3818
+ /* The push runs in the background: the first request starts it, and
3819
+ while it says "sending" the page asks again (join) until it ends --
3820
+ a long push never looks like a failure or a restart. */
3821
+ let sent;
3822
+ for (let first = true; ; first = false) {
3823
+ sent = await post(`${API}/git/${r.name}/push`, first
3824
+ ? { head: r.out.head, target: r.out.target, ...(r.out.guards?.confirm ? { sure: true } : {}) }
3825
+ : { head: r.out.head, target: r.out.target, join: true });
3826
+ if (sent?.status !== 'sending') break;
3827
+ }
3819
3828
  r.sent = { ok: true, text: sent.already ? `✓ Already in ${sent.branch}` : sent.commits > 0 ? `✓ Sent to ${sent.branch}` : `✓ Made ${sent.branch}` };
3820
3829
  } catch (error) { r.sent = { ok: false, text: /^Not sent/.test(error.message) ? error.message : `Not sent: ${error.message}` }; }
3821
3830
  r.sending = false; paint();