@team-agent/installer 0.5.124 → 0.5.125
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 -1
- package/crates/team-agent/src/cli/emit.rs +41 -15
- package/crates/team-agent/src/cli/intent/runtime.rs +5 -53
- package/crates/team-agent/src/cli/intent/runtime_tests.rs +0 -120
- 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 +6 -5
- package/crates/team-agent/src/cli/models.rs +40 -119
- 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/status_send.rs +17 -0
- package/crates/team-agent/src/compiler/tests.rs +21 -5
- package/crates/team-agent/src/compiler.rs +24 -1
- package/crates/team-agent/src/contract_runtime/backend.rs +22 -6
- package/crates/team-agent/src/contract_runtime/config.rs +34 -24
- package/crates/team-agent/src/contract_runtime/discovery.rs +33 -0
- package/crates/team-agent/src/contract_runtime/framework.rs +89 -34
- package/crates/team-agent/src/contract_runtime/registry.rs +258 -21
- package/crates/team-agent/src/coordinator/runtime_detectors.rs +0 -1
- 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 +0 -1
- 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 +14 -1
- package/crates/team-agent/src/lifecycle/launch/agent_state.rs +0 -9
- package/crates/team-agent/src/lifecycle/launch/fork_agent.rs +0 -1
- package/crates/team-agent/src/lifecycle/launch/mcp_config.rs +2 -2
- package/crates/team-agent/src/lifecycle/launch/spawn.rs +0 -28
- 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 -20
- package/crates/team-agent/src/lifecycle/profile_launch.rs +11 -39
- package/crates/team-agent/src/lifecycle/profile_smoke.rs +1 -2
- package/crates/team-agent/src/lifecycle/restart/common.rs +1 -63
- package/crates/team-agent/src/lifecycle/role_config.rs +42 -3
- package/crates/team-agent/src/lifecycle/tests/cli_argv_routing_red.rs +38 -7
- package/crates/team-agent/src/lifecycle/tests/clone_fork_copilot_perms_red.rs +6 -2
- package/crates/team-agent/src/lifecycle/tests/restart_rebind_hotfix_252_red.rs +0 -1
- package/crates/team-agent/src/lifecycle/tests/worker_spawn_env_red.rs +0 -137
- package/crates/team-agent/src/lifecycle/tests.rs +0 -3
- 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 +181 -35
- package/crates/team-agent/src/messaging/delivery_consumption_tests.rs +4 -4
- 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 +66 -4
- package/crates/team-agent/src/messaging/tests/runtime.rs +110 -4
- package/crates/team-agent/src/messaging/tests/spine.rs +22 -6
- package/crates/team-agent/src/model/enums.rs +1 -8
- package/crates/team-agent/src/provider/adapter.rs +1 -67
- package/crates/team-agent/src/provider/adapters/mod.rs +0 -1
- 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 +2 -73
- package/crates/team-agent/src/provider/session/capture.rs +1 -1
- package/crates/team-agent/src/provider/session/context_fork.rs +4 -4
- package/crates/team-agent/src/provider/session_scan/common.rs +1 -2
- package/crates/team-agent/src/provider/session_scan.rs +0 -4
- package/crates/team-agent/src/provider/submit_now.rs +5 -28
- package/crates/team-agent/src/provider/tests/adapter.rs +5 -184
- package/crates/team-agent/src/provider/tests/classify.rs +53 -0
- package/crates/team-agent/src/provider/tests/command_helpers.rs +1 -4
- package/crates/team-agent/src/provider/types.rs +1 -1
- package/crates/team-agent/src/provider/wire.rs +48 -8
- 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 +1 -1
- 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/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/provider/adapters/cursor_agent.rs +0 -44
- 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
|
@@ -99,25 +99,26 @@ fn mode(meta: &Value, path: &Path) -> Result<Option<CommunicationMode>, ConfigEr
|
|
|
99
99
|
.transpose()
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
+
/// `contract_runtime` is an exact boolean; a bare shared key stays legacy.
|
|
103
|
+
fn opted_in(meta: &Value, path: &Path) -> Result<bool, ConfigError> {
|
|
104
|
+
match meta.get("contract_runtime") {
|
|
105
|
+
None => Ok(false),
|
|
106
|
+
Some(Value::Bool(value)) => Ok(*value),
|
|
107
|
+
_ => Err(invalid(path, "contract_runtime")),
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
102
111
|
/// A malformed explicit contract header cannot fall back to the default Pi worker.
|
|
103
112
|
fn malformed_contract_header(body: &str) -> bool {
|
|
104
113
|
body.strip_prefix("---\n").is_some_and(|header| {
|
|
105
|
-
header
|
|
114
|
+
let fields: Vec<(&str, &str)> = header
|
|
106
115
|
.lines()
|
|
107
116
|
.take_while(|line| *line != "---")
|
|
108
|
-
.
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
.split('#')
|
|
114
|
-
.next()
|
|
115
|
-
.unwrap_or("")
|
|
116
|
-
.trim()
|
|
117
|
-
.trim_matches(['\'', '"']),
|
|
118
|
-
)
|
|
119
|
-
})
|
|
120
|
-
})
|
|
117
|
+
.filter_map(|line| line.split_once(':'))
|
|
118
|
+
.map(|(key, value)| (key.trim(), value.split('#').next().unwrap_or("").trim().trim_matches(['\'', '"'])))
|
|
119
|
+
.collect();
|
|
120
|
+
let opted_in = fields.iter().any(|(key, value)| *key == "contract_runtime" && *value == "true");
|
|
121
|
+
opted_in || fields.iter().any(|(key, value)| *key == "provider" && super::registry::recognizes(value, false))
|
|
121
122
|
})
|
|
122
123
|
}
|
|
123
124
|
|
|
@@ -177,13 +178,19 @@ fn read_team_inner(
|
|
|
177
178
|
};
|
|
178
179
|
let (meta, body) = split_front_matter(&raw);
|
|
179
180
|
let normalized = raw.replace("\r\n", "\n").replace('\r', "\n");
|
|
180
|
-
|
|
181
|
+
// Only an unparsed header loses both keys; an omitted provider is the default `pi`.
|
|
182
|
+
if meta.get("provider").is_none()
|
|
183
|
+
&& meta.get("contract_runtime").is_none()
|
|
184
|
+
&& malformed_contract_header(&normalized)
|
|
185
|
+
{
|
|
181
186
|
return Err(invalid(&path, "front matter"));
|
|
182
187
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
188
|
+
let opted = opted_in(&meta, &path)?;
|
|
189
|
+
if opted
|
|
190
|
+
|| meta
|
|
191
|
+
.get("provider")
|
|
192
|
+
.and_then(Value::as_str)
|
|
193
|
+
.is_some_and(|provider| super::registry::recognizes(provider, false))
|
|
187
194
|
{
|
|
188
195
|
selected = true;
|
|
189
196
|
}
|
|
@@ -247,9 +254,15 @@ fn read_team_inner(
|
|
|
247
254
|
if !ids.insert(id.clone()) {
|
|
248
255
|
return Err(invalid(&source, "duplicate agent id"));
|
|
249
256
|
}
|
|
257
|
+
// `leader` is the framework's own forwarding route. A role of that name
|
|
258
|
+
// on either runtime would shadow it, so refuse before any seat spawns.
|
|
259
|
+
if id == "leader" {
|
|
260
|
+
return Err(invalid(&source, "reserved worker id"));
|
|
261
|
+
}
|
|
250
262
|
let provider = text(&meta, "provider", &source)?.unwrap_or_else(|| "pi".into());
|
|
251
|
-
let
|
|
252
|
-
|
|
263
|
+
let opted = opted_in(&meta, &source)?;
|
|
264
|
+
let registration = super::registry::declared(&provider, opted);
|
|
265
|
+
if registration.is_none() && (opted || super::registry::recognizes(&provider, false)) {
|
|
253
266
|
return Err(invalid(&source, "provider"));
|
|
254
267
|
}
|
|
255
268
|
let runtime = if registration.is_some() {
|
|
@@ -269,9 +282,6 @@ fn read_team_inner(
|
|
|
269
282
|
let provider =
|
|
270
283
|
ProviderId::new(registration.identity.id).map_err(|_| invalid(&source, "provider"))?;
|
|
271
284
|
let id = SeatId::new(id).map_err(|_| invalid(&source, "agent id"))?;
|
|
272
|
-
if id.as_str() == "leader" {
|
|
273
|
-
return Err(invalid(&source, "reserved worker id"));
|
|
274
|
-
}
|
|
275
285
|
if text(&meta, "auth_mode", &source)?.is_some_and(|value| value != "subscription")
|
|
276
286
|
|| text(&meta, "profile", &source)?.is_some()
|
|
277
287
|
{
|
|
@@ -4,8 +4,11 @@ use std::path::{Path, PathBuf};
|
|
|
4
4
|
use team_agent_contract::contract::{hooks::*, plan::CatalogObservation, types::*};
|
|
5
5
|
use team_agent_contract::host::{command::{PublicCommand, RealCommandRunner}, process::resolve_cwd};
|
|
6
6
|
use team_agent_contract::kiro::native as kiro;
|
|
7
|
+
use team_agent_contract::providers::claude::{catalog as claude_catalog, launcher as claude};
|
|
8
|
+
use team_agent_contract::providers::codex::{catalog as codex_catalog, launcher as codex};
|
|
7
9
|
use team_agent_contract::providers::cursor::native as cursor;
|
|
8
10
|
use team_agent_contract::providers::grok_build::native as grok;
|
|
11
|
+
use team_agent_contract::providers::pi::{catalog as pi_catalog, launcher as pi};
|
|
9
12
|
use thiserror::Error;
|
|
10
13
|
|
|
11
14
|
use super::registry::{self, NativeProvider, NativeRuntime};
|
|
@@ -22,6 +25,12 @@ pub enum DiscoveryError {
|
|
|
22
25
|
CursorProbe(#[from] cursor::ProbeError),
|
|
23
26
|
#[error("native Grok launcher probe failed: {0}")]
|
|
24
27
|
GrokProbe(#[from] grok::ProbeError),
|
|
28
|
+
#[error("native Codex launcher probe failed: {0}")]
|
|
29
|
+
CodexProbe(#[from] codex_catalog::ProbeError),
|
|
30
|
+
#[error("native Pi launcher probe failed: {0}")]
|
|
31
|
+
PiProbe(#[from] pi_catalog::ProbeError),
|
|
32
|
+
#[error("native Claude launcher probe failed: {0}")]
|
|
33
|
+
ClaudeProbe(#[from] claude_catalog::ProbeError),
|
|
25
34
|
#[error("native discovery contract: {0:?}")]
|
|
26
35
|
Contract(ContractError),
|
|
27
36
|
#[error("native model discovery: {0:?}")]
|
|
@@ -76,6 +85,9 @@ pub fn discover(provider: &ProviderId, workspace: &Path) -> Result<Discovery, Di
|
|
|
76
85
|
NativeProvider::Kiro => kiro::probe_launcher(&command, &mut RealCommandRunner::default(), bounds)?,
|
|
77
86
|
NativeProvider::Cursor => cursor::probe_launcher(&command, &mut RealCommandRunner::default(), bounds)?,
|
|
78
87
|
NativeProvider::GrokBuild => grok::probe_launcher(&command, &mut RealCommandRunner::default(), bounds)?,
|
|
88
|
+
NativeProvider::Codex => codex_catalog::probe_launcher(&command, &mut RealCommandRunner::default(), bounds)?,
|
|
89
|
+
NativeProvider::Pi => pi_catalog::probe_launcher(&command, &mut RealCommandRunner::default(), bounds)?,
|
|
90
|
+
NativeProvider::Claude => claude_catalog::probe_launcher(&command, &mut RealCommandRunner::default(), bounds)?,
|
|
79
91
|
};
|
|
80
92
|
let request = CatalogRequest {
|
|
81
93
|
provider: ProviderId::new(descriptor.identity.id).map_err(DiscoveryError::Contract)?,
|
|
@@ -110,6 +122,21 @@ pub fn discover(provider: &ProviderId, workspace: &Path) -> Result<Discovery, Di
|
|
|
110
122
|
.map_err(DiscoveryError::Contract)?;
|
|
111
123
|
catalog_hook.discover(&request, &mut host)
|
|
112
124
|
}
|
|
125
|
+
NativeProvider::Codex => {
|
|
126
|
+
let mut host = codex_catalog::NativeCatalog::new(request.clone(), RealCommandRunner::default())
|
|
127
|
+
.map_err(DiscoveryError::Contract)?;
|
|
128
|
+
catalog_hook.discover(&request, &mut host)
|
|
129
|
+
}
|
|
130
|
+
NativeProvider::Pi => {
|
|
131
|
+
let mut host = pi_catalog::NativeCatalog::new(request.clone(), RealCommandRunner::default())
|
|
132
|
+
.map_err(DiscoveryError::Contract)?;
|
|
133
|
+
catalog_hook.discover(&request, &mut host)
|
|
134
|
+
}
|
|
135
|
+
NativeProvider::Claude => {
|
|
136
|
+
let mut host = claude_catalog::NativeCatalog::new(request.clone(), RealCommandRunner::default())
|
|
137
|
+
.map_err(DiscoveryError::Contract)?;
|
|
138
|
+
catalog_hook.discover(&request, &mut host)
|
|
139
|
+
}
|
|
113
140
|
}.map_err(DiscoveryError::Catalog)?;
|
|
114
141
|
let result = Discovery { engine: command.entry.clone(), command, native, catalog, runtime: None };
|
|
115
142
|
validate_catalog(provider, &result).map_err(DiscoveryError::Contract)?;
|
|
@@ -131,6 +158,12 @@ pub(super) fn discover_runtime(provider: &ProviderId, workspace: &Path) -> Resul
|
|
|
131
158
|
cursor::probe_runtime(&discovery.command, &home()?, &mut RealCommandRunner::default(), bounds)?),
|
|
132
159
|
NativeProvider::GrokBuild => NativeRuntime::GrokBuild(
|
|
133
160
|
grok::probe_runtime(&discovery.command, &home()?, &mut RealCommandRunner::default(), bounds)?),
|
|
161
|
+
NativeProvider::Codex => NativeRuntime::Codex(
|
|
162
|
+
codex::probe_runtime(&discovery.command, &home()?, &mut RealCommandRunner::default(), bounds)?),
|
|
163
|
+
NativeProvider::Pi => NativeRuntime::Pi(
|
|
164
|
+
pi::probe_runtime(&discovery.command, &home()?, &mut RealCommandRunner::default(), bounds)?),
|
|
165
|
+
NativeProvider::Claude => NativeRuntime::Claude(
|
|
166
|
+
claude::probe_runtime(&discovery.command, &home()?, &mut RealCommandRunner::default(), bounds)?),
|
|
134
167
|
};
|
|
135
168
|
discovery.catalog = runtime.bind_catalog(&discovery.catalog).map_err(DiscoveryError::Contract)?;
|
|
136
169
|
discovery.engine = runtime.engine().clone();
|
|
@@ -54,15 +54,27 @@ pub fn require_legacy_lifecycle(
|
|
|
54
54
|
) else {
|
|
55
55
|
return Ok(());
|
|
56
56
|
};
|
|
57
|
+
let row = agent.and_then(|id| selected.state.get("agents").and_then(|agents| agents.get(id)));
|
|
58
|
+
// A pre-upgrade legacy Cursor seat has no engine left; only teardown is admitted.
|
|
59
|
+
let teardown = matches!(operation, "stop-agent" | "remove-agent");
|
|
60
|
+
if !teardown
|
|
61
|
+
&& row
|
|
62
|
+
.and_then(|row| row.get("provider"))
|
|
63
|
+
.and_then(Value::as_str)
|
|
64
|
+
.is_some_and(crate::provider::wire::is_retired_provider)
|
|
65
|
+
{
|
|
66
|
+
return Err(crate::cli::CliError::Runtime(
|
|
67
|
+
crate::provider::wire::RETIRED_PROVIDER_ERROR.into(),
|
|
68
|
+
));
|
|
69
|
+
}
|
|
57
70
|
let selected_native = match agent {
|
|
58
|
-
Some(
|
|
59
|
-
.state
|
|
60
|
-
.get("agents")
|
|
61
|
-
.and_then(|agents| agents.get(id))
|
|
62
|
-
.is_some_and(is_contract),
|
|
71
|
+
Some(_) => row.is_some_and(is_contract),
|
|
63
72
|
None => has_contract(&selected.state),
|
|
64
73
|
};
|
|
65
|
-
|
|
74
|
+
// A recorded legacy seat is torn down on its own runtime even when its role
|
|
75
|
+
// document now declares a contract leaf (`cursor_agent` before the upgrade).
|
|
76
|
+
let configured_native = !(teardown && row.is_some())
|
|
77
|
+
&& selected
|
|
66
78
|
.state
|
|
67
79
|
.get("team_dir")
|
|
68
80
|
.and_then(Value::as_str)
|
|
@@ -88,23 +100,28 @@ pub fn require_legacy_role(
|
|
|
88
100
|
path: Option<&Path>,
|
|
89
101
|
provider: Option<&str>,
|
|
90
102
|
) -> Result<(), crate::cli::CliError> {
|
|
91
|
-
|
|
92
|
-
.and_then(|path| std::fs::read_to_string(path).ok())
|
|
93
|
-
.and_then(|raw| {
|
|
94
|
-
crate::compiler::split_front_matter(&raw)
|
|
95
|
-
.0
|
|
96
|
-
.get("provider")
|
|
97
|
-
.and_then(crate::model::yaml::Value::as_str)
|
|
98
|
-
.map(str::to_owned)
|
|
99
|
-
});
|
|
100
|
-
if provider
|
|
101
|
-
.or(declared.as_deref())
|
|
102
|
-
.is_some_and(super::registry::recognizes)
|
|
103
|
-
{
|
|
103
|
+
if declares_contract(path, provider) {
|
|
104
104
|
return Err(crate::cli::CliError::Runtime("contract_capability_unverified: mutable contract-native role lifecycle is not admitted; use initial quick-start; no role file was changed".into()));
|
|
105
105
|
}
|
|
106
106
|
Ok(())
|
|
107
107
|
}
|
|
108
|
+
/// Whether a role document or CLI provider value selects a contract leaf.
|
|
109
|
+
pub fn declares_contract(path: Option<&Path>, provider: Option<&str>) -> bool {
|
|
110
|
+
let meta = path
|
|
111
|
+
.and_then(|path| std::fs::read_to_string(path).ok())
|
|
112
|
+
.map(|raw| crate::compiler::split_front_matter(&raw).0);
|
|
113
|
+
let declared = meta.as_ref().and_then(|meta| {
|
|
114
|
+
meta.get("provider")
|
|
115
|
+
.and_then(crate::model::yaml::Value::as_str)
|
|
116
|
+
.map(str::to_owned)
|
|
117
|
+
});
|
|
118
|
+
let opted_in = meta.as_ref().is_some_and(|meta| {
|
|
119
|
+
matches!(meta.get("contract_runtime"), Some(crate::model::yaml::Value::Bool(true)))
|
|
120
|
+
});
|
|
121
|
+
provider
|
|
122
|
+
.or(declared.as_deref())
|
|
123
|
+
.is_some_and(|provider| super::registry::recognizes(provider, opted_in))
|
|
124
|
+
}
|
|
108
125
|
pub fn team_config(
|
|
109
126
|
workspace: &Path,
|
|
110
127
|
directory: &Path,
|
|
@@ -132,21 +149,7 @@ pub fn start_role(
|
|
|
132
149
|
if directory.canonicalize()? != selected.team_dir.canonicalize()? {
|
|
133
150
|
return Err(error("native role source changed while acquiring lifecycle ownership".into()));
|
|
134
151
|
}
|
|
135
|
-
|
|
136
|
-
.map_err(|e| error(e.to_string()))?
|
|
137
|
-
.ok_or_else(|| error("contract role no longer configured".into()))?;
|
|
138
|
-
let role = config.roles.iter().find(|role| &role.id == seat)
|
|
139
|
-
.ok_or_else(|| error("contract role not found".into()))?;
|
|
140
|
-
let (_, record) = backend::start(&selected.run_workspace, &selected.team_key, role, &config.members)
|
|
141
|
-
.map_err(|e| error(e.to_string()))?;
|
|
142
|
-
if record.outcome != Outcome::Committed {
|
|
143
|
-
return Err(error(format!("native startup seat={id} operation={:?} phase={:?} outcome={:?}: {}",
|
|
144
|
-
record.id, record.phase, record.outcome, record.failure.unwrap_or_default())));
|
|
145
|
-
}
|
|
146
|
-
// Preserve each committed seat before a later discovery/spawn can fail.
|
|
147
|
-
// A whole-batch error must never hide this generation's physical effects.
|
|
148
|
-
let projected = super::commands::publish_at(&selected.run_workspace, &selected.team_key, seat, true)?;
|
|
149
|
-
Ok(projected)
|
|
152
|
+
start_configured(&selected.run_workspace, &selected.team_dir, &selected.team_key, seat)
|
|
150
153
|
}).map_err(|e| crate::lifecycle::LifecycleError::Provider(e.to_string()))?;
|
|
151
154
|
if result.is_none() {
|
|
152
155
|
return Err(crate::lifecycle::LifecycleError::Provider("native startup scope/seat is not addressable; no legacy fallback".into()));
|
|
@@ -154,6 +157,58 @@ pub fn start_role(
|
|
|
154
157
|
Ok(())
|
|
155
158
|
}
|
|
156
159
|
|
|
160
|
+
/// Start one configured contract role and publish its seat. The caller holds
|
|
161
|
+
/// the lifecycle lock (or owns the whole launch) and has seeded the state row.
|
|
162
|
+
pub(crate) fn start_configured(
|
|
163
|
+
workspace: &Path,
|
|
164
|
+
directory: &Path,
|
|
165
|
+
team: &str,
|
|
166
|
+
seat: &SeatId,
|
|
167
|
+
) -> Result<Value, crate::cli::CliError> {
|
|
168
|
+
let error = |error: String| crate::cli::CliError::Runtime(error);
|
|
169
|
+
let config = team_config(workspace, directory, team)
|
|
170
|
+
.map_err(|e| error(e.to_string()))?
|
|
171
|
+
.ok_or_else(|| error("contract role no longer configured".into()))?;
|
|
172
|
+
let role = config.roles.iter().find(|role| &role.id == seat)
|
|
173
|
+
.ok_or_else(|| error(format!("contract role not found in {}", directory.join("agents").display())))?;
|
|
174
|
+
let (_, record) = backend::start(workspace, team, role, &config.members)
|
|
175
|
+
.map_err(|e| error(e.to_string()))?;
|
|
176
|
+
if record.outcome != Outcome::Committed {
|
|
177
|
+
return Err(error(format!("native startup seat={} operation={:?} phase={:?} outcome={:?}: {}",
|
|
178
|
+
seat.as_str(), record.id, record.phase, record.outcome, record.failure.unwrap_or_default())));
|
|
179
|
+
}
|
|
180
|
+
// Preserve each committed seat before a later discovery/spawn can fail.
|
|
181
|
+
// A whole-batch error must never hide this generation's physical effects.
|
|
182
|
+
super::commands::publish_at(workspace, team, seat, true)
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/// add-agent owns a brand-new seat. If its start committed but publication
|
|
186
|
+
/// failed, stop that seat before the caller rolls its row back: a refused add
|
|
187
|
+
/// never leaves a running native process outside status/stop. An unpublished
|
|
188
|
+
/// spawn stays with its fenced receipt for explicit recovery.
|
|
189
|
+
pub(crate) fn start_new_seat(
|
|
190
|
+
workspace: &Path,
|
|
191
|
+
directory: &Path,
|
|
192
|
+
team: &str,
|
|
193
|
+
seat: &SeatId,
|
|
194
|
+
) -> Result<(), crate::cli::CliError> {
|
|
195
|
+
let Err(error) = start_configured(workspace, directory, team, seat) else {
|
|
196
|
+
return Ok(());
|
|
197
|
+
};
|
|
198
|
+
let started = Backend::open_readonly(workspace, team)
|
|
199
|
+
.ok()
|
|
200
|
+
.and_then(|backend| backend.store.seat(seat).ok().flatten())
|
|
201
|
+
.is_some_and(|current| current.status != SeatStatus::Stopped && current.physical.is_some());
|
|
202
|
+
if started {
|
|
203
|
+
if let Err(stop) = backend::stop(workspace, team, seat) {
|
|
204
|
+
return Err(crate::cli::CliError::Runtime(format!(
|
|
205
|
+
"{error}; stopping the started native seat failed: {stop}"
|
|
206
|
+
)));
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
Err(error)
|
|
210
|
+
}
|
|
211
|
+
|
|
157
212
|
pub fn project_seat(workspace: &Path, team: &str, id: &str) -> Result<Value, BackendError> {
|
|
158
213
|
let mut backend = Backend::open_readonly(workspace, team)?;
|
|
159
214
|
let seat = backend
|