dsh-background-task-engine 1.0.1 → 1.0.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/CHANGELOG.md +29 -0
- package/README.en.md +266 -0
- package/README.md +171 -203
- package/docs/TEST-REPORT.md +18 -0
- package/package.json +9 -5
- package/README.zh.md +0 -179
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,35 @@ All notable changes to `dsh-background-task-engine` are documented here.
|
|
|
4
4
|
The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and
|
|
5
5
|
the project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
6
|
|
|
7
|
+
## [1.0.3] — 2026-11-26
|
|
8
|
+
|
|
9
|
+
Packaging fixes required for plugin-market listing.
|
|
10
|
+
|
|
11
|
+
### Changed
|
|
12
|
+
|
|
13
|
+
- `@deepseek-ai/schemastery` moved from `dependencies` to `peerDependencies`
|
|
14
|
+
(also kept in `devDependencies` for local builds). It is a host-provided
|
|
15
|
+
`@deepseek-ai/*` package, so declaring it as a peer avoids shipping a second
|
|
16
|
+
copy and follows the market guidance. `zod` stays a regular dependency because
|
|
17
|
+
record schemas are validated in-process regardless of the host.
|
|
18
|
+
- Added `assets/icon-180.png`: the market accepts raster icons only
|
|
19
|
+
(`png`/`jpg`/`jpeg`/`webp`) and refuses SVG, so a 180×180 PNG is now shipped
|
|
20
|
+
alongside `icon.svg` (which the DSH plugin list still uses).
|
|
21
|
+
|
|
22
|
+
## [1.0.2] — 2026-11-26
|
|
23
|
+
|
|
24
|
+
Documentation release: the default README is now Chinese.
|
|
25
|
+
|
|
26
|
+
### Changed
|
|
27
|
+
|
|
28
|
+
- `README.md` is now the Chinese document, so the npm package page and the GitHub
|
|
29
|
+
repository home both render in Chinese by default.
|
|
30
|
+
- The previous English README moved to `README.en.md`; both files carry a
|
|
31
|
+
language switch at the top. `README.zh.md` was removed (it is now `README.md`).
|
|
32
|
+
- `package.json` `description` is now Chinese, so the npm listing summary matches
|
|
33
|
+
the README.
|
|
34
|
+
- `files` updated from `README.zh.md` to `README.en.md`.
|
|
35
|
+
|
|
7
36
|
## [1.0.1] — 2026-11-26
|
|
8
37
|
|
|
9
38
|
Documentation-only release.
|
package/README.en.md
ADDED
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
# dsh-background-task-engine
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/dsh-background-task-engine)
|
|
4
|
+
[](LICENSE)
|
|
5
|
+
|
|
6
|
+
**English | [中文](README.md)**
|
|
7
|
+
|
|
8
|
+
Durable background task engine for **DeepSeek Harness (DSH)**: reusable task
|
|
9
|
+
templates, ordered linear steps, one persisted run ledger, progress and history
|
|
10
|
+
queries, explicit failure/interruption recovery, and optional linkage to native
|
|
11
|
+
DSH Schedule.
|
|
12
|
+
|
|
13
|
+
It does not reimplement a scheduler, an agent loop, a job registry or a storage
|
|
14
|
+
backend — it composes the Host's own `ctx.schedule`, `ctx.storageDomain` and
|
|
15
|
+
`ctx.tools`.
|
|
16
|
+
|
|
17
|
+
- [Install](#install)
|
|
18
|
+
- [Tools](#tools)
|
|
19
|
+
- [Execution protocol](#execution-protocol)
|
|
20
|
+
- [Data model](#data-model)
|
|
21
|
+
- [Configuration](#configuration)
|
|
22
|
+
- [Errors](#errors)
|
|
23
|
+
- [Security](#security)
|
|
24
|
+
- [Upgrade](#upgrade)
|
|
25
|
+
- [Troubleshooting](#troubleshooting)
|
|
26
|
+
- [Development](#development)
|
|
27
|
+
|
|
28
|
+
## Install
|
|
29
|
+
|
|
30
|
+
Requirements: DSH **0.2.2-rc.3** or a compatible release with
|
|
31
|
+
`ctx.storageDomain` mounted (the stock base bundle does this with
|
|
32
|
+
`storage-domain backend: json`).
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
# from npm (published 1.0.2)
|
|
36
|
+
dsh plugin --profile <name> add dsh-background-task-engine
|
|
37
|
+
|
|
38
|
+
# or from a local checkout
|
|
39
|
+
dsh plugin --profile <name> add /absolute/path/to/dsh-background-task-engine
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
When installing from a directory path, run `npm install` in that directory first:
|
|
43
|
+
the plugin imports `@deepseek-ai/schemastery`, and a missing `node_modules` makes
|
|
44
|
+
the loader fail with `ERR_MODULE_NOT_FOUND`. The registry spec carries its own
|
|
45
|
+
dependencies and needs no checkout.
|
|
46
|
+
|
|
47
|
+
Then restart the app. Confirm in **Plugins** that the row
|
|
48
|
+
`background-task-engine` is enabled; the row shows this bundle's title,
|
|
49
|
+
description and icon.
|
|
50
|
+
|
|
51
|
+
The bundle patch is intentionally empty apart from the plugin row, so installing
|
|
52
|
+
it does not change any other setting:
|
|
53
|
+
|
|
54
|
+
```yaml
|
|
55
|
+
- insert:
|
|
56
|
+
- id: background-task-engine
|
|
57
|
+
name: 'dsh-background-task-engine'
|
|
58
|
+
config: { ... }
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Tools
|
|
62
|
+
|
|
63
|
+
Twelve model-facing tools, all returning
|
|
64
|
+
`{ success: true, ... }` or `{ success: false, error: { code, message, retryable, relatedRunId? } }`.
|
|
65
|
+
|
|
66
|
+
| Tool | Purpose | Key arguments |
|
|
67
|
+
|---|---|---|
|
|
68
|
+
| `task_create` | Create a template (1–10 steps) | `title`, `description?`, `steps[]`, `copyFromTaskId?` |
|
|
69
|
+
| `task_list` | List this Session's templates | `status?`, `query?`, `limit?`, `cursor?` |
|
|
70
|
+
| `task_get` | Read one template + recent runs | `taskId`, `includeRuns?` |
|
|
71
|
+
| `task_update` | Edit title/description/steps/status | `taskId`, `expectedRevision`, `changes` |
|
|
72
|
+
| `task_archive` | Soft-archive; history preserved | `taskId`, `expectedRevision` |
|
|
73
|
+
| `task_schedule` | Manage the native schedule link | `taskId`, `action`, `timing?`, `scheduleRule?` |
|
|
74
|
+
| `task_run` | Start a manual run now | `taskId`, `manualRunId?`, `defer?` |
|
|
75
|
+
| `task_run_begin` | Claim a run (task or queued run or delivery payload) | `taskId?`, `runId?`, `triggerPayload?`, `scheduleId?`, `occurrenceKey?`, `idempotencyKey?` |
|
|
76
|
+
| `task_step_report` | Report a step | `runId`, `stepId`, `action`, `summary?`, `error?` |
|
|
77
|
+
| `task_run_finish` | Submit the run result | `runId`, `status`, `summary?`, `error?` |
|
|
78
|
+
| `task_run_history` | Page run history | `taskId`, `status?`, `limit?`, `cursor?` |
|
|
79
|
+
| `task_resume` | Recover a failed/interrupted/blocked run | `runId`, `confirmation?` |
|
|
80
|
+
|
|
81
|
+
`task_schedule` actions: `create`, `update`, `pause`, `resume`, `delete`,
|
|
82
|
+
`run_now`, `status`. Timing input accepts `at`, `every`, `rrule`, `cron`,
|
|
83
|
+
`daily`, `weekly`; `daily`/`weekly` are translated to an equivalent `RRULE` so
|
|
84
|
+
the plugin depends on fewer host shapes. The plugin stores only `scheduleId`
|
|
85
|
+
plus a small reference — never a copy of cron state.
|
|
86
|
+
|
|
87
|
+
## Execution protocol
|
|
88
|
+
|
|
89
|
+
A run is executed **by the calling Agent in its own authorized context**. There
|
|
90
|
+
is no worker process, and a `followup` receipt is never treated as completion.
|
|
91
|
+
|
|
92
|
+
1. `task_run` or `task_run_begin` → `runId` + snapshot + step list.
|
|
93
|
+
2. For each step in `order`: `task_step_report(action:"started")`.
|
|
94
|
+
3. `task_step_report(action:"completed" | "failed" | "skipped")` with a real
|
|
95
|
+
summary. `completed` requires the step's `completionCriteria` to be met.
|
|
96
|
+
4. Missing input, a pending approval, or an unmet external condition →
|
|
97
|
+
`task_run_finish(status:"blocked", summary:"…")` naming what is awaited.
|
|
98
|
+
5. All required steps completed → `task_run_finish(status:"succeeded")`.
|
|
99
|
+
6. A failure → `task_step_report(action:"failed", error:{…})` **then**
|
|
100
|
+
`task_run_finish(status:"failed")`.
|
|
101
|
+
|
|
102
|
+
Progress is always `floor(completed required steps / required steps × 100)` and is
|
|
103
|
+
recomputed from persisted step rows — never from caller claims.
|
|
104
|
+
|
|
105
|
+
### Scheduled runs
|
|
106
|
+
|
|
107
|
+
A `task_schedule` create stores a prompt carrying `task_id_json` on the host
|
|
108
|
+
schedule. When a delivery arrives:
|
|
109
|
+
|
|
110
|
+
```text
|
|
111
|
+
task_run_begin({ triggerPayload: "<the delivered message>" })
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
The tool extracts `task_id_json`, `schedule_id_json` and `occurrence_at`, then
|
|
115
|
+
uses `schedule:<scheduleId>:<occurrence>` as the idempotency key. A duplicated
|
|
116
|
+
delivery returns the existing run with `deduplicated: true` instead of starting a
|
|
117
|
+
second execution. **Delivery proves the message was enqueued — not that the run
|
|
118
|
+
finished.**
|
|
119
|
+
|
|
120
|
+
## Data model
|
|
121
|
+
|
|
122
|
+
StorageDomain unit `dsh_background_task_engine`, schema version `1`
|
|
123
|
+
(the underscore form is required: the host's unit-name rule is
|
|
124
|
+
`/^[a-z][a-z0-9_]*$/`).
|
|
125
|
+
|
|
126
|
+
| Table | Key | Contents |
|
|
127
|
+
|---|---|---|
|
|
128
|
+
| `tasks` | `taskId` | template, status, revision, owner Session, steps, schedule reference |
|
|
129
|
+
| `task_runs` | `runId` | status, trigger, snapshot, progress, times, summary/error, `resumesRunId` |
|
|
130
|
+
| `task_run_steps` | `runId/stepId` | per-run step status, attempt, times, summary/error |
|
|
131
|
+
| `meta` | `global` | `schemaVersion`, applied-migration ledger, recovery/prune timestamps |
|
|
132
|
+
|
|
133
|
+
Status machines:
|
|
134
|
+
|
|
135
|
+
```text
|
|
136
|
+
Task active → paused → active active/paused → archived (final)
|
|
137
|
+
TaskRun queued → running → succeeded | failed | blocked | interrupted
|
|
138
|
+
queued → skipped
|
|
139
|
+
blocked → failed | interrupted (never back to running)
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
`failed`, `succeeded`, `interrupted` and `skipped` are terminal. Recovery always
|
|
143
|
+
creates a **new** run with `resumesRunId`; completed steps are carried over, the
|
|
144
|
+
run continues at the first unfinished step, and a run whose failed step may have
|
|
145
|
+
had side effects requires an explicit `confirmation`.
|
|
146
|
+
|
|
147
|
+
Retention: terminal runs older than `historyRetentionDays` (default 90) are
|
|
148
|
+
pruned with their step rows at startup. Active runs, templates and audit events
|
|
149
|
+
are never pruned.
|
|
150
|
+
|
|
151
|
+
## Configuration
|
|
152
|
+
|
|
153
|
+
Exported as `Config` (Schemastery) and validated again at load; out-of-range
|
|
154
|
+
values fail the load rather than being clamped.
|
|
155
|
+
|
|
156
|
+
| Key | Default | Range | Meaning |
|
|
157
|
+
|---|---|---|---|
|
|
158
|
+
| `maxTasksPerOwner` | 100 | 1–1000 | unarchived templates per Session |
|
|
159
|
+
| `maxStepsPerTask` | 10 | 1–10 | steps per template (V1.0 is linear) |
|
|
160
|
+
| `maxActiveRunsPerOwner` | 3 | 1–20 | concurrent queued/running runs per Session |
|
|
161
|
+
| `maxParallelRunsPerTask` | 1 | 1 | parallel runs of one task (fixed in V1.0) |
|
|
162
|
+
| `defaultTimeoutMinutes` | 60 | 1–1440 | timeout used for identification only |
|
|
163
|
+
| `staleRunAfterMinutes` | 30 | 1–1440 | age at which a startup scan marks a run `interrupted` |
|
|
164
|
+
| `historyRetentionDays` | 90 | 1–3650 | terminal run retention |
|
|
165
|
+
| `maxSummaryChars` | 2000 | 100–10000 | summary truncation bound |
|
|
166
|
+
|
|
167
|
+
## Errors
|
|
168
|
+
|
|
169
|
+
| Code | Meaning | Retryable |
|
|
170
|
+
|---|---|---|
|
|
171
|
+
| `TASK_NOT_FOUND` | task missing, or not owned by this Session | no |
|
|
172
|
+
| `TASK_ALREADY_RUNNING` | the task already has an active run | after it ends |
|
|
173
|
+
| `TASK_REVISION_CONFLICT` | `expectedRevision` is stale | re-read, then retry |
|
|
174
|
+
| `TASK_INVALID_STEPS` | bad step definition / count | fix arguments |
|
|
175
|
+
| `TASK_RUN_NOT_FOUND` | run missing or not owned by this Session | no |
|
|
176
|
+
| `TASK_RUN_ALREADY_FINISHED` | run is terminal | start a new run |
|
|
177
|
+
| `TASK_STEP_ORDER_INVALID` | out-of-order, unknown, or duplicate step report | fix order |
|
|
178
|
+
| `TASK_PERMISSION_DENIED` | archived/paused task, or missing resume confirmation | no |
|
|
179
|
+
| `TASK_SCHEDULE_UNAVAILABLE` | Schedule not mounted | after the host provides it |
|
|
180
|
+
| `TASK_SCHEDULE_FAILED` | host schedule operation failed | inspect host state |
|
|
181
|
+
| `TASK_STORAGE_ERROR` | StorageDomain missing, failed, or incompatible | after the host is fixed |
|
|
182
|
+
| `TASK_RUN_INTERRUPTED` | execution lost, marked interrupted | `task_resume` |
|
|
183
|
+
| `TASK_MAX_CONCURRENCY` | per-Session active-run cap reached | after a run ends |
|
|
184
|
+
| `TASK_INVALID_ARGUMENTS` | argument failed validation | fix arguments |
|
|
185
|
+
| `TASK_INTERNAL_ERROR` | unexpected runtime failure | no |
|
|
186
|
+
|
|
187
|
+
The first 13 are the PRD's stable codes; the last two are additive so an
|
|
188
|
+
unexpected failure is never reported as a misleading PRD code.
|
|
189
|
+
|
|
190
|
+
## Security
|
|
191
|
+
|
|
192
|
+
- **Session isolation.** Every tool entry point resolves the caller Session from
|
|
193
|
+
`exec.agent.session.id` and compares it with the record owner. A record owned by
|
|
194
|
+
another Session is reported as `TASK_NOT_FOUND`, so the error cannot be used to
|
|
195
|
+
probe other Sessions' data.
|
|
196
|
+
- **No privilege escalation.** The engine never adds shell, file, browser or
|
|
197
|
+
network capability. Every action runs through the Agent's already-authorized
|
|
198
|
+
tools and existing approval flow.
|
|
199
|
+
- **Templates are data.** Step `instruction` text is user content with no
|
|
200
|
+
elevated authority; a template cannot change system prompts, permissions or
|
|
201
|
+
tool access. External text is rendered as untrusted single-line text.
|
|
202
|
+
- **No leakage.** Error messages are sanitised: stack frames dropped, absolute
|
|
203
|
+
paths replaced with `<path>`, credential-looking assignments redacted.
|
|
204
|
+
- **No code injection.** Task arguments cannot carry JavaScript, dynamic imports
|
|
205
|
+
or scripts; there is no evaluator anywhere in the plugin.
|
|
206
|
+
- Scheduling is bound to the creating Session, so a scheduled run executes in the
|
|
207
|
+
Session that owns the task.
|
|
208
|
+
|
|
209
|
+
## Upgrade
|
|
210
|
+
|
|
211
|
+
1. Bump the bundle; the plugin row keeps its config.
|
|
212
|
+
2. On next start the engine opens the domain, compares the stored
|
|
213
|
+
`meta.schemaVersion`, and runs any pending migration once each, recording a
|
|
214
|
+
marker **only after** the migration succeeds.
|
|
215
|
+
3. A stored version **higher** than the plugin supports is refused with
|
|
216
|
+
`TASK_STORAGE_ERROR` — downgrading is not silently allowed.
|
|
217
|
+
|
|
218
|
+
v1.0.0 ships an empty migration set (the baseline shape needs none); the runner
|
|
219
|
+
and ledger exist so a future shape change is a data edit plus one entry.
|
|
220
|
+
|
|
221
|
+
## Troubleshooting
|
|
222
|
+
|
|
223
|
+
| Symptom | Cause | Fix |
|
|
224
|
+
|---|---|---|
|
|
225
|
+
| Every tool returns `TASK_STORAGE_ERROR` mentioning `ctx.storageDomain` | the Host has no StorageDomain mounted | enable `storage` + `storage-json` + `storage-domain` in the profile |
|
|
226
|
+
| `invalid unit name '…'` | a domain/table name with a hyphen | the unit must match `/^[a-z][a-z0-9_]*$/` (this plugin uses `dsh_background_task_engine`) |
|
|
227
|
+
| `TASK_SCHEDULE_UNAVAILABLE` | `ctx.schedule` is not mounted | scheduling is optional; manual runs still work |
|
|
228
|
+
| Row did not activate: *cannot get property "…" without inject* | a plugin read an optional service as a property | resolve optional services via `ctx.get` |
|
|
229
|
+
| `TASK_REVISION_CONFLICT` | two edits raced | `task_get`, then retry with the current `revision` |
|
|
230
|
+
| A run is `interrupted` after a restart | the Host stopped mid-run; nothing is auto-restarted | `task_resume` with a confirmation if a step may have had side effects |
|
|
231
|
+
| Install rejected: *dsh.bundle.patch must be a file path* | flat manifest form | use `"dsh": { "bundle": { "patch": "./cordis.patch.yml" } }` |
|
|
232
|
+
|
|
233
|
+
## Development
|
|
234
|
+
|
|
235
|
+
```sh
|
|
236
|
+
npm install
|
|
237
|
+
npm run build # tsc -> dist/
|
|
238
|
+
npm run typecheck
|
|
239
|
+
npm test # 81 tests
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
Layout:
|
|
243
|
+
|
|
244
|
+
```text
|
|
245
|
+
src/
|
|
246
|
+
index.ts plugin entry: name / inject / Config / apply
|
|
247
|
+
host.ts structural host contract (no host package imports)
|
|
248
|
+
config.ts Schemastery Config + resolveConfig
|
|
249
|
+
errors.ts stable codes, payloads, message sanitisation
|
|
250
|
+
domain/records.ts zod record schemas
|
|
251
|
+
domain/state.ts TaskRun/StepRun state machines, progress, ordering
|
|
252
|
+
storage/spec.ts domain declaration, migrations, integrity check
|
|
253
|
+
storage/repository.ts the only reader/writer of domain tables
|
|
254
|
+
services/ audit, task, run, schedule adapter, engine
|
|
255
|
+
tools/ 12 tool definitions + shared plumbing
|
|
256
|
+
prompt/guidance.ts execution protocol and delivery parsing
|
|
257
|
+
tests/ domain, storage, rendering, integration (+ fakes)
|
|
258
|
+
docs/ API compatibility audit, test report, detail page
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
Verification records: `docs/API-COMPATIBILITY-AUDIT.md` (host capability audit,
|
|
262
|
+
including the real-stack runs) and `docs/TEST-REPORT.md` (all 81 assertions).
|
|
263
|
+
|
|
264
|
+
## License
|
|
265
|
+
|
|
266
|
+
MIT — see [LICENSE](LICENSE).
|
package/README.md
CHANGED
|
@@ -3,51 +3,43 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/dsh-background-task-engine)
|
|
4
4
|
[](LICENSE)
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
- [
|
|
16
|
-
- [
|
|
17
|
-
- [
|
|
18
|
-
- [
|
|
19
|
-
- [
|
|
20
|
-
- [
|
|
21
|
-
- [
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
## Install
|
|
27
|
-
|
|
28
|
-
Requirements: DSH **0.2.2-rc.3** or a compatible release with
|
|
29
|
-
`ctx.storageDomain` mounted (the stock base bundle does this with
|
|
30
|
-
`storage-domain backend: json`).
|
|
6
|
+
**[English](README.en.md) | 中文**
|
|
7
|
+
|
|
8
|
+
给 **DeepSeek Harness(DSH)** 用的持久化后台任务引擎:可复用的任务模板、有序线性步骤、单次运行账本、进度与历史查询、失败/中断后的人工恢复,以及可选的 DSH 原生定时关联。
|
|
9
|
+
|
|
10
|
+
它不重写调度器、Agent Loop、作业注册表或存储后端,只复用宿主已有的 `ctx.schedule`、`ctx.storageDomain` 和 `ctx.tools`。
|
|
11
|
+
|
|
12
|
+
- [安装](#安装)
|
|
13
|
+
- [工具](#工具)
|
|
14
|
+
- [执行协议](#执行协议)
|
|
15
|
+
- [数据模型](#数据模型)
|
|
16
|
+
- [配置](#配置)
|
|
17
|
+
- [错误码](#错误码)
|
|
18
|
+
- [安全](#安全)
|
|
19
|
+
- [升级](#升级)
|
|
20
|
+
- [排障](#排障)
|
|
21
|
+
- [开发](#开发)
|
|
22
|
+
|
|
23
|
+
## 安装
|
|
24
|
+
|
|
25
|
+
要求:DSH **0.2.2-rc.3** 或兼容版本,且已挂载 `ctx.storageDomain`(官方 base bundle 默认以 `storage-domain backend: json` 挂载)。
|
|
31
26
|
|
|
32
27
|
```sh
|
|
33
|
-
#
|
|
34
|
-
dsh plugin --profile
|
|
28
|
+
# 从 npm 安装(已发布 1.0.2)
|
|
29
|
+
dsh plugin --profile <名称> add dsh-background-task-engine
|
|
35
30
|
|
|
36
|
-
#
|
|
37
|
-
dsh plugin --profile
|
|
31
|
+
# 或从本地目录安装
|
|
32
|
+
dsh plugin --profile <名称> add /绝对路径/dsh-background-task-engine
|
|
38
33
|
```
|
|
39
34
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
35
|
+
**用目录方式安装时,请先在该目录执行 `npm install`。** 插件会 `import '@deepseek-ai/schemastery'`,缺少 `node_modules` 时宿主会报
|
|
36
|
+
`ERR_MODULE_NOT_FOUND`。走 registry 规格则自带依赖,不需要本地 checkout。
|
|
37
|
+
|
|
38
|
+
也可以直接在应用内操作:**插件** 页面 → **添加插件** → 粘贴 `dsh-background-task-engine` → 安装 → 启用。
|
|
44
39
|
|
|
45
|
-
|
|
46
|
-
`background-task-engine` is enabled; the row shows this bundle's title,
|
|
47
|
-
description and icon.
|
|
40
|
+
安装后重启应用,在 **插件** 页面确认 `background-task-engine` 一行已启用;该行会显示本包的标题、描述与图标。
|
|
48
41
|
|
|
49
|
-
|
|
50
|
-
it does not change any other setting:
|
|
42
|
+
bundle patch 除插件行外不含任何其他内容,因此安装它不会改动任何别的设置:
|
|
51
43
|
|
|
52
44
|
```yaml
|
|
53
45
|
- insert:
|
|
@@ -56,209 +48,185 @@ it does not change any other setting:
|
|
|
56
48
|
config: { ... }
|
|
57
49
|
```
|
|
58
50
|
|
|
59
|
-
##
|
|
51
|
+
## 工具
|
|
60
52
|
|
|
61
|
-
|
|
62
|
-
`{ success: true, ... }`
|
|
53
|
+
12 个模型可见工具,统一返回
|
|
54
|
+
`{ success: true, ... }` 或 `{ success: false, error: { code, message, retryable, relatedRunId? } }`。
|
|
63
55
|
|
|
64
|
-
|
|
|
56
|
+
| 工具 | 用途 | 关键参数 |
|
|
65
57
|
|---|---|---|
|
|
66
|
-
| `task_create` |
|
|
67
|
-
| `task_list` |
|
|
68
|
-
| `task_get` |
|
|
69
|
-
| `task_update` |
|
|
70
|
-
| `task_archive` |
|
|
71
|
-
| `task_schedule` |
|
|
72
|
-
| `task_run` |
|
|
73
|
-
| `task_run_begin` |
|
|
74
|
-
| `task_step_report` |
|
|
75
|
-
| `task_run_finish` |
|
|
76
|
-
| `task_run_history` |
|
|
77
|
-
| `task_resume` |
|
|
78
|
-
|
|
79
|
-
`task_schedule`
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
Progress is always `floor(completed required steps / required steps × 100)` and is
|
|
101
|
-
recomputed from persisted step rows — never from caller claims.
|
|
102
|
-
|
|
103
|
-
### Scheduled runs
|
|
104
|
-
|
|
105
|
-
A `task_schedule` create stores a prompt carrying `task_id_json` on the host
|
|
106
|
-
schedule. When a delivery arrives:
|
|
58
|
+
| `task_create` | 创建模板(1–10 步) | `title`、`description?`、`steps[]`、`copyFromTaskId?` |
|
|
59
|
+
| `task_list` | 列出本会话的模板 | `status?`、`query?`、`limit?`、`cursor?` |
|
|
60
|
+
| `task_get` | 读取单个模板与最近运行 | `taskId`、`includeRuns?` |
|
|
61
|
+
| `task_update` | 修改标题/描述/步骤/状态 | `taskId`、`expectedRevision`、变更字段 |
|
|
62
|
+
| `task_archive` | 软归档,保留历史 | `taskId`、`expectedRevision` |
|
|
63
|
+
| `task_schedule` | 管理原生定时关联 | `taskId`、`action`、`timing?`、`scheduleRule?` |
|
|
64
|
+
| `task_run` | 立即手动执行 | `taskId`、`manualRunId?`、`defer?` |
|
|
65
|
+
| `task_run_begin` | 认领一次运行(任务 / 排队中的运行 / 投递原文) | `taskId?`、`runId?`、`triggerPayload?`、`scheduleId?`、`occurrenceKey?`、`idempotencyKey?` |
|
|
66
|
+
| `task_step_report` | 上报步骤状态 | `runId`、`stepId`、`action`、`summary?`、`error?` |
|
|
67
|
+
| `task_run_finish` | 提交运行结果 | `runId`、`status`、`summary?`、`error?` |
|
|
68
|
+
| `task_run_history` | 分页查询运行历史 | `taskId`、`status?`、`limit?`、`cursor?` |
|
|
69
|
+
| `task_resume` | 恢复失败/中断/阻塞的运行 | `runId`、`confirmation?` |
|
|
70
|
+
|
|
71
|
+
`task_schedule` 的 action:`create`、`update`、`pause`、`resume`、`delete`、`run_now`、`status`。timing 接受 `at`、`every`、`rrule`、`cron`、`daily`、`weekly`;其中 `daily`/`weekly` 会被转换成等价的 `RRULE`,以减少对宿主 shapes 的依赖。插件只保存 `scheduleId` 与少量引用,绝不复制 Cron 状态。
|
|
72
|
+
|
|
73
|
+
## 执行协议
|
|
74
|
+
|
|
75
|
+
运行由**调用方 Agent 在自己的授权上下文中**执行。没有独立 worker 进程,也不会把
|
|
76
|
+
`followup` 回执当作执行完成。
|
|
77
|
+
|
|
78
|
+
1. `task_run` 或 `task_run_begin` → 取得 `runId`、模板快照与步骤列表。
|
|
79
|
+
2. 按 `order` 顺序对每一步调用 `task_step_report(action:"started")`。
|
|
80
|
+
3. 结束时报告 `task_step_report(action:"completed" | "failed" | "skipped")` 并给出真实摘要;
|
|
81
|
+
`completed` 必须满足该步骤的 `completionCriteria`。
|
|
82
|
+
4. 缺少输入、等待审批或外部条件不满足 → `task_run_finish(status:"blocked", summary:"…")`,并在摘要中写明在等什么。
|
|
83
|
+
5. 全部必需步骤 completed → `task_run_finish(status:"succeeded")`。
|
|
84
|
+
6. 失败 → 先 `task_step_report(action:"failed", error:{…})`,**再**
|
|
85
|
+
`task_run_finish(status:"failed")`。
|
|
86
|
+
|
|
87
|
+
进度恒为 `floor(已完成必需步骤数 / 必需步骤总数 × 100)`,并且始终由已持久化的步骤记录重算——不采信调用方自报。
|
|
88
|
+
|
|
89
|
+
### 定时触发
|
|
90
|
+
|
|
91
|
+
`task_schedule` 创建时会把带 `task_id_json` 的提示词写入宿主定时任务。投递到达后:
|
|
107
92
|
|
|
108
93
|
```text
|
|
109
|
-
task_run_begin({ triggerPayload: "
|
|
94
|
+
task_run_begin({ triggerPayload: "<投递消息原文>" })
|
|
110
95
|
```
|
|
111
96
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
second execution. **Delivery proves the message was enqueued — not that the run
|
|
116
|
-
finished.**
|
|
97
|
+
工具会从中提取 `task_id_json`、`schedule_id_json` 与 `occurrence_at`,并以
|
|
98
|
+
`schedule:<scheduleId>:<occurrence>` 作为幂等键。重复投递会返回已有运行并标记
|
|
99
|
+
`deduplicated: true`,不会重复启动。**投递只证明消息已入队,不代表运行完成。**
|
|
117
100
|
|
|
118
|
-
##
|
|
101
|
+
## 数据模型
|
|
119
102
|
|
|
120
|
-
StorageDomain
|
|
121
|
-
|
|
122
|
-
`/^[a-z][a-z0-9_]*$/`).
|
|
103
|
+
StorageDomain 单元为 `dsh_background_task_engine`,schema 版本 `1`
|
|
104
|
+
(必须用下划线形式:宿主的单元名规则是 `/^[a-z][a-z0-9_]*$/`)。
|
|
123
105
|
|
|
124
|
-
|
|
|
106
|
+
| 表 | 主键 | 内容 |
|
|
125
107
|
|---|---|---|
|
|
126
|
-
| `tasks` | `taskId` |
|
|
127
|
-
| `task_runs` | `runId` |
|
|
128
|
-
| `task_run_steps` | `runId/stepId` |
|
|
129
|
-
| `meta` | `global` | `schemaVersion
|
|
108
|
+
| `tasks` | `taskId` | 模板、状态、revision、所属会话、步骤、定时引用 |
|
|
109
|
+
| `task_runs` | `runId` | 状态、触发来源、快照、进度、时间、摘要/错误、`resumesRunId` |
|
|
110
|
+
| `task_run_steps` | `runId/stepId` | 本次运行的步骤状态、尝试次数、时间、摘要/错误 |
|
|
111
|
+
| `meta` | `global` | `schemaVersion`、迁移台账、恢复/清理时间戳 |
|
|
130
112
|
|
|
131
|
-
|
|
113
|
+
状态机:
|
|
132
114
|
|
|
133
115
|
```text
|
|
134
|
-
Task active → paused → active active/paused → archived
|
|
116
|
+
Task active → paused → active active/paused → archived(终态)
|
|
135
117
|
TaskRun queued → running → succeeded | failed | blocked | interrupted
|
|
136
118
|
queued → skipped
|
|
137
|
-
blocked → failed | interrupted
|
|
119
|
+
blocked → failed | interrupted (绝不回到 running)
|
|
138
120
|
```
|
|
139
121
|
|
|
140
|
-
`failed
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
had side effects requires an explicit `confirmation`.
|
|
122
|
+
`failed`、`succeeded`、`interrupted`、`skipped` 均为终态。恢复总是创建**新的**运行并写入
|
|
123
|
+
`resumesRunId`;已完成步骤会被结转,从第一个未完成步骤继续;若失败步骤可能已产生副作用,
|
|
124
|
+
必须提供显式的 `confirmation`。
|
|
144
125
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
are never pruned.
|
|
126
|
+
保留策略:终态运行及其步骤行超过 `historyRetentionDays`(默认 90 天)后,会在启动时被清理。
|
|
127
|
+
活动运行、任务模板与审计事件永不清理。
|
|
148
128
|
|
|
149
|
-
##
|
|
129
|
+
## 配置
|
|
150
130
|
|
|
151
|
-
|
|
152
|
-
values fail the load rather than being clamped.
|
|
131
|
+
以 `Config`(Schemastery)导出,并在加载时二次校验;越界值会让加载失败,而不是被静默截断。
|
|
153
132
|
|
|
154
|
-
|
|
|
133
|
+
| 配置项 | 默认 | 范围 | 含义 |
|
|
155
134
|
|---|---|---|---|
|
|
156
|
-
| `maxTasksPerOwner` | 100 | 1–1000 |
|
|
157
|
-
| `maxStepsPerTask` | 10 | 1–10 |
|
|
158
|
-
| `maxActiveRunsPerOwner` | 3 | 1–20 |
|
|
159
|
-
| `maxParallelRunsPerTask` | 1 | 1 |
|
|
160
|
-
| `defaultTimeoutMinutes` | 60 | 1–1440 |
|
|
161
|
-
| `staleRunAfterMinutes` | 30 | 1–1440 |
|
|
162
|
-
| `historyRetentionDays` | 90 | 1–3650 |
|
|
163
|
-
| `maxSummaryChars` | 2000 | 100–10000 |
|
|
164
|
-
|
|
165
|
-
##
|
|
166
|
-
|
|
167
|
-
|
|
|
135
|
+
| `maxTasksPerOwner` | 100 | 1–1000 | 每个会话的未归档模板上限 |
|
|
136
|
+
| `maxStepsPerTask` | 10 | 1–10 | 单任务步骤上限(V1.0 为线性) |
|
|
137
|
+
| `maxActiveRunsPerOwner` | 3 | 1–20 | 每个会话并发 queued/running 上限 |
|
|
138
|
+
| `maxParallelRunsPerTask` | 1 | 1 | 同一任务的并行运行数(V1.0 固定) |
|
|
139
|
+
| `defaultTimeoutMinutes` | 60 | 1–1440 | 超时阈值,仅用于识别 |
|
|
140
|
+
| `staleRunAfterMinutes` | 30 | 1–1440 | 启动扫描判定 `interrupted` 的失联时长 |
|
|
141
|
+
| `historyRetentionDays` | 90 | 1–3650 | 终态运行保留天数 |
|
|
142
|
+
| `maxSummaryChars` | 2000 | 100–10000 | 摘要截断上限 |
|
|
143
|
+
|
|
144
|
+
## 错误码
|
|
145
|
+
|
|
146
|
+
| 错误码 | 含义 | 可重试 |
|
|
168
147
|
|---|---|---|
|
|
169
|
-
| `TASK_NOT_FOUND` |
|
|
170
|
-
| `TASK_ALREADY_RUNNING` |
|
|
171
|
-
| `TASK_REVISION_CONFLICT` | `expectedRevision`
|
|
172
|
-
| `TASK_INVALID_STEPS` |
|
|
173
|
-
| `TASK_RUN_NOT_FOUND` |
|
|
174
|
-
| `TASK_RUN_ALREADY_FINISHED` |
|
|
175
|
-
| `TASK_STEP_ORDER_INVALID` |
|
|
176
|
-
| `TASK_PERMISSION_DENIED` |
|
|
177
|
-
| `TASK_SCHEDULE_UNAVAILABLE` | Schedule
|
|
178
|
-
| `TASK_SCHEDULE_FAILED` |
|
|
179
|
-
| `TASK_STORAGE_ERROR` | StorageDomain
|
|
180
|
-
| `TASK_RUN_INTERRUPTED` |
|
|
181
|
-
| `TASK_MAX_CONCURRENCY` |
|
|
182
|
-
| `TASK_INVALID_ARGUMENTS` |
|
|
183
|
-
| `TASK_INTERNAL_ERROR` |
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
`meta.schemaVersion`, and runs any pending migration once each, recording a
|
|
212
|
-
marker **only after** the migration succeeds.
|
|
213
|
-
3. A stored version **higher** than the plugin supports is refused with
|
|
214
|
-
`TASK_STORAGE_ERROR` — downgrading is not silently allowed.
|
|
215
|
-
|
|
216
|
-
v1.0.0 ships an empty migration set (the baseline shape needs none); the runner
|
|
217
|
-
and ledger exist so a future shape change is a data edit plus one entry.
|
|
218
|
-
|
|
219
|
-
## Troubleshooting
|
|
220
|
-
|
|
221
|
-
| Symptom | Cause | Fix |
|
|
148
|
+
| `TASK_NOT_FOUND` | 任务不存在,或不属于当前会话 | 否 |
|
|
149
|
+
| `TASK_ALREADY_RUNNING` | 该任务已有活动运行 | 运行结束后 |
|
|
150
|
+
| `TASK_REVISION_CONFLICT` | `expectedRevision` 已过期 | 重新读取后重试 |
|
|
151
|
+
| `TASK_INVALID_STEPS` | 步骤定义或数量非法 | 修正参数 |
|
|
152
|
+
| `TASK_RUN_NOT_FOUND` | 运行不存在,或不属于当前会话 | 否 |
|
|
153
|
+
| `TASK_RUN_ALREADY_FINISHED` | 运行已进入终态 | 创建新运行 |
|
|
154
|
+
| `TASK_STEP_ORDER_INVALID` | 步骤顺序错误、未知步骤或重复上报 | 修正执行顺序 |
|
|
155
|
+
| `TASK_PERMISSION_DENIED` | 任务已归档/暂停,或缺少恢复确认 | 否 |
|
|
156
|
+
| `TASK_SCHEDULE_UNAVAILABLE` | 未挂载 Schedule | 宿主提供后 |
|
|
157
|
+
| `TASK_SCHEDULE_FAILED` | 宿主定时操作失败 | 核对宿主状态 |
|
|
158
|
+
| `TASK_STORAGE_ERROR` | StorageDomain 缺失、失败或不兼容 | 宿主修复后 |
|
|
159
|
+
| `TASK_RUN_INTERRUPTED` | 执行丢失,已标记中断 | 用 `task_resume` |
|
|
160
|
+
| `TASK_MAX_CONCURRENCY` | 达到该会话的活动运行上限 | 运行结束后 |
|
|
161
|
+
| `TASK_INVALID_ARGUMENTS` | 参数校验失败 | 修正参数 |
|
|
162
|
+
| `TASK_INTERNAL_ERROR` | 未预期的运行时错误 | 否 |
|
|
163
|
+
|
|
164
|
+
前 13 个是 PRD 规定的稳定错误码;后两个为补充码,用来确保意外失败不会被误报成 PRD 错误码。
|
|
165
|
+
|
|
166
|
+
## 安全
|
|
167
|
+
|
|
168
|
+
- **会话隔离。** 每个工具入口都从 `exec.agent.session.id` 解析调用方会话并与记录归属比对。
|
|
169
|
+
属于其他会话的记录一律报 `TASK_NOT_FOUND`,因此该错误无法被用来探测他人的数据。
|
|
170
|
+
- **不提升权限。** 引擎不新增 Shell、文件、浏览器或网络能力;所有动作都走 Agent 已授权的
|
|
171
|
+
工具与既有审批流程。
|
|
172
|
+
- **模板只是数据。** 步骤的 `instruction` 是用户内容,不具更高权限;模板无法改变系统提示、
|
|
173
|
+
权限或工具可用性。外部文本按不可信单行文本渲染。
|
|
174
|
+
- **不泄露。** 错误信息经过净化:丢弃堆栈、把绝对路径替换为 `<path>`、脱敏疑似凭据的赋值。
|
|
175
|
+
- **不可注入代码。** 任务参数无法携带 JavaScript、动态 import 或脚本;插件内不存在任何求值器。
|
|
176
|
+
- 定时任务绑定创建时的会话,因此到期执行发生在拥有该任务的会话内。
|
|
177
|
+
|
|
178
|
+
## 升级
|
|
179
|
+
|
|
180
|
+
1. 升级 bundle;插件行会保留其配置。
|
|
181
|
+
2. 下次启动时,引擎打开 domain、比对已存 `meta.schemaVersion`,并逐条执行尚未应用的迁移,
|
|
182
|
+
**只有迁移成功后**才写入台账标记。
|
|
183
|
+
3. 若已存版本**高于**插件支持的版本,直接以 `TASK_STORAGE_ERROR` 拒绝——不允许静默降级。
|
|
184
|
+
|
|
185
|
+
v1.0.0 起附带空迁移集(基线结构无需迁移);运行器与台账已就位,未来结构变更只需新增一条迁移。
|
|
186
|
+
|
|
187
|
+
## 排障
|
|
188
|
+
|
|
189
|
+
| 现象 | 原因 | 处理 |
|
|
222
190
|
|---|---|---|
|
|
223
|
-
|
|
|
224
|
-
| `invalid unit name '…'` |
|
|
225
|
-
| `TASK_SCHEDULE_UNAVAILABLE` | `ctx.schedule`
|
|
226
|
-
|
|
|
227
|
-
| `TASK_REVISION_CONFLICT` |
|
|
228
|
-
|
|
|
229
|
-
|
|
|
191
|
+
| 所有工具都报 `TASK_STORAGE_ERROR` 并提到 `ctx.storageDomain` | Host 未挂载 StorageDomain | 在 profile 中启用 `storage` + `storage-json` + `storage-domain` |
|
|
192
|
+
| `invalid unit name '…'` | domain/表名里含连字符 | 单元名必须匹配 `/^[a-z][a-z0-9_]*$/`(本插件用 `dsh_background_task_engine`) |
|
|
193
|
+
| `TASK_SCHEDULE_UNAVAILABLE` | 未挂载 `ctx.schedule` | 定时是可选能力,手动执行不受影响 |
|
|
194
|
+
| 插件行未激活:*cannot get property "…" without inject* | 以属性方式读取了可选服务 | 可选服务应通过 `ctx.get` 解析 |
|
|
195
|
+
| `TASK_REVISION_CONFLICT` | 两次修改竞争 | 先 `task_get`,再用最新 `revision` 重试 |
|
|
196
|
+
| 重启后运行变成 `interrupted` | 宿主中途停止,且不会自动重启 | 若某步骤可能有副作用,带 `confirmation` 调用 `task_resume` |
|
|
197
|
+
| 安装被拒:*dsh.bundle.patch must be a file path* | 清单用了扁平写法 | 改用 `"dsh": { "bundle": { "patch": "./cordis.patch.yml" } }` |
|
|
230
198
|
|
|
231
|
-
##
|
|
199
|
+
## 开发
|
|
232
200
|
|
|
233
201
|
```sh
|
|
234
202
|
npm install
|
|
235
203
|
npm run build # tsc -> dist/
|
|
236
204
|
npm run typecheck
|
|
237
|
-
npm test # 81
|
|
205
|
+
npm test # 81 个用例
|
|
238
206
|
```
|
|
239
207
|
|
|
240
|
-
|
|
208
|
+
目录结构:
|
|
241
209
|
|
|
242
210
|
```text
|
|
243
211
|
src/
|
|
244
|
-
index.ts
|
|
245
|
-
host.ts
|
|
212
|
+
index.ts 插件入口:name / inject / Config / apply
|
|
213
|
+
host.ts 结构化宿主契约(不 import 宿主包)
|
|
246
214
|
config.ts Schemastery Config + resolveConfig
|
|
247
|
-
errors.ts
|
|
248
|
-
domain/records.ts zod
|
|
249
|
-
domain/state.ts TaskRun/StepRun
|
|
250
|
-
storage/spec.ts domain
|
|
251
|
-
storage/repository.ts
|
|
252
|
-
services/
|
|
253
|
-
tools/ 12
|
|
254
|
-
prompt/guidance.ts
|
|
255
|
-
tests/ domain
|
|
256
|
-
docs/
|
|
215
|
+
errors.ts 稳定错误码、错误载荷、消息净化
|
|
216
|
+
domain/records.ts zod 记录 schema
|
|
217
|
+
domain/state.ts TaskRun/StepRun 状态机、进度、顺序守卫
|
|
218
|
+
storage/spec.ts domain 声明、迁移、完整性校验
|
|
219
|
+
storage/repository.ts 唯一读写 domain 表的地方
|
|
220
|
+
services/ 审计、任务、运行、定时适配、引擎
|
|
221
|
+
tools/ 12 个工具定义与共用管道
|
|
222
|
+
prompt/guidance.ts 执行协议与投递解析
|
|
223
|
+
tests/ domain、storage、渲染、集成(含假件)
|
|
224
|
+
docs/ 宿主能力审计、测试报告、详情页
|
|
257
225
|
```
|
|
258
226
|
|
|
259
|
-
|
|
260
|
-
|
|
227
|
+
验证记录:`docs/API-COMPATIBILITY-AUDIT.md`(宿主能力审计,含真实宿主栈运行)与
|
|
228
|
+
`docs/TEST-REPORT.md`(全部 81 条断言)。
|
|
261
229
|
|
|
262
|
-
##
|
|
230
|
+
## 许可证
|
|
263
231
|
|
|
264
|
-
MIT
|
|
232
|
+
MIT,见 [LICENSE](LICENSE)。
|
package/docs/TEST-REPORT.md
CHANGED
|
@@ -133,6 +133,24 @@ Practical consequence: run `npm install` in the package directory before
|
|
|
133
133
|
registry spec (`dsh-background-task-engine@1.0.0`) once published — it carries its
|
|
134
134
|
own `node_modules` and does not depend on the checkout.
|
|
135
135
|
|
|
136
|
+
## 1.0.2 (README language) verification
|
|
137
|
+
|
|
138
|
+
Documentation-only release; code is unchanged from 1.0.0/1.0.1.
|
|
139
|
+
|
|
140
|
+
| Check | Result |
|
|
141
|
+
|---|---|
|
|
142
|
+
| `README.md` default language | Chinese |
|
|
143
|
+
| English document | `README.en.md`, with a language switch in both files |
|
|
144
|
+
| Heading anchors in the Chinese table of contents | all 10 resolve to real headings |
|
|
145
|
+
| Code fences | 12 per file, balanced |
|
|
146
|
+
| File links (`LICENSE`, `docs/*`, `README.en.md`) | all exist |
|
|
147
|
+
| `package.json` `description` | Chinese, matches the README |
|
|
148
|
+
| `files` list | `README.en.md` replaces the removed `README.zh.md` |
|
|
149
|
+
| `npm pack` contents | both `README.md` (12.5 kB) and `README.en.md` (12.8 kB) present |
|
|
150
|
+
| Published `1.0.2` installed from registry | `README.md` inside the package is Chinese; `description` Chinese |
|
|
151
|
+
| Build + tests | BUILD OK, 81/81 |
|
|
152
|
+
| Profile install of `1.0.2` | `application: applied`, 12/12 tools |
|
|
153
|
+
|
|
136
154
|
## Test inventory
|
|
137
155
|
|
|
138
156
|
Every assertion from the last full run is listed below.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-background-task-engine",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.0.3",
|
|
4
|
+
"description": "DSH 后台任务引擎:可复用任务模板、线性步骤、持久化运行账本、进度与历史查询、失败/中断恢复,可选关联 DSH 原生定时任务。",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"deepseek-harness",
|
|
7
7
|
"dsh",
|
|
@@ -30,8 +30,9 @@
|
|
|
30
30
|
"locale/*.json",
|
|
31
31
|
"docs",
|
|
32
32
|
"icon.svg",
|
|
33
|
+
"screenshots.json",
|
|
33
34
|
"README.md",
|
|
34
|
-
"README.
|
|
35
|
+
"README.en.md",
|
|
35
36
|
"CHANGELOG.md",
|
|
36
37
|
"LICENSE"
|
|
37
38
|
],
|
|
@@ -51,13 +52,13 @@
|
|
|
51
52
|
}
|
|
52
53
|
},
|
|
53
54
|
"dependencies": {
|
|
54
|
-
"@deepseek-ai/schemastery": "^3.18.5",
|
|
55
55
|
"zod": "^3.25.76"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@types/node": "^22.10.2",
|
|
59
59
|
"typescript": "^5.7.2",
|
|
60
|
-
"vitest": "^2.1.8"
|
|
60
|
+
"vitest": "^2.1.8",
|
|
61
|
+
"@deepseek-ai/schemastery": "^3.18.5"
|
|
61
62
|
},
|
|
62
63
|
"engines": {
|
|
63
64
|
"node": ">=20"
|
|
@@ -69,5 +70,8 @@
|
|
|
69
70
|
"test": "vitest run",
|
|
70
71
|
"test:watch": "vitest",
|
|
71
72
|
"prepublishOnly": "npm run clean && npm run build"
|
|
73
|
+
},
|
|
74
|
+
"peerDependencies": {
|
|
75
|
+
"@deepseek-ai/schemastery": "^3.18.5"
|
|
72
76
|
}
|
|
73
77
|
}
|
package/README.zh.md
DELETED
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
# dsh-background-task-engine
|
|
2
|
-
|
|
3
|
-
DeepSeek Harness 的**后台任务引擎**:可复用的任务模板、有序线性步骤、单次运行账本、进度与历史查询、失败/中断后的人工恢复,以及可选的 DSH 原生定时关联。
|
|
4
|
-
|
|
5
|
-
它不实现调度器、Agent Loop、作业注册表或存储后端,而是复用 Host 自身的 `ctx.schedule`、`ctx.storageDomain` 与 `ctx.tools`。
|
|
6
|
-
|
|
7
|
-
- [安装](#安装)
|
|
8
|
-
- [工具](#工具)
|
|
9
|
-
- [执行协议](#执行协议)
|
|
10
|
-
- [数据模型](#数据模型)
|
|
11
|
-
- [配置](#配置)
|
|
12
|
-
- [错误码](#错误码)
|
|
13
|
-
- [安全](#安全)
|
|
14
|
-
- [升级](#升级)
|
|
15
|
-
- [排障](#排障)
|
|
16
|
-
- [开发](#开发)
|
|
17
|
-
|
|
18
|
-
## 安装
|
|
19
|
-
|
|
20
|
-
要求:DSH **0.2.2-rc.3** 或兼容版本,且已挂载 `ctx.storageDomain`(官方 base bundle 默认以 `storage-domain backend: json` 挂载)。
|
|
21
|
-
|
|
22
|
-
```sh
|
|
23
|
-
# 本地目录
|
|
24
|
-
dsh plugin --profile <名称> add /绝对路径/dsh-background-task-engine
|
|
25
|
-
|
|
26
|
-
# 或从 npm
|
|
27
|
-
dsh plugin --profile <名称> add dsh-background-task-engine
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
重启应用后,在 **插件** 页面确认 `background-task-engine` 一行已启用,并显示本包的标题、描述与图标。
|
|
31
|
-
|
|
32
|
-
## 工具
|
|
33
|
-
|
|
34
|
-
12 个模型可见工具,统一返回 `{ success: true, ... }` 或 `{ success: false, error: { code, message, retryable, relatedRunId? } }`。
|
|
35
|
-
|
|
36
|
-
| 工具 | 用途 | 关键参数 |
|
|
37
|
-
|---|---|---|
|
|
38
|
-
| `task_create` | 创建模板(1–10 步) | `title`、`description?`、`steps[]`、`copyFromTaskId?` |
|
|
39
|
-
| `task_list` | 列出本会话模板 | `status?`、`query?`、`limit?`、`cursor?` |
|
|
40
|
-
| `task_get` | 查看模板与最近运行 | `taskId`、`includeRuns?` |
|
|
41
|
-
| `task_update` | 修改标题/描述/步骤/状态 | `taskId`、`expectedRevision`、变更字段 |
|
|
42
|
-
| `task_archive` | 软归档,保留历史 | `taskId`、`expectedRevision` |
|
|
43
|
-
| `task_schedule` | 管理原生定时关联 | `taskId`、`action`、`timing?`、`scheduleRule?` |
|
|
44
|
-
| `task_run` | 立即手动执行 | `taskId`、`manualRunId?`、`defer?` |
|
|
45
|
-
| `task_run_begin` | 认领一次运行 | `taskId?`、`runId?`、`triggerPayload?`、`scheduleId?`、`occurrenceKey?`、`idempotencyKey?` |
|
|
46
|
-
| `task_step_report` | 上报步骤 | `runId`、`stepId`、`action`、`summary?`、`error?` |
|
|
47
|
-
| `task_run_finish` | 提交运行结果 | `runId`、`status`、`summary?`、`error?` |
|
|
48
|
-
| `task_run_history` | 分页查询运行历史 | `taskId`、`status?`、`limit?`、`cursor?` |
|
|
49
|
-
| `task_resume` | 恢复失败/中断/阻塞运行 | `runId`、`confirmation?` |
|
|
50
|
-
|
|
51
|
-
`task_schedule` 的 action:`create`、`update`、`pause`、`resume`、`delete`、`run_now`、`status`。timing 支持 `at`、`every`、`rrule`、`cron`、`daily`、`weekly`;其中 `daily`/`weekly` 会转换成等价的 `RRULE`,以减少对宿主 shapes 的依赖。插件只保存 `scheduleId` 与少量引用,不复制任何 Cron 状态。
|
|
52
|
-
|
|
53
|
-
## 执行协议
|
|
54
|
-
|
|
55
|
-
运行由**调用方 Agent 在自己的授权上下文中**执行,没有独立 worker 进程,也不会把 followup 回执当作完成凭证。
|
|
56
|
-
|
|
57
|
-
1. `task_run` 或 `task_run_begin` → 取得 `runId`、模板快照与步骤列表。
|
|
58
|
-
2. 按 `order` 顺序对每一步调用 `task_step_report(action:"started")`。
|
|
59
|
-
3. 结束时报告 `completed` / `failed` / `skipped` 并给出真实摘要;`completed` 必须满足该步骤的 `completionCriteria`。
|
|
60
|
-
4. 缺少输入、等待审批或外部条件不满足 → `task_run_finish(status:"blocked", summary:"…")`,说明在等什么。
|
|
61
|
-
5. 全部必需步骤 completed → `task_run_finish(status:"succeeded")`。
|
|
62
|
-
6. 失败 → 先 `task_step_report(action:"failed", error:{…})`,再 `task_run_finish(status:"failed")`。
|
|
63
|
-
|
|
64
|
-
进度恒为 `floor(已完成必需步骤数 / 必需步骤总数 × 100)`,且始终由已持久化的步骤记录重算,不采信调用方自报。
|
|
65
|
-
|
|
66
|
-
### 定时触发
|
|
67
|
-
|
|
68
|
-
`task_schedule` 创建时会把带 `task_id_json` 的提示词写入宿主定时任务。投递到达后:
|
|
69
|
-
|
|
70
|
-
```text
|
|
71
|
-
task_run_begin({ triggerPayload: "<投递消息原文>" })
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
工具会从中提取 `task_id_json`、`schedule_id_json` 与 `occurrence_at`,并以 `schedule:<scheduleId>:<occurrence>` 作为幂等键。重复投递返回已有运行并标记 `deduplicated: true`,不会重复启动。**投递只证明消息入队,不代表运行完成。**
|
|
75
|
-
|
|
76
|
-
## 数据模型
|
|
77
|
-
|
|
78
|
-
StorageDomain 单元 `dsh_background_task_engine`,schema 版本 `1`(必须使用下划线形式:宿主的单元名规则是 `/^[a-z][a-z0-9_]*$/`)。
|
|
79
|
-
|
|
80
|
-
| 表 | 主键 | 内容 |
|
|
81
|
-
|---|---|---|
|
|
82
|
-
| `tasks` | `taskId` | 模板、状态、revision、所属会话、步骤、定时引用 |
|
|
83
|
-
| `task_runs` | `runId` | 状态、触发来源、快照、进度、时间、摘要/错误、`resumesRunId` |
|
|
84
|
-
| `task_run_steps` | `runId/stepId` | 本次运行的步骤状态、尝试次数、时间、摘要/错误 |
|
|
85
|
-
| `meta` | `global` | `schemaVersion`、迁移台账、恢复/清理时间 |
|
|
86
|
-
|
|
87
|
-
状态机:
|
|
88
|
-
|
|
89
|
-
```text
|
|
90
|
-
Task active → paused → active active/paused → archived(终态)
|
|
91
|
-
TaskRun queued → running → succeeded | failed | blocked | interrupted
|
|
92
|
-
queued → skipped
|
|
93
|
-
blocked → failed | interrupted (绝不回到 running)
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
`succeeded`、`failed`、`interrupted`、`skipped` 为终态。恢复总是创建**新的**运行并写 `resumesRunId`;已完成步骤被结转,从第一个未完成步骤继续;若失败步骤可能已产生副作用,必须提供 `confirmation`。
|
|
97
|
-
|
|
98
|
-
保留策略:超过 `historyRetentionDays`(默认 90 天)的终态运行及其步骤行会在启动时清理。活动运行、任务模板与审计事件永不清理。
|
|
99
|
-
|
|
100
|
-
## 配置
|
|
101
|
-
|
|
102
|
-
以 `Config`(Schemastery)导出,加载时二次校验;越界值会使加载失败而不是被静默截断。
|
|
103
|
-
|
|
104
|
-
| 配置项 | 默认 | 范围 | 含义 |
|
|
105
|
-
|---|---|---|---|
|
|
106
|
-
| `maxTasksPerOwner` | 100 | 1–1000 | 每个会话未归档模板上限 |
|
|
107
|
-
| `maxStepsPerTask` | 10 | 1–10 | 单任务步骤上限(V1.0 为线性) |
|
|
108
|
-
| `maxActiveRunsPerOwner` | 3 | 1–20 | 每个会话并发 queued/running 上限 |
|
|
109
|
-
| `maxParallelRunsPerTask` | 1 | 1 | 同一任务并行运行数(V1.0 固定) |
|
|
110
|
-
| `defaultTimeoutMinutes` | 60 | 1–1440 | 超时识别阈值(仅用于识别) |
|
|
111
|
-
| `staleRunAfterMinutes` | 30 | 1–1440 | 启动扫描判定 `interrupted` 的失联时长 |
|
|
112
|
-
| `historyRetentionDays` | 90 | 1–3650 | 终态运行保留天数 |
|
|
113
|
-
| `maxSummaryChars` | 2000 | 100–10000 | 摘要截断上限 |
|
|
114
|
-
|
|
115
|
-
## 错误码
|
|
116
|
-
|
|
117
|
-
| 错误码 | 含义 | 可重试 |
|
|
118
|
-
|---|---|---|
|
|
119
|
-
| `TASK_NOT_FOUND` | 任务不存在或不属于当前会话 | 否 |
|
|
120
|
-
| `TASK_ALREADY_RUNNING` | 已有活动运行 | 运行结束后 |
|
|
121
|
-
| `TASK_REVISION_CONFLICT` | `expectedRevision` 已过期 | 重新读取后重试 |
|
|
122
|
-
| `TASK_INVALID_STEPS` | 步骤定义或数量非法 | 修正参数 |
|
|
123
|
-
| `TASK_RUN_NOT_FOUND` | 运行不存在或不属于当前会话 | 否 |
|
|
124
|
-
| `TASK_RUN_ALREADY_FINISHED` | 运行已终态 | 创建新运行 |
|
|
125
|
-
| `TASK_STEP_ORDER_INVALID` | 顺序错误、未知步骤或重复上报 | 修正顺序 |
|
|
126
|
-
| `TASK_PERMISSION_DENIED` | 任务已归档/暂停,或缺少恢复确认 | 否 |
|
|
127
|
-
| `TASK_SCHEDULE_UNAVAILABLE` | Schedule 未挂载 | 宿主提供后 |
|
|
128
|
-
| `TASK_SCHEDULE_FAILED` | 宿主定时操作失败 | 核对宿主状态 |
|
|
129
|
-
| `TASK_STORAGE_ERROR` | StorageDomain 缺失、失败或不兼容 | 宿主修复后 |
|
|
130
|
-
| `TASK_RUN_INTERRUPTED` | 执行丢失,已标记中断 | 用 `task_resume` |
|
|
131
|
-
| `TASK_MAX_CONCURRENCY` | 达到会话并发上限 | 运行结束后 |
|
|
132
|
-
| `TASK_INVALID_ARGUMENTS` | 参数校验失败 | 修正参数 |
|
|
133
|
-
| `TASK_INTERNAL_ERROR` | 未预期的运行时错误 | 否 |
|
|
134
|
-
|
|
135
|
-
前 13 个是 PRD 稳定错误码;后两个为补充,确保意外失败不会被误报成 PRD 错误码。
|
|
136
|
-
|
|
137
|
-
## 安全
|
|
138
|
-
|
|
139
|
-
- **会话隔离**:每个工具入口都从 `exec.agent.session.id` 解析调用方并与记录归属比对;他人会话的记录一律报 `TASK_NOT_FOUND`,避免被用来探测。
|
|
140
|
-
- **不提升权限**:插件不新增 Shell、文件、浏览器或网络能力;所有动作沿用 Agent 已授权的工具与既有审批流程。
|
|
141
|
-
- **模板是数据**:步骤 `instruction` 是用户内容,不具更高权限;模板无法改变系统提示、权限或工具可用性。外部文本按不可信单行文本渲染。
|
|
142
|
-
- **不泄露**:错误信息经净化处理——丢弃堆栈、把绝对路径替换为 `<path>`、脱敏疑似凭据。
|
|
143
|
-
- **不可注入代码**:任务参数不能携带 JavaScript、动态 import 或脚本,插件内不存在任何求值器。
|
|
144
|
-
- 定时任务绑定创建时的会话,因此到期执行发生在拥有该任务的会话内。
|
|
145
|
-
|
|
146
|
-
## 升级
|
|
147
|
-
|
|
148
|
-
1. 升级 bundle,插件行保留其 provenance 与配置。
|
|
149
|
-
2. 下次启动时引擎打开 domain、比对 `meta.schemaVersion`,逐条执行尚未应用的迁移;每条迁移**成功之后**才写入台账标记。
|
|
150
|
-
3. 若存储版本**高于**插件支持版本,直接以 `TASK_STORAGE_ERROR` 拒绝——不允许静默降级。
|
|
151
|
-
|
|
152
|
-
v1.0.0 附带空迁移集(基线结构无需迁移),但运行器与台账已就位,未来结构变更只需新增一条迁移。
|
|
153
|
-
|
|
154
|
-
## 排障
|
|
155
|
-
|
|
156
|
-
| 现象 | 原因 | 处理 |
|
|
157
|
-
|---|---|---|
|
|
158
|
-
| 所有工具报 `TASK_STORAGE_ERROR`(提到 `ctx.storageDomain`) | Host 未挂载 StorageDomain | 在 profile 中启用 `storage` + `storage-json` + `storage-domain` |
|
|
159
|
-
| `invalid unit name '…'` | domain/表名含连字符 | 单元名必须匹配 `/^[a-z][a-z0-9_]*$/`(本插件用 `dsh_background_task_engine`) |
|
|
160
|
-
| `TASK_SCHEDULE_UNAVAILABLE` | 未挂载 `ctx.schedule` | 定时是可选项,手动执行不受影响 |
|
|
161
|
-
| 插件行未激活:*cannot get property "…" without inject* | 以属性方式读取可选服务 | 可选服务应通过 `ctx.get` 获取 |
|
|
162
|
-
| `TASK_REVISION_CONFLICT` | 两次修改竞争 | 先 `task_get` 取最新 `revision` 再改 |
|
|
163
|
-
| 重启后运行变成 `interrupted` | Host 中途停止,且不会自动重启 | 若失败步骤可能有副作用,带 `confirmation` 调用 `task_resume` |
|
|
164
|
-
| 安装被拒:*dsh.bundle.patch must be a file path* | 清单用了扁平写法 | 使用 `"dsh": { "bundle": { "patch": "./cordis.patch.yml" } }` |
|
|
165
|
-
|
|
166
|
-
## 开发
|
|
167
|
-
|
|
168
|
-
```sh
|
|
169
|
-
npm install
|
|
170
|
-
npm run build # tsc -> dist/
|
|
171
|
-
npm run typecheck
|
|
172
|
-
npm test # 81 个用例
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
目录结构与验证记录见英文 README;宿主能力审计见 `docs/API-COMPATIBILITY-AUDIT.md`,全部 81 条断言见 `docs/TEST-REPORT.md`。
|
|
176
|
-
|
|
177
|
-
## 许可证
|
|
178
|
-
|
|
179
|
-
MIT,见 [LICENSE](LICENSE)。
|