@arcticdata/dsh-datarc-skills 0.0.0-stage → 26.39.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. package/README.md +20 -2
  2. package/cordis.patch.yml +4 -0
  3. package/icon.svg +4 -0
  4. package/index.js +35 -0
  5. package/locale/en.json +6 -0
  6. package/locale/zh.json +6 -0
  7. package/package.json +37 -4
  8. package/skills/datarc-access-permissions/SKILL.md +30 -0
  9. package/skills/datarc-access-permissions/references/api.md +31 -0
  10. package/skills/datarc-access-permissions/references/write-order.md +16 -0
  11. package/skills/datarc-analysis-report/SKILL.md +125 -0
  12. package/skills/datarc-analysis-report/agents/openai.yaml +6 -0
  13. package/skills/datarc-analysis-report/references/analyst-frameworks.md +215 -0
  14. package/skills/datarc-analysis-report/references/api-contracts.md +478 -0
  15. package/skills/datarc-analysis-report/references/direct-card-fallback-design.md +66 -0
  16. package/skills/datarc-analysis-report/references/human-in-the-loop.md +142 -0
  17. package/skills/datarc-analysis-report/references/loop-personalization-policy.md +138 -0
  18. package/skills/datarc-analysis-report/references/manifest-example.json +779 -0
  19. package/skills/datarc-analysis-report/references/narrative-schema.md +160 -0
  20. package/skills/datarc-analysis-report/references/question-syntax.md +151 -0
  21. package/skills/datarc-analysis-report/scripts/run_analysis_report.py +2225 -0
  22. package/skills/datarc-analysis-report/scripts/run_dataseek_cards.py +1914 -0
  23. package/skills/datarc-analysis-report/scripts/test_run_analysis_report.py +5295 -0
  24. package/skills/datarc-data-search/SKILL.md +243 -0
  25. package/skills/datarc-data-search/scripts/calculate.py +116 -0
  26. package/skills/datarc-data-search/scripts/data-search.mjs +628 -0
  27. package/skills/datarc-data-search/scripts/datarc-client.mjs +464 -0
  28. package/skills/datarc-data-search/scripts/search-result.mjs +211 -0
  29. package/skills/datarc-dataseek-batch-evaluation/SKILL.md +59 -0
  30. package/skills/datarc-dataseek-batch-evaluation/references/artifacts.md +36 -0
  31. package/skills/datarc-dataseek-batch-evaluation/references/equivalence.md +30 -0
  32. package/skills/datarc-dataseek-batch-evaluation/scripts/datarc-client.mjs +464 -0
  33. package/skills/datarc-dataseek-batch-evaluation/scripts/dataseek-batch-evaluation.mjs +1020 -0
  34. package/skills/datarc-dataseek-search/SKILL.md +96 -0
  35. package/skills/datarc-dataseek-search/scripts/datarc-client.mjs +464 -0
  36. package/skills/datarc-dataseek-search/scripts/dataseek-search.mjs +257 -0
  37. package/skills/datarc-dataseek-semantic-debugging/SKILL.md +44 -0
  38. package/skills/datarc-dataseek-semantic-debugging/agents/openai.yaml +4 -0
  39. package/skills/datarc-dataseek-semantic-debugging/evals/evals.json +165 -0
  40. package/skills/datarc-dataseek-semantic-debugging/references/dataset.md +77 -0
  41. package/skills/datarc-dataseek-semantic-debugging/references/input-and-resolution.md +93 -0
  42. package/skills/datarc-dataseek-semantic-debugging/references/interventions.md +64 -0
  43. package/skills/datarc-dataseek-semantic-debugging/references/knowledge-and-prompts.md +47 -0
  44. package/skills/datarc-dataseek-semantic-debugging/references/rollback.md +11 -0
  45. package/skills/datarc-dataseek-semantic-debugging/references/verification-and-rollback.md +95 -0
  46. package/skills/datarc-dataseek-semantic-debugging/scripts/semantic-debugging.mjs +29 -0
  47. package/skills/datarc-dataseek-testset-generation/SKILL.md +47 -0
  48. package/skills/datarc-dataseek-testset-generation/scripts/datarc-client.mjs +464 -0
  49. package/skills/datarc-dataseek-testset-generation/scripts/dataseek-testset-generation.mjs +526 -0
  50. package/skills/datarc-datasource/SKILL.md +97 -0
  51. package/skills/datarc-oauth/SKILL.md +47 -0
  52. package/skills/datarc-oauth/scripts/auth.mjs +130 -0
  53. package/skills/datarc-oauth/scripts/credentials.mjs +237 -0
  54. package/skills/datarc-report-add-card/SKILL.md +90 -0
  55. package/skills/datarc-report-add-card/agents/openai.yaml +4 -0
  56. package/skills/datarc-report-add-card/scripts/datarc-client.mjs +464 -0
  57. package/skills/datarc-report-add-card/scripts/report-card.mjs +439 -0
  58. package/skills/datarc-semantic-alias/SKILL.md +20 -0
  59. package/skills/datarc-semantic-alias/scripts/alias-plan.mjs +422 -0
  60. package/skills/datarc-semantic-alias/scripts/alias.mjs +11 -0
  61. package/skills/datarc-semantic-calibration/SKILL.md +20 -0
  62. package/skills/datarc-semantic-calibration/scripts/calibration-plan.mjs +683 -0
  63. package/skills/datarc-semantic-calibration/scripts/calibration.mjs +11 -0
  64. package/skills/datarc-semantic-core/SKILL.md +12 -0
  65. package/skills/datarc-semantic-core/scripts/artifact-journal.mjs +830 -0
  66. package/skills/datarc-semantic-core/scripts/canonical.mjs +48 -0
  67. package/skills/datarc-semantic-core/scripts/case-model.mjs +608 -0
  68. package/skills/datarc-semantic-core/scripts/cli.mjs +180 -0
  69. package/skills/datarc-semantic-core/scripts/datarc-client.mjs +180 -0
  70. package/skills/datarc-semantic-core/scripts/interpretation-pairs.mjs +57 -0
  71. package/skills/datarc-semantic-core/scripts/interventions.mjs +693 -0
  72. package/skills/datarc-semantic-core/scripts/live-resolution.mjs +305 -0
  73. package/skills/datarc-semantic-core/scripts/model-scope.mjs +49 -0
  74. package/skills/datarc-semantic-core/scripts/reproduction.mjs +330 -0
  75. package/skills/datarc-semantic-core/scripts/semantic-cli.mjs +740 -0
  76. package/skills/datarc-semantic-core/scripts/shared.mjs +312 -0
  77. package/skills/datarc-semantic-core/scripts/verification.mjs +1014 -0
  78. package/skills/datarc-semantic-dataset/SKILL.md +20 -0
  79. package/skills/datarc-semantic-dataset/scripts/dataset-plan.mjs +749 -0
  80. package/skills/datarc-semantic-dataset/scripts/dataset-preflight.mjs +813 -0
  81. package/skills/datarc-semantic-dataset/scripts/dataset.mjs +11 -0
  82. package/skills/datarc-semantic-knowledge/SKILL.md +38 -0
  83. package/skills/datarc-semantic-knowledge/references/knowledge-drafts.md +61 -0
  84. package/skills/datarc-semantic-knowledge/references/knowledge-generation.json +16 -0
  85. package/skills/datarc-semantic-knowledge/scripts/knowledge-draft.mjs +347 -0
  86. package/skills/datarc-semantic-knowledge/scripts/knowledge-plan.mjs +848 -0
  87. package/skills/datarc-semantic-knowledge/scripts/knowledge.mjs +31 -0
  88. package/skills/datarc-semantic-prompt/SKILL.md +20 -0
  89. package/skills/datarc-semantic-prompt/scripts/prompt-plan.mjs +447 -0
  90. package/skills/datarc-semantic-prompt/scripts/prompt.mjs +15 -0
  91. package/skills/datarc-semantic-synonym/SKILL.md +20 -0
  92. package/skills/datarc-semantic-synonym/scripts/synonym-plan.mjs +688 -0
  93. package/skills/datarc-semantic-synonym/scripts/synonym.mjs +11 -0
  94. package/skills/datarc-viz-analysis-report/SKILL.md +108 -0
  95. package/skills/datarc-viz-analysis-report/assets/LICENSE-echarts.md +8 -0
  96. package/skills/datarc-viz-analysis-report/assets/echarts.min.js +45 -0
  97. package/skills/datarc-viz-analysis-report/references/api-contracts.md +163 -0
  98. package/skills/datarc-viz-analysis-report/references/derivation-log.md +157 -0
  99. package/skills/datarc-viz-analysis-report/references/evidence-framework.md +76 -0
  100. package/skills/datarc-viz-analysis-report/references/html-template.md +92 -0
  101. package/skills/datarc-viz-analysis-report/references/provenance-format.md +56 -0
  102. package/skills/datarc-viz-analysis-report/references/question-syntax.md +151 -0
  103. package/skills/datarc-viz-analysis-report/scripts/render_viz_report.py +1708 -0
  104. package/skills/datarc-viz-analysis-report/scripts/test_render_viz_report.py +964 -0
  105. package/skills/datarc-workspace-configuration/SKILL.md +59 -0
  106. package/skills/datarc-workspace-configuration/references/artifacts.md +75 -0
  107. package/skills/datarc-workspace-configuration/references/verification.md +20 -0
  108. package/skills/datarc-workspace-configuration/scripts/configuration.mjs +662 -0
  109. package/skills/datarc-workspace-context/SKILL.md +43 -0
  110. package/skills/datarc-workspace-context/agents/openai.yaml +4 -0
  111. package/skills/datarc-workspace-context/scripts/datarc-client.mjs +31 -0
  112. package/skills/datarc-workspace-context/scripts/query-display.mjs +114 -0
  113. package/skills/datarc-workspace-context/scripts/workspace-context.mjs +58 -0
  114. package/skills/datarc-workspace-custom-tables/SKILL.md +89 -0
  115. package/skills/datarc-workspace-custom-tables/scripts/datarc-client.mjs +165 -0
  116. package/skills/datarc-workspace-custom-tables/scripts/workspace-custom-tables.mjs +601 -0
  117. package/skills/datarc-workspace-keywords/SKILL.md +197 -0
  118. package/skills/datarc-workspace-keywords/agents/openai.yaml +4 -0
  119. package/skills/datarc-workspace-keywords/references/api-fields.md +79 -0
  120. package/skills/datarc-workspace-keywords/references/derived-measures.md +177 -0
  121. package/skills/datarc-workspace-keywords/scripts/datarc-client.mjs +145 -0
  122. package/skills/datarc-workspace-keywords/scripts/workspace-keywords.mjs +2421 -0
  123. package/skills/datarc-workspace-membership/SKILL.md +29 -0
  124. package/skills/datarc-workspace-membership/references/api.md +19 -0
  125. package/skills/datarc-workspace-modeling/SKILL.md +209 -0
  126. package/skills/datarc-workspace-modeling/agents/openai.yaml +4 -0
  127. package/skills/datarc-workspace-modeling/references/join-preview.md +38 -0
  128. package/skills/datarc-workspace-modeling/references/model-plan.md +300 -0
  129. package/skills/datarc-workspace-modeling/references/model-tags.md +95 -0
  130. package/skills/datarc-workspace-modeling/references/modeling-contract.json +29 -0
  131. package/skills/datarc-workspace-modeling/references/modeling-fixtures.json +2423 -0
  132. package/skills/datarc-workspace-modeling/scripts/datarc-client.mjs +137 -0
  133. package/skills/datarc-workspace-modeling/scripts/workspace-model-tags.mjs +238 -0
  134. package/skills/datarc-workspace-modeling/scripts/workspace-modeling.mjs +1261 -0
  135. package/skills-index.json +194 -0
@@ -0,0 +1,422 @@
1
+ import {
2
+ canonicalJson,
3
+ hashArtifactValue as hashValue,
4
+ } from "../../datarc-semantic-core/scripts/canonical.mjs";
5
+ import {
6
+ authoritiesForCaseIds,
7
+ claimStepCaseIds,
8
+ fail,
9
+ isRecord,
10
+ listOf,
11
+ normalizeText,
12
+ READ_ONLY_FIELDS,
13
+ requiredText,
14
+ } from "../../datarc-semantic-core/scripts/shared.mjs";
15
+
16
+ export async function planAlias(client, plan, operation, planningEvidence) {
17
+ const { resourceKind } = operation;
18
+ if (!READ_ONLY_FIELDS[resourceKind])
19
+ fail("INVALID_ALIAS", "alias requires a dimension or measure resourceId");
20
+ const resourceId = canonicalAliasResourceId(operation.resourceId);
21
+ const aliases = listOf(operation.aliases).map((alias) =>
22
+ requiredText(alias, "alias"),
23
+ );
24
+ if (aliases.length === 0)
25
+ fail("INVALID_ALIAS", "alias requires at least one alias");
26
+ for (const alias of aliases) {
27
+ const explicitOwners = findCoalescedAliasOwners(
28
+ operation.aliasOwners,
29
+ alias,
30
+ );
31
+ const owners =
32
+ explicitOwners.length > 0
33
+ ? explicitOwners
34
+ : [findAliasOwner(planningEvidence, alias)].filter(Boolean);
35
+ for (const owner of owners)
36
+ if (
37
+ String(owner.resourceId ?? owner.id) !== String(resourceId) ||
38
+ (owner.resourceKind ?? owner.kind) !== resourceKind
39
+ )
40
+ fail(
41
+ "ALIAS_CONFLICT",
42
+ "the alias is already owned by another resource",
43
+ { owner },
44
+ );
45
+ }
46
+ const endpoint = aliasPath(plan.workspaceId, resourceKind, resourceId);
47
+ const before = cleanAlias(
48
+ await client.request("GET", endpoint),
49
+ resourceKind,
50
+ );
51
+ const names = Array.isArray(before.names) ? before.names : [];
52
+ const newAliases = aliases.filter(
53
+ (alias) =>
54
+ !names.some((name) => normalizeText(name) === normalizeText(alias)),
55
+ );
56
+ if (newAliases.length === 0) {
57
+ plan.summaries.push({
58
+ kind: "alias",
59
+ status: "noop",
60
+ resourceKind,
61
+ resourceId,
62
+ caseIds: structuredClone(operation.caseIds),
63
+ });
64
+ return;
65
+ }
66
+ const evidence = await validateAliasNames(
67
+ client,
68
+ plan.workspaceId,
69
+ resourceKind,
70
+ newAliases,
71
+ );
72
+ plan.steps.push({
73
+ kind: "alias",
74
+ caseIds: structuredClone(operation.caseIds),
75
+ endpoint,
76
+ operation: "PUT",
77
+ before,
78
+ after: { ...before, names: [...names, ...newAliases] },
79
+ preconditions: { nameValidation: evidence },
80
+ dictionarySyncRequired: true,
81
+ });
82
+ plan.summaries.push({
83
+ kind: "alias",
84
+ status: "planned",
85
+ resourceKind,
86
+ resourceId,
87
+ caseIds: structuredClone(operation.caseIds),
88
+ });
89
+ }
90
+
91
+ export function cleanAlias(value, resourceKind) {
92
+ const result = structuredClone(value ?? {});
93
+ for (const field of READ_ONLY_FIELDS[resourceKind]) delete result[field];
94
+ return result;
95
+ }
96
+
97
+ export function findAliasOwner(evidence, alias) {
98
+ return listOf(evidence?.aliasOwners).find(
99
+ (owner) => normalizeText(owner.alias) === normalizeText(alias),
100
+ );
101
+ }
102
+
103
+ export function findCoalescedAliasOwners(entries, alias) {
104
+ return listOf(entries)
105
+ .filter((entry) => normalizeText(entry.alias) === normalizeText(alias))
106
+ .map((entry) => entry.owner);
107
+ }
108
+
109
+ export async function validateAliasNames(client, workspaceId, field, names) {
110
+ const result = await client.request(
111
+ "POST",
112
+ `/api/v2/admin-projects/${workspaceId}/name-validation/`,
113
+ { body: { field, names: structuredClone(names) } },
114
+ );
115
+ if (result?.status !== "SUCCESS")
116
+ fail(
117
+ "ALIAS_NAME_VALIDATION_FAILED",
118
+ "alias name validation did not succeed",
119
+ { field, status: result?.status },
120
+ );
121
+ return {
122
+ field,
123
+ namesHash: hashValue(names),
124
+ status: "SUCCESS",
125
+ };
126
+ }
127
+
128
+ export async function revalidateAliasStep(client, workspaceId, step) {
129
+ const { field, names } = validateAliasStepStructure(step, workspaceId);
130
+ await validateAliasNames(client, workspaceId, field, names);
131
+ }
132
+
133
+ export function validateAliasStepStructure(step, workspaceId) {
134
+ const allowedStepFields = new Set([
135
+ "after",
136
+ "before",
137
+ "caseIds",
138
+ "dictionarySyncRequired",
139
+ "endpoint",
140
+ "kind",
141
+ "operation",
142
+ "preconditions",
143
+ ]);
144
+ if (
145
+ Object.keys(step).some((field) => !allowedStepFields.has(field)) ||
146
+ [...allowedStepFields].some((field) => !Object.hasOwn(step, field)) ||
147
+ step.kind !== "alias" ||
148
+ step.dictionarySyncRequired !== true
149
+ )
150
+ fail("INVALID_ALIAS_PLAN", "alias step fields are invalid");
151
+ const identity = aliasStepIdentity(step.endpoint, workspaceId);
152
+ if (step.operation !== "PUT")
153
+ fail("INVALID_ALIAS_PLAN", "alias steps must use PUT");
154
+ if (!isRecord(step.before) || !isRecord(step.after))
155
+ fail("INVALID_ALIAS_PLAN", "alias steps require object snapshots");
156
+ if (canonicalAliasResourceId(step.before.id) !== identity.resourceId)
157
+ fail("INVALID_ALIAS_PLAN", "alias endpoint does not match its resource");
158
+ if (!Array.isArray(step.after.names))
159
+ fail("INVALID_ALIAS_PLAN", "alias after.names must be an array");
160
+ if (step.before.names !== undefined && !Array.isArray(step.before.names))
161
+ fail("INVALID_ALIAS_PLAN", "alias before.names must be an array");
162
+
163
+ const beforeNames = listOf(step.before.names);
164
+ const afterNames = step.after.names;
165
+ if (
166
+ afterNames.length <= beforeNames.length ||
167
+ canonicalJson(afterNames.slice(0, beforeNames.length)) !==
168
+ canonicalJson(beforeNames)
169
+ )
170
+ fail(
171
+ "INVALID_ALIAS_PLAN",
172
+ "alias names must preserve the original ordered prefix",
173
+ );
174
+
175
+ const beforeBody = structuredClone(step.before);
176
+ const afterBody = structuredClone(step.after);
177
+ delete beforeBody.names;
178
+ delete afterBody.names;
179
+ if (canonicalJson(beforeBody) !== canonicalJson(afterBody))
180
+ fail("INVALID_ALIAS_PLAN", "alias steps may only append names");
181
+
182
+ const seenNames = new Set(beforeNames.map(normalizeText));
183
+ const names = afterNames.slice(beforeNames.length);
184
+ for (const name of names) {
185
+ if (
186
+ typeof name !== "string" ||
187
+ !name.trim() ||
188
+ name !== name.trim() ||
189
+ seenNames.has(normalizeText(name))
190
+ )
191
+ fail("INVALID_ALIAS_PLAN", "appended aliases must be unique names");
192
+ seenNames.add(normalizeText(name));
193
+ }
194
+
195
+ if (!Array.isArray(step.caseIds) || step.caseIds.length === 0)
196
+ fail("INVALID_ALIAS_PLAN", "alias steps require caseIds");
197
+ const caseIds = new Set();
198
+ for (const caseId of step.caseIds) {
199
+ if (
200
+ typeof caseId !== "string" ||
201
+ !caseId ||
202
+ caseId !== caseId.trim() ||
203
+ caseIds.has(caseId)
204
+ )
205
+ fail("INVALID_ALIAS_PLAN", "alias step caseIds are invalid");
206
+ caseIds.add(caseId);
207
+ }
208
+
209
+ if (
210
+ !isRecord(step.preconditions) ||
211
+ canonicalJson(Object.keys(step.preconditions).sort()) !==
212
+ canonicalJson(["nameValidation"])
213
+ )
214
+ fail(
215
+ "INVALID_ALIAS_VALIDATION_EVIDENCE",
216
+ "alias preconditions are invalid",
217
+ );
218
+ const evidence = step.preconditions.nameValidation;
219
+ if (
220
+ evidence?.field !== identity.field ||
221
+ evidence?.status !== "SUCCESS" ||
222
+ evidence?.namesHash !== hashValue(names)
223
+ )
224
+ fail(
225
+ "INVALID_ALIAS_VALIDATION_EVIDENCE",
226
+ "alias validation evidence does not match the planned names",
227
+ { field: identity.field },
228
+ );
229
+ return {
230
+ caseIds: [...caseIds],
231
+ field: identity.field,
232
+ names,
233
+ resourceId: identity.resourceId,
234
+ };
235
+ }
236
+
237
+ export function aliasStepIdentity(endpoint, workspaceId) {
238
+ const prefixes = [
239
+ ["dimension", `/api/v2/admin-projects/${workspaceId}/dimensions/`],
240
+ ["measure", `/api/v2/admin-projects/${workspaceId}/measures/`],
241
+ ];
242
+ for (const [field, prefix] of prefixes) {
243
+ if (typeof endpoint !== "string" || !endpoint.startsWith(prefix)) continue;
244
+ const suffix = endpoint.slice(prefix.length);
245
+ if (!suffix.endsWith("/") || suffix.slice(0, -1).includes("/")) break;
246
+ const resourceText = suffix.slice(0, -1);
247
+ const resourceId = canonicalAliasResourceId(resourceText);
248
+ if (resourceText !== String(resourceId))
249
+ fail("INVALID_ALIAS_PLAN", "alias endpoint resourceId is not canonical");
250
+ return { field, resourceId };
251
+ }
252
+ fail("INVALID_ALIAS_PLAN", "alias endpoint is invalid for the workspace");
253
+ }
254
+
255
+ export function canonicalAliasResourceId(value) {
256
+ const text = typeof value === "string" ? value.trim() : value;
257
+ if (!(
258
+ (typeof text === "number" && Number.isSafeInteger(text)) ||
259
+ (typeof text === "string" && /^\d+$/.test(text))
260
+ ))
261
+ fail("INVALID_ALIAS", "alias resourceId must be a positive integer");
262
+ const resourceId = Number(text);
263
+ if (!Number.isSafeInteger(resourceId) || resourceId <= 0)
264
+ fail("INVALID_ALIAS", "alias resourceId must be a positive integer");
265
+ return resourceId;
266
+ }
267
+
268
+ export function aliasPath(workspaceId, resourceKind, resourceId) {
269
+ return `/api/v2/admin-projects/${workspaceId}/${
270
+ resourceKind === "measure" ? "measures" : "dimensions"
271
+ }/${resourceId}/`;
272
+ }
273
+
274
+ function aliasAuthorityTarget(operation) {
275
+ if (!READ_ONLY_FIELDS[operation.resourceKind])
276
+ fail("INVALID_ALIAS", "alias requires a dimension or measure resourceId");
277
+ return {
278
+ alias: requiredText(operation.alias, "alias"),
279
+ resourceId: canonicalAliasResourceId(operation.resourceId),
280
+ resourceKind: operation.resourceKind,
281
+ };
282
+ }
283
+
284
+ function createAliasCoalescer() {
285
+ const groups = new Map();
286
+ const targets = new Map();
287
+ return {
288
+ add(operation, result) {
289
+ const caseId = operation.caseId.trim();
290
+ const { resourceKind } = operation;
291
+ if (!READ_ONLY_FIELDS[resourceKind])
292
+ fail("INVALID_ALIAS", "alias requires a dimension or measure resourceId");
293
+ const resourceId = canonicalAliasResourceId(operation.resourceId);
294
+ const alias = requiredText(operation.alias, "alias");
295
+ const targetKey = `alias:${resourceKind}:${resourceId}`;
296
+ const aliasKey = normalizeText(alias);
297
+ const previousTarget = targets.get(aliasKey);
298
+ if (previousTarget !== undefined && previousTarget !== targetKey)
299
+ fail("ALIAS_CONFLICT", "the alias targets more than one resource", {
300
+ alias,
301
+ });
302
+ targets.set(aliasKey, targetKey);
303
+
304
+ let group = groups.get(targetKey);
305
+ if (!group) {
306
+ group = {
307
+ ...structuredClone(operation),
308
+ caseId,
309
+ resourceId,
310
+ aliases: [],
311
+ aliasOwners: [],
312
+ caseIds: [],
313
+ };
314
+ delete group.alias;
315
+ delete group.aliasOwner;
316
+ groups.set(targetKey, group);
317
+ result.push(group);
318
+ }
319
+ group.caseIds.push(caseId);
320
+ if (!group.aliases.some((value) => normalizeText(value) === aliasKey))
321
+ group.aliases.push(alias);
322
+ if (operation.aliasOwner !== undefined)
323
+ group.aliasOwners.push({
324
+ alias,
325
+ owner: structuredClone(operation.aliasOwner),
326
+ });
327
+ return true;
328
+ },
329
+ };
330
+ }
331
+
332
+ function aliasWriteDesired(client, step) {
333
+ return client.request("PUT", step.endpoint, { body: step.after });
334
+ }
335
+
336
+ function aliasWriteBefore(client, step) {
337
+ return client.request("PUT", step.endpoint, { body: step.before });
338
+ }
339
+
340
+ async function aliasReadState(client, workspaceId, step) {
341
+ const kind = step.endpoint.includes("/measures/") ? "measure" : "dimension";
342
+ return cleanAlias(await client.request("GET", step.endpoint), kind);
343
+ }
344
+
345
+ function validateAliasAuthorityTarget(target) {
346
+ if (
347
+ canonicalJson(Object.keys(target).sort()) !==
348
+ canonicalJson(["alias", "resourceId", "resourceKind"]) ||
349
+ !READ_ONLY_FIELDS[target.resourceKind] ||
350
+ canonicalAliasResourceId(target.resourceId) !== target.resourceId ||
351
+ requiredText(target.alias, "authority.alias") !== target.alias
352
+ )
353
+ fail("INVALID_PLAN_STRUCTURE", "alias authority target is invalid");
354
+ }
355
+
356
+ function validateAliasPlanStep(step, plan, authorities, plannedCaseIds, usedCaseIds) {
357
+ const { caseIds, field, names, resourceId } = validateAliasStepStructure(
358
+ step,
359
+ plan.workspaceId,
360
+ );
361
+ const stepAuthorities = authoritiesForCaseIds(
362
+ authorities,
363
+ caseIds,
364
+ "alias",
365
+ "INVALID_ALIAS_PLAN",
366
+ );
367
+ const beforeNames = new Set(listOf(step.before.names).map(normalizeText));
368
+ const expectedNames = [];
369
+ const expectedSet = new Set();
370
+ for (const { target } of stepAuthorities) {
371
+ const aliasKey = normalizeText(target.alias);
372
+ if (
373
+ target.resourceKind !== field ||
374
+ target.resourceId !== resourceId ||
375
+ !step.after.names.some((name) => normalizeText(name) === aliasKey)
376
+ )
377
+ fail(
378
+ "INVALID_ALIAS_PLAN",
379
+ "alias step caseIds must match exact alias authorities",
380
+ );
381
+ if (!beforeNames.has(aliasKey) && !expectedSet.has(aliasKey)) {
382
+ expectedSet.add(aliasKey);
383
+ expectedNames.push(aliasKey);
384
+ }
385
+ }
386
+ if (
387
+ canonicalJson(names.map(normalizeText)) !== canonicalJson(expectedNames)
388
+ )
389
+ fail(
390
+ "INVALID_ALIAS_PLAN",
391
+ "alias step additions must exactly match case authorities",
392
+ );
393
+ claimStepCaseIds(usedCaseIds, caseIds);
394
+ for (const caseId of caseIds) plannedCaseIds.add(caseId);
395
+ }
396
+
397
+ function aliasSummaryMatches(summary, authorityTargets) {
398
+ const targets = authorityTargets.map(({ target }) => target);
399
+ return targets.every(
400
+ (target) =>
401
+ summary.resourceKind === target.resourceKind &&
402
+ summary.resourceId === target.resourceId,
403
+ );
404
+ }
405
+
406
+ export const aliasKind = {
407
+ name: "alias",
408
+ planable: true,
409
+ plan: (client, plan, operation, options = {}) =>
410
+ planAlias(client, plan, operation, options.planningEvidence),
411
+ authorityTarget: aliasAuthorityTarget,
412
+ createCoalescer: createAliasCoalescer,
413
+ writeDesired: aliasWriteDesired,
414
+ writeBefore: aliasWriteBefore,
415
+ readState: aliasReadState,
416
+ postApplyRead: revalidateAliasStep,
417
+ targetKey: (step) => `alias:${step.endpoint}`,
418
+ validateAuthorityTarget: validateAliasAuthorityTarget,
419
+ validateStep: validateAliasPlanStep,
420
+ summaryField: ["resourceKind", "resourceId"],
421
+ summaryMatches: aliasSummaryMatches,
422
+ };
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env node
2
+ import { runIfMain } from "../../datarc-semantic-core/scripts/cli.mjs";
3
+ import { createEngine } from "../../datarc-semantic-core/scripts/interventions.mjs";
4
+ import { createSemanticCli } from "../../datarc-semantic-core/scripts/semantic-cli.mjs";
5
+ import { aliasKind } from "./alias-plan.mjs";
6
+
7
+ const { runCli } = createSemanticCli({
8
+ engine: createEngine([aliasKind]),
9
+ });
10
+
11
+ await runIfMain(import.meta.url, runCli);
@@ -0,0 +1,20 @@
1
+ ---
2
+ name: datarc-semantic-calibration
3
+ description: calibration 语义干预子 skill。scripts/calibration.mjs 注册本 kind(semantic_calibration)的 plan/apply/verify/rollback;独立运行,脚本依赖 datarc-semantic-core,名称选择依赖 datarc-workspace-context。
4
+ ---
5
+
6
+ # Datarc 语义调试 — calibration
7
+
8
+ 工作区尚未确定时,先按 [datarc-workspace-context](../datarc-workspace-context/SKILL.md) 读取可访问工作区名称;不明确时列出名称让用户按名称或序号选择,不要求用户提供工作区 ID。选定后实时校验并内部传入原有 ID 参数;同一服务和账号下已确认的工作区可复用,原有权限检查与写入确认不变。
9
+
10
+ calibration 类语义干预的 plan / apply / verify / rollback。用法与参数契约同入口 skill(见 datarc-dataseek-semantic-debugging/SKILL.md 与 --help)。
11
+
12
+ ```bash
13
+ node scripts/calibration.mjs --help
14
+ ```
15
+
16
+ 安装时须连同 datarc-semantic-core 一起安装。本 CLI 只注册 calibration 一类;跨类型或方向未定时,用入口 datarc-dataseek-semantic-debugging。
17
+
18
+ ## 配置方案与验收报告
19
+
20
+ 复杂或跨资源配置先使用 [配置方案与验收](../datarc-workspace-configuration/SKILL.md) 生成方案文档,用户确认该版本后执行;配置回读及就绪后按方案真实查询并生成验收报告。保留本技能的专门确认和验证门槛。简单明确修改无需额外长方案;缺少相关技能时说明依赖,不把未执行的验证写成通过。