teamshare-bridge 0.28.10 → 0.28.12
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/dist/lib/git/git-presence.js +4 -2
- package/dist/lib/git/git-presence.js.map +1 -1
- package/dist/lib/orchestrator/client.js +14 -0
- package/dist/lib/orchestrator/client.js.map +1 -1
- package/dist/lib/orchestrator/handlers/index.d.ts +1 -0
- package/dist/lib/orchestrator/handlers/index.js +3 -1
- package/dist/lib/orchestrator/handlers/index.js.map +1 -1
- package/dist/lib/orchestrator/handlers/repair.d.ts +12 -0
- package/dist/lib/orchestrator/handlers/repair.js +75 -0
- package/dist/lib/orchestrator/handlers/repair.js.map +1 -0
- package/dist/lib/orchestrator/worktree.d.ts +22 -0
- package/dist/lib/orchestrator/worktree.js +103 -24
- package/dist/lib/orchestrator/worktree.js.map +1 -1
- package/dist/lib/workspace/isolation-repair.d.ts +49 -0
- package/dist/lib/workspace/isolation-repair.js +498 -0
- package/dist/lib/workspace/isolation-repair.js.map +1 -0
- package/dist/lib/workspace/mirror.d.ts +29 -0
- package/dist/lib/workspace/mirror.js +5 -0
- package/dist/lib/workspace/mirror.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,498 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.repairIsolation = repairIsolation;
|
|
4
|
+
/**
|
|
5
|
+
* Isolation repair (2026-11-13): the "Fix this computer" button.
|
|
6
|
+
*
|
|
7
|
+
* Why this module exists. Isolation failures are the one class of failure that
|
|
8
|
+
* makes a task look DEAD rather than broken: the wake is acknowledged, the
|
|
9
|
+
* bridge settles it `blocked` in a few seconds, and NOTHING the agent would do
|
|
10
|
+
* ever runs. The human presses "Run task" again and again - and because
|
|
11
|
+
* `runTask()` calls `resumeAutoRun()` first, the failure counter resets to 1 on
|
|
12
|
+
* every press, so the task never even reaches the suspension cap that would have
|
|
13
|
+
* explained itself in a comment.
|
|
14
|
+
*
|
|
15
|
+
* Every one of those failures is mechanical: a stale tree a dead process still
|
|
16
|
+
* holds open, a lease that names a folder the project no longer lives in, a lock
|
|
17
|
+
* nobody owns, a registry (OpenCode's shared service) pinning an old run
|
|
18
|
+
* directory. They are all repairable locally, and none of them needs the agent.
|
|
19
|
+
*
|
|
20
|
+
* So this is a DETERMINISTIC repair, not a retry: it inspects the machine, fixes
|
|
21
|
+
* what it provably can, and then PROVES the fix by building the real mirror the
|
|
22
|
+
* run will use. The caller (the bridge command handler) reports the checklist to
|
|
23
|
+
* the hub; the task-detail / Orchestrator surfaces render it.
|
|
24
|
+
*
|
|
25
|
+
* Safety rules that are NOT negotiable (they mirror the sweeper's):
|
|
26
|
+
* - a tree with a live owner (lease pid or presence row) is never touched;
|
|
27
|
+
* - a marker-less non-empty tree is QUARANTINED, never deleted - its bytes may
|
|
28
|
+
* be a dead run's only copy and we do not know which repos they belong to;
|
|
29
|
+
* - deletion only ever happens under `deep:true` (a human clicked the box) and
|
|
30
|
+
* only for trees we can prove are dead (`.abandoned-*` quarantines, empty
|
|
31
|
+
* shells, or a mirror whose linked folder no longer exists);
|
|
32
|
+
* - a mirror we build is LEFT IN PLACE so the next run ADOPTS it (its branch
|
|
33
|
+
* base, marker and lease are exactly what `createIsolationMirror` would have
|
|
34
|
+
* produced anyway).
|
|
35
|
+
*/
|
|
36
|
+
const node_child_process_1 = require("node:child_process");
|
|
37
|
+
const node_fs_1 = require("node:fs");
|
|
38
|
+
const node_path_1 = require("node:path");
|
|
39
|
+
const config_1 = require("../config");
|
|
40
|
+
const git_presence_1 = require("../git/git-presence");
|
|
41
|
+
const index_recovery_1 = require("../git/index-recovery");
|
|
42
|
+
const lock_1 = require("../lock");
|
|
43
|
+
const worktree_1 = require("../orchestrator/worktree");
|
|
44
|
+
const mirror_1 = require("./mirror");
|
|
45
|
+
const mirror_lease_1 = require("./mirror-lease");
|
|
46
|
+
const opencode_projects_1 = require("./opencode-projects");
|
|
47
|
+
const shims_1 = require("./shims");
|
|
48
|
+
const state_root_1 = require("./state-root");
|
|
49
|
+
const log = (msg) => console.log(`[repair] ${msg}`);
|
|
50
|
+
/** A tree must be at least this old before `deep` will consider it abandoned. */
|
|
51
|
+
const DEEP_MIN_AGE_MS = 24 * 3600_000;
|
|
52
|
+
/** Ceiling for the whole deep-clean pass, so the command answers in time. */
|
|
53
|
+
const DEEP_BUDGET_MS = 90_000;
|
|
54
|
+
/** Ceiling for measuring a directory (a 2.6 GB tree must not stall the reply). */
|
|
55
|
+
const SIZE_BUDGET_MS = 8_000;
|
|
56
|
+
function msg(err) {
|
|
57
|
+
return err instanceof Error ? err.message : String(err);
|
|
58
|
+
}
|
|
59
|
+
function samePath(a, b) {
|
|
60
|
+
const norm = (p) => (0, node_path_1.resolve)(p).replace(/\\/g, '/').toLowerCase().replace(/\/+$/, '');
|
|
61
|
+
return norm(a) === norm(b);
|
|
62
|
+
}
|
|
63
|
+
/** Bounded recursive byte count. Never throws. */
|
|
64
|
+
function dirBytes(dir, budgetMs = SIZE_BUDGET_MS) {
|
|
65
|
+
const deadline = Date.now() + budgetMs;
|
|
66
|
+
let total = 0;
|
|
67
|
+
const walk = (d) => {
|
|
68
|
+
if (Date.now() > deadline)
|
|
69
|
+
return;
|
|
70
|
+
let entries;
|
|
71
|
+
try {
|
|
72
|
+
entries = (0, node_fs_1.readdirSync)(d, { withFileTypes: true });
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
for (const entry of entries) {
|
|
78
|
+
if (Date.now() > deadline)
|
|
79
|
+
return;
|
|
80
|
+
const child = (0, node_path_1.join)(d, entry.name);
|
|
81
|
+
try {
|
|
82
|
+
if (entry.isDirectory())
|
|
83
|
+
walk(child);
|
|
84
|
+
else if (entry.isFile())
|
|
85
|
+
total += (0, node_fs_1.statSync)(child).size;
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
/* a file that vanished mid-walk is not an error */
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
walk(dir);
|
|
93
|
+
return total;
|
|
94
|
+
}
|
|
95
|
+
/** `git worktree prune`, without the arbitration shims (self-deadlock guard). */
|
|
96
|
+
function gitPrune(repo) {
|
|
97
|
+
try {
|
|
98
|
+
(0, node_child_process_1.execFileSync)('git', ['worktree', 'prune'], {
|
|
99
|
+
cwd: repo,
|
|
100
|
+
encoding: 'utf-8',
|
|
101
|
+
timeout: 20_000,
|
|
102
|
+
windowsHide: true,
|
|
103
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
104
|
+
env: (0, shims_1.envWithoutShims)(),
|
|
105
|
+
});
|
|
106
|
+
return { ok: true };
|
|
107
|
+
}
|
|
108
|
+
catch (err) {
|
|
109
|
+
return { ok: false, detail: msg(err) };
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* The repair itself. Idempotent: running it twice is a no-op the second time
|
|
114
|
+
* (every action is a conditional cleanup), which matters because a human will
|
|
115
|
+
* press the button more than once.
|
|
116
|
+
*/
|
|
117
|
+
async function repairIsolation(opts) {
|
|
118
|
+
const started = Date.now();
|
|
119
|
+
const checks = [];
|
|
120
|
+
const actions = [];
|
|
121
|
+
const check = (id, label, status, detail) => {
|
|
122
|
+
checks.push({ id, label, status, detail });
|
|
123
|
+
};
|
|
124
|
+
const act = (id, detail) => {
|
|
125
|
+
actions.push({ id, detail });
|
|
126
|
+
log(detail);
|
|
127
|
+
};
|
|
128
|
+
const raw = String(opts.folder ?? '').trim();
|
|
129
|
+
if (!raw) {
|
|
130
|
+
check('folder', 'Linked folder', 'fail', 'No folder is linked to this project on this computer.');
|
|
131
|
+
return {
|
|
132
|
+
ok: false,
|
|
133
|
+
reason: 'PROJECT_NOT_LINKED',
|
|
134
|
+
hint: 'Link the project folder from the project Members tab (or run: teamshare-agent link --project <id> --path <folder>).',
|
|
135
|
+
checks,
|
|
136
|
+
actions,
|
|
137
|
+
mirrorReady: false,
|
|
138
|
+
durationMs: Date.now() - started,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
const folder = (0, node_path_1.resolve)(raw);
|
|
142
|
+
// ── 1. The linked folder itself ───────────────────────────────────────────
|
|
143
|
+
const rejection = (0, worktree_1.repoPathRejection)(folder);
|
|
144
|
+
if (rejection) {
|
|
145
|
+
check('folder', 'Linked folder', 'fail', rejection);
|
|
146
|
+
return {
|
|
147
|
+
ok: false,
|
|
148
|
+
reason: 'LINKED_FOLDER_UNSUPPORTED',
|
|
149
|
+
hint: 'Link a local folder - network shares are not supported.',
|
|
150
|
+
checks,
|
|
151
|
+
actions,
|
|
152
|
+
mirrorReady: false,
|
|
153
|
+
durationMs: Date.now() - started,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
const preflight = (0, config_1.preflightFolder)(folder);
|
|
157
|
+
if (!preflight.ok) {
|
|
158
|
+
check('folder', 'Linked folder', 'fail', preflight.reason);
|
|
159
|
+
return {
|
|
160
|
+
ok: false,
|
|
161
|
+
reason: 'LINKED_FOLDER_UNAVAILABLE',
|
|
162
|
+
hint: 'Fix the folder itself (it must exist and be readable + writable by you), then press Fix again.',
|
|
163
|
+
checks,
|
|
164
|
+
actions,
|
|
165
|
+
mirrorReady: false,
|
|
166
|
+
durationMs: Date.now() - started,
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
check('folder', 'Linked folder', 'ok', `${folder} (readable, writable)`);
|
|
170
|
+
// ── 2. git on this machine ────────────────────────────────────────────────
|
|
171
|
+
// A button press must RE-PROBE: a cached `blocked` last 5s and a cached
|
|
172
|
+
// verdict 60s, and reporting a stale verdict after a real repair is how a
|
|
173
|
+
// "fixed" machine still looks broken.
|
|
174
|
+
(0, git_presence_1.resetGitAvailabilityCache)();
|
|
175
|
+
const git = (0, git_presence_1.probeGit)();
|
|
176
|
+
if (git.state === 'absent') {
|
|
177
|
+
check('git', 'git', 'fail', 'git is not installed on this computer.');
|
|
178
|
+
return {
|
|
179
|
+
ok: false,
|
|
180
|
+
reason: 'GIT_NOT_INSTALLED',
|
|
181
|
+
hint: 'Install git (https://git-scm.com/downloads), then press Fix again.',
|
|
182
|
+
checks,
|
|
183
|
+
actions,
|
|
184
|
+
mirrorReady: false,
|
|
185
|
+
durationMs: Date.now() - started,
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
if (git.state === 'blocked') {
|
|
189
|
+
check('git', 'git', 'warn', `Could not verify git: ${git.detail ?? 'the probe did not answer in time'}. ` +
|
|
190
|
+
'This is a bridge/machine-load problem, not a missing install.');
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
check('git', 'git', 'ok', git.version ?? 'a usable git was found');
|
|
194
|
+
}
|
|
195
|
+
// ── 3. Repo shape + stale worktree registrations ──────────────────────────
|
|
196
|
+
const isRepo = (0, mirror_1.isGitRepoDir)(folder);
|
|
197
|
+
check('repo', 'Repository', 'ok', isRepo
|
|
198
|
+
? 'a git repository'
|
|
199
|
+
: 'not a git repository yet - the mirror initialises one (git init + a baseline commit) before any run');
|
|
200
|
+
const nested = (0, mirror_1.discoverNestedRepos)(folder);
|
|
201
|
+
const repos = isRepo ? [folder, ...nested] : [...nested];
|
|
202
|
+
for (const repo of repos) {
|
|
203
|
+
const result = gitPrune(repo);
|
|
204
|
+
if (result.ok) {
|
|
205
|
+
act('worktree-prune', `Pruned stale worktree registrations in ${repo}`);
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
check('worktree-prune', 'Worktree registry', 'warn', `Could not prune ${repo}: ${result.detail ?? 'git refused'}`);
|
|
209
|
+
}
|
|
210
|
+
// The daemon's own in-memory "this index is wedged" marker. A repair is the
|
|
211
|
+
// signal that a human asked for a fresh attempt.
|
|
212
|
+
(0, index_recovery_1.clearBlockedIndexRepo)(repo);
|
|
213
|
+
}
|
|
214
|
+
if (repos.length === 0) {
|
|
215
|
+
act('worktree-prune', 'No repositories here yet - nothing to prune');
|
|
216
|
+
}
|
|
217
|
+
// ── 4. Base branch ────────────────────────────────────────────────────────
|
|
218
|
+
const base = (0, mirror_1.resolveBaseBranch)(folder, {
|
|
219
|
+
configuredBase: opts.configuredBase ?? null,
|
|
220
|
+
});
|
|
221
|
+
check('base', 'Base branch', base ? 'ok' : 'warn', base
|
|
222
|
+
? `the run starts from ${base}`
|
|
223
|
+
: 'no branch resolves yet - the container root gets a baseline commit before the mirror is built');
|
|
224
|
+
// ── 5. Stale agent lock ───────────────────────────────────────────────────
|
|
225
|
+
const lock = (0, lock_1.readLock)(opts.agentId);
|
|
226
|
+
if (lock) {
|
|
227
|
+
if ((0, lock_1.isLockBusy)(opts.agentId)) {
|
|
228
|
+
check('agent-lock', 'Agent lock', 'warn', `Held by pid ${lock.pid} (${lock.kind}) - a session is using this agent right now.`);
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
(0, lock_1.clearLock)(opts.agentId);
|
|
232
|
+
act('clear-stale-lock', `Cleared a stale agent lock (pid ${lock.pid} is gone, ${lock.kind})`);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
check('agent-lock', 'Agent lock', 'ok', 'free');
|
|
237
|
+
}
|
|
238
|
+
// ── 6. Stale mirror leases ────────────────────────────────────────────────
|
|
239
|
+
// A lease is a pointer to a tree. It is garbage when the tree is gone, and
|
|
240
|
+
// actively misleading when it names a DIFFERENT linked folder (the project was
|
|
241
|
+
// moved, so the old workspace key still holds a lease claiming this task).
|
|
242
|
+
let liveTaskLease = false;
|
|
243
|
+
for (const lease of (0, mirror_lease_1.listMirrorLeases)()) {
|
|
244
|
+
const isThisTask = !!opts.taskId && lease.taskId === opts.taskId;
|
|
245
|
+
if (!lease.path || !(0, node_fs_1.existsSync)(lease.path)) {
|
|
246
|
+
(0, mirror_lease_1.deleteMirrorLease)(lease.taskId);
|
|
247
|
+
act('drop-lease', `Dropped a lease whose tree no longer exists (task ${lease.taskId.slice(0, 8)})`);
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
if (isThisTask && lease.folder && !samePath(lease.folder, folder)) {
|
|
251
|
+
(0, mirror_lease_1.deleteMirrorLease)(lease.taskId);
|
|
252
|
+
act('drop-lease', `Dropped this task's lease: it names ${lease.folder}, but the project is linked to ${folder}`);
|
|
253
|
+
continue;
|
|
254
|
+
}
|
|
255
|
+
if (isThisTask && (0, mirror_lease_1.mirrorLeaseIsLive)(lease))
|
|
256
|
+
liveTaskLease = true;
|
|
257
|
+
}
|
|
258
|
+
if (liveTaskLease) {
|
|
259
|
+
check('agent-lock', 'Mirror ownership', 'warn', "A live session already owns this task's tree.");
|
|
260
|
+
}
|
|
261
|
+
// ── 7. This folder's workspace leftovers ──────────────────────────────────
|
|
262
|
+
// `forgetOpencodeProject` is the load-bearing part: OpenCode's shared service
|
|
263
|
+
// registers every run directory and holds a handle on it, which is what makes
|
|
264
|
+
// a rename/rmdir fail with EBUSY and the retry fail "could not be moved
|
|
265
|
+
// aside". Nothing is deleted here - only the registry entry is released.
|
|
266
|
+
const thisRoot = (0, state_root_1.worktreeRootFor)(folder);
|
|
267
|
+
let unlocked = 0;
|
|
268
|
+
try {
|
|
269
|
+
for (const entry of (0, node_fs_1.readdirSync)(thisRoot, { withFileTypes: true })) {
|
|
270
|
+
if (!entry.isDirectory())
|
|
271
|
+
continue;
|
|
272
|
+
const dir = (0, node_path_1.join)(thisRoot, entry.name);
|
|
273
|
+
try {
|
|
274
|
+
(0, opencode_projects_1.forgetOpencodeProject)(dir);
|
|
275
|
+
unlocked += 1;
|
|
276
|
+
}
|
|
277
|
+
catch {
|
|
278
|
+
/* best-effort: the registry is a convenience, not a dependency */
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
catch {
|
|
283
|
+
/* no worktree root yet - a fresh project */
|
|
284
|
+
}
|
|
285
|
+
if (unlocked > 0) {
|
|
286
|
+
act('forget-opencode', `Released ${unlocked} stale run director${unlocked === 1 ? 'y' : 'ies'} from OpenCode's registry (the EBUSY holder)`);
|
|
287
|
+
}
|
|
288
|
+
// ── 8. Deep clean (opt-in) ────────────────────────────────────────────────
|
|
289
|
+
let freedBytes = 0;
|
|
290
|
+
if (opts.deep) {
|
|
291
|
+
const swept = await deepClean(opts.taskId ?? null);
|
|
292
|
+
freedBytes = swept.freedBytes;
|
|
293
|
+
for (const line of swept.notes)
|
|
294
|
+
act('deep-clean', line);
|
|
295
|
+
if (swept.freedBytes > 0) {
|
|
296
|
+
act('deep-clean', `Reclaimed ${(swept.freedBytes / 1024 / 1024).toFixed(0)} MB of dead workspace trees`);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
// ── 9. Prove it: build the real mirror ────────────────────────────────────
|
|
300
|
+
// Only for a TASK-SCOPED repair: the tree is `taskrun-<taskId>` and the run
|
|
301
|
+
// that follows ADOPTS it, so building it here is a proof the next press
|
|
302
|
+
// really can start. A project-level repair has no task to adopt an ephemeral
|
|
303
|
+
// tree, and building one would only leave litter for the sweeper.
|
|
304
|
+
let mirrorReady = false;
|
|
305
|
+
let mirrorPath;
|
|
306
|
+
let repoCount;
|
|
307
|
+
const shouldBuild = opts.buildMirror !== false && !!opts.taskId;
|
|
308
|
+
/**
|
|
309
|
+
* Can a run start from here? A live session already inside the tree is the
|
|
310
|
+
* strongest possible yes - reporting `ok: false` there would tell a human
|
|
311
|
+
* "still blocked" about a tree that is currently working.
|
|
312
|
+
*/
|
|
313
|
+
let mirrorSatisfied = !shouldBuild;
|
|
314
|
+
if (!shouldBuild) {
|
|
315
|
+
check('mirror', 'Working tree', 'ok', opts.taskId
|
|
316
|
+
? 'Not built (mirror build skipped) - the checks above are what matters.'
|
|
317
|
+
: 'Nothing to pre-build: this repair was not for a specific task.');
|
|
318
|
+
}
|
|
319
|
+
else if (liveTaskLease) {
|
|
320
|
+
mirrorSatisfied = true;
|
|
321
|
+
check('mirror', 'Working tree', 'ok', 'Already in use by a live session - nothing to rebuild.');
|
|
322
|
+
}
|
|
323
|
+
else {
|
|
324
|
+
const outcome = await (0, mirror_1.createIsolationMirror)(folder, opts.taskId, opts.agentId, opts.projectId ?? null, {
|
|
325
|
+
taskId: opts.taskId,
|
|
326
|
+
configuredBase: opts.configuredBase ?? null,
|
|
327
|
+
});
|
|
328
|
+
if (outcome.ok) {
|
|
329
|
+
mirrorReady = true;
|
|
330
|
+
mirrorSatisfied = true;
|
|
331
|
+
mirrorPath = outcome.mirror.path;
|
|
332
|
+
repoCount = outcome.mirror.repos.length;
|
|
333
|
+
// Mark it ready-for-adoption. A freshly created lease with no `handedTo`
|
|
334
|
+
// is treated as "a spawn may still be in flight" for
|
|
335
|
+
// ORPHAN_RECLAIM_MIN_AGE_MS (10 min), so a human who presses Fix twice
|
|
336
|
+
// would otherwise be told another session owns a tree this repair just
|
|
337
|
+
// built. `keptForRetry` is exactly the mirror's own vocabulary for "a
|
|
338
|
+
// tree waiting to be picked up again".
|
|
339
|
+
(0, mirror_lease_1.markMirrorKeptForRetry)(opts.taskId, 'prepared by isolation repair');
|
|
340
|
+
check('mirror', 'Working tree', 'ok', `${outcome.mirror.repos.length} repo(s) ready at ${outcome.mirror.path}` +
|
|
341
|
+
(outcome.mirror.adopted
|
|
342
|
+
? ` (adopted a previous attempt${outcome.mirror.dirtyFiles ? `, ${outcome.mirror.dirtyFiles} uncommitted file(s) intact` : ''})`
|
|
343
|
+
: ''));
|
|
344
|
+
act('build-mirror', `Built the isolation tree this run will use (${outcome.mirror.repos.length} repo(s)) - the next run adopts it`);
|
|
345
|
+
}
|
|
346
|
+
else {
|
|
347
|
+
check('mirror', 'Working tree', 'fail', outcome.detail ?? `the mirror could not be created (${outcome.reason})`);
|
|
348
|
+
return {
|
|
349
|
+
ok: false,
|
|
350
|
+
reason: 'MIRROR_UNAVAILABLE',
|
|
351
|
+
hint: outcome.reason === 'blocked'
|
|
352
|
+
? 'Another session still owns this tree. Wait for it to finish (or stop it), then press Fix again.'
|
|
353
|
+
: 'The tree could not be created - the detail above names the exact git failure.',
|
|
354
|
+
checks,
|
|
355
|
+
actions,
|
|
356
|
+
mirrorReady: false,
|
|
357
|
+
...(freedBytes ? { freedBytes } : {}),
|
|
358
|
+
durationMs: Date.now() - started,
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
const failed = checks.some((c) => c.status === 'fail');
|
|
363
|
+
return {
|
|
364
|
+
ok: !failed && mirrorSatisfied,
|
|
365
|
+
...(failed ? { reason: 'CHECKS_FAILED' } : {}),
|
|
366
|
+
checks,
|
|
367
|
+
actions,
|
|
368
|
+
mirrorReady,
|
|
369
|
+
...(mirrorPath ? { mirrorPath } : {}),
|
|
370
|
+
...(repoCount != null ? { repos: repoCount } : {}),
|
|
371
|
+
...(freedBytes ? { freedBytes } : {}),
|
|
372
|
+
durationMs: Date.now() - started,
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Delete only trees we can PROVE are dead.
|
|
377
|
+
*
|
|
378
|
+
* Three shapes qualify, and nothing else does:
|
|
379
|
+
* 1. `.abandoned-<ts>` - a quarantine this bridge itself created. Its own log
|
|
380
|
+
* line has told the human "delete it by hand once you have confirmed nothing
|
|
381
|
+
* in it is needed"; ticking Deep clean IS that confirmation.
|
|
382
|
+
* 2. an EMPTY mirror directory - no bytes to lose, and the next create reuses
|
|
383
|
+
* the path anyway.
|
|
384
|
+
* 3. a mirror whose linked folder no longer EXISTS on disk - there is no repo
|
|
385
|
+
* to rescue its commits into, so keeping it can only waste space forever.
|
|
386
|
+
*
|
|
387
|
+
* Anything else (a marker-bearing tree for a live project, a marker-less tree
|
|
388
|
+
* with content) is left alone: the first is a retry's only copy of its work and
|
|
389
|
+
* the second cannot be rescued onto a known branch.
|
|
390
|
+
*/
|
|
391
|
+
async function deepClean(currentTaskId) {
|
|
392
|
+
const deadline = Date.now() + DEEP_BUDGET_MS;
|
|
393
|
+
let freedBytes = 0;
|
|
394
|
+
const notes = [];
|
|
395
|
+
for (const root of (0, state_root_1.allWorkspaceRoots)()) {
|
|
396
|
+
const treesRoot = (0, node_path_1.join)(root, '.teamshare-worktrees');
|
|
397
|
+
let entries;
|
|
398
|
+
try {
|
|
399
|
+
entries = (0, node_fs_1.readdirSync)(treesRoot, { withFileTypes: true });
|
|
400
|
+
}
|
|
401
|
+
catch {
|
|
402
|
+
continue;
|
|
403
|
+
}
|
|
404
|
+
for (const entry of entries) {
|
|
405
|
+
if (Date.now() > deadline) {
|
|
406
|
+
notes.push('Deep clean hit its time budget - press Fix again to continue.');
|
|
407
|
+
return { freedBytes, notes };
|
|
408
|
+
}
|
|
409
|
+
if (!entry.isDirectory())
|
|
410
|
+
continue;
|
|
411
|
+
const dir = (0, node_path_1.join)(treesRoot, entry.name);
|
|
412
|
+
// Never the tree this very run is about to use.
|
|
413
|
+
const entryTask = (0, mirror_1.taskIdForMirrorDir)(dir);
|
|
414
|
+
if (currentTaskId && entryTask && entryTask === currentTaskId)
|
|
415
|
+
continue;
|
|
416
|
+
const quarantined = entry.name.includes('.abandoned-');
|
|
417
|
+
const empty = (0, worktree_1.isDirEmpty)(dir);
|
|
418
|
+
const marker = (0, mirror_1.readMirrorMarker)(dir);
|
|
419
|
+
const folderGone = !!marker?.folder && !(0, node_fs_1.existsSync)(marker.folder);
|
|
420
|
+
// A live owner is never touched, whatever shape the tree is in.
|
|
421
|
+
const lease = entryTask ? (0, mirror_lease_1.readMirrorLease)(entryTask) : null;
|
|
422
|
+
if (lease && samePath(lease.path, dir) && (0, mirror_lease_1.mirrorLeaseIsLive)(lease)) {
|
|
423
|
+
continue;
|
|
424
|
+
}
|
|
425
|
+
if (!quarantined && !empty && !folderGone) {
|
|
426
|
+
// Known-live project: a stale tree is left for the 6h sweeper, which
|
|
427
|
+
// rescues work onto a branch first. Quarantining here would only move
|
|
428
|
+
// it.
|
|
429
|
+
continue;
|
|
430
|
+
}
|
|
431
|
+
if (!quarantined && marker) {
|
|
432
|
+
let age = Number.POSITIVE_INFINITY;
|
|
433
|
+
try {
|
|
434
|
+
age = Date.now() - (0, node_fs_1.statSync)(dir).mtimeMs;
|
|
435
|
+
}
|
|
436
|
+
catch {
|
|
437
|
+
/* unreadable: treat as old enough only if the folder is gone */
|
|
438
|
+
}
|
|
439
|
+
if (!folderGone && age < DEEP_MIN_AGE_MS)
|
|
440
|
+
continue;
|
|
441
|
+
}
|
|
442
|
+
const before = dirBytes(dir);
|
|
443
|
+
try {
|
|
444
|
+
(0, opencode_projects_1.forgetOpencodeProject)(dir);
|
|
445
|
+
}
|
|
446
|
+
catch {
|
|
447
|
+
/* best-effort */
|
|
448
|
+
}
|
|
449
|
+
if (marker && !quarantined) {
|
|
450
|
+
// Rescue-first teardown: commits any uncommitted work onto the tree's
|
|
451
|
+
// own branch, then removes. Refuses (and keeps) rather than lose it.
|
|
452
|
+
const result = await (0, mirror_1.detachIsolationMirror)(dir, undefined, {
|
|
453
|
+
reason: 'deep clean',
|
|
454
|
+
guardLiveSession: true,
|
|
455
|
+
log: (text) => log(text),
|
|
456
|
+
});
|
|
457
|
+
if (result.kept.length === 0) {
|
|
458
|
+
freedBytes += before;
|
|
459
|
+
notes.push(`${entry.name}: work rescued where possible, tree removed (${(before / 1024 / 1024).toFixed(0)} MB)`);
|
|
460
|
+
}
|
|
461
|
+
else {
|
|
462
|
+
notes.push(`${entry.name}: kept - ${result.details[0]?.error ?? 'it could not be removed safely'}`);
|
|
463
|
+
}
|
|
464
|
+
continue;
|
|
465
|
+
}
|
|
466
|
+
try {
|
|
467
|
+
(0, node_fs_1.rmSync)(dir, {
|
|
468
|
+
recursive: true,
|
|
469
|
+
force: true,
|
|
470
|
+
maxRetries: 3,
|
|
471
|
+
retryDelay: 150,
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
catch {
|
|
475
|
+
// Locked: park it instead so the next pass can retry without the name
|
|
476
|
+
// colliding with a live path.
|
|
477
|
+
if (!quarantined) {
|
|
478
|
+
try {
|
|
479
|
+
(0, node_fs_1.renameSync)(dir, `${dir}.abandoned-${Date.now().toString(36)}`);
|
|
480
|
+
}
|
|
481
|
+
catch {
|
|
482
|
+
/* still locked - reported below */
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
if (!(0, node_fs_1.existsSync)(dir)) {
|
|
487
|
+
freedBytes += before;
|
|
488
|
+
notes.push(`${entry.name}: removed (${(before / 1024 / 1024).toFixed(0)} MB, ${quarantined ? 'quarantined tree' : empty ? 'empty shell' : 'linked folder no longer exists'})`);
|
|
489
|
+
}
|
|
490
|
+
else if (entryTask) {
|
|
491
|
+
(0, mirror_lease_1.deleteMirrorLease)(entryTask);
|
|
492
|
+
notes.push(`${entry.name}: locked by a dead process - its lease was dropped, retry after the holder exits`);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
return { freedBytes, notes };
|
|
497
|
+
}
|
|
498
|
+
//# sourceMappingURL=isolation-repair.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isolation-repair.js","sourceRoot":"","sources":["../../../src/lib/workspace/isolation-repair.ts"],"names":[],"mappings":";;AAyLA,0CA4VC;AArhBD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,2DAAkD;AAClD,qCAOiB;AACjB,yCAA0C;AAC1C,sCAA4C;AAC5C,sDAA0E;AAC1E,0DAA8D;AAC9D,kCAA0D;AAC1D,uDAAyE;AACzE,qCAQkB;AAClB,iDAMwB;AACxB,2DAA4D;AAC5D,mCAA0C;AAC1C,6CAAkE;AAElE,MAAM,GAAG,GAAG,CAAC,GAAW,EAAQ,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,GAAG,EAAE,CAAC,CAAC;AAElE,iFAAiF;AACjF,MAAM,eAAe,GAAG,EAAE,GAAG,QAAQ,CAAC;AAEtC,6EAA6E;AAC7E,MAAM,cAAc,GAAG,MAAM,CAAC;AAE9B,kFAAkF;AAClF,MAAM,cAAc,GAAG,KAAK,CAAC;AAkD7B,SAAS,GAAG,CAA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SAAS,EAAE,CAAC;gBACrB,IAAA,gCAAiB,EAAC,SAAS,CAAC,CAAC;gBAC7B,KAAK,CAAC,IAAI,CACR,GAAG,KAAK,CAAC,IAAI,kFAAkF,CAChG,CAAC;YACJ,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;AAC/B,CAAC"}
|
|
@@ -285,6 +285,35 @@ export declare function ensureLiveMirror(opts: {
|
|
|
285
285
|
deliverableBranch?: string | null;
|
|
286
286
|
log?: (text: string) => void;
|
|
287
287
|
}): Promise<MirrorRecovery>;
|
|
288
|
+
/**
|
|
289
|
+
* Base ref for a new worktree, resolved through THE base-branch ladder
|
|
290
|
+
* (2026-12):
|
|
291
|
+
*
|
|
292
|
+
* 1. the task's own branch, when it exists (retry continues the last attempt)
|
|
293
|
+
* 2. the project-wide base branch, when a human set one
|
|
294
|
+
* 3. the branch checked out in THIS repo of the linked folder <- the default
|
|
295
|
+
* 4. the repo default (`detectDefaultBranch`)
|
|
296
|
+
*
|
|
297
|
+
* Step 3 is the fix: the mirror used to be based on `detectDefaultBranch`,
|
|
298
|
+
* which resolves `origin/HEAD` first, so a folder sitting on `staging` got a
|
|
299
|
+
* tree cut from `master` and a PR opened against `master`.
|
|
300
|
+
*
|
|
301
|
+
* For steps 2/3 a remote-tracking ref (`origin/<name>`) is preferred when it
|
|
302
|
+
* exists - the PR base is the REMOTE branch, so the tree should start at the
|
|
303
|
+
* commit that branch points at. Step 1 prefers the LOCAL task branch, because
|
|
304
|
+
* a previous attempt may have committed without pushing.
|
|
305
|
+
*
|
|
306
|
+
* The mirror is still created DETACHED, so nothing is checked out in the main
|
|
307
|
+
* repo.
|
|
308
|
+
*
|
|
309
|
+
* Exported for the isolation REPAIR path (`workspace/isolation-repair.ts`),
|
|
310
|
+
* which reports which base a run would start from - the same ladder the real
|
|
311
|
+
* mirror uses, so a repair can never claim a branch the next run would not pick.
|
|
312
|
+
*/
|
|
313
|
+
export declare function resolveBaseBranch(repo: string, opts?: {
|
|
314
|
+
continueFrom?: string | null;
|
|
315
|
+
configuredBase?: string | null;
|
|
316
|
+
}): string | null;
|
|
288
317
|
/**
|
|
289
318
|
* Claim a mirror for THIS session (called by the spawned CLI on start).
|
|
290
319
|
* Records the pid in the lease so a second wake can tell "someone is working
|
|
@@ -15,6 +15,7 @@ exports.discoverNestedRepos = discoverNestedRepos;
|
|
|
15
15
|
exports.ensureContainerRoot = ensureContainerRoot;
|
|
16
16
|
exports.createIsolationMirror = createIsolationMirror;
|
|
17
17
|
exports.ensureLiveMirror = ensureLiveMirror;
|
|
18
|
+
exports.resolveBaseBranch = resolveBaseBranch;
|
|
18
19
|
exports.claimMirrorForSession = claimMirrorForSession;
|
|
19
20
|
exports.settleMirrorLease = settleMirrorLease;
|
|
20
21
|
exports.mirrorSessionIsLive = mirrorSessionIsLive;
|
|
@@ -1104,6 +1105,10 @@ function countDirtyFiles(dir, marker) {
|
|
|
1104
1105
|
*
|
|
1105
1106
|
* The mirror is still created DETACHED, so nothing is checked out in the main
|
|
1106
1107
|
* repo.
|
|
1108
|
+
*
|
|
1109
|
+
* Exported for the isolation REPAIR path (`workspace/isolation-repair.ts`),
|
|
1110
|
+
* which reports which base a run would start from - the same ladder the real
|
|
1111
|
+
* mirror uses, so a repair can never claim a branch the next run would not pick.
|
|
1107
1112
|
*/
|
|
1108
1113
|
function resolveBaseBranch(repo, opts) {
|
|
1109
1114
|
const resolves = (ref) => {
|