oh-my-codex 0.21.48 → 0.22.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Cargo.lock +6 -6
- package/Cargo.toml +1 -1
- package/README.md +15 -0
- package/crates/omx-mux/src/herdr.rs +481 -0
- package/crates/omx-mux/src/lib.rs +5 -0
- package/dist/cli/__tests__/plugin-cache-live-pin-3790.test.js +104 -3
- package/dist/cli/__tests__/plugin-cache-live-pin-3790.test.js.map +1 -1
- package/dist/cli/__tests__/question.test.js +33 -0
- package/dist/cli/__tests__/question.test.js.map +1 -1
- package/dist/cli/__tests__/session-compare.test.d.ts +2 -0
- package/dist/cli/__tests__/session-compare.test.d.ts.map +1 -0
- package/dist/cli/__tests__/session-compare.test.js +183 -0
- package/dist/cli/__tests__/session-compare.test.js.map +1 -0
- package/dist/cli/__tests__/team.test.js +8 -0
- package/dist/cli/__tests__/team.test.js.map +1 -1
- package/dist/cli/plugin-marketplace.d.ts.map +1 -1
- package/dist/cli/plugin-marketplace.js +11 -4
- package/dist/cli/plugin-marketplace.js.map +1 -1
- package/dist/cli/question.d.ts.map +1 -1
- package/dist/cli/question.js +8 -1
- package/dist/cli/question.js.map +1 -1
- package/dist/cli/session-compare.d.ts +11 -0
- package/dist/cli/session-compare.d.ts.map +1 -0
- package/dist/cli/session-compare.js +172 -0
- package/dist/cli/session-compare.js.map +1 -0
- package/dist/cli/session-search.d.ts.map +1 -1
- package/dist/cli/session-search.js +7 -0
- package/dist/cli/session-search.js.map +1 -1
- package/dist/cli/team.d.ts.map +1 -1
- package/dist/cli/team.js +2 -0
- package/dist/cli/team.js.map +1 -1
- package/dist/config/__tests__/multiplexer.test.d.ts +2 -0
- package/dist/config/__tests__/multiplexer.test.d.ts.map +1 -0
- package/dist/config/__tests__/multiplexer.test.js +118 -0
- package/dist/config/__tests__/multiplexer.test.js.map +1 -0
- package/dist/config/multiplexer.d.ts +29 -0
- package/dist/config/multiplexer.d.ts.map +1 -0
- package/dist/config/multiplexer.js +91 -0
- package/dist/config/multiplexer.js.map +1 -0
- package/dist/question/__tests__/ui.test.js +40 -1
- package/dist/question/__tests__/ui.test.js.map +1 -1
- package/dist/question/ui.d.ts.map +1 -1
- package/dist/question/ui.js +37 -7
- package/dist/question/ui.js.map +1 -1
- package/dist/scripts/__tests__/codex-native-hook.test.js +281 -1
- package/dist/scripts/__tests__/codex-native-hook.test.js.map +1 -1
- package/dist/scripts/codex-native-hook.d.ts.map +1 -1
- package/dist/scripts/codex-native-hook.js +8 -2
- package/dist/scripts/codex-native-hook.js.map +1 -1
- package/dist/scripts/notify-hook/team-worker-lease.d.ts +15 -0
- package/dist/scripts/notify-hook/team-worker-lease.d.ts.map +1 -0
- package/dist/scripts/notify-hook/team-worker-lease.js +63 -0
- package/dist/scripts/notify-hook/team-worker-lease.js.map +1 -0
- package/dist/scripts/notify-hook/team-worker-posttooluse.d.ts +1 -0
- package/dist/scripts/notify-hook/team-worker-posttooluse.d.ts.map +1 -1
- package/dist/scripts/notify-hook/team-worker-posttooluse.js +16 -5
- package/dist/scripts/notify-hook/team-worker-posttooluse.js.map +1 -1
- package/dist/scripts/notify-hook/team-worker.d.ts +12 -1
- package/dist/scripts/notify-hook/team-worker.d.ts.map +1 -1
- package/dist/scripts/notify-hook/team-worker.js +16 -4
- package/dist/scripts/notify-hook/team-worker.js.map +1 -1
- package/dist/session-history/__tests__/compare.test.d.ts +2 -0
- package/dist/session-history/__tests__/compare.test.d.ts.map +1 -0
- package/dist/session-history/__tests__/compare.test.js +257 -0
- package/dist/session-history/__tests__/compare.test.js.map +1 -0
- package/dist/session-history/compare.d.ts +74 -0
- package/dist/session-history/compare.d.ts.map +1 -0
- package/dist/session-history/compare.js +165 -0
- package/dist/session-history/compare.js.map +1 -0
- package/dist/team/__tests__/api-interop.test.js +3 -3
- package/dist/team/__tests__/completion-evidence.test.js +31 -1
- package/dist/team/__tests__/completion-evidence.test.js.map +1 -1
- package/dist/team/__tests__/cross-rebase-smoke.test.js +263 -31
- package/dist/team/__tests__/cross-rebase-smoke.test.js.map +1 -1
- package/dist/team/__tests__/herdr-session-realherdr.test.d.ts +2 -0
- package/dist/team/__tests__/herdr-session-realherdr.test.d.ts.map +1 -0
- package/dist/team/__tests__/herdr-session-realherdr.test.js +68 -0
- package/dist/team/__tests__/herdr-session-realherdr.test.js.map +1 -0
- package/dist/team/__tests__/herdr-session.test.d.ts +2 -0
- package/dist/team/__tests__/herdr-session.test.d.ts.map +1 -0
- package/dist/team/__tests__/herdr-session.test.js +228 -0
- package/dist/team/__tests__/herdr-session.test.js.map +1 -0
- package/dist/team/__tests__/hook-primary-e2e-contract.test.js +9 -3
- package/dist/team/__tests__/hook-primary-e2e-contract.test.js.map +1 -1
- package/dist/team/__tests__/idle-nudge.test.js +84 -0
- package/dist/team/__tests__/idle-nudge.test.js.map +1 -1
- package/dist/team/__tests__/mcp-comm.test.js +25 -1
- package/dist/team/__tests__/mcp-comm.test.js.map +1 -1
- package/dist/team/__tests__/rebalance-policy.test.js +27 -9
- package/dist/team/__tests__/rebalance-policy.test.js.map +1 -1
- package/dist/team/__tests__/runtime-delivery.test.d.ts +2 -0
- package/dist/team/__tests__/runtime-delivery.test.d.ts.map +1 -0
- package/dist/team/__tests__/runtime-delivery.test.js +570 -0
- package/dist/team/__tests__/runtime-delivery.test.js.map +1 -0
- package/dist/team/__tests__/runtime.test.js +938 -70
- package/dist/team/__tests__/runtime.test.js.map +1 -1
- package/dist/team/__tests__/scaling.test.js +645 -1
- package/dist/team/__tests__/scaling.test.js.map +1 -1
- package/dist/team/__tests__/state-renewal.test.d.ts +2 -0
- package/dist/team/__tests__/state-renewal.test.d.ts.map +1 -0
- package/dist/team/__tests__/state-renewal.test.js +555 -0
- package/dist/team/__tests__/state-renewal.test.js.map +1 -0
- package/dist/team/__tests__/state.test.js +121 -2
- package/dist/team/__tests__/state.test.js.map +1 -1
- package/dist/team/__tests__/task-lease.test.d.ts +2 -0
- package/dist/team/__tests__/task-lease.test.d.ts.map +1 -0
- package/dist/team/__tests__/task-lease.test.js +179 -0
- package/dist/team/__tests__/task-lease.test.js.map +1 -0
- package/dist/team/__tests__/team-ops-contract.test.js +1 -0
- package/dist/team/__tests__/team-ops-contract.test.js.map +1 -1
- package/dist/team/__tests__/worker-bootstrap.test.js +2 -0
- package/dist/team/__tests__/worker-bootstrap.test.js.map +1 -1
- package/dist/team/api-interop.d.ts +1 -1
- package/dist/team/api-interop.d.ts.map +1 -1
- package/dist/team/api-interop.js +13 -1
- package/dist/team/api-interop.js.map +1 -1
- package/dist/team/completion-evidence.d.ts +1 -1
- package/dist/team/completion-evidence.d.ts.map +1 -1
- package/dist/team/completion-evidence.js +9 -0
- package/dist/team/completion-evidence.js.map +1 -1
- package/dist/team/goal-workflow.js +1 -1
- package/dist/team/herdr-session.d.ts +234 -0
- package/dist/team/herdr-session.d.ts.map +1 -0
- package/dist/team/herdr-session.js +489 -0
- package/dist/team/herdr-session.js.map +1 -0
- package/dist/team/idle-nudge.d.ts +16 -4
- package/dist/team/idle-nudge.d.ts.map +1 -1
- package/dist/team/idle-nudge.js +51 -19
- package/dist/team/idle-nudge.js.map +1 -1
- package/dist/team/mcp-comm.d.ts +6 -4
- package/dist/team/mcp-comm.d.ts.map +1 -1
- package/dist/team/mcp-comm.js +4 -0
- package/dist/team/mcp-comm.js.map +1 -1
- package/dist/team/rebalance-policy.d.ts.map +1 -1
- package/dist/team/rebalance-policy.js +5 -2
- package/dist/team/rebalance-policy.js.map +1 -1
- package/dist/team/runtime.d.ts.map +1 -1
- package/dist/team/runtime.js +463 -166
- package/dist/team/runtime.js.map +1 -1
- package/dist/team/scaling.d.ts +3 -3
- package/dist/team/scaling.d.ts.map +1 -1
- package/dist/team/scaling.js +394 -200
- package/dist/team/scaling.js.map +1 -1
- package/dist/team/state/monitor.d.ts +3 -0
- package/dist/team/state/monitor.d.ts.map +1 -1
- package/dist/team/state/monitor.js +3 -0
- package/dist/team/state/monitor.js.map +1 -1
- package/dist/team/state/tasks.d.ts +4 -1
- package/dist/team/state/tasks.d.ts.map +1 -1
- package/dist/team/state/tasks.js +36 -5
- package/dist/team/state/tasks.js.map +1 -1
- package/dist/team/state/types.d.ts +9 -0
- package/dist/team/state/types.d.ts.map +1 -1
- package/dist/team/state/types.js.map +1 -1
- package/dist/team/state.d.ts +15 -2
- package/dist/team/state.d.ts.map +1 -1
- package/dist/team/state.js +73 -5
- package/dist/team/state.js.map +1 -1
- package/dist/team/task-lease.d.ts +4 -0
- package/dist/team/task-lease.d.ts.map +1 -0
- package/dist/team/task-lease.js +74 -0
- package/dist/team/task-lease.js.map +1 -0
- package/dist/team/team-ops.d.ts +2 -1
- package/dist/team/team-ops.d.ts.map +1 -1
- package/dist/team/team-ops.js +1 -0
- package/dist/team/team-ops.js.map +1 -1
- package/dist/team/tmux-session.d.ts +1 -1
- package/dist/team/tmux-session.d.ts.map +1 -1
- package/dist/team/tmux-session.js +10 -2
- package/dist/team/tmux-session.js.map +1 -1
- package/dist/team/worker-bootstrap.d.ts.map +1 -1
- package/dist/team/worker-bootstrap.js +16 -3
- package/dist/team/worker-bootstrap.js.map +1 -1
- package/package.json +1 -1
- package/plugins/oh-my-codex/.codex-plugin/plugin.json +1 -1
- package/plugins/oh-my-codex/hooks/codex-native-hook.mjs +4 -1
- package/plugins/oh-my-codex/skills/worker/SKILL.md +7 -1
- package/skills/worker/SKILL.md +7 -1
- package/src/scripts/__tests__/codex-native-hook.test.ts +279 -0
- package/src/scripts/codex-native-hook.ts +8 -2
- package/src/scripts/notify-hook/team-worker-lease.ts +69 -0
- package/src/scripts/notify-hook/team-worker-posttooluse.ts +16 -4
- package/src/scripts/notify-hook/team-worker.ts +15 -4
package/Cargo.lock
CHANGED
|
@@ -32,7 +32,7 @@ checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
|
|
|
32
32
|
|
|
33
33
|
[[package]]
|
|
34
34
|
name = "omx-api"
|
|
35
|
-
version = "0.
|
|
35
|
+
version = "0.22.1"
|
|
36
36
|
dependencies = [
|
|
37
37
|
"serde",
|
|
38
38
|
"serde_json",
|
|
@@ -40,14 +40,14 @@ dependencies = [
|
|
|
40
40
|
|
|
41
41
|
[[package]]
|
|
42
42
|
name = "omx-explore-harness"
|
|
43
|
-
version = "0.
|
|
43
|
+
version = "0.22.1"
|
|
44
44
|
dependencies = [
|
|
45
45
|
"libc",
|
|
46
46
|
]
|
|
47
47
|
|
|
48
48
|
[[package]]
|
|
49
49
|
name = "omx-mux"
|
|
50
|
-
version = "0.
|
|
50
|
+
version = "0.22.1"
|
|
51
51
|
dependencies = [
|
|
52
52
|
"serde",
|
|
53
53
|
"serde_json",
|
|
@@ -55,7 +55,7 @@ dependencies = [
|
|
|
55
55
|
|
|
56
56
|
[[package]]
|
|
57
57
|
name = "omx-runtime"
|
|
58
|
-
version = "0.
|
|
58
|
+
version = "0.22.1"
|
|
59
59
|
dependencies = [
|
|
60
60
|
"fs2",
|
|
61
61
|
"libc",
|
|
@@ -67,7 +67,7 @@ dependencies = [
|
|
|
67
67
|
|
|
68
68
|
[[package]]
|
|
69
69
|
name = "omx-runtime-core"
|
|
70
|
-
version = "0.
|
|
70
|
+
version = "0.22.1"
|
|
71
71
|
dependencies = [
|
|
72
72
|
"fs2",
|
|
73
73
|
"serde",
|
|
@@ -76,7 +76,7 @@ dependencies = [
|
|
|
76
76
|
|
|
77
77
|
[[package]]
|
|
78
78
|
name = "omx-sparkshell"
|
|
79
|
-
version = "0.
|
|
79
|
+
version = "0.22.1"
|
|
80
80
|
dependencies = [
|
|
81
81
|
"omx-mux",
|
|
82
82
|
]
|
package/Cargo.toml
CHANGED
package/README.md
CHANGED
|
@@ -395,6 +395,21 @@ Unknown durations remain unknown, and a recorded result without an explicit erro
|
|
|
395
395
|
does not prove success. See [session timeline](./docs/session-timeline.md) for
|
|
396
396
|
supported records, status meanings, and examples.
|
|
397
397
|
|
|
398
|
+
### Compare two sessions
|
|
399
|
+
|
|
400
|
+
Use `omx session compare <baseline-id> <candidate-id>` to compare execution counts,
|
|
401
|
+
explicit failures, and namespace-aware tool timing after a workflow change.
|
|
402
|
+
The report distinguishes added and removed tools, preserves unknown measurements,
|
|
403
|
+
and reports absolute and percentage changes. Use `--sort duration` to find the
|
|
404
|
+
largest mean-latency increases, or `--json --output comparison.json` to save a report.
|
|
405
|
+
|
|
406
|
+
For automation, `--fail-on-regression` exits 2 on observed regressions and 3 on
|
|
407
|
+
inconclusive evidence. `--max-duration-increase 10` changes the default 20% mean
|
|
408
|
+
tool latency threshold; latency checks require complete timing coverage on both
|
|
409
|
+
sides. Display filters never change the whole-session assessment. Compare
|
|
410
|
+
similar workloads and see [session comparison](./docs/session-compare.md) for
|
|
411
|
+
cross-home selection, evidence gaps, and exit-code semantics.
|
|
412
|
+
|
|
398
413
|
### Team runtime
|
|
399
414
|
|
|
400
415
|
Use the team runtime when you specifically need durable tmux/worktree coordination, not as the default way to begin using OMX. In Codex App or plain outside-tmux sessions, treat `omx team` as a tmux-runtime shell surface rather than a directly available in-app workflow; launch OMX CLI from shell first if you actually want team execution.
|
|
@@ -0,0 +1,481 @@
|
|
|
1
|
+
use std::env;
|
|
2
|
+
use std::path::PathBuf;
|
|
3
|
+
use std::process::Command;
|
|
4
|
+
|
|
5
|
+
use serde::Deserialize;
|
|
6
|
+
|
|
7
|
+
use crate::types::{MuxAdapter, MuxError, MuxOperation, MuxOutcome, MuxTarget};
|
|
8
|
+
|
|
9
|
+
/// Herdr control commands answer a JSON envelope; errors are the same
|
|
10
|
+
/// envelope shape printed on stderr with a non-zero exit.
|
|
11
|
+
#[derive(Debug, Deserialize)]
|
|
12
|
+
struct HerdrEnvelope {
|
|
13
|
+
#[serde(default)]
|
|
14
|
+
result: Option<serde_json::Value>,
|
|
15
|
+
#[serde(default)]
|
|
16
|
+
error: Option<HerdrErrorEnvelope>,
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
#[derive(Debug, Deserialize)]
|
|
20
|
+
struct HerdrErrorEnvelope {
|
|
21
|
+
#[serde(default)]
|
|
22
|
+
code: Option<String>,
|
|
23
|
+
#[serde(default)]
|
|
24
|
+
message: Option<String>,
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/// Herdr pane ids are `wN:pM`; both segments run alphanumeric past 9
|
|
28
|
+
/// (`wA:pB`, ...). Unlike tmux `%N` ids they are never reused.
|
|
29
|
+
pub fn is_herdr_pane_id(handle: &str) -> bool {
|
|
30
|
+
let (workspace, pane) = match handle.split_once(':') {
|
|
31
|
+
Some(parts) => parts,
|
|
32
|
+
None => return false,
|
|
33
|
+
};
|
|
34
|
+
let workspace_body = workspace.strip_prefix('w').unwrap_or("");
|
|
35
|
+
let pane_body = pane.strip_prefix('p').unwrap_or("");
|
|
36
|
+
!workspace_body.is_empty()
|
|
37
|
+
&& !pane_body.is_empty()
|
|
38
|
+
&& workspace_body
|
|
39
|
+
.chars()
|
|
40
|
+
.chain(pane_body.chars())
|
|
41
|
+
.all(|ch| ch.is_ascii_alphanumeric())
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
fn env_herdr_binary() -> String {
|
|
45
|
+
// Same trust-pinning as the TypeScript backend (src/team/herdr-session.ts):
|
|
46
|
+
// HERDR_BIN_PATH wins only when it is an absolute path to an existing file.
|
|
47
|
+
match env::var("HERDR_BIN_PATH") {
|
|
48
|
+
Ok(pinned) if PathBuf::from(&pinned).is_absolute() && PathBuf::from(&pinned).is_file() => {
|
|
49
|
+
pinned
|
|
50
|
+
}
|
|
51
|
+
_ => "herdr".to_string(),
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/// Run a herdr command. Returns stdout on success; a non-zero exit decodes the
|
|
56
|
+
/// stderr error envelope into a typed AdapterFailed message.
|
|
57
|
+
fn run_herdr(bin: &str, args: &[&str]) -> Result<String, MuxError> {
|
|
58
|
+
let output = Command::new(bin)
|
|
59
|
+
.args(args)
|
|
60
|
+
.output()
|
|
61
|
+
.map_err(|e| MuxError::AdapterFailed(format!("failed to run herdr: {e}")))?;
|
|
62
|
+
|
|
63
|
+
if output.status.success() {
|
|
64
|
+
String::from_utf8(output.stdout)
|
|
65
|
+
.map_err(|e| MuxError::AdapterFailed(format!("invalid utf-8 from herdr: {e}")))
|
|
66
|
+
} else {
|
|
67
|
+
Err(herdr_command_error(&output.stderr, args))
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
fn herdr_command_error(stderr: &[u8], args: &[&str]) -> MuxError {
|
|
72
|
+
let stderr_text = String::from_utf8_lossy(stderr);
|
|
73
|
+
let detail = serde_json::from_str::<HerdrEnvelope>(stderr_text.trim())
|
|
74
|
+
.ok()
|
|
75
|
+
.and_then(|envelope| envelope.error)
|
|
76
|
+
.map(|error| {
|
|
77
|
+
format!(
|
|
78
|
+
"herdr_{}: {}",
|
|
79
|
+
error.code.as_deref().unwrap_or("error"),
|
|
80
|
+
error.message.as_deref().unwrap_or("herdr command failed")
|
|
81
|
+
)
|
|
82
|
+
})
|
|
83
|
+
.unwrap_or_else(|| stderr_text.trim().chars().take(300).collect());
|
|
84
|
+
MuxError::AdapterFailed(format!(
|
|
85
|
+
"herdr {} failed: {}",
|
|
86
|
+
args.first().unwrap_or(&""),
|
|
87
|
+
detail
|
|
88
|
+
))
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/// Run a herdr control command and return its `result` payload.
|
|
92
|
+
fn run_herdr_result(bin: &str, args: &[&str]) -> Result<serde_json::Value, MuxError> {
|
|
93
|
+
let stdout = run_herdr(bin, args)?;
|
|
94
|
+
let envelope = serde_json::from_str::<HerdrEnvelope>(stdout.trim())
|
|
95
|
+
.map_err(|e| MuxError::AdapterFailed(format!("herdr printed non-JSON output: {e}")))?;
|
|
96
|
+
if let Some(error) = envelope.error {
|
|
97
|
+
return Err(MuxError::AdapterFailed(format!(
|
|
98
|
+
"herdr_{}: {}",
|
|
99
|
+
error.code.as_deref().unwrap_or("error"),
|
|
100
|
+
error.message.as_deref().unwrap_or("herdr command failed")
|
|
101
|
+
)));
|
|
102
|
+
}
|
|
103
|
+
envelope.result.ok_or_else(|| {
|
|
104
|
+
MuxError::AdapterFailed(format!(
|
|
105
|
+
"herdr {} returned no result",
|
|
106
|
+
args.first().unwrap_or(&"")
|
|
107
|
+
))
|
|
108
|
+
})
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/// Extract a herdr target string from a `MuxTarget`.
|
|
112
|
+
fn resolve_target_handle(target: &MuxTarget) -> Result<String, MuxError> {
|
|
113
|
+
match target {
|
|
114
|
+
MuxTarget::DeliveryHandle(handle) => {
|
|
115
|
+
if handle.is_empty() {
|
|
116
|
+
Err(MuxError::InvalidTarget("empty delivery handle".into()))
|
|
117
|
+
} else if !is_herdr_pane_id(handle) {
|
|
118
|
+
Err(MuxError::InvalidTarget(format!(
|
|
119
|
+
"not a herdr pane id (expected wN:pM): {handle}"
|
|
120
|
+
)))
|
|
121
|
+
} else {
|
|
122
|
+
Ok(handle.clone())
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
MuxTarget::Detached => Err(MuxError::InvalidTarget(
|
|
126
|
+
"cannot operate on a detached target".into(),
|
|
127
|
+
)),
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/// Build the argument list for `herdr pane get` (existence proof).
|
|
132
|
+
pub fn build_pane_get_args(pane: &str) -> Vec<String> {
|
|
133
|
+
vec!["pane".into(), "get".into(), pane.into()]
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/// Build the argument list for `herdr agent prompt` (semantic submit).
|
|
137
|
+
pub fn build_agent_prompt_args(pane: &str, text: &str) -> Vec<String> {
|
|
138
|
+
vec!["agent".into(), "prompt".into(), pane.into(), text.into()]
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/// Build the argument list for `herdr pane read --source recent-unwrapped`.
|
|
142
|
+
pub fn build_pane_read_args(pane: &str, visible_lines: usize) -> Vec<String> {
|
|
143
|
+
vec![
|
|
144
|
+
"pane".into(),
|
|
145
|
+
"read".into(),
|
|
146
|
+
pane.into(),
|
|
147
|
+
"--source".into(),
|
|
148
|
+
"recent-unwrapped".into(),
|
|
149
|
+
"--lines".into(),
|
|
150
|
+
visible_lines.to_string(),
|
|
151
|
+
]
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/// Build the argument list for `herdr agent list` (liveness inventory).
|
|
155
|
+
pub fn build_agent_list_args() -> Vec<String> {
|
|
156
|
+
vec!["agent".into(), "list".into()]
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/// Build the argument list for `herdr agent attach`.
|
|
160
|
+
pub fn build_agent_attach_args(pane: &str) -> Vec<String> {
|
|
161
|
+
vec!["agent".into(), "attach".into(), pane.into()]
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/// Liveness from an `agent list` envelope: alive iff the pane hosts a live
|
|
165
|
+
/// agent (agent entries are cleared when the agent exits).
|
|
166
|
+
pub fn liveness_from_agent_list(list_json: &str, pane: &str) -> Result<bool, MuxError> {
|
|
167
|
+
let envelope = serde_json::from_str::<HerdrEnvelope>(list_json.trim())
|
|
168
|
+
.map_err(|e| MuxError::AdapterFailed(format!("herdr printed non-JSON output: {e}")))?;
|
|
169
|
+
let agents = envelope
|
|
170
|
+
.result
|
|
171
|
+
.and_then(|result| result.get("agents").cloned())
|
|
172
|
+
.and_then(|agents| agents.as_array().cloned())
|
|
173
|
+
.unwrap_or_default();
|
|
174
|
+
Ok(agents
|
|
175
|
+
.iter()
|
|
176
|
+
.any(|agent| agent.get("pane_id").and_then(|id| id.as_str()) == Some(pane)))
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/// MuxAdapter implementation shelling out to the `herdr` CLI (verified against
|
|
180
|
+
/// Herdr v0.9.5). Pane-addressed: SendInput goes through `agent prompt`
|
|
181
|
+
/// (submission-verified, honors bracketed paste), CaptureTail through
|
|
182
|
+
/// `pane read --source recent-unwrapped` (same joined-line semantics as
|
|
183
|
+
/// `capture-pane -J`), liveness through the live `agent list` inventory.
|
|
184
|
+
#[derive(Debug, Clone)]
|
|
185
|
+
pub struct HerdrAdapter {
|
|
186
|
+
bin: String,
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
impl HerdrAdapter {
|
|
190
|
+
pub fn new() -> Self {
|
|
191
|
+
Self {
|
|
192
|
+
bin: env_herdr_binary(),
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/// Pin an explicit herdr binary (tests and trust-pinned deployments).
|
|
197
|
+
pub fn with_bin(bin: impl Into<String>) -> Self {
|
|
198
|
+
Self { bin: bin.into() }
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
pub fn status(&self) -> &'static str {
|
|
202
|
+
"herdr adapter ready"
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
fn do_resolve_target(&self, target: &MuxTarget) -> Result<MuxOutcome, MuxError> {
|
|
206
|
+
let handle = resolve_target_handle(target)?;
|
|
207
|
+
let args = build_pane_get_args(&handle);
|
|
208
|
+
let str_args: Vec<&str> = args.iter().map(|s| s.as_str()).collect();
|
|
209
|
+
// `pane get` keeps answering for closed panes (ids are never reused):
|
|
210
|
+
// this proves the target names a herdr pane, not that it hosts an
|
|
211
|
+
// agent — liveness is a separate operation.
|
|
212
|
+
run_herdr_result(&self.bin, &str_args)?;
|
|
213
|
+
Ok(MuxOutcome::TargetResolved {
|
|
214
|
+
resolved_handle: handle,
|
|
215
|
+
})
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
fn do_send_input(
|
|
219
|
+
&self,
|
|
220
|
+
target: &MuxTarget,
|
|
221
|
+
envelope: &crate::types::InputEnvelope,
|
|
222
|
+
) -> Result<MuxOutcome, MuxError> {
|
|
223
|
+
let handle = resolve_target_handle(target)?;
|
|
224
|
+
let text = envelope.normalized_text();
|
|
225
|
+
let args = build_agent_prompt_args(&handle, &text);
|
|
226
|
+
let str_args: Vec<&str> = args.iter().map(|s| s.as_str()).collect();
|
|
227
|
+
// `agent prompt` submits natively: the Enter presses of the submit
|
|
228
|
+
// policy are satisfied by the semantic submission itself.
|
|
229
|
+
run_herdr_result(&self.bin, &str_args)?;
|
|
230
|
+
Ok(MuxOutcome::InputAccepted {
|
|
231
|
+
bytes_written: text.len(),
|
|
232
|
+
})
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
fn do_capture_tail(
|
|
236
|
+
&self,
|
|
237
|
+
target: &MuxTarget,
|
|
238
|
+
visible_lines: usize,
|
|
239
|
+
) -> Result<MuxOutcome, MuxError> {
|
|
240
|
+
let handle = resolve_target_handle(target)?;
|
|
241
|
+
let args = build_pane_read_args(&handle, visible_lines);
|
|
242
|
+
let str_args: Vec<&str> = args.iter().map(|s| s.as_str()).collect();
|
|
243
|
+
// `pane read` prints plain text, not the JSON envelope.
|
|
244
|
+
let body = run_herdr(&self.bin, &str_args)?;
|
|
245
|
+
Ok(MuxOutcome::TailCaptured {
|
|
246
|
+
visible_lines,
|
|
247
|
+
body,
|
|
248
|
+
})
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
fn do_inspect_liveness(&self, target: &MuxTarget) -> Result<MuxOutcome, MuxError> {
|
|
252
|
+
let handle = resolve_target_handle(target)?;
|
|
253
|
+
let args = build_agent_list_args();
|
|
254
|
+
let str_args: Vec<&str> = args.iter().map(|s| s.as_str()).collect();
|
|
255
|
+
let result = run_herdr_result(&self.bin, &str_args)?;
|
|
256
|
+
let alive = result
|
|
257
|
+
.get("agents")
|
|
258
|
+
.and_then(|agents| agents.as_array())
|
|
259
|
+
.map(|agents| {
|
|
260
|
+
agents.iter().any(|agent| {
|
|
261
|
+
agent.get("pane_id").and_then(|id| id.as_str()) == Some(handle.as_str())
|
|
262
|
+
})
|
|
263
|
+
})
|
|
264
|
+
.unwrap_or(false);
|
|
265
|
+
Ok(MuxOutcome::LivenessChecked { alive })
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
fn do_attach(&self, target: &MuxTarget) -> Result<MuxOutcome, MuxError> {
|
|
269
|
+
let handle = resolve_target_handle(target)?;
|
|
270
|
+
let args = build_agent_attach_args(&handle);
|
|
271
|
+
let str_args: Vec<&str> = args.iter().map(|s| s.as_str()).collect();
|
|
272
|
+
// Interactive: takes over the terminal until the client detaches,
|
|
273
|
+
// mirroring `tmux attach-session`.
|
|
274
|
+
run_herdr(&self.bin, &str_args)?;
|
|
275
|
+
Ok(MuxOutcome::Attached { handle })
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
fn do_detach(&self, _target: &MuxTarget) -> Result<MuxOutcome, MuxError> {
|
|
279
|
+
// Detaching is a Herdr TUI keybinding; the CLI exposes no detach, so
|
|
280
|
+
// there is nothing an automation adapter could drive.
|
|
281
|
+
Err(MuxError::Unsupported(
|
|
282
|
+
"herdr detach is an interactive TUI action; the CLI has no detach command".into(),
|
|
283
|
+
))
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
impl Default for HerdrAdapter {
|
|
288
|
+
fn default() -> Self {
|
|
289
|
+
Self::new()
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
impl MuxAdapter for HerdrAdapter {
|
|
294
|
+
fn adapter_name(&self) -> &'static str {
|
|
295
|
+
"herdr"
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
fn execute(&self, operation: &MuxOperation) -> Result<MuxOutcome, MuxError> {
|
|
299
|
+
match operation {
|
|
300
|
+
MuxOperation::ResolveTarget { target } => self.do_resolve_target(target),
|
|
301
|
+
MuxOperation::SendInput { target, envelope } => self.do_send_input(target, envelope),
|
|
302
|
+
MuxOperation::CaptureTail {
|
|
303
|
+
target,
|
|
304
|
+
visible_lines,
|
|
305
|
+
} => self.do_capture_tail(target, *visible_lines),
|
|
306
|
+
MuxOperation::InspectLiveness { target } => self.do_inspect_liveness(target),
|
|
307
|
+
MuxOperation::Attach { target } => self.do_attach(target),
|
|
308
|
+
MuxOperation::Detach { target } => self.do_detach(target),
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
#[cfg(test)]
|
|
314
|
+
mod tests {
|
|
315
|
+
use super::*;
|
|
316
|
+
use crate::types::{InputEnvelope, SubmitPolicy};
|
|
317
|
+
|
|
318
|
+
#[test]
|
|
319
|
+
fn is_herdr_pane_id_accepts_the_grammar_including_alphanumeric_past_nine() {
|
|
320
|
+
for handle in ["w5:p2", "wA:pB", "w12:p34", "w9:p12"] {
|
|
321
|
+
assert!(is_herdr_pane_id(handle), "{handle} should parse");
|
|
322
|
+
}
|
|
323
|
+
for handle in [
|
|
324
|
+
"%12", "w5", "w5:", ":p2", "x5:p2", "w5:x2", "w-1:p2", "", "w5:p2:q",
|
|
325
|
+
] {
|
|
326
|
+
assert!(!is_herdr_pane_id(handle), "{handle} should not parse");
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
#[test]
|
|
331
|
+
fn resolve_target_handle_rejects_empty_detached_and_tmux_handles() {
|
|
332
|
+
let err = resolve_target_handle(&MuxTarget::DeliveryHandle(String::new()))
|
|
333
|
+
.expect_err("should reject empty");
|
|
334
|
+
assert!(matches!(err, MuxError::InvalidTarget(_)));
|
|
335
|
+
|
|
336
|
+
let err = resolve_target_handle(&MuxTarget::Detached).expect_err("should reject detached");
|
|
337
|
+
assert!(matches!(err, MuxError::InvalidTarget(_)));
|
|
338
|
+
|
|
339
|
+
let err = resolve_target_handle(&MuxTarget::DeliveryHandle("sess:0.1".into()))
|
|
340
|
+
.expect_err("should reject tmux handles");
|
|
341
|
+
assert!(matches!(err, MuxError::InvalidTarget(_)));
|
|
342
|
+
match err {
|
|
343
|
+
MuxError::InvalidTarget(message) => {
|
|
344
|
+
assert!(message.contains("not a herdr pane id"), "{message}");
|
|
345
|
+
}
|
|
346
|
+
_ => unreachable!(),
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
#[test]
|
|
351
|
+
fn resolve_target_handle_accepts_valid_pane_id() {
|
|
352
|
+
let handle = resolve_target_handle(&MuxTarget::DeliveryHandle("w5:p2".into()))
|
|
353
|
+
.expect("should accept valid handle");
|
|
354
|
+
assert_eq!(handle, "w5:p2");
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
#[test]
|
|
358
|
+
fn build_agent_prompt_args_constructs_correct_args() {
|
|
359
|
+
let args = build_agent_prompt_args("w5:p2", "hello world");
|
|
360
|
+
assert_eq!(args, vec!["agent", "prompt", "w5:p2", "hello world"]);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
#[test]
|
|
364
|
+
fn build_pane_read_args_constructs_correct_args() {
|
|
365
|
+
let args = build_pane_read_args("wA:pB", 80);
|
|
366
|
+
assert_eq!(
|
|
367
|
+
args,
|
|
368
|
+
vec![
|
|
369
|
+
"pane",
|
|
370
|
+
"read",
|
|
371
|
+
"wA:pB",
|
|
372
|
+
"--source",
|
|
373
|
+
"recent-unwrapped",
|
|
374
|
+
"--lines",
|
|
375
|
+
"80"
|
|
376
|
+
]
|
|
377
|
+
);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
#[test]
|
|
381
|
+
fn build_pane_get_and_list_and_attach_args_are_stable() {
|
|
382
|
+
assert_eq!(build_pane_get_args("w5:p2"), vec!["pane", "get", "w5:p2"]);
|
|
383
|
+
assert_eq!(build_agent_list_args(), vec!["agent", "list"]);
|
|
384
|
+
assert_eq!(
|
|
385
|
+
build_agent_attach_args("w5:p2"),
|
|
386
|
+
vec!["agent", "attach", "w5:p2"]
|
|
387
|
+
);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
#[test]
|
|
391
|
+
fn herdr_command_error_decodes_the_stderr_envelope() {
|
|
392
|
+
let stderr = br#"{"error":{"code":"pane_not_found","message":"pane w99:p1 not found"},"id":"cli:pane:get"}"#;
|
|
393
|
+
match herdr_command_error(stderr, &["pane", "get"]) {
|
|
394
|
+
MuxError::AdapterFailed(detail) => {
|
|
395
|
+
assert!(detail.contains("herdr_pane_not_found"), "{detail}");
|
|
396
|
+
assert!(detail.contains("pane w99:p1 not found"), "{detail}");
|
|
397
|
+
}
|
|
398
|
+
other => panic!("expected AdapterFailed, got {other:?}"),
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
#[test]
|
|
403
|
+
fn herdr_command_error_falls_back_to_raw_stderr() {
|
|
404
|
+
match herdr_command_error(b"some raw failure\n", &["pane", "close"]) {
|
|
405
|
+
MuxError::AdapterFailed(detail) => assert!(detail.contains("some raw failure")),
|
|
406
|
+
other => panic!("expected AdapterFailed, got {other:?}"),
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
#[test]
|
|
411
|
+
fn liveness_from_agent_list_matches_the_pane_entry() {
|
|
412
|
+
let list = r#"{"id":"cli:agent:list","result":{"agents":[{"name":"omx-a-w1","pane_id":"w5:p2"}],"type":"agent_list"}}"#;
|
|
413
|
+
assert!(liveness_from_agent_list(list, "w5:p2").expect("parse"));
|
|
414
|
+
assert!(!liveness_from_agent_list(list, "w5:p3").expect("parse"));
|
|
415
|
+
assert!(!liveness_from_agent_list(
|
|
416
|
+
r#"{"id":"cli:agent:list","result":{"agents":[],"type":"agent_list"}}"#,
|
|
417
|
+
"w5:p2"
|
|
418
|
+
)
|
|
419
|
+
.expect("parse"));
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
#[test]
|
|
423
|
+
fn liveness_from_agent_list_rejects_non_json() {
|
|
424
|
+
let err = liveness_from_agent_list("not json", "w5:p2").expect_err("should reject");
|
|
425
|
+
assert!(matches!(err, MuxError::AdapterFailed(_)));
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
#[test]
|
|
429
|
+
fn send_prompt_uses_normalized_text() {
|
|
430
|
+
let envelope = InputEnvelope::new("line1\nline2", SubmitPolicy::enter(2, 100));
|
|
431
|
+
let text = envelope.normalized_text();
|
|
432
|
+
assert_eq!(text, "line1 line2");
|
|
433
|
+
let args = build_agent_prompt_args("w5:p2", &text);
|
|
434
|
+
assert_eq!(args[3], "line1 line2");
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
#[test]
|
|
438
|
+
fn adapter_name_is_herdr() {
|
|
439
|
+
let adapter = HerdrAdapter::new();
|
|
440
|
+
assert_eq!(adapter.adapter_name(), "herdr");
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
#[test]
|
|
444
|
+
fn status_reports_ready() {
|
|
445
|
+
let adapter = HerdrAdapter::new();
|
|
446
|
+
assert_eq!(adapter.status(), "herdr adapter ready");
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
#[test]
|
|
450
|
+
fn execute_rejects_targets_without_shelling_out() {
|
|
451
|
+
let adapter = HerdrAdapter::with_bin("/nonexistent/herdr-binary");
|
|
452
|
+
for operation in [
|
|
453
|
+
MuxOperation::ResolveTarget {
|
|
454
|
+
target: MuxTarget::Detached,
|
|
455
|
+
},
|
|
456
|
+
MuxOperation::ResolveTarget {
|
|
457
|
+
target: MuxTarget::DeliveryHandle("%12".into()),
|
|
458
|
+
},
|
|
459
|
+
MuxOperation::CaptureTail {
|
|
460
|
+
target: MuxTarget::DeliveryHandle("sess:0.1".into()),
|
|
461
|
+
visible_lines: 80,
|
|
462
|
+
},
|
|
463
|
+
] {
|
|
464
|
+
let err = adapter
|
|
465
|
+
.execute(&operation)
|
|
466
|
+
.expect_err("should reject target");
|
|
467
|
+
assert!(matches!(err, MuxError::InvalidTarget(_)), "{err}");
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
#[test]
|
|
472
|
+
fn execute_detach_is_unsupported() {
|
|
473
|
+
let adapter = HerdrAdapter::with_bin("/nonexistent/herdr-binary");
|
|
474
|
+
let err = adapter
|
|
475
|
+
.execute(&MuxOperation::Detach {
|
|
476
|
+
target: MuxTarget::DeliveryHandle("w5:p2".into()),
|
|
477
|
+
})
|
|
478
|
+
.expect_err("detach is unsupported");
|
|
479
|
+
assert!(matches!(err, MuxError::Unsupported(_)), "{err}");
|
|
480
|
+
}
|
|
481
|
+
}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
mod herdr;
|
|
1
2
|
mod tmux;
|
|
2
3
|
mod types;
|
|
3
4
|
|
|
5
|
+
pub use herdr::{
|
|
6
|
+
build_agent_attach_args, build_agent_list_args, build_agent_prompt_args, build_pane_get_args,
|
|
7
|
+
build_pane_read_args, is_herdr_pane_id, liveness_from_agent_list, HerdrAdapter,
|
|
8
|
+
};
|
|
4
9
|
pub use tmux::{build_capture_pane_args, TmuxAdapter};
|
|
5
10
|
pub use types::*;
|
|
6
11
|
|