@@ -541,9 +541,9 @@ function satisfiesMinimumCrabboxVersion(version: string, minimum: number[]) {
541541 return ! parsed . suffix || isPostReleaseDescribeSuffix ( parsed . suffix ) ;
542542}
543543
544- function gitOutput ( commandArgs : string [ ] ) {
544+ function gitOutput ( commandArgs : string [ ] , extraEnv : ProcessEnv = { } ) {
545545 const gitBinary = resolvePathBinary ( "git" , process . env , process . platform ) ?? "git" ;
546- const gitEnv = { ...process . env , GIT_CONFIG_GLOBAL : "/dev/null" } ;
546+ const gitEnv = { ...process . env , ... extraEnv , GIT_CONFIG_GLOBAL : "/dev/null" } ;
547547 const invocation = spawnInvocation ( gitBinary , commandArgs , gitEnv , process . platform ) ;
548548 const result = spawnSync ( invocation . command , invocation . args , {
549549 cwd : repoRoot ,
@@ -3200,7 +3200,13 @@ function analyzeRemoteCommand(invocation: RunInvocation) {
32003200 } ;
32013201}
32023202
3203- function prepareRemoteWsl2JsBootstrapScript ( run : RunInvocation , facts : RunFacts , provider : string ) {
3203+ function prepareRemoteWsl2JsBootstrapScript (
3204+ run : RunInvocation ,
3205+ facts : RunFacts ,
3206+ provider : string ,
3207+ changedGateBase : string ,
3208+ changedGateAlias : string ,
3209+ ) {
32043210 const runtimeEntrypoint = awsMacosBunEntrypoints . has ( facts . runtimeEntrypoint )
32053211 ? ""
32063212 : facts . runtimeEntrypoint ;
@@ -3220,7 +3226,7 @@ function prepareRemoteWsl2JsBootstrapScript(run: RunInvocation, facts: RunFacts,
32203226 const originalShellCommand = facts . scopedEnvCommand ?. shellCommand ?? renderRunShellCommand ( run ) ;
32213227 const script = `${ remoteWsl2JsBootstrap ( {
32223228 packageManager : facts . packageManager ,
3223- } ) } || exit $?\n{ ${ originalShellCommand } \n}\n`;
3229+ } ) } || exit $?\n${ facts . changedGate && changedGateBase ? ` ${ remoteGitBootstrapForChangedGate ( changedGateBase , changedGateAlias ) } || exit $?\n` : "" } { ${ originalShellCommand } \n}\n`;
32243230 writeFileSync ( scriptPath , script , "utf8" ) ;
32253231 chmodSync ( scriptPath , 0o700 ) ;
32263232
@@ -3410,21 +3416,19 @@ function isWorktreeClean() {
34103416 return status . status === 0 && status . stdout === "" ;
34113417}
34123418
3413- function shouldUseFullCheckoutForCleanRemoteSync ( commandArgs : string [ ] , _providerName : string ) {
3419+ function shouldUseFullCheckoutForRemoteSync ( commandArgs : string [ ] , _providerName : string ) {
34143420 if ( commandArgs [ 0 ] !== "run" ) {
34153421 return false ;
34163422 }
34173423 if ( hasOption ( commandArgs , "--no-sync" ) ) {
34183424 return false ;
34193425 }
3420- if ( ! isWorktreeClean ( ) ) {
3421- return false ;
3422- }
34233426
3424- return (
3425- isSparseCheckout ( ) ||
3426- isChangedGateCommand ( parseRunInvocation ( help . text , commandArgs ) . commandArgs )
3427- ) ;
3427+ const changedGate = isChangedGateCommand ( parseRunInvocation ( help . text , commandArgs ) . commandArgs ) ;
3428+ if ( changedGate && ! isNativeWindowsRemoteTarget ( commandArgs ) ) {
3429+ return true ;
3430+ }
3431+ return isWorktreeClean ( ) && ( isSparseCheckout ( ) || changedGate ) ;
34283432}
34293433
34303434function defaultFullCheckoutSyncRoot ( ) {
@@ -3498,9 +3502,27 @@ function assertFullCheckoutSyncDisk(root: string) {
34983502 ) ;
34993503}
35003504
3505+ function currentWorktreeTree ( syncRoot : string ) {
3506+ const indexDir = mkdtempSync ( resolve ( syncRoot , "openclaw-crabbox-index-" ) ) ;
3507+ const indexPath = resolve ( indexDir , "index" ) ;
3508+ const indexEnv = { GIT_INDEX_FILE : indexPath } ;
3509+ try {
3510+ const read = gitOutput ( [ "read-tree" , "HEAD" ] , indexEnv ) ;
3511+ const add = gitOutput ( [ "add" , "-A" , "--" , "." ] , indexEnv ) ;
3512+ const tree = gitOutput ( [ "write-tree" ] , indexEnv ) ;
3513+ if ( read . status !== 0 || add . status !== 0 || tree . status !== 0 || ! tree . stdout ) {
3514+ throw new Error ( read . text || add . text || tree . text || "git write-tree failed" ) ;
3515+ }
3516+ return tree . stdout ;
3517+ } finally {
3518+ rmSync ( indexDir , { recursive : true , force : true } ) ;
3519+ }
3520+ }
3521+
35013522function prepareFullCheckoutForSync ( options : { changedGateBase ?: string } = { } ) {
35023523 const syncRoot = fullCheckoutSyncRoot ( ) ;
35033524 assertFullCheckoutSyncDisk ( syncRoot ) ;
3525+ const changedGateTree = options . changedGateBase ? currentWorktreeTree ( syncRoot ) : "" ;
35043526 const dir = mkdtempSync ( resolve ( syncRoot , "openclaw-crabbox-sync-" ) ) ;
35053527 let active = false ;
35063528 let resolvedChangedGateBase = options . changedGateBase ?? "" ;
@@ -3526,19 +3548,15 @@ function prepareFullCheckoutForSync(options: { changedGateBase?: string } = {})
35263548 try {
35273549 bundleTempDir = mkdtempSync ( resolve ( syncRoot , "openclaw-crabbox-bundle-" ) ) ;
35283550 const bundleTempPath = resolve ( bundleTempDir , "changed-gate.bundle" ) ;
3529- const head = gitOutput ( [ "-C" , dir , "rev-parse" , "HEAD" ] ) ;
35303551 const base = gitOutput ( [ "-C" , dir , "rev-parse" , options . changedGateBase ] ) ;
3531- if ( head . status !== 0 || base . status !== 0 || ! head . stdout || ! base . stdout ) {
3532- throw new Error ( `git rev-parse failed: ${ head . text || base . text } ` ) ;
3552+ const baseTree = gitOutput ( [ "-C" , dir , "rev-parse" , `${ options . changedGateBase } ^{tree}` ] ) ;
3553+ if ( base . status !== 0 || baseTree . status !== 0 || ! base . stdout || ! baseTree . stdout ) {
3554+ throw new Error ( `git rev-parse failed: ${ base . text || baseTree . text } ` ) ;
35333555 }
35343556 resolvedChangedGateBase = base . stdout ;
3535- if ( head . stdout === base . stdout ) {
3557+ if ( changedGateTree === baseTree . stdout ) {
35363558 writeFileSync ( bundleTempPath , "" , "utf8" ) ;
35373559 } else {
3538- const headTree = gitOutput ( [ "-C" , dir , "rev-parse" , "HEAD^{tree}" ] ) ;
3539- if ( headTree . status !== 0 || ! headTree . stdout ) {
3540- throw new Error ( headTree . text || "git rev-parse HEAD tree failed" ) ;
3541- }
35423560 // A parentless carrier makes the bundle self-contained while sending
35433561 // only the final tree. The remote attaches the fetched base as parent.
35443562 const transportCommit = gitOutput ( [
@@ -3549,7 +3567,7 @@ function prepareFullCheckoutForSync(options: { changedGateBase?: string } = {})
35493567 "-c" ,
3550356835513569 "commit-tree" ,
3552- headTree . stdout ,
3570+ changedGateTree ,
35533571 "-m" ,
35543572 "remote-changed-gate-tree" ,
35553573 ] ) ;
@@ -3762,6 +3780,8 @@ function applyRunTransforms(
37623780 invocation ,
37633781 facts ,
37643782 options . provider ,
3783+ options . changedGateBase ,
3784+ options . changedGateAlias ,
37653785 ) ;
37663786 let transformedArgs = wsl2ScriptBootstrap . args ;
37673787 invocation = parseRunInvocation ( help . text , transformedArgs ) ;
@@ -3938,7 +3958,7 @@ normalizedArgs = scriptBootstrap.args;
39383958const scriptStdinPrepared = scriptBootstrap . prepared ;
39393959let wsl2ScriptBootstrap = { args : normalizedArgs , cleanup : ( ) => { } , prepared : false } ;
39403960try {
3941- if ( shouldUseFullCheckoutForCleanRemoteSync ( normalizedArgs , provider ) ) {
3961+ if ( shouldUseFullCheckoutForRemoteSync ( normalizedArgs , provider ) ) {
39423962 const invocation = parseRunInvocation ( help . text , normalizedArgs ) ;
39433963 const facts = analyzeRemoteCommand ( invocation ) ;
39443964 const changedGate = facts . changedGate ? changedGateBaseForCommand ( facts . commandArgs ) : null ;
@@ -3953,11 +3973,11 @@ try {
39533973 remoteChangedGateBase = checkout . changedGateBase ;
39543974 remoteChangedGateAlias = changedGate ?. remoteAlias ?? "" ;
39553975 console . error (
3956- `[crabbox] sparse clean checkout detected ; syncing from temporary full checkout ${ checkout . dir } ` ,
3976+ `[crabbox] isolated checkout sync ; syncing from temporary full checkout ${ checkout . dir } ` ,
39573977 ) ;
39583978 if ( checkout . changedGateBase ) {
39593979 console . error (
3960- `[crabbox] remote changed gate detected; overlaying local HEAD as worktree changes from ${ checkout . changedGateBase } ` ,
3980+ `[crabbox] remote changed gate detected; overlaying the local worktree as changes from ${ checkout . changedGateBase } ` ,
39613981 ) ;
39623982 }
39633983 }
@@ -4124,7 +4144,7 @@ if (childStderr) {
41244144 } ) ;
41254145}
41264146const childKillGraceMs = resolveChildKillGraceMs ( process . env ) ;
4127- let childForceKillTimer : NodeJS . Timeout | undefined ;
4147+ let childForceKillTimer : ReturnType < typeof setTimeout > | undefined ;
41284148let childTreeShutdownStarted = false ;
41294149if ( fullCheckout ) {
41304150 try {
0 commit comments