-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathopencode.rs
More file actions
65 lines (58 loc) · 2.59 KB
/
opencode.rs
File metadata and controls
65 lines (58 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//! OpenCode `HarnessAdapter` — Rust port of `packages/cli/src/harnesses/opencode.ts`.
//!
//! OpenCode shares the pending-stamp + watch-loop shape with codex, so the
//! adapter is constructed via [`super::pending_stamp::session_store_adapter`]
//! instead of re-implementing the trait. The only opencode-specific bits are:
//!
//! * `name = "opencode"` — the dispatch key and log-line label.
//! * `session_root` — `$HOME/.local/share/opencode/storage/session`,
//! resolved lazily so tests that override `$HOME` see the override.
//! Mirrors the TS sibling's `path.join(homedir(), '.local', 'share',
//! 'opencode', 'storage', 'session')` exactly.
//! * `ingest_sessions` — defers to
//! [`relayburn_sdk::ingest_opencode_sessions`], the opencode-only ingest
//! pass. The factory opens a fresh ledger handle per call (mirrors the
//! TS lock-then-write-then-close shape; SQLite WAL keeps the per-tick
//! open cheap). The SDK verb is sync, so we pass it directly as a fn
//! pointer to [`pending_stamp::session_store_adapter`].
use std::path::PathBuf;
use relayburn_sdk::ingest_opencode_sessions;
use super::pending_stamp;
use super::HarnessAdapter;
use crate::util::home::home_dir;
/// `$HOME/.local/share/opencode/storage/session`. Mirrors the TS sibling
/// and the SDK's internal `opencode_sessions_dir` default.
fn opencode_sessions_dir() -> PathBuf {
home_dir()
.join(".local")
.join("share")
.join("opencode")
.join("storage")
.join("session")
}
/// Hand out a `&'static dyn HarnessAdapter` for opencode. The registry
/// calls this once at lazy-init time. See
/// [`pending_stamp::session_store_adapter`] for the leak semantics.
pub fn adapter() -> &'static dyn HarnessAdapter {
pending_stamp::session_store_adapter("opencode", opencode_sessions_dir, ingest_opencode_sessions)
}
#[cfg(test)]
mod tests {
use super::*;
use crate::harnesses::test_env::with_test_home;
/// `adapter()` round-trips through the trait surface — name, session
/// root, and the `&'static` lifetime the registry requires. Mirrors
/// the registry's `pending_stamp_adapter_static_fits_runtime_registry`
/// check, but pinned to the opencode configuration specifically.
#[test]
fn adapter_round_trip() {
let a: &'static dyn HarnessAdapter = adapter();
assert_eq!(a.name(), "opencode");
with_test_home("/tmp/burn-opencode-test-home", || {
assert_eq!(
a.session_root(),
PathBuf::from("/tmp/burn-opencode-test-home/.local/share/opencode/storage/session")
);
});
}
}