worker: unify granted Worker control

This commit is contained in:
2026-08-17 00:18:49 +09:00
parent f41ab0e277
commit 8be2cfd2a3
9 changed files with 1304 additions and 302 deletions
-3
View File
@@ -21,7 +21,6 @@ use crate::shutdown_after_idle::{
ShutdownAfterIdleRequest, TicketIntakeReadyShutdownHook, is_ticket_intake_role,
take_shutdown_request_after_status,
};
use crate::spawn::comm_tools::{sub_worker_send_tool, sub_worker_stop_tool};
use crate::spawn::registry::SpawnedWorkerRegistry;
use crate::spawn::tool::sub_worker_spawn_tool;
use crate::worker::{
@@ -921,8 +920,6 @@ where
scope_handle,
prompts,
));
engine.register_tool(sub_worker_send_tool(spawned_registry.clone()));
engine.register_tool(sub_worker_stop_tool(spawned_registry.clone()));
observation_providers.push(Arc::new(
crate::feature::builtin::worker_observation::SpawnedSubWorkerObservationProvider::new(
spawned_registry,
File diff suppressed because it is too large Load Diff
@@ -7,7 +7,7 @@ use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use session_store::collect_state;
use super::manage_worker::WORKER_CONTROL_SERVICE_ID;
use super::manage_worker::{WORKER_CONTROL_SERVICE_ID, WorkerControlService};
use crate::feature::{
FeatureDescriptor, FeatureInstallContext, FeatureInstallError, FeatureInstructionContribution,
FeatureInstructionDeclaration, FeatureInstructionId, FeatureModule, ServiceId,
@@ -186,6 +186,43 @@ fn workspace_client_error(error: crate::worker::WorkspaceClientError) -> WorkerO
}
#[derive(Clone)]
struct ControlAuthorizedObservationProvider {
control: Arc<dyn WorkerControlService>,
inner: Arc<dyn WorkerObservationProvider>,
}
#[async_trait]
impl WorkerObservationProvider for ControlAuthorizedObservationProvider {
async fn list_worker_sessions(
&self,
) -> Result<Vec<WorkerObservationSubject>, WorkerObservationError> {
let candidates = self.inner.list_worker_sessions().await?;
let mut granted = Vec::new();
for candidate in candidates {
if self
.control
.ensure_permission(&candidate.subject, "observe")
.await
.is_ok()
{
granted.push(candidate);
}
}
Ok(granted)
}
async fn capture_worker_session(
&self,
subject: &WorkerObservationSubjectRef,
) -> Result<WorkerSessionCapture, WorkerObservationError> {
self.control
.ensure_permission(subject, "observe")
.await
.map_err(|_| WorkerObservationError::NotFound)?;
self.inner.capture_worker_session(subject).await
}
}
pub struct WorkerObservationFeature {
provider: Arc<dyn WorkerObservationProvider>,
}
@@ -227,17 +264,25 @@ impl FeatureModule for WorkerObservationFeature {
.register(FeatureInstructionContribution::new(
observation_instruction(),
))?;
let control = context
.services()
.require::<dyn WorkerControlService>(&ServiceId::builtin(WORKER_CONTROL_SERVICE_ID))?;
let provider: Arc<dyn WorkerObservationProvider> =
Arc::new(ControlAuthorizedObservationProvider {
control,
inner: self.provider.clone(),
});
context.tools().register(ToolContribution::new(
"ViewSessionOverview",
overview_definition(self.provider.clone()),
overview_definition(provider.clone()),
))?;
context.tools().register(ToolContribution::new(
"SearchSessionEntries",
search_definition(self.provider.clone()),
search_definition(provider.clone()),
))?;
context.tools().register(ToolContribution::new(
"ReadSessionEntry",
read_definition(self.provider.clone()),
read_definition(provider),
))?;
Ok(())
}
+7 -1
View File
@@ -1,6 +1,9 @@
#![cfg_attr(not(test), allow(dead_code, unused_imports))]
//! Parent-facing tools for in-process Internal SubWorker sessions.
//!
//! All four tools share the same parent-owned `SpawnedWorkerRegistry` of typed session handles.
//! Legacy direct-child tool constructors are test-only; production exposes the
//! registry through the unified `worker.control` service and Worker tools.
//! There is no Runtime catalog lookup or child socket transport, so a Worker can operate only on
//! its direct Internal children. The socket helper at the bottom remains solely for the legacy
//! top-level Worker callback protocol and is not part of SubWorker communication.
@@ -74,6 +77,7 @@ impl Tool for SubWorkerListTool {
}
}
#[cfg(test)]
pub fn sub_worker_list_tool(registry: Arc<SpawnedWorkerRegistry>) -> ToolDefinition {
Arc::new(move || {
let schema = schemars::schema_for!(SubWorkerListInput);
@@ -132,6 +136,7 @@ impl Tool for SubWorkerSendTool {
}
}
#[cfg(test)]
pub fn sub_worker_send_tool(registry: Arc<SpawnedWorkerRegistry>) -> ToolDefinition {
Arc::new(move || {
let schema = schemars::schema_for!(SubWorkerSendInput);
@@ -186,6 +191,7 @@ impl Tool for SubWorkerStopTool {
}
}
#[cfg(test)]
pub fn sub_worker_stop_tool(registry: Arc<SpawnedWorkerRegistry>) -> ToolDefinition {
Arc::new(move || {
let schema = schemars::schema_for!(NameInput);