@team-agent/installer 0.5.121 → 0.5.123
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 +8 -1
- package/Cargo.toml +1 -1
- package/crates/team-agent/src/cli/diagnose.rs +176 -10
- package/crates/team-agent/src/cli/intent/runtime.rs +78 -42
- package/crates/team-agent/src/cli/intent/runtime_tests.rs +137 -0
- package/crates/team-agent/src/cli/intent/tests.rs +37 -0
- package/crates/team-agent/src/cli/intent.rs +22 -0
- package/crates/team-agent/src/contract_runtime/backend.rs +490 -2
- package/crates/team-agent/src/contract_runtime/commands.rs +38 -24
- package/crates/team-agent/src/contract_runtime/forward.rs +59 -0
- package/crates/team-agent/src/contract_runtime/framework.rs +23 -17
- package/crates/team-agent/src/coordinator/tests/health_sync.rs +27 -8
- package/crates/team-agent/src/lifecycle/launch/quick_start.rs +6 -17
- package/crates/team-agent/src/lifecycle/launch/quick_start_transport.rs +26 -19
- package/crates/team-agent/src/lifecycle/launch/spawn.rs +19 -2
- package/crates/team-agent/src/lifecycle/restart/agent.rs +3 -0
- package/crates/team-agent/src/lifecycle/restart/common.rs +3 -0
- package/crates/team-agent/src/lifecycle/restart/rebuild.rs +100 -31
- package/crates/team-agent/src/lifecycle/restart.rs +1 -0
- package/crates/team-agent/src/lifecycle/tests/acceptance_b_batch_red.rs +16 -3
- package/crates/team-agent/src/lifecycle/tests/cursor_restart_resume_red.rs +132 -1
- package/crates/team-agent/src/lifecycle/tests/launch_spawn.rs +7 -5
- package/crates/team-agent/src/lifecycle/tests/subprep_codex_trust_roundtrip_red.rs +8 -2
- package/crates/team-agent/src/mcp_server/readiness.rs +66 -3
- package/crates/team-agent/src/mcp_server/readiness_tests.rs +30 -0
- package/crates/team-agent/src/messaging/delivery_consumption_tests.rs +12 -1
- package/crates/team-agent/src/messaging/tests/dup_inject.rs +48 -4
- package/crates/team-agent/src/messaging/tests/spine.rs +45 -14
- package/crates/team-agent/src/provider/wire.rs +2 -1
- package/npm/install.mjs +17 -97
- package/package.json +4 -4
|
@@ -5,7 +5,6 @@ use std::path::Path;
|
|
|
5
5
|
use serde_json::{json, Value};
|
|
6
6
|
use team_agent_contract::contract::types::SeatId;
|
|
7
7
|
use team_agent_contract::orchestration::store::{Outcome, SeatStatus};
|
|
8
|
-
use team_agent_contract::host::process::{sample_process, ProcessState};
|
|
9
8
|
|
|
10
9
|
use crate::cli::CliError;
|
|
11
10
|
use crate::lifecycle::lock::{acquire_agent_lifecycle_lock, LifecycleLockRequest};
|
|
@@ -21,7 +20,7 @@ fn error(error: impl std::fmt::Display) -> CliError {
|
|
|
21
20
|
|
|
22
21
|
/// None delegates only a non-contract selection. Once selected, any identity,
|
|
23
22
|
/// ownership, state or physical error stays on this route and cannot fall back.
|
|
24
|
-
fn with_agent(
|
|
23
|
+
pub(super) fn with_agent(
|
|
25
24
|
workspace: &Path,
|
|
26
25
|
team: Option<&str>,
|
|
27
26
|
agent: &str,
|
|
@@ -51,10 +50,7 @@ fn with_agent(
|
|
|
51
50
|
apply(&latest, &SeatId::new(agent).map_err(error)?).map(Some)
|
|
52
51
|
}
|
|
53
52
|
|
|
54
|
-
fn
|
|
55
|
-
publish_at(&selected.run_workspace, &selected.team_key, id, clear_stop)
|
|
56
|
-
}
|
|
57
|
-
fn publish_at(workspace: &Path, team: &str, id: &SeatId, clear_stop: bool) -> Result<Value, CliError> {
|
|
53
|
+
pub(super) fn publish_at(workspace: &Path, team: &str, id: &SeatId, clear_stop: bool) -> Result<Value, CliError> {
|
|
58
54
|
let projected = framework::project_seat(workspace, team, id.as_str()).map_err(error)?;
|
|
59
55
|
StateRepository::new(workspace).commit(
|
|
60
56
|
StateWriteIntent::StartAgent { team_key: team, agent_id: id.as_str() },
|
|
@@ -70,6 +66,9 @@ fn publish_at(workspace: &Path, team: &str, id: &SeatId, clear_stop: bool) -> Re
|
|
|
70
66
|
}
|
|
71
67
|
},
|
|
72
68
|
).map_err(error)?;
|
|
69
|
+
// Fresh, explicit resume and team restart share this one publication path.
|
|
70
|
+
// Only the exact live receipt may claim a session it actually created.
|
|
71
|
+
backend::bind_workspace_session(workspace, team, id).map_err(error)?;
|
|
73
72
|
Ok(projected)
|
|
74
73
|
}
|
|
75
74
|
|
|
@@ -121,34 +120,32 @@ pub fn start_agent(
|
|
|
121
120
|
return Ok(json!({"ok":false,"agent_id":agent,"status":"paused","reason":"agent_paused"}));
|
|
122
121
|
}
|
|
123
122
|
let unstarted = framework::is_paused_unstarted(row);
|
|
124
|
-
|
|
123
|
+
if unstarted {
|
|
125
124
|
// Full pure team admission precedes native allocation or role writes.
|
|
126
125
|
backend::preflight(&config).map_err(error)?;
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
134
|
-
if seat.status != SeatStatus::Stopped && seat.physical.as_ref().is_some_and(|target| sample_process(&target.process) == ProcessState::Alive) {
|
|
135
|
-
return Err(error("native seat is already running; use stop-agent first"));
|
|
136
|
-
}
|
|
137
|
-
Some(backend::prepare_resume(&selected.run_workspace, &selected.team_key, id, Some(role)).map_err(error)?)
|
|
126
|
+
} else if backend::preflight_start_role(&selected.run_workspace, &selected.team_key, role).map_err(error)? {
|
|
127
|
+
backend::preflight(&config).map_err(error)?;
|
|
128
|
+
}
|
|
129
|
+
let before = if unstarted { None } else {
|
|
130
|
+
Backend::open_readonly(&selected.run_workspace, &selected.team_key).map_err(error)?
|
|
131
|
+
.store.creation_receipt(id, None).map_err(error)?
|
|
138
132
|
};
|
|
139
133
|
crate::lifecycle::role_config::commit_contract_role(&source, &previous, &next).map_err(error)?;
|
|
140
|
-
let receipt =
|
|
141
|
-
Some(prepared) => backend::resume(prepared).map_err(error)?,
|
|
142
|
-
None => backend::start(&selected.run_workspace, &selected.team_key, role, &config.members).map_err(error)?.1,
|
|
143
|
-
};
|
|
134
|
+
let receipt = backend::start(&selected.run_workspace, &selected.team_key, role, &config.members).map_err(error)?.1;
|
|
144
135
|
// An uncertain operation never rolls the authoritative native store back
|
|
145
136
|
// to the old generation. The receipt remains available for recovery.
|
|
146
|
-
let projection = checked_projection(&receipt, ||
|
|
137
|
+
let projection = checked_projection(&receipt, || publish_at(&selected.run_workspace, &selected.team_key, id, true))?;
|
|
147
138
|
let coordinator = crate::coordinator::start_coordinator_with_team(
|
|
148
139
|
&crate::coordinator::WorkspacePath::new(selected.run_workspace.clone()), Some(&selected.team_key),
|
|
149
140
|
).map_err(error)?;
|
|
150
141
|
Ok(json!({"ok":coordinator.ok,"agent_id":agent,"status":"running","runtime":"contract",
|
|
151
|
-
"start_mode":
|
|
142
|
+
"start_mode":match before {
|
|
143
|
+
None => "fresh",
|
|
144
|
+
Some(ref original) if original.outcome == Outcome::Compensated => "fresh",
|
|
145
|
+
Some(ref original) if original.id == receipt.id && original.outcome != Outcome::Committed => "receipt_completed",
|
|
146
|
+
Some(ref original) if original.id == receipt.id => "reused",
|
|
147
|
+
Some(_) => "resumed",
|
|
148
|
+
}, "operation":receipt.id,
|
|
152
149
|
"session_id":projection.get("session_id"),"generation":projection.get("generation"),
|
|
153
150
|
"coordinator":crate::lifecycle::coordinator_start_summary_value(
|
|
154
151
|
&crate::lifecycle::CoordinatorStartSummary::from_start_report(&coordinator))}))
|
|
@@ -259,6 +256,23 @@ pub fn stop_agent(
|
|
|
259
256
|
|
|
260
257
|
#[cfg(test)]
|
|
261
258
|
mod tests {
|
|
259
|
+
// Assembly guard, not a substitute for the real shared-session restart/
|
|
260
|
+
// shutdown RED→GREEN journey. All start callers must use this common path.
|
|
261
|
+
#[test]
|
|
262
|
+
fn shared_owner_claim_follows_common_projection_commit_including_team_restart() {
|
|
263
|
+
let source = include_str!("commands.rs");
|
|
264
|
+
let body = source.split_once("pub(super) fn publish_at").unwrap().1
|
|
265
|
+
.split_once("fn check_record").unwrap().0;
|
|
266
|
+
let persisted = body.find("StateRepository::new(workspace).commit").unwrap();
|
|
267
|
+
let claimed = body.find("backend::bind_workspace_session(workspace, team, id)").unwrap();
|
|
268
|
+
let returned = body.find("Ok(projected)").unwrap();
|
|
269
|
+
assert!(persisted < claimed && claimed < returned);
|
|
270
|
+
let restart = source.split_once("pub(crate) fn restart_prepared").unwrap().1
|
|
271
|
+
.split_once("pub fn restart(").unwrap().0;
|
|
272
|
+
assert!(restart.contains("publish_at(workspace, team, &id, false)"));
|
|
273
|
+
assert!(!include_str!("framework.rs").contains("backend::bind_workspace_session"));
|
|
274
|
+
}
|
|
275
|
+
|
|
262
276
|
use super::*;
|
|
263
277
|
use team_agent_contract::contract::{delivery::DeliveryEffect, session::CwdIdentity, types::*};
|
|
264
278
|
use team_agent_contract::orchestration::store::{OperationRecord, Phase, SeatRecord, TransactionKind};
|
|
@@ -208,10 +208,69 @@ pub fn drain(
|
|
|
208
208
|
Ok(completed)
|
|
209
209
|
}
|
|
210
210
|
|
|
211
|
+
/// Explicit operator egress only: reuse committed native receipts, never run a
|
|
212
|
+
/// coordinator tick, provider admission, input delivery, or candidate migration.
|
|
213
|
+
/// The original runtime binding remains authoritative even when this helper was
|
|
214
|
+
/// built from a newer revision. Pending forwards retain their exact source IDs.
|
|
215
|
+
pub fn drain_scoped_pending_egress(
|
|
216
|
+
workspace: &std::path::Path,
|
|
217
|
+
team: &str,
|
|
218
|
+
expected_scope: &str,
|
|
219
|
+
apply: bool,
|
|
220
|
+
) -> Result<Value, String> {
|
|
221
|
+
if !workspace.is_absolute() || team.is_empty() || team.trim() != team {
|
|
222
|
+
return Err("egress requires an absolute workspace and exact explicit team".into());
|
|
223
|
+
}
|
|
224
|
+
ScopeId::new(expected_scope).map_err(|error| error.to_string())?;
|
|
225
|
+
let selected = crate::state::selector::resolve_active_team_readonly(
|
|
226
|
+
workspace, Some(team), crate::state::selector::SelectorMode::RuntimeOnly,
|
|
227
|
+
).map_err(|error| error.to_string())?;
|
|
228
|
+
crate::lifecycle::launch::ensure_owner_allowed_for_state(&selected.state, None)
|
|
229
|
+
.map_err(|error| error.to_string())?;
|
|
230
|
+
let original = super::backend::Backend::open_readonly(&selected.run_workspace, &selected.team_key)
|
|
231
|
+
.map_err(|error| error.to_string())?;
|
|
232
|
+
if original.binding.scope.as_str() != expected_scope || original.binding.team != team {
|
|
233
|
+
return Err("egress scope/binding mismatch".into());
|
|
234
|
+
}
|
|
235
|
+
let binding = serde_json::to_value(&original.binding).map_err(|error| error.to_string())?;
|
|
236
|
+
let before: Vec<_> = original.store.pending_forwards(32).map_err(|error| error.to_string())?
|
|
237
|
+
.into_iter().map(|intent| intent.id).collect();
|
|
238
|
+
drop(original);
|
|
239
|
+
let processed = if apply {
|
|
240
|
+
let mut backend = super::backend::Backend::open(&selected.run_workspace, &selected.team_key)
|
|
241
|
+
.map_err(|error| error.to_string())?;
|
|
242
|
+
if serde_json::to_value(&backend.binding).map_err(|error| error.to_string())? != binding {
|
|
243
|
+
return Err("egress binding changed before claim".into());
|
|
244
|
+
}
|
|
245
|
+
drain(&backend.binding.framework(), &mut backend.store, 32).map_err(|error| error.to_string())?
|
|
246
|
+
} else { 0 };
|
|
247
|
+
let after = super::backend::Backend::open_readonly(&selected.run_workspace, &selected.team_key)
|
|
248
|
+
.map_err(|error| error.to_string())?;
|
|
249
|
+
if serde_json::to_value(&after.binding).map_err(|error| error.to_string())? != binding {
|
|
250
|
+
return Err("egress binding changed during forwarding".into());
|
|
251
|
+
}
|
|
252
|
+
let pending: Vec<_> = after.store.pending_forwards(32).map_err(|error| error.to_string())?
|
|
253
|
+
.into_iter().map(|intent| intent.id).collect();
|
|
254
|
+
Ok(json!({"scope":expected_scope,"team":team,"apply":apply,"processed":processed,
|
|
255
|
+
"pending_before":before,"pending_after":pending,"binding_unchanged":true,
|
|
256
|
+
"native_input":"not_invoked","coordinator_lifecycle":"not_invoked",
|
|
257
|
+
"leader_consumption":"requires actual natural receipt"}))
|
|
258
|
+
}
|
|
259
|
+
|
|
211
260
|
#[cfg(test)]
|
|
212
261
|
mod tests {
|
|
213
262
|
use super::*;
|
|
214
263
|
#[test]
|
|
264
|
+
fn egress_operator_refuses_implicit_workspace_team_and_invalid_scope_before_io() {
|
|
265
|
+
for (workspace, team, scope) in [
|
|
266
|
+
("relative", "team", "scope"), ("/", "", "scope"),
|
|
267
|
+
("/", " team", "scope"), ("/", "team", ""), ("/", "team", "bad/scope"),
|
|
268
|
+
] {
|
|
269
|
+
assert!(drain_scoped_pending_egress(std::path::Path::new(workspace), team, scope, false).is_err());
|
|
270
|
+
assert!(drain_scoped_pending_egress(std::path::Path::new(workspace), team, scope, true).is_err());
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
#[test]
|
|
215
274
|
fn compact_native_result_becomes_the_existing_framework_business_schema() {
|
|
216
275
|
let compact = json!({"schema_version":1,"agent_id":"worker","task_id":"msg-bound","status":"completed","summary":"5535"});
|
|
217
276
|
let result = framework_result("result-fixed", "worker", &compact).unwrap();
|
|
@@ -127,23 +127,29 @@ pub fn start_role(
|
|
|
127
127
|
team: &str,
|
|
128
128
|
id: &str,
|
|
129
129
|
) -> Result<(), crate::lifecycle::LifecycleError> {
|
|
130
|
-
let
|
|
131
|
-
|
|
132
|
-
.
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
.
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
.
|
|
139
|
-
|
|
140
|
-
backend::start(
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
"native startup {:?}: {}",
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
130
|
+
let result = super::commands::with_agent(workspace, Some(team), id, "start-role", |selected, seat| {
|
|
131
|
+
let error = |error: String| crate::cli::CliError::Runtime(error);
|
|
132
|
+
if directory.canonicalize()? != selected.team_dir.canonicalize()? {
|
|
133
|
+
return Err(error("native role source changed while acquiring lifecycle ownership".into()));
|
|
134
|
+
}
|
|
135
|
+
let config = team_config(&selected.run_workspace, &selected.team_dir, &selected.team_key)
|
|
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)
|
|
150
|
+
}).map_err(|e| crate::lifecycle::LifecycleError::Provider(e.to_string()))?;
|
|
151
|
+
if result.is_none() {
|
|
152
|
+
return Err(crate::lifecycle::LifecycleError::Provider("native startup scope/seat is not addressable; no legacy fallback".into()));
|
|
147
153
|
}
|
|
148
154
|
Ok(())
|
|
149
155
|
}
|
|
@@ -15,6 +15,7 @@ use super::*;
|
|
|
15
15
|
/// agent. `has_session`→true (gate passes); `inject`→Ok (delivery may run); the rest are Ok defaults.
|
|
16
16
|
struct CapturingTransport {
|
|
17
17
|
scrollback: String,
|
|
18
|
+
targets: Vec<PaneInfo>,
|
|
18
19
|
}
|
|
19
20
|
impl Transport for CapturingTransport {
|
|
20
21
|
fn kind(&self) -> BackendKind {
|
|
@@ -73,7 +74,7 @@ impl Transport for CapturingTransport {
|
|
|
73
74
|
Ok(PaneLiveness::Live)
|
|
74
75
|
}
|
|
75
76
|
fn list_targets(&self) -> Result<Vec<PaneInfo>, TransportError> {
|
|
76
|
-
Ok(
|
|
77
|
+
Ok(self.targets.clone())
|
|
77
78
|
}
|
|
78
79
|
fn has_session(&self, _s: &SessionName) -> Result<bool, TransportError> {
|
|
79
80
|
Ok(true)
|
|
@@ -106,6 +107,14 @@ impl Transport for CapturingTransport {
|
|
|
106
107
|
fn seeded_health_coord(
|
|
107
108
|
agents: serde_json::Value,
|
|
108
109
|
scrollback: &str,
|
|
110
|
+
) -> (Coordinator, std::path::PathBuf) {
|
|
111
|
+
seeded_health_coord_with_readiness(agents, scrollback, false)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
fn seeded_health_coord_with_readiness(
|
|
115
|
+
agents: serde_json::Value,
|
|
116
|
+
scrollback: &str,
|
|
117
|
+
ready: bool,
|
|
109
118
|
) -> (Coordinator, std::path::PathBuf) {
|
|
110
119
|
use std::sync::atomic::{AtomicU64, Ordering};
|
|
111
120
|
static N: AtomicU64 = AtomicU64::new(0);
|
|
@@ -115,11 +124,18 @@ fn seeded_health_coord(
|
|
|
115
124
|
N.fetch_add(1, Ordering::Relaxed)
|
|
116
125
|
));
|
|
117
126
|
std::fs::create_dir_all(&dir).unwrap();
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
127
|
+
let mut state = serde_json::json!({ "session_name": "team-health", "agents": agents });
|
|
128
|
+
#[cfg(unix)]
|
|
129
|
+
let targets = if ready {
|
|
130
|
+
vec![crate::mcp_server::readiness::test_ready_worker(
|
|
131
|
+
&dir, &mut state, "current", "w1", "%1",
|
|
132
|
+
)]
|
|
133
|
+
} else {
|
|
134
|
+
Vec::new()
|
|
135
|
+
};
|
|
136
|
+
#[cfg(not(unix))]
|
|
137
|
+
let targets = { let _ = ready; Vec::new() };
|
|
138
|
+
crate::state::persist::save_runtime_state(&dir, &state).unwrap();
|
|
123
139
|
let ws = WorkspacePath::new(dir.clone());
|
|
124
140
|
let reg: Box<dyn ProviderRegistry> = Box::new(MockRegistry::new(&[], &[]));
|
|
125
141
|
let coord = Coordinator::for_test(
|
|
@@ -127,6 +143,7 @@ fn seeded_health_coord(
|
|
|
127
143
|
reg,
|
|
128
144
|
Box::new(CapturingTransport {
|
|
129
145
|
scrollback: scrollback.to_string(),
|
|
146
|
+
targets,
|
|
130
147
|
}),
|
|
131
148
|
None,
|
|
132
149
|
None,
|
|
@@ -260,10 +277,12 @@ fn spine2_capture_missing_captures_session_id_for_missing_agent() {
|
|
|
260
277
|
// activity/agent_health WORKING remains diagnostic turn state.
|
|
261
278
|
#[test]
|
|
262
279
|
fn spine2_sync_health_working_status_delivers_same_tick() {
|
|
263
|
-
let (coord, dir) =
|
|
280
|
+
let (coord, dir) = seeded_health_coord_with_readiness(
|
|
281
|
+
one_agent("codex"), "Working (5s · esc to interrupt)", true,
|
|
282
|
+
);
|
|
264
283
|
let store = MessageStore::open(&dir).unwrap();
|
|
265
284
|
let mid = store
|
|
266
|
-
.create_message(Some("t"), "leader", "w1", "hi", None, true,
|
|
285
|
+
.create_message(Some("t"), "leader", "w1", "hi", None, true, Some("current"))
|
|
267
286
|
.unwrap();
|
|
268
287
|
let conn = crate::db::schema::open_db(store.db_path()).unwrap();
|
|
269
288
|
conn.execute(
|
|
@@ -1579,15 +1579,10 @@ pub(crate) fn quick_start_with_transport_in_workspace_pi_preflight(
|
|
|
1579
1579
|
crate::lifecycle::restart::LifecyclePhase::ReadinessWait,
|
|
1580
1580
|
);
|
|
1581
1581
|
let worker_readiness = quick_start_worker_readiness(&workspace, &state_team_key);
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
&state,
|
|
1587
|
-
started_attach_window_names(&launch.started),
|
|
1588
|
-
)
|
|
1589
|
-
})
|
|
1590
|
-
.unwrap_or_else(|| started_attach_window_names(&launch.started));
|
|
1582
|
+
// The selected server is the display surface. Do not invent a leader
|
|
1583
|
+
// window or omit native windows merely because they are not legacy starts.
|
|
1584
|
+
let attach_windows = transport.list_windows(&session_name).unwrap_or_default()
|
|
1585
|
+
.into_iter().map(|window| window.as_str().to_owned()).collect::<Vec<_>>();
|
|
1591
1586
|
let attach_commands = attach_commands_for_runtime_windows(
|
|
1592
1587
|
launch.tmux_endpoint.as_deref(),
|
|
1593
1588
|
&workspace,
|
|
@@ -1597,15 +1592,9 @@ pub(crate) fn quick_start_with_transport_in_workspace_pi_preflight(
|
|
|
1597
1592
|
let mut next_actions = vec![format!(
|
|
1598
1593
|
"team compiled; real spawn is behind the transport/provider boundary; {coordinator_action}"
|
|
1599
1594
|
)];
|
|
1600
|
-
// Stage QR (design doc
|
|
1601
|
-
// .team/artifacts/quickstart-restart-separation-design.md):
|
|
1602
|
-
// quick-start is initial-creation-only. After success, remind the
|
|
1603
|
-
// operator that subsequent starts must go through restart so the
|
|
1604
|
-
// user's context (sessions, ownership, tasks) survives.
|
|
1605
1595
|
next_actions.push(
|
|
1606
|
-
"
|
|
1607
|
-
`team-agent restart`
|
|
1608
|
-
already-initialised teams)"
|
|
1596
|
+
"team initialized; use `team-agent start` for idempotent activation, or \
|
|
1597
|
+
`team-agent team restart` for an intentional restart; quick-start is a compatibility creation command"
|
|
1609
1598
|
.to_string(),
|
|
1610
1599
|
);
|
|
1611
1600
|
if should_emit_workspace_socket_missing_hint(
|
|
@@ -239,25 +239,10 @@ pub(super) fn attach_commands_for_runtime_windows<'a>(
|
|
|
239
239
|
) -> Vec<String> {
|
|
240
240
|
let windows = window_names.into_iter().collect::<Vec<_>>();
|
|
241
241
|
let attach = if let Some(endpoint) = endpoint.filter(|endpoint| !endpoint.is_empty()) {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
format!(
|
|
247
|
-
"tmux -S {} attach -t {}:{}",
|
|
248
|
-
endpoint,
|
|
249
|
-
session_name.as_str(),
|
|
250
|
-
window_name
|
|
251
|
-
)
|
|
252
|
-
})
|
|
253
|
-
.collect::<Vec<_>>()
|
|
254
|
-
} else {
|
|
255
|
-
crate::tmux_backend::attach_commands_for_windows(
|
|
256
|
-
workspace,
|
|
257
|
-
session_name,
|
|
258
|
-
windows.iter().copied(),
|
|
259
|
-
)
|
|
260
|
-
}
|
|
242
|
+
let address = serde_json::json!({"tmux_endpoint":endpoint});
|
|
243
|
+
windows.iter().filter_map(|window| crate::tmux_backend::attach_command_for_runtime_state_or_workspace(
|
|
244
|
+
workspace, Some(&address), session_name, window,
|
|
245
|
+
)).collect::<Vec<_>>()
|
|
261
246
|
} else {
|
|
262
247
|
crate::tmux_backend::attach_commands_for_windows(
|
|
263
248
|
workspace,
|
|
@@ -359,3 +344,25 @@ pub(super) fn attach_window_names_with_managed_leader(
|
|
|
359
344
|
pub(super) fn state_uses_managed_leader(state: &serde_json::Value) -> bool {
|
|
360
345
|
crate::state::projection::state_is_managed_leader(state)
|
|
361
346
|
}
|
|
347
|
+
|
|
348
|
+
#[cfg(test)]
|
|
349
|
+
mod workspace_attach_tests {
|
|
350
|
+
use super::*;
|
|
351
|
+
|
|
352
|
+
#[test]
|
|
353
|
+
fn explicit_shared_endpoint_is_not_replaced_by_workspace_hash() {
|
|
354
|
+
let session = SessionName::new("team-native");
|
|
355
|
+
assert_eq!(attach_commands_for_runtime_windows(Some("authorized-workspace"),
|
|
356
|
+
Path::new("/not-the-selected-socket"), &session, ["grok-worker"]),
|
|
357
|
+
["tmux -L authorized-workspace attach -t team-native:grok-worker"]);
|
|
358
|
+
assert_eq!(attach_commands_for_runtime_windows(Some("/private/tmp/owned/tmux.sock"),
|
|
359
|
+
Path::new("/not-the-selected-socket"), &session, ["grok-worker"]),
|
|
360
|
+
["tmux -S /private/tmp/owned/tmux.sock attach -t team-native:grok-worker"]);
|
|
361
|
+
assert!(attach_commands_for_runtime_windows(Some("authorized-workspace"),
|
|
362
|
+
Path::new("/not-the-selected-socket"), &session, std::iter::empty()).is_empty());
|
|
363
|
+
assert_eq!(attach_commands_for_runtime_windows(Some("authorized-workspace"),
|
|
364
|
+
Path::new("/not-the-selected-socket"), &session, ["leader", "grok-worker"]),
|
|
365
|
+
["tmux -L authorized-workspace attach -t team-native:leader",
|
|
366
|
+
"tmux -L authorized-workspace attach -t team-native:grok-worker"]);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
@@ -78,7 +78,13 @@ pub(super) fn spawn_agents(
|
|
|
78
78
|
let mut contract_started = Vec::new();
|
|
79
79
|
#[cfg(not(unix))]
|
|
80
80
|
let contract_started = Vec::new();
|
|
81
|
-
|
|
81
|
+
let agents = spec_agent_values(spec);
|
|
82
|
+
#[cfg(unix)]
|
|
83
|
+
let has_contract = agents.iter().any(|agent| agent.get("provider").and_then(Value::as_str)
|
|
84
|
+
.is_some_and(|provider| crate::contract_runtime::registry::descriptor(provider).is_some()));
|
|
85
|
+
#[cfg(not(unix))]
|
|
86
|
+
let has_contract = false;
|
|
87
|
+
for agent in agents {
|
|
82
88
|
let Some(agent_id_raw) = agent.get("id").and_then(Value::as_str) else {
|
|
83
89
|
continue;
|
|
84
90
|
};
|
|
@@ -406,7 +412,7 @@ pub(super) fn spawn_agents(
|
|
|
406
412
|
}
|
|
407
413
|
// One independent tmux window per worker; no GUI/display layout.
|
|
408
414
|
let window = WindowName::new(agent_id_raw);
|
|
409
|
-
let spawn = if started.is_empty() {
|
|
415
|
+
let spawn = if started.is_empty() && contract_started.is_empty() {
|
|
410
416
|
transport.spawn_first_with_env_unset(
|
|
411
417
|
session_name,
|
|
412
418
|
&window,
|
|
@@ -455,6 +461,17 @@ pub(super) fn spawn_agents(
|
|
|
455
461
|
.or_else(|| profile_launch.claude_projects_root.clone()),
|
|
456
462
|
managed_mcp_config: plan.managed_mcp_config || profile_launch.managed_mcp_config,
|
|
457
463
|
});
|
|
464
|
+
if has_contract && contract_started.is_empty() && started.len() == 1 {
|
|
465
|
+
// A native seat following the first legacy seat must be able to
|
|
466
|
+
// verify the same session before borrowing it, not after the batch.
|
|
467
|
+
let selected = crate::state::selector::resolve_active_team_readonly(workspace,
|
|
468
|
+
Some(&mcp_team_id), crate::state::selector::SelectorMode::RuntimeOnly)
|
|
469
|
+
.map_err(|e| LifecycleError::TeamSelect(e.to_string()))?;
|
|
470
|
+
let generation = crate::state::projection::session_generation(&selected.state)
|
|
471
|
+
.unwrap_or(session_name.as_str());
|
|
472
|
+
transport.set_session_owner_with_generation(session_name, workspace, &mcp_team_id, generation)
|
|
473
|
+
.map_err(|e| LifecycleError::Transport(e.to_string()))?;
|
|
474
|
+
}
|
|
458
475
|
}
|
|
459
476
|
Ok((started, contract_started))
|
|
460
477
|
}
|
|
@@ -1410,6 +1410,9 @@ pub(super) fn mark_agent_started(
|
|
|
1410
1410
|
"spawn_cwd".to_string(),
|
|
1411
1411
|
serde_json::json!(spawn.spawn_cwd.to_string_lossy().to_string()),
|
|
1412
1412
|
);
|
|
1413
|
+
if let Some(path) = &spawn.mcp_config_path {
|
|
1414
|
+
agent.insert("mcp_config".to_string(), serde_json::json!(path));
|
|
1415
|
+
}
|
|
1413
1416
|
// 0.4.6 Stage 1+2: ensure spawn_epoch is present after every start.
|
|
1414
1417
|
// reset_agent_at_paths bumps it before start; non-reset starts
|
|
1415
1418
|
// initialise to 1 (or preserve existing) so capture/event paths can
|
|
@@ -45,6 +45,8 @@ pub(super) struct SpawnedAgentWindow {
|
|
|
45
45
|
pub profile_launch: crate::provider::ProviderProfileLaunch,
|
|
46
46
|
pub layout_placement: Option<crate::lifecycle::launch::LayoutPlacement>,
|
|
47
47
|
pub spawn_cwd: std::path::PathBuf,
|
|
48
|
+
/// Actual configuration generated for this spawn, not inferred from old state.
|
|
49
|
+
pub mcp_config_path: Option<std::path::PathBuf>,
|
|
48
50
|
/// Issue 2 (Round 3b gate review §6): the resolved `owner_team_id` used
|
|
49
51
|
/// for this spawn's MCP env / command. Callers (`mark_agent_respawned`,
|
|
50
52
|
/// `mark_agent_started`) must persist this back into the agent row so
|
|
@@ -701,6 +703,7 @@ pub(super) fn spawn_agent_window(
|
|
|
701
703
|
profile_launch,
|
|
702
704
|
layout_placement: layout_placement.cloned(),
|
|
703
705
|
spawn_cwd: native_spawn_cwd,
|
|
706
|
+
mcp_config_path,
|
|
704
707
|
owner_team_id: team_id,
|
|
705
708
|
})
|
|
706
709
|
}
|