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/runtime.js CHANGED
@@ -42446,6 +42446,7 @@ class CliUsageError extends LocalRefusal {
42446
42446
  }
42447
42447
 
42448
42448
  // src/commands/protocol/source-dir/command-lock.ts
42449
+ import { readFileSync as readFileSync4 } from "node:fs";
42449
42450
  import { lstat as lstat3, mkdir as mkdir2, readFile as readFile2, realpath as realpath2, rm as rm3, rmdir, stat as stat2, writeFile as writeFile2 } from "node:fs/promises";
42450
42451
  import { hostname } from "node:os";
42451
42452
  import { dirname as dirname7, join as join6, resolve as resolve4 } from "node:path";
@@ -46036,7 +46037,7 @@ function formerBlockHint(ctx, formerKey, renamed, rewritten, spell) {
46036
46037
  const unbound = [...ctx.declsByKey.values()].filter((decl) => !ctx.knownKeys.has(decl.key) && !renamedTo.has(decl.key));
46037
46038
  const lead = `${spell([{ kind: "name", name: formerKey }])} is a block this workflow had that ${SOURCE_ENTRY_FILE} no longer declares under that key`;
46038
46039
  const [only] = unbound;
46039
- return unbound.length === 1 && only ? `${lead}: if ${only.name} is it renamed, write ${rewritten(only.key)}.` : `${lead}: if you renamed it, write ${spell([{ kind: "name", name: "newkey" }])}, where newkey is its display name lowercased with whitespace and dots removed.`;
46040
+ return unbound.length === 1 && only ? `${lead}: if it was renamed to ${only.name}, an apply that keeps its id rewrites this reference to ${rewritten(only.key)}, so no edit is needed.` : `${lead}: if you renamed it, write ${spell([{ kind: "name", name: "newkey" }])}, where newkey is its display name lowercased with whitespace and dots removed.`;
46040
46041
  }
46041
46042
  function subflowScopeRef(ctx, node, container, members, site) {
46042
46043
  const kind = containerKindOf(container) ?? "loop";
@@ -48326,8 +48327,11 @@ function readCodeFile(ctx, compiled, language, decl) {
48326
48327
  }
48327
48328
  function parseCodeFile(ctx, path, text, language, at, decl) {
48328
48329
  const { limits } = ctx;
48330
+ const before = ctx.codeFiles.bytes;
48329
48331
  ctx.codeFiles.bytes += utf8Bytes(text, limits.maxTotalBytes);
48330
48332
  if (ctx.codeFiles.bytes > limits.maxTotalBytes) {
48333
+ if (before > limits.maxTotalBytes)
48334
+ return null;
48331
48335
  ctx.reporter.report("E_LIMIT_EXCEEDED", `The workflow and its code files total more than ${limits.maxTotalBytes} bytes.`, at, { hint: "Share one code file between blocks, or shorten the code.", blockKey: decl.key });
48332
48336
  return null;
48333
48337
  }
@@ -50466,6 +50470,9 @@ var refusalClass = refusalClassifier();
50466
50470
  var CHANGED_BLOCK_REFUSALS = new Map([
50467
50471
  ["W_REF_OUT_OF_SCOPE", "E_APPLY_REF_OUT_OF_SCOPE"]
50468
50472
  ]);
50473
+ var PARAM_REFUSALS = new Map([
50474
+ ["W_UNKNOWN_OPTION", "E_APPLY_INVALID_SUBBLOCK_FIELD"]
50475
+ ]);
50469
50476
  var ENTRY_REFUSALS = new Map([
50470
50477
  ["W_UNKNOWN_OUTPUT_PATH", "E_APPLY_UNRESOLVED_REF"]
50471
50478
  ]);
@@ -50475,6 +50482,7 @@ var CODE_FILE_REFUSALS = new Map([
50475
50482
  ["W_CODE_FILE_REF_SYNTAX", "E_APPLY_CODE_FILE_REF_SYNTAX"]
50476
50483
  ]);
50477
50484
  var REFUSABLE_WARNING_CODES = new Set([
50485
+ "W_UNKNOWN_OPTION",
50478
50486
  "W_REF_OUT_OF_SCOPE",
50479
50487
  "W_UNKNOWN_OUTPUT_PATH",
50480
50488
  "W_UNRESOLVED_REF",
@@ -50486,6 +50494,11 @@ var EDIT_REFUSALS = [
50486
50494
  refusal,
50487
50495
  where: "changed block"
50488
50496
  })),
50497
+ ...[...PARAM_REFUSALS].map(([warning, refusal]) => ({
50498
+ warning,
50499
+ refusal,
50500
+ where: "workflow.ts"
50501
+ })),
50489
50502
  ...[...ENTRY_REFUSALS].map(([warning, refusal]) => ({
50490
50503
  warning,
50491
50504
  refusal,
@@ -50511,6 +50524,15 @@ function refusalOf(finding, edit) {
50511
50524
  const edited = edit.changed(blockKey) || !inEntryFile && edit.codeEdited(blockKey, span.file);
50512
50525
  return edited ? onChanged : undefined;
50513
50526
  }
50527
+ const onParam = PARAM_REFUSALS.get(finding.code);
50528
+ if (onParam) {
50529
+ const { param } = finding;
50530
+ if (!inEntryFile || param === undefined || param === "operation")
50531
+ return;
50532
+ if (!edit.changed(blockKey))
50533
+ return;
50534
+ return edit.paramChanged?.(blockKey, param) ?? true ? onParam : undefined;
50535
+ }
50514
50536
  if (inEntryFile) {
50515
50537
  const inEntry = ENTRY_REFUSALS.get(finding.code);
50516
50538
  return inEntry && edit.changed(blockKey) ? inEntry : undefined;
@@ -50518,6 +50540,9 @@ function refusalOf(finding, edit) {
50518
50540
  const inCode = CODE_FILE_REFUSALS.get(finding.code);
50519
50541
  return inCode && edit.codeEdited(blockKey, span.file) ? inCode : undefined;
50520
50542
  }
50543
+ function refusesEdited(finding, edit) {
50544
+ return refusalOf(finding, edit) !== undefined;
50545
+ }
50521
50546
  function refuseEditedFindings(compiled, edit) {
50522
50547
  const refused = (finding) => {
50523
50548
  const code = refusalOf(finding, edit);
@@ -50701,6 +50726,10 @@ function capLength(text) {
50701
50726
  class Reporter {
50702
50727
  diagnostics = [];
50703
50728
  withheld = [];
50729
+ get omitted() {
50730
+ return [...this.omittedCounts.values()];
50731
+ }
50732
+ omittedCounts = new Map;
50704
50733
  refusableHeld = new Set;
50705
50734
  indexes = new Map;
50706
50735
  errorCount = 0;
@@ -50744,7 +50773,7 @@ class Reporter {
50744
50773
  if (this.infoCount >= MAX_LISTED)
50745
50774
  return;
50746
50775
  } else if (this.warningCount >= MAX_LISTED) {
50747
- this.withhold(code, message, at, extras);
50776
+ this.omit(code, message, at, extras);
50748
50777
  if (this.warningCount === MAX_LISTED) {
50749
50778
  this.truncated(`Listed ${MAX_LISTED} warnings; the rest are omitted. The next: ${message}`, at, framesSource(code));
50750
50779
  }
@@ -50753,7 +50782,7 @@ class Reporter {
50753
50782
  const ofCode = this.warningsByCode.get(code) ?? 0;
50754
50783
  this.warningsByCode.set(code, ofCode + 1);
50755
50784
  if (ofCode >= MAX_WARNINGS_PER_CODE) {
50756
- this.withhold(code, message, at, extras);
50785
+ this.omit(code, message, at, extras);
50757
50786
  if (ofCode === MAX_WARNINGS_PER_CODE) {
50758
50787
  this.truncated(`Listed ${MAX_WARNINGS_PER_CODE} ${code} warnings; the rest of them are omitted. The next: ${message}`, at, framesSource(code));
50759
50788
  }
@@ -50765,10 +50794,25 @@ class Reporter {
50765
50794
  this.refusableHeld.add(held);
50766
50795
  this.record(code, message, at, extras, framesSource(code));
50767
50796
  }
50768
- withhold(code, message, at, extras) {
50797
+ omit(code, message, at, extras) {
50769
50798
  const held = refusableKey(code, at, extras);
50770
- if (held === undefined || this.refusableHeld.has(held))
50799
+ if (held === undefined || this.refusableHeld.has(held)) {
50800
+ const refusable = held === undefined ? undefined : { file: at.file, param: extras.param };
50801
+ const key = [code, extras.blockKey ?? "", refusable?.file ?? "", refusable?.param ?? ""].join("\x00");
50802
+ const counted = this.omittedCounts.get(key);
50803
+ if (counted)
50804
+ counted.count++;
50805
+ else {
50806
+ this.omittedCounts.set(key, {
50807
+ code,
50808
+ ...extras.blockKey !== undefined ? { blockKey: extras.blockKey } : {},
50809
+ ...refusable ? { file: refusable.file } : {},
50810
+ ...refusable?.param !== undefined ? { param: refusable.param } : {},
50811
+ count: 1
50812
+ });
50813
+ }
50771
50814
  return;
50815
+ }
50772
50816
  this.refusableHeld.add(held);
50773
50817
  const { hint, ...listed } = extras;
50774
50818
  const diagnostic = this.build(code, message, at, listed, framesSource(code));
@@ -51324,6 +51368,7 @@ function emptyResult(reporter, sdkMajor) {
51324
51368
  workflow: null,
51325
51369
  diagnostics: reporter.diagnostics,
51326
51370
  withheld: reporter.withheld,
51371
+ omitted: reporter.omitted,
51327
51372
  spans: {},
51328
51373
  metaSpans: {},
51329
51374
  hints: { blocks: {} },
@@ -51562,6 +51607,7 @@ function compileEntry(input, file, text, reporter) {
51562
51607
  workflow,
51563
51608
  diagnostics: reporter.diagnostics,
51564
51609
  withheld: reporter.withheld,
51610
+ omitted: reporter.omitted,
51565
51611
  spans,
51566
51612
  metaSpans: ctx.metaSpans,
51567
51613
  hints,
@@ -52556,7 +52602,7 @@ function assertSendableCodeFiles(files) {
52556
52602
  }
52557
52603
  function sourceRelativePath(path) {
52558
52604
  const normalized = posix2.normalize(path.replace(/\\/g, "/"));
52559
- if (normalized.startsWith("/") || /^[A-Za-z]:/.test(normalized) || normalized === "." || normalized === ".." || normalized.startsWith("../")) {
52605
+ if (normalized.includes("\x00") || normalized.startsWith("/") || /^[A-Za-z]:/.test(normalized) || normalized === "." || normalized === ".." || normalized.startsWith("../")) {
52560
52606
  return null;
52561
52607
  }
52562
52608
  return normalized.startsWith("./") ? normalized.slice(2) : normalized;
@@ -52571,11 +52617,11 @@ function lockCodeFiles(lock) {
52571
52617
  }
52572
52618
  return paths;
52573
52619
  }
52574
- function orphanedCodeFiles(previousLock, nextLock, written) {
52620
+ function orphanedCodeFiles(previousLock, nextLock, written, recorded) {
52575
52621
  const kept = lockCodeFiles(nextLock);
52576
52622
  for (const path of written)
52577
52623
  kept.add(path);
52578
- return [...lockCodeFiles(previousLock)].filter((path) => path.startsWith(`${SOURCE_CODE_DIR}/`) && isCodeFilePath(path) && !kept.has(path));
52624
+ return [...lockCodeFiles(previousLock)].filter((path) => path.startsWith(`${SOURCE_CODE_DIR}/`) && isCodeFilePath(path) && Object.hasOwn(recorded, path) && !kept.has(path));
52579
52625
  }
52580
52626
  function writableFiles(files) {
52581
52627
  const refused = refusedSourcePaths(files);
@@ -52951,14 +52997,32 @@ async function withSourceDirLock(dir, run, options = {}) {
52951
52997
  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 });
52952
52998
  }
52953
52999
  const owner = { pid: process.pid, host: hostname() };
52954
- const disposeSignalRelease = removeStagingOnSignal(() => lock);
53000
+ let ownerRecorded = false;
53001
+ const ownedLock = () => {
53002
+ if (!ownerRecorded)
53003
+ return lock;
53004
+ try {
53005
+ const recorded = toRecord(JSON.parse(readFileSync4(join6(lock, LOCK_OWNER_FILE), "utf8")));
53006
+ return recorded.pid === owner.pid && recorded.host === owner.host ? lock : null;
53007
+ } catch {
53008
+ return null;
53009
+ }
53010
+ };
53011
+ const disposeSignalRelease = removeStagingOnSignal(ownedLock);
52955
53012
  try {
52956
53013
  await writeFile2(join6(lock, LOCK_OWNER_FILE), JSON.stringify(owner));
53014
+ ownerRecorded = true;
52957
53015
  return await run();
52958
53016
  } finally {
52959
- disposeSignalRelease();
52960
- await rm3(await checkedPath(root, SOURCE_DIR_LOCK, new Set), { recursive: true, force: true });
52961
- await removeCreatedFolders();
53017
+ try {
53018
+ await rm3(await checkedPath(root, SOURCE_DIR_LOCK, new Set), {
53019
+ recursive: true,
53020
+ force: true
53021
+ });
53022
+ await removeCreatedFolders();
53023
+ } finally {
53024
+ disposeSignalRelease();
53025
+ }
52962
53026
  }
52963
53027
  }
52964
53028
  async function removeEmptyFolders(dir, outermost) {
@@ -53098,10 +53162,11 @@ async function editedFiles(dir, touched, written) {
53098
53162
  }
53099
53163
  async function locallyEditedFiles(dir, answer, previousLock) {
53100
53164
  const touched = new Map(Object.entries(answer.files));
53101
- for (const path of orphanedCodeFiles(previousLock, answer.lock, touched.keys())) {
53165
+ const { digests } = await readFolderWritten(dir);
53166
+ for (const path of orphanedCodeFiles(previousLock, answer.lock, touched.keys(), digests)) {
53102
53167
  touched.set(path, null);
53103
53168
  }
53104
- return editedFiles(dir, touched, (await readFolderWritten(dir)).digests);
53169
+ return editedFiles(dir, touched, digests);
53105
53170
  }
53106
53171
  function inWorkspace(key, path) {
53107
53172
  return `${KIND_DIRS.workflow}/${key}/${path}`;
@@ -53166,7 +53231,7 @@ async function writeBack(dir, answer, previousLock, extra = { write: [] }) {
53166
53231
  `]
53167
53232
  ];
53168
53233
  const write = [...printed, ...folder ? [] : writtenFiles(writtenRecord(files)), ...extra.write];
53169
- const orphaned = orphanedCodeFiles(previousLock, answer.lock, Object.keys(answer.files));
53234
+ const orphaned = orphanedCodeFiles(previousLock, answer.lock, Object.keys(answer.files), (await readFolderWritten(dir)).digests);
53170
53235
  const unnamed = await unnamedCodeFiles(dir, previousLock, answer, orphaned);
53171
53236
  await updateSourceDir(dir, {
53172
53237
  write,
@@ -53217,7 +53282,7 @@ function sourceExitCodeRows(prefix) {
53217
53282
  },
53218
53283
  {
53219
53284
  code: 1,
53220
- 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",
53285
+ 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",
53221
53286
  next: "Fix what it printed and run it again",
53222
53287
  help: {
53223
53288
  "workflows source apply": "the source has errors (each printed as file:line:column with its frame and hint) or the command failed",
@@ -56505,8 +56570,14 @@ function isMachine(format) {
56505
56570
  function resultDiagnostics(format, diagnostics, verbose = false) {
56506
56571
  if (!isMachine(format))
56507
56572
  return {};
56573
+ const hidden = (finding) => !verbose && finding.severity === "info" && finding.code !== "I_FINDINGS_TRUNCATED";
56574
+ const hiddenCount = diagnostics.filter(hidden).length;
56575
+ const marked = (finding) => finding.code === "I_FINDINGS_TRUNCATED" && hiddenCount > 0 ? {
56576
+ ...finding,
56577
+ message: `${finding.message} ${hiddenCount} info finding${hiddenCount === 1 ? "" : "s"} listed ${hiddenCount === 1 ? "is" : "are"} hidden too; pass --verbose to see ${hiddenCount === 1 ? "it" : "them"}.`
56578
+ } : finding;
56508
56579
  return {
56509
- diagnostics: diagnostics.filter((finding) => verbose || finding.severity !== "info" || finding.code === "I_FINDINGS_TRUNCATED").map(({ frame: _frame, ...finding }) => finding)
56580
+ diagnostics: diagnostics.filter((finding) => !hidden(finding)).map(({ frame: _frame, ...finding }) => marked(finding))
56510
56581
  };
56511
56582
  }
56512
56583
  function findingKey(diagnostic) {
@@ -56799,7 +56870,7 @@ async function readJson(directory, path, hint) {
56799
56870
  }
56800
56871
  function codeFilePaths(entry, lock) {
56801
56872
  const candidates = lockCodeFiles(lock);
56802
- for (const literal of codeFileReferences(entry)) {
56873
+ for (const literal of entry === null ? [] : codeFileReferences(entry)) {
56803
56874
  const path = sourceRelativePath(literal);
56804
56875
  if (path)
56805
56876
  candidates.add(path);
@@ -56867,7 +56938,7 @@ The primer above is enough to edit; read a section here when a step needs it.
56867
56938
  2. \`sim workflows source check --dir .\`: compiles offline with the server's compiler, in milliseconds. It catches what \`tsc\` cannot (duplicate names, cycles, literal secrets), and fails (exit 1) on a missing required field, an unknown option or output path, a wrong value kind, an out-of-range value, an unwired condition or router branch or a literal secret in a block you added (\`--strict\`: in every block). It also adds the blocks the source now uses to \`tsconfig.json\`.
56868
56939
  3. \`${typecheckCommand()}\`: about a second; catches what step 2 and the dry run do not (such as a reference to a start input the trigger does not declare). It runs the TypeScript release the declarations are built for (the directory has no \`package.json\`; plain \`bunx tsc\` would run whatever version it finds). \`tsconfig.json\` includes only the blocks the source used at the last check, get or apply: a builder from another block fails with \`has no exported member\` until you run step 2 (or use \`${typecheckCommand(TSCONFIG_FULL_FILE)}\`, every current block). The dry run is the authority: a printed line you did not edit that \`tsc\` flags and the dry run accepts is fine.
56869
56940
  4. \`sim workflows source status --dir .\`: the files you changed (\`sim workflows source diff --dir .\` shows the edits), whether the workflow changed on the server since the get, and the command to run next (\`--offline\`: skip the server). Then \`sim workflows source apply --dir . --dry-run\` until it exits 0.
56870
- 5. \`sim workflows source apply --dir . --yes\`: saves the draft, refusing errors, block deletions without \`--allow-delete\` and a stale directory, so it needs no separate dry run (without \`--yes\` and a terminal it prints the plan and exits ${SOURCE_PLANNED_EXIT_CODE}). \`--deploy\` also deploys it; without it, a deployed workflow's next \`sim workflows deploy <id>\` is printed. It then rewrites \`${SOURCE_ENTRY_FILE}\` in canonical form (order, quoting, defaults left out).
56941
+ 5. \`sim workflows source apply --dir . --yes\`: saves the draft, refusing errors, block deletions without \`--allow-delete\` and a stale directory, so it needs no separate dry run (without \`--yes\` and a terminal it prints the plan and exits ${SOURCE_PLANNED_EXIT_CODE}). \`--deploy\` also deploys it; without it, a deployed workflow's next \`sim workflows deploy <id> --expected-draft-fingerprint <fingerprint>\` is printed, which deploys only the draft this apply saved. It then rewrites \`${SOURCE_ENTRY_FILE}\` in canonical form (order, quoting, defaults left out).
56871
56942
  6. Exit ${SOURCE_STALE_EXIT_CODE} (\`SOURCE_STALE\`, HTTP 409, or \`E_APPLY_STALE\` on a dry run): the workflow changed and nothing was saved. Run \`sim workflows source get <workflowId> --dir <fresh dir>\`, reapply your edit there, dry-run, apply. A get into this directory refuses to overwrite your unapplied edits unless you pass \`--force\`. Exit ${SOURCE_STALE_EXIT_CODE} right after an apply that ended without an answer (a timeout, a dropped connection) means the draft changed, by that apply or by someone else: get into a fresh directory and compare. Only when it holds your edit, run \`sim workflows source get <workflowId> --dir . --force\`; otherwise reapply your edit in the fresh directory.
56872
56943
 
56873
56944
  Editing the \`workflow('…')\` name or description renames or redescribes the workflow; a name another workflow in its folder holds is refused with \`E_NAME_TAKEN\`. Lines starting \`note:\` explain something the write did differently than the source says; read them.
@@ -57094,7 +57165,7 @@ async function writeWorkflowSource(args) {
57094
57165
  report(data, deployment);
57095
57166
  }
57096
57167
  async function deployStep(client, data, options) {
57097
- const deployCommand = `sim workflows deploy ${data.workflowId}`;
57168
+ const deployCommand = `sim workflows deploy ${data.workflowId} --expected-draft-fingerprint ${data.base.fingerprint}`;
57098
57169
  if (!options.deploy) {
57099
57170
  if (!data.needsRedeployment)
57100
57171
  return {};
@@ -57105,6 +57176,24 @@ async function deployStep(client, data, options) {
57105
57176
  }
57106
57177
  };
57107
57178
  }
57179
+ if (!data.applied && !data.needsRedeployment) {
57180
+ const status = await client.request("getWorkflowDeployment", {
57181
+ params: { workflowId: data.workflowId }
57182
+ }).then((response) => response.data, (error) => {
57183
+ throw deployFailure(error, options, deployCommand);
57184
+ });
57185
+ if (status.isDeployed && !status.needsRedeployment) {
57186
+ if (!options.machine)
57187
+ printError("The live version already matches the draft; nothing was deployed.");
57188
+ return {
57189
+ deployed: {
57190
+ ...status.activeDeployment ? { version: status.activeDeployment.version } : {},
57191
+ isDeployed: true
57192
+ },
57193
+ needsRedeployment: false
57194
+ };
57195
+ }
57196
+ }
57108
57197
  const deployed = await client.request("deployWorkflow", {
57109
57198
  params: { workflowId: data.workflowId },
57110
57199
  body: { expectedDraftFingerprint: data.base.fingerprint }
@@ -57139,6 +57228,7 @@ function attachWorkflowSourceApply(source) {
57139
57228
  const [command, connectApply] = apiCommand(source, "apply", [
57140
57229
  "applyWorkflowSource",
57141
57230
  "deployWorkflow",
57231
+ "getWorkflowDeployment",
57142
57232
  "getSourceResources"
57143
57233
  ]);
57144
57234
  absoluteDirOption(command);
@@ -57187,7 +57277,8 @@ function attachWorkflowSourceCreate(source) {
57187
57277
  "createWorkflowFromSource",
57188
57278
  "getSourceCatalog",
57189
57279
  "getSourceResources",
57190
- "deployWorkflow"
57280
+ "deployWorkflow",
57281
+ "getWorkflowDeployment"
57191
57282
  ]);
57192
57283
  absoluteDirOption(command);
57193
57284
  verboseFlag(command);
@@ -63492,7 +63583,7 @@ var ADVANCED_GUIDE = `# Sim workspace source: advanced
63492
63583
 
63493
63584
  ## Promote to another workspace
63494
63585
 
63495
- \`sim workspaces source apply --dir . --to <workspaceId> --dry-run\`, then \`--yes\`: applies this directory to another workspace (dev to prod). Each resource binds by key to the target's own: one the target holds under the same key is updated in place (a workflow keeps its id and block ids, so its webhook URLs), a key it lacks is created (or adopts a resource of the same name). Each promote records what it left in the target in \`.sim/targets/<workspaceId>.json\` (commit it), and the next promote compares with that: a resource changed in the target since is kept when this directory left it alone, and refused as stale (exit ${SOURCE_STALE_EXIT_CODE}) when this directory changed it too. A resource with no record (the first promote, or one created in the target since) is updated to match this directory; delete the record to take the target as it stands again. Secrets and credentials bind by name and key to the target's own; no value is copied. The target's resources this directory does not declare are kept with a warning, or deleted 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\`).
63586
+ \`sim workspaces source apply --dir . --to <workspaceId> --dry-run\`, then \`--yes\`: applies this directory to another workspace (dev to prod). Each resource binds by key to the target's own: one the target holds under the same key is updated in place (a workflow keeps its id and block ids, so its webhook URLs), a key it lacks is created (or adopts a resource of the same name). Each promote records what it left in the target in \`.sim/targets/<workspaceId>.json\` (commit it), and the next promote compares with that: a resource changed in the target since is kept when this directory left it alone, and refused as stale (exit ${SOURCE_STALE_EXIT_CODE}) when this directory changed it too. A resource with no record (the first promote, or one created in the target since) is updated to match this directory; delete the record to take the target as it stands again. Secrets and credentials bind by name and key to the target's own; no value is copied. The target's resources this directory never declared (and no promote left there) are kept with a warning, even with \`--allow-delete\`; deleting them too takes \`--delete-target-only\` beside \`--allow-delete\`. A resource this directory deleted since the last promote is deleted in the target only with \`--allow-delete\`. Before the first promote, set the target's secrets (\`sim secrets set NAME --scope workspace -w <workspaceId>\`) and connect its credentials, or the workflows using them are held back. This directory stays bound to the workspace it was read from. Without \`--to\`, \`check\`, \`status\`, \`diff\` and \`apply\` act on the workspace this directory was read from, whatever the profile's default; a \`--workspace\` naming another is refused (\`SOURCE_OTHER_WORKSPACE\`).
63496
63587
  `;
63497
63588
  var WORKSPACE_TREE = {
63498
63589
  kind: "workspace",
@@ -63701,6 +63792,32 @@ async function assertWorkspaceDir(dir) {
63701
63792
  function keepFile(kind) {
63702
63793
  return isFileKind(kind) ? null : `${KIND_DIRS[kind]}/${KEEP_FILE}`;
63703
63794
  }
63795
+ function dropUnnamedCodeFiles(files) {
63796
+ const named = new Map;
63797
+ const unnamed = [];
63798
+ for (const path of Object.keys(files)) {
63799
+ if (kindOfPath(path) !== "workflow")
63800
+ continue;
63801
+ const segments = path.split("/");
63802
+ if (segments[2] !== SOURCE_CODE_DIR)
63803
+ continue;
63804
+ const folder = segments.slice(0, 2).join("/");
63805
+ let sent = named.get(folder);
63806
+ if (!sent) {
63807
+ let lock = null;
63808
+ try {
63809
+ lock = JSON.parse(files[`${folder}/${SOURCE_LOCK_FILE}`] ?? "null");
63810
+ } catch {}
63811
+ sent = new Set(codeFilePaths(files[`${folder}/${SOURCE_ENTRY_FILE}`] ?? null, lock));
63812
+ named.set(folder, sent);
63813
+ }
63814
+ if (!sent.has(segments.slice(2).join("/"))) {
63815
+ unnamed.push(path);
63816
+ delete files[path];
63817
+ }
63818
+ }
63819
+ return unnamed.sort(compareStrings);
63820
+ }
63704
63821
  function pruneUnchangedWorkflows(files, written, workspaceId) {
63705
63822
  const workflowPaths = Object.keys(files).filter((path) => kindOfPath(path) === "workflow");
63706
63823
  const folders = KIND_LAYOUTS.workflow.group(workflowPaths).groups;
@@ -63745,6 +63862,7 @@ async function readWorkspaceDir(dir, only, workspaceId, written, options = {}) {
63745
63862
  if (text !== null)
63746
63863
  files[path] = text;
63747
63864
  });
63865
+ const unnamed = dropUnnamedCodeFiles(files);
63748
63866
  if (!options.whole)
63749
63867
  pruneUnchangedWorkflows(files, written, workspaceId);
63750
63868
  const root = await realpath4(dir);
@@ -63773,7 +63891,7 @@ async function readWorkspaceDir(dir, only, workspaceId, written, options = {}) {
63773
63891
  throw new SourceDirError(`${WORKSPACE_BASE_FILE} in ${dir} is not valid JSON (a merge conflict?). Restore it from version control, or get the workspace into a fresh directory with \`sim workspaces source get --dir <fresh dir>\` and carry your edits over.`, { code: "SOURCE_BASE_INVALID" });
63774
63892
  }
63775
63893
  }
63776
- return { kinds, files, blobs, ignored, hashed, ...base ? { base } : {} };
63894
+ return { kinds, files, blobs, ignored, unnamed, hashed, ...base ? { base } : {} };
63777
63895
  }
63778
63896
  function skippedFile(skipped) {
63779
63897
  return skipped.length > 0 ? `${JSON.stringify(skipped, null, 2)}
@@ -64019,7 +64137,7 @@ async function compileWorkflowDir(dir, workspaceCatalog, declarations) {
64019
64137
  ...storedEdges ? { storedUnreadEdges: storedEdges } : {},
64020
64138
  ...envNames ? { envNames, envDeclaredIn: KIND_DIRS.secret } : {}
64021
64139
  });
64022
- return { lock, files, compiled, storedBlocks, printedWith };
64140
+ return { lock, files, compiled, storedBlocks, printedWith, catalog };
64023
64141
  }
64024
64142
  async function workspaceWorkflowInputs(root, catalog) {
64025
64143
  const inputs = new Map;
@@ -64040,7 +64158,8 @@ function withWorkflowInputs(local, inputs) {
64040
64158
  return { ...local, workflows };
64041
64159
  }
64042
64160
  async function checkWorkflowDir(dir, catalog, options) {
64043
- const { lock, files, compiled, storedBlocks, printedWith } = await compileWorkflowDir(dir, catalog, options.declarations);
64161
+ const compiledDir = await compileWorkflowDir(dir, catalog, options.declarations);
64162
+ const { lock, files, compiled, storedBlocks, printedWith } = compiledDir;
64044
64163
  const entryText = files[SOURCE_ENTRY_FILE];
64045
64164
  const locate = (block, param, names) => {
64046
64165
  const prefix = encodeAnchor({ kind: "param", block, param: "" });
@@ -64102,19 +64221,33 @@ async function checkWorkflowDir(dir, catalog, options) {
64102
64221
  const head = /^(?:\$ref\.|<)([A-Za-z0-9_]+)/.exec(text)?.[1];
64103
64222
  return head !== undefined && removedKeys.has(head);
64104
64223
  };
64105
- const refusable = (finding) => !mayBeRenamed(finding);
64224
+ const variesByDeployment = (finding) => {
64225
+ const { blockKey, param } = finding;
64226
+ if (finding.code !== "W_UNKNOWN_OPTION" || blockKey === undefined || param === undefined) {
64227
+ return false;
64228
+ }
64229
+ return optionsVaryOn(blockKey, (id) => id === param);
64230
+ };
64231
+ const optionsVaryOn = (blockKey, matches) => {
64232
+ const type = compiled.workflow ? getOwn(compiled.workflow.blocks, blockKey)?.type : undefined;
64233
+ const block = type === undefined ? undefined : catalogBlock(compiledDir.catalog, type);
64234
+ return block?.subBlocks.some((sub) => matches(sub.id) && sub.optionsVary === true) === true;
64235
+ };
64236
+ const exempt = (finding) => mayBeRenamed(finding) || variesByDeployment(finding);
64237
+ const refusable = (finding) => !exempt(finding);
64106
64238
  const refused = [
64107
64239
  ...refuseEditedFindings({
64108
64240
  diagnostics: compiled.diagnostics.filter(refusable),
64109
64241
  withheld: compiled.withheld.filter(refusable)
64110
64242
  }, { changed, codeEdited }),
64111
- ...compiled.diagnostics.filter(mayBeRenamed)
64243
+ ...compiled.diagnostics.filter(exempt)
64112
64244
  ];
64113
64245
  const findings = [
64114
64246
  ...refused.filter((diagnostic) => reported(diagnostic.code, diagnostic.blockKey)),
64115
64247
  ...declared
64116
- ].map(({ code, severity, message, hint, frame, span, blockKey }) => {
64117
- const raised = severity === "warning" && fails(code, blockKey);
64248
+ ].map((finding) => {
64249
+ const { code, severity, message, hint, frame, span, blockKey } = finding;
64250
+ const raised = severity === "warning" && !variesByDeployment(finding) && fails(code, blockKey);
64118
64251
  return {
64119
64252
  code,
64120
64253
  severity: raised ? "error" : severity,
@@ -64124,19 +64257,52 @@ async function checkWorkflowDir(dir, catalog, options) {
64124
64257
  ...span ? { file: `${prefix}${span.file}`, line: span.line, column: span.column } : {}
64125
64258
  };
64126
64259
  });
64127
- return { findings, entry: entryText };
64260
+ const unlisted = { errors: 0, warnings: 0 };
64261
+ const edit = { changed, codeEdited };
64262
+ for (const { code, blockKey, count, varies, refused: isRefused } of [
64263
+ ...compiled.omitted.map((omitted) => {
64264
+ const finding = {
64265
+ code: omitted.code,
64266
+ severity: "warning",
64267
+ ...omitted.blockKey !== undefined ? { blockKey: omitted.blockKey } : {},
64268
+ ...omitted.param !== undefined ? { param: omitted.param } : {}
64269
+ };
64270
+ const varies = variesByDeployment(finding);
64271
+ return {
64272
+ ...omitted,
64273
+ varies,
64274
+ refused: !varies && omitted.file !== undefined && refusesEdited({ ...finding, span: { file: omitted.file } }, edit)
64275
+ };
64276
+ }),
64277
+ ...compiled.withheld.filter((finding) => !refusable(finding) || !refusesEdited(finding, edit)).map((finding) => ({
64278
+ code: finding.code,
64279
+ blockKey: finding.blockKey,
64280
+ count: 1,
64281
+ varies: variesByDeployment(finding),
64282
+ refused: false
64283
+ }))
64284
+ ]) {
64285
+ if (!reported(code, blockKey))
64286
+ continue;
64287
+ if (isRefused || !varies && fails(code, blockKey))
64288
+ unlisted.errors += count;
64289
+ else
64290
+ unlisted.warnings += count;
64291
+ }
64292
+ return { findings, entry: entryText, unlisted };
64128
64293
  }
64129
64294
  function reportCheck(output, findings, result, options = {}) {
64130
64295
  const shown = findingsOutput(output, options.verbose);
64131
64296
  const listed = boundAnswerFindings(findings, options.bound);
64132
64297
  shown.print(listed);
64133
- const errors = findings.filter((finding) => finding.severity === "error").length;
64298
+ const unlisted = options.unlisted ?? { errors: 0, warnings: 0 };
64299
+ const errors = findings.filter((finding) => finding.severity === "error").length + unlisted.errors;
64134
64300
  if (errors > 0)
64135
64301
  setSoftExitCode(1);
64136
64302
  printProtocolResult(output, {
64137
64303
  checked: "compile",
64138
64304
  errors,
64139
- warnings: findings.filter((finding) => finding.severity === "warning").length,
64305
+ warnings: findings.filter((finding) => finding.severity === "warning").length + unlisted.warnings,
64140
64306
  ...result,
64141
64307
  ...shown.result(listed)
64142
64308
  });
@@ -64180,7 +64346,7 @@ function attachWorkflowSourceCheck(source) {
64180
64346
  ...await readWorkspaceDeclarations(workspace.root),
64181
64347
  workflowInputs: await workspaceWorkflowInputs(workspace.root, catalog)
64182
64348
  } : undefined;
64183
- const { findings, entry } = await checkWorkflowDir(options.dir, catalog, {
64349
+ const { findings, entry, unlisted } = await checkWorkflowDir(options.dir, catalog, {
64184
64350
  strict: strictMode(options),
64185
64351
  ...declarations ? { declarations } : {}
64186
64352
  });
@@ -64191,7 +64357,8 @@ function attachWorkflowSourceCheck(source) {
64191
64357
  await refreshTsconfigs(options.dir, workspaceId, WORKFLOW_TREE, { sources: [entry] }, { incremental: true });
64192
64358
  }
64193
64359
  reportCheck(profile.output, findings, { catalogHash: catalog.hash }, {
64194
- verbose: options.verbose === true
64360
+ verbose: options.verbose === true,
64361
+ unlisted
64195
64362
  });
64196
64363
  });
64197
64364
  }
@@ -65030,6 +65197,9 @@ function printStatusReport(format, heading, report, planLine, findings) {
65030
65197
  } else {
65031
65198
  lines.push(s.yellow(`Server not checked${report.note ? `: ${sanitize(report.note)}` : "."}`));
65032
65199
  }
65200
+ if (report.unnamed?.length) {
65201
+ lines.push(s.dim(`Not named by any codeFile(), so applying never sends ${report.unnamed.length === 1 ? "it" : "them"}: ${sanitize(report.unnamed.join(", "))}`));
65202
+ }
65033
65203
  if (report.server === "checked" && report.note)
65034
65204
  lines.push(s.dim(sanitize(report.note)));
65035
65205
  if (report.plan)
@@ -65197,23 +65367,25 @@ async function readLocalWorkflow(dir) {
65197
65367
  const base = await readBase(dir, undefined);
65198
65368
  const { workflowId } = base;
65199
65369
  const written = await readFolderWritten(dir);
65200
- const paths = [
65201
- SOURCE_ENTRY_FILE,
65202
- ...(await listSourceFiles(dir, SOURCE_CODE_DIR)).filter((path) => !path.split("/").some((segment) => segment.startsWith(".")))
65203
- ];
65204
- const texts = {};
65205
- for (const path of paths) {
65370
+ const entry = await readSourceText(dir, SOURCE_ENTRY_FILE);
65371
+ const sent = new Set(codeFilePaths(entry, await readPreviousLock(dir)));
65372
+ const listed = (await listSourceFiles(dir, SOURCE_CODE_DIR)).filter((path) => !path.split("/").some((segment) => segment.startsWith(".")));
65373
+ const texts = entry === null ? {} : { [SOURCE_ENTRY_FILE]: entry };
65374
+ for (const path of listed.filter((each) => sent.has(each))) {
65206
65375
  const text = await readSourceText(dir, path);
65207
65376
  if (text !== null)
65208
65377
  texts[path] = text;
65209
65378
  }
65210
65379
  const current = Object.fromEntries(Object.entries(texts).map(([path, text]) => [path, digest(text)]));
65380
+ const unnamed = listed.filter((path) => !sent.has(path));
65381
+ const ignored = new Set(unnamed);
65211
65382
  return {
65212
65383
  base,
65213
65384
  workflowId,
65214
65385
  written,
65215
65386
  texts,
65216
- changed: changedFiles(current, written.digests, () => true)
65387
+ changed: changedFiles(current, written.digests, (path) => !ignored.has(path)),
65388
+ unnamed
65217
65389
  };
65218
65390
  }
65219
65391
  function workflowPlanFindings(data) {
@@ -65296,13 +65468,14 @@ function attachWorkflowSourceStatus(source) {
65296
65468
  }
65297
65469
  }
65298
65470
  const status = sourceStatus(locals, serverChanges);
65299
- const plan = data ? planSummary(data) : null;
65471
+ const plan = data && serverChanges.length === 0 ? planSummary(data) : null;
65300
65472
  const report = {
65301
65473
  workflowId,
65302
65474
  dir: options.dir,
65303
65475
  server,
65304
65476
  ...note ? { note } : {},
65305
65477
  ...status,
65478
+ ...local.unnamed.length > 0 ? { unnamed: local.unnamed } : {},
65306
65479
  plan,
65307
65480
  next: nextStep(status, {
65308
65481
  prefix: PREFIX,
@@ -65505,15 +65678,22 @@ function promotionSubmission(input) {
65505
65678
  if (lock !== undefined)
65506
65679
  files[lockPath] = lock;
65507
65680
  }
65681
+ const targetOnly = [];
65508
65682
  const resources = Object.fromEntries(Object.entries(input.target.base.resources).flatMap(([address, live]) => {
65509
65683
  const parsed = parseResourceAddress(address);
65510
65684
  if (!parsed)
65511
65685
  return [];
65512
65686
  const keys = declared.get(parsed.kind);
65513
- if (keys === undefined || !(input.allowDelete || keys.has(parsed.key)))
65687
+ if (keys === undefined)
65514
65688
  return [];
65515
65689
  const recorded = input.record?.resources[resourceAddress(parsed.kind, parsed.key)];
65516
- return [[address, recorded?.id === live.id ? recorded : live]];
65690
+ const promoted = recorded?.id === live.id ? recorded : undefined;
65691
+ if (!keys.has(parsed.key) && !promoted) {
65692
+ targetOnly.push(resourceAddress(parsed.kind, parsed.key));
65693
+ if (!input.deleteTargetOnly)
65694
+ return [];
65695
+ }
65696
+ return [[address, promoted ?? live]];
65517
65697
  }));
65518
65698
  for (const [address, recorded] of Object.entries(input.record?.resources ?? {})) {
65519
65699
  if (Object.hasOwn(input.target.base.resources, address))
@@ -65528,7 +65708,8 @@ function promotionSubmission(input) {
65528
65708
  return {
65529
65709
  files,
65530
65710
  base: { ...input.target.base, resources },
65531
- deletedInTarget: [...new Set(deletedInTarget)].sort(compareStrings)
65711
+ deletedInTarget: [...new Set(deletedInTarget)].sort(compareStrings),
65712
+ targetOnly: targetOnly.sort(compareStrings)
65532
65713
  };
65533
65714
  }
65534
65715
  function promotionRecord(input) {
@@ -65540,7 +65721,13 @@ function promotionRecord(input) {
65540
65721
  resources[resourceAddress(parsed.kind, parsed.key)] = entry;
65541
65722
  }
65542
65723
  }
65543
- Object.assign(resources, input.applied.base.resources);
65724
+ const targetOnly = new Set(input.submission.targetOnly);
65725
+ for (const [address, entry] of Object.entries(input.applied.base.resources)) {
65726
+ const parsed = parseResourceAddress(address);
65727
+ if (parsed && !targetOnly.has(address)) {
65728
+ resources[resourceAddress(parsed.kind, parsed.key)] = entry;
65729
+ }
65730
+ }
65544
65731
  const workflows = {};
65545
65732
  if (!managed.has("workflow")) {
65546
65733
  Object.assign(workflows, input.previous?.workflows);
@@ -65596,6 +65783,10 @@ function outcomeText(change, outcome) {
65596
65783
  function printPlan(plan, diagnostics, outcome) {
65597
65784
  const drifted = new Map(serverResourceChanges(diagnostics).filter((change) => change.server !== "added").map((change) => [`${change.kind}:${change.key}`, change.server]));
65598
65785
  const driftOf = (change) => change.action === "noop" ? drifted.get(`${change.kind}:${change.key}`) : undefined;
65786
+ const addressesOf = (code) => new Set(diagnostics.filter((finding) => finding.code === code).map((finding) => `${finding.kind}:${finding.key}`));
65787
+ const stale = addressesOf("E_APPLY_STALE");
65788
+ const deleteRefused = addressesOf("E_APPLY_DELETE_NOT_ALLOWED");
65789
+ const refusedDelete = (change) => change.action === "noop" && deleteRefused.has(`${change.kind}:${change.key}`);
65599
65790
  for (const kind of APPLY_ORDER) {
65600
65791
  const changes = plan.filter((change) => change.kind === kind);
65601
65792
  if (changes.length === 0)
@@ -65603,14 +65794,19 @@ function printPlan(plan, diagnostics, outcome) {
65603
65794
  const counts = new Map;
65604
65795
  for (const change of changes) {
65605
65796
  const drift = driftOf(change);
65606
- const label = drift ? `${drift} on the server` : change.action === "noop" ? "unchanged" : change.action;
65797
+ const label = drift ? `${drift} on the server` : refusedDelete(change) ? "delete refused" : change.action === "noop" ? "unchanged" : change.action;
65607
65798
  counts.set(label, (counts.get(label) ?? 0) + 1);
65608
65799
  }
65609
65800
  printError(`${KIND_DIRS[kind]}: ${[...counts].map(([label, count]) => `${count} ${label}`).join(", ")}`);
65610
65801
  for (const change of changes) {
65611
65802
  const drift = driftOf(change);
65612
65803
  if (drift) {
65613
- printError(` ! ${change.key} (${drift} on the server; kept as the server has it)`);
65804
+ const fate = stale.has(`${change.kind}:${change.key}`) ? "your edit is refused as stale" : "kept as the server has it";
65805
+ printError(` ! ${change.key} (${drift} on the server; ${fate})`);
65806
+ continue;
65807
+ }
65808
+ if (refusedDelete(change)) {
65809
+ printError(` - ${change.key} — refused, needs --allow-delete`);
65614
65810
  continue;
65615
65811
  }
65616
65812
  if (change.action === "noop")
@@ -65641,7 +65837,7 @@ function missingBlobPaths(error) {
65641
65837
  return errors.flatMap((finding) => typeof finding.file === "string" ? [finding.file] : []);
65642
65838
  }
65643
65839
  var WORKFLOW_LOCK_PATH = new RegExp(`^${KIND_DIRS.workflow}/([^/]+)/${SOURCE_LOCK_FILE.replaceAll(".", "\\.")}$`);
65644
- async function orphanedWorkflowFiles(dir, files) {
65840
+ async function orphanedWorkflowFiles(dir, files, recorded) {
65645
65841
  const filesByFolder = new Map;
65646
65842
  for (const path of Object.keys(files)) {
65647
65843
  if (!path.startsWith(`${KIND_DIRS.workflow}/`))
@@ -65668,7 +65864,8 @@ async function orphanedWorkflowFiles(dir, files) {
65668
65864
  if (!isRecordLike(next) || !isRecordLike(next.blocks))
65669
65865
  continue;
65670
65866
  const previous = await readSourceJson(dir, path);
65671
- orphaned.push(...orphanedCodeFiles(previous, next, written).map((file) => `${folder}/${file}`));
65867
+ const inFolder = Object.fromEntries(Object.entries(recorded).flatMap(([recordedPath, sha]) => recordedPath.startsWith(`${folder}/`) ? [[recordedPath.slice(folder.length + 1), sha]] : []));
65868
+ orphaned.push(...orphanedCodeFiles(previous, next, written, inFolder).map((file) => `${folder}/${file}`));
65672
65869
  }
65673
65870
  return orphaned;
65674
65871
  }
@@ -65721,7 +65918,7 @@ function droppedResourceFiles(sent, reprinted) {
65721
65918
  async function saveApplied(dir, data, submission, written, records) {
65722
65919
  assertWorkspacePaths(Object.keys(data.files));
65723
65920
  const orphaned = [
65724
- ...await orphanedWorkflowFiles(dir, data.files),
65921
+ ...await orphanedWorkflowFiles(dir, data.files, written.digests),
65725
65922
  ...droppedResourceFiles(submission.files, data.files)
65726
65923
  ];
65727
65924
  const kept = { ...written.digests, ...appliedBlobDigests(submission, data.base) };
@@ -65746,7 +65943,7 @@ function baseWorkflowOf(base) {
65746
65943
  function baseWorkspaceOf(base) {
65747
65944
  return isRecordLike(base) && typeof base.workspaceId === "string" ? base.workspaceId : null;
65748
65945
  }
65749
- async function promoted(client, dir, submission, target, allowDelete) {
65946
+ async function promoted(client, dir, submission, target, deleteTargetOnly) {
65750
65947
  if (baseWorkspaceOf(submission.base) === target) {
65751
65948
  throw new SourceDirError(`${dir} was read from workspace ${target}; apply it without --to.`, {
65752
65949
  code: "SOURCE_PROMOTE_SAME_WORKSPACE"
@@ -65768,14 +65965,15 @@ async function promoted(client, dir, submission, target, allowDelete) {
65768
65965
  kinds: submission.kinds,
65769
65966
  target: { files: data.files, base: targetBase },
65770
65967
  record,
65771
- allowDelete
65968
+ deleteTargetOnly
65772
65969
  });
65773
65970
  return {
65774
65971
  submission: { ...submission, files: composed.files, base: composed.base },
65775
65972
  files: submission.files,
65776
65973
  record,
65777
65974
  target,
65778
- deletedInTarget: composed.deletedInTarget
65975
+ deletedInTarget: composed.deletedInTarget,
65976
+ targetOnly: composed.targetOnly
65779
65977
  };
65780
65978
  }
65781
65979
  async function savePromotion(dir, target, promotion, data) {
@@ -65790,7 +65988,8 @@ async function savePromotion(dir, target, promotion, data) {
65790
65988
  files: promotion.files,
65791
65989
  submission: {
65792
65990
  files: promotion.submission.files,
65793
- base: parseWorkspaceBase(promotion.submission.base).base ?? base
65991
+ base: parseWorkspaceBase(promotion.submission.base).base ?? base,
65992
+ targetOnly: promotion.targetOnly
65794
65993
  },
65795
65994
  applied: { base, files: data.files, plan: data.plan }
65796
65995
  });
@@ -65800,23 +65999,33 @@ async function savePromotion(dir, target, promotion, data) {
65800
65999
  function resourceWhere(kind, key) {
65801
66000
  return isFileKind(kind) ? `${KIND_DIRS[kind]} ${key}` : `${KIND_DIRS[kind]}/${key}`;
65802
66001
  }
65803
- function promotionHint(code, target) {
66002
+ function promotionHint(code, target, targetOnly) {
65804
66003
  const record = promotionRecordPath(target) ?? ".sim/targets/<workspaceId>.json";
65805
66004
  if (code === "E_APPLY_STALE") {
65806
- return `Workspace ${target} changed this resource since the last promotion from this directory. Carry that change into the directory, or undo it in ${target}, then promote again; to take ${target} as it stands now, delete ${record} first.`;
66005
+ 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.`;
66006
+ }
66007
+ if (code === "W_SERVER_CHANGED") {
66008
+ 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.`;
66009
+ }
66010
+ if (code === "E_APPLY_DELETE_NOT_ALLOWED") {
66011
+ 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.`;
66012
+ }
66013
+ if (code === "W_UNDECLARED" && targetOnly) {
66014
+ return `Only workspace ${target} holds it: this directory does not declare it and no promotion from it left it there, so the promotion keeps it, with or without --allow-delete. To delete it there, add --delete-target-only beside --allow-delete; to manage it from this directory, declare it here.`;
65807
66015
  }
65808
66016
  if (code === "E_APPLY_NO_BASE") {
65809
66017
  return `Workspace ${target} holds this resource, but no promotion from this directory recorded it. Rename the declaration, or rename or delete the resource in ${target}, then promote again.`;
65810
66018
  }
65811
66019
  return;
65812
66020
  }
65813
- function withPromotionHint(finding, code, target) {
65814
- const hint = promotionHint(code, target);
66021
+ function withPromotionHint(finding, code, promotion) {
66022
+ const targetOnly = promotion.targetOnly.includes(`${finding.kind}:${finding.key}`);
66023
+ const hint = promotionHint(code, promotion.target, targetOnly);
65815
66024
  return hint === undefined ? finding : { ...finding, hint };
65816
66025
  }
65817
66026
  function promotionDiagnostics(diagnostics, promotion) {
65818
66027
  const warned = new Set(promotion.deletedInTarget);
65819
- return diagnostics.flatMap((finding) => finding.code === "W_SERVER_DELETED" && warned.has(`${finding.kind}:${finding.key}`) ? [] : [withPromotionHint(finding, finding.code, promotion.target)]);
66028
+ return diagnostics.flatMap((finding) => finding.code === "W_SERVER_DELETED" && warned.has(`${finding.kind}:${finding.key}`) ? [] : [withPromotionHint(finding, finding.code, promotion)]);
65820
66029
  }
65821
66030
  function promotionWarnings(promotion, outcome) {
65822
66031
  const { target } = promotion;
@@ -65835,11 +66044,12 @@ function promotionWarnings(promotion, outcome) {
65835
66044
  }
65836
66045
  ];
65837
66046
  });
65838
- const targetOnly = outcome.plan.filter((change) => change.action === "delete" && (!outcome.failed || wasWritten(change, outcome))).map((change) => ({
66047
+ const onlyInTarget = new Set(promotion.targetOnly);
66048
+ const targetOnly = outcome.plan.filter((change) => change.action === "delete" && onlyInTarget.has(`${change.kind}:${change.key}`) && (!outcome.failed || wasWritten(change, outcome))).map((change) => ({
65839
66049
  code: "W_PROMOTE_DELETES_TARGET_ONLY",
65840
66050
  severity: "warning",
65841
- message: `${resourceWhere(change.kind, change.key)} is only in workspace ${target}, not in this directory, so --allow-delete deletes it there.`,
65842
- hint: "Promote without --allow-delete to keep it, or declare it in this directory.",
66051
+ message: `${resourceWhere(change.kind, change.key)} is only in workspace ${target}, not in this directory, so --delete-target-only deletes it there.`,
66052
+ hint: "Promote without --delete-target-only to keep it, or declare it in this directory.",
65843
66053
  kind: change.kind,
65844
66054
  key: change.key
65845
66055
  }));
@@ -65853,7 +66063,7 @@ function rehinted(refusal, promotion) {
65853
66063
  return refusal;
65854
66064
  const details = {
65855
66065
  ...refusal.details,
65856
- diagnostics: diagnostics.map((finding) => isRecordLike(finding) && typeof finding.code === "string" ? withPromotionHint(finding, finding.code, promotion.target) : finding)
66066
+ diagnostics: diagnostics.map((finding) => isRecordLike(finding) && typeof finding.code === "string" ? withPromotionHint(finding, finding.code, promotion) : finding)
65857
66067
  };
65858
66068
  const copy = new SimApiError(refusal.message, refusal.status, refusal.code, details, refusal.exitCode, refusal.requestId);
65859
66069
  copy.retryAfterMs = refusal.retryAfterMs;
@@ -65874,7 +66084,8 @@ function attachWorkspaceSourceApply(source) {
65874
66084
  "copy every workflow from a dev workspace into a prod workspace (--to)",
65875
66085
  "save bulk edits to every workflow"
65876
66086
  ]);
65877
- command.option("--dir <dir>", "Workspace source directory written by `workspaces source get`", ".").option("--dry-run", "Plan and check without writing anything").option("-y, --yes", "Apply without asking for confirmation").option("--allow-delete", "Delete resources, columns and data the directory no longer declares").option("--only <kinds>", `Apply only these kinds (${ONLY_KINDS_HELP})`).option("--to <workspaceId>", "Promote the directory to another workspace (dev to prod): its resources bind by key to that workspace's own and are updated in place. Only .sim/targets/<workspaceId>.json changes, the record the next promotion compares with: a resource changed there since is kept, or refused as stale (exit 5) when the directory changed it too").allowExcessArguments(false).description("Apply a workspace source directory").addHelpText("after", `${sourceExitCodesHelp("workspaces source apply")}${SOURCE_WRITE_EXIT_CODES_HELP}`).action(async (options) => {
66087
+ 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) => {
66088
+ assertTargetOnlyDeletable(options);
65878
66089
  const mode = writeMode(options);
65879
66090
  const only = parseKinds(options.only);
65880
66091
  const { client, profile } = connect();
@@ -65941,7 +66152,7 @@ function attachWorkspaceSourceApply(source) {
65941
66152
  await assertWorkspaceDir(options.dir);
65942
66153
  }
65943
66154
  assertBlobsFetched(options.dir, read, written.digests);
65944
- promotion = options.to ? await promoted(client, options.dir, read, options.to, options.allowDelete === true) : null;
66155
+ promotion = options.to ? await promoted(client, options.dir, read, options.to, options.deleteTargetOnly === true) : null;
65945
66156
  const submission = promotion?.submission ?? read;
65946
66157
  const reported = (data) => promotion ? {
65947
66158
  ...data,
@@ -66019,9 +66230,20 @@ function applyCommand(options) {
66019
66230
  `sim workspaces source apply --dir ${shellWord(options.dir)}`,
66020
66231
  ...options.only ? [`--only ${shellWord(options.only)}`] : [],
66021
66232
  ...options.to ? [`--to ${shellWord(options.to)}`] : [],
66022
- ...options.allowDelete ? ["--allow-delete"] : []
66233
+ ...options.allowDelete ? ["--allow-delete"] : [],
66234
+ ...options.deleteTargetOnly ? ["--delete-target-only"] : []
66023
66235
  ].join(" ");
66024
66236
  }
66237
+ function assertTargetOnlyDeletable(options) {
66238
+ if (!options.deleteTargetOnly)
66239
+ return;
66240
+ if (!options.to) {
66241
+ throw new CliUsageError("--delete-target-only deletes a promotion target's own resources: it needs --to <workspaceId>.");
66242
+ }
66243
+ if (!options.allowDelete) {
66244
+ 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.");
66245
+ }
66246
+ }
66025
66247
  function notSentFindings(paths) {
66026
66248
  return paths.map((path) => ({
66027
66249
  code: "W_PATH_NOT_SENT",
@@ -66115,6 +66337,7 @@ ${SOURCE_DIR_BUSY_HELP}`).action(async (options, command) => {
66115
66337
  };
66116
66338
  const keys = await workspaceWorkflowKeys(options.dir);
66117
66339
  const findings = [];
66340
+ const unlisted = { errors: 0, warnings: 0 };
66118
66341
  for (const key of keys) {
66119
66342
  const checked = await checkWorkflowDir(join12(options.dir, KIND_DIRS.workflow, key), catalog, {
66120
66343
  declarations,
@@ -66122,6 +66345,8 @@ ${SOURCE_DIR_BUSY_HELP}`).action(async (options, command) => {
66122
66345
  prefix: `${KIND_DIRS.workflow}/${key}/`
66123
66346
  });
66124
66347
  findings.push(...checked.findings);
66348
+ unlisted.errors += checked.unlisted.errors;
66349
+ unlisted.warnings += checked.unlisted.warnings;
66125
66350
  }
66126
66351
  for (const {
66127
66352
  code,
@@ -66144,7 +66369,7 @@ ${SOURCE_DIR_BUSY_HELP}`).action(async (options, command) => {
66144
66369
  }
66145
66370
  await refreshWorkspaceTypes(options.dir, withWorkflowInputs(declarations.local, workflowInputs));
66146
66371
  await refreshWorkspaceTsconfigs(options.dir, workspaceId);
66147
- reportCheck(profile.output, findings, { workflows: keys.length, catalogHash: catalog.hash }, { verbose: options.verbose === true, bound: WORKSPACE_ANSWER_BOUND });
66372
+ reportCheck(profile.output, findings, { workflows: keys.length, catalogHash: catalog.hash }, { verbose: options.verbose === true, bound: WORKSPACE_ANSWER_BOUND, unlisted });
66148
66373
  });
66149
66374
  });
66150
66375
  }
@@ -66320,6 +66545,9 @@ function attachWorkspaceSourceGet(source) {
66320
66545
  const result = await writeWorkspaceSource(client, options.dir, data, options.force === true);
66321
66546
  const findings = findingsOutput(profile.output);
66322
66547
  findings.print(data.diagnostics);
66548
+ for (const { kind, key, reason } of data.skipped) {
66549
+ 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).`);
66550
+ }
66323
66551
  printTreeResult(profile.output, {
66324
66552
  workspaceId: data.workspaceId,
66325
66553
  dir: options.dir,
@@ -66353,9 +66581,10 @@ async function readLocalWorkspace(dir, only) {
66353
66581
  current[path] = digest(text);
66354
66582
  for (const blob of submission.blobs)
66355
66583
  current[blob.path] = blob.sha256;
66584
+ const unnamed = new Set(submission.unnamed);
66356
66585
  const changed = changedFiles(current, written.digests, (path) => {
66357
66586
  const kind = kindOfPath(path);
66358
- return kind !== null && (!only || only.includes(kind));
66587
+ return kind !== null && (!only || only.includes(kind)) && !unnamed.has(path);
66359
66588
  });
66360
66589
  return { submission, written, changed, readFrom };
66361
66590
  }
@@ -66508,6 +66737,7 @@ ${SOURCE_DIR_BUSY_HELP}`).action(async (options, invoked) => {
66508
66737
  server,
66509
66738
  ...note ? { note } : {},
66510
66739
  ...status,
66740
+ ...local.submission.unnamed.length > 0 ? { unnamed: local.submission.unnamed } : {},
66511
66741
  plan,
66512
66742
  next: (login ? null : unmanagedNext(status, local.submission.kinds, options.dir, workspaceScope)) ?? nextStep(status, {
66513
66743
  prefix: PREFIX2,