@heybox/hb-sdk 0.8.0-alpha.2 → 0.8.0-alpha.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.
Files changed (41) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +20 -0
  3. package/dist/cli-chunks/{build-CCLWgXyA.cjs → build-qWzAbpS7.cjs} +2 -2
  4. package/dist/cli-chunks/{context-Brh56h56.cjs → context-CtS2Thp0.cjs} +1 -1
  5. package/dist/cli-chunks/{create-BZ-hi2s1.cjs → create-PV5ua977.cjs} +1 -1
  6. package/dist/cli-chunks/{dev-CoSXtEYa.cjs → dev-CwKbAm_H.cjs} +10 -14
  7. package/dist/cli-chunks/doctor-tJUGOYrm.cjs +65 -0
  8. package/dist/cli-chunks/{index-CS6Q0o5C.cjs → index-DVuD75Hr.cjs} +1 -1
  9. package/dist/cli-chunks/{index-BL5eEPap.cjs → index-De687C6-.cjs} +33 -24
  10. package/dist/cli-chunks/{index.esm-BoBHPfpq.cjs → index.esm-B-4yrLNm.cjs} +6 -5
  11. package/dist/cli-chunks/{login-CILLxGuf.cjs → login-DolpqD8K.cjs} +2 -2
  12. package/dist/cli-chunks/{project-vite-Qu6Xe9Dn.cjs → project-vite-1rvkK-M8.cjs} +1 -1
  13. package/dist/cli-chunks/{remote-DRuTQ51u.cjs → remote-rIAQE_G2.cjs} +4 -4
  14. package/dist/cli-chunks/{session-D-_N3WVL.cjs → session-CzaM2Cq3.cjs} +1 -1
  15. package/dist/cli-chunks/skill-CM40_9WH.cjs +83 -0
  16. package/dist/cli-chunks/version-Bz-AfXQU.cjs +8 -0
  17. package/dist/cli.cjs +1 -1
  18. package/dist/index.cjs.js +1 -1
  19. package/dist/index.esm.js +1 -1
  20. package/dist/vite.cjs.js +1 -1
  21. package/dist/vite.esm.js +1 -1
  22. package/package.json +12 -7
  23. package/skill/SKILL.md +7 -8
  24. package/skill/references/api-protocol.md +2 -2
  25. package/skill/references/api-root.md +2 -2
  26. package/skill/references/cli.md +6 -5
  27. package/skill/references/examples.md +1 -1
  28. package/skill/references/llms-index.md +1 -1
  29. package/skill/references/recipes.md +1 -1
  30. package/skill/references/safety-boundaries.md +1 -1
  31. package/skill/skill.json +10 -5
  32. package/types/skill-metadata.d.ts +0 -4
  33. package/dist/cli-chunks/doctor-EsCYJGhV.cjs +0 -204
  34. package/skill/scripts/check-references.mjs +0 -14
  35. package/skill/scripts/markdown-sections.mjs +0 -36
  36. package/skill/scripts/package-skill.mjs +0 -60
  37. package/skill/scripts/package-skill.sh +0 -6
  38. package/skill/scripts/skill-metadata.mjs +0 -77
  39. package/skill/scripts/sync-agent-skills-payload.mjs +0 -359
  40. package/skill/scripts/sync-references.mjs +0 -826
  41. package/skill/scripts/validate-skill.mjs +0 -263
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heybox/hb-sdk",
3
- "version": "0.8.0-alpha.2",
3
+ "version": "0.8.0-alpha.3",
4
4
  "sideEffects": [
5
5
  "./src/index.ts",
6
6
  "./src/core/singleton.ts",
@@ -53,12 +53,16 @@
53
53
  "keywords": [],
54
54
  "author": "",
55
55
  "license": "ISC",
56
+ "engines": {
57
+ "node": ">=22.20.0"
58
+ },
56
59
  "dependencies": {
57
60
  "@msgpack/msgpack": "2.8.0",
58
61
  "parse5": "^7.3.0",
62
+ "skills": "1.5.23",
59
63
  "undici": "^7.28.0",
60
64
  "ws": "^8.18.0",
61
- "@heybox/hb-sdk-protocol": "0.8.0-alpha.2"
65
+ "@heybox/hb-sdk-protocol": "0.8.0-alpha.3"
62
66
  },
63
67
  "peerDependencies": {
64
68
  "vite": ">=5"
@@ -108,13 +112,13 @@
108
112
  "vue-tsc": "^3.3.7",
109
113
  "vite": "^8.0.12",
110
114
  "vitest": "^3.2.4",
115
+ "@heybox-domain/heybox-theme": "~0.1.0",
111
116
  "@heybox-domain/heybox-vue3-ui": "~0.1.0",
117
+ "@heybox/hb-sdk-runtime": "~0.8.0-alpha.3",
118
+ "@heybox/hb-api": "~1.25.23",
112
119
  "@heybox/runtime-policy": "~0.2.0",
113
- "@heybox-domain/heybox-theme": "~0.1.0",
114
120
  "@heybox/runtime-transport-fetch": "~0.2.0",
115
- "@heybox/hb-api": "~1.25.23",
116
- "@heybox/runtime": "~0.2.0",
117
- "@heybox/hb-sdk-runtime": "~0.8.0-alpha.2"
121
+ "@heybox/runtime": "~0.2.0"
118
122
  },
119
123
  "publishConfig": {
120
124
  "registry": "https://registry.npmjs.org/",
@@ -162,7 +166,7 @@
162
166
  "build:templates": "node scripts/copy-cli-templates.cjs",
163
167
  "build:types": "tsc -p tsconfig.dts.json",
164
168
  "check:boundary": "node scripts/check-boundary.cjs",
165
- "check:docs-sync": "pnpm -w exec hbexec hb-sdk check",
169
+ "check:docs-sync": "pnpm --filter @heybox-docs/docs-hb_sdk run check:reference && node scripts/skill/check-references.mjs && node scripts/skill/validate-skill.mjs",
166
170
  "check:compatibility-evidence": "node scripts/validate-compatibility-evidence.mjs",
167
171
  "check:api-semver": "node ../../ops/jobs/hb-sdk-docs-contract/semantic-diff.cjs",
168
172
  "clean": "rimraf ./dist && rimraf ./types",
@@ -176,6 +180,7 @@
176
180
  "test:watch": "NODE_OPTIONS='--conditions=heybox' vitest",
177
181
  "changelog:draft": "node scripts/changelog-draft.cjs",
178
182
  "check:changelog": "node scripts/check-changelog.cjs",
183
+ "release:verify-tarball": "node scripts/skill/verify-tarball-install.mjs",
179
184
  "test:release": "node --test scripts/release-family.test.cjs ../../ops/jobs/publish-changed-packages/publish.test.cjs ../../ops/jobs/release-hb-sdk/docs-release-contract.test.cjs",
180
185
  "test:compatibility-evidence": "node --test scripts/validate-compatibility-evidence.test.mjs",
181
186
  "release:prepare": "node scripts/release-prepare.cjs",
package/skill/SKILL.md CHANGED
@@ -114,17 +114,16 @@ For host/runtime/protocol-maintenance code:
114
114
  - `cat packages/hb-sdk/DOC_SYNC_CHECKLIST.md`
115
115
  3. When preparing a package release, run `pnpm --filter @heybox/hb-sdk run release:prepare -- --bump patch` or `pnpm --filter @heybox/hb-sdk run release:prepare -- --version <x.y.z>`. The release assistant updates the Protocol/Runtime/SDK family versions, inserts `packages/hb-sdk/CHANGELOG.md`, and runs `check:changelog`. Use `--ai-command "<command>"` or `HB_SDK_CHANGELOG_AI_COMMAND` when an AI writer should rewrite the Conventional Commit draft. Review the entry for Mini-program developers and Host/Runtime integration maintainers, and do not expose Runtime internal adapter, state-machine, or security-policy details.
116
116
  4. When modifying this repo's source skill at `packages/hb-sdk/skill` and preparing distributable artifacts, also run:
117
- - `node packages/hb-sdk/skill/scripts/package-skill.mjs`
117
+ - `node packages/hb-sdk/scripts/skill/sync-references.mjs`
118
+ - `node packages/hb-sdk/scripts/skill/validate-skill.mjs`
118
119
  5. When modifying CLI, local debugging, package exports, or package dependency direction, also run:
119
120
  - `pnpm --filter @heybox/hb-sdk run check:boundary`
120
121
  - `pnpm --filter @heybox/hb-sdk run test:unit`
121
- 6. Inspect the generated zip before distribution:
122
- - `unzip -l packages/hb-sdk/hb-sdk.zip | sed -n '1,120p'`
123
- 7. When adding or modifying the deploy command or its upload pipeline, also run:
122
+ 6. When adding or modifying the deploy command or its upload pipeline, also run:
124
123
  - `pnpm --filter @heybox/hb-sdk run check:boundary`
125
124
  - `pnpm --filter @heybox/hb-sdk run test:unit`
126
125
  - Verify `dist/cli.cjs` does not have any `require('cos-nodejs-sdk-v5')` left after `build:cli`; the boundary check enforces this automatically.
127
- 8. Verify the canonical payload before publishing:
128
- - `pnpm exec hbexec hb-sdk sync`
129
- - `pnpm exec hbexec hb-sdk check`
130
- - For a release artifact, run `pnpm exec hbexec hb-sdk sync --out-dir <payload-dir>` and then `pnpm exec hbexec hb-sdk check-artifact --artifact-dir <payload-dir>`.
126
+ 7. Verify the canonical payload before publishing:
127
+ - `node packages/hb-sdk/scripts/skill/sync-references.mjs`
128
+ - `node packages/hb-sdk/scripts/skill/validate-skill.mjs`
129
+ - For a release artifact, run `npm pack --dry-run` and `node packages/hb-sdk/scripts/skill/verify-tarball-install.mjs`.
@@ -1,6 +1,6 @@
1
1
  # Protocol API reference
2
2
 
3
- > Generated by `node packages/hb-sdk/skill/scripts/sync-references.mjs` from the public hb-sdk source/docs. Do not edit by hand; update sources or this generator instead.
3
+ > Generated by `node packages/hb-sdk/scripts/skill/sync-references.mjs` from the public hb-sdk source/docs. Do not edit by hand; update sources or this generator instead.
4
4
 
5
5
  ## Sources
6
6
 
@@ -302,7 +302,7 @@ Reference 由 `@heybox/hb-sdk` 的公开导出与源码注释自动生成,不
302
302
  | Miniapp Publish API | 0 | 5 | 2 | 0 | 0 |
303
303
  | Vite API | 0 | 1 | 5 | 1 | 1 |
304
304
 
305
- <!-- Generated by apps/docs/hb-sdk/scripts/generate-api-docs.ts; schemaVersion=2; fingerprint=904f09f0012164f5d6b18c0f93477bb2bd541a41b99da8f270d0a40b93e96602 -->
305
+ <!-- Generated by apps/docs/hb-sdk/scripts/generate-api-docs.ts; schemaVersion=2; fingerprint=cb985ad876f7066639ee3b72d545185f251ed6ad597b8276425e02615bb608ba -->
306
306
 
307
307
  ## SDK API
308
308
 
@@ -1,6 +1,6 @@
1
1
  # Root API reference
2
2
 
3
- > Generated by `node packages/hb-sdk/skill/scripts/sync-references.mjs` from the public hb-sdk source/docs. Do not edit by hand; update sources or this generator instead.
3
+ > Generated by `node packages/hb-sdk/scripts/skill/sync-references.mjs` from the public hb-sdk source/docs. Do not edit by hand; update sources or this generator instead.
4
4
 
5
5
  ## Sources
6
6
 
@@ -24,7 +24,7 @@
24
24
  ## Package metadata
25
25
 
26
26
  - Package: `@heybox/hb-sdk`
27
- - Version at generation time: `0.8.0-alpha.2`
27
+ - Version at generation time: `0.8.0-alpha.3`
28
28
  - Public root export: `@heybox/hb-sdk`
29
29
  - Protocol export: `@heybox/hb-sdk/protocol`
30
30
  - Vite plugin export: `@heybox/hb-sdk/vite`
@@ -1,6 +1,6 @@
1
1
  # CLI reference
2
2
 
3
- > Generated by `node packages/hb-sdk/skill/scripts/sync-references.mjs` from the public hb-sdk source/docs. Do not edit by hand; update sources or this generator instead.
3
+ > Generated by `node packages/hb-sdk/scripts/skill/sync-references.mjs` from the public hb-sdk source/docs. Do not edit by hand; update sources or this generator instead.
4
4
 
5
5
  ## Sources
6
6
 
@@ -40,7 +40,8 @@ hb-sdk build [--env <name>] [--verbose]
40
40
  hb-sdk login
41
41
  hb-sdk login status
42
42
  hb-sdk login clear
43
- hb-sdk doctor
43
+ hb-sdk skill install [--global] [--agent <agent>] [--all-agents] [--force]
44
+ hb-sdk doctor [--agent <agent>] [--all-agents] [--json]
44
45
  hb-sdk remote access
45
46
  hb-sdk remote entity list
46
47
  hb-sdk remote entity current
@@ -272,8 +273,8 @@ Agent rules:
272
273
 
273
274
  Agent rules:
274
275
 
275
- - Use `hb-sdk doctor` for read-only diagnosis of local SDK, remote latest skill metadata, and local skill metadata.
276
- - Do not use `hb-sdk doctor` to auto-install skills; when installation or refresh is needed, tell the user to run `npx skills add https://open.xiaoheihe.cn/agent-skills/hb-sdk`.
277
- - If doctor reports `SDK_MISMATCH`, tell the user to upgrade `@heybox/hb-sdk@latest` before reinstalling the skill.
276
+ - Use `hb-sdk doctor [--agent <agent>] [--all-agents] [--json]` for read-only diagnosis of the locally installed SDK and its bundled Skill.
277
+ - Use `hb-sdk skill install` to install or refresh the Skill bundled with the matching npm package. Add `--global` for user scope, `--agent <agent>` for one Agent, or `--all-agents` for every supported Agent.
278
+ - If doctor reports `SDK_MISMATCH`, upgrade the project dependency to the matching @heybox/hb-sdk version before reinstalling the skill.
278
279
 
279
280
  ## Update reminders
@@ -1,6 +1,6 @@
1
1
  # Smoke examples and anti-examples
2
2
 
3
- > Generated by `node packages/hb-sdk/skill/scripts/sync-references.mjs` from the public hb-sdk source/docs. Do not edit by hand; update sources or this generator instead.
3
+ > Generated by `node packages/hb-sdk/scripts/skill/sync-references.mjs` from the public hb-sdk source/docs. Do not edit by hand; update sources or this generator instead.
4
4
 
5
5
  ## Sources
6
6
 
@@ -1,6 +1,6 @@
1
1
  # LLM documentation index
2
2
 
3
- > Generated by `node packages/hb-sdk/skill/scripts/sync-references.mjs` from the public hb-sdk source/docs. Do not edit by hand; update sources or this generator instead.
3
+ > Generated by `node packages/hb-sdk/scripts/skill/sync-references.mjs` from the public hb-sdk source/docs. Do not edit by hand; update sources or this generator instead.
4
4
 
5
5
  ## Sources
6
6
 
@@ -1,6 +1,6 @@
1
1
  # Recipes
2
2
 
3
- > Generated by `node packages/hb-sdk/skill/scripts/sync-references.mjs` from the public hb-sdk source/docs. Do not edit by hand; update sources or this generator instead.
3
+ > Generated by `node packages/hb-sdk/scripts/skill/sync-references.mjs` from the public hb-sdk source/docs. Do not edit by hand; update sources or this generator instead.
4
4
 
5
5
  ## Sources
6
6
 
@@ -1,6 +1,6 @@
1
1
  # Safety boundaries
2
2
 
3
- > Generated by `node packages/hb-sdk/skill/scripts/sync-references.mjs` from the public hb-sdk source/docs. Do not edit by hand; update sources or this generator instead.
3
+ > Generated by `node packages/hb-sdk/scripts/skill/sync-references.mjs` from the public hb-sdk source/docs. Do not edit by hand; update sources or this generator instead.
4
4
 
5
5
  ## Sources
6
6
 
package/skill/skill.json CHANGED
@@ -1,11 +1,16 @@
1
1
  {
2
2
  "name": "hb-sdk",
3
- "skillVersion": "0.8.0-alpha.2+skill.417e5072238c",
3
+ "skillVersion": "0.8.0-alpha.3+skill.9d9d09c2d52c",
4
4
  "sdk": {
5
5
  "package": "@heybox/hb-sdk",
6
- "version": "0.8.0-alpha.2",
7
- "compatibility": "0.8.0-alpha.2"
6
+ "version": "0.8.0-alpha.3",
7
+ "compatibility": "0.8.0-alpha.3"
8
8
  },
9
- "source": "https://open.xiaoheihe.cn/agent-skills/hb-sdk",
10
- "integrity": "sha256-417e5072238c0b2a53836824d60639046935ad28ca337a63d82016421c97127b"
9
+ "distribution": {
10
+ "type": "npm",
11
+ "package": "@heybox/hb-sdk",
12
+ "version": "0.8.0-alpha.3",
13
+ "path": "skill"
14
+ },
15
+ "integrity": "sha256-9d9d09c2d52ce6fca7e0ea48bcfa51bad464502d92e32e97dd0d1cad321fae52"
11
16
  }
@@ -1,6 +1,2 @@
1
1
  export declare const HB_SDK_PACKAGE_NAME = "@heybox/hb-sdk";
2
2
  export declare const HB_SDK_SKILL_NAME = "hb-sdk";
3
- export declare const HB_SDK_AGENT_SKILLS_BASE_URL = "https://open.xiaoheihe.cn/agent-skills";
4
- export declare const HB_SDK_SKILL_SOURCE = "https://open.xiaoheihe.cn/agent-skills/hb-sdk";
5
- export declare const HB_SDK_SKILL_INDEX_URL = "https://open.xiaoheihe.cn/agent-skills/.well-known/agent-skills/index.json";
6
- export declare const HB_SDK_SKILL_INSTALL_COMMAND = "npx skills add https://open.xiaoheihe.cn/agent-skills/hb-sdk";
@@ -1,204 +0,0 @@
1
- 'use strict';
2
-
3
- var fs$1 = require('node:fs');
4
- var fs = require('node:fs/promises');
5
- var os = require('node:os');
6
- var path = require('node:path');
7
- var index = require('./index-BL5eEPap.cjs');
8
- require('node:module');
9
- require('path');
10
- require('os');
11
- require('readline');
12
- require('tty');
13
- require('assert');
14
- require('events');
15
- require('stream');
16
- require('buffer');
17
- require('util');
18
-
19
- const DEFAULT_TIMEOUT_MS = 3000;
20
- const PACKAGE_JSON_CANDIDATES = [
21
- path.resolve(__dirname, '..', 'package.json'),
22
- path.resolve(__dirname, '..', '..', 'package.json'),
23
- path.resolve(__dirname, '..', '..', '..', 'package.json'),
24
- ];
25
- async function runDoctorCommand(runtime = {}) {
26
- const logger = runtime.logger ?? index.createCliLogger();
27
- const result = await logger.task('正在检查 Agent Skill 元数据', () => getDoctorResult(runtime), {
28
- successText: 'Agent Skill 检查完成',
29
- });
30
- printDoctorResult(result, logger);
31
- printDoctorNextStep(result, logger);
32
- return result;
33
- }
34
- async function getDoctorResult(runtime = {}) {
35
- const currentSdkVersion = await readCurrentSdkVersion(runtime.packageJsonFiles);
36
- const localSkillJsonPath = await resolveLocalSkillJsonPath(runtime);
37
- let remoteSkill;
38
- try {
39
- remoteSkill = await fetchRemoteSkill(runtime);
40
- }
41
- catch {
42
- return {
43
- currentSdkVersion,
44
- localSkillJsonPath,
45
- status: 'REMOTE_UNAVAILABLE',
46
- };
47
- }
48
- if (remoteSkill?.sdk?.version !== currentSdkVersion) {
49
- return {
50
- currentSdkVersion,
51
- localSkillJsonPath,
52
- remoteSkill,
53
- status: 'SDK_MISMATCH',
54
- };
55
- }
56
- const localSkill = await readLocalSkillManifest(localSkillJsonPath);
57
- if (!localSkill.exists) {
58
- return {
59
- currentSdkVersion,
60
- localSkillJsonPath,
61
- remoteSkill,
62
- status: 'SKILL_MISSING',
63
- };
64
- }
65
- if (!localSkill.manifest ||
66
- localSkill.manifest.name !== index.HB_SDK_SKILL_NAME ||
67
- localSkill.manifest.skillVersion !== remoteSkill.version ||
68
- localSkill.manifest.sdk?.version !== remoteSkill.sdk?.version) {
69
- return {
70
- currentSdkVersion,
71
- localSkillJsonPath,
72
- localSkillVersion: localSkill.manifest?.skillVersion,
73
- remoteSkill,
74
- status: 'SKILL_OUTDATED',
75
- };
76
- }
77
- return {
78
- currentSdkVersion,
79
- localSkillJsonPath,
80
- localSkillVersion: localSkill.manifest.skillVersion,
81
- remoteSkill,
82
- status: 'OK',
83
- };
84
- }
85
- function printDoctorResult(result, logger) {
86
- logger.section('Doctor');
87
- logger.info(`SDK version: ${result.currentSdkVersion}`);
88
- logger.info(`Remote skill: ${result.remoteSkill?.version ? `${result.remoteSkill.version} (sdk ${result.remoteSkill.sdk?.version ?? 'unknown'})` : 'unavailable'}`);
89
- logger.info(`Local skill: ${result.localSkillVersion ?? 'missing'}`);
90
- logger.debug(`Local skill path: ${result.localSkillJsonPath}`);
91
- logger.info(`Status: ${result.status}`);
92
- }
93
- function printDoctorNextStep(result, logger) {
94
- if (result.status === 'OK') {
95
- logger.success('Skill is up to date.');
96
- return;
97
- }
98
- if (result.status === 'SDK_MISMATCH') {
99
- logger.warn(`Current SDK does not match the latest skill metadata. Upgrade with: npm i -D ${index.HB_SDK_PACKAGE_NAME}@latest`);
100
- logger.info(`Then install or refresh the skill manually: ${formatSkillInstallCommand(result)}`);
101
- return;
102
- }
103
- if (result.status === 'REMOTE_UNAVAILABLE') {
104
- logger.warn('Remote skill metadata is unavailable. Try again later.');
105
- logger.info(`Manual install command: ${index.HB_SDK_SKILL_INSTALL_COMMAND}`);
106
- return;
107
- }
108
- logger.info(`Install or refresh the skill manually: ${formatSkillInstallCommand(result)}`);
109
- }
110
- function formatSkillInstallCommand(result) {
111
- return `npx skills add ${result.remoteSkill?.source || index.HB_SDK_SKILL_SOURCE}`;
112
- }
113
- async function fetchRemoteSkill(runtime) {
114
- const fetchImpl = runtime.fetchImpl ?? fetch;
115
- const controller = new AbortController();
116
- const timeout = setTimeout(() => controller.abort(), runtime.timeoutMs ?? DEFAULT_TIMEOUT_MS);
117
- try {
118
- const response = await fetchImpl(runtime.remoteIndexUrl ?? index.HB_SDK_SKILL_INDEX_URL, {
119
- headers: {
120
- accept: 'application/json',
121
- },
122
- signal: controller.signal,
123
- });
124
- if (!response.ok) {
125
- throw new Error(`remote skill index returned ${response.status}`);
126
- }
127
- const index$1 = (await response.json());
128
- const skill = index$1.skills?.find(item => item.name === index.HB_SDK_SKILL_NAME);
129
- if (!skill?.version || skill.sdk?.package !== index.HB_SDK_PACKAGE_NAME || !skill.sdk.version) {
130
- throw new Error('remote hb-sdk skill metadata is incomplete');
131
- }
132
- return skill;
133
- }
134
- finally {
135
- clearTimeout(timeout);
136
- }
137
- }
138
- async function readLocalSkillManifest(skillJsonPath) {
139
- if (!(await pathExists(skillJsonPath))) {
140
- return {
141
- exists: false,
142
- };
143
- }
144
- try {
145
- return {
146
- exists: true,
147
- manifest: JSON.parse(await fs.readFile(skillJsonPath, 'utf8')),
148
- };
149
- }
150
- catch {
151
- return {
152
- exists: true,
153
- };
154
- }
155
- }
156
- async function readCurrentSdkVersion(packageJsonCandidates = PACKAGE_JSON_CANDIDATES) {
157
- for (const candidate of packageJsonCandidates) {
158
- if (!(await pathExists(candidate))) {
159
- continue;
160
- }
161
- const packageJson = JSON.parse(await fs.readFile(candidate, 'utf8'));
162
- if (typeof packageJson.version === 'string' && packageJson.version) {
163
- return packageJson.version;
164
- }
165
- }
166
- throw new Error('未能读取 @heybox/hb-sdk 当前版本号');
167
- }
168
- async function resolveLocalSkillJsonPath(runtime) {
169
- if (runtime.localSkillJsonPath) {
170
- return runtime.localSkillJsonPath;
171
- }
172
- const projectSkillJsonPath = await findProjectSkillJsonPath(runtime.cwd ?? process.cwd());
173
- if (projectSkillJsonPath) {
174
- return projectSkillJsonPath;
175
- }
176
- const codexHome = runtime.codexHome ?? runtime.env?.CODEX_HOME ?? process.env.CODEX_HOME ?? path.join(os.homedir(), '.codex');
177
- return path.join(codexHome, 'skills', index.HB_SDK_SKILL_NAME, 'skill.json');
178
- }
179
- async function findProjectSkillJsonPath(startDir) {
180
- let current = path.resolve(startDir);
181
- while (true) {
182
- const skillJsonPath = path.join(current, '.agents', 'skills', index.HB_SDK_SKILL_NAME, 'skill.json');
183
- if ((await pathExists(path.join(current, 'package.json'))) && (await pathExists(skillJsonPath))) {
184
- return skillJsonPath;
185
- }
186
- const parent = path.dirname(current);
187
- if (parent === current) {
188
- return undefined;
189
- }
190
- current = parent;
191
- }
192
- }
193
- async function pathExists(filePath) {
194
- try {
195
- await fs.access(filePath, fs$1.constants.F_OK);
196
- return true;
197
- }
198
- catch {
199
- return false;
200
- }
201
- }
202
-
203
- exports.getDoctorResult = getDoctorResult;
204
- exports.runDoctorCommand = runDoctorCommand;
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env node
2
- import { spawnSync } from 'node:child_process';
3
- import path from 'node:path';
4
- import { fileURLToPath } from 'node:url';
5
- import process from 'node:process';
6
-
7
- const scriptPath = path.join(path.dirname(fileURLToPath(import.meta.url)), 'sync-references.mjs');
8
- const result = spawnSync(process.execPath, [scriptPath, '--check'], {
9
- cwd: process.cwd(),
10
- encoding: 'utf8',
11
- stdio: 'inherit',
12
- });
13
-
14
- process.exit(result.status ?? 1);
@@ -1,36 +0,0 @@
1
- export function extractSection(markdown, heading) {
2
- const lines = markdown.split('\n');
3
- const start = lines.findIndex((line) => line.trim() === heading);
4
- if (start === -1) return '';
5
- const level = heading.match(/^#+/)?.[0].length ?? 2;
6
- const out = [lines[start]];
7
- let fenceChar = '';
8
- for (let index = start + 1; index < lines.length; index += 1) {
9
- const line = lines[index];
10
- const fenceMatch = line.match(/^\s*(`{3,}|~{3,})/);
11
-
12
- if (fenceChar) {
13
- out.push(line);
14
- if (fenceMatch?.[1]?.startsWith(fenceChar)) fenceChar = '';
15
- continue;
16
- }
17
-
18
- if (fenceMatch) {
19
- fenceChar = fenceMatch[1][0];
20
- out.push(line);
21
- continue;
22
- }
23
-
24
- const headingMatch = line.match(/^(#+)\s/);
25
- if (headingMatch && headingMatch[1].length <= level) break;
26
- out.push(line);
27
- }
28
- return out.join('\n').trimEnd();
29
- }
30
-
31
- export function replaceRequiredSection(markdown, heading, replacement) {
32
- const section = extractSection(markdown, heading);
33
- if (!section) throw new Error(`sync-references: 未找到待覆盖章节 ${heading}`);
34
- const start = markdown.indexOf(section);
35
- return `${markdown.slice(0, start)}${replacement.trimEnd()}${markdown.slice(start + section.length)}`;
36
- }
@@ -1,60 +0,0 @@
1
- #!/usr/bin/env node
2
- import { cpSync, existsSync, mkdtempSync, rmSync } from 'node:fs';
3
- import { spawnSync } from 'node:child_process';
4
- import { tmpdir } from 'node:os';
5
- import path from 'node:path';
6
- import { fileURLToPath } from 'node:url';
7
- import process from 'node:process';
8
- import { HB_SDK_SKILL_NAME } from './skill-metadata.mjs';
9
-
10
- const scriptDir = path.dirname(fileURLToPath(import.meta.url));
11
- const skillDir = path.resolve(scriptDir, '..');
12
- const packageRoot = path.resolve(skillDir, '..');
13
- const skillName = HB_SDK_SKILL_NAME;
14
- const repoRoot = findRepoRoot(process.cwd()) ?? packageRoot;
15
- const zipPath = path.join(packageRoot, `${skillName}.zip`);
16
-
17
- function findRepoRoot(startDir) {
18
- let dir = path.resolve(startDir);
19
- while (true) {
20
- if (existsSync(path.join(dir, 'package.json')) && existsSync(path.join(dir, 'packages/hb-sdk/package.json'))) {
21
- return dir;
22
- }
23
- const parent = path.dirname(dir);
24
- if (parent === dir) return null;
25
- dir = parent;
26
- }
27
- }
28
-
29
- if (!existsSync(path.join(skillDir, 'SKILL.md'))) {
30
- console.error(`Missing ${path.relative(repoRoot, path.join(skillDir, 'SKILL.md'))}.`);
31
- process.exit(1);
32
- }
33
-
34
- if (existsSync(zipPath)) rmSync(zipPath);
35
-
36
- const tempRoot = mkdtempSync(path.join(tmpdir(), 'hb-sdk-skill-'));
37
- const packagedSkillRoot = path.join(tempRoot, skillName);
38
-
39
- try {
40
- cpSync(skillDir, packagedSkillRoot, { recursive: true });
41
-
42
- const result = spawnSync(
43
- 'zip',
44
- ['-r', zipPath, skillName, '-x', `${skillName}/README.md`, '-x', `${skillName}/**/.DS_Store`],
45
- {
46
- cwd: tempRoot,
47
- encoding: 'utf8',
48
- },
49
- );
50
-
51
- if (result.status !== 0) {
52
- process.stderr.write(result.stderr || result.stdout);
53
- process.exit(result.status ?? 1);
54
- }
55
-
56
- console.error(result.stdout.trim());
57
- console.log(JSON.stringify({ ok: true, zip: path.relative(repoRoot, zipPath).split(path.sep).join('/') }));
58
- } finally {
59
- rmSync(tempRoot, { recursive: true, force: true });
60
- }
@@ -1,6 +0,0 @@
1
- #!/bin/bash
2
- set -euo pipefail
3
-
4
- SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
5
- echo "Packaging hb-sdk skill" >&2
6
- node "$SCRIPT_DIR/package-skill.mjs"
@@ -1,77 +0,0 @@
1
- import { createHash } from 'node:crypto';
2
-
3
- export const HB_SDK_SKILL_NAME = 'hb-sdk';
4
- export const HB_SDK_PACKAGE_NAME = '@heybox/hb-sdk';
5
- export const HB_SDK_AGENT_SKILLS_BASE_URL = 'https://open.xiaoheihe.cn/agent-skills';
6
- export const HB_SDK_SKILL_SOURCE = `${HB_SDK_AGENT_SKILLS_BASE_URL}/${HB_SDK_SKILL_NAME}`;
7
- export const HB_SDK_SKILL_INDEX_URL = `${HB_SDK_AGENT_SKILLS_BASE_URL}/.well-known/agent-skills/index.json`;
8
- export const HB_SDK_SKILL_INSTALL_COMMAND = `npx skills add ${HB_SDK_SKILL_SOURCE}`;
9
-
10
- export function createSkillContentHash(fileEntries) {
11
- const hash = createHash('sha256');
12
-
13
- for (const entry of [...fileEntries].sort((left, right) => left.path.localeCompare(right.path))) {
14
- hash.update(entry.path);
15
- hash.update('\0');
16
- hash.update(entry.content);
17
- hash.update('\0');
18
- }
19
-
20
- return {
21
- hex: hash.digest('hex'),
22
- };
23
- }
24
-
25
- export function createSkillManifest({ contentHash, sdkVersion }) {
26
- const shortHash = contentHash.hex.slice(0, 12);
27
-
28
- return {
29
- name: HB_SDK_SKILL_NAME,
30
- skillVersion: `${sdkVersion}+skill.${shortHash}`,
31
- sdk: {
32
- package: HB_SDK_PACKAGE_NAME,
33
- version: sdkVersion,
34
- compatibility: sdkVersion,
35
- },
36
- source: HB_SDK_SKILL_SOURCE,
37
- integrity: `sha256-${contentHash.hex}`,
38
- };
39
- }
40
-
41
- export function validateSkillManifest({ manifest, sdkVersion }) {
42
- const errors = [];
43
-
44
- if (manifest?.name !== HB_SDK_SKILL_NAME) {
45
- errors.push(`skill.json name must be \`${HB_SDK_SKILL_NAME}\`.`);
46
- }
47
-
48
- if (manifest?.sdk?.package !== HB_SDK_PACKAGE_NAME) {
49
- errors.push(`skill.json sdk.package must be \`${HB_SDK_PACKAGE_NAME}\`.`);
50
- }
51
-
52
- if (manifest?.sdk?.version !== sdkVersion) {
53
- errors.push('skill.json sdk.version must match packages/hb-sdk/package.json version.');
54
- }
55
-
56
- if (manifest?.sdk?.compatibility !== sdkVersion) {
57
- errors.push('skill.json sdk.compatibility must match packages/hb-sdk/package.json version.');
58
- }
59
-
60
- if (typeof manifest?.skillVersion !== 'string' || !manifest.skillVersion.startsWith(`${sdkVersion}+skill.`)) {
61
- errors.push('skill.json skillVersion must be derived from the current SDK version.');
62
- }
63
-
64
- if (manifest?.source !== HB_SDK_SKILL_SOURCE) {
65
- errors.push('skill.json source must be the public hb-sdk skill URL.');
66
- }
67
-
68
- if (typeof manifest?.integrity !== 'string' || !/^sha256-[0-9a-f]{64}$/.test(manifest.integrity)) {
69
- errors.push('skill.json integrity must be a sha256 hex digest.');
70
- }
71
-
72
- return errors;
73
- }
74
-
75
- export function normalizeSkillManifest(manifest) {
76
- return `${JSON.stringify(manifest, null, 2)}\n`;
77
- }