@staff0rd/assist 0.1017.0 → 0.1019.0
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/commands/sessions/web/bundle.js +443 -443
- package/dist/index.js +433 -138
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import { Command } from "commander";
|
|
|
6
6
|
// package.json
|
|
7
7
|
var package_default = {
|
|
8
8
|
name: "@staff0rd/assist",
|
|
9
|
-
version: "0.
|
|
9
|
+
version: "0.1019.0",
|
|
10
10
|
type: "module",
|
|
11
11
|
main: "dist/index.js",
|
|
12
12
|
bin: {
|
|
@@ -8656,8 +8656,8 @@ function subsequenceScore(text18, query) {
|
|
|
8656
8656
|
function scoreFilePath(path109, query) {
|
|
8657
8657
|
const needle = query.trim().toLowerCase();
|
|
8658
8658
|
if (!needle) return 0;
|
|
8659
|
-
const
|
|
8660
|
-
const inBasename = subsequenceScore(
|
|
8659
|
+
const basename36 = path109.slice(path109.lastIndexOf("/") + 1);
|
|
8660
|
+
const inBasename = subsequenceScore(basename36, needle);
|
|
8661
8661
|
if (inBasename !== null) return BASENAME_WEIGHT + inBasename;
|
|
8662
8662
|
return subsequenceScore(path109, needle);
|
|
8663
8663
|
}
|
|
@@ -28590,8 +28590,8 @@ var pinnedPr;
|
|
|
28590
28590
|
function getPinnedPr() {
|
|
28591
28591
|
return pinnedPr;
|
|
28592
28592
|
}
|
|
28593
|
-
function currentPrSelector(
|
|
28594
|
-
return pinnedPr === void 0 ?
|
|
28593
|
+
function currentPrSelector(currentBranch7) {
|
|
28594
|
+
return pinnedPr === void 0 ? currentBranch7() : String(pinnedPr);
|
|
28595
28595
|
}
|
|
28596
28596
|
|
|
28597
28597
|
// src/commands/prs/shared.ts
|
|
@@ -51689,6 +51689,7 @@ function finishStatusChange(session, status2, exitCode, deps2) {
|
|
|
51689
51689
|
);
|
|
51690
51690
|
deps2.dismiss(session.id);
|
|
51691
51691
|
} else deps2.notify();
|
|
51692
|
+
if (status2 !== "running") deps2.idle?.(session);
|
|
51692
51693
|
}
|
|
51693
51694
|
|
|
51694
51695
|
// src/commands/sessions/daemon/applyStatusChange.ts
|
|
@@ -51721,6 +51722,268 @@ function makeStatusChangeHandler(sessions, deps2) {
|
|
|
51721
51722
|
);
|
|
51722
51723
|
}
|
|
51723
51724
|
|
|
51725
|
+
// src/commands/sessions/shared/backlogRunArgs.ts
|
|
51726
|
+
function backlogRunArgs(session) {
|
|
51727
|
+
const args = session.assistArgs;
|
|
51728
|
+
if (session.commandType !== "assist" || !args) return void 0;
|
|
51729
|
+
if (args[0] !== "backlog" || args[1] !== "run" || !args[2]) return void 0;
|
|
51730
|
+
return args;
|
|
51731
|
+
}
|
|
51732
|
+
|
|
51733
|
+
// src/commands/sessions/daemon/transfer/launchOnTarget.ts
|
|
51734
|
+
function launchOnTarget(route, request) {
|
|
51735
|
+
return new Promise((resolve32) => {
|
|
51736
|
+
const capture = {
|
|
51737
|
+
send: (raw) => {
|
|
51738
|
+
const msg = JSON.parse(raw);
|
|
51739
|
+
if (msg.type === "created")
|
|
51740
|
+
resolve32({ ok: true, sessionId: msg.sessionId });
|
|
51741
|
+
else if (msg.type === "error")
|
|
51742
|
+
resolve32({ ok: false, error: String(msg.message) });
|
|
51743
|
+
}
|
|
51744
|
+
};
|
|
51745
|
+
if (!route(capture, request))
|
|
51746
|
+
resolve32({ ok: false, error: `${request.node} is not a linked node` });
|
|
51747
|
+
});
|
|
51748
|
+
}
|
|
51749
|
+
|
|
51750
|
+
// src/commands/sessions/daemon/transfer/settleTransfer.ts
|
|
51751
|
+
function settleTransfer(client, deps2, s, outcome, traceId) {
|
|
51752
|
+
const target = s.transfer?.target ?? "target";
|
|
51753
|
+
if (!outcome.ok) {
|
|
51754
|
+
daemonLog(
|
|
51755
|
+
`session ${s.id} transfer to ${target} failed trace=${traceId}: ${outcome.error}; source kept`
|
|
51756
|
+
);
|
|
51757
|
+
s.transfer = { target, error: outcome.error };
|
|
51758
|
+
deps2.notify();
|
|
51759
|
+
sendTo(client, {
|
|
51760
|
+
type: "error",
|
|
51761
|
+
message: `Transfer to ${target} failed: ${outcome.error}`
|
|
51762
|
+
});
|
|
51763
|
+
return;
|
|
51764
|
+
}
|
|
51765
|
+
daemonLog(
|
|
51766
|
+
`session ${s.id} transferred to ${target} as ${outcome.sessionId} trace=${traceId}; closing source`
|
|
51767
|
+
);
|
|
51768
|
+
s.transfer = void 0;
|
|
51769
|
+
deps2.discard(s.id);
|
|
51770
|
+
sendTo(client, { type: "notice", message: `Transferred to ${target}` });
|
|
51771
|
+
}
|
|
51772
|
+
|
|
51773
|
+
// src/commands/sessions/daemon/transfer/handOffToTarget.ts
|
|
51774
|
+
async function handOffToTarget(client, deps2, s, { args, target, cwd, traceId, snapshot }) {
|
|
51775
|
+
deps2.stop(s.id);
|
|
51776
|
+
deps2.notify();
|
|
51777
|
+
const outcome = await launchOnTarget(deps2.links.route, {
|
|
51778
|
+
type: "create-assist",
|
|
51779
|
+
assistArgs: args,
|
|
51780
|
+
cwd,
|
|
51781
|
+
node: target,
|
|
51782
|
+
title: s.title,
|
|
51783
|
+
subtitle: s.subtitle,
|
|
51784
|
+
traceId,
|
|
51785
|
+
transfer: snapshot
|
|
51786
|
+
});
|
|
51787
|
+
settleTransfer(client, deps2, s, outcome, traceId);
|
|
51788
|
+
}
|
|
51789
|
+
|
|
51790
|
+
// src/commands/sessions/daemon/transfer/queueTransfer.ts
|
|
51791
|
+
function queueTransfer(client, notify2, s, target, cwd) {
|
|
51792
|
+
daemonLog(
|
|
51793
|
+
`session ${s.id} transfer to ${target} queued: agent mid-turn, waiting for idle`
|
|
51794
|
+
);
|
|
51795
|
+
s.transfer = { target, queued: { cwd } };
|
|
51796
|
+
notify2();
|
|
51797
|
+
sendTo(client, {
|
|
51798
|
+
type: "notice",
|
|
51799
|
+
message: `Transfer to ${target} will start once the agent is idle`
|
|
51800
|
+
});
|
|
51801
|
+
}
|
|
51802
|
+
|
|
51803
|
+
// src/commands/sessions/daemon/transfer/transferRefusal.ts
|
|
51804
|
+
function transferRefusal(s, target, links2) {
|
|
51805
|
+
if (!s) return "unknown session";
|
|
51806
|
+
if (!backlogRunArgs(s)) return "only backlog run sessions can be transferred";
|
|
51807
|
+
if (s.transfer?.queued)
|
|
51808
|
+
return `a transfer to ${s.transfer.target} is already pending`;
|
|
51809
|
+
if (s.transfer && !s.transfer.error)
|
|
51810
|
+
return `already transferring to ${s.transfer.target}`;
|
|
51811
|
+
if (!target || target === links2.localNode())
|
|
51812
|
+
return `the session already runs on ${links2.localNode()}`;
|
|
51813
|
+
if (!links2.isConnected(target)) return `${target} is not connected`;
|
|
51814
|
+
return void 0;
|
|
51815
|
+
}
|
|
51816
|
+
|
|
51817
|
+
// src/commands/sessions/daemon/transfer/pushTransferSnapshot.ts
|
|
51818
|
+
import { basename as basename32 } from "path";
|
|
51819
|
+
|
|
51820
|
+
// src/commands/sessions/daemon/transfer/TransferSnapshot.ts
|
|
51821
|
+
function transferRefFor(itemId2) {
|
|
51822
|
+
return `assist/transfer/${itemId2}`;
|
|
51823
|
+
}
|
|
51824
|
+
function parseTransferSnapshot(value) {
|
|
51825
|
+
if (!value || typeof value !== "object") return void 0;
|
|
51826
|
+
const { ref, branch: branch2, upstream } = value;
|
|
51827
|
+
if (typeof ref !== "string" || !ref.startsWith("assist/transfer/"))
|
|
51828
|
+
return void 0;
|
|
51829
|
+
return {
|
|
51830
|
+
ref,
|
|
51831
|
+
branch: typeof branch2 === "string" ? branch2 : void 0,
|
|
51832
|
+
upstream: typeof upstream === "string" ? upstream : void 0
|
|
51833
|
+
};
|
|
51834
|
+
}
|
|
51835
|
+
|
|
51836
|
+
// src/commands/sessions/daemon/transfer/pushTransferSnapshot.ts
|
|
51837
|
+
var PUSH_TIMEOUT_MS = 12e4;
|
|
51838
|
+
var WIP_COMMIT = [
|
|
51839
|
+
"-c",
|
|
51840
|
+
"user.name=assist",
|
|
51841
|
+
"-c",
|
|
51842
|
+
"user.email=assist@localhost",
|
|
51843
|
+
"-c",
|
|
51844
|
+
"commit.gpgsign=false",
|
|
51845
|
+
"commit",
|
|
51846
|
+
"--no-verify",
|
|
51847
|
+
"--allow-empty",
|
|
51848
|
+
"--quiet",
|
|
51849
|
+
"-m",
|
|
51850
|
+
"assist transfer WIP"
|
|
51851
|
+
];
|
|
51852
|
+
async function currentBranch6(path109, treeRoot) {
|
|
51853
|
+
const branch2 = await gitOrNull(path109, ["symbolic-ref", "--short", "HEAD"]);
|
|
51854
|
+
if (!branch2 || treeRoot && branch2 === basename32(treeRoot)) return void 0;
|
|
51855
|
+
return branch2;
|
|
51856
|
+
}
|
|
51857
|
+
async function upstreamBranch2(path109) {
|
|
51858
|
+
const upstream = await gitOrNull(path109, [
|
|
51859
|
+
"rev-parse",
|
|
51860
|
+
"--abbrev-ref",
|
|
51861
|
+
"--symbolic-full-name",
|
|
51862
|
+
"@{u}"
|
|
51863
|
+
]);
|
|
51864
|
+
if (!upstream?.startsWith("origin/")) return void 0;
|
|
51865
|
+
return upstream.slice("origin/".length);
|
|
51866
|
+
}
|
|
51867
|
+
async function pushTransferSnapshot(path109, itemId2, treeRoot) {
|
|
51868
|
+
const ref = transferRefFor(itemId2);
|
|
51869
|
+
const branch2 = await currentBranch6(path109, treeRoot);
|
|
51870
|
+
const upstream = await upstreamBranch2(path109);
|
|
51871
|
+
const head = (await git2(path109, ["rev-parse", "HEAD"])).trim();
|
|
51872
|
+
await git2(path109, ["add", "-A"]);
|
|
51873
|
+
try {
|
|
51874
|
+
await git2(path109, WIP_COMMIT);
|
|
51875
|
+
await git2(
|
|
51876
|
+
path109,
|
|
51877
|
+
["push", "--no-verify", "--force", "origin", `HEAD:refs/heads/${ref}`],
|
|
51878
|
+
PUSH_TIMEOUT_MS
|
|
51879
|
+
);
|
|
51880
|
+
} finally {
|
|
51881
|
+
await git2(path109, ["reset", "--mixed", "--quiet", head]);
|
|
51882
|
+
}
|
|
51883
|
+
return { ref, branch: branch2, upstream };
|
|
51884
|
+
}
|
|
51885
|
+
|
|
51886
|
+
// src/commands/sessions/daemon/transfer/snapshotTree.ts
|
|
51887
|
+
async function snapshotTree(s, args, traceId) {
|
|
51888
|
+
const path109 = s.worktree?.path ?? s.cwd;
|
|
51889
|
+
if (!path109) return void 0;
|
|
51890
|
+
const snapshot = await pushTransferSnapshot(path109, args[2], s.worktree?.path);
|
|
51891
|
+
daemonLog(
|
|
51892
|
+
`session ${s.id} pushed ${path109} to ${snapshot.ref} (branch=${snapshot.branch ?? "tree"} upstream=${snapshot.upstream ?? "none"}) trace=${traceId}`
|
|
51893
|
+
);
|
|
51894
|
+
return snapshot;
|
|
51895
|
+
}
|
|
51896
|
+
|
|
51897
|
+
// src/commands/sessions/daemon/transfer/snapshotOrFail.ts
|
|
51898
|
+
async function snapshotOrFail(s, args, traceId) {
|
|
51899
|
+
try {
|
|
51900
|
+
return { ok: true, snapshot: await snapshotTree(s, args, traceId) };
|
|
51901
|
+
} catch (error) {
|
|
51902
|
+
const reason4 = error instanceof Error ? error.message : String(error);
|
|
51903
|
+
return { ok: false, error: `push failed: ${reason4}` };
|
|
51904
|
+
}
|
|
51905
|
+
}
|
|
51906
|
+
|
|
51907
|
+
// src/commands/sessions/daemon/transfer/transferSession.ts
|
|
51908
|
+
function refuse(client, id, message3) {
|
|
51909
|
+
daemonLog(`session ${id} transfer refused: ${message3}`);
|
|
51910
|
+
sendTo(client, { type: "error", message: `Transfer refused: ${message3}` });
|
|
51911
|
+
}
|
|
51912
|
+
async function transferSession(client, deps2, { sessionId: id, target, cwd }) {
|
|
51913
|
+
const s = deps2.session(id);
|
|
51914
|
+
const refused = transferRefusal(s, target, deps2.links);
|
|
51915
|
+
const args = s && backlogRunArgs(s);
|
|
51916
|
+
if (refused || !s || !args)
|
|
51917
|
+
return refuse(client, id, refused ?? "unknown session");
|
|
51918
|
+
if (s.status === "running")
|
|
51919
|
+
return queueTransfer(client, deps2.notify, s, target, cwd);
|
|
51920
|
+
const traceId = newTraceId();
|
|
51921
|
+
daemonLog(
|
|
51922
|
+
`session ${id} transfer to ${target} (cwd=${cwd ?? "default"}) trace=${traceId}: snapshotting tree`
|
|
51923
|
+
);
|
|
51924
|
+
s.transfer = { target };
|
|
51925
|
+
deps2.notify();
|
|
51926
|
+
const pushed = await snapshotOrFail(s, args, traceId);
|
|
51927
|
+
if (!pushed.ok) {
|
|
51928
|
+
s.transfer = { target, error: pushed.error };
|
|
51929
|
+
deps2.notify();
|
|
51930
|
+
return refuse(client, id, pushed.error);
|
|
51931
|
+
}
|
|
51932
|
+
await handOffToTarget(client, deps2, s, {
|
|
51933
|
+
args,
|
|
51934
|
+
target,
|
|
51935
|
+
cwd,
|
|
51936
|
+
traceId,
|
|
51937
|
+
snapshot: pushed.snapshot
|
|
51938
|
+
});
|
|
51939
|
+
}
|
|
51940
|
+
|
|
51941
|
+
// src/commands/sessions/daemon/transfer/runQueuedTransfer.ts
|
|
51942
|
+
function runQueuedTransfer(client, deps2, s) {
|
|
51943
|
+
const queued = s.transfer?.queued;
|
|
51944
|
+
if (!s.transfer || !queued || s.status === "running") return void 0;
|
|
51945
|
+
const { target } = s.transfer;
|
|
51946
|
+
daemonLog(
|
|
51947
|
+
`session ${s.id} went ${s.status}; running queued transfer to ${target}`
|
|
51948
|
+
);
|
|
51949
|
+
s.transfer = void 0;
|
|
51950
|
+
return transferSession(client, deps2, {
|
|
51951
|
+
sessionId: s.id,
|
|
51952
|
+
target,
|
|
51953
|
+
cwd: queued.cwd
|
|
51954
|
+
});
|
|
51955
|
+
}
|
|
51956
|
+
|
|
51957
|
+
// src/commands/sessions/daemon/transfer/transferDepsFor.ts
|
|
51958
|
+
function transferDepsFor(m) {
|
|
51959
|
+
return {
|
|
51960
|
+
session: m.session,
|
|
51961
|
+
links: m.links,
|
|
51962
|
+
stop: (id) => m.stopSession(id),
|
|
51963
|
+
discard: m.discardSession,
|
|
51964
|
+
notify: () => m.update(() => true)
|
|
51965
|
+
};
|
|
51966
|
+
}
|
|
51967
|
+
|
|
51968
|
+
// src/commands/sessions/daemon/transfer/queuedTransferTrigger.ts
|
|
51969
|
+
function queuedTransferTrigger(host) {
|
|
51970
|
+
const viewers = {
|
|
51971
|
+
send: (raw) => {
|
|
51972
|
+
for (const viewer of host.clients.viewers()) viewer.send(raw);
|
|
51973
|
+
}
|
|
51974
|
+
};
|
|
51975
|
+
return (s) => void runQueuedTransfer(viewers, transferDepsFor(host), s);
|
|
51976
|
+
}
|
|
51977
|
+
|
|
51978
|
+
// src/commands/sessions/daemon/makeManagerStatusHandler.ts
|
|
51979
|
+
function makeManagerStatusHandler(sessions, host) {
|
|
51980
|
+
return makeStatusChangeHandler(sessions, {
|
|
51981
|
+
dismiss: (id) => host.dismissSession(id),
|
|
51982
|
+
notify: () => host.update(() => true),
|
|
51983
|
+
idle: queuedTransferTrigger(host)
|
|
51984
|
+
});
|
|
51985
|
+
}
|
|
51986
|
+
|
|
51724
51987
|
// src/commands/sessions/daemon/applySetStatus.ts
|
|
51725
51988
|
function opensPrompt(status2, source) {
|
|
51726
51989
|
const askUserQuestion = source === "pretool" && status2 === "waiting";
|
|
@@ -52804,7 +53067,7 @@ function rearmStoppedSessions(sessions, notify2) {
|
|
|
52804
53067
|
|
|
52805
53068
|
// src/commands/sessions/daemon/worktree/reconcileWorktreesOnRestore.ts
|
|
52806
53069
|
import { existsSync as existsSync100 } from "fs";
|
|
52807
|
-
import { basename as
|
|
53070
|
+
import { basename as basename34 } from "path";
|
|
52808
53071
|
|
|
52809
53072
|
// src/commands/sessions/daemon/worktree/accountedTrees.ts
|
|
52810
53073
|
function accountedTrees(sessions) {
|
|
@@ -52912,7 +53175,7 @@ function capped2(lines2) {
|
|
|
52912
53175
|
}
|
|
52913
53176
|
|
|
52914
53177
|
// src/commands/sessions/daemon/worktree/resurfaceOrphanedWorktree.ts
|
|
52915
|
-
import { basename as
|
|
53178
|
+
import { basename as basename33 } from "path";
|
|
52916
53179
|
function resurfaceOrphanedWorktree(sessions, spawnWith, recovered, notify2) {
|
|
52917
53180
|
const { orphan, reason: reason4, held } = recovered;
|
|
52918
53181
|
let id;
|
|
@@ -52935,7 +53198,7 @@ function orphanedSession(id, recovered) {
|
|
|
52935
53198
|
const { orphan, reason: reason4, held } = recovered;
|
|
52936
53199
|
return {
|
|
52937
53200
|
...sessionBase(id, "stopped"),
|
|
52938
|
-
name: `recovered ${
|
|
53201
|
+
name: `recovered ${basename33(orphan.path)}`,
|
|
52939
53202
|
subtitle: `${held.summary} in ${orphan.path}`,
|
|
52940
53203
|
commandType: "claude",
|
|
52941
53204
|
pty: null,
|
|
@@ -52996,7 +53259,7 @@ async function recoverOrphanedWorktrees(sessions, spawnWith, notify2) {
|
|
|
52996
53259
|
logVanishedTree(sessions, path109);
|
|
52997
53260
|
vanished.set(clone, [
|
|
52998
53261
|
...vanished.get(clone) ?? [],
|
|
52999
|
-
{ path: path109, branch:
|
|
53262
|
+
{ path: path109, branch: basename34(path109) }
|
|
53000
53263
|
]);
|
|
53001
53264
|
continue;
|
|
53002
53265
|
}
|
|
@@ -53559,19 +53822,27 @@ function toPeerMessage(data) {
|
|
|
53559
53822
|
}
|
|
53560
53823
|
|
|
53561
53824
|
// src/commands/sessions/daemon/links/forwardLinkCreate.ts
|
|
53825
|
+
var TRANSFER_CREATE_TIMEOUT_MS = 3e5;
|
|
53826
|
+
function createTimeoutMs(ctx, data) {
|
|
53827
|
+
const base = ctx.deps.createTimeoutMs;
|
|
53828
|
+
return data.transfer ? Math.max(base, TRANSFER_CREATE_TIMEOUT_MS) : base;
|
|
53829
|
+
}
|
|
53562
53830
|
function armCreateTimeout(ctx, client, data) {
|
|
53563
53831
|
const node = ctx.spec.name;
|
|
53564
|
-
const timer = setTimeout(
|
|
53565
|
-
|
|
53566
|
-
|
|
53567
|
-
|
|
53568
|
-
|
|
53569
|
-
|
|
53570
|
-
|
|
53571
|
-
|
|
53572
|
-
|
|
53573
|
-
|
|
53574
|
-
|
|
53832
|
+
const timer = setTimeout(
|
|
53833
|
+
() => {
|
|
53834
|
+
const pending = ctx.relay.pendingCreators;
|
|
53835
|
+
const index2 = pending.findIndex((p) => p.timer === timer);
|
|
53836
|
+
if (index2 === -1) return;
|
|
53837
|
+
pending.splice(index2, 1);
|
|
53838
|
+
daemonLog(`link ${node} ws: ${data.type} timed out (cwd=${data.cwd})`);
|
|
53839
|
+
sendTo(client, {
|
|
53840
|
+
type: "error",
|
|
53841
|
+
message: `Session on ${node} did not start: the peer did not respond.`
|
|
53842
|
+
});
|
|
53843
|
+
},
|
|
53844
|
+
createTimeoutMs(ctx, data)
|
|
53845
|
+
);
|
|
53575
53846
|
timer.unref?.();
|
|
53576
53847
|
ctx.relay.pendingCreators.push({ client, timer });
|
|
53577
53848
|
}
|
|
@@ -54345,10 +54616,10 @@ var SessionManager = class {
|
|
|
54345
54616
|
resume(sessionId, cwd, name, harness) {
|
|
54346
54617
|
return resumeInTree(this.treeCtx(), sessionId, cwd, name, harness);
|
|
54347
54618
|
}
|
|
54348
|
-
onStatusChange =
|
|
54349
|
-
|
|
54350
|
-
|
|
54351
|
-
|
|
54619
|
+
onStatusChange = makeManagerStatusHandler(
|
|
54620
|
+
this.sessions,
|
|
54621
|
+
this
|
|
54622
|
+
);
|
|
54352
54623
|
io = new SessionIo(
|
|
54353
54624
|
this.sessions,
|
|
54354
54625
|
() => this.onStatusChange,
|
|
@@ -55370,6 +55641,107 @@ var sessionSettingHandlers = {
|
|
|
55370
55641
|
)
|
|
55371
55642
|
};
|
|
55372
55643
|
|
|
55644
|
+
// src/commands/sessions/daemon/worktree/allocatePreparedAndBind.ts
|
|
55645
|
+
function allocatePreparedAndBind(ctx, cwd, create, prepare, options2 = {}, context) {
|
|
55646
|
+
const alloc = allocateTree(cwd, boundTreeRoots(ctx.sessions), options2);
|
|
55647
|
+
const prepared = (alloc.ready ?? Promise.resolve()).then(
|
|
55648
|
+
() => prepare(alloc.cwd)
|
|
55649
|
+
);
|
|
55650
|
+
prepared.catch(() => {
|
|
55651
|
+
});
|
|
55652
|
+
const id = ctx.spawnWith((sid) => create(sid, alloc.cwd), context);
|
|
55653
|
+
const session = ctx.sessions.get(id);
|
|
55654
|
+
bindNewWorktree(
|
|
55655
|
+
session,
|
|
55656
|
+
{ ...alloc, ready: prepared },
|
|
55657
|
+
ctx.notify,
|
|
55658
|
+
ctx.startHeld
|
|
55659
|
+
);
|
|
55660
|
+
if (session && !alloc.created)
|
|
55661
|
+
prepared.then(
|
|
55662
|
+
() => ctx.startHeld(session),
|
|
55663
|
+
() => {
|
|
55664
|
+
}
|
|
55665
|
+
);
|
|
55666
|
+
return { id, prepared };
|
|
55667
|
+
}
|
|
55668
|
+
|
|
55669
|
+
// src/commands/sessions/daemon/transfer/restoreTransferSnapshot.ts
|
|
55670
|
+
var FETCH_TIMEOUT_MS2 = 12e4;
|
|
55671
|
+
async function switchToSnapshot(path109, snapshot, sha) {
|
|
55672
|
+
const { branch: branch2 } = snapshot;
|
|
55673
|
+
if (!branch2 || branch2 === await remoteDefaultBranch(path109)) {
|
|
55674
|
+
await git2(path109, ["reset", "--hard", "--quiet", sha]);
|
|
55675
|
+
return await gitOrNull(path109, ["symbolic-ref", "--short", "HEAD"]) ?? sha;
|
|
55676
|
+
}
|
|
55677
|
+
await git2(path109, ["checkout", "--quiet", "-B", branch2, sha]);
|
|
55678
|
+
return branch2;
|
|
55679
|
+
}
|
|
55680
|
+
async function trackUpstream(path109, upstream) {
|
|
55681
|
+
await gitResult(path109, ["fetch", "--quiet", "origin", upstream]);
|
|
55682
|
+
const tracked = await gitResult(path109, [
|
|
55683
|
+
"branch",
|
|
55684
|
+
`--set-upstream-to=origin/${upstream}`
|
|
55685
|
+
]);
|
|
55686
|
+
if (!tracked.ok)
|
|
55687
|
+
daemonLog(
|
|
55688
|
+
`transfer restore ${path109}: could not track origin/${upstream}: ${tracked.error}`
|
|
55689
|
+
);
|
|
55690
|
+
}
|
|
55691
|
+
async function restoreTransferSnapshot(path109, snapshot) {
|
|
55692
|
+
if (await gitOrNull(path109, ["status", "--porcelain"]))
|
|
55693
|
+
throw new Error(`${path109} has uncommitted changes`);
|
|
55694
|
+
await git2(
|
|
55695
|
+
path109,
|
|
55696
|
+
["fetch", "--quiet", "origin", `refs/heads/${snapshot.ref}`],
|
|
55697
|
+
FETCH_TIMEOUT_MS2
|
|
55698
|
+
);
|
|
55699
|
+
const sha = (await git2(path109, ["rev-parse", "FETCH_HEAD"])).trim();
|
|
55700
|
+
const branch2 = await switchToSnapshot(path109, snapshot, sha);
|
|
55701
|
+
await git2(path109, ["reset", "--soft", "--quiet", "HEAD~1"]);
|
|
55702
|
+
if (snapshot.upstream) await trackUpstream(path109, snapshot.upstream);
|
|
55703
|
+
daemonLog(
|
|
55704
|
+
`transfer restore ${path109}: ${snapshot.ref} restored onto ${branch2}${snapshot.upstream ? ` tracking origin/${snapshot.upstream}` : ""}`
|
|
55705
|
+
);
|
|
55706
|
+
const deleted = await gitResult(
|
|
55707
|
+
path109,
|
|
55708
|
+
["push", "--no-verify", "--quiet", "origin", "--delete", snapshot.ref],
|
|
55709
|
+
FETCH_TIMEOUT_MS2
|
|
55710
|
+
);
|
|
55711
|
+
daemonLog(
|
|
55712
|
+
deleted.ok ? `transfer restore ${path109}: deleted ${snapshot.ref} from origin` : `transfer restore ${path109}: could not delete ${snapshot.ref} from origin: ${deleted.error}`
|
|
55713
|
+
);
|
|
55714
|
+
}
|
|
55715
|
+
|
|
55716
|
+
// src/commands/sessions/daemon/transfer/spawnTransferredRun.ts
|
|
55717
|
+
async function spawnTransferredRun(ctx, discard, { assistArgs, cwd, meta, snapshot, traceId }, context) {
|
|
55718
|
+
const trace = `trace=${traceId ?? "none"}`;
|
|
55719
|
+
const { id, prepared } = allocatePreparedAndBind(
|
|
55720
|
+
ctx,
|
|
55721
|
+
cwd,
|
|
55722
|
+
(sid, resolvedCwd) => createAssistSession(sid, assistArgs, resolvedCwd, meta, true),
|
|
55723
|
+
async (path109) => {
|
|
55724
|
+
if (!path109) throw new Error("no working tree to restore into");
|
|
55725
|
+
daemonLog(`transfer restore ${path109}: fetching ${snapshot.ref} ${trace}`);
|
|
55726
|
+
await restoreTransferSnapshot(path109, snapshot);
|
|
55727
|
+
},
|
|
55728
|
+
{ inPlace: meta.inPlace },
|
|
55729
|
+
context
|
|
55730
|
+
);
|
|
55731
|
+
try {
|
|
55732
|
+
await prepared;
|
|
55733
|
+
} catch (error) {
|
|
55734
|
+
const reason4 = error instanceof Error ? error.message : String(error);
|
|
55735
|
+
daemonLog(
|
|
55736
|
+
`session ${id} transfer restore failed ${trace}: ${reason4}; run not started, ${snapshot.ref} left on origin`
|
|
55737
|
+
);
|
|
55738
|
+
discard(id);
|
|
55739
|
+
throw new Error(`restore failed: ${reason4}`);
|
|
55740
|
+
}
|
|
55741
|
+
daemonLog(`session ${id} transfer restored ${trace}; starting run`);
|
|
55742
|
+
return id;
|
|
55743
|
+
}
|
|
55744
|
+
|
|
55373
55745
|
// src/commands/sessions/daemon/worktree/prCheckoutNumber.ts
|
|
55374
55746
|
var CHECKOUT_COMMANDS = /* @__PURE__ */ new Set([
|
|
55375
55747
|
"review",
|
|
@@ -55420,14 +55792,28 @@ function spawnAssistCreate(m, d) {
|
|
|
55420
55792
|
const assistArgs = d.assistArgs ?? [];
|
|
55421
55793
|
const cwd = d.cwd;
|
|
55422
55794
|
const inPlace = d.inPlace === true;
|
|
55795
|
+
const meta = {
|
|
55796
|
+
title: d.title,
|
|
55797
|
+
subtitle: d.subtitle
|
|
55798
|
+
};
|
|
55799
|
+
const snapshot = parseTransferSnapshot(d.transfer);
|
|
55800
|
+
if (snapshot)
|
|
55801
|
+
return spawnTransferredRun(
|
|
55802
|
+
m.treeCtx(),
|
|
55803
|
+
m.discardSession,
|
|
55804
|
+
{
|
|
55805
|
+
assistArgs,
|
|
55806
|
+
cwd,
|
|
55807
|
+
meta: { ...meta, inPlace },
|
|
55808
|
+
snapshot,
|
|
55809
|
+
traceId: d.traceId
|
|
55810
|
+
},
|
|
55811
|
+
spawnContextFrom(d)
|
|
55812
|
+
);
|
|
55423
55813
|
const spawn13 = (holder) => m.spawnAssist(
|
|
55424
55814
|
assistArgs,
|
|
55425
55815
|
holder ?? cwd,
|
|
55426
|
-
{
|
|
55427
|
-
title: d.title,
|
|
55428
|
-
subtitle: d.subtitle,
|
|
55429
|
-
inPlace: inPlace || holder !== void 0
|
|
55430
|
-
},
|
|
55816
|
+
{ ...meta, inPlace: inPlace || holder !== void 0 },
|
|
55431
55817
|
spawnContextFrom(d)
|
|
55432
55818
|
);
|
|
55433
55819
|
if (inPlace || !isPrCheckoutArgs(assistArgs)) return spawn13();
|
|
@@ -55463,122 +55849,30 @@ function spawnCreate(m, d) {
|
|
|
55463
55849
|
);
|
|
55464
55850
|
}
|
|
55465
55851
|
|
|
55466
|
-
// src/commands/sessions/
|
|
55467
|
-
function
|
|
55468
|
-
|
|
55469
|
-
|
|
55470
|
-
|
|
55471
|
-
return args;
|
|
55472
|
-
}
|
|
55473
|
-
|
|
55474
|
-
// src/commands/sessions/daemon/transfer/launchOnTarget.ts
|
|
55475
|
-
function launchOnTarget(route, request) {
|
|
55476
|
-
return new Promise((resolve32) => {
|
|
55477
|
-
const capture = {
|
|
55478
|
-
send: (raw) => {
|
|
55479
|
-
const msg = JSON.parse(raw);
|
|
55480
|
-
if (msg.type === "created")
|
|
55481
|
-
resolve32({ ok: true, sessionId: msg.sessionId });
|
|
55482
|
-
else if (msg.type === "error")
|
|
55483
|
-
resolve32({ ok: false, error: String(msg.message) });
|
|
55484
|
-
}
|
|
55485
|
-
};
|
|
55486
|
-
if (!route(capture, request))
|
|
55487
|
-
resolve32({ ok: false, error: `${request.node} is not a linked node` });
|
|
55488
|
-
});
|
|
55489
|
-
}
|
|
55490
|
-
|
|
55491
|
-
// src/commands/sessions/daemon/transfer/settleTransfer.ts
|
|
55492
|
-
function settleTransfer(client, deps2, s, outcome, traceId) {
|
|
55493
|
-
const target = s.transfer?.target ?? "target";
|
|
55494
|
-
if (!outcome.ok) {
|
|
55495
|
-
daemonLog(
|
|
55496
|
-
`session ${s.id} transfer to ${target} failed trace=${traceId}: ${outcome.error}; source kept`
|
|
55497
|
-
);
|
|
55498
|
-
s.transfer = { target, error: outcome.error };
|
|
55499
|
-
deps2.notify();
|
|
55500
|
-
sendTo(client, {
|
|
55501
|
-
type: "error",
|
|
55502
|
-
message: `Transfer to ${target} failed: ${outcome.error}`
|
|
55503
|
-
});
|
|
55504
|
-
return;
|
|
55852
|
+
// src/commands/sessions/daemon/transfer/cancelQueuedTransfer.ts
|
|
55853
|
+
function cancelQueuedTransfer(s, id) {
|
|
55854
|
+
if (!s?.transfer?.queued) {
|
|
55855
|
+
daemonLog(`session ${id} cancel-transfer ignored: no pending transfer`);
|
|
55856
|
+
return false;
|
|
55505
55857
|
}
|
|
55506
|
-
daemonLog(
|
|
55507
|
-
`session ${s.id} transferred to ${target} as ${outcome.sessionId} trace=${traceId}; closing source`
|
|
55508
|
-
);
|
|
55858
|
+
daemonLog(`session ${id} pending transfer to ${s.transfer.target} cancelled`);
|
|
55509
55859
|
s.transfer = void 0;
|
|
55510
|
-
|
|
55511
|
-
sendTo(client, { type: "notice", message: `Transferred to ${target}` });
|
|
55512
|
-
}
|
|
55513
|
-
|
|
55514
|
-
// src/commands/sessions/daemon/transfer/transferRefusal.ts
|
|
55515
|
-
function transferRefusal(s, target, links2) {
|
|
55516
|
-
if (!s) return "unknown session";
|
|
55517
|
-
if (!backlogRunArgs(s)) return "only backlog run sessions can be transferred";
|
|
55518
|
-
if (s.transfer && !s.transfer.error)
|
|
55519
|
-
return `already transferring to ${s.transfer.target}`;
|
|
55520
|
-
if (!target || target === links2.localNode())
|
|
55521
|
-
return `the session already runs on ${links2.localNode()}`;
|
|
55522
|
-
if (!links2.isConnected(target)) return `${target} is not connected`;
|
|
55523
|
-
return void 0;
|
|
55524
|
-
}
|
|
55525
|
-
async function heldWorkRefusal(s) {
|
|
55526
|
-
const path109 = s.worktree?.path ?? s.cwd;
|
|
55527
|
-
if (!path109) return void 0;
|
|
55528
|
-
const durability = await checkDurability(path109);
|
|
55529
|
-
if (durability.durable) return void 0;
|
|
55530
|
-
const held = await describeHeldWork(path109, durability.reason);
|
|
55531
|
-
return `${held.summary} in ${path109} \u2014 commit and push before transferring`;
|
|
55532
|
-
}
|
|
55533
|
-
|
|
55534
|
-
// src/commands/sessions/daemon/transfer/transferSession.ts
|
|
55535
|
-
function refuse(client, id, message3) {
|
|
55536
|
-
daemonLog(`session ${id} transfer refused: ${message3}`);
|
|
55537
|
-
sendTo(client, { type: "error", message: `Transfer refused: ${message3}` });
|
|
55538
|
-
}
|
|
55539
|
-
async function transferSession(client, deps2, { sessionId: id, target, cwd }) {
|
|
55540
|
-
const s = deps2.session(id);
|
|
55541
|
-
const refused = transferRefusal(s, target, deps2.links);
|
|
55542
|
-
if (refused || !s) return refuse(client, id, refused ?? "unknown session");
|
|
55543
|
-
const held = await heldWorkRefusal(s);
|
|
55544
|
-
if (held) return refuse(client, id, held);
|
|
55545
|
-
const traceId = newTraceId();
|
|
55546
|
-
daemonLog(
|
|
55547
|
-
`session ${id} transfer to ${target} (cwd=${cwd ?? "default"}) trace=${traceId}: stopping source`
|
|
55548
|
-
);
|
|
55549
|
-
s.transfer = { target };
|
|
55550
|
-
deps2.stop(id);
|
|
55551
|
-
deps2.notify();
|
|
55552
|
-
const outcome = await launchOnTarget(deps2.links.route, {
|
|
55553
|
-
type: "create-assist",
|
|
55554
|
-
assistArgs: backlogRunArgs(s),
|
|
55555
|
-
cwd,
|
|
55556
|
-
node: target,
|
|
55557
|
-
title: s.title,
|
|
55558
|
-
subtitle: s.subtitle,
|
|
55559
|
-
traceId
|
|
55560
|
-
});
|
|
55561
|
-
settleTransfer(client, deps2, s, outcome, traceId);
|
|
55860
|
+
return true;
|
|
55562
55861
|
}
|
|
55563
55862
|
|
|
55564
55863
|
// src/commands/sessions/daemon/transfer/handleTransfer.ts
|
|
55565
55864
|
var handleTransfer = routed((client, m, d) => {
|
|
55566
55865
|
daemonLog(`transfer received: id=${d.sessionId} target=${d.target}`);
|
|
55567
|
-
void transferSession(
|
|
55568
|
-
|
|
55569
|
-
|
|
55570
|
-
|
|
55571
|
-
|
|
55572
|
-
|
|
55573
|
-
|
|
55574
|
-
|
|
55575
|
-
|
|
55576
|
-
|
|
55577
|
-
sessionId: d.sessionId,
|
|
55578
|
-
target: d.target,
|
|
55579
|
-
cwd: d.cwd
|
|
55580
|
-
}
|
|
55581
|
-
);
|
|
55866
|
+
void transferSession(client, transferDepsFor(m), {
|
|
55867
|
+
sessionId: d.sessionId,
|
|
55868
|
+
target: d.target,
|
|
55869
|
+
cwd: d.cwd
|
|
55870
|
+
});
|
|
55871
|
+
});
|
|
55872
|
+
var handleCancelTransfer = routed((_client, m, d) => {
|
|
55873
|
+
const id = d.sessionId;
|
|
55874
|
+
daemonLog(`cancel-transfer received: id=${id}`);
|
|
55875
|
+
m.update(() => cancelQueuedTransfer(m.session(id), id));
|
|
55582
55876
|
});
|
|
55583
55877
|
|
|
55584
55878
|
// src/commands/sessions/daemon/messageHandlers.ts
|
|
@@ -55640,6 +55934,7 @@ var messageHandlers = {
|
|
|
55640
55934
|
discard: routed((_client, m, d) => m.discardSession(d.sessionId)),
|
|
55641
55935
|
stop: routed((_client, m, d) => m.stopSession(d.sessionId)),
|
|
55642
55936
|
transfer: handleTransfer,
|
|
55937
|
+
"cancel-transfer": handleCancelTransfer,
|
|
55643
55938
|
...sessionSettingHandlers,
|
|
55644
55939
|
"set-active": (_client, m, d) => m.active.set(d.cwd, d.sessionId),
|
|
55645
55940
|
"set-status": handleSetStatus,
|