Skip to content

Commit e6b73af

Browse files
byapparovclaude
andcommitted
refactor(run): decide the snapshot default in run.ts until #164 lands (#146)
Drop the copy of #164's HeadlessRun mark. `aictrl run` now calls `Snapshot.setDefault(false)` before it bootstraps, and `Snapshot.enabled()` uses that process default when config leaves `snapshot` unset. Marked for consolidation with HeadlessRun (#152). Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent fe27d03 commit e6b73af

5 files changed

Lines changed: 27 additions & 40 deletions

File tree

‎packages/cli/README.md‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,13 @@ Automatically fetches the PR branch and imports the agent session used to create
124124

125125
Aictrl reads config from `.aictrl/` (project) or `~/.config/aictrl/` (global).
126126

127+
### Snapshots
128+
129+
Sessions snapshot the git worktree at each model step, which backs patches, session
130+
diffs and revert. `aictrl run` (without `--attach`) skips them, because nothing in a
131+
headless run reads them and each one stages the whole worktree. Set `"snapshot": true`
132+
in config to keep them in a run, or `"snapshot": false` to turn them off everywhere.
133+
127134
### Models
128135

129136
| Provider | Env Var |
@@ -137,13 +144,6 @@ Use `--variant` to select provider-specific reasoning effort. For OpenAI-compati
137144
Ollama models, `--variant none` sends `reasoning_effort: "none"` to disable
138145
thinking; model `options` can also set `reasoning_effort: "none"` directly.
139146

140-
### Snapshots
141-
142-
Sessions snapshot the git worktree at each model step, which backs patches, session
143-
diffs and revert. `aictrl run` (without `--attach`) skips them, because nothing in a
144-
headless run reads them and each one stages the whole worktree. Set `"snapshot": true`
145-
in config to keep them in a run, or `"snapshot": false` to turn them off everywhere.
146-
147147
## Local Development
148148

149149
```bash

‎packages/cli/src/cli/cmd/run.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { terminal } from "./run.terminal"
1010
import { buildToolCatalogItems } from "./tool-catalog"
1111
import { withTimeout } from "../../util/timeout"
1212
import { Flag } from "../../flag/flag"
13-
import { HeadlessRun } from "../../flag/headless-run"
1413
import { bootstrap } from "../bootstrap"
1514
import { EOL } from "os"
1615
import { Filesystem } from "../../util/filesystem"
@@ -23,6 +22,7 @@ import { PermissionNext } from "../../permission/next"
2322
import { Session } from "../../session"
2423
import type { MessageV2 } from "../../session/message-v2"
2524
import { SessionPrompt } from "../../session/prompt"
25+
import { Snapshot } from "../../snapshot"
2626
import { Config } from "../../config/config"
2727
import { GlobalBus } from "../../bus/global"
2828
import { Instance } from "../../project/instance"
@@ -1094,13 +1094,14 @@ export const RunCommand = cmd({
10941094
await Shutdown.flush()
10951095
}
10961096

1097+
// Nothing in a run reads snapshots, patches or session diffs, so local sessions skip
1098+
// them unless config sets `snapshot: true` (#146). consolidate with HeadlessRun (#152)
1099+
Snapshot.setDefault(false)
10971100
invocation.phase("bootstrap")
10981101
if (args.attach) {
10991102
return await invocation.run(() => execute(createAictrlClient({ baseUrl: args.attach, directory })))
11001103
}
11011104

1102-
// Sessions this process serves belong to the headless run until it finishes.
1103-
HeadlessRun.enable()
11041105
const execution = bootstrap(process.cwd(), async () => {
11051106
const sdk = {
11061107
session: {
@@ -1193,6 +1194,6 @@ export const RunCommand = cmd({
11931194
}
11941195
await execute(sdk)
11951196
})
1196-
await invocation.run(execution).finally(() => HeadlessRun.disable())
1197+
await invocation.run(execution)
11971198
},
11981199
})

‎packages/cli/src/flag/headless-run.ts‎

Lines changed: 0 additions & 21 deletions
This file was deleted.

‎packages/cli/src/snapshot/index.ts‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import path from "path"
33
import fs from "fs/promises"
44
import { Log } from "../util/log"
55
import { Flag } from "../flag/flag"
6-
import { HeadlessRun } from "../flag/headless-run"
76
import { Global } from "../global"
87
import z from "zod"
98
import { Config } from "../config/config"
@@ -14,6 +13,8 @@ export namespace Snapshot {
1413
const log = Log.create({ service: "snapshot" })
1514
const hour = 60 * 60 * 1000
1615
const prune = "7.days"
16+
// Applies when config leaves `snapshot` unset; a headless `aictrl run` turns it off.
17+
let byDefault = true
1718

1819
export function init() {
1920
Scheduler.register({
@@ -24,16 +25,21 @@ export namespace Snapshot {
2425
})
2526
}
2627

28+
/** Sets whether this process snapshots the worktree when config leaves `snapshot` unset. */
29+
export function setDefault(enabled: boolean) {
30+
byDefault = enabled
31+
}
32+
2733
/**
2834
* Whether this instance snapshots the worktree. Config `snapshot` decides when it
29-
* is set. Otherwise a headless `aictrl run` skips snapshots: nothing in a run reads
30-
* them, and each one stages the whole worktree with `git add` (#146).
35+
* is set; otherwise the process default applies, which `aictrl run` turns off:
36+
* nothing in a run reads snapshots, and each one stages the whole worktree (#146).
3137
*/
3238
export async function enabled() {
3339
if (Instance.project.vcs !== "git" || Flag.AICTRL_CLIENT === "acp") return false
3440
const cfg = await Config.get()
3541
if (cfg.snapshot !== undefined) return cfg.snapshot
36-
return !HeadlessRun.enabled()
42+
return byDefault
3743
}
3844

3945
export async function cleanup() {

‎packages/cli/test/session/processor-snapshot.test.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { afterEach, describe, expect, spyOn, test } from "bun:test"
22
import fs from "fs/promises"
33
import path from "path"
44
import { Agent } from "../../src/agent/agent"
5-
import { HeadlessRun } from "../../src/flag/headless-run"
65
import { Global } from "../../src/global"
76
import { Identifier } from "../../src/id/id"
87
import { Instance } from "../../src/project/instance"
@@ -17,7 +16,7 @@ import { Storage } from "../../src/storage/storage"
1716
import type { Config } from "../../src/config/config"
1817
import { tmpdir } from "../fixture/fixture"
1918

20-
afterEach(() => HeadlessRun.disable())
19+
afterEach(() => Snapshot.setDefault(true))
2120

2221
/**
2322
* Runs one model step that writes `out.txt` in a git worktree and returns what the
@@ -112,7 +111,8 @@ async function step(config: Partial<Config.Info> = {}) {
112111

113112
describe("headless run snapshots (#146)", () => {
114113
test("a headless run takes no snapshot, records no patch and writes no session diff", async () => {
115-
HeadlessRun.enable()
114+
// what `aictrl run` sets before it bootstraps
115+
Snapshot.setDefault(false)
116116
const result = await step()
117117

118118
expect(result.shadow).toBe(false)
@@ -126,7 +126,8 @@ describe("headless run snapshots (#146)", () => {
126126
})
127127

128128
test("config `snapshot: true` re-enables snapshots, patches and the session diff in a headless run", async () => {
129-
HeadlessRun.enable()
129+
// what `aictrl run` sets before it bootstraps
130+
Snapshot.setDefault(false)
130131
const result = await step({ snapshot: true })
131132

132133
expect(result.shadow).toBe(true)

0 commit comments

Comments
 (0)