@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,31 @@
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 { draftCli } from "./knowledge-draft.mjs";
6
+ import { knowledgeKind } from "./knowledge-plan.mjs";
7
+ import {
8
+ promptKind,
9
+ buildPromptPlan,
10
+ } from "../../datarc-semantic-prompt/scripts/prompt-plan.mjs";
11
+
12
+ const KNOWLEDGE_KINDS = [knowledgeKind, promptKind];
13
+
14
+ const { runCli } = createSemanticCli({
15
+ engine: createEngine(KNOWLEDGE_KINDS),
16
+ promptBridgePlan: buildPromptPlan,
17
+ });
18
+
19
+ export async function runKnowledgeCli(argv = process.argv.slice(2)) {
20
+ if (argv.includes("--help")) {
21
+ process.stdout.write(draftCli.HELP_TEXT);
22
+ return runCli(argv);
23
+ }
24
+ if (!["draft-context", "draft-validate"].includes(argv[0]))
25
+ return runCli(argv);
26
+ const result = await draftCli.run(argv);
27
+ process.stdout.write(`${JSON.stringify(result)}\n`);
28
+ if (!result.ok) process.exitCode = 1;
29
+ }
30
+
31
+ await runIfMain(import.meta.url, runKnowledgeCli);
@@ -0,0 +1,20 @@
1
+ ---
2
+ name: datarc-semantic-prompt
3
+ description: prompt 语义干预子 skill。scripts/prompt.mjs 注册 prompt_bridge + knowledge 两类;独立运行,依赖 datarc-semantic-core 与 datarc-semantic-knowledge。
4
+ ---
5
+
6
+ # Datarc 语义调试 — prompt
7
+
8
+ 工作区尚未确定时,先按 [datarc-workspace-context](../datarc-workspace-context/SKILL.md) 读取可访问工作区名称;不明确时列出名称让用户按名称或序号选择,不要求用户提供工作区 ID。选定后实时校验并内部传入原有 ID 参数;同一服务和账号下已确认的工作区可复用,原有权限检查与写入确认不变。
9
+
10
+ prompt_bridge 类语义干预的 plan / apply / verify / rollback(依赖 Knowledge 规划的桥接场景)。用法与参数契约同入口 skill(见 datarc-dataseek-semantic-debugging/SKILL.md 与 --help)。
11
+
12
+ ```bash
13
+ node scripts/prompt.mjs --help
14
+ ```
15
+
16
+ 安装时须连同 datarc-semantic-core 与 datarc-semantic-knowledge 一起安装(Prompt 桥接由 Knowledge 规划派生)。跨类型或方向未定时,用入口 datarc-dataseek-semantic-debugging。
17
+
18
+ ## 配置方案与验收报告
19
+
20
+ 复杂或跨资源配置先使用 [配置方案与验收](../datarc-workspace-configuration/SKILL.md) 生成方案文档,用户确认该版本后执行;配置回读及就绪后按方案真实查询并生成验收报告。保留本技能的专门确认和验证门槛。简单明确修改无需额外长方案;缺少相关技能时说明依赖,不把未执行的验证写成通过。
@@ -0,0 +1,447 @@
1
+ import {
2
+ canonicalJson,
3
+ hashArtifactValue as hashValue,
4
+ withHash,
5
+ } from "../../datarc-semantic-core/scripts/canonical.mjs";
6
+ import {
7
+ bindSummaryAuthorityTargets,
8
+ canonicalPlanResourceId,
9
+ fail,
10
+ isRecord,
11
+ requireArrayResponse,
12
+ statesEqual,
13
+ validateMutationCaseIds,
14
+ } from "../../datarc-semantic-core/scripts/shared.mjs";
15
+ import {
16
+ bridgeLanguage,
17
+ KNOWLEDGE_SLOT,
18
+ promptBody,
19
+ promptBridgeSource,
20
+ promptCollectionPath,
21
+ revalidatePairedKnowledge,
22
+ semanticPrompt,
23
+ } from "../../datarc-semantic-knowledge/scripts/knowledge-plan.mjs";
24
+
25
+ const PLAN_VERSION = 1; // must match interventions PLAN_VERSION
26
+ export function buildPromptPlan(knowledgePlan, workspaceId) {
27
+ const caseIds = new Set(
28
+ knowledgePlan.promptChanges.flatMap((change) => change.caseIds),
29
+ );
30
+ const scenesByCase = new Map();
31
+ for (const change of knowledgePlan.promptChanges) {
32
+ const scene = change.pairedKnowledge?.scene ?? change.after?.scene;
33
+ for (const caseId of change.caseIds) {
34
+ if (!scenesByCase.has(caseId)) scenesByCase.set(caseId, new Set());
35
+ scenesByCase.get(caseId).add(scene);
36
+ }
37
+ }
38
+ const authorities = knowledgePlan.authorities
39
+ .filter((authority) => caseIds.has(authority.caseId))
40
+ .map((authority) => ({
41
+ ...authority,
42
+ kind: "prompt_bridge",
43
+ target: { scene: [...scenesByCase.get(authority.caseId)] },
44
+ }));
45
+ const steps = knowledgePlan.promptChanges.map((change) => ({
46
+ kind: "prompt_bridge",
47
+ caseIds: structuredClone(change.caseIds),
48
+ endpoint: change.endpoint,
49
+ operation: change.operation,
50
+ before: change.before,
51
+ after: change.after,
52
+ dictionarySyncRequired: false,
53
+ pairedKnowledge: structuredClone({
54
+ ...change.pairedKnowledge,
55
+ knowledgeTarget: Object.fromEntries(
56
+ change.caseIds.map((caseId) => {
57
+ const authority = knowledgePlan.authorities.find(
58
+ (a) => a.caseId === caseId,
59
+ );
60
+ return [
61
+ caseId,
62
+ authority ? structuredClone(authority.target) : undefined,
63
+ ];
64
+ }),
65
+ ),
66
+ }),
67
+ preconditions: { dryRuns: change.dryRuns, source: change.source },
68
+ }));
69
+ const plan = {
70
+ version: PLAN_VERSION,
71
+ workspaceId,
72
+ authorities,
73
+ steps,
74
+ summaries: steps.map((step) => ({
75
+ kind: "prompt_bridge",
76
+ status: "planned",
77
+ scene: step.after?.scene,
78
+ caseIds: structuredClone(step.caseIds),
79
+ })),
80
+ warnings: [],
81
+ impact: [],
82
+ };
83
+ bindSummaryAuthorityTargets(plan);
84
+ return withHash(plan, "planHash");
85
+ }
86
+
87
+ export async function revalidatePromptBridgeStep(
88
+ client,
89
+ workspaceId,
90
+ step,
91
+ authorities,
92
+ ) {
93
+ const { dryRuns, source } = validatePromptBridgeStepStructure(
94
+ step,
95
+ workspaceId,
96
+ );
97
+ await revalidatePairedKnowledge(client, workspaceId, step, authorities);
98
+ const collection = promptCollectionPath(workspaceId);
99
+ if (source.kind === "default") {
100
+ const defaults = await client.request("GET", `${collection}default/`, {
101
+ query: { scene: step.after.scene },
102
+ });
103
+ if (
104
+ !isRecord(defaults) ||
105
+ canonicalJson(promptBridgeSource("default", defaults)) !==
106
+ canonicalJson(source) ||
107
+ bridgeLanguage(defaults.prompt, step.after.scene, "prompt") !==
108
+ step.after.prompt ||
109
+ bridgeLanguage(defaults.promptEn, step.after.scene, "promptEn") !==
110
+ step.after.promptEn
111
+ )
112
+ fail(
113
+ "PROMPT_SOURCE_DRIFT",
114
+ "default Prompt changed after the bridge was planned",
115
+ );
116
+ }
117
+ for (const evidence of dryRuns) {
118
+ const response = await client.request("POST", `${collection}dry-run/`, {
119
+ body: {
120
+ scene: step.after.scene,
121
+ prompt: step.after[evidence.field],
122
+ language: evidence.language,
123
+ },
124
+ });
125
+ if (!isRecord(response) || typeof response.prompt !== "string")
126
+ fail("PROMPT_DRY_RUN_FAILED", "Prompt dry-run response is invalid");
127
+ }
128
+ }
129
+
130
+ export function validatePromptBridgeStepStructure(step, workspaceId) {
131
+ const allowed = new Set([
132
+ "after",
133
+ "before",
134
+ "caseIds",
135
+ "dictionarySyncRequired",
136
+ "endpoint",
137
+ "kind",
138
+ "operation",
139
+ "pairedKnowledge",
140
+ "preconditions",
141
+ ]);
142
+ if (
143
+ Object.keys(step).some((field) => !allowed.has(field)) ||
144
+ [...allowed].some((field) => !Object.hasOwn(step, field)) ||
145
+ step.kind !== "prompt_bridge" ||
146
+ step.dictionarySyncRequired !== false
147
+ )
148
+ fail("INVALID_PROMPT_BRIDGE_PLAN", "Prompt bridge step fields are invalid");
149
+ const collection = promptCollectionPath(workspaceId);
150
+ const after = validatePromptSnapshot(
151
+ step.after,
152
+ "after",
153
+ step.operation === "PATCH",
154
+ );
155
+ let before = null;
156
+ if (step.operation === "POST") {
157
+ if (
158
+ step.before !== null ||
159
+ after.id !== undefined ||
160
+ step.endpoint !== collection
161
+ )
162
+ fail(
163
+ "INVALID_PROMPT_BRIDGE_PLAN",
164
+ "Prompt bridge POST must create from the collection",
165
+ );
166
+ } else if (step.operation === "PATCH") {
167
+ before = validatePromptSnapshot(step.before, "before", true);
168
+ const beforeId = canonicalPlanResourceId(
169
+ before.id,
170
+ "INVALID_PROMPT_BRIDGE_PLAN",
171
+ );
172
+ const afterId = canonicalPlanResourceId(
173
+ after.id,
174
+ "INVALID_PROMPT_BRIDGE_PLAN",
175
+ );
176
+ if (
177
+ beforeId !== afterId ||
178
+ before.scene !== after.scene ||
179
+ step.endpoint !== `${collection}${beforeId}/` ||
180
+ statesEqual(before, after)
181
+ )
182
+ fail(
183
+ "INVALID_PROMPT_BRIDGE_PLAN",
184
+ "Prompt bridge PATCH identity or desired state is invalid",
185
+ );
186
+ } else
187
+ fail("INVALID_PROMPT_BRIDGE_PLAN", "Prompt bridge operation is invalid");
188
+
189
+ const caseIds = validateMutationCaseIds(
190
+ step.caseIds,
191
+ "INVALID_PROMPT_BRIDGE_PLAN",
192
+ );
193
+ if (
194
+ !isRecord(step.pairedKnowledge) ||
195
+ !["caseIds", "scene"].every((field) =>
196
+ Object.hasOwn(step.pairedKnowledge, field),
197
+ ) ||
198
+ Object.keys(step.pairedKnowledge).some(
199
+ (field) => !["caseIds", "scene", "knowledgeTarget"].includes(field),
200
+ ) ||
201
+ step.pairedKnowledge.scene !== after.scene ||
202
+ canonicalJson(step.pairedKnowledge.caseIds) !== canonicalJson(caseIds)
203
+ )
204
+ fail(
205
+ "INVALID_PROMPT_BRIDGE_PLAN",
206
+ "Prompt bridge is not bound to its Knowledge authorities",
207
+ );
208
+ const { dryRuns, source } = validatePromptBridgePreconditions(
209
+ step.preconditions,
210
+ before,
211
+ after,
212
+ );
213
+ return { after, before, caseIds, dryRuns, source };
214
+ }
215
+
216
+ export function validatePromptSnapshot(value, label, requireId) {
217
+ if (!isRecord(value))
218
+ fail(
219
+ "INVALID_PROMPT_BRIDGE_PLAN",
220
+ `Prompt bridge ${label} must be an object`,
221
+ );
222
+ const allowed = new Set([
223
+ ...(requireId ? ["id"] : []),
224
+ "prompt",
225
+ "promptEn",
226
+ "scene",
227
+ ]);
228
+ if (
229
+ Object.keys(value).some((field) => !allowed.has(field)) ||
230
+ [...allowed].some((field) => !Object.hasOwn(value, field)) ||
231
+ !Number.isSafeInteger(value.scene) ||
232
+ value.scene <= 0 ||
233
+ typeof value.prompt !== "string" ||
234
+ typeof value.promptEn !== "string" ||
235
+ (!value.prompt.trim() && !value.promptEn.trim())
236
+ )
237
+ fail(
238
+ "INVALID_PROMPT_BRIDGE_PLAN",
239
+ `Prompt bridge ${label} snapshot is invalid`,
240
+ );
241
+ if (requireId)
242
+ canonicalPlanResourceId(value.id, "INVALID_PROMPT_BRIDGE_PLAN");
243
+ for (const field of ["prompt", "promptEn"]) {
244
+ const count = value[field].split(KNOWLEDGE_SLOT).length - 1;
245
+ if (count > 1 || (label === "after" && value[field].trim() && count !== 1))
246
+ fail(
247
+ "INVALID_PROMPT_BRIDGE_PLAN",
248
+ `Prompt bridge ${label} slot count is invalid`,
249
+ );
250
+ }
251
+ return value;
252
+ }
253
+
254
+ export function validatePromptBridgePreconditions(
255
+ preconditions,
256
+ before,
257
+ after,
258
+ ) {
259
+ if (
260
+ !isRecord(preconditions) ||
261
+ canonicalJson(Object.keys(preconditions).sort()) !==
262
+ canonicalJson(["dryRuns", "source"]) ||
263
+ !Array.isArray(preconditions.dryRuns) ||
264
+ !isRecord(preconditions.source)
265
+ )
266
+ fail(
267
+ "INVALID_PROMPT_BRIDGE_PLAN",
268
+ "Prompt bridge preconditions are invalid",
269
+ );
270
+ const source = preconditions.source;
271
+ if (
272
+ canonicalJson(Object.keys(source).sort()) !==
273
+ canonicalJson(["kind", "promptEnHash", "promptHash"]) ||
274
+ !new Set(["default", "workspace_override"]).has(source.kind) ||
275
+ !/^[0-9a-f]{64}$/u.test(source.promptHash) ||
276
+ !/^[0-9a-f]{64}$/u.test(source.promptEnHash) ||
277
+ (source.kind === "default") !== (before === null) ||
278
+ (before !== null &&
279
+ canonicalJson(source) !==
280
+ canonicalJson(promptBridgeSource("workspace_override", before))) ||
281
+ (before !== null &&
282
+ (bridgeLanguage(before.prompt, after.scene, "prompt") !== after.prompt ||
283
+ bridgeLanguage(before.promptEn, after.scene, "promptEn") !==
284
+ after.promptEn))
285
+ )
286
+ fail(
287
+ "INVALID_PROMPT_BRIDGE_PLAN",
288
+ "Prompt bridge source evidence is invalid",
289
+ );
290
+ const expectedFields = ["prompt", "promptEn"].filter(
291
+ (field) =>
292
+ after[field].trim() &&
293
+ (before === null || after[field] !== before[field]),
294
+ );
295
+ const seen = new Set();
296
+ for (const evidence of preconditions.dryRuns) {
297
+ if (
298
+ !isRecord(evidence) ||
299
+ canonicalJson(Object.keys(evidence).sort()) !==
300
+ canonicalJson(["field", "language", "promptHash", "status"]) ||
301
+ !expectedFields.includes(evidence.field) ||
302
+ seen.has(evidence.field) ||
303
+ evidence.language !== (evidence.field === "prompt" ? "zh-CN" : "en-US") ||
304
+ evidence.promptHash !== hashValue(after[evidence.field]) ||
305
+ evidence.status !== "SUCCESS"
306
+ )
307
+ fail(
308
+ "INVALID_PROMPT_BRIDGE_PLAN",
309
+ "Prompt bridge dry-run evidence is invalid",
310
+ );
311
+ seen.add(evidence.field);
312
+ }
313
+ if (
314
+ seen.size !== expectedFields.length ||
315
+ expectedFields.some((field) => !seen.has(field))
316
+ )
317
+ fail(
318
+ "INVALID_PROMPT_BRIDGE_PLAN",
319
+ "every changed Prompt language requires one dry-run",
320
+ );
321
+ return { dryRuns: preconditions.dryRuns, source };
322
+ }
323
+
324
+ function promptWriteDesired(client, step) {
325
+ return client.request(step.operation, step.endpoint, {
326
+ body: promptBody(step.after, step.operation === "POST"),
327
+ });
328
+ }
329
+
330
+ function promptWriteBefore(client, step) {
331
+ return client.request("PATCH", step.endpoint, {
332
+ body: promptBody(step.before, false),
333
+ });
334
+ }
335
+
336
+ async function promptReadState(client, workspaceId, step) {
337
+ const id = step.after?.id ?? step.before?.id;
338
+ if (id !== undefined)
339
+ return semanticPrompt(
340
+ await client.request(
341
+ "GET",
342
+ `${promptCollectionPath(workspaceId)}${id}/`,
343
+ ),
344
+ );
345
+ const rows = requireArrayResponse(
346
+ await client.request("GET", promptCollectionPath(workspaceId)),
347
+ "INVALID_PROMPT_STATE",
348
+ "workspace Prompt list must be an array",
349
+ );
350
+ const matches = rows.filter(
351
+ (item) =>
352
+ String(item.scene) === String(step.after?.scene ?? step.before?.scene),
353
+ );
354
+ if (matches.length > 1)
355
+ fail(
356
+ "PROMPT_IDENTITY_AMBIGUOUS",
357
+ "multiple workspace Prompts match one scene",
358
+ );
359
+ return matches[0] ? semanticPrompt(matches[0]) : null;
360
+ }
361
+
362
+ async function promptReadCreatedState(client, workspaceId, step) {
363
+ const id = step.after?.id;
364
+ const rows = requireArrayResponse(
365
+ await client.request("GET", promptCollectionPath(workspaceId)),
366
+ "INVALID_PROMPT_STATE",
367
+ "workspace Prompt list must be an array",
368
+ );
369
+ const row = rows.find((item) => String(item.id) === String(id));
370
+ return row ? semanticPrompt(row) : null;
371
+ }
372
+
373
+ async function promptExactCreatedCandidates(client, workspaceId, step) {
374
+ const scene = step.after?.scene;
375
+ const rows = requireArrayResponse(
376
+ await client.request("GET", promptCollectionPath(workspaceId)),
377
+ "INVALID_PROMPT_STATE",
378
+ "workspace Prompt list must be an array",
379
+ );
380
+ return rows
381
+ .filter((row) => String(row.scene) === String(scene))
382
+ .map(semanticPrompt);
383
+ }
384
+
385
+ function promptRevalidate(client, workspaceId, step, ctx) {
386
+ return revalidatePromptBridgeStep(
387
+ client,
388
+ workspaceId,
389
+ step,
390
+ ctx.authorities,
391
+ );
392
+ }
393
+
394
+ function validatePromptAuthorityTarget(target) {
395
+ const allowed = new Set(["scene"]);
396
+ if (
397
+ Object.keys(target).some((field) => !allowed.has(field)) ||
398
+ !Array.isArray(target.scene) ||
399
+ target.scene.length === 0 ||
400
+ target.scene.some((scene) => !Number.isSafeInteger(scene) || scene <= 0)
401
+ )
402
+ fail("INVALID_PLAN_STRUCTURE", "Prompt authority target is invalid");
403
+ }
404
+
405
+ function validatePromptPlanStep(step, plan, authorities, plannedCaseIds) {
406
+ const { caseIds } = validatePromptBridgeStepStructure(
407
+ step,
408
+ plan.workspaceId,
409
+ );
410
+ for (const caseId of caseIds) {
411
+ const authority = authorities.get(caseId);
412
+ const matched =
413
+ authority?.kind === "knowledge"
414
+ ? authority.target.scenes.includes(step.after.scene)
415
+ : authority?.kind === "prompt_bridge"
416
+ ? authority.target.scene.includes(step.after.scene)
417
+ : false;
418
+ if (!matched)
419
+ fail(
420
+ "INVALID_PROMPT_BRIDGE_PLAN",
421
+ "Prompt bridge caseIds must match exact Knowledge authorities",
422
+ );
423
+ plannedCaseIds.add(caseId);
424
+ }
425
+ }
426
+
427
+ function promptSummaryMatches(summary, authorityTargets) {
428
+ const targets = authorityTargets.map(({ target }) => target);
429
+ return targets.every((target) => summary.name === target.name);
430
+ }
431
+
432
+ export const promptKind = {
433
+ name: "prompt_bridge",
434
+ planable: false,
435
+ writeDesired: promptWriteDesired,
436
+ writeBefore: promptWriteBefore,
437
+ readState: promptReadState,
438
+ readCreatedState: promptReadCreatedState,
439
+ postApplyRead: promptRevalidate,
440
+ exactCreatedCandidates: promptExactCreatedCandidates,
441
+ collection: promptCollectionPath,
442
+ targetKey: (step) => `prompt:${step.after?.id ?? step.after?.scene}`,
443
+ validateAuthorityTarget: validatePromptAuthorityTarget,
444
+ validateStep: validatePromptPlanStep,
445
+ summaryField: ["scene"],
446
+ summaryMatches: promptSummaryMatches,
447
+ };
@@ -0,0 +1,15 @@
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 { knowledgeKind } from "../../datarc-semantic-knowledge/scripts/knowledge-plan.mjs";
6
+ import { promptKind, buildPromptPlan } from "./prompt-plan.mjs";
7
+
8
+ const PROMPT_KINDS = [knowledgeKind, promptKind];
9
+
10
+ const { runCli } = createSemanticCli({
11
+ engine: createEngine(PROMPT_KINDS),
12
+ promptBridgePlan: buildPromptPlan,
13
+ });
14
+
15
+ await runIfMain(import.meta.url, runCli);
@@ -0,0 +1,20 @@
1
+ ---
2
+ name: datarc-semantic-synonym
3
+ description: synonym 语义干预子 skill。scripts/synonym.mjs 注册本 kind(dimension_value_synonym)的 plan/apply/verify/rollback;独立运行,脚本依赖 datarc-semantic-core,名称选择依赖 datarc-workspace-context。
4
+ ---
5
+
6
+ # Datarc 语义调试 — synonym
7
+
8
+ 工作区尚未确定时,先按 [datarc-workspace-context](../datarc-workspace-context/SKILL.md) 读取可访问工作区名称;不明确时列出名称让用户按名称或序号选择,不要求用户提供工作区 ID。选定后实时校验并内部传入原有 ID 参数;同一服务和账号下已确认的工作区可复用,原有权限检查与写入确认不变。
9
+
10
+ synonym 类语义干预的 plan / apply / verify / rollback。用法与参数契约同入口 skill(见 datarc-dataseek-semantic-debugging/SKILL.md 与 --help)。
11
+
12
+ ```bash
13
+ node scripts/synonym.mjs --help
14
+ ```
15
+
16
+ 安装时须连同 datarc-semantic-core 一起安装。本 CLI 只注册 synonym 一类;跨类型或方向未定时,用入口 datarc-dataseek-semantic-debugging。
17
+
18
+ ## 配置方案与验收报告
19
+
20
+ 复杂或跨资源配置先使用 [配置方案与验收](../datarc-workspace-configuration/SKILL.md) 生成方案文档,用户确认该版本后执行;配置回读及就绪后按方案真实查询并生成验收报告。保留本技能的专门确认和验证门槛。简单明确修改无需额外长方案;缺少相关技能时说明依赖,不把未执行的验证写成通过。