@dcrays/scheduled-task 0.1.3 → 0.1.4

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/README.md CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  书灵墨宝的 DSH 持久化定时任务服务插件。加载后注册 `manage_cron_automation` 工具,并提供 `/api/cron-automations` HTTP API。
4
4
 
5
- 本包对应 `production` 环境。
5
+ 单一发布包同时适用于生产与测试桌面:运行时根据 `mobook.json` 中记录的环境将定时任务数据库隔离在 `cron/<env>/cron.sqlite`。
package/cordis.patch.yml CHANGED
@@ -8,7 +8,7 @@
8
8
  - webServer
9
9
  - tools
10
10
  config:
11
- runtimeEnvironment: production
11
+ runtimeEnvironment: development
12
12
  legacyDatabaseEnvironment: production
13
13
  maxPromptChars: 16384
14
14
  listPushIntervalSeconds: 30
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@dcrays/scheduled-task",
3
- "version": "0.1.3",
4
- "description": "Persistent client-facing cron automation service for DeepSeek Harness (production)",
3
+ "version": "0.1.4",
4
+ "description": "Persistent client-facing cron automation service for DeepSeek Harness",
5
5
  "type": "module",
6
6
  "main": "plugin/index.js",
7
7
  "types": "plugin/index.d.ts",
package/plugin/index.js CHANGED
@@ -1339,7 +1339,7 @@ function openClawImportSource(sqlitePath) {
1339
1339
 
1340
1340
  // dist-npm/src/runtime-environment.js
1341
1341
  import path3 from "node:path";
1342
- import { existsSync as existsSync2, realpathSync as realpathSync2 } from "node:fs";
1342
+ import { existsSync as existsSync2, readFileSync, realpathSync as realpathSync2 } from "node:fs";
1343
1343
  import { dshHomePath as dshHomePath2 } from "@deepseek-ai/dsh-home-paths";
1344
1344
  var CRON_RUNTIME_ENVIRONMENTS = ["development", "test", "production"];
1345
1345
  function resolveCronRuntimeEnvironment(value) {
@@ -1349,6 +1349,15 @@ function resolveCronRuntimeEnvironment(value) {
1349
1349
  }
1350
1350
  throw new Error(`Unsupported cron runtime environment: ${environment}`);
1351
1351
  }
1352
+ function readDesktopRuntimeEnvironment() {
1353
+ try {
1354
+ const parsed = JSON.parse(readFileSync(dshHomePath2("mobook.json"), "utf8"));
1355
+ const value = parsed && typeof parsed === "object" ? parsed.environment : void 0;
1356
+ return typeof value === "string" && value.trim() ? value.trim() : void 0;
1357
+ } catch {
1358
+ return void 0;
1359
+ }
1360
+ }
1352
1361
  function cronRuntimePath(environment, ...segments) {
1353
1362
  return dshHomePath2("cron", environment, ...segments);
1354
1363
  }
@@ -1581,7 +1590,7 @@ var CronAutomationService = class extends Service {
1581
1590
  super(owner, "cronAutomations");
1582
1591
  this.owner = owner;
1583
1592
  this.config = config;
1584
- this.runtimeEnvironment = resolveCronRuntimeEnvironment(config.runtimeEnvironment);
1593
+ this.runtimeEnvironment = resolveCronRuntimeEnvironment(readDesktopRuntimeEnvironment() ?? config.runtimeEnvironment);
1585
1594
  const databaseFile = resolveCronDatabaseFile(config.databaseFile, this.runtimeEnvironment);
1586
1595
  const logger = owner.logger("dsh-cron-automation");
1587
1596
  this.manager = new CronAutomationManager(new CronAutomationRepository(databaseFile), {
@@ -1,6 +1,13 @@
1
1
  export declare const CRON_RUNTIME_ENVIRONMENTS: readonly ["development", "test", "production"];
2
2
  export type CronRuntimeEnvironment = (typeof CRON_RUNTIME_ENVIRONMENTS)[number];
3
3
  export declare function resolveCronRuntimeEnvironment(value: string | undefined): CronRuntimeEnvironment;
4
+ /**
5
+ * Read the desktop build environment recorded in mobook.json. A single cron
6
+ * package ships for every desktop build; the environment written by the client
7
+ * before DSH starts keeps scheduled tasks isolated per build (cron/<env>) even
8
+ * though all builds share one DSH_HOME.
9
+ */
10
+ export declare function readDesktopRuntimeEnvironment(): string | undefined;
4
11
  /**
5
12
  * Keep scheduled tasks and the import ledger isolated between desktop build
6
13
  * environments even though they intentionally share one DSH_HOME.
@@ -1,5 +1,5 @@
1
1
  import path from 'node:path';
2
- import { existsSync, realpathSync } from 'node:fs';
2
+ import { existsSync, readFileSync, realpathSync } from 'node:fs';
3
3
  import { dshHomePath } from '@deepseek-ai/dsh-home-paths';
4
4
  export const CRON_RUNTIME_ENVIRONMENTS = ['development', 'test', 'production'];
5
5
  export function resolveCronRuntimeEnvironment(value) {
@@ -9,6 +9,22 @@ export function resolveCronRuntimeEnvironment(value) {
9
9
  }
10
10
  throw new Error(`Unsupported cron runtime environment: ${environment}`);
11
11
  }
12
+ /**
13
+ * Read the desktop build environment recorded in mobook.json. A single cron
14
+ * package ships for every desktop build; the environment written by the client
15
+ * before DSH starts keeps scheduled tasks isolated per build (cron/<env>) even
16
+ * though all builds share one DSH_HOME.
17
+ */
18
+ export function readDesktopRuntimeEnvironment() {
19
+ try {
20
+ const parsed = JSON.parse(readFileSync(dshHomePath('mobook.json'), 'utf8'));
21
+ const value = parsed && typeof parsed === 'object' ? parsed.environment : undefined;
22
+ return typeof value === 'string' && value.trim() ? value.trim() : undefined;
23
+ }
24
+ catch {
25
+ return undefined;
26
+ }
27
+ }
12
28
  /**
13
29
  * Keep scheduled tasks and the import ledger isolated between desktop build
14
30
  * environments even though they intentionally share one DSH_HOME.