Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions rust/contracts/rust-core-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -8810,3 +8810,18 @@ editor and may explicitly set selected default handlers. macOS associates conten
types, so extensions sharing a type may change together. The installed package
stays read-only. No regex or all-files catch-all
registration is permitted. See [fixtures](../fixtures/application/file-associations-v1.json).

## Plugin workflow projections (`plugins.workflow`)

`operation:"prepare"` takes `{method,params}` and returns strictly checked params
and `{textBytes,outputLines,outputBytes,resources}` limits. Network defaults are
resolved here. `quickPick` takes `{items,query}` and returns source `indices`;
`input` takes `{pick,value}` and returns `{valid}`. `status` takes bounded
`items:[{id,priority}]` and returns ordered `ids`. `treePage` takes `{cursor,
lastCursor,count,lastCount,rows,lastVisible}` and returns `{load}` only near the
end when both cursor and retained count advance. `output` takes `{open,text}`
and returns `{lines,open,maxLines,maxBytes}` as one bounded increment, never the
retained history. Unknown operations/fields and malformed projection input fail
with `invalid_request`. This hot path is excluded from request tracing; its text
may contain secrets. Public backend methods and lifecycle are specified in the
[plugin contract](../../shared/plugins/contract/v1/README.md#workflow-host-methods).
3 changes: 3 additions & 0 deletions rust/crates/core/src/protocol/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ pub enum AiCommand {
#[derive(Debug, Clone)]
/// The `plugins.*` commands; their names live in [`CoreCommand::parse`].
pub enum PluginsCommand {
/// Plans bounded plugin interactions and projects their native input/output.
Workflow,
/// Validates and normalizes a declarative plugin manifest (`plugins.declarative.validate`).
DeclarativeValidate,
/// Checks what a backend returned for a plugin view and gives the whole view to draw (`plugins.ui.applyResult`).
Expand Down Expand Up @@ -1167,6 +1169,7 @@ impl CoreCommand {
"plugins.declarative.validate" => {
Some(Self::Plugins(PluginsCommand::DeclarativeValidate))
}
"plugins.workflow" => Some(Self::Plugins(PluginsCommand::Workflow)),
"plugins.ui.applyResult" => Some(Self::Plugins(PluginsCommand::UIApplyResult)),
"plugins.web.open" => Some(Self::Plugins(PluginsCommand::WebOpen)),
"plugins.web.close" => Some(Self::Plugins(PluginsCommand::WebClose)),
Expand Down
3 changes: 3 additions & 0 deletions rust/crates/core/src/runtime/dispatcher/plugins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ pub(super) fn dispatch(
payload: Value,
) -> CoreResponse {
match command {
PluginsCommand::Workflow => {
plugin_response(id, payload, lithe_plugin_rpc::workflow::command)
}
PluginsCommand::UIApplyResult => {
plugin_response(id, payload, lithe_plugin_manifest::apply_result_command)
}
Expand Down
1 change: 1 addition & 0 deletions rust/crates/core/src/runtime/request_trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ pub(crate) fn is_hot(method: &str) -> bool {
method,
"document.classifyText"
| "document.lifecycle"
| "plugins.workflow"
| "markdown.render"
| "markdown.outline"
| "markdown.resolveReference"
Expand Down
1 change: 1 addition & 0 deletions rust/crates/plugin-rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ lithe-plugin-model = { path = "../plugin-model" }
lithe-protocol = { path = "../protocol" }
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0", features = ["preserve_order"] }
url = "2.5"
3 changes: 2 additions & 1 deletion rust/crates/plugin-rpc/src/host_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub(crate) fn check_host_params(
_ => return Err(invalid("Params must be an object.")),
};
let allowed: &[&str] = match rule {
HostParams::Workflow => return Err(invalid("Workflow validation requires a method.")),
HostParams::Empty => &[],
HostParams::Credential { with_secret: true } => &["key", "secret"],
HostParams::Credential { with_secret: false } => &["key"],
Expand Down Expand Up @@ -284,7 +285,7 @@ pub(crate) fn check_host_params(
| HostParams::WorkspaceWatch
| HostParams::WorkspaceFindFiles
| HostParams::WorkspaceFindText => check_workspace_read_params(rule, params, &invalid)?,
HostParams::Empty | HostParams::Object => {}
HostParams::Empty | HostParams::Object | HostParams::Workflow => {}
}
Ok(())
}
Expand Down
126 changes: 123 additions & 3 deletions rust/crates/plugin-rpc/src/host_requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ pub(crate) enum HostParams {
WorkspaceFindFiles,
/// A bounded text search at the workspace root (plan API-08).
WorkspaceFindText,
/// Strict, bounded interactive, presentation and managed-network requests.
Workflow,
/// Any object whose `context`, when present, is a well-formed
/// reference. The service checks the rest and answers
/// `plugin.host.invalidParams` or, for a field it does not know,
Expand All @@ -112,6 +114,120 @@ pub(crate) struct HostMethod {
/// service adds its rows here, its grant to `GRANTABLE_HOST_SERVICES` and
/// the manifest permission, and its handler to the host's dispatcher.
pub(crate) const HOST_METHODS: &[HostMethod] = &[
HostMethod {
method: "lithe/host/window/showQuickPick",
service: "window",
permission: Some("window.input"),
params: HostParams::Workflow,
},
HostMethod {
method: "lithe/host/window/showInputBox",
service: "window",
permission: Some("window.input"),
params: HostParams::Workflow,
},
HostMethod {
method: "lithe/host/preview/openMarkdown",
service: "preview",
permission: Some("preview.open"),
params: HostParams::Workflow,
},
HostMethod {
method: "lithe/host/editor/showDiff",
service: "editor",
permission: Some("editor.open"),
params: HostParams::Workflow,
},
HostMethod {
method: "lithe/host/views/refresh",
service: "views",
permission: Some("views.refresh"),
params: HostParams::Workflow,
},
HostMethod {
method: "lithe/host/output/create",
service: "output",
permission: Some("output.write"),
params: HostParams::Workflow,
},
HostMethod {
method: "lithe/host/output/append",
service: "output",
permission: Some("output.write"),
params: HostParams::Workflow,
},
HostMethod {
method: "lithe/host/output/clear",
service: "output",
permission: Some("output.write"),
params: HostParams::Workflow,
},
HostMethod {
method: "lithe/host/output/show",
service: "output",
permission: Some("output.write"),
params: HostParams::Workflow,
},
HostMethod {
method: "lithe/host/output/dispose",
service: "output",
permission: Some("output.write"),
params: HostParams::Workflow,
},
HostMethod {
method: "lithe/host/progress/create",
service: "progress",
permission: Some("window.progress"),
params: HostParams::Workflow,
},
HostMethod {
method: "lithe/host/progress/report",
service: "progress",
permission: Some("window.progress"),
params: HostParams::Workflow,
},
HostMethod {
method: "lithe/host/progress/end",
service: "progress",
permission: Some("window.progress"),
params: HostParams::Workflow,
},
HostMethod {
method: "lithe/host/statusBar/setItem",
service: "statusBar",
permission: Some("statusBar.write"),
params: HostParams::Workflow,
},
HostMethod {
method: "lithe/host/statusBar/removeItem",
service: "statusBar",
permission: Some("statusBar.write"),
params: HostParams::Workflow,
},
HostMethod {
method: "lithe/host/clipboard/readText",
service: "clipboard",
permission: Some("clipboard.read"),
params: HostParams::Workflow,
},
HostMethod {
method: "lithe/host/clipboard/writeText",
service: "clipboard",
permission: Some("clipboard.write"),
params: HostParams::Workflow,
},
HostMethod {
method: "lithe/host/workspace/reveal",
service: "workspace",
permission: Some("workspace.reveal"),
params: HostParams::Workflow,
},
HostMethod {
method: "lithe/host/network/request",
service: "network",
permission: Some("network.request"),
params: HostParams::Workflow,
},
HostMethod {
method: RUN_START,
service: HOST_SERVICE_RUN,
Expand Down Expand Up @@ -409,13 +525,13 @@ pub(crate) const HOST_METHODS: &[HostMethod] = &[
method: "lithe/host/preview/openHTML",
service: "preview",
permission: Some("preview.open"),
params: HostParams::Object,
params: HostParams::Workflow,
},
HostMethod {
method: "lithe/host/browser/openExternal",
service: "browser",
permission: Some("browser.open"),
params: HostParams::Object,
params: HostParams::Workflow,
},
HostMethod {
method: "lithe/host/window/showInformation",
Expand Down Expand Up @@ -534,7 +650,11 @@ pub fn host_request(
details: None,
});
}
check_host_params(entry.params, params)?;
if entry.params == HostParams::Workflow {
workflow::check_params(method, params.unwrap_or(&Value::Null))?;
} else {
check_host_params(entry.params, params)?;
}
if entry.method == GET_CAPABILITIES {
return Ok(HostRoute::Answer(capabilities_answer(version, granted)));
}
Expand Down
10 changes: 10 additions & 0 deletions rust/crates/plugin-rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
//! dispatchers.

pub mod host_api;
pub mod workflow;

use lithe_plugin_language_servers::is_protocol_name;
use lithe_plugin_model::capabilities::{
Expand Down Expand Up @@ -138,6 +139,15 @@ pub fn methods_for_permission(permission: &str) -> Vec<&'static str> {

/// Permissions for the additive host services.
pub const HOST_PERMISSIONS: &[&str] = &[
"window.input",
"views.refresh",
"output.write",
"window.progress",
"statusBar.write",
"clipboard.read",
"clipboard.write",
"workspace.reveal",
"network.request",
"workspace.files.read",
"workspace.files.watch",
"build.options.read",
Expand Down
Loading
Loading