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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,14 @@ Works:
config.json sets `remToPxRate` (16), `workHoursPerDay` (8) and `clockFormat` (`auto` follows the Qt locale, or `12h` / `24h`).

↵ copies the answer (HUD), Ctrl+↵ pastes it through `omarchy-clipboard-paste-text`, Ctrl+Shift+C copies "question = answer". Each one saves to **Calculator History** (`db/calculator.json`, 4096 rows / 90 days): a built-in command and pushed view, searchable, Ctrl+D deletes an entry, Ctrl+Shift+D deletes all. RPC: `calculator.calculate|historyGetAll|historyDelete|historyDeleteAll|refreshCurrencies|getCurrencies`. A bare number, word or quantity (`42`, `firefox`, `5 kg`) never produces a row, because the section takes ↵.
- **Script Commands** (SPEC §9.9, ref 03 §5): `core/ScriptCommands.js` (header parsing, arguments, output handling) and `services/ScriptCommandsSource.qml` (scan, runs, inline refresh).
- Folders: `~/.config/oma-cast/script-commands` plus config.json `scriptCommandDirectories` (absolute or `~/`). A bash scan skips dirs, non-executables, empty files, `.template.` files, files over 2 MB and files with no `@raycast.` line. It runs on every open and on Reload Script Commands. Files whose header is broken are listed under "Invalid Scripts" in Search Script Commands.
- Scripts run as `bash -lc 'cd <cwd>; exec <script> $1..$3'` (login env, LC_ALL unset). Modes: compact (running toast with Cancel on Ctrl+T, then the last line), silent (HUD), fullOutput (the `script-output` view streams ANSI-stripped output, ↵ copies, Ctrl+R runs again, leaving the view stops the script [I]) and inline (subtitle = first line, refreshed on `refreshTime` ≥ 10 s, 30 s timeout [D]).
- Arguments are pills; dropdowns step with ↑/↓ and start on their first option; passwords show as dots. `needsConfirmation` uses the alert.
- Built-ins: Search / Create (title + mode pills, writes a template, opens `omarchy-launch-editor`) / Reload Script Commands. RPC: `scriptCommands.getScripts|reload|runScript|cancelScript|getRun`.
- Not done: ANSI colours in the output view, icon URLs (not fetched [D]), `iconDark`, a settings page for the folders.
- **Latency:** show → mapped in 59–66 ms, hide in 24–42 ms on Omarchy 4.0.6 (`tests/smoke.sh`; it was 37–44 ms on the old `OverlayWindow`).
- **Tests:** root search, calculator and default-agent hand-off coverage (`node --test tests/*.test.js`).
- **Tests:** root search, calculator, script commands and default-agent hand-off coverage (`node --test tests/*.test.js`).

**Default-agent hand-off (fork, 2026-10-20):** user-authorized addition outside the original phase plan. The root fallback "Ask default agent" and Ctrl+Alt+Enter pass the query to `omarchy-agent --prompt` as a literal argv element. `AgentLauncher.qml` checks the configured agent/terminal with a bounded, question-free preflight, prevents overlapping submissions and cancels on hide/unload. `Launcher.qml` dismisses the overlay before launching through `Util.execArgv`. Errors leave the query visible. There are no new dependencies, model APIs, credentials or question-history writes. Existing CLI approval behaviour is inherited. Portable checks do not establish live terminal focus, authentication, or provider compatibility; verify those on Omarchy.

Expand Down
35 changes: 34 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,39 @@ read credentials, or make model API calls. Successful preflight checks establish
launch prerequisites, not successful sign-in or a running terminal; those still
need live desktop validation.

## Script Commands

Put an executable script with Raycast's `@raycast.*` header comments in
`~/.config/oma-cast/script-commands`, and it shows up in root search:

```bash
#!/bin/bash
# @raycast.schemaVersion 1
# @raycast.title Restart Waybar
# @raycast.mode compact
# @raycast.argument1 { "type": "text", "placeholder": "Profile", "optional": true }
```

Scripts from the [`raycast/script-commands`](https://github.com/raycast/script-commands)
repo use the same format, but many of them call macOS-only tools.

- **Modes:** `compact` shows the last line of output in a toast, `silent`
closes the launcher and shows it in the OSD, `fullOutput` opens a view that
streams the output, and `inline` shows the first line as the row's subtitle,
refreshed every `refreshTime` (10 s or more).
- **Arguments:** up to three (`text`, `password` or `dropdown`), typed in pills
after the search text. Tab moves between them and ↑/↓ steps through a
dropdown's options.
- **Commands:** *Search Script Commands* lists your scripts by package, plus any
files with a broken header. *Create Script Command* writes a script from a
template and opens it in your editor. *Reload Script Commands* rescans the
folders (oma-cast also rescans every time it opens).
- **Actions:** Edit Script (`Ctrl+E`) and Copy Path (`Ctrl+Shift+C`). In the
output view, ↵ copies the output and `Ctrl+R` runs the script again.

To scan more folders, add them to `~/.config/oma-cast/config.json`:
`"scriptCommandDirectories": ["~/bin/raycast"]`.

## Keyboard

| Key | Does |
Expand Down Expand Up @@ -114,7 +147,7 @@ oma-cast doctor
oma-cast is early. Search, ranking and the Omarchy integration are done. Coming next:

- [ ] Settings window
- [ ] Script Commands
- [x] Script Commands
- [ ] Clipboard history, snippets, quicklinks, calculator
- [ ] Running Raycast extensions built from the open-source [`raycast/extensions`](https://github.com/raycast/extensions) repo
- [ ] Window management
Expand Down
156 changes: 155 additions & 1 deletion plugin/Backend.qml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import "core/OmarchyMenu.js" as OmarchyMenu
import "core/RootSearch.js" as RootSearch
import "core/Agent.js" as Agent
import "core/Calculator.js" as Calculator
import "core/ScriptCommands.js" as ScriptCommands
import "services"

Item {
Expand All @@ -35,7 +36,7 @@ Item {
property var candidates: []
property var candidatesById: ({})
property int candidatesRevision: 0
readonly property bool loading: menuSource.loading || agentLauncher.checking
readonly property bool loading: menuSource.loading || agentLauncher.checking || scriptSource.foregroundRuns > 0
// Bumped when exchange rates or zone offsets arrive, so an open
// calculator row re-evaluates.
readonly property int calculatorRevision: (calculatorData.rates ? 1 : 0) + calculatorData.ratesFetchedAt + calculatorData.zonesAt
Expand Down Expand Up @@ -76,6 +77,10 @@ Item {
for (var i = 0; i < apps.length; i++) if (apps[i] && apps[i].id) next.push(RootSearch.appCandidate(apps[i]))
next = next.concat(RootSearch.menuCandidates(menuSource.tree, menuSource.guards, menuSource.providerItems, backend.deps))
for (var b = 0; b < RootSearch.BUILTINS.length; b++) next.push(RootSearch.builtinCandidate(RootSearch.BUILTINS[b]))
for (var s = 0; s < scriptSource.scripts.length; s++) {
var script = scriptSource.scripts[s]
next.push(ScriptCommands.candidate(script, scriptSource.inline[script.id] || null))
}
var byId = ({})
for (var j = 0; j < next.length; j++) byId[next[j].id] = next[j]
backend.candidates = next
Expand Down Expand Up @@ -179,6 +184,83 @@ Item {
return null
}

// ------------------------------------------------------- script commands

function scriptFor(id) {
var script = scriptSource.byId[id]
if (!script) throw new Error("Script not found. Reload Script Commands and try again.")
return script
}

// ↵ on a script: validate its arguments, confirm if it asks to, then run
// it in its mode (SPEC §9.9).
function runScript(candidate, data) {
var script = backend.scriptFor(candidate.id)
var args = ScriptCommands.argumentValues(script.arguments, (data && data.arguments) || {})
if (script.needsConfirmation && !(data && data.confirmed))
return { confirm: { title: script.title, message: "Are you sure you want to run this script?", primary: "Run Script", destructive: false } }
backend.recordVisit(candidate.id, String(data && data.query || "").trim())
var runId = scriptSource.start(script, args, script.mode)
if (script.mode === "fullOutput") return { push: { kind: "script-output", runId: runId, title: script.title } }
if (script.mode === "silent") return { close: true }
return { toast: { style: "running", title: (script.mode === "inline" ? "Refreshing " : "Running ") + script.title + "…", actions: [
{ id: "cancel", title: "Cancel", done: "Cancelled", call: { method: "scriptCommands.cancelScript", data: { runId: runId } } }
] } }
}

function scriptRunAction(rowId, action) {
var runId = String(rowId).slice("script-run:".length)
var run = scriptSource.run(runId)
if (!run) throw new Error("That run is gone")
switch (action) {
case "open":
case "copy-output":
Util.execArgv(["wl-copy", "--", ScriptCommands.stripAnsi(run.output)])
return { close: true, hud: "Copied to Clipboard" }
case "run-again":
var script = backend.scriptFor(run.scriptId)
scriptSource.cancel(runId)
var next = scriptSource.start(script, run.args, run.mode)
return { replace: { kind: "script-output", runId: next, title: script.title } }
case "stop-script":
scriptSource.cancel(runId)
return { toast: { style: "success", title: "Stopped " + run.title } }
case "edit-script":
Util.execArgv(["omarchy-launch-editor", run.path])
return { close: true }
}
throw new Error("Unknown action " + action)
}

function scriptErrorFor(rowId) {
var found = scriptSource.errors.filter(function(e) { return e.id === rowId })[0]
if (!found) throw new Error("Script not found. Reload Script Commands and try again.")
return ScriptCommands.errorCandidate(found)
}

function scriptFileAction(path, action) {
if (action === "edit-script" || action === "open") {
Util.execArgv(["omarchy-launch-editor", path])
return { close: true }
}
if (action === "copy-path") {
Util.execArgv(["wl-copy", "--", path])
return { close: true, hud: "Copied to Clipboard" }
}
throw new Error("Unknown action " + action)
}

function runInfo(runId) {
var run = scriptSource.run(runId)
if (!run) return null
var status = run.running ? "Running…"
: run.cancelled ? "Stopped"
: run.crashed ? "Stopped by a signal"
: run.exitCode === 0 ? "Finished" : "Failed with exit code " + run.exitCode
return { runId: run.id, title: run.title, running: run.running, exitCode: run.exitCode, status: status,
output: (run.truncated ? "…\n" : "") + ScriptCommands.stripAnsi(run.output) }
}

// ------------------------------------------------------------- execution

function summonPlugin(id, payload) {
Expand Down Expand Up @@ -247,7 +329,23 @@ Item {
var target = menuSource.tree.items[candidate.target]
if (!target) return { toast: { style: "failure", title: "Menu " + candidate.target + " not found" } }
return { push: { kind: "menu", menuId: target.id, title: target.label } }
case "script":
return backend.runScript(candidate, data)
case "builtin":
if (candidate.run.createScript) {
var spec = (data && data.arguments) || {}
var missingArg = RootSearch.missingArgument(candidate.arguments, spec)
if (missingArg >= 0) throw new Error("Type a " + candidate.arguments[missingArg].placeholder.toLowerCase() + " first")
var mode = ScriptCommands.optionValue(candidate.arguments[1], spec.mode)
backend.recordVisit(id, query)
scriptSource.create(backend.paths.scriptCommands, String(spec.title), mode)
return {}
}
if (candidate.run.reloadScripts) {
backend.recordVisit(id, query)
scriptSource.scan(true)
return {}
}
if (candidate.run.url) {
var values = (data && data.arguments) || {}
var missing = RootSearch.missingArgument(candidate.arguments, values)
Expand All @@ -267,6 +365,9 @@ Item {
throw new Error("Cannot open " + id)
}

if (candidate.kind === "script" && (action === "edit-script" || action === "copy-path"))
return backend.scriptFileAction(candidate.scriptPath, action)

switch (action) {
case "open-in-omarchy-menu":
backend.summonPlugin("omarchy.menu", JSON.stringify({ menu: backend.omarchyRouteFor(candidate) }))
Expand Down Expand Up @@ -389,6 +490,8 @@ Item {
var sections
if (view && view.kind === "menu") sections = RootSearch.submenuSections(backend.candidates, view.menuId, query, ctx, backend.deps)
else if (view && view.kind === "calculator-history") sections = RootSearch.historySections(calculatorStore.doc.history, query, ctx.nowMs, Calculator.filterHistory)
else if (view && view.kind === "script-commands") sections = RootSearch.scriptSections(backend.candidates, scriptSource.errors.map(ScriptCommands.errorCandidate), query, ctx, backend.deps)
else if (view && view.kind === "script-output") sections = []
else {
ctx.filter = String(data && data.filter || "all")
if (query.trim() && ctx.filter === "all") ctx.calculation = backend.calculate(query)
Expand All @@ -402,6 +505,11 @@ Item {
var rowId = String(data && data.id || "")
if (rowId === RootSearch.CALCULATOR_ID) return RootSearch.actionsFor({ kind: "calculator" })
if (rowId.indexOf("calculator-history:") === 0) return RootSearch.actionsFor({ kind: "calculator-history" })
if (rowId.indexOf("script-run:") === 0) {
var run = scriptSource.run(rowId.slice("script-run:".length))
return RootSearch.actionsFor({ kind: "script-run", running: !!(run && run.running) })
}
if (rowId.indexOf(ScriptCommands.ERROR_PREFIX) === 0) return RootSearch.actionsFor({ kind: "script-error" })
var candidate = backend.decorated(rowId)
if (!candidate) {
var fallback = RootSearch.FALLBACKS.filter(function(f) { return f.id === data.id })[0]
Expand All @@ -421,6 +529,8 @@ Item {
var entry = backend.historyEntry(rowId)
return entry ? RootSearch.aboutFor(RootSearch.historyCandidate(entry, nowMs), nowMs) : []
}
if (rowId.indexOf(ScriptCommands.ERROR_PREFIX) === 0) return RootSearch.aboutFor(backend.scriptErrorFor(rowId), nowMs)
if (rowId.indexOf("script-run:") === 0) return []
var candidate = backend.decorated(rowId)
if (!candidate) {
var f = RootSearch.FALLBACKS.filter(function(x) { return x.id === rowId })[0]
Expand Down Expand Up @@ -455,6 +565,9 @@ Item {
if (!entry) throw new Error("No such history entry")
return backend.calculatorAction(String(data.action || "open"), entry, entry.id)
}
if (data && String(data.id).indexOf("script-run:") === 0) return backend.scriptRunAction(data.id, String(data.action || "open"))
if (data && String(data.id).indexOf(ScriptCommands.ERROR_PREFIX) === 0)
return backend.scriptFileAction(backend.scriptErrorFor(data.id).scriptPath, String(data.action || "open"))
return backend.performAction(data)
},
getSearchHistory: function() { return frecencyStore.loaded ? frecencyStore.doc.searchHistory : [] }
Expand Down Expand Up @@ -484,6 +597,32 @@ Item {
}
})

// Names from Raycast's scriptCommands namespace (ref 02 §2).
Rpc.register(backend.registry, "scriptCommands", {
getScripts: function() {
return {
directories: scriptSource.directories,
scripts: scriptSource.scripts.map(function(s) {
return { id: s.id, title: s.title, mode: s.mode, path: s.path, packageName: s.packageName, inline: scriptSource.inline[s.id] || null }
}),
errors: scriptSource.errors
}
},
reload: function() { scriptSource.scan(true); return null },
runScript: function(data) {
return backend.performAction({ id: String(data && data.id || ""), action: "open", arguments: (data && data.arguments) || {}, confirmed: true })
},
cancelScript: function(data) {
if (!scriptSource.cancel(String(data && data.runId || ""))) throw new Error("That script is not running")
return null
},
getRun: function(data) {
var info = backend.runInfo(String(data && data.runId || ""))
if (!info) throw new Error("That run is gone")
return info
}
})

Rpc.register(backend.registry, "frecency", {
visit: function(data) { backend.recordVisit(String(data.id), String(data.query || "")); return null },
get: function(data) {
Expand Down Expand Up @@ -517,6 +656,7 @@ Item {
if (method === "window.visibilityChanged" && data && data.visible) {
menuSource.refresh()
calculatorData.refresh()
scriptSource.scan(false)
}
if (method === "window.visibilityChanged" && data && !data.visible) agentLauncher.cancel()
}
Expand All @@ -537,6 +677,20 @@ Item {
}
}

ScriptCommandsSource {
id: scriptSource
directories: backend.directoriesReady ? ScriptCommands.directories(backend.paths.scriptCommands, backend.config.scriptCommandDirectories, backend.paths.home) : []
onRevisionChanged: rebuildTimer.restart()
onMessage: function(level, text, metadata) { backend.log(level, "script-commands", text, metadata) }
onReloaded: function(count, errorCount) { backend.emit("scriptCommands.reloaded", { count: count, errors: errorCount }) }
onRunOutput: function(runId) { backend.emit("scriptCommands.output", { runId: runId }) }
onRunFinished: function(runId, result) { backend.emit("scriptCommands.finished", result) }
onCreated: function(ok, path, text) {
if (ok) Util.execArgv(["omarchy-launch-editor", path])
backend.emit("scriptCommands.created", { ok: ok, path: path, message: text })
}
}

OmarchyMenuSource {
id: menuSource
onRevisionChanged: rebuildTimer.restart()
Expand Down
Loading