Fix stale review flag healing and prevent concurrent state overwrites
Use already-loaded state in list command instead of re-reading. In review command, patch in_review on fresh state to avoid clobbering concurrent changes, and skip worktree save in print mode. Remove unused white import and unnecessary nullish coalescing fallback. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
99f5a378f1
commit
2f524da292
|
|
@ -2,7 +2,7 @@ import { homedir } from "os"
|
||||||
import * as git from "../git.ts"
|
import * as git from "../git.ts"
|
||||||
import * as vm from "../vm.ts"
|
import * as vm from "../vm.ts"
|
||||||
import * as state from "../state.ts"
|
import * as state from "../state.ts"
|
||||||
import { reset, dim, bold, green, yellow, cyan, magenta, white, red } from "../fmt.ts"
|
import { reset, dim, bold, green, yellow, cyan, magenta, red } from "../fmt.ts"
|
||||||
|
|
||||||
export async function action(opts: { json?: boolean }) {
|
export async function action(opts: { json?: boolean }) {
|
||||||
const root = await git.repoRoot()
|
const root = await git.repoRoot()
|
||||||
|
|
@ -62,13 +62,7 @@ export async function action(opts: { json?: boolean }) {
|
||||||
// Batch self-heal stale in_review flags with a single state write
|
// Batch self-heal stale in_review flags with a single state write
|
||||||
if (staleReviewSessions.length > 0) {
|
if (staleReviewSessions.length > 0) {
|
||||||
for (const s of staleReviewSessions) s.in_review = false
|
for (const s of staleReviewSessions) s.in_review = false
|
||||||
const current = await state.load(root).catch(() => null)
|
await state.save(root, st).catch(() => {})
|
||||||
if (current) {
|
|
||||||
for (const s of staleReviewSessions) {
|
|
||||||
if (current.sessions[s.branch]) current.sessions[s.branch].in_review = false
|
|
||||||
}
|
|
||||||
await state.save(root, current).catch(() => {})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opts.json) {
|
if (opts.json) {
|
||||||
|
|
@ -93,7 +87,7 @@ export async function action(opts: { json?: boolean }) {
|
||||||
for (const s of sessions) {
|
for (const s of sessions) {
|
||||||
const prompt = (s.prompt ?? "").split("\n")[0]
|
const prompt = (s.prompt ?? "").split("\n")[0]
|
||||||
const status = statuses[s.branch] ?? "idle"
|
const status = statuses[s.branch] ?? "idle"
|
||||||
const { icon, color: bc } = styles[status] ?? styles.idle
|
const { icon, color: bc } = styles[status]
|
||||||
const maxPrompt = cols - prefixWidth
|
const maxPrompt = cols - prefixWidth
|
||||||
const truncated = maxPrompt > 3 && prompt.length > maxPrompt ? prompt.slice(0, maxPrompt - 3) + "..." : prompt
|
const truncated = maxPrompt > 3 && prompt.length > maxPrompt ? prompt.slice(0, maxPrompt - 3) + "..." : prompt
|
||||||
console.log(`${icon} ${bc}${s.branch.padEnd(branchWidth)}${reset} ${dim}${truncated}${reset}`)
|
console.log(`${icon} ${bc}${s.branch.padEnd(branchWidth)}${reset} ${dim}${truncated}${reset}`)
|
||||||
|
|
|
||||||
|
|
@ -82,9 +82,14 @@ Your thoughts, in brief.
|
||||||
await vm.claude(session.worktree, { prompt })
|
await vm.claude(session.worktree, { prompt })
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
// Always attempt save and clear review state
|
spin.stop()
|
||||||
await saveChanges(session.worktree, session.branch).catch(() => {})
|
// Save worktree changes only in interactive mode
|
||||||
session.in_review = false
|
if (!opts.print) await saveChanges(session.worktree, session.branch).catch(() => {})
|
||||||
await state.setSession(root, session).catch(() => {})
|
// Patch only in_review on fresh state to avoid overwriting concurrent changes
|
||||||
|
const current = await state.load(root).catch(() => null)
|
||||||
|
if (current?.sessions[session.branch]) {
|
||||||
|
current.sessions[session.branch].in_review = false
|
||||||
|
await state.save(root, current).catch(() => {})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user