@team-agent/installer 0.5.89 → 0.5.91
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/crates/team-agent/src/cli/adapters.rs +102 -162
- package/crates/team-agent/src/cli/emit.rs +12 -75
- package/crates/team-agent/src/cli/mod.rs +1 -1
- package/crates/team-agent/src/cli/spec.rs +1 -4
- package/crates/team-agent/src/cli/status_port/inbox.rs +42 -17
- package/crates/team-agent/src/cli/tests/lane_c.rs +34 -26
- package/crates/team-agent/src/cli/tests/main_preserved.rs +4 -70
- package/crates/team-agent/src/cli/tests/missing_subcommands.rs +0 -68
- package/crates/team-agent/src/cli/types.rs +3 -16
- package/crates/team-agent/src/coordinator/tests/tick_core.rs +5 -6
- package/crates/team-agent/src/coordinator/tick.rs +1 -16
- package/crates/team-agent/src/coordinator/types.rs +1 -1
- package/crates/team-agent/src/db/message_store.rs +10 -5
- package/crates/team-agent/src/fake_worker.rs +4 -4
- package/crates/team-agent/src/lifecycle/tests/harvest2_a_batch_red.rs +2 -2
- package/crates/team-agent/src/lifecycle/tests/launch_spawn.rs +0 -10
- package/crates/team-agent/src/lifecycle/tests/phase_golden.rs +2 -9
- package/crates/team-agent/src/lifecycle/tests/upgrade_compat_0211_red.rs +1 -26
- package/crates/team-agent/src/main.rs +7 -2
- package/crates/team-agent/src/mcp_server/mod.rs +1 -1
- package/crates/team-agent/src/messaging/mod.rs +2 -2
- package/crates/team-agent/src/messaging/results.rs +234 -386
- package/crates/team-agent/src/messaging/tests/runtime.rs +91 -135
- package/crates/team-agent/src/messaging/watchers.rs +1 -1
- package/package.json +4 -4
- package/skills/team-agent/SKILL.md +3 -3
- package/skills/team-agent/command-coverage.json +2 -9
- package/skills/team-agent/references/team-agent-operator.md +661 -0
|
@@ -1,37 +1,62 @@
|
|
|
1
1
|
//!
|
|
2
2
|
use super::*;
|
|
3
3
|
|
|
4
|
+
const SUMMARY_LIMIT: usize = 120;
|
|
5
|
+
|
|
6
|
+
fn clean_text(text: &str) -> String {
|
|
7
|
+
text.chars().filter(|ch| !ch.is_control()).collect()
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
fn compact_field(value: Option<&Value>) -> Value {
|
|
11
|
+
value
|
|
12
|
+
.and_then(Value::as_str)
|
|
13
|
+
.map(|text| Value::String(clean_text(text)))
|
|
14
|
+
.unwrap_or(Value::Null)
|
|
15
|
+
}
|
|
16
|
+
|
|
4
17
|
pub fn inbox(
|
|
5
18
|
workspace: &Path,
|
|
6
19
|
agent: &str,
|
|
7
20
|
limit: usize,
|
|
8
|
-
since: Option<&str>,
|
|
9
|
-
as_json: bool,
|
|
10
21
|
owner_team_id: Option<&str>,
|
|
11
22
|
) -> Result<Value, CliError> {
|
|
12
|
-
let _ = as_json;
|
|
13
23
|
let store = crate::message_store::MessageStore::open(workspace)
|
|
14
24
|
.map_err(|e| CliError::Runtime(e.to_string()))?;
|
|
15
|
-
let
|
|
25
|
+
let messages = store
|
|
16
26
|
.inbox(agent, limit, owner_team_id)
|
|
17
|
-
.map_err(|e| CliError::Runtime(e.to_string()))
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
.get("created_at")
|
|
22
|
-
.and_then(Value::as_str)
|
|
23
|
-
.and_then(parse_rfc3339)
|
|
24
|
-
.is_some_and(|created| created >= cutoff)
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
+
.map_err(|e| CliError::Runtime(e.to_string()))?
|
|
28
|
+
.into_iter()
|
|
29
|
+
.map(compact_message)
|
|
30
|
+
.collect::<Vec<_>>();
|
|
27
31
|
Ok(json!({
|
|
28
32
|
"ok": true,
|
|
29
33
|
"agent_id": agent,
|
|
30
34
|
"messages": messages,
|
|
31
|
-
"since": since,
|
|
32
35
|
}))
|
|
33
36
|
}
|
|
34
37
|
|
|
35
|
-
|
|
36
|
-
|
|
38
|
+
fn compact_message(message: Value) -> Value {
|
|
39
|
+
json!({
|
|
40
|
+
"message_id": compact_field(message.get("message_id")),
|
|
41
|
+
"sender": compact_field(message.get("sender")),
|
|
42
|
+
"recipient": compact_field(message.get("recipient")),
|
|
43
|
+
"status": compact_field(message.get("status")),
|
|
44
|
+
"created_at": compact_field(message.get("created_at")),
|
|
45
|
+
"summary": compact_summary(message.get("content").and_then(Value::as_str).unwrap_or("")),
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
fn compact_summary(content: &str) -> String {
|
|
50
|
+
let summary = content
|
|
51
|
+
.lines()
|
|
52
|
+
.map(|line| clean_text(line).trim().to_string())
|
|
53
|
+
.find(|line| !line.is_empty())
|
|
54
|
+
.unwrap_or_default();
|
|
55
|
+
let mut chars = summary.chars();
|
|
56
|
+
let truncated = chars.by_ref().take(SUMMARY_LIMIT).collect::<String>();
|
|
57
|
+
if chars.next().is_some() {
|
|
58
|
+
format!("{truncated}…")
|
|
59
|
+
} else {
|
|
60
|
+
truncated
|
|
61
|
+
}
|
|
37
62
|
}
|
|
@@ -211,36 +211,44 @@ fn approvals_golden_shape_has_waiting_count_and_scan_not_agent() {
|
|
|
211
211
|
let _ = std::fs::remove_dir_all(&ws);
|
|
212
212
|
}
|
|
213
213
|
|
|
214
|
-
// ── inbox:
|
|
215
|
-
// `since` (not `agent`/`limit`). RUST mod.rs:136-144 stub {ok,agent,limit,messages}. RED. ──────────
|
|
214
|
+
// ── inbox: compact fallback projection ───────────────────────────────────────────────
|
|
216
215
|
#[test]
|
|
217
|
-
fn
|
|
216
|
+
fn inbox_golden_shape_is_compact_and_scoped_to_agent() {
|
|
218
217
|
let ws = tmp_workspace();
|
|
219
|
-
let v = status_port::inbox(&ws, "alpha",
|
|
218
|
+
let v = status_port::inbox(&ws, "alpha", 3, None).expect("inbox");
|
|
220
219
|
let obj = v.as_object().expect("inbox dict");
|
|
220
|
+
assert_eq!(v["agent_id"], json!("alpha"));
|
|
221
221
|
let order: Vec<&str> = obj.keys().map(String::as_str).collect();
|
|
222
|
-
assert_eq!(
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
222
|
+
assert_eq!(order, vec!["ok", "agent_id", "messages"]);
|
|
223
|
+
let _ = std::fs::remove_dir_all(&ws);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
#[test]
|
|
227
|
+
fn inbox_excludes_leader_stage_result_notifications() {
|
|
228
|
+
let ws = tmp_workspace();
|
|
229
|
+
let store = crate::message_store::MessageStore::open(&ws).unwrap();
|
|
230
|
+
let message_id = store
|
|
231
|
+
.create_message(
|
|
232
|
+
None,
|
|
233
|
+
"leader",
|
|
234
|
+
"worker",
|
|
235
|
+
"Task t reported success; Result id: res-1",
|
|
236
|
+
None,
|
|
237
|
+
false,
|
|
238
|
+
None,
|
|
239
|
+
)
|
|
240
|
+
.unwrap();
|
|
241
|
+
let conn = crate::db::schema::open_db(store.db_path()).unwrap();
|
|
242
|
+
conn.execute(
|
|
243
|
+
"update messages set presentation = ?1 where message_id = ?2",
|
|
244
|
+
rusqlite::params![
|
|
245
|
+
json!({"sink": "leader", "class": "stage_result"}).to_string(),
|
|
246
|
+
message_id,
|
|
247
|
+
],
|
|
248
|
+
)
|
|
249
|
+
.unwrap();
|
|
250
|
+
let value = status_port::inbox(&ws, "leader", 3, None).expect("inbox");
|
|
251
|
+
assert!(value["messages"].as_array().unwrap().is_empty());
|
|
244
252
|
let _ = std::fs::remove_dir_all(&ws);
|
|
245
253
|
}
|
|
246
254
|
|
|
@@ -208,7 +208,7 @@ fn inbox_returns_stored_message_for_recipient() {
|
|
|
208
208
|
let mid = store
|
|
209
209
|
.create_message(None, "leader", "w1", "hello w1", None, true, None)
|
|
210
210
|
.unwrap();
|
|
211
|
-
let v = status_port::inbox(&ws, "w1", 20, None
|
|
211
|
+
let v = status_port::inbox(&ws, "w1", 20, None).expect("inbox");
|
|
212
212
|
let messages = v["messages"].as_array().expect("messages array");
|
|
213
213
|
assert_eq!(
|
|
214
214
|
messages.len(),
|
|
@@ -223,30 +223,12 @@ fn inbox_returns_stored_message_for_recipient() {
|
|
|
223
223
|
);
|
|
224
224
|
assert_eq!(m["recipient"], json!("w1"));
|
|
225
225
|
assert_eq!(m["sender"], json!("leader"));
|
|
226
|
-
assert_eq!(m["
|
|
226
|
+
assert_eq!(m["summary"], json!("hello w1"));
|
|
227
227
|
assert_eq!(
|
|
228
228
|
m["status"],
|
|
229
229
|
json!("accepted"),
|
|
230
230
|
"create_message persists status='accepted'"
|
|
231
231
|
);
|
|
232
|
-
// NULL owner_team_id semantics: status.inbox() calls MessageStore.inbox(agent) with
|
|
233
|
-
// owner_team_id=None (no team clause), so a NULL-owner message MUST surface for its recipient.
|
|
234
|
-
assert_eq!(
|
|
235
|
-
m["owner_team_id"],
|
|
236
|
-
json!(null),
|
|
237
|
-
"the stored message's owner_team_id is NULL and still returned"
|
|
238
|
-
);
|
|
239
|
-
// byte-faithful raw-row columns: requires_ack is the 0/1 INT; artifact_refs the literal text "[]".
|
|
240
|
-
assert_eq!(
|
|
241
|
-
m["requires_ack"],
|
|
242
|
-
json!(1),
|
|
243
|
-
"requires_ack is the 0/1 int, not a bool"
|
|
244
|
-
);
|
|
245
|
-
assert_eq!(
|
|
246
|
-
m["artifact_refs"],
|
|
247
|
-
json!("[]"),
|
|
248
|
-
"artifact_refs is the raw text column, not parsed"
|
|
249
|
-
);
|
|
250
232
|
let _ = std::fs::remove_dir_all(&ws);
|
|
251
233
|
}
|
|
252
234
|
// ── BUG-2 (match scope) — inbox(agent) returns rows where sender==agent OR recipient==agent, and
|
|
@@ -265,11 +247,11 @@ fn inbox_matches_sender_or_recipient_and_excludes_others() {
|
|
|
265
247
|
store
|
|
266
248
|
.create_message(None, "leader", "w2", "unrelated to w2", None, true, None)
|
|
267
249
|
.unwrap();
|
|
268
|
-
let v = status_port::inbox(&ws, "w1", 20, None
|
|
250
|
+
let v = status_port::inbox(&ws, "w1", 20, None).expect("inbox");
|
|
269
251
|
let messages = v["messages"].as_array().expect("messages array");
|
|
270
252
|
let mut contents: Vec<String> = messages
|
|
271
253
|
.iter()
|
|
272
|
-
.map(|m| m["
|
|
254
|
+
.map(|m| m["summary"].as_str().unwrap().to_string())
|
|
273
255
|
.collect();
|
|
274
256
|
contents.sort();
|
|
275
257
|
assert_eq!(
|
|
@@ -691,54 +673,6 @@ fn remove_agent_from_spec_refusal_is_not_success_envelope() {
|
|
|
691
673
|
);
|
|
692
674
|
}
|
|
693
675
|
#[test]
|
|
694
|
-
fn collect_uncollected_result_marks_db_and_outputs_result() {
|
|
695
|
-
let ws = tmp_workspace();
|
|
696
|
-
seed_collect_state(&ws);
|
|
697
|
-
seed_uncollected_result(&ws, "res_collect_red");
|
|
698
|
-
let out = json_output(
|
|
699
|
-
cmd_collect(&CollectArgs {
|
|
700
|
-
workspace: ws.clone(),
|
|
701
|
-
result_file: None,
|
|
702
|
-
json: true,
|
|
703
|
-
team: None,
|
|
704
|
-
})
|
|
705
|
-
.unwrap(),
|
|
706
|
-
);
|
|
707
|
-
assert_eq!(out["ok"], json!(true));
|
|
708
|
-
assert_eq!(
|
|
709
|
-
out["collected_results"][0]["result_id"],
|
|
710
|
-
json!("res_collect_red")
|
|
711
|
-
);
|
|
712
|
-
assert_eq!(out["collected_results"][0]["scope"], json!("task"));
|
|
713
|
-
assert_eq!(
|
|
714
|
-
out["results"],
|
|
715
|
-
json!({"total": 1, "uncollected": 0, "collected": 1, "invalid": 0, "by_status": {}})
|
|
716
|
-
);
|
|
717
|
-
let store = crate::message_store::MessageStore::open(&ws).unwrap();
|
|
718
|
-
let conn = crate::db::schema::open_db(store.db_path()).unwrap();
|
|
719
|
-
let status: String = conn
|
|
720
|
-
.query_row(
|
|
721
|
-
"select status from results where result_id = 'res_collect_red'",
|
|
722
|
-
[],
|
|
723
|
-
|row| row.get(0),
|
|
724
|
-
)
|
|
725
|
-
.unwrap();
|
|
726
|
-
assert_eq!(status, "collected");
|
|
727
|
-
let state = read_state(&ws);
|
|
728
|
-
assert_eq!(state["tasks"][0]["status"], json!("done"));
|
|
729
|
-
assert_eq!(
|
|
730
|
-
state["tasks"][0]["accepted_result_id"],
|
|
731
|
-
json!("res_collect_red")
|
|
732
|
-
);
|
|
733
|
-
assert!(
|
|
734
|
-
read_events(&ws)
|
|
735
|
-
.iter()
|
|
736
|
-
.any(|e| e["event"] == json!("collect.result")
|
|
737
|
-
&& e["result_id"] == json!("res_collect_red")),
|
|
738
|
-
"collect must emit collect.result for the stored result"
|
|
739
|
-
);
|
|
740
|
-
}
|
|
741
|
-
#[test]
|
|
742
676
|
fn stuck_cancel_persists_suppression_and_stuck_list_reads_state() {
|
|
743
677
|
let ws = tmp_workspace();
|
|
744
678
|
seed_collect_state(&ws);
|
|
@@ -275,36 +275,6 @@ fn seed_team_spec(ws: &std::path::Path) {
|
|
|
275
275
|
std::fs::write(ws.join("team.spec.yaml"), spec).unwrap();
|
|
276
276
|
}
|
|
277
277
|
|
|
278
|
-
fn seed_collect_runtime_state(ws: &std::path::Path) {
|
|
279
|
-
crate::state::persist::save_runtime_state(
|
|
280
|
-
ws,
|
|
281
|
-
&json!({
|
|
282
|
-
"active_team_key": "fake-e2e",
|
|
283
|
-
"team_dir": ws.to_string_lossy().to_string(),
|
|
284
|
-
"spec_path": ws.join("team.spec.yaml").to_string_lossy().to_string(),
|
|
285
|
-
"session_name": "team-agent-fake-e2e",
|
|
286
|
-
"leader": {"id": "leader"},
|
|
287
|
-
"agents": {
|
|
288
|
-
"fake_impl": {
|
|
289
|
-
"status": "running",
|
|
290
|
-
"provider": "fake",
|
|
291
|
-
"role": "implementation_engineer",
|
|
292
|
-
"window": "fake_impl",
|
|
293
|
-
"owner_team_id": "fake-e2e"
|
|
294
|
-
}
|
|
295
|
-
},
|
|
296
|
-
"tasks": [{
|
|
297
|
-
"id": "task_impl",
|
|
298
|
-
"title": "Fake implementation",
|
|
299
|
-
"type": "implementation",
|
|
300
|
-
"status": "pending",
|
|
301
|
-
"assignee": "fake_impl"
|
|
302
|
-
}]
|
|
303
|
-
}),
|
|
304
|
-
)
|
|
305
|
-
.unwrap();
|
|
306
|
-
}
|
|
307
|
-
|
|
308
278
|
// ── sessions ── golden cli/parser.py:230 `cmd_sessions` -> runtime.sessions(ws). EXIT 0.
|
|
309
279
|
// `team-agent sessions --workspace <ws> --json` on an empty ws ->
|
|
310
280
|
// {"ok":true,"sessions":[],"workspace":"<ws>"} (--json sort_keys). RED: unrouted -> Error.
|
|
@@ -324,44 +294,6 @@ fn dispatch_routes_sessions_subcommand() {
|
|
|
324
294
|
let _ = std::fs::remove_dir_all(&ws);
|
|
325
295
|
}
|
|
326
296
|
|
|
327
|
-
// ── collect ── golden parser.py:292 `cmd_collect` -> runtime.collect(ws). With a valid
|
|
328
|
-
// team.spec.yaml present and nothing to collect -> EXIT 0, golden:
|
|
329
|
-
// {"collected":[],"collected_results":[],"coordinator":{"ok":false,"status":"not_required"},
|
|
330
|
-
// "delivered_messages":[],"invalid_results":[],"ok":true,"results":{...},"state_file":"<ws>/team_state.md"}
|
|
331
|
-
// RED: unrouted -> Error.
|
|
332
|
-
#[test]
|
|
333
|
-
#[serial(env)]
|
|
334
|
-
fn dispatch_routes_collect_with_spec() {
|
|
335
|
-
let _env = EnvUnsetGuard::unset(&[
|
|
336
|
-
"TEAM_AGENT_WORKSPACE",
|
|
337
|
-
"TEAM_AGENT_TEAM_ID",
|
|
338
|
-
"TEAM_AGENT_OWNER_TEAM_ID",
|
|
339
|
-
"TEAM_AGENT_ACTIVE_TEAM",
|
|
340
|
-
"TEAM_AGENT_ID",
|
|
341
|
-
"TEAM_AGENT_LEADER_PANE_ID",
|
|
342
|
-
"TEAM_AGENT_LEADER_SESSION_UUID",
|
|
343
|
-
"TEAM_AGENT_LEADER_SESSION_UUID_OVERRIDE",
|
|
344
|
-
"TEAM_AGENT_LEADER_PROVIDER",
|
|
345
|
-
"TMUX",
|
|
346
|
-
"TMUX_PANE",
|
|
347
|
-
]);
|
|
348
|
-
let ws = tmp_workspace();
|
|
349
|
-
let _cleanup = WorkspaceCleanup(ws.clone());
|
|
350
|
-
seed_team_spec(&ws);
|
|
351
|
-
seed_collect_runtime_state(&ws);
|
|
352
|
-
let code = run(
|
|
353
|
-
&cli_argv(&["collect", "--workspace", &ws.to_string_lossy(), "--json"]),
|
|
354
|
-
&ws,
|
|
355
|
-
);
|
|
356
|
-
assert_eq!(
|
|
357
|
-
code,
|
|
358
|
-
ExitCode::Ok,
|
|
359
|
-
"`collect` must ROUTE to cmd_collect (parser.py:292); with a valid spec golden exits 0 \
|
|
360
|
-
{{collected,collected_results,coordinator,delivered_messages,invalid_results,ok,results,state_file}}; \
|
|
361
|
-
today -> unknown-subcommand Error"
|
|
362
|
-
);
|
|
363
|
-
}
|
|
364
|
-
|
|
365
297
|
// ── diagnose ── attached is host-registry authority, not state.json self-sign.
|
|
366
298
|
// Seed leader_receiver=attached + a ~/.team-agent/leaders/ row for this workspace
|
|
367
299
|
// + NO session_name + NO agents -> issues=[] -> EXIT 0.
|
|
@@ -44,10 +44,10 @@ pub enum CliError {
|
|
|
44
44
|
/// state 解析失败(歧义/未找到 team 等)。透传 step 5。
|
|
45
45
|
#[error("{0}")]
|
|
46
46
|
State(#[from] crate::state::StateError),
|
|
47
|
-
/// messaging 委派失败(send/
|
|
47
|
+
/// messaging 委派失败(send/stuck)。透传 step 11。
|
|
48
48
|
#[error("{0}")]
|
|
49
49
|
Messaging(crate::messaging::MessagingError),
|
|
50
|
-
/// I/O(cli-error
|
|
50
|
+
/// I/O(cli-error 落盘)。bug-084:写路径降级,不裸 panic。
|
|
51
51
|
#[error("io: {0}")]
|
|
52
52
|
Io(#[from] std::io::Error),
|
|
53
53
|
/// JSON 解析。
|
|
@@ -407,13 +407,12 @@ pub struct ApprovalsArgs {
|
|
|
407
407
|
pub team: Option<String>,
|
|
408
408
|
}
|
|
409
409
|
|
|
410
|
-
/// `inbox`(`parser.py:217`)
|
|
410
|
+
/// `inbox`(`parser.py:217`)。极简消息兜底查看器。
|
|
411
411
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
412
412
|
pub struct InboxArgs {
|
|
413
413
|
pub agent: String,
|
|
414
414
|
pub workspace: PathBuf,
|
|
415
415
|
pub limit: usize,
|
|
416
|
-
pub since: Option<String>,
|
|
417
416
|
pub json: bool,
|
|
418
417
|
/// Stage 4: explicit `--team` scope.
|
|
419
418
|
pub team: Option<String>,
|
|
@@ -682,18 +681,6 @@ pub struct ProfileArgs {
|
|
|
682
681
|
pub json: bool,
|
|
683
682
|
}
|
|
684
683
|
|
|
685
|
-
/// `collect`(`parser.py:292`)。
|
|
686
|
-
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
687
|
-
pub struct CollectArgs {
|
|
688
|
-
pub workspace: PathBuf,
|
|
689
|
-
pub result_file: Option<PathBuf>,
|
|
690
|
-
pub json: bool,
|
|
691
|
-
/// Stage 4: explicit `--team` scope. Destructive (consumes result
|
|
692
|
-
/// envelopes); CLI dispatch refuses bare invocation in a
|
|
693
|
-
/// multi-alive-team workspace.
|
|
694
|
-
pub team: Option<String>,
|
|
695
|
-
}
|
|
696
|
-
|
|
697
684
|
/// Read-only lookup of all stored result envelopes for one case.
|
|
698
685
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
699
686
|
pub struct ResultsArgs {
|
|
@@ -82,7 +82,7 @@ fn tick_side_effect_order_is_the_fixed_sequence() {
|
|
|
82
82
|
// startup_prompts -> runtime_prompts -> sync_health -> deliver_pending ->
|
|
83
83
|
// fire_scheduled -> detect_stuck -> record_unknown_idle -> evaluate_takeover ->
|
|
84
84
|
// detect_deadlocks -> detect_compaction -> detect_drift -> detect_api_errors ->
|
|
85
|
-
// ATOMIC_save (bug-084 wrap) ->
|
|
85
|
+
// ATOMIC_save (bug-084 wrap) -> prune_dedupe_log.
|
|
86
86
|
// The porter must push each step name into the injected recorder at its call site.
|
|
87
87
|
let recorder: OrderRecorder = std::sync::Arc::new(std::sync::Mutex::new(Vec::new()));
|
|
88
88
|
let (coord, _calls) = coord_for_test(true, None, Some(std::sync::Arc::clone(&recorder)));
|
|
@@ -106,19 +106,18 @@ fn tick_side_effect_order_is_the_fixed_sequence() {
|
|
|
106
106
|
"detect_drift",
|
|
107
107
|
"detect_api_errors",
|
|
108
108
|
"atomic_save",
|
|
109
|
-
"collect_results",
|
|
110
109
|
"prune_dedupe_log",
|
|
111
110
|
];
|
|
112
111
|
assert_eq!(
|
|
113
112
|
order, expected,
|
|
114
113
|
"tick side-effect ORDER must match the fixed sequence"
|
|
115
114
|
);
|
|
116
|
-
// ATOMIC save is the LAST mutation before read-only
|
|
115
|
+
// ATOMIC save is the LAST mutation before the read-only prune (bug-084 wrap point).
|
|
117
116
|
let save_idx = order.iter().position(|s| *s == "atomic_save").unwrap();
|
|
118
|
-
let
|
|
117
|
+
let prune_idx = order.iter().position(|s| *s == "prune_dedupe_log").unwrap();
|
|
119
118
|
assert!(
|
|
120
|
-
save_idx <
|
|
121
|
-
"save precedes
|
|
119
|
+
save_idx < prune_idx,
|
|
120
|
+
"save precedes prune (bug-084 wrap is the last mutation)"
|
|
122
121
|
);
|
|
123
122
|
}
|
|
124
123
|
|
|
@@ -104,7 +104,7 @@ pub struct TickReport {
|
|
|
104
104
|
pub session_drift: Vec<SessionDriftResult>,
|
|
105
105
|
/// `detect_leader_api_errors`(`lifecycle.py:344`)——cross-dep step 11。
|
|
106
106
|
pub api_errors: Vec<LeaderApiError>,
|
|
107
|
-
///
|
|
107
|
+
/// Reserved result projection slot; report_result now finalizes directly.
|
|
108
108
|
pub results: Vec<CollectedResult>,
|
|
109
109
|
}
|
|
110
110
|
|
|
@@ -528,12 +528,6 @@ impl Coordinator {
|
|
|
528
528
|
collections,
|
|
529
529
|
));
|
|
530
530
|
}
|
|
531
|
-
self.record_step(TickStepGroup::Delivery, "collect_results");
|
|
532
|
-
collections.results =
|
|
533
|
-
collect_results(crate::messaging::collect_results_and_notify_watchers(
|
|
534
|
-
self.workspace.as_path(),
|
|
535
|
-
&event_log,
|
|
536
|
-
)?);
|
|
537
531
|
self.record_step(TickStepGroup::Persist, "prune_dedupe_log");
|
|
538
532
|
Ok(base_tick_report(true, false, None, Some(true), collections))
|
|
539
533
|
}
|
|
@@ -1554,15 +1548,6 @@ fn empty_tick_report(
|
|
|
1554
1548
|
base_tick_report(ok, stop, reason, persisted, TickCollections::default())
|
|
1555
1549
|
}
|
|
1556
1550
|
|
|
1557
|
-
fn collect_results(value: Value) -> Vec<CollectedResult> {
|
|
1558
|
-
let Some(result_id) = value.get("result_id").and_then(Value::as_str) else {
|
|
1559
|
-
return Vec::new();
|
|
1560
|
-
};
|
|
1561
|
-
vec![CollectedResult {
|
|
1562
|
-
result_id: result_id.to_string(),
|
|
1563
|
-
}]
|
|
1564
|
-
}
|
|
1565
|
-
|
|
1566
1551
|
struct ProviderTurnClassifier;
|
|
1567
1552
|
|
|
1568
1553
|
impl TurnStateClassifier for ProviderTurnClassifier {
|
|
@@ -543,7 +543,7 @@ pub struct LeaderApiError {
|
|
|
543
543
|
pub message: String,
|
|
544
544
|
}
|
|
545
545
|
|
|
546
|
-
///
|
|
546
|
+
/// Result projection reported by a coordinator tick. Report results now finalize inline.
|
|
547
547
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
548
548
|
pub struct CollectedResult {
|
|
549
549
|
pub result_id: String,
|
|
@@ -727,9 +727,11 @@ impl MessageStore {
|
|
|
727
727
|
Ok(changed == 1)
|
|
728
728
|
}
|
|
729
729
|
|
|
730
|
-
/// Read inbox rows for an agent.
|
|
731
|
-
///
|
|
732
|
-
///
|
|
730
|
+
/// Read ordinary inbox rows for an agent. Leader stage-result notifications are
|
|
731
|
+
/// delivered through the leader receiver, not exposed as mailbox fallback rows.
|
|
732
|
+
/// This projection intentionally has no owner-team filter when the caller does
|
|
733
|
+
/// not provide one: legacy/CLI inbox must surface NULL-owner messages stored for
|
|
734
|
+
/// the agent.
|
|
733
735
|
pub fn inbox(
|
|
734
736
|
&self,
|
|
735
737
|
agent_id: &str,
|
|
@@ -744,7 +746,9 @@ impl MessageStore {
|
|
|
744
746
|
status, content, artifact_refs, created_at, updated_at, delivered_at,
|
|
745
747
|
acknowledged_at, error, delivery_attempts
|
|
746
748
|
from messages
|
|
747
|
-
where (sender = ?1 or recipient = ?1)
|
|
749
|
+
where (sender = ?1 or recipient = ?1)
|
|
750
|
+
and owner_team_id = ?3
|
|
751
|
+
and coalesce(json_extract(presentation, '$.class'), 'message') != 'stage_result'
|
|
748
752
|
order by created_at desc
|
|
749
753
|
limit ?2"
|
|
750
754
|
}
|
|
@@ -753,7 +757,8 @@ impl MessageStore {
|
|
|
753
757
|
status, content, artifact_refs, created_at, updated_at, delivered_at,
|
|
754
758
|
acknowledged_at, error, delivery_attempts
|
|
755
759
|
from messages
|
|
756
|
-
where sender = ?1 or recipient = ?1
|
|
760
|
+
where (sender = ?1 or recipient = ?1)
|
|
761
|
+
and coalesce(json_extract(presentation, '$.class'), 'message') != 'stage_result'
|
|
757
762
|
order by created_at desc
|
|
758
763
|
limit ?2"
|
|
759
764
|
}
|
|
@@ -220,8 +220,8 @@ mod tests {
|
|
|
220
220
|
let (task_id, agent_id, status, env) = stored_result(ws);
|
|
221
221
|
assert_eq!(
|
|
222
222
|
(task_id.as_str(), agent_id.as_str(), status.as_str()),
|
|
223
|
-
("t1", "w1", "
|
|
224
|
-
"stored result row must be task_id=t1 agent_id=w1 status=
|
|
223
|
+
("t1", "w1", "collected"),
|
|
224
|
+
"stored result row must be task_id=t1 agent_id=w1 status=collected"
|
|
225
225
|
);
|
|
226
226
|
assert_eq!(
|
|
227
227
|
env["schema_version"],
|
|
@@ -291,8 +291,8 @@ mod tests {
|
|
|
291
291
|
let (task_id, agent_id, status, envelope) = stored_result(&ws);
|
|
292
292
|
assert_eq!(
|
|
293
293
|
(task_id.as_str(), agent_id.as_str(), status.as_str()),
|
|
294
|
-
("m1", "w1", "
|
|
295
|
-
"a direct-message result must use its message id for message-scope
|
|
294
|
+
("m1", "w1", "collected"),
|
|
295
|
+
"a direct-message result must use its message id for message-scope auto-finalization"
|
|
296
296
|
);
|
|
297
297
|
assert_ne!(
|
|
298
298
|
envelope["task_id"],
|
|
@@ -255,8 +255,8 @@ fn t3_unknown_business_status_is_preserved_without_normalized_event() {
|
|
|
255
255
|
let envelope: serde_json::Value =
|
|
256
256
|
serde_json::from_str(&row.envelope).expect("T3-1 durable envelope JSON");
|
|
257
257
|
assert_eq!(
|
|
258
|
-
row.status,
|
|
259
|
-
"T3-1 ingress:
|
|
258
|
+
row.status, "collected",
|
|
259
|
+
"T3-1 ingress: report_result auto-finalization must mark the durable row collected"
|
|
260
260
|
);
|
|
261
261
|
assert_eq!(
|
|
262
262
|
envelope["status"],
|
|
@@ -410,16 +410,6 @@ fn quick_start_teamdir_under_dot_team_uses_project_workspace_for_status_and_coll
|
|
|
410
410
|
"status should normalize teamdir to project-root runtime state: {status:?}"
|
|
411
411
|
);
|
|
412
412
|
|
|
413
|
-
let collect = crate::cli::cmd_collect(&crate::cli::CollectArgs {
|
|
414
|
-
result_file: None,
|
|
415
|
-
workspace: team.clone(),
|
|
416
|
-
json: true,
|
|
417
|
-
team: None,
|
|
418
|
-
});
|
|
419
|
-
assert!(
|
|
420
|
-
collect.is_ok(),
|
|
421
|
-
"collect should normalize teamdir to the same project-root state/spec: {collect:?}"
|
|
422
|
-
);
|
|
423
413
|
}
|
|
424
414
|
|
|
425
415
|
#[test]
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
use super::launch_spawn::seed_healthy_coordinator;
|
|
2
2
|
use super::*;
|
|
3
3
|
use crate::cli::{
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
cmd_diagnose, cmd_send, cmd_status, lifecycle_port, CmdOutput, CmdResult, DiagnoseArgs,
|
|
5
|
+
SendArgs, StatusArgs,
|
|
6
6
|
};
|
|
7
7
|
use crate::transport::test_support::OfflineTransport;
|
|
8
8
|
use crate::transport::WindowName;
|
|
@@ -275,12 +275,6 @@ fn run_phase_golden(spec: PhaseGolden) -> Value {
|
|
|
275
275
|
to_name: None,
|
|
276
276
|
to_leader: None,
|
|
277
277
|
});
|
|
278
|
-
let collect = cmd_collect(&CollectArgs {
|
|
279
|
-
workspace: workspace.clone(),
|
|
280
|
-
result_file: None,
|
|
281
|
-
json: true,
|
|
282
|
-
team: Some(spec.team_key.to_string()),
|
|
283
|
-
});
|
|
284
278
|
let lifecycle_transport = codex_ready_transport()
|
|
285
279
|
.with_session_present(true)
|
|
286
280
|
.with_windows(vec![WindowName::new("w1"), WindowName::new("w2")]);
|
|
@@ -303,7 +297,6 @@ fn run_phase_golden(spec: PhaseGolden) -> Value {
|
|
|
303
297
|
{ "step": "status-json", "result": cmd_value(status_compact) },
|
|
304
298
|
{ "step": "status-detail-json", "result": cmd_value(status_detail) },
|
|
305
299
|
{ "step": "send", "result": cmd_value(send) },
|
|
306
|
-
{ "step": "collect", "result": cmd_value(collect) },
|
|
307
300
|
{ "step": "phase-lifecycle-op", "output": lifecycle },
|
|
308
301
|
{
|
|
309
302
|
"step": "shutdown-keep-logs",
|
|
@@ -19,9 +19,7 @@ use std::sync::Mutex;
|
|
|
19
19
|
use rusqlite::params;
|
|
20
20
|
use serde_json::{json, Value};
|
|
21
21
|
use serial_test::serial;
|
|
22
|
-
use team_agent::cli::{
|
|
23
|
-
cmd_collect_for_team, cmd_status_for_team, CmdOutput, CollectArgs, StatusArgs,
|
|
24
|
-
};
|
|
22
|
+
use team_agent::cli::{cmd_status_for_team, CmdOutput, StatusArgs};
|
|
25
23
|
use team_agent::db::schema::{initialize_schema, open_db, table_layout, SCHEMA_VERSION};
|
|
26
24
|
use team_agent::event_log::EventLog;
|
|
27
25
|
use team_agent::lifecycle::restart::classify_restart_plan;
|
|
@@ -239,29 +237,6 @@ fn upgrade_status_collect_scope_by_selected_team_key() {
|
|
|
239
237
|
"status --team upgrade-key must not expose sibling rows; status={status}"
|
|
240
238
|
);
|
|
241
239
|
|
|
242
|
-
let collect = json_output(cmd_collect_for_team(
|
|
243
|
-
&CollectArgs {
|
|
244
|
-
workspace: fixture.workspace.clone(),
|
|
245
|
-
result_file: None,
|
|
246
|
-
json: true,
|
|
247
|
-
team: None,
|
|
248
|
-
},
|
|
249
|
-
Some(TEAM_KEY),
|
|
250
|
-
));
|
|
251
|
-
let empty = Vec::new();
|
|
252
|
-
let collected_ids = collect
|
|
253
|
-
.get("collected_results")
|
|
254
|
-
.and_then(Value::as_array)
|
|
255
|
-
.unwrap_or(&empty)
|
|
256
|
-
.iter()
|
|
257
|
-
.filter_map(|item| item.get("result_id").and_then(Value::as_str))
|
|
258
|
-
.collect::<Vec<_>>();
|
|
259
|
-
assert!(
|
|
260
|
-
collected_ids.contains(&"res-existing-upgrade")
|
|
261
|
-
&& collected_ids.contains(&"res-upgrade")
|
|
262
|
-
&& !collected_ids.contains(&"res-sibling"),
|
|
263
|
-
"collect --team upgrade-key must collect only selected runtime-key rows; collect={collect}"
|
|
264
|
-
);
|
|
265
240
|
}
|
|
266
241
|
|
|
267
242
|
#[test]
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
//! `team-agent` 二进制入口。
|
|
2
2
|
|
|
3
3
|
fn main() -> anyhow::Result<()> {
|
|
4
|
-
let mut args = std::env::
|
|
4
|
+
let mut args = std::env::args_os()
|
|
5
|
+
.skip(1)
|
|
6
|
+
.map(|arg| arg.to_string_lossy().into_owned());
|
|
5
7
|
let command = args.next();
|
|
6
8
|
if matches!(command.as_deref(), Some("fake-worker")) {
|
|
7
9
|
let mut workspace = None;
|
|
@@ -35,7 +37,10 @@ fn main() -> anyhow::Result<()> {
|
|
|
35
37
|
team_agent::mcp_server::main(&workspace, &[])?;
|
|
36
38
|
return Ok(());
|
|
37
39
|
}
|
|
38
|
-
let argv = std::env::
|
|
40
|
+
let argv = std::env::args_os()
|
|
41
|
+
.skip(1)
|
|
42
|
+
.map(|arg| arg.to_string_lossy().into_owned())
|
|
43
|
+
.collect::<Vec<_>>();
|
|
39
44
|
let cwd = std::env::current_dir()?;
|
|
40
45
|
std::process::exit(team_agent::cli::run(&argv, &cwd).code());
|
|
41
46
|
}
|