@team-agent/installer 0.5.126 → 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 -91
- package/crates/team-agent/src/cli/emit.rs +61 -28
- package/crates/team-agent/src/cli/grok_slot.rs +88 -3
- package/crates/team-agent/src/cli/intent/runtime.rs +38 -9
- package/crates/team-agent/src/cli/intent/runtime_tests.rs +147 -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 +38 -9
- package/crates/team-agent/src/cli/models.rs +789 -186
- 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 +3 -3
- package/crates/team-agent/src/cli/tests/named_address.rs +11 -10
- package/crates/team-agent/src/cli/tests/run_delegation.rs +12 -9
- package/crates/team-agent/src/cli/tests/status_send.rs +70 -273
- package/crates/team-agent/src/compiler/tests.rs +39 -27
- package/crates/team-agent/src/compiler.rs +206 -6
- package/crates/team-agent/src/contract_runtime/backend.rs +181 -11
- package/crates/team-agent/src/contract_runtime/commands.rs +338 -7
- package/crates/team-agent/src/contract_runtime/config.rs +30 -19
- 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 -14
- 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 +93 -130
- package/crates/team-agent/src/coordinator/steps/abnormal.rs +45 -5
- package/crates/team-agent/src/coordinator/tests/api_error_recovery.rs +8 -29
- package/crates/team-agent/src/coordinator/tests/energy.rs +4 -4
- package/crates/team-agent/src/coordinator/tests/health_sync.rs +44 -2
- package/crates/team-agent/src/coordinator/tests/main_preserved.rs +2 -2
- package/crates/team-agent/src/coordinator/tests/spine.rs +1 -1
- package/crates/team-agent/src/coordinator/tests/takeover.rs +3 -3
- 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 +36 -179
- package/crates/team-agent/src/lifecycle/launch/fork_entry.rs +87 -6
- package/crates/team-agent/src/lifecycle/launch/mcp_config.rs +13 -488
- 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 +26 -2
- package/crates/team-agent/src/lifecycle/launch/spawn.rs +41 -31
- package/crates/team-agent/src/lifecycle/launch.rs +27 -12
- package/crates/team-agent/src/lifecycle/profile_launch.rs +318 -64
- 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 +298 -133
- package/crates/team-agent/src/lifecycle/restart/remove.rs +129 -0
- 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 +79 -27
- package/crates/team-agent/src/lifecycle/tests/acceptance_b_batch_red.rs +1 -1
- package/crates/team-agent/src/lifecycle/tests/agent_ops.rs +8 -12
- package/crates/team-agent/src/lifecycle/tests/behavioral_diff_264_red.rs +37 -240
- 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 +329 -70
- 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 +25 -39
- package/crates/team-agent/src/lifecycle/tests/copilot_provider_red.rs +7 -11
- package/crates/team-agent/src/lifecycle/tests/core.rs +39 -36
- package/crates/team-agent/src/lifecycle/tests/f032_startup_prompt_best_effort_red.rs +22 -8
- 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 +15 -133
- package/crates/team-agent/src/lifecycle/tests/harvest2_a_batch_red.rs +60 -20
- package/crates/team-agent/src/lifecycle/tests/host_cotenant_death_p0_contract.rs +30 -67
- package/crates/team-agent/src/lifecycle/tests/issue238_codex_effort_contract.rs +3 -31
- package/crates/team-agent/src/lifecycle/tests/lane_ops.rs +194 -169
- package/crates/team-agent/src/lifecycle/tests/launch_spawn.rs +164 -282
- package/crates/team-agent/src/lifecycle/tests/lifecycle_rollback_red.rs +15 -78
- package/crates/team-agent/src/lifecycle/tests/main_preserved.rs +7 -7
- package/crates/team-agent/src/lifecycle/tests/mcp_tool_name_format_red.rs +6 -6
- package/crates/team-agent/src/lifecycle/tests/phase_b_contracts.rs +75 -69
- package/crates/team-agent/src/lifecycle/tests/phase_golden.rs +2 -10
- 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 +14 -15
- package/crates/team-agent/src/lifecycle/tests/restart.rs +12 -153
- package/crates/team-agent/src/lifecycle/tests/restart_build_before_destroy_0540_contract.rs +27 -5
- package/crates/team-agent/src/lifecycle/tests/restart_liveness_red.rs +59 -10
- package/crates/team-agent/src/lifecycle/tests/restart_rebind_hotfix_252_red.rs +47 -6
- package/crates/team-agent/src/lifecycle/tests/restart_session_capture_red.rs +3 -1374
- package/crates/team-agent/src/lifecycle/tests/resume_recover_red.rs +27 -10
- package/crates/team-agent/src/lifecycle/tests/status_credential_redaction_contract.rs +7 -7
- package/crates/team-agent/src/lifecycle/tests/subprep_codex_trust_roundtrip_red.rs +67 -313
- package/crates/team-agent/src/lifecycle/tests/swallow_batch4_semantics_red.rs +254 -2
- package/crates/team-agent/src/lifecycle/tests/team_in_team_identity_scope_red.rs +2 -2
- package/crates/team-agent/src/lifecycle/tests/team_in_team_sibling_quick_start_red.rs +1 -1
- package/crates/team-agent/src/lifecycle/tests/team_in_team_state_scope_red.rs +2 -2
- package/crates/team-agent/src/lifecycle/tests/team_key_retirement_txn_red.rs +4 -4
- package/crates/team-agent/src/lifecycle/tests/upgrade_compat_0211_red.rs +74 -19
- package/crates/team-agent/src/lifecycle/tests/verify_rs031_window_consistency_red.rs +38 -39
- package/crates/team-agent/src/lifecycle/tests/worker_spawn_env_red.rs +51 -88
- package/crates/team-agent/src/lifecycle/tests.rs +3 -4
- package/crates/team-agent/src/lifecycle/types.rs +18 -5
- 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 +86 -109
- 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 +143 -253
- 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 +255 -150
- package/crates/team-agent/src/messaging/tests/main_preserved.rs +2 -2
- package/crates/team-agent/src/messaging/tests/runtime.rs +9 -115
- package/crates/team-agent/src/messaging/tests/spine.rs +44 -24
- package/crates/team-agent/src/messaging/tests/wave2.rs +13 -20
- package/crates/team-agent/src/messaging/types.rs +1 -0
- package/crates/team-agent/src/provider/adapter.rs +208 -254
- 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 -7
- 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 +111 -111
- package/crates/team-agent/src/provider/session/context_fork/claude.rs +123 -0
- package/crates/team-agent/src/provider/session/context_fork/outcome.rs +10 -18
- package/crates/team-agent/src/provider/session/context_fork.rs +87 -74
- package/crates/team-agent/src/provider/session/mod.rs +2 -3
- package/crates/team-agent/src/provider/session_scan/claude.rs +523 -0
- package/crates/team-agent/src/provider/session_scan/common.rs +47 -47
- package/crates/team-agent/src/provider/session_scan/pi.rs +34 -1
- package/crates/team-agent/src/provider/session_scan.rs +13 -13
- package/crates/team-agent/src/provider/tests/adapter.rs +127 -121
- package/crates/team-agent/src/provider/tests/classify.rs +0 -53
- package/crates/team-agent/src/provider/tests/command_helpers.rs +11 -19
- package/crates/team-agent/src/provider/tests/idle.rs +13 -19
- package/crates/team-agent/src/provider/types.rs +0 -4
- package/crates/team-agent/src/provider/wire.rs +34 -20
- 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 +9 -43
- package/package.json +4 -4
- package/skills/team-agent/SKILL.md +7 -8
- package/skills/team-agent/command-coverage.json +15 -1
- package/skills/team-agent/docs/reference/team-agent-operator.md +5 -3
- package/skills/team-agent/references/team-agent-operator.md +5 -3
- package/crates/team-agent/src/lifecycle/launch/grok_per_seat.rs +0 -260
- package/crates/team-agent/src/lifecycle/tests/codex_weak_window_attribution_red.rs +0 -683
- package/crates/team-agent/src/lifecycle/tests/grok_effort_argv_red.rs +0 -247
- package/crates/team-agent/src/lifecycle/tests/grok_mcp_overlay_red.rs +0 -507
- package/crates/team-agent/src/lifecycle/tests/grok_restart_resume_red.rs +0 -300
- package/crates/team-agent/src/provider/adapters/codex.rs +0 -101
- package/crates/team-agent/src/provider/adapters/grok.rs +0 -67
- package/crates/team-agent/src/provider/session/context_fork/codex.rs +0 -514
- package/crates/team-agent/src/provider/session_scan/codex.rs +0 -326
- package/crates/team-agent/src/provider/session_scan/grok.rs +0 -288
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
//! Public lifecycle dispatch for contract seats. A private native pane is never
|
|
2
2
|
//! operated through the legacy workspace socket or provider-enum fallback.
|
|
3
3
|
use std::path::Path;
|
|
4
|
+
use std::time::Duration;
|
|
4
5
|
|
|
5
6
|
use serde_json::{json, Value};
|
|
6
|
-
use team_agent_contract::contract::
|
|
7
|
+
use team_agent_contract::contract::delivery::InputSurface;
|
|
8
|
+
use team_agent_contract::contract::probe::{PaneReadyEvidence, Probe, ProbeOutcome};
|
|
9
|
+
use team_agent_contract::contract::types::{Digest, OperationId, SeatId};
|
|
10
|
+
use team_agent_contract::host::{clock::RealClock, process::{sample_process, ProcessState}};
|
|
11
|
+
use team_agent_contract::orchestration::physical::{PhysicalRuntime, Registration};
|
|
7
12
|
use team_agent_contract::orchestration::store::{Outcome, SeatStatus};
|
|
8
13
|
|
|
9
14
|
use crate::cli::CliError;
|
|
@@ -12,7 +17,7 @@ use crate::model::ids::AgentId;
|
|
|
12
17
|
use crate::state::repository::{StateRepository, StateWriteIntent};
|
|
13
18
|
use crate::state::selector::{resolve_active_team_readonly, SelectedTeam, SelectorMode};
|
|
14
19
|
|
|
15
|
-
use super::{backend::{self, Backend, BackendError}, config, framework};
|
|
20
|
+
use super::{backend::{self, Backend, BackendError}, config, framework, registry};
|
|
16
21
|
|
|
17
22
|
fn error(error: impl std::fmt::Display) -> CliError {
|
|
18
23
|
CliError::Runtime(error.to_string())
|
|
@@ -105,15 +110,15 @@ pub fn start_agent(
|
|
|
105
110
|
};
|
|
106
111
|
// Contract configuration, not a stale legacy dynamic_role_file, is the
|
|
107
112
|
// authoritative source. Never patch an unrelated external role file.
|
|
108
|
-
let original = config::
|
|
113
|
+
let original = config::read_seat(&args, agent).map_err(error)?.ok_or(BackendError::Metadata).map_err(error)?;
|
|
109
114
|
let source = original.roles.iter().find(|role| &role.id == id)
|
|
110
115
|
.ok_or(BackendError::Metadata).map_err(error)?.source.clone();
|
|
111
116
|
let previous = std::fs::read_to_string(&source).map_err(error)?;
|
|
112
117
|
let next = crate::lifecycle::role_config::patched_role(&previous, &AgentId::new(agent), patch, false).map_err(error)?;
|
|
113
|
-
let config = config::read_team_with_role_override(&args, &source, &next).map_err(error)?.ok_or(BackendError::Metadata).map_err(error)?;
|
|
118
|
+
let config = config::read_team_with_role_override(&args, &source, &next, agent).map_err(error)?.ok_or(BackendError::Metadata).map_err(error)?;
|
|
114
119
|
let role = config.roles.iter().find(|role| &role.id == id).ok_or(BackendError::Metadata).map_err(error)?;
|
|
115
120
|
let row = selected.state.get("agents").and_then(|agents| agents.get(agent)).ok_or(BackendError::Metadata).map_err(error)?;
|
|
116
|
-
if row.get("provider").and_then(Value::as_str)
|
|
121
|
+
if !registry::same_provider(row.get("provider").and_then(Value::as_str).unwrap_or(""), role.provider.as_str()) {
|
|
117
122
|
return Err(error("provider change requires a new seat identity"));
|
|
118
123
|
}
|
|
119
124
|
if role.paused {
|
|
@@ -127,8 +132,12 @@ pub fn start_agent(
|
|
|
127
132
|
backend::preflight(&config).map_err(error)?;
|
|
128
133
|
}
|
|
129
134
|
let before = if unstarted { None } else {
|
|
130
|
-
Backend::open_readonly(&selected.run_workspace, &selected.team_key).map_err(error)
|
|
131
|
-
|
|
135
|
+
let backend = Backend::open_readonly(&selected.run_workspace, &selected.team_key).map_err(error)?;
|
|
136
|
+
// A retired generation is history, not a session this start resumes.
|
|
137
|
+
match backend.store.creation_receipt(id, None).map_err(error)? {
|
|
138
|
+
Some(record) if backend.store.retired(&record.target.identity).map_err(error)? => None,
|
|
139
|
+
other => other,
|
|
140
|
+
}
|
|
132
141
|
};
|
|
133
142
|
crate::lifecycle::role_config::commit_contract_role(&source, &previous, &next).map_err(error)?;
|
|
134
143
|
let receipt = backend::start(&selected.run_workspace, &selected.team_key, role, &config.members).map_err(error)?.1;
|
|
@@ -147,6 +156,7 @@ pub fn start_agent(
|
|
|
147
156
|
Some(_) => "resumed",
|
|
148
157
|
}, "operation":receipt.id,
|
|
149
158
|
"session_id":projection.get("session_id"),"generation":projection.get("generation"),
|
|
159
|
+
"session_observation":projection.get("session_observation"),"warning":projection.get("session_warning"),
|
|
150
160
|
"coordinator":crate::lifecycle::coordinator_start_summary_value(
|
|
151
161
|
&crate::lifecycle::CoordinatorStartSummary::from_start_report(&coordinator))}))
|
|
152
162
|
})
|
|
@@ -254,6 +264,266 @@ pub fn stop_agent(
|
|
|
254
264
|
})
|
|
255
265
|
}
|
|
256
266
|
|
|
267
|
+
/// What remove/reset may rely on. Idle needs positive evidence; anything the
|
|
268
|
+
/// framework cannot prove idle is never treated as idle.
|
|
269
|
+
#[derive(Debug, PartialEq, Eq)]
|
|
270
|
+
enum Activity {
|
|
271
|
+
Stopped,
|
|
272
|
+
Exited,
|
|
273
|
+
Idle,
|
|
274
|
+
Working(String),
|
|
275
|
+
Unverified(String),
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// Two captures this far apart straddle a one-second elapsed counter, and a
|
|
279
|
+
// streamed reply that hides a provider's busy marker still changes the frame.
|
|
280
|
+
const SETTLE: Duration = Duration::from_millis(1500);
|
|
281
|
+
const REMOVE_WORKING: &str = "agent is currently working; stop the agent before removing it";
|
|
282
|
+
const RESET_WORKING: &str =
|
|
283
|
+
"agent is currently working; wait for completion or stop the agent before resetting session";
|
|
284
|
+
|
|
285
|
+
/// Read-only: a held seat lease, then the seat's own pane read twice, then
|
|
286
|
+
/// the lease and queue again so a delivery between the captures still counts.
|
|
287
|
+
fn activity(workspace: &Path, team: &str, id: &SeatId) -> Result<Activity, CliError> {
|
|
288
|
+
let backend = Backend::open_readonly(workspace, team).map_err(error)?;
|
|
289
|
+
let busy = || Activity::Working("a lifecycle operation or message delivery holds the seat".into());
|
|
290
|
+
// An interrupted startup holds the lease before its seat row is published.
|
|
291
|
+
if backend.store.leased(id).map_err(error)? {
|
|
292
|
+
return Ok(busy());
|
|
293
|
+
}
|
|
294
|
+
let Some(seat) = backend.store.seat(id).map_err(error)? else {
|
|
295
|
+
return Ok(Activity::Stopped);
|
|
296
|
+
};
|
|
297
|
+
if seat.status == SeatStatus::Stopped {
|
|
298
|
+
return Ok(Activity::Stopped);
|
|
299
|
+
}
|
|
300
|
+
let Some(target) = seat.physical.as_ref() else {
|
|
301
|
+
return Ok(Activity::Unverified("no native target is recorded".into()));
|
|
302
|
+
};
|
|
303
|
+
match sample_process(&target.process) {
|
|
304
|
+
ProcessState::Alive => {}
|
|
305
|
+
ProcessState::Exited | ProcessState::Replaced => return Ok(Activity::Exited),
|
|
306
|
+
ProcessState::Unknown(failure) => {
|
|
307
|
+
return Ok(Activity::Unverified(format!("native process state is unknown: {failure}")))
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
// Starting stays until the first delivery; only the surface decides then.
|
|
311
|
+
if seat.status == SeatStatus::Unknown {
|
|
312
|
+
return Ok(Activity::Unverified("native seat is quarantined after an uncertain native effect".into()));
|
|
313
|
+
}
|
|
314
|
+
let selected = registry::provider(seat.provider.as_str()).map_err(error)?;
|
|
315
|
+
let adapter = backend::adapter(&backend.binding, &seat.identity, &seat.provider).map_err(error)?;
|
|
316
|
+
let hooks = adapter.hooks();
|
|
317
|
+
let clock = RealClock::new();
|
|
318
|
+
let nonce = backend.store.propose_identity(id).map_err(error)?.instance;
|
|
319
|
+
let physical = PhysicalRuntime::new(
|
|
320
|
+
Registration {
|
|
321
|
+
descriptor: selected.descriptor(),
|
|
322
|
+
hooks: &hooks,
|
|
323
|
+
controls: selected.controls(),
|
|
324
|
+
startup: selected.startup(),
|
|
325
|
+
session_panel: selected.session_panel(),
|
|
326
|
+
},
|
|
327
|
+
backend::settings(&backend.binding, selected),
|
|
328
|
+
OperationId::new(format!("observe-{}", nonce.as_str())).map_err(error)?,
|
|
329
|
+
&clock,
|
|
330
|
+
).map_err(error)?;
|
|
331
|
+
let capture = || physical.surface(&seat)
|
|
332
|
+
.map_err(|failure| Activity::Unverified(format!("native surface capture failed: {failure}")));
|
|
333
|
+
let first = match capture() {
|
|
334
|
+
Ok(sample) => sample,
|
|
335
|
+
Err(unverified) => return Ok(unverified),
|
|
336
|
+
};
|
|
337
|
+
std::thread::sleep(SETTLE);
|
|
338
|
+
let observed = match capture() {
|
|
339
|
+
Ok(second) => classify(&first, &second),
|
|
340
|
+
Err(unverified) => unverified,
|
|
341
|
+
};
|
|
342
|
+
if observed == Activity::Idle {
|
|
343
|
+
if backend.store.leased(id).map_err(error)? {
|
|
344
|
+
return Ok(busy());
|
|
345
|
+
}
|
|
346
|
+
if backend.store.has_queued_for(&seat.identity).map_err(error)? {
|
|
347
|
+
return Ok(Activity::Working("a queued message is about to be delivered".into()));
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
Ok(observed)
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
fn classify(
|
|
354
|
+
first: &(Probe<PaneReadyEvidence>, Digest),
|
|
355
|
+
second: &(Probe<PaneReadyEvidence>, Digest),
|
|
356
|
+
) -> Activity {
|
|
357
|
+
let read = |sample: &(Probe<PaneReadyEvidence>, Digest)| match &sample.0.outcome {
|
|
358
|
+
ProbeOutcome::Observed(pane) => Some(pane.surface),
|
|
359
|
+
_ => None,
|
|
360
|
+
};
|
|
361
|
+
let (before, after) = (read(first), read(second));
|
|
362
|
+
if let Some(busy) = [before, after].into_iter().flatten().find(|surface| matches!(surface,
|
|
363
|
+
InputSurface::Busy | InputSurface::Queued | InputSurface::ComposerContainsPaste | InputSurface::NativeAccepted))
|
|
364
|
+
{
|
|
365
|
+
return Activity::Working(format!("native surface reads {busy:?}"));
|
|
366
|
+
}
|
|
367
|
+
match (before, after) {
|
|
368
|
+
(Some(InputSurface::ComposerReady), Some(InputSurface::ComposerReady)) if first.1 == second.1 => Activity::Idle,
|
|
369
|
+
(Some(InputSurface::ComposerReady), Some(InputSurface::ComposerReady)) => {
|
|
370
|
+
Activity::Working("native output changed between two captures".into())
|
|
371
|
+
}
|
|
372
|
+
_ => Activity::Unverified(format!("native surface reads {before:?} then {after:?}")),
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
fn refused(agent: &str, reason: &str, error: &str, evidence: Option<String>, action: &str) -> Value {
|
|
377
|
+
json!({"ok":false,"agent_id":agent,"status":"refused","runtime":"contract","reason":reason,
|
|
378
|
+
"error":error,"evidence":evidence,"action":action})
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
fn stop_seat(selected: &SelectedTeam, id: &SeatId) -> Result<OperationId, CliError> {
|
|
382
|
+
let receipt = backend::stop(&selected.run_workspace, &selected.team_key, id).map_err(error)?;
|
|
383
|
+
check_record(&receipt)?;
|
|
384
|
+
Ok(receipt.id)
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/// A working seat is never removed, even with --force. A stopped seat needs
|
|
388
|
+
/// only --confirm; an idle live seat also needs --force and is stopped first.
|
|
389
|
+
pub fn remove_agent(
|
|
390
|
+
workspace: &Path,
|
|
391
|
+
team: Option<&str>,
|
|
392
|
+
agent: &str,
|
|
393
|
+
from_spec: bool,
|
|
394
|
+
confirm: bool,
|
|
395
|
+
force: bool,
|
|
396
|
+
) -> Result<Option<Value>, CliError> {
|
|
397
|
+
with_agent(workspace, team, agent, "remove-agent", |selected, id| {
|
|
398
|
+
if !confirm {
|
|
399
|
+
return Ok(refused(agent, "confirm_required", "remove-agent requires --confirm", None, "rerun with --confirm"));
|
|
400
|
+
}
|
|
401
|
+
let row = selected.state.get("agents").and_then(|agents| agents.get(agent))
|
|
402
|
+
.ok_or(BackendError::Metadata).map_err(error)?;
|
|
403
|
+
let agent_id = AgentId::new(agent);
|
|
404
|
+
// Every shared-record input resolves before the native seat is touched.
|
|
405
|
+
crate::lifecycle::restart::remove::preflight_contract_removal(
|
|
406
|
+
&selected.run_workspace, &agent_id, Some(&selected.team_key),
|
|
407
|
+
).map_err(error)?;
|
|
408
|
+
let mut stopped = None;
|
|
409
|
+
if !framework::is_paused_unstarted(row) {
|
|
410
|
+
match activity(&selected.run_workspace, &selected.team_key, id)? {
|
|
411
|
+
Activity::Stopped => {}
|
|
412
|
+
Activity::Working(evidence) => return Ok(refused(agent, "agent_working", REMOVE_WORKING,
|
|
413
|
+
Some(evidence), "wait for the agent to finish, or stop it, then rerun remove-agent")),
|
|
414
|
+
Activity::Unverified(evidence) => return Ok(refused(agent, "agent_activity_unverified",
|
|
415
|
+
"agent activity could not be verified idle; stop the agent before removing it",
|
|
416
|
+
Some(evidence), "stop the agent, then rerun remove-agent")),
|
|
417
|
+
Activity::Idle if !force => return Ok(refused(agent, "force_required",
|
|
418
|
+
"agent is running; remove-agent requires --force", None,
|
|
419
|
+
"rerun with --force to stop and remove the running agent")),
|
|
420
|
+
Activity::Idle | Activity::Exited => stopped = Some(stop_seat(selected, id)?),
|
|
421
|
+
}
|
|
422
|
+
// The native identity ends before the shared records: a failure
|
|
423
|
+
// below leaves a row a rerun removes, never a resumable old seat.
|
|
424
|
+
backend::retire(&selected.run_workspace, &selected.team_key, id).map_err(error)?;
|
|
425
|
+
}
|
|
426
|
+
let report = crate::lifecycle::restart::remove::remove_contract_records_locked(
|
|
427
|
+
&selected.run_workspace, &agent_id, from_spec, force, stopped.is_some(),
|
|
428
|
+
Some(&selected.team_key),
|
|
429
|
+
).map_err(error)?;
|
|
430
|
+
Ok(json!({"ok":true,"agent_id":agent,"status":"removed","runtime":"contract",
|
|
431
|
+
"stopped":stopped.is_some(),"operation":stopped,"report":format!("{report:?}")}))
|
|
432
|
+
})
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
/// Ok: the seat is stopped, exited or idle; Err: the reset refusal receipt.
|
|
436
|
+
fn reset_guard(observed: Activity, agent: &str) -> Result<Activity, Value> {
|
|
437
|
+
match observed {
|
|
438
|
+
Activity::Working(evidence) => Err(refused(agent, "agent_working", RESET_WORKING,
|
|
439
|
+
Some(evidence), "wait for the agent to finish, or stop it, then rerun reset-agent")),
|
|
440
|
+
Activity::Unverified(evidence) => Err(refused(agent, "agent_activity_unverified",
|
|
441
|
+
"agent activity could not be verified idle; wait for completion or stop the agent before resetting session",
|
|
442
|
+
Some(evidence), "stop the agent, then rerun reset-agent")),
|
|
443
|
+
clear => Ok(clear),
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
/// Discards the native session only when the seat is provably not working,
|
|
448
|
+
/// then starts the same seat ID on a fresh generation and session.
|
|
449
|
+
pub fn reset_agent(
|
|
450
|
+
workspace: &Path,
|
|
451
|
+
team: Option<&str>,
|
|
452
|
+
agent: &str,
|
|
453
|
+
discard_session: bool,
|
|
454
|
+
) -> Result<Option<Value>, CliError> {
|
|
455
|
+
with_agent(workspace, team, agent, "reset-agent", |selected, id| {
|
|
456
|
+
if !discard_session {
|
|
457
|
+
return Ok(json!({"ok":false,"agent_id":agent,"status":"refused","runtime":"contract",
|
|
458
|
+
"reason":"discard_session_required"}));
|
|
459
|
+
}
|
|
460
|
+
let row = selected.state.get("agents").and_then(|agents| agents.get(agent))
|
|
461
|
+
.ok_or(BackendError::Metadata).map_err(error)?;
|
|
462
|
+
let config = framework::team_config(&selected.run_workspace, &selected.team_dir, &selected.team_key, Some(agent))
|
|
463
|
+
.map_err(error)?.ok_or_else(|| error("contract role no longer configured"))?;
|
|
464
|
+
let role = config.roles.iter().find(|role| &role.id == id)
|
|
465
|
+
.ok_or_else(|| error("contract role no longer configured"))?;
|
|
466
|
+
if !registry::same_provider(row.get("provider").and_then(Value::as_str).unwrap_or(""), role.provider.as_str()) {
|
|
467
|
+
return Err(error("provider change requires a new seat identity"));
|
|
468
|
+
}
|
|
469
|
+
if role.paused {
|
|
470
|
+
return Ok(json!({"ok":false,"agent_id":agent,"status":"paused","reason":"agent_paused","runtime":"contract"}));
|
|
471
|
+
}
|
|
472
|
+
let live = !framework::is_paused_unstarted(row);
|
|
473
|
+
// The guard runs when the command is invoked, before the slow native
|
|
474
|
+
// admission below: a message sent just before reset is still queued or
|
|
475
|
+
// in flight then. It runs again right before the stop, so work that
|
|
476
|
+
// began during admission is refused too.
|
|
477
|
+
if live {
|
|
478
|
+
if let Err(refusal) = reset_guard(activity(&selected.run_workspace, &selected.team_key, id)?, agent) {
|
|
479
|
+
return Ok(refusal);
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
// Pure admission of the replacement precedes any stop or retirement.
|
|
483
|
+
let mut admission = config.clone();
|
|
484
|
+
admission.roles.retain(|candidate| &candidate.id == id);
|
|
485
|
+
backend::preflight(&admission).map_err(error)?;
|
|
486
|
+
let mut stopped = None;
|
|
487
|
+
let mut discarded = None;
|
|
488
|
+
if live {
|
|
489
|
+
// The fresh start below must not fail its candidate fence after the
|
|
490
|
+
// old seat is already gone.
|
|
491
|
+
backend::refresh_quiescent_candidate(&selected.run_workspace, &selected.team_key, id).map_err(error)?;
|
|
492
|
+
match reset_guard(activity(&selected.run_workspace, &selected.team_key, id)?, agent) {
|
|
493
|
+
Err(refusal) => return Ok(refusal),
|
|
494
|
+
Ok(Activity::Stopped) => {}
|
|
495
|
+
Ok(_) => stopped = Some(stop_seat(selected, id)?),
|
|
496
|
+
}
|
|
497
|
+
discarded = backend::retire(&selected.run_workspace, &selected.team_key, id).map_err(error)?
|
|
498
|
+
.and_then(|seat| seat.session).map(|session| session.native_session);
|
|
499
|
+
}
|
|
500
|
+
// The row stops naming the retired incarnation. If the fresh start
|
|
501
|
+
// below fails, this unbound stopped seed is skipped by team restart
|
|
502
|
+
// and admitted fresh by a later start.
|
|
503
|
+
StateRepository::new(&selected.run_workspace).commit(
|
|
504
|
+
StateWriteIntent::StartAgent { team_key: &selected.team_key, agent_id: agent },
|
|
505
|
+
|state| {
|
|
506
|
+
if let Some(row) = state.get_mut("agents").and_then(|agents| agents.get_mut(agent)).and_then(Value::as_object_mut) {
|
|
507
|
+
for key in ["contract_scope", "contract_instance", "generation", "session_id"] {
|
|
508
|
+
row.insert(key.into(), Value::Null);
|
|
509
|
+
}
|
|
510
|
+
row.insert("status".into(), json!("stopped"));
|
|
511
|
+
}
|
|
512
|
+
},
|
|
513
|
+
).map_err(error)?;
|
|
514
|
+
let projection = framework::start_configured(&selected.run_workspace, &selected.team_dir, &selected.team_key, id)?;
|
|
515
|
+
let coordinator = crate::coordinator::start_coordinator_with_team(
|
|
516
|
+
&crate::coordinator::WorkspacePath::new(selected.run_workspace.clone()), Some(&selected.team_key),
|
|
517
|
+
).map_err(error)?;
|
|
518
|
+
Ok(json!({"ok":coordinator.ok,"agent_id":agent,"status":"reset","runtime":"contract",
|
|
519
|
+
"start_mode":"fresh","stopped":stopped.is_some(),"operation":stopped,
|
|
520
|
+
"discarded_session_id":discarded,"session_id":projection.get("session_id"),
|
|
521
|
+
"new_session_id":projection.get("session_id"),"generation":projection.get("generation"),
|
|
522
|
+
"coordinator":crate::lifecycle::coordinator_start_summary_value(
|
|
523
|
+
&crate::lifecycle::CoordinatorStartSummary::from_start_report(&coordinator))}))
|
|
524
|
+
})
|
|
525
|
+
}
|
|
526
|
+
|
|
257
527
|
#[cfg(test)]
|
|
258
528
|
mod tests {
|
|
259
529
|
// Assembly guard, not a substitute for the real shared-session restart/
|
|
@@ -337,4 +607,65 @@ mod tests {
|
|
|
337
607
|
.unwrap_err().to_string();
|
|
338
608
|
assert!(error.contains("metadata is invalid"));
|
|
339
609
|
}
|
|
610
|
+
|
|
611
|
+
fn surface(surface: Option<InputSurface>, text: &[u8]) -> (Probe<PaneReadyEvidence>, Digest) {
|
|
612
|
+
let scope = team_agent_contract::contract::probe::EvidenceScope {
|
|
613
|
+
identity: receipt(Outcome::Committed).target.identity, endpoint: "fixture".into(),
|
|
614
|
+
pane: "%0".into(), binding: "fixture".into(), session: None, sequence: 1,
|
|
615
|
+
observed_at: Duration::ZERO, valid_for: Duration::from_secs(2), source: "fixture".into(),
|
|
616
|
+
};
|
|
617
|
+
let outcome = match surface {
|
|
618
|
+
Some(surface) => ProbeOutcome::Observed(PaneReadyEvidence { profile_id: "fixture".into(), surface }),
|
|
619
|
+
None => ProbeOutcome::Pending { deadline: Duration::ZERO },
|
|
620
|
+
};
|
|
621
|
+
(Probe { scope, outcome }, team_agent_contract::host::digest(text))
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
#[test]
|
|
625
|
+
fn working_guard_calls_a_seat_idle_only_on_two_still_composer_ready_captures() {
|
|
626
|
+
let ready = surface(Some(InputSurface::ComposerReady), b"idle");
|
|
627
|
+
assert_eq!(classify(&ready, &ready.clone()), Activity::Idle);
|
|
628
|
+
// A streamed reply can hide the busy marker, but it still moves the frame.
|
|
629
|
+
assert!(matches!(classify(&ready, &surface(Some(InputSurface::ComposerReady), b"idle, then more")),
|
|
630
|
+
Activity::Working(_)));
|
|
631
|
+
for busy in [InputSurface::Busy, InputSurface::Queued, InputSurface::ComposerContainsPaste,
|
|
632
|
+
InputSurface::NativeAccepted]
|
|
633
|
+
{
|
|
634
|
+
assert!(matches!(classify(&ready, &surface(Some(busy), b"idle")), Activity::Working(_)), "{busy:?}");
|
|
635
|
+
assert!(matches!(classify(&surface(Some(busy), b"x"), &surface(None, b"x")), Activity::Working(_)),
|
|
636
|
+
"{busy:?}");
|
|
637
|
+
}
|
|
638
|
+
for other in [None, Some(InputSurface::Starting), Some(InputSurface::ShellOrUnknown),
|
|
639
|
+
Some(InputSurface::StartupRiskWarning), Some(InputSurface::Fault)]
|
|
640
|
+
{
|
|
641
|
+
assert!(matches!(classify(&ready, &surface(other, b"idle")), Activity::Unverified(_)), "{other:?}");
|
|
642
|
+
assert!(matches!(classify(&surface(other, b"idle"), &ready), Activity::Unverified(_)), "{other:?}");
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
// 2.8a: a reset issued right after a send must observe the queued or
|
|
647
|
+
// in-flight message, not a turn that the slow admission let finish.
|
|
648
|
+
#[test]
|
|
649
|
+
fn reset_guards_the_seat_before_its_slow_admission_and_again_before_the_stop() {
|
|
650
|
+
let source = include_str!("commands.rs");
|
|
651
|
+
let body = source.split_once("pub fn reset_agent(").unwrap().1
|
|
652
|
+
.split_once("#[cfg(test)]").unwrap().0;
|
|
653
|
+
let first = body.find("reset_guard(activity(").unwrap();
|
|
654
|
+
let admission = body.find("backend::preflight(&admission)").unwrap();
|
|
655
|
+
let second = body.rfind("reset_guard(activity(").unwrap();
|
|
656
|
+
let stop = body.find("stop_seat(selected, id)").unwrap();
|
|
657
|
+
assert!(first < admission && admission < second && second < stop);
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
#[test]
|
|
661
|
+
fn remove_and_reset_route_contract_seats_before_the_legacy_refusal() {
|
|
662
|
+
let cli = include_str!("../cli/mod.rs");
|
|
663
|
+
for (entry, native, gate) in [
|
|
664
|
+
("pub fn remove_agent(", "contract_runtime::commands::remove_agent(", "\"remove-agent\","),
|
|
665
|
+
("pub fn reset_agent(", "contract_runtime::commands::reset_agent(", "\"reset-agent\","),
|
|
666
|
+
] {
|
|
667
|
+
let body = cli.split_once(entry).unwrap().1;
|
|
668
|
+
assert!(body.find(native).unwrap() < body.find(gate).unwrap(), "{entry}");
|
|
669
|
+
}
|
|
670
|
+
}
|
|
340
671
|
}
|
|
@@ -99,7 +99,8 @@ fn mode(meta: &Value, path: &Path) -> Result<Option<CommunicationMode>, ConfigEr
|
|
|
99
99
|
.transpose()
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
/// `contract_runtime` is an exact boolean
|
|
102
|
+
/// `contract_runtime` is an exact boolean. Every contract name selects its leaf
|
|
103
|
+
/// without it; `true` only insists that the provider be a contract leaf.
|
|
103
104
|
fn opted_in(meta: &Value, path: &Path) -> Result<bool, ConfigError> {
|
|
104
105
|
match meta.get("contract_runtime") {
|
|
105
106
|
None => Ok(false),
|
|
@@ -118,7 +119,7 @@ fn malformed_contract_header(body: &str) -> bool {
|
|
|
118
119
|
.map(|(key, value)| (key.trim(), value.split('#').next().unwrap_or("").trim().trim_matches(['\'', '"'])))
|
|
119
120
|
.collect();
|
|
120
121
|
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
|
|
122
|
+
opted_in || fields.iter().any(|(key, value)| *key == "provider" && super::registry::recognizes(value))
|
|
122
123
|
})
|
|
123
124
|
}
|
|
124
125
|
|
|
@@ -134,7 +135,13 @@ pub fn read_team_with_user_source(
|
|
|
134
135
|
args: &QuickStartArgs,
|
|
135
136
|
user_source: impl FnOnce() -> Result<Option<Source>, ConfigError>,
|
|
136
137
|
) -> Result<Option<TeamConfig>, ConfigError> {
|
|
137
|
-
read_team_inner(args, user_source, None)
|
|
138
|
+
read_team_inner(args, user_source, None, None)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/// Admit only the addressed seat's native capabilities; retain sibling routing
|
|
142
|
+
/// metadata without validating their model/auth/permission launch settings.
|
|
143
|
+
pub fn read_seat(args: &QuickStartArgs, seat: &str) -> Result<Option<TeamConfig>, ConfigError> {
|
|
144
|
+
read_team_inner(args, prompt::user_source, None, Some(seat))
|
|
138
145
|
}
|
|
139
146
|
|
|
140
147
|
/// Compile an admitted role-document change without first writing any file.
|
|
@@ -142,14 +149,16 @@ pub(crate) fn read_team_with_role_override(
|
|
|
142
149
|
args: &QuickStartArgs,
|
|
143
150
|
path: &Path,
|
|
144
151
|
contents: &str,
|
|
152
|
+
seat: &str,
|
|
145
153
|
) -> Result<Option<TeamConfig>, ConfigError> {
|
|
146
|
-
read_team_inner(args, prompt::user_source, Some((path, contents)))
|
|
154
|
+
read_team_inner(args, prompt::user_source, Some((path, contents)), Some(seat))
|
|
147
155
|
}
|
|
148
156
|
|
|
149
157
|
fn read_team_inner(
|
|
150
158
|
args: &QuickStartArgs,
|
|
151
159
|
user_source: impl FnOnce() -> Result<Option<Source>, ConfigError>,
|
|
152
160
|
role_override: Option<(&Path, &str)>,
|
|
161
|
+
seat: Option<&str>,
|
|
153
162
|
) -> Result<Option<TeamConfig>, ConfigError> {
|
|
154
163
|
let agents = args.agents_dir.join("agents");
|
|
155
164
|
let entries = match std::fs::read_dir(&agents) {
|
|
@@ -185,15 +194,15 @@ fn read_team_inner(
|
|
|
185
194
|
{
|
|
186
195
|
return Err(invalid(&path, "front matter"));
|
|
187
196
|
}
|
|
188
|
-
let
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
+
let addressed = seat.is_none_or(|seat| {
|
|
198
|
+
meta.get("agent_id").or_else(|| meta.get("name")).and_then(Value::as_str)
|
|
199
|
+
.or_else(|| path.file_stem().and_then(|name| name.to_str())) == Some(seat)
|
|
200
|
+
});
|
|
201
|
+
if addressed && (opted_in(&meta, &path)?
|
|
202
|
+
|| meta
|
|
203
|
+
.get("provider")
|
|
204
|
+
.and_then(Value::as_str)
|
|
205
|
+
.is_some_and(super::registry::recognizes))
|
|
197
206
|
{
|
|
198
207
|
selected = true;
|
|
199
208
|
}
|
|
@@ -263,11 +272,7 @@ fn read_team_inner(
|
|
|
263
272
|
return Err(invalid(&source, "reserved worker id"));
|
|
264
273
|
}
|
|
265
274
|
let provider = text(&meta, "provider", &source)?.unwrap_or_else(|| "pi".into());
|
|
266
|
-
let
|
|
267
|
-
let registration = super::registry::declared(&provider, opted);
|
|
268
|
-
if registration.is_none() && (opted || super::registry::recognizes(&provider, false)) {
|
|
269
|
-
return Err(invalid(&source, "provider"));
|
|
270
|
-
}
|
|
275
|
+
let registration = super::registry::declared(&provider);
|
|
271
276
|
let runtime = if registration.is_some() {
|
|
272
277
|
RuntimeFamily::Contract
|
|
273
278
|
} else {
|
|
@@ -275,10 +280,16 @@ fn read_team_inner(
|
|
|
275
280
|
};
|
|
276
281
|
members.push(MemberRoute {
|
|
277
282
|
id: id.clone(),
|
|
278
|
-
provider: registration.
|
|
283
|
+
provider: registration.map_or_else(|| provider.clone(), |descriptor| descriptor.identity.id.into()),
|
|
279
284
|
source: source.canonicalize()?,
|
|
280
285
|
runtime,
|
|
281
286
|
});
|
|
287
|
+
if seat.is_some_and(|seat| seat != id) {
|
|
288
|
+
continue;
|
|
289
|
+
}
|
|
290
|
+
if registration.is_none() && (opted_in(&meta, &source)? || super::registry::recognizes(&provider)) {
|
|
291
|
+
return Err(invalid(&source, "provider"));
|
|
292
|
+
}
|
|
282
293
|
let Some(registration) = registration else {
|
|
283
294
|
continue;
|
|
284
295
|
};
|
|
@@ -19,14 +19,34 @@ impl Fixture {
|
|
|
19
19
|
}
|
|
20
20
|
impl Drop for Fixture { fn drop(&mut self) { let _ = std::fs::remove_dir_all(&self.root); } }
|
|
21
21
|
|
|
22
|
+
#[test]
|
|
23
|
+
fn selected_seat_ignores_sibling_native_admission_but_keeps_forwarding_routes() {
|
|
24
|
+
let fixture = Fixture::new();
|
|
25
|
+
std::fs::write(&fixture.role, "---\nprovider: grok\nmodel: grok-4.7\nauth_mode: subscription\ndangerously_skip_permissions: true\n---\nTarget\n").unwrap();
|
|
26
|
+
let roles = fixture.args.agents_dir.join("agents");
|
|
27
|
+
std::fs::write(roles.join("legacy.md"), "---\nprovider: claude\nprofile: claude-default\n---\nLegacy\n").unwrap();
|
|
28
|
+
for rejected in ["profile: codex-default", "auth_mode: compatible_api", "dangerously_skip_permissions: invalid", "contract_runtime: invalid"] {
|
|
29
|
+
std::fs::write(roles.join("retired.md"), format!("---\nprovider: codex\nmodel: native-model\n{rejected}\n---\nRetired sibling\n")).unwrap();
|
|
30
|
+
assert!(read_team_inner(&fixture.args, || Ok(None), None, None).is_err());
|
|
31
|
+
let config = read_team_inner(&fixture.args, || Ok(None), None, Some("worker")).unwrap().unwrap();
|
|
32
|
+
assert_eq!(config.roles.len(), 1);
|
|
33
|
+
assert_eq!(config.roles[0].provider.as_str(), "grok_build");
|
|
34
|
+
assert!(config.roles[0].bypass);
|
|
35
|
+
assert!(config.members.iter().any(|member| member.id == "legacy" && member.runtime == RuntimeFamily::Legacy));
|
|
36
|
+
assert!(read_team_inner(&fixture.args, || Ok(None), None, Some("retired")).is_err());
|
|
37
|
+
}
|
|
38
|
+
assert!(read_team_inner(&fixture.args, || Ok(None), None, Some("missing")).unwrap().is_none());
|
|
39
|
+
assert!(!fixture.root.join(".team").exists());
|
|
40
|
+
}
|
|
41
|
+
|
|
22
42
|
#[test]
|
|
23
43
|
fn virtual_role_change_is_readonly_and_binds_new_instruction_digest() {
|
|
24
44
|
let fixture = Fixture::new();
|
|
25
45
|
let before = std::fs::read(&fixture.role).unwrap();
|
|
26
46
|
let path = fixture.role.canonicalize().unwrap();
|
|
27
47
|
let contents = "---\nprovider: cursor\nmodel: new-model\n---\nNew instructions\n";
|
|
28
|
-
let original = read_team_inner(&fixture.args, || Ok(None), None).unwrap().unwrap();
|
|
29
|
-
let changed = read_team_inner(&fixture.args, || Ok(None), Some((&path, contents))).unwrap().unwrap();
|
|
48
|
+
let original = read_team_inner(&fixture.args, || Ok(None), None, None).unwrap().unwrap();
|
|
49
|
+
let changed = read_team_inner(&fixture.args, || Ok(None), Some((&path, contents)), Some("worker")).unwrap().unwrap();
|
|
30
50
|
assert_eq!(changed.roles[0].model, "new-model");
|
|
31
51
|
assert_eq!(changed.roles[0].body, "New instructions\n");
|
|
32
52
|
assert_ne!(changed.roles[0].prompt.sha256, original.roles[0].prompt.sha256);
|
|
@@ -41,7 +61,7 @@ fn virtual_api_profile_is_refused_without_file_effects() {
|
|
|
41
61
|
let before = std::fs::read(&fixture.role).unwrap();
|
|
42
62
|
let path = fixture.role.canonicalize().unwrap();
|
|
43
63
|
let contents = "---\nprovider: cursor\nmodel: new-model\nprofile: unsupported\n---\nInstructions\n";
|
|
44
|
-
assert!(matches!(read_team_inner(&fixture.args, || Ok(None), Some((&path, contents))), Err(ConfigError::Unsupported(_))));
|
|
64
|
+
assert!(matches!(read_team_inner(&fixture.args, || Ok(None), Some((&path, contents)), Some("worker")), Err(ConfigError::Unsupported(_))));
|
|
45
65
|
assert_eq!(std::fs::read(&fixture.role).unwrap(), before);
|
|
46
66
|
assert!(!fixture.root.join(".team").exists());
|
|
47
67
|
}
|
|
@@ -51,6 +71,6 @@ fn virtual_role_override_cannot_match_a_different_source() {
|
|
|
51
71
|
let fixture = Fixture::new();
|
|
52
72
|
let other = fixture.root.join("other.md");
|
|
53
73
|
let contents = "---\nprovider: cursor\nmodel: wrong-model\n---\nOther\n";
|
|
54
|
-
let config = read_team_inner(&fixture.args, || Ok(None), Some((&other, contents))).unwrap().unwrap();
|
|
74
|
+
let config = read_team_inner(&fixture.args, || Ok(None), Some((&other, contents)), Some("worker")).unwrap().unwrap();
|
|
55
75
|
assert_eq!(config.roles[0].model, "old-model");
|
|
56
76
|
}
|
|
@@ -174,7 +174,7 @@ pub(super) fn discover_runtime(provider: &ProviderId, workspace: &Path) -> Resul
|
|
|
174
174
|
|
|
175
175
|
fn validate_catalog(provider: &ProviderId, discovery: &Discovery) -> Result<(), ContractError> {
|
|
176
176
|
let descriptor = registry::provider(provider.as_str())?.descriptor();
|
|
177
|
-
if discovery.catalog.provider !=
|
|
177
|
+
if discovery.catalog.provider.as_str() != descriptor.identity.id
|
|
178
178
|
|| discovery.catalog.native != discovery.native
|
|
179
179
|
|| discovery.catalog.schema != descriptor.model.catalog.require("native catalog source")?.schema
|
|
180
180
|
{
|
|
@@ -381,6 +381,17 @@ mod tests {
|
|
|
381
381
|
assert!(json["current_role_model"].is_null());
|
|
382
382
|
}
|
|
383
383
|
|
|
384
|
+
#[test]
|
|
385
|
+
fn grok_catalog_alias_uses_the_same_canonical_identity() {
|
|
386
|
+
for provider in ["grok", "grok_build"] {
|
|
387
|
+
let mut discovery = cursor_catalog();
|
|
388
|
+
discovery.catalog.provider = ProviderId::new("grok_build").unwrap();
|
|
389
|
+
discovery.catalog.schema = grok::CATALOG_SOURCE.schema.into();
|
|
390
|
+
let args = ModelsArgs { provider: provider.into(), search: None, json: true };
|
|
391
|
+
assert_eq!(render_models(&args, Ok(discovery)).unwrap().exit, ExitCode::Ok);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
384
395
|
#[test]
|
|
385
396
|
fn mismatched_catalog_provider_native_or_schema_is_not_projected() {
|
|
386
397
|
let args = ModelsArgs { provider: "cursor".into(), search: None, json: true };
|
|
@@ -96,7 +96,7 @@ fn fork_locked(
|
|
|
96
96
|
if std::fs::symlink_metadata(&role_path).is_ok() {
|
|
97
97
|
return Err(error(format!("role file already exists: {}", role_path.display())));
|
|
98
98
|
}
|
|
99
|
-
let config = framework::team_config(workspace, &selected.team_dir, team).map_err(error)?
|
|
99
|
+
let config = framework::team_config(workspace, &selected.team_dir, team, Some(source_id.as_str())).map_err(error)?
|
|
100
100
|
.ok_or_else(|| error("contract team configuration is unavailable"))?;
|
|
101
101
|
let source_role = config.roles.iter().find(|role| &role.id == source_id)
|
|
102
102
|
.ok_or_else(|| error("contract source role is no longer configured"))?;
|
|
@@ -116,7 +116,7 @@ fn fork_locked(
|
|
|
116
116
|
role_path: role_path.clone(), role_bytes: role_text.into_bytes(), spec_path: spec_path.clone(), pre_spec,
|
|
117
117
|
};
|
|
118
118
|
let result = (|| -> Result<Value, CliError> {
|
|
119
|
-
let config = framework::team_config(workspace, &selected.team_dir, team).map_err(error)?
|
|
119
|
+
let config = framework::team_config(workspace, &selected.team_dir, team, Some(target_id.as_str())).map_err(error)?
|
|
120
120
|
.ok_or_else(|| error("contract team configuration is unavailable"))?;
|
|
121
121
|
let role = config.roles.iter().find(|role| role.id == target_id)
|
|
122
122
|
.ok_or_else(|| error("forked contract role was not configured"))?;
|
|
@@ -174,13 +174,6 @@ fn native_fork(
|
|
|
174
174
|
let selected = registry::provider(role.provider.as_str())?;
|
|
175
175
|
let descriptor = selected.descriptor();
|
|
176
176
|
let discovered = discovery::discover_runtime(&role.provider, workspace)?;
|
|
177
|
-
if let Some(path) = selected.native_fork_source(discovered.runtime.as_ref(), &session)? {
|
|
178
|
-
// The exact parent backing the native CLI reads must exist before any effect.
|
|
179
|
-
let metadata = std::fs::symlink_metadata(&path)?;
|
|
180
|
-
if !metadata.is_file() || metadata.len() == 0 {
|
|
181
|
-
return Err(ContractError::Invalid("native fork parent backing").into());
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
177
|
backend::publish_framework_routes(&mut backend, members)?;
|
|
185
178
|
let identity = backend.store.propose_identity(&role.id)?;
|
|
186
179
|
let server_key = selected.server_key_for(&identity)?;
|
|
@@ -193,7 +186,7 @@ fn native_fork(
|
|
|
193
186
|
launch.paths.cwd = super::workspace::prepare(&backend.binding, &role.id)?;
|
|
194
187
|
}
|
|
195
188
|
backend::require_private_primary(selected, &launch.paths.cwd)?;
|
|
196
|
-
backend::preassign_session(
|
|
189
|
+
backend::preassign_session(&mut launch, &discovered)?;
|
|
197
190
|
let operation = OperationId::new(format!("fork-{}", launch.identity.instance.as_str()))?;
|
|
198
191
|
let request = ForkRequest {
|
|
199
192
|
mode: ForkMode::NativeNewSeat,
|