@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
|
@@ -340,7 +340,7 @@ fn start_at_selected(
|
|
|
340
340
|
}
|
|
341
341
|
}
|
|
342
342
|
|
|
343
|
-
//
|
|
343
|
+
// Keep role-file values authoritative except for explicit CLI bypass intent.
|
|
344
344
|
// Equal supplied values are omitted from the patch to preserve existing file bytes.
|
|
345
345
|
fn reconcile_creation(
|
|
346
346
|
text: &str,
|
|
@@ -383,10 +383,7 @@ fn reconcile_creation(
|
|
|
383
383
|
}
|
|
384
384
|
match meta.get("dangerously_skip_permissions") {
|
|
385
385
|
Some(Value::Bool(value)) => {
|
|
386
|
-
if
|
|
387
|
-
if bypass != *value {
|
|
388
|
-
return Err(conflict("bypass"));
|
|
389
|
-
}
|
|
386
|
+
if next.bypass == Some(*value) {
|
|
390
387
|
next.bypass = None;
|
|
391
388
|
}
|
|
392
389
|
}
|
|
@@ -395,11 +392,6 @@ fn reconcile_creation(
|
|
|
395
392
|
"role dangerously_skip_permissions must be a boolean".into(),
|
|
396
393
|
))
|
|
397
394
|
}
|
|
398
|
-
None if next.bypass.is_none() => {
|
|
399
|
-
return Err(LifecycleError::RequirementUnmet(
|
|
400
|
-
"add-agent requires bypass in --role-file or --bypass <true|false>".into(),
|
|
401
|
-
))
|
|
402
|
-
}
|
|
403
395
|
None => {}
|
|
404
396
|
}
|
|
405
397
|
for (field, supplied) in [
|
|
@@ -990,10 +982,6 @@ mod tests {
|
|
|
990
982
|
provider: Some("pi".into()),
|
|
991
983
|
..Default::default()
|
|
992
984
|
},
|
|
993
|
-
RoleConfigPatch {
|
|
994
|
-
bypass: Some(true),
|
|
995
|
-
..Default::default()
|
|
996
|
-
},
|
|
997
985
|
RoleConfigPatch {
|
|
998
986
|
model: Some("other".into()),
|
|
999
987
|
..Default::default()
|
|
@@ -1042,6 +1030,43 @@ mod tests {
|
|
|
1042
1030
|
}
|
|
1043
1031
|
}
|
|
1044
1032
|
|
|
1033
|
+
#[test]
|
|
1034
|
+
fn explicit_bypass_overrides_role_file_in_both_directions() {
|
|
1035
|
+
for &provider in crate::provider::wire::all_providers() {
|
|
1036
|
+
let provider = crate::provider::wire::provider_wire(provider);
|
|
1037
|
+
for declared in [true, false] {
|
|
1038
|
+
let text = format!("---\nprovider: {provider}\ndangerously_skip_permissions: {declared}\n---\nbody");
|
|
1039
|
+
let patch = RoleConfigPatch {
|
|
1040
|
+
bypass: Some(!declared),
|
|
1041
|
+
..Default::default()
|
|
1042
|
+
};
|
|
1043
|
+
let reconciled = reconcile_creation(&text, &patch).unwrap();
|
|
1044
|
+
let next = patched_role(&text, &AgentId::new("w"), &reconciled, false).unwrap();
|
|
1045
|
+
assert_eq!(
|
|
1046
|
+
role_parts(&next).unwrap().0.get("dangerously_skip_permissions"),
|
|
1047
|
+
Some(&Value::Bool(!declared))
|
|
1048
|
+
);
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
#[test]
|
|
1054
|
+
fn omitted_bypass_preserves_native_default_and_invalid_boolean_is_rejected() {
|
|
1055
|
+
let patch = RoleConfigPatch {
|
|
1056
|
+
provider: Some("pi".into()),
|
|
1057
|
+
..Default::default()
|
|
1058
|
+
};
|
|
1059
|
+
assert_eq!(reconcile_creation("", &patch).unwrap().bypass, None);
|
|
1060
|
+
assert_eq!(
|
|
1061
|
+
reconcile_creation("---\nprovider: pi\n---\n", &RoleConfigPatch::default())
|
|
1062
|
+
.unwrap().bypass,
|
|
1063
|
+
None
|
|
1064
|
+
);
|
|
1065
|
+
assert!(reconcile_creation(
|
|
1066
|
+
"---\nprovider: pi\ndangerously_skip_permissions: yes\n---\n", &patch
|
|
1067
|
+
).is_err());
|
|
1068
|
+
}
|
|
1069
|
+
|
|
1045
1070
|
#[test]
|
|
1046
1071
|
fn legacy_cr_only_header_does_not_change_engine_when_patched() {
|
|
1047
1072
|
let text = "---\rprovider: codex\ndangerously_skip_permissions: false\r---\r\rbody\r";
|
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
//! Claude compatible-api managed config contracts for Batch A Lane 2.
|
|
2
|
+
//!
|
|
3
|
+
//! The profile resolver owns file artifacts; the provider only consumes `managed_mcp_config`.
|
|
4
|
+
//! These tests verify the public files/env/argv shape expected by Python 0.2.11 parity.
|
|
5
|
+
|
|
6
|
+
#![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
|
|
7
|
+
|
|
8
|
+
#[path = "../../../tests/support/hermetic.rs"]
|
|
9
|
+
mod hermetic_guard;
|
|
10
|
+
#[allow(dead_code)]
|
|
11
|
+
fn _hermetic_boundary_marker(_: &hermetic_guard::HermeticTestEnv) {}
|
|
12
|
+
|
|
13
|
+
use std::collections::{BTreeMap, BTreeSet};
|
|
14
|
+
use std::path::{Path, PathBuf};
|
|
15
|
+
use std::sync::atomic::{AtomicU64, Ordering};
|
|
16
|
+
use std::sync::Mutex;
|
|
17
|
+
|
|
18
|
+
use serde_json::{json, Value};
|
|
19
|
+
use serial_test::serial;
|
|
20
|
+
use team_agent::lifecycle::quick_start_with_transport_in_workspace;
|
|
21
|
+
use team_agent::model::enums::{AuthMode, Provider};
|
|
22
|
+
use team_agent::provider::{
|
|
23
|
+
get_adapter, McpConfig, ProviderCommandContext, ProviderCommandOverrides, ProviderProfileLaunch,
|
|
24
|
+
};
|
|
25
|
+
use team_agent::transport::{
|
|
26
|
+
AttachOutcome, BackendKind, CaptureRange, CapturedText, InjectPayload, InjectReport,
|
|
27
|
+
InjectStage, InjectVerification, Key, PaneField, PaneId, PaneInfo, SessionName, SetEnvOutcome,
|
|
28
|
+
SpawnResult, SubmitVerification, Target, Transport, TransportError, TurnVerification,
|
|
29
|
+
WindowName,
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
#[test]
|
|
33
|
+
#[serial(env)]
|
|
34
|
+
fn compatible_api_profile_writes_claude_settings_and_project_state_with_mcp_servers() {
|
|
35
|
+
let _hermetic = hermetic_guard::HermeticTestEnv::enter_with_leader("claude-compatible-config");
|
|
36
|
+
let ws = tmp_dir("compatible-config-files");
|
|
37
|
+
super::launch_spawn::seed_healthy_coordinator(&ws);
|
|
38
|
+
let team = write_claude_profile_team(&ws, "cfgteam", "clauder");
|
|
39
|
+
let transport = RecordingTransport::default();
|
|
40
|
+
|
|
41
|
+
quick_start_with_transport_in_workspace(&ws, &team, None, true, Some("cfgteam"), &transport)
|
|
42
|
+
.expect("quick-start through recording transport should resolve compatible profile config");
|
|
43
|
+
|
|
44
|
+
let spawn = transport.single_spawn();
|
|
45
|
+
let config_dir = spawn
|
|
46
|
+
.env
|
|
47
|
+
.get("CLAUDE_CONFIG_DIR")
|
|
48
|
+
.map(PathBuf::from)
|
|
49
|
+
.expect("CLAUDE_CONFIG_DIR must be injected");
|
|
50
|
+
let settings = read_json(&config_dir.join("settings.json"));
|
|
51
|
+
let project_state = read_json(&config_dir.join(".claude.json"));
|
|
52
|
+
|
|
53
|
+
assert!(
|
|
54
|
+
settings_contains_trust_onboarding_and_theme(&settings),
|
|
55
|
+
"settings.json must pre-accept workspace trust/onboarding/theme for managed compatible_api Claude; path={} settings={settings}",
|
|
56
|
+
config_dir.join("settings.json").display()
|
|
57
|
+
);
|
|
58
|
+
assert!(
|
|
59
|
+
project_state
|
|
60
|
+
.pointer("/mcpServers/team_orchestrator")
|
|
61
|
+
.or_else(|| project_state.pointer("/projects/cfgteam/mcpServers/team_orchestrator"))
|
|
62
|
+
.is_some(),
|
|
63
|
+
".claude.json must contain the Team Agent MCP server project state; path={} project_state={project_state}",
|
|
64
|
+
config_dir.join(".claude.json").display()
|
|
65
|
+
);
|
|
66
|
+
assert!(
|
|
67
|
+
!argv_has_flag(&spawn.argv, "--mcp-config"),
|
|
68
|
+
"managed compatible_api launch uses CLAUDE_CONFIG_DIR artifacts, not provider argv --mcp-config; argv={:?}",
|
|
69
|
+
spawn.argv
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
#[test]
|
|
74
|
+
fn managed_profile_command_plan_omits_mcp_config_even_when_mcp_config_is_available() {
|
|
75
|
+
let root = tmp_dir("managed-plan-config");
|
|
76
|
+
let profile = ProviderProfileLaunch {
|
|
77
|
+
env_overlay: BTreeMap::from([(
|
|
78
|
+
"CLAUDE_CONFIG_DIR".to_string(),
|
|
79
|
+
root.join("claude-config").display().to_string(),
|
|
80
|
+
)]),
|
|
81
|
+
env_unset: BTreeSet::from(["ANTHROPIC_API_KEY".to_string()]),
|
|
82
|
+
command_overrides: ProviderCommandOverrides {
|
|
83
|
+
model: Some("profile-effective-haiku".to_string()),
|
|
84
|
+
..ProviderCommandOverrides::default()
|
|
85
|
+
},
|
|
86
|
+
claude_config_dir: Some(root.join("claude-config")),
|
|
87
|
+
claude_projects_root: Some(root.join("claude-config").join("projects")),
|
|
88
|
+
managed_mcp_config: true,
|
|
89
|
+
};
|
|
90
|
+
let config = McpConfig {
|
|
91
|
+
raw: json!({
|
|
92
|
+
"team_orchestrator": {
|
|
93
|
+
"type": "stdio",
|
|
94
|
+
"command": "team-agent",
|
|
95
|
+
"args": ["mcp-server", "--workspace", "{workspace}"]
|
|
96
|
+
}
|
|
97
|
+
}),
|
|
98
|
+
};
|
|
99
|
+
let plan = get_adapter(Provider::Claude)
|
|
100
|
+
.build_command_plan(ProviderCommandContext {
|
|
101
|
+
auth_mode: AuthMode::CompatibleApi,
|
|
102
|
+
mcp_config: Some(&config),
|
|
103
|
+
system_prompt: Some("worker prompt requiring native MCP"),
|
|
104
|
+
model: Some("profile-effective-haiku"),
|
|
105
|
+
dangerously_skip_permissions: false,
|
|
106
|
+
profile_launch: Some(&profile),
|
|
107
|
+
agent_id_hint: None,
|
|
108
|
+
effort: None,
|
|
109
|
+
})
|
|
110
|
+
.expect("managed compatible_api command plan should build");
|
|
111
|
+
|
|
112
|
+
assert!(
|
|
113
|
+
plan.managed_mcp_config,
|
|
114
|
+
"CommandPlan.managed_mcp_config must reflect ProviderProfileLaunch.managed_mcp_config; plan={plan:?}"
|
|
115
|
+
);
|
|
116
|
+
assert!(
|
|
117
|
+
!argv_has_flag(&plan.argv, "--mcp-config"),
|
|
118
|
+
"managed mode must not pass --mcp-config JSON/string in argv; config is materialized under CLAUDE_CONFIG_DIR; argv={:?}",
|
|
119
|
+
plan.argv
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
fn settings_contains_trust_onboarding_and_theme(settings: &Value) -> bool {
|
|
124
|
+
let text = settings.to_string();
|
|
125
|
+
["trust", "onboarding", "theme"]
|
|
126
|
+
.iter()
|
|
127
|
+
.all(|needle| text.to_ascii_lowercase().contains(needle))
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
fn read_json(path: &Path) -> Value {
|
|
131
|
+
let text = std::fs::read_to_string(path).unwrap_or_else(|err| {
|
|
132
|
+
panic!(
|
|
133
|
+
"expected managed Claude config file {}: {err}",
|
|
134
|
+
path.display()
|
|
135
|
+
)
|
|
136
|
+
});
|
|
137
|
+
serde_json::from_str(&text).unwrap_or_else(|err| {
|
|
138
|
+
panic!(
|
|
139
|
+
"managed Claude config file must be JSON {}: {err}; text={text}",
|
|
140
|
+
path.display()
|
|
141
|
+
)
|
|
142
|
+
})
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
fn write_claude_profile_team(ws: &Path, team_key: &str, agent_id: &str) -> PathBuf {
|
|
146
|
+
let team = ws.join(team_key);
|
|
147
|
+
std::fs::create_dir_all(team.join("agents")).unwrap();
|
|
148
|
+
std::fs::create_dir_all(ws.join(".team").join("current").join("profiles")).unwrap();
|
|
149
|
+
std::fs::write(
|
|
150
|
+
ws.join(".team").join("current").join("profiles").join("local.env"),
|
|
151
|
+
"ANTHROPIC_BASE_URL=https://llm.local/v1\nANTHROPIC_AUTH_TOKEN=local-secret\nANTHROPIC_MODEL=profile-effective-haiku\n",
|
|
152
|
+
)
|
|
153
|
+
.unwrap();
|
|
154
|
+
std::fs::write(
|
|
155
|
+
team.join("TEAM.md"),
|
|
156
|
+
format!(
|
|
157
|
+
"---\nname: {team_key}\nobjective: Claude compatible config contract.\nprovider: claude\nauth_mode: compatible_api\ndangerously_skip_permissions: false\n---\n\nTeam.\n"
|
|
158
|
+
),
|
|
159
|
+
)
|
|
160
|
+
.unwrap();
|
|
161
|
+
std::fs::write(
|
|
162
|
+
team.join("agents").join(format!("{agent_id}.md")),
|
|
163
|
+
format!(
|
|
164
|
+
"---\nname: {agent_id}\nrole: Claude Worker\nprovider: claude\nauth_mode: compatible_api\ndangerously_skip_permissions: false\nprofile: local\nmodel: null\ntools:\n - mcp_team\n---\n\nWorker.\n"
|
|
165
|
+
),
|
|
166
|
+
)
|
|
167
|
+
.unwrap();
|
|
168
|
+
team
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
fn argv_has_flag(argv: &[String], flag: &str) -> bool {
|
|
172
|
+
argv.iter().any(|arg| arg == flag)
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
fn tmp_dir(tag: &str) -> PathBuf {
|
|
176
|
+
static N: AtomicU64 = AtomicU64::new(0);
|
|
177
|
+
let dir = std::env::temp_dir().join(format!(
|
|
178
|
+
"ta-rs-claude-compatible-config-{tag}-{}-{}",
|
|
179
|
+
std::process::id(),
|
|
180
|
+
N.fetch_add(1, Ordering::Relaxed)
|
|
181
|
+
));
|
|
182
|
+
let _ = std::fs::remove_dir_all(&dir);
|
|
183
|
+
std::fs::create_dir_all(&dir).unwrap();
|
|
184
|
+
std::fs::canonicalize(dir).unwrap()
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
#[derive(Debug, Clone)]
|
|
188
|
+
struct RecordedSpawn {
|
|
189
|
+
argv: Vec<String>,
|
|
190
|
+
env: BTreeMap<String, String>,
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
#[derive(Debug, Default)]
|
|
194
|
+
struct RecordingTransport {
|
|
195
|
+
spawns: Mutex<Vec<RecordedSpawn>>,
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
impl RecordingTransport {
|
|
199
|
+
fn single_spawn(&self) -> RecordedSpawn {
|
|
200
|
+
let spawns = self.spawns.lock().unwrap();
|
|
201
|
+
assert_eq!(
|
|
202
|
+
spawns.len(),
|
|
203
|
+
1,
|
|
204
|
+
"fixture should record one Claude worker spawn; spawns={spawns:?}"
|
|
205
|
+
);
|
|
206
|
+
spawns[0].clone()
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
impl Transport for RecordingTransport {
|
|
211
|
+
fn kind(&self) -> BackendKind {
|
|
212
|
+
BackendKind::Tmux
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
fn spawn_first(
|
|
216
|
+
&self,
|
|
217
|
+
session: &SessionName,
|
|
218
|
+
window: &WindowName,
|
|
219
|
+
argv: &[String],
|
|
220
|
+
_cwd: &Path,
|
|
221
|
+
env: &BTreeMap<String, String>,
|
|
222
|
+
) -> Result<SpawnResult, TransportError> {
|
|
223
|
+
self.spawn_into(session, window, argv, _cwd, env)
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
fn spawn_into(
|
|
227
|
+
&self,
|
|
228
|
+
session: &SessionName,
|
|
229
|
+
window: &WindowName,
|
|
230
|
+
argv: &[String],
|
|
231
|
+
_cwd: &Path,
|
|
232
|
+
env: &BTreeMap<String, String>,
|
|
233
|
+
) -> Result<SpawnResult, TransportError> {
|
|
234
|
+
let mut spawns = self.spawns.lock().unwrap();
|
|
235
|
+
spawns.push(RecordedSpawn {
|
|
236
|
+
argv: argv.to_vec(),
|
|
237
|
+
env: env.clone(),
|
|
238
|
+
});
|
|
239
|
+
Ok(SpawnResult {
|
|
240
|
+
pane_id: PaneId::new(format!("%{}", spawns.len())),
|
|
241
|
+
session: session.clone(),
|
|
242
|
+
window: window.clone(),
|
|
243
|
+
child_pid: Some(20_000 + spawns.len() as u32),
|
|
244
|
+
})
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
fn inject(
|
|
248
|
+
&self,
|
|
249
|
+
_target: &Target,
|
|
250
|
+
_payload: &InjectPayload,
|
|
251
|
+
_submit: Key,
|
|
252
|
+
_bracketed: bool,
|
|
253
|
+
) -> Result<InjectReport, TransportError> {
|
|
254
|
+
Ok(InjectReport {
|
|
255
|
+
stage_reached: InjectStage::Submit,
|
|
256
|
+
inject_verification: InjectVerification::CaptureContainsToken,
|
|
257
|
+
submit_verification: SubmitVerification::EnterSentWithoutPlaceholderCheck,
|
|
258
|
+
turn_verification: TurnVerification::NotYetObserved,
|
|
259
|
+
attempts: 1,
|
|
260
|
+
submit_diagnostics: None,
|
|
261
|
+
})
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
fn send_keys(&self, _target: &Target, _keys: &[Key]) -> Result<(), TransportError> {
|
|
265
|
+
Ok(())
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
fn capture(
|
|
269
|
+
&self,
|
|
270
|
+
_target: &Target,
|
|
271
|
+
range: CaptureRange,
|
|
272
|
+
) -> Result<CapturedText, TransportError> {
|
|
273
|
+
Ok(CapturedText {
|
|
274
|
+
text: String::new(),
|
|
275
|
+
range,
|
|
276
|
+
})
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
fn query(&self, _target: &Target, field: PaneField) -> Result<Option<String>, TransportError> {
|
|
280
|
+
match field {
|
|
281
|
+
PaneField::PaneWidth => Ok(Some("120".to_string())),
|
|
282
|
+
_ => Ok(None),
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
fn liveness(
|
|
287
|
+
&self,
|
|
288
|
+
_pane: &PaneId,
|
|
289
|
+
) -> Result<team_agent::transport::PaneLiveness, TransportError> {
|
|
290
|
+
Ok(team_agent::transport::PaneLiveness::Live)
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
fn list_targets(&self) -> Result<Vec<PaneInfo>, TransportError> {
|
|
294
|
+
Ok(Vec::new())
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
fn has_session(&self, _session: &SessionName) -> Result<bool, TransportError> {
|
|
298
|
+
Ok(false)
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
fn list_windows(&self, _session: &SessionName) -> Result<Vec<WindowName>, TransportError> {
|
|
302
|
+
Ok(Vec::new())
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
fn set_session_env(
|
|
306
|
+
&self,
|
|
307
|
+
_session: &SessionName,
|
|
308
|
+
_key: &str,
|
|
309
|
+
_value: &str,
|
|
310
|
+
) -> Result<SetEnvOutcome, TransportError> {
|
|
311
|
+
Ok(SetEnvOutcome::Applied)
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
fn kill_session(&self, _session: &SessionName) -> Result<(), TransportError> {
|
|
315
|
+
Ok(())
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
fn kill_window(&self, _target: &Target) -> Result<(), TransportError> {
|
|
319
|
+
Ok(())
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
fn attach_session(&self, _session: &SessionName) -> Result<AttachOutcome, TransportError> {
|
|
323
|
+
Ok(AttachOutcome::Attached)
|
|
324
|
+
}
|
|
325
|
+
}
|