claude-code-session-manager 0.130.1 → 0.130.3
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/.claude-plugin/marketplace.json +1 -1
- package/bin/cli.cjs +19 -2
- package/dist/assets/AgentLibrary-BmrXNwK8.js +2 -0
- package/dist/assets/{AppSettings-A3KoPcmL.js → AppSettings-Cs4POznd.js} +1 -1
- package/dist/assets/{Button-DvTXa_-4.js → Button-UUr5giu8.js} +1 -1
- package/dist/assets/DocumentEditorPane-C46Hj0lz.js +1 -0
- package/dist/assets/Extensions-B9QdiNOV.js +2 -0
- package/dist/assets/{History-DcnZxMoU.js → History-Bndupj87.js} +2 -2
- package/dist/assets/{Library-LftcMs6C.js → Library-DFn0YPIW.js} +5 -5
- package/dist/assets/{ListDetail-CnL1azR0.js → ListDetail-DjMn8a_3.js} +1 -1
- package/dist/assets/{Panel-CA6TdCHv.js → Panel-CIvb-XXN.js} +1 -1
- package/dist/assets/ProjectClaudeConfig-BQQRtMdK.js +25 -0
- package/dist/assets/{ProvenanceBadge-Y3DhyiJo.js → ProvenanceBadge-ej8W2ZIK.js} +1 -1
- package/dist/assets/{Scheduler-Ca1qo_kp.js → Scheduler-DSVBWqRK.js} +8 -8
- package/dist/assets/Settings-DqxUna06.js +2 -0
- package/dist/assets/{SkillReferenceGraph-2WMsKdmr.js → SkillReferenceGraph-BEMTdxdD.js} +1 -1
- package/dist/assets/Skills-DTXehVS7.js +12 -0
- package/dist/assets/{SourceChip-CeprSxwb.js → SourceChip-BrPci8FX.js} +1 -1
- package/dist/assets/SystemPrompt-B43hNP0X.js +1 -0
- package/dist/assets/{TiptapBody-BvxcQ_tS.js → TiptapBody-B-R2Bpda.js} +1 -1
- package/dist/assets/{Toggle-keTV_HDb.js → Toggle-DKb4x1BP.js} +1 -1
- package/dist/assets/ViewTabs-CcJdFZgv.js +1 -0
- package/dist/assets/{VoiceButton-5ETBv9eI.js → VoiceButton-BSH0UI3u.js} +1 -1
- package/dist/assets/{historyTotals-NAZqiuzd.js → historyTotals-5oUEu_fe.js} +1 -1
- package/dist/assets/index-C9w-dVzo.js +3090 -0
- package/dist/assets/{index-Bp8XE9A6.css → index-CMCcT2yg.css} +1 -1
- package/dist/index.html +2 -2
- package/dist-web/app.css +1 -1
- package/dist-web/app.js +420 -416
- package/package.json +1 -1
- package/plugins/session-manager-dev/.claude-plugin/plugin.json +1 -1
- package/plugins/session-manager-dev/skills/maintaining-md-network/drift-check.md +15 -5
- package/plugins/session-manager-dev/skills/maintaining-md-network/scripts/drift-check.cjs +8 -4
- package/src/main/agentLibrary.cjs +81 -29
- package/src/main/agentsIpc.cjs +21 -16
- package/src/main/build-info.json +4 -4
- package/src/main/ipcSchemas.cjs +7 -1
- package/src/main/lib/epic/epicWorktreeMerge.cjs +11 -9
- package/src/main/lib/feedback-remote/remoteIpcDispatch.cjs +2 -0
- package/src/main/lib/git/gitWorktree.cjs +216 -43
- package/src/main/lib/mdNetworkScan.cjs +555 -0
- package/src/main/lib/persona-macro/agentPersonaSchema.cjs +18 -5
- package/src/main/lib/persona-macro/builtinMacros.cjs +6 -4
- package/src/main/lib/persona-macro/macroJobDispatch.cjs +9 -2
- package/src/main/lib/scheduler/terminalRunOutcome.cjs +61 -15
- package/src/main/projectPages.cjs +32 -7
- package/src/main/scheduler/gitTreeGuard.cjs +85 -12
- package/src/main/scheduler.cjs +16 -5
- package/src/preload/api.d.ts +91 -6
- package/src/preload/apiSurface.json +7 -0
- package/src/preload/index.cjs +1 -0
- package/dist/assets/AgentLibrary-Dlhtc8Ty.js +0 -2
- package/dist/assets/Extensions-Ddb4sQpO.js +0 -13
- package/dist/assets/Memory-smN9-Yoo.js +0 -25
- package/dist/assets/Settings-BFwlV-as.js +0 -2
- package/dist/assets/SystemPrompt-B8TXIGXo.js +0 -1
- package/dist/assets/ViewTabs-fupn9keJ.js +0 -1
- package/dist/assets/index-QJxszEhM.js +0 -3086
|
@@ -1535,8 +1535,11 @@ async function integrateBranch({ cwd, branch, key, kind, carriedPaths, baseBranc
|
|
|
1535
1535
|
cwd, targetRef: `refs/heads/${expectedBranch}`, branch, message: mergeMessage,
|
|
1536
1536
|
});
|
|
1537
1537
|
if (refResult.ok) {
|
|
1538
|
-
// Spread refResult first so
|
|
1539
|
-
//
|
|
1538
|
+
// Spread refResult first so the landing's own shape passes through
|
|
1539
|
+
// untouched: a fast-forward keeps `fastForward: true`, the normal
|
|
1540
|
+
// diverged case keeps `linear: true` + `replayedCommits` (the branch
|
|
1541
|
+
// replayed onto the ref tip, no merge commit), and only the merge
|
|
1542
|
+
// fallback carries `mergeCommit: true` + `linearFallback`. This used to
|
|
1540
1543
|
// hard-code `fastForward: false` on every success, misreporting a
|
|
1541
1544
|
// plain fast-forward as a merge.
|
|
1542
1545
|
return { ...refResult, viaRef: true, sha: refResult.sha || refBranchHead };
|
|
@@ -1614,7 +1617,7 @@ async function integrateBranch({ cwd, branch, key, kind, carriedPaths, baseBranc
|
|
|
1614
1617
|
const headSha = await readHeadSha(cwd);
|
|
1615
1618
|
const r = await replayBranchOnto({ cwd, ontoSha: headSha, branch: branchHead });
|
|
1616
1619
|
if (!r.ok) {
|
|
1617
|
-
if (
|
|
1620
|
+
if (REPLAY_MERGE_FALLBACK_KINDS.has(r.failureKind)) {
|
|
1618
1621
|
linearFallback = r.failureKind;
|
|
1619
1622
|
break;
|
|
1620
1623
|
}
|
|
@@ -1944,19 +1947,97 @@ async function salvageDirtyDelta({ cwd, paths, outFile }) {
|
|
|
1944
1947
|
}
|
|
1945
1948
|
|
|
1946
1949
|
/**
|
|
1947
|
-
* True when
|
|
1948
|
-
*
|
|
1949
|
-
*
|
|
1950
|
-
*
|
|
1950
|
+
* True when `branch` holds no work that isn't already landed on `cwd`'s
|
|
1951
|
+
* current HEAD: its tip is an ancestor of (or equal to) HEAD, or, failing
|
|
1952
|
+
* that, `isBranchContentLanded({ cwd, base: 'HEAD', branch })` proves its
|
|
1953
|
+
* content is there. Linear landing (PRDs 2743, 2825) replays a branch, so a
|
|
1954
|
+
* landed branch's own commits never become ancestors of HEAD. Ancestry alone
|
|
1955
|
+
* made the stranded-branch sweep (branchSweep.cjs) re-integrate such a branch
|
|
1956
|
+
* once per process lifetime, and `reclaimTerminalJobOrphans` keep its checkout
|
|
1957
|
+
* (validator finding I-2). Used by both to tell a genuinely stranded
|
|
1958
|
+
* `sm-job/*` branch from one that's already a no-op.
|
|
1951
1959
|
* Never throws; a branch that doesn't exist, or any other git failure, is
|
|
1952
1960
|
* conservatively reported as NOT merged so a caller never treats an
|
|
1953
1961
|
* unreadable branch as safe to skip.
|
|
1954
1962
|
*/
|
|
1955
1963
|
async function isBranchMergedIntoHead(cwd, branch) {
|
|
1964
|
+
let branchHead;
|
|
1965
|
+
try {
|
|
1966
|
+
branchHead = (await execGit(['rev-parse', '--verify', branch], { cwd, timeout: 10_000 })).trim();
|
|
1967
|
+
} catch {
|
|
1968
|
+
return false;
|
|
1969
|
+
}
|
|
1956
1970
|
try {
|
|
1957
|
-
const branchHead = (await execGit(['rev-parse', '--verify', branch], { cwd, timeout: 10_000 })).trim();
|
|
1958
1971
|
const mergeBase = (await execGit(['merge-base', 'HEAD', branch], { cwd, timeout: 10_000 })).trim();
|
|
1959
|
-
|
|
1972
|
+
if (mergeBase !== '' && mergeBase === branchHead) return true;
|
|
1973
|
+
} catch {
|
|
1974
|
+
// No merge base, or git failed: ancestry proves nothing, so the content check decides.
|
|
1975
|
+
}
|
|
1976
|
+
return (await isBranchContentLanded({ cwd, base: 'HEAD', branch })) === true;
|
|
1977
|
+
}
|
|
1978
|
+
|
|
1979
|
+
/**
|
|
1980
|
+
* True when `branch`'s CONTENT is already in `base`, by any of three proofs,
|
|
1981
|
+
* cheapest first. Linear landing (PRDs 2743, 2825) replays a branch, so its
|
|
1982
|
+
* original commits never become ancestors of the base, and an ancestry-only
|
|
1983
|
+
* check reads a landed branch as unmerged (validator finding I-2).
|
|
1984
|
+
* 1. Ancestry: the branch tip is an ancestor of (or equal to) base.
|
|
1985
|
+
* 2. Patch-ids: `rev-list --right-only --cherry-pick --no-merges --count
|
|
1986
|
+
* <base>...<branch>` prints 0. Every non-merge branch commit has a
|
|
1987
|
+
* patch-equivalent commit on base, as a clean replay leaves. This proof
|
|
1988
|
+
* never sees a merge commit's own resolution.
|
|
1989
|
+
* 3. Merged tree: `merge-tree --write-tree <base> <branch>` exits 0 with
|
|
1990
|
+
* base's own tree. Merging the branch would change nothing. This catches
|
|
1991
|
+
* a replay whose diff context shifted, which changes the patch-id but
|
|
1992
|
+
* not the content.
|
|
1993
|
+
* Returns null when `branch` or `base` does not resolve to a commit. Returns
|
|
1994
|
+
* false otherwise, including a merge-tree conflict, a git too old for
|
|
1995
|
+
* `--write-tree` (< 2.38), or any other git failure, so an unreadable answer
|
|
1996
|
+
* never reads as landed. Never throws. Both names resolve to SHAs first and
|
|
1997
|
+
* only SHAs reach git. A name starting with '-' resolves only via
|
|
1998
|
+
* `refs/heads/`, as in replayBranchOnto.
|
|
1999
|
+
*
|
|
2000
|
+
* @param {{ cwd?: string, base?: string, branch?: string }} [opts]
|
|
2001
|
+
* @returns {Promise<boolean|null>}
|
|
2002
|
+
*/
|
|
2003
|
+
async function isBranchContentLanded({ cwd, base = 'HEAD', branch } = {}) {
|
|
2004
|
+
try {
|
|
2005
|
+
if (typeof cwd !== 'string' || !cwd) return null;
|
|
2006
|
+
const resolveName = async (name) => {
|
|
2007
|
+
if (typeof name !== 'string' || !name) return null;
|
|
2008
|
+
return (name.startsWith('-') ? null : await tryResolveCommit(cwd, `${name}^{commit}`))
|
|
2009
|
+
|| tryResolveCommit(cwd, `refs/heads/${name}^{commit}`);
|
|
2010
|
+
};
|
|
2011
|
+
const baseSha = await resolveName(base);
|
|
2012
|
+
const tipSha = await resolveName(branch);
|
|
2013
|
+
if (!baseSha || !tipSha) return null;
|
|
2014
|
+
|
|
2015
|
+
try {
|
|
2016
|
+
await execGit(['merge-base', '--is-ancestor', tipSha, baseSha], { cwd, timeout: 10_000 });
|
|
2017
|
+
return true;
|
|
2018
|
+
} catch {
|
|
2019
|
+
// Exit 1 = not an ancestor. On any other failure, try the content proofs.
|
|
2020
|
+
}
|
|
2021
|
+
|
|
2022
|
+
try {
|
|
2023
|
+
const out = await execGit(
|
|
2024
|
+
['rev-list', '--right-only', '--cherry-pick', '--no-merges', '--count', `${baseSha}...${tipSha}`],
|
|
2025
|
+
{ cwd, timeout: 30_000 },
|
|
2026
|
+
);
|
|
2027
|
+
if (Number.parseInt(out.trim(), 10) === 0) return true;
|
|
2028
|
+
} catch {
|
|
2029
|
+
// Fall through to the merged-tree proof.
|
|
2030
|
+
}
|
|
2031
|
+
|
|
2032
|
+
try {
|
|
2033
|
+
const out = await execGit(['merge-tree', '--write-tree', '--no-messages', baseSha, tipSha], { cwd, timeout: 30_000 });
|
|
2034
|
+
const mergedTree = (out.split('\n')[0] || '').trim();
|
|
2035
|
+
const baseTree = (await execGit(['rev-parse', '--verify', `${baseSha}^{tree}`], { cwd, timeout: 10_000 })).trim();
|
|
2036
|
+
return mergedTree !== '' && mergedTree === baseTree;
|
|
2037
|
+
} catch {
|
|
2038
|
+
// Exit 1 = conflict, 129 = git < 2.38. Neither proves the content landed.
|
|
2039
|
+
return false;
|
|
2040
|
+
}
|
|
1960
2041
|
} catch {
|
|
1961
2042
|
return false;
|
|
1962
2043
|
}
|
|
@@ -1988,10 +2069,12 @@ function keyFromBranch(kind, branch) {
|
|
|
1988
2069
|
*
|
|
1989
2070
|
* Never assumes it's safe to delete — proves it, two ways, for each
|
|
1990
2071
|
* candidate:
|
|
1991
|
-
* 1. `isBranchMergedIntoHead`: the branch holds
|
|
1992
|
-
*
|
|
1993
|
-
* so integrating it again could add
|
|
1994
|
-
* committed work
|
|
2072
|
+
* 1. `isBranchMergedIntoHead`: the branch holds no work that isn't already
|
|
2073
|
+
* on `cwd`'s HEAD (zero commits ahead of main, or its commits landed
|
|
2074
|
+
* there as a linear replay) — so integrating it again could add
|
|
2075
|
+
* nothing, and removing it loses no committed work
|
|
2076
|
+
* (`deleteBranchKeepingUniqueCommits` still pins a tip no other ref
|
|
2077
|
+
* holds).
|
|
1995
2078
|
* 2. Every path still dirty in the checkout itself (`git status
|
|
1996
2079
|
* --porcelain` run with cwd = the checkout dir) lives under
|
|
1997
2080
|
* `session-manager-operations/` — i.e. it's carried-over ops-folder
|
|
@@ -2221,18 +2304,34 @@ async function runMergeTreeWriteTree({ cwd, oldSha, branchSha }) {
|
|
|
2221
2304
|
|
|
2222
2305
|
const REPLAY_MAX_COMMITS = 200;
|
|
2223
2306
|
|
|
2307
|
+
/**
|
|
2308
|
+
* The `replayBranchOnto` failure kinds both landing paths answer with their
|
|
2309
|
+
* logged two-parent merge fallback (`linearFallback` = the kind); every other
|
|
2310
|
+
* replay failure lands nothing.
|
|
2311
|
+
*/
|
|
2312
|
+
const REPLAY_MERGE_FALLBACK_KINDS = new Set(['git_too_old', 'content_conflict', 'branch_has_merges']);
|
|
2313
|
+
|
|
2224
2314
|
/**
|
|
2225
2315
|
* Checkout-free linear replay: rebuilds `branch`'s non-merge commits on top of
|
|
2226
2316
|
* `ontoSha` purely in the object database (`git merge-tree --write-tree` +
|
|
2227
2317
|
* `git commit-tree`). Touches no checkout, index, HEAD or ref — the caller
|
|
2228
|
-
* decides what to do with the returned `tipSha`. It
|
|
2229
|
-
*
|
|
2230
|
-
*
|
|
2231
|
-
*
|
|
2318
|
+
* decides what to do with the returned `tipSha`. It is the linear step of both
|
|
2319
|
+
* landing paths — `integrateBranch` in the checkout and `attemptIntegrateOntoRef`
|
|
2320
|
+
* onto a bare ref: fast-forward first, then this replay, and a two-parent
|
|
2321
|
+
* "merge ..." commit only as their logged fallback (git too old, a replay
|
|
2322
|
+
* conflict, a branch merge the replay cannot reproduce, or
|
|
2323
|
+
* SM_LINEAR_LANDING_DISABLE=1). Landings stay linear because Bilko's
|
|
2324
|
+
* scripts/sync-local-main.sh refuses a local main carrying merge commits
|
|
2325
|
+
* origin lacks.
|
|
2232
2326
|
*
|
|
2233
2327
|
* Original author name/email/date and the full message are preserved; commits
|
|
2234
2328
|
* whose patch is already in `ontoSha`'s history (cherry-pick equivalence) or
|
|
2235
|
-
* that become empty are listed in `skipped`. Merge commits are never replayed
|
|
2329
|
+
* that become empty are listed in `skipped`. Merge commits are never replayed,
|
|
2330
|
+
* so a merge's resolution (e.g. a conflict resolved with `git merge` in an Epic
|
|
2331
|
+
* worktree) can hold content no replayed commit carries: when the replayed
|
|
2332
|
+
* range holds a merge commit, the replayed tip's tree must equal the tree
|
|
2333
|
+
* `git merge-tree --write-tree <onto> <branch>` writes (real merge base), or
|
|
2334
|
+
* it fails `branch_has_merges` rather than drop that content.
|
|
2236
2335
|
* Needs git >= 2.40 (`merge-tree --merge-base`). Never throws.
|
|
2237
2336
|
*
|
|
2238
2337
|
* @returns {Promise<{ok:true, tipSha:string, replayed:{from:string,to:string}[], skipped:string[], fastForward?:true}
|
|
@@ -2355,6 +2454,34 @@ async function replayBranchOnto({ cwd, ontoSha, branch }) {
|
|
|
2355
2454
|
replayed.push({ from: c, to: newSha });
|
|
2356
2455
|
tip = newSha;
|
|
2357
2456
|
}
|
|
2457
|
+
|
|
2458
|
+
// Validator finding I-1: a merge commit's resolution never reaches the
|
|
2459
|
+
// replay above, so prove the replay reproduced the branch's content — the
|
|
2460
|
+
// tree a real merge of the two tips writes — before calling it linear.
|
|
2461
|
+
const mergeCount = Number.parseInt((await execGit(
|
|
2462
|
+
['rev-list', '--count', '--merges', `${onto}..${tipIn}`],
|
|
2463
|
+
{ cwd, timeout: 30_000 },
|
|
2464
|
+
)).trim(), 10);
|
|
2465
|
+
if (mergeCount > 0) {
|
|
2466
|
+
let mergedTree = '';
|
|
2467
|
+
try {
|
|
2468
|
+
const out = await execGit(['merge-tree', '--write-tree', '--no-messages', onto, tipIn], { cwd, timeout: 30_000 });
|
|
2469
|
+
mergedTree = (out.split('\n')[0] || '').trim();
|
|
2470
|
+
} catch {
|
|
2471
|
+
// Any non-zero exit, a conflict included, leaves no tree to prove the replay against.
|
|
2472
|
+
}
|
|
2473
|
+
const replayedTree = (await execGit(['rev-parse', `${tip}^{tree}`], { cwd, timeout: 10_000 })).trim();
|
|
2474
|
+
if (!mergedTree || mergedTree !== replayedTree) {
|
|
2475
|
+
const merges = `${mergeCount} merge commit${mergeCount === 1 ? '' : 's'}`;
|
|
2476
|
+
return {
|
|
2477
|
+
ok: false,
|
|
2478
|
+
failureKind: 'branch_has_merges',
|
|
2479
|
+
reason: mergedTree
|
|
2480
|
+
? `branch holds ${merges} whose content a linear replay does not reproduce (replayed tree ${replayedTree}, merged tree ${mergedTree})`
|
|
2481
|
+
: `branch holds ${merges} and git merge-tree of ${onto} and ${tipIn} wrote no clean tree to check the replay against`,
|
|
2482
|
+
};
|
|
2483
|
+
}
|
|
2484
|
+
}
|
|
2358
2485
|
const result = { ok: true, tipSha: tip, replayed, skipped };
|
|
2359
2486
|
if (autoResolved) { result.autoResolved = autoResolved; result.resolvedPaths = Array.from(resolvedSet).sort(); }
|
|
2360
2487
|
return result;
|
|
@@ -2364,13 +2491,24 @@ async function replayBranchOnto({ cwd, ontoSha, branch }) {
|
|
|
2364
2491
|
}
|
|
2365
2492
|
|
|
2366
2493
|
/**
|
|
2367
|
-
* One computation attempt for `integrateOntoRef` — resolves both tips fresh
|
|
2368
|
-
* decides
|
|
2494
|
+
* One computation attempt for `integrateOntoRef` — resolves both tips fresh
|
|
2495
|
+
* and decides, in order: no-op (`integrated: false`); fast-forward when
|
|
2496
|
+
* `targetRef` is an ancestor of `branch` (`fastForward: true`); otherwise a
|
|
2497
|
+
* linear replay of the branch's commits onto the ref tip via
|
|
2498
|
+
* `replayBranchOnto` (`linear: true`, `replayedCommits`). Only when
|
|
2499
|
+
* SM_LINEAR_LANDING_DISABLE=1 or the replay fails with one of
|
|
2500
|
+
* `REPLAY_MERGE_FALLBACK_KINDS` (`git_too_old` / `content_conflict` /
|
|
2501
|
+
* `branch_has_merges`) does it console.warn and fall back to a two-parent
|
|
2502
|
+
* merge commit (`git merge-tree --write-tree` + `git commit-tree`, parents
|
|
2503
|
+
* [ref tip, branch tip]) reported as `mergeCommit: true` with
|
|
2504
|
+
* `linearFallback` naming why; any other replay failure is
|
|
2505
|
+
* `failureKind: 'other'` with the ref untouched. Every outcome lands via a
|
|
2369
2506
|
* compare-and-swap `git update-ref`. Returns `{ retry: true }` (never `ok`)
|
|
2370
2507
|
* when the CAS lost a race against a concurrent ref update — the caller
|
|
2371
2508
|
* recomputes from scratch, since a stale `oldSha` invalidates everything
|
|
2372
|
-
* derived from it (the ff
|
|
2373
|
-
* inputs). Every other return is terminal: a real
|
|
2509
|
+
* derived from it (the ff/replay/merge decision, the replayed commits, the
|
|
2510
|
+
* merge-tree/commit-tree inputs). Every other return is terminal: a real
|
|
2511
|
+
* `{ ok: true/false, ... }`.
|
|
2374
2512
|
*/
|
|
2375
2513
|
async function attemptIntegrateOntoRef({ cwd, targetRef, branch, message }) {
|
|
2376
2514
|
const branchSha = await tryResolveCommit(cwd, `${branch}^{commit}`);
|
|
@@ -2436,6 +2574,32 @@ async function attemptIntegrateOntoRef({ cwd, targetRef, branch, message }) {
|
|
|
2436
2574
|
return { ok: true, integrated: true, fastForward: true, sha: branchSha };
|
|
2437
2575
|
}
|
|
2438
2576
|
|
|
2577
|
+
// Diverged: replay the branch's commits onto the ref tip and land the
|
|
2578
|
+
// replayed tip through the same CAS — the in-checkout path's linear landing
|
|
2579
|
+
// (PRD 2743), done checkout-free. `branchSha`, never the name, reaches the
|
|
2580
|
+
// replay so it rebuilds exactly the commits resolved above. A two-parent
|
|
2581
|
+
// merge is only the logged fallback for what a replay cannot do.
|
|
2582
|
+
let linearFallback = '';
|
|
2583
|
+
if (process.env.SM_LINEAR_LANDING_DISABLE === '1') {
|
|
2584
|
+
linearFallback = 'disabled';
|
|
2585
|
+
} else {
|
|
2586
|
+
const r = await replayBranchOnto({ cwd, ontoSha: oldSha, branch: branchSha });
|
|
2587
|
+
if (r.ok) {
|
|
2588
|
+
const outcome = await updateRefOrClassify([targetRef, r.tipSha, oldSha]);
|
|
2589
|
+
if (outcome.retry) return { retry: true };
|
|
2590
|
+
if (!outcome.ok) return outcome;
|
|
2591
|
+
return {
|
|
2592
|
+
ok: true, integrated: true, linear: true, sha: r.tipSha, replayedCommits: r.replayed.length,
|
|
2593
|
+
...(r.autoResolved ? { autoResolved: r.autoResolved, resolvedPaths: r.resolvedPaths } : {}),
|
|
2594
|
+
};
|
|
2595
|
+
}
|
|
2596
|
+
if (!REPLAY_MERGE_FALLBACK_KINDS.has(r.failureKind)) {
|
|
2597
|
+
return { ok: false, failureKind: 'other', reason: r.reason };
|
|
2598
|
+
}
|
|
2599
|
+
linearFallback = r.failureKind;
|
|
2600
|
+
}
|
|
2601
|
+
console.warn(`[gitWorktree] linear landing of ${branch} onto ${targetRef} fell back to a merge commit (${linearFallback})`);
|
|
2602
|
+
|
|
2439
2603
|
const mergeTreeResult = await runMergeTreeWriteTree({ cwd, oldSha, branchSha });
|
|
2440
2604
|
if (!mergeTreeResult.ok) return mergeTreeResult;
|
|
2441
2605
|
|
|
@@ -2461,29 +2625,9 @@ async function attemptIntegrateOntoRef({ cwd, targetRef, branch, message }) {
|
|
|
2461
2625
|
const outcome = await updateRefOrClassify([targetRef, newSha, oldSha]);
|
|
2462
2626
|
if (outcome.retry) return { retry: true };
|
|
2463
2627
|
if (!outcome.ok) return outcome;
|
|
2464
|
-
return { ok: true, integrated: true, mergeCommit: true, sha: newSha };
|
|
2628
|
+
return { ok: true, integrated: true, mergeCommit: true, sha: newSha, linearFallback };
|
|
2465
2629
|
}
|
|
2466
2630
|
|
|
2467
|
-
/**
|
|
2468
|
-
* Lands `branch` onto `targetRef` WITHOUT touching any working tree, index,
|
|
2469
|
-
* or HEAD — no `git checkout`, no `git merge`, nothing in any human's or
|
|
2470
|
-
* job's own checkout ever moves. Fast-forwards via a compare-and-swap `git
|
|
2471
|
-
* update-ref` when `targetRef` is an ancestor of `branch`; otherwise builds a
|
|
2472
|
-
* merge commit entirely in the object database (`git merge-tree --write-tree`
|
|
2473
|
-
* + `git commit-tree`) and lands IT via the same CAS. This is the foundation
|
|
2474
|
-
* for a per-Epic `sm-land/<epicId>` integration branch that scheduler jobs
|
|
2475
|
-
* can land onto regardless of what the human's own checkout is doing.
|
|
2476
|
-
*
|
|
2477
|
-
* Refuses up front (`failureKind: 'target_checked_out'`, nothing touched) if
|
|
2478
|
-
* `targetRef` is checked out in ANY worktree of this repo — updating a
|
|
2479
|
-
* checked-out branch's ref out from under `git worktree list` would desync
|
|
2480
|
-
* that working tree's HEAD from its own index, which no compare-and-swap can
|
|
2481
|
-
* detect or prevent (a worktree's HEAD isn't a ref-race participant here).
|
|
2482
|
-
*
|
|
2483
|
-
* A CAS loss (the ref moved between our read and our write — a sibling
|
|
2484
|
-
* caller landed first) retries the WHOLE computation, up to 3 attempts total,
|
|
2485
|
-
* before giving up with `failureKind: 'ref_race'`.
|
|
2486
|
-
*/
|
|
2487
2631
|
/**
|
|
2488
2632
|
* Normalizes `targetRef` to a full `refs/heads/...` name: a short name like
|
|
2489
2633
|
* `sm-land/x` becomes `refs/heads/sm-land/x`; a value already under
|
|
@@ -2598,6 +2742,34 @@ async function checkTargetRefNotCheckedOut({ cwd, targetRef }) {
|
|
|
2598
2742
|
return { ok: true };
|
|
2599
2743
|
}
|
|
2600
2744
|
|
|
2745
|
+
/**
|
|
2746
|
+
* Lands `branch` onto `targetRef` WITHOUT touching any working tree, index,
|
|
2747
|
+
* or HEAD — no `git checkout`, no `git merge`, nothing in any human's or
|
|
2748
|
+
* job's own checkout ever moves. Fast-forwards via a compare-and-swap `git
|
|
2749
|
+
* update-ref` when `targetRef` is an ancestor of `branch`; otherwise replays
|
|
2750
|
+
* the branch's commits onto the ref tip entirely in the object database
|
|
2751
|
+
* (`replayBranchOnto`) and lands the replayed tip via the same CAS
|
|
2752
|
+
* (`linear: true` — no merge commit, so tooling that refuses merge commits,
|
|
2753
|
+
* like Bilko's scripts/sync-local-main.sh, keeps working). Only when
|
|
2754
|
+
* SM_LINEAR_LANDING_DISABLE=1, or the replay needs a newer git, conflicts
|
|
2755
|
+
* on one of the branch's commits, or cannot reproduce a merge commit inside
|
|
2756
|
+
* the branch (`branch_has_merges`), does it fall back — with a console.warn —
|
|
2757
|
+
* to a two-parent merge commit (`git merge-tree --write-tree` + `git
|
|
2758
|
+
* commit-tree`, `message` as its text) landed via the same CAS and reported
|
|
2759
|
+
* as `mergeCommit: true` + `linearFallback`. This is the foundation for a
|
|
2760
|
+
* per-Epic `sm-land/<epicId>` integration branch that scheduler jobs can land
|
|
2761
|
+
* onto regardless of what the human's own checkout is doing.
|
|
2762
|
+
*
|
|
2763
|
+
* Refuses up front (`failureKind: 'target_checked_out'`, nothing touched) if
|
|
2764
|
+
* `targetRef` is checked out in ANY worktree of this repo — updating a
|
|
2765
|
+
* checked-out branch's ref out from under `git worktree list` would desync
|
|
2766
|
+
* that working tree's HEAD from its own index, which no compare-and-swap can
|
|
2767
|
+
* detect or prevent (a worktree's HEAD isn't a ref-race participant here).
|
|
2768
|
+
*
|
|
2769
|
+
* A CAS loss (the ref moved between our read and our write — a sibling
|
|
2770
|
+
* caller landed first) retries the WHOLE computation, up to 3 attempts total,
|
|
2771
|
+
* before giving up with `failureKind: 'ref_race'`.
|
|
2772
|
+
*/
|
|
2601
2773
|
async function integrateOntoRef({ cwd, targetRef, branch, message }) {
|
|
2602
2774
|
if (!cwd || typeof cwd !== 'string') return { ok: false, reason: 'no cwd provided' };
|
|
2603
2775
|
if (!targetRef || typeof targetRef !== 'string') return { ok: false, reason: 'no targetRef provided' };
|
|
@@ -2932,6 +3104,7 @@ module.exports = {
|
|
|
2932
3104
|
salvageWorktreeDiff,
|
|
2933
3105
|
salvageDirtyDelta,
|
|
2934
3106
|
isBranchMergedIntoHead,
|
|
3107
|
+
isBranchContentLanded,
|
|
2935
3108
|
parseWorktreeListPorcelain,
|
|
2936
3109
|
listCwdHolders,
|
|
2937
3110
|
hasLiveHolder,
|