@team-agent/installer 0.5.126 → 0.5.128
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Cargo.lock +1 -1
- package/Cargo.toml +1 -1
- package/README.md +11 -0
- package/crates/team-agent/src/cli/adapters.rs +3 -13
- package/crates/team-agent/src/cli/arguments.rs +4 -0
- package/crates/team-agent/src/cli/diagnose.rs +68 -91
- package/crates/team-agent/src/cli/emit.rs +61 -28
- package/crates/team-agent/src/cli/grok_slot.rs +88 -3
- package/crates/team-agent/src/cli/intent/runtime.rs +38 -9
- package/crates/team-agent/src/cli/intent/runtime_tests.rs +147 -11
- package/crates/team-agent/src/cli/intent/tests.rs +10 -12
- package/crates/team-agent/src/cli/intent.rs +1 -1
- package/crates/team-agent/src/cli/mod.rs +38 -9
- package/crates/team-agent/src/cli/models.rs +789 -186
- package/crates/team-agent/src/cli/schedule.rs +175 -0
- package/crates/team-agent/src/cli/send/persist.rs +0 -36
- package/crates/team-agent/src/cli/send/presentation.rs +1 -1
- package/crates/team-agent/src/cli/send.rs +108 -110
- package/crates/team-agent/src/cli/spec.rs +6 -0
- package/crates/team-agent/src/cli/status_port/brief.rs +5 -67
- package/crates/team-agent/src/cli/tests/leader_watch.rs +12 -62
- package/crates/team-agent/src/cli/tests/mod.rs +3 -3
- package/crates/team-agent/src/cli/tests/named_address.rs +11 -10
- package/crates/team-agent/src/cli/tests/run_delegation.rs +12 -9
- package/crates/team-agent/src/cli/tests/status_send.rs +70 -273
- package/crates/team-agent/src/compiler/tests.rs +39 -27
- package/crates/team-agent/src/compiler.rs +206 -6
- package/crates/team-agent/src/contract_runtime/backend.rs +181 -11
- package/crates/team-agent/src/contract_runtime/commands.rs +338 -7
- package/crates/team-agent/src/contract_runtime/config.rs +30 -19
- package/crates/team-agent/src/contract_runtime/config_tests.rs +24 -4
- package/crates/team-agent/src/contract_runtime/discovery.rs +12 -1
- package/crates/team-agent/src/contract_runtime/fork.rs +3 -10
- package/crates/team-agent/src/contract_runtime/framework.rs +28 -14
- package/crates/team-agent/src/contract_runtime/mcp.rs +19 -24
- package/crates/team-agent/src/contract_runtime/prompt.rs +2 -2
- package/crates/team-agent/src/contract_runtime/registry.rs +93 -130
- package/crates/team-agent/src/coordinator/steps/abnormal.rs +45 -5
- package/crates/team-agent/src/coordinator/tests/api_error_recovery.rs +8 -29
- package/crates/team-agent/src/coordinator/tests/energy.rs +4 -4
- package/crates/team-agent/src/coordinator/tests/health_sync.rs +44 -2
- package/crates/team-agent/src/coordinator/tests/main_preserved.rs +2 -2
- package/crates/team-agent/src/coordinator/tests/spine.rs +1 -1
- package/crates/team-agent/src/coordinator/tests/takeover.rs +3 -3
- package/crates/team-agent/src/coordinator/tick.rs +1 -89
- package/crates/team-agent/src/db/message_store.rs +7 -65
- package/crates/team-agent/src/direct_delivery.rs +368 -0
- package/crates/team-agent/src/inbox_store.rs +169 -0
- package/crates/team-agent/src/leader/registry.rs +5 -0
- package/crates/team-agent/src/leader/start.rs +2 -1
- package/crates/team-agent/src/leader/tests/lease_api.rs +2 -2
- package/crates/team-agent/src/leader/tests/prompt_contract.rs +1 -0
- package/crates/team-agent/src/lib.rs +2 -0
- package/crates/team-agent/src/lifecycle/launch/add_agent.rs +33 -0
- package/crates/team-agent/src/lifecycle/launch/add_agent_state.rs +206 -1
- package/crates/team-agent/src/lifecycle/launch/clone_agent.rs +28 -2
- package/crates/team-agent/src/lifecycle/launch/fork_agent.rs +36 -179
- package/crates/team-agent/src/lifecycle/launch/fork_entry.rs +87 -6
- package/crates/team-agent/src/lifecycle/launch/mcp_config.rs +13 -488
- package/crates/team-agent/src/lifecycle/launch/pi_mcp.rs +351 -81
- package/crates/team-agent/src/lifecycle/launch/pi_mcp_extension.js +3 -4
- package/crates/team-agent/src/lifecycle/launch/quick_start.rs +26 -2
- package/crates/team-agent/src/lifecycle/launch/spawn.rs +41 -31
- package/crates/team-agent/src/lifecycle/launch.rs +27 -12
- package/crates/team-agent/src/lifecycle/profile_launch.rs +318 -64
- package/crates/team-agent/src/lifecycle/restart/agent.rs +1 -0
- package/crates/team-agent/src/lifecycle/restart/avatar.rs +1798 -0
- package/crates/team-agent/src/lifecycle/restart/claude_fork.rs +163 -0
- package/crates/team-agent/src/lifecycle/restart/common.rs +298 -133
- package/crates/team-agent/src/lifecycle/restart/remove.rs +129 -0
- package/crates/team-agent/src/lifecycle/restart/selection.rs +5 -5
- package/crates/team-agent/src/lifecycle/restart.rs +4 -0
- package/crates/team-agent/src/lifecycle/role_config.rs +79 -27
- package/crates/team-agent/src/lifecycle/tests/acceptance_b_batch_red.rs +1 -1
- package/crates/team-agent/src/lifecycle/tests/agent_ops.rs +8 -12
- package/crates/team-agent/src/lifecycle/tests/behavioral_diff_264_red.rs +37 -240
- package/crates/team-agent/src/lifecycle/tests/claude_compatible_config_red.rs +325 -0
- package/crates/team-agent/src/lifecycle/tests/claude_profile_launch_red.rs +320 -8
- package/crates/team-agent/src/lifecycle/tests/cli_argv_routing_red.rs +329 -70
- package/crates/team-agent/src/lifecycle/tests/clone_fork_copilot_perms_red.rs +378 -4
- package/crates/team-agent/src/lifecycle/tests/communication_mode_runtime_contract_red.rs +25 -39
- package/crates/team-agent/src/lifecycle/tests/copilot_provider_red.rs +7 -11
- package/crates/team-agent/src/lifecycle/tests/core.rs +39 -36
- package/crates/team-agent/src/lifecycle/tests/f032_startup_prompt_best_effort_red.rs +22 -8
- package/crates/team-agent/src/lifecycle/tests/fixtures/pi_native_mcp_host.mjs +2 -1
- package/crates/team-agent/src/lifecycle/tests/grok_require_explicit_model_red.rs +15 -133
- package/crates/team-agent/src/lifecycle/tests/harvest2_a_batch_red.rs +60 -20
- package/crates/team-agent/src/lifecycle/tests/host_cotenant_death_p0_contract.rs +30 -67
- package/crates/team-agent/src/lifecycle/tests/issue238_codex_effort_contract.rs +3 -31
- package/crates/team-agent/src/lifecycle/tests/lane_ops.rs +194 -169
- package/crates/team-agent/src/lifecycle/tests/launch_spawn.rs +164 -282
- package/crates/team-agent/src/lifecycle/tests/lifecycle_rollback_red.rs +15 -78
- package/crates/team-agent/src/lifecycle/tests/main_preserved.rs +7 -7
- package/crates/team-agent/src/lifecycle/tests/mcp_tool_name_format_red.rs +6 -6
- package/crates/team-agent/src/lifecycle/tests/phase_b_contracts.rs +75 -69
- package/crates/team-agent/src/lifecycle/tests/phase_golden.rs +2 -10
- package/crates/team-agent/src/lifecycle/tests/pi_catalog_red.rs +18 -6
- package/crates/team-agent/src/lifecycle/tests/pi_command_red.rs +70 -52
- package/crates/team-agent/src/lifecycle/tests/pi_compiler_red.rs +210 -0
- package/crates/team-agent/src/lifecycle/tests/pi_dual_entry_red.rs +157 -4
- package/crates/team-agent/src/lifecycle/tests/pi_executable_mcp_red.rs +526 -10
- package/crates/team-agent/src/lifecycle/tests/pi_fork_session_inheritance_red.rs +1419 -0
- package/crates/team-agent/src/lifecycle/tests/pi_lifecycle_doctor_red.rs +68 -1
- package/crates/team-agent/src/lifecycle/tests/pi_native_mcp_capability_red.rs +34 -12
- package/crates/team-agent/src/lifecycle/tests/pi_session_delivery_red.rs +94 -2
- package/crates/team-agent/src/lifecycle/tests/quick_start_worker_readiness_red.rs +14 -15
- package/crates/team-agent/src/lifecycle/tests/restart.rs +12 -153
- package/crates/team-agent/src/lifecycle/tests/restart_build_before_destroy_0540_contract.rs +27 -5
- package/crates/team-agent/src/lifecycle/tests/restart_liveness_red.rs +59 -10
- package/crates/team-agent/src/lifecycle/tests/restart_rebind_hotfix_252_red.rs +47 -6
- package/crates/team-agent/src/lifecycle/tests/restart_session_capture_red.rs +3 -1374
- package/crates/team-agent/src/lifecycle/tests/resume_recover_red.rs +27 -10
- package/crates/team-agent/src/lifecycle/tests/status_credential_redaction_contract.rs +7 -7
- package/crates/team-agent/src/lifecycle/tests/subprep_codex_trust_roundtrip_red.rs +67 -313
- package/crates/team-agent/src/lifecycle/tests/swallow_batch4_semantics_red.rs +254 -2
- package/crates/team-agent/src/lifecycle/tests/team_in_team_identity_scope_red.rs +2 -2
- package/crates/team-agent/src/lifecycle/tests/team_in_team_sibling_quick_start_red.rs +1 -1
- package/crates/team-agent/src/lifecycle/tests/team_in_team_state_scope_red.rs +2 -2
- package/crates/team-agent/src/lifecycle/tests/team_key_retirement_txn_red.rs +4 -4
- package/crates/team-agent/src/lifecycle/tests/upgrade_compat_0211_red.rs +74 -19
- package/crates/team-agent/src/lifecycle/tests/verify_rs031_window_consistency_red.rs +38 -39
- package/crates/team-agent/src/lifecycle/tests/worker_spawn_env_red.rs +51 -88
- package/crates/team-agent/src/lifecycle/tests.rs +3 -4
- package/crates/team-agent/src/lifecycle/types.rs +18 -5
- package/crates/team-agent/src/lifecycle/worker_command_context.rs +43 -50
- package/crates/team-agent/src/mcp_server/readiness.rs +130 -149
- package/crates/team-agent/src/mcp_server/readiness_tests.rs +86 -109
- package/crates/team-agent/src/mcp_server/tests/scoped.rs +21 -31
- package/crates/team-agent/src/mcp_server/tests/send.rs +72 -107
- package/crates/team-agent/src/mcp_server/tests/tools.rs +10 -12
- package/crates/team-agent/src/mcp_server/tools.rs +70 -196
- package/crates/team-agent/src/messaging/delivery.rs +143 -253
- package/crates/team-agent/src/messaging/delivery_consumption_tests.rs +5 -5
- package/crates/team-agent/src/messaging/helpers.rs +1 -19
- package/crates/team-agent/src/messaging/mod.rs +1 -0
- package/crates/team-agent/src/messaging/reminders.rs +316 -0
- package/crates/team-agent/src/messaging/scheduler.rs +7 -1
- package/crates/team-agent/src/messaging/tests/dup_inject.rs +255 -150
- package/crates/team-agent/src/messaging/tests/main_preserved.rs +2 -2
- package/crates/team-agent/src/messaging/tests/runtime.rs +9 -115
- package/crates/team-agent/src/messaging/tests/spine.rs +44 -24
- package/crates/team-agent/src/messaging/tests/wave2.rs +13 -20
- package/crates/team-agent/src/messaging/types.rs +1 -0
- package/crates/team-agent/src/provider/adapter.rs +208 -254
- package/crates/team-agent/src/provider/adapters/claude.rs +78 -0
- package/crates/team-agent/src/provider/adapters/claude_fork.rs +131 -0
- package/crates/team-agent/src/provider/adapters/mod.rs +7 -7
- package/crates/team-agent/src/provider/adapters/pi.rs +106 -0
- package/crates/team-agent/src/provider/classify.rs +1 -66
- package/crates/team-agent/src/provider/model_catalog.rs +201 -13
- package/crates/team-agent/src/provider/session/capture.rs +111 -111
- package/crates/team-agent/src/provider/session/context_fork/claude.rs +123 -0
- package/crates/team-agent/src/provider/session/context_fork/outcome.rs +10 -18
- package/crates/team-agent/src/provider/session/context_fork.rs +87 -74
- package/crates/team-agent/src/provider/session/mod.rs +2 -3
- package/crates/team-agent/src/provider/session_scan/claude.rs +523 -0
- package/crates/team-agent/src/provider/session_scan/common.rs +47 -47
- package/crates/team-agent/src/provider/session_scan/pi.rs +34 -1
- package/crates/team-agent/src/provider/session_scan.rs +13 -13
- package/crates/team-agent/src/provider/tests/adapter.rs +127 -121
- package/crates/team-agent/src/provider/tests/classify.rs +0 -53
- package/crates/team-agent/src/provider/tests/command_helpers.rs +11 -19
- package/crates/team-agent/src/provider/tests/idle.rs +13 -19
- package/crates/team-agent/src/provider/types.rs +0 -4
- package/crates/team-agent/src/provider/wire.rs +34 -20
- package/crates/team-agent/src/state/abnormal_watch/tests/mod.rs +1 -1
- package/crates/team-agent/src/state/persist.rs +6 -6
- package/crates/team-agent/src/state/projection.rs +1 -1
- package/crates/team-agent/src/state/repository/tests.rs +2 -2
- package/crates/team-agent/src/test_support/models_timeout_fixture.rs +144 -0
- package/crates/team-agent/src/tmux_backend/tests.rs +0 -151
- package/crates/team-agent/src/tmux_backend.rs +9 -43
- package/package.json +4 -4
- package/skills/team-agent/SKILL.md +7 -8
- package/skills/team-agent/command-coverage.json +15 -1
- package/skills/team-agent/docs/reference/team-agent-operator.md +5 -3
- package/skills/team-agent/references/team-agent-operator.md +5 -3
- package/crates/team-agent/src/lifecycle/launch/grok_per_seat.rs +0 -260
- package/crates/team-agent/src/lifecycle/tests/codex_weak_window_attribution_red.rs +0 -683
- package/crates/team-agent/src/lifecycle/tests/grok_effort_argv_red.rs +0 -247
- package/crates/team-agent/src/lifecycle/tests/grok_mcp_overlay_red.rs +0 -507
- package/crates/team-agent/src/lifecycle/tests/grok_restart_resume_red.rs +0 -300
- package/crates/team-agent/src/provider/adapters/codex.rs +0 -101
- package/crates/team-agent/src/provider/adapters/grok.rs +0 -67
- package/crates/team-agent/src/provider/session/context_fork/codex.rs +0 -514
- package/crates/team-agent/src/provider/session_scan/codex.rs +0 -326
- package/crates/team-agent/src/provider/session_scan/grok.rs +0 -288
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
//!
|
|
2
|
+
//! Claude / ClaudeCode provider-local command builders + permission helpers.
|
|
3
|
+
//!
|
|
4
|
+
//! Extracted from `provider/adapter.rs` (0.4.x decoupling step 2). Pure
|
|
5
|
+
//! extraction — byte-identical to the original inline forms. Scope kept
|
|
6
|
+
//! small on purpose: base command + launch wrapper +
|
|
7
|
+
//! launch wrapper. Auth hints (`claude_auth_hint`) and the context-aware model
|
|
8
|
+
//! resolver (`claude_context_model`) stay in `adapter.rs`; capture scanning
|
|
9
|
+
//! helpers now live under `provider/session_scan/claude.rs`.
|
|
10
|
+
|
|
11
|
+
use crate::model::enums::{AuthMode, Provider};
|
|
12
|
+
use crate::provider::adapter::{next_session_token, prompt_needs_native_mcp, BasicProviderAdapter};
|
|
13
|
+
use crate::provider::{McpConfig, ProviderAdapter, ProviderError};
|
|
14
|
+
use crate::provider::command_helpers::{append_opt_pair, append_pair};
|
|
15
|
+
|
|
16
|
+
pub(crate) fn claude_launch_command(
|
|
17
|
+
adapter: &BasicProviderAdapter,
|
|
18
|
+
auth_mode: AuthMode,
|
|
19
|
+
mcp_config: Option<&McpConfig>,
|
|
20
|
+
system_prompt: Option<&str>,
|
|
21
|
+
model: Option<&str>,
|
|
22
|
+
dangerously_skip_permissions: bool,
|
|
23
|
+
) -> Result<Vec<String>, ProviderError> {
|
|
24
|
+
let mut argv = claude_base_command(
|
|
25
|
+
adapter,
|
|
26
|
+
auth_mode,
|
|
27
|
+
mcp_config,
|
|
28
|
+
system_prompt,
|
|
29
|
+
model,
|
|
30
|
+
dangerously_skip_permissions,
|
|
31
|
+
false,
|
|
32
|
+
None,
|
|
33
|
+
)?;
|
|
34
|
+
append_pair(&mut argv, "--session-id", next_session_token());
|
|
35
|
+
Ok(argv)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
pub(crate) fn claude_base_command(
|
|
39
|
+
adapter: &BasicProviderAdapter,
|
|
40
|
+
auth_mode: AuthMode,
|
|
41
|
+
mcp_config: Option<&McpConfig>,
|
|
42
|
+
system_prompt: Option<&str>,
|
|
43
|
+
model: Option<&str>,
|
|
44
|
+
dangerously_skip_permissions: bool,
|
|
45
|
+
managed_mcp_config: bool,
|
|
46
|
+
// 0.4.x provider effort MVP step 5: when Some, inject `--effort <level>`
|
|
47
|
+
// immediately after the model (before prompt/MCP).
|
|
48
|
+
effort: Option<crate::model::enums::ProviderEffort>,
|
|
49
|
+
) -> Result<Vec<String>, ProviderError> {
|
|
50
|
+
let mut argv = vec!["claude".to_string()];
|
|
51
|
+
if dangerously_skip_permissions {
|
|
52
|
+
// 0.5.66 bypass 单源:flag 由 provider_bypass_flag 表供给(单源)。
|
|
53
|
+
let flag = crate::provider::bypass_flags::provider_bypass_flag(Provider::Claude)
|
|
54
|
+
.expect("claude provider must define a bypass flag");
|
|
55
|
+
argv.push(flag.to_string());
|
|
56
|
+
} else {
|
|
57
|
+
append_pair(&mut argv, "--permission-mode", "default");
|
|
58
|
+
}
|
|
59
|
+
append_opt_pair(&mut argv, "--model", model);
|
|
60
|
+
if let Some(effort) = effort {
|
|
61
|
+
argv.push("--effort".to_string());
|
|
62
|
+
argv.push(effort.as_str().to_string());
|
|
63
|
+
}
|
|
64
|
+
append_opt_pair(&mut argv, "--append-system-prompt", system_prompt);
|
|
65
|
+
if !managed_mcp_config
|
|
66
|
+
&& (mcp_config.is_some()
|
|
67
|
+
|| auth_mode == AuthMode::CompatibleApi
|
|
68
|
+
|| system_prompt.is_some_and(prompt_needs_native_mcp))
|
|
69
|
+
{
|
|
70
|
+
let raw = if let Some(config) = mcp_config {
|
|
71
|
+
serde_json::json!({"mcpServers": config.raw.clone()})
|
|
72
|
+
} else {
|
|
73
|
+
serde_json::json!({"mcpServers": adapter.mcp_config(auth_mode)?.raw})
|
|
74
|
+
};
|
|
75
|
+
append_pair(&mut argv, "--mcp-config", raw.to_string());
|
|
76
|
+
}
|
|
77
|
+
Ok(argv)
|
|
78
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
//!
|
|
2
|
+
use std::path::{Path, PathBuf};
|
|
3
|
+
|
|
4
|
+
use crate::provider::{ProviderError, SessionId};
|
|
5
|
+
|
|
6
|
+
#[derive(Debug)]
|
|
7
|
+
pub(crate) struct ClaudeForkMaterialization {
|
|
8
|
+
path: PathBuf,
|
|
9
|
+
keep: bool,
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
impl ClaudeForkMaterialization {
|
|
13
|
+
pub(crate) fn path(&self) -> &Path {
|
|
14
|
+
&self.path
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
pub(crate) fn keep(&mut self) {
|
|
18
|
+
self.keep = true;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
impl Drop for ClaudeForkMaterialization {
|
|
23
|
+
fn drop(&mut self) {
|
|
24
|
+
if !self.keep {
|
|
25
|
+
let _ = std::fs::remove_file(&self.path);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
pub(crate) fn materialize_claude_fork(
|
|
31
|
+
source_path: &Path,
|
|
32
|
+
source_session_id: &SessionId,
|
|
33
|
+
target_session_id: &SessionId,
|
|
34
|
+
source_agent_id: &str,
|
|
35
|
+
target_agent_id: &str,
|
|
36
|
+
) -> Result<ClaudeForkMaterialization, ProviderError> {
|
|
37
|
+
let parent = source_path.parent().ok_or_else(|| {
|
|
38
|
+
ProviderError::Io(format!(
|
|
39
|
+
"claude source backing has no parent: {}",
|
|
40
|
+
source_path.display()
|
|
41
|
+
))
|
|
42
|
+
})?;
|
|
43
|
+
let target_path = parent.join(format!("{}.jsonl", target_session_id.as_str()));
|
|
44
|
+
if target_path.exists() {
|
|
45
|
+
return Err(ProviderError::Io(format!(
|
|
46
|
+
"claude fork destination already exists: {}",
|
|
47
|
+
target_path.display()
|
|
48
|
+
)));
|
|
49
|
+
}
|
|
50
|
+
let source = std::fs::read_to_string(source_path)
|
|
51
|
+
.map_err(|error| ProviderError::Io(error.to_string()))?;
|
|
52
|
+
let rewritten = source
|
|
53
|
+
.replace(source_session_id.as_str(), target_session_id.as_str())
|
|
54
|
+
.replace(
|
|
55
|
+
&format!("You are Team Agent worker `{source_agent_id}`"),
|
|
56
|
+
&format!("You are Team Agent worker `{target_agent_id}`"),
|
|
57
|
+
);
|
|
58
|
+
validate_jsonl(&rewritten)?;
|
|
59
|
+
let temp = parent.join(format!(
|
|
60
|
+
".{}.tmp-{}",
|
|
61
|
+
target_session_id.as_str(),
|
|
62
|
+
std::process::id()
|
|
63
|
+
));
|
|
64
|
+
let result = std::fs::write(&temp, rewritten)
|
|
65
|
+
.and_then(|_| std::fs::rename(&temp, &target_path))
|
|
66
|
+
.map_err(|error| ProviderError::Io(error.to_string()));
|
|
67
|
+
if let Err(error) = result {
|
|
68
|
+
let _ = std::fs::remove_file(&temp);
|
|
69
|
+
return Err(error);
|
|
70
|
+
}
|
|
71
|
+
Ok(ClaudeForkMaterialization {
|
|
72
|
+
path: target_path,
|
|
73
|
+
keep: false,
|
|
74
|
+
})
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
fn validate_jsonl(text: &str) -> Result<(), ProviderError> {
|
|
78
|
+
let mut rows = 0_usize;
|
|
79
|
+
for (index, line) in text.lines().enumerate() {
|
|
80
|
+
if line.trim().is_empty() {
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
serde_json::from_str::<serde_json::Value>(line).map_err(|error| {
|
|
84
|
+
ProviderError::Io(format!(
|
|
85
|
+
"claude fork source has invalid JSONL at line {}: {error}",
|
|
86
|
+
index + 1
|
|
87
|
+
))
|
|
88
|
+
})?;
|
|
89
|
+
rows += 1;
|
|
90
|
+
}
|
|
91
|
+
if rows == 0 {
|
|
92
|
+
return Err(ProviderError::Io(
|
|
93
|
+
"claude fork source backing has no JSONL records".to_string(),
|
|
94
|
+
));
|
|
95
|
+
}
|
|
96
|
+
Ok(())
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
#[cfg(test)]
|
|
100
|
+
mod tests {
|
|
101
|
+
use super::*;
|
|
102
|
+
|
|
103
|
+
#[test]
|
|
104
|
+
fn snapshot_rekeys_every_record_and_preserves_source() {
|
|
105
|
+
let dir = std::env::temp_dir().join(format!("ta-claude-fork-copy-{}", std::process::id()));
|
|
106
|
+
let _ = std::fs::remove_dir_all(&dir);
|
|
107
|
+
std::fs::create_dir_all(&dir).unwrap();
|
|
108
|
+
let source_id = SessionId::new("11111111-1111-4111-8111-111111111111");
|
|
109
|
+
let target_id = SessionId::new("22222222-2222-4222-8222-222222222222");
|
|
110
|
+
let source_path = dir.join(format!("{}.jsonl", source_id.as_str()));
|
|
111
|
+
let source = format!(
|
|
112
|
+
"{{\"sessionId\":\"{}\"}}\n{{\"payload\":{{\"session_id\":\"{}\"}}}}\n",
|
|
113
|
+
source_id.as_str(),
|
|
114
|
+
source_id.as_str()
|
|
115
|
+
);
|
|
116
|
+
std::fs::write(&source_path, &source).unwrap();
|
|
117
|
+
|
|
118
|
+
let mut materialized =
|
|
119
|
+
materialize_claude_fork(&source_path, &source_id, &target_id, "source", "target")
|
|
120
|
+
.unwrap();
|
|
121
|
+
let target_path = dir.join(format!("{}.jsonl", target_id.as_str()));
|
|
122
|
+
let target = std::fs::read_to_string(&target_path).unwrap();
|
|
123
|
+
assert!(!target.contains(source_id.as_str()));
|
|
124
|
+
assert!(target.contains(target_id.as_str()));
|
|
125
|
+
assert_eq!(std::fs::read_to_string(&source_path).unwrap(), source);
|
|
126
|
+
materialized.keep();
|
|
127
|
+
drop(materialized);
|
|
128
|
+
assert!(target_path.is_file());
|
|
129
|
+
let _ = std::fs::remove_dir_all(&dir);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
@@ -8,23 +8,23 @@
|
|
|
8
8
|
//! dispatches into these helpers exactly as the inline forms did.
|
|
9
9
|
//!
|
|
10
10
|
//! Per-file scope:
|
|
11
|
-
//! * `
|
|
12
|
-
//! tool_timeout, developer-instructions escaping.
|
|
11
|
+
//! * `claude` — Claude/ClaudeCode argv, bypass flag, auth hint, model passthrough.
|
|
13
12
|
//! * `copilot` — Copilot argv (no-color/no-remote/disable-builtin-mcps),
|
|
14
13
|
//! MCP `type→transport` translation, resume base, weak auth hint.
|
|
15
14
|
//! * `fake` — Built-in scripted worker exec path.
|
|
16
15
|
//!
|
|
17
|
-
//!
|
|
18
|
-
//! (`
|
|
19
|
-
//!
|
|
16
|
+
//! Codex and Grok workers run only through their contract leaves
|
|
17
|
+
//! (`codex_tui`, `grok_build`); their legacy worker builders were excised. The
|
|
18
|
+
//! Codex and Grok leaders exec their bare public command (`leader/start.rs`).
|
|
20
19
|
//!
|
|
21
20
|
//! Behavior is byte-identical to pre-split. Future steps may move
|
|
22
21
|
//! `pre_spawn_adjust_plan`, `profile_env`, `session_backing_probe`, and
|
|
23
22
|
//! `session_candidates` into provider-owned hooks following the same
|
|
24
23
|
//! per-file layout.
|
|
25
24
|
|
|
26
|
-
pub(crate) mod
|
|
25
|
+
pub(crate) mod claude;
|
|
26
|
+
pub(crate) mod claude_fork;
|
|
27
27
|
pub(crate) mod copilot;
|
|
28
28
|
pub(crate) mod copilot_fork;
|
|
29
29
|
pub(crate) mod fake;
|
|
30
|
-
pub(crate) mod
|
|
30
|
+
pub(crate) mod pi;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
//! ---
|
|
2
|
+
//! purpose: Pi CLI 的纯工具映射与 fresh/resume argv 构造
|
|
3
|
+
//! contract:
|
|
4
|
+
//! provides:
|
|
5
|
+
//! - name: build_pi_command_argv
|
|
6
|
+
//! what: 仅从已验证输入构造保留 direct Pi 配置的 Team Agent argv
|
|
7
|
+
//! boundary:
|
|
8
|
+
//! - 不发现 executable、catalog、adapter 或 MCP 配置
|
|
9
|
+
//! - 除 resume exact backing 存在性外不读文件;不写文件、不启动进程
|
|
10
|
+
//! maturity: wired
|
|
11
|
+
//! ---
|
|
12
|
+
|
|
13
|
+
use std::path::Path;
|
|
14
|
+
|
|
15
|
+
use crate::model::enums::ProviderEffort;
|
|
16
|
+
use crate::provider::ProviderError;
|
|
17
|
+
use crate::provider::command_helpers::{append_opt_pair, append_pair};
|
|
18
|
+
|
|
19
|
+
#[derive(Debug, Clone, Copy)]
|
|
20
|
+
pub(crate) enum PiSessionSelector<'a> {
|
|
21
|
+
/// Pi assigns the session id. Passing `--session-id` makes Pi warn and
|
|
22
|
+
/// then create, because the id is not a project session yet.
|
|
23
|
+
Fresh,
|
|
24
|
+
FreshWithId {
|
|
25
|
+
id: &'a crate::provider::SessionId,
|
|
26
|
+
},
|
|
27
|
+
Resume { path: &'a Path },
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
pub(crate) struct PiCommandRequest<'a> {
|
|
31
|
+
pub extension: &'a Path,
|
|
32
|
+
pub model: Option<&'a str>,
|
|
33
|
+
pub effort: Option<ProviderEffort>,
|
|
34
|
+
pub system_prompt: &'a str,
|
|
35
|
+
/// Team-owned session root for isolated seats; `None` preserves Pi's native default.
|
|
36
|
+
pub session_dir: Option<&'a Path>,
|
|
37
|
+
pub session: PiSessionSelector<'a>,
|
|
38
|
+
pub agent_id: &'a str,
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/// ---
|
|
42
|
+
/// purpose: 从已验证 semantic request 构造仅追加 Team Agent MCP/提示/session 的 Pi argv
|
|
43
|
+
/// returns: exact ordered fresh/resume argv,argv[0] 固定为裸 `pi`
|
|
44
|
+
/// errors: 必需字段时返回 ProviderError
|
|
45
|
+
/// ---
|
|
46
|
+
pub(crate) fn build_pi_command_argv(
|
|
47
|
+
request: PiCommandRequest<'_>,
|
|
48
|
+
) -> Result<Vec<String>, ProviderError> {
|
|
49
|
+
if request.extension.as_os_str().is_empty()
|
|
50
|
+
|| request
|
|
51
|
+
.session_dir
|
|
52
|
+
.is_some_and(|session_dir| session_dir.as_os_str().is_empty())
|
|
53
|
+
|| request.model.is_some_and(|model| model.trim().is_empty())
|
|
54
|
+
|| request.system_prompt.trim().is_empty()
|
|
55
|
+
|| request.agent_id.trim().is_empty()
|
|
56
|
+
{
|
|
57
|
+
return Err(ProviderError::Command(
|
|
58
|
+
"Pi command requires extension, prompt, and agent id".to_string(),
|
|
59
|
+
));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Executable discovery/preflight belongs to the lifecycle materializer;
|
|
63
|
+
// the actual command must remain PATH-resolved at spawn time.
|
|
64
|
+
let mut argv = vec![
|
|
65
|
+
"pi".to_string(),
|
|
66
|
+
"-e".to_string(),
|
|
67
|
+
request.extension.to_string_lossy().into_owned(),
|
|
68
|
+
];
|
|
69
|
+
append_opt_pair(&mut argv, "--model", request.model);
|
|
70
|
+
if let Some(effort) = request.effort {
|
|
71
|
+
argv.push("--thinking".to_string());
|
|
72
|
+
argv.push(effort.as_str().to_string());
|
|
73
|
+
}
|
|
74
|
+
append_pair(&mut argv, "--append-system-prompt", request.system_prompt);
|
|
75
|
+
if let Some(session_dir) = request.session_dir {
|
|
76
|
+
append_pair(&mut argv, "--session-dir", session_dir.to_string_lossy().into_owned());
|
|
77
|
+
}
|
|
78
|
+
// The shared lifecycle materializer always revalidates resume root/path/header.
|
|
79
|
+
// Keep the pure argv builder usable before a fixture root is materialized, while
|
|
80
|
+
// refusing a missing exact file once the recorded path's parent exists.
|
|
81
|
+
match request.session {
|
|
82
|
+
PiSessionSelector::Fresh => {}
|
|
83
|
+
PiSessionSelector::FreshWithId { id } => {
|
|
84
|
+
argv.extend(["--session-id".to_string(), id.as_str().to_string()]);
|
|
85
|
+
}
|
|
86
|
+
PiSessionSelector::Resume { path }
|
|
87
|
+
if !path.as_os_str().is_empty()
|
|
88
|
+
&& (!path.parent().is_some_and(Path::is_dir) || path.is_file()) =>
|
|
89
|
+
{
|
|
90
|
+
append_pair(&mut argv, "--session", path.to_string_lossy().into_owned());
|
|
91
|
+
}
|
|
92
|
+
PiSessionSelector::Resume { path } if !path.as_os_str().is_empty() => {
|
|
93
|
+
return Err(ProviderError::ResumeUnavailable(format!(
|
|
94
|
+
"Pi exact session backing is missing: {}",
|
|
95
|
+
path.display()
|
|
96
|
+
)));
|
|
97
|
+
}
|
|
98
|
+
_ => {
|
|
99
|
+
return Err(ProviderError::Command(
|
|
100
|
+
"Pi command requires a non-empty session selector".to_string(),
|
|
101
|
+
));
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
append_pair(&mut argv, "--name", request.agent_id);
|
|
105
|
+
Ok(argv)
|
|
106
|
+
}
|
|
@@ -68,71 +68,6 @@ pub fn classify(
|
|
|
68
68
|
Ok(decide_state(fact, process))
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
/// #379: where an agent's Claude process keeps its live registry record and
|
|
72
|
-
/// under which session id. Beside the captured transcript
|
|
73
|
-
/// (`<config>/projects/<slug>/<sessionId>.jsonl`); before capture, under the
|
|
74
|
-
/// projects root it was launched with (profile, else the native
|
|
75
|
-
/// `$HOME/.claude/projects`) and the `--session-id` it was started under.
|
|
76
|
-
pub fn claude_registry_key(agent: &serde_json::Value) -> Option<(std::path::PathBuf, String)> {
|
|
77
|
-
let text = |key: &str| {
|
|
78
|
-
agent.get(key).and_then(serde_json::Value::as_str).filter(|value| !value.is_empty())
|
|
79
|
-
};
|
|
80
|
-
let (projects, session_id) = match text("rollout_path").map(std::path::Path::new) {
|
|
81
|
-
Some(rollout) => (rollout.parent()?.parent()?.to_path_buf(), rollout.file_stem()?.to_str()?),
|
|
82
|
-
None => (
|
|
83
|
-
text("claude_projects_root").map(std::path::PathBuf::from).or_else(|| {
|
|
84
|
-
std::env::var_os("HOME")
|
|
85
|
-
.map(|home| std::path::PathBuf::from(home).join(".claude").join("projects"))
|
|
86
|
-
})?,
|
|
87
|
-
text("_pending_session_id").or_else(|| text("session_id"))?,
|
|
88
|
-
),
|
|
89
|
-
};
|
|
90
|
-
if projects.file_name()? != "projects" {
|
|
91
|
-
return None;
|
|
92
|
-
}
|
|
93
|
-
Some((projects.parent()?.join("sessions"), session_id.to_owned()))
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/// #379: Claude Code's own live turn state. The CLI writes `status` into
|
|
97
|
-
/// `<config>/sessions/<pid>.json` at startup and on every transition
|
|
98
|
-
/// (`running`→`busy`, `requires_action`→`waiting`, `idle`→`idle`). A record
|
|
99
|
-
/// counts only with this session id, a live pid and, when it names one, the
|
|
100
|
-
/// same tmux pane. None = no decisive record.
|
|
101
|
-
pub fn claude_registry_turn_state(
|
|
102
|
-
sessions: &std::path::Path,
|
|
103
|
-
session_id: &str,
|
|
104
|
-
pane_id: Option<&str>,
|
|
105
|
-
) -> Option<TurnState> {
|
|
106
|
-
let entries = std::fs::read_dir(sessions).ok()?;
|
|
107
|
-
entries.flatten().find_map(|entry| {
|
|
108
|
-
let path = entry.path();
|
|
109
|
-
if path.extension()? != "json" || entry.metadata().ok()?.len() > 64 * 1024 {
|
|
110
|
-
return None;
|
|
111
|
-
}
|
|
112
|
-
let record: serde_json::Value = serde_json::from_slice(&std::fs::read(&path).ok()?).ok()?;
|
|
113
|
-
let field = |key: &str| record.get(key).and_then(serde_json::Value::as_str);
|
|
114
|
-
if field("sessionId") != Some(session_id) {
|
|
115
|
-
return None;
|
|
116
|
-
}
|
|
117
|
-
// `tmux` is `<session>:@<window>.%<pane>`.
|
|
118
|
-
if let (Some(pane), Some(tmux)) = (pane_id, field("tmux")) {
|
|
119
|
-
if tmux.rsplit_once('.').map(|(_, recorded)| recorded) != Some(pane) {
|
|
120
|
-
return None;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
let pid = u32::try_from(record.get("pid")?.as_u64()?).ok()?;
|
|
124
|
-
if !crate::platform::process::pid_is_alive(pid) {
|
|
125
|
-
return None;
|
|
126
|
-
}
|
|
127
|
-
match field("status")? {
|
|
128
|
-
"busy" => Some(TurnState::Working),
|
|
129
|
-
"waiting" => Some(TurnState::BlockedOnHuman),
|
|
130
|
-
"idle" => Some(TurnState::Idle),
|
|
131
|
-
_ => None,
|
|
132
|
-
}
|
|
133
|
-
})
|
|
134
|
-
}
|
|
135
|
-
|
|
136
71
|
/// Blocker-2 Layer-2: scan Claude transcript records for background task
|
|
137
72
|
/// lifecycle markers. Returns `Some(turn_id)` when at least one background
|
|
138
73
|
/// task is OPEN (started but not closed) — caller treats as `TurnOpen` with
|
|
@@ -484,7 +419,7 @@ fn decide_state(fact: &LifecycleFact, process: ProcessLiveness) -> ClassifyResul
|
|
|
484
419
|
ProcessLiveness::Alive => classify_result(
|
|
485
420
|
TurnState::Working,
|
|
486
421
|
fact.turn_id.clone(),
|
|
487
|
-
if
|
|
422
|
+
if fact.reason == "assistant_in_flight" {
|
|
488
423
|
&fact.reason
|
|
489
424
|
} else {
|
|
490
425
|
"open_turn"
|