You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maka.apache.org by wy...@apache.org on 2026/09/24 19:19:00 UTC
(maka) branch feat/runtime-host-rust updated: feat(workhub): WorkHub as a terminal app, and views that open sessions
This is an automated email from the ASF dual-hosted git repository.
M4n5ter pushed a commit to branch feat/runtime-host-rust
in repository https://gitbox.apache.org/repos/asf/maka.git
The following commit(s) were added to refs/heads/feat/runtime-host-rust by this push:
new 03c4349a04 feat(workhub): WorkHub as a terminal app, and views that open sessions
03c4349a04 is described below
commit 03c4349a04ceb29dd19babea4e092a37820005f3
Author: M4n5ter <m4...@gmail.com>
AuthorDate: Fri Sep 25 03:18:50 2026 +0800
feat(workhub): WorkHub as a terminal app, and views that open sessions
WorkHub becomes an app of its own, pinned in the sidebar.
- It asks once for leave to work in its own workspace and start the
sessions it delegates to, then opens its coordinator.
- The coordinator conversation is one step away: tell WorkHub what you
need, or ask how the work is going.
- A board files the delegated work under Active, Needs you, Done and
All, with each piece's state and what it returned so far.
- Recovery failures, unavailability and results still being collected
show above the board.
- Each piece opens the session doing it and the session that asked for
it. It can be stopped, which asks first, or resumed once stopped. A
change already being applied is shown instead of a second one.
The view contract gains a session target, so any view can open a Maka
session it names; the shell opens it as a tab and the view keeps its
drafts. Agent graph work uses it to open each agent's session. The
TypeScript contract follows, and the compatibility epoch moves to 190.
Application views that follow no changes stream read again when a
session changes, so the board keeps up as delegated sessions work.
Generated-by: Claude Code
---
crates/graph/src/plugin/terminal.rs | 19 +
crates/plugins/src/terminal_ui/view.rs | 3 +
crates/protocol/src/lib.rs | 2 +-
crates/tui/src/apps.rs | 45 +-
crates/tui/src/apps/instance.rs | 2 +
crates/tui/src/apps/tree.rs | 3 +
crates/workhub/src/plugin.rs | 1 +
crates/workhub/src/plugin/remote.rs | 9 +-
crates/workhub/src/plugin/terminal.rs | 654 ++++++++++++++++++++++++++++
packages/plugin-sdk/src/terminal-view.ts | 4 +-
packages/runtime-host/src/protocol/index.ts | 2 +-
11 files changed, 734 insertions(+), 10 deletions(-)
diff --git a/crates/graph/src/plugin/terminal.rs b/crates/graph/src/plugin/terminal.rs
index 0f42392f00..e644682f48 100644
--- a/crates/graph/src/plugin/terminal.rs
+++ b/crates/graph/src/plugin/terminal.rs
@@ -167,6 +167,7 @@ struct Work {
#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
struct Execution {
+ session_id: String,
state: String,
result_record_id: Option<String>,
}
@@ -678,6 +679,23 @@ fn detail_view(
"state",
vec![(format!("{glyph} "), tone), (label, tone)],
));
+ if let Some(execution) = &work.execution {
+ children.push(Node::Item {
+ key: "session".into(),
+ title: words.t(
+ "Open the agent's session",
+ "打开该智能体的会话",
+ "開啟該智慧體的工作階段",
+ ),
+ detail: String::new(),
+ meta: String::new(),
+ tone: Tone::Normal,
+ current: false,
+ target: view::Target::Session {
+ session: execution.session_id.clone(),
+ },
+ });
+ }
}
if let Some(detail) = detail {
children.push(stack(
@@ -1032,6 +1050,7 @@ mod tests {
instruction: format!("Step {index}\nmore detail"),
status: "requested".into(),
execution: Some(Execution {
+ session_id: format!("agent-{index}"),
state: (*state).into(),
result_record_id: None,
}),
diff --git a/crates/plugins/src/terminal_ui/view.rs b/crates/plugins/src/terminal_ui/view.rs
index e27e0b1cec..fa63f442b9 100644
--- a/crates/plugins/src/terminal_ui/view.rs
+++ b/crates/plugins/src/terminal_ui/view.rs
@@ -164,6 +164,8 @@ pub enum Target {
Route { route: Value },
/// Submit a declared action.
Action { action: String },
+ /// Open a Maka session in the shell, such as one a plugin started.
+ Session { session: String },
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
@@ -652,6 +654,7 @@ impl View {
Target::Route { route: value } => route(value),
Target::Action { action } if actions.contains(action.as_str()) => Ok(()),
Target::Action { .. } => Err(invalid()),
+ Target::Session { session } => identifier(session),
}
}
diff --git a/crates/protocol/src/lib.rs b/crates/protocol/src/lib.rs
index 778d935d2d..0a94ccad3c 100644
--- a/crates/protocol/src/lib.rs
+++ b/crates/protocol/src/lib.rs
@@ -60,7 +60,7 @@ use serde::Serialize;
use serde_json::Value;
pub const PROTOCOL_VERSION: u64 = 0;
-pub const COMPATIBILITY_EPOCH: u64 = 189;
+pub const COMPATIBILITY_EPOCH: u64 = 190;
pub const COMPOSITION_ID: &str = "maka.interactive";
pub const MAX_MESSAGE_BYTES: usize = 768 * 1024;
pub const MAX_IN_FLIGHT_DOMAIN_REQUESTS: usize = 64;
diff --git a/crates/tui/src/apps.rs b/crates/tui/src/apps.rs
index a8225fcd24..7c45bfd778 100644
--- a/crates/tui/src/apps.rs
+++ b/crates/tui/src/apps.rs
@@ -947,6 +947,9 @@ impl App {
}
Command::CancelConfirm => apps.confirming = None,
Command::View(Intent::Navigate(route)) => instance.navigate(route, &locale),
+ Command::View(Intent::Open(session)) => {
+ return self.apply(Action::Visit(Route::Session(session)));
+ }
Command::View(Intent::Submit(id)) => {
if asks(instance, &id) {
apps.confirming = Some((key, id));
@@ -1026,15 +1029,18 @@ impl App {
})
.collect()
}
- /// A session changed (a turn settled, its metadata moved): its views on
- /// screen that follow no changes stream of their own read again.
+ /// A session changed (a turn settled, its metadata moved): its views,
+ /// and application views that may track sessions, read again when on
+ /// screen and following no changes stream of their own.
pub fn apps_session_changed(&mut self, session: &str) {
let locale = self.apps.locale.clone();
let visible: Vec<_> = self
.apps
.instances
.keys()
- .filter(|key| key.session.as_deref() == Some(session) && self.app_visible(key))
+ .filter(|key| {
+ key.session.as_deref().is_none_or(|own| own == session) && self.app_visible(key)
+ })
.cloned()
.collect();
for key in visible {
@@ -2223,4 +2229,37 @@ pub(crate) mod tests {
"a submission missing its key can be checked, never resent"
);
}
+
+ #[test]
+ fn a_view_opens_a_session_it_names_without_losing_its_draft() {
+ use maka_plugins::terminal_ui::view::{Node, Target};
+ let mut app = app();
+ {
+ let instance = instance_mut(&mut app);
+ let view = instance.view.as_mut().unwrap();
+ view.root = Node::Column {
+ key: "root".into(),
+ gap: 0,
+ children: vec![Node::Item {
+ key: "worker".into(),
+ title: "Open the worker".into(),
+ detail: String::new(),
+ meta: String::new(),
+ tone: Tone::Normal,
+ current: false,
+ target: Target::Session {
+ session: "worker".into(),
+ },
+ }],
+ };
+ view.validate().unwrap();
+ }
+ instance_mut(&mut app)
+ .drafts
+ .insert("enabled".into(), json!(false));
+ draw(&mut app, 90, 26);
+ click(&mut app, "app/body/frame/content/root/worker");
+ assert_eq!(app.navigation.current(), Route::Session("worker".into()));
+ assert_eq!(instance(&app).drafts["enabled"], json!(false));
+ }
}
diff --git a/crates/tui/src/apps/instance.rs b/crates/tui/src/apps/instance.rs
index b6ab58864d..c48498fce6 100644
--- a/crates/tui/src/apps/instance.rs
+++ b/crates/tui/src/apps/instance.rs
@@ -208,6 +208,8 @@ impl Instance {
Intent::Toggle(id) | Intent::Pick(id, _) | Intent::Commit(id) => {
view.field(id).is_some_and(|field| field.enabled)
}
+ // A session opens beside the app; drafts stay where they are.
+ Intent::Open(_) => true,
}
}
/// What Return in a one-line field submits: the primary button that
diff --git a/crates/tui/src/apps/tree.rs b/crates/tui/src/apps/tree.rs
index aa74ace6ea..442e1c5ef2 100644
--- a/crates/tui/src/apps/tree.rs
+++ b/crates/tui/src/apps/tree.rs
@@ -39,6 +39,8 @@ pub enum Intent {
Pick(String, String),
/// Return in a one-line text field: the field's default action.
Commit(String),
+ /// Open a Maka session the view names.
+ Open(String),
}
/// A text field's well in the laid-out tree; its owner paints the editor.
@@ -308,6 +310,7 @@ impl<M> Builder<'_, M> {
let (intent, chevron) = match target {
Target::Route { route } => (Intent::Navigate(route.clone()), true),
Target::Action { action } => (Intent::Submit(action.clone()), false),
+ Target::Session { session } => (Intent::Open(session.clone()), true),
};
let mut head = vec![
Node::text("title", vec![(title.clone(), tone(*item_tone))])
diff --git a/crates/workhub/src/plugin.rs b/crates/workhub/src/plugin.rs
index 040616da5b..50bd5c6c5f 100644
--- a/crates/workhub/src/plugin.rs
+++ b/crates/workhub/src/plugin.rs
@@ -19,6 +19,7 @@
mod remote;
mod session;
+mod terminal;
mod tools;
use crate::{Access, Coordinator, Repository, assignment::Assignments};
diff --git a/crates/workhub/src/plugin/remote.rs b/crates/workhub/src/plugin/remote.rs
index 85e12f63f7..910971bd1a 100644
--- a/crates/workhub/src/plugin/remote.rs
+++ b/crates/workhub/src/plugin/remote.rs
@@ -37,6 +37,7 @@ pub(super) fn publish(
package: &str,
digest: &str,
) -> Result<(), String> {
+ super::terminal::publish(staged, manager.clone(), package)?;
for (name, action) in [
("authorize", Action::Authorize),
("consent", Action::Consent),
@@ -78,7 +79,7 @@ pub(super) fn publish(
Ok(())
}
#[derive(Clone, Copy)]
-enum Action {
+pub(super) enum Action {
Authorize,
Consent,
Template,
@@ -103,9 +104,9 @@ enum Action {
Configure,
Enqueue,
}
-struct Call {
- manager: Arc<Manager>,
- action: Action,
+pub(super) struct Call {
+ pub(super) manager: Arc<Manager>,
+ pub(super) action: Action,
}
#[derive(Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
diff --git a/crates/workhub/src/plugin/terminal.rs b/crates/workhub/src/plugin/terminal.rs
new file mode 100644
index 0000000000..70a1eb6a67
--- /dev/null
+++ b/crates/workhub/src/plugin/terminal.rs
@@ -0,0 +1,654 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+//! WorkHub as an app of its own: a coordinator conversation to hand work
+//! to, and a board of the work it delegated to other sessions, each piece
+//! with where it runs, how it stands and what it returned. It speaks
+//! WorkHub's own Remote methods.
+
+use super::{
+ Manager,
+ remote::{Action as Call, Call as Calling},
+};
+use futures_util::future::BoxFuture;
+use maka_plugins::{
+ authorization::{Capability, Request as Authorization, Target as Scope},
+ contributions::Staged,
+ remote::{Caller, Error, Method, key},
+ terminal_ui::{
+ Context, Descriptor, Text, VERSION,
+ app::{self, App, Cx, Submission, Words},
+ view::{self, Action, Confirm, Node, Reply, Role, Tone, View, build::*},
+ },
+};
+use serde::Deserialize;
+use serde_json::{Value, json};
+use std::sync::Arc;
+
+pub(super) fn publish(
+ staged: &mut Staged,
+ manager: Arc<Manager>,
+ package: &str,
+) -> Result<(), String> {
+ let endpoint = app::endpoint(
+ Hub(manager),
+ Descriptor::new(Text::plain("WorkHub"), Context::Application)
+ .icon("◈", "H")
+ .order(10),
+ )
+ .map_err(|error| error.to_string())?;
+ staged
+ .insert(
+ key(package, "terminal").map_err(|error| error.to_string())?,
+ endpoint,
+ )
+ .map_err(|error| error.to_string())
+}
+
+struct Hub(Arc<Manager>);
+
+/// WorkHub works in its own plugin workspace, and needs leave to run there.
+fn workspace() -> Scope {
+ Scope::PluginWorkspace {
+ sandbox_mode: maka_runtime::execution::SandboxMode::WorkspaceWrite,
+ }
+}
+
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+struct Query {
+ coordinator_session_id: Option<String>,
+ recovery: Recovery,
+}
+#[derive(Deserialize, Default)]
+#[serde(rename_all = "camelCase", default)]
+struct Recovery {
+ pending_results: bool,
+ failures: Vec<Failure>,
+ unavailable: Option<String>,
+}
+#[derive(Deserialize)]
+struct Failure {
+ message: String,
+ retrying: bool,
+}
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+struct Page {
+ entries: Vec<Summary>,
+ next_after: Option<String>,
+}
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+struct Summary {
+ operation_id: String,
+ title: String,
+ source: Invocation,
+ delivery: Option<Delivery>,
+ retired: bool,
+ control: Option<String>,
+}
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+struct Invocation {
+ session_id: String,
+}
+#[derive(Deserialize)]
+struct Delivery {
+ receipt: Receipt,
+}
+#[derive(Deserialize)]
+struct Receipt {
+ invocation: Invocation,
+}
+#[derive(Deserialize)]
+#[serde(rename_all = "camelCase")]
+struct Feedback {
+ id: String,
+ state: String,
+ result_preview: Option<String>,
+}
+
+/// Where the app is: the board under a filter, or one piece of work.
+#[derive(Deserialize, Default)]
+#[serde(default)]
+struct Place {
+ filter: Option<String>,
+ after: Option<String>,
+ assignment: Option<String>,
+}
+
+impl Hub {
+ async fn call<T: for<'de> Deserialize<'de>>(
+ &self,
+ action: Call,
+ input: Value,
+ caller: &Caller,
+ ) -> Result<T, Error> {
+ let value = Calling {
+ manager: self.0.clone(),
+ action,
+ }
+ .call(input, caller.clone())
+ .await?;
+ serde_json::from_value(value).map_err(|error| Error::Provider(error.to_string()))
+ }
+ async fn ready(&self, caller: &Caller) -> Result<bool, Error> {
+ let remembered: Option<Value> =
+ self.call(Call::Consent, json!(workspace()), caller).await?;
+ Ok(remembered.is_some())
+ }
+ async fn board(
+ &self,
+ caller: &Caller,
+ after: Option<String>,
+ ) -> Result<(Page, Vec<Feedback>), Error> {
+ let page: Page = self
+ .call(Call::Assignments, json!({"after": after}), caller)
+ .await?;
+ let ids: Vec<&str> = page
+ .entries
+ .iter()
+ .take(32)
+ .map(|entry| entry.operation_id.as_str())
+ .collect();
+ let feedback: Vec<Feedback> = if ids.is_empty() {
+ vec![]
+ } else {
+ self.call(Call::Feedback, json!(ids), caller).await?
+ };
+ Ok((page, feedback))
+ }
+}
+
+impl App for Hub {
+ fn read(&self, route: Value, cx: Cx) -> BoxFuture<'static, Result<View, Error>> {
+ let this = Hub(self.0.clone());
+ Box::pin(async move {
+ let words = &cx.words;
+ if !this.ready(&cx.caller).await? {
+ return Ok(welcome(words));
+ }
+ let query: Query = this.call(Call::Query, Value::Null, &cx.caller).await?;
+ let place: Place = serde_json::from_value(route).unwrap_or_default();
+ let (page, feedback) = this.board(&cx.caller, place.after.clone()).await?;
+ if let Some(id) = &place.assignment {
+ let summary = page.entries.iter().find(|entry| &entry.operation_id == id);
+ let state = feedback.iter().find(|item| &item.id == id);
+ return Ok(assignment(words, id, summary, state));
+ }
+ let filter = place.filter.unwrap_or_else(|| "active".into());
+ Ok(board(words, &query, &page, &feedback, &filter))
+ })
+ }
+
+ fn submit(&self, submission: Submission, cx: Cx) -> BoxFuture<'static, Result<Reply, Error>> {
+ let this = Hub(self.0.clone());
+ Box::pin(async move {
+ let rejected = |error: Error| match error {
+ Error::Invalid(message) | Error::Provider(message) => Ok(Reply::Rejected {
+ message: view::build::clean(&message, false)
+ .chars()
+ .take(256)
+ .collect(),
+ }),
+ error => Err(error),
+ };
+ match submission.action.as_str() {
+ "setup" => {
+ let Some(grant) = submission.grant else {
+ return Ok(Reply::Consent {
+ request: Authorization {
+ operation_id: uuid::Uuid::new_v4(),
+ title: "Let WorkHub coordinate work".into(),
+ target: workspace(),
+ capabilities: [Capability::Executions].into(),
+ },
+ });
+ };
+ if let Err(error) = this
+ .call::<Value>(Call::Authorize, json!({"id": grant}), &cx.caller)
+ .await
+ {
+ return rejected(error);
+ }
+ match this
+ .call::<Value>(Call::Resolve, Value::Null, &cx.caller)
+ .await
+ {
+ Ok(_) => Ok(Reply::Applied { route: Value::Null }),
+ Err(error) => rejected(error),
+ }
+ }
+ "start" => match this
+ .call::<Value>(Call::Resolve, Value::Null, &cx.caller)
+ .await
+ {
+ Ok(_) => Ok(Reply::Applied { route: Value::Null }),
+ Err(error) => rejected(error),
+ },
+ action @ ("stop" | "resume") => {
+ let id = submission
+ .route
+ .get("assignment")
+ .and_then(Value::as_str)
+ .ok_or_else(|| Error::Invalid("No assignment".into()))?
+ .to_owned();
+ match this
+ .call::<Value>(
+ Call::Control,
+ json!({"operationId":uuid::Uuid::new_v4().to_string(),"assignmentId":id,
+ "action":{"kind":action}}),
+ &cx.caller,
+ )
+ .await
+ {
+ Ok(_) => Ok(Reply::Applied {
+ route: submission.route,
+ }),
+ Err(error) => rejected(error),
+ }
+ }
+ _ => Err(Error::Invalid("Unknown WorkHub action".into())),
+ }
+ })
+ }
+}
+
+fn view_of(title: &str, revision: &str, actions: Vec<Action>, root: Node) -> View {
+ View {
+ version: VERSION,
+ title: title.into(),
+ revision: revision.into(),
+ fields: vec![],
+ actions,
+ root,
+ }
+}
+
+fn welcome(words: &Words) -> View {
+ view_of(
+ "WorkHub",
+ "welcome",
+ vec![view::build::action("setup", words.t("Set up WorkHub", "设置 WorkHub", "設定 WorkHub"))],
+ column(
+ "root",
+ vec![
+ heading("title", "WorkHub"),
+ text(
+ "pitch",
+ words.t(
+ "Hand WorkHub a goal in plain words. It plans the work, delegates each piece to a session, and keeps track until it is done.",
+ "用自然语言把目标交给 WorkHub。它会规划工作,把每一部分委派给会话,并一直跟进到完成。",
+ "用自然語言把目標交給 WorkHub。它會規劃工作,把每一部分委派給工作階段,並一直追蹤到完成。",
+ ),
+ Tone::Muted,
+ ),
+ text(
+ "leave",
+ words.t(
+ "It works in its own workspace and starts the sessions it delegates to, so it asks first.",
+ "它在自己的工作区中运行,并会启动被委派的会话,因此需要先获得许可。",
+ "它在自己的工作區中執行,並會啟動被委派的工作階段,因此需要先取得許可。",
+ ),
+ Tone::Subtle,
+ ),
+ row("setup", vec![button("setup", "setup", Role::Primary)]),
+ ],
+ ),
+ )
+}
+
+/// How a piece of work stands, and which filter shows it.
+fn state(words: &Words, state: Option<&str>) -> (String, Tone, &'static str) {
+ let (en, zh_cn, zh_tw, tone, group) = match state {
+ Some("running") => ("Running", "运行中", "執行中", Tone::Accent, "active"),
+ Some("accepted") => ("Queued", "排队中", "排隊中", Tone::Muted, "active"),
+ Some("recovering") => ("Checking", "核对中", "核對中", Tone::Warning, "active"),
+ Some("waiting_for_user") => ("Needs you", "需要你", "需要你", Tone::Warning, "attention"),
+ Some("failed") => ("Failed", "失败", "失敗", Tone::Error, "attention"),
+ Some("completed") => ("Done", "完成", "完成", Tone::Success, "done"),
+ Some("aborted") => ("Stopped", "已停止", "已停止", Tone::Muted, "done"),
+ _ => ("Unknown", "未知", "未知", Tone::Subtle, "active"),
+ };
+ (words.t(en, zh_cn, zh_tw), tone, group)
+}
+
+fn board(words: &Words, query: &Query, page: &Page, feedback: &[Feedback], filter: &str) -> View {
+ let mut children = vec![];
+ let mut actions = vec![];
+ match &query.coordinator_session_id {
+ Some(session) => children.push(Node::Item {
+ key: "coordinator".into(),
+ title: words.t("Coordinator conversation", "协调对话", "協調對話"),
+ detail: words.t(
+ "Tell WorkHub what you need, or ask how the work is going",
+ "告诉 WorkHub 你需要什么,或询问工作进展",
+ "告訴 WorkHub 你需要什麼,或詢問工作進展",
+ ),
+ meta: String::new(),
+ tone: Tone::Accent,
+ current: false,
+ target: view::Target::Session {
+ session: session.clone(),
+ },
+ }),
+ None => {
+ actions.push(view::build::action(
+ "start",
+ words.t("Start WorkHub", "启动 WorkHub", "啟動 WorkHub"),
+ ));
+ children.push(row("start", vec![button("start", "start", Role::Primary)]));
+ }
+ }
+ let recovery = &query.recovery;
+ if let Some(unavailable) = &recovery.unavailable {
+ children.push(text(
+ "unavailable",
+ view::build::clean(unavailable, false),
+ Tone::Warning,
+ ));
+ }
+ for (index, failure) in recovery.failures.iter().take(5).enumerate() {
+ let tone = if failure.retrying {
+ Tone::Warning
+ } else {
+ Tone::Error
+ };
+ children.push(text(
+ format!("failure-{index}"),
+ view::build::clean(&failure.message, false),
+ tone,
+ ));
+ }
+ if recovery.pending_results {
+ children.push(text(
+ "pending",
+ words.t(
+ "Some results are still being collected.",
+ "仍在收集部分结果。",
+ "仍在收集部分結果。",
+ ),
+ Tone::Subtle,
+ ));
+ }
+ children.push(tabs(
+ "filter",
+ filter,
+ [
+ ("active", words.t("Active", "进行中", "進行中")),
+ ("attention", words.t("Needs you", "需要你", "需要你")),
+ ("done", words.t("Done", "已完成", "已完成")),
+ ("all", words.t("All", "全部", "全部")),
+ ]
+ .into_iter()
+ .map(|(id, label)| (id.to_owned(), label, json!({"filter": id})))
+ .collect(),
+ ));
+ let rows: Vec<Node> = page
+ .entries
+ .iter()
+ .filter(|entry| !entry.retired)
+ .filter_map(|entry| {
+ let item = feedback.iter().find(|item| item.id == entry.operation_id);
+ let (label, tone, group) = state(words, item.map(|item| item.state.as_str()));
+ if filter != "all" && group != filter {
+ return None;
+ }
+ let mut row = link(
+ format!("work-{}", entry.operation_id).replace('/', ":"),
+ view::build::clean(&entry.title, false),
+ json!({"assignment": entry.operation_id, "filter": filter}),
+ )
+ .meta(label)
+ .tone(tone);
+ if let Some(preview) = item.and_then(|item| item.result_preview.as_deref()) {
+ row = row.detail(view::build::clean(preview, false));
+ }
+ Some(row.into())
+ })
+ .collect();
+ if rows.is_empty() {
+ children.push(text(
+ "empty",
+ words.t(
+ "Nothing here. Work WorkHub delegates appears as it starts.",
+ "这里还没有内容。WorkHub 委派的工作开始后会出现在这里。",
+ "這裡還沒有內容。WorkHub 委派的工作開始後會出現在這裡。",
+ ),
+ Tone::Muted,
+ ));
+ } else {
+ children.push(scroll("work", 24, stack("list", rows)));
+ }
+ if let Some(after) = &page.next_after {
+ children.push(
+ link(
+ "more",
+ words.t("Older work", "更早的工作", "更早的工作"),
+ json!({"filter": filter, "after": after}),
+ )
+ .into(),
+ );
+ }
+ view_of("WorkHub", filter, actions, column("root", children))
+}
+
+fn assignment(
+ words: &Words,
+ id: &str,
+ summary: Option<&Summary>,
+ feedback: Option<&Feedback>,
+) -> View {
+ let Some(summary) = summary else {
+ return view_of(
+ "WorkHub",
+ id,
+ vec![],
+ column(
+ "root",
+ vec![text(
+ "gone",
+ words.t(
+ "This work is no longer listed.",
+ "这项工作已不在列表中。",
+ "這項工作已不在列表中。",
+ ),
+ Tone::Muted,
+ )],
+ ),
+ );
+ };
+ let (label, tone, group) = state(words, feedback.map(|item| item.state.as_str()));
+ let mut children = vec![
+ heading("title", view::build::clean(&summary.title, false)),
+ spans("state", vec![("● ".into(), tone), (label, tone)]),
+ ];
+ if let Some(preview) = feedback.and_then(|item| item.result_preview.as_deref()) {
+ children.push(stack(
+ "result",
+ vec![
+ text(
+ "label",
+ words.t("Result so far", "目前结果", "目前結果"),
+ Tone::Subtle,
+ ),
+ markdown("text", view::build::clean(preview, true)),
+ ],
+ ));
+ }
+ if let Some(delivery) = &summary.delivery {
+ children.push(Node::Item {
+ key: "delegated".into(),
+ title: words.t(
+ "Open the session doing it",
+ "打开执行它的会话",
+ "開啟執行它的工作階段",
+ ),
+ detail: String::new(),
+ meta: String::new(),
+ tone: Tone::Normal,
+ current: false,
+ target: view::Target::Session {
+ session: delivery.receipt.invocation.session_id.clone(),
+ },
+ });
+ }
+ children.push(Node::Item {
+ key: "source".into(),
+ title: words.t(
+ "Open where it was asked for",
+ "打开发起它的会话",
+ "開啟發起它的工作階段",
+ ),
+ detail: String::new(),
+ meta: String::new(),
+ tone: Tone::Normal,
+ current: false,
+ target: view::Target::Session {
+ session: summary.source.session_id.clone(),
+ },
+ });
+ let mut actions = vec![];
+ let stopped = feedback.is_some_and(|item| item.state == "aborted");
+ if summary.control.is_some() {
+ // A stop or resume is already on its way; another waits for it.
+ children.push(text(
+ "applying",
+ words.t(
+ "A change to this work is being applied.",
+ "正在应用对这项工作的更改。",
+ "正在套用對這項工作的變更。",
+ ),
+ Tone::Subtle,
+ ));
+ } else if group != "done" {
+ actions.push(Action {
+ confirm: Some(Confirm {
+ title: words.t("Stop this work?", "停止这项工作?", "停止這項工作?"),
+ message: words.t(
+ "The session doing it stops. What it already changed stays.",
+ "执行它的会话会停止。已做出的更改会保留。",
+ "執行它的工作階段會停止。已做出的變更會保留。",
+ ),
+ destructive: true,
+ }),
+ ..view::build::action("stop", words.t("Stop", "停止", "停止"))
+ });
+ children.push(row(
+ "controls",
+ vec![button("stop", "stop", Role::Destructive)],
+ ));
+ } else if stopped {
+ actions.push(view::build::action(
+ "resume",
+ words.t("Resume", "继续", "繼續"),
+ ));
+ children.push(row(
+ "controls",
+ vec![button("resume", "resume", Role::Primary)],
+ ));
+ }
+ view_of(
+ "WorkHub",
+ &format!(
+ "{id}:{}",
+ feedback.map_or("none", |item| item.state.as_str())
+ ),
+ actions,
+ column("root", children),
+ )
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ fn summary(id: &str) -> Summary {
+ Summary {
+ operation_id: id.into(),
+ title: format!("Task {id}"),
+ source: Invocation {
+ session_id: "coordinator".into(),
+ },
+ delivery: Some(Delivery {
+ receipt: Receipt {
+ invocation: Invocation {
+ session_id: format!("worker-{id}"),
+ },
+ },
+ }),
+ retired: false,
+ control: None,
+ }
+ }
+
+ #[test]
+ fn the_board_files_work_by_state_and_each_piece_opens_its_sessions() {
+ let words = Words::new("en");
+ welcome(&words).validate().unwrap();
+ let query = Query {
+ coordinator_session_id: Some("coordinator".into()),
+ recovery: Recovery {
+ pending_results: true,
+ failures: vec![Failure {
+ message: "Could not reach a session".into(),
+ retrying: true,
+ }],
+ unavailable: None,
+ },
+ };
+ let page = Page {
+ entries: vec![summary("a"), summary("b")],
+ next_after: Some("b".into()),
+ };
+ let feedback = vec![
+ Feedback {
+ id: "a".into(),
+ state: "running".into(),
+ result_preview: None,
+ },
+ Feedback {
+ id: "b".into(),
+ state: "waiting_for_user".into(),
+ result_preview: Some("Which branch?".into()),
+ },
+ ];
+ let active = board(&words, &query, &page, &feedback, "active");
+ active.validate().unwrap();
+ let text = serde_json::to_string(&active).unwrap();
+ assert!(text.contains("Task a") && !text.contains("Task b"));
+ assert!(text.contains("\"kind\":\"session\"") && text.contains("Could not reach"));
+ let attention =
+ serde_json::to_string(&board(&words, &query, &page, &feedback, "attention")).unwrap();
+ assert!(attention.contains("Task b") && attention.contains("Which branch?"));
+ let detail = assignment(&words, "a", page.entries.first(), feedback.first());
+ detail.validate().unwrap();
+ assert!(
+ detail
+ .action("stop")
+ .unwrap()
+ .confirm
+ .as_ref()
+ .unwrap()
+ .destructive
+ );
+ assert!(serde_json::to_string(&detail).unwrap().contains("worker-a"));
+ }
+}
diff --git a/packages/plugin-sdk/src/terminal-view.ts b/packages/plugin-sdk/src/terminal-view.ts
index 3836ef0f50..75a916bed1 100644
--- a/packages/plugin-sdk/src/terminal-view.ts
+++ b/packages/plugin-sdk/src/terminal-view.ts
@@ -79,7 +79,9 @@ export type TerminalTarget =
/** Read another route of this view; Back returns. */
| { kind: 'route'; route: Json }
/** Submit a declared action. */
- | { kind: 'action'; action: string };
+ | { kind: 'action'; action: string }
+ /** Open a Maka session in the shell, such as one the plugin started. */
+ | { kind: 'session'; session: string };
/** Keys are unique among siblings, contain no `/`, and stay stable across reads. */
export type TerminalNode =
diff --git a/packages/runtime-host/src/protocol/index.ts b/packages/runtime-host/src/protocol/index.ts
index 7a0bf6266f..7e6cd2bd01 100644
--- a/packages/runtime-host/src/protocol/index.ts
+++ b/packages/runtime-host/src/protocol/index.ts
@@ -119,7 +119,7 @@ export const RUNTIME_HOST_PROTOCOL_VERSION = 0 as const;
// Increment when the same protocol version no longer guarantees safe Client-Host
// interoperability. Mismatches are rejected before domain commands are admitted.
// Native bundle bindings and whole-catalog invalidation require matching clients.
-export const RUNTIME_HOST_COMPATIBILITY_EPOCH = 189 as const;
+export const RUNTIME_HOST_COMPATIBILITY_EPOCH = 190 as const;
export const RUNTIME_HOST_MAX_MESSAGE_BYTES = 768 * 1024;
export const RUNTIME_HOST_MAX_IN_FLIGHT_DOMAIN_REQUESTS = 64;
export const INTERACTIVE_RUNTIME_HOST_COMPOSITION_ID = 'maka.interactive' as const;
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@maka.apache.org
For additional commands, e-mail: commits-help@maka.apache.org