qiyu-cli 0.0.0-stage → 0.2.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.
- package/LICENSE +21 -0
- package/README.md +467 -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 +908 -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 +28 -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 +371 -0
- package/dist/skill/install.js +1202 -0
- package/dist/skill/paths.js +343 -0
- package/dist/skill/qiyu/SKILL.md +92 -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
|
@@ -0,0 +1,479 @@
|
|
|
1
|
+
// src/commands/sync-run.ts —— D-T13:sync run 的编排层。
|
|
2
|
+
// 职责(spec §三/§七 + 多任务审查的派发义务):
|
|
3
|
+
// ① fetchZip 生产接线:sessions 任务的下载通道在本层注入 —— 全局 fetch 拉 ZIP 二进制
|
|
4
|
+
// (下载链接是带签名的临时 URL,服务端已授权,不附加 query;凭证缺失在编排入口
|
|
5
|
+
// 已显式失败,管线不会进入)。
|
|
6
|
+
// ② 任务排序:显式拓扑序 + 分组交错 —— 按 orderTasks 的 rank 分层执行(层间升序、
|
|
7
|
+
// 层内 rotated 批(runRotated)先行 + plain 逐个):dim(0) → reports/tickets/
|
|
8
|
+
// sessions(1) → knowledge(items/points(2) 先于 categories(3),驱动序来自 items
|
|
9
|
+
// 落库;显式排序不靠报错兜底)。dim 先于报表是硬约束:staff_salary_detail 按
|
|
10
|
+
// staff 表逐客服驱动,缺 dim 首跑必败。
|
|
11
|
+
// ③ robotId 注入:StoreConfig.options.knowledgeRobotIds(number[])在配置层透传、
|
|
12
|
+
// 本层传给 categories 任务消费(发现盲区的手工兜底路径)。
|
|
13
|
+
// ④ --pretty(G1 已实现):输出缩进开关,写在子命令之后;解析循环收下它
|
|
14
|
+
// (见 RUN_BOOL_FLAGS 分支的 `|| a === '--pretty'`),开启动作在命令层。
|
|
15
|
+
// ⑤ 退出码:任一任务 complete/partial(部分成功)→ 0;全部 failed → 1;用法 → 2。
|
|
16
|
+
// ⑥ 中断裁决:不装 signal handler —— 事务边界是安全点,进程被 kill 时 DuckDB 回滚、
|
|
17
|
+
// 水位不推,下次 run 从水位续跑(红线 3 钉死用例覆盖)。
|
|
18
|
+
import { openStore } from '../store/index.js';
|
|
19
|
+
import { resolveStoreConfig, currentStoreEnv } from '../store/config.js';
|
|
20
|
+
import { fileProfile } from '../core/config.js';
|
|
21
|
+
import { resolveCredentialsUsingFile, currentCredentialEnv } from './credentials-source.js';
|
|
22
|
+
import { RateGate } from '../sync/rate-gate.js';
|
|
23
|
+
import { runTask, runRotated } from '../sync/engine.js';
|
|
24
|
+
import { SYNC_TASKS, taskById } from '../sync/registry.js';
|
|
25
|
+
import { readWatermark } from '../sync/state.js';
|
|
26
|
+
// callPaced 静态导入(范围外发现③):wireCategories 的注入路径也必须过任务层的限频闸门 ——
|
|
27
|
+
// 该接口(ai.knowledge.getCategoryTree)限频 1 次/秒,裸 call 不落冷却行。
|
|
28
|
+
import { callPaced } from '../sync/tasks/pace.js';
|
|
29
|
+
import { DAY_MS, parseTimeArg, msToShanghaiIso, shanghaiIso } from '../core/time.js';
|
|
30
|
+
import { ok, fail, usageFail, describeArgs, setPretty } from '../output.js';
|
|
31
|
+
import { thrownToExit } from './store.js';
|
|
32
|
+
import { GLOBAL_FLAGS, STORE_FLAGS, renderFlagNames, valueFlagNames } from './spec-types.js';
|
|
33
|
+
/**
|
|
34
|
+
* `sync run` 的业务 flag。事实源是这份常量:解析器的值位判定与「可用:…」错误文案
|
|
35
|
+
* 都从它派生,`sync.ts` 的 `SYNC_SPECS` 也引用它(不另写一份)。
|
|
36
|
+
*
|
|
37
|
+
* ⚠️ `--since/--until` 是值位;`--full/--quiet` 是布尔。`--db/--profile/--backend`
|
|
38
|
+
* 走 `STORE_FLAGS`(与 `parseStoreFlags` 同一份)——`sync run` 自己解析这三个 flag
|
|
39
|
+
* (不走 `parseStoreFlags`:它要连同 `--since/--until` 一起按值位处理)。
|
|
40
|
+
*
|
|
41
|
+
* ⚠️ **数组顺序就是「可用:…」文案的顺序**(历史文案是 `--full --since --until --quiet
|
|
42
|
+
* --db --profile --backend`,逐字被既有输出依赖):不要按「先布尔后值位」重排。
|
|
43
|
+
*/
|
|
44
|
+
export const RUN_FLAGS = [
|
|
45
|
+
{ name: '--full', kind: 'bool' },
|
|
46
|
+
{ name: '--since', kind: 'value' },
|
|
47
|
+
{ name: '--until', kind: 'value' },
|
|
48
|
+
{ name: '--quiet', kind: 'bool' },
|
|
49
|
+
...STORE_FLAGS,
|
|
50
|
+
];
|
|
51
|
+
/** 值位 flag 名(`--since/--until/--db/--profile/--backend`)。 */
|
|
52
|
+
const RUN_VALUE_FLAGS = valueFlagNames(RUN_FLAGS);
|
|
53
|
+
/** 布尔 flag 名(`--full/--quiet`)。 */
|
|
54
|
+
const RUN_BOOL_FLAGS = RUN_FLAGS.filter((f) => f.kind === 'bool').map((f) => f.name);
|
|
55
|
+
/**
|
|
56
|
+
* 「可用:……」清单。⚠️ **分隔符是空格**(不是「、」)——这行文案逐字被既有输出依赖,
|
|
57
|
+
* 不得改分隔符。
|
|
58
|
+
*/
|
|
59
|
+
const RUN_AVAILABLE = renderFlagNames(RUN_FLAGS, { separator: ' ' });
|
|
60
|
+
// E 起时间助手下沉 core/time(query/ 不得 import sync/,两域同源);本层保留
|
|
61
|
+
// re-export —— 既有导入点(commands/sync.ts 等)与测试不破。
|
|
62
|
+
export { parseTimeArg, msToShanghaiIso };
|
|
63
|
+
/** 引擎产出的毫秒区间 → 上海 ISO 区间数组。 */
|
|
64
|
+
function rangeOut(r) {
|
|
65
|
+
return [shanghaiIso(r.start), shanghaiIso(r.end)];
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* 任务分层 rank(orderTasks 与执行分层共用的唯一来源,审查裁定:不靠报错兜底)。
|
|
69
|
+
* 键序:dim(0) → windowed 报表/工单/会话(1) → knowledge.items/points(2) →
|
|
70
|
+
* knowledge.categories(3,驱动序来自 items 落库)。
|
|
71
|
+
*/
|
|
72
|
+
function taskRank(t) {
|
|
73
|
+
if (t.id.startsWith('dim.'))
|
|
74
|
+
return 0;
|
|
75
|
+
if (t.id === 'knowledge.categories')
|
|
76
|
+
return 3;
|
|
77
|
+
if (t.id.startsWith('knowledge.'))
|
|
78
|
+
return 2;
|
|
79
|
+
return 1;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* 显式任务排序:按 taskRank 分层(键序见上)。
|
|
83
|
+
* 调用方传入的任务 id 顺序仅决定同层内次序(sort 稳定);缺省(全量跑)按注册表声明序。
|
|
84
|
+
*/
|
|
85
|
+
export function orderTasks(tasks) {
|
|
86
|
+
return [...tasks].sort((a, b) => taskRank(a) - taskRank(b));
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* fetchZip 生产接线(T10 报告的接线义务):全局 fetch 拉 ZIP 二进制字节。
|
|
90
|
+
* 修复批 4 #9:**必须有超时** —— 签名 URL 挂起时 `sync run` 会永久挂住、写锁不释放
|
|
91
|
+
*(abort 后引擎记 fetch_failed gap、水位冻结,锁由 finally 清掉)。
|
|
92
|
+
* `AbortSignal.timeout` 是 Node ≥17.3 的内置能力(engines 已声明 ≥20.12)。
|
|
93
|
+
*/
|
|
94
|
+
const DOWNLOAD_TIMEOUT_MS = 120_000;
|
|
95
|
+
async function downloadZip(url) {
|
|
96
|
+
let res;
|
|
97
|
+
try {
|
|
98
|
+
res = await fetch(url, { signal: AbortSignal.timeout(DOWNLOAD_TIMEOUT_MS) });
|
|
99
|
+
}
|
|
100
|
+
catch (e) {
|
|
101
|
+
// AbortError/TimeoutError → 中文可读消息(由引擎的 failDetail 包装后进 gap detail)
|
|
102
|
+
if (e.name === 'TimeoutError' || e.name === 'AbortError') {
|
|
103
|
+
throw new Error(`导出包下载超时(${DOWNLOAD_TIMEOUT_MS / 1000} 秒未完成):` +
|
|
104
|
+
'下载链接可能已失效或网络不可达,重跑本任务即可(导出结果在服务端可复用)');
|
|
105
|
+
}
|
|
106
|
+
throw e;
|
|
107
|
+
}
|
|
108
|
+
if (!res.ok) {
|
|
109
|
+
throw new Error(`导出包下载失败:HTTP ${res.status}(链接可能已失效——重新同步即可)`);
|
|
110
|
+
}
|
|
111
|
+
const buf = await res.arrayBuffer();
|
|
112
|
+
return new Uint8Array(buf);
|
|
113
|
+
}
|
|
114
|
+
/** 给 sessions 任务包装 fetch:把 fetchZip/pollIntervalMs/maxPolls 注进 FetchCtx(T10 的注入面)。 */
|
|
115
|
+
function wireSessions(task, opts) {
|
|
116
|
+
if (task.id !== 'sessions.export')
|
|
117
|
+
return task;
|
|
118
|
+
const orig = task.fetch;
|
|
119
|
+
return {
|
|
120
|
+
...task,
|
|
121
|
+
fetch: async (w, c) => orig(w, {
|
|
122
|
+
...c,
|
|
123
|
+
fetchZip: downloadZip,
|
|
124
|
+
...(opts.maxPolls !== undefined ? { maxPolls: opts.maxPolls } : {}),
|
|
125
|
+
}),
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* 给 knowledge.categories 包装 fetch:注入手工 robotId(StoreConfig.options.
|
|
130
|
+
* knowledgeRobotIds)——发现盲区的兜底(知识库为空的机器人不在 items 驱动序里)。
|
|
131
|
+
* 注入语义:items 驱动失败(表空)时改用注入 id 逐机器人拉取;items 非空时注入
|
|
132
|
+
* id 不生效(避免伪造驱动行污染 items 表)。
|
|
133
|
+
*/
|
|
134
|
+
function wireCategories(task, robotIds, clock) {
|
|
135
|
+
if (task.id !== 'knowledge.categories' || robotIds.length === 0)
|
|
136
|
+
return task;
|
|
137
|
+
const orig = task.fetch;
|
|
138
|
+
return {
|
|
139
|
+
...task,
|
|
140
|
+
fetch: async (w, c) => {
|
|
141
|
+
try {
|
|
142
|
+
return await orig(w, c);
|
|
143
|
+
}
|
|
144
|
+
catch (e) {
|
|
145
|
+
if (!/knowledge_items 表为空/.test(e.message))
|
|
146
|
+
throw e;
|
|
147
|
+
}
|
|
148
|
+
// 注入路径:行拍平消费任务层的共享实现(flattenCategoryTree),不复制投影;
|
|
149
|
+
// 取数走任务层的 callPaced —— `ai.knowledge.getCategoryTree` 限频 1 次/秒,
|
|
150
|
+
// 裸 call 会让远端 14009 不落冷却行、本地令牌桶的拒绝直接冒泡成 fetch_failed gap
|
|
151
|
+
// (B 高-1 的同一口径:所有任务层取数都必须经 callPaced)。
|
|
152
|
+
const { flattenCategoryTree } = await import('../sync/tasks/knowledge.js');
|
|
153
|
+
const nowIso = new Date(clock()).toISOString();
|
|
154
|
+
const rows = [];
|
|
155
|
+
for (const rid of robotIds) {
|
|
156
|
+
const res = await callPaced('ai.knowledge.getCategoryTree', { robotId: rid }, c);
|
|
157
|
+
flattenCategoryTree(String(rid), res.payload, rows, nowIso);
|
|
158
|
+
}
|
|
159
|
+
return { rows, apiCount: rows.length };
|
|
160
|
+
},
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* 从配置文件读 `profiles.<name>.robots` 的 robotId 列表(G1 兜底来源)。
|
|
165
|
+
*
|
|
166
|
+
* ⚠️ 只取**键**(robotId),显示名是给人看的、注入面用不着。
|
|
167
|
+
* ⚠️ 任何读取失败一律返回 `[]`:本函数是**兜底**,不是主路径 —— 上面
|
|
168
|
+
* `resolveStoreConfig` 已经对同一份文件做过权限裁决与结构校验(含凭证且过宽
|
|
169
|
+
* 会在此前抛出),这里再抛一次只会把同一个问题报两遍,而且会掩盖真正的失败原因。
|
|
170
|
+
*/
|
|
171
|
+
function robotsFromConfig(configPath, profileFlag) {
|
|
172
|
+
try {
|
|
173
|
+
const r = fileProfile(configPath, profileFlag ?? process.env.QIYU_PROFILE);
|
|
174
|
+
return Object.keys(r.profile?.robots ?? {})
|
|
175
|
+
.map((k) => Number(k))
|
|
176
|
+
.filter((n) => Number.isInteger(n) && n > 0);
|
|
177
|
+
}
|
|
178
|
+
catch {
|
|
179
|
+
return [];
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
/** 任务条目 → 输出形态(spec §七字段名)。 */
|
|
183
|
+
function taskOut(r, watermark, lastSyncedAt, notes = []) {
|
|
184
|
+
return {
|
|
185
|
+
task: r.taskId,
|
|
186
|
+
status: r.status,
|
|
187
|
+
windows: r.windows,
|
|
188
|
+
rows: r.rows,
|
|
189
|
+
resolved_range: rangeOut(r.resolvedRange),
|
|
190
|
+
watermark,
|
|
191
|
+
last_synced_at: lastSyncedAt,
|
|
192
|
+
// gap 区间与 resolved_range 同走上海 ISO(E 中-2/C-11:时间形态在命令层统一,
|
|
193
|
+
// 不动引擎——引擎产出的毫秒字符串在格式化层转换)。
|
|
194
|
+
gaps: r.gaps.map((g) => ({
|
|
195
|
+
range: [msToShanghaiIso(g.rangeStart), msToShanghaiIso(g.rangeEnd)],
|
|
196
|
+
reason: g.reason, detail: g.detail,
|
|
197
|
+
})),
|
|
198
|
+
// 命令层的按任务说明(恒在,可为空数组):当前唯一生产者是「请求区间早于接口下界」
|
|
199
|
+
//(见 runSyncRun 的 floorNote)——把「区间不可得」与「同步故障」在输出里分开。
|
|
200
|
+
notes,
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* sync run 侧的存储失败出口。
|
|
205
|
+
*
|
|
206
|
+
* ⚠️ **保留底层错误的 hint**(架构审查 F1):`store_not_initialized` 有四种成因,只有
|
|
207
|
+
* 「库不存在」能靠 `qiyu store init` 解决;「路径不是 DuckDB 文件」「他人库」「依赖未安装」
|
|
208
|
+
* 跑 store init 会**再次失败**(`duckdb.ts:216-222` 会拒绝他人库,`depError` 的 hint 指向
|
|
209
|
+
* npm install)。早先无条件改成「请先运行 store init」,把 Agent 送进
|
|
210
|
+
* `sync run → store init → sync run` 死循环,且与 `store status`/`db tables` 对同一失败
|
|
211
|
+
* 给出的 hint 互相矛盾。现在只在**没有**底层 hint 时补缺省建议。
|
|
212
|
+
*/
|
|
213
|
+
function storeInitFail(e) {
|
|
214
|
+
const err = e;
|
|
215
|
+
const msg = err.message ?? String(e);
|
|
216
|
+
if (err.kind === 'store_not_initialized' || /not a valid DuckDB database/i.test(msg)) {
|
|
217
|
+
// 成因优先于缺省建议:底层 hint(依赖缺失 / 他人库 / 权限)原样保留;
|
|
218
|
+
// 「路径存在但不是 DuckDB 文件」由 DuckDB 原文判定(store.ts 同款文案)。
|
|
219
|
+
const hint = err.hint
|
|
220
|
+
?? (/not a valid DuckDB database/i.test(msg)
|
|
221
|
+
? '该路径已存在且不是 DuckDB 数据库,请换 --db 路径'
|
|
222
|
+
: '数据库尚未初始化。请先运行:qiyu store init');
|
|
223
|
+
return fail({
|
|
224
|
+
code: 'store_not_initialized', kind: 'store_not_initialized',
|
|
225
|
+
retryable: false,
|
|
226
|
+
message: msg,
|
|
227
|
+
hint,
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
return thrownToExit(e);
|
|
231
|
+
}
|
|
232
|
+
/** sync run 的完整编排(从 flags/env 到退出码)。返回值即命令退出码。 */
|
|
233
|
+
export async function runSyncRun(argv) {
|
|
234
|
+
setPretty(false); // G1:每条命令入口重置输出格式 —— 同一进程内多次 run(测试)不残留上一条命令的开关。
|
|
235
|
+
const clock = () => Date.now();
|
|
236
|
+
// —— flag 解析(store.ts 同族:值位守卫,--开头算缺值)——
|
|
237
|
+
// 已知 token 集(help 分流的豁免名单)= 全局 flag + 本命令的**布尔** flag。
|
|
238
|
+
// ⚠️ 不含值位:`sync run --help --since 7d` 必须报「--help 不接受额外参数」并把
|
|
239
|
+
// `--since` 点出来(既有测试钉着这条次序);值位只在下面的解析循环里消费。
|
|
240
|
+
const KNOWN = new Set([...GLOBAL_FLAGS.map((f) => f.name), ...RUN_BOOL_FLAGS]);
|
|
241
|
+
// ⚠️ `--help` 必须先分流、且不吞额外参数(架构审查 F2):全仓不变量是「help 永远成功、
|
|
242
|
+
// 但不能把写错的参数静默吃掉」。早先这一分支写在解析循环里,于是
|
|
243
|
+
// `sync run --help --bogus` 退出码 0(--bogus 被吞)、`--pretty --help` 却退出码 2
|
|
244
|
+
// (先撞上 --pretty 检查)—— 同一组 token 因书写顺序得到两种结果。
|
|
245
|
+
if (argv.includes('--help') || argv.includes('-h')) {
|
|
246
|
+
const extra = argv.filter((a) => !KNOWN.has(a));
|
|
247
|
+
if (extra.length > 0) {
|
|
248
|
+
// ⚠️ 不要写「未知参数」:`--since`/`--db` 是**已知**参数,只是不能与 --help 同用。
|
|
249
|
+
// 与 query.ts 的 help 分流同款措辞(CodeRabbit 复审 minor)。
|
|
250
|
+
return usageFail(`--help 不接受额外参数:${describeArgs(extra)}`);
|
|
251
|
+
}
|
|
252
|
+
process.stdout.write(SYNC_RUN_USAGE);
|
|
253
|
+
return 0;
|
|
254
|
+
}
|
|
255
|
+
// G1:--pretty 已实现。与 help 的次序保持原样(help 分流在前);解析循环里
|
|
256
|
+
// `--pretty` 落进未知参数分支会报错,所以在 KNOWN 里收下并在原拒绝点开启。
|
|
257
|
+
if (argv.includes('--pretty'))
|
|
258
|
+
setPretty(true);
|
|
259
|
+
const flags = {};
|
|
260
|
+
const taskIds = [];
|
|
261
|
+
for (let i = 0; i < argv.length; i++) {
|
|
262
|
+
const a = argv[i];
|
|
263
|
+
if (RUN_VALUE_FLAGS.includes(a)) {
|
|
264
|
+
const v = argv[i + 1];
|
|
265
|
+
if (v === undefined || v.startsWith('--')) {
|
|
266
|
+
return usageFail(`${a} 缺少取值`);
|
|
267
|
+
}
|
|
268
|
+
flags[a] = v;
|
|
269
|
+
i++;
|
|
270
|
+
}
|
|
271
|
+
else if (RUN_BOOL_FLAGS.includes(a) || a === '--pretty') {
|
|
272
|
+
// G1:--pretty 是已实现的输出开关(布尔)。收下避免报「未知参数」。
|
|
273
|
+
flags[a] = a;
|
|
274
|
+
}
|
|
275
|
+
else if (a.startsWith('-')) {
|
|
276
|
+
return usageFail(`未知参数:${describeArgs([a])}。可用:${RUN_AVAILABLE}`);
|
|
277
|
+
}
|
|
278
|
+
else {
|
|
279
|
+
taskIds.push(a);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
if (flags['--full'] && (flags['--since'] || flags['--until'])) {
|
|
283
|
+
return usageFail('--full 与 --since/--until 互斥:全量重刷不叠加区间参数');
|
|
284
|
+
}
|
|
285
|
+
// —— 任务 id 校验(usage:未知 id 是参数错误)——
|
|
286
|
+
const unknown = taskIds.filter((id) => taskById(id) === undefined);
|
|
287
|
+
if (unknown.length > 0) {
|
|
288
|
+
return usageFail(`未知任务:${unknown.join('、')}\n可用任务:${SYNC_TASKS.map((t) => t.id).join('、')}`);
|
|
289
|
+
}
|
|
290
|
+
// —— 凭证前置(api.ts 同族:缺凭证是环境问题 → auth_missing 退出码 1)——
|
|
291
|
+
const credOutcome = resolveCredentialsUsingFile(currentCredentialEnv());
|
|
292
|
+
if (!credOutcome.ok)
|
|
293
|
+
return fail(credOutcome.error);
|
|
294
|
+
const creds = credOutcome.creds;
|
|
295
|
+
// —— store 打开(rw 单写者)——
|
|
296
|
+
// ⚠️ close 覆盖 openStore 之后的**所有**路径(B 低-1,沿 store.ts 的 C1 形态):
|
|
297
|
+
// 迁移失败 / 他人库 / 后续任何异常,连接与 DuckDB instance 都必须在 finally 释放 ——
|
|
298
|
+
// 此前 close 只挂在第二个 try 的 finally 上,第一个 try(open+init)失败即泄漏。
|
|
299
|
+
let resolved;
|
|
300
|
+
try {
|
|
301
|
+
resolved = resolveStoreConfig({
|
|
302
|
+
flags: { db: flags['--db'], profile: flags['--profile'], backend: flags['--backend'] },
|
|
303
|
+
env: currentStoreEnv(),
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
catch (e) {
|
|
307
|
+
return usageFail(e.message);
|
|
308
|
+
}
|
|
309
|
+
let store;
|
|
310
|
+
try {
|
|
311
|
+
try {
|
|
312
|
+
store = await openStore(resolved.config, 'rw');
|
|
313
|
+
await store.init();
|
|
314
|
+
}
|
|
315
|
+
catch (e) {
|
|
316
|
+
return storeInitFail(e);
|
|
317
|
+
}
|
|
318
|
+
// —— 区间合成(时钟注入点:parseTimeArg 接受 clock;Nd/yesterday 已带区间,
|
|
319
|
+
// YYYY-MM-DD/ISO 只给起点 → end=clock 当前或配对的另一端)——
|
|
320
|
+
let rangeOverride;
|
|
321
|
+
if (flags['--full']) {
|
|
322
|
+
rangeOverride = { start: 0, end: clock() };
|
|
323
|
+
}
|
|
324
|
+
else if (flags['--since'] || flags['--until']) {
|
|
325
|
+
const untilMs = flags['--until']
|
|
326
|
+
? parseTimeArg(flags['--until'], clock, '--until')
|
|
327
|
+
: null;
|
|
328
|
+
if (flags['--until'] && untilMs === null) {
|
|
329
|
+
return usageFail(`--until 无法解析:${flags['--until']}。支持 Nd / yesterday / YYYY-MM-DD / ISO 8601`);
|
|
330
|
+
}
|
|
331
|
+
const sinceMs = flags['--since']
|
|
332
|
+
? parseTimeArg(flags['--since'], clock, '--since')
|
|
333
|
+
: null;
|
|
334
|
+
if (flags['--since'] && sinceMs === null) {
|
|
335
|
+
return usageFail(`--since 无法解析:${flags['--since']}。支持 Nd / yesterday / YYYY-MM-DD / ISO 8601`);
|
|
336
|
+
}
|
|
337
|
+
// 归一:Nd/yesterday 返回完整区间(起点优先);日期/ISO 返回时刻。
|
|
338
|
+
// 单 --until(分段回补):start=0、end=until 时刻;单 --since:start=since 时刻、
|
|
339
|
+
// end=now;成对:[since 时刻, until 时刻];--since 带 Nd 区间时用其 start。
|
|
340
|
+
const start = sinceMs === null ? 0
|
|
341
|
+
: typeof sinceMs === 'object' ? sinceMs.start : sinceMs;
|
|
342
|
+
const end = untilMs === null ? clock()
|
|
343
|
+
: typeof untilMs === 'object' ? untilMs.end : untilMs;
|
|
344
|
+
if (start >= end) {
|
|
345
|
+
return usageFail(`区间无效:start >= end(${new Date(start).toISOString()} >= ${new Date(end).toISOString()})`);
|
|
346
|
+
}
|
|
347
|
+
rangeOverride = { start, end };
|
|
348
|
+
}
|
|
349
|
+
// —— 任务选取与排序 ——
|
|
350
|
+
const selected = orderTasks(taskIds.length > 0
|
|
351
|
+
? taskIds.map((id) => taskById(id))
|
|
352
|
+
: SYNC_TASKS);
|
|
353
|
+
// —— robotId 注入面(配置层透传,本层消费)——
|
|
354
|
+
const opts = resolved.config.options;
|
|
355
|
+
const rawIds = opts?.knowledgeRobotIds;
|
|
356
|
+
// 修复批 4 #10:**整数组校验** —— 任一元素不是正整数即 usageFail(退出码 2)。
|
|
357
|
+
// 此前 `map(Number).filter(...)` 会把 `["abc", -1]` 静默丢成空数组:用户 typo
|
|
358
|
+
// 了 robotId 却毫无反馈(注入面静默失效)。非数组的错误分支保留。
|
|
359
|
+
if (rawIds !== undefined && !Array.isArray(rawIds)) {
|
|
360
|
+
return usageFail('配置文件 store.options.knowledgeRobotIds 必须是数字数组');
|
|
361
|
+
}
|
|
362
|
+
if (Array.isArray(rawIds)) {
|
|
363
|
+
const bad = rawIds.find((x) => !Number.isInteger(x) || x <= 0);
|
|
364
|
+
if (bad !== undefined) {
|
|
365
|
+
return usageFail(`配置文件 store.options.knowledgeRobotIds 必须是正整数数组(非法元素:${String(bad)})`);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
const robotIds = rawIds !== undefined
|
|
369
|
+
? rawIds.map((x) => Number(x)).filter((x) => Number.isInteger(x) && x > 0)
|
|
370
|
+
// ⚠️ G1 起配置里的 `profiles.<name>.robots`(`auth whoami` 输出的那份映射)
|
|
371
|
+
// 是兜底来源 —— 否则它是个「声明了但没人读」的死字段。优先级:
|
|
372
|
+
// store.options.knowledgeRobotIds > robots 键(向后兼容:已配 options 的
|
|
373
|
+
// 行为逐字不变)。权限裁决复用上方 resolveStoreConfig 的结果(同一次
|
|
374
|
+
// 调用已经查过),这里只读不再裁决。
|
|
375
|
+
: robotsFromConfig(resolved.configPath, flags['--profile']);
|
|
376
|
+
const ctxBase = {
|
|
377
|
+
store,
|
|
378
|
+
credentials: creds,
|
|
379
|
+
gate: new RateGate(store, clock),
|
|
380
|
+
clock,
|
|
381
|
+
};
|
|
382
|
+
const onProgress = flags['--quiet'] === undefined
|
|
383
|
+
? (line) => { process.stderr.write(line + '\n'); }
|
|
384
|
+
: undefined;
|
|
385
|
+
// —— 分层交错执行(高-1 修复):selected 已按 taskRank 有序,这里按 rank 分段 ——
|
|
386
|
+
// 每段内:reportDayRotation 批走 runRotated(同一天背靠背、避开同路径 30s 冷却),
|
|
387
|
+
// 其余逐个 runTask。段间严格串行 ⇒ rank=0 的 dim 先落库,rank=1 的报表才驱动
|
|
388
|
+
// staff 表(staff_salary_detail 缺 dim 首跑必败),knowledge 的 items/points(2)
|
|
389
|
+
// 先于 categories(3)。两组不再整体前后排列(那会把 dim 排到报表之后)。
|
|
390
|
+
const results = [];
|
|
391
|
+
// 按任务的「请求区间早于接口下界」说明(B 中-5 命令层补口):
|
|
392
|
+
// 声明了 windowStartFloorDays 的任务(接口物理上只提供最近 N 天,如 `ticket.search`
|
|
393
|
+
// 的 `opStart` 被服务端静默钳到 now−31 天),当**整个请求区间**早于该下界时,这段历史
|
|
394
|
+
// 上游给不出数据 —— 结果形态可能是任务层守卫显式失败(落 gap、partial),也可能是
|
|
395
|
+
// 服务端静默改写窗口(客户端以为同步了 [a,b],实际拿到的是别的窗口)。两种都不该让
|
|
396
|
+
// Agent 误读成「同步故障」或「这段已同步」→ 本层在此补 notes 把话说在明处。
|
|
397
|
+
// 判据只取「end 早于下界」(请求区间整体不可得);与下界部分重叠(start 在下界之前、
|
|
398
|
+
// end 在下界之后)的显式正数起点是引擎「原样照发」的既定语义(批 1 裁定),不在本层改写。
|
|
399
|
+
const floorNotes = new Map();
|
|
400
|
+
if (rangeOverride !== undefined) {
|
|
401
|
+
for (const t of selected) {
|
|
402
|
+
if (t.windowStartFloorDays === undefined)
|
|
403
|
+
continue;
|
|
404
|
+
const floor = clock() - t.windowStartFloorDays * DAY_MS;
|
|
405
|
+
if (rangeOverride.end <= floor) {
|
|
406
|
+
floorNotes.set(t.id, [
|
|
407
|
+
`请求区间结束于 ${shanghaiIso(rangeOverride.end)},早于该接口可得数据的最早边界 ` +
|
|
408
|
+
`${shanghaiIso(floor)}(now − ${t.windowStartFloorDays} 天):这段区间上游物理上给不出数据 ——` +
|
|
409
|
+
`结果要么是任务层守卫显式失败(落 gap、partial),要么是服务端把窗口静默改写;` +
|
|
410
|
+
`两者都不代表「请求的区间已同步」,请勿据此判断数据完整。`,
|
|
411
|
+
]);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
const ranks = [...new Set(selected.map((t) => taskRank(t)))].sort((a, b) => a - b);
|
|
416
|
+
for (const rank of ranks) {
|
|
417
|
+
const layer = selected.filter((t) => taskRank(t) === rank);
|
|
418
|
+
const rotated = layer.filter((t) => t.reportDayRotation);
|
|
419
|
+
const plain = layer.filter((t) => !t.reportDayRotation)
|
|
420
|
+
.map((t) => wireCategories(wireSessions(t, {}), robotIds, clock));
|
|
421
|
+
if (rotated.length > 0) {
|
|
422
|
+
results.push(...await runRotated(rotated, {
|
|
423
|
+
...ctxBase, rangeOverride, onProgress,
|
|
424
|
+
}));
|
|
425
|
+
}
|
|
426
|
+
for (const t of plain) {
|
|
427
|
+
results.push(await runTask(t, { ...ctxBase, rangeOverride, onProgress }));
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
// —— 输出(spec §七)——
|
|
431
|
+
const tasksOut = [];
|
|
432
|
+
for (const r of results) {
|
|
433
|
+
const st = await readWatermark(store, r.taskId);
|
|
434
|
+
tasksOut.push(taskOut(r, st.watermark, st.lastSyncedAt, floorNotes.get(r.taskId) ?? []));
|
|
435
|
+
}
|
|
436
|
+
// 全失败判定(T13 fix 中-1):引擎对 windowed 全窗失败权威产出 partial('failed'
|
|
437
|
+
// 只留给快照 gate 拦截路径)——「全失败」必须补判窗口级:succeeded=0 且 failed>0
|
|
438
|
+
// 的任务与 status='failed' 并列计入退出码 1。
|
|
439
|
+
const allFailed = results.every((r) => r.status === 'failed' || (r.windows.succeeded === 0 && r.windows.failed > 0));
|
|
440
|
+
const code = ok({ tasks: tasksOut, truncated: false });
|
|
441
|
+
// stderr 汇总(spec §二:核对不符等在 run 结束的 stderr 汇总中列出;下界裁剪的
|
|
442
|
+
// notes 同样进 stderr——--quiet 时只看 stdout 的 tasks[].notes)。
|
|
443
|
+
if (flags['--quiet'] === undefined) {
|
|
444
|
+
for (const r of results) {
|
|
445
|
+
if (r.gaps.length > 0) {
|
|
446
|
+
process.stderr.write(`[${r.taskId}] ${r.gaps.length} 个缺口:` +
|
|
447
|
+
r.gaps.map((g) => g.reason).join('、') + '\n');
|
|
448
|
+
}
|
|
449
|
+
for (const n of floorNotes.get(r.taskId) ?? []) {
|
|
450
|
+
process.stderr.write(`[${r.taskId}] 提示:${n}\n`);
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
return allFailed ? 1 : code;
|
|
455
|
+
}
|
|
456
|
+
catch (e) {
|
|
457
|
+
return thrownToExit(e);
|
|
458
|
+
}
|
|
459
|
+
finally {
|
|
460
|
+
// openStore 之前的失败(resolveStoreConfig/凭证/flag)已在更早的 return 处理,
|
|
461
|
+
// 不会进这里;走到本 finally 时 store 可能仍为 undefined(openStore 自身抛错)。
|
|
462
|
+
if (store !== undefined)
|
|
463
|
+
await store.close();
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
export const SYNC_RUN_USAGE = `用法:qiyu sync run [任务...] [参数]
|
|
467
|
+
|
|
468
|
+
qiyu sync run 增量同步全部任务(缺省 = 注册表全部)
|
|
469
|
+
qiyu sync run <任务...> 只跑指定任务
|
|
470
|
+
--full 全区间重刷(与 --since/--until 互斥)
|
|
471
|
+
--since T --until T 指定区间;T 支持 Nd / yesterday / YYYY-MM-DD / ISO 8601
|
|
472
|
+
(相对时间与日期按 Asia/Shanghai 解析)
|
|
473
|
+
--quiet 关闭 stderr 进度
|
|
474
|
+
--db / --profile / --backend 存储定位(store 命令同族)
|
|
475
|
+
|
|
476
|
+
进度与提示走 stderr;stdout 是 {tasks:[…], truncated:false},每任务含 resolved_range
|
|
477
|
+
(+08:00 ISO)、gaps(同 ISO 形态)与 notes(请求区间早于接口可得下界等说明,空数组为常态)。
|
|
478
|
+
部分成功退出码 0;全部失败 1;用法错误 2。中断在事务边界安全(kill 后续跑)。
|
|
479
|
+
`;
|