opencode-routines 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Different AI
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,132 @@
1
+ # opencode-routines
2
+
3
+ Claude-Code-style routines for [opencode](https://opencode.ai): same-session loops, same-session cron prompts, and host-backed standalone scheduled agents.
4
+
5
+ This package is a hard fork / successor of `opencode-scheduler` by Benjamin Shafii. The durable host scheduler implementation is derived from that project; this fork changes the product model around routines and adds Claude-aligned tool names.
6
+
7
+ ## Install
8
+
9
+ Server tools only:
10
+
11
+ ```json
12
+ {
13
+ "plugin": ["opencode-routines"]
14
+ }
15
+ ```
16
+
17
+ Server tools plus optional TUI slash commands:
18
+
19
+ ```json
20
+ {
21
+ "plugin": ["opencode-routines", "opencode-routines/tui"]
22
+ }
23
+ ```
24
+
25
+ `opencode-routines/tui` is a subpath export from the same npm package, not a separate package.
26
+
27
+ ## Concepts
28
+
29
+ | Concept | Session model | Where it runs | Persistence |
30
+ |---|---|---|---|
31
+ | Loop | Same conversation | Current opencode host/process | Process-scoped |
32
+ | Cron prompt | Same conversation | Current opencode host/process | Session-only for now |
33
+ | Standalone schedule | Fresh standalone opencode run | Host scheduler: launchd/systemd/Task Scheduler/cron | Durable |
34
+
35
+ The ambiguous `/schedule` slash command is intentionally **not** registered. Use `/schedule-standalone-session` for help with durable standalone schedules, or use the `ScheduleCreate` tool directly.
36
+
37
+ ## Same-session loop tools
38
+
39
+ | Tool | Description |
40
+ |---|---|
41
+ | `LoopCreate` | Start a same-session loop. Fixed interval when `interval` is provided; dynamic mode otherwise. |
42
+ | `LoopList` | List active loops in this plugin process. |
43
+ | `LoopDelete` | Stop an active loop. |
44
+ | `ScheduleWakeup` | Dynamic-loop wake-up tool. Only works for an active dynamic loop in the same session and prompt. |
45
+
46
+ `ScheduleWakeup` parameters align with Claude Code:
47
+
48
+ | Param | Type | Required | Description |
49
+ |---|---|---|---|
50
+ | `delaySeconds` | number | yes | Seconds until wake-up. Clamped to 60-3600. |
51
+ | `prompt` | string | yes | The loop prompt to fire on wake-up. |
52
+ | `reason` | string | yes | Short explanation for the wake-up. |
53
+
54
+ ## Same-session cron tools
55
+
56
+ | Tool | Description |
57
+ |---|---|
58
+ | `CronCreate` | Schedule a prompt at wall-clock times in the current session. |
59
+ | `CronList` | List active same-session cron prompts. |
60
+ | `CronDelete` | Cancel a same-session cron prompt. |
61
+
62
+ `CronCreate` parameters:
63
+
64
+ | Param | Type | Required | Default | Description |
65
+ |---|---|---|---|---|
66
+ | `cron` | string | yes | — | 5-field cron in local timezone: `M H DoM Mon DoW`. |
67
+ | `prompt` | string | yes | — | Prompt to enqueue in the same session. |
68
+ | `recurring` | boolean | no | `true` | `false` = one-shot. |
69
+ | `durable` | boolean | no | `false` | Accepted for Claude compatibility, but currently session-only. |
70
+
71
+ ## Durable standalone schedule tools
72
+
73
+ Claude-aligned aliases:
74
+
75
+ | Tool | Description |
76
+ |---|---|
77
+ | `ScheduleCreate` | Create a durable host-backed standalone scheduled opencode run. |
78
+ | `ScheduleList` | List standalone schedules. |
79
+ | `ScheduleDelete` | Delete a standalone schedule. |
80
+ | `ScheduleRun` | Run a standalone schedule immediately. |
81
+ | `ScheduleLogs` | View logs for a standalone schedule. |
82
+
83
+ Legacy compatibility aliases are still present:
84
+
85
+ | Tool | Description |
86
+ |---|---|
87
+ | `schedule_job` | Create a durable standalone schedule. |
88
+ | `list_jobs` | List durable standalone schedules. |
89
+ | `get_job` | Get schedule details. |
90
+ | `update_job` | Update a schedule. |
91
+ | `delete_job` | Delete a schedule. |
92
+ | `run_job` | Run a schedule immediately. |
93
+ | `job_logs` | View schedule logs. |
94
+ | `cleanup_global` | Clean up scheduler artifacts across all scopes. |
95
+
96
+ Durable standalone schedules use the host scheduler: launchd on macOS, systemd on Linux, Task Scheduler on Windows, or cron fallback. Each run starts a fresh standalone `opencode run` by default. Pass explicit `session`, `continue`, or `attachUrl` only when you intentionally want different behavior.
97
+
98
+ ## Optional TUI commands
99
+
100
+ Available when `opencode-routines/tui` is installed:
101
+
102
+ | Command | Meaning |
103
+ |---|---|
104
+ | `/loop` | Start a same-session live loop. Fixed interval syntax: `5m /babysit-prs`. Dynamic syntax: `/babysit-prs`. |
105
+ | `/loops` | List active loops. Selecting a loop stops it. |
106
+ | `/stop-loop` | Stop an active loop. |
107
+ | `/schedule-standalone-session` | Help entry for durable standalone schedules. |
108
+
109
+ ## Storage
110
+
111
+ Standalone schedule storage remains compatible with `opencode-scheduler`:
112
+
113
+ | What | Where |
114
+ |---|---|
115
+ | Job configs | `~/.config/opencode/scheduler/scopes/<scopeId>/jobs/*.json` |
116
+ | Run records | `~/.config/opencode/scheduler/scopes/<scopeId>/runs/*.jsonl` |
117
+ | Locks | `~/.config/opencode/scheduler/scopes/<scopeId>/locks/*.json` |
118
+ | Logs | `~/.config/opencode/logs/scheduler/<scopeId>/*.log` |
119
+ | Supervisor script | `~/.config/opencode/scheduler/supervisor.pl` |
120
+
121
+ ## Publishing
122
+
123
+ ```bash
124
+ npm login
125
+ npm publish
126
+ ```
127
+
128
+ Bump `version` in `package.json` before each release.
129
+
130
+ ## License
131
+
132
+ MIT
@@ -0,0 +1,61 @@
1
+ /**
2
+ * OpenCode Scheduler Plugin
3
+ *
4
+ * Schedule recurring jobs using launchd (Mac), systemd (Linux), schtasks (Windows), or cron fallback.
5
+ * Jobs are stored under ~/.config/opencode/scheduler/ (scoped by workdir).
6
+ *
7
+ * Features:
8
+ * - Survives reboots
9
+ * - Catches up on missed runs (if computer was asleep)
10
+ * - Cross-platform (Mac + Linux + Windows)
11
+ * - Working directory support for MCP configs
12
+ * - Environment variable injection (PATH for node/npx)
13
+ */
14
+ import type { Plugin } from "@opencode-ai/plugin";
15
+ type OpencodeRunFormat = "default" | "json";
16
+ interface JobRunSpec {
17
+ prompt?: string;
18
+ command?: string;
19
+ arguments?: string;
20
+ files?: string[];
21
+ agent?: string;
22
+ model?: string;
23
+ variant?: string;
24
+ title?: string;
25
+ share?: boolean;
26
+ continue?: boolean;
27
+ session?: string;
28
+ runFormat?: OpencodeRunFormat;
29
+ attachUrl?: string;
30
+ port?: number;
31
+ }
32
+ type JobInvocation = {
33
+ command: string;
34
+ args: string[];
35
+ };
36
+ interface Job {
37
+ scopeId?: string;
38
+ slug: string;
39
+ name: string;
40
+ schedule: string;
41
+ prompt?: string;
42
+ attachUrl?: string;
43
+ run?: JobRunSpec;
44
+ invocation?: JobInvocation;
45
+ timeoutSeconds?: number;
46
+ source?: string;
47
+ workdir?: string;
48
+ createdAt: string;
49
+ updatedAt?: string;
50
+ lastRunAt?: string;
51
+ lastRunExitCode?: number;
52
+ lastRunError?: string;
53
+ lastRunSource?: "manual" | "scheduled";
54
+ lastRunStatus?: "running" | "success" | "failed";
55
+ }
56
+ export declare function __testBuildOpencodeArgs(job: Job): {
57
+ command: string;
58
+ args: string[];
59
+ };
60
+ export declare const SchedulerPlugin: Plugin;
61
+ export default SchedulerPlugin;