diff --git a/Cargo.lock b/Cargo.lock index 99cd7cf2e..4d3ae0f14 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13347,7 +13347,7 @@ dependencies = [ [[package]] name = "zatex" -version = "0.3.5" +version = "0.3.7" dependencies = [ "tiny-skia", "ttf-parser", @@ -13598,7 +13598,7 @@ dependencies = [ [[package]] name = "zeron" -version = "0.3.5" +version = "0.3.7" dependencies = [ "anyhow", "clap", @@ -13623,7 +13623,7 @@ dependencies = [ [[package]] name = "zeron-audio" -version = "0.3.5" +version = "0.3.7" dependencies = [ "base64 0.22.1", "cpal 0.18.2", @@ -13635,7 +13635,7 @@ dependencies = [ [[package]] name = "zeron-cli" -version = "0.3.5" +version = "0.3.7" dependencies = [ "anyhow", "clap", @@ -13651,7 +13651,7 @@ dependencies = [ [[package]] name = "zeron-client" -version = "0.3.5" +version = "0.3.7" dependencies = [ "anyhow", "async-trait", @@ -13682,7 +13682,7 @@ dependencies = [ [[package]] name = "zeron-doc" -version = "0.3.5" +version = "0.3.7" dependencies = [ "chrono", "loro", @@ -13697,7 +13697,7 @@ dependencies = [ [[package]] name = "zeron-engine" -version = "0.3.5" +version = "0.3.7" dependencies = [ "alacritty_terminal", "anyhow", @@ -13757,7 +13757,7 @@ dependencies = [ [[package]] name = "zeron-harness" -version = "0.3.5" +version = "0.3.7" dependencies = [ "anyhow", "async-trait", @@ -13791,7 +13791,7 @@ dependencies = [ [[package]] name = "zeron-launch" -version = "0.3.5" +version = "0.3.7" dependencies = [ "libc", "tempfile", @@ -13800,14 +13800,14 @@ dependencies = [ [[package]] name = "zeron-markdown" -version = "0.3.5" +version = "0.3.7" dependencies = [ "pulldown-cmark", ] [[package]] name = "zeron-mcp" -version = "0.3.5" +version = "0.3.7" dependencies = [ "anyhow", "async-trait", @@ -13829,7 +13829,7 @@ dependencies = [ [[package]] name = "zeron-mobile" -version = "0.3.5" +version = "0.3.7" dependencies = [ "async-trait", "serde", @@ -13856,14 +13856,14 @@ dependencies = [ [[package]] name = "zeron-mobile-bindgen" -version = "0.3.5" +version = "0.3.7" dependencies = [ "uniffi", ] [[package]] name = "zeron-notify" -version = "0.3.5" +version = "0.3.7" dependencies = [ "objc", "sha2", @@ -13872,11 +13872,11 @@ dependencies = [ [[package]] name = "zeron-orb" -version = "0.3.5" +version = "0.3.7" [[package]] name = "zeron-plugin-guard" -version = "0.3.5" +version = "0.3.7" dependencies = [ "serde_json", "tempfile", @@ -13884,7 +13884,7 @@ dependencies = [ [[package]] name = "zeron-preview" -version = "0.3.5" +version = "0.3.7" dependencies = [ "anyhow", "async-trait", @@ -13914,11 +13914,11 @@ dependencies = [ [[package]] name = "zeron-preview-label" -version = "0.3.5" +version = "0.3.7" [[package]] name = "zeron-proto" -version = "0.3.5" +version = "0.3.7" dependencies = [ "chrono", "pulldown-cmark", @@ -13929,7 +13929,7 @@ dependencies = [ [[package]] name = "zeron-rpc" -version = "0.3.5" +version = "0.3.7" dependencies = [ "anyhow", "async-trait", @@ -13950,7 +13950,7 @@ dependencies = [ [[package]] name = "zeron-sync" -version = "0.3.5" +version = "0.3.7" dependencies = [ "base64 0.22.1", "block2 0.6.2", @@ -13976,7 +13976,7 @@ dependencies = [ [[package]] name = "zeron-syntax" -version = "0.3.5" +version = "0.3.7" dependencies = [ "thiserror 2.0.20", "tree-sitter", @@ -14011,14 +14011,14 @@ dependencies = [ [[package]] name = "zeron-term" -version = "0.3.5" +version = "0.3.7" dependencies = [ "alacritty_terminal", ] [[package]] name = "zeron-term-link" -version = "0.3.5" +version = "0.3.7" dependencies = [ "anyhow", "async-trait", @@ -14035,7 +14035,7 @@ dependencies = [ [[package]] name = "zeron-text" -version = "0.3.5" +version = "0.3.7" dependencies = [ "core-foundation 0.10.1", "core-graphics 0.24.0", @@ -14052,7 +14052,7 @@ dependencies = [ [[package]] name = "zeron-theme" -version = "0.3.5" +version = "0.3.7" dependencies = [ "anyhow", "clap", @@ -14067,7 +14067,7 @@ dependencies = [ [[package]] name = "zeron-ui" -version = "0.3.5" +version = "0.3.7" dependencies = [ "alacritty_terminal", "anyhow", @@ -14150,7 +14150,7 @@ dependencies = [ [[package]] name = "zeron-update" -version = "0.3.5" +version = "0.3.7" dependencies = [ "anyhow", "futures", @@ -14167,11 +14167,11 @@ dependencies = [ [[package]] name = "zeron-veil" -version = "0.3.5" +version = "0.3.7" [[package]] name = "zeron-visual" -version = "0.3.5" +version = "0.3.7" dependencies = [ "base64 0.22.1", "gltf", @@ -14183,7 +14183,7 @@ dependencies = [ [[package]] name = "zeron-visual-gpu" -version = "0.3.5" +version = "0.3.7" dependencies = [ "image", "pollster 0.4.0", @@ -14194,7 +14194,7 @@ dependencies = [ [[package]] name = "zeron-voice" -version = "0.3.5" +version = "0.3.7" dependencies = [ "anyhow", "cpal 0.17.3", @@ -14213,7 +14213,7 @@ dependencies = [ [[package]] name = "zeron-voice-media" -version = "0.3.5" +version = "0.3.7" dependencies = [ "async-trait", "semver", @@ -14228,7 +14228,7 @@ dependencies = [ [[package]] name = "zeron-voice-session" -version = "0.3.5" +version = "0.3.7" dependencies = [ "async-trait", "futures", diff --git a/Cargo.toml b/Cargo.toml index 2b3cdd9bb..7865ac29a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,7 +38,7 @@ members = [ ] [workspace.package] -version = "0.3.5" +version = "0.3.7" edition = "2024" license = "MIT" publish = false diff --git a/apps/zgx/Cargo.lock b/apps/zgx/Cargo.lock index 437ed1ee8..d096e16e9 100644 --- a/apps/zgx/Cargo.lock +++ b/apps/zgx/Cargo.lock @@ -7067,7 +7067,7 @@ dependencies = [ [[package]] name = "zatex" -version = "0.3.5" +version = "0.3.7" dependencies = [ "ttf-parser", ] @@ -7233,7 +7233,7 @@ checksum = "e13084392c5e4bc371903e2935a5eaeed24905a7511356b883835e18a78f6879" [[package]] name = "zeron-cli" -version = "0.3.5" +version = "0.3.7" dependencies = [ "anyhow", "clap", @@ -7248,7 +7248,7 @@ dependencies = [ [[package]] name = "zeron-launch" -version = "0.3.5" +version = "0.3.7" dependencies = [ "libc", "windows-sys 0.61.2", @@ -7256,7 +7256,7 @@ dependencies = [ [[package]] name = "zeron-notify" -version = "0.3.5" +version = "0.3.7" dependencies = [ "objc", "sha2", @@ -7265,18 +7265,18 @@ dependencies = [ [[package]] name = "zeron-plugin-guard" -version = "0.3.5" +version = "0.3.7" dependencies = [ "serde_json", ] [[package]] name = "zeron-preview-label" -version = "0.3.5" +version = "0.3.7" [[package]] name = "zeron-proto" -version = "0.3.5" +version = "0.3.7" dependencies = [ "chrono", "pulldown-cmark 0.12.2", @@ -7287,7 +7287,7 @@ dependencies = [ [[package]] name = "zeron-theme" -version = "0.3.5" +version = "0.3.7" dependencies = [ "anyhow", "clap", @@ -7301,7 +7301,7 @@ dependencies = [ [[package]] name = "zeron-update" -version = "0.3.5" +version = "0.3.7" dependencies = [ "anyhow", "futures", @@ -7318,7 +7318,7 @@ dependencies = [ [[package]] name = "zeron-visual" -version = "0.3.5" +version = "0.3.7" dependencies = [ "base64 0.22.1", "gltf", @@ -7330,7 +7330,7 @@ dependencies = [ [[package]] name = "zeron-visual-gpu" -version = "0.3.5" +version = "0.3.7" dependencies = [ "pollster", "tracing", @@ -7340,7 +7340,7 @@ dependencies = [ [[package]] name = "zeron-voice" -version = "0.3.5" +version = "0.3.7" dependencies = [ "anyhow", "cpal", diff --git a/apps/zgx/docs/plugins.md b/apps/zgx/docs/plugins.md index 6ad2dd6bd..5ac07018a 100644 --- a/apps/zgx/docs/plugins.md +++ b/apps/zgx/docs/plugins.md @@ -52,7 +52,8 @@ Your own plugins are signed as yours, and re-signed and reloaded each time you s | `navigate` | open chats and pages (`zeron.open`) | | `links.open` | open http(s) links (`zeron.open_url`), where you open links (Settings → Links) | | `notifications` | send you notifications (`zeron.notify`), as Zeron's own: Settings → Notifications decides whether they show, a few a minute at most | -| `compose` | put text in the message box (`zeron.compose`), or a review comment on it (`zeron.compose_comment`); you still send it | +| `compose` | put text in the message box, after what's there or in place of its words (`zeron.compose`), or a review comment on it (`zeron.compose_comment`); you still send it | +| `draft` | read the message box's draft as you type it (`zeron.draft`), or any chat's (`zeron.draft_of`), and take it whole, put it back, swap it or let it go (`zeron.take_draft`, `put_draft`, `swap_draft`, `drop_draft`). See [The composer's draft](#the-composers-draft) | | `github`, `github.write` | read (and write) GitHub through Zeron's engine (older calls; prefer `commands` with `gh`) | | `network` | the internet: `ui.fetch`, and remote images (`ui.image { src = "https://…" }`). See [Reaching the network](#reaching-the-network) | | `clipboard`, `files`, `web`, `windows` | zgx's clipboard, file dialogs, web views, windows | @@ -213,9 +214,13 @@ Zeron draws that row on your settings page: "Use as wallpaper", and while it's o | call | what | needs | |---|---|---| | `zeron.open("home" \| { session = id } \| { settings = page })` | open a page | `navigate` | -| `zeron.compose(text)` | text into the message box | `compose` | +| `zeron.compose(text, { replace?, session? })` | text into a chat's draft: after what's there (on a line of its own), or in place of its words (`replace = true`, its chips kept); the chat shown's draft, or `session`'s ([below](#the-composers-draft)) | `compose` | | `zeron.compose_comment { file, line, note, to?, side?, snippet?, key?, session? }` | a review comment on a file or a diff, as a chip on a chat's draft (below) | `compose` | | `zeron.composed()` | in a build: your comments still on a draft, by `key`: `{ session, hovered }` | `compose` | +| `zeron.draft()` | in a build: the message box's draft, `{ session?, text, attachments = { { kind, name } } }` (below) | `draft` | +| `zeron.take_draft(key)`, `zeron.put_draft(key)`, `zeron.swap_draft(key)`, `zeron.drop_draft(key)` | the draft taken whole and kept by Zeron under your key; put back; traded with what the key keeps; let go (below) | `draft` | +| `zeron.drafts()` | in a build: what Zeron keeps for you, by key: `{ session?, text, attachments, at }` | `draft` | +| `zeron.draft_of(session)` | a promise of chat `session`'s draft as it is now, as `zeron.draft()` says it (`""`: a new chat's) | `draft` | | `zeron.toast(text)` | a short note at the window's foot | (always) | | `zeron.need("panel").open_tab { kind, title, icon?, data? }` | a tab of yours in the chat's panel; asked again, the one there is brought forward (found by `data.key` when you give one, else by its title) | `panel.tabs` | | `zeron.tab(kind, function(tab) return node end)` | how a kind of your tabs draws (`tab` = `{ kind, title, data }`) | `panel.tabs` | @@ -274,6 +279,48 @@ Comments on the diff (each cites the file and line it belongs to; L = line numbe Give each a `key` of your own: `zeron.composed()` lists yours still on a draft by it (taken off or sent, gone), and says which one's chip is under the pointer (`hovered`), so the lines it was left on can keep a mark and light up as its chip is pointed at. Zeron's Git plugin does all of this in its Changes (`plugins-builtin/git/changes.luau`): the diff's + (or a drag from it over lines) opens `ds/comment`'s composer under them, using `ds/git_changes`'s `on_comment`, `ranges` and `marks`. +### The composer's draft + +With `draft`, a plugin reads what you're typing and can set it aside and bring it back: a stash for a prompt written in the wrong chat, a counter of its length, a bar that says what it carries. + +- **`zeron.draft()`**, read in a build or an effect, is the draft shown as it changes: `session` (the chat it's for; nil on a new chat), `text` (the words as typed) and `attachments`, each chip's `kind` (`"file"`, `"image"`, `"chat"`, `"comment"`, …) and `name`. A file's path is never in it. +- **`zeron.take_draft(key)`** takes the draft shown whole (its words, its chips, the passages quoted in it) and clears the composer. Zeron keeps it, under your `key` (1 to 64 characters), so your plugin never holds a file's path. An empty draft isn't taken; taking under a key that's kept replaces what it kept. Up to 16 at once. +- **`zeron.put_draft(key)`** puts what `key` kept back on the draft shown, in whichever chat is open, and lets it go. Onto an empty composer it's as it was taken; onto words already there, its words follow after a blank line and its chips after theirs. +- **`zeron.swap_draft(key)`** trades the draft shown with what `key` keeps. Either may be empty, so one call sets the draft aside (nothing kept), brings it back (an empty composer), or swaps the two. +- **`zeron.drop_draft(key)`** lets what `key` kept go. +- **`zeron.drafts()`**, read in a build, is what Zeron keeps for you, by key: `{ session?, text, attachments, at }` (`at` as `os.time()`). Drafts are kept while Zeron runs, as chats' own drafts are. +- **`zeron.draft_of(session)`** reads another chat's draft once, shown or not: a promise of `{ session?, text, attachments }`, as `zeron.draft()` says it (`""` for a new chat's, with no session). + +With `compose` too, a plugin can change the words in place: **`zeron.compose(text, { replace = true })`** puts `text` in place of the draft's words, leaving its chips where they are, and `session` names another chat's draft. A rewrite or a snippet that expands is a read and a replace: + +```lua +-- ("ui.add", "draft", "compose"): /bug alone in the box becomes the template. +ui.effect(function() + local d = zeron.draft() + if d and d.text == "/bug" then + zeron.compose("## What happened\n\n## What I expected\n\n## Steps\n", { replace = true, session = d.session }) + end +end) +``` + +Nothing is sent: the person sees the new words in the composer, and sends or edits them. `zeron.compose` takes 20,000 characters at most. + +Each is done in the order you ask. A prompt stash is one shortcut and one chip: + +```lua +-- ⌘⇧S (Ctrl+Shift+S): set the draft aside, bring it back, or swap the two. +ui.command { id = "stash", title = "Stash prompt", key = "cmd+shift+s", run = function() + zeron.swap_draft("stash") +end } + +-- While one is kept, a chip over the composer: click to bring it back. +zeron.place { at = "#chat-composer", before = function(): Node + return ui.show(function(): boolean + return zeron.drafts().stash ~= nil + end, ui.button { "Stashed", on_click = function() zeron.swap_draft("stash") end }) +end } +``` + ## Programs and a database A plugin can do real work of its own: run the command-line tools you already use, and keep what it learns. diff --git a/apps/zgx/plugins-builtin/git/zeron.luau b/apps/zgx/plugins-builtin/git/zeron.luau index c5f896393..553b6cc16 100644 --- a/apps/zgx/plugins-builtin/git/zeron.luau +++ b/apps/zgx/plugins-builtin/git/zeron.luau @@ -69,13 +69,31 @@ -- zeron.on_message(function(message) end) -- what arrives: { from = { id, name }, data, at } ("devices") -- zeron.open(route) "home", { session = id }, { settings = page } ("navigate") --- zeron.compose(text) text into the message box, for you to send ("compose") +-- zeron.compose(text, { replace?, session? }) +-- text into the message box, for you to send: after +-- what's there, or in place of its words (`replace = +-- true`, its chips kept); the chat shown's draft, or +-- `session`'s ("compose") -- zeron.compose_comment { file, line, note, to?, side?, snippet?, key?, session? } -- a review comment chip on a session's draft, sent as -- Zeron's review comments block (file:line, the note, -- the code under it) ("compose") -- zeron.composed() in a build: your comments still on a draft, by key -- ({ [key] = { session, hovered } }), reactive ("compose") +-- zeron.draft() the composer's draft as you type it: { session?, +-- text, attachments = { { kind, name } } }, reactive +-- ("draft") +-- zeron.take_draft(key), zeron.put_draft(key), zeron.swap_draft(key), +-- zeron.drop_draft(key) +-- the draft taken whole (words, chips, quotes) and +-- kept by Zeron under your key, the composer +-- cleared; put back on the draft shown; the two +-- traded; let go ("draft") +-- zeron.drafts() what Zeron keeps for you, by key: { session?, text, +-- attachments, at }, reactive ("draft") +-- zeron.draft_of(session) +-- a promise of another chat's draft, as `draft()` +-- says it, read once ("" a new chat's) ("draft") -- zeron.toast(text) a short note at the window's foot (always) -- zeron.notify { title, body?, session? } a notification, as Zeron's -- own (Settings → Notifications) ("notifications") @@ -1343,8 +1361,16 @@ return function(id: string): any ui.invoke(`{prefix}.open_url`, url) end - function M.compose(text: string) - ui.invoke("zeron.compose.insert", text) + -- `text` into a chat's draft, for the person to send ("compose"): after + -- what's there, on a line of its own; with `replace = true`, in place of + -- its words (what it carries stays). The chat shown's draft, or + -- `session`'s ("" a new chat's). + function M.compose(text: string, opts: { replace: boolean?, session: string? }?) + if opts and (opts.replace or opts.session) then + ui.invoke("zeron.compose.insert", { text = text, replace = opts.replace == true, session = opts.session or ui.null }) + else + ui.invoke("zeron.compose.insert", text) + end end -- A review comment on a file or a diff, as a chip on a session's draft @@ -1374,6 +1400,57 @@ return function(id: string): any return composed:get() or {} end + -- The composer's draft as you type it: the chat it's for (nil, a new + -- chat), its words, and what it carries, each chip's kind ("file", + -- "image", "chat", …) and name, never a file's path. Read in a build or + -- an effect: it changes as the draft does. Nil until Zeron says. + -- (Reached on first read: only a plugin allowed "draft" may.) + local draft: any = nil + function M.draft(): { session: string?, text: string, attachments: { { kind: string, name: string } } }? + draft = draft or ui.shared("zeron.draft", nil :: any) + return draft:get() + end + + -- The draft shown, taken whole (its words, its chips, the passages + -- quoted in it) and kept by Zeron under `key`, yours, the composer + -- cleared; what that key kept before is replaced. An empty draft isn't + -- taken. Up to 16 kept at once. + function M.take_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "take", key = key }) + end + + -- What `key` kept, put back on the draft shown as it was taken (after + -- what's there, if the composer isn't empty), and no longer kept. + function M.put_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "put", key = key }) + end + + -- The draft shown and what `key` keeps, traded: either may be empty, so + -- one call sets the draft aside, brings it back, or swaps the two. + function M.swap_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "swap", key = key }) + end + + -- What `key` kept, let go of. + function M.drop_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "drop", key = key }) + end + + -- What Zeron keeps for you, by key: the chat each was taken from, its + -- words, what it carries (as `draft()` says it) and when (os.time). + -- Read in a build: it changes as you take and put back. + local drafts = ui.shared(`{prefix}.drafts`, {} :: { [string]: any }) + function M.drafts(): { [string]: { session: string?, text: string, attachments: { { kind: string, name: string } }, at: number } } + return drafts:get() or {} + end + + -- Chat `session`'s draft as it is now, unsent: shown or not (`draft()` + -- follows the one shown). A promise of { session?, text, attachments } + -- as `draft()` says it ("" a new chat's draft, with no session). + function M.draft_of(session: string): any + return ui.call(`{prefix}.draft_of`, session) + end + function M.toast(text: string) ui.invoke(`{prefix}.toast`, text) end diff --git a/apps/zgx/plugins-builtin/github/zeron.luau b/apps/zgx/plugins-builtin/github/zeron.luau index c5f896393..553b6cc16 100644 --- a/apps/zgx/plugins-builtin/github/zeron.luau +++ b/apps/zgx/plugins-builtin/github/zeron.luau @@ -69,13 +69,31 @@ -- zeron.on_message(function(message) end) -- what arrives: { from = { id, name }, data, at } ("devices") -- zeron.open(route) "home", { session = id }, { settings = page } ("navigate") --- zeron.compose(text) text into the message box, for you to send ("compose") +-- zeron.compose(text, { replace?, session? }) +-- text into the message box, for you to send: after +-- what's there, or in place of its words (`replace = +-- true`, its chips kept); the chat shown's draft, or +-- `session`'s ("compose") -- zeron.compose_comment { file, line, note, to?, side?, snippet?, key?, session? } -- a review comment chip on a session's draft, sent as -- Zeron's review comments block (file:line, the note, -- the code under it) ("compose") -- zeron.composed() in a build: your comments still on a draft, by key -- ({ [key] = { session, hovered } }), reactive ("compose") +-- zeron.draft() the composer's draft as you type it: { session?, +-- text, attachments = { { kind, name } } }, reactive +-- ("draft") +-- zeron.take_draft(key), zeron.put_draft(key), zeron.swap_draft(key), +-- zeron.drop_draft(key) +-- the draft taken whole (words, chips, quotes) and +-- kept by Zeron under your key, the composer +-- cleared; put back on the draft shown; the two +-- traded; let go ("draft") +-- zeron.drafts() what Zeron keeps for you, by key: { session?, text, +-- attachments, at }, reactive ("draft") +-- zeron.draft_of(session) +-- a promise of another chat's draft, as `draft()` +-- says it, read once ("" a new chat's) ("draft") -- zeron.toast(text) a short note at the window's foot (always) -- zeron.notify { title, body?, session? } a notification, as Zeron's -- own (Settings → Notifications) ("notifications") @@ -1343,8 +1361,16 @@ return function(id: string): any ui.invoke(`{prefix}.open_url`, url) end - function M.compose(text: string) - ui.invoke("zeron.compose.insert", text) + -- `text` into a chat's draft, for the person to send ("compose"): after + -- what's there, on a line of its own; with `replace = true`, in place of + -- its words (what it carries stays). The chat shown's draft, or + -- `session`'s ("" a new chat's). + function M.compose(text: string, opts: { replace: boolean?, session: string? }?) + if opts and (opts.replace or opts.session) then + ui.invoke("zeron.compose.insert", { text = text, replace = opts.replace == true, session = opts.session or ui.null }) + else + ui.invoke("zeron.compose.insert", text) + end end -- A review comment on a file or a diff, as a chip on a session's draft @@ -1374,6 +1400,57 @@ return function(id: string): any return composed:get() or {} end + -- The composer's draft as you type it: the chat it's for (nil, a new + -- chat), its words, and what it carries, each chip's kind ("file", + -- "image", "chat", …) and name, never a file's path. Read in a build or + -- an effect: it changes as the draft does. Nil until Zeron says. + -- (Reached on first read: only a plugin allowed "draft" may.) + local draft: any = nil + function M.draft(): { session: string?, text: string, attachments: { { kind: string, name: string } } }? + draft = draft or ui.shared("zeron.draft", nil :: any) + return draft:get() + end + + -- The draft shown, taken whole (its words, its chips, the passages + -- quoted in it) and kept by Zeron under `key`, yours, the composer + -- cleared; what that key kept before is replaced. An empty draft isn't + -- taken. Up to 16 kept at once. + function M.take_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "take", key = key }) + end + + -- What `key` kept, put back on the draft shown as it was taken (after + -- what's there, if the composer isn't empty), and no longer kept. + function M.put_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "put", key = key }) + end + + -- The draft shown and what `key` keeps, traded: either may be empty, so + -- one call sets the draft aside, brings it back, or swaps the two. + function M.swap_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "swap", key = key }) + end + + -- What `key` kept, let go of. + function M.drop_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "drop", key = key }) + end + + -- What Zeron keeps for you, by key: the chat each was taken from, its + -- words, what it carries (as `draft()` says it) and when (os.time). + -- Read in a build: it changes as you take and put back. + local drafts = ui.shared(`{prefix}.drafts`, {} :: { [string]: any }) + function M.drafts(): { [string]: { session: string?, text: string, attachments: { { kind: string, name: string } }, at: number } } + return drafts:get() or {} + end + + -- Chat `session`'s draft as it is now, unsent: shown or not (`draft()` + -- follows the one shown). A promise of { session?, text, attachments } + -- as `draft()` says it ("" a new chat's draft, with no session). + function M.draft_of(session: string): any + return ui.call(`{prefix}.draft_of`, session) + end + function M.toast(text: string) ui.invoke(`{prefix}.toast`, text) end diff --git a/apps/zgx/plugins-builtin/parallax-scenes/zeron.luau b/apps/zgx/plugins-builtin/parallax-scenes/zeron.luau index c5f896393..553b6cc16 100644 --- a/apps/zgx/plugins-builtin/parallax-scenes/zeron.luau +++ b/apps/zgx/plugins-builtin/parallax-scenes/zeron.luau @@ -69,13 +69,31 @@ -- zeron.on_message(function(message) end) -- what arrives: { from = { id, name }, data, at } ("devices") -- zeron.open(route) "home", { session = id }, { settings = page } ("navigate") --- zeron.compose(text) text into the message box, for you to send ("compose") +-- zeron.compose(text, { replace?, session? }) +-- text into the message box, for you to send: after +-- what's there, or in place of its words (`replace = +-- true`, its chips kept); the chat shown's draft, or +-- `session`'s ("compose") -- zeron.compose_comment { file, line, note, to?, side?, snippet?, key?, session? } -- a review comment chip on a session's draft, sent as -- Zeron's review comments block (file:line, the note, -- the code under it) ("compose") -- zeron.composed() in a build: your comments still on a draft, by key -- ({ [key] = { session, hovered } }), reactive ("compose") +-- zeron.draft() the composer's draft as you type it: { session?, +-- text, attachments = { { kind, name } } }, reactive +-- ("draft") +-- zeron.take_draft(key), zeron.put_draft(key), zeron.swap_draft(key), +-- zeron.drop_draft(key) +-- the draft taken whole (words, chips, quotes) and +-- kept by Zeron under your key, the composer +-- cleared; put back on the draft shown; the two +-- traded; let go ("draft") +-- zeron.drafts() what Zeron keeps for you, by key: { session?, text, +-- attachments, at }, reactive ("draft") +-- zeron.draft_of(session) +-- a promise of another chat's draft, as `draft()` +-- says it, read once ("" a new chat's) ("draft") -- zeron.toast(text) a short note at the window's foot (always) -- zeron.notify { title, body?, session? } a notification, as Zeron's -- own (Settings → Notifications) ("notifications") @@ -1343,8 +1361,16 @@ return function(id: string): any ui.invoke(`{prefix}.open_url`, url) end - function M.compose(text: string) - ui.invoke("zeron.compose.insert", text) + -- `text` into a chat's draft, for the person to send ("compose"): after + -- what's there, on a line of its own; with `replace = true`, in place of + -- its words (what it carries stays). The chat shown's draft, or + -- `session`'s ("" a new chat's). + function M.compose(text: string, opts: { replace: boolean?, session: string? }?) + if opts and (opts.replace or opts.session) then + ui.invoke("zeron.compose.insert", { text = text, replace = opts.replace == true, session = opts.session or ui.null }) + else + ui.invoke("zeron.compose.insert", text) + end end -- A review comment on a file or a diff, as a chip on a session's draft @@ -1374,6 +1400,57 @@ return function(id: string): any return composed:get() or {} end + -- The composer's draft as you type it: the chat it's for (nil, a new + -- chat), its words, and what it carries, each chip's kind ("file", + -- "image", "chat", …) and name, never a file's path. Read in a build or + -- an effect: it changes as the draft does. Nil until Zeron says. + -- (Reached on first read: only a plugin allowed "draft" may.) + local draft: any = nil + function M.draft(): { session: string?, text: string, attachments: { { kind: string, name: string } } }? + draft = draft or ui.shared("zeron.draft", nil :: any) + return draft:get() + end + + -- The draft shown, taken whole (its words, its chips, the passages + -- quoted in it) and kept by Zeron under `key`, yours, the composer + -- cleared; what that key kept before is replaced. An empty draft isn't + -- taken. Up to 16 kept at once. + function M.take_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "take", key = key }) + end + + -- What `key` kept, put back on the draft shown as it was taken (after + -- what's there, if the composer isn't empty), and no longer kept. + function M.put_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "put", key = key }) + end + + -- The draft shown and what `key` keeps, traded: either may be empty, so + -- one call sets the draft aside, brings it back, or swaps the two. + function M.swap_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "swap", key = key }) + end + + -- What `key` kept, let go of. + function M.drop_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "drop", key = key }) + end + + -- What Zeron keeps for you, by key: the chat each was taken from, its + -- words, what it carries (as `draft()` says it) and when (os.time). + -- Read in a build: it changes as you take and put back. + local drafts = ui.shared(`{prefix}.drafts`, {} :: { [string]: any }) + function M.drafts(): { [string]: { session: string?, text: string, attachments: { { kind: string, name: string } }, at: number } } + return drafts:get() or {} + end + + -- Chat `session`'s draft as it is now, unsent: shown or not (`draft()` + -- follows the one shown). A promise of { session?, text, attachments } + -- as `draft()` says it ("" a new chat's draft, with no session). + function M.draft_of(session: string): any + return ui.call(`{prefix}.draft_of`, session) + end + function M.toast(text: string) ui.invoke(`{prefix}.toast`, text) end diff --git a/apps/zgx/plugins-dev/account-pin/zeron.luau b/apps/zgx/plugins-dev/account-pin/zeron.luau index c5f896393..553b6cc16 100644 --- a/apps/zgx/plugins-dev/account-pin/zeron.luau +++ b/apps/zgx/plugins-dev/account-pin/zeron.luau @@ -69,13 +69,31 @@ -- zeron.on_message(function(message) end) -- what arrives: { from = { id, name }, data, at } ("devices") -- zeron.open(route) "home", { session = id }, { settings = page } ("navigate") --- zeron.compose(text) text into the message box, for you to send ("compose") +-- zeron.compose(text, { replace?, session? }) +-- text into the message box, for you to send: after +-- what's there, or in place of its words (`replace = +-- true`, its chips kept); the chat shown's draft, or +-- `session`'s ("compose") -- zeron.compose_comment { file, line, note, to?, side?, snippet?, key?, session? } -- a review comment chip on a session's draft, sent as -- Zeron's review comments block (file:line, the note, -- the code under it) ("compose") -- zeron.composed() in a build: your comments still on a draft, by key -- ({ [key] = { session, hovered } }), reactive ("compose") +-- zeron.draft() the composer's draft as you type it: { session?, +-- text, attachments = { { kind, name } } }, reactive +-- ("draft") +-- zeron.take_draft(key), zeron.put_draft(key), zeron.swap_draft(key), +-- zeron.drop_draft(key) +-- the draft taken whole (words, chips, quotes) and +-- kept by Zeron under your key, the composer +-- cleared; put back on the draft shown; the two +-- traded; let go ("draft") +-- zeron.drafts() what Zeron keeps for you, by key: { session?, text, +-- attachments, at }, reactive ("draft") +-- zeron.draft_of(session) +-- a promise of another chat's draft, as `draft()` +-- says it, read once ("" a new chat's) ("draft") -- zeron.toast(text) a short note at the window's foot (always) -- zeron.notify { title, body?, session? } a notification, as Zeron's -- own (Settings → Notifications) ("notifications") @@ -1343,8 +1361,16 @@ return function(id: string): any ui.invoke(`{prefix}.open_url`, url) end - function M.compose(text: string) - ui.invoke("zeron.compose.insert", text) + -- `text` into a chat's draft, for the person to send ("compose"): after + -- what's there, on a line of its own; with `replace = true`, in place of + -- its words (what it carries stays). The chat shown's draft, or + -- `session`'s ("" a new chat's). + function M.compose(text: string, opts: { replace: boolean?, session: string? }?) + if opts and (opts.replace or opts.session) then + ui.invoke("zeron.compose.insert", { text = text, replace = opts.replace == true, session = opts.session or ui.null }) + else + ui.invoke("zeron.compose.insert", text) + end end -- A review comment on a file or a diff, as a chip on a session's draft @@ -1374,6 +1400,57 @@ return function(id: string): any return composed:get() or {} end + -- The composer's draft as you type it: the chat it's for (nil, a new + -- chat), its words, and what it carries, each chip's kind ("file", + -- "image", "chat", …) and name, never a file's path. Read in a build or + -- an effect: it changes as the draft does. Nil until Zeron says. + -- (Reached on first read: only a plugin allowed "draft" may.) + local draft: any = nil + function M.draft(): { session: string?, text: string, attachments: { { kind: string, name: string } } }? + draft = draft or ui.shared("zeron.draft", nil :: any) + return draft:get() + end + + -- The draft shown, taken whole (its words, its chips, the passages + -- quoted in it) and kept by Zeron under `key`, yours, the composer + -- cleared; what that key kept before is replaced. An empty draft isn't + -- taken. Up to 16 kept at once. + function M.take_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "take", key = key }) + end + + -- What `key` kept, put back on the draft shown as it was taken (after + -- what's there, if the composer isn't empty), and no longer kept. + function M.put_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "put", key = key }) + end + + -- The draft shown and what `key` keeps, traded: either may be empty, so + -- one call sets the draft aside, brings it back, or swaps the two. + function M.swap_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "swap", key = key }) + end + + -- What `key` kept, let go of. + function M.drop_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "drop", key = key }) + end + + -- What Zeron keeps for you, by key: the chat each was taken from, its + -- words, what it carries (as `draft()` says it) and when (os.time). + -- Read in a build: it changes as you take and put back. + local drafts = ui.shared(`{prefix}.drafts`, {} :: { [string]: any }) + function M.drafts(): { [string]: { session: string?, text: string, attachments: { { kind: string, name: string } }, at: number } } + return drafts:get() or {} + end + + -- Chat `session`'s draft as it is now, unsent: shown or not (`draft()` + -- follows the one shown). A promise of { session?, text, attachments } + -- as `draft()` says it ("" a new chat's draft, with no session). + function M.draft_of(session: string): any + return ui.call(`{prefix}.draft_of`, session) + end + function M.toast(text: string) ui.invoke(`{prefix}.toast`, text) end diff --git a/apps/zgx/plugins-dev/account-rotate/zeron.luau b/apps/zgx/plugins-dev/account-rotate/zeron.luau index c5f896393..553b6cc16 100644 --- a/apps/zgx/plugins-dev/account-rotate/zeron.luau +++ b/apps/zgx/plugins-dev/account-rotate/zeron.luau @@ -69,13 +69,31 @@ -- zeron.on_message(function(message) end) -- what arrives: { from = { id, name }, data, at } ("devices") -- zeron.open(route) "home", { session = id }, { settings = page } ("navigate") --- zeron.compose(text) text into the message box, for you to send ("compose") +-- zeron.compose(text, { replace?, session? }) +-- text into the message box, for you to send: after +-- what's there, or in place of its words (`replace = +-- true`, its chips kept); the chat shown's draft, or +-- `session`'s ("compose") -- zeron.compose_comment { file, line, note, to?, side?, snippet?, key?, session? } -- a review comment chip on a session's draft, sent as -- Zeron's review comments block (file:line, the note, -- the code under it) ("compose") -- zeron.composed() in a build: your comments still on a draft, by key -- ({ [key] = { session, hovered } }), reactive ("compose") +-- zeron.draft() the composer's draft as you type it: { session?, +-- text, attachments = { { kind, name } } }, reactive +-- ("draft") +-- zeron.take_draft(key), zeron.put_draft(key), zeron.swap_draft(key), +-- zeron.drop_draft(key) +-- the draft taken whole (words, chips, quotes) and +-- kept by Zeron under your key, the composer +-- cleared; put back on the draft shown; the two +-- traded; let go ("draft") +-- zeron.drafts() what Zeron keeps for you, by key: { session?, text, +-- attachments, at }, reactive ("draft") +-- zeron.draft_of(session) +-- a promise of another chat's draft, as `draft()` +-- says it, read once ("" a new chat's) ("draft") -- zeron.toast(text) a short note at the window's foot (always) -- zeron.notify { title, body?, session? } a notification, as Zeron's -- own (Settings → Notifications) ("notifications") @@ -1343,8 +1361,16 @@ return function(id: string): any ui.invoke(`{prefix}.open_url`, url) end - function M.compose(text: string) - ui.invoke("zeron.compose.insert", text) + -- `text` into a chat's draft, for the person to send ("compose"): after + -- what's there, on a line of its own; with `replace = true`, in place of + -- its words (what it carries stays). The chat shown's draft, or + -- `session`'s ("" a new chat's). + function M.compose(text: string, opts: { replace: boolean?, session: string? }?) + if opts and (opts.replace or opts.session) then + ui.invoke("zeron.compose.insert", { text = text, replace = opts.replace == true, session = opts.session or ui.null }) + else + ui.invoke("zeron.compose.insert", text) + end end -- A review comment on a file or a diff, as a chip on a session's draft @@ -1374,6 +1400,57 @@ return function(id: string): any return composed:get() or {} end + -- The composer's draft as you type it: the chat it's for (nil, a new + -- chat), its words, and what it carries, each chip's kind ("file", + -- "image", "chat", …) and name, never a file's path. Read in a build or + -- an effect: it changes as the draft does. Nil until Zeron says. + -- (Reached on first read: only a plugin allowed "draft" may.) + local draft: any = nil + function M.draft(): { session: string?, text: string, attachments: { { kind: string, name: string } } }? + draft = draft or ui.shared("zeron.draft", nil :: any) + return draft:get() + end + + -- The draft shown, taken whole (its words, its chips, the passages + -- quoted in it) and kept by Zeron under `key`, yours, the composer + -- cleared; what that key kept before is replaced. An empty draft isn't + -- taken. Up to 16 kept at once. + function M.take_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "take", key = key }) + end + + -- What `key` kept, put back on the draft shown as it was taken (after + -- what's there, if the composer isn't empty), and no longer kept. + function M.put_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "put", key = key }) + end + + -- The draft shown and what `key` keeps, traded: either may be empty, so + -- one call sets the draft aside, brings it back, or swaps the two. + function M.swap_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "swap", key = key }) + end + + -- What `key` kept, let go of. + function M.drop_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "drop", key = key }) + end + + -- What Zeron keeps for you, by key: the chat each was taken from, its + -- words, what it carries (as `draft()` says it) and when (os.time). + -- Read in a build: it changes as you take and put back. + local drafts = ui.shared(`{prefix}.drafts`, {} :: { [string]: any }) + function M.drafts(): { [string]: { session: string?, text: string, attachments: { { kind: string, name: string } }, at: number } } + return drafts:get() or {} + end + + -- Chat `session`'s draft as it is now, unsent: shown or not (`draft()` + -- follows the one shown). A promise of { session?, text, attachments } + -- as `draft()` says it ("" a new chat's draft, with no session). + function M.draft_of(session: string): any + return ui.call(`{prefix}.draft_of`, session) + end + function M.toast(text: string) ui.invoke(`{prefix}.toast`, text) end diff --git a/apps/zgx/plugins-dev/checkout-status/zeron.luau b/apps/zgx/plugins-dev/checkout-status/zeron.luau index c5f896393..553b6cc16 100644 --- a/apps/zgx/plugins-dev/checkout-status/zeron.luau +++ b/apps/zgx/plugins-dev/checkout-status/zeron.luau @@ -69,13 +69,31 @@ -- zeron.on_message(function(message) end) -- what arrives: { from = { id, name }, data, at } ("devices") -- zeron.open(route) "home", { session = id }, { settings = page } ("navigate") --- zeron.compose(text) text into the message box, for you to send ("compose") +-- zeron.compose(text, { replace?, session? }) +-- text into the message box, for you to send: after +-- what's there, or in place of its words (`replace = +-- true`, its chips kept); the chat shown's draft, or +-- `session`'s ("compose") -- zeron.compose_comment { file, line, note, to?, side?, snippet?, key?, session? } -- a review comment chip on a session's draft, sent as -- Zeron's review comments block (file:line, the note, -- the code under it) ("compose") -- zeron.composed() in a build: your comments still on a draft, by key -- ({ [key] = { session, hovered } }), reactive ("compose") +-- zeron.draft() the composer's draft as you type it: { session?, +-- text, attachments = { { kind, name } } }, reactive +-- ("draft") +-- zeron.take_draft(key), zeron.put_draft(key), zeron.swap_draft(key), +-- zeron.drop_draft(key) +-- the draft taken whole (words, chips, quotes) and +-- kept by Zeron under your key, the composer +-- cleared; put back on the draft shown; the two +-- traded; let go ("draft") +-- zeron.drafts() what Zeron keeps for you, by key: { session?, text, +-- attachments, at }, reactive ("draft") +-- zeron.draft_of(session) +-- a promise of another chat's draft, as `draft()` +-- says it, read once ("" a new chat's) ("draft") -- zeron.toast(text) a short note at the window's foot (always) -- zeron.notify { title, body?, session? } a notification, as Zeron's -- own (Settings → Notifications) ("notifications") @@ -1343,8 +1361,16 @@ return function(id: string): any ui.invoke(`{prefix}.open_url`, url) end - function M.compose(text: string) - ui.invoke("zeron.compose.insert", text) + -- `text` into a chat's draft, for the person to send ("compose"): after + -- what's there, on a line of its own; with `replace = true`, in place of + -- its words (what it carries stays). The chat shown's draft, or + -- `session`'s ("" a new chat's). + function M.compose(text: string, opts: { replace: boolean?, session: string? }?) + if opts and (opts.replace or opts.session) then + ui.invoke("zeron.compose.insert", { text = text, replace = opts.replace == true, session = opts.session or ui.null }) + else + ui.invoke("zeron.compose.insert", text) + end end -- A review comment on a file or a diff, as a chip on a session's draft @@ -1374,6 +1400,57 @@ return function(id: string): any return composed:get() or {} end + -- The composer's draft as you type it: the chat it's for (nil, a new + -- chat), its words, and what it carries, each chip's kind ("file", + -- "image", "chat", …) and name, never a file's path. Read in a build or + -- an effect: it changes as the draft does. Nil until Zeron says. + -- (Reached on first read: only a plugin allowed "draft" may.) + local draft: any = nil + function M.draft(): { session: string?, text: string, attachments: { { kind: string, name: string } } }? + draft = draft or ui.shared("zeron.draft", nil :: any) + return draft:get() + end + + -- The draft shown, taken whole (its words, its chips, the passages + -- quoted in it) and kept by Zeron under `key`, yours, the composer + -- cleared; what that key kept before is replaced. An empty draft isn't + -- taken. Up to 16 kept at once. + function M.take_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "take", key = key }) + end + + -- What `key` kept, put back on the draft shown as it was taken (after + -- what's there, if the composer isn't empty), and no longer kept. + function M.put_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "put", key = key }) + end + + -- The draft shown and what `key` keeps, traded: either may be empty, so + -- one call sets the draft aside, brings it back, or swaps the two. + function M.swap_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "swap", key = key }) + end + + -- What `key` kept, let go of. + function M.drop_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "drop", key = key }) + end + + -- What Zeron keeps for you, by key: the chat each was taken from, its + -- words, what it carries (as `draft()` says it) and when (os.time). + -- Read in a build: it changes as you take and put back. + local drafts = ui.shared(`{prefix}.drafts`, {} :: { [string]: any }) + function M.drafts(): { [string]: { session: string?, text: string, attachments: { { kind: string, name: string } }, at: number } } + return drafts:get() or {} + end + + -- Chat `session`'s draft as it is now, unsent: shown or not (`draft()` + -- follows the one shown). A promise of { session?, text, attachments } + -- as `draft()` says it ("" a new chat's draft, with no session). + function M.draft_of(session: string): any + return ui.call(`{prefix}.draft_of`, session) + end + function M.toast(text: string) ui.invoke(`{prefix}.toast`, text) end diff --git a/apps/zgx/plugins-dev/compact-sidebar/zeron.luau b/apps/zgx/plugins-dev/compact-sidebar/zeron.luau index c5f896393..553b6cc16 100644 --- a/apps/zgx/plugins-dev/compact-sidebar/zeron.luau +++ b/apps/zgx/plugins-dev/compact-sidebar/zeron.luau @@ -69,13 +69,31 @@ -- zeron.on_message(function(message) end) -- what arrives: { from = { id, name }, data, at } ("devices") -- zeron.open(route) "home", { session = id }, { settings = page } ("navigate") --- zeron.compose(text) text into the message box, for you to send ("compose") +-- zeron.compose(text, { replace?, session? }) +-- text into the message box, for you to send: after +-- what's there, or in place of its words (`replace = +-- true`, its chips kept); the chat shown's draft, or +-- `session`'s ("compose") -- zeron.compose_comment { file, line, note, to?, side?, snippet?, key?, session? } -- a review comment chip on a session's draft, sent as -- Zeron's review comments block (file:line, the note, -- the code under it) ("compose") -- zeron.composed() in a build: your comments still on a draft, by key -- ({ [key] = { session, hovered } }), reactive ("compose") +-- zeron.draft() the composer's draft as you type it: { session?, +-- text, attachments = { { kind, name } } }, reactive +-- ("draft") +-- zeron.take_draft(key), zeron.put_draft(key), zeron.swap_draft(key), +-- zeron.drop_draft(key) +-- the draft taken whole (words, chips, quotes) and +-- kept by Zeron under your key, the composer +-- cleared; put back on the draft shown; the two +-- traded; let go ("draft") +-- zeron.drafts() what Zeron keeps for you, by key: { session?, text, +-- attachments, at }, reactive ("draft") +-- zeron.draft_of(session) +-- a promise of another chat's draft, as `draft()` +-- says it, read once ("" a new chat's) ("draft") -- zeron.toast(text) a short note at the window's foot (always) -- zeron.notify { title, body?, session? } a notification, as Zeron's -- own (Settings → Notifications) ("notifications") @@ -1343,8 +1361,16 @@ return function(id: string): any ui.invoke(`{prefix}.open_url`, url) end - function M.compose(text: string) - ui.invoke("zeron.compose.insert", text) + -- `text` into a chat's draft, for the person to send ("compose"): after + -- what's there, on a line of its own; with `replace = true`, in place of + -- its words (what it carries stays). The chat shown's draft, or + -- `session`'s ("" a new chat's). + function M.compose(text: string, opts: { replace: boolean?, session: string? }?) + if opts and (opts.replace or opts.session) then + ui.invoke("zeron.compose.insert", { text = text, replace = opts.replace == true, session = opts.session or ui.null }) + else + ui.invoke("zeron.compose.insert", text) + end end -- A review comment on a file or a diff, as a chip on a session's draft @@ -1374,6 +1400,57 @@ return function(id: string): any return composed:get() or {} end + -- The composer's draft as you type it: the chat it's for (nil, a new + -- chat), its words, and what it carries, each chip's kind ("file", + -- "image", "chat", …) and name, never a file's path. Read in a build or + -- an effect: it changes as the draft does. Nil until Zeron says. + -- (Reached on first read: only a plugin allowed "draft" may.) + local draft: any = nil + function M.draft(): { session: string?, text: string, attachments: { { kind: string, name: string } } }? + draft = draft or ui.shared("zeron.draft", nil :: any) + return draft:get() + end + + -- The draft shown, taken whole (its words, its chips, the passages + -- quoted in it) and kept by Zeron under `key`, yours, the composer + -- cleared; what that key kept before is replaced. An empty draft isn't + -- taken. Up to 16 kept at once. + function M.take_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "take", key = key }) + end + + -- What `key` kept, put back on the draft shown as it was taken (after + -- what's there, if the composer isn't empty), and no longer kept. + function M.put_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "put", key = key }) + end + + -- The draft shown and what `key` keeps, traded: either may be empty, so + -- one call sets the draft aside, brings it back, or swaps the two. + function M.swap_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "swap", key = key }) + end + + -- What `key` kept, let go of. + function M.drop_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "drop", key = key }) + end + + -- What Zeron keeps for you, by key: the chat each was taken from, its + -- words, what it carries (as `draft()` says it) and when (os.time). + -- Read in a build: it changes as you take and put back. + local drafts = ui.shared(`{prefix}.drafts`, {} :: { [string]: any }) + function M.drafts(): { [string]: { session: string?, text: string, attachments: { { kind: string, name: string } }, at: number } } + return drafts:get() or {} + end + + -- Chat `session`'s draft as it is now, unsent: shown or not (`draft()` + -- follows the one shown). A promise of { session?, text, attachments } + -- as `draft()` says it ("" a new chat's draft, with no session). + function M.draft_of(session: string): any + return ui.call(`{prefix}.draft_of`, session) + end + function M.toast(text: string) ui.invoke(`{prefix}.toast`, text) end diff --git a/apps/zgx/plugins-dev/composer-cat/zeron.luau b/apps/zgx/plugins-dev/composer-cat/zeron.luau index c5f896393..553b6cc16 100644 --- a/apps/zgx/plugins-dev/composer-cat/zeron.luau +++ b/apps/zgx/plugins-dev/composer-cat/zeron.luau @@ -69,13 +69,31 @@ -- zeron.on_message(function(message) end) -- what arrives: { from = { id, name }, data, at } ("devices") -- zeron.open(route) "home", { session = id }, { settings = page } ("navigate") --- zeron.compose(text) text into the message box, for you to send ("compose") +-- zeron.compose(text, { replace?, session? }) +-- text into the message box, for you to send: after +-- what's there, or in place of its words (`replace = +-- true`, its chips kept); the chat shown's draft, or +-- `session`'s ("compose") -- zeron.compose_comment { file, line, note, to?, side?, snippet?, key?, session? } -- a review comment chip on a session's draft, sent as -- Zeron's review comments block (file:line, the note, -- the code under it) ("compose") -- zeron.composed() in a build: your comments still on a draft, by key -- ({ [key] = { session, hovered } }), reactive ("compose") +-- zeron.draft() the composer's draft as you type it: { session?, +-- text, attachments = { { kind, name } } }, reactive +-- ("draft") +-- zeron.take_draft(key), zeron.put_draft(key), zeron.swap_draft(key), +-- zeron.drop_draft(key) +-- the draft taken whole (words, chips, quotes) and +-- kept by Zeron under your key, the composer +-- cleared; put back on the draft shown; the two +-- traded; let go ("draft") +-- zeron.drafts() what Zeron keeps for you, by key: { session?, text, +-- attachments, at }, reactive ("draft") +-- zeron.draft_of(session) +-- a promise of another chat's draft, as `draft()` +-- says it, read once ("" a new chat's) ("draft") -- zeron.toast(text) a short note at the window's foot (always) -- zeron.notify { title, body?, session? } a notification, as Zeron's -- own (Settings → Notifications) ("notifications") @@ -1343,8 +1361,16 @@ return function(id: string): any ui.invoke(`{prefix}.open_url`, url) end - function M.compose(text: string) - ui.invoke("zeron.compose.insert", text) + -- `text` into a chat's draft, for the person to send ("compose"): after + -- what's there, on a line of its own; with `replace = true`, in place of + -- its words (what it carries stays). The chat shown's draft, or + -- `session`'s ("" a new chat's). + function M.compose(text: string, opts: { replace: boolean?, session: string? }?) + if opts and (opts.replace or opts.session) then + ui.invoke("zeron.compose.insert", { text = text, replace = opts.replace == true, session = opts.session or ui.null }) + else + ui.invoke("zeron.compose.insert", text) + end end -- A review comment on a file or a diff, as a chip on a session's draft @@ -1374,6 +1400,57 @@ return function(id: string): any return composed:get() or {} end + -- The composer's draft as you type it: the chat it's for (nil, a new + -- chat), its words, and what it carries, each chip's kind ("file", + -- "image", "chat", …) and name, never a file's path. Read in a build or + -- an effect: it changes as the draft does. Nil until Zeron says. + -- (Reached on first read: only a plugin allowed "draft" may.) + local draft: any = nil + function M.draft(): { session: string?, text: string, attachments: { { kind: string, name: string } } }? + draft = draft or ui.shared("zeron.draft", nil :: any) + return draft:get() + end + + -- The draft shown, taken whole (its words, its chips, the passages + -- quoted in it) and kept by Zeron under `key`, yours, the composer + -- cleared; what that key kept before is replaced. An empty draft isn't + -- taken. Up to 16 kept at once. + function M.take_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "take", key = key }) + end + + -- What `key` kept, put back on the draft shown as it was taken (after + -- what's there, if the composer isn't empty), and no longer kept. + function M.put_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "put", key = key }) + end + + -- The draft shown and what `key` keeps, traded: either may be empty, so + -- one call sets the draft aside, brings it back, or swaps the two. + function M.swap_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "swap", key = key }) + end + + -- What `key` kept, let go of. + function M.drop_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "drop", key = key }) + end + + -- What Zeron keeps for you, by key: the chat each was taken from, its + -- words, what it carries (as `draft()` says it) and when (os.time). + -- Read in a build: it changes as you take and put back. + local drafts = ui.shared(`{prefix}.drafts`, {} :: { [string]: any }) + function M.drafts(): { [string]: { session: string?, text: string, attachments: { { kind: string, name: string } }, at: number } } + return drafts:get() or {} + end + + -- Chat `session`'s draft as it is now, unsent: shown or not (`draft()` + -- follows the one shown). A promise of { session?, text, attachments } + -- as `draft()` says it ("" a new chat's draft, with no session). + function M.draft_of(session: string): any + return ui.call(`{prefix}.draft_of`, session) + end + function M.toast(text: string) ui.invoke(`{prefix}.toast`, text) end diff --git a/apps/zgx/plugins-dev/focus/zeron.luau b/apps/zgx/plugins-dev/focus/zeron.luau index c5f896393..553b6cc16 100644 --- a/apps/zgx/plugins-dev/focus/zeron.luau +++ b/apps/zgx/plugins-dev/focus/zeron.luau @@ -69,13 +69,31 @@ -- zeron.on_message(function(message) end) -- what arrives: { from = { id, name }, data, at } ("devices") -- zeron.open(route) "home", { session = id }, { settings = page } ("navigate") --- zeron.compose(text) text into the message box, for you to send ("compose") +-- zeron.compose(text, { replace?, session? }) +-- text into the message box, for you to send: after +-- what's there, or in place of its words (`replace = +-- true`, its chips kept); the chat shown's draft, or +-- `session`'s ("compose") -- zeron.compose_comment { file, line, note, to?, side?, snippet?, key?, session? } -- a review comment chip on a session's draft, sent as -- Zeron's review comments block (file:line, the note, -- the code under it) ("compose") -- zeron.composed() in a build: your comments still on a draft, by key -- ({ [key] = { session, hovered } }), reactive ("compose") +-- zeron.draft() the composer's draft as you type it: { session?, +-- text, attachments = { { kind, name } } }, reactive +-- ("draft") +-- zeron.take_draft(key), zeron.put_draft(key), zeron.swap_draft(key), +-- zeron.drop_draft(key) +-- the draft taken whole (words, chips, quotes) and +-- kept by Zeron under your key, the composer +-- cleared; put back on the draft shown; the two +-- traded; let go ("draft") +-- zeron.drafts() what Zeron keeps for you, by key: { session?, text, +-- attachments, at }, reactive ("draft") +-- zeron.draft_of(session) +-- a promise of another chat's draft, as `draft()` +-- says it, read once ("" a new chat's) ("draft") -- zeron.toast(text) a short note at the window's foot (always) -- zeron.notify { title, body?, session? } a notification, as Zeron's -- own (Settings → Notifications) ("notifications") @@ -1343,8 +1361,16 @@ return function(id: string): any ui.invoke(`{prefix}.open_url`, url) end - function M.compose(text: string) - ui.invoke("zeron.compose.insert", text) + -- `text` into a chat's draft, for the person to send ("compose"): after + -- what's there, on a line of its own; with `replace = true`, in place of + -- its words (what it carries stays). The chat shown's draft, or + -- `session`'s ("" a new chat's). + function M.compose(text: string, opts: { replace: boolean?, session: string? }?) + if opts and (opts.replace or opts.session) then + ui.invoke("zeron.compose.insert", { text = text, replace = opts.replace == true, session = opts.session or ui.null }) + else + ui.invoke("zeron.compose.insert", text) + end end -- A review comment on a file or a diff, as a chip on a session's draft @@ -1374,6 +1400,57 @@ return function(id: string): any return composed:get() or {} end + -- The composer's draft as you type it: the chat it's for (nil, a new + -- chat), its words, and what it carries, each chip's kind ("file", + -- "image", "chat", …) and name, never a file's path. Read in a build or + -- an effect: it changes as the draft does. Nil until Zeron says. + -- (Reached on first read: only a plugin allowed "draft" may.) + local draft: any = nil + function M.draft(): { session: string?, text: string, attachments: { { kind: string, name: string } } }? + draft = draft or ui.shared("zeron.draft", nil :: any) + return draft:get() + end + + -- The draft shown, taken whole (its words, its chips, the passages + -- quoted in it) and kept by Zeron under `key`, yours, the composer + -- cleared; what that key kept before is replaced. An empty draft isn't + -- taken. Up to 16 kept at once. + function M.take_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "take", key = key }) + end + + -- What `key` kept, put back on the draft shown as it was taken (after + -- what's there, if the composer isn't empty), and no longer kept. + function M.put_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "put", key = key }) + end + + -- The draft shown and what `key` keeps, traded: either may be empty, so + -- one call sets the draft aside, brings it back, or swaps the two. + function M.swap_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "swap", key = key }) + end + + -- What `key` kept, let go of. + function M.drop_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "drop", key = key }) + end + + -- What Zeron keeps for you, by key: the chat each was taken from, its + -- words, what it carries (as `draft()` says it) and when (os.time). + -- Read in a build: it changes as you take and put back. + local drafts = ui.shared(`{prefix}.drafts`, {} :: { [string]: any }) + function M.drafts(): { [string]: { session: string?, text: string, attachments: { { kind: string, name: string } }, at: number } } + return drafts:get() or {} + end + + -- Chat `session`'s draft as it is now, unsent: shown or not (`draft()` + -- follows the one shown). A promise of { session?, text, attachments } + -- as `draft()` says it ("" a new chat's draft, with no session). + function M.draft_of(session: string): any + return ui.call(`{prefix}.draft_of`, session) + end + function M.toast(text: string) ui.invoke(`{prefix}.toast`, text) end diff --git a/apps/zgx/plugins-dev/keep-going/zeron.luau b/apps/zgx/plugins-dev/keep-going/zeron.luau index c5f896393..553b6cc16 100644 --- a/apps/zgx/plugins-dev/keep-going/zeron.luau +++ b/apps/zgx/plugins-dev/keep-going/zeron.luau @@ -69,13 +69,31 @@ -- zeron.on_message(function(message) end) -- what arrives: { from = { id, name }, data, at } ("devices") -- zeron.open(route) "home", { session = id }, { settings = page } ("navigate") --- zeron.compose(text) text into the message box, for you to send ("compose") +-- zeron.compose(text, { replace?, session? }) +-- text into the message box, for you to send: after +-- what's there, or in place of its words (`replace = +-- true`, its chips kept); the chat shown's draft, or +-- `session`'s ("compose") -- zeron.compose_comment { file, line, note, to?, side?, snippet?, key?, session? } -- a review comment chip on a session's draft, sent as -- Zeron's review comments block (file:line, the note, -- the code under it) ("compose") -- zeron.composed() in a build: your comments still on a draft, by key -- ({ [key] = { session, hovered } }), reactive ("compose") +-- zeron.draft() the composer's draft as you type it: { session?, +-- text, attachments = { { kind, name } } }, reactive +-- ("draft") +-- zeron.take_draft(key), zeron.put_draft(key), zeron.swap_draft(key), +-- zeron.drop_draft(key) +-- the draft taken whole (words, chips, quotes) and +-- kept by Zeron under your key, the composer +-- cleared; put back on the draft shown; the two +-- traded; let go ("draft") +-- zeron.drafts() what Zeron keeps for you, by key: { session?, text, +-- attachments, at }, reactive ("draft") +-- zeron.draft_of(session) +-- a promise of another chat's draft, as `draft()` +-- says it, read once ("" a new chat's) ("draft") -- zeron.toast(text) a short note at the window's foot (always) -- zeron.notify { title, body?, session? } a notification, as Zeron's -- own (Settings → Notifications) ("notifications") @@ -1343,8 +1361,16 @@ return function(id: string): any ui.invoke(`{prefix}.open_url`, url) end - function M.compose(text: string) - ui.invoke("zeron.compose.insert", text) + -- `text` into a chat's draft, for the person to send ("compose"): after + -- what's there, on a line of its own; with `replace = true`, in place of + -- its words (what it carries stays). The chat shown's draft, or + -- `session`'s ("" a new chat's). + function M.compose(text: string, opts: { replace: boolean?, session: string? }?) + if opts and (opts.replace or opts.session) then + ui.invoke("zeron.compose.insert", { text = text, replace = opts.replace == true, session = opts.session or ui.null }) + else + ui.invoke("zeron.compose.insert", text) + end end -- A review comment on a file or a diff, as a chip on a session's draft @@ -1374,6 +1400,57 @@ return function(id: string): any return composed:get() or {} end + -- The composer's draft as you type it: the chat it's for (nil, a new + -- chat), its words, and what it carries, each chip's kind ("file", + -- "image", "chat", …) and name, never a file's path. Read in a build or + -- an effect: it changes as the draft does. Nil until Zeron says. + -- (Reached on first read: only a plugin allowed "draft" may.) + local draft: any = nil + function M.draft(): { session: string?, text: string, attachments: { { kind: string, name: string } } }? + draft = draft or ui.shared("zeron.draft", nil :: any) + return draft:get() + end + + -- The draft shown, taken whole (its words, its chips, the passages + -- quoted in it) and kept by Zeron under `key`, yours, the composer + -- cleared; what that key kept before is replaced. An empty draft isn't + -- taken. Up to 16 kept at once. + function M.take_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "take", key = key }) + end + + -- What `key` kept, put back on the draft shown as it was taken (after + -- what's there, if the composer isn't empty), and no longer kept. + function M.put_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "put", key = key }) + end + + -- The draft shown and what `key` keeps, traded: either may be empty, so + -- one call sets the draft aside, brings it back, or swaps the two. + function M.swap_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "swap", key = key }) + end + + -- What `key` kept, let go of. + function M.drop_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "drop", key = key }) + end + + -- What Zeron keeps for you, by key: the chat each was taken from, its + -- words, what it carries (as `draft()` says it) and when (os.time). + -- Read in a build: it changes as you take and put back. + local drafts = ui.shared(`{prefix}.drafts`, {} :: { [string]: any }) + function M.drafts(): { [string]: { session: string?, text: string, attachments: { { kind: string, name: string } }, at: number } } + return drafts:get() or {} + end + + -- Chat `session`'s draft as it is now, unsent: shown or not (`draft()` + -- follows the one shown). A promise of { session?, text, attachments } + -- as `draft()` says it ("" a new chat's draft, with no session). + function M.draft_of(session: string): any + return ui.call(`{prefix}.draft_of`, session) + end + function M.toast(text: string) ui.invoke(`{prefix}.toast`, text) end diff --git a/apps/zgx/plugins-dev/md-hello/zeron.luau b/apps/zgx/plugins-dev/md-hello/zeron.luau index c5f896393..553b6cc16 100644 --- a/apps/zgx/plugins-dev/md-hello/zeron.luau +++ b/apps/zgx/plugins-dev/md-hello/zeron.luau @@ -69,13 +69,31 @@ -- zeron.on_message(function(message) end) -- what arrives: { from = { id, name }, data, at } ("devices") -- zeron.open(route) "home", { session = id }, { settings = page } ("navigate") --- zeron.compose(text) text into the message box, for you to send ("compose") +-- zeron.compose(text, { replace?, session? }) +-- text into the message box, for you to send: after +-- what's there, or in place of its words (`replace = +-- true`, its chips kept); the chat shown's draft, or +-- `session`'s ("compose") -- zeron.compose_comment { file, line, note, to?, side?, snippet?, key?, session? } -- a review comment chip on a session's draft, sent as -- Zeron's review comments block (file:line, the note, -- the code under it) ("compose") -- zeron.composed() in a build: your comments still on a draft, by key -- ({ [key] = { session, hovered } }), reactive ("compose") +-- zeron.draft() the composer's draft as you type it: { session?, +-- text, attachments = { { kind, name } } }, reactive +-- ("draft") +-- zeron.take_draft(key), zeron.put_draft(key), zeron.swap_draft(key), +-- zeron.drop_draft(key) +-- the draft taken whole (words, chips, quotes) and +-- kept by Zeron under your key, the composer +-- cleared; put back on the draft shown; the two +-- traded; let go ("draft") +-- zeron.drafts() what Zeron keeps for you, by key: { session?, text, +-- attachments, at }, reactive ("draft") +-- zeron.draft_of(session) +-- a promise of another chat's draft, as `draft()` +-- says it, read once ("" a new chat's) ("draft") -- zeron.toast(text) a short note at the window's foot (always) -- zeron.notify { title, body?, session? } a notification, as Zeron's -- own (Settings → Notifications) ("notifications") @@ -1343,8 +1361,16 @@ return function(id: string): any ui.invoke(`{prefix}.open_url`, url) end - function M.compose(text: string) - ui.invoke("zeron.compose.insert", text) + -- `text` into a chat's draft, for the person to send ("compose"): after + -- what's there, on a line of its own; with `replace = true`, in place of + -- its words (what it carries stays). The chat shown's draft, or + -- `session`'s ("" a new chat's). + function M.compose(text: string, opts: { replace: boolean?, session: string? }?) + if opts and (opts.replace or opts.session) then + ui.invoke("zeron.compose.insert", { text = text, replace = opts.replace == true, session = opts.session or ui.null }) + else + ui.invoke("zeron.compose.insert", text) + end end -- A review comment on a file or a diff, as a chip on a session's draft @@ -1374,6 +1400,57 @@ return function(id: string): any return composed:get() or {} end + -- The composer's draft as you type it: the chat it's for (nil, a new + -- chat), its words, and what it carries, each chip's kind ("file", + -- "image", "chat", …) and name, never a file's path. Read in a build or + -- an effect: it changes as the draft does. Nil until Zeron says. + -- (Reached on first read: only a plugin allowed "draft" may.) + local draft: any = nil + function M.draft(): { session: string?, text: string, attachments: { { kind: string, name: string } } }? + draft = draft or ui.shared("zeron.draft", nil :: any) + return draft:get() + end + + -- The draft shown, taken whole (its words, its chips, the passages + -- quoted in it) and kept by Zeron under `key`, yours, the composer + -- cleared; what that key kept before is replaced. An empty draft isn't + -- taken. Up to 16 kept at once. + function M.take_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "take", key = key }) + end + + -- What `key` kept, put back on the draft shown as it was taken (after + -- what's there, if the composer isn't empty), and no longer kept. + function M.put_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "put", key = key }) + end + + -- The draft shown and what `key` keeps, traded: either may be empty, so + -- one call sets the draft aside, brings it back, or swaps the two. + function M.swap_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "swap", key = key }) + end + + -- What `key` kept, let go of. + function M.drop_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "drop", key = key }) + end + + -- What Zeron keeps for you, by key: the chat each was taken from, its + -- words, what it carries (as `draft()` says it) and when (os.time). + -- Read in a build: it changes as you take and put back. + local drafts = ui.shared(`{prefix}.drafts`, {} :: { [string]: any }) + function M.drafts(): { [string]: { session: string?, text: string, attachments: { { kind: string, name: string } }, at: number } } + return drafts:get() or {} + end + + -- Chat `session`'s draft as it is now, unsent: shown or not (`draft()` + -- follows the one shown). A promise of { session?, text, attachments } + -- as `draft()` says it ("" a new chat's draft, with no session). + function M.draft_of(session: string): any + return ui.call(`{prefix}.draft_of`, session) + end + function M.toast(text: string) ui.invoke(`{prefix}.toast`, text) end diff --git a/apps/zgx/plugins-dev/notes-tool/zeron.luau b/apps/zgx/plugins-dev/notes-tool/zeron.luau index c5f896393..553b6cc16 100644 --- a/apps/zgx/plugins-dev/notes-tool/zeron.luau +++ b/apps/zgx/plugins-dev/notes-tool/zeron.luau @@ -69,13 +69,31 @@ -- zeron.on_message(function(message) end) -- what arrives: { from = { id, name }, data, at } ("devices") -- zeron.open(route) "home", { session = id }, { settings = page } ("navigate") --- zeron.compose(text) text into the message box, for you to send ("compose") +-- zeron.compose(text, { replace?, session? }) +-- text into the message box, for you to send: after +-- what's there, or in place of its words (`replace = +-- true`, its chips kept); the chat shown's draft, or +-- `session`'s ("compose") -- zeron.compose_comment { file, line, note, to?, side?, snippet?, key?, session? } -- a review comment chip on a session's draft, sent as -- Zeron's review comments block (file:line, the note, -- the code under it) ("compose") -- zeron.composed() in a build: your comments still on a draft, by key -- ({ [key] = { session, hovered } }), reactive ("compose") +-- zeron.draft() the composer's draft as you type it: { session?, +-- text, attachments = { { kind, name } } }, reactive +-- ("draft") +-- zeron.take_draft(key), zeron.put_draft(key), zeron.swap_draft(key), +-- zeron.drop_draft(key) +-- the draft taken whole (words, chips, quotes) and +-- kept by Zeron under your key, the composer +-- cleared; put back on the draft shown; the two +-- traded; let go ("draft") +-- zeron.drafts() what Zeron keeps for you, by key: { session?, text, +-- attachments, at }, reactive ("draft") +-- zeron.draft_of(session) +-- a promise of another chat's draft, as `draft()` +-- says it, read once ("" a new chat's) ("draft") -- zeron.toast(text) a short note at the window's foot (always) -- zeron.notify { title, body?, session? } a notification, as Zeron's -- own (Settings → Notifications) ("notifications") @@ -1343,8 +1361,16 @@ return function(id: string): any ui.invoke(`{prefix}.open_url`, url) end - function M.compose(text: string) - ui.invoke("zeron.compose.insert", text) + -- `text` into a chat's draft, for the person to send ("compose"): after + -- what's there, on a line of its own; with `replace = true`, in place of + -- its words (what it carries stays). The chat shown's draft, or + -- `session`'s ("" a new chat's). + function M.compose(text: string, opts: { replace: boolean?, session: string? }?) + if opts and (opts.replace or opts.session) then + ui.invoke("zeron.compose.insert", { text = text, replace = opts.replace == true, session = opts.session or ui.null }) + else + ui.invoke("zeron.compose.insert", text) + end end -- A review comment on a file or a diff, as a chip on a session's draft @@ -1374,6 +1400,57 @@ return function(id: string): any return composed:get() or {} end + -- The composer's draft as you type it: the chat it's for (nil, a new + -- chat), its words, and what it carries, each chip's kind ("file", + -- "image", "chat", …) and name, never a file's path. Read in a build or + -- an effect: it changes as the draft does. Nil until Zeron says. + -- (Reached on first read: only a plugin allowed "draft" may.) + local draft: any = nil + function M.draft(): { session: string?, text: string, attachments: { { kind: string, name: string } } }? + draft = draft or ui.shared("zeron.draft", nil :: any) + return draft:get() + end + + -- The draft shown, taken whole (its words, its chips, the passages + -- quoted in it) and kept by Zeron under `key`, yours, the composer + -- cleared; what that key kept before is replaced. An empty draft isn't + -- taken. Up to 16 kept at once. + function M.take_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "take", key = key }) + end + + -- What `key` kept, put back on the draft shown as it was taken (after + -- what's there, if the composer isn't empty), and no longer kept. + function M.put_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "put", key = key }) + end + + -- The draft shown and what `key` keeps, traded: either may be empty, so + -- one call sets the draft aside, brings it back, or swaps the two. + function M.swap_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "swap", key = key }) + end + + -- What `key` kept, let go of. + function M.drop_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "drop", key = key }) + end + + -- What Zeron keeps for you, by key: the chat each was taken from, its + -- words, what it carries (as `draft()` says it) and when (os.time). + -- Read in a build: it changes as you take and put back. + local drafts = ui.shared(`{prefix}.drafts`, {} :: { [string]: any }) + function M.drafts(): { [string]: { session: string?, text: string, attachments: { { kind: string, name: string } }, at: number } } + return drafts:get() or {} + end + + -- Chat `session`'s draft as it is now, unsent: shown or not (`draft()` + -- follows the one shown). A promise of { session?, text, attachments } + -- as `draft()` says it ("" a new chat's draft, with no session). + function M.draft_of(session: string): any + return ui.call(`{prefix}.draft_of`, session) + end + function M.toast(text: string) ui.invoke(`{prefix}.toast`, text) end diff --git a/apps/zgx/plugins-dev/ping/zeron.luau b/apps/zgx/plugins-dev/ping/zeron.luau index c5f896393..553b6cc16 100644 --- a/apps/zgx/plugins-dev/ping/zeron.luau +++ b/apps/zgx/plugins-dev/ping/zeron.luau @@ -69,13 +69,31 @@ -- zeron.on_message(function(message) end) -- what arrives: { from = { id, name }, data, at } ("devices") -- zeron.open(route) "home", { session = id }, { settings = page } ("navigate") --- zeron.compose(text) text into the message box, for you to send ("compose") +-- zeron.compose(text, { replace?, session? }) +-- text into the message box, for you to send: after +-- what's there, or in place of its words (`replace = +-- true`, its chips kept); the chat shown's draft, or +-- `session`'s ("compose") -- zeron.compose_comment { file, line, note, to?, side?, snippet?, key?, session? } -- a review comment chip on a session's draft, sent as -- Zeron's review comments block (file:line, the note, -- the code under it) ("compose") -- zeron.composed() in a build: your comments still on a draft, by key -- ({ [key] = { session, hovered } }), reactive ("compose") +-- zeron.draft() the composer's draft as you type it: { session?, +-- text, attachments = { { kind, name } } }, reactive +-- ("draft") +-- zeron.take_draft(key), zeron.put_draft(key), zeron.swap_draft(key), +-- zeron.drop_draft(key) +-- the draft taken whole (words, chips, quotes) and +-- kept by Zeron under your key, the composer +-- cleared; put back on the draft shown; the two +-- traded; let go ("draft") +-- zeron.drafts() what Zeron keeps for you, by key: { session?, text, +-- attachments, at }, reactive ("draft") +-- zeron.draft_of(session) +-- a promise of another chat's draft, as `draft()` +-- says it, read once ("" a new chat's) ("draft") -- zeron.toast(text) a short note at the window's foot (always) -- zeron.notify { title, body?, session? } a notification, as Zeron's -- own (Settings → Notifications) ("notifications") @@ -1343,8 +1361,16 @@ return function(id: string): any ui.invoke(`{prefix}.open_url`, url) end - function M.compose(text: string) - ui.invoke("zeron.compose.insert", text) + -- `text` into a chat's draft, for the person to send ("compose"): after + -- what's there, on a line of its own; with `replace = true`, in place of + -- its words (what it carries stays). The chat shown's draft, or + -- `session`'s ("" a new chat's). + function M.compose(text: string, opts: { replace: boolean?, session: string? }?) + if opts and (opts.replace or opts.session) then + ui.invoke("zeron.compose.insert", { text = text, replace = opts.replace == true, session = opts.session or ui.null }) + else + ui.invoke("zeron.compose.insert", text) + end end -- A review comment on a file or a diff, as a chip on a session's draft @@ -1374,6 +1400,57 @@ return function(id: string): any return composed:get() or {} end + -- The composer's draft as you type it: the chat it's for (nil, a new + -- chat), its words, and what it carries, each chip's kind ("file", + -- "image", "chat", …) and name, never a file's path. Read in a build or + -- an effect: it changes as the draft does. Nil until Zeron says. + -- (Reached on first read: only a plugin allowed "draft" may.) + local draft: any = nil + function M.draft(): { session: string?, text: string, attachments: { { kind: string, name: string } } }? + draft = draft or ui.shared("zeron.draft", nil :: any) + return draft:get() + end + + -- The draft shown, taken whole (its words, its chips, the passages + -- quoted in it) and kept by Zeron under `key`, yours, the composer + -- cleared; what that key kept before is replaced. An empty draft isn't + -- taken. Up to 16 kept at once. + function M.take_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "take", key = key }) + end + + -- What `key` kept, put back on the draft shown as it was taken (after + -- what's there, if the composer isn't empty), and no longer kept. + function M.put_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "put", key = key }) + end + + -- The draft shown and what `key` keeps, traded: either may be empty, so + -- one call sets the draft aside, brings it back, or swaps the two. + function M.swap_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "swap", key = key }) + end + + -- What `key` kept, let go of. + function M.drop_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "drop", key = key }) + end + + -- What Zeron keeps for you, by key: the chat each was taken from, its + -- words, what it carries (as `draft()` says it) and when (os.time). + -- Read in a build: it changes as you take and put back. + local drafts = ui.shared(`{prefix}.drafts`, {} :: { [string]: any }) + function M.drafts(): { [string]: { session: string?, text: string, attachments: { { kind: string, name: string } }, at: number } } + return drafts:get() or {} + end + + -- Chat `session`'s draft as it is now, unsent: shown or not (`draft()` + -- follows the one shown). A promise of { session?, text, attachments } + -- as `draft()` says it ("" a new chat's draft, with no session). + function M.draft_of(session: string): any + return ui.call(`{prefix}.draft_of`, session) + end + function M.toast(text: string) ui.invoke(`{prefix}.toast`, text) end diff --git a/apps/zgx/plugins-dev/session-status/zeron.luau b/apps/zgx/plugins-dev/session-status/zeron.luau index c5f896393..553b6cc16 100644 --- a/apps/zgx/plugins-dev/session-status/zeron.luau +++ b/apps/zgx/plugins-dev/session-status/zeron.luau @@ -69,13 +69,31 @@ -- zeron.on_message(function(message) end) -- what arrives: { from = { id, name }, data, at } ("devices") -- zeron.open(route) "home", { session = id }, { settings = page } ("navigate") --- zeron.compose(text) text into the message box, for you to send ("compose") +-- zeron.compose(text, { replace?, session? }) +-- text into the message box, for you to send: after +-- what's there, or in place of its words (`replace = +-- true`, its chips kept); the chat shown's draft, or +-- `session`'s ("compose") -- zeron.compose_comment { file, line, note, to?, side?, snippet?, key?, session? } -- a review comment chip on a session's draft, sent as -- Zeron's review comments block (file:line, the note, -- the code under it) ("compose") -- zeron.composed() in a build: your comments still on a draft, by key -- ({ [key] = { session, hovered } }), reactive ("compose") +-- zeron.draft() the composer's draft as you type it: { session?, +-- text, attachments = { { kind, name } } }, reactive +-- ("draft") +-- zeron.take_draft(key), zeron.put_draft(key), zeron.swap_draft(key), +-- zeron.drop_draft(key) +-- the draft taken whole (words, chips, quotes) and +-- kept by Zeron under your key, the composer +-- cleared; put back on the draft shown; the two +-- traded; let go ("draft") +-- zeron.drafts() what Zeron keeps for you, by key: { session?, text, +-- attachments, at }, reactive ("draft") +-- zeron.draft_of(session) +-- a promise of another chat's draft, as `draft()` +-- says it, read once ("" a new chat's) ("draft") -- zeron.toast(text) a short note at the window's foot (always) -- zeron.notify { title, body?, session? } a notification, as Zeron's -- own (Settings → Notifications) ("notifications") @@ -1343,8 +1361,16 @@ return function(id: string): any ui.invoke(`{prefix}.open_url`, url) end - function M.compose(text: string) - ui.invoke("zeron.compose.insert", text) + -- `text` into a chat's draft, for the person to send ("compose"): after + -- what's there, on a line of its own; with `replace = true`, in place of + -- its words (what it carries stays). The chat shown's draft, or + -- `session`'s ("" a new chat's). + function M.compose(text: string, opts: { replace: boolean?, session: string? }?) + if opts and (opts.replace or opts.session) then + ui.invoke("zeron.compose.insert", { text = text, replace = opts.replace == true, session = opts.session or ui.null }) + else + ui.invoke("zeron.compose.insert", text) + end end -- A review comment on a file or a diff, as a chip on a session's draft @@ -1374,6 +1400,57 @@ return function(id: string): any return composed:get() or {} end + -- The composer's draft as you type it: the chat it's for (nil, a new + -- chat), its words, and what it carries, each chip's kind ("file", + -- "image", "chat", …) and name, never a file's path. Read in a build or + -- an effect: it changes as the draft does. Nil until Zeron says. + -- (Reached on first read: only a plugin allowed "draft" may.) + local draft: any = nil + function M.draft(): { session: string?, text: string, attachments: { { kind: string, name: string } } }? + draft = draft or ui.shared("zeron.draft", nil :: any) + return draft:get() + end + + -- The draft shown, taken whole (its words, its chips, the passages + -- quoted in it) and kept by Zeron under `key`, yours, the composer + -- cleared; what that key kept before is replaced. An empty draft isn't + -- taken. Up to 16 kept at once. + function M.take_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "take", key = key }) + end + + -- What `key` kept, put back on the draft shown as it was taken (after + -- what's there, if the composer isn't empty), and no longer kept. + function M.put_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "put", key = key }) + end + + -- The draft shown and what `key` keeps, traded: either may be empty, so + -- one call sets the draft aside, brings it back, or swaps the two. + function M.swap_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "swap", key = key }) + end + + -- What `key` kept, let go of. + function M.drop_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "drop", key = key }) + end + + -- What Zeron keeps for you, by key: the chat each was taken from, its + -- words, what it carries (as `draft()` says it) and when (os.time). + -- Read in a build: it changes as you take and put back. + local drafts = ui.shared(`{prefix}.drafts`, {} :: { [string]: any }) + function M.drafts(): { [string]: { session: string?, text: string, attachments: { { kind: string, name: string } }, at: number } } + return drafts:get() or {} + end + + -- Chat `session`'s draft as it is now, unsent: shown or not (`draft()` + -- follows the one shown). A promise of { session?, text, attachments } + -- as `draft()` says it ("" a new chat's draft, with no session). + function M.draft_of(session: string): any + return ui.call(`{prefix}.draft_of`, session) + end + function M.toast(text: string) ui.invoke(`{prefix}.toast`, text) end diff --git a/apps/zgx/plugins-dev/session-words/zeron.luau b/apps/zgx/plugins-dev/session-words/zeron.luau index c5f896393..553b6cc16 100644 --- a/apps/zgx/plugins-dev/session-words/zeron.luau +++ b/apps/zgx/plugins-dev/session-words/zeron.luau @@ -69,13 +69,31 @@ -- zeron.on_message(function(message) end) -- what arrives: { from = { id, name }, data, at } ("devices") -- zeron.open(route) "home", { session = id }, { settings = page } ("navigate") --- zeron.compose(text) text into the message box, for you to send ("compose") +-- zeron.compose(text, { replace?, session? }) +-- text into the message box, for you to send: after +-- what's there, or in place of its words (`replace = +-- true`, its chips kept); the chat shown's draft, or +-- `session`'s ("compose") -- zeron.compose_comment { file, line, note, to?, side?, snippet?, key?, session? } -- a review comment chip on a session's draft, sent as -- Zeron's review comments block (file:line, the note, -- the code under it) ("compose") -- zeron.composed() in a build: your comments still on a draft, by key -- ({ [key] = { session, hovered } }), reactive ("compose") +-- zeron.draft() the composer's draft as you type it: { session?, +-- text, attachments = { { kind, name } } }, reactive +-- ("draft") +-- zeron.take_draft(key), zeron.put_draft(key), zeron.swap_draft(key), +-- zeron.drop_draft(key) +-- the draft taken whole (words, chips, quotes) and +-- kept by Zeron under your key, the composer +-- cleared; put back on the draft shown; the two +-- traded; let go ("draft") +-- zeron.drafts() what Zeron keeps for you, by key: { session?, text, +-- attachments, at }, reactive ("draft") +-- zeron.draft_of(session) +-- a promise of another chat's draft, as `draft()` +-- says it, read once ("" a new chat's) ("draft") -- zeron.toast(text) a short note at the window's foot (always) -- zeron.notify { title, body?, session? } a notification, as Zeron's -- own (Settings → Notifications) ("notifications") @@ -1343,8 +1361,16 @@ return function(id: string): any ui.invoke(`{prefix}.open_url`, url) end - function M.compose(text: string) - ui.invoke("zeron.compose.insert", text) + -- `text` into a chat's draft, for the person to send ("compose"): after + -- what's there, on a line of its own; with `replace = true`, in place of + -- its words (what it carries stays). The chat shown's draft, or + -- `session`'s ("" a new chat's). + function M.compose(text: string, opts: { replace: boolean?, session: string? }?) + if opts and (opts.replace or opts.session) then + ui.invoke("zeron.compose.insert", { text = text, replace = opts.replace == true, session = opts.session or ui.null }) + else + ui.invoke("zeron.compose.insert", text) + end end -- A review comment on a file or a diff, as a chip on a session's draft @@ -1374,6 +1400,57 @@ return function(id: string): any return composed:get() or {} end + -- The composer's draft as you type it: the chat it's for (nil, a new + -- chat), its words, and what it carries, each chip's kind ("file", + -- "image", "chat", …) and name, never a file's path. Read in a build or + -- an effect: it changes as the draft does. Nil until Zeron says. + -- (Reached on first read: only a plugin allowed "draft" may.) + local draft: any = nil + function M.draft(): { session: string?, text: string, attachments: { { kind: string, name: string } } }? + draft = draft or ui.shared("zeron.draft", nil :: any) + return draft:get() + end + + -- The draft shown, taken whole (its words, its chips, the passages + -- quoted in it) and kept by Zeron under `key`, yours, the composer + -- cleared; what that key kept before is replaced. An empty draft isn't + -- taken. Up to 16 kept at once. + function M.take_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "take", key = key }) + end + + -- What `key` kept, put back on the draft shown as it was taken (after + -- what's there, if the composer isn't empty), and no longer kept. + function M.put_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "put", key = key }) + end + + -- The draft shown and what `key` keeps, traded: either may be empty, so + -- one call sets the draft aside, brings it back, or swaps the two. + function M.swap_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "swap", key = key }) + end + + -- What `key` kept, let go of. + function M.drop_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "drop", key = key }) + end + + -- What Zeron keeps for you, by key: the chat each was taken from, its + -- words, what it carries (as `draft()` says it) and when (os.time). + -- Read in a build: it changes as you take and put back. + local drafts = ui.shared(`{prefix}.drafts`, {} :: { [string]: any }) + function M.drafts(): { [string]: { session: string?, text: string, attachments: { { kind: string, name: string } }, at: number } } + return drafts:get() or {} + end + + -- Chat `session`'s draft as it is now, unsent: shown or not (`draft()` + -- follows the one shown). A promise of { session?, text, attachments } + -- as `draft()` says it ("" a new chat's draft, with no session). + function M.draft_of(session: string): any + return ui.call(`{prefix}.draft_of`, session) + end + function M.toast(text: string) ui.invoke(`{prefix}.toast`, text) end diff --git a/apps/zgx/plugins-dev/settings-demo/zeron.luau b/apps/zgx/plugins-dev/settings-demo/zeron.luau index c5f896393..553b6cc16 100644 --- a/apps/zgx/plugins-dev/settings-demo/zeron.luau +++ b/apps/zgx/plugins-dev/settings-demo/zeron.luau @@ -69,13 +69,31 @@ -- zeron.on_message(function(message) end) -- what arrives: { from = { id, name }, data, at } ("devices") -- zeron.open(route) "home", { session = id }, { settings = page } ("navigate") --- zeron.compose(text) text into the message box, for you to send ("compose") +-- zeron.compose(text, { replace?, session? }) +-- text into the message box, for you to send: after +-- what's there, or in place of its words (`replace = +-- true`, its chips kept); the chat shown's draft, or +-- `session`'s ("compose") -- zeron.compose_comment { file, line, note, to?, side?, snippet?, key?, session? } -- a review comment chip on a session's draft, sent as -- Zeron's review comments block (file:line, the note, -- the code under it) ("compose") -- zeron.composed() in a build: your comments still on a draft, by key -- ({ [key] = { session, hovered } }), reactive ("compose") +-- zeron.draft() the composer's draft as you type it: { session?, +-- text, attachments = { { kind, name } } }, reactive +-- ("draft") +-- zeron.take_draft(key), zeron.put_draft(key), zeron.swap_draft(key), +-- zeron.drop_draft(key) +-- the draft taken whole (words, chips, quotes) and +-- kept by Zeron under your key, the composer +-- cleared; put back on the draft shown; the two +-- traded; let go ("draft") +-- zeron.drafts() what Zeron keeps for you, by key: { session?, text, +-- attachments, at }, reactive ("draft") +-- zeron.draft_of(session) +-- a promise of another chat's draft, as `draft()` +-- says it, read once ("" a new chat's) ("draft") -- zeron.toast(text) a short note at the window's foot (always) -- zeron.notify { title, body?, session? } a notification, as Zeron's -- own (Settings → Notifications) ("notifications") @@ -1343,8 +1361,16 @@ return function(id: string): any ui.invoke(`{prefix}.open_url`, url) end - function M.compose(text: string) - ui.invoke("zeron.compose.insert", text) + -- `text` into a chat's draft, for the person to send ("compose"): after + -- what's there, on a line of its own; with `replace = true`, in place of + -- its words (what it carries stays). The chat shown's draft, or + -- `session`'s ("" a new chat's). + function M.compose(text: string, opts: { replace: boolean?, session: string? }?) + if opts and (opts.replace or opts.session) then + ui.invoke("zeron.compose.insert", { text = text, replace = opts.replace == true, session = opts.session or ui.null }) + else + ui.invoke("zeron.compose.insert", text) + end end -- A review comment on a file or a diff, as a chip on a session's draft @@ -1374,6 +1400,57 @@ return function(id: string): any return composed:get() or {} end + -- The composer's draft as you type it: the chat it's for (nil, a new + -- chat), its words, and what it carries, each chip's kind ("file", + -- "image", "chat", …) and name, never a file's path. Read in a build or + -- an effect: it changes as the draft does. Nil until Zeron says. + -- (Reached on first read: only a plugin allowed "draft" may.) + local draft: any = nil + function M.draft(): { session: string?, text: string, attachments: { { kind: string, name: string } } }? + draft = draft or ui.shared("zeron.draft", nil :: any) + return draft:get() + end + + -- The draft shown, taken whole (its words, its chips, the passages + -- quoted in it) and kept by Zeron under `key`, yours, the composer + -- cleared; what that key kept before is replaced. An empty draft isn't + -- taken. Up to 16 kept at once. + function M.take_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "take", key = key }) + end + + -- What `key` kept, put back on the draft shown as it was taken (after + -- what's there, if the composer isn't empty), and no longer kept. + function M.put_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "put", key = key }) + end + + -- The draft shown and what `key` keeps, traded: either may be empty, so + -- one call sets the draft aside, brings it back, or swaps the two. + function M.swap_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "swap", key = key }) + end + + -- What `key` kept, let go of. + function M.drop_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "drop", key = key }) + end + + -- What Zeron keeps for you, by key: the chat each was taken from, its + -- words, what it carries (as `draft()` says it) and when (os.time). + -- Read in a build: it changes as you take and put back. + local drafts = ui.shared(`{prefix}.drafts`, {} :: { [string]: any }) + function M.drafts(): { [string]: { session: string?, text: string, attachments: { { kind: string, name: string } }, at: number } } + return drafts:get() or {} + end + + -- Chat `session`'s draft as it is now, unsent: shown or not (`draft()` + -- follows the one shown). A promise of { session?, text, attachments } + -- as `draft()` says it ("" a new chat's draft, with no session). + function M.draft_of(session: string): any + return ui.call(`{prefix}.draft_of`, session) + end + function M.toast(text: string) ui.invoke(`{prefix}.toast`, text) end diff --git a/apps/zgx/plugins-sdk/zeron.luau b/apps/zgx/plugins-sdk/zeron.luau index c5f896393..553b6cc16 100644 --- a/apps/zgx/plugins-sdk/zeron.luau +++ b/apps/zgx/plugins-sdk/zeron.luau @@ -69,13 +69,31 @@ -- zeron.on_message(function(message) end) -- what arrives: { from = { id, name }, data, at } ("devices") -- zeron.open(route) "home", { session = id }, { settings = page } ("navigate") --- zeron.compose(text) text into the message box, for you to send ("compose") +-- zeron.compose(text, { replace?, session? }) +-- text into the message box, for you to send: after +-- what's there, or in place of its words (`replace = +-- true`, its chips kept); the chat shown's draft, or +-- `session`'s ("compose") -- zeron.compose_comment { file, line, note, to?, side?, snippet?, key?, session? } -- a review comment chip on a session's draft, sent as -- Zeron's review comments block (file:line, the note, -- the code under it) ("compose") -- zeron.composed() in a build: your comments still on a draft, by key -- ({ [key] = { session, hovered } }), reactive ("compose") +-- zeron.draft() the composer's draft as you type it: { session?, +-- text, attachments = { { kind, name } } }, reactive +-- ("draft") +-- zeron.take_draft(key), zeron.put_draft(key), zeron.swap_draft(key), +-- zeron.drop_draft(key) +-- the draft taken whole (words, chips, quotes) and +-- kept by Zeron under your key, the composer +-- cleared; put back on the draft shown; the two +-- traded; let go ("draft") +-- zeron.drafts() what Zeron keeps for you, by key: { session?, text, +-- attachments, at }, reactive ("draft") +-- zeron.draft_of(session) +-- a promise of another chat's draft, as `draft()` +-- says it, read once ("" a new chat's) ("draft") -- zeron.toast(text) a short note at the window's foot (always) -- zeron.notify { title, body?, session? } a notification, as Zeron's -- own (Settings → Notifications) ("notifications") @@ -1343,8 +1361,16 @@ return function(id: string): any ui.invoke(`{prefix}.open_url`, url) end - function M.compose(text: string) - ui.invoke("zeron.compose.insert", text) + -- `text` into a chat's draft, for the person to send ("compose"): after + -- what's there, on a line of its own; with `replace = true`, in place of + -- its words (what it carries stays). The chat shown's draft, or + -- `session`'s ("" a new chat's). + function M.compose(text: string, opts: { replace: boolean?, session: string? }?) + if opts and (opts.replace or opts.session) then + ui.invoke("zeron.compose.insert", { text = text, replace = opts.replace == true, session = opts.session or ui.null }) + else + ui.invoke("zeron.compose.insert", text) + end end -- A review comment on a file or a diff, as a chip on a session's draft @@ -1374,6 +1400,57 @@ return function(id: string): any return composed:get() or {} end + -- The composer's draft as you type it: the chat it's for (nil, a new + -- chat), its words, and what it carries, each chip's kind ("file", + -- "image", "chat", …) and name, never a file's path. Read in a build or + -- an effect: it changes as the draft does. Nil until Zeron says. + -- (Reached on first read: only a plugin allowed "draft" may.) + local draft: any = nil + function M.draft(): { session: string?, text: string, attachments: { { kind: string, name: string } } }? + draft = draft or ui.shared("zeron.draft", nil :: any) + return draft:get() + end + + -- The draft shown, taken whole (its words, its chips, the passages + -- quoted in it) and kept by Zeron under `key`, yours, the composer + -- cleared; what that key kept before is replaced. An empty draft isn't + -- taken. Up to 16 kept at once. + function M.take_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "take", key = key }) + end + + -- What `key` kept, put back on the draft shown as it was taken (after + -- what's there, if the composer isn't empty), and no longer kept. + function M.put_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "put", key = key }) + end + + -- The draft shown and what `key` keeps, traded: either may be empty, so + -- one call sets the draft aside, brings it back, or swaps the two. + function M.swap_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "swap", key = key }) + end + + -- What `key` kept, let go of. + function M.drop_draft(key: string) + ui.invoke(`{prefix}.draft`, { op = "drop", key = key }) + end + + -- What Zeron keeps for you, by key: the chat each was taken from, its + -- words, what it carries (as `draft()` says it) and when (os.time). + -- Read in a build: it changes as you take and put back. + local drafts = ui.shared(`{prefix}.drafts`, {} :: { [string]: any }) + function M.drafts(): { [string]: { session: string?, text: string, attachments: { { kind: string, name: string } }, at: number } } + return drafts:get() or {} + end + + -- Chat `session`'s draft as it is now, unsent: shown or not (`draft()` + -- follows the one shown). A promise of { session?, text, attachments } + -- as `draft()` says it ("" a new chat's draft, with no session). + function M.draft_of(session: string): any + return ui.call(`{prefix}.draft_of`, session) + end + function M.toast(text: string) ui.invoke(`{prefix}.toast`, text) end diff --git a/apps/zgx/src/agents.rs b/apps/zgx/src/agents.rs index af62053ae..00506865c 100644 --- a/apps/zgx/src/agents.rs +++ b/apps/zgx/src/agents.rs @@ -411,6 +411,24 @@ pub fn install(host: &ScriptHost) { a.add_key(id, provider, key, name).await } }); + // An API key for Cloud's agents (Settings → Providers with Cloud + // shown): kept by the vault, authorized for the account's Cloud device + // (`device`), the key every Cloud machine uses from its next turn. + // Rejects with the engine's words, which never hold the key. + let a = agents.clone(); + host.async_action("agents.cloud_key", move |args| { + let a = a.clone(); + let provider = args.field("provider").map(text).unwrap_or_default(); + let key = args.field("key").map(text).unwrap_or_default().trim().to_string(); + let device = args.field("device").map(text).unwrap_or_default(); + async move { + crate::plugins::preview::refuse("agents.cloud_key")?; + let params = cloud_key_params(&provider, &key, &device)?; + engine::get().call("VaultPutApiKey", params).await.map_err(|error| engine::outcome(&error).to_string())?; + a.load_accounts(true).await; + Ok(Value::Nil) + } + }); // An API key's name (no secret: on whichever device shows it), rejecting // with the engine's words. let a = agents.clone(); @@ -1948,6 +1966,20 @@ fn epoch_secs(s: &str) -> Option { mod tests { use super::*; + /// A Cloud API key goes to the vault for the account's Cloud device: + /// Anthropic's or OpenAI's only, a real key, Cloud on. + #[test] + fn a_cloud_key_is_one_cloud_runs_for_its_device() { + let ok = cloud_key_params("anthropic-key", "sk-ant-123", "cloud-acct").unwrap(); + assert_eq!(ok, json!({ "provider": "anthropic-key", "key": "sk-ant-123", "authorizedDevices": ["cloud-acct"] })); + assert!(cloud_key_params("openai-key", "sk-1", "d").is_ok()); + assert!(cloud_key_params("claude", "sk", "d").is_err(), "a login isn't a key"); + assert!(cloud_key_params("anthropic-key", "", "d").is_err()); + assert!(cloud_key_params("anthropic-key", "a\nb", "d").is_err()); + assert!(cloud_key_params("anthropic-key", &"k".repeat(5000), "d").is_err()); + assert!(cloud_key_params("anthropic-key", "sk", "").is_err(), "Cloud off"); + } + /// Pi signed in to Claude, or another login put in use: Pi's models are /// looked up again. Usage moving, or another agent's, isn't Pi's change. #[test] @@ -2228,6 +2260,22 @@ pub(crate) fn shown_target() -> Option { } /// `params` addressed to the device Providers shows. +/// `VaultPutApiKey`'s params for a Cloud API key: Anthropic's or OpenAI's +/// alone, a key that's there and no longer than any key is, for the +/// account's Cloud device. Else why not. +pub(crate) fn cloud_key_params(provider: &str, key: &str, device: &str) -> Result { + if !matches!(provider, "anthropic-key" | "openai-key") { + return Err("Cloud takes Anthropic and OpenAI keys".into()); + } + if key.is_empty() || key.len() > 4096 || key.chars().any(char::is_control) { + return Err("That isn't an API key".into()); + } + if device.is_empty() { + return Err("Turn Cloud on in Settings → Cloud first".into()); + } + Ok(json!({ "provider": provider, "key": key, "authorizedDevices": [device] })) +} + pub(crate) fn addressed_to_shown(params: Json) -> Json { addressed_to(shown_target().as_deref(), params) } diff --git a/apps/zgx/src/links.rs b/apps/zgx/src/links.rs index 8d647e251..a2486dcce 100644 --- a/apps/zgx/src/links.rs +++ b/apps/zgx/src/links.rs @@ -71,6 +71,41 @@ pub fn open(url: &str) { }); } +/// Banner clicks, taken in this process. The engine posts Zeron's banners, +/// but macOS hands a click to the app its bundle names (Zeron.app's +/// interface, this process), never to the engine that posted it, so the +/// engine's own route (`open -a … zeron://notification/…`) never runs. As +/// Zeron.app's interface always has (crates/ui `notify::on_click`), the +/// click is answered here: Zeron comes forward, on the banner's chat. +pub fn take_banner_clicks() { + zeron_notify::on_click(|target| { + activate(); + clicked(&target); + }); +} + +/// A clicked banner's target (a chat, or agent updates), opened as its +/// `zeron://notification/` link is. +fn clicked(target: &str) { + open(&zeron_notify::link(target)); +} + +/// This app to the front: a banner was clicked. (Main thread: the click +/// comes through the AppKit delegate.) +#[cfg(target_os = "macos")] +fn activate() { + use objc::{class, msg_send, sel, sel_impl}; + unsafe { + let app: *mut objc::runtime::Object = msg_send![class!(NSApplication), sharedApplication]; + if !app.is_null() { + let _: () = msg_send![app, activateIgnoringOtherApps: true]; + } + } +} + +#[cfg(not(target_os = "macos"))] +fn activate() {} + fn tell(target: Target) { let seq = SEQ.with(|s| { s.set(s.get() + 1); @@ -94,6 +129,28 @@ fn tell(target: Target) { mod tests { use super::*; + fn last() -> (Option, Option) { + LAST.with(|l| { + let l = l.borrow(); + let text = |k: &str| match l.field(k) { + Some(Value::Str(s)) => Some(s.to_string()), + Some(Value::Text(s)) => Some(s.to_string()), + _ => None, + }; + (text("chat"), text("settings")) + }) + } + + /// A banner clicked in this process (macOS hands the click to the app, + /// not the engine that posted it) opens its chat as its link would. + #[test] + fn a_clicked_banner_opens_its_chat() { + clicked("chat-42"); + assert_eq!(last(), (Some("chat-42".into()), None)); + clicked(zeron_notify::AGENT_UPDATES_TARGET); + assert_eq!(last(), (None, Some("providers".into()))); + } + #[test] fn banners_and_chat_links_open_where_zeron_s_do() { assert_eq!(parse(&zeron_notify::link("chat-1")), Some((Target::Chat("chat-1".into()), None))); diff --git a/apps/zgx/src/main.rs b/apps/zgx/src/main.rs index 11a592697..e3431f7b8 100644 --- a/apps/zgx/src/main.rs +++ b/apps/zgx/src/main.rs @@ -352,6 +352,8 @@ fn main() -> Result<(), Box> { } }); } + // A clicked banner: Zeron forward on its chat (src/links.rs). + links::take_banner_clicks(); let options = match screen { Screen::Intro => intro_window(), Screen::Onboarding => onboarding_window(), diff --git a/apps/zgx/src/plugins/grants.rs b/apps/zgx/src/plugins/grants.rs index 6093dfebd..2e731d6e2 100644 --- a/apps/zgx/src/plugins/grants.rs +++ b/apps/zgx/src/plugins/grants.rs @@ -39,6 +39,9 @@ pub const SHARED_READ: &[(&str, Option<&str>)] = &[ ("zeron.project", Some("zeron.sessions")), ("zeron.device", Some("zeron.devices")), ("zeron.devices", Some("zeron.devices")), + // The draft in the window's composer, for a plugin allowed "draft": + // `{ session, text, attachments = { { kind, name } } }`, never a path. + ("zeron.draft", Some("zeron.draft")), // Whether the window shows and is in front (the SDK's `zeron.window`): // work no one would see waits for it. ("zgx.window.shown", None), @@ -77,9 +80,9 @@ pub const ACTIONS: &[(&str, &str)] = &[ pub const NEVER_REPLACED: &[&str] = &["@app/screens/plugins", "@app/screens/shell/settings"]; /// Each plugin's own actions (`plugin..`). -pub const OWN_ACTIONS: &[&str] = &["result", "ack", "send", "menus", "toast", "problem", "open_tab", "add_page", "github_watch", "github_call", "store_set", "setting_status", "open_url", "notify", "cost", "run", "db", "service_call", "agents", "menu_run", "compose_comment", "file", "block"]; +pub const OWN_ACTIONS: &[&str] = &["result", "ack", "send", "menus", "toast", "problem", "open_tab", "add_page", "github_watch", "github_call", "store_set", "setting_status", "open_url", "notify", "cost", "run", "db", "service_call", "agents", "menu_run", "compose_comment", "draft", "draft_of", "file", "block"]; /// Each plugin's own shared state, to read (`plugin..`). -pub const OWN_SHARED: &[&str] = &["calls", "inbox", "records", "github", "store", "settings", "locales", "menu_items", "composed"]; +pub const OWN_SHARED: &[&str] = &["calls", "inbox", "records", "github", "store", "settings", "locales", "menu_items", "composed", "drafts"]; /// The capability naming plugin `id`'s own calls and actions. pub fn own(id: &str) -> Capability { @@ -252,6 +255,9 @@ pub fn capabilities(id: &str, permissions: &[String], change: &[String], replace "pages.add" => out.push(Capability::OverrideElement(page_selector(id))), "navigate" => out.push(named("zeron.navigate")), "compose" => out.push(named("zeron.compose")), + // Reading the composer's draft (`zeron.draft`); taking it and + // putting it back are its own action's, checked by the host. + "draft" => out.push(named("zeron.draft")), "devices" => out.push(named("zeron.devices")), "network" => out.push(Capability::Fetch), "clipboard" => out.push(Capability::Clipboard), @@ -394,6 +400,15 @@ mod tests { assert!(!got.iter().any(|c| matches!(c, Capability::Override(_)))); } + /// "draft" reads the composer's draft; "compose" alone never does. + #[test] + fn only_draft_reads_the_draft() { + let draft = Capability::Named("zeron.draft".into()); + assert_eq!(capabilities("stash", &s(&["draft"]), &[], &[]), vec![own("stash"), draft.clone()]); + assert!(!capabilities("x", &s(&["compose"]), &[], &[]).contains(&draft)); + assert!(SHARED_READ.contains(&("zeron.draft", Some("zeron.draft")))); + } + #[test] fn listed_targets_without_the_permission_give_nothing() { let got = capabilities("x", &[], &s(&["#titlebar-actions"]), &s(&["@app/screens/chat"])); diff --git a/apps/zgx/src/plugins/mod.rs b/apps/zgx/src/plugins/mod.rs index 43e8a8776..a557ef1bc 100644 --- a/apps/zgx/src/plugins/mod.rs +++ b/apps/zgx/src/plugins/mod.rs @@ -456,6 +456,88 @@ pub(crate) fn comment(asked: &Value, shown: &str) -> Option { Some(json_value(&out)) } +/// The longest key a plugin keeps a taken draft under. +const DRAFT_KEY: usize = 64; + +/// A plugin's ask of the composer's draft (`zeron.take_draft`, +/// `put_draft`, `swap_draft`, `drop_draft`), held to `{ op, key }`: `op` +/// one of "take", "put", "swap" or "drop", `key` 1 to 64 characters with +/// no control characters. Anything else is refused. +pub(crate) fn draft_ask(asked: &Value) -> Option { + let op = asked.field("op").map(text)?; + let key = asked.field("key").map(text)?; + let valid_key = !key.is_empty() && key.chars().count() <= DRAFT_KEY && !key.chars().any(char::is_control); + if !matches!(op.as_str(), "take" | "put" | "swap" | "drop") || !valid_key { + return None; + } + Some(Value::record([("op", Value::from(op.as_str())), ("key", Value::from(key.as_str()))])) +} + +/// What `zeron.compose` asks of the composer: its words alone (added to +/// the draft shown, as ever), or with `{ text, replace, session }` (the +/// draft's words replaced, or a chat named other than the one shown). +pub(crate) fn compose(asked: &Value) -> Value { + let Some(words) = asked.field("text") else { + return Value::from(text(asked).as_str()); + }; + let words = match words { + Value::Str(_) | Value::Text(_) => words.clone(), + _ => Value::from(""), + }; + let mut fields = vec![ + ("text", words), + ("replace", Value::from(matches!(asked.field("replace"), Some(Value::Bool(true))))), + ]; + if let Some(session) = asked.field("session").map(text).filter(|s| !s.is_empty()) { + fields.push(("session", Value::from(session.as_str()))); + } + Value::record(fields) +} + +/// The app's shared states a chat's draft lives in (screens/chat/shared), +/// each read with the value the app starts it at: read before the app has +/// made one, it's made as the app would. +const DRAFT_HERE: &str = "chat.composer.here"; +const DRAFT_TEXT: &str = "chat.composer.text"; +const DRAFT_CARGO: &str = "chat.composer.cargo"; +const DRAFTS_KEPT: &str = "chat.composer.drafts"; + +/// What a draft carries, as plugins are told it (as `zeron.draft()` says +/// it, screens/plugins): each chip's kind and name, never a file's path. +fn draft_attachments(cargo: &Value) -> Value { + let said = |item: &Value, field: &str, or: &str| match item.field(field) { + Some(v @ Value::Str(_)) => v.clone(), + _ => Value::from(or), + }; + vlist(cargo.items().iter().map(|item| Value::record([("kind", said(item, "kind", "file")), ("name", said(item, "name", ""))])).collect()) +} + +/// Chat `session`'s draft, for `zeron.draft_of` ("draft"): out in the +/// composer (`here` its chat, "" a new chat's; `shown` its words, `cargo` +/// its chips) or kept for it (`kept`, by chat). Its words as typed, what it +/// carries, and its chat (none for a new chat's). A chat with no draft has +/// no words and carries nothing. +pub(crate) fn draft_of(session: &str, here: &Value, shown: &Value, cargo: &Value, kept: &Value) -> Value { + let (words, carried) = if session == text(here) { + (shown.clone(), cargo.clone()) + } else { + let d = kept.field(session); + ( + d.and_then(|d| d.field("text")).cloned().unwrap_or_default(), + d.and_then(|d| d.field("cargo")).cloned().unwrap_or_default(), + ) + }; + let words = match words { + Value::Str(_) | Value::Text(_) => words, + _ => Value::from(""), + }; + let mut fields = vec![("text", words), ("attachments", draft_attachments(&carried))]; + if !session.is_empty() { + fields.push(("session", Value::from(session))); + } + Value::record(fields) +} + /// Plugins for the main window `cx` shows `host` in. pub fn install(cx: &mut WindowContext, host: &ScriptHost) { expose_surface(host); @@ -2398,6 +2480,49 @@ impl Bridge { } } }); + // The composer's draft taken (its words, its chips, the passages + // quoted in it), put back or let go, under a key of the plugin's, + // for a plugin allowed "draft": screens/plugins keeps what's taken + // (the plugin never holds its files' paths) and tells it what it + // keeps as `plugin..drafts`. + host.action(format!("plugin.{id}.draft"), { + let (me, plugin) = (me.clone(), plugin.clone()); + move |asked| { + if let Some(b) = me.upgrade() + && b.item(&plugin).is_some_and(|i| i.may("draft")) + { + match draft_ask(&asked) { + Some(asked) => b.request("draft", &plugin, asked), + None => eprintln!("zeron-zgx: plugin {plugin}: a draft ask that isn't take, put, swap or drop with a key, refused"), + } + } + } + }); + // Another chat's draft, as it is (`zeron.draft_of`, "draft"): read + // where the app keeps it, once, never followed. + host.async_action(format!("plugin.{id}.draft_of"), { + let (me, plugin) = (me.clone(), plugin.clone()); + move |asked| { + let (me, plugin) = (me.clone(), plugin.clone()); + async move { + let b = me.upgrade().ok_or("This plugin isn't on")?; + let item = b.item(&plugin).ok_or("This plugin isn't on")?; + if !item.may("draft") { + return Err("This plugin wasn't allowed to read what you type in the message box".to_string()); + } + let session = text(&asked); + if session.chars().count() > 200 { + return Err("That isn't a chat".to_string()); + } + let read = |name: &str, initial: Value| b.host.shared(name, initial).signal().with_untracked(Value::clone); + let here = read(DRAFT_HERE, Value::from("")); + let shown = read(DRAFT_TEXT, Value::from("")); + let cargo = read(DRAFT_CARGO, vlist(Vec::new())); + let kept = read(DRAFTS_KEPT, Value::record(Vec::<(&str, Value)>::new())); + Ok(draft_of(&session, &here, &shown, &cargo, &kept)) + } + } + }); host.action(format!("plugin.{id}.open_url"), { let (me, plugin) = (me.clone(), plugin.clone()); move |url| { @@ -3298,9 +3423,9 @@ impl Bridge { }); host.action("zeron.compose.insert", { let me = me.clone(); - move |text_| { + move |asked| { if let Some(b) = me.upgrade() { - b.request("compose", "", Value::from(text(&text_).as_str())); + b.request("compose", "", compose(&asked)); } } }); @@ -3442,6 +3567,52 @@ mod tests { assert_eq!(gone, vec!["clock".to_string(), "ping".to_string()]); } + /// `zeron.compose(text)` adds its words as ever; with options, it says + /// whether they replace the draft and which chat's (none: the shown). + #[test] + fn compose_takes_words_alone_or_with_replace_and_a_chat() { + assert_eq!(compose(&Value::from("hello")), Value::from("hello")); + let asked = json_value(&json!({ "text": "clearer", "replace": true, "session": "s2" })); + let out = compose(&asked); + assert_eq!(text(out.field("text").unwrap()), "clearer"); + assert_eq!(out.field("replace"), Some(&Value::from(true))); + assert_eq!(text(out.field("session").unwrap()), "s2"); + // (Only `true` replaces; a blank chat is the one shown; words that + // aren't text are none.) + let loose = json_value(&json!({ "text": 5, "replace": "yes", "session": "" })); + let out = compose(&loose); + assert_eq!(text(out.field("text").unwrap()), ""); + assert_eq!(out.field("replace"), Some(&Value::from(false))); + assert!(out.field("session").is_none()); + } + + /// `zeron.draft_of`: the chat shown's draft (from the composer), or + /// another chat's (kept), with its chat and its chips by kind and name + /// alone; a new chat's has no chat; a chat with none, nothing. + #[test] + fn a_chats_draft_is_read_where_it_is_kept_without_paths() { + let kept = json_value(&json!({ + "s2": { "text": "kept words", "cargo": [{ "kind": "file", "name": "a.rs", "path": "/Users/me/a.rs" }] }, + "": { "text": "new chat words", "cargo": [] }, + })); + let (here, shown) = (Value::from("s1"), Value::from("typing now")); + let cargo = json_value(&json!([{ "kind": "image", "name": "shot.png", "path": "/tmp/shot.png" }])); + let out = draft_of("s1", &here, &shown, &cargo, &kept); + assert_eq!(value_json(&out), json!({ "text": "typing now", "session": "s1", "attachments": [{ "kind": "image", "name": "shot.png" }] })); + let out = draft_of("s2", &here, &shown, &cargo, &kept); + assert_eq!(value_json(&out), json!({ "text": "kept words", "session": "s2", "attachments": [{ "kind": "file", "name": "a.rs" }] })); + assert!(!out.to_json().contains("/Users/me"), "never a path"); + // A chat with no draft: nothing written, nothing carried. + let out = draft_of("s9", &here, &shown, &cargo, &kept); + assert_eq!(value_json(&out), json!({ "text": "", "session": "s9", "attachments": [] })); + // A new chat's draft, kept while a chat shows: no chat. + let out = draft_of("", &here, &shown, &cargo, &kept); + assert_eq!(value_json(&out), json!({ "text": "new chat words", "attachments": [] })); + // Before the app has made its states: nothing, not an error. + let out = draft_of("s1", &Value::Nil, &Value::Nil, &Value::Nil, &Value::Nil); + assert_eq!(text(out.field("text").unwrap()), ""); + } + /// R21: a plugin's review comment goes on the chat shown alone, with /// at most the 40 lines of code that are sent (a 20,000-character /// snippet once rode along unseen, onto any chat's draft). @@ -3462,6 +3633,23 @@ mod tests { assert!(text(comment(&wide, "s1").unwrap().field("snippet").unwrap()).len() <= COMMENT_BYTES); } + /// A plugin's ask of the draft is take, put, swap or drop, under a key + /// of 1 to 64 characters; nothing else rides along to the app. + #[test] + fn a_draft_ask_is_take_put_or_drop_with_a_key() { + let ask = |v: Json| draft_ask(&json_value(&v)); + let took = ask(json!({ "op": "take", "key": "stash", "extra": "dropped" })).expect("a take"); + assert_eq!(value_json(&took), json!({ "op": "take", "key": "stash" })); + assert!(ask(json!({ "op": "put", "key": "k".repeat(64) })).is_some()); + assert!(ask(json!({ "op": "drop", "key": "é" })).is_some()); + assert!(ask(json!({ "op": "swap", "key": "stash" })).is_some()); + assert!(ask(json!({ "op": "send", "key": "stash" })).is_none(), "not an op"); + assert!(ask(json!({ "op": "take", "key": "" })).is_none(), "no key"); + assert!(ask(json!({ "op": "take" })).is_none(), "no key"); + assert!(ask(json!({ "op": "take", "key": "k".repeat(65) })).is_none(), "too long"); + assert!(ask(json!({ "op": "take", "key": "a\nb" })).is_none(), "a control character"); + } + #[test] fn only_a_plugin_on_loads_from_its_snapshot_with_its_grants() { let on = item(json!({ diff --git a/apps/zgx/src/sessions.rs b/apps/zgx/src/sessions.rs index 7e5810e89..f446abc04 100644 --- a/apps/zgx/src/sessions.rs +++ b/apps/zgx/src/sessions.rs @@ -191,6 +191,21 @@ struct RowWith { working_side_chats: u32, known_project: bool, agent_icon: Option, + /// The last turn its agent finished, as its session row marks it + /// (`lastCompletedTurn`): what a "finished" chime rings on moving. + turn: Option, +} + +/// A session row's finished turn, and whether the row is fresh: written in +/// the last `SESSION_STALE_MS`, so a turn's end just published rather than +/// an old row a sync or reconnect brings back (the shipping app's chime +/// rule, crates/engine/src/desktop_notify.rs `SessionNotificationState`). +fn finished_turn(session: Option<&Session>, at: chrono::DateTime) -> (Option, bool) { + let Some(s) = session else { + return (None, false); + }; + let fresh = at.signed_duration_since(s.updated_at).num_milliseconds() <= zeron_proto::view::SESSION_STALE_MS; + (s.last_completed_turn.clone(), fresh) } /// `slot` holds `item` now; whether that's new. @@ -621,6 +636,7 @@ fn child_row(rows: &mut HashMap, c: &Json, id: &str, parent: &str, working_side_chats: 0, known_project: false, agent_icon: harness.and_then(crate::agents::registry_icon), + turn: None, }; if rows.get(id).is_some_and(|row| row.with == with) { return; @@ -681,6 +697,7 @@ fn top_row( working_side_chats, known_project: project.is_some(), agent_icon: harness.and_then(crate::agents::registry_icon), + turn: finished_turn(session, at).0, }; if let Some(row) = rows.get(id).filter(|row| row.with == with) { return row.value.clone(); @@ -721,6 +738,12 @@ fn top_row( // it woke (Unix seconds). ("sleep_until", with.sleep.filter(|s| s.0).map_or(Value::Nil, |s| Value::from(s.1 as f64))), ("woke", with.sleep.filter(|s| !s.0).map_or(Value::Nil, |s| Value::from(s.1 as f64))), + // The last turn its agent finished (an opaque mark), and whether its + // session row was fresh when that was read: the chimes ring + // "finished" on this moving, never on the status alone ("done" is + // only unseen activity, which your own send makes too). + ("turn", with.turn.as_deref().map_or(Value::Nil, Value::from)), + ("turn_fresh", Value::from(finished_turn(session, at).1)), ]); rows.insert(id.to_owned(), Row { moved: moved(c), updated: updated as f64, marks, with, value: value.clone() }); value @@ -2516,6 +2539,33 @@ mod tests { assert!(!s.rows.borrow().contains_key("b")); } + /// A chat's finished turn (what the "done" chime rings on, issue #1437): + /// its session's `lastCompletedTurn`, published as it moves, and whether + /// the row saying so is fresh. + #[test] + fn a_chat_s_finished_turn_is_published_as_it_moves() { + let now = now_seconds(); + let s = with_children("2099-01-01T00:00:00Z"); + s.heard.set(true); + let row = |turn: &str, ago: i64| { + json!([{ "chatId": "p", "deviceId": "d", "status": "idle", "updatedAt": iso(now - ago), "lastCompletedTurn": turn }]) + }; + s.set_live(row("t1", 1)); + s.publish(); + let p = s.value(); + assert_eq!(chat(&p, "p").field("turn").map(crate::auth::text).as_deref(), Some("t1")); + assert!(chat(&p, "p").field("turn_fresh").is_some_and(zgx_script::Value::truthy)); + let before = s.published.get(); + s.heard(Slot::Live, row("t2", 0)); + assert_eq!(s.published.get(), before + 1, "a finish is shown at once"); + assert_eq!(chat(&s.value(), "p").field("turn").map(crate::auth::text).as_deref(), Some("t2")); + // An end published long ago (a sync, a reconnect): not fresh. + s.heard(Slot::Live, row("t3", 600)); + let p = s.value(); + assert_eq!(chat(&p, "p").field("turn").map(crate::auth::text).as_deref(), Some("t3")); + assert!(!chat(&p, "p").field("turn_fresh").is_some_and(zgx_script::Value::truthy)); + } + #[test] fn an_update_that_changes_nothing_publishes_nothing() { let s = with_children("2099-01-01T00:00:00Z"); diff --git a/apps/zgx/ui/account/sessions.luau b/apps/zgx/ui/account/sessions.luau index 22b51e557..7940c4c68 100644 --- a/apps/zgx/ui/account/sessions.luau +++ b/apps/zgx/ui/account/sessions.luau @@ -77,6 +77,11 @@ export type Chat = { -- woke (Unix seconds). sleep_until: number?, woke: number?, + -- The last turn its agent finished (an opaque mark, nil before its + -- first), and whether its session row was fresh as that was read: what + -- the "finished" chime rings on moving (screens/settings/chimes). + turn: string?, + turn_fresh: boolean?, } export type WaitingOn = { id: string, kind: string, label: string } -- A side chat: a chat under another (its `parent`). diff --git a/apps/zgx/ui/chat_fixture.luau b/apps/zgx/ui/chat_fixture.luau index dbed19a9d..16d15fda3 100644 --- a/apps/zgx/ui/chat_fixture.luau +++ b/apps/zgx/ui/chat_fixture.luau @@ -1616,6 +1616,29 @@ ui.effect(function() table.sort(keys) plugin_comments:set(table.concat(keys, ",")) end) +-- The draft lifted out whole and laid back (a plugin's `zeron.take_draft` +-- and `put_draft`; screens/plugins keeps it between the two, as this +-- does). `test_lifted` says what was lifted: its words and how many chips. +local lifted: any = nil +local lifted_said = ui.state("test_lifted", "") +ui.command { + id = "draft_lift", + title = "A plugin takes the draft", + run = function() + lifted = require("@app/screens/chat/shared").lift() + lifted_said:set(if lifted then `{lifted.text}|{#lifted.cargo}` else "nothing") + end, +} +ui.command { + id = "draft_lay", + title = "A plugin puts the draft back", + run = function() + if lifted then + require("@app/screens/chat/shared").lay(lifted) + lifted = nil + end + end, +} ui.command { id = "comment_moves", title = "The comment is carried two lines down", diff --git a/apps/zgx/ui/chimes_fixture.luau b/apps/zgx/ui/chimes_fixture.luau new file mode 100644 index 000000000..a9788cbae --- /dev/null +++ b/apps/zgx/ui/chimes_fixture.luau @@ -0,0 +1,7 @@ +-- The session chimes (screens/settings/chimes) with no engine: a test sets +-- the `sessions` shared state as the engine would publish it, and reads what +-- played from `settings_stub_calls` ("sound.play:done", …). +require("./settings_stub") +require("@app/screens/settings/chimes") + +return ui.column {} diff --git a/apps/zgx/ui/consent_fixture.luau b/apps/zgx/ui/consent_fixture.luau index 666c0d1fd..0c70daf87 100644 --- a/apps/zgx/ui/consent_fixture.luau +++ b/apps/zgx/ui/consent_fixture.luau @@ -174,9 +174,9 @@ local PLUGINS: { [string]: any } = { hash = "long-1", status = "pending", author = { kind = "unknown" }, - permissions = { "ui.add", "ui.change", "profile.read", "sessions.read", "messages.read", "account.email", "files.read", "panel.tabs", "pages.add", "github", "github.write", "notifications", "links.open", "navigate", "compose", "network", "clipboard", "files", "web", "windows", "tools", "devices", "service", "commands", "native" }, + permissions = { "ui.add", "ui.change", "profile.read", "sessions.read", "messages.read", "account.email", "files.read", "panel.tabs", "pages.add", "github", "github.write", "notifications", "links.open", "navigate", "compose", "draft", "network", "clipboard", "files", "web", "windows", "tools", "devices", "service", "commands", "native" }, allowed = {}, - ask = { "ui.add", "ui.change", "profile.read", "sessions.read", "messages.read", "account.email", "files.read", "panel.tabs", "pages.add", "github", "github.write", "notifications", "links.open", "navigate", "compose", "network", "clipboard", "files", "web", "windows", "tools", "devices", "service", "commands", "native" }, + ask = { "ui.add", "ui.change", "profile.read", "sessions.read", "messages.read", "account.email", "files.read", "panel.tabs", "pages.add", "github", "github.write", "notifications", "links.open", "navigate", "compose", "draft", "network", "clipboard", "files", "web", "windows", "tools", "devices", "service", "commands", "native" }, ui = { change = { "#shell" } }, commands = { "git" }, tools = { { name = "a", description = "First." } }, diff --git a/apps/zgx/ui/ds/provider_card.luau b/apps/zgx/ui/ds/provider_card.luau index 6e3cb0f3c..959c15355 100644 --- a/apps/zgx/ui/ds/provider_card.luau +++ b/apps/zgx/ui/ds/provider_card.luau @@ -221,6 +221,9 @@ export type CardProps = { -- back, Claude's when it can't finish in the browser) or "failed". foot: (string | () -> string)?, enabled: State, + -- An agent nothing here switches or updates (Cloud's: on every Cloud + -- machine, its accounts alone managed here): no switch, no Update. + fixed: boolean?, -- The account in use, by its email. active: () -> string?, settings: boolean?, @@ -1468,7 +1471,7 @@ function M.Card(c: CardProps): Node gap = "$space.3", items = "center", ui.show(function() - return latest() ~= nil or (c.updating ~= nil and c.updating()) + return not c.fixed and (latest() ~= nil or (c.updating ~= nil and c.updating())) end, Button { locale.t("ds.provider_card.update"), tone = "secondary", @@ -1488,7 +1491,7 @@ function M.Card(c: CardProps): Node on_click = c.on_settings, } else nil, - Switch { value = c.enabled, label = locale.t("ds.provider_card.enabled", { name = provider.name }) :: any }, + if c.fixed then nil else Switch { value = c.enabled, label = locale.t("ds.provider_card.enabled", { name = provider.name }) :: any }, }, } -- Its accounts, a row each, keyed: one arriving or going is that row diff --git a/apps/zgx/ui/locales/en.json b/apps/zgx/ui/locales/en.json index ca649afdb..bd46a6a85 100644 --- a/apps/zgx/ui/locales/en.json +++ b/apps/zgx/ui/locales/en.json @@ -1631,7 +1631,18 @@ }, "remove_row_description": "Chats that used it stay." }, - "couldnt_switch": "Couldn't switch accounts" + "couldnt_switch": "Couldn't switch accounts", + "cloud": "Cloud", + "cloud_keys": { + "title": "API keys", + "section_description": "Instead of signing in, Cloud can use an API key. A key saved here becomes the account its agent uses on every Cloud machine, from its next turn.", + "anthropic": "Anthropic API key", + "openai": "OpenAI API key", + "description": "For {agent} on Cloud. Kept in Zeron's vault, never on this computer.", + "placeholder": "Paste a key", + "save": "Save", + "saved": "{agent} on Cloud now uses this key" + } }, "devices": { "title": "Devices", @@ -3220,7 +3231,8 @@ "show": "Show in Finder", "dismiss": "Dismiss {name}", "saving": "Saving…" - } + }, + "dismiss_error": "Dismiss" }, "browser_api": { "empty": "Enter a website or localhost address.", @@ -3484,7 +3496,11 @@ }, "compose": { "title": "Put text in the message box", - "detail": "You still send it." + "detail": "It can add to what you've written or replace it. You still send it." + }, + "draft": { + "title": "Read what you type in the message box, and set it aside", + "detail": "It sees your words in any chat before you send them, and can take the draft away and put it back later. It never sends it." }, "network": { "title": "Connect to the internet", diff --git a/apps/zgx/ui/locales/zh-Hans.json b/apps/zgx/ui/locales/zh-Hans.json index bd31e2390..27d1fe97e 100644 --- a/apps/zgx/ui/locales/zh-Hans.json +++ b/apps/zgx/ui/locales/zh-Hans.json @@ -1631,7 +1631,18 @@ }, "remove_row_description": "使用过它的对话会保留。" }, - "couldnt_switch": "无法切换账户" + "couldnt_switch": "无法切换账户", + "cloud": "云端", + "cloud_keys": { + "title": "API 密钥", + "section_description": "云端也可以使用 API 密钥,而不必登录。在此保存的密钥会成为该代理在每台云端机器上使用的账户,从下一轮开始生效。", + "anthropic": "Anthropic API 密钥", + "openai": "OpenAI API 密钥", + "description": "用于云端的 {agent}。保存在 Zeron 的密钥库中,不会存放在这台电脑上。", + "placeholder": "粘贴密钥", + "save": "保存", + "saved": "云端的 {agent} 现在使用此密钥" + } }, "devices": { "title": "设备", @@ -3220,7 +3231,8 @@ "show": "在访达中显示", "dismiss": "关闭 {name}", "saving": "正在保存…" - } + }, + "dismiss_error": "关闭" }, "browser_api": { "empty": "输入网站或 localhost 地址。", @@ -3484,7 +3496,11 @@ }, "compose": { "title": "在消息输入框中填写文本", - "detail": "仍由你来发送。" + "detail": "它可以补充或替换你写的内容,仍由你来发送。" + }, + "draft": { + "title": "读取你在消息输入框中输入的内容,并可暂存", + "detail": "它能在你发送前看到你在任意聊天中输入的文字,也能把草稿暂时取走、稍后放回。它不会替你发送。" }, "network": { "title": "连接互联网", diff --git a/apps/zgx/ui/screens/chat/shared.luau b/apps/zgx/ui/screens/chat/shared.luau index 65c706396..53a6dba09 100644 --- a/apps/zgx/ui/screens/chat/shared.luau +++ b/apps/zgx/ui/screens/chat/shared.luau @@ -13,6 +13,7 @@ local Quote = require("@ds/quote") local Annotation = require("@ds/annotation") local sessions = require("@account/sessions") local agents = require("@account/agents") +local cloud = require("@account/cloud") local locale = require("@ds/locale") local toast = require("@ds/toast") local ChatLinks = require("@app/screens/chat/chat_links") @@ -228,6 +229,11 @@ function M.showing(): string return here:peek() end +-- The same, read as it changes. +function M.showing_now(): string + return here:get() +end + function M.show(key: string) local was = here:peek() if was == key then @@ -264,6 +270,52 @@ function M.take(): (string, { any }) return text, cargo end +-- The draft shown, lifted out whole to be put back later (a plugin's +-- `zeron.take_draft`): its words as typed, its chips and the passages +-- quoted in it, the composer cleared. Nil when there's nothing to lift. +function M.lift(): { text: string, cargo: { any }, quotes: { [string]: string } }? + local text, cargo, quotes = M.text:peek(), M.cargo:peek(), M.quotes:peek() + if text == "" and #cargo == 0 then + return nil + end + ui.batch(function() + M.text:set("") + M.cargo:set({}) + M.quotes:set({}) + end) + return { text = text, cargo = cargo, quotes = quotes } +end + +-- A lifted draft put back on the draft shown (`zeron.put_draft`). Onto an +-- empty composer it's as it was; onto words already there, its words follow +-- them after a blank line and its chips follow theirs, its files numbered +-- after those there. +function M.lay(d: { text: string, cargo: { any }, quotes: { [string]: string } }) + local here_text, here_cargo = M.text:peek(), M.cargo:peek() + ui.batch(function() + if here_text == "" and #here_cargo == 0 then + M.text:set(d.text) + M.cargo:set(d.cargo) + M.quotes:set(d.quotes) + return + end + local quotes = table.clone(M.quotes:peek()) + for line, passage in d.quotes do + quotes[line] = passage + end + M.quotes:set(quotes) + if d.text ~= "" then + M.text:set(if here_text == "" then d.text else `{here_text}\n\n{d.text}`) + end + for _, item in d.cargo do + local moved = table.clone(item) + moved.mention = nil + M.push_cargo(nil, moved) + end + end) + M.focus:add(1) +end + -- A passage of the transcript, quoted into the draft (its line marks it) -- or carried as a chip. function M.mention(q: Quote.Quote) @@ -893,6 +945,16 @@ function M.draft_of(key: string): { text: string, cargo: { any }, chosen: { [str } end +-- Chat `key`'s draft's words as they are, read without following them +-- (`draft_of` follows them): what a plugin's `zeron.compose` adds to. +function M.peek_text_of(key: string): string + if here:peek() == key then + return M.text:peek() + end + local d = kept:peek()[key] + return if d and type(d.text) == "string" then d.text else "" +end + -- Chat `key`'s draft changed where it's shown by its id (`field`: "text" -- or "chosen"): written wherever it is, as `draft_of` reads it. function M.set_draft_of(key: string, field: string, value: any) @@ -970,9 +1032,19 @@ local here_device = ui.computed(function(): string? end) -- The accounts' key for a device: "" for this one, whose engine answers --- for itself. +-- for itself; "cloud" for any of Cloud's (a chat's machine, or the +-- account's Cloud device), whose accounts are the vault's, every Cloud +-- machine's alike, as Settings → Providers shows them (this engine answers +-- for "cloud": crates/engine cloud_accounts). A machine can't be asked: +-- its accounts aren't its own, and asking would wake it. local function account_key(device: string?): string - return if device == nil or device == here_device:get() then "" else device + if device == nil or device == here_device:get() then + return "" + end + if cloud.on_device(device) or device == cloud.device() then + return "cloud" + end + return device end -- Models of Cursor's own pool (Composer, Grok), not the third-party one. diff --git a/apps/zgx/ui/screens/panel/browser.luau b/apps/zgx/ui/screens/panel/browser.luau index d204c8c90..6289bada6 100644 --- a/apps/zgx/ui/screens/panel/browser.luau +++ b/apps/zgx/ui/screens/panel/browser.luau @@ -433,6 +433,32 @@ Page = ui.component(function(props: Props): Node -- Annotation mode, as the bar's toggle shows it. local mode = ui.use_state(annotating:peek()[id] == true) + -- This navigation, as the page tells it: whether its own document came + -- (committed: the page's content, not the host's error page), whether + -- its process ended after, and whether its failure was dismissed. Each + -- starts over with the next navigation (a reload, Try again). + -- A failure after the page committed is no page missing: the page drew, + -- and it's what to show (a 429 or 5xx page, Google's "unusual traffic" + -- check: WebView2 calls a page with an error status a failed + -- navigation; WebKit a load interrupted once the page was in). + local committed = ui.use_state(false) + local crashed = ui.use_state(false) + local dismissed = ui.use_state(false) + -- The page that didn't load, over where it would be (`trouble`). + local function failed(): boolean + if not has_page(web) or web.error == nil or dismissed:get() then + return false + end + return crashed:get() or not committed:get() + end + local function dismiss(): boolean + if not failed() then + return false + end + dismissed:set(true) + return true + end + -- Made with an address and no page yet (a saved tab, a link opened): -- the page loads. (A reload finds the page where it was: nothing moves.) -- A new tab with a home page set opens on it (once: the start page is @@ -556,7 +582,7 @@ Page = ui.component(function(props: Props): Node end end local function start_annotating() - if not has_page(web) or web.error then + if not has_page(web) or failed() then if mode:peek() then mode:set(false) end @@ -969,6 +995,11 @@ Page = ui.component(function(props: Props): Node return true end if e.key == "Escape" then + -- (Nothing typed to take back: the failure over the page + -- dismissed, as from anywhere else in the tab.) + if address:peek() == last_url and dismiss() then + return true + end -- (Back to the page's address, as a browser's.) suggestions.quiet(last_url) address:set(last_url) @@ -1064,7 +1095,7 @@ Page = ui.component(function(props: Props): Node tooltip = ui.t("panel.browser.annotate_tooltip", { key = ui.shortcut_text(if shell_keys then shell_keys.combo("panel.annotate") else "cmd+shift+i") }):get(), tooltip_side = "bottom", disabled = function(): boolean - return not can_leave() or web.error ~= nil + return not can_leave() or failed() end, on_change = function(on: boolean) if on then @@ -1533,7 +1564,21 @@ Page = ui.component(function(props: Props): Node on_state(value.state) end end, + on_error = function(url: string, _why: string) + -- (The page's process ended: no navigation's, and nothing left + -- drawn, committed or not.) + if url == "" then + crashed:set(true) + end + end, on_navigate = function(e: any) + if type(e) == "table" and e.kind == "started" then + committed:set(false) + crashed:set(false) + dismissed:set(false) + elseif type(e) == "table" and e.kind == "committed" then + committed:set(true) + end -- Another page: its picker is gone with the last, so the mode -- ends (the shipping app's; its marks come back by restore). if type(e) == "table" and e.kind == "committed" and annotating:peek()[id] then @@ -1572,9 +1617,7 @@ Page = ui.component(function(props: Props): Node or string.find(l, "internet connection", 1, true) ~= nil or string.find(l, "not connected", 1, true) ~= nil end - local trouble = ui.show(function(): boolean - return has_page(web) and web.error ~= nil - end, ui.column { + local trouble = ui.show(failed, ui.column { absolute = true, left = 0, right = 0, @@ -1623,6 +1666,14 @@ Page = ui.component(function(props: Props): Node web:reload() end, }, + -- What the page drew anyway, under (Escape too): until the + -- next navigation. + secondary = { + label = ui.t("panel.browser.dismiss_error") :: any, + on_click = function() + dismiss() + end, + }, } end, { w_full = true, grow = 1, min_h = 0 }), }) @@ -1634,6 +1685,14 @@ Page = ui.component(function(props: Props): Node w_full = true, grow = 1, min_h = 0, + -- A bare Escape nothing in the tab took (the error's buttons, the + -- bar's): the failure dismissed, the page under it shown. + on_key = function(e: any): boolean? + if e.key == "Escape" and not (e.shift or e.cmd or e.alt or e.ctrl) and dismiss() then + return true + end + return nil + end, bar, problem_line, find_bar, diff --git a/apps/zgx/ui/screens/plugins/init.luau b/apps/zgx/ui/screens/plugins/init.luau index 7d3cbb4b4..372587175 100644 --- a/apps/zgx/ui/screens/plugins/init.luau +++ b/apps/zgx/ui/screens/plugins/init.luau @@ -17,6 +17,8 @@ -- zeron.device { id, name } where you're working -- zeron.devices { { id, name, here } } your devices -- zeron.appearance "light" | "dark" +-- zeron.draft { session?, text, attachments = { { kind, name } } } +-- the composer's draft ("draft") -- - **What records are made from**, for the host alone (no plugin reads -- these; each reads its own `plugin..records`, holding only what it -- was allowed, src/plugins/records.rs): @@ -43,7 +45,6 @@ local store = require("@app/screens/settings/store") local PrivateText = require("@ds/private_text") local state = require("@app/screens/plugins/state") local page = require("@app/screens/plugins/page") -local chat = require("@app/screens/chat") local ChatShared = require("@app/screens/chat/shared") local Cargo = require("@ds/composer_cargo") @@ -166,6 +167,128 @@ ui.effect(function() put(out.appearance, if kind == "light" or kind == "high-contrast-light" then "light" else "dark") end) +-- What a draft carries, as plugins are told it: each chip's kind and name +-- alone, never a file's path. +local function attachments_of(cargo: { any }): { any } + local list = {} + for _, item in cargo do + table.insert(list, { kind = tostring(item.kind or "file"), name = tostring(item.name or "") }) + end + return list +end + +-- The composer's draft, for plugins allowed "draft" (`zeron.draft()`): the +-- chat it's for (nil, a new chat), its words, and what it carries. +-- Written only while a plugin that's on may read it: otherwise no key +-- typed copies the draft (a long one, every key) for no one. +local draft_out = ui.shared("zeron.draft", nil :: any) +local draft_read = ui.computed(function(): boolean + for _, it in state.now:get().list or {} do + if it.status == "on" and table.find(it.permissions or {}, "draft") then + return true + end + end + return false +end) +ui.effect(function() + if not draft_read:get() then + if draft_out:peek() ~= nil then + put(draft_out, nil) + end + return + end + local key = ChatShared.showing_now() + put(draft_out, { + session = if key ~= "" then key else ui.null, + text = ChatShared.text:get(), + attachments = attachments_of(ChatShared.cargo:get()), + }) +end) + +-- The drafts plugins took (`zeron.take_draft`), each plugin's by its own +-- keys, kept whole here so a plugin never holds its files' paths. Kept for +-- the run, as chats' drafts are; a reload of the scripts keeps them. +-- Each plugin is told what it keeps (`plugin..drafts`): by key, the +-- chat it was taken from, its words, what it carries and when. +local DRAFTS_KEPT = 16 +local shelves = ui.shared("plugins.drafts", {} :: { [string]: { [string]: any } }) +local shelves_told: { [string]: boolean } = {} +ui.effect(function() + local all = shelves:get() + for plugin in all do + shelves_told[plugin] = true + end + for plugin in shelves_told do + local told: { [string]: any } = {} + for key, d in all[plugin] or {} do + told[key] = { + session = d.session or ui.null, + text = d.text, + attachments = attachments_of(d.cargo), + at = d.at, + } + end + ui.shared(`plugin.{plugin}.drafts`, {} :: any):set(told) + end +end) + +-- A plugin's ask of the draft (the host checked "draft" and that it's +-- take, put, swap or drop with a key). +local function draft_asked(plugin: string, op: string, key: string) + local all = table.clone(shelves:peek()) + local mine = table.clone(all[plugin] or {}) + -- (Room for one more, unless it goes where that key kept one.) + local count = 0 + for _ in mine do + count += 1 + end + local full = mine[key] == nil and count >= DRAFTS_KEPT + local function kept_now(d: any, from: string): any + return { text = d.text, cargo = d.cargo, quotes = d.quotes, session = if from ~= "" then from else nil, at = os.time() } + end + if op == "take" then + if full then + return + end + local from = ChatShared.showing() + local d = ChatShared.lift() + if d == nil then + return + end + mine[key] = kept_now(d, from) + elseif op == "swap" then + -- The draft shown and what `key` kept, traded: either may be + -- nothing, so one call sets a draft aside, brings it back, or both. + local was = mine[key] + local from = ChatShared.showing() + if full then + return + end + local d = ChatShared.lift() + if d == nil and was == nil then + return + end + if was ~= nil then + ChatShared.lay(was) + end + mine[key] = if d ~= nil then kept_now(d, from) else nil + elseif op == "put" then + local d = mine[key] + if d == nil then + return + end + mine[key] = nil + ChatShared.lay(d) + elseif op == "drop" then + if mine[key] == nil then + return + end + mine[key] = nil + end + all[plugin] = if next(mine) ~= nil then mine else nil + shelves:set(all) +end + -- What a failed plugin's notice offers (a toast's action: `ds/toast`). ds.toast.action("plugins.open_folder", function(id: string) state.open_folder(id) @@ -185,8 +308,26 @@ local function run(r: any) elseif type(to) == "table" and type(to.settings) == "string" and to.settings ~= "account" then route.settings(to.settings) end - elseif r.kind == "compose" and type(r.value) == "string" then - chat.store.insert(string.sub(r.value, 1, 20000)) + elseif r.kind == "compose" and (type(r.value) == "string" or (type(r.value) == "table" and type(r.value.text) == "string")) then + -- `zeron.compose(text, { replace, session })` (the host checked + -- "compose"; its words alone come as a string): the words put in a + -- chat's draft, the one shown unless it names another ("" a new + -- chat's), in place of its words (its chips stay) or after them, on + -- a line of their own. Unsent: the person sends it. Shown, the + -- composer takes the keys. + local v = if type(r.value) == "string" then { text = r.value } else r.value + local words = string.sub(v.text, 1, 20000) + local shown = ChatShared.showing() + local key = if type(v.session) == "string" and #v.session <= 200 then v.session else shown + if v.replace ~= true then + local now = ChatShared.peek_text_of(key) + local sep = if now == "" or string.sub(now, -1) == "\n" then "" else "\n" + words = now .. sep .. words + end + ChatShared.set_draft_of(key, "text", words) + if key == shown then + ChatShared.focus:add(1) + end elseif r.kind == "compose_comment" and type(r.value) == "table" and type(r.title) == "string" then -- A plugin's review comment on a file or a diff (the host checked -- "compose"): a comment chip on the session's draft, as the files @@ -207,6 +348,13 @@ local function run(r: any) session = if type(c.session) == "string" then c.session else nil, } end + elseif r.kind == "draft" and type(r.value) == "table" and type(r.title) == "string" and r.title ~= "" then + -- A plugin taking the draft, putting one back, swapping the two, or + -- letting one go. + local op, key = r.value.op, r.value.key + if type(op) == "string" and type(key) == "string" then + draft_asked(r.title, op, key) + end elseif r.kind == "panel_tab" and type(r.value) == "table" then -- A plugin's tab in a chat's panel (the host checked "panel.tabs"). local ok, Panel = pcall(require, "@app/screens/panel") diff --git a/apps/zgx/ui/screens/plugins/words.luau b/apps/zgx/ui/screens/plugins/words.luau index 911f70bd6..3e18ba196 100644 --- a/apps/zgx/ui/screens/plugins/words.luau +++ b/apps/zgx/ui/screens/plugins/words.luau @@ -298,6 +298,9 @@ function M.permission(item: any, permission: string): Line return line(false, "map-arrow-right", "plugins.words.permission.navigate.title") elseif permission == "compose" then return line(false, "chat-round-line", "plugins.words.permission.compose.title", "plugins.words.permission.compose.detail") + elseif permission == "draft" then + -- (What you type, read as you type it: said plainly.) + return line(false, "pen", "plugins.words.permission.draft.title", "plugins.words.permission.draft.detail") elseif permission == "network" then -- The places it names (any site, with "*"), those on this device or -- your network said so, and risky then. diff --git a/apps/zgx/ui/screens/settings/chimes.luau b/apps/zgx/ui/screens/settings/chimes.luau index 65f5cb1a8..6b8447374 100644 --- a/apps/zgx/ui/screens/settings/chimes.luau +++ b/apps/zgx/ui/screens/settings/chimes.luau @@ -1,9 +1,19 @@ -- The sessions' chimes, as the shipping app plays them (crates/ui --- shell.rs, its one session detector): a chat turning done, waiting on you, --- or failed plays its sound, if Settings → Notifications has it on. A --- chat's first appearance only sets where it stands (a launch, a sync, a --- hot reload never ring), and what it was is kept in state, so a reload --- picks up where it was. +-- shell.rs, its one session detector; crates/engine desktop_notify's +-- `ping_since`): a chat waiting on you, or failed, plays its sound as its +-- status turns so; a turn finished plays "done", if Settings → +-- Notifications has it on. A chat's first appearance only sets where it +-- stands (a launch, a sync, a hot reload never ring), and what it was is +-- kept in state, so a reload picks up where it was. +-- +-- "Finished" is the turn mark moving (`turn`, the session's +-- `lastCompletedTurn`), never the status "done": that's only activity you +-- haven't seen, and your own message makes it too (issue #1437). Nor does +-- every move ring: one published with the next turn already running is +-- your message carrying it on (a steer, a queued message taken), and a +-- send that replaces the agent's runtime marks the old turn's end a moment +-- before your turn starts, so a finish waits `SETTLE` to stand; a turn +-- going on (or asking, or failing) meanwhile takes it with it. -- -- And the window's focus, told to the engine (`SetViewportFocus`), which -- holds its banners while Zeron is the app in front if Notifications says @@ -16,39 +26,120 @@ local prefs = require("@app/screens/settings/prefs") local M = {} --- Each chat's status as last seen, by id ("" for idle). -local seen = ui.state("settings_chimes_seen", {} :: { [string]: string }) +type Seen = { status: string, turn: string? } --- What a status turning on plays. +-- Each chat as last seen, by id: its status ("" for idle) and finished turn. +local seen = ui.state("settings_chimes_seen_turns", {} :: { [string]: Seen }) + +-- Finishes waiting to stand, by chat: the turn, and when it rings +-- (`ui.now()`, ms). +local settling = ui.state("settings_chimes_settling", {} :: { [string]: { turn: string, at: number } }) + +-- How long a finish waits to stand before it rings (the engine's banners' +-- `DONE_SETTLE`). +local SETTLE = 2000 + +-- What a status turning on plays. ("done" isn't one: see above.) local SOUND: { [string]: string } = { - done = "done", input = "request", failed = "attention", } +-- A turn going on, or asking, or failing: nothing has finished. +local function busy(status: string): boolean + return status == "working" or status == "waiting" or status == "input" or status == "failed" +end + +-- One chime for many at once: the most urgent. +local function louder(ring: string?, sound: string): string + if ring == nil or sound == "attention" or (sound == "request" and ring == "done") then + return sound + end + return ring +end + +local function play(ring: string?) + if ring and prefs.chimes(ring) then + host.invoke("sound.play", ring) + end +end + ui.effect(function() local now = sessions.now:get() if now.state ~= "ready" then return end local before = seen:peek() - local after: { [string]: string } = {} + local after: { [string]: Seen } = {} + local waits = table.clone(settling:peek()) + local moved = false local ring: string? = nil for _, c in now.chats do local status = c.status or "" - after[c.id] = status local was = before[c.id] - if was ~= nil and was ~= status and SOUND[status] then - -- (One chime for many at once: the most urgent.) - local sound = SOUND[status] - if ring == nil or sound == "attention" or (sound == "request" and ring == "done") then - ring = sound + -- (A session row gone for a while, a host restarting, keeps the turn + -- last seen: its coming back is no finish.) + after[c.id] = { status = status, turn = c.turn or (was and was.turn) } + if busy(status) and waits[c.id] then + waits[c.id] = nil + moved = true + end + if was ~= nil then + if was.status ~= status and SOUND[status] then + ring = louder(ring, SOUND[status]) + end + if c.turn ~= nil and c.turn ~= was.turn and c.turn_fresh ~= false and not busy(status) then + waits[c.id] = { turn = c.turn, at = ui.now() + SETTLE } + moved = true end end end + -- (A chat gone takes its finish with it.) + for id in waits do + if after[id] == nil then + waits[id] = nil + moved = true + end + end seen:set(after) - if ring and prefs.chimes(ring) then - host.invoke("sound.play", ring) + if moved then + settling:set(waits) + end + play(ring) +end) + +-- The finishes due by `upto` have stood: they ring, once each moment (one +-- chime for many). (The timer that calls this is the deadline: its clock +-- needn't be `ui.now()`'s, so that's never asked again here.) +local function stand(upto: number) + local waits = settling:peek() + local left = {} + local ring: string? = nil + for id, w in waits do + if w.at <= upto then + local now = seen:peek()[id] + if now and now.turn == w.turn and not busy(now.status) then + ring = louder(ring, "done") + end + else + left[id] = w + end + end + settling:set(left) + play(ring) +end +ui.effect(function() + local soonest: number? = nil + for _, w in settling:get() do + soonest = if soonest then math.min(soonest, w.at) else w.at + end + -- (A timer made in an effect belongs to its run: a new finish, or one + -- taken, sets it again.) + if soonest then + local upto: number = soonest + ui.after(math.max(0, upto - ui.now()), function() + stand(upto) + end) end end) diff --git a/apps/zgx/ui/screens/settings/devices.luau b/apps/zgx/ui/screens/settings/devices.luau index 9a88ef06c..06637b28c 100644 --- a/apps/zgx/ui/screens/settings/devices.luau +++ b/apps/zgx/ui/screens/settings/devices.luau @@ -169,7 +169,9 @@ local icon_of = M.icon -- choosing one calls `choose` with its id. Built once: its options follow -- the devices as they come, go and are renamed, and the choice follows -- `shown`. -function M.picker(shown: () -> string?, choose: (id: string) -> ()): Node +-- (`extra`: more choices after the computers, each `{ value, label, icon }`: +-- Providers' Cloud, whose accounts every Cloud machine uses.) +function M.picker(shown: () -> string?, choose: (id: string) -> (), extra: (() -> { any })?): Node local function computers(): { sessions.Device } return sessions.computers(sessions.devices:get(), true) end @@ -181,9 +183,12 @@ function M.picker(shown: () -> string?, choose: (id: string) -> ()): Node end return "" end + local function extras(): { any } + return if extra then extra() else {} + end return ui.show( function(): boolean - return #computers() > 1 + return #computers() > 1 or #extras() > 0 end, ui.component(function(): Node local chosen = ui.use_state(shown() or here()) @@ -208,6 +213,9 @@ function M.picker(shown: () -> string?, choose: (id: string) -> ()): Node description = if not d.here and d.online == false then ui.t("settings.devices.offline") else nil, }) end + for _, e in extras() do + table.insert(options, e) + end return options end, on_change = choose, diff --git a/apps/zgx/ui/screens/settings/providers.luau b/apps/zgx/ui/screens/settings/providers.luau index 2876379aa..d1e13d9a3 100644 --- a/apps/zgx/ui/screens/settings/providers.luau +++ b/apps/zgx/ui/screens/settings/providers.luau @@ -23,6 +23,7 @@ local prefs = require("@app/screens/settings/prefs") local registry = require("@account/registry") local add_agent = require("@app/screens/settings/add_agent") local sign_in_terminal = require("@app/screens/settings/sign_in_terminal") +local cloud = require("@account/cloud") local M = {} @@ -108,6 +109,20 @@ local function here(): string? end return nil end +-- Cloud, as one choice after the computers (never its machines): the +-- accounts every Cloud machine uses, kept by the vault, which the engine +-- answers for (crates/engine cloud_accounts: Claude Code and Codex, their +-- logins and API keys). Offered while Cloud is on. +local CLOUD = "cloud" +local function on_cloud(): boolean + return now().target == CLOUD +end +local function cloud_choice(): { any } + if cloud.on() or on_cloud() then + return { { value = CLOUD, label = ui.t("settings.providers.cloud"):get(), icon = "cloud" } } + end + return {} +end -- The device shown: the engine's target, else this one. local function shown_device(): string? return now().target or here() @@ -115,6 +130,9 @@ end -- (In the locale shown: read where it's drawn.) local function device_name(): string local id = shown_device() + if id == CLOUD then + return ui.t("settings.providers.cloud"):get() + end for _, d in computers() do if d.id == id then return if d.here then ui.t("settings.providers.this_mac"):get() else d.name @@ -124,8 +142,11 @@ local function device_name(): string end local function choose_device(id: string) agents.target(if id == here() then nil else id) - -- (The registry as that device sees it: what it has added, its builds.) - registry.load() + -- (The registry as that device sees it: what it has added, its builds. + -- Cloud runs only Zeron's own.) + if id ~= CLOUD then + registry.load() + end end -- Which of the page's views shows: the agents, the registry ("add"), or @@ -152,7 +173,8 @@ local function kind(): string if s == "looking" or s == "unavailable" then return s end - return "found" + -- (Cloud's page is another: its accounts, its keys, nothing to add.) + return if now().target == "cloud" then "cloud" else "found" end -- Which agent's settings are open (none: ""). @@ -223,6 +245,9 @@ local function card(row: State): Node -- no accounts, and signs in its own way. (Its updates come as any -- agent's: the engine's update coordinator, the registry its feed.) local from_registry = (first :: any).registry == true + -- Cloud's (made for it: the cards are keyed by the device shown): on + -- every Cloud machine, its accounts alone managed here. + local cloud_card = on_cloud() -- The switch follows the engine; a flip goes to it, and its answer -- comes back in the row. local on = ui.use_state(first.enabled) @@ -234,7 +259,7 @@ local function card(row: State): Node if flipped ~= said then on:set(said) end - elseif flipped ~= said then + elseif flipped ~= said and not cloud_card then agents.set_enabled(id, flipped) end end) @@ -250,6 +275,7 @@ local function card(row: State): Node return (row:get() :: any).updating == true end, sign_in_only = from_registry, + fixed = cloud_card, login_note = function(): string? return (row:get() :: any).login_note end, @@ -329,7 +355,7 @@ local function card(row: State): Node end return nil end, - settings = true, + settings = not cloud_card, on_settings = function() load_subagents() open_settings:set(id) @@ -421,7 +447,13 @@ local function cards(): Node gap = "$space.4", ui.each(ui.computed(installed), function(_a: agents.Agent, _i: number, row: State): Node return card(row) - end, { key = by_id }), + end, { + -- (By the device shown too: a card is made for its device, + -- Cloud's unlike a computer's.) + key = function(a: agents.Agent): string + return `{now().target or ""}|{a.id}` + end, + }), } ) end @@ -490,6 +522,85 @@ local function more(): Node ) end +-- Cloud's API keys: Anthropic's for Claude Code, OpenAI's for Codex, kept +-- by the vault. A key saved becomes its agent's account in use, every Cloud +-- machine's from its next turn (as signing in does). +local CLOUD_KEYS = { + { provider = "anthropic-key", agent = "Claude Code", label = "settings.providers.cloud_keys.anthropic" }, + { provider = "openai-key", agent = "Codex", label = "settings.providers.cloud_keys.openai" }, +} +local function cloud_key_row(k: { provider: string, agent: string, label: string }): Node + return ui.component(function(): Node + local value = ui.use_state("") + local busy = ui.use_state(false) + local problem = ui.use_state("") + local function save() + local key = value:peek() + if busy:peek() or key == "" then + return + end + busy:set(true) + problem:set("") + host.call("agents.cloud_key", { provider = k.provider, key = key, device = cloud.device() or "" }):after(function() + busy:set(false) + value:set("") + toast.show { title = ui.t("settings.providers.cloud_keys.saved", { agent = k.agent }):get(), tone = "success" } + end, function(err: any) + busy:set(false) + problem:set(if type(err) == "table" and err.message then tostring(err.message) else tostring(err)) + end) + end + return ds.Settings.Row { + label = ui.t(k.label), + description = function(): string + local p = problem:get() + return if p ~= "" then p else ui.t("settings.providers.cloud_keys.description", { agent = k.agent }):get() + end, + control = ui.row { + gap = "$space.2", + items = "center", + ds.TextField { + value = value, + password = true, + w = 220, + size = "sm", + name = ui.t(k.label), + placeholder = ui.t("settings.providers.cloud_keys.placeholder"), + on_commit = function() + save() + end, + }, + ds.Button { + ui.t("settings.providers.cloud_keys.save"), + tone = "secondary", + size = "sm", + busy = function(): boolean + return busy:get() + end, + disabled = function(): boolean + return value:get() == "" + end, + on_click = save, + }, + }, + } + end)({}) +end +local function cloud_keys(): Node + return ds.Settings.Section { + title = ui.t("settings.providers.cloud_keys.title"), + description = ui.t("settings.providers.cloud_keys.section_description"), + ds.Settings.Group { + ui.column { + w_full = true, + cloud_key_row(CLOUD_KEYS[1]), + ds.Settings.Rule(), + cloud_key_row(CLOUD_KEYS[2]), + }, + }, + } +end + local function body(k: string): Node if k == "looking" then return ds.ProviderCard.Loading() @@ -498,6 +609,9 @@ local function body(k: string): Node return device_name() end, agents.load) end + if k == "cloud" then + return ui.column { w_full = true, gap = "$space.6", cards(), cloud_keys() } + end return ui.column { w_full = true, gap = "$space.6", cards(), more() } end @@ -767,7 +881,7 @@ local function agents_page(): Node -- Agents are per device: which one's (a choice once there's more -- than this one). -- (The same choice as Plugins': screens/settings/devices.) - trail = devices_page.picker(shown_device, choose_device), + trail = devices_page.picker(shown_device, choose_device, cloud_choice), -- (At the top right, on the title's line, as Plugins' is.) trail_top = true, ui.presence(kind, body, { w_full = true, enter = { opacity = { 0, 1 }, duration = 120 }, exit = { opacity = 0, duration = 60 }, mode = "wait" }), @@ -792,6 +906,10 @@ function M.view(): Node -- (Once a visit: a hot reload doesn't ask again.) The page opens on the -- agents; the registry is looked at too, for what it has to add. visits.once("providers", function() + -- (Whether Cloud is on, for its choice.) + if cloud.now:peek().phase == "unknown" then + cloud.load() + end agents.load() registry.load() if view:peek() ~= "agents" then diff --git a/apps/zgx/ui/settings_stub.luau b/apps/zgx/ui/settings_stub.luau index e68bd3ff8..3d0e4b6e7 100644 --- a/apps/zgx/ui/settings_stub.luau +++ b/apps/zgx/ui/settings_stub.luau @@ -432,6 +432,21 @@ end -- a switch of device shows whose. local agents = require("@account/agents") local function agents_of(target: string?): any + -- Cloud (the engine answers for it from the vault): Claude Code and + -- Codex, always installed; Codex with an account, so on. + if target == "cloud" then + local function one(id: string, name: string, mark: string, accounts: { any }): any + return { id = id, name = name, mark = mark, installed = true, can_install = false, enabled = #accounts > 0, version = nil, installing = false, login = "idle", accounts = accounts } + end + return { + state = "ready", + target = target, + list = { + one("claude-code", "Claude Code", "claude", {}), + one("codex", "Codex", "openai", { { id = "c1", email = "ada@example.com", plan = "Pro", session = 0.1, week = 0.2, active = true } }), + }, + } + end local name = if target then "Codex" else "Claude Code" local id = if target then "codex" else "claude-code" return { diff --git a/apps/zgx/ui/tests/browser_load_error.test.luau b/apps/zgx/ui/tests/browser_load_error.test.luau new file mode 100644 index 000000000..9933e9355 --- /dev/null +++ b/apps/zgx/ui/tests/browser_load_error.test.luau @@ -0,0 +1,175 @@ +-- The panel's browser tab when a load fails: a page that never came says +-- so over where it would be, with Try again and Dismiss (Escape too), the +-- page under it shown once dismissed, until the next navigation; a page +-- that came and drew (Google's "unusual traffic" check, a 429 WebView2 +-- calls a failed navigation) shows as it is, no failure over it. On the +-- panel in ui/panel_fixture.luau, its page stood in for. + +local FIELD = 'role:combobox "Address"' +local FAILED = '"Couldn\'t load this page"' +local DISMISS = 'role:button "Dismiss"' +local RETRY = 'role:button "Try again"' + +local function eventually(app: any, ok: () -> boolean, ms: number?): boolean + for _ = 1, math.ceil((ms or 5000) / 50) do + if ok() then + return true + end + app:wait('"never shown, only waited past"', { timeout_ms = 50 }) + end + return ok() +end + +local function panel(): any + local app = mount("panel_fixture.luau") + app:resize(900, 640) + app:frames(10) + expect(app:error()).to_be_nil() + expect(app:wait("#panel-empty", { timeout_ms = 15000 })).to_be(true) + app:click("#panel-open-browser") + expect(app:wait(FIELD, { timeout_ms = 15000 })).to_be(true) + return app +end + +local function calls(app: any): string + return app:state("test_web_calls") or "" +end + +-- To google.com/sorry, the page loaded (the field shows its address). +local URL = "https://www.google.com/sorry/index" +local function go(app: any): string + app:click("#outside") + app:frames(2) + app:type(FIELD, URL) + app:key("Enter") + app:frames(10) + expect(eventually(app, function(): boolean + return app:tree(FIELD):find(`="{string.sub(URL, 1, 36)}`, 1, true) ~= nil + end)).to_be(true) + app:frames(5) + return app:state("test_web_last_id") +end + +-- The page moving on, as the host tells it (`started`, `committed`). +local function navigate(app: any, kind: string) + app:set_state("test_web_nav_kind", kind) + app:command("test.web_navigate") + app:frames(5) +end + +-- The load failing, as the host has it: the error on the page's state. +local function fail(app: any, id: string, why: string) + app:set_state(`test_web_error_{id}`, why) + app:frames(10) +end + +-- The page under the overlay is the fixture's stand-in (`page `). +local function page_shown(app: any): boolean + return app:has("#stub-web") +end + +test("browser load error: a page that never came shows the failure, Try again and Dismiss", function() + local app = panel() + local id = go(app) + navigate(app, "started") + fail(app, id, "A server with the specified hostname could not be found.") + expect(app:wait(FAILED, { timeout_ms = 3000 })).to_be(true) + expect(app:has(RETRY)).to_be(true) + expect(app:has(DISMISS)).to_be(true) + expect(app:tree('role:checkbox "Annotate"')).to_contain("disabled") +end) + +test("browser load error: Dismiss hides the failure and the page stays", function() + local app = panel() + local id = go(app) + navigate(app, "started") + fail(app, id, "The page could not be loaded.") + expect(app:wait(FAILED, { timeout_ms = 3000 })).to_be(true) + app:click(DISMISS) + app:frames(10) + expect(app:has(FAILED)).to_be(false) + expect(app:has(RETRY)).to_be(false) + expect(page_shown(app)).to_be(true) + expect(app:has(`"page {URL}"`)).to_be(true) + -- Only this navigation's: the next one's failure shows again. + navigate(app, "started") + expect(app:wait(FAILED, { timeout_ms = 3000 })).to_be(true) +end) + +test("browser load error: Escape dismisses", function() + local app = panel() + local id = go(app) + navigate(app, "started") + fail(app, id, "The page could not be loaded.") + expect(app:wait(FAILED, { timeout_ms = 3000 })).to_be(true) + -- (From the address field, nothing typed in it to take back.) + app:click(FIELD) + app:frames(2) + app:key("Escape") + app:frames(10) + expect(app:has(FAILED)).to_be(false) + expect(page_shown(app)).to_be(true) +end) + +test("browser load error: Escape from the failure's own buttons dismisses", function() + local app = panel() + local id = go(app) + navigate(app, "started") + fail(app, id, "The page could not be loaded.") + expect(app:wait(FAILED, { timeout_ms = 3000 })).to_be(true) + -- (Tab from the field: past the bar's ⋯ to Try again.) + app:click(FIELD) + app:frames(2) + for _ = 1, 4 do + if app:tree(RETRY):find("focused", 1, true) then + break + end + app:key("Tab") + app:frames(2) + end + expect(app:tree(RETRY)).to_contain("focused") + app:key("Escape") + app:frames(10) + expect(app:has(FAILED)).to_be(false) + expect(page_shown(app)).to_be(true) + expect(calls(app)).never.to_contain("reload") +end) + +test("browser load error: Try again reloads the page", function() + local app = panel() + local id = go(app) + navigate(app, "started") + fail(app, id, "Could not connect to the server.") + expect(app:wait(FAILED, { timeout_ms = 3000 })).to_be(true) + app:click(RETRY) + app:frames(5) + expect(calls(app)).to_contain("reload") +end) + +test("browser load error: a page that came and drew, with an error status, shows no failure", function() + local app = panel() + local id = go(app) + -- WebView2: the server's own page (a 429) committed, then the + -- navigation reported failed, in the default words. + navigate(app, "started") + navigate(app, "committed") + fail(app, id, "The page could not be loaded.") + expect(app:has(FAILED)).to_be(false) + expect(app:has(RETRY)).to_be(false) + expect(page_shown(app)).to_be(true) + -- (And the page's controls are the page's: annotate isn't held off.) + expect(app:tree('role:checkbox "Annotate"')).never.to_contain("disabled") + -- A reload that never commits is a failure again. + navigate(app, "started") + expect(app:wait(FAILED, { timeout_ms = 3000 })).to_be(true) +end) + +test("browser load error: no network still says offline, with Dismiss", function() + local app = panel() + local id = go(app) + navigate(app, "started") + fail(app, id, "The internet connection appears to be offline.") + expect(app:wait("\"You're offline\"", { timeout_ms = 3000 })).to_be(true) + expect(app:has(RETRY)).to_be(true) + expect(app:has(DISMISS)).to_be(true) +end) diff --git a/apps/zgx/ui/tests/chat_draft_lift.test.luau b/apps/zgx/ui/tests/chat_draft_lift.test.luau new file mode 100644 index 000000000..1c17c1924 --- /dev/null +++ b/apps/zgx/ui/tests/chat_draft_lift.test.luau @@ -0,0 +1,60 @@ +-- A plugin allowed "draft" takes the composer's draft whole and puts it back +-- (`zeron.take_draft`, `put_draft`, `swap_draft`: screens/plugins keeps it +-- between, through screens/chat/shared's `lift` and `lay`). Taken, the +-- composer is clear; put back in another chat, its words and its chips are +-- as they were and go with the message; put back over words already there, +-- they follow those. + +local function open(app: any, chat: string) + app:command(`go_{chat}`) + app:frames(30) +end + +test("a draft taken in one chat is put back in another whole, chips and all", function() + local app = mount("chat_fixture.luau") + app:resize(900, 700) + open(app, "s2") + app:type('role:textbox "Message"', "Wrong chat prompt") + app:command("mention_s1") + app:frames(10) + app:command("draft_lift") + app:frames(10) + expect(app:state("test_lifted")).to_be("Wrong chat prompt|1") + -- Taken: nothing left on this chat's draft. + expect(app:has('#chat-composer >> role:button "Long chat"')).to_be(false) + expect(app:has('#chat-composer >> ~"Wrong chat prompt"')).to_be(false) + -- Put back in another chat, and sent from there. + open(app, "s3") + app:command("draft_lay") + app:frames(30) + expect(app:has('#chat-composer >> ~"Wrong chat prompt"')).to_be(true) + app:key("Enter") + app:frames(30) + expect(app:state("calls")).to_contain("send:s3:Wrong chat prompt\n\nChats attached:\n- [Long chat](zeron-chat:s1)") + expect(app:error()).to_be(nil) +end) + +test("an empty draft isn't taken", function() + local app = mount("chat_fixture.luau") + app:resize(900, 700) + open(app, "s2") + app:command("draft_lift") + app:frames(10) + expect(app:state("test_lifted")).to_be("nothing") +end) + +test("a draft put back over words already there follows them", function() + local app = mount("chat_fixture.luau") + app:resize(900, 700) + open(app, "s2") + app:type('role:textbox "Message"', "Second") + app:command("draft_lift") + app:frames(10) + app:type('role:textbox "Message"', "First") + app:command("draft_lay") + app:frames(30) + app:key("Enter") + app:frames(30) + expect(app:state("calls")).to_contain("send:s2:First\n\nSecond") + expect(app:error()).to_be(nil) +end) diff --git a/apps/zgx/ui/tests/chimes.test.luau b/apps/zgx/ui/tests/chimes.test.luau new file mode 100644 index 000000000..2b4716acb --- /dev/null +++ b/apps/zgx/ui/tests/chimes.test.luau @@ -0,0 +1,114 @@ +-- The session chimes (screens/settings/chimes, issue #1437): "done" rings +-- when a turn finishes (its `turn` mark moving and standing a moment), never +-- for a chat turning "done" alone, which is only activity you haven't seen +-- and your own send makes too. Questions and failures ring at once. + +local function chat(id: string, status: string?, turn: string?, fresh: boolean?): any + return { + id = id, + title = id, + device = "here", + status = status, + updated = 0, + created = 0, + turn = turn, + turn_fresh = if fresh == nil then true else fresh, + } +end + +local function publish(app: any, chats: { any }) + app:set_state("sessions", { + state = "ready", + devices = {}, + projects = {}, + chats = chats, + archived = {}, + places = { pinned = {}, sections = {} }, + places_ready = true, + }) + app:frames(2) +end + +local function played(app: any): { string } + local out = {} + for _, c in (app:state("settings_stub_calls") :: any) or {} do + local sound = string.match(c, "^sound%.play:(.+)$") + if sound then + table.insert(out, sound) + end + end + return out +end + +-- Long enough for a finish to stand (chimes' SETTLE, 2 s). +local function settle(app: any) + app:wait("#never-shown", { timeout_ms = 2400 }) + app:frames(3) +end + +local function open(chats: { any }): any + local app = mount("chimes_fixture.luau") + publish(app, chats) + return app +end + +test("chimes: your own send never rings done", function() + local app = open({ chat("a", nil, "t1") }) + -- The send lands: your message makes the chat unseen ("done") before the + -- live row says it's working; the turn mark hasn't moved. + publish(app, { chat("a", "done", "t1") }) + publish(app, { chat("a", "working", "t1") }) + -- A steer, or a queued message taken, as a turn ends: the end is + -- published with the next turn already running. + publish(app, { chat("a", "working", "t2") }) + -- A send that replaces the runtime: the old turn's end lands idle, then + -- your turn starts a moment later. + publish(app, { chat("a", "done", "t3") }) + publish(app, { chat("a", "working", "t3") }) + settle(app) + expect(#played(app)).to_be(0) + + -- The turn your message started finishing: that rings, once. + publish(app, { chat("a", "done", "t4") }) + expect(#played(app)).to_be(0) + settle(app) + expect(table.concat(played(app), ",")).to_be("done") + settle(app) + expect(#played(app)).to_be(1) +end) + +test("chimes: a chat's first turn finishing rings done", function() + local app = open({ chat("new", "working", nil) }) + publish(app, { chat("new", "done", "t1") }) + settle(app) + expect(table.concat(played(app), ",")).to_be("done") +end) + +test("chimes: an old row coming back, or a session row returning, never rings", function() + local app = open({ chat("a", nil, "t1") }) + -- A sync brings back an end published long ago. + publish(app, { chat("a", "done", "t2", false) }) + -- The row goes away (a host restarting) and comes back as it was. + publish(app, { chat("a", nil, nil) }) + publish(app, { chat("a", nil, "t2") }) + settle(app) + expect(#played(app)).to_be(0) +end) + +test("chimes: questions and failures ring at once", function() + local app = open({ chat("q", "working", "t1"), chat("f", "working", "t1") }) + publish(app, { chat("q", "input", "t1"), chat("f", "working", "t1") }) + expect(table.concat(played(app), ",")).to_be("request") + publish(app, { chat("q", "input", "t1"), chat("f", "failed", "t1") }) + expect(table.concat(played(app), ",")).to_be("request,attention") +end) + +test("chimes: Task completed off keeps done quiet, the rest still ring", function() + local app = open({ chat("a", "working", "t1") }) + app:set_state("settings_sound_done", false) + publish(app, { chat("a", "done", "t2") }) + settle(app) + expect(#played(app)).to_be(0) + publish(app, { chat("a", "input", "t2") }) + expect(table.concat(played(app), ",")).to_be("request") +end) diff --git a/apps/zgx/ui/tests/model_accounts.test.luau b/apps/zgx/ui/tests/model_accounts.test.luau index 3ea1abea1..a79be2447 100644 --- a/apps/zgx/ui/tests/model_accounts.test.luau +++ b/apps/zgx/ui/tests/model_accounts.test.luau @@ -91,6 +91,33 @@ test("a chat on another computer reads that computer's accounts", function() expect(app:state("calls")).to_contain("switch_on:box:claude-code:b2") end) +-- A chat on a Cloud machine: its accounts are Cloud's, the vault's (as +-- Settings → Providers shows them under Cloud), never the machine's own, +-- which isn't asked (it would be woken). +test("a chat on a Cloud machine reads and switches Cloud's accounts", function() + local app = with_accounts({ + [""] = { ["claude-code"] = accounts() }, + cloud = { + ["claude-code"] = { + { id = "v1", email = "team@example.test", plan = "Max", active = true, can_switch = true, windows = { window("Week", 0.4) } }, + { id = "v2", email = "spare@example.test", plan = "Pro", active = false, can_switch = true, windows = {} }, + }, + }, + }) + app:set_state("chat_device", "cloud-f60cde46") + app:frames(10) + expect(app:state("calls")).to_contain("watch_device:cloud") + expect(string.find(app:state("calls"), "watch_device:cloud-f60cde46", 1, true)).to_be(nil) + app:click('role:button "Model"') + app:frames(30) + expect(app:tree("#model-picker-account")).to_contain("team@example.test") + app:click("#model-picker-account") + app:frames(30) + app:click('~"spare@example.test"') + app:frames(30) + expect(app:state("calls")).to_contain("switch_on:cloud:claude-code:v2") +end) + test("a computer whose accounts haven't come has neither, and is asked", function() local app = with_accounts(here(accounts())) app:set_state("chat_device", "somewhere-else") diff --git a/apps/zgx/ui/tests/plugin_compose_replace.test.luau b/apps/zgx/ui/tests/plugin_compose_replace.test.luau new file mode 100644 index 000000000..e91e12e8a --- /dev/null +++ b/apps/zgx/ui/tests/plugin_compose_replace.test.luau @@ -0,0 +1,54 @@ +-- What a plugin allowed "compose" puts in a chat's draft +-- (`zeron.compose(text, opts)`, handed on by screens/plugins as the host +-- asks it): after what's there, or in place of its words with its chips +-- kept (`replace`), in the chat shown or another (`session`), never sent. +-- On the shell in ui/shell_fixture.luau, the host's asks made here. + +local seq = 0 +local function ask(app: any, value: any) + seq += 1 + app:set_state("plugins.request", { { seq = 1000 + seq, kind = "compose", title = "", value = value } }) + app:frames(10) +end + +local function open(): any + seq = 0 + local app = mount("shell_fixture.luau") + app:resize(1400, 800) + app:set_state("shell_fixture.plugins", true) + app:frames(30) + app:click('#shell-sidebar >> role:button "Fix the build"') + app:frames(30) + return app +end + +local BOX = "#chat-composer >> role:textbox" + +test("a plugin's words replace the draft's, or follow them on a line of their own", function() + local app = open() + app:type(BOX, "fix teh bulid pls") + app:frames(5) + ask(app, { text = "Please fix the build.", replace = true }) + expect(app:text(BOX)).to_be("Please fix the build.") + ask(app, { text = "It fails on main." }) + expect(app:text(BOX)).to_be("Please fix the build.\nIt fails on main.") + -- Words alone, as ever: after what's there. + ask(app, "Thanks.") + expect(app:text(BOX)).to_be("Please fix the build.\nIt fails on main.\nThanks.") + -- Nothing sent. + expect(app:state("calls")).never.to_contain("send:a1") +end) + +test("a plugin's words go in another chat's draft, which shows them when it's opened", function() + local app = open() + app:type(BOX, "here, untouched") + app:frames(5) + ask(app, { text = "for the docs", replace = true, session = "a2" }) + expect(app:text(BOX)).to_be("here, untouched") + app:click('#shell-sidebar >> role:button "Write the docs"') + app:frames(30) + expect(app:text(BOX)).to_be("for the docs") + app:click('#shell-sidebar >> role:button "Fix the build"') + app:frames(30) + expect(app:text(BOX)).to_be("here, untouched") +end) diff --git a/apps/zgx/ui/tests/plugin_draft_read.test.luau b/apps/zgx/ui/tests/plugin_draft_read.test.luau new file mode 100644 index 000000000..76e9bc044 --- /dev/null +++ b/apps/zgx/ui/tests/plugin_draft_read.test.luau @@ -0,0 +1,49 @@ +-- The composer's draft as plugins read it (`zeron.draft`, "draft"): written +-- only while a plugin that's on may read it, so with none no key typed +-- copies the draft for no one; with one, it follows what's typed, its chat +-- and its chips by kind and name. On the shell in ui/shell_fixture.luau. + +local function open(): any + local app = mount("shell_fixture.luau") + app:resize(1400, 800) + app:set_state("shell_fixture.plugins", true) + app:frames(30) + app:click('#shell-sidebar >> role:button "Fix the build"') + app:frames(30) + return app +end + +local function with_plugin(app: any, status: string) + app:set_state("plugins", { + state = "ready", + list = { { id = "stash", name = "Stash", status = status, permissions = { "ui.add", "draft" }, allowed = { "ui.add", "draft" } } }, + }) + app:frames(5) +end + +test("with no plugin that reads the draft, typing publishes nothing", function() + local app = open() + app:type("#chat-composer >> role:textbox", "a private thought") + app:frames(5) + expect(app:state("zeron.draft")).to_be_nil() + -- One that's off reads nothing either. + with_plugin(app, "off") + app:type("#chat-composer >> role:textbox", "still private") + app:frames(5) + expect(app:state("zeron.draft")).to_be_nil() +end) + +test("with a plugin on that reads the draft, it follows what's typed, and goes with the plugin", function() + local app = open() + with_plugin(app, "on") + app:type("#chat-composer >> role:textbox", "first words") + app:frames(5) + local d = app:state("zeron.draft") + expect(d).never.to_be_nil() + expect(d.text).to_be("first words") + expect(type(d.session)).to_be("string") + expect(#d.attachments).to_be(0) + -- Turned off: nothing kept out for it. + with_plugin(app, "off") + expect(app:state("zeron.draft")).to_be_nil() +end) diff --git a/apps/zgx/ui/tests/providers_cloud.test.luau b/apps/zgx/ui/tests/providers_cloud.test.luau new file mode 100644 index 000000000..b6b696335 --- /dev/null +++ b/apps/zgx/ui/tests/providers_cloud.test.luau @@ -0,0 +1,77 @@ +-- Settings → Providers offers Cloud as one more choice after the computers, +-- while Cloud is on: its agents' accounts (the vault's, every Cloud machine +-- uses them), with no switch, no settings and nothing to install, and API +-- keys to save for it. Without Cloud, no such choice. On the shell in +-- ui/shell_fixture.luau, Cloud from ui/cloud_stub.luau. + +local PAGE = "#settings-page" +local NAV = "#settings-nav" + +local function shows(app: any, scope: string, text: string): boolean + return app:tree(scope):find(text, 1, true) ~= nil +end + +local function asked(app: any, entry: string): boolean + for _, c in (app:state("settings_stub_calls") :: any) or {} do + if c == entry then + return true + end + end + return false +end + +local function open(with_cloud: boolean): any + local app = mount("shell_fixture.luau") + app:resize(1200, 900) + app:frames(30) + app:command("settings_stub.sign_in") + if with_cloud then + app:command("cloud_stub.offer") + end + app:command("shell.settings") + app:frames(20) + app:click(`{NAV} >> role:tab "Providers"`) + app:frames(30) + return app +end + +test("with Cloud on, Providers offers Cloud: its agents' accounts, no switch or settings, and its API keys", function() + local app = open(true) + app:click(`{PAGE} >> role:button "Device"`) + app:frames(10) + expect(app:has('role:menuitem "Cloud"')).to_be(true) + app:click('role:menuitem "Cloud"') + app:frames(30) + expect(asked(app, "agents.target:cloud")).to_be(true) + expect(shows(app, PAGE, "Claude Code")).to_be(true) + expect(shows(app, PAGE, "Codex")).to_be(true) + expect(shows(app, PAGE, "ada@example.com")).to_be(true) + -- Nothing to switch, set or install: its accounts alone. + expect(app:has(`{PAGE} >> role:switch "Codex on"`)).to_be(false) + expect(app:has(`{PAGE} >> role:button "Codex settings"`)).to_be(false) + expect(shows(app, PAGE, "Add another agent")).to_be(false) + -- Its API keys, saved for Cloud. + expect(shows(app, PAGE, "Anthropic API key")).to_be(true) + expect(shows(app, PAGE, "OpenAI API key")).to_be(true) + app:type(`{PAGE} >> role:textbox "OpenAI API key"`, "sk-test-123") + app:frames(5) + app:click(`{PAGE} >> role:button "Save" [2]`) + app:frames(10) + expect(asked(app, "agents.cloud_key")).to_be(true) + expect(app:error()).to_be_nil() + -- Back to this computer: its agents as they were, with their switches. + app:click(`{PAGE} >> role:button "Device"`) + app:frames(10) + app:click('role:menuitem "MacBook Pro"') + app:frames(30) + expect(asked(app, "agents.target:")).to_be(true) + expect(app:has(`{PAGE} >> role:switch "Claude Code on"`)).to_be(true) + expect(shows(app, PAGE, "Anthropic API key")).to_be(false) +end) + +test("without Cloud, Providers offers no Cloud", function() + local app = open(false) + app:click(`{PAGE} >> role:button "Device"`) + app:frames(10) + expect(app:has('role:menuitem "Cloud"')).to_be(false) +end) diff --git a/crates/engine/src/desktop_notify.rs b/crates/engine/src/desktop_notify.rs index c395531a0..e27315b91 100644 --- a/crates/engine/src/desktop_notify.rs +++ b/crates/engine/src/desktop_notify.rs @@ -31,6 +31,14 @@ use zeron_proto::{Chat, ConnectivityState, HarnessUpdatePhase, HarnessUpdateStat static ENABLED: AtomicBool = AtomicBool::new(false); +/// How long a finish waits to stand before it rings. The person's own +/// message often comes with one: a steer or a queued row taken as a turn +/// ends publishes that end with Working (their message carries the turn on), +/// and a send that replaces the runtime marks the old turn's end a moment +/// before the new one starts. Neither is "finished"; a turn that follows +/// within this window takes the finish with it. +const DONE_SETTLE: chrono::Duration = chrono::Duration::seconds(2); + /// This process shows desktop banners: engines assembled from now on post /// them (and advertise [`zeron_proto::capabilities::DESKTOP_NOTIFICATIONS_V1`]). pub fn enable() { @@ -222,7 +230,12 @@ impl Prefs { /// What a banner asked for by something other than a session (a plugin's, /// through `PostNotification`) came to: shown, or why not. -pub(crate) fn asked_outcome(prefs_enabled: bool, background_only: bool, focused: bool, desktop: bool) -> &'static str { +pub(crate) fn asked_outcome( + prefs_enabled: bool, + background_only: bool, + focused: bool, + desktop: bool, +) -> &'static str { if !desktop { "unavailable" } else if !prefs_enabled { @@ -237,7 +250,13 @@ pub(crate) fn asked_outcome(prefs_enabled: bool, background_only: bool, focused: /// A banner asked for (a plugin's): shown as the engine's own are, under /// the same Settings (`notificationsEnabled`, "only when in the /// background"), clicking it opening `target` (a session). What it came to. -pub(crate) fn post_asked(data_dir: &Path, focus: &ViewportFocus, title: &str, body: &str, target: Option<&str>) -> &'static str { +pub(crate) fn post_asked( + data_dir: &Path, + focus: &ViewportFocus, + title: &str, + body: &str, + target: Option<&str>, +) -> &'static str { let prefs = Prefs::read(data_dir); let outcome = asked_outcome(prefs.enabled, prefs.background_only, focus.any(), enabled()); if outcome == "posted" { @@ -261,7 +280,9 @@ pub(crate) fn post_for( std::sync::LazyLock::new(Default::default); let body: String = body.chars().take(500).collect(); let paced = { - let mut pace = PACE.lock().unwrap_or_else(std::sync::PoisonError::into_inner); + let mut pace = PACE + .lock() + .unwrap_or_else(std::sync::PoisonError::into_inner); !asked_in_time(pace.entry(source.to_owned()).or_default(), Instant::now()) }; if paced { @@ -273,11 +294,19 @@ pub(crate) fn post_for( /// Whether one more banner from a source may show, given when its last /// ones did: at most [`ASKED_PER_MINUTE`] a minute, [`ASKED_APART`] apart. -pub(crate) fn asked_in_time(history: &mut std::collections::VecDeque, now: Instant) -> bool { - while history.front().is_some_and(|at| now.duration_since(*at) >= Duration::from_secs(60)) { +pub(crate) fn asked_in_time( + history: &mut std::collections::VecDeque, + now: Instant, +) -> bool { + while history + .front() + .is_some_and(|at| now.duration_since(*at) >= Duration::from_secs(60)) + { history.pop_front(); } - let apart = history.back().is_none_or(|at| now.duration_since(*at) >= ASKED_APART); + let apart = history + .back() + .is_none_or(|at| now.duration_since(*at) >= ASKED_APART); if apart && history.len() < ASKED_PER_MINUTE { history.push_back(now); return true; @@ -316,6 +345,9 @@ struct Notifier { focus: ViewportFocus, post: Post, baselines: HashMap, + /// Finishes waiting to stand ([`DONE_SETTLE`]): chat → its title and + /// when it rings. + settling: HashMap)>, connectivity: ConnectivityNotificationState, updates_seen: HashSet, } @@ -328,6 +360,7 @@ impl Notifier { focus, post, baselines: HashMap::new(), + settling: HashMap::new(), connectivity: ConnectivityNotificationState::default(), updates_seen: HashSet::new(), } @@ -356,15 +389,56 @@ impl Notifier { if !chat.is_some_and(Chat::is_top_level) { continue; } + // A turn going on (or asking, or failing) takes a waiting + // finish with it. + if status.indicator != Indicator::None { + self.settling.remove(&session.chat_id); + } if let Some(prev) = prev && let Some(ping) = status.ping_since(&prev, false) { let title = chat .and_then(|chat| chat.title.clone()) .unwrap_or_else(|| "New session".into()); - due.push((title, ping, session.chat_id.clone())); + match ping { + // Published with the next turn already running: the + // person's message carried it on, nothing finished. + Ping::Done if status.indicator == Indicator::Working => {} + Ping::Done => { + self.settling + .insert(session.chat_id.clone(), (title, now + DONE_SETTLE)); + } + _ => due.push((title, ping, session.chat_id.clone())), + } } } + self.post_due(due); + } + + /// When the next waiting finish rings. + fn next_settled(&self) -> Option> { + self.settling.values().map(|(_, at)| *at).min() + } + + /// Ring the finishes that have stood for [`DONE_SETTLE`]. + fn flush(&mut self, now: chrono::DateTime) { + let stood: Vec = self + .settling + .iter() + .filter(|(_, (_, at))| *at <= now) + .map(|(chat, _)| chat.clone()) + .collect(); + let due = stood + .into_iter() + .filter_map(|chat| { + let (title, _) = self.settling.remove(&chat)?; + Some((title, Ping::Done, chat)) + }) + .collect(); + self.post_due(due); + } + + fn post_due(&mut self, due: Vec<(String, Ping, String)>) { if due.is_empty() || self.allowed().is_none() { return; } @@ -464,6 +538,7 @@ pub(crate) fn spawn(core: &crate::EngineCore, data_dir: PathBuf) -> tokio::task: let mut updates_due: Option = Some(tokio::time::Instant::now() + UPDATE_DEBOUNCE); loop { + let settles_at = notifier.next_settled(); tokio::select! { changed = sessions.changed() => { if changed.is_err() { break; } @@ -485,6 +560,17 @@ pub(crate) fn spawn(core: &crate::EngineCore, data_dir: PathBuf) -> tokio::task: updates.borrow_and_update(); updates_due.get_or_insert(tokio::time::Instant::now() + UPDATE_DEBOUNCE); } + _ = async { + match settles_at { + Some(at) => { + let wait = (at - chrono::Utc::now()).to_std().unwrap_or_default(); + tokio::time::sleep(wait).await; + } + None => std::future::pending().await, + } + } => { + notifier.flush(chrono::Utc::now()); + } _ = async { match updates_due { Some(at) => tokio::time::sleep_until(at).await, @@ -505,21 +591,38 @@ mod tests { #[test] fn a_plugin_s_banner_keeps_to_the_settings_and_its_pace() { assert_eq!(asked_outcome(true, false, true, true), "posted"); - assert_eq!(asked_outcome(true, true, true, true), "held", "only when in the background, and a window is in front"); + assert_eq!( + asked_outcome(true, true, true, true), + "held", + "only when in the background, and a window is in front" + ); assert_eq!(asked_outcome(true, true, false, true), "posted"); assert_eq!(asked_outcome(false, false, false, true), "off"); - assert_eq!(asked_outcome(true, false, false, false), "unavailable", "a server never shows banners"); + assert_eq!( + asked_outcome(true, false, false, false), + "unavailable", + "a server never shows banners" + ); let mut history = std::collections::VecDeque::new(); let t0 = Instant::now(); assert!(asked_in_time(&mut history, t0)); - assert!(!asked_in_time(&mut history, t0 + Duration::from_secs(1)), "too soon after the last"); + assert!( + !asked_in_time(&mut history, t0 + Duration::from_secs(1)), + "too soon after the last" + ); let mut at = t0; for _ in 1..ASKED_PER_MINUTE { at += ASKED_APART; assert!(asked_in_time(&mut history, at)); } - assert!(!asked_in_time(&mut history, at + ASKED_APART), "a minute's worth"); - assert!(asked_in_time(&mut history, t0 + Duration::from_secs(61)), "a minute on, one more"); + assert!( + !asked_in_time(&mut history, at + ASKED_APART), + "a minute's worth" + ); + assert!( + asked_in_time(&mut history, t0 + Duration::from_secs(61)), + "a minute on, one more" + ); } use super::*; @@ -782,6 +885,8 @@ mod tests { &chats, now, ); + // (Once it has settled: a finish waits a moment for a turn to follow.) + notifier.flush(now + DONE_SETTLE); assert_eq!( *posted.lock().unwrap(), vec![( @@ -793,6 +898,7 @@ mod tests { // A focused window holds it back (background-only is the default). focus.set("window", true); notifier.sessions(&[session("a", Some("t3"), now)], &chats, now); + notifier.flush(now + DONE_SETTLE); assert_eq!(posted.lock().unwrap().len(), 1); // Banners off: nothing, focused or not. focus.set("window", false); @@ -802,9 +908,68 @@ mod tests { ) .unwrap(); notifier.sessions(&[session("a", Some("t4"), now)], &chats, now); + notifier.flush(now + DONE_SETTLE); assert_eq!(posted.lock().unwrap().len(), 1); } + fn working(chat_id: &str, turn: Option<&str>, now: chrono::DateTime) -> Session { + let mut row = session(chat_id, turn, now); + row.status = zeron_proto::SessionStatus::Working; + row.started_at = Some(now); + row + } + + /// Your own message never rings "finished". These are the rows + /// crates/engine/src/sessions.rs publishes at such a send. + #[test] + fn a_send_steer_or_queued_send_never_rings_finished() { + let dir = tempfile::tempdir().unwrap(); + let (mut notifier, posted, _) = notifier(dir.path()); + let chats = [chat("a", "Fix the build", None)]; + let t0 = chrono::Utc::now(); + let at = |ms: i64| t0 + chrono::Duration::milliseconds(ms); + notifier.sessions(&[session("a", Some("t1"), at(0))], &chats, at(0)); + + // A plain send to an idle chat: Working, the marker as it was. + notifier.sessions(&[working("a", Some("t1"), at(10))], &chats, at(10)); + notifier.flush(at(10_000)); + // A steer (or a queued row taken) as the turn ends: the end is + // published with Working, the person's message carrying it on. + notifier.sessions(&[working("a", Some("t2"), at(20))], &chats, at(20)); + notifier.flush(at(10_000)); + // A send that replaces the runtime: the held end lands Idle, then + // the new turn starts a moment later. + notifier.sessions(&[session("a", Some("t3"), at(30))], &chats, at(30)); + notifier.sessions(&[working("a", Some("t3"), at(200))], &chats, at(200)); + notifier.flush(at(10_000)); + assert!( + posted.lock().unwrap().is_empty(), + "rang on a send: {:?}", + posted.lock().unwrap() + ); + + // The turn your message started finishing: that rings, once. + notifier.sessions(&[session("a", Some("t4"), at(20_000))], &chats, at(20_000)); + notifier.flush(at(30_000)); + notifier.flush(at(40_000)); + assert_eq!(posted.lock().unwrap().len(), 1); + } + + /// A question or a failure doesn't wait: it rings at once. + #[test] + fn a_question_or_failure_rings_at_once() { + let dir = tempfile::tempdir().unwrap(); + let (mut notifier, posted, _) = notifier(dir.path()); + let chats = [chat("a", "Fix the build", None)]; + let now = chrono::Utc::now(); + notifier.sessions(&[working("a", Some("t1"), now)], &chats, now); + let mut asking = working("a", Some("t1"), now); + asking.status = zeron_proto::SessionStatus::AwaitingInput; + notifier.sessions(&[asking], &chats, now); + assert_eq!(posted.lock().unwrap().len(), 1); + assert_eq!(posted.lock().unwrap()[0].1, "Waiting on your input"); + } + #[test] fn agent_updates_banner_once_per_release() { let dir = tempfile::tempdir().unwrap(); diff --git a/crates/engine/src/plugins/manifest.rs b/crates/engine/src/plugins/manifest.rs index 3a7f68195..5bfd31f57 100644 --- a/crates/engine/src/plugins/manifest.rs +++ b/crates/engine/src/plugins/manifest.rs @@ -28,6 +28,9 @@ pub const KNOWN_PERMISSIONS: &[&str] = &[ "notifications", "navigate", "compose", + // Reading the composer's draft, and taking it and putting it back + // (`zeron.draft`, `take_draft`, `put_draft`). + "draft", "network", "clipboard", "files", diff --git a/crates/mcp/src/tools/plugins.rs b/crates/mcp/src/tools/plugins.rs index 8bdc7d7fd..d8d585bd6 100644 --- a/crates/mcp/src/tools/plugins.rs +++ b/crates/mcp/src/tools/plugins.rs @@ -164,7 +164,7 @@ pub(super) fn catalog() -> Vec { vec![ ToolDef { name: CREATE_PLUGIN, - description: "Create a Zeron plugin on this device: a folder with a manifest (zeron-plugin.json), init.luau to edit, and zeron.luau, the SDK. Zeron signs it as yours and loads it, and re-signs and reloads it as you save; the person allows once, in Zeron, any permissions it asks for. `id` is lowercase letters, digits and dashes (2-40). `permissions` are what the plugin may do (ui.add, ui.change, ui.replace, profile.read, sessions.read, messages.read, account.email, files.read, panel.tabs, pages.add, github, github.write, navigate, compose, network, clipboard, files, web, windows, tools, devices, native, commands: with a manifest `commands` list of programs it runs, as you). The reply links the authoring guide (`guide`): read it before writing.", + description: "Create a Zeron plugin on this device: a folder with a manifest (zeron-plugin.json), init.luau to edit, and zeron.luau, the SDK. Zeron signs it as yours and loads it, and re-signs and reloads it as you save; the person allows once, in Zeron, any permissions it asks for. `id` is lowercase letters, digits and dashes (2-40). `permissions` are what the plugin may do (ui.add, ui.change, ui.replace, profile.read, sessions.read, messages.read, account.email, files.read, panel.tabs, pages.add, github, github.write, navigate, compose, draft, network, clipboard, files, web, windows, tools, devices, native, commands: with a manifest `commands` list of programs it runs, as you). The reply links the authoring guide (`guide`): read it before writing.", input_schema: json!({ "type": "object", "properties": { diff --git a/crates/update/src/lib.rs b/crates/update/src/lib.rs index d698dbe58..067653bbd 100644 --- a/crates/update/src/lib.rs +++ b/crates/update/src/lib.rs @@ -1248,10 +1248,11 @@ fn on_cloud() -> bool { on_cloud_platform(std::env::var("ZERON_DEVICE_PLATFORM").ok().as_deref()) } -/// Release files a Cloud machine never runs: the desktop app's background -/// engine (78 MB). A Cloud machine runs `zeron headless`, which links the -/// engine, and its disk is copied back in on every wake. -pub const CLOUD_UNUSED_FILES: &[&str] = &["zeron-engine"]; +/// Release files a Cloud machine never runs: none. (`zeron-engine` was here +/// until 2026-11-15, when `zeron headless` linked the engine. Since 0.3.0 the +/// release's `zeron` is the zgx app, whose `zeron headless` runs the +/// `zeron-engine` beside it: a machine without it never came online.) +pub const CLOUD_UNUSED_FILES: &[&str] = &[]; /// Remove [`CLOUD_UNUSED_FILES`] from the version folder `dir`. pub fn strip_cloud_unused(dir: &Path) { @@ -3692,9 +3693,11 @@ mod tests { assert_eq!(folders(&app_root), ["0.2.10", "0.2.11", "0.2.12", "current"]); } + /// `zeron headless` runs the `zeron-engine` beside it: a Cloud machine + /// keeps it in every version (it once left it out, and never came online). #[cfg(unix)] #[test] - fn a_cloud_machine_keeps_no_desktop_engine() { + fn a_cloud_machine_keeps_the_engine_its_headless_runs() { let tmp = tempfile::tempdir().unwrap(); let app_root = tmp.path().join("app"); versions_installed(&app_root, &["0.2.10", "0.2.11"]); @@ -3708,7 +3711,7 @@ mod tests { strip_unused_from_versions(&app_root); for ver in ["0.2.10", "0.2.11"] { - assert!(!app_root.join(ver).join("zeron-engine").exists(), "{ver}"); + assert!(app_root.join(ver).join("zeron-engine").exists(), "{ver}"); assert!(app_root.join(ver).join("zeron").exists(), "{ver}"); } assert!(app_root.join("notes").join("zeron-engine").exists()); @@ -4169,11 +4172,11 @@ mod tests { assert!(staged.join("zeron").is_file()); } - /// The release carries the desktop's background engine; a Cloud machine - /// stages the release without it, anywhere else keeps it. + /// The release carries `zeron-engine`, which `zeron headless` runs: a + /// Cloud machine stages it as anywhere else does. #[cfg(unix)] #[tokio::test] - async fn a_cloud_machine_stages_a_release_without_the_desktop_engine() { + async fn a_cloud_machine_stages_a_release_with_its_engine() { let tmp = tempfile::tempdir().unwrap(); let pkg = tmp.path().join("pkg"); std::fs::create_dir_all(pkg.join("zeron-pkg")).unwrap(); @@ -4190,7 +4193,7 @@ mod tests { .into(), ..Manifest::default() }; - for (cloud, kept) in [(true, false), (false, true)] { + for (cloud, kept) in [(true, true), (false, true)] { let app_root = tmp.path().join(format!("app-{cloud}")); std::fs::create_dir_all(&app_root).unwrap(); let (base, server) = serve_forever(bytes.clone()).await; diff --git a/crates/update/tests/update_transaction.rs b/crates/update/tests/update_transaction.rs index 3a50d6bb3..882ab5210 100644 --- a/crates/update/tests/update_transaction.rs +++ b/crates/update/tests/update_transaction.rs @@ -489,7 +489,7 @@ mod versioned { let mut rig = Rig::new("ok"); rig.platform = platform; rig.install_old(&["0.8.0", "0.9.0"]); - // The desktop's background engine, as the release ships it. + // The engine `zeron headless` runs, as the release ships it. for version in ["1.0.0", "2.0.0"] { std::fs::write(rig.app.join(version).join("zeron-engine"), "desktop").unwrap(); } @@ -497,12 +497,9 @@ mod versioned { rig.run_until_settled(); rig.assert_updated(&id); rig.app_settles_to(expected); - // A Cloud machine never runs it, and copies it back in on every wake. - assert_eq!( - rig.app.join("2.0.0/zeron-engine").exists(), - platform.is_none(), - "platform {platform:?}" - ); + // Kept everywhere, Cloud too: `zeron headless` runs it (a Cloud + // machine once left it out, and never came online). + assert!(rig.app.join("2.0.0/zeron-engine").exists(), "platform {platform:?}"); } } diff --git a/docs/design/cloud-device.md b/docs/design/cloud-device.md index df22d29af..994867f73 100644 --- a/docs/design/cloud-device.md +++ b/docs/design/cloud-device.md @@ -431,12 +431,12 @@ machine (`ZERON_DEVICE_PLATFORM=cloud`) keeps none of them: going back there is downloads anyway. Other Linux installs keep the newest older one, to go back to by hand. Never `current`, the running executable's folder, or a newer version (an update being staged). -A Cloud machine doesn't keep the release's `zeron-engine` either: it's the desktop app's background -engine (78 MB), and the unit runs `zeron headless`, which links the engine. The installer and the -updater leave it out, and the tidy and the pre-sleep cleanup remove it from versions installed before. -Measured on staging (send to first output, n=8 each), a machine on one version went from a median of -17.5 s to 14.2 s once neither it nor Codex's downloads came back with each wake; its wake downloaded -225 MB, 205 of them the engine it runs. +A Cloud machine keeps the release's `zeron-engine` (78 MB). From 2026-11-07 to 2026-11-15 the +installer, the updater and the tidy left it out, when the unit's `zeron headless` linked the engine; +since 0.3.0 the release's `zeron` is the zgx app, whose `zeron headless` runs that `zeron-engine`, so +a machine without it exited at once and never enrolled. The installer keeps it now, and a repair +(`~/.zeron/repair-engine`, the unit's `ExecStartPre=-`, set up by the installer and every wake) puts +it back before each start if an older updater left it out (edge/src/cloud/install-script.ts). A longer wake reads as updating: the engine says so (`POST /runner/wake-stage`), `CloudSession.stage` is `updating` while it lasts (a stage nobody clears stops showing after 10 minutes), the desktop's diff --git a/edge/src/cloud/install-script.ts b/edge/src/cloud/install-script.ts index eed6fe562..b6c96c15d 100644 --- a/edge/src/cloud/install-script.ts +++ b/edge/src/cloud/install-script.ts @@ -48,6 +48,60 @@ ExecStart=/bin/systemctl start --no-block ${CLOUD_UNIT_NAME} WantedBy=multi-user.target `; +/** + * Puts back the release's `zeron-engine` beside the `zeron` the unit runs, when + * it's missing. Since 0.3.0 the release's `zeron` is the zgx app, whose + * `zeron headless` hands off to that engine: without it the unit exits at + * once, restarts every second and never enrolls. Machines lost it to the + * installer, the engine's own updater and the pre-sleep tidy, which all left + * it out on Cloud (0.3.5's still do), so the unit runs this before every start + * (`ExecStartPre=-`: it never fails a start). Downloads only while it's + * missing, the version `current` names, from the edge's own releases. + */ +export const REPAIR_ENGINE_SCRIPT = `#!/bin/sh +# Zeron Cloud: put back a missing zeron-engine (edge/src/cloud/install-script.ts). +home="\${ZERON_CLOUD_HOME:-$HOME}" +cur="$home/.zeron/app/current" +[ -x "$cur/zeron" ] || exit 0 +[ -f "$cur/zeron-engine" ] && exit 0 +dest="$(readlink -f "$cur")" || exit 0 +ver="$(basename "$dest")" +case "$ver" in + "" | *[!A-Za-z0-9._+-]*) exit 0 ;; +esac +case "$(uname -m)" in + x86_64 | amd64) arch=x86_64 ;; + aarch64 | arm64) arch=aarch64 ;; + *) exit 0 ;; +esac +[ -n "\${ZERON_EDGE_URL:-}" ] || exit 0 +tmp="$(mktemp -d "$home/.zeron/.repair.XXXXXX")" || exit 0 +trap 'rm -rf "$tmp"' EXIT +curl -fsSL --retry 3 --connect-timeout 15 --speed-limit 1048576 --speed-time 15 \\ + -o "$tmp/zeron.tar.gz" "$ZERON_EDGE_URL/releases/zeron-$ver-linux-$arch.tar.gz" || exit 0 +tar -xzf "$tmp/zeron.tar.gz" -C "$tmp" "zeron-$ver-linux-$arch/zeron-engine" || exit 0 +chmod 755 "$tmp/zeron-$ver-linux-$arch/zeron-engine" +mv -f "$tmp/zeron-$ver-linux-$arch/zeron-engine" "$dest/zeron-engine" +echo "zeron cloud: put back zeron-engine for $ver" +`; + +/** + * Writes the repair script (`REPAIR_ENGINE_SCRIPT`) to `~/.zeron/repair-engine` + * and a drop-in running it before the engine's unit starts, each only when it + * differs, reloading systemd only then. Run by the installer and by every + * wake's first command, so machines set up before it get it as they wake. + * Best effort: a failure here never stops what follows. + * `ZERON_CLOUD_HOME` / `ZERON_CLOUD_UNIT_DIR` exist for the unit tier. + */ +export const ENSURE_REPAIR = + `{ h="\${ZERON_CLOUD_HOME:-$HOME}"; r="$h/.zeron/repair-engine"; ` + + `dd="\${ZERON_CLOUD_UNIT_DIR:-/etc/systemd/system}/${CLOUD_UNIT_NAME}.d"; ` + + `t="$(mktemp)" && printf %s '${btoa(REPAIR_ENGINE_SCRIPT)}' | base64 -d >"$t" && ` + + `{ cmp -s "$t" "$r" || install -m 0700 "$t" "$r"; } && ` + + `printf '[Service]\\nExecStartPre=-%s\\n' "$r" >"$t" && ` + + `{ cmp -s "$t" "$dd/repair-engine.conf" || { sudo mkdir -p "$dd" && sudo install -m 0644 "$t" "$dd/repair-engine.conf" && sudo systemctl daemon-reload; }; }; ` + + `rm -f "$t"; } >/dev/null 2>&1 || true`; + export const CLOUD_INSTALL_SCRIPT = `#!/bin/sh # Zeron Cloud engine installer (edge/src/cloud/install-script.ts). # POSIX sh, idempotent, provider-neutral. @@ -85,7 +139,9 @@ esac restart=0 dest="$app/$ver" -if [ -x "$dest/zeron" ]; then +# (Whole, its zeron-engine too: \`zeron headless\` runs it, and installs +# made before 2026-11-15 left it out.) +if [ -x "$dest/zeron" ] && [ -f "$dest/zeron-engine" ]; then echo "zeron $ver already installed" else tmp="$(mktemp -d "$data/.download.XXXXXX")" @@ -99,10 +155,8 @@ else tar -xzf "$tmp/zeron.tar.gz" -C "$tmp/unpacked" --strip-components=1 # Probe before switching: a binary that cannot start must not replace one that can. "$tmp/unpacked/zeron" --version >/dev/null - # The desktop app's background engine (78 MB): never run here (the unit runs - # \`zeron headless\`, which links the engine), and every byte on this disk is - # copied back in on every wake. The engine's updater leaves it out too. - rm -f "$tmp/unpacked/zeron-engine" + # (zeron-engine stays: \`zeron headless\` runs it. Without it the unit + # exits at once and the machine never enrolls.) rm -rf "$dest" mv "$tmp/unpacked" "$dest" fi @@ -172,6 +226,8 @@ else rm -f "$boot_new" fi +# A zeron-engine an update leaves out is put back before each start. +${ENSURE_REPAIR} sudo systemctl daemon-reload sudo systemctl enable ${CLOUD_UNIT_NAME} ${CLOUD_BOOT_UNIT_NAME} >/dev/null sudo systemctl start ${CLOUD_BOOT_UNIT_NAME} @@ -253,6 +309,9 @@ export const RESTART_ENGINE_COMMAND = `sudo systemctl restart ${CLOUD_UNIT_NAME} * systemd hasn't read yet gets one reload. `--no-block` answers at once (the * engine's first token says it's up). Idempotent: a no-op when it's running. */ export const START_ENGINE_COMMAND = + // (First, the repair of a missing zeron-engine before each start, for + // machines set up before it: a no-op once it's there.) + `${ENSURE_REPAIR}; ` + `sudo systemctl start --no-block ${CLOUD_UNIT_NAME} || ` + `{ sudo systemctl daemon-reload; sudo systemctl start --no-block ${CLOUD_UNIT_NAME}; }`; diff --git a/edge/test/unit/install-script.test.ts b/edge/test/unit/install-script.test.ts index b96da8ce3..a4b8420ec 100644 --- a/edge/test/unit/install-script.test.ts +++ b/edge/test/unit/install-script.test.ts @@ -13,6 +13,7 @@ import { afterEach, beforeEach, describe, expect, it } from "vitest"; import { CLOUD_BOOT_UNIT, CLOUD_INSTALL_SCRIPT, + REPAIR_ENGINE_SCRIPT, START_ENGINE_COMMAND, STOP_ENGINE_COMMAND, installCommand, @@ -110,8 +111,15 @@ describe("cloud install script", { timeout: 60_000 }, () => { const data = join(home, ".zeron"); expect(readlinkSync(join(data, "app", "current"))).toBe(join(data, "app", "1.2.3")); expect(existsSync(join(data, "app", "1.2.3", "zeron"))).toBe(true); - // Never run on Cloud, and copied back in on every wake if kept. - expect(existsSync(join(data, "app", "1.2.3", "zeron-engine"))).toBe(false); + // Kept: `zeron headless` runs it (without it the unit exits at once and + // the machine never enrolls). + expect(existsSync(join(data, "app", "1.2.3", "zeron-engine"))).toBe(true); + // And put back before each start, should an update leave it out. + expect(statSync(join(data, "repair-engine")).mode & 0o777).toBe(0o700); + expect(readFileSync(join(data, "repair-engine"), "utf8")).toBe(REPAIR_ENGINE_SCRIPT); + expect(readFileSync(join(units, "zeron-cloud.service.d", "repair-engine.conf"), "utf8")).toBe( + `[Service]\nExecStartPre=-${join(data, "repair-engine")}\n` + ); const envFile = join(data, "env"); expect(statSync(envFile).mode & 0o777).toBe(0o600); expect(readFileSync(envFile, "utf8")).toBe( @@ -159,6 +167,45 @@ describe("cloud install script", { timeout: 60_000 }, () => { expect(calls()).toContain("systemctl restart zeron-cloud.service"); }); + it("downloads again a version installed without its zeron-engine", () => { + const { home, run, calls, clearCalls } = setup(); + run("org.user.cloud-1.codeA"); + const engine = join(home, ".zeron", "app", "1.2.3", "zeron-engine"); + rmSync(engine); + clearCalls(); + run("org.user.cloud-1.codeA"); + expect(existsSync(engine)).toBe(true); + expect(calls().filter((c) => c.includes(".tar.gz"))).toHaveLength(1); + }); + + it("puts back a zeron-engine an update left out, and does nothing once it's there", () => { + const { home, run, calls, clearCalls } = setup(); + run("org.user.cloud-1.codeA"); + const data = join(home, ".zeron"); + const engine = join(data, "app", "1.2.3", "zeron-engine"); + const repair = () => + execFileSync("sh", [join(data, "repair-engine")], { + env: { PATH: `${join(root, "bin")}:/usr/bin:/bin`, ZERON_CLOUD_HOME: home, ZERON_EDGE_URL: "https://edge.test" }, + encoding: "utf8" + }); + rmSync(engine); + clearCalls(); + expect(repair()).toContain("put back zeron-engine for 1.2.3"); + expect(existsSync(engine)).toBe(true); + expect(statSync(engine).mode & 0o111).not.toBe(0); + expect(calls().filter((c) => c.includes("/releases/zeron-1.2.3-linux-x86_64.tar.gz"))).toHaveLength(1); + // There: no download. + clearCalls(); + repair(); + expect(calls().filter((c) => c.startsWith("curl"))).toHaveLength(0); + // A download that fails leaves the start to go on (it never fails it). + rmSync(engine); + writeFileSync(join(root, "bin", "curl"), "#!/bin/sh\nexit 22\n"); + chmodSync(join(root, "bin", "curl"), 0o755); + expect(() => repair()).not.toThrow(); + expect(existsSync(engine)).toBe(false); + }); + it("doesn't wait for the network to start the engine, and starts it on boot without being asked", () => { const { units, run } = setup(); run("org.user.cloud-1.codeA"); @@ -237,9 +284,19 @@ describe("cloud install script", { timeout: 60_000 }, () => { }); it("starts the engine without waiting on it, and reloads once for a unit systemd hasn't read", () => { - const { calls, clearCalls } = setup(); + const { home, units, calls, clearCalls } = setup(); + mkdirSync(join(home, ".zeron"), { recursive: true }); const start = () => - execFileSync("sh", ["-c", START_ENGINE_COMMAND], { env: { PATH: `${join(root, "bin")}:/usr/bin:/bin` }, encoding: "utf8" }); + execFileSync("sh", ["-c", START_ENGINE_COMMAND], { + env: { PATH: `${join(root, "bin")}:/usr/bin:/bin`, ZERON_CLOUD_HOME: home, ZERON_CLOUD_UNIT_DIR: units }, + encoding: "utf8" + }); + // A machine set up before the repair: its first wake writes it, once. + clearCalls(); + start(); + expect(calls()).toEqual(["systemctl daemon-reload", "systemctl start --no-block zeron-cloud.service"]); + expect(readFileSync(join(home, ".zeron", "repair-engine"), "utf8")).toBe(REPAIR_ENGINE_SCRIPT); + expect(readFileSync(join(units, "zeron-cloud.service.d", "repair-engine.conf"), "utf8")).toContain("ExecStartPre=-"); clearCalls(); start(); expect(calls()).toEqual(["systemctl start --no-block zeron-cloud.service"]);