@intentius/chant 0.124.96 → 0.124.98

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 (237) hide show
  1. package/dist/audit/core.d.ts +29 -0
  2. package/dist/audit/core.d.ts.map +1 -1
  3. package/dist/audit/core.js +48 -11
  4. package/dist/audit/identity.d.ts +27 -0
  5. package/dist/audit/identity.d.ts.map +1 -0
  6. package/dist/audit/identity.js +36 -0
  7. package/dist/audit/report-html.d.ts +3 -1
  8. package/dist/audit/report-html.d.ts.map +1 -1
  9. package/dist/audit/report-html.js +1 -1
  10. package/dist/audit/report-model.d.ts +16 -0
  11. package/dist/audit/report-model.d.ts.map +1 -1
  12. package/dist/audit/report-model.js +5 -1
  13. package/dist/change-set-graph.d.ts +3 -1
  14. package/dist/change-set-graph.d.ts.map +1 -1
  15. package/dist/change-set-graph.js +7 -1
  16. package/dist/change-set.d.ts +5 -2
  17. package/dist/change-set.d.ts.map +1 -1
  18. package/dist/change-set.js +6 -3
  19. package/dist/ci-agent.d.ts +17 -0
  20. package/dist/ci-agent.d.ts.map +1 -1
  21. package/dist/ci-agent.js +32 -0
  22. package/dist/ci-comment-allow.d.ts +88 -0
  23. package/dist/ci-comment-allow.d.ts.map +1 -0
  24. package/dist/ci-comment-allow.js +178 -0
  25. package/dist/ci-comment-commands.d.ts +12 -0
  26. package/dist/ci-comment-commands.d.ts.map +1 -1
  27. package/dist/ci-comment-commands.js +22 -0
  28. package/dist/ci-control.d.ts +6 -1
  29. package/dist/ci-control.d.ts.map +1 -1
  30. package/dist/ci-control.js +6 -1
  31. package/dist/ci-product.d.ts +3 -0
  32. package/dist/ci-product.d.ts.map +1 -1
  33. package/dist/ci-product.js +3 -0
  34. package/dist/cli/commands/audit.d.ts +3 -1
  35. package/dist/cli/commands/audit.d.ts.map +1 -1
  36. package/dist/cli/commands/audit.js +23 -6
  37. package/dist/cli/commands/import.d.ts +8 -1
  38. package/dist/cli/commands/import.d.ts.map +1 -1
  39. package/dist/cli/commands/import.js +31 -6
  40. package/dist/cli/handlers/agent.d.ts.map +1 -1
  41. package/dist/cli/handlers/agent.js +12 -2
  42. package/dist/cli/handlers/pr-comment.d.ts +6 -0
  43. package/dist/cli/handlers/pr-comment.d.ts.map +1 -1
  44. package/dist/cli/handlers/pr-comment.js +12 -0
  45. package/dist/cli/handlers/promote.d.ts.map +1 -1
  46. package/dist/cli/handlers/promote.js +53 -6
  47. package/dist/cli/main.d.ts.map +1 -1
  48. package/dist/cli/main.js +29 -6
  49. package/dist/cli/parse-args.d.ts.map +1 -1
  50. package/dist/cli/parse-args.js +23 -0
  51. package/dist/cli/registry.d.ts +8 -0
  52. package/dist/cli/registry.d.ts.map +1 -1
  53. package/dist/cloud-lister/mask.d.ts +30 -1
  54. package/dist/cloud-lister/mask.d.ts.map +1 -1
  55. package/dist/cloud-lister/mask.js +66 -3
  56. package/dist/components/driver.d.ts +8 -1
  57. package/dist/components/driver.d.ts.map +1 -1
  58. package/dist/components/driver.js +1 -0
  59. package/dist/components/product-pipeline.d.ts +23 -1
  60. package/dist/components/product-pipeline.d.ts.map +1 -1
  61. package/dist/components/product-pipeline.js +40 -7
  62. package/dist/components/product-plan.d.ts +20 -0
  63. package/dist/components/product-plan.d.ts.map +1 -1
  64. package/dist/components/product-plan.js +11 -1
  65. package/dist/control/applied.d.ts +8 -1
  66. package/dist/control/applied.d.ts.map +1 -1
  67. package/dist/control/applied.js +18 -2
  68. package/dist/control/dispatch.d.ts +52 -0
  69. package/dist/control/dispatch.d.ts.map +1 -1
  70. package/dist/control/dispatch.js +140 -4
  71. package/dist/control/train.d.ts +198 -0
  72. package/dist/control/train.d.ts.map +1 -0
  73. package/dist/control/train.js +294 -0
  74. package/dist/deep-observation.js +2 -2
  75. package/dist/floor-table.data.d.ts.map +1 -1
  76. package/dist/floor-table.data.js +7 -1
  77. package/dist/graph-detail.d.ts +9 -0
  78. package/dist/graph-detail.d.ts.map +1 -1
  79. package/dist/graph-detail.js +38 -13
  80. package/dist/graph-refs.d.ts +233 -3
  81. package/dist/graph-refs.d.ts.map +1 -1
  82. package/dist/graph-refs.js +106 -15
  83. package/dist/lint/post-synth.d.ts +22 -0
  84. package/dist/lint/post-synth.d.ts.map +1 -1
  85. package/dist/lint/rules/declarable-naming-convention.d.ts +12 -0
  86. package/dist/lint/rules/declarable-naming-convention.d.ts.map +1 -1
  87. package/dist/lint/rules/declarable-naming-convention.js +38 -8
  88. package/dist/lint/rules/imported-source.d.ts +20 -0
  89. package/dist/lint/rules/imported-source.d.ts.map +1 -0
  90. package/dist/lint/rules/imported-source.js +27 -0
  91. package/dist/lint/rules/no-unused-declarable.d.ts.map +1 -1
  92. package/dist/lint/rules/no-unused-declarable.js +3 -0
  93. package/dist/op/gate.d.ts +2 -0
  94. package/dist/op/gate.d.ts.map +1 -1
  95. package/dist/op/gate.js +8 -1
  96. package/dist/pr-forge-reads.d.ts +17 -0
  97. package/dist/pr-forge-reads.d.ts.map +1 -1
  98. package/dist/pr-forge-reads.js +55 -0
  99. package/dist/reconcile.d.ts +9 -0
  100. package/dist/reconcile.d.ts.map +1 -1
  101. package/dist/release-floors.d.ts +9 -1
  102. package/dist/release-floors.d.ts.map +1 -1
  103. package/dist/release-floors.js +10 -2
  104. package/dist/repo-path.d.ts +29 -0
  105. package/dist/repo-path.d.ts.map +1 -0
  106. package/dist/repo-path.js +81 -0
  107. package/dist/sensitive-key.d.ts +23 -0
  108. package/dist/sensitive-key.d.ts.map +1 -1
  109. package/dist/sensitive-key.js +37 -0
  110. package/dist/terraform/hcl2json.d.ts +7 -0
  111. package/dist/terraform/hcl2json.d.ts.map +1 -1
  112. package/dist/terraform/hcl2json.js +7 -0
  113. package/dist/wave-runtime.mjs +352 -345
  114. package/dist/workspace/catalog-edges.d.ts +147 -0
  115. package/dist/workspace/catalog-edges.d.ts.map +1 -0
  116. package/dist/workspace/catalog-edges.js +461 -0
  117. package/dist/workspace/compose-graph.d.ts +73 -3
  118. package/dist/workspace/compose-graph.d.ts.map +1 -1
  119. package/dist/workspace/declaration.d.ts +2 -0
  120. package/dist/workspace/declaration.d.ts.map +1 -1
  121. package/dist/workspace/declaration.js +1 -0
  122. package/dist/workspace/declaration.schema.json +6 -0
  123. package/dist/workspace/discover.d.ts +134 -0
  124. package/dist/workspace/discover.d.ts.map +1 -0
  125. package/dist/workspace/discover.js +372 -0
  126. package/dist/workspace/graph-cli.d.ts +20 -0
  127. package/dist/workspace/graph-cli.d.ts.map +1 -1
  128. package/dist/workspace/graph-cli.js +178 -20
  129. package/dist/workspace/graph.schema.json +195 -2
  130. package/dist/workspace/release-train.d.ts +214 -3
  131. package/dist/workspace/release-train.d.ts.map +1 -1
  132. package/dist/workspace/release-train.js +552 -16
  133. package/dist/workspace/repo-ref.d.ts +14 -0
  134. package/dist/workspace/repo-ref.d.ts.map +1 -1
  135. package/dist/workspace/repo-ref.js +26 -1
  136. package/dist/workspace/workspace-gates.d.ts +24 -0
  137. package/dist/workspace/workspace-gates.d.ts.map +1 -1
  138. package/dist/workspace/workspace-gates.js +29 -5
  139. package/dist/workspace/workspace-ledger.d.ts +31 -5
  140. package/dist/workspace/workspace-ledger.d.ts.map +1 -1
  141. package/dist/workspace/workspace-ledger.js +2 -1
  142. package/dist/workspace/workspace-run.d.ts +14 -0
  143. package/dist/workspace/workspace-run.d.ts.map +1 -1
  144. package/dist/workspace/workspace-run.js +2 -2
  145. package/dist/yaml.d.ts.map +1 -1
  146. package/dist/yaml.js +33 -8
  147. package/package.json +1 -1
  148. package/src/audit/core.test.ts +64 -1
  149. package/src/audit/core.ts +75 -10
  150. package/src/audit/identity.test.ts +31 -0
  151. package/src/audit/identity.ts +43 -0
  152. package/src/audit/report-html.ts +4 -2
  153. package/src/audit/report-model.ts +21 -1
  154. package/src/change-set-graph.test.ts +33 -1
  155. package/src/change-set-graph.ts +7 -1
  156. package/src/change-set.ts +6 -3
  157. package/src/ci-agent.test.ts +32 -0
  158. package/src/ci-agent.ts +42 -0
  159. package/src/ci-comment-allow.test.ts +380 -0
  160. package/src/ci-comment-allow.ts +184 -0
  161. package/src/ci-comment-commands.ts +25 -0
  162. package/src/ci-control.ts +42 -0
  163. package/src/ci-product.ts +3 -0
  164. package/src/cli/commands/audit-parser-notice.test.ts +74 -0
  165. package/src/cli/commands/audit.test.ts +12 -0
  166. package/src/cli/commands/audit.ts +25 -7
  167. package/src/cli/commands/import-layout.test.ts +2 -1
  168. package/src/cli/commands/import.ts +29 -6
  169. package/src/cli/handlers/agent.ts +13 -2
  170. package/src/cli/handlers/pr-before-merge.test.ts +18 -0
  171. package/src/cli/handlers/pr-comment.ts +12 -0
  172. package/src/cli/handlers/promote.test.ts +68 -0
  173. package/src/cli/handlers/promote.ts +52 -6
  174. package/src/cli/main.test.ts +5 -0
  175. package/src/cli/main.ts +29 -6
  176. package/src/cli/parse-args.ts +18 -0
  177. package/src/cli/registry.ts +8 -0
  178. package/src/cloud-lister/kubernetes.k3d.e2e.test.ts +104 -0
  179. package/src/cloud-lister/mask-references.test.ts +132 -0
  180. package/src/cloud-lister/mask.ts +68 -3
  181. package/src/components/driver.ts +9 -1
  182. package/src/components/product-pipeline.ts +57 -7
  183. package/src/components/product-plan.ts +27 -2
  184. package/src/control/applied.ts +33 -3
  185. package/src/control/dispatch.ts +156 -5
  186. package/src/control/train.test.ts +215 -0
  187. package/src/control/train.ts +413 -0
  188. package/src/deep-observation.ts +2 -2
  189. package/src/floor-table.data.ts +7 -1
  190. package/src/graph-detail.ts +37 -12
  191. package/src/graph-refs.test.ts +45 -1
  192. package/src/graph-refs.ts +321 -14
  193. package/src/lint/post-synth.ts +20 -0
  194. package/src/lint/rules/declarable-naming-convention.test.ts +35 -1
  195. package/src/lint/rules/declarable-naming-convention.ts +35 -8
  196. package/src/lint/rules/imported-source.test.ts +22 -0
  197. package/src/lint/rules/imported-source.ts +31 -0
  198. package/src/lint/rules/no-unused-declarable.test.ts +16 -0
  199. package/src/lint/rules/no-unused-declarable.ts +7 -0
  200. package/src/op/gate.ts +10 -2
  201. package/src/pr-forge-reads.ts +62 -0
  202. package/src/reconcile.ts +9 -0
  203. package/src/release-floors.ts +14 -2
  204. package/src/repo-path.test.ts +72 -0
  205. package/src/repo-path.ts +103 -0
  206. package/src/sensitive-key.ts +38 -0
  207. package/src/terraform/hcl2json.ts +8 -0
  208. package/src/workspace/application-set.e2e.test.ts +405 -0
  209. package/src/workspace/catalog-edges.ts +507 -0
  210. package/src/workspace/ci-green-workflow.test.ts +2 -2
  211. package/src/workspace/cluster-join.e2e.test.ts +150 -0
  212. package/src/workspace/compose-graph.ts +74 -5
  213. package/src/workspace/declaration.schema.json +6 -0
  214. package/src/workspace/declaration.ts +3 -0
  215. package/src/workspace/discover.e2e.test.ts +122 -0
  216. package/src/workspace/discover.test.ts +225 -0
  217. package/src/workspace/discover.ts +406 -0
  218. package/src/workspace/drift-reader.test.ts +3 -3
  219. package/src/workspace/external-secret-catalog.e2e.test.ts +98 -0
  220. package/src/workspace/external-secret-catalog.test.ts +142 -0
  221. package/src/workspace/graph-cli.ts +207 -21
  222. package/src/workspace/graph-contract.test.ts +92 -0
  223. package/src/workspace/graph.schema.json +195 -2
  224. package/src/workspace/helm-references.e2e.test.ts +135 -0
  225. package/src/workspace/identity-annotation-catalog.e2e.test.ts +91 -0
  226. package/src/workspace/identity-annotation-catalog.test.ts +139 -0
  227. package/src/workspace/release-train-repos.test.ts +304 -0
  228. package/src/workspace/release-train.test.ts +296 -0
  229. package/src/workspace/release-train.ts +631 -16
  230. package/src/workspace/repo-ref.ts +26 -1
  231. package/src/workspace/runs-on.test.ts +45 -0
  232. package/src/workspace/workspace-gates.ts +48 -5
  233. package/src/workspace/workspace-ledger.ts +28 -5
  234. package/src/workspace/workspace-run.test.ts +1 -1
  235. package/src/workspace/workspace-run.ts +2 -2
  236. package/src/yaml.test.ts +96 -8
  237. package/src/yaml.ts +36 -8
@@ -26,15 +26,17 @@
26
26
  import { execFileSync } from "node:child_process";
27
27
  import { existsSync, mkdirSync, mkdtempSync, rmSync, symlinkSync } from "node:fs";
28
28
  import { tmpdir } from "node:os";
29
- import { dirname, join, resolve } from "node:path";
29
+ import { dirname, isAbsolute, join, resolve } from "node:path";
30
30
  import { formatError } from "../cli/format.js";
31
31
  import { INSTANCE_ROLLUP_CODES } from "../instance-nodes.js";
32
32
  import { graphBox, plantability } from "./box-factory.js";
33
33
  import { composedId, composeWorkspaceGraph, readMemberIr } from "./compose-graph.js";
34
+ import { placeCatalogPass, runCatalogPass, runsOnEdges } from "./catalog-edges.js";
35
+ import { detailIdMap } from "../graph-detail.js";
34
36
  import { isViewDocument, prefixView } from "../capabilities/view.js";
35
37
  import { refusedCapabilityView } from "./nested-graph.js";
36
38
  import { openGraphCache, planStamps, splitCached, storeReads, withoutUnits } from "./graph-cache.js";
37
- import { readDeclaration, readerVersion, WORKSPACE_ERROR_CODES, WorkspaceReadError } from "./declaration.js";
39
+ import { DECLARATION_FILES, readDeclaration, readerVersion, WORKSPACE_ERROR_CODES, WorkspaceReadError } from "./declaration.js";
38
40
  import { describePlan, emitDocument, executePlan, memberStatus, planJson, planMembers } from "./member-commands.js";
39
41
  import { loadKindRegistry, REPO_KIND } from "./kinds.js";
40
42
  import { repoIdentity } from "./repo-ref.js";
@@ -43,6 +45,7 @@ import { prepareKindReaders } from "./kind-readers.js";
43
45
  import { recordLinkRows } from "./record-assets.js";
44
46
  import { RecordReadError } from "./records.js";
45
47
  import { workingTree } from "./tree.js";
48
+ import { declares, discover, discoveredTree, discoveredWorkspaceName, discoveryKinds, locateDiscovered } from "./discover.js";
46
49
  import { handToRootChant, locateWorkspace } from "./which-chant.js";
47
50
  /** The version of the `graph` document this chant writes. */
48
51
  export const GRAPH_CONTRACT_VERSION = 1;
@@ -57,7 +60,7 @@ export const GRAPH_ERROR_CODES = [...WORKSPACE_ERROR_CODES, "live-at-revision"];
57
60
  export const GRAPH_INSTANCE_ROLLUP_CODES = INSTANCE_ROLLUP_CODES;
58
61
  /** Why `--live` and `--at` don't go together (#2875). */
59
62
  const LIVE_AT_REVISION = "--live reads the account as it stands now, and --at reads the source at a revision; chant workspace graph takes one of them";
60
- const USAGE = "chant workspace graph [dir] [--at <rev>] [--member <name>] [--kind <kind file>] [-o <file>] [--env <env>] [--live [--overlay] [--traffic <level>]] [--no-cache] [--dry-run] | chant workspace graph --composites [--at <rev>] [--member <name>] [-o <file>] | chant workspace graph --intent <path[:start-end]|path#symbol|member/node|sha> [--at <rev>] [--kind <kind file>...] [--follow-squash] [--json]";
63
+ const USAGE = "chant workspace graph [dir] [--discover [--runs-on <member>=<member>/<address>]...] [--at <rev>] [--member <name>] [--kind <kind file>] [-o <file>] [--env <env>] [--live [--overlay] [--traffic <level>]] [--no-cache] [--dry-run] | chant workspace graph --composites [--at <rev>] [--member <name>] [-o <file>] | chant workspace graph --intent <path[:start-end]|path#symbol|member/node|sha> [--at <rev>] [--kind <kind file>...] [--follow-squash] [--json]";
61
64
  /** The command line a member runs for its component graph (#2662). */
62
65
  export function componentGraphArgv(args) {
63
66
  return ["graph", ".", "--components", "--format", "ir", ...(args.env ? ["--env", args.env] : [])];
@@ -154,12 +157,39 @@ function compose(plan, results, only, declarationMembers, live = false, capabili
154
157
  }
155
158
  return { inputs, failed };
156
159
  }
157
- /** Plan a graph read without running anything, for `--dry-run`. Throws a {@link WorkspaceReadError}. */
158
- export function planGraph(query) {
160
+ /**
161
+ * The declaration a read covers and the kinds it reads with. With
162
+ * `discover`, and no declaration in `cwd` itself, the members are found by
163
+ * probe and the declaration is held in memory. Throws a {@link WorkspaceReadError}.
164
+ */
165
+ function readSource(query) {
166
+ if (query.discover) {
167
+ const where = locateDiscovered(query.cwd, query.at);
168
+ if (!declares(where.base)) {
169
+ const kinds = discoveryKinds();
170
+ const found = discover(where.base, kinds, discoveredWorkspaceName(where.rootOnDisk), query.runsOn);
171
+ const tree = discoveredTree(where.base, found.declaration);
172
+ const declaration = readDeclaration(tree, "", { rootChant: true });
173
+ return {
174
+ located: { ...where, tree },
175
+ declaration,
176
+ kinds: kinds.registry,
177
+ kindProblems: kinds.problems,
178
+ treeAt: (dir) => discoveredTree(workingTree(dir), found.declaration),
179
+ discovered: found.entries,
180
+ };
181
+ }
182
+ }
159
183
  const located = locateWorkspace(query.cwd, query.at);
160
184
  const declaration = readDeclaration(located.tree, "", { rootChant: true });
185
+ // Kinds are read before planning: a package kind with a graph block runs (#2874).
161
186
  const { registry: kinds, problems } = loadKindRegistry(declaration.pins, located.rootOnDisk);
162
- return planMembers("graph", located.rootOnDisk, { only: query.members, reader: query.reader, tree: located.tree, kinds, kindProblems: problems.map((p) => p.message) });
187
+ return { located, declaration, kinds, kindProblems: problems.map((p) => p.message), treeAt: workingTree };
188
+ }
189
+ /** Plan a graph read without running anything, for `--dry-run`. Throws a {@link WorkspaceReadError}. */
190
+ export function planGraph(query) {
191
+ const { located, kinds, kindProblems } = readSource(query);
192
+ return planMembers("graph", located.rootOnDisk, { only: query.members, reader: query.reader, tree: located.tree, kinds, kindProblems });
163
193
  }
164
194
  /**
165
195
  * Plan the members a workspace read covers, run each under its own toolchain
@@ -174,11 +204,7 @@ export async function readMembers(query, options) {
174
204
  let exported;
175
205
  let readers;
176
206
  try {
177
- const located = locateWorkspace(query.cwd, query.at);
178
- const declaration = readDeclaration(located.tree, "", { rootChant: true });
179
- // Kinds are read before planning: a package kind with a graph block runs (#2874).
180
- const { registry: kinds, problems } = loadKindRegistry(declaration.pins, located.rootOnDisk);
181
- const kindProblems = problems.map((p) => p.message);
207
+ const { located, declaration, kinds, kindProblems, treeAt, discovered } = readSource(query);
182
208
  let plan = planMembers("graph", located.rootOnDisk, { only: query.members, reader: query.reader, tree: located.tree, kinds, kindProblems });
183
209
  const args = (query.args ?? {});
184
210
  // Members whose last source read still stands are answered from the cache (#2876).
@@ -189,7 +215,7 @@ export async function readMembers(query, options) {
189
215
  const served = new Set(split?.hits.map((h) => h.id));
190
216
  if (located.at !== null && withoutUnits(plan, served).groups.length > 0) {
191
217
  exported = exportRevision(located, withoutUnits(plan, served).groups.flatMap((g) => g.units.map((u) => u.dir)));
192
- plan = planMembers("graph", exported, { only: query.members, reader: query.reader, tree: workingTree(exported), kinds, kindProblems });
218
+ plan = planMembers("graph", exported, { only: query.members, reader: query.reader, tree: treeAt(exported), kinds, kindProblems });
193
219
  }
194
220
  // Only the members that run get a reader project; a served member needs none.
195
221
  const toRun = withoutUnits(plan, served);
@@ -210,7 +236,7 @@ export async function readMembers(query, options) {
210
236
  for (const r of results)
211
237
  if (r.stderr.trim() && query.onStderr)
212
238
  query.onStderr(r.stderr.endsWith("\n") ? r.stderr : `${r.stderr}\n`);
213
- return { located, declaration, kinds, plan, results, served, stamps, ...(components ? { components } : {}) };
239
+ return { located, declaration, kinds, plan, results, served, stamps, ...(components ? { components } : {}), ...(discovered ? { discovered } : {}) };
214
240
  }
215
241
  finally {
216
242
  readers?.cleanup();
@@ -240,7 +266,7 @@ export async function workspaceGraph(query) {
240
266
  return { doc: { ...head, error: { code: "live-at-revision", message: LIVE_AT_REVISION, location: null } }, failed: true };
241
267
  }
242
268
  try {
243
- const { located, declaration, kinds, plan, results, served, stamps, components } = await readMembers(query, { cache: true });
269
+ const { located, declaration, kinds, plan, results, served, stamps, components, discovered } = await readMembers(query, { cache: true });
244
270
  const args = (query.args ?? {});
245
271
  const { inputs, failed } = compose(plan, results, query.members, declaration.members, !!args.live, !!args.capabilityView);
246
272
  for (const { member } of inputs) {
@@ -252,6 +278,9 @@ export async function workspaceGraph(query) {
252
278
  // Links (#2539) resolve against the declaration that was read, the revision's for --at, and the kinds installed now.
253
279
  // A kind's link reader (#3932) reads the member's files in the tree read, as check does.
254
280
  const graph = composeWorkspaceGraph({ name: declaration.name, root: located.root, repo: repoIdentity(located.rootOnDisk) }, inputs, { declaration, kinds, read: readKindLinks(declaration, located.tree, kinds) });
281
+ // The reference catalogs over the composed graph (#5097), on full attributes whatever --detail asks for.
282
+ if (query.catalog && !args.live)
283
+ await addCatalogEdges(graph, query, args, { workspace: graph.workspace, inputs, located, runsOn: runsOnOf(declaration.members) });
255
284
  // The box's factory and listing (#3146), from the declaration read, so --at gives them at that revision.
256
285
  for (const member of graph.members)
257
286
  member.box = graphBox(declaration.members.find((m) => m.name === member.name)?.box ?? null, located.tree, declaration.members);
@@ -276,7 +305,12 @@ export async function workspaceGraph(query) {
276
305
  query.onStderr?.(`${formatError({ message: `--kind ${query.kind}: ${err.code}: ${err.message}`, hint: USAGE })}\n`);
277
306
  }
278
307
  }
279
- return { doc: { ...head, at: located.at, plantable: plantability(declaration), ...graph }, failed: failed || recordsFailed || nestedFailed, ...(components ? { components } : {}) };
308
+ // A discovered read lists every directory a kind claims (#5095), the ones that are not members included.
309
+ return {
310
+ doc: { ...head, at: located.at, plantable: plantability(declaration), ...graph, ...(discovered ? { discovered } : {}) },
311
+ failed: failed || recordsFailed || nestedFailed,
312
+ ...(components ? { components } : {}),
313
+ };
280
314
  }
281
315
  catch (err) {
282
316
  if (!(err instanceof WorkspaceReadError))
@@ -284,6 +318,115 @@ export async function workspaceGraph(query) {
284
318
  return { doc: { ...head, error: { code: err.code, message: err.message, location: err.location ?? null } }, failed: true };
285
319
  }
286
320
  }
321
+ /** The reference catalog of each lexicon that has one, best effort: a lexicon that does not load has none. */
322
+ async function loadCatalogs(lexicons) {
323
+ const { loadPlugin } = await import("../cli/plugins.js");
324
+ const out = [];
325
+ for (const lexicon of lexicons) {
326
+ try {
327
+ const catalog = (await loadPlugin(lexicon)).referenceCatalog;
328
+ if (catalog)
329
+ out.push({ lexicon, catalog });
330
+ }
331
+ catch {
332
+ // Not installed where this chant can load it: its nodes get no derived edges.
333
+ }
334
+ }
335
+ return out;
336
+ }
337
+ /**
338
+ * The catalog pass (#5097): load the catalogs of the lexicons the graph
339
+ * holds, read the members again at `--detail 3` when the document is printed
340
+ * at another tier, since the rules read nested attributes (`spec`,
341
+ * `metadata`) that the lower tiers leave out, run the pass over those nodes
342
+ * and place what it finds on the document's nodes.
343
+ */
344
+ async function addCatalogEdges(graph, query, args, read) {
345
+ const lexicons = [...new Set(graph.nodes.map((n) => n.lexicon))].sort();
346
+ const catalogs = await loadCatalogs(lexicons);
347
+ const level = (args.detail ?? 2);
348
+ let full = read.inputs;
349
+ if (catalogs.length > 0 && level !== 3) {
350
+ // With no stderr and no capability view: the document's own read has
351
+ // passed on what the members said already.
352
+ const again = await readMembers({ ...query, args: { ...args, detail: 3, capabilityView: false }, onStderr: undefined, inTree: undefined, components: false }, { cache: true });
353
+ full = compose(again.plan, again.results, query.members, again.declaration.members).inputs;
354
+ }
355
+ const printed = new Set(read.inputs.filter((i) => i.ir).map((i) => i.member.name));
356
+ const readable = full.filter((i) => i.ir && printed.has(i.member.name)).map((i) => ({ member: { ...i.member }, ir: i.ir }));
357
+ const nodes = catalogs.length > 0 ? composeWorkspaceGraph(read.workspace, readable).nodes : [];
358
+ const placed = new Map();
359
+ for (const { member, ir } of readable) {
360
+ for (const [id, at] of detailIdMap(ir, level))
361
+ placed.set(composedId(member.name, id), composedId(member.name, at));
362
+ }
363
+ const pass = runCatalogPass(nodes, catalogs, catalogs.length > 0 ? readable.map((i) => i.member.name) : [], repoPathLookup(read.located, read.workspace.repo ?? null), treeFileReader(read.located));
364
+ // The declared cluster each member runs on (#5101): its edges are drawn first, so a Secret they join is not also derived or left dangling.
365
+ const declared = runsOnEdges(nodes, read.runsOn, catalogs);
366
+ for (const problem of declared.problems)
367
+ query.onStderr?.(`warning: ${problem}\n`);
368
+ pass.dangling = pass.dangling.filter((d) => !(declared.joined.has(d.from) && pass.rules[d.rule]?.relation === "reference"));
369
+ graph.edges = [...graph.edges, ...declared.edges.map((e) => ({ ...e, from: placed.get(e.from) ?? e.from, to: placed.get(e.to) ?? e.to })).filter((e) => e.from !== e.to)];
370
+ placeCatalogPass(graph, pass, placed, level);
371
+ }
372
+ /** A repository URL with its scheme, credentials, `.git` and case taken off, so two spellings of one repository compare equal. */
373
+ export function repoKey(url) {
374
+ let u = url.trim().toLowerCase();
375
+ u = u.replace(/^[a-z][a-z0-9+.-]*:\/\//, "").replace(/^[^@/]+@/, "");
376
+ // scp-like `host:owner/repo` is `host/owner/repo`.
377
+ u = u.replace(/^([^/:]+):(?!\d+\/)/, "$1/").replace(/^([^/:]+):\d+\//, "$1/");
378
+ return u.replace(/\/+$/, "").replace(/\.git$/, "");
379
+ }
380
+ /**
381
+ * Where a path rule's path is (#5102): read in the tree the workspace was
382
+ * read from, when the path's repository is the workspace's own (its origin)
383
+ * and the path is under the workspace root. A path in any other repository,
384
+ * or with no origin to compare with, is not read.
385
+ */
386
+ function repoPathLookup(located, repo) {
387
+ if (repo === null)
388
+ return undefined;
389
+ const own = repoKey(repo);
390
+ const root = located.root;
391
+ if (isAbsolute(root))
392
+ return undefined;
393
+ return (ref) => {
394
+ if (repoKey(ref.repo) !== own)
395
+ return undefined;
396
+ let path = ref.value;
397
+ if (root !== "." && root !== "") {
398
+ if (path !== root && !path.startsWith(`${root}/`))
399
+ return undefined;
400
+ path = path.slice(root.length + 1);
401
+ }
402
+ if (path === "")
403
+ return "dir";
404
+ return located.tree.stat(path) ?? "missing";
405
+ };
406
+ }
407
+ /**
408
+ * A workspace-relative file's text from the tree the workspace is read from,
409
+ * for the files a generated node names (#5094), or undefined when it is not
410
+ * a file there or cannot be read.
411
+ */
412
+ function treeFileReader(located) {
413
+ return (path) => {
414
+ if (path === "" || path.startsWith("/") || path.split("/").includes(".."))
415
+ return undefined;
416
+ if (located.tree.stat(path) !== "file")
417
+ return undefined;
418
+ try {
419
+ return located.tree.read(path);
420
+ }
421
+ catch {
422
+ return undefined;
423
+ }
424
+ };
425
+ }
426
+ /** The `runsOn` each declared member sets, by member name (#5101). */
427
+ function runsOnOf(members) {
428
+ return new Map(members.filter((m) => m.runsOn !== null).map((m) => [m.name, m.runsOn]));
429
+ }
287
430
  /**
288
431
  * Expand every member of kind `workspace` the query covers, read-only (#2551,
289
432
  * ws-071), and every member of kind `repo` the same way, at its pinned
@@ -347,10 +490,22 @@ export async function runWorkspaceGraph(ctx) {
347
490
  console.error(formatError({ message: `${cwd} does not exist`, hint: USAGE }));
348
491
  return 1;
349
492
  }
350
- // The root's chant reads the declaration (ws-021).
351
- const handed = await handToRootChant(cwd, args.at);
352
- if (handed !== undefined)
353
- return handed;
493
+ if (args.runsOn && !args.discover) {
494
+ console.error(formatError({ message: "--runs-on sets a discovered member's cluster; with a declaration, set runsOn on the member's entry", hint: USAGE }));
495
+ return 2;
496
+ }
497
+ // --discover (#5095) reads one directory with no declaration, as the composed graph only.
498
+ if (args.discover && (args.composites || args.intent !== undefined || args.kind !== undefined)) {
499
+ console.error(formatError({ message: "--discover reads the composed graph, and takes none of --composites, --intent and --kind", hint: USAGE }));
500
+ return 1;
501
+ }
502
+ // The root's chant reads the declaration (ws-021). A discovered read has
503
+ // none to hand over, unless <dir> holds one itself, which is then read.
504
+ if (!args.discover || DECLARATION_FILES.some((f) => existsSync(join(cwd, f)))) {
505
+ const handed = await handToRootChant(cwd, args.at);
506
+ if (handed !== undefined)
507
+ return handed;
508
+ }
354
509
  // Composite instances joined to components (#2662) are their own document.
355
510
  if (args.composites) {
356
511
  if (args.intent !== undefined || args.kind !== undefined) {
@@ -384,7 +539,7 @@ export async function runWorkspaceGraph(ctx) {
384
539
  if (args.dryRun) {
385
540
  let plan;
386
541
  try {
387
- plan = planGraph({ cwd, at: args.at, members: args.members });
542
+ plan = planGraph({ cwd, at: args.at, members: args.members, ...(args.discover ? { discover: true } : {}) });
388
543
  }
389
544
  catch (err) {
390
545
  if (!(err instanceof WorkspaceReadError))
@@ -401,8 +556,11 @@ export async function runWorkspaceGraph(ctx) {
401
556
  members: args.members,
402
557
  args,
403
558
  ...(args.noCache ? { noCache: true } : {}),
559
+ ...(args.discover ? { discover: true } : {}),
560
+ ...(args.runsOn ? { runsOn: args.runsOn } : {}),
404
561
  ...(args.kind !== undefined ? { kind: resolve(args.kind) } : {}),
405
562
  onStderr: (text) => process.stderr.write(text),
563
+ catalog: true,
406
564
  });
407
565
  emitDocument(doc, args.output);
408
566
  if ("error" in doc) {
@@ -101,12 +101,22 @@
101
101
  }
102
102
  },
103
103
  "dangling": {
104
- "description": "Added in contract 1 by #3922. The members' references whose target is no node of their graph (#3910): a job `needs` a job no workflow declares, a `uses:` names another repository's workflow, a GitLab `include:` names a file chant did not generate. Each member's `ir.dangling` entry with `from` prefixed by its member and a `member` field, sorted by `from`, `path` and `value`. Absent when no member has one.",
104
+ "description": "Added in contract 1 by #3922. The members' references whose target is no node of their graph (#3910): a job `needs` a job no workflow declares, a `uses:` names another repository's workflow, a GitLab `include:` names a file chant did not generate. Each member's `ir.dangling` entry with `from` prefixed by its member and a `member` field, then (#5097) each reference the reference catalog found no node for, with its `rule`. Sorted by `from`, `path` and `value`. Absent when there is none.",
105
105
  "type": "array",
106
106
  "items": {
107
107
  "$ref": "#/$defs/dangling"
108
108
  }
109
109
  },
110
+ "ambiguous": {
111
+ "description": "Added in contract 1 by #5097, written by chant 0.124.98 and newer. References the reference catalog matched to more than one node: no edge is drawn, and every candidate is listed. Sorted by `from`, `rule` and `value`. Absent when there are none.",
112
+ "type": "array",
113
+ "items": {
114
+ "$ref": "#/$defs/ambiguous"
115
+ }
116
+ },
117
+ "catalog": {
118
+ "$ref": "#/$defs/catalog"
119
+ },
110
120
  "groups": {
111
121
  "type": "object",
112
122
  "required": [
@@ -272,9 +282,46 @@
272
282
  "plantable": {
273
283
  "description": "Added in contract 1 by #3146. Whether a host such as a studio's planter can plant the workspace as one box: exactly one member's box block declares services, read from the declaration at the revision read. Not a check: a records-only or infra workspace is valid and simply not plantable.",
274
284
  "$ref": "#/$defs/plantable"
285
+ },
286
+ "discovered": {
287
+ "type": "array",
288
+ "description": "Added in contract 1 by #5095. Present only for chant workspace graph <dir> --discover when <dir> holds no declaration: every directory a kind's probe claims, sorted by dir, with what became of it. Absent for a declared read.",
289
+ "items": { "$ref": "#/$defs/discoveredDir" }
275
290
  }
276
291
  }
277
292
  },
293
+ "discoveredDir": {
294
+ "type": "object",
295
+ "description": "Added in contract 1 by #5095. One directory a kind's probe claims in a discovered read.",
296
+ "additionalProperties": false,
297
+ "required": ["dir", "member", "kind", "source", "probe", "outcome", "claims", "note"],
298
+ "properties": {
299
+ "dir": { "type": "string", "description": "The directory, relative to <dir> with / separators; \".\" for <dir> itself." },
300
+ "member": { "type": ["string", "null"], "description": "The member's name when outcome is member, else null. It depends on dir alone, by the rule the workspace graph page gives." },
301
+ "kind": { "type": ["string", "null"], "description": "The kind the precedence order picks; null for a tie." },
302
+ "source": { "type": ["string", "null"], "description": "Where that kind comes from: builtin, or the package that supplies it; null for a tie." },
303
+ "probe": { "type": ["object", "null"], "description": "That kind's probe, as its kinds file states it; null for a tie." },
304
+ "outcome": {
305
+ "enum": ["member", "tie", "module", "inside-member"],
306
+ "description": "member: read as the member named in member. tie: two or more kinds share the highest precedence, and it is not read. module: a .tf file under <dir> calls it through a local source, so it is read with each root that calls it. inside-member: it sits inside another member's directory, and members don't nest except inside the root member \".\"."
307
+ },
308
+ "claims": {
309
+ "type": "array",
310
+ "description": "Every kind whose probe claims the directory, highest precedence first.",
311
+ "items": {
312
+ "type": "object",
313
+ "additionalProperties": false,
314
+ "required": ["kind", "precedence", "source"],
315
+ "properties": {
316
+ "kind": { "type": "string" },
317
+ "precedence": { "type": "number" },
318
+ "source": { "type": "string" }
319
+ }
320
+ }
321
+ },
322
+ "note": { "type": ["string", "null"], "description": "Why the directory is not a member, in one line; null for a member." }
323
+ }
324
+ },
278
325
  "member": {
279
326
  "type": "object",
280
327
  "required": [
@@ -590,6 +637,28 @@
590
637
  }
591
638
  }
592
639
  },
640
+ "generatedBy": {
641
+ "type": "object",
642
+ "description": "Added in contract 1 by #5102. On a node the reference catalog generated from another, an Application an ApplicationSet's list or clusters generator yields: the generating node's id, the rule, the generator, the parameters it was made with (flattened to a.b.c keys) and, for a clusters generator, the cluster Secret it was made for. Its id is the generating node's id, a slash and its name. Since #5094 a node read from a file a generated node names (a generated Application's Helm values file, or an object under its extraObjects) has generatedBy too, naming that generated node, the generate rule and generator \"file\", with empty params.",
643
+ "required": ["node", "rule", "generator", "params"],
644
+ "properties": {
645
+ "node": { "type": "string" },
646
+ "rule": { "type": "string" },
647
+ "generator": { "type": "string" },
648
+ "params": { "type": "object", "additionalProperties": { "type": "string" } },
649
+ "cluster": { "type": "string" }
650
+ }
651
+ },
652
+ "expansion": {
653
+ "type": "object",
654
+ "description": "Added in contract 1 by #5102. On a node a catalog rule generates nodes from, an ApplicationSet: the rule, how many nodes it generated, and one line for each thing it did not expand, such as another generator, templatePatch or a template function it does not read.",
655
+ "required": ["rule", "generated", "notExpanded"],
656
+ "properties": {
657
+ "rule": { "type": "string" },
658
+ "generated": { "type": "integer", "minimum": 0 },
659
+ "notExpanded": { "type": "array", "items": { "type": "string" } }
660
+ }
661
+ },
593
662
  "facts": {
594
663
  "type": "object",
595
664
  "description": "Added in contract 1 by #4529, written by chant 0.124.54 and newer. What an ownership engine observed about the node: ownership, markers, ownedBy, cloudIds, recordVersions and observedAt, each optional, in the shape of EngineFacts (packages/core/src/graph-schema/graph.schema.json). Set on a Pulumi member on plunge from its checked-in engine-graph.json. Never read for a decision."
@@ -655,8 +724,21 @@
655
724
  "enum": ["block", "instance", "property"],
656
725
  "description": "Added in contract 1 by #4529, written by chant 0.124.54 and newer. What the edge joins: two blocks, two instances, or a property of one instance to another. A Pulumi member's dependencies and parent edges are instance; a plunge member's property edges are property. Absent when the source does not say."
657
726
  },
727
+ "origin": {
728
+ "enum": ["declared", "observed", "derived"],
729
+ "description": "Where the edge came from, as on a member's IR: `derived` for an edge a reference catalog rule drew. Added in contract 1 by #5097, written by chant 0.124.98 and newer. The composed graph draws derived edges between members too. Absent reads as `declared` on a source read and `observed` on a live one."
730
+ },
731
+ "rule": {
732
+ "type": "string",
733
+ "description": "With `origin: \"derived\"`: the rule that drew the edge, `<lexicon>:<holder kind>:<path>`. `catalog.rules` describes it."
734
+ },
735
+ "relation": {
736
+ "enum": ["reference", "containment"],
737
+ "description": "`reference` (the default when absent) or `containment`: the holder sits inside the target, and is in `groups.byContainer` too."
738
+ },
658
739
  "member": {
659
- "type": "string"
740
+ "type": "string",
741
+ "description": "The member the edge was read in. For a derived edge, the holder's member; the edge's ends carry their own."
660
742
  }
661
743
  }
662
744
  },
@@ -695,6 +777,117 @@
695
777
  "nested": {
696
778
  "type": "string",
697
779
  "description": "For a member of kind `workspace`: the nested workspace's member the reference was read through, as on a node."
780
+ },
781
+ "rule": {
782
+ "type": "string",
783
+ "description": "Added in contract 1 by #5097, written by chant 0.124.98 and newer. For a reference the reference catalog read: the rule that read it, as on an edge. Absent on a member's own dangling references."
784
+ },
785
+ "targetKind": {
786
+ "type": "string",
787
+ "description": "Added in contract 1 by #5097, written by chant 0.124.98 and newer. The kind the rule looks for, when it names one."
788
+ },
789
+ "through": {
790
+ "type": "string",
791
+ "description": "Added in contract 1 by #5098. For a reference read through another node, the id of that node: the store a key is read from, or (#5102) the ApplicationSet that generated the Application whose path is missing."
792
+ },
793
+ "cluster": {
794
+ "type": "string",
795
+ "description": "Added in contract 1 by #5102. For a path a generated Application names: the cluster Secret it was generated for."
796
+ }
797
+ }
798
+ },
799
+ "ambiguous": {
800
+ "type": "object",
801
+ "required": ["from", "member", "rule", "path", "value", "candidates"],
802
+ "properties": {
803
+ "from": {
804
+ "type": "string",
805
+ "description": "The node holding the reference."
806
+ },
807
+ "member": {
808
+ "type": "string",
809
+ "description": "The holder's member."
810
+ },
811
+ "rule": {
812
+ "type": "string",
813
+ "description": "The rule that read the reference, as on an edge."
814
+ },
815
+ "path": {
816
+ "type": "string"
817
+ },
818
+ "value": {
819
+ "type": "string"
820
+ },
821
+ "candidates": {
822
+ "type": "array",
823
+ "items": {
824
+ "type": "string"
825
+ },
826
+ "description": "Every node the value matched, sorted. At `--detail` 0 and 1, the nodes they are drawn as."
827
+ }
828
+ }
829
+ },
830
+ "catalog": {
831
+ "description": "Added in contract 1 by #5097, written by chant 0.124.98 and newer. What the reference catalog pass read. Absent with `--live`, where each member's own chant runs its catalog.",
832
+ "type": "object",
833
+ "required": ["lexicons", "members", "rules"],
834
+ "properties": {
835
+ "lexicons": {
836
+ "type": "array",
837
+ "items": {
838
+ "type": "string"
839
+ },
840
+ "description": "The lexicons whose reference catalog ran, sorted. A lexicon of the graph that is not listed has no catalog, or did not load, and its nodes hold no derived references."
841
+ },
842
+ "members": {
843
+ "type": "array",
844
+ "items": {
845
+ "type": "string"
846
+ },
847
+ "description": "The members whose nodes the pass read, sorted."
848
+ },
849
+ "rules": {
850
+ "type": "object",
851
+ "description": "Every rule an edge, a dangling entry or an ambiguous entry names, by rule id.",
852
+ "additionalProperties": {
853
+ "type": "object",
854
+ "required": ["lexicon", "from", "path", "relation", "targetKinds"],
855
+ "properties": {
856
+ "lexicon": {
857
+ "type": "string"
858
+ },
859
+ "from": {
860
+ "type": "string",
861
+ "description": "The holder kind the rule reads."
862
+ },
863
+ "path": {
864
+ "type": "string",
865
+ "description": "The attribute path, with `[]` for each element of a list and `[\"key\"]` for a key that holds dots or slashes."
866
+ },
867
+ "relation": {
868
+ "enum": ["reference", "containment"]
869
+ },
870
+ "targetKinds": {
871
+ "type": "array",
872
+ "items": {
873
+ "type": "string"
874
+ },
875
+ "description": "The kinds the target can be. One id can stand for several rules, one per kind. Empty when the rule takes any kind."
876
+ },
877
+ "label": {
878
+ "type": "string",
879
+ "description": "The rule's human-facing name for the relation, such as `runs as`."
880
+ }
881
+ }
882
+ }
883
+ },
884
+ "nonLiteral": {
885
+ "type": "object",
886
+ "additionalProperties": {
887
+ "type": "integer",
888
+ "minimum": 1
889
+ },
890
+ "description": "By node id: arguments the pass did not read because their value is not literal, such as a terraform interpolation. Absent when there are none."
698
891
  }
699
892
  }
700
893
  },