-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathregistry.ts
More file actions
1408 lines (1373 loc) · 51.6 KB
/
Copy pathregistry.ts
File metadata and controls
1408 lines (1373 loc) · 51.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
/**
* The metadata conversion table (ADR-0087 D2).
*
* Seeded with the **retroactive protocol-11 renames** — the calibration set the
* ADR names: had this layer existed, protocol 11 would have needed *zero*
* consumer action for these. Each entry is lossless, declared, loud, tested, and
* expiring (see {@link MetadataConversion}).
*
* Entries are grouped by the major that introduced the canonical shape
* (`toMajor`): a runtime on major N applies every conversion with
* `toMajor === N` (it accepts the N−1 shape at load), and the N+1 loader retires
* them — graduating them into the P2 migration chain rather than deleting them.
* Until P2 exists these remain the permanent, replayable transform history.
*/
import type { ConversionApplication, MetadataConversion } from './types.js';
import { mapCollection, mapFlowNodes, mapPages, renameConfigKey, renameKey } from './walk.js';
/**
* Flow callout node type rename (protocol 11.0).
*
* The divergent `http_request` / `http_call` / `webhook` node types were
* unified to the single canonical `http` node (see
* `services/service-automation/src/builtin/http-nodes.ts`). A pure enum
* re-spelling — losslessly convertible.
*/
const flowNodeHttpRename: MetadataConversion = {
id: 'flow-node-http-callout-rename',
toMajor: 11,
surface: 'flow.node.type',
summary: "flow callout node types 'http_request' / 'http_call' / 'webhook' → 'http'",
apply(stack, emit, context) {
const aliases = new Set(['http_request', 'http_call', 'webhook']);
return mapFlowNodes(stack, (node, path) => {
const type = node.type;
if (typeof type !== 'string' || !aliases.has(type)) return node;
// `flow.node.type` is an OPEN namespace (ADR-0018 removed the enum gate),
// so a retired official name could be re-registered by a third party. If a
// live executor owns this token in this environment, refuse the rewrite —
// clobbering it would silently break that node — and report a loud,
// actionable conflict instead (ADR-0078). On the pure build/validate seam
// `context` is absent, so the historical alias converts as normal.
if (context?.reservedNodeTypes?.has(type)) {
context.reportConflict?.({
token: type,
path: `${path}.type`,
reason:
`'${type}' is a protocol-11 retired official flow-node type, but a live ` +
`executor is registered under that exact name in this environment. The ` +
`conversion to 'http' was skipped to avoid breaking it. Rename your ` +
`custom node to a non-reserved type (the reserved names are ` +
`'http_request' / 'http_call' / 'webhook', all superseded by 'http').`,
});
return node;
}
emit({ from: type, to: 'http', path: `${path}.type` });
return { ...node, type: 'http' };
});
},
fixture: {
before: {
flows: [
{
name: 'notify_flow',
nodes: [
{ id: 'n1', type: 'start' },
{ id: 'n2', type: 'http_request', config: { url: 'https://example.com' } },
{ id: 'n3', type: 'webhook', config: { url: 'https://hooks.example.com' } },
],
},
],
},
after: {
flows: [
{
name: 'notify_flow',
nodes: [
{ id: 'n1', type: 'start' },
{ id: 'n2', type: 'http', config: { url: 'https://example.com' } },
{ id: 'n3', type: 'http', config: { url: 'https://hooks.example.com' } },
],
},
],
},
expectedNotices: 2,
},
};
/**
* Page `kind: 'jsx'` → `kind: 'html'` (protocol 11.4).
*
* `'jsx'` is a documented deprecated alias of the canonical `'html'` page kind
* (ADR-0080; see `spec/src/ui/page.zod.ts`). The `source` semantics are
* identical, so the rename is lossless.
*/
const pageKindJsxToHtml: MetadataConversion = {
id: 'page-kind-jsx-to-html',
toMajor: 11,
surface: 'page.kind',
summary: "page kind 'jsx' → 'html' (ADR-0080 canonical spelling)",
apply(stack, emit) {
return mapPages(stack, (page, path) => {
if (page.kind !== 'jsx') return page;
emit({ from: 'jsx', to: 'html', path: `${path}.kind` });
return { ...page, kind: 'html' };
});
},
fixture: {
before: {
pages: [{ name: 'landing', kind: 'jsx', source: '<div>hi</div>' }],
},
after: {
pages: [{ name: 'landing', kind: 'html', source: '<div>hi</div>' }],
},
expectedNotices: 1,
},
};
/**
* CRUD flow-node `config.filters` → `config.filter` (protocol 11.0).
*
* This entry demonstrates ADR-0087's **PD #12 retirement path** (issue #2645):
* the `get_record` / `update_record` / `delete_record` executors historically
* tolerated the `filters` alias via a consumer-side
* `readAliasedConfig(cfg, …, 'filter', ['filters'], …)` fallback. That scattered
* dialect tolerance is promoted here into one declared, expiring conversion and
* the executor fallback is deleted: the load path now hands the executor the
* canonical `filter` key, so the executor reads `cfg.filter` directly.
*/
const flowNodeFilterAlias: MetadataConversion = {
id: 'flow-node-crud-filter-alias',
toMajor: 11,
surface: 'flow.node.config.filter',
summary: "CRUD flow-node config key 'filters' → 'filter'",
apply(stack, emit) {
const crudTypes = new Set(['get_record', 'update_record', 'delete_record']);
return mapFlowNodes(stack, (node, path) => {
if (typeof node.type !== 'string' || !crudTypes.has(node.type)) return node;
const renamed = renameConfigKey(node, 'filters', 'filter');
if (!renamed) return node;
emit({ from: 'filters', to: 'filter', path: `${path}.config.filter` });
return renamed;
});
},
fixture: {
before: {
flows: [
{
name: 'purge_flow',
nodes: [
{ id: 'n1', type: 'start' },
{
id: 'n2',
type: 'delete_record',
config: { objectName: 'lead', filters: { status: 'stale' } },
},
],
},
],
},
after: {
flows: [
{
name: 'purge_flow',
nodes: [
{ id: 'n1', type: 'start' },
{
id: 'n2',
type: 'delete_record',
config: { objectName: 'lead', filter: { status: 'stale' } },
},
],
},
],
},
expectedNotices: 1,
},
};
/**
* Object `compactLayout` → `highlightFields` (spec 11.7.0, ADR-0085; alias
* retired at authoring in 11.9.1, #2536).
*
* A pure key rename — the value (ordered field-name list) is unchanged.
* **Retired from the load path**: the schema tombstones `compactLayout` with a
* fix-it error, so the loader must NOT quietly accept it; the entry exists so
* `migrate meta --from 10|11` rewrites old *sources* (backfilled per the
* ADR-0087 true-up — the rename shipped before the conversion layer existed).
*/
const objectCompactLayoutRename: MetadataConversion = {
id: 'object-compactLayout-to-highlightFields',
toMajor: 11,
retiredFromLoadPath: true,
surface: 'object.compactLayout',
summary: "object key 'compactLayout' → 'highlightFields' (ADR-0085 semantic roles)",
apply(stack, emit) {
return mapCollection(stack, 'objects', (obj, path) => {
const renamed = renameKey(obj, 'compactLayout', 'highlightFields');
if (!renamed) return obj;
emit({ from: 'compactLayout', to: 'highlightFields', path: `${path}.highlightFields` });
return renamed;
});
},
fixture: {
before: {
objects: [{ name: 'crm_lead', label: 'Lead', compactLayout: ['name', 'status'] }],
},
after: {
objects: [{ name: 'crm_lead', label: 'Lead', highlightFields: ['name', 'status'] }],
},
expectedNotices: 1,
},
};
/**
* Stack collection `roles:` → `positions:` (protocol 13, ADR-0090 D3).
*
* The distribution concept was renamed Role → Position across the platform;
* the stack-definition collection key renamed with it. A pure key move — the
* item shapes migrate separately (`position.parent` removal is semantic, see
* the step-13 TODOs). **Retired from the load path**: ADR-0090 shipped this as
* a pre-launch one-step rename with no alias window; the entry preserves it as
* replayable chain history.
*/
const stackRolesToPositions: MetadataConversion = {
id: 'stack-roles-to-positions',
toMajor: 13,
retiredFromLoadPath: true,
surface: 'stack.roles',
summary: "stack collection key 'roles' → 'positions' (ADR-0090 D3)",
apply(stack, emit) {
const renamed = renameKey(stack, 'roles', 'positions');
if (!renamed) return stack;
emit({ from: 'roles', to: 'positions', path: 'positions' });
return renamed;
},
fixture: {
before: {
roles: [{ name: 'sales_rep', label: 'Sales Rep' }],
},
after: {
positions: [{ name: 'sales_rep', label: 'Sales Rep' }],
},
expectedNotices: 1,
},
};
/**
* OWD legacy aliases `read` / `read_write` → canonical (protocol 13,
* ADR-0090 D4).
*
* The two aliases with an unambiguous canonical spelling convert mechanically;
* the third legacy alias `'full'` has NO lossless target (full access includes
* transfer/delete — wider than `public_read_write`) and is delegated to the
* step-13 semantic TODO instead (D2 scope guard: lossless only). Handles both
* `object.sharingModel` and the nested `object.security.sharingModel` spot.
* **Retired from the load path** (one-step removal; authoring rejects with a
* fix-it).
*/
const owdLegacyReadAliases: MetadataConversion = {
id: 'owd-legacy-read-aliases',
toMajor: 13,
retiredFromLoadPath: true,
surface: 'object.sharingModel',
summary: "object sharingModel 'read' → 'public_read', 'read_write' → 'public_read_write' (ADR-0090 D4)",
apply(stack, emit) {
const CANONICAL: Record<string, string> = {
read: 'public_read',
read_write: 'public_read_write',
};
return mapCollection(stack, 'objects', (obj, path) => {
let next = obj;
const direct = next.sharingModel;
if (typeof direct === 'string' && CANONICAL[direct]) {
emit({ from: direct, to: CANONICAL[direct]!, path: `${path}.sharingModel` });
next = { ...next, sharingModel: CANONICAL[direct] };
}
const security = next.security;
if (security && typeof security === 'object' && !Array.isArray(security)) {
const nested = (security as Record<string, unknown>).sharingModel;
if (typeof nested === 'string' && CANONICAL[nested]) {
emit({ from: nested, to: CANONICAL[nested]!, path: `${path}.security.sharingModel` });
next = { ...next, security: { ...(security as Record<string, unknown>), sharingModel: CANONICAL[nested] } };
}
}
return next;
});
},
fixture: {
before: {
objects: [
{ name: 'crm_deal', label: 'Deal', sharingModel: 'read' },
{ name: 'crm_note', label: 'Note', security: { sharingModel: 'read_write' } },
],
},
after: {
objects: [
{ name: 'crm_deal', label: 'Deal', sharingModel: 'public_read' },
{ name: 'crm_note', label: 'Note', security: { sharingModel: 'public_read_write' } },
],
},
expectedNotices: 2,
},
};
/**
* Sharing-rule recipient type `'role'` → `'position'` (protocol 13,
* ADR-0090 D3).
*
* Applies to both `sharedWith.type` and the owner-rule `ownedBy.type`. The
* removed `'role_and_subordinates'` recipient is NOT converted — its v2
* replacement (`unit_and_subordinates`) expands a *different* tree (business
* units, not the retired role hierarchy), so it is a step-13 semantic TODO.
* **Retired from the load path** (one-step rename, no alias window).
*/
const sharingRecipientRoleToPosition: MetadataConversion = {
id: 'sharing-recipient-role-to-position',
toMajor: 13,
retiredFromLoadPath: true,
surface: 'sharingRule.sharedWith.type',
summary: "sharing-rule recipient type 'role' → 'position' (ADR-0090 D3)",
apply(stack, emit) {
const renameRecipient = (rule: Record<string, unknown>, key: string, path: string) => {
const recipient = rule[key];
if (!recipient || typeof recipient !== 'object' || Array.isArray(recipient)) return rule;
const dict = recipient as Record<string, unknown>;
if (dict.type !== 'role') return rule;
emit({ from: 'role', to: 'position', path: `${path}.${key}.type` });
return { ...rule, [key]: { ...dict, type: 'position' } };
};
return mapCollection(stack, 'sharingRules', (rule, path) => {
let next = renameRecipient(rule, 'sharedWith', path);
next = renameRecipient(next, 'ownedBy', path);
return next;
});
},
fixture: {
before: {
sharingRules: [
{
name: 'share_sales',
type: 'owner',
object: 'crm_deal',
sharedWith: { type: 'role', value: 'sales_mgr' },
ownedBy: { type: 'role', value: 'sales_rep' },
},
],
},
after: {
sharingRules: [
{
name: 'share_sales',
type: 'owner',
object: 'crm_deal',
sharedWith: { type: 'position', value: 'sales_mgr' },
ownedBy: { type: 'position', value: 'sales_rep' },
},
],
},
expectedNotices: 2,
},
};
/**
* Book audience gated arm `{ profile }` → `{ permissionSet }` (protocol 14,
* ADR-0090 D2 fallout; shipped in 14.0.0 as a pre-launch one-step rename).
*
* Packages own permission sets but never positions (ADR-0090 D9), so the
* gate is a capability reference. Value carried over 1:1. **Retired from the
* load path** — the zod union rejects `{ profile }` at parse; this entry is
* the replayable chain history the one-step ship skipped.
*/
const bookAudienceProfileToPermissionSet: MetadataConversion = {
id: 'book-audience-profile-to-permission-set',
toMajor: 14,
retiredFromLoadPath: true,
surface: 'book.audience',
summary: "book audience gated arm '{ profile }' → '{ permissionSet }' (ADR-0090 D2/D9)",
apply(stack, emit) {
return mapCollection(stack, 'books', (book, path) => {
const audience = book.audience;
if (!audience || typeof audience !== 'object' || Array.isArray(audience)) return book;
const dict = audience as Record<string, unknown>;
if (typeof dict.profile !== 'string' || dict.permissionSet != null) return book;
emit({ from: 'profile', to: 'permissionSet', path: `${path}.audience.permissionSet` });
const { profile, ...rest } = dict;
return { ...book, audience: { ...rest, permissionSet: profile } };
});
},
fixture: {
before: {
books: [{ name: 'crm_admin_guide', audience: { profile: 'crm_admin' } }],
},
after: {
books: [{ name: 'crm_admin_guide', audience: { permissionSet: 'crm_admin' } }],
},
expectedNotices: 1,
},
};
/** Rename a visibility alias key on a dict, emitting with the given path. */
function renameVisibilityAlias(
dict: Record<string, unknown>,
alias: string,
path: string,
emit: (detail: { from: string; to: string; path: string }) => void,
): Record<string, unknown> {
const renamed = renameKey(dict, alias, 'visibleWhen');
if (!renamed) return dict;
emit({ from: alias, to: 'visibleWhen', path: `${path}.visibleWhen` });
return renamed;
}
/**
* View form `visibleOn` → `visibleWhen` (protocol 15, ADR-0089 D2).
*
* The conditional-visibility predicate is unified under the canonical
* `visibleWhen` across all layers. Applies to form sections and (recursively
* nested) form fields in every `views[].form` / `views[].formViews.*`
* container. **Live window**: the protocol-15 loader accepts the deprecated
* key (the zod schemas also normalize it at parse — this entry makes the
* acceptance *declared, loud, and expiring* per ADR-0087 D2, and will
* graduate into the step-16 chain when the alias is removed).
*/
const viewVisibleOnToVisibleWhen: MetadataConversion = {
id: 'view-visibleOn-to-visibleWhen',
toMajor: 15,
surface: 'view.form.visibleOn',
summary: "view form section/field key 'visibleOn' → 'visibleWhen' (ADR-0089)",
apply(stack, emit) {
const mapFields = (fields: unknown, path: string): unknown => {
if (!Array.isArray(fields)) return fields;
let changed = false;
const next = fields.map((field, i) => {
if (!field || typeof field !== 'object' || Array.isArray(field)) return field;
let dict = field as Record<string, unknown>;
dict = renameVisibilityAlias(dict, 'visibleOn', `${path}[${i}]`, emit);
const nested = mapFields(dict.fields, `${path}[${i}].fields`);
if (nested !== dict.fields) dict = { ...dict, fields: nested };
if (dict !== field) changed = true;
return dict;
});
return changed ? next : fields;
};
const mapSections = (sections: unknown, path: string): unknown => {
if (!Array.isArray(sections)) return sections;
let changed = false;
const next = sections.map((section, i) => {
if (!section || typeof section !== 'object' || Array.isArray(section)) return section;
let dict = section as Record<string, unknown>;
dict = renameVisibilityAlias(dict, 'visibleOn', `${path}[${i}]`, emit);
const fields = mapFields(dict.fields, `${path}[${i}].fields`);
if (fields !== dict.fields) dict = { ...dict, fields };
if (dict !== section) changed = true;
return dict;
});
return changed ? next : sections;
};
const mapForm = (form: unknown, path: string): unknown => {
if (!form || typeof form !== 'object' || Array.isArray(form)) return form;
let dict = form as Record<string, unknown>;
for (const key of ['sections', 'groups'] as const) {
const mapped = mapSections(dict[key], `${path}.${key}`);
if (mapped !== dict[key]) dict = { ...dict, [key]: mapped };
}
const fields = mapFields(dict.fields, `${path}.fields`);
if (fields !== dict.fields) dict = { ...dict, fields };
return dict;
};
return mapCollection(stack, 'views', (view, path) => {
let next = view;
const form = mapForm(next.form, `${path}.form`);
if (form !== next.form) next = { ...next, form };
const formViews = next.formViews;
if (formViews && typeof formViews === 'object' && !Array.isArray(formViews)) {
let fvChanged = false;
const nextViews: Record<string, unknown> = {};
for (const [name, fv] of Object.entries(formViews as Record<string, unknown>)) {
const mapped = mapForm(fv, `${path}.formViews.${name}`);
if (mapped !== fv) fvChanged = true;
nextViews[name] = mapped;
}
if (fvChanged) next = { ...next, formViews: nextViews };
}
return next;
});
},
fixture: {
before: {
views: [
{
object: 'crm_lead',
form: {
sections: [
{
label: 'Details',
visibleOn: "record.status == 'open'",
fields: ['name', { field: 'priority', visibleOn: "record.priority != ''" }],
},
],
},
},
],
},
after: {
views: [
{
object: 'crm_lead',
form: {
sections: [
{
label: 'Details',
visibleWhen: "record.status == 'open'",
fields: ['name', { field: 'priority', visibleWhen: "record.priority != ''" }],
},
],
},
},
],
},
expectedNotices: 2,
},
};
/**
* Page component `visibility` → `visibleWhen` (protocol 15, ADR-0089 D2).
*
* The page-component spelling of the same predicate. Applies to
* `pages[].regions[].components[]`. **Live window**, same terms as
* {@link viewVisibleOnToVisibleWhen}. (An AI agent's `visibility` property is
* a different, unrelated surface and is not touched.)
*/
const pageComponentVisibilityToVisibleWhen: MetadataConversion = {
id: 'page-component-visibility-to-visibleWhen',
toMajor: 15,
surface: 'page.component.visibility',
summary: "page component key 'visibility' → 'visibleWhen' (ADR-0089)",
apply(stack, emit) {
return mapPages(stack, (page, path) => {
const regions = page.regions;
if (!Array.isArray(regions)) return page;
let regionsChanged = false;
const nextRegions = regions.map((region, ri) => {
if (!region || typeof region !== 'object' || Array.isArray(region)) return region;
const dict = region as Record<string, unknown>;
const components = dict.components;
if (!Array.isArray(components)) return region;
let componentsChanged = false;
const nextComponents = components.map((component, ci) => {
if (!component || typeof component !== 'object' || Array.isArray(component)) return component;
const mapped = renameVisibilityAlias(
component as Record<string, unknown>,
'visibility',
`${path}.regions[${ri}].components[${ci}]`,
emit,
);
if (mapped !== component) componentsChanged = true;
return mapped;
});
if (!componentsChanged) return region;
regionsChanged = true;
return { ...dict, components: nextComponents };
});
if (!regionsChanged) return page;
return { ...page, regions: nextRegions };
});
},
fixture: {
before: {
pages: [
{
name: 'crm_home',
regions: [
{
name: 'main',
components: [
{ type: 'record:list', visibility: "page.selectedId != ''" },
{ type: 'element:divider' },
],
},
],
},
],
},
after: {
pages: [
{
name: 'crm_home',
regions: [
{
name: 'main',
components: [
{ type: 'record:list', visibleWhen: "page.selectedId != ''" },
{ type: 'element:divider' },
],
},
],
},
],
},
expectedNotices: 1,
},
};
/* ── Protocol 17: the three fold-and-drop aliases retire (#3855) ───────────────
*
* `execute`, `conditionalRequired` and `topics` were each folded into their
* canonical key by a schema transform and dropped from the parsed output. They
* are now removed from the spec outright, and each schema TOMBSTONES its key
* with a fix-it error (`retiredKey`, `shared/retired-key.ts`) so the loader
* cannot quietly accept it — the same shape as
* `object-compactLayout-to-highlightFields` above.
*
* All three are therefore `retiredFromLoadPath: true` from the day they land:
* there is no alias window, deliberately. What the entries buy is the two
* things a consumer actually needs, neither of which is an error message:
*
* - they appear in `CONVERSIONS_BY_MAJOR[17]`, so `spec-changes.json` (D4)
* carries them — and the generated upgrade guide and the `spec_changes` MCP
* tool are projections of that record, composed across however many majors
* the consumer is jumping;
* - the step-17 chain entry references them by id, so
* `os migrate meta --from 16` REWRITES the consumer's source mechanically
* instead of asking them to hand-edit.
*
* The tombstone error is the backstop for someone who did neither, and it says
* so by pointing at `migrate meta`.
*/
// `Dict` / `isDict` are module-private in `walk.ts`. Re-declared locally rather
// than widening that module's exports, which would grow the package API surface
// for an internal one-line type guard.
type Dict = Record<string, unknown>;
const isDict = (v: unknown): v is Dict => typeof v === 'object' && v !== null && !Array.isArray(v);
type Emit = (detail: ConversionApplication) => void;
/** Rename a key on every field of every object (and object extension). Fields
* are a RECORD keyed by field name, so `mapCollection` does not reach them. */
function mapObjectFieldsKey(stack: Dict, collection: string, from: string, to: string, emit: Emit): Dict {
return mapCollection(stack, collection, (owner, path) => {
const fields = owner.fields;
if (!isDict(fields)) return owner;
let changed = false;
const next: Dict = {};
for (const [name, def] of Object.entries(fields)) {
if (!isDict(def)) {
next[name] = def;
continue;
}
const renamed = renameKey(def, from, to);
if (renamed) {
emit({ from, to, path: `${path}.fields.${name}.${to}` });
next[name] = renamed;
changed = true;
} else {
next[name] = def;
}
}
return changed ? { ...owner, fields: next } : owner;
});
}
/**
* Action `execute` → `target` (protocol 17, #3713 / #3742 / #3855).
*
* A pure key rename — the value (a handler/flow/URL ref) is unchanged. Actions
* appear both top-level and nested under their object, so both are walked.
*/
const actionExecuteToTarget: MetadataConversion = {
id: 'action-execute-to-target',
toMajor: 17,
retiredFromLoadPath: true,
surface: 'action.execute',
summary: "action key 'execute' → 'target' (the deprecated handler alias, #3713)",
apply(stack, emit) {
const renameOn = (action: Dict, path: string): Dict => {
const renamed = renameKey(action, 'execute', 'target');
if (!renamed) return action;
emit({ from: 'execute', to: 'target', path: `${path}.target` });
return renamed;
};
const withTopLevel = mapCollection(stack, 'actions', renameOn);
return mapCollection(withTopLevel, 'objects', (obj, path) => {
const nested = mapCollection(obj, 'actions', (action, actionPath) =>
renameOn(action, `${path}.${actionPath}`),
);
return nested;
});
},
fixture: {
before: {
actions: [{ name: 'convert', label: 'Convert', type: 'script', execute: 'convertHandler' }],
},
after: {
actions: [{ name: 'convert', label: 'Convert', type: 'script', target: 'convertHandler' }],
},
expectedNotices: 1,
},
};
/**
* Field `conditionalRequired` → `requiredWhen` (protocol 17, #3754 / #3855).
*
* A pure key rename — the value (a CEL predicate, bare or enveloped) is
* unchanged. Covers object fields and object-extension fields: the same
* `FieldSchema`, so the same alias.
*/
const fieldConditionalRequiredToRequiredWhen: MetadataConversion = {
id: 'field-conditionalRequired-to-requiredWhen',
toMajor: 17,
retiredFromLoadPath: true,
surface: 'field.conditionalRequired',
summary: "field key 'conditionalRequired' → 'requiredWhen' (the deprecated predicate alias, #3754)",
apply(stack, emit) {
const withObjects = mapObjectFieldsKey(stack, 'objects', 'conditionalRequired', 'requiredWhen', emit);
return mapObjectFieldsKey(withObjects, 'objectExtensions', 'conditionalRequired', 'requiredWhen', emit);
},
fixture: {
before: {
objects: [{
name: 'crm_task',
label: 'Task',
fields: { due_date: { type: 'date', conditionalRequired: 'record.stage == "closed"' } },
}],
},
after: {
objects: [{
name: 'crm_task',
label: 'Task',
fields: { due_date: { type: 'date', requiredWhen: 'record.stage == "closed"' } },
}],
},
expectedNotices: 1,
},
};
/**
* Agent `knowledge.topics` → `knowledge.sources` (protocol 17, #1891 / #3855).
*
* A pure key rename — the value (a list of RAG source tags) is unchanged.
*/
const agentKnowledgeTopicsToSources: MetadataConversion = {
id: 'agent-knowledge-topics-to-sources',
toMajor: 17,
retiredFromLoadPath: true,
surface: 'agent.knowledge.topics',
summary: "agent knowledge key 'topics' → 'sources' (the deprecated RAG-source alias, #1891)",
apply(stack, emit) {
return mapCollection(stack, 'agents', (agent, path) => {
const knowledge = agent.knowledge;
if (!isDict(knowledge)) return agent;
const renamed = renameKey(knowledge, 'topics', 'sources');
if (!renamed) return agent;
emit({ from: 'topics', to: 'sources', path: `${path}.knowledge.sources` });
return { ...agent, knowledge: renamed };
});
},
fixture: {
before: {
agents: [{ name: 'support_bot', knowledge: { topics: ['faq', 'policies'], indexes: ['docs'] } }],
},
after: {
agents: [{ name: 'support_bot', knowledge: { sources: ['faq', 'policies'], indexes: ['docs'] } }],
},
expectedNotices: 1,
},
};
/**
* Agent `tools` → dropped (protocol 17, #3894 / #3820).
*
* NOT a rename — there is no key to move the value to. ADR-0064 says an
* agent's tool set is exactly the union of its surface-compatible skills'
* tools, and `agent.tools[]` was the seam that broke it (it resolved names
* against the FULL registry with no surface check). Each entry has to become
* a reference inside a SKILL, which needs a human decision about which skill
* — so this conversion drops the dead key and emits one notice per agent
* naming what was lost, rather than guessing a destination.
*
* Dropping is safe: the cloud runtime stopped reading the field entirely
* (cloud#910), so by protocol 17 it contributes nothing at load time. What
* the notice preserves is the AUTHOR's knowledge of which tools they meant.
*/
const agentToolsToSkills: MetadataConversion = {
id: 'agent-tools-to-skills',
toMajor: 17,
retiredFromLoadPath: true,
surface: 'agent.tools',
summary: "agent key 'tools' removed — declare capability in a skill (ADR-0064, #3894)",
apply(stack, emit) {
return mapCollection(stack, 'agents', (agent, path) => {
if (!('tools' in agent) || agent.tools == null) return agent;
const next: Dict = { ...agent };
delete next.tools;
// The notice carries `tools → skills` at the agent's path: the author
// sees WHICH agent lost inline references and where the capability has
// to be re-declared. The tool names themselves stay in their git
// history, which is where a judgement call should be read from.
emit({ from: 'tools', to: 'skills', path: `${path}.skills` });
return next;
});
},
fixture: {
before: {
agents: [
{
name: 'support_bot',
skills: ['case_management'],
tools: [{ type: 'action', name: 'create_ticket' }],
},
],
},
after: {
agents: [{ name: 'support_bot', skills: ['case_management'] }],
},
expectedNotices: 1,
},
};
/**
* Sharing-rule `accessLevel: 'full'` → `'edit'` (protocol 17, #3865).
*
* `full` was documented as "Full Access (Transfer, Share, Delete)" but no code
* path ever granted transfer, re-share, or delete because of it: both
* enforcement sites matched `access_level in ('edit','full')`, so it behaved as
* `edit` while telling admins it granted more (ADR-0078 declared-but-unenforced;
* ADR-0049). It was removed from `SharingLevel`, which makes this rewrite
* strictly **lossless** — unlike the OWD `sharingModel: 'full'` alias, which had
* no equivalent target and was delegated to a step-13 semantic TODO. Here the
* old and new shapes are already behaviourally identical, so the loader can
* convert with zero consumer action.
*
* **Live window** — deliberately unlike its three step-17 siblings, which are
* `retiredFromLoadPath` because each was an already-deprecated key whose schema
* now tombstones it with a fix-it error. `full` carried no prior deprecation and
* a removed enum VALUE yields only a generic zod message, so it gets the
* ADR-0087 D2 default instead: the protocol-17 loader accepts it for one major
* (this entry runs at `normalizeStackInput`, *before* the enum rejects it) and
* retires at 18. Accepting it is zero-risk precisely because the rewrite is
* behaviour-preserving. The runtime counterpart for already-persisted rows lives
* in `plugin-sharing` (grant-time normalisation + a boot backfill over
* `sys_sharing_rule` / `sys_record_share`).
*/
const sharingRuleAccessLevelFullToEdit: MetadataConversion = {
id: 'sharing-rule-access-level-full-to-edit',
toMajor: 17,
surface: 'sharingRule.accessLevel',
summary: "sharing-rule accessLevel 'full' → 'edit' (#3865 — `full` never granted more than `edit`)",
apply(stack, emit) {
return mapCollection(stack, 'sharingRules', (rule, path) => {
if (rule.accessLevel !== 'full') return rule;
emit({ from: 'full', to: 'edit', path: `${path}.accessLevel` });
return { ...rule, accessLevel: 'edit' };
});
},
fixture: {
before: {
sharingRules: [
{
name: 'share_open_deals',
type: 'criteria',
object: 'crm_deal',
accessLevel: 'full',
condition: 'record.status == "open"',
sharedWith: { type: 'business_unit', value: 'bu_sales' },
},
],
},
after: {
sharingRules: [
{
name: 'share_open_deals',
type: 'criteria',
object: 'crm_deal',
accessLevel: 'edit',
condition: 'record.status == "open"',
sharedWith: { type: 'business_unit', value: 'bu_sales' },
},
],
},
expectedNotices: 1,
},
};
/** Rename each `[from, to]` config pair on flow nodes of the given types. */
function renameFlowConfigAliases(
stack: Dict,
nodeTypes: ReadonlySet<string>,
pairs: ReadonlyArray<readonly [string, string]>,
emit: Emit,
): Dict {
return mapFlowNodes(stack, (node, path) => {
if (typeof node.type !== 'string' || !nodeTypes.has(node.type)) return node;
let next = node;
for (const [from, to] of pairs) {
const renamed = renameConfigKey(next, from, to);
if (!renamed) continue;
emit({ from, to, path: `${path}.config.${to}` });
next = renamed;
}
return next;
});
}
/**
* CRUD flow-node `config.object` → `config.objectName` (protocol 17, #3796).
*
* The last tenant of the `readAliasedConfig` executor shim
* (`service-automation/src/builtin/config-aliases.ts`) graduates into the
* conversion layer, completing the PD #12 retirement path that
* {@link flowNodeFilterAlias} pioneered: the alias is rewritten to the
* canonical key at load — including the `AutomationEngine.registerFlow`
* rehydration seam — so the CRUD executors read `cfg.objectName` directly and
* the shim is deleted. **Live window**: stored flows authored with `object`
* keep loading through this major; retires at 18.
*/
const flowNodeCrudObjectAlias: MetadataConversion = {
id: 'flow-node-crud-object-alias',
toMajor: 17,
surface: 'flow.node.config.objectName',
summary: "CRUD flow-node config key 'object' → 'objectName' (#3796 — `readAliasedConfig` shim graduation)",
apply(stack, emit) {
const crudTypes = new Set(['get_record', 'create_record', 'update_record', 'delete_record']);
return renameFlowConfigAliases(stack, crudTypes, [['object', 'objectName']], emit);
},
fixture: {
before: {
flows: [
{
name: 'lead_lookup',
nodes: [
{ id: 'n1', type: 'start' },
{ id: 'n2', type: 'get_record', config: { object: 'lead', recordId: '{leadId}' } },
// canonical already present → the shadowed alias is left alone (no notice)
{ id: 'n3', type: 'create_record', config: { objectName: 'task', object: 'ignored' } },
],
},
],
},
after: {
flows: [
{
name: 'lead_lookup',
nodes: [
{ id: 'n1', type: 'start' },
{ id: 'n2', type: 'get_record', config: { objectName: 'lead', recordId: '{leadId}' } },
{ id: 'n3', type: 'create_record', config: { objectName: 'task', object: 'ignored' } },
],
},
],
},
expectedNotices: 1,
},
};
/**
* Lift `notify`'s nested `config.source: { object, id }` onto the canonical flat
* `sourceObject` / `sourceId` keys (#4045).
*
* The fifth notify alias, and the only one that is not a 1:1 rename — it is a
* 1→2 destructuring, so {@link renameFlowConfigAliases}' pair mechanism cannot
* express it. Semantics mirror the `??` precedence the executor used to carry:
* a canonical key already present WINS and its nested counterpart is left
* shadowed, exactly as {@link renameConfigKey} treats a shadowed alias.
*
* `source` is dropped once at least one part was lifted — every part is by then
* either lifted or shadowed by a canonical key, so nothing observable is lost
* (the executor only ever read `.object` / `.id`). A `source` that is not a dict,
* or carries neither key, is left untouched rather than silently deleted.
*/
function liftNotifySourceShape(stack: Dict, emit: Emit): Dict {
return mapFlowNodes(stack, (node, path) => {
if (node.type !== 'notify') return node;
const config = node.config;
if (!isDict(config)) return node;
const source = config.source;
if (!isDict(source)) return node;
const nextConfig: Dict = { ...config };
let lifted = false;
for (const [from, to] of [['object', 'sourceObject'], ['id', 'sourceId']] as const) {
if (source[from] == null) continue;
if (nextConfig[to] != null) continue; // canonical already wins
nextConfig[to] = source[from];
emit({ from: `source.${from}`, to, path: `${path}.config.${to}` });
lifted = true;
}
if (!lifted) return node;
delete nextConfig.source;
return { ...node, config: nextConfig };
});
}
/**
* Notify flow-node config key aliases → canonical (protocol 17, #3796 / #4045).