Skip to content

Commit 485918c

Browse files
committed
Wire up the OpenCode routine in launchd, daily at 6 AM
opencode run doesn't resolve custom slash commands (open upstream bug: anomalyco/opencode#7345) — passing "/event-watch" just forwards that literal text to the model instead of loading the command file. Add a wrapper script that pulls the model and prompt body out of .opencode/commands/event-watch.md's frontmatter directly and invokes opencode run with those, so the command file stays the single source of truth. Point the plist at the wrapper, fix the working directory/binary paths to match this machine (confirmed via a real end-to-end test run), and set the schedule to daily 6 AM.
1 parent 29c77fd commit 485918c

2 files changed

Lines changed: 49 additions & 26 deletions

File tree

‎launchd/com.michaelcmar.event-watch-opencode.plist‎

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,34 @@
55
<key>Label</key>
66
<string>com.michaelcmar.event-watch-opencode</string>
77

8-
<!-- Runs `opencode run` with the auto flag against the /event-watch
9-
command, from the repo directory. The auto flag auto-approves the
10-
permission prompts (bash, edit, write) that opencode would otherwise
11-
stop and ask about interactively — needed since nothing is watching
12-
this when launchd fires it. It only changes prompts that would
13-
otherwise ask; it does not override any explicit "deny" rule in
14-
opencode.json (there are none here).
8+
<!-- Runs run-event-watch-opencode.sh, which itself calls opencode run
9+
with the model and prompt body pulled from the command file,
10+
plus the auto flag. It's a wrapper instead of a plain
11+
`opencode run` against the /event-watch command because opencode
12+
run does not resolve custom slash commands (open upstream bug)
13+
— see the comment at the top of that script for details. If that
14+
ever gets fixed upstream, this plist can point straight at
15+
opencode again.
1516
16-
Before enabling this job, run the same command by hand once from a
17-
terminal (omit the auto flag, so you can watch it) to confirm:
17+
Before enabling this job, confirm:
1818
- `opencode auth login` has been run once to connect the OpenRouter
1919
provider (stores the API key in opencode's own credential store,
2020
not in this repo, so it's never committed).
2121
- The Gmail MCP server's one-time OAuth consent has been completed
22-
(see README/chat notes for the exact command) so its refresh
23-
token is cached under ~/.gmail-mcp/ and future runs need no
24-
browser interaction.
25-
Update the path below to match `which opencode` on your machine if
26-
it's not at /usr/local/bin/opencode. -->
22+
so its refresh token is cached under ~/.gmail-mcp/ and future
23+
runs need no browser interaction.
24+
Update the paths below if this repo or the opencode binary ever move. -->
2725
<key>ProgramArguments</key>
2826
<array>
29-
<string>/usr/local/bin/opencode</string>
30-
<string>run</string>
31-
<string>--auto</string>
32-
<string>/event-watch</string>
27+
<string>/Users/michaelcmar/Projects/event-watch/launchd/run-event-watch-opencode.sh</string>
3328
</array>
3429

3530
<key>WorkingDirectory</key>
36-
<string>/Users/michaelcmar/Documents/Developer/event-watch</string>
31+
<string>/Users/michaelcmar/Projects/event-watch</string>
3732

3833
<!-- launchd does not source your shell profile, so PATH must be set explicitly.
39-
Run `which node` and `which opencode` locally and add their directories
40-
here if the job fails to find either.
34+
Run `which node` locally and add its directory here if the job fails to
35+
find it (opencode needs it to spawn the Gmail MCP server via npx).
4136
4237
OPENCODE_ENABLE_EXA turns on opencode's built-in websearch/webfetch
4338
tools (Exa-hosted, no separate API key needed); they're off by
@@ -56,17 +51,16 @@
5651
</dict>
5752

5853
<key>StandardOutPath</key>
59-
<string>/Users/michaelcmar/Documents/Developer/event-watch/logs/event-watch-opencode.out.log</string>
54+
<string>/Users/michaelcmar/Projects/event-watch/logs/event-watch-opencode.out.log</string>
6055

6156
<key>StandardErrorPath</key>
62-
<string>/Users/michaelcmar/Documents/Developer/event-watch/logs/event-watch-opencode.err.log</string>
57+
<string>/Users/michaelcmar/Projects/event-watch/logs/event-watch-opencode.err.log</string>
6358

64-
<!-- Every day at 9:00 AM local time (daily instead of weekly, since
65-
OpenRouter billing has no weekly-quota reason to hold back). -->
59+
<!-- Every day at 6:00 AM local time. -->
6660
<key>StartCalendarInterval</key>
6761
<dict>
6862
<key>Hour</key>
69-
<integer>9</integer>
63+
<integer>6</integer>
7064
<key>Minute</key>
7165
<integer>0</integer>
7266
</dict>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
# Wrapper for the launchd job, needed because `opencode run` does not
3+
# resolve custom slash commands (open upstream bug, confirmed as of
4+
# opencode 1.17.20 — https://github.com/anomalyco/opencode/issues/7345):
5+
# passing "/event-watch" as the prompt just forwards that literal text to
6+
# the model instead of loading .opencode/commands/event-watch.md.
7+
#
8+
# Workaround: pull the model and prompt body out of that command file's
9+
# frontmatter ourselves and pass them directly via -m/argv, so this file
10+
# is the only place that needs to change if the invocation trick stops
11+
# being necessary (once upstream fixes it, this can go back to a plain
12+
# `opencode run --auto "/event-watch"`).
13+
set -euo pipefail
14+
15+
REPO_DIR="/Users/michaelcmar/Projects/event-watch"
16+
COMMAND_FILE="$REPO_DIR/.opencode/commands/event-watch.md"
17+
OPENCODE_BIN="/Users/michaelcmar/.opencode/bin/opencode"
18+
19+
cd "$REPO_DIR"
20+
21+
MODEL=$(sed -n 's/^model: *//p' "$COMMAND_FILE" | head -1)
22+
PROMPT=$(awk '/^---$/{c++; next} c>=2' "$COMMAND_FILE")
23+
24+
if [ -z "$MODEL" ] || [ -z "$PROMPT" ]; then
25+
echo "Failed to extract model/prompt from $COMMAND_FILE — aborting." >&2
26+
exit 1
27+
fi
28+
29+
exec "$OPENCODE_BIN" run -m "$MODEL" --auto "$PROMPT"

0 commit comments

Comments
 (0)