@dshtrading/hk 0.1.3 → 0.1.5

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/lib/index.d.ts CHANGED
@@ -1,47 +1,14 @@
1
1
  import Schema from "@deepseek-ai/schemastery";
2
- import { Context } from "@deepseek-ai/cordis";
3
2
  //#region src/index.d.ts
4
- /**
5
- * Cordis 插件名 = patch 行 id(TEMPLATES §8):`dsh-trading-hk-*` 市场命名空间,
6
- * 全仓唯一(insert-only 铁律 #1)。
7
- */
8
3
  declare const name = "dsh-trading-hk-installer";
9
4
  interface Config {
10
- /** preset 自安装 root 覆盖;默认 ~/.dsh-trading-presets(须与 base 层 agent-presets 行的 roots 一致)。 */
11
5
  presetRoot?: string;
12
6
  }
13
7
  declare const Config: Schema<Config>;
14
- declare const PRESET_ID = "hk-trader";
15
- /** 默认安装 root:市场自有目录(S3 建议——绝不写进 ~/.dsh/.agent-presets 用户创作区)。 */
16
- declare const DEFAULT_PRESET_ROOT: string;
17
- interface SelfInstallResult {
18
- /** 安装目录(preset 目录名即 roster id)。 */
19
- dir: string;
20
- /** 本次实际写入的文件名;空数组 = 内容已是当前代际。 */
21
- wrote: string[];
22
- /** 被跳过的文件与原因(用户改过/无管理戳)。 */
23
- skipped: string[];
24
- }
25
- /**
26
- * 幂等自安装 preset(S3 机制 + 2026-08-29 代际管理戳升级):mkdir -p + 逐文件按管理戳
27
- * 三代裁决——
28
- *
29
- * 1. 目标不存在 → 写入(头行 = `# dsh-trading-managed: <内容sha前8>` + shipped 内容);
30
- * 2. 目标存在且带本包可识别的管理戳(托管文件)→ 正文与 shipped 内容不同则整文件更新
31
- * (以新代际覆盖——戳即「本文件归安装器托管」的约定);
32
- * 3. 目标存在但无管理戳(用户改过/前代安装器所装)→ 跳过并记录提示(删除该文件即可
33
- * 让安装器重新提供)。
34
- *
35
- * 迁移注意:代际升级前由旧安装器写入的已装文件没有管理戳,按第 3 条处理(跳过 + log
36
- * 提示)——宁可不更新,绝不覆盖用户改动。
37
- *
38
- * 卸载本 bundle 不删除已安装目录(有意为之):升级/重装后再次 apply 即恢复一致;本包
39
- * 被移除后 preset 行不可解析只会得到带原因的 broken 行,无进程崩溃(S3 REPORT broken 语义)。
40
- * preset 引用的插件包必须进本 bundle 的 dependencies(S3 坑 3),见 package.json。
41
- */
42
- declare function installPreset(options?: {
43
- presetRoot?: string;
44
- }): Promise<SelfInstallResult>;
45
- declare function apply(ctx: Context, config: Config): void;
8
+ declare function getPresetContribution(): Promise<{
9
+ market: "hk";
10
+ traderRows: string;
11
+ }>;
12
+ declare function apply(): void;
46
13
  //#endregion
47
- export { Config, DEFAULT_PRESET_ROOT, PRESET_ID, SelfInstallResult, apply, installPreset, name };
14
+ export { Config, apply, getPresetContribution, name };
package/lib/index.js CHANGED
@@ -1,108 +1,18 @@
1
- import { createHash } from "node:crypto";
2
- import { mkdir, readFile, writeFile } from "node:fs/promises";
3
- import { homedir } from "node:os";
4
- import { join } from "node:path";
5
- import { fileURLToPath } from "node:url";
1
+ import { readFile } from "node:fs/promises";
6
2
  import Schema from "@deepseek-ai/schemastery";
7
3
  //#region src/index.ts
8
- /**
9
- * @dshtrading/hk — hk 市场 bundle。包承载两块实质内容(实装形态抄 @dshtrading/us):
10
- *
11
- * 1. `cordis.patch.yml`(由 package.json 的 `dsh.bundle.patch` 声明):insert-only
12
- * 聚合本 bundle 的 host 面常驻行(铁律 #1)。connector/kit 两行在 preset 的
13
- * agent.cordis.yml(preset 级会话隔离,见 assets/preset/hk-trader/)。
14
- * 2. `dsh-trading-hk-installer` 插件(本模块):hk-trader preset 幂等自安装(S3 机制)。
15
- * 自安装职责必须在 bundle(host 面常驻)而非 kit 插件——kit 行在 preset 平面,
16
- * preset 不存在时 kit.apply() 永不运行,鸡生蛋(2026-08-29 主 agent 结构性修复)。
17
- *
18
- * cn/hk 是**同一个 connector-tencent 插件包的两个实例**(单包双市场,手册 §8):
19
- * 本 bundle 的 preset 行挂 market=hk 实例(提供 tradingHkMarketData + hk_* 工具)。
20
- *
21
- * @module @dshtrading/hk
22
- */
23
- /**
24
- * Cordis 插件名 = patch 行 id(TEMPLATES §8):`dsh-trading-hk-*` 市场命名空间,
25
- * 全仓唯一(insert-only 铁律 #1)。
26
- */
4
+ /** Market bundle capability source. @dshtrading/base/presets is the sole preset writer. */
27
5
  const name = "dsh-trading-hk-installer";
28
6
  const Config = Schema.object({ presetRoot: Schema.string() });
29
- const PRESET_ID = "hk-trader";
30
- /** 默认安装 root:市场自有目录(S3 建议——绝不写进 ~/.dsh/.agent-presets 用户创作区)。 */
31
- const DEFAULT_PRESET_ROOT = join(homedir(), ".dsh-trading-presets");
32
- /** 预置资产随本包分发(bundle 是市场组装点,preset 资产归 bundle 所有)。 */
33
- const PRESET_ASSET_DIR = fileURLToPath(new URL("../assets/preset/", import.meta.url));
34
- const PRESET_FILES = ["agent.cordis.yml", "preset.yml"];
35
- /** 管理戳注释行前缀:托管安装文件的头行,值 = shipped 内容(不含戳行)的 SHA-256 前 8 位。 */
36
- const MANAGED_STAMP_PREFIX = "# dsh-trading-managed: ";
37
- function contentSha8(content) {
38
- return createHash("sha256").update(content, "utf8").digest("hex").slice(0, 8);
39
- }
40
- /** 提取已安装文件头行的管理戳;null = 无戳(文件视为用户所有)。 */
41
- function readManagedStamp(current) {
42
- if (!current.startsWith(MANAGED_STAMP_PREFIX)) return null;
43
- const stamp = (current.includes("\n") ? current.slice(0, current.indexOf("\n")) : current).slice(23).trim();
44
- return /^[0-9a-f]{8}$/.test(stamp) ? stamp : null;
45
- }
46
- /** 已安装文件去掉管理戳头行后的正文。 */
47
- function bodyAfterStamp(current) {
48
- return current.includes("\n") ? current.slice(current.indexOf("\n") + 1) : "";
49
- }
50
- /**
51
- * 幂等自安装 preset(S3 机制 + 2026-08-29 代际管理戳升级):mkdir -p + 逐文件按管理戳
52
- * 三代裁决——
53
- *
54
- * 1. 目标不存在 → 写入(头行 = `# dsh-trading-managed: <内容sha前8>` + shipped 内容);
55
- * 2. 目标存在且带本包可识别的管理戳(托管文件)→ 正文与 shipped 内容不同则整文件更新
56
- * (以新代际覆盖——戳即「本文件归安装器托管」的约定);
57
- * 3. 目标存在但无管理戳(用户改过/前代安装器所装)→ 跳过并记录提示(删除该文件即可
58
- * 让安装器重新提供)。
59
- *
60
- * 迁移注意:代际升级前由旧安装器写入的已装文件没有管理戳,按第 3 条处理(跳过 + log
61
- * 提示)——宁可不更新,绝不覆盖用户改动。
62
- *
63
- * 卸载本 bundle 不删除已安装目录(有意为之):升级/重装后再次 apply 即恢复一致;本包
64
- * 被移除后 preset 行不可解析只会得到带原因的 broken 行,无进程崩溃(S3 REPORT broken 语义)。
65
- * preset 引用的插件包必须进本 bundle 的 dependencies(S3 坑 3),见 package.json。
66
- */
67
- async function installPreset(options = {}) {
68
- const dir = join(options.presetRoot ?? DEFAULT_PRESET_ROOT, PRESET_ID);
69
- await mkdir(dir, { recursive: true });
70
- const wrote = [];
71
- const skipped = [];
72
- for (const file of PRESET_FILES) {
73
- const content = await readFile(join(PRESET_ASSET_DIR, PRESET_ID, file), "utf8");
74
- const stamped = `${MANAGED_STAMP_PREFIX}${contentSha8(content)}\n${content}`;
75
- const target = join(dir, file);
76
- let current = null;
77
- try {
78
- current = await readFile(target, "utf8");
79
- } catch {}
80
- if (current === null) {
81
- await writeFile(target, stamped);
82
- wrote.push(file);
83
- continue;
84
- }
85
- if (readManagedStamp(current) === null) {
86
- skipped.push(`${file} (no management stamp — user-modified file left untouched; delete it to let the installer re-provision it)`);
87
- continue;
88
- }
89
- if (bodyAfterStamp(current) !== content) {
90
- await writeFile(target, stamped);
91
- wrote.push(file);
92
- }
93
- }
7
+ async function getPresetContribution() {
8
+ const asset = (await readFile(new URL("../assets/preset/hk-trader/agent.cordis.yml", import.meta.url), "utf8")).replace(/\r\n/g, "\n");
9
+ const start = asset.indexOf("- id: dsh-trading-hk-connector-group\n");
10
+ if (start < 0) throw new Error("Missing hk capability rows");
94
11
  return {
95
- dir,
96
- wrote,
97
- skipped
12
+ market: "hk",
13
+ traderRows: asset.slice(start)
98
14
  };
99
15
  }
100
- function logger(ctx) {
101
- const service = ctx.logger;
102
- return typeof service === "function" ? service(name) : console;
103
- }
104
- function apply(ctx, config) {
105
- installPreset({ presetRoot: config?.presetRoot }).then((result) => logger(ctx).info("[dsh-trading-hk-installer] self-install %s preset at %s wrote=[%s] skipped=[%s]", PRESET_ID, result.dir, result.wrote.join(",") || "nothing — already current", result.skipped.join("; ") || "none"), (error) => logger(ctx).warn("[dsh-trading-hk-installer] hk-trader preset self-install failed: %s", error));
106
- }
16
+ function apply() {}
107
17
  //#endregion
108
- export { Config, DEFAULT_PRESET_ROOT, PRESET_ID, apply, installPreset, name };
18
+ export { Config, apply, getPresetContribution, name };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@dshtrading/hk",
3
3
  "description": "HK (Hong Kong) market bundle for dsh-trading: host-plane hk-trader preset installer + insert-only aggregation of the Tencent connector (market=hk instance) and hk kit rows (design rule #1)",
4
- "version": "0.1.3",
4
+ "version": "0.1.5",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
7
7
  "types": "./lib/index.d.ts",
@@ -25,11 +25,11 @@
25
25
  }
26
26
  },
27
27
  "dependencies": {
28
- "@dshtrading/connector-futu": "0.1.3",
29
- "@dshtrading/connector-longbridge": "0.1.3",
30
- "@dshtrading/connector-tencent": "0.1.3",
31
- "@dshtrading/connector-tiger": "0.1.3",
32
- "@dshtrading/kit-hk": "0.1.3"
28
+ "@dshtrading/connector-futu": "0.1.5",
29
+ "@dshtrading/connector-longbridge": "0.1.5",
30
+ "@dshtrading/connector-tencent": "0.1.5",
31
+ "@dshtrading/connector-tiger": "0.1.5",
32
+ "@dshtrading/kit-hk": "0.1.5"
33
33
  },
34
34
  "peerDependencies": {
35
35
  "@deepseek-ai/cordis": ">=4.0.0",