longtable 0.1.39 → 0.1.41
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/package.json +1 -1
- package/src/repo.mjs +45 -1
- package/src/run.mjs +19 -2
package/package.json
CHANGED
package/src/repo.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// The connection's own clean copy of the team's code: the latest main, never the person's work folder.
|
|
2
2
|
|
|
3
3
|
import { execFileSync } from "node:child_process";
|
|
4
|
-
import { cpSync, existsSync, mkdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { cpSync, existsSync, mkdirSync, readFileSync, realpathSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
5
5
|
import { join, resolve } from "node:path";
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
7
7
|
import { home, log } from "./store.mjs";
|
|
@@ -537,6 +537,50 @@ function copyIncluded(repo, dir) {
|
|
|
537
537
|
// Opens (or reopens) the worktree for a job. `branch` is the task's branch for work, or the branch to read for a
|
|
538
538
|
// review; with no branch it reads the default one. Work on a branch that already exists picks up where it left off.
|
|
539
539
|
// A job that only reads gets a worktree of its own (`job`), removed when it ends, so two jobs never share one.
|
|
540
|
+
// The working copies Longtable made in a person's own repository (under ~/.longtable/trees), tidied when no job runs.
|
|
541
|
+
// One with changes not committed is never touched. A clean one whose branch holds nothing of its own (every commit on
|
|
542
|
+
// it is on another branch or remote too) goes, branch and all: there is nothing to lose. A clean one whose branch does
|
|
543
|
+
// hold work loses only its folder, once it has been quiet for a week; the branch and its commits stay, and a follow-up
|
|
544
|
+
// lays a fresh folder. The person's own worktrees are never looked at.
|
|
545
|
+
export function tidyTrees(repos, { quietDays = 7 } = {}) {
|
|
546
|
+
// Compared by real path: git names a worktree by its real path, and the same folder can be reached another way (a
|
|
547
|
+
// Mac's /var is /private/var; Windows can name a folder by its short name).
|
|
548
|
+
const real = (p) => { try { return realpathSync.native(p); } catch { return resolve(p); } };
|
|
549
|
+
const key = (p) => real(p).replace(/\\/g, "/").toLowerCase() + "/";
|
|
550
|
+
const ours = key(join(home, "trees"));
|
|
551
|
+
const out = { removed: [], deleted: [], kept: [] };
|
|
552
|
+
for (const repo of [...new Set((repos || []).filter(Boolean))]) {
|
|
553
|
+
let list = "";
|
|
554
|
+
try { list = tgit(repo, ["worktree", "list", "--porcelain"]); } catch { continue; }
|
|
555
|
+
for (const block of list.split(/\r?\n\r?\n/)) {
|
|
556
|
+
const path = /^worktree (.+)$/m.exec(block)?.[1];
|
|
557
|
+
const ref = /^branch (refs\/heads\/.+)$/m.exec(block)?.[1] || null;
|
|
558
|
+
if (!path || !existsSync(path) || !key(path).startsWith(ours)) continue;
|
|
559
|
+
let dirty = true;
|
|
560
|
+
try { dirty = tgit(path, ["status", "--porcelain"]) !== ""; } catch {}
|
|
561
|
+
if (dirty) { out.kept.push({ path, why: "changes not committed" }); continue; }
|
|
562
|
+
const branch = ref ? ref.slice("refs/heads/".length) : null;
|
|
563
|
+
const mine = !!branch && branch.startsWith("longtable/");
|
|
564
|
+
let unique = false;
|
|
565
|
+
if (mine) {
|
|
566
|
+
try {
|
|
567
|
+
const tip = tgit(repo, ["rev-parse", ref]);
|
|
568
|
+
unique = !tgit(repo, ["for-each-ref", "--contains", tip, "--format=%(refname)"]).split(/\r?\n/).some((r) => r && !r.startsWith("refs/heads/longtable/"));
|
|
569
|
+
} catch { unique = true; }
|
|
570
|
+
}
|
|
571
|
+
if (unique) {
|
|
572
|
+
let at = 0;
|
|
573
|
+
try { at = Number(tgit(path, ["log", "-1", "--format=%ct"])) * 1000; } catch {}
|
|
574
|
+
if (Date.now() - at < quietDays * 24 * 3600 * 1000) { out.kept.push({ path, why: "work from this week" }); continue; }
|
|
575
|
+
}
|
|
576
|
+
try { tgit(repo, ["worktree", "remove", "--force", path]); out.removed.push(path); } catch { out.kept.push({ path, why: "could not be removed" }); continue; }
|
|
577
|
+
if (mine && !unique) { try { tgit(repo, ["branch", "-D", branch]); out.deleted.push(branch); } catch {} }
|
|
578
|
+
}
|
|
579
|
+
try { tgit(repo, ["worktree", "prune"]); } catch {}
|
|
580
|
+
}
|
|
581
|
+
return out;
|
|
582
|
+
}
|
|
583
|
+
|
|
540
584
|
export function openTree(seat, branch, { doing = false, job = "read" } = {}) {
|
|
541
585
|
const table = safeTable(seat.table_id);
|
|
542
586
|
if (branch) safeBranch(branch);
|
package/src/run.mjs
CHANGED
|
@@ -20,7 +20,7 @@ import { client } from "./api.mjs";
|
|
|
20
20
|
import { ask, findClaude, stopAll } from "./claude.mjs";
|
|
21
21
|
import { askCodex, codexLimits, findCodex } from "./codex.mjs";
|
|
22
22
|
import { packCode } from "./pack.mjs";
|
|
23
|
-
import { changedSoFar, closeTree, fileFolder, folderChanges, folderState, freshCopy, isAddress, pushPlan, sourceFor, trustedRepo, landTree, landWork, neverCommit, openBranch, openTree, openWork, ownFolder, layTree, patchOf, realRepo, refreshBranch, safeTable, treeChanges, undoCommit, workBranch } from "./repo.mjs";
|
|
23
|
+
import { changedSoFar, closeTree, fileFolder, folderChanges, folderState, freshCopy, isAddress, pushPlan, sourceFor, trustedRepo, landTree, landWork, neverCommit, openBranch, openTree, openWork, ownFolder, layTree, tidyTrees, patchOf, realRepo, refreshBranch, safeTable, treeChanges, undoCommit, workBranch } from "./repo.mjs";
|
|
24
24
|
import { alwaysRules } from "./approve-server.mjs";
|
|
25
25
|
import { fileURLToPath } from "node:url";
|
|
26
26
|
import { cut, hideSecrets, home, loadSecret, log, readConfig, writeWhole } from "./store.mjs";
|
|
@@ -1089,10 +1089,16 @@ async function work(rpc, seat, engines, raw) {
|
|
|
1089
1089
|
// The table's repository, when the owner set one this computer knows, is where the team's code is read from and
|
|
1090
1090
|
// where branches land, for this job and every kind of work below.
|
|
1091
1091
|
const source = seat.source ? sourceFor(seat, job.repo, job.use_repo) : seat.source;
|
|
1092
|
-
|
|
1092
|
+
const trusted = seat.source ? trustedRepo(seat, job.repo, job.use_repo) : null;
|
|
1093
|
+
heardRepo(seat, job.repo, trusted);
|
|
1093
1094
|
if (source !== seat.source) seat = { ...seat, source };
|
|
1094
1095
|
if (job.kind === "sandbox") {
|
|
1095
1096
|
try {
|
|
1097
|
+
// A copy lands where the team's hosting builds it. One that would only land in a folder on this computer (the
|
|
1098
|
+
// table names a repository this person has not said yes to) is refused, saying what to press.
|
|
1099
|
+
if (job.repo && !trusted && /^file:/i.test(String(seat.source || ""))) {
|
|
1100
|
+
throw new Error(`${job.me}'s Claude has not said yes to the table's repository, so this copy would only land on this computer. In ${job.me}'s AI window, press Use it`);
|
|
1101
|
+
}
|
|
1096
1102
|
await workSandbox(rpc, { ...seat, model: await chosenModel(rpc, seat, job) }, engines, job);
|
|
1097
1103
|
} catch (e) {
|
|
1098
1104
|
log(`sandbox job ${job.job_id} failed: ${e.message}`);
|
|
@@ -1571,6 +1577,17 @@ export async function runLoop({ pollMs = 1000, backup = false } = {}) {
|
|
|
1571
1577
|
setInterval(checkRelease, 10 * 60 * 1000).unref?.();
|
|
1572
1578
|
// Two lanes on one connection: long work in one, everything quick in the other, so an hour of work never keeps
|
|
1573
1579
|
// the table from hearing people or answering a question.
|
|
1580
|
+
// The working copies it left in people's own repositories are tidied at start and every six hours, only while no job
|
|
1581
|
+
// runs (a job may be using one).
|
|
1582
|
+
const tidy = () => {
|
|
1583
|
+
if (busy > 0 || claiming > 0) return;
|
|
1584
|
+
try {
|
|
1585
|
+
const t = tidyTrees(seats.filter((s) => s.kind === "claude").map((s) => realRepo(s)));
|
|
1586
|
+
if (t.removed.length || t.kept.length) log(`tidied its working copies: removed ${t.removed.length} (and ${t.deleted.length} empty branches), left ${t.kept.length}${t.kept.length ? ` (${[...new Set(t.kept.map((k) => k.why))].join(", ")})` : ""}`);
|
|
1587
|
+
} catch (e) { log(`could not tidy its working copies: ${e.message}`); }
|
|
1588
|
+
};
|
|
1589
|
+
tidy();
|
|
1590
|
+
setInterval(tidy, 6 * 3600 * 1000).unref?.();
|
|
1574
1591
|
// Declared before the lanes start: they read it the moment a full-mode job arrives.
|
|
1575
1592
|
let aside = 0;
|
|
1576
1593
|
await Promise.all([lane("light"), lane("heavy")]);
|