@team-agent/installer 0.2.11 → 0.3.0
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 +744 -0
- package/Cargo.toml +34 -0
- package/crates/team-agent/Cargo.toml +33 -0
- package/crates/team-agent/src/cli/adapters.rs +1343 -0
- package/crates/team-agent/src/cli/diagnose.rs +554 -0
- package/crates/team-agent/src/cli/emit.rs +1077 -0
- package/crates/team-agent/src/cli/helpers.rs +88 -0
- package/crates/team-agent/src/cli/leader.rs +216 -0
- package/crates/team-agent/src/cli/mod.rs +1141 -0
- package/crates/team-agent/src/cli/profile.rs +306 -0
- package/crates/team-agent/src/cli/send.rs +215 -0
- package/crates/team-agent/src/cli/status.rs +179 -0
- package/crates/team-agent/src/cli/status_port.rs +502 -0
- package/crates/team-agent/src/cli/tests/base.rs +616 -0
- package/crates/team-agent/src/cli/tests/compile.rs +96 -0
- package/crates/team-agent/src/cli/tests/divergence.rs +509 -0
- package/crates/team-agent/src/cli/tests/lane_c.rs +333 -0
- package/crates/team-agent/src/cli/tests/leader_watch.rs +395 -0
- package/crates/team-agent/src/cli/tests/main_preserved.rs +675 -0
- package/crates/team-agent/src/cli/tests/missing_subcommands.rs +390 -0
- package/crates/team-agent/src/cli/tests/mod.rs +97 -0
- package/crates/team-agent/src/cli/tests/peer_allow.rs +137 -0
- package/crates/team-agent/src/cli/tests/repair_state_byte_lock.rs +302 -0
- package/crates/team-agent/src/cli/tests/run_delegation.rs +305 -0
- package/crates/team-agent/src/cli/tests/status_send.rs +385 -0
- package/crates/team-agent/src/cli/tests/verb_profile.rs +182 -0
- package/crates/team-agent/src/cli/tests/verb_settle.rs +236 -0
- package/crates/team-agent/src/cli/tests/verb_validate.rs +184 -0
- package/crates/team-agent/src/cli/types.rs +605 -0
- package/crates/team-agent/src/compiler/tests.rs +701 -0
- package/crates/team-agent/src/compiler.rs +489 -0
- package/crates/team-agent/src/coordinator/backoff.rs +153 -0
- package/crates/team-agent/src/coordinator/health.rs +436 -0
- package/crates/team-agent/src/coordinator/mod.rs +80 -0
- package/crates/team-agent/src/coordinator/orphan.rs +179 -0
- package/crates/team-agent/src/coordinator/tests/abnormal.rs +255 -0
- package/crates/team-agent/src/coordinator/tests/basics.rs +262 -0
- package/crates/team-agent/src/coordinator/tests/daemon.rs +323 -0
- package/crates/team-agent/src/coordinator/tests/health_sync.rs +263 -0
- package/crates/team-agent/src/coordinator/tests/main_preserved.rs +136 -0
- package/crates/team-agent/src/coordinator/tests/mod.rs +310 -0
- package/crates/team-agent/src/coordinator/tests/spine.rs +261 -0
- package/crates/team-agent/src/coordinator/tests/takeover.rs +227 -0
- package/crates/team-agent/src/coordinator/tests/tick_core.rs +256 -0
- package/crates/team-agent/src/coordinator/tests/watch.rs +167 -0
- package/crates/team-agent/src/coordinator/tick.rs +2032 -0
- package/crates/team-agent/src/coordinator/types.rs +584 -0
- package/crates/team-agent/src/db/migration.rs +716 -0
- package/crates/team-agent/src/db/mod.rs +23 -0
- package/crates/team-agent/src/db/schema.rs +378 -0
- package/crates/team-agent/src/event_log.rs +375 -0
- package/crates/team-agent/src/fake_worker.rs +253 -0
- package/crates/team-agent/src/leader/helpers.rs +190 -0
- package/crates/team-agent/src/leader/inject.rs +33 -0
- package/crates/team-agent/src/leader/lease.rs +1063 -0
- package/crates/team-agent/src/leader/mod.rs +99 -0
- package/crates/team-agent/src/leader/owner_bind.rs +292 -0
- package/crates/team-agent/src/leader/rediscover/tests.rs +525 -0
- package/crates/team-agent/src/leader/rediscover.rs +1099 -0
- package/crates/team-agent/src/leader/start.rs +273 -0
- package/crates/team-agent/src/leader/takeover.rs +235 -0
- package/crates/team-agent/src/leader/tests/basics.rs +183 -0
- package/crates/team-agent/src/leader/tests/byte_findings.rs +234 -0
- package/crates/team-agent/src/leader/tests/identity.rs +206 -0
- package/crates/team-agent/src/leader/tests/idle.rs +271 -0
- package/crates/team-agent/src/leader/tests/lease_api.rs +225 -0
- package/crates/team-agent/src/leader/tests/lease_claim.rs +253 -0
- package/crates/team-agent/src/leader/tests/mod.rs +125 -0
- package/crates/team-agent/src/leader/tests/rediscover.rs +351 -0
- package/crates/team-agent/src/leader/tests/wake_start_owner.rs +204 -0
- package/crates/team-agent/src/leader/types.rs +487 -0
- package/crates/team-agent/src/lib.rs +85 -0
- package/crates/team-agent/src/lifecycle/display.rs +228 -0
- package/crates/team-agent/src/lifecycle/helpers.rs +112 -0
- package/crates/team-agent/src/lifecycle/launch/plan.rs +227 -0
- package/crates/team-agent/src/lifecycle/launch.rs +1833 -0
- package/crates/team-agent/src/lifecycle/mod.rs +62 -0
- package/crates/team-agent/src/lifecycle/restart/agent.rs +533 -0
- package/crates/team-agent/src/lifecycle/restart/common.rs +517 -0
- package/crates/team-agent/src/lifecycle/restart/orchestrator.rs +41 -0
- package/crates/team-agent/src/lifecycle/restart/rebuild.rs +268 -0
- package/crates/team-agent/src/lifecycle/restart/remove.rs +780 -0
- package/crates/team-agent/src/lifecycle/restart/selection.rs +208 -0
- package/crates/team-agent/src/lifecycle/restart/team_state.rs +242 -0
- package/crates/team-agent/src/lifecycle/restart.rs +76 -0
- package/crates/team-agent/src/lifecycle/tests/agent_ops.rs +455 -0
- package/crates/team-agent/src/lifecycle/tests/core.rs +989 -0
- package/crates/team-agent/src/lifecycle/tests/lane_ops.rs +583 -0
- package/crates/team-agent/src/lifecycle/tests/launch_spawn.rs +933 -0
- package/crates/team-agent/src/lifecycle/tests/main_preserved.rs +265 -0
- package/crates/team-agent/src/lifecycle/tests.rs +27 -0
- package/crates/team-agent/src/lifecycle/types.rs +685 -0
- package/crates/team-agent/src/main.rs +41 -0
- package/crates/team-agent/src/mcp_server/helpers.rs +228 -0
- package/crates/team-agent/src/mcp_server/mod.rs +183 -0
- package/crates/team-agent/src/mcp_server/normalize.rs +312 -0
- package/crates/team-agent/src/mcp_server/tests/golden.rs +283 -0
- package/crates/team-agent/src/mcp_server/tests/normalize.rs +244 -0
- package/crates/team-agent/src/mcp_server/tests/scoped.rs +189 -0
- package/crates/team-agent/src/mcp_server/tests/send.rs +222 -0
- package/crates/team-agent/src/mcp_server/tests/tools.rs +158 -0
- package/crates/team-agent/src/mcp_server/tests/wire.rs +159 -0
- package/crates/team-agent/src/mcp_server/tests.rs +38 -0
- package/crates/team-agent/src/mcp_server/tools.rs +603 -0
- package/crates/team-agent/src/mcp_server/types.rs +421 -0
- package/crates/team-agent/src/mcp_server/wire.rs +388 -0
- package/crates/team-agent/src/message_store.rs +767 -0
- package/crates/team-agent/src/messaging/activity.rs +433 -0
- package/crates/team-agent/src/messaging/delivery.rs +542 -0
- package/crates/team-agent/src/messaging/helpers.rs +209 -0
- package/crates/team-agent/src/messaging/leader_receiver.rs +340 -0
- package/crates/team-agent/src/messaging/mod.rs +147 -0
- package/crates/team-agent/src/messaging/peers.rs +32 -0
- package/crates/team-agent/src/messaging/results.rs +537 -0
- package/crates/team-agent/src/messaging/scheduler.rs +344 -0
- package/crates/team-agent/src/messaging/selftest.rs +100 -0
- package/crates/team-agent/src/messaging/send.rs +582 -0
- package/crates/team-agent/src/messaging/tests/basic.rs +357 -0
- package/crates/team-agent/src/messaging/tests/main_preserved.rs +122 -0
- package/crates/team-agent/src/messaging/tests/mod.rs +293 -0
- package/crates/team-agent/src/messaging/tests/runtime.rs +1422 -0
- package/crates/team-agent/src/messaging/tests/spine.rs +437 -0
- package/crates/team-agent/src/messaging/trust.rs +192 -0
- package/crates/team-agent/src/messaging/types.rs +355 -0
- package/crates/team-agent/src/messaging/watchers.rs +591 -0
- package/crates/team-agent/src/model/enums.rs +311 -0
- package/crates/team-agent/src/model/errors.rs +17 -0
- package/crates/team-agent/src/model/ids.rs +155 -0
- package/crates/team-agent/src/model/mod.rs +22 -0
- package/crates/team-agent/src/model/paths.rs +228 -0
- package/crates/team-agent/src/model/permissions.rs +567 -0
- package/crates/team-agent/src/model/routing.rs +340 -0
- package/crates/team-agent/src/model/spec.rs +680 -0
- package/crates/team-agent/src/model/task_graph.rs +380 -0
- package/crates/team-agent/src/model/testdata/fuzz.golden.yaml +43 -0
- package/crates/team-agent/src/model/testdata/fuzz.yaml +43 -0
- package/crates/team-agent/src/model/testdata/spec_invalid_a.yaml +207 -0
- package/crates/team-agent/src/model/testdata/team.spec.golden.yaml +206 -0
- package/crates/team-agent/src/model/testdata/team.spec.yaml +206 -0
- package/crates/team-agent/src/model/yaml/tests.rs +288 -0
- package/crates/team-agent/src/model/yaml.rs +800 -0
- package/crates/team-agent/src/packaging/install.rs +305 -0
- package/crates/team-agent/src/packaging/migrate.rs +30 -0
- package/crates/team-agent/src/packaging/mod.rs +82 -0
- package/crates/team-agent/src/packaging/repair.rs +24 -0
- package/crates/team-agent/src/packaging/tests.rs +829 -0
- package/crates/team-agent/src/packaging/types.rs +369 -0
- package/crates/team-agent/src/provider/adapter.rs +801 -0
- package/crates/team-agent/src/provider/approvals/mod.rs +2 -0
- package/crates/team-agent/src/provider/approvals/parsing.rs +452 -0
- package/crates/team-agent/src/provider/approvals/runtime_prompts.rs +163 -0
- package/crates/team-agent/src/provider/classify.rs +456 -0
- package/crates/team-agent/src/provider/faults.rs +136 -0
- package/crates/team-agent/src/provider/helpers.rs +41 -0
- package/crates/team-agent/src/provider/mod.rs +53 -0
- package/crates/team-agent/src/provider/startup_prompt.rs +423 -0
- package/crates/team-agent/src/provider/tests/adapter.rs +239 -0
- package/crates/team-agent/src/provider/tests/classify.rs +240 -0
- package/crates/team-agent/src/provider/tests/faults.rs +120 -0
- package/crates/team-agent/src/provider/tests/idle.rs +208 -0
- package/crates/team-agent/src/provider/tests/wire.rs +213 -0
- package/crates/team-agent/src/provider/tests.rs +31 -0
- package/crates/team-agent/src/provider/types.rs +424 -0
- package/crates/team-agent/src/state/identity.rs +656 -0
- package/crates/team-agent/src/state/mod.rs +58 -0
- package/crates/team-agent/src/state/owner_gate.rs +423 -0
- package/crates/team-agent/src/state/persist.rs +712 -0
- package/crates/team-agent/src/state/projection.rs +657 -0
- package/crates/team-agent/src/state/selector.rs +105 -0
- package/crates/team-agent/src/state/testdata/state-rich.canonical.json +133 -0
- package/crates/team-agent/src/tmux_backend/tests.rs +586 -0
- package/crates/team-agent/src/tmux_backend.rs +758 -0
- package/crates/team-agent/src/transport/test_support.rs +252 -0
- package/crates/team-agent/src/transport/tests/behavior.rs +327 -0
- package/crates/team-agent/src/transport/tests/mod.rs +199 -0
- package/crates/team-agent/src/transport/tests/wire.rs +527 -0
- package/crates/team-agent/src/transport.rs +774 -0
- package/npm/install.mjs +90 -106
- package/package.json +15 -13
- package/crates/team-agent-core/Cargo.toml +0 -12
- package/crates/team-agent-core/src/lib.rs +0 -332
- package/crates/team-agent-core/src/main.rs +0 -152
- package/pyproject.toml +0 -18
- package/scripts/install.py +0 -88
- package/scripts/run_regression_tests.py +0 -83
- package/src/team_agent/__init__.py +0 -3
- package/src/team_agent/__main__.py +0 -5
- package/src/team_agent/_legacy_pane_discovery.py +0 -186
- package/src/team_agent/abnormal_track.py +0 -253
- package/src/team_agent/approvals/__init__.py +0 -65
- package/src/team_agent/approvals/constants.py +0 -6
- package/src/team_agent/approvals/parsing.py +0 -176
- package/src/team_agent/approvals/runtime_prompts.py +0 -171
- package/src/team_agent/approvals/status.py +0 -176
- package/src/team_agent/cli/__init__.py +0 -137
- package/src/team_agent/cli/commands.py +0 -481
- package/src/team_agent/cli/e2e.py +0 -202
- package/src/team_agent/cli/helpers.py +0 -226
- package/src/team_agent/cli/parser.py +0 -540
- package/src/team_agent/compiler.py +0 -334
- package/src/team_agent/coordinator/__init__.py +0 -53
- package/src/team_agent/coordinator/__main__.py +0 -119
- package/src/team_agent/coordinator/lifecycle.py +0 -411
- package/src/team_agent/coordinator/metadata.py +0 -61
- package/src/team_agent/coordinator/paths.py +0 -17
- package/src/team_agent/diagnose/__init__.py +0 -48
- package/src/team_agent/diagnose/checks.py +0 -101
- package/src/team_agent/diagnose/comms.py +0 -213
- package/src/team_agent/diagnose/health.py +0 -241
- package/src/team_agent/diagnose/orphan_cleanup.py +0 -364
- package/src/team_agent/diagnose/preflight.py +0 -194
- package/src/team_agent/diagnose/quick_start.py +0 -324
- package/src/team_agent/display/__init__.py +0 -92
- package/src/team_agent/display/adaptive.py +0 -511
- package/src/team_agent/display/backend.py +0 -46
- package/src/team_agent/display/close.py +0 -154
- package/src/team_agent/display/ghostty.py +0 -77
- package/src/team_agent/display/rebuild.py +0 -102
- package/src/team_agent/display/tiling.py +0 -156
- package/src/team_agent/display/worker_window.py +0 -114
- package/src/team_agent/display/workspace.py +0 -382
- package/src/team_agent/errors.py +0 -10
- package/src/team_agent/events.py +0 -84
- package/src/team_agent/fake_worker.py +0 -80
- package/src/team_agent/idle_predicate.py +0 -218
- package/src/team_agent/idle_takeover.py +0 -59
- package/src/team_agent/idle_takeover_wiring.py +0 -114
- package/src/team_agent/launch/__init__.py +0 -41
- package/src/team_agent/launch/bootstrap.py +0 -85
- package/src/team_agent/launch/config.py +0 -106
- package/src/team_agent/launch/core.py +0 -301
- package/src/team_agent/launch/requirements.py +0 -57
- package/src/team_agent/leader/__init__.py +0 -926
- package/src/team_agent/leader_binding.py +0 -183
- package/src/team_agent/lifecycle/__init__.py +0 -5
- package/src/team_agent/lifecycle/agents.py +0 -278
- package/src/team_agent/lifecycle/operations.py +0 -411
- package/src/team_agent/lifecycle/paste_buffer_hygiene.py +0 -39
- package/src/team_agent/lifecycle/start.py +0 -363
- package/src/team_agent/mcp_server/__init__.py +0 -42
- package/src/team_agent/mcp_server/__main__.py +0 -7
- package/src/team_agent/mcp_server/contracts.py +0 -148
- package/src/team_agent/mcp_server/normalize.py +0 -257
- package/src/team_agent/mcp_server/server.py +0 -150
- package/src/team_agent/mcp_server/tools.py +0 -352
- package/src/team_agent/message_store/__init__.py +0 -23
- package/src/team_agent/message_store/agent_health.py +0 -113
- package/src/team_agent/message_store/core.py +0 -497
- package/src/team_agent/message_store/leader_notification_log.py +0 -198
- package/src/team_agent/message_store/result_watchers.py +0 -251
- package/src/team_agent/message_store/schema.py +0 -308
- package/src/team_agent/message_store/schema_migration.py +0 -448
- package/src/team_agent/messaging/__init__.py +0 -1
- package/src/team_agent/messaging/activity_detector.py +0 -262
- package/src/team_agent/messaging/delivery.py +0 -504
- package/src/team_agent/messaging/deps.py +0 -247
- package/src/team_agent/messaging/idle_alerts.py +0 -423
- package/src/team_agent/messaging/internal_delivery.py +0 -46
- package/src/team_agent/messaging/leader.py +0 -497
- package/src/team_agent/messaging/leader_api_errors.py +0 -216
- package/src/team_agent/messaging/leader_panes.py +0 -673
- package/src/team_agent/messaging/owner_bypass.py +0 -29
- package/src/team_agent/messaging/result_delivery.py +0 -539
- package/src/team_agent/messaging/results.py +0 -447
- package/src/team_agent/messaging/scheduler.py +0 -450
- package/src/team_agent/messaging/send.py +0 -532
- package/src/team_agent/messaging/session_drift.py +0 -94
- package/src/team_agent/messaging/tmux_io.py +0 -506
- package/src/team_agent/messaging/tmux_prompt.py +0 -338
- package/src/team_agent/messaging/trust_auto_answer.py +0 -52
- package/src/team_agent/orchestrator/__init__.py +0 -376
- package/src/team_agent/orchestrator/plan.py +0 -122
- package/src/team_agent/orchestrator/state.py +0 -128
- package/src/team_agent/paths.py +0 -45
- package/src/team_agent/permissions.py +0 -123
- package/src/team_agent/profiles/__init__.py +0 -82
- package/src/team_agent/profiles/constants.py +0 -19
- package/src/team_agent/profiles/core.py +0 -407
- package/src/team_agent/profiles/helpers.py +0 -69
- package/src/team_agent/profiles/provider_env.py +0 -188
- package/src/team_agent/profiles/smoke.py +0 -201
- package/src/team_agent/provider_cli/__init__.py +0 -43
- package/src/team_agent/provider_cli/adapter.py +0 -172
- package/src/team_agent/provider_cli/base.py +0 -48
- package/src/team_agent/provider_cli/claude.py +0 -503
- package/src/team_agent/provider_cli/codex.py +0 -336
- package/src/team_agent/provider_cli/copilot.py +0 -8
- package/src/team_agent/provider_cli/fake.py +0 -39
- package/src/team_agent/provider_cli/gemini.py +0 -95
- package/src/team_agent/provider_cli/opencode.py +0 -8
- package/src/team_agent/provider_cli/prompt.py +0 -62
- package/src/team_agent/provider_cli/registry.py +0 -18
- package/src/team_agent/provider_cli/unsupported.py +0 -32
- package/src/team_agent/provider_state/README.md +0 -78
- package/src/team_agent/provider_state/__init__.py +0 -91
- package/src/team_agent/provider_state/claude.py +0 -86
- package/src/team_agent/provider_state/codex.py +0 -84
- package/src/team_agent/provider_state/common.py +0 -207
- package/src/team_agent/provider_state/registry.py +0 -118
- package/src/team_agent/providers.py +0 -163
- package/src/team_agent/quality_gates.py +0 -104
- package/src/team_agent/restart/__init__.py +0 -34
- package/src/team_agent/restart/orchestration.py +0 -554
- package/src/team_agent/restart/selection.py +0 -89
- package/src/team_agent/restart/snapshot.py +0 -70
- package/src/team_agent/routing.py +0 -84
- package/src/team_agent/runtime.py +0 -1243
- package/src/team_agent/rust_core.py +0 -327
- package/src/team_agent/sessions/__init__.py +0 -25
- package/src/team_agent/sessions/capture.py +0 -144
- package/src/team_agent/sessions/inventory.py +0 -44
- package/src/team_agent/sessions/resume.py +0 -135
- package/src/team_agent/simple_yaml.py +0 -236
- package/src/team_agent/spec.py +0 -370
- package/src/team_agent/state.py +0 -693
- package/src/team_agent/status/__init__.py +0 -63
- package/src/team_agent/status/approvals.py +0 -52
- package/src/team_agent/status/compact.py +0 -158
- package/src/team_agent/status/constants.py +0 -18
- package/src/team_agent/status/inbox.py +0 -58
- package/src/team_agent/status/peek.py +0 -117
- package/src/team_agent/status/queries.py +0 -199
- package/src/team_agent/task_graph.py +0 -80
- package/src/team_agent/terminal.py +0 -57
- package/src/team_agent/wake.py +0 -58
- package/src/team_agent/watch/__init__.py +0 -145
|
@@ -0,0 +1,517 @@
|
|
|
1
|
+
use super::*;
|
|
2
|
+
|
|
3
|
+
pub(super) fn spawn_agent_window(
|
|
4
|
+
workspace: &Path,
|
|
5
|
+
session_name: &SessionName,
|
|
6
|
+
agent_id: &AgentId,
|
|
7
|
+
agent: &serde_json::Value,
|
|
8
|
+
resume_session_id: Option<&SessionId>,
|
|
9
|
+
into_existing_session: bool,
|
|
10
|
+
transport: &dyn crate::transport::Transport,
|
|
11
|
+
safety: Option<&DangerousApproval>,
|
|
12
|
+
) -> Result<crate::transport::SpawnResult, LifecycleError> {
|
|
13
|
+
let provider = agent_provider(agent);
|
|
14
|
+
let auth_mode = agent_auth_mode(agent);
|
|
15
|
+
let model = agent.get("model").and_then(|v| v.as_str());
|
|
16
|
+
let adapter = crate::provider::get_adapter(provider);
|
|
17
|
+
let resume_session_id = if adapter.caps().resume {
|
|
18
|
+
resume_session_id
|
|
19
|
+
} else {
|
|
20
|
+
None
|
|
21
|
+
};
|
|
22
|
+
// Contract C / F6.4: thread compiled role/tools/MCP context through restart as well —
|
|
23
|
+
// a restarted worker must come back up with the SAME callable MCP capability + role
|
|
24
|
+
// prompt as a fresh launch, else `report_result` becomes unreachable after every restart.
|
|
25
|
+
let role = agent.get("role").and_then(|v| v.as_str());
|
|
26
|
+
let detected_safety;
|
|
27
|
+
let safety = if let Some(safety) = safety {
|
|
28
|
+
safety
|
|
29
|
+
} else {
|
|
30
|
+
detected_safety = crate::lifecycle::launch::effective_runtime_config_for_worker_spawn()?;
|
|
31
|
+
&detected_safety
|
|
32
|
+
};
|
|
33
|
+
let tools = crate::lifecycle::launch::worker_tool_refs(agent_tool_strings(agent), safety);
|
|
34
|
+
let tool_refs: Vec<&str> = tools.iter().map(String::as_str).collect();
|
|
35
|
+
let mcp_config = adapter
|
|
36
|
+
.mcp_config(auth_mode)
|
|
37
|
+
.map_err(|e| LifecycleError::Provider(e.to_string()))?;
|
|
38
|
+
let mut argv = match resume_session_id {
|
|
39
|
+
Some(session_id) => adapter
|
|
40
|
+
.build_resume_command_with_context(
|
|
41
|
+
Some(session_id),
|
|
42
|
+
auth_mode,
|
|
43
|
+
Some(&mcp_config),
|
|
44
|
+
role,
|
|
45
|
+
model,
|
|
46
|
+
&tool_refs,
|
|
47
|
+
)
|
|
48
|
+
.map_err(|e| LifecycleError::Provider(e.to_string()))?,
|
|
49
|
+
None => adapter
|
|
50
|
+
.build_command_with_tools(auth_mode, Some(&mcp_config), role, model, &tool_refs)
|
|
51
|
+
.map_err(|e| LifecycleError::Provider(e.to_string()))?,
|
|
52
|
+
};
|
|
53
|
+
// owner_team_id resolution: prefer the runtime-state row's `owner_team_id` (set by
|
|
54
|
+
// launch/restart); fall back to the active team key for paths that don't write the
|
|
55
|
+
// row first (e.g. add-agent calls spawn before upserting team metadata).
|
|
56
|
+
let state_for_team =
|
|
57
|
+
crate::state::persist::load_runtime_state(workspace).unwrap_or(serde_json::json!({}));
|
|
58
|
+
let team_id = agent
|
|
59
|
+
.get("owner_team_id")
|
|
60
|
+
.and_then(|v| v.as_str())
|
|
61
|
+
.map(str::to_string)
|
|
62
|
+
.or_else(|| {
|
|
63
|
+
let key = crate::messaging::leader_receiver::active_team_key(workspace, &state_for_team);
|
|
64
|
+
(!key.is_empty()).then_some(key)
|
|
65
|
+
});
|
|
66
|
+
crate::lifecycle::launch::fill_spawn_placeholders_full(
|
|
67
|
+
&mut argv,
|
|
68
|
+
workspace,
|
|
69
|
+
agent_id.as_str(),
|
|
70
|
+
team_id.as_deref(),
|
|
71
|
+
);
|
|
72
|
+
let window = WindowName::new(agent_id.as_str());
|
|
73
|
+
let env = crate::lifecycle::launch::inherited_env_with_team_overrides(
|
|
74
|
+
workspace,
|
|
75
|
+
agent_id.as_str(),
|
|
76
|
+
team_id.as_deref(),
|
|
77
|
+
);
|
|
78
|
+
let result = if into_existing_session {
|
|
79
|
+
transport.spawn_into(session_name, &window, &argv, workspace, &env)
|
|
80
|
+
} else {
|
|
81
|
+
transport.spawn_first(session_name, &window, &argv, workspace, &env)
|
|
82
|
+
};
|
|
83
|
+
let spawn = result.map_err(|e| LifecycleError::Transport(e.to_string()))?;
|
|
84
|
+
let _ = adapter.handle_startup_prompts(
|
|
85
|
+
transport,
|
|
86
|
+
&crate::transport::Target::Pane(spawn.pane_id.clone()),
|
|
87
|
+
30,
|
|
88
|
+
0.5,
|
|
89
|
+
);
|
|
90
|
+
Ok(spawn)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
pub(super) fn start_coordinator_for_workspace(workspace: &Path) -> Result<bool, LifecycleError> {
|
|
94
|
+
let workspace = crate::coordinator::WorkspacePath::new(workspace.to_path_buf());
|
|
95
|
+
crate::coordinator::start_coordinator(&workspace)
|
|
96
|
+
.map(|report| report.ok)
|
|
97
|
+
.map_err(|e| LifecycleError::StatePersist(e.to_string()))
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
pub(super) fn state_session_name(state: &serde_json::Value) -> SessionName {
|
|
101
|
+
state
|
|
102
|
+
.get("session_name")
|
|
103
|
+
.and_then(|v| v.as_str())
|
|
104
|
+
.filter(|s| !s.is_empty())
|
|
105
|
+
.map(SessionName::new)
|
|
106
|
+
.unwrap_or_else(|| SessionName::new("team-agent"))
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
pub(super) fn session_name_present(state: &serde_json::Value) -> bool {
|
|
110
|
+
state
|
|
111
|
+
.get("session_name")
|
|
112
|
+
.and_then(|v| v.as_str())
|
|
113
|
+
.map(|s| !s.is_empty())
|
|
114
|
+
.unwrap_or(false)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
pub(super) fn session_live_or_default(
|
|
118
|
+
transport: &dyn crate::transport::Transport,
|
|
119
|
+
session_name: &SessionName,
|
|
120
|
+
default: bool,
|
|
121
|
+
) -> bool {
|
|
122
|
+
match std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
|
|
123
|
+
transport.has_session(session_name)
|
|
124
|
+
})) {
|
|
125
|
+
Ok(Ok(live)) => live,
|
|
126
|
+
Ok(Err(_)) => false,
|
|
127
|
+
Err(_) => default,
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
pub(super) fn agent_provider(agent: &serde_json::Value) -> Provider {
|
|
132
|
+
agent
|
|
133
|
+
.get("provider")
|
|
134
|
+
.and_then(|v| v.as_str())
|
|
135
|
+
.and_then(parse_provider)
|
|
136
|
+
.unwrap_or(Provider::Codex)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
pub(super) fn agent_auth_mode(agent: &serde_json::Value) -> AuthMode {
|
|
140
|
+
agent
|
|
141
|
+
.get("auth_mode")
|
|
142
|
+
.and_then(|v| v.as_str())
|
|
143
|
+
.and_then(parse_auth_mode)
|
|
144
|
+
.unwrap_or(AuthMode::Subscription)
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
pub(super) fn agent_session_id(agent: &serde_json::Value) -> Option<SessionId> {
|
|
148
|
+
agent
|
|
149
|
+
.get("session_id")
|
|
150
|
+
.and_then(|v| v.as_str())
|
|
151
|
+
.filter(|s| !s.is_empty())
|
|
152
|
+
.map(SessionId::new)
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
pub(super) fn agent_rollout_path(agent: &serde_json::Value) -> Option<RolloutPath> {
|
|
156
|
+
agent
|
|
157
|
+
.get("rollout_path")
|
|
158
|
+
.and_then(|v| v.as_str())
|
|
159
|
+
.filter(|s| !s.is_empty())
|
|
160
|
+
.map(RolloutPath::new)
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/// Tools list off an agent's runtime state entry (`tools: [...]`). Restart paths
|
|
164
|
+
/// don't have the full spec object, only the runtime state — so they read tools from
|
|
165
|
+
/// the state row, falling back to an empty list. Contract C requires the worker
|
|
166
|
+
/// command be built with the tool list, even on restart.
|
|
167
|
+
pub(super) fn agent_tool_strings(agent: &serde_json::Value) -> Vec<String> {
|
|
168
|
+
agent
|
|
169
|
+
.get("tools")
|
|
170
|
+
.and_then(|v| v.as_array())
|
|
171
|
+
.map(|items| {
|
|
172
|
+
items
|
|
173
|
+
.iter()
|
|
174
|
+
.filter_map(|v| v.as_str())
|
|
175
|
+
.map(str::to_string)
|
|
176
|
+
.collect()
|
|
177
|
+
})
|
|
178
|
+
.unwrap_or_default()
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
pub(super) fn agent_window(agent: &serde_json::Value, agent_id: &AgentId) -> String {
|
|
182
|
+
agent
|
|
183
|
+
.get("window")
|
|
184
|
+
.and_then(|v| v.as_str())
|
|
185
|
+
.filter(|s| !s.is_empty())
|
|
186
|
+
.unwrap_or_else(|| agent_id.as_str())
|
|
187
|
+
.to_string()
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
pub(super) fn parse_provider(raw: &str) -> Option<Provider> {
|
|
191
|
+
match raw {
|
|
192
|
+
"claude" => Some(Provider::Claude),
|
|
193
|
+
"claude_code" => Some(Provider::ClaudeCode),
|
|
194
|
+
"codex" => Some(Provider::Codex),
|
|
195
|
+
"gemini_cli" => Some(Provider::GeminiCli),
|
|
196
|
+
"fake" => Some(Provider::Fake),
|
|
197
|
+
_ => None,
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
pub(super) fn provider_wire(provider: Provider) -> &'static str {
|
|
202
|
+
match provider {
|
|
203
|
+
Provider::Claude => "claude",
|
|
204
|
+
Provider::ClaudeCode => "claude_code",
|
|
205
|
+
Provider::Codex => "codex",
|
|
206
|
+
Provider::GeminiCli => "gemini_cli",
|
|
207
|
+
Provider::Fake => "fake",
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
pub(super) fn parse_auth_mode(raw: &str) -> Option<AuthMode> {
|
|
212
|
+
match raw {
|
|
213
|
+
"subscription" => Some(AuthMode::Subscription),
|
|
214
|
+
"official_api" => Some(AuthMode::OfficialApi),
|
|
215
|
+
"compatible_api" => Some(AuthMode::CompatibleApi),
|
|
216
|
+
_ => None,
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
pub(super) fn load_team_spec(workspace: &Path) -> Result<YamlValue, LifecycleError> {
|
|
221
|
+
let spec_path = workspace.join("team.spec.yaml");
|
|
222
|
+
if !spec_path.exists() {
|
|
223
|
+
return Err(LifecycleError::TeamSelect(format!(
|
|
224
|
+
"missing spec: {}",
|
|
225
|
+
spec_path.display()
|
|
226
|
+
)));
|
|
227
|
+
}
|
|
228
|
+
let text = std::fs::read_to_string(&spec_path)
|
|
229
|
+
.map_err(|e| LifecycleError::Compile(format!("{}: {e}", spec_path.display())))?;
|
|
230
|
+
yaml::loads(&text).map_err(|e| LifecycleError::Compile(e.to_string()))
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
pub(super) fn find_spec_agent<'a>(spec: &'a YamlValue, agent_id: &AgentId) -> Option<&'a YamlValue> {
|
|
234
|
+
let leader_is_agent = spec
|
|
235
|
+
.get("leader")
|
|
236
|
+
.and_then(|v| v.get("id"))
|
|
237
|
+
.and_then(YamlValue::as_str)
|
|
238
|
+
.map(|id| id == agent_id.as_str())
|
|
239
|
+
.unwrap_or(false);
|
|
240
|
+
if leader_is_agent {
|
|
241
|
+
return None;
|
|
242
|
+
}
|
|
243
|
+
spec.get("agents")?
|
|
244
|
+
.as_list()?
|
|
245
|
+
.iter()
|
|
246
|
+
.find(|agent| {
|
|
247
|
+
agent
|
|
248
|
+
.get("id")
|
|
249
|
+
.and_then(YamlValue::as_str)
|
|
250
|
+
.map(|id| id == agent_id.as_str())
|
|
251
|
+
.unwrap_or(false)
|
|
252
|
+
})
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
pub(super) fn unknown_worker(agent_id: &AgentId) -> LifecycleError {
|
|
256
|
+
LifecycleError::RequirementUnmet(format!("unknown worker agent id: {agent_id}"))
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
pub(super) fn state_session_name_from_spec(state: &serde_json::Value, spec: &YamlValue) -> SessionName {
|
|
260
|
+
state
|
|
261
|
+
.get("session_name")
|
|
262
|
+
.and_then(|v| v.as_str())
|
|
263
|
+
.filter(|s| !s.is_empty())
|
|
264
|
+
.map(SessionName::new)
|
|
265
|
+
.or_else(|| {
|
|
266
|
+
spec.get("runtime")
|
|
267
|
+
.and_then(|v| v.get("session_name"))
|
|
268
|
+
.and_then(YamlValue::as_str)
|
|
269
|
+
.map(SessionName::new)
|
|
270
|
+
})
|
|
271
|
+
.or_else(|| {
|
|
272
|
+
spec.get("team")
|
|
273
|
+
.and_then(|v| v.get("name"))
|
|
274
|
+
.and_then(YamlValue::as_str)
|
|
275
|
+
.map(|name| SessionName::new(format!("team-{name}")))
|
|
276
|
+
})
|
|
277
|
+
.unwrap_or_else(|| SessionName::new("team-agent"))
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
pub(super) fn mark_agent_stopped(
|
|
281
|
+
state: &mut serde_json::Value,
|
|
282
|
+
agent_id: &AgentId,
|
|
283
|
+
spec_agent: &YamlValue,
|
|
284
|
+
window: &str,
|
|
285
|
+
) -> Result<(), LifecycleError> {
|
|
286
|
+
if !state.is_object() {
|
|
287
|
+
*state = serde_json::json!({});
|
|
288
|
+
}
|
|
289
|
+
let Some(root) = state.as_object_mut() else {
|
|
290
|
+
return Err(LifecycleError::StatePersist(
|
|
291
|
+
"runtime state root is not an object".to_string(),
|
|
292
|
+
));
|
|
293
|
+
};
|
|
294
|
+
let agents = root
|
|
295
|
+
.entry("agents".to_string())
|
|
296
|
+
.or_insert_with(|| serde_json::json!({}));
|
|
297
|
+
if !agents.is_object() {
|
|
298
|
+
*agents = serde_json::json!({});
|
|
299
|
+
}
|
|
300
|
+
let Some(agent_map) = agents.as_object_mut() else {
|
|
301
|
+
return Err(LifecycleError::StatePersist(
|
|
302
|
+
"runtime state agents is not an object".to_string(),
|
|
303
|
+
));
|
|
304
|
+
};
|
|
305
|
+
let provider = spec_agent
|
|
306
|
+
.get("provider")
|
|
307
|
+
.and_then(YamlValue::as_str)
|
|
308
|
+
.unwrap_or("codex");
|
|
309
|
+
let entry = agent_map
|
|
310
|
+
.entry(agent_id.as_str().to_string())
|
|
311
|
+
.or_insert_with(|| serde_json::json!({}));
|
|
312
|
+
if !entry.is_object() {
|
|
313
|
+
*entry = serde_json::json!({});
|
|
314
|
+
}
|
|
315
|
+
let Some(obj) = entry.as_object_mut() else {
|
|
316
|
+
return Err(LifecycleError::StatePersist(
|
|
317
|
+
"agent state is not an object".to_string(),
|
|
318
|
+
));
|
|
319
|
+
};
|
|
320
|
+
obj.insert("status".to_string(), serde_json::json!("stopped"));
|
|
321
|
+
obj.insert("provider".to_string(), serde_json::json!(provider));
|
|
322
|
+
obj.insert("agent_id".to_string(), serde_json::json!(agent_id.as_str()));
|
|
323
|
+
obj.insert("last_window".to_string(), serde_json::json!(window));
|
|
324
|
+
obj.remove("window");
|
|
325
|
+
obj.remove("pane_id");
|
|
326
|
+
Ok(())
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
pub(super) fn mark_agent_running_noop(
|
|
330
|
+
state: &mut serde_json::Value,
|
|
331
|
+
agent_id: &AgentId,
|
|
332
|
+
session_name: &SessionName,
|
|
333
|
+
window: &str,
|
|
334
|
+
) -> Result<(), LifecycleError> {
|
|
335
|
+
if !state.is_object() {
|
|
336
|
+
*state = serde_json::json!({});
|
|
337
|
+
}
|
|
338
|
+
let Some(root) = state.as_object_mut() else {
|
|
339
|
+
return Err(LifecycleError::StatePersist(
|
|
340
|
+
"runtime state root is not an object".to_string(),
|
|
341
|
+
));
|
|
342
|
+
};
|
|
343
|
+
root.insert(
|
|
344
|
+
"session_name".to_string(),
|
|
345
|
+
serde_json::json!(session_name.as_str()),
|
|
346
|
+
);
|
|
347
|
+
let agents = root
|
|
348
|
+
.entry("agents".to_string())
|
|
349
|
+
.or_insert_with(|| serde_json::json!({}));
|
|
350
|
+
if !agents.is_object() {
|
|
351
|
+
*agents = serde_json::json!({});
|
|
352
|
+
}
|
|
353
|
+
let Some(agent_map) = agents.as_object_mut() else {
|
|
354
|
+
return Err(LifecycleError::StatePersist(
|
|
355
|
+
"runtime state agents is not an object".to_string(),
|
|
356
|
+
));
|
|
357
|
+
};
|
|
358
|
+
let entry = agent_map
|
|
359
|
+
.entry(agent_id.as_str().to_string())
|
|
360
|
+
.or_insert_with(|| serde_json::json!({}));
|
|
361
|
+
if !entry.is_object() {
|
|
362
|
+
*entry = serde_json::json!({});
|
|
363
|
+
}
|
|
364
|
+
let Some(obj) = entry.as_object_mut() else {
|
|
365
|
+
return Err(LifecycleError::StatePersist(
|
|
366
|
+
"agent state is not an object".to_string(),
|
|
367
|
+
));
|
|
368
|
+
};
|
|
369
|
+
obj.insert("status".to_string(), serde_json::json!("running"));
|
|
370
|
+
obj.insert("agent_id".to_string(), serde_json::json!(agent_id.as_str()));
|
|
371
|
+
obj.insert("window".to_string(), serde_json::json!(window));
|
|
372
|
+
Ok(())
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
pub(super) fn write_start_agent_noop_event(
|
|
376
|
+
workspace: &Path,
|
|
377
|
+
agent_id: &AgentId,
|
|
378
|
+
target: &str,
|
|
379
|
+
coordinator_started: bool,
|
|
380
|
+
) -> Result<(), LifecycleError> {
|
|
381
|
+
crate::event_log::EventLog::new(workspace)
|
|
382
|
+
.write(
|
|
383
|
+
"start_agent.noop",
|
|
384
|
+
serde_json::json!({
|
|
385
|
+
"agent_id": agent_id.as_str(),
|
|
386
|
+
"target": target,
|
|
387
|
+
"coordinator": coordinator_started,
|
|
388
|
+
}),
|
|
389
|
+
)
|
|
390
|
+
.map_err(|e| LifecycleError::StatePersist(e.to_string()))?;
|
|
391
|
+
Ok(())
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
pub(super) fn window_exists(
|
|
395
|
+
transport: &dyn crate::transport::Transport,
|
|
396
|
+
session_name: &SessionName,
|
|
397
|
+
window: &str,
|
|
398
|
+
) -> bool {
|
|
399
|
+
match std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
|
|
400
|
+
transport.list_windows(session_name)
|
|
401
|
+
})) {
|
|
402
|
+
Ok(Ok(windows)) => windows.iter().any(|w| w.as_str() == window),
|
|
403
|
+
Ok(Err(_)) | Err(_) => false,
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
pub(super) fn close_agent_display(state: &mut serde_json::Value, agent_id: &AgentId) {
|
|
408
|
+
let Some(display) = state
|
|
409
|
+
.get_mut("agents")
|
|
410
|
+
.and_then(|v| v.as_object_mut())
|
|
411
|
+
.and_then(|agents| agents.get_mut(agent_id.as_str()))
|
|
412
|
+
.and_then(|agent| agent.get_mut("display"))
|
|
413
|
+
.and_then(|display| display.as_object_mut())
|
|
414
|
+
else {
|
|
415
|
+
return;
|
|
416
|
+
};
|
|
417
|
+
let backend = display
|
|
418
|
+
.get("backend")
|
|
419
|
+
.and_then(|v| v.as_str())
|
|
420
|
+
.unwrap_or("")
|
|
421
|
+
.to_string();
|
|
422
|
+
// golden operations.py:88-92: close_ghostty_display (display/close.py:17-48) mutates NOTHING in the
|
|
423
|
+
// persisted state for a ghostty_window; only the ghostty_workspace slot is relabeled
|
|
424
|
+
// (close.py:84-85: status="stopped", pane_title=f"stopped: {agent_id}") and re-assigned back.
|
|
425
|
+
if backend == "ghostty_workspace" {
|
|
426
|
+
display.insert("status".to_string(), serde_json::json!("stopped"));
|
|
427
|
+
display.insert(
|
|
428
|
+
"pane_title".to_string(),
|
|
429
|
+
serde_json::json!(format!("stopped: {}", agent_id.as_str())),
|
|
430
|
+
);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
pub(super) fn discard_agent_session_fields(
|
|
435
|
+
state: &mut serde_json::Value,
|
|
436
|
+
agent_id: &AgentId,
|
|
437
|
+
) -> Result<(), LifecycleError> {
|
|
438
|
+
let Some(agent) = state
|
|
439
|
+
.get_mut("agents")
|
|
440
|
+
.and_then(|v| v.as_object_mut())
|
|
441
|
+
.and_then(|agents| agents.get_mut(agent_id.as_str()))
|
|
442
|
+
else {
|
|
443
|
+
return Err(unknown_worker(agent_id));
|
|
444
|
+
};
|
|
445
|
+
let Some(obj) = agent.as_object_mut() else {
|
|
446
|
+
return Err(LifecycleError::StatePersist(
|
|
447
|
+
"agent state is not an object".to_string(),
|
|
448
|
+
));
|
|
449
|
+
};
|
|
450
|
+
// golden operations.py:119 pops EXACTLY `[*SESSION_CAPTURE_FIELDS, "_pending_session_id"]`.
|
|
451
|
+
// spawn_cwd lives in SESSION_STATE_FIELDS (state.py:26-28), NOT SESSION_CAPTURE_FIELDS, so it is
|
|
452
|
+
// PRESERVED through the discard. (Probe: SESSION_CAPTURE_FIELDS = session_id, rollout_path,
|
|
453
|
+
// captured_at, captured_via, attribution_confidence.)
|
|
454
|
+
for key in [
|
|
455
|
+
"session_id",
|
|
456
|
+
"rollout_path",
|
|
457
|
+
"captured_at",
|
|
458
|
+
"captured_via",
|
|
459
|
+
"attribution_confidence",
|
|
460
|
+
"_pending_session_id",
|
|
461
|
+
] {
|
|
462
|
+
obj.remove(key);
|
|
463
|
+
}
|
|
464
|
+
obj.insert("status".to_string(), serde_json::json!("stopped"));
|
|
465
|
+
Ok(())
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
pub(super) fn agent_is_running(
|
|
469
|
+
state: &serde_json::Value,
|
|
470
|
+
agent_id: &AgentId,
|
|
471
|
+
transport: &dyn crate::transport::Transport,
|
|
472
|
+
) -> bool {
|
|
473
|
+
let agent_state = state
|
|
474
|
+
.get("agents")
|
|
475
|
+
.and_then(|v| v.get(agent_id.as_str()));
|
|
476
|
+
let status = agent_state
|
|
477
|
+
.and_then(|v| v.get("status"))
|
|
478
|
+
.and_then(|v| v.as_str())
|
|
479
|
+
.map(str::to_ascii_lowercase);
|
|
480
|
+
// golden agents.py:247-252 (_is_running): True ONLY for {running,busy}; EVERY other status (including
|
|
481
|
+
// stopped/paused/failed/removed) falls through to the session_name + tmux-window-exists check.
|
|
482
|
+
if matches!(status.as_deref(), Some("running" | "busy")) {
|
|
483
|
+
return true;
|
|
484
|
+
}
|
|
485
|
+
let Some(session_name) = state
|
|
486
|
+
.get("session_name")
|
|
487
|
+
.and_then(|v| v.as_str())
|
|
488
|
+
.filter(|s| !s.is_empty())
|
|
489
|
+
.map(SessionName::new)
|
|
490
|
+
else {
|
|
491
|
+
return false;
|
|
492
|
+
};
|
|
493
|
+
let window = agent_state
|
|
494
|
+
.and_then(|v| v.get("window"))
|
|
495
|
+
.and_then(|v| v.as_str())
|
|
496
|
+
.filter(|s| !s.is_empty())
|
|
497
|
+
.unwrap_or_else(|| agent_id.as_str());
|
|
498
|
+
window_exists(transport, &session_name, window)
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
pub(super) fn is_dynamic_agent(
|
|
502
|
+
state: &serde_json::Value,
|
|
503
|
+
spec_agent: &YamlValue,
|
|
504
|
+
agent_id: &AgentId,
|
|
505
|
+
) -> bool {
|
|
506
|
+
let dynamic_role = state
|
|
507
|
+
.get("agents")
|
|
508
|
+
.and_then(|v| v.get(agent_id.as_str()))
|
|
509
|
+
.and_then(|v| v.get("dynamic_role_file"))
|
|
510
|
+
.and_then(|v| v.as_str())
|
|
511
|
+
.is_some_and(|s| !s.is_empty());
|
|
512
|
+
dynamic_role
|
|
513
|
+
|| spec_agent
|
|
514
|
+
.get("forked_from")
|
|
515
|
+
.and_then(YamlValue::as_str)
|
|
516
|
+
.is_some_and(|s| !s.is_empty())
|
|
517
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
use super::*;
|
|
2
|
+
|
|
3
|
+
// ── lifecycle::orchestrator —— plan 多 stage 状态机(halt / status)──────────
|
|
4
|
+
|
|
5
|
+
/// `halt_plan(workspace, plan_id, reason)`(`orchestrator/__init__.py:152`)。停 plan;
|
|
6
|
+
/// 非 running → 幂等返回。
|
|
7
|
+
pub fn halt_plan(
|
|
8
|
+
workspace: &Path,
|
|
9
|
+
plan_id: &PlanId,
|
|
10
|
+
reason: &str,
|
|
11
|
+
) -> Result<PlanProgress, LifecycleError> {
|
|
12
|
+
let _ = reason;
|
|
13
|
+
let path = plan_state_path(workspace, plan_id);
|
|
14
|
+
if !path.exists() {
|
|
15
|
+
return Err(LifecycleError::InvalidPlan(format!(
|
|
16
|
+
"plan not found: {}",
|
|
17
|
+
plan_id.as_str()
|
|
18
|
+
)));
|
|
19
|
+
}
|
|
20
|
+
let state = read_plan_state(&path)?;
|
|
21
|
+
Ok(PlanProgress::Halted {
|
|
22
|
+
plan_id: state.plan_id,
|
|
23
|
+
reason: "already_terminal".to_string(),
|
|
24
|
+
artifact: state.halt_artifact,
|
|
25
|
+
})
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/// `plan_status(workspace, plan_id)`(`orchestrator/__init__.py:177`)。读 plan 持久态。
|
|
29
|
+
pub fn plan_status(
|
|
30
|
+
workspace: &Path,
|
|
31
|
+
plan_id: &PlanId,
|
|
32
|
+
) -> Result<PlanState, LifecycleError> {
|
|
33
|
+
let path = plan_state_path(workspace, plan_id);
|
|
34
|
+
if !path.exists() {
|
|
35
|
+
return Err(LifecycleError::InvalidPlan(format!(
|
|
36
|
+
"plan not found: {}",
|
|
37
|
+
plan_id.as_str()
|
|
38
|
+
)));
|
|
39
|
+
}
|
|
40
|
+
read_plan_state(&path)
|
|
41
|
+
}
|