@lukstei/dsh-schedule-script 0.0.0-stage → 0.2.2-rc.5.3
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 +21 -0
- package/README.md +203 -2
- package/cordis.patch.yml +4 -0
- package/dist/client.js +848 -0
- package/dist/index.js +826 -0
- package/package.json +103 -3
- package/src/client.tsx +717 -0
- package/src/executor.ts +101 -0
- package/src/fold.ts +154 -0
- package/src/index.ts +616 -0
- package/src/parser.ts +138 -0
- package/src/runner-cli.ts +81 -0
- package/src/skill.ts +120 -0
- package/src/styles.ts +333 -0
- package/src/types.ts +132 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Lukas Steinbrecher
|
|
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
CHANGED
|
@@ -1,3 +1,204 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @lukstei/dsh-schedule-script
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## Summary
|
|
4
|
+
|
|
5
|
+
Runs recurring TypeScript scripts in the background without calling the model. A script polls something, keeps state between runs, and only wakes the agent when it returns a `prompt`. Agents use it through the `schedule-script` skill and two tools; users see a status button and a command card in the chat.
|
|
6
|
+
|
|
7
|
+
## Table of Contents
|
|
8
|
+
|
|
9
|
+
- [Use this package](#use-this-package)
|
|
10
|
+
- [Understand the implementation](#understand-the-implementation)
|
|
11
|
+
- [Further Exploration](#further-exploration)
|
|
12
|
+
- [Model Experience](#model-experience)
|
|
13
|
+
- [Known Limitations and Deferred Work](#known-limitations-and-deferred-work)
|
|
14
|
+
- [Dev Note](#dev-note)
|
|
15
|
+
|
|
16
|
+
-----
|
|
17
|
+
|
|
18
|
+
<a id="use-this-package"></a>
|
|
19
|
+
## Use this package
|
|
20
|
+
|
|
21
|
+
Mount it in the agent's Cordis composition (also shipped as `cordis.patch.yml`):
|
|
22
|
+
|
|
23
|
+
```yaml
|
|
24
|
+
- id: schedule-script
|
|
25
|
+
name: '@lukstei/dsh-schedule-script'
|
|
26
|
+
config: {}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
The plugin has no config fields. Required services (`inject`): `commands`, `sessionProjections`, `tools`, `skills`, `schedule`. The web client bundle (`./client`) needs `slots`, `remote`, `remote.schedule`.
|
|
30
|
+
|
|
31
|
+
### Plugin dependencies
|
|
32
|
+
|
|
33
|
+
Server-side and client-side entries.
|
|
34
|
+
|
|
35
|
+
**Server-side** (`inject`: `commands`, `sessionProjections`, `tools`, `skills`, `schedule`):
|
|
36
|
+
|
|
37
|
+
| Plugin / service | Required? | Provided by | Effect without it |
|
|
38
|
+
|---|---|---|---|
|
|
39
|
+
| `commands` | Required | @deepseek-ai/dsh-commands | Plugin stays pending; never applies. |
|
|
40
|
+
| `sessionProjections` | Required | @deepseek-ai/dsh-session-projection | Plugin stays pending; never applies. |
|
|
41
|
+
| `tools` | Required | @deepseek-ai/dsh-tools | Plugin stays pending; never applies. No schedule tools. |
|
|
42
|
+
| `skills` | Required | @deepseek-ai/dsh-skill | Plugin stays pending; never applies. The `schedule-script` skill is not registered. |
|
|
43
|
+
| `schedule` | Required | @deepseek-ai/dsh-schedule | Plugin stays pending; never applies. No automation tasks to create, list or delete. |
|
|
44
|
+
|
|
45
|
+
**Client-side** (`inject`: `slots`, `remote`, `remote.schedule`):
|
|
46
|
+
|
|
47
|
+
| Plugin / service | Required? | Provided by | Effect without it |
|
|
48
|
+
|---|---|---|---|
|
|
49
|
+
| `slots` | Required | @deepseek-ai/dsh-client-ui-slots | Plugin stays pending; never applies. |
|
|
50
|
+
| `remote`, `remote.schedule` | Required | @deepseek-ai/dsh-api-remotes / @deepseek-ai/dsh-schedule host Remote | Plugin stays pending; never applies. No popover or command view. |
|
|
51
|
+
|
|
52
|
+
Used by: nothing.
|
|
53
|
+
|
|
54
|
+
### Script contract
|
|
55
|
+
|
|
56
|
+
A script is a standalone `.ts` file that exports a named `main`. Zero imports are expected. The runner calls `main({ state, sessionId })`:
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
interface State {
|
|
60
|
+
count: number;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export async function main(ctx: { state: State; sessionId: string }): Promise<{
|
|
64
|
+
state: State; // required, passed back as ctx.state on the next run
|
|
65
|
+
prompt?: string; // wakes the agent with this text
|
|
66
|
+
error?: string; // recoverable warning, schedule keeps running
|
|
67
|
+
stop?: boolean; // end recurrence
|
|
68
|
+
}> {
|
|
69
|
+
const count = ctx.state.count + 1;
|
|
70
|
+
return { state: { count }, stop: count >= 10 };
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
| Result field | Behavior |
|
|
75
|
+
|---|---|
|
|
76
|
+
| `state` | Required. Missing or `undefined` fails the run. |
|
|
77
|
+
| `prompt` | Must be a string. Injected into the session as `[Scheduled Task: <scriptPath>]` plus the text, waking the agent. |
|
|
78
|
+
| `error` | Must be a string. Run is marked `warning`; no model call, schedule continues. |
|
|
79
|
+
| `stop` | Must be a boolean. Records a `stop` event and deletes the schedule. |
|
|
80
|
+
|
|
81
|
+
Input `state` is mandatory. Uncaught exceptions, a missing `main`, an invalid result shape, or a timeout are fatal: the run records an `error` event, a `stop` event, and the schedule is deleted.
|
|
82
|
+
|
|
83
|
+
### Tools and skill
|
|
84
|
+
|
|
85
|
+
| Name | Purpose |
|
|
86
|
+
|---|---|
|
|
87
|
+
| `schedule-script` skill | Registered in the skills catalog. Teaches the contract and a two-turn workflow (write script and propose parameters, then test and schedule after the user confirms). |
|
|
88
|
+
| `test_schedule_script` | One isolated run of a script, as the scheduler would run it. Params: `script_path`, `state` (both required), `timeout_ms` (default `30000`). |
|
|
89
|
+
| `schedule_script` | Creates a recurring schedule through the `schedule` service. Params: `script_path`, `title`, `state` (required), `interval_seconds` (default and minimum `60`). |
|
|
90
|
+
|
|
91
|
+
`schedule_script` fails if the session already has an active script schedule, or if another create for the same session is in flight. The schedule prompt is a JSON payload (`kind: "dsh-schedule-script"`, `scriptPath`, `state`, optional `timeoutMs`); the schedule target is the current session.
|
|
92
|
+
|
|
93
|
+
### Runtime behavior
|
|
94
|
+
|
|
95
|
+
1. The schedule service delivers a `[SCHEDULE REMINDER BATCH]` message to the session.
|
|
96
|
+
2. On `agent/pre-step` the plugin parses the batch, checks each script reminder against the active schedules for the session, and runs verified scripts (timeout `30000` ms unless the payload sets `timeoutMs`).
|
|
97
|
+
3. Script prompts replace the batch text. Non-script reminders stay in the batch. If nothing remains and the message list has other messages, the batch message is removed; if it is the only message, the step is rejected so no model call happens.
|
|
98
|
+
4. If more than one active script schedule targets the session, no script runs and the agent gets a notice to pause or delete all but one.
|
|
99
|
+
|
|
100
|
+
Client UI: a status button in the prompt toolbar (`conversation.input.left`, order 85) and a command card for `dsh-schedule-script` events in the chat (`conversation.chat.commandview`).
|
|
101
|
+
|
|
102
|
+
### CLI runner
|
|
103
|
+
|
|
104
|
+
The subprocess entry can be run by hand. It reads input JSON and writes output JSON:
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
echo '{"state":{"count":0},"sessionId":"s"}' > /tmp/in.json
|
|
108
|
+
node src/runner-cli.ts path/to/script.ts /tmp/in.json /tmp/out.json
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Usage: `runner-cli.ts <scriptPath> <inputPath> <outputPath>`. Output is `{ success: true, result }` or `{ success: false, error, stack }`. Requires a Node version that runs `.ts` files natively.
|
|
112
|
+
|
|
113
|
+
-----
|
|
114
|
+
|
|
115
|
+
<a id="understand-the-implementation"></a>
|
|
116
|
+
## Understand the implementation
|
|
117
|
+
|
|
118
|
+
<details>
|
|
119
|
+
<summary>Implementation internals — click to expand</summary>
|
|
120
|
+
|
|
121
|
+
### Files
|
|
122
|
+
|
|
123
|
+
| File | Role |
|
|
124
|
+
|---|---|
|
|
125
|
+
| `src/index.ts` | Plugin entry: projection, skill, tools, `agent/pre-step` hook, schedule verification and cleanup. |
|
|
126
|
+
| `src/executor.ts` | `executeScript`: writes `input.json` in a temp dir (`dsh-script-*`), spawns `process.execPath src/runner-cli.ts <script> <in> <out>` with the session `cwd` and an abort signal, reads `output.json`. Timeout is reported as `Script execution timed out after <n>ms`. |
|
|
127
|
+
| `src/runner-cli.ts` | Imports the script, calls `main`, validates the result, writes the output file. |
|
|
128
|
+
| `src/parser.ts` | Schedule prompt payload and reminder-batch parsing and formatting. |
|
|
129
|
+
| `src/fold.ts` | Folds session events into the projection state. |
|
|
130
|
+
| `src/types.ts` | Script types, event payloads, zod schemas for the summary. |
|
|
131
|
+
| `src/skill.ts` | Skill name, description, content. |
|
|
132
|
+
| `src/client.tsx` | Web client: slots, hooks, `ScheduleScriptPill`, command card. |
|
|
133
|
+
|
|
134
|
+
### Persisted state
|
|
135
|
+
|
|
136
|
+
Events are `command/run` + `command/done` pairs named `dsh-schedule-script`, with a JSON `args` payload whose `action` is `skill`, `start`, `iteration`, `error`, `stop`, or `cleanup`. A `command/done` is `error` only for fatal `error` actions.
|
|
137
|
+
|
|
138
|
+
The session projection key is `dshScheduleScript` (state version 1). The wire view is `null` until the skill was invoked, a run happened, or a script path is set. Summary fields: `scriptStatus` (`idle`, `running`, `warning`, `error`, `stopped`), `skillInvoked`, `scheduleId`, `cleanupPending`, `cleanupError`, `scriptPath`, `totalRuns`, `lastRunAt`, `lastDurationMs`, `state`, `lastPrompt`, `lastError`.
|
|
139
|
+
|
|
140
|
+
State owned by the session: `iteration` is `totalRuns + 1`, and the script's input state is the last recorded state, falling back to the payload's initial state. A session whose last status is `stopped` or `error` has its schedule deleted instead of run. Cleanup failures are recorded and `cleanupPending` stays set.
|
|
141
|
+
|
|
142
|
+
### Trust boundaries
|
|
143
|
+
|
|
144
|
+
Script path, state and timeout come from the model through `schedule_script` and are stored in the schedule prompt. Scripts run as a child Node process with the parent environment and the session working directory. There is no sandbox inside this package.
|
|
145
|
+
|
|
146
|
+
</details>
|
|
147
|
+
|
|
148
|
+
-----
|
|
149
|
+
|
|
150
|
+
<a id="further-exploration"></a>
|
|
151
|
+
## Further Exploration
|
|
152
|
+
|
|
153
|
+
- Upstream: [DSH module graph](https://github.com/deepseek-ai/deepseek-harness/blob/master/docs/module-graph.md).
|
|
154
|
+
- Sibling: [@lukstei/dsh-yaml-workflow](../dsh-yaml-workflow/README.md)
|
|
155
|
+
|
|
156
|
+
<a id="model-experience"></a>
|
|
157
|
+
## Model Experience
|
|
158
|
+
|
|
159
|
+
### schedule-script skill
|
|
160
|
+
|
|
161
|
+
#### What the model sees
|
|
162
|
+
|
|
163
|
+
One catalog entry: `schedule-script` with the description "Schedule recurring TypeScript background scripts without consuming LLM tokens." Loading it returns the full skill text (script contract, return fields, error handling, two-turn workflow).
|
|
164
|
+
|
|
165
|
+
#### Token effect
|
|
166
|
+
|
|
167
|
+
Catalog entry always; skill body only after the model loads it.
|
|
168
|
+
|
|
169
|
+
#### KV Cache effect
|
|
170
|
+
|
|
171
|
+
Static catalog entry. The skill body extends the conversation after the load.
|
|
172
|
+
|
|
173
|
+
### test_schedule_script, schedule_script
|
|
174
|
+
|
|
175
|
+
#### What the model sees
|
|
176
|
+
|
|
177
|
+
Both tools are hidden until the session has loaded the skill, run a script, or has a script path recorded. Tool admission is resolved at turn boundaries, so they appear on the turn after the skill load. Results are a single message line (the test result also carries `state`, `prompt`, `error`, `stop`, `duration_ms`). When a script returns a `prompt`, the model receives it in place of the reminder batch message, prefixed `[Scheduled Task: <path>]`.
|
|
178
|
+
|
|
179
|
+
#### Token effect
|
|
180
|
+
|
|
181
|
+
Two tool schemas once admitted. Silent script runs cost no tokens. A wake-up costs the prompt text.
|
|
182
|
+
|
|
183
|
+
#### KV Cache effect
|
|
184
|
+
|
|
185
|
+
Admitting the tools changes the tool list, which invalidates the cached prefix once for that session. Wake-up prompts replace the reminder batch message in place.
|
|
186
|
+
|
|
187
|
+
<a id="known-limitations-and-deferred-work"></a>
|
|
188
|
+
## Known Limitations and Deferred Work
|
|
189
|
+
|
|
190
|
+
- One script schedule per session. Another is refused while one is active.
|
|
191
|
+
- The minimum interval is 60 seconds; lower values are clamped.
|
|
192
|
+
- Scripts are not sandboxed by this package.
|
|
193
|
+
- Running `.ts` files depends on the Node binary supporting native type stripping; the package passes no flags.
|
|
194
|
+
|
|
195
|
+
<a id="dev-note"></a>
|
|
196
|
+
### Dev Note
|
|
197
|
+
|
|
198
|
+
<details>
|
|
199
|
+
<summary>Working context for maintainers — click to expand</summary>
|
|
200
|
+
|
|
201
|
+
- `pnpm run verify` runs check, build, typecheck, and tests. `pnpm run ladle` serves component stories (`src/stories/`).
|
|
202
|
+
- The skill text says scripts run in "Node 26 subprocesses"; `package.json` declares no `engines` field.
|
|
203
|
+
|
|
204
|
+
</details>
|
package/cordis.patch.yml
ADDED