@team-agent/installer 0.5.124 → 0.5.125

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 (97) hide show
  1. package/Cargo.lock +1 -8
  2. package/Cargo.toml +1 -1
  3. package/README.md +2 -2
  4. package/README.zh.md +2 -2
  5. package/crates/team-agent/Cargo.toml +0 -1
  6. package/crates/team-agent/src/cli/diagnose.rs +39 -1
  7. package/crates/team-agent/src/cli/emit.rs +41 -15
  8. package/crates/team-agent/src/cli/intent/runtime.rs +5 -53
  9. package/crates/team-agent/src/cli/intent/runtime_tests.rs +0 -120
  10. package/crates/team-agent/src/cli/leader.rs +2 -3
  11. package/crates/team-agent/src/cli/leader_prompt.rs +1 -1
  12. package/crates/team-agent/src/cli/mod.rs +6 -5
  13. package/crates/team-agent/src/cli/models.rs +40 -119
  14. package/crates/team-agent/src/cli/route.rs +1 -1
  15. package/crates/team-agent/src/cli/send/persist.rs +36 -0
  16. package/crates/team-agent/src/cli/send/presentation.rs +7 -1
  17. package/crates/team-agent/src/cli/send.rs +3 -1
  18. package/crates/team-agent/src/cli/spec.rs +1 -2
  19. package/crates/team-agent/src/cli/status_port/brief.rs +66 -0
  20. package/crates/team-agent/src/cli/tests/base.rs +4 -11
  21. package/crates/team-agent/src/cli/tests/status_send.rs +17 -0
  22. package/crates/team-agent/src/compiler/tests.rs +21 -5
  23. package/crates/team-agent/src/compiler.rs +24 -1
  24. package/crates/team-agent/src/contract_runtime/backend.rs +22 -6
  25. package/crates/team-agent/src/contract_runtime/config.rs +34 -24
  26. package/crates/team-agent/src/contract_runtime/discovery.rs +33 -0
  27. package/crates/team-agent/src/contract_runtime/framework.rs +89 -34
  28. package/crates/team-agent/src/contract_runtime/registry.rs +258 -21
  29. package/crates/team-agent/src/coordinator/runtime_detectors.rs +0 -1
  30. package/crates/team-agent/src/coordinator/tick.rs +89 -1
  31. package/crates/team-agent/src/db/message_store.rs +78 -3
  32. package/crates/team-agent/src/layout/worker_window_helpers.rs +0 -1
  33. package/crates/team-agent/src/leader/prompt.rs +1 -2
  34. package/crates/team-agent/src/leader/provider_attribution.rs +0 -52
  35. package/crates/team-agent/src/leader/start.rs +0 -1
  36. package/crates/team-agent/src/leader/tests/prompt_contract.rs +2 -3
  37. package/crates/team-agent/src/lifecycle/launch/add_agent.rs +91 -0
  38. package/crates/team-agent/src/lifecycle/launch/add_agent_state.rs +14 -1
  39. package/crates/team-agent/src/lifecycle/launch/agent_state.rs +0 -9
  40. package/crates/team-agent/src/lifecycle/launch/fork_agent.rs +0 -1
  41. package/crates/team-agent/src/lifecycle/launch/mcp_config.rs +2 -2
  42. package/crates/team-agent/src/lifecycle/launch/spawn.rs +0 -28
  43. package/crates/team-agent/src/lifecycle/launch/spec_state.rs +0 -1
  44. package/crates/team-agent/src/lifecycle/launch/worker_env.rs +0 -108
  45. package/crates/team-agent/src/lifecycle/launch.rs +2 -20
  46. package/crates/team-agent/src/lifecycle/profile_launch.rs +11 -39
  47. package/crates/team-agent/src/lifecycle/profile_smoke.rs +1 -2
  48. package/crates/team-agent/src/lifecycle/restart/common.rs +1 -63
  49. package/crates/team-agent/src/lifecycle/role_config.rs +42 -3
  50. package/crates/team-agent/src/lifecycle/tests/cli_argv_routing_red.rs +38 -7
  51. package/crates/team-agent/src/lifecycle/tests/clone_fork_copilot_perms_red.rs +6 -2
  52. package/crates/team-agent/src/lifecycle/tests/restart_rebind_hotfix_252_red.rs +0 -1
  53. package/crates/team-agent/src/lifecycle/tests/worker_spawn_env_red.rs +0 -137
  54. package/crates/team-agent/src/lifecycle/tests.rs +0 -3
  55. package/crates/team-agent/src/lifecycle/worker_command_context.rs +2 -4
  56. package/crates/team-agent/src/mcp_server/readiness.rs +148 -97
  57. package/crates/team-agent/src/mcp_server/readiness_tests.rs +115 -16
  58. package/crates/team-agent/src/messaging/delivery.rs +181 -35
  59. package/crates/team-agent/src/messaging/delivery_consumption_tests.rs +4 -4
  60. package/crates/team-agent/src/messaging/enter_rescue_tests.rs +1 -1
  61. package/crates/team-agent/src/messaging/helpers.rs +19 -0
  62. package/crates/team-agent/src/messaging/tests/dup_inject.rs +66 -4
  63. package/crates/team-agent/src/messaging/tests/runtime.rs +110 -4
  64. package/crates/team-agent/src/messaging/tests/spine.rs +22 -6
  65. package/crates/team-agent/src/model/enums.rs +1 -8
  66. package/crates/team-agent/src/provider/adapter.rs +1 -67
  67. package/crates/team-agent/src/provider/adapters/mod.rs +0 -1
  68. package/crates/team-agent/src/provider/argv_route.rs +1 -5
  69. package/crates/team-agent/src/provider/bypass_flags.rs +3 -11
  70. package/crates/team-agent/src/provider/classify.rs +68 -3
  71. package/crates/team-agent/src/provider/faults.rs +1 -1
  72. package/crates/team-agent/src/provider/model_catalog.rs +2 -73
  73. package/crates/team-agent/src/provider/session/capture.rs +1 -1
  74. package/crates/team-agent/src/provider/session/context_fork.rs +4 -4
  75. package/crates/team-agent/src/provider/session_scan/common.rs +1 -2
  76. package/crates/team-agent/src/provider/session_scan.rs +0 -4
  77. package/crates/team-agent/src/provider/submit_now.rs +5 -28
  78. package/crates/team-agent/src/provider/tests/adapter.rs +5 -184
  79. package/crates/team-agent/src/provider/tests/classify.rs +53 -0
  80. package/crates/team-agent/src/provider/tests/command_helpers.rs +1 -4
  81. package/crates/team-agent/src/provider/types.rs +1 -1
  82. package/crates/team-agent/src/provider/wire.rs +48 -8
  83. package/crates/team-agent/src/tmux_backend/native_input_tests.rs +2 -178
  84. package/crates/team-agent/src/tmux_backend/tests.rs +151 -0
  85. package/crates/team-agent/src/tmux_backend.rs +43 -8
  86. package/crates/team-agent/src/transport/native_input.rs +2 -231
  87. package/package.json +4 -4
  88. package/skills/team-agent/SKILL.md +1 -1
  89. package/crates/team-agent/src/lifecycle/launch/cursor_create_chat.rs +0 -229
  90. package/crates/team-agent/src/lifecycle/launch/cursor_mcp.rs +0 -522
  91. package/crates/team-agent/src/lifecycle/launch/cursor_mcp_iso.rs +0 -282
  92. package/crates/team-agent/src/lifecycle/tests/cursor_mcp_overlay.rs +0 -576
  93. package/crates/team-agent/src/lifecycle/tests/cursor_require_explicit_model_red.rs +0 -222
  94. package/crates/team-agent/src/lifecycle/tests/cursor_restart_resume_red.rs +0 -511
  95. package/crates/team-agent/src/provider/adapters/cursor_agent.rs +0 -44
  96. package/crates/team-agent/src/provider/session_scan/cursor.rs +0 -538
  97. package/crates/team-agent/src/provider/testdata/cursor-list-models-native.stdout +0 -250
@@ -24,6 +24,38 @@
24
24
 
25
25
  use crate::model::enums::Provider;
26
26
 
27
+ /// A state row written by a release that still ran the legacy Cursor engine.
28
+ /// No legacy runtime exists for it now; it must never fall back to another
29
+ /// provider. Role and CLI declarations of these names select the contract leaf.
30
+ pub(crate) const RETIRED_PROVIDER_ERROR: &str =
31
+ "legacy cursor_agent seat has no runtime in this release; stop or remove it, then add it again (provider: cursor)";
32
+
33
+ pub(crate) fn is_retired_provider(raw: &str) -> bool {
34
+ matches!(raw.trim().to_ascii_lowercase().as_str(), "cursor_agent" | "agent")
35
+ }
36
+
37
+ pub(crate) fn require_active_state_providers(
38
+ state: &serde_json::Value,
39
+ target: Option<&str>,
40
+ ) -> Result<(), &'static str> {
41
+ if state
42
+ .get("agents")
43
+ .and_then(serde_json::Value::as_object)
44
+ .is_some_and(|agents| {
45
+ agents.iter().any(|(id, row)| {
46
+ target.is_none_or(|target| target == id)
47
+ && row
48
+ .get("provider")
49
+ .and_then(serde_json::Value::as_str)
50
+ .is_some_and(is_retired_provider)
51
+ })
52
+ })
53
+ {
54
+ return Err(RETIRED_PROVIDER_ERROR);
55
+ }
56
+ Ok(())
57
+ }
58
+
27
59
  /// Canonical snake_case wire string for `Provider`. Used for state JSON,
28
60
  /// log fields, and any cross-process serialization. Stable: do not change
29
61
  /// existing values.
@@ -35,7 +67,6 @@ pub(crate) fn provider_wire(provider: Provider) -> &'static str {
35
67
  Provider::Copilot => "copilot",
36
68
  Provider::GeminiCli => "gemini_cli",
37
69
  Provider::Grok => "grok",
38
- Provider::CursorAgent => "cursor_agent",
39
70
  Provider::Pi => "pi",
40
71
  Provider::Fake => "fake",
41
72
  }
@@ -83,7 +114,6 @@ pub(crate) fn requires_resume_backing(provider: Provider) -> bool {
83
114
  | Provider::ClaudeCode
84
115
  | Provider::Copilot
85
116
  | Provider::Grok
86
- | Provider::CursorAgent
87
117
  | Provider::Pi
88
118
  )
89
119
  }
@@ -104,10 +134,6 @@ pub(crate) fn aliases(provider: Provider) -> &'static [&'static str] {
104
134
  Provider::Copilot => &["copilot"],
105
135
  Provider::GeminiCli => &["gemini_cli"],
106
136
  Provider::Grok => &["grok"],
107
- // canonical wire form 恒为首项 (parse_provider round-trip 依赖); "agent"
108
- // 是 exec 二进制名, 仅作 alias (不参与 command-text 子串匹配, 见
109
- // leader/provider_attribution.rs TODO)。
110
- Provider::CursorAgent => &["cursor_agent", "agent"],
111
137
  Provider::Pi => &["pi"],
112
138
  Provider::Fake => &["fake"],
113
139
  }
@@ -125,7 +151,6 @@ pub(crate) fn command_name(provider: Provider) -> &'static str {
125
151
  Provider::Copilot => "copilot",
126
152
  Provider::GeminiCli => "gemini",
127
153
  Provider::Grok => "grok",
128
- Provider::CursorAgent => "agent",
129
154
  Provider::Pi => "pi",
130
155
  Provider::Fake => "team-agent",
131
156
  }
@@ -138,7 +163,6 @@ const ALL_PROVIDERS: &[Provider] = &[
138
163
  Provider::Copilot,
139
164
  Provider::GeminiCli,
140
165
  Provider::Grok,
141
- Provider::CursorAgent,
142
166
  Provider::Pi,
143
167
  Provider::Fake,
144
168
  ];
@@ -290,6 +314,22 @@ mod tests {
290
314
  assert_eq!(parse_provider("CLAUDE"), None); // case-sensitive
291
315
  }
292
316
 
317
+ #[test]
318
+ fn retired_state_guard_is_scoped_to_the_addressed_seat() {
319
+ let state = serde_json::json!({"agents": {
320
+ "pi": {"provider": "pi"},
321
+ "claude": {"provider": "claude"},
322
+ "retired": {"provider": "cursor_agent"}
323
+ }});
324
+ assert!(require_active_state_providers(&state, Some("pi")).is_ok());
325
+ assert!(require_active_state_providers(&state, Some("claude")).is_ok());
326
+ assert!(require_active_state_providers(&state, Some("retired")).is_err());
327
+ assert!(require_active_state_providers(&state, None).is_err());
328
+ for retired in ["cursor_agent", "agent"] {
329
+ assert_eq!(parse_provider(retired), None, "no legacy engine to parse into");
330
+ }
331
+ }
332
+
293
333
  #[test]
294
334
  fn aliases_first_entry_is_canonical_wire() {
295
335
  for &p in ALL_PROVIDERS {
@@ -20,12 +20,6 @@ enum Mode {
20
20
  R6IdleNotice,
21
21
  PiFolded,
22
22
  PiFoldedUnstable,
23
- CursorFollowup,
24
- CursorHeaderEvicted,
25
- CursorHistoryOnly,
26
- CursorLongHistory,
27
- CursorExpanded,
28
- CursorExpandedDirty,
29
23
  }
30
24
  struct State {
31
25
  mode: Mode,
@@ -59,13 +53,7 @@ impl CommandRunner for Runner {
59
53
  };
60
54
  let height = if matches!(
61
55
  state.mode,
62
- Mode::R6IdleNotice
63
- | Mode::PiFolded
64
- | Mode::PiFoldedUnstable
65
- | Mode::CursorHistoryOnly
66
- | Mode::CursorLongHistory
67
- | Mode::CursorExpanded
68
- | Mode::CursorExpandedDirty
56
+ Mode::R6IdleNotice | Mode::PiFolded | Mode::PiFoldedUnstable
69
57
  ) {
70
58
  24
71
59
  } else {
@@ -177,64 +165,6 @@ impl CommandRunner for Runner {
177
165
  }
178
166
  String::new()
179
167
  };
180
- let stdout = if state.provider == Provider::CursorAgent
181
- && argv.iter().any(|arg| arg == "capture-pane")
182
- {
183
- let followup = matches!(
184
- state.mode,
185
- Mode::CursorFollowup
186
- | Mode::CursorHeaderEvicted
187
- | Mode::CursorHistoryOnly
188
- | Mode::CursorLongHistory
189
- | Mode::CursorExpanded
190
- | Mode::CursorExpandedDirty
191
- );
192
- let placeholder = if followup {
193
- "Add a follow-up"
194
- } else {
195
- "Plan, search, build anything"
196
- };
197
- let header = if matches!(state.mode, Mode::CursorFollowup)
198
- || (matches!(state.mode, Mode::CursorHeaderEvicted) && state.pasted > 0)
199
- {
200
- ""
201
- } else {
202
- "Cursor Agent\nv2026.10.01-e373342\n"
203
- };
204
- let (composer, history) = if state.entered > 0 {
205
- (placeholder, "[Pasted text #2 +25 lines]")
206
- } else if state.pasted > 0 {
207
- ("[Pasted text #2 +25 lines]", "[Pasted text #1 +25 lines]")
208
- } else {
209
- (placeholder, "[Pasted text #1 +25 lines]")
210
- };
211
- let padding = if matches!(state.mode, Mode::CursorLongHistory) {
212
- "historical transcript row\n".repeat(70)
213
- } else {
214
- String::new()
215
- };
216
- let frame = format!(
217
- "{header}{history}\n{padding}→ {composer}\nGrok 4.7 High Run Everything\n/owned/project\n"
218
- );
219
- if matches!(state.mode, Mode::CursorExpanded | Mode::CursorExpandedDirty) {
220
- let expanded = include_str!("../../tests/fixtures/cursor-followup-expanded.txt");
221
- if matches!(state.mode, Mode::CursorExpandedDirty)
222
- || state.pasted > 0 && state.entered == 0
223
- {
224
- format!("[Pasted text #1 +30 lines]\n{expanded}")
225
- } else if state.entered > 0 {
226
- format!("{marker}\n→ Add a follow-up\nGrok 4.7 256K High · 8.6% Run Everything\n/owned/project\n")
227
- } else {
228
- "[Pasted text #1 +30 lines]\n→ Add a follow-up\nGrok 4.7 256K High · 8.6% Run Everything\n/owned/project\n".into()
229
- }
230
- } else if matches!(state.mode, Mode::CursorHistoryOnly) {
231
- format!("{frame}{}", "unknown current row\n".repeat(24))
232
- } else {
233
- frame
234
- }
235
- } else {
236
- stdout
237
- };
238
168
  Ok(CommandOutput {
239
169
  success: true,
240
170
  code: Some(0),
@@ -485,7 +415,7 @@ fn native_input_capsule_baseline_exclusion_is_provider_aware() {
485
415
  vec!["[paste #1 +30 lines]", "[paste #2 1234 chars]"]
486
416
  );
487
417
  assert_eq!(
488
- capsule_labels(Provider::CursorAgent, history),
418
+ capsule_labels(Provider::Claude, history),
489
419
  vec!["[Pasted text #3 +25 lines]"]
490
420
  );
491
421
  }
@@ -734,112 +664,6 @@ fn native_input_rescue_binding_busy_and_canonical_changes_never_send_a_key() {
734
664
  assert_eq!(f.state.lock().unwrap().entered, 0);
735
665
  }
736
666
 
737
- #[test]
738
- fn native_input_cursor_owned_new_capsule_transfers_to_transcript_without_token_claim() {
739
- let f = Fixture::new(Mode::Normal);
740
- f.state.lock().unwrap().provider = Provider::CursorAgent;
741
- let (report, evidence) = f.inject();
742
- let report = report.unwrap();
743
- let evidence = evidence.unwrap();
744
- assert_eq!(
745
- report.inject_verification,
746
- InjectVerification::CaptureContainsNewPastedContentPrompt
747
- );
748
- assert_eq!(
749
- report.submit_verification,
750
- SubmitVerification::EnterSentWithoutPlaceholderCheck
751
- );
752
- assert_eq!(
753
- evidence.capsule.as_deref(),
754
- Some("[Pasted text #2 +25 lines]")
755
- );
756
- assert_eq!(evidence.baseline_capsules, ["[Pasted text #1 +25 lines]"]);
757
- let state = f.state.lock().unwrap();
758
- assert_eq!(state.pasted, 1);
759
- assert_eq!(state.entered, 1);
760
- }
761
-
762
- #[test]
763
- fn native_input_cursor_clean_followup_uses_one_paste_one_enter_across_banner_eviction() {
764
- for mode in [
765
- Mode::CursorFollowup,
766
- Mode::CursorHeaderEvicted,
767
- Mode::CursorLongHistory,
768
- ] {
769
- let f = Fixture::new(mode);
770
- f.state.lock().unwrap().provider = Provider::CursorAgent;
771
- let (report, evidence) = f.inject();
772
- let report = report.unwrap();
773
- assert_eq!(
774
- report.submit_verification,
775
- SubmitVerification::EnterSentWithoutPlaceholderCheck
776
- );
777
- let evidence = evidence.unwrap();
778
- assert_eq!(evidence.phase, NativeInputPhase::Accepted);
779
- assert_eq!(
780
- evidence.capsule.as_deref(),
781
- Some("[Pasted text #2 +25 lines]")
782
- );
783
- let state = f.state.lock().unwrap();
784
- assert_eq!((state.pasted, state.entered), (1, 1));
785
- }
786
- }
787
-
788
- #[test]
789
- fn native_input_cursor_expanded_followup_reaches_seen_then_one_enter() {
790
- let f = Fixture::new(Mode::CursorExpanded);
791
- f.state.lock().unwrap().provider = Provider::CursorAgent;
792
- let text = "For a harmless terminal-scroll fixture, reply with exactly 240 numbered lines, one per line, from 001 through 240, each formatted `NNN: amber`; do not use tools or change any files. Then wait.\n\n[team-agent-token:msg_one]";
793
- let (report, evidence) = with_native_input(Some(f.request()), || {
794
- f.backend.inject(
795
- &Target::Pane(PaneId::new("%1")),
796
- &InjectPayload::Text(text.into()),
797
- Key::Enter,
798
- true,
799
- )
800
- });
801
- let report = report.unwrap();
802
- assert_eq!(
803
- report.submit_verification,
804
- SubmitVerification::EnterSentWithoutPlaceholderCheck
805
- );
806
- assert_eq!(
807
- report.inject_verification,
808
- InjectVerification::CaptureContainsToken
809
- );
810
- let evidence = evidence.unwrap();
811
- assert_eq!(evidence.phase, NativeInputPhase::Accepted);
812
- assert!(evidence.capsule.is_none());
813
- assert_eq!(evidence.baseline_capsules, ["[Pasted text #1 +30 lines]"]);
814
- let state = f.state.lock().unwrap();
815
- assert_eq!((state.pasted, state.entered), (1, 1));
816
- assert!(state.stage_captures[1] >= 2);
817
- }
818
-
819
- #[test]
820
- fn native_input_cursor_foreign_expanded_followup_is_zero_effect() {
821
- let f = Fixture::new(Mode::CursorExpandedDirty);
822
- f.state.lock().unwrap().provider = Provider::CursorAgent;
823
- let (report, _) = f.inject();
824
- assert!(report.is_err());
825
- let state = f.state.lock().unwrap();
826
- assert_eq!((state.pasted, state.entered), (0, 0));
827
- }
828
-
829
- #[test]
830
- fn native_input_cursor_history_only_composer_cannot_authorize_paste_or_enter() {
831
- let f = Fixture::new(Mode::CursorHistoryOnly);
832
- f.state.lock().unwrap().provider = Provider::CursorAgent;
833
- let (result, _) = f.inject();
834
- let state = f.state.lock().unwrap();
835
- assert_eq!(
836
- (state.pasted, state.entered),
837
- (0, 0),
838
- "old history is not current composer authority"
839
- );
840
- assert!(result.is_err());
841
- }
842
-
843
667
  #[test]
844
668
  fn native_input_buffer_uses_authoritative_message_not_first_quoted_marker() {
845
669
  let f = Fixture::new(Mode::Normal);
@@ -4101,3 +4101,154 @@ fn wrap_gap_true_on_joined_token_a_cannot_see() {
4101
4101
  "B must still cover the wrap gap A cannot see"
4102
4102
  );
4103
4103
  }
4104
+
4105
+ // ═════════════════════════════════════════════════════════════════════════
4106
+ // #379: Claude Code echoes the submitted turn right above its composer box
4107
+ // ═════════════════════════════════════════════════════════════════════════
4108
+
4109
+ const CLAUDE_379_MARKER: &str = "[team-agent-token:msg_claude379]";
4110
+
4111
+ /// A 56-column Claude Code 2.1.309 pane as tmux captures it: history, the rows
4112
+ /// above the box, the composer between two rules (`❯` + U+00A0), then the footer.
4113
+ fn claude_379_frame(history: &str, above: &str, composer: &str) -> String {
4114
+ let rule = "─".repeat(56);
4115
+ format!(
4116
+ "{history}\n\n{above}\n ◐ medium · /effort\n{rule}\n❯\u{a0}{composer}\n{rule}\n ⏵⏵ bypass permissions on (shift+tab to cycle)\n"
4117
+ )
4118
+ }
4119
+
4120
+ fn claude_379_payload() -> String {
4121
+ format!("Team Agent message from leader:\n\nline1\nline2\n\n{CLAUDE_379_MARKER}")
4122
+ }
4123
+
4124
+ /// The submitted turn as Claude draws it in history: `❯` then indented rows.
4125
+ fn claude_379_echo() -> String {
4126
+ claude_379_payload()
4127
+ .lines()
4128
+ .enumerate()
4129
+ .map(|(i, line)| match (i, line.is_empty()) {
4130
+ (0, _) => format!("❯ {line}"),
4131
+ (_, true) => String::new(),
4132
+ _ => format!(" {line}"),
4133
+ })
4134
+ .collect::<Vec<_>>()
4135
+ .join("\n")
4136
+ }
4137
+
4138
+ #[test]
4139
+ fn issue379_history_echo_above_the_claude_box_is_not_composer() {
4140
+ let text = normalize_capture(&claude_379_frame(&claude_379_echo(), "· Waddling…", ""));
4141
+ assert!(
4142
+ super::token_in_bottom_n(&text, CLAUDE_379_MARKER, 15),
4143
+ "fixture: the echo sits inside the legacy bottom-15 window"
4144
+ );
4145
+ assert!(!super::should_resubmit_enter(&text, CLAUDE_379_MARKER, None));
4146
+ assert_eq!(
4147
+ super::consumption_from_capture(&text, CLAUDE_379_MARKER, true, None),
4148
+ Some(true)
4149
+ );
4150
+ assert_eq!(
4151
+ super::consumption_from_capture(
4152
+ &text,
4153
+ CLAUDE_379_MARKER,
4154
+ false,
4155
+ Some(super::PasteLatch::HashId(1))
4156
+ ),
4157
+ Some(true)
4158
+ );
4159
+ // The token still between the rules is still composer.
4160
+ let pending = normalize_capture(&claude_379_frame("", "", &format!("ping {CLAUDE_379_MARKER}")));
4161
+ assert!(super::should_resubmit_enter(&pending, CLAUDE_379_MARKER, None));
4162
+ assert_eq!(
4163
+ super::consumption_from_capture(&pending, CLAUDE_379_MARKER, true, None),
4164
+ Some(false)
4165
+ );
4166
+ }
4167
+
4168
+ #[test]
4169
+ fn issue379_claude_busy_is_the_live_spinner_row_not_a_glyph_scan() {
4170
+ for spinner in ["· Waddling…", "✻ Baking… (3s · thinking)", "✽ Beboppin'…"] {
4171
+ let text = normalize_capture(&claude_379_frame("❯ question", spinner, ""));
4172
+ let busy = super::provider_busy_signal_match(&text);
4173
+ assert_eq!(
4174
+ busy.map(|signal| signal.kind),
4175
+ Some(BusySignalKind::SpinnerGlyph),
4176
+ "{spinner}"
4177
+ );
4178
+ assert_eq!(
4179
+ observe_turn_from_capture(&text, Some(CLAUDE_379_MARKER)),
4180
+ TurnVerification::LeaderNewTurnBoundaryVerified
4181
+ );
4182
+ }
4183
+ // Todo rows under the spinner push it past the bottom window; still busy.
4184
+ let todos = "✶ Sprouting…\n ⎿ ☐ one\n ☐ two\n ☐ three\n ☐ four\n ☐ five\n ☐ six";
4185
+ let text = normalize_capture(&claude_379_frame("❯ question", todos, ""));
4186
+ assert!(super::provider_busy_signal_match(&text).is_some());
4187
+ // A finished turn's summary and transcript prose are not a live turn.
4188
+ let done = normalize_capture(&claude_379_frame(
4189
+ "❯ question\n\n⏺ Still working on thinking about it.",
4190
+ "✻ Worked for 3s",
4191
+ "",
4192
+ ));
4193
+ assert!(super::provider_busy_signal_match(&done).is_none());
4194
+ // Queued input is native custody: busy, and not composer text.
4195
+ let queued = normalize_capture(&claude_379_frame(
4196
+ &claude_379_echo(),
4197
+ "",
4198
+ "Press up to edit queued messages",
4199
+ ));
4200
+ assert!(super::provider_busy_signal_match(&queued).is_some());
4201
+ assert!(!super::should_resubmit_enter(&queued, CLAUDE_379_MARKER, None));
4202
+ }
4203
+
4204
+ #[test]
4205
+ fn issue379_claude_submit_verifies_on_the_first_enter() {
4206
+ let folded = claude_379_frame("⏺ earlier reply", "", "[Pasted text #1 +5 lines]");
4207
+ let submitted = claude_379_frame(&claude_379_echo(), "· Waddling… (1s · thinking)", "");
4208
+ let (be, rec) = backend_folded(&folded, &submitted);
4209
+ let report = be
4210
+ .inject(
4211
+ &Target::Pane(PaneId::new("%7")),
4212
+ &InjectPayload::Text(claude_379_payload()),
4213
+ Key::Enter,
4214
+ true,
4215
+ )
4216
+ .expect("inject");
4217
+ assert_eq!(
4218
+ report.submit_verification,
4219
+ SubmitVerification::EnterSentWithoutPlaceholderCheck
4220
+ );
4221
+ let calls = rec.lock().unwrap().clone();
4222
+ assert_eq!(count_submit_enters(&calls), 1, "no extra Enter into an empty composer; calls={calls:?}");
4223
+ // Enter not taken: the folded paste stays between the rules.
4224
+ let (be, _rec) = backend_folded(&folded, &folded);
4225
+ let report = be
4226
+ .inject(
4227
+ &Target::Pane(PaneId::new("%7")),
4228
+ &InjectPayload::Text(claude_379_payload()),
4229
+ Key::Enter,
4230
+ true,
4231
+ )
4232
+ .expect("inject");
4233
+ assert_eq!(
4234
+ report.submit_verification,
4235
+ SubmitVerification::SubmitConsumptionUnverified
4236
+ );
4237
+ }
4238
+
4239
+ #[test]
4240
+ fn issue379_busy_seen_in_any_post_enter_sample_survives_a_quiet_final_frame() {
4241
+ let mut diagnostics = super::ConsumptionDiagnostics::default();
4242
+ let busy = normalize_capture(&claude_379_frame("❯ question", "✳ Moseying…", ""));
4243
+ let quiet = normalize_capture(&claude_379_frame("❯ question", "⏺ Streaming reply", ""));
4244
+ for text in [&busy, &quiet] {
4245
+ diagnostics.record(super::consumption_capture_observation(
4246
+ text,
4247
+ Some(CLAUDE_379_MARKER),
4248
+ false,
4249
+ None,
4250
+ ));
4251
+ }
4252
+ assert!(diagnostics.busy_seen);
4253
+ assert!(diagnostics.busy_signal_kind.is_none(), "latest sample stays as observed");
4254
+ }
@@ -1702,7 +1702,7 @@ thread_local! {
1702
1702
  static CURSOR_SINGLE_ENTER: Cell<bool> = const { Cell::new(false) };
1703
1703
  }
1704
1704
 
1705
- /// Run `f` with a paste→Enter floor. Delivery sets 1s for CursorAgent and Grok.
1705
+ /// Run `f` with a paste→Enter floor. Delivery sets 1s for Grok.
1706
1706
  /// Tests pass a small non-zero Duration to cover the sleep branch.
1707
1707
  /// Default is ZERO — claude/codex and unset callers pay nothing.
1708
1708
  /// This is not TEAM_AGENT_TEST_TMP (that var is a path, always set in seats).
@@ -1712,7 +1712,7 @@ thread_local! {
1712
1712
  /// floor: 本次生效的最小间隔;ZERO 表示不等
1713
1713
  /// f: 在该地板下执行的闭包
1714
1714
  /// returns: 原样返回 f 的返回值
1715
- /// boundary: thread_local 作用域,不跨线程;只设阈值,真正的等待发生在 sleep_remaining_paste_to_submit_floor;默认 ZERO,只有 delivery 对 cursor 才设 1s
1715
+ /// boundary: thread_local 作用域,不跨线程;只设阈值,真正的等待发生在 sleep_remaining_paste_to_submit_floor;默认 ZERO,只有 delivery 对 Grok 才设 1s
1716
1716
  /// ---
1717
1717
  pub fn with_paste_to_submit_floor<R>(floor: Duration, f: impl FnOnce() -> R) -> R {
1718
1718
  PASTE_TO_SUBMIT_FLOOR.with(|cell| {
@@ -1733,7 +1733,7 @@ pub(crate) fn current_paste_to_submit_floor() -> Duration {
1733
1733
  }
1734
1734
 
1735
1735
  /// ---
1736
- /// purpose: cursor 注入单回车闸(delivery 仅对 CursorAgent 打开)
1736
+ /// purpose: 单回车闸(delivery 仅对 Pi 打开;最初为 Cursor 实测)
1737
1737
  /// contract: 默认关;打开后重试 Enter 仅当 token 仍在输入区且无 busy
1738
1738
  /// boundary: 不改 claude/grok/codex 默认重试;测试隔离下默认关
1739
1739
  /// ---
@@ -1891,6 +1891,16 @@ fn token_in_bottom_n(text: &str, marker: &str, n: usize) -> bool {
1891
1891
  .any(|line| line.contains(marker))
1892
1892
  }
1893
1893
 
1894
+ /// #379: Claude Code echoes the submitted turn right above its composer box,
1895
+ /// well inside the bottom-15 window. When that box is recognized only the text
1896
+ /// between its rules is composer; otherwise the whole tail stays in charge.
1897
+ fn composer_view(text: &str) -> std::borrow::Cow<'_, str> {
1898
+ match team_agent_contract::providers::claude::interaction::inspect_legacy_composer(text) {
1899
+ Some((_, current)) => std::borrow::Cow::Owned(current),
1900
+ None => std::borrow::Cow::Borrowed(text),
1901
+ }
1902
+ }
1903
+
1894
1904
  /// purpose: token 在本轮注入中的三态观测
1895
1905
  /// contract:
1896
1906
  /// - Visible: 当前 capture 可见
@@ -2010,7 +2020,7 @@ fn latch_paste(text: &str, current: Option<PasteLatch>) -> Option<PasteLatch> {
2010
2020
  if current.is_some() {
2011
2021
  return current;
2012
2022
  }
2013
- let prompt = pasted_prompt_in_composer(text, 15)?;
2023
+ let prompt = pasted_prompt_in_composer(&composer_view(text), 15)?;
2014
2024
  if let Some(id) = prompt.id {
2015
2025
  return Some(PasteLatch::HashId(id));
2016
2026
  }
@@ -2053,6 +2063,7 @@ fn consumption_from_placeholder(text: &str, tracked: Option<PasteLatch>) -> Opti
2053
2063
  /// boundary: 不重粘文本;不把不同 grok 行数当成可重按的同一次;tracked 为 None 时占位符路径一律不重按(token 仍在底 15 非空行的重按与 tracked 无关)
2054
2064
  /// ---
2055
2065
  pub(crate) fn should_resubmit_enter(text: &str, marker: &str, tracked: Option<PasteLatch>) -> bool {
2066
+ let text = &*composer_view(text);
2056
2067
  if token_in_bottom_n(text, marker, 15) {
2057
2068
  return true;
2058
2069
  }
@@ -2087,7 +2098,8 @@ pub(crate) fn this_paste_identity_in_composer(
2087
2098
  marker: &str,
2088
2099
  tracked: Option<PasteLatch>,
2089
2100
  ) -> bool {
2090
- should_resubmit_enter(text, marker, tracked) || composer_joined(text, 15).contains(marker)
2101
+ should_resubmit_enter(text, marker, tracked)
2102
+ || composer_joined(&composer_view(text), 15).contains(marker)
2091
2103
  }
2092
2104
 
2093
2105
  /// ---
@@ -2149,6 +2161,7 @@ pub(crate) fn should_resubmit_enter_cursor(text: &str, marker: &str) -> bool {
2149
2161
  /// boundary: token 出现在未折叠的高块里不算完成(按早了);只判「能不能按」,不判「按了有没有成」
2150
2162
  /// ---
2151
2163
  pub(crate) fn paste_ready_for_enter(text: &str, marker: &str) -> bool {
2164
+ let text = &*composer_view(text);
2152
2165
  if pasted_prompt_in_composer(text, 15).is_some() {
2153
2166
  return true;
2154
2167
  }
@@ -2185,6 +2198,7 @@ pub(crate) fn consumption_from_capture(
2185
2198
  token_ever_visible: bool,
2186
2199
  tracked: Option<PasteLatch>,
2187
2200
  ) -> Option<bool> {
2201
+ let text = &*composer_view(text);
2188
2202
  let token_now = token_in_bottom_n(text, marker, 15);
2189
2203
  match token_sighting(token_now, token_ever_visible) {
2190
2204
  TokenSighting::Visible => Some(false),
@@ -2231,10 +2245,13 @@ struct ConsumptionDiagnostics {
2231
2245
  current_marker_in_bottom_15: Option<bool>,
2232
2246
  paste_identity_in_composer: Option<bool>,
2233
2247
  consumption_from_capture_result: Option<bool>,
2248
+ /// Busy in any post-Enter sample: one final frame lands on a random spinner phase.
2249
+ busy_seen: bool,
2234
2250
  }
2235
2251
 
2236
2252
  impl ConsumptionDiagnostics {
2237
2253
  fn record(&mut self, observation: ConsumptionCaptureObservation) {
2254
+ self.busy_seen |= observation.busy.is_some();
2238
2255
  self.busy_signal_kind = observation.busy.map(|match_| match_.kind);
2239
2256
  self.busy_line_from_bottom = observation.busy.map(|match_| match_.line_from_bottom);
2240
2257
  self.current_marker_in_bottom_15 = observation.marker_in_bottom_15;
@@ -2316,6 +2333,22 @@ fn busy_signal_kind_in_line(line: &str) -> Option<BusySignalKind> {
2316
2333
  }
2317
2334
 
2318
2335
  fn provider_busy_signal_match(text: &str) -> Option<BusySignalMatch> {
2336
+ use team_agent_contract::{contract::delivery::InputSurface, providers::claude::interaction};
2337
+ // #379: Claude Code's box decides alone. Its spinner glyph animates through
2338
+ // `·` and a finished turn leaves `✻ Worked for 3s` in the window, so a
2339
+ // per-line glyph scan is neither stable nor live.
2340
+ if let Some((surface, _)) = interaction::inspect_legacy_composer(text) {
2341
+ let row = text
2342
+ .lines()
2343
+ .rev()
2344
+ .filter(|line| !line.trim().is_empty())
2345
+ .position(interaction::spinner_row)
2346
+ .unwrap_or(0);
2347
+ return (surface == InputSurface::Busy).then_some(BusySignalMatch {
2348
+ kind: BusySignalKind::SpinnerGlyph,
2349
+ line_from_bottom: u8::try_from(row).unwrap_or(u8::MAX),
2350
+ });
2351
+ }
2319
2352
  text.lines()
2320
2353
  .rev()
2321
2354
  .filter(|line| !line.trim().is_empty())
@@ -2351,6 +2384,7 @@ pub(crate) fn observe_turn_from_capture(text: &str, marker: Option<&str>) -> Tur
2351
2384
  if provider_busy_signal_in_tail(text) {
2352
2385
  return TurnVerification::LeaderNewTurnBoundaryVerified;
2353
2386
  }
2387
+ let text = &*composer_view(text);
2354
2388
  let paste_still = pasted_prompt_in_composer(text, 15).is_some();
2355
2389
  let token_still = marker
2356
2390
  .map(|m| token_in_bottom_n(text, m, 15))
@@ -2382,8 +2416,9 @@ fn submit_attempt_observation(
2382
2416
  let marker_position = marker.and_then(|m| marker_position_from_bottom(&captured.text, m));
2383
2417
  // marker 在时也走 pasted_prompt_match:折叠占位符是编排长粘贴的正信号,
2384
2418
  // 不能只在无 token 载荷上才认。matched 仍表示「composer 里还有待提交信号」。
2419
+ let composer = composer_view(&captured.text);
2385
2420
  let (matched, matched_literal, where_in_tail) = if let Some(marker) = marker {
2386
- if token_in_bottom_n(&captured.text, marker, 15) {
2421
+ if token_in_bottom_n(&composer, marker, 15) {
2387
2422
  (
2388
2423
  true,
2389
2424
  marker_position.map(|_| marker.to_string()),
@@ -2391,7 +2426,7 @@ fn submit_attempt_observation(
2391
2426
  )
2392
2427
  } else if let Some((literal, where_in_tail)) = pasted_prompt_match(&captured.text) {
2393
2428
  (
2394
- pasted_prompt_in_composer(&captured.text, 15).is_some(),
2429
+ pasted_prompt_in_composer(&composer, 15).is_some(),
2395
2430
  Some(literal.to_string()),
2396
2431
  Some(where_in_tail),
2397
2432
  )
@@ -3673,7 +3708,7 @@ impl Transport for TmuxBackend {
3673
3708
  marker,
3674
3709
  inject_start.elapsed().as_millis() as u64,
3675
3710
  ));
3676
- if observation.busy.is_some() {
3711
+ if consumption_diagnostics.busy_seen {
3677
3712
  consumption_reason = SubmitConsumptionReason::FallbackBusy;
3678
3713
  SubmitVerification::EnterSentWithoutPlaceholderCheck
3679
3714
  } else {