sim 2.2.33-preview.319.1 → 2.2.33-preview.320.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 +299 -69
- package/dist/runtime.js +299 -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 { readFileSync as readFileSync4 } 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);
|
|
@@ -52902,14 +52948,32 @@ async function withSourceDirLock(dir, run, options = {}) {
|
|
|
52902
52948
|
throw new SourceDirError(`Another sim command is using ${dir}; nothing was read or written. Run this one again once it finished. If none is running, remove ${join6(dir, SOURCE_DIR_LOCK)}.`, { code: "SOURCE_DIR_BUSY", exitCode: SOURCE_BUSY_EXIT_CODE });
|
|
52903
52949
|
}
|
|
52904
52950
|
const owner = { pid: process.pid, host: hostname() };
|
|
52905
|
-
|
|
52951
|
+
let ownerRecorded = false;
|
|
52952
|
+
const ownedLock = () => {
|
|
52953
|
+
if (!ownerRecorded)
|
|
52954
|
+
return lock;
|
|
52955
|
+
try {
|
|
52956
|
+
const recorded = toRecord(JSON.parse(readFileSync4(join6(lock, LOCK_OWNER_FILE), "utf8")));
|
|
52957
|
+
return recorded.pid === owner.pid && recorded.host === owner.host ? lock : null;
|
|
52958
|
+
} catch {
|
|
52959
|
+
return null;
|
|
52960
|
+
}
|
|
52961
|
+
};
|
|
52962
|
+
const disposeSignalRelease = removeStagingOnSignal(ownedLock);
|
|
52906
52963
|
try {
|
|
52907
52964
|
await writeFile2(join6(lock, LOCK_OWNER_FILE), JSON.stringify(owner));
|
|
52965
|
+
ownerRecorded = true;
|
|
52908
52966
|
return await run();
|
|
52909
52967
|
} finally {
|
|
52910
|
-
|
|
52911
|
-
|
|
52912
|
-
|
|
52968
|
+
try {
|
|
52969
|
+
await rm3(await checkedPath(root, SOURCE_DIR_LOCK, new Set), {
|
|
52970
|
+
recursive: true,
|
|
52971
|
+
force: true
|
|
52972
|
+
});
|
|
52973
|
+
await removeCreatedFolders();
|
|
52974
|
+
} finally {
|
|
52975
|
+
disposeSignalRelease();
|
|
52976
|
+
}
|
|
52913
52977
|
}
|
|
52914
52978
|
}
|
|
52915
52979
|
async function removeEmptyFolders(dir, outermost) {
|
|
@@ -53049,10 +53113,11 @@ async function editedFiles(dir, touched, written) {
|
|
|
53049
53113
|
}
|
|
53050
53114
|
async function locallyEditedFiles(dir, answer, previousLock) {
|
|
53051
53115
|
const touched = new Map(Object.entries(answer.files));
|
|
53052
|
-
|
|
53116
|
+
const { digests } = await readFolderWritten(dir);
|
|
53117
|
+
for (const path of orphanedCodeFiles(previousLock, answer.lock, touched.keys(), digests)) {
|
|
53053
53118
|
touched.set(path, null);
|
|
53054
53119
|
}
|
|
53055
|
-
return editedFiles(dir, touched,
|
|
53120
|
+
return editedFiles(dir, touched, digests);
|
|
53056
53121
|
}
|
|
53057
53122
|
function inWorkspace(key, path) {
|
|
53058
53123
|
return `${KIND_DIRS.workflow}/${key}/${path}`;
|
|
@@ -53117,7 +53182,7 @@ async function writeBack(dir, answer, previousLock, extra = { write: [] }) {
|
|
|
53117
53182
|
`]
|
|
53118
53183
|
];
|
|
53119
53184
|
const write = [...printed, ...folder ? [] : writtenFiles(writtenRecord(files)), ...extra.write];
|
|
53120
|
-
const orphaned = orphanedCodeFiles(previousLock, answer.lock, Object.keys(answer.files));
|
|
53185
|
+
const orphaned = orphanedCodeFiles(previousLock, answer.lock, Object.keys(answer.files), (await readFolderWritten(dir)).digests);
|
|
53121
53186
|
const unnamed = await unnamedCodeFiles(dir, previousLock, answer, orphaned);
|
|
53122
53187
|
await updateSourceDir(dir, {
|
|
53123
53188
|
write,
|
|
@@ -53168,7 +53233,7 @@ function sourceExitCodeRows(prefix) {
|
|
|
53168
53233
|
},
|
|
53169
53234
|
{
|
|
53170
53235
|
code: 1,
|
|
53171
|
-
meaning: "The source has errors (each printed as `file:line:column` with a hint), a locked block (`E_APPLY_LOCKED_BLOCK`), a name another workflow holds (`SOURCE_NAME_TAKEN`), a cancelled prompt, or the command failed",
|
|
53236
|
+
meaning: prefix === "sim workspaces source" ? "The source has errors (each printed as `file:line:column` with a hint), a locked block (`E_APPLY_LOCKED_BLOCK`), a name another resource holds (`E_NAME_TAKEN`), a cancelled prompt, or the command failed" : "The source has errors (each printed as `file:line:column` with a hint), a locked block (`E_APPLY_LOCKED_BLOCK`), a name another workflow holds (`SOURCE_NAME_TAKEN`), a cancelled prompt, or the command failed",
|
|
53172
53237
|
next: "Fix what it printed and run it again",
|
|
53173
53238
|
help: {
|
|
53174
53239
|
"workflows source apply": "the source has errors (each printed as file:line:column with its frame and hint) or the command failed",
|
|
@@ -56456,8 +56521,14 @@ function isMachine(format) {
|
|
|
56456
56521
|
function resultDiagnostics(format, diagnostics, verbose = false) {
|
|
56457
56522
|
if (!isMachine(format))
|
|
56458
56523
|
return {};
|
|
56524
|
+
const hidden = (finding) => !verbose && finding.severity === "info" && finding.code !== "I_FINDINGS_TRUNCATED";
|
|
56525
|
+
const hiddenCount = diagnostics.filter(hidden).length;
|
|
56526
|
+
const marked = (finding) => finding.code === "I_FINDINGS_TRUNCATED" && hiddenCount > 0 ? {
|
|
56527
|
+
...finding,
|
|
56528
|
+
message: `${finding.message} ${hiddenCount} info finding${hiddenCount === 1 ? "" : "s"} listed ${hiddenCount === 1 ? "is" : "are"} hidden too; pass --verbose to see ${hiddenCount === 1 ? "it" : "them"}.`
|
|
56529
|
+
} : finding;
|
|
56459
56530
|
return {
|
|
56460
|
-
diagnostics: diagnostics.filter((finding) =>
|
|
56531
|
+
diagnostics: diagnostics.filter((finding) => !hidden(finding)).map(({ frame: _frame, ...finding }) => marked(finding))
|
|
56461
56532
|
};
|
|
56462
56533
|
}
|
|
56463
56534
|
function findingKey(diagnostic) {
|
|
@@ -56750,7 +56821,7 @@ async function readJson(directory, path, hint) {
|
|
|
56750
56821
|
}
|
|
56751
56822
|
function codeFilePaths(entry, lock) {
|
|
56752
56823
|
const candidates = lockCodeFiles(lock);
|
|
56753
|
-
for (const literal of codeFileReferences(entry)) {
|
|
56824
|
+
for (const literal of entry === null ? [] : codeFileReferences(entry)) {
|
|
56754
56825
|
const path = sourceRelativePath(literal);
|
|
56755
56826
|
if (path)
|
|
56756
56827
|
candidates.add(path);
|
|
@@ -56818,7 +56889,7 @@ The primer above is enough to edit; read a section here when a step needs it.
|
|
|
56818
56889
|
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
56890
|
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
56891
|
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).
|
|
56892
|
+
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
56893
|
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
56894
|
|
|
56824
56895
|
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 +57116,7 @@ async function writeWorkflowSource(args) {
|
|
|
57045
57116
|
report(data, deployment);
|
|
57046
57117
|
}
|
|
57047
57118
|
async function deployStep(client, data, options) {
|
|
57048
|
-
const deployCommand = `sim workflows deploy ${data.workflowId}`;
|
|
57119
|
+
const deployCommand = `sim workflows deploy ${data.workflowId} --expected-draft-fingerprint ${data.base.fingerprint}`;
|
|
57049
57120
|
if (!options.deploy) {
|
|
57050
57121
|
if (!data.needsRedeployment)
|
|
57051
57122
|
return {};
|
|
@@ -57056,6 +57127,24 @@ async function deployStep(client, data, options) {
|
|
|
57056
57127
|
}
|
|
57057
57128
|
};
|
|
57058
57129
|
}
|
|
57130
|
+
if (!data.applied && !data.needsRedeployment) {
|
|
57131
|
+
const status = await client.request("getWorkflowDeployment", {
|
|
57132
|
+
params: { workflowId: data.workflowId }
|
|
57133
|
+
}).then((response) => response.data, (error) => {
|
|
57134
|
+
throw deployFailure(error, options, deployCommand);
|
|
57135
|
+
});
|
|
57136
|
+
if (status.isDeployed && !status.needsRedeployment) {
|
|
57137
|
+
if (!options.machine)
|
|
57138
|
+
printError("The live version already matches the draft; nothing was deployed.");
|
|
57139
|
+
return {
|
|
57140
|
+
deployed: {
|
|
57141
|
+
...status.activeDeployment ? { version: status.activeDeployment.version } : {},
|
|
57142
|
+
isDeployed: true
|
|
57143
|
+
},
|
|
57144
|
+
needsRedeployment: false
|
|
57145
|
+
};
|
|
57146
|
+
}
|
|
57147
|
+
}
|
|
57059
57148
|
const deployed = await client.request("deployWorkflow", {
|
|
57060
57149
|
params: { workflowId: data.workflowId },
|
|
57061
57150
|
body: { expectedDraftFingerprint: data.base.fingerprint }
|
|
@@ -57090,6 +57179,7 @@ function attachWorkflowSourceApply(source) {
|
|
|
57090
57179
|
const [command, connectApply] = apiCommand(source, "apply", [
|
|
57091
57180
|
"applyWorkflowSource",
|
|
57092
57181
|
"deployWorkflow",
|
|
57182
|
+
"getWorkflowDeployment",
|
|
57093
57183
|
"getSourceResources"
|
|
57094
57184
|
]);
|
|
57095
57185
|
absoluteDirOption(command);
|
|
@@ -57138,7 +57228,8 @@ function attachWorkflowSourceCreate(source) {
|
|
|
57138
57228
|
"createWorkflowFromSource",
|
|
57139
57229
|
"getSourceCatalog",
|
|
57140
57230
|
"getSourceResources",
|
|
57141
|
-
"deployWorkflow"
|
|
57231
|
+
"deployWorkflow",
|
|
57232
|
+
"getWorkflowDeployment"
|
|
57142
57233
|
]);
|
|
57143
57234
|
absoluteDirOption(command);
|
|
57144
57235
|
verboseFlag(command);
|
|
@@ -63443,7 +63534,7 @@ var ADVANCED_GUIDE = `# Sim workspace source: advanced
|
|
|
63443
63534
|
|
|
63444
63535
|
## Promote to another workspace
|
|
63445
63536
|
|
|
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
|
|
63537
|
+
\`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
63538
|
`;
|
|
63448
63539
|
var WORKSPACE_TREE = {
|
|
63449
63540
|
kind: "workspace",
|
|
@@ -63652,6 +63743,32 @@ async function assertWorkspaceDir(dir) {
|
|
|
63652
63743
|
function keepFile(kind) {
|
|
63653
63744
|
return isFileKind(kind) ? null : `${KIND_DIRS[kind]}/${KEEP_FILE}`;
|
|
63654
63745
|
}
|
|
63746
|
+
function dropUnnamedCodeFiles(files) {
|
|
63747
|
+
const named = new Map;
|
|
63748
|
+
const unnamed = [];
|
|
63749
|
+
for (const path of Object.keys(files)) {
|
|
63750
|
+
if (kindOfPath(path) !== "workflow")
|
|
63751
|
+
continue;
|
|
63752
|
+
const segments = path.split("/");
|
|
63753
|
+
if (segments[2] !== SOURCE_CODE_DIR)
|
|
63754
|
+
continue;
|
|
63755
|
+
const folder = segments.slice(0, 2).join("/");
|
|
63756
|
+
let sent = named.get(folder);
|
|
63757
|
+
if (!sent) {
|
|
63758
|
+
let lock = null;
|
|
63759
|
+
try {
|
|
63760
|
+
lock = JSON.parse(files[`${folder}/${SOURCE_LOCK_FILE}`] ?? "null");
|
|
63761
|
+
} catch {}
|
|
63762
|
+
sent = new Set(codeFilePaths(files[`${folder}/${SOURCE_ENTRY_FILE}`] ?? null, lock));
|
|
63763
|
+
named.set(folder, sent);
|
|
63764
|
+
}
|
|
63765
|
+
if (!sent.has(segments.slice(2).join("/"))) {
|
|
63766
|
+
unnamed.push(path);
|
|
63767
|
+
delete files[path];
|
|
63768
|
+
}
|
|
63769
|
+
}
|
|
63770
|
+
return unnamed.sort(compareStrings);
|
|
63771
|
+
}
|
|
63655
63772
|
function pruneUnchangedWorkflows(files, written, workspaceId) {
|
|
63656
63773
|
const workflowPaths = Object.keys(files).filter((path) => kindOfPath(path) === "workflow");
|
|
63657
63774
|
const folders = KIND_LAYOUTS.workflow.group(workflowPaths).groups;
|
|
@@ -63696,6 +63813,7 @@ async function readWorkspaceDir(dir, only, workspaceId, written, options = {}) {
|
|
|
63696
63813
|
if (text !== null)
|
|
63697
63814
|
files[path] = text;
|
|
63698
63815
|
});
|
|
63816
|
+
const unnamed = dropUnnamedCodeFiles(files);
|
|
63699
63817
|
if (!options.whole)
|
|
63700
63818
|
pruneUnchangedWorkflows(files, written, workspaceId);
|
|
63701
63819
|
const root = await realpath4(dir);
|
|
@@ -63724,7 +63842,7 @@ async function readWorkspaceDir(dir, only, workspaceId, written, options = {}) {
|
|
|
63724
63842
|
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
63843
|
}
|
|
63726
63844
|
}
|
|
63727
|
-
return { kinds, files, blobs, ignored, hashed, ...base ? { base } : {} };
|
|
63845
|
+
return { kinds, files, blobs, ignored, unnamed, hashed, ...base ? { base } : {} };
|
|
63728
63846
|
}
|
|
63729
63847
|
function skippedFile(skipped) {
|
|
63730
63848
|
return skipped.length > 0 ? `${JSON.stringify(skipped, null, 2)}
|
|
@@ -63970,7 +64088,7 @@ async function compileWorkflowDir(dir, workspaceCatalog, declarations) {
|
|
|
63970
64088
|
...storedEdges ? { storedUnreadEdges: storedEdges } : {},
|
|
63971
64089
|
...envNames ? { envNames, envDeclaredIn: KIND_DIRS.secret } : {}
|
|
63972
64090
|
});
|
|
63973
|
-
return { lock, files, compiled, storedBlocks, printedWith };
|
|
64091
|
+
return { lock, files, compiled, storedBlocks, printedWith, catalog };
|
|
63974
64092
|
}
|
|
63975
64093
|
async function workspaceWorkflowInputs(root, catalog) {
|
|
63976
64094
|
const inputs = new Map;
|
|
@@ -63991,7 +64109,8 @@ function withWorkflowInputs(local, inputs) {
|
|
|
63991
64109
|
return { ...local, workflows };
|
|
63992
64110
|
}
|
|
63993
64111
|
async function checkWorkflowDir(dir, catalog, options) {
|
|
63994
|
-
const
|
|
64112
|
+
const compiledDir = await compileWorkflowDir(dir, catalog, options.declarations);
|
|
64113
|
+
const { lock, files, compiled, storedBlocks, printedWith } = compiledDir;
|
|
63995
64114
|
const entryText = files[SOURCE_ENTRY_FILE];
|
|
63996
64115
|
const locate = (block, param, names) => {
|
|
63997
64116
|
const prefix = encodeAnchor({ kind: "param", block, param: "" });
|
|
@@ -64053,19 +64172,33 @@ async function checkWorkflowDir(dir, catalog, options) {
|
|
|
64053
64172
|
const head = /^(?:\$ref\.|<)([A-Za-z0-9_]+)/.exec(text)?.[1];
|
|
64054
64173
|
return head !== undefined && removedKeys.has(head);
|
|
64055
64174
|
};
|
|
64056
|
-
const
|
|
64175
|
+
const variesByDeployment = (finding) => {
|
|
64176
|
+
const { blockKey, param } = finding;
|
|
64177
|
+
if (finding.code !== "W_UNKNOWN_OPTION" || blockKey === undefined || param === undefined) {
|
|
64178
|
+
return false;
|
|
64179
|
+
}
|
|
64180
|
+
return optionsVaryOn(blockKey, (id) => id === param);
|
|
64181
|
+
};
|
|
64182
|
+
const optionsVaryOn = (blockKey, matches) => {
|
|
64183
|
+
const type = compiled.workflow ? getOwn(compiled.workflow.blocks, blockKey)?.type : undefined;
|
|
64184
|
+
const block = type === undefined ? undefined : catalogBlock(compiledDir.catalog, type);
|
|
64185
|
+
return block?.subBlocks.some((sub) => matches(sub.id) && sub.optionsVary === true) === true;
|
|
64186
|
+
};
|
|
64187
|
+
const exempt = (finding) => mayBeRenamed(finding) || variesByDeployment(finding);
|
|
64188
|
+
const refusable = (finding) => !exempt(finding);
|
|
64057
64189
|
const refused = [
|
|
64058
64190
|
...refuseEditedFindings({
|
|
64059
64191
|
diagnostics: compiled.diagnostics.filter(refusable),
|
|
64060
64192
|
withheld: compiled.withheld.filter(refusable)
|
|
64061
64193
|
}, { changed, codeEdited }),
|
|
64062
|
-
...compiled.diagnostics.filter(
|
|
64194
|
+
...compiled.diagnostics.filter(exempt)
|
|
64063
64195
|
];
|
|
64064
64196
|
const findings = [
|
|
64065
64197
|
...refused.filter((diagnostic) => reported(diagnostic.code, diagnostic.blockKey)),
|
|
64066
64198
|
...declared
|
|
64067
|
-
].map((
|
|
64068
|
-
const
|
|
64199
|
+
].map((finding) => {
|
|
64200
|
+
const { code, severity, message, hint, frame, span, blockKey } = finding;
|
|
64201
|
+
const raised = severity === "warning" && !variesByDeployment(finding) && fails(code, blockKey);
|
|
64069
64202
|
return {
|
|
64070
64203
|
code,
|
|
64071
64204
|
severity: raised ? "error" : severity,
|
|
@@ -64075,19 +64208,52 @@ async function checkWorkflowDir(dir, catalog, options) {
|
|
|
64075
64208
|
...span ? { file: `${prefix}${span.file}`, line: span.line, column: span.column } : {}
|
|
64076
64209
|
};
|
|
64077
64210
|
});
|
|
64078
|
-
|
|
64211
|
+
const unlisted = { errors: 0, warnings: 0 };
|
|
64212
|
+
const edit = { changed, codeEdited };
|
|
64213
|
+
for (const { code, blockKey, count, varies, refused: isRefused } of [
|
|
64214
|
+
...compiled.omitted.map((omitted) => {
|
|
64215
|
+
const finding = {
|
|
64216
|
+
code: omitted.code,
|
|
64217
|
+
severity: "warning",
|
|
64218
|
+
...omitted.blockKey !== undefined ? { blockKey: omitted.blockKey } : {},
|
|
64219
|
+
...omitted.param !== undefined ? { param: omitted.param } : {}
|
|
64220
|
+
};
|
|
64221
|
+
const varies = variesByDeployment(finding);
|
|
64222
|
+
return {
|
|
64223
|
+
...omitted,
|
|
64224
|
+
varies,
|
|
64225
|
+
refused: !varies && omitted.file !== undefined && refusesEdited({ ...finding, span: { file: omitted.file } }, edit)
|
|
64226
|
+
};
|
|
64227
|
+
}),
|
|
64228
|
+
...compiled.withheld.filter((finding) => !refusable(finding) || !refusesEdited(finding, edit)).map((finding) => ({
|
|
64229
|
+
code: finding.code,
|
|
64230
|
+
blockKey: finding.blockKey,
|
|
64231
|
+
count: 1,
|
|
64232
|
+
varies: variesByDeployment(finding),
|
|
64233
|
+
refused: false
|
|
64234
|
+
}))
|
|
64235
|
+
]) {
|
|
64236
|
+
if (!reported(code, blockKey))
|
|
64237
|
+
continue;
|
|
64238
|
+
if (isRefused || !varies && fails(code, blockKey))
|
|
64239
|
+
unlisted.errors += count;
|
|
64240
|
+
else
|
|
64241
|
+
unlisted.warnings += count;
|
|
64242
|
+
}
|
|
64243
|
+
return { findings, entry: entryText, unlisted };
|
|
64079
64244
|
}
|
|
64080
64245
|
function reportCheck(output, findings, result, options = {}) {
|
|
64081
64246
|
const shown = findingsOutput(output, options.verbose);
|
|
64082
64247
|
const listed = boundAnswerFindings(findings, options.bound);
|
|
64083
64248
|
shown.print(listed);
|
|
64084
|
-
const
|
|
64249
|
+
const unlisted = options.unlisted ?? { errors: 0, warnings: 0 };
|
|
64250
|
+
const errors = findings.filter((finding) => finding.severity === "error").length + unlisted.errors;
|
|
64085
64251
|
if (errors > 0)
|
|
64086
64252
|
setSoftExitCode(1);
|
|
64087
64253
|
printProtocolResult(output, {
|
|
64088
64254
|
checked: "compile",
|
|
64089
64255
|
errors,
|
|
64090
|
-
warnings: findings.filter((finding) => finding.severity === "warning").length,
|
|
64256
|
+
warnings: findings.filter((finding) => finding.severity === "warning").length + unlisted.warnings,
|
|
64091
64257
|
...result,
|
|
64092
64258
|
...shown.result(listed)
|
|
64093
64259
|
});
|
|
@@ -64131,7 +64297,7 @@ function attachWorkflowSourceCheck(source) {
|
|
|
64131
64297
|
...await readWorkspaceDeclarations(workspace.root),
|
|
64132
64298
|
workflowInputs: await workspaceWorkflowInputs(workspace.root, catalog)
|
|
64133
64299
|
} : undefined;
|
|
64134
|
-
const { findings, entry } = await checkWorkflowDir(options.dir, catalog, {
|
|
64300
|
+
const { findings, entry, unlisted } = await checkWorkflowDir(options.dir, catalog, {
|
|
64135
64301
|
strict: strictMode(options),
|
|
64136
64302
|
...declarations ? { declarations } : {}
|
|
64137
64303
|
});
|
|
@@ -64142,7 +64308,8 @@ function attachWorkflowSourceCheck(source) {
|
|
|
64142
64308
|
await refreshTsconfigs(options.dir, workspaceId, WORKFLOW_TREE, { sources: [entry] }, { incremental: true });
|
|
64143
64309
|
}
|
|
64144
64310
|
reportCheck(profile.output, findings, { catalogHash: catalog.hash }, {
|
|
64145
|
-
verbose: options.verbose === true
|
|
64311
|
+
verbose: options.verbose === true,
|
|
64312
|
+
unlisted
|
|
64146
64313
|
});
|
|
64147
64314
|
});
|
|
64148
64315
|
}
|
|
@@ -64981,6 +65148,9 @@ function printStatusReport(format, heading, report, planLine, findings) {
|
|
|
64981
65148
|
} else {
|
|
64982
65149
|
lines.push(s.yellow(`Server not checked${report.note ? `: ${sanitize(report.note)}` : "."}`));
|
|
64983
65150
|
}
|
|
65151
|
+
if (report.unnamed?.length) {
|
|
65152
|
+
lines.push(s.dim(`Not named by any codeFile(), so applying never sends ${report.unnamed.length === 1 ? "it" : "them"}: ${sanitize(report.unnamed.join(", "))}`));
|
|
65153
|
+
}
|
|
64984
65154
|
if (report.server === "checked" && report.note)
|
|
64985
65155
|
lines.push(s.dim(sanitize(report.note)));
|
|
64986
65156
|
if (report.plan)
|
|
@@ -65148,23 +65318,25 @@ async function readLocalWorkflow(dir) {
|
|
|
65148
65318
|
const base = await readBase(dir, undefined);
|
|
65149
65319
|
const { workflowId } = base;
|
|
65150
65320
|
const written = await readFolderWritten(dir);
|
|
65151
|
-
const
|
|
65152
|
-
|
|
65153
|
-
|
|
65154
|
-
];
|
|
65155
|
-
const
|
|
65156
|
-
for (const path of paths) {
|
|
65321
|
+
const entry = await readSourceText(dir, SOURCE_ENTRY_FILE);
|
|
65322
|
+
const sent = new Set(codeFilePaths(entry, await readPreviousLock(dir)));
|
|
65323
|
+
const listed = (await listSourceFiles(dir, SOURCE_CODE_DIR)).filter((path) => !path.split("/").some((segment) => segment.startsWith(".")));
|
|
65324
|
+
const texts = entry === null ? {} : { [SOURCE_ENTRY_FILE]: entry };
|
|
65325
|
+
for (const path of listed.filter((each) => sent.has(each))) {
|
|
65157
65326
|
const text = await readSourceText(dir, path);
|
|
65158
65327
|
if (text !== null)
|
|
65159
65328
|
texts[path] = text;
|
|
65160
65329
|
}
|
|
65161
65330
|
const current = Object.fromEntries(Object.entries(texts).map(([path, text]) => [path, digest(text)]));
|
|
65331
|
+
const unnamed = listed.filter((path) => !sent.has(path));
|
|
65332
|
+
const ignored = new Set(unnamed);
|
|
65162
65333
|
return {
|
|
65163
65334
|
base,
|
|
65164
65335
|
workflowId,
|
|
65165
65336
|
written,
|
|
65166
65337
|
texts,
|
|
65167
|
-
changed: changedFiles(current, written.digests, () =>
|
|
65338
|
+
changed: changedFiles(current, written.digests, (path) => !ignored.has(path)),
|
|
65339
|
+
unnamed
|
|
65168
65340
|
};
|
|
65169
65341
|
}
|
|
65170
65342
|
function workflowPlanFindings(data) {
|
|
@@ -65247,13 +65419,14 @@ function attachWorkflowSourceStatus(source) {
|
|
|
65247
65419
|
}
|
|
65248
65420
|
}
|
|
65249
65421
|
const status = sourceStatus(locals, serverChanges);
|
|
65250
|
-
const plan = data ? planSummary(data) : null;
|
|
65422
|
+
const plan = data && serverChanges.length === 0 ? planSummary(data) : null;
|
|
65251
65423
|
const report = {
|
|
65252
65424
|
workflowId,
|
|
65253
65425
|
dir: options.dir,
|
|
65254
65426
|
server,
|
|
65255
65427
|
...note ? { note } : {},
|
|
65256
65428
|
...status,
|
|
65429
|
+
...local.unnamed.length > 0 ? { unnamed: local.unnamed } : {},
|
|
65257
65430
|
plan,
|
|
65258
65431
|
next: nextStep(status, {
|
|
65259
65432
|
prefix: PREFIX,
|
|
@@ -65456,15 +65629,22 @@ function promotionSubmission(input) {
|
|
|
65456
65629
|
if (lock !== undefined)
|
|
65457
65630
|
files[lockPath] = lock;
|
|
65458
65631
|
}
|
|
65632
|
+
const targetOnly = [];
|
|
65459
65633
|
const resources = Object.fromEntries(Object.entries(input.target.base.resources).flatMap(([address, live]) => {
|
|
65460
65634
|
const parsed = parseResourceAddress(address);
|
|
65461
65635
|
if (!parsed)
|
|
65462
65636
|
return [];
|
|
65463
65637
|
const keys = declared.get(parsed.kind);
|
|
65464
|
-
if (keys === undefined
|
|
65638
|
+
if (keys === undefined)
|
|
65465
65639
|
return [];
|
|
65466
65640
|
const recorded = input.record?.resources[resourceAddress(parsed.kind, parsed.key)];
|
|
65467
|
-
|
|
65641
|
+
const promoted = recorded?.id === live.id ? recorded : undefined;
|
|
65642
|
+
if (!keys.has(parsed.key) && !promoted) {
|
|
65643
|
+
targetOnly.push(resourceAddress(parsed.kind, parsed.key));
|
|
65644
|
+
if (!input.deleteTargetOnly)
|
|
65645
|
+
return [];
|
|
65646
|
+
}
|
|
65647
|
+
return [[address, promoted ?? live]];
|
|
65468
65648
|
}));
|
|
65469
65649
|
for (const [address, recorded] of Object.entries(input.record?.resources ?? {})) {
|
|
65470
65650
|
if (Object.hasOwn(input.target.base.resources, address))
|
|
@@ -65479,7 +65659,8 @@ function promotionSubmission(input) {
|
|
|
65479
65659
|
return {
|
|
65480
65660
|
files,
|
|
65481
65661
|
base: { ...input.target.base, resources },
|
|
65482
|
-
deletedInTarget: [...new Set(deletedInTarget)].sort(compareStrings)
|
|
65662
|
+
deletedInTarget: [...new Set(deletedInTarget)].sort(compareStrings),
|
|
65663
|
+
targetOnly: targetOnly.sort(compareStrings)
|
|
65483
65664
|
};
|
|
65484
65665
|
}
|
|
65485
65666
|
function promotionRecord(input) {
|
|
@@ -65491,7 +65672,13 @@ function promotionRecord(input) {
|
|
|
65491
65672
|
resources[resourceAddress(parsed.kind, parsed.key)] = entry;
|
|
65492
65673
|
}
|
|
65493
65674
|
}
|
|
65494
|
-
|
|
65675
|
+
const targetOnly = new Set(input.submission.targetOnly);
|
|
65676
|
+
for (const [address, entry] of Object.entries(input.applied.base.resources)) {
|
|
65677
|
+
const parsed = parseResourceAddress(address);
|
|
65678
|
+
if (parsed && !targetOnly.has(address)) {
|
|
65679
|
+
resources[resourceAddress(parsed.kind, parsed.key)] = entry;
|
|
65680
|
+
}
|
|
65681
|
+
}
|
|
65495
65682
|
const workflows = {};
|
|
65496
65683
|
if (!managed.has("workflow")) {
|
|
65497
65684
|
Object.assign(workflows, input.previous?.workflows);
|
|
@@ -65547,6 +65734,10 @@ function outcomeText(change, outcome) {
|
|
|
65547
65734
|
function printPlan(plan, diagnostics, outcome) {
|
|
65548
65735
|
const drifted = new Map(serverResourceChanges(diagnostics).filter((change) => change.server !== "added").map((change) => [`${change.kind}:${change.key}`, change.server]));
|
|
65549
65736
|
const driftOf = (change) => change.action === "noop" ? drifted.get(`${change.kind}:${change.key}`) : undefined;
|
|
65737
|
+
const addressesOf = (code) => new Set(diagnostics.filter((finding) => finding.code === code).map((finding) => `${finding.kind}:${finding.key}`));
|
|
65738
|
+
const stale = addressesOf("E_APPLY_STALE");
|
|
65739
|
+
const deleteRefused = addressesOf("E_APPLY_DELETE_NOT_ALLOWED");
|
|
65740
|
+
const refusedDelete = (change) => change.action === "noop" && deleteRefused.has(`${change.kind}:${change.key}`);
|
|
65550
65741
|
for (const kind of APPLY_ORDER) {
|
|
65551
65742
|
const changes = plan.filter((change) => change.kind === kind);
|
|
65552
65743
|
if (changes.length === 0)
|
|
@@ -65554,14 +65745,19 @@ function printPlan(plan, diagnostics, outcome) {
|
|
|
65554
65745
|
const counts = new Map;
|
|
65555
65746
|
for (const change of changes) {
|
|
65556
65747
|
const drift = driftOf(change);
|
|
65557
|
-
const label = drift ? `${drift} on the server` : change.action === "noop" ? "unchanged" : change.action;
|
|
65748
|
+
const label = drift ? `${drift} on the server` : refusedDelete(change) ? "delete refused" : change.action === "noop" ? "unchanged" : change.action;
|
|
65558
65749
|
counts.set(label, (counts.get(label) ?? 0) + 1);
|
|
65559
65750
|
}
|
|
65560
65751
|
printError(`${KIND_DIRS[kind]}: ${[...counts].map(([label, count]) => `${count} ${label}`).join(", ")}`);
|
|
65561
65752
|
for (const change of changes) {
|
|
65562
65753
|
const drift = driftOf(change);
|
|
65563
65754
|
if (drift) {
|
|
65564
|
-
|
|
65755
|
+
const fate = stale.has(`${change.kind}:${change.key}`) ? "your edit is refused as stale" : "kept as the server has it";
|
|
65756
|
+
printError(` ! ${change.key} (${drift} on the server; ${fate})`);
|
|
65757
|
+
continue;
|
|
65758
|
+
}
|
|
65759
|
+
if (refusedDelete(change)) {
|
|
65760
|
+
printError(` - ${change.key} — refused, needs --allow-delete`);
|
|
65565
65761
|
continue;
|
|
65566
65762
|
}
|
|
65567
65763
|
if (change.action === "noop")
|
|
@@ -65592,7 +65788,7 @@ function missingBlobPaths(error) {
|
|
|
65592
65788
|
return errors.flatMap((finding) => typeof finding.file === "string" ? [finding.file] : []);
|
|
65593
65789
|
}
|
|
65594
65790
|
var WORKFLOW_LOCK_PATH = new RegExp(`^${KIND_DIRS.workflow}/([^/]+)/${SOURCE_LOCK_FILE.replaceAll(".", "\\.")}$`);
|
|
65595
|
-
async function orphanedWorkflowFiles(dir, files) {
|
|
65791
|
+
async function orphanedWorkflowFiles(dir, files, recorded) {
|
|
65596
65792
|
const filesByFolder = new Map;
|
|
65597
65793
|
for (const path of Object.keys(files)) {
|
|
65598
65794
|
if (!path.startsWith(`${KIND_DIRS.workflow}/`))
|
|
@@ -65619,7 +65815,8 @@ async function orphanedWorkflowFiles(dir, files) {
|
|
|
65619
65815
|
if (!isRecordLike(next) || !isRecordLike(next.blocks))
|
|
65620
65816
|
continue;
|
|
65621
65817
|
const previous = await readSourceJson(dir, path);
|
|
65622
|
-
|
|
65818
|
+
const inFolder = Object.fromEntries(Object.entries(recorded).flatMap(([recordedPath, sha]) => recordedPath.startsWith(`${folder}/`) ? [[recordedPath.slice(folder.length + 1), sha]] : []));
|
|
65819
|
+
orphaned.push(...orphanedCodeFiles(previous, next, written, inFolder).map((file) => `${folder}/${file}`));
|
|
65623
65820
|
}
|
|
65624
65821
|
return orphaned;
|
|
65625
65822
|
}
|
|
@@ -65672,7 +65869,7 @@ function droppedResourceFiles(sent, reprinted) {
|
|
|
65672
65869
|
async function saveApplied(dir, data, submission, written, records) {
|
|
65673
65870
|
assertWorkspacePaths(Object.keys(data.files));
|
|
65674
65871
|
const orphaned = [
|
|
65675
|
-
...await orphanedWorkflowFiles(dir, data.files),
|
|
65872
|
+
...await orphanedWorkflowFiles(dir, data.files, written.digests),
|
|
65676
65873
|
...droppedResourceFiles(submission.files, data.files)
|
|
65677
65874
|
];
|
|
65678
65875
|
const kept = { ...written.digests, ...appliedBlobDigests(submission, data.base) };
|
|
@@ -65697,7 +65894,7 @@ function baseWorkflowOf(base) {
|
|
|
65697
65894
|
function baseWorkspaceOf(base) {
|
|
65698
65895
|
return isRecordLike(base) && typeof base.workspaceId === "string" ? base.workspaceId : null;
|
|
65699
65896
|
}
|
|
65700
|
-
async function promoted(client, dir, submission, target,
|
|
65897
|
+
async function promoted(client, dir, submission, target, deleteTargetOnly) {
|
|
65701
65898
|
if (baseWorkspaceOf(submission.base) === target) {
|
|
65702
65899
|
throw new SourceDirError(`${dir} was read from workspace ${target}; apply it without --to.`, {
|
|
65703
65900
|
code: "SOURCE_PROMOTE_SAME_WORKSPACE"
|
|
@@ -65719,14 +65916,15 @@ async function promoted(client, dir, submission, target, allowDelete) {
|
|
|
65719
65916
|
kinds: submission.kinds,
|
|
65720
65917
|
target: { files: data.files, base: targetBase },
|
|
65721
65918
|
record,
|
|
65722
|
-
|
|
65919
|
+
deleteTargetOnly
|
|
65723
65920
|
});
|
|
65724
65921
|
return {
|
|
65725
65922
|
submission: { ...submission, files: composed.files, base: composed.base },
|
|
65726
65923
|
files: submission.files,
|
|
65727
65924
|
record,
|
|
65728
65925
|
target,
|
|
65729
|
-
deletedInTarget: composed.deletedInTarget
|
|
65926
|
+
deletedInTarget: composed.deletedInTarget,
|
|
65927
|
+
targetOnly: composed.targetOnly
|
|
65730
65928
|
};
|
|
65731
65929
|
}
|
|
65732
65930
|
async function savePromotion(dir, target, promotion, data) {
|
|
@@ -65741,7 +65939,8 @@ async function savePromotion(dir, target, promotion, data) {
|
|
|
65741
65939
|
files: promotion.files,
|
|
65742
65940
|
submission: {
|
|
65743
65941
|
files: promotion.submission.files,
|
|
65744
|
-
base: parseWorkspaceBase(promotion.submission.base).base ?? base
|
|
65942
|
+
base: parseWorkspaceBase(promotion.submission.base).base ?? base,
|
|
65943
|
+
targetOnly: promotion.targetOnly
|
|
65745
65944
|
},
|
|
65746
65945
|
applied: { base, files: data.files, plan: data.plan }
|
|
65747
65946
|
});
|
|
@@ -65751,23 +65950,33 @@ async function savePromotion(dir, target, promotion, data) {
|
|
|
65751
65950
|
function resourceWhere(kind, key) {
|
|
65752
65951
|
return isFileKind(kind) ? `${KIND_DIRS[kind]} ${key}` : `${KIND_DIRS[kind]}/${key}`;
|
|
65753
65952
|
}
|
|
65754
|
-
function promotionHint(code, target) {
|
|
65953
|
+
function promotionHint(code, target, targetOnly) {
|
|
65755
65954
|
const record = promotionRecordPath(target) ?? ".sim/targets/<workspaceId>.json";
|
|
65756
65955
|
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
|
|
65956
|
+
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.`;
|
|
65957
|
+
}
|
|
65958
|
+
if (code === "W_SERVER_CHANGED") {
|
|
65959
|
+
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.`;
|
|
65960
|
+
}
|
|
65961
|
+
if (code === "E_APPLY_DELETE_NOT_ALLOWED") {
|
|
65962
|
+
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.`;
|
|
65963
|
+
}
|
|
65964
|
+
if (code === "W_UNDECLARED" && targetOnly) {
|
|
65965
|
+
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
65966
|
}
|
|
65759
65967
|
if (code === "E_APPLY_NO_BASE") {
|
|
65760
65968
|
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
65969
|
}
|
|
65762
65970
|
return;
|
|
65763
65971
|
}
|
|
65764
|
-
function withPromotionHint(finding, code,
|
|
65765
|
-
const
|
|
65972
|
+
function withPromotionHint(finding, code, promotion) {
|
|
65973
|
+
const targetOnly = promotion.targetOnly.includes(`${finding.kind}:${finding.key}`);
|
|
65974
|
+
const hint = promotionHint(code, promotion.target, targetOnly);
|
|
65766
65975
|
return hint === undefined ? finding : { ...finding, hint };
|
|
65767
65976
|
}
|
|
65768
65977
|
function promotionDiagnostics(diagnostics, promotion) {
|
|
65769
65978
|
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
|
|
65979
|
+
return diagnostics.flatMap((finding) => finding.code === "W_SERVER_DELETED" && warned.has(`${finding.kind}:${finding.key}`) ? [] : [withPromotionHint(finding, finding.code, promotion)]);
|
|
65771
65980
|
}
|
|
65772
65981
|
function promotionWarnings(promotion, outcome) {
|
|
65773
65982
|
const { target } = promotion;
|
|
@@ -65786,11 +65995,12 @@ function promotionWarnings(promotion, outcome) {
|
|
|
65786
65995
|
}
|
|
65787
65996
|
];
|
|
65788
65997
|
});
|
|
65789
|
-
const
|
|
65998
|
+
const onlyInTarget = new Set(promotion.targetOnly);
|
|
65999
|
+
const targetOnly = outcome.plan.filter((change) => change.action === "delete" && onlyInTarget.has(`${change.kind}:${change.key}`) && (!outcome.failed || wasWritten(change, outcome))).map((change) => ({
|
|
65790
66000
|
code: "W_PROMOTE_DELETES_TARGET_ONLY",
|
|
65791
66001
|
severity: "warning",
|
|
65792
|
-
message: `${resourceWhere(change.kind, change.key)} is only in workspace ${target}, not in this directory, so --
|
|
65793
|
-
hint: "Promote without --
|
|
66002
|
+
message: `${resourceWhere(change.kind, change.key)} is only in workspace ${target}, not in this directory, so --delete-target-only deletes it there.`,
|
|
66003
|
+
hint: "Promote without --delete-target-only to keep it, or declare it in this directory.",
|
|
65794
66004
|
kind: change.kind,
|
|
65795
66005
|
key: change.key
|
|
65796
66006
|
}));
|
|
@@ -65804,7 +66014,7 @@ function rehinted(refusal, promotion) {
|
|
|
65804
66014
|
return refusal;
|
|
65805
66015
|
const details = {
|
|
65806
66016
|
...refusal.details,
|
|
65807
|
-
diagnostics: diagnostics.map((finding) => isRecordLike(finding) && typeof finding.code === "string" ? withPromotionHint(finding, finding.code, promotion
|
|
66017
|
+
diagnostics: diagnostics.map((finding) => isRecordLike(finding) && typeof finding.code === "string" ? withPromotionHint(finding, finding.code, promotion) : finding)
|
|
65808
66018
|
};
|
|
65809
66019
|
const copy = new SimApiError(refusal.message, refusal.status, refusal.code, details, refusal.exitCode, refusal.requestId);
|
|
65810
66020
|
copy.retryAfterMs = refusal.retryAfterMs;
|
|
@@ -65825,7 +66035,8 @@ function attachWorkspaceSourceApply(source) {
|
|
|
65825
66035
|
"copy every workflow from a dev workspace into a prod workspace (--to)",
|
|
65826
66036
|
"save bulk edits to every workflow"
|
|
65827
66037
|
]);
|
|
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) => {
|
|
66038
|
+
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) => {
|
|
66039
|
+
assertTargetOnlyDeletable(options);
|
|
65829
66040
|
const mode = writeMode(options);
|
|
65830
66041
|
const only = parseKinds(options.only);
|
|
65831
66042
|
const { client, profile } = connect();
|
|
@@ -65892,7 +66103,7 @@ function attachWorkspaceSourceApply(source) {
|
|
|
65892
66103
|
await assertWorkspaceDir(options.dir);
|
|
65893
66104
|
}
|
|
65894
66105
|
assertBlobsFetched(options.dir, read, written.digests);
|
|
65895
|
-
promotion = options.to ? await promoted(client, options.dir, read, options.to, options.
|
|
66106
|
+
promotion = options.to ? await promoted(client, options.dir, read, options.to, options.deleteTargetOnly === true) : null;
|
|
65896
66107
|
const submission = promotion?.submission ?? read;
|
|
65897
66108
|
const reported = (data) => promotion ? {
|
|
65898
66109
|
...data,
|
|
@@ -65970,9 +66181,20 @@ function applyCommand(options) {
|
|
|
65970
66181
|
`sim workspaces source apply --dir ${shellWord(options.dir)}`,
|
|
65971
66182
|
...options.only ? [`--only ${shellWord(options.only)}`] : [],
|
|
65972
66183
|
...options.to ? [`--to ${shellWord(options.to)}`] : [],
|
|
65973
|
-
...options.allowDelete ? ["--allow-delete"] : []
|
|
66184
|
+
...options.allowDelete ? ["--allow-delete"] : [],
|
|
66185
|
+
...options.deleteTargetOnly ? ["--delete-target-only"] : []
|
|
65974
66186
|
].join(" ");
|
|
65975
66187
|
}
|
|
66188
|
+
function assertTargetOnlyDeletable(options) {
|
|
66189
|
+
if (!options.deleteTargetOnly)
|
|
66190
|
+
return;
|
|
66191
|
+
if (!options.to) {
|
|
66192
|
+
throw new CliUsageError("--delete-target-only deletes a promotion target's own resources: it needs --to <workspaceId>.");
|
|
66193
|
+
}
|
|
66194
|
+
if (!options.allowDelete) {
|
|
66195
|
+
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.");
|
|
66196
|
+
}
|
|
66197
|
+
}
|
|
65976
66198
|
function notSentFindings(paths) {
|
|
65977
66199
|
return paths.map((path) => ({
|
|
65978
66200
|
code: "W_PATH_NOT_SENT",
|
|
@@ -66066,6 +66288,7 @@ ${SOURCE_DIR_BUSY_HELP}`).action(async (options, command) => {
|
|
|
66066
66288
|
};
|
|
66067
66289
|
const keys = await workspaceWorkflowKeys(options.dir);
|
|
66068
66290
|
const findings = [];
|
|
66291
|
+
const unlisted = { errors: 0, warnings: 0 };
|
|
66069
66292
|
for (const key of keys) {
|
|
66070
66293
|
const checked = await checkWorkflowDir(join12(options.dir, KIND_DIRS.workflow, key), catalog, {
|
|
66071
66294
|
declarations,
|
|
@@ -66073,6 +66296,8 @@ ${SOURCE_DIR_BUSY_HELP}`).action(async (options, command) => {
|
|
|
66073
66296
|
prefix: `${KIND_DIRS.workflow}/${key}/`
|
|
66074
66297
|
});
|
|
66075
66298
|
findings.push(...checked.findings);
|
|
66299
|
+
unlisted.errors += checked.unlisted.errors;
|
|
66300
|
+
unlisted.warnings += checked.unlisted.warnings;
|
|
66076
66301
|
}
|
|
66077
66302
|
for (const {
|
|
66078
66303
|
code,
|
|
@@ -66095,7 +66320,7 @@ ${SOURCE_DIR_BUSY_HELP}`).action(async (options, command) => {
|
|
|
66095
66320
|
}
|
|
66096
66321
|
await refreshWorkspaceTypes(options.dir, withWorkflowInputs(declarations.local, workflowInputs));
|
|
66097
66322
|
await refreshWorkspaceTsconfigs(options.dir, workspaceId);
|
|
66098
|
-
reportCheck(profile.output, findings, { workflows: keys.length, catalogHash: catalog.hash }, { verbose: options.verbose === true, bound: WORKSPACE_ANSWER_BOUND });
|
|
66323
|
+
reportCheck(profile.output, findings, { workflows: keys.length, catalogHash: catalog.hash }, { verbose: options.verbose === true, bound: WORKSPACE_ANSWER_BOUND, unlisted });
|
|
66099
66324
|
});
|
|
66100
66325
|
});
|
|
66101
66326
|
}
|
|
@@ -66271,6 +66496,9 @@ function attachWorkspaceSourceGet(source) {
|
|
|
66271
66496
|
const result = await writeWorkspaceSource(client, options.dir, data, options.force === true);
|
|
66272
66497
|
const findings = findingsOutput(profile.output);
|
|
66273
66498
|
findings.print(data.diagnostics);
|
|
66499
|
+
for (const { kind, key, reason } of data.skipped) {
|
|
66500
|
+
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).`);
|
|
66501
|
+
}
|
|
66274
66502
|
printTreeResult(profile.output, {
|
|
66275
66503
|
workspaceId: data.workspaceId,
|
|
66276
66504
|
dir: options.dir,
|
|
@@ -66304,9 +66532,10 @@ async function readLocalWorkspace(dir, only) {
|
|
|
66304
66532
|
current[path] = digest(text);
|
|
66305
66533
|
for (const blob of submission.blobs)
|
|
66306
66534
|
current[blob.path] = blob.sha256;
|
|
66535
|
+
const unnamed = new Set(submission.unnamed);
|
|
66307
66536
|
const changed = changedFiles(current, written.digests, (path) => {
|
|
66308
66537
|
const kind = kindOfPath(path);
|
|
66309
|
-
return kind !== null && (!only || only.includes(kind));
|
|
66538
|
+
return kind !== null && (!only || only.includes(kind)) && !unnamed.has(path);
|
|
66310
66539
|
});
|
|
66311
66540
|
return { submission, written, changed, readFrom };
|
|
66312
66541
|
}
|
|
@@ -66459,6 +66688,7 @@ ${SOURCE_DIR_BUSY_HELP}`).action(async (options, invoked) => {
|
|
|
66459
66688
|
server,
|
|
66460
66689
|
...note ? { note } : {},
|
|
66461
66690
|
...status,
|
|
66691
|
+
...local.submission.unnamed.length > 0 ? { unnamed: local.submission.unnamed } : {},
|
|
66462
66692
|
plan,
|
|
66463
66693
|
next: (login ? null : unmanagedNext(status, local.submission.kinds, options.dir, workspaceScope)) ?? nextStep(status, {
|
|
66464
66694
|
prefix: PREFIX2,
|