mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-10 20:46:09 +00:00
* feat: add session thread management Squash of codex/thread-management (025aefc3ad1) onto origin/main: pin/archive/rename sessions via sessions.patch, archived-aware sessions.list, lifecycle fencing, read-only archived chat, SDK + Swift protocol support, Control UI session management. * refactor(ui): minimal session rows with hover-revealed management Chat picker and sidebar recents share session-row primitives: single-line rows, relative timestamps, rename/archive/pin revealed on hover or focus, accent pin badge for pinned rows, and an active-run spinner in the trail slot. Sidebar floats pinned sessions above recency via the shared comparator and gains archive/pin actions through the unified sessions-view patch fallback. Archive eligibility is one shared policy (canArchiveSessionRow); the sidebar/picker active-run tooltip now uses the real sessionsView.activeRun locale key. * fix: align session admission with mailbox-era main Integration fixes after rebasing onto current main: sessions_list mailbox test expectations learn the archived/pinned row fields and archived:false list param; gateway agent admission treats a session as deleted only when both the requested and canonical alias sets miss it (legacy bare-main stores and exec-approval followups read under different spellings); cron persist tests keep a consistent store across claim-guarded persist calls; the ACP abort hook test asserts abort propagation instead of signal identity; drop dead lifecycle writes flagged by no-useless-assignment and fix the promise-executor return in the codex compact test. * fix(qa): align UI e2e and shard fixtures with redesigned session rows Sidebar session rows are wrapper divs with an inner link now: update the navigation browser tests and chat-flow Playwright selectors. Seed a real per-test session store for the auto-fallback admission guard instead of depending on leftover host files at /tmp/sessions.json. Teach the test-projects routing fixture about the suites that newly import the shared temp-dir helper. Document the Codex thread-format contract for archivedAt/pinnedAt (flag derived from server-stamped timestamp, epoch ms here vs Codex epoch seconds) at the type and in the session docs. * test: route auto-fallback suite through temp-dir helper plans The auto-fallback suite now imports the shared temp-dir helper for its seeded session store, so the top-level helper routing fixture must list it in the auto-reply plan.
96 lines
3.3 KiB
Swift
96 lines
3.3 KiB
Swift
import AppKit
|
|
import Foundation
|
|
import OpenClawKit
|
|
|
|
enum SessionActions {
|
|
static func patchSession(
|
|
key: String,
|
|
thinking: String?? = nil,
|
|
verbose: String?? = nil) async throws
|
|
{
|
|
var params: [String: AnyHashable] = ["key": AnyHashable(key)]
|
|
|
|
if let thinking {
|
|
params["thinkingLevel"] = thinking.map(AnyHashable.init) ?? AnyHashable(NSNull())
|
|
}
|
|
if let verbose {
|
|
params["verboseLevel"] = verbose.map(AnyHashable.init) ?? AnyHashable(NSNull())
|
|
}
|
|
|
|
_ = try await ControlChannel.shared.request(method: "sessions.patch", params: params)
|
|
}
|
|
|
|
static func resetSession(key: String) async throws {
|
|
_ = try await ControlChannel.shared.request(
|
|
method: "sessions.reset",
|
|
params: ["key": AnyHashable(key)])
|
|
}
|
|
|
|
static func deleteSession(key: String) async throws {
|
|
_ = try await ControlChannel.shared.request(
|
|
method: "sessions.delete",
|
|
params: ["key": AnyHashable(key), "deleteTranscript": AnyHashable(true)])
|
|
}
|
|
|
|
static func compactSession(key: String, maxLines: Int = 400) async throws {
|
|
let response = try await ControlChannel.shared.request(
|
|
method: "sessions.compact",
|
|
params: ["key": AnyHashable(key), "maxLines": AnyHashable(maxLines)],
|
|
timeoutMs: 0,
|
|
retryTransportFailures: false)
|
|
try OpenClawSessionsCompactResponse.requireSuccess(from: response)
|
|
}
|
|
|
|
@MainActor
|
|
static func confirmDestructiveAction(title: String, message: String, action: String) -> Bool {
|
|
let alert = NSAlert()
|
|
alert.messageText = title
|
|
alert.informativeText = message
|
|
alert.addButton(withTitle: action)
|
|
alert.addButton(withTitle: "Cancel")
|
|
alert.alertStyle = .warning
|
|
return alert.runModal() == .alertFirstButtonReturn
|
|
}
|
|
|
|
@MainActor
|
|
static func presentError(title: String, error: Error) {
|
|
let alert = NSAlert()
|
|
alert.messageText = title
|
|
alert.informativeText = (error as? LocalizedError)?.errorDescription ?? error.localizedDescription
|
|
alert.addButton(withTitle: "OK")
|
|
alert.alertStyle = .warning
|
|
alert.runModal()
|
|
}
|
|
|
|
@MainActor
|
|
static func openSessionLogInCode(sessionId: String, storePath: String?) {
|
|
let candidates: [URL] = {
|
|
var urls: [URL] = []
|
|
if let storePath, !storePath.isEmpty {
|
|
let dir = URL(fileURLWithPath: storePath).deletingLastPathComponent()
|
|
urls.append(dir.appendingPathComponent("\(sessionId).jsonl"))
|
|
}
|
|
urls.append(OpenClawPaths.stateDirURL.appendingPathComponent("sessions/\(sessionId).jsonl"))
|
|
return urls
|
|
}()
|
|
|
|
let existing = candidates.first(where: { FileManager().fileExists(atPath: $0.path) })
|
|
guard let url = existing else {
|
|
let alert = NSAlert()
|
|
alert.messageText = "Session log not found"
|
|
alert.informativeText = sessionId
|
|
alert.runModal()
|
|
return
|
|
}
|
|
|
|
let proc = Process()
|
|
proc.launchPath = "/usr/bin/env"
|
|
proc.arguments = ["code", url.path]
|
|
if (try? proc.run()) != nil {
|
|
return
|
|
}
|
|
|
|
NSWorkspace.shared.activateFileViewerSelecting([url])
|
|
}
|
|
}
|