@open-dy/interest-card-cli 0.1.0-beta.29 → 0.1.0-beta.31

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 (205) hide show
  1. package/browser-runtime/scripts/cli.mjs +10 -3
  2. package/browser-runtime/scripts/inspect-preview-state.mjs +6 -4
  3. package/card-skills/douyin-interest-card-browser/references/commands.md +1 -1
  4. package/card-skills/douyin-interest-card-capability/SKILL.md +12 -4
  5. package/card-skills/douyin-interest-card-capability/references/common/openapi/external/guide.md +5 -5
  6. package/card-skills/douyin-interest-card-capability/references/microapp/api/capability-index.json +27 -27
  7. package/card-skills/douyin-interest-card-capability/references/microapp/api/connect-socket.md +24 -1
  8. package/card-skills/douyin-interest-card-capability/references/microapp/api/create-bytenn-engine-context.md +11 -1
  9. package/card-skills/douyin-interest-card-capability/references/microapp/api/create-camera-context.md +12 -0
  10. package/card-skills/douyin-interest-card-capability/references/microapp/api/create-canvas-context.md +45 -1
  11. package/card-skills/douyin-interest-card-capability/references/microapp/api/create-effect-camera-stream.md +21 -1
  12. package/card-skills/douyin-interest-card-capability/references/microapp/api/create-inner-audio-context.md +80 -3
  13. package/card-skills/douyin-interest-card-capability/references/microapp/api/create-intersection-observer.md +12 -1
  14. package/card-skills/douyin-interest-card-capability/references/microapp/api/create-interstitial-ad.md +12 -0
  15. package/card-skills/douyin-interest-card-capability/references/microapp/api/create-live-player-context.md +16 -0
  16. package/card-skills/douyin-interest-card-capability/references/microapp/api/create-map-context.md +24 -0
  17. package/card-skills/douyin-interest-card-capability/references/microapp/api/create-media-recorder.md +17 -0
  18. package/card-skills/douyin-interest-card-capability/references/microapp/api/create-offscreen-canvas.md +9 -1
  19. package/card-skills/douyin-interest-card-capability/references/microapp/api/create-rewarded-video-ad.md +16 -0
  20. package/card-skills/douyin-interest-card-capability/references/microapp/api/create-rtc-room-context.md +33 -0
  21. package/card-skills/douyin-interest-card-capability/references/microapp/api/create-scene-activity-context.md +13 -0
  22. package/card-skills/douyin-interest-card-capability/references/microapp/api/create-selector-query.md +13 -1
  23. package/card-skills/douyin-interest-card-capability/references/microapp/api/create-sticker-manager.md +11 -1
  24. package/card-skills/douyin-interest-card-capability/references/microapp/api/create-video-context.md +17 -0
  25. package/card-skills/douyin-interest-card-capability/references/microapp/api/download-file.md +10 -0
  26. package/card-skills/douyin-interest-card-capability/references/microapp/api/get-algorithm-manager.md +9 -1
  27. package/card-skills/douyin-interest-card-capability/references/microapp/api/get-background-audio-manager.md +60 -1
  28. package/card-skills/douyin-interest-card-capability/references/microapp/api/get-file-system-manager.md +37 -0
  29. package/card-skills/douyin-interest-card-capability/references/microapp/api/get-recorder-manager.md +23 -0
  30. package/card-skills/douyin-interest-card-capability/references/microapp/api/get-update-manager.md +11 -0
  31. package/card-skills/douyin-interest-card-capability/references/microapp/api/preload-video.md +8 -0
  32. package/card-skills/douyin-interest-card-capability/references/microapp/api/request.md +8 -0
  33. package/card-skills/douyin-interest-card-capability/references/microapp/api/upload-file.md +10 -0
  34. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/capability-index.json +9 -4
  35. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/censor-image.md +1 -1
  36. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/censor-text.md +1 -1
  37. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/check-fans.md +1 -1
  38. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/create-activity.md +1 -1
  39. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-affiliate-id.md +1 -1
  40. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-aiuser-data-info.md +1 -1
  41. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-aiuser-item-list.md +1 -1
  42. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-aiuser-profile.md +1 -1
  43. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-fans-favourite.md +1 -1
  44. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-fans-profile.md +1 -1
  45. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-fans-source.md +1 -1
  46. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-feed.md +1 -1
  47. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-follow-feed.md +1 -1
  48. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-follow-hot-word.md +1 -1
  49. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-friend-list.md +1 -1
  50. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-hot-list.md +1 -1
  51. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-music-collection-list.md +1 -1
  52. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-recommend.md +1 -1
  53. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-related-id.md +1 -1
  54. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-room-real-time-data.md +1 -1
  55. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-user-basic-data.md +1 -1
  56. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-user-cert-labels-info.md +1 -1
  57. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-user-comment-data.md +1 -1
  58. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-user-constellation.md +1 -1
  59. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-user-fans-data.md +1 -1
  60. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-user-fans-profile.md +1 -1
  61. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-user-following.md +1 -1
  62. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-user-hash-mobile.md +1 -1
  63. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-user-interest.md +1 -1
  64. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-user-item-data.md +1 -1
  65. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-user-like-data.md +1 -1
  66. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-user-profile-data.md +1 -1
  67. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-user-share-data.md +1 -1
  68. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/get-video-pack.md +48 -3
  69. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/modify-activity.md +1 -1
  70. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/query-activity-info.md +1 -1
  71. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/query-activity-user-completion-status.md +1 -1
  72. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/query-room-data.md +1 -1
  73. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/search-experience.md +1 -1
  74. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/search-general.md +1 -1
  75. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/search-live.md +1 -1
  76. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/search-music.md +1 -1
  77. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/search-user.md +1 -1
  78. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/search-video.md +1 -1
  79. package/card-skills/douyin-interest-card-capability/references/microapp/openapi/external/search-vision.md +1 -1
  80. package/card-skills/douyin-interest-card-capability/references/opencard/api/call-container.md +1 -0
  81. package/card-skills/douyin-interest-card-capability/references/opencard/api/capability-index.json +6 -6
  82. package/card-skills/douyin-interest-card-capability/references/opencard/api/create-inner-audio-context.md +60 -1
  83. package/card-skills/douyin-interest-card-capability/references/opencard/api/create-map-context.md +24 -0
  84. package/card-skills/douyin-interest-card-capability/references/opencard/api/create-selector-query.md +13 -1
  85. package/card-skills/douyin-interest-card-capability/references/opencard/api/create-video-context.md +17 -0
  86. package/card-skills/douyin-interest-card-capability/references/opencard/api/download-file.md +1 -3
  87. package/card-skills/douyin-interest-card-capability/references/opencard/api/get-background-audio-manager.md +60 -1
  88. package/card-skills/douyin-interest-card-capability/references/opencard/api/request.md +1 -3
  89. package/card-skills/douyin-interest-card-capability/references/opencard/api/upload-file.md +1 -3
  90. package/card-skills/douyin-interest-card-capability/references/opencard/closed-domain-openapi.md +2 -2
  91. package/card-skills/douyin-interest-card-capability/references/opencard/component/button.md +4 -2
  92. package/card-skills/douyin-interest-card-capability/references/opencard/component/canvas.md +4 -3
  93. package/card-skills/douyin-interest-card-capability/references/opencard/component/capability-index.json +8 -9
  94. package/card-skills/douyin-interest-card-capability/references/opencard/component/checkbox-group.md +2 -0
  95. package/card-skills/douyin-interest-card-capability/references/opencard/component/image.md +3 -2
  96. package/card-skills/douyin-interest-card-capability/references/opencard/component/input.md +3 -2
  97. package/card-skills/douyin-interest-card-capability/references/opencard/component/text.md +3 -3
  98. package/card-skills/douyin-interest-card-capability/references/opencard/component/textarea.md +5 -5
  99. package/card-skills/douyin-interest-card-capability/references/opencard/component/video.md +10 -2
  100. package/card-skills/douyin-interest-card-capability/references/opencard/component-guide.md +5 -3
  101. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/capability-index.json +16 -11
  102. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/censor-image.md +1 -1
  103. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/censor-text.md +1 -1
  104. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/check-fans.md +1 -1
  105. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/create-activity.md +1 -1
  106. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-affiliate-id.md +1 -1
  107. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-aiuser-data-info.md +10 -9
  108. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-aiuser-item-list.md +10 -9
  109. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-aiuser-profile.md +10 -9
  110. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-fans-favourite.md +1 -1
  111. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-fans-profile.md +1 -1
  112. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-fans-source.md +1 -1
  113. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-feed.md +1 -1
  114. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-follow-feed.md +1 -1
  115. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-follow-hot-word.md +1 -1
  116. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-friend-list.md +1 -1
  117. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-hot-list.md +1 -1
  118. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-music-collection-list.md +1 -1
  119. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-recommend.md +1 -1
  120. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-related-id.md +1 -1
  121. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-room-real-time-data.md +1 -1
  122. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-user-basic-data.md +10 -9
  123. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-user-cert-labels-info.md +1 -1
  124. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-user-comment-data.md +1 -1
  125. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-user-constellation.md +10 -9
  126. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-user-fans-data.md +1 -1
  127. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-user-fans-profile.md +1 -1
  128. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-user-following.md +10 -9
  129. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-user-hash-mobile.md +1 -1
  130. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-user-interest.md +10 -9
  131. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-user-item-data.md +1 -1
  132. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-user-like-data.md +1 -1
  133. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-user-profile-data.md +1 -1
  134. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-user-share-data.md +1 -1
  135. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/get-video-pack.md +48 -3
  136. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/modify-activity.md +1 -1
  137. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/query-activity-info.md +1 -1
  138. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/query-activity-user-completion-status.md +1 -1
  139. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/query-room-data.md +1 -1
  140. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/search-experience.md +1 -1
  141. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/search-general.md +1 -1
  142. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/search-live.md +1 -1
  143. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/search-music.md +1 -1
  144. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/search-user.md +1 -1
  145. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/search-video.md +1 -1
  146. package/card-skills/douyin-interest-card-capability/references/opencard/openapi/search-vision.md +1 -1
  147. package/card-skills/douyin-interest-card-cli/SKILL.md +1 -1
  148. package/card-skills/douyin-interest-card-generate/SKILL.md +5 -3
  149. package/card-skills/douyin-interest-card-generate/init.sh +13 -23
  150. package/card-skills/douyin-interest-card-generate/references/common/fullstack.md +6 -10
  151. package/card-skills/douyin-interest-card-generate/references/common/private-data-intent-routing.md +1 -1
  152. package/card-skills/douyin-interest-card-generate/references/common/upgrade-to-post.md +1 -1
  153. package/card-skills/douyin-interest-card-generate/references/microapp/microapp.md +1 -1
  154. package/card-skills/douyin-interest-card-generate/references/opencard/api.md +8 -0
  155. package/card-skills/douyin-interest-card-generate/references/opencard/closed-domain-card.md +1 -1
  156. package/card-skills/douyin-interest-card-generate/references/opencard/components.md +11 -28
  157. package/card-skills/douyin-interest-card-generate/references/opencard/opencard.md +9 -7
  158. package/card-skills/douyin-interest-card-generate/references/opencard/rendering.md +5 -5
  159. package/card-skills/douyin-interest-card-generate/references/opencard/taro-dsl.md +6 -6
  160. package/card-skills/douyin-interest-card-generate/templates/fragments/opencard/package.json +2 -2
  161. package/card-skills/douyin-interest-card-generate/templates/fragments/opencard/pnpm-lock.yaml +17 -17
  162. package/card-skills/douyin-interest-card-generate/templates/taro/closed-domain-server/package.json +1 -1
  163. package/card-skills/douyin-interest-card-generate/templates/taro/package.json +5 -4
  164. package/card-skills/douyin-interest-card-generate/templates/taro/pnpm-lock.yaml +27 -26
  165. package/card-skills/douyin-interest-card-generate/templates/taro/server/package.json +1 -1
  166. package/dist/src/args.js +23 -8
  167. package/dist/src/browser.js +3 -1
  168. package/dist/src/card/agent-chat.js +4 -0
  169. package/dist/src/card/binding.js +2 -1
  170. package/dist/src/card/candidate.js +90 -0
  171. package/dist/src/card/card-api.js +2 -2
  172. package/dist/src/card/card-token.js +25 -2
  173. package/dist/src/card/chat-commands.js +26 -11
  174. package/dist/src/card/constants.js +5 -0
  175. package/dist/src/card/create-project-client.js +2 -2
  176. package/dist/src/card/create.js +29 -3
  177. package/dist/src/card/editor-client.js +41 -6
  178. package/dist/src/card/editor-fs.js +4 -4
  179. package/dist/src/card/global-skills.js +6 -1
  180. package/dist/src/card/handlers-misc.js +3 -6
  181. package/dist/src/card/handlers.js +32 -24
  182. package/dist/src/card/help.js +6 -4
  183. package/dist/src/card/ignore.js +22 -0
  184. package/dist/src/card/project.js +13 -4
  185. package/dist/src/card-install.js +8 -9
  186. package/dist/src/cli.js +5 -2
  187. package/dist/src/config.js +26 -3
  188. package/dist/src/creator-device-login.js +2 -1
  189. package/dist/src/creator-login-session.js +6 -6
  190. package/dist/src/creator-passport-login.js +8 -2
  191. package/dist/src/creator-session.js +30 -7
  192. package/dist/src/current-user.js +29 -0
  193. package/dist/src/help-access.js +22 -0
  194. package/dist/src/help.js +6 -2
  195. package/dist/src/http.js +4 -4
  196. package/dist/src/login-handlers.js +2 -1
  197. package/dist/src/platform-process.js +98 -0
  198. package/dist/src/platform.js +1 -1
  199. package/dist/src/request-source.js +4 -0
  200. package/dist/src/telemetry-session.js +17 -0
  201. package/dist/src/telemetry.js +166 -3
  202. package/dist/src/update-check.js +5 -3
  203. package/dist/src/upgrade.js +20 -8
  204. package/package.json +1 -1
  205. package/card-skills/douyin-interest-card-capability/references/opencard/component/svg.md +0 -58
@@ -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;
@@ -8,6 +8,8 @@ import { sleep } from './cli-helpers.js';
8
8
  import { resolveConfigPath } from './config.js';
9
9
  import { formatCreatorQrExpiry } from './external-login/passport-utils.js';
10
10
  import { printText } from './output.js';
11
+ import { LINK_LOGIN_FALLBACK } from './browser.js';
12
+ import { DETACHED_WORKER_OPTIONS, writeFileReplacing } from './platform-process.js';
11
13
  import { renderQrCode } from './qr.js';
12
14
  import { CliError } from './types.js';
13
15
  /** Private argv flag for the background process that keeps the QR session alive. */
@@ -83,15 +85,13 @@ function isInside(child, parent) {
83
85
  }
84
86
  export async function publishCreatorLoginStatus(configPath, status) {
85
87
  const target = creatorLoginStatusPath(configPath);
86
- const temporary = `${target}.${process.pid}.tmp`;
87
88
  await fs.mkdir(path.dirname(target), { recursive: true });
88
89
  // The status may hold a link authorization's device_code: owner-only, like the config file.
89
- await fs.writeFile(temporary, JSON.stringify({
90
+ await writeFileReplacing(target, JSON.stringify({
90
91
  ...status,
91
92
  pid: status.pid ?? process.pid,
92
93
  configPath: resolveConfigPath(configPath),
93
- }), { mode: 0o600 });
94
- await fs.rename(temporary, target);
94
+ }), 0o600);
95
95
  await fs.chmod(target, 0o600).catch(() => undefined);
96
96
  }
97
97
  /** The detached login finished: the status file must stop saying it waits for a scan. */
@@ -127,7 +127,7 @@ export async function detachCreatorLogin(parsed, options, deps = {}) {
127
127
  // Link authorization is the default login, so the QR worker is told to stay on the QR flow.
128
128
  ...sessionWorkerArgs(argv.slice(2).filter(arg => arg !== '--qr')),
129
129
  '--qr',
130
- ], { detached: true, stdio: 'ignore', cwd: process.cwd(), env: process.env });
130
+ ], { ...DETACHED_WORKER_OPTIONS, stdio: 'ignore', cwd: process.cwd(), env: process.env });
131
131
  child.on('error', () => undefined);
132
132
  child.unref();
133
133
  let status;
@@ -195,7 +195,7 @@ async function waitForHandoff(statusPath, pid, deps) {
195
195
  }
196
196
  await pause(200);
197
197
  }
198
- throw new CliError('Creator center QR login did not produce a QR code. Run `interest-card-cli login --platform creator --json` again.', 'PASSPORT_QR_INIT_TIMEOUT');
198
+ throw new CliError(`Creator center QR login did not produce a QR code. ${LINK_LOGIN_FALLBACK}`, 'PASSPORT_QR_INIT_TIMEOUT');
199
199
  }
200
200
  function sessionWorkerArgs(args) {
201
201
  return [
@@ -1,4 +1,4 @@
1
- import { launchLoginBrowser } from './browser.js';
1
+ import { LINK_LOGIN_FALLBACK, launchLoginBrowser } from './browser.js';
2
2
  import { getNumber, sleep } from './cli-helpers.js';
3
3
  import { createCookieCredentialConfig, getConfigBaseUrl, sanitizeConfig, saveConfig, } from './config.js';
4
4
  import { tokenLoginConfig } from './card/card-token.js';
@@ -46,7 +46,13 @@ export async function handleCreatorPassportLogin(parsed, options) {
46
46
  watchPassportResponses(page, parsed, qrState, notify, publishScan);
47
47
  notify('Starting creator center QR login...');
48
48
  await openCreatorLogin(page, options.baseUrl);
49
- await qrState.waitForQr(Math.min(30, timeoutSeconds));
49
+ await qrState.waitForQr(Math.min(30, timeoutSeconds)).catch((error) => {
50
+ // The login page never showed a QR code here; link authorization does not need the page.
51
+ if (error instanceof CliError && error.code === 'PASSPORT_QR_INIT_TIMEOUT') {
52
+ throw new CliError(`${error.message} ${LINK_LOGIN_FALLBACK}`, error.code);
53
+ }
54
+ throw error;
55
+ });
50
56
  await waitUntilConfirmed(qrState, page, options.baseUrl, {
51
57
  timeoutSeconds,
52
58
  intervalSeconds,
@@ -2,6 +2,7 @@ import { cardApi } from './card/card-api.js';
2
2
  import { isCardGateError } from './card/card-token.js';
3
3
  import { CARD_API_ROUTES } from './card/constants.js';
4
4
  import { requestJson } from './http.js';
5
+ import { noteSessionCheckRetry } from './telemetry-session.js';
5
6
  import { CliError } from './types.js';
6
7
  /** Douyin passport app id of the creator center (see apps/creator-application creator-logout). */
7
8
  export const CREATOR_PASSPORT_AID = 2906;
@@ -13,12 +14,25 @@ export const CREATOR_PASSPORT_AID = 2906;
13
14
  * and a service that is down or unreachable are reported as what they are: scanning again does
14
15
  * not fix any of them.
15
16
  */
16
- export async function verifyCreatorSession(config) {
17
- try {
18
- await cardApi(config, CARD_API_ROUTES.tenantList, {});
19
- }
20
- catch (error) {
21
- throw sessionCheckError(error);
17
+ /** How long the login waits for a card service that answers 5xx, and how often it asks again. */
18
+ export const SESSION_CHECK_RETRY_WINDOW_MS = 30_000;
19
+ const SESSION_CHECK_RETRY_INTERVAL_MS = 3_000;
20
+ export async function verifyCreatorSession(config, options = {}) {
21
+ const now = options.now ?? Date.now;
22
+ const pause = options.sleep ?? ((ms) => new Promise(resolve => setTimeout(resolve, ms)));
23
+ const deadline = now() + (options.retryServerErrorMs ?? 0);
24
+ for (;;) {
25
+ try {
26
+ await cardApi(config, CARD_API_ROUTES.tenantList, {});
27
+ break;
28
+ }
29
+ catch (error) {
30
+ if (!isServerError(error) || now() + SESSION_CHECK_RETRY_INTERVAL_MS > deadline) {
31
+ throw sessionCheckError(error);
32
+ }
33
+ noteSessionCheckRetry();
34
+ await pause(SESSION_CHECK_RETRY_INTERVAL_MS);
35
+ }
22
36
  }
23
37
  const account = await requestJson(config, {
24
38
  path: '/passport/web/account/info/',
@@ -26,7 +40,9 @@ export async function verifyCreatorSession(config) {
26
40
  assertBusinessSuccess: false,
27
41
  }).catch(() => undefined);
28
42
  const data = account?.data || {};
29
- const userId = String(data.user_id_str || data.user_id || '').trim();
43
+ const rawId = data.user_id_str || data.user_id;
44
+ const userId = typeof rawId === 'number' && !Number.isSafeInteger(rawId)
45
+ ? '' : String(rawId || '').trim();
30
46
  return {
31
47
  id: userId,
32
48
  email: userId || 'creator',
@@ -35,6 +51,13 @@ export async function verifyCreatorSession(config) {
35
51
  avatar: data.avatar_url || '',
36
52
  };
37
53
  }
54
+ function isServerError(error) {
55
+ if (isCardGateError(error) || !(error instanceof CliError)) {
56
+ return false;
57
+ }
58
+ const status = error.details?.status;
59
+ return typeof status === 'number' && status >= 500;
60
+ }
38
61
  function sessionCheckError(error) {
39
62
  if (isCardGateError(error)) {
40
63
  return error;
@@ -0,0 +1,29 @@
1
+ import { printText } from './output.js';
2
+ import { CliError } from './types.js';
3
+ import { cardApi } from './card/card-api.js';
4
+ import { saveCandidateCapability } from './config.js';
5
+ import { cliSourceHeaders } from './request-source.js';
6
+ import { CARD_API_ROUTES, getCardApiBaseUrl } from './card/constants.js';
7
+ import { getCardPpeHeaders, loadCardConfig } from './card/project.js';
8
+ export function candidateCapabilityRoute(parsed) {
9
+ return JSON.stringify([getCardApiBaseUrl(), cliSourceHeaders(getCardPpeHeaders(parsed)['x-tt-env'])['x-tt-env'] ?? '']);
10
+ }
11
+ /** Resolve the current account from the authenticated server, never a project owner or cached email. */
12
+ export async function handleWhoami(parsed) {
13
+ const { config } = await loadCardConfig(parsed);
14
+ const response = await cardApi(config, CARD_API_ROUTES.authMe, {}, { headers: getCardPpeHeaders(parsed) });
15
+ const uid = response.data?.uid;
16
+ if (typeof uid !== 'string' || !/^[1-9][0-9]*$/.test(uid)) {
17
+ throw new CliError('The identity endpoint did not return a valid UID string.', 'CURRENT_USER_ID_UNAVAILABLE');
18
+ }
19
+ const capabilities = { candidate_testing: response.data?.capabilities?.candidate_testing === true };
20
+ if (config.token_type === 'Bearer') {
21
+ await saveCandidateCapability(config, candidateCapabilityRoute(parsed), capabilities.candidate_testing)
22
+ .catch(() => undefined);
23
+ }
24
+ const result = { ok: true, command: 'whoami', baseUrl: config.base_url,
25
+ data: { uid, source: 'cli_auth_me', capabilities } };
26
+ if (!parsed.options.json)
27
+ printText(uid);
28
+ return result;
29
+ }
@@ -0,0 +1,22 @@
1
+ import { hasExplicitPlatform, resolveCommandConfigPath } from './command-context.js';
2
+ import { readCandidateCapability, tryLoadConfig } from './config.js';
3
+ import { helpText } from './help.js';
4
+ import { candidateCapabilityRoute } from './current-user.js';
5
+ /** Help reads cached display preferences. Candidate authorization is enforced by the service. */
6
+ async function canShowTestingHelp(parsed) {
7
+ try {
8
+ const scoped = hasExplicitPlatform(parsed) ? parsed
9
+ : { ...parsed, options: { ...parsed.options, platform: 'creator' } };
10
+ const config = await tryLoadConfig(resolveCommandConfigPath(scoped));
11
+ if (config?.token_type !== 'Bearer' || !(Date.parse(config.expires_at) > Date.now()))
12
+ return false;
13
+ return await readCandidateCapability(config, candidateCapabilityRoute(parsed));
14
+ }
15
+ catch {
16
+ return false;
17
+ }
18
+ }
19
+ export async function resolvedHelpText(parsed, command) {
20
+ const needsAccess = !['install', 'card-install', 'login', 'logout', 'upgrade', 'version', 'browser'].includes(command ?? '');
21
+ return helpText(command, needsAccess && await canShowTestingHelp(parsed));
22
+ }
package/dist/src/help.js CHANGED
@@ -1,7 +1,11 @@
1
1
  import { cardHelp } from './card/help.js';
2
2
  import { DEFAULT_CREATOR_CONFIG_PATH, getCliVersion } from './types.js';
3
- export function helpText(command) {
3
+ export function helpText(command, testingAllowed = false) {
4
4
  switch (command) {
5
+ case 'whoami':
6
+ return testingAllowed
7
+ ? 'interest-card-cli whoami [--platform creator] [--config <path>] [--ppe <lane>] [--json]'
8
+ : cardHelp(false);
5
9
  case 'install':
6
10
  case 'card-install':
7
11
  return installHelp();
@@ -15,7 +19,7 @@ export function helpText(command) {
15
19
  case 'browser':
16
20
  return browserHelp();
17
21
  default:
18
- return cardHelp();
22
+ return cardHelp(testingAllowed);
19
23
  }
20
24
  }
21
25
  function installHelp() {
package/dist/src/http.js CHANGED
@@ -126,12 +126,12 @@ export function getAgentTraceDetail(config, params) {
126
126
  },
127
127
  });
128
128
  }
129
- export async function verifyAuth(config) {
130
- await verifyUserSession(config);
129
+ export async function verifyAuth(config, options = {}) {
130
+ await verifyUserSession(config, options);
131
131
  }
132
- export async function verifyUserSession(config) {
132
+ export async function verifyUserSession(config, options = {}) {
133
133
  if (isCreatorPlatform(getConfigBaseUrl(config))) {
134
- return verifyCreatorSession(config);
134
+ return verifyCreatorSession(config, options);
135
135
  }
136
136
  const response = await requestJson(config, {
137
137
  path: '/api/getUserInfo',
@@ -4,6 +4,7 @@ import { getNumber } from './cli-helpers.js';
4
4
  import { handleCreatorDeviceLogin, LINK_SENT_FLAG, requireLinkSentBeforeWait, waitForPendingLinkLogin, } from './creator-device-login.js';
5
5
  import { handleCreatorBrowserLogin } from './creator-login.js';
6
6
  import { isCreatorLoginSession } from './creator-login-session.js';
7
+ import { SESSION_CHECK_RETRY_WINDOW_MS } from './creator-session.js';
7
8
  import { handleCreatorPassportLogin } from './creator-passport-login.js';
8
9
  import { isCreatorPlatform } from './platform.js';
9
10
  import { verifyAuth } from './http.js';
@@ -79,7 +80,7 @@ async function reuseExistingLogin(parsed, previous, targetConfigPath, targetBase
79
80
  const runtimePrevious = applyRuntimeConfigOverrides(previous, parsed);
80
81
  try {
81
82
  if (!parsed.options['skip-verify']) {
82
- await verifyAuth(runtimePrevious);
83
+ await verifyAuth(runtimePrevious, { retryServerErrorMs: SESSION_CHECK_RETRY_WINDOW_MS });
83
84
  }
84
85
  const resolvedPath = resolveConfigPath(targetConfigPath);
85
86
  if (!parsed.options.json) {