@team-agent/installer 0.2.10 → 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 -83
- package/src/team_agent/coordinator/lifecycle.py +0 -363
- 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 -200
- package/src/team_agent/idle_takeover.py +0 -59
- package/src/team_agent/idle_takeover_wiring.py +0 -111
- 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 -254
- package/src/team_agent/messaging/delivery.py +0 -473
- 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 -457
- 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 -86
- 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 -1239
- 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 -143
- 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 -602
- 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,436 @@
|
|
|
1
|
+
//! coordinator 健康/身份 & 只读可观测面:metadata 身份原语 + coordinator 路径 + watch 实时流。
|
|
2
|
+
|
|
3
|
+
use std::io::{Read, Seek, SeekFrom};
|
|
4
|
+
use std::path::{Path, PathBuf};
|
|
5
|
+
use std::process::{Command, Stdio};
|
|
6
|
+
|
|
7
|
+
use serde_json::Value;
|
|
8
|
+
use thiserror::Error;
|
|
9
|
+
|
|
10
|
+
use crate::message_store::MessageStore;
|
|
11
|
+
|
|
12
|
+
use super::types::{
|
|
13
|
+
CoordinatorHealthStatus, CoordinatorMetadata, HealthReport, MetadataSource, Pid, SchemaError,
|
|
14
|
+
SchemaHealth, StartError, StartOutcome, StartReport, StopError, StopOutcome, StopReport,
|
|
15
|
+
WatchCursor, WorkspacePath, PROTOCOL_VERSION, ROTATION_MARKER,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// ===========================================================================
|
|
19
|
+
// coordinator daemon lifecycle (lifecycle.py:38-247).
|
|
20
|
+
// start_coordinator spawns the `team-agent coordinator --workspace <ws>` daemon subprocess;
|
|
21
|
+
// the actual spawn is the #[ignore] real-machine boundary, the idempotent decision is testable.
|
|
22
|
+
// ===========================================================================
|
|
23
|
+
|
|
24
|
+
/// `coordinator_health`(`lifecycle.py:38-46`):`running ∧ metadata_ok ∧ schema_ok` → typed report.
|
|
25
|
+
pub fn coordinator_health(workspace: &WorkspacePath) -> HealthReport {
|
|
26
|
+
let schema = message_store_schema_health(workspace);
|
|
27
|
+
let pid_path = coordinator_pid_path(workspace);
|
|
28
|
+
let pid = read_pid_file(&pid_path);
|
|
29
|
+
let status = match pid {
|
|
30
|
+
Some(pid) => match pid_is_running(pid) {
|
|
31
|
+
Ok(true) => CoordinatorHealthStatus::Running,
|
|
32
|
+
Ok(false) | Err(_) => CoordinatorHealthStatus::Stale,
|
|
33
|
+
},
|
|
34
|
+
None if pid_path.exists() => CoordinatorHealthStatus::InvalidPid,
|
|
35
|
+
None => CoordinatorHealthStatus::Missing,
|
|
36
|
+
};
|
|
37
|
+
let metadata = read_coordinator_metadata(workspace);
|
|
38
|
+
let metadata_ok = pid.is_some_and(|p| coordinator_metadata_ok(metadata.as_ref(), p));
|
|
39
|
+
let running = matches!(status, CoordinatorHealthStatus::Running);
|
|
40
|
+
HealthReport {
|
|
41
|
+
ok: running && metadata_ok && schema.ok,
|
|
42
|
+
status,
|
|
43
|
+
pid,
|
|
44
|
+
metadata,
|
|
45
|
+
metadata_ok,
|
|
46
|
+
schema,
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/// `start_coordinator`(`lifecycle.py:49-121`):幂等 — 已健康 no-op(AlreadyRunning);metadata 不兼容
|
|
51
|
+
/// 先 stop 再起;schema 不兼容拒启 + hint;否则 spawn `team-agent coordinator --workspace <ws>`。
|
|
52
|
+
pub fn start_coordinator(workspace: &WorkspacePath) -> Result<StartReport, StartError> {
|
|
53
|
+
let health = coordinator_health(workspace);
|
|
54
|
+
if health.ok {
|
|
55
|
+
return Ok(StartReport {
|
|
56
|
+
ok: true,
|
|
57
|
+
pid: health.pid,
|
|
58
|
+
status: StartOutcome::AlreadyRunning,
|
|
59
|
+
log: Some(coordinator_log_path(workspace)),
|
|
60
|
+
schema_error: None,
|
|
61
|
+
action: None,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
if !health.schema.ok {
|
|
65
|
+
return Ok(StartReport {
|
|
66
|
+
ok: false,
|
|
67
|
+
pid: health.pid,
|
|
68
|
+
status: StartOutcome::SchemaIncompatible,
|
|
69
|
+
log: None,
|
|
70
|
+
schema_error: health.schema.error,
|
|
71
|
+
action: health.schema.action,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
if health.pid.is_some() && !health.metadata_ok && health.metadata.is_some() {
|
|
75
|
+
match stop_coordinator(workspace) {
|
|
76
|
+
Ok(stop) if stop.ok => {}
|
|
77
|
+
Ok(_) | Err(_) => {
|
|
78
|
+
return Ok(StartReport {
|
|
79
|
+
ok: false,
|
|
80
|
+
pid: health.pid,
|
|
81
|
+
status: StartOutcome::RestartIncompatibleStopFailed,
|
|
82
|
+
log: None,
|
|
83
|
+
schema_error: None,
|
|
84
|
+
action: None,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
let runtime_dir = crate::model::paths::runtime_dir(workspace.as_path());
|
|
91
|
+
std::fs::create_dir_all(&runtime_dir)?;
|
|
92
|
+
let log_path = coordinator_log_path(workspace);
|
|
93
|
+
let log = std::fs::OpenOptions::new()
|
|
94
|
+
.create(true)
|
|
95
|
+
.append(true)
|
|
96
|
+
.open(&log_path)?;
|
|
97
|
+
let log_err = log.try_clone()?;
|
|
98
|
+
let child = Command::new(std::env::current_exe()?)
|
|
99
|
+
.args(["coordinator", "--workspace"])
|
|
100
|
+
.arg(workspace.as_path())
|
|
101
|
+
.stdin(Stdio::null())
|
|
102
|
+
.stdout(Stdio::from(log))
|
|
103
|
+
.stderr(Stdio::from(log_err))
|
|
104
|
+
.spawn()?;
|
|
105
|
+
let pid = Pid::new(child.id());
|
|
106
|
+
std::fs::write(coordinator_pid_path(workspace), pid.to_string())?;
|
|
107
|
+
write_coordinator_metadata(workspace, pid, MetadataSource::Start)?;
|
|
108
|
+
Ok(StartReport {
|
|
109
|
+
ok: true,
|
|
110
|
+
pid: Some(pid),
|
|
111
|
+
status: StartOutcome::Started,
|
|
112
|
+
log: Some(log_path),
|
|
113
|
+
schema_error: None,
|
|
114
|
+
action: None,
|
|
115
|
+
})
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/// `stop_coordinator`(`lifecycle.py:228-247`):SIGTERM pid + 清 pid/meta → typed report。
|
|
119
|
+
pub fn stop_coordinator(workspace: &WorkspacePath) -> Result<StopReport, StopError> {
|
|
120
|
+
let pid_path = coordinator_pid_path(workspace);
|
|
121
|
+
if !pid_path.exists() {
|
|
122
|
+
return Ok(StopReport {
|
|
123
|
+
ok: true,
|
|
124
|
+
status: StopOutcome::Missing,
|
|
125
|
+
pid: None,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
let Some(pid) = read_pid_file(&pid_path) else {
|
|
129
|
+
remove_file_if_exists(&pid_path)?;
|
|
130
|
+
remove_file_if_exists(&coordinator_meta_path(workspace))?;
|
|
131
|
+
return Ok(StopReport {
|
|
132
|
+
ok: true,
|
|
133
|
+
status: StopOutcome::InvalidPidRemoved,
|
|
134
|
+
pid: None,
|
|
135
|
+
});
|
|
136
|
+
};
|
|
137
|
+
let Ok(pid_t) = libc::pid_t::try_from(pid.get()) else {
|
|
138
|
+
return Ok(StopReport {
|
|
139
|
+
ok: false,
|
|
140
|
+
status: StopOutcome::KillFailed,
|
|
141
|
+
pid: Some(pid),
|
|
142
|
+
});
|
|
143
|
+
};
|
|
144
|
+
let rc = unsafe { libc::kill(pid_t, libc::SIGTERM) };
|
|
145
|
+
if rc != 0 {
|
|
146
|
+
return Ok(StopReport {
|
|
147
|
+
ok: false,
|
|
148
|
+
status: StopOutcome::KillFailed,
|
|
149
|
+
pid: Some(pid),
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
remove_file_if_exists(&pid_path)?;
|
|
153
|
+
remove_file_if_exists(&coordinator_meta_path(workspace))?;
|
|
154
|
+
Ok(StopReport {
|
|
155
|
+
ok: true,
|
|
156
|
+
status: StopOutcome::Stopped,
|
|
157
|
+
pid: Some(pid),
|
|
158
|
+
})
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// ===========================================================================
|
|
162
|
+
// metadata 身份原语(metadata.py)—— 自由函数面
|
|
163
|
+
// ===========================================================================
|
|
164
|
+
|
|
165
|
+
/// `pid_is_running`(`metadata.py:16-25`):`os.kill(pid, 0)` + `ps -o stat=` 查 zombie(Z* → 不算活)。
|
|
166
|
+
/// §10 fallible:进程探测 I/O 可失败 → Result。
|
|
167
|
+
pub fn pid_is_running(pid: Pid) -> Result<bool, std::io::Error> {
|
|
168
|
+
let Ok(pid_t) = libc::pid_t::try_from(pid.get()) else {
|
|
169
|
+
return Ok(false);
|
|
170
|
+
};
|
|
171
|
+
let signal_rc = unsafe { libc::kill(pid_t, 0) };
|
|
172
|
+
if signal_rc != 0 {
|
|
173
|
+
let err = std::io::Error::last_os_error();
|
|
174
|
+
return match err.raw_os_error() {
|
|
175
|
+
Some(libc::EPERM) | Some(libc::ESRCH) => Ok(false),
|
|
176
|
+
_ => Err(err),
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
let out = Command::new("ps")
|
|
180
|
+
.args(["-p", &pid.to_string(), "-o", "stat="])
|
|
181
|
+
.output()?;
|
|
182
|
+
if !out.status.success() {
|
|
183
|
+
return Ok(false);
|
|
184
|
+
}
|
|
185
|
+
let stat = String::from_utf8_lossy(&out.stdout).trim().to_string();
|
|
186
|
+
Ok(!stat.is_empty() && !stat.starts_with('Z'))
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/// `read_coordinator_metadata`(`metadata.py:28-34`)。读 `coordinator.json`;损坏/缺失/非 dict → `None`。
|
|
190
|
+
pub fn read_coordinator_metadata(workspace: &WorkspacePath) -> Option<CoordinatorMetadata> {
|
|
191
|
+
let text = std::fs::read_to_string(coordinator_meta_path(workspace)).ok()?;
|
|
192
|
+
serde_json::from_str(&text).ok()
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/// `coordinator_metadata_ok`(`metadata.py:37-43`):三元全等
|
|
196
|
+
/// `meta.pid == pid ∧ meta.protocol_version == PROTOCOL_VERSION ∧
|
|
197
|
+
/// meta.message_store_schema_version == SCHEMA_VERSION`。任一不符 → false(不静默继续旧 schema)。
|
|
198
|
+
pub fn coordinator_metadata_ok(metadata: Option<&CoordinatorMetadata>, pid: Pid) -> bool {
|
|
199
|
+
metadata.is_some_and(|m| {
|
|
200
|
+
m.pid == pid
|
|
201
|
+
&& m.protocol_version == PROTOCOL_VERSION
|
|
202
|
+
&& m.message_store_schema_version == crate::db::schema::SCHEMA_VERSION
|
|
203
|
+
})
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/// `write_coordinator_metadata`(`metadata.py:46-61`)。写 `coordinator.json`(pretty indent=2),
|
|
207
|
+
/// `updated_at = now(utc).isoformat()`。
|
|
208
|
+
pub fn write_coordinator_metadata(
|
|
209
|
+
workspace: &WorkspacePath,
|
|
210
|
+
pid: Pid,
|
|
211
|
+
source: MetadataSource,
|
|
212
|
+
) -> Result<(), std::io::Error> {
|
|
213
|
+
let path = coordinator_meta_path(workspace);
|
|
214
|
+
if let Some(parent) = path.parent() {
|
|
215
|
+
std::fs::create_dir_all(parent)?;
|
|
216
|
+
}
|
|
217
|
+
let metadata = CoordinatorMetadata {
|
|
218
|
+
pid,
|
|
219
|
+
protocol_version: PROTOCOL_VERSION,
|
|
220
|
+
message_store_schema_version: crate::db::schema::SCHEMA_VERSION,
|
|
221
|
+
source,
|
|
222
|
+
updated_at: chrono::Utc::now().to_rfc3339(),
|
|
223
|
+
};
|
|
224
|
+
let text = serde_json::to_string_pretty(&metadata)
|
|
225
|
+
.map_err(|e| std::io::Error::other(e.to_string()))?;
|
|
226
|
+
std::fs::write(path, text)
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
fn message_store_schema_health(workspace: &WorkspacePath) -> SchemaHealth {
|
|
230
|
+
match MessageStore::open(workspace.as_path()) {
|
|
231
|
+
Ok(_) => SchemaHealth {
|
|
232
|
+
ok: true,
|
|
233
|
+
schema_version: crate::db::schema::SCHEMA_VERSION,
|
|
234
|
+
error: None,
|
|
235
|
+
action: None,
|
|
236
|
+
},
|
|
237
|
+
Err(e) => SchemaHealth {
|
|
238
|
+
ok: false,
|
|
239
|
+
schema_version: crate::db::schema::SCHEMA_VERSION,
|
|
240
|
+
error: Some(SchemaError::InitFailed {
|
|
241
|
+
message: e.to_string(),
|
|
242
|
+
}),
|
|
243
|
+
action: Some("run team-agent repair-state --schema".to_string()),
|
|
244
|
+
},
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
fn read_pid_file(path: &Path) -> Option<Pid> {
|
|
249
|
+
let text = std::fs::read_to_string(path).ok()?;
|
|
250
|
+
let raw = text.trim().parse::<u32>().ok()?;
|
|
251
|
+
Some(Pid::new(raw))
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
fn remove_file_if_exists(path: &Path) -> Result<(), std::io::Error> {
|
|
255
|
+
match std::fs::remove_file(path) {
|
|
256
|
+
Ok(()) => Ok(()),
|
|
257
|
+
Err(e) if e.kind() == std::io::ErrorKind::NotFound => Ok(()),
|
|
258
|
+
Err(e) => Err(e),
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// ===========================================================================
|
|
263
|
+
// coordinator 路径(paths.py)
|
|
264
|
+
// ===========================================================================
|
|
265
|
+
|
|
266
|
+
/// `coordinator.pid` 路径(`paths.py:8`)= `runtime_dir(workspace)/coordinator.pid`。
|
|
267
|
+
pub fn coordinator_pid_path(workspace: &WorkspacePath) -> PathBuf {
|
|
268
|
+
crate::model::paths::runtime_dir(workspace.as_path()).join("coordinator.pid")
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/// `coordinator.json` 路径(`paths.py:12`)。
|
|
272
|
+
pub fn coordinator_meta_path(workspace: &WorkspacePath) -> PathBuf {
|
|
273
|
+
crate::model::paths::runtime_dir(workspace.as_path()).join("coordinator.json")
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/// `coordinator.log` 路径(`paths.py:16`)。
|
|
277
|
+
pub fn coordinator_log_path(workspace: &WorkspacePath) -> PathBuf {
|
|
278
|
+
crate::model::paths::runtime_dir(workspace.as_path()).join("coordinator.log")
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// ===========================================================================
|
|
282
|
+
// watch 实时流(watch/__init__.py)—— `team-agent watch`
|
|
283
|
+
// ===========================================================================
|
|
284
|
+
|
|
285
|
+
/// `collect_watch_lines`(`watch.py:40`)。tail events.jsonl(过滤 team)+ latest_results,
|
|
286
|
+
/// 渲染人类可读行;处理 log rotation(ROTATION_MARKER + offset 重置,不重放历史段)。
|
|
287
|
+
/// 推进 `cursor`。
|
|
288
|
+
pub fn collect_watch_lines(
|
|
289
|
+
workspace: &WorkspacePath,
|
|
290
|
+
cursor: &mut WatchCursor,
|
|
291
|
+
store: &MessageStore,
|
|
292
|
+
team: Option<&str>,
|
|
293
|
+
) -> Result<Vec<String>, WatchError> {
|
|
294
|
+
let _ = (store, team);
|
|
295
|
+
let logs = crate::model::paths::logs_dir(workspace.as_path());
|
|
296
|
+
let events_path = logs.join("events.jsonl");
|
|
297
|
+
let archive_path = logs.join("events.jsonl.1");
|
|
298
|
+
let archive_signature = file_signature(&archive_path)?;
|
|
299
|
+
let mut lines = Vec::new();
|
|
300
|
+
|
|
301
|
+
let size = std::fs::metadata(&events_path).map(|m| m.len()).unwrap_or(0);
|
|
302
|
+
let rotated = cursor.initialized
|
|
303
|
+
&& (cursor.archive_signature != archive_signature || cursor.event_offset > size);
|
|
304
|
+
if rotated {
|
|
305
|
+
lines.push(ROTATION_MARKER.to_string());
|
|
306
|
+
cursor.event_offset = 0;
|
|
307
|
+
}
|
|
308
|
+
cursor.archive_signature = archive_signature;
|
|
309
|
+
|
|
310
|
+
let mut file = match std::fs::File::open(&events_path) {
|
|
311
|
+
Ok(file) => file,
|
|
312
|
+
Err(e) if e.kind() == std::io::ErrorKind::NotFound => {
|
|
313
|
+
cursor.initialized = true;
|
|
314
|
+
return Ok(lines);
|
|
315
|
+
}
|
|
316
|
+
Err(e) => return Err(WatchError::Io(e)),
|
|
317
|
+
};
|
|
318
|
+
file.seek(SeekFrom::Start(cursor.event_offset))?;
|
|
319
|
+
let mut text = String::new();
|
|
320
|
+
file.read_to_string(&mut text)?;
|
|
321
|
+
cursor.event_offset = file.stream_position()?;
|
|
322
|
+
cursor.initialized = true;
|
|
323
|
+
for line in text.lines() {
|
|
324
|
+
if let Ok(event) = serde_json::from_str::<Value>(line) {
|
|
325
|
+
if let Some(rendered) = render_event_line(&event) {
|
|
326
|
+
lines.push(rendered);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
Ok(lines)
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/// `render_event_line`(`watch.py:46-63`)。把一条 step 4 事件渲染成人类可读行;非可渲染事件 → `None`。
|
|
334
|
+
/// 消费的事件类型:`result_received` / `leader_receiver.{injected,submitted}` / `send.failed` /
|
|
335
|
+
/// `leader_receiver.rebind_required` / `leader.api_error`(card 表)。
|
|
336
|
+
pub fn render_event_line(event: &Value) -> Option<String> {
|
|
337
|
+
let event_name = event.get("event").and_then(Value::as_str)?;
|
|
338
|
+
match event_name {
|
|
339
|
+
"result_received" => Some(format!(
|
|
340
|
+
"result_received: {} -> {}",
|
|
341
|
+
clean_field(event, &["agent_id"], "-"),
|
|
342
|
+
prefix_chars(&clean_field(event, &["summary"], "-"), 80)
|
|
343
|
+
)),
|
|
344
|
+
"leader_receiver.injected" | "leader_receiver.submitted" => {
|
|
345
|
+
let id = first_field(event, &["message_id", "msg_id"]).unwrap_or("-");
|
|
346
|
+
let id = prefix_chars(id, 12);
|
|
347
|
+
Some(format!(
|
|
348
|
+
"leader_receiver.injected: {} -> {}",
|
|
349
|
+
id,
|
|
350
|
+
clean_field(event, &["recipient", "to"], "-")
|
|
351
|
+
))
|
|
352
|
+
}
|
|
353
|
+
"send.failed" => Some(format!(
|
|
354
|
+
"send.failed: {} reason={}",
|
|
355
|
+
clean_field(event, &["recipient", "to", "target"], "-"),
|
|
356
|
+
clean_field(event, &["reason", "error"], "-")
|
|
357
|
+
)),
|
|
358
|
+
"leader_receiver.rebind_required" => Some(format!(
|
|
359
|
+
"leader_receiver.rebind_required: pane={} reason={}",
|
|
360
|
+
clean_field(event, &["old_pane_id", "pane_id", "target"], "-"),
|
|
361
|
+
clean_field(event, &["reason", "rediscovery_status"], "-")
|
|
362
|
+
)),
|
|
363
|
+
"leader.api_error" => Some(format!(
|
|
364
|
+
"leader.api_error: {} provider={} snippet={}",
|
|
365
|
+
clean_field(event, &["error_class"], "Unknown"),
|
|
366
|
+
clean_field(event, &["provider"], "-"),
|
|
367
|
+
clean_field(event, &["matched_pattern_snippet", "snippet"], "-")
|
|
368
|
+
)),
|
|
369
|
+
_ => None,
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/// `run_watch`(`watch.py:25`)。`team-agent watch` 主循环:反复 `collect_watch_lines` + 输出 + sleep。
|
|
374
|
+
/// `output`/`sleep` 注入便于测试。§10 返 Result。
|
|
375
|
+
pub fn run_watch(
|
|
376
|
+
workspace: &WorkspacePath,
|
|
377
|
+
team: Option<&str>,
|
|
378
|
+
interval_sec: f64,
|
|
379
|
+
output: &mut dyn FnMut(&str),
|
|
380
|
+
) -> Result<(), WatchError> {
|
|
381
|
+
let store = MessageStore::open(workspace.as_path())?;
|
|
382
|
+
let mut cursor = WatchCursor::default();
|
|
383
|
+
let interval = if interval_sec.is_finite() && interval_sec > 0.0 {
|
|
384
|
+
std::time::Duration::from_secs_f64(interval_sec)
|
|
385
|
+
} else {
|
|
386
|
+
std::time::Duration::from_millis(100)
|
|
387
|
+
};
|
|
388
|
+
loop {
|
|
389
|
+
for line in collect_watch_lines(workspace, &mut cursor, &store, team)? {
|
|
390
|
+
output(&line);
|
|
391
|
+
}
|
|
392
|
+
std::thread::sleep(interval);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/// watch 错误(读 events.jsonl / latest_results)。
|
|
397
|
+
#[derive(Debug, Error)]
|
|
398
|
+
pub enum WatchError {
|
|
399
|
+
#[error("io: {0}")]
|
|
400
|
+
Io(#[from] std::io::Error),
|
|
401
|
+
#[error("message store: {0}")]
|
|
402
|
+
MessageStore(#[from] crate::message_store::MessageStoreError),
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
fn file_signature(path: &Path) -> Result<Option<(u64, i128)>, WatchError> {
|
|
406
|
+
let meta = match std::fs::metadata(path) {
|
|
407
|
+
Ok(meta) => meta,
|
|
408
|
+
Err(e) if e.kind() == std::io::ErrorKind::NotFound => return Ok(None),
|
|
409
|
+
Err(e) => return Err(WatchError::Io(e)),
|
|
410
|
+
};
|
|
411
|
+
let modified = meta.modified().ok();
|
|
412
|
+
let nanos = modified
|
|
413
|
+
.and_then(|t| t.duration_since(std::time::UNIX_EPOCH).ok())
|
|
414
|
+
.and_then(|d| i128::try_from(d.as_nanos()).ok())
|
|
415
|
+
.unwrap_or(0);
|
|
416
|
+
Ok(Some((meta.len(), nanos)))
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
fn first_field<'a>(event: &'a Value, keys: &[&str]) -> Option<&'a str> {
|
|
420
|
+
keys.iter().find_map(|key| event.get(*key).and_then(Value::as_str))
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
fn clean_field(event: &Value, keys: &[&str], default: &str) -> String {
|
|
424
|
+
first_field(event, keys)
|
|
425
|
+
.map(clean_text)
|
|
426
|
+
.filter(|s| !s.is_empty())
|
|
427
|
+
.unwrap_or_else(|| default.to_string())
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
fn clean_text(text: &str) -> String {
|
|
431
|
+
text.split_whitespace().collect::<Vec<_>>().join(" ")
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
fn prefix_chars(text: &str, max: usize) -> String {
|
|
435
|
+
text.chars().take(max).collect()
|
|
436
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
//! step 12 · coordinator — daemon lifecycle / single-tick orchestration SKELETON (ROUND-0).
|
|
2
|
+
//!
|
|
3
|
+
//! Card: `docs/phase0/subsystems/12-coordinator.md`.
|
|
4
|
+
//! Truth source (READ-ONLY snapshot `team-agent-public` @ v0.2.11 / `439bef8`):
|
|
5
|
+
//! - `coordinator/__init__.py` (public re-export face; lazy `main` to break import cycle)
|
|
6
|
+
//! - `coordinator/__main__.py` (daemon main loop: pid/meta write, SIGTERM→STOP,
|
|
7
|
+
//! orphan self-detect, catch-all + exponential backoff 5→60s, tick_error dedupe/suppress,
|
|
8
|
+
//! tick_recovered)
|
|
9
|
+
//! - `coordinator/lifecycle.py` (health / start / stop / tick orchestration + schema health)
|
|
10
|
+
//! - `coordinator/metadata.py` (COORDINATOR_PROTOCOL_VERSION=2, pid_is_running, read/write/ok meta)
|
|
11
|
+
//! - `coordinator/paths.py` (coordinator.pid / coordinator.json / coordinator.log paths)
|
|
12
|
+
//! - `watch/__init__.py` (run_watch / collect_watch_lines / render_event_line / WatchCursor)
|
|
13
|
+
//! - `abnormal_track.py` (Gap 32 §4 provider-neutral abnormal track:
|
|
14
|
+
//! process_abnormal_records / detect_whole_team_gone)
|
|
15
|
+
//!
|
|
16
|
+
//! 职责(card §职责):per-workspace daemon 生命周期 + 单次 tick 编排。tick 按固定顺序把
|
|
17
|
+
//! step 8-11 的原子操作串成一个只读 + 投递既定 obligation 的回路 —— **绝不**在无 pending
|
|
18
|
+
//! obligation 时注入探索性 prompt(§10 MUST-NOT-13 / §84)。
|
|
19
|
+
//!
|
|
20
|
+
//! 铁律(card §bug/陷阱):
|
|
21
|
+
//! - **bug-084**:tick-end `save_runtime_state` 失败 → degraded `TickReport{ok:false,
|
|
22
|
+
//! reason:PersistenceDegraded, persisted:false}` + `runtime.state.save_failed` 事件,**绝不 panic**;
|
|
23
|
+
//! 主循环 catch + 指数退避 5→10→20→40→60→60s + 去重/抑制 tick_error。
|
|
24
|
+
//! - **bug-085 / unknown≠idle**:`TurnState::Unknown` 显式 block ping(穷尽 match,无 fallthrough);
|
|
25
|
+
//! `rollout_path` 用 `Option<RolloutPath>`;长期 unknown 第 60 tick 起每 12 tick
|
|
26
|
+
//! 发 `idle_takeover.unknown_persistent`。
|
|
27
|
+
//! - **take-over arm 来自真实投递**:监视器只能由真实 leader→worker 投递的 turn-open edge arm,
|
|
28
|
+
//! 绝不凭空 arm;无投递的队 → `not_armed_no_worker_turn`,绝不 ping。
|
|
29
|
+
//! - **schema 兼容门**:metadata 三元(pid/protocol_version/message_store_schema_version)任一不匹配
|
|
30
|
+
//! → restart_incompatible 先 stop 再起,**不可静默继续**用旧 schema 写库;区分 pre-init 必需列
|
|
31
|
+
//! (拒启)vs migratable 列(可迁移)。
|
|
32
|
+
//! - **孤儿不退 SIGTERM**:必须 SIGKILL 升级,优先按 pgid 杀整组。
|
|
33
|
+
//! - **孤儿自终止**:仅 `current_ppid != initial_ppid ∧ current_ppid == 1 ∧ workspace 不存在`
|
|
34
|
+
//! 三者同时成立才自杀。
|
|
35
|
+
//! - **§84 零注入**:无 pending obligation + event 时绝不注入探索性 prompt;compaction/drift/
|
|
36
|
+
//! api-error/idle 探测都是只读分类;唯一会投递的 `push_idle_reminder` 也只在 `should_ping` 时
|
|
37
|
+
//! 发一条中立 ack 提示。
|
|
38
|
+
//! - **整队消失区分 clean vs unexpected**:clean_shutdown/restart_in_progress 静默,
|
|
39
|
+
//! 仅 unexpected exit 写 durable marker + 延迟到下条 leader 命令再 escalate。
|
|
40
|
+
//! - **abnormal track 不读屏/不命名 provider**:只消费结构化 fault fact + 进程身份;
|
|
41
|
+
//! `(signature, turn_id)` 去重,turn_id 缺失退化为 per-record fingerprint 桶。
|
|
42
|
+
//! - **watch rotation**:archive_signature 变化或 offset>size 即插 ROTATION_MARKER 并重置 offset,
|
|
43
|
+
//! 不重放历史段。
|
|
44
|
+
//!
|
|
45
|
+
//! ROUND-0:仅类型 + struct/enum + fn/trait/method 签名。所有 body =
|
|
46
|
+
//! `unimplemented!("step12 port: <what>")`。fallible 路径返 `Result`/`Option`(§10 实现层禁
|
|
47
|
+
//! unwrap/expect/panic,签名先做成 fallible)。daemon-path `tick(..) -> Result<TickReport, TickError>`。
|
|
48
|
+
//! `#![deny(...)]` 由 leader 在集成时统一加,本骨架不加。
|
|
49
|
+
|
|
50
|
+
// ROUND-0 skeleton:fn body 全 unimplemented!() → import/field/method 暂未被用;P2 porter 落实现时移除。
|
|
51
|
+
#![allow(dead_code, unused_imports)]
|
|
52
|
+
// §10:daemon-path(tick/abnormal/health)实现层禁 unwrap/expect/panic(unimplemented!() stub 不被拦);
|
|
53
|
+
// tests 子模块各自 allow。bug-084:tick-end persist 失败走 degraded TickReport,绝不 panic。
|
|
54
|
+
#![deny(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
|
|
55
|
+
|
|
56
|
+
// ── module-root REUSE imports ─────────────────────────────────────────────
|
|
57
|
+
// decompose 前这些 `use` 在 coordinator.rs 顶层,测试 `mod tests` 经 `use super::*`
|
|
58
|
+
// 继承它们。拆分后保留在 mod.rs(私有 use,子模块 tests 仍经 `use super::*` 解析)。
|
|
59
|
+
use crate::message_store::MessageStore;
|
|
60
|
+
use crate::model::enums::Provider;
|
|
61
|
+
use crate::provider::{ProviderAdapter, TurnId, TurnState};
|
|
62
|
+
use serde_json::Value;
|
|
63
|
+
|
|
64
|
+
pub mod backoff;
|
|
65
|
+
pub mod health;
|
|
66
|
+
pub mod orphan;
|
|
67
|
+
pub mod tick;
|
|
68
|
+
pub mod types;
|
|
69
|
+
|
|
70
|
+
// ── Re-export the full module-root surface (RE-EXPORT INVARIANT) ──────────────
|
|
71
|
+
// 这些 `pub use`/`pub(crate) use` 把每个曾在 module 根可见的 item 重新 surface 到
|
|
72
|
+
// `crate::coordinator::X`,使外部 crate 路径 + 测试 `use super::*` 解析保持不变。
|
|
73
|
+
pub use types::*;
|
|
74
|
+
pub use tick::*;
|
|
75
|
+
pub use backoff::*;
|
|
76
|
+
pub use orphan::*;
|
|
77
|
+
pub use health::*;
|
|
78
|
+
|
|
79
|
+
#[cfg(test)]
|
|
80
|
+
mod tests;
|