@team-agent/installer 0.5.128 → 0.6.1
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/README.md +4 -4
- package/README.zh.md +1 -1
- package/package.json +4 -8
- package/skills/team-agent/SKILL.md +37 -20
- package/skills/team-agent/command-coverage.json +169 -183
- package/skills/team-agent/docs/reference/team-agent-operator.md +64 -30
- package/skills/team-agent/references/recovery-runbook.md +1 -1
- package/skills/team-agent/references/team-agent-operator.md +64 -30
- package/templates/team_state.md +1 -1
- package/Cargo.lock +0 -1063
- package/Cargo.toml +0 -36
- package/crates/team-agent/Cargo.toml +0 -69
- package/crates/team-agent/src/app_server_test_support.rs +0 -258
- package/crates/team-agent/src/cli/adapters.rs +0 -1288
- package/crates/team-agent/src/cli/arguments.rs +0 -405
- package/crates/team-agent/src/cli/attach_app_server_leader.rs +0 -98
- package/crates/team-agent/src/cli/diagnose.rs +0 -1721
- package/crates/team-agent/src/cli/emit.rs +0 -2930
- package/crates/team-agent/src/cli/grok_slot.rs +0 -384
- package/crates/team-agent/src/cli/helpers.rs +0 -91
- package/crates/team-agent/src/cli/intent/runtime.rs +0 -1216
- package/crates/team-agent/src/cli/intent/runtime_tests.rs +0 -912
- package/crates/team-agent/src/cli/intent/tests.rs +0 -689
- package/crates/team-agent/src/cli/intent.rs +0 -664
- package/crates/team-agent/src/cli/leader.rs +0 -300
- package/crates/team-agent/src/cli/leader_prompt.rs +0 -261
- package/crates/team-agent/src/cli/leaders.rs +0 -418
- package/crates/team-agent/src/cli/mod.rs +0 -6545
- package/crates/team-agent/src/cli/models.rs +0 -1206
- package/crates/team-agent/src/cli/named_address.rs +0 -1651
- package/crates/team-agent/src/cli/profile.rs +0 -342
- package/crates/team-agent/src/cli/route.rs +0 -212
- package/crates/team-agent/src/cli/schedule.rs +0 -175
- package/crates/team-agent/src/cli/send/coordinator.rs +0 -164
- package/crates/team-agent/src/cli/send/mailbox.rs +0 -145
- package/crates/team-agent/src/cli/send/persist.rs +0 -156
- package/crates/team-agent/src/cli/send/presentation.rs +0 -370
- package/crates/team-agent/src/cli/send/resolve.rs +0 -573
- package/crates/team-agent/src/cli/send.rs +0 -199
- package/crates/team-agent/src/cli/shutdown_socket.rs +0 -288
- package/crates/team-agent/src/cli/spec.rs +0 -165
- package/crates/team-agent/src/cli/status.rs +0 -280
- package/crates/team-agent/src/cli/status_port/agents.rs +0 -358
- package/crates/team-agent/src/cli/status_port/approvals.rs +0 -79
- package/crates/team-agent/src/cli/status_port/brief.rs +0 -1981
- package/crates/team-agent/src/cli/status_port/compact.rs +0 -240
- package/crates/team-agent/src/cli/status_port/format.rs +0 -146
- package/crates/team-agent/src/cli/status_port/inbox.rs +0 -62
- package/crates/team-agent/src/cli/status_port/runtime.rs +0 -197
- package/crates/team-agent/src/cli/status_port/snapshot.rs +0 -208
- package/crates/team-agent/src/cli/status_port/store.rs +0 -416
- package/crates/team-agent/src/cli/status_port/tests.rs +0 -90
- package/crates/team-agent/src/cli/status_port.rs +0 -92
- package/crates/team-agent/src/cli/tests/base.rs +0 -885
- package/crates/team-agent/src/cli/tests/divergence.rs +0 -518
- package/crates/team-agent/src/cli/tests/lane_c.rs +0 -453
- package/crates/team-agent/src/cli/tests/leader_watch.rs +0 -322
- package/crates/team-agent/src/cli/tests/main_preserved.rs +0 -430
- package/crates/team-agent/src/cli/tests/missing_subcommands.rs +0 -336
- package/crates/team-agent/src/cli/tests/mod.rs +0 -137
- package/crates/team-agent/src/cli/tests/named_address.rs +0 -761
- package/crates/team-agent/src/cli/tests/parser_safety.rs +0 -383
- package/crates/team-agent/src/cli/tests/run_delegation.rs +0 -484
- package/crates/team-agent/src/cli/tests/shutdown_kill_plan.rs +0 -2179
- package/crates/team-agent/src/cli/tests/status_brief.rs +0 -1514
- package/crates/team-agent/src/cli/tests/status_send.rs +0 -888
- package/crates/team-agent/src/cli/tests/verb_install_skill.rs +0 -93
- package/crates/team-agent/src/cli/tests/verb_profile.rs +0 -392
- package/crates/team-agent/src/cli/triage.rs +0 -234
- package/crates/team-agent/src/cli/types.rs +0 -591
- package/crates/team-agent/src/codex_app_server.rs +0 -546
- package/crates/team-agent/src/communication_mode/mod.rs +0 -56
- package/crates/team-agent/src/compiler/tests.rs +0 -827
- package/crates/team-agent/src/compiler.rs +0 -890
- package/crates/team-agent/src/conpty/backend.rs +0 -829
- package/crates/team-agent/src/conpty/mod.rs +0 -33
- package/crates/team-agent/src/contract_runtime/backend.rs +0 -1744
- package/crates/team-agent/src/contract_runtime/commands.rs +0 -671
- package/crates/team-agent/src/contract_runtime/config.rs +0 -364
- package/crates/team-agent/src/contract_runtime/config_tests.rs +0 -76
- package/crates/team-agent/src/contract_runtime/discovery.rs +0 -449
- package/crates/team-agent/src/contract_runtime/fork.rs +0 -361
- package/crates/team-agent/src/contract_runtime/forward.rs +0 -288
- package/crates/team-agent/src/contract_runtime/framework.rs +0 -367
- package/crates/team-agent/src/contract_runtime/mcp.rs +0 -394
- package/crates/team-agent/src/contract_runtime/mod.rs +0 -17
- package/crates/team-agent/src/contract_runtime/prompt.rs +0 -216
- package/crates/team-agent/src/contract_runtime/pump.rs +0 -271
- package/crates/team-agent/src/contract_runtime/registry.rs +0 -553
- package/crates/team-agent/src/contract_runtime/workspace.rs +0 -228
- package/crates/team-agent/src/coordinator/backoff.rs +0 -741
- package/crates/team-agent/src/coordinator/conpty_shim.rs +0 -805
- package/crates/team-agent/src/coordinator/health.rs +0 -1185
- package/crates/team-agent/src/coordinator/mod.rs +0 -119
- package/crates/team-agent/src/coordinator/orphan.rs +0 -110
- package/crates/team-agent/src/coordinator/runtime_detectors.rs +0 -798
- package/crates/team-agent/src/coordinator/runtime_observation.rs +0 -84
- package/crates/team-agent/src/coordinator/steps/abnormal.rs +0 -2309
- package/crates/team-agent/src/coordinator/steps/delivery.rs +0 -15
- package/crates/team-agent/src/coordinator/steps/health_sync.rs +0 -15
- package/crates/team-agent/src/coordinator/steps/mod.rs +0 -126
- package/crates/team-agent/src/coordinator/steps/persist.rs +0 -15
- package/crates/team-agent/src/coordinator/steps/runtime_prompts.rs +0 -15
- package/crates/team-agent/src/coordinator/steps/session_gate.rs +0 -16
- package/crates/team-agent/src/coordinator/tests/a0_lostupdate.rs +0 -158
- package/crates/team-agent/src/coordinator/tests/abnormal.rs +0 -312
- package/crates/team-agent/src/coordinator/tests/api_error_recovery.rs +0 -300
- package/crates/team-agent/src/coordinator/tests/basics.rs +0 -211
- package/crates/team-agent/src/coordinator/tests/daemon.rs +0 -514
- package/crates/team-agent/src/coordinator/tests/energy.rs +0 -549
- package/crates/team-agent/src/coordinator/tests/health_sync.rs +0 -503
- package/crates/team-agent/src/coordinator/tests/main_preserved.rs +0 -186
- package/crates/team-agent/src/coordinator/tests/mod.rs +0 -295
- package/crates/team-agent/src/coordinator/tests/s3_bounded.rs +0 -207
- package/crates/team-agent/src/coordinator/tests/spine.rs +0 -308
- package/crates/team-agent/src/coordinator/tests/takeover.rs +0 -286
- package/crates/team-agent/src/coordinator/tests/tick_core.rs +0 -237
- package/crates/team-agent/src/coordinator/tick.rs +0 -3024
- package/crates/team-agent/src/coordinator/types.rs +0 -540
- package/crates/team-agent/src/db/agent_health_capture.rs +0 -126
- package/crates/team-agent/src/db/message_store.rs +0 -1527
- package/crates/team-agent/src/db/migration.rs +0 -984
- package/crates/team-agent/src/db/mod.rs +0 -26
- package/crates/team-agent/src/db/schema.rs +0 -663
- package/crates/team-agent/src/diagnose/comms.rs +0 -242
- package/crates/team-agent/src/diagnose/mod.rs +0 -44
- package/crates/team-agent/src/diagnose/orphans.rs +0 -889
- package/crates/team-agent/src/direct_delivery.rs +0 -368
- package/crates/team-agent/src/event_log.rs +0 -502
- package/crates/team-agent/src/fake_worker.rs +0 -303
- package/crates/team-agent/src/inbox_store.rs +0 -169
- package/crates/team-agent/src/kill_audit.rs +0 -106
- package/crates/team-agent/src/layout/manager.rs +0 -248
- package/crates/team-agent/src/layout/mod.rs +0 -36
- package/crates/team-agent/src/layout/overlay.rs +0 -134
- package/crates/team-agent/src/layout/placement.rs +0 -52
- package/crates/team-agent/src/layout/recovery.rs +0 -106
- package/crates/team-agent/src/layout/runtime_sessions.rs +0 -317
- package/crates/team-agent/src/layout/sessions.rs +0 -294
- package/crates/team-agent/src/layout/tmux_endpoint.rs +0 -165
- package/crates/team-agent/src/layout/worker_env.rs +0 -721
- package/crates/team-agent/src/layout/worker_window_helpers.rs +0 -37
- package/crates/team-agent/src/leader/helpers.rs +0 -178
- package/crates/team-agent/src/leader/incident.rs +0 -6
- package/crates/team-agent/src/leader/lease.rs +0 -3356
- package/crates/team-agent/src/leader/mod.rs +0 -104
- package/crates/team-agent/src/leader/owner_bind.rs +0 -400
- package/crates/team-agent/src/leader/prompt.rs +0 -905
- package/crates/team-agent/src/leader/provider_attribution.rs +0 -247
- package/crates/team-agent/src/leader/rediscover/tests.rs +0 -689
- package/crates/team-agent/src/leader/rediscover.rs +0 -1192
- package/crates/team-agent/src/leader/registry.rs +0 -888
- package/crates/team-agent/src/leader/start.rs +0 -4501
- package/crates/team-agent/src/leader/takeover.rs +0 -65
- package/crates/team-agent/src/leader/tests/basics.rs +0 -337
- package/crates/team-agent/src/leader/tests/byte_findings.rs +0 -355
- package/crates/team-agent/src/leader/tests/claim_leader_mailbox_flush_contract.rs +0 -544
- package/crates/team-agent/src/leader/tests/historical_inventory_upgrade_gate_red.rs +0 -624
- package/crates/team-agent/src/leader/tests/identity.rs +0 -465
- package/crates/team-agent/src/leader/tests/identity_session_names.rs +0 -42
- package/crates/team-agent/src/leader/tests/idle.rs +0 -113
- package/crates/team-agent/src/leader/tests/lease_api.rs +0 -520
- package/crates/team-agent/src/leader/tests/lease_claim.rs +0 -629
- package/crates/team-agent/src/leader/tests/mod.rs +0 -106
- package/crates/team-agent/src/leader/tests/prompt_contract.rs +0 -268
- package/crates/team-agent/src/leader/tests/rediscover.rs +0 -403
- package/crates/team-agent/src/leader/tests/rehomed_env.rs +0 -83
- package/crates/team-agent/src/leader/tests/team_in_team_state_scope_red.rs +0 -1273
- package/crates/team-agent/src/leader/tests/terminal_and_replay_vs_rerender_invariants_red.rs +0 -417
- package/crates/team-agent/src/leader/tests/wake_start_owner.rs +0 -168
- package/crates/team-agent/src/leader/types.rs +0 -534
- package/crates/team-agent/src/lib.rs +0 -147
- package/crates/team-agent/src/lifecycle/helpers.rs +0 -212
- package/crates/team-agent/src/lifecycle/launch/add_agent.rs +0 -881
- package/crates/team-agent/src/lifecycle/launch/add_agent_state.rs +0 -598
- package/crates/team-agent/src/lifecycle/launch/agent_state.rs +0 -332
- package/crates/team-agent/src/lifecycle/launch/clone_agent.rs +0 -204
- package/crates/team-agent/src/lifecycle/launch/fork_agent.rs +0 -107
- package/crates/team-agent/src/lifecycle/launch/fork_entry.rs +0 -144
- package/crates/team-agent/src/lifecycle/launch/identity.rs +0 -674
- package/crates/team-agent/src/lifecycle/launch/layout.rs +0 -350
- package/crates/team-agent/src/lifecycle/launch/leader_context.rs +0 -589
- package/crates/team-agent/src/lifecycle/launch/mcp_config.rs +0 -160
- package/crates/team-agent/src/lifecycle/launch/ownership.rs +0 -105
- package/crates/team-agent/src/lifecycle/launch/pi_mcp.rs +0 -899
- package/crates/team-agent/src/lifecycle/launch/pi_mcp_extension.js +0 -225
- package/crates/team-agent/src/lifecycle/launch/plan.rs +0 -269
- package/crates/team-agent/src/lifecycle/launch/quick_start.rs +0 -5200
- package/crates/team-agent/src/lifecycle/launch/quick_start_transport.rs +0 -368
- package/crates/team-agent/src/lifecycle/launch/readiness.rs +0 -519
- package/crates/team-agent/src/lifecycle/launch/role_source.rs +0 -287
- package/crates/team-agent/src/lifecycle/launch/spawn.rs +0 -473
- package/crates/team-agent/src/lifecycle/launch/spec_state.rs +0 -801
- package/crates/team-agent/src/lifecycle/launch/state_projection.rs +0 -624
- package/crates/team-agent/src/lifecycle/launch/worker_env.rs +0 -558
- package/crates/team-agent/src/lifecycle/launch.rs +0 -557
- package/crates/team-agent/src/lifecycle/lock.rs +0 -350
- package/crates/team-agent/src/lifecycle/mod.rs +0 -79
- package/crates/team-agent/src/lifecycle/pane_input_lock.rs +0 -239
- package/crates/team-agent/src/lifecycle/profile_launch.rs +0 -1067
- package/crates/team-agent/src/lifecycle/profile_smoke.rs +0 -557
- package/crates/team-agent/src/lifecycle/restart/agent.rs +0 -2199
- package/crates/team-agent/src/lifecycle/restart/avatar.rs +0 -1798
- package/crates/team-agent/src/lifecycle/restart/claude_fork.rs +0 -163
- package/crates/team-agent/src/lifecycle/restart/common.rs +0 -2362
- package/crates/team-agent/src/lifecycle/restart/orchestrator.rs +0 -65
- package/crates/team-agent/src/lifecycle/restart/preflight.rs +0 -113
- package/crates/team-agent/src/lifecycle/restart/rebuild.rs +0 -5135
- package/crates/team-agent/src/lifecycle/restart/remove.rs +0 -1504
- package/crates/team-agent/src/lifecycle/restart/selection.rs +0 -559
- package/crates/team-agent/src/lifecycle/restart/team_state.rs +0 -329
- package/crates/team-agent/src/lifecycle/restart.rs +0 -227
- package/crates/team-agent/src/lifecycle/role_config.rs +0 -1230
- package/crates/team-agent/src/lifecycle/tests/acceptance_b_batch_red.rs +0 -1021
- package/crates/team-agent/src/lifecycle/tests/agent_ops.rs +0 -1205
- package/crates/team-agent/src/lifecycle/tests/b0_legacy_snapshot_nonauthority_contract.rs +0 -265
- package/crates/team-agent/src/lifecycle/tests/b0_reader_hideone_audit_contract.rs +0 -490
- package/crates/team-agent/src/lifecycle/tests/behavioral_diff_264_red.rs +0 -656
- package/crates/team-agent/src/lifecycle/tests/claude_compatible_config_red.rs +0 -325
- package/crates/team-agent/src/lifecycle/tests/claude_profile_launch_red.rs +0 -447
- package/crates/team-agent/src/lifecycle/tests/cli_argv_routing_red.rs +0 -1638
- package/crates/team-agent/src/lifecycle/tests/clone_agent_preserves_source_tools.rs +0 -427
- package/crates/team-agent/src/lifecycle/tests/clone_fork_copilot_perms_red.rs +0 -770
- package/crates/team-agent/src/lifecycle/tests/communication_mode_runtime_contract_red.rs +0 -419
- package/crates/team-agent/src/lifecycle/tests/copilot_provider_red.rs +0 -2035
- package/crates/team-agent/src/lifecycle/tests/core.rs +0 -1327
- package/crates/team-agent/src/lifecycle/tests/f032_startup_prompt_best_effort_red.rs +0 -315
- package/crates/team-agent/src/lifecycle/tests/fixtures/pi_list_models_g0.stdout.txt +0 -222
- package/crates/team-agent/src/lifecycle/tests/fixtures/pi_list_models_spaced_ids.stdout.txt +0 -9
- package/crates/team-agent/src/lifecycle/tests/fixtures/pi_native_mcp_host.mjs +0 -72
- package/crates/team-agent/src/lifecycle/tests/gate_fixtures.rs +0 -562
- package/crates/team-agent/src/lifecycle/tests/grok_require_explicit_model_red.rs +0 -110
- package/crates/team-agent/src/lifecycle/tests/harvest2_a_batch_red.rs +0 -512
- package/crates/team-agent/src/lifecycle/tests/host_cotenant_death_p0_contract.rs +0 -921
- package/crates/team-agent/src/lifecycle/tests/issue238_codex_effort_contract.rs +0 -68
- package/crates/team-agent/src/lifecycle/tests/lane_ops.rs +0 -1851
- package/crates/team-agent/src/lifecycle/tests/launch_spawn.rs +0 -3983
- package/crates/team-agent/src/lifecycle/tests/lifecycle_lock.rs +0 -339
- package/crates/team-agent/src/lifecycle/tests/lifecycle_rollback_red.rs +0 -596
- package/crates/team-agent/src/lifecycle/tests/main_preserved.rs +0 -513
- package/crates/team-agent/src/lifecycle/tests/mcp_tool_name_format_red.rs +0 -69
- package/crates/team-agent/src/lifecycle/tests/phase_b_contracts.rs +0 -824
- package/crates/team-agent/src/lifecycle/tests/phase_golden.rs +0 -723
- package/crates/team-agent/src/lifecycle/tests/pi_catalog_red.rs +0 -164
- package/crates/team-agent/src/lifecycle/tests/pi_command_red.rs +0 -200
- package/crates/team-agent/src/lifecycle/tests/pi_compiler_red.rs +0 -210
- package/crates/team-agent/src/lifecycle/tests/pi_dual_entry_red.rs +0 -527
- package/crates/team-agent/src/lifecycle/tests/pi_executable_mcp_red.rs +0 -1062
- package/crates/team-agent/src/lifecycle/tests/pi_fork_session_inheritance_red.rs +0 -1419
- package/crates/team-agent/src/lifecycle/tests/pi_lifecycle_doctor_red.rs +0 -98
- package/crates/team-agent/src/lifecycle/tests/pi_native_mcp_capability_red.rs +0 -550
- package/crates/team-agent/src/lifecycle/tests/pi_session_delivery_red.rs +0 -226
- package/crates/team-agent/src/lifecycle/tests/quick_start_worker_readiness_red.rs +0 -332
- package/crates/team-agent/src/lifecycle/tests/realmachine_clusters_1_6_red.rs +0 -786
- package/crates/team-agent/src/lifecycle/tests/realmachine_residual_g1_g4_red.rs +0 -648
- package/crates/team-agent/src/lifecycle/tests/restart.rs +0 -185
- package/crates/team-agent/src/lifecycle/tests/restart_build_before_destroy_0540_contract.rs +0 -1053
- package/crates/team-agent/src/lifecycle/tests/restart_liveness_red.rs +0 -679
- package/crates/team-agent/src/lifecycle/tests/restart_rebind_hotfix_252_red.rs +0 -1126
- package/crates/team-agent/src/lifecycle/tests/restart_session_capture_red.rs +0 -153
- package/crates/team-agent/src/lifecycle/tests/resume_recover_red.rs +0 -427
- package/crates/team-agent/src/lifecycle/tests/stale_team_saveconflict_contract.rs +0 -431
- package/crates/team-agent/src/lifecycle/tests/startup_latency_contract.rs +0 -1066
- package/crates/team-agent/src/lifecycle/tests/status_credential_redaction_contract.rs +0 -876
- package/crates/team-agent/src/lifecycle/tests/subprep_codex_trust_roundtrip_red.rs +0 -1026
- package/crates/team-agent/src/lifecycle/tests/swallow_batch4_semantics_red.rs +0 -342
- package/crates/team-agent/src/lifecycle/tests/team_in_team_identity_scope_red.rs +0 -543
- package/crates/team-agent/src/lifecycle/tests/team_in_team_sibling_quick_start_red.rs +0 -1103
- package/crates/team-agent/src/lifecycle/tests/team_in_team_state_scope_red.rs +0 -1276
- package/crates/team-agent/src/lifecycle/tests/team_key_retirement_roster_red.rs +0 -145
- package/crates/team-agent/src/lifecycle/tests/team_key_retirement_txn_red.rs +0 -603
- package/crates/team-agent/src/lifecycle/tests/test_isolation_escape_contract.rs +0 -936
- package/crates/team-agent/src/lifecycle/tests/upgrade_compat_0211_red.rs +0 -970
- package/crates/team-agent/src/lifecycle/tests/verify_rs031_window_consistency_red.rs +0 -995
- package/crates/team-agent/src/lifecycle/tests/worker_spawn_env_red.rs +0 -836
- package/crates/team-agent/src/lifecycle/tests.rs +0 -105
- package/crates/team-agent/src/lifecycle/types.rs +0 -877
- package/crates/team-agent/src/lifecycle/worker_command_context.rs +0 -363
- package/crates/team-agent/src/main.rs +0 -52
- package/crates/team-agent/src/mcp_server/helpers.rs +0 -510
- package/crates/team-agent/src/mcp_server/lifecycle_tools/mod.rs +0 -6
- package/crates/team-agent/src/mcp_server/lifecycle_tools/state_status.rs +0 -43
- package/crates/team-agent/src/mcp_server/mod.rs +0 -119
- package/crates/team-agent/src/mcp_server/normalize.rs +0 -485
- package/crates/team-agent/src/mcp_server/readiness.rs +0 -527
- package/crates/team-agent/src/mcp_server/readiness_tests.rs +0 -348
- package/crates/team-agent/src/mcp_server/tests/golden.rs +0 -285
- package/crates/team-agent/src/mcp_server/tests/normalize.rs +0 -247
- package/crates/team-agent/src/mcp_server/tests/scoped.rs +0 -158
- package/crates/team-agent/src/mcp_server/tests/send.rs +0 -353
- package/crates/team-agent/src/mcp_server/tests/tools.rs +0 -341
- package/crates/team-agent/src/mcp_server/tests/wire.rs +0 -254
- package/crates/team-agent/src/mcp_server/tests.rs +0 -43
- package/crates/team-agent/src/mcp_server/tools.rs +0 -889
- package/crates/team-agent/src/mcp_server/types.rs +0 -396
- package/crates/team-agent/src/mcp_server/wire.rs +0 -867
- package/crates/team-agent/src/messaging/activity.rs +0 -461
- package/crates/team-agent/src/messaging/address.rs +0 -87
- package/crates/team-agent/src/messaging/delivery.rs +0 -3727
- package/crates/team-agent/src/messaging/delivery_consumption_tests.rs +0 -234
- package/crates/team-agent/src/messaging/enter_rescue.rs +0 -362
- package/crates/team-agent/src/messaging/enter_rescue_tests.rs +0 -633
- package/crates/team-agent/src/messaging/helpers.rs +0 -336
- package/crates/team-agent/src/messaging/leader_channel.rs +0 -287
- package/crates/team-agent/src/messaging/leader_receiver.rs +0 -786
- package/crates/team-agent/src/messaging/mod.rs +0 -167
- package/crates/team-agent/src/messaging/persist.rs +0 -377
- package/crates/team-agent/src/messaging/presentation.rs +0 -417
- package/crates/team-agent/src/messaging/reminders.rs +0 -316
- package/crates/team-agent/src/messaging/results/collection_tests.rs +0 -719
- package/crates/team-agent/src/messaging/results.rs +0 -1415
- package/crates/team-agent/src/messaging/scheduler.rs +0 -223
- package/crates/team-agent/src/messaging/selftest.rs +0 -315
- package/crates/team-agent/src/messaging/send.rs +0 -981
- package/crates/team-agent/src/messaging/tests/basic.rs +0 -346
- package/crates/team-agent/src/messaging/tests/dup_inject.rs +0 -657
- package/crates/team-agent/src/messaging/tests/e23.rs +0 -49
- package/crates/team-agent/src/messaging/tests/leader_channel.rs +0 -169
- package/crates/team-agent/src/messaging/tests/leader_inject_acceptance.rs +0 -817
- package/crates/team-agent/src/messaging/tests/main_preserved.rs +0 -85
- package/crates/team-agent/src/messaging/tests/mod.rs +0 -306
- package/crates/team-agent/src/messaging/tests/runtime.rs +0 -3549
- package/crates/team-agent/src/messaging/tests/spine.rs +0 -853
- package/crates/team-agent/src/messaging/tests/wave2.rs +0 -381
- package/crates/team-agent/src/messaging/trust.rs +0 -215
- package/crates/team-agent/src/messaging/types.rs +0 -472
- package/crates/team-agent/src/messaging/wait.rs +0 -366
- package/crates/team-agent/src/messaging/watchers.rs +0 -916
- package/crates/team-agent/src/model/enums.rs +0 -356
- package/crates/team-agent/src/model/errors.rs +0 -18
- package/crates/team-agent/src/model/ids.rs +0 -165
- package/crates/team-agent/src/model/mod.rs +0 -29
- package/crates/team-agent/src/model/name_similarity.rs +0 -252
- package/crates/team-agent/src/model/pane_authority_refusal.rs +0 -359
- package/crates/team-agent/src/model/paths.rs +0 -257
- package/crates/team-agent/src/model/routing.rs +0 -387
- package/crates/team-agent/src/model/spec.rs +0 -1184
- package/crates/team-agent/src/model/task_graph.rs +0 -321
- package/crates/team-agent/src/model/testdata/fuzz.golden.yaml +0 -43
- package/crates/team-agent/src/model/testdata/fuzz.yaml +0 -43
- package/crates/team-agent/src/model/testdata/spec_invalid_a.yaml +0 -209
- package/crates/team-agent/src/model/testdata/team.spec.golden.yaml +0 -208
- package/crates/team-agent/src/model/testdata/team.spec.yaml +0 -208
- package/crates/team-agent/src/model/yaml/tests.rs +0 -188
- package/crates/team-agent/src/model/yaml.rs +0 -802
- package/crates/team-agent/src/os_probe.rs +0 -280
- package/crates/team-agent/src/packaging/install.rs +0 -219
- package/crates/team-agent/src/packaging/migrate.rs +0 -38
- package/crates/team-agent/src/packaging/mod.rs +0 -91
- package/crates/team-agent/src/packaging/repair.rs +0 -33
- package/crates/team-agent/src/packaging/tests.rs +0 -822
- package/crates/team-agent/src/packaging/types.rs +0 -417
- package/crates/team-agent/src/platform/argv.rs +0 -331
- package/crates/team-agent/src/platform/errors.rs +0 -104
- package/crates/team-agent/src/platform/file_lock.rs +0 -279
- package/crates/team-agent/src/platform/mod.rs +0 -5
- package/crates/team-agent/src/platform/process.rs +0 -545
- package/crates/team-agent/src/provider/adapter.rs +0 -1150
- package/crates/team-agent/src/provider/adapters/claude.rs +0 -78
- package/crates/team-agent/src/provider/adapters/claude_fork.rs +0 -131
- package/crates/team-agent/src/provider/adapters/copilot.rs +0 -75
- package/crates/team-agent/src/provider/adapters/copilot_fork.rs +0 -307
- package/crates/team-agent/src/provider/adapters/fake.rs +0 -18
- package/crates/team-agent/src/provider/adapters/mod.rs +0 -30
- package/crates/team-agent/src/provider/adapters/pi.rs +0 -106
- package/crates/team-agent/src/provider/approvals/mod.rs +0 -3
- package/crates/team-agent/src/provider/approvals/parsing.rs +0 -586
- package/crates/team-agent/src/provider/approvals/runtime_prompts.rs +0 -205
- package/crates/team-agent/src/provider/argv_route.rs +0 -405
- package/crates/team-agent/src/provider/bypass_flags.rs +0 -116
- package/crates/team-agent/src/provider/classify.rs +0 -708
- package/crates/team-agent/src/provider/command_helpers.rs +0 -45
- package/crates/team-agent/src/provider/faults.rs +0 -165
- package/crates/team-agent/src/provider/helpers.rs +0 -52
- package/crates/team-agent/src/provider/mod.rs +0 -78
- package/crates/team-agent/src/provider/model_catalog.rs +0 -910
- package/crates/team-agent/src/provider/session/capture.rs +0 -2731
- package/crates/team-agent/src/provider/session/context_fork/claude.rs +0 -123
- package/crates/team-agent/src/provider/session/context_fork/outcome.rs +0 -172
- package/crates/team-agent/src/provider/session/context_fork.rs +0 -396
- package/crates/team-agent/src/provider/session/mod.rs +0 -36
- package/crates/team-agent/src/provider/session/resume.rs +0 -269
- package/crates/team-agent/src/provider/session_scan/claude.rs +0 -523
- package/crates/team-agent/src/provider/session_scan/common/tests.rs +0 -316
- package/crates/team-agent/src/provider/session_scan/common.rs +0 -654
- package/crates/team-agent/src/provider/session_scan/copilot.rs +0 -280
- package/crates/team-agent/src/provider/session_scan/pi.rs +0 -185
- package/crates/team-agent/src/provider/session_scan.rs +0 -71
- package/crates/team-agent/src/provider/startup_prompt.rs +0 -757
- package/crates/team-agent/src/provider/submit_now.rs +0 -71
- package/crates/team-agent/src/provider/testdata/copilot-ready-marker.txt +0 -5
- package/crates/team-agent/src/provider/testdata/copilot-trust-prompt.txt +0 -19
- package/crates/team-agent/src/provider/testdata/grok-models-authenticated.stdout +0 -9
- package/crates/team-agent/src/provider/testdata/grok-models-unauthenticated.stdout +0 -7
- package/crates/team-agent/src/provider/tests/adapter.rs +0 -441
- package/crates/team-agent/src/provider/tests/classify.rs +0 -148
- package/crates/team-agent/src/provider/tests/command_helpers.rs +0 -35
- package/crates/team-agent/src/provider/tests/copilot_fork.rs +0 -191
- package/crates/team-agent/src/provider/tests/faults.rs +0 -200
- package/crates/team-agent/src/provider/tests/idle.rs +0 -177
- package/crates/team-agent/src/provider/tests/wire.rs +0 -213
- package/crates/team-agent/src/provider/tests.rs +0 -32
- package/crates/team-agent/src/provider/types.rs +0 -529
- package/crates/team-agent/src/provider/wire.rs +0 -394
- package/crates/team-agent/src/redaction.rs +0 -259
- package/crates/team-agent/src/state/abnormal_watch/tests/mod.rs +0 -248
- package/crates/team-agent/src/state/abnormal_watch.rs +0 -144
- package/crates/team-agent/src/state/identity.rs +0 -914
- package/crates/team-agent/src/state/identity_keys.rs +0 -132
- package/crates/team-agent/src/state/mod.rs +0 -74
- package/crates/team-agent/src/state/owner_gate.rs +0 -482
- package/crates/team-agent/src/state/ownership.rs +0 -563
- package/crates/team-agent/src/state/paths.rs +0 -395
- package/crates/team-agent/src/state/persist.rs +0 -3811
- package/crates/team-agent/src/state/projection.rs +0 -1508
- package/crates/team-agent/src/state/repository/intent.rs +0 -14
- package/crates/team-agent/src/state/repository/tests.rs +0 -184
- package/crates/team-agent/src/state/repository.rs +0 -866
- package/crates/team-agent/src/state/selector.rs +0 -160
- package/crates/team-agent/src/state/testdata/state-rich.canonical.json +0 -133
- package/crates/team-agent/src/test_support/models_timeout_fixture.rs +0 -144
- package/crates/team-agent/src/tmux_backend/enter_rescue.rs +0 -325
- package/crates/team-agent/src/tmux_backend/enter_rescue_tests.rs +0 -432
- package/crates/team-agent/src/tmux_backend/native_input.rs +0 -513
- package/crates/team-agent/src/tmux_backend/native_input_tests.rs +0 -742
- package/crates/team-agent/src/tmux_backend/tests.rs +0 -4103
- package/crates/team-agent/src/tmux_backend.rs +0 -4492
- package/crates/team-agent/src/topology.rs +0 -537
- package/crates/team-agent/src/transport/enter_rescue.rs +0 -166
- package/crates/team-agent/src/transport/native_input.rs +0 -491
- package/crates/team-agent/src/transport/test_support.rs +0 -743
- package/crates/team-agent/src/transport/tests/behavior.rs +0 -326
- package/crates/team-agent/src/transport/tests/mod.rs +0 -194
- package/crates/team-agent/src/transport/tests/wire.rs +0 -574
- package/crates/team-agent/src/transport.rs +0 -1655
- package/crates/team-agent/src/transport_factory.rs +0 -819
|
@@ -1,881 +0,0 @@
|
|
|
1
|
-
//! ---
|
|
2
|
-
//! purpose: 动态角色文档加一席,失败按快照回滚;force 变体先摘旧席再加
|
|
3
|
-
//! contract:
|
|
4
|
-
//! provides:
|
|
5
|
-
//! - name: add_agent
|
|
6
|
-
//! what: 编译角色进 runtime spec 并起席,失败回滚 spec 与 state
|
|
7
|
-
//! - name: add_agent_force
|
|
8
|
-
//! what: 先快照并摘除同名旧席,再走正常加席,失败按快照恢复
|
|
9
|
-
//! - name: add_agent_with_transport_at_paths
|
|
10
|
-
//! what: 加席的实体实现,含 owner 门、重名拒绝、原子写 spec 与起席
|
|
11
|
-
//! depends:
|
|
12
|
-
//! - crate::lifecycle::lock
|
|
13
|
-
//! - crate::lifecycle::restart
|
|
14
|
-
//! - crate::lifecycle::restart::remove
|
|
15
|
-
//! - crate::compiler
|
|
16
|
-
//! - crate::state::selector
|
|
17
|
-
//! - crate::state::projection
|
|
18
|
-
//! - crate::state::persist
|
|
19
|
-
//! - crate::tmux_backend
|
|
20
|
-
//! boundary:
|
|
21
|
-
//! - 不拷贝外部角色文件进 team 目录,就地读取编译
|
|
22
|
-
//! - 起席一律走 restart 的 start_agent_at_paths,本文件不直接 spawn
|
|
23
|
-
//! - 回滚只恢复 spec 字节与 runtime state,不回收已 spawn 的 pane
|
|
24
|
-
//! maturity: wired
|
|
25
|
-
//! ---
|
|
26
|
-
use std::collections::{BTreeMap, BTreeSet};
|
|
27
|
-
use std::path::{Path, PathBuf};
|
|
28
|
-
use std::process::Command;
|
|
29
|
-
use std::time::{SystemTime, UNIX_EPOCH};
|
|
30
|
-
|
|
31
|
-
use crate::lifecycle::*;
|
|
32
|
-
use crate::model::enums::{AuthMode, PaneLiveness, Provider, ProviderEffort};
|
|
33
|
-
use crate::model::ids::AgentId;
|
|
34
|
-
use crate::model::yaml::{self, Value};
|
|
35
|
-
use crate::state::persist::load_runtime_state;
|
|
36
|
-
use crate::transport::{PaneId, SessionName, Target, Transport, WindowName};
|
|
37
|
-
|
|
38
|
-
use crate::lifecycle::lock::{acquire_agent_lifecycle_lock, LifecycleLockRequest};
|
|
39
|
-
|
|
40
|
-
use super::*;
|
|
41
|
-
|
|
42
|
-
struct AgentReservation {
|
|
43
|
-
workspace: PathBuf,
|
|
44
|
-
team_key: String,
|
|
45
|
-
agent_id: AgentId,
|
|
46
|
-
owner: String,
|
|
47
|
-
active: bool,
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
impl AgentReservation {
|
|
51
|
-
fn commit(mut self) {
|
|
52
|
-
self.active = false;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
impl Drop for AgentReservation {
|
|
57
|
-
fn drop(&mut self) {
|
|
58
|
-
if !self.active {
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
let request = LifecycleLockRequest {
|
|
62
|
-
workspace: &self.workspace,
|
|
63
|
-
operation: "agent-reservation-rollback",
|
|
64
|
-
team: Some(self.team_key.as_str()),
|
|
65
|
-
agent_id: Some(&self.agent_id),
|
|
66
|
-
};
|
|
67
|
-
let Ok(_lock) = acquire_agent_lifecycle_lock(request) else {
|
|
68
|
-
let _ = crate::event_log::EventLog::new(&self.workspace).write(
|
|
69
|
-
"lifecycle.clone_reservation_rollback_failed",
|
|
70
|
-
serde_json::json!({
|
|
71
|
-
"agent_id": self.agent_id.as_str(),
|
|
72
|
-
"reservation_owner": self.owner,
|
|
73
|
-
"reason": "lifecycle lock unavailable",
|
|
74
|
-
}),
|
|
75
|
-
);
|
|
76
|
-
return;
|
|
77
|
-
};
|
|
78
|
-
let result =
|
|
79
|
-
release_agent_reservation(&self.workspace, &self.team_key, &self.agent_id, &self.owner);
|
|
80
|
-
let _ = crate::event_log::EventLog::new(&self.workspace).write(
|
|
81
|
-
if result.is_ok() {
|
|
82
|
-
"lifecycle.clone_reservation_rolled_back"
|
|
83
|
-
} else {
|
|
84
|
-
"lifecycle.clone_reservation_rollback_failed"
|
|
85
|
-
},
|
|
86
|
-
serde_json::json!({
|
|
87
|
-
"agent_id": self.agent_id.as_str(),
|
|
88
|
-
"reservation_owner": self.owner,
|
|
89
|
-
"result": result.as_ref().err().map(ToString::to_string),
|
|
90
|
-
}),
|
|
91
|
-
);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
fn reserve_agent_slot(
|
|
96
|
-
workspace: &Path,
|
|
97
|
-
team: Option<&str>,
|
|
98
|
-
agent_id: &AgentId,
|
|
99
|
-
) -> Result<AgentReservation, LifecycleError> {
|
|
100
|
-
let state = crate::state::projection::select_runtime_state(workspace, team)
|
|
101
|
-
.map_err(|error| LifecycleError::TeamSelect(error.to_string()))?;
|
|
102
|
-
let team_key = team
|
|
103
|
-
.filter(|key| !key.is_empty())
|
|
104
|
-
.map(str::to_string)
|
|
105
|
-
.or_else(|| explicit_active_team_key(&state))
|
|
106
|
-
.unwrap_or_else(|| crate::state::projection::team_state_key(&state));
|
|
107
|
-
let owner = format!(
|
|
108
|
-
"{}-{}",
|
|
109
|
-
std::process::id(),
|
|
110
|
-
SystemTime::now()
|
|
111
|
-
.duration_since(UNIX_EPOCH)
|
|
112
|
-
.map_err(|error| LifecycleError::StatePersist(error.to_string()))?
|
|
113
|
-
.as_nanos()
|
|
114
|
-
);
|
|
115
|
-
let mut latest = crate::state::projection::select_runtime_state(workspace, Some(&team_key))
|
|
116
|
-
.map_err(|error| LifecycleError::TeamSelect(error.to_string()))?;
|
|
117
|
-
ensure_owner_allowed_for_state(&latest, Some(agent_id))?;
|
|
118
|
-
if runtime_agent_exists(&latest, agent_id) {
|
|
119
|
-
return Err(LifecycleError::RequirementUnmet(format!(
|
|
120
|
-
"agent id already exists: {agent_id}"
|
|
121
|
-
)));
|
|
122
|
-
}
|
|
123
|
-
latest
|
|
124
|
-
.as_object_mut()
|
|
125
|
-
.ok_or_else(|| LifecycleError::StatePersist("runtime state root is not an object".into()))?
|
|
126
|
-
.entry("agents")
|
|
127
|
-
.or_insert_with(|| serde_json::json!({}));
|
|
128
|
-
let agents = latest
|
|
129
|
-
.get_mut("agents")
|
|
130
|
-
.and_then(serde_json::Value::as_object_mut)
|
|
131
|
-
.ok_or_else(|| {
|
|
132
|
-
LifecycleError::StatePersist("runtime state agents is not an object".into())
|
|
133
|
-
})?;
|
|
134
|
-
agents.insert(
|
|
135
|
-
agent_id.as_str().to_string(),
|
|
136
|
-
serde_json::json!({
|
|
137
|
-
"agent_id": agent_id.as_str(),
|
|
138
|
-
"status": "reserved",
|
|
139
|
-
"reservation_owner": owner,
|
|
140
|
-
}),
|
|
141
|
-
);
|
|
142
|
-
save_launched_team_state_for_key(
|
|
143
|
-
workspace,
|
|
144
|
-
&latest,
|
|
145
|
-
Some(team_key.as_str()),
|
|
146
|
-
Some(agent_id.as_str()),
|
|
147
|
-
)?;
|
|
148
|
-
let _ = crate::event_log::EventLog::new(workspace).write(
|
|
149
|
-
"lifecycle.clone_reservation_acquired",
|
|
150
|
-
serde_json::json!({
|
|
151
|
-
"agent_id": agent_id.as_str(),
|
|
152
|
-
"reservation_owner": owner,
|
|
153
|
-
"team": team_key,
|
|
154
|
-
}),
|
|
155
|
-
);
|
|
156
|
-
Ok(AgentReservation {
|
|
157
|
-
workspace: workspace.to_path_buf(),
|
|
158
|
-
team_key,
|
|
159
|
-
agent_id: agent_id.clone(),
|
|
160
|
-
owner,
|
|
161
|
-
active: true,
|
|
162
|
-
})
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
fn release_agent_reservation(
|
|
166
|
-
workspace: &Path,
|
|
167
|
-
team_key: &str,
|
|
168
|
-
agent_id: &AgentId,
|
|
169
|
-
owner: &str,
|
|
170
|
-
) -> Result<(), LifecycleError> {
|
|
171
|
-
let mut state = crate::state::projection::select_runtime_state(workspace, Some(team_key))
|
|
172
|
-
.map_err(|error| LifecycleError::TeamSelect(error.to_string()))?;
|
|
173
|
-
let matches = state
|
|
174
|
-
.get("agents")
|
|
175
|
-
.and_then(|agents| agents.get(agent_id.as_str()))
|
|
176
|
-
.and_then(|agent| agent.get("reservation_owner"))
|
|
177
|
-
.and_then(serde_json::Value::as_str)
|
|
178
|
-
== Some(owner);
|
|
179
|
-
if !matches {
|
|
180
|
-
return Ok(());
|
|
181
|
-
}
|
|
182
|
-
state
|
|
183
|
-
.get_mut("agents")
|
|
184
|
-
.and_then(serde_json::Value::as_object_mut)
|
|
185
|
-
.ok_or_else(|| {
|
|
186
|
-
LifecycleError::StatePersist("runtime state agents is not an object".into())
|
|
187
|
-
})?
|
|
188
|
-
.remove(agent_id.as_str());
|
|
189
|
-
save_launched_team_state_for_key(workspace, &state, Some(team_key), Some(agent_id.as_str()))
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
/// ---
|
|
193
|
-
/// purpose: 加一席的默认入口,解析活跃 team、拿生命周期锁、路由到该 team 实际使用的 tmux socket
|
|
194
|
-
/// params:
|
|
195
|
-
/// role_file_path: 外部角色文档路径,就地读取不拷贝
|
|
196
|
-
/// open_display: 是否为新席开显示
|
|
197
|
-
/// returns: 新席的环境与启动模式
|
|
198
|
-
/// errors: 选不到 team 返回 TeamSelect,角色文件缺失或编译失败返回 Compile,重名返回 RequirementUnmet
|
|
199
|
-
/// contract_id: lifecycle.add_agent.entry
|
|
200
|
-
/// ---
|
|
201
|
-
/// `add_agent(workspace, agent_id, role_file_path, open_display, team)`
|
|
202
|
-
/// (`lifecycle/operations.py:143`)。动态 role doc 编译进 spec + 起 worker;失败**字节级回滚**
|
|
203
|
-
/// spec_yaml / workspace_state / **team_state.md** / role_file(Gap 15.11),每步发
|
|
204
|
-
/// `lifecycle.add_step_*` 事件(顺序被测试锁死)。
|
|
205
|
-
pub fn add_agent(
|
|
206
|
-
workspace: &Path,
|
|
207
|
-
agent_id: &AgentId,
|
|
208
|
-
role_file_path: &Path,
|
|
209
|
-
open_display: bool,
|
|
210
|
-
team: Option<&str>,
|
|
211
|
-
) -> Result<AddAgentReport, LifecycleError> {
|
|
212
|
-
let selected = match crate::state::selector::resolve_active_team(
|
|
213
|
-
workspace,
|
|
214
|
-
team,
|
|
215
|
-
crate::state::selector::SelectorMode::RequireSpec,
|
|
216
|
-
) {
|
|
217
|
-
Ok(selected) => selected,
|
|
218
|
-
Err(_) if workspace.join("TEAM.md").exists() => {
|
|
219
|
-
// TEAM.md lives in the run workspace. `team_workspace()` always walks
|
|
220
|
-
// to the parent and would spawn on a hash socket of the scratch parent.
|
|
221
|
-
// Use the idempotent run-workspace so persisted `tmux_endpoint` wins.
|
|
222
|
-
let run_workspace = crate::model::paths::canonical_run_workspace(workspace)
|
|
223
|
-
.map_err(|e| LifecycleError::StatePersist(e.to_string()))?;
|
|
224
|
-
let transport =
|
|
225
|
-
crate::lifecycle::restart::lifecycle_worker_tmux_backend_for_selected_state(
|
|
226
|
-
&run_workspace, team,
|
|
227
|
-
)
|
|
228
|
-
.unwrap_or_else(|_| {
|
|
229
|
-
crate::tmux_backend::TmuxBackend::for_workspace(&run_workspace)
|
|
230
|
-
});
|
|
231
|
-
return add_agent_with_transport(
|
|
232
|
-
workspace,
|
|
233
|
-
agent_id,
|
|
234
|
-
role_file_path,
|
|
235
|
-
open_display,
|
|
236
|
-
team,
|
|
237
|
-
&transport,
|
|
238
|
-
);
|
|
239
|
-
}
|
|
240
|
-
Err(error) => return Err(LifecycleError::TeamSelect(error.to_string())),
|
|
241
|
-
};
|
|
242
|
-
let lifecycle_lock = acquire_agent_lifecycle_lock(LifecycleLockRequest {
|
|
243
|
-
workspace: &selected.run_workspace,
|
|
244
|
-
operation: "add-agent",
|
|
245
|
-
team: Some(selected.team_key.as_str()),
|
|
246
|
-
agent_id: Some(agent_id),
|
|
247
|
-
})?;
|
|
248
|
-
let reservation = reserve_agent_slot(
|
|
249
|
-
&selected.run_workspace,
|
|
250
|
-
Some(selected.team_key.as_str()),
|
|
251
|
-
agent_id,
|
|
252
|
-
)?;
|
|
253
|
-
drop(lifecycle_lock);
|
|
254
|
-
// E5 §3:compile_team 要角色定义目录(team_dir),不是 spec 落点(spec_workspace=runtime)。
|
|
255
|
-
let team_dir = selected.team_dir;
|
|
256
|
-
// **0.3.24 add-agent socket drift fix**: route to the live team's persisted
|
|
257
|
-
// tmux endpoint (NOT the workspace-hash for_workspace socket). Without this,
|
|
258
|
-
// `add-agent` spawns into an orphan socket (e.g. `ta-<hash>/termclaud`) while
|
|
259
|
-
// the live team runs on its persisted default socket — the leader can't see
|
|
260
|
-
// the new window, state never registers, and the orphaned `claude` process
|
|
261
|
-
// floats forever (macmini repro: `demo-director` startup blocker).
|
|
262
|
-
let transport = crate::lifecycle::restart::lifecycle_worker_tmux_backend_for_selected_state(
|
|
263
|
-
&selected.run_workspace,
|
|
264
|
-
Some(selected.team_key.as_str()),
|
|
265
|
-
)
|
|
266
|
-
.unwrap_or_else(|_| crate::tmux_backend::TmuxBackend::for_workspace(&selected.run_workspace));
|
|
267
|
-
add_agent_with_transport_at_paths_reserved(
|
|
268
|
-
&selected.run_workspace,
|
|
269
|
-
&team_dir,
|
|
270
|
-
agent_id,
|
|
271
|
-
role_file_path,
|
|
272
|
-
open_display,
|
|
273
|
-
Some(selected.team_key.as_str()),
|
|
274
|
-
&transport,
|
|
275
|
-
Some(reservation),
|
|
276
|
-
false,
|
|
277
|
-
None,
|
|
278
|
-
)
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
/// ---
|
|
282
|
-
/// purpose: 强制重建一席,先快照旧席再摘除再加回
|
|
283
|
-
/// params:
|
|
284
|
-
/// force: 为假时直接退回普通 add_agent
|
|
285
|
-
/// returns: 新席的环境与启动模式
|
|
286
|
-
/// errors: 任一步失败都按快照恢复,恢复本身再出错时错误里附 rollback_errors
|
|
287
|
-
/// contract_id: lifecycle.add_agent.force_entry
|
|
288
|
-
/// ---
|
|
289
|
-
/// Reconcile a single existing/inconsistent seat, then reuse the normal add
|
|
290
|
-
/// path. The external role source is preserved by remove-agent ownership
|
|
291
|
-
/// checks, so this is a one-command force-recreate rather than a team restart.
|
|
292
|
-
pub fn add_agent_force(
|
|
293
|
-
workspace: &Path,
|
|
294
|
-
agent_id: &AgentId,
|
|
295
|
-
role_file_path: &Path,
|
|
296
|
-
open_display: bool,
|
|
297
|
-
team: Option<&str>,
|
|
298
|
-
force: bool,
|
|
299
|
-
) -> Result<AddAgentReport, LifecycleError> {
|
|
300
|
-
if !force {
|
|
301
|
-
return add_agent(workspace, agent_id, role_file_path, open_display, team);
|
|
302
|
-
}
|
|
303
|
-
let selected = crate::state::selector::resolve_active_team(
|
|
304
|
-
workspace,
|
|
305
|
-
team,
|
|
306
|
-
crate::state::selector::SelectorMode::RequireSpec,
|
|
307
|
-
)
|
|
308
|
-
.map_err(|error| LifecycleError::TeamSelect(error.to_string()))?;
|
|
309
|
-
let canonical_team_key = selected.team_key.clone();
|
|
310
|
-
let _lock = acquire_agent_lifecycle_lock(LifecycleLockRequest {
|
|
311
|
-
workspace: &selected.run_workspace,
|
|
312
|
-
operation: "add-agent-force",
|
|
313
|
-
team: Some(canonical_team_key.as_str()),
|
|
314
|
-
agent_id: Some(agent_id),
|
|
315
|
-
})?;
|
|
316
|
-
let transport = crate::lifecycle::restart::lifecycle_worker_tmux_backend_for_selected_state(
|
|
317
|
-
&selected.run_workspace,
|
|
318
|
-
Some(canonical_team_key.as_str()),
|
|
319
|
-
)
|
|
320
|
-
.unwrap_or_else(|_| crate::tmux_backend::TmuxBackend::for_workspace(&selected.run_workspace));
|
|
321
|
-
force_recreate_with_transport_locked(
|
|
322
|
-
&selected.run_workspace,
|
|
323
|
-
&selected.team_dir,
|
|
324
|
-
agent_id,
|
|
325
|
-
role_file_path,
|
|
326
|
-
open_display,
|
|
327
|
-
Some(canonical_team_key.as_str()),
|
|
328
|
-
&transport,
|
|
329
|
-
)
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
/// ---
|
|
333
|
-
/// purpose: 带注入 transport 的加席入口,归一 workspace 并拿锁后转实体实现
|
|
334
|
-
/// returns: 新席的环境与启动模式
|
|
335
|
-
/// errors: 归一 workspace 失败返回 StatePersist,其余透传
|
|
336
|
-
/// contract_id: lifecycle.add_agent.entry
|
|
337
|
-
/// ---
|
|
338
|
-
/// `add_agent` with an injected transport — after the recompile+write, wires the new worker spawn
|
|
339
|
-
/// (via start_agent_with_transport) + start_coordinator (rt-host-a sweep: recompiled but never spawned).
|
|
340
|
-
pub(crate) fn add_agent_with_transport(
|
|
341
|
-
workspace: &Path,
|
|
342
|
-
agent_id: &AgentId,
|
|
343
|
-
role_file_path: &Path,
|
|
344
|
-
open_display: bool,
|
|
345
|
-
team: Option<&str>,
|
|
346
|
-
transport: &dyn Transport,
|
|
347
|
-
) -> Result<AddAgentReport, LifecycleError> {
|
|
348
|
-
let run_workspace = crate::model::paths::canonical_run_workspace(workspace)
|
|
349
|
-
.map_err(|e| LifecycleError::StatePersist(e.to_string()))?;
|
|
350
|
-
let lifecycle_lock = acquire_agent_lifecycle_lock(LifecycleLockRequest {
|
|
351
|
-
workspace: &run_workspace,
|
|
352
|
-
operation: "add-agent",
|
|
353
|
-
team,
|
|
354
|
-
agent_id: Some(agent_id),
|
|
355
|
-
})?;
|
|
356
|
-
let reservation = reserve_agent_slot(&run_workspace, team, agent_id)?;
|
|
357
|
-
drop(lifecycle_lock);
|
|
358
|
-
add_agent_with_transport_at_paths_reserved(
|
|
359
|
-
&run_workspace,
|
|
360
|
-
workspace,
|
|
361
|
-
agent_id,
|
|
362
|
-
role_file_path,
|
|
363
|
-
open_display,
|
|
364
|
-
team,
|
|
365
|
-
transport,
|
|
366
|
-
Some(reservation),
|
|
367
|
-
false,
|
|
368
|
-
None,
|
|
369
|
-
)
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
/// ---
|
|
373
|
-
/// purpose: 带注入 transport 的强制重建入口
|
|
374
|
-
/// params:
|
|
375
|
-
/// force: 为假时退回普通 add_agent_with_transport
|
|
376
|
-
/// returns: 新席的环境与启动模式
|
|
377
|
-
/// errors: 归一 workspace 失败返回 StatePersist,其余透传
|
|
378
|
-
/// contract_id: lifecycle.add_agent.force_entry
|
|
379
|
-
/// ---
|
|
380
|
-
pub(crate) fn add_agent_with_transport_force(
|
|
381
|
-
workspace: &Path,
|
|
382
|
-
agent_id: &AgentId,
|
|
383
|
-
role_file_path: &Path,
|
|
384
|
-
open_display: bool,
|
|
385
|
-
team: Option<&str>,
|
|
386
|
-
force: bool,
|
|
387
|
-
transport: &dyn Transport,
|
|
388
|
-
) -> Result<AddAgentReport, LifecycleError> {
|
|
389
|
-
if !force {
|
|
390
|
-
return add_agent_with_transport(
|
|
391
|
-
workspace,
|
|
392
|
-
agent_id,
|
|
393
|
-
role_file_path,
|
|
394
|
-
open_display,
|
|
395
|
-
team,
|
|
396
|
-
transport,
|
|
397
|
-
);
|
|
398
|
-
}
|
|
399
|
-
let run_workspace = crate::model::paths::canonical_run_workspace(workspace)
|
|
400
|
-
.map_err(|error| LifecycleError::StatePersist(error.to_string()))?;
|
|
401
|
-
let _lock = acquire_agent_lifecycle_lock(LifecycleLockRequest {
|
|
402
|
-
workspace: &run_workspace,
|
|
403
|
-
operation: "add-agent-force",
|
|
404
|
-
team,
|
|
405
|
-
agent_id: Some(agent_id),
|
|
406
|
-
})?;
|
|
407
|
-
force_recreate_with_transport_locked(
|
|
408
|
-
&run_workspace,
|
|
409
|
-
workspace,
|
|
410
|
-
agent_id,
|
|
411
|
-
role_file_path,
|
|
412
|
-
open_display,
|
|
413
|
-
team,
|
|
414
|
-
transport,
|
|
415
|
-
)
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
/// ---
|
|
419
|
-
/// purpose: 已持锁状态下的强制重建,先校验替换源可用再消费旧席
|
|
420
|
-
/// returns: 新席报告;成功后还要过快照的一致性校验
|
|
421
|
-
/// errors: 角色文件不存在先行返回 Compile;摘除、加回或一致性校验失败时按快照恢复并返回错误
|
|
422
|
-
/// ---
|
|
423
|
-
pub(crate) fn force_recreate_with_transport_locked(
|
|
424
|
-
run_workspace: &Path,
|
|
425
|
-
team_dir: &Path,
|
|
426
|
-
agent_id: &AgentId,
|
|
427
|
-
role_file_path: &Path,
|
|
428
|
-
open_display: bool,
|
|
429
|
-
team: Option<&str>,
|
|
430
|
-
transport: &dyn Transport,
|
|
431
|
-
) -> Result<AddAgentReport, LifecycleError> {
|
|
432
|
-
// Reject an unusable replacement source before consuming the old seat.
|
|
433
|
-
// Deeper compile/spawn failures remain covered by the transaction snapshot.
|
|
434
|
-
if !role_file_path.exists() {
|
|
435
|
-
return Err(LifecycleError::Compile(format!(
|
|
436
|
-
"role file not found: {}",
|
|
437
|
-
role_file_path.display()
|
|
438
|
-
)));
|
|
439
|
-
}
|
|
440
|
-
let snapshot = crate::lifecycle::restart::remove::ForceRecreateSnapshot::capture(
|
|
441
|
-
run_workspace,
|
|
442
|
-
agent_id,
|
|
443
|
-
team,
|
|
444
|
-
transport,
|
|
445
|
-
)?;
|
|
446
|
-
let remove = crate::lifecycle::restart::remove::remove_agent_with_transport_locked(
|
|
447
|
-
run_workspace,
|
|
448
|
-
agent_id,
|
|
449
|
-
true,
|
|
450
|
-
true,
|
|
451
|
-
team,
|
|
452
|
-
transport,
|
|
453
|
-
);
|
|
454
|
-
if let Err(error) = remove {
|
|
455
|
-
let restore_errors = snapshot.restore(team, transport);
|
|
456
|
-
return force_recreate_rollback_error(agent_id, error, restore_errors);
|
|
457
|
-
}
|
|
458
|
-
let operation = add_agent_with_transport_at_paths_locked(
|
|
459
|
-
run_workspace,
|
|
460
|
-
team_dir,
|
|
461
|
-
agent_id,
|
|
462
|
-
role_file_path,
|
|
463
|
-
open_display,
|
|
464
|
-
team,
|
|
465
|
-
transport,
|
|
466
|
-
)
|
|
467
|
-
.and_then(|report| {
|
|
468
|
-
maybe_fail_force_recreate_after_spawn()?;
|
|
469
|
-
Ok(report)
|
|
470
|
-
})
|
|
471
|
-
.and_then(|report| {
|
|
472
|
-
snapshot.require_coherent(agent_id, team, transport)?;
|
|
473
|
-
Ok(report)
|
|
474
|
-
});
|
|
475
|
-
match operation {
|
|
476
|
-
Ok(report) => Ok(report),
|
|
477
|
-
Err(error) => {
|
|
478
|
-
let restore_errors = snapshot.restore_after_consumption(transport);
|
|
479
|
-
force_recreate_rollback_error(agent_id, error, restore_errors)
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
/// ---
|
|
485
|
-
/// purpose: 把原始错误与回滚过程中的错误合成一个对外错误
|
|
486
|
-
/// returns: 回滚干净时原样返回原始错误;否则包成 StatePersist 并附 rollback_errors
|
|
487
|
-
/// ---
|
|
488
|
-
pub(super) fn force_recreate_rollback_error<T>(
|
|
489
|
-
agent_id: &AgentId,
|
|
490
|
-
error: LifecycleError,
|
|
491
|
-
restore_errors: Vec<String>,
|
|
492
|
-
) -> Result<T, LifecycleError> {
|
|
493
|
-
if restore_errors.is_empty() {
|
|
494
|
-
Err(error)
|
|
495
|
-
} else {
|
|
496
|
-
Err(LifecycleError::StatePersist(format!(
|
|
497
|
-
"force-recreate failed for {agent_id}: {error}; rollback_errors={}",
|
|
498
|
-
restore_errors.join("|")
|
|
499
|
-
)))
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
/// ---
|
|
504
|
-
/// purpose: 测试用注入点,按环境变量在 spawn 之后制造一次失败
|
|
505
|
-
/// returns: 环境变量未设或为空时直接成功
|
|
506
|
-
/// errors: 设了非空值时返回 StatePersist
|
|
507
|
-
/// ---
|
|
508
|
-
pub(super) fn maybe_fail_force_recreate_after_spawn() -> Result<(), LifecycleError> {
|
|
509
|
-
let Ok(reason) = std::env::var("TEAM_AGENT_TEST_FAIL_FORCE_RECREATE_AFTER_SPAWN") else {
|
|
510
|
-
return Ok(());
|
|
511
|
-
};
|
|
512
|
-
if reason.is_empty() {
|
|
513
|
-
return Ok(());
|
|
514
|
-
}
|
|
515
|
-
Err(LifecycleError::StatePersist(format!(
|
|
516
|
-
"injected force-recreate failure after spawn: {reason}"
|
|
517
|
-
)))
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
/// ---
|
|
521
|
-
/// purpose: 加席的实体实现,含 owner 门、重名拒绝、重编译 spec 原子写、席位 state upsert 与起席
|
|
522
|
-
/// params:
|
|
523
|
-
/// run_workspace: 已归一的 run workspace
|
|
524
|
-
/// team_dir: 角色定义所在目录,编译 team 用它
|
|
525
|
-
/// returns: 新席的环境与启动模式
|
|
526
|
-
/// errors: owner 门不过或重名返回 RequirementUnmet,角色文件缺失或编译不一致返回 Compile,state 与 spawn 失败先回滚再透传原错
|
|
527
|
-
/// ---
|
|
528
|
-
pub(super) fn add_agent_with_transport_at_paths(
|
|
529
|
-
run_workspace: &Path,
|
|
530
|
-
team_dir: &Path,
|
|
531
|
-
agent_id: &AgentId,
|
|
532
|
-
role_file_path: &Path,
|
|
533
|
-
open_display: bool,
|
|
534
|
-
team: Option<&str>,
|
|
535
|
-
transport: &dyn Transport,
|
|
536
|
-
) -> Result<AddAgentReport, LifecycleError> {
|
|
537
|
-
add_agent_with_transport_at_paths_reserved(
|
|
538
|
-
run_workspace,
|
|
539
|
-
team_dir,
|
|
540
|
-
agent_id,
|
|
541
|
-
role_file_path,
|
|
542
|
-
open_display,
|
|
543
|
-
team,
|
|
544
|
-
transport,
|
|
545
|
-
None,
|
|
546
|
-
false,
|
|
547
|
-
None,
|
|
548
|
-
)
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
#[allow(clippy::too_many_arguments)]
|
|
552
|
-
pub(crate) fn add_agent_with_transport_at_paths_locked(
|
|
553
|
-
run_workspace: &Path,
|
|
554
|
-
team_dir: &Path,
|
|
555
|
-
agent_id: &AgentId,
|
|
556
|
-
role_file_path: &Path,
|
|
557
|
-
open_display: bool,
|
|
558
|
-
team: Option<&str>,
|
|
559
|
-
transport: &dyn Transport,
|
|
560
|
-
) -> Result<AddAgentReport, LifecycleError> {
|
|
561
|
-
add_agent_with_transport_at_paths_reserved(
|
|
562
|
-
run_workspace,
|
|
563
|
-
team_dir,
|
|
564
|
-
agent_id,
|
|
565
|
-
role_file_path,
|
|
566
|
-
open_display,
|
|
567
|
-
team,
|
|
568
|
-
transport,
|
|
569
|
-
None,
|
|
570
|
-
true,
|
|
571
|
-
None,
|
|
572
|
-
)
|
|
573
|
-
}
|
|
574
|
-
|
|
575
|
-
/// fork-agent's new seat under the held lifecycle lock: the ordinary add-agent
|
|
576
|
-
/// transaction (and rollback), whose first spawn natively forks `parent`.
|
|
577
|
-
#[allow(clippy::too_many_arguments)]
|
|
578
|
-
pub(crate) fn add_forked_agent_locked(
|
|
579
|
-
run_workspace: &Path,
|
|
580
|
-
team_dir: &Path,
|
|
581
|
-
agent_id: &AgentId,
|
|
582
|
-
role_file_path: &Path,
|
|
583
|
-
open_display: bool,
|
|
584
|
-
team: Option<&str>,
|
|
585
|
-
transport: &dyn Transport,
|
|
586
|
-
parent: &crate::provider::SessionId,
|
|
587
|
-
) -> Result<AddAgentReport, LifecycleError> {
|
|
588
|
-
add_agent_with_transport_at_paths_reserved(
|
|
589
|
-
run_workspace,
|
|
590
|
-
team_dir,
|
|
591
|
-
agent_id,
|
|
592
|
-
role_file_path,
|
|
593
|
-
open_display,
|
|
594
|
-
team,
|
|
595
|
-
transport,
|
|
596
|
-
None,
|
|
597
|
-
true,
|
|
598
|
-
Some(parent),
|
|
599
|
-
)
|
|
600
|
-
}
|
|
601
|
-
|
|
602
|
-
#[allow(clippy::too_many_arguments)]
|
|
603
|
-
fn add_agent_with_transport_at_paths_reserved(
|
|
604
|
-
run_workspace: &Path,
|
|
605
|
-
team_dir: &Path,
|
|
606
|
-
agent_id: &AgentId,
|
|
607
|
-
role_file_path: &Path,
|
|
608
|
-
open_display: bool,
|
|
609
|
-
team: Option<&str>,
|
|
610
|
-
transport: &dyn Transport,
|
|
611
|
-
reservation: Option<AgentReservation>,
|
|
612
|
-
lifecycle_lock_held: bool,
|
|
613
|
-
fork_parent: Option<&crate::provider::SessionId>,
|
|
614
|
-
) -> Result<AddAgentReport, LifecycleError> {
|
|
615
|
-
let runtime_state = crate::state::persist::load_runtime_state(run_workspace)
|
|
616
|
-
.map_err(|e| LifecycleError::StatePersist(e.to_string()))?;
|
|
617
|
-
let canonical_team_key = team
|
|
618
|
-
.filter(|key| !key.is_empty())
|
|
619
|
-
.map(str::to_string)
|
|
620
|
-
.or_else(|| explicit_active_team_key(&runtime_state))
|
|
621
|
-
.unwrap_or_else(|| crate::state::projection::team_state_key(&runtime_state));
|
|
622
|
-
let owner_state =
|
|
623
|
-
crate::state::projection::select_runtime_state(run_workspace, Some(&canonical_team_key))
|
|
624
|
-
.map_err(|e| LifecycleError::TeamSelect(e.to_string()))?;
|
|
625
|
-
ensure_owner_allowed_for_state(&owner_state, Some(agent_id))?;
|
|
626
|
-
if !role_file_path.exists() {
|
|
627
|
-
return Err(LifecycleError::Compile(format!(
|
|
628
|
-
"role file not found: {}",
|
|
629
|
-
role_file_path.display()
|
|
630
|
-
)));
|
|
631
|
-
}
|
|
632
|
-
let reservation_owned = reservation.as_ref().is_some_and(|reservation| {
|
|
633
|
-
owner_state
|
|
634
|
-
.get("agents")
|
|
635
|
-
.and_then(|agents| agents.get(agent_id.as_str()))
|
|
636
|
-
.and_then(|agent| agent.get("reservation_owner"))
|
|
637
|
-
.and_then(serde_json::Value::as_str)
|
|
638
|
-
== Some(reservation.owner.as_str())
|
|
639
|
-
});
|
|
640
|
-
if runtime_agent_exists(&owner_state, agent_id) && !reservation_owned {
|
|
641
|
-
return Err(LifecycleError::RequirementUnmet(format!(
|
|
642
|
-
"agent id already exists: {agent_id}"
|
|
643
|
-
)));
|
|
644
|
-
}
|
|
645
|
-
// E5 Bug1:不再 copy role 文件进 <team_dir>/agents(自拷贝 O_TRUNC 截断反模式)。
|
|
646
|
-
// 就地读外部 role 文档编译,注入 base team spec 的 agents/routing。role 文件留在原处。
|
|
647
|
-
let mut spec = crate::compiler::compile_team(team_dir)
|
|
648
|
-
.map_err(|e| LifecycleError::Compile(e.to_string()))?;
|
|
649
|
-
override_spec_workspace(&mut spec, run_workspace);
|
|
650
|
-
let workspace_s = spec
|
|
651
|
-
.get("team")
|
|
652
|
-
.and_then(|team| team.get("workspace"))
|
|
653
|
-
.and_then(Value::as_str)
|
|
654
|
-
.unwrap_or_else(|| team_dir.to_str().unwrap_or_default())
|
|
655
|
-
.to_string();
|
|
656
|
-
let team_meta = crate::compiler::read_front_matter(&team_dir.join("TEAM.md"))
|
|
657
|
-
.map(|(meta, _)| meta)
|
|
658
|
-
.unwrap_or(Value::Null);
|
|
659
|
-
let compiled = crate::compiler::compile_role_agent(role_file_path, &team_meta, &workspace_s)
|
|
660
|
-
.map_err(|e| LifecycleError::Compile(e.to_string()))?;
|
|
661
|
-
if compiled.id != agent_id.as_str() {
|
|
662
|
-
return Err(LifecycleError::Compile(format!(
|
|
663
|
-
"role file declares name '{}' but add-agent id is '{}'",
|
|
664
|
-
compiled.id, agent_id
|
|
665
|
-
)));
|
|
666
|
-
}
|
|
667
|
-
// The compiled spec carries a contract leaf's canonical id (`agent` → `cursor`).
|
|
668
|
-
#[cfg(unix)]
|
|
669
|
-
let contract_provider = compiled
|
|
670
|
-
.agent
|
|
671
|
-
.get("provider")
|
|
672
|
-
.and_then(Value::as_str)
|
|
673
|
-
.filter(|provider| crate::contract_runtime::registry::descriptor(provider).is_some())
|
|
674
|
-
.map(str::to_owned);
|
|
675
|
-
let compiled_agent = compiled.agent.clone();
|
|
676
|
-
inject_agent_into_spec(&mut spec, compiled_agent.clone(), &compiled.id)?;
|
|
677
|
-
// E5 spec 迁移:重编译的 spec 原子写到 .team/runtime/<team_key>/(不落用户目录 team_dir)。
|
|
678
|
-
let spec_path = crate::model::paths::runtime_spec_path(run_workspace, &canonical_team_key);
|
|
679
|
-
// E42 (0.3.24 P0): capture pre-write bytes for atomic rollback. If anything
|
|
680
|
-
// downstream of write_spec_atomic + upsert_agent_state_from_role + spawn
|
|
681
|
-
// fails, restore the prior bytes so the canonical spec / runtime state never
|
|
682
|
-
// get a half-written row that disagrees with what remove-agent can see.
|
|
683
|
-
let reservation_lock = if lifecycle_lock_held {
|
|
684
|
-
None
|
|
685
|
-
} else {
|
|
686
|
-
Some(acquire_agent_lifecycle_lock(LifecycleLockRequest {
|
|
687
|
-
workspace: run_workspace,
|
|
688
|
-
operation: "add-agent",
|
|
689
|
-
team,
|
|
690
|
-
agent_id: Some(agent_id),
|
|
691
|
-
})?)
|
|
692
|
-
};
|
|
693
|
-
let pre_spec_text = match std::fs::read_to_string(&spec_path) {
|
|
694
|
-
Ok(text) => Some(text),
|
|
695
|
-
Err(e) if e.kind() == std::io::ErrorKind::NotFound => None,
|
|
696
|
-
Err(e) => return Err(LifecycleError::StatePersist(format!("read spec: {e}"))),
|
|
697
|
-
};
|
|
698
|
-
// Merge against the latest runtime spec while holding only the short
|
|
699
|
-
// filesystem critical section. Role compilation happened before this lock;
|
|
700
|
-
// peer reservations therefore remain visible instead of being overwritten
|
|
701
|
-
// by a stale base-spec snapshot.
|
|
702
|
-
let mut latest_spec = pre_spec_text
|
|
703
|
-
.as_deref()
|
|
704
|
-
.and_then(|text| crate::model::yaml::loads(text).ok())
|
|
705
|
-
.unwrap_or(spec);
|
|
706
|
-
inject_agent_into_spec(&mut latest_spec, compiled_agent, &compiled.id)?;
|
|
707
|
-
write_spec_atomic(&spec_path, &latest_spec)?;
|
|
708
|
-
drop(reservation_lock);
|
|
709
|
-
#[cfg(unix)]
|
|
710
|
-
if let Some(provider) = contract_provider {
|
|
711
|
-
return add_contract_seat(
|
|
712
|
-
run_workspace,
|
|
713
|
-
team_dir,
|
|
714
|
-
&spec_path,
|
|
715
|
-
pre_spec_text.as_deref(),
|
|
716
|
-
&canonical_team_key,
|
|
717
|
-
agent_id,
|
|
718
|
-
&provider,
|
|
719
|
-
role_file_path,
|
|
720
|
-
reservation,
|
|
721
|
-
);
|
|
722
|
-
}
|
|
723
|
-
let (meta, _) = crate::compiler::read_front_matter(role_file_path)
|
|
724
|
-
.map_err(|e| LifecycleError::Compile(e.to_string()))?;
|
|
725
|
-
// upsert writes status="starting" (E42) — start_agent_at_paths::mark_agent_started
|
|
726
|
-
// promotes to "running" on Ok. If anything fails between here and the Ok
|
|
727
|
-
// return below, rollback restores the captured pre-bytes.
|
|
728
|
-
if let Err(error) = upsert_agent_state_from_role(
|
|
729
|
-
run_workspace,
|
|
730
|
-
&canonical_team_key,
|
|
731
|
-
agent_id,
|
|
732
|
-
&meta,
|
|
733
|
-
role_file_path,
|
|
734
|
-
fork_parent,
|
|
735
|
-
) {
|
|
736
|
-
rollback_add_agent_atomic(
|
|
737
|
-
run_workspace,
|
|
738
|
-
&spec_path,
|
|
739
|
-
pre_spec_text.as_deref(),
|
|
740
|
-
None,
|
|
741
|
-
Some(&canonical_team_key),
|
|
742
|
-
agent_id,
|
|
743
|
-
"state_upsert_failed",
|
|
744
|
-
);
|
|
745
|
-
return Err(error);
|
|
746
|
-
}
|
|
747
|
-
let started = match crate::lifecycle::restart::start_agent_at_paths(
|
|
748
|
-
run_workspace,
|
|
749
|
-
spec_path.parent().unwrap_or(team_dir),
|
|
750
|
-
agent_id,
|
|
751
|
-
false,
|
|
752
|
-
open_display,
|
|
753
|
-
true,
|
|
754
|
-
Some(&canonical_team_key),
|
|
755
|
-
transport,
|
|
756
|
-
) {
|
|
757
|
-
Ok(started) => started,
|
|
758
|
-
Err(error) => {
|
|
759
|
-
rollback_add_agent_atomic(
|
|
760
|
-
run_workspace,
|
|
761
|
-
&spec_path,
|
|
762
|
-
pre_spec_text.as_deref(),
|
|
763
|
-
None,
|
|
764
|
-
Some(&canonical_team_key),
|
|
765
|
-
agent_id,
|
|
766
|
-
"start_agent_failed",
|
|
767
|
-
);
|
|
768
|
-
return Err(error);
|
|
769
|
-
}
|
|
770
|
-
};
|
|
771
|
-
let (env, start_mode) = match started {
|
|
772
|
-
StartAgentOutcome::Running {
|
|
773
|
-
env, start_mode, ..
|
|
774
|
-
} => (env, start_mode),
|
|
775
|
-
StartAgentOutcome::Noop { .. } => {
|
|
776
|
-
rollback_add_agent_atomic(
|
|
777
|
-
run_workspace,
|
|
778
|
-
&spec_path,
|
|
779
|
-
pre_spec_text.as_deref(),
|
|
780
|
-
None,
|
|
781
|
-
Some(&canonical_team_key),
|
|
782
|
-
agent_id,
|
|
783
|
-
"start_agent_noop",
|
|
784
|
-
);
|
|
785
|
-
return Err(LifecycleError::RequirementUnmet(format!(
|
|
786
|
-
"start_agent.noop: newly added agent {agent_id} must spawn, not reuse a live window"
|
|
787
|
-
)));
|
|
788
|
-
}
|
|
789
|
-
StartAgentOutcome::Paused { .. } => {
|
|
790
|
-
rollback_add_agent_atomic(
|
|
791
|
-
run_workspace,
|
|
792
|
-
&spec_path,
|
|
793
|
-
pre_spec_text.as_deref(),
|
|
794
|
-
None,
|
|
795
|
-
Some(&canonical_team_key),
|
|
796
|
-
agent_id,
|
|
797
|
-
"added_agent_paused",
|
|
798
|
-
);
|
|
799
|
-
return Err(LifecycleError::RequirementUnmet(format!(
|
|
800
|
-
"added agent {agent_id} is paused"
|
|
801
|
-
)));
|
|
802
|
-
}
|
|
803
|
-
};
|
|
804
|
-
if let Some(reservation) = reservation {
|
|
805
|
-
reservation.commit();
|
|
806
|
-
}
|
|
807
|
-
Ok(AddAgentReport {
|
|
808
|
-
env,
|
|
809
|
-
start_mode,
|
|
810
|
-
role_file: role_file_path.to_path_buf(),
|
|
811
|
-
})
|
|
812
|
-
}
|
|
813
|
-
|
|
814
|
-
/// A contract seat starts in the native framework, never the legacy transport:
|
|
815
|
-
/// the seeded row is what the framework's start/publish path projects onto.
|
|
816
|
-
/// Its role must live in `<team_dir>/agents`, where the contract config reads.
|
|
817
|
-
#[cfg(unix)]
|
|
818
|
-
#[allow(clippy::too_many_arguments)]
|
|
819
|
-
fn add_contract_seat(
|
|
820
|
-
run_workspace: &Path,
|
|
821
|
-
team_dir: &Path,
|
|
822
|
-
spec_path: &Path,
|
|
823
|
-
pre_spec_text: Option<&str>,
|
|
824
|
-
team_key: &str,
|
|
825
|
-
agent_id: &AgentId,
|
|
826
|
-
provider: &str,
|
|
827
|
-
role_file_path: &Path,
|
|
828
|
-
reservation: Option<AgentReservation>,
|
|
829
|
-
) -> Result<AddAgentReport, LifecycleError> {
|
|
830
|
-
let rollback = |reason: &str| {
|
|
831
|
-
rollback_add_agent_atomic(
|
|
832
|
-
run_workspace,
|
|
833
|
-
spec_path,
|
|
834
|
-
pre_spec_text,
|
|
835
|
-
None,
|
|
836
|
-
Some(team_key),
|
|
837
|
-
agent_id,
|
|
838
|
-
reason,
|
|
839
|
-
)
|
|
840
|
-
};
|
|
841
|
-
let seed = serde_json::json!({
|
|
842
|
-
"agent_id": agent_id.as_str(), "provider": provider, "runtime_family": "contract",
|
|
843
|
-
"status": "starting", "contract_instance": null, "pane_id": null,
|
|
844
|
-
});
|
|
845
|
-
if let Err(error) = upsert_agent_entry(run_workspace, team_key, agent_id, seed) {
|
|
846
|
-
rollback("state_upsert_failed");
|
|
847
|
-
return Err(error);
|
|
848
|
-
}
|
|
849
|
-
let started = team_agent_contract::contract::types::SeatId::new(agent_id.as_str())
|
|
850
|
-
.map_err(|error| error.to_string())
|
|
851
|
-
.and_then(|seat| {
|
|
852
|
-
crate::contract_runtime::framework::start_new_seat(
|
|
853
|
-
run_workspace,
|
|
854
|
-
team_dir,
|
|
855
|
-
team_key,
|
|
856
|
-
&seat,
|
|
857
|
-
)
|
|
858
|
-
.map_err(|error| error.to_string())
|
|
859
|
-
});
|
|
860
|
-
if let Err(error) = started {
|
|
861
|
-
rollback("start_agent_failed");
|
|
862
|
-
return Err(LifecycleError::Provider(error));
|
|
863
|
-
}
|
|
864
|
-
let coordinator = crate::coordinator::start_coordinator_with_team(
|
|
865
|
-
&crate::coordinator::WorkspacePath::new(run_workspace.to_path_buf()),
|
|
866
|
-
Some(team_key),
|
|
867
|
-
)
|
|
868
|
-
.map_err(|error| LifecycleError::StatePersist(error.to_string()))?;
|
|
869
|
-
if let Some(reservation) = reservation {
|
|
870
|
-
reservation.commit();
|
|
871
|
-
}
|
|
872
|
-
Ok(AddAgentReport {
|
|
873
|
-
env: AgentActionEnvelope {
|
|
874
|
-
agent_id: agent_id.clone(),
|
|
875
|
-
state_file: crate::state::persist::runtime_state_path(run_workspace),
|
|
876
|
-
coordinator_started: coordinator.ok,
|
|
877
|
-
},
|
|
878
|
-
start_mode: StartMode::Fresh,
|
|
879
|
-
role_file: role_file_path.to_path_buf(),
|
|
880
|
-
})
|
|
881
|
-
}
|