@tenonhq/dovetail-servicenow 0.0.53 → 0.0.55

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -675,6 +675,40 @@ adds diagnostics (app-switch status, resolved column key, assigned sys_id) to th
675
675
  result note. Ground truth (the HAR dissection) lives in the CTO repo's create-table
676
676
  docs.
677
677
 
678
+ ### Dictionary attributes (`sys_dictionary.attributes`) and the reference-column rule
679
+
680
+ **Team rule (2026-10-08): every reference column carries `readonly_clickthrough=true`.**
681
+ `add-column` and `create-table` apply it by default to every `reference` column; any
682
+ other attributes you need ride alongside it.
683
+
684
+ ```bash
685
+ # default — the column is created with readonly_clickthrough=true, verified on read-back
686
+ npx dove-sn add-column --table x_cadso_journey --label Owner --type reference --reference sys_user --update-set <sys_id>
687
+ # more attributes (merged with the default) / opt out of the default
688
+ npx dove-sn add-column ... --attributes "ref_auto_completer=AJAXTableCompleter,ref_ac_columns=name;email"
689
+ npx dove-sn add-column ... --no-readonly-clickthrough
690
+ # fix an EXISTING column — MERGED into its current attributes, never overwriting them
691
+ npx dove-sn set-column --table x_cadso_automate_email_batch --column x_cadso_journey_instance_step \
692
+ --attributes readonly_clickthrough=true --update-set <sys_id>
693
+ # read-only audit: which reference columns lack it
694
+ npx dove-sn reference-attr-audit --scope-prefix x_cadso_ --json
695
+ ```
696
+
697
+ - **Format.** `--attributes` (MCP `attributes`) is `"k=v,k2=v2"` or, in JSON/MCP, a
698
+ `{ key: value }` map. Keys are identifiers; a value may not contain `,` (the separator).
699
+ - **Merge, never clobber.** `set-column` sets the named keys and keeps every other
700
+ attribute the column carries. A column that already has them reports `unchanged`.
701
+ - **Verified.** add-column reads `attributes` back; if the insert dropped a key it patches
702
+ once (as a merge) and re-reads — still missing is `failed` (exit 2). create-table reads
703
+ every column with attributes back after the form save (`columnAttributes` on the
704
+ result) and merge-patches into `--update-set` the same way. set-column verifies each
705
+ requested key order-insensitively.
706
+ - **Opt-out / override.** `--no-readonly-clickthrough` (create-table: table-wide;
707
+ per column `readonly_clickthrough: false` in `--from-json`), or set
708
+ `readonly_clickthrough=false` in `attributes` — the caller's value wins.
709
+ - **Inherited columns** are refused by `set-column --attributes` for now (a per-child
710
+ `sys_dictionary_override` for attributes has not been verified live).
711
+
678
712
  ### Add a unique index
679
713
 
680
714
  Create a **single-column UNIQUE index** on an existing table, then read it back.
@@ -879,12 +913,43 @@ switches the executing user's app scope + update set server-side, inserts, and
879
913
  restores both — so the record is owned by the right app and the insert is captured
880
914
  in the right update set. Like `set-field` it **refuses** schema tables and verifies
881
915
  via read-back. It also **refuses** `sys_update_set` — the op cannot set an update
882
- set's application, so create sets with `dove createUpdateSet` instead. `--scope` and `--update-set` are required; `--if-absent
916
+ set's application, so create sets with `dove createUpdateSet` instead. `--scope` and `--update-set` are required. `--scope` takes a scope name or a
917
+ `sys_scope` sys_id. Every global-scope app (e.g. the Dovetail app) has the scope name
918
+ `global`, which always means the Global scope itself, so reach a specific global app by its
919
+ sys_id. The server answers an unknown scope with 404, and a name shared by several apps with
920
+ 409, instead of falling back to your session scope; the record gets both `sys_scope` and
921
+ `sys_package`. `--if-absent
883
922
  "<encoded-query>"` makes re-runs idempotent (the insert is skipped when the query
884
923
  already matches a row). Exit codes: `0` created / skipped-in-sync / dry-run, `1` bad
885
924
  args, `2` write landed unverified (or skipped with drift). To **update** an existing
886
925
  record instead, use `set-field`.
887
926
 
927
+ #### Session domain (`--domain`, domain-separated instances)
928
+
929
+ `set-field`, `create-record`, `add-choices` and `remove-choices` (and their MCP tools
930
+ `set_field`, `create_record`, `add_choices_to_field`, `remove_choices_from_field`, as
931
+ `domain`) take `--domain <global|domain sys_id>`, **default `global`**. It is the session
932
+ domain the server op runs the write in. On a domain-separated instance the API user's
933
+ session starts in its own domain (`sys_user.sys_domain`), and that domain decides two
934
+ things the HTTP response never mentions:
935
+
936
+ - **Insert** — the new row is stamped with the session domain. A `sys_domain` in the
937
+ payload does not override it. (`create-record` without `--domain` uses the payload's
938
+ `sys_domain` as the session domain; both given and different is refused.)
939
+ - **Update of a process record** (`sys_script`, `sys_choice`, ...) that lives in a domain
940
+ *above* the session's — the platform does **not** edit it. It creates a domain
941
+ **override**: a new row in the session domain whose `sys_overrides` points at the
942
+ original, which stays unchanged.
943
+
944
+ The server op switches the session domain before the write and restores it afterwards,
945
+ and echoes `domain: { requested, applied, previous }`. It fails closed (nothing written)
946
+ if the switch does not take. Every verb then reads back **across domains**
947
+ (`sysparm_query_no_domain=true`) and reports `failed` / exits `2` with
948
+ `DOMAIN CHECK FAILED` when the record's `sys_domain` is not the expected one or a new
949
+ override row appeared. If the instance's op predates domain selection (no echo), the
950
+ message says so — deploy `servicenow/dovetail/sys_ws_operation/{pushWithUpdateSet,createRecord}.js`
951
+ to the Dovetail Core definition. Tables without `sys_domain` skip every domain check.
952
+
888
953
  #### Field sources (`--fields`, `--from-json`, `--from-stdin`)
889
954
 
890
955
  Both verbs take their field map from any combination of three sources; on a shared
@@ -1261,7 +1326,9 @@ record — dry-run by default, `confirm:true` to apply, `updateSetSysId` require
1261
1326
  record read back before AND after so success is only reported once it is confirmed
1262
1327
  gone) — all read-back-verified; `set_field` / `create_record` are captured in the
1263
1328
  update set you pass, while `delete_record` pins the set as current and reads the DELETE
1264
- capture back (`captureState`) until [#297](https://github.com/TenonHQ/Dovetail/issues/297) ships — `host_assets` (deploy a built
1329
+ capture back (`captureState`) until [#297](https://github.com/TenonHQ/Dovetail/issues/297) ships — `reference_attr_audit` (read-only: reference columns under a table-name prefix
1330
+ missing `readonly_clickthrough=true`; `add_column` / `create_table` columns and
1331
+ `set_column` also take `attributes` — see "Dictionary attributes"), `host_assets` (deploy a built
1265
1332
  dist/), plus the Flow Designer
1266
1333
  tools `flow_view` (read a flow/subflow's step graph), `action_view` (read an action
1267
1334
  type's model), `action_edit` (structurally edit a published action type — per-step
package/dist/choices.js CHANGED
@@ -13,6 +13,7 @@ exports.ChoiceWriteError = void 0;
13
13
  exports.encodeQueryValue = encodeQueryValue;
14
14
  exports.addChoicesToField = addChoicesToField;
15
15
  exports.removeChoicesFromField = removeChoicesFromField;
16
+ const domain_1 = require("./domain");
16
17
  /**
17
18
  * Thrown when a choices write fails partway through the value loop.
18
19
  *
@@ -282,6 +283,35 @@ function buildChoiceFields(table, column, choice, scope) {
282
283
  }
283
284
  return fields;
284
285
  }
286
+ /** Normalise params.domain, naming the verb in the error. */
287
+ function resolveVerbDomain(verb, domain) {
288
+ try {
289
+ return (0, domain_1.normalizeDomain)(domain);
290
+ }
291
+ catch (e) {
292
+ throw new Error(verb + ": " + (e instanceof Error ? e.message : String(e)));
293
+ }
294
+ }
295
+ /** Snapshot of the overrides that already point at the rows a run will update. */
296
+ async function overrideBaseline(client, existing, toUpdate) {
297
+ var supported = existing.length > 0 &&
298
+ (0, domain_1.rowSupportsOverrides)(existing[0]);
299
+ if (!supported || toUpdate.length === 0) {
300
+ return { supported: supported, before: [] };
301
+ }
302
+ return {
303
+ supported: true,
304
+ before: await (0, domain_1.findOverrides)(client, "sys_choice", toUpdate),
305
+ };
306
+ }
307
+ function noWriteDomainCheck(domain) {
308
+ return {
309
+ requested: domain,
310
+ serverAcknowledged: true,
311
+ overridesCreated: [],
312
+ problems: [],
313
+ };
314
+ }
285
315
  function isUnchanged(existing, choice) {
286
316
  var sameLabel = existing.label === choice.label;
287
317
  var sameLang = (existing.language || "en") === (choice.language || "en");
@@ -310,6 +340,10 @@ async function addChoicesToField(client, params) {
310
340
  // Strict equality on purpose: a truthy-but-not-true value (the string "false" from a
311
341
  // mis-parsed flag, say) must not silently turn a planned run into a live write.
312
342
  var dryRun = params.dryRun === true;
343
+ var domain = resolveVerbDomain("add-choices", params.domain);
344
+ var acknowledged = true;
345
+ var createdIds = [];
346
+ var updatedIds = [];
313
347
  var dict = await fetchDictionary(client, params.table, params.column);
314
348
  var updateSet = await fetchUpdateSet(client, params.updateSetSysId);
315
349
  var scopeName = await resolveScopeName(client, dict.sys_scope);
@@ -322,12 +356,14 @@ async function addChoicesToField(client, params) {
322
356
  var choiceNow = choiceWas;
323
357
  if (params.choiceType !== null && Number(dict.choice) !== targetChoiceType) {
324
358
  if (!dryRun) {
325
- await client.claude.pushWithUpdateSet({
359
+ var dictResp = await client.claude.pushWithUpdateSet({
326
360
  update_set_sys_id: params.updateSetSysId,
327
361
  table: "sys_dictionary",
328
362
  record_sys_id: dict.sys_id,
329
363
  fields: { choice: String(targetChoiceType) },
364
+ domain: domain,
330
365
  });
366
+ acknowledged = acknowledged && (0, domain_1.readServerDomainEcho)(dictResp) !== null;
331
367
  }
332
368
  choiceNow = targetChoiceType;
333
369
  }
@@ -341,6 +377,11 @@ async function addChoicesToField(client, params) {
341
377
  return c.value;
342
378
  })));
343
379
  var existingByValue = groupExistingByKey(existing);
380
+ // Pre-write override baseline for every row this run will UPDATE, so an update the
381
+ // platform diverts into a domain override is caught on read-back.
382
+ var addBaseline = dryRun
383
+ ? { supported: false, before: [] }
384
+ : await overrideBaseline(client, existing, staleRowIds(choices, existingByValue));
344
385
  var results = [];
345
386
  for (var i = 0; i < choices.length; i += 1) {
346
387
  var choice = choices[i];
@@ -385,12 +426,15 @@ async function addChoicesToField(client, params) {
385
426
  }
386
427
  try {
387
428
  for (var s = 0; s < stale.length; s += 1) {
388
- await client.claude.pushWithUpdateSet({
429
+ var updResp = await client.claude.pushWithUpdateSet({
389
430
  update_set_sys_id: params.updateSetSysId,
390
431
  table: "sys_choice",
391
432
  record_sys_id: stale[s].sys_id,
392
433
  fields: updFields,
434
+ domain: domain,
393
435
  });
436
+ acknowledged = acknowledged && (0, domain_1.readServerDomainEcho)(updResp) !== null;
437
+ updatedIds.push(stale[s].sys_id);
394
438
  }
395
439
  }
396
440
  catch (e) {
@@ -424,11 +468,16 @@ async function addChoicesToField(client, params) {
424
468
  fields: buildChoiceFields(params.table, params.column, choice, dict.sys_scope),
425
469
  scope: scopeName,
426
470
  update_set_sys_id: params.updateSetSysId,
471
+ domain: domain,
427
472
  });
428
473
  }
429
474
  catch (e) {
430
475
  throw new ChoiceWriteError("add-choices", choice.value, results, e);
431
476
  }
477
+ acknowledged = acknowledged && (0, domain_1.readServerDomainEcho)(created) !== null;
478
+ if (created && created.sys_id) {
479
+ createdIds.push(String(created.sys_id));
480
+ }
432
481
  results.push({
433
482
  value: choice.value,
434
483
  label: choice.label,
@@ -452,8 +501,32 @@ async function addChoicesToField(client, params) {
452
501
  updateSet: { sysId: updateSet.sys_id, name: updateSet.name },
453
502
  dryRun: dryRun,
454
503
  choices: results,
504
+ domain: dryRun
505
+ ? noWriteDomainCheck(domain)
506
+ : await (0, domain_1.auditWrittenRows)({
507
+ client: client,
508
+ table: "sys_choice",
509
+ domain: domain,
510
+ createdIds: createdIds,
511
+ updatedIds: updatedIds,
512
+ overridesSupported: addBaseline.supported,
513
+ overridesBefore: addBaseline.before,
514
+ serverAcknowledged: acknowledged,
515
+ }),
455
516
  };
456
517
  }
518
+ /** sys_ids of every existing row the add pass will rewrite (mirrors the loop's stale filter). */
519
+ function staleRowIds(choices, existingByValue) {
520
+ var ids = [];
521
+ choices.forEach(function (choice) {
522
+ var key = (choice.language || "en") + "::" + choice.value;
523
+ (existingByValue[key] || []).forEach(function (row) {
524
+ if (!isUnchanged(row, choice))
525
+ ids.push(row.sys_id);
526
+ });
527
+ });
528
+ return ids;
529
+ }
457
530
  /**
458
531
  * Soft-delete choice values for a field: set `inactive=true` on each matching
459
532
  * sys_choice row via pushWithUpdateSet. NEVER a hard delete — the row stays, so the
@@ -499,6 +572,9 @@ async function removeChoicesFromField(client, params) {
499
572
  var language = params.language || "en";
500
573
  // Strict equality on purpose — see addChoicesToField.
501
574
  var dryRun = params.dryRun === true;
575
+ var domain = resolveVerbDomain("remove-choices", params.domain);
576
+ var removeAcknowledged = true;
577
+ var deactivatedIds = [];
502
578
  // fetchDictionary throws a clear error when the field does not exist; fetchUpdateSet
503
579
  // throws unless the set is in progress. Both mirror the add path's guards.
504
580
  var dict = await fetchDictionary(client, params.table, params.column);
@@ -510,6 +586,16 @@ async function removeChoicesFromField(client, params) {
510
586
  // scoped to the request rather than the whole field.
511
587
  var existing = await fetchExistingChoices(client, params.table, params.column, values);
512
588
  var existingByValue = groupExistingByKey(existing);
589
+ var toDeactivate = [];
590
+ values.forEach(function (v) {
591
+ (existingByValue[language + "::" + v] || []).forEach(function (row) {
592
+ if (row.inactive !== "true")
593
+ toDeactivate.push(row.sys_id);
594
+ });
595
+ });
596
+ var removeBaseline = dryRun
597
+ ? { supported: false, before: [] }
598
+ : await overrideBaseline(client, existing, toDeactivate);
513
599
  var results = [];
514
600
  for (var i = 0; i < values.length; i += 1) {
515
601
  var value = values[i];
@@ -558,12 +644,16 @@ async function removeChoicesFromField(client, params) {
558
644
  }
559
645
  try {
560
646
  for (var a = 0; a < active.length; a += 1) {
561
- await client.claude.pushWithUpdateSet({
647
+ var deactResp = await client.claude.pushWithUpdateSet({
562
648
  update_set_sys_id: params.updateSetSysId,
563
649
  table: "sys_choice",
564
650
  record_sys_id: active[a].sys_id,
565
651
  fields: { inactive: "true" },
652
+ domain: domain,
566
653
  });
654
+ removeAcknowledged =
655
+ removeAcknowledged && (0, domain_1.readServerDomainEcho)(deactResp) !== null;
656
+ deactivatedIds.push(active[a].sys_id);
567
657
  }
568
658
  }
569
659
  catch (e) {
@@ -587,5 +677,17 @@ async function removeChoicesFromField(client, params) {
587
677
  updateSet: { sysId: updateSet.sys_id, name: updateSet.name },
588
678
  dryRun: dryRun,
589
679
  choices: results,
680
+ domain: dryRun
681
+ ? noWriteDomainCheck(domain)
682
+ : await (0, domain_1.auditWrittenRows)({
683
+ client: client,
684
+ table: "sys_choice",
685
+ domain: domain,
686
+ createdIds: [],
687
+ updatedIds: deactivatedIds,
688
+ overridesSupported: removeBaseline.supported,
689
+ overridesBefore: removeBaseline.before,
690
+ serverAcknowledged: removeAcknowledged,
691
+ }),
590
692
  };
591
693
  }
package/dist/cli.d.ts CHANGED
@@ -28,5 +28,15 @@ interface ParsedArgs {
28
28
  positional: Array<string>;
29
29
  }
30
30
  export declare function parseArgs(argv: Array<string>): ParsedArgs;
31
+ /**
32
+ * --domain for the record-write verbs (set-field, create-record, add-choices,
33
+ * remove-choices): the session domain the write runs in. Absent → undefined, and the
34
+ * verb defaults to "global". A bare flag or a value that is neither "global" nor a
35
+ * 32-hex sys_id is refused — a typo must never silently fall back to the default.
36
+ */
37
+ export declare function domainFlag(verb: string, flags: Record<string, string>, bare: Record<string, boolean>): {
38
+ domain?: string;
39
+ error?: string;
40
+ };
31
41
  export declare function main(argv: Array<string>): Promise<number>;
32
42
  export {};
package/dist/cli.js CHANGED
@@ -47,6 +47,7 @@ var __importStar = (this && this.__importStar) || (function () {
47
47
  })();
48
48
  Object.defineProperty(exports, "__esModule", { value: true });
49
49
  exports.parseArgs = parseArgs;
50
+ exports.domainFlag = domainFlag;
50
51
  exports.main = main;
51
52
  const fs = __importStar(require("fs"));
52
53
  const path = __importStar(require("path"));
@@ -82,6 +83,7 @@ const testFlow_1 = require("./flowDesigner/testFlow");
82
83
  const table_1 = require("./table");
83
84
  const setField_1 = require("./setField");
84
85
  const createRecord_1 = require("./createRecord");
86
+ const domain_1 = require("./domain");
85
87
  const deleteRecord_1 = require("./deleteRecord");
86
88
  const invokeRest_1 = require("./invokeRest");
87
89
  const publishApp_1 = require("./publishApp");
@@ -173,6 +175,33 @@ function bareStringFlagError(verb, bare) {
173
175
  }
174
176
  return null;
175
177
  }
178
+ /**
179
+ * --domain for the record-write verbs (set-field, create-record, add-choices,
180
+ * remove-choices): the session domain the write runs in. Absent → undefined, and the
181
+ * verb defaults to "global". A bare flag or a value that is neither "global" nor a
182
+ * 32-hex sys_id is refused — a typo must never silently fall back to the default.
183
+ */
184
+ function domainFlag(verb, flags, bare) {
185
+ if (bare && bare.domain) {
186
+ return { error: verb + ": --domain needs a value (\"global\" or a domain sys_id).\n" };
187
+ }
188
+ if (!flags || flags.domain === undefined) {
189
+ return {};
190
+ }
191
+ try {
192
+ return { domain: (0, domain_1.normalizeDomain)(flags.domain) };
193
+ }
194
+ catch (e) {
195
+ return { error: verb + ": --" + (e instanceof Error ? e.message : String(e)) + "\n" };
196
+ }
197
+ }
198
+ /** Print a choices verb's domain failure (if any) and return the exit code it implies. */
199
+ function choicesDomainExit(check) {
200
+ if (!check || check.problems.length === 0)
201
+ return 0;
202
+ process.stderr.write((0, domain_1.multiRowDomainNote)(check, "pushWithUpdateSet / createRecord") + "\n");
203
+ return 2;
204
+ }
176
205
  async function runAddChoices(flags, bare) {
177
206
  // `updateSetSysId` is guarded alongside `update-set` because paramsFromFlags accepts
178
207
  // both spellings — guarding only the dashed one leaves the alias as a way in.
@@ -181,20 +210,29 @@ async function runAddChoices(flags, bare) {
181
210
  process.stderr.write(bareErr);
182
211
  return 1;
183
212
  }
213
+ var addDomain = domainFlag("add-choices", flags, bare);
214
+ if (addDomain.error) {
215
+ process.stderr.write(addDomain.error);
216
+ return 1;
217
+ }
184
218
  var params = paramsFromFlags(flags);
185
219
  // The flag is parsed for every verb; this verb used to drop it on the floor and WRITE
186
220
  // (#296). Threading it here is what makes --dry-run a real plan, not a label.
187
221
  if (flags["dry-run"] === "true") {
188
222
  params.dryRun = true;
189
223
  }
224
+ // The flag wins over a --from-json spec's own "domain".
225
+ if (addDomain.domain !== undefined) {
226
+ params.domain = addDomain.domain;
227
+ }
190
228
  var client = (0, client_1.createClient)({});
191
229
  var result = await (0, choices_1.addChoicesToField)(client, params);
192
230
  if (flags.json === "true") {
193
231
  process.stdout.write(JSON.stringify({ params: params, result: result }, null, 2) + "\n");
194
- return 0;
232
+ return choicesDomainExit(result.domain);
195
233
  }
196
234
  process.stdout.write((0, formatter_1.formatAddChoicesResult)(params.table, params.column, result) + "\n");
197
- return 0;
235
+ return choicesDomainExit(result.domain);
198
236
  }
199
237
  function removeParamsFromFlags(flags) {
200
238
  if (flags["from-json"]) {
@@ -238,18 +276,26 @@ async function runRemoveChoices(flags, bare) {
238
276
  process.stderr.write(bareErr);
239
277
  return 1;
240
278
  }
279
+ var removeDomain = domainFlag("remove-choices", flags, bare);
280
+ if (removeDomain.error) {
281
+ process.stderr.write(removeDomain.error);
282
+ return 1;
283
+ }
241
284
  var params = removeParamsFromFlags(flags);
242
285
  if (flags["dry-run"] === "true") {
243
286
  params.dryRun = true;
244
287
  }
288
+ if (removeDomain.domain !== undefined) {
289
+ params.domain = removeDomain.domain;
290
+ }
245
291
  var client = (0, client_1.createClient)({});
246
292
  var result = await (0, choices_1.removeChoicesFromField)(client, params);
247
293
  if (flags.json === "true") {
248
294
  process.stdout.write(JSON.stringify({ params: params, result: result }, null, 2) + "\n");
249
- return 0;
295
+ return choicesDomainExit(result.domain);
250
296
  }
251
297
  process.stdout.write((0, formatter_1.formatRemoveChoicesResult)(params.table, params.column, result) + "\n");
252
- return 0;
298
+ return choicesDomainExit(result.domain);
253
299
  }
254
300
  /**
255
301
  * dove-sn build-flow:
@@ -1268,7 +1314,9 @@ function parseColumnsInline(input) {
1268
1314
  * --columns "Key:string:255, Severity:choice:50, Occurence Count:integer:5"
1269
1315
  * [--extends sys_metadata] [--number-prefix ERR] [--user-role x_cadso_core.user]
1270
1316
  * [--no-acls] [--no-menu] [--update-set <sys_id>] [--save-action <sys_id>]
1271
- * [--from-json <spec.json>] [--dry-run] [--json]
1317
+ * [--no-readonly-clickthrough] [--from-json <spec.json>] [--dry-run] [--json]
1318
+ * Reference columns carry readonly_clickthrough=true by default; per-column
1319
+ * `attributes` / `readonly_clickthrough` ride on the --from-json column specs.
1272
1320
  */
1273
1321
  async function runCreateTable(flags) {
1274
1322
  var spec = {};
@@ -1285,6 +1333,16 @@ async function runCreateTable(flags) {
1285
1333
  process.stderr.write("create-table: --name, --label, --scope and --columns (or --from-json) are required\n");
1286
1334
  return 1;
1287
1335
  }
1336
+ // Table-wide opt-out of the reference default; a column that says otherwise wins.
1337
+ if (flags["no-readonly-clickthrough"] === "true") {
1338
+ columns = columns.map(function (c) {
1339
+ if (c.readonly_clickthrough !== undefined)
1340
+ return c;
1341
+ var copy = Object.assign({}, c);
1342
+ copy.readonly_clickthrough = false;
1343
+ return copy;
1344
+ });
1345
+ }
1288
1346
  var params = {
1289
1347
  client: (0, client_1.createClient)({}),
1290
1348
  name: name,
@@ -1394,6 +1452,7 @@ async function runDesignAccess(flags) {
1394
1452
  * --table x_cadso_journey --label URL --type url
1395
1453
  * [--name url] [--max-length 1024] [--reference <table>]
1396
1454
  * [--mandatory] [--default <value>] [--dependent-on-field <element>]
1455
+ * [--attributes "k=v,k2=v2"] [--no-readonly-clickthrough]
1397
1456
  * [--scope x_cadso_journey] [--cross-scope] [--ensure-design-access]
1398
1457
  * [--update-set <sys_id>] [--from-json <spec.json>] [--dry-run] [--debug] [--json]
1399
1458
  * --update-set is required unless --dry-run. --cross-scope opts in to a column
@@ -1423,6 +1482,17 @@ async function runAddColumn(flags) {
1423
1482
  column.dependent_on_field = flags["dependent-on-field"];
1424
1483
  }
1425
1484
  }
1485
+ // Apply to a --from-json column too, so the flags never silently do nothing.
1486
+ if (column && flags.attributes !== undefined) {
1487
+ if (flags.attributes === "true" || !flags.attributes.trim()) {
1488
+ process.stderr.write('add-column: --attributes needs a value, e.g. --attributes "readonly_clickthrough=true"\n');
1489
+ return 1;
1490
+ }
1491
+ column.attributes = flags.attributes;
1492
+ }
1493
+ if (column && flags["no-readonly-clickthrough"] === "true") {
1494
+ column.readonly_clickthrough = false;
1495
+ }
1426
1496
  if (!table || !column || !column.label) {
1427
1497
  process.stderr.write("add-column: --table and --label (with --type) are required (or --from-json)\n");
1428
1498
  return 1;
@@ -1554,6 +1624,56 @@ async function runAddIndex(flags) {
1554
1624
  return 2;
1555
1625
  return 0;
1556
1626
  }
1627
+ /**
1628
+ * dove-sn reference-attr-audit:
1629
+ * --scope-prefix x_cadso_ [--attribute "readonly_clickthrough=true"] [--json]
1630
+ *
1631
+ * Read-only. Lists active reference columns under the prefix whose
1632
+ * sys_dictionary.attributes lack the attribute (team rule: readonly_clickthrough=true).
1633
+ * Backfilling is a separate decision — set-column --attributes per column.
1634
+ *
1635
+ * Exit codes: 0 read (findings are a report, not a failure), 1 bad args.
1636
+ */
1637
+ async function runReferenceAttrAudit(flags) {
1638
+ var prefix = flags["scope-prefix"];
1639
+ if (!prefix || prefix === "true") {
1640
+ process.stderr.write("reference-attr-audit: --scope-prefix <prefix> is required (e.g. x_cadso_)\n");
1641
+ return 1;
1642
+ }
1643
+ if (flags.attribute === "true") {
1644
+ process.stderr.write('reference-attr-audit: --attribute needs a value, e.g. "readonly_clickthrough=true"\n');
1645
+ return 1;
1646
+ }
1647
+ var result;
1648
+ try {
1649
+ result = await (0, table_1.referenceAttrAudit)({
1650
+ client: (0, client_1.createClient)({}),
1651
+ scopePrefix: prefix,
1652
+ attribute: flags.attribute,
1653
+ });
1654
+ }
1655
+ catch (e) {
1656
+ var msg = e instanceof Error ? e.message : String(e);
1657
+ if (/^reference-attr-audit:/.test(msg)) {
1658
+ process.stderr.write(msg + "\n");
1659
+ return 1;
1660
+ }
1661
+ throw e;
1662
+ }
1663
+ if (flags.json === "true") {
1664
+ process.stdout.write(JSON.stringify(result, null, 2) + "\n");
1665
+ return 0;
1666
+ }
1667
+ process.stdout.write(result.scopePrefix + "* — " + result.total + " reference column(s), " +
1668
+ result.missing.length + " missing '" + result.attribute + "'" +
1669
+ (result.truncated ? " (SCAN TRUNCATED — results incomplete)" : "") + "\n");
1670
+ for (var i = 0; i < result.missing.length; i += 1) {
1671
+ var m = result.missing[i];
1672
+ process.stdout.write(" " + m.table + "." + m.element + " -> " + (m.reference || "(no target)") +
1673
+ " [" + (m.attributes || "no attributes") + "]\n");
1674
+ }
1675
+ return 0;
1676
+ }
1557
1677
  /**
1558
1678
  * dove-sn index-list:
1559
1679
  * --table x_cadso_automate_message_batch_recipient [--json]
@@ -1714,6 +1834,7 @@ function parseBoolFlag(name, raw, verb = "set-column") {
1714
1834
  * --table x_cadso_journey --column description --update-set <sys_id>
1715
1835
  * [--label "Description"] [--mandatory true|false] [--default <v>]
1716
1836
  * [--read-only true|false] [--max-length 4000] [--dependent-on-field <element>]
1837
+ * [--attributes "k=v,k2=v2"] (MERGED into the column's existing attributes)
1717
1838
  * [--dry-run] [--json]
1718
1839
  *
1719
1840
  * Updates an EXISTING column's schema. `internal_type` and a rename are refused —
@@ -1755,6 +1876,9 @@ async function runSetColumn(flags, bare) {
1755
1876
  if (flags["dependent-on-field"] !== undefined) {
1756
1877
  attributes.dependentOnField = flags["dependent-on-field"].trim();
1757
1878
  }
1879
+ // A bare --attributes is refused above (stringFlags); the value is validated in setColumn.
1880
+ if (flags.attributes !== undefined)
1881
+ attributes.attributes = flags.attributes;
1758
1882
  if (flags["max-length"] !== undefined) {
1759
1883
  var len = Number(flags["max-length"]);
1760
1884
  // sys_dictionary.max_length is an integer; the MCP schema enforces int() too.
@@ -1893,10 +2017,17 @@ function getProcessStdin() {
1893
2017
  * way stdin is ever read; never implicit)
1894
2018
  * — at least one field source is required
1895
2019
  * --update-set <sys_id> (required — the change is captured here)
2020
+ * [--domain global|<domain sys_id>] (session domain for the write; default global)
1896
2021
  * [--dry-run] [--json]
1897
- * Exit codes: 0 applied/dry-run, 1 bad args, 2 write landed but read-back unverified.
2022
+ * Exit codes: 0 applied/dry-run, 1 bad args, 2 write landed but read-back unverified
2023
+ * (including a sys_domain change or a domain OVERRIDE row created instead of an in-place update).
1898
2024
  */
1899
- async function runSetField(flags) {
2025
+ async function runSetField(flags, bare) {
2026
+ var setDomain = domainFlag("set-field", flags, bare || {});
2027
+ if (setDomain.error) {
2028
+ process.stderr.write(setDomain.error);
2029
+ return 1;
2030
+ }
1900
2031
  var table = flags.table;
1901
2032
  var fields;
1902
2033
  try {
@@ -1926,6 +2057,8 @@ async function runSetField(flags) {
1926
2057
  params.query = flags.query;
1927
2058
  if (flags["dry-run"] === "true")
1928
2059
  params.dryRun = true;
2060
+ if (setDomain.domain !== undefined)
2061
+ params.domain = setDomain.domain;
1929
2062
  var result = await (0, setField_1.setField)(params);
1930
2063
  if (flags.json === "true") {
1931
2064
  process.stdout.write(JSON.stringify(result, null, 2) + "\n");
@@ -1960,11 +2093,18 @@ async function runSetField(flags) {
1960
2093
  * --scope x_cadso_core (the app that owns the new record)
1961
2094
  * --update-set <sys_id> (required — the insert is captured here)
1962
2095
  * [--if-absent "name=avg_message_parts"] (skip the insert when this query already matches)
2096
+ * [--domain global|<domain sys_id>] (session domain for the insert; default global,
2097
+ * or the payload's sys_domain when it carries one)
1963
2098
  * [--dry-run] [--json]
1964
2099
  * Exit codes: 0 created/skipped-in-sync/dry-run, 1 bad args, 2 write landed but read-back unverified
1965
2100
  * (or skipped with drift).
1966
2101
  */
1967
- async function runCreateRecord(flags) {
2102
+ async function runCreateRecord(flags, bare) {
2103
+ var createDomain = domainFlag("create-record", flags, bare || {});
2104
+ if (createDomain.error) {
2105
+ process.stderr.write(createDomain.error);
2106
+ return 1;
2107
+ }
1968
2108
  var table = flags.table;
1969
2109
  var fields;
1970
2110
  try {
@@ -1994,6 +2134,8 @@ async function runCreateRecord(flags) {
1994
2134
  params.ifAbsentQuery = flags["if-absent"];
1995
2135
  if (flags["dry-run"] === "true")
1996
2136
  params.dryRun = true;
2137
+ if (createDomain.domain !== undefined)
2138
+ params.domain = createDomain.domain;
1997
2139
  var result = await (0, createRecord_1.createRecord)(params);
1998
2140
  if (flags.json === "true") {
1999
2141
  process.stdout.write(JSON.stringify(result, null, 2) + "\n");
@@ -2770,6 +2912,9 @@ async function dispatch(parsed) {
2770
2912
  if (parsed.command === "add-index") {
2771
2913
  return await runAddIndex(parsed.flags);
2772
2914
  }
2915
+ if (parsed.command === "reference-attr-audit") {
2916
+ return await runReferenceAttrAudit(parsed.flags);
2917
+ }
2773
2918
  if (parsed.command === "index-list") {
2774
2919
  return await runIndexList(parsed.flags);
2775
2920
  }
@@ -2783,10 +2928,10 @@ async function dispatch(parsed) {
2783
2928
  return await runSetTable(parsed.flags, parsed.bare);
2784
2929
  }
2785
2930
  if (parsed.command === "set-field") {
2786
- return await runSetField(parsed.flags);
2931
+ return await runSetField(parsed.flags, parsed.bare);
2787
2932
  }
2788
2933
  if (parsed.command === "create-record") {
2789
- return await runCreateRecord(parsed.flags);
2934
+ return await runCreateRecord(parsed.flags, parsed.bare);
2790
2935
  }
2791
2936
  if (parsed.command === "sync-ux-events") {
2792
2937
  return await runSyncUxEvents(parsed.flags, parsed.bare);