@team-agent/installer 0.5.127 → 0.5.128
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 +1 -1
- package/Cargo.toml +1 -1
- package/README.md +11 -0
- package/crates/team-agent/src/cli/adapters.rs +3 -13
- package/crates/team-agent/src/cli/arguments.rs +4 -0
- package/crates/team-agent/src/cli/diagnose.rs +68 -22
- package/crates/team-agent/src/cli/emit.rs +58 -26
- package/crates/team-agent/src/cli/intent/runtime.rs +32 -5
- package/crates/team-agent/src/cli/intent/runtime_tests.rs +102 -11
- package/crates/team-agent/src/cli/intent/tests.rs +10 -12
- package/crates/team-agent/src/cli/intent.rs +1 -1
- package/crates/team-agent/src/cli/mod.rs +25 -8
- package/crates/team-agent/src/cli/models.rs +764 -7
- package/crates/team-agent/src/cli/schedule.rs +175 -0
- package/crates/team-agent/src/cli/send/persist.rs +0 -36
- package/crates/team-agent/src/cli/send/presentation.rs +1 -1
- package/crates/team-agent/src/cli/send.rs +108 -110
- package/crates/team-agent/src/cli/spec.rs +6 -0
- package/crates/team-agent/src/cli/status_port/brief.rs +5 -67
- package/crates/team-agent/src/cli/tests/leader_watch.rs +12 -62
- package/crates/team-agent/src/cli/tests/mod.rs +1 -1
- package/crates/team-agent/src/cli/tests/named_address.rs +11 -10
- package/crates/team-agent/src/cli/tests/run_delegation.rs +9 -6
- package/crates/team-agent/src/cli/tests/status_send.rs +68 -271
- package/crates/team-agent/src/compiler/tests.rs +3 -18
- package/crates/team-agent/src/compiler.rs +205 -6
- package/crates/team-agent/src/contract_runtime/backend.rs +145 -11
- package/crates/team-agent/src/contract_runtime/commands.rs +7 -7
- package/crates/team-agent/src/contract_runtime/config.rs +26 -16
- package/crates/team-agent/src/contract_runtime/config_tests.rs +24 -4
- package/crates/team-agent/src/contract_runtime/discovery.rs +12 -1
- package/crates/team-agent/src/contract_runtime/fork.rs +3 -10
- package/crates/team-agent/src/contract_runtime/framework.rs +28 -11
- package/crates/team-agent/src/contract_runtime/mcp.rs +19 -24
- package/crates/team-agent/src/contract_runtime/prompt.rs +2 -2
- package/crates/team-agent/src/contract_runtime/registry.rs +56 -92
- package/crates/team-agent/src/coordinator/steps/abnormal.rs +11 -11
- package/crates/team-agent/src/coordinator/tests/api_error_recovery.rs +16 -54
- package/crates/team-agent/src/coordinator/tests/health_sync.rs +42 -0
- package/crates/team-agent/src/coordinator/tick.rs +1 -89
- package/crates/team-agent/src/db/message_store.rs +7 -65
- package/crates/team-agent/src/direct_delivery.rs +368 -0
- package/crates/team-agent/src/inbox_store.rs +169 -0
- package/crates/team-agent/src/leader/registry.rs +5 -0
- package/crates/team-agent/src/leader/start.rs +2 -1
- package/crates/team-agent/src/leader/tests/lease_api.rs +2 -2
- package/crates/team-agent/src/leader/tests/prompt_contract.rs +1 -0
- package/crates/team-agent/src/lib.rs +2 -0
- package/crates/team-agent/src/lifecycle/launch/add_agent.rs +33 -0
- package/crates/team-agent/src/lifecycle/launch/add_agent_state.rs +206 -1
- package/crates/team-agent/src/lifecycle/launch/clone_agent.rs +28 -2
- package/crates/team-agent/src/lifecycle/launch/fork_agent.rs +38 -13
- package/crates/team-agent/src/lifecycle/launch/fork_entry.rs +87 -6
- package/crates/team-agent/src/lifecycle/launch/mcp_config.rs +9 -1
- package/crates/team-agent/src/lifecycle/launch/pi_mcp.rs +351 -81
- package/crates/team-agent/src/lifecycle/launch/pi_mcp_extension.js +3 -4
- package/crates/team-agent/src/lifecycle/launch/quick_start.rs +24 -0
- package/crates/team-agent/src/lifecycle/launch/spawn.rs +36 -13
- package/crates/team-agent/src/lifecycle/launch.rs +24 -1
- package/crates/team-agent/src/lifecycle/profile_launch.rs +321 -11
- package/crates/team-agent/src/lifecycle/restart/agent.rs +1 -0
- package/crates/team-agent/src/lifecycle/restart/avatar.rs +1798 -0
- package/crates/team-agent/src/lifecycle/restart/claude_fork.rs +163 -0
- package/crates/team-agent/src/lifecycle/restart/common.rs +345 -35
- package/crates/team-agent/src/lifecycle/restart/selection.rs +5 -5
- package/crates/team-agent/src/lifecycle/restart.rs +4 -0
- package/crates/team-agent/src/lifecycle/role_config.rs +39 -14
- package/crates/team-agent/src/lifecycle/tests/claude_compatible_config_red.rs +325 -0
- package/crates/team-agent/src/lifecycle/tests/claude_profile_launch_red.rs +320 -8
- package/crates/team-agent/src/lifecycle/tests/cli_argv_routing_red.rs +236 -13
- package/crates/team-agent/src/lifecycle/tests/clone_fork_copilot_perms_red.rs +378 -4
- package/crates/team-agent/src/lifecycle/tests/communication_mode_runtime_contract_red.rs +5 -4
- package/crates/team-agent/src/lifecycle/tests/copilot_provider_red.rs +7 -11
- package/crates/team-agent/src/lifecycle/tests/core.rs +47 -18
- package/crates/team-agent/src/lifecycle/tests/fixtures/pi_native_mcp_host.mjs +2 -1
- package/crates/team-agent/src/lifecycle/tests/grok_require_explicit_model_red.rs +14 -14
- package/crates/team-agent/src/lifecycle/tests/harvest2_a_batch_red.rs +60 -20
- package/crates/team-agent/src/lifecycle/tests/launch_spawn.rs +28 -26
- package/crates/team-agent/src/lifecycle/tests/mcp_tool_name_format_red.rs +6 -6
- package/crates/team-agent/src/lifecycle/tests/pi_catalog_red.rs +18 -6
- package/crates/team-agent/src/lifecycle/tests/pi_command_red.rs +70 -52
- package/crates/team-agent/src/lifecycle/tests/pi_compiler_red.rs +210 -0
- package/crates/team-agent/src/lifecycle/tests/pi_dual_entry_red.rs +157 -4
- package/crates/team-agent/src/lifecycle/tests/pi_executable_mcp_red.rs +526 -10
- package/crates/team-agent/src/lifecycle/tests/pi_fork_session_inheritance_red.rs +1419 -0
- package/crates/team-agent/src/lifecycle/tests/pi_lifecycle_doctor_red.rs +68 -1
- package/crates/team-agent/src/lifecycle/tests/pi_native_mcp_capability_red.rs +34 -12
- package/crates/team-agent/src/lifecycle/tests/pi_session_delivery_red.rs +94 -2
- package/crates/team-agent/src/lifecycle/tests/quick_start_worker_readiness_red.rs +10 -11
- package/crates/team-agent/src/lifecycle/tests/status_credential_redaction_contract.rs +2 -2
- package/crates/team-agent/src/lifecycle/tests/swallow_batch4_semantics_red.rs +254 -2
- package/crates/team-agent/src/lifecycle/tests/upgrade_compat_0211_red.rs +4 -4
- package/crates/team-agent/src/lifecycle/tests/verify_rs031_window_consistency_red.rs +5 -6
- package/crates/team-agent/src/lifecycle/tests/worker_spawn_env_red.rs +16 -7
- package/crates/team-agent/src/lifecycle/tests.rs +3 -0
- package/crates/team-agent/src/lifecycle/types.rs +18 -2
- package/crates/team-agent/src/lifecycle/worker_command_context.rs +43 -50
- package/crates/team-agent/src/mcp_server/readiness.rs +130 -149
- package/crates/team-agent/src/mcp_server/readiness_tests.rs +98 -119
- package/crates/team-agent/src/mcp_server/tests/scoped.rs +21 -31
- package/crates/team-agent/src/mcp_server/tests/send.rs +72 -107
- package/crates/team-agent/src/mcp_server/tests/tools.rs +10 -12
- package/crates/team-agent/src/mcp_server/tools.rs +70 -196
- package/crates/team-agent/src/messaging/delivery.rs +160 -218
- package/crates/team-agent/src/messaging/delivery_consumption_tests.rs +5 -5
- package/crates/team-agent/src/messaging/helpers.rs +1 -19
- package/crates/team-agent/src/messaging/mod.rs +1 -0
- package/crates/team-agent/src/messaging/reminders.rs +316 -0
- package/crates/team-agent/src/messaging/scheduler.rs +7 -1
- package/crates/team-agent/src/messaging/tests/dup_inject.rs +191 -85
- package/crates/team-agent/src/messaging/tests/runtime.rs +4 -110
- package/crates/team-agent/src/messaging/tests/spine.rs +40 -24
- package/crates/team-agent/src/messaging/types.rs +1 -0
- package/crates/team-agent/src/provider/adapter.rs +303 -51
- package/crates/team-agent/src/provider/adapters/claude.rs +78 -0
- package/crates/team-agent/src/provider/adapters/claude_fork.rs +131 -0
- package/crates/team-agent/src/provider/adapters/mod.rs +7 -5
- package/crates/team-agent/src/provider/adapters/pi.rs +106 -0
- package/crates/team-agent/src/provider/classify.rs +1 -66
- package/crates/team-agent/src/provider/model_catalog.rs +201 -13
- package/crates/team-agent/src/provider/session/capture.rs +106 -6
- package/crates/team-agent/src/provider/session/context_fork/claude.rs +123 -0
- package/crates/team-agent/src/provider/session/context_fork/outcome.rs +4 -0
- package/crates/team-agent/src/provider/session/context_fork.rs +150 -18
- package/crates/team-agent/src/provider/session_scan/claude.rs +523 -0
- package/crates/team-agent/src/provider/session_scan/common.rs +44 -8
- package/crates/team-agent/src/provider/session_scan/pi.rs +34 -1
- package/crates/team-agent/src/provider/session_scan.rs +16 -6
- package/crates/team-agent/src/provider/tests/adapter.rs +104 -17
- package/crates/team-agent/src/provider/tests/classify.rs +0 -53
- package/crates/team-agent/src/provider/tests/command_helpers.rs +12 -3
- package/crates/team-agent/src/provider/tests/idle.rs +37 -0
- package/crates/team-agent/src/provider/wire.rs +22 -34
- package/crates/team-agent/src/state/abnormal_watch/tests/mod.rs +1 -1
- package/crates/team-agent/src/state/persist.rs +6 -6
- package/crates/team-agent/src/state/projection.rs +1 -1
- package/crates/team-agent/src/state/repository/tests.rs +2 -2
- package/crates/team-agent/src/test_support/models_timeout_fixture.rs +144 -0
- package/crates/team-agent/src/tmux_backend/tests.rs +0 -151
- package/crates/team-agent/src/tmux_backend.rs +5 -40
- package/package.json +4 -4
- package/skills/team-agent/SKILL.md +5 -7
- package/skills/team-agent/command-coverage.json +1 -1
- package/skills/team-agent/docs/reference/team-agent-operator.md +3 -3
- package/skills/team-agent/references/team-agent-operator.md +3 -3
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
//!
|
|
2
|
+
use std::path::{Path, PathBuf};
|
|
3
|
+
|
|
4
|
+
use crate::provider::{ProviderError, SessionId};
|
|
5
|
+
|
|
6
|
+
#[derive(Debug)]
|
|
7
|
+
pub(crate) struct ClaudeForkMaterialization {
|
|
8
|
+
path: PathBuf,
|
|
9
|
+
keep: bool,
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
impl ClaudeForkMaterialization {
|
|
13
|
+
pub(crate) fn path(&self) -> &Path {
|
|
14
|
+
&self.path
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
pub(crate) fn keep(&mut self) {
|
|
18
|
+
self.keep = true;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
impl Drop for ClaudeForkMaterialization {
|
|
23
|
+
fn drop(&mut self) {
|
|
24
|
+
if !self.keep {
|
|
25
|
+
let _ = std::fs::remove_file(&self.path);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
pub(crate) fn materialize_claude_fork(
|
|
31
|
+
source_path: &Path,
|
|
32
|
+
source_session_id: &SessionId,
|
|
33
|
+
target_session_id: &SessionId,
|
|
34
|
+
source_agent_id: &str,
|
|
35
|
+
target_agent_id: &str,
|
|
36
|
+
) -> Result<ClaudeForkMaterialization, ProviderError> {
|
|
37
|
+
let parent = source_path.parent().ok_or_else(|| {
|
|
38
|
+
ProviderError::Io(format!(
|
|
39
|
+
"claude source backing has no parent: {}",
|
|
40
|
+
source_path.display()
|
|
41
|
+
))
|
|
42
|
+
})?;
|
|
43
|
+
let target_path = parent.join(format!("{}.jsonl", target_session_id.as_str()));
|
|
44
|
+
if target_path.exists() {
|
|
45
|
+
return Err(ProviderError::Io(format!(
|
|
46
|
+
"claude fork destination already exists: {}",
|
|
47
|
+
target_path.display()
|
|
48
|
+
)));
|
|
49
|
+
}
|
|
50
|
+
let source = std::fs::read_to_string(source_path)
|
|
51
|
+
.map_err(|error| ProviderError::Io(error.to_string()))?;
|
|
52
|
+
let rewritten = source
|
|
53
|
+
.replace(source_session_id.as_str(), target_session_id.as_str())
|
|
54
|
+
.replace(
|
|
55
|
+
&format!("You are Team Agent worker `{source_agent_id}`"),
|
|
56
|
+
&format!("You are Team Agent worker `{target_agent_id}`"),
|
|
57
|
+
);
|
|
58
|
+
validate_jsonl(&rewritten)?;
|
|
59
|
+
let temp = parent.join(format!(
|
|
60
|
+
".{}.tmp-{}",
|
|
61
|
+
target_session_id.as_str(),
|
|
62
|
+
std::process::id()
|
|
63
|
+
));
|
|
64
|
+
let result = std::fs::write(&temp, rewritten)
|
|
65
|
+
.and_then(|_| std::fs::rename(&temp, &target_path))
|
|
66
|
+
.map_err(|error| ProviderError::Io(error.to_string()));
|
|
67
|
+
if let Err(error) = result {
|
|
68
|
+
let _ = std::fs::remove_file(&temp);
|
|
69
|
+
return Err(error);
|
|
70
|
+
}
|
|
71
|
+
Ok(ClaudeForkMaterialization {
|
|
72
|
+
path: target_path,
|
|
73
|
+
keep: false,
|
|
74
|
+
})
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
fn validate_jsonl(text: &str) -> Result<(), ProviderError> {
|
|
78
|
+
let mut rows = 0_usize;
|
|
79
|
+
for (index, line) in text.lines().enumerate() {
|
|
80
|
+
if line.trim().is_empty() {
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
serde_json::from_str::<serde_json::Value>(line).map_err(|error| {
|
|
84
|
+
ProviderError::Io(format!(
|
|
85
|
+
"claude fork source has invalid JSONL at line {}: {error}",
|
|
86
|
+
index + 1
|
|
87
|
+
))
|
|
88
|
+
})?;
|
|
89
|
+
rows += 1;
|
|
90
|
+
}
|
|
91
|
+
if rows == 0 {
|
|
92
|
+
return Err(ProviderError::Io(
|
|
93
|
+
"claude fork source backing has no JSONL records".to_string(),
|
|
94
|
+
));
|
|
95
|
+
}
|
|
96
|
+
Ok(())
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
#[cfg(test)]
|
|
100
|
+
mod tests {
|
|
101
|
+
use super::*;
|
|
102
|
+
|
|
103
|
+
#[test]
|
|
104
|
+
fn snapshot_rekeys_every_record_and_preserves_source() {
|
|
105
|
+
let dir = std::env::temp_dir().join(format!("ta-claude-fork-copy-{}", std::process::id()));
|
|
106
|
+
let _ = std::fs::remove_dir_all(&dir);
|
|
107
|
+
std::fs::create_dir_all(&dir).unwrap();
|
|
108
|
+
let source_id = SessionId::new("11111111-1111-4111-8111-111111111111");
|
|
109
|
+
let target_id = SessionId::new("22222222-2222-4222-8222-222222222222");
|
|
110
|
+
let source_path = dir.join(format!("{}.jsonl", source_id.as_str()));
|
|
111
|
+
let source = format!(
|
|
112
|
+
"{{\"sessionId\":\"{}\"}}\n{{\"payload\":{{\"session_id\":\"{}\"}}}}\n",
|
|
113
|
+
source_id.as_str(),
|
|
114
|
+
source_id.as_str()
|
|
115
|
+
);
|
|
116
|
+
std::fs::write(&source_path, &source).unwrap();
|
|
117
|
+
|
|
118
|
+
let mut materialized =
|
|
119
|
+
materialize_claude_fork(&source_path, &source_id, &target_id, "source", "target")
|
|
120
|
+
.unwrap();
|
|
121
|
+
let target_path = dir.join(format!("{}.jsonl", target_id.as_str()));
|
|
122
|
+
let target = std::fs::read_to_string(&target_path).unwrap();
|
|
123
|
+
assert!(!target.contains(source_id.as_str()));
|
|
124
|
+
assert!(target.contains(target_id.as_str()));
|
|
125
|
+
assert_eq!(std::fs::read_to_string(&source_path).unwrap(), source);
|
|
126
|
+
materialized.keep();
|
|
127
|
+
drop(materialized);
|
|
128
|
+
assert!(target_path.is_file());
|
|
129
|
+
let _ = std::fs::remove_dir_all(&dir);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
@@ -8,21 +8,23 @@
|
|
|
8
8
|
//! dispatches into these helpers exactly as the inline forms did.
|
|
9
9
|
//!
|
|
10
10
|
//! Per-file scope:
|
|
11
|
+
//! * `claude` — Claude/ClaudeCode argv, bypass flag, auth hint, model passthrough.
|
|
11
12
|
//! * `copilot` — Copilot argv (no-color/no-remote/disable-builtin-mcps),
|
|
12
13
|
//! MCP `type→transport` translation, resume base, weak auth hint.
|
|
13
14
|
//! * `fake` — Built-in scripted worker exec path.
|
|
14
15
|
//!
|
|
15
|
-
//!
|
|
16
|
-
//!
|
|
17
|
-
//!
|
|
18
|
-
//! `lifecycle/launch/pi_mcp.rs`; the Codex and Grok leaders exec their bare
|
|
19
|
-
//! public command (`leader/start.rs`).
|
|
16
|
+
//! Codex and Grok workers run only through their contract leaves
|
|
17
|
+
//! (`codex_tui`, `grok_build`); their legacy worker builders were excised. The
|
|
18
|
+
//! Codex and Grok leaders exec their bare public command (`leader/start.rs`).
|
|
20
19
|
//!
|
|
21
20
|
//! Behavior is byte-identical to pre-split. Future steps may move
|
|
22
21
|
//! `pre_spawn_adjust_plan`, `profile_env`, `session_backing_probe`, and
|
|
23
22
|
//! `session_candidates` into provider-owned hooks following the same
|
|
24
23
|
//! per-file layout.
|
|
25
24
|
|
|
25
|
+
pub(crate) mod claude;
|
|
26
|
+
pub(crate) mod claude_fork;
|
|
26
27
|
pub(crate) mod copilot;
|
|
27
28
|
pub(crate) mod copilot_fork;
|
|
28
29
|
pub(crate) mod fake;
|
|
30
|
+
pub(crate) mod pi;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
//! ---
|
|
2
|
+
//! purpose: Pi CLI 的纯工具映射与 fresh/resume argv 构造
|
|
3
|
+
//! contract:
|
|
4
|
+
//! provides:
|
|
5
|
+
//! - name: build_pi_command_argv
|
|
6
|
+
//! what: 仅从已验证输入构造保留 direct Pi 配置的 Team Agent argv
|
|
7
|
+
//! boundary:
|
|
8
|
+
//! - 不发现 executable、catalog、adapter 或 MCP 配置
|
|
9
|
+
//! - 除 resume exact backing 存在性外不读文件;不写文件、不启动进程
|
|
10
|
+
//! maturity: wired
|
|
11
|
+
//! ---
|
|
12
|
+
|
|
13
|
+
use std::path::Path;
|
|
14
|
+
|
|
15
|
+
use crate::model::enums::ProviderEffort;
|
|
16
|
+
use crate::provider::ProviderError;
|
|
17
|
+
use crate::provider::command_helpers::{append_opt_pair, append_pair};
|
|
18
|
+
|
|
19
|
+
#[derive(Debug, Clone, Copy)]
|
|
20
|
+
pub(crate) enum PiSessionSelector<'a> {
|
|
21
|
+
/// Pi assigns the session id. Passing `--session-id` makes Pi warn and
|
|
22
|
+
/// then create, because the id is not a project session yet.
|
|
23
|
+
Fresh,
|
|
24
|
+
FreshWithId {
|
|
25
|
+
id: &'a crate::provider::SessionId,
|
|
26
|
+
},
|
|
27
|
+
Resume { path: &'a Path },
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
pub(crate) struct PiCommandRequest<'a> {
|
|
31
|
+
pub extension: &'a Path,
|
|
32
|
+
pub model: Option<&'a str>,
|
|
33
|
+
pub effort: Option<ProviderEffort>,
|
|
34
|
+
pub system_prompt: &'a str,
|
|
35
|
+
/// Team-owned session root for isolated seats; `None` preserves Pi's native default.
|
|
36
|
+
pub session_dir: Option<&'a Path>,
|
|
37
|
+
pub session: PiSessionSelector<'a>,
|
|
38
|
+
pub agent_id: &'a str,
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/// ---
|
|
42
|
+
/// purpose: 从已验证 semantic request 构造仅追加 Team Agent MCP/提示/session 的 Pi argv
|
|
43
|
+
/// returns: exact ordered fresh/resume argv,argv[0] 固定为裸 `pi`
|
|
44
|
+
/// errors: 必需字段时返回 ProviderError
|
|
45
|
+
/// ---
|
|
46
|
+
pub(crate) fn build_pi_command_argv(
|
|
47
|
+
request: PiCommandRequest<'_>,
|
|
48
|
+
) -> Result<Vec<String>, ProviderError> {
|
|
49
|
+
if request.extension.as_os_str().is_empty()
|
|
50
|
+
|| request
|
|
51
|
+
.session_dir
|
|
52
|
+
.is_some_and(|session_dir| session_dir.as_os_str().is_empty())
|
|
53
|
+
|| request.model.is_some_and(|model| model.trim().is_empty())
|
|
54
|
+
|| request.system_prompt.trim().is_empty()
|
|
55
|
+
|| request.agent_id.trim().is_empty()
|
|
56
|
+
{
|
|
57
|
+
return Err(ProviderError::Command(
|
|
58
|
+
"Pi command requires extension, prompt, and agent id".to_string(),
|
|
59
|
+
));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Executable discovery/preflight belongs to the lifecycle materializer;
|
|
63
|
+
// the actual command must remain PATH-resolved at spawn time.
|
|
64
|
+
let mut argv = vec![
|
|
65
|
+
"pi".to_string(),
|
|
66
|
+
"-e".to_string(),
|
|
67
|
+
request.extension.to_string_lossy().into_owned(),
|
|
68
|
+
];
|
|
69
|
+
append_opt_pair(&mut argv, "--model", request.model);
|
|
70
|
+
if let Some(effort) = request.effort {
|
|
71
|
+
argv.push("--thinking".to_string());
|
|
72
|
+
argv.push(effort.as_str().to_string());
|
|
73
|
+
}
|
|
74
|
+
append_pair(&mut argv, "--append-system-prompt", request.system_prompt);
|
|
75
|
+
if let Some(session_dir) = request.session_dir {
|
|
76
|
+
append_pair(&mut argv, "--session-dir", session_dir.to_string_lossy().into_owned());
|
|
77
|
+
}
|
|
78
|
+
// The shared lifecycle materializer always revalidates resume root/path/header.
|
|
79
|
+
// Keep the pure argv builder usable before a fixture root is materialized, while
|
|
80
|
+
// refusing a missing exact file once the recorded path's parent exists.
|
|
81
|
+
match request.session {
|
|
82
|
+
PiSessionSelector::Fresh => {}
|
|
83
|
+
PiSessionSelector::FreshWithId { id } => {
|
|
84
|
+
argv.extend(["--session-id".to_string(), id.as_str().to_string()]);
|
|
85
|
+
}
|
|
86
|
+
PiSessionSelector::Resume { path }
|
|
87
|
+
if !path.as_os_str().is_empty()
|
|
88
|
+
&& (!path.parent().is_some_and(Path::is_dir) || path.is_file()) =>
|
|
89
|
+
{
|
|
90
|
+
append_pair(&mut argv, "--session", path.to_string_lossy().into_owned());
|
|
91
|
+
}
|
|
92
|
+
PiSessionSelector::Resume { path } if !path.as_os_str().is_empty() => {
|
|
93
|
+
return Err(ProviderError::ResumeUnavailable(format!(
|
|
94
|
+
"Pi exact session backing is missing: {}",
|
|
95
|
+
path.display()
|
|
96
|
+
)));
|
|
97
|
+
}
|
|
98
|
+
_ => {
|
|
99
|
+
return Err(ProviderError::Command(
|
|
100
|
+
"Pi command requires a non-empty session selector".to_string(),
|
|
101
|
+
));
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
append_pair(&mut argv, "--name", request.agent_id);
|
|
105
|
+
Ok(argv)
|
|
106
|
+
}
|
|
@@ -68,71 +68,6 @@ pub fn classify(
|
|
|
68
68
|
Ok(decide_state(fact, process))
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
/// #379: where an agent's Claude process keeps its live registry record and
|
|
72
|
-
/// under which session id. Beside the captured transcript
|
|
73
|
-
/// (`<config>/projects/<slug>/<sessionId>.jsonl`); before capture, under the
|
|
74
|
-
/// projects root it was launched with (profile, else the native
|
|
75
|
-
/// `$HOME/.claude/projects`) and the `--session-id` it was started under.
|
|
76
|
-
pub fn claude_registry_key(agent: &serde_json::Value) -> Option<(std::path::PathBuf, String)> {
|
|
77
|
-
let text = |key: &str| {
|
|
78
|
-
agent.get(key).and_then(serde_json::Value::as_str).filter(|value| !value.is_empty())
|
|
79
|
-
};
|
|
80
|
-
let (projects, session_id) = match text("rollout_path").map(std::path::Path::new) {
|
|
81
|
-
Some(rollout) => (rollout.parent()?.parent()?.to_path_buf(), rollout.file_stem()?.to_str()?),
|
|
82
|
-
None => (
|
|
83
|
-
text("claude_projects_root").map(std::path::PathBuf::from).or_else(|| {
|
|
84
|
-
std::env::var_os("HOME")
|
|
85
|
-
.map(|home| std::path::PathBuf::from(home).join(".claude").join("projects"))
|
|
86
|
-
})?,
|
|
87
|
-
text("_pending_session_id").or_else(|| text("session_id"))?,
|
|
88
|
-
),
|
|
89
|
-
};
|
|
90
|
-
if projects.file_name()? != "projects" {
|
|
91
|
-
return None;
|
|
92
|
-
}
|
|
93
|
-
Some((projects.parent()?.join("sessions"), session_id.to_owned()))
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/// #379: Claude Code's own live turn state. The CLI writes `status` into
|
|
97
|
-
/// `<config>/sessions/<pid>.json` at startup and on every transition
|
|
98
|
-
/// (`running`→`busy`, `requires_action`→`waiting`, `idle`→`idle`). A record
|
|
99
|
-
/// counts only with this session id, a live pid and, when it names one, the
|
|
100
|
-
/// same tmux pane. None = no decisive record.
|
|
101
|
-
pub fn claude_registry_turn_state(
|
|
102
|
-
sessions: &std::path::Path,
|
|
103
|
-
session_id: &str,
|
|
104
|
-
pane_id: Option<&str>,
|
|
105
|
-
) -> Option<TurnState> {
|
|
106
|
-
let entries = std::fs::read_dir(sessions).ok()?;
|
|
107
|
-
entries.flatten().find_map(|entry| {
|
|
108
|
-
let path = entry.path();
|
|
109
|
-
if path.extension()? != "json" || entry.metadata().ok()?.len() > 64 * 1024 {
|
|
110
|
-
return None;
|
|
111
|
-
}
|
|
112
|
-
let record: serde_json::Value = serde_json::from_slice(&std::fs::read(&path).ok()?).ok()?;
|
|
113
|
-
let field = |key: &str| record.get(key).and_then(serde_json::Value::as_str);
|
|
114
|
-
if field("sessionId") != Some(session_id) {
|
|
115
|
-
return None;
|
|
116
|
-
}
|
|
117
|
-
// `tmux` is `<session>:@<window>.%<pane>`.
|
|
118
|
-
if let (Some(pane), Some(tmux)) = (pane_id, field("tmux")) {
|
|
119
|
-
if tmux.rsplit_once('.').map(|(_, recorded)| recorded) != Some(pane) {
|
|
120
|
-
return None;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
let pid = u32::try_from(record.get("pid")?.as_u64()?).ok()?;
|
|
124
|
-
if !crate::platform::process::pid_is_alive(pid) {
|
|
125
|
-
return None;
|
|
126
|
-
}
|
|
127
|
-
match field("status")? {
|
|
128
|
-
"busy" => Some(TurnState::Working),
|
|
129
|
-
"waiting" => Some(TurnState::BlockedOnHuman),
|
|
130
|
-
"idle" => Some(TurnState::Idle),
|
|
131
|
-
_ => None,
|
|
132
|
-
}
|
|
133
|
-
})
|
|
134
|
-
}
|
|
135
|
-
|
|
136
71
|
/// Blocker-2 Layer-2: scan Claude transcript records for background task
|
|
137
72
|
/// lifecycle markers. Returns `Some(turn_id)` when at least one background
|
|
138
73
|
/// task is OPEN (started but not closed) — caller treats as `TurnOpen` with
|
|
@@ -484,7 +419,7 @@ fn decide_state(fact: &LifecycleFact, process: ProcessLiveness) -> ClassifyResul
|
|
|
484
419
|
ProcessLiveness::Alive => classify_result(
|
|
485
420
|
TurnState::Working,
|
|
486
421
|
fact.turn_id.clone(),
|
|
487
|
-
if
|
|
422
|
+
if fact.reason == "assistant_in_flight" {
|
|
488
423
|
&fact.reason
|
|
489
424
|
} else {
|
|
490
425
|
"open_turn"
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
//! Provider model discovery, bounded native catalog queries, and shared fuzzy search.
|
|
2
|
-
use std::collections::HashSet;
|
|
2
|
+
use std::collections::{HashMap, HashSet};
|
|
3
3
|
use std::ffi::OsString;
|
|
4
4
|
use std::io::{Read, Write};
|
|
5
|
-
use std::path::Path;
|
|
5
|
+
use std::path::{Path, PathBuf};
|
|
6
6
|
use std::process::{Child, Command, ExitStatus, Stdio};
|
|
7
|
+
use std::sync::atomic::{AtomicU64, Ordering};
|
|
7
8
|
use std::sync::mpsc;
|
|
8
9
|
use std::time::{Duration, Instant};
|
|
9
10
|
|
|
@@ -12,6 +13,8 @@ use crate::provider::wire::{parse_canonical_provider, provider_wire};
|
|
|
12
13
|
|
|
13
14
|
const CATALOG_TIMEOUT: Duration = Duration::from_secs(10);
|
|
14
15
|
const MAX_CATALOG_BYTES: u64 = 1024 * 1024;
|
|
16
|
+
const CLAUDE_REQUEST_ID: &str = "team-agent-model-catalog";
|
|
17
|
+
static TEMP_DIR_SEQUENCE: AtomicU64 = AtomicU64::new(0);
|
|
15
18
|
|
|
16
19
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
|
17
20
|
pub struct ModelRecord {
|
|
@@ -127,23 +130,20 @@ pub fn parse_catalog_provider(name: &str) -> Option<Provider> {
|
|
|
127
130
|
|
|
128
131
|
#[derive(Clone, Copy)]
|
|
129
132
|
enum CatalogSource {
|
|
133
|
+
Pi,
|
|
130
134
|
Codex,
|
|
131
135
|
Grok,
|
|
136
|
+
Claude,
|
|
132
137
|
}
|
|
133
138
|
|
|
134
139
|
// Exhaustive by design: a new Provider variant must make an explicit catalog decision.
|
|
135
|
-
// `team-agent models --provider claude|claude_code|pi` reads the contract
|
|
136
|
-
// leaf's catalog (contract_runtime::discovery) before reaching this table.
|
|
137
140
|
fn catalog_source(provider: Provider) -> Option<CatalogSource> {
|
|
138
141
|
match provider {
|
|
142
|
+
Provider::Pi => Some(CatalogSource::Pi),
|
|
139
143
|
Provider::Codex => Some(CatalogSource::Codex),
|
|
144
|
+
Provider::Claude | Provider::ClaudeCode => Some(CatalogSource::Claude),
|
|
140
145
|
Provider::Grok => Some(CatalogSource::Grok),
|
|
141
|
-
Provider::
|
|
142
|
-
| Provider::ClaudeCode
|
|
143
|
-
| Provider::Pi
|
|
144
|
-
| Provider::Copilot
|
|
145
|
-
| Provider::GeminiCli
|
|
146
|
-
| Provider::Fake => None,
|
|
146
|
+
Provider::Copilot | Provider::GeminiCli | Provider::Fake => None,
|
|
147
147
|
}
|
|
148
148
|
}
|
|
149
149
|
|
|
@@ -152,6 +152,10 @@ pub fn discover_model_catalog(provider_name: &str) -> Result<Vec<ModelRecord>, C
|
|
|
152
152
|
let source = catalog_source(provider).ok_or(CatalogError::UnsupportedProvider)?;
|
|
153
153
|
let requested_provider = provider_wire(provider);
|
|
154
154
|
let records = match source {
|
|
155
|
+
CatalogSource::Pi => {
|
|
156
|
+
let bytes = run_native("pi", &["--list-models"], None, None, &[], CATALOG_TIMEOUT, MAX_CATALOG_BYTES, &mut NoopObserver)?;
|
|
157
|
+
parse_pi_catalog(&bytes)?
|
|
158
|
+
}
|
|
155
159
|
CatalogSource::Codex => {
|
|
156
160
|
let bytes = run_native("codex", &["debug", "models"], None, None, &[], CATALOG_TIMEOUT, MAX_CATALOG_BYTES, &mut NoopObserver)?;
|
|
157
161
|
parse_codex_catalog(&bytes, requested_provider)?
|
|
@@ -160,6 +164,7 @@ pub fn discover_model_catalog(provider_name: &str) -> Result<Vec<ModelRecord>, C
|
|
|
160
164
|
let bytes = run_native("grok", &["models"], None, None, &[], CATALOG_TIMEOUT, MAX_CATALOG_BYTES, &mut NoopObserver)?;
|
|
161
165
|
parse_grok_catalog(&bytes)?
|
|
162
166
|
}
|
|
167
|
+
CatalogSource::Claude => discover_claude_catalog(requested_provider)?,
|
|
163
168
|
};
|
|
164
169
|
Ok(records)
|
|
165
170
|
}
|
|
@@ -350,6 +355,90 @@ fn parse_codex_catalog(bytes: &[u8], provider: &str) -> Result<Vec<ModelRecord>,
|
|
|
350
355
|
Ok(visible)
|
|
351
356
|
}
|
|
352
357
|
|
|
358
|
+
fn discover_claude_catalog(provider: &str) -> Result<Vec<ModelRecord>, CatalogError> {
|
|
359
|
+
let cwd = OwnedTempDir::create()?;
|
|
360
|
+
let args = [
|
|
361
|
+
"--print", "--input-format", "stream-json", "--output-format", "stream-json", "--verbose",
|
|
362
|
+
"--no-session-persistence", "--strict-mcp-config", "--mcp-config", r#"{"mcpServers":{}}"#,
|
|
363
|
+
"--setting-sources", "", "--settings", r#"{"disableAllHooks":true}"#, "--tools", "", "--no-chrome",
|
|
364
|
+
];
|
|
365
|
+
let request = serde_json::json!({"type":"control_request","request_id":CLAUDE_REQUEST_ID,"request":{"subtype":"initialize","hooks":{},"agents":{},"skills":[]}});
|
|
366
|
+
let mut input = serde_json::to_vec(&request).map_err(|_| CatalogError::InvalidProtocol)?;
|
|
367
|
+
input.push(b'\n');
|
|
368
|
+
let bytes = run_native("claude", &args, Some(&input), Some(&cwd.0), &["CLAUDECODE"], CATALOG_TIMEOUT, MAX_CATALOG_BYTES, &mut NoopObserver)?;
|
|
369
|
+
parse_claude_catalog(&bytes, provider)
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
fn parse_claude_catalog(bytes: &[u8], provider: &str) -> Result<Vec<ModelRecord>, CatalogError> {
|
|
373
|
+
let text = std::str::from_utf8(bytes).map_err(|_| CatalogError::InvalidUtf8)?;
|
|
374
|
+
let mut response = None;
|
|
375
|
+
for line in text.lines() {
|
|
376
|
+
if line.is_empty() { return Err(CatalogError::InvalidProtocol); }
|
|
377
|
+
let frame: serde_json::Value = serde_json::from_str(line).map_err(|_| CatalogError::InvalidProtocol)?;
|
|
378
|
+
let frame_type = frame
|
|
379
|
+
.get("type")
|
|
380
|
+
.and_then(serde_json::Value::as_str)
|
|
381
|
+
.filter(|frame_type| !frame_type.is_empty())
|
|
382
|
+
.ok_or(CatalogError::InvalidProtocol)?;
|
|
383
|
+
if frame_type != "control_response" {
|
|
384
|
+
continue;
|
|
385
|
+
}
|
|
386
|
+
if response.is_some() {
|
|
387
|
+
return Err(CatalogError::InvalidProtocol);
|
|
388
|
+
}
|
|
389
|
+
let result = frame.get("response").ok_or(CatalogError::UnsupportedSchema)?;
|
|
390
|
+
let outer_request_id = frame.get("request_id").and_then(serde_json::Value::as_str);
|
|
391
|
+
let inner_request_id = result.get("request_id").and_then(serde_json::Value::as_str);
|
|
392
|
+
if (outer_request_id != Some(CLAUDE_REQUEST_ID) && inner_request_id != Some(CLAUDE_REQUEST_ID))
|
|
393
|
+
|| frame.get("request_id").is_some_and(|id| id.as_str() != Some(CLAUDE_REQUEST_ID))
|
|
394
|
+
|| result.get("request_id").is_some_and(|id| id.as_str() != Some(CLAUDE_REQUEST_ID))
|
|
395
|
+
{
|
|
396
|
+
return Err(CatalogError::InvalidProtocol);
|
|
397
|
+
}
|
|
398
|
+
if result.get("subtype").and_then(serde_json::Value::as_str) != Some("success") { return Err(CatalogError::InvalidProtocol); }
|
|
399
|
+
let rows = result.get("response").and_then(|v| v.get("models")).and_then(serde_json::Value::as_array).ok_or(CatalogError::UnsupportedSchema)?;
|
|
400
|
+
response = Some(rows.clone());
|
|
401
|
+
}
|
|
402
|
+
let rows = response.ok_or(CatalogError::InvalidProtocol)?;
|
|
403
|
+
if rows.is_empty() { return Err(CatalogError::Empty); }
|
|
404
|
+
let mut source_values = HashSet::new();
|
|
405
|
+
let mut by_id = HashMap::<String, usize>::new();
|
|
406
|
+
let mut records: Vec<ModelRecord> = Vec::new();
|
|
407
|
+
let mut group_defaults = Vec::<bool>::new();
|
|
408
|
+
let mut group_has_non_default_display = Vec::<bool>::new();
|
|
409
|
+
let mut any_default = false;
|
|
410
|
+
for row in rows {
|
|
411
|
+
let row = row.as_object().ok_or(CatalogError::Malformed)?;
|
|
412
|
+
let value = required_string(row.get("value"))?;
|
|
413
|
+
let resolved = required_string(row.get("resolvedModel")).map_err(|_| CatalogError::UnsupportedSchema)?;
|
|
414
|
+
let display = required_string(row.get("displayName")).map_err(|_| CatalogError::UnsupportedSchema)?;
|
|
415
|
+
validate_identity(value)?;
|
|
416
|
+
validate_identity(resolved)?;
|
|
417
|
+
validate_display(display)?;
|
|
418
|
+
if !source_values.insert(value.to_string()) { return Err(CatalogError::DuplicateIdentity(value.into())); }
|
|
419
|
+
let is_default = value == "default";
|
|
420
|
+
any_default |= is_default;
|
|
421
|
+
if let Some(index) = by_id.get(resolved).copied() {
|
|
422
|
+
let record = &mut records[index];
|
|
423
|
+
record.aliases.push(value.into());
|
|
424
|
+
if !is_default && !group_has_non_default_display[index] {
|
|
425
|
+
record.display_name = display.into();
|
|
426
|
+
group_has_non_default_display[index] = true;
|
|
427
|
+
}
|
|
428
|
+
group_defaults[index] |= is_default;
|
|
429
|
+
} else {
|
|
430
|
+
by_id.insert(resolved.into(), records.len());
|
|
431
|
+
records.push(ModelRecord { provider: provider.into(), vendor: "anthropic".into(), id: resolved.into(), display_name: display.into(), default: None, aliases: vec![value.into()] });
|
|
432
|
+
group_defaults.push(is_default);
|
|
433
|
+
group_has_non_default_display.push(!is_default);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
for (record, is_default) in records.iter_mut().zip(group_defaults) {
|
|
437
|
+
record.default = any_default.then_some(is_default);
|
|
438
|
+
}
|
|
439
|
+
Ok(records)
|
|
440
|
+
}
|
|
441
|
+
|
|
353
442
|
fn required_string(value: Option<&serde_json::Value>) -> Result<&str, CatalogError> {
|
|
354
443
|
let value = value.and_then(serde_json::Value::as_str).ok_or(CatalogError::UnsupportedSchema)?;
|
|
355
444
|
if value.trim().is_empty() { return Err(CatalogError::UnsupportedSchema); }
|
|
@@ -532,6 +621,54 @@ fn terminate(child: &mut Child, pid: u32) {
|
|
|
532
621
|
let _ = child.wait();
|
|
533
622
|
}
|
|
534
623
|
|
|
624
|
+
pub(crate) fn finish_stdout_after_exit(
|
|
625
|
+
stdout: std::process::ChildStdout,
|
|
626
|
+
status: ExitStatus,
|
|
627
|
+
timeout: Duration,
|
|
628
|
+
max_bytes: u64,
|
|
629
|
+
observer: &mut dyn CatalogObserver,
|
|
630
|
+
) -> Result<Vec<u8>, CatalogError> {
|
|
631
|
+
if !status.success() { observer.exited(&status); return Err(CatalogError::CommandFailed); }
|
|
632
|
+
observer.exited(&status);
|
|
633
|
+
let (tx, rx) = mpsc::channel();
|
|
634
|
+
let reader = std::thread::Builder::new().name("model-catalog-reader".into()).spawn(move || {
|
|
635
|
+
let mut bytes = Vec::new();
|
|
636
|
+
let result = stdout.take(max_bytes.saturating_add(1)).read_to_end(&mut bytes);
|
|
637
|
+
let _ = tx.send(result.map(|_| bytes));
|
|
638
|
+
}).map_err(|_| CatalogError::OutputReadFailed)?;
|
|
639
|
+
let result = match rx.recv_timeout(timeout) {
|
|
640
|
+
Ok(Ok(bytes)) if bytes.len() as u64 <= max_bytes => Ok(bytes),
|
|
641
|
+
Ok(Ok(_)) => Err(CatalogError::OutputTooLarge),
|
|
642
|
+
Ok(Err(_)) | Err(mpsc::RecvTimeoutError::Disconnected) => Err(CatalogError::OutputReadFailed),
|
|
643
|
+
Err(mpsc::RecvTimeoutError::Timeout) => { observer.output_timeout(); Err(CatalogError::Timeout) }
|
|
644
|
+
};
|
|
645
|
+
if !matches!(&result, Err(CatalogError::Timeout)) { let _ = reader.join(); }
|
|
646
|
+
result
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
struct OwnedTempDir(PathBuf);
|
|
650
|
+
impl OwnedTempDir {
|
|
651
|
+
fn create() -> Result<Self, CatalogError> {
|
|
652
|
+
use std::os::unix::fs::DirBuilderExt;
|
|
653
|
+
let root = std::env::temp_dir();
|
|
654
|
+
for _ in 0..8 {
|
|
655
|
+
let id = TEMP_DIR_SEQUENCE.fetch_add(1, Ordering::Relaxed);
|
|
656
|
+
let path = root.join(format!("team-agent-claude-models-{}-{id}", std::process::id()));
|
|
657
|
+
let mut builder = std::fs::DirBuilder::new();
|
|
658
|
+
builder.mode(0o700);
|
|
659
|
+
match builder.create(&path) {
|
|
660
|
+
Ok(()) => return Ok(Self(path)),
|
|
661
|
+
Err(error) if error.kind() == std::io::ErrorKind::AlreadyExists => continue,
|
|
662
|
+
Err(_) => return Err(CatalogError::TemporaryDirectoryUnavailable),
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
Err(CatalogError::TemporaryDirectoryUnavailable)
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
impl Drop for OwnedTempDir {
|
|
669
|
+
fn drop(&mut self) { let _ = std::fs::remove_dir_all(&self.0); }
|
|
670
|
+
}
|
|
671
|
+
|
|
535
672
|
#[cfg(all(test, unix))]
|
|
536
673
|
mod command_wait_regressions {
|
|
537
674
|
use super::*;
|
|
@@ -684,18 +821,20 @@ mod tests {
|
|
|
684
821
|
#[test]
|
|
685
822
|
fn provider_capability_is_explicit_and_exact() {
|
|
686
823
|
for (name, provider) in [
|
|
824
|
+
("pi", Provider::Pi),
|
|
687
825
|
("codex", Provider::Codex),
|
|
826
|
+
("claude", Provider::Claude),
|
|
827
|
+
("claude_code", Provider::ClaudeCode),
|
|
688
828
|
("grok", Provider::Grok),
|
|
689
829
|
] {
|
|
690
830
|
assert_eq!(parse_catalog_provider(name), Some(provider));
|
|
691
831
|
assert_eq!(provider_wire(provider), name);
|
|
692
832
|
assert!(catalog_source(provider).is_some());
|
|
693
833
|
}
|
|
694
|
-
|
|
695
|
-
for name in ["", "cloud", "pi", "claude", "claude_code", "cursor", "cursor_agent", "agent", "claude-code", "copilot", "gemini_cli", "fake", "Pi", "CODEX", " pi", "pi ", "pi/model", "codex:model", "claude_code_extra"] {
|
|
834
|
+
for name in ["", "cloud", "cursor", "cursor_agent", "agent", "claude-code", "copilot", "gemini_cli", "fake", "Pi", "CODEX", " pi", "pi ", "pi/model", "codex:model", "claude_code_extra"] {
|
|
696
835
|
assert_eq!(parse_catalog_provider(name), None);
|
|
697
836
|
}
|
|
698
|
-
for provider in [Provider::
|
|
837
|
+
for provider in [Provider::Copilot, Provider::GeminiCli, Provider::Fake] {
|
|
699
838
|
assert!(catalog_source(provider).is_none());
|
|
700
839
|
}
|
|
701
840
|
}
|
|
@@ -711,6 +850,55 @@ mod tests {
|
|
|
711
850
|
assert!(matches!(parse_codex_catalog(duplicate, "codex"), Err(CatalogError::DuplicateIdentity(_))));
|
|
712
851
|
}
|
|
713
852
|
|
|
853
|
+
#[test]
|
|
854
|
+
fn claude_selectors_group_by_exact_resolved_id() {
|
|
855
|
+
let response = serde_json::json!({"type":"control_response","request_id":CLAUDE_REQUEST_ID,"response":{"subtype":"success","response":{"models":[
|
|
856
|
+
{"value":"default","resolvedModel":"claude-opus-5-5[1m]","displayName":"Default"},
|
|
857
|
+
{"value":"opus[1m]","resolvedModel":"claude-opus-5-5[1m]","displayName":"Opus 1M"},
|
|
858
|
+
{"value":"opus-alt","resolvedModel":"claude-opus-5-5[1m]","displayName":"Alternate display"},
|
|
859
|
+
{"value":"sonnet","resolvedModel":"claude-sonnet-5","displayName":"Sonnet"}
|
|
860
|
+
]}}});
|
|
861
|
+
let bytes = format!("{}\n", response).into_bytes();
|
|
862
|
+
let rows = parse_claude_catalog(&bytes, "claude_code").unwrap();
|
|
863
|
+
assert_eq!(rows.len(), 2);
|
|
864
|
+
assert_eq!(rows[0].provider, "claude_code");
|
|
865
|
+
assert_eq!(rows[0].id, "claude-opus-5-5[1m]");
|
|
866
|
+
assert_eq!(rows[0].display_name, "Opus 1M");
|
|
867
|
+
assert_eq!(rows[0].aliases, vec!["default", "opus[1m]", "opus-alt"]);
|
|
868
|
+
assert_eq!(rows[0].default, Some(true));
|
|
869
|
+
assert_eq!(rows[1].default, Some(false));
|
|
870
|
+
assert!(model_matches(&rows[0], "OPUS 1M"));
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
#[test]
|
|
874
|
+
fn claude_ignores_other_stream_frames_and_matches_nested_request_id() {
|
|
875
|
+
let models = serde_json::json!([{"value":"default","resolvedModel":"claude-sonnet-5","displayName":"Sonnet"}]);
|
|
876
|
+
let frames = [
|
|
877
|
+
serde_json::json!({"type":"system","subtype":"hook_started"}),
|
|
878
|
+
serde_json::json!({"type":"system","subtype":"hook_response"}),
|
|
879
|
+
serde_json::json!({"type":"stream_event","event":{"type":"message_start"}}),
|
|
880
|
+
serde_json::json!({"type":"control_response","response":{"subtype":"success","request_id":CLAUDE_REQUEST_ID,"response":{"models":models}}}),
|
|
881
|
+
];
|
|
882
|
+
let bytes = frames.iter().map(serde_json::Value::to_string).collect::<Vec<_>>().join("\n");
|
|
883
|
+
let rows = parse_claude_catalog(bytes.as_bytes(), "claude_code").unwrap();
|
|
884
|
+
assert_eq!(rows.len(), 1);
|
|
885
|
+
assert_eq!(rows[0].id, "claude-sonnet-5");
|
|
886
|
+
|
|
887
|
+
let conflicting = serde_json::json!({"type":"control_response","request_id":CLAUDE_REQUEST_ID,"response":{"subtype":"success","request_id":"wrong-id","response":{"models":[{"value":"default","resolvedModel":"claude-sonnet-5","displayName":"Sonnet"}]}}});
|
|
888
|
+
assert!(matches!(parse_claude_catalog(format!("{}\n", conflicting).as_bytes(), "claude_code"), Err(CatalogError::InvalidProtocol)));
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
#[test]
|
|
892
|
+
fn claude_missing_canonical_id_and_duplicate_selectors_fail_closed() {
|
|
893
|
+
let missing = serde_json::json!({"type":"control_response","request_id":CLAUDE_REQUEST_ID,"response":{"subtype":"success","response":{"models":[{"value":"default","displayName":"Default"}]}}});
|
|
894
|
+
assert!(matches!(parse_claude_catalog(format!("{}\n", missing).as_bytes(), "claude"), Err(CatalogError::UnsupportedSchema)));
|
|
895
|
+
let duplicate = serde_json::json!({"type":"control_response","request_id":CLAUDE_REQUEST_ID,"response":{"subtype":"success","response":{"models":[
|
|
896
|
+
{"value":"opus","resolvedModel":"claude-opus","displayName":"Opus"},
|
|
897
|
+
{"value":"opus","resolvedModel":"claude-opus[1m]","displayName":"Opus 1M"}
|
|
898
|
+
]}}});
|
|
899
|
+
assert!(matches!(parse_claude_catalog(format!("{}\n", duplicate).as_bytes(), "claude"), Err(CatalogError::DuplicateIdentity(_))));
|
|
900
|
+
}
|
|
901
|
+
|
|
714
902
|
#[test]
|
|
715
903
|
fn matcher_uses_and_tokens_and_all_catalog_fields() {
|
|
716
904
|
let row = ModelRecord { provider: "codex".into(), vendor: "openai".into(), id: "gpt-6-luna".into(), display_name: "GPT Luna".into(), default: None, aliases: vec![] };
|