@intentius/behold 0.31.0 → 0.33.0

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 (50) hide show
  1. package/AGENTS.md +64 -2787
  2. package/README.md +78 -13
  3. package/THIRD_PARTY.md +6 -5
  4. package/dist/chant-KLLNQOCK.js +117 -0
  5. package/dist/choudoufu-chant-read-MJ6DK23L.js +36 -0
  6. package/dist/chunk-26K6QLVB.js +157 -0
  7. package/dist/chunk-4IETG5U7.js +267 -0
  8. package/dist/chunk-7DQDWJI5.js +46 -0
  9. package/dist/chunk-ANJ33KX4.js +78 -0
  10. package/dist/chunk-C7OMVDI5.js +124 -0
  11. package/dist/chunk-GG3SLEYM.js +30297 -0
  12. package/dist/chunk-GMCRBXPQ.js +15578 -0
  13. package/dist/chunk-IMX6PXXA.js +1019 -0
  14. package/dist/chunk-JHLNY324.js +232 -0
  15. package/dist/chunk-JJPU2DXX.js +54 -0
  16. package/dist/chunk-KUHU6T4P.js +2820 -0
  17. package/dist/chunk-OY4EF7ZO.js +5651 -0
  18. package/dist/chunk-XKWCGNT2.js +8139 -0
  19. package/dist/chunk-YO233FHU.js +136 -0
  20. package/dist/cli.js +491 -72879
  21. package/dist/config-XKQQ4ORG.js +69 -0
  22. package/dist/config-run-4IMSAYPX.js +418 -0
  23. package/dist/declaration-5NE7H5UD.js +6867 -0
  24. package/dist/index.js +99 -0
  25. package/dist/main-4PGA5RJS.js +2509 -0
  26. package/dist/mcp-W2CHVEPI.js +753 -0
  27. package/dist/object-store-H77QSRIZ.js +1033 -0
  28. package/dist/src-54PT4UC5.js +1189 -0
  29. package/dist/tree-W23HE2EZ.js +17 -0
  30. package/example-choudoufu-estate/chant.workspace.json +1 -1
  31. package/example-terraform-estate/README.md +2 -2
  32. package/example-terraform-estate/chant.workspace.json +1 -1
  33. package/example-three-cloud/chant.workspace.json +2 -2
  34. package/example-three-cloud/package-lock.json +32 -515
  35. package/example-three-cloud/package.json +5 -5
  36. package/package.json +26 -13
  37. package/schemas/graph/v1/graph.schema.json +140 -0
  38. package/web/app.js +9 -4
  39. package/web/boot-motion.js +6 -0
  40. package/web/cut-around.d.ts +30 -0
  41. package/web/cut-around.js +138 -0
  42. package/web/edge-weight.d.ts +8 -2
  43. package/web/edge-weight.js +34 -4
  44. package/web/edge-weight.test.js +36 -1
  45. package/web/index.html +8 -20
  46. package/web/neighbourhood.js +105 -0
  47. package/web/neighbourhood.test.js +131 -0
  48. package/web/outside-refs.js +515 -0
  49. package/web/outside-refs.test.js +249 -0
  50. package/web/theme-paint.js +14 -0
package/README.md CHANGED
@@ -1,7 +1,20 @@
1
1
  # behold
2
2
 
3
- **A live control plane on [chant](https://github.com/INTENTIUS/chant).** Every
4
- substrate in one graph, coloured by drift. Then act through delegated, gated Ops.
3
+ **Your infrastructure repo as a graph, from the files.**
4
+
5
+ ```sh
6
+ npx @intentius/behold serve .
7
+ ```
8
+
9
+ Run it in a folder of Terraform and it finds each root and draws it as a box of resources, with an edge for each reference the configuration states. It needs no state file or cloud account, and it runs no `terraform` binary. It writes nothing into the folder it reads. Terraform roots are what it draws from files today. Kubernetes manifests in a plain directory and the edges between tools are coming. behold works beside the tools a repo already uses.
10
+
11
+ ![Two Terraform roots, app and net, drawn as boxes of resources with an edge for each reference](https://raw.githubusercontent.com/INTENTIUS/behold/main/docs/public/readme/two-roots.png)
12
+
13
+ ## With chant
14
+
15
+ Reads what chant records for terragucci and plywood.
16
+
17
+ Every substrate in one graph, coloured by drift. Then act through delegated, gated Ops.
5
18
 
6
19
  📖 **[Documentation](https://intentius.io/behold/)** starts with an agent prompt
7
20
  that gets you to a running graph without reading anything else first.
@@ -130,6 +143,53 @@ To colour the graph by what is actually deployed, name an environment with
130
143
  for one specific demo project. `behold demo` and `serve --local` supersede it for
131
144
  every purpose; it is kept for compatibility and is not documented further.</sub>
132
145
 
146
+ ## Print the graph: `behold graph`
147
+
148
+ `behold graph [dir]` reads a directory and prints its graph, with no server
149
+ and no browser. A CI job, an editor or a script can take the output as it is.
150
+
151
+ ```sh
152
+ npx @intentius/behold graph ./infra --json | jq '.nodes | length'
153
+ npx @intentius/behold graph ./infra --ir -o graph.json --detail 3
154
+ ```
155
+
156
+ `--json` (the default) prints the `behold-graph/1` document. `--ir` prints the
157
+ unversioned `{ir, meta}` snapshot that `/api/graph` answers, without its SVG.
158
+ Neither holds an absolute path, and a card's source text is left out unless
159
+ you pass `--source`. A root that does not parse is one card in the output, as
160
+ it is in the browser.
161
+ `--svg [--theme light|dark]` writes the picture as one self-contained SVG file.
162
+
163
+ Two cuts print part of the graph. `--changed <base>..<head>` keeps what
164
+ changed between two commits (cards added, removed or changed, marked `diff` in
165
+ the document) and the cards within `--depth` hops of them (default 1), read
166
+ from `git archive` into a temporary directory, so the checkout is not touched
167
+ and a shallow clone works once both commits are fetched. A commit that only
168
+ reformats a file changes no card. Past `--budget` cards (default 60) the
169
+ neighbours fold into a count per box, then the cut becomes a table of counts.
170
+ `--around <id>[,<id>...]` keeps the named cards or boxes and what is within
171
+ `--depth` hops, `--up` or `--down` for one direction.
172
+
173
+ ```sh
174
+ npx @intentius/behold graph ./infra --changed origin/main...HEAD -o cut.json
175
+ npx @intentius/behold graph ./infra --around prod/prod/aws_vpc.main --depth 2
176
+ ```
177
+
178
+ `npx @intentius/behold graph ./infra` is a lean install. The Kubernetes client
179
+ is an optional peer, so `npm install` does not fetch it;
180
+ see "Optional install" below.
181
+
182
+ ### Optional install: the Kubernetes client
183
+
184
+ `@intentius/chant-k8s-client` (it brings `@kubernetes/client-node`, 63 MB) is an
185
+ optional peer of `@intentius/behold`, so a plain `npm install` does not fetch it.
186
+ It is loaded only to read a kubeconfig: the server's context lookups, the
187
+ kubectl context pills and `behold doctor`. When it is missing those paths stop
188
+ with one line naming it. Install it with `npm i @intentius/chant-k8s-client`.
189
+
190
+ `behold graph` on a Terraform folder, `serve`, `export` and `behold mcp` do not
191
+ need it.
192
+
133
193
  ## Export and host: a shareable, interactive snapshot
134
194
 
135
195
  `behold export` freezes whatever estate you're looking at into a **self-contained
@@ -449,15 +509,17 @@ The docs' terragucci page says what it shows.
449
509
 
450
510
  The demo is served at `/`: the live demo's page, else the first listed one.
451
511
  `/kiosk` redirects to `/`. The listed demos are the multi-state plan-and-apply
452
- ones, each at a path of its own (`/choudoufu-compose`, `/terragrunt-choudoufu`,
453
- `/atmos-choudoufu`, `/chant-compose`); one is listed once its tool has a published cycle
512
+ ones (`choudoufu-compose`, `terragrunt-choudoufu`, `atmos-choudoufu`,
513
+ `chant-compose`); one is listed once its tool has a published cycle
454
514
  (`cycles/<tool>/latest.json` beside `demo.json`) or is live, and
455
- `/api/terragucci/demos` says which. A page shows the demo's live run, or replays
456
- its latest cycle, under a banner with the example's name, its products, a link to
457
- its code in INTENTIUS/terragucci, and a switcher when more than one is listed.
515
+ `/api/terragucci/demos` says which. No demo has a page of its own: a tool's
516
+ path (`/choudoufu-compose`, `/terragrunt-choudoufu`, `/atmos-choudoufu`,
517
+ `/chant-compose`) redirects to `/` with a 302, so a link to one lands on
518
+ whichever demo `/` shows. The page shows that demo under a banner with the
519
+ example's name, the act, its products and a link to its code.
458
520
  The older tools' URLs (`/terraform`, `/terragrunt`, `/cdk-terrain`, `/choudoufu`,
459
- `/chant`, and the fan-out pages) redirect to `/`. Any other short path answers
460
- 404 with a link to the front page.
521
+ `/chant`, and the fan-out pages) redirect to `/` too. Any other short path
522
+ answers 404 with a link to the front page.
461
523
 
462
524
  In a declared workspace, the gates waiting on a person come from
463
525
  `chant workspace status <env> --json`, keyed `member/op/gate` the way arugula's
@@ -561,7 +623,7 @@ reason. [example-carve/README.md](example-carve/README.md) has the estate's full
561
623
  and the offline/`--live` split.
562
624
 
563
625
  behold writes only into `app/carveout/` inside the demo copy it made, and
564
- nothing else. Your Terraform is never edited; see AGENTS.md, "Invariant".
626
+ nothing else. Your Terraform is never edited; see AGENTS.md, "The write boundary".
565
627
 
566
628
  ## Configuration: `.behold.json`
567
629
 
@@ -677,8 +739,8 @@ yourself when you like.
677
739
 
678
740
  ## Layout
679
741
 
680
- A shape rather than a manifest. `src/` is ~85 modules with one concern each, and
681
- [AGENTS.md](./AGENTS.md) is the map that stays current.
742
+ A shape rather than a manifest. `src/` is ~85 modules with one concern each;
743
+ [AGENTS.md](./AGENTS.md) names the rules that hold across them.
682
744
 
683
745
  ```
684
746
  src/
@@ -722,7 +784,10 @@ Flux mark, a `Helm::Release` the Helm wheel. The corpus is vendored under
722
784
  `web/icons/` (30 kubernetes/community SVGs, 3 cncf/artwork marks for
723
785
  Flux/Argo/Helm, licensing in `THIRD_PARTY.md`) and mapped kind by kind in
724
786
  `src/icon-packs.ts`; a kind with no official icon falls through to pinhole's
725
- keyword heuristic rather than a wrong picture.
787
+ keyword heuristic rather than a wrong picture. The painter reads the corpus from
788
+ `src/icons.generated.ts`, which `npm run generate:icons` writes from `web/icons/`
789
+ and `npm run check:icons` holds to it, so `src/render.ts` reads no file and
790
+ bundles for a browser (`npm run check:browser-bundle`, #1069).
726
791
 
727
792
  dagre's layout is a good first draft, not a final one: drag a card to move
728
793
  it, grab a containment box's corner to resize it, and both survive a reload.
package/THIRD_PARTY.md CHANGED
@@ -36,11 +36,12 @@ into one document cannot collide. No geometry is touched; every path is byte-ide
36
36
  upstream. [`scripts/vendor-icons.mjs`](./scripts/vendor-icons.mjs) re-fetches the corpus at
37
37
  the pinned revision, and `--check` asserts the working tree still matches it.
38
38
 
39
- At render time one further step happens to the copy in memory, never to the file on disk:
40
- [`src/icon-packs.ts`](./src/icon-packs.ts) splices each body into the graph SVG without its
41
- root `<svg>`, so the remaining `inkscape:`/`sodipodi:` attributes — which that root declared
42
- the namespaces for — are dropped and `xlink:href` becomes the plain SVG 2 `href`. Editor
43
- state only; nothing that paints.
39
+ At build time one further step happens to a copy, never to the file on disk:
40
+ [`src/icon-svg.ts`](./src/icon-svg.ts) splits each body out of its root `<svg>`, so the
41
+ remaining `inkscape:`/`sodipodi:` attributes — which that root declared the namespaces for —
42
+ are dropped and `xlink:href` becomes the plain SVG 2 `href`. Editor state only; nothing that
43
+ paints. `npm run generate:icons` writes the result to `src/icons.generated.ts`, which is what
44
+ [`src/icon-packs.ts`](./src/icon-packs.ts) splices into the graph SVG.
44
45
 
45
46
  ## Flux, Argo and Helm project marks (`web/icons/cncf/`)
46
47
 
@@ -0,0 +1,117 @@
1
+ import {
2
+ CI_FORGES,
3
+ ChantCliError,
4
+ TRAFFIC_FLOOR,
5
+ applyArgs,
6
+ carveStatus,
7
+ chantBinFrom,
8
+ chantFloor,
9
+ chantPackageFrom,
10
+ ciForgeFor,
11
+ ciPipeline,
12
+ ciPipelineArgs,
13
+ ciWorkflowName,
14
+ classifyChantFailure,
15
+ clusterRootGraphIr,
16
+ compareEnvs,
17
+ compareEnvsArgs,
18
+ componentGraphIr,
19
+ componentGraphLayout,
20
+ componentGraphPath,
21
+ componentStatus,
22
+ componentStatusArgs,
23
+ envOverridesFor,
24
+ graphArgs,
25
+ graphFlags,
26
+ graphIr,
27
+ graphLayout,
28
+ graphPath,
29
+ helmRenderDiffArgs,
30
+ helmRenderDiffLive,
31
+ helmRenders,
32
+ helmRendersArgs,
33
+ isIntentRead,
34
+ isScheduledRead,
35
+ isSearchRead,
36
+ lifecycleDiffArgs,
37
+ lifecycleDiffLive,
38
+ lifecyclePlan,
39
+ lifecyclePlanArgs,
40
+ meetsFloor,
41
+ memberTakesTraffic,
42
+ opRunArgs,
43
+ parseCiPipeline,
44
+ pipeLines,
45
+ pipelineEnvFromYaml,
46
+ readsInFlight,
47
+ resolveChant,
48
+ resolveLexicons,
49
+ runChantRaw,
50
+ runChantStream,
51
+ runCommandStream,
52
+ runEventsArgs,
53
+ sanitizeStackGraph,
54
+ stackGraph,
55
+ stackGraphArgs,
56
+ stripAnsi,
57
+ withLoaderPath
58
+ } from "./chunk-OY4EF7ZO.js";
59
+ import "./chunk-7DQDWJI5.js";
60
+ export {
61
+ CI_FORGES,
62
+ ChantCliError,
63
+ TRAFFIC_FLOOR,
64
+ applyArgs,
65
+ carveStatus,
66
+ chantBinFrom,
67
+ chantFloor,
68
+ chantPackageFrom,
69
+ ciForgeFor,
70
+ ciPipeline,
71
+ ciPipelineArgs,
72
+ ciWorkflowName,
73
+ classifyChantFailure,
74
+ clusterRootGraphIr,
75
+ compareEnvs,
76
+ compareEnvsArgs,
77
+ componentGraphIr,
78
+ componentGraphLayout,
79
+ componentGraphPath,
80
+ componentStatus,
81
+ componentStatusArgs,
82
+ envOverridesFor,
83
+ graphArgs,
84
+ graphFlags,
85
+ graphIr,
86
+ graphLayout,
87
+ graphPath,
88
+ helmRenderDiffArgs,
89
+ helmRenderDiffLive,
90
+ helmRenders,
91
+ helmRendersArgs,
92
+ isIntentRead,
93
+ isScheduledRead,
94
+ isSearchRead,
95
+ lifecycleDiffArgs,
96
+ lifecycleDiffLive,
97
+ lifecyclePlan,
98
+ lifecyclePlanArgs,
99
+ meetsFloor,
100
+ memberTakesTraffic,
101
+ opRunArgs,
102
+ parseCiPipeline,
103
+ pipeLines,
104
+ pipelineEnvFromYaml,
105
+ readsInFlight,
106
+ resolveChant,
107
+ resolveLexicons,
108
+ runChantRaw,
109
+ runChantStream,
110
+ runCommandStream,
111
+ runEventsArgs,
112
+ sanitizeStackGraph,
113
+ stackGraph,
114
+ stackGraphArgs,
115
+ stripAnsi,
116
+ withLoaderPath
117
+ };
@@ -0,0 +1,36 @@
1
+ import {
2
+ LIVE_PLAN_DIR_ENV,
3
+ cacheChoudoufuPlan,
4
+ cachedChoudoufuPlan,
5
+ choudoufuChantArgs,
6
+ choudoufuChantUnavailable,
7
+ choudoufuRootName,
8
+ livePlanDocumentFile,
9
+ planDriftFromIr,
10
+ readChoudoufuThroughChant,
11
+ resetChoudoufuPlanCache,
12
+ rootAnswerOf,
13
+ rootAnswerOfNotes,
14
+ setChoudoufuChantDeps
15
+ } from "./chunk-26K6QLVB.js";
16
+ import "./chunk-4IETG5U7.js";
17
+ import {
18
+ memberSourceStamp
19
+ } from "./chunk-OY4EF7ZO.js";
20
+ import "./chunk-7DQDWJI5.js";
21
+ export {
22
+ LIVE_PLAN_DIR_ENV,
23
+ cacheChoudoufuPlan,
24
+ cachedChoudoufuPlan,
25
+ choudoufuChantArgs,
26
+ choudoufuChantUnavailable,
27
+ choudoufuRootName,
28
+ livePlanDocumentFile,
29
+ memberSourceStamp,
30
+ planDriftFromIr,
31
+ readChoudoufuThroughChant,
32
+ resetChoudoufuPlanCache,
33
+ rootAnswerOf,
34
+ rootAnswerOfNotes,
35
+ setChoudoufuChantDeps
36
+ };
@@ -0,0 +1,157 @@
1
+ import {
2
+ PLAN_READ_ENV,
3
+ TERRAFORM_OBSERVE_ENV,
4
+ hasRootReads,
5
+ rootReadReasonWords,
6
+ rootReadsOf
7
+ } from "./chunk-4IETG5U7.js";
8
+ import {
9
+ CHOUDOUFU_PLAN_CHANT_FLOOR,
10
+ ChoudoufuReadError,
11
+ TERRAFORM_LEXICON_PKG,
12
+ choudoufuSpawnOverride,
13
+ meetsFloor,
14
+ parseLivePlan,
15
+ resolvedVersion,
16
+ stripAnsi,
17
+ terraformReaderState,
18
+ writeTerraformScratchProject
19
+ } from "./chunk-OY4EF7ZO.js";
20
+
21
+ // src/choudoufu-chant-read.ts
22
+ import { mkdtempSync, readFileSync, rmSync } from "node:fs";
23
+ import { tmpdir } from "node:os";
24
+ import { basename, join } from "node:path";
25
+ var LIVE_PLAN_DIR_ENV = "CHANT_TERRAFORM_LIVE_PLAN_DIR";
26
+ var choudoufuChantArgs = () => ["graph", ".", "--live", "--overlay", "--env", PLAN_READ_ENV, "--format", "ir", "--detail", "3"];
27
+ var livePlanDocumentFile = (root) => `${root.replace(/[^A-Za-z0-9._-]/g, "_")}.live-plan.json`;
28
+ var choudoufuRootName = (dir) => basename(dir);
29
+ var depsOverride;
30
+ function setChoudoufuChantDeps(deps) {
31
+ depsOverride = deps;
32
+ }
33
+ async function choudoufuChantUnavailable(deps = depsOverride) {
34
+ if (deps === null) return "no chant to read the plan through";
35
+ const d = deps ?? {};
36
+ const absent = d.readerAbsent ? d.readerAbsent() : terraformReaderState().refusal?.error;
37
+ if (absent) return absent;
38
+ const chant = d.chantVersion ? d.chantVersion() : (await import("./chant-KLLNQOCK.js")).resolveChant().version;
39
+ if (!meetsFloor(chant, CHOUDOUFU_PLAN_CHANT_FLOOR)) return `the plan read on a choudoufu member needs chant ${CHOUDOUFU_PLAN_CHANT_FLOOR} or newer; behold has ${chant ?? "(unknown version)"}`;
40
+ const lexicon = d.lexiconVersion ? d.lexiconVersion() : resolvedVersion(TERRAFORM_LEXICON_PKG);
41
+ if (!meetsFloor(lexicon, CHOUDOUFU_PLAN_CHANT_FLOOR)) return `the plan read on a choudoufu member needs ${TERRAFORM_LEXICON_PKG} ${CHOUDOUFU_PLAN_CHANT_FLOOR} or newer; behold has ${lexicon ?? "(unknown version)"}`;
42
+ return void 0;
43
+ }
44
+ function rootAnswerOf(ir, root, stderr = "") {
45
+ const key = `terraform.roots.${root}`;
46
+ if (!hasRootReads(ir)) return rootAnswerOfNotes(stderr, root);
47
+ const rr = rootReadsOf(ir)[key];
48
+ if (!rr) return { answered: "live" };
49
+ if (rr.depth === "live+plan" && rr.fellBackTo === void 0) return { answered: "live+plan", note: `${key}: the plan read answered, beside live-plan, which answered presence and ownership` };
50
+ const why = rr.reason ? ` (${rootReadReasonWords(rr.reason)})` : "";
51
+ return {
52
+ answered: "live",
53
+ note: rr.fellBackTo === "declared" ? `${key}: no read answered${why}` : `${key}: the ${rr.depth} read failed${why}, so live-plan alone answered; plan attributes are absent`
54
+ };
55
+ }
56
+ function rootAnswerOfNotes(stderr, root) {
57
+ const prefix = `terraform.roots.${root}: `;
58
+ for (const line of stripAnsi(stderr).split("\n")) {
59
+ const at = line.indexOf(prefix);
60
+ if (at === -1) continue;
61
+ const rest = line.slice(at + prefix.length).trim();
62
+ if (rest.startsWith("the plan read answered")) return { answered: "live+plan", note: `${prefix}${rest}` };
63
+ if (rest.startsWith("the plan read failed") || rest.startsWith("no read answered")) return { answered: "live", note: `${prefix}${rest}` };
64
+ }
65
+ return { answered: "live" };
66
+ }
67
+ var isRecord = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
68
+ function blockAddressOf(n, root) {
69
+ if (!n.id.startsWith(`${root}/`)) return void 0;
70
+ return n.id.slice(root.length + 1).replace(/~\d+$/, "").split("/").join(".");
71
+ }
72
+ var comparable = (actions) => actions.includes("update") || actions.includes("delete") && actions.includes("create");
73
+ function planDriftFromIr(ir, root) {
74
+ const out = /* @__PURE__ */ new Map();
75
+ for (const n of ir.nodes) {
76
+ if (n.kind !== "Terraform::Resource") continue;
77
+ const block = blockAddressOf(n, root);
78
+ const a = n.attrs ?? {};
79
+ if (!block || typeof a.planAction !== "string") continue;
80
+ const actions = isRecord(a.planActions) ? a.planActions : { [block]: [a.planAction] };
81
+ const changes = Array.isArray(a.planChanges) ? a.planChanges : [];
82
+ for (const [instance, acts] of Object.entries(actions)) {
83
+ if (!Array.isArray(acts) || !comparable(acts)) continue;
84
+ const mine = changes.filter((c) => typeof c.path === "string" && (typeof c.instance === "string" ? c.instance : block) === instance).map((c) => ({ path: c.path, oldValue: c.before ?? null, newValue: c.after ?? null }));
85
+ if (mine.length) out.set(instance, { address: instance, actions: acts, changes: mine });
86
+ }
87
+ }
88
+ return out;
89
+ }
90
+ async function readChoudoufuThroughChant(dir, deps = depsOverride ?? void 0) {
91
+ const root = choudoufuRootName(dir);
92
+ const project = writeTerraformScratchProject(dir, { roots: [{ name: root, dir: "." }], skipped: [] }, void 0, "chdf");
93
+ const handed = mkdtempSync(join(tmpdir(), "behold-choudoufu-live-plan-"));
94
+ try {
95
+ const env = { ...choudoufuSpawnOverride() ?? {}, [TERRAFORM_OBSERVE_ENV]: "plan", [LIVE_PLAN_DIR_ENV]: handed };
96
+ const run = deps?.run ?? (async (args, cwd, e) => (await import("./chant-KLLNQOCK.js")).runChantRaw(args, cwd, e));
97
+ const res = await run(choudoufuChantArgs(), project, env);
98
+ let ir;
99
+ try {
100
+ ir = res.code === 0 ? JSON.parse(res.stdout) : void 0;
101
+ } catch {
102
+ ir = void 0;
103
+ }
104
+ const answer = rootAnswerOf(ir, root, res.stderr);
105
+ let text;
106
+ try {
107
+ text = readFileSync(join(handed, livePlanDocumentFile(root)), "utf8");
108
+ } catch {
109
+ const why = answer.note ?? stripAnsi(res.stderr).split("\n").find((l) => /error/i.test(l))?.trim() ?? `chant exited ${res.code} and handed back no live-plan document`;
110
+ throw new ChoudoufuReadError(
111
+ { error: `chant could not read ${dir} live: ${why}`, code: "choudoufu-live-check", remedy: "Give behold the ambient read-only AWS credentials the estate's `live-plan` and `plan` need (AWS_PROFILE, or AWS_ENDPOINT_URL for an emulator), then re-check live with plan." },
112
+ dir
113
+ );
114
+ }
115
+ const parsed = parseLivePlan({ code: 0, stdout: text, stderr: "" }, dir);
116
+ if (!parsed.ok) throw new ChoudoufuReadError(parsed.refusal, dir);
117
+ let drift = /* @__PURE__ */ new Map();
118
+ if (res.code === 0 && !ir) return { plan: parsed.doc, answered: "live", note: `chant printed something that is not a graph for ${dir}; the plan was not read`, drift };
119
+ if (ir && answer.answered === "live+plan") {
120
+ drift = planDriftFromIr(ir, root);
121
+ return { plan: parsed.doc, answered: "live+plan", ...answer.note ? { note: answer.note } : {}, drift };
122
+ }
123
+ return { plan: parsed.doc, answered: "live", ...answer.note ? { note: answer.note } : {}, drift };
124
+ } finally {
125
+ rmSync(handed, { recursive: true, force: true });
126
+ }
127
+ }
128
+ var planCache = /* @__PURE__ */ new Map();
129
+ function resetChoudoufuPlanCache(dir) {
130
+ if (dir === void 0) planCache.clear();
131
+ else planCache.delete(dir);
132
+ }
133
+ function cachedChoudoufuPlan(dir, stamp) {
134
+ if (stamp === void 0) return void 0;
135
+ const hit = planCache.get(dir);
136
+ return hit && hit.stamp === stamp ? hit.drift : void 0;
137
+ }
138
+ function cacheChoudoufuPlan(dir, stamp, drift) {
139
+ if (stamp === void 0) return;
140
+ planCache.set(dir, { stamp, drift });
141
+ }
142
+
143
+ export {
144
+ LIVE_PLAN_DIR_ENV,
145
+ choudoufuChantArgs,
146
+ livePlanDocumentFile,
147
+ choudoufuRootName,
148
+ setChoudoufuChantDeps,
149
+ choudoufuChantUnavailable,
150
+ rootAnswerOf,
151
+ rootAnswerOfNotes,
152
+ planDriftFromIr,
153
+ readChoudoufuThroughChant,
154
+ resetChoudoufuPlanCache,
155
+ cachedChoudoufuPlan,
156
+ cacheChoudoufuPlan
157
+ };