diff --git a/packages/opencode/src/snapshot/index.ts b/packages/opencode/src/snapshot/index.ts index e809a0a4ad..2189036abc 100644 --- a/packages/opencode/src/snapshot/index.ts +++ b/packages/opencode/src/snapshot/index.ts @@ -179,18 +179,24 @@ export const layer: Layer.Layer = ) }) - const stage = Effect.fnUntraced(function* (files: string[], env?: Record) { // kilocode_change + // kilocode_change start + const stage = Effect.fnUntraced(function* ( + files: string[], + opts?: { env?: Record; root?: boolean }, + ) { + // kilocode_change end if (!files.length) return // kilocode_change start - // Seeded snapshots cover the worktree root, so a single pathspec avoids + // A new root snapshot covers the full worktree, so a single pathspec avoids // quadratic matching against every tracked path in very large repositories. - const cmd = env + const cmd = opts?.root ? ["add", "--all", "--sparse", "--", "."] : ["add", "--all", "--sparse", "--pathspec-from-file=-", "--pathspec-file-nul"] + const result = yield* git([...cfg, ...args(cmd)], { cwd: state.directory, - env, - stdin: env ? undefined : feed(files), + env: opts?.env, + stdin: opts?.root ? undefined : feed(files), }) // kilocode_change end if (result.code === 0) return @@ -238,7 +244,7 @@ export const layer: Layer.Layer = yield* fs.writeFileString(target, text ? `${text}\n` : "").pipe(Effect.orDie) }) - const add = Effect.fnUntraced(function* (env?: Record) { // kilocode_change + const add = Effect.fnUntraced(function* (opts?: { env?: Record; root?: boolean }) { // kilocode_change yield* sync() const [diff, other] = yield* Effect.all( [ @@ -303,7 +309,7 @@ export const layer: Layer.Layer = // kilocode_change start - initial seeded writes stay protected by the source pin yield* stage( allow.filter((item) => !block.has(item)), - env, + opts, ) }) @@ -376,7 +382,7 @@ export const layer: Layer.Layer = GIT_ALTERNATE_OBJECT_DIRECTORIES: path.join(seed.gitdir, "objects"), } : undefined - yield* add(env) + yield* add({ env, root: !existed && state.directory === state.worktree }) if ( seed && !(yield* KiloSnapshotMaterialize.localize({