openyida 2026.4.20 → 2026.4.24

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.
package/lib/auth/login.js CHANGED
@@ -106,6 +106,7 @@ function refreshCsrfFromCache() {
106
106
  if (!cookieData || !cookieData.cookies) {
107
107
  const { error: chalkError } = require('../core/chalk');
108
108
  chalkError(t('login.no_cookie_cache'));
109
+ return null;
109
110
  }
110
111
 
111
112
  const { csrfToken, corpId, userId } = extractInfoFromCookies(cookieData.cookies);
@@ -113,6 +114,7 @@ function refreshCsrfFromCache() {
113
114
  if (!csrfToken) {
114
115
  const { error: chalkError2 } = require('../core/chalk');
115
116
  chalkError2(t('login.no_csrf_in_cache'));
117
+ return null;
116
118
  }
117
119
 
118
120
  const baseUrl = resolveBaseUrl(cookieData);
@@ -217,6 +219,7 @@ function interactiveLogin() {
217
219
  if (!playwrightPath) {
218
220
  const { error: chalkError3 } = require('../core/chalk');
219
221
  chalkError3(t('login.no_playwright'), { hint: `${t('login.playwright_install1')}\n ${t('login.playwright_install2')}` });
222
+ return null;
220
223
  }
221
224
 
222
225
  const { c: lc, info: chalkInfo, label: chalkLabel2 } = require('../core/chalk');
@@ -303,6 +306,7 @@ const { URL } = require('url');
303
306
  if (!csrfToken) {
304
307
  const { error: chalkError4 } = require('../core/chalk');
305
308
  chalkError4(t('login.no_csrf_in_cookie'));
309
+ return null;
306
310
  }
307
311
 
308
312
  saveCookieCache(result.cookies, result.base_url);
@@ -329,16 +333,32 @@ const { URL } = require('url');
329
333
  * 退出登录:清空项目级 Cookie 文件。
330
334
  */
331
335
  function logout() {
332
- const { c, banner, label, success: chalkSuccess4, warn: chalkWarn, hint: chalkHint, sep } = require('../core/chalk');
336
+ const { banner, label, success: chalkSuccess4, warn: chalkWarn, hint: chalkHint, sep } = require('../core/chalk');
333
337
 
334
338
  banner(t('login.logout_title'));
335
339
 
336
340
  const projectRoot = findProjectRoot();
337
- const projectCookieFile = path.join(projectRoot, '.cache', 'cookies.json');
338
- label('Cookie', projectCookieFile);
339
341
 
340
- if (fs.existsSync(projectCookieFile)) {
341
- fs.unlinkSync(projectCookieFile);
342
+ // 删除当前环境对应的 Cookie 文件(多环境隔离)
343
+ const { getCookieFilePath } = require('../core/env-manager');
344
+ const envCookieFile = getCookieFilePath(projectRoot);
345
+ // 兼容旧版:同时删除 cookies.json(历史遗留文件)
346
+ const legacyCookieFile = path.join(projectRoot, '.cache', 'cookies.json');
347
+
348
+ label('Cookie (env)', envCookieFile);
349
+ if (envCookieFile !== legacyCookieFile) {
350
+ label('Cookie (legacy)', legacyCookieFile);
351
+ }
352
+
353
+ let deleted = false;
354
+ for (const cookieFile of [envCookieFile, legacyCookieFile]) {
355
+ if (fs.existsSync(cookieFile)) {
356
+ fs.unlinkSync(cookieFile);
357
+ deleted = true;
358
+ }
359
+ }
360
+
361
+ if (deleted) {
342
362
  chalkSuccess4(t('login.logout_success'));
343
363
  chalkHint(t('login.logout_hint'));
344
364
  } else {
@@ -254,44 +254,33 @@ class EnvironmentChecker {
254
254
  }
255
255
 
256
256
  checkLoginStatus() {
257
- const cookiePath = path.join(this.projectRoot, '.cache', 'cookies.json');
258
- if (!fs.existsSync(cookiePath)) {
259
- return {
260
- id: 'env-login',
261
- label: '宜搭登录态',
262
- passed: false,
263
- severity: Severity.WARNING,
264
- message: '未登录(运行 yida login 登录)',
265
- fixType: FixType.COMMAND,
266
- fixCommand: 'yida login',
267
- };
268
- }
257
+ // 使用统一的 loadCookieData 加载登录态(兼容多环境 cookie 文件)
258
+ const { loadCookieData } = require('./utils');
259
+ const cookieData = loadCookieData(this.projectRoot);
269
260
 
270
- try {
271
- const cookieData = JSON.parse(fs.readFileSync(cookiePath, 'utf-8'));
272
- const cookies = Array.isArray(cookieData) ? cookieData : cookieData.cookies || [];
273
- const hasToken = cookies.some((c) => c.name === 'tianshu_csrf_token');
274
- const passed = hasToken;
275
- return {
276
- id: 'env-login',
277
- label: `宜搭登录态:${passed ? '已登录' : 'Cookie 存在但可能已过期'}`,
278
- passed,
279
- severity: passed ? Severity.INFO : Severity.WARNING,
280
- message: passed ? null : 'Cookie 可能已过期,运行 yida login 重新登录',
281
- fixType: passed ? null : FixType.COMMAND,
282
- fixCommand: passed ? null : 'yida login',
283
- };
284
- } catch {
261
+ if (!cookieData || !cookieData.cookies || cookieData.cookies.length === 0) {
285
262
  return {
286
263
  id: 'env-login',
287
264
  label: '宜搭登录态',
288
265
  passed: false,
289
266
  severity: Severity.WARNING,
290
- message: 'Cookie 文件损坏',
267
+ message: '未登录(运行 openyida login 登录)',
291
268
  fixType: FixType.COMMAND,
292
- fixCommand: 'yida login',
269
+ fixCommand: 'openyida login --qr',
293
270
  };
294
271
  }
272
+
273
+ const hasToken = cookieData.cookies.some((c) => c.name === 'tianshu_csrf_token');
274
+ const passed = hasToken;
275
+ return {
276
+ id: 'env-login',
277
+ label: `宜搭登录态:${passed ? '已登录' : 'Cookie 存在但可能已过期'}`,
278
+ passed,
279
+ severity: passed ? Severity.INFO : Severity.WARNING,
280
+ message: passed ? null : 'Cookie 可能已过期,运行 openyida login 重新登录',
281
+ fixType: passed ? null : FixType.COMMAND,
282
+ fixCommand: passed ? null : 'openyida login --qr',
283
+ };
295
284
  }
296
285
 
297
286
  async checkNetwork() {
@@ -407,7 +396,7 @@ class VersionChecker {
407
396
  label: `openyida 版本:${installedVersion}(SKILL 期望:${skillVersion})`,
408
397
  passed,
409
398
  severity: passed ? Severity.INFO : Severity.WARNING,
410
- message: passed ? null : `版本不匹配,建议升级到最新版`,
399
+ message: passed ? null : '版本不匹配,建议升级到最新版',
411
400
  fixType: passed ? null : FixType.COMMAND,
412
401
  fixCommand: passed ? null : 'npm install -g openyida@latest',
413
402
  }];
@@ -13,6 +13,7 @@ const { execSync } = require('child_process');
13
13
  const { fetchLatestVersion, isNewer } = require('./check-update');
14
14
  const { t } = require('./i18n');
15
15
  const { warn } = require('./chalk');
16
+ const { getNpmExecutable } = require('./utils');
16
17
 
17
18
  // ── ANSI 颜色常量 ──────────────────────────────────
18
19
  const RESET = '\x1b[0m';
@@ -64,8 +65,8 @@ function renderStatusTable(rows) {
64
65
  */
65
66
  function detectPackageManager() {
66
67
  try {
67
- const npmRoot = execSync('npm root -g', { encoding: 'utf8', timeout: 5000 }).trim();
68
- const globalPath = execSync('npm prefix -g', { encoding: 'utf8', timeout: 5000 }).trim();
68
+ const npmRoot = execSync(`${getNpmExecutable()} root -g`, { encoding: 'utf8', timeout: 5000 }).trim();
69
+ const globalPath = execSync(`${getNpmExecutable()} prefix -g`, { encoding: 'utf8', timeout: 5000 }).trim();
69
70
  if (globalPath && npmRoot) {
70
71
  return 'npm';
71
72
  }
@@ -128,7 +129,7 @@ async function runUpdate(currentVersion) {
128
129
  const installSpinner = createSpinner(t('update.installing'));
129
130
 
130
131
  try {
131
- execSync('npm install -g openyida@latest', {
132
+ execSync(`${getNpmExecutable()} install -g openyida@latest`, {
132
133
  stdio: ['pipe', 'pipe', 'pipe'],
133
134
  timeout: 120000,
134
135
  });
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "openyida",
3
- "version": "2026.04.20",
3
+ "version": "2026.4.24",
4
4
  "description": "OpenYida CLI - 宜搭低代码 AI 开发工具(安装即用,零配置)",
5
5
  "bin": {
6
- "openyida": "./bin/yida.js",
7
- "yida": "./bin/yida.js"
6
+ "openyida": "bin/yida.js",
7
+ "yida": "bin/yida.js"
8
8
  },
9
9
  "files": [
10
10
  "bin/",