qiyu-cli 0.2.1 → 0.2.3
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 +433 -72
- package/dist/cli.js +48 -7
- package/dist/commands/api-notes.js +70 -0
- package/dist/commands/api.js +169 -49
- package/dist/commands/auth.js +151 -29
- package/dist/commands/credentials-source.js +30 -5
- package/dist/commands/db-notes.js +75 -0
- package/dist/commands/db.js +165 -127
- package/dist/commands/query-notes.js +58 -0
- package/dist/commands/query.js +449 -61
- package/dist/commands/skill.js +445 -51
- package/dist/commands/spec-types.js +101 -1
- package/dist/commands/stats.js +160 -33
- package/dist/commands/store-flags.js +18 -0
- package/dist/commands/store-notes.js +38 -0
- package/dist/commands/store-precheck.js +321 -0
- package/dist/commands/store.js +165 -77
- package/dist/commands/sync-notes.js +374 -0
- package/dist/commands/sync-run.js +180 -47
- package/dist/commands/sync.js +232 -127
- package/dist/core/config.js +280 -24
- package/dist/core/credentials.js +38 -4
- package/dist/core/edition.js +1 -1
- package/dist/core/envelope.js +73 -9
- package/dist/core/errors.js +73 -16
- package/dist/core/http.js +175 -54
- package/dist/core/ratelimit.js +5 -1
- package/dist/core/registry/index.js +36 -2
- package/dist/core/registry/params/export.session.check.json +17 -2
- package/dist/core/registry/params/export.session.json +24 -2
- package/dist/core/registry/params/export.session.one.json +10 -2
- package/dist/core/registry/params/export.session.one.message.json +17 -2
- package/dist/core/registry/specs.json +65 -43
- package/dist/core/shell.js +30 -0
- package/dist/core/time.js +1 -1
- package/dist/core/validate.js +21 -2
- package/dist/output.js +215 -29
- package/dist/postinstall.js +14 -5
- package/dist/query/errors.js +145 -45
- package/dist/query/mask.js +1277 -25
- package/dist/query/metric-catalog.js +11 -0
- package/dist/query/native-error.js +189 -0
- package/dist/query/sandbox.js +148 -25
- package/dist/query/table-query.js +36 -5
- package/dist/schedule/install.js +136 -13
- package/dist/skill/check.js +11 -6
- package/dist/skill/detect.js +89 -29
- package/dist/skill/install.js +233 -43
- package/dist/skill/paths.js +54 -0
- package/dist/skill/qiyu/SKILL.md +29 -5
- package/dist/skill/qiyu/errors.md +5 -4
- package/dist/skill/qiyu/protocols.md +57 -5
- package/dist/skill/qiyu/setup.md +6 -2
- package/dist/store/config.js +92 -16
- package/dist/store/duckdb.js +1551 -64
- package/dist/store/object-kinds.js +32 -0
- package/dist/store/retry.js +190 -7
- package/dist/store/schema.js +32 -4
- package/dist/sync/engine.js +439 -77
- package/dist/sync/registry.js +6 -0
- package/dist/sync/state.js +20 -0
- package/dist/sync/tasks/dim.js +23 -14
- package/dist/sync/tasks/knowledge.js +50 -8
- package/dist/sync/tasks/pace.js +27 -0
- package/dist/sync/tasks/pipeline.js +29 -9
- package/dist/sync/tasks/reports.js +176 -49
- package/dist/sync/tasks/sessions.js +88 -21
- package/dist/sync/tasks/tickets.js +59 -8
- package/dist/sync/types.js +60 -1
- package/dist/sync/windowing.js +0 -22
- package/dist/sync/write-contract.js +79 -0
- package/package.json +2 -2
|
@@ -11,10 +11,20 @@
|
|
|
11
11
|
`--limit` 或缩小时间窗口重查,不要拿样本当全量。
|
|
12
12
|
- `warnings`:非空必须逐条读。它们点名「窗口内部有缺口」「区间天数不足」这类**静默失败**;
|
|
13
13
|
忽略 warnings 的 Agent 会把残缺数据当事实汇报。
|
|
14
|
-
- `masked` / `masked_columns` / `mask_warnings`:输出默认脱敏;`mask_warnings`
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
- `masked` / `masked_columns` / `mask_warnings`:输出默认脱敏;`mask_warnings` 非空时**逐条读**——
|
|
15
|
+
它装两类事:**脱敏缺口**(敏感值没被打码)与**脱敏对结果的副作用**(`GROUP BY`/`DISTINCT`
|
|
16
|
+
把不同原值压成同一个脱敏值,分组与计数会失真,别名分组也照样报警;非敏感列按手机号形态
|
|
17
|
+
被误改)。含敏感列的结论要额外小心。两个**字面陷阱**:`masked: true` 只表示
|
|
18
|
+
脱敏开关开着,**不代表有值被改写**(那看 `masked_columns`,为空是常态);`--no-mask`
|
|
19
|
+
时 `mask_warnings` **恒为空**——空不等于脱敏完整,那是「根本没脱敏」,风险警告在
|
|
20
|
+
`warnings` 里。
|
|
21
|
+
- `resolved_range` / `data_coverage`:前者是**过滤边界**(不是有数据的范围),后者是
|
|
22
|
+
时间列在过滤范围内的 **MIN/MAX**。⚠️ `data_coverage` 只有首尾两点、**看不见内部缺口**
|
|
23
|
+
——7 天里只有第 1、7 天有数据时它照样报满区间。`iso-day` 表在**给了 `--since`/`--until`
|
|
24
|
+
时**另有 `warnings` 兜底(「区间内应有 N 个自然日,实际只有 M 个有数据」),**没有时间
|
|
25
|
+
过滤时这条兜底不触发**;`iso-instant` 与 `epoch-ms` 表任何情况下都没有兜底,要核对内部
|
|
26
|
+
覆盖得自己按自然日 `GROUP BY` 数行。
|
|
27
|
+
报告结论时带上这两个区间,让人类知道你算的是哪段数据。逐键释义见输出的 `meta.field_notes`。
|
|
18
28
|
- `--sql` 通道不判定区间与覆盖:`resolved_range` 与 `data_coverage` **恒为 null**——实际
|
|
19
29
|
区间以你写的 SQL 过滤为准,报告时自己写清。
|
|
20
30
|
|
|
@@ -25,7 +35,39 @@
|
|
|
25
35
|
1. **窗口写错**:相对时间按上海时区解析,而 Agent 常跑在 UTC 容器里——「昨天」可能不是
|
|
26
36
|
人类说的昨天,且不会报任何错。
|
|
27
37
|
2. **本地还没同步到这段**:用 `qiyu sync status` 看水位与缺口;`qiyu sync verify` 可以核对
|
|
28
|
-
|
|
38
|
+
本地与远端的一致性——但**只有快照任务**与远端行数核对(`expected_from_api`),windowed
|
|
39
|
+
任务不请求远端、只核对本地行数与同步状态记录,**drift 为空不代表与远端一致**(发现
|
|
40
|
+
漂移时以非零退出码明示)。缺口先看 `gaps[].reason`:
|
|
41
|
+
`rate_limit_local` 等到 `detail` 里的时刻再重跑,`fetch_failed`/`write_failed`/
|
|
42
|
+
`count_mismatch` 重跑 `sync run` 覆盖该区间;`knowledge_row_malformed`/
|
|
43
|
+
`staff_id_list_malformed`/`row_missing_key`/`filter_matched_no_staff`/`export_*`
|
|
44
|
+
是**成功窗上的提示**(不等于同步失败)。⚠️ 「提示」不等于「数据没缺」,两档分开读:
|
|
45
|
+
`knowledge_row_malformed`/`staff_id_list_malformed`/`row_missing_key` 描述的行
|
|
46
|
+
**确实没落库**(`detail` 是丢失规模,必须核对上游形态;`row_missing_key` 的行连
|
|
47
|
+
`fetched`/`written` 都不计,窗口仍可能 `complete`);`filter_matched_no_staff`/
|
|
48
|
+
`export_fixture_unreported`/`export_window_mismatch` **未必缺数据**(可能只是筛选
|
|
49
|
+
没命中、或空窗本来就空)。不确定就读 `detail`。
|
|
50
|
+
- ⚠️ **`range_status` 的两个取值字面都在撒谎**(逐值释义见输出的 `meta.field_notes`):
|
|
51
|
+
`complete` 只表示「水位推进过」——中窗失败时它照样是 `complete`,**不是**「全窗口成功」;
|
|
52
|
+
`pending` 只表示「最近一次运行没推进水位」——首窗失败时后续成功窗照常落库,**不是**
|
|
53
|
+
「库里没数据」;先成功一轮再跑一轮首窗失败同样回到 `pending`(watermark 保留上一轮的
|
|
54
|
+
值),所以也**不是**「从未同步过」;更**不是**「正在同步」。判数据完整不要只看
|
|
55
|
+
`range_status`,也不要只看 `gaps`——
|
|
56
|
+
**空 `gaps` 不等于完整**(`windows.skipped > 0` 时可能没有缺口记录、但请求区间仍有
|
|
57
|
+
未覆盖段)。要同时看覆盖范围(`sync status` 的 `resolved_range`、以及 `sync run` 的
|
|
58
|
+
`windows.skipped` —— status 与 verify 都不输出后者)与历史缺口的新鲜度。
|
|
59
|
+
- ⚠️ **`gaps` 是历史记录,不等于「当前仍缺」**:旧记录与新记录的 `reason` 相同,按
|
|
60
|
+
`reason` 分不出新旧;`range` 也只能说明「相关」——换边界重跑后数据可能已补齐,而旧
|
|
61
|
+
缺口的 `range` 仍与你评估的区间重叠。**没有一次覆盖核对就不能确认新鲜度**:写
|
|
62
|
+
「该区间有历史缺口记录,新鲜度未确认」,不要直接报成当前故障。
|
|
63
|
+
- ⚠️ `sync run` 的 `status: "partial"` **也覆盖「一行都没落」的全窗失败**:两个字段分开
|
|
64
|
+
读——`windows.succeeded` 是成功窗数(空窗也算成功),`rows.written` 才是落库行数。
|
|
65
|
+
- ⚠️ **`sync verify` 的 `drift` 为空 / 退出码 0 不能当完整性证据**:对 windowed 任务
|
|
66
|
+
它只核对同步状态记录(实测中窗失败的库同样给 `drift: []` + 退出码 0),快照任务另有
|
|
67
|
+
上游行数核对。windowed 的完整性要另行核对两处:`sync status` 的 `gaps` 与
|
|
68
|
+
`resolved_range`,以及 `sync run` 的 `windows.skipped`(status/verify 都不输出它)。
|
|
69
|
+
- ⚠️ `locked: true` 是**残留的写者章**(上一轮被强杀),不是「正在同步中」——真持锁的
|
|
70
|
+
写者会让 `sync status` 先退避等待,等到后读到的是那一轮的结果。重跑 `sync run` 即可。
|
|
29
71
|
3. **真的没有数据**。
|
|
30
72
|
|
|
31
73
|
报告 0 行时写「查询窗口 X 到 Y 内 0 行」,并说明排除了哪几种成因;不要写「系统里没有」。
|
|
@@ -34,6 +76,16 @@
|
|
|
34
76
|
|
|
35
77
|
- **绝不猜单位**——百分比还是绝对值、按日还是按小时,猜错数字全错。报表字段的声明单位、
|
|
36
78
|
本地观测分布、哨兵值由 `qiyu stats fields <报表表>` 给出。
|
|
79
|
+
- **`declared.<字段>.unit` 的每个取值怎么用,看输出的 `meta.field_notes`**(那里逐值给了
|
|
80
|
+
释义与动作):`ms` 是毫秒;`unknown` 是「判不出单位」而不是「没有单位」(如实写
|
|
81
|
+
「单位未知」,不要猜)。`ratio` 的 0–1 量纲**只有 `assignedRatio` 经设计稿实测**——
|
|
82
|
+
其余 `ratio` 是按名字推断的(`source: name-suffix`,**推断不是实测**)。`observed` 的
|
|
83
|
+
`min`/`max` 只能核对一致性、**不是量纲证据**:全都落在 0–1 时,它与「0–1 小数」和
|
|
84
|
+
「数值恰好都 <1% 的百分数」都相容。量纲不明确就**报告原值并标注不确定**,不要自行
|
|
85
|
+
换算成百分比。
|
|
86
|
+
`source` 就告诉你这条声明是实测(`design-doc`)还是命名推断。
|
|
87
|
+
- `declared.<字段>.higher_is_better` **恒为 null**——没有任何上游依据,不要据此判断指标
|
|
88
|
+
好坏方向,也不要一直等它变成 true/false。
|
|
37
89
|
- 哨兵值会混进聚合(例如「无处理人」用特殊编号表示,不排除就会凭空多出一个「员工」)。
|
|
38
90
|
先看观测分布,再决定过滤条件。
|
|
39
91
|
- 声明了但本地观测不到取值的字段,报告时写「未观测到取值」——声明是契约,不是事实。
|
package/dist/skill/qiyu/setup.md
CHANGED
|
@@ -12,11 +12,15 @@
|
|
|
12
12
|
|
|
13
13
|
1. **缺失时问人类**。要「机器人编号清单」,不要自己编造、不要按数字区间试探、
|
|
14
14
|
不要把会话里见过的编号当全量。
|
|
15
|
-
2.
|
|
16
|
-
- `store.options.knowledgeRobotIds`(正整数数组)—— **优先**;
|
|
15
|
+
2. 人类把编号写进配置文件(两种写法都认,都在 `profiles.<name>` 之下):
|
|
16
|
+
- `profiles.<name>.store.options.knowledgeRobotIds`(正整数数组)—— **优先**;
|
|
17
17
|
- `profiles.<name>.robots`(`{"1000001":"机器人A"}` 映射,键是编号、值是显示名)——
|
|
18
18
|
`knowledgeRobotIds` 缺席时的兜底。
|
|
19
19
|
|
|
20
|
+
⚠️ **`knowledgeRobotIds` 在 `store` 块的 `options` 里面,比 `robots` 低两层** —— 两处写混
|
|
21
|
+
(例如把 `knowledgeRobotIds` 直接放在 `profiles.<name>` 下)会被 CLI 以
|
|
22
|
+
「配置文件未知键」拒绝(退出码 2)。转述给人类时请给**完整路径**,不要只说键名。
|
|
23
|
+
|
|
20
24
|
`qiyu sync run` 在条目数据集为空(分类树没有可依据的编号来源)时会改用这些编号逐机器人
|
|
21
25
|
拉取分类树;条目数据非空时以条目数据为准。写错(非正整数)会被 CLI 以用法错误拒绝并点名
|
|
22
26
|
非法元素。`qiyu auth whoami` 的 `data.robots` 会如实列出配置里的映射(未校验有效性)。
|
package/dist/store/config.js
CHANGED
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
// 一律委托 core 层 —— 这样 auth 与 store 看到的「未知键」「JSON 畸形」「权限过宽」
|
|
9
9
|
// 是同一句话,不会出现两套口径。
|
|
10
10
|
import { homedir } from 'node:os';
|
|
11
|
-
import {
|
|
12
|
-
import { configPathFor, loadConfigFile, checkPermissions, configHasCredentials } from '../core/config.js';
|
|
11
|
+
import { join, isAbsolute } from 'node:path';
|
|
12
|
+
import { configPathFor, loadConfigFile, checkPermissions, configHasCredentials, insecureConfigError, nonEmptyValue, resolveProfileName } from '../core/config.js';
|
|
13
13
|
export const DEFAULTS = {
|
|
14
14
|
relPath: join('.qiyu', 'duckdb', 'qiyu.duckdb'),
|
|
15
15
|
backend: 'duckdb',
|
|
@@ -30,6 +30,19 @@ function assertKnownKeys(obj, known, prefix) {
|
|
|
30
30
|
function expandHome(p, home) {
|
|
31
31
|
return p === '~' ? home : p.startsWith('~/') ? join(home, p.slice(2)) : p;
|
|
32
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* 取「命令行 > 环境变量 > 配置文件 > 内置默认」的某一层,**同时返回来源**(spec §3.2)。
|
|
35
|
+
*
|
|
36
|
+
* 为什么要来源:报错得说清是哪一层坏的(见下面的空白守卫)。
|
|
37
|
+
* ⚠️ 环境变量层的空串已由 `nonEmptyValue`(core/config.ts,全仓唯一实现)归一成
|
|
38
|
+
* undefined —— 传进来的 `env.QIYU_*` 必须先过它,否则 `''` 会遮蔽配置文件里的真值。
|
|
39
|
+
*/
|
|
40
|
+
function pickLayer(layers, fallback) {
|
|
41
|
+
for (const l of layers)
|
|
42
|
+
if (l.value !== undefined)
|
|
43
|
+
return { value: l.value, source: l.source };
|
|
44
|
+
return { value: fallback, source: '内置默认' };
|
|
45
|
+
}
|
|
33
46
|
function assertPositiveInt(v, key, max) {
|
|
34
47
|
if (typeof v !== 'number' || !Number.isInteger(v) || v <= 0) {
|
|
35
48
|
throw new Error(`配置文件 ${key} 必须是正整数,实际为 ${JSON.stringify(v)}`);
|
|
@@ -75,12 +88,12 @@ export function resolveStoreConfig(opts = {}) {
|
|
|
75
88
|
onWarn: (m) => process.stderr.write(`${m}\n`),
|
|
76
89
|
});
|
|
77
90
|
if (!perm.ok) {
|
|
78
|
-
//
|
|
79
|
-
//
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
91
|
+
// ⚠️ 必须抛**带 kind** 的错误(2026-10-26 实测修):这里此前抛普通 Error,而各命令
|
|
92
|
+
// catch 一律 `usageFail(...)` —— 于是「配置含凭证且权限过宽」在 store/db/query/stats/
|
|
93
|
+
// sync 上被降级成退出码 2 + `kind: usage`("改参数重来")且 hint 丢失,只有
|
|
94
|
+
// auth/api 那条路径如实给出退出码 1 + `kind: config_insecure`。同一个危险状态两种
|
|
95
|
+
// 行为,Agent 会去改参数而真正的动作是 chmod。统一由 core 的构造点产出。
|
|
96
|
+
throw insecureConfigError(configPath, perm.reason);
|
|
84
97
|
}
|
|
85
98
|
}
|
|
86
99
|
const profiles = file.profiles;
|
|
@@ -96,23 +109,80 @@ export function resolveStoreConfig(opts = {}) {
|
|
|
96
109
|
throw new Error(`配置文件 profiles.${name}.store.options 必须是对象`);
|
|
97
110
|
}
|
|
98
111
|
}
|
|
99
|
-
|
|
100
|
-
|
|
112
|
+
// ⚠️ 点名的 profile 必须存在(2026-10-27 实测修):此前 `profiles[profileName] ?? {}`
|
|
113
|
+
// 把「profile 拼错」和「profile 存在但没配 store」合并成同一个静默回落 ——
|
|
114
|
+
// `--profile prodd`(少一个字母)会读到**默认库**并返回 `ok:true` 与其中的数据,
|
|
115
|
+
// Agent 看不出自己读错了库;`store init --profile prodd` 还会在默认路径上创建
|
|
116
|
+
// 一个用户从未配置的库。与全仓「未知名字必须拒绝并给候选」一致(未知表/未知任务/
|
|
117
|
+
// 未知接口 id/未知后端/未知配置键),也与 §3.3「拼错的配置键静默无效等于让用户
|
|
118
|
+
// 以为设置生效了」同一条理由。
|
|
119
|
+
//
|
|
120
|
+
// 边界(刻意保留的回落):
|
|
121
|
+
// · 配置文件不存在 → `loadConfigFile` 给出空 file,`profiles` 为空,
|
|
122
|
+
// 下面的 `available.length > 0` 直接放行(首次运行)—— 所以不需要再判
|
|
123
|
+
// `configExists`(实测删掉该条件全绿:它与长度判据完全冗余,留着是死条件);
|
|
124
|
+
// · 配置文件存在但 `profiles` 为空 → 同上(空配置没有可选项);
|
|
125
|
+
// · profile 存在但缺 store 块 → 走默认(tests/store/config.test.ts 钉着);
|
|
126
|
+
// · 未点名任何 profile(连 defaultProfile 都没有)→ 用内置 `default`,不查。
|
|
127
|
+
// ⚠️ 空串口径与 auth 侧逐字一致:`--profile ''` 是 usage 错误(`auth login` 的
|
|
128
|
+
// normalizeProfile 同样报「--profile 不能为空」);`QIYU_PROFILE=`(变量未设的
|
|
129
|
+
// 典型形态)与 `defaultProfile: ''` 当未设置 —— 档名解析走 core 的
|
|
130
|
+
// `resolveProfileName`(唯一实现),凭证侧与 store 侧不得对同一份配置给出两种解读。
|
|
131
|
+
if (flags.profile !== undefined && flags.profile.trim() === '') {
|
|
132
|
+
throw new Error('--profile 不能为空');
|
|
133
|
+
}
|
|
134
|
+
const namedProfile = resolveProfileName({
|
|
135
|
+
flag: flags.profile, envProfile: env.QIYU_PROFILE, defaultProfile: file.defaultProfile,
|
|
136
|
+
});
|
|
137
|
+
const profileName = namedProfile.name;
|
|
138
|
+
if (namedProfile.source !== undefined) {
|
|
139
|
+
const available = Object.keys(profiles);
|
|
140
|
+
// ⚠️ own-property 判据(2026-10-27,CodeRabbit):`profiles[x] === undefined` 会被
|
|
141
|
+
// 原型链绕过 —— `--profile constructor` / `toString` 命中 `Object.prototype` 上的
|
|
142
|
+
// 继承属性,守卫放行后回落默认库。parseConfig 已改用 null 原型对象,这里是第二道锁
|
|
143
|
+
// (resolveStoreConfig 的 profiles 只来自 parseConfig,但判据本身不该依赖来源)。
|
|
144
|
+
if (available.length > 0 && !Object.hasOwn(profiles, profileName)) {
|
|
145
|
+
throw new Error(`配置文件里没有 profile ${JSON.stringify(profileName)}(来自 ${namedProfile.source};` +
|
|
146
|
+
`现有:${available.join('、')})—— 检查拼写,或先在配置文件里加上这个 profile`);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
const prof = Object.hasOwn(profiles, profileName) ? profiles[profileName] : {};
|
|
101
150
|
const storeBlock = (prof.store ?? {});
|
|
102
|
-
|
|
151
|
+
// backend 的类型守卫与 path 同款(此前只有 path 有):配置写 123 / {} 时,
|
|
152
|
+
// `未知后端:[object Object]。目前仅支持 duckdb` 既不点名键路径、也读不出坏了什么。
|
|
153
|
+
if (storeBlock.backend !== undefined && typeof storeBlock.backend !== 'string') {
|
|
154
|
+
throw new Error(`配置文件 profiles.${profileName}.store.backend 必须是字符串`);
|
|
155
|
+
}
|
|
156
|
+
const backend = pickLayer([
|
|
157
|
+
{ source: '--backend', value: flags.backend },
|
|
158
|
+
{ source: 'QIYU_STORE_BACKEND', value: nonEmptyValue(env.QIYU_STORE_BACKEND) },
|
|
159
|
+
{ source: `配置文件 profiles.${profileName}.store.backend`, value: storeBlock.backend },
|
|
160
|
+
], DEFAULTS.backend);
|
|
161
|
+
const rawBackend = backend.value;
|
|
103
162
|
if (rawBackend !== 'duckdb') {
|
|
104
|
-
throw new Error(`未知后端:${rawBackend}
|
|
163
|
+
throw new Error(`未知后端:${JSON.stringify(rawBackend)}(来自 ${backend.source})。目前仅支持 duckdb`);
|
|
105
164
|
}
|
|
106
165
|
// ⚠️ path 类型守卫(K 组 M1):配置写数字/对象时,expandHome 会对非字符串调
|
|
107
166
|
// startsWith 抛裸英文 TypeError,且不点名键路径 —— 违反 fail-closed 点名键路径约定。
|
|
108
167
|
if (storeBlock.path !== undefined && typeof storeBlock.path !== 'string') {
|
|
109
168
|
throw new Error(`配置文件 profiles.${profileName}.store.path 必须是字符串`);
|
|
110
169
|
}
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
170
|
+
const path = pickLayer([
|
|
171
|
+
{ source: '--db', value: flags.db },
|
|
172
|
+
{ source: 'QIYU_DB_PATH', value: nonEmptyValue(env.QIYU_DB_PATH) },
|
|
173
|
+
{ source: `配置文件 profiles.${profileName}.store.path`, value: storeBlock.path },
|
|
174
|
+
], DEFAULTS.relPath);
|
|
175
|
+
const rawPath = path.value;
|
|
176
|
+
// ⚠️ 空串守卫(K 组 M4):空白值会穿过所有前置检查直达 DuckDB,产出难懂的底层错误。
|
|
177
|
+
// 空串不是合法路径,usage 拒绝。
|
|
178
|
+
// ⚠️ 文案点名**真正给了空白值的那一层**(2026-10-29 实测修):此前写死
|
|
179
|
+
// 「--db / QIYU_DB_PATH / store.path 均为空」—— 而实测 store.path 明明配了值,
|
|
180
|
+
// 是被 `QIYU_DB_PATH=` 遮蔽的(报错把三层一起指控,Agent 会去改没坏的那层)。
|
|
181
|
+
// ⚠️ 环境变量的**空串**到不了这里(`nonEmptyValue` 已视为未设置);能到这里的是
|
|
182
|
+
// 显式 flag 的空白值、空白串环境变量(`' '`)、以及配置文件里的空白 path。
|
|
114
183
|
if (rawPath.trim() === '') {
|
|
115
|
-
throw new Error(
|
|
184
|
+
throw new Error(`数据库路径不能为空:${path.source} 给了空白值 ${JSON.stringify(rawPath)}。`
|
|
185
|
+
+ '空串不是合法路径 —— 想回落到下一层:别传这个 flag / unset 这个变量 / 删掉这个配置键');
|
|
116
186
|
}
|
|
117
187
|
const readOnlyRetryMs = storeBlock.readOnlyRetryMs === undefined
|
|
118
188
|
? DEFAULTS.readOnlyRetryMs
|
|
@@ -121,6 +191,11 @@ export function resolveStoreConfig(opts = {}) {
|
|
|
121
191
|
? DEFAULTS.batchSize
|
|
122
192
|
: assertPositiveInt(storeBlock.batchSize, `profiles.${profileName}.store.batchSize`, 100_000);
|
|
123
193
|
// 相对路径(内置默认 relPath)按 home 解析;~ 前缀展开为 home(M-6)
|
|
194
|
+
// ⚠️ 刻意不按 cwd 解析(2026-11-07 审查):`--db` 的值会被固化进**调度条目**
|
|
195
|
+
//(sync install),而调度任务的 cwd 不一定是安装时的 cwd;相对 HOME 是唯一在
|
|
196
|
+
// 交互与调度两侧稳定一致的基准。代价是与其他命令「相对路径按 cwd」的直觉相反 ——
|
|
197
|
+
// 所以各命令的 --help 必须写明这一点(`DB_PATH_FLAG_HELP`),否则 Agent 会以为
|
|
198
|
+
// `--db data/q.db` 指向当前目录,实际建到了 ~/data/q.db。
|
|
124
199
|
const expanded = expandHome(rawPath, home);
|
|
125
200
|
const finalPath = isAbsolute(expanded) ? expanded : join(home, expanded);
|
|
126
201
|
return {
|
|
@@ -133,5 +208,6 @@ export function resolveStoreConfig(opts = {}) {
|
|
|
133
208
|
},
|
|
134
209
|
configPath,
|
|
135
210
|
configExists,
|
|
211
|
+
...(namedProfile.source !== undefined ? { profileFlag: profileName } : {}),
|
|
136
212
|
};
|
|
137
213
|
}
|