@elementumai/edk 0.13.0 → 0.13.2

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.
Files changed (101) hide show
  1. package/README.md +6 -2
  2. package/dist-sdk/src/catalog/factories.js +8 -2
  3. package/dist-sdk/src/catalog/types.d.ts +5 -0
  4. package/dist-sdk/src/engine/coverage-gaps.d.ts +12 -0
  5. package/dist-sdk/src/engine/coverage-gaps.js +23 -0
  6. package/dist-sdk/src/engine/ei/run.d.ts +8 -0
  7. package/dist-sdk/src/engine/ei/run.js +46 -7
  8. package/dist-sdk/src/engine/progress.d.ts +1 -0
  9. package/dist-sdk/src/engine/progress.js +6 -0
  10. package/dist-sdk/src/engine/pull/context.d.ts +24 -0
  11. package/dist-sdk/src/engine/pull/result-output.d.ts +2 -0
  12. package/dist-sdk/src/engine/pull/result-output.js +1 -1
  13. package/dist-sdk/src/engine/pull/stream-root.d.ts +11 -0
  14. package/dist-sdk/src/engine/pull/stream-root.js +22 -6
  15. package/dist-sdk/src/engine/tf/escape.d.ts +8 -3
  16. package/dist-sdk/src/engine/tf/escape.js +17 -4
  17. package/dist-sdk/src/engine/workspace/authoring-layout.js +16 -2
  18. package/dist-sdk/src/entities/access-policy/from-tf.js +4 -7
  19. package/dist-sdk/src/entities/agent/deserializer/print-agent-v2.js +2 -1
  20. package/dist-sdk/src/entities/agent/from-tf.d.ts +2 -0
  21. package/dist-sdk/src/entities/agent/from-tf.js +28 -1
  22. package/dist-sdk/src/entities/agent/module.js +1 -0
  23. package/dist-sdk/src/entities/agent/to-tf.d.ts +3 -1
  24. package/dist-sdk/src/entities/agent/to-tf.js +21 -3
  25. package/dist-sdk/src/entities/app/from-tf.d.ts +1 -0
  26. package/dist-sdk/src/entities/app/from-tf.js +6 -23
  27. package/dist-sdk/src/entities/app/index.d.ts +1 -1
  28. package/dist-sdk/src/entities/app/module.js +2 -0
  29. package/dist-sdk/src/entities/approval-chain/from-tf.js +2 -2
  30. package/dist-sdk/src/entities/automation/build.d.ts +10 -1
  31. package/dist-sdk/src/entities/automation/deserializer/print-automation.js +1 -0
  32. package/dist-sdk/src/entities/automation/from-tf.js +72 -11
  33. package/dist-sdk/src/entities/automation/index.d.ts +1 -1
  34. package/dist-sdk/src/entities/automation/module.js +12 -0
  35. package/dist-sdk/src/entities/automation/system-ref-name.d.ts +23 -3
  36. package/dist-sdk/src/entities/automation/system-ref-name.js +86 -4
  37. package/dist-sdk/src/entities/automation/to-tf.d.ts +5 -1
  38. package/dist-sdk/src/entities/automation/to-tf.js +312 -51
  39. package/dist-sdk/src/entities/automation/triggers.d.ts +5 -1
  40. package/dist-sdk/src/entities/automation/workflow-output.d.ts +7 -0
  41. package/dist-sdk/src/entities/automation/workflow-output.js +8 -0
  42. package/dist-sdk/src/entities/dashboard/from-tf.d.ts +3 -1
  43. package/dist-sdk/src/entities/dashboard/from-tf.js +42 -2
  44. package/dist-sdk/src/entities/dashboard/to-tf.js +9 -1
  45. package/dist-sdk/src/entities/dashboard-widget-order/module.d.ts +10 -0
  46. package/dist-sdk/src/entities/dashboard-widget-order/module.js +25 -0
  47. package/dist-sdk/src/entities/dashboard-widget-order/order.d.ts +31 -0
  48. package/dist-sdk/src/entities/dashboard-widget-order/order.js +102 -0
  49. package/dist-sdk/src/entities/dynamic-layout/lint.d.ts +7 -0
  50. package/dist-sdk/src/entities/dynamic-layout/lint.js +48 -0
  51. package/dist-sdk/src/entities/dynamic-layout/to-tf.js +2 -0
  52. package/dist-sdk/src/entities/element/from-tf.d.ts +1 -0
  53. package/dist-sdk/src/entities/element/from-tf.js +5 -21
  54. package/dist-sdk/src/entities/element/index.d.ts +1 -1
  55. package/dist-sdk/src/entities/element/module.js +2 -0
  56. package/dist-sdk/src/entities/element/to-tf.js +1 -0
  57. package/dist-sdk/src/entities/field/from-tf.d.ts +25 -2
  58. package/dist-sdk/src/entities/field/from-tf.js +119 -14
  59. package/dist-sdk/src/entities/relationship/from-tf.js +2 -2
  60. package/dist-sdk/src/entities/role/build.d.ts +3 -4
  61. package/dist-sdk/src/entities/search-table/build.d.ts +9 -3
  62. package/dist-sdk/src/entities/search-table/build.js +4 -4
  63. package/dist-sdk/src/entities/search-table/printer.js +3 -1
  64. package/dist-sdk/src/entities/search-table/to-tf.js +20 -2
  65. package/dist-sdk/src/entities/shared/context.d.ts +14 -1
  66. package/dist-sdk/src/entities/shared/filters/index.d.ts +24 -13
  67. package/dist-sdk/src/entities/shared/filters/index.js +12 -1
  68. package/dist-sdk/src/entities/shared/filters/print.d.ts +2 -0
  69. package/dist-sdk/src/entities/shared/filters/print.js +15 -6
  70. package/dist-sdk/src/entities/shared/filters/tf-codec.d.ts +4 -0
  71. package/dist-sdk/src/entities/shared/filters/tf-codec.js +16 -0
  72. package/dist-sdk/src/entities/shared/filters/types.d.ts +4 -0
  73. package/dist-sdk/src/entities/shared/tool-field-ref.d.ts +1 -1
  74. package/dist-sdk/src/entities/shared/tool-field-ref.js +2 -5
  75. package/dist-sdk/src/entities/task/from-tf.js +3 -3
  76. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.d.ts +3 -3
  77. package/dist-sdk/src/entities/view/agent-view-layout-from-tf.js +6 -4
  78. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.d.ts +4 -2
  79. package/dist-sdk/src/entities/view/agent-view-layout-to-tf.js +6 -1
  80. package/dist-sdk/src/entities/view/agent-view-layout.d.ts +14 -2
  81. package/dist-sdk/src/entities/view/custom-view-references.d.ts +33 -0
  82. package/dist-sdk/src/entities/view/custom-view-references.js +140 -0
  83. package/dist-sdk/src/entities/view/custom-view-validate.d.ts +16 -9
  84. package/dist-sdk/src/entities/view/custom-view-validate.js +38 -18
  85. package/dist-sdk/src/entities/view/from-tf.js +9 -0
  86. package/dist-sdk/src/entities/view/layout-lint.d.ts +26 -0
  87. package/dist-sdk/src/entities/view/layout-lint.js +50 -0
  88. package/dist-sdk/src/entities/view/to-tf.d.ts +2 -0
  89. package/dist-sdk/src/entities/view/to-tf.js +69 -47
  90. package/dist-sdk/src/entities/visual-flow/build.d.ts +8 -1
  91. package/dist-sdk/src/entities/visual-flow/from-tf.js +16 -0
  92. package/dist-sdk/src/entities/visual-flow/initiate.d.ts +12 -0
  93. package/dist-sdk/src/entities/visual-flow/initiate.js +12 -0
  94. package/dist-sdk/src/entities/visual-flow/module.js +52 -1
  95. package/dist-sdk/src/entities/visual-flow/to-tf.js +16 -2
  96. package/dist-sdk/src/entities/widget/from-tf.js +6 -6
  97. package/dist-sdk/src/graph/index.d.ts +4 -0
  98. package/dist-sdk/src/graph/index.js +1 -0
  99. package/dist-sdk/src/graph/modules.js +2 -0
  100. package/dist-sdk/src/graph/types.d.ts +36 -1
  101. package/package.json +2 -2
package/README.md CHANGED
@@ -28,10 +28,13 @@ folders:
28
28
 
29
29
  ```sh
30
30
  npm install @elementumai/edk
31
+ npm install --save-dev typescript
31
32
  ```
32
33
 
33
- Use Node 24 or newer. The npm package is the authoring SDK; the only public
34
- executable is `elementum`.
34
+ Use Node 24 or newer. TypeScript is what checks your files (`npx tsc --noEmit`);
35
+ the SDK brings the Node type definitions the workspace's `tsconfig.json` names.
36
+ The npm package is the authoring SDK; the only public executable is
37
+ `elementum`.
35
38
 
36
39
  ### Platform support
37
40
 
@@ -103,6 +106,7 @@ mkdir elementum-workspace
103
106
  cd elementum-workspace
104
107
  npm init -y
105
108
  npm install @elementumai/edk
109
+ npm install --save-dev typescript
106
110
  elementum auth login --profile <profile>
107
111
  elementum --profile=<profile> pull org --data-only
108
112
  cd <instance>/<organization>
@@ -369,13 +369,19 @@ function stampOwnedRefs(bag, identity, parentKind) {
369
369
  ...(identity.namespace !== undefined ? { parentNamespace: identity.namespace } : {}),
370
370
  }]));
371
371
  }
372
- /** Stamp the owning app's stable key and display name onto each skill token. */
372
+ /** Stamp the owning app's stable key, display name and namespace onto each skill token. */
373
373
  function stampSkillRefs(bag, identity) {
374
374
  if (bag === undefined)
375
375
  return undefined;
376
376
  const out = {};
377
377
  for (const [refName, ref] of Object.entries(bag)) {
378
- out[refName] = { ...ref, refName, parent: identity.refName, parentName: identity.name };
378
+ out[refName] = {
379
+ ...ref,
380
+ refName,
381
+ parent: identity.refName,
382
+ parentName: identity.name,
383
+ ...(identity.namespace !== undefined ? { parentNamespace: identity.namespace } : {}),
384
+ };
379
385
  }
380
386
  return out;
381
387
  }
@@ -78,6 +78,11 @@ export interface SkillRef extends CatalogRef<"skill"> {
78
78
  * owner identity needed to resolve `app_id` without exposing a platform id.
79
79
  */
80
80
  readonly parentName?: string;
81
+ /**
82
+ * Namespace of the owning app, when its catalog records one. A build looks
83
+ * an owner outside the workspace up by it, as ei's export does (edk#2919).
84
+ */
85
+ readonly parentNamespace?: string;
81
86
  /**
82
87
  * A raw platform id, when the export carries a `skill_ids`/
83
88
  * `preloaded_skill_ids` entry that resolves to neither a self-app resource
@@ -15,11 +15,23 @@
15
15
  * (edk#2250; the mapping is emitted, and the called workflow fails at run time)
16
16
  * - a synchronous Dynamic Reference runAutomation inside a forEach (edk#1870;
17
17
  * the task is emitted, and the caller never resumes at run time)
18
+ * - a live automation output that reads a task inside a switch case, for-each
19
+ * loop or fork/join branch (edk#2988; the output is emitted, and a republish
20
+ * fails the platform's publish check)
21
+ * - a record trigger's changedFields listing a platform-managed system field
22
+ * (edk#2989; the field is kept, and the platform never fires on its change)
18
23
  * - the custom-view non-PanesBlock root hint (check.mjs `warn`; the layout is
19
24
  * emitted exactly as authored, edk#1771)
25
+ * - a custom-view binding to a path missing from spec.state (the page reads it
26
+ * as undefined; the layout is emitted exactly as authored, edk#2923)
20
27
  * - the executeScript lint for an undeclared input, an output no return sets
21
28
  * (edk#2286), or a script with no top-level return (edk#2364); the script is
22
29
  * emitted as authored
30
+ * - the record details layout checks (edk#1774): an empty classic group, a
31
+ * group of more than 12 fields or of more than 8 at maxColumns 1, a
32
+ * right-panel section sharing a displayOrder with a main-area one, and in
33
+ * dynamic layouts an empty container or more than 8 stacked fields; the
34
+ * layout is emitted as authored
23
35
  *
24
36
  * The ~600 emit sites push free-form `"<where>: <what>; dropped"` strings.
25
37
  * Rather than rewrite every site, they are classified here, where they leave
@@ -15,11 +15,23 @@
15
15
  * (edk#2250; the mapping is emitted, and the called workflow fails at run time)
16
16
  * - a synchronous Dynamic Reference runAutomation inside a forEach (edk#1870;
17
17
  * the task is emitted, and the caller never resumes at run time)
18
+ * - a live automation output that reads a task inside a switch case, for-each
19
+ * loop or fork/join branch (edk#2988; the output is emitted, and a republish
20
+ * fails the platform's publish check)
21
+ * - a record trigger's changedFields listing a platform-managed system field
22
+ * (edk#2989; the field is kept, and the platform never fires on its change)
18
23
  * - the custom-view non-PanesBlock root hint (check.mjs `warn`; the layout is
19
24
  * emitted exactly as authored, edk#1771)
25
+ * - a custom-view binding to a path missing from spec.state (the page reads it
26
+ * as undefined; the layout is emitted exactly as authored, edk#2923)
20
27
  * - the executeScript lint for an undeclared input, an output no return sets
21
28
  * (edk#2286), or a script with no top-level return (edk#2364); the script is
22
29
  * emitted as authored
30
+ * - the record details layout checks (edk#1774): an empty classic group, a
31
+ * group of more than 12 fields or of more than 8 at maxColumns 1, a
32
+ * right-panel section sharing a displayOrder with a main-area one, and in
33
+ * dynamic layouts an empty container or more than 8 stacked fields; the
34
+ * layout is emitted as authored
23
35
  *
24
36
  * The ~600 emit sites push free-form `"<where>: <what>; dropped"` strings.
25
37
  * Rather than rewrite every site, they are classified here, where they leave
@@ -34,9 +46,20 @@ const ADVISORY_DIAGNOSTICS = [
34
46
  // edk#1870. The task and loop names are quoted as authored and may contain `"`, so match them with
35
47
  // [\s\S]* and anchor on the fixed rest of the message, end included (the label is a sanitized TF label).
36
48
  /^automation \S+: task "[\s\S]*" is a synchronous Dynamic Reference runAutomation inside forEach "[\s\S]*"; the platform never resumes the caller after the called automation finishes, so the steps after it never run and the run stays parked\. Move the call out of the forEach, or call a known automation by its catalog ref \(Select Automation\)$/,
49
+ /^automation \S+: field ".*" is set from .+, a (?:whole|Multi-Select)/,
50
+ // edk#2988. Output and task names are quoted as authored, so match them with [\s\S]*.
51
+ /^automation \S+: automation output "[\s\S]*" references task "[\s\S]*" inside a switch case, for-each loop or fork\/join branch; the platform's publish check accepts outputs only from top-level tasks/,
52
+ // edk#2989. Field names are quoted as authored; anchor on the fixed rest of the message.
53
+ /^automation \S+: changedFields lists system fields? [\s\S]*; the platform never fires a record trigger on a system field's change, so (?:this trigger never fires|only the other listed fields fire it)\. Kept as listed: removing a field would change what the trigger watches \(with none left, it fires on every change\)$/,
37
54
  /^automation \S+: executeScript ".*" (?:reads input|declares output|has no top-level return) /,
38
55
  /^applied-automation-revisions\.json .*; until then no automation is checked for an edit without a revision bump$/,
39
56
  /\.root: "[^"]*" is (?:untyped|a [A-Za-z0-9_]+); the root is usually a PanesBlock \(needed for record lists to open the details pane\)$/,
57
+ /: binds to "[^"]*", which is not in spec\.state, so it starts undefined\. Add an initial value there to set its default\.$/,
58
+ // edk#1774 record details layout checks (src/entities/view/layout-lint.ts, src/entities/dynamic-layout/lint.ts).
59
+ // Section names are quoted as authored, so match them with [\s\S]* and anchor on the fixed rest of the message.
60
+ /\.sections\[\d+\](?: \("[\s\S]*"\))?: group section (?:has no fields, widgets or agent, so the record page shows an empty section; add fields or remove it|holds \d+ fields; split them into labeled groups \(key fields first\) so the record page doesn't read as one long list|stacks \d+ fields in one column \(maxColumns: 1\); use maxColumns: 2 or split it into labeled groups)$/,
61
+ /\.sections\[\d+\](?: \("[\s\S]*"\))?: right-panel section shares displayOrder -?\d+ with main-area [\s\S]+; the platform reads sections back by displayOrder, so plan replaces this layout on every run\. Give each section its own displayOrder, counted across both panels$/,
62
+ /dynamicLayouts\.[\s\S]+\.components\.[\s\S]+: (?:(?:container|section|row|column|grid|card) has no children, so it renders empty; add components or remove it|(?:container|section|column|card) stacks \d+ fields in one column; put them in a grid \(columns: 2\) or split them into titled sections)$/,
40
63
  ];
41
64
  export function isAdvisoryDiagnostic(message) {
42
65
  return ADVISORY_DIAGNOSTICS.some((pattern) => pattern.test(message));
@@ -31,6 +31,14 @@ export declare class EiRunError extends Error {
31
31
  readonly stdout?: string;
32
32
  constructor(message: string, exitCode: number | null, stderr?: string, stdout?: string);
33
33
  }
34
+ /** Whether OpenTofu output reports a stale provider selection (edk#2946). */
35
+ export declare function mentionsStaleProviderSelection(text: string): boolean;
36
+ /**
37
+ * Whether a `runEiPassthrough` since the last take printed a stale provider
38
+ * selection diagnostic (edk#2946); clears it. Output handed to a terminal
39
+ * (`passthroughNeedsTerminal`) is not seen here.
40
+ */
41
+ export declare function takeStaleProviderSelection(): boolean;
34
42
  export declare function configureBridgeProfile(profile: string | undefined): void;
35
43
  export declare function configuredBridgeProfile(): string | undefined;
36
44
  export declare function managedElementumRoot(): string;
@@ -63,8 +63,41 @@ const LOCAL_HELP_TIMEOUT_MS = 1_500;
63
63
  let bridgeProfile;
64
64
  /** Convert the provider's default tflog text sink into EDK technical logs. */
65
65
  const TFLOG_LINE = /^time=(\S+)\s+level=(TRACE|DEBUG|INFO|WARN|ERROR)\s+msg="((?:\\.|[^"])*)"/;
66
- const TOFU_TRANSIENT_LINE = /^.+: (Reading|Still reading|Read complete after|Preparing import|Importing|Import complete|Import complete after|Refreshing state|Still refreshing|Refresh complete after|Creating|Still creating|Creation complete after|Modifying|Still modifying|Modification complete after|Destroying|Still destroying|Destruction complete after)(?:\.\.\.|\s)/;
66
+ /**
67
+ * A resource instance address as OpenTofu prints it before a progress verb:
68
+ * `elementum_app.x`, `data.elementum_field.y`, `module.m["k"].elementum_app.x[0]`,
69
+ * or a deposed instance (`elementum_app.x (deposed object 1a2b3c4d)`). A
70
+ * diagnostic header such as `Warning: Creating …` or `│ Error: Modifying …`
71
+ * is never an address, so it is not mistaken for progress (edk#2942). The Go
72
+ * bridge's `progressResourceLine` (cmd/elementum/terraform/executor.go) uses
73
+ * the same grammar.
74
+ */
75
+ const TOFU_ADDRESS_INDEX = String.raw `(?:\[(?:\d+|"(?:[^"\\]|\\.)*")\])?`;
76
+ const TOFU_RESOURCE_ADDRESS = String.raw `(?:module\.[A-Za-z_][\w-]*${TOFU_ADDRESS_INDEX}\.)*(?:data\.)?[A-Za-z_][\w-]*\.[A-Za-z_][\w-]*${TOFU_ADDRESS_INDEX}(?: \(deposed object [^)]+\))?`;
77
+ const TOFU_TRANSIENT_LINE = new RegExp(String.raw `^${TOFU_RESOURCE_ADDRESS}: (Reading|Still reading|Read complete after|Preparing import|Importing|Import complete|Import complete after|Refreshing state|Still refreshing|Refresh complete after|Creating|Still creating|Creation complete after|Modifying|Still modifying|Modification complete after|Destroying|Still destroying|Destruction complete after)(?:\.\.\.|\s)`);
67
78
  const ANSI_SEQUENCE = /\x1b\[[0-?]*[ -/]*[@-~]/g;
79
+ /**
80
+ * OpenTofu's diagnostics for a provider selection that no longer matches
81
+ * providers.tf: a lock pinning another version, or a locked package that is
82
+ * not installed. The same test as the bridge's `isStaleProviderSelection`
83
+ * (cmd/elementum/terraform/executor.go).
84
+ */
85
+ const STALE_PROVIDER_SELECTION = /Inconsistent dependency lock file|Required plugins are not installed/;
86
+ let staleProviderSelectionSeen = false;
87
+ /** Whether OpenTofu output reports a stale provider selection (edk#2946). */
88
+ export function mentionsStaleProviderSelection(text) {
89
+ return STALE_PROVIDER_SELECTION.test(withoutAnsi(text));
90
+ }
91
+ /**
92
+ * Whether a `runEiPassthrough` since the last take printed a stale provider
93
+ * selection diagnostic (edk#2946); clears it. Output handed to a terminal
94
+ * (`passthroughNeedsTerminal`) is not seen here.
95
+ */
96
+ export function takeStaleProviderSelection() {
97
+ const seen = staleProviderSelectionSeen;
98
+ staleProviderSelectionSeen = false;
99
+ return seen;
100
+ }
68
101
  function withoutAnsi(line) {
69
102
  return line.replace(ANSI_SEQUENCE, "");
70
103
  }
@@ -484,8 +517,14 @@ export function runEiPassthrough(args, opts) {
484
517
  loggedTofuLines.add(plain);
485
518
  writeTechnicalLog("DEBUG", "tofu", plain);
486
519
  };
520
+ // edk#2946: note a stale provider selection whatever else consumes the line.
521
+ const observed = (consume) => (line) => {
522
+ if (mentionsStaleProviderSelection(line))
523
+ staleProviderSelectionSeen = true;
524
+ return consume?.(line) ?? false;
525
+ };
487
526
  const output = Promise.all([
488
- routeEiOutput(child.stdout, opts?.stdout ?? process.stdout, opts?.bridge === true ? (line) => {
527
+ routeEiOutput(child.stdout, opts?.stdout ?? process.stdout, observed(opts?.bridge === true ? (line) => {
489
528
  const plain = withoutAnsi(line);
490
529
  const event = parseProgressEvent(line);
491
530
  if (event !== undefined) {
@@ -520,8 +559,8 @@ export function runEiPassthrough(args, opts) {
520
559
  // A bridge-versioned ei may still emit ordinary user-facing text
521
560
  // (for example "Using tofu") on stdout. Preserve it verbatim.
522
561
  return false;
523
- } : undefined, writeUserPayload),
524
- routeEiOutput(child.stderr, opts?.stderr ?? process.stderr, opts?.bridge === true ? (line) => {
562
+ } : undefined), writeUserPayload),
563
+ routeEiOutput(child.stderr, opts?.stderr ?? process.stderr, observed(opts?.bridge === true ? (line) => {
525
564
  const plain = withoutAnsi(line);
526
565
  const event = parseProgressEvent(line);
527
566
  if (event !== undefined) {
@@ -559,7 +598,7 @@ export function runEiPassthrough(args, opts) {
559
598
  // Preserve unrecognized stderr through the writer callback so the
560
599
  // caller-selected stderr destination is retained.
561
600
  return false;
562
- } : undefined, writeUserPayload),
601
+ } : undefined), writeUserPayload),
563
602
  ]);
564
603
  const forwardSignal = (signal) => child.kill(signal);
565
604
  process.once("SIGINT", forwardSignal);
@@ -1066,8 +1105,8 @@ export function parseTofuJsonEvent(line) {
1066
1105
  return { type: "other" };
1067
1106
  }
1068
1107
  }
1069
- const TOFU_PROGRESS_LINE = /^(.+?): (Reading|Still reading|Preparing import|Importing|Refreshing state|Still refreshing|Read complete after|Import complete after|Refresh complete after|Creating|Still creating|Creation complete after|Modifying|Still modifying|Modification complete after|Destroying|Still destroying|Destruction complete after)\b/;
1070
- const TOFU_PROGRESS_EVENT_LABEL = /^(Reading|Still reading|Preparing import|Importing|Refreshing state|Still refreshing|Read complete after|Import complete after|Refresh complete after|Creating|Still creating|Creation complete after|Modifying|Still modifying|Modification complete after|Destroying|Still destroying|Destruction complete after):\s+(.+)$/;
1108
+ const TOFU_PROGRESS_LINE = new RegExp(String.raw `^(${TOFU_RESOURCE_ADDRESS}): (Reading|Still reading|Preparing import|Importing|Refreshing state|Still refreshing|Read complete after|Import complete after|Refresh complete after|Creating|Still creating|Creation complete after|Modifying|Still modifying|Modification complete after|Destroying|Still destroying|Destruction complete after)\b`);
1109
+ const TOFU_PROGRESS_EVENT_LABEL = new RegExp(String.raw `^(Reading|Still reading|Preparing import|Importing|Refreshing state|Still refreshing|Read complete after|Import complete after|Refresh complete after|Creating|Still creating|Creation complete after|Modifying|Still modifying|Modification complete after|Destroying|Still destroying|Destruction complete after):\s+(${TOFU_RESOURCE_ADDRESS})$`);
1071
1110
  const TOFU_PROGRESS_STARTS = new Set([
1072
1111
  "Reading", "Preparing import", "Importing", "Refreshing state",
1073
1112
  "Creating", "Modifying", "Destroying",
@@ -138,5 +138,6 @@ export declare function liveProgressActive(): boolean;
138
138
  export declare function applyProgressEvent(event: ProgressEvent): void;
139
139
  export declare function renderTextEffects(text: string, effects: readonly TextEffect[] | undefined): string;
140
140
  export declare function green(text: string): PullResultSegment;
141
+ export declare function yellow(text: string): PullResultSegment;
141
142
  export declare function red(text: string): PullResultSegment;
142
143
  export declare function bold(text: string): PullResultSegment;
@@ -702,6 +702,12 @@ export function green(text) {
702
702
  };
703
703
  }
704
704
  ;
705
+ export function yellow(text) {
706
+ return {
707
+ text,
708
+ textEffects: [{ start: 0, end: text.length, color: "yellow" }],
709
+ };
710
+ }
705
711
  export function red(text) {
706
712
  return {
707
713
  text,
@@ -45,6 +45,15 @@ export interface FromTfContext {
45
45
  readonly appRefName: string;
46
46
  readonly skillRefName: string;
47
47
  }>;
48
+ /**
49
+ * Owner namespace + skill display name → materialized catalog skill ref.
50
+ * ei looks a skill's owner up by namespace alone, and a namespace is unique
51
+ * where a display name is not, so it wins when the export carries one (edk#2919).
52
+ */
53
+ readonly foreignSkillRefsByOwnerNamespace?: ReadonlyMap<string, {
54
+ readonly appRefName: string;
55
+ readonly skillRefName: string;
56
+ }>;
48
57
  readonly foreignElementRefNames?: ReadonlyMap<string, string>;
49
58
  readonly foreignTaskRefNames?: ReadonlyMap<string, string>;
50
59
  /** Imported platform field id -> typed owner/key, assembled by the recursive pull workspace context. */
@@ -54,6 +63,15 @@ export interface FromTfContext {
54
63
  readonly fieldName?: string;
55
64
  readonly fieldType?: string;
56
65
  }>;
66
+ /**
67
+ * `elementum_field.<label>` → platform id, for a `data "elementum_field"`
68
+ * lookup of one of the pulled owner's own fields that pull does not extract
69
+ * (#2815: ei looks up an element's Closed at / Closed by fields this way).
70
+ * A layout or view that names it keeps the field by this id, as for any
71
+ * other unextracted field (#1978), instead of dropping it. Absent: dropped
72
+ * as before.
73
+ */
74
+ readonly ownFieldIdsByDataAddress?: ReadonlyMap<string, string>;
57
75
  /** Platform table id -> typed org catalog identity, loaded by recursive pull when table refs are present. */
58
76
  readonly foreignTableRefsById?: ReadonlyMap<string, {
59
77
  readonly tableRefName: string;
@@ -263,6 +281,12 @@ export interface ExtractRequirement {
263
281
  readonly pruneOwnFile?: {
264
282
  readonly kind: EntityKindId;
265
283
  readonly prune: (items: readonly unknown[]) => readonly unknown[];
284
+ /**
285
+ * Set when `prune` removes the whole own-file item: its earlier authored
286
+ * file is archived once `address` is released, so the next plan doesn't
287
+ * create it again (#2892).
288
+ */
289
+ readonly archiveRefName?: string;
266
290
  };
267
291
  }
268
292
  /**
@@ -15,6 +15,8 @@ export interface ManagedResultVerdict {
15
15
  readonly gaps?: number;
16
16
  /** Live configuration left out of source on request (e.g. `--skip-unsupported-layouts`). */
17
17
  readonly omitted?: number;
18
+ /** Other problems the command reported without failing (e.g. a data-only org pull's failed workspace build). */
19
+ readonly warnings?: number;
18
20
  }
19
21
  export declare function managedResultStatus(operation: string, verdict: ManagedResultVerdict): ManagedResultStatus;
20
22
  /**
@@ -4,7 +4,7 @@ import { flushRepeatedTechnicalLogs, machineReadableLogsEnabled, renderTextEffec
4
4
  export function managedResultStatus(operation, verdict) {
5
5
  const outcome = verdict.failed === true
6
6
  ? "failure"
7
- : (verdict.skipped ?? 0) > 0 || (verdict.gaps ?? 0) > 0 || (verdict.omitted ?? 0) > 0
7
+ : (verdict.skipped ?? 0) > 0 || (verdict.gaps ?? 0) > 0 || (verdict.omitted ?? 0) > 0 || (verdict.warnings ?? 0) > 0
8
8
  ? "warning"
9
9
  : "success";
10
10
  return { operation, outcome };
@@ -35,6 +35,14 @@ export interface StreamRootExtract {
35
35
  readonly cloudLinkHandle?: string;
36
36
  /** Resource addresses in the stream that aren't extracted — reported, not fatal (plan §6). */
37
37
  readonly skipped: readonly string[];
38
+ /**
39
+ * Skipped address → the own-file child it belongs to (`skippedOwnFiles`,
40
+ * #1877), so the stale-path sweep keeps a skipped child's file (edk#2926).
41
+ */
42
+ readonly skippedOwners?: ReadonlyMap<string, {
43
+ readonly kind: EntityKindId;
44
+ readonly refName: string;
45
+ }>;
38
46
  /** Skipped addresses no authored source can ever manage; adoption releases any already in state (see OwnFileExtractResult). */
39
47
  readonly releaseIfManaged?: readonly string[];
40
48
  /** Own-file ref names whose authored files are archived because their state was released (#1858). */
@@ -110,10 +118,13 @@ export interface StreamRootExtractOptions {
110
118
  readonly options?: readonly string[];
111
119
  readonly systemStage?: true;
112
120
  }>;
121
+ /** See `FromTfContext.ownFieldIdsByDataAddress` (#2815). */
122
+ readonly ownFieldIdsByDataAddress?: FromTfContext["ownFieldIdsByDataAddress"];
113
123
  readonly foreignSkillRefsByOwnerName?: ReadonlyMap<string, {
114
124
  readonly appRefName: string;
115
125
  readonly skillRefName: string;
116
126
  }>;
127
+ readonly foreignSkillRefsByOwnerNamespace?: FromTfContext["foreignSkillRefsByOwnerNamespace"];
117
128
  readonly foreignTableRefsById?: ReadonlyMap<string, {
118
129
  readonly tableRefName: string;
119
130
  readonly name: string;
@@ -395,7 +395,9 @@ export function extractStreamRoot(doc, kindId, opts = {}) {
395
395
  ...(opts.cloning !== undefined ? { cloning: opts.cloning } : {}),
396
396
  foreignFieldRefsById: opts.foreignFieldRefsById,
397
397
  foreignFieldRefsByDataAddress: opts.foreignFieldRefsByDataAddress,
398
+ ...(opts.ownFieldIdsByDataAddress !== undefined && { ownFieldIdsByDataAddress: opts.ownFieldIdsByDataAddress }),
398
399
  foreignSkillRefsByOwnerName: opts.foreignSkillRefsByOwnerName,
400
+ foreignSkillRefsByOwnerNamespace: opts.foreignSkillRefsByOwnerNamespace,
399
401
  fieldNamesByOwnerRefName: opts.fieldNamesByOwnerRefName,
400
402
  // Root and own-file extractors both print group refs (edk#1412).
401
403
  groupKeysByName: opts.groupKeysByName,
@@ -468,7 +470,7 @@ export function extractStreamRoot(doc, kindId, opts = {}) {
468
470
  skippedOwners.set(address, { kind: child.kind, refName });
469
471
  }
470
472
  }
471
- rootInstance = dropDependentsOfSkipped(rootInstance, ownFileByKind, requiresExtracted, new Set(resources.keys()), skipped, releaseIfManaged, diagnostics, reports, opts.keptOwnFile);
473
+ rootInstance = dropDependentsOfSkipped(rootInstance, ownFileByKind, requiresExtracted, new Set(resources.keys()), skipped, releaseIfManaged, diagnostics, reports, opts.keptOwnFile, quarantineOwnFiles);
472
474
  if (settles.length > 0) {
473
475
  const settledRoot = rootInstance;
474
476
  const inSource = resourcesInSource({
@@ -487,6 +489,7 @@ export function extractStreamRoot(doc, kindId, opts = {}) {
487
489
  ownFileByKind,
488
490
  ...(root.cloudLinkHandle !== undefined && { cloudLinkHandle: root.cloudLinkHandle }),
489
491
  skipped,
492
+ ...(skippedOwners.size > 0 && { skippedOwners }),
490
493
  ...(releaseIfManaged.length > 0 && { releaseIfManaged }),
491
494
  ...(quarantineOwnFiles.length > 0 && { quarantineOwnFiles }),
492
495
  diagnostics,
@@ -521,39 +524,52 @@ export function extractApp(doc, opts = {}) {
521
524
  * adoption keeps managing it (SF3). That outcome is reported on the
522
525
  * informational `reports` channel, not as a coverage gap: nothing is lost.
523
526
  */
524
- function dropDependentsOfSkipped(root, ownFileByKind, requirements, streamAddresses, skipped, releaseIfManaged, diagnostics, reports, keptOwnFile) {
527
+ function dropDependentsOfSkipped(root, ownFileByKind, requirements, streamAddresses, skipped, releaseIfManaged, diagnostics, reports, keptOwnFile, quarantineOwnFiles = []) {
525
528
  const skippedSet = new Set(skipped);
529
+ // A released requirement's authored file is archived after adoption, so it
530
+ // can't keep its dependent buildable (#2892).
531
+ const releasedSet = new Set(releaseIfManaged);
526
532
  let pruned = root;
527
533
  for (const requirement of requirements) {
528
534
  if (skippedSet.has(requirement.address))
529
535
  continue;
530
- const reason = unbuildableReason(requirement, root, streamAddresses, skippedSet, keptOwnFile, reports);
536
+ const reason = unbuildableReason(requirement, root, streamAddresses, skippedSet, releasedSet, keptOwnFile, reports);
531
537
  if (reason === undefined)
532
538
  continue;
533
539
  pruned = requirement.prune(pruned);
534
540
  const ownFile = requirement.pruneOwnFile;
535
- if (ownFile !== undefined)
541
+ if (ownFile !== undefined) {
536
542
  ownFileByKind.set(ownFile.kind, ownFile.prune(ownFileByKind.get(ownFile.kind) ?? []));
543
+ if (ownFile.archiveRefName !== undefined) {
544
+ quarantineOwnFiles.push({ kind: ownFile.kind, refName: ownFile.archiveRefName, afterRelease: [requirement.address] });
545
+ }
546
+ }
537
547
  skipped.push(requirement.address);
538
548
  skippedSet.add(requirement.address);
539
549
  releaseIfManaged.push(requirement.address);
550
+ releasedSet.add(requirement.address);
540
551
  diagnostics.push(typedCoverageGap({
541
552
  kind: "skipped",
542
553
  entity: requirement.address,
543
554
  detail: `left out of the pull, skipped: ${reason}`,
544
- consequence: "it is not written to source or adopted, and adoption releases it if state already manages it; it keeps running on the platform unmanaged until a later pull extracts what it needs, which writes it back to source and adopts it again",
555
+ consequence: "it is not written to source or adopted, and adoption releases it if state already manages it; it keeps running on the platform unmanaged until a later pull extracts what it needs, which writes it back to source and adopts it again" +
556
+ (requirement.pruneOwnFile?.archiveRefName !== undefined
557
+ ? `. Its file from an earlier pull (${requirement.pruneOwnFile.kind} ${requirement.pruneOwnFile.archiveRefName}) is archived once adoption releases it; with --no-adopt, or if adoption fails first, that file stays until a pull that adopts`
558
+ : ""),
545
559
  }));
546
560
  }
547
561
  return pruned;
548
562
  }
549
563
  /** Why build will not emit `requirement`'s dependent, or undefined when it will. */
550
- function unbuildableReason(requirement, root, streamAddresses, skipped, keptOwnFile, reports) {
564
+ function unbuildableReason(requirement, root, streamAddresses, skipped, released, keptOwnFile, reports) {
551
565
  if (requirement.unresolved === true)
552
566
  return `it needs ${requirement.requires}, which is not a resource this pull extracts`;
553
567
  if (!streamAddresses.has(requirement.requires))
554
568
  return `it needs ${requirement.requires}, which is not in the export`;
555
569
  if (!skipped.has(requirement.requires))
556
570
  return undefined;
571
+ if (released.has(requirement.requires))
572
+ return `it needs ${requirement.requires}, which this pull skipped and releases`;
557
573
  const ownFile = requirement.requiresOwnFile;
558
574
  if (ownFile !== undefined && keptOwnFile?.(root, ownFile.kind, ownFile.refName) === true) {
559
575
  reports.push(`${requirement.address}: kept in source and adoption: ${requirement.requires} was not re-extracted this pull, but its authored ${ownFile.kind} file ${ownFile.refName}.ts is kept, so build still emits both`);
@@ -15,8 +15,13 @@ export declare function decodeTemplateEscapes(s: string): string;
15
15
  export declare function encodeTemplateEscapes(s: string): string;
16
16
  /**
17
17
  * Render a logical string as an HCL2 quoted string literal.
18
- * JSON string escaping is a subset of HCL2's quoted-string escapes
19
- * (\n, \t, \", \\, \uXXXX are all valid HCL); template introducers are
20
- * additionally doubled so they stay literal.
18
+ * JSON string escaping is almost a subset of HCL2's quoted-string escapes
19
+ * (\n, \r, \t, \", \\, \uXXXX are all valid HCL), but JSON also writes
20
+ * U+0008 as `\b` and U+000C as `\f`, which HCL2 rejects ("Invalid escape
21
+ * sequence"). Those two are rewritten as `\u0008` / `\u000c` (#3003): a live
22
+ * script can hold a real backspace where its author meant a regex `\b`.
23
+ * Template introducers are additionally doubled so they stay literal. A lone
24
+ * UTF-16 surrogate (JSON `\ud800`) has no UTF-8 form, so HCL still rejects it;
25
+ * plan fails loudly on that rather than writing something different.
21
26
  */
22
27
  export declare function quoteHclString(logical: string): string;
@@ -19,10 +19,23 @@ export function encodeTemplateEscapes(s) {
19
19
  }
20
20
  /**
21
21
  * Render a logical string as an HCL2 quoted string literal.
22
- * JSON string escaping is a subset of HCL2's quoted-string escapes
23
- * (\n, \t, \", \\, \uXXXX are all valid HCL); template introducers are
24
- * additionally doubled so they stay literal.
22
+ * JSON string escaping is almost a subset of HCL2's quoted-string escapes
23
+ * (\n, \r, \t, \", \\, \uXXXX are all valid HCL), but JSON also writes
24
+ * U+0008 as `\b` and U+000C as `\f`, which HCL2 rejects ("Invalid escape
25
+ * sequence"). Those two are rewritten as `\u0008` / `\u000c` (#3003): a live
26
+ * script can hold a real backspace where its author meant a regex `\b`.
27
+ * Template introducers are additionally doubled so they stay literal. A lone
28
+ * UTF-16 surrogate (JSON `\ud800`) has no UTF-8 form, so HCL still rejects it;
29
+ * plan fails loudly on that rather than writing something different.
25
30
  */
26
31
  export function quoteHclString(logical) {
27
- return JSON.stringify(encodeTemplateEscapes(logical));
32
+ // Walk JSON's escape pairs, so an escaped backslash followed by "b" (`\\b`)
33
+ // is never mistaken for a `\b` escape.
34
+ return JSON.stringify(encodeTemplateEscapes(logical)).replace(/\\(u[0-9a-fA-F]{4}|.)/g, (pair, escape) => {
35
+ if (escape === "b")
36
+ return "\\u0008";
37
+ if (escape === "f")
38
+ return "\\u000c";
39
+ return pair;
40
+ });
28
41
  }
@@ -53,6 +53,20 @@ export function isAuthoringHelperFile(fileName) {
53
53
  // `_1Foo`, `_3_1Bar` — managed entity refs, not helpers.
54
54
  return !/^\d/.test(stem.slice(1));
55
55
  }
56
+ /**
57
+ * The error for a non-entity file directly in an app, element, table, task or
58
+ * portal folder: name the file and how to make it a helper (#2897). A name that
59
+ * starts with "_" and a digit is an entity ref (#751), not a helper.
60
+ */
61
+ function helperFileMessage(rel, bag, refFolder, stem) {
62
+ // A "_" + letter stem is already a helper and never gets here. "_" + digit is
63
+ // an entity ref (#751), so a stem that starts with a digit, with or without
64
+ // the "_", needs a letter after the "_" to become a helper.
65
+ const suggestion = /^_?\d/.test(stem) ? `_helper_${stem.replace(/^_/, "")}` : `_${stem}`;
66
+ return (`${rel}: the only source file directly in ${bag}/${refFolder}/ is ${bag}/${refFolder}/${refFolder}.ts. ` +
67
+ `For a helper module that other files import, start its name with "_" and a letter (${bag}/${refFolder}/${suggestion}.ts): ` +
68
+ `files named that way are helpers, not ${bag}.`);
69
+ }
56
70
  /** Walk up from `startDir` to the nearest directory that contains `tsconfig.json`. */
57
71
  export function findOrgWorkspaceByTsconfig(startDir) {
58
72
  let cur = resolve(startDir);
@@ -89,7 +103,7 @@ export function assertRelativeAuthoringPath(relPath) {
89
103
  if (parts.length === 3) {
90
104
  const refFolder = parts[1];
91
105
  if (refFolder !== stem) {
92
- throw new Error(`Table file must be tables/${refFolder}/${refFolder}.ts, got ${rel}`);
106
+ throw new Error(helperFileMessage(rel, bag, refFolder, stem));
93
107
  }
94
108
  return;
95
109
  }
@@ -108,7 +122,7 @@ export function assertRelativeAuthoringPath(relPath) {
108
122
  if (parts.length === 3) {
109
123
  const refFolder = parts[1];
110
124
  if (refFolder !== stem) {
111
- throw new Error(`Aspect file must be ${bag}/${refFolder}/${refFolder}.ts, got ${rel}`);
125
+ throw new Error(helperFileMessage(rel, bag, refFolder, stem));
112
126
  }
113
127
  return;
114
128
  }
@@ -13,14 +13,12 @@
13
13
  import { EntityTfError } from "../../engine/entity.js";
14
14
  import { dataRefLabel, groupCatalogKey, resourceRefLabel } from "../../engine/pull/context.js";
15
15
  import { appResourceLabelPrefix, elementResourceLabelPrefix, isTfExpr, scopedResourceLabel, tfLabelToTsLabel, } from "../../engine/tf/index.js";
16
- import { SYSTEM_FIELD_KEY_SET } from "../../core/system-fields.js";
17
- import { bagKeyForPulledCustomField } from "../field/from-tf.js";
18
- import { ELEMENT_SYSTEM_FIELD_KEYS } from "../element/system-fields.js";
16
+ import { pulledFieldBagKey } from "../field/from-tf.js";
19
17
  import { filterFromTf as deserializeFilterFromTf } from "../shared/filters/tf-codec.js";
20
18
  import { groupId, userId, } from "./principal.js";
21
19
  import { KNOWN_ACCESS_POLICY_ATTRS } from "./types.js";
22
20
  import { finishPulledMemberList } from "./member-list.js";
23
- function fieldRef(value, owner, where) {
21
+ function fieldRef(value, owner, where, ctx) {
24
22
  if (isTfExpr(value) && value.$expr === "resource-attr" && value.type.endsWith("_field") && value.path[0] === "id") {
25
23
  // scopedLabelToBagKey's stripping is a documented no-op when the label
26
24
  // isn't actually prefixed for this owner (src/engine/tf/labels.ts) - it
@@ -33,8 +31,7 @@ function fieldRef(value, owner, where) {
33
31
  // final throw below can handle it instead of a silent wrong answer.
34
32
  const prefix = owner.scope === "element" ? elementResourceLabelPrefix(owner.ownerTfLabel) : appResourceLabelPrefix(owner.ownerTfLabel);
35
33
  if (value.label.startsWith(prefix)) {
36
- const reserved = owner.scope === "element" ? new Set(ELEMENT_SYSTEM_FIELD_KEYS) : SYSTEM_FIELD_KEY_SET;
37
- return { kind: "field", appHandle: owner.ownerRefName, fieldKey: bagKeyForPulledCustomField(owner.ownerTfLabel, value.label, owner.scope, reserved) };
34
+ return { kind: "field", appHandle: owner.ownerRefName, fieldKey: pulledFieldBagKey(owner.ownerTfLabel, value.label, owner.scope, ctx) };
38
35
  }
39
36
  }
40
37
  // A system field (status/title/id/stage/…) has no own resource block — ei
@@ -88,7 +85,7 @@ function picklistOptionLabel(value, owner) {
88
85
  export function filterFromTf(value, owner, where, ctx, options) {
89
86
  try {
90
87
  return deserializeFilterFromTf(value, {
91
- field: (fieldValue) => fieldRef(fieldValue, owner, where),
88
+ field: (fieldValue) => fieldRef(fieldValue, owner, where, ctx),
92
89
  reference: () => { throw new EntityTfError(`${where}: access-policy reference values are not supported`); },
93
90
  literal: (literal) => picklistOptionLabel(literal, owner) ?? stageName(literal, owner, ctx) ?? literal,
94
91
  ...(options?.optionLookupsAreIdentities === true && { optionLookupsAreIdentities: true }),
@@ -309,7 +309,8 @@ function printSkillRefToken(ref, appRefName, crossOrg) {
309
309
  const todo = crossOrg
310
310
  ? ` // TODO: cross-org clone — "${ref.name}" was resolved in the SOURCE org; verify it exists (with this name) in the destination org`
311
311
  : "";
312
- return `{ __kind: "skill", refName: ${quote(ref.name)}, name: ${quote(ref.name)}, parent: ${quote(ref.appRefName ?? ref.appName)}, parentName: ${quote(ref.appName)} },${todo}`;
312
+ const namespace = ref.appNamespace !== undefined ? `, parentNamespace: ${quote(ref.appNamespace)}` : "";
313
+ return `{ __kind: "skill", refName: ${quote(ref.name)}, name: ${quote(ref.name)}, parent: ${quote(ref.appRefName ?? ref.appName)}, parentName: ${quote(ref.appName)}${namespace} },${todo}`;
313
314
  }
314
315
  function printStartingActionVariableType(type) {
315
316
  if (type === "NUMBER")
@@ -26,6 +26,8 @@ export type NormalizedSkillRef = {
26
26
  readonly kind: "foreign";
27
27
  readonly name: string;
28
28
  readonly appName: string;
29
+ /** The owner's namespace, when ei looked the owner up by it (edk#2919). */
30
+ readonly appNamespace?: string;
29
31
  readonly appRefName?: string;
30
32
  readonly key?: string;
31
33
  } | {
@@ -14,7 +14,7 @@ import { filterFromTf } from "../access-policy/from-tf.js";
14
14
  import { a2aSkillFromTf } from "../agent-a2a-skill/from-tf.js";
15
15
  import { toolFromTf } from "../agent-tool/from-tf.js";
16
16
  import { agentToolBareLabel } from "../agent-tool/to-tf.js";
17
- import { resolveDataAspectTarget } from "../shared/aspect-target-from-tf.js";
17
+ import { dataAspectDisplayName, dataAspectRefName, resolveDataAspectTarget } from "../shared/aspect-target-from-tf.js";
18
18
  import { connectorIdentityFromTf } from "../shared/connector-from-tf.js";
19
19
  import { resolveToolFieldKey } from "../shared/tool-field-ref.js";
20
20
  import { APP_RESOURCE_TYPE } from "../app/module.js";
@@ -77,6 +77,33 @@ function parseSkillRef(item, where, ownerTfLabel, ctx) {
77
77
  const owner = ownerId === undefined ? undefined : ctx.importedResource?.(ownerId);
78
78
  appName = typeof owner?.attrs["name"] === "string" ? owner.attrs["name"] : undefined;
79
79
  }
80
+ // ei looks another app up by namespace alone (`data "elementum_app" { namespace }`),
81
+ // as for a service account's owner (#2197). The namespace is unique where
82
+ // a display name is not, so it alone picks the owner and its catalog
83
+ // skill (edk#2919).
84
+ const appNamespace = appName === undefined && appDataLabel !== undefined
85
+ ? ctx.dataAttrs?.(APP_RESOURCE_TYPE, appDataLabel)?.["namespace"]
86
+ : undefined;
87
+ if (typeof appNamespace === "string" && appNamespace !== "" && appDataLabel !== undefined) {
88
+ const catalogSkill = ctx.foreignSkillRefsByOwnerNamespace?.get(JSON.stringify([appNamespace, name]));
89
+ const ownerInWorkspace = ctx.foreignAppRefNamespaces?.get(appNamespace) !== undefined;
90
+ if (catalogSkill === undefined && !ownerInWorkspace) {
91
+ ctx.diagnostics.push(`${where}: data.${SKILL_RESOURCE_TYPE}.${item.label}: owner namespace "${appNamespace}" is not in the workspace or the export's ref-only catalog; ` +
92
+ "kept as a literal skill token looked up by that namespace — pull that app and re-pull for a catalog token");
93
+ }
94
+ // The workspace app with this namespace; else the namespace's catalog
95
+ // key, which is the app's refName once it is pulled.
96
+ const appRefName = dataAspectRefName(ctx, "app", appDataLabel);
97
+ return {
98
+ kind: "foreign",
99
+ name,
100
+ appName: dataAspectDisplayName(ctx, "app", appDataLabel) ?? appNamespace,
101
+ appNamespace,
102
+ ...(catalogSkill !== undefined
103
+ ? { appRefName: catalogSkill.appRefName, key: catalogSkill.skillRefName }
104
+ : appRefName !== undefined ? { appRefName } : {}),
105
+ };
106
+ }
80
107
  if (appName === undefined) {
81
108
  ctx.diagnostics.push(`${where}: data.${SKILL_RESOURCE_TYPE}.${item.label} has no resolvable app_id owner; dropped`);
82
109
  return undefined;