@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.
- package/README.md +20 -2
- package/cordis.patch.yml +4 -0
- package/icon.svg +4 -0
- package/index.js +35 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +37 -4
- package/skills/datarc-access-permissions/SKILL.md +30 -0
- package/skills/datarc-access-permissions/references/api.md +31 -0
- package/skills/datarc-access-permissions/references/write-order.md +16 -0
- package/skills/datarc-analysis-report/SKILL.md +125 -0
- package/skills/datarc-analysis-report/agents/openai.yaml +6 -0
- package/skills/datarc-analysis-report/references/analyst-frameworks.md +215 -0
- package/skills/datarc-analysis-report/references/api-contracts.md +478 -0
- package/skills/datarc-analysis-report/references/direct-card-fallback-design.md +66 -0
- package/skills/datarc-analysis-report/references/human-in-the-loop.md +142 -0
- package/skills/datarc-analysis-report/references/loop-personalization-policy.md +138 -0
- package/skills/datarc-analysis-report/references/manifest-example.json +779 -0
- package/skills/datarc-analysis-report/references/narrative-schema.md +160 -0
- package/skills/datarc-analysis-report/references/question-syntax.md +151 -0
- package/skills/datarc-analysis-report/scripts/run_analysis_report.py +2225 -0
- package/skills/datarc-analysis-report/scripts/run_dataseek_cards.py +1914 -0
- package/skills/datarc-analysis-report/scripts/test_run_analysis_report.py +5295 -0
- package/skills/datarc-data-search/SKILL.md +243 -0
- package/skills/datarc-data-search/scripts/calculate.py +116 -0
- package/skills/datarc-data-search/scripts/data-search.mjs +628 -0
- package/skills/datarc-data-search/scripts/datarc-client.mjs +464 -0
- package/skills/datarc-data-search/scripts/search-result.mjs +211 -0
- package/skills/datarc-dataseek-batch-evaluation/SKILL.md +59 -0
- package/skills/datarc-dataseek-batch-evaluation/references/artifacts.md +36 -0
- package/skills/datarc-dataseek-batch-evaluation/references/equivalence.md +30 -0
- package/skills/datarc-dataseek-batch-evaluation/scripts/datarc-client.mjs +464 -0
- package/skills/datarc-dataseek-batch-evaluation/scripts/dataseek-batch-evaluation.mjs +1020 -0
- package/skills/datarc-dataseek-search/SKILL.md +96 -0
- package/skills/datarc-dataseek-search/scripts/datarc-client.mjs +464 -0
- package/skills/datarc-dataseek-search/scripts/dataseek-search.mjs +257 -0
- package/skills/datarc-dataseek-semantic-debugging/SKILL.md +44 -0
- package/skills/datarc-dataseek-semantic-debugging/agents/openai.yaml +4 -0
- package/skills/datarc-dataseek-semantic-debugging/evals/evals.json +165 -0
- package/skills/datarc-dataseek-semantic-debugging/references/dataset.md +77 -0
- package/skills/datarc-dataseek-semantic-debugging/references/input-and-resolution.md +93 -0
- package/skills/datarc-dataseek-semantic-debugging/references/interventions.md +64 -0
- package/skills/datarc-dataseek-semantic-debugging/references/knowledge-and-prompts.md +47 -0
- package/skills/datarc-dataseek-semantic-debugging/references/rollback.md +11 -0
- package/skills/datarc-dataseek-semantic-debugging/references/verification-and-rollback.md +95 -0
- package/skills/datarc-dataseek-semantic-debugging/scripts/semantic-debugging.mjs +29 -0
- package/skills/datarc-dataseek-testset-generation/SKILL.md +47 -0
- package/skills/datarc-dataseek-testset-generation/scripts/datarc-client.mjs +464 -0
- package/skills/datarc-dataseek-testset-generation/scripts/dataseek-testset-generation.mjs +526 -0
- package/skills/datarc-datasource/SKILL.md +97 -0
- package/skills/datarc-oauth/SKILL.md +47 -0
- package/skills/datarc-oauth/scripts/auth.mjs +130 -0
- package/skills/datarc-oauth/scripts/credentials.mjs +237 -0
- package/skills/datarc-report-add-card/SKILL.md +90 -0
- package/skills/datarc-report-add-card/agents/openai.yaml +4 -0
- package/skills/datarc-report-add-card/scripts/datarc-client.mjs +464 -0
- package/skills/datarc-report-add-card/scripts/report-card.mjs +439 -0
- package/skills/datarc-semantic-alias/SKILL.md +20 -0
- package/skills/datarc-semantic-alias/scripts/alias-plan.mjs +422 -0
- package/skills/datarc-semantic-alias/scripts/alias.mjs +11 -0
- package/skills/datarc-semantic-calibration/SKILL.md +20 -0
- package/skills/datarc-semantic-calibration/scripts/calibration-plan.mjs +683 -0
- package/skills/datarc-semantic-calibration/scripts/calibration.mjs +11 -0
- package/skills/datarc-semantic-core/SKILL.md +12 -0
- package/skills/datarc-semantic-core/scripts/artifact-journal.mjs +830 -0
- package/skills/datarc-semantic-core/scripts/canonical.mjs +48 -0
- package/skills/datarc-semantic-core/scripts/case-model.mjs +608 -0
- package/skills/datarc-semantic-core/scripts/cli.mjs +180 -0
- package/skills/datarc-semantic-core/scripts/datarc-client.mjs +180 -0
- package/skills/datarc-semantic-core/scripts/interpretation-pairs.mjs +57 -0
- package/skills/datarc-semantic-core/scripts/interventions.mjs +693 -0
- package/skills/datarc-semantic-core/scripts/live-resolution.mjs +305 -0
- package/skills/datarc-semantic-core/scripts/model-scope.mjs +49 -0
- package/skills/datarc-semantic-core/scripts/reproduction.mjs +330 -0
- package/skills/datarc-semantic-core/scripts/semantic-cli.mjs +740 -0
- package/skills/datarc-semantic-core/scripts/shared.mjs +312 -0
- package/skills/datarc-semantic-core/scripts/verification.mjs +1014 -0
- package/skills/datarc-semantic-dataset/SKILL.md +20 -0
- package/skills/datarc-semantic-dataset/scripts/dataset-plan.mjs +749 -0
- package/skills/datarc-semantic-dataset/scripts/dataset-preflight.mjs +813 -0
- package/skills/datarc-semantic-dataset/scripts/dataset.mjs +11 -0
- package/skills/datarc-semantic-knowledge/SKILL.md +38 -0
- package/skills/datarc-semantic-knowledge/references/knowledge-drafts.md +61 -0
- package/skills/datarc-semantic-knowledge/references/knowledge-generation.json +16 -0
- package/skills/datarc-semantic-knowledge/scripts/knowledge-draft.mjs +347 -0
- package/skills/datarc-semantic-knowledge/scripts/knowledge-plan.mjs +848 -0
- package/skills/datarc-semantic-knowledge/scripts/knowledge.mjs +31 -0
- package/skills/datarc-semantic-prompt/SKILL.md +20 -0
- package/skills/datarc-semantic-prompt/scripts/prompt-plan.mjs +447 -0
- package/skills/datarc-semantic-prompt/scripts/prompt.mjs +15 -0
- package/skills/datarc-semantic-synonym/SKILL.md +20 -0
- package/skills/datarc-semantic-synonym/scripts/synonym-plan.mjs +688 -0
- package/skills/datarc-semantic-synonym/scripts/synonym.mjs +11 -0
- package/skills/datarc-viz-analysis-report/SKILL.md +108 -0
- package/skills/datarc-viz-analysis-report/assets/LICENSE-echarts.md +8 -0
- package/skills/datarc-viz-analysis-report/assets/echarts.min.js +45 -0
- package/skills/datarc-viz-analysis-report/references/api-contracts.md +163 -0
- package/skills/datarc-viz-analysis-report/references/derivation-log.md +157 -0
- package/skills/datarc-viz-analysis-report/references/evidence-framework.md +76 -0
- package/skills/datarc-viz-analysis-report/references/html-template.md +92 -0
- package/skills/datarc-viz-analysis-report/references/provenance-format.md +56 -0
- package/skills/datarc-viz-analysis-report/references/question-syntax.md +151 -0
- package/skills/datarc-viz-analysis-report/scripts/render_viz_report.py +1708 -0
- package/skills/datarc-viz-analysis-report/scripts/test_render_viz_report.py +964 -0
- package/skills/datarc-workspace-configuration/SKILL.md +59 -0
- package/skills/datarc-workspace-configuration/references/artifacts.md +75 -0
- package/skills/datarc-workspace-configuration/references/verification.md +20 -0
- package/skills/datarc-workspace-configuration/scripts/configuration.mjs +662 -0
- package/skills/datarc-workspace-context/SKILL.md +43 -0
- package/skills/datarc-workspace-context/agents/openai.yaml +4 -0
- package/skills/datarc-workspace-context/scripts/datarc-client.mjs +31 -0
- package/skills/datarc-workspace-context/scripts/query-display.mjs +114 -0
- package/skills/datarc-workspace-context/scripts/workspace-context.mjs +58 -0
- package/skills/datarc-workspace-custom-tables/SKILL.md +89 -0
- package/skills/datarc-workspace-custom-tables/scripts/datarc-client.mjs +165 -0
- package/skills/datarc-workspace-custom-tables/scripts/workspace-custom-tables.mjs +601 -0
- package/skills/datarc-workspace-keywords/SKILL.md +197 -0
- package/skills/datarc-workspace-keywords/agents/openai.yaml +4 -0
- package/skills/datarc-workspace-keywords/references/api-fields.md +79 -0
- package/skills/datarc-workspace-keywords/references/derived-measures.md +177 -0
- package/skills/datarc-workspace-keywords/scripts/datarc-client.mjs +145 -0
- package/skills/datarc-workspace-keywords/scripts/workspace-keywords.mjs +2421 -0
- package/skills/datarc-workspace-membership/SKILL.md +29 -0
- package/skills/datarc-workspace-membership/references/api.md +19 -0
- package/skills/datarc-workspace-modeling/SKILL.md +209 -0
- package/skills/datarc-workspace-modeling/agents/openai.yaml +4 -0
- package/skills/datarc-workspace-modeling/references/join-preview.md +38 -0
- package/skills/datarc-workspace-modeling/references/model-plan.md +300 -0
- package/skills/datarc-workspace-modeling/references/model-tags.md +95 -0
- package/skills/datarc-workspace-modeling/references/modeling-contract.json +29 -0
- package/skills/datarc-workspace-modeling/references/modeling-fixtures.json +2423 -0
- package/skills/datarc-workspace-modeling/scripts/datarc-client.mjs +137 -0
- package/skills/datarc-workspace-modeling/scripts/workspace-model-tags.mjs +238 -0
- package/skills/datarc-workspace-modeling/scripts/workspace-modeling.mjs +1261 -0
- package/skills-index.json +194 -0
|
@@ -0,0 +1,740 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { unlink } from "node:fs/promises";
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
commandJournalFailure,
|
|
6
|
+
createCli,
|
|
7
|
+
journalCommand,
|
|
8
|
+
requireConfirmation,
|
|
9
|
+
timestamp,
|
|
10
|
+
withOptionalArtifact,
|
|
11
|
+
} from "./cli.mjs";
|
|
12
|
+
import {
|
|
13
|
+
appendReservedArtifact,
|
|
14
|
+
completeCommandArtifact,
|
|
15
|
+
createCommandArtifactIdentity,
|
|
16
|
+
readJson,
|
|
17
|
+
reserveArtifact,
|
|
18
|
+
validateFinalBundle,
|
|
19
|
+
validateRollbackBundle,
|
|
20
|
+
} from "./artifact-journal.mjs";
|
|
21
|
+
import {
|
|
22
|
+
normalizeCases,
|
|
23
|
+
resolveTarget,
|
|
24
|
+
validateCaseSet,
|
|
25
|
+
} from "./case-model.mjs";
|
|
26
|
+
import { hashArtifactValue } from "./canonical.mjs";
|
|
27
|
+
import {
|
|
28
|
+
createClient,
|
|
29
|
+
DatarcError,
|
|
30
|
+
errorJson,
|
|
31
|
+
parseArgs,
|
|
32
|
+
required,
|
|
33
|
+
} from "./datarc-client.mjs";
|
|
34
|
+
import {
|
|
35
|
+
liveResolutionJournalRequest,
|
|
36
|
+
normalizeLiveResolutionInput,
|
|
37
|
+
resolveLiveCases,
|
|
38
|
+
} from "./live-resolution.mjs";
|
|
39
|
+
import { normalizeReproductionInput, reproduceCase } from "./reproduction.mjs";
|
|
40
|
+
import {
|
|
41
|
+
bindVerificationToAuthorities,
|
|
42
|
+
captureSyncBaseline,
|
|
43
|
+
deriveVerificationSyncTargets,
|
|
44
|
+
verifyReceipt,
|
|
45
|
+
waitForFreshDictionary,
|
|
46
|
+
} from "./verification.mjs";
|
|
47
|
+
|
|
48
|
+
export function createSemanticCli({ engine, promptBridgePlan }) {
|
|
49
|
+
const { applyPlan, preparePlan, rollbackReceipt, validateApplyPlan } = engine;
|
|
50
|
+
const availableKinds = new Set(engine.kinds.map((kind) => kind.name));
|
|
51
|
+
const kindList = [...availableKinds].join("、");
|
|
52
|
+
|
|
53
|
+
const COMMAND_FLAGS = {
|
|
54
|
+
direction: new Set(["input", "output"]),
|
|
55
|
+
diagnose: new Set(["input", "output"]),
|
|
56
|
+
resolve: new Set(["input", "output"]),
|
|
57
|
+
"resolve-live": new Set(["input", "output"]),
|
|
58
|
+
reproduce: new Set(["input", "output"]),
|
|
59
|
+
plan: new Set(["input", "output", "direction"]),
|
|
60
|
+
apply: new Set(["input", "output", "confirm"]),
|
|
61
|
+
verify: new Set(["input", "output"]),
|
|
62
|
+
rollback: new Set(["input", "output", "confirm"]),
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const HELP_TEXT_DEFINITION = `Usage:
|
|
66
|
+
node scripts/semantic-debugging.mjs <command> --input <path|-> [--output <path>] [--confirm <token>] [--direction <hash>]
|
|
67
|
+
|
|
68
|
+
Commands and input JSON:
|
|
69
|
+
direction {workspaceId,sourceType,input}; recommends the narrowest intervention kind per case with rationale and risk, and returns a directionHash for plan --direction
|
|
70
|
+
diagnose {sourceType,input}; sourceType is mapping_list, current_search_correction, or reported_search_correction
|
|
71
|
+
resolve {cases,catalog,selections?}; each selection may use selectedId, selectedProp, and allowedKinds
|
|
72
|
+
resolve-live {workspaceId,cases,selections?}; loads compact current-admin candidates, then requires an exact id/prop selection for write authority; requires --output
|
|
73
|
+
reproduce {workspaceId,caseId,sourceType,question}; only current_search_correction or reported_search_correction; requires --output; creates a new current-administrator thread and leaves normal search history
|
|
74
|
+
plan {workspaceId,operations:[{caseId,kind,...}],planningEvidence?}; each operation carries a kind; cross-kind input emits one single-kind plan per kind (writes <output>.<kind>), and Knowledge that needs a Prompt bridge emits a dependent prompt_bridge plan (dependsOn the Knowledge planHash); reserves all outputs before API; --direction <hash> verifies the confirmed direction
|
|
75
|
+
apply one or more plan artifacts; repeat --input/--output/--confirm per plan; plans apply in dependsOn order, each applying exactly one resource kind; revalidates Alias names, synonym cut/owners, and calibration cut before journal/write; calibration replacement is one atomic POST; requires --output and --confirm APPLY:<planHash>
|
|
76
|
+
verify a statusless final {plan,receipt,baseline,mutationStartedAt,...} bundle only; requires --output; suites exactly match plan authorities and each has one primary + paraphrase, plus a contrast probe only when the intervention could collide; sync targets are derived from the plan; Knowledge returns manual_confirmation_required until its new-thread answers are inspected
|
|
77
|
+
rollback a complete or applying plan+receipt bundle; semantically validates the root plan; real dictionary restoration records a fresh sync anchor before write and waits for task type 2; requires --output and --confirm ROLLBACK:<receiptHash>
|
|
78
|
+
|
|
79
|
+
Flags:
|
|
80
|
+
--input - Read JSON from stdin
|
|
81
|
+
--output PATH Write the full private artifact; API-backed commands use a checksum-chained 0600 write-ahead journal; existing files are not overwritten
|
|
82
|
+
--confirm TOKEN Exact hash confirmation for apply or rollback
|
|
83
|
+
--direction HASH Confirmed directionHash from the direction command
|
|
84
|
+
--help Show this help
|
|
85
|
+
|
|
86
|
+
DATARC_ENDPOINT and DATARC_TOKEN are required only for API-backed commands.
|
|
87
|
+
Alias name validation is preflight, not a lock; see references/interventions.md for the validation-to-PUT TOCTOU boundary.
|
|
88
|
+
Stdout is compact JSON and never contains full plan, receipt, Prompt, corpus, SQL, reasoning, token, or API payload snapshots.
|
|
89
|
+
Registered intervention kinds: ${kindList}.`;
|
|
90
|
+
|
|
91
|
+
async function diagnose(client, input, args) {
|
|
92
|
+
const sourceType = required(input ?? {}, "sourceType");
|
|
93
|
+
const cases = validateCaseSet(normalizeCases(sourceType, input.input));
|
|
94
|
+
const result = { version: 1, sourceType, cases };
|
|
95
|
+
return withOptionalArtifact(result, args.output, {
|
|
96
|
+
sourceType,
|
|
97
|
+
cases: cases.length,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async function direction(client, input, args) {
|
|
102
|
+
const workspaceId = required(input ?? {}, "workspaceId");
|
|
103
|
+
const sourceType = required(input ?? {}, "sourceType");
|
|
104
|
+
const cases = validateCaseSet(normalizeCases(sourceType, input.input));
|
|
105
|
+
const suggestions = cases.map((semanticCase) => {
|
|
106
|
+
const suggestedKind = suggestKind(semanticCase);
|
|
107
|
+
return {
|
|
108
|
+
caseId: `${semanticCase.sourceType}:${semanticCase.sourceIndex}`,
|
|
109
|
+
suggestedKind,
|
|
110
|
+
rationale: rationaleFor(suggestedKind),
|
|
111
|
+
risk: riskFor(suggestedKind),
|
|
112
|
+
};
|
|
113
|
+
});
|
|
114
|
+
const directionHash = hashArtifactValue(
|
|
115
|
+
suggestions.map(({ caseId, suggestedKind }) => ({
|
|
116
|
+
caseId,
|
|
117
|
+
suggestedKind,
|
|
118
|
+
})),
|
|
119
|
+
);
|
|
120
|
+
return withOptionalArtifact(
|
|
121
|
+
{ version: 1, workspaceId, directionHash, cases: suggestions },
|
|
122
|
+
args.output,
|
|
123
|
+
{ directionHash, cases: suggestions },
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function suggestKind(semanticCase) {
|
|
128
|
+
const kind = semanticCase.targetHint?.kind;
|
|
129
|
+
const suggested =
|
|
130
|
+
kind === "dataset" || kind === "model"
|
|
131
|
+
? "dataset"
|
|
132
|
+
: kind === "knowledge"
|
|
133
|
+
? "knowledge"
|
|
134
|
+
: kind === "dimension" || kind === "measure"
|
|
135
|
+
? "alias"
|
|
136
|
+
: semanticCase.sourceType === "mapping_list"
|
|
137
|
+
? "alias"
|
|
138
|
+
: semanticCase.targetHint?.prop !== undefined
|
|
139
|
+
? "alias"
|
|
140
|
+
: "dimension_value_synonym";
|
|
141
|
+
return availableKinds.has(suggested) ? suggested : [...availableKinds][0];
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function rationaleFor(kind) {
|
|
145
|
+
return (
|
|
146
|
+
{
|
|
147
|
+
alias: "把词/字段映射到现有维度或指标,最窄且可逆",
|
|
148
|
+
dimension_value_synonym: "为维度值补充同义词以扩展召回",
|
|
149
|
+
semantic_calibration: "固定多 token 组合的语义解析",
|
|
150
|
+
dataset: "把可复用成员集建模为命名数据集",
|
|
151
|
+
knowledge: "补充解释或上下文规则",
|
|
152
|
+
prompt_bridge: "调整工作区 Prompt 模板",
|
|
153
|
+
}[kind] ?? "需要进一步确认干预方向"
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function riskFor(kind) {
|
|
158
|
+
return (
|
|
159
|
+
{
|
|
160
|
+
alias: "影响该维度/指标的所有后续查询",
|
|
161
|
+
dimension_value_synonym: "可能影响其他维度值召回,需验证不误伤",
|
|
162
|
+
semantic_calibration: "影响多 token 组合的固定解析",
|
|
163
|
+
dataset: "影响成员集的时效与口径",
|
|
164
|
+
knowledge: "影响解释与上下文,需新线程验证",
|
|
165
|
+
prompt_bridge: "影响模板覆盖的所有场景",
|
|
166
|
+
}[kind] ?? "未知风险"
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
async function resolveCases(client, input, args) {
|
|
171
|
+
const cases = validateCaseSet(input?.cases);
|
|
172
|
+
if (input?.catalog === undefined)
|
|
173
|
+
throw new DatarcError("catalog is required", "INVALID_INPUT");
|
|
174
|
+
if (input.selections !== undefined && !Array.isArray(input.selections))
|
|
175
|
+
throw new DatarcError("selections must be an array", "INVALID_INPUT");
|
|
176
|
+
const resolutions = cases.map((semanticCase, index) => ({
|
|
177
|
+
sourceIndex: semanticCase.sourceIndex,
|
|
178
|
+
resolution: resolveTarget(
|
|
179
|
+
semanticCase.targetHint,
|
|
180
|
+
input.catalog,
|
|
181
|
+
input.selections?.[index] ?? {},
|
|
182
|
+
),
|
|
183
|
+
}));
|
|
184
|
+
const resolved = resolutions.filter(
|
|
185
|
+
({ resolution }) => resolution.mutationAllowed,
|
|
186
|
+
).length;
|
|
187
|
+
return withOptionalArtifact({ version: 1, cases, resolutions }, args.output, {
|
|
188
|
+
cases: cases.length,
|
|
189
|
+
resolved,
|
|
190
|
+
unresolved: cases.length - resolved,
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
async function resolveLive(client, input, args, options) {
|
|
195
|
+
const normalized = normalizeLiveResolutionInput(input);
|
|
196
|
+
return journalCommand({
|
|
197
|
+
command: "resolve-live",
|
|
198
|
+
workspaceId: normalized.workspaceId,
|
|
199
|
+
input,
|
|
200
|
+
request: liveResolutionJournalRequest(normalized),
|
|
201
|
+
output: required(args, "output"),
|
|
202
|
+
options,
|
|
203
|
+
operation: () => resolveLiveCases(client, normalized),
|
|
204
|
+
response: (result, artifact) => {
|
|
205
|
+
const resolved = result.resolutions.filter(
|
|
206
|
+
({ resolution }) => resolution.mutationAllowed,
|
|
207
|
+
).length;
|
|
208
|
+
return {
|
|
209
|
+
artifact,
|
|
210
|
+
summary: {
|
|
211
|
+
cases: result.resolutions.length,
|
|
212
|
+
resolved,
|
|
213
|
+
unresolved: result.resolutions.length - resolved,
|
|
214
|
+
},
|
|
215
|
+
};
|
|
216
|
+
},
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
async function reproduce(client, input, args, options) {
|
|
221
|
+
const normalized = normalizeReproductionInput(input);
|
|
222
|
+
const questionHash = createHash("sha256")
|
|
223
|
+
.update(normalized.question)
|
|
224
|
+
.digest("hex");
|
|
225
|
+
return journalCommand({
|
|
226
|
+
command: "reproduce",
|
|
227
|
+
workspaceId: normalized.workspaceId,
|
|
228
|
+
input,
|
|
229
|
+
request: {
|
|
230
|
+
workspaceId: normalized.workspaceId,
|
|
231
|
+
caseId: normalized.caseId,
|
|
232
|
+
sourceType: normalized.sourceType,
|
|
233
|
+
questionHash,
|
|
234
|
+
},
|
|
235
|
+
output: required(args, "output"),
|
|
236
|
+
options,
|
|
237
|
+
operation: () => reproduceCase(client, normalized, options),
|
|
238
|
+
response: (result, artifact) => ({
|
|
239
|
+
artifact,
|
|
240
|
+
summary: {
|
|
241
|
+
caseId: result.caseId,
|
|
242
|
+
sourceType: result.sourceType,
|
|
243
|
+
state: result.message.state,
|
|
244
|
+
cutPairCount: result.cut.pairs.length,
|
|
245
|
+
interpretationCount: result.message.interpretations.length,
|
|
246
|
+
},
|
|
247
|
+
}),
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
async function plan(client, input, args, options) {
|
|
252
|
+
const output = required(args, "output");
|
|
253
|
+
const workspaceId = required(input ?? {}, "workspaceId");
|
|
254
|
+
if (args.direction !== undefined) {
|
|
255
|
+
const expected = hashArtifactValue(
|
|
256
|
+
[].concat(input?.operations ?? []).map((operation) => ({
|
|
257
|
+
caseId: String(operation?.caseId ?? "").trim(),
|
|
258
|
+
suggestedKind: operation?.kind,
|
|
259
|
+
})),
|
|
260
|
+
);
|
|
261
|
+
if (args.direction !== expected)
|
|
262
|
+
throw new DatarcError(
|
|
263
|
+
"direction confirmation does not match the operations",
|
|
264
|
+
"DIRECTION_MISMATCH",
|
|
265
|
+
);
|
|
266
|
+
}
|
|
267
|
+
const grouped = new Map();
|
|
268
|
+
for (const operation of input?.operations ?? []) {
|
|
269
|
+
if (!operation || typeof operation?.kind !== "string" || !operation.kind)
|
|
270
|
+
throw new DatarcError("each operation requires a kind", "INVALID_INPUT");
|
|
271
|
+
if (!grouped.has(operation.kind)) grouped.set(operation.kind, []);
|
|
272
|
+
grouped.get(operation.kind).push(operation);
|
|
273
|
+
}
|
|
274
|
+
if (grouped.size === 0)
|
|
275
|
+
throw new DatarcError(
|
|
276
|
+
"operations must be a non-empty array",
|
|
277
|
+
"INVALID_INPUT",
|
|
278
|
+
);
|
|
279
|
+
|
|
280
|
+
const multi = grouped.size > 1;
|
|
281
|
+
const reservations = [];
|
|
282
|
+
for (const [kind, operations] of grouped) {
|
|
283
|
+
const subInput = {
|
|
284
|
+
workspaceId,
|
|
285
|
+
operations,
|
|
286
|
+
...(input.planningEvidence === undefined
|
|
287
|
+
? {}
|
|
288
|
+
: { planningEvidence: input.planningEvidence }),
|
|
289
|
+
};
|
|
290
|
+
const identity = createCommandArtifactIdentity({
|
|
291
|
+
command: "plan",
|
|
292
|
+
workspaceId,
|
|
293
|
+
request: subInput,
|
|
294
|
+
});
|
|
295
|
+
const path = multi ? `${output}.${kind}` : output;
|
|
296
|
+
reservations.push({
|
|
297
|
+
kind,
|
|
298
|
+
subInput,
|
|
299
|
+
identity,
|
|
300
|
+
path,
|
|
301
|
+
optional: false,
|
|
302
|
+
reserved: await reserveArtifact(
|
|
303
|
+
path,
|
|
304
|
+
{ ...identity, status: "reserved" },
|
|
305
|
+
{
|
|
306
|
+
openArtifact: options.openArtifact,
|
|
307
|
+
openDirectory: options.openDirectory,
|
|
308
|
+
journalId: options.journalId,
|
|
309
|
+
},
|
|
310
|
+
),
|
|
311
|
+
});
|
|
312
|
+
if (kind === "knowledge" && promptBridgePlan !== undefined) {
|
|
313
|
+
const promptPath = `${output}.prompt_bridge`;
|
|
314
|
+
const promptIdentity = createCommandArtifactIdentity({
|
|
315
|
+
command: "plan",
|
|
316
|
+
workspaceId,
|
|
317
|
+
request: subInput,
|
|
318
|
+
});
|
|
319
|
+
reservations.push({
|
|
320
|
+
kind: "prompt_bridge",
|
|
321
|
+
subInput,
|
|
322
|
+
identity: promptIdentity,
|
|
323
|
+
path: promptPath,
|
|
324
|
+
optional: true,
|
|
325
|
+
reserved: await reserveArtifact(
|
|
326
|
+
promptPath,
|
|
327
|
+
{ ...promptIdentity, status: "reserved" },
|
|
328
|
+
{
|
|
329
|
+
openArtifact: options.openArtifact,
|
|
330
|
+
openDirectory: options.openDirectory,
|
|
331
|
+
journalId: options.journalId,
|
|
332
|
+
},
|
|
333
|
+
),
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
const plans = [];
|
|
339
|
+
let failure = null;
|
|
340
|
+
try {
|
|
341
|
+
for (const reservation of reservations) {
|
|
342
|
+
if (reservation.kind === "prompt_bridge") continue;
|
|
343
|
+
await appendReservedArtifact(reservation.reserved, {
|
|
344
|
+
...reservation.identity,
|
|
345
|
+
status: "running",
|
|
346
|
+
});
|
|
347
|
+
const prepared = await preparePlan(client, reservation.subInput, options);
|
|
348
|
+
await appendReservedArtifact(
|
|
349
|
+
reservation.reserved,
|
|
350
|
+
completeCommandArtifact(reservation.identity, prepared),
|
|
351
|
+
);
|
|
352
|
+
plans.push({
|
|
353
|
+
kind: reservation.kind,
|
|
354
|
+
artifact: reservation.reserved.artifact,
|
|
355
|
+
hash: prepared.planHash,
|
|
356
|
+
});
|
|
357
|
+
if (prepared.promptChanges?.length && promptBridgePlan !== undefined) {
|
|
358
|
+
const promptReservation = reservations.find(
|
|
359
|
+
(r) => r.kind === "prompt_bridge",
|
|
360
|
+
);
|
|
361
|
+
await appendReservedArtifact(promptReservation.reserved, {
|
|
362
|
+
...promptReservation.identity,
|
|
363
|
+
status: "running",
|
|
364
|
+
});
|
|
365
|
+
const promptPlan = promptBridgePlan(prepared, workspaceId);
|
|
366
|
+
await appendReservedArtifact(
|
|
367
|
+
promptReservation.reserved,
|
|
368
|
+
completeCommandArtifact(promptReservation.identity, promptPlan),
|
|
369
|
+
);
|
|
370
|
+
plans.push({
|
|
371
|
+
kind: "prompt_bridge",
|
|
372
|
+
artifact: promptReservation.reserved.artifact,
|
|
373
|
+
hash: promptPlan.planHash,
|
|
374
|
+
dependsOn: prepared.planHash,
|
|
375
|
+
});
|
|
376
|
+
promptReservation.used = true;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
} catch (error) {
|
|
380
|
+
failure = error;
|
|
381
|
+
} finally {
|
|
382
|
+
for (const reservation of reservations) {
|
|
383
|
+
await reservation.reserved.handle.close();
|
|
384
|
+
if (reservation.optional && !reservation.used)
|
|
385
|
+
await unlink(reservation.path).catch(() => {});
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
if (failure) {
|
|
389
|
+
const failedReservation =
|
|
390
|
+
reservations.find((r) => r.kind !== "prompt_bridge" || r.used) ??
|
|
391
|
+
reservations[0];
|
|
392
|
+
throw commandJournalFailure(failure, failedReservation.reserved, "plan");
|
|
393
|
+
}
|
|
394
|
+
return {
|
|
395
|
+
plans: plans.map(({ kind, artifact, hash, dependsOn }) => ({
|
|
396
|
+
kind,
|
|
397
|
+
artifact,
|
|
398
|
+
...(dependsOn === undefined ? {} : { dependsOn }),
|
|
399
|
+
hash,
|
|
400
|
+
})),
|
|
401
|
+
};
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
async function apply(client, inputs, args, options) {
|
|
405
|
+
const plans = Array.isArray(inputs) ? inputs : [inputs];
|
|
406
|
+
if (plans.length === 0)
|
|
407
|
+
throw new DatarcError("apply requires at least one plan", "INVALID_INPUT");
|
|
408
|
+
const outputs = [].concat(args.output ?? []);
|
|
409
|
+
const confirmations = [].concat(args.confirm ?? []);
|
|
410
|
+
if (outputs.length !== plans.length || confirmations.length !== plans.length)
|
|
411
|
+
throw new DatarcError(
|
|
412
|
+
"apply requires one --output and one --confirm per --input plan",
|
|
413
|
+
"INVALID_ARGUMENT",
|
|
414
|
+
);
|
|
415
|
+
const ordered = orderPlans(plans);
|
|
416
|
+
const applied = [];
|
|
417
|
+
for (const plan of ordered) {
|
|
418
|
+
const index = plans.indexOf(plan);
|
|
419
|
+
applied.push(
|
|
420
|
+
await applyOne(
|
|
421
|
+
client,
|
|
422
|
+
plan,
|
|
423
|
+
confirmations[index],
|
|
424
|
+
outputs[index],
|
|
425
|
+
options,
|
|
426
|
+
),
|
|
427
|
+
);
|
|
428
|
+
}
|
|
429
|
+
return applied.length === 1 ? applied[0] : { applications: applied };
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
function orderPlans(plans) {
|
|
433
|
+
const byHash = new Map(plans.map((plan) => [plan.planHash, plan]));
|
|
434
|
+
const ordered = [];
|
|
435
|
+
const visited = new Set();
|
|
436
|
+
const visiting = new Set();
|
|
437
|
+
const visit = (plan) => {
|
|
438
|
+
if (visited.has(plan.planHash)) return;
|
|
439
|
+
if (visiting.has(plan.planHash))
|
|
440
|
+
throw new DatarcError("apply dependency cycle", "DEPENDENCY_CYCLE");
|
|
441
|
+
visiting.add(plan.planHash);
|
|
442
|
+
if (plan.dependsOn !== undefined) {
|
|
443
|
+
const dependency = byHash.get(plan.dependsOn);
|
|
444
|
+
if (dependency !== undefined) visit(dependency);
|
|
445
|
+
}
|
|
446
|
+
visiting.delete(plan.planHash);
|
|
447
|
+
visited.add(plan.planHash);
|
|
448
|
+
ordered.push(plan);
|
|
449
|
+
};
|
|
450
|
+
for (const plan of plans) visit(plan);
|
|
451
|
+
return ordered;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
async function applyOne(client, plan, confirmation, output, options) {
|
|
455
|
+
requireConfirmation(confirmation, "APPLY", plan?.planHash);
|
|
456
|
+
validateApplyPlan(plan, confirmation);
|
|
457
|
+
const reserved = await reserveArtifact(
|
|
458
|
+
output,
|
|
459
|
+
{
|
|
460
|
+
status: "reserved",
|
|
461
|
+
plan,
|
|
462
|
+
},
|
|
463
|
+
{
|
|
464
|
+
openArtifact: options.openArtifact,
|
|
465
|
+
openDirectory: options.openDirectory,
|
|
466
|
+
journalId: options.journalId,
|
|
467
|
+
},
|
|
468
|
+
);
|
|
469
|
+
|
|
470
|
+
try {
|
|
471
|
+
const baseline = await captureSyncBaseline(client, plan.workspaceId);
|
|
472
|
+
const mutationStartedAt = timestamp(options.now);
|
|
473
|
+
const progressBundle = (receipt) => ({
|
|
474
|
+
status: "applying",
|
|
475
|
+
plan,
|
|
476
|
+
baseline,
|
|
477
|
+
mutationStartedAt,
|
|
478
|
+
receipt,
|
|
479
|
+
});
|
|
480
|
+
try {
|
|
481
|
+
const receipt = await applyPlan(client, plan, confirmation, {
|
|
482
|
+
onProgress: (progressReceipt) =>
|
|
483
|
+
appendReservedArtifact(reserved, progressBundle(progressReceipt)),
|
|
484
|
+
});
|
|
485
|
+
const bundle = { plan, receipt, baseline, mutationStartedAt };
|
|
486
|
+
await appendReservedArtifact(reserved, bundle);
|
|
487
|
+
return {
|
|
488
|
+
artifact: reserved.artifact,
|
|
489
|
+
summary: {
|
|
490
|
+
workspaceId: receipt.workspaceId,
|
|
491
|
+
completedSteps: receipt.completedSteps.length,
|
|
492
|
+
},
|
|
493
|
+
hash: receipt.receiptHash,
|
|
494
|
+
};
|
|
495
|
+
} catch (error) {
|
|
496
|
+
if (reserved.syncAmbiguous)
|
|
497
|
+
throw new DatarcError(
|
|
498
|
+
"artifact sync result is ambiguous; reload the artifact",
|
|
499
|
+
error.code ?? "ARTIFACT_WRITE_FAILED",
|
|
500
|
+
{
|
|
501
|
+
artifact: reserved.artifact,
|
|
502
|
+
phase: "apply",
|
|
503
|
+
partial: true,
|
|
504
|
+
reloadRequired: true,
|
|
505
|
+
},
|
|
506
|
+
);
|
|
507
|
+
const durableReceipt = reserved.lastDurableValue?.receipt;
|
|
508
|
+
if (!durableReceipt) throw error;
|
|
509
|
+
throw new DatarcError(
|
|
510
|
+
"apply failed; partial receipt saved",
|
|
511
|
+
error.code ?? "APPLY_FAILED",
|
|
512
|
+
{
|
|
513
|
+
artifact: reserved.artifact,
|
|
514
|
+
hash: durableReceipt.receiptHash,
|
|
515
|
+
phase: "apply",
|
|
516
|
+
partial: true,
|
|
517
|
+
},
|
|
518
|
+
);
|
|
519
|
+
}
|
|
520
|
+
} finally {
|
|
521
|
+
await reserved.handle.close();
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
async function verify(client, input, args, options) {
|
|
526
|
+
const bundle = receiptBundle(input);
|
|
527
|
+
if (!validateFinalBundle(bundle))
|
|
528
|
+
throw new DatarcError(
|
|
529
|
+
"verification requires a complete hash-valid plan and receipt bundle",
|
|
530
|
+
"INVALID_RECEIPT",
|
|
531
|
+
);
|
|
532
|
+
validateApplyPlan(bundle.plan, `APPLY:${bundle.plan.planHash}`);
|
|
533
|
+
if (Object.hasOwn(input ?? {}, "syncTargets"))
|
|
534
|
+
throw new DatarcError(
|
|
535
|
+
"sync targets are derived from the verified plan",
|
|
536
|
+
"CALLER_SYNC_TARGETS_FORBIDDEN",
|
|
537
|
+
);
|
|
538
|
+
const receipt = bundle.receipt;
|
|
539
|
+
const verificationInput = bindVerificationToAuthorities(
|
|
540
|
+
bundle.plan.authorities,
|
|
541
|
+
input.verification,
|
|
542
|
+
bundle.plan.steps,
|
|
543
|
+
);
|
|
544
|
+
const syncTargets = deriveVerificationSyncTargets(bundle.plan, receipt);
|
|
545
|
+
return journalCommand({
|
|
546
|
+
command: "verify",
|
|
547
|
+
workspaceId: receipt.workspaceId,
|
|
548
|
+
input,
|
|
549
|
+
request: verifyJournalRequest(verificationInput, bundle),
|
|
550
|
+
output: required(args, "output"),
|
|
551
|
+
options,
|
|
552
|
+
operation: async () => {
|
|
553
|
+
const poll = input?.poll ?? {};
|
|
554
|
+
let synchronization = null;
|
|
555
|
+
if (receipt.completedSteps?.some((step) => step.dictionarySyncRequired)) {
|
|
556
|
+
synchronization = await waitForFreshDictionary(
|
|
557
|
+
client,
|
|
558
|
+
receipt.workspaceId,
|
|
559
|
+
{
|
|
560
|
+
baseline: bundle.baseline,
|
|
561
|
+
mutationAt: bundle.mutationStartedAt,
|
|
562
|
+
targets: syncTargets,
|
|
563
|
+
},
|
|
564
|
+
poll,
|
|
565
|
+
);
|
|
566
|
+
}
|
|
567
|
+
const verification = await verifyReceipt(
|
|
568
|
+
client,
|
|
569
|
+
receipt,
|
|
570
|
+
verificationInput,
|
|
571
|
+
poll,
|
|
572
|
+
);
|
|
573
|
+
return { synchronization, verification };
|
|
574
|
+
},
|
|
575
|
+
response: (result, artifact) => ({
|
|
576
|
+
artifact,
|
|
577
|
+
summary: {
|
|
578
|
+
status: result.verification.status,
|
|
579
|
+
passed: result.verification.passed,
|
|
580
|
+
automatedChecksPassed: result.verification.automatedChecksPassed,
|
|
581
|
+
manualConfirmationRequired:
|
|
582
|
+
result.verification.manualConfirmationRequired,
|
|
583
|
+
suites: result.verification.suites.length,
|
|
584
|
+
probes: result.verification.suites.reduce(
|
|
585
|
+
(count, suite) => count + suite.probes.length,
|
|
586
|
+
0,
|
|
587
|
+
),
|
|
588
|
+
synchronization:
|
|
589
|
+
result.synchronization === null ? "not_required" : "fresh",
|
|
590
|
+
receiptHash: receipt.receiptHash,
|
|
591
|
+
},
|
|
592
|
+
}),
|
|
593
|
+
});
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
async function rollback(client, input, args, options) {
|
|
597
|
+
const bundle = receiptBundle(input);
|
|
598
|
+
if (!validateRollbackBundle(bundle))
|
|
599
|
+
throw new DatarcError(
|
|
600
|
+
"rollback requires one hash-valid plan and bound receipt bundle",
|
|
601
|
+
"INVALID_RECEIPT",
|
|
602
|
+
);
|
|
603
|
+
validateApplyPlan(bundle.plan, `APPLY:${bundle.plan.planHash}`);
|
|
604
|
+
const confirmation = required(args, "confirm");
|
|
605
|
+
requireConfirmation(confirmation, "ROLLBACK", bundle.receipt?.receiptHash);
|
|
606
|
+
const receipt = bundle.receipt;
|
|
607
|
+
return journalCommand({
|
|
608
|
+
command: "rollback",
|
|
609
|
+
workspaceId: receipt.workspaceId,
|
|
610
|
+
input,
|
|
611
|
+
request: rollbackJournalRequest(receipt),
|
|
612
|
+
output: required(args, "output"),
|
|
613
|
+
options,
|
|
614
|
+
operation: async ({ identity, reserved }) => {
|
|
615
|
+
let syncAnchor = null;
|
|
616
|
+
const result = await rollbackReceipt(client, receipt, confirmation, {
|
|
617
|
+
beforeDictionaryMutation: async () => {
|
|
618
|
+
const baseline = await captureSyncBaseline(
|
|
619
|
+
client,
|
|
620
|
+
receipt.workspaceId,
|
|
621
|
+
);
|
|
622
|
+
const mutationStartedAt = timestamp(options.now);
|
|
623
|
+
await appendReservedArtifact(reserved, {
|
|
624
|
+
...identity,
|
|
625
|
+
status: "running",
|
|
626
|
+
rollbackSync: { baseline, mutationStartedAt },
|
|
627
|
+
});
|
|
628
|
+
syncAnchor = { baseline, mutationStartedAt };
|
|
629
|
+
},
|
|
630
|
+
});
|
|
631
|
+
let synchronization = null;
|
|
632
|
+
if (result.dictionaryMutations > 0) {
|
|
633
|
+
if (syncAnchor === null)
|
|
634
|
+
throw new DatarcError(
|
|
635
|
+
"dictionary rollback is missing a durable sync anchor",
|
|
636
|
+
"ROLLBACK_SYNC_ANCHOR_MISSING",
|
|
637
|
+
);
|
|
638
|
+
synchronization = await waitForFreshDictionary(
|
|
639
|
+
client,
|
|
640
|
+
receipt.workspaceId,
|
|
641
|
+
{
|
|
642
|
+
baseline: syncAnchor.baseline,
|
|
643
|
+
mutationAt: syncAnchor.mutationStartedAt,
|
|
644
|
+
targets: [],
|
|
645
|
+
},
|
|
646
|
+
options,
|
|
647
|
+
);
|
|
648
|
+
}
|
|
649
|
+
return { ...result, synchronization };
|
|
650
|
+
},
|
|
651
|
+
response: (result, artifact) => ({
|
|
652
|
+
artifact,
|
|
653
|
+
summary: {
|
|
654
|
+
restored: result.restored.length,
|
|
655
|
+
receiptHash: result.receiptHash,
|
|
656
|
+
synchronization:
|
|
657
|
+
result.synchronization === null ? "not_required" : "fresh",
|
|
658
|
+
},
|
|
659
|
+
}),
|
|
660
|
+
});
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
function receiptBundle(input) {
|
|
664
|
+
if (input?.receipt && typeof input.receipt === "object") return input;
|
|
665
|
+
return { receipt: input };
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
function verifyJournalRequest(verification, bundle) {
|
|
669
|
+
return {
|
|
670
|
+
workspaceId: bundle.receipt.workspaceId,
|
|
671
|
+
planHash: bundle.plan.planHash,
|
|
672
|
+
receiptHash: bundle.receipt.receiptHash,
|
|
673
|
+
suites: verification.suites.map((suite) => ({
|
|
674
|
+
caseId: suite.caseId,
|
|
675
|
+
gate: suite.gate,
|
|
676
|
+
probes: suite.probes.map((probe) => ({
|
|
677
|
+
kind: probe.kind,
|
|
678
|
+
questionHash: hashArtifactValue(probe.question),
|
|
679
|
+
expectation: {
|
|
680
|
+
expectedProps: journalStrings(probe.expectedProps),
|
|
681
|
+
forbiddenProps: journalStrings(probe.forbiddenProps),
|
|
682
|
+
},
|
|
683
|
+
})),
|
|
684
|
+
})),
|
|
685
|
+
};
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
function rollbackJournalRequest(receipt) {
|
|
689
|
+
return {
|
|
690
|
+
workspaceId: receipt?.workspaceId,
|
|
691
|
+
planHash: receipt?.planHash,
|
|
692
|
+
receiptHash: receipt?.receiptHash,
|
|
693
|
+
};
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
function journalStrings(values) {
|
|
697
|
+
if (!Array.isArray(values)) return [];
|
|
698
|
+
return [
|
|
699
|
+
...new Set(values.map((value) => String(value).trim()).filter(Boolean)),
|
|
700
|
+
];
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
const { execute, run, HELP_TEXT } = createCli({
|
|
704
|
+
commandNames: Object.keys(COMMAND_FLAGS),
|
|
705
|
+
flags: COMMAND_FLAGS,
|
|
706
|
+
help: HELP_TEXT_DEFINITION,
|
|
707
|
+
localCommands: ["direction", "diagnose", "resolve"],
|
|
708
|
+
requiresOutput: [
|
|
709
|
+
"resolve-live",
|
|
710
|
+
"reproduce",
|
|
711
|
+
"plan",
|
|
712
|
+
"apply",
|
|
713
|
+
"verify",
|
|
714
|
+
"rollback",
|
|
715
|
+
],
|
|
716
|
+
repeatableFlags: { apply: ["input", "output", "confirm"] },
|
|
717
|
+
handlers: {
|
|
718
|
+
direction,
|
|
719
|
+
diagnose,
|
|
720
|
+
resolve: resolveCases,
|
|
721
|
+
"resolve-live": resolveLive,
|
|
722
|
+
reproduce,
|
|
723
|
+
plan,
|
|
724
|
+
apply,
|
|
725
|
+
verify,
|
|
726
|
+
rollback,
|
|
727
|
+
},
|
|
728
|
+
});
|
|
729
|
+
|
|
730
|
+
async function runCli(argv = process.argv.slice(2)) {
|
|
731
|
+
if (argv.includes("--help")) process.stdout.write(`${HELP_TEXT}\n`);
|
|
732
|
+
else {
|
|
733
|
+
const result = await run(argv);
|
|
734
|
+
process.stdout.write(`${JSON.stringify(result)}\n`);
|
|
735
|
+
if (!result.ok) process.exitCode = 1;
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
return { execute, run, HELP_TEXT, runCli };
|
|
740
|
+
}
|