@team-agent/installer 0.5.127 → 0.5.128

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.
Files changed (145) hide show
  1. package/Cargo.lock +1 -1
  2. package/Cargo.toml +1 -1
  3. package/README.md +11 -0
  4. package/crates/team-agent/src/cli/adapters.rs +3 -13
  5. package/crates/team-agent/src/cli/arguments.rs +4 -0
  6. package/crates/team-agent/src/cli/diagnose.rs +68 -22
  7. package/crates/team-agent/src/cli/emit.rs +58 -26
  8. package/crates/team-agent/src/cli/intent/runtime.rs +32 -5
  9. package/crates/team-agent/src/cli/intent/runtime_tests.rs +102 -11
  10. package/crates/team-agent/src/cli/intent/tests.rs +10 -12
  11. package/crates/team-agent/src/cli/intent.rs +1 -1
  12. package/crates/team-agent/src/cli/mod.rs +25 -8
  13. package/crates/team-agent/src/cli/models.rs +764 -7
  14. package/crates/team-agent/src/cli/schedule.rs +175 -0
  15. package/crates/team-agent/src/cli/send/persist.rs +0 -36
  16. package/crates/team-agent/src/cli/send/presentation.rs +1 -1
  17. package/crates/team-agent/src/cli/send.rs +108 -110
  18. package/crates/team-agent/src/cli/spec.rs +6 -0
  19. package/crates/team-agent/src/cli/status_port/brief.rs +5 -67
  20. package/crates/team-agent/src/cli/tests/leader_watch.rs +12 -62
  21. package/crates/team-agent/src/cli/tests/mod.rs +1 -1
  22. package/crates/team-agent/src/cli/tests/named_address.rs +11 -10
  23. package/crates/team-agent/src/cli/tests/run_delegation.rs +9 -6
  24. package/crates/team-agent/src/cli/tests/status_send.rs +68 -271
  25. package/crates/team-agent/src/compiler/tests.rs +3 -18
  26. package/crates/team-agent/src/compiler.rs +205 -6
  27. package/crates/team-agent/src/contract_runtime/backend.rs +145 -11
  28. package/crates/team-agent/src/contract_runtime/commands.rs +7 -7
  29. package/crates/team-agent/src/contract_runtime/config.rs +26 -16
  30. package/crates/team-agent/src/contract_runtime/config_tests.rs +24 -4
  31. package/crates/team-agent/src/contract_runtime/discovery.rs +12 -1
  32. package/crates/team-agent/src/contract_runtime/fork.rs +3 -10
  33. package/crates/team-agent/src/contract_runtime/framework.rs +28 -11
  34. package/crates/team-agent/src/contract_runtime/mcp.rs +19 -24
  35. package/crates/team-agent/src/contract_runtime/prompt.rs +2 -2
  36. package/crates/team-agent/src/contract_runtime/registry.rs +56 -92
  37. package/crates/team-agent/src/coordinator/steps/abnormal.rs +11 -11
  38. package/crates/team-agent/src/coordinator/tests/api_error_recovery.rs +16 -54
  39. package/crates/team-agent/src/coordinator/tests/health_sync.rs +42 -0
  40. package/crates/team-agent/src/coordinator/tick.rs +1 -89
  41. package/crates/team-agent/src/db/message_store.rs +7 -65
  42. package/crates/team-agent/src/direct_delivery.rs +368 -0
  43. package/crates/team-agent/src/inbox_store.rs +169 -0
  44. package/crates/team-agent/src/leader/registry.rs +5 -0
  45. package/crates/team-agent/src/leader/start.rs +2 -1
  46. package/crates/team-agent/src/leader/tests/lease_api.rs +2 -2
  47. package/crates/team-agent/src/leader/tests/prompt_contract.rs +1 -0
  48. package/crates/team-agent/src/lib.rs +2 -0
  49. package/crates/team-agent/src/lifecycle/launch/add_agent.rs +33 -0
  50. package/crates/team-agent/src/lifecycle/launch/add_agent_state.rs +206 -1
  51. package/crates/team-agent/src/lifecycle/launch/clone_agent.rs +28 -2
  52. package/crates/team-agent/src/lifecycle/launch/fork_agent.rs +38 -13
  53. package/crates/team-agent/src/lifecycle/launch/fork_entry.rs +87 -6
  54. package/crates/team-agent/src/lifecycle/launch/mcp_config.rs +9 -1
  55. package/crates/team-agent/src/lifecycle/launch/pi_mcp.rs +351 -81
  56. package/crates/team-agent/src/lifecycle/launch/pi_mcp_extension.js +3 -4
  57. package/crates/team-agent/src/lifecycle/launch/quick_start.rs +24 -0
  58. package/crates/team-agent/src/lifecycle/launch/spawn.rs +36 -13
  59. package/crates/team-agent/src/lifecycle/launch.rs +24 -1
  60. package/crates/team-agent/src/lifecycle/profile_launch.rs +321 -11
  61. package/crates/team-agent/src/lifecycle/restart/agent.rs +1 -0
  62. package/crates/team-agent/src/lifecycle/restart/avatar.rs +1798 -0
  63. package/crates/team-agent/src/lifecycle/restart/claude_fork.rs +163 -0
  64. package/crates/team-agent/src/lifecycle/restart/common.rs +345 -35
  65. package/crates/team-agent/src/lifecycle/restart/selection.rs +5 -5
  66. package/crates/team-agent/src/lifecycle/restart.rs +4 -0
  67. package/crates/team-agent/src/lifecycle/role_config.rs +39 -14
  68. package/crates/team-agent/src/lifecycle/tests/claude_compatible_config_red.rs +325 -0
  69. package/crates/team-agent/src/lifecycle/tests/claude_profile_launch_red.rs +320 -8
  70. package/crates/team-agent/src/lifecycle/tests/cli_argv_routing_red.rs +236 -13
  71. package/crates/team-agent/src/lifecycle/tests/clone_fork_copilot_perms_red.rs +378 -4
  72. package/crates/team-agent/src/lifecycle/tests/communication_mode_runtime_contract_red.rs +5 -4
  73. package/crates/team-agent/src/lifecycle/tests/copilot_provider_red.rs +7 -11
  74. package/crates/team-agent/src/lifecycle/tests/core.rs +47 -18
  75. package/crates/team-agent/src/lifecycle/tests/fixtures/pi_native_mcp_host.mjs +2 -1
  76. package/crates/team-agent/src/lifecycle/tests/grok_require_explicit_model_red.rs +14 -14
  77. package/crates/team-agent/src/lifecycle/tests/harvest2_a_batch_red.rs +60 -20
  78. package/crates/team-agent/src/lifecycle/tests/launch_spawn.rs +28 -26
  79. package/crates/team-agent/src/lifecycle/tests/mcp_tool_name_format_red.rs +6 -6
  80. package/crates/team-agent/src/lifecycle/tests/pi_catalog_red.rs +18 -6
  81. package/crates/team-agent/src/lifecycle/tests/pi_command_red.rs +70 -52
  82. package/crates/team-agent/src/lifecycle/tests/pi_compiler_red.rs +210 -0
  83. package/crates/team-agent/src/lifecycle/tests/pi_dual_entry_red.rs +157 -4
  84. package/crates/team-agent/src/lifecycle/tests/pi_executable_mcp_red.rs +526 -10
  85. package/crates/team-agent/src/lifecycle/tests/pi_fork_session_inheritance_red.rs +1419 -0
  86. package/crates/team-agent/src/lifecycle/tests/pi_lifecycle_doctor_red.rs +68 -1
  87. package/crates/team-agent/src/lifecycle/tests/pi_native_mcp_capability_red.rs +34 -12
  88. package/crates/team-agent/src/lifecycle/tests/pi_session_delivery_red.rs +94 -2
  89. package/crates/team-agent/src/lifecycle/tests/quick_start_worker_readiness_red.rs +10 -11
  90. package/crates/team-agent/src/lifecycle/tests/status_credential_redaction_contract.rs +2 -2
  91. package/crates/team-agent/src/lifecycle/tests/swallow_batch4_semantics_red.rs +254 -2
  92. package/crates/team-agent/src/lifecycle/tests/upgrade_compat_0211_red.rs +4 -4
  93. package/crates/team-agent/src/lifecycle/tests/verify_rs031_window_consistency_red.rs +5 -6
  94. package/crates/team-agent/src/lifecycle/tests/worker_spawn_env_red.rs +16 -7
  95. package/crates/team-agent/src/lifecycle/tests.rs +3 -0
  96. package/crates/team-agent/src/lifecycle/types.rs +18 -2
  97. package/crates/team-agent/src/lifecycle/worker_command_context.rs +43 -50
  98. package/crates/team-agent/src/mcp_server/readiness.rs +130 -149
  99. package/crates/team-agent/src/mcp_server/readiness_tests.rs +98 -119
  100. package/crates/team-agent/src/mcp_server/tests/scoped.rs +21 -31
  101. package/crates/team-agent/src/mcp_server/tests/send.rs +72 -107
  102. package/crates/team-agent/src/mcp_server/tests/tools.rs +10 -12
  103. package/crates/team-agent/src/mcp_server/tools.rs +70 -196
  104. package/crates/team-agent/src/messaging/delivery.rs +160 -218
  105. package/crates/team-agent/src/messaging/delivery_consumption_tests.rs +5 -5
  106. package/crates/team-agent/src/messaging/helpers.rs +1 -19
  107. package/crates/team-agent/src/messaging/mod.rs +1 -0
  108. package/crates/team-agent/src/messaging/reminders.rs +316 -0
  109. package/crates/team-agent/src/messaging/scheduler.rs +7 -1
  110. package/crates/team-agent/src/messaging/tests/dup_inject.rs +191 -85
  111. package/crates/team-agent/src/messaging/tests/runtime.rs +4 -110
  112. package/crates/team-agent/src/messaging/tests/spine.rs +40 -24
  113. package/crates/team-agent/src/messaging/types.rs +1 -0
  114. package/crates/team-agent/src/provider/adapter.rs +303 -51
  115. package/crates/team-agent/src/provider/adapters/claude.rs +78 -0
  116. package/crates/team-agent/src/provider/adapters/claude_fork.rs +131 -0
  117. package/crates/team-agent/src/provider/adapters/mod.rs +7 -5
  118. package/crates/team-agent/src/provider/adapters/pi.rs +106 -0
  119. package/crates/team-agent/src/provider/classify.rs +1 -66
  120. package/crates/team-agent/src/provider/model_catalog.rs +201 -13
  121. package/crates/team-agent/src/provider/session/capture.rs +106 -6
  122. package/crates/team-agent/src/provider/session/context_fork/claude.rs +123 -0
  123. package/crates/team-agent/src/provider/session/context_fork/outcome.rs +4 -0
  124. package/crates/team-agent/src/provider/session/context_fork.rs +150 -18
  125. package/crates/team-agent/src/provider/session_scan/claude.rs +523 -0
  126. package/crates/team-agent/src/provider/session_scan/common.rs +44 -8
  127. package/crates/team-agent/src/provider/session_scan/pi.rs +34 -1
  128. package/crates/team-agent/src/provider/session_scan.rs +16 -6
  129. package/crates/team-agent/src/provider/tests/adapter.rs +104 -17
  130. package/crates/team-agent/src/provider/tests/classify.rs +0 -53
  131. package/crates/team-agent/src/provider/tests/command_helpers.rs +12 -3
  132. package/crates/team-agent/src/provider/tests/idle.rs +37 -0
  133. package/crates/team-agent/src/provider/wire.rs +22 -34
  134. package/crates/team-agent/src/state/abnormal_watch/tests/mod.rs +1 -1
  135. package/crates/team-agent/src/state/persist.rs +6 -6
  136. package/crates/team-agent/src/state/projection.rs +1 -1
  137. package/crates/team-agent/src/state/repository/tests.rs +2 -2
  138. package/crates/team-agent/src/test_support/models_timeout_fixture.rs +144 -0
  139. package/crates/team-agent/src/tmux_backend/tests.rs +0 -151
  140. package/crates/team-agent/src/tmux_backend.rs +5 -40
  141. package/package.json +4 -4
  142. package/skills/team-agent/SKILL.md +5 -7
  143. package/skills/team-agent/command-coverage.json +1 -1
  144. package/skills/team-agent/docs/reference/team-agent-operator.md +3 -3
  145. package/skills/team-agent/references/team-agent-operator.md +3 -3
@@ -26,7 +26,9 @@ use crate::event_log::EventLog;
26
26
  use crate::message_store::MessageStore;
27
27
  use crate::model::enums::{PaneLiveness, Provider};
28
28
  use crate::model::ids::TeamKey;
29
- use crate::provider::wire::parse_canonical_provider;
29
+ use crate::provider::wire::{
30
+ is_claude_family, parse_canonical_provider, parse_provider, provider_wire,
31
+ };
30
32
  use crate::transport::{
31
33
  submit_verification_wire, turn_verification_wire, BusySignalKind, CaptureRange,
32
34
  CaptureSampleOutcome, InjectPayload, InjectReport, InjectVerification, InputSurfaceProbe, Key,
@@ -299,156 +301,6 @@ fn prepare_message_state(
299
301
  Ok(Ok(prepared))
300
302
  }
301
303
 
302
- /// #372: how long a seat may wait for its MCP handshake, counted from its
303
- /// spawn or the message's creation (whichever is later), before the message
304
- /// parks instead of re-polling every tick.
305
- #[cfg(unix)]
306
- const MCP_HANDSHAKE_WAIT_LIMIT_SECS: i64 = 300;
307
-
308
- #[cfg(unix)]
309
- #[allow(clippy::too_many_arguments)]
310
- fn mcp_handshake_pending_outcome(
311
- workspace: &Path,
312
- store: &MessageStore,
313
- event_log: &EventLog,
314
- state: &serde_json::Value,
315
- owner: Option<&str>,
316
- message_id: &str,
317
- message: &PendingMessage,
318
- attempt: u32,
319
- reason: &str,
320
- ) -> Result<DeliveryOutcome, MessagingError> {
321
- let already_claimed = || DeliveryOutcome {
322
- ok: false,
323
- status: DeliveryStatus::Refused,
324
- message_status: MessageStatusShadow("target_resolved".to_string()),
325
- message_id: Some(message_id.to_string()),
326
- verification: None,
327
- stage: None,
328
- reason: Some(DeliveryRefusal::MessageAlreadyClaimed),
329
- channel: None,
330
- ack_forced_off: false,
331
- turn_verification: None,
332
- };
333
- let spawned_at = state["agents"][message.recipient.as_str()]["spawned_at"].as_str();
334
- let waited_s = [spawned_at, message.created_at.as_deref()]
335
- .into_iter()
336
- .flatten()
337
- .filter_map(|at| chrono::DateTime::parse_from_rfc3339(at).ok())
338
- .max()
339
- .map_or(0, |since| {
340
- (chrono::Utc::now() - since.with_timezone(&chrono::Utc)).num_seconds()
341
- });
342
- if waited_s >= MCP_HANDSHAKE_WAIT_LIMIT_SECS {
343
- if !store.park_delivery_before_input(message_id, attempt)? {
344
- return Ok(already_claimed());
345
- }
346
- // A receipt published between this preflight and the park found no
347
- // parked row to resume; one re-check keeps that publication from being lost.
348
- let published_meanwhile = owner.is_some_and(|owner| {
349
- crate::mcp_server::readiness::preflight(workspace, Some(owner), &message.recipient, state)
350
- .is_ok()
351
- });
352
- if published_meanwhile {
353
- store.requeue_parked_deliveries(&message.recipient, owner.unwrap_or_default())?;
354
- } else {
355
- event_log.write("delivery.mcp_handshake_parked", serde_json::json!({
356
- "message_id": message_id,
357
- "recipient": message.recipient,
358
- "reason": reason,
359
- "waited_s": waited_s,
360
- }))?;
361
- notify_mcp_handshake_parked(workspace, store, event_log, state, &message.recipient, reason, waited_s)?;
362
- }
363
- return Ok(DeliveryOutcome {
364
- ok: false,
365
- status: DeliveryStatus::Blocked,
366
- message_status: MessageStatusShadow(
367
- if published_meanwhile { "accepted" } else { "queued_until_start" }.to_string(),
368
- ),
369
- message_id: Some(message_id.to_string()),
370
- verification: Some(format!("{}:{reason}", crate::message_store::MCP_HANDSHAKE_TIMEOUT)),
371
- stage: None,
372
- reason: None,
373
- channel: None,
374
- ack_forced_off: false,
375
- turn_verification: None,
376
- });
377
- }
378
- // No paste/key has occurred. Only this exact claim may be released; a
379
- // concurrent cancellation or newer delivery must never be overwritten.
380
- if !store.release_delivery_before_input(message_id, attempt, reason)? {
381
- return Ok(already_claimed());
382
- }
383
- event_log.write("delivery.deferred_mcp_handshake", serde_json::json!({
384
- "message_id": message_id,
385
- "recipient": message.recipient,
386
- "reason": reason,
387
- "waited_s": waited_s,
388
- "effect": "none",
389
- }))?;
390
- Ok(DeliveryOutcome {
391
- ok: false,
392
- status: DeliveryStatus::Degraded,
393
- message_status: MessageStatusShadow("target_resolved".to_string()),
394
- message_id: Some(message_id.to_string()),
395
- verification: Some(reason.to_string()),
396
- stage: None,
397
- reason: None,
398
- channel: None,
399
- ack_forced_off: false,
400
- turn_verification: None,
401
- })
402
- }
403
-
404
- /// One leader notice per seat spawn; later parks of the same spawn stay quiet.
405
- #[cfg(unix)]
406
- fn notify_mcp_handshake_parked(
407
- workspace: &Path,
408
- store: &MessageStore,
409
- event_log: &EventLog,
410
- state: &serde_json::Value,
411
- recipient: &str,
412
- reason: &str,
413
- waited_s: i64,
414
- ) -> Result<(), MessagingError> {
415
- let agent = &state["agents"][recipient];
416
- let result_id = format!(
417
- "mcp_handshake.timeout:{recipient}:{}",
418
- agent["spawned_at"].as_str().unwrap_or("unknown")
419
- );
420
- let notified = crate::db::schema::open_db(store.db_path())?
421
- .query_row(
422
- "select 1 from leader_notification_log where result_id = ?1 limit 1",
423
- params![result_id],
424
- |_| Ok(()),
425
- )
426
- .optional()?
427
- .is_some();
428
- if notified {
429
- return Ok(());
430
- }
431
- let live = agent["pane_pid"]
432
- .as_u64()
433
- .and_then(|pid| u32::try_from(pid).ok())
434
- .map(crate::mcp_server::readiness::live_servers_under)
435
- .unwrap_or_default();
436
- let live = if live.is_empty() { "none".to_string() } else { format!("{live:?}") };
437
- let content = format!(
438
- "mcp_handshake.timeout\nerror: messages to {recipient} are parked after waiting {waited_s}s for its MCP handshake ({reason}); live mcp-server pids under its pane: {live}\naction: run team-agent restart {recipient}; parked messages resume automatically once its MCP server publishes a handshake\nlog: .team/logs/events.jsonl"
439
- );
440
- let outcome = crate::messaging::send_to_leader_receiver(
441
- workspace, state, "leader", &content, None, "coordinator", false, Some(&result_id), event_log,
442
- );
443
- event_log.write("delivery.mcp_handshake_parked_notification", serde_json::json!({
444
- "recipient": recipient,
445
- "result_id": result_id,
446
- "live_mcp_servers": live,
447
- "error": outcome.err().map(|error| error.to_string()),
448
- }))?;
449
- Ok(())
450
- }
451
-
452
304
  fn deliver_prepared_message(
453
305
  workspace: &Path,
454
306
  store: &MessageStore,
@@ -791,11 +643,8 @@ fn deliver_prepared_message(
791
643
  turn_verification: None,
792
644
  });
793
645
  }
794
- // Startup control must remain reachable before protocol admission: some
795
- // clients cannot initialize MCP until their trust prompt is answered.
796
- // No business input is allowed before the current tools/list flush. A
797
- // readiness-only refusal releases this exact claim without spending an
798
- // input attempt; it never holds a pane-input lock or sleeps for startup.
646
+ // MCP readiness is diagnostic, not permission to type into a live pane.
647
+ // Missing/foreign evidence never releases the claim or parks this message.
799
648
  #[cfg(unix)]
800
649
  {
801
650
  let admission = crate::mcp_server::readiness::preflight(
@@ -807,10 +656,11 @@ fn deliver_prepared_message(
807
656
  Ok(())
808
657
  });
809
658
  if let Err(reason) = admission {
810
- return mcp_handshake_pending_outcome(
811
- workspace, store, event_log, state, canonical_owner_team_id.as_deref(),
812
- message_id, &message, attempt, reason,
813
- );
659
+ let _ = event_log.write("delivery.mcp_handshake_warning", serde_json::json!({
660
+ "message_id": message_id,
661
+ "reason": reason,
662
+ "delivery_blocked": false,
663
+ }));
814
664
  }
815
665
  }
816
666
  let rendered = render_message(
@@ -836,18 +686,25 @@ fn deliver_prepared_message(
836
686
  );
837
687
  // v0.5.113 delivery: address/owner and pane serialization are authoritative;
838
688
  // composer appearance is not admission. Native CLIs buffer/queue input.
839
- let inject_attempt = transport.inject_with_submit_observer(
840
- &target,
841
- &payload,
842
- Key::Enter,
843
- true,
844
- Some(&submit_observer),
689
+ let inject_attempt = crate::tmux_backend::with_cursor_single_enter(
690
+ recipient_requires_single_enter(state, &message.recipient),
691
+ || {
692
+ transport.inject_with_submit_observer(
693
+ &target,
694
+ &payload,
695
+ Key::Enter,
696
+ true,
697
+ Some(&submit_observer),
698
+ )
699
+ },
845
700
  );
846
701
  let inject_report = match inject_attempt {
847
702
  Ok(report) => {
848
703
  // grok 忙时第一次回车只入显式队列。默认 send-now:只重按回车顶出去。
849
704
  // 无 `Enter:send now` 时零次额外按键,claude/codex 行为不变。
850
- if !crate::provider::submit_now::keep_provider_queue_requested() {
705
+ if !crate::provider::submit_now::keep_provider_queue_requested()
706
+ && recipient_allows_explicit_queue_flush(state, &message.recipient)
707
+ {
851
708
  match crate::provider::submit_now::flush_explicit_queue(transport, &target) {
852
709
  Ok(flush) if flush.extra_enters > 0 => {
853
710
  let _ = event_log.write(
@@ -987,31 +844,7 @@ fn deliver_prepared_message(
987
844
  // worker delivery both require post-submit evidence; leader additionally
988
845
  // waits for its authoritative provider transcript below.
989
846
  let native_consumed = observed_token_consumed(transport, state, &message.recipient, &target, message_id);
990
- let mut verified = submit_verified && native_consumed != Some(false);
991
- // #379: a pane the verifier could not read is not a failed send. The
992
- // recipient's own transcript row (user turn or queued enqueue) is the
993
- // provider's receipt; native observers keep their veto.
994
- if !verified
995
- && native_consumed.is_none()
996
- && recipient_transcript_contains_within(
997
- state,
998
- &message.recipient,
999
- &message_token_marker(message_id),
1000
- TRANSCRIPT_RECEIPT_TAIL_BYTES,
1001
- )
1002
- {
1003
- verified = true;
1004
- event_log.write(
1005
- "send.unverified_reconciled",
1006
- serde_json::json!({
1007
- "message_id": message_id,
1008
- "recipient": message.recipient,
1009
- "source": "recipient_transcript",
1010
- "submit_verification": submit_verification_wire(inject_report.submit_verification),
1011
- "attempts": inject_report.attempts,
1012
- }),
1013
- )?;
1014
- }
847
+ let verified = submit_verified && native_consumed != Some(false);
1015
848
  if !verified {
1016
849
  let reason = if native_consumed == Some(false) {
1017
850
  "submit_unverified:current_composer_or_consumption_unknown".to_string()
@@ -1034,7 +867,6 @@ fn deliver_prepared_message(
1034
867
  "recipient": message.recipient,
1035
868
  "reason": reason,
1036
869
  "attempts": inject_report.attempts,
1037
- "delivery_attempt": attempt,
1038
870
  "submit_attempts_detail": submit_attempts_detail,
1039
871
  });
1040
872
  merge_inject_readback_fields(
@@ -1044,8 +876,7 @@ fn deliver_prepared_message(
1044
876
  resolved.metadata.as_ref(),
1045
877
  );
1046
878
  event_log.write("send.unverified", unverified)?;
1047
- // #379: the budget is delivery attempts, not Enter presses inside one.
1048
- if attempt >= u32::from(SEND_RETRY_MAX_ATTEMPTS) {
879
+ if inject_report.attempts >= u32::from(SEND_RETRY_MAX_ATTEMPTS) {
1049
880
  store.mark(message_id, "failed", Some("send_unverified_exhausted"))?;
1050
881
  emit_send_failed_exhausted(
1051
882
  workspace,
@@ -1053,7 +884,7 @@ fn deliver_prepared_message(
1053
884
  event_log,
1054
885
  message_id,
1055
886
  &message.recipient,
1056
- attempt,
887
+ inject_report.attempts,
1057
888
  "send_unverified_exhausted",
1058
889
  &reason,
1059
890
  Some(&inject_report),
@@ -1087,6 +918,75 @@ fn deliver_prepared_message(
1087
918
  turn_verification: Some(turn_verification),
1088
919
  });
1089
920
  }
921
+ // S1-CAPTURE-001 (0.4.8, CR M4 Claude phase-1): for Claude/ClaudeCode
922
+ // recipients with a known authoritative rollout_path, verify the message
923
+ // token actually reached the worker's transcript before marking
924
+ // delivered. This catches the gate's mis-attribution: pane inject
925
+ // succeeded but the token landed in the leader/unassigned transcript,
926
+ // not the worker's. Budget per architect plan: 64KB tail / single
927
+ // per-delivery check / short grace window. Phase-1 Claude only —
928
+ // codex/copilot keep the pre-fix behaviour (will be addressed in
929
+ // phase-2 once Claude phase-1 is field-validated).
930
+ if let Some((rollout_path, provider_wire_str)) =
931
+ claude_recipient_rollout(state, &message.recipient)
932
+ {
933
+ let token_marker = format!("[team-agent-token:{message_id}]");
934
+ let grace = std::time::Duration::from_millis(200);
935
+ let deadline = std::time::Instant::now() + std::time::Duration::from_millis(500);
936
+ let transcript_has_token = loop {
937
+ let found = rollout_tail_contains(&rollout_path, &token_marker, 64 * 1024);
938
+ if found || std::time::Instant::now() >= deadline {
939
+ break found;
940
+ }
941
+ std::thread::sleep(grace);
942
+ };
943
+ if !transcript_has_token {
944
+ // Loud but non-fatal: emit a mismatch event for diagnose/status
945
+ // observability. Do NOT mark delivered — degrade to
946
+ // submitted_unverified so capture is forced to re-attribute.
947
+ let reason = format!(
948
+ "transcript_missing:provider={provider_wire_str},rollout={}",
949
+ rollout_path.display()
950
+ );
951
+ event_log.write(
952
+ "provider.session.transcript_mismatch",
953
+ serde_json::json!({
954
+ "message_id": message_id,
955
+ "recipient": message.recipient,
956
+ "provider": provider_wire_str,
957
+ "rollout_path": rollout_path.to_string_lossy(),
958
+ "pane_id": state
959
+ .get("agents")
960
+ .and_then(|a| a.get(&message.recipient))
961
+ .and_then(|a| a.get("pane_id"))
962
+ .and_then(serde_json::Value::as_str)
963
+ .unwrap_or(""),
964
+ "spawn_epoch": state
965
+ .get("agents")
966
+ .and_then(|a| a.get(&message.recipient))
967
+ .and_then(|a| a.get("spawn_epoch"))
968
+ .and_then(serde_json::Value::as_u64)
969
+ .unwrap_or(0),
970
+ "reason": "transcript_missing",
971
+ }),
972
+ )?;
973
+ store.mark(message_id, "submitted_unverified", Some(&reason))?;
974
+ bind_enter_watchdog(store, transport, state, &target, message_id, &message,
975
+ canonical_owner_team_id.as_deref(), event_log)?;
976
+ return Ok(DeliveryOutcome {
977
+ ok: false,
978
+ status: DeliveryStatus::Failed,
979
+ message_status: MessageStatusShadow("submitted_unverified".to_string()),
980
+ message_id: Some(message_id.to_string()),
981
+ verification: Some(reason),
982
+ stage: Some(DeliveryStage::Submit),
983
+ reason: None,
984
+ channel: None,
985
+ ack_forced_off: false,
986
+ turn_verification: Some(turn_verification),
987
+ });
988
+ }
989
+ }
1090
990
  if is_leader_recipient {
1091
991
  store.record_delivery_submission(message_id, readback_verified)?;
1092
992
  match observe_leader_receipt(state, message_id) {
@@ -2398,11 +2298,11 @@ pub fn deliver_pending_messages(
2398
2298
  where status in (
2399
2299
  'pending', 'accepted', 'target_resolved',
2400
2300
  'submitted_pending_acceptance', 'queued_until_leader_attach', ?1
2401
- )
2301
+ ) or (status = 'queued_until_start' and error = ?2)
2402
2302
  order by created_at, message_id",
2403
2303
  )?;
2404
2304
  let rows = stmt.query_map(
2405
- [crate::message_store::MessageRowStatus::QueuedCoordinatorUnavailable.as_str()],
2305
+ [crate::message_store::MessageRowStatus::QueuedCoordinatorUnavailable.as_str(), crate::message_store::MCP_HANDSHAKE_TIMEOUT],
2406
2306
  |row| row.get::<_, String>(0),
2407
2307
  )?;
2408
2308
  rows.collect::<Result<Vec<_>, _>>()?
@@ -2547,15 +2447,17 @@ fn recipient_pane_has_actionable_startup_prompt(
2547
2447
  _ => return false,
2548
2448
  };
2549
2449
  match provider {
2450
+ Provider::Claude | Provider::ClaudeCode => matches!(
2451
+ crate::provider::classify_claude_startup_screen(&captured),
2452
+ crate::provider::StartupScreenDecision::AnswerWorkspaceTrust
2453
+ ),
2550
2454
  Provider::Copilot => matches!(
2551
2455
  crate::provider::classify_copilot_startup_screen(&captured),
2552
2456
  crate::provider::StartupScreenDecision::AnswerWorkspaceTrust
2553
2457
  ),
2554
- // Claude Code, Codex, Grok and Pi workers run only through their
2555
- // contract leaves; a legacy row was refused before this peek.
2556
- Provider::Claude
2557
- | Provider::ClaudeCode
2558
- | Provider::Codex
2458
+ // Codex and Grok workers run only through their contract leaves; a
2459
+ // legacy row was refused before this peek.
2460
+ Provider::Codex
2559
2461
  | Provider::Pi
2560
2462
  | Provider::Grok
2561
2463
  | Provider::GeminiCli
@@ -2573,6 +2475,31 @@ fn recipient_provider(state: &serde_json::Value, recipient: &str) -> Option<Prov
2573
2475
  .and_then(parse_canonical_provider)
2574
2476
  }
2575
2477
 
2478
+ /// ---
2479
+ /// purpose: 判断收件 provider 是否必须禁止 submit observer 重按 Enter
2480
+ /// returns: Pi 为 true,其余为 false
2481
+ /// ---
2482
+ pub(crate) fn recipient_requires_single_enter(state: &serde_json::Value, recipient: &str) -> bool {
2483
+ matches!(
2484
+ recipient_provider(state, recipient),
2485
+ Some(Provider::Pi)
2486
+ )
2487
+ }
2488
+
2489
+ /// ---
2490
+ /// purpose: 判断收件 provider 是否允许 Grok send-now 显式队列 flush
2491
+ /// returns: Pi 为 false,其余为 true
2492
+ /// ---
2493
+ pub(crate) fn recipient_allows_explicit_queue_flush(
2494
+ state: &serde_json::Value,
2495
+ recipient: &str,
2496
+ ) -> bool {
2497
+ !matches!(
2498
+ recipient_provider(state, recipient),
2499
+ Some(Provider::Pi)
2500
+ )
2501
+ }
2502
+
2576
2503
  fn leader_rollout_path(state: &serde_json::Value) -> Option<std::path::PathBuf> {
2577
2504
  if let Some(receiver) = leader_receiver_value(state).filter(|receiver| {
2578
2505
  receiver.get("provider").and_then(serde_json::Value::as_str) == Some("pi")
@@ -3464,6 +3391,30 @@ pub fn retry_injection_after_trust_auto_answer(
3464
3391
  })
3465
3392
  }
3466
3393
 
3394
+ /// S1-CAPTURE-001 (0.4.8 phase-1): returns (rollout_path, provider_wire) when
3395
+ /// the recipient agent is Claude/ClaudeCode with a known authoritative
3396
+ /// rollout_path; otherwise None (skip transcript verify). Phase-1 Claude only —
3397
+ /// codex/copilot return None and keep pre-fix delivery semantics.
3398
+ fn claude_recipient_rollout(
3399
+ state: &serde_json::Value,
3400
+ recipient: &str,
3401
+ ) -> Option<(std::path::PathBuf, &'static str)> {
3402
+ let agent = state.get("agents")?.get(recipient)?;
3403
+ let provider = agent
3404
+ .get("provider")
3405
+ .and_then(serde_json::Value::as_str)
3406
+ .and_then(parse_provider)?;
3407
+ if !is_claude_family(provider) {
3408
+ return None;
3409
+ }
3410
+ let provider_wire_str = provider_wire(provider);
3411
+ let rollout = agent
3412
+ .get("rollout_path")
3413
+ .and_then(serde_json::Value::as_str)
3414
+ .filter(|s| !s.is_empty())?;
3415
+ Some((std::path::PathBuf::from(rollout), provider_wire_str))
3416
+ }
3417
+
3467
3418
  /// S1-CAPTURE-001 (0.4.8 phase-1): bounded tail read of the rollout file
3468
3419
  /// searching for `needle`. Reads up to `tail_bytes` from the end of the file
3469
3420
  /// (default 64KB budget). Returns true iff the needle appears in the tail.
@@ -3581,21 +3532,12 @@ pub(crate) fn token_already_visible(
3581
3532
  }
3582
3533
 
3583
3534
  fn recipient_transcript_contains(state: &serde_json::Value, recipient: &str, marker: &str) -> bool {
3584
- recipient_transcript_contains_within(state, recipient, marker, 64 * 1024)
3585
- }
3586
-
3587
- /// The receipt row can sit behind seconds of tool output by verdict time.
3588
- const TRANSCRIPT_RECEIPT_TAIL_BYTES: u64 = 1024 * 1024;
3589
-
3590
- fn recipient_transcript_contains_within(
3591
- state: &serde_json::Value,
3592
- recipient: &str,
3593
- marker: &str,
3594
- tail_bytes: u64,
3595
- ) -> bool {
3596
- recipient_transcript_paths(state, recipient)
3597
- .iter()
3598
- .any(|path| rollout_tail_contains(path, marker, tail_bytes))
3535
+ for path in recipient_transcript_paths(state, recipient) {
3536
+ if rollout_tail_contains(&path, marker, 64 * 1024) {
3537
+ return true;
3538
+ }
3539
+ }
3540
+ false
3599
3541
  }
3600
3542
 
3601
3543
  fn recipient_transcript_paths(
@@ -103,7 +103,7 @@ fn frame(composer: &str, transcript: &str) -> InputFrame {
103
103
 
104
104
  #[test]
105
105
  fn current_token_in_composer_is_not_duplicate_delivered_or_repasted() {
106
- let f = Fixture::new("fake");
106
+ let f = Fixture::new("pi");
107
107
  let marker = message_token_marker("msg_one");
108
108
  let t = f
109
109
  .transport()
@@ -122,7 +122,7 @@ fn successful_transport_report_does_not_override_unconsumed_composer() {
122
122
  "[Pasted text #1 +25 lines]",
123
123
  "foreign draft",
124
124
  ] {
125
- let mut f = Fixture::new("fake");
125
+ let mut f = Fixture::new("pi");
126
126
  #[cfg(unix)]
127
127
  let panes = vec![crate::mcp_server::readiness::test_ready_worker(
128
128
  &f.workspace,
@@ -146,7 +146,7 @@ fn successful_transport_report_does_not_override_unconsumed_composer() {
146
146
 
147
147
  #[test]
148
148
  fn unknown_current_native_surface_is_unverified_not_success() {
149
- let f = Fixture::new("fake");
149
+ let f = Fixture::new("pi");
150
150
  let t = f
151
151
  .transport()
152
152
  .with_native_input_error("native_surface_unknown");
@@ -167,7 +167,7 @@ fn pane_visibility_without_an_observation_protocol_is_not_duplicate_acceptance()
167
167
 
168
168
  #[test]
169
169
  fn current_empty_composer_and_unique_transcript_token_prove_consumption() {
170
- let f = Fixture::new("fake");
170
+ let f = Fixture::new("pi");
171
171
  let marker = message_token_marker("msg_one");
172
172
  let t = f
173
173
  .transport()
@@ -180,7 +180,7 @@ fn current_empty_composer_and_unique_transcript_token_prove_consumption() {
180
180
 
181
181
  #[test]
182
182
  fn busy_answers_or_duplicate_history_tokens_do_not_prove_consumption() {
183
- let f = Fixture::new("fake");
183
+ let f = Fixture::new("pi");
184
184
  let target = Target::Pane(PaneId::new("%1"));
185
185
  for transcript in [
186
186
  "answer is 5535",
@@ -105,6 +105,7 @@ pub(crate) fn validate_result_envelope(envelope: &serde_json::Value) -> Result<(
105
105
  pub(crate) fn parse_scheduled_kind(kind: &str) -> Result<ScheduledKind, MessagingError> {
106
106
  match kind {
107
107
  "send" => Ok(ScheduledKind::Send),
108
+ "reminder" => Ok(ScheduledKind::Reminder),
108
109
  "health_ping" => Ok(ScheduledKind::HealthPing),
109
110
  "trust_retry" => Ok(ScheduledKind::TrustRetry),
110
111
  "enter_rescue" => Ok(ScheduledKind::EnterRescue),
@@ -158,25 +159,6 @@ pub(crate) fn latest_prompt_signal(scrollback: &str) -> Option<AgentActivity> {
158
159
  // IRON LAW (activity.rs:3 / bug-071/077/085): no-signal in the bottom
159
160
  // region must be Uncertain (caller treats None here as "no decisive
160
161
  // signal" and surfaces Uncertain), NEVER silently flipped to Idle.
161
- // #379: Claude Code's spinner sits above its composer box, outside the
162
- // bottom five rows, and its finished-turn `✻ Worked for 3s` sits inside
163
- // them. The box's own grammar (shared with delivery) decides instead.
164
- if let Some((surface, _)) =
165
- team_agent_contract::providers::claude::interaction::inspect_legacy_composer(scrollback)
166
- {
167
- use team_agent_contract::contract::delivery::InputSurface;
168
- match surface {
169
- InputSurface::Busy => {
170
- return Some(AgentActivity {
171
- status: ActivityStatus::Working,
172
- confidence: 0.9,
173
- rationale: "claude_spinner_row".to_string(),
174
- })
175
- }
176
- InputSurface::ComposerReady => return Some(idle_activity()),
177
- _ => {}
178
- }
179
- }
180
162
  let active_region: Vec<&str> = scrollback
181
163
  .lines()
182
164
  .rev()
@@ -72,6 +72,7 @@ pub mod persist;
72
72
  pub mod presentation;
73
73
  pub mod results;
74
74
  pub mod scheduler;
75
+ pub(crate) mod reminders;
75
76
  pub mod selftest;
76
77
  pub mod send;
77
78
  pub mod trust;