@team-agent/installer 0.5.124 → 0.5.126
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 -8
- package/Cargo.toml +1 -1
- package/README.md +2 -2
- package/README.zh.md +2 -2
- package/crates/team-agent/Cargo.toml +0 -1
- package/crates/team-agent/src/cli/diagnose.rs +39 -69
- package/crates/team-agent/src/cli/emit.rs +45 -15
- package/crates/team-agent/src/cli/intent/runtime.rs +5 -53
- package/crates/team-agent/src/cli/intent/runtime_tests.rs +10 -130
- package/crates/team-agent/src/cli/leader.rs +2 -3
- package/crates/team-agent/src/cli/leader_prompt.rs +1 -1
- package/crates/team-agent/src/cli/mod.rs +28 -33
- package/crates/team-agent/src/cli/models.rs +44 -880
- package/crates/team-agent/src/cli/route.rs +1 -1
- package/crates/team-agent/src/cli/send/persist.rs +36 -0
- package/crates/team-agent/src/cli/send/presentation.rs +7 -1
- package/crates/team-agent/src/cli/send.rs +3 -1
- package/crates/team-agent/src/cli/spec.rs +1 -2
- package/crates/team-agent/src/cli/status_port/brief.rs +66 -0
- package/crates/team-agent/src/cli/tests/base.rs +4 -11
- package/crates/team-agent/src/cli/tests/mod.rs +1 -1
- package/crates/team-agent/src/cli/tests/run_delegation.rs +5 -4
- package/crates/team-agent/src/cli/tests/status_send.rs +17 -0
- package/crates/team-agent/src/compiler/tests.rs +39 -8
- package/crates/team-agent/src/compiler.rs +28 -204
- package/crates/team-agent/src/contract_runtime/backend.rs +79 -40
- package/crates/team-agent/src/contract_runtime/config.rs +37 -24
- package/crates/team-agent/src/contract_runtime/discovery.rs +33 -0
- package/crates/team-agent/src/contract_runtime/fork.rs +368 -0
- package/crates/team-agent/src/contract_runtime/framework.rs +87 -34
- package/crates/team-agent/src/contract_runtime/mod.rs +1 -0
- package/crates/team-agent/src/contract_runtime/registry.rs +299 -21
- package/crates/team-agent/src/coordinator/runtime_detectors.rs +0 -1
- package/crates/team-agent/src/coordinator/tests/api_error_recovery.rs +29 -8
- package/crates/team-agent/src/coordinator/tests/health_sync.rs +0 -42
- package/crates/team-agent/src/coordinator/tick.rs +89 -1
- package/crates/team-agent/src/db/message_store.rs +78 -3
- package/crates/team-agent/src/layout/worker_window_helpers.rs +0 -1
- package/crates/team-agent/src/leader/prompt.rs +1 -2
- package/crates/team-agent/src/leader/provider_attribution.rs +0 -52
- package/crates/team-agent/src/leader/start.rs +1 -2
- package/crates/team-agent/src/leader/tests/prompt_contract.rs +2 -3
- package/crates/team-agent/src/lifecycle/launch/add_agent.rs +91 -0
- package/crates/team-agent/src/lifecycle/launch/add_agent_state.rs +15 -195
- package/crates/team-agent/src/lifecycle/launch/agent_state.rs +0 -9
- package/crates/team-agent/src/lifecycle/launch/clone_agent.rs +11 -27
- package/crates/team-agent/src/lifecycle/launch/fork_agent.rs +18 -29
- package/crates/team-agent/src/lifecycle/launch/fork_entry.rs +6 -87
- package/crates/team-agent/src/lifecycle/launch/mcp_config.rs +3 -11
- package/crates/team-agent/src/lifecycle/launch/pi_mcp.rs +74 -244
- package/crates/team-agent/src/lifecycle/launch/quick_start.rs +0 -24
- package/crates/team-agent/src/lifecycle/launch/role_source.rs +5 -0
- package/crates/team-agent/src/lifecycle/launch/spawn.rs +21 -61
- package/crates/team-agent/src/lifecycle/launch/spec_state.rs +0 -1
- package/crates/team-agent/src/lifecycle/launch/worker_env.rs +0 -108
- package/crates/team-agent/src/lifecycle/launch.rs +2 -43
- package/crates/team-agent/src/lifecycle/profile_launch.rs +21 -348
- package/crates/team-agent/src/lifecycle/profile_smoke.rs +1 -2
- package/crates/team-agent/src/lifecycle/restart/common.rs +43 -378
- package/crates/team-agent/src/lifecycle/restart/selection.rs +5 -5
- package/crates/team-agent/src/lifecycle/restart.rs +0 -2
- package/crates/team-agent/src/lifecycle/role_config.rs +42 -3
- package/crates/team-agent/src/lifecycle/tests/behavioral_diff_264_red.rs +11 -6
- package/crates/team-agent/src/lifecycle/tests/claude_profile_launch_red.rs +8 -320
- package/crates/team-agent/src/lifecycle/tests/cli_argv_routing_red.rs +60 -145
- package/crates/team-agent/src/lifecycle/tests/clone_fork_copilot_perms_red.rs +8 -334
- package/crates/team-agent/src/lifecycle/tests/communication_mode_runtime_contract_red.rs +30 -11
- package/crates/team-agent/src/lifecycle/tests/copilot_provider_red.rs +2 -2
- package/crates/team-agent/src/lifecycle/tests/core.rs +17 -16
- package/crates/team-agent/src/lifecycle/tests/grok_require_explicit_model_red.rs +12 -12
- package/crates/team-agent/src/lifecycle/tests/harvest2_a_batch_red.rs +3 -51
- package/crates/team-agent/src/lifecycle/tests/launch_spawn.rs +26 -28
- package/crates/team-agent/src/lifecycle/tests/pi_catalog_red.rs +6 -18
- package/crates/team-agent/src/lifecycle/tests/pi_command_red.rs +52 -70
- package/crates/team-agent/src/lifecycle/tests/pi_dual_entry_red.rs +4 -157
- package/crates/team-agent/src/lifecycle/tests/pi_executable_mcp_red.rs +10 -302
- package/crates/team-agent/src/lifecycle/tests/pi_lifecycle_doctor_red.rs +1 -68
- package/crates/team-agent/src/lifecycle/tests/pi_native_mcp_capability_red.rs +1 -19
- package/crates/team-agent/src/lifecycle/tests/pi_session_delivery_red.rs +2 -100
- package/crates/team-agent/src/lifecycle/tests/quick_start_worker_readiness_red.rs +11 -10
- package/crates/team-agent/src/lifecycle/tests/restart_rebind_hotfix_252_red.rs +0 -1
- package/crates/team-agent/src/lifecycle/tests/restart_session_capture_red.rs +2 -106
- 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 +2 -254
- 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 +6 -5
- package/crates/team-agent/src/lifecycle/tests/worker_spawn_env_red.rs +7 -153
- package/crates/team-agent/src/lifecycle/tests.rs +0 -6
- package/crates/team-agent/src/lifecycle/types.rs +2 -18
- package/crates/team-agent/src/lifecycle/worker_command_context.rs +2 -4
- package/crates/team-agent/src/mcp_server/readiness.rs +148 -97
- package/crates/team-agent/src/mcp_server/readiness_tests.rs +115 -16
- package/crates/team-agent/src/messaging/delivery.rs +185 -168
- package/crates/team-agent/src/messaging/delivery_consumption_tests.rs +5 -5
- package/crates/team-agent/src/messaging/enter_rescue_tests.rs +1 -1
- package/crates/team-agent/src/messaging/helpers.rs +19 -0
- package/crates/team-agent/src/messaging/tests/dup_inject.rs +67 -5
- package/crates/team-agent/src/messaging/tests/runtime.rs +110 -4
- package/crates/team-agent/src/messaging/tests/spine.rs +46 -36
- package/crates/team-agent/src/model/enums.rs +1 -8
- package/crates/team-agent/src/provider/adapter.rs +33 -302
- package/crates/team-agent/src/provider/adapters/mod.rs +4 -5
- package/crates/team-agent/src/provider/argv_route.rs +1 -5
- package/crates/team-agent/src/provider/bypass_flags.rs +3 -11
- package/crates/team-agent/src/provider/classify.rs +68 -3
- package/crates/team-agent/src/provider/faults.rs +1 -1
- package/crates/team-agent/src/provider/model_catalog.rs +14 -273
- package/crates/team-agent/src/provider/session/capture.rs +7 -107
- package/crates/team-agent/src/provider/session/context_fork/outcome.rs +0 -4
- package/crates/team-agent/src/provider/session/context_fork.rs +17 -109
- package/crates/team-agent/src/provider/session_scan/common.rs +11 -36
- package/crates/team-agent/src/provider/session_scan/pi.rs +1 -34
- package/crates/team-agent/src/provider/session_scan.rs +4 -14
- package/crates/team-agent/src/provider/submit_now.rs +5 -28
- package/crates/team-agent/src/provider/tests/adapter.rs +39 -275
- package/crates/team-agent/src/provider/tests/classify.rs +53 -0
- package/crates/team-agent/src/provider/tests/command_helpers.rs +3 -15
- package/crates/team-agent/src/provider/tests/idle.rs +0 -25
- package/crates/team-agent/src/provider/types.rs +1 -1
- package/crates/team-agent/src/provider/wire.rs +79 -11
- 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/repository/tests.rs +2 -2
- package/crates/team-agent/src/tmux_backend/native_input_tests.rs +2 -178
- package/crates/team-agent/src/tmux_backend/tests.rs +151 -0
- package/crates/team-agent/src/tmux_backend.rs +43 -8
- package/crates/team-agent/src/transport/native_input.rs +2 -231
- package/package.json +4 -4
- package/skills/team-agent/SKILL.md +7 -5
- 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/cursor_create_chat.rs +0 -229
- package/crates/team-agent/src/lifecycle/launch/cursor_mcp.rs +0 -522
- package/crates/team-agent/src/lifecycle/launch/cursor_mcp_iso.rs +0 -282
- package/crates/team-agent/src/lifecycle/restart/avatar.rs +0 -1805
- package/crates/team-agent/src/lifecycle/tests/claude_compatible_config_red.rs +0 -325
- package/crates/team-agent/src/lifecycle/tests/cursor_mcp_overlay.rs +0 -576
- package/crates/team-agent/src/lifecycle/tests/cursor_require_explicit_model_red.rs +0 -222
- package/crates/team-agent/src/lifecycle/tests/cursor_restart_resume_red.rs +0 -511
- package/crates/team-agent/src/lifecycle/tests/pi_compiler_red.rs +0 -210
- package/crates/team-agent/src/lifecycle/tests/pi_fork_session_inheritance_red.rs +0 -1409
- package/crates/team-agent/src/provider/adapters/claude.rs +0 -78
- package/crates/team-agent/src/provider/adapters/claude_fork.rs +0 -131
- package/crates/team-agent/src/provider/adapters/cursor_agent.rs +0 -44
- package/crates/team-agent/src/provider/adapters/pi.rs +0 -100
- package/crates/team-agent/src/provider/session/context_fork/claude.rs +0 -123
- package/crates/team-agent/src/provider/session_scan/claude.rs +0 -523
- package/crates/team-agent/src/provider/session_scan/cursor.rs +0 -538
- package/crates/team-agent/src/provider/testdata/cursor-list-models-native.stdout +0 -250
- package/crates/team-agent/src/test_support/models_timeout_fixture.rs +0 -144
|
@@ -50,7 +50,7 @@ use super::*;
|
|
|
50
50
|
/// pre-write JSON (so the half-written `status:starting` row is gone). The
|
|
51
51
|
/// caller propagates the ORIGINAL operation error after rollback; rollback
|
|
52
52
|
/// errors are swallowed (best-effort, no panic).
|
|
53
|
-
pub(
|
|
53
|
+
pub(crate) fn rollback_add_agent_atomic(
|
|
54
54
|
run_workspace: &Path,
|
|
55
55
|
spec_path: &Path,
|
|
56
56
|
pre_spec_text: Option<&str>,
|
|
@@ -156,6 +156,20 @@ pub(super) fn upsert_agent_state_from_role(
|
|
|
156
156
|
agent_id: &AgentId,
|
|
157
157
|
meta: &Value,
|
|
158
158
|
dynamic_role_file: &Path,
|
|
159
|
+
) -> Result<(), LifecycleError> {
|
|
160
|
+
let entry = starting_agent_entry(workspace, agent_id, meta, dynamic_role_file);
|
|
161
|
+
upsert_agent_entry(workspace, canonical_team_key, agent_id, entry)
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/// ---
|
|
165
|
+
/// purpose: 把一席的 starting 行写进团队 state 并落盘
|
|
166
|
+
/// errors: 读或写 runtime state 失败时返回 StatePersist
|
|
167
|
+
/// ---
|
|
168
|
+
pub(crate) fn upsert_agent_entry(
|
|
169
|
+
workspace: &Path,
|
|
170
|
+
canonical_team_key: &str,
|
|
171
|
+
agent_id: &AgentId,
|
|
172
|
+
entry: serde_json::Value,
|
|
159
173
|
) -> Result<(), LifecycleError> {
|
|
160
174
|
let mut state =
|
|
161
175
|
crate::state::projection::select_runtime_state(workspace, Some(canonical_team_key))
|
|
@@ -179,7 +193,6 @@ pub(super) fn upsert_agent_state_from_role(
|
|
|
179
193
|
"runtime state agents is not an object".to_string(),
|
|
180
194
|
));
|
|
181
195
|
};
|
|
182
|
-
let entry = starting_agent_entry(workspace, agent_id, meta, dynamic_role_file);
|
|
183
196
|
agent_map.insert(agent_id.as_str().to_string(), entry);
|
|
184
197
|
crate::lifecycle::restart::remove::clear_agent_retirement_in_state(&mut state, agent_id);
|
|
185
198
|
save_launched_team_state_for_key(
|
|
@@ -190,199 +203,6 @@ pub(super) fn upsert_agent_state_from_role(
|
|
|
190
203
|
)
|
|
191
204
|
}
|
|
192
205
|
|
|
193
|
-
/// ---
|
|
194
|
-
/// purpose: 首次登记 Pi fork 席位,原子带入目标角色与完整 fork capture seed
|
|
195
|
-
/// returns: 成功后 TARGET 已按 ForkAgent typed intent 登记为 starting
|
|
196
|
-
/// errors: 重复席位、无效 capture seed 或 state 写入失败时拒绝
|
|
197
|
-
/// ---
|
|
198
|
-
pub(crate) fn fork_upsert_agent_state_from_role(
|
|
199
|
-
workspace: &Path,
|
|
200
|
-
canonical_team_key: &str,
|
|
201
|
-
agent_id: &AgentId,
|
|
202
|
-
meta: &Value,
|
|
203
|
-
compiled_agent: &Value,
|
|
204
|
-
dynamic_role_file: &Path,
|
|
205
|
-
seed: &ForkCaptureSeed,
|
|
206
|
-
) -> Result<(), LifecycleError> {
|
|
207
|
-
if agent_id == &seed.source_agent_id {
|
|
208
|
-
return Err(LifecycleError::RequirementUnmet(
|
|
209
|
-
"fork target must differ from source".to_string(),
|
|
210
|
-
));
|
|
211
|
-
}
|
|
212
|
-
if seed.captured.captured_via != crate::provider::CaptureVia::ForkSnapshot
|
|
213
|
-
|| seed.captured.attribution_confidence != crate::provider::Confidence::High
|
|
214
|
-
|| seed.captured.session_id.is_none()
|
|
215
|
-
|| seed.captured.rollout_path.is_none()
|
|
216
|
-
|| seed.captured_at.is_empty()
|
|
217
|
-
{
|
|
218
|
-
return Err(LifecycleError::RequirementUnmet(
|
|
219
|
-
"fork capture seed is incomplete or not a verified Pi snapshot".to_string(),
|
|
220
|
-
));
|
|
221
|
-
}
|
|
222
|
-
if compiled_agent.get("id").and_then(Value::as_str) != Some(agent_id.as_str()) {
|
|
223
|
-
return Err(LifecycleError::Compile(
|
|
224
|
-
"compiled fork role id does not match target".to_string(),
|
|
225
|
-
));
|
|
226
|
-
}
|
|
227
|
-
let sessions_root = std::fs::canonicalize(&seed.pi_sessions_root)
|
|
228
|
-
.map_err(|e| LifecycleError::StatePersist(e.to_string()))?;
|
|
229
|
-
let backing = seed.captured.rollout_path.as_ref().ok_or_else(|| {
|
|
230
|
-
LifecycleError::RequirementUnmet("fork backing path is missing".to_string())
|
|
231
|
-
})?;
|
|
232
|
-
let backing_path = std::fs::canonicalize(&backing.0)
|
|
233
|
-
.map_err(|e| LifecycleError::StatePersist(e.to_string()))?;
|
|
234
|
-
if !backing_path.starts_with(&sessions_root) {
|
|
235
|
-
return Err(LifecycleError::RequirementUnmet(
|
|
236
|
-
"fork backing is outside the target Pi session root".to_string(),
|
|
237
|
-
));
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
let mut state =
|
|
241
|
-
crate::state::projection::select_runtime_state(workspace, Some(canonical_team_key))
|
|
242
|
-
.map_err(|e| LifecycleError::TeamSelect(e.to_string()))?;
|
|
243
|
-
if !state.is_object() {
|
|
244
|
-
state = serde_json::json!({});
|
|
245
|
-
}
|
|
246
|
-
let root = state.as_object_mut().ok_or_else(|| {
|
|
247
|
-
LifecycleError::StatePersist("runtime state root is not an object".to_string())
|
|
248
|
-
})?;
|
|
249
|
-
let agents = root
|
|
250
|
-
.entry("agents".to_string())
|
|
251
|
-
.or_insert_with(|| serde_json::json!({}));
|
|
252
|
-
if !agents.is_object() {
|
|
253
|
-
*agents = serde_json::json!({});
|
|
254
|
-
}
|
|
255
|
-
let agent_map = agents.as_object_mut().ok_or_else(|| {
|
|
256
|
-
LifecycleError::StatePersist("runtime state agents is not an object".to_string())
|
|
257
|
-
})?;
|
|
258
|
-
if agent_map.contains_key(agent_id.as_str()) {
|
|
259
|
-
return Err(LifecycleError::RequirementUnmet(format!(
|
|
260
|
-
"agent id already exists in selected team: {}",
|
|
261
|
-
agent_id
|
|
262
|
-
)));
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
let source_profile_dir = agent_map
|
|
266
|
-
.get(seed.source_agent_id.as_str())
|
|
267
|
-
.and_then(serde_json::Value::as_object)
|
|
268
|
-
.and_then(|source| source.get("_profile_dir"))
|
|
269
|
-
.and_then(serde_json::Value::as_str)
|
|
270
|
-
.filter(|path| !path.is_empty())
|
|
271
|
-
.map(|path| serde_json::json!(path));
|
|
272
|
-
let mut entry = starting_agent_entry(workspace, agent_id, meta, dynamic_role_file);
|
|
273
|
-
let entry_object = entry.as_object_mut().ok_or_else(|| {
|
|
274
|
-
LifecycleError::StatePersist("fork target entry is not an object".to_string())
|
|
275
|
-
})?;
|
|
276
|
-
for field in [
|
|
277
|
-
"provider",
|
|
278
|
-
"auth_mode",
|
|
279
|
-
"role",
|
|
280
|
-
"model",
|
|
281
|
-
"effort",
|
|
282
|
-
"profile",
|
|
283
|
-
"tools",
|
|
284
|
-
"system_prompt",
|
|
285
|
-
"output_contract",
|
|
286
|
-
"communication_mode",
|
|
287
|
-
"working_directory",
|
|
288
|
-
"cwd",
|
|
289
|
-
"config",
|
|
290
|
-
"name",
|
|
291
|
-
"dangerously_skip_permissions",
|
|
292
|
-
] {
|
|
293
|
-
if let Some(value) = compiled_agent.get(field) {
|
|
294
|
-
entry_object.insert(field.to_string(), yaml_value_to_json(value));
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
if compiled_agent.get("model").is_some() && !entry_object.contains_key("model_source") {
|
|
298
|
-
entry_object.insert("model_source".to_string(), serde_json::json!("team"));
|
|
299
|
-
}
|
|
300
|
-
entry_object.insert("agent_id".to_string(), serde_json::json!(agent_id.as_str()));
|
|
301
|
-
entry_object.insert("label".to_string(), serde_json::json!(agent_id.as_str()));
|
|
302
|
-
entry_object.insert(
|
|
303
|
-
"owner_team_id".to_string(),
|
|
304
|
-
serde_json::json!(canonical_team_key),
|
|
305
|
-
);
|
|
306
|
-
entry_object.insert(
|
|
307
|
-
"claude_projects_root".to_string(),
|
|
308
|
-
serde_json::json!(sessions_root.to_string_lossy().to_string()),
|
|
309
|
-
);
|
|
310
|
-
entry_object.insert(
|
|
311
|
-
"forked_from".to_string(),
|
|
312
|
-
serde_json::json!(seed.source_agent_id.as_str()),
|
|
313
|
-
);
|
|
314
|
-
entry_object.insert(
|
|
315
|
-
"spawn_cwd".to_string(),
|
|
316
|
-
serde_json::json!(seed.captured.spawn_cwd.to_string_lossy().to_string()),
|
|
317
|
-
);
|
|
318
|
-
entry_object.insert(
|
|
319
|
-
"session_id".to_string(),
|
|
320
|
-
serde_json::json!(seed.captured.session_id.as_ref().map(|id| id.as_str())),
|
|
321
|
-
);
|
|
322
|
-
let backing = seed.captured.rollout_path.as_ref().ok_or_else(|| {
|
|
323
|
-
LifecycleError::RequirementUnmet("fork backing path is missing".to_string())
|
|
324
|
-
})?;
|
|
325
|
-
entry_object.insert(
|
|
326
|
-
"rollout_path".to_string(),
|
|
327
|
-
serde_json::json!(backing.0.to_string_lossy().to_string()),
|
|
328
|
-
);
|
|
329
|
-
entry_object.insert(
|
|
330
|
-
"captured_at".to_string(),
|
|
331
|
-
serde_json::json!(seed.captured_at.as_str()),
|
|
332
|
-
);
|
|
333
|
-
entry_object.insert(
|
|
334
|
-
"captured_via".to_string(),
|
|
335
|
-
serde_json::to_value(seed.captured.captured_via)
|
|
336
|
-
.map_err(|e| LifecycleError::StatePersist(e.to_string()))?,
|
|
337
|
-
);
|
|
338
|
-
entry_object.insert(
|
|
339
|
-
"attribution_confidence".to_string(),
|
|
340
|
-
serde_json::to_value(seed.captured.attribution_confidence)
|
|
341
|
-
.map_err(|e| LifecycleError::StatePersist(e.to_string()))?,
|
|
342
|
-
);
|
|
343
|
-
entry_object.insert("capture_state".to_string(), serde_json::json!("captured"));
|
|
344
|
-
if let Some(profile_dir) = source_profile_dir {
|
|
345
|
-
entry_object.insert("_profile_dir".to_string(), profile_dir);
|
|
346
|
-
} else {
|
|
347
|
-
entry_object.insert(
|
|
348
|
-
"_profile_dir".to_string(),
|
|
349
|
-
serde_json::json!(seed.profile_dir.to_string_lossy().to_string()),
|
|
350
|
-
);
|
|
351
|
-
}
|
|
352
|
-
agent_map.insert(agent_id.as_str().to_string(), entry);
|
|
353
|
-
crate::lifecycle::restart::remove::clear_agent_retirement_in_state(&mut state, agent_id);
|
|
354
|
-
crate::state::repository::StateRepository::new(workspace)
|
|
355
|
-
.save(
|
|
356
|
-
crate::state::repository::StateWriteIntent::ForkAgent {
|
|
357
|
-
team_key: canonical_team_key,
|
|
358
|
-
agent_id: agent_id.as_str(),
|
|
359
|
-
},
|
|
360
|
-
&state,
|
|
361
|
-
)
|
|
362
|
-
.map_err(|e| LifecycleError::StatePersist(e.to_string()))
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
fn yaml_value_to_json(value: &Value) -> serde_json::Value {
|
|
366
|
-
match value {
|
|
367
|
-
Value::Null => serde_json::Value::Null,
|
|
368
|
-
Value::Bool(value) => serde_json::json!(value),
|
|
369
|
-
Value::Int(value) => serde_json::json!(value),
|
|
370
|
-
Value::Float(value) => serde_json::Number::from_f64(*value)
|
|
371
|
-
.map(serde_json::Value::Number)
|
|
372
|
-
.unwrap_or(serde_json::Value::Null),
|
|
373
|
-
Value::Str(value) => serde_json::json!(value),
|
|
374
|
-
Value::List(values) => {
|
|
375
|
-
serde_json::Value::Array(values.iter().map(yaml_value_to_json).collect())
|
|
376
|
-
}
|
|
377
|
-
Value::Map(values) => serde_json::Value::Object(
|
|
378
|
-
values
|
|
379
|
-
.iter()
|
|
380
|
-
.map(|(key, value)| (key.clone(), yaml_value_to_json(value)))
|
|
381
|
-
.collect(),
|
|
382
|
-
),
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
|
|
386
206
|
fn starting_agent_entry(
|
|
387
207
|
workspace: &Path,
|
|
388
208
|
agent_id: &AgentId,
|
|
@@ -129,14 +129,6 @@ pub(super) fn running_agent_state(
|
|
|
129
129
|
if let Some(started_agent) = started_agent {
|
|
130
130
|
persist_started_agent_plan_state(&mut state, started_agent);
|
|
131
131
|
}
|
|
132
|
-
// Cursor chdirs to its native --workspace primary. Session archives are
|
|
133
|
-
// keyed by this directory, not the real project supplied via --add-dir.
|
|
134
|
-
let cursor_cwd = if provider == Provider::CursorAgent && cursor_mcp_isolation_enabled() {
|
|
135
|
-
Some(cursor_mcp_project_dir(workspace, id)?)
|
|
136
|
-
} else {
|
|
137
|
-
None
|
|
138
|
-
};
|
|
139
|
-
let spawn_cwd = cursor_cwd.as_deref().unwrap_or(spawn_cwd);
|
|
140
132
|
state.insert(
|
|
141
133
|
"spawn_cwd".to_string(),
|
|
142
134
|
serde_json::json!(spawn_cwd.to_string_lossy().to_string()),
|
|
@@ -240,7 +232,6 @@ fn provider_wire_str(provider: Provider) -> &'static str {
|
|
|
240
232
|
Provider::Copilot => "copilot",
|
|
241
233
|
Provider::GeminiCli => "gemini_cli",
|
|
242
234
|
Provider::Grok => "grok",
|
|
243
|
-
Provider::CursorAgent => "cursor_agent",
|
|
244
235
|
Provider::Pi => "pi",
|
|
245
236
|
Provider::Fake => "fake",
|
|
246
237
|
}
|
|
@@ -47,6 +47,16 @@ pub fn clone_agent(
|
|
|
47
47
|
.ok_or_else(|| {
|
|
48
48
|
LifecycleError::RequirementUnmet(format!("unknown worker agent id: {source_agent_id}"))
|
|
49
49
|
})?;
|
|
50
|
+
// A pre-upgrade Claude Code or Pi row has no legacy runtime to clone onto.
|
|
51
|
+
if let Some(retired) = source_agent
|
|
52
|
+
.get("provider")
|
|
53
|
+
.and_then(serde_json::Value::as_str)
|
|
54
|
+
.filter(|provider| crate::provider::wire::is_retired_provider(provider))
|
|
55
|
+
{
|
|
56
|
+
return Err(LifecycleError::Provider(
|
|
57
|
+
crate::provider::wire::retired_provider_error(retired).into(),
|
|
58
|
+
));
|
|
59
|
+
}
|
|
50
60
|
let source_session_id = source_agent
|
|
51
61
|
.get("session_id")
|
|
52
62
|
.and_then(serde_json::Value::as_str)
|
|
@@ -122,37 +132,11 @@ fn read_agent_session(
|
|
|
122
132
|
.get("rollout_path")
|
|
123
133
|
.and_then(serde_json::Value::as_str)
|
|
124
134
|
.filter(|value| !value.is_empty())
|
|
125
|
-
.map(std::path::PathBuf::from)
|
|
126
|
-
.or_else(|| find_claude_backing(agent, session))?;
|
|
135
|
+
.map(std::path::PathBuf::from)?;
|
|
127
136
|
let distinct = source_session_id.is_none_or(|source| source.as_str() != session);
|
|
128
137
|
(distinct && backing.is_file()).then(|| (SessionId::new(session), backing))
|
|
129
138
|
}
|
|
130
139
|
|
|
131
|
-
fn find_claude_backing(agent: &serde_json::Value, session: &str) -> Option<std::path::PathBuf> {
|
|
132
|
-
let root = agent
|
|
133
|
-
.get("claude_projects_root")
|
|
134
|
-
.and_then(serde_json::Value::as_str)
|
|
135
|
-
.map(std::path::PathBuf::from)
|
|
136
|
-
.or_else(|| {
|
|
137
|
-
std::env::var_os("HOME")
|
|
138
|
-
.map(|home| std::path::PathBuf::from(home).join(".claude/projects"))
|
|
139
|
-
})?;
|
|
140
|
-
let target = format!("{session}.jsonl");
|
|
141
|
-
let mut pending = vec![root];
|
|
142
|
-
while let Some(dir) = pending.pop() {
|
|
143
|
-
let entries = std::fs::read_dir(&dir).ok()?;
|
|
144
|
-
for entry in entries.flatten() {
|
|
145
|
-
let path = entry.path();
|
|
146
|
-
if path.is_dir() {
|
|
147
|
-
pending.push(path);
|
|
148
|
-
} else if path.file_name().and_then(|name| name.to_str()) == Some(target.as_str()) {
|
|
149
|
-
return Some(path);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
None
|
|
154
|
-
}
|
|
155
|
-
|
|
156
140
|
fn persist_clone_session(
|
|
157
141
|
workspace: &Path,
|
|
158
142
|
team_key: &str,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
//! ---
|
|
2
|
-
//! purpose: Pi
|
|
2
|
+
//! purpose: legacy 席位的窗口内分身(Grok);Claude Code / Pi 席位只走 contract 管道的原生新席位 fork
|
|
3
3
|
//! contract:
|
|
4
4
|
//! provides:
|
|
5
5
|
//! - name: fork_agent_with_transport
|
|
6
|
-
//! what:
|
|
6
|
+
//! what: Grok 走窗口内斜杠 fork;升级前遗留的 claude/pi worker 行明确拒绝
|
|
7
7
|
//! - name: in_window_fork
|
|
8
8
|
//! what: 已验证的 provider+subscription 给出 command+screen_mark;未验证返回 None
|
|
9
9
|
//! depends:
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
//! - crate::lifecycle::profile_launch
|
|
13
13
|
//! - crate::transport::Transport
|
|
14
14
|
//! boundary:
|
|
15
|
-
//! -
|
|
16
|
-
//! -
|
|
15
|
+
//! - 新席位 fork 只由 contract_runtime::fork 管道完成,这里不注册新席位
|
|
16
|
+
//! - 窗口内分身不 spawn 新 pane,不改 TEAM_AGENT_ID / MCP / 席位名
|
|
17
17
|
//! - 重试只重按回车,不重粘 /fork
|
|
18
18
|
//! - 不把 pane 锁超时从 200ms 调大
|
|
19
19
|
//! - 未验证的 provider 不猜斜杠命令
|
|
@@ -43,18 +43,16 @@ pub struct InWindowFork {
|
|
|
43
43
|
/// ---
|
|
44
44
|
/// Official in-window fork. None = unverified or unsupported-auth.
|
|
45
45
|
/// grok `/fork` mark `forked from` (2026-08-17).
|
|
46
|
-
///
|
|
47
|
-
///
|
|
46
|
+
/// Claude's `/branch` is retired here: it moves the SOURCE process onto the
|
|
47
|
+
/// branch (renamed "<title> (Branch)") while the seat's captured tuple still
|
|
48
|
+
/// names the old session, and creates no seat. Claude Code and Pi fork only
|
|
49
|
+
/// into a new seat through the contract pipeline (`contract_runtime::fork`).
|
|
48
50
|
pub fn in_window_fork(provider: Provider, auth: AuthMode) -> Option<InWindowFork> {
|
|
49
51
|
match (provider, auth) {
|
|
50
52
|
(Provider::Grok, AuthMode::Subscription) => Some(InWindowFork {
|
|
51
53
|
command: "/fork",
|
|
52
54
|
screen_mark: "forked from",
|
|
53
55
|
}),
|
|
54
|
-
(Provider::Claude | Provider::ClaudeCode, AuthMode::Subscription) => Some(InWindowFork {
|
|
55
|
-
command: "/branch",
|
|
56
|
-
screen_mark: "Branched conversation",
|
|
57
|
-
}),
|
|
58
56
|
_ => None,
|
|
59
57
|
}
|
|
60
58
|
}
|
|
@@ -68,14 +66,7 @@ pub fn in_window_fork_command(provider: Provider, auth: AuthMode) -> Option<&'st
|
|
|
68
66
|
}
|
|
69
67
|
|
|
70
68
|
fn refuse_missing_in_window_fork(provider: Provider, provider_raw: &str) -> LifecycleError {
|
|
71
|
-
if matches!(
|
|
72
|
-
provider,
|
|
73
|
-
Provider::Grok
|
|
74
|
-
| Provider::Claude
|
|
75
|
-
| Provider::ClaudeCode
|
|
76
|
-
| Provider::CursorAgent
|
|
77
|
-
| Provider::Pi
|
|
78
|
-
) {
|
|
69
|
+
if matches!(provider, Provider::Grok | Provider::Pi) {
|
|
79
70
|
LifecycleError::Provider(format!(
|
|
80
71
|
"{provider_raw} does not support native session fork"
|
|
81
72
|
))
|
|
@@ -100,7 +91,7 @@ pub fn fork_agent_with_transport(
|
|
|
100
91
|
source_agent_id: &AgentId,
|
|
101
92
|
as_agent_id: &AgentId,
|
|
102
93
|
label: Option<&str>,
|
|
103
|
-
|
|
94
|
+
open_display: bool,
|
|
104
95
|
team: Option<&str>,
|
|
105
96
|
transport: &dyn Transport,
|
|
106
97
|
) -> Result<ForkAgentReport, LifecycleError> {
|
|
@@ -140,17 +131,16 @@ pub fn fork_agent_with_transport(
|
|
|
140
131
|
.get("auth_mode")
|
|
141
132
|
.and_then(serde_json::Value::as_str)
|
|
142
133
|
.unwrap_or("subscription");
|
|
134
|
+
// A pre-upgrade Claude Code or Pi row has no legacy runtime to fork from;
|
|
135
|
+
// contract seats fork through the contract pipeline before this point.
|
|
136
|
+
if crate::provider::wire::is_retired_provider(provider_raw) {
|
|
137
|
+
return Err(LifecycleError::Provider(
|
|
138
|
+
crate::provider::wire::retired_provider_error(provider_raw).into(),
|
|
139
|
+
));
|
|
140
|
+
}
|
|
141
|
+
let _ = (label, open_display);
|
|
143
142
|
let provider = parse_provider(provider_raw).unwrap_or(Provider::Grok);
|
|
144
143
|
let auth = parse_auth_mode(auth_raw).unwrap_or(AuthMode::Subscription);
|
|
145
|
-
if provider == Provider::Pi {
|
|
146
|
-
return crate::lifecycle::restart::fork_pi_new_seat_locked(
|
|
147
|
-
&selected,
|
|
148
|
-
source_agent_id,
|
|
149
|
-
as_agent_id,
|
|
150
|
-
label,
|
|
151
|
-
transport,
|
|
152
|
-
);
|
|
153
|
-
}
|
|
154
144
|
let Some(spec) = in_window_fork(provider, auth) else {
|
|
155
145
|
return Err(refuse_missing_in_window_fork(provider, provider_raw));
|
|
156
146
|
};
|
|
@@ -210,7 +200,6 @@ pub fn fork_agent_with_transport(
|
|
|
210
200
|
},
|
|
211
201
|
session_id: None,
|
|
212
202
|
backing_state: ForkBackingState::Verified,
|
|
213
|
-
pi_fork: None,
|
|
214
203
|
})
|
|
215
204
|
}
|
|
216
205
|
|
|
@@ -44,39 +44,13 @@ pub fn fork_agent(
|
|
|
44
44
|
.map_err(|e| LifecycleError::TeamSelect(e.to_string()))?;
|
|
45
45
|
// Fork-agent routes to the selected live team's persisted endpoint, not
|
|
46
46
|
// the workspace-hash fallback socket.
|
|
47
|
-
let
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
.and_then(|agent| agent.get("provider"))
|
|
52
|
-
.and_then(serde_json::Value::as_str)
|
|
53
|
-
== Some("pi");
|
|
54
|
-
let transport: Box<dyn crate::transport::Transport> = if is_pi {
|
|
55
|
-
#[cfg(test)]
|
|
56
|
-
{
|
|
57
|
-
test_fork_transport(&selected, source_agent_id)
|
|
58
|
-
}
|
|
59
|
-
#[cfg(not(test))]
|
|
60
|
-
{
|
|
61
|
-
Box::new(
|
|
62
|
-
crate::lifecycle::restart::lifecycle_worker_tmux_backend_selection_for_state(
|
|
63
|
-
&selected.run_workspace,
|
|
64
|
-
&selected.state,
|
|
65
|
-
)?
|
|
66
|
-
.backend,
|
|
67
|
-
)
|
|
68
|
-
}
|
|
69
|
-
} else {
|
|
70
|
-
Box::new(
|
|
71
|
-
crate::lifecycle::restart::lifecycle_worker_tmux_backend_for_selected_state(
|
|
72
|
-
&selected.run_workspace,
|
|
73
|
-
Some(selected.team_key.as_str()),
|
|
74
|
-
)
|
|
75
|
-
.unwrap_or_else(|_| {
|
|
76
|
-
crate::tmux_backend::TmuxBackend::for_workspace(&selected.run_workspace)
|
|
77
|
-
}),
|
|
47
|
+
let transport: Box<dyn crate::transport::Transport> = Box::new(
|
|
48
|
+
crate::lifecycle::restart::lifecycle_worker_tmux_backend_for_selected_state(
|
|
49
|
+
&selected.run_workspace,
|
|
50
|
+
Some(selected.team_key.as_str()),
|
|
78
51
|
)
|
|
79
|
-
|
|
52
|
+
.unwrap_or_else(|_| crate::tmux_backend::TmuxBackend::for_workspace(&selected.run_workspace)),
|
|
53
|
+
);
|
|
80
54
|
fork_agent_with_transport(
|
|
81
55
|
workspace,
|
|
82
56
|
source_agent_id,
|
|
@@ -87,58 +61,3 @@ pub fn fork_agent(
|
|
|
87
61
|
transport.as_ref(),
|
|
88
62
|
)
|
|
89
63
|
}
|
|
90
|
-
|
|
91
|
-
#[cfg(test)]
|
|
92
|
-
fn test_fork_transport(
|
|
93
|
-
selected: &crate::state::selector::SelectedTeam,
|
|
94
|
-
source_agent_id: &AgentId,
|
|
95
|
-
) -> Box<dyn crate::transport::Transport> {
|
|
96
|
-
let state = &selected.state;
|
|
97
|
-
let session = state
|
|
98
|
-
.get("session_name")
|
|
99
|
-
.and_then(serde_json::Value::as_str)
|
|
100
|
-
.filter(|value| !value.is_empty())
|
|
101
|
-
.map(crate::transport::SessionName::new)
|
|
102
|
-
.unwrap_or_else(|| crate::transport::SessionName::new("offline"));
|
|
103
|
-
let source = state
|
|
104
|
-
.get("agents")
|
|
105
|
-
.and_then(|agents| agents.get(source_agent_id.as_str()));
|
|
106
|
-
let targets = source
|
|
107
|
-
.and_then(|agent| agent.get("pane_id"))
|
|
108
|
-
.and_then(serde_json::Value::as_str)
|
|
109
|
-
.filter(|pane| !pane.is_empty())
|
|
110
|
-
.map(|pane| {
|
|
111
|
-
let window = source
|
|
112
|
-
.and_then(|agent| agent.get("window"))
|
|
113
|
-
.and_then(serde_json::Value::as_str)
|
|
114
|
-
.filter(|value| !value.is_empty())
|
|
115
|
-
.unwrap_or(source_agent_id.as_str());
|
|
116
|
-
vec![crate::transport::PaneInfo {
|
|
117
|
-
pane_id: crate::transport::PaneId::new(pane),
|
|
118
|
-
session: session.clone(),
|
|
119
|
-
window_index: None,
|
|
120
|
-
window_name: Some(crate::transport::WindowName::new(window)),
|
|
121
|
-
pane_index: None,
|
|
122
|
-
tty: None,
|
|
123
|
-
current_command: None,
|
|
124
|
-
current_path: None,
|
|
125
|
-
active: false,
|
|
126
|
-
pane_pid: None,
|
|
127
|
-
leader_env: std::collections::BTreeMap::new(),
|
|
128
|
-
}]
|
|
129
|
-
})
|
|
130
|
-
.unwrap_or_default();
|
|
131
|
-
let endpoint = state
|
|
132
|
-
.get("tmux_endpoint")
|
|
133
|
-
.or_else(|| state.get("tmux_socket"))
|
|
134
|
-
.and_then(serde_json::Value::as_str)
|
|
135
|
-
.filter(|value| !value.is_empty())
|
|
136
|
-
.map(str::to_string)
|
|
137
|
-
.unwrap_or_else(|| "offline".to_string());
|
|
138
|
-
Box::new(
|
|
139
|
-
crate::transport::test_support::OfflineTransport::new()
|
|
140
|
-
.with_session_present(true)
|
|
141
|
-
.with_targets(targets)
|
|
142
|
-
.with_tmux_endpoint(endpoint),
|
|
143
|
-
)
|
|
144
|
-
}
|
|
@@ -472,8 +472,8 @@ fn grok_trusted_folders(text: &str) -> Vec<PathBuf> {
|
|
|
472
472
|
/// returns: 成功返回空值;写前先清 per-seat 键,已有表里的未知环境键会被保留
|
|
473
473
|
/// errors: 缺条目或缺 command 时返回 StatePersist,清洗失败透传 RequirementUnmet,写文件失败返回 StatePersist
|
|
474
474
|
/// ---
|
|
475
|
-
/// Grok CLI 没有 `--mcp-config
|
|
476
|
-
///
|
|
475
|
+
/// Grok CLI 没有 `--mcp-config`。launch 路径写一份 provider 实际会读的文件。
|
|
476
|
+
/// Grok 只认项目作用域
|
|
477
477
|
/// `<cwd>/.grok/config.toml`(`grok mcp add --scope project` 的产物)。
|
|
478
478
|
///
|
|
479
479
|
/// Unique writer of `<cwd>/.grok/config.toml`. Reconcile leftover per-seat
|
|
@@ -610,7 +610,7 @@ fn upsert_toml_table_prefixes(existing: &str, tables: &[&str], stanza: &str) ->
|
|
|
610
610
|
/// ---
|
|
611
611
|
/// purpose: 把 argv 里 provider 原生的 MCP 配置参数改指到已落盘的文件
|
|
612
612
|
/// params:
|
|
613
|
-
/// argv: 就地改写;
|
|
613
|
+
/// argv: 就地改写;copilot 改 --additional-mcp-config 并加 @ 前缀
|
|
614
614
|
/// returns: argv 里没有对应参数时什么都不做
|
|
615
615
|
/// ---
|
|
616
616
|
pub(crate) fn point_native_mcp_config_at_file(
|
|
@@ -619,14 +619,6 @@ pub(crate) fn point_native_mcp_config_at_file(
|
|
|
619
619
|
path: &Path,
|
|
620
620
|
) {
|
|
621
621
|
match provider {
|
|
622
|
-
Provider::Claude | Provider::ClaudeCode => {
|
|
623
|
-
let Some(index) = argv.iter().position(|arg| arg == "--mcp-config") else {
|
|
624
|
-
return;
|
|
625
|
-
};
|
|
626
|
-
if let Some(value) = argv.get_mut(index.saturating_add(1)) {
|
|
627
|
-
*value = path.to_string_lossy().to_string();
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
622
|
// §C1 note: copilot `--additional-mcp-config` 接受 `@file`,直接指向既有
|
|
631
623
|
// `.team/runtime/mcp/<agent>.json`(launch 路径 write_worker_mcp_config 已写)。
|
|
632
624
|
// 既避免 inline JSON 包 mcpServers wrapper 的语义错位,也更利于 ps 验法。
|