@team-agent/installer 0.5.122 → 0.5.124
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 +103 -43
- package/crates/team-agent/src/cli/intent/runtime_tests.rs +198 -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/cli/models.rs +54 -10
- package/crates/team-agent/src/contract_runtime/backend.rs +498 -2
- package/crates/team-agent/src/contract_runtime/commands.rs +38 -24
- package/crates/team-agent/src/contract_runtime/discovery.rs +46 -56
- 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/contract_runtime/registry.rs +41 -3
- package/crates/team-agent/src/lifecycle/launch/pi_mcp.rs +19 -101
- 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/rebuild.rs +95 -31
- package/crates/team-agent/src/lifecycle/restart.rs +1 -0
- package/crates/team-agent/src/lifecycle/tests/cli_argv_routing_red.rs +5 -6
- package/crates/team-agent/src/lifecycle/tests/launch_spawn.rs +7 -5
- 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/messaging/delivery.rs +5 -3
- package/crates/team-agent/src/provider/adapters/pi.rs +4 -4
- package/crates/team-agent/src/provider/session_scan/pi.rs +32 -19
- package/crates/team-agent/src/provider/tests/command_helpers.rs +2 -2
- package/crates/team-agent/src/provider/wire.rs +2 -1
- package/npm/install.mjs +56 -99
- package/package.json +4 -4
package/Cargo.lock
CHANGED
|
@@ -727,7 +727,7 @@ dependencies = [
|
|
|
727
727
|
|
|
728
728
|
[[package]]
|
|
729
729
|
name = "team-agent"
|
|
730
|
-
version = "0.5.
|
|
730
|
+
version = "0.5.124"
|
|
731
731
|
dependencies = [
|
|
732
732
|
"anyhow",
|
|
733
733
|
"chrono",
|
|
@@ -755,6 +755,7 @@ dependencies = [
|
|
|
755
755
|
"serde",
|
|
756
756
|
"serde_json",
|
|
757
757
|
"sha2",
|
|
758
|
+
"unicode-width",
|
|
758
759
|
]
|
|
759
760
|
|
|
760
761
|
[[package]]
|
|
@@ -789,6 +790,12 @@ version = "1.0.26"
|
|
|
789
790
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
790
791
|
checksum = "d245f478577f809a851594d02313b640fb437e0bb33866753cff937863096954"
|
|
791
792
|
|
|
793
|
+
[[package]]
|
|
794
|
+
name = "unicode-width"
|
|
795
|
+
version = "0.2.2"
|
|
796
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
797
|
+
checksum = "b4ac048d71ede7ee76d585517add45da530660ef4390e49b098733c6e897f254"
|
|
798
|
+
|
|
792
799
|
[[package]]
|
|
793
800
|
name = "vcpkg"
|
|
794
801
|
version = "0.2.15"
|
package/Cargo.toml
CHANGED
|
@@ -93,6 +93,79 @@ pub(crate) fn classify_tmux_server_error(error_text: &str) -> &'static str {
|
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
+
fn recorded_mux_pane(agent_state: &Value) -> Option<&str> {
|
|
97
|
+
["pane_id", "native_pane"].iter().find_map(|key| {
|
|
98
|
+
agent_state
|
|
99
|
+
.get(*key)
|
|
100
|
+
.and_then(Value::as_str)
|
|
101
|
+
.filter(|value| !value.is_empty())
|
|
102
|
+
})
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
fn explicit_window_name(agent_state: &Value) -> Option<&str> {
|
|
106
|
+
["window", "window_name"].iter().find_map(|key| {
|
|
107
|
+
agent_state
|
|
108
|
+
.get(*key)
|
|
109
|
+
.and_then(Value::as_str)
|
|
110
|
+
.filter(|value| !value.is_empty())
|
|
111
|
+
})
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
fn is_public_window_name(provider: &str, window: &str) -> bool {
|
|
115
|
+
// Contract ids such as grok_build are not legacy Provider aliases, but
|
|
116
|
+
// their tmux title is the public command, not the seat id.
|
|
117
|
+
if provider == "grok_build" && window == "grok" {
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
parse_provider(provider).is_some_and(|parsed| {
|
|
121
|
+
command_name(parsed) == window
|
|
122
|
+
|| crate::layout::worker_window_helpers::provider_window_name(parsed) == window
|
|
123
|
+
})
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
fn window_name_reconciles(
|
|
127
|
+
agent_id: &str,
|
|
128
|
+
agent_state: &Value,
|
|
129
|
+
windows: &[crate::transport::WindowName],
|
|
130
|
+
) -> bool {
|
|
131
|
+
let explicit = explicit_window_name(agent_state);
|
|
132
|
+
let provider = agent_state
|
|
133
|
+
.get("provider")
|
|
134
|
+
.and_then(Value::as_str)
|
|
135
|
+
.unwrap_or("");
|
|
136
|
+
windows.iter().any(|window| {
|
|
137
|
+
let name = window.as_str();
|
|
138
|
+
explicit.is_some_and(|expected| expected == name)
|
|
139
|
+
|| is_public_window_name(provider, name)
|
|
140
|
+
|| name == agent_id
|
|
141
|
+
})
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/// A native CLI owns its window title. Seat presence is the recorded pane id
|
|
145
|
+
/// on this transport; display names are only a fallback.
|
|
146
|
+
fn worker_window_is_missing(
|
|
147
|
+
agent_id: &str,
|
|
148
|
+
agent_state: &Value,
|
|
149
|
+
windows: &[crate::transport::WindowName],
|
|
150
|
+
panes: &[crate::transport::PaneInfo],
|
|
151
|
+
backend: &dyn Transport,
|
|
152
|
+
) -> bool {
|
|
153
|
+
if let Some(pane_id) = recorded_mux_pane(agent_state) {
|
|
154
|
+
if panes.iter().any(|pane| pane.pane_id.as_str() == pane_id) {
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
if !panes.is_empty() {
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
match backend.has_pane(&crate::transport::PaneId::new(pane_id)) {
|
|
161
|
+
Ok(Some(true)) => return false,
|
|
162
|
+
Ok(Some(false)) => return true,
|
|
163
|
+
_ => {}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
!window_name_reconciles(agent_id, agent_state, windows)
|
|
167
|
+
}
|
|
168
|
+
|
|
96
169
|
pub(crate) fn diagnose_runtime(state: &Value, backend: &dyn Transport) -> (Value, Value) {
|
|
97
170
|
diagnose_runtime_with_workspace(None, state, backend)
|
|
98
171
|
}
|
|
@@ -244,6 +317,7 @@ fn diagnose_runtime_with_workspace(
|
|
|
244
317
|
if let Ok(windows) = backend.list_windows(&crate::transport::SessionName::new(
|
|
245
318
|
session_name.to_string(),
|
|
246
319
|
)) {
|
|
320
|
+
let panes = backend.list_targets().unwrap_or_default();
|
|
247
321
|
if let Some(agents) = state.get("agents").and_then(Value::as_object) {
|
|
248
322
|
for (agent_id, agent_state) in agents {
|
|
249
323
|
let provider = agent_state
|
|
@@ -290,16 +364,7 @@ fn diagnose_runtime_with_workspace(
|
|
|
290
364
|
.map(|path| path.to_string_lossy().to_string()),
|
|
291
365
|
}));
|
|
292
366
|
}
|
|
293
|
-
|
|
294
|
-
.iter()
|
|
295
|
-
.find_map(|key| {
|
|
296
|
-
agent_state
|
|
297
|
-
.get(*key)
|
|
298
|
-
.and_then(Value::as_str)
|
|
299
|
-
.filter(|s| !s.is_empty())
|
|
300
|
-
})
|
|
301
|
-
.unwrap_or(agent_id);
|
|
302
|
-
if !windows.iter().any(|w| w.as_str() == window) {
|
|
367
|
+
if worker_window_is_missing(agent_id, agent_state, &windows, &panes, backend) {
|
|
303
368
|
issues.push(json!(format!("worker_window_missing:{agent_id}")));
|
|
304
369
|
}
|
|
305
370
|
if agent_state
|
|
@@ -1309,6 +1374,107 @@ mod tests {
|
|
|
1309
1374
|
);
|
|
1310
1375
|
let _ = std::fs::remove_dir_all(&workspace);
|
|
1311
1376
|
}
|
|
1377
|
+
|
|
1378
|
+
fn pane(session: &str, pane_id: &str, window: &str) -> crate::transport::PaneInfo {
|
|
1379
|
+
crate::transport::PaneInfo {
|
|
1380
|
+
pane_id: crate::transport::PaneId::new(pane_id),
|
|
1381
|
+
session: crate::transport::SessionName::new(session),
|
|
1382
|
+
window_index: None,
|
|
1383
|
+
window_name: Some(crate::transport::WindowName::new(window)),
|
|
1384
|
+
pane_index: None,
|
|
1385
|
+
tty: None,
|
|
1386
|
+
current_command: Some(window.to_string()),
|
|
1387
|
+
current_path: None,
|
|
1388
|
+
active: true,
|
|
1389
|
+
pane_pid: Some(1),
|
|
1390
|
+
leader_env: Default::default(),
|
|
1391
|
+
}
|
|
1392
|
+
}
|
|
1393
|
+
|
|
1394
|
+
fn has_issue(issues: &Value, issue: &str) -> bool {
|
|
1395
|
+
issues
|
|
1396
|
+
.as_array()
|
|
1397
|
+
.is_some_and(|items| items.iter().any(|item| item.as_str() == Some(issue)))
|
|
1398
|
+
}
|
|
1399
|
+
|
|
1400
|
+
fn grok_state(extra: Value) -> Value {
|
|
1401
|
+
let mut agent = json!({
|
|
1402
|
+
"provider": "grok_build",
|
|
1403
|
+
"status": "running",
|
|
1404
|
+
"runtime_family": "contract",
|
|
1405
|
+
"window": null,
|
|
1406
|
+
"pane_id": null,
|
|
1407
|
+
"session_name": null
|
|
1408
|
+
});
|
|
1409
|
+
if let (Some(agent), Some(extra)) = (agent.as_object_mut(), extra.as_object()) {
|
|
1410
|
+
for (key, value) in extra {
|
|
1411
|
+
agent.insert(key.clone(), value.clone());
|
|
1412
|
+
}
|
|
1413
|
+
}
|
|
1414
|
+
json!({
|
|
1415
|
+
"session_name": "team-current",
|
|
1416
|
+
"agents": { "grok-seat": agent }
|
|
1417
|
+
})
|
|
1418
|
+
}
|
|
1419
|
+
|
|
1420
|
+
#[test]
|
|
1421
|
+
fn doctor_accepts_live_native_pane_when_window_title_is_not_agent_id() {
|
|
1422
|
+
let state = grok_state(json!({"native_pane": "%1"}));
|
|
1423
|
+
let backend = crate::transport::test_support::OfflineTransport::new()
|
|
1424
|
+
.with_session_present(true)
|
|
1425
|
+
.with_windows(vec![crate::transport::WindowName::new("grok")])
|
|
1426
|
+
.with_targets(vec![pane("team-current", "%1", "renamed-by-cli")]);
|
|
1427
|
+
let (issues, _) = diagnose_runtime(&state, &backend);
|
|
1428
|
+
assert!(
|
|
1429
|
+
!has_issue(&issues, "worker_window_missing:grok-seat"),
|
|
1430
|
+
"live pane id must prove the seat without the agent-id window name; issues={issues}"
|
|
1431
|
+
);
|
|
1432
|
+
}
|
|
1433
|
+
|
|
1434
|
+
#[test]
|
|
1435
|
+
fn doctor_does_not_treat_another_public_window_as_a_missing_pane() {
|
|
1436
|
+
let state = grok_state(json!({"native_pane": "%1"}));
|
|
1437
|
+
let backend = crate::transport::test_support::OfflineTransport::new()
|
|
1438
|
+
.with_session_present(true)
|
|
1439
|
+
.with_windows(vec![crate::transport::WindowName::new("grok")])
|
|
1440
|
+
.with_targets(vec![pane("team-current", "%9", "grok")]);
|
|
1441
|
+
let (issues, _) = diagnose_runtime(&state, &backend);
|
|
1442
|
+
assert!(
|
|
1443
|
+
has_issue(&issues, "worker_window_missing:grok-seat"),
|
|
1444
|
+
"a same-named window must not hide a different pane id; issues={issues}"
|
|
1445
|
+
);
|
|
1446
|
+
}
|
|
1447
|
+
|
|
1448
|
+
#[test]
|
|
1449
|
+
fn doctor_accepts_public_window_name_when_no_pane_id_is_recorded() {
|
|
1450
|
+
let state = grok_state(json!({}));
|
|
1451
|
+
let backend = crate::transport::test_support::OfflineTransport::new()
|
|
1452
|
+
.with_session_present(true)
|
|
1453
|
+
.with_windows(vec![crate::transport::WindowName::new("grok")]);
|
|
1454
|
+
let (issues, _) = diagnose_runtime(&state, &backend);
|
|
1455
|
+
assert!(
|
|
1456
|
+
!has_issue(&issues, "worker_window_missing:grok-seat"),
|
|
1457
|
+
"public command title is a valid fallback; issues={issues}"
|
|
1458
|
+
);
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1461
|
+
#[test]
|
|
1462
|
+
fn doctor_still_accepts_legacy_agent_id_window_name() {
|
|
1463
|
+
let state = json!({
|
|
1464
|
+
"session_name": "team-current",
|
|
1465
|
+
"agents": {
|
|
1466
|
+
"worker-a": { "provider": "pi", "status": "running" }
|
|
1467
|
+
}
|
|
1468
|
+
});
|
|
1469
|
+
let backend = crate::transport::test_support::OfflineTransport::new()
|
|
1470
|
+
.with_session_present(true)
|
|
1471
|
+
.with_windows(vec![crate::transport::WindowName::new("worker-a")]);
|
|
1472
|
+
let (issues, _) = diagnose_runtime(&state, &backend);
|
|
1473
|
+
assert!(
|
|
1474
|
+
!has_issue(&issues, "worker_window_missing:worker-a"),
|
|
1475
|
+
"legacy agent-id windows remain present; issues={issues}"
|
|
1476
|
+
);
|
|
1477
|
+
}
|
|
1312
1478
|
}
|
|
1313
1479
|
|
|
1314
1480
|
pub(crate) fn build_profile_smoke_check_for_team(
|
|
@@ -243,6 +243,11 @@ fn check_native_noop_settings(
|
|
|
243
243
|
"native launch configuration drift for {id}; stop before applying settings"
|
|
244
244
|
)));
|
|
245
245
|
}
|
|
246
|
+
checked(crate::contract_runtime::backend::preflight_start_role(
|
|
247
|
+
&selected.run_workspace,
|
|
248
|
+
&selected.team_key,
|
|
249
|
+
current,
|
|
250
|
+
))?;
|
|
246
251
|
}
|
|
247
252
|
Ok(())
|
|
248
253
|
}
|
|
@@ -278,6 +283,29 @@ fn shell_carrier(command: &str) -> bool {
|
|
|
278
283
|
fn surface_liveness(command: &str, native_frame: bool, live_child: bool) -> bool {
|
|
279
284
|
!command.is_empty() && native_frame && (!shell_carrier(command) || live_child)
|
|
280
285
|
}
|
|
286
|
+
fn argv0_names(argv0: &str, native: crate::provider::Provider) -> bool {
|
|
287
|
+
Path::new(argv0).file_name().and_then(|name| name.to_str())
|
|
288
|
+
== Some(crate::provider::wire::command_name(native))
|
|
289
|
+
}
|
|
290
|
+
/// Native installers may exec a version-named file (Claude Code:
|
|
291
|
+
/// `~/.local/bin/claude` -> `versions/<semver>`), so tmux reports the version
|
|
292
|
+
/// as the pane command. The exact argv[0] of the pane process, or of a live
|
|
293
|
+
/// child under its carrier, still names the provider. Unobservable is not
|
|
294
|
+
/// positive evidence.
|
|
295
|
+
fn launched_as_provider(pid: u32, native: crate::provider::Provider) -> bool {
|
|
296
|
+
let named = |pid: u32| {
|
|
297
|
+
crate::platform::argv::argv_tokens(pid)
|
|
298
|
+
.and_then(|argv| argv.into_iter().next())
|
|
299
|
+
.is_some_and(|argv0| argv0_names(&argv0, native))
|
|
300
|
+
};
|
|
301
|
+
named(pid)
|
|
302
|
+
|| crate::platform::process::process_tree(pid)
|
|
303
|
+
.unwrap_or_default()
|
|
304
|
+
.into_iter()
|
|
305
|
+
.any(|child| {
|
|
306
|
+
child != pid && named(child) && crate::platform::process::pid_is_alive(child)
|
|
307
|
+
})
|
|
308
|
+
}
|
|
281
309
|
|
|
282
310
|
/// Positive native/store or exact carrier+pane+provider observations only.
|
|
283
311
|
fn observe(selected: &SelectedTeam, id: &str, row: &Value) -> Result<Observation, CliError> {
|
|
@@ -294,6 +322,16 @@ fn observe(selected: &SelectedTeam, id: &str, row: &Value) -> Result<Observation
|
|
|
294
322
|
if crate::contract_runtime::framework::is_paused_unstarted(row) {
|
|
295
323
|
return Ok(Observation::Unstarted);
|
|
296
324
|
}
|
|
325
|
+
if checked(
|
|
326
|
+
crate::contract_runtime::backend::start_needs_reconciliation(
|
|
327
|
+
&selected.run_workspace,
|
|
328
|
+
&selected.team_key,
|
|
329
|
+
&checked(SeatId::new(id))?,
|
|
330
|
+
row,
|
|
331
|
+
),
|
|
332
|
+
)? {
|
|
333
|
+
return Ok(Observation::NativeReconcile);
|
|
334
|
+
}
|
|
297
335
|
let backend = checked(crate::contract_runtime::backend::Backend::open_readonly(
|
|
298
336
|
&selected.run_workspace,
|
|
299
337
|
&selected.team_key,
|
|
@@ -386,7 +424,8 @@ fn observe(selected: &SelectedTeam, id: &str, row: &Value) -> Result<Observation
|
|
|
386
424
|
}
|
|
387
425
|
let command = matches[0].current_command.as_deref().unwrap_or("");
|
|
388
426
|
let positive_command = command == crate::provider::wire::command_name(native)
|
|
389
|
-
|| crate::leader::provider_attribution::command_matches_provider(native, command)
|
|
427
|
+
|| crate::leader::provider_attribution::command_matches_provider(native, command)
|
|
428
|
+
|| (!command.is_empty() && !shell_carrier(command) && launched_as_provider(pid, native));
|
|
390
429
|
let positive_surface = if !positive_command && !command.is_empty() {
|
|
391
430
|
let frame = checked(
|
|
392
431
|
backend.observe_native_input(&Target::Pane(PaneId::new(pane.unwrap_or(""))), native),
|
|
@@ -481,7 +520,6 @@ fn preflight_start(
|
|
|
481
520
|
) -> Result<(), CliError> {
|
|
482
521
|
#[cfg(unix)]
|
|
483
522
|
if crate::contract_runtime::framework::is_contract(row) {
|
|
484
|
-
use team_agent_contract::contract::types::SeatId;
|
|
485
523
|
let config = checked(crate::contract_runtime::framework::team_config(
|
|
486
524
|
&selected.run_workspace,
|
|
487
525
|
&selected.team_dir,
|
|
@@ -493,12 +531,17 @@ fn preflight_start(
|
|
|
493
531
|
.iter()
|
|
494
532
|
.find(|r| r.id.as_str() == id)
|
|
495
533
|
.ok_or_else(|| refusal("missing native role"))?;
|
|
496
|
-
|
|
497
|
-
&
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
534
|
+
if crate::contract_runtime::framework::is_paused_unstarted(row) {
|
|
535
|
+
checked(crate::contract_runtime::backend::preflight(&config))?;
|
|
536
|
+
} else {
|
|
537
|
+
if checked(crate::contract_runtime::backend::preflight_start_role(
|
|
538
|
+
&selected.run_workspace,
|
|
539
|
+
&selected.team_key,
|
|
540
|
+
role,
|
|
541
|
+
))? {
|
|
542
|
+
checked(crate::contract_runtime::backend::preflight(&config))?;
|
|
543
|
+
}
|
|
544
|
+
}
|
|
502
545
|
return Ok(());
|
|
503
546
|
}
|
|
504
547
|
let provider = crate::provider::wire::parse_provider(provider(row))
|
|
@@ -814,47 +857,54 @@ fn plan_with_observer(
|
|
|
814
857
|
return Ok(plan);
|
|
815
858
|
}
|
|
816
859
|
let spec = selected.spec_path.as_ref().filter(|p| p.is_file());
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
}
|
|
835
|
-
active = true;
|
|
836
|
-
} else {
|
|
837
|
-
plan.skipped.push(json!({"agent":id,"reason":if paused(row){"paused"}else if crate::state::projection::agent_explicit_stop(row){"explicit_stop"}else{"stopped_preserved_by_original_restart"}}));
|
|
860
|
+
let missing_spec = spec.is_none();
|
|
861
|
+
if missing_spec && plan.intent.verb == Verb::Restart && target.is_none() {
|
|
862
|
+
// Keep restart's stopped-roster fence ahead of spec/source admission.
|
|
863
|
+
// Its original locked handler owns reconstruction for active rosters.
|
|
864
|
+
let rows = selected
|
|
865
|
+
.state
|
|
866
|
+
.get("agents")
|
|
867
|
+
.and_then(Value::as_object)
|
|
868
|
+
.ok_or_else(|| refusal("missing agents"))?;
|
|
869
|
+
let mut active = false;
|
|
870
|
+
for (id, row) in rows {
|
|
871
|
+
if !paused(row)
|
|
872
|
+
&& !crate::state::projection::agent_explicit_stop(row)
|
|
873
|
+
&& !crate::state::projection::agent_stopped_for_restart(row)
|
|
874
|
+
{
|
|
875
|
+
if observe(&selected, id, row)? == Observation::Unknown {
|
|
876
|
+
return Err(refusal("unknown physical identity"));
|
|
838
877
|
}
|
|
878
|
+
active = true;
|
|
879
|
+
} else {
|
|
880
|
+
plan.skipped.push(json!({"agent":id,"reason":if paused(row){"paused"}else if crate::state::projection::agent_explicit_stop(row){"explicit_stop"}else{"stopped_preserved_by_original_restart"}}));
|
|
839
881
|
}
|
|
840
|
-
if !active {
|
|
841
|
-
return Ok(no_eligible(
|
|
842
|
-
plan,
|
|
843
|
-
"missing spec cannot be rebuilt without an active roster",
|
|
844
|
-
));
|
|
845
|
-
}
|
|
846
|
-
plan.steps.push(Step::RestartTeam(restart_args(&plan)));
|
|
847
|
-
return Ok(plan);
|
|
848
882
|
}
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
883
|
+
if !active {
|
|
884
|
+
return Ok(no_eligible(
|
|
885
|
+
plan,
|
|
886
|
+
"stopped roster requires explicit team start",
|
|
887
|
+
));
|
|
888
|
+
}
|
|
889
|
+
plan.steps.push(Step::RestartTeam(restart_args(&plan)));
|
|
890
|
+
return Ok(plan);
|
|
852
891
|
}
|
|
853
|
-
let
|
|
854
|
-
|
|
892
|
+
let runtime_spec =
|
|
893
|
+
crate::model::paths::runtime_spec_path(&selected.run_workspace, &selected.team_key);
|
|
894
|
+
let spec_value = match spec {
|
|
895
|
+
Some(path) => checked(yaml::loads(&std::fs::read_to_string(path)?))?,
|
|
896
|
+
None if plan.intent.verb != Verb::Stop => checked(
|
|
897
|
+
crate::lifecycle::restart::compile_runtime_spec_from_roles(
|
|
898
|
+
&selected.run_workspace, &selected.team_key, &selected.state,
|
|
899
|
+
),
|
|
900
|
+
)?,
|
|
901
|
+
None => return Err(refusal("runtime spec missing; team stop can inspect and stop the selected runtime without rebuilding it")),
|
|
902
|
+
};
|
|
855
903
|
validate_roster(
|
|
856
904
|
&spec_value,
|
|
857
|
-
spec.
|
|
905
|
+
spec.unwrap_or(&runtime_spec)
|
|
906
|
+
.parent()
|
|
907
|
+
.unwrap_or(&selected.run_workspace),
|
|
858
908
|
)?;
|
|
859
909
|
let spec_ids: BTreeSet<String> = spec_value
|
|
860
910
|
.get("agents")
|
|
@@ -1043,6 +1093,16 @@ fn plan_with_observer(
|
|
|
1043
1093
|
{
|
|
1044
1094
|
return Ok(no_eligible(plan, "no eligible nonpaused roster"));
|
|
1045
1095
|
}
|
|
1096
|
+
if missing_spec {
|
|
1097
|
+
plan.steps.insert(
|
|
1098
|
+
0,
|
|
1099
|
+
Step::RestoreSpec {
|
|
1100
|
+
workspace: selected.run_workspace,
|
|
1101
|
+
team: selected.team_key,
|
|
1102
|
+
compiled: spec_value,
|
|
1103
|
+
},
|
|
1104
|
+
);
|
|
1105
|
+
}
|
|
1046
1106
|
Ok(plan)
|
|
1047
1107
|
}
|
|
1048
1108
|
fn restart_args(plan: &Plan) -> RestartArgs {
|
|
@@ -54,6 +54,143 @@ fn absent_source_is_one_original_create_not_restart_or_probe() {
|
|
|
54
54
|
assert_eq!(actions(&plan), [("quick_start", None)]);
|
|
55
55
|
assert!(!crate::state::persist::runtime_state_path(root.path()).exists());
|
|
56
56
|
}
|
|
57
|
+
#[test]
|
|
58
|
+
#[serial_test::serial(env)]
|
|
59
|
+
fn startup_spec_red_stopped_team_uses_start_without_restart_or_planning_writes() {
|
|
60
|
+
let (root, intent) = fixture(&["one", "two"]);
|
|
61
|
+
install(
|
|
62
|
+
root.path(),
|
|
63
|
+
&[("one", "stopped", true), ("two", "stopped", false)],
|
|
64
|
+
);
|
|
65
|
+
let spec = crate::model::paths::runtime_spec_path(root.path(), "fixture");
|
|
66
|
+
std::fs::remove_file(&spec).unwrap();
|
|
67
|
+
let state = crate::state::persist::runtime_state_path(root.path());
|
|
68
|
+
let before = std::fs::read(&state).unwrap();
|
|
69
|
+
let result = plan_with_observer(intent, |_, _, _| Ok(Observation::StoppedVerified));
|
|
70
|
+
assert_eq!(std::fs::read(&state).unwrap(), before);
|
|
71
|
+
assert!(
|
|
72
|
+
!spec.exists(),
|
|
73
|
+
"readonly planning must not rebuild the spec"
|
|
74
|
+
);
|
|
75
|
+
let plan = result.expect("complete roles must provide a noncircular start plan when only the derived spec is missing");
|
|
76
|
+
assert_eq!(
|
|
77
|
+
plan.steps
|
|
78
|
+
.iter()
|
|
79
|
+
.filter_map(|step| match step {
|
|
80
|
+
Step::StartAgent(args) => Some(args.agent.as_str()),
|
|
81
|
+
_ => None,
|
|
82
|
+
})
|
|
83
|
+
.collect::<Vec<_>>(),
|
|
84
|
+
["one", "two"]
|
|
85
|
+
);
|
|
86
|
+
assert!(!plan
|
|
87
|
+
.steps
|
|
88
|
+
.iter()
|
|
89
|
+
.any(|step| matches!(step, Step::RestartTeam(_) | Step::StopAgent(_))));
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
#[test]
|
|
93
|
+
#[serial_test::serial(env)]
|
|
94
|
+
fn startup_spec_red_live_team_recovers_metadata_without_process_restart() {
|
|
95
|
+
let (root, intent) = fixture(&["one"]);
|
|
96
|
+
install(root.path(), &[("one", "running", false)]);
|
|
97
|
+
let spec = crate::model::paths::runtime_spec_path(root.path(), "fixture");
|
|
98
|
+
std::fs::remove_file(&spec).unwrap();
|
|
99
|
+
let state = crate::state::persist::runtime_state_path(root.path());
|
|
100
|
+
let before = std::fs::read(&state).unwrap();
|
|
101
|
+
let result = plan_with_observer(intent, |_, _, _| Ok(Observation::Live));
|
|
102
|
+
assert_eq!(std::fs::read(&state).unwrap(), before);
|
|
103
|
+
assert!(!spec.exists());
|
|
104
|
+
let plan =
|
|
105
|
+
result.expect("missing derived metadata must not require restarting a verified live seat");
|
|
106
|
+
assert!(!plan.steps.iter().any(|step| matches!(
|
|
107
|
+
step,
|
|
108
|
+
Step::StartAgent(_) | Step::StopAgent(_) | Step::RestartTeam(_) | Step::CreateTeam(_)
|
|
109
|
+
)));
|
|
110
|
+
assert!(plan
|
|
111
|
+
.skipped
|
|
112
|
+
.iter()
|
|
113
|
+
.any(|entry| entry["reason"] == "already_running"));
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
#[test]
|
|
117
|
+
#[serial_test::serial(env)]
|
|
118
|
+
fn startup_spec_repair_executes_only_metadata_and_preserves_seat_identity() {
|
|
119
|
+
let (root, intent) = fixture(&["one"]);
|
|
120
|
+
install(root.path(), &[("one", "stopped", true)]);
|
|
121
|
+
let spec = crate::model::paths::runtime_spec_path(root.path(), "fixture");
|
|
122
|
+
std::fs::remove_file(&spec).unwrap();
|
|
123
|
+
let state = crate::state::persist::runtime_state_path(root.path());
|
|
124
|
+
let before: Value = serde_json::from_slice(&std::fs::read(&state).unwrap()).unwrap();
|
|
125
|
+
let plan = plan_with_observer(intent, |_, _, _| Ok(Observation::StoppedVerified)).unwrap();
|
|
126
|
+
let repair = plan
|
|
127
|
+
.steps
|
|
128
|
+
.iter()
|
|
129
|
+
.find(|step| matches!(step, Step::RestoreSpec { .. }))
|
|
130
|
+
.unwrap();
|
|
131
|
+
for _ in 0..2 {
|
|
132
|
+
recheck(&plan, repair, false).unwrap();
|
|
133
|
+
assert_eq!(repair.execute().unwrap().exit, ExitCode::Ok);
|
|
134
|
+
assert!(spec.is_file());
|
|
135
|
+
let after: Value = serde_json::from_slice(&std::fs::read(&state).unwrap()).unwrap();
|
|
136
|
+
assert_eq!(after["teams"]["fixture"]["spec_path"], json!(spec));
|
|
137
|
+
assert_eq!(
|
|
138
|
+
relevant(&after["teams"]["fixture"]["agents"]["one"]),
|
|
139
|
+
relevant(&before["teams"]["fixture"]["agents"]["one"])
|
|
140
|
+
);
|
|
141
|
+
assert_eq!(
|
|
142
|
+
after["teams"]["fixture"]["agents"]["one"]["explicit_stop"],
|
|
143
|
+
true
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
#[test]
|
|
149
|
+
#[serial_test::serial(env)]
|
|
150
|
+
fn startup_spec_repair_rechecks_source_under_lock_and_unknown_stays_blocked() {
|
|
151
|
+
let (root, intent) = fixture(&["one"]);
|
|
152
|
+
install(root.path(), &[("one", "stopped", true)]);
|
|
153
|
+
let spec = crate::model::paths::runtime_spec_path(root.path(), "fixture");
|
|
154
|
+
std::fs::remove_file(&spec).unwrap();
|
|
155
|
+
assert!(plan_with_observer(intent.clone(), |_, _, _| Ok(Observation::Unknown)).is_err());
|
|
156
|
+
assert!(!spec.exists());
|
|
157
|
+
let plan = plan_with_observer(intent, |_, _, _| Ok(Observation::StoppedVerified)).unwrap();
|
|
158
|
+
let repair = plan
|
|
159
|
+
.steps
|
|
160
|
+
.iter()
|
|
161
|
+
.find(|step| matches!(step, Step::RestoreSpec { .. }))
|
|
162
|
+
.unwrap();
|
|
163
|
+
let state = crate::state::persist::runtime_state_path(root.path());
|
|
164
|
+
let before = std::fs::read(&state).unwrap();
|
|
165
|
+
let role = root.path().join("agents/one.md");
|
|
166
|
+
let changed = std::fs::read_to_string(&role)
|
|
167
|
+
.unwrap()
|
|
168
|
+
.replace("Fixture", "Changed role body");
|
|
169
|
+
std::fs::write(role, changed).unwrap();
|
|
170
|
+
assert!(
|
|
171
|
+
repair.execute().is_err(),
|
|
172
|
+
"the executor must not rely only on the earlier planner recheck"
|
|
173
|
+
);
|
|
174
|
+
assert_eq!(std::fs::read(state).unwrap(), before);
|
|
175
|
+
assert!(!spec.exists());
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
#[test]
|
|
179
|
+
#[serial_test::serial(env)]
|
|
180
|
+
fn startup_spec_missing_restart_still_preserves_explicit_stop() {
|
|
181
|
+
let (root, mut intent) = fixture(&["one"]);
|
|
182
|
+
install(root.path(), &[("one", "stopped", true)]);
|
|
183
|
+
let spec = crate::model::paths::runtime_spec_path(root.path(), "fixture");
|
|
184
|
+
std::fs::remove_file(&spec).unwrap();
|
|
185
|
+
intent.verb = Verb::Restart;
|
|
186
|
+
let plan =
|
|
187
|
+
plan_with_observer(intent, |_, _, _| panic!("held seat must not be probed")).unwrap();
|
|
188
|
+
assert!(plan.steps.is_empty());
|
|
189
|
+
assert!(plan.no_eligible.is_some());
|
|
190
|
+
assert_eq!(plan.skipped[0]["reason"], "explicit_stop");
|
|
191
|
+
assert!(!spec.exists());
|
|
192
|
+
}
|
|
193
|
+
|
|
57
194
|
#[test]
|
|
58
195
|
#[serial_test::serial(env)]
|
|
59
196
|
fn stopped_team_starts_both_and_mixed_start_leaves_live_peer_untouched() {
|
|
@@ -566,6 +703,67 @@ fn original_supervised_shell_needs_both_current_native_frame_and_live_child() {
|
|
|
566
703
|
assert!(!surface_liveness("node", false, true));
|
|
567
704
|
}
|
|
568
705
|
|
|
706
|
+
#[test]
|
|
707
|
+
fn provider_argv0_is_exact_basename_not_substring() {
|
|
708
|
+
use crate::model::enums::Provider;
|
|
709
|
+
assert!(argv0_names("claude", Provider::Claude));
|
|
710
|
+
assert!(argv0_names("/Users/u/.local/bin/claude", Provider::Claude));
|
|
711
|
+
assert!(argv0_names("claude", Provider::ClaudeCode));
|
|
712
|
+
for argv0 in ["2.1.309", "claude-wrapper", "team-agent", "node", ""] {
|
|
713
|
+
assert!(!argv0_names(argv0, Provider::Claude), "{argv0}");
|
|
714
|
+
}
|
|
715
|
+
assert!(argv0_names("agent", Provider::CursorAgent));
|
|
716
|
+
assert!(!argv0_names("team-agent", Provider::CursorAgent));
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
#[test]
|
|
720
|
+
#[cfg(unix)]
|
|
721
|
+
fn version_named_native_install_is_identified_by_launch_argv0() {
|
|
722
|
+
// Claude Code's native installer execs `versions/<semver>`; tmux then
|
|
723
|
+
// reports e.g. `2.1.309` as the pane command while argv[0] stays `claude`.
|
|
724
|
+
use crate::model::enums::Provider;
|
|
725
|
+
use std::os::unix::process::CommandExt;
|
|
726
|
+
let mut claude = std::process::Command::new("sleep")
|
|
727
|
+
.arg0("claude")
|
|
728
|
+
.arg("30")
|
|
729
|
+
.spawn()
|
|
730
|
+
.unwrap();
|
|
731
|
+
let mut other = std::process::Command::new("sleep")
|
|
732
|
+
.arg("30")
|
|
733
|
+
.spawn()
|
|
734
|
+
.unwrap();
|
|
735
|
+
let launched = launched_as_provider(claude.id(), Provider::Claude);
|
|
736
|
+
let _ = claude.kill();
|
|
737
|
+
let _ = claude.wait();
|
|
738
|
+
assert!(launched);
|
|
739
|
+
let launched = launched_as_provider(other.id(), Provider::Claude);
|
|
740
|
+
let _ = other.kill();
|
|
741
|
+
let _ = other.wait();
|
|
742
|
+
assert!(!launched);
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
#[test]
|
|
746
|
+
#[cfg(unix)]
|
|
747
|
+
fn supervised_carrier_child_launched_as_provider_is_identified() {
|
|
748
|
+
// Original restart supervises the provider as a child of a shell carrier.
|
|
749
|
+
use crate::model::enums::Provider;
|
|
750
|
+
use std::os::unix::process::CommandExt;
|
|
751
|
+
let mut carrier = std::process::Command::new("bash")
|
|
752
|
+
.args(["-c", "exec -a claude sleep 30 & wait"])
|
|
753
|
+
.process_group(0)
|
|
754
|
+
.spawn()
|
|
755
|
+
.unwrap();
|
|
756
|
+
let deadline = std::time::Instant::now() + std::time::Duration::from_secs(5);
|
|
757
|
+
let mut launched = false;
|
|
758
|
+
while !launched && std::time::Instant::now() < deadline {
|
|
759
|
+
launched = launched_as_provider(carrier.id(), Provider::Claude);
|
|
760
|
+
std::thread::sleep(std::time::Duration::from_millis(20));
|
|
761
|
+
}
|
|
762
|
+
unsafe { libc::kill(-(carrier.id() as i32), libc::SIGKILL) };
|
|
763
|
+
let _ = carrier.wait();
|
|
764
|
+
assert!(launched);
|
|
765
|
+
}
|
|
766
|
+
|
|
569
767
|
#[test]
|
|
570
768
|
fn unchanged_observation_port_rejects_native_screen_followed_by_exit_tail() {
|
|
571
769
|
use crate::model::enums::Provider;
|