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
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,11 @@ struct ClaudeReader: AgentHarnessReader {
// A subagent's prompts and tool output never open a turn, and its
// tool output can be large: no need to decode it to know that.
if AgentLogParser.contains(line, #""isSidechain":true"#) { return [] }
// Claude Code compacts an idle session on its own, writing the summary
// as a user line that no reply follows; it begins no work.
guard let json = AgentLogParser.object(line), json["type"] as? String == "user",
json["isMeta"] as? Bool != true, json["isSidechain"] as? Bool != true else { return [] }
json["isMeta"] as? Bool != true, json["isSidechain"] as? Bool != true,
json["isCompactSummary"] as? Bool != true else { return [] }
adopt(json, into: &state)
state.turnOpen = true
state.runningCommands = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ struct ClaudeTranscriptReader {
if json["toolEndsTurn"] as? Bool == true { facts.append(.turnEnded(date, completed: true)) }
break
}
guard json["isMeta"] as? Bool != true else { break }
// The summary an idle compaction writes is no prompt and begins no turn.
guard json["isMeta"] as? Bool != true, json["isCompactSummary"] as? Bool != true else { break }
let texts = (content as? String).map { [$0] }
?? blocks.compactMap { $0["type"] as? String == "text" ? $0["text"] as? String : nil }
if texts.contains(where: { $0.hasPrefix("[Request interrupted by user") || $0.hasPrefix("<local-command-std") }) {
Expand Down
2 changes: 2 additions & 0 deletions Tests/ClaudeSessionReaderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ enum ClaudeSessionReaderTests {
default: return nil
}
}
suite.expect(!parse([summary], previews: false).contains { if case .turnBegan = $0 { return true }; return false },
"an idle compaction's summary begins no turn")
suite.expect(said.first == "Also run lint" && said.count == 2,
"a prompt typed while Claude works counts; summaries and commands do not: \(said.map { $0.prefix(20) })")
suite.expect(said.last?.count == ClaudeTranscriptReader.replyLimit && said.last?.hasSuffix("…") == true,
Expand Down
4 changes: 4 additions & 0 deletions Tests/HarnessReaderContractTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ enum HarnessReaderContractTests {
let now = Date(timeIntervalSince1970: 0)
var state = AgentLogState()
let reader = AgentProvider.claude.reader
var idle = AgentLogState()
let compacted = line(#"{"type":"user","isCompactSummary":true,"timestamp":1790087000,"sessionId":"s","message":{"content":"This session is being continued from a previous conversation"}}"#)
suite.expect(reader.parse(compacted, state: &idle, now: now).isEmpty && !idle.turnOpen,
"the summary Claude Code writes when it compacts an idle session begins no work")
let began = Date(timeIntervalSince1970: 1_790_088_000)
let prompt = line(#"{"type":"user","timestamp":1790088000,"sessionId":"s","cwd":"/Users/me/code/app","message":{"content":"work"}}"#)
suite.expect(reader.parse(prompt, state: &state, now: now) == [.turnBegan(began)],
Expand Down
Loading