Repository Public License
1# Flow SDK: actions, hosts and what a third party could add23This document describes the extension surface of the Flow module (`FlowEngine`) as it exists in the code, and the4platform rules that bound it. Language reference: [FLOW_LANGUAGE.md](FLOW_LANGUAGE.md).56## Model78```9workflow text ──compile──▶ FlowValidatedProgram ──FlowRunner──▶ FlowActionCall ──▶ FlowHost (the app) ──▶ effect10 ▲ ▲11 FlowActionRegistry (definitions) capability grant, allow-list, confirmation, budgets12```1314- A **definition** (`FlowActionDefinition`) is *data*: a name, typed parameters, a result type, a capability and15 whether the user must confirm. It contains no code.16- The **host** (`FlowHost`) is *code compiled into the application*. It receives calls that have already passed17 every check and performs them.18- The **interpreter** connects the two. It never touches tabs, files, the network or an AI provider itself.1920## Defining an action2122```swift23let translate = FlowActionDefinition(24 name: "translate", // one or two lowercase words25 summary: "Translate text.",26 parameters: [27 FlowParameter("content", label: nil, .value([.text])), // positional28 FlowParameter("language", label: "into_language", .option(["french", "english"])),29 ],30 result: .text,31 capability: .ai, // required; pick the narrowest that applies32 confirmation: .never)3334let registry = try FlowActionRegistry.standard.adding([translate])35let compilation = FlowCompiler.compile(source, registry: registry)36```3738`register` rejects definitions that could confuse the parser or weaken the checks:3940- the name is one or two words of lowercase letters/underscores, not reserved, not `wait`, not already taken, and41 cannot share its first word with an action of a different word count (`extract` vs `extract article`);42- at most one positional parameter; labels are single lowercase words, unique, not reserved (`as` excepted);43- value types cannot be `unknown`, `nothing` or `option`; option lists are non-empty lowercase words;44- an action with an `as` parameter cannot return a value;45- a capability is mandatory (only the engine's own `wait` has none).4647Capabilities are open strings (`FlowCapability(rawValue:)`). The built-in ones are `navigate`, `read`, `interact`,48`submit-form`, `ai`, `write-file`, `download`, `write-note`, `write-bookmark`, `notify`. `navigate`, `download`,49`submit-form` and `interact` are treated as networked and force `allow domains`.5051The same registry must be used to compile and to run; the validated program carries it.5253## Implementing the host5455```swift56public protocol FlowHost: Sendable {57 func perform(_ call: FlowActionCall) async throws -> FlowValue58 func confirm(_ request: FlowConfirmationRequest) async -> Bool59}60```6162`FlowActionCall` carries `runID`, `stepID`, `action`, `arguments` (by parameter name), `policy` (the allow-list),63`timeoutSeconds` and `spaceName`.6465Host obligations:66671. Return a value of the declared result type (anything else fails the step as a contract violation).682. Apply `call.policy` to everything the engine cannot see: HTTP redirects, sub-frames it reads, files it fetches.693. Honour task cancellation promptly (timeouts and user cancellation are delivered that way).704. Treat a `FlowPage` whose handle it does not know as stale and reopen `page.url`.715. Treat all text coming from pages as untrusted data, in particular before handing it to an AI provider: page72 content must never be able to change what a workflow does. The engine guarantees this on its side (page text is73 only ever a value), the host must guarantee it in its prompts.746. Never run a workflow for a private (ghost) window with a `FlowRunStore`.7576What the engine guarantees before `perform` is called: the capability was granted for this run, every URL/page77argument is `http(s)` and on the allow-list, the step and duration budgets are not exhausted, and — for actions78with `confirmation: .always` — `confirm` returned `true` for this very step.7980## What a third party could add — and what it cannot8182**Today, in this codebase:** a third party cannot add anything at run time. Registries are built in Swift code that83is compiled into the app; there is no file format, no download, no plug-in loader for action definitions, and no84UI to install one. The extension point above is for code that ships inside the application binary (ORIX's own85modules, or a fork).8687**Workflows themselves** are the user-facing extension mechanism: they can be written, imported (Capsule) and88shared as text. A workflow is data interpreted over the fixed action set of the installed app; importing one never89adds a capability, an action or code.9091### iOS and iPadOS9293- No downloaded or user-supplied **native code** is ever executed, and none could be: iOS only runs code signed in94 the app bundle.95- Flow is a **data-only interpreted DSL over a fixed action set**. It has no way to define functions, no `eval`,96 no access to JavaScriptCore or to a web view's script engine, no dynamic library loading and no way to change97 the action registry. What the app can do after installing a workflow is exactly what it could do before.98- The relevant rule is **App Store Review Guideline 2.5.2** (apps must be self-contained and may not download,99 install or execute code which introduces or changes features or functionality of the app). The design above is100 intended to stay inside it: interpreted text that only selects among built-in, reviewed features.101 **This must be re-checked against Apple's current guideline text (and the clause of the Developer Program License102 Agreement on interpreted code) before any distribution** — the guideline wording changes and this103 document is not a legal review. In particular, adding a way to download action *definitions* or shared workflows104 from a server controlled by ORIX would need a fresh reading of 2.5.2.105106### macOS107108- The same rule applies to the Mac App Store.109- A real third-party extension mechanism on the Mac (new actions implemented by someone else) would have to run110 the extension as a **separate, sandboxed process that the user explicitly authorises** — for example an App111 Extension / ExtensionKit extension or an XPC service with its own entitlements — talking to the app over a112 narrow, typed IPC protocol equivalent to `FlowActionCall` → `FlowValue`, with its declared capabilities shown to113 the user and enforced by the app, not by the extension.114- **This is not implemented.** There is no extension point, no IPC protocol, no discovery and no settings UI for115 it. Nothing in the module loads code from outside the application.116117## Stability118119- Language version: `FlowLanguage.currentVersion` = 1. A workflow declaring another version is rejected120 (`unsupported-version`); nothing is migrated automatically.121- Stored run logs: `FlowRunStore.currentSchemaVersion` = 1, kept in the setting `flow.schema_version`; table122 `flow_runs` (created idempotently by the module, not by Persistence's migrations).123 `NavigatorDatabase.lifecycle.deleteEverything()` does not know this table: the app must also call124 `FlowRunStore.deleteAll()`.125- Diagnostic codes are part of the contract (the editor may key behaviour on them); messages and hints are not.126127## Not verified128129- No real `FlowHost` exists; everything here is exercised with a scripted host in tests.130- No App Review has been attempted. The 2.5.2 reasoning above is the design intent, not a ruling.131