@gadicc/loom 1.16.1 → 1.18.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 (104) hide show
  1. package/README.md +74 -41
  2. package/deno.json +3 -0
  3. package/esm/_dnt.polyfills.d.ts +6 -0
  4. package/esm/_dnt.polyfills.d.ts.map +1 -1
  5. package/esm/mod.d.ts +2 -0
  6. package/esm/mod.d.ts.map +1 -1
  7. package/esm/mod.js +2 -0
  8. package/esm/src/cli/mod.d.ts +4 -2
  9. package/esm/src/cli/mod.d.ts.map +1 -1
  10. package/esm/src/cli/mod.js +2018 -369
  11. package/esm/src/cli/projectTooling.d.ts +138 -0
  12. package/esm/src/cli/projectTooling.d.ts.map +1 -0
  13. package/esm/src/cli/projectTooling.js +614 -0
  14. package/esm/src/mail/errors.d.ts +33 -0
  15. package/esm/src/mail/errors.d.ts.map +1 -0
  16. package/esm/src/mail/errors.js +89 -0
  17. package/esm/src/mail/memory.d.ts +30 -0
  18. package/esm/src/mail/memory.d.ts.map +1 -0
  19. package/esm/src/mail/memory.js +340 -0
  20. package/esm/src/mail/mod.d.ts +7 -0
  21. package/esm/src/mail/mod.d.ts.map +1 -0
  22. package/esm/src/mail/mod.js +6 -0
  23. package/esm/src/mail/postal.d.ts +57 -0
  24. package/esm/src/mail/postal.d.ts.map +1 -0
  25. package/esm/src/mail/postal.js +238 -0
  26. package/esm/src/mail/retry.d.ts +9 -0
  27. package/esm/src/mail/retry.d.ts.map +1 -0
  28. package/esm/src/mail/retry.js +19 -0
  29. package/esm/src/mail/service.d.ts +23 -0
  30. package/esm/src/mail/service.d.ts.map +1 -0
  31. package/esm/src/mail/service.js +185 -0
  32. package/esm/src/mail/types.d.ts +176 -0
  33. package/esm/src/mail/types.d.ts.map +1 -0
  34. package/esm/src/mail/types.js +1 -0
  35. package/esm/src/mui/mail.d.ts +29 -0
  36. package/esm/src/mui/mail.d.ts.map +1 -0
  37. package/esm/src/mui/mail.js +114 -0
  38. package/esm/src/mui/mailView.d.ts +20 -0
  39. package/esm/src/mui/mailView.d.ts.map +1 -0
  40. package/esm/src/mui/mailView.js +26 -0
  41. package/esm/src/mui/mod.d.ts +1 -0
  42. package/esm/src/mui/mod.d.ts.map +1 -1
  43. package/esm/src/mui/mod.js +1 -0
  44. package/esm/src/next/mail/mod.d.ts +3 -0
  45. package/esm/src/next/mail/mod.d.ts.map +1 -0
  46. package/esm/src/next/mail/mod.js +2 -0
  47. package/esm/src/next/mail/route.d.ts +12 -0
  48. package/esm/src/next/mail/route.d.ts.map +1 -0
  49. package/esm/src/next/mail/route.js +43 -0
  50. package/package.json +56 -2
  51. package/script/_dnt.polyfills.d.ts +6 -0
  52. package/script/_dnt.polyfills.d.ts.map +1 -1
  53. package/script/mod.d.ts +2 -0
  54. package/script/mod.d.ts.map +1 -1
  55. package/script/mod.js +2 -0
  56. package/script/src/cli/mod.d.ts +4 -2
  57. package/script/src/cli/mod.d.ts.map +1 -1
  58. package/script/src/cli/mod.js +2018 -369
  59. package/script/src/cli/projectTooling.d.ts +138 -0
  60. package/script/src/cli/projectTooling.d.ts.map +1 -0
  61. package/script/src/cli/projectTooling.js +634 -0
  62. package/script/src/mail/errors.d.ts +33 -0
  63. package/script/src/mail/errors.d.ts.map +1 -0
  64. package/script/src/mail/errors.js +97 -0
  65. package/script/src/mail/memory.d.ts +30 -0
  66. package/script/src/mail/memory.d.ts.map +1 -0
  67. package/script/src/mail/memory.js +345 -0
  68. package/script/src/mail/mod.d.ts +7 -0
  69. package/script/src/mail/mod.d.ts.map +1 -0
  70. package/script/src/mail/mod.js +22 -0
  71. package/script/src/mail/postal.d.ts +57 -0
  72. package/script/src/mail/postal.d.ts.map +1 -0
  73. package/script/src/mail/postal.js +245 -0
  74. package/script/src/mail/retry.d.ts +9 -0
  75. package/script/src/mail/retry.d.ts.map +1 -0
  76. package/script/src/mail/retry.js +22 -0
  77. package/script/src/mail/service.d.ts +23 -0
  78. package/script/src/mail/service.d.ts.map +1 -0
  79. package/script/src/mail/service.js +189 -0
  80. package/script/src/mail/types.d.ts +176 -0
  81. package/script/src/mail/types.d.ts.map +1 -0
  82. package/script/src/mail/types.js +2 -0
  83. package/script/src/mui/mail.d.ts +29 -0
  84. package/script/src/mui/mail.d.ts.map +1 -0
  85. package/script/src/mui/mail.js +159 -0
  86. package/script/src/mui/mailView.d.ts +20 -0
  87. package/script/src/mui/mailView.d.ts.map +1 -0
  88. package/script/src/mui/mailView.js +32 -0
  89. package/script/src/mui/mod.d.ts +1 -0
  90. package/script/src/mui/mod.d.ts.map +1 -1
  91. package/script/src/mui/mod.js +1 -0
  92. package/script/src/next/mail/mod.d.ts +3 -0
  93. package/script/src/next/mail/mod.d.ts.map +1 -0
  94. package/script/src/next/mail/mod.js +18 -0
  95. package/script/src/next/mail/route.d.ts +12 -0
  96. package/script/src/next/mail/route.d.ts.map +1 -0
  97. package/script/src/next/mail/route.js +46 -0
  98. package/skills/loom/SKILL.md +34 -22
  99. package/skills/loom-db/SKILL.md +9 -7
  100. package/skills/loom-db/references/db-stack.md +2 -1
  101. package/skills/loom-jobs/SKILL.md +9 -6
  102. package/skills/loom-lingui/SKILL.md +38 -0
  103. package/skills/loom-lingui/agents/openai.yaml +4 -0
  104. package/skills/loom-mail/SKILL.md +68 -0
@@ -0,0 +1,634 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseJsonc = parseJsonc;
4
+ exports.detectProjectTooling = detectProjectTooling;
5
+ exports.readTaskStore = readTaskStore;
6
+ exports.denoConfigAsPackageJson = denoConfigAsPackageJson;
7
+ exports.readProjectPackageMetadata = readProjectPackageMetadata;
8
+ exports.mutateProjectDependencies = mutateProjectDependencies;
9
+ exports.mutateDenoLinks = mutateDenoLinks;
10
+ exports.readDenoLinks = readDenoLinks;
11
+ exports.getTaskCommand = getTaskCommand;
12
+ exports.getTaskDependencies = getTaskDependencies;
13
+ exports.formatTaskInvocation = formatTaskInvocation;
14
+ exports.taskInvokes = taskInvokes;
15
+ exports.taskInvokesCommand = taskInvokesCommand;
16
+ exports.taskRunsBeforeCommand = taskRunsBeforeCommand;
17
+ exports.ensureTask = ensureTask;
18
+ exports.ensureTaskPrerequisite = ensureTaskPrerequisite;
19
+ exports.ensureTaskFollowup = ensureTaskFollowup;
20
+ exports.findTaskConflicts = findTaskConflicts;
21
+ const promises_1 = require("node:fs/promises");
22
+ const node_module_1 = require("node:module");
23
+ const node_path_1 = require("node:path");
24
+ const jsoncRequire = (0, node_module_1.createRequire)(globalThis[Symbol.for("import-meta-ponyfill-commonjs")](require, module).url);
25
+ let cachedJsoncParser;
26
+ function getJsoncParser() {
27
+ cachedJsoncParser ??= jsoncRequire("jsonc-parser");
28
+ return cachedJsoncParser;
29
+ }
30
+ async function readTextIfExists(path) {
31
+ try {
32
+ return await (0, promises_1.readFile)(path, "utf8");
33
+ }
34
+ catch (error) {
35
+ if (error.code === "ENOENT")
36
+ return null;
37
+ throw error;
38
+ }
39
+ }
40
+ /** Parses Deno JSON/JSONC while reporting every syntax error. */
41
+ function parseJsonc(text, filename) {
42
+ const { parse, printParseErrorCode } = getJsoncParser();
43
+ const errors = [];
44
+ const value = parse(text, errors, {
45
+ allowEmptyContent: false,
46
+ allowTrailingComma: true,
47
+ disallowComments: false,
48
+ });
49
+ if (errors.length) {
50
+ const detail = errors.map((error) => `${printParseErrorCode(error.error)} at offset ${error.offset}`).join(", ");
51
+ throw new Error(`Failed to parse ${filename}: ${detail}`);
52
+ }
53
+ return value;
54
+ }
55
+ function parseStrictJson(text, filename) {
56
+ try {
57
+ return JSON.parse(text);
58
+ }
59
+ catch (error) {
60
+ throw new Error(`Failed to parse ${filename}: ${error.message}`);
61
+ }
62
+ }
63
+ function formattingOptions(text) {
64
+ const eol = text.includes("\r\n") ? "\r\n" : "\n";
65
+ const indentation = text.match(/(?:^|\r?\n)([\t ]+)\S/m)?.[1] ?? " ";
66
+ const insertSpaces = !indentation.includes("\t");
67
+ return {
68
+ eol,
69
+ insertFinalNewline: text.endsWith("\n"),
70
+ insertSpaces,
71
+ keepLines: true,
72
+ tabSize: insertSpaces ? Math.max(1, indentation.length) : 1,
73
+ };
74
+ }
75
+ function updateJsonPath(text, path, value) {
76
+ const { applyEdits, modify } = getJsoncParser();
77
+ return applyEdits(text, modify(text, path, value, { formattingOptions: formattingOptions(text) }));
78
+ }
79
+ function hasOwn(value, key) {
80
+ return Object.prototype.hasOwnProperty.call(value, key);
81
+ }
82
+ function definitionsEqual(left, right) {
83
+ return JSON.stringify(left) === JSON.stringify(right);
84
+ }
85
+ function definitionsConflict(left, right) {
86
+ if (definitionsEqual(left, right))
87
+ return false;
88
+ const leftCommand = getTaskCommand(left);
89
+ const rightCommand = getTaskCommand(right);
90
+ if (leftCommand !== rightCommand)
91
+ return true;
92
+ const leftDependencies = getTaskDependencies(left);
93
+ const rightDependencies = getTaskDependencies(right);
94
+ if (JSON.stringify(leftDependencies) !== JSON.stringify(rightDependencies)) {
95
+ return true;
96
+ }
97
+ const executionKeys = ["env", "files", "output"];
98
+ return executionKeys.some((key) => JSON.stringify(typeof left === "object" ? left[key] : undefined) !==
99
+ JSON.stringify(typeof right === "object" ? right[key] : undefined));
100
+ }
101
+ function packageManagerFromField(value) {
102
+ for (const manager of ["pnpm", "yarn", "npm", "deno"]) {
103
+ if (value?.startsWith(`${manager}@`))
104
+ return manager;
105
+ }
106
+ return null;
107
+ }
108
+ async function detectDependencyManager(cwd, packageJson, denoConfig) {
109
+ const declared = packageManagerFromField(packageJson?.packageManager);
110
+ if (declared)
111
+ return declared;
112
+ if (await readTextIfExists((0, node_path_1.join)(cwd, "pnpm-lock.yaml")))
113
+ return "pnpm";
114
+ if (await readTextIfExists((0, node_path_1.join)(cwd, "yarn.lock")))
115
+ return "yarn";
116
+ if (await readTextIfExists((0, node_path_1.join)(cwd, "package-lock.json")))
117
+ return "npm";
118
+ if (denoConfig || await readTextIfExists((0, node_path_1.join)(cwd, "deno.lock"))) {
119
+ return "deno";
120
+ }
121
+ return "npm";
122
+ }
123
+ function validateRecordedTooling(tooling, available) {
124
+ const configs = new Set([
125
+ "deno.json",
126
+ "deno.jsonc",
127
+ "package.json",
128
+ ]);
129
+ const managers = new Set(["deno", "npm", "pnpm", "yarn"]);
130
+ if (!tooling || typeof tooling !== "object" ||
131
+ !tooling.tasks || typeof tooling.tasks !== "object" ||
132
+ !tooling.dependencies || typeof tooling.dependencies !== "object" ||
133
+ !configs.has(tooling.tasks.config) ||
134
+ !configs.has(tooling.dependencies.config) ||
135
+ !managers.has(tooling.tasks.runner) ||
136
+ !managers.has(tooling.dependencies.manager)) {
137
+ throw new Error("loom.json records invalid project tooling.");
138
+ }
139
+ if (!available.has(tooling.tasks.config)) {
140
+ throw new Error(`loom.json records missing task config: ${tooling.tasks.config}`);
141
+ }
142
+ if (!available.has(tooling.dependencies.config)) {
143
+ throw new Error(`loom.json records missing dependency config: ${tooling.dependencies.config}`);
144
+ }
145
+ if (tooling.tasks.config !== "package.json" && tooling.tasks.runner !== "deno") {
146
+ throw new Error(`${tooling.tasks.config} tasks must use the deno task runner.`);
147
+ }
148
+ if (tooling.dependencies.config !== "package.json" &&
149
+ tooling.dependencies.manager !== "deno") {
150
+ throw new Error(`${tooling.dependencies.config} dependencies must use the deno manager.`);
151
+ }
152
+ }
153
+ /**
154
+ * Detects project tooling once during adoption. A recorded Loom choice is
155
+ * authoritative on later runs and is validated instead of inferred again.
156
+ */
157
+ async function detectProjectTooling(cwd, recorded) {
158
+ const packageText = await readTextIfExists((0, node_path_1.join)(cwd, "package.json"));
159
+ const denoText = await readTextIfExists((0, node_path_1.join)(cwd, "deno.json"));
160
+ const denoJsoncText = await readTextIfExists((0, node_path_1.join)(cwd, "deno.jsonc"));
161
+ if (denoText !== null && denoJsoncText !== null) {
162
+ throw new Error("Both deno.json and deno.jsonc exist. Keep one Deno config or record a single unambiguous project config before running Loom.");
163
+ }
164
+ if (packageText === null && denoText === null && denoJsoncText === null) {
165
+ throw new Error(`No package.json, deno.json, or deno.jsonc found in ${cwd}`);
166
+ }
167
+ const denoConfigPath = denoText !== null
168
+ ? "deno.json"
169
+ : denoJsoncText !== null
170
+ ? "deno.jsonc"
171
+ : null;
172
+ const denoConfigText = denoText ?? denoJsoncText;
173
+ const packageJson = packageText === null
174
+ ? null
175
+ : parseStrictJson(packageText, "package.json");
176
+ const denoConfig = denoConfigText === null || !denoConfigPath
177
+ ? null
178
+ : parseJsonc(denoConfigText, denoConfigPath);
179
+ const available = new Set();
180
+ if (packageText !== null)
181
+ available.add("package.json");
182
+ if (denoConfigPath)
183
+ available.add(denoConfigPath);
184
+ if (recorded) {
185
+ validateRecordedTooling(recorded, available);
186
+ return recorded;
187
+ }
188
+ const dependencyManager = await detectDependencyManager(cwd, packageJson, denoConfig);
189
+ const dependencyConfig = packageJson
190
+ ? "package.json"
191
+ : denoConfigPath;
192
+ const denoOwnsTasks = Boolean(denoConfig && hasOwn(denoConfig, "tasks"));
193
+ const taskConfig = denoOwnsTasks || !packageJson
194
+ ? denoConfigPath
195
+ : "package.json";
196
+ const taskRunner = taskConfig === "package.json"
197
+ ? dependencyManager
198
+ : "deno";
199
+ return {
200
+ dependencies: {
201
+ config: dependencyConfig,
202
+ manager: dependencyManager,
203
+ },
204
+ tasks: {
205
+ config: taskConfig,
206
+ runner: taskRunner,
207
+ },
208
+ };
209
+ }
210
+ /** Reads the task definitions from the recorded authoritative config. */
211
+ async function readTaskStore(cwd, tooling) {
212
+ const text = await readTextIfExists((0, node_path_1.join)(cwd, tooling.config));
213
+ if (text === null) {
214
+ throw new Error(`Missing authoritative task config: ${tooling.config}`);
215
+ }
216
+ if (tooling.config === "package.json") {
217
+ const packageJson = parseStrictJson(text, tooling.config);
218
+ const definitions = packageJson.scripts ?? {};
219
+ validateTaskDefinitions(definitions, tooling.config, false);
220
+ return {
221
+ config: tooling.config,
222
+ definitions,
223
+ rootKey: "scripts",
224
+ runner: tooling.runner,
225
+ text,
226
+ };
227
+ }
228
+ const denoConfig = parseJsonc(text, tooling.config);
229
+ const definitions = denoConfig.tasks ?? {};
230
+ validateTaskDefinitions(definitions, tooling.config, true);
231
+ return {
232
+ config: tooling.config,
233
+ definitions,
234
+ rootKey: "tasks",
235
+ runner: tooling.runner,
236
+ text,
237
+ };
238
+ }
239
+ function validateTaskDefinitions(definitions, config, allowStructured) {
240
+ if (!definitions || typeof definitions !== "object" ||
241
+ Array.isArray(definitions)) {
242
+ throw new Error(`${config} tasks/scripts must be an object.`);
243
+ }
244
+ for (const [name, definition] of Object.entries(definitions)) {
245
+ if (typeof definition === "string")
246
+ continue;
247
+ if (!allowStructured || !definition || typeof definition !== "object" ||
248
+ Array.isArray(definition)) {
249
+ throw new Error(`${config} task '${name}' has an invalid definition.`);
250
+ }
251
+ const task = definition;
252
+ if (task.command !== undefined && typeof task.command !== "string") {
253
+ throw new Error(`${config} task '${name}' has a non-string command.`);
254
+ }
255
+ if (task.dependencies !== undefined &&
256
+ (!Array.isArray(task.dependencies) ||
257
+ task.dependencies.some((dependency) => typeof dependency !== "string"))) {
258
+ throw new Error(`${config} task '${name}' has invalid dependencies.`);
259
+ }
260
+ }
261
+ }
262
+ function parseNpmImport(value) {
263
+ if (typeof value !== "string")
264
+ return undefined;
265
+ const match = value.match(/^npm:((?:@[^/]+\/)?[^@/]+)(?:@([^/]+))?(?:\/.*)?$/);
266
+ return match ? { name: match[1], version: match[2] ?? "*" } : undefined;
267
+ }
268
+ /** Projects a Deno import map and task table into Loom's dependency signals. */
269
+ function denoConfigAsPackageJson(config) {
270
+ const dependencies = {};
271
+ for (const value of Object.values(config.imports ?? {})) {
272
+ const dependency = parseNpmImport(value);
273
+ if (dependency)
274
+ dependencies[dependency.name] = dependency.version;
275
+ }
276
+ const scripts = Object.fromEntries(Object.entries(config.tasks ?? {}).flatMap(([name, definition]) => {
277
+ const command = getTaskCommand(definition);
278
+ return command ? [[name, command]] : [];
279
+ }));
280
+ return {
281
+ dependencies,
282
+ name: config.name,
283
+ packageManager: "deno",
284
+ scripts,
285
+ version: config.version,
286
+ };
287
+ }
288
+ /** Reads package metadata, falling back to Deno imports/tasks for Deno-only projects. */
289
+ async function readProjectPackageMetadata(cwd) {
290
+ const packageText = await readTextIfExists((0, node_path_1.join)(cwd, "package.json"));
291
+ if (packageText !== null) {
292
+ return {
293
+ config: "package.json",
294
+ packageJson: parseStrictJson(packageText, "package.json"),
295
+ path: (0, node_path_1.join)(cwd, "package.json"),
296
+ };
297
+ }
298
+ const denoJsonText = await readTextIfExists((0, node_path_1.join)(cwd, "deno.json"));
299
+ const denoJsoncText = await readTextIfExists((0, node_path_1.join)(cwd, "deno.jsonc"));
300
+ if (denoJsonText !== null && denoJsoncText !== null) {
301
+ throw new Error("Both deno.json and deno.jsonc exist.");
302
+ }
303
+ const config = denoJsonText !== null ? "deno.json" : "deno.jsonc";
304
+ const text = denoJsonText ?? denoJsoncText;
305
+ if (text === null) {
306
+ throw new Error(`No package.json, deno.json, or deno.jsonc found in ${cwd}`);
307
+ }
308
+ return {
309
+ config: config,
310
+ packageJson: denoConfigAsPackageJson(parseJsonc(text, config)),
311
+ path: (0, node_path_1.join)(cwd, config),
312
+ };
313
+ }
314
+ function npmImport(name, version) {
315
+ return `npm:${name}@${version}`;
316
+ }
317
+ /**
318
+ * Applies dependency changes to the recorded dependency owner. Deno projects
319
+ * use imports and share one dependency class; package projects retain the
320
+ * dependencies/devDependencies distinction.
321
+ */
322
+ async function mutateProjectDependencies(cwd, tooling, mutation) {
323
+ const path = (0, node_path_1.join)(cwd, tooling.config);
324
+ const original = await readTextIfExists(path);
325
+ if (original === null) {
326
+ throw new Error(`Missing authoritative dependency config: ${tooling.config}`);
327
+ }
328
+ let text = original;
329
+ const changedKeys = [];
330
+ const removedKeys = [];
331
+ if (tooling.config === "package.json") {
332
+ let config = parseStrictJson(text, tooling.config);
333
+ for (const [field, additions] of [
334
+ ["dependencies", mutation.dependencies],
335
+ ["devDependencies", mutation.devDependencies],
336
+ ]) {
337
+ for (const [name, version] of Object.entries(additions ?? {})) {
338
+ if (!mutation.replace && config[field]?.[name])
339
+ continue;
340
+ if (config[field]?.[name] === version)
341
+ continue;
342
+ text = updateJsonPath(text, [field, name], version);
343
+ config = parseStrictJson(text, tooling.config);
344
+ changedKeys.push(name);
345
+ }
346
+ }
347
+ for (const name of mutation.remove ?? []) {
348
+ for (const field of ["dependencies", "devDependencies"]) {
349
+ if (!config[field]?.[name])
350
+ continue;
351
+ text = updateJsonPath(text, [field, name], undefined);
352
+ config = parseStrictJson(text, tooling.config);
353
+ removedKeys.push(name);
354
+ }
355
+ }
356
+ }
357
+ else {
358
+ let config = parseJsonc(text, tooling.config);
359
+ const additions = {
360
+ ...mutation.devDependencies,
361
+ ...mutation.dependencies,
362
+ };
363
+ for (const [name, version] of Object.entries(additions)) {
364
+ const desired = npmImport(name, version);
365
+ if (!mutation.replace && config.imports?.[name])
366
+ continue;
367
+ if (config.imports?.[name] === desired)
368
+ continue;
369
+ text = updateJsonPath(text, ["imports", name], desired);
370
+ config = parseJsonc(text, tooling.config);
371
+ changedKeys.push(name);
372
+ }
373
+ for (const name of mutation.remove ?? []) {
374
+ if (!config.imports?.[name])
375
+ continue;
376
+ text = updateJsonPath(text, ["imports", name], undefined);
377
+ config = parseJsonc(text, tooling.config);
378
+ removedKeys.push(name);
379
+ }
380
+ if (config.nodeModulesDir === undefined) {
381
+ text = updateJsonPath(text, ["nodeModulesDir"], "auto");
382
+ }
383
+ }
384
+ if (text !== original)
385
+ await (0, promises_1.writeFile)(path, text, "utf8");
386
+ return {
387
+ changed: text !== original,
388
+ changedKeys: [...new Set(changedKeys)],
389
+ config: tooling.config,
390
+ removedKeys: [...new Set(removedKeys)],
391
+ };
392
+ }
393
+ /** Adds or removes local dependency links in a Deno config. */
394
+ async function mutateDenoLinks(cwd, config, mutation) {
395
+ const path = (0, node_path_1.join)(cwd, config);
396
+ const original = await readTextIfExists(path);
397
+ if (original === null)
398
+ throw new Error(`Missing Deno config: ${config}`);
399
+ const denoConfig = parseJsonc(original, config);
400
+ let links = [...(denoConfig.links ?? [])];
401
+ if (mutation.remove) {
402
+ links = links.filter((link) => link !== mutation.remove);
403
+ }
404
+ if (mutation.add && !links.includes(mutation.add))
405
+ links.push(mutation.add);
406
+ const text = JSON.stringify(links) === JSON.stringify(denoConfig.links ?? [])
407
+ ? original
408
+ : updateJsonPath(original, ["links"], links.length ? links : undefined);
409
+ if (text !== original)
410
+ await (0, promises_1.writeFile)(path, text, "utf8");
411
+ return { changed: text !== original, links };
412
+ }
413
+ /** Returns the configured local links without resolving their paths. */
414
+ async function readDenoLinks(cwd, config) {
415
+ const text = await readTextIfExists((0, node_path_1.join)(cwd, config));
416
+ if (text === null)
417
+ throw new Error(`Missing Deno config: ${config}`);
418
+ return parseJsonc(text, config).links ?? [];
419
+ }
420
+ /** Returns the executable command portion of either task representation. */
421
+ function getTaskCommand(definition) {
422
+ if (typeof definition === "string")
423
+ return definition;
424
+ return typeof definition?.command === "string"
425
+ ? definition.command
426
+ : undefined;
427
+ }
428
+ function getTaskDependencies(definition) {
429
+ return typeof definition === "object" &&
430
+ Array.isArray(definition.dependencies)
431
+ ? definition.dependencies.filter((value) => typeof value === "string")
432
+ : [];
433
+ }
434
+ /** Formats a task invocation for the selected project runner. */
435
+ function formatTaskInvocation(tasks, name) {
436
+ switch (tasks.runner) {
437
+ case "deno":
438
+ return `deno task ${name}`;
439
+ case "npm":
440
+ return `npm run ${name}`;
441
+ case "pnpm":
442
+ return `pnpm ${name}`;
443
+ case "yarn":
444
+ return `yarn ${name}`;
445
+ }
446
+ }
447
+ function taskInvocationPatterns(name) {
448
+ const escaped = name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
449
+ const tail = `(?:[\\s;&|)]|$)`;
450
+ return [
451
+ new RegExp(`(?:^|[\\s;&|($])deno\\s+task\\s+${escaped}${tail}`),
452
+ new RegExp(`(?:^|[\\s;&|($])npm\\s+run\\s+${escaped}${tail}`),
453
+ new RegExp(`(?:^|[\\s;&|($])pnpm\\s+(?:run\\s+)?${escaped}${tail}`),
454
+ new RegExp(`(?:^|[\\s;&|($])yarn\\s+(?:run\\s+)?${escaped}${tail}`),
455
+ ];
456
+ }
457
+ function commandInvokesTask(command, name) {
458
+ return Boolean(command &&
459
+ taskInvocationPatterns(name).some((pattern) => pattern.test(command)));
460
+ }
461
+ /** Checks direct and transitive task references without executing shell code. */
462
+ function taskInvokes(store, source, target) {
463
+ const visiting = new Set();
464
+ const visit = (name) => {
465
+ if (name === target)
466
+ return true;
467
+ if (visiting.has(name))
468
+ return false;
469
+ visiting.add(name);
470
+ const definition = store.definitions[name];
471
+ const command = getTaskCommand(definition);
472
+ if (commandInvokesTask(command, target))
473
+ return true;
474
+ if (getTaskDependencies(definition).some(visit))
475
+ return true;
476
+ return Object.keys(store.definitions).some((candidate) => candidate !== name && commandInvokesTask(command, candidate) &&
477
+ visit(candidate));
478
+ };
479
+ return source !== target && visit(source);
480
+ }
481
+ /** Checks whether a task, or a task it invokes, contains a command fragment. */
482
+ function taskInvokesCommand(store, source, expectedCommand) {
483
+ const normalizedExpected = expectedCommand.trim().replace(/\s+/g, " ");
484
+ const visiting = new Set();
485
+ const visit = (name) => {
486
+ if (visiting.has(name))
487
+ return false;
488
+ visiting.add(name);
489
+ const definition = store.definitions[name];
490
+ const command = getTaskCommand(definition)?.replace(/\s+/g, " ");
491
+ if (command?.includes(normalizedExpected))
492
+ return true;
493
+ if (getTaskDependencies(definition).some(visit))
494
+ return true;
495
+ return Object.keys(store.definitions).some((candidate) => candidate !== name && commandInvokesTask(command, candidate) &&
496
+ visit(candidate));
497
+ };
498
+ return normalizedExpected.length > 0 && visit(source);
499
+ }
500
+ /** Verifies that a task invocation is ordered before a command fragment. */
501
+ function taskRunsBeforeCommand(store, source, prerequisite, beforeCommand) {
502
+ const definition = store.definitions[source];
503
+ const command = getTaskCommand(definition);
504
+ if (!command || !command.includes(beforeCommand))
505
+ return false;
506
+ if (getTaskDependencies(definition).some((dependency) => dependency === prerequisite ||
507
+ taskInvokes(store, dependency, prerequisite))) {
508
+ return true;
509
+ }
510
+ const commandIndex = command.indexOf(beforeCommand);
511
+ return taskInvocationPatterns(prerequisite).some((pattern) => {
512
+ const match = pattern.exec(command);
513
+ return match !== null && match.index < commandIndex;
514
+ });
515
+ }
516
+ /** Ensures one task through a localized JSON/JSONC edit. */
517
+ async function ensureTask(cwd, tooling, options) {
518
+ const store = await readTaskStore(cwd, tooling);
519
+ validateTaskDefinitions({ [options.name]: options.definition }, store.config, store.config !== "package.json");
520
+ const previous = store.definitions[options.name];
521
+ if (previous !== undefined && definitionsEqual(previous, options.definition)) {
522
+ return { changed: false, config: store.config, previous, preserved: false };
523
+ }
524
+ if (previous !== undefined && options.onConflict === "preserve") {
525
+ return { changed: false, config: store.config, previous, preserved: true };
526
+ }
527
+ const text = updateJsonPath(store.text, [store.rootKey, options.name], options.definition);
528
+ if (text !== store.text) {
529
+ await (0, promises_1.writeFile)((0, node_path_1.join)(cwd, store.config), text, "utf8");
530
+ }
531
+ return {
532
+ changed: text !== store.text,
533
+ config: store.config,
534
+ previous,
535
+ preserved: false,
536
+ };
537
+ }
538
+ /**
539
+ * Ensures a prerequisite runs before a named task. Deno tasks use their native
540
+ * dependency graph; package scripts receive the runner-specific invocation.
541
+ */
542
+ async function ensureTaskPrerequisite(cwd, tooling, taskName, prerequisite) {
543
+ const store = await readTaskStore(cwd, tooling);
544
+ const current = store.definitions[taskName];
545
+ if (current === undefined) {
546
+ throw new Error(`Cannot compose missing task: ${taskName}`);
547
+ }
548
+ if (taskInvokes(store, taskName, prerequisite)) {
549
+ return { changed: false, config: store.config };
550
+ }
551
+ let definition;
552
+ if (store.config !== "package.json") {
553
+ if (typeof current === "string") {
554
+ definition = { command: current, dependencies: [prerequisite] };
555
+ }
556
+ else {
557
+ definition = {
558
+ ...current,
559
+ dependencies: [...getTaskDependencies(current), prerequisite],
560
+ };
561
+ }
562
+ }
563
+ else {
564
+ const command = getTaskCommand(current);
565
+ if (!command)
566
+ throw new Error(`Task has no command: ${taskName}`);
567
+ definition = `${formatTaskInvocation(tooling, prerequisite)} && (${command})`;
568
+ }
569
+ const result = await ensureTask(cwd, tooling, {
570
+ definition,
571
+ name: taskName,
572
+ });
573
+ return { changed: result.changed, config: result.config };
574
+ }
575
+ /** Ensures a named task runs after another task's existing command succeeds. */
576
+ async function ensureTaskFollowup(cwd, tooling, taskName, followup) {
577
+ const store = await readTaskStore(cwd, tooling);
578
+ const current = store.definitions[taskName];
579
+ if (current === undefined) {
580
+ throw new Error(`Cannot compose missing task: ${taskName}`);
581
+ }
582
+ if (taskInvokes(store, taskName, followup)) {
583
+ return { changed: false, config: store.config };
584
+ }
585
+ const command = getTaskCommand(current);
586
+ if (!command)
587
+ throw new Error(`Task has no command: ${taskName}`);
588
+ const composed = `(${command}) && ${formatTaskInvocation(tooling, followup)}`;
589
+ const definition = typeof current === "string"
590
+ ? composed
591
+ : { ...current, command: composed };
592
+ const result = await ensureTask(cwd, tooling, {
593
+ definition,
594
+ name: taskName,
595
+ });
596
+ return { changed: result.changed, config: result.config };
597
+ }
598
+ function delegatesToAuthoritativeDenoTask(primaryConfig, secondaryConfig, name, definition) {
599
+ return primaryConfig !== "package.json" &&
600
+ secondaryConfig === "package.json" &&
601
+ getTaskCommand(definition)?.trim() === `deno task ${name}`;
602
+ }
603
+ /** Finds duplicate task names that differ and do not delegate to Deno. */
604
+ async function findTaskConflicts(cwd, authoritative) {
605
+ const primary = await readTaskStore(cwd, authoritative);
606
+ const secondaryConfigs = primary.config === "package.json"
607
+ ? ["deno.json", "deno.jsonc"]
608
+ : ["package.json"];
609
+ const conflicts = [];
610
+ for (const secondaryConfig of secondaryConfigs) {
611
+ const text = await readTextIfExists((0, node_path_1.join)(cwd, secondaryConfig));
612
+ if (text === null)
613
+ continue;
614
+ const secondary = await readTaskStore(cwd, {
615
+ config: secondaryConfig,
616
+ runner: secondaryConfig === "package.json" ? "npm" : "deno",
617
+ });
618
+ for (const [name, definition] of Object.entries(primary.definitions)) {
619
+ const other = secondary.definitions[name];
620
+ if (other === undefined || !definitionsConflict(definition, other) ||
621
+ delegatesToAuthoritativeDenoTask(primary.config, secondaryConfig, name, other)) {
622
+ continue;
623
+ }
624
+ conflicts.push({
625
+ authoritative: definition,
626
+ authoritativeConfig: primary.config,
627
+ name,
628
+ secondary: other,
629
+ secondaryConfig,
630
+ });
631
+ }
632
+ }
633
+ return conflicts;
634
+ }
@@ -0,0 +1,33 @@
1
+ import type { LoomMailFailure } from "./types.js";
2
+ export declare class LoomMailError extends Error {
3
+ readonly code: string;
4
+ constructor(message: string, options: {
5
+ cause?: unknown;
6
+ code: string;
7
+ });
8
+ }
9
+ export declare class LoomMailValidationError extends LoomMailError {
10
+ constructor(message: string);
11
+ }
12
+ export declare class LoomMailTransportError extends LoomMailError {
13
+ readonly payload?: Record<string, unknown>;
14
+ readonly retryable: boolean;
15
+ constructor(message: string, options: {
16
+ cause?: unknown;
17
+ code: string;
18
+ payload?: Record<string, unknown>;
19
+ retryable: boolean;
20
+ });
21
+ toFailure(): LoomMailFailure;
22
+ }
23
+ export declare class LoomMailDeliveryError extends LoomMailError {
24
+ readonly failure: LoomMailFailure;
25
+ readonly messageId: string;
26
+ readonly retryAt: Date | null;
27
+ constructor(messageId: string, failure: LoomMailFailure, retryAt: Date | null);
28
+ }
29
+ export declare class LoomMailLeaseLostError extends LoomMailError {
30
+ readonly messageId: string;
31
+ constructor(messageId: string);
32
+ }
33
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/src/mail/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,qBAAa,aAAc,SAAQ,KAAK;IACtC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAEV,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE;CAKxE;AAED,qBAAa,uBAAwB,SAAQ,aAAa;gBAC5C,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,sBAAuB,SAAQ,aAAa;IACvD,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC3C,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;gBAG1B,OAAO,EAAE,MAAM,EACf,OAAO,EAAE;QACP,KAAK,CAAC,EAAE,OAAO,CAAC;QAChB,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAClC,SAAS,EAAE,OAAO,CAAC;KACpB;IAQH,SAAS,IAAI,eAAe;CAQ7B;AAED,qBAAa,qBAAsB,SAAQ,aAAa;IACtD,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAC;IAClC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,IAAI,GAAG,IAAI,CAAC;gBAG5B,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,eAAe,EACxB,OAAO,EAAE,IAAI,GAAG,IAAI;CAQvB;AAED,qBAAa,sBAAuB,SAAQ,aAAa;IACvD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;gBAEf,SAAS,EAAE,MAAM;CAO9B"}