qiyu-cli 0.0.0-stage → 0.2.0
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/LICENSE +21 -0
- package/README.md +464 -2
- package/dist/cli.js +248 -0
- package/dist/commands/api.js +770 -0
- package/dist/commands/auth.js +349 -0
- package/dist/commands/credentials-source.js +70 -0
- package/dist/commands/db.js +503 -0
- package/dist/commands/local-fallback-wiring.js +67 -0
- package/dist/commands/local-fallback.js +34 -0
- package/dist/commands/query.js +564 -0
- package/dist/commands/skill-specs.js +64 -0
- package/dist/commands/skill.js +863 -0
- package/dist/commands/spec-types.js +145 -0
- package/dist/commands/stats.js +299 -0
- package/dist/commands/store-flags.js +56 -0
- package/dist/commands/store.js +258 -0
- package/dist/commands/sync-run.js +479 -0
- package/dist/commands/sync.js +757 -0
- package/dist/commands/tree.js +27 -0
- package/dist/core/config.js +259 -0
- package/dist/core/credentials.js +71 -0
- package/dist/core/edition.js +18 -0
- package/dist/core/envelope.js +201 -0
- package/dist/core/errors.js +356 -0
- package/dist/core/http.js +348 -0
- package/dist/core/ratelimit.js +126 -0
- package/dist/core/registry/index.js +212 -0
- package/dist/core/registry/params/ai.knowledge.addKnowledge.json +88 -0
- package/dist/core/registry/params/ai.knowledge.deleteKnowledges.json +46 -0
- package/dist/core/registry/params/ai.knowledge.editChannelAnswer.json +60 -0
- package/dist/core/registry/params/ai.knowledge.editKnowledge.json +95 -0
- package/dist/core/registry/params/ai.knowledge.editKnowledgeNoSimilars.json +102 -0
- package/dist/core/registry/params/ai.knowledge.getCategoryTree.json +39 -0
- package/dist/core/registry/params/ai.knowledge.getDetail.json +46 -0
- package/dist/core/registry/params/ai.knowledge.search.json +67 -0
- package/dist/core/registry/params/ai.statistic.transferHuman.json +60 -0
- package/dist/core/registry/params/category.list.json +39 -0
- package/dist/core/registry/params/chat.queue.group.query.json +39 -0
- package/dist/core/registry/params/crm.modifyOrder.json +48 -0
- package/dist/core/registry/params/crm.modifyUser.json +48 -0
- package/dist/core/registry/params/crm.syncCrmInfo.json +46 -0
- package/dist/core/registry/params/crm.tagChange.json +74 -0
- package/dist/core/registry/params/data.overview.ipcc.json +32 -0
- package/dist/core/registry/params/data.overview.session.json +53 -0
- package/dist/core/registry/params/evaluation.setting.get.json +39 -0
- package/dist/core/registry/params/event.applyStaff.json +116 -0
- package/dist/core/registry/params/event.evaluate.json +74 -0
- package/dist/core/registry/params/event.inviteEvaluate.json +81 -0
- package/dist/core/registry/params/event.qcResult.json +166 -0
- package/dist/core/registry/params/event.queryQueueStatus.json +39 -0
- package/dist/core/registry/params/event.queueEnter.json +40 -0
- package/dist/core/registry/params/event.queueLeave.json +46 -0
- package/dist/core/registry/params/event.quitQueue.json +39 -0
- package/dist/core/registry/params/event.sessionChange.json +95 -0
- package/dist/core/registry/params/event.sessionData.json +452 -0
- package/dist/core/registry/params/event.sessionEnd.json +117 -0
- package/dist/core/registry/params/event.sessionStart.json +109 -0
- package/dist/core/registry/params/event.updateUInfo.json +46 -0
- package/dist/core/registry/params/export.session.check.json +7 -0
- package/dist/core/registry/params/export.session.json +7 -0
- package/dist/core/registry/params/export.session.one.json +7 -0
- package/dist/core/registry/params/export.session.one.message.json +7 -0
- package/dist/core/registry/params/get_call_order.json +50 -0
- package/dist/core/registry/params/get_call_user_info.json +36 -0
- package/dist/core/registry/params/get_order.json +50 -0
- package/dist/core/registry/params/get_token.json +22 -0
- package/dist/core/registry/params/get_user_info.json +36 -0
- package/dist/core/registry/params/icoutcall.callIntercept.list.json +32 -0
- package/dist/core/registry/params/icoutcall.dialogFlow.fuzzySearch.json +53 -0
- package/dist/core/registry/params/icoutcall.dialogFlow.getDialogFlowList.json +32 -0
- package/dist/core/registry/params/icoutcall.get.customer.json +39 -0
- package/dist/core/registry/params/icoutcall.get.jobdetail.json +39 -0
- package/dist/core/registry/params/icoutcall.get.jobproperties.json +39 -0
- package/dist/core/registry/params/icoutcall.history.seat.json +67 -0
- package/dist/core/registry/params/icoutcall.history.team.json +67 -0
- package/dist/core/registry/params/icoutcall.job.create.json +53 -0
- package/dist/core/registry/params/icoutcall.job.importcustomer.json +46 -0
- package/dist/core/registry/params/icoutcall.job.pause.json +39 -0
- package/dist/core/registry/params/icoutcall.job.readdcustomer.json +109 -0
- package/dist/core/registry/params/icoutcall.job.start.json +39 -0
- package/dist/core/registry/params/icoutcall.job.terminate.json +39 -0
- package/dist/core/registry/params/icoutcall.phone.getLineList.json +32 -0
- package/dist/core/registry/params/ipcc.calltask.add.auto.json +117 -0
- package/dist/core/registry/params/ipcc.calltask.add.byCustom.json +96 -0
- package/dist/core/registry/params/ipcc.calltask.add.byRelation.json +82 -0
- package/dist/core/registry/params/ipcc.calltask.add.toGroup.json +89 -0
- package/dist/core/registry/params/ipcc.calltask.add.toStaff.json +89 -0
- package/dist/core/registry/params/ipcc.calltask.get.json +47 -0
- package/dist/core/registry/params/ipcc.calltaskdetail.add.json +54 -0
- package/dist/core/registry/params/ipcc.calltaskdetail.delete.json +40 -0
- package/dist/core/registry/params/ipcc.calltaskdetail.get.json +54 -0
- package/dist/core/registry/params/ipcc.calltaskdetail.update.json +40 -0
- package/dist/core/registry/params/ipcc.customfield.template.get.json +47 -0
- package/dist/core/registry/params/ipcc.login.json +47 -0
- package/dist/core/registry/params/kefu.add.json +130 -0
- package/dist/core/registry/params/kefu.delete.json +39 -0
- package/dist/core/registry/params/kefu.update.json +137 -0
- package/dist/core/registry/params/kefu.v2.query.json +39 -0
- package/dist/core/registry/params/kefuGroup.add.json +39 -0
- package/dist/core/registry/params/kefuGroup.delete.json +39 -0
- package/dist/core/registry/params/kefuGroup.update.json +46 -0
- package/dist/core/registry/params/kefuGroup.updateKefus.json +46 -0
- package/dist/core/registry/params/merchant.account.login.json +53 -0
- package/dist/core/registry/params/merchant.changePassword.json +46 -0
- package/dist/core/registry/params/merchant.create.json +81 -0
- package/dist/core/registry/params/merchant.disable.json +39 -0
- package/dist/core/registry/params/merchant.enable.json +39 -0
- package/dist/core/registry/params/merchant.list.json +46 -0
- package/dist/core/registry/params/merchant.query.json +46 -0
- package/dist/core/registry/params/merchant.update.json +74 -0
- package/dist/core/registry/params/message.send.image.json +53 -0
- package/dist/core/registry/params/message.send.json +53 -0
- package/dist/core/registry/params/message.send.voice.json +53 -0
- package/dist/core/registry/params/message.sendFile.json +39 -0
- package/dist/core/registry/params/message.uploadFile.json +39 -0
- package/dist/core/registry/params/online.session.category.list.json +39 -0
- package/dist/core/registry/params/online.session.customfield.template.json +39 -0
- package/dist/core/registry/params/online.session.customfield.update.json +74 -0
- package/dist/core/registry/params/order.upload.json +40 -0
- package/dist/core/registry/params/push.msg.image.json +74 -0
- package/dist/core/registry/params/push.msg.richText.json +74 -0
- package/dist/core/registry/params/push.msg.text.json +74 -0
- package/dist/core/registry/params/receive.message.json +89 -0
- package/dist/core/registry/params/robot.data.getQuestionsByCategoryName.json +67 -0
- package/dist/core/registry/params/robot.data.knowledge.json +46 -0
- package/dist/core/registry/params/robot.data.kpoint.json +46 -0
- package/dist/core/registry/params/robot.data.queryStandardByEffectiveQuestion.json +46 -0
- package/dist/core/registry/params/robot.data.queryStandardQuestionList.json +46 -0
- package/dist/core/registry/params/robot.evaluation.comment.json +67 -0
- package/dist/core/registry/params/robot.evaluation.setting.json +46 -0
- package/dist/core/registry/params/robot.session.assist.json +74 -0
- package/dist/core/registry/params/robot.session.chat.json +74 -0
- package/dist/core/registry/params/robot.session.close.json +53 -0
- package/dist/core/registry/params/robot.session.commonQuestions.json +74 -0
- package/dist/core/registry/params/robot.session.create.json +81 -0
- package/dist/core/registry/params/robot.session.evaluation.json +67 -0
- package/dist/core/registry/params/robot.session.msgAssociate.json +46 -0
- package/dist/core/registry/params/robot.session.msgEvaluation.json +53 -0
- package/dist/core/registry/params/robot.session.msgPredict.json +74 -0
- package/dist/core/registry/params/robot.session.transfer.json +36 -0
- package/dist/core/registry/params/robot.session.uploadFile.json +32 -0
- package/dist/core/registry/params/robot.statistic.summary.json +53 -0
- package/dist/core/registry/params/robot.transfer.config.json +15 -0
- package/dist/core/registry/params/session.user.profile.json +39 -0
- package/dist/core/registry/params/settings.wxTemplates.json +46 -0
- package/dist/core/registry/params/smstask.create.json +53 -0
- package/dist/core/registry/params/smstask.status.json +39 -0
- package/dist/core/registry/params/staff.group.list.new.json +39 -0
- package/dist/core/registry/params/staff.group.members.new.json +46 -0
- package/dist/core/registry/params/staff.list.new.json +46 -0
- package/dist/core/registry/params/staff.login.json +47 -0
- package/dist/core/registry/params/statistic.overview.json +61 -0
- package/dist/core/registry/params/statistic.performance.json +82 -0
- package/dist/core/registry/params/statistic.salaryDetail.json +54 -0
- package/dist/core/registry/params/statistic.satisfaction.report.json +68 -0
- package/dist/core/registry/params/statistic.staffAttendance.json +75 -0
- package/dist/core/registry/params/statistic.staffquality.json +75 -0
- package/dist/core/registry/params/statistic.staffworklod.json +68 -0
- package/dist/core/registry/params/tag.all.json +32 -0
- package/dist/core/registry/params/tag.batchUpdate.json +32 -0
- package/dist/core/registry/params/tag.update.json +60 -0
- package/dist/core/registry/params/ticket.apply.json +46 -0
- package/dist/core/registry/params/ticket.batch.modify.json +53 -0
- package/dist/core/registry/params/ticket.create.json +151 -0
- package/dist/core/registry/params/ticket.filter.count.json +46 -0
- package/dist/core/registry/params/ticket.filter.list.json +46 -0
- package/dist/core/registry/params/ticket.finish.json +60 -0
- package/dist/core/registry/params/ticket.followers.update.json +60 -0
- package/dist/core/registry/params/ticket.list.json +74 -0
- package/dist/core/registry/params/ticket.log.json +39 -0
- package/dist/core/registry/params/ticket.modify.json +74 -0
- package/dist/core/registry/params/ticket.new.detail.json +39 -0
- package/dist/core/registry/params/ticket.reminder.json +60 -0
- package/dist/core/registry/params/ticket.reopen.json +67 -0
- package/dist/core/registry/params/ticket.reply.json +60 -0
- package/dist/core/registry/params/ticket.search.json +116 -0
- package/dist/core/registry/params/ticket.template.fields.json +39 -0
- package/dist/core/registry/params/ticket.template.list.json +39 -0
- package/dist/core/registry/params/ticket.transfer.json +74 -0
- package/dist/core/registry/params/track.event.set.json +32 -0
- package/dist/core/registry/params/wecom.robot.switch.json +43 -0
- package/dist/core/registry/params.js +84 -0
- package/dist/core/registry/specs.json +2172 -0
- package/dist/core/registry/validate.json +11 -0
- package/dist/core/registry/validation-overrides.js +98 -0
- package/dist/core/sanitize.js +24 -0
- package/dist/core/sign.js +21 -0
- package/dist/core/time.js +194 -0
- package/dist/core/validate.js +140 -0
- package/dist/output.js +263 -0
- package/dist/postinstall.js +178 -0
- package/dist/query/errors.js +395 -0
- package/dist/query/mask.js +368 -0
- package/dist/query/metric-catalog.js +85 -0
- package/dist/query/sandbox.js +544 -0
- package/dist/query/table-query.js +297 -0
- package/dist/query/time-shape.js +44 -0
- package/dist/schedule/install.js +377 -0
- package/dist/skill/check.js +429 -0
- package/dist/skill/detect.js +336 -0
- package/dist/skill/install.js +1202 -0
- package/dist/skill/paths.js +343 -0
- package/dist/skill/qiyu/SKILL.md +86 -0
- package/dist/skill/qiyu/errors.md +55 -0
- package/dist/skill/qiyu/forbidden.md +52 -0
- package/dist/skill/qiyu/metrics.md +65 -0
- package/dist/skill/qiyu/protocols.md +55 -0
- package/dist/skill/qiyu/setup.md +50 -0
- package/dist/skill/refs.js +379 -0
- package/dist/store/config.js +137 -0
- package/dist/store/duckdb.js +321 -0
- package/dist/store/index.js +18 -0
- package/dist/store/retry.js +36 -0
- package/dist/store/schema.js +419 -0
- package/dist/store/types.js +4 -0
- package/dist/sync/day.js +8 -0
- package/dist/sync/engine.js +818 -0
- package/dist/sync/rate-gate.js +95 -0
- package/dist/sync/registry.js +22 -0
- package/dist/sync/state.js +114 -0
- package/dist/sync/tasks/dim.js +186 -0
- package/dist/sync/tasks/knowledge.js +252 -0
- package/dist/sync/tasks/pace.js +66 -0
- package/dist/sync/tasks/pipeline.js +321 -0
- package/dist/sync/tasks/reports.js +448 -0
- package/dist/sync/tasks/sessions.js +188 -0
- package/dist/sync/tasks/tickets.js +219 -0
- package/dist/sync/types.js +1 -0
- package/dist/sync/windowing.js +56 -0
- package/package.json +52 -4
package/dist/cli.js
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { pathToFileURL } from 'node:url';
|
|
3
|
+
import { realpathSync } from 'node:fs';
|
|
4
|
+
import { authCommand } from './commands/auth.js';
|
|
5
|
+
import { fail, usageFail, describeArgs, setSkillWarning, setPretty, ok } from './output.js';
|
|
6
|
+
import { PACKAGE_VERSION, SKILL_CONTRACT_VERSION } from './core/edition.js';
|
|
7
|
+
import { detectSkillState, entityUndeterminedNote, npmRelativeBase, resolveEntityDirSources, resolveSkillSourceDir, skillWarning, } from './skill/detect.js';
|
|
8
|
+
import { apiCommand } from './commands/api.js';
|
|
9
|
+
import { prettyAfterSubcommand } from './commands/spec-types.js';
|
|
10
|
+
import { wireLocalFallback } from './commands/local-fallback-wiring.js';
|
|
11
|
+
import { storeCommand } from './commands/store.js';
|
|
12
|
+
import { syncCommand } from './commands/sync.js';
|
|
13
|
+
import { dbCommand } from './commands/db.js';
|
|
14
|
+
import { queryCommand } from './commands/query.js';
|
|
15
|
+
import { statsCommand } from './commands/stats.js';
|
|
16
|
+
import { skillCommand } from './commands/skill.js';
|
|
17
|
+
// `COMMAND_TREE` 的**权威位置**是 `commands/tree.ts`(worktree 裁定,见那里顶部注释):
|
|
18
|
+
// 它只 import 各命令模块、不含入口逻辑,将来 `src/skill/check.ts` 从**那里**消费。
|
|
19
|
+
// 本文件 re-export 只是兼容入口(计划原文写的是 `cli.ts` 汇总),免得调用方改路径。
|
|
20
|
+
export { COMMAND_TREE } from './commands/tree.js';
|
|
21
|
+
// —— 限流 fallback 接线(G1 契约小件)——
|
|
22
|
+
// `api call` 的限流错误要附「改用本地查询」建议(retry_strategy/fallback),
|
|
23
|
+
// 而该建议需要 sync 任务注册表与本地库探测;`commands/api.ts` 按分层红线
|
|
24
|
+
// 不得 import 它们(auth/api 零 store 加载),所以由入口层把默认提供者装进
|
|
25
|
+
// `local-fallback.ts` 的注入槽。模块级执行一次即可(进程生命周期)。
|
|
26
|
+
wireLocalFallback();
|
|
27
|
+
const COMMANDS = {
|
|
28
|
+
auth: authCommand,
|
|
29
|
+
api: apiCommand,
|
|
30
|
+
store: storeCommand,
|
|
31
|
+
sync: syncCommand,
|
|
32
|
+
db: dbCommand,
|
|
33
|
+
query: queryCommand,
|
|
34
|
+
stats: statsCommand,
|
|
35
|
+
// skill 是 F 子项目对用户的正式门面(install/check/where 三子命令)。
|
|
36
|
+
// `commands/skill.ts` 是全仓唯一允许 import `skill/` 的 commands 文件(分层豁免)。
|
|
37
|
+
skill: skillCommand,
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* 顶层用法说明。**走 stdout、退出码 0** —— 这不是错误,是请求帮助。
|
|
41
|
+
* ⚠️ 全局约束承诺了「CLI 的 `--help` 一律中文」,所以这里必须实现它,
|
|
42
|
+
* 不能让它落到「未知子命令」分支(实测那会输出「未知子命令:--help」,退出码 2)。
|
|
43
|
+
*/
|
|
44
|
+
const USAGE = `用法:qiyu <子命令> [参数]
|
|
45
|
+
|
|
46
|
+
全局选项:
|
|
47
|
+
--help, -h 输出本帮助(唯一以裸文本而非 JSON 输出的情形)
|
|
48
|
+
--version 输出版本 JSON:包版本与 skill 正文契约版本
|
|
49
|
+
(Agent 用它判断已安装的 skill 与 CLI 是否配套)
|
|
50
|
+
--pretty 输出缩进 JSON(人类可读;写在具体子命令之后,
|
|
51
|
+
如 qiyu api list --pretty。默认紧凑输出已是合法 JSON,
|
|
52
|
+
Agent 解析不需要它)
|
|
53
|
+
|
|
54
|
+
子命令:
|
|
55
|
+
auth whoami 检查凭证是否已配置
|
|
56
|
+
api list [--all] 列出接口(默认只列可主动调用的出站接口)
|
|
57
|
+
api call <id> [--body <JSON>] [--yes] [--no-validate] [--strict]
|
|
58
|
+
调用接口;危险接口必须加 --yes
|
|
59
|
+
api schema <id> 查看接口的请求参数表与响应形状
|
|
60
|
+
store init [--db <path>] [--profile <name>] [--backend <name>]
|
|
61
|
+
初始化本地数据库(DuckDB)
|
|
62
|
+
store status [--db <path>] [--profile <name>] [--backend <name>]
|
|
63
|
+
查看数据库状态与各表行数
|
|
64
|
+
sync tasks 列出全部同步任务与不支持的实时快照数据集
|
|
65
|
+
sync run [任务...] 同步数据进本地库(--full / --since / --until / --quiet)
|
|
66
|
+
sync status [任务...] 水位、区间状态、缺口与锁(只读;缺省全部任务)
|
|
67
|
+
sync verify [任务...] 核对本地与远端一致性(快照三方核对;drift 非空退出码 1)
|
|
68
|
+
sync install --schedule CRON [--yes]
|
|
69
|
+
安装系统定时调度(macOS=launchd / linux=systemd user /
|
|
70
|
+
win32=schtasks。默认 dry-run;--yes 才写入)
|
|
71
|
+
sync uninstall [--yes] 移除系统调度条目(默认 dry-run,--yes 才删除)
|
|
72
|
+
db tables 列出库中全部表:行数、粒度、时间范围、PII 列
|
|
73
|
+
db describe <表> 查看单表列定义(列名、类型、可空、敏感标记、时间列)
|
|
74
|
+
query --sql <SQL> 任意只读 SQL(三层只读沙箱 + 默认脱敏 + 行数上限 + 超时)
|
|
75
|
+
query --table <表> [--since <时间>] [--until <时间>] [--group-by <列>]
|
|
76
|
+
受约束查询通道(列白名单、时间列语义化、精确脱敏)
|
|
77
|
+
stats fields <报表表> 指标声明(带出处)+ 本地观测分布 + -1 哨兵
|
|
78
|
+
skill install [--dir <path>] [--link <agent>]... [--no-link] [--force] [--dry-run]
|
|
79
|
+
安装 skill 正文并链接到已存在的 agent 目录
|
|
80
|
+
skill check [--installed [--dir <path>] | --compare [--dir <path>]]
|
|
81
|
+
校验 skill 正文引用与 CLI 契约(有违规退出码 1;
|
|
82
|
+
--compare 下内容不一致也算失败)
|
|
83
|
+
skill where [--dir <path>] 报告实体目录与各 agent 链接状态(只读,不修复)
|
|
84
|
+
|
|
85
|
+
查询族参数:
|
|
86
|
+
query --limit <n> / --timeout <秒> / --no-mask
|
|
87
|
+
行数上限 / 超时 / 关闭默认脱敏(细节见 qiyu query --help)
|
|
88
|
+
--db <path> / --profile <name> / --backend <name>
|
|
89
|
+
db / query / stats 共用的存储定位(与 store / sync 同族)
|
|
90
|
+
|
|
91
|
+
出错时 stdout 是 {"ok":false,"error":{code,kind,retryable,message,hint?}}。
|
|
92
|
+
⚠️ 请按 kind 分支,不要按 code —— code 只是个标签:它可能是服务端的
|
|
93
|
+
数字码(如 14009),也可能是本 CLI 合成的词(usage / network / internal /
|
|
94
|
+
auth_missing / config_insecure / confirm_required / store_locked / store_not_initialized /
|
|
95
|
+
local_rate_limit / query_error / sandbox_blocked / query_timeout / unknown)。
|
|
96
|
+
合成词查不到官方错误码表。
|
|
97
|
+
|
|
98
|
+
退出码:0 成功 · 1 业务错误 · 2 用法错误 · 3 网络错误 · 4 需要 --yes
|
|
99
|
+
`;
|
|
100
|
+
export async function run(argv) {
|
|
101
|
+
setPretty(false); // G1:每条命令入口重置输出格式 —— 同一进程内多次 run(测试)不残留上一条命令的开关。
|
|
102
|
+
// —— skill 安装态探测(Task 10,设计稿 D2.1):只提示,绝不改退出码、data、文件 ——
|
|
103
|
+
// 每个命令启动时探测一次:装了但过期 / 未装时往 meta.warnings 注入一句提示;
|
|
104
|
+
// 探测失败(unknown)静默跳过,不影响命令本身。cli.ts 是唯一允许同时 import
|
|
105
|
+
// output.js 与 skill/ 的入口层,探测经 setSkillWarning 注入而不是让 output.ts
|
|
106
|
+
// 反向 import skill/(分层红线,Task 14 钉住)。
|
|
107
|
+
// 实体目录解析走全仓唯一实现(`skill/detect.ts` 的 `resolveEntityDirSources`):
|
|
108
|
+
// 显式通道(--dir / QIYU_SKILL_DIR)照常;Node 测试进程里宿主 npm_config 与真实 home
|
|
109
|
+
// 都不读(测试绝不读写真实 `~`,宿主 `.npmrc` 的 npm_config_* 也不得泄进测试)。
|
|
110
|
+
// 每次 run() 都显式 setSkillWarning(...)(探测不了就是 undefined)——同一进程内
|
|
111
|
+
// 多次 run 不残留上一条的提示。
|
|
112
|
+
//
|
|
113
|
+
// ⚠️ 门因**显式开关**(QIYU_DISABLE_SKILL_PROBE)关掉时不能静默(G3 追加审查 [57]):
|
|
114
|
+
// 用户主动关了探测,就得看得见「为什么没有提示」。而 Node 测试进程这一路**不写**
|
|
115
|
+
// meta.warnings——那会让每条测试命令都多一条无关警告(审查 [21] 实测的正是这种污染)。
|
|
116
|
+
// 测试路径的解释由 `qiyu skill where` 给出(排查命令看得见即可)。
|
|
117
|
+
const entityResolution = resolveEntityDirSources({
|
|
118
|
+
env: process.env,
|
|
119
|
+
baseDir: npmRelativeBase(process.env, () => process.cwd()),
|
|
120
|
+
});
|
|
121
|
+
const skillEntityDir = entityResolution.decided ? entityResolution.dir : undefined;
|
|
122
|
+
const skillSourceDir = resolveSkillSourceDir();
|
|
123
|
+
const suppressedNote = !entityResolution.decided && entityResolution.reason === 'env'
|
|
124
|
+
? entityUndeterminedNote(entityResolution)
|
|
125
|
+
: undefined;
|
|
126
|
+
setSkillWarning(skillEntityDir !== undefined && skillSourceDir !== undefined
|
|
127
|
+
? skillWarning(detectSkillState(skillEntityDir, skillSourceDir, PACKAGE_VERSION), { entityDir: skillEntityDir, currentVersion: PACKAGE_VERSION })
|
|
128
|
+
: suppressedNote);
|
|
129
|
+
const [sub, ...rest] = argv;
|
|
130
|
+
if (sub === '--help' || sub === '-h') {
|
|
131
|
+
// ⚠️ `--help` 不吞额外参数(2026-10-08 修)—— 与叶子命令同一条次序
|
|
132
|
+
// (未知/位置参数 → help)。此前它是"首个 token 特判且排在最前",实测
|
|
133
|
+
// `qiyu --help --bod` / `qiyu --help extra` 都返回 0、把拼错的 flag / 多余的位置
|
|
134
|
+
// 参数**静默吞掉**(而 `qiyu --bod` 单独跑是 2)—— "多带一个 --help"把一条用法
|
|
135
|
+
// 错误变成了静默成功,与 `api list --al --help` 是同一个坑,分派层这一处漏了。
|
|
136
|
+
// `--help --help` 仍给帮助:`--help`/`-h` 是这条伪命令仅有的合法 token
|
|
137
|
+
// (与 `api list --help --help` 同答 —— 都不算"额外参数")。
|
|
138
|
+
// ⚠️ `--pretty` 同样豁免(2026-10-08;G1 起已实现为缩进开关):它是**合法 flag**,
|
|
139
|
+
// 不是"额外参数"—— `qiyu --help --pretty` 给帮助(与 `api list --help --pretty` 同答)。
|
|
140
|
+
const extra = rest.filter((a) => a !== '--help' && a !== '-h' && a !== '--pretty');
|
|
141
|
+
if (extra.length > 0) {
|
|
142
|
+
return usageFail(`未知参数:${describeArgs(extra)}。--help 不接受额外参数`);
|
|
143
|
+
}
|
|
144
|
+
process.stdout.write(USAGE);
|
|
145
|
+
return 0;
|
|
146
|
+
}
|
|
147
|
+
// ⚠️ `--version`(Task 12,spec D6):输出**机器可读**的包版本与 skill 正文
|
|
148
|
+
// 契约版本。为什么需要它:skill 正文是单独安装的副本,可能与本 CLI 不配套;
|
|
149
|
+
// Agent 靠 `skill_contract_version` 判断手上的正文能不能配这份 CLI
|
|
150
|
+
// (键名逐字为 `version` 与 `skill_contract_version`,是 Agent 契约的一部分)。
|
|
151
|
+
// 额外参数纪律与 `--help` **完全一致**(同一份豁免清单:`--help`/`-h`/`--pretty`
|
|
152
|
+
// 是合法 token,其余含位置参数一律 2)—— 分派层每条伪命令守同一条规则,
|
|
153
|
+
// 免得再出现「多带一个 flag 把用法错误静默吞成 0」的旧坑。
|
|
154
|
+
// ⚠️ `--version --help` 给**版本 JSON** 而不是 USAGE:全局约束只给裸文本
|
|
155
|
+
// `--help` 开了一个口子,不能开第二个。
|
|
156
|
+
// 输出走 `ok()`(而非自己写 stdout):skill 安装态提示要能经 `meta.warnings`
|
|
157
|
+
// 合并进来,且成功信封的形态由 output.ts 一处统一。
|
|
158
|
+
if (sub === '--version') {
|
|
159
|
+
const extra = rest.filter((a) => a !== '--help' && a !== '-h' && a !== '--pretty');
|
|
160
|
+
if (extra.length > 0) {
|
|
161
|
+
return usageFail(`未知参数:${describeArgs(extra)}。--version 不接受额外参数`);
|
|
162
|
+
}
|
|
163
|
+
// G1:--version --pretty → 缩进的版本 JSON(帮助/版本检查是例外:--pretty 有可修饰的对象)
|
|
164
|
+
if (rest.includes('--pretty'))
|
|
165
|
+
setPretty(true);
|
|
166
|
+
return ok({ version: PACKAGE_VERSION, skill_contract_version: SKILL_CONTRACT_VERSION });
|
|
167
|
+
}
|
|
168
|
+
// ⚠️ 分派层的 `--pretty` 必须与叶子层同答(2026-10-08 统一)。此前它落到
|
|
169
|
+
// 「未知子命令:--pretty」—— 而 `--pretty` 是真实存在的输出开关(G1 已实现)
|
|
170
|
+
// (与 ㉖ 在叶子层修的是同一句话),把合法 flag 说成"未知子命令"是同一类事实错误;
|
|
171
|
+
// 且 `qiyu --pretty --help` 此前被静默吞成 2(而 `qiyu api list --pretty --help` 是 0)。
|
|
172
|
+
// 次序:**未知/位置 → help → version → `--pretty`**(叶子命令没有 --version,
|
|
173
|
+
// 前两步与叶子层逐字一致;version 只在分派层存在)。
|
|
174
|
+
// G1:--pretty 已实现,但它必须写在具体子命令之后(`qiyu api list --pretty`)。
|
|
175
|
+
// 写在顶层时没有任何可修饰的输出(帮助是裸文本、version 是另一条伪命令)。
|
|
176
|
+
if (sub === '--pretty') {
|
|
177
|
+
const unknown = rest.filter((a) => a.startsWith('-') && a !== '--pretty' && a !== '--help' && a !== '-h');
|
|
178
|
+
const positional = rest.filter((a) => !a.startsWith('-'));
|
|
179
|
+
const extra = [...unknown, ...positional];
|
|
180
|
+
if (extra.length > 0) {
|
|
181
|
+
// `qiyu --pretty api list` 落在这里 —— 提示正确写法比只报"未知参数"有用
|
|
182
|
+
return usageFail(`未知参数:${describeArgs(extra)}。--pretty 必须写在具体子命令之后`);
|
|
183
|
+
}
|
|
184
|
+
if (rest.includes('--help') || rest.includes('-h')) {
|
|
185
|
+
process.stdout.write(USAGE);
|
|
186
|
+
return 0;
|
|
187
|
+
}
|
|
188
|
+
return usageFail(prettyAfterSubcommand('<子命令>'));
|
|
189
|
+
}
|
|
190
|
+
if (!sub) {
|
|
191
|
+
return usageFail(`用法:qiyu <子命令> [参数](\`qiyu --help\` 查看全部)`);
|
|
192
|
+
}
|
|
193
|
+
// ⚠️ 判据必须是 `Object.hasOwn` 而**不是** `if (!handler)`。
|
|
194
|
+
// `COMMANDS` 是普通对象字面量,`COMMANDS['toString']` 会命中
|
|
195
|
+
// `Object.prototype.toString`(**truthy**)—— 于是 `if (!handler)` 不成立,
|
|
196
|
+
// 原型方法被当成子命令处理器调用。实测(Node 24):
|
|
197
|
+
// toString / constructor → 返回非数字(string / []),
|
|
198
|
+
// 随后 `process.exitCode = <非数字>` 抛 ERR_INVALID_ARG_TYPE
|
|
199
|
+
// valueOf / hasOwnProperty / __proto__ → 直接抛 TypeError
|
|
200
|
+
// 配合入口缺 `.catch()`(见下方),这些 rejection 会变成 unhandled rejection:
|
|
201
|
+
// Node 打印一段原生堆栈、退出码 1 —— 既不是「未知子命令」的退出码 2,
|
|
202
|
+
// 也不符合「stdout 必须是合法 JSON」的契约(错误要在 stdout 出 JSON,stderr 只是镜像)。
|
|
203
|
+
//
|
|
204
|
+
// 这不是假想的:仓库已在 `core/ratelimit.ts` 修过**同一类问题**
|
|
205
|
+
// (`Object.hasOwn(RATE_LIMITS, endpointId)`,并有测试钉 `limitFor('constructor')`)。
|
|
206
|
+
// 同类缺陷只修了一处 —— 分发表漏了。
|
|
207
|
+
if (!Object.hasOwn(COMMANDS, sub)) {
|
|
208
|
+
// ⚠️ 用 describeArgs 渲染 sub(2026-10-08 修):`qiyu " "` 此前报
|
|
209
|
+
// 「未知子命令: ;可用子命令:…」—— 名字是纯空白、不可见,
|
|
210
|
+
// 与空串参数是同一个病(说明必须指名它抱怨的东西)。
|
|
211
|
+
return usageFail(`未知子命令:${describeArgs([sub])}\n可用子命令:${Object.keys(COMMANDS).join('、') || '(暂无)'}`);
|
|
212
|
+
}
|
|
213
|
+
return COMMANDS[sub](rest);
|
|
214
|
+
}
|
|
215
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(realpathSync(process.argv[1])).href) {
|
|
216
|
+
// ⚠️ 用 `process.exitCode = code`,**不要**用 `process.exit` —— 后者会在
|
|
217
|
+
// stdout 尚未排空时强杀进程,把大输出**静默截断**。实测(Node 24):`api call`
|
|
218
|
+
// 管道输出 392846 字节时只写出 131072 字节(正好是 128 KiB 管道缓冲区),
|
|
219
|
+
// 退出码仍是 0、没有任何报错。而 `qiyu api call ticket.search | jq` 正是 Agent
|
|
220
|
+
// 的标准用法,也是**唯一**值得管道的场景(大结果集)—— 它拿到的 JSON 会在中间
|
|
221
|
+
// 断掉,jq 报一个与真实原因(输出太大)毫无关系的解析错误。
|
|
222
|
+
// 设 `exitCode` 后让事件循环自然结束,Node 会先把 stdout 排空再退出。
|
|
223
|
+
// (`AbortSignal.timeout` 用的是 unref 定时器,不会拖住进程 —— 已验证。)
|
|
224
|
+
// ⚠️ **必须挂 `.catch()`** —— `run()` 的类型签名是 `Promise<number>`,**不保证不抛**。
|
|
225
|
+
// 任一子命令抛出未捕获异常时 `.then` 的成功分支不执行,而没有 `.catch()` 时
|
|
226
|
+
// rejection 变成 unhandled rejection:Node 打印一段原生堆栈(含文件路径与
|
|
227
|
+
// `file://` URL)到 stderr、**stdout 0 字节**、退出码 1。此时 stdout 既不是合法
|
|
228
|
+
// JSON、也没有任何内容 —— 全局约束「其余任何情况下 stdout 都必须是合法 JSON」
|
|
229
|
+
// 在这条路径上完全落空。
|
|
230
|
+
//
|
|
231
|
+
// 为什么各子命令自己的 try/catch 不够:那是**逐命令**的。入口要对
|
|
232
|
+
// 「将来某个任务新增的子命令忘了 catch」与「原型键命中了不存在的处理器」
|
|
233
|
+
// (见上方 `Object.hasOwn` 的说明)这两种情形零防护兜底。
|
|
234
|
+
// → 未捕获异常映射到 `EXIT.BUSINESS`(1),与 `exitCodeFor` 的 default 一致。
|
|
235
|
+
run(process.argv.slice(2))
|
|
236
|
+
.then((code) => { process.exitCode = code; })
|
|
237
|
+
.catch((e) => {
|
|
238
|
+
// ⚠️ catch 里必须走 `fail()`,stdout 才有合法 JSON —— 只写 stderr 的话
|
|
239
|
+
// `qiyu … | jq` 在这条路径上仍然 parse error,而 jq 报的是解析错误,
|
|
240
|
+
// Agent 看不到真正的原因。全局约束要求「其余任何情况下 stdout 都必须是
|
|
241
|
+
// 合法 JSON」,catch 是其中一条路径,不豁免。
|
|
242
|
+
process.exitCode = fail({
|
|
243
|
+
code: 'internal', kind: 'internal', retryable: false,
|
|
244
|
+
message: e instanceof Error ? e.message : String(e),
|
|
245
|
+
hint: 'CLI 内部错误,这应当报告为缺陷 —— 请附上复现命令。',
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
}
|