@arcticdata/dsh-datarc-assistant 26.39.0 → 26.39.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/README.md +45 -10
- package/api-operations.js +404 -0
- package/client.js +452 -87
- package/cordis.patch.yml +4 -4
- package/entry/SKILL.md +34 -0
- package/icon.png +0 -0
- package/index.js +35 -47
- package/locale/en.json +6 -6
- package/locale/zh.json +6 -6
- package/native-api.mjs +326 -0
- package/native-contracts.js +195 -0
- package/native-execution.js +184 -0
- package/native-runner.mjs +107 -0
- package/native-state.js +67 -0
- package/native-tools.js +241 -0
- package/operations.js +1260 -0
- package/package.json +65 -51
- package/{skills → runtime}/datarc-access-permissions/SKILL.md +30 -30
- package/{skills → runtime}/datarc-access-permissions/references/api.md +31 -31
- package/{skills → runtime}/datarc-access-permissions/references/write-order.md +16 -16
- package/{skills → runtime}/datarc-analysis-report/SKILL.md +125 -125
- package/{skills → runtime}/datarc-analysis-report/agents/openai.yaml +6 -6
- package/{skills → runtime}/datarc-analysis-report/references/analyst-frameworks.md +215 -215
- package/{skills → runtime}/datarc-analysis-report/references/api-contracts.md +478 -478
- package/{skills → runtime}/datarc-analysis-report/references/direct-card-fallback-design.md +66 -66
- package/{skills → runtime}/datarc-analysis-report/references/human-in-the-loop.md +142 -142
- package/{skills → runtime}/datarc-analysis-report/references/loop-personalization-policy.md +138 -138
- package/{skills → runtime}/datarc-analysis-report/references/manifest-example.json +779 -779
- package/{skills → runtime}/datarc-analysis-report/references/narrative-schema.md +160 -160
- package/{skills → runtime}/datarc-analysis-report/references/question-syntax.md +151 -151
- package/{skills → runtime}/datarc-analysis-report/scripts/run_analysis_report.py +2225 -2225
- package/{skills → runtime}/datarc-analysis-report/scripts/run_dataseek_cards.py +1914 -1914
- package/{skills → runtime}/datarc-analysis-report/scripts/test_run_analysis_report.py +5295 -5295
- package/{skills → runtime}/datarc-data-search/SKILL.md +243 -243
- package/{skills → runtime}/datarc-data-search/scripts/calculate.py +116 -116
- package/{skills → runtime}/datarc-data-search/scripts/data-search.mjs +628 -628
- package/{skills/datarc-dataseek-search → runtime/datarc-data-search}/scripts/datarc-client.mjs +464 -464
- package/{skills → runtime}/datarc-data-search/scripts/search-result.mjs +211 -211
- package/{skills → runtime}/datarc-dataseek-batch-evaluation/SKILL.md +59 -59
- package/{skills → runtime}/datarc-dataseek-batch-evaluation/references/artifacts.md +36 -36
- package/{skills → runtime}/datarc-dataseek-batch-evaluation/references/equivalence.md +30 -30
- package/{skills/datarc-data-search → runtime/datarc-dataseek-batch-evaluation}/scripts/datarc-client.mjs +464 -464
- package/{skills → runtime}/datarc-dataseek-batch-evaluation/scripts/dataseek-batch-evaluation.mjs +1020 -1020
- package/{skills → runtime}/datarc-dataseek-search/SKILL.md +96 -96
- package/{skills/datarc-dataseek-batch-evaluation → runtime/datarc-dataseek-search}/scripts/datarc-client.mjs +464 -464
- package/{skills → runtime}/datarc-dataseek-search/scripts/dataseek-search.mjs +257 -257
- package/{skills → runtime}/datarc-dataseek-semantic-debugging/SKILL.md +44 -44
- package/{skills → runtime}/datarc-dataseek-semantic-debugging/agents/openai.yaml +4 -4
- package/{skills → runtime}/datarc-dataseek-semantic-debugging/evals/evals.json +165 -165
- package/{skills → runtime}/datarc-dataseek-semantic-debugging/references/dataset.md +77 -77
- package/{skills → runtime}/datarc-dataseek-semantic-debugging/references/input-and-resolution.md +93 -93
- package/{skills → runtime}/datarc-dataseek-semantic-debugging/references/interventions.md +64 -64
- package/{skills → runtime}/datarc-dataseek-semantic-debugging/references/knowledge-and-prompts.md +47 -47
- package/{skills → runtime}/datarc-dataseek-semantic-debugging/references/rollback.md +11 -11
- package/{skills → runtime}/datarc-dataseek-semantic-debugging/references/verification-and-rollback.md +95 -95
- package/{skills → runtime}/datarc-dataseek-semantic-debugging/scripts/semantic-debugging.mjs +29 -29
- package/{skills → runtime}/datarc-dataseek-testset-generation/SKILL.md +47 -47
- package/{skills → runtime}/datarc-dataseek-testset-generation/scripts/datarc-client.mjs +464 -464
- package/{skills → runtime}/datarc-dataseek-testset-generation/scripts/dataseek-testset-generation.mjs +526 -526
- package/{skills → runtime}/datarc-datasource/SKILL.md +97 -97
- package/{skills → runtime}/datarc-oauth/SKILL.md +50 -50
- package/{skills → runtime}/datarc-oauth/scripts/auth.mjs +192 -192
- package/{skills → runtime}/datarc-oauth/scripts/credentials.mjs +237 -237
- package/{skills → runtime}/datarc-report-add-card/SKILL.md +90 -90
- package/{skills → runtime}/datarc-report-add-card/agents/openai.yaml +4 -4
- package/runtime/datarc-report-add-card/scripts/datarc-client.mjs +464 -0
- package/{skills → runtime}/datarc-report-add-card/scripts/report-card.mjs +439 -439
- package/{skills → runtime}/datarc-semantic-alias/SKILL.md +20 -20
- package/{skills → runtime}/datarc-semantic-alias/scripts/alias-plan.mjs +422 -422
- package/{skills → runtime}/datarc-semantic-alias/scripts/alias.mjs +11 -11
- package/{skills → runtime}/datarc-semantic-calibration/SKILL.md +20 -20
- package/{skills → runtime}/datarc-semantic-calibration/scripts/calibration-plan.mjs +683 -683
- package/{skills → runtime}/datarc-semantic-calibration/scripts/calibration.mjs +11 -11
- package/{skills → runtime}/datarc-semantic-core/SKILL.md +12 -12
- package/{skills → runtime}/datarc-semantic-core/scripts/artifact-journal.mjs +853 -830
- package/{skills → runtime}/datarc-semantic-core/scripts/canonical.mjs +48 -48
- package/{skills → runtime}/datarc-semantic-core/scripts/case-model.mjs +608 -608
- package/{skills → runtime}/datarc-semantic-core/scripts/cli.mjs +180 -180
- package/{skills → runtime}/datarc-semantic-core/scripts/datarc-client.mjs +180 -180
- package/{skills → runtime}/datarc-semantic-core/scripts/interpretation-pairs.mjs +57 -57
- package/{skills → runtime}/datarc-semantic-core/scripts/interventions.mjs +693 -693
- package/{skills → runtime}/datarc-semantic-core/scripts/live-resolution.mjs +305 -305
- package/{skills → runtime}/datarc-semantic-core/scripts/model-scope.mjs +49 -49
- package/{skills → runtime}/datarc-semantic-core/scripts/reproduction.mjs +330 -330
- package/{skills → runtime}/datarc-semantic-core/scripts/semantic-cli.mjs +799 -740
- package/{skills → runtime}/datarc-semantic-core/scripts/shared.mjs +312 -312
- package/{skills → runtime}/datarc-semantic-core/scripts/verification.mjs +1111 -1014
- package/{skills → runtime}/datarc-semantic-dataset/SKILL.md +20 -20
- package/{skills → runtime}/datarc-semantic-dataset/scripts/dataset-plan.mjs +749 -749
- package/{skills → runtime}/datarc-semantic-dataset/scripts/dataset-preflight.mjs +813 -813
- package/{skills → runtime}/datarc-semantic-dataset/scripts/dataset.mjs +11 -11
- package/{skills → runtime}/datarc-semantic-knowledge/SKILL.md +38 -38
- package/{skills → runtime}/datarc-semantic-knowledge/references/knowledge-drafts.md +61 -61
- package/{skills → runtime}/datarc-semantic-knowledge/references/knowledge-generation.json +16 -16
- package/{skills → runtime}/datarc-semantic-knowledge/scripts/knowledge-draft.mjs +347 -347
- package/{skills → runtime}/datarc-semantic-knowledge/scripts/knowledge-plan.mjs +848 -848
- package/{skills → runtime}/datarc-semantic-knowledge/scripts/knowledge.mjs +31 -31
- package/{skills → runtime}/datarc-semantic-prompt/SKILL.md +20 -20
- package/{skills → runtime}/datarc-semantic-prompt/scripts/prompt-plan.mjs +598 -447
- package/{skills → runtime}/datarc-semantic-prompt/scripts/prompt.mjs +15 -15
- package/{skills → runtime}/datarc-semantic-synonym/SKILL.md +20 -20
- package/{skills → runtime}/datarc-semantic-synonym/scripts/synonym-plan.mjs +688 -688
- package/{skills → runtime}/datarc-semantic-synonym/scripts/synonym.mjs +11 -11
- package/{skills → runtime}/datarc-viz-analysis-report/SKILL.md +108 -108
- package/{skills → runtime}/datarc-viz-analysis-report/assets/LICENSE-echarts.md +8 -8
- package/{skills → runtime}/datarc-viz-analysis-report/assets/echarts.min.js +45 -45
- package/{skills → runtime}/datarc-viz-analysis-report/references/api-contracts.md +163 -163
- package/{skills → runtime}/datarc-viz-analysis-report/references/derivation-log.md +157 -157
- package/{skills → runtime}/datarc-viz-analysis-report/references/evidence-framework.md +76 -76
- package/{skills → runtime}/datarc-viz-analysis-report/references/html-template.md +92 -92
- package/{skills → runtime}/datarc-viz-analysis-report/references/provenance-format.md +56 -56
- package/{skills → runtime}/datarc-viz-analysis-report/references/question-syntax.md +151 -151
- package/{skills → runtime}/datarc-viz-analysis-report/scripts/render_viz_report.py +1708 -1708
- package/{skills → runtime}/datarc-viz-analysis-report/scripts/test_render_viz_report.py +964 -964
- package/{skills → runtime}/datarc-workspace-configuration/SKILL.md +59 -59
- package/{skills → runtime}/datarc-workspace-configuration/references/artifacts.md +75 -75
- package/{skills → runtime}/datarc-workspace-configuration/references/verification.md +20 -20
- package/{skills → runtime}/datarc-workspace-configuration/scripts/configuration.mjs +722 -662
- package/{skills → runtime}/datarc-workspace-context/SKILL.md +43 -43
- package/{skills → runtime}/datarc-workspace-context/agents/openai.yaml +4 -4
- package/{skills → runtime}/datarc-workspace-context/scripts/datarc-client.mjs +31 -31
- package/{skills → runtime}/datarc-workspace-context/scripts/query-display.mjs +114 -114
- package/{skills → runtime}/datarc-workspace-context/scripts/workspace-context.mjs +58 -58
- package/{skills → runtime}/datarc-workspace-custom-tables/SKILL.md +89 -89
- package/{skills → runtime}/datarc-workspace-custom-tables/scripts/datarc-client.mjs +165 -165
- package/{skills → runtime}/datarc-workspace-custom-tables/scripts/workspace-custom-tables.mjs +601 -601
- package/{skills → runtime}/datarc-workspace-keywords/SKILL.md +197 -197
- package/{skills → runtime}/datarc-workspace-keywords/agents/openai.yaml +4 -4
- package/{skills → runtime}/datarc-workspace-keywords/references/api-fields.md +79 -79
- package/{skills → runtime}/datarc-workspace-keywords/references/derived-measures.md +177 -177
- package/{skills → runtime}/datarc-workspace-keywords/scripts/datarc-client.mjs +145 -145
- package/{skills → runtime}/datarc-workspace-keywords/scripts/workspace-keywords.mjs +2421 -2421
- package/{skills → runtime}/datarc-workspace-membership/SKILL.md +29 -29
- package/{skills → runtime}/datarc-workspace-membership/references/api.md +19 -19
- package/{skills → runtime}/datarc-workspace-modeling/SKILL.md +209 -209
- package/{skills → runtime}/datarc-workspace-modeling/agents/openai.yaml +4 -4
- package/{skills → runtime}/datarc-workspace-modeling/references/join-preview.md +38 -38
- package/{skills → runtime}/datarc-workspace-modeling/references/model-plan.md +300 -300
- package/{skills → runtime}/datarc-workspace-modeling/references/model-tags.md +95 -95
- package/{skills → runtime}/datarc-workspace-modeling/references/modeling-contract.json +29 -29
- package/{skills → runtime}/datarc-workspace-modeling/references/modeling-fixtures.json +2423 -2423
- package/{skills → runtime}/datarc-workspace-modeling/scripts/datarc-client.mjs +137 -137
- package/{skills → runtime}/datarc-workspace-modeling/scripts/workspace-model-tags.mjs +238 -238
- package/{skills → runtime}/datarc-workspace-modeling/scripts/workspace-modeling.mjs +1261 -1261
- package/skills-provider.js +51 -0
- package/workflow-index.json +434 -0
- package/icon.svg +0 -4
- package/skills/datarc-report-add-card/scripts/datarc-client.mjs +0 -464
- package/skills-index.json +0 -194
|
@@ -1,662 +1,722 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { resolveCredentials } from "../../datarc-oauth/scripts/credentials.mjs";
|
|
3
|
-
import { createHash } from "node:crypto";
|
|
4
|
-
import { spawn } from "node:child_process";
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
[
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
);
|
|
47
|
-
ensure(
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
"
|
|
54
|
-
);
|
|
55
|
-
ensure(
|
|
56
|
-
Array.isArray(plan.
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
"
|
|
62
|
-
);
|
|
63
|
-
ensure(
|
|
64
|
-
plan.
|
|
65
|
-
"
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
);
|
|
84
|
-
ensure(
|
|
85
|
-
|
|
86
|
-
"
|
|
87
|
-
);
|
|
88
|
-
ensure(
|
|
89
|
-
|
|
90
|
-
"
|
|
91
|
-
);
|
|
92
|
-
ensure(
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
"
|
|
108
|
-
);
|
|
109
|
-
ensure(
|
|
110
|
-
|
|
111
|
-
"
|
|
112
|
-
);
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
if (
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
const
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
);
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
(
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
.
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
return value;
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
.
|
|
564
|
-
|
|
565
|
-
.
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
return
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
return
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
.
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
[
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
return
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
}
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { resolveCredentials } from "../../datarc-oauth/scripts/credentials.mjs";
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
import { spawn } from "node:child_process";
|
|
5
|
+
import {
|
|
6
|
+
readFile,
|
|
7
|
+
writeFile,
|
|
8
|
+
mkdir,
|
|
9
|
+
rename,
|
|
10
|
+
mkdtemp,
|
|
11
|
+
open,
|
|
12
|
+
rm,
|
|
13
|
+
} from "node:fs/promises";
|
|
14
|
+
import { resolve, join, dirname, basename } from "node:path";
|
|
15
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
16
|
+
import { isDeepStrictEqual } from "node:util";
|
|
17
|
+
|
|
18
|
+
const HELP = `configuration.mjs plan --input draft.json --output <new-directory>
|
|
19
|
+
configuration.mjs verify --plan <plan.json> --confirm <planHash> --output <new-directory>
|
|
20
|
+
plan generates plan.json and plan.md without network access.
|
|
21
|
+
verify runs approved query cases, then writes acceptance.json/md and evidence.
|
|
22
|
+
It does not modify workspace configuration or certify configuration readback.`;
|
|
23
|
+
const executors = {
|
|
24
|
+
"data-search": ["datarc-data-search", "data-search.mjs", "search"],
|
|
25
|
+
"dataseek-search": ["datarc-dataseek-search", "dataseek-search.mjs", "ask"],
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export function digest(value) {
|
|
29
|
+
return createHash("sha256")
|
|
30
|
+
.update(JSON.stringify(canonical(value)))
|
|
31
|
+
.digest("hex");
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function validatePlan(plan) {
|
|
35
|
+
ensure(
|
|
36
|
+
plan?.schemaVersion === 1,
|
|
37
|
+
"方案版本无效;请按 schemaVersion=1 重新生成",
|
|
38
|
+
);
|
|
39
|
+
for (const key of ["taskId", "goal", "identity", "timeRange"])
|
|
40
|
+
ensure(text(plan[key]), `缺少 ${key};请补齐方案后重试`);
|
|
41
|
+
ensure(
|
|
42
|
+
Number.isSafeInteger(plan.workspaceId) && plan.workspaceId > 0,
|
|
43
|
+
"工作区 ID 无效;请先唯一定位工作区",
|
|
44
|
+
);
|
|
45
|
+
ensure(typeof plan.endpoint === "string", "缺少服务地址;请补齐 endpoint");
|
|
46
|
+
const url = new URL(plan.endpoint);
|
|
47
|
+
ensure(
|
|
48
|
+
["http:", "https:"].includes(url.protocol) &&
|
|
49
|
+
!url.username &&
|
|
50
|
+
!url.password &&
|
|
51
|
+
!url.search &&
|
|
52
|
+
!url.hash,
|
|
53
|
+
"服务地址不应包含凭据、查询或片段;请填写干净的服务入口",
|
|
54
|
+
);
|
|
55
|
+
ensure(
|
|
56
|
+
Array.isArray(plan.changes) &&
|
|
57
|
+
plan.changes.length > 0 &&
|
|
58
|
+
plan.changes.every(
|
|
59
|
+
(c) => text(c.target) && text(c.change) && text(c.impact),
|
|
60
|
+
),
|
|
61
|
+
"请为每项变更填写 target、change 和 impact",
|
|
62
|
+
);
|
|
63
|
+
ensure(
|
|
64
|
+
Array.isArray(plan.questions) && plan.questions.every(text),
|
|
65
|
+
"questions 应为待澄清问题列表;无问题时填写空数组",
|
|
66
|
+
);
|
|
67
|
+
ensure(
|
|
68
|
+
Array.isArray(plan.cases) && plan.cases.length <= 20,
|
|
69
|
+
"cases 应为最多 20 个验收问题;请缩小本次范围",
|
|
70
|
+
);
|
|
71
|
+
ensure(
|
|
72
|
+
plan.cases.length || text(plan.noQueryReason),
|
|
73
|
+
"无查询用例时请填写 noQueryReason,说明为何只需配置回读",
|
|
74
|
+
);
|
|
75
|
+
const ids = new Set();
|
|
76
|
+
for (const c of plan.cases) {
|
|
77
|
+
ensure(
|
|
78
|
+
text(c.id) &&
|
|
79
|
+
/^[a-zA-Z0-9_-]+$/.test(c.id) &&
|
|
80
|
+
!ids.has(c.id.toLowerCase()),
|
|
81
|
+
"验收编号无效或重复(忽略大小写);请使用字母、数字、下划线或短横线,并修改冲突编号,不能仅改变大小写",
|
|
82
|
+
);
|
|
83
|
+
ids.add(c.id.toLowerCase());
|
|
84
|
+
ensure(
|
|
85
|
+
text(c.question) && !c.question.startsWith("--"),
|
|
86
|
+
"验收问题为空或格式无效;请填写原始业务问题",
|
|
87
|
+
);
|
|
88
|
+
ensure(
|
|
89
|
+
Object.hasOwn(executors, c.executor),
|
|
90
|
+
"验收执行器不支持;请选择 data-search 或 dataseek-search",
|
|
91
|
+
);
|
|
92
|
+
ensure(
|
|
93
|
+
typeof c.required === "boolean" && typeof c.reviewRequired === "boolean",
|
|
94
|
+
"请明确 required 和 reviewRequired 布尔值",
|
|
95
|
+
);
|
|
96
|
+
ensure(
|
|
97
|
+
c.executor !== "dataseek-search" || c.reviewRequired,
|
|
98
|
+
"DataSeek 原问题需核对理解及范围;请设置 reviewRequired=true",
|
|
99
|
+
);
|
|
100
|
+
ensure(
|
|
101
|
+
Array.isArray(c.modelUids) &&
|
|
102
|
+
c.modelUids.every(
|
|
103
|
+
(v) =>
|
|
104
|
+
typeof v === "string" &&
|
|
105
|
+
/^(?:[a-f0-9]{32}|[a-f0-9-]{36})$/i.test(v),
|
|
106
|
+
),
|
|
107
|
+
"modelUids 无效;请填写实际模型 UID 列表,无限定时为空",
|
|
108
|
+
);
|
|
109
|
+
ensure(
|
|
110
|
+
c.executor !== "dataseek-search" || !c.modelUids.length,
|
|
111
|
+
"DataSeek 入口不支持强制模型参数;请在问题和人工复核中核对范围,勿伪造模型限制",
|
|
112
|
+
);
|
|
113
|
+
ensure(
|
|
114
|
+
Array.isArray(c.assertions),
|
|
115
|
+
"assertions 应为列表;缺少可靠预期时填写空数组,结果将待确认",
|
|
116
|
+
);
|
|
117
|
+
ensure(
|
|
118
|
+
!c.assertions.length || text(c.expectedSource),
|
|
119
|
+
"请说明预期依据 expectedSource,不能使用本次查询结果自证正确",
|
|
120
|
+
);
|
|
121
|
+
for (const a of c.assertions) {
|
|
122
|
+
ensure(
|
|
123
|
+
typeof a.pointer === "string" &&
|
|
124
|
+
/^\/(?:[^~]|~[01])*$/.test(a.pointer) &&
|
|
125
|
+
/^\/data\/.*\/previews\/\d+\/data(?:\/|$)/.test(a.pointer),
|
|
126
|
+
"断言路径应为预览业务数据的 JSON Pointer;请定位 previews 中的 data,不能只检查技术成功字段",
|
|
127
|
+
);
|
|
128
|
+
ensure(Object.hasOwn(a, "equals"), "缺少 equals 预期值;请补充可信基准");
|
|
129
|
+
if (a.tolerance !== undefined)
|
|
130
|
+
ensure(
|
|
131
|
+
typeof a.equals === "number" &&
|
|
132
|
+
Number.isFinite(a.equals) &&
|
|
133
|
+
Number.isFinite(a.tolerance) &&
|
|
134
|
+
a.tolerance >= 0,
|
|
135
|
+
"数值容差无效;请填写非负有限数值",
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return plan;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export async function generatePlan(draft, output) {
|
|
143
|
+
validatePlan(draft);
|
|
144
|
+
ensure(
|
|
145
|
+
!Object.hasOwn(draft, "planHash"),
|
|
146
|
+
"输入已含 planHash;请从原始草案生成新版本,不要手工覆盖摘要",
|
|
147
|
+
);
|
|
148
|
+
const sealed = { ...draft, planHash: digest(draft) };
|
|
149
|
+
await mkdir(output, { recursive: false, mode: 0o700 });
|
|
150
|
+
await save(join(output, "plan.json"), sealed);
|
|
151
|
+
await writeFile(join(output, "plan.md"), renderPlan(sealed), {
|
|
152
|
+
flag: "wx",
|
|
153
|
+
mode: 0o600,
|
|
154
|
+
});
|
|
155
|
+
return {
|
|
156
|
+
planHash: sealed.planHash,
|
|
157
|
+
document: join(output, "plan.md"),
|
|
158
|
+
blocked: draft.questions.length > 0,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export function assess(c, raw) {
|
|
163
|
+
if (raw?.ok !== true)
|
|
164
|
+
return {
|
|
165
|
+
status: "error",
|
|
166
|
+
reason: raw?.error?.backgroundMayStillRun
|
|
167
|
+
? "本地等待已停止,后台查询可能仍在运行;请先核查任务状态,不要立即重复查询"
|
|
168
|
+
: "查询执行失败;请检查证据中的错误并处理后重试",
|
|
169
|
+
};
|
|
170
|
+
const health = queryHealth(c.executor, raw.data);
|
|
171
|
+
if (health) return health;
|
|
172
|
+
const comparisons = c.assertions.map((a) => {
|
|
173
|
+
const actual = pointer(raw, a.pointer);
|
|
174
|
+
const passed =
|
|
175
|
+
actual !== undefined &&
|
|
176
|
+
(a.tolerance === undefined
|
|
177
|
+
? isDeepStrictEqual(actual, a.equals)
|
|
178
|
+
: typeof actual === "number" &&
|
|
179
|
+
Number.isFinite(actual) &&
|
|
180
|
+
Math.abs(actual - a.equals) <= a.tolerance);
|
|
181
|
+
return {
|
|
182
|
+
pointer: a.pointer,
|
|
183
|
+
matched: passed,
|
|
184
|
+
missing: actual === undefined,
|
|
185
|
+
expected: a.equals,
|
|
186
|
+
...(actual === undefined ? {} : { actual }),
|
|
187
|
+
};
|
|
188
|
+
});
|
|
189
|
+
if (comparisons.some((a) => a.missing))
|
|
190
|
+
return {
|
|
191
|
+
status: "error",
|
|
192
|
+
reason: "证据字段缺失;请检查结果结构与方案路径,变更方案后重新确认",
|
|
193
|
+
comparisons,
|
|
194
|
+
};
|
|
195
|
+
if (comparisons.some((a) => !a.matched))
|
|
196
|
+
return {
|
|
197
|
+
status: "fail",
|
|
198
|
+
reason: "实际结果与方案预期不符;请核对业务口径和数据",
|
|
199
|
+
comparisons,
|
|
200
|
+
};
|
|
201
|
+
if (!comparisons.length || c.reviewRequired)
|
|
202
|
+
return {
|
|
203
|
+
status: "review",
|
|
204
|
+
reason: "查询已完成;请核对业务预期、理解和实际模型范围",
|
|
205
|
+
comparisons,
|
|
206
|
+
};
|
|
207
|
+
return {
|
|
208
|
+
status: "pass",
|
|
209
|
+
reason: "查询完整,所列断言符合预期;仅覆盖方案中的检查项",
|
|
210
|
+
comparisons,
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export async function verifyPlan(sealed, confirmation, output, options = {}) {
|
|
215
|
+
const { planHash, ...plan } = sealed;
|
|
216
|
+
validatePlan(plan);
|
|
217
|
+
ensure(
|
|
218
|
+
planHash === digest(plan) && confirmation === planHash,
|
|
219
|
+
"方案已变化或确认不匹配;请重新生成文档并确认当前版本",
|
|
220
|
+
);
|
|
221
|
+
ensure(!plan.questions.length, "方案仍有待澄清问题;请先补齐需求并重新确认");
|
|
222
|
+
const { endpoint, token } = resolveCredentials(options);
|
|
223
|
+
ensure(
|
|
224
|
+
normalizeEndpoint(endpoint) === normalizeEndpoint(plan.endpoint),
|
|
225
|
+
"当前服务与方案不一致;请核对 DATARC_ENDPOINT,不要切换到其他工作区执行",
|
|
226
|
+
);
|
|
227
|
+
if (!options.run && plan.cases.length)
|
|
228
|
+
ensure(token, "缺少 DATARC_TOKEN;请先按 datarc-oauth 完成认证");
|
|
229
|
+
await mkdir(output, { recursive: false, mode: 0o700 });
|
|
230
|
+
const run = options.run ?? runQuery;
|
|
231
|
+
const now = options.now ?? Date.now;
|
|
232
|
+
const deadline = now() + 30 * 60 * 1000;
|
|
233
|
+
const report = {
|
|
234
|
+
taskId: plan.taskId,
|
|
235
|
+
planHash,
|
|
236
|
+
workspaceId: plan.workspaceId,
|
|
237
|
+
endpoint: plan.endpoint,
|
|
238
|
+
identity: plan.identity,
|
|
239
|
+
identitySource: "caller-declared",
|
|
240
|
+
timeRange: plan.timeRange,
|
|
241
|
+
startedAt: new Date().toISOString(),
|
|
242
|
+
configurationStatus: "not_assessed",
|
|
243
|
+
userAcceptance: "pending",
|
|
244
|
+
results: [],
|
|
245
|
+
};
|
|
246
|
+
const persist = async () => {
|
|
247
|
+
report.counts = Object.fromEntries(
|
|
248
|
+
["pass", "fail", "error", "review", "not_run", "running"].map((s) => [
|
|
249
|
+
s,
|
|
250
|
+
report.results.filter((r) => r.status === s).length,
|
|
251
|
+
]),
|
|
252
|
+
);
|
|
253
|
+
const required = report.results.filter((r) => r.required);
|
|
254
|
+
report.status = !plan.cases.length
|
|
255
|
+
? "not_applicable"
|
|
256
|
+
: required.some((r) => ["fail", "error"].includes(r.status))
|
|
257
|
+
? "failed"
|
|
258
|
+
: required.some((r) => r.status !== "pass") ||
|
|
259
|
+
report.results.length !== plan.cases.length
|
|
260
|
+
? "incomplete"
|
|
261
|
+
: required.length
|
|
262
|
+
? "passed"
|
|
263
|
+
: "review";
|
|
264
|
+
// Always write JSON first so an interrupted render still leaves evidence.
|
|
265
|
+
await save(join(output, "acceptance.json"), report);
|
|
266
|
+
await writeFile(join(output, "acceptance.md"), renderReport(plan, report), {
|
|
267
|
+
mode: 0o600,
|
|
268
|
+
});
|
|
269
|
+
};
|
|
270
|
+
report.results = plan.cases.map((c) => ({
|
|
271
|
+
id: c.id,
|
|
272
|
+
question: c.question,
|
|
273
|
+
required: c.required,
|
|
274
|
+
status: "not_run",
|
|
275
|
+
reason: "尚未运行;请检查执行记录",
|
|
276
|
+
}));
|
|
277
|
+
await persist();
|
|
278
|
+
for (const [index, c] of plan.cases.entries()) {
|
|
279
|
+
if (now() >= deadline) {
|
|
280
|
+
report.results[index].reason =
|
|
281
|
+
"总时限已到;请检查已完成结果,再决定是否重新验收";
|
|
282
|
+
continue;
|
|
283
|
+
}
|
|
284
|
+
let raw;
|
|
285
|
+
report.results[index] = {
|
|
286
|
+
...report.results[index],
|
|
287
|
+
status: "running",
|
|
288
|
+
reason: "查询执行中;若进程已中断,后台可能仍在运行,请先核查任务再补跑",
|
|
289
|
+
};
|
|
290
|
+
await persist();
|
|
291
|
+
try {
|
|
292
|
+
raw = await run(plan, c, Math.min(300000, deadline - now()));
|
|
293
|
+
} catch {
|
|
294
|
+
raw = {
|
|
295
|
+
ok: false,
|
|
296
|
+
error: {
|
|
297
|
+
code: "RUNNER_ERROR",
|
|
298
|
+
stopRun: true,
|
|
299
|
+
backgroundMayStillRun: true,
|
|
300
|
+
message: "查询进程异常;请核对依赖、网络与后台任务后重试",
|
|
301
|
+
},
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
raw = sanitizeErrors(raw, token, true);
|
|
305
|
+
const file = `${c.id}.evidence.json`;
|
|
306
|
+
const evidence = {
|
|
307
|
+
taskId: plan.taskId,
|
|
308
|
+
planHash,
|
|
309
|
+
caseId: c.id,
|
|
310
|
+
workspaceId: plan.workspaceId,
|
|
311
|
+
executor: c.executor,
|
|
312
|
+
question: c.question,
|
|
313
|
+
executedAt: new Date().toISOString(),
|
|
314
|
+
raw,
|
|
315
|
+
};
|
|
316
|
+
await save(join(output, file), evidence);
|
|
317
|
+
report.results[index] = {
|
|
318
|
+
...report.results[index],
|
|
319
|
+
...assess(c, raw),
|
|
320
|
+
evidence: file,
|
|
321
|
+
evidenceHash: digest(evidence),
|
|
322
|
+
};
|
|
323
|
+
await persist();
|
|
324
|
+
if (raw?.error?.stopRun) break;
|
|
325
|
+
}
|
|
326
|
+
await persist();
|
|
327
|
+
return {
|
|
328
|
+
status: report.status,
|
|
329
|
+
counts: report.counts,
|
|
330
|
+
document: join(output, "acceptance.md"),
|
|
331
|
+
configurationStatus: report.configurationStatus,
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
export async function runQuery(plan, c, timeoutMs) {
|
|
336
|
+
const { token } = resolveCredentials();
|
|
337
|
+
const [folder, script, command] = executors[c.executor];
|
|
338
|
+
const scriptPath = fileURLToPath(
|
|
339
|
+
new URL(`../../${folder}/scripts/${script}`, import.meta.url),
|
|
340
|
+
);
|
|
341
|
+
const args = [
|
|
342
|
+
scriptPath,
|
|
343
|
+
command,
|
|
344
|
+
"--workspace-id",
|
|
345
|
+
String(plan.workspaceId),
|
|
346
|
+
"--question",
|
|
347
|
+
c.question,
|
|
348
|
+
"--max-wait-ms",
|
|
349
|
+
String(timeoutMs),
|
|
350
|
+
];
|
|
351
|
+
for (const uid of c.modelUids) args.push("--model-uid", uid);
|
|
352
|
+
const parent = resolve(process.cwd());
|
|
353
|
+
const directory = await mkdtemp(join(parent, ".datarc-query-"));
|
|
354
|
+
const output = join(directory, "stdout.json"),
|
|
355
|
+
maximum = 8 * 1024 * 1024;
|
|
356
|
+
let stdout;
|
|
357
|
+
try {
|
|
358
|
+
stdout = await open(output, "wx", 0o600);
|
|
359
|
+
return await new Promise((resolveResult) => {
|
|
360
|
+
let child;
|
|
361
|
+
try {
|
|
362
|
+
child = spawn(process.execPath, args, {
|
|
363
|
+
shell: false,
|
|
364
|
+
windowsHide: true,
|
|
365
|
+
env: {
|
|
366
|
+
...process.env,
|
|
367
|
+
DATARC_ENDPOINT: normalizeEndpoint(plan.endpoint),
|
|
368
|
+
DATARC_TOKEN: token,
|
|
369
|
+
},
|
|
370
|
+
stdio: ["ignore", stdout.fd, "ignore"],
|
|
371
|
+
});
|
|
372
|
+
} catch {
|
|
373
|
+
resolveResult({
|
|
374
|
+
ok: false,
|
|
375
|
+
error: {
|
|
376
|
+
code: "START_FAILED",
|
|
377
|
+
stopRun: true,
|
|
378
|
+
message: "查询进程未能启动,请检查运行依赖和当前目录权限后重试",
|
|
379
|
+
},
|
|
380
|
+
});
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
let stopped,
|
|
384
|
+
startupError,
|
|
385
|
+
finished = false;
|
|
386
|
+
const stop = (code) => {
|
|
387
|
+
if (finished) return;
|
|
388
|
+
stopped ??= code;
|
|
389
|
+
child.kill();
|
|
390
|
+
};
|
|
391
|
+
const cancel = () => stop("CANCELLED");
|
|
392
|
+
process.once("SIGINT", cancel);
|
|
393
|
+
process.once("SIGTERM", cancel);
|
|
394
|
+
const timer = setTimeout(() => stop("TIMEOUT"), timeoutMs);
|
|
395
|
+
const monitor = setInterval(() => {
|
|
396
|
+
void stdout
|
|
397
|
+
.stat()
|
|
398
|
+
.then((info) => {
|
|
399
|
+
if (info.size > maximum) stop("OUTPUT_LIMIT");
|
|
400
|
+
})
|
|
401
|
+
.catch(() => stop("OUTPUT_READ_FAILED"));
|
|
402
|
+
}, 50);
|
|
403
|
+
const cleanup = () => {
|
|
404
|
+
finished = true;
|
|
405
|
+
clearTimeout(timer);
|
|
406
|
+
clearInterval(monitor);
|
|
407
|
+
process.removeListener("SIGINT", cancel);
|
|
408
|
+
process.removeListener("SIGTERM", cancel);
|
|
409
|
+
};
|
|
410
|
+
child.once("error", () => {
|
|
411
|
+
startupError = true;
|
|
412
|
+
});
|
|
413
|
+
child.once("close", async (code) => {
|
|
414
|
+
cleanup();
|
|
415
|
+
if (startupError) {
|
|
416
|
+
resolveResult({
|
|
417
|
+
ok: false,
|
|
418
|
+
error: {
|
|
419
|
+
code: "START_FAILED",
|
|
420
|
+
stopRun: true,
|
|
421
|
+
message: "查询进程未能启动,请检查运行依赖后重试",
|
|
422
|
+
},
|
|
423
|
+
});
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
try {
|
|
427
|
+
if ((await stdout.stat()).size > maximum) stopped ??= "OUTPUT_LIMIT";
|
|
428
|
+
if (stopped) {
|
|
429
|
+
resolveResult({
|
|
430
|
+
ok: false,
|
|
431
|
+
error: {
|
|
432
|
+
code: stopped,
|
|
433
|
+
stopRun: true,
|
|
434
|
+
backgroundMayStillRun: true,
|
|
435
|
+
message:
|
|
436
|
+
"本地等待已停止,后台任务可能仍在运行;请核查后再发起查询",
|
|
437
|
+
},
|
|
438
|
+
});
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
const bytes = await readFile(output);
|
|
442
|
+
if (bytes.length > maximum) {
|
|
443
|
+
resolveResult({
|
|
444
|
+
ok: false,
|
|
445
|
+
error: {
|
|
446
|
+
code: "OUTPUT_LIMIT",
|
|
447
|
+
stopRun: true,
|
|
448
|
+
message: "查询输出超过原8MiB上限,请缩小查询范围后重新验收",
|
|
449
|
+
},
|
|
450
|
+
});
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
const raw = JSON.parse(bytes.toString("utf8").replace(/^\uFEFF/, ""));
|
|
454
|
+
if (code !== 0 || raw?.ok !== true) {
|
|
455
|
+
resolveResult({
|
|
456
|
+
ok: false,
|
|
457
|
+
error: {
|
|
458
|
+
code: "QUERY_FAILED",
|
|
459
|
+
message: "查询失败;请检查诊断证据中的原因并处理后重试",
|
|
460
|
+
...safeDiagnostic(
|
|
461
|
+
raw?.error && typeof raw.error === "object"
|
|
462
|
+
? raw.error
|
|
463
|
+
: {
|
|
464
|
+
message:
|
|
465
|
+
raw?.error ??
|
|
466
|
+
"查询进程异常退出;请核对依赖和服务状态",
|
|
467
|
+
},
|
|
468
|
+
token,
|
|
469
|
+
),
|
|
470
|
+
stopRun: true,
|
|
471
|
+
exitCode: code,
|
|
472
|
+
},
|
|
473
|
+
});
|
|
474
|
+
return;
|
|
475
|
+
}
|
|
476
|
+
resolveResult(raw);
|
|
477
|
+
} catch {
|
|
478
|
+
resolveResult({
|
|
479
|
+
ok: false,
|
|
480
|
+
error: {
|
|
481
|
+
code: "INVALID_OUTPUT",
|
|
482
|
+
stopRun: true,
|
|
483
|
+
message: "查询未返回有效JSON,请检查搜索技能依赖后重试",
|
|
484
|
+
},
|
|
485
|
+
});
|
|
486
|
+
}
|
|
487
|
+
});
|
|
488
|
+
});
|
|
489
|
+
} finally {
|
|
490
|
+
await stdout?.close();
|
|
491
|
+
if (
|
|
492
|
+
dirname(directory) !== parent ||
|
|
493
|
+
!basename(directory).startsWith(".datarc-query-")
|
|
494
|
+
)
|
|
495
|
+
throw new Error("查询临时目录身份异常,请保留现场核对,不清理未知路径");
|
|
496
|
+
await rm(directory, { recursive: true, force: true });
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
function queryHealth(executor, data) {
|
|
501
|
+
const invalid = {
|
|
502
|
+
status: "error",
|
|
503
|
+
reason: "查询包含失败、未执行分支或无数据卡;请检查完整结果后再验收",
|
|
504
|
+
};
|
|
505
|
+
const validResults = (results) =>
|
|
506
|
+
Array.isArray(results) &&
|
|
507
|
+
results.length > 0 &&
|
|
508
|
+
results.every(
|
|
509
|
+
(r) =>
|
|
510
|
+
r &&
|
|
511
|
+
!r.error &&
|
|
512
|
+
Array.isArray(r.previews) &&
|
|
513
|
+
r.previews.length > 0 &&
|
|
514
|
+
r.previews.every((p) => p && !p.error && Object.hasOwn(p, "data")),
|
|
515
|
+
);
|
|
516
|
+
if (executor === "data-search")
|
|
517
|
+
return ["success", "empty"].includes(data?.status) &&
|
|
518
|
+
validResults(data.results) &&
|
|
519
|
+
data.results.every((r) => ["success", "empty"].includes(r.status))
|
|
520
|
+
? null
|
|
521
|
+
: invalid;
|
|
522
|
+
const actionsValid = (actions) =>
|
|
523
|
+
Array.isArray(actions) &&
|
|
524
|
+
actions.length > 0 &&
|
|
525
|
+
actions.every((a) => {
|
|
526
|
+
if (!a || a.error) return false;
|
|
527
|
+
if (["answer", "search"].includes(a.type)) return validResults(a.results);
|
|
528
|
+
const children =
|
|
529
|
+
a.type === "parallel"
|
|
530
|
+
? a.children
|
|
531
|
+
: a.type === "chained"
|
|
532
|
+
? a.steps
|
|
533
|
+
: null;
|
|
534
|
+
return (
|
|
535
|
+
Array.isArray(children) &&
|
|
536
|
+
children.length > 0 &&
|
|
537
|
+
children.every(
|
|
538
|
+
(child) => child && !child.error && actionsValid(child.actions),
|
|
539
|
+
)
|
|
540
|
+
);
|
|
541
|
+
});
|
|
542
|
+
return actionsValid(data?.actions) ? null : invalid;
|
|
543
|
+
}
|
|
544
|
+
function sanitizeErrors(value, token, envelope = false) {
|
|
545
|
+
if (Array.isArray(value))
|
|
546
|
+
return value.map((item) => sanitizeErrors(item, token));
|
|
547
|
+
if (!value || typeof value !== "object") return value;
|
|
548
|
+
return Object.fromEntries(
|
|
549
|
+
Object.entries(value).map(([key, item]) => [
|
|
550
|
+
key,
|
|
551
|
+
key === "error"
|
|
552
|
+
? safeDiagnostic(item, token)
|
|
553
|
+
: // Only the CLI envelope's data contains query structure. Nested data
|
|
554
|
+
// fields are business payloads (including preview rows), not diagnostics.
|
|
555
|
+
key === "data" && !envelope
|
|
556
|
+
? item
|
|
557
|
+
: sanitizeErrors(item, token),
|
|
558
|
+
]),
|
|
559
|
+
);
|
|
560
|
+
}
|
|
561
|
+
function safeDiagnostic(value, token) {
|
|
562
|
+
if (Array.isArray(value))
|
|
563
|
+
return value.map((item) => safeDiagnostic(item, token));
|
|
564
|
+
if (value && typeof value === "object")
|
|
565
|
+
return Object.fromEntries(
|
|
566
|
+
Object.entries(value).map(([key, item]) => [
|
|
567
|
+
key,
|
|
568
|
+
/^(?:password|passwd|pwd|token|access[_-]?token|refresh[_-]?token|authorization|cookie|set-cookie|secret|api[_-]?key|sql|prompt|databaseurl|connectionstring)$/i.test(
|
|
569
|
+
key,
|
|
570
|
+
)
|
|
571
|
+
? "***"
|
|
572
|
+
: safeDiagnostic(item, token),
|
|
573
|
+
]),
|
|
574
|
+
);
|
|
575
|
+
if (typeof value !== "string") return value;
|
|
576
|
+
return (token ? value.replaceAll(token, "***") : value)
|
|
577
|
+
.replace(/:\/\/[^\s/@]+:[^\s/@]+@/g, "://***@")
|
|
578
|
+
.replace(/\b(Bearer|Basic)\s+[A-Za-z0-9._~+\/-]+=*/gi, "$1 ***")
|
|
579
|
+
.replace(
|
|
580
|
+
/((?:password|passwd|pwd|token|authorization|secret|api[_-]?key)\s*[:=]\s*)(?:"[^"]*"|'[^']*'|[^\s,;]+)/gi,
|
|
581
|
+
"$1***",
|
|
582
|
+
);
|
|
583
|
+
}
|
|
584
|
+
function canonical(value) {
|
|
585
|
+
if (Array.isArray(value)) return value.map(canonical);
|
|
586
|
+
if (value && typeof value === "object")
|
|
587
|
+
return Object.fromEntries(
|
|
588
|
+
Object.keys(value)
|
|
589
|
+
.sort()
|
|
590
|
+
.map((k) => [k, canonical(value[k])]),
|
|
591
|
+
);
|
|
592
|
+
return value;
|
|
593
|
+
}
|
|
594
|
+
function pointer(value, path) {
|
|
595
|
+
for (const key of path
|
|
596
|
+
.slice(1)
|
|
597
|
+
.split("/")
|
|
598
|
+
.map((k) => k.replaceAll("~1", "/").replaceAll("~0", "~"))) {
|
|
599
|
+
if (
|
|
600
|
+
value === null ||
|
|
601
|
+
typeof value !== "object" ||
|
|
602
|
+
!Object.hasOwn(value, key)
|
|
603
|
+
)
|
|
604
|
+
return undefined;
|
|
605
|
+
value = value[key];
|
|
606
|
+
}
|
|
607
|
+
return value;
|
|
608
|
+
}
|
|
609
|
+
function text(value) {
|
|
610
|
+
return typeof value === "string" && value.trim().length > 0;
|
|
611
|
+
}
|
|
612
|
+
function ensure(condition, message) {
|
|
613
|
+
if (!condition) throw new Error(message);
|
|
614
|
+
}
|
|
615
|
+
function normalizeEndpoint(value) {
|
|
616
|
+
return String(value ?? "")
|
|
617
|
+
.split("#", 1)[0]
|
|
618
|
+
.replace(/\/+$/, "");
|
|
619
|
+
}
|
|
620
|
+
function md(value) {
|
|
621
|
+
return String(value ?? "")
|
|
622
|
+
.replaceAll("&", "&")
|
|
623
|
+
.replaceAll("<", "<")
|
|
624
|
+
.replaceAll(">", ">")
|
|
625
|
+
.replace(/[\\`*_{}\[\]()#!|]/g, "\\$&")
|
|
626
|
+
.replace(/[\r\n]+/g, " ");
|
|
627
|
+
}
|
|
628
|
+
async function save(path, value) {
|
|
629
|
+
const temporary = path + ".tmp";
|
|
630
|
+
await writeFile(temporary, JSON.stringify(value, null, 2) + "\n", {
|
|
631
|
+
mode: 0o600,
|
|
632
|
+
});
|
|
633
|
+
await rename(temporary, path);
|
|
634
|
+
}
|
|
635
|
+
function renderPlan(p) {
|
|
636
|
+
return `# 配置方案:${md(p.goal)}\n\n工作区:${p.workspaceId}|服务:${md(p.endpoint)}\n\n任务:${md(p.taskId)}|方案指纹:${p.planHash}\n\n验证身份(声明):${md(p.identity)}|时间口径:${md(p.timeRange)}\n\n## 计划变更\n\n${p.changes.map((c) => `- ${md(c.target)}:${md(c.change)};影响:${md(c.impact)}`).join("\n")}\n\n## 待澄清\n\n${p.questions.length ? p.questions.map((q) => `- ${md(q)}`).join("\n") : "无。复杂配置请确认本版本后执行;子技能专门确认门槛仍保留。"}\n\n## 验收计划\n\n${p.cases.map((c) => `### ${md(c.id)}:${md(c.question)}\n\n执行器:${c.executor};${c.required ? "必需" : "可选"};人工复核:${c.reviewRequired ? "需要" : "无需"};模型:${md(c.modelUids.join(", ") || "未强制限定")}\n\n预期依据:${md(c.expectedSource || "缺少可靠基准,待业务确认")}\n\n${c.assertions.map((a) => `- ${md(a.pointer)} = ${md(JSON.stringify(a.equals))}${a.tolerance === undefined ? "" : `,容差 ${a.tolerance}`}`).join("\n")}`).join("\n\n") || md(p.noQueryReason)}\n\n## 执行边界\n\n依赖和配置回读由对应业务技能执行;查询会创建会话、异步任务,链式问题可能创建临时数据集。本工具不修改配置、不提供备份恢复。发现未知写入结果或并发变化时停止,先核对现状。\n`;
|
|
637
|
+
}
|
|
638
|
+
function renderReport(p, r) {
|
|
639
|
+
const labels = {
|
|
640
|
+
passed: "必需查询检查通过",
|
|
641
|
+
failed: "未通过",
|
|
642
|
+
incomplete: "未完成",
|
|
643
|
+
not_applicable: "不适用",
|
|
644
|
+
pass: "通过",
|
|
645
|
+
fail: "不符合预期",
|
|
646
|
+
error: "执行报错",
|
|
647
|
+
review: "待业务复核",
|
|
648
|
+
not_run: "未运行",
|
|
649
|
+
running: "执行中",
|
|
650
|
+
};
|
|
651
|
+
const short = (value) => md(JSON.stringify(value)?.slice(0, 180) ?? "缺失");
|
|
652
|
+
return `# 配置查询验收报告\n\n查询验收:${labels[r.status]};配置保存与生效:本工具未核验;业务验收:待用户确认。\n\n工作区:${r.workspaceId}|身份(声明):${md(r.identity)}|时间:${md(r.timeRange)}\n\n方案指纹:${r.planHash}\n\n${Object.entries(
|
|
653
|
+
r.counts,
|
|
654
|
+
)
|
|
655
|
+
.map(([s, n]) => `${labels[s]}: ${n}`)
|
|
656
|
+
.join(
|
|
657
|
+
";",
|
|
658
|
+
)}\n\n## 逐项结果\n\n${r.results.map((x) => `- **${md(x.id)} / ${labels[x.status]}** ${md(x.question)}:${md(x.reason)}${x.evidence ? ` [证据](${x.evidence})` : ""}\n${(x.comparisons ?? []).map((a) => ` - ${md(a.pointer)}:预期 ${short(a.expected)};实际 ${short(a.actual)}。`).join("\n")}`).join("\n") || md(p.noQueryReason)}\n\n## 下一步\n\n请结合业务技能的配置回读与就绪结果交付;待复核项核对语义、模型和业务基准,失败项处理后重新验收,未运行项说明原因。长结果仅显示摘要,完整值见证据;预览不能证明全量唯一性或其他用户权限。报告不会自动确认业务验收。\n`;
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
export async function main(argv) {
|
|
662
|
+
if (!argv.length || argv.includes("--help")) return { help: HELP };
|
|
663
|
+
const [command, ...rest] = argv;
|
|
664
|
+
ensure(
|
|
665
|
+
["plan", "verify"].includes(command),
|
|
666
|
+
"未知命令;请运行 --help 查看用法",
|
|
667
|
+
);
|
|
668
|
+
const args = {};
|
|
669
|
+
const allowed =
|
|
670
|
+
command === "plan"
|
|
671
|
+
? ["--input", "--output"]
|
|
672
|
+
: ["--plan", "--confirm", "--output"];
|
|
673
|
+
for (let i = 0; i < rest.length; i += 2) {
|
|
674
|
+
ensure(
|
|
675
|
+
allowed.includes(rest[i]) &&
|
|
676
|
+
!Object.hasOwn(args, rest[i]) &&
|
|
677
|
+
text(rest[i + 1]) &&
|
|
678
|
+
!rest[i + 1].startsWith("--"),
|
|
679
|
+
"参数缺失、重复或未知;请运行 --help 核对",
|
|
680
|
+
);
|
|
681
|
+
args[rest[i]] = rest[i + 1];
|
|
682
|
+
}
|
|
683
|
+
ensure(
|
|
684
|
+
allowed.every((k) => text(args[k])),
|
|
685
|
+
"缺少必填参数;请运行 --help 核对",
|
|
686
|
+
);
|
|
687
|
+
const input = JSON.parse(
|
|
688
|
+
(
|
|
689
|
+
await readFile(
|
|
690
|
+
resolve(args[command === "plan" ? "--input" : "--plan"]),
|
|
691
|
+
"utf8",
|
|
692
|
+
)
|
|
693
|
+
).replace(/^\uFEFF/, ""),
|
|
694
|
+
);
|
|
695
|
+
const output = resolve(args["--output"]);
|
|
696
|
+
return command === "plan"
|
|
697
|
+
? generatePlan(input, output)
|
|
698
|
+
: verifyPlan(input, args["--confirm"], output);
|
|
699
|
+
}
|
|
700
|
+
if (
|
|
701
|
+
process.argv[1] &&
|
|
702
|
+
import.meta.url === pathToFileURL(resolve(process.argv[1])).href
|
|
703
|
+
) {
|
|
704
|
+
try {
|
|
705
|
+
process.stdout.write(
|
|
706
|
+
JSON.stringify({ ok: true, data: await main(process.argv.slice(2)) }) +
|
|
707
|
+
"\n",
|
|
708
|
+
);
|
|
709
|
+
} catch (error) {
|
|
710
|
+
process.stdout.write(
|
|
711
|
+
JSON.stringify({
|
|
712
|
+
ok: false,
|
|
713
|
+
error: {
|
|
714
|
+
message: error.message,
|
|
715
|
+
nextAction:
|
|
716
|
+
"检查输入及输出目录;输出目录必须是尚不存在的新目录,避免覆盖已有证据",
|
|
717
|
+
},
|
|
718
|
+
}) + "\n",
|
|
719
|
+
);
|
|
720
|
+
process.exitCode = 1;
|
|
721
|
+
}
|
|
722
|
+
}
|