@open-dy/interest-card-cli 0.1.0-beta.30 → 0.1.0-beta.32

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 (210) hide show
  1. package/browser-runtime/scripts/capture-feed-card.sh +23 -18
  2. package/browser-runtime/scripts/cli.mjs +10 -3
  3. package/browser-runtime/scripts/inspect-preview-state.mjs +6 -4
  4. package/browser-runtime/scripts/preview-session.mjs +9 -0
  5. package/card-skills/douyin-interest-card-browser/references/commands.md +1 -1
  6. package/card-skills/douyin-interest-card-capability/SKILL.md +12 -4
  7. package/card-skills/douyin-interest-card-capability/references/common/openapi/external/guide.md +5 -5
  8. package/card-skills/douyin-interest-card-capability/references/microapp/api/capability-index.json +27 -27
  9. package/card-skills/douyin-interest-card-capability/references/microapp/api/connect-socket.md +24 -1
  10. package/card-skills/douyin-interest-card-capability/references/microapp/api/create-bytenn-engine-context.md +11 -1
  11. package/card-skills/douyin-interest-card-capability/references/microapp/api/create-camera-context.md +12 -0
  12. package/card-skills/douyin-interest-card-capability/references/microapp/api/create-canvas-context.md +45 -1
  13. package/card-skills/douyin-interest-card-capability/references/microapp/api/create-effect-camera-stream.md +21 -1
  14. package/card-skills/douyin-interest-card-capability/references/microapp/api/create-inner-audio-context.md +80 -3
  15. package/card-skills/douyin-interest-card-capability/references/microapp/api/create-intersection-observer.md +12 -1
  16. package/card-skills/douyin-interest-card-capability/references/microapp/api/create-interstitial-ad.md +12 -0
  17. package/card-skills/douyin-interest-card-capability/references/microapp/api/create-live-player-context.md +16 -0
  18. package/card-skills/douyin-interest-card-capability/references/microapp/api/create-map-context.md +24 -0
  19. package/card-skills/douyin-interest-card-capability/references/microapp/api/create-media-recorder.md +17 -0
  20. package/card-skills/douyin-interest-card-capability/references/microapp/api/create-offscreen-canvas.md +9 -1
  21. package/card-skills/douyin-interest-card-capability/references/microapp/api/create-rewarded-video-ad.md +16 -0
  22. package/card-skills/douyin-interest-card-capability/references/microapp/api/create-rtc-room-context.md +33 -0
  23. package/card-skills/douyin-interest-card-capability/references/microapp/api/create-scene-activity-context.md +13 -0
  24. package/card-skills/douyin-interest-card-capability/references/microapp/api/create-selector-query.md +13 -1
  25. package/card-skills/douyin-interest-card-capability/references/microapp/api/create-sticker-manager.md +11 -1
  26. package/card-skills/douyin-interest-card-capability/references/microapp/api/create-video-context.md +17 -0
  27. package/card-skills/douyin-interest-card-capability/references/microapp/api/download-file.md +10 -0
  28. package/card-skills/douyin-interest-card-capability/references/microapp/api/get-algorithm-manager.md +9 -1
  29. package/card-skills/douyin-interest-card-capability/references/microapp/api/get-background-audio-manager.md +60 -1
  30. package/card-skills/douyin-interest-card-capability/references/microapp/api/get-file-system-manager.md +37 -0
  31. package/card-skills/douyin-interest-card-capability/references/microapp/api/get-recorder-manager.md +23 -0
  32. package/card-skills/douyin-interest-card-capability/references/microapp/api/get-update-manager.md +11 -0
  33. package/card-skills/douyin-interest-card-capability/references/microapp/api/preload-video.md +8 -0
  34. package/card-skills/douyin-interest-card-capability/references/microapp/api/request.md +8 -0
  35. package/card-skills/douyin-interest-card-capability/references/microapp/api/upload-file.md +10 -0
  36. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/capability-index.json +9 -4
  37. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/censor-image.md +1 -1
  38. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/censor-text.md +1 -1
  39. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/check-fans.md +1 -1
  40. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/create-activity.md +1 -1
  41. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-affiliate-id.md +1 -1
  42. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-aiuser-data-info.md +1 -1
  43. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-aiuser-item-list.md +1 -1
  44. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-aiuser-profile.md +7 -5
  45. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-fans-favourite.md +1 -1
  46. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-fans-profile.md +1 -1
  47. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-fans-source.md +1 -1
  48. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-feed.md +1 -1
  49. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-follow-feed.md +1 -1
  50. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-follow-hot-word.md +1 -1
  51. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-friend-list.md +1 -1
  52. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-hot-list.md +1 -1
  53. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-music-collection-list.md +1 -1
  54. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-recommend.md +1 -1
  55. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-related-id.md +1 -1
  56. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-room-real-time-data.md +1 -1
  57. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-user-basic-data.md +1 -1
  58. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-user-cert-labels-info.md +1 -1
  59. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-user-comment-data.md +1 -1
  60. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-user-constellation.md +1 -1
  61. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-user-fans-data.md +1 -1
  62. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-user-fans-profile.md +1 -1
  63. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-user-following.md +1 -1
  64. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-user-hash-mobile.md +1 -1
  65. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-user-interest.md +1 -1
  66. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-user-item-data.md +1 -1
  67. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-user-like-data.md +1 -1
  68. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-user-profile-data.md +1 -1
  69. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-user-share-data.md +1 -1
  70. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-video-pack.md +48 -3
  71. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/modify-activity.md +1 -1
  72. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/query-activity-info.md +1 -1
  73. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/query-activity-user-completion-status.md +1 -1
  74. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/query-room-data.md +1 -1
  75. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/search-experience.md +1 -1
  76. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/search-general.md +1 -1
  77. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/search-live.md +1 -1
  78. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/search-music.md +1 -1
  79. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/search-user.md +1 -1
  80. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/search-video.md +1 -1
  81. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/search-vision.md +1 -1
  82. package/card-skills/douyin-interest-card-capability/references/opencard/api/call-container.md +1 -0
  83. package/card-skills/douyin-interest-card-capability/references/opencard/api/capability-index.json +6 -6
  84. package/card-skills/douyin-interest-card-capability/references/opencard/api/create-inner-audio-context.md +60 -1
  85. package/card-skills/douyin-interest-card-capability/references/opencard/api/create-map-context.md +24 -0
  86. package/card-skills/douyin-interest-card-capability/references/opencard/api/create-selector-query.md +13 -1
  87. package/card-skills/douyin-interest-card-capability/references/opencard/api/create-video-context.md +17 -0
  88. package/card-skills/douyin-interest-card-capability/references/opencard/api/download-file.md +1 -3
  89. package/card-skills/douyin-interest-card-capability/references/opencard/api/get-background-audio-manager.md +60 -1
  90. package/card-skills/douyin-interest-card-capability/references/opencard/api/request.md +1 -3
  91. package/card-skills/douyin-interest-card-capability/references/opencard/api/upload-file.md +1 -3
  92. package/card-skills/douyin-interest-card-capability/references/opencard/closed-domain-openapi.md +2 -2
  93. package/card-skills/douyin-interest-card-capability/references/opencard/component/button.md +4 -2
  94. package/card-skills/douyin-interest-card-capability/references/opencard/component/canvas.md +4 -3
  95. package/card-skills/douyin-interest-card-capability/references/opencard/component/capability-index.json +8 -9
  96. package/card-skills/douyin-interest-card-capability/references/opencard/component/checkbox-group.md +2 -0
  97. package/card-skills/douyin-interest-card-capability/references/opencard/component/image.md +3 -2
  98. package/card-skills/douyin-interest-card-capability/references/opencard/component/input.md +3 -2
  99. package/card-skills/douyin-interest-card-capability/references/opencard/component/text.md +3 -3
  100. package/card-skills/douyin-interest-card-capability/references/opencard/component/textarea.md +5 -5
  101. package/card-skills/douyin-interest-card-capability/references/opencard/component/video.md +10 -2
  102. package/card-skills/douyin-interest-card-capability/references/opencard/component-guide.md +5 -3
  103. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/capability-index.json +16 -11
  104. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/censor-image.md +1 -1
  105. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/censor-text.md +1 -1
  106. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/check-fans.md +1 -1
  107. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/create-activity.md +1 -1
  108. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-affiliate-id.md +1 -1
  109. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-aiuser-data-info.md +10 -9
  110. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-aiuser-item-list.md +10 -9
  111. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-aiuser-profile.md +16 -13
  112. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-fans-favourite.md +1 -1
  113. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-fans-profile.md +1 -1
  114. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-fans-source.md +1 -1
  115. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-feed.md +1 -1
  116. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-follow-feed.md +1 -1
  117. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-follow-hot-word.md +1 -1
  118. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-friend-list.md +1 -1
  119. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-hot-list.md +1 -1
  120. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-music-collection-list.md +1 -1
  121. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-recommend.md +1 -1
  122. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-related-id.md +1 -1
  123. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-room-real-time-data.md +1 -1
  124. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-user-basic-data.md +10 -9
  125. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-user-cert-labels-info.md +1 -1
  126. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-user-comment-data.md +1 -1
  127. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-user-constellation.md +10 -9
  128. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-user-fans-data.md +1 -1
  129. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-user-fans-profile.md +1 -1
  130. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-user-following.md +10 -9
  131. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-user-hash-mobile.md +1 -1
  132. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-user-interest.md +10 -9
  133. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-user-item-data.md +1 -1
  134. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-user-like-data.md +1 -1
  135. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-user-profile-data.md +1 -1
  136. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-user-share-data.md +1 -1
  137. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-video-pack.md +48 -3
  138. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/modify-activity.md +1 -1
  139. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/query-activity-info.md +1 -1
  140. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/query-activity-user-completion-status.md +1 -1
  141. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/query-room-data.md +1 -1
  142. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/search-experience.md +1 -1
  143. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/search-general.md +1 -1
  144. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/search-live.md +1 -1
  145. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/search-music.md +1 -1
  146. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/search-user.md +1 -1
  147. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/search-video.md +1 -1
  148. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/search-vision.md +1 -1
  149. package/card-skills/douyin-interest-card-capability/scripts/search-capabilities.mjs +7 -4
  150. package/card-skills/douyin-interest-card-cli/SKILL.md +11 -5
  151. package/card-skills/douyin-interest-card-generate/SKILL.md +5 -3
  152. package/card-skills/douyin-interest-card-generate/init.sh +13 -23
  153. package/card-skills/douyin-interest-card-generate/references/common/fullstack.md +6 -10
  154. package/card-skills/douyin-interest-card-generate/references/common/post-card-differences.md +29 -3
  155. package/card-skills/douyin-interest-card-generate/references/common/private-data-intent-routing.md +1 -1
  156. package/card-skills/douyin-interest-card-generate/references/common/upgrade-to-post.md +29 -6
  157. package/card-skills/douyin-interest-card-generate/references/microapp/microapp.md +1 -1
  158. package/card-skills/douyin-interest-card-generate/references/opencard/api.md +8 -0
  159. package/card-skills/douyin-interest-card-generate/references/opencard/closed-domain-card.md +1 -1
  160. package/card-skills/douyin-interest-card-generate/references/opencard/components.md +11 -28
  161. package/card-skills/douyin-interest-card-generate/references/opencard/opencard.md +9 -7
  162. package/card-skills/douyin-interest-card-generate/references/opencard/rendering.md +5 -5
  163. package/card-skills/douyin-interest-card-generate/references/opencard/taro-dsl.md +6 -6
  164. package/card-skills/douyin-interest-card-generate/scripts/inspect-post-upgrade.mjs +630 -0
  165. package/card-skills/douyin-interest-card-generate/templates/fragments/opencard/package.json +2 -2
  166. package/card-skills/douyin-interest-card-generate/templates/fragments/opencard/pnpm-lock.yaml +17 -17
  167. package/card-skills/douyin-interest-card-generate/templates/taro/closed-domain-server/package.json +1 -1
  168. package/card-skills/douyin-interest-card-generate/templates/taro/package.json +5 -4
  169. package/card-skills/douyin-interest-card-generate/templates/taro/pnpm-lock.yaml +27 -26
  170. package/card-skills/douyin-interest-card-generate/templates/taro/server/package.json +1 -1
  171. package/dist/src/args.js +23 -8
  172. package/dist/src/browser.js +3 -1
  173. package/dist/src/card/agent-chat.js +4 -0
  174. package/dist/src/card/binding.js +2 -1
  175. package/dist/src/card/candidate.js +90 -0
  176. package/dist/src/card/card-api.js +2 -2
  177. package/dist/src/card/card-token.js +25 -2
  178. package/dist/src/card/chat-commands.js +26 -11
  179. package/dist/src/card/constants.js +5 -0
  180. package/dist/src/card/create-project-client.js +2 -2
  181. package/dist/src/card/create.js +29 -3
  182. package/dist/src/card/editor-client.js +41 -6
  183. package/dist/src/card/editor-fs.js +4 -4
  184. package/dist/src/card/global-skills.js +6 -1
  185. package/dist/src/card/handlers-misc.js +3 -6
  186. package/dist/src/card/handlers.js +32 -24
  187. package/dist/src/card/help.js +6 -4
  188. package/dist/src/card/ignore.js +22 -0
  189. package/dist/src/card/project.js +13 -4
  190. package/dist/src/card-install.js +8 -9
  191. package/dist/src/cli.js +5 -2
  192. package/dist/src/config.js +26 -3
  193. package/dist/src/creator-device-login.js +2 -1
  194. package/dist/src/creator-login-session.js +6 -6
  195. package/dist/src/creator-passport-login.js +8 -2
  196. package/dist/src/creator-session.js +30 -7
  197. package/dist/src/current-user.js +29 -0
  198. package/dist/src/help-access.js +22 -0
  199. package/dist/src/help.js +6 -2
  200. package/dist/src/http.js +4 -4
  201. package/dist/src/login-handlers.js +2 -1
  202. package/dist/src/platform-process.js +98 -0
  203. package/dist/src/platform.js +1 -1
  204. package/dist/src/request-source.js +4 -0
  205. package/dist/src/telemetry-session.js +17 -0
  206. package/dist/src/telemetry.js +7 -2
  207. package/dist/src/update-check.js +5 -3
  208. package/dist/src/upgrade.js +56 -12
  209. package/package.json +1 -1
  210. package/card-skills/douyin-interest-card-capability/references/opencard/component/svg.md +0 -58
@@ -62,6 +62,7 @@ export const CARD_API_ROUTES = {
62
62
  tenantList: 'tenant/list',
63
63
  conversationCreate: 'conversation/create',
64
64
  msgSend: 'msg/send',
65
+ authMe: 'auth/me',
65
66
  msgPoll: 'msg/poll',
66
67
  };
67
68
  /**
@@ -96,6 +97,10 @@ export const LOCAL_DEBOUNCE_MS = 300;
96
97
  export const ECHO_WINDOW_MS = 10_000;
97
98
  export const PING_INTERVAL_MS = 30_000;
98
99
  export const REQUEST_TIMEOUT_MS = 60_000;
100
+ /** A batch of up to 50 files / 4 MB regularly takes the sandbox longer than a minute to write. */
101
+ export const WRITE_TIMEOUT_MS = 180_000;
102
+ /** Connection attempts before giving up; a sleeping sandbox often refuses the first one. */
103
+ export const CONNECT_RETRY_DELAYS_MS = [1_000, 3_000];
99
104
  export const CONNECT_TIMEOUT_MS = 15_000;
100
105
  export const MAX_RECONNECT_DELAY_MS = 30_000;
101
106
  export const MAX_PUSH_RETRIES = 3;
@@ -1,4 +1,4 @@
1
- import { CLI_SOURCE_HEADERS } from '../request-source.js';
1
+ import { cliSourceHeaders } from '../request-source.js';
2
2
  import { fetchWithCredential, isCardGateError } from './card-token.js';
3
3
  import { CliError } from '../types.js';
4
4
  import { CARD_LOGIN_HINT, getProjectCreateUrl } from './constants.js';
@@ -83,7 +83,7 @@ export async function createCardProject(options) {
83
83
  referer: `${CARD_WEB_ORIGIN}/`,
84
84
  'content-type': 'application/json',
85
85
  'x-aicore-tenant': options.tenant,
86
- ...CLI_SOURCE_HEADERS,
86
+ ...cliSourceHeaders(options.headers?.['x-tt-env']),
87
87
  },
88
88
  body: JSON.stringify({
89
89
  tenant: options.tenant,
@@ -1,3 +1,4 @@
1
+ import { readCardCandidate } from './candidate.js';
1
2
  import { noteTelemetryProject } from '../telemetry-project.js';
2
3
  import { getString } from '../cli-helpers.js';
3
4
  import { printText } from '../output.js';
@@ -9,7 +10,7 @@ import { followAndReport } from './chat-commands.js';
9
10
  import { BLANK_COPY_SOLUTION_ID, BLANK_INSPIRATION_KEY } from './constants.js';
10
11
  import { createCardProject } from './create-project-client.js';
11
12
  import { restartDevServices } from './dev-commands.js';
12
- import { buildProjectPageUrl, getTenantOption, loadCardConfig } from './project.js';
13
+ import { buildProjectPageUrl, getCardPpeHeaders, getTenantOption, loadCardConfig } from './project.js';
13
14
  import { applyBlankProjectName, normalizeProjectName } from './rename.js';
14
15
  const SEEDED_HINT = 'The sandbox has the blank interest-card template. Pull the project, then immediately set a name that matches the card with interest-card-cli rename --name "<name>" before writing any card code. Do not wait until the card is finished. Implement the card locally. Do not send the card description to the platform agent. data.projectName is only the placeholder list title.';
15
16
  /** Visible user bubble for blank create; keeps the conversation panel from looking empty. */
@@ -28,6 +29,11 @@ export function buildBlankCopyReminder(conversationId) {
28
29
  */
29
30
  export async function handleCardCreate(parsed) {
30
31
  const blank = Boolean(parsed.options.blank);
32
+ const routingHeaders = getCardPpeHeaders(parsed);
33
+ const lane = routingHeaders['x-tt-env'];
34
+ if (blank && lane) {
35
+ throw new CliError('PPE create requires a project description. Omit --blank.', 'CARD_INVALID_ARGS');
36
+ }
31
37
  const prompt = parsed.positionals.join(' ').trim();
32
38
  if (blank && prompt) {
33
39
  throw new CliError('create --blank does not take a card description. Implement the card locally after the command returns seeded.', 'CARD_INVALID_ARGS');
@@ -41,16 +47,20 @@ export async function handleCardCreate(parsed) {
41
47
  }
42
48
  const { config, auth } = await loadCardConfig(parsed);
43
49
  const tenant = getTenantOption(parsed);
44
- const headers = tenant ? buildWorkspaceHeaders(config.base_url, tenant) : undefined;
50
+ const headers = { ...(tenant ? buildWorkspaceHeaders(config.base_url, tenant) : {}), ...routingHeaders };
51
+ const candidate = await readCardCandidate(parsed);
52
+ if (candidate && blank)
53
+ throw new CliError('Candidate create requires a query; do not combine with --blank.', 'CARD_INVALID_ARGS');
45
54
  const { projectId, conversationId } = await createCardProject({
46
55
  cookie: auth,
56
+ headers: routingHeaders,
47
57
  tenant,
48
58
  name: requestedName,
49
59
  });
50
60
  // Noted at once: the project exists from here on, whatever happens to the first message.
51
61
  noteTelemetryProject({ projectId, conversationId });
52
62
  const projectUrl = buildProjectPageUrl(projectId);
53
- const target = { config, headers, conversationId, projectId };
63
+ const target = { config, headers, conversationId, projectId, candidate };
54
64
  const messageId = await sendCardMessage(target, blank
55
65
  ? {
56
66
  text: BLANK_SEED_USER_TEXT,
@@ -59,6 +69,22 @@ export async function handleCardCreate(parsed) {
59
69
  multiModal: false,
60
70
  }
61
71
  : { text: prompt }).catch((error) => {
72
+ if (lane || candidate) {
73
+ const cause = error instanceof CliError ? error : undefined;
74
+ const details = cause?.details;
75
+ const environment = lane ? `PPE lane ${lane}` : 'production';
76
+ const receipt = details?.messageId ? `message ${details.messageId}` : `project ${projectId}`;
77
+ const lookup = `Check ${receipt} in ${environment} before retrying.`;
78
+ const retry = 'If the message was not sent, use reply on the existing project with the same routing and candidate options.';
79
+ throw new CliError(`Project created, but sending the prompt failed: ${error instanceof Error ? error.message : String(error)}`, cause?.code ?? 'CARD_CREATE_PROMPT_FAILED', {
80
+ ...details,
81
+ projectId,
82
+ conversationId,
83
+ projectUrl,
84
+ ...(lane ? { ppeLane: lane } : {}),
85
+ hint: [details?.hint, lookup, retry].filter(Boolean).join(' '),
86
+ });
87
+ }
62
88
  throw new CliError(`Project created, but sending the prompt failed: ${error instanceof Error ? error.message : String(error)}`, 'CARD_CREATE_PROMPT_FAILED', {
63
89
  projectId,
64
90
  conversationId,
@@ -1,7 +1,7 @@
1
1
  import { CliError } from '../types.js';
2
2
  import { CLI_SOURCE_HEADERS } from '../request-source.js';
3
3
  import { credentialHeaders } from './card-token.js';
4
- import { CONNECT_TIMEOUT_MS, PING_INTERVAL_MS, REQUEST_TIMEOUT_MS, getEditorWsUrl, } from './constants.js';
4
+ import { CONNECT_RETRY_DELAYS_MS, CONNECT_TIMEOUT_MS, PING_INTERVAL_MS, REQUEST_TIMEOUT_MS, getEditorWsUrl, } from './constants.js';
5
5
  /** JSON-RPC client for the editor websocket that the web IDE also uses. */
6
6
  export class EditorClient {
7
7
  socket;
@@ -138,10 +138,45 @@ export class EditorClient {
138
138
  }
139
139
  }
140
140
  }
141
- export async function connectEditor(conversationId, cookie) {
142
- const client = new EditorClient({ url: getEditorWsUrl(), conversationId, cookie });
143
- await client.connect();
144
- return client;
141
+ /** Connects to the sandbox editor, trying again while the sandbox is still waking up. */
142
+ export async function connectEditor(conversationId, cookie, deps = {}) {
143
+ const create = deps.create ?? (() => new EditorClient({ url: getEditorWsUrl(), conversationId, cookie }));
144
+ const delays = deps.retryDelaysMs ?? CONNECT_RETRY_DELAYS_MS;
145
+ for (let attempt = 0;; attempt += 1) {
146
+ const client = create();
147
+ try {
148
+ await client.connect();
149
+ return client;
150
+ }
151
+ catch (error) {
152
+ client.close();
153
+ const retryable = error instanceof CliError && error.code === 'CARD_SANDBOX_UNAVAILABLE';
154
+ if (!retryable || attempt >= delays.length) {
155
+ throw error;
156
+ }
157
+ await new Promise(resolve => setTimeout(resolve, delays[attempt]));
158
+ }
159
+ }
160
+ }
161
+ /**
162
+ * Runs `work` on a sandbox connection and, when the connection drops midway (close code 1006),
163
+ * once more on a new one. Only for work that is safe to repeat from the start.
164
+ */
165
+ export async function withEditor(connect, work) {
166
+ for (let attempt = 0;; attempt += 1) {
167
+ const client = await connect();
168
+ try {
169
+ return await work(client);
170
+ }
171
+ catch (error) {
172
+ if (attempt > 0 || !(error instanceof CliError) || error.code !== 'CARD_WS_CLOSED') {
173
+ throw error;
174
+ }
175
+ }
176
+ finally {
177
+ client.close();
178
+ }
179
+ }
145
180
  }
146
181
  function parseMessage(data) {
147
182
  try {
@@ -153,6 +188,6 @@ function parseMessage(data) {
153
188
  }
154
189
  function connectError(message) {
155
190
  return new CliError(message, 'CARD_SANDBOX_UNAVAILABLE', {
156
- hint: 'Check login with `interest-card-cli login --platform ext`, then open the project in the browser (`interest-card-cli open`) to wake the sandbox.',
191
+ hint: 'Run the command again. If it keeps failing, open the project in the browser (`interest-card-cli open`) to wake the sandbox, and check login with `interest-card-cli status --json`.',
157
192
  });
158
193
  }
@@ -1,6 +1,6 @@
1
1
  import { CliError } from '../types.js';
2
2
  import { CLI_SOURCE_HEADERS } from '../request-source.js';
3
- import { CARD_REMOTE_ROOT, CARD_SANDBOX_PROJECT_DIR, isTrustedSessionUrl, MAX_BATCH_BYTES, MAX_BATCH_FILES, } from './constants.js';
3
+ import { CARD_REMOTE_ROOT, CARD_SANDBOX_PROJECT_DIR, isTrustedSessionUrl, MAX_BATCH_BYTES, MAX_BATCH_FILES, WRITE_TIMEOUT_MS, } from './constants.js';
4
4
  import { REMOTE_ZIP_EXCLUDES } from './ignore.js';
5
5
  import { assertSafeEntryPath, extractZipEntries } from './zip-extract.js';
6
6
  import { fetchWithCredential } from './card-token.js';
@@ -82,7 +82,7 @@ export async function writeRemoteFiles(client, items) {
82
82
  content: item.content.toString('base64'),
83
83
  })),
84
84
  };
85
- results.push(...(await runBatch(client, 'fs.write', params, batch.map(item => item.path))));
85
+ results.push(...(await runBatch(client, 'fs.write', params, batch.map(item => item.path), WRITE_TIMEOUT_MS)));
86
86
  }
87
87
  return results;
88
88
  }
@@ -126,12 +126,12 @@ function chunkWrites(items) {
126
126
  return batches;
127
127
  }
128
128
  /** The server returns a bare `{success}` for single items and per-item `results` for batches. */
129
- async function runBatch(client, method, params, paths) {
129
+ async function runBatch(client, method, params, paths, timeoutMs) {
130
130
  if (!paths.length) {
131
131
  return [];
132
132
  }
133
133
  try {
134
- const result = await client.call('fs', method, params);
134
+ const result = await client.call('fs', method, params, timeoutMs);
135
135
  if (paths.length === 1) {
136
136
  return [{ path: paths[0], success: result?.success !== false }];
137
137
  }
@@ -4,6 +4,7 @@ import fs from 'node:fs/promises';
4
4
  import os from 'node:os';
5
5
  import path from 'node:path';
6
6
  import { resolveConfigPath } from '../config.js';
7
+ import { commandInvocation } from '../platform-process.js';
7
8
  import { CliError, DEFAULT_CONFIG_DIR } from '../types.js';
8
9
  import { getCliVersion } from '../version.js';
9
10
  import { ENTRY_SKILL, LEGACY_SKILL_NAMES, PROJECT_SKILLS } from './skill-names.js';
@@ -237,7 +238,11 @@ function stampPath(home) {
237
238
  /** With --json, `npx skills` output goes to stderr so stdout stays one JSON document. */
238
239
  function runSkillsCli(args, json) {
239
240
  return new Promise((resolve, reject) => {
240
- const child = spawn('npx', args, { stdio: json ? ['ignore', 2, 2] : 'inherit' });
241
+ const run = commandInvocation('npx', args);
242
+ const child = spawn(run.command, run.args, {
243
+ ...run.options,
244
+ stdio: json ? ['ignore', 2, 2] : 'inherit',
245
+ });
241
246
  child.on('error', reject);
242
247
  child.on('close', code => {
243
248
  if (code === 0) {
@@ -2,6 +2,7 @@ import { spawn } from 'node:child_process';
2
2
  import path from 'node:path';
3
3
  import { getString } from '../cli-helpers.js';
4
4
  import { printText } from '../output.js';
5
+ import { browserOpenCommand } from '../platform-process.js';
5
6
  import { CliError } from '../types.js';
6
7
  import { acquireLock, findProjectRoot, readBinding, readManifest, writeManifest, } from './binding.js';
7
8
  import { CARD_CONFLICT_SUFFIX } from './constants.js';
@@ -200,12 +201,8 @@ async function checkSandbox(parsed, conversationId) {
200
201
  }
201
202
  }
202
203
  function openInBrowser(url) {
203
- const [command, args] = process.platform === 'darwin'
204
- ? ['open', [url]]
205
- : process.platform === 'win32'
206
- ? ['cmd', ['/c', 'start', '', url]]
207
- : ['xdg-open', [url]];
208
- spawn(command, args, { stdio: 'ignore', detached: true })
204
+ const [command, args] = browserOpenCommand(url);
205
+ spawn(command, args, { stdio: 'ignore', detached: true, windowsHide: true })
209
206
  .on('error', () => undefined)
210
207
  .unref();
211
208
  }
@@ -6,9 +6,10 @@ import { CliError } from '../types.js';
6
6
  import { formatSkillsNotice, formatSkillsRefreshed, shouldSkipSkillsNotice, } from '../update-check.js';
7
7
  import { acquireLock, findProjectRoot, manifestFromSnapshot, readBinding, readManifest, writeBinding, writeManifest, writeStateDirGitignore, } from './binding.js';
8
8
  import { CARD_COMMIT_TITLE, CARD_LOGIN_HINT, CARD_REMOTE_ROOT, CARD_STATE_DIR, } from './constants.js';
9
- import { connectEditor } from './editor-client.js';
9
+ import { connectEditor, withEditor } from './editor-client.js';
10
10
  import { commitRemote, downloadRemoteFiles } from './editor-fs.js';
11
11
  import { handleCardOpen, handleCardResolve, handleCardSkills, handleCardStatus, } from './handlers-misc.js';
12
+ import { hasCandidateOptions } from './candidate.js';
12
13
  import { handleCardAnswer, handleCardReply } from './chat-commands.js';
13
14
  import { handleCardCreate } from './create.js';
14
15
  import { handleCardRename } from './rename.js';
@@ -27,7 +28,7 @@ import { DEFAULT_PROJECT_AGENTS, SUPPORTED_AGENTS, findStaleSkillInstall, instal
27
28
  import { createReporter } from './reporter.js';
28
29
  import { scanLocal, writeLocalFile } from './snapshot.js';
29
30
  import { SyncEngine } from './sync-engine.js';
30
- export function handleCard(parsed) {
31
+ export async function handleCard(parsed) {
31
32
  return dispatchCard(parsed).catch((error) => {
32
33
  throw toAuthExpiredError(error);
33
34
  });
@@ -64,20 +65,26 @@ export async function noticeStaleSkills(parsed) {
64
65
  * BFF answers HTTP 401 `{"error":1001}`.
65
66
  */
66
67
  function toAuthExpiredError(error) {
67
- const status = error instanceof CliError && error.code === 'HTTP_ERROR'
68
- ? error.details?.status
69
- : undefined;
70
- const authRequired = error instanceof CliError && error.code === 'AUTH_REQUIRED';
71
- if (status !== 401 && !authRequired) {
68
+ if (!(error instanceof CliError))
69
+ return error;
70
+ const details = error.details;
71
+ if (error.code !== 'AUTH_REQUIRED' && !(error.code === 'HTTP_ERROR' && details?.status === 401)) {
72
72
  return error;
73
73
  }
74
74
  return new CliError('Creator center login has expired.', 'CARD_AUTH_EXPIRED', {
75
75
  hint: CARD_LOGIN_HINT,
76
+ ...(details?.xTtLogid ? { xTtLogid: details.xTtLogid } : {}),
76
77
  });
77
78
  }
78
79
  async function dispatchCard(parsed) {
79
80
  const [subcommand, ...positionals] = parsed.positionals;
80
81
  const sub = { ...parsed, positionals };
82
+ if ('ppe' in sub.options && !['create', 'reply', 'answer'].includes(subcommand)) {
83
+ throw new CliError('--ppe requires create, reply, or answer.', 'CARD_INVALID_ARGS');
84
+ }
85
+ if (hasCandidateOptions(sub) && !['create', 'reply', 'answer'].includes(subcommand)) {
86
+ throw new CliError('Candidate options require create, reply, or answer.', 'CARD_CANDIDATE_INVALID');
87
+ }
81
88
  if (subcommand !== 'skills') {
82
89
  await noticeStaleSkills(parsed);
83
90
  }
@@ -120,14 +127,16 @@ async function dispatchCard(parsed) {
120
127
  return handleCardDev(sub);
121
128
  case 'deps':
122
129
  return handleCardDeps(sub, handleCardPush);
123
- default:
130
+ default: {
131
+ const help = cardHelp(false);
124
132
  if (!parsed.options.json) {
125
- printText(cardHelp());
133
+ printText(help);
126
134
  }
127
135
  if (subcommand) {
128
136
  return Promise.reject(new CliError(`Unknown card command: ${subcommand}`, 'UNKNOWN_COMMAND'));
129
137
  }
130
- return Promise.resolve({ ok: true, command: 'card', data: { help: cardHelp() } });
138
+ return { ok: true, command: 'card', data: { help } };
139
+ }
131
140
  }
132
141
  }
133
142
  async function handleCardPull(parsed) {
@@ -146,9 +155,9 @@ async function handleCardPull(parsed) {
146
155
  : await resolveCardProject(config, projectId, getTenantOption(parsed));
147
156
  const root = path.resolve(dirArg || getString(parsed, 'dir') || `card-${project.projectId || project.conversationId}`);
148
157
  await assertPullTarget(root, Boolean(parsed.options.force));
149
- const client = await connectEditor(project.conversationId, auth);
150
158
  let fileCount = 0;
151
- try {
159
+ await withEditor(() => connectEditor(project.conversationId, auth), async (client) => {
160
+ fileCount = 0;
152
161
  const remote = await downloadRemoteFiles(client, auth, createIgnoreMatcher(root));
153
162
  const gitignore = remote.get('.gitignore');
154
163
  if (gitignore) {
@@ -161,10 +170,7 @@ async function handleCardPull(parsed) {
161
170
  fileCount += 1;
162
171
  }
163
172
  }
164
- }
165
- finally {
166
- client.close();
167
- }
173
+ });
168
174
  await writeBinding(root, {
169
175
  version: 1,
170
176
  platform: 'ext',
@@ -273,11 +279,17 @@ async function handleCardPush(parsed) {
273
279
  const binding = await readBinding(root);
274
280
  const { auth } = await loadCardConfig(parsed);
275
281
  const release = await acquireLock(root);
276
- const client = await connectEditor(binding.conversationId, auth).catch(async (error) => {
277
- await release();
278
- throw error;
279
- });
280
282
  try {
283
+ return await withEditor(() => connectEditor(binding.conversationId, auth),
284
+ // A push that lost its connection starts over: files already written compare equal and are skipped.
285
+ client => pushThrough(parsed, root, client, auth));
286
+ }
287
+ finally {
288
+ await release();
289
+ }
290
+ }
291
+ async function pushThrough(parsed, root, client, auth) {
292
+ {
281
293
  const report = createReporter(Boolean(parsed.options.json));
282
294
  const result = await reconcile({ root, client, cookie: auth, ignore: createIgnoreMatcher(root), report }, await readManifest(root), parsed.options.force ? 'local' : undefined);
283
295
  const commitTitle = getCommitTitle(parsed);
@@ -330,10 +342,6 @@ async function handleCardPush(parsed) {
330
342
  }
331
343
  return { ok: true, command: 'card-push', data };
332
344
  }
333
- finally {
334
- client.close();
335
- await release();
336
- }
337
345
  }
338
346
  async function assertPullTarget(root, force) {
339
347
  const entries = await fs.readdir(root).catch(() => []);
@@ -1,5 +1,5 @@
1
1
  import { DEFAULT_CREATOR_CONFIG_PATH } from '../types.js';
2
- export function cardHelp() {
2
+ export function cardHelp(testingAllowed = false) {
3
3
  return `Interest card (兴趣卡) local editing
4
4
 
5
5
  Pull an interest card project from its sandbox, edit it locally with any agent,
@@ -50,10 +50,10 @@ Commands:
50
50
  skills uninstall [--global] Remove the skills this CLI installed (project, or global)
51
51
  install Install the CLI and global skills, then log in
52
52
  login / logout Creator center login (see \`help login\`)
53
- upgrade [--check] Update the CLI and refresh skills
53
+ ${testingAllowed ? ' whoami Current authenticated creator UID\n' : ''} upgrade [--check] Update the CLI and refresh skills
54
54
  version Print the CLI version
55
55
 
56
- Every command above also works as \`interest-card-cli card <command>\`.
56
+ Project commands also work as \`interest-card-cli card <command>\`; account and setup commands stay at the top level.
57
57
 
58
58
  Options:
59
59
  -j, --json Print JSON; sync events stream to stderr as NDJSON
@@ -86,7 +86,9 @@ Options:
86
86
  --service <name> logs: only lines tagged [name], e.g. opencard, server
87
87
  --grep <text> logs: only lines containing text (case-insensitive)
88
88
  --all logs: include earlier dev runs, not just the latest
89
- --no-wait dev restart: return without waiting for the ports
89
+ ${testingAllowed ? ` --ppe <lane> create/reply/answer: PPE testing lane (testing allowlist required)
90
+ --prompt-file <file> override the system prompt for this turn (testing allowlist required)
91
+ --skill <name>=<url> repeat for each single-Skill ZIP on CDN (testing allowlist required)\n` : ''} --no-wait dev restart: return without waiting for the ports
90
92
  --timeout <seconds> dev restart: wait this long for ready (default 180);
91
93
  deps: kill pnpm after this long (default 300)
92
94
  --target <root|server|opencard>
@@ -27,6 +27,17 @@ export const BUILTIN_IGNORE_PATTERNS = [
27
27
  '.fnm_shell/',
28
28
  '.cache/',
29
29
  '.local/',
30
+ // Some sandboxes use card-app itself as HOME. Its browser profile holds sockets that zip cannot
31
+ // read, and its shell history and tokens are not project files.
32
+ '.config/',
33
+ '.pki/',
34
+ '.fontconfig/',
35
+ '.ipython/',
36
+ '.jupyter/',
37
+ '.skill_token',
38
+ '.bash_history',
39
+ '.bashrc',
40
+ '.Xauthority',
30
41
  '.pnpm-store/',
31
42
  '.tmp/',
32
43
  '.env',
@@ -60,6 +71,17 @@ export const REMOTE_ZIP_EXCLUDES = [
60
71
  '*/.cache/*',
61
72
  '.local/*',
62
73
  '*/.local/*',
74
+ '.config/*',
75
+ '*/.config/*',
76
+ '.pki/*',
77
+ '*/.pki/*',
78
+ '.fontconfig/*',
79
+ '.ipython/*',
80
+ '.jupyter/*',
81
+ '.skill_token',
82
+ '.bash_history',
83
+ '.bashrc',
84
+ '.Xauthority',
63
85
  '.pnpm-store/*',
64
86
  '*/.pnpm-store/*',
65
87
  '.tmp/*',
@@ -1,7 +1,7 @@
1
1
  import { noteTelemetryProject } from '../telemetry-project.js';
2
2
  import { getString } from '../cli-helpers.js';
3
3
  import { applyRuntimeConfigOverrides, hasExplicitPlatform, loadCommandConfig, } from '../command-context.js';
4
- import { cardAuthFor } from './card-token.js';
4
+ import { cardAuthFor, isCardGateError } from './card-token.js';
5
5
  import { cardApi } from './card-api.js';
6
6
  import { buildWorkspaceHeaders, isExternalConfig } from '../platform.js';
7
7
  import { CliError } from '../types.js';
@@ -17,7 +17,7 @@ export async function loadCardConfig(parsed) {
17
17
  }
18
18
  catch (error) {
19
19
  // A mistyped --platform is not a login problem: scanning again would not fix it.
20
- if (error instanceof CliError && error.code === 'UNKNOWN_PLATFORM') {
20
+ if (isCardGateError(error) || (error instanceof CliError && error.code === 'UNKNOWN_PLATFORM')) {
21
21
  throw error;
22
22
  }
23
23
  throw new CliError('Not logged in to the creator center.', 'CARD_AUTH_EXPIRED', {
@@ -51,8 +51,8 @@ export function parseProjectRef(input) {
51
51
  export function buildProjectPageUrl(projectId) {
52
52
  return `${CARD_PROJECT_PAGE_URL}/${encodeURIComponent(projectId)}`;
53
53
  }
54
- export async function resolveCardProject(config, projectId, tenant) {
55
- const response = await cardApi(config, CARD_API_ROUTES.projectGet, { projectId }, { headers: tenant ? buildWorkspaceHeaders(config.base_url, tenant) : undefined });
54
+ export async function resolveCardProject(config, projectId, tenant, routingHeaders) {
55
+ const response = await cardApi(config, CARD_API_ROUTES.projectGet, { projectId }, { headers: { ...(tenant ? buildWorkspaceHeaders(config.base_url, tenant) : {}), ...routingHeaders } });
56
56
  const app = response.data?.app;
57
57
  if (!app) {
58
58
  throw new CliError('Project not found or no permission.', 'CARD_PROJECT_NOT_FOUND', {
@@ -118,3 +118,12 @@ function toTime(value) {
118
118
  export function getTenantOption(parsed) {
119
119
  return getString(parsed, 'tenant') || CARD_DEFAULT_TENANT;
120
120
  }
121
+ export function getCardPpeHeaders(parsed) {
122
+ if (!('ppe' in parsed.options))
123
+ return {};
124
+ const lane = getString(parsed, 'ppe');
125
+ if (!lane || !/^ppe_[a-zA-Z0-9][a-zA-Z0-9_-]{0,99}$/.test(lane)) {
126
+ throw new CliError('Pass a valid PPE lane name to --ppe.', 'CARD_INVALID_ARGS');
127
+ }
128
+ return { 'x-tt-env': lane, 'x-use-ppe': '1' };
129
+ }
@@ -1,9 +1,10 @@
1
- import { execFileSync } from 'node:child_process';
1
+ import { spawnSync } from 'node:child_process';
2
2
  import { existsSync, readFileSync } from 'node:fs';
3
3
  import path from 'node:path';
4
4
  import { installGlobalSkills } from './card/global-skills.js';
5
5
  import { getString, getStringList } from './cli-helpers.js';
6
6
  import { handleLogin } from './login-handlers.js';
7
+ import { commandInvocation } from './platform-process.js';
7
8
  import { compareVersions } from './semver.js';
8
9
  import { CliError } from './types.js';
9
10
  import { CLI_PACKAGE_NAME, upgradeTarget } from './update-check.js';
@@ -111,14 +112,12 @@ async function desiredVersion(running) {
111
112
  }
112
113
  }
113
114
  function globalRoot() {
114
- try {
115
- return execFileSync('npm', ['root', '-g'], { stdio: ['ignore', 'pipe', 'ignore'] })
116
- .toString()
117
- .trim();
118
- }
119
- catch {
120
- return undefined;
121
- }
115
+ const run = commandInvocation('npm', ['root', '-g']);
116
+ const result = spawnSync(run.command, run.args, {
117
+ ...run.options,
118
+ stdio: ['ignore', 'pipe', 'ignore'],
119
+ });
120
+ return (result.status === 0 && result.stdout.toString().trim()) || undefined;
122
121
  }
123
122
  function readInstalledVersion(root) {
124
123
  try {
package/dist/src/cli.js CHANGED
@@ -3,7 +3,7 @@ import { runBrowserCommand, splitBrowserArgv } from './card/browser-command.js';
3
3
  import { hasExplicitPlatform, prepareCommandConfigPath } from './command-context.js';
4
4
  import { getString } from './cli-helpers.js';
5
5
  import { getConfigCookie, removeConfig, tryLoadConfig } from './config.js';
6
- import { helpText } from './help.js';
6
+ import { resolvedHelpText } from './help-access.js';
7
7
  import { buildLogoutUrl } from './http.js';
8
8
  import { handleCard, noticeStaleSkills } from './card/handlers.js';
9
9
  import { revokeCardToken } from './card/card-token.js';
@@ -14,6 +14,7 @@ import { handleLogin } from './login-handlers.js';
14
14
  import { removeLegacyBrowserProfile } from './creator-login.js';
15
15
  import { cancelPendingCreatorLogin } from './creator-login-session.js';
16
16
  import { CLI_SOURCE_HEADERS, invalidLaneEnv } from './request-source.js';
17
+ import { handleWhoami } from './current-user.js';
17
18
  import { printJson, printText } from './output.js';
18
19
  import { trackCommand } from './telemetry.js';
19
20
  import { CliError, getCliVersion } from './types.js';
@@ -29,7 +30,7 @@ export async function runCli(argv) {
29
30
  }
30
31
  const parsed = parseCliArgs(argv);
31
32
  if (parsed.options.help || parsed.command === 'help') {
32
- printText(helpText(parsed.command === 'help' ? parsed.positionals.join(' ') : parsed.command));
33
+ printText(await resolvedHelpText(parsed, parsed.command === 'help' ? parsed.positionals.join(' ') : parsed.command));
33
34
  return;
34
35
  }
35
36
  if (parsed.command !== 'upgrade' && parsed.command !== 'install') {
@@ -107,6 +108,8 @@ function runCommand(parsed) {
107
108
  return Promise.reject(new CliError(laneError, 'INVALID_LANE_ENV'));
108
109
  }
109
110
  switch (parsed.command) {
111
+ case 'whoami':
112
+ return handleWhoami(parsed);
110
113
  case 'login':
111
114
  return handleLogin(parsed);
112
115
  case 'logout':
@@ -1,14 +1,16 @@
1
- import { randomUUID } from 'node:crypto';
1
+ import { createHash, randomUUID } from 'node:crypto';
2
2
  import fs from 'node:fs/promises';
3
3
  import os from 'node:os';
4
4
  import path from 'node:path';
5
+ import { renameReplacing } from './platform-process.js';
5
6
  import { DEFAULT_BASE_URL, DEFAULT_CLIENT_ID, DEFAULT_CONFIG_DIR, DEFAULT_CONFIG_PATH, LEGACY_CLIENT_ID, LEGACY_CONFIG_DIR, CliError, } from './types.js';
6
7
  const CONFIG_FILE_NAMES = ['config.json', 'config-aihub.json'];
7
8
  export function resolveConfigPath(configPath = getConfigPathEnvironmentOverride() || DEFAULT_CONFIG_PATH, homeDir = os.homedir()) {
8
9
  if (configPath === '~') {
9
10
  return homeDir;
10
11
  }
11
- if (configPath.startsWith('~/')) {
12
+ // `~\\` is how the same path is written in PowerShell and cmd.
13
+ if (configPath.startsWith('~/') || configPath.startsWith('~\\')) {
12
14
  return path.join(homeDir, configPath.slice(2));
13
15
  }
14
16
  return path.resolve(configPath);
@@ -141,6 +143,27 @@ export async function saveConfig(configPath, config) {
141
143
  await writeConfigAtomically(resolvedPath, config);
142
144
  return resolvedPath;
143
145
  }
146
+ // Keep capability data beside the login so a concurrent whoami cannot rewrite a login or undo logout.
147
+ function candidateCapabilityKey(config, route) {
148
+ return createHash('sha256').update(JSON.stringify([config.access_token, route])).digest('hex');
149
+ }
150
+ export async function readCandidateCapability(config, route) {
151
+ const configPath = getLoadedConfigPath(config);
152
+ if (!configPath)
153
+ return false;
154
+ const cache = await fs.readFile(`${configPath}.capabilities.json`, 'utf8')
155
+ .then(raw => JSON.parse(raw)).catch(() => undefined);
156
+ return cache?.key === candidateCapabilityKey(config, route) && cache.candidate_testing === true;
157
+ }
158
+ export async function saveCandidateCapability(config, route, allowed) {
159
+ const configPath = getLoadedConfigPath(config);
160
+ if (configPath) {
161
+ await writeConfigAtomically(`${configPath}.capabilities.json`, {
162
+ key: candidateCapabilityKey(config, route),
163
+ candidate_testing: allowed,
164
+ });
165
+ }
166
+ }
144
167
  export async function removeConfig(configPath) {
145
168
  const resolvedPath = resolveConfigPath(configPath);
146
169
  try {
@@ -276,7 +299,7 @@ async function writeConfigAtomically(configPath, config) {
276
299
  encoding: 'utf8',
277
300
  mode: 0o600,
278
301
  });
279
- await fs.rename(temporaryPath, configPath);
302
+ await renameReplacing(temporaryPath, configPath);
280
303
  await fs.chmod(configPath, 0o600);
281
304
  }
282
305
  finally {
@@ -7,6 +7,7 @@ import { CREATOR_LOGIN_SESSION_FLAG, creatorLoginStatusPath, isCreatorLoginSessi
7
7
  import { handleCreatorPassportLogin } from './creator-passport-login.js';
8
8
  import { formatCreatorQrExpiry } from './external-login/passport-utils.js';
9
9
  import { printText } from './output.js';
10
+ import { DETACHED_WORKER_OPTIONS } from './platform-process.js';
10
11
  import { laneHeaders, laneName } from './request-source.js';
11
12
  import { CliError, } from './types.js';
12
13
  /** How long the worker waits for the status file that carries its request. */
@@ -358,7 +359,7 @@ function spawnWorker(parsed, options, deps) {
358
359
  '--config',
359
360
  resolveConfigPath(options.configPath),
360
361
  `--${CREATOR_LOGIN_SESSION_FLAG}`,
361
- ], { detached: true, stdio: 'ignore', cwd: process.cwd(), env: process.env });
362
+ ], { ...DETACHED_WORKER_OPTIONS, stdio: 'ignore', cwd: process.cwd(), env: process.env });
362
363
  child.on('error', () => undefined);
363
364
  child.unref();
364
365
  return child;