Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/persist-snapshot-disable.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@kilocode/cli": patch
---

Persist disabling snapshots from the slow-repo prompt across restarts.
31 changes: 12 additions & 19 deletions packages/opencode/src/kilocode/snapshot/track.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ import { PartID as PartIDSchema } from "@/session/schema"
import type { MessageV2 } from "@/session/message-v2"
import { KiloPartLifecycle } from "@/kilocode/session/part-lifecycle"
import { KilocodeConfig } from "@/kilocode/config/config"
import { capture } from "@/kilocode/instance"
import { ConfigParse } from "@/config/parse"
import * as Log from "@opencode-ai/core/util/log"
import { iife } from "@/util/iife"
import { EffectBridge } from "@/effect/bridge"
import { makeRuntime } from "@/effect/run-service"
import type { Config } from "@/config/config"
// Avoid an eager `import { Session }` here: session/index.ts indirectly
Expand Down Expand Up @@ -473,7 +475,9 @@ export namespace KiloSnapshotTrack {

if (answer === "disable") {
log.info("user chose to disable snapshot for this project")
yield* Effect.promise(() =>
// Restore instance context across the Promise boundary; Effect.promise
// drops it, and persistDisable needs the project directory.
yield* EffectBridge.fromPromise(() =>
hooks.persistDisable().catch((err) => {
log.error("failed to persist snapshot:false to project config", { err })
}),
Expand Down Expand Up @@ -631,17 +635,20 @@ export namespace KiloSnapshotTrack {
},

async persistDisable() {
const directory = await currentDirectory()
if (!directory) return
const ctx = capture()
if (!ctx) {
log.error("persistDisable: no instance directory; snapshot:false was not written to project config")
return
}
// Every field on Config.Info is Schema.optional(...), so a single-key
// object is structurally a valid Config.Info — no cast needed.
const patch: Config.Info = { snapshot: false }
await fsRt.runPromise((fs) =>
Effect.gen(function* () {
yield* KilocodeConfig.updateProjectConfig({
fs,
directory: directory.directory,
worktree: directory.worktree,
directory: ctx.directory,
worktree: ctx.worktree,
config: patch,
read: (file) =>
fs.readFileString(file).pipe(
Expand Down Expand Up @@ -681,18 +688,4 @@ export namespace KiloSnapshotTrack {
return applyEdits(out, edits)
}, input)
}

/**
* Resolve the active instance directory/worktree. Runs via `Instance.current`
* when available; returns undefined outside of an instance context (e.g. in
* tests that bypass the runtime).
*/
async function currentDirectory(): Promise<{ directory: string; worktree?: string } | undefined> {
const { Instance } = await import("@/kilocode/instance")
try {
return { directory: Instance.directory, worktree: Instance.worktree }
} catch {
return undefined
}
}
}
42 changes: 42 additions & 0 deletions packages/opencode/test/kilocode/snapshot-track-timeout.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
import { describe, expect, test } from "bun:test"
import { Deferred, Duration, Effect, Fiber } from "effect"
import * as TestClock from "effect/testing/TestClock"
import path from "path"
import { PartID, type MessageID, type SessionID } from "../../src/session/schema"
import { KiloSnapshotTrack } from "../../src/kilocode/snapshot/track"
import { KiloPartLifecycle } from "../../src/kilocode/session/part-lifecycle"
import { TestInstance } from "../fixture/fixture"
import { awaitWithTimeout, it } from "../lib/effect"

const SESSION = "ses_test" as SessionID
Expand Down Expand Up @@ -949,6 +951,46 @@ describe("KiloSnapshotTrack progress indicator", () => {
})
})

describe("KiloSnapshotTrack persistDisable", () => {
it.instance(
"disable writes snapshot:false to the project config",
() =>
Effect.gen(function* () {
const test = yield* TestInstance
const state = KiloSnapshotTrack.makeState()
const hooks: KiloSnapshotTrack.Hooks = {
...KiloSnapshotTrack.defaultHooks,
async ask() {
return "disable"
},
async startProgress() {},
async updateProgress() {},
async endProgress() {},
}

yield* KiloSnapshotTrack.wrap({
inner: hangInner(),
state,
sessionID: SESSION,
messageID: MESSAGE,
hooks,
timeoutMs: 10,
progressDelayMs: 2,
})

const file = path.join(test.directory, ".kilo", "kilo.jsonc")
const text = yield* Effect.tryPromise(() => Bun.file(file).text())
expect(JSON.parse(text).snapshot).toBe(false)
expect(state.disabledForSession).toBe(true)
}),
{ git: true },
)

test("persistDisable without instance context does not throw", async () => {
await KiloSnapshotTrack.defaultHooks.persistDisable()
})
})

describe("KiloSnapshotTrack constants", () => {
test("TIMEOUT_MS defaults to 10s and respects env override", () => {
// The constant is evaluated once at module load, so we can only assert
Expand Down
Loading