@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
|
@@ -19,6 +19,8 @@ team-agent doctor --workspace . --json
|
|
|
19
19
|
team-agent inbox leader --workspace . --team project-team -n 3
|
|
20
20
|
team-agent models --provider NAME
|
|
21
21
|
team-agent models --provider claude
|
|
22
|
+
team-agent models --provider codex
|
|
23
|
+
team-agent models --provider grok
|
|
22
24
|
team-agent models --provider pi
|
|
23
25
|
team-agent profile init my-api --auth-mode compatible_api --workspace .
|
|
24
26
|
team-agent restart reviewer --workspace . --team project-team
|
|
@@ -35,7 +37,7 @@ team-agent start --from ./my-team --workspace . --team project-team
|
|
|
35
37
|
team-agent start --from .team/current --workspace . --team project-team
|
|
36
38
|
team-agent start --help
|
|
37
39
|
team-agent start --workspace . --team project-team
|
|
38
|
-
team-agent start analyst --provider pi --
|
|
40
|
+
team-agent start analyst --provider pi --bypass false --prompt "Analyze the proposed change"
|
|
39
41
|
team-agent start auditor --role-file /absolute/path/to/auditor.md
|
|
40
42
|
team-agent start reviewer --effort high --bypass false
|
|
41
43
|
team-agent start reviewer --effort high --bypass false --workspace . --team project-team
|
|
@@ -142,7 +144,7 @@ Creation needs complete configuration; start is not automatic template generatio
|
|
|
142
144
|
|
|
143
145
|
Do not silently pick provider, model, effort or bypass. False preserves native permissions; it is not a read-only or sandbox guarantee. Use supported `models --provider NAME` discovery and retain exact model IDs.
|
|
144
146
|
|
|
145
|
-
Traditional minimal Markdown remains accepted by the original compiler. Its compatibility interpretation is **not a default for a new user plan**: provider defaults to Pi, bypass to false, and unset effort
|
|
147
|
+
Traditional minimal Markdown remains accepted by the original compiler. Its compatibility interpretation is **not a default for a new user plan**: provider defaults to Pi, bypass to false, and unset model/effort are left to the provider. Codex and Grok workers run only through their contract leaves, which require an exact model ID from `team-agent models --provider codex|grok`; an unset model is refused, never guessed. Team Agent does not infer a role model from TEAM defaults. Contract leaves use only an explicit role effort; legacy explicit TEAM provider_effort remains supported for non-Pi legacy roles (Claude, Copilot, Gemini); do not invent an effort for unspecified roles.
|
|
146
148
|
|
|
147
149
|
Supported role metadata:
|
|
148
150
|
- `agent_id` (legacy `name`) and `role` identify the seat.
|
|
@@ -157,7 +159,7 @@ A RoleOnly seat can be registered from its complete role file. A genuinely absen
|
|
|
157
159
|
|
|
158
160
|
```sh
|
|
159
161
|
team-agent start auditor --role-file /absolute/path/to/auditor.md
|
|
160
|
-
team-agent start analyst --provider pi --
|
|
162
|
+
team-agent start analyst --provider pi --bypass false --prompt "Analyze the proposed change"
|
|
161
163
|
```
|
|
162
164
|
|
|
163
165
|
An imported external role goes into this team's `agents/ID.md`; the original stays untouched. A file already at that destination is used in place. Equal file/CLI definitions are accepted; conflicting provider/model/effort/bypass/prompt/profile values refuse before writes/startup. Omitted model, effort, profile and role body remain unchanged.
|
|
@@ -19,6 +19,8 @@ team-agent doctor --workspace . --json
|
|
|
19
19
|
team-agent inbox leader --workspace . --team project-team -n 3
|
|
20
20
|
team-agent models --provider NAME
|
|
21
21
|
team-agent models --provider claude
|
|
22
|
+
team-agent models --provider codex
|
|
23
|
+
team-agent models --provider grok
|
|
22
24
|
team-agent models --provider pi
|
|
23
25
|
team-agent profile init my-api --auth-mode compatible_api --workspace .
|
|
24
26
|
team-agent restart reviewer --workspace . --team project-team
|
|
@@ -35,7 +37,7 @@ team-agent start --from ./my-team --workspace . --team project-team
|
|
|
35
37
|
team-agent start --from .team/current --workspace . --team project-team
|
|
36
38
|
team-agent start --help
|
|
37
39
|
team-agent start --workspace . --team project-team
|
|
38
|
-
team-agent start analyst --provider pi --
|
|
40
|
+
team-agent start analyst --provider pi --bypass false --prompt "Analyze the proposed change"
|
|
39
41
|
team-agent start auditor --role-file /absolute/path/to/auditor.md
|
|
40
42
|
team-agent start reviewer --effort high --bypass false
|
|
41
43
|
team-agent start reviewer --effort high --bypass false --workspace . --team project-team
|
|
@@ -142,7 +144,7 @@ Creation needs complete configuration; start is not automatic template generatio
|
|
|
142
144
|
|
|
143
145
|
Do not silently pick provider, model, effort or bypass. False preserves native permissions; it is not a read-only or sandbox guarantee. Use supported `models --provider NAME` discovery and retain exact model IDs.
|
|
144
146
|
|
|
145
|
-
Traditional minimal Markdown remains accepted by the original compiler. Its compatibility interpretation is **not a default for a new user plan**: provider defaults to Pi, bypass to false, and unset effort
|
|
147
|
+
Traditional minimal Markdown remains accepted by the original compiler. Its compatibility interpretation is **not a default for a new user plan**: provider defaults to Pi, bypass to false, and unset model/effort are left to the provider. Codex and Grok workers run only through their contract leaves, which require an exact model ID from `team-agent models --provider codex|grok`; an unset model is refused, never guessed. Team Agent does not infer a role model from TEAM defaults. Contract leaves use only an explicit role effort; legacy explicit TEAM provider_effort remains supported for non-Pi legacy roles (Claude, Copilot, Gemini); do not invent an effort for unspecified roles.
|
|
146
148
|
|
|
147
149
|
Supported role metadata:
|
|
148
150
|
- `agent_id` (legacy `name`) and `role` identify the seat.
|
|
@@ -157,7 +159,7 @@ A RoleOnly seat can be registered from its complete role file. A genuinely absen
|
|
|
157
159
|
|
|
158
160
|
```sh
|
|
159
161
|
team-agent start auditor --role-file /absolute/path/to/auditor.md
|
|
160
|
-
team-agent start analyst --provider pi --
|
|
162
|
+
team-agent start analyst --provider pi --bypass false --prompt "Analyze the proposed change"
|
|
161
163
|
```
|
|
162
164
|
|
|
163
165
|
An imported external role goes into this team's `agents/ID.md`; the original stays untouched. A file already at that destination is used in place. Equal file/CLI definitions are accepted; conflicting provider/model/effort/bypass/prompt/profile values refuse before writes/startup. Omitted model, effort, profile and role body remain unchanged.
|
|
@@ -1,260 +0,0 @@
|
|
|
1
|
-
//! ---
|
|
2
|
-
//! purpose: 判定 .grok/config.toml env 里哪些键是每席私有
|
|
3
|
-
//! contract:
|
|
4
|
-
//! provides:
|
|
5
|
-
//! - name: is_per_seat_env_key
|
|
6
|
-
//! what: TEAM_AGENT_* 除 WORKSPACE 外都是每席键
|
|
7
|
-
//! - name: per_seat_keys_in_toml
|
|
8
|
-
//! what: 扫描 toml env 表里的每席键
|
|
9
|
-
//! - name: strip_per_seat_keys_from_toml
|
|
10
|
-
//! what: 从任意 .env 表删掉每席键,留下非框架键
|
|
11
|
-
//! - name: non_per_seat_env_in_tables
|
|
12
|
-
//! what: 从指定表的 .env 取出非每席键(值原样),供 overlay 保留
|
|
13
|
-
//! boundary:
|
|
14
|
-
//! - 不写盘
|
|
15
|
-
//! - 不数 grok 席位个数
|
|
16
|
-
//! - 剥离结果只含键名,不含键值
|
|
17
|
-
//! maturity: wired
|
|
18
|
-
//! ---
|
|
19
|
-
|
|
20
|
-
/// ---
|
|
21
|
-
/// purpose: 判断某环境键是否属于每席私有
|
|
22
|
-
/// returns: 以 TEAM_AGENT_ 起头且不是 TEAM_AGENT_WORKSPACE 时为 true
|
|
23
|
-
/// ---
|
|
24
|
-
/// Shared identity keys belong on pane env. The only TEAM_AGENT_* key
|
|
25
|
-
/// allowed in the directory-scoped grok toml is WORKSPACE (same cwd).
|
|
26
|
-
pub(crate) fn is_per_seat_env_key(key: &str) -> bool {
|
|
27
|
-
let key = key.trim();
|
|
28
|
-
key.starts_with("TEAM_AGENT_") && key != "TEAM_AGENT_WORKSPACE"
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/// ---
|
|
32
|
-
/// purpose: 扫出 toml 里所有 env 表中的每席键
|
|
33
|
-
/// returns: 首次出现顺序的键值对,值已去掉引号
|
|
34
|
-
/// ---
|
|
35
|
-
pub(crate) fn per_seat_keys_in_toml(text: &str) -> Vec<(String, String)> {
|
|
36
|
-
let mut in_env_table = false;
|
|
37
|
-
let mut out = Vec::new();
|
|
38
|
-
for line in text.lines() {
|
|
39
|
-
let trimmed = line.trim();
|
|
40
|
-
if trimmed.starts_with('[') && trimmed.ends_with(']') {
|
|
41
|
-
let name = &trimmed[1..trimmed.len() - 1];
|
|
42
|
-
in_env_table = name.ends_with(".env");
|
|
43
|
-
continue;
|
|
44
|
-
}
|
|
45
|
-
if !in_env_table {
|
|
46
|
-
continue;
|
|
47
|
-
}
|
|
48
|
-
let Some((key, rest)) = trimmed.split_once('=') else {
|
|
49
|
-
continue;
|
|
50
|
-
};
|
|
51
|
-
let key = key.trim();
|
|
52
|
-
if !is_per_seat_env_key(key) {
|
|
53
|
-
continue;
|
|
54
|
-
}
|
|
55
|
-
let rest = rest.trim();
|
|
56
|
-
let value = rest
|
|
57
|
-
.strip_prefix('"')
|
|
58
|
-
.and_then(|s| s.strip_suffix('"'))
|
|
59
|
-
.or_else(|| rest.strip_prefix('\'').and_then(|s| s.strip_suffix('\'')))
|
|
60
|
-
.unwrap_or(rest);
|
|
61
|
-
if out.iter().any(|(existing, _)| existing == key) {
|
|
62
|
-
continue;
|
|
63
|
-
}
|
|
64
|
-
out.push((key.to_string(), value.to_string()));
|
|
65
|
-
}
|
|
66
|
-
out
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/// ---
|
|
70
|
-
/// purpose: 从所有 env 表里删掉每席键
|
|
71
|
-
/// returns: 删后的全文,以及被删键名的首次出现顺序列表,不含值
|
|
72
|
-
/// ---
|
|
73
|
-
/// Drop per-seat `TEAM_AGENT_*` assignments from any `*.env` table.
|
|
74
|
-
/// Other keys (`TEAM_AGENT_WORKSPACE`, `GROK_FOLDER_TRUST`, user keys) stay.
|
|
75
|
-
/// Returned names are first-seen order, values never included.
|
|
76
|
-
pub(crate) fn strip_per_seat_keys_from_toml(text: &str) -> (String, Vec<String>) {
|
|
77
|
-
let mut in_env_table = false;
|
|
78
|
-
let mut out = String::new();
|
|
79
|
-
let mut removed = Vec::new();
|
|
80
|
-
for line in text.lines() {
|
|
81
|
-
let trimmed = line.trim();
|
|
82
|
-
if trimmed.starts_with('[') && trimmed.ends_with(']') {
|
|
83
|
-
let name = &trimmed[1..trimmed.len() - 1];
|
|
84
|
-
in_env_table = name.ends_with(".env");
|
|
85
|
-
out.push_str(line);
|
|
86
|
-
out.push('\n');
|
|
87
|
-
continue;
|
|
88
|
-
}
|
|
89
|
-
if in_env_table {
|
|
90
|
-
if let Some((key, _)) = trimmed.split_once('=') {
|
|
91
|
-
let key = key.trim();
|
|
92
|
-
if is_per_seat_env_key(key) {
|
|
93
|
-
if !removed.iter().any(|existing| existing == key) {
|
|
94
|
-
removed.push(key.to_string());
|
|
95
|
-
}
|
|
96
|
-
continue;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
out.push_str(line);
|
|
101
|
-
out.push('\n');
|
|
102
|
-
}
|
|
103
|
-
(out, removed)
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
fn toml_env_value(rest: &str) -> String {
|
|
107
|
-
let rest = rest.trim();
|
|
108
|
-
rest.strip_prefix('"')
|
|
109
|
-
.and_then(|s| s.strip_suffix('"'))
|
|
110
|
-
.or_else(|| rest.strip_prefix('\'').and_then(|s| s.strip_suffix('\'')))
|
|
111
|
-
.unwrap_or(rest)
|
|
112
|
-
.to_string()
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/// ---
|
|
116
|
-
/// purpose: 取出指定表的 env 段里非每席的键值
|
|
117
|
-
/// params:
|
|
118
|
-
/// tables: 目标表名前缀,只看这些表下的 env 段
|
|
119
|
-
/// returns: 键到值的有序映射,供覆盖写入时保留用户键
|
|
120
|
-
/// ---
|
|
121
|
-
/// Keys in `tables*.env` that are **not** per-seat. Unknown keys must be
|
|
122
|
-
/// kept — detection failure does not authorize deletion.
|
|
123
|
-
pub(crate) fn non_per_seat_env_in_tables(
|
|
124
|
-
text: &str,
|
|
125
|
-
tables: &[&str],
|
|
126
|
-
) -> std::collections::BTreeMap<String, String> {
|
|
127
|
-
let mut in_target_env = false;
|
|
128
|
-
let mut out = std::collections::BTreeMap::new();
|
|
129
|
-
for line in text.lines() {
|
|
130
|
-
let trimmed = line.trim();
|
|
131
|
-
if trimmed.starts_with('[') && trimmed.ends_with(']') {
|
|
132
|
-
let name = &trimmed[1..trimmed.len() - 1];
|
|
133
|
-
in_target_env = name.ends_with(".env")
|
|
134
|
-
&& tables
|
|
135
|
-
.iter()
|
|
136
|
-
.any(|table| name == *table || name.starts_with(&format!("{table}.")));
|
|
137
|
-
continue;
|
|
138
|
-
}
|
|
139
|
-
if !in_target_env {
|
|
140
|
-
continue;
|
|
141
|
-
}
|
|
142
|
-
let Some((key, rest)) = trimmed.split_once('=') else {
|
|
143
|
-
continue;
|
|
144
|
-
};
|
|
145
|
-
let key = key.trim();
|
|
146
|
-
if key.is_empty() || is_per_seat_env_key(key) {
|
|
147
|
-
continue;
|
|
148
|
-
}
|
|
149
|
-
out.entry(key.to_string())
|
|
150
|
-
.or_insert_with(|| toml_env_value(rest));
|
|
151
|
-
}
|
|
152
|
-
out
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
#[cfg(test)]
|
|
156
|
-
mod tests {
|
|
157
|
-
use super::*;
|
|
158
|
-
|
|
159
|
-
#[test]
|
|
160
|
-
fn workspace_is_shared_other_team_agent_keys_are_per_seat() {
|
|
161
|
-
assert!(!is_per_seat_env_key("TEAM_AGENT_WORKSPACE"));
|
|
162
|
-
assert!(is_per_seat_env_key("TEAM_AGENT_ID"));
|
|
163
|
-
assert!(is_per_seat_env_key("TEAM_AGENT_OWNER_TEAM_ID"));
|
|
164
|
-
assert!(is_per_seat_env_key("TEAM_AGENT_AUTH_MODE"));
|
|
165
|
-
assert!(is_per_seat_env_key("TEAM_AGENT_FUTURE_SEAT_KEY"));
|
|
166
|
-
assert!(!is_per_seat_env_key("GROK_FOLDER_TRUST"));
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
#[test]
|
|
170
|
-
fn scan_finds_per_seat_keys_in_env_table_only() {
|
|
171
|
-
let text = r#"
|
|
172
|
-
[mcp_servers.other.env]
|
|
173
|
-
TEAM_AGENT_ID = "ignore-other-server-still-counts"
|
|
174
|
-
|
|
175
|
-
[mcp_servers.team_orchestrator]
|
|
176
|
-
command = "/bin/x"
|
|
177
|
-
|
|
178
|
-
[mcp_servers.team_orchestrator.env]
|
|
179
|
-
TEAM_AGENT_WORKSPACE = "/ws"
|
|
180
|
-
TEAM_AGENT_AUTH_MODE = "impostor"
|
|
181
|
-
"#;
|
|
182
|
-
let keys = per_seat_keys_in_toml(text);
|
|
183
|
-
assert!(
|
|
184
|
-
keys.iter()
|
|
185
|
-
.any(|(k, v)| k == "TEAM_AGENT_AUTH_MODE" && v == "impostor"),
|
|
186
|
-
"must see AUTH; keys={keys:?}"
|
|
187
|
-
);
|
|
188
|
-
assert!(
|
|
189
|
-
keys.iter().any(|(k, _)| k == "TEAM_AGENT_ID"),
|
|
190
|
-
"any env table per-seat key counts; keys={keys:?}"
|
|
191
|
-
);
|
|
192
|
-
assert!(
|
|
193
|
-
!keys.iter().any(|(k, _)| k == "TEAM_AGENT_WORKSPACE"),
|
|
194
|
-
"WORKSPACE is shared; keys={keys:?}"
|
|
195
|
-
);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
#[test]
|
|
199
|
-
fn strip_drops_only_per_seat_keys_and_returns_names() {
|
|
200
|
-
let text = r#"
|
|
201
|
-
[mcp_servers.keep.env]
|
|
202
|
-
GROK_FOLDER_TRUST = "1"
|
|
203
|
-
TEAM_AGENT_ID = "impostor"
|
|
204
|
-
TEAM_AGENT_WORKSPACE = "/ws"
|
|
205
|
-
|
|
206
|
-
[mcp_servers.keep]
|
|
207
|
-
command = "/bin/keep"
|
|
208
|
-
|
|
209
|
-
[other]
|
|
210
|
-
TEAM_AGENT_AUTH_MODE = "not-in-env-table"
|
|
211
|
-
"#;
|
|
212
|
-
let (cleaned, removed) = strip_per_seat_keys_from_toml(text);
|
|
213
|
-
assert_eq!(removed, vec!["TEAM_AGENT_ID".to_string()]);
|
|
214
|
-
assert!(
|
|
215
|
-
!cleaned.contains("TEAM_AGENT_ID"),
|
|
216
|
-
"per-seat key must leave the env table; cleaned={cleaned}"
|
|
217
|
-
);
|
|
218
|
-
assert!(
|
|
219
|
-
cleaned.contains("GROK_FOLDER_TRUST = \"1\"")
|
|
220
|
-
&& cleaned.contains("TEAM_AGENT_WORKSPACE = \"/ws\"")
|
|
221
|
-
&& cleaned.contains("TEAM_AGENT_AUTH_MODE = \"not-in-env-table\"")
|
|
222
|
-
&& cleaned.contains("command = \"/bin/keep\""),
|
|
223
|
-
"non-per-seat keys and non-env tables stay; cleaned={cleaned}"
|
|
224
|
-
);
|
|
225
|
-
assert!(
|
|
226
|
-
!cleaned.contains("impostor"),
|
|
227
|
-
"stripped values must not be rewritten; cleaned={cleaned}"
|
|
228
|
-
);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
#[test]
|
|
232
|
-
fn non_per_seat_scan_keeps_unknown_keys_from_named_tables_only() {
|
|
233
|
-
let text = r#"
|
|
234
|
-
[mcp_servers.keep-me.env]
|
|
235
|
-
GROK_FOLDER_TRUST = "other-table"
|
|
236
|
-
|
|
237
|
-
[mcp_servers.team_orchestrator.env]
|
|
238
|
-
TEAM_AGENT_ID = "stale"
|
|
239
|
-
GROK_FOLDER_TRUST = "1"
|
|
240
|
-
TEAM_AGENT_WORKSPACE = "/ws"
|
|
241
|
-
USER_EXTRA = "keep"
|
|
242
|
-
"#;
|
|
243
|
-
let kept = non_per_seat_env_in_tables(text, &["mcp_servers.team_orchestrator"]);
|
|
244
|
-
assert_eq!(kept.get("GROK_FOLDER_TRUST").map(String::as_str), Some("1"));
|
|
245
|
-
assert_eq!(kept.get("USER_EXTRA").map(String::as_str), Some("keep"));
|
|
246
|
-
assert_eq!(
|
|
247
|
-
kept.get("TEAM_AGENT_WORKSPACE").map(String::as_str),
|
|
248
|
-
Some("/ws")
|
|
249
|
-
);
|
|
250
|
-
assert!(
|
|
251
|
-
!kept.contains_key("TEAM_AGENT_ID"),
|
|
252
|
-
"per-seat keys are not preserved; kept={kept:?}"
|
|
253
|
-
);
|
|
254
|
-
assert_ne!(
|
|
255
|
-
kept.get("GROK_FOLDER_TRUST").map(String::as_str),
|
|
256
|
-
Some("other-table"),
|
|
257
|
-
"only the named table is read; kept={kept:?}"
|
|
258
|
-
);
|
|
259
|
-
}
|
|
260
|
-
}
|