@team-agent/installer 0.5.126 → 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.
- package/Cargo.lock +1 -1
- package/Cargo.toml +1 -1
- package/README.md +11 -0
- package/crates/team-agent/src/cli/adapters.rs +3 -13
- package/crates/team-agent/src/cli/arguments.rs +4 -0
- package/crates/team-agent/src/cli/diagnose.rs +68 -91
- package/crates/team-agent/src/cli/emit.rs +61 -28
- package/crates/team-agent/src/cli/grok_slot.rs +88 -3
- package/crates/team-agent/src/cli/intent/runtime.rs +38 -9
- package/crates/team-agent/src/cli/intent/runtime_tests.rs +147 -11
- package/crates/team-agent/src/cli/intent/tests.rs +10 -12
- package/crates/team-agent/src/cli/intent.rs +1 -1
- package/crates/team-agent/src/cli/mod.rs +38 -9
- package/crates/team-agent/src/cli/models.rs +789 -186
- package/crates/team-agent/src/cli/schedule.rs +175 -0
- package/crates/team-agent/src/cli/send/persist.rs +0 -36
- package/crates/team-agent/src/cli/send/presentation.rs +1 -1
- package/crates/team-agent/src/cli/send.rs +108 -110
- package/crates/team-agent/src/cli/spec.rs +6 -0
- package/crates/team-agent/src/cli/status_port/brief.rs +5 -67
- package/crates/team-agent/src/cli/tests/leader_watch.rs +12 -62
- package/crates/team-agent/src/cli/tests/mod.rs +3 -3
- package/crates/team-agent/src/cli/tests/named_address.rs +11 -10
- package/crates/team-agent/src/cli/tests/run_delegation.rs +12 -9
- package/crates/team-agent/src/cli/tests/status_send.rs +70 -273
- package/crates/team-agent/src/compiler/tests.rs +39 -27
- package/crates/team-agent/src/compiler.rs +206 -6
- package/crates/team-agent/src/contract_runtime/backend.rs +181 -11
- package/crates/team-agent/src/contract_runtime/commands.rs +338 -7
- package/crates/team-agent/src/contract_runtime/config.rs +30 -19
- package/crates/team-agent/src/contract_runtime/config_tests.rs +24 -4
- package/crates/team-agent/src/contract_runtime/discovery.rs +12 -1
- package/crates/team-agent/src/contract_runtime/fork.rs +3 -10
- package/crates/team-agent/src/contract_runtime/framework.rs +28 -14
- package/crates/team-agent/src/contract_runtime/mcp.rs +19 -24
- package/crates/team-agent/src/contract_runtime/prompt.rs +2 -2
- package/crates/team-agent/src/contract_runtime/registry.rs +93 -130
- package/crates/team-agent/src/coordinator/steps/abnormal.rs +45 -5
- package/crates/team-agent/src/coordinator/tests/api_error_recovery.rs +8 -29
- package/crates/team-agent/src/coordinator/tests/energy.rs +4 -4
- package/crates/team-agent/src/coordinator/tests/health_sync.rs +44 -2
- package/crates/team-agent/src/coordinator/tests/main_preserved.rs +2 -2
- package/crates/team-agent/src/coordinator/tests/spine.rs +1 -1
- package/crates/team-agent/src/coordinator/tests/takeover.rs +3 -3
- package/crates/team-agent/src/coordinator/tick.rs +1 -89
- package/crates/team-agent/src/db/message_store.rs +7 -65
- package/crates/team-agent/src/direct_delivery.rs +368 -0
- package/crates/team-agent/src/inbox_store.rs +169 -0
- package/crates/team-agent/src/leader/registry.rs +5 -0
- package/crates/team-agent/src/leader/start.rs +2 -1
- package/crates/team-agent/src/leader/tests/lease_api.rs +2 -2
- package/crates/team-agent/src/leader/tests/prompt_contract.rs +1 -0
- package/crates/team-agent/src/lib.rs +2 -0
- package/crates/team-agent/src/lifecycle/launch/add_agent.rs +33 -0
- package/crates/team-agent/src/lifecycle/launch/add_agent_state.rs +206 -1
- package/crates/team-agent/src/lifecycle/launch/clone_agent.rs +28 -2
- package/crates/team-agent/src/lifecycle/launch/fork_agent.rs +36 -179
- package/crates/team-agent/src/lifecycle/launch/fork_entry.rs +87 -6
- package/crates/team-agent/src/lifecycle/launch/mcp_config.rs +13 -488
- package/crates/team-agent/src/lifecycle/launch/pi_mcp.rs +351 -81
- package/crates/team-agent/src/lifecycle/launch/pi_mcp_extension.js +3 -4
- package/crates/team-agent/src/lifecycle/launch/quick_start.rs +26 -2
- package/crates/team-agent/src/lifecycle/launch/spawn.rs +41 -31
- package/crates/team-agent/src/lifecycle/launch.rs +27 -12
- package/crates/team-agent/src/lifecycle/profile_launch.rs +318 -64
- package/crates/team-agent/src/lifecycle/restart/agent.rs +1 -0
- package/crates/team-agent/src/lifecycle/restart/avatar.rs +1798 -0
- package/crates/team-agent/src/lifecycle/restart/claude_fork.rs +163 -0
- package/crates/team-agent/src/lifecycle/restart/common.rs +298 -133
- package/crates/team-agent/src/lifecycle/restart/remove.rs +129 -0
- package/crates/team-agent/src/lifecycle/restart/selection.rs +5 -5
- package/crates/team-agent/src/lifecycle/restart.rs +4 -0
- package/crates/team-agent/src/lifecycle/role_config.rs +79 -27
- package/crates/team-agent/src/lifecycle/tests/acceptance_b_batch_red.rs +1 -1
- package/crates/team-agent/src/lifecycle/tests/agent_ops.rs +8 -12
- package/crates/team-agent/src/lifecycle/tests/behavioral_diff_264_red.rs +37 -240
- package/crates/team-agent/src/lifecycle/tests/claude_compatible_config_red.rs +325 -0
- package/crates/team-agent/src/lifecycle/tests/claude_profile_launch_red.rs +320 -8
- package/crates/team-agent/src/lifecycle/tests/cli_argv_routing_red.rs +329 -70
- package/crates/team-agent/src/lifecycle/tests/clone_fork_copilot_perms_red.rs +378 -4
- package/crates/team-agent/src/lifecycle/tests/communication_mode_runtime_contract_red.rs +25 -39
- package/crates/team-agent/src/lifecycle/tests/copilot_provider_red.rs +7 -11
- package/crates/team-agent/src/lifecycle/tests/core.rs +39 -36
- package/crates/team-agent/src/lifecycle/tests/f032_startup_prompt_best_effort_red.rs +22 -8
- package/crates/team-agent/src/lifecycle/tests/fixtures/pi_native_mcp_host.mjs +2 -1
- package/crates/team-agent/src/lifecycle/tests/grok_require_explicit_model_red.rs +15 -133
- package/crates/team-agent/src/lifecycle/tests/harvest2_a_batch_red.rs +60 -20
- package/crates/team-agent/src/lifecycle/tests/host_cotenant_death_p0_contract.rs +30 -67
- package/crates/team-agent/src/lifecycle/tests/issue238_codex_effort_contract.rs +3 -31
- package/crates/team-agent/src/lifecycle/tests/lane_ops.rs +194 -169
- package/crates/team-agent/src/lifecycle/tests/launch_spawn.rs +164 -282
- package/crates/team-agent/src/lifecycle/tests/lifecycle_rollback_red.rs +15 -78
- package/crates/team-agent/src/lifecycle/tests/main_preserved.rs +7 -7
- package/crates/team-agent/src/lifecycle/tests/mcp_tool_name_format_red.rs +6 -6
- package/crates/team-agent/src/lifecycle/tests/phase_b_contracts.rs +75 -69
- package/crates/team-agent/src/lifecycle/tests/phase_golden.rs +2 -10
- package/crates/team-agent/src/lifecycle/tests/pi_catalog_red.rs +18 -6
- package/crates/team-agent/src/lifecycle/tests/pi_command_red.rs +70 -52
- package/crates/team-agent/src/lifecycle/tests/pi_compiler_red.rs +210 -0
- package/crates/team-agent/src/lifecycle/tests/pi_dual_entry_red.rs +157 -4
- package/crates/team-agent/src/lifecycle/tests/pi_executable_mcp_red.rs +526 -10
- package/crates/team-agent/src/lifecycle/tests/pi_fork_session_inheritance_red.rs +1419 -0
- package/crates/team-agent/src/lifecycle/tests/pi_lifecycle_doctor_red.rs +68 -1
- package/crates/team-agent/src/lifecycle/tests/pi_native_mcp_capability_red.rs +34 -12
- package/crates/team-agent/src/lifecycle/tests/pi_session_delivery_red.rs +94 -2
- package/crates/team-agent/src/lifecycle/tests/quick_start_worker_readiness_red.rs +14 -15
- package/crates/team-agent/src/lifecycle/tests/restart.rs +12 -153
- package/crates/team-agent/src/lifecycle/tests/restart_build_before_destroy_0540_contract.rs +27 -5
- package/crates/team-agent/src/lifecycle/tests/restart_liveness_red.rs +59 -10
- package/crates/team-agent/src/lifecycle/tests/restart_rebind_hotfix_252_red.rs +47 -6
- package/crates/team-agent/src/lifecycle/tests/restart_session_capture_red.rs +3 -1374
- package/crates/team-agent/src/lifecycle/tests/resume_recover_red.rs +27 -10
- package/crates/team-agent/src/lifecycle/tests/status_credential_redaction_contract.rs +7 -7
- package/crates/team-agent/src/lifecycle/tests/subprep_codex_trust_roundtrip_red.rs +67 -313
- package/crates/team-agent/src/lifecycle/tests/swallow_batch4_semantics_red.rs +254 -2
- package/crates/team-agent/src/lifecycle/tests/team_in_team_identity_scope_red.rs +2 -2
- package/crates/team-agent/src/lifecycle/tests/team_in_team_sibling_quick_start_red.rs +1 -1
- package/crates/team-agent/src/lifecycle/tests/team_in_team_state_scope_red.rs +2 -2
- package/crates/team-agent/src/lifecycle/tests/team_key_retirement_txn_red.rs +4 -4
- package/crates/team-agent/src/lifecycle/tests/upgrade_compat_0211_red.rs +74 -19
- package/crates/team-agent/src/lifecycle/tests/verify_rs031_window_consistency_red.rs +38 -39
- package/crates/team-agent/src/lifecycle/tests/worker_spawn_env_red.rs +51 -88
- package/crates/team-agent/src/lifecycle/tests.rs +3 -4
- package/crates/team-agent/src/lifecycle/types.rs +18 -5
- package/crates/team-agent/src/lifecycle/worker_command_context.rs +43 -50
- package/crates/team-agent/src/mcp_server/readiness.rs +130 -149
- package/crates/team-agent/src/mcp_server/readiness_tests.rs +86 -109
- package/crates/team-agent/src/mcp_server/tests/scoped.rs +21 -31
- package/crates/team-agent/src/mcp_server/tests/send.rs +72 -107
- package/crates/team-agent/src/mcp_server/tests/tools.rs +10 -12
- package/crates/team-agent/src/mcp_server/tools.rs +70 -196
- package/crates/team-agent/src/messaging/delivery.rs +143 -253
- package/crates/team-agent/src/messaging/delivery_consumption_tests.rs +5 -5
- package/crates/team-agent/src/messaging/helpers.rs +1 -19
- package/crates/team-agent/src/messaging/mod.rs +1 -0
- package/crates/team-agent/src/messaging/reminders.rs +316 -0
- package/crates/team-agent/src/messaging/scheduler.rs +7 -1
- package/crates/team-agent/src/messaging/tests/dup_inject.rs +255 -150
- package/crates/team-agent/src/messaging/tests/main_preserved.rs +2 -2
- package/crates/team-agent/src/messaging/tests/runtime.rs +9 -115
- package/crates/team-agent/src/messaging/tests/spine.rs +44 -24
- package/crates/team-agent/src/messaging/tests/wave2.rs +13 -20
- package/crates/team-agent/src/messaging/types.rs +1 -0
- package/crates/team-agent/src/provider/adapter.rs +208 -254
- package/crates/team-agent/src/provider/adapters/claude.rs +78 -0
- package/crates/team-agent/src/provider/adapters/claude_fork.rs +131 -0
- package/crates/team-agent/src/provider/adapters/mod.rs +7 -7
- package/crates/team-agent/src/provider/adapters/pi.rs +106 -0
- package/crates/team-agent/src/provider/classify.rs +1 -66
- package/crates/team-agent/src/provider/model_catalog.rs +201 -13
- package/crates/team-agent/src/provider/session/capture.rs +111 -111
- package/crates/team-agent/src/provider/session/context_fork/claude.rs +123 -0
- package/crates/team-agent/src/provider/session/context_fork/outcome.rs +10 -18
- package/crates/team-agent/src/provider/session/context_fork.rs +87 -74
- package/crates/team-agent/src/provider/session/mod.rs +2 -3
- package/crates/team-agent/src/provider/session_scan/claude.rs +523 -0
- package/crates/team-agent/src/provider/session_scan/common.rs +47 -47
- package/crates/team-agent/src/provider/session_scan/pi.rs +34 -1
- package/crates/team-agent/src/provider/session_scan.rs +13 -13
- package/crates/team-agent/src/provider/tests/adapter.rs +127 -121
- package/crates/team-agent/src/provider/tests/classify.rs +0 -53
- package/crates/team-agent/src/provider/tests/command_helpers.rs +11 -19
- package/crates/team-agent/src/provider/tests/idle.rs +13 -19
- package/crates/team-agent/src/provider/types.rs +0 -4
- package/crates/team-agent/src/provider/wire.rs +34 -20
- package/crates/team-agent/src/state/abnormal_watch/tests/mod.rs +1 -1
- package/crates/team-agent/src/state/persist.rs +6 -6
- package/crates/team-agent/src/state/projection.rs +1 -1
- package/crates/team-agent/src/state/repository/tests.rs +2 -2
- package/crates/team-agent/src/test_support/models_timeout_fixture.rs +144 -0
- package/crates/team-agent/src/tmux_backend/tests.rs +0 -151
- package/crates/team-agent/src/tmux_backend.rs +9 -43
- package/package.json +4 -4
- package/skills/team-agent/SKILL.md +7 -8
- package/skills/team-agent/command-coverage.json +15 -1
- package/skills/team-agent/docs/reference/team-agent-operator.md +5 -3
- package/skills/team-agent/references/team-agent-operator.md +5 -3
- package/crates/team-agent/src/lifecycle/launch/grok_per_seat.rs +0 -260
- package/crates/team-agent/src/lifecycle/tests/codex_weak_window_attribution_red.rs +0 -683
- package/crates/team-agent/src/lifecycle/tests/grok_effort_argv_red.rs +0 -247
- package/crates/team-agent/src/lifecycle/tests/grok_mcp_overlay_red.rs +0 -507
- package/crates/team-agent/src/lifecycle/tests/grok_restart_resume_red.rs +0 -300
- package/crates/team-agent/src/provider/adapters/codex.rs +0 -101
- package/crates/team-agent/src/provider/adapters/grok.rs +0 -67
- package/crates/team-agent/src/provider/session/context_fork/codex.rs +0 -514
- package/crates/team-agent/src/provider/session_scan/codex.rs +0 -326
- package/crates/team-agent/src/provider/session_scan/grok.rs +0 -288
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
fn report_result_infers_agent_from_env_when_not_explicit() {
|
|
3
3
|
// env identity present, no explicit agent_id → envelope.agent_id == env id.
|
|
4
4
|
let tools = TeamOrchestratorTools::with_identity(
|
|
5
|
-
&
|
|
5
|
+
&seed_state_ws("report-env", &json!({"teams": {"teamA": {"agents": {}}}})),
|
|
6
6
|
Some(AgentId::new("worker-7")),
|
|
7
7
|
Some(TeamKey::new("teamA")),
|
|
8
8
|
);
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
#[test]
|
|
48
48
|
fn report_result_accepts_explicit_captured_agent() {
|
|
49
49
|
let tools = TeamOrchestratorTools::with_identity(
|
|
50
|
-
&
|
|
50
|
+
&seed_state_ws("report-explicit-match", &json!({"teams": {"teamA": {"agents": {}}}})),
|
|
51
51
|
Some(AgentId::new("worker-7")),
|
|
52
52
|
Some(TeamKey::new("teamA")),
|
|
53
53
|
);
|
|
@@ -130,7 +130,7 @@
|
|
|
130
130
|
}
|
|
131
131
|
|
|
132
132
|
#[test]
|
|
133
|
-
fn
|
|
133
|
+
fn report_result_ignores_current_turn_and_old_delivered_attribution() {
|
|
134
134
|
let ws = unique_ws("report-current-message");
|
|
135
135
|
seed_report_message(
|
|
136
136
|
&ws,
|
|
@@ -153,9 +153,7 @@
|
|
|
153
153
|
"target_resolved",
|
|
154
154
|
"2026-07-06T13:27:35.000000+00:00",
|
|
155
155
|
);
|
|
156
|
-
//
|
|
157
|
-
// target_resolved alone is not physical-submit proof. Current-turn
|
|
158
|
-
// attribution comes from the state pointer armed at physical submit.
|
|
156
|
+
// Even an armed legacy coordinator pointer must not determine attribution.
|
|
159
157
|
seed_report_scope_state(
|
|
160
158
|
&ws,
|
|
161
159
|
&json!({
|
|
@@ -194,13 +192,13 @@
|
|
|
194
192
|
let v = serde_json::to_value(&ok).unwrap();
|
|
195
193
|
assert_eq!(
|
|
196
194
|
v.get("task_id"),
|
|
197
|
-
Some(&json!("
|
|
198
|
-
"
|
|
195
|
+
Some(&json!("manual")),
|
|
196
|
+
"decoupled reports do not infer attribution from delivery or coordinator state"
|
|
199
197
|
);
|
|
200
198
|
}
|
|
201
199
|
|
|
202
200
|
#[test]
|
|
203
|
-
fn
|
|
201
|
+
fn report_result_ignores_target_resolved_and_assigned_task_fallback() {
|
|
204
202
|
let ws = unique_ws("report-target-resolved-no-current");
|
|
205
203
|
seed_report_message(
|
|
206
204
|
&ws,
|
|
@@ -249,14 +247,14 @@
|
|
|
249
247
|
);
|
|
250
248
|
assert_eq!(
|
|
251
249
|
v.get("task_id"),
|
|
252
|
-
Some(&json!("
|
|
253
|
-
"
|
|
250
|
+
Some(&json!("manual")),
|
|
251
|
+
"only explicit task attribution is retained in the decoupled inbox"
|
|
254
252
|
);
|
|
255
253
|
}
|
|
256
254
|
|
|
257
255
|
#[test]
|
|
258
256
|
fn report_result_does_not_backfill_old_delivered_message_after_latest_result() {
|
|
259
|
-
let ws =
|
|
257
|
+
let ws = seed_state_ws("report-no-old-backfill", &json!({"teams": {"gate055": {"agents": {}}}}));
|
|
260
258
|
seed_report_message(
|
|
261
259
|
&ws,
|
|
262
260
|
"msg_old",
|
|
@@ -13,7 +13,7 @@ use crate::model::ids::{AgentId, TaskId, TeamKey};
|
|
|
13
13
|
use crate::event_log::EventLog;
|
|
14
14
|
|
|
15
15
|
// ── REUSE: step 5 state persist / projection ────────────────────────────────
|
|
16
|
-
use crate::
|
|
16
|
+
use crate::direct_delivery::snapshot as load_runtime_state;
|
|
17
17
|
|
|
18
18
|
// ── REUSE: step 11 messaging delegate surface ───────────────────────────────
|
|
19
19
|
use crate::messaging::{self, DeliveryStatus, MessageTarget, SendOptions, TrustedSender};
|
|
@@ -219,124 +219,66 @@ impl TeamOrchestratorTools {
|
|
|
219
219
|
mailbox: Option<&Value>,
|
|
220
220
|
presentation: Option<&Value>,
|
|
221
221
|
) -> Result<SendOutcome, ToolError> {
|
|
222
|
-
// A worker without a spawn-time identity cannot safely emit a message.
|
|
223
222
|
self.require_captured_identity("send_message")?;
|
|
224
|
-
let
|
|
225
|
-
crate::messaging::presentation::normalize_send_presentation(mailbox, presentation)
|
|
226
|
-
.map_err(|error| {
|
|
227
|
-
ToolError::new(
|
|
228
|
-
ToolErrorReason::InvalidToolArguments,
|
|
229
|
-
format!("invalid send routing: {error}"),
|
|
230
|
-
"PresentationError",
|
|
231
|
-
)
|
|
232
|
-
})?;
|
|
233
|
-
let presentation = normalized.request;
|
|
234
|
-
let deprecation = normalized.deprecation;
|
|
235
|
-
let canonical_owner_team = self.canonical_owner_team_key()?;
|
|
223
|
+
let _ = (task_id, requires_ack);
|
|
236
224
|
if matches!(scope_override, Some(Scope::Workspace)) {
|
|
237
|
-
return Err(self.rpc_scope_refused(
|
|
238
|
-
"send_message",
|
|
239
|
-
None,
|
|
240
|
-
scope_override.and_then(scope_override_name),
|
|
241
|
-
));
|
|
242
|
-
}
|
|
243
|
-
if let Some(err) = self.refuse_cross_team_peer(to, None) {
|
|
244
|
-
return Err(err);
|
|
225
|
+
return Err(self.rpc_scope_refused("send_message", None, Some("workspace")));
|
|
245
226
|
}
|
|
246
|
-
let
|
|
247
|
-
ToolError::new(
|
|
248
|
-
ToolErrorReason::McpScopeRefused,
|
|
249
|
-
"send_message requires framework-injected TEAM_AGENT_ID",
|
|
250
|
-
"IdentityError",
|
|
251
|
-
)
|
|
252
|
-
})?;
|
|
253
|
-
let sender = TrustedSender::from_runtime_identity(sender);
|
|
254
|
-
let ack = requires_ack.unwrap_or_else(|| requires_ack_for_target(to));
|
|
255
|
-
// C14/C15/C17 scope audit (#230 I-2/I-6 contract): emit mcp.scope_resolved
|
|
256
|
-
// for every worker-origin send before any routing/delivery — the funnel
|
|
257
|
-
// assertions grep this event to verify the worker call was scoped under the
|
|
258
|
-
// spawn-time owner-team env, not a back-inferred default.
|
|
259
|
-
EventLog::new(&self.workspace)
|
|
260
|
-
.write(
|
|
261
|
-
"mcp.scope_resolved",
|
|
262
|
-
serde_json::json!({
|
|
263
|
-
"tool": "send_message",
|
|
264
|
-
"sender": sender.as_str(),
|
|
265
|
-
"owner_team_id": canonical_owner_team.as_ref().map(TeamKey::as_str),
|
|
266
|
-
"to": match to {
|
|
267
|
-
MessageTarget::Single(t) => serde_json::Value::String(t.clone()),
|
|
268
|
-
MessageTarget::Broadcast => serde_json::Value::String("*".to_string()),
|
|
269
|
-
MessageTarget::Fanout(list) => serde_json::Value::Array(
|
|
270
|
-
list.iter().map(|s| serde_json::Value::String(s.clone())).collect(),
|
|
271
|
-
),
|
|
272
|
-
},
|
|
273
|
-
"requires_ack": ack,
|
|
274
|
-
}),
|
|
275
|
-
)
|
|
227
|
+
let normalized = crate::messaging::presentation::normalize_send_presentation(mailbox, presentation)
|
|
276
228
|
.map_err(tool_runtime_error)?;
|
|
277
|
-
let
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
229
|
+
let owner_team = self.canonical_owner_team_key()?;
|
|
230
|
+
let directory = crate::direct_delivery::directory(&self.workspace, owner_team.as_ref().map(TeamKey::as_str))
|
|
231
|
+
.map_err(tool_runtime_error)?;
|
|
232
|
+
let sender = self.require_captured_identity("send_message")?.as_str();
|
|
233
|
+
let targets = match to {
|
|
234
|
+
MessageTarget::Single(target) if target == "*" => directory.agents().into_iter().filter(|agent| agent != sender).collect(),
|
|
235
|
+
MessageTarget::Single(target) => vec![target.clone()],
|
|
236
|
+
MessageTarget::Fanout(targets) => targets.clone(),
|
|
237
|
+
MessageTarget::Broadcast => directory.agents().into_iter().filter(|agent| agent != sender).collect(),
|
|
286
238
|
};
|
|
287
|
-
if
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
ok.fields.insert(
|
|
295
|
-
"verification".to_string(),
|
|
296
|
-
Value::String(verification.to_string()),
|
|
297
|
-
);
|
|
298
|
-
}
|
|
299
|
-
if let Some(deprecation) = deprecation {
|
|
300
|
-
ok.fields
|
|
301
|
-
.insert("warning".to_string(), Value::String(deprecation));
|
|
302
|
-
}
|
|
303
|
-
return Ok(SendOutcome::Direct(ok));
|
|
239
|
+
if targets.is_empty() { return Err(tool_runtime_error("no recipients")); }
|
|
240
|
+
let stored_only = normalized.request.sink != crate::messaging::presentation::PresentationSink::Leader;
|
|
241
|
+
let mut destinations = Vec::new();
|
|
242
|
+
for target in targets {
|
|
243
|
+
if target != "leader" && !directory.agents().contains(&target) {
|
|
244
|
+
return Err(ToolError::new(ToolErrorReason::PeerNotInScope,
|
|
245
|
+
format!("recipient is not in the captured team: {target}"), "ScopeError"));
|
|
304
246
|
}
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
_ => {
|
|
312
|
-
let value = delivery_outcome_value(&out);
|
|
313
|
-
let ok = compact_tool_result(&value)?;
|
|
314
|
-
return Ok(SendOutcome::Direct(ok));
|
|
315
|
-
}
|
|
316
|
-
};
|
|
317
|
-
return Ok(SendOutcome::WorkerAccepted {
|
|
318
|
-
poll_via: format!("team-agent inbox {message_id}"),
|
|
319
|
-
message_id,
|
|
320
|
-
warning: deprecation,
|
|
321
|
-
});
|
|
322
|
-
}
|
|
323
|
-
let out = messaging::send_message(&self.workspace, to, content, &opts)
|
|
324
|
-
.map_err(tool_runtime_error)?;
|
|
325
|
-
let value = delivery_outcome_value(&out);
|
|
326
|
-
let mut ok = compact_tool_result(&value)?;
|
|
327
|
-
if matches!(out.status, DeliveryStatus::StoredOnly) {
|
|
328
|
-
if let Some(verification) = out.verification.as_deref() {
|
|
329
|
-
ok.fields.insert(
|
|
330
|
-
"verification".to_string(),
|
|
331
|
-
Value::String(verification.to_string()),
|
|
332
|
-
);
|
|
247
|
+
let endpoint = directory.endpoint(&target);
|
|
248
|
+
if !stored_only && target != "leader" {
|
|
249
|
+
endpoint.as_ref().map_err(tool_runtime_error)?;
|
|
250
|
+
}
|
|
251
|
+
if !destinations.iter().any(|(agent, _)| agent == &target) {
|
|
252
|
+
destinations.push((target, endpoint));
|
|
333
253
|
}
|
|
334
254
|
}
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
255
|
+
let mut results = Vec::new();
|
|
256
|
+
for (agent, endpoint) in destinations {
|
|
257
|
+
let mut message_id = None;
|
|
258
|
+
if stored_only || agent == "leader" {
|
|
259
|
+
let record = crate::inbox_store::record(sender, &agent, content, directory.team.as_deref(), "message");
|
|
260
|
+
message_id = record.get("message_id").cloned();
|
|
261
|
+
crate::inbox_store::append(&directory.workspace, &agent, &record).map_err(tool_runtime_error)?;
|
|
262
|
+
}
|
|
263
|
+
let mut value = if stored_only {
|
|
264
|
+
serde_json::json!({"status": "stored", "recipient": agent, "mailbox": true})
|
|
265
|
+
} else {
|
|
266
|
+
let text = format!("Team Agent message from {sender}:\n\n{content}");
|
|
267
|
+
match endpoint.and_then(|_| directory.send(&agent, &text)) {
|
|
268
|
+
Ok(value) => value,
|
|
269
|
+
Err(error) if message_id.is_some() => serde_json::json!({"status": "stored", "recipient": agent, "delivery_error": error}),
|
|
270
|
+
Err(error) => return Err(tool_runtime_error(error)),
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
if let Some(id) = message_id { value["message_id"] = id; }
|
|
274
|
+
results.push(value);
|
|
338
275
|
}
|
|
339
|
-
|
|
276
|
+
let mut value = if results.len() == 1 { results.remove(0) } else {
|
|
277
|
+
serde_json::json!({"status": "sent", "results": results})
|
|
278
|
+
};
|
|
279
|
+
value["ok"] = Value::Bool(true);
|
|
280
|
+
if let Some(warning) = normalized.deprecation { value["warning"] = Value::String(warning); }
|
|
281
|
+
Ok(SendOutcome::Direct(ToolOk { fields: object_fields(value) }))
|
|
340
282
|
}
|
|
341
283
|
|
|
342
284
|
pub(crate) fn refuse_scope_override(&self) -> ToolError {
|
|
@@ -467,85 +409,7 @@ impl TeamOrchestratorTools {
|
|
|
467
409
|
);
|
|
468
410
|
}
|
|
469
411
|
if !obj.contains_key("task_id") {
|
|
470
|
-
|
|
471
|
-
// message-scoped fallback, before defaulting to "manual".
|
|
472
|
-
// 1. explicit arg
|
|
473
|
-
// 2. current physical direct turn for this agent
|
|
474
|
-
// 3. bounded latest reportable direct message with no result yet
|
|
475
|
-
// 4. latest nonterminal assigned task in teams.<owner>.tasks,
|
|
476
|
-
// only when no newer failed/refused/blocked direct turn blocks fallback
|
|
477
|
-
// 5. "manual" — truly uncorrelated; collect still rejects
|
|
478
|
-
let owner_team_id_str = self.owner_team_id.as_ref().map(|t| t.as_str().to_string());
|
|
479
|
-
let mut attributed_message_id = None;
|
|
480
|
-
let mut attribution_scope = None;
|
|
481
|
-
let mut task_id_source = None;
|
|
482
|
-
let resolved = if let Some(task_id) = task_id {
|
|
483
|
-
task_id.to_string()
|
|
484
|
-
} else if let Some(agent) = self.agent_id.as_ref() {
|
|
485
|
-
if let Some(message_id) = current_reportable_message_for(
|
|
486
|
-
&self.workspace,
|
|
487
|
-
agent.as_str(),
|
|
488
|
-
owner_team_id_str.as_deref(),
|
|
489
|
-
) {
|
|
490
|
-
attributed_message_id = Some(message_id.clone());
|
|
491
|
-
attribution_scope = Some("message");
|
|
492
|
-
task_id_source = Some("current_turn_message");
|
|
493
|
-
message_id
|
|
494
|
-
} else {
|
|
495
|
-
match direct_message_attribution_for(
|
|
496
|
-
&self.workspace,
|
|
497
|
-
agent.as_str(),
|
|
498
|
-
owner_team_id_str.as_deref(),
|
|
499
|
-
) {
|
|
500
|
-
DirectMessageAttribution::Reportable(message_id) => {
|
|
501
|
-
attributed_message_id = Some(message_id.clone());
|
|
502
|
-
attribution_scope = Some("message");
|
|
503
|
-
task_id_source = Some("direct_message");
|
|
504
|
-
message_id
|
|
505
|
-
}
|
|
506
|
-
DirectMessageAttribution::BlockedByNewer {
|
|
507
|
-
message_id,
|
|
508
|
-
status,
|
|
509
|
-
error,
|
|
510
|
-
} => {
|
|
511
|
-
push_report_warning(
|
|
512
|
-
obj,
|
|
513
|
-
serde_json::json!({
|
|
514
|
-
"code": "result_attribution_blocked_by_newer_direct_message",
|
|
515
|
-
"field": "task_id",
|
|
516
|
-
"severity": "warning",
|
|
517
|
-
"advisory": true,
|
|
518
|
-
"message_id": message_id,
|
|
519
|
-
"message_status": status,
|
|
520
|
-
"message_error": error,
|
|
521
|
-
}),
|
|
522
|
-
);
|
|
523
|
-
"manual".to_string()
|
|
524
|
-
}
|
|
525
|
-
DirectMessageAttribution::None => latest_task_for_assignee(
|
|
526
|
-
&self.workspace,
|
|
527
|
-
agent.as_str(),
|
|
528
|
-
owner_team_id_str.as_deref(),
|
|
529
|
-
)
|
|
530
|
-
.unwrap_or_else(|| "manual".to_string()),
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
} else {
|
|
534
|
-
"manual".to_string()
|
|
535
|
-
};
|
|
536
|
-
obj.insert("task_id".to_string(), Value::String(resolved));
|
|
537
|
-
if let Some(message_id) = attributed_message_id {
|
|
538
|
-
obj.entry("attributed_message_id")
|
|
539
|
-
.or_insert(Value::String(message_id));
|
|
540
|
-
}
|
|
541
|
-
if let Some(scope) = attribution_scope {
|
|
542
|
-
obj.entry("attribution_scope")
|
|
543
|
-
.or_insert(Value::String(scope.to_string()));
|
|
544
|
-
}
|
|
545
|
-
if let Some(source) = task_id_source {
|
|
546
|
-
obj.entry("task_id_source")
|
|
547
|
-
.or_insert(Value::String(source.to_string()));
|
|
548
|
-
}
|
|
412
|
+
obj.insert("task_id".to_string(), Value::String(task_id.unwrap_or("manual").to_string()));
|
|
549
413
|
}
|
|
550
414
|
// The framework capture is authoritative even when a matching request
|
|
551
415
|
// value was supplied; this also canonicalizes surrounding whitespace.
|
|
@@ -617,13 +481,23 @@ impl TeamOrchestratorTools {
|
|
|
617
481
|
}
|
|
618
482
|
}
|
|
619
483
|
let owner_team = self.canonical_owner_team_key()?;
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
)
|
|
625
|
-
.map_err(tool_runtime_error)
|
|
626
|
-
|
|
484
|
+
let team = owner_team.as_ref().map(TeamKey::as_str);
|
|
485
|
+
let sender = self.require_captured_identity("report_result")?.as_str();
|
|
486
|
+
let summary = env_value.get("summary").and_then(Value::as_str).unwrap_or("");
|
|
487
|
+
let mut record = crate::inbox_store::record(sender, "leader", summary, team, "result");
|
|
488
|
+
record["envelope"] = env_value.clone();
|
|
489
|
+
crate::inbox_store::append(&self.workspace, "leader", &record).map_err(tool_runtime_error)?;
|
|
490
|
+
let mut value = serde_json::json!({"ok": true, "status": "stored", "message_id": record["message_id"],
|
|
491
|
+
"task_id": env_value["task_id"], "agent_id": sender});
|
|
492
|
+
if normalized.presentation.sink == crate::messaging::presentation::PresentationSink::Leader {
|
|
493
|
+
let delivery = crate::direct_delivery::directory(&self.workspace, team)
|
|
494
|
+
.and_then(|directory| directory.send("leader", &format!("Team Agent result from {sender}:\n\n{summary}")));
|
|
495
|
+
match delivery {
|
|
496
|
+
Ok(_) => { value["status"] = Value::String("reported".into()); }
|
|
497
|
+
Err(error) => { value["delivery_error"] = Value::String(error); }
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
Ok(ToolOk { fields: object_fields(value) })
|
|
627
501
|
}
|
|
628
502
|
|
|
629
503
|
/// `get_team_status`: return the owner-team-scoped machine-readable status.
|