dsh-background-task-engine 0.0.0-stage → 1.0.1

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.
Files changed (58) hide show
  1. package/CHANGELOG.md +91 -0
  2. package/LICENSE +21 -0
  3. package/README.md +263 -2
  4. package/README.zh.md +179 -0
  5. package/cordis.patch.yml +20 -0
  6. package/dist/config.d.ts +86 -0
  7. package/dist/config.js +106 -0
  8. package/dist/domain/records.d.ts +543 -0
  9. package/dist/domain/records.js +135 -0
  10. package/dist/domain/state.d.ts +61 -0
  11. package/dist/domain/state.js +128 -0
  12. package/dist/errors.d.ts +38 -0
  13. package/dist/errors.js +99 -0
  14. package/dist/host.d.ts +165 -0
  15. package/dist/host.js +56 -0
  16. package/dist/index.d.ts +60 -0
  17. package/dist/index.js +78 -0
  18. package/dist/prompt/guidance.d.ts +30 -0
  19. package/dist/prompt/guidance.js +62 -0
  20. package/dist/services/audit.d.ts +39 -0
  21. package/dist/services/audit.js +48 -0
  22. package/dist/services/engine.d.ts +435 -0
  23. package/dist/services/engine.js +150 -0
  24. package/dist/services/run-service.d.ts +145 -0
  25. package/dist/services/run-service.js +569 -0
  26. package/dist/services/schedule-adapter.d.ts +92 -0
  27. package/dist/services/schedule-adapter.js +220 -0
  28. package/dist/services/task-service.d.ts +146 -0
  29. package/dist/services/task-service.js +490 -0
  30. package/dist/storage/repository.d.ts +65 -0
  31. package/dist/storage/repository.js +194 -0
  32. package/dist/storage/spec.d.ts +97 -0
  33. package/dist/storage/spec.js +149 -0
  34. package/dist/tools/run-tools.d.ts +14 -0
  35. package/dist/tools/run-tools.js +402 -0
  36. package/dist/tools/schedule-tool.d.ts +11 -0
  37. package/dist/tools/schedule-tool.js +238 -0
  38. package/dist/tools/shared.d.ts +108 -0
  39. package/dist/tools/shared.js +278 -0
  40. package/dist/tools/task-tools.d.ts +7 -0
  41. package/dist/tools/task-tools.js +321 -0
  42. package/dist/utils/id.d.ts +8 -0
  43. package/dist/utils/id.js +29 -0
  44. package/dist/utils/page.d.ts +36 -0
  45. package/dist/utils/page.js +71 -0
  46. package/dist/utils/text.d.ts +20 -0
  47. package/dist/utils/text.js +46 -0
  48. package/dist/utils/time.d.ts +7 -0
  49. package/dist/utils/time.js +38 -0
  50. package/docs/API-COMPATIBILITY-AUDIT.md +203 -0
  51. package/docs/DETAIL.md +1 -0
  52. package/docs/DETAIL.zh.md +1 -0
  53. package/docs/TEST-REPORT.md +232 -0
  54. package/docs/preview.svg +68 -0
  55. package/icon.svg +23 -0
  56. package/locale/en.json +7 -0
  57. package/locale/zh.json +7 -0
  58. package/package.json +71 -4
@@ -0,0 +1,203 @@
1
+ # API Compatibility Audit
2
+
3
+ Deliverable for PRD chapter 3 and 16.1. Everything below was verified against the
4
+ **installed** DeepSeek Harness on this machine, not against `master` docs.
5
+
6
+ ## 1. Host versions
7
+
8
+ | Component | Value | How verified |
9
+ |---|---|---|
10
+ | DSH distribution | Desktop app | `DSH_PROFILE=desktop`, install dir inside `app.asar` |
11
+ | `@deepseek-ai/dsh` | **0.2.2-rc.3** | `DSH_INSTALL_DIR/package.json` |
12
+ | `@deepseek-ai/cordis` | **~4.1.0** | dependency of the above |
13
+ | `@deepseek-ai/schemastery` | 3.18.5 (resolved) | profile `node_modules`, `Schema` is the **default export** |
14
+ | `zod` | 3.x (profile-resolved) | profile `node_modules` |
15
+ | Profile | `~/.dsh/profiles/desktop` | `$DSH_PROFILE_DIR` |
16
+
17
+ ## 2. Module resolution constraint (decisive)
18
+
19
+ The plugin is loaded from the profile, where the host's own packages are **not**
20
+ resolvable:
21
+
22
+ ```console
23
+ $ cd "$DSH_PROFILE_DIR" && node -e "require.resolve('@deepseek-ai/dsh-tools')"
24
+ Error: Cannot find module '@deepseek-ai/dsh-tools' # code MODULE_NOT_FOUND
25
+ $ node -e "require.resolve('zod')" # ok
26
+ $ node -e "require.resolve('@deepseek-ai/schemastery')" # ok
27
+ ```
28
+
29
+ Installed third-party plugins show the same pattern: across `dsh-mnemon`,
30
+ `dsh-context`, `dsh-better-sidebar` and `dshmarket`, the only host import is
31
+ `@deepseek-ai/schemastery`.
32
+
33
+ **Consequence.** The plugin cannot `import { defineTool } from
34
+ '@deepseek-ai/dsh-tools'` the way first-party packages do. It therefore:
35
+
36
+ - declares the host contract **structurally** in `src/host.ts` (interfaces only),
37
+ - builds plain tool-definition objects matching `ToolDefinition`,
38
+ - constructs the domain spec as a plain object (the facility accepts it),
39
+ - imports only `zod` and `@deepseek-ai/schemastery` at runtime.
40
+
41
+ This is a public-shape dependency, not a private-path dependency: every shape
42
+ below is a documented export, and all of them were exercised against the real
43
+ packages (§6).
44
+
45
+ ## 3. `ctx.storageDomain` — required
46
+
47
+ Source: `@deepseek-ai/dsh-storage-domain/src/{index,spec,domain}.ts`.
48
+
49
+ | Fact | Detail |
50
+ |---|---|
51
+ | Service | `ctx.storageDomain: DomainFacility`, provided by the `storage-domain` plugin with `inject: ['storage']` |
52
+ | Open | `await ctx.storageDomain.open(spec)` → `Domain`; the caller owns `domain.close()` |
53
+ | Spec | `{ name, version, layout?, compatibleVersions?, invalidRecords?, global?, tables: {name: {valueSchema}} }` — record schemas are **zod** |
54
+ | Reads | `table.get(key)`, `table.entries()`, `table.keys()`, `table.size` — **synchronous**, from memory |
55
+ | Writes | `put`, `delete`, `deleteMany`, `update(key, fn)`, all `Promise`-returning, durable before resolve |
56
+ | Atomic RMW | `update`'s mutator runs inside the domain's per-key write chain |
57
+ | Missing key | `update` on an absent key rejects with `missing-key` |
58
+ | Records | shared immutables — never mutate in place |
59
+ | Validation | `valueSchema.parse` runs **only at open** (per record); writes are not re-validated |
60
+
61
+ **`UNIT_NAME_RE` is `/^[a-z][a-z0-9_]*$/`** (`dsh-storage/src/backend.ts:10`).
62
+
63
+ > This was the one finding that only a real host uncovered: with the domain named
64
+ > `dsh-background-task-engine`, `open()` failed with
65
+ > `invalid unit name 'dsh-background-task-engine'`. The storage unit is now
66
+ > `dsh_background_task_engine` (underscores), which is deliberately different from
67
+ > the npm package name (hyphens). `createDomainSpec()` is asserted against
68
+ > `UNIT_NAME_PATTERN` in tests, and the engine re-checks every unit/table name
69
+ > before opening.
70
+
71
+ Backend routing on this profile: the base bundle configures `storage-domain` with
72
+ `backend: json`, so records land in `<DSH_HOME>/storages/<unit>.json`. The plugin
73
+ never names a backend and never touches a file.
74
+
75
+ ## 4. `ctx.schedule` — optional
76
+
77
+ Source: `@deepseek-ai/dsh-schedule/src/{index,types}.ts`.
78
+
79
+ | Fact | Detail |
80
+ |---|---|
81
+ | Service | `ctx.schedule: ScheduleService` (`static inject = ['agents','sessions','storageDomain','sessionPersistence']`) |
82
+ | Create | `create({ title, prompt, timing, target? }, actorSessionId?, signal?)` → `ScheduleCatalogEntry` |
83
+ | Edit | `edit({ id, action:'update', patch:{title?,prompt?,timing?,target?,active?}, expectedUpdatedAt? })` |
84
+ | Delete | `edit({ id, action:'delete' })` → `{deleted:true}` or `{code:'schedule_not_found'}` |
85
+ | View / Run | `view({id})`, `run({id})` |
86
+ | Timing kinds | `at` / `after` / `every` / `daily` / `weekly` / `cron` / `rrule` |
87
+ | Targets | `session` / `new_once` / `new` |
88
+ | Delivery text | one-shot: `[SCHEDULE REMINDER]` + `schedule_id_json`, `occurrence_at`, `reminder_prompt_json`; batch: `[SCHEDULE REMINDER BATCH]` + `reminders_json[]` |
89
+ | Delivery ≠ completion | acknowledgements prove inbox persistence only |
90
+
91
+ **Optional-service hazard.** Cordis only exposes an injected service as a context
92
+ property. Reading `ctx.schedule` without listing it in `inject` throws
93
+ `cannot get property "schedule" without inject` — which made the first install
94
+ report `1 entry did not activate`.
95
+
96
+ The plugin therefore declares `inject: ['tools', 'storageDomain']` (both
97
+ mandatory) and resolves Schedule through `optionalService(ctx, 'schedule')`, which
98
+ tries `ctx.get('schedule')` and treats absence as "not mounted". PRD FR-012 is
99
+ honoured: manual runs work, `task_schedule` reports
100
+ `TASK_SCHEDULE_UNAVAILABLE`. Tests reproduce the throwing-property behaviour.
101
+
102
+ ## 5. `ctx.tools` — required
103
+
104
+ Source: `@deepseek-ai/dsh-tools/src/{index,contracts,schema,json-schema}.ts`.
105
+
106
+ | Fact | Detail |
107
+ |---|---|
108
+ | Service | `ctx.tools: ToolsService` (`static inject = ['systemPrompt']`) |
109
+ | Register | `register(definition, options?)` → disposer; registrations die with the scope |
110
+ | Definition | `{ name, description, parameters, output:{schema, render(args,value)}, execute(args,exec) }` |
111
+ | Required at register | `output` exists, `output.render` is a function, `output.schema` passes `assertSupportedJsonSchema` |
112
+ | Output check | `validateJsonSchemaValue(tool.output.schema, value)` then `tool.output.render(...)` |
113
+ | `exec` | carries `agent` (`agent.session.id` = SessionId), `signal`, `callId` |
114
+ | `ToolSchema.parameters` | `Record<string, unknown>` — plain JSON Schema |
115
+
116
+ **Supported JSON Schema subset** (anything else throws at registration):
117
+
118
+ `type` (object/array/string/number/integer/boolean/null), `oneOf`, `properties`,
119
+ `required`, `additionalProperties`, `items`, `enum`, `const`, `description`,
120
+ `title`, `default`, `examples`.
121
+
122
+ `minLength`, `pattern`, `maximum`, `format`, `minimum`, `maxItems` are **not**
123
+ supported — all length/range/count limits are enforced in code (zod + service
124
+ guards) instead.
125
+
126
+ **Verified against the real validator**, not our own copy:
127
+
128
+ ```console
129
+ $ ELECTRON_RUN_AS_NODE=1 "$DSH_NODE_EXECUTABLE" /tmp/verify-host-contract.mjs
130
+ registered: 12
131
+ schema-valid: 12/12
132
+ ```
133
+
134
+ ## 6. Real-host integration run
135
+
136
+ Both scripts boot the **actual** host packages
137
+ (`cordis` + `dsh-storage` + `dsh-storage-json` + `dsh-storage-domain` +
138
+ `dsh-system-prompt` + `dsh-tools`) out of the installed `app.asar` and mount this
139
+ plugin into them.
140
+
141
+ Mount + full manual loop:
142
+
143
+ ```console
144
+ tools visible to model: 12
145
+ task_archive, task_create, task_get, task_list, task_resume, task_run,
146
+ task_run_begin, task_run_finish, task_run_history, task_schedule,
147
+ task_step_report, task_update
148
+ missing: none
149
+ task_create: {"success":true,"taskId":"tsk_e3daa7j8mbprgcq33tjv",...}
150
+ task_run: true running | steps: 2
151
+ step 1: completed progress=50%
152
+ step 2: completed progress=100%
153
+ task_run_finish: succeeded 100% | required 2/2
154
+ task_run_history: 1 run(s), first = succeeded
155
+ schedule dedupe: true | trigger: schedule | deduplicated: true
156
+ domain file: true
157
+ unit version: 1 | tables: tasks,task_runs,task_run_steps,meta
158
+ task rows: 2
159
+ meta: {"global":{"schemaVersion":1,"appliedMigrations":{}}}
160
+ ```
161
+
162
+ Restart / persistence / resume (§ PRD 14.4), second process over the same file:
163
+
164
+ ```console
165
+ before restart: task tsk_z98awts11jmd4w5csjhr | run run_p9yfwjfsqbszhf3cjagw
166
+ after restart: task found = true | steps = 2
167
+ after restart: runs = 1 | status = interrupted
168
+ after restart: step1 carried = completed
169
+ resume: true running | resumesRunId = true | carried = 1 | pending = 1
170
+ ```
171
+
172
+ ## 7. Services deliberately **not** used
173
+
174
+ | Service | Why not |
175
+ |---|---|
176
+ | `ctx.jobs` | process-level, Session-owned, not a cross-restart ledger (PRD 16.3). TaskRun lives in StorageDomain. |
177
+ | `ctx.agents` / `followup()` | A `followup` MessageId is an enqueue receipt, not a completion handle (PRD FR-005). The calling Agent executes in-line. |
178
+ | Goal / Workflow | Out of V1.0 scope; no reimplementation. |
179
+ | Private APIs | None used. No `src/` deep imports, no internal symbols. |
180
+
181
+ ## 8. Profile installation
182
+
183
+ `plugin_manager install_bundle` on this workspace directory:
184
+
185
+ - manifest must nest the patch: `"dsh": { "bundle": { "patch": "./cordis.patch.yml" } }`
186
+ (a bare string is rejected with *"dsh.bundle.patch must be a file path or a list of file paths"*);
187
+ - result after the two fixes above: **`application: applied`, `warnings: []`**;
188
+ - profile row: `dsh-background-task-engine` in `dependencies` (link) **and** in
189
+ `dsh.profile.bundles`.
190
+
191
+ ## 9. Remaining known limits
192
+
193
+ 1. **Schedule end-to-end delivery** could not be exercised in-process: the real
194
+ `ScheduleService` requires `agents`, `sessions`, `sessionPersistence` and a
195
+ session controller, which only the full application composes. Its adapter is
196
+ covered by unit/integration tests against a double with the documented
197
+ contract, and every host failure path is mapped to `TASK_SCHEDULE_FAILED`.
198
+ The delivery-envelope parser is tested against the documented
199
+ `[SCHEDULE REMINDER]` payload.
200
+ 2. **`JSON` backend single-unit layout**: the whole domain is one document, so
201
+ write cost grows with retained runs. Mitigated by the 90-day retention prune.
202
+ 3. **`domain/changed` is in-process only**; a second host process sees writes
203
+ after reopening the domain, not live.
package/docs/DETAIL.md ADDED
@@ -0,0 +1 @@
1
+ ![A reusable task template with three ordered steps is started, producing one run ledger whose first two required steps are completed and whose third is now running](preview.svg)
@@ -0,0 +1 @@
1
+ ![一个含三个有序步骤的可复用任务模板被启动后,生成一份运行账本:前两个必需步骤已完成,第三个正在执行](preview.svg)
@@ -0,0 +1,232 @@
1
+ # Test Report
2
+
3
+ Verification record for `dsh-background-task-engine` 1.0.0 against PRD chapter 14.
4
+
5
+ ## How to reproduce
6
+
7
+ ```sh
8
+ npm install
9
+ npm run build # tsc -> dist/
10
+ npm test # vitest run
11
+ ```
12
+
13
+ ## Summary
14
+
15
+ | Suite | File | Tests | Result |
16
+ |---|---|---|---|
17
+ | Domain | `tests/domain/state.test.ts` | 18 | PASS |
18
+ | Storage | `tests/storage/repository.test.ts` | 17 | PASS |
19
+ | Rendering | `tests/tools/render.test.ts` | 13 | PASS |
20
+ | Integration | `tests/integration/tools.test.ts` | 33 | PASS |
21
+ | **Total** | 4 files | **81** | **all passing** |
22
+
23
+ ```console
24
+ $ npx vitest run
25
+ ✓ tests/domain/state.test.ts (18 tests)
26
+ ✓ tests/storage/repository.test.ts (17 tests)
27
+ ✓ tests/tools/render.test.ts (13 tests)
28
+ ✓ tests/integration/tools.test.ts (33 tests)
29
+
30
+ Test Files 4 passed (4)
31
+ Tests 81 passed (81)
32
+ ```
33
+
34
+ The integration suite drives the real plugin entry point (`apply()` →
35
+ `ctx.tools.register`) through a fake StorageDomain whose semantics mirror the
36
+ documented host contract: synchronous reads, a serialized per-key write chain,
37
+ zod validation at the boundary, and `missing-key` on `update`. The fake context
38
+ even throws on un-injected service property access, like Cordis does.
39
+
40
+ ## Host-side verification (not part of `npm test`)
41
+
42
+ Two scripts boot the **real** DSH packages out of the installed `app.asar`:
43
+
44
+ | Check | Result |
45
+ |---|---|
46
+ | 12 tools registered and visible in `tools.schemas()` | 12 / 12 |
47
+ | All schemas accepted by the host's `assertSupportedJsonSchema` | 12 / 12 |
48
+ | `task_create` → `task_run` → 2 × `task_step_report` → `task_run_finish` | succeeded, 100 %, 2/2 required |
49
+ | `task_run_history` after the loop | 1 run, `succeeded` |
50
+ | Duplicate schedule delivery (`scheduleId` + `occurrenceKey`) | same `runId`, `deduplicated: true` |
51
+ | Persisted JSON document | `dsh_background_task_engine.json`, unit v1, 4 tables |
52
+ | Restart over the same file | task + steps intact, stale run → `interrupted` |
53
+ | Resume after restart | new `runId`, `resumesRunId` set, 1 carried / 1 pending |
54
+
55
+ Details and console output: `docs/API-COMPATIBILITY-AUDIT.md` §6.
56
+
57
+ ## Requirement coverage (PRD 14)
58
+
59
+ | PRD | Requirement | Covered by |
60
+ |---|---|---|
61
+ | 14.1 | unique `taskId`; title/steps/>10 rejected; revision increments and stale revision rejected; archive keeps history; snapshot frozen | `integration` → *task templates (PRD 14.1)* |
62
+ | 14.2 | independent TaskRun; strict step order; unknown `stepId` and skips rejected; idempotency key; `succeeded` needs all required steps; failure keeps step id/error/time | `integration` → *manual execution (PRD 14.2)* |
63
+ | 14.3 | link host schedule; failed rule update not reported as success; pause/resume/delete honour host result; delivery identifies task + occurrence; duplicate delivery does not restart; delivery ≠ success | `integration` → *schedule linkage (PRD 14.3)* |
64
+ | 14.4 | records survive restart; stale run → `interrupted`; resume creates new run with `resumesRunId`; starts at first unfinished step; no automatic replay; old run unchanged | `integration` + `storage` + real-host restart run |
65
+ | 14.5 | cross-Session reads/writes denied; active-run cap; illegal transitions rejected; malicious text inert; no credential/path leakage | `integration` → *isolation, concurrency and safety*; `domain` → *error contract* |
66
+ | 14.6 | installs in the local profile; tools callable; missing StorageDomain errors loudly; Schedule optional; uninstall keeps data | `plugin_manager install_bundle` → `application: applied`; `integration` → *tool registration and startup* |
67
+ | 14.7 | definition of done (installable, CRUD, 1–10 steps, manual + schedule, run/step state, recovery, idempotency/concurrency/isolation, persistence + migration + prune, tests, docs) | this report + README + CHANGELOG |
68
+
69
+ ## Bugs found and fixed during verification
70
+
71
+ | # | Symptom | Root cause | Fix |
72
+ |---|---|---|---|
73
+ | 1 | Install rejected: *"dsh.bundle.patch must be a file path or a list of file paths"* | manifest used the flat `dsh.bundle: "./cordis.patch.yml"` form | nested `dsh.bundle.patch` |
74
+ | 2 | Install reported *"cannot get property \"schedule\" without inject"* | optional service read as a context property | `optionalService()` via `ctx.get`, absence = not mounted |
75
+ | 3 | Every tool returned `TASK_STORAGE_ERROR: invalid unit name 'dsh-background-task-engine'` **on the real host only** | host `UNIT_NAME_RE` forbids hyphens | unit renamed to `dsh_background_task_engine`, asserted in tests, re-checked at startup |
76
+ | 4 | A custom renderer hid the error text on failed calls | early `return` used the wrong check | single `isFailure()` guard used by every presenter |
77
+ | 5 | `renderRun` swapped `(args, value)` | argument order | corrected, plus a test that renders **every** tool with a failure envelope |
78
+ | 6 | Repeating a terminal `step_report` was silently treated as a no-op | blanket same-status short-circuit | only a repeated `started` is idempotent; terminal repeats are ordering errors |
79
+
80
+ Bugs 1–3 were only observable against the real host, which is why
81
+ `docs/API-COMPATIBILITY-AUDIT.md` records the real-stack runs separately from the
82
+ unit suite.
83
+
84
+ ## Post-publish verification (GitHub artifact)
85
+
86
+ The committed `main` was cloned fresh and treated as an independent artifact:
87
+
88
+ | Check | Result |
89
+ |---|---|
90
+ | `git clone` from `github.com:yzzshanyin-rgb/dsh-background-task-engine` | ok, commit `a01bdd6` |
91
+ | Fresh `npm install && npm run build` | BUILD OK |
92
+ | Rebuilt `dist/` vs committed `dist/` | identical (`git status` clean) |
93
+ | `npm test` in the clone | **81 / 81 passing** |
94
+ | `npm pack` tarball | 58 files, 81 KB |
95
+ | Tarball contents | `dist/index.js`, `locale/{en,zh}.json`, `icon.svg`, `docs/DETAIL{,.zh}.md`, `docs/preview.svg`, `cordis.patch.yml` all present |
96
+ | Tarball installed into a clean project | 12/12 tools register; `Config()` returns the documented defaults |
97
+ | Clone installed into the real desktop profile | `application: applied`, no warnings |
98
+
99
+ Two packaging details were confirmed while doing this: `@deepseek-ai/schemastery`
100
+ must stay a regular dependency (every installed community plugin that defines a
101
+ `Config` declares it the same way), and the shipped `dist/` is byte-identical to a
102
+ fresh build, so the published artifact cannot drift from source.
103
+
104
+ ## Published artifact verification (npm)
105
+
106
+ After `npm publish` (registry confirms `dsh-background-task-engine@1.0.0`,
107
+ `dist-tags.latest = 1.0.0`, maintainer `anishuodedui`), the **published** package
108
+ was verified independently of the checkout:
109
+
110
+ | Check | Result |
111
+ |---|---|
112
+ | `npm view dsh-background-task-engine version` | `1.0.0`, `latest = 1.0.0` |
113
+ | `npm install dsh-background-task-engine@1.0.0` into a clean project | 5 packages, no errors |
114
+ | Load the installed copy | 26 exports; `name` / `inject` as documented |
115
+ | `apply()` on the installed copy | **12/12 tools register** |
116
+ | `Config({})` on the installed copy | documented defaults |
117
+ | Install into the real desktop profile (`@1.0.0`, not a link) | **`application: applied`**, `warnings: []` |
118
+ | Profile copy shape | real directory from the registry (not a symlink), own `node_modules` |
119
+ | Display resources in the installed copy | `locale/{en,zh}.json`, `icon.svg`, `docs/DETAIL{,.zh}.md`, `docs/preview.svg` all present |
120
+ | Locale titles | `Background task engine` / `后台任务引擎` |
121
+
122
+ ### One installation hazard worth recording
123
+
124
+ `@deepseek-ai/schemastery` resolves only if the dependency is installed. When the
125
+ bundle was installed as a **registry** package immediately after the workspace
126
+ `node_modules` had been removed, the loader resolved through the stale workspace
127
+ path and failed with `ERR_MODULE_NOT_FOUND: Cannot find package
128
+ '@deepseek-ai/schemastery'`. Restoring the workspace dependencies and
129
+ reinstalling from the registry produced a clean `application: applied`.
130
+
131
+ Practical consequence: run `npm install` in the package directory before
132
+ `plugin_manager install_bundle` when handing it a directory path, and prefer the
133
+ registry spec (`dsh-background-task-engine@1.0.0`) once published — it carries its
134
+ own `node_modules` and does not depend on the checkout.
135
+
136
+ ## Test inventory
137
+
138
+ Every assertion from the last full run is listed below.
139
+
140
+
141
+ ### tests/domain/state.test.ts (18)
142
+
143
+ - `PASS` TaskRun state machine accepts the documented transitions
144
+ - `PASS` TaskRun state machine refuses to go back from a non-running state to running
145
+ - `PASS` TaskRun state machine treats terminal states as final
146
+ - `PASS` TaskRun state machine rejects re-reporting the same step status
147
+ - `PASS` progress and ordering computes floor(completed required / required total * 100)
148
+ - `PASS` progress and ordering never counts optional or non-completed steps as progress
149
+ - `PASS` progress and ordering finds the first unfinished step in order
150
+ - `PASS` progress and ordering blocks succeeded while a required step is unfinished
151
+ - `PASS` progress and ordering refuses to start a later step before its predecessors
152
+ - `PASS` error contract sanitises paths, stacks and credentials
153
+ - `PASS` error contract maps unknown failures to TASK_INTERNAL_ERROR and missing keys to TASK_NOT_FOUND
154
+ - `PASS` configuration validation fills documented defaults
155
+ - `PASS` configuration validation rejects out-of-range values instead of clamping
156
+ - `PASS` trigger payload parsing extracts task, schedule and occurrence from a delivery message
157
+ - `PASS` trigger payload parsing returns an empty envelope for unrelated text
158
+ - `PASS` pagination and text limits round-trips cursors and keysets by (timestamp, id)
159
+ - `PASS` pagination and text limits treats an invalid cursor as the first page and compares ties by id
160
+ - `PASS` pagination and text limits truncates summaries at the configured bound and strips control characters
161
+
162
+ ### tests/storage/repository.test.ts (17)
163
+
164
+ - `PASS` domain declaration uses host-legal unit and table names
165
+ - `PASS` domain declaration declares three model tables plus the metadata table
166
+ - `PASS` domain declaration rejects records that do not match the declared schema
167
+ - `PASS` migrations records an applied migration in the ledger exactly once
168
+ - `PASS` migrations stops writing when a migration fails and leaves no marker
169
+ - `PASS` migrations refuses data written by a newer schema version
170
+ - `PASS` migrations ships no migration for v1 (the baseline shape needs none)
171
+ - `PASS` integrity verification reports a clean domain
172
+ - `PASS` integrity verification detects runs that reference a missing task
173
+ - `PASS` repository write semantics serialises concurrent mutations so the revision advances exactly once per call
174
+ - `PASS` repository write semantics writes steps before the run so a crash cannot leave progress without a run
175
+ - `PASS` repository write semantics deletes a run together with its step rows
176
+ - `PASS` retention pruning removes only old terminal runs and never an active one
177
+ - `PASS` startup recovery interrupts a stale run and its running step without creating a new run
178
+ - `PASS` startup recovery leaves a freshly updated run alone
179
+ - `PASS` facility wiring opens the declared domain once and reads back the same handle
180
+ - `PASS` facility wiring schedule adapter reports unavailability without a host service
181
+
182
+ ### tests/integration/tools.test.ts (33)
183
+
184
+ - `PASS` tool registration and startup registers all 12 task_* tools
185
+ - `PASS` tool registration and startup publishes a JSON Schema the host subset accepts for every tool
186
+ - `PASS` tool registration and startup refuses to start without a StorageDomain instead of degrading to memory
187
+ - `PASS` tool registration and startup reports a storage open failure through TASK_STORAGE_ERROR
188
+ - `PASS` task templates (PRD 14.1) creates a task with a unique id, revision 1 and ordered steps
189
+ - `PASS` task templates (PRD 14.1) rejects a missing title, empty steps and more than 10 steps
190
+ - `PASS` task templates (PRD 14.1) increments revision and rejects a stale expectedRevision
191
+ - `PASS` task templates (PRD 14.1) keeps run history after archiving and blocks further edits
192
+ - `PASS` task templates (PRD 14.1) freezes the step template at run start
193
+ - `PASS` task templates (PRD 14.1) lists, filters and paginates tasks per session
194
+ - `PASS` task templates (PRD 14.1) copies an existing template
195
+ - `PASS` manual execution (PRD 14.2) creates an independent TaskRun with a snapshot and pending steps
196
+ - `PASS` manual execution (PRD 14.2) executes steps in order and reports persisted progress
197
+ - `PASS` manual execution (PRD 14.2) rejects unknown step ids and duplicate reports
198
+ - `PASS` manual execution (PRD 14.2) refuses succeeded until every required step is completed
199
+ - `PASS` manual execution (PRD 14.2) records the failed step id, error summary and timestamp
200
+ - `PASS` manual execution (PRD 14.2) is idempotent on manualRunId
201
+ - `PASS` manual execution (PRD 14.2) supports the queued → running two-phase start
202
+ - `PASS` schedule linkage (PRD 14.3) creates and links a native schedule, then pauses and resumes it
203
+ - `PASS` schedule linkage (PRD 14.3) does not report success when the host rule update fails
204
+ - `PASS` schedule linkage (PRD 14.3) unlinks the rule on delete and on archive
205
+ - `PASS` schedule linkage (PRD 14.3) keeps manual execution working when Schedule is unavailable
206
+ - `PASS` schedule linkage (PRD 14.3) identifies task and occurrence from a scheduled delivery and dedupes repeats
207
+ - `PASS` schedule linkage (PRD 14.3) rejects an unidentifiable trigger payload
208
+ - `PASS` recovery semantics (PRD 14.4) marks a stale running run as interrupted on the next startup
209
+ - `PASS` recovery semantics (PRD 14.4) resumes from the first unfinished step without replaying completed ones
210
+ - `PASS` recovery semantics (PRD 14.4) resumes a blocked run without confirmation because no step failed
211
+ - `PASS` recovery semantics (PRD 14.4) refuses to resume a run that may still be executing
212
+ - `PASS` isolation, concurrency and safety (PRD 14.5) hides another session’s tasks behind TASK_NOT_FOUND
213
+ - `PASS` isolation, concurrency and safety (PRD 14.5) enforces the per-owner active run limit
214
+ - `PASS` isolation, concurrency and safety (PRD 14.5) rejects illegal transitions such as reporting on a paused task or finishing twice
215
+ - `PASS` isolation, concurrency and safety (PRD 14.5) keeps malicious template text inert
216
+ - `PASS` isolation, concurrency and safety (PRD 14.5) never echoes credentials or host paths in error results
217
+
218
+ ### tests/tools/render.test.ts (13)
219
+
220
+ - `PASS` uniform envelope renders failures as a single actionable line
221
+ - `PASS` uniform envelope declares success and error on every output schema
222
+ - `PASS` timing translation passes through at / every / rrule / cron
223
+ - `PASS` timing translation expresses daily and weekly wall-clock schedules as an RRULE
224
+ - `PASS` timing translation rejects invalid timing input instead of silently accepting it
225
+ - `PASS` timing translation describes every timing shape for display
226
+ - `PASS` host schedule prompt carries the task id so a delivery can be mapped back to a task
227
+ - `PASS` tool rendering (what the model sees) renders a created task with its id, steps and revision
228
+ - `PASS` tool rendering (what the model sees) renders run progress with per-step marks and the next step
229
+ - `PASS` tool rendering (what the model sees) renders a failure with the failing step and the recovery hint
230
+ - `PASS` tool rendering (what the model sees) renders every tool without throwing on a failure envelope
231
+ - `PASS` schedule adapter failure mapping maps host rejections to TASK_SCHEDULE_FAILED with a sanitised message
232
+ - `PASS` schedule adapter failure mapping treats a missing host entry as already gone rather than a hard failure
@@ -0,0 +1,68 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="640" height="300" viewBox="0 0 640 300" role="img" aria-label="A task template with three ordered steps is started, producing one run ledger whose first two required steps are completed and whose third is now running.">
2
+ <rect width="640" height="300" fill="none"/>
3
+
4
+ <!-- ================= LEFT: the reusable template ================= -->
5
+ <g fill="none" stroke-linecap="round" stroke-linejoin="round">
6
+ <rect x="44" y="62" width="188" height="196" rx="13" fill="#FBFCFE" stroke="#3D4A5C" stroke-width="2.6"/>
7
+ <!-- header band: fill only, then one separator, so no double edge appears -->
8
+ <path d="M44 75a13 13 0 0 1 13-13h162a13 13 0 0 1 13 13v15H44z" fill="#E8EEF6" stroke="none"/>
9
+ <path d="M44 90h188" stroke="#3D4A5C" stroke-width="2.6"/>
10
+
11
+ <!-- step rows: fixed geometry, no overlaps -->
12
+ <g stroke="#3D4A5C" stroke-width="2.2">
13
+ <rect x="62" y="106" width="152" height="38" rx="8" fill="#FFFFFF"/>
14
+ <rect x="62" y="154" width="152" height="38" rx="8" fill="#FFFFFF"/>
15
+ <rect x="62" y="202" width="152" height="38" rx="8" fill="#FFFFFF"/>
16
+ </g>
17
+ <!-- order numbers are drawn as dots, not glyphs -->
18
+ <g fill="#BBD3DE" stroke="none">
19
+ <circle cx="76" cy="125" r="3.4"/>
20
+ <circle cx="76" cy="173" r="3.4"/>
21
+ <circle cx="76" cy="221" r="3.4"/>
22
+ </g>
23
+ <!-- instruction lines -->
24
+ <g stroke="#8A97A8" stroke-width="2.2" stroke-linecap="round">
25
+ <path d="M88 121h108M88 131h68"/>
26
+ <path d="M88 169h108M88 179h52"/>
27
+ <path d="M88 217h108M88 227h76"/>
28
+ </g>
29
+ </g>
30
+
31
+ <!-- ================= MIDDLE: the start action ================= -->
32
+ <g fill="none" stroke="#3D4A5C" stroke-width="2.8" stroke-linecap="round" stroke-linejoin="round">
33
+ <path d="M258 160h56"/>
34
+ <path d="M308 152l10 8-10 8"/>
35
+ </g>
36
+ <g>
37
+ <circle cx="286" cy="150" r="0" fill="none"/>
38
+ </g>
39
+
40
+ <!-- ================= RIGHT: the run ledger ================= -->
41
+ <g fill="none" stroke-linecap="round" stroke-linejoin="round">
42
+ <rect x="356" y="62" width="240" height="196" rx="13" fill="#FBFCFE" stroke="#3D4A5C" stroke-width="2.6"/>
43
+ <path d="M356 75a13 13 0 0 1 13-13h214a13 13 0 0 1 13 13v15H356z" fill="#E3F0E9" stroke="none"/>
44
+ <path d="M356 90h240" stroke="#3D4A5C" stroke-width="2.6"/>
45
+ <!-- run marker in the header -->
46
+ <path d="M372 73h74" stroke="#2F7A57" stroke-width="3.2"/>
47
+
48
+ <!-- progress bar: 66% of required steps -->
49
+ <rect x="374" y="106" width="204" height="13" rx="6.5" fill="#E4E9F0" stroke="none"/>
50
+ <rect x="374" y="96" width="136" height="13" rx="6.5" fill="#2F7A57" stroke="none"/>
51
+
52
+ <!-- step 1 carried over as completed -->
53
+ <circle cx="390" cy="144" r="10" fill="#E3F0E9" stroke="none"/>
54
+ <path d="M385 144l3.6 3.6 6.4-7.2" stroke="#2F7A57" stroke-width="2.4"/>
55
+ <path d="M410 139h164M410 151h96" stroke="#8A97A8" stroke-width="2.2"/>
56
+
57
+ <!-- step 2 carried over as completed -->
58
+ <circle cx="390" cy="186" r="10" fill="#E3F0E9" stroke="none"/>
59
+ <path d="M385 186l3.6 3.6 6.4-7.2" stroke="#2F7A57" stroke-width="2.4"/>
60
+ <path d="M410 181h164M410 193h72" stroke="#8A97A8" stroke-width="2.2"/>
61
+
62
+ <!-- step 3 currently running -->
63
+ <circle cx="390" cy="228" r="10" fill="#FAF1DE" stroke="#C08A2E" stroke-width="2.4"/>
64
+ <path d="M387 223v10l8.4-5z" fill="#C08A2E" stroke="none"/>
65
+ <path d="M410 223h164M410 235h60" stroke="#C2CBD8" stroke-width="2.2"/>
66
+ </g>
67
+
68
+ </svg>
package/icon.svg ADDED
@@ -0,0 +1,23 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="36" height="36" viewBox="0 0 36 36" role="img" aria-label="Background task engine">
2
+ <!-- One dominant subject: a task ledger with three ordered step marks and a
3
+ status light for a run in progress. Flat fills, no tile, transparent
4
+ background, no text. -->
5
+ <g fill="none" stroke-linecap="round" stroke-linejoin="round">
6
+ <!-- sheet -->
7
+ <rect x="7" y="4.8" width="22" height="26.4" rx="3.6" fill="#FBFCFE" stroke="#3D4A5C" stroke-width="2.3"/>
8
+ <!-- header separator -->
9
+ <path d="M7 12.2h22" stroke="#3D4A5C" stroke-width="2.3"/>
10
+ <!-- run status light in the header -->
11
+ <circle cx="24.2" cy="8.5" r="2.1" fill="#2F7A57" stroke="none"/>
12
+
13
+ <!-- step 1: completed -->
14
+ <path d="M11.4 17.3l2.1 2.1 3.7-4.2" stroke="#2F7A57" stroke-width="2.3"/>
15
+ <path d="M21.6 17.6h3.4" stroke="#8A97A8" stroke-width="2"/>
16
+ <!-- step 2: completed -->
17
+ <path d="M11.4 23.2l2.1 2.1 3.7-4.2" stroke="#2F7A57" stroke-width="2.3"/>
18
+ <path d="M21.6 23.5h3.4" stroke="#8A97A8" stroke-width="2"/>
19
+ <!-- step 3: pending -->
20
+ <circle cx="13.9" cy="28.9" r="1.9" stroke="#8A97A8" stroke-width="2"/>
21
+ <path d="M21.6 29.1h3.4" stroke="#C2CBD8" stroke-width="2"/>
22
+ </g>
23
+ </svg>
package/locale/en.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "meta": {
3
+ "title": "Background task engine",
4
+ "description": "Durable task templates with ordered steps, a persisted run ledger, progress and history queries, failure/interruption recovery, and optional native DSH Schedule linkage. Exposes 12 task_* tools; task data is stored in a StorageDomain and stays private to the Session that created it.",
5
+ "detail": "docs/DETAIL.md"
6
+ }
7
+ }
package/locale/zh.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "meta": {
3
+ "title": "后台任务引擎",
4
+ "description": "可复用的任务模板与线性步骤、持久化的运行账本、进度与历史查询、失败/中断后的人工恢复,并可选关联 DSH 原生定时任务。提供 12 个 task_* 工具;任务数据存放在 StorageDomain 中,只有创建它的 Session 可见。",
5
+ "detail": "docs/DETAIL.zh.md"
6
+ }
7
+ }
package/package.json CHANGED
@@ -1,6 +1,73 @@
1
1
  {
2
2
  "name": "dsh-background-task-engine",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.1",
4
+ "description": "Durable background task engine for DeepSeek Harness: task templates, linear step runs, persisted progress, failure recovery and optional DSH Schedule linkage.",
5
+ "keywords": [
6
+ "deepseek-harness",
7
+ "dsh",
8
+ "dsh-plugin",
9
+ "dsh-bundle",
10
+ "task-engine",
11
+ "background-task",
12
+ "task-orchestration",
13
+ "schedule"
14
+ ],
15
+ "type": "module",
16
+ "main": "dist/index.js",
17
+ "types": "dist/index.d.ts",
18
+ "exports": {
19
+ ".": {
20
+ "types": "./dist/index.d.ts",
21
+ "default": "./dist/index.js"
22
+ },
23
+ "./locale/*.json": "./locale/*.json",
24
+ "./icon": "./icon.svg",
25
+ "./package.json": "./package.json"
26
+ },
27
+ "files": [
28
+ "dist",
29
+ "cordis.patch.yml",
30
+ "locale/*.json",
31
+ "docs",
32
+ "icon.svg",
33
+ "README.md",
34
+ "README.zh.md",
35
+ "CHANGELOG.md",
36
+ "LICENSE"
37
+ ],
38
+ "license": "MIT",
39
+ "author": "yzzshanyin-rgb",
40
+ "repository": {
41
+ "type": "git",
42
+ "url": "git+https://github.com/yzzshanyin-rgb/dsh-background-task-engine.git"
43
+ },
44
+ "homepage": "https://github.com/yzzshanyin-rgb/dsh-background-task-engine#readme",
45
+ "bugs": {
46
+ "url": "https://github.com/yzzshanyin-rgb/dsh-background-task-engine/issues"
47
+ },
48
+ "dsh": {
49
+ "bundle": {
50
+ "patch": "./cordis.patch.yml"
51
+ }
52
+ },
53
+ "dependencies": {
54
+ "@deepseek-ai/schemastery": "^3.18.5",
55
+ "zod": "^3.25.76"
56
+ },
57
+ "devDependencies": {
58
+ "@types/node": "^22.10.2",
59
+ "typescript": "^5.7.2",
60
+ "vitest": "^2.1.8"
61
+ },
62
+ "engines": {
63
+ "node": ">=20"
64
+ },
65
+ "scripts": {
66
+ "build": "tsc -p tsconfig.json",
67
+ "clean": "rm -rf dist",
68
+ "typecheck": "tsc -p tsconfig.json --noEmit",
69
+ "test": "vitest run",
70
+ "test:watch": "vitest",
71
+ "prepublishOnly": "npm run clean && npm run build"
72
+ }
73
+ }