@yosai/cli 0.2.1-test.13 → 0.2.1-test.14

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/README.md CHANGED
@@ -58,6 +58,7 @@ yos skill install # 安装 9 个内置 Skill(总入口 + 领域 + 安装
58
58
  - 环境变量(均优先于配置文件,适合 CI/容器场景):`YOS_API_KEY` 访问令牌、`YOS_ENV` 服务环境(prod / test / dev)
59
59
  - 版本检查:命令执行前会检查对应通道最新版(后台进程查询、结果缓存 10 分钟),落后时以 stderr 提示「请先执行 yos update 升级再继续任务」;升级通道自动跟随服务环境(测试环境跟 test 通道)。CLI 不静默安装,升级由用户或 Agent 按提示显式执行
60
60
  - 服务环境(测试/开发用):`yos login --env test` 切到测试环境,`--env dev` 指向本机开发服务(http://localhost:8080)
61
+ - 托管模式(YOS 客户端内置 CLI 专用):`YOS_MANAGED=1` 时安装、升级、登录与 Skill 由客户端统一管理——不做版本检查与升级提示,拒绝 `update` / `install` / `login` / `skill install`,令牌只认客户端注入的 `YOS_API_KEY`(不读配置文件),`doctor` 跳过配置文件与 Skill 检查;客户端应同时以 `YOS_CONFIG_DIR` 指向自身私有目录,与用户自行安装的 CLI 配置隔离
61
62
 
62
63
  ## 故障排查
63
64
 
package/dist/cli.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { parseArgs } from 'node:util';
2
2
  import { DOMAIN_META } from './domain-commands.js';
3
3
  import { CliError, EXIT, UsageError } from './errors.js';
4
+ import { isBlockedInManaged, isManaged, MANAGED_HINT } from './managed.js';
4
5
  import { print, printErr, renderRows } from './output.js';
5
6
  import { handleUpdateNotice } from './update-notice.js';
6
7
  const registry = [];
@@ -17,7 +18,7 @@ export function renderHelp() {
17
18
  ' 0. yos <领域> --help 按领域浏览能力(kb / docs / retrieve / support / transcript)',
18
19
  ' 1. yos tool list 动态发现全部工具(领域命令未覆盖时)',
19
20
  ' 2. 领域命令未覆盖的场景用 yos tool schema / tool call 兜底',
20
- ' 3. yos skill install 安装内置 Skill,接入本机 AI 助手(Claude Code / Cursor / Qoder 等)',
21
+ ...(isManaged() ? [] : [' 3. yos skill install 安装内置 Skill,接入本机 AI 助手(Claude Code / Cursor / Qoder 等)']),
21
22
  '',
22
23
  '约定:',
23
24
  ' - 输出默认人类可读;--json 输出结构化结果(工具返回原文在 text 字段内)',
@@ -28,6 +29,7 @@ export function renderHelp() {
28
29
  ' YOS_API_KEY 访问令牌',
29
30
  ' YOS_ENV 服务环境(prod / test / dev;缺省生产)',
30
31
  ' YOS_CONFIG_DIR 配置目录(缺省 ~/.config/yos)',
32
+ ' YOS_MANAGED 托管模式(=1 时由 YOS 客户端托管,用户无需设置)',
31
33
  '',
32
34
  '示例:',
33
35
  ' yos doctor',
@@ -39,8 +41,9 @@ export function renderHelp() {
39
41
  ' yos docs download NDxxxx --out ./报告.pdf',
40
42
  '',
41
43
  ];
44
+ const visible = registry.filter((command) => !isBlockedInManaged(command.name));
42
45
  for (const group of GROUP_ORDER) {
43
- const commands = registry.filter((command) => command.group === group);
46
+ const commands = visible.filter((command) => command.group === group);
44
47
  if (commands.length === 0) {
45
48
  continue;
46
49
  }
@@ -48,7 +51,7 @@ export function renderHelp() {
48
51
  lines.push(indentRows(renderRows(commands.map((command) => [command.name, command.description]))));
49
52
  lines.push('');
50
53
  }
51
- const ungrouped = registry.filter((command) => !command.group);
54
+ const ungrouped = visible.filter((command) => !command.group);
52
55
  if (ungrouped.length > 0) {
53
56
  lines.push(indentRows(renderRows(ungrouped.map((command) => [command.name, command.description]))));
54
57
  lines.push('');
@@ -167,6 +170,11 @@ export async function dispatch(argv) {
167
170
  return EXIT.USAGE;
168
171
  }
169
172
  const { command, rest } = matched;
173
+ if (isBlockedInManaged(command.name)) {
174
+ printErr(`错误: 内置 CLI 不支持 yos ${command.name}`);
175
+ printErr(`提示: ${MANAGED_HINT},无需也不能自行执行`);
176
+ return EXIT.USAGE;
177
+ }
170
178
  if (rest.includes('--help') || rest.includes('-h')) {
171
179
  print(renderCommandHelp(command));
172
180
  return EXIT.OK;
@@ -2,6 +2,7 @@ import { register } from '../cli.js';
2
2
  import { loadConfig, maskKey, resolveEnv, resolveKey } from '../config.js';
3
3
  import { DEFAULT_ENV, endpointOfEnv, envLabel } from '../endpoints.js';
4
4
  import { CliError, EXIT } from '../errors.js';
5
+ import { isManaged } from '../managed.js';
5
6
  import { formatIdentity, OpenApisClient } from '../openapis-client.js';
6
7
  import { print, printJson } from '../output.js';
7
8
  import { readPackageMeta } from '../npm-meta.js';
@@ -18,11 +19,10 @@ register({
18
19
  const config = loadConfig();
19
20
  const env = resolveEnv(config);
20
21
  const endpoint = endpointOfEnv(env);
21
- checks.push({
22
- name: '配置文件',
23
- ok: config !== null,
24
- detail: config ? '已找到' : '未找到,请执行 yos login',
25
- });
22
+ const managed = isManaged();
23
+ checks.push(managed
24
+ ? { name: '运行模式', ok: true, detail: '客户端托管(令牌与环境由 YOS 客户端注入)' }
25
+ : { name: '配置文件', ok: config !== null, detail: config ? '已找到' : '未找到,请执行 yos login' });
26
26
  if (env !== DEFAULT_ENV) {
27
27
  checks.push({
28
28
  name: '服务环境',
@@ -54,11 +54,13 @@ register({
54
54
  }
55
55
  }
56
56
  const skillDirs = config?.installedSkillDirs ?? [];
57
- checks.push({
58
- name: 'Skill 安装',
59
- ok: skillDirs.length > 0,
60
- detail: skillDirs.length > 0 ? skillDirs.join(', ') : '尚未安装,执行 yos skill install',
61
- });
57
+ if (!managed) {
58
+ checks.push({
59
+ name: 'Skill 安装',
60
+ ok: skillDirs.length > 0,
61
+ detail: skillDirs.length > 0 ? skillDirs.join(', ') : '尚未安装,执行 yos skill install',
62
+ });
63
+ }
62
64
  const meta = readPackageMeta();
63
65
  const envNote = env === DEFAULT_ENV ? '' : `(环境=${envLabel(env)})`;
64
66
  checks.push({
@@ -66,12 +68,14 @@ register({
66
68
  ok: meta !== null,
67
69
  detail: meta ? `${meta.version}${envNote}` : 'unknown(未找到 package.json)',
68
70
  });
69
- const state = loadVersionState();
70
- checks.push({
71
- name: 'Skill 同步',
72
- ok: meta !== null && state?.version === meta.version && skillDirs.length > 0,
73
- detail: skillSyncDetail(meta, state, skillDirs),
74
- });
71
+ if (!managed) {
72
+ const state = loadVersionState();
73
+ checks.push({
74
+ name: 'Skill 同步',
75
+ ok: meta !== null && state?.version === meta.version && skillDirs.length > 0,
76
+ detail: skillSyncDetail(meta, state, skillDirs),
77
+ });
78
+ }
75
79
  if (flags.json) {
76
80
  printJson({ checks });
77
81
  }
package/dist/config.js CHANGED
@@ -3,6 +3,7 @@ import { homedir } from 'node:os';
3
3
  import { join } from 'node:path';
4
4
  import { channelOfEnv, DEFAULT_ENV, endpointOfEnv } from './endpoints.js';
5
5
  import { UsageError } from './errors.js';
6
+ import { isManaged } from './managed.js';
6
7
  export function configDir() {
7
8
  return process.env.YOS_CONFIG_DIR ?? join(homedir(), '.config', 'yos');
8
9
  }
@@ -32,6 +33,9 @@ export function resolveKey(config) {
32
33
  if (fromEnv) {
33
34
  return fromEnv;
34
35
  }
36
+ if (isManaged()) {
37
+ throw new UsageError('未注入访问令牌', '内置 CLI 的令牌由 YOS 客户端注入 YOS_API_KEY,请重新登录 YOS 客户端');
38
+ }
35
39
  if (config?.apiKey) {
36
40
  return config.apiKey;
37
41
  }
package/dist/errors.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { isManaged } from './managed.js';
1
2
  export const EXIT = {
2
3
  OK: 0,
3
4
  BUSINESS: 1,
@@ -33,11 +34,15 @@ export class NetworkError extends CliError {
33
34
  }
34
35
  export class AuthError extends CliError {
35
36
  constructor(message) {
36
- super(message, EXIT.AUTH, '请执行 `yos login` 重新配置访问令牌');
37
+ super(message, EXIT.AUTH, isManaged()
38
+ ? '内置 CLI 的令牌由 YOS 客户端注入,请重新登录 YOS 客户端'
39
+ : '请执行 `yos login` 重新配置访问令牌');
37
40
  }
38
41
  }
39
42
  export class UpgradeError extends CliError {
40
43
  constructor(message, hint) {
41
- super(message, EXIT.UPGRADE, hint ?? '执行 `yos update` 升级后重试');
44
+ super(message, EXIT.UPGRADE, isManaged()
45
+ ? '请升级 YOS 客户端后重试'
46
+ : hint ?? '执行 `yos update` 升级后重试');
42
47
  }
43
48
  }
@@ -0,0 +1,9 @@
1
+ export const MANAGED_ENV = 'YOS_MANAGED';
2
+ const MANAGED_BLOCKED_COMMANDS = new Set(['update', 'install', 'login', 'skill install']);
3
+ export const MANAGED_HINT = '内置 CLI 的安装、升级、登录与 Skill 由 YOS 客户端统一管理';
4
+ export function isManaged() {
5
+ return process.env[MANAGED_ENV] === '1';
6
+ }
7
+ export function isBlockedInManaged(commandName) {
8
+ return isManaged() && MANAGED_BLOCKED_COMMANDS.has(commandName);
9
+ }
@@ -3,6 +3,7 @@ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
3
3
  import { join } from 'node:path';
4
4
  import { fileURLToPath } from 'node:url';
5
5
  import { configDir, loadConfig, resolveChannel } from './config.js';
6
+ import { isManaged } from './managed.js';
6
7
  import { compareVersions, getCliVersion } from './npm-meta.js';
7
8
  import { printErr } from './output.js';
8
9
  export const CACHE_TTL_MS = 10 * 60 * 1000;
@@ -48,6 +49,9 @@ export function evaluateNotice(input) {
48
49
  return 'notify';
49
50
  }
50
51
  export function handleUpdateNotice(commandName) {
52
+ if (isManaged()) {
53
+ return;
54
+ }
51
55
  try {
52
56
  const channel = resolveChannel(loadConfig());
53
57
  if (channel === null) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yosai/cli",
3
- "version": "0.2.1-test.13",
3
+ "version": "0.2.1-test.14",
4
4
  "description": "YOS 能力的 Agent 执行入口:工具调用、知识库管理与文件上传",
5
5
  "type": "module",
6
6
  "bin": {