Debug menu: session controls and thinking/verbose

This commit is contained in:
Peter Steinberger
2025-12-09 21:32:21 +01:00
parent ad5c7d97ca
commit f34b238713
3 changed files with 120 additions and 1 deletions

View File

@@ -4,6 +4,7 @@ import SwiftUI
enum DebugActions {
private static let verboseDefaultsKey = "clawdis.debug.verboseMain"
private static let sessionMenuLimit = 12
@MainActor
static func openAgentEventsWindow() {
@@ -183,6 +184,72 @@ enum DebugActions {
}
return path
}
// MARK: - Sessions (thinking / verbose)
static func recentSessions(limit: Int = sessionMenuLimit) async -> [SessionRow] {
let hints = SessionLoader.configHints()
let store = SessionLoader.resolveStorePath(override: hints.storePath)
let defaults = SessionDefaults(
model: hints.model ?? SessionLoader.fallbackModel,
contextTokens: hints.contextTokens ?? SessionLoader.fallbackContextTokens)
guard let rows = try? await SessionLoader.loadRows(at: store, defaults: defaults) else { return [] }
return Array(rows.prefix(limit))
}
static func updateSession(
key: String,
thinking: String?,
verbose: String?) async throws
{
let hints = SessionLoader.configHints()
let store = SessionLoader.resolveStorePath(override: hints.storePath)
let url = URL(fileURLWithPath: store)
guard FileManager.default.fileExists(atPath: store) else {
throw DebugActionError.message("Session store missing at \(store)")
}
let data = try Data(contentsOf: url)
var decoded = try JSONDecoder().decode([String: SessionEntryRecord].self, from: data)
var entry = decoded[key] ?? SessionEntryRecord(
sessionId: nil,
updatedAt: Date().timeIntervalSince1970 * 1000,
systemSent: nil,
abortedLastRun: nil,
thinkingLevel: nil,
verboseLevel: nil,
inputTokens: nil,
outputTokens: nil,
totalTokens: nil,
model: nil,
contextTokens: nil)
entry = SessionEntryRecord(
sessionId: entry.sessionId,
updatedAt: Date().timeIntervalSince1970 * 1000,
systemSent: entry.systemSent,
abortedLastRun: entry.abortedLastRun,
thinkingLevel: thinking,
verboseLevel: verbose,
inputTokens: entry.inputTokens,
outputTokens: entry.outputTokens,
totalTokens: entry.totalTokens,
model: entry.model,
contextTokens: entry.contextTokens)
decoded[key] = entry
let encoded = try JSONEncoder().encode(decoded)
try encoded.write(to: url, options: [.atomic])
}
@MainActor
static func openSessionStoreInCode() {
let path = SessionLoader.defaultStorePath
let proc = Process()
proc.launchPath = "/usr/bin/env"
proc.arguments = ["code", path]
try? proc.run()
}
}
enum DebugActionError: LocalizedError {