@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
|
@@ -23,6 +23,15 @@ use crate::transport::{PaneId, SessionName, Target, Transport, WindowName};
|
|
|
23
23
|
|
|
24
24
|
use crate::lifecycle::lock::{acquire_agent_lifecycle_lock, LifecycleLockRequest};
|
|
25
25
|
|
|
26
|
+
#[derive(Clone, Debug)]
|
|
27
|
+
pub(crate) struct ForkCaptureSeed {
|
|
28
|
+
pub source_agent_id: AgentId,
|
|
29
|
+
pub captured: crate::provider::CapturedSession,
|
|
30
|
+
pub captured_at: String,
|
|
31
|
+
pub pi_sessions_root: PathBuf,
|
|
32
|
+
pub profile_dir: PathBuf,
|
|
33
|
+
}
|
|
34
|
+
|
|
26
35
|
use super::*;
|
|
27
36
|
|
|
28
37
|
// ── lifecycle::launch —— 冷启 / quick-start / 危险审批探测 ──────────────────
|
|
@@ -343,6 +352,20 @@ pub(crate) use mcp_config::{
|
|
|
343
352
|
|
|
344
353
|
pub(crate) mod pi_mcp;
|
|
345
354
|
|
|
355
|
+
pub(crate) fn run_pi_catalog_preflight(
|
|
356
|
+
agents_dir: &std::path::Path,
|
|
357
|
+
discover: &mut dyn FnMut(&str) -> Result<Vec<String>, ()>,
|
|
358
|
+
) -> Result<(), crate::lifecycle::LifecycleError> {
|
|
359
|
+
crate::compiler::preflight_pi_models_in_team_with(agents_dir, discover).map_err(|error| {
|
|
360
|
+
crate::lifecycle::LifecycleError::PiModelPreflight {
|
|
361
|
+
requested: error.requested,
|
|
362
|
+
candidates: error.candidates,
|
|
363
|
+
action: error.action,
|
|
364
|
+
not_ready: error.not_ready,
|
|
365
|
+
}
|
|
366
|
+
})
|
|
367
|
+
}
|
|
368
|
+
|
|
346
369
|
mod worker_env;
|
|
347
370
|
pub(super) use worker_env::*;
|
|
348
371
|
pub(crate) use worker_env::{
|
|
@@ -402,7 +425,7 @@ pub(super) use add_agent::*;
|
|
|
402
425
|
pub use add_agent::{add_agent, add_agent_force};
|
|
403
426
|
pub(crate) use add_agent::{
|
|
404
427
|
add_agent_with_transport, add_agent_with_transport_at_paths_locked,
|
|
405
|
-
add_agent_with_transport_force, force_recreate_with_transport_locked,
|
|
428
|
+
add_agent_with_transport_force, add_forked_agent_locked, force_recreate_with_transport_locked,
|
|
406
429
|
};
|
|
407
430
|
|
|
408
431
|
pub(crate) mod add_agent_state;
|
|
@@ -205,6 +205,9 @@ fn prepare_profile_launch(
|
|
|
205
205
|
return Ok(ProviderProfileLaunch::default());
|
|
206
206
|
};
|
|
207
207
|
let Some(path) = find_profile_file(workspace, profile, agent.profile_dir.as_deref()) else {
|
|
208
|
+
if agent.provider == Provider::Pi && agent.auth_mode == AuthMode::Subscription {
|
|
209
|
+
return Ok(ProviderProfileLaunch::default());
|
|
210
|
+
}
|
|
208
211
|
return Err(profile_not_found(profile));
|
|
209
212
|
};
|
|
210
213
|
let loaded = read_profile_file(path)?;
|
|
@@ -212,8 +215,26 @@ fn prepare_profile_launch(
|
|
|
212
215
|
|
|
213
216
|
let mut env_overlay = provider_env_exports(agent.provider, agent.auth_mode, &loaded.values);
|
|
214
217
|
let mut env_unset = provider_env_unsets(agent.provider, agent.auth_mode);
|
|
215
|
-
|
|
216
|
-
let
|
|
218
|
+
let mut claude_config_dir = None;
|
|
219
|
+
let mut claude_projects_root = None;
|
|
220
|
+
let mut managed_mcp_config = false;
|
|
221
|
+
|
|
222
|
+
if matches!(agent.provider, Provider::Claude | Provider::ClaudeCode)
|
|
223
|
+
&& agent.auth_mode == AuthMode::CompatibleApi
|
|
224
|
+
{
|
|
225
|
+
let dir = compatible_claude_config_dir(workspace, &agent.id)?;
|
|
226
|
+
if let Some(config) = mcp_config {
|
|
227
|
+
ensure_compatible_claude_mcp_config(&dir, workspace, config)?;
|
|
228
|
+
managed_mcp_config = true;
|
|
229
|
+
}
|
|
230
|
+
let projects_root = dir.join("projects");
|
|
231
|
+
env_overlay.insert(
|
|
232
|
+
"CLAUDE_CONFIG_DIR".to_string(),
|
|
233
|
+
dir.to_string_lossy().to_string(),
|
|
234
|
+
);
|
|
235
|
+
claude_projects_root = Some(projects_root);
|
|
236
|
+
claude_config_dir = Some(dir);
|
|
237
|
+
}
|
|
217
238
|
|
|
218
239
|
env_overlay.extend(compatible_api_network_exports(
|
|
219
240
|
agent.auth_mode,
|
|
@@ -233,9 +254,9 @@ fn prepare_profile_launch(
|
|
|
233
254
|
env_overlay,
|
|
234
255
|
env_unset,
|
|
235
256
|
command_overrides,
|
|
236
|
-
claude_config_dir
|
|
237
|
-
claude_projects_root
|
|
238
|
-
managed_mcp_config
|
|
257
|
+
claude_config_dir,
|
|
258
|
+
claude_projects_root,
|
|
259
|
+
managed_mcp_config,
|
|
239
260
|
})
|
|
240
261
|
}
|
|
241
262
|
|
|
@@ -418,6 +439,19 @@ fn provider_env_exports(
|
|
|
418
439
|
return exports;
|
|
419
440
|
}
|
|
420
441
|
match provider {
|
|
442
|
+
Provider::Claude | Provider::ClaudeCode => {
|
|
443
|
+
append_env_pair(&mut exports, "ANTHROPIC_BASE_URL", value_or_alternate(values, "ANTHROPIC_BASE_URL", "BASE_URL"));
|
|
444
|
+
if auth_mode == AuthMode::OfficialApi {
|
|
445
|
+
append_env_pair(&mut exports, "ANTHROPIC_API_KEY", value_or_alternate(values, "ANTHROPIC_API_KEY", "API_KEY"));
|
|
446
|
+
}
|
|
447
|
+
append_env_pair(&mut exports, "ANTHROPIC_AUTH_TOKEN", value_or_alternate(values, "ANTHROPIC_AUTH_TOKEN", "AUTH_TOKEN")
|
|
448
|
+
.or_else(|| {
|
|
449
|
+
(auth_mode == AuthMode::CompatibleApi)
|
|
450
|
+
.then(|| value_or_alternate(values, "ANTHROPIC_API_KEY", "API_KEY"))
|
|
451
|
+
.flatten()
|
|
452
|
+
}));
|
|
453
|
+
append_env_pair(&mut exports, "ANTHROPIC_MODEL", profile_model(values));
|
|
454
|
+
}
|
|
421
455
|
Provider::GeminiCli => {
|
|
422
456
|
append_env_pair(&mut exports, "GEMINI_API_KEY", value_or_alternate(values, "GEMINI_API_KEY", "API_KEY"));
|
|
423
457
|
}
|
|
@@ -440,9 +474,9 @@ fn provider_env_exports(
|
|
|
440
474
|
}
|
|
441
475
|
}
|
|
442
476
|
}
|
|
443
|
-
//
|
|
444
|
-
//
|
|
445
|
-
Provider::
|
|
477
|
+
// Codex and Grok workers run only through their subscription-only
|
|
478
|
+
// contract leaves; Pi retains its native subscription credentials.
|
|
479
|
+
Provider::Codex | Provider::Grok | Provider::Pi => {}
|
|
446
480
|
Provider::Fake => {}
|
|
447
481
|
}
|
|
448
482
|
exports
|
|
@@ -463,10 +497,16 @@ mod append_env_contract {
|
|
|
463
497
|
let map = |pairs: &[(&str, &str)]| -> BTreeMap<String, String> {
|
|
464
498
|
pairs.iter().map(|(k, v)| (k.to_string(), v.to_string())).collect()
|
|
465
499
|
};
|
|
466
|
-
for provider in [Provider::
|
|
500
|
+
for provider in [Provider::Codex, Provider::Grok, Provider::Pi] {
|
|
467
501
|
assert!(provider_env_exports(provider, AuthMode::OfficialApi, &values).is_empty());
|
|
468
502
|
assert!(provider_env_exports(provider, AuthMode::CompatibleApi, &values).is_empty());
|
|
469
503
|
}
|
|
504
|
+
for provider in [Provider::Claude, Provider::ClaudeCode] {
|
|
505
|
+
assert_eq!(provider_env_exports(provider, AuthMode::OfficialApi, &values), map(&[
|
|
506
|
+
("ANTHROPIC_BASE_URL", " raw\nbase "), ("ANTHROPIC_API_KEY", "dummy"),
|
|
507
|
+
("ANTHROPIC_AUTH_TOKEN", "dummy-token"), ("ANTHROPIC_MODEL", " raw model "),
|
|
508
|
+
]));
|
|
509
|
+
}
|
|
470
510
|
assert_eq!(provider_env_exports(Provider::GeminiCli, AuthMode::OfficialApi, &values), map(&[("GEMINI_API_KEY", "dummy")]));
|
|
471
511
|
assert_eq!(provider_env_exports(Provider::Copilot, AuthMode::CompatibleApi, &values), map(&[
|
|
472
512
|
("COPILOT_PROVIDER_BASE_URL", " raw\nbase "), ("COPILOT_PROVIDER_TYPE", "custom"),
|
|
@@ -617,6 +657,270 @@ fn shell_quote(value: &str) -> String {
|
|
|
617
657
|
format!("'{}'", value.replace('\'', "'\"'\"'"))
|
|
618
658
|
}
|
|
619
659
|
|
|
660
|
+
fn compatible_claude_config_dir(
|
|
661
|
+
workspace: &Path,
|
|
662
|
+
agent_id: &str,
|
|
663
|
+
) -> Result<PathBuf, LifecycleError> {
|
|
664
|
+
let dir = workspace
|
|
665
|
+
.join(".team/runtime/provider-config")
|
|
666
|
+
.join(agent_id)
|
|
667
|
+
.join("claude");
|
|
668
|
+
std::fs::create_dir_all(&dir)
|
|
669
|
+
.map_err(|e| LifecycleError::StatePersist(format!("{}: {e}", dir.display())))?;
|
|
670
|
+
ensure_compatible_claude_config(&dir, workspace)?;
|
|
671
|
+
Ok(dir)
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
fn ensure_compatible_claude_config(dir: &Path, workspace: &Path) -> Result<(), LifecycleError> {
|
|
675
|
+
let settings_path = dir.join("settings.json");
|
|
676
|
+
let mut settings = read_json_object(&settings_path)?;
|
|
677
|
+
insert_if_missing(&mut settings, "theme", serde_json::json!("auto"));
|
|
678
|
+
insert_if_missing(
|
|
679
|
+
&mut settings,
|
|
680
|
+
"skipDangerousModePermissionPrompt",
|
|
681
|
+
serde_json::json!(true),
|
|
682
|
+
);
|
|
683
|
+
settings.insert(
|
|
684
|
+
"hasCompletedOnboarding".to_string(),
|
|
685
|
+
serde_json::json!(true),
|
|
686
|
+
);
|
|
687
|
+
settings.insert(
|
|
688
|
+
"hasTrustDialogAccepted".to_string(),
|
|
689
|
+
serde_json::json!(true),
|
|
690
|
+
);
|
|
691
|
+
insert_if_missing(
|
|
692
|
+
&mut settings,
|
|
693
|
+
"lastOnboardingVersion",
|
|
694
|
+
serde_json::json!("2.1.0"),
|
|
695
|
+
);
|
|
696
|
+
insert_if_missing(
|
|
697
|
+
&mut settings,
|
|
698
|
+
"firstStartTime",
|
|
699
|
+
serde_json::json!("1970-01-01T00:00:00.000Z"),
|
|
700
|
+
);
|
|
701
|
+
insert_if_missing(&mut settings, "numStartups", serde_json::json!(0));
|
|
702
|
+
insert_if_missing(
|
|
703
|
+
&mut settings,
|
|
704
|
+
"projectOnboardingSeenCount",
|
|
705
|
+
serde_json::json!(1),
|
|
706
|
+
);
|
|
707
|
+
write_json_object(&settings_path, &settings)?;
|
|
708
|
+
|
|
709
|
+
let state_path = dir.join(".claude.json");
|
|
710
|
+
let mut state = read_json_object(&state_path)?;
|
|
711
|
+
state.insert(
|
|
712
|
+
"hasCompletedOnboarding".to_string(),
|
|
713
|
+
serde_json::json!(true),
|
|
714
|
+
);
|
|
715
|
+
insert_if_missing(
|
|
716
|
+
&mut state,
|
|
717
|
+
"lastOnboardingVersion",
|
|
718
|
+
serde_json::json!("2.1.0"),
|
|
719
|
+
);
|
|
720
|
+
insert_if_missing(
|
|
721
|
+
&mut state,
|
|
722
|
+
"firstStartTime",
|
|
723
|
+
serde_json::json!("1970-01-01T00:00:00.000Z"),
|
|
724
|
+
);
|
|
725
|
+
insert_if_missing(&mut state, "numStartups", serde_json::json!(0));
|
|
726
|
+
ensure_claude_projects(&mut state, workspace, None);
|
|
727
|
+
write_json_object(&state_path, &state)
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
fn ensure_compatible_claude_mcp_config(
|
|
731
|
+
dir: &Path,
|
|
732
|
+
workspace: &Path,
|
|
733
|
+
mcp_config: &McpConfig,
|
|
734
|
+
) -> Result<(), LifecycleError> {
|
|
735
|
+
let state_path = dir.join(".claude.json");
|
|
736
|
+
let mut state = read_json_object(&state_path)?;
|
|
737
|
+
state.insert(
|
|
738
|
+
"hasCompletedOnboarding".to_string(),
|
|
739
|
+
serde_json::json!(true),
|
|
740
|
+
);
|
|
741
|
+
state.insert(
|
|
742
|
+
"hasTrustDialogAccepted".to_string(),
|
|
743
|
+
serde_json::json!(true),
|
|
744
|
+
);
|
|
745
|
+
insert_if_missing(
|
|
746
|
+
&mut state,
|
|
747
|
+
"projectOnboardingSeenCount",
|
|
748
|
+
serde_json::json!(1),
|
|
749
|
+
);
|
|
750
|
+
state.insert("mcpServers".to_string(), mcp_config.raw.clone());
|
|
751
|
+
state.insert(
|
|
752
|
+
"enabledMcpjsonServers".to_string(),
|
|
753
|
+
serde_json::json!(mcp_server_names(&mcp_config.raw)),
|
|
754
|
+
);
|
|
755
|
+
ensure_claude_projects(&mut state, workspace, Some(&mcp_config.raw));
|
|
756
|
+
write_json_object(&state_path, &state)
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
fn ensure_claude_projects(
|
|
760
|
+
state: &mut serde_json::Map<String, serde_json::Value>,
|
|
761
|
+
workspace: &Path,
|
|
762
|
+
mcp_servers: Option<&serde_json::Value>,
|
|
763
|
+
) {
|
|
764
|
+
if !state
|
|
765
|
+
.get("projects")
|
|
766
|
+
.is_some_and(serde_json::Value::is_object)
|
|
767
|
+
{
|
|
768
|
+
state.insert("projects".to_string(), serde_json::json!({}));
|
|
769
|
+
}
|
|
770
|
+
let Some(projects) = state
|
|
771
|
+
.get_mut("projects")
|
|
772
|
+
.and_then(serde_json::Value::as_object_mut)
|
|
773
|
+
else {
|
|
774
|
+
return;
|
|
775
|
+
};
|
|
776
|
+
for key in claude_project_keys(workspace) {
|
|
777
|
+
let entry = projects.entry(key).or_insert_with(|| serde_json::json!({}));
|
|
778
|
+
if !entry.is_object() {
|
|
779
|
+
*entry = serde_json::json!({});
|
|
780
|
+
}
|
|
781
|
+
let Some(project) = entry.as_object_mut() else {
|
|
782
|
+
continue;
|
|
783
|
+
};
|
|
784
|
+
project.insert(
|
|
785
|
+
"hasTrustDialogAccepted".to_string(),
|
|
786
|
+
serde_json::json!(true),
|
|
787
|
+
);
|
|
788
|
+
insert_if_missing(project, "projectOnboardingSeenCount", serde_json::json!(1));
|
|
789
|
+
if let Some(mcp_servers) = mcp_servers {
|
|
790
|
+
insert_if_missing(project, "allowedTools", serde_json::json!([]));
|
|
791
|
+
insert_if_missing(project, "mcpContextUris", serde_json::json!([]));
|
|
792
|
+
project.insert(
|
|
793
|
+
"enabledMcpjsonServers".to_string(),
|
|
794
|
+
serde_json::json!(mcp_server_names(mcp_servers)),
|
|
795
|
+
);
|
|
796
|
+
insert_if_missing(project, "disabledMcpjsonServers", serde_json::json!([]));
|
|
797
|
+
insert_if_missing(
|
|
798
|
+
project,
|
|
799
|
+
"hasClaudeMdExternalIncludesApproved",
|
|
800
|
+
serde_json::json!(false),
|
|
801
|
+
);
|
|
802
|
+
insert_if_missing(
|
|
803
|
+
project,
|
|
804
|
+
"hasClaudeMdExternalIncludesWarningShown",
|
|
805
|
+
serde_json::json!(false),
|
|
806
|
+
);
|
|
807
|
+
if !project
|
|
808
|
+
.get("mcpServers")
|
|
809
|
+
.is_some_and(serde_json::Value::is_object)
|
|
810
|
+
{
|
|
811
|
+
project.insert("mcpServers".to_string(), serde_json::json!({}));
|
|
812
|
+
}
|
|
813
|
+
if let Some(existing) = project
|
|
814
|
+
.get_mut("mcpServers")
|
|
815
|
+
.and_then(serde_json::Value::as_object_mut)
|
|
816
|
+
{
|
|
817
|
+
if let Some(servers) = mcp_servers.as_object() {
|
|
818
|
+
existing.extend(servers.clone());
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
fn mcp_server_names(mcp_servers: &serde_json::Value) -> Vec<String> {
|
|
826
|
+
mcp_servers
|
|
827
|
+
.as_object()
|
|
828
|
+
.map(|servers| servers.keys().cloned().collect())
|
|
829
|
+
.unwrap_or_default()
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
/// swallow batch 4 C1-C4 (MUST-NOT-9/13): a CORRUPT provider-config JSON fails
|
|
833
|
+
/// EXPLICITLY — the old `unwrap_or_default` turned a parse failure into an empty map
|
|
834
|
+
/// that the subsequent write flattened back over the user's file (silent destructive
|
|
835
|
+
/// rewrite). A missing file stays Ok(empty) — only an existing-but-unparseable file
|
|
836
|
+
/// errors, naming the path + parse detail + next action; the file is never touched.
|
|
837
|
+
fn read_json_object(
|
|
838
|
+
path: &Path,
|
|
839
|
+
) -> Result<serde_json::Map<String, serde_json::Value>, LifecycleError> {
|
|
840
|
+
let text = match std::fs::read_to_string(path) {
|
|
841
|
+
Ok(text) => text,
|
|
842
|
+
Err(error) if error.kind() == std::io::ErrorKind::NotFound => {
|
|
843
|
+
return Ok(serde_json::Map::new());
|
|
844
|
+
}
|
|
845
|
+
Err(error) => {
|
|
846
|
+
return Err(LifecycleError::RequirementUnmet(format!(
|
|
847
|
+
"profile_invalid_json: {} could not be read: {error}; fix or remove the file (or restore a backup) and relaunch",
|
|
848
|
+
path.display()
|
|
849
|
+
)));
|
|
850
|
+
}
|
|
851
|
+
};
|
|
852
|
+
match serde_json::from_str::<serde_json::Value>(&text) {
|
|
853
|
+
Ok(serde_json::Value::Object(map)) => Ok(map),
|
|
854
|
+
Ok(other) => Err(LifecycleError::RequirementUnmet(format!(
|
|
855
|
+
"profile_invalid_json: {} is not a JSON object (found {}); fix or remove the file (or restore a backup) and relaunch",
|
|
856
|
+
path.display(),
|
|
857
|
+
json_kind(&other)
|
|
858
|
+
))),
|
|
859
|
+
Err(error) => Err(LifecycleError::RequirementUnmet(format!(
|
|
860
|
+
"profile_invalid_json: {} could not be parsed: {error}; fix or remove the file (or restore a backup) and relaunch",
|
|
861
|
+
path.display()
|
|
862
|
+
))),
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
fn json_kind(value: &serde_json::Value) -> &'static str {
|
|
867
|
+
match value {
|
|
868
|
+
serde_json::Value::Null => "null",
|
|
869
|
+
serde_json::Value::Bool(_) => "a boolean",
|
|
870
|
+
serde_json::Value::Number(_) => "a number",
|
|
871
|
+
serde_json::Value::String(_) => "a string",
|
|
872
|
+
serde_json::Value::Array(_) => "an array",
|
|
873
|
+
serde_json::Value::Object(_) => "an object",
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
fn write_json_object(
|
|
878
|
+
path: &Path,
|
|
879
|
+
value: &serde_json::Map<String, serde_json::Value>,
|
|
880
|
+
) -> Result<(), LifecycleError> {
|
|
881
|
+
if let Some(parent) = path.parent() {
|
|
882
|
+
std::fs::create_dir_all(parent)
|
|
883
|
+
.map_err(|e| LifecycleError::StatePersist(format!("{}: {e}", parent.display())))?;
|
|
884
|
+
}
|
|
885
|
+
let body = serde_json::to_string_pretty(value)
|
|
886
|
+
.map_err(|e| LifecycleError::StatePersist(format!("serialize {}: {e}", path.display())))?;
|
|
887
|
+
std::fs::write(path, format!("{body}\n"))
|
|
888
|
+
.map_err(|e| LifecycleError::StatePersist(format!("{}: {e}", path.display())))?;
|
|
889
|
+
set_owner_only_permissions(path)
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
fn insert_if_missing(
|
|
893
|
+
map: &mut serde_json::Map<String, serde_json::Value>,
|
|
894
|
+
key: &str,
|
|
895
|
+
value: serde_json::Value,
|
|
896
|
+
) {
|
|
897
|
+
map.entry(key.to_string()).or_insert(value);
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
fn claude_project_keys(workspace: &Path) -> Vec<String> {
|
|
901
|
+
let mut keys = vec![workspace.to_string_lossy().to_string()];
|
|
902
|
+
if let Ok(resolved) = workspace.canonicalize() {
|
|
903
|
+
let resolved = resolved.to_string_lossy().to_string();
|
|
904
|
+
if !keys.iter().any(|key| key == &resolved) {
|
|
905
|
+
keys.push(resolved);
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
for key in keys.clone() {
|
|
909
|
+
if let Some(stripped) = key.strip_prefix("/private/var/") {
|
|
910
|
+
push_unique_string(&mut keys, format!("/var/{stripped}"));
|
|
911
|
+
} else if let Some(stripped) = key.strip_prefix("/var/") {
|
|
912
|
+
push_unique_string(&mut keys, format!("/private/var/{stripped}"));
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
keys
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
fn push_unique_string(values: &mut Vec<String>, value: String) {
|
|
919
|
+
if !values.iter().any(|existing| existing == &value) {
|
|
920
|
+
values.push(value);
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
|
|
620
924
|
fn compatible_api_network_exports(
|
|
621
925
|
auth_mode: AuthMode,
|
|
622
926
|
values: &BTreeMap<String, String>,
|
|
@@ -654,12 +958,18 @@ fn required_profile_keys(provider: Provider, auth_mode: AuthMode) -> &'static [&
|
|
|
654
958
|
return &[];
|
|
655
959
|
}
|
|
656
960
|
match provider {
|
|
961
|
+
Provider::Claude | Provider::ClaudeCode => match auth_mode {
|
|
962
|
+
AuthMode::OfficialApi => &["API_KEY"],
|
|
963
|
+
AuthMode::CompatibleApi => &["BASE_URL", "API_KEY"],
|
|
964
|
+
AuthMode::Subscription => &[],
|
|
965
|
+
},
|
|
657
966
|
Provider::GeminiCli => &["API_KEY"],
|
|
658
967
|
// C-7-1 cr verdict: copilot 一期 subscription-only,无 BYOK required key 集合;
|
|
659
968
|
// 二期 BYOK 立项时填(向后兼容字段保留)。
|
|
660
969
|
Provider::Copilot => &[],
|
|
661
|
-
//
|
|
662
|
-
|
|
970
|
+
// Codex/Grok worker 只走 subscription-only contract leaf;Pi 一期无 BYOK
|
|
971
|
+
// required key 集合 (同 copilot 精神)。
|
|
972
|
+
Provider::Codex | Provider::Grok | Provider::Pi => &[],
|
|
663
973
|
Provider::Fake => &[],
|
|
664
974
|
}
|
|
665
975
|
}
|
|
@@ -1468,6 +1468,7 @@ pub(super) fn mark_agent_started(
|
|
|
1468
1468
|
agent.remove("startup_prompts");
|
|
1469
1469
|
agent.remove("startup_prompt_status");
|
|
1470
1470
|
agent.remove("startup_prompt_probe_epoch");
|
|
1471
|
+
agent.remove(crate::lifecycle::launch::add_agent_state::FORK_PARENT_SESSION_ID);
|
|
1471
1472
|
agent.remove("startup_prompt_probe_disabled_at");
|
|
1472
1473
|
Ok(())
|
|
1473
1474
|
}
|