beautx-cli 1.0.6 → 1.0.7-beta.1

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 (57) hide show
  1. package/README.md +44 -15
  2. package/dist/{analyze-0SATHpUC.mjs → analyze-CcsdZtz9.mjs} +5 -5
  3. package/dist/{api-D3JyDoiw.mjs → api-B5nQypBz.mjs} +2 -2
  4. package/dist/{audio-BfNibfXF.mjs → audio-DVH0I5Zh.mjs} +3 -3
  5. package/dist/{beauty-plan-DQl_OJNK.mjs → beauty-plan-Cd88u5h0.mjs} +4 -4
  6. package/dist/cli.mjs +7651 -19
  7. package/dist/config-BOuRZAk1.mjs +15 -0
  8. package/dist/{consultant-DbYBzHqQ.mjs → consultant-C1uiuItn.mjs} +1 -1
  9. package/dist/{content-BTHG2DCs.mjs → content-CpFANyPe.mjs} +3 -3
  10. package/dist/{current-BDH1xER9.mjs → current--kwV_-9S.mjs} +3 -3
  11. package/dist/{customer-D04eXm64.mjs → customer-Chl1bGg9.mjs} +1 -1
  12. package/dist/{deal-analysis-Dpg9VGjK.mjs → deal-analysis-Bf6TwBmH.mjs} +4 -4
  13. package/dist/{doc-CWgdZ_Eh.mjs → doc-BtwmuoPs.mjs} +3 -3
  14. package/dist/doctor-DuGxP40X.mjs +37 -0
  15. package/dist/{env-vars-CXEHR_mk.mjs → env-vars-Dinhf5lt.mjs} +21 -40
  16. package/dist/{fields-D-iEk93w.mjs → fields-MsjROq8O.mjs} +4 -4
  17. package/dist/{focus-BMcnVGqT.mjs → focus-CM6mZYRj.mjs} +1 -1
  18. package/dist/{get-BLdqZ3XJ.mjs → get-Z_hTyubv.mjs} +3 -3
  19. package/dist/install-DP9xV1rY.mjs +50 -0
  20. package/dist/{kb-BPy6E_uX.mjs → kb-CjQXEOY5.mjs} +2 -2
  21. package/dist/{list-C73pWNBd.mjs → list-B84PLHzp.mjs} +2 -2
  22. package/dist/list-BNZV4wei.mjs +77 -0
  23. package/dist/{list-DyePBi8K.mjs → list-BSR3H7_0.mjs} +4 -4
  24. package/dist/{list-DqXRvhfS.mjs → list-BT0_KdNZ.mjs} +5 -5
  25. package/dist/{list-BMbWa85R.mjs → list-C0wn72hg.mjs} +4 -4
  26. package/dist/{list-DIvD8BvI.mjs → list-C6imhAfi.mjs} +4 -4
  27. package/dist/{list-Ck_kx-iC.mjs → list-CDi3ySyx.mjs} +5 -5
  28. package/dist/{list-JL2fmylz.mjs → list-CGJa9z3d.mjs} +4 -4
  29. package/dist/{list-CB7YZTB4.mjs → list-CJiei-hu.mjs} +4 -4
  30. package/dist/list-D809kN14.mjs +85 -0
  31. package/dist/{mcp-args-CYOCdClW.mjs → mcp-args-B8InvGQc.mjs} +1 -1
  32. package/dist/{mcp-client-OuKd8iir.mjs → mcp-client-aS31KU6J.mjs} +37 -76
  33. package/dist/{mcp-result-B5HHO7ap.mjs → mcp-result-Bl71pkOt.mjs} +2 -2
  34. package/dist/{portrait-tags-DRQi5JcR.mjs → portrait-tags-BYded-6k.mjs} +4 -4
  35. package/dist/{project-CEmZCvSp.mjs → project-DSO_7ofq.mjs} +3 -3
  36. package/dist/project-access-Cq8d1YTo.mjs +2 -0
  37. package/dist/{project-access-O-VSqqVC.mjs → project-access-DlypxnQF.mjs} +21 -30
  38. package/dist/project-store-CYuTFefu.mjs +2 -0
  39. package/dist/project-store-D0UuLan2.mjs +219 -0
  40. package/dist/{qa-B7WbwUts.mjs → qa-CqUiXIZn.mjs} +5 -5
  41. package/dist/{resistance-FtBtoEDl.mjs → resistance-DiDDixVq.mjs} +1 -1
  42. package/dist/{search-BuMtyCiU.mjs → search-sjRwA-la.mjs} +5 -5
  43. package/dist/skill-DBpgezPV.mjs +15 -0
  44. package/dist/skill-client-D4_QGDkj.mjs +171 -0
  45. package/dist/{summary-Cg79V9oz.mjs → summary-C7lrTImW.mjs} +4 -4
  46. package/dist/{text-CGOU6uh9.mjs → text-BZo7B8mz.mjs} +5 -5
  47. package/dist/upload-D4wSmRqs.mjs +76 -0
  48. package/dist/{use-Bzhvb9I3.mjs → use-DQ_M0FOH.mjs} +8 -6
  49. package/dist/{visit-vaoFdiLr.mjs → visit-CxAYV6z6.mjs} +2 -2
  50. package/dist/{visit-evaluate-BQIyxZeM.mjs → visit-evaluate-BTKqc8fd.mjs} +4 -4
  51. package/dist/{visit-query-args-CDDQ9JJ8.mjs → visit-query-args-BLwj26s6.mjs} +2 -2
  52. package/package.json +1 -1
  53. package/dist/config-C8aqUXV7.mjs +0 -14
  54. package/dist/env-callback-CIXEvt0i.mjs +0 -349
  55. package/dist/format-9T59sVxH.mjs +0 -7253
  56. package/dist/list-FCCClcl-.mjs +0 -64
  57. package/dist/project-store-DHqT0-nk.mjs +0 -55
@@ -1,349 +0,0 @@
1
- import { d as resolveEndpoints, f as syncProcessEnv, h as EnvCallbackFailedError, l as readEnv, m as ConfigInvalidError, t as ENV_KEYS, u as requireUserId } from "./env-vars-CXEHR_mk.mjs";
2
- import { appendFileSync, mkdirSync } from "node:fs";
3
- import { join } from "node:path";
4
- import { homedir } from "node:os";
5
- //#region src/core/debug-log.ts
6
- /**
7
- * Append-only debug log under {@code ~//home/wuying/jvscrew/files/.beautx-cli/log.jsonl}.
8
- *
9
- * - Errors are always logged (helps sandbox debugging when Agent hides stderr).
10
- * - Set {@code WANGAI_CLI_DEBUG=1} for verbose HTTP / command tracing.
11
- */
12
- const LOG_DIR = join(homedir(), "/home/wuying/jvscrew/files/.beautx-cli");
13
- const LOG_FILE = join(LOG_DIR, "log.jsonl");
14
- const REDACT_KEYS = new Set([
15
- "mcp_token",
16
- "refresh_token",
17
- "access_token",
18
- "authorization",
19
- "token",
20
- "password",
21
- "secret"
22
- ]);
23
- function isVerboseDebugEnabled() {
24
- const raw = process.env.WANGAI_CLI_DEBUG?.trim().toLowerCase();
25
- return raw === "1" || raw === "true" || raw === "yes";
26
- }
27
- function debugLogPath() {
28
- return LOG_FILE;
29
- }
30
- function debugLog(level, event, payload) {
31
- if (level === "info" && !isVerboseDebugEnabled()) return;
32
- try {
33
- mkdirSync(LOG_DIR, { recursive: true });
34
- appendFileSync(LOG_FILE, `${JSON.stringify({
35
- ts: (/* @__PURE__ */ new Date()).toISOString(),
36
- level,
37
- event,
38
- pid: process.pid,
39
- ...payload ? { data: redactValue(payload) } : {}
40
- })}\n`, "utf8");
41
- } catch {}
42
- }
43
- function debugLogError(event, payload) {
44
- debugLog("error", event, payload);
45
- }
46
- function debugLogInfo(event, payload) {
47
- debugLog("info", event, payload);
48
- }
49
- function redactValue(value, key) {
50
- if (value == null) return value;
51
- if (key && REDACT_KEYS.has(key.toLowerCase())) return "[REDACTED]";
52
- if (typeof value === "string") {
53
- if (/^Bearer\s+/i.test(value)) return "Bearer [REDACTED]";
54
- if (value.length > 64 && /^eyJ[\w-]+\.eyJ/.test(value)) return "[REDACTED_JWT]";
55
- return value;
56
- }
57
- if (Array.isArray(value)) return value.map((item) => redactValue(item));
58
- if (typeof value === "object") {
59
- const out = {};
60
- for (const [k, v] of Object.entries(value)) out[k] = redactValue(v, k);
61
- return out;
62
- }
63
- return value;
64
- }
65
- //#endregion
66
- //#region src/core/http-error.ts
67
- /** Extract human {@code msg} from Host / Pierre envelopes embedded in HTTP bodies. */
68
- function parseHttpErrorBody(status, text) {
69
- const trimmed = text?.trim() ?? "";
70
- if (!trimmed) return { message: `HTTP ${status}` };
71
- try {
72
- const parsed = JSON.parse(trimmed);
73
- const msg = pickString(parsed, "msg", "message") ?? (parsed.error && typeof parsed.error === "object" ? pickString(parsed.error, "message", "msg") : void 0);
74
- const code = pickString(parsed, "code") ?? (parsed.error && typeof parsed.error === "object" ? pickString(parsed.error, "code") : void 0);
75
- if (msg) return {
76
- message: msg,
77
- code,
78
- details: parsed
79
- };
80
- return {
81
- message: `HTTP ${status}`,
82
- code,
83
- details: parsed
84
- };
85
- } catch {
86
- return {
87
- message: trimmed.length > 500 ? `${trimmed.slice(0, 500)}…` : trimmed,
88
- details: trimmed
89
- };
90
- }
91
- }
92
- function pickString(obj, ...keys) {
93
- for (const key of keys) {
94
- const value = obj[key];
95
- if (value != null && String(value).trim()) return String(value).trim();
96
- }
97
- }
98
- //#endregion
99
- //#region src/core/env-callback.ts
100
- /**
101
- * Host env-vars callback — read-merge-write on each update.
102
- *
103
- * Host GET returns variable **definitions** (key, description); it does not
104
- * return live values. The sandbox {@link process.env} is the source of truth
105
- * for current values when building the POST body.
106
- */
107
- const RETRY_DELAYS_MS = [
108
- 0,
109
- 300,
110
- 800
111
- ];
112
- function envVarsUrl(query) {
113
- const userId = requireUserId();
114
- const { callbackBaseUrl } = resolveEndpoints();
115
- let url = `${callbackBaseUrl.replace(/\/$/, "")}/api/wang-claw/out/env-vars/${encodeURIComponent(userId)}`;
116
- const tenantId = query?.tenantId?.trim();
117
- if (tenantId) url += `?${new URLSearchParams({ tenantId }).toString()}`;
118
- return url;
119
- }
120
- /** Host env-vars API requires {@code tenantId} query param; fall back to current env. */
121
- function resolveCallbackTenantId(explicit) {
122
- return explicit?.trim() || readEnv(ENV_KEYS.TENANT_ID)?.trim() || void 0;
123
- }
124
- /** Host GET: key + description (+ metadata). Values are filled from process.env. */
125
- function parseEnvVarDefinitions(parsed) {
126
- if (!parsed || typeof parsed !== "object") return [];
127
- const obj = parsed;
128
- let vars = obj.variables;
129
- if (!Array.isArray(vars) && obj.data && typeof obj.data === "object") vars = obj.data.variables;
130
- if (!Array.isArray(vars)) return [];
131
- return vars.filter((v) => Boolean(v) && typeof v === "object").map((v) => ({
132
- key: String(v.key ?? "").trim(),
133
- value: "",
134
- description: v.description != null ? String(v.description) : void 0
135
- })).filter((v) => v.key);
136
- }
137
- /** Fill variable values from the live sandbox env (Host-injected process.env). */
138
- function hydrateEnvVarValuesFromProcessEnv(items) {
139
- return items.map((item) => {
140
- const fromEnv = process.env[item.key]?.trim();
141
- return fromEnv ? {
142
- ...item,
143
- value: fromEnv
144
- } : item;
145
- });
146
- }
147
- /** When Host has no stored record yet, seed merge from non-empty process.env keys. */
148
- function knownEnvVarsFromProcessEnv() {
149
- return Object.values(ENV_KEYS).map((key) => {
150
- const value = process.env[key]?.trim();
151
- if (!value) return null;
152
- return {
153
- key,
154
- value,
155
- description: `beautx-cli: ${key}`
156
- };
157
- }).filter((item) => item != null);
158
- }
159
- async function resolveExistingForMerge(query) {
160
- const definitions = await fetchEnvVarDefinitions(query);
161
- if (definitions.length === 0) return knownEnvVarsFromProcessEnv();
162
- return hydrateEnvVarValuesFromProcessEnv(definitions);
163
- }
164
- /** Merge patches onto existing items (values sourced from process.env + patches). */
165
- function mergeEnvVars(existing, patches) {
166
- const patchMap = new Map(patches.map((p) => [p.key, p]));
167
- const merged = [];
168
- const seen = /* @__PURE__ */ new Set();
169
- for (const item of existing) {
170
- const patch = patchMap.get(item.key);
171
- if (patch) {
172
- merged.push({
173
- key: item.key,
174
- value: patch.value,
175
- description: patch.description ?? item.description ?? `beautx-cli: ${item.key}`
176
- });
177
- seen.add(item.key);
178
- } else merged.push({ ...item });
179
- }
180
- for (const patch of patches) {
181
- if (seen.has(patch.key)) continue;
182
- merged.push({
183
- key: patch.key,
184
- value: patch.value,
185
- description: patch.description ?? `beautx-cli: ${patch.key}`
186
- });
187
- }
188
- return merged;
189
- }
190
- /**
191
- * Host POST rejects any variable with blank {@code value} (@NotBlank).
192
- * Fill gaps from the live sandbox env, then drop entries still empty.
193
- */
194
- function prepareVariablesForPost(variables) {
195
- return variables.map((item) => {
196
- if (item.value.trim()) return item;
197
- const fromEnv = process.env[item.key]?.trim();
198
- return fromEnv ? {
199
- ...item,
200
- value: fromEnv
201
- } : item;
202
- }).filter((item) => item.value.trim() !== "");
203
- }
204
- async function fetchWithRetry(url, init) {
205
- let lastFailure;
206
- for (let attempt = 0; attempt < RETRY_DELAYS_MS.length; attempt++) {
207
- if (RETRY_DELAYS_MS[attempt] > 0) await new Promise((r) => setTimeout(r, RETRY_DELAYS_MS[attempt]));
208
- try {
209
- debugLogInfo("env_callback_http", {
210
- method: init.method ?? "GET",
211
- url,
212
- attempt: attempt + 1
213
- });
214
- const resp = await fetch(url, {
215
- ...init,
216
- signal: AbortSignal.timeout(3e4)
217
- });
218
- if (resp.ok || resp.status === 404) {
219
- debugLogInfo("env_callback_http_ok", {
220
- method: init.method ?? "GET",
221
- url,
222
- status: resp.status
223
- });
224
- return resp;
225
- }
226
- const text = await resp.text().catch(() => "");
227
- lastFailure = {
228
- status: resp.status,
229
- text
230
- };
231
- } catch (e) {
232
- lastFailure = {
233
- status: 0,
234
- text: e instanceof Error ? e.message : String(e)
235
- };
236
- }
237
- }
238
- throwEnvCallbackHttpError(lastFailure?.status ?? 0, lastFailure?.text ?? "Host env 回调失败", init.method ?? "GET", url);
239
- }
240
- function throwEnvCallbackHttpError(status, text, method, url) {
241
- const parsed = status > 0 ? parseHttpErrorBody(status, text) : { message: text || "Host env 回调失败" };
242
- debugLogError("env_callback_http_error", {
243
- method,
244
- url,
245
- status: status > 0 ? status : void 0,
246
- message: parsed.message,
247
- upstreamCode: parsed.code,
248
- details: parsed.details
249
- });
250
- throw new EnvCallbackFailedError(parsed.message, {
251
- status: status > 0 ? status : void 0,
252
- upstreamCode: parsed.code,
253
- details: parsed.details
254
- });
255
- }
256
- /** Pull Host variable definitions (keys/descriptions; values come from process.env). */
257
- async function fetchEnvVarDefinitions(query) {
258
- const resp = await fetchWithRetry(envVarsUrl(query), {
259
- method: "GET",
260
- headers: { Accept: "application/json" }
261
- });
262
- if (resp.status === 404) return [];
263
- return parseEnvVarDefinitions(await resp.json().catch(() => ({})));
264
- }
265
- /**
266
- * Update Host env: GET definitions → hydrate values from process.env → merge patches → POST.
267
- * Host requires {@code tenantId} as a query parameter on both GET and POST.
268
- */
269
- async function patchEnvVars(patches, options) {
270
- if (patches.length === 0) return;
271
- const tenantId = resolveCallbackTenantId(options?.tenantId);
272
- if (!tenantId) throw new ConfigInvalidError("Host env 回调缺少 tenantId", "运行 `beautx-cli config list` 确认 TENANT_ID 已注入");
273
- const query = { tenantId };
274
- const variables = prepareVariablesForPost(mergeEnvVars(await resolveExistingForMerge(query), patches));
275
- const url = envVarsUrl(query);
276
- const body = JSON.stringify({ variables: variables.map((v) => ({
277
- key: v.key,
278
- value: v.value,
279
- description: v.description ?? `beautx-cli: ${v.key}`
280
- })) });
281
- let lastFailure;
282
- for (let attempt = 0; attempt < RETRY_DELAYS_MS.length; attempt++) {
283
- if (RETRY_DELAYS_MS[attempt] > 0) await new Promise((r) => setTimeout(r, RETRY_DELAYS_MS[attempt]));
284
- try {
285
- debugLogInfo("env_callback_http", {
286
- method: "POST",
287
- url,
288
- attempt: attempt + 1,
289
- patchKeys: patches.map((p) => p.key)
290
- });
291
- const resp = await fetch(url, {
292
- method: "POST",
293
- headers: { "Content-Type": "application/json" },
294
- body,
295
- signal: AbortSignal.timeout(3e4)
296
- });
297
- if (resp.ok) {
298
- debugLogInfo("env_callback_http_ok", {
299
- method: "POST",
300
- url,
301
- status: resp.status
302
- });
303
- syncProcessEnv(Object.fromEntries(patches.map((p) => [p.key, p.value])));
304
- return;
305
- }
306
- const text = await resp.text().catch(() => "");
307
- lastFailure = {
308
- status: resp.status,
309
- text
310
- };
311
- } catch (e) {
312
- lastFailure = {
313
- status: 0,
314
- text: e instanceof Error ? e.message : String(e)
315
- };
316
- }
317
- }
318
- throwEnvCallbackHttpError(lastFailure?.status ?? 0, lastFailure?.text ?? "Host env 回调失败", "POST", url);
319
- }
320
- async function patchEnvRecord(record, options) {
321
- await patchEnvVars(Object.entries(record).map(([key, value]) => ({
322
- key,
323
- value
324
- })), options);
325
- }
326
- /** Persist refreshed OAuth tokens to Host env. */
327
- async function persistTokensToHost(accessToken, refreshToken, expiresAtMs) {
328
- await patchEnvRecord({
329
- [ENV_KEYS.MCP_TOKEN]: accessToken,
330
- [ENV_KEYS.REFRESH_TOKEN]: refreshToken,
331
- [ENV_KEYS.EXPIRES_TIMES]: String(expiresAtMs)
332
- });
333
- }
334
- /** Persist active project/tenant selection to Host env. */
335
- async function persistActiveProjectToHost(project) {
336
- const tenantId = project.tenantId?.trim();
337
- if (!tenantId) throw new ConfigInvalidError("project use 缺少 tenantId,无法写回 Host 环境", "运行 `beautx-cli config list` 确认 TENANT_ID;若仍失败请联系平台");
338
- const record = {
339
- [ENV_KEYS.TENANT_ID]: tenantId,
340
- [ENV_KEYS.ESTATE_ID]: project.projectId
341
- };
342
- const tenantName = project.tenantName?.trim();
343
- const projectName = project.projectName?.trim();
344
- if (tenantName) record[ENV_KEYS.TENANT_NAME] = tenantName;
345
- if (projectName) record[ENV_KEYS.ESTATE_NAME] = projectName;
346
- await patchEnvRecord(record, { tenantId });
347
- }
348
- //#endregion
349
- export { debugLogPath as a, debugLogInfo as i, persistTokensToHost as n, isVerboseDebugEnabled as o, debugLogError as r, persistActiveProjectToHost as t };