@huaqiu/dsh-pcb-initial-placement 0.0.0-stage → 0.7.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 深圳华秋智联股份有限公司
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,48 @@
1
- # Temporary Holding Version
1
+ # @huaqiu/dsh-pcb-initial-placement
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Phase-1 PCB initial-placement skill for DeepSeek Harness, shipped as a
4
+ standalone DSH skill plugin.
5
+
6
+ This package is the extracted `pcb-initial-placement` skill: it used to ride
7
+ inside `@huaqiu/dsh-kicad`, which meant installing the KiCad plugin always
8
+ installed this skill too. Splitting it out makes the skill independently
9
+ installable, and lets each distribution choose for itself:
10
+
11
+ | Distribution | Choice |
12
+ |---|---|
13
+ | HQ Edge (headless, `kicad` host) | bundles it — the catalog entry in `release-manifest/plugins-release-manifest.json` is what its packaging discovers |
14
+ | Standalone desktop (`@huaqiu/hardware-engineering`) | deliberately not a dependency, so desktop installs stay opt-in |
15
+
16
+ ## What You Get
17
+
18
+ ```
19
+ @huaqiu/dsh-pcb-initial-placement
20
+ └── Skill pcb-initial-placement — SKILL.md + references/ + agents/ + scripts/
21
+ ```
22
+
23
+ No DSH tools are registered. The skill's executable half is its own Python
24
+ helpers (`scripts/*.py`), which the agent runs itself: stage the board through
25
+ the KiCad IPC API, fall back to an offline `.kicad_pcb` write only when IPC is
26
+ unavailable.
27
+
28
+ ## How The Plugin Is Wired
29
+
30
+ ```yaml
31
+ - insert:
32
+ - id: huaqiu-dsh-pcb-initial-placement
33
+ name: '@huaqiu/dsh-pcb-initial-placement'
34
+ inject: ['skills']
35
+ ```
36
+
37
+ `skills` is the DSH runtime's plugin-bundled skill registry. `apply()`
38
+ registers the skill and returns a disposer.
39
+
40
+ Resolution is package-relative — `<package>/lib/index.mjs` →
41
+ `<package>/skills/pcb-initial-placement` — which is why `files[]` contains
42
+ `skills`; otherwise npm would strip the skill from the published artifact.
43
+
44
+ ## Runtime Requirements
45
+
46
+ - A DSH runtime providing the `skills` service.
47
+ - For the IPC path: a running KiCad with the IPC API enabled (see SKILL.md for
48
+ the exact prerequisites and the offline fallback).
@@ -0,0 +1,20 @@
1
+ # DSH bundle patch: inserts the Huaqiu PCB initial-placement skill plugin.
2
+ #
3
+ # This package exists so `pcb-initial-placement` can be installed ON ITS OWN
4
+ # instead of arriving as baggage of `@huaqiu/dsh-kicad`'s skill bundle:
5
+ #
6
+ # - HQ Edge discovers it from `plugins-release-manifest.json` and bundles it
7
+ # into the headless runtime (kicad host only — the skill drives KiCad IPC);
8
+ # - the standalone desktop product bundle (@huaqiu/hardware-engineering)
9
+ # deliberately does NOT list it: desktop installs stay opt-in.
10
+ #
11
+ # The row registers exactly one skill (`ctx.skills.register()`) and no tools:
12
+ # the skill's executable halves are its own Python scripts under `scripts/`,
13
+ # which the agent runs itself (see SKILL.md).
14
+ #
15
+ # The entry `inject` MUST match the node-half module contract (`src/index.ts`
16
+ # `export const inject`): `skills`.
17
+ - insert:
18
+ - id: huaqiu-dsh-pcb-initial-placement
19
+ name: '@huaqiu/dsh-pcb-initial-placement'
20
+ inject: ['skills']
@@ -0,0 +1,107 @@
1
+ import { Context } from "@deepseek-ai/cordis";
2
+ //#region src/config.d.ts
3
+ /**
4
+ * Configuration for `@huaqiu/dsh-pcb-initial-placement`.
5
+ *
6
+ * The plugin carries one knowledge skill plus its Python helpers. Nothing here
7
+ * connects to KiCad: the skill tells the agent how to drive the KiCad IPC API
8
+ * itself, so there is no host/port/timeout configuration to resolve.
9
+ *
10
+ * @module
11
+ */
12
+ /** Canonical skill directory name shipped by this package. */
13
+ declare const PCB_INITIAL_PLACEMENT_SKILL_NAME = "pcb-initial-placement";
14
+ /** Configuration accepted by the plugin's `apply()`. */
15
+ interface PcbInitialPlacementConfig {
16
+ /** Bundled skill directory override (defaults to this package's skills/). */
17
+ skillsDir?: string;
18
+ }
19
+ type PcbInitialPlacementConfigInput = Partial<PcbInitialPlacementConfig>;
20
+ //#endregion
21
+ //#region src/paths.d.ts
22
+ /**
23
+ * Absolute path of the bundled skill directory.
24
+ *
25
+ * Resolution order: explicit override, `DSH_PCB_INITIAL_PLACEMENT_SKILLS_DIR`,
26
+ * then the package-relative location.
27
+ */
28
+ declare function resolveSkillDir(moduleUrl: string, override?: string): string;
29
+ /**
30
+ * Resolve the skill directory and assert the skill is actually present.
31
+ *
32
+ * @throws when `SKILL.md` is missing.
33
+ */
34
+ declare function requireSkillDir(moduleUrl: string, override?: string): string;
35
+ //#endregion
36
+ //#region src/index.d.ts
37
+ /** Plugin id — matches package.json. */
38
+ declare const name = "@huaqiu/dsh-pcb-initial-placement";
39
+ /**
40
+ * `skills` is REQUIRED: it is the DSH runtime's plugin-bundled skill registry,
41
+ * and registering the skill is this plugin's entire job.
42
+ */
43
+ declare const inject: readonly ["skills"];
44
+ /** The `skills` service shape consumed by this plugin. */
45
+ interface SkillRegistration {
46
+ /** Skill id — must match DSH's discoverable skill id format. */
47
+ name: string;
48
+ /** Catalog description shown to the model. */
49
+ description: string;
50
+ /** Full SKILL.md body. */
51
+ content: string;
52
+ /** Discovery source for plugin-bundled skills. */
53
+ source: 'runtime';
54
+ /** Where `references/` and `scripts/` live for progressive disclosure. */
55
+ resourceBase: {
56
+ kind: 'directory';
57
+ path: string;
58
+ };
59
+ }
60
+ declare module '@deepseek-ai/cordis' {
61
+ interface Context {
62
+ /** DSH skill registry, provided by the runtime skill service. */
63
+ skills: {
64
+ /** Register a plugin-bundled skill; returns its unregister disposer. */
65
+ register(skill: SkillRegistration): () => void;
66
+ };
67
+ }
68
+ }
69
+ /**
70
+ * Extract the `description` field from SKILL.md YAML frontmatter.
71
+ *
72
+ * Supports single-line quoted values and the folded block form
73
+ * (`description: >-` followed by indented lines).
74
+ */
75
+ declare function skillDescription(markdown: string): string | undefined;
76
+ /** Read the bundled skill as a ready-to-register record. */
77
+ declare function readBundledSkill(moduleUrl: string, override?: string): {
78
+ dir: string;
79
+ name: string;
80
+ description: string;
81
+ content: string;
82
+ };
83
+ /**
84
+ * Read the bundled skill, or `null` when the installed package does not carry
85
+ * it.
86
+ *
87
+ * A missing `skills/` tree is a packaging failure, but the right blast radius
88
+ * is "this skill is unavailable", not "the whole DSH plugin tree aborts": the
89
+ * same rule `@huaqiu/dsh-kicad` follows, so a bad tarball never takes the EDA
90
+ * session down with it.
91
+ */
92
+ declare function tryReadBundledSkill(moduleUrl: string, override?: string): {
93
+ dir: string;
94
+ name: string;
95
+ description: string;
96
+ content: string;
97
+ } | null;
98
+ /**
99
+ * Host plugin body — register the bundled skill.
100
+ *
101
+ * @param ctx - real cordis context (node side).
102
+ * @param config - plugin overlay config (skills directory override).
103
+ * @returns disposer — unregisters the skill on plugin dispose.
104
+ */
105
+ declare function apply(ctx: Context, config?: PcbInitialPlacementConfigInput): () => void;
106
+ //#endregion
107
+ export { PCB_INITIAL_PLACEMENT_SKILL_NAME, type PcbInitialPlacementConfig, type PcbInitialPlacementConfigInput, SkillRegistration, apply, inject, name, readBundledSkill, requireSkillDir, resolveSkillDir, skillDescription, tryReadBundledSkill };
package/lib/index.mjs ADDED
@@ -0,0 +1,173 @@
1
+ import { getLogger } from "@huaqiu/dsh-plugin-log";
2
+ import { existsSync, readFileSync } from "node:fs";
3
+ import { dirname, join, resolve } from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+ //#region src/config.ts
6
+ /**
7
+ * Configuration for `@huaqiu/dsh-pcb-initial-placement`.
8
+ *
9
+ * The plugin carries one knowledge skill plus its Python helpers. Nothing here
10
+ * connects to KiCad: the skill tells the agent how to drive the KiCad IPC API
11
+ * itself, so there is no host/port/timeout configuration to resolve.
12
+ *
13
+ * @module
14
+ */
15
+ /** Canonical skill directory name shipped by this package. */
16
+ const PCB_INITIAL_PLACEMENT_SKILL_NAME = "pcb-initial-placement";
17
+ /** Environment variable mirroring {@link PcbInitialPlacementConfig.skillsDir}. */
18
+ const SKILLS_DIR_ENV = "DSH_PCB_INITIAL_PLACEMENT_SKILLS_DIR";
19
+ /** Whether any skill-directory override was supplied (used for startup logging). */
20
+ function hasSkillsDirOverride(input = {}) {
21
+ return Boolean(input.skillsDir ?? process.env["DSH_PCB_INITIAL_PLACEMENT_SKILLS_DIR"]);
22
+ }
23
+ //#endregion
24
+ //#region src/paths.ts
25
+ /**
26
+ * Resolution of the bundled `pcb-initial-placement` skill directory.
27
+ *
28
+ * The skill ships inside the installed package
29
+ * (`<pkg>/skills/pcb-initial-placement/`). Resolving relative to the loaded
30
+ * module works for source tests, built artifacts and npm installs alike.
31
+ *
32
+ * @module
33
+ */
34
+ /**
35
+ * Absolute path of the bundled skill directory.
36
+ *
37
+ * Resolution order: explicit override, `DSH_PCB_INITIAL_PLACEMENT_SKILLS_DIR`,
38
+ * then the package-relative location.
39
+ */
40
+ function resolveSkillDir(moduleUrl, override) {
41
+ if (override && override.trim().length > 0) return resolve(override);
42
+ const envOverride = process.env[SKILLS_DIR_ENV];
43
+ if (envOverride && envOverride.trim().length > 0) return resolve(envOverride);
44
+ const here = dirname(fileURLToPath(moduleUrl));
45
+ return resolve(here, "..", "skills", PCB_INITIAL_PLACEMENT_SKILL_NAME);
46
+ }
47
+ /**
48
+ * Resolve the skill directory and assert the skill is actually present.
49
+ *
50
+ * @throws when `SKILL.md` is missing.
51
+ */
52
+ function requireSkillDir(moduleUrl, override) {
53
+ const dir = resolveSkillDir(moduleUrl, override);
54
+ const skillFile = join(dir, "SKILL.md");
55
+ if (!existsSync(skillFile)) throw new Error(`@huaqiu/dsh-pcb-initial-placement: bundled skill missing at ${skillFile}. The installed package is incomplete; reinstall @huaqiu/dsh-pcb-initial-placement so that its skills/ directory is present.`);
56
+ return dir;
57
+ }
58
+ //#endregion
59
+ //#region src/index.ts
60
+ /** Plugin id — matches package.json. */
61
+ const name = "@huaqiu/dsh-pcb-initial-placement";
62
+ /**
63
+ * `skills` is REQUIRED: it is the DSH runtime's plugin-bundled skill registry,
64
+ * and registering the skill is this plugin's entire job.
65
+ */
66
+ const inject = ["skills"];
67
+ const log = getLogger("dsh-pcb-initial-placement");
68
+ log.info("dsh-pcb-initial-placement: module loaded (waiting for the skills service)");
69
+ /**
70
+ * Fallback catalogue description, used only when SKILL.md frontmatter has no
71
+ * parseable `description` (the shipped file is authoritative).
72
+ */
73
+ const FALLBACK_SKILL_DESCRIPTION = "Phase-1 initial placement for a KiCad PCB that has a netlist but no layout: functional clustering, anchor placement, zone partitioning, overlap-free packing and a handover report, applied through the KiCad IPC API.";
74
+ /**
75
+ * Extract the `description` field from SKILL.md YAML frontmatter.
76
+ *
77
+ * Supports single-line quoted values and the folded block form
78
+ * (`description: >-` followed by indented lines).
79
+ */
80
+ function skillDescription(markdown) {
81
+ const frontmatter = /^---\r?\n([\s\S]*?)\r?\n---/.exec(markdown);
82
+ if (!frontmatter?.[1]) return void 0;
83
+ const lines = frontmatter[1].split(/\r?\n/);
84
+ const lineIndex = lines.findIndex((candidate) => /^\s*description\s*:/.test(candidate));
85
+ if (lineIndex < 0) return void 0;
86
+ const raw = lines[lineIndex].slice(lines[lineIndex].indexOf(":") + 1).trim();
87
+ if (raw === ">-" || raw === ">" || raw === "|-" || raw === "|") {
88
+ const block = [];
89
+ for (const line of lines.slice(lineIndex + 1)) {
90
+ if (/^\s+\S/.test(line)) {
91
+ block.push(line.trim());
92
+ continue;
93
+ }
94
+ if (line.trim().length === 0) continue;
95
+ break;
96
+ }
97
+ const text = block.join(" ").trim();
98
+ return text.length > 0 ? text : void 0;
99
+ }
100
+ const unquoted = raw.replace(/^["']/, "").replace(/["']$/, "");
101
+ return unquoted.length > 0 ? unquoted : void 0;
102
+ }
103
+ /** Read the bundled skill as a ready-to-register record. */
104
+ function readBundledSkill(moduleUrl, override) {
105
+ const dir = requireSkillDir(moduleUrl, override);
106
+ const content = readFileSync(join(dir, "SKILL.md"), "utf8");
107
+ return {
108
+ dir,
109
+ name: PCB_INITIAL_PLACEMENT_SKILL_NAME,
110
+ description: skillDescription(content) ?? FALLBACK_SKILL_DESCRIPTION,
111
+ content
112
+ };
113
+ }
114
+ /**
115
+ * Read the bundled skill, or `null` when the installed package does not carry
116
+ * it.
117
+ *
118
+ * A missing `skills/` tree is a packaging failure, but the right blast radius
119
+ * is "this skill is unavailable", not "the whole DSH plugin tree aborts": the
120
+ * same rule `@huaqiu/dsh-kicad` follows, so a bad tarball never takes the EDA
121
+ * session down with it.
122
+ */
123
+ function tryReadBundledSkill(moduleUrl, override) {
124
+ try {
125
+ return readBundledSkill(moduleUrl, override);
126
+ } catch (err) {
127
+ log.error("dsh-pcb-initial-placement: bundled skill unavailable — the plugin stays loaded without registering it; reinstall the package to restore it", {
128
+ expectedDir: resolveSkillDir(moduleUrl, override),
129
+ error: String(err?.message ?? err)
130
+ });
131
+ return null;
132
+ }
133
+ }
134
+ /**
135
+ * Host plugin body — register the bundled skill.
136
+ *
137
+ * @param ctx - real cordis context (node side).
138
+ * @param config - plugin overlay config (skills directory override).
139
+ * @returns disposer — unregisters the skill on plugin dispose.
140
+ */
141
+ function apply(ctx, config = {}) {
142
+ if (!ctx.skills || typeof ctx.skills.register !== "function") throw new Error("@huaqiu/dsh-pcb-initial-placement requires the DSH `skills` service (ctx.skills.register).");
143
+ const skill = tryReadBundledSkill(import.meta.url, config.skillsDir);
144
+ log.info("applying dsh-pcb-initial-placement node half", {
145
+ hasSkillsDirOverride: hasSkillsDirOverride(config),
146
+ skillDir: skill?.dir ?? resolveSkillDir(import.meta.url, config.skillsDir),
147
+ skillPresent: skill !== null
148
+ });
149
+ const disposers = [];
150
+ if (skill) disposers.push(ctx.skills.register({
151
+ name: skill.name,
152
+ description: skill.description,
153
+ content: skill.content,
154
+ source: "runtime",
155
+ resourceBase: {
156
+ kind: "directory",
157
+ path: skill.dir
158
+ }
159
+ }));
160
+ log.info("dsh-pcb-initial-placement node half ready", {
161
+ skill: skill?.name ?? null,
162
+ degraded: skill === null
163
+ });
164
+ return () => {
165
+ for (const dispose of disposers.reverse()) try {
166
+ dispose();
167
+ } catch (err) {
168
+ log.warn("dsh-pcb-initial-placement disposer failed", { error: String(err?.message ?? err) });
169
+ }
170
+ };
171
+ }
172
+ //#endregion
173
+ export { PCB_INITIAL_PLACEMENT_SKILL_NAME, apply, inject, name, readBundledSkill, requireSkillDir, resolveSkillDir, skillDescription, tryReadBundledSkill };
package/package.json CHANGED
@@ -1,6 +1,54 @@
1
1
  {
2
2
  "name": "@huaqiu/dsh-pcb-initial-placement",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.7.19",
4
+ "type": "module",
5
+ "description": "Huaqiu PCB initial-placement skill for DeepSeek Harness, shipped as a standalone DSH skill plugin.",
6
+ "keywords": [
7
+ "dsh",
8
+ "dsh-plugin",
9
+ "huaqiu",
10
+ "kicad",
11
+ "pcb",
12
+ "skill"
13
+ ],
14
+ "license": "MIT",
15
+ "main": "./lib/index.mjs",
16
+ "types": "./lib/index.d.mts",
17
+ "exports": {
18
+ ".": {
19
+ "types": "./lib/index.d.mts",
20
+ "default": "./lib/index.mjs"
21
+ },
22
+ "./cordis.patch.yml": "./cordis.patch.yml",
23
+ "./package.json": "./package.json"
24
+ },
25
+ "dsh": {
26
+ "bundle": {
27
+ "patch": "./cordis.patch.yml"
28
+ }
29
+ },
30
+ "engines": {
31
+ "dsh": "^0.2.2-rc.1"
32
+ },
33
+ "peerDependencies": {
34
+ "@deepseek-ai/cordis": "^4.0.1"
35
+ },
36
+ "dependencies": {
37
+ "@huaqiu/dsh-plugin-log": "0.7.19"
38
+ },
39
+ "files": [
40
+ "lib",
41
+ "src",
42
+ "skills",
43
+ "cordis.patch.yml",
44
+ "README.md"
45
+ ],
46
+ "publishConfig": {
47
+ "access": "public"
48
+ },
49
+ "scripts": {
50
+ "typecheck": "tsc --noEmit",
51
+ "build": "tsdown",
52
+ "test": "vitest run"
53
+ }
6
54
  }