@heybox/hb-sdk 0.8.0-alpha → 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 (64) hide show
  1. package/CHANGELOG.md +44 -1
  2. package/README.md +87 -14
  3. package/THIRD_PARTY_NOTICES.md +1755 -0
  4. package/dist/cli-chunks/{build-DJWFSM1B.cjs → build-qWzAbpS7.cjs} +2 -2
  5. package/dist/cli-chunks/{context-DV2UK1Nz.cjs → context-CtS2Thp0.cjs} +1 -26
  6. package/dist/cli-chunks/{create-2HfoB48V.cjs → create-PV5ua977.cjs} +1 -1
  7. package/dist/cli-chunks/{dev-Dgt2zS9k.cjs → dev-CwKbAm_H.cjs} +337 -522
  8. package/dist/cli-chunks/doctor-tJUGOYrm.cjs +65 -0
  9. package/dist/cli-chunks/{index-BjoSXl8C.cjs → index-DVuD75Hr.cjs} +1 -1
  10. package/dist/cli-chunks/{index-D62ANeBv.cjs → index-De687C6-.cjs} +33 -24
  11. package/dist/cli-chunks/{index.esm-CigcxJ2B.cjs → index.esm-B-4yrLNm.cjs} +6 -5
  12. package/dist/cli-chunks/{login-Cumknwdx.cjs → login-DolpqD8K.cjs} +2 -2
  13. package/dist/cli-chunks/{project-vite-CcE-HMmd.cjs → project-vite-1rvkK-M8.cjs} +1 -1
  14. package/dist/cli-chunks/{remote-DDdP3xcE.cjs → remote-rIAQE_G2.cjs} +4 -4
  15. package/dist/cli-chunks/{session-BDi_AZSv.cjs → session-CzaM2Cq3.cjs} +1 -1
  16. package/dist/cli-chunks/skill-CM40_9WH.cjs +83 -0
  17. package/dist/cli-chunks/version-Bz-AfXQU.cjs +8 -0
  18. package/dist/cli.cjs +1 -1
  19. package/dist/devtools/browser-dev-host/assets/browser-dev-host-uq-Wac6k.js +97 -0
  20. package/dist/devtools/browser-dev-host/assets/heybox-logo-CogNENsk.svg +6 -0
  21. package/dist/devtools/browser-dev-host/assets/index-CeP6SLB3.js +567 -0
  22. package/dist/devtools/browser-dev-host/assets/index-KD2f3Jdz.css +1 -0
  23. package/dist/devtools/browser-dev-host/assets/workbench-state-D-1U0JRq.js +5 -0
  24. package/dist/devtools/browser-dev-host/index.html +6 -435
  25. package/dist/index.cjs.js +924 -28
  26. package/dist/index.esm.js +924 -29
  27. package/dist/protocol.cjs.js +208 -6
  28. package/dist/protocol.esm.js +182 -7
  29. package/dist/vite.cjs.js +1 -1
  30. package/dist/vite.esm.js +1 -1
  31. package/package.json +29 -10
  32. package/skill/SKILL.md +16 -13
  33. package/skill/references/api-protocol.md +100 -4
  34. package/skill/references/api-root.md +142 -15
  35. package/skill/references/cli.md +27 -22
  36. package/skill/references/examples.md +30 -1
  37. package/skill/references/llms-index.md +1 -1
  38. package/skill/references/recipes.md +106 -2
  39. package/skill/references/safety-boundaries.md +12 -1
  40. package/skill/skill.json +10 -5
  41. package/types/core/client.d.ts +17 -1
  42. package/types/core/sdk.d.ts +3 -0
  43. package/types/core/singleton.d.ts +3 -0
  44. package/types/index.d.ts +4 -2
  45. package/types/modules/files/index.d.ts +5 -0
  46. package/types/modules/files/registry.d.ts +35 -0
  47. package/types/modules/files/types.d.ts +159 -0
  48. package/types/modules/network/index.d.ts +50 -3
  49. package/types/protocol/capabilities.d.ts +2 -2
  50. package/types/protocol/constants.d.ts +1 -1
  51. package/types/protocol/guards.d.ts +1 -1
  52. package/types/protocol/types.d.ts +1 -1
  53. package/types/protocol.d.ts +4 -3
  54. package/types/skill-metadata.d.ts +0 -4
  55. package/dist/cli-chunks/doctor-C95gIao_.cjs +0 -204
  56. package/dist/devtools/browser-dev-host/main.js +0 -12263
  57. package/skill/scripts/check-references.mjs +0 -14
  58. package/skill/scripts/markdown-sections.mjs +0 -36
  59. package/skill/scripts/package-skill.mjs +0 -60
  60. package/skill/scripts/package-skill.sh +0 -6
  61. package/skill/scripts/skill-metadata.mjs +0 -77
  62. package/skill/scripts/sync-agent-skills-payload.mjs +0 -359
  63. package/skill/scripts/sync-references.mjs +0 -794
  64. package/skill/scripts/validate-skill.mjs +0 -263
@@ -1 +1 @@
1
- export { MINI_PROGRAM_BRIDGE_NONCE_PARAM, MINI_PROGRAM_MESSAGE_NAMESPACE, MINI_PROGRAM_MESSAGE_VERSION, RUNTIME_LOCATION_PROBE_METHOD, SDK_CSP_VIOLATION_METHOD, SDK_HANDSHAKE_METHOD, SDK_LOCATION_REPORT_METHOD, } from '@heybox/hb-sdk-protocol';
1
+ export { MINI_PROGRAM_BRIDGE_NONCE_PARAM, MINI_PROGRAM_MESSAGE_NAMESPACE, MINI_PROGRAM_MESSAGE_VERSION, MINI_PROGRAM_OPERATION_PROGRESS_METHOD, RUNTIME_LOCATION_PROBE_METHOD, SDK_CSP_VIOLATION_METHOD, SDK_HANDSHAKE_METHOD, SDK_LOCATION_REPORT_METHOD, } from '@heybox/hb-sdk-protocol';
@@ -1 +1 @@
1
- export { isMiniProgramBridgeMessage } from '@heybox/hb-sdk-protocol';
1
+ export { isMiniProgramBridgeMessage, isMiniProgramByteArray, isMiniProgramDirectoryDescriptor, isMiniProgramDirectoryRef, isMiniProgramDownloadProgressPayload, isMiniProgramFileDescriptor, isMiniProgramFileRef, isMiniProgramFileStat, isMiniProgramFileSystemEntityDescriptor, isMiniProgramPathRootRef, isMiniProgramRelativePath, } from '@heybox/hb-sdk-protocol';
@@ -1,4 +1,4 @@
1
1
  import type { MiniProgramEventName, MiniProgramEventPayloadMap } from '@heybox/hb-sdk-protocol';
2
- export type { MiniProgramBridgeError, MiniProgramBridgeMessage, MiniProgramBridgeMessageType, MiniProgramEventName, MiniProgramEventPayloadMap, RuntimeLocationProbePayload, SDKCSPBlockedResourceType, SDKCSPViolationPayload, SDKHandshakePayload, SDKLocationReportPayload, SDKLocationReportTrigger, } from '@heybox/hb-sdk-protocol';
2
+ export type { MiniProgramBridgeError, MiniProgramBridgeCancelMessage, MiniProgramBridgeMessage, MiniProgramBridgeMessageType, MiniProgramBridgeProgressMessage, MiniProgramEventName, MiniProgramEventPayloadMap, RuntimeLocationProbePayload, SDKCSPBlockedResourceType, SDKCSPViolationPayload, SDKHandshakePayload, SDKLocationReportPayload, SDKLocationReportTrigger, } from '@heybox/hb-sdk-protocol';
3
3
  /** 小程序事件监听函数。 */
4
4
  export type MiniProgramEventHandler<T extends MiniProgramEventName = MiniProgramEventName> = (payload: MiniProgramEventPayloadMap[T]) => void;
@@ -1,8 +1,9 @@
1
- export { AUTH_LOGIN_METHOD, CLOUD_LEADERBOARD_DELETE_CURRENT_USER_ENTRY_METHOD, CLOUD_LEADERBOARD_GET_CURRENT_USER_ENTRY_METHOD, CLOUD_LEADERBOARD_GET_INFO_METHOD, CLOUD_LEADERBOARD_GET_LIST_METHOD, CLOUD_LEADERBOARD_SUBMIT_METHOD, DEVICE_SET_CLIPBOARD_METHOD, DEVICE_VIBRATE_METHOD, MINI_PROGRAM_BRIDGE_NONCE_PARAM, MINI_PROGRAM_MESSAGE_NAMESPACE, MINI_PROGRAM_MESSAGE_VERSION, MINI_PROGRAM_PROTOCOL_CAPABILITIES, NAVIGATION_CLOSE_METHOD, NAVIGATION_OPEN_APP_PAGE_METHOD, NAVIGATION_RELOAD_METHOD, NETWORK_REQUEST_METHOD, RUNTIME_LOCATION_PROBE_METHOD, SDK_CSP_VIOLATION_METHOD, SDK_HANDSHAKE_METHOD, SDK_LOCATION_REPORT_METHOD, SHARE_COPY_LINK_METHOD, SHARE_SCREENSHOT_METHOD, SHARE_SHOW_SHARE_MENU_METHOD, STORAGE_GET_STORAGE_METHOD, STORAGE_SET_STORAGE_METHOD, UI_HIDE_LOADING_METHOD, UI_SHOW_LOADING_METHOD, UI_SHOW_TOAST_METHOD, USER_INFO_AUTHORIZATION_SCOPES, USER_GET_INFO_METHOD, USER_GET_STEAM_GAME_LIST_METHOD, USER_REVOKE_AUTHORIZATION_METHOD, VIEWPORT_GET_WINDOW_INFO_METHOD, VIEWPORT_SET_NAVIGATION_BAR_STYLE_METHOD, isManagedMiniProgramRuntimePermissionKey, isMiniProgramBridgeMessage, parseMiniProgramRuntimePermissions, } from '@heybox/hb-sdk-protocol';
2
- export type { AuthorizedUserInfo, ClosePayload, CloseResult, CopyLinkPayload, CopyLinkResult, DeleteCurrentUserLeaderboardEntryPayload, DeleteCurrentUserLeaderboardEntryResult, GetCurrentUserLeaderboardEntryPayload, GetCurrentUserLeaderboardEntryResult, GetLeaderboardInfoPayload, GetLeaderboardInfoResult, GetLeaderboardListPayload, GetLeaderboardListResult, GetSteamGameListPayload, GetSteamGameListResult, GetStoragePayload, GetStorageResult, GetUserInfoPayload, GetUserInfoResult, GetWindowInfoPayload, GetWindowInfoResult, HideLoadingPayload, HideLoadingResult, LeaderboardEntry, LeaderboardOrder, LoginPayload, LoginResult, LoginScope, MiniProgramAuthMethod, MiniProgramBridgeError, MiniProgramBridgeMessage, MiniProgramBridgeMessageType, MiniProgramBridgeMethod, MiniProgramCapabilityDefinition, MiniProgramCapabilityModule, MiniProgramCapabilityPayload, MiniProgramCapabilityPayloadMap, MiniProgramCapabilityResult, MiniProgramCapabilityResultMap, MiniProgramCapabilityRisk, MiniProgramCloudMethod, MiniProgramDeviceMethod, MiniProgramEventName, MiniProgramEventPayloadMap, MiniProgramNavigationBarForegroundStyle, MiniProgramNavigationMethod, MiniProgramNetworkHeaders, MiniProgramNetworkMethod, MiniProgramNetworkParams, MiniProgramNetworkRequestMethod, MiniProgramRuntimePermissionEntry, MiniProgramRuntimePermissionsSnapshot, MiniProgramRuntimePermissionStatus, MiniProgramSafeArea, MiniProgramScreenshotRect, MiniProgramShareChannel, MiniProgramShareMethod, MiniProgramSharePostOptions, MiniProgramStorageMethod, MiniProgramToastStatus, MiniProgramUiMethod, MiniProgramUserInfoResult, MiniProgramUserMethod, MiniProgramVibrateIntensity, MiniProgramViewportMethod, MiniProgramWindowInfoResult, NetworkRequestPayload, NetworkResponsePayload, OpenAppPagePayload, OpenAppPageResult, OpenGameDetailAppPagePayload, OpenPostDetailAppPagePayload, OpenUserDetailAppPagePayload, ParsedMiniProgramRuntimePermissions, ReloadPayload, ReloadResult, RevokeAuthorizationPayload, RevokeAuthorizationResult, RuntimeLocationProbePayload, ScreenshotPayload, ScreenshotResult, SDKCSPBlockedResourceType, SDKCSPViolationPayload, SDKHandshakePayload, SDKLocationReportPayload, SDKLocationReportTrigger, SetClipboardPayload, SetClipboardResult, SetNavigationBarStylePayload, SetNavigationBarStyleResult, SetStoragePayload, ShowLoadingPayload, ShowLoadingResult, ShowShareMenuPayload, ShowShareMenuResult, ShowToastPayload, ShowToastResult, SteamGameListData, SteamGameListItem, SteamGameListSort, SteamGamePrice, SubmitLeaderboardEntryPayload, SubmitLeaderboardEntryResult, UserInfoAuthorization, UserInfoAuthorizationScope, UserInfoAuthorizationStatus, VibratePayload, VibrateResult, } from '@heybox/hb-sdk-protocol';
1
+ export { AUTH_LOGIN_METHOD, CLOUD_LEADERBOARD_DELETE_CURRENT_USER_ENTRY_METHOD, CLOUD_LEADERBOARD_GET_CURRENT_USER_ENTRY_METHOD, CLOUD_LEADERBOARD_GET_INFO_METHOD, CLOUD_LEADERBOARD_GET_LIST_METHOD, CLOUD_LEADERBOARD_SUBMIT_METHOD, DIRECTORY_CREATE_METHOD, DIRECTORY_EXISTS_METHOD, DIRECTORY_LIST_METHOD, DIRECTORY_REMOVE_METHOD, DEVICE_SET_CLIPBOARD_METHOD, DEVICE_VIBRATE_METHOD, FILES_PICK_DIRECTORY_METHOD, FILES_PICK_FILES_METHOD, FILES_SAVE_FILE_METHOD, FILE_CREATE_METHOD, FILE_EXISTS_METHOD, FILE_READ_BYTES_METHOD, FILE_READ_TEXT_METHOD, FILE_REMOVE_METHOD, FILE_STAT_METHOD, FILE_WRITE_BYTES_METHOD, FILE_WRITE_TEXT_METHOD, MINI_PROGRAM_BRIDGE_NONCE_PARAM, MINI_PROGRAM_MESSAGE_NAMESPACE, MINI_PROGRAM_MESSAGE_VERSION, MINI_PROGRAM_OPERATION_PROGRESS_METHOD, MINI_PROGRAM_PROTOCOL_CAPABILITIES, NAVIGATION_CLOSE_METHOD, NAVIGATION_OPEN_APP_PAGE_METHOD, NAVIGATION_RELOAD_METHOD, NETWORK_REQUEST_METHOD, NETWORK_DOWNLOAD_METHOD, RUNTIME_LOCATION_PROBE_METHOD, SDK_CSP_VIOLATION_METHOD, SDK_HANDSHAKE_METHOD, SDK_LOCATION_REPORT_METHOD, SHARE_COPY_LINK_METHOD, SHARE_SCREENSHOT_METHOD, SHARE_SHOW_SHARE_MENU_METHOD, STORAGE_GET_STORAGE_METHOD, STORAGE_SET_STORAGE_METHOD, UI_HIDE_LOADING_METHOD, UI_SHOW_LOADING_METHOD, UI_SHOW_TOAST_METHOD, USER_INFO_AUTHORIZATION_SCOPES, USER_GET_INFO_METHOD, USER_GET_STEAM_GAME_LIST_METHOD, USER_REVOKE_AUTHORIZATION_METHOD, VIEWPORT_GET_WINDOW_INFO_METHOD, VIEWPORT_SET_NAVIGATION_BAR_STYLE_METHOD, isManagedMiniProgramRuntimePermissionKey, isMiniProgramByteArray, isMiniProgramBridgeMessage, isMiniProgramDirectoryDescriptor, isMiniProgramDirectoryRef, isMiniProgramDownloadProgressPayload, isMiniProgramFileDescriptor, isMiniProgramFileRef, isMiniProgramFileStat, isMiniProgramFileSystemEntityDescriptor, isMiniProgramPathRootRef, isMiniProgramRelativePath, parseMiniProgramRuntimePermissions, } from '@heybox/hb-sdk-protocol';
2
+ export type { AuthorizedUserInfo, ClosePayload, CloseResult, CopyLinkPayload, CopyLinkResult, DirectoryCreatePayload, DirectoryCreateResult, DirectoryExistsPayload, DirectoryExistsResult, DirectoryListPayload, DirectoryListResult, DirectoryRemovePayload, DirectoryRemoveResult, DeleteCurrentUserLeaderboardEntryPayload, DeleteCurrentUserLeaderboardEntryResult, GetCurrentUserLeaderboardEntryPayload, GetCurrentUserLeaderboardEntryResult, GetLeaderboardInfoPayload, GetLeaderboardInfoResult, GetLeaderboardListPayload, GetLeaderboardListResult, GetSteamGameListPayload, GetSteamGameListResult, GetStoragePayload, GetStorageResult, GetUserInfoPayload, GetUserInfoResult, GetWindowInfoPayload, GetWindowInfoResult, DownloadProgressPayload, HideLoadingPayload, HideLoadingResult, FileCreatePayload, FileCreateResult, FileExistsPayload, FileExistsResult, FileReadBytesPayload, FileReadBytesResult, FileReadTextPayload, FileReadTextResult, FileRemovePayload, FileRemoveResult, FileStatPayload, FileStatResult, FileWriteBytesPayload, FileWriteBytesResult, FileWriteTextPayload, FileWriteTextResult, LeaderboardEntry, LeaderboardOrder, LoginPayload, LoginResult, LoginScope, MiniProgramAuthMethod, MiniProgramBridgeError, MiniProgramBridgeCancelMessage, MiniProgramBridgeMessage, MiniProgramBridgeMessageType, MiniProgramBridgeProgressMessage, MiniProgramBridgeMethod, MiniProgramCapabilityDefinition, MiniProgramCapabilityModule, MiniProgramCapabilityPayload, MiniProgramCapabilityPayloadMap, MiniProgramCapabilityResult, MiniProgramCapabilityResultMap, MiniProgramCapabilityRisk, MiniProgramCloudMethod, MiniProgramDeviceMethod, MiniProgramDirectoryDescriptor, MiniProgramDirectoryMethod, MiniProgramDirectoryRef, MiniProgramDirectDirectoryRef, MiniProgramDirectFileRef, MiniProgramEventName, MiniProgramEventPayloadMap, MiniProgramFileDescriptor, MiniProgramFileMode, MiniProgramFileMethod, MiniProgramFileRef, MiniProgramFilesMethod, MiniProgramFileStat, MiniProgramFileSystemEntityDescriptor, MiniProgramFileSystemEntityRef, MiniProgramPathRootRef, MiniProgramSandboxRootRef, MiniProgramNavigationBarForegroundStyle, MiniProgramNavigationMethod, MiniProgramNetworkHeaders, MiniProgramNetworkMethod, MiniProgramNetworkParams, MiniProgramNetworkRequestMethod, MiniProgramRuntimePermissionEntry, MiniProgramRuntimePermissionsSnapshot, MiniProgramRuntimePermissionStatus, MiniProgramSafeArea, MiniProgramScreenshotRect, MiniProgramShareChannel, MiniProgramShareMethod, MiniProgramSharePostOptions, MiniProgramStorageMethod, MiniProgramToastStatus, MiniProgramUiMethod, MiniProgramUserInfoResult, MiniProgramUserMethod, MiniProgramVibrateIntensity, MiniProgramViewportMethod, MiniProgramWindowInfoResult, NetworkRequestPayload, NetworkResponsePayload, NetworkDownloadPayload, NetworkDownloadResult, OpenAppPagePayload, OpenAppPageResult, OpenGameDetailAppPagePayload, OpenPostDetailAppPagePayload, OpenUserDetailAppPagePayload, PickDirectoryPayload, PickDirectoryResult, PickFilesPayload, PickFilesResult, ParsedMiniProgramRuntimePermissions, ReloadPayload, ReloadResult, RevokeAuthorizationPayload, RevokeAuthorizationResult, RuntimeLocationProbePayload, ScreenshotPayload, ScreenshotResult, SaveFilePayload, SaveFileResult, SDKCSPBlockedResourceType, SDKCSPViolationPayload, SDKHandshakePayload, SDKLocationReportPayload, SDKLocationReportTrigger, SetClipboardPayload, SetClipboardResult, SetNavigationBarStylePayload, SetNavigationBarStyleResult, SetStoragePayload, ShowLoadingPayload, ShowLoadingResult, ShowShareMenuPayload, ShowShareMenuResult, ShowToastPayload, ShowToastResult, SteamGameListData, SteamGameListItem, SteamGameListSort, SteamGamePrice, SubmitLeaderboardEntryPayload, SubmitLeaderboardEntryResult, UserInfoAuthorization, UserInfoAuthorizationScope, UserInfoAuthorizationStatus, VibratePayload, VibrateResult, } from '@heybox/hb-sdk-protocol';
3
3
  export type { LoginOptions } from './modules/auth';
4
4
  export type { GetSteamGameListOptions } from './modules/user';
5
5
  export type { MiniProgramEventHandler } from './protocol/types';
6
- export type { MiniProgramNetworkRequestConfig, MiniProgramNetworkResponse, MiniProgramNetworkValidateStatus, } from './modules/network';
6
+ export type { DownloadBaseOptions, DownloadOptions, DownloadProgress, MiniProgramNetworkRequestConfig, MiniProgramNetworkResponse, MiniProgramNetworkValidateStatus, } from './modules/network';
7
+ export type { CreateOptions, DirectoryHandle, FileHandle, FileMode, FileStat, FileSystem, FileSystemEntity, FilesModule, ListOptions, PathRoot, PickDirectoryOptions, PickFilesOptions, RemoveOptions, SaveFileOptions, } from './modules/files';
7
8
  export type { MiniProgramScreenshotOptions, MiniProgramShowShareMenuOptions } from './modules/share';
8
9
  export type { MiniProgramSetNavigationBarStyleOptions } from './modules/viewport';
@@ -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-D62ANeBv.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;