@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
@@ -0,0 +1,267 @@
1
+ import {
2
+ TERRAFORM_LEXICON,
3
+ TERRAFORM_LEXICON_PKG,
4
+ floorFor,
5
+ floorMet,
6
+ floorRefusal,
7
+ graphIr,
8
+ invalidateReadGeneration,
9
+ memberSourceStamp,
10
+ resolveChant,
11
+ resolvedVersion,
12
+ stripAnsi,
13
+ terraformMemberScan,
14
+ terraformReaderState,
15
+ writeTerraformScratchProject
16
+ } from "./chunk-OY4EF7ZO.js";
17
+
18
+ // src/terraform-plan.ts
19
+ var TERRAFORM_PLAN_READ = "plan read on a Terraform root";
20
+ var TERRAFORM_OBSERVE_ENV = "CHANT_TERRAFORM_OBSERVE";
21
+ var PLAN_READ_ENV = "behold-plan";
22
+ var terraformPlanArgs = () => ["graph", ".", "--live", "--overlay", "--env", PLAN_READ_ENV, "--format", "ir", "--detail", "3"];
23
+ function rootReadsOf(ir) {
24
+ const reads = ir?.rootReads;
25
+ if (!reads || typeof reads !== "object" || Array.isArray(reads)) return {};
26
+ const out = {};
27
+ for (const [key, v] of Object.entries(reads)) {
28
+ if (!v || typeof v !== "object" || typeof v.depth !== "string") continue;
29
+ out[key] = v;
30
+ }
31
+ return out;
32
+ }
33
+ function hasRootReads(ir) {
34
+ const reads = ir?.rootReads;
35
+ return !!reads && typeof reads === "object" && !Array.isArray(reads);
36
+ }
37
+ var NOTE = /terraform\.roots\.([^:\s]+): (.*)$/;
38
+ function parsePlanNotes(stderr) {
39
+ const out = /* @__PURE__ */ new Map();
40
+ for (const line of stripAnsi(stderr).split("\n")) {
41
+ const m = NOTE.exec(line.trim());
42
+ if (!m) continue;
43
+ const [, root, rest] = m;
44
+ const answered = rest.startsWith("the plan read answered") ? "plan" : /so the state read answered/.test(rest) ? "state" : rest.startsWith("no read answered") ? "none" : void 0;
45
+ const reason = answered !== "plan" && /no provider credentials/.test(rest) ? { reason: "no-credentials" } : {};
46
+ if (answered) out.set(root, { root, answered, ...reason, note: `terraform.roots.${root}: ${rest}` });
47
+ }
48
+ return [...out.values()].sort((a, b) => a.root.localeCompare(b.root));
49
+ }
50
+ function rootReadReasonWords(reason) {
51
+ const words = {
52
+ "no-credentials": "no provider credentials",
53
+ "plan-failed": "the plan failed",
54
+ "needs-init": "the root needs init, which chant never runs",
55
+ "backend-unreachable": "the plan read could not reach the backend",
56
+ "state-read-failed": "the state read failed",
57
+ "read-failed": "the read failed"
58
+ };
59
+ return words[reason] ?? reason;
60
+ }
61
+ function planRootAnswers(ir) {
62
+ const out = [];
63
+ for (const [key, rr] of Object.entries(rootReadsOf(ir))) {
64
+ if (!key.startsWith("terraform.roots.")) continue;
65
+ const root = key.slice("terraform.roots.".length);
66
+ const read = rr.fellBackTo ?? rr.depth;
67
+ const answered = read === "plan" ? "plan" : read === "state" ? "state" : "none";
68
+ const why = rr.reason ? ` (${rootReadReasonWords(rr.reason)})` : "";
69
+ const words = rr.fellBackTo === void 0 ? `the ${rr.depth} read answered` : rr.fellBackTo === "declared" ? `no read answered, declared only: the ${rr.depth} read failed${why}` : `the ${rr.depth} read failed${why}, so the ${rr.fellBackTo} read answered`;
70
+ out.push({ root, answered, ...rr.reason ? { reason: rr.reason } : {}, note: `${key}: ${words}` });
71
+ }
72
+ return out.sort((a, b) => a.root.localeCompare(b.root));
73
+ }
74
+ var strings = (v) => Array.isArray(v) && v.every((x) => typeof x === "string") && v.length ? v : void 0;
75
+ var entries = (v) => Array.isArray(v) && v.length ? v : void 0;
76
+ function planFactsOf(node) {
77
+ const a = node.attrs ?? {};
78
+ if (typeof a.planAction !== "string") return void 0;
79
+ const facts = { source: "plan", action: a.planAction };
80
+ if (a.planActions && typeof a.planActions === "object") facts.actions = a.planActions;
81
+ if (typeof a.planActionReason === "string") facts.reason = a.planActionReason;
82
+ const replace = strings(a.planReplacePaths);
83
+ if (replace) facts.replacePaths = replace;
84
+ const unknown = strings(a.planAfterUnknown);
85
+ if (unknown) facts.afterUnknown = unknown;
86
+ const changes = entries(a.planChanges);
87
+ if (changes) facts.changes = changes;
88
+ const drift = entries(a.planDrift);
89
+ if (drift) facts.drift = drift;
90
+ if (typeof a.planDriftAction === "string") facts.driftAction = a.planDriftAction;
91
+ const relevant = strings(a.planRelevantAttributes);
92
+ if (relevant) facts.relevant = relevant;
93
+ return facts;
94
+ }
95
+ var rootOf = (n) => typeof n.attrs?.root === "string" && n.attrs.root ? n.attrs.root : n.id.includes("/") ? n.id.slice(0, n.id.indexOf("/")) : void 0;
96
+ var isBlockWithRows = (n) => n.lexicon === TERRAFORM_LEXICON && (n.kind === "Terraform::Resource" || n.kind === "Terraform::Data");
97
+ var topAttr = (path) => path.split(/[.[]/)[0];
98
+ function forcedFromOf(id, root, paths, edges) {
99
+ const out = [];
100
+ for (const path of paths) {
101
+ for (const e of edges ?? []) {
102
+ const via = e.viaAttr;
103
+ if (e.from !== id || typeof via !== "string" || topAttr(via) !== topAttr(path)) continue;
104
+ const from = root && e.to.startsWith(`${root}/`) ? e.to.slice(root.length + 1) : e.to;
105
+ if (!out.some((o) => o.path === path && o.from === from)) out.push({ path, from });
106
+ }
107
+ }
108
+ return out.length ? out : void 0;
109
+ }
110
+ function terraformPlanReadOf(ir, stderr = "") {
111
+ const roots = hasRootReads(ir) ? planRootAnswers(ir) : parsePlanNotes(stderr);
112
+ const byRoot = new Map(roots.map((r) => [r.root, r]));
113
+ const cards = {};
114
+ for (const n of ir.nodes) {
115
+ if (!isBlockWithRows(n)) continue;
116
+ const root = rootOf(n);
117
+ const answer = root ? byRoot.get(root) : void 0;
118
+ if (answer?.answered === "plan") {
119
+ const facts = planFactsOf(n);
120
+ if (facts) {
121
+ const from = facts.replacePaths ? forcedFromOf(n.id, root, facts.replacePaths, ir.edges ?? []) : void 0;
122
+ cards[n.id] = from ? { ...facts, forcedFrom: from } : facts;
123
+ }
124
+ } else if (answer) {
125
+ cards[n.id] = { source: answer.answered, note: answer.note, ...answer.reason ? { readReason: answer.reason } : {} };
126
+ }
127
+ }
128
+ return { roots, cards };
129
+ }
130
+ function planReadFloorRefusal(chant, lexicon) {
131
+ const f = floorFor(TERRAFORM_PLAN_READ);
132
+ if (!floorMet(f, chant)) return floorRefusal(f, chant);
133
+ if (!floorMet(f, lexicon)) {
134
+ return {
135
+ error: `The ${f.read} needs ${TERRAFORM_LEXICON_PKG} ${f.floor} or newer. behold has ${lexicon ?? "(unknown version)"}.`,
136
+ code: "chant-too-old",
137
+ remedy: `Upgrade ${TERRAFORM_LEXICON_PKG} to ${f.floor} or newer beside behold.`
138
+ };
139
+ }
140
+ return void 0;
141
+ }
142
+ async function readTerraformPlan(dir, deps = {}) {
143
+ const { resolveChant: resolveChant2 } = await import("./chant-KLLNQOCK.js");
144
+ const chant = deps.chantVersion ? deps.chantVersion() : resolveChant2().version;
145
+ const lexicon = deps.lexiconVersion ? deps.lexiconVersion() : resolvedVersion(TERRAFORM_LEXICON_PKG);
146
+ const refusal = planReadFloorRefusal(chant, lexicon);
147
+ if (refusal) return { ok: false, refusal };
148
+ const state = terraformReaderState();
149
+ if (state.refusal) return { ok: false, refusal: state.refusal };
150
+ const { scan, components } = terraformMemberScan(dir);
151
+ if (!scan.roots.length) return { ok: true, read: { roots: [], cards: {} } };
152
+ const project = writeTerraformScratchProject(dir, scan, void 0, "tf", components);
153
+ const env = { ...deps.spawnEnv, [TERRAFORM_OBSERVE_ENV]: "plan" };
154
+ const run = deps.run ?? (async (args, cwd, e) => (await import("./chant-KLLNQOCK.js")).runChantRaw(args, cwd, e));
155
+ const res = await run(terraformPlanArgs(), project, env);
156
+ if (res.code !== 0) {
157
+ const first = stripAnsi(res.stderr).split("\n").find((l) => /error/i.test(l)) ?? `exit ${res.code}`;
158
+ return { ok: false, refusal: { error: `chant could not read the plan for ${dir}: ${first.trim()}`, code: "terraform-plan", remedy: "Run the same read by hand in the scratch project to see chant's whole message." } };
159
+ }
160
+ let ir;
161
+ try {
162
+ ir = JSON.parse(res.stdout);
163
+ } catch {
164
+ return { ok: false, refusal: { error: `chant printed something that is not a graph for ${dir}.`, code: "terraform-plan", remedy: "Check the chant behold runs: `behold doctor`." } };
165
+ }
166
+ return { ok: true, read: terraformPlanReadOf(ir, res.stderr) };
167
+ }
168
+ function paintTerraformPlan(ir, read, member) {
169
+ let painted = 0;
170
+ for (const n of ir.nodes) {
171
+ if (n.lexicon !== TERRAFORM_LEXICON) continue;
172
+ const key = member && n.id.startsWith(`${member}/`) ? n.id.slice(member.length + 1) : n.id;
173
+ const facts = read.cards[key];
174
+ if (!facts) continue;
175
+ n.attrs = { ...n.attrs, _plan: facts };
176
+ painted++;
177
+ }
178
+ return painted;
179
+ }
180
+ function terraformPlanNote(answers) {
181
+ if (!answers.length) return "plan: no stock Terraform root is served";
182
+ const parts = [];
183
+ for (const a of answers) {
184
+ const who = a.member ? `${a.member}: ` : "";
185
+ if (a.refusal) {
186
+ parts.push(`${who}plan not read (${a.refusal.error})`);
187
+ continue;
188
+ }
189
+ for (const r of a.roots ?? []) {
190
+ parts.push(
191
+ r.answered === "plan" ? `${who}${r.root} read from the plan` : r.answered === "state" ? `${who}${r.root} plan not read, the state read answered (${r.note.replace(/^terraform\.roots\.[^:]+: /, "")})` : `${who}${r.root} plan not read, nothing answered (${r.note.replace(/^terraform\.roots\.[^:]+: /, "")})`
192
+ );
193
+ }
194
+ }
195
+ return parts.length ? `plan: ${parts.join("; ")}` : void 0;
196
+ }
197
+
198
+ // src/member-ir.ts
199
+ import { resolve } from "node:path";
200
+ function memberIrCacheSize(env = process.env) {
201
+ const override = Number.parseInt(env.BEHOLD_ESTATE_IR_CACHE ?? "", 10);
202
+ return Number.isInteger(override) && override >= 0 ? override : 64;
203
+ }
204
+ var chantVia = {
205
+ tool: (dir) => {
206
+ const chant = resolveChant(dir);
207
+ return `${chant.bin}\0${chant.version ?? ""}`;
208
+ },
209
+ read: (dir, opts) => graphIr(dir, opts)
210
+ };
211
+ function cacheKey(dir, opts, via) {
212
+ const canonical = JSON.stringify(opts, Object.keys(opts).sort());
213
+ return `${resolve(dir)}\0${via.tool(dir)}\0${canonical}`;
214
+ }
215
+ var cache = /* @__PURE__ */ new Map();
216
+ var hits = 0;
217
+ var misses = 0;
218
+ function memberIrCacheStats() {
219
+ return { hits, misses, entries: cache.size };
220
+ }
221
+ function invalidateMember(dir) {
222
+ invalidateReadGeneration();
223
+ if (dir === void 0) {
224
+ cache.clear();
225
+ return;
226
+ }
227
+ const root = resolve(dir);
228
+ for (const [key, entry] of cache) if (entry.dir === root) cache.delete(key);
229
+ }
230
+ async function memberIr(dir, opts = {}, via = chantVia) {
231
+ const size = memberIrCacheSize();
232
+ if (opts.live || opts.overlay || size === 0) return via.read(dir, opts);
233
+ const stamp = memberSourceStamp(dir);
234
+ const key = cacheKey(dir, opts, via);
235
+ const hit = stamp !== void 0 ? cache.get(key) : void 0;
236
+ if (hit && hit.stamp === stamp) {
237
+ hits++;
238
+ cache.delete(key);
239
+ cache.set(key, hit);
240
+ return structuredClone(hit.ir);
241
+ }
242
+ misses++;
243
+ const ir = await via.read(dir, opts);
244
+ if (stamp === void 0 || memberSourceStamp(dir) !== stamp) return ir;
245
+ cache.delete(key);
246
+ cache.set(key, { dir: resolve(dir), stamp, ir });
247
+ for (const oldest of cache.keys()) {
248
+ if (cache.size <= size) break;
249
+ cache.delete(oldest);
250
+ }
251
+ return structuredClone(ir);
252
+ }
253
+
254
+ export {
255
+ TERRAFORM_OBSERVE_ENV,
256
+ PLAN_READ_ENV,
257
+ rootReadsOf,
258
+ hasRootReads,
259
+ rootReadReasonWords,
260
+ readTerraformPlan,
261
+ paintTerraformPlan,
262
+ terraformPlanNote,
263
+ chantVia,
264
+ memberIrCacheStats,
265
+ invalidateMember,
266
+ memberIr
267
+ };
@@ -0,0 +1,46 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
8
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
9
+ }) : x)(function(x) {
10
+ if (typeof require !== "undefined") return require.apply(this, arguments);
11
+ throw Error('Dynamic require of "' + x + '" is not supported');
12
+ });
13
+ var __commonJS = (cb, mod) => function __require2() {
14
+ try {
15
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
16
+ } catch (e) {
17
+ throw mod = 0, e;
18
+ }
19
+ };
20
+ var __export = (target, all) => {
21
+ for (var name in all)
22
+ __defProp(target, name, { get: all[name], enumerable: true });
23
+ };
24
+ var __copyProps = (to, from, except, desc) => {
25
+ if (from && typeof from === "object" || typeof from === "function") {
26
+ for (let key of __getOwnPropNames(from))
27
+ if (!__hasOwnProp.call(to, key) && key !== except)
28
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
29
+ }
30
+ return to;
31
+ };
32
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
33
+ // If the importer is in node compatibility mode or this is not an ESM
34
+ // file that has been converted to a CommonJS file using a Babel-
35
+ // compatible transform (i.e. "__esModule" has not been set), then set
36
+ // "default" to the CommonJS "module.exports" for node compatibility.
37
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
38
+ mod
39
+ ));
40
+
41
+ export {
42
+ __require,
43
+ __commonJS,
44
+ __export,
45
+ __toESM
46
+ };
@@ -0,0 +1,78 @@
1
+ // node_modules/@intentius/chant/dist/cloud-lister/sigv4.js
2
+ import { createHash, createHmac } from "node:crypto";
3
+ var EMPTY_PAYLOAD_SHA256 = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855";
4
+ function sha256Hex(data) {
5
+ return typeof data === "string" ? createHash("sha256").update(data, "utf8").digest("hex") : createHash("sha256").update(data).digest("hex");
6
+ }
7
+ function hmac(key, data) {
8
+ return createHmac("sha256", key).update(data, "utf8").digest();
9
+ }
10
+ function encodeRfc3986(value) {
11
+ return encodeURIComponent(value).replace(/[!'()*]/g, (c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`);
12
+ }
13
+ function amzDates(now) {
14
+ const iso = now.toISOString().replace(/[-:]/g, "").replace(/\.\d{3}/, "");
15
+ return { amzDate: iso, dateStamp: iso.slice(0, 8) };
16
+ }
17
+ function signingKey(secret, dateStamp, region, service) {
18
+ return hmac(hmac(hmac(hmac(`AWS4${secret}`, dateStamp), region), service), "aws4_request");
19
+ }
20
+ function canonicalQuery(url) {
21
+ const pairs = [];
22
+ url.searchParams.forEach((v, k) => pairs.push([encodeRfc3986(k), encodeRfc3986(v)]));
23
+ pairs.sort((a, b) => a[0] === b[0] ? a[1] < b[1] ? -1 : a[1] > b[1] ? 1 : 0 : a[0] < b[0] ? -1 : 1);
24
+ return pairs.map(([k, v]) => `${k}=${v}`).join("&");
25
+ }
26
+ function signV4(input) {
27
+ const url = new URL(input.url);
28
+ const { amzDate, dateStamp } = amzDates(input.now);
29
+ const payloadHash = input.payloadHash ?? (input.body.length === 0 ? EMPTY_PAYLOAD_SHA256 : sha256Hex(input.body));
30
+ const headers = {};
31
+ for (const [k, v] of Object.entries(input.headers))
32
+ headers[k.toLowerCase()] = v.trim().replace(/\s+/g, " ");
33
+ headers.host = url.host;
34
+ headers["x-amz-date"] = amzDate;
35
+ if (input.contentSha256)
36
+ headers["x-amz-content-sha256"] = payloadHash;
37
+ if (input.credentials.sessionToken)
38
+ headers["x-amz-security-token"] = input.credentials.sessionToken;
39
+ const unsigned = new Set([...input.unsignedHeaders ?? []].map((n) => n.toLowerCase()));
40
+ const names = Object.keys(headers).filter((n) => !unsigned.has(n)).sort();
41
+ const canonicalHeaders = names.map((n) => `${n}:${headers[n]}
42
+ `).join("");
43
+ const signedHeaders = names.join(";");
44
+ const canonicalRequest = [input.method.toUpperCase(), url.pathname || "/", canonicalQuery(url), canonicalHeaders, signedHeaders, payloadHash].join("\n");
45
+ const scope = `${dateStamp}/${input.region}/${input.service}/aws4_request`;
46
+ const stringToSign = ["AWS4-HMAC-SHA256", amzDate, scope, sha256Hex(canonicalRequest)].join("\n");
47
+ const signature = createHmac("sha256", signingKey(input.credentials.secretAccessKey, dateStamp, input.region, input.service)).update(stringToSign, "utf8").digest("hex");
48
+ headers.authorization = `AWS4-HMAC-SHA256 Credential=${input.credentials.accessKeyId}/${scope}, SignedHeaders=${signedHeaders}, Signature=${signature}`;
49
+ if (input.omitHost)
50
+ delete headers.host;
51
+ return headers;
52
+ }
53
+ function presignV4(input) {
54
+ const url = new URL(input.url);
55
+ const { amzDate, dateStamp } = amzDates(input.now);
56
+ const scope = `${dateStamp}/${input.region}/${input.service}/aws4_request`;
57
+ const params = {
58
+ ...Object.fromEntries(url.searchParams),
59
+ "X-Amz-Algorithm": "AWS4-HMAC-SHA256",
60
+ "X-Amz-Credential": `${input.credentials.accessKeyId}/${scope}`,
61
+ "X-Amz-Date": amzDate,
62
+ "X-Amz-Expires": String(input.seconds),
63
+ ...input.credentials.sessionToken ? { "X-Amz-Security-Token": input.credentials.sessionToken } : {},
64
+ "X-Amz-SignedHeaders": "host"
65
+ };
66
+ const query = Object.keys(params).sort().map((k) => `${encodeRfc3986(k)}=${encodeRfc3986(params[k])}`).join("&");
67
+ const canonical = ["GET", url.pathname, query, `host:${url.host}`, "", "host", "UNSIGNED-PAYLOAD"].join("\n");
68
+ const toSign = ["AWS4-HMAC-SHA256", amzDate, scope, sha256Hex(canonical)].join("\n");
69
+ const signature = createHmac("sha256", signingKey(input.credentials.secretAccessKey, dateStamp, input.region, input.service)).update(toSign).digest("hex");
70
+ return `${url.origin}${url.pathname}?${query}&X-Amz-Signature=${signature}`;
71
+ }
72
+
73
+ export {
74
+ sha256Hex,
75
+ encodeRfc3986,
76
+ signV4,
77
+ presignV4
78
+ };
@@ -0,0 +1,124 @@
1
+ // node_modules/@intentius/chant/dist/workspace/tree.js
2
+ import { execFileSync } from "node:child_process";
3
+ import { readdirSync, readFileSync, statSync } from "node:fs";
4
+ import { join } from "node:path";
5
+ function joinPath(...parts) {
6
+ return parts.filter((p) => p !== "" && p !== ".").join("/");
7
+ }
8
+ function workingTree(root) {
9
+ return {
10
+ label: "",
11
+ stat(path) {
12
+ try {
13
+ const s = statSync(join(root, path));
14
+ return s.isDirectory() ? "dir" : s.isFile() ? "file" : void 0;
15
+ } catch {
16
+ return void 0;
17
+ }
18
+ },
19
+ list(path) {
20
+ let dirents;
21
+ try {
22
+ dirents = readdirSync(join(root, path), { withFileTypes: true });
23
+ } catch {
24
+ return void 0;
25
+ }
26
+ const out = [];
27
+ for (const d of dirents) {
28
+ let type = d.isDirectory() ? "dir" : d.isFile() ? "file" : void 0;
29
+ if (!type && d.isSymbolicLink()) {
30
+ try {
31
+ const s = statSync(join(root, path, d.name));
32
+ type = s.isDirectory() ? "dir" : s.isFile() ? "file" : void 0;
33
+ } catch {
34
+ }
35
+ }
36
+ if (type)
37
+ out.push({ name: d.name, type });
38
+ }
39
+ return out;
40
+ },
41
+ read(path) {
42
+ return readFileSync(join(root, path), "utf-8");
43
+ },
44
+ bytes(path) {
45
+ return readFileSync(join(root, path));
46
+ }
47
+ };
48
+ }
49
+ function git(cwd, args) {
50
+ return execFileSync("git", args, { cwd, encoding: "utf-8", stdio: ["ignore", "pipe", "pipe"], maxBuffer: 512 * 1024 * 1024 });
51
+ }
52
+ function gitTop(cwd) {
53
+ try {
54
+ return git(cwd, ["rev-parse", "--show-toplevel"]).trim();
55
+ } catch {
56
+ return void 0;
57
+ }
58
+ }
59
+ function resolveCommit(top, rev) {
60
+ if (rev.startsWith("-"))
61
+ return void 0;
62
+ try {
63
+ return git(top, ["rev-parse", "--verify", "--quiet", `${rev}^{commit}`]).trim();
64
+ } catch {
65
+ return void 0;
66
+ }
67
+ }
68
+ function gitTree(top, commit, prefix = "") {
69
+ const entries = /* @__PURE__ */ new Map([["", "dir"]]);
70
+ const children = /* @__PURE__ */ new Map([["", []]]);
71
+ const out = git(top, ["ls-tree", "-r", "-t", "-z", "--full-tree", commit]);
72
+ for (const line of out.split("\0")) {
73
+ if (!line)
74
+ continue;
75
+ const tab = line.indexOf(" ");
76
+ const type = line.slice(0, tab).split(" ")[1];
77
+ const full = line.slice(tab + 1);
78
+ let path;
79
+ if (prefix === "")
80
+ path = full;
81
+ else if (full.startsWith(`${prefix}/`))
82
+ path = full.slice(prefix.length + 1);
83
+ else
84
+ continue;
85
+ const kind = type === "tree" ? "dir" : type === "blob" ? "file" : void 0;
86
+ if (!kind)
87
+ continue;
88
+ entries.set(path, kind);
89
+ const slash = path.lastIndexOf("/");
90
+ const parent = slash < 0 ? "" : path.slice(0, slash);
91
+ if (!children.has(parent))
92
+ children.set(parent, []);
93
+ children.get(parent).push({ name: path.slice(slash + 1), type: kind });
94
+ if (kind === "dir" && !children.has(path))
95
+ children.set(path, []);
96
+ }
97
+ return {
98
+ label: ` at ${commit.slice(0, 8)}`,
99
+ stat: (path) => entries.get(path),
100
+ list: (path) => entries.get(path) === "dir" ? [...children.get(path) ?? []] : void 0,
101
+ read(path) {
102
+ if (entries.get(path) !== "file")
103
+ throw new Error(`${path} is not a file${` at ${commit.slice(0, 8)}`}`);
104
+ return git(top, ["cat-file", "blob", `${commit}:${joinPath(prefix, path)}`]);
105
+ },
106
+ bytes(path) {
107
+ if (entries.get(path) !== "file")
108
+ throw new Error(`${path} is not a file${` at ${commit.slice(0, 8)}`}`);
109
+ return execFileSync("git", ["cat-file", "blob", `${commit}:${joinPath(prefix, path)}`], { cwd: top, stdio: ["ignore", "pipe", "pipe"], maxBuffer: 512 * 1024 * 1024 });
110
+ }
111
+ };
112
+ }
113
+ function skippedDir(name) {
114
+ return name === "node_modules" || name.startsWith(".");
115
+ }
116
+
117
+ export {
118
+ joinPath,
119
+ workingTree,
120
+ gitTop,
121
+ resolveCommit,
122
+ gitTree,
123
+ skippedDir
124
+ };