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/index.js
CHANGED
|
@@ -42397,6 +42397,7 @@ class CliUsageError extends LocalRefusal {
|
|
|
42397
42397
|
}
|
|
42398
42398
|
|
|
42399
42399
|
// src/commands/protocol/source-dir/command-lock.ts
|
|
42400
|
+
import { rmSync as rmSync3 } from "node:fs";
|
|
42400
42401
|
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";
|
|
42401
42402
|
import { hostname } from "node:os";
|
|
42402
42403
|
import { dirname as dirname7, join as join6, resolve as resolve4 } from "node:path";
|
|
@@ -45987,7 +45988,7 @@ function formerBlockHint(ctx, formerKey, renamed, rewritten, spell) {
|
|
|
45987
45988
|
const unbound = [...ctx.declsByKey.values()].filter((decl) => !ctx.knownKeys.has(decl.key) && !renamedTo.has(decl.key));
|
|
45988
45989
|
const lead = `${spell([{ kind: "name", name: formerKey }])} is a block this workflow had that ${SOURCE_ENTRY_FILE} no longer declares under that key`;
|
|
45989
45990
|
const [only] = unbound;
|
|
45990
|
-
return unbound.length === 1 && only ? `${lead}: if ${only.name}
|
|
45991
|
+
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.`;
|
|
45991
45992
|
}
|
|
45992
45993
|
function subflowScopeRef(ctx, node, container, members, site) {
|
|
45993
45994
|
const kind = containerKindOf(container) ?? "loop";
|
|
@@ -48277,8 +48278,11 @@ function readCodeFile(ctx, compiled, language, decl) {
|
|
|
48277
48278
|
}
|
|
48278
48279
|
function parseCodeFile(ctx, path, text, language, at, decl) {
|
|
48279
48280
|
const { limits } = ctx;
|
|
48281
|
+
const before = ctx.codeFiles.bytes;
|
|
48280
48282
|
ctx.codeFiles.bytes += utf8Bytes(text, limits.maxTotalBytes);
|
|
48281
48283
|
if (ctx.codeFiles.bytes > limits.maxTotalBytes) {
|
|
48284
|
+
if (before > limits.maxTotalBytes)
|
|
48285
|
+
return null;
|
|
48282
48286
|
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 });
|
|
48283
48287
|
return null;
|
|
48284
48288
|
}
|
|
@@ -50417,6 +50421,9 @@ var refusalClass = refusalClassifier();
|
|
|
50417
50421
|
var CHANGED_BLOCK_REFUSALS = new Map([
|
|
50418
50422
|
["W_REF_OUT_OF_SCOPE", "E_APPLY_REF_OUT_OF_SCOPE"]
|
|
50419
50423
|
]);
|
|
50424
|
+
var PARAM_REFUSALS = new Map([
|
|
50425
|
+
["W_UNKNOWN_OPTION", "E_APPLY_INVALID_SUBBLOCK_FIELD"]
|
|
50426
|
+
]);
|
|
50420
50427
|
var ENTRY_REFUSALS = new Map([
|
|
50421
50428
|
["W_UNKNOWN_OUTPUT_PATH", "E_APPLY_UNRESOLVED_REF"]
|
|
50422
50429
|
]);
|
|
@@ -50426,6 +50433,7 @@ var CODE_FILE_REFUSALS = new Map([
|
|
|
50426
50433
|
["W_CODE_FILE_REF_SYNTAX", "E_APPLY_CODE_FILE_REF_SYNTAX"]
|
|
50427
50434
|
]);
|
|
50428
50435
|
var REFUSABLE_WARNING_CODES = new Set([
|
|
50436
|
+
"W_UNKNOWN_OPTION",
|
|
50429
50437
|
"W_REF_OUT_OF_SCOPE",
|
|
50430
50438
|
"W_UNKNOWN_OUTPUT_PATH",
|
|
50431
50439
|
"W_UNRESOLVED_REF",
|
|
@@ -50437,6 +50445,11 @@ var EDIT_REFUSALS = [
|
|
|
50437
50445
|
refusal,
|
|
50438
50446
|
where: "changed block"
|
|
50439
50447
|
})),
|
|
50448
|
+
...[...PARAM_REFUSALS].map(([warning, refusal]) => ({
|
|
50449
|
+
warning,
|
|
50450
|
+
refusal,
|
|
50451
|
+
where: "workflow.ts"
|
|
50452
|
+
})),
|
|
50440
50453
|
...[...ENTRY_REFUSALS].map(([warning, refusal]) => ({
|
|
50441
50454
|
warning,
|
|
50442
50455
|
refusal,
|
|
@@ -50462,6 +50475,15 @@ function refusalOf(finding, edit) {
|
|
|
50462
50475
|
const edited = edit.changed(blockKey) || !inEntryFile && edit.codeEdited(blockKey, span.file);
|
|
50463
50476
|
return edited ? onChanged : undefined;
|
|
50464
50477
|
}
|
|
50478
|
+
const onParam = PARAM_REFUSALS.get(finding.code);
|
|
50479
|
+
if (onParam) {
|
|
50480
|
+
const { param } = finding;
|
|
50481
|
+
if (!inEntryFile || param === undefined || param === "operation")
|
|
50482
|
+
return;
|
|
50483
|
+
if (!edit.changed(blockKey))
|
|
50484
|
+
return;
|
|
50485
|
+
return edit.paramChanged?.(blockKey, param) ?? true ? onParam : undefined;
|
|
50486
|
+
}
|
|
50465
50487
|
if (inEntryFile) {
|
|
50466
50488
|
const inEntry = ENTRY_REFUSALS.get(finding.code);
|
|
50467
50489
|
return inEntry && edit.changed(blockKey) ? inEntry : undefined;
|
|
@@ -50469,6 +50491,9 @@ function refusalOf(finding, edit) {
|
|
|
50469
50491
|
const inCode = CODE_FILE_REFUSALS.get(finding.code);
|
|
50470
50492
|
return inCode && edit.codeEdited(blockKey, span.file) ? inCode : undefined;
|
|
50471
50493
|
}
|
|
50494
|
+
function refusesEdited(finding, edit) {
|
|
50495
|
+
return refusalOf(finding, edit) !== undefined;
|
|
50496
|
+
}
|
|
50472
50497
|
function refuseEditedFindings(compiled, edit) {
|
|
50473
50498
|
const refused = (finding) => {
|
|
50474
50499
|
const code = refusalOf(finding, edit);
|
|
@@ -50652,6 +50677,10 @@ function capLength(text) {
|
|
|
50652
50677
|
class Reporter {
|
|
50653
50678
|
diagnostics = [];
|
|
50654
50679
|
withheld = [];
|
|
50680
|
+
get omitted() {
|
|
50681
|
+
return [...this.omittedCounts.values()];
|
|
50682
|
+
}
|
|
50683
|
+
omittedCounts = new Map;
|
|
50655
50684
|
refusableHeld = new Set;
|
|
50656
50685
|
indexes = new Map;
|
|
50657
50686
|
errorCount = 0;
|
|
@@ -50695,7 +50724,7 @@ class Reporter {
|
|
|
50695
50724
|
if (this.infoCount >= MAX_LISTED)
|
|
50696
50725
|
return;
|
|
50697
50726
|
} else if (this.warningCount >= MAX_LISTED) {
|
|
50698
|
-
this.
|
|
50727
|
+
this.omit(code, message, at, extras);
|
|
50699
50728
|
if (this.warningCount === MAX_LISTED) {
|
|
50700
50729
|
this.truncated(`Listed ${MAX_LISTED} warnings; the rest are omitted. The next: ${message}`, at, framesSource(code));
|
|
50701
50730
|
}
|
|
@@ -50704,7 +50733,7 @@ class Reporter {
|
|
|
50704
50733
|
const ofCode = this.warningsByCode.get(code) ?? 0;
|
|
50705
50734
|
this.warningsByCode.set(code, ofCode + 1);
|
|
50706
50735
|
if (ofCode >= MAX_WARNINGS_PER_CODE) {
|
|
50707
|
-
this.
|
|
50736
|
+
this.omit(code, message, at, extras);
|
|
50708
50737
|
if (ofCode === MAX_WARNINGS_PER_CODE) {
|
|
50709
50738
|
this.truncated(`Listed ${MAX_WARNINGS_PER_CODE} ${code} warnings; the rest of them are omitted. The next: ${message}`, at, framesSource(code));
|
|
50710
50739
|
}
|
|
@@ -50716,10 +50745,25 @@ class Reporter {
|
|
|
50716
50745
|
this.refusableHeld.add(held);
|
|
50717
50746
|
this.record(code, message, at, extras, framesSource(code));
|
|
50718
50747
|
}
|
|
50719
|
-
|
|
50748
|
+
omit(code, message, at, extras) {
|
|
50720
50749
|
const held = refusableKey(code, at, extras);
|
|
50721
|
-
if (held === undefined || this.refusableHeld.has(held))
|
|
50750
|
+
if (held === undefined || this.refusableHeld.has(held)) {
|
|
50751
|
+
const refusable = held === undefined ? undefined : { file: at.file, param: extras.param };
|
|
50752
|
+
const key = [code, extras.blockKey ?? "", refusable?.file ?? "", refusable?.param ?? ""].join("\x00");
|
|
50753
|
+
const counted = this.omittedCounts.get(key);
|
|
50754
|
+
if (counted)
|
|
50755
|
+
counted.count++;
|
|
50756
|
+
else {
|
|
50757
|
+
this.omittedCounts.set(key, {
|
|
50758
|
+
code,
|
|
50759
|
+
...extras.blockKey !== undefined ? { blockKey: extras.blockKey } : {},
|
|
50760
|
+
...refusable ? { file: refusable.file } : {},
|
|
50761
|
+
...refusable?.param !== undefined ? { param: refusable.param } : {},
|
|
50762
|
+
count: 1
|
|
50763
|
+
});
|
|
50764
|
+
}
|
|
50722
50765
|
return;
|
|
50766
|
+
}
|
|
50723
50767
|
this.refusableHeld.add(held);
|
|
50724
50768
|
const { hint, ...listed } = extras;
|
|
50725
50769
|
const diagnostic = this.build(code, message, at, listed, framesSource(code));
|
|
@@ -51275,6 +51319,7 @@ function emptyResult(reporter, sdkMajor) {
|
|
|
51275
51319
|
workflow: null,
|
|
51276
51320
|
diagnostics: reporter.diagnostics,
|
|
51277
51321
|
withheld: reporter.withheld,
|
|
51322
|
+
omitted: reporter.omitted,
|
|
51278
51323
|
spans: {},
|
|
51279
51324
|
metaSpans: {},
|
|
51280
51325
|
hints: { blocks: {} },
|
|
@@ -51513,6 +51558,7 @@ function compileEntry(input, file, text, reporter) {
|
|
|
51513
51558
|
workflow,
|
|
51514
51559
|
diagnostics: reporter.diagnostics,
|
|
51515
51560
|
withheld: reporter.withheld,
|
|
51561
|
+
omitted: reporter.omitted,
|
|
51516
51562
|
spans,
|
|
51517
51563
|
metaSpans: ctx.metaSpans,
|
|
51518
51564
|
hints,
|
|
@@ -52507,7 +52553,7 @@ function assertSendableCodeFiles(files) {
|
|
|
52507
52553
|
}
|
|
52508
52554
|
function sourceRelativePath(path) {
|
|
52509
52555
|
const normalized = posix2.normalize(path.replace(/\\/g, "/"));
|
|
52510
|
-
if (normalized.startsWith("/") || /^[A-Za-z]:/.test(normalized) || normalized === "." || normalized === ".." || normalized.startsWith("../")) {
|
|
52556
|
+
if (normalized.includes("\x00") || normalized.startsWith("/") || /^[A-Za-z]:/.test(normalized) || normalized === "." || normalized === ".." || normalized.startsWith("../")) {
|
|
52511
52557
|
return null;
|
|
52512
52558
|
}
|
|
52513
52559
|
return normalized.startsWith("./") ? normalized.slice(2) : normalized;
|
|
@@ -52522,11 +52568,11 @@ function lockCodeFiles(lock) {
|
|
|
52522
52568
|
}
|
|
52523
52569
|
return paths;
|
|
52524
52570
|
}
|
|
52525
|
-
function orphanedCodeFiles(previousLock, nextLock, written) {
|
|
52571
|
+
function orphanedCodeFiles(previousLock, nextLock, written, recorded) {
|
|
52526
52572
|
const kept = lockCodeFiles(nextLock);
|
|
52527
52573
|
for (const path of written)
|
|
52528
52574
|
kept.add(path);
|
|
52529
|
-
return [...lockCodeFiles(previousLock)].filter((path) => path.startsWith(`${SOURCE_CODE_DIR}/`) && isCodeFilePath(path) && !kept.has(path));
|
|
52575
|
+
return [...lockCodeFiles(previousLock)].filter((path) => path.startsWith(`${SOURCE_CODE_DIR}/`) && isCodeFilePath(path) && Object.hasOwn(recorded, path) && !kept.has(path));
|
|
52530
52576
|
}
|
|
52531
52577
|
function writableFiles(files) {
|
|
52532
52578
|
const refused = refusedSourcePaths(files);
|
|
@@ -52907,8 +52953,12 @@ async function withSourceDirLock(dir, run, options = {}) {
|
|
|
52907
52953
|
await writeFile2(join6(lock, LOCK_OWNER_FILE), JSON.stringify(owner));
|
|
52908
52954
|
return await run();
|
|
52909
52955
|
} finally {
|
|
52910
|
-
|
|
52911
|
-
|
|
52956
|
+
try {
|
|
52957
|
+
const held = await checkedPath(root, SOURCE_DIR_LOCK, new Set);
|
|
52958
|
+
rmSync3(held, { recursive: true, force: true });
|
|
52959
|
+
} finally {
|
|
52960
|
+
disposeSignalRelease();
|
|
52961
|
+
}
|
|
52912
52962
|
await removeCreatedFolders();
|
|
52913
52963
|
}
|
|
52914
52964
|
}
|
|
@@ -53049,10 +53099,11 @@ async function editedFiles(dir, touched, written) {
|
|
|
53049
53099
|
}
|
|
53050
53100
|
async function locallyEditedFiles(dir, answer, previousLock) {
|
|
53051
53101
|
const touched = new Map(Object.entries(answer.files));
|
|
53052
|
-
|
|
53102
|
+
const { digests } = await readFolderWritten(dir);
|
|
53103
|
+
for (const path of orphanedCodeFiles(previousLock, answer.lock, touched.keys(), digests)) {
|
|
53053
53104
|
touched.set(path, null);
|
|
53054
53105
|
}
|
|
53055
|
-
return editedFiles(dir, touched,
|
|
53106
|
+
return editedFiles(dir, touched, digests);
|
|
53056
53107
|
}
|
|
53057
53108
|
function inWorkspace(key, path) {
|
|
53058
53109
|
return `${KIND_DIRS.workflow}/${key}/${path}`;
|
|
@@ -53117,7 +53168,7 @@ async function writeBack(dir, answer, previousLock, extra = { write: [] }) {
|
|
|
53117
53168
|
`]
|
|
53118
53169
|
];
|
|
53119
53170
|
const write = [...printed, ...folder ? [] : writtenFiles(writtenRecord(files)), ...extra.write];
|
|
53120
|
-
const orphaned = orphanedCodeFiles(previousLock, answer.lock, Object.keys(answer.files));
|
|
53171
|
+
const orphaned = orphanedCodeFiles(previousLock, answer.lock, Object.keys(answer.files), (await readFolderWritten(dir)).digests);
|
|
53121
53172
|
const unnamed = await unnamedCodeFiles(dir, previousLock, answer, orphaned);
|
|
53122
53173
|
await updateSourceDir(dir, {
|
|
53123
53174
|
write,
|
|
@@ -53168,7 +53219,7 @@ function sourceExitCodeRows(prefix) {
|
|
|
53168
53219
|
},
|
|
53169
53220
|
{
|
|
53170
53221
|
code: 1,
|
|
53171
|
-
meaning:
|
|
53222
|
+
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`,
|
|
53172
53223
|
next: "Fix what it printed and run it again",
|
|
53173
53224
|
help: {
|
|
53174
53225
|
"workflows source apply": "the source has errors (each printed as file:line:column with its frame and hint) or the command failed",
|
|
@@ -53320,7 +53371,7 @@ have been written and how to check.`;
|
|
|
53320
53371
|
|
|
53321
53372
|
// src/commands/protocol/source-tree.ts
|
|
53322
53373
|
import { createHash as createHash5 } from "node:crypto";
|
|
53323
|
-
import { rmSync as
|
|
53374
|
+
import { rmSync as rmSync4 } from "node:fs";
|
|
53324
53375
|
import { mkdir as mkdir3, mkdtemp as mkdtemp3, readFile as readFile3, rename as rename3, rm as rm4, writeFile as writeFile3 } from "node:fs/promises";
|
|
53325
53376
|
import { dirname as dirname8, join as join7 } from "node:path";
|
|
53326
53377
|
|
|
@@ -56013,7 +56064,7 @@ function writeWorkspaceCatalogPointer(workspaceId, hash) {
|
|
|
56013
56064
|
if (legacy === `${hash}.json`)
|
|
56014
56065
|
continue;
|
|
56015
56066
|
try {
|
|
56016
|
-
|
|
56067
|
+
rmSync4(join7(catalogCacheDir(), legacy), { recursive: true, force: true });
|
|
56017
56068
|
} catch {}
|
|
56018
56069
|
}
|
|
56019
56070
|
}
|
|
@@ -56456,8 +56507,14 @@ function isMachine(format) {
|
|
|
56456
56507
|
function resultDiagnostics(format, diagnostics, verbose = false) {
|
|
56457
56508
|
if (!isMachine(format))
|
|
56458
56509
|
return {};
|
|
56510
|
+
const hidden = (finding) => !verbose && finding.severity === "info" && finding.code !== "I_FINDINGS_TRUNCATED";
|
|
56511
|
+
const hiddenCount = diagnostics.filter(hidden).length;
|
|
56512
|
+
const marked = (finding) => finding.code === "I_FINDINGS_TRUNCATED" && hiddenCount > 0 ? {
|
|
56513
|
+
...finding,
|
|
56514
|
+
message: `${finding.message} ${hiddenCount} info finding${hiddenCount === 1 ? "" : "s"} listed ${hiddenCount === 1 ? "is" : "are"} hidden too; pass --verbose to see ${hiddenCount === 1 ? "it" : "them"}.`
|
|
56515
|
+
} : finding;
|
|
56459
56516
|
return {
|
|
56460
|
-
diagnostics: diagnostics.filter((finding) =>
|
|
56517
|
+
diagnostics: diagnostics.filter((finding) => !hidden(finding)).map(({ frame: _frame, ...finding }) => marked(finding))
|
|
56461
56518
|
};
|
|
56462
56519
|
}
|
|
56463
56520
|
function findingKey(diagnostic) {
|
|
@@ -56750,7 +56807,7 @@ async function readJson(directory, path, hint) {
|
|
|
56750
56807
|
}
|
|
56751
56808
|
function codeFilePaths(entry, lock) {
|
|
56752
56809
|
const candidates = lockCodeFiles(lock);
|
|
56753
|
-
for (const literal of codeFileReferences(entry)) {
|
|
56810
|
+
for (const literal of entry === null ? [] : codeFileReferences(entry)) {
|
|
56754
56811
|
const path = sourceRelativePath(literal);
|
|
56755
56812
|
if (path)
|
|
56756
56813
|
candidates.add(path);
|
|
@@ -56818,7 +56875,7 @@ The primer above is enough to edit; read a section here when a step needs it.
|
|
|
56818
56875
|
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\`.
|
|
56819
56876
|
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.
|
|
56820
56877
|
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.
|
|
56821
|
-
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).
|
|
56878
|
+
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).
|
|
56822
56879
|
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.
|
|
56823
56880
|
|
|
56824
56881
|
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.
|
|
@@ -57045,7 +57102,7 @@ async function writeWorkflowSource(args) {
|
|
|
57045
57102
|
report(data, deployment);
|
|
57046
57103
|
}
|
|
57047
57104
|
async function deployStep(client, data, options) {
|
|
57048
|
-
const deployCommand = `sim workflows deploy ${data.workflowId}`;
|
|
57105
|
+
const deployCommand = `sim workflows deploy ${data.workflowId} --expected-draft-fingerprint ${data.base.fingerprint}`;
|
|
57049
57106
|
if (!options.deploy) {
|
|
57050
57107
|
if (!data.needsRedeployment)
|
|
57051
57108
|
return {};
|
|
@@ -57056,6 +57113,24 @@ async function deployStep(client, data, options) {
|
|
|
57056
57113
|
}
|
|
57057
57114
|
};
|
|
57058
57115
|
}
|
|
57116
|
+
if (!data.applied && !data.needsRedeployment) {
|
|
57117
|
+
const status = await client.request("getWorkflowDeployment", {
|
|
57118
|
+
params: { workflowId: data.workflowId }
|
|
57119
|
+
}).then((response) => response.data, (error) => {
|
|
57120
|
+
throw deployFailure(error, options, deployCommand);
|
|
57121
|
+
});
|
|
57122
|
+
if (status.isDeployed && !status.needsRedeployment) {
|
|
57123
|
+
if (!options.machine)
|
|
57124
|
+
printError("The live version already matches the draft; nothing was deployed.");
|
|
57125
|
+
return {
|
|
57126
|
+
deployed: {
|
|
57127
|
+
...status.activeDeployment ? { version: status.activeDeployment.version } : {},
|
|
57128
|
+
isDeployed: true
|
|
57129
|
+
},
|
|
57130
|
+
needsRedeployment: false
|
|
57131
|
+
};
|
|
57132
|
+
}
|
|
57133
|
+
}
|
|
57059
57134
|
const deployed = await client.request("deployWorkflow", {
|
|
57060
57135
|
params: { workflowId: data.workflowId },
|
|
57061
57136
|
body: { expectedDraftFingerprint: data.base.fingerprint }
|
|
@@ -57090,6 +57165,7 @@ function attachWorkflowSourceApply(source) {
|
|
|
57090
57165
|
const [command, connectApply] = apiCommand(source, "apply", [
|
|
57091
57166
|
"applyWorkflowSource",
|
|
57092
57167
|
"deployWorkflow",
|
|
57168
|
+
"getWorkflowDeployment",
|
|
57093
57169
|
"getSourceResources"
|
|
57094
57170
|
]);
|
|
57095
57171
|
absoluteDirOption(command);
|
|
@@ -57138,7 +57214,8 @@ function attachWorkflowSourceCreate(source) {
|
|
|
57138
57214
|
"createWorkflowFromSource",
|
|
57139
57215
|
"getSourceCatalog",
|
|
57140
57216
|
"getSourceResources",
|
|
57141
|
-
"deployWorkflow"
|
|
57217
|
+
"deployWorkflow",
|
|
57218
|
+
"getWorkflowDeployment"
|
|
57142
57219
|
]);
|
|
57143
57220
|
absoluteDirOption(command);
|
|
57144
57221
|
verboseFlag(command);
|
|
@@ -63443,7 +63520,7 @@ var ADVANCED_GUIDE = `# Sim workspace source: advanced
|
|
|
63443
63520
|
|
|
63444
63521
|
## Promote to another workspace
|
|
63445
63522
|
|
|
63446
|
-
\`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
|
|
63523
|
+
\`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\`).
|
|
63447
63524
|
`;
|
|
63448
63525
|
var WORKSPACE_TREE = {
|
|
63449
63526
|
kind: "workspace",
|
|
@@ -63652,6 +63729,32 @@ async function assertWorkspaceDir(dir) {
|
|
|
63652
63729
|
function keepFile(kind) {
|
|
63653
63730
|
return isFileKind(kind) ? null : `${KIND_DIRS[kind]}/${KEEP_FILE}`;
|
|
63654
63731
|
}
|
|
63732
|
+
function dropUnnamedCodeFiles(files) {
|
|
63733
|
+
const named = new Map;
|
|
63734
|
+
const unnamed = [];
|
|
63735
|
+
for (const path of Object.keys(files)) {
|
|
63736
|
+
if (kindOfPath(path) !== "workflow")
|
|
63737
|
+
continue;
|
|
63738
|
+
const segments = path.split("/");
|
|
63739
|
+
if (segments[2] !== SOURCE_CODE_DIR)
|
|
63740
|
+
continue;
|
|
63741
|
+
const folder = segments.slice(0, 2).join("/");
|
|
63742
|
+
let sent = named.get(folder);
|
|
63743
|
+
if (!sent) {
|
|
63744
|
+
let lock = null;
|
|
63745
|
+
try {
|
|
63746
|
+
lock = JSON.parse(files[`${folder}/${SOURCE_LOCK_FILE}`] ?? "null");
|
|
63747
|
+
} catch {}
|
|
63748
|
+
sent = new Set(codeFilePaths(files[`${folder}/${SOURCE_ENTRY_FILE}`] ?? null, lock));
|
|
63749
|
+
named.set(folder, sent);
|
|
63750
|
+
}
|
|
63751
|
+
if (!sent.has(segments.slice(2).join("/"))) {
|
|
63752
|
+
unnamed.push(path);
|
|
63753
|
+
delete files[path];
|
|
63754
|
+
}
|
|
63755
|
+
}
|
|
63756
|
+
return unnamed.sort(compareStrings);
|
|
63757
|
+
}
|
|
63655
63758
|
function pruneUnchangedWorkflows(files, written, workspaceId) {
|
|
63656
63759
|
const workflowPaths = Object.keys(files).filter((path) => kindOfPath(path) === "workflow");
|
|
63657
63760
|
const folders = KIND_LAYOUTS.workflow.group(workflowPaths).groups;
|
|
@@ -63696,6 +63799,7 @@ async function readWorkspaceDir(dir, only, workspaceId, written, options = {}) {
|
|
|
63696
63799
|
if (text !== null)
|
|
63697
63800
|
files[path] = text;
|
|
63698
63801
|
});
|
|
63802
|
+
const unnamed = dropUnnamedCodeFiles(files);
|
|
63699
63803
|
if (!options.whole)
|
|
63700
63804
|
pruneUnchangedWorkflows(files, written, workspaceId);
|
|
63701
63805
|
const root = await realpath4(dir);
|
|
@@ -63724,7 +63828,7 @@ async function readWorkspaceDir(dir, only, workspaceId, written, options = {}) {
|
|
|
63724
63828
|
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" });
|
|
63725
63829
|
}
|
|
63726
63830
|
}
|
|
63727
|
-
return { kinds, files, blobs, ignored, hashed, ...base ? { base } : {} };
|
|
63831
|
+
return { kinds, files, blobs, ignored, unnamed, hashed, ...base ? { base } : {} };
|
|
63728
63832
|
}
|
|
63729
63833
|
function skippedFile(skipped) {
|
|
63730
63834
|
return skipped.length > 0 ? `${JSON.stringify(skipped, null, 2)}
|
|
@@ -63970,7 +64074,7 @@ async function compileWorkflowDir(dir, workspaceCatalog, declarations) {
|
|
|
63970
64074
|
...storedEdges ? { storedUnreadEdges: storedEdges } : {},
|
|
63971
64075
|
...envNames ? { envNames, envDeclaredIn: KIND_DIRS.secret } : {}
|
|
63972
64076
|
});
|
|
63973
|
-
return { lock, files, compiled, storedBlocks, printedWith };
|
|
64077
|
+
return { lock, files, compiled, storedBlocks, printedWith, catalog };
|
|
63974
64078
|
}
|
|
63975
64079
|
async function workspaceWorkflowInputs(root, catalog) {
|
|
63976
64080
|
const inputs = new Map;
|
|
@@ -63991,7 +64095,8 @@ function withWorkflowInputs(local, inputs) {
|
|
|
63991
64095
|
return { ...local, workflows };
|
|
63992
64096
|
}
|
|
63993
64097
|
async function checkWorkflowDir(dir, catalog, options) {
|
|
63994
|
-
const
|
|
64098
|
+
const compiledDir = await compileWorkflowDir(dir, catalog, options.declarations);
|
|
64099
|
+
const { lock, files, compiled, storedBlocks, printedWith } = compiledDir;
|
|
63995
64100
|
const entryText = files[SOURCE_ENTRY_FILE];
|
|
63996
64101
|
const locate = (block, param, names) => {
|
|
63997
64102
|
const prefix = encodeAnchor({ kind: "param", block, param: "" });
|
|
@@ -64053,19 +64158,30 @@ async function checkWorkflowDir(dir, catalog, options) {
|
|
|
64053
64158
|
const head = /^(?:\$ref\.|<)([A-Za-z0-9_]+)/.exec(text)?.[1];
|
|
64054
64159
|
return head !== undefined && removedKeys.has(head);
|
|
64055
64160
|
};
|
|
64056
|
-
const
|
|
64161
|
+
const variesByDeployment = (finding) => {
|
|
64162
|
+
const { blockKey, param } = finding;
|
|
64163
|
+
if (finding.code !== "W_UNKNOWN_OPTION" || blockKey === undefined || param === undefined) {
|
|
64164
|
+
return false;
|
|
64165
|
+
}
|
|
64166
|
+
const type = compiled.workflow ? getOwn(compiled.workflow.blocks, blockKey)?.type : undefined;
|
|
64167
|
+
const block = type === undefined ? undefined : catalogBlock(compiledDir.catalog, type);
|
|
64168
|
+
return block?.subBlocks.some((sub) => sub.id === param && sub.optionsVary === true) === true;
|
|
64169
|
+
};
|
|
64170
|
+
const exempt = (finding) => mayBeRenamed(finding) || variesByDeployment(finding);
|
|
64171
|
+
const refusable = (finding) => !exempt(finding);
|
|
64057
64172
|
const refused = [
|
|
64058
64173
|
...refuseEditedFindings({
|
|
64059
64174
|
diagnostics: compiled.diagnostics.filter(refusable),
|
|
64060
64175
|
withheld: compiled.withheld.filter(refusable)
|
|
64061
64176
|
}, { changed, codeEdited }),
|
|
64062
|
-
...compiled.diagnostics.filter(
|
|
64177
|
+
...compiled.diagnostics.filter(exempt)
|
|
64063
64178
|
];
|
|
64064
64179
|
const findings = [
|
|
64065
64180
|
...refused.filter((diagnostic) => reported(diagnostic.code, diagnostic.blockKey)),
|
|
64066
64181
|
...declared
|
|
64067
|
-
].map((
|
|
64068
|
-
const
|
|
64182
|
+
].map((finding) => {
|
|
64183
|
+
const { code, severity, message, hint, frame, span, blockKey } = finding;
|
|
64184
|
+
const raised = severity === "warning" && !variesByDeployment(finding) && fails(code, blockKey);
|
|
64069
64185
|
return {
|
|
64070
64186
|
code,
|
|
64071
64187
|
severity: raised ? "error" : severity,
|
|
@@ -64075,19 +64191,52 @@ async function checkWorkflowDir(dir, catalog, options) {
|
|
|
64075
64191
|
...span ? { file: `${prefix}${span.file}`, line: span.line, column: span.column } : {}
|
|
64076
64192
|
};
|
|
64077
64193
|
});
|
|
64078
|
-
|
|
64194
|
+
const unlisted = { errors: 0, warnings: 0 };
|
|
64195
|
+
const edit = { changed, codeEdited };
|
|
64196
|
+
for (const { code, blockKey, count, varies, refused: isRefused } of [
|
|
64197
|
+
...compiled.omitted.map((omitted) => {
|
|
64198
|
+
const finding = {
|
|
64199
|
+
code: omitted.code,
|
|
64200
|
+
severity: "warning",
|
|
64201
|
+
...omitted.blockKey !== undefined ? { blockKey: omitted.blockKey } : {},
|
|
64202
|
+
...omitted.param !== undefined ? { param: omitted.param } : {}
|
|
64203
|
+
};
|
|
64204
|
+
const varies = variesByDeployment(finding);
|
|
64205
|
+
return {
|
|
64206
|
+
...omitted,
|
|
64207
|
+
varies,
|
|
64208
|
+
refused: !varies && omitted.file !== undefined && refusesEdited({ ...finding, span: { file: omitted.file } }, edit)
|
|
64209
|
+
};
|
|
64210
|
+
}),
|
|
64211
|
+
...compiled.withheld.filter((finding) => !refusable(finding) || !refusesEdited(finding, edit)).map((finding) => ({
|
|
64212
|
+
code: finding.code,
|
|
64213
|
+
blockKey: finding.blockKey,
|
|
64214
|
+
count: 1,
|
|
64215
|
+
varies: variesByDeployment(finding),
|
|
64216
|
+
refused: false
|
|
64217
|
+
}))
|
|
64218
|
+
]) {
|
|
64219
|
+
if (!reported(code, blockKey))
|
|
64220
|
+
continue;
|
|
64221
|
+
if (isRefused || !varies && fails(code, blockKey))
|
|
64222
|
+
unlisted.errors += count;
|
|
64223
|
+
else
|
|
64224
|
+
unlisted.warnings += count;
|
|
64225
|
+
}
|
|
64226
|
+
return { findings, entry: entryText, unlisted };
|
|
64079
64227
|
}
|
|
64080
64228
|
function reportCheck(output, findings, result, options = {}) {
|
|
64081
64229
|
const shown = findingsOutput(output, options.verbose);
|
|
64082
64230
|
const listed = boundAnswerFindings(findings, options.bound);
|
|
64083
64231
|
shown.print(listed);
|
|
64084
|
-
const
|
|
64232
|
+
const unlisted = options.unlisted ?? { errors: 0, warnings: 0 };
|
|
64233
|
+
const errors = findings.filter((finding) => finding.severity === "error").length + unlisted.errors;
|
|
64085
64234
|
if (errors > 0)
|
|
64086
64235
|
setSoftExitCode(1);
|
|
64087
64236
|
printProtocolResult(output, {
|
|
64088
64237
|
checked: "compile",
|
|
64089
64238
|
errors,
|
|
64090
|
-
warnings: findings.filter((finding) => finding.severity === "warning").length,
|
|
64239
|
+
warnings: findings.filter((finding) => finding.severity === "warning").length + unlisted.warnings,
|
|
64091
64240
|
...result,
|
|
64092
64241
|
...shown.result(listed)
|
|
64093
64242
|
});
|
|
@@ -64131,7 +64280,7 @@ function attachWorkflowSourceCheck(source) {
|
|
|
64131
64280
|
...await readWorkspaceDeclarations(workspace.root),
|
|
64132
64281
|
workflowInputs: await workspaceWorkflowInputs(workspace.root, catalog)
|
|
64133
64282
|
} : undefined;
|
|
64134
|
-
const { findings, entry } = await checkWorkflowDir(options.dir, catalog, {
|
|
64283
|
+
const { findings, entry, unlisted } = await checkWorkflowDir(options.dir, catalog, {
|
|
64135
64284
|
strict: strictMode(options),
|
|
64136
64285
|
...declarations ? { declarations } : {}
|
|
64137
64286
|
});
|
|
@@ -64142,7 +64291,8 @@ function attachWorkflowSourceCheck(source) {
|
|
|
64142
64291
|
await refreshTsconfigs(options.dir, workspaceId, WORKFLOW_TREE, { sources: [entry] }, { incremental: true });
|
|
64143
64292
|
}
|
|
64144
64293
|
reportCheck(profile.output, findings, { catalogHash: catalog.hash }, {
|
|
64145
|
-
verbose: options.verbose === true
|
|
64294
|
+
verbose: options.verbose === true,
|
|
64295
|
+
unlisted
|
|
64146
64296
|
});
|
|
64147
64297
|
});
|
|
64148
64298
|
}
|
|
@@ -64981,6 +65131,9 @@ function printStatusReport(format, heading, report, planLine, findings) {
|
|
|
64981
65131
|
} else {
|
|
64982
65132
|
lines.push(s.yellow(`Server not checked${report.note ? `: ${sanitize(report.note)}` : "."}`));
|
|
64983
65133
|
}
|
|
65134
|
+
if (report.unnamed?.length) {
|
|
65135
|
+
lines.push(s.dim(`Not named by any codeFile(), so applying never sends ${report.unnamed.length === 1 ? "it" : "them"}: ${sanitize(report.unnamed.join(", "))}`));
|
|
65136
|
+
}
|
|
64984
65137
|
if (report.server === "checked" && report.note)
|
|
64985
65138
|
lines.push(s.dim(sanitize(report.note)));
|
|
64986
65139
|
if (report.plan)
|
|
@@ -65148,23 +65301,25 @@ async function readLocalWorkflow(dir) {
|
|
|
65148
65301
|
const base = await readBase(dir, undefined);
|
|
65149
65302
|
const { workflowId } = base;
|
|
65150
65303
|
const written = await readFolderWritten(dir);
|
|
65151
|
-
const
|
|
65152
|
-
|
|
65153
|
-
|
|
65154
|
-
];
|
|
65155
|
-
const
|
|
65156
|
-
for (const path of paths) {
|
|
65304
|
+
const entry = await readSourceText(dir, SOURCE_ENTRY_FILE);
|
|
65305
|
+
const sent = new Set(codeFilePaths(entry, await readPreviousLock(dir)));
|
|
65306
|
+
const listed = (await listSourceFiles(dir, SOURCE_CODE_DIR)).filter((path) => !path.split("/").some((segment) => segment.startsWith(".")));
|
|
65307
|
+
const texts = entry === null ? {} : { [SOURCE_ENTRY_FILE]: entry };
|
|
65308
|
+
for (const path of listed.filter((each) => sent.has(each))) {
|
|
65157
65309
|
const text = await readSourceText(dir, path);
|
|
65158
65310
|
if (text !== null)
|
|
65159
65311
|
texts[path] = text;
|
|
65160
65312
|
}
|
|
65161
65313
|
const current = Object.fromEntries(Object.entries(texts).map(([path, text]) => [path, digest(text)]));
|
|
65314
|
+
const unnamed = listed.filter((path) => !sent.has(path));
|
|
65315
|
+
const ignored = new Set(unnamed);
|
|
65162
65316
|
return {
|
|
65163
65317
|
base,
|
|
65164
65318
|
workflowId,
|
|
65165
65319
|
written,
|
|
65166
65320
|
texts,
|
|
65167
|
-
changed: changedFiles(current, written.digests, () =>
|
|
65321
|
+
changed: changedFiles(current, written.digests, (path) => !ignored.has(path)),
|
|
65322
|
+
unnamed
|
|
65168
65323
|
};
|
|
65169
65324
|
}
|
|
65170
65325
|
function workflowPlanFindings(data) {
|
|
@@ -65247,13 +65402,14 @@ function attachWorkflowSourceStatus(source) {
|
|
|
65247
65402
|
}
|
|
65248
65403
|
}
|
|
65249
65404
|
const status = sourceStatus(locals, serverChanges);
|
|
65250
|
-
const plan = data ? planSummary(data) : null;
|
|
65405
|
+
const plan = data && serverChanges.length === 0 ? planSummary(data) : null;
|
|
65251
65406
|
const report = {
|
|
65252
65407
|
workflowId,
|
|
65253
65408
|
dir: options.dir,
|
|
65254
65409
|
server,
|
|
65255
65410
|
...note ? { note } : {},
|
|
65256
65411
|
...status,
|
|
65412
|
+
...local.unnamed.length > 0 ? { unnamed: local.unnamed } : {},
|
|
65257
65413
|
plan,
|
|
65258
65414
|
next: nextStep(status, {
|
|
65259
65415
|
prefix: PREFIX,
|
|
@@ -65456,15 +65612,22 @@ function promotionSubmission(input) {
|
|
|
65456
65612
|
if (lock !== undefined)
|
|
65457
65613
|
files[lockPath] = lock;
|
|
65458
65614
|
}
|
|
65615
|
+
const targetOnly = [];
|
|
65459
65616
|
const resources = Object.fromEntries(Object.entries(input.target.base.resources).flatMap(([address, live]) => {
|
|
65460
65617
|
const parsed = parseResourceAddress(address);
|
|
65461
65618
|
if (!parsed)
|
|
65462
65619
|
return [];
|
|
65463
65620
|
const keys = declared.get(parsed.kind);
|
|
65464
|
-
if (keys === undefined
|
|
65621
|
+
if (keys === undefined)
|
|
65465
65622
|
return [];
|
|
65466
65623
|
const recorded = input.record?.resources[resourceAddress(parsed.kind, parsed.key)];
|
|
65467
|
-
|
|
65624
|
+
const promoted = recorded?.id === live.id ? recorded : undefined;
|
|
65625
|
+
if (!keys.has(parsed.key) && !promoted) {
|
|
65626
|
+
targetOnly.push(resourceAddress(parsed.kind, parsed.key));
|
|
65627
|
+
if (!input.deleteTargetOnly)
|
|
65628
|
+
return [];
|
|
65629
|
+
}
|
|
65630
|
+
return [[address, promoted ?? live]];
|
|
65468
65631
|
}));
|
|
65469
65632
|
for (const [address, recorded] of Object.entries(input.record?.resources ?? {})) {
|
|
65470
65633
|
if (Object.hasOwn(input.target.base.resources, address))
|
|
@@ -65479,7 +65642,8 @@ function promotionSubmission(input) {
|
|
|
65479
65642
|
return {
|
|
65480
65643
|
files,
|
|
65481
65644
|
base: { ...input.target.base, resources },
|
|
65482
|
-
deletedInTarget: [...new Set(deletedInTarget)].sort(compareStrings)
|
|
65645
|
+
deletedInTarget: [...new Set(deletedInTarget)].sort(compareStrings),
|
|
65646
|
+
targetOnly: targetOnly.sort(compareStrings)
|
|
65483
65647
|
};
|
|
65484
65648
|
}
|
|
65485
65649
|
function promotionRecord(input) {
|
|
@@ -65491,7 +65655,13 @@ function promotionRecord(input) {
|
|
|
65491
65655
|
resources[resourceAddress(parsed.kind, parsed.key)] = entry;
|
|
65492
65656
|
}
|
|
65493
65657
|
}
|
|
65494
|
-
|
|
65658
|
+
const targetOnly = new Set(input.submission.targetOnly);
|
|
65659
|
+
for (const [address, entry] of Object.entries(input.applied.base.resources)) {
|
|
65660
|
+
const parsed = parseResourceAddress(address);
|
|
65661
|
+
if (parsed && !targetOnly.has(address)) {
|
|
65662
|
+
resources[resourceAddress(parsed.kind, parsed.key)] = entry;
|
|
65663
|
+
}
|
|
65664
|
+
}
|
|
65495
65665
|
const workflows = {};
|
|
65496
65666
|
if (!managed.has("workflow")) {
|
|
65497
65667
|
Object.assign(workflows, input.previous?.workflows);
|
|
@@ -65547,6 +65717,10 @@ function outcomeText(change, outcome) {
|
|
|
65547
65717
|
function printPlan(plan, diagnostics, outcome) {
|
|
65548
65718
|
const drifted = new Map(serverResourceChanges(diagnostics).filter((change) => change.server !== "added").map((change) => [`${change.kind}:${change.key}`, change.server]));
|
|
65549
65719
|
const driftOf = (change) => change.action === "noop" ? drifted.get(`${change.kind}:${change.key}`) : undefined;
|
|
65720
|
+
const addressesOf = (code) => new Set(diagnostics.filter((finding) => finding.code === code).map((finding) => `${finding.kind}:${finding.key}`));
|
|
65721
|
+
const stale = addressesOf("E_APPLY_STALE");
|
|
65722
|
+
const deleteRefused = addressesOf("E_APPLY_DELETE_NOT_ALLOWED");
|
|
65723
|
+
const refusedDelete = (change) => change.action === "noop" && deleteRefused.has(`${change.kind}:${change.key}`);
|
|
65550
65724
|
for (const kind of APPLY_ORDER) {
|
|
65551
65725
|
const changes = plan.filter((change) => change.kind === kind);
|
|
65552
65726
|
if (changes.length === 0)
|
|
@@ -65554,14 +65728,19 @@ function printPlan(plan, diagnostics, outcome) {
|
|
|
65554
65728
|
const counts = new Map;
|
|
65555
65729
|
for (const change of changes) {
|
|
65556
65730
|
const drift = driftOf(change);
|
|
65557
|
-
const label = drift ? `${drift} on the server` : change.action === "noop" ? "unchanged" : change.action;
|
|
65731
|
+
const label = drift ? `${drift} on the server` : refusedDelete(change) ? "delete refused" : change.action === "noop" ? "unchanged" : change.action;
|
|
65558
65732
|
counts.set(label, (counts.get(label) ?? 0) + 1);
|
|
65559
65733
|
}
|
|
65560
65734
|
printError(`${KIND_DIRS[kind]}: ${[...counts].map(([label, count]) => `${count} ${label}`).join(", ")}`);
|
|
65561
65735
|
for (const change of changes) {
|
|
65562
65736
|
const drift = driftOf(change);
|
|
65563
65737
|
if (drift) {
|
|
65564
|
-
|
|
65738
|
+
const fate = stale.has(`${change.kind}:${change.key}`) ? "your edit is refused as stale" : "kept as the server has it";
|
|
65739
|
+
printError(` ! ${change.key} (${drift} on the server; ${fate})`);
|
|
65740
|
+
continue;
|
|
65741
|
+
}
|
|
65742
|
+
if (refusedDelete(change)) {
|
|
65743
|
+
printError(` - ${change.key} — refused, needs --allow-delete`);
|
|
65565
65744
|
continue;
|
|
65566
65745
|
}
|
|
65567
65746
|
if (change.action === "noop")
|
|
@@ -65592,7 +65771,7 @@ function missingBlobPaths(error) {
|
|
|
65592
65771
|
return errors.flatMap((finding) => typeof finding.file === "string" ? [finding.file] : []);
|
|
65593
65772
|
}
|
|
65594
65773
|
var WORKFLOW_LOCK_PATH = new RegExp(`^${KIND_DIRS.workflow}/([^/]+)/${SOURCE_LOCK_FILE.replaceAll(".", "\\.")}$`);
|
|
65595
|
-
async function orphanedWorkflowFiles(dir, files) {
|
|
65774
|
+
async function orphanedWorkflowFiles(dir, files, recorded) {
|
|
65596
65775
|
const filesByFolder = new Map;
|
|
65597
65776
|
for (const path of Object.keys(files)) {
|
|
65598
65777
|
if (!path.startsWith(`${KIND_DIRS.workflow}/`))
|
|
@@ -65619,7 +65798,8 @@ async function orphanedWorkflowFiles(dir, files) {
|
|
|
65619
65798
|
if (!isRecordLike(next) || !isRecordLike(next.blocks))
|
|
65620
65799
|
continue;
|
|
65621
65800
|
const previous = await readSourceJson(dir, path);
|
|
65622
|
-
|
|
65801
|
+
const inFolder = Object.fromEntries(Object.entries(recorded).flatMap(([recordedPath, sha]) => recordedPath.startsWith(`${folder}/`) ? [[recordedPath.slice(folder.length + 1), sha]] : []));
|
|
65802
|
+
orphaned.push(...orphanedCodeFiles(previous, next, written, inFolder).map((file) => `${folder}/${file}`));
|
|
65623
65803
|
}
|
|
65624
65804
|
return orphaned;
|
|
65625
65805
|
}
|
|
@@ -65672,7 +65852,7 @@ function droppedResourceFiles(sent, reprinted) {
|
|
|
65672
65852
|
async function saveApplied(dir, data, submission, written, records) {
|
|
65673
65853
|
assertWorkspacePaths(Object.keys(data.files));
|
|
65674
65854
|
const orphaned = [
|
|
65675
|
-
...await orphanedWorkflowFiles(dir, data.files),
|
|
65855
|
+
...await orphanedWorkflowFiles(dir, data.files, written.digests),
|
|
65676
65856
|
...droppedResourceFiles(submission.files, data.files)
|
|
65677
65857
|
];
|
|
65678
65858
|
const kept = { ...written.digests, ...appliedBlobDigests(submission, data.base) };
|
|
@@ -65697,7 +65877,7 @@ function baseWorkflowOf(base) {
|
|
|
65697
65877
|
function baseWorkspaceOf(base) {
|
|
65698
65878
|
return isRecordLike(base) && typeof base.workspaceId === "string" ? base.workspaceId : null;
|
|
65699
65879
|
}
|
|
65700
|
-
async function promoted(client, dir, submission, target,
|
|
65880
|
+
async function promoted(client, dir, submission, target, deleteTargetOnly) {
|
|
65701
65881
|
if (baseWorkspaceOf(submission.base) === target) {
|
|
65702
65882
|
throw new SourceDirError(`${dir} was read from workspace ${target}; apply it without --to.`, {
|
|
65703
65883
|
code: "SOURCE_PROMOTE_SAME_WORKSPACE"
|
|
@@ -65719,14 +65899,15 @@ async function promoted(client, dir, submission, target, allowDelete) {
|
|
|
65719
65899
|
kinds: submission.kinds,
|
|
65720
65900
|
target: { files: data.files, base: targetBase },
|
|
65721
65901
|
record,
|
|
65722
|
-
|
|
65902
|
+
deleteTargetOnly
|
|
65723
65903
|
});
|
|
65724
65904
|
return {
|
|
65725
65905
|
submission: { ...submission, files: composed.files, base: composed.base },
|
|
65726
65906
|
files: submission.files,
|
|
65727
65907
|
record,
|
|
65728
65908
|
target,
|
|
65729
|
-
deletedInTarget: composed.deletedInTarget
|
|
65909
|
+
deletedInTarget: composed.deletedInTarget,
|
|
65910
|
+
targetOnly: composed.targetOnly
|
|
65730
65911
|
};
|
|
65731
65912
|
}
|
|
65732
65913
|
async function savePromotion(dir, target, promotion, data) {
|
|
@@ -65741,7 +65922,8 @@ async function savePromotion(dir, target, promotion, data) {
|
|
|
65741
65922
|
files: promotion.files,
|
|
65742
65923
|
submission: {
|
|
65743
65924
|
files: promotion.submission.files,
|
|
65744
|
-
base: parseWorkspaceBase(promotion.submission.base).base ?? base
|
|
65925
|
+
base: parseWorkspaceBase(promotion.submission.base).base ?? base,
|
|
65926
|
+
targetOnly: promotion.targetOnly
|
|
65745
65927
|
},
|
|
65746
65928
|
applied: { base, files: data.files, plan: data.plan }
|
|
65747
65929
|
});
|
|
@@ -65751,23 +65933,33 @@ async function savePromotion(dir, target, promotion, data) {
|
|
|
65751
65933
|
function resourceWhere(kind, key) {
|
|
65752
65934
|
return isFileKind(kind) ? `${KIND_DIRS[kind]} ${key}` : `${KIND_DIRS[kind]}/${key}`;
|
|
65753
65935
|
}
|
|
65754
|
-
function promotionHint(code, target) {
|
|
65936
|
+
function promotionHint(code, target, targetOnly) {
|
|
65755
65937
|
const record = promotionRecordPath(target) ?? ".sim/targets/<workspaceId>.json";
|
|
65756
65938
|
if (code === "E_APPLY_STALE") {
|
|
65757
|
-
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
|
|
65939
|
+
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.`;
|
|
65940
|
+
}
|
|
65941
|
+
if (code === "W_SERVER_CHANGED") {
|
|
65942
|
+
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.`;
|
|
65943
|
+
}
|
|
65944
|
+
if (code === "E_APPLY_DELETE_NOT_ALLOWED") {
|
|
65945
|
+
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.`;
|
|
65946
|
+
}
|
|
65947
|
+
if (code === "W_UNDECLARED" && targetOnly) {
|
|
65948
|
+
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.`;
|
|
65758
65949
|
}
|
|
65759
65950
|
if (code === "E_APPLY_NO_BASE") {
|
|
65760
65951
|
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.`;
|
|
65761
65952
|
}
|
|
65762
65953
|
return;
|
|
65763
65954
|
}
|
|
65764
|
-
function withPromotionHint(finding, code,
|
|
65765
|
-
const
|
|
65955
|
+
function withPromotionHint(finding, code, promotion) {
|
|
65956
|
+
const targetOnly = promotion.targetOnly.includes(`${finding.kind}:${finding.key}`);
|
|
65957
|
+
const hint = promotionHint(code, promotion.target, targetOnly);
|
|
65766
65958
|
return hint === undefined ? finding : { ...finding, hint };
|
|
65767
65959
|
}
|
|
65768
65960
|
function promotionDiagnostics(diagnostics, promotion) {
|
|
65769
65961
|
const warned = new Set(promotion.deletedInTarget);
|
|
65770
|
-
return diagnostics.flatMap((finding) => finding.code === "W_SERVER_DELETED" && warned.has(`${finding.kind}:${finding.key}`) ? [] : [withPromotionHint(finding, finding.code, promotion
|
|
65962
|
+
return diagnostics.flatMap((finding) => finding.code === "W_SERVER_DELETED" && warned.has(`${finding.kind}:${finding.key}`) ? [] : [withPromotionHint(finding, finding.code, promotion)]);
|
|
65771
65963
|
}
|
|
65772
65964
|
function promotionWarnings(promotion, outcome) {
|
|
65773
65965
|
const { target } = promotion;
|
|
@@ -65786,11 +65978,12 @@ function promotionWarnings(promotion, outcome) {
|
|
|
65786
65978
|
}
|
|
65787
65979
|
];
|
|
65788
65980
|
});
|
|
65789
|
-
const
|
|
65981
|
+
const onlyInTarget = new Set(promotion.targetOnly);
|
|
65982
|
+
const targetOnly = outcome.plan.filter((change) => change.action === "delete" && onlyInTarget.has(`${change.kind}:${change.key}`) && (!outcome.failed || wasWritten(change, outcome))).map((change) => ({
|
|
65790
65983
|
code: "W_PROMOTE_DELETES_TARGET_ONLY",
|
|
65791
65984
|
severity: "warning",
|
|
65792
|
-
message: `${resourceWhere(change.kind, change.key)} is only in workspace ${target}, not in this directory, so --
|
|
65793
|
-
hint: "Promote without --
|
|
65985
|
+
message: `${resourceWhere(change.kind, change.key)} is only in workspace ${target}, not in this directory, so --delete-target-only deletes it there.`,
|
|
65986
|
+
hint: "Promote without --delete-target-only to keep it, or declare it in this directory.",
|
|
65794
65987
|
kind: change.kind,
|
|
65795
65988
|
key: change.key
|
|
65796
65989
|
}));
|
|
@@ -65804,7 +65997,7 @@ function rehinted(refusal, promotion) {
|
|
|
65804
65997
|
return refusal;
|
|
65805
65998
|
const details = {
|
|
65806
65999
|
...refusal.details,
|
|
65807
|
-
diagnostics: diagnostics.map((finding) => isRecordLike(finding) && typeof finding.code === "string" ? withPromotionHint(finding, finding.code, promotion
|
|
66000
|
+
diagnostics: diagnostics.map((finding) => isRecordLike(finding) && typeof finding.code === "string" ? withPromotionHint(finding, finding.code, promotion) : finding)
|
|
65808
66001
|
};
|
|
65809
66002
|
const copy = new SimApiError(refusal.message, refusal.status, refusal.code, details, refusal.exitCode, refusal.requestId);
|
|
65810
66003
|
copy.retryAfterMs = refusal.retryAfterMs;
|
|
@@ -65825,7 +66018,8 @@ function attachWorkspaceSourceApply(source) {
|
|
|
65825
66018
|
"copy every workflow from a dev workspace into a prod workspace (--to)",
|
|
65826
66019
|
"save bulk edits to every workflow"
|
|
65827
66020
|
]);
|
|
65828
|
-
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) => {
|
|
66021
|
+
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) => {
|
|
66022
|
+
assertTargetOnlyDeletable(options);
|
|
65829
66023
|
const mode = writeMode(options);
|
|
65830
66024
|
const only = parseKinds(options.only);
|
|
65831
66025
|
const { client, profile } = connect();
|
|
@@ -65892,7 +66086,7 @@ function attachWorkspaceSourceApply(source) {
|
|
|
65892
66086
|
await assertWorkspaceDir(options.dir);
|
|
65893
66087
|
}
|
|
65894
66088
|
assertBlobsFetched(options.dir, read, written.digests);
|
|
65895
|
-
promotion = options.to ? await promoted(client, options.dir, read, options.to, options.
|
|
66089
|
+
promotion = options.to ? await promoted(client, options.dir, read, options.to, options.deleteTargetOnly === true) : null;
|
|
65896
66090
|
const submission = promotion?.submission ?? read;
|
|
65897
66091
|
const reported = (data) => promotion ? {
|
|
65898
66092
|
...data,
|
|
@@ -65970,9 +66164,20 @@ function applyCommand(options) {
|
|
|
65970
66164
|
`sim workspaces source apply --dir ${shellWord(options.dir)}`,
|
|
65971
66165
|
...options.only ? [`--only ${shellWord(options.only)}`] : [],
|
|
65972
66166
|
...options.to ? [`--to ${shellWord(options.to)}`] : [],
|
|
65973
|
-
...options.allowDelete ? ["--allow-delete"] : []
|
|
66167
|
+
...options.allowDelete ? ["--allow-delete"] : [],
|
|
66168
|
+
...options.deleteTargetOnly ? ["--delete-target-only"] : []
|
|
65974
66169
|
].join(" ");
|
|
65975
66170
|
}
|
|
66171
|
+
function assertTargetOnlyDeletable(options) {
|
|
66172
|
+
if (!options.deleteTargetOnly)
|
|
66173
|
+
return;
|
|
66174
|
+
if (!options.to) {
|
|
66175
|
+
throw new CliUsageError("--delete-target-only deletes a promotion target's own resources: it needs --to <workspaceId>.");
|
|
66176
|
+
}
|
|
66177
|
+
if (!options.allowDelete) {
|
|
66178
|
+
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.");
|
|
66179
|
+
}
|
|
66180
|
+
}
|
|
65976
66181
|
function notSentFindings(paths) {
|
|
65977
66182
|
return paths.map((path) => ({
|
|
65978
66183
|
code: "W_PATH_NOT_SENT",
|
|
@@ -66066,6 +66271,7 @@ ${SOURCE_DIR_BUSY_HELP}`).action(async (options, command) => {
|
|
|
66066
66271
|
};
|
|
66067
66272
|
const keys = await workspaceWorkflowKeys(options.dir);
|
|
66068
66273
|
const findings = [];
|
|
66274
|
+
const unlisted = { errors: 0, warnings: 0 };
|
|
66069
66275
|
for (const key of keys) {
|
|
66070
66276
|
const checked = await checkWorkflowDir(join12(options.dir, KIND_DIRS.workflow, key), catalog, {
|
|
66071
66277
|
declarations,
|
|
@@ -66073,6 +66279,8 @@ ${SOURCE_DIR_BUSY_HELP}`).action(async (options, command) => {
|
|
|
66073
66279
|
prefix: `${KIND_DIRS.workflow}/${key}/`
|
|
66074
66280
|
});
|
|
66075
66281
|
findings.push(...checked.findings);
|
|
66282
|
+
unlisted.errors += checked.unlisted.errors;
|
|
66283
|
+
unlisted.warnings += checked.unlisted.warnings;
|
|
66076
66284
|
}
|
|
66077
66285
|
for (const {
|
|
66078
66286
|
code,
|
|
@@ -66095,7 +66303,7 @@ ${SOURCE_DIR_BUSY_HELP}`).action(async (options, command) => {
|
|
|
66095
66303
|
}
|
|
66096
66304
|
await refreshWorkspaceTypes(options.dir, withWorkflowInputs(declarations.local, workflowInputs));
|
|
66097
66305
|
await refreshWorkspaceTsconfigs(options.dir, workspaceId);
|
|
66098
|
-
reportCheck(profile.output, findings, { workflows: keys.length, catalogHash: catalog.hash }, { verbose: options.verbose === true, bound: WORKSPACE_ANSWER_BOUND });
|
|
66306
|
+
reportCheck(profile.output, findings, { workflows: keys.length, catalogHash: catalog.hash }, { verbose: options.verbose === true, bound: WORKSPACE_ANSWER_BOUND, unlisted });
|
|
66099
66307
|
});
|
|
66100
66308
|
});
|
|
66101
66309
|
}
|
|
@@ -66271,6 +66479,9 @@ function attachWorkspaceSourceGet(source) {
|
|
|
66271
66479
|
const result = await writeWorkspaceSource(client, options.dir, data, options.force === true);
|
|
66272
66480
|
const findings = findingsOutput(profile.output);
|
|
66273
66481
|
findings.print(data.diagnostics);
|
|
66482
|
+
for (const { kind, key, reason } of data.skipped) {
|
|
66483
|
+
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).`);
|
|
66484
|
+
}
|
|
66274
66485
|
printTreeResult(profile.output, {
|
|
66275
66486
|
workspaceId: data.workspaceId,
|
|
66276
66487
|
dir: options.dir,
|
|
@@ -66304,9 +66515,10 @@ async function readLocalWorkspace(dir, only) {
|
|
|
66304
66515
|
current[path] = digest(text);
|
|
66305
66516
|
for (const blob of submission.blobs)
|
|
66306
66517
|
current[blob.path] = blob.sha256;
|
|
66518
|
+
const unnamed = new Set(submission.unnamed);
|
|
66307
66519
|
const changed = changedFiles(current, written.digests, (path) => {
|
|
66308
66520
|
const kind = kindOfPath(path);
|
|
66309
|
-
return kind !== null && (!only || only.includes(kind));
|
|
66521
|
+
return kind !== null && (!only || only.includes(kind)) && !unnamed.has(path);
|
|
66310
66522
|
});
|
|
66311
66523
|
return { submission, written, changed, readFrom };
|
|
66312
66524
|
}
|
|
@@ -66459,6 +66671,7 @@ ${SOURCE_DIR_BUSY_HELP}`).action(async (options, invoked) => {
|
|
|
66459
66671
|
server,
|
|
66460
66672
|
...note ? { note } : {},
|
|
66461
66673
|
...status,
|
|
66674
|
+
...local.submission.unnamed.length > 0 ? { unnamed: local.submission.unnamed } : {},
|
|
66462
66675
|
plan,
|
|
66463
66676
|
next: (login ? null : unmanagedNext(status, local.submission.kinds, options.dir, workspaceScope)) ?? nextStep(status, {
|
|
66464
66677
|
prefix: PREFIX2,
|