@team-agent/installer 0.5.123 → 0.5.125
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 -8
- package/Cargo.toml +1 -1
- package/README.md +2 -2
- package/README.zh.md +2 -2
- package/crates/team-agent/Cargo.toml +0 -1
- package/crates/team-agent/src/cli/diagnose.rs +39 -1
- package/crates/team-agent/src/cli/emit.rs +41 -15
- package/crates/team-agent/src/cli/intent/runtime.rs +30 -54
- package/crates/team-agent/src/cli/intent/runtime_tests.rs +59 -118
- package/crates/team-agent/src/cli/leader.rs +2 -3
- package/crates/team-agent/src/cli/leader_prompt.rs +1 -1
- package/crates/team-agent/src/cli/mod.rs +6 -5
- package/crates/team-agent/src/cli/models.rs +93 -128
- package/crates/team-agent/src/cli/route.rs +1 -1
- package/crates/team-agent/src/cli/send/persist.rs +36 -0
- package/crates/team-agent/src/cli/send/presentation.rs +7 -1
- package/crates/team-agent/src/cli/send.rs +3 -1
- package/crates/team-agent/src/cli/spec.rs +1 -2
- package/crates/team-agent/src/cli/status_port/brief.rs +66 -0
- package/crates/team-agent/src/cli/tests/base.rs +4 -11
- package/crates/team-agent/src/cli/tests/status_send.rs +17 -0
- package/crates/team-agent/src/compiler/tests.rs +21 -5
- package/crates/team-agent/src/compiler.rs +24 -1
- package/crates/team-agent/src/contract_runtime/backend.rs +30 -6
- package/crates/team-agent/src/contract_runtime/config.rs +34 -24
- package/crates/team-agent/src/contract_runtime/discovery.rs +79 -56
- package/crates/team-agent/src/contract_runtime/framework.rs +89 -34
- package/crates/team-agent/src/contract_runtime/registry.rs +299 -24
- package/crates/team-agent/src/coordinator/runtime_detectors.rs +0 -1
- package/crates/team-agent/src/coordinator/tick.rs +89 -1
- package/crates/team-agent/src/db/message_store.rs +78 -3
- package/crates/team-agent/src/layout/worker_window_helpers.rs +0 -1
- package/crates/team-agent/src/leader/prompt.rs +1 -2
- package/crates/team-agent/src/leader/provider_attribution.rs +0 -52
- package/crates/team-agent/src/leader/start.rs +0 -1
- package/crates/team-agent/src/leader/tests/prompt_contract.rs +2 -3
- package/crates/team-agent/src/lifecycle/launch/add_agent.rs +91 -0
- package/crates/team-agent/src/lifecycle/launch/add_agent_state.rs +14 -1
- package/crates/team-agent/src/lifecycle/launch/agent_state.rs +0 -9
- package/crates/team-agent/src/lifecycle/launch/fork_agent.rs +0 -1
- package/crates/team-agent/src/lifecycle/launch/mcp_config.rs +2 -2
- package/crates/team-agent/src/lifecycle/launch/pi_mcp.rs +19 -101
- package/crates/team-agent/src/lifecycle/launch/spawn.rs +0 -28
- package/crates/team-agent/src/lifecycle/launch/spec_state.rs +0 -1
- package/crates/team-agent/src/lifecycle/launch/worker_env.rs +0 -108
- package/crates/team-agent/src/lifecycle/launch.rs +2 -20
- package/crates/team-agent/src/lifecycle/profile_launch.rs +11 -39
- package/crates/team-agent/src/lifecycle/profile_smoke.rs +1 -2
- package/crates/team-agent/src/lifecycle/restart/common.rs +1 -63
- package/crates/team-agent/src/lifecycle/role_config.rs +42 -3
- package/crates/team-agent/src/lifecycle/tests/cli_argv_routing_red.rs +43 -13
- package/crates/team-agent/src/lifecycle/tests/clone_fork_copilot_perms_red.rs +6 -2
- package/crates/team-agent/src/lifecycle/tests/pi_catalog_red.rs +1 -3
- package/crates/team-agent/src/lifecycle/tests/pi_command_red.rs +4 -16
- package/crates/team-agent/src/lifecycle/tests/pi_compiler_red.rs +1 -3
- package/crates/team-agent/src/lifecycle/tests/pi_executable_mcp_red.rs +84 -53
- package/crates/team-agent/src/lifecycle/tests/pi_fork_session_inheritance_red.rs +19 -1
- package/crates/team-agent/src/lifecycle/tests/pi_session_delivery_red.rs +21 -0
- package/crates/team-agent/src/lifecycle/tests/restart_rebind_hotfix_252_red.rs +0 -1
- package/crates/team-agent/src/lifecycle/tests/worker_spawn_env_red.rs +0 -137
- package/crates/team-agent/src/lifecycle/tests.rs +0 -3
- package/crates/team-agent/src/lifecycle/worker_command_context.rs +2 -4
- package/crates/team-agent/src/mcp_server/readiness.rs +148 -97
- package/crates/team-agent/src/mcp_server/readiness_tests.rs +115 -16
- package/crates/team-agent/src/messaging/delivery.rs +186 -38
- package/crates/team-agent/src/messaging/delivery_consumption_tests.rs +4 -4
- package/crates/team-agent/src/messaging/enter_rescue_tests.rs +1 -1
- package/crates/team-agent/src/messaging/helpers.rs +19 -0
- package/crates/team-agent/src/messaging/tests/dup_inject.rs +66 -4
- package/crates/team-agent/src/messaging/tests/runtime.rs +110 -4
- package/crates/team-agent/src/messaging/tests/spine.rs +22 -6
- package/crates/team-agent/src/model/enums.rs +1 -8
- package/crates/team-agent/src/provider/adapter.rs +1 -67
- package/crates/team-agent/src/provider/adapters/mod.rs +0 -1
- package/crates/team-agent/src/provider/adapters/pi.rs +4 -4
- package/crates/team-agent/src/provider/argv_route.rs +1 -5
- package/crates/team-agent/src/provider/bypass_flags.rs +3 -11
- package/crates/team-agent/src/provider/classify.rs +68 -3
- package/crates/team-agent/src/provider/faults.rs +1 -1
- package/crates/team-agent/src/provider/model_catalog.rs +2 -73
- package/crates/team-agent/src/provider/session/capture.rs +1 -1
- package/crates/team-agent/src/provider/session/context_fork.rs +4 -4
- package/crates/team-agent/src/provider/session_scan/common.rs +1 -2
- package/crates/team-agent/src/provider/session_scan/pi.rs +32 -19
- package/crates/team-agent/src/provider/session_scan.rs +0 -4
- package/crates/team-agent/src/provider/submit_now.rs +5 -28
- package/crates/team-agent/src/provider/tests/adapter.rs +5 -184
- package/crates/team-agent/src/provider/tests/classify.rs +53 -0
- package/crates/team-agent/src/provider/tests/command_helpers.rs +3 -6
- package/crates/team-agent/src/provider/types.rs +1 -1
- package/crates/team-agent/src/provider/wire.rs +48 -8
- package/crates/team-agent/src/tmux_backend/native_input_tests.rs +2 -178
- package/crates/team-agent/src/tmux_backend/tests.rs +151 -0
- package/crates/team-agent/src/tmux_backend.rs +43 -8
- package/crates/team-agent/src/transport/native_input.rs +2 -231
- package/npm/install.mjs +40 -3
- package/package.json +4 -4
- package/skills/team-agent/SKILL.md +1 -1
- package/crates/team-agent/src/lifecycle/launch/cursor_create_chat.rs +0 -229
- package/crates/team-agent/src/lifecycle/launch/cursor_mcp.rs +0 -522
- package/crates/team-agent/src/lifecycle/launch/cursor_mcp_iso.rs +0 -282
- package/crates/team-agent/src/lifecycle/tests/cursor_mcp_overlay.rs +0 -576
- package/crates/team-agent/src/lifecycle/tests/cursor_require_explicit_model_red.rs +0 -222
- package/crates/team-agent/src/lifecycle/tests/cursor_restart_resume_red.rs +0 -511
- package/crates/team-agent/src/provider/adapters/cursor_agent.rs +0 -44
- package/crates/team-agent/src/provider/session_scan/cursor.rs +0 -538
- package/crates/team-agent/src/provider/testdata/cursor-list-models-native.stdout +0 -250
|
@@ -7,14 +7,30 @@ use std::sync::atomic::{AtomicU32, Ordering};
|
|
|
7
7
|
|
|
8
8
|
static COUNTER: AtomicU32 = AtomicU32::new(0);
|
|
9
9
|
|
|
10
|
+
#[cfg(unix)]
|
|
10
11
|
#[test]
|
|
11
|
-
fn
|
|
12
|
-
for
|
|
13
|
-
let role = write_tmp(
|
|
12
|
+
fn every_cursor_provider_name_compiles_to_the_contract_leaf() {
|
|
13
|
+
for provider in ["cursor", "cursor_agent", "cursor-agent", "agent"] {
|
|
14
|
+
let role = write_tmp(
|
|
15
|
+
"cursor.md",
|
|
16
|
+
&format!("---\nprovider: {provider}\nmodel: gpt-5.6-luna-xhigh\n---\nRole\n"),
|
|
17
|
+
);
|
|
18
|
+
let compiled = compile_role_agent(&role, &Value::Map(Vec::new()), "/workspace").unwrap();
|
|
19
|
+
assert_eq!(
|
|
20
|
+
compiled.agent.get("provider").and_then(Value::as_str),
|
|
21
|
+
Some("cursor"),
|
|
22
|
+
"{provider}"
|
|
23
|
+
);
|
|
24
|
+
fs::remove_dir_all(role.parent().unwrap()).unwrap();
|
|
25
|
+
// The leaf's effort admission applies, not a legacy warning-and-ignore.
|
|
26
|
+
let role = write_tmp(
|
|
27
|
+
"cursor.md",
|
|
28
|
+
&format!("---\nprovider: {provider}\nmodel: gpt-5.6-luna-xhigh\neffort: high\n---\nRole\n"),
|
|
29
|
+
);
|
|
14
30
|
let error = compile_role_agent(&role, &Value::Map(Vec::new()), "/workspace")
|
|
15
31
|
.err()
|
|
16
|
-
.expect("Cursor
|
|
17
|
-
assert!(error.to_string().contains("
|
|
32
|
+
.expect("Cursor effort is a model ID, never a separate flag");
|
|
33
|
+
assert!(error.to_string().contains("exact catalog model ID"), "{provider}: {error}");
|
|
18
34
|
fs::remove_dir_all(role.parent().unwrap()).unwrap();
|
|
19
35
|
}
|
|
20
36
|
}
|
|
@@ -495,8 +495,31 @@ fn compile_role_agent_with_mode(
|
|
|
495
495
|
.filter(|provider| !provider.trim().is_empty())
|
|
496
496
|
.unwrap_or_else(|| "pi".to_string());
|
|
497
497
|
let is_pi = parse_canonical_provider(&provider) == Some(Provider::Pi);
|
|
498
|
+
// An exact boolean opt-in; a bare shared key (codex) keeps its legacy meaning.
|
|
499
|
+
let contract_runtime = match meta.get("contract_runtime") {
|
|
500
|
+
None => false,
|
|
501
|
+
Some(Value::Bool(value)) => *value,
|
|
502
|
+
Some(_) => {
|
|
503
|
+
return Err(ModelError::Validation(format!(
|
|
504
|
+
"{}: contract_runtime must be a boolean",
|
|
505
|
+
role_path.display()
|
|
506
|
+
)))
|
|
507
|
+
}
|
|
508
|
+
};
|
|
509
|
+
#[cfg(unix)]
|
|
510
|
+
let contract = crate::contract_runtime::registry::declared(&provider, contract_runtime);
|
|
511
|
+
#[cfg(not(unix))]
|
|
512
|
+
let contract: Option<()> = None;
|
|
513
|
+
if contract_runtime && contract.is_none() {
|
|
514
|
+
return Err(ModelError::Validation(format!(
|
|
515
|
+
"{}: contract_runtime: true requires a contract provider (got {provider})",
|
|
516
|
+
role_path.display()
|
|
517
|
+
)));
|
|
518
|
+
}
|
|
519
|
+
// The compiled spec and state carry the leaf's canonical id, so legacy
|
|
520
|
+
// readers of a shared key never mistake this seat for a legacy one.
|
|
498
521
|
#[cfg(unix)]
|
|
499
|
-
let
|
|
522
|
+
let provider = contract.map_or(provider, |descriptor| descriptor.identity.id.to_string());
|
|
500
523
|
#[cfg(unix)]
|
|
501
524
|
let contract_role = contract.is_some();
|
|
502
525
|
#[cfg(not(unix))]
|
|
@@ -431,6 +431,10 @@ fn request(
|
|
|
431
431
|
return Err(ContractError::AmbiguousProfile.into());
|
|
432
432
|
}
|
|
433
433
|
profile.policy.require("native submit policy")?;
|
|
434
|
+
// The worker execs exactly the public command its runtime route was probed on.
|
|
435
|
+
let launcher = discovered.runtime.as_ref()
|
|
436
|
+
.ok_or(ContractError::Invalid("native runtime installation"))?
|
|
437
|
+
.launcher();
|
|
434
438
|
Ok(LaunchRequest {
|
|
435
439
|
provider: role.provider.as_str().into(),
|
|
436
440
|
operation: Operation::Fresh,
|
|
@@ -444,6 +448,7 @@ fn request(
|
|
|
444
448
|
identity,
|
|
445
449
|
native: discovered.native.clone(),
|
|
446
450
|
paths: LaunchPaths {
|
|
451
|
+
launcher,
|
|
447
452
|
executable: discovered.engine.clone(),
|
|
448
453
|
candidate: binding.candidate.clone(),
|
|
449
454
|
cwd: binding.workspace.clone(),
|
|
@@ -465,7 +470,7 @@ fn preflight_request(
|
|
|
465
470
|
discovered: &Discovery,
|
|
466
471
|
) -> Result<LaunchRequest, BackendError> {
|
|
467
472
|
let mut request = request(binding, role, identity, discovered)?;
|
|
468
|
-
if registry::provider(role.provider.as_str())
|
|
473
|
+
if matches!(registry::provider(role.provider.as_str())?, registry::NativeProvider::GrokBuild | registry::NativeProvider::Codex | registry::NativeProvider::Pi | registry::NativeProvider::Claude) {
|
|
469
474
|
// Pure H2 only: this is a proposed private path, not a filesystem receipt.
|
|
470
475
|
request.paths.cwd = team_agent_contract::contract::session::CwdIdentity {
|
|
471
476
|
path: binding.transport_root.join("workspaces").join(role.id.as_str()),
|
|
@@ -475,6 +480,22 @@ fn preflight_request(
|
|
|
475
480
|
Ok(request)
|
|
476
481
|
}
|
|
477
482
|
|
|
483
|
+
/// Providers whose native config search would otherwise inherit a Git or
|
|
484
|
+
/// project configuration ancestor. Metadata only; no body is read.
|
|
485
|
+
fn require_private_primary(
|
|
486
|
+
selected: registry::NativeProvider,
|
|
487
|
+
cwd: &team_agent_contract::contract::session::CwdIdentity,
|
|
488
|
+
) -> Result<(), BackendError> {
|
|
489
|
+
match selected {
|
|
490
|
+
registry::NativeProvider::GrokBuild => team_agent_contract::providers::grok_build::native::require_private_primary(cwd)?,
|
|
491
|
+
registry::NativeProvider::Codex => team_agent_contract::providers::codex::launcher::require_private_primary(cwd)?,
|
|
492
|
+
registry::NativeProvider::Pi => team_agent_contract::providers::pi::launcher::require_private_primary(cwd)?,
|
|
493
|
+
registry::NativeProvider::Claude => team_agent_contract::providers::claude::launcher::require_private_primary(cwd)?,
|
|
494
|
+
registry::NativeProvider::Kiro | registry::NativeProvider::Cursor => {}
|
|
495
|
+
}
|
|
496
|
+
Ok(())
|
|
497
|
+
}
|
|
498
|
+
|
|
478
499
|
/// Team-wide native discovery/admission before the shared launcher creates any
|
|
479
500
|
/// seats (including legacy peers). Bounded read-only native commands run; no
|
|
480
501
|
/// runtime store, worker config, private socket, or worker process is created.
|
|
@@ -788,8 +809,10 @@ pub fn start(
|
|
|
788
809
|
if !descriptor.workspace.shared_cwd {
|
|
789
810
|
request.paths.cwd = super::workspace::prepare(&backend.binding, &role.id)?;
|
|
790
811
|
}
|
|
791
|
-
|
|
792
|
-
|
|
812
|
+
require_private_primary(selected, &request.paths.cwd)?;
|
|
813
|
+
if selected == registry::NativeProvider::Claude {
|
|
814
|
+
// `--session-id` names the fresh session; derived from this proposed instance.
|
|
815
|
+
request.preassigned_session = Some(team_agent_contract::providers::claude::session_id(&request.identity));
|
|
793
816
|
}
|
|
794
817
|
if let Some(registry::NativeRuntime::Cursor(runtime)) = &discovered.runtime {
|
|
795
818
|
request.preassigned_session = Some(
|
|
@@ -937,9 +960,7 @@ pub fn prepare_resume(
|
|
|
937
960
|
binding: source, expected_source: parent.identity,
|
|
938
961
|
});
|
|
939
962
|
let selected = registry::provider(role.provider.as_str())?;
|
|
940
|
-
|
|
941
|
-
team_agent_contract::providers::grok_build::native::require_private_primary(&request.paths.cwd)?;
|
|
942
|
-
}
|
|
963
|
+
require_private_primary(selected, &request.paths.cwd)?;
|
|
943
964
|
let resolved = resolve_launch(selected.descriptor(), &hooks, &request, Some(&discovered.catalog))?;
|
|
944
965
|
validate_launch_plan(selected.descriptor(), &resolved, &adapter.plan(&resolved)?)?;
|
|
945
966
|
Ok(PreparedResume { binding: backend.binding, role, discovered, request })
|
|
@@ -1486,6 +1507,9 @@ mod tests {
|
|
|
1486
1507
|
ui: "metadata".into(), platform: Platform::MacOs, executable_sha256: digest(b"launcher"),
|
|
1487
1508
|
};
|
|
1488
1509
|
let mut discovery = Discovery {
|
|
1510
|
+
command: team_agent_contract::host::command::PublicCommand {
|
|
1511
|
+
name: "cursor-agent".into(), search_path: "/controlled".into(), entry: "/controlled/cursor-agent".into(),
|
|
1512
|
+
},
|
|
1489
1513
|
runtime: None,
|
|
1490
1514
|
engine: "/controlled/cursor-agent".into(), native: native.clone(),
|
|
1491
1515
|
catalog: CatalogObservation { provider, native,
|
|
@@ -99,25 +99,26 @@ fn mode(meta: &Value, path: &Path) -> Result<Option<CommunicationMode>, ConfigEr
|
|
|
99
99
|
.transpose()
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
+
/// `contract_runtime` is an exact boolean; a bare shared key stays legacy.
|
|
103
|
+
fn opted_in(meta: &Value, path: &Path) -> Result<bool, ConfigError> {
|
|
104
|
+
match meta.get("contract_runtime") {
|
|
105
|
+
None => Ok(false),
|
|
106
|
+
Some(Value::Bool(value)) => Ok(*value),
|
|
107
|
+
_ => Err(invalid(path, "contract_runtime")),
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
102
111
|
/// A malformed explicit contract header cannot fall back to the default Pi worker.
|
|
103
112
|
fn malformed_contract_header(body: &str) -> bool {
|
|
104
113
|
body.strip_prefix("---\n").is_some_and(|header| {
|
|
105
|
-
header
|
|
114
|
+
let fields: Vec<(&str, &str)> = header
|
|
106
115
|
.lines()
|
|
107
116
|
.take_while(|line| *line != "---")
|
|
108
|
-
.
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
.split('#')
|
|
114
|
-
.next()
|
|
115
|
-
.unwrap_or("")
|
|
116
|
-
.trim()
|
|
117
|
-
.trim_matches(['\'', '"']),
|
|
118
|
-
)
|
|
119
|
-
})
|
|
120
|
-
})
|
|
117
|
+
.filter_map(|line| line.split_once(':'))
|
|
118
|
+
.map(|(key, value)| (key.trim(), value.split('#').next().unwrap_or("").trim().trim_matches(['\'', '"'])))
|
|
119
|
+
.collect();
|
|
120
|
+
let opted_in = fields.iter().any(|(key, value)| *key == "contract_runtime" && *value == "true");
|
|
121
|
+
opted_in || fields.iter().any(|(key, value)| *key == "provider" && super::registry::recognizes(value, false))
|
|
121
122
|
})
|
|
122
123
|
}
|
|
123
124
|
|
|
@@ -177,13 +178,19 @@ fn read_team_inner(
|
|
|
177
178
|
};
|
|
178
179
|
let (meta, body) = split_front_matter(&raw);
|
|
179
180
|
let normalized = raw.replace("\r\n", "\n").replace('\r', "\n");
|
|
180
|
-
|
|
181
|
+
// Only an unparsed header loses both keys; an omitted provider is the default `pi`.
|
|
182
|
+
if meta.get("provider").is_none()
|
|
183
|
+
&& meta.get("contract_runtime").is_none()
|
|
184
|
+
&& malformed_contract_header(&normalized)
|
|
185
|
+
{
|
|
181
186
|
return Err(invalid(&path, "front matter"));
|
|
182
187
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
188
|
+
let opted = opted_in(&meta, &path)?;
|
|
189
|
+
if opted
|
|
190
|
+
|| meta
|
|
191
|
+
.get("provider")
|
|
192
|
+
.and_then(Value::as_str)
|
|
193
|
+
.is_some_and(|provider| super::registry::recognizes(provider, false))
|
|
187
194
|
{
|
|
188
195
|
selected = true;
|
|
189
196
|
}
|
|
@@ -247,9 +254,15 @@ fn read_team_inner(
|
|
|
247
254
|
if !ids.insert(id.clone()) {
|
|
248
255
|
return Err(invalid(&source, "duplicate agent id"));
|
|
249
256
|
}
|
|
257
|
+
// `leader` is the framework's own forwarding route. A role of that name
|
|
258
|
+
// on either runtime would shadow it, so refuse before any seat spawns.
|
|
259
|
+
if id == "leader" {
|
|
260
|
+
return Err(invalid(&source, "reserved worker id"));
|
|
261
|
+
}
|
|
250
262
|
let provider = text(&meta, "provider", &source)?.unwrap_or_else(|| "pi".into());
|
|
251
|
-
let
|
|
252
|
-
|
|
263
|
+
let opted = opted_in(&meta, &source)?;
|
|
264
|
+
let registration = super::registry::declared(&provider, opted);
|
|
265
|
+
if registration.is_none() && (opted || super::registry::recognizes(&provider, false)) {
|
|
253
266
|
return Err(invalid(&source, "provider"));
|
|
254
267
|
}
|
|
255
268
|
let runtime = if registration.is_some() {
|
|
@@ -269,9 +282,6 @@ fn read_team_inner(
|
|
|
269
282
|
let provider =
|
|
270
283
|
ProviderId::new(registration.identity.id).map_err(|_| invalid(&source, "provider"))?;
|
|
271
284
|
let id = SeatId::new(id).map_err(|_| invalid(&source, "agent id"))?;
|
|
272
|
-
if id.as_str() == "leader" {
|
|
273
|
-
return Err(invalid(&source, "reserved worker id"));
|
|
274
|
-
}
|
|
275
285
|
if text(&meta, "auth_mode", &source)?.is_some_and(|value| value != "subscription")
|
|
276
286
|
|| text(&meta, "profile", &source)?.is_some()
|
|
277
287
|
{
|
|
@@ -2,10 +2,13 @@
|
|
|
2
2
|
use std::path::{Path, PathBuf};
|
|
3
3
|
|
|
4
4
|
use team_agent_contract::contract::{hooks::*, plan::CatalogObservation, types::*};
|
|
5
|
-
use team_agent_contract::host::{command::RealCommandRunner, process::resolve_cwd};
|
|
5
|
+
use team_agent_contract::host::{command::{PublicCommand, RealCommandRunner}, process::resolve_cwd};
|
|
6
6
|
use team_agent_contract::kiro::native as kiro;
|
|
7
|
+
use team_agent_contract::providers::claude::{catalog as claude_catalog, launcher as claude};
|
|
8
|
+
use team_agent_contract::providers::codex::{catalog as codex_catalog, launcher as codex};
|
|
7
9
|
use team_agent_contract::providers::cursor::native as cursor;
|
|
8
10
|
use team_agent_contract::providers::grok_build::native as grok;
|
|
11
|
+
use team_agent_contract::providers::pi::{catalog as pi_catalog, launcher as pi};
|
|
9
12
|
use thiserror::Error;
|
|
10
13
|
|
|
11
14
|
use super::registry::{self, NativeProvider, NativeRuntime};
|
|
@@ -22,6 +25,12 @@ pub enum DiscoveryError {
|
|
|
22
25
|
CursorProbe(#[from] cursor::ProbeError),
|
|
23
26
|
#[error("native Grok launcher probe failed: {0}")]
|
|
24
27
|
GrokProbe(#[from] grok::ProbeError),
|
|
28
|
+
#[error("native Codex launcher probe failed: {0}")]
|
|
29
|
+
CodexProbe(#[from] codex_catalog::ProbeError),
|
|
30
|
+
#[error("native Pi launcher probe failed: {0}")]
|
|
31
|
+
PiProbe(#[from] pi_catalog::ProbeError),
|
|
32
|
+
#[error("native Claude launcher probe failed: {0}")]
|
|
33
|
+
ClaudeProbe(#[from] claude_catalog::ProbeError),
|
|
25
34
|
#[error("native discovery contract: {0:?}")]
|
|
26
35
|
Contract(ContractError),
|
|
27
36
|
#[error("native model discovery: {0:?}")]
|
|
@@ -31,12 +40,16 @@ pub enum DiscoveryError {
|
|
|
31
40
|
}
|
|
32
41
|
|
|
33
42
|
pub struct Discovery {
|
|
43
|
+
/// The provider's public command exactly as the user's shell resolves it.
|
|
44
|
+
pub command: PublicCommand,
|
|
34
45
|
pub engine: PathBuf,
|
|
35
46
|
pub native: NativeIdentity,
|
|
36
47
|
pub catalog: CatalogObservation,
|
|
37
48
|
pub runtime: Option<NativeRuntime>,
|
|
38
49
|
}
|
|
39
50
|
|
|
51
|
+
/// Canonical tool path for framework infrastructure such as tmux. Providers
|
|
52
|
+
/// never use this: they launch their public command through [`public_command`].
|
|
40
53
|
pub fn executable(name: &'static str) -> Result<PathBuf, DiscoveryError> {
|
|
41
54
|
let path = std::env::var_os("PATH").ok_or(DiscoveryError::Executable(name))?;
|
|
42
55
|
for directory in std::env::split_paths(&path) {
|
|
@@ -52,6 +65,13 @@ pub fn executable(name: &'static str) -> Result<PathBuf, DiscoveryError> {
|
|
|
52
65
|
Err(DiscoveryError::Executable(name))
|
|
53
66
|
}
|
|
54
67
|
|
|
68
|
+
/// The first `name` on this process's PATH, kept as found so user wrappers and
|
|
69
|
+
/// vendor symlinks stay in the route. No install directory is ever guessed.
|
|
70
|
+
pub fn public_command(name: &'static str) -> Result<PublicCommand, DiscoveryError> {
|
|
71
|
+
let path = std::env::var_os("PATH").ok_or(DiscoveryError::Executable(name))?;
|
|
72
|
+
PublicCommand::resolve(name, &path).map_err(|_| DiscoveryError::Executable(name))
|
|
73
|
+
}
|
|
74
|
+
|
|
55
75
|
pub fn discover(provider: &ProviderId, workspace: &Path) -> Result<Discovery, DiscoveryError> {
|
|
56
76
|
let selected = registry::provider(provider.as_str()).map_err(DiscoveryError::Contract)?;
|
|
57
77
|
let descriptor = selected.descriptor();
|
|
@@ -59,43 +79,26 @@ pub fn discover(provider: &ProviderId, workspace: &Path) -> Result<Discovery, Di
|
|
|
59
79
|
deadline: std::time::Duration::from_secs(30),
|
|
60
80
|
max_output_bytes: 1024 * 1024,
|
|
61
81
|
};
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
NativeProvider::
|
|
71
|
-
let home = std::env::var_os("HOME")
|
|
72
|
-
.map(PathBuf::from)
|
|
73
|
-
.ok_or(DiscoveryError::Executable("HOME for native installation lookup"))?;
|
|
74
|
-
let engine = kiro::resolve_helper(&launcher, &home)?;
|
|
75
|
-
let native = kiro::probe_engine(&engine, &mut RealCommandRunner::default(), bounds)?;
|
|
76
|
-
(engine, native)
|
|
77
|
-
}
|
|
78
|
-
NativeProvider::Cursor => {
|
|
79
|
-
let engine = cursor::resolve_launcher(&launcher)?;
|
|
80
|
-
let native = cursor::probe_launcher(&engine, &mut RealCommandRunner::default(), bounds)?;
|
|
81
|
-
(engine, native)
|
|
82
|
-
}
|
|
83
|
-
NativeProvider::GrokBuild => {
|
|
84
|
-
let engine = grok::resolve_launcher(&launcher)?;
|
|
85
|
-
let native = grok::probe_launcher(&engine, &mut RealCommandRunner::default(), bounds)?;
|
|
86
|
-
(engine, native)
|
|
87
|
-
}
|
|
82
|
+
// Every metadata probe runs the PATH-selected entry, wrappers included.
|
|
83
|
+
let command = public_command(descriptor.identity.binary)?;
|
|
84
|
+
let native = match selected {
|
|
85
|
+
NativeProvider::Kiro => kiro::probe_launcher(&command, &mut RealCommandRunner::default(), bounds)?,
|
|
86
|
+
NativeProvider::Cursor => cursor::probe_launcher(&command, &mut RealCommandRunner::default(), bounds)?,
|
|
87
|
+
NativeProvider::GrokBuild => grok::probe_launcher(&command, &mut RealCommandRunner::default(), bounds)?,
|
|
88
|
+
NativeProvider::Codex => codex_catalog::probe_launcher(&command, &mut RealCommandRunner::default(), bounds)?,
|
|
89
|
+
NativeProvider::Pi => pi_catalog::probe_launcher(&command, &mut RealCommandRunner::default(), bounds)?,
|
|
90
|
+
NativeProvider::Claude => claude_catalog::probe_launcher(&command, &mut RealCommandRunner::default(), bounds)?,
|
|
88
91
|
};
|
|
89
92
|
let request = CatalogRequest {
|
|
90
93
|
provider: ProviderId::new(descriptor.identity.id).map_err(DiscoveryError::Contract)?,
|
|
91
94
|
native: native.clone(),
|
|
92
|
-
executable:
|
|
95
|
+
executable: command.entry.clone(),
|
|
93
96
|
cwd: resolve_cwd(workspace)?,
|
|
94
97
|
source: descriptor.model.catalog.require("native catalog source").map_err(DiscoveryError::Contract)?.clone(),
|
|
95
98
|
bounds,
|
|
96
99
|
};
|
|
97
|
-
// H1 does not use these pointers or execute an MCP server.
|
|
98
|
-
//
|
|
100
|
+
// H1 does not use these pointers or execute an MCP server. The launcher
|
|
101
|
+
// fingerprint authorizes only metadata reads, never worker launch.
|
|
99
102
|
let adapter = selected.adapter(
|
|
100
103
|
std::env::current_exe()?.canonicalize()?,
|
|
101
104
|
Vec::new(),
|
|
@@ -119,39 +122,53 @@ pub fn discover(provider: &ProviderId, workspace: &Path) -> Result<Discovery, Di
|
|
|
119
122
|
.map_err(DiscoveryError::Contract)?;
|
|
120
123
|
catalog_hook.discover(&request, &mut host)
|
|
121
124
|
}
|
|
125
|
+
NativeProvider::Codex => {
|
|
126
|
+
let mut host = codex_catalog::NativeCatalog::new(request.clone(), RealCommandRunner::default())
|
|
127
|
+
.map_err(DiscoveryError::Contract)?;
|
|
128
|
+
catalog_hook.discover(&request, &mut host)
|
|
129
|
+
}
|
|
130
|
+
NativeProvider::Pi => {
|
|
131
|
+
let mut host = pi_catalog::NativeCatalog::new(request.clone(), RealCommandRunner::default())
|
|
132
|
+
.map_err(DiscoveryError::Contract)?;
|
|
133
|
+
catalog_hook.discover(&request, &mut host)
|
|
134
|
+
}
|
|
135
|
+
NativeProvider::Claude => {
|
|
136
|
+
let mut host = claude_catalog::NativeCatalog::new(request.clone(), RealCommandRunner::default())
|
|
137
|
+
.map_err(DiscoveryError::Contract)?;
|
|
138
|
+
catalog_hook.discover(&request, &mut host)
|
|
139
|
+
}
|
|
122
140
|
}.map_err(DiscoveryError::Catalog)?;
|
|
123
|
-
let result = Discovery { engine, native, catalog, runtime: None };
|
|
141
|
+
let result = Discovery { engine: command.entry.clone(), command, native, catalog, runtime: None };
|
|
124
142
|
validate_catalog(provider, &result).map_err(DiscoveryError::Contract)?;
|
|
125
143
|
Ok(result)
|
|
126
144
|
}
|
|
127
145
|
|
|
128
|
-
/// Runtime discovery is separate from public catalog metadata.
|
|
129
|
-
/// bridges
|
|
146
|
+
/// Runtime discovery is separate from public catalog metadata. Each provider
|
|
147
|
+
/// bridges its catalog to the native image its public command route execs into.
|
|
130
148
|
pub(super) fn discover_runtime(provider: &ProviderId, workspace: &Path) -> Result<Discovery, DiscoveryError> {
|
|
131
149
|
let mut discovery = discover(provider, workspace)?;
|
|
132
150
|
let selected = registry::provider(provider.as_str()).map_err(DiscoveryError::Contract)?;
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
151
|
+
let bounds = ReadBounds { deadline: std::time::Duration::from_secs(30), max_output_bytes: 1024 * 1024 };
|
|
152
|
+
let home = || std::env::var_os("HOME").map(PathBuf::from)
|
|
153
|
+
.ok_or(DiscoveryError::Executable("HOME for native subscription"));
|
|
154
|
+
let runtime = match selected {
|
|
155
|
+
NativeProvider::Kiro => NativeRuntime::Kiro(
|
|
156
|
+
kiro::probe_runtime(&discovery.command, &mut RealCommandRunner::default(), bounds)?),
|
|
157
|
+
NativeProvider::Cursor => NativeRuntime::Cursor(
|
|
158
|
+
cursor::probe_runtime(&discovery.command, &home()?, &mut RealCommandRunner::default(), bounds)?),
|
|
159
|
+
NativeProvider::GrokBuild => NativeRuntime::GrokBuild(
|
|
160
|
+
grok::probe_runtime(&discovery.command, &home()?, &mut RealCommandRunner::default(), bounds)?),
|
|
161
|
+
NativeProvider::Codex => NativeRuntime::Codex(
|
|
162
|
+
codex::probe_runtime(&discovery.command, &home()?, &mut RealCommandRunner::default(), bounds)?),
|
|
163
|
+
NativeProvider::Pi => NativeRuntime::Pi(
|
|
164
|
+
pi::probe_runtime(&discovery.command, &home()?, &mut RealCommandRunner::default(), bounds)?),
|
|
165
|
+
NativeProvider::Claude => NativeRuntime::Claude(
|
|
166
|
+
claude::probe_runtime(&discovery.command, &home()?, &mut RealCommandRunner::default(), bounds)?),
|
|
167
|
+
};
|
|
168
|
+
discovery.catalog = runtime.bind_catalog(&discovery.catalog).map_err(DiscoveryError::Contract)?;
|
|
169
|
+
discovery.engine = runtime.engine().clone();
|
|
170
|
+
discovery.native = runtime.native().clone();
|
|
171
|
+
discovery.runtime = Some(runtime);
|
|
155
172
|
Ok(discovery)
|
|
156
173
|
}
|
|
157
174
|
|
|
@@ -245,6 +262,10 @@ mod tests {
|
|
|
245
262
|
use crate::cli::{CmdOutput, ExitCode, ModelsArgs};
|
|
246
263
|
use team_agent_contract::contract::plan::ModelRecord;
|
|
247
264
|
|
|
265
|
+
fn controlled_command(name: &str) -> PublicCommand {
|
|
266
|
+
PublicCommand { name: name.into(), search_path: "/controlled".into(), entry: format!("/controlled/{name}").into() }
|
|
267
|
+
}
|
|
268
|
+
|
|
248
269
|
#[test]
|
|
249
270
|
fn native_catalog_projection_preserves_ids_without_claiming_auth_or_effort() {
|
|
250
271
|
let native = NativeIdentity {
|
|
@@ -255,8 +276,9 @@ mod tests {
|
|
|
255
276
|
executable_sha256: Digest([1; 32]),
|
|
256
277
|
};
|
|
257
278
|
let discovery = Discovery {
|
|
279
|
+
command: controlled_command("kiro-cli"),
|
|
258
280
|
runtime: None,
|
|
259
|
-
engine: "/controlled/kiro-cli
|
|
281
|
+
engine: "/controlled/kiro-cli".into(),
|
|
260
282
|
native: native.clone(),
|
|
261
283
|
catalog: CatalogObservation {
|
|
262
284
|
provider: ProviderId::new("kiro").unwrap(),
|
|
@@ -319,6 +341,7 @@ mod tests {
|
|
|
319
341
|
executable_sha256: Digest([2; 32]),
|
|
320
342
|
};
|
|
321
343
|
Discovery {
|
|
344
|
+
command: controlled_command("cursor-agent"),
|
|
322
345
|
runtime: None,
|
|
323
346
|
engine: "/controlled/cursor-agent".into(),
|
|
324
347
|
native: native.clone(),
|
|
@@ -54,15 +54,27 @@ pub fn require_legacy_lifecycle(
|
|
|
54
54
|
) else {
|
|
55
55
|
return Ok(());
|
|
56
56
|
};
|
|
57
|
+
let row = agent.and_then(|id| selected.state.get("agents").and_then(|agents| agents.get(id)));
|
|
58
|
+
// A pre-upgrade legacy Cursor seat has no engine left; only teardown is admitted.
|
|
59
|
+
let teardown = matches!(operation, "stop-agent" | "remove-agent");
|
|
60
|
+
if !teardown
|
|
61
|
+
&& row
|
|
62
|
+
.and_then(|row| row.get("provider"))
|
|
63
|
+
.and_then(Value::as_str)
|
|
64
|
+
.is_some_and(crate::provider::wire::is_retired_provider)
|
|
65
|
+
{
|
|
66
|
+
return Err(crate::cli::CliError::Runtime(
|
|
67
|
+
crate::provider::wire::RETIRED_PROVIDER_ERROR.into(),
|
|
68
|
+
));
|
|
69
|
+
}
|
|
57
70
|
let selected_native = match agent {
|
|
58
|
-
Some(
|
|
59
|
-
.state
|
|
60
|
-
.get("agents")
|
|
61
|
-
.and_then(|agents| agents.get(id))
|
|
62
|
-
.is_some_and(is_contract),
|
|
71
|
+
Some(_) => row.is_some_and(is_contract),
|
|
63
72
|
None => has_contract(&selected.state),
|
|
64
73
|
};
|
|
65
|
-
|
|
74
|
+
// A recorded legacy seat is torn down on its own runtime even when its role
|
|
75
|
+
// document now declares a contract leaf (`cursor_agent` before the upgrade).
|
|
76
|
+
let configured_native = !(teardown && row.is_some())
|
|
77
|
+
&& selected
|
|
66
78
|
.state
|
|
67
79
|
.get("team_dir")
|
|
68
80
|
.and_then(Value::as_str)
|
|
@@ -88,23 +100,28 @@ pub fn require_legacy_role(
|
|
|
88
100
|
path: Option<&Path>,
|
|
89
101
|
provider: Option<&str>,
|
|
90
102
|
) -> Result<(), crate::cli::CliError> {
|
|
91
|
-
|
|
92
|
-
.and_then(|path| std::fs::read_to_string(path).ok())
|
|
93
|
-
.and_then(|raw| {
|
|
94
|
-
crate::compiler::split_front_matter(&raw)
|
|
95
|
-
.0
|
|
96
|
-
.get("provider")
|
|
97
|
-
.and_then(crate::model::yaml::Value::as_str)
|
|
98
|
-
.map(str::to_owned)
|
|
99
|
-
});
|
|
100
|
-
if provider
|
|
101
|
-
.or(declared.as_deref())
|
|
102
|
-
.is_some_and(super::registry::recognizes)
|
|
103
|
-
{
|
|
103
|
+
if declares_contract(path, provider) {
|
|
104
104
|
return Err(crate::cli::CliError::Runtime("contract_capability_unverified: mutable contract-native role lifecycle is not admitted; use initial quick-start; no role file was changed".into()));
|
|
105
105
|
}
|
|
106
106
|
Ok(())
|
|
107
107
|
}
|
|
108
|
+
/// Whether a role document or CLI provider value selects a contract leaf.
|
|
109
|
+
pub fn declares_contract(path: Option<&Path>, provider: Option<&str>) -> bool {
|
|
110
|
+
let meta = path
|
|
111
|
+
.and_then(|path| std::fs::read_to_string(path).ok())
|
|
112
|
+
.map(|raw| crate::compiler::split_front_matter(&raw).0);
|
|
113
|
+
let declared = meta.as_ref().and_then(|meta| {
|
|
114
|
+
meta.get("provider")
|
|
115
|
+
.and_then(crate::model::yaml::Value::as_str)
|
|
116
|
+
.map(str::to_owned)
|
|
117
|
+
});
|
|
118
|
+
let opted_in = meta.as_ref().is_some_and(|meta| {
|
|
119
|
+
matches!(meta.get("contract_runtime"), Some(crate::model::yaml::Value::Bool(true)))
|
|
120
|
+
});
|
|
121
|
+
provider
|
|
122
|
+
.or(declared.as_deref())
|
|
123
|
+
.is_some_and(|provider| super::registry::recognizes(provider, opted_in))
|
|
124
|
+
}
|
|
108
125
|
pub fn team_config(
|
|
109
126
|
workspace: &Path,
|
|
110
127
|
directory: &Path,
|
|
@@ -132,21 +149,7 @@ pub fn start_role(
|
|
|
132
149
|
if directory.canonicalize()? != selected.team_dir.canonicalize()? {
|
|
133
150
|
return Err(error("native role source changed while acquiring lifecycle ownership".into()));
|
|
134
151
|
}
|
|
135
|
-
|
|
136
|
-
.map_err(|e| error(e.to_string()))?
|
|
137
|
-
.ok_or_else(|| error("contract role no longer configured".into()))?;
|
|
138
|
-
let role = config.roles.iter().find(|role| &role.id == seat)
|
|
139
|
-
.ok_or_else(|| error("contract role not found".into()))?;
|
|
140
|
-
let (_, record) = backend::start(&selected.run_workspace, &selected.team_key, role, &config.members)
|
|
141
|
-
.map_err(|e| error(e.to_string()))?;
|
|
142
|
-
if record.outcome != Outcome::Committed {
|
|
143
|
-
return Err(error(format!("native startup seat={id} operation={:?} phase={:?} outcome={:?}: {}",
|
|
144
|
-
record.id, record.phase, record.outcome, record.failure.unwrap_or_default())));
|
|
145
|
-
}
|
|
146
|
-
// Preserve each committed seat before a later discovery/spawn can fail.
|
|
147
|
-
// A whole-batch error must never hide this generation's physical effects.
|
|
148
|
-
let projected = super::commands::publish_at(&selected.run_workspace, &selected.team_key, seat, true)?;
|
|
149
|
-
Ok(projected)
|
|
152
|
+
start_configured(&selected.run_workspace, &selected.team_dir, &selected.team_key, seat)
|
|
150
153
|
}).map_err(|e| crate::lifecycle::LifecycleError::Provider(e.to_string()))?;
|
|
151
154
|
if result.is_none() {
|
|
152
155
|
return Err(crate::lifecycle::LifecycleError::Provider("native startup scope/seat is not addressable; no legacy fallback".into()));
|
|
@@ -154,6 +157,58 @@ pub fn start_role(
|
|
|
154
157
|
Ok(())
|
|
155
158
|
}
|
|
156
159
|
|
|
160
|
+
/// Start one configured contract role and publish its seat. The caller holds
|
|
161
|
+
/// the lifecycle lock (or owns the whole launch) and has seeded the state row.
|
|
162
|
+
pub(crate) fn start_configured(
|
|
163
|
+
workspace: &Path,
|
|
164
|
+
directory: &Path,
|
|
165
|
+
team: &str,
|
|
166
|
+
seat: &SeatId,
|
|
167
|
+
) -> Result<Value, crate::cli::CliError> {
|
|
168
|
+
let error = |error: String| crate::cli::CliError::Runtime(error);
|
|
169
|
+
let config = team_config(workspace, directory, team)
|
|
170
|
+
.map_err(|e| error(e.to_string()))?
|
|
171
|
+
.ok_or_else(|| error("contract role no longer configured".into()))?;
|
|
172
|
+
let role = config.roles.iter().find(|role| &role.id == seat)
|
|
173
|
+
.ok_or_else(|| error(format!("contract role not found in {}", directory.join("agents").display())))?;
|
|
174
|
+
let (_, record) = backend::start(workspace, team, role, &config.members)
|
|
175
|
+
.map_err(|e| error(e.to_string()))?;
|
|
176
|
+
if record.outcome != Outcome::Committed {
|
|
177
|
+
return Err(error(format!("native startup seat={} operation={:?} phase={:?} outcome={:?}: {}",
|
|
178
|
+
seat.as_str(), record.id, record.phase, record.outcome, record.failure.unwrap_or_default())));
|
|
179
|
+
}
|
|
180
|
+
// Preserve each committed seat before a later discovery/spawn can fail.
|
|
181
|
+
// A whole-batch error must never hide this generation's physical effects.
|
|
182
|
+
super::commands::publish_at(workspace, team, seat, true)
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/// add-agent owns a brand-new seat. If its start committed but publication
|
|
186
|
+
/// failed, stop that seat before the caller rolls its row back: a refused add
|
|
187
|
+
/// never leaves a running native process outside status/stop. An unpublished
|
|
188
|
+
/// spawn stays with its fenced receipt for explicit recovery.
|
|
189
|
+
pub(crate) fn start_new_seat(
|
|
190
|
+
workspace: &Path,
|
|
191
|
+
directory: &Path,
|
|
192
|
+
team: &str,
|
|
193
|
+
seat: &SeatId,
|
|
194
|
+
) -> Result<(), crate::cli::CliError> {
|
|
195
|
+
let Err(error) = start_configured(workspace, directory, team, seat) else {
|
|
196
|
+
return Ok(());
|
|
197
|
+
};
|
|
198
|
+
let started = Backend::open_readonly(workspace, team)
|
|
199
|
+
.ok()
|
|
200
|
+
.and_then(|backend| backend.store.seat(seat).ok().flatten())
|
|
201
|
+
.is_some_and(|current| current.status != SeatStatus::Stopped && current.physical.is_some());
|
|
202
|
+
if started {
|
|
203
|
+
if let Err(stop) = backend::stop(workspace, team, seat) {
|
|
204
|
+
return Err(crate::cli::CliError::Runtime(format!(
|
|
205
|
+
"{error}; stopping the started native seat failed: {stop}"
|
|
206
|
+
)));
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
Err(error)
|
|
210
|
+
}
|
|
211
|
+
|
|
157
212
|
pub fn project_seat(workspace: &Path, team: &str, id: &str) -> Result<Value, BackendError> {
|
|
158
213
|
let mut backend = Backend::open_readonly(workspace, team)?;
|
|
159
214
|
let seat = backend
|