sim 2.2.33-preview.319.1 → 2.2.33-preview.321.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/protocol/source-check.d.ts +7 -0
- package/dist/commands/protocol/source-dir/command-lock.d.ts +1 -1
- package/dist/commands/protocol/source-dir/layout.d.ts +8 -6
- package/dist/commands/protocol/source-status.d.ts +2 -0
- package/dist/commands/protocol/workflow-dir.d.ts +9 -0
- package/dist/commands/protocol/workspace-source-dir.d.ts +5 -0
- package/dist/generated/v2-api.d.ts +3 -0
- package/dist/index.js +282 -69
- package/dist/runtime.js +282 -69
- package/package.json +1 -1
package/dist/runtime.js
CHANGED
|
@@ -42446,6 +42446,7 @@ class CliUsageError extends LocalRefusal {
|
|
|
42446
42446
|
}
|
|
42447
42447
|
|
|
42448
42448
|
// src/commands/protocol/source-dir/command-lock.ts
|
|
42449
|
+
import { rmSync as rmSync3 } from "node:fs";
|
|
42449
42450
|
import { lstat as lstat3, mkdir as mkdir2, readFile as readFile2, realpath as realpath2, rm as rm3, rmdir, stat as stat2, writeFile as writeFile2 } from "node:fs/promises";
|
|
42450
42451
|
import { hostname } from "node:os";
|
|
42451
42452
|
import { dirname as dirname7, join as join6, resolve as resolve4 } from "node:path";
|
|
@@ -46036,7 +46037,7 @@ function formerBlockHint(ctx, formerKey, renamed, rewritten, spell) {
|
|
|
46036
46037
|
const unbound = [...ctx.declsByKey.values()].filter((decl) => !ctx.knownKeys.has(decl.key) && !renamedTo.has(decl.key));
|
|
46037
46038
|
const lead = `${spell([{ kind: "name", name: formerKey }])} is a block this workflow had that ${SOURCE_ENTRY_FILE} no longer declares under that key`;
|
|
46038
46039
|
const [only] = unbound;
|
|
46039
|
-
return unbound.length === 1 && only ? `${lead}: if ${only.name}
|
|
46040
|
+
return unbound.length === 1 && only ? `${lead}: if it was renamed to ${only.name}, an apply that keeps its id rewrites this reference to ${rewritten(only.key)}, so no edit is needed.` : `${lead}: if you renamed it, write ${spell([{ kind: "name", name: "newkey" }])}, where newkey is its display name lowercased with whitespace and dots removed.`;
|
|
46040
46041
|
}
|
|
46041
46042
|
function subflowScopeRef(ctx, node, container, members, site) {
|
|
46042
46043
|
const kind = containerKindOf(container) ?? "loop";
|
|
@@ -48326,8 +48327,11 @@ function readCodeFile(ctx, compiled, language, decl) {
|
|
|
48326
48327
|
}
|
|
48327
48328
|
function parseCodeFile(ctx, path, text, language, at, decl) {
|
|
48328
48329
|
const { limits } = ctx;
|
|
48330
|
+
const before = ctx.codeFiles.bytes;
|
|
48329
48331
|
ctx.codeFiles.bytes += utf8Bytes(text, limits.maxTotalBytes);
|
|
48330
48332
|
if (ctx.codeFiles.bytes > limits.maxTotalBytes) {
|
|
48333
|
+
if (before > limits.maxTotalBytes)
|
|
48334
|
+
return null;
|
|
48331
48335
|
ctx.reporter.report("E_LIMIT_EXCEEDED", `The workflow and its code files total more than ${limits.maxTotalBytes} bytes.`, at, { hint: "Share one code file between blocks, or shorten the code.", blockKey: decl.key });
|
|
48332
48336
|
return null;
|
|
48333
48337
|
}
|
|
@@ -50466,6 +50470,9 @@ var refusalClass = refusalClassifier();
|
|
|
50466
50470
|
var CHANGED_BLOCK_REFUSALS = new Map([
|
|
50467
50471
|
["W_REF_OUT_OF_SCOPE", "E_APPLY_REF_OUT_OF_SCOPE"]
|
|
50468
50472
|
]);
|
|
50473
|
+
var PARAM_REFUSALS = new Map([
|
|
50474
|
+
["W_UNKNOWN_OPTION", "E_APPLY_INVALID_SUBBLOCK_FIELD"]
|
|
50475
|
+
]);
|
|
50469
50476
|
var ENTRY_REFUSALS = new Map([
|
|
50470
50477
|
["W_UNKNOWN_OUTPUT_PATH", "E_APPLY_UNRESOLVED_REF"]
|
|
50471
50478
|
]);
|
|
@@ -50475,6 +50482,7 @@ var CODE_FILE_REFUSALS = new Map([
|
|
|
50475
50482
|
["W_CODE_FILE_REF_SYNTAX", "E_APPLY_CODE_FILE_REF_SYNTAX"]
|
|
50476
50483
|
]);
|
|
50477
50484
|
var REFUSABLE_WARNING_CODES = new Set([
|
|
50485
|
+
"W_UNKNOWN_OPTION",
|
|
50478
50486
|
"W_REF_OUT_OF_SCOPE",
|
|
50479
50487
|
"W_UNKNOWN_OUTPUT_PATH",
|
|
50480
50488
|
"W_UNRESOLVED_REF",
|
|
@@ -50486,6 +50494,11 @@ var EDIT_REFUSALS = [
|
|
|
50486
50494
|
refusal,
|
|
50487
50495
|
where: "changed block"
|
|
50488
50496
|
})),
|
|
50497
|
+
...[...PARAM_REFUSALS].map(([warning, refusal]) => ({
|
|
50498
|
+
warning,
|
|
50499
|
+
refusal,
|
|
50500
|
+
where: "workflow.ts"
|
|
50501
|
+
})),
|
|
50489
50502
|
...[...ENTRY_REFUSALS].map(([warning, refusal]) => ({
|
|
50490
50503
|
warning,
|
|
50491
50504
|
refusal,
|
|
@@ -50511,6 +50524,15 @@ function refusalOf(finding, edit) {
|
|
|
50511
50524
|
const edited = edit.changed(blockKey) || !inEntryFile && edit.codeEdited(blockKey, span.file);
|
|
50512
50525
|
return edited ? onChanged : undefined;
|
|
50513
50526
|
}
|
|
50527
|
+
const onParam = PARAM_REFUSALS.get(finding.code);
|
|
50528
|
+
if (onParam) {
|
|
50529
|
+
const { param } = finding;
|
|
50530
|
+
if (!inEntryFile || param === undefined || param === "operation")
|
|
50531
|
+
return;
|
|
50532
|
+
if (!edit.changed(blockKey))
|
|
50533
|
+
return;
|
|
50534
|
+
return edit.paramChanged?.(blockKey, param) ?? true ? onParam : undefined;
|
|
50535
|
+
}
|
|
50514
50536
|
if (inEntryFile) {
|
|
50515
50537
|
const inEntry = ENTRY_REFUSALS.get(finding.code);
|
|
50516
50538
|
return inEntry && edit.changed(blockKey) ? inEntry : undefined;
|
|
@@ -50518,6 +50540,9 @@ function refusalOf(finding, edit) {
|
|
|
50518
50540
|
const inCode = CODE_FILE_REFUSALS.get(finding.code);
|
|
50519
50541
|
return inCode && edit.codeEdited(blockKey, span.file) ? inCode : undefined;
|
|
50520
50542
|
}
|
|
50543
|
+
function refusesEdited(finding, edit) {
|
|
50544
|
+
return refusalOf(finding, edit) !== undefined;
|
|
50545
|
+
}
|
|
50521
50546
|
function refuseEditedFindings(compiled, edit) {
|
|
50522
50547
|
const refused = (finding) => {
|
|
50523
50548
|
const code = refusalOf(finding, edit);
|
|
@@ -50701,6 +50726,10 @@ function capLength(text) {
|
|
|
50701
50726
|
class Reporter {
|
|
50702
50727
|
diagnostics = [];
|
|
50703
50728
|
withheld = [];
|
|
50729
|
+
get omitted() {
|
|
50730
|
+
return [...this.omittedCounts.values()];
|
|
50731
|
+
}
|
|
50732
|
+
omittedCounts = new Map;
|
|
50704
50733
|
refusableHeld = new Set;
|
|
50705
50734
|
indexes = new Map;
|
|
50706
50735
|
errorCount = 0;
|
|
@@ -50744,7 +50773,7 @@ class Reporter {
|
|
|
50744
50773
|
if (this.infoCount >= MAX_LISTED)
|
|
50745
50774
|
return;
|
|
50746
50775
|
} else if (this.warningCount >= MAX_LISTED) {
|
|
50747
|
-
this.
|
|
50776
|
+
this.omit(code, message, at, extras);
|
|
50748
50777
|
if (this.warningCount === MAX_LISTED) {
|
|
50749
50778
|
this.truncated(`Listed ${MAX_LISTED} warnings; the rest are omitted. The next: ${message}`, at, framesSource(code));
|
|
50750
50779
|
}
|
|
@@ -50753,7 +50782,7 @@ class Reporter {
|
|
|
50753
50782
|
const ofCode = this.warningsByCode.get(code) ?? 0;
|
|
50754
50783
|
this.warningsByCode.set(code, ofCode + 1);
|
|
50755
50784
|
if (ofCode >= MAX_WARNINGS_PER_CODE) {
|
|
50756
|
-
this.
|
|
50785
|
+
this.omit(code, message, at, extras);
|
|
50757
50786
|
if (ofCode === MAX_WARNINGS_PER_CODE) {
|
|
50758
50787
|
this.truncated(`Listed ${MAX_WARNINGS_PER_CODE} ${code} warnings; the rest of them are omitted. The next: ${message}`, at, framesSource(code));
|
|
50759
50788
|
}
|
|
@@ -50765,10 +50794,25 @@ class Reporter {
|
|
|
50765
50794
|
this.refusableHeld.add(held);
|
|
50766
50795
|
this.record(code, message, at, extras, framesSource(code));
|
|
50767
50796
|
}
|
|
50768
|
-
|
|
50797
|
+
omit(code, message, at, extras) {
|
|
50769
50798
|
const held = refusableKey(code, at, extras);
|
|
50770
|
-
if (held === undefined || this.refusableHeld.has(held))
|
|
50799
|
+
if (held === undefined || this.refusableHeld.has(held)) {
|
|
50800
|
+
const refusable = held === undefined ? undefined : { file: at.file, param: extras.param };
|
|
50801
|
+
const key = [code, extras.blockKey ?? "", refusable?.file ?? "", refusable?.param ?? ""].join("\x00");
|
|
50802
|
+
const counted = this.omittedCounts.get(key);
|
|
50803
|
+
if (counted)
|
|
50804
|
+
counted.count++;
|
|
50805
|
+
else {
|
|
50806
|
+
this.omittedCounts.set(key, {
|
|
50807
|
+
code,
|
|
50808
|
+
...extras.blockKey !== undefined ? { blockKey: extras.blockKey } : {},
|
|
50809
|
+
...refusable ? { file: refusable.file } : {},
|
|
50810
|
+
...refusable?.param !== undefined ? { param: refusable.param } : {},
|
|
50811
|
+
count: 1
|
|
50812
|
+
});
|
|
50813
|
+
}
|
|
50771
50814
|
return;
|
|
50815
|
+
}
|
|
50772
50816
|
this.refusableHeld.add(held);
|
|
50773
50817
|
const { hint, ...listed } = extras;
|
|
50774
50818
|
const diagnostic = this.build(code, message, at, listed, framesSource(code));
|
|
@@ -51324,6 +51368,7 @@ function emptyResult(reporter, sdkMajor) {
|
|
|
51324
51368
|
workflow: null,
|
|
51325
51369
|
diagnostics: reporter.diagnostics,
|
|
51326
51370
|
withheld: reporter.withheld,
|
|
51371
|
+
omitted: reporter.omitted,
|
|
51327
51372
|
spans: {},
|
|
51328
51373
|
metaSpans: {},
|
|
51329
51374
|
hints: { blocks: {} },
|
|
@@ -51562,6 +51607,7 @@ function compileEntry(input, file, text, reporter) {
|
|
|
51562
51607
|
workflow,
|
|
51563
51608
|
diagnostics: reporter.diagnostics,
|
|
51564
51609
|
withheld: reporter.withheld,
|
|
51610
|
+
omitted: reporter.omitted,
|
|
51565
51611
|
spans,
|
|
51566
51612
|
metaSpans: ctx.metaSpans,
|
|
51567
51613
|
hints,
|
|
@@ -52556,7 +52602,7 @@ function assertSendableCodeFiles(files) {
|
|
|
52556
52602
|
}
|
|
52557
52603
|
function sourceRelativePath(path) {
|
|
52558
52604
|
const normalized = posix2.normalize(path.replace(/\\/g, "/"));
|
|
52559
|
-
if (normalized.startsWith("/") || /^[A-Za-z]:/.test(normalized) || normalized === "." || normalized === ".." || normalized.startsWith("../")) {
|
|
52605
|
+
if (normalized.includes("\x00") || normalized.startsWith("/") || /^[A-Za-z]:/.test(normalized) || normalized === "." || normalized === ".." || normalized.startsWith("../")) {
|
|
52560
52606
|
return null;
|
|
52561
52607
|
}
|
|
52562
52608
|
return normalized.startsWith("./") ? normalized.slice(2) : normalized;
|
|
@@ -52571,11 +52617,11 @@ function lockCodeFiles(lock) {
|
|
|
52571
52617
|
}
|
|
52572
52618
|
return paths;
|
|
52573
52619
|
}
|
|
52574
|
-
function orphanedCodeFiles(previousLock, nextLock, written) {
|
|
52620
|
+
function orphanedCodeFiles(previousLock, nextLock, written, recorded) {
|
|
52575
52621
|
const kept = lockCodeFiles(nextLock);
|
|
52576
52622
|
for (const path of written)
|
|
52577
52623
|
kept.add(path);
|
|
52578
|
-
return [...lockCodeFiles(previousLock)].filter((path) => path.startsWith(`${SOURCE_CODE_DIR}/`) && isCodeFilePath(path) && !kept.has(path));
|
|
52624
|
+
return [...lockCodeFiles(previousLock)].filter((path) => path.startsWith(`${SOURCE_CODE_DIR}/`) && isCodeFilePath(path) && Object.hasOwn(recorded, path) && !kept.has(path));
|
|
52579
52625
|
}
|
|
52580
52626
|
function writableFiles(files) {
|
|
52581
52627
|
const refused = refusedSourcePaths(files);
|
|
@@ -52956,8 +53002,12 @@ async function withSourceDirLock(dir, run, options = {}) {
|
|
|
52956
53002
|
await writeFile2(join6(lock, LOCK_OWNER_FILE), JSON.stringify(owner));
|
|
52957
53003
|
return await run();
|
|
52958
53004
|
} finally {
|
|
52959
|
-
|
|
52960
|
-
|
|
53005
|
+
try {
|
|
53006
|
+
const held = await checkedPath(root, SOURCE_DIR_LOCK, new Set);
|
|
53007
|
+
rmSync3(held, { recursive: true, force: true });
|
|
53008
|
+
} finally {
|
|
53009
|
+
disposeSignalRelease();
|
|
53010
|
+
}
|
|
52961
53011
|
await removeCreatedFolders();
|
|
52962
53012
|
}
|
|
52963
53013
|
}
|
|
@@ -53098,10 +53148,11 @@ async function editedFiles(dir, touched, written) {
|
|
|
53098
53148
|
}
|
|
53099
53149
|
async function locallyEditedFiles(dir, answer, previousLock) {
|
|
53100
53150
|
const touched = new Map(Object.entries(answer.files));
|
|
53101
|
-
|
|
53151
|
+
const { digests } = await readFolderWritten(dir);
|
|
53152
|
+
for (const path of orphanedCodeFiles(previousLock, answer.lock, touched.keys(), digests)) {
|
|
53102
53153
|
touched.set(path, null);
|
|
53103
53154
|
}
|
|
53104
|
-
return editedFiles(dir, touched,
|
|
53155
|
+
return editedFiles(dir, touched, digests);
|
|
53105
53156
|
}
|
|
53106
53157
|
function inWorkspace(key, path) {
|
|
53107
53158
|
return `${KIND_DIRS.workflow}/${key}/${path}`;
|
|
@@ -53166,7 +53217,7 @@ async function writeBack(dir, answer, previousLock, extra = { write: [] }) {
|
|
|
53166
53217
|
`]
|
|
53167
53218
|
];
|
|
53168
53219
|
const write = [...printed, ...folder ? [] : writtenFiles(writtenRecord(files)), ...extra.write];
|
|
53169
|
-
const orphaned = orphanedCodeFiles(previousLock, answer.lock, Object.keys(answer.files));
|
|
53220
|
+
const orphaned = orphanedCodeFiles(previousLock, answer.lock, Object.keys(answer.files), (await readFolderWritten(dir)).digests);
|
|
53170
53221
|
const unnamed = await unnamedCodeFiles(dir, previousLock, answer, orphaned);
|
|
53171
53222
|
await updateSourceDir(dir, {
|
|
53172
53223
|
write,
|
|
@@ -53217,7 +53268,7 @@ function sourceExitCodeRows(prefix) {
|
|
|
53217
53268
|
},
|
|
53218
53269
|
{
|
|
53219
53270
|
code: 1,
|
|
53220
|
-
meaning:
|
|
53271
|
+
meaning: `The source has errors (each printed as \`file:line:column\` with a hint), a locked block (\`E_APPLY_LOCKED_BLOCK\`), ${prefix === "sim workspaces source" ? "a name another resource holds (`E_NAME_TAKEN`)" : "a name another workflow holds (`SOURCE_NAME_TAKEN`)"}, a cancelled prompt, or the command failed`,
|
|
53221
53272
|
next: "Fix what it printed and run it again",
|
|
53222
53273
|
help: {
|
|
53223
53274
|
"workflows source apply": "the source has errors (each printed as file:line:column with its frame and hint) or the command failed",
|
|
@@ -53369,7 +53420,7 @@ have been written and how to check.`;
|
|
|
53369
53420
|
|
|
53370
53421
|
// src/commands/protocol/source-tree.ts
|
|
53371
53422
|
import { createHash as createHash5 } from "node:crypto";
|
|
53372
|
-
import { rmSync as
|
|
53423
|
+
import { rmSync as rmSync4 } from "node:fs";
|
|
53373
53424
|
import { mkdir as mkdir3, mkdtemp as mkdtemp3, readFile as readFile3, rename as rename3, rm as rm4, writeFile as writeFile3 } from "node:fs/promises";
|
|
53374
53425
|
import { dirname as dirname8, join as join7 } from "node:path";
|
|
53375
53426
|
|
|
@@ -56062,7 +56113,7 @@ function writeWorkspaceCatalogPointer(workspaceId, hash) {
|
|
|
56062
56113
|
if (legacy === `${hash}.json`)
|
|
56063
56114
|
continue;
|
|
56064
56115
|
try {
|
|
56065
|
-
|
|
56116
|
+
rmSync4(join7(catalogCacheDir(), legacy), { recursive: true, force: true });
|
|
56066
56117
|
} catch {}
|
|
56067
56118
|
}
|
|
56068
56119
|
}
|
|
@@ -56505,8 +56556,14 @@ function isMachine(format) {
|
|
|
56505
56556
|
function resultDiagnostics(format, diagnostics, verbose = false) {
|
|
56506
56557
|
if (!isMachine(format))
|
|
56507
56558
|
return {};
|
|
56559
|
+
const hidden = (finding) => !verbose && finding.severity === "info" && finding.code !== "I_FINDINGS_TRUNCATED";
|
|
56560
|
+
const hiddenCount = diagnostics.filter(hidden).length;
|
|
56561
|
+
const marked = (finding) => finding.code === "I_FINDINGS_TRUNCATED" && hiddenCount > 0 ? {
|
|
56562
|
+
...finding,
|
|
56563
|
+
message: `${finding.message} ${hiddenCount} info finding${hiddenCount === 1 ? "" : "s"} listed ${hiddenCount === 1 ? "is" : "are"} hidden too; pass --verbose to see ${hiddenCount === 1 ? "it" : "them"}.`
|
|
56564
|
+
} : finding;
|
|
56508
56565
|
return {
|
|
56509
|
-
diagnostics: diagnostics.filter((finding) =>
|
|
56566
|
+
diagnostics: diagnostics.filter((finding) => !hidden(finding)).map(({ frame: _frame, ...finding }) => marked(finding))
|
|
56510
56567
|
};
|
|
56511
56568
|
}
|
|
56512
56569
|
function findingKey(diagnostic) {
|
|
@@ -56799,7 +56856,7 @@ async function readJson(directory, path, hint) {
|
|
|
56799
56856
|
}
|
|
56800
56857
|
function codeFilePaths(entry, lock) {
|
|
56801
56858
|
const candidates = lockCodeFiles(lock);
|
|
56802
|
-
for (const literal of codeFileReferences(entry)) {
|
|
56859
|
+
for (const literal of entry === null ? [] : codeFileReferences(entry)) {
|
|
56803
56860
|
const path = sourceRelativePath(literal);
|
|
56804
56861
|
if (path)
|
|
56805
56862
|
candidates.add(path);
|
|
@@ -56867,7 +56924,7 @@ The primer above is enough to edit; read a section here when a step needs it.
|
|
|
56867
56924
|
2. \`sim workflows source check --dir .\`: compiles offline with the server's compiler, in milliseconds. It catches what \`tsc\` cannot (duplicate names, cycles, literal secrets), and fails (exit 1) on a missing required field, an unknown option or output path, a wrong value kind, an out-of-range value, an unwired condition or router branch or a literal secret in a block you added (\`--strict\`: in every block). It also adds the blocks the source now uses to \`tsconfig.json\`.
|
|
56868
56925
|
3. \`${typecheckCommand()}\`: about a second; catches what step 2 and the dry run do not (such as a reference to a start input the trigger does not declare). It runs the TypeScript release the declarations are built for (the directory has no \`package.json\`; plain \`bunx tsc\` would run whatever version it finds). \`tsconfig.json\` includes only the blocks the source used at the last check, get or apply: a builder from another block fails with \`has no exported member\` until you run step 2 (or use \`${typecheckCommand(TSCONFIG_FULL_FILE)}\`, every current block). The dry run is the authority: a printed line you did not edit that \`tsc\` flags and the dry run accepts is fine.
|
|
56869
56926
|
4. \`sim workflows source status --dir .\`: the files you changed (\`sim workflows source diff --dir .\` shows the edits), whether the workflow changed on the server since the get, and the command to run next (\`--offline\`: skip the server). Then \`sim workflows source apply --dir . --dry-run\` until it exits 0.
|
|
56870
|
-
5. \`sim workflows source apply --dir . --yes\`: saves the draft, refusing errors, block deletions without \`--allow-delete\` and a stale directory, so it needs no separate dry run (without \`--yes\` and a terminal it prints the plan and exits ${SOURCE_PLANNED_EXIT_CODE}). \`--deploy\` also deploys it; without it, a deployed workflow's next \`sim workflows deploy <id>\` is printed. It then rewrites \`${SOURCE_ENTRY_FILE}\` in canonical form (order, quoting, defaults left out).
|
|
56927
|
+
5. \`sim workflows source apply --dir . --yes\`: saves the draft, refusing errors, block deletions without \`--allow-delete\` and a stale directory, so it needs no separate dry run (without \`--yes\` and a terminal it prints the plan and exits ${SOURCE_PLANNED_EXIT_CODE}). \`--deploy\` also deploys it; without it, a deployed workflow's next \`sim workflows deploy <id> --expected-draft-fingerprint <fingerprint>\` is printed, which deploys only the draft this apply saved. It then rewrites \`${SOURCE_ENTRY_FILE}\` in canonical form (order, quoting, defaults left out).
|
|
56871
56928
|
6. Exit ${SOURCE_STALE_EXIT_CODE} (\`SOURCE_STALE\`, HTTP 409, or \`E_APPLY_STALE\` on a dry run): the workflow changed and nothing was saved. Run \`sim workflows source get <workflowId> --dir <fresh dir>\`, reapply your edit there, dry-run, apply. A get into this directory refuses to overwrite your unapplied edits unless you pass \`--force\`. Exit ${SOURCE_STALE_EXIT_CODE} right after an apply that ended without an answer (a timeout, a dropped connection) means the draft changed, by that apply or by someone else: get into a fresh directory and compare. Only when it holds your edit, run \`sim workflows source get <workflowId> --dir . --force\`; otherwise reapply your edit in the fresh directory.
|
|
56872
56929
|
|
|
56873
56930
|
Editing the \`workflow('…')\` name or description renames or redescribes the workflow; a name another workflow in its folder holds is refused with \`E_NAME_TAKEN\`. Lines starting \`note:\` explain something the write did differently than the source says; read them.
|
|
@@ -57094,7 +57151,7 @@ async function writeWorkflowSource(args) {
|
|
|
57094
57151
|
report(data, deployment);
|
|
57095
57152
|
}
|
|
57096
57153
|
async function deployStep(client, data, options) {
|
|
57097
|
-
const deployCommand = `sim workflows deploy ${data.workflowId}`;
|
|
57154
|
+
const deployCommand = `sim workflows deploy ${data.workflowId} --expected-draft-fingerprint ${data.base.fingerprint}`;
|
|
57098
57155
|
if (!options.deploy) {
|
|
57099
57156
|
if (!data.needsRedeployment)
|
|
57100
57157
|
return {};
|
|
@@ -57105,6 +57162,24 @@ async function deployStep(client, data, options) {
|
|
|
57105
57162
|
}
|
|
57106
57163
|
};
|
|
57107
57164
|
}
|
|
57165
|
+
if (!data.applied && !data.needsRedeployment) {
|
|
57166
|
+
const status = await client.request("getWorkflowDeployment", {
|
|
57167
|
+
params: { workflowId: data.workflowId }
|
|
57168
|
+
}).then((response) => response.data, (error) => {
|
|
57169
|
+
throw deployFailure(error, options, deployCommand);
|
|
57170
|
+
});
|
|
57171
|
+
if (status.isDeployed && !status.needsRedeployment) {
|
|
57172
|
+
if (!options.machine)
|
|
57173
|
+
printError("The live version already matches the draft; nothing was deployed.");
|
|
57174
|
+
return {
|
|
57175
|
+
deployed: {
|
|
57176
|
+
...status.activeDeployment ? { version: status.activeDeployment.version } : {},
|
|
57177
|
+
isDeployed: true
|
|
57178
|
+
},
|
|
57179
|
+
needsRedeployment: false
|
|
57180
|
+
};
|
|
57181
|
+
}
|
|
57182
|
+
}
|
|
57108
57183
|
const deployed = await client.request("deployWorkflow", {
|
|
57109
57184
|
params: { workflowId: data.workflowId },
|
|
57110
57185
|
body: { expectedDraftFingerprint: data.base.fingerprint }
|
|
@@ -57139,6 +57214,7 @@ function attachWorkflowSourceApply(source) {
|
|
|
57139
57214
|
const [command, connectApply] = apiCommand(source, "apply", [
|
|
57140
57215
|
"applyWorkflowSource",
|
|
57141
57216
|
"deployWorkflow",
|
|
57217
|
+
"getWorkflowDeployment",
|
|
57142
57218
|
"getSourceResources"
|
|
57143
57219
|
]);
|
|
57144
57220
|
absoluteDirOption(command);
|
|
@@ -57187,7 +57263,8 @@ function attachWorkflowSourceCreate(source) {
|
|
|
57187
57263
|
"createWorkflowFromSource",
|
|
57188
57264
|
"getSourceCatalog",
|
|
57189
57265
|
"getSourceResources",
|
|
57190
|
-
"deployWorkflow"
|
|
57266
|
+
"deployWorkflow",
|
|
57267
|
+
"getWorkflowDeployment"
|
|
57191
57268
|
]);
|
|
57192
57269
|
absoluteDirOption(command);
|
|
57193
57270
|
verboseFlag(command);
|
|
@@ -63492,7 +63569,7 @@ var ADVANCED_GUIDE = `# Sim workspace source: advanced
|
|
|
63492
63569
|
|
|
63493
63570
|
## Promote to another workspace
|
|
63494
63571
|
|
|
63495
|
-
\`sim workspaces source apply --dir . --to <workspaceId> --dry-run\`, then \`--yes\`: applies this directory to another workspace (dev to prod). Each resource binds by key to the target's own: one the target holds under the same key is updated in place (a workflow keeps its id and block ids, so its webhook URLs), a key it lacks is created (or adopts a resource of the same name). Each promote records what it left in the target in \`.sim/targets/<workspaceId>.json\` (commit it), and the next promote compares with that: a resource changed in the target since is kept when this directory left it alone, and refused as stale (exit ${SOURCE_STALE_EXIT_CODE}) when this directory changed it too. A resource with no record (the first promote, or one created in the target since) is updated to match this directory; delete the record to take the target as it stands again. Secrets and credentials bind by name and key to the target's own; no value is copied. The target's resources this directory
|
|
63572
|
+
\`sim workspaces source apply --dir . --to <workspaceId> --dry-run\`, then \`--yes\`: applies this directory to another workspace (dev to prod). Each resource binds by key to the target's own: one the target holds under the same key is updated in place (a workflow keeps its id and block ids, so its webhook URLs), a key it lacks is created (or adopts a resource of the same name). Each promote records what it left in the target in \`.sim/targets/<workspaceId>.json\` (commit it), and the next promote compares with that: a resource changed in the target since is kept when this directory left it alone, and refused as stale (exit ${SOURCE_STALE_EXIT_CODE}) when this directory changed it too. A resource with no record (the first promote, or one created in the target since) is updated to match this directory; delete the record to take the target as it stands again. Secrets and credentials bind by name and key to the target's own; no value is copied. The target's resources this directory never declared (and no promote left there) are kept with a warning, even with \`--allow-delete\`; deleting them too takes \`--delete-target-only\` beside \`--allow-delete\`. A resource this directory deleted since the last promote is deleted in the target only with \`--allow-delete\`. Before the first promote, set the target's secrets (\`sim secrets set NAME --scope workspace -w <workspaceId>\`) and connect its credentials, or the workflows using them are held back. This directory stays bound to the workspace it was read from. Without \`--to\`, \`check\`, \`status\`, \`diff\` and \`apply\` act on the workspace this directory was read from, whatever the profile's default; a \`--workspace\` naming another is refused (\`SOURCE_OTHER_WORKSPACE\`).
|
|
63496
63573
|
`;
|
|
63497
63574
|
var WORKSPACE_TREE = {
|
|
63498
63575
|
kind: "workspace",
|
|
@@ -63701,6 +63778,32 @@ async function assertWorkspaceDir(dir) {
|
|
|
63701
63778
|
function keepFile(kind) {
|
|
63702
63779
|
return isFileKind(kind) ? null : `${KIND_DIRS[kind]}/${KEEP_FILE}`;
|
|
63703
63780
|
}
|
|
63781
|
+
function dropUnnamedCodeFiles(files) {
|
|
63782
|
+
const named = new Map;
|
|
63783
|
+
const unnamed = [];
|
|
63784
|
+
for (const path of Object.keys(files)) {
|
|
63785
|
+
if (kindOfPath(path) !== "workflow")
|
|
63786
|
+
continue;
|
|
63787
|
+
const segments = path.split("/");
|
|
63788
|
+
if (segments[2] !== SOURCE_CODE_DIR)
|
|
63789
|
+
continue;
|
|
63790
|
+
const folder = segments.slice(0, 2).join("/");
|
|
63791
|
+
let sent = named.get(folder);
|
|
63792
|
+
if (!sent) {
|
|
63793
|
+
let lock = null;
|
|
63794
|
+
try {
|
|
63795
|
+
lock = JSON.parse(files[`${folder}/${SOURCE_LOCK_FILE}`] ?? "null");
|
|
63796
|
+
} catch {}
|
|
63797
|
+
sent = new Set(codeFilePaths(files[`${folder}/${SOURCE_ENTRY_FILE}`] ?? null, lock));
|
|
63798
|
+
named.set(folder, sent);
|
|
63799
|
+
}
|
|
63800
|
+
if (!sent.has(segments.slice(2).join("/"))) {
|
|
63801
|
+
unnamed.push(path);
|
|
63802
|
+
delete files[path];
|
|
63803
|
+
}
|
|
63804
|
+
}
|
|
63805
|
+
return unnamed.sort(compareStrings);
|
|
63806
|
+
}
|
|
63704
63807
|
function pruneUnchangedWorkflows(files, written, workspaceId) {
|
|
63705
63808
|
const workflowPaths = Object.keys(files).filter((path) => kindOfPath(path) === "workflow");
|
|
63706
63809
|
const folders = KIND_LAYOUTS.workflow.group(workflowPaths).groups;
|
|
@@ -63745,6 +63848,7 @@ async function readWorkspaceDir(dir, only, workspaceId, written, options = {}) {
|
|
|
63745
63848
|
if (text !== null)
|
|
63746
63849
|
files[path] = text;
|
|
63747
63850
|
});
|
|
63851
|
+
const unnamed = dropUnnamedCodeFiles(files);
|
|
63748
63852
|
if (!options.whole)
|
|
63749
63853
|
pruneUnchangedWorkflows(files, written, workspaceId);
|
|
63750
63854
|
const root = await realpath4(dir);
|
|
@@ -63773,7 +63877,7 @@ async function readWorkspaceDir(dir, only, workspaceId, written, options = {}) {
|
|
|
63773
63877
|
throw new SourceDirError(`${WORKSPACE_BASE_FILE} in ${dir} is not valid JSON (a merge conflict?). Restore it from version control, or get the workspace into a fresh directory with \`sim workspaces source get --dir <fresh dir>\` and carry your edits over.`, { code: "SOURCE_BASE_INVALID" });
|
|
63774
63878
|
}
|
|
63775
63879
|
}
|
|
63776
|
-
return { kinds, files, blobs, ignored, hashed, ...base ? { base } : {} };
|
|
63880
|
+
return { kinds, files, blobs, ignored, unnamed, hashed, ...base ? { base } : {} };
|
|
63777
63881
|
}
|
|
63778
63882
|
function skippedFile(skipped) {
|
|
63779
63883
|
return skipped.length > 0 ? `${JSON.stringify(skipped, null, 2)}
|
|
@@ -64019,7 +64123,7 @@ async function compileWorkflowDir(dir, workspaceCatalog, declarations) {
|
|
|
64019
64123
|
...storedEdges ? { storedUnreadEdges: storedEdges } : {},
|
|
64020
64124
|
...envNames ? { envNames, envDeclaredIn: KIND_DIRS.secret } : {}
|
|
64021
64125
|
});
|
|
64022
|
-
return { lock, files, compiled, storedBlocks, printedWith };
|
|
64126
|
+
return { lock, files, compiled, storedBlocks, printedWith, catalog };
|
|
64023
64127
|
}
|
|
64024
64128
|
async function workspaceWorkflowInputs(root, catalog) {
|
|
64025
64129
|
const inputs = new Map;
|
|
@@ -64040,7 +64144,8 @@ function withWorkflowInputs(local, inputs) {
|
|
|
64040
64144
|
return { ...local, workflows };
|
|
64041
64145
|
}
|
|
64042
64146
|
async function checkWorkflowDir(dir, catalog, options) {
|
|
64043
|
-
const
|
|
64147
|
+
const compiledDir = await compileWorkflowDir(dir, catalog, options.declarations);
|
|
64148
|
+
const { lock, files, compiled, storedBlocks, printedWith } = compiledDir;
|
|
64044
64149
|
const entryText = files[SOURCE_ENTRY_FILE];
|
|
64045
64150
|
const locate = (block, param, names) => {
|
|
64046
64151
|
const prefix = encodeAnchor({ kind: "param", block, param: "" });
|
|
@@ -64102,19 +64207,30 @@ async function checkWorkflowDir(dir, catalog, options) {
|
|
|
64102
64207
|
const head = /^(?:\$ref\.|<)([A-Za-z0-9_]+)/.exec(text)?.[1];
|
|
64103
64208
|
return head !== undefined && removedKeys.has(head);
|
|
64104
64209
|
};
|
|
64105
|
-
const
|
|
64210
|
+
const variesByDeployment = (finding) => {
|
|
64211
|
+
const { blockKey, param } = finding;
|
|
64212
|
+
if (finding.code !== "W_UNKNOWN_OPTION" || blockKey === undefined || param === undefined) {
|
|
64213
|
+
return false;
|
|
64214
|
+
}
|
|
64215
|
+
const type = compiled.workflow ? getOwn(compiled.workflow.blocks, blockKey)?.type : undefined;
|
|
64216
|
+
const block = type === undefined ? undefined : catalogBlock(compiledDir.catalog, type);
|
|
64217
|
+
return block?.subBlocks.some((sub) => sub.id === param && sub.optionsVary === true) === true;
|
|
64218
|
+
};
|
|
64219
|
+
const exempt = (finding) => mayBeRenamed(finding) || variesByDeployment(finding);
|
|
64220
|
+
const refusable = (finding) => !exempt(finding);
|
|
64106
64221
|
const refused = [
|
|
64107
64222
|
...refuseEditedFindings({
|
|
64108
64223
|
diagnostics: compiled.diagnostics.filter(refusable),
|
|
64109
64224
|
withheld: compiled.withheld.filter(refusable)
|
|
64110
64225
|
}, { changed, codeEdited }),
|
|
64111
|
-
...compiled.diagnostics.filter(
|
|
64226
|
+
...compiled.diagnostics.filter(exempt)
|
|
64112
64227
|
];
|
|
64113
64228
|
const findings = [
|
|
64114
64229
|
...refused.filter((diagnostic) => reported(diagnostic.code, diagnostic.blockKey)),
|
|
64115
64230
|
...declared
|
|
64116
|
-
].map((
|
|
64117
|
-
const
|
|
64231
|
+
].map((finding) => {
|
|
64232
|
+
const { code, severity, message, hint, frame, span, blockKey } = finding;
|
|
64233
|
+
const raised = severity === "warning" && !variesByDeployment(finding) && fails(code, blockKey);
|
|
64118
64234
|
return {
|
|
64119
64235
|
code,
|
|
64120
64236
|
severity: raised ? "error" : severity,
|
|
@@ -64124,19 +64240,52 @@ async function checkWorkflowDir(dir, catalog, options) {
|
|
|
64124
64240
|
...span ? { file: `${prefix}${span.file}`, line: span.line, column: span.column } : {}
|
|
64125
64241
|
};
|
|
64126
64242
|
});
|
|
64127
|
-
|
|
64243
|
+
const unlisted = { errors: 0, warnings: 0 };
|
|
64244
|
+
const edit = { changed, codeEdited };
|
|
64245
|
+
for (const { code, blockKey, count, varies, refused: isRefused } of [
|
|
64246
|
+
...compiled.omitted.map((omitted) => {
|
|
64247
|
+
const finding = {
|
|
64248
|
+
code: omitted.code,
|
|
64249
|
+
severity: "warning",
|
|
64250
|
+
...omitted.blockKey !== undefined ? { blockKey: omitted.blockKey } : {},
|
|
64251
|
+
...omitted.param !== undefined ? { param: omitted.param } : {}
|
|
64252
|
+
};
|
|
64253
|
+
const varies = variesByDeployment(finding);
|
|
64254
|
+
return {
|
|
64255
|
+
...omitted,
|
|
64256
|
+
varies,
|
|
64257
|
+
refused: !varies && omitted.file !== undefined && refusesEdited({ ...finding, span: { file: omitted.file } }, edit)
|
|
64258
|
+
};
|
|
64259
|
+
}),
|
|
64260
|
+
...compiled.withheld.filter((finding) => !refusable(finding) || !refusesEdited(finding, edit)).map((finding) => ({
|
|
64261
|
+
code: finding.code,
|
|
64262
|
+
blockKey: finding.blockKey,
|
|
64263
|
+
count: 1,
|
|
64264
|
+
varies: variesByDeployment(finding),
|
|
64265
|
+
refused: false
|
|
64266
|
+
}))
|
|
64267
|
+
]) {
|
|
64268
|
+
if (!reported(code, blockKey))
|
|
64269
|
+
continue;
|
|
64270
|
+
if (isRefused || !varies && fails(code, blockKey))
|
|
64271
|
+
unlisted.errors += count;
|
|
64272
|
+
else
|
|
64273
|
+
unlisted.warnings += count;
|
|
64274
|
+
}
|
|
64275
|
+
return { findings, entry: entryText, unlisted };
|
|
64128
64276
|
}
|
|
64129
64277
|
function reportCheck(output, findings, result, options = {}) {
|
|
64130
64278
|
const shown = findingsOutput(output, options.verbose);
|
|
64131
64279
|
const listed = boundAnswerFindings(findings, options.bound);
|
|
64132
64280
|
shown.print(listed);
|
|
64133
|
-
const
|
|
64281
|
+
const unlisted = options.unlisted ?? { errors: 0, warnings: 0 };
|
|
64282
|
+
const errors = findings.filter((finding) => finding.severity === "error").length + unlisted.errors;
|
|
64134
64283
|
if (errors > 0)
|
|
64135
64284
|
setSoftExitCode(1);
|
|
64136
64285
|
printProtocolResult(output, {
|
|
64137
64286
|
checked: "compile",
|
|
64138
64287
|
errors,
|
|
64139
|
-
warnings: findings.filter((finding) => finding.severity === "warning").length,
|
|
64288
|
+
warnings: findings.filter((finding) => finding.severity === "warning").length + unlisted.warnings,
|
|
64140
64289
|
...result,
|
|
64141
64290
|
...shown.result(listed)
|
|
64142
64291
|
});
|
|
@@ -64180,7 +64329,7 @@ function attachWorkflowSourceCheck(source) {
|
|
|
64180
64329
|
...await readWorkspaceDeclarations(workspace.root),
|
|
64181
64330
|
workflowInputs: await workspaceWorkflowInputs(workspace.root, catalog)
|
|
64182
64331
|
} : undefined;
|
|
64183
|
-
const { findings, entry } = await checkWorkflowDir(options.dir, catalog, {
|
|
64332
|
+
const { findings, entry, unlisted } = await checkWorkflowDir(options.dir, catalog, {
|
|
64184
64333
|
strict: strictMode(options),
|
|
64185
64334
|
...declarations ? { declarations } : {}
|
|
64186
64335
|
});
|
|
@@ -64191,7 +64340,8 @@ function attachWorkflowSourceCheck(source) {
|
|
|
64191
64340
|
await refreshTsconfigs(options.dir, workspaceId, WORKFLOW_TREE, { sources: [entry] }, { incremental: true });
|
|
64192
64341
|
}
|
|
64193
64342
|
reportCheck(profile.output, findings, { catalogHash: catalog.hash }, {
|
|
64194
|
-
verbose: options.verbose === true
|
|
64343
|
+
verbose: options.verbose === true,
|
|
64344
|
+
unlisted
|
|
64195
64345
|
});
|
|
64196
64346
|
});
|
|
64197
64347
|
}
|
|
@@ -65030,6 +65180,9 @@ function printStatusReport(format, heading, report, planLine, findings) {
|
|
|
65030
65180
|
} else {
|
|
65031
65181
|
lines.push(s.yellow(`Server not checked${report.note ? `: ${sanitize(report.note)}` : "."}`));
|
|
65032
65182
|
}
|
|
65183
|
+
if (report.unnamed?.length) {
|
|
65184
|
+
lines.push(s.dim(`Not named by any codeFile(), so applying never sends ${report.unnamed.length === 1 ? "it" : "them"}: ${sanitize(report.unnamed.join(", "))}`));
|
|
65185
|
+
}
|
|
65033
65186
|
if (report.server === "checked" && report.note)
|
|
65034
65187
|
lines.push(s.dim(sanitize(report.note)));
|
|
65035
65188
|
if (report.plan)
|
|
@@ -65197,23 +65350,25 @@ async function readLocalWorkflow(dir) {
|
|
|
65197
65350
|
const base = await readBase(dir, undefined);
|
|
65198
65351
|
const { workflowId } = base;
|
|
65199
65352
|
const written = await readFolderWritten(dir);
|
|
65200
|
-
const
|
|
65201
|
-
|
|
65202
|
-
|
|
65203
|
-
];
|
|
65204
|
-
const
|
|
65205
|
-
for (const path of paths) {
|
|
65353
|
+
const entry = await readSourceText(dir, SOURCE_ENTRY_FILE);
|
|
65354
|
+
const sent = new Set(codeFilePaths(entry, await readPreviousLock(dir)));
|
|
65355
|
+
const listed = (await listSourceFiles(dir, SOURCE_CODE_DIR)).filter((path) => !path.split("/").some((segment) => segment.startsWith(".")));
|
|
65356
|
+
const texts = entry === null ? {} : { [SOURCE_ENTRY_FILE]: entry };
|
|
65357
|
+
for (const path of listed.filter((each) => sent.has(each))) {
|
|
65206
65358
|
const text = await readSourceText(dir, path);
|
|
65207
65359
|
if (text !== null)
|
|
65208
65360
|
texts[path] = text;
|
|
65209
65361
|
}
|
|
65210
65362
|
const current = Object.fromEntries(Object.entries(texts).map(([path, text]) => [path, digest(text)]));
|
|
65363
|
+
const unnamed = listed.filter((path) => !sent.has(path));
|
|
65364
|
+
const ignored = new Set(unnamed);
|
|
65211
65365
|
return {
|
|
65212
65366
|
base,
|
|
65213
65367
|
workflowId,
|
|
65214
65368
|
written,
|
|
65215
65369
|
texts,
|
|
65216
|
-
changed: changedFiles(current, written.digests, () =>
|
|
65370
|
+
changed: changedFiles(current, written.digests, (path) => !ignored.has(path)),
|
|
65371
|
+
unnamed
|
|
65217
65372
|
};
|
|
65218
65373
|
}
|
|
65219
65374
|
function workflowPlanFindings(data) {
|
|
@@ -65296,13 +65451,14 @@ function attachWorkflowSourceStatus(source) {
|
|
|
65296
65451
|
}
|
|
65297
65452
|
}
|
|
65298
65453
|
const status = sourceStatus(locals, serverChanges);
|
|
65299
|
-
const plan = data ? planSummary(data) : null;
|
|
65454
|
+
const plan = data && serverChanges.length === 0 ? planSummary(data) : null;
|
|
65300
65455
|
const report = {
|
|
65301
65456
|
workflowId,
|
|
65302
65457
|
dir: options.dir,
|
|
65303
65458
|
server,
|
|
65304
65459
|
...note ? { note } : {},
|
|
65305
65460
|
...status,
|
|
65461
|
+
...local.unnamed.length > 0 ? { unnamed: local.unnamed } : {},
|
|
65306
65462
|
plan,
|
|
65307
65463
|
next: nextStep(status, {
|
|
65308
65464
|
prefix: PREFIX,
|
|
@@ -65505,15 +65661,22 @@ function promotionSubmission(input) {
|
|
|
65505
65661
|
if (lock !== undefined)
|
|
65506
65662
|
files[lockPath] = lock;
|
|
65507
65663
|
}
|
|
65664
|
+
const targetOnly = [];
|
|
65508
65665
|
const resources = Object.fromEntries(Object.entries(input.target.base.resources).flatMap(([address, live]) => {
|
|
65509
65666
|
const parsed = parseResourceAddress(address);
|
|
65510
65667
|
if (!parsed)
|
|
65511
65668
|
return [];
|
|
65512
65669
|
const keys = declared.get(parsed.kind);
|
|
65513
|
-
if (keys === undefined
|
|
65670
|
+
if (keys === undefined)
|
|
65514
65671
|
return [];
|
|
65515
65672
|
const recorded = input.record?.resources[resourceAddress(parsed.kind, parsed.key)];
|
|
65516
|
-
|
|
65673
|
+
const promoted = recorded?.id === live.id ? recorded : undefined;
|
|
65674
|
+
if (!keys.has(parsed.key) && !promoted) {
|
|
65675
|
+
targetOnly.push(resourceAddress(parsed.kind, parsed.key));
|
|
65676
|
+
if (!input.deleteTargetOnly)
|
|
65677
|
+
return [];
|
|
65678
|
+
}
|
|
65679
|
+
return [[address, promoted ?? live]];
|
|
65517
65680
|
}));
|
|
65518
65681
|
for (const [address, recorded] of Object.entries(input.record?.resources ?? {})) {
|
|
65519
65682
|
if (Object.hasOwn(input.target.base.resources, address))
|
|
@@ -65528,7 +65691,8 @@ function promotionSubmission(input) {
|
|
|
65528
65691
|
return {
|
|
65529
65692
|
files,
|
|
65530
65693
|
base: { ...input.target.base, resources },
|
|
65531
|
-
deletedInTarget: [...new Set(deletedInTarget)].sort(compareStrings)
|
|
65694
|
+
deletedInTarget: [...new Set(deletedInTarget)].sort(compareStrings),
|
|
65695
|
+
targetOnly: targetOnly.sort(compareStrings)
|
|
65532
65696
|
};
|
|
65533
65697
|
}
|
|
65534
65698
|
function promotionRecord(input) {
|
|
@@ -65540,7 +65704,13 @@ function promotionRecord(input) {
|
|
|
65540
65704
|
resources[resourceAddress(parsed.kind, parsed.key)] = entry;
|
|
65541
65705
|
}
|
|
65542
65706
|
}
|
|
65543
|
-
|
|
65707
|
+
const targetOnly = new Set(input.submission.targetOnly);
|
|
65708
|
+
for (const [address, entry] of Object.entries(input.applied.base.resources)) {
|
|
65709
|
+
const parsed = parseResourceAddress(address);
|
|
65710
|
+
if (parsed && !targetOnly.has(address)) {
|
|
65711
|
+
resources[resourceAddress(parsed.kind, parsed.key)] = entry;
|
|
65712
|
+
}
|
|
65713
|
+
}
|
|
65544
65714
|
const workflows = {};
|
|
65545
65715
|
if (!managed.has("workflow")) {
|
|
65546
65716
|
Object.assign(workflows, input.previous?.workflows);
|
|
@@ -65596,6 +65766,10 @@ function outcomeText(change, outcome) {
|
|
|
65596
65766
|
function printPlan(plan, diagnostics, outcome) {
|
|
65597
65767
|
const drifted = new Map(serverResourceChanges(diagnostics).filter((change) => change.server !== "added").map((change) => [`${change.kind}:${change.key}`, change.server]));
|
|
65598
65768
|
const driftOf = (change) => change.action === "noop" ? drifted.get(`${change.kind}:${change.key}`) : undefined;
|
|
65769
|
+
const addressesOf = (code) => new Set(diagnostics.filter((finding) => finding.code === code).map((finding) => `${finding.kind}:${finding.key}`));
|
|
65770
|
+
const stale = addressesOf("E_APPLY_STALE");
|
|
65771
|
+
const deleteRefused = addressesOf("E_APPLY_DELETE_NOT_ALLOWED");
|
|
65772
|
+
const refusedDelete = (change) => change.action === "noop" && deleteRefused.has(`${change.kind}:${change.key}`);
|
|
65599
65773
|
for (const kind of APPLY_ORDER) {
|
|
65600
65774
|
const changes = plan.filter((change) => change.kind === kind);
|
|
65601
65775
|
if (changes.length === 0)
|
|
@@ -65603,14 +65777,19 @@ function printPlan(plan, diagnostics, outcome) {
|
|
|
65603
65777
|
const counts = new Map;
|
|
65604
65778
|
for (const change of changes) {
|
|
65605
65779
|
const drift = driftOf(change);
|
|
65606
|
-
const label = drift ? `${drift} on the server` : change.action === "noop" ? "unchanged" : change.action;
|
|
65780
|
+
const label = drift ? `${drift} on the server` : refusedDelete(change) ? "delete refused" : change.action === "noop" ? "unchanged" : change.action;
|
|
65607
65781
|
counts.set(label, (counts.get(label) ?? 0) + 1);
|
|
65608
65782
|
}
|
|
65609
65783
|
printError(`${KIND_DIRS[kind]}: ${[...counts].map(([label, count]) => `${count} ${label}`).join(", ")}`);
|
|
65610
65784
|
for (const change of changes) {
|
|
65611
65785
|
const drift = driftOf(change);
|
|
65612
65786
|
if (drift) {
|
|
65613
|
-
|
|
65787
|
+
const fate = stale.has(`${change.kind}:${change.key}`) ? "your edit is refused as stale" : "kept as the server has it";
|
|
65788
|
+
printError(` ! ${change.key} (${drift} on the server; ${fate})`);
|
|
65789
|
+
continue;
|
|
65790
|
+
}
|
|
65791
|
+
if (refusedDelete(change)) {
|
|
65792
|
+
printError(` - ${change.key} — refused, needs --allow-delete`);
|
|
65614
65793
|
continue;
|
|
65615
65794
|
}
|
|
65616
65795
|
if (change.action === "noop")
|
|
@@ -65641,7 +65820,7 @@ function missingBlobPaths(error) {
|
|
|
65641
65820
|
return errors.flatMap((finding) => typeof finding.file === "string" ? [finding.file] : []);
|
|
65642
65821
|
}
|
|
65643
65822
|
var WORKFLOW_LOCK_PATH = new RegExp(`^${KIND_DIRS.workflow}/([^/]+)/${SOURCE_LOCK_FILE.replaceAll(".", "\\.")}$`);
|
|
65644
|
-
async function orphanedWorkflowFiles(dir, files) {
|
|
65823
|
+
async function orphanedWorkflowFiles(dir, files, recorded) {
|
|
65645
65824
|
const filesByFolder = new Map;
|
|
65646
65825
|
for (const path of Object.keys(files)) {
|
|
65647
65826
|
if (!path.startsWith(`${KIND_DIRS.workflow}/`))
|
|
@@ -65668,7 +65847,8 @@ async function orphanedWorkflowFiles(dir, files) {
|
|
|
65668
65847
|
if (!isRecordLike(next) || !isRecordLike(next.blocks))
|
|
65669
65848
|
continue;
|
|
65670
65849
|
const previous = await readSourceJson(dir, path);
|
|
65671
|
-
|
|
65850
|
+
const inFolder = Object.fromEntries(Object.entries(recorded).flatMap(([recordedPath, sha]) => recordedPath.startsWith(`${folder}/`) ? [[recordedPath.slice(folder.length + 1), sha]] : []));
|
|
65851
|
+
orphaned.push(...orphanedCodeFiles(previous, next, written, inFolder).map((file) => `${folder}/${file}`));
|
|
65672
65852
|
}
|
|
65673
65853
|
return orphaned;
|
|
65674
65854
|
}
|
|
@@ -65721,7 +65901,7 @@ function droppedResourceFiles(sent, reprinted) {
|
|
|
65721
65901
|
async function saveApplied(dir, data, submission, written, records) {
|
|
65722
65902
|
assertWorkspacePaths(Object.keys(data.files));
|
|
65723
65903
|
const orphaned = [
|
|
65724
|
-
...await orphanedWorkflowFiles(dir, data.files),
|
|
65904
|
+
...await orphanedWorkflowFiles(dir, data.files, written.digests),
|
|
65725
65905
|
...droppedResourceFiles(submission.files, data.files)
|
|
65726
65906
|
];
|
|
65727
65907
|
const kept = { ...written.digests, ...appliedBlobDigests(submission, data.base) };
|
|
@@ -65746,7 +65926,7 @@ function baseWorkflowOf(base) {
|
|
|
65746
65926
|
function baseWorkspaceOf(base) {
|
|
65747
65927
|
return isRecordLike(base) && typeof base.workspaceId === "string" ? base.workspaceId : null;
|
|
65748
65928
|
}
|
|
65749
|
-
async function promoted(client, dir, submission, target,
|
|
65929
|
+
async function promoted(client, dir, submission, target, deleteTargetOnly) {
|
|
65750
65930
|
if (baseWorkspaceOf(submission.base) === target) {
|
|
65751
65931
|
throw new SourceDirError(`${dir} was read from workspace ${target}; apply it without --to.`, {
|
|
65752
65932
|
code: "SOURCE_PROMOTE_SAME_WORKSPACE"
|
|
@@ -65768,14 +65948,15 @@ async function promoted(client, dir, submission, target, allowDelete) {
|
|
|
65768
65948
|
kinds: submission.kinds,
|
|
65769
65949
|
target: { files: data.files, base: targetBase },
|
|
65770
65950
|
record,
|
|
65771
|
-
|
|
65951
|
+
deleteTargetOnly
|
|
65772
65952
|
});
|
|
65773
65953
|
return {
|
|
65774
65954
|
submission: { ...submission, files: composed.files, base: composed.base },
|
|
65775
65955
|
files: submission.files,
|
|
65776
65956
|
record,
|
|
65777
65957
|
target,
|
|
65778
|
-
deletedInTarget: composed.deletedInTarget
|
|
65958
|
+
deletedInTarget: composed.deletedInTarget,
|
|
65959
|
+
targetOnly: composed.targetOnly
|
|
65779
65960
|
};
|
|
65780
65961
|
}
|
|
65781
65962
|
async function savePromotion(dir, target, promotion, data) {
|
|
@@ -65790,7 +65971,8 @@ async function savePromotion(dir, target, promotion, data) {
|
|
|
65790
65971
|
files: promotion.files,
|
|
65791
65972
|
submission: {
|
|
65792
65973
|
files: promotion.submission.files,
|
|
65793
|
-
base: parseWorkspaceBase(promotion.submission.base).base ?? base
|
|
65974
|
+
base: parseWorkspaceBase(promotion.submission.base).base ?? base,
|
|
65975
|
+
targetOnly: promotion.targetOnly
|
|
65794
65976
|
},
|
|
65795
65977
|
applied: { base, files: data.files, plan: data.plan }
|
|
65796
65978
|
});
|
|
@@ -65800,23 +65982,33 @@ async function savePromotion(dir, target, promotion, data) {
|
|
|
65800
65982
|
function resourceWhere(kind, key) {
|
|
65801
65983
|
return isFileKind(kind) ? `${KIND_DIRS[kind]} ${key}` : `${KIND_DIRS[kind]}/${key}`;
|
|
65802
65984
|
}
|
|
65803
|
-
function promotionHint(code, target) {
|
|
65985
|
+
function promotionHint(code, target, targetOnly) {
|
|
65804
65986
|
const record = promotionRecordPath(target) ?? ".sim/targets/<workspaceId>.json";
|
|
65805
65987
|
if (code === "E_APPLY_STALE") {
|
|
65806
|
-
return `Workspace ${target} changed this resource since the last promotion from this directory. Carry that change into the directory, or undo it in ${target}, then promote again
|
|
65988
|
+
return `Workspace ${target} changed this resource since the last promotion from this directory. Carry that change into the directory (\`sim workspaces source get --workspace ${target} --dir <fresh dir>\` prints it), or undo it in ${target}, then promote again. Don't delete ${record} to get past this: the next promotion would then overwrite every change made in ${target} since, rows its workflows wrote included.`;
|
|
65989
|
+
}
|
|
65990
|
+
if (code === "W_SERVER_CHANGED") {
|
|
65991
|
+
return `Workspace ${target} changed this resource since the last promotion from this directory, and this promotion keeps that change. To carry it into the directory, \`sim workspaces source get --workspace ${target} --dir <fresh dir>\` prints it.`;
|
|
65992
|
+
}
|
|
65993
|
+
if (code === "E_APPLY_DELETE_NOT_ALLOWED") {
|
|
65994
|
+
return `This directory no longer declares it. Pass --allow-delete to delete it in ${target} too: that deletes only what this directory dropped, and resources only ${target} holds are kept. Or restore it to keep it.`;
|
|
65995
|
+
}
|
|
65996
|
+
if (code === "W_UNDECLARED" && targetOnly) {
|
|
65997
|
+
return `Only workspace ${target} holds it: this directory does not declare it and no promotion from it left it there, so the promotion keeps it, with or without --allow-delete. To delete it there, add --delete-target-only beside --allow-delete; to manage it from this directory, declare it here.`;
|
|
65807
65998
|
}
|
|
65808
65999
|
if (code === "E_APPLY_NO_BASE") {
|
|
65809
66000
|
return `Workspace ${target} holds this resource, but no promotion from this directory recorded it. Rename the declaration, or rename or delete the resource in ${target}, then promote again.`;
|
|
65810
66001
|
}
|
|
65811
66002
|
return;
|
|
65812
66003
|
}
|
|
65813
|
-
function withPromotionHint(finding, code,
|
|
65814
|
-
const
|
|
66004
|
+
function withPromotionHint(finding, code, promotion) {
|
|
66005
|
+
const targetOnly = promotion.targetOnly.includes(`${finding.kind}:${finding.key}`);
|
|
66006
|
+
const hint = promotionHint(code, promotion.target, targetOnly);
|
|
65815
66007
|
return hint === undefined ? finding : { ...finding, hint };
|
|
65816
66008
|
}
|
|
65817
66009
|
function promotionDiagnostics(diagnostics, promotion) {
|
|
65818
66010
|
const warned = new Set(promotion.deletedInTarget);
|
|
65819
|
-
return diagnostics.flatMap((finding) => finding.code === "W_SERVER_DELETED" && warned.has(`${finding.kind}:${finding.key}`) ? [] : [withPromotionHint(finding, finding.code, promotion
|
|
66011
|
+
return diagnostics.flatMap((finding) => finding.code === "W_SERVER_DELETED" && warned.has(`${finding.kind}:${finding.key}`) ? [] : [withPromotionHint(finding, finding.code, promotion)]);
|
|
65820
66012
|
}
|
|
65821
66013
|
function promotionWarnings(promotion, outcome) {
|
|
65822
66014
|
const { target } = promotion;
|
|
@@ -65835,11 +66027,12 @@ function promotionWarnings(promotion, outcome) {
|
|
|
65835
66027
|
}
|
|
65836
66028
|
];
|
|
65837
66029
|
});
|
|
65838
|
-
const
|
|
66030
|
+
const onlyInTarget = new Set(promotion.targetOnly);
|
|
66031
|
+
const targetOnly = outcome.plan.filter((change) => change.action === "delete" && onlyInTarget.has(`${change.kind}:${change.key}`) && (!outcome.failed || wasWritten(change, outcome))).map((change) => ({
|
|
65839
66032
|
code: "W_PROMOTE_DELETES_TARGET_ONLY",
|
|
65840
66033
|
severity: "warning",
|
|
65841
|
-
message: `${resourceWhere(change.kind, change.key)} is only in workspace ${target}, not in this directory, so --
|
|
65842
|
-
hint: "Promote without --
|
|
66034
|
+
message: `${resourceWhere(change.kind, change.key)} is only in workspace ${target}, not in this directory, so --delete-target-only deletes it there.`,
|
|
66035
|
+
hint: "Promote without --delete-target-only to keep it, or declare it in this directory.",
|
|
65843
66036
|
kind: change.kind,
|
|
65844
66037
|
key: change.key
|
|
65845
66038
|
}));
|
|
@@ -65853,7 +66046,7 @@ function rehinted(refusal, promotion) {
|
|
|
65853
66046
|
return refusal;
|
|
65854
66047
|
const details = {
|
|
65855
66048
|
...refusal.details,
|
|
65856
|
-
diagnostics: diagnostics.map((finding) => isRecordLike(finding) && typeof finding.code === "string" ? withPromotionHint(finding, finding.code, promotion
|
|
66049
|
+
diagnostics: diagnostics.map((finding) => isRecordLike(finding) && typeof finding.code === "string" ? withPromotionHint(finding, finding.code, promotion) : finding)
|
|
65857
66050
|
};
|
|
65858
66051
|
const copy = new SimApiError(refusal.message, refusal.status, refusal.code, details, refusal.exitCode, refusal.requestId);
|
|
65859
66052
|
copy.retryAfterMs = refusal.retryAfterMs;
|
|
@@ -65874,7 +66067,8 @@ function attachWorkspaceSourceApply(source) {
|
|
|
65874
66067
|
"copy every workflow from a dev workspace into a prod workspace (--to)",
|
|
65875
66068
|
"save bulk edits to every workflow"
|
|
65876
66069
|
]);
|
|
65877
|
-
command.option("--dir <dir>", "Workspace source directory written by `workspaces source get`", ".").option("--dry-run", "Plan and check without writing anything").option("-y, --yes", "Apply without asking for confirmation").option("--allow-delete", "Delete resources, columns and data the directory no longer declares").option("--only <kinds>", `Apply only these kinds (${ONLY_KINDS_HELP})`).option("--to <workspaceId>", "Promote the directory to another workspace (dev to prod): its resources bind by key to that workspace's own and are updated in place. Only .sim/targets/<workspaceId>.json changes, the record the next promotion compares with: a resource changed there since is kept, or refused as stale (exit 5) when the directory changed it too").allowExcessArguments(false).description("Apply a workspace source directory").addHelpText("after", `${sourceExitCodesHelp("workspaces source apply")}${SOURCE_WRITE_EXIT_CODES_HELP}`).action(async (options) => {
|
|
66070
|
+
command.option("--dir <dir>", "Workspace source directory written by `workspaces source get`", ".").option("--dry-run", "Plan and check without writing anything").option("-y, --yes", "Apply without asking for confirmation").option("--allow-delete", "Delete resources, columns and data the directory no longer declares (with --to, only what it deleted since the last promotion: the target's own resources are kept)").option("--delete-target-only", "With --to and --allow-delete, also delete the target's resources this directory never declared and no promotion from it left there (prod-only tables and their rows, skills made in prod). Without it a promotion keeps them, naming each with a warning").option("--only <kinds>", `Apply only these kinds (${ONLY_KINDS_HELP})`).option("--to <workspaceId>", "Promote the directory to another workspace (dev to prod): its resources bind by key to that workspace's own and are updated in place. Only .sim/targets/<workspaceId>.json changes, the record the next promotion compares with: a resource changed there since is kept, or refused as stale (exit 5) when the directory changed it too").allowExcessArguments(false).description("Apply a workspace source directory").addHelpText("after", `${sourceExitCodesHelp("workspaces source apply")}${SOURCE_WRITE_EXIT_CODES_HELP}`).action(async (options) => {
|
|
66071
|
+
assertTargetOnlyDeletable(options);
|
|
65878
66072
|
const mode = writeMode(options);
|
|
65879
66073
|
const only = parseKinds(options.only);
|
|
65880
66074
|
const { client, profile } = connect();
|
|
@@ -65941,7 +66135,7 @@ function attachWorkspaceSourceApply(source) {
|
|
|
65941
66135
|
await assertWorkspaceDir(options.dir);
|
|
65942
66136
|
}
|
|
65943
66137
|
assertBlobsFetched(options.dir, read, written.digests);
|
|
65944
|
-
promotion = options.to ? await promoted(client, options.dir, read, options.to, options.
|
|
66138
|
+
promotion = options.to ? await promoted(client, options.dir, read, options.to, options.deleteTargetOnly === true) : null;
|
|
65945
66139
|
const submission = promotion?.submission ?? read;
|
|
65946
66140
|
const reported = (data) => promotion ? {
|
|
65947
66141
|
...data,
|
|
@@ -66019,9 +66213,20 @@ function applyCommand(options) {
|
|
|
66019
66213
|
`sim workspaces source apply --dir ${shellWord(options.dir)}`,
|
|
66020
66214
|
...options.only ? [`--only ${shellWord(options.only)}`] : [],
|
|
66021
66215
|
...options.to ? [`--to ${shellWord(options.to)}`] : [],
|
|
66022
|
-
...options.allowDelete ? ["--allow-delete"] : []
|
|
66216
|
+
...options.allowDelete ? ["--allow-delete"] : [],
|
|
66217
|
+
...options.deleteTargetOnly ? ["--delete-target-only"] : []
|
|
66023
66218
|
].join(" ");
|
|
66024
66219
|
}
|
|
66220
|
+
function assertTargetOnlyDeletable(options) {
|
|
66221
|
+
if (!options.deleteTargetOnly)
|
|
66222
|
+
return;
|
|
66223
|
+
if (!options.to) {
|
|
66224
|
+
throw new CliUsageError("--delete-target-only deletes a promotion target's own resources: it needs --to <workspaceId>.");
|
|
66225
|
+
}
|
|
66226
|
+
if (!options.allowDelete) {
|
|
66227
|
+
throw new CliUsageError("--delete-target-only needs --allow-delete beside it: add it, and the promotion also deletes what this directory deleted since the last promotion.");
|
|
66228
|
+
}
|
|
66229
|
+
}
|
|
66025
66230
|
function notSentFindings(paths) {
|
|
66026
66231
|
return paths.map((path) => ({
|
|
66027
66232
|
code: "W_PATH_NOT_SENT",
|
|
@@ -66115,6 +66320,7 @@ ${SOURCE_DIR_BUSY_HELP}`).action(async (options, command) => {
|
|
|
66115
66320
|
};
|
|
66116
66321
|
const keys = await workspaceWorkflowKeys(options.dir);
|
|
66117
66322
|
const findings = [];
|
|
66323
|
+
const unlisted = { errors: 0, warnings: 0 };
|
|
66118
66324
|
for (const key of keys) {
|
|
66119
66325
|
const checked = await checkWorkflowDir(join12(options.dir, KIND_DIRS.workflow, key), catalog, {
|
|
66120
66326
|
declarations,
|
|
@@ -66122,6 +66328,8 @@ ${SOURCE_DIR_BUSY_HELP}`).action(async (options, command) => {
|
|
|
66122
66328
|
prefix: `${KIND_DIRS.workflow}/${key}/`
|
|
66123
66329
|
});
|
|
66124
66330
|
findings.push(...checked.findings);
|
|
66331
|
+
unlisted.errors += checked.unlisted.errors;
|
|
66332
|
+
unlisted.warnings += checked.unlisted.warnings;
|
|
66125
66333
|
}
|
|
66126
66334
|
for (const {
|
|
66127
66335
|
code,
|
|
@@ -66144,7 +66352,7 @@ ${SOURCE_DIR_BUSY_HELP}`).action(async (options, command) => {
|
|
|
66144
66352
|
}
|
|
66145
66353
|
await refreshWorkspaceTypes(options.dir, withWorkflowInputs(declarations.local, workflowInputs));
|
|
66146
66354
|
await refreshWorkspaceTsconfigs(options.dir, workspaceId);
|
|
66147
|
-
reportCheck(profile.output, findings, { workflows: keys.length, catalogHash: catalog.hash }, { verbose: options.verbose === true, bound: WORKSPACE_ANSWER_BOUND });
|
|
66355
|
+
reportCheck(profile.output, findings, { workflows: keys.length, catalogHash: catalog.hash }, { verbose: options.verbose === true, bound: WORKSPACE_ANSWER_BOUND, unlisted });
|
|
66148
66356
|
});
|
|
66149
66357
|
});
|
|
66150
66358
|
}
|
|
@@ -66320,6 +66528,9 @@ function attachWorkspaceSourceGet(source) {
|
|
|
66320
66528
|
const result = await writeWorkspaceSource(client, options.dir, data, options.force === true);
|
|
66321
66529
|
const findings = findingsOutput(profile.output);
|
|
66322
66530
|
findings.print(data.diagnostics);
|
|
66531
|
+
for (const { kind, key, reason } of data.skipped) {
|
|
66532
|
+
printError(`Skipped ${kind} ${key}: ${reason} It is not written here, and an apply keeps it as the server has it (${WORKSPACE_SKIPPED_FILE} lists it).`);
|
|
66533
|
+
}
|
|
66323
66534
|
printTreeResult(profile.output, {
|
|
66324
66535
|
workspaceId: data.workspaceId,
|
|
66325
66536
|
dir: options.dir,
|
|
@@ -66353,9 +66564,10 @@ async function readLocalWorkspace(dir, only) {
|
|
|
66353
66564
|
current[path] = digest(text);
|
|
66354
66565
|
for (const blob of submission.blobs)
|
|
66355
66566
|
current[blob.path] = blob.sha256;
|
|
66567
|
+
const unnamed = new Set(submission.unnamed);
|
|
66356
66568
|
const changed = changedFiles(current, written.digests, (path) => {
|
|
66357
66569
|
const kind = kindOfPath(path);
|
|
66358
|
-
return kind !== null && (!only || only.includes(kind));
|
|
66570
|
+
return kind !== null && (!only || only.includes(kind)) && !unnamed.has(path);
|
|
66359
66571
|
});
|
|
66360
66572
|
return { submission, written, changed, readFrom };
|
|
66361
66573
|
}
|
|
@@ -66508,6 +66720,7 @@ ${SOURCE_DIR_BUSY_HELP}`).action(async (options, invoked) => {
|
|
|
66508
66720
|
server,
|
|
66509
66721
|
...note ? { note } : {},
|
|
66510
66722
|
...status,
|
|
66723
|
+
...local.submission.unnamed.length > 0 ? { unnamed: local.submission.unnamed } : {},
|
|
66511
66724
|
plan,
|
|
66512
66725
|
next: (login ? null : unmanagedNext(status, local.submission.kinds, options.dir, workspaceScope)) ?? nextStep(status, {
|
|
66513
66726
|
prefix: PREFIX2,
|