@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.
- 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 -22
- package/crates/team-agent/src/cli/emit.rs +58 -26
- package/crates/team-agent/src/cli/intent/runtime.rs +32 -5
- package/crates/team-agent/src/cli/intent/runtime_tests.rs +102 -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 +25 -8
- package/crates/team-agent/src/cli/models.rs +764 -7
- 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 +1 -1
- package/crates/team-agent/src/cli/tests/named_address.rs +11 -10
- package/crates/team-agent/src/cli/tests/run_delegation.rs +9 -6
- package/crates/team-agent/src/cli/tests/status_send.rs +68 -271
- package/crates/team-agent/src/compiler/tests.rs +3 -18
- package/crates/team-agent/src/compiler.rs +205 -6
- package/crates/team-agent/src/contract_runtime/backend.rs +145 -11
- package/crates/team-agent/src/contract_runtime/commands.rs +7 -7
- package/crates/team-agent/src/contract_runtime/config.rs +26 -16
- 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 -11
- 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 +56 -92
- package/crates/team-agent/src/coordinator/steps/abnormal.rs +11 -11
- package/crates/team-agent/src/coordinator/tests/api_error_recovery.rs +16 -54
- package/crates/team-agent/src/coordinator/tests/health_sync.rs +42 -0
- 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 +38 -13
- package/crates/team-agent/src/lifecycle/launch/fork_entry.rs +87 -6
- package/crates/team-agent/src/lifecycle/launch/mcp_config.rs +9 -1
- 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 +24 -0
- package/crates/team-agent/src/lifecycle/launch/spawn.rs +36 -13
- package/crates/team-agent/src/lifecycle/launch.rs +24 -1
- package/crates/team-agent/src/lifecycle/profile_launch.rs +321 -11
- 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 +345 -35
- 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 +39 -14
- 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 +236 -13
- 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 +5 -4
- package/crates/team-agent/src/lifecycle/tests/copilot_provider_red.rs +7 -11
- package/crates/team-agent/src/lifecycle/tests/core.rs +47 -18
- 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 +14 -14
- package/crates/team-agent/src/lifecycle/tests/harvest2_a_batch_red.rs +60 -20
- package/crates/team-agent/src/lifecycle/tests/launch_spawn.rs +28 -26
- package/crates/team-agent/src/lifecycle/tests/mcp_tool_name_format_red.rs +6 -6
- 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 +10 -11
- package/crates/team-agent/src/lifecycle/tests/status_credential_redaction_contract.rs +2 -2
- package/crates/team-agent/src/lifecycle/tests/swallow_batch4_semantics_red.rs +254 -2
- package/crates/team-agent/src/lifecycle/tests/upgrade_compat_0211_red.rs +4 -4
- package/crates/team-agent/src/lifecycle/tests/verify_rs031_window_consistency_red.rs +5 -6
- package/crates/team-agent/src/lifecycle/tests/worker_spawn_env_red.rs +16 -7
- package/crates/team-agent/src/lifecycle/tests.rs +3 -0
- package/crates/team-agent/src/lifecycle/types.rs +18 -2
- 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 +98 -119
- 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 +160 -218
- 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 +191 -85
- package/crates/team-agent/src/messaging/tests/runtime.rs +4 -110
- package/crates/team-agent/src/messaging/tests/spine.rs +40 -24
- package/crates/team-agent/src/messaging/types.rs +1 -0
- package/crates/team-agent/src/provider/adapter.rs +303 -51
- 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 -5
- 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 +106 -6
- package/crates/team-agent/src/provider/session/context_fork/claude.rs +123 -0
- package/crates/team-agent/src/provider/session/context_fork/outcome.rs +4 -0
- package/crates/team-agent/src/provider/session/context_fork.rs +150 -18
- package/crates/team-agent/src/provider/session_scan/claude.rs +523 -0
- package/crates/team-agent/src/provider/session_scan/common.rs +44 -8
- package/crates/team-agent/src/provider/session_scan/pi.rs +34 -1
- package/crates/team-agent/src/provider/session_scan.rs +16 -6
- package/crates/team-agent/src/provider/tests/adapter.rs +104 -17
- package/crates/team-agent/src/provider/tests/classify.rs +0 -53
- package/crates/team-agent/src/provider/tests/command_helpers.rs +12 -3
- package/crates/team-agent/src/provider/tests/idle.rs +37 -0
- package/crates/team-agent/src/provider/wire.rs +22 -34
- 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 +5 -40
- package/package.json +4 -4
- package/skills/team-agent/SKILL.md +5 -7
- package/skills/team-agent/command-coverage.json +1 -1
- package/skills/team-agent/docs/reference/team-agent-operator.md +3 -3
- package/skills/team-agent/references/team-agent-operator.md +3 -3
|
@@ -0,0 +1,523 @@
|
|
|
1
|
+
//! ---
|
|
2
|
+
//! purpose: claude 家族的会话归属过滤——按 expected id 直达 ~/.claude/projects/<编码 cwd>/<sid>.jsonl 读头验身份,并为通用扫描提供 leader-transcript 与 cwd 字段两道排除判据
|
|
3
|
+
//! contract:
|
|
4
|
+
//! provides:
|
|
5
|
+
//! - name: projects_dir_for_cwd
|
|
6
|
+
//! what: 由 HOME + spawn_cwd 推出 claude 的 projects 目录(非字母数字字符一律替成 '-')
|
|
7
|
+
//! - name: encode_projects_dir
|
|
8
|
+
//! what: claude 的目录名编码规则本身
|
|
9
|
+
//! - name: scan_expected_session
|
|
10
|
+
//! what: 有 pending id 时的直达捕获:读头 64KB,验 sessionId 一致 + 有 user/assistant 记录 + 无 leader marker + 有 cwd 字段,四条全过才出候选
|
|
11
|
+
//! - name: rollout_path_has_leader_marker
|
|
12
|
+
//! what: 判某条 transcript 是不是 leader 的(customTitle/agentName == "claude leader")
|
|
13
|
+
//! - name: records_have_leader_marker
|
|
14
|
+
//! what: 上一条的记录级判据
|
|
15
|
+
//! - name: has_cwd_field
|
|
16
|
+
//! what: 记录里有没有 cwd 字段——claude transcript 的最低可信度门槛
|
|
17
|
+
//! - name: apply_expected_session_filter
|
|
18
|
+
//! what: 通用扫描结果的收窄:expected 命中则独取,未命中则只留身份/路径阳性的
|
|
19
|
+
//! requires:
|
|
20
|
+
//! - name: super::common
|
|
21
|
+
//! what: 读头、解析记录、embedded 身份、时间窗过滤都复用 common
|
|
22
|
+
//! - name: crate::provider::helpers::find_session_id
|
|
23
|
+
//! what: 从记录里取 sessionId 的统一入口
|
|
24
|
+
//! boundary:
|
|
25
|
+
//! - 只服务 Provider::Claude / ClaudeCode;rollout_path_has_leader_marker 对其它 provider 恒 false
|
|
26
|
+
//! - 不写盘、不改 state、不发事件
|
|
27
|
+
//! - 直达路径不做同 cwd「最新文件」回落——有 pending id 就只认那一个文件名
|
|
28
|
+
//! - leader transcript 一律排除,防止 worker 席位绑上 leader 的会话
|
|
29
|
+
//! maturity: wired
|
|
30
|
+
//! ---
|
|
31
|
+
use std::path::{Path, PathBuf};
|
|
32
|
+
|
|
33
|
+
use crate::provider::helpers::find_session_id;
|
|
34
|
+
use crate::provider::types::{CaptureVia, CapturedSession, Confidence, RolloutPath, SessionId};
|
|
35
|
+
use crate::provider::Provider;
|
|
36
|
+
|
|
37
|
+
use super::{CaptureSessionContext, CapturedSessionCandidate};
|
|
38
|
+
|
|
39
|
+
/// ---
|
|
40
|
+
/// purpose: 由 HOME 与席位 cwd 推出 claude 存放该工作目录 transcript 的 projects 子目录
|
|
41
|
+
/// params:
|
|
42
|
+
/// home: HOME 根;调用方决定是真实 HOME 还是隔离根
|
|
43
|
+
/// spawn_cwd: 席位工作目录;先 canonicalize,失败则原样使用
|
|
44
|
+
/// returns: <home>/.claude/projects/<编码后的 cwd>;编码结果为空串时 None
|
|
45
|
+
/// contract:
|
|
46
|
+
/// provides:
|
|
47
|
+
/// - name: projects_dir_for_cwd
|
|
48
|
+
/// what: 只拼路径,不创建目录、不判存在性
|
|
49
|
+
/// boundary:
|
|
50
|
+
/// - 不枚举目录内容、不读任何文件
|
|
51
|
+
/// - canonicalize 失败不报错,退回原路径——编码结果因此可能与 claude 实际用的目录不同
|
|
52
|
+
/// ---
|
|
53
|
+
pub(crate) fn projects_dir_for_cwd(home: &Path, spawn_cwd: &Path) -> Option<PathBuf> {
|
|
54
|
+
let canonical = std::fs::canonicalize(spawn_cwd).unwrap_or_else(|_| spawn_cwd.to_path_buf());
|
|
55
|
+
let encoded = encode_projects_dir(&canonical.to_string_lossy());
|
|
56
|
+
if encoded.is_empty() {
|
|
57
|
+
return None;
|
|
58
|
+
}
|
|
59
|
+
Some(home.join(".claude").join("projects").join(encoded))
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/// ---
|
|
63
|
+
/// purpose: 复刻 claude 的 projects 目录名编码:非 ASCII 字母数字的字符一律替成单个 '-'
|
|
64
|
+
/// params:
|
|
65
|
+
/// path: 待编码的路径文本
|
|
66
|
+
/// returns: 等长的编码串;输入为空则空串
|
|
67
|
+
/// contract:
|
|
68
|
+
/// provides:
|
|
69
|
+
/// - name: encode_projects_dir
|
|
70
|
+
/// what: 纯字符映射,逐字符一对一,不折叠连续分隔符
|
|
71
|
+
/// boundary:
|
|
72
|
+
/// - 有损且不可逆:不同路径可以编出同一个目录名
|
|
73
|
+
/// - 不做长度截断、不做大小写归一
|
|
74
|
+
/// ---
|
|
75
|
+
pub(super) fn encode_projects_dir(path: &str) -> String {
|
|
76
|
+
let mut out = String::with_capacity(path.len());
|
|
77
|
+
for c in path.chars() {
|
|
78
|
+
if c.is_ascii_alphanumeric() {
|
|
79
|
+
out.push(c);
|
|
80
|
+
} else {
|
|
81
|
+
out.push('-');
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
out
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/// ---
|
|
88
|
+
/// purpose: 有 pending id 时直达那一个 transcript 文件,读头验明身份后给出唯一候选
|
|
89
|
+
/// params:
|
|
90
|
+
/// context: 需要 expected_session_id;projects 根优先取 provider_projects_root,否则退到 HOME/.claude/projects;spawn_cwd 决定编码后的子目录
|
|
91
|
+
/// returns: 四道校验全过则一条 FsWatch/High 候选(带 embedded 身份与是否与本席位一致);任一条不过则空向量
|
|
92
|
+
/// contract:
|
|
93
|
+
/// provides:
|
|
94
|
+
/// - name: scan_expected_session
|
|
95
|
+
/// what: 只读该文件头 64KB;不遍历目录、不比较 mtime
|
|
96
|
+
/// boundary:
|
|
97
|
+
/// - 无 expected_session_id / 无法确定 projects 根 / 编码为空 / 文件读不出来 → 空向量
|
|
98
|
+
/// - 四道校验:sessionId 与 expected 相等、存在 user 或 assistant 记录、不含 leader marker、至少一条记录有 cwd 字段
|
|
99
|
+
/// - embedded 身份与本席位不符时仍返回候选(positive_agent_id_match=false),是否拒绝交给上游分配器判定
|
|
100
|
+
/// - agent_path_match 恒 false:直达路径下文件名就是 uuid,不含席位名
|
|
101
|
+
/// ---
|
|
102
|
+
pub(super) fn scan_expected_session(
|
|
103
|
+
context: &CaptureSessionContext,
|
|
104
|
+
) -> Vec<CapturedSessionCandidate> {
|
|
105
|
+
let Some(expected) = context.expected_session_id.as_ref() else {
|
|
106
|
+
return Vec::new();
|
|
107
|
+
};
|
|
108
|
+
let Some(projects_root) = context.provider_projects_root.clone().or_else(|| {
|
|
109
|
+
std::env::var_os("HOME")
|
|
110
|
+
.map(PathBuf::from)
|
|
111
|
+
.map(|home| home.join(".claude").join("projects"))
|
|
112
|
+
}) else {
|
|
113
|
+
return Vec::new();
|
|
114
|
+
};
|
|
115
|
+
let canonical =
|
|
116
|
+
std::fs::canonicalize(&context.spawn_cwd).unwrap_or_else(|_| context.spawn_cwd.clone());
|
|
117
|
+
let encoded = encode_projects_dir(&canonical.to_string_lossy());
|
|
118
|
+
if encoded.is_empty() {
|
|
119
|
+
return Vec::new();
|
|
120
|
+
}
|
|
121
|
+
let path = projects_root
|
|
122
|
+
.join(encoded)
|
|
123
|
+
.join(format!("{}.jsonl", expected.as_str()));
|
|
124
|
+
let Ok(text) = super::common::read_head_text(&path, super::common::CAPTURE_HEAD_BYTES) else {
|
|
125
|
+
return Vec::new();
|
|
126
|
+
};
|
|
127
|
+
let records = super::common::parse_session_records(&text);
|
|
128
|
+
let session_matches = records
|
|
129
|
+
.iter()
|
|
130
|
+
.find_map(find_session_id)
|
|
131
|
+
.is_some_and(|session_id| session_id == expected.as_str());
|
|
132
|
+
let has_lifecycle_record = records.iter().any(|record| {
|
|
133
|
+
matches!(
|
|
134
|
+
record.get("type").and_then(serde_json::Value::as_str),
|
|
135
|
+
Some("user" | "assistant")
|
|
136
|
+
)
|
|
137
|
+
});
|
|
138
|
+
if !session_matches
|
|
139
|
+
|| !has_lifecycle_record
|
|
140
|
+
|| records_have_leader_marker(&records)
|
|
141
|
+
|| !records.iter().any(has_cwd_field)
|
|
142
|
+
{
|
|
143
|
+
return Vec::new();
|
|
144
|
+
}
|
|
145
|
+
let embedded_agent_id = super::common::embedded_team_agent_worker_id_from_text(&text);
|
|
146
|
+
let positive_agent_id_match = embedded_agent_id.as_deref() == Some(context.agent_id.as_str());
|
|
147
|
+
vec![CapturedSessionCandidate {
|
|
148
|
+
captured: CapturedSession {
|
|
149
|
+
session_id: Some(expected.clone()),
|
|
150
|
+
rollout_path: Some(RolloutPath::new(path)),
|
|
151
|
+
captured_via: CaptureVia::FsWatch,
|
|
152
|
+
attribution_confidence: Confidence::High,
|
|
153
|
+
spawn_cwd: context.spawn_cwd.clone(),
|
|
154
|
+
},
|
|
155
|
+
embedded_agent_id,
|
|
156
|
+
positive_agent_id_match,
|
|
157
|
+
agent_path_match: false,
|
|
158
|
+
}]
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/// ---
|
|
162
|
+
/// purpose: 判断一条 transcript 是不是 leader 的会话,供捕获与 event-log 修复两条通道共用排除
|
|
163
|
+
/// params:
|
|
164
|
+
/// provider: 非 Claude/ClaudeCode 一律直接判否
|
|
165
|
+
/// rollout_path: 待判定的 transcript 路径
|
|
166
|
+
/// returns: 读得到头且头部记录里出现 leader marker 才为 true
|
|
167
|
+
/// contract:
|
|
168
|
+
/// provides:
|
|
169
|
+
/// - name: rollout_path_has_leader_marker
|
|
170
|
+
/// what: 只读头 64KB
|
|
171
|
+
/// boundary:
|
|
172
|
+
/// - 文件打不开、解析不出记录一律返回 false —— 判据是 fail-open 的:读不到不等于不是 leader
|
|
173
|
+
/// - marker 只在头窗口内查;超出 64KB 之后才出现的 marker 看不见
|
|
174
|
+
/// ---
|
|
175
|
+
pub(crate) fn rollout_path_has_leader_marker(provider: Provider, rollout_path: &Path) -> bool {
|
|
176
|
+
if !matches!(provider, Provider::Claude | Provider::ClaudeCode) {
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
let Ok(text) = super::common::read_head_text(rollout_path, super::common::CAPTURE_HEAD_BYTES)
|
|
180
|
+
else {
|
|
181
|
+
return false;
|
|
182
|
+
};
|
|
183
|
+
let records = super::common::parse_session_records(&text);
|
|
184
|
+
records_have_leader_marker(&records)
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/// ---
|
|
188
|
+
/// purpose: 在已解析的记录里找 leader 身份 marker
|
|
189
|
+
/// params:
|
|
190
|
+
/// records: 已解析的 transcript 记录切片
|
|
191
|
+
/// returns: 任一记录的 customTitle 或 agentName 小写后等于 "claude leader" 即 true
|
|
192
|
+
/// contract:
|
|
193
|
+
/// provides:
|
|
194
|
+
/// - name: records_have_leader_marker
|
|
195
|
+
/// what: 纯内存判定,无 I/O
|
|
196
|
+
/// boundary:
|
|
197
|
+
/// - 判据是精确串相等(仅大小写不敏感),不做包含匹配、不认其它别名
|
|
198
|
+
/// ---
|
|
199
|
+
pub(super) fn records_have_leader_marker(records: &[serde_json::Value]) -> bool {
|
|
200
|
+
records.iter().any(|record| {
|
|
201
|
+
let custom_title = record
|
|
202
|
+
.get("customTitle")
|
|
203
|
+
.and_then(serde_json::Value::as_str)
|
|
204
|
+
.map(str::to_ascii_lowercase);
|
|
205
|
+
let agent_name = record
|
|
206
|
+
.get("agentName")
|
|
207
|
+
.and_then(serde_json::Value::as_str)
|
|
208
|
+
.map(str::to_ascii_lowercase);
|
|
209
|
+
matches!(custom_title.as_deref(), Some("claude leader"))
|
|
210
|
+
|| matches!(agent_name.as_deref(), Some("claude leader"))
|
|
211
|
+
})
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/// ---
|
|
215
|
+
/// purpose: 判断一条 claude 记录是否带 cwd 字段——用作 transcript 是否够格当候选的最低门槛
|
|
216
|
+
/// params:
|
|
217
|
+
/// record: 单条已解析记录
|
|
218
|
+
/// returns: common::record_cwd 能取到值即 true
|
|
219
|
+
/// contract:
|
|
220
|
+
/// provides:
|
|
221
|
+
/// - name: has_cwd_field
|
|
222
|
+
/// what: 只判字段有无,不比较 cwd 是否等于席位 cwd
|
|
223
|
+
/// boundary:
|
|
224
|
+
/// - 不做路径等价判定;是否同 cwd 由调用方另行判断
|
|
225
|
+
/// ---
|
|
226
|
+
pub(super) fn has_cwd_field(record: &serde_json::Value) -> bool {
|
|
227
|
+
super::common::record_cwd(record).is_some()
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/// ---
|
|
231
|
+
/// purpose: 用 pending id 收窄通用扫描的结果,把「可能是它」压成「就是它」或「至少身份阳性」
|
|
232
|
+
/// params:
|
|
233
|
+
/// context: 有 expected_session_id 才做收窄;否则退到时间窗过滤
|
|
234
|
+
/// out: 待收窄的候选列表,按值传入
|
|
235
|
+
/// returns: expected 命中则只留那一条;未命中则只留 positive_agent_id_match 或 agent_path_match 为真的;无 expected 则原表经唯一时间窗过滤后返回
|
|
236
|
+
/// errors: 当前实现不产生 Err;返回 Result 是为与其它 provider 过滤器同形
|
|
237
|
+
/// contract:
|
|
238
|
+
/// provides:
|
|
239
|
+
/// - name: apply_expected_session_filter
|
|
240
|
+
/// what: 纯过滤,不读盘(时间窗分支会取候选文件 mtime)
|
|
241
|
+
/// boundary:
|
|
242
|
+
/// - 未命中 expected 时不返回空而是返回身份阳性子集——弱于「必须命中」,允许分配器再判
|
|
243
|
+
/// - 不排序;expected 优先排序由 common::sort_expected_first_if_needed 另做
|
|
244
|
+
/// ---
|
|
245
|
+
pub(super) fn apply_expected_session_filter(
|
|
246
|
+
context: &CaptureSessionContext,
|
|
247
|
+
mut out: Vec<CapturedSessionCandidate>,
|
|
248
|
+
) -> Result<Vec<CapturedSessionCandidate>, crate::provider::types::ProviderError> {
|
|
249
|
+
if let Some(expected) = context.expected_session_id.as_ref() {
|
|
250
|
+
if let Some(hit) = out
|
|
251
|
+
.iter()
|
|
252
|
+
.find(|candidate| session_matches(candidate, expected))
|
|
253
|
+
{
|
|
254
|
+
return Ok(vec![hit.clone()]);
|
|
255
|
+
}
|
|
256
|
+
let positive_only: Vec<CapturedSessionCandidate> = out
|
|
257
|
+
.iter()
|
|
258
|
+
.filter(|candidate| candidate.positive_agent_id_match || candidate.agent_path_match)
|
|
259
|
+
.cloned()
|
|
260
|
+
.collect();
|
|
261
|
+
return Ok(positive_only);
|
|
262
|
+
}
|
|
263
|
+
super::common::apply_spawn_time_window_if_unique(Provider::Claude, context, &mut out);
|
|
264
|
+
Ok(out)
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
fn session_matches(candidate: &CapturedSessionCandidate, expected: &SessionId) -> bool {
|
|
268
|
+
candidate
|
|
269
|
+
.captured
|
|
270
|
+
.session_id
|
|
271
|
+
.as_ref()
|
|
272
|
+
.is_some_and(|session| session.as_str() == expected.as_str())
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
#[cfg(test)]
|
|
276
|
+
mod tests {
|
|
277
|
+
#![allow(clippy::unwrap_used)]
|
|
278
|
+
|
|
279
|
+
use super::*;
|
|
280
|
+
use crate::provider::types::SessionId;
|
|
281
|
+
use crate::provider::Provider;
|
|
282
|
+
use std::sync::atomic::{AtomicU64, Ordering};
|
|
283
|
+
|
|
284
|
+
fn tmp_root(tag: &str) -> PathBuf {
|
|
285
|
+
static CTR: AtomicU64 = AtomicU64::new(0);
|
|
286
|
+
let dir = std::env::temp_dir().join(format!(
|
|
287
|
+
"ta-e6-attr-{}-{}-{}",
|
|
288
|
+
tag,
|
|
289
|
+
std::process::id(),
|
|
290
|
+
CTR.fetch_add(1, Ordering::Relaxed)
|
|
291
|
+
));
|
|
292
|
+
std::fs::create_dir_all(&dir).unwrap();
|
|
293
|
+
dir
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
fn write_transcript(dir: &Path, uuid: &str, cwd: &Path) -> PathBuf {
|
|
297
|
+
std::fs::create_dir_all(dir).unwrap();
|
|
298
|
+
let path = dir.join(format!("{uuid}.jsonl"));
|
|
299
|
+
let line = serde_json::json!({
|
|
300
|
+
"type": "user",
|
|
301
|
+
"sessionId": uuid,
|
|
302
|
+
"cwd": cwd.to_string_lossy(),
|
|
303
|
+
});
|
|
304
|
+
std::fs::write(&path, format!("{line}\n")).unwrap();
|
|
305
|
+
path
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
fn expected_transcript_dir(projects_root: &Path, cwd: &Path) -> PathBuf {
|
|
309
|
+
let canonical = std::fs::canonicalize(cwd).unwrap_or_else(|_| cwd.to_path_buf());
|
|
310
|
+
projects_root.join(encode_projects_dir(&canonical.to_string_lossy()))
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
#[test]
|
|
314
|
+
fn claude_leader_marker_in_custom_title_is_detected() {
|
|
315
|
+
let records = vec![serde_json::json!({
|
|
316
|
+
"type": "custom-title",
|
|
317
|
+
"customTitle": "claude leader",
|
|
318
|
+
"sessionId": "ea059b82",
|
|
319
|
+
})];
|
|
320
|
+
assert!(records_have_leader_marker(&records));
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
#[test]
|
|
324
|
+
fn claude_leader_marker_in_agent_name_is_detected() {
|
|
325
|
+
let records = vec![serde_json::json!({
|
|
326
|
+
"type": "agent-name",
|
|
327
|
+
"agentName": "claude leader",
|
|
328
|
+
"sessionId": "ea059b82",
|
|
329
|
+
})];
|
|
330
|
+
assert!(records_have_leader_marker(&records));
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
#[test]
|
|
334
|
+
fn claude_worker_records_have_no_leader_marker() {
|
|
335
|
+
let records = vec![
|
|
336
|
+
serde_json::json!({
|
|
337
|
+
"type": "custom-title",
|
|
338
|
+
"customTitle": "claude release-engineer",
|
|
339
|
+
"sessionId": "abc12345",
|
|
340
|
+
}),
|
|
341
|
+
serde_json::json!({
|
|
342
|
+
"type": "user",
|
|
343
|
+
"content": "Team Agent message from leader: do X",
|
|
344
|
+
"sessionId": "abc12345",
|
|
345
|
+
}),
|
|
346
|
+
];
|
|
347
|
+
assert!(!records_have_leader_marker(&records));
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
#[test]
|
|
351
|
+
fn claude_leader_marker_is_case_insensitive() {
|
|
352
|
+
let records = vec![serde_json::json!({
|
|
353
|
+
"customTitle": "Claude Leader",
|
|
354
|
+
})];
|
|
355
|
+
assert!(records_have_leader_marker(&records));
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
#[test]
|
|
359
|
+
fn claude_projects_dir_for_cwd_encodes_slashes_to_dashes() {
|
|
360
|
+
let home = Path::new("/home/u");
|
|
361
|
+
let cwd = tmp_root("encode");
|
|
362
|
+
let got = projects_dir_for_cwd(home, &cwd).unwrap();
|
|
363
|
+
let canon = std::fs::canonicalize(&cwd).unwrap();
|
|
364
|
+
let expected_leaf = encode_projects_dir(&canon.to_string_lossy());
|
|
365
|
+
assert_eq!(
|
|
366
|
+
got,
|
|
367
|
+
home.join(".claude").join("projects").join(expected_leaf)
|
|
368
|
+
);
|
|
369
|
+
let _ = std::fs::remove_dir_all(&cwd);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
#[test]
|
|
373
|
+
fn encode_claude_projects_dir_parity_with_real_claude_naming() {
|
|
374
|
+
assert_eq!(
|
|
375
|
+
encode_projects_dir("/Users/alauda/code"),
|
|
376
|
+
"-Users-alauda-code"
|
|
377
|
+
);
|
|
378
|
+
assert_eq!(
|
|
379
|
+
encode_projects_dir("/Users/alauda/Documents/code/agent前沿探索/多agent协作"),
|
|
380
|
+
"-Users-alauda-Documents-code-agent------agent--"
|
|
381
|
+
);
|
|
382
|
+
assert_eq!(
|
|
383
|
+
encode_projects_dir("/Users/foo bar.baz/v1.2"),
|
|
384
|
+
"-Users-foo-bar-baz-v1-2"
|
|
385
|
+
);
|
|
386
|
+
assert_eq!(
|
|
387
|
+
encode_projects_dir("/proj/.team/runtime"),
|
|
388
|
+
"-proj--team-runtime"
|
|
389
|
+
);
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
#[test]
|
|
393
|
+
fn scan_expected_session_id_hit_returns_only_that_candidate() {
|
|
394
|
+
let base = tmp_root("c-hit");
|
|
395
|
+
let cwd = base.join("ws");
|
|
396
|
+
std::fs::create_dir_all(&cwd).unwrap();
|
|
397
|
+
let proj = base.join("projects");
|
|
398
|
+
write_transcript(&proj, "11111111-1111-4111-8111-111111111111", &cwd);
|
|
399
|
+
let expected = write_transcript(
|
|
400
|
+
&expected_transcript_dir(&proj, &cwd),
|
|
401
|
+
"22222222-2222-4222-8222-222222222222",
|
|
402
|
+
&cwd,
|
|
403
|
+
);
|
|
404
|
+
let ctx = CaptureSessionContext {
|
|
405
|
+
agent_id: "w1".to_string(),
|
|
406
|
+
spawn_cwd: cwd.clone(),
|
|
407
|
+
pane_id: None,
|
|
408
|
+
pane_pid: None,
|
|
409
|
+
spawned_at: None,
|
|
410
|
+
expected_session_id: Some(SessionId::new("22222222-2222-4222-8222-222222222222")),
|
|
411
|
+
provider_projects_root: Some(proj.clone()),
|
|
412
|
+
};
|
|
413
|
+
let out = super::super::scan_session_candidates_once(Provider::ClaudeCode, &ctx).unwrap();
|
|
414
|
+
assert_eq!(out.len(), 1);
|
|
415
|
+
assert_eq!(
|
|
416
|
+
out[0].captured.session_id.as_ref().unwrap().as_str(),
|
|
417
|
+
"22222222-2222-4222-8222-222222222222"
|
|
418
|
+
);
|
|
419
|
+
assert_eq!(
|
|
420
|
+
out[0].captured.rollout_path.as_ref().unwrap().as_path(),
|
|
421
|
+
expected
|
|
422
|
+
);
|
|
423
|
+
let _ = std::fs::remove_dir_all(&base);
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
#[test]
|
|
427
|
+
fn scan_spawn_time_window_disambiguates_two_siblings() {
|
|
428
|
+
let base = tmp_root("b-window");
|
|
429
|
+
let cwd = base.join("ws");
|
|
430
|
+
std::fs::create_dir_all(&cwd).unwrap();
|
|
431
|
+
let proj = base.join("projects");
|
|
432
|
+
let old = write_transcript(&proj, "aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaaa", &cwd);
|
|
433
|
+
let new = write_transcript(&proj, "bbbbbbbb-bbbb-4bbb-8bbb-bbbbbbbbbbbb", &cwd);
|
|
434
|
+
let long_ago =
|
|
435
|
+
std::time::SystemTime::UNIX_EPOCH + std::time::Duration::from_secs(1_000_000);
|
|
436
|
+
filetime_set(&old, long_ago);
|
|
437
|
+
let ctx = CaptureSessionContext {
|
|
438
|
+
agent_id: "w1".to_string(),
|
|
439
|
+
spawn_cwd: cwd.clone(),
|
|
440
|
+
pane_id: None,
|
|
441
|
+
pane_pid: None,
|
|
442
|
+
spawned_at: Some("2020-01-01T00:00:00+00:00".to_string()),
|
|
443
|
+
expected_session_id: None,
|
|
444
|
+
provider_projects_root: Some(proj.clone()),
|
|
445
|
+
};
|
|
446
|
+
let out = super::super::scan_session_candidates_once(Provider::ClaudeCode, &ctx).unwrap();
|
|
447
|
+
assert_eq!(out.len(), 1);
|
|
448
|
+
assert_eq!(
|
|
449
|
+
out[0].captured.session_id.as_ref().unwrap().as_str(),
|
|
450
|
+
"bbbbbbbb-bbbb-4bbb-8bbb-bbbbbbbbbbbb"
|
|
451
|
+
);
|
|
452
|
+
let _ = new;
|
|
453
|
+
let _ = std::fs::remove_dir_all(&base);
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
#[test]
|
|
457
|
+
fn scan_no_spawned_at_keeps_both_siblings_ambiguous() {
|
|
458
|
+
let base = tmp_root("b-noamb");
|
|
459
|
+
let cwd = base.join("ws");
|
|
460
|
+
std::fs::create_dir_all(&cwd).unwrap();
|
|
461
|
+
let proj = base.join("projects");
|
|
462
|
+
write_transcript(&proj, "cccccccc-cccc-4ccc-8ccc-cccccccccccc", &cwd);
|
|
463
|
+
write_transcript(&proj, "dddddddd-dddd-4ddd-8ddd-dddddddddddd", &cwd);
|
|
464
|
+
let ctx = CaptureSessionContext {
|
|
465
|
+
agent_id: "w1".to_string(),
|
|
466
|
+
spawn_cwd: cwd.clone(),
|
|
467
|
+
pane_id: None,
|
|
468
|
+
pane_pid: None,
|
|
469
|
+
spawned_at: None,
|
|
470
|
+
expected_session_id: None,
|
|
471
|
+
provider_projects_root: Some(proj.clone()),
|
|
472
|
+
};
|
|
473
|
+
let out = super::super::scan_session_candidates_once(Provider::ClaudeCode, &ctx).unwrap();
|
|
474
|
+
assert!(out.len() >= 2);
|
|
475
|
+
let _ = std::fs::remove_dir_all(&base);
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
#[test]
|
|
479
|
+
fn scan_expected_session_id_miss_refuses_to_pick_leader_sibling() {
|
|
480
|
+
let base = tmp_root("strict-no-leader-fallback");
|
|
481
|
+
let cwd = base.join("ws");
|
|
482
|
+
std::fs::create_dir_all(&cwd).unwrap();
|
|
483
|
+
let proj = base.join("projects");
|
|
484
|
+
let leader = write_transcript(&proj, "11111111-1111-4111-8111-111111111111", &cwd);
|
|
485
|
+
let stale = write_transcript(&proj, "22222222-2222-4222-8222-222222222222", &cwd);
|
|
486
|
+
let addressed =
|
|
487
|
+
expected_transcript_dir(&proj, &cwd).join("99999999-9999-4999-8999-999999999999.jsonl");
|
|
488
|
+
std::fs::create_dir_all(addressed.parent().unwrap()).unwrap();
|
|
489
|
+
std::fs::write(
|
|
490
|
+
&addressed,
|
|
491
|
+
format!(
|
|
492
|
+
"{}\n",
|
|
493
|
+
serde_json::json!({
|
|
494
|
+
"type": "user",
|
|
495
|
+
"sessionId": "22222222-2222-4222-8222-222222222222",
|
|
496
|
+
"cwd": cwd.to_string_lossy(),
|
|
497
|
+
})
|
|
498
|
+
),
|
|
499
|
+
)
|
|
500
|
+
.unwrap();
|
|
501
|
+
let _ = (leader, stale);
|
|
502
|
+
let ctx = CaptureSessionContext {
|
|
503
|
+
agent_id: "claude-worker".to_string(),
|
|
504
|
+
spawn_cwd: cwd.clone(),
|
|
505
|
+
pane_id: None,
|
|
506
|
+
pane_pid: None,
|
|
507
|
+
spawned_at: Some("2020-01-01T00:00:00+00:00".to_string()),
|
|
508
|
+
expected_session_id: Some(SessionId::new("99999999-9999-4999-8999-999999999999")),
|
|
509
|
+
provider_projects_root: Some(proj.clone()),
|
|
510
|
+
};
|
|
511
|
+
let out = super::super::scan_session_candidates_once(Provider::ClaudeCode, &ctx).unwrap();
|
|
512
|
+
assert!(
|
|
513
|
+
out.is_empty(),
|
|
514
|
+
"expected-id miss must not fall back to latest"
|
|
515
|
+
);
|
|
516
|
+
let _ = std::fs::remove_dir_all(&base);
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
fn filetime_set(path: &Path, when: std::time::SystemTime) {
|
|
520
|
+
let f = std::fs::OpenOptions::new().write(true).open(path).unwrap();
|
|
521
|
+
f.set_modified(when).unwrap();
|
|
522
|
+
}
|
|
523
|
+
}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
//! - name: candidate_session_files
|
|
6
6
|
//! what: 枚举候选文件(隔离根 + spawn_cwd 递归),去重排序并按 mtime 截到 300 条
|
|
7
7
|
//! - name: parse_candidate_files
|
|
8
|
-
//! what: 逐个读头 64KB 解析成 CapturedSessionCandidate,途中套 cwd
|
|
8
|
+
//! what: 逐个读头 64KB 解析成 CapturedSessionCandidate,途中套 cwd 匹配、embedded 身份、claude cwd 字段与 leader marker 四道排除
|
|
9
9
|
//! - name: apply_spawned_at_filter
|
|
10
10
|
//! what: 剔除早于席位进程世代边界(spawned_at)的存档;spawned_at 存在但解析不了则清空候选
|
|
11
11
|
//! - name: apply_spawn_time_window_if_unique
|
|
@@ -29,10 +29,12 @@
|
|
|
29
29
|
//! requires:
|
|
30
30
|
//! - name: crate::provider::helpers
|
|
31
31
|
//! what: find_session_id 与 parse_jsonl_records
|
|
32
|
+
//! - name: super::claude
|
|
33
|
+
//! what: claude 家族的 projects 目录推导、cwd 字段判据与 leader marker 判据
|
|
32
34
|
//! boundary:
|
|
33
35
|
//! - 一律只读:不写盘、不改 state、不发事件
|
|
34
36
|
//! - 只产出候选与事实;归属最终由上游分配器裁定,本文件不写会话
|
|
35
|
-
//! - spawn_cwd 递归最深 4 层,且跳过 .team 运行时目录
|
|
37
|
+
//! - spawn_cwd 递归最深 4 层,且跳过 .team 运行时目录(claude 的隔离根例外)
|
|
36
38
|
//! - 候选上限 300 条,超出按 mtime 由新到旧截断——截掉的部分不留痕迹
|
|
37
39
|
//! - "看起来像会话文件"的判据很宽(.json/.jsonl 后缀,或名字含 session/rollout/席位 id),收窄靠后续 provider 专属过滤
|
|
38
40
|
//! maturity: wired
|
|
@@ -62,7 +64,7 @@ pub(super) const CAPTURE_HEAD_BYTES: u64 = 65_536;
|
|
|
62
64
|
/// ---
|
|
63
65
|
/// purpose: 枚举本席位可能对应的会话文件,产出待解析的候选路径表
|
|
64
66
|
/// params:
|
|
65
|
-
///
|
|
67
|
+
/// provider: 决定要不要去 ~/.claude/projects 找
|
|
66
68
|
/// context: provider_projects_root(隔离根)、spawn_cwd(必扫)、agent_id(参与文件名匹配)
|
|
67
69
|
/// returns: 去重并排序后的候选;requires_cwd_match=false 的排前面,同组按路径字典序
|
|
68
70
|
/// errors: 只有 spawn_cwd 这一层根目录读不开才上抛 Io;隔离根读失败静默跳过
|
|
@@ -77,12 +79,14 @@ pub(super) const CAPTURE_HEAD_BYTES: u64 = 65_536;
|
|
|
77
79
|
/// - 任何 provider 都不走 HOME 分支——Copilot / Pi 各有专属扫描,退役的 legacy 席位不扫描
|
|
78
80
|
/// ---
|
|
79
81
|
pub(super) fn candidate_session_files(
|
|
80
|
-
|
|
82
|
+
provider: Provider,
|
|
81
83
|
context: &CaptureSessionContext,
|
|
82
84
|
) -> Result<Vec<SessionCandidate>, ProviderError> {
|
|
83
85
|
let mut out = Vec::new();
|
|
84
86
|
if let Some(root) = context.provider_projects_root.as_ref() {
|
|
85
|
-
|
|
87
|
+
let allowed_team_root =
|
|
88
|
+
matches!(provider, Provider::Claude | Provider::ClaudeCode).then_some(root.as_path());
|
|
89
|
+
collect_optional_candidate_files(root, &context.agent_id, allowed_team_root, &mut out)?;
|
|
86
90
|
}
|
|
87
91
|
collect_candidate_files(
|
|
88
92
|
&context.spawn_cwd,
|
|
@@ -92,6 +96,27 @@ pub(super) fn candidate_session_files(
|
|
|
92
96
|
None,
|
|
93
97
|
&mut out,
|
|
94
98
|
)?;
|
|
99
|
+
if let Some(home) = std::env::var_os("HOME").map(PathBuf::from) {
|
|
100
|
+
match provider {
|
|
101
|
+
Provider::Claude | Provider::ClaudeCode => {
|
|
102
|
+
if let Some(dir) = super::claude::projects_dir_for_cwd(&home, &context.spawn_cwd) {
|
|
103
|
+
collect_optional_candidate_files(&dir, &context.agent_id, None, &mut out)?;
|
|
104
|
+
}
|
|
105
|
+
collect_optional_candidate_files(
|
|
106
|
+
&home.join(".claude").join("projects"),
|
|
107
|
+
&context.agent_id,
|
|
108
|
+
None,
|
|
109
|
+
&mut out,
|
|
110
|
+
)?;
|
|
111
|
+
}
|
|
112
|
+
Provider::Codex
|
|
113
|
+
| Provider::Copilot
|
|
114
|
+
| Provider::Grok
|
|
115
|
+
| Provider::Pi
|
|
116
|
+
| Provider::GeminiCli
|
|
117
|
+
| Provider::Fake => {}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
95
120
|
out.sort_by(|a, b| {
|
|
96
121
|
a.requires_cwd_match
|
|
97
122
|
.cmp(&b.requires_cwd_match)
|
|
@@ -105,7 +130,7 @@ pub(super) fn candidate_session_files(
|
|
|
105
130
|
/// ---
|
|
106
131
|
/// purpose: 把候选路径读头解析成结构化候选,并在解析途中就滤掉明显不属于本席位的
|
|
107
132
|
/// params:
|
|
108
|
-
///
|
|
133
|
+
/// provider: 决定是否套用 claude 专属的两道排除
|
|
109
134
|
/// context: 提供 spawn_cwd 与 agent_id 两个比对基准
|
|
110
135
|
/// candidates: candidate_session_files 的产物
|
|
111
136
|
/// returns: 通过全部排除的候选;每条带 embedded 身份、positive_agent_id_match 与 agent_path_match
|
|
@@ -114,12 +139,12 @@ pub(super) fn candidate_session_files(
|
|
|
114
139
|
/// - name: parse_candidate_files
|
|
115
140
|
/// what: 每个文件只读头 64KB,且只取到最后一个完整行
|
|
116
141
|
/// boundary:
|
|
117
|
-
/// -
|
|
142
|
+
/// - 四道排除:读不出头 / 解析不出记录 → 跳过;requires_cwd_match 的候选 cwd 对不上 → 跳过;embedded 身份存在且不等于本席位 → 跳过;claude 家族有 session id 却无 cwd 字段、或含 leader marker → 跳过
|
|
118
143
|
/// - 无 session id 的候选不丢弃,降级为 FsMtimeFallback + Confidence::Low
|
|
119
144
|
/// - 身份判定用两套文本:正文 text 判 TEAM_AGENT_ID,未截行的原始字节判 embedded worker id
|
|
120
145
|
/// ---
|
|
121
146
|
pub(super) fn parse_candidate_files(
|
|
122
|
-
|
|
147
|
+
provider: Provider,
|
|
123
148
|
context: &CaptureSessionContext,
|
|
124
149
|
candidates: Vec<SessionCandidate>,
|
|
125
150
|
) -> Vec<CapturedSessionCandidate> {
|
|
@@ -141,6 +166,12 @@ pub(super) fn parse_candidate_files(
|
|
|
141
166
|
continue;
|
|
142
167
|
}
|
|
143
168
|
let session_id = records.iter().find_map(find_session_id);
|
|
169
|
+
if matches!(provider, Provider::Claude | Provider::ClaudeCode)
|
|
170
|
+
&& session_id.is_some()
|
|
171
|
+
&& !records.iter().any(super::claude::has_cwd_field)
|
|
172
|
+
{
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
144
175
|
let captured_via = if session_id.is_some() {
|
|
145
176
|
CaptureVia::FsWatch
|
|
146
177
|
} else {
|
|
@@ -161,6 +192,11 @@ pub(super) fn parse_candidate_files(
|
|
|
161
192
|
let positive_agent_id_match = candidate_text_has_team_agent_id(&text, context)
|
|
162
193
|
|| embedded_agent_id.as_deref() == Some(context.agent_id.as_str());
|
|
163
194
|
let agent_path_match = candidate_path_matches_agent_id(&path, context);
|
|
195
|
+
if matches!(provider, Provider::Claude | Provider::ClaudeCode)
|
|
196
|
+
&& super::claude::records_have_leader_marker(&records)
|
|
197
|
+
{
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
164
200
|
out.push(CapturedSessionCandidate {
|
|
165
201
|
captured: CapturedSession {
|
|
166
202
|
session_id: session_id.map(SessionId::new),
|