@north-light/crouter 0.3.303 → 0.3.305
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/api/__tests__/integration/client.test.js +37 -36
- package/dist/api/client.d.ts +32 -55
- package/dist/api/client.js +102 -98
- package/dist/api/dto/messages.d.ts +6 -5
- package/dist/api/errors.d.ts +3 -0
- package/dist/api/errors.js +10 -0
- package/dist/api/index.d.ts +1 -1
- package/dist/api/index.js +1 -1
- package/dist/builtin-memory/internal/plugins.md +1 -1
- package/dist/builtin-pi-packages/pi-crtr-extensions/extensions/__tests__/integration/provider-rotation.test.ts +87 -0
- package/dist/builtin-pi-packages/pi-crtr-extensions/extensions/provider-rotation.js +31 -26
- package/dist/builtin-pi-packages/pi-crtr-extensions/extensions/provider-rotation.ts +33 -26
- package/dist/clients/attach/viewer.js +584 -584
- package/dist/commands/__tests__/seam/daemon-status.test.d.ts +1 -0
- package/dist/commands/__tests__/seam/daemon-status.test.js +29 -0
- package/dist/commands/api-client.d.ts +3 -3
- package/dist/commands/api-client.js +3 -3
- package/dist/commands/memory/read.js +2 -1
- package/dist/commands/node/bash.js +6 -6
- package/dist/commands/node/create.js +7 -1
- package/dist/commands/node/message.js +3 -3
- package/dist/commands/node/wait.js +1 -1
- package/dist/commands/node-worktree.js +5 -1
- package/dist/commands/sys/daemon.js +11 -13
- package/dist/core/__tests__/broker-stream-watchdog-floor.test.js +0 -2
- package/dist/core/__tests__/daemon-boot.test.js +1 -1
- package/dist/core/__tests__/fixtures/fake-engine.js +14 -15
- package/dist/core/__tests__/helpers/harness.d.ts +2 -0
- package/dist/core/__tests__/helpers/harness.js +9 -0
- package/dist/core/__tests__/integration/tmux-surface.test.js +53 -0
- package/dist/core/__tests__/integration/worktree-land.test.js +50 -0
- package/dist/core/__tests__/integration/worktree-reap.test.js +184 -5
- package/dist/core/__tests__/kickoff.test.js +40 -0
- package/dist/core/__tests__/parse-argv-stdin-secret.test.js +14 -0
- package/dist/core/__tests__/seam/broker-attach-stream.test.js +13 -0
- package/dist/core/__tests__/seam/broker-provider-retry.test.js +25 -0
- package/dist/core/__tests__/seam/broker-startup-diagnostics.test.d.ts +1 -0
- package/dist/core/__tests__/seam/broker-startup-diagnostics.test.js +82 -0
- package/dist/core/__tests__/seam/deadline-wake-delivery.test.d.ts +1 -0
- package/dist/core/__tests__/seam/deadline-wake-delivery.test.js +138 -0
- package/dist/core/__tests__/seam/reopen-invalidated-worktree.test.d.ts +1 -0
- package/dist/core/__tests__/seam/reopen-invalidated-worktree.test.js +60 -0
- package/dist/core/bash-jobs.d.ts +20 -8
- package/dist/core/bash-jobs.js +40 -21
- package/dist/core/canvas/types.d.ts +4 -2
- package/dist/core/command.js +1 -1
- package/dist/core/fault-classifier.d.ts +7 -1
- package/dist/core/fault-classifier.js +9 -4
- package/dist/core/provider-failure.d.ts +30 -0
- package/dist/core/provider-failure.js +86 -0
- package/dist/core/runtime/broker/event-projection.d.ts +0 -3
- package/dist/core/runtime/broker/event-projection.js +2 -15
- package/dist/core/runtime/broker/fault-retry.js +16 -0
- package/dist/core/runtime/broker-persona-guidance.js +12 -0
- package/dist/core/runtime/broker.js +0 -5
- package/dist/core/runtime/fault.d.ts +2 -1
- package/dist/core/runtime/fault.js +39 -1
- package/dist/core/runtime/host.js +10 -1
- package/dist/core/runtime/kickoff.d.ts +3 -0
- package/dist/core/runtime/kickoff.js +24 -4
- package/dist/core/runtime/reopen.d.ts +2 -2
- package/dist/core/runtime/reopen.js +6 -4
- package/dist/core/runtime/revive.js +3 -3
- package/dist/core/runtime/spawn.js +5 -6
- package/dist/core/runtime/tmux-bindings.js +14 -3
- package/dist/core/termrender/version.d.ts +1 -1
- package/dist/core/termrender/version.js +1 -1
- package/dist/core/worktree-close.d.ts +4 -0
- package/dist/core/worktree-close.js +228 -0
- package/dist/core/worktree-containment.d.ts +14 -0
- package/dist/core/worktree-containment.js +48 -0
- package/dist/core/worktree-mutation-async.d.ts +13 -0
- package/dist/core/worktree-mutation-async.js +281 -0
- package/dist/core/worktree-sweep.js +24 -82
- package/dist/core/worktree.d.ts +1 -0
- package/dist/core/worktree.js +7 -4
- package/dist/daemon/__tests__/integration/api-startup-readiness.test.js +10 -8
- package/dist/daemon/api/__tests__/reopen-delivery.test.js +31 -0
- package/dist/daemon/api/__tests__/seam/api-server.test.js +70 -1
- package/dist/daemon/api/__tests__/seam/leaf-api-parity.test.js +36 -4
- package/dist/daemon/api/handlers/bash-jobs.js +1 -1
- package/dist/daemon/api/handlers/messages.js +33 -14
- package/dist/daemon/api/handlers/reports.js +3 -2
- package/dist/daemon/api/handlers/worktree.js +7 -6
- package/dist/daemon/fleet.d.ts +1 -1
- package/dist/daemon/fleet.js +30 -12
- package/dist/daemon/manage.d.ts +8 -5
- package/dist/daemon/manage.js +63 -40
- package/dist/daemon/reconcilers/broker-supervision.js +10 -1
- package/dist/daemon/reconcilers/managed-worktree-sweep.js +12 -0
- package/dist/daemon/reconcilers/node-lifecycle/tick.d.ts +0 -6
- package/dist/daemon/reconcilers/node-lifecycle/tick.js +1 -13
- package/dist/daemon/reconcilers/node-lifecycle/wants-execution.d.ts +5 -0
- package/dist/daemon/reconcilers/node-lifecycle/wants-execution.js +11 -0
- package/dist/pi-extensions/__tests__/canvas-context-intro.test.js +83 -0
- package/dist/pi-extensions/__tests__/integration/canvas-bash-valve.test.d.ts +1 -0
- package/dist/pi-extensions/__tests__/integration/canvas-bash-valve.test.js +133 -0
- package/dist/pi-extensions/canvas-bash-valve.d.ts +2 -0
- package/dist/pi-extensions/canvas-bash-valve.js +73 -43
- package/dist/pi-extensions/canvas-inbox-watcher.js +0 -2
- package/package.json +1 -1
- package/runtime.lock.json +5 -5
|
@@ -99,6 +99,12 @@ export function listContextDir(nodeId) {
|
|
|
99
99
|
return [];
|
|
100
100
|
return readdirSync(dir).sort();
|
|
101
101
|
}
|
|
102
|
+
/** A retained report proves this node has already done work. It must restart
|
|
103
|
+
* from current context, never by replaying its birth mandate. */
|
|
104
|
+
export function hasRetainedReports(nodeId) {
|
|
105
|
+
const dir = reportsDir(nodeId);
|
|
106
|
+
return existsSync(dir) && readdirSync(dir).some((file) => file.endsWith('.md'));
|
|
107
|
+
}
|
|
102
108
|
/** Capture revive bearings for `meta`: read the pending yield note, advance the
|
|
103
109
|
* feed cursor past unread reports, and capture external persona framing.
|
|
104
110
|
* Revive paths call it once, then pass the result to the pure kickoff builder. */
|
|
@@ -113,9 +119,23 @@ export function drainBearings(meta) {
|
|
|
113
119
|
let unreadDigest = null;
|
|
114
120
|
if (entries.length > 0) {
|
|
115
121
|
writeCursor(nodeId, entries.at(-1).entry_id);
|
|
116
|
-
// The launch
|
|
117
|
-
//
|
|
118
|
-
|
|
122
|
+
// The launch argv carries one message. Keep coalescing card-free runs, but
|
|
123
|
+
// start a new batch at each entry with cards. A batch's cards are therefore
|
|
124
|
+
// directly ahead of its coalesced text, so they cannot leap an earlier body.
|
|
125
|
+
const cardsFor = (entry) => {
|
|
126
|
+
const cards = entry.data?.['cards'];
|
|
127
|
+
return Array.isArray(cards) ? cards.filter((card) => typeof card === 'string') : [];
|
|
128
|
+
};
|
|
129
|
+
const segments = [];
|
|
130
|
+
for (const entry of entries) {
|
|
131
|
+
if (cardsFor(entry).length > 0 || segments.length === 0)
|
|
132
|
+
segments.push([]);
|
|
133
|
+
segments.at(-1).push(entry);
|
|
134
|
+
}
|
|
135
|
+
unreadDigest = segments.map((segment) => [
|
|
136
|
+
...cardsFor(segment[0]),
|
|
137
|
+
coalesce(segment).map((delivery) => delivery.text).join('\n\n'),
|
|
138
|
+
].join('\n\n')).join('\n\n');
|
|
119
139
|
}
|
|
120
140
|
const drift = personaDrift(nodeId);
|
|
121
141
|
const driftGuidance = drift?.guidance === undefined || drift.guidance === ''
|
|
@@ -261,7 +281,7 @@ export function buildReviveKickoff(meta, bearings, wakeReason) {
|
|
|
261
281
|
// (audit 2026-06-09, Bug 4: mq45b6ch-9ecc2f03), whose only mandate on disk IS
|
|
262
282
|
// the goal. Surface the goal then. When a roadmap exists it stays the sole
|
|
263
283
|
// source of truth (the goal is usually stale by comparison) — unchanged.
|
|
264
|
-
if (!hasRoadmapBody) {
|
|
284
|
+
if (!hasRoadmapBody && !hasRetainedReports(nodeId)) {
|
|
265
285
|
const goal = readGoal(nodeId);
|
|
266
286
|
if (goal !== null && goal.trim() !== '') {
|
|
267
287
|
parts.push(`<goal file="${goalPath(nodeId)}">\n${goal.trim()}\n</goal>`);
|
|
@@ -25,14 +25,14 @@ export declare function commitReopen(nodeId: string, expectedFinalReport: string
|
|
|
25
25
|
* unlatched node is valid here — it still becomes resident. Writing lifecycle
|
|
26
26
|
* first leaves a failed latch CAS with the canonical-final pointer intact.
|
|
27
27
|
* Both writes finish before either delivery channel begins. */
|
|
28
|
-
export declare function commitReopenResident(nodeId: string):
|
|
28
|
+
export declare function commitReopenResident(nodeId: string, expectedFinalReport?: string): string | null;
|
|
29
29
|
/** Convenience wrapper for a doorway with NO intervening fallible step between
|
|
30
30
|
* the gate check and the reopen clear (`node lifecycle revive` has nothing
|
|
31
31
|
* fallible between the gate and `reviveNode`). Validates and, when `reopen`,
|
|
32
32
|
* clears in one call.
|
|
33
33
|
*
|
|
34
34
|
* - `reopen` false + latched → throws `node_finalized`.
|
|
35
|
-
* - `reopen` true + latched → CAS-clears the latch (side effect) and returns.
|
|
35
|
+
* - `reopen` true + latched → makes the node resident and CAS-clears the latch (side effect) and returns.
|
|
36
36
|
* - `reopen` true + not latched → throws `not_finalized`.
|
|
37
37
|
* - `reopen` false + not latched → no-op (the common case). */
|
|
38
38
|
export declare function assertReopenGate(nodeId: string, reopen: boolean): void;
|
|
@@ -104,7 +104,7 @@ export function commitReopen(nodeId, expectedFinalReport) {
|
|
|
104
104
|
* unlatched node is valid here — it still becomes resident. Writing lifecycle
|
|
105
105
|
* first leaves a failed latch CAS with the canonical-final pointer intact.
|
|
106
106
|
* Both writes finish before either delivery channel begins. */
|
|
107
|
-
export function commitReopenResident(nodeId) {
|
|
107
|
+
export function commitReopenResident(nodeId, expectedFinalReport) {
|
|
108
108
|
const finalReport = currentFinalReport(nodeId);
|
|
109
109
|
updateNode(nodeId, { lifecycle: 'resident' });
|
|
110
110
|
// A reopened node that is still parked in a terminal status has to come back
|
|
@@ -116,7 +116,8 @@ export function commitReopenResident(nodeId) {
|
|
|
116
116
|
transition(nodeId, 'revive');
|
|
117
117
|
}
|
|
118
118
|
if (finalReport !== null)
|
|
119
|
-
commitReopen(nodeId, finalReport);
|
|
119
|
+
commitReopen(nodeId, expectedFinalReport ?? finalReport);
|
|
120
|
+
return finalReport;
|
|
120
121
|
}
|
|
121
122
|
/** Convenience wrapper for a doorway with NO intervening fallible step between
|
|
122
123
|
* the gate check and the reopen clear (`node lifecycle revive` has nothing
|
|
@@ -124,12 +125,13 @@ export function commitReopenResident(nodeId) {
|
|
|
124
125
|
* clears in one call.
|
|
125
126
|
*
|
|
126
127
|
* - `reopen` false + latched → throws `node_finalized`.
|
|
127
|
-
* - `reopen` true + latched → CAS-clears the latch (side effect) and returns.
|
|
128
|
+
* - `reopen` true + latched → makes the node resident and CAS-clears the latch (side effect) and returns.
|
|
128
129
|
* - `reopen` true + not latched → throws `not_finalized`.
|
|
129
130
|
* - `reopen` false + not latched → no-op (the common case). */
|
|
130
131
|
export function assertReopenGate(nodeId, reopen) {
|
|
131
132
|
if (reopen) {
|
|
132
|
-
|
|
133
|
+
const expectedFinalReport = assertFinalizedForReopen(nodeId);
|
|
134
|
+
commitReopenResident(nodeId, expectedFinalReport);
|
|
133
135
|
return;
|
|
134
136
|
}
|
|
135
137
|
assertNotFinalized(nodeId);
|
|
@@ -31,7 +31,7 @@ import { isParked, transition } from './lifecycle.js';
|
|
|
31
31
|
import { fanDoctrineWake } from './close.js';
|
|
32
32
|
import { InputError } from '../io.js';
|
|
33
33
|
import { buildPiArgv } from './launch.js';
|
|
34
|
-
import { buildReviveKickoff, drainBearings, readGoal, readYieldMessage, RUNTIME_RESTART_CONTINUATION } from './kickoff.js';
|
|
34
|
+
import { buildReviveKickoff, drainBearings, hasRetainedReports, readGoal, readYieldMessage, RUNTIME_RESTART_CONTINUATION } from './kickoff.js';
|
|
35
35
|
import { readRoadmap } from './roadmap.js';
|
|
36
36
|
import { encodeKickoffOrigin, KICKOFF_ORIGIN_ENV } from './stamp/protocol.js';
|
|
37
37
|
import { headlessBrokerHost } from './host.js';
|
|
@@ -105,7 +105,7 @@ function resumableSessionArgs(nodeId, meta, resume) {
|
|
|
105
105
|
}
|
|
106
106
|
// Return type
|
|
107
107
|
/** A relaunch that has NO transcript to resume or branch from, and no durable
|
|
108
|
-
* work state on disk (no roadmap,
|
|
108
|
+
* work state on disk (no roadmap, yield note, or retained report), is not a revive at all — the
|
|
109
109
|
* node never got a conversation off the ground, so there is no "previous
|
|
110
110
|
* in-memory context" that was lost. pi does not write a `.jsonl` until the
|
|
111
111
|
* first turn, so an idle node the user never messaged is the common case: it
|
|
@@ -116,7 +116,7 @@ function resumableSessionArgs(nodeId, meta, resume) {
|
|
|
116
116
|
* a BIRTH instead: replay the spawn mandate when it has one, or boot with no
|
|
117
117
|
* prompt at all and leave it sitting exactly where it was. */
|
|
118
118
|
function isUnstartedBirth(nodeId) {
|
|
119
|
-
return readRoadmap(nodeId) === null && readYieldMessage(nodeId) === null;
|
|
119
|
+
return readRoadmap(nodeId) === null && readYieldMessage(nodeId) === null && !hasRetainedReports(nodeId);
|
|
120
120
|
}
|
|
121
121
|
/** Whether a fresh context window would have anything on disk to stand on: a
|
|
122
122
|
* goal, a roadmap, or both. The negative is what makes a fresh cycle worse
|
|
@@ -15,7 +15,7 @@ import { spawnNode, currentNodeContext, rootOfSpine, newNodeId, preflightNodeId
|
|
|
15
15
|
import { resolveProfileOperand } from '../profiles/manifest.js';
|
|
16
16
|
import { selectProfileForCwd, selectProfileForCwdReadOnly } from '../profiles/select.js';
|
|
17
17
|
import { buildLaunchSpecAsync, buildPiArgv } from './launch.js';
|
|
18
|
-
import {
|
|
18
|
+
import { createManagedWorktreeAsync, rollbackManagedWorktreeAsync } from '../worktree-mutation-async.js';
|
|
19
19
|
import { usage, brokerLaunchFailed } from '../errors.js';
|
|
20
20
|
import { writeGoal } from './kickoff.js';
|
|
21
21
|
import { appendSituationalContext, formatSituationalProse } from './situational-context.js';
|
|
@@ -25,7 +25,6 @@ import { encodeKickoffOrigin, KICKOFF_ORIGIN_ENV } from './stamp/protocol.js';
|
|
|
25
25
|
import { canonicalSessionFile, contextDir, findNodeBySessionFile, getNode, fullName, recordPid, setFrozen } from '../canvas/index.js';
|
|
26
26
|
import { boundFleet, brokerThresholdsForDaemon } from './fleet.js';
|
|
27
27
|
import { emitEvent } from '../events/emit.js';
|
|
28
|
-
import { jobDir } from '../canvas/paths.js';
|
|
29
28
|
import { openViewerWindow, focusOf, windowOfPane, } from './placement.js';
|
|
30
29
|
import { waitForBrokerViewSocket } from './placement-tmux.js';
|
|
31
30
|
import { transition } from './lifecycle.js';
|
|
@@ -259,7 +258,7 @@ export async function spawnChildPrepared(opts, beforeBrokerLaunch) {
|
|
|
259
258
|
let spawnCwd = opts.cwd;
|
|
260
259
|
try {
|
|
261
260
|
if (wantsWorktree) {
|
|
262
|
-
managedWorktree =
|
|
261
|
+
managedWorktree = await createManagedWorktreeAsync(opts.worktreeCwd ?? opts.cwd, nodeId, opts.worktreeBase);
|
|
263
262
|
spawnCwd = managedWorktree.path;
|
|
264
263
|
}
|
|
265
264
|
// Spine: a managed child reports up to its spawner (has a manager); an
|
|
@@ -409,7 +408,7 @@ export async function spawnChildPrepared(opts, beforeBrokerLaunch) {
|
|
|
409
408
|
if (placed.pid === null) {
|
|
410
409
|
const error = new Error(`broker host returned no pid for ${meta.node_id}`);
|
|
411
410
|
transition(meta.node_id, 'crash', { reason: 'launch_failed', outcome: launchFailureOutcome(error) });
|
|
412
|
-
throw brokerLaunchFailed(`failed to launch the broker engine for ${meta.node_id} (${meta.name}) — the node was not started.`, `Inspect
|
|
411
|
+
throw brokerLaunchFailed(`failed to launch the broker engine for ${meta.node_id} (${meta.name}) — the node was not started.`, `Inspect canonical event diagnostics with \`crtr sys logs --node ${meta.node_id}\`, then verify the pi engine can start in this environment.`);
|
|
413
412
|
}
|
|
414
413
|
recordPid(meta.node_id, placed.pid);
|
|
415
414
|
// A root created through `node new --root` must accept viewers before the
|
|
@@ -425,7 +424,7 @@ export async function spawnChildPrepared(opts, beforeBrokerLaunch) {
|
|
|
425
424
|
? `the root broker ${meta.node_id} could not start — ${why}`
|
|
426
425
|
: `the root broker ${meta.node_id} never bound its view socket — it was not started.`, why !== null
|
|
427
426
|
? 'Resolve the cause named above, then retry.'
|
|
428
|
-
: `The broker engine exited before binding its view socket. Inspect
|
|
427
|
+
: `The broker engine exited before binding its view socket. Inspect canonical event diagnostics with \`crtr sys logs --node ${meta.node_id}\`, then retry.`);
|
|
429
428
|
}
|
|
430
429
|
// A --root opens NO viewer from here. spawnChild runs daemon-side only, and
|
|
431
430
|
// the daemon is paneless by construction (manage.ts strips TMUX/TMUX_PANE
|
|
@@ -484,7 +483,7 @@ export async function spawnChildPrepared(opts, beforeBrokerLaunch) {
|
|
|
484
483
|
// worktree — the node stays alive (crashed, if the launch itself failed)
|
|
485
484
|
// with its worktree intact rather than pinned to a deleted path.
|
|
486
485
|
if (managedWorktree !== undefined && nodeId !== undefined && getNode(nodeId) === null) {
|
|
487
|
-
|
|
486
|
+
await rollbackManagedWorktreeAsync(managedWorktree);
|
|
488
487
|
}
|
|
489
488
|
throw err;
|
|
490
489
|
}
|
|
@@ -586,14 +586,25 @@ function reconcileTmuxBindings(bindingSnapshot, passthroughSnapshot = []) {
|
|
|
586
586
|
}
|
|
587
587
|
}
|
|
588
588
|
// Restore every wrapper crouter still owns before the ordinary binding sweep.
|
|
589
|
-
// A live line that
|
|
590
|
-
// is protected from this and every later
|
|
591
|
-
// passthrough preference off and on again.
|
|
589
|
+
// A live line that matches neither the fingerprint nor the original crouter
|
|
590
|
+
// recorded is a user's later rebind: it is protected from this and every later
|
|
591
|
+
// reconciliation until they toggle the passthrough preference off and on again.
|
|
592
|
+
//
|
|
593
|
+
// A live line equal to the ORIGINAL is not a rebind. It is the user's own tmux
|
|
594
|
+
// config re-sourced over the wrapper, which every `source-file` and every fresh
|
|
595
|
+
// tmux server does. Relinquishing there disarmed passthrough silently and
|
|
596
|
+
// permanently for anyone whose config binds a key crouter wraps, so that case
|
|
597
|
+
// falls through with nothing to restore — the wrap pass below re-reads the live
|
|
598
|
+
// line as the original and wraps it again. It also releases a key already stuck
|
|
599
|
+
// relinquished: matching the recorded original is proof the user did not rebind
|
|
600
|
+
// it to something of their own.
|
|
592
601
|
const protectedRootKeys = new Set();
|
|
593
602
|
const wrappers = [];
|
|
594
603
|
for (const prior of manifest.wrappers) {
|
|
595
604
|
const desired = desiredWrappers.get(prior.key);
|
|
596
605
|
const live = bindingAt(ROOT_TABLE, prior.key);
|
|
606
|
+
if (live !== null && live === prior.original)
|
|
607
|
+
continue;
|
|
597
608
|
if (prior.state === 'relinquished' || live !== prior.wrapper) {
|
|
598
609
|
protectedRootKeys.add(prior.key);
|
|
599
610
|
if (desired !== undefined) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const TERMRENDER_VERSION = "4.12.
|
|
1
|
+
export declare const TERMRENDER_VERSION = "4.12.12";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const TERMRENDER_VERSION = '4.12.
|
|
1
|
+
export const TERMRENDER_VERSION = '4.12.12';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type CloseManagedWorktreeResult } from './worktree.js';
|
|
2
|
+
/** Async daemon executor for explicit close. The lock wait and every Git
|
|
3
|
+
* subprocess yield to the daemon event loop. */
|
|
4
|
+
export declare function closeManagedWorktreeAsync(nodeId: string): Promise<CloseManagedWorktreeResult>;
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { existsSync, realpathSync } from 'node:fs';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import { getNode, updateNode } from './canvas/index.js';
|
|
4
|
+
import { withExclusiveDirectoryLockAsync } from './exclusive-lock.js';
|
|
5
|
+
import { gitAsync } from './git.js';
|
|
6
|
+
import { proveBranchContained } from './worktree-containment.js';
|
|
7
|
+
import { concludeAbsentManagedWorktreeAsync } from './worktree-mutation-async.js';
|
|
8
|
+
import { parseStatusPorcelain, planLandIntoCheckout } from './worktree-landing.js';
|
|
9
|
+
import { WORKTREE_LOCK_WAIT_MS, checkoutPathForBranchInList, missingWorktreeRecoveryHint, persistClosedWorktreeState, samePath, worktreeLockPathForCommonDir, WorktreeError } from './worktree.js';
|
|
10
|
+
import { shellQuote } from '../shared/shell-quote.js';
|
|
11
|
+
function detailOf(result) {
|
|
12
|
+
return (result.stderr.trim() || result.stdout.trim()).trim();
|
|
13
|
+
}
|
|
14
|
+
async function runGit(cwd, args, code, next) {
|
|
15
|
+
const result = await gitAsync(args, cwd);
|
|
16
|
+
if (result.status !== 0)
|
|
17
|
+
throw new WorktreeError(code, `git ${args.join(' ')} failed`, next, detailOf(result));
|
|
18
|
+
return result.stdout.trim();
|
|
19
|
+
}
|
|
20
|
+
async function commonGitDir(cwd) {
|
|
21
|
+
const output = await runGit(cwd, ['rev-parse', '--git-common-dir'], 'git_common_dir_failed', 'Inspect the repository git metadata, then retry.');
|
|
22
|
+
return realpathSync(resolve(cwd, output));
|
|
23
|
+
}
|
|
24
|
+
async function resolveLandableBase(cwd, baseRef) {
|
|
25
|
+
const ref = `refs/heads/${baseRef}`;
|
|
26
|
+
const exists = await gitAsync(['show-ref', '--verify', '--quiet', ref], cwd);
|
|
27
|
+
if (exists.status === 1 && exists.executionFailed !== true) {
|
|
28
|
+
throw new WorktreeError('missing_base_branch', `managed worktree base '${baseRef}' does not name an existing local branch`, 'The base must be a local branch that landing can fast-forward — freshen your local branch from origin first (rebase-not-merge), then base on it.');
|
|
29
|
+
}
|
|
30
|
+
if (exists.status !== 0) {
|
|
31
|
+
const execution = exists.processError === undefined ? '' : `\nprocess error: ${exists.processError}`;
|
|
32
|
+
throw new WorktreeError('base_branch_inspection_failed', `could not inspect local base branch '${baseRef}' (git show-ref exited with status ${exists.status})`, 'Inspect the repository and its Git metadata, then retry.', `status: ${exists.status}\nstderr: ${exists.stderr.trim() || '<empty>'}${execution}`);
|
|
33
|
+
}
|
|
34
|
+
return runGit(cwd, ['rev-parse', '--verify', ref], 'base_branch_resolve_failed', 'Inspect the local base branch, then retry.');
|
|
35
|
+
}
|
|
36
|
+
async function rebaseInProgress(cwd) {
|
|
37
|
+
for (const path of ['rebase-merge', 'rebase-apply']) {
|
|
38
|
+
const gitPath = await runGit(cwd, ['rev-parse', '--git-path', path], 'git_path_failed', 'Inspect the worktree manually, then retry.');
|
|
39
|
+
if (existsSync(gitPath))
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
async function registeredWorktree(cwd, path, branch) {
|
|
45
|
+
const list = await gitAsync(['worktree', 'list', '--porcelain'], cwd);
|
|
46
|
+
if (list.status !== 0)
|
|
47
|
+
return false;
|
|
48
|
+
let current = null;
|
|
49
|
+
for (const line of list.stdout.split('\n')) {
|
|
50
|
+
if (line.startsWith('worktree '))
|
|
51
|
+
current = line.slice('worktree '.length).trim();
|
|
52
|
+
else if (current !== null && samePath(current, path) && line === `branch refs/heads/${branch}`)
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
function deferredCleanupResult(wt) {
|
|
58
|
+
return {
|
|
59
|
+
worktree_removed: false,
|
|
60
|
+
worktree_remove_error: `cleanup pending: the caller checkout at ${wt.path} remains intact. After its node exits, run \`git -C ${shellQuote(wt.repo_root)} worktree remove ${shellQuote(wt.path)}\` after confirming it is safe to delete.`,
|
|
61
|
+
branch_deleted: false,
|
|
62
|
+
branch_delete_error: `cleanup pending: local branch ${wt.branch} remains checked out at ${wt.path}; delete it only after that checkout is removed and its landed commit is still contained in ${wt.base_ref}.`,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function recordBlockedLandIntent(nodeId, blocked) {
|
|
66
|
+
const current = getNode(nodeId)?.managed_worktree;
|
|
67
|
+
if (current === undefined || current === null || current.state !== 'open')
|
|
68
|
+
return;
|
|
69
|
+
const { sweep: _sweep, ...retained } = current;
|
|
70
|
+
updateNode(nodeId, { managed_worktree: { ...retained, land_intent: { at: new Date().toISOString(), blocked } } });
|
|
71
|
+
}
|
|
72
|
+
async function dropStashIfStillTip(cwd, stashSha) {
|
|
73
|
+
const tip = await gitAsync(['rev-parse', '--verify', '--quiet', 'refs/stash'], cwd);
|
|
74
|
+
if (tip.status === 0 && tip.stdout.trim() === stashSha)
|
|
75
|
+
await gitAsync(['stash', 'drop'], cwd);
|
|
76
|
+
}
|
|
77
|
+
async function landIntoBaseCheckout(baseCheckout, branch, baseSha, landedSha) {
|
|
78
|
+
const status = await gitAsync(['status', '--porcelain'], baseCheckout);
|
|
79
|
+
if (status.status !== 0)
|
|
80
|
+
return { ok: false, detail: detailOf(status) };
|
|
81
|
+
const diff = await gitAsync(['diff', '--name-only', baseSha, landedSha], baseCheckout);
|
|
82
|
+
if (diff.status !== 0)
|
|
83
|
+
return { ok: false, detail: detailOf(diff) };
|
|
84
|
+
const incoming = diff.stdout.split('\n').map((line) => line.trim()).filter((line) => line !== '');
|
|
85
|
+
const plan = planLandIntoCheckout(parseStatusPorcelain(status.stdout), incoming);
|
|
86
|
+
if (plan.kind === 'refuse')
|
|
87
|
+
return { ok: false, detail: `untracked files in ${baseCheckout} would be overwritten by the incoming commits: ${plan.collisions.join(', ')}` };
|
|
88
|
+
const merge = async () => {
|
|
89
|
+
const result = await gitAsync(['merge', '--ff-only', landedSha], baseCheckout);
|
|
90
|
+
return result.status === 0 ? { ok: true } : { ok: false, detail: detailOf(result) };
|
|
91
|
+
};
|
|
92
|
+
if (plan.kind === 'direct')
|
|
93
|
+
return merge();
|
|
94
|
+
const before = await gitAsync(['rev-parse', '--verify', '--quiet', 'refs/stash'], baseCheckout);
|
|
95
|
+
const beforeSha = before.status === 0 ? before.stdout.trim() : null;
|
|
96
|
+
const pushed = await gitAsync(['stash', 'push', '--message', `crtr landing ${branch}`], baseCheckout);
|
|
97
|
+
if (pushed.status !== 0)
|
|
98
|
+
return { ok: false, detail: detailOf(pushed) };
|
|
99
|
+
const after = await gitAsync(['rev-parse', '--verify', '--quiet', 'refs/stash'], baseCheckout);
|
|
100
|
+
const stashSha = after.status === 0 ? after.stdout.trim() : null;
|
|
101
|
+
if (stashSha === null || stashSha === beforeSha)
|
|
102
|
+
return merge();
|
|
103
|
+
const recovery = `local changes from ${baseCheckout} are retained in stash ${stashSha}; recover them with \`git -C ${shellQuote(baseCheckout)} stash apply ${stashSha}\` and resolve any conflict.`;
|
|
104
|
+
const landed = await merge();
|
|
105
|
+
if (!landed.ok) {
|
|
106
|
+
if ((await gitAsync(['stash', 'apply', stashSha], baseCheckout)).status === 0) {
|
|
107
|
+
await dropStashIfStillTip(baseCheckout, stashSha);
|
|
108
|
+
return landed;
|
|
109
|
+
}
|
|
110
|
+
return { ok: false, detail: `${landed.detail}\n${recovery}` };
|
|
111
|
+
}
|
|
112
|
+
if ((await gitAsync(['stash', 'apply', stashSha], baseCheckout)).status === 0) {
|
|
113
|
+
await dropStashIfStillTip(baseCheckout, stashSha);
|
|
114
|
+
return { ok: true };
|
|
115
|
+
}
|
|
116
|
+
await gitAsync(['reset', '--hard', landedSha], baseCheckout);
|
|
117
|
+
return { ok: true, stash: `the shared base checkout was reset to landed commit ${landedSha} because local changes conflicted with it. ${recovery}` };
|
|
118
|
+
}
|
|
119
|
+
async function closeLocked(nodeId) {
|
|
120
|
+
const node = getNode(nodeId);
|
|
121
|
+
if (node === null)
|
|
122
|
+
throw new WorktreeError('unknown_node', `unknown node: ${nodeId}`, 'Run this from a live node, or pass a real node id once that command supports it.');
|
|
123
|
+
const wt = node?.managed_worktree?.state === 'open' ? node.managed_worktree : null;
|
|
124
|
+
if (wt === null)
|
|
125
|
+
throw new WorktreeError('no_managed_worktree', `node ${nodeId} has no open managed worktree`, 'Nothing to close for this node.');
|
|
126
|
+
if (!existsSync(wt.path))
|
|
127
|
+
throw new WorktreeError('worktree_missing', `managed worktree path is missing: ${wt.path}`, missingWorktreeRecoveryHint(wt));
|
|
128
|
+
if (await rebaseInProgress(wt.path))
|
|
129
|
+
throw new WorktreeError('rebase_in_progress', 'this managed worktree is mid-rebase', `Resolve conflicts in ${wt.path}, run \`git rebase --continue\` there, then rerun \`crtr node worktree close\`.`);
|
|
130
|
+
const status = await runGit(wt.path, ['status', '--porcelain'], 'status_failed', 'Inspect the worktree manually, then retry.');
|
|
131
|
+
if (status !== '')
|
|
132
|
+
throw new WorktreeError('dirty_worktree', 'managed worktree has uncommitted changes', `Commit the work in ${wt.path}, then rerun \`crtr node worktree close\`.`);
|
|
133
|
+
const branch = await runGit(wt.path, ['rev-parse', '--abbrev-ref', 'HEAD'], 'branch_check_failed', 'Inspect the worktree manually, then retry.');
|
|
134
|
+
const head = await runGit(wt.path, ['rev-parse', 'HEAD'], 'landed_sha_failed', 'Inspect the worktree checkout manually, then rerun `crtr node worktree close`.');
|
|
135
|
+
if (branch !== wt.branch) {
|
|
136
|
+
const recorded = await gitAsync(['show-ref', '--verify', '--quiet', `refs/heads/${wt.branch}`], wt.path);
|
|
137
|
+
if (recorded.status === 0 || branch === 'HEAD' || !(await registeredWorktree(wt.repo_root, wt.path, branch))) {
|
|
138
|
+
throw new WorktreeError('wrong_branch', `managed worktree is not on its recorded branch (expected ${wt.branch}, found ${branch === 'HEAD' ? 'detached HEAD' : branch})`, `Inspect ${wt.path}, then rerun \`crtr node worktree close\`.`);
|
|
139
|
+
}
|
|
140
|
+
if (await proveBranchContained(wt.path, wt, head) === null) {
|
|
141
|
+
throw new WorktreeError('branch_moved_unlanded', `managed worktree's recorded branch ${wt.branch} no longer exists; its checkout is now on ${branch} at ${head}, which carries content local base branch '${wt.base_ref}' does not yet contain`, `Land or push ${branch} through its own workflow before closing.`);
|
|
142
|
+
}
|
|
143
|
+
const commonDir = await commonGitDir(wt.path);
|
|
144
|
+
if (!(await registeredWorktree(wt.repo_root, wt.path, branch)) || (await runGit(wt.path, ['rev-parse', '--abbrev-ref', 'HEAD'], 'branch_check_failed', 'Inspect the worktree manually, then retry.')) !== branch || (await runGit(wt.path, ['rev-parse', 'HEAD'], 'branch_check_failed', 'Inspect the worktree manually, then retry.')) !== head) {
|
|
145
|
+
throw new WorktreeError('wrong_branch', `managed worktree at ${wt.path} changed while closing`, `Inspect ${wt.path}, then rerun \`crtr node worktree close\`.`);
|
|
146
|
+
}
|
|
147
|
+
persistClosedWorktreeState(nodeId, { ...wt, disposal: { observed_branch: branch, observed_sha: head, common_dir: commonDir, authorized: new Date().toISOString() } }, 'pending');
|
|
148
|
+
return { node_id: nodeId, branch, worktree_path: wt.path, landed_sha: head, ...deferredCleanupResult(wt), branch_delete_error: `${branch} is not a crtr-managed branch and will never be deleted automatically; it is preserved once the checkout above is removed.` };
|
|
149
|
+
}
|
|
150
|
+
// Decide whether landing remains before resolving a destination. A diverged
|
|
151
|
+
// local base cannot replay history that the recorded upstream already has.
|
|
152
|
+
if (await proveBranchContained(wt.path, wt, head) !== null) {
|
|
153
|
+
persistClosedWorktreeState(nodeId, wt, 'pending');
|
|
154
|
+
return { node_id: nodeId, branch: wt.branch, worktree_path: wt.path, landed_sha: head, ...deferredCleanupResult(wt) };
|
|
155
|
+
}
|
|
156
|
+
let baseSha;
|
|
157
|
+
try {
|
|
158
|
+
baseSha = await resolveLandableBase(wt.path, wt.base_ref);
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
if (!(error instanceof WorktreeError) || error.code !== 'missing_base_branch' || head !== wt.base_sha)
|
|
162
|
+
throw error;
|
|
163
|
+
persistClosedWorktreeState(nodeId, wt, 'pending');
|
|
164
|
+
return { node_id: nodeId, branch: wt.branch, worktree_path: wt.path, landed_sha: wt.base_sha, ...deferredCleanupResult(wt) };
|
|
165
|
+
}
|
|
166
|
+
const rebase = await gitAsync(['rebase', baseSha], wt.path);
|
|
167
|
+
if (rebase.status !== 0)
|
|
168
|
+
throw new WorktreeError('rebase_failed', `rebase onto local base branch '${wt.base_ref}' did not complete`, `Resolve conflicts in ${wt.path}, run \`git rebase --continue\` there, then rerun \`crtr node worktree close\`.`, detailOf(rebase));
|
|
169
|
+
const landedSha = await runGit(wt.path, ['rev-parse', 'HEAD'], 'landed_sha_failed', 'Inspect the worktree checkout manually, then rerun `crtr node worktree close`.');
|
|
170
|
+
const blocked = (message, next, detail) => {
|
|
171
|
+
recordBlockedLandIntent(nodeId, message);
|
|
172
|
+
return new WorktreeError('land_base_failed', message, next, detail);
|
|
173
|
+
};
|
|
174
|
+
const fastForward = await gitAsync(['merge-base', '--is-ancestor', baseSha, landedSha], wt.path);
|
|
175
|
+
if (fastForward.status !== 0)
|
|
176
|
+
throw blocked(`rebased worktree is not a fast-forward of local base branch '${wt.base_ref}'`, 'Ask the user how to land this managed worktree.', detailOf(fastForward));
|
|
177
|
+
const list = await runGit(wt.path, ['worktree', 'list', '--porcelain'], 'worktree_list_failed', 'Inspect the repository worktrees manually, then retry.');
|
|
178
|
+
const baseCheckout = checkoutPathForBranchInList(list, wt.base_ref);
|
|
179
|
+
let stashNote;
|
|
180
|
+
if (baseCheckout !== null) {
|
|
181
|
+
const checkoutHead = await gitAsync(['rev-parse', 'HEAD'], baseCheckout);
|
|
182
|
+
if (checkoutHead.status !== 0 || checkoutHead.stdout.trim() !== baseSha)
|
|
183
|
+
throw blocked(`local base branch '${wt.base_ref}' changed while this worktree was closing`, `Reconcile the base checkout at ${baseCheckout}, then rerun \`crtr node worktree close\`.`, checkoutHead.status !== 0 ? detailOf(checkoutHead) : `expected ${baseSha}, found ${checkoutHead.stdout.trim()}`);
|
|
184
|
+
const landed = await landIntoBaseCheckout(baseCheckout, wt.branch, baseSha, landedSha);
|
|
185
|
+
if (!landed.ok)
|
|
186
|
+
throw blocked(`could not fast-forward local base branch '${wt.base_ref}' to this worktree`, `Local base branch '${wt.base_ref}' is checked out at ${baseCheckout} in a state that blocks a fast-forward.`, landed.detail);
|
|
187
|
+
stashNote = landed.stash;
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
const update = await gitAsync(['update-ref', `refs/heads/${wt.base_ref}`, landedSha, baseSha], wt.path);
|
|
191
|
+
if (update.status !== 0)
|
|
192
|
+
throw blocked(`could not fast-forward local base branch '${wt.base_ref}' to this worktree`, 'Ask the user how to land this managed worktree.', detailOf(update));
|
|
193
|
+
}
|
|
194
|
+
persistClosedWorktreeState(nodeId, wt, 'pending');
|
|
195
|
+
return { node_id: nodeId, branch: wt.branch, worktree_path: wt.path, landed_sha: landedSha, ...deferredCleanupResult(wt), ...(stashNote === undefined ? {} : { base_checkout_stash: stashNote }) };
|
|
196
|
+
}
|
|
197
|
+
/** Async daemon executor for explicit close. The lock wait and every Git
|
|
198
|
+
* subprocess yield to the daemon event loop. */
|
|
199
|
+
export async function closeManagedWorktreeAsync(nodeId) {
|
|
200
|
+
const wt = getNode(nodeId)?.managed_worktree;
|
|
201
|
+
if (wt === undefined || wt === null || wt.state !== 'open')
|
|
202
|
+
return closeLocked(nodeId);
|
|
203
|
+
if (!existsSync(wt.path)) {
|
|
204
|
+
const conclusion = await concludeAbsentManagedWorktreeAsync(nodeId);
|
|
205
|
+
if (conclusion !== null) {
|
|
206
|
+
return {
|
|
207
|
+
node_id: nodeId,
|
|
208
|
+
branch: conclusion.dropped.branch,
|
|
209
|
+
worktree_path: conclusion.dropped.worktree_path,
|
|
210
|
+
landed_sha: conclusion.landedSha,
|
|
211
|
+
worktree_removed: true,
|
|
212
|
+
branch_deleted: conclusion.dropped.branch_deleted,
|
|
213
|
+
...(conclusion.dropped.branch_delete_error === undefined ? {} : { branch_delete_error: conclusion.dropped.branch_delete_error }),
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
const current = getNode(nodeId)?.managed_worktree;
|
|
218
|
+
if (current === undefined || current === null || current.state !== 'open')
|
|
219
|
+
return closeLocked(nodeId);
|
|
220
|
+
const cwd = existsSync(current.path) ? current.path : current.repo_root;
|
|
221
|
+
const commonDir = await commonGitDir(cwd);
|
|
222
|
+
return withExclusiveDirectoryLockAsync(worktreeLockPathForCommonDir(commonDir), () => closeLocked(nodeId), {
|
|
223
|
+
// Leave room for the API handler to serialize the typed refusal before its
|
|
224
|
+
// 30s client socket deadline.
|
|
225
|
+
timeoutMs: Math.min(WORKTREE_LOCK_WAIT_MS, 25_000),
|
|
226
|
+
timeoutError: () => new WorktreeError('worktree_lock_timeout', `timed out waiting to create a managed worktree in ${commonDir}`, 'Wait for the other managed-worktree operation to finish, then retry.'),
|
|
227
|
+
});
|
|
228
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ManagedWorktree } from './canvas/index.js';
|
|
2
|
+
export interface BranchContainmentProof {
|
|
3
|
+
containingRef: string;
|
|
4
|
+
containingSha: string;
|
|
5
|
+
}
|
|
6
|
+
/** Resolve the base branch's configured upstream, or its origin fallback. */
|
|
7
|
+
export declare function upstreamTip(cwd: string, baseRef: string): Promise<{
|
|
8
|
+
ref: string;
|
|
9
|
+
sha: string;
|
|
10
|
+
} | null>;
|
|
11
|
+
/** Prove that a recorded base or its upstream already carries a branch's
|
|
12
|
+
* committed content. This is the one decision point for explicit close and
|
|
13
|
+
* sweep cleanup: destination resolution happens only when this returns null. */
|
|
14
|
+
export declare function proveBranchContained(cwd: string, wt: Pick<ManagedWorktree, 'base_ref'>, branchSha: string): Promise<BranchContainmentProof | null>;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { gitAsync } from './git.js';
|
|
2
|
+
async function revParseRef(cwd, ref) {
|
|
3
|
+
const result = await gitAsync(['rev-parse', '--verify', '--quiet', ref], cwd);
|
|
4
|
+
return result.status === 0 ? result.stdout.trim() : null;
|
|
5
|
+
}
|
|
6
|
+
/** Resolve the base branch's configured upstream, or its origin fallback. */
|
|
7
|
+
export async function upstreamTip(cwd, baseRef) {
|
|
8
|
+
const upstream = await gitAsync(['rev-parse', '--symbolic-full-name', '--verify', `${baseRef}@{upstream}`], cwd);
|
|
9
|
+
const ref = upstream.status === 0 && upstream.stdout.trim().startsWith('refs/')
|
|
10
|
+
? upstream.stdout.trim()
|
|
11
|
+
: `refs/remotes/origin/${baseRef}`;
|
|
12
|
+
const sha = await revParseRef(cwd, ref);
|
|
13
|
+
return sha === null ? null : { ref, sha };
|
|
14
|
+
}
|
|
15
|
+
/** Prove that a recorded base or its upstream already carries a branch's
|
|
16
|
+
* committed content. This is the one decision point for explicit close and
|
|
17
|
+
* sweep cleanup: destination resolution happens only when this returns null. */
|
|
18
|
+
export async function proveBranchContained(cwd, wt, branchSha) {
|
|
19
|
+
const candidates = [];
|
|
20
|
+
const localBaseRef = `refs/heads/${wt.base_ref}`;
|
|
21
|
+
const localBase = await revParseRef(cwd, localBaseRef);
|
|
22
|
+
if (localBase !== null)
|
|
23
|
+
candidates.push({ ref: localBaseRef, sha: localBase });
|
|
24
|
+
const upstream = await upstreamTip(cwd, wt.base_ref);
|
|
25
|
+
if (upstream !== null)
|
|
26
|
+
candidates.push(upstream);
|
|
27
|
+
for (const candidate of candidates) {
|
|
28
|
+
if ((await gitAsync(['merge-base', '--is-ancestor', branchSha, candidate.sha], cwd)).status === 0)
|
|
29
|
+
return { containingRef: candidate.ref, containingSha: candidate.sha };
|
|
30
|
+
}
|
|
31
|
+
for (const candidate of candidates) {
|
|
32
|
+
const cherry = await gitAsync(['cherry', candidate.sha, branchSha], cwd);
|
|
33
|
+
if (cherry.status !== 0)
|
|
34
|
+
continue;
|
|
35
|
+
const lines = cherry.stdout.split('\n').map((line) => line.trim()).filter((line) => line !== '');
|
|
36
|
+
if (lines.every((line) => line.startsWith('-')))
|
|
37
|
+
return { containingRef: candidate.ref, containingSha: candidate.sha };
|
|
38
|
+
}
|
|
39
|
+
for (const candidate of candidates) {
|
|
40
|
+
const candidateTree = await revParseRef(cwd, `${candidate.sha}^{tree}`);
|
|
41
|
+
if (candidateTree === null)
|
|
42
|
+
continue;
|
|
43
|
+
const merged = await gitAsync(['merge-tree', '--write-tree', candidate.sha, branchSha], cwd);
|
|
44
|
+
if (merged.status === 0 && merged.stdout.split('\n')[0]?.trim() === candidateTree)
|
|
45
|
+
return { containingRef: candidate.ref, containingSha: candidate.sha };
|
|
46
|
+
}
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type ManagedWorktree } from './canvas/index.js';
|
|
2
|
+
import { type AbandonManagedWorktreeResult, type AutoDroppedWorktree } from './worktree.js';
|
|
3
|
+
export declare function rollbackManagedWorktreeAsync(wt: ManagedWorktree): Promise<void>;
|
|
4
|
+
export declare function createManagedWorktreeAsync(cwd: string, nodeId: string, baseRef?: string): Promise<ManagedWorktree>;
|
|
5
|
+
export interface AbsentWorktreeConclusion {
|
|
6
|
+
dropped: AutoDroppedWorktree;
|
|
7
|
+
landedSha: string;
|
|
8
|
+
}
|
|
9
|
+
/** Conclude an absent checkout only from the same branch-delivery proof used by
|
|
10
|
+
* push-final and explicit close. */
|
|
11
|
+
export declare function concludeAbsentManagedWorktreeAsync(nodeId: string): Promise<AbsentWorktreeConclusion | null>;
|
|
12
|
+
export declare function autoDropCleanManagedWorktreeAsync(nodeId: string): Promise<AutoDroppedWorktree | null>;
|
|
13
|
+
export declare function abandonManagedWorktreeAsync(nodeId: string, by: string): Promise<AbandonManagedWorktreeResult>;
|