Skip to content

Commit 86c30f0

Browse files
igorcostaAutohand Evolve
andauthored
Merge pull request #687 from autohandai/cto/ship-all-safety-20261020
Apply the reviewed CLI safety, provider-routing, review and update changes. Full local bun run proof passed: lint, typecheck, build, 12,132 unit tests and 299 real-terminal tests across all 72 terminal files. CLI publication remains held for the GitHub Actions billing lock. GitHub CI jobs did not start: the account is locked due to a billing issue. Igor explicitly approved merging CLI items while this release block remains. Co-authored-by: Autohand Evolve <code-noreply@autohand.ai>
2 parents 87eb950 + 58f7267 commit 86c30f0

55 files changed

Lines changed: 1195 additions & 292 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎docs/automode.md‎

Lines changed: 37 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -23,38 +23,12 @@ autohand --auto-mode "Build a REST API for todos"
2323

2424
## How It Works
2525

26-
```
27-
┌─────────────────────────────────────────────────────────────┐
28-
│ AUTO-MODE LOOP │
29-
├─────────────────────────────────────────────────────────────┤
30-
│ │
31-
│ 1. User starts: autohand --auto-mode "Build REST API" │
32-
│ │ │
33-
│ 2. Create worktree ────┼──▶ autohand-automode-<timestamp> │
34-
│ │ │
35-
│ 3. Initialize state ───┼──▶ .autohand/automode.local.md │
36-
│ │ │
37-
│ ┌──────────────────────▼──────────────────────────┐ │
38-
│ │ ITERATION LOOP │ │
39-
│ │ ┌─────────────────────────────────────────┐ │ │
40-
│ │ │ 4. Feed prompt to LLM │ │ │
41-
│ │ │ 5. Execute actions (read/write/run) │ │ │
42-
│ │ │ 6. Agent tries to exit │ │ │
43-
│ │ │ 7. Stop hook intercepts │───┐│ │
44-
│ │ │ 8. Check completion conditions │ ││ │
45-
│ │ │ - Completion marker detected? │ ││ │
46-
│ │ │ - Max iterations reached? │ ││ │
47-
│ │ │ - Cancel signal received? │ ││ │
48-
│ │ │ 9. If not complete: feed prompt again │◀──┘│ │
49-
│ │ └─────────────────────────────────────────┘ │ │
50-
│ └─────────────────────────────────────────────────┘ │
51-
│ │ │
52-
│ 10. On completion ─────┼──▶ Merge worktree to main │
53-
│ │ │
54-
│ 11. Generate report ───┼──▶ AUTOMODE_CHANGELOG.md │
55-
│ │
56-
└─────────────────────────────────────────────────────────────┘
57-
```
26+
1. Creates an isolated Git worktree by default.
27+
2. Stores private state for this run outside the project.
28+
3. Repeats the task until it prints the completion marker, hits a configured limit, or stops making progress.
29+
4. Keeps the branch and worktree for review and prints merge and cleanup commands.
30+
5. Writes `AUTOMODE_CHANGELOG.md` inside the worktree.
31+
5832

5933
## CLI Usage
6034

@@ -71,7 +45,6 @@ autohand --auto-mode "<prompt>" [options]
7145
| `--no-worktree` | Disable git worktree isolation | - |
7246
| `--checkpoint-interval <n>` | Git commit every N iterations | 5 |
7347
| `--max-runtime <m>` | Maximum runtime in minutes | 120 |
74-
| `--max-cost <d>` | Maximum API cost in dollars | 10 |
7548
| `--interactive-on-complete` | Hand off directly to interactive mode when loop ends (TTY only) | Off |
7649
| `--dry-run` | Preview actions without executing | - |
7750

@@ -85,7 +58,6 @@ autohand --auto-mode "Build a CLI tool for file backup"
8558
autohand --auto-mode "Refactor auth system" \
8659
--max-iterations 30 \
8760
--max-runtime 60 \
88-
--max-cost 5 \
8961
--completion-promise "REFACTOR_COMPLETE"
9062

9163
# Without worktree (use current branch)
@@ -171,11 +143,12 @@ Multiple ways to stop an auto-mode loop:
171143

172144
### Resource Limits
173145

146+
CLI runs reject `--max-cost` and `automode.maxCost` because they cannot enforce a dollar spend limit. Use iteration and runtime limits instead.
147+
174148
| Limit | Default | Purpose |
175149
|-------|---------|---------|
176150
| Max Iterations | 50 | Prevents infinite loops |
177151
| Max Runtime | 120 min | Limits total time |
178-
| Max Cost | $10 | Caps API spending |
179152
| Checkpoint Interval | 5 | Creates git checkpoints |
180153

181154
### Git Worktree Isolation
@@ -184,38 +157,37 @@ By default, auto-mode creates an isolated git worktree to protect your main bran
184157

185158
```
186159
┌─────────────────────────────────────────────────────────────────┐
187-
│ WORKTREE LIFECYCLE │
160+
│ WORKTREE LIFECYCLE │
188161
├─────────────────────────────────────────────────────────────────┤
189-
│ │
190-
│ START │
191-
│ ├─ Create branch: autohand-automode-<timestamp> │
192-
│ ├─ Create worktree: /tmp/autohand-worktree-<hash> │
193-
│ └─ ALL file operations now happen in the worktree │
194-
│ │
195-
│ DURING LOOP │
196-
│ ├─ Agent reads/writes files in worktree │
197-
│ ├─ Every N iterations: checkpoint commit to automode branch │
198-
│ └─ Main branch remains untouched │
199-
│ │
200-
│ ON SUCCESS │
201-
│ ├─ git checkout <original-branch> │
202-
│ ├─ git merge autohand-automode-xxx │
203-
│ ├─ git worktree remove /tmp/autohand-worktree-xxx │
204-
│ └─ git branch -d autohand-automode-xxx │
205-
│ │
206-
│ ON CANCEL/ERROR │
207-
│ └─ Worktree PRESERVED for manual inspection │
208-
│ You can: cd /tmp/autohand-worktree-xxx │
209-
│ git log, git diff, cherry-pick, etc. │
210-
│ │
162+
│ │
163+
│ START │
164+
│ ├─ Create branch: autohand-automode-<timestamp>-<id> │
165+
│ ├─ Create worktree: <temp dir>/autohand-worktree-<hash> │
166+
│ └─ ALL file operations now happen in the worktree │
167+
│ │
168+
│ DURING LOOP │
169+
│ ├─ Agent reads/writes files in worktree │
170+
│ ├─ Every N iterations: checkpoint commit to automode branch │
171+
│ └─ Main branch remains untouched │
172+
│ │
173+
│ ON SUCCESS │
174+
│ ├─ Commit a final checkpoint in the isolated branch │
175+
│ ├─ Print branch, worktree, review and recovery commands │
176+
│ └─ Preserve the branch and worktree for manual review │
177+
│ │
178+
│ ON CANCEL, LIMIT OR ERROR │
179+
│ └─ Worktree PRESERVED for manual inspection │
180+
│ You can: cd <worktree path from the summary> │
181+
│ git log, git diff, cherry-pick, etc. │
182+
│ │
211183
└─────────────────────────────────────────────────────────────────┘
212184
```
213185

214186
**Key Points:**
215187
- **One worktree per session** (not per iteration)
216188
- **All agent operations** (file reads, writes, commands) happen in the worktree
217189
- **Checkpoints** create commits in the automode branch at regular intervals
218-
- **Merge happens once** at the end on successful completion
190+
- **Merge is manual**: completed runs keep their branch and worktree for review. The summary prints the merge and safe cleanup commands.
219191
- **Preserved on failure** so you can inspect, recover, or cherry-pick changes
220192

221193
**Benefits:**
@@ -237,16 +209,16 @@ This prevents getting stuck in unproductive loops.
237209

238210
## State File
239211

240-
Auto-mode maintains state in `.autohand/automode.local.md`:
212+
Each run stores its state in `$AUTOHAND_HOME/automode/<workspace-id>/<run-id>/automode.local.md` (`~/.autohand` is the default home). State stays outside the project and is private to the current user. Legacy `.autohand/automode.local.md` files are ignored and do not activate a later interactive session:
241213

242214
```markdown
243215
# Auto-Mode State
244216

245217
## Session
246218
- **Started:** 2026-01-06T14:30:00Z
247219
- **Prompt:** Build a REST API for todos with CRUD operations
248-
- **Branch:** autohand-automode-1736175000
249-
- **Worktree:** /tmp/autohand-worktree-abc123
220+
- **Branch:** autohand-automode-1736175000-a1b2c3d4
221+
- **Worktree:** <temp dir>/autohand-worktree-abc123
250222

251223
## Progress
252224
- **Current Iteration:** 12
@@ -275,7 +247,7 @@ After each session, auto-mode generates `AUTOMODE_CHANGELOG.md`:
275247
- **Task:** Build a REST API for todos
276248
- **Duration:** 45 minutes (12 iterations)
277249
- **Result:** Completed successfully
278-
- **Branch:** autohand-automode-1736175000 → merged to main
250+
- **Branch:** autohand-automode-1736175000-a1b2c3d4 → awaiting review
279251

280252
## Iterations
281253
### Iteration 1 (14:30:00)
@@ -327,7 +299,6 @@ Add defaults to `~/.autohand/config.json`:
327299
"automode": {
328300
"maxIterations": 50,
329301
"maxRuntime": 120,
330-
"maxCost": 10,
331302
"checkpointInterval": 5,
332303
"completionPromise": "DONE",
333304
"useWorktree": true,
@@ -366,15 +337,15 @@ Add defaults to `~/.autohand/config.json`:
366337
### High cost
367338

368339
- Lower `--max-iterations`
369-
- Set a stricter `--max-cost`
340+
- Set a shorter `--max-runtime`
370341
- Use a more efficient model
371342
- Break task into smaller chunks
372343

373344
### Loop appears stuck
374345

375346
- The circuit breaker should auto-trigger
376347
- Press ESC to cancel manually
377-
- Check `.autohand/automode.local.md` for state
348+
- Check the run's private state under `AUTOHAND_HOME/automode/` (default: `~/.autohand/automode/`)
378349

379350
## Related
380351

‎docs/config-reference.md‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ See [Workspace Safety](./workspace-safety.md) for full details.
774774
| `activitySymbol` | string | `"✳"` | Symbol shown before the activity verb in activity indicator output |
775775
| `showTips` | boolean | `true` | Rotate tips about slash commands, the `/ @ $ ! : ?` triggers and shortcuts beside the idle composer |
776776
| `enterWhileWorking` | string | `select` | While a turn runs, Enter queues a draft; select a queued message with the arrow keys, press Enter to edit it, then Enter to steer or Shift+Enter to save it in the queue. `steer` and `queue` retain the earlier direct steering shortcuts for configured sessions |
777-
| `defaultInteractionMode` | `"default"`, `"plan"`, `"automode"` or `"yolo"` | `"automode"` | Mode an interactive terminal session starts in. Auto mode runs without approval prompts; set `"default"` to be asked before risky actions. `--plan`, `--yolo`, `--restricted`, `--dry-run`, `--unrestricted`, `--yes` and a `restricted` or `external` `permissions.mode` take precedence, and command, RPC and ACP runs are never switched to auto mode |
777+
| `defaultInteractionMode` | `"default"`, `"plan"`, `"automode"` or `"yolo"` | `"default"` | Mode an interactive terminal session starts in. The default asks before risky actions. Auto mode requires an explicit flag, mode selection, or `defaultInteractionMode` set to `"automode"`, and runs without approval prompts. `--plan`, `--yolo`, `--restricted`, `--dry-run`, `--unrestricted`, `--yes` and a `restricted` or `external` `permissions.mode` take precedence, and command, RPC and ACP runs are never switched to auto mode |
778778
| `statusLine.showProviderModel` | boolean | `true` | Show the active provider and model in the composer status line |
779779
| `statusLine.showContext` | boolean | `true` | Show the context percentage in the composer status line |
780780
| `statusLine.showCommandHint` | boolean | `true` | Show command, mention, skill, and terminal-entry hints in the composer status line |
@@ -2927,7 +2927,6 @@ Inspect the result with `zit status` and `zit show <change>`; accepting the chan
29272927
| `--completion-promise <text>` | Completion marker text (default: "DONE") |
29282928
| `--checkpoint-interval <n>` | Git commit every N iterations (default: 5) |
29292929
| `--max-runtime <m>` | Max runtime in minutes (default: 120) |
2930-
| `--max-cost <d>` | Max API cost in dollars (default: 10) |
29312930
| `--interactive-on-complete` | After auto-mode ends, hand off directly to interactive mode (TTY only) |
29322931

29332932
### Skills & Learning

‎src/auth/ensureAuth.ts‎

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { checkForUpdates } from '../utils/versionCheck.js';
1515
import packageJson from '../../package.json' with { type: 'json' };
1616
import type { LoadedConfig } from '../types.js';
1717
import { spawn, spawnSync } from 'node:child_process';
18-
import { platform } from 'node:os';
18+
import { getUpdateCommand } from '../utils/installMethod.js';
1919

2020
/**
2121
* Get git commit hash (short)
@@ -44,33 +44,14 @@ async function getGitCommit(): Promise<string> {
4444
* Run the appropriate upgrade command based on platform
4545
*/
4646
async function runUpgrade(): Promise<void> {
47-
const os = platform();
48-
let command: string;
49-
let args: string[];
50-
const shell: string | boolean = false;
51-
52-
if (os === 'win32') {
53-
// Windows
54-
command = 'powershell.exe';
55-
args = ['-Command', 'iwr -useb https://autohand.ai/install.ps1 | iex'];
56-
} else if (os === 'darwin') {
57-
// macOS - try brew first, fallback to curl
58-
command = 'sh';
59-
args = ['-c', 'brew install autohandai/code/autohand-code || curl -fsSL https://autohand.ai/install.sh | sh'];
60-
} else {
61-
// Linux - use curl
62-
command = 'sh';
63-
args = ['-c', 'curl -fsSL https://autohand.ai/install.sh | sh'];
64-
}
65-
47+
const { command, args, hint } = getUpdateCommand(packageJson.version.includes('-alpha.') ? 'alpha' : 'stable');
6648
console.log(chalk.gray('Upgrading Autohand...'));
6749
console.log(chalk.gray(`Running: ${command} ${args.join(' ')}`));
6850
console.log();
6951

7052
return new Promise((resolve, reject) => {
7153
const child = spawn(command, args, {
7254
stdio: 'inherit',
73-
shell: shell || undefined,
7455
// The installer offers to start Autohand with a first message; a nested
7556
// session inside the one being upgraded must never start.
7657
env: { ...process.env, AUTOHAND_INSTALL_FIRST_RUN: 'no' },
@@ -86,14 +67,7 @@ async function runUpgrade(): Promise<void> {
8667
console.log();
8768
console.log(chalk.red('Upgrade failed.'));
8869
console.log(chalk.gray('You can try manually:'));
89-
if (os === 'win32') {
90-
console.log(chalk.gray(' iwr -useb https://autohand.ai/install.ps1 | iex'));
91-
} else {
92-
console.log(chalk.gray(' curl -fsSL https://autohand.ai/install.sh | sh'));
93-
console.log(chalk.gray(' or: brew install autohandai/code/autohand-code'));
94-
}
95-
console.log(chalk.gray(' or: npm i -g autohand-cli'));
96-
console.log(chalk.gray(' or: bun i -g autohand-cli'));
70+
console.log(chalk.gray(` ${hint}`));
9771
reject(new Error(`Upgrade failed with exit code ${code}`));
9872
}
9973
});
@@ -224,6 +198,13 @@ function isTokenExpiredLocally(config: LoadedConfig): boolean {
224198
* Reloads config after login. Exits if login fails.
225199
*/
226200
async function promptLogin(config: LoadedConfig): Promise<LoadedConfig> {
201+
const ci = process.env.CI?.trim().toLowerCase();
202+
if (!process.stdin.isTTY || !process.stdout.isTTY || (ci && ci !== 'false' && ci !== '0')) {
203+
const status = config.auth?.token ? 'Your Autohand sign-in has expired.' : 'Not signed in.';
204+
console.error(chalk.red(`${status} Run \`autohand login\`, or in CI set AUTOHAND_API_KEY and add --bare.`));
205+
console.error('CI sign-in: https://docs.autohand.ai/guides/ci-cd-automation');
206+
process.exit(1);
207+
}
227208
// Show modal with logo and login/exit options
228209
if (process.stdout.isTTY) {
229210
const commit = await getGitCommit();

‎src/billing/planSummary.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ export interface PlanSummary {
1717

1818
const TIER_LABELS: Record<string, string> = {
1919
free: 'Free',
20+
lite: 'Lite',
2021
pro: 'Pro',
22+
pro_plus: 'Pro+',
2123
max: 'Max',
2224
team: 'Team',
2325
enterprise: 'Enterprise',
@@ -66,13 +68,15 @@ export function formatComposerPlanLabel(plan: PlanSummary | null | undefined): s
6668
return plan.tier === 'team' ? plan.accountName || plan.label : plan.label;
6769
}
6870

69-
export type UpgradeTarget = 'pro' | 'max' | 'team';
71+
export type UpgradeTarget = 'lite' | 'pro' | 'pro_plus' | 'max' | 'team';
7072

7173
/** Self-serve tiers in purchase order. Team and enterprise are managed in billing. */
72-
const PLAN_LADDER: ReadonlyArray<'free' | UpgradeTarget> = ['free', 'pro', 'max', 'team'];
74+
const PLAN_LADDER: ReadonlyArray<'free' | UpgradeTarget> = ['free', 'lite', 'pro', 'pro_plus', 'max', 'team'];
7375

7476
/** Next paid tier for a self-serve plan; null for team, enterprise and unknown tiers. */
7577
export function nextPlanTier(tier: string | undefined): UpgradeTarget | null {
78+
// Keep Free's existing destination until the separate Q-0018 decision.
79+
if (tier === 'free') return 'pro';
7680
const index = PLAN_LADDER.indexOf(tier as 'free' | UpgradeTarget);
7781
if (index < 0) return null;
7882
return (PLAN_LADDER[index + 1] as UpgradeTarget | undefined) ?? null;

‎src/commands/settings.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,6 @@ export const SETTINGS_REGISTRY: SettingDef[] = [
209209
// Auto-mode
210210
{ key: 'automode.maxIterations', labelKey: 'commands.settings.automode.maxIterations', descriptionKey: 'commands.settings.automode.maxIterationsDesc', category: 'automode', type: 'number', defaultValue: 50 },
211211
{ key: 'automode.maxRuntime', labelKey: 'commands.settings.automode.maxRuntime', descriptionKey: 'commands.settings.automode.maxRuntimeDesc', category: 'automode', type: 'number', defaultValue: 120 },
212-
{ key: 'automode.maxCost', labelKey: 'commands.settings.automode.maxCost', descriptionKey: 'commands.settings.automode.maxCostDesc', category: 'automode', type: 'number', defaultValue: 10 },
213212
{ key: 'automode.checkpointInterval', labelKey: 'commands.settings.automode.checkpointInterval', descriptionKey: 'commands.settings.automode.checkpointIntervalDesc', category: 'automode', type: 'number', defaultValue: 5 },
214213
{ key: 'automode.useWorktree', labelKey: 'commands.settings.automode.useWorktree', descriptionKey: 'commands.settings.automode.useWorktreeDesc', category: 'automode', type: 'boolean', defaultValue: true },
215214

0 commit comments

Comments
 (0)