@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,208 @@
|
|
|
1
|
+
use super::*;
|
|
2
|
+
use super::common::*;
|
|
3
|
+
|
|
4
|
+
/// bug-085 四象限 `start_mode` 决策(`start.py:179-188` + `_resume_rollout_missing` `start.py:66-69`),
|
|
5
|
+
/// **从 start_agent 的整条 lock+spawn 路径里分离出的纯函数**(gate gap:porter 需要单元级 RED
|
|
6
|
+
/// for `FreshAfterMissingRollout`,而 start_agent 全路径不可单测)。语义:
|
|
7
|
+
/// - `_resume_rollout_missing` 仅 codex 且有 session_id 时可能 true:`!rollout_path || !exists`。
|
|
8
|
+
/// - 初始 `start_mode = if session_id { Resumed } else { Fresh }`(`start.py:179`)。
|
|
9
|
+
/// - **仅当** `missing && allow_fresh` 才升级为 `FreshAfterMissingRollout` 并清空 session_id
|
|
10
|
+
/// (`start.py:180-190`)。`missing && !allow_fresh` 仍 `Resumed`(随后真实 resume 会 fail)。
|
|
11
|
+
/// - 非 codex:rollout 永不"缺失",直接看 session_id。
|
|
12
|
+
pub fn decide_start_mode(
|
|
13
|
+
provider: &str,
|
|
14
|
+
session_id: Option<&SessionId>,
|
|
15
|
+
rollout_path: Option<&RolloutPath>,
|
|
16
|
+
rollout_exists: bool,
|
|
17
|
+
allow_fresh: bool,
|
|
18
|
+
) -> StartMode {
|
|
19
|
+
match session_id {
|
|
20
|
+
None => StartMode::Fresh,
|
|
21
|
+
Some(_) => {
|
|
22
|
+
let missing_codex_rollout =
|
|
23
|
+
provider == "codex" && (rollout_path.is_none() || !rollout_exists);
|
|
24
|
+
if missing_codex_rollout && allow_fresh {
|
|
25
|
+
StartMode::FreshAfterMissingRollout
|
|
26
|
+
} else {
|
|
27
|
+
StartMode::Resumed
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/// `first_send_at` 严格分类(`_classify_first_send_at`,`orchestration.py:399`)。
|
|
34
|
+
/// **绝不靠 truthiness**:`""`/`0`/`False`/`"null"`/非 ISO → `Corrupt`。
|
|
35
|
+
pub fn classify_first_send_at(raw: &serde_json::Value) -> FirstSendAtState {
|
|
36
|
+
match raw {
|
|
37
|
+
serde_json::Value::Null => FirstSendAtState::Absent,
|
|
38
|
+
serde_json::Value::String(s) => {
|
|
39
|
+
if is_python_fromisoformat_like(s) {
|
|
40
|
+
FirstSendAtState::Valid
|
|
41
|
+
} else {
|
|
42
|
+
FirstSendAtState::Corrupt
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
serde_json::Value::Bool(_)
|
|
46
|
+
| serde_json::Value::Number(_)
|
|
47
|
+
| serde_json::Value::Array(_)
|
|
48
|
+
| serde_json::Value::Object(_) => FirstSendAtState::Corrupt,
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
fn is_python_fromisoformat_like(raw: &str) -> bool {
|
|
53
|
+
if raw.is_empty() {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
if chrono::DateTime::parse_from_rfc3339(raw).is_ok()
|
|
57
|
+
|| chrono::DateTime::parse_from_str(raw, "%Y-%m-%dT%H:%M:%S%z").is_ok()
|
|
58
|
+
|| chrono::DateTime::parse_from_str(raw, "%Y-%m-%dT%H:%M:%S%.f%z").is_ok()
|
|
59
|
+
{
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
let normalized = normalize_iso_separator(raw);
|
|
64
|
+
for pattern in [
|
|
65
|
+
"%Y-%m-%d",
|
|
66
|
+
"%Y%m%d",
|
|
67
|
+
"%Y-%m-%dT%H:%M",
|
|
68
|
+
"%Y-%m-%dT%H:%M:%S",
|
|
69
|
+
"%Y-%m-%dT%H:%M:%S%.f",
|
|
70
|
+
"%Y-%m-%dT%H:%M%z",
|
|
71
|
+
"%Y-%m-%dT%H:%M:%S%z",
|
|
72
|
+
"%Y-%m-%dT%H:%M:%S%.f%z",
|
|
73
|
+
"%Y%m%dT%H%M%S",
|
|
74
|
+
] {
|
|
75
|
+
if chrono::NaiveDate::parse_from_str(&normalized, pattern).is_ok()
|
|
76
|
+
|| chrono::NaiveDateTime::parse_from_str(&normalized, pattern).is_ok()
|
|
77
|
+
|| chrono::DateTime::parse_from_str(&normalized, pattern).is_ok()
|
|
78
|
+
{
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
false
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
fn normalize_iso_separator(raw: &str) -> String {
|
|
86
|
+
let mut out = String::with_capacity(raw.len());
|
|
87
|
+
for (idx, ch) in raw.chars().enumerate() {
|
|
88
|
+
if idx == 10 && matches!(ch, ' ' | 't' | '_') {
|
|
89
|
+
out.push('T');
|
|
90
|
+
} else {
|
|
91
|
+
out.push(ch);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
out
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/// Python `type(value).__name__` 映射(`orchestration.py:446`):corrupt first_send_at
|
|
98
|
+
/// 条目的 `raw_first_send_at_type` golden。锁死跨语言一致:`null→"NoneType"`、`""/"x"→"str"`、
|
|
99
|
+
/// `0/123→"int"`、`false→"bool"`、`[]→"list"`、`{}→"dict"`、float→`"float"`。
|
|
100
|
+
/// **绝不**用 Rust 的 `"null"/"string"/"number"/"boolean"/"array"/"object"`(serde 名)—— 必须是
|
|
101
|
+
/// Python 名,否则 audit payload 与真相源不一致。
|
|
102
|
+
pub fn python_type_name(value: &serde_json::Value) -> &'static str {
|
|
103
|
+
match value {
|
|
104
|
+
serde_json::Value::Null => "NoneType",
|
|
105
|
+
serde_json::Value::String(_) => "str",
|
|
106
|
+
serde_json::Value::Bool(_) => "bool",
|
|
107
|
+
serde_json::Value::Array(_) => "list",
|
|
108
|
+
serde_json::Value::Object(_) => "dict",
|
|
109
|
+
serde_json::Value::Number(n) => {
|
|
110
|
+
if n.is_i64() || n.is_u64() {
|
|
111
|
+
"int"
|
|
112
|
+
} else {
|
|
113
|
+
"float"
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/// Route B 全量验证(纯计算,**无破坏性副作用**;`_emit_resume_decisions` +
|
|
120
|
+
/// `_collect_corrupt_first_send_at`,`orchestration.py:430/467`)。读 fixture state 的
|
|
121
|
+
/// `agents.<id>`,对每非 paused worker:
|
|
122
|
+
/// (1) corrupt first_send_at → 收进 `corrupt_entries`(carry python type-name);
|
|
123
|
+
/// (2) 算 resume 决策(`resumable→Resume` / `!resumable&&!interacted→FreshStart` /
|
|
124
|
+
/// `!resumable&&interacted&&allow_fresh→FreshStart` / 否则 `Refuse`);
|
|
125
|
+
/// (3) `Refuse` 的 worker(reason=`no_persisted_session_id`(无 session)|`session_unresumable`)
|
|
126
|
+
/// 进 `unresumable`。
|
|
127
|
+
/// restart() **先**调它再 teardown;corrupt 非空 → `RefusedInvalidFirstSendAt`,unresumable
|
|
128
|
+
/// 非空且 !allow_fresh → `RefusedResumeAtomicity`。**refuse 早于一切 teardown,nothing created**。
|
|
129
|
+
pub fn classify_restart_plan(
|
|
130
|
+
state: &serde_json::Value,
|
|
131
|
+
allow_fresh: bool,
|
|
132
|
+
) -> Result<RestartPlan, LifecycleError> {
|
|
133
|
+
let mut decisions = Vec::new();
|
|
134
|
+
let mut corrupt_entries = Vec::new();
|
|
135
|
+
let mut unresumable = Vec::new();
|
|
136
|
+
|
|
137
|
+
let Some(agents) = state.get("agents").and_then(|v| v.as_object()) else {
|
|
138
|
+
return Ok(RestartPlan {
|
|
139
|
+
decisions,
|
|
140
|
+
corrupt_entries,
|
|
141
|
+
unresumable,
|
|
142
|
+
});
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
for (worker_id, agent) in agents {
|
|
146
|
+
if agent
|
|
147
|
+
.get("status")
|
|
148
|
+
.and_then(|v| v.as_str())
|
|
149
|
+
.map(|s| s == "paused")
|
|
150
|
+
.unwrap_or(false)
|
|
151
|
+
{
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
let first_send_at_raw = agent
|
|
156
|
+
.get("first_send_at")
|
|
157
|
+
.cloned()
|
|
158
|
+
.unwrap_or(serde_json::Value::Null);
|
|
159
|
+
let first_send_at_state = classify_first_send_at(&first_send_at_raw);
|
|
160
|
+
if matches!(first_send_at_state, FirstSendAtState::Corrupt) {
|
|
161
|
+
corrupt_entries.push(CorruptFirstSendAt {
|
|
162
|
+
worker_id: AgentId::new(worker_id.clone()),
|
|
163
|
+
raw_first_send_at_type: python_type_name(&first_send_at_raw).to_string(),
|
|
164
|
+
raw_first_send_at: first_send_at_raw,
|
|
165
|
+
});
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
let session_id = agent
|
|
170
|
+
.get("session_id")
|
|
171
|
+
.and_then(|v| v.as_str())
|
|
172
|
+
.filter(|s| !s.is_empty())
|
|
173
|
+
.map(SessionId::new);
|
|
174
|
+
let interacted = matches!(first_send_at_state, FirstSendAtState::Valid);
|
|
175
|
+
let decision = if session_id.is_some() {
|
|
176
|
+
ResumeDecision::Resume
|
|
177
|
+
} else if !interacted || allow_fresh {
|
|
178
|
+
ResumeDecision::FreshStart
|
|
179
|
+
} else {
|
|
180
|
+
ResumeDecision::Refuse
|
|
181
|
+
};
|
|
182
|
+
let agent_id = AgentId::new(worker_id.clone());
|
|
183
|
+
if matches!(decision, ResumeDecision::Refuse) {
|
|
184
|
+
unresumable.push(UnresumableWorker {
|
|
185
|
+
agent_id: agent_id.clone(),
|
|
186
|
+
reason: "no_persisted_session_id".to_string(),
|
|
187
|
+
session_id: session_id.clone(),
|
|
188
|
+
first_send_at: first_send_at_raw.as_str().map(|s| s.to_string()),
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
decisions.push(RestartedAgent {
|
|
192
|
+
agent_id,
|
|
193
|
+
restart_mode: match decision {
|
|
194
|
+
ResumeDecision::Resume => StartMode::Resumed,
|
|
195
|
+
ResumeDecision::FreshStart => StartMode::Fresh,
|
|
196
|
+
ResumeDecision::Refuse => StartMode::Noop,
|
|
197
|
+
},
|
|
198
|
+
decision,
|
|
199
|
+
session_id,
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
Ok(RestartPlan {
|
|
204
|
+
decisions,
|
|
205
|
+
corrupt_entries,
|
|
206
|
+
unresumable,
|
|
207
|
+
})
|
|
208
|
+
}
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
use super::*;
|
|
2
|
+
|
|
3
|
+
pub(crate) fn write_team_state(
|
|
4
|
+
workspace: &Path,
|
|
5
|
+
spec: &YamlValue,
|
|
6
|
+
state: &serde_json::Value,
|
|
7
|
+
) -> Result<std::path::PathBuf, LifecycleError> {
|
|
8
|
+
let rel = spec
|
|
9
|
+
.get("context")
|
|
10
|
+
.and_then(|v| v.get("state_file"))
|
|
11
|
+
.and_then(YamlValue::as_str)
|
|
12
|
+
.unwrap_or("team_state.md");
|
|
13
|
+
let path = workspace.join(rel);
|
|
14
|
+
if let Some(parent) = path.parent() {
|
|
15
|
+
std::fs::create_dir_all(parent)
|
|
16
|
+
.map_err(|e| LifecycleError::StatePersist(format!("write team_state: {e}")))?;
|
|
17
|
+
}
|
|
18
|
+
// golden state.py:625-686 — byte-faithful layout (probed). Blank line after the title and after each
|
|
19
|
+
// '##' header; '## Team' / '## Latest Results' sections; Task Graph as
|
|
20
|
+
// `- {id} [{status}], assignee={assignee|unassigned}, deps={deps|none}: {title}`.
|
|
21
|
+
let mut lines: Vec<String> = Vec::new();
|
|
22
|
+
lines.push("# Team State".to_string());
|
|
23
|
+
lines.push(String::new());
|
|
24
|
+
lines.push(format!("Updated: {}", team_state_now()));
|
|
25
|
+
lines.push(String::new());
|
|
26
|
+
lines.push("## Objective".to_string());
|
|
27
|
+
lines.push(String::new());
|
|
28
|
+
lines.push(
|
|
29
|
+
spec.get("team")
|
|
30
|
+
.and_then(|v| v.get("objective"))
|
|
31
|
+
.and_then(YamlValue::as_str)
|
|
32
|
+
.unwrap_or("")
|
|
33
|
+
.to_string(),
|
|
34
|
+
);
|
|
35
|
+
lines.push(String::new());
|
|
36
|
+
lines.push("## Team".to_string());
|
|
37
|
+
lines.push(String::new());
|
|
38
|
+
lines.push(format!(
|
|
39
|
+
"- Name: {}",
|
|
40
|
+
spec.get("team")
|
|
41
|
+
.and_then(|v| v.get("name"))
|
|
42
|
+
.and_then(YamlValue::as_str)
|
|
43
|
+
.unwrap_or("None")
|
|
44
|
+
));
|
|
45
|
+
lines.push(format!(
|
|
46
|
+
"- Runtime session: {}",
|
|
47
|
+
state
|
|
48
|
+
.get("session_name")
|
|
49
|
+
.and_then(|v| v.as_str())
|
|
50
|
+
.unwrap_or("None")
|
|
51
|
+
));
|
|
52
|
+
// leader_receiver (golden state.py:642-651): direct_tmux line, else inbox-fallback + log lines.
|
|
53
|
+
if let Some(receiver) = state
|
|
54
|
+
.get("leader_receiver")
|
|
55
|
+
.and_then(|v| v.as_object())
|
|
56
|
+
.filter(|m| !m.is_empty())
|
|
57
|
+
{
|
|
58
|
+
let g = |k: &str| receiver.get(k).and_then(|v| v.as_str()).unwrap_or("None");
|
|
59
|
+
if receiver.get("mode").and_then(|v| v.as_str()) == Some("direct_tmux") {
|
|
60
|
+
lines.push(format!(
|
|
61
|
+
"- Leader receiver: direct tmux {} ({}, {})",
|
|
62
|
+
g("pane_id"),
|
|
63
|
+
g("provider"),
|
|
64
|
+
g("status")
|
|
65
|
+
));
|
|
66
|
+
} else {
|
|
67
|
+
lines.push(format!(
|
|
68
|
+
"- Leader inbox fallback: {}:{} ({})",
|
|
69
|
+
g("session"),
|
|
70
|
+
g("window"),
|
|
71
|
+
g("status")
|
|
72
|
+
));
|
|
73
|
+
lines.push(format!("- Leader inbox log: {}", g("path")));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
lines.push(String::new());
|
|
77
|
+
lines.push("## Agents".to_string());
|
|
78
|
+
lines.push(String::new());
|
|
79
|
+
if let Some(agents) = spec.get("agents").and_then(YamlValue::as_list) {
|
|
80
|
+
for agent in agents {
|
|
81
|
+
let Some(id) = agent.get("id").and_then(YamlValue::as_str) else {
|
|
82
|
+
continue;
|
|
83
|
+
};
|
|
84
|
+
let role = agent
|
|
85
|
+
.get("role")
|
|
86
|
+
.and_then(YamlValue::as_str)
|
|
87
|
+
.unwrap_or(id);
|
|
88
|
+
let provider = agent
|
|
89
|
+
.get("provider")
|
|
90
|
+
.and_then(YamlValue::as_str)
|
|
91
|
+
.unwrap_or("codex");
|
|
92
|
+
let status = state
|
|
93
|
+
.get("agents")
|
|
94
|
+
.and_then(|v| v.get(id))
|
|
95
|
+
.and_then(|v| v.get("status"))
|
|
96
|
+
.and_then(|v| v.as_str())
|
|
97
|
+
.unwrap_or("unknown");
|
|
98
|
+
lines.push(format!("- {id}: {role} on {provider} ({status})"));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
lines.push(String::new());
|
|
102
|
+
lines.push("## Task Graph".to_string());
|
|
103
|
+
lines.push(String::new());
|
|
104
|
+
// golden: runtime.get("tasks", spec.get("tasks", [])) — state tasks else spec tasks.
|
|
105
|
+
let tasks = team_state_tasks(spec, state);
|
|
106
|
+
for task in &tasks {
|
|
107
|
+
let id = task_field_str(task, "id");
|
|
108
|
+
let title = task_field_str(task, "title");
|
|
109
|
+
let status = {
|
|
110
|
+
let s = task_field_str(task, "status");
|
|
111
|
+
if s.is_empty() { "pending".to_string() } else { s }
|
|
112
|
+
};
|
|
113
|
+
let assignee = {
|
|
114
|
+
let a = task_field_str(task, "assignee");
|
|
115
|
+
if a.is_empty() { "unassigned".to_string() } else { a }
|
|
116
|
+
};
|
|
117
|
+
let deps = {
|
|
118
|
+
let d = task_field_list(task, "deps");
|
|
119
|
+
if d.is_empty() { "none".to_string() } else { d.join(", ") }
|
|
120
|
+
};
|
|
121
|
+
lines.push(format!("- {id} [{status}], assignee={assignee}, deps={deps}: {title}"));
|
|
122
|
+
let summary = task_field_str(task, "last_result_summary");
|
|
123
|
+
if !summary.is_empty() {
|
|
124
|
+
lines.push(format!(" Summary: {summary}"));
|
|
125
|
+
}
|
|
126
|
+
for art in task_artifact_refs(task) {
|
|
127
|
+
lines.push(art);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
lines.push(String::new());
|
|
131
|
+
lines.push("## Latest Results".to_string());
|
|
132
|
+
lines.push(String::new());
|
|
133
|
+
// remove/stop/reset pass no results -> header + blank only (golden).
|
|
134
|
+
lines.push(String::new());
|
|
135
|
+
lines.push("## Blockers".to_string());
|
|
136
|
+
lines.push(String::new());
|
|
137
|
+
let blockers: Vec<&TeamStateTask> = tasks
|
|
138
|
+
.iter()
|
|
139
|
+
.filter(|t| matches!(task_field_str(t, "status").as_str(), "blocked" | "failed" | "needs_retry"))
|
|
140
|
+
.collect();
|
|
141
|
+
if blockers.is_empty() {
|
|
142
|
+
lines.push("- None".to_string());
|
|
143
|
+
} else {
|
|
144
|
+
for task in blockers {
|
|
145
|
+
let id = task_field_str(task, "id");
|
|
146
|
+
let summary = {
|
|
147
|
+
let s = task_field_str(task, "last_result_summary");
|
|
148
|
+
if s.is_empty() { task_field_str(task, "title") } else { s }
|
|
149
|
+
};
|
|
150
|
+
lines.push(format!("- {id}: {summary}"));
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
lines.push(String::new());
|
|
154
|
+
lines.push("## Next Step".to_string());
|
|
155
|
+
lines.push(String::new());
|
|
156
|
+
lines.push("- Continue routing ready tasks and collect result envelopes.".to_string());
|
|
157
|
+
let text = format!("{}\n", lines.join("\n"));
|
|
158
|
+
std::fs::write(&path, text)
|
|
159
|
+
.map_err(|e| LifecycleError::StatePersist(format!("write team_state: {e}")))?;
|
|
160
|
+
Ok(path)
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/// A task row sourced from either runtime state (serde_json) or the spec (YAML), so write_team_state
|
|
164
|
+
/// can mirror golden's `runtime.get("tasks", spec.get("tasks", []))` fallback.
|
|
165
|
+
enum TeamStateTask {
|
|
166
|
+
Json(serde_json::Value),
|
|
167
|
+
Yaml(YamlValue),
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/// golden `datetime.now(timezone.utc).isoformat()` analog (microseconds + `+00:00`).
|
|
171
|
+
fn team_state_now() -> String {
|
|
172
|
+
chrono::Utc::now().format("%Y-%m-%dT%H:%M:%S%.6f+00:00").to_string()
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
fn team_state_tasks(spec: &YamlValue, state: &serde_json::Value) -> Vec<TeamStateTask> {
|
|
176
|
+
if let Some(tasks) = state.get("tasks").and_then(|v| v.as_array()) {
|
|
177
|
+
return tasks.iter().cloned().map(TeamStateTask::Json).collect();
|
|
178
|
+
}
|
|
179
|
+
if let Some(tasks) = spec.get("tasks").and_then(YamlValue::as_list) {
|
|
180
|
+
return tasks.iter().cloned().map(TeamStateTask::Yaml).collect();
|
|
181
|
+
}
|
|
182
|
+
Vec::new()
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
fn task_field_str(task: &TeamStateTask, key: &str) -> String {
|
|
186
|
+
match task {
|
|
187
|
+
TeamStateTask::Json(v) => v.get(key).and_then(|v| v.as_str()).unwrap_or("").to_string(),
|
|
188
|
+
TeamStateTask::Yaml(v) => v.get(key).and_then(YamlValue::as_str).unwrap_or("").to_string(),
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
fn task_field_list(task: &TeamStateTask, key: &str) -> Vec<String> {
|
|
193
|
+
match task {
|
|
194
|
+
TeamStateTask::Json(v) => v
|
|
195
|
+
.get(key)
|
|
196
|
+
.and_then(|v| v.as_array())
|
|
197
|
+
.map(|items| items.iter().filter_map(|i| i.as_str().map(str::to_string)).collect())
|
|
198
|
+
.unwrap_or_default(),
|
|
199
|
+
TeamStateTask::Yaml(v) => v
|
|
200
|
+
.get(key)
|
|
201
|
+
.and_then(YamlValue::as_list)
|
|
202
|
+
.map(|items| items.iter().filter_map(|i| i.as_str().map(str::to_string)).collect())
|
|
203
|
+
.unwrap_or_default(),
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
fn task_artifact_refs(task: &TeamStateTask) -> Vec<String> {
|
|
208
|
+
match task {
|
|
209
|
+
TeamStateTask::Json(v) => v
|
|
210
|
+
.get("artifact_refs")
|
|
211
|
+
.and_then(|v| v.as_array())
|
|
212
|
+
.map(|refs| {
|
|
213
|
+
refs.iter()
|
|
214
|
+
.map(|r| match r.as_object() {
|
|
215
|
+
Some(m) => format!(
|
|
216
|
+
" Artifact: {} - {}",
|
|
217
|
+
m.get("path").and_then(|v| v.as_str()).unwrap_or("None"),
|
|
218
|
+
m.get("description").and_then(|v| v.as_str()).unwrap_or("")
|
|
219
|
+
),
|
|
220
|
+
None => format!(" Artifact: INVALID artifact ref {r}"),
|
|
221
|
+
})
|
|
222
|
+
.collect()
|
|
223
|
+
})
|
|
224
|
+
.unwrap_or_default(),
|
|
225
|
+
TeamStateTask::Yaml(v) => v
|
|
226
|
+
.get("artifact_refs")
|
|
227
|
+
.and_then(YamlValue::as_list)
|
|
228
|
+
.map(|refs| {
|
|
229
|
+
refs.iter()
|
|
230
|
+
.map(|r| match r.as_map() {
|
|
231
|
+
Some(_) => format!(
|
|
232
|
+
" Artifact: {} - {}",
|
|
233
|
+
r.get("path").and_then(YamlValue::as_str).unwrap_or("None"),
|
|
234
|
+
r.get("description").and_then(YamlValue::as_str).unwrap_or("")
|
|
235
|
+
),
|
|
236
|
+
None => format!(" Artifact: INVALID artifact ref {:?}", r),
|
|
237
|
+
})
|
|
238
|
+
.collect()
|
|
239
|
+
})
|
|
240
|
+
.unwrap_or_default(),
|
|
241
|
+
}
|
|
242
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
//! lifecycle::restart —— 单 worker 起/停/重置/删 + 整队 Route B 重建 + plan halt/status。
|
|
2
|
+
|
|
3
|
+
use std::path::Path;
|
|
4
|
+
use std::collections::BTreeMap;
|
|
5
|
+
|
|
6
|
+
use crate::model::enums::{AuthMode, Provider};
|
|
7
|
+
use crate::model::ids::AgentId;
|
|
8
|
+
use crate::model::yaml::{self, Value as YamlValue};
|
|
9
|
+
use crate::provider::{RolloutPath, SessionId};
|
|
10
|
+
use crate::transport::{SessionName, Target, WindowName};
|
|
11
|
+
|
|
12
|
+
use super::*;
|
|
13
|
+
|
|
14
|
+
// ── lifecycle::agent —— 单 worker 起/停/重置/增/fork/删(全部 owner-gate 优先 + 回滚)─
|
|
15
|
+
|
|
16
|
+
struct LifecyclePaths {
|
|
17
|
+
run_workspace: std::path::PathBuf,
|
|
18
|
+
spec_workspace: std::path::PathBuf,
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
struct LifecyclePathRefs<'a> {
|
|
22
|
+
run_workspace: &'a Path,
|
|
23
|
+
spec_workspace: &'a Path,
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
mod agent;
|
|
27
|
+
mod common;
|
|
28
|
+
mod orchestrator;
|
|
29
|
+
mod rebuild;
|
|
30
|
+
mod remove;
|
|
31
|
+
mod selection;
|
|
32
|
+
mod team_state;
|
|
33
|
+
|
|
34
|
+
pub use agent::{reset_agent, reset_agent_with_transport, start_agent, start_agent_with_transport, stop_agent, stop_agent_with_transport};
|
|
35
|
+
pub(crate) use agent::start_agent_at_paths;
|
|
36
|
+
pub use orchestrator::{halt_plan, plan_status};
|
|
37
|
+
pub use rebuild::{restart, restart_candidates, restart_with_transport, select_restart_state};
|
|
38
|
+
pub use remove::{remove_agent, remove_agent_with_transport};
|
|
39
|
+
pub use selection::{classify_first_send_at, classify_restart_plan, decide_start_mode, python_type_name};
|
|
40
|
+
pub(crate) use team_state::write_team_state;
|
|
41
|
+
|
|
42
|
+
pub(crate) fn lifecycle_run_workspace(workspace: &Path) -> Result<std::path::PathBuf, LifecycleError> {
|
|
43
|
+
crate::model::paths::canonical_run_workspace(workspace)
|
|
44
|
+
.map_err(|e| LifecycleError::StatePersist(e.to_string()))
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
fn lifecycle_paths(workspace: &Path, team: Option<&str>) -> Result<LifecyclePaths, LifecycleError> {
|
|
48
|
+
let selected = crate::state::selector::resolve_active_team(
|
|
49
|
+
workspace,
|
|
50
|
+
team,
|
|
51
|
+
crate::state::selector::SelectorMode::RequireSpec,
|
|
52
|
+
)
|
|
53
|
+
.map_err(|e| LifecycleError::TeamSelect(e.to_string()))?;
|
|
54
|
+
let spec_workspace = selected_state_spec_workspace(&selected.state)
|
|
55
|
+
.or(selected.spec_workspace)
|
|
56
|
+
.ok_or_else(|| LifecycleError::TeamSelect("active team spec workspace not found".to_string()))?;
|
|
57
|
+
Ok(LifecyclePaths {
|
|
58
|
+
run_workspace: selected.run_workspace,
|
|
59
|
+
spec_workspace,
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
fn selected_state_spec_workspace(state: &serde_json::Value) -> Option<std::path::PathBuf> {
|
|
64
|
+
state
|
|
65
|
+
.get("spec_path")
|
|
66
|
+
.and_then(serde_json::Value::as_str)
|
|
67
|
+
.filter(|s| !s.is_empty())
|
|
68
|
+
.and_then(|s| Path::new(s).parent().map(Path::to_path_buf))
|
|
69
|
+
.or_else(|| {
|
|
70
|
+
state
|
|
71
|
+
.get("team_dir")
|
|
72
|
+
.and_then(serde_json::Value::as_str)
|
|
73
|
+
.filter(|s| !s.is_empty())
|
|
74
|
+
.map(std::path::PathBuf::from)
|
|
75
|
+
})
|
|
76
|
+
}
|