@clearlydev/nx-archweave 0.4.5 → 0.5.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 (32) hide show
  1. package/README.md +13 -13
  2. package/dist/bin/review-verdict.js +1 -1
  3. package/dist/generators/_chunks/{chunk-FNSOLEVB.js → chunk-3ZHRZK5M.js} +1 -1
  4. package/dist/generators/_chunks/{chunk-FQHFT5IH.js → chunk-5Z7VZPES.js} +8 -1
  5. package/dist/generators/_chunks/{chunk-LRJVAOZ2.js → chunk-624F6DEP.js} +10 -5
  6. package/dist/generators/_chunks/{chunk-GPZEZVPN.js → chunk-ILICA6LC.js} +5 -4
  7. package/dist/generators/_chunks/{chunk-EGVFXXPE.js → chunk-L3T4H7OF.js} +14 -14
  8. package/dist/generators/_chunks/{chunk-AFAORV5O.js → chunk-M7OQWSNF.js} +1 -1
  9. package/dist/generators/_chunks/{chunk-L2RZ2LBO.js → chunk-N6B6VBHG.js} +32 -8
  10. package/dist/generators/_chunks/{chunk-KXPL6AJW.js → chunk-Q7IYHKT3.js} +2 -2
  11. package/dist/generators/_chunks/{chunk-FKABQJTB.js → chunk-SEUY3OCQ.js} +2 -2
  12. package/dist/generators/_chunks/{chunk-SKM3CM5G.js → chunk-TJ6SCQLI.js} +17 -9
  13. package/dist/generators/_chunks/{chunk-B55SAIUS.js → chunk-WVMTOWLM.js} +1 -1
  14. package/dist/generators/_chunks/{chunk-XSXOQ2EE.js → chunk-ZNTGYYLU.js} +6 -5
  15. package/dist/generators/add-agent-rules/generator.js +3 -3
  16. package/dist/generators/add-backend/generator.js +3 -3
  17. package/dist/generators/add-fsd-lite/generator.js +6 -5
  18. package/dist/generators/add-github-templates/generator.js +3 -3
  19. package/dist/generators/add-integration/generator.js +5 -5
  20. package/dist/generators/add-review/generator.js +4 -4
  21. package/dist/generators/allow-builds/generator.js +1 -1
  22. package/dist/generators/doctor/generator.js +233 -29
  23. package/dist/generators/entity/generator.js +4 -4
  24. package/dist/generators/feature/generator.js +4 -4
  25. package/dist/generators/init/generator.js +303 -61
  26. package/dist/generators/install-integration/generator.js +5 -5
  27. package/dist/generators/page/generator.js +4 -4
  28. package/dist/generators/shared/generator.js +4 -4
  29. package/dist/generators/widget/generator.js +4 -4
  30. package/package.json +1 -1
  31. package/src/generators/add-fsd-lite/schema.json +1 -1
  32. package/src/generators/init/schema.json +3 -3
@@ -1,15 +1,17 @@
1
1
  import {
2
2
  recordedReview,
3
3
  runAddReview
4
- } from "../_chunks/chunk-FKABQJTB.js";
4
+ } from "../_chunks/chunk-SEUY3OCQ.js";
5
+ import "../_chunks/chunk-ASY3CK5L.js";
5
6
  import {
6
7
  DEFAULT_MAX_ROUNDS,
8
+ REVIEW_PROVIDERS,
7
9
  buildReviewConfigSnippet
8
- } from "../_chunks/chunk-EGVFXXPE.js";
10
+ } from "../_chunks/chunk-L3T4H7OF.js";
9
11
  import {
10
12
  renderAddAgentRulesReport,
11
13
  runAddAgentRules
12
- } from "../_chunks/chunk-XSXOQ2EE.js";
14
+ } from "../_chunks/chunk-ZNTGYYLU.js";
13
15
  import {
14
16
  renderAddReviewReport
15
17
  } from "../_chunks/chunk-AON4KGZT.js";
@@ -17,26 +19,31 @@ import "../_chunks/chunk-5MI3O4VZ.js";
17
19
  import {
18
20
  renderAddBackendBody,
19
21
  runAddBackend
20
- } from "../_chunks/chunk-LRJVAOZ2.js";
22
+ } from "../_chunks/chunk-624F6DEP.js";
21
23
  import "../_chunks/chunk-WNO3ZGBB.js";
22
24
  import {
23
25
  DEFAULT_CONFLICT_POLICY,
24
26
  renderAddFsdLiteReport,
25
27
  runAddFsdLite
26
- } from "../_chunks/chunk-SKM3CM5G.js";
27
- import "../_chunks/chunk-L2RZ2LBO.js";
28
+ } from "../_chunks/chunk-TJ6SCQLI.js";
29
+ import {
30
+ TOOLKIT_CONFIG_INPUT,
31
+ lintInputsProjectSnippet,
32
+ lintInputsTargetDefaultsSnippet
33
+ } from "../_chunks/chunk-N6B6VBHG.js";
28
34
  import {
29
35
  allFrameworkProfiles,
30
36
  resolveFrontendApp
31
- } from "../_chunks/chunk-B55SAIUS.js";
37
+ } from "../_chunks/chunk-WVMTOWLM.js";
32
38
  import "../_chunks/chunk-TXAQ2GJC.js";
33
39
  import {
40
+ ESLINT_CONFIG_CANDIDATES,
34
41
  readBoundaryTags
35
42
  } from "../_chunks/chunk-6ZTIUBB2.js";
36
43
  import {
37
44
  renderAddGithubTemplatesReport,
38
45
  runAddGithubTemplates
39
- } from "../_chunks/chunk-FNSOLEVB.js";
46
+ } from "../_chunks/chunk-3ZHRZK5M.js";
40
47
  import "../_chunks/chunk-YNMLB4DL.js";
41
48
  import "../_chunks/chunk-JPS6XKYK.js";
42
49
  import {
@@ -45,6 +52,7 @@ import {
45
52
  import {
46
53
  spawnableCommand
47
54
  } from "../_chunks/chunk-34V6HAJT.js";
55
+ import "../_chunks/chunk-ILICA6LC.js";
48
56
  import {
49
57
  DEFAULT_AI_HOSTS,
50
58
  RECORDED_BACKENDS,
@@ -60,10 +68,11 @@ import {
60
68
  resolveLocaleOption,
61
69
  reviewProviderFor,
62
70
  treePackageManager
63
- } from "../_chunks/chunk-AFAORV5O.js";
71
+ } from "../_chunks/chunk-M7OQWSNF.js";
64
72
  import {
65
- packageManagerCommands
66
- } from "../_chunks/chunk-FQHFT5IH.js";
73
+ packageManagerCommands,
74
+ runNxCommand
75
+ } from "../_chunks/chunk-5Z7VZPES.js";
67
76
 
68
77
  // src/generators/init/generator.ts
69
78
  import { execFileSync } from "node:child_process";
@@ -80,30 +89,16 @@ function buildFsdConfig(enforcement, frontend) {
80
89
  layerMapping: Object.fromEntries(allFrameworkProfiles().map((profile) => [profile.id, [...profile.layers]]))
81
90
  };
82
91
  }
92
+ var QUICK_START_DEFAULTS = {
93
+ reviewEnabledDefault: false,
94
+ reviewMode: "fast",
95
+ fsdEnforcement: "warn",
96
+ agentRulesTeamRules: false,
97
+ githubTemplates: { issue: false, pr: true, codeowners: false }
98
+ };
83
99
  var PRESET_DEFAULTS = {
84
- "quick-start": {
85
- // add-review: opt-in (a single install question), `fast` mode by default.
86
- reviewEnabledDefault: false,
87
- reviewMode: "fast",
88
- // add-fsd-lite: enabled with every default layer, no questions — violations warn.
89
- fsdEnforcement: "warn",
90
- // add-agent-rules: enabled (simple version). Which files follow from the AI hosts
91
- // picked, no longer from the preset.
92
- agentRulesTeamRules: false,
93
- // add-github-templates: minimal (PR template only).
94
- githubTemplates: { issue: false, pr: true, codeowners: false }
95
- },
96
- solo: {
97
- // add-review: `fast` mode by default — no opt-in question, so enabled by default.
98
- reviewEnabledDefault: true,
99
- reviewMode: "fast",
100
- // add-fsd-lite: enabled — violations warn (no over-enforcement).
101
- fsdEnforcement: "warn",
102
- // add-agent-rules: enabled — files follow the AI hosts picked.
103
- agentRulesTeamRules: false,
104
- // add-github-templates: optional — see note #2 above.
105
- githubTemplates: { issue: false, pr: true, codeowners: false }
106
- },
100
+ "quick-start": QUICK_START_DEFAULTS,
101
+ solo: QUICK_START_DEFAULTS,
107
102
  team: {
108
103
  // Requiring review only for P2 findings when CODEOWNERS is wired up is out of v0.1
109
104
  // scope and has no field here. The other two Team-only behaviors are the two
@@ -113,12 +108,12 @@ var PRESET_DEFAULTS = {
113
108
  reviewEnabledDefault: true,
114
109
  reviewMode: "standard",
115
110
  // add-fsd-lite: enabled + stricter module boundaries — the canonical FSD rule
116
- // reports as an error here, as a warning in the other presets.
111
+ // reports as an error here, as a warning in quick-start.
117
112
  fsdEnforcement: "error",
118
113
  // add-agent-rules: enabled + an extra team-rules section — the extra section is
119
114
  // content `template-engine/agent-rules` composes, not a different `files` list.
120
115
  agentRulesTeamRules: true,
121
- // add-github-templates: full (Issue+PR, CODEOWNERS optional) — see note #2 above.
116
+ // add-github-templates: full (Issue+PR, CODEOWNERS opt-in).
122
117
  githubTemplates: { issue: true, pr: true, codeowners: false }
123
118
  }
124
119
  };
@@ -155,6 +150,166 @@ function buildPresetConfig(input) {
155
150
  };
156
151
  }
157
152
 
153
+ // src/generators/init/left-for-you.ts
154
+ var PLUGIN = "@clearlydev/nx-archweave";
155
+ function leftForYou(report) {
156
+ const runNx = report.runNx ?? runNxCommand(report.packageManager);
157
+ const kept = [];
158
+ const manual = [];
159
+ for (const section of report.sections) {
160
+ if (!section.enabled || section.report === null) continue;
161
+ const sectionReport = section.report;
162
+ switch (sectionReport.kind) {
163
+ case "fsd": {
164
+ const fsd = sectionReport.report;
165
+ if (fsd.aborted) break;
166
+ if (fsd.eslint === "degraded-unrecognized") {
167
+ manual.push(
168
+ fsd.eslintPath === null ? `${fsd.project ?? "the app"}: no ESLint config found \u2014 add the archweave/fsd-boundaries rule to one (the snippet is above)` : `${fsd.eslintPath}: not recognized \u2014 add the archweave/fsd-boundaries rule yourself (the snippet is above)`
169
+ );
170
+ }
171
+ const steiger = fsd.steiger;
172
+ if (steiger !== null) {
173
+ if (steiger.config === "kept") kept.push(`${steiger.configPath}: an existing steiger config with other content \u2014 left as it is`);
174
+ if (steiger.target === "unrecognized") manual.push(`${fsd.project ?? "the app"}: add the fsd-check target yourself (no parseable project.json or package.json)`);
175
+ if (steiger.dependencies === "unrecognized") {
176
+ manual.push("package.json: could not be parsed \u2014 add steiger and @feature-sliced/steiger-plugin to devDependencies yourself");
177
+ }
178
+ }
179
+ break;
180
+ }
181
+ case "agentRules":
182
+ for (const file of sectionReport.report.files) {
183
+ if (file.action === "user-modified") {
184
+ kept.push(`${file.filePath}: its nx-archweave block was edited by hand \u2014 to replace it: ${runNx} g ${PLUGIN}:add-agent-rules --overwriteBlock`);
185
+ } else if (file.action === "unrecognized") {
186
+ kept.push(`${file.filePath}: left untouched (${file.reason ?? "its nx-archweave markers could not be placed"}) \u2014 fix the file, then rerun init`);
187
+ }
188
+ }
189
+ break;
190
+ case "githubTemplates":
191
+ for (const file of sectionReport.report.files) {
192
+ if (file.action === "skipped") {
193
+ kept.push(`${file.filePath}: a different file is already there \u2014 to use the generated one, delete it and run ${runNx} g ${PLUGIN}:add-github-templates`);
194
+ }
195
+ }
196
+ break;
197
+ case "review": {
198
+ const review = sectionReport.report;
199
+ if (review.workflowAction === "aborted") break;
200
+ if (review.workflowAction === "proposed" || review.workflowAction === "skipped") {
201
+ kept.push(`${review.workflowPath}: differs from the generated workflow \u2014 to replace it: ${runNx} g ${PLUGIN}:add-review --onConflict=overwrite`);
202
+ } else if (review.workflowAction === "alternate") {
203
+ manual.push(`${review.workflowPath}: written alongside the existing workflow \u2014 replace the main workflow file with it yourself`);
204
+ }
205
+ if (review.dependabot === "proposed") manual.push(".github/dependabot.yml: add the github-actions entry shown above");
206
+ break;
207
+ }
208
+ case "backend": {
209
+ const backend = sectionReport.report;
210
+ if (backend.refused !== void 0) break;
211
+ if (backend.eslint === "degraded-unrecognized") manual.push("ESLint boundaries: your config was not recognized \u2014 merge the constraints shown above yourself");
212
+ if (backend.tsconfigPaths === "unrecognized") {
213
+ manual.push(`tsconfig.base.json: could not be parsed \u2014 add the ${backend.sharedTypesPackage ?? "shared-types"} path yourself`);
214
+ }
215
+ const linkedByPaths = backend.tsconfigPaths === "added" || backend.tsconfigPaths === "present";
216
+ if (backend.workspaceGlob === "unrecognized" && !linkedByPaths) {
217
+ const registry = packageManagerCommands(backend.packageManager ?? "pnpm").workspaceRegistration;
218
+ manual.push(`${registry}: shape not recognized \u2014 add '${backend.sharedTypesRoot ?? "libs/shared-types"}' to its workspace list yourself`);
219
+ }
220
+ break;
221
+ }
222
+ }
223
+ }
224
+ return { kept, manual };
225
+ }
226
+ function renderLeftForYou(left) {
227
+ const lines = [];
228
+ if (left.kept.length > 0) {
229
+ lines.push("", "Skipped to keep your changes:", ...left.kept.map((item) => ` ${item}`));
230
+ }
231
+ if (left.manual.length > 0) {
232
+ lines.push("", "Needs a manual step:", ...left.manual.map((item) => ` ${item}`));
233
+ }
234
+ return lines;
235
+ }
236
+
237
+ // src/generators/init/lint-inputs.ts
238
+ import { getProjects } from "@nx/devkit";
239
+ import { parse } from "jsonc-parser";
240
+ var ESLINT_PLUGIN = "@nx/eslint/plugin";
241
+ var ESLINT_EXECUTOR = "@nx/eslint:lint";
242
+ var isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
243
+ function applyLintInputs(tree, input) {
244
+ const raw = tree.read("nx.json", "utf-8");
245
+ if (raw === null) return void 0;
246
+ const nxJson = parse(raw, [], { allowTrailingComma: true });
247
+ if (!isObject(nxJson)) return void 0;
248
+ const plugins = Array.isArray(nxJson["plugins"]) ? nxJson["plugins"] : [];
249
+ const plugin = plugins.find((entry) => entry === ESLINT_PLUGIN || isObject(entry) && entry["plugin"] === ESLINT_PLUGIN);
250
+ const options = isObject(plugin) && isObject(plugin["options"]) ? plugin["options"] : {};
251
+ const target = typeof options["targetName"] === "string" ? options["targetName"] : "lint";
252
+ const targetDefaults = isObject(nxJson["targetDefaults"]) ? nxJson["targetDefaults"] : {};
253
+ const namedInputs = isObject(nxJson["namedInputs"]) ? nxJson["namedInputs"] : {};
254
+ const defaultsKey = [target, ESLINT_EXECUTOR].find((key) => isObject(targetDefaults[key]) && Array.isArray(targetDefaults[key]["inputs"]));
255
+ const defaultsInputs = defaultsKey === void 0 ? void 0 : targetDefaults[defaultsKey]["inputs"];
256
+ const carries = (inputs) => inputs.some((entry) => {
257
+ if (entry === TOOLKIT_CONFIG_INPUT) return true;
258
+ const named = typeof entry === "string" ? namedInputs[entry.replace(/^\^/, "")] : void 0;
259
+ return Array.isArray(named) && named.includes(TOOLKIT_CONFIG_INPUT);
260
+ });
261
+ if (defaultsInputs !== void 0 && carries(defaultsInputs)) return { action: "present", target };
262
+ const projects = getProjects(tree);
263
+ const ownTarget = (name) => {
264
+ const project = projects.get(name);
265
+ if (project === void 0) return void 0;
266
+ if (isObject(project.targets?.[target])) return { file: projectFile(tree, project.root), inputs: project.targets?.[target]?.inputs };
267
+ const pkg = readJson(tree, `${prefix(project.root)}package.json`);
268
+ if (isObject(pkg) && isObject(pkg["scripts"]) && typeof pkg["scripts"][target] === "string") return { file: `${prefix(project.root)}package.json`, inputs: void 0 };
269
+ return void 0;
270
+ };
271
+ const ownTargets = [...projects.keys()].filter((name) => ownTarget(name) !== void 0).sort();
272
+ const reason = !input.firstRun ? "not-first-run" : plugin === void 0 ? "no-plugin" : ownTargets.length > 0 ? "own-targets" : defaultsInputs !== void 0 ? "existing-inputs" : void 0;
273
+ if (reason === void 0) {
274
+ if (!input.dryRun) tree.write("nx.json", applyJsonEdits(raw, [[["targetDefaults", target, "inputs"], ["...", TOOLKIT_CONFIG_INPUT]]]));
275
+ return { action: "added", target };
276
+ }
277
+ const fsdProjects = input.fsdProjects.filter((name) => prefix(projects.get(name)?.root ?? "") !== "");
278
+ const snippet = reason === "existing-inputs" && defaultsKey !== void 0 ? [`Add "${TOOLKIT_CONFIG_INPUT}" to targetDefaults["${defaultsKey}"].inputs in nx.json.`] : plugin !== void 0 && ownTargets.length === 0 ? lintInputsTargetDefaultsSnippet(target) : fsdProjects.flatMap((name) => {
279
+ const root = projects.get(name)?.root ?? "";
280
+ const own = ownTarget(name);
281
+ return lintInputsProjectSnippet({
282
+ file: own?.file ?? projectFile(tree, root),
283
+ target,
284
+ ownInputs: own?.inputs !== void 0,
285
+ eslintConfigs: eslintConfigs(tree, root)
286
+ });
287
+ });
288
+ return {
289
+ action: "snippet",
290
+ target,
291
+ reason,
292
+ ...reason === "own-targets" ? { ownTargets } : {},
293
+ snippet,
294
+ skipCache: fsdProjects.map((name) => `${input.runNx} ${target} ${name} --skip-nx-cache`)
295
+ };
296
+ }
297
+ function prefix(root) {
298
+ return root === "" || root === "." ? "" : `${root}/`;
299
+ }
300
+ function readJson(tree, path) {
301
+ const raw = tree.read(path, "utf-8");
302
+ return raw === null ? null : parse(raw, [], { allowTrailingComma: true });
303
+ }
304
+ function projectFile(tree, root) {
305
+ return tree.exists(`${prefix(root)}project.json`) ? `${prefix(root)}project.json` : `${prefix(root)}package.json`;
306
+ }
307
+ function eslintConfigs(tree, root) {
308
+ const own = ESLINT_CONFIG_CANDIDATES.find((name) => tree.exists(`${prefix(root)}${name}`));
309
+ const workspace = ESLINT_CONFIG_CANDIDATES.find((name) => tree.exists(name));
310
+ return [...own === void 0 || prefix(root) === "" ? [] : [`{projectRoot}/${own}`], ...workspace === void 0 ? [] : [`{workspaceRoot}/${workspace}`]];
311
+ }
312
+
158
313
  // src/generators/init/render.ts
159
314
  var SECTION_TITLES = {
160
315
  fsd: "add-fsd-lite",
@@ -186,18 +341,19 @@ function sectionAborted(section) {
186
341
  return false;
187
342
  }
188
343
  function failedSections(report) {
189
- return report.sections.filter(sectionAborted).map((section) => SECTION_TITLES[section.id]);
344
+ const failed = report.sections.filter(sectionAborted).map((section) => SECTION_TITLES[section.id]);
345
+ return report.config?.action === "unrecognized" ? [...failed, "toolkit.config.json"] : failed;
190
346
  }
191
347
  function renderInitReport(report) {
192
348
  const lines = [];
193
349
  const backendSuffix = report.backend === "none" ? "" : `, backend: ${report.backend}`;
194
350
  const header = `init (preset: ${report.preset}, frontend: ${report.frontend}${backendSuffix})`;
195
351
  lines.push(report.dryRun ? `${header} \u2014 dry run` : header);
352
+ if (report.preset === "solo") {
353
+ lines.push("Note: solo is now an alias of quick-start \u2014 AI PR review stays off unless you pass --review.");
354
+ }
196
355
  if (report.refused) {
197
- lines.push("");
198
- lines.push("Refused: the working tree has uncommitted changes.");
199
- lines.push(" init only runs against a clean working tree, so a partial run can be rolled back exactly");
200
- lines.push(" to what was committed \u2014 commit or stash your changes, then rerun.");
356
+ lines.push("", ...renderRefusal(report.dirtyFiles));
201
357
  return lines.join("\n");
202
358
  }
203
359
  for (const section of report.sections) {
@@ -208,6 +364,9 @@ function renderInitReport(report) {
208
364
  lines.push(
209
365
  section.id === "fsd" && report.frontend === "none" ? " skipped (backend-only workspace \u2014 no frontend to structure)" : " skipped (disabled for this run)"
210
366
  );
367
+ if (section.keptFiles !== void 0 && section.keptFiles.length > 0) {
368
+ lines.push(` Kept as they are: ${section.keptFiles.join(", ")}. To update them, run add-review.`);
369
+ }
211
370
  continue;
212
371
  }
213
372
  if (section.thrownError !== void 0) {
@@ -232,8 +391,9 @@ function renderInitReport(report) {
232
391
  lines.push(` already records ${fieldList} (unchanged)`);
233
392
  break;
234
393
  case "unrecognized":
235
- lines.push(` not updated \u2014 the file is not a JSON object, so init left it alone (it never rewrites a shape it`);
236
- lines.push(` does not recognize). Add ${fieldList} by hand so standalone reruns resolve the same values.`);
394
+ lines.push(` aborted \u2014 the file is not a JSON object, so init left it alone (it never rewrites a shape it`);
395
+ lines.push(` does not recognize) and could not record ${fieldList}. The generators you run next read`);
396
+ lines.push(" them from here: make the file a JSON object (or delete it), then rerun init.");
237
397
  break;
238
398
  case "skipped":
239
399
  break;
@@ -241,17 +401,18 @@ function renderInitReport(report) {
241
401
  if (report.config.notRecorded.length > 0) {
242
402
  lines.push(` not recorded: ${report.config.notRecorded.map((n) => n.field).join(", ")} \u2014 that section did not apply cleanly`);
243
403
  lines.push(" this run (aborted, or written as an alternate file). Once resolved, record it with:");
244
- const runNx = packageManagerCommands(report.packageManager ?? "pnpm").runNx;
404
+ const runNx = report.runNx ?? runNxCommand(report.packageManager);
245
405
  for (const entry of report.config.notRecorded) lines.push(` ${runNx} g @clearlydev/nx-archweave:${entry.rerun}`);
246
406
  }
247
407
  }
408
+ if (report.lintInputs !== void 0) lines.push("", "## nx.json", ...renderLintInputs(report.lintInputs, report.dryRun));
248
409
  const ranDirty = report.allowDirty === true && !report.cleanTree && !report.dryRun;
249
410
  if (ranDirty && report.dirtyFromCaller !== true) {
250
411
  lines.push("");
251
412
  lines.push("Note: --allowDirty was set and the working tree already had uncommitted changes \u2014");
252
413
  lines.push("restoring the files this run modified also reverts your earlier changes to them.");
253
414
  }
254
- const hadAbort = report.sections.some(sectionAborted);
415
+ const hadAbort = failedSections(report).length > 0;
255
416
  if (!report.dryRun && hadAbort) {
256
417
  lines.push("");
257
418
  lines.push("One or more sections aborted. To undo what this run wrote:");
@@ -265,8 +426,53 @@ function renderInitReport(report) {
265
426
  for (const path of written.created) lines.push(` ${path}`);
266
427
  }
267
428
  }
429
+ lines.push(...renderLeftForYou(leftForYou(report)));
268
430
  return lines.join("\n");
269
431
  }
432
+ function renderLintInputs(outcome, dryRun) {
433
+ if (outcome.action === "present") return [` ${outcome.target} inputs already include toolkit.config.json`];
434
+ if (outcome.action === "added") {
435
+ return [
436
+ ` ${dryRun ? "would add" : "added"} "{workspaceRoot}/toolkit.config.json" to targetDefaults.${outcome.target}.inputs, after "..." (which keeps`,
437
+ " the inputs @nx/eslint/plugin infers), so Nx re-runs lint after a change to the fsd policy"
438
+ ];
439
+ }
440
+ const reason = {
441
+ "not-first-run": "init writes nx.json only when it sets a workspace up for the first time",
442
+ "no-plugin": "@nx/eslint/plugin is not registered, so targetDefaults would replace the lint targets' inputs",
443
+ "own-targets": `${(outcome.ownTargets ?? []).join(", ")} write their own ${outcome.target} target, which keeps only what targetDefaults lists`,
444
+ "existing-inputs": `targetDefaults already gives ${outcome.target} inputs of its own`
445
+ }[outcome.reason ?? "not-first-run"];
446
+ return [
447
+ " toolkit.config.json is not among lint's inputs, so Nx can replay a cached lint result after a change to the",
448
+ ` fsd policy. Not written \u2014 ${reason}.`,
449
+ ...(outcome.snippet ?? []).map((line) => ` ${line}`),
450
+ ...(outcome.skipCache ?? []).length > 0 ? [` Or, after changing the fsd policy, check with: ${(outcome.skipCache ?? []).join(", ")}`] : []
451
+ ];
452
+ }
453
+ var SHOWN_DIRTY_FILES = 20;
454
+ var LOCKFILES = /* @__PURE__ */ new Set(["pnpm-lock.yaml", "package-lock.json", "yarn.lock", "bun.lock", "bun.lockb"]);
455
+ function renderRefusal(dirtyFiles) {
456
+ const lines = ["Refused: the working tree has uncommitted changes."];
457
+ lines.push(" init only runs against a clean working tree, so a partial run can be rolled back exactly");
458
+ if (dirtyFiles === void 0 || dirtyFiles.length === 0) {
459
+ lines.push(" to what was committed \u2014 commit or stash your changes, then rerun.");
460
+ } else {
461
+ lines.push(" to what was committed. Uncommitted:");
462
+ for (const path of dirtyFiles.slice(0, SHOWN_DIRTY_FILES)) lines.push(` ${path}`);
463
+ if (dirtyFiles.length > SHOWN_DIRTY_FILES) lines.push(` \u2026 and ${dirtyFiles.length - SHOWN_DIRTY_FILES} more`);
464
+ const pluginInstall = dirtyFiles.includes("package.json") && dirtyFiles.every((path) => path === "package.json" || LOCKFILES.has(path));
465
+ if (pluginInstall) {
466
+ lines.push(" These are the plugin install. Commit them, then rerun init:");
467
+ lines.push(` git add ${dirtyFiles.join(" ")} && git commit -m "chore: add @clearlydev/nx-archweave"`);
468
+ } else {
469
+ lines.push(" Check them with `git status`, then commit or stash them, and rerun init.");
470
+ }
471
+ }
472
+ lines.push(" Or pass --allowDirty to run anyway: restoring a file this run modifies then also reverts");
473
+ lines.push(" the changes you had made to it.");
474
+ return lines;
475
+ }
270
476
 
271
477
  // src/generators/init/validation.ts
272
478
  import { spawnSync } from "node:child_process";
@@ -340,15 +546,15 @@ function recordPresetChoices(tree, choices, notRecorded, write) {
340
546
  const { raw, parsed } = readToolkitConfigFile(tree);
341
547
  if (raw !== null && parsed === null) return { action: "unrecognized", fields, notRecorded };
342
548
  const existing = parsed ?? {};
343
- const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
549
+ const isObject2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
344
550
  const edits = [];
345
551
  for (const key of topLevel) {
346
552
  if (existing[key] !== choices[key]) edits.push([[key], choices[key]]);
347
553
  }
348
554
  const nested = (parent, key, value) => {
349
555
  const holder = existing[parent];
350
- if (isObject(holder) && holder[key] === value) return;
351
- edits.push(isObject(holder) ? [[parent, key], value] : [[parent], { [key]: value }]);
556
+ if (isObject2(holder) && holder[key] === value) return;
557
+ edits.push(isObject2(holder) ? [[parent, key], value] : [[parent], { [key]: value }]);
352
558
  };
353
559
  if (choices.enforcement !== void 0) nested("fsd", "enforcement", choices.enforcement);
354
560
  if (choices.teamRules !== void 0) nested("agentRules", "teamRules", choices.teamRules);
@@ -365,6 +571,10 @@ function recordPresetChoices(tree, choices, notRecorded, write) {
365
571
  if (write) tree.write(TOOLKIT_CONFIG_PATH, applyJsonEdits(raw, edits));
366
572
  return { action: raw === null ? "created" : "updated", fields, notRecorded };
367
573
  }
574
+ function existingReviewFiles(tree, config) {
575
+ const workflows = Object.values(REVIEW_PROVIDERS).map((provider) => provider.workflowFileName).filter((path) => tree.exists(path));
576
+ return config?.["review"] === void 0 ? workflows : [...workflows, "toolkit.config.json (review field)"];
577
+ }
368
578
  function keptReviewProvider(option, config) {
369
579
  const recordedHosts = resolveAiHostsOption(void 0, config);
370
580
  const hosts = resolveAiHostsOption(option, config);
@@ -388,6 +598,7 @@ function writtenSince(before, tree) {
388
598
  }
389
599
  function runInit(tree, options, deps) {
390
600
  const before = pendingContents(tree);
601
+ const firstRun = !tree.exists("toolkit.config.json");
391
602
  const recorded = readToolkitConfigFile(tree).parsed;
392
603
  const preset = options.preset ?? recordedChoice(recorded, "preset", RECORDED_PRESETS);
393
604
  if (preset === void 0) {
@@ -403,9 +614,10 @@ function runInit(tree, options, deps) {
403
614
  const dryRun = options.dryRun ?? false;
404
615
  const locale = resolveLocaleOption(options.locale, recorded);
405
616
  const allowDirty = options.allowDirty ?? false;
406
- const cleanTree = dryRun ? true : deps.isWorkingTreeClean(tree.root);
617
+ const changes = dryRun ? [] : deps.workingTreeChanges(tree.root);
618
+ const cleanTree = changes !== null && changes.length === 0;
407
619
  if (!cleanTree && !allowDirty) {
408
- return { preset, frontend, backend, dryRun, cleanTree: false, allowDirty, refused: true, sections: [] };
620
+ return { preset, frontend, backend, dryRun, cleanTree: false, allowDirty, refused: true, ...changes === null ? {} : { dirtyFiles: changes }, sections: [] };
409
621
  }
410
622
  const knownPackageManager = options.packageManager ?? treePackageManager(tree, recorded);
411
623
  const packageManager = knownPackageManager ?? "pnpm";
@@ -510,7 +722,7 @@ function runInit(tree, options, deps) {
510
722
  });
511
723
  sections.push({ id: "review", enabled: true, report: { kind: "review", report } });
512
724
  } else {
513
- sections.push({ id: "review", enabled: false, report: null });
725
+ sections.push({ id: "review", enabled: false, report: null, keptFiles: existingReviewFiles(tree, recorded) });
514
726
  }
515
727
  const fsdSections = sections.filter((s) => s.id === "fsd");
516
728
  const fsdRan = fsdSections.some((s) => s.enabled);
@@ -533,6 +745,12 @@ function runInit(tree, options, deps) {
533
745
  });
534
746
  notRecorded.push({ field: "aiHosts", rerun: `add-agent-rules --hosts=${config.aiHosts.join(",")}` });
535
747
  }
748
+ const lintInputs = fsdApplied ? applyLintInputs(tree, {
749
+ firstRun,
750
+ fsdProjects: fsdSections.flatMap((s) => s.report?.kind === "fsd" && s.report.report.project !== null ? [s.report.report.project] : []),
751
+ dryRun,
752
+ runNx: runNxCommand(knownPackageManager)
753
+ }) : void 0;
536
754
  const configOutcome = recordPresetChoices(
537
755
  tree,
538
756
  {
@@ -561,6 +779,7 @@ function runInit(tree, options, deps) {
561
779
  frontend,
562
780
  backend,
563
781
  packageManager,
782
+ runNx: runNxCommand(knownPackageManager),
564
783
  dryRun,
565
784
  cleanTree,
566
785
  allowDirty,
@@ -568,21 +787,44 @@ function runInit(tree, options, deps) {
568
787
  refused: false,
569
788
  sections,
570
789
  config: configOutcome,
790
+ ...lintInputs === void 0 ? {} : { lintInputs },
571
791
  written: dryRun ? void 0 : writtenSince(before, tree)
572
792
  };
573
793
  }
574
- function gitIsWorkingTreeClean(root) {
794
+ function gitWorkingTreeChanges(root) {
575
795
  try {
576
- const output = execFileSync("git", ["status", "--porcelain"], { cwd: root, encoding: "utf-8" });
577
- return output.trim().length === 0;
796
+ const output = execFileSync("git", ["status", "--porcelain", "-z"], { cwd: root, encoding: "utf-8" });
797
+ const entries = output.split("\0");
798
+ const paths = [];
799
+ for (let index = 0; index < entries.length; index += 1) {
800
+ const entry = entries[index];
801
+ if (entry.length < 4) continue;
802
+ paths.push(entry.slice(3));
803
+ if (/[RC]/.test(entry.slice(0, 2))) index += 1;
804
+ }
805
+ return paths;
578
806
  } catch (error) {
579
807
  console.warn(
580
808
  "init: could not determine the working tree status (the git command failed) \u2014 treating it as dirty for safety."
581
809
  );
582
810
  if (error instanceof Error) console.warn(` ${error.message}`);
583
- return false;
811
+ return null;
584
812
  }
585
813
  }
814
+ function initFailure(report, strict) {
815
+ if (report.refused) return "init refused: the working tree has uncommitted changes \u2014 see the report above.";
816
+ const aborted = failedSections(report);
817
+ if (aborted.length > 0) return `init: a section aborted (${aborted.join(", ")}) \u2014 see the report above.`;
818
+ if (!strict) return null;
819
+ const left = leftForYou(report);
820
+ const count = left.kept.length + left.manual.length;
821
+ return count === 0 ? null : `init --strict: init couldn't do everything you asked for (${count} ${count === 1 ? "item" : "items"}) \u2014 see the report above.`;
822
+ }
823
+ function reportedFailure(message) {
824
+ const error = new Error(message);
825
+ error.stack = "";
826
+ return error;
827
+ }
586
828
  function collectWrittenWorkflowPaths(report) {
587
829
  const paths = [];
588
830
  for (const section of report.sections) {
@@ -594,17 +836,17 @@ function collectWrittenWorkflowPaths(report) {
594
836
  }
595
837
  return paths;
596
838
  }
597
- async function initGenerator(tree, options, deps = { isWorkingTreeClean: gitIsWorkingTreeClean }) {
839
+ async function initGenerator(tree, options, deps = { workingTreeChanges: gitWorkingTreeChanges }) {
598
840
  const changesBefore = tree.listChanges().length;
599
841
  const report = runInit(tree, { ...options, dryRun: resolveDryRun(options) }, deps);
600
842
  console.log(renderInitReport(report));
601
- const failed = options.strict === true ? report.refused ? ["the dirty-tree check"] : failedSections(report) : [];
602
- const strictFailure = failed.length === 0 ? null : new Error(`init --strict: a section aborted (${failed.join(", ")}) \u2014 see the report above.`);
603
- if (strictFailure !== null && (report.dryRun || report.refused)) throw strictFailure;
843
+ const message = initFailure(report, options.strict === true);
844
+ const failure = message === null ? null : reportedFailure(message);
845
+ if (failure !== null && (report.dryRun || report.refused)) throw failure;
604
846
  if (report.dryRun || report.refused) return;
605
847
  const wrote = tree.listChanges().length !== changesBefore;
606
848
  if (!wrote) {
607
- if (strictFailure !== null) throw strictFailure;
849
+ if (failure !== null) throw failure;
608
850
  return;
609
851
  }
610
852
  const workflowPaths = collectWrittenWorkflowPaths(report);
@@ -612,7 +854,7 @@ async function initGenerator(tree, options, deps = { isWorkingTreeClean: gitIsWo
612
854
  const graphOutputFile = join(tmpdir(), `nx-archweave-init-graph-${Date.now()}.json`);
613
855
  return () => {
614
856
  runPostInitValidation({ root, workflowPaths, graphOutputFile }, createProcessExec());
615
- if (strictFailure !== null) throw strictFailure;
857
+ if (failure !== null) throw failure;
616
858
  };
617
859
  }
618
860
  var generator_default = initGenerator;
@@ -2,9 +2,6 @@ import {
2
2
  runRecordPipeline
3
3
  } from "../_chunks/chunk-URV6FLUH.js";
4
4
  import "../_chunks/chunk-U6LAFHSF.js";
5
- import {
6
- diskRunNx
7
- } from "../_chunks/chunk-GPZEZVPN.js";
8
5
  import {
9
6
  DEFAULT_PLUGIN_SCOPE,
10
7
  PLUGIN_IDS,
@@ -19,8 +16,11 @@ import {
19
16
  verifyViaClaudeCli
20
17
  } from "../_chunks/chunk-AQHV7DJS.js";
21
18
  import "../_chunks/chunk-34V6HAJT.js";
22
- import "../_chunks/chunk-AFAORV5O.js";
23
- import "../_chunks/chunk-FQHFT5IH.js";
19
+ import {
20
+ diskRunNx
21
+ } from "../_chunks/chunk-ILICA6LC.js";
22
+ import "../_chunks/chunk-M7OQWSNF.js";
23
+ import "../_chunks/chunk-5Z7VZPES.js";
24
24
 
25
25
  // ../integrations/dist/config/declare-enabled-integration.js
26
26
  import { existsSync, lstatSync, readFileSync, renameSync, statSync, unlinkSync, writeFileSync } from "node:fs";
@@ -3,8 +3,8 @@ import {
3
3
  } from "../_chunks/chunk-H222FPLK.js";
4
4
  import {
5
5
  runFsdSlice
6
- } from "../_chunks/chunk-KXPL6AJW.js";
7
- import "../_chunks/chunk-B55SAIUS.js";
6
+ } from "../_chunks/chunk-Q7IYHKT3.js";
7
+ import "../_chunks/chunk-WVMTOWLM.js";
8
8
  import "../_chunks/chunk-TXAQ2GJC.js";
9
9
  import "../_chunks/chunk-6ZTIUBB2.js";
10
10
  import "../_chunks/chunk-YNMLB4DL.js";
@@ -12,8 +12,8 @@ import "../_chunks/chunk-JPS6XKYK.js";
12
12
  import {
13
13
  resolveDryRun
14
14
  } from "../_chunks/chunk-TUN34LAQ.js";
15
- import "../_chunks/chunk-AFAORV5O.js";
16
- import "../_chunks/chunk-FQHFT5IH.js";
15
+ import "../_chunks/chunk-M7OQWSNF.js";
16
+ import "../_chunks/chunk-5Z7VZPES.js";
17
17
 
18
18
  // src/generators/page/generator.ts
19
19
  async function pageGenerator(tree, options) {
@@ -3,8 +3,8 @@ import {
3
3
  } from "../_chunks/chunk-H222FPLK.js";
4
4
  import {
5
5
  runFsdSlice
6
- } from "../_chunks/chunk-KXPL6AJW.js";
7
- import "../_chunks/chunk-B55SAIUS.js";
6
+ } from "../_chunks/chunk-Q7IYHKT3.js";
7
+ import "../_chunks/chunk-WVMTOWLM.js";
8
8
  import "../_chunks/chunk-TXAQ2GJC.js";
9
9
  import "../_chunks/chunk-6ZTIUBB2.js";
10
10
  import "../_chunks/chunk-YNMLB4DL.js";
@@ -12,8 +12,8 @@ import "../_chunks/chunk-JPS6XKYK.js";
12
12
  import {
13
13
  resolveDryRun
14
14
  } from "../_chunks/chunk-TUN34LAQ.js";
15
- import "../_chunks/chunk-AFAORV5O.js";
16
- import "../_chunks/chunk-FQHFT5IH.js";
15
+ import "../_chunks/chunk-M7OQWSNF.js";
16
+ import "../_chunks/chunk-5Z7VZPES.js";
17
17
 
18
18
  // src/generators/shared/generator.ts
19
19
  async function sharedGenerator(tree, options) {