@habitat-ai/cli 0.5.14 → 0.6.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 (65) hide show
  1. package/README.md +62 -4
  2. package/dist/application-gZ8XAszE.js +80 -0
  3. package/dist/application.js +2 -18
  4. package/dist/cli-hhbbymEz.js +4738 -0
  5. package/dist/cli.js +2 -0
  6. package/dist/command-DkmTpQvc.js +74 -0
  7. package/dist/command.d.ts +36 -35
  8. package/dist/command.js +2 -45
  9. package/dist/generators/cli-command.js +263 -0
  10. package/dist/generators/cli-extension.js +192 -0
  11. package/dist/generators/init.js +20 -20
  12. package/dist/generators/preset.js +8 -7
  13. package/dist/generators/remove-hook.js +7 -4
  14. package/dist/generators/service.js +130 -139
  15. package/dist/habitat.app-Cl-58zQB.js +16615 -0
  16. package/dist/habitat.app.js +2 -0
  17. package/dist/host-BcptPYDL.js +293 -0
  18. package/dist/host.d.ts +57 -0
  19. package/dist/host.js +3 -0
  20. package/dist/index.js +8 -5
  21. package/dist/initialization-BWDg3bks.js +249 -0
  22. package/dist/migrations/0-5-7-repository-foundation.js +42 -38
  23. package/dist/nx-generators-DQDXOkMX.js +44 -0
  24. package/dist/nx-generators.js +2 -51
  25. package/dist/nx-plugin.d.ts +4 -1
  26. package/dist/nx-plugin.js +241 -15
  27. package/dist/oclif-CJS8CHjO.js +11 -0
  28. package/dist/oclif.js +3 -0
  29. package/dist/product-version-Bqc0L8lq.js +18 -0
  30. package/dist/publish-generator-tree-CgFdcykY.js +14 -0
  31. package/dist/repository-preset-DYxxe7p3.js +543 -0
  32. package/dist/verified-writes-Cne-zTxS.js +60 -0
  33. package/generators/cli-command/schema.json +20 -0
  34. package/generators/cli-extension/schema.json +20 -0
  35. package/generators/service/files/AGENTS.md.template +2 -2
  36. package/generators/service/files/habitat.toml.template +1 -1
  37. package/generators.json +10 -0
  38. package/oclif.manifest.json +1094 -27
  39. package/package.json +72 -8
  40. package/dist/application.d.ts +0 -14
  41. package/dist/commands/check.d.ts +0 -15
  42. package/dist/commands/check.js +0 -32
  43. package/dist/commands/hook.d.ts +0 -12
  44. package/dist/commands/hook.js +0 -25
  45. package/dist/commands/resolve.d.ts +0 -9
  46. package/dist/commands/resolve.js +0 -15
  47. package/dist/generators/init.d.ts +0 -3
  48. package/dist/generators/preset.d.ts +0 -4
  49. package/dist/generators/remove-hook.d.ts +0 -3
  50. package/dist/generators/service.d.ts +0 -16
  51. package/dist/index.d.ts +0 -1
  52. package/dist/lib/binding.d.ts +0 -10
  53. package/dist/lib/binding.js +0 -16
  54. package/dist/lib/output.d.ts +0 -9
  55. package/dist/lib/output.js +0 -22
  56. package/dist/migrations/0-5-7-repository-foundation.d.ts +0 -3
  57. package/dist/nx/initialization.d.ts +0 -62
  58. package/dist/nx/initialization.js +0 -265
  59. package/dist/nx/projection.d.ts +0 -29
  60. package/dist/nx/projection.js +0 -308
  61. package/dist/nx/repository-preset.d.ts +0 -22
  62. package/dist/nx/repository-preset.js +0 -595
  63. package/dist/nx-generators.d.ts +0 -42
  64. package/dist/product-version.d.ts +0 -2
  65. package/dist/product-version.js +0 -15
@@ -0,0 +1,543 @@
1
+ import { n as planHabitatNxRegistration } from "./initialization-BWDg3bks.js";
2
+ import { Type } from "typebox";
3
+ import { Validator } from "typebox/schema";
4
+ import { getProjects, readJson, readNxJson, updateNxJson, writeJson } from "@nx/devkit";
5
+ import { isDeepStrictEqual } from "node:util";
6
+ //#region src/nx/repository-preset.ts
7
+ const PACKAGE_PATH = "package.json";
8
+ const HABITAT_PROJECT_PATH = "scripts/habitat/project.json";
9
+ const TYPESCRIPT_CONFIG_PATH = "tsconfig.base.json";
10
+ const ALTERNATE_PACKAGE_MANAGER_PATHS = [
11
+ "package-lock.json",
12
+ "npm-shrinkwrap.json",
13
+ "pnpm-lock.yaml",
14
+ "pnpm-workspace.yaml",
15
+ "yarn.lock"
16
+ ];
17
+ const BUN_VERSION = "1.3.14";
18
+ const BIOME_VERSION = "2.5.3";
19
+ const ESLINT_VERSION = "10.0.3";
20
+ const NX_VERSION = "23.1.1";
21
+ const TYPESCRIPT_ESLINT_PARSER_VERSION = "8.66.0";
22
+ const RootPackageSchema = Type.Object({
23
+ private: Type.Optional(Type.Boolean({ description: "Whether the repository root is excluded from publication." })),
24
+ type: Type.Optional(Type.String({ description: "Module system selected by the repository root." })),
25
+ packageManager: Type.Optional(Type.String({ description: "Package manager and version selected by the repository root." })),
26
+ workspaces: Type.Optional(Type.Array(Type.String(), { description: "Bun workspace roots owned by the repository." })),
27
+ scripts: Type.Optional(Type.Record(Type.String(), Type.String(), { description: "Root command faces delegated to the Nx scheduler." })),
28
+ devDependencies: Type.Optional(Type.Record(Type.String(), Type.String(), { description: "Development tools installed at the repository root." })),
29
+ dependencies: Type.Optional(Type.Record(Type.String(), Type.String(), { description: "Runtime dependencies installed at the repository root." })),
30
+ optionalDependencies: Type.Optional(Type.Record(Type.String(), Type.String(), { description: "Optional dependencies installed at the repository root." })),
31
+ peerDependencies: Type.Optional(Type.Record(Type.String(), Type.String(), { description: "Peer dependencies declared by the repository root." })),
32
+ overrides: Type.Optional(Type.Record(Type.String(), Type.Unknown(), { description: "Root dependency versions overridden during Bun resolution." })),
33
+ resolutions: Type.Optional(Type.Record(Type.String(), Type.Unknown(), { description: "Root dependency versions selected during Bun resolution." })),
34
+ patchedDependencies: Type.Optional(Type.Record(Type.String(), Type.String(), { description: "Dependency patches applied by Bun during installation." })),
35
+ nx: Type.Optional(Type.Object({ includedScripts: Type.Optional(Type.Array(Type.String(), { description: "Root scripts intentionally projected into the Nx project graph." })) }, {
36
+ additionalProperties: true,
37
+ description: "Nx root package projection controls."
38
+ }))
39
+ }, {
40
+ additionalProperties: true,
41
+ description: "Bun Nx repository package metadata."
42
+ });
43
+ const TypeScriptConfigSchema = Type.Object({ compilerOptions: Type.Optional(Type.Object({ types: Type.Optional(Type.Array(Type.String(), { description: "Ambient type packages loaded by the repository compiler." })) }, {
44
+ additionalProperties: true,
45
+ description: "Compiler foundation and consumer-specific TypeScript options."
46
+ })) }, { additionalProperties: true });
47
+ const HabitatProjectSchema = Type.Object({
48
+ name: Type.Literal("habitat", { description: "Canonical Nx identity for repository-wide Habitat policy tasks." }),
49
+ root: Type.Literal("scripts/habitat", { description: "Canonical owner root for repository-wide Habitat policy tasks." }),
50
+ tags: Type.Tuple([Type.Literal("type:tool"), Type.Literal("role:architecture-policy")], { description: "Canonical Nx classification for the Habitat policy owner." }),
51
+ targets: Type.Record(Type.String(), Type.Unknown(), { description: "Nx tasks owned by the repository-wide Habitat policy project." })
52
+ }, { additionalProperties: true });
53
+ const packageValidator = new Validator({}, RootPackageSchema);
54
+ const habitatProjectValidator = new Validator({}, HabitatProjectSchema);
55
+ const typescriptConfigValidator = new Validator({}, TypeScriptConfigSchema);
56
+ const standardWorkspaces = [
57
+ "apps/*",
58
+ "services/*",
59
+ "packages/*",
60
+ "resources/*",
61
+ "plugins/cli/topics/*",
62
+ "plugins/web/*",
63
+ "plugins/server/api/*",
64
+ "plugins/async/workflows/*",
65
+ "plugins/async/schedules/*"
66
+ ];
67
+ const standardScripts = {
68
+ build: "nx run-many -t build",
69
+ check: "nx run-many -t check",
70
+ ci: "nx run-many -t build,check,test",
71
+ "ci:affected": "nx affected -t build,check,test",
72
+ format: "nx run habitat:format",
73
+ lint: "nx run habitat:lint",
74
+ test: "nx run-many -t test",
75
+ typecheck: "nx run-many -t typecheck"
76
+ };
77
+ const standardDevDependencies = {
78
+ "@biomejs/biome": BIOME_VERSION,
79
+ "@nx/eslint": NX_VERSION,
80
+ "@nx/eslint-plugin": NX_VERSION,
81
+ "@typescript-eslint/parser": TYPESCRIPT_ESLINT_PARSER_VERSION,
82
+ "@types/node": "24.13.3",
83
+ "bun-types": BUN_VERSION,
84
+ eslint: ESLINT_VERSION,
85
+ nx: NX_VERSION,
86
+ typescript: "5.9.3"
87
+ };
88
+ const standardNamedInputs = {
89
+ default: [
90
+ "{projectRoot}/**/*",
91
+ "!{projectRoot}/dist/**",
92
+ "!{projectRoot}/coverage/**"
93
+ ],
94
+ production: [
95
+ "default",
96
+ "!{projectRoot}/test/**",
97
+ "!{projectRoot}/**/*.test.*",
98
+ "!{projectRoot}/**/*.spec.*"
99
+ ],
100
+ bunToolchain: [
101
+ "{workspaceRoot}/package.json",
102
+ "{workspaceRoot}/bun.lock",
103
+ "{workspaceRoot}/bunfig.toml"
104
+ ],
105
+ typescriptRuntime: ["bunToolchain", "{workspaceRoot}/tsconfig.base.json"]
106
+ };
107
+ const nativeNxPresetNamedInputs = {
108
+ default: ["{projectRoot}/**/*", "sharedGlobals"],
109
+ production: ["default"]
110
+ };
111
+ const nxEslintPlugin = {
112
+ plugin: "@nx/eslint/plugin",
113
+ options: { targetName: "check:boundaries" }
114
+ };
115
+ const standardTargetDefaults = {
116
+ build: {
117
+ cache: true,
118
+ dependsOn: ["^build"],
119
+ inputs: [
120
+ "production",
121
+ "^production",
122
+ "typescriptRuntime"
123
+ ],
124
+ outputs: ["{projectRoot}/dist"]
125
+ },
126
+ check: {
127
+ cache: false,
128
+ dependsOn: [
129
+ {
130
+ projects: ["habitat"],
131
+ target: "lint"
132
+ },
133
+ "check:boundaries",
134
+ "typecheck",
135
+ "verify",
136
+ "check:policy",
137
+ "^check"
138
+ ],
139
+ outputs: []
140
+ },
141
+ test: {
142
+ cache: true,
143
+ dependsOn: ["^build"],
144
+ inputs: [
145
+ "default",
146
+ "^default",
147
+ "typescriptRuntime"
148
+ ],
149
+ outputs: []
150
+ },
151
+ typecheck: {
152
+ cache: true,
153
+ dependsOn: ["^build"],
154
+ inputs: [
155
+ "default",
156
+ "^default",
157
+ "typescriptRuntime"
158
+ ],
159
+ outputs: []
160
+ },
161
+ verify: {
162
+ cache: false,
163
+ dependsOn: ["build", "^build"],
164
+ outputs: []
165
+ }
166
+ };
167
+ const bunfig = `env = false
168
+
169
+ [install]
170
+ linker = "isolated"
171
+ # Registry versions remain registry consumers; source relationships opt in with workspace:*.
172
+ linkWorkspacePackages = false
173
+ `;
174
+ const eslintConfig = `import nxPlugin from "@nx/eslint-plugin";
175
+ import tsParser from "@typescript-eslint/parser";
176
+
177
+ export default [
178
+ ...nxPlugin.configs["flat/base"],
179
+ {
180
+ files: ["**/*.{js,jsx,cjs,mjs,ts,tsx,cts,mts}"],
181
+ ignores: [
182
+ "**/node_modules/**",
183
+ "**/dist/**",
184
+ "**/coverage/**",
185
+ "**/.nx/**",
186
+ "**/.habitat/cache/**",
187
+ "**/.tmp/**",
188
+ ],
189
+ rules: {
190
+ "@nx/enforce-module-boundaries": [
191
+ "error",
192
+ {
193
+ allow: [],
194
+ depConstraints: [],
195
+ enforceBuildableLibDependency: false,
196
+ },
197
+ ],
198
+ },
199
+ },
200
+ {
201
+ files: ["**/*.{ts,tsx,cts,mts}"],
202
+ languageOptions: {
203
+ parser: tsParser,
204
+ parserOptions: {
205
+ ecmaFeatures: { jsx: true },
206
+ ecmaVersion: "latest",
207
+ sourceType: "module",
208
+ },
209
+ },
210
+ },
211
+ ];
212
+ `;
213
+ const standardTypeScriptCompilerOptions = {
214
+ target: "ES2022",
215
+ module: "ESNext",
216
+ moduleResolution: "Bundler",
217
+ lib: ["ES2022"],
218
+ strict: true,
219
+ skipLibCheck: true,
220
+ types: ["bun-types", "node"]
221
+ };
222
+ /**
223
+ * Admits package-owned initialization only for the canonical Bun consumer shape.
224
+ * The check runs before the generator plans package, Nx, hook, or policy changes.
225
+ */
226
+ function assertHabitatBunConsumer(tree) {
227
+ assertBunRepositoryArtifacts(tree);
228
+ const packageJson = readRootPackage(tree);
229
+ const requiredManager = `bun@${BUN_VERSION}`;
230
+ if (packageJson.packageManager !== requiredManager) throw new Error(`Habitat initialization requires packageManager '${requiredManager}'; received '${packageJson.packageManager}'.`);
231
+ const nxPackageManager = requireNxJson(tree).cli?.packageManager;
232
+ if (nxPackageManager !== void 0 && nxPackageManager !== "bun") throw new Error(`Habitat initialization requires Nx package manager 'bun'; received '${nxPackageManager}'.`);
233
+ }
234
+ const biomeConfig = jsonDocument({
235
+ $schema: `https://biomejs.dev/schemas/${BIOME_VERSION}/schema.json`,
236
+ vcs: {
237
+ enabled: true,
238
+ clientKind: "git",
239
+ useIgnoreFile: true
240
+ },
241
+ files: {
242
+ ignoreUnknown: true,
243
+ includes: [
244
+ "**",
245
+ "!**/node_modules/**",
246
+ "!**/dist/**",
247
+ "!**/coverage/**",
248
+ "!**/.venv/**",
249
+ "!.nx/**",
250
+ "!.habitat/cache/**",
251
+ "!**/.tmp/**"
252
+ ]
253
+ },
254
+ formatter: {
255
+ enabled: true,
256
+ useEditorconfig: true,
257
+ formatWithErrors: false,
258
+ indentStyle: "space",
259
+ indentWidth: 2,
260
+ lineWidth: 100,
261
+ lineEnding: "lf"
262
+ },
263
+ linter: {
264
+ enabled: true,
265
+ rules: {
266
+ preset: "none",
267
+ correctness: {
268
+ noConstAssign: "error",
269
+ noSelfAssign: "error",
270
+ noUnreachable: "error",
271
+ noUnreachableSuper: "error",
272
+ noUnsafeFinally: "error",
273
+ noUnsafeOptionalChaining: "error",
274
+ useIsNan: "error",
275
+ useValidTypeof: "error"
276
+ },
277
+ suspicious: {
278
+ noDebugger: "error",
279
+ noDuplicateCase: "error",
280
+ noDuplicateClassMembers: "error",
281
+ noDuplicateJsxProps: "error",
282
+ noDuplicateObjectKeys: "error",
283
+ noDuplicateParameters: "error",
284
+ noFallthroughSwitchClause: "error",
285
+ noGlobalIsFinite: "error",
286
+ noGlobalIsNan: "error",
287
+ noSparseArray: "error",
288
+ noWith: "error",
289
+ useGetterReturn: "error"
290
+ }
291
+ }
292
+ },
293
+ javascript: { formatter: {
294
+ quoteStyle: "double",
295
+ semicolons: "always",
296
+ trailingCommas: "es5"
297
+ } },
298
+ assist: {
299
+ enabled: true,
300
+ actions: { source: { organizeImports: "on" } }
301
+ }
302
+ });
303
+ const habitatProjectDocument = {
304
+ $schema: "../../node_modules/nx/schemas/project-schema.json",
305
+ name: "habitat",
306
+ root: "scripts/habitat",
307
+ tags: ["type:tool", "role:architecture-policy"],
308
+ targets: {
309
+ lint: {
310
+ executor: "nx:run-commands",
311
+ cache: true,
312
+ inputs: [
313
+ "{workspaceRoot}/**/*.{js,mjs,jsx,cjs,ts,mts,cts,tsx,json,jsonld,webapp,webmanifest,jsonc,code-snippets,code-workspace,sublime-build,sublime-commands,sublime-completions,sublime-keymap,sublime-macro,sublime-menu,sublime-mousemap,sublime-project,sublime-settings,sublime-theme,sublime-workspace,sublime_metrics,sublime_session,css,graphqls,graphql,gql,html,svg,astro,vue,svelte,grit}",
314
+ "{workspaceRoot}/**/{.all-contributorsrc,.arcconfig,.auto-changelog,.bowerrc,.c8rc,.htmlhintrc,.imgbotconfig,.jslintrc,.nycrc,.tern-config,.tern-project,.vuerc,.watchmanconfig,.ember-cli,.jscsrc,.jshintrc,.babelrc,.hintrc,.swcrc,mcmod.info}",
315
+ "{workspaceRoot}/.editorconfig",
316
+ "{workspaceRoot}/.gitignore",
317
+ "{workspaceRoot}/biome.json",
318
+ "bunToolchain"
319
+ ],
320
+ outputs: [],
321
+ options: { command: "biome lint --diagnostic-level=error ." }
322
+ },
323
+ format: {
324
+ executor: "nx:run-commands",
325
+ cache: false,
326
+ options: { command: "biome format --write ." }
327
+ },
328
+ check: {
329
+ executor: "nx:noop",
330
+ cache: false,
331
+ outputs: []
332
+ }
333
+ }
334
+ };
335
+ const habitatProject = jsonDocument(habitatProjectDocument);
336
+ /**
337
+ * Converges one repository on Habitat's portable Bun/Nx configuration.
338
+ *
339
+ * Product inventory, policy selections, documentation routers, aliases, release
340
+ * policy, and hosted CI remain consumer-owned and are never generated here.
341
+ */
342
+ function initializeHabitatBunRepository(tree, binding, options) {
343
+ assertBunManager(options.packageManager);
344
+ assertBunRepositoryArtifacts(tree);
345
+ const packageJson = readRootPackage(tree);
346
+ assertBunPackage(packageJson);
347
+ assertCanonicalTextFoundation(tree);
348
+ assertHabitatProjectAuthority(tree);
349
+ const typescriptConfig = readTypeScriptConfig(tree);
350
+ const nxJson = requireNxJson(tree);
351
+ const nxRegistration = planHabitatNxRegistration(nxJson, binding);
352
+ const nextPackage = planRootPackage(packageJson);
353
+ const nextNx = planNxJson(nxRegistration.value);
354
+ const nextTypeScriptConfig = planTypeScriptConfig(typescriptConfig);
355
+ const files = plannedTextFiles(tree);
356
+ if (!isDeepStrictEqual(packageJson, nextPackage)) writeJson(tree, PACKAGE_PATH, nextPackage);
357
+ if (!isDeepStrictEqual(nxJson, nextNx)) updateNxJson(tree, nextNx);
358
+ if (!isDeepStrictEqual(typescriptConfig, nextTypeScriptConfig)) writeJson(tree, TYPESCRIPT_CONFIG_PATH, nextTypeScriptConfig);
359
+ for (const file of files) tree.write(file.path, file.contents);
360
+ return { packageChanged: !isDeepStrictEqual(packageJson, nextPackage) };
361
+ }
362
+ function readRootPackage(tree) {
363
+ if (!tree.exists(PACKAGE_PATH)) throw new Error("Habitat repository generation requires package.json.");
364
+ const input = readJson(tree, PACKAGE_PATH);
365
+ if (!packageValidator.Check(input)) throw new Error("package.json is not a supported Bun Nx repository document.");
366
+ return input;
367
+ }
368
+ function requireNxJson(tree) {
369
+ const nxJson = readNxJson(tree);
370
+ if (nxJson === null) throw new Error("Habitat repository generation requires nx.json.");
371
+ return nxJson;
372
+ }
373
+ function readTypeScriptConfig(tree) {
374
+ if (!tree.exists(TYPESCRIPT_CONFIG_PATH) || isEmptyTextFile(tree, TYPESCRIPT_CONFIG_PATH)) return;
375
+ const input = readJson(tree, TYPESCRIPT_CONFIG_PATH);
376
+ if (!typescriptConfigValidator.Check(input)) throw new Error(`${TYPESCRIPT_CONFIG_PATH} is not a supported TypeScript configuration.`);
377
+ return input;
378
+ }
379
+ function assertBunManager(packageManager) {
380
+ if (packageManager !== "bun") throw new Error(`Habitat repository preset requires Bun; received '${packageManager}'.`);
381
+ }
382
+ function assertBunRepositoryArtifacts(tree) {
383
+ const alternate = ALTERNATE_PACKAGE_MANAGER_PATHS.find((path) => tree.exists(path));
384
+ if (alternate !== void 0) throw new Error(`Habitat repository preset refuses alternate package-manager artifact '${alternate}'.`);
385
+ }
386
+ function assertCanonicalTextFoundation(tree) {
387
+ for (const [path, canonical] of [["biome.json", biomeConfig], ["bunfig.toml", bunfig]]) {
388
+ if (!tree.exists(path) || isEmptyTextFile(tree, path)) continue;
389
+ if (tree.read(path, "utf8") !== canonical) throw new Error(`Habitat repository preset found incompatible foundation file '${path}'.`);
390
+ }
391
+ }
392
+ function assertBunPackage(packageJson) {
393
+ const requiredManager = `bun@${BUN_VERSION}`;
394
+ if (packageJson.packageManager !== void 0 && packageJson.packageManager !== requiredManager) throw new Error(`Habitat repository preset requires packageManager '${requiredManager}'; received '${packageJson.packageManager}'.`);
395
+ if (packageJson.private === false) throw new Error("Habitat repository preset requires a private workspace root.");
396
+ if (packageJson.type !== void 0 && packageJson.type !== "module") throw new Error("Habitat repository preset requires an ESM workspace root.");
397
+ const conflictingScript = packageJson.nx?.includedScripts?.find((script) => Object.hasOwn(standardScripts, script));
398
+ if (conflictingScript !== void 0) throw new Error(`Habitat repository preset requires nx.includedScripts to exclude scheduler script '${conflictingScript}'.`);
399
+ for (const [name, command] of Object.entries(standardScripts)) {
400
+ const existing = packageJson.scripts?.[name];
401
+ if (existing !== void 0 && existing !== command) throw new Error(`Habitat repository preset found incompatible root scheduler script '${name}'.`);
402
+ }
403
+ for (const [name, version] of Object.entries(standardDevDependencies)) {
404
+ for (const bucket of [
405
+ "dependencies",
406
+ "optionalDependencies",
407
+ "peerDependencies"
408
+ ]) if (packageJson[bucket]?.[name] !== void 0) throw new Error(`Habitat repository preset requires tool dependency '${name}' in devDependencies.`);
409
+ const existing = packageJson.devDependencies?.[name];
410
+ if (existing !== void 0 && existing !== version) throw new Error(`Habitat repository preset found incompatible tool dependency '${name}@${existing}'.`);
411
+ for (const control of ["overrides", "resolutions"]) {
412
+ const selected = packageJson[control]?.[name];
413
+ if (selected !== void 0 && selected !== version) throw new Error(`Habitat repository preset found incompatible ${control} selection for tool '${name}'.`);
414
+ }
415
+ const patched = Object.keys(packageJson.patchedDependencies ?? {}).find((specifier) => specifier === name || specifier.startsWith(`${name}@`));
416
+ if (patched !== void 0) throw new Error(`Habitat repository preset refuses patched foundation tool '${patched}'.`);
417
+ }
418
+ }
419
+ function assertHabitatProjectAuthority(tree) {
420
+ const emptyHabitatProject = isEmptyTextFile(tree, HABITAT_PROJECT_PATH);
421
+ const projects = getProjects(emptyHabitatProject ? withoutHabitatProject(tree) : tree);
422
+ const project = projects.get("habitat");
423
+ if (project !== void 0 && project.root !== "scripts/habitat") throw new Error(`Habitat repository preset found project 'habitat' at incompatible root '${project.root}'.`);
424
+ const conflictingRootOwner = [...projects.entries()].find(([name, configuration]) => name !== "habitat" && configuration.root === "scripts/habitat");
425
+ if (conflictingRootOwner !== void 0) throw new Error(`Habitat repository preset found root 'scripts/habitat' owned by incompatible project '${conflictingRootOwner[0]}'.`);
426
+ if (!tree.exists(HABITAT_PROJECT_PATH) || emptyHabitatProject) return;
427
+ const input = readJson(tree, HABITAT_PROJECT_PATH);
428
+ if (!habitatProjectValidator.Check(input)) throw new Error(`${HABITAT_PROJECT_PATH} is not a compatible Habitat policy project.`);
429
+ if (Object.hasOwn(input, "projectType")) throw new Error(`${HABITAT_PROJECT_PATH} must not declare projectType.`);
430
+ for (const target of [
431
+ "check",
432
+ "format",
433
+ "lint"
434
+ ]) if (!isDeepStrictEqual(input.targets[target], habitatProjectDocument.targets[target])) throw new Error(`${HABITAT_PROJECT_PATH} has incompatible Habitat target '${target}'.`);
435
+ }
436
+ function planRootPackage(packageJson) {
437
+ return {
438
+ ...packageJson,
439
+ private: true,
440
+ type: "module",
441
+ packageManager: packageJson.packageManager ?? `bun@${BUN_VERSION}`,
442
+ workspaces: [.../* @__PURE__ */ new Set([...standardWorkspaces, ...packageJson.workspaces ?? []])],
443
+ scripts: {
444
+ ...standardScripts,
445
+ ...packageJson.scripts
446
+ },
447
+ nx: {
448
+ ...packageJson.nx,
449
+ includedScripts: [...packageJson.nx?.includedScripts ?? []]
450
+ },
451
+ devDependencies: {
452
+ ...packageJson.devDependencies,
453
+ ...standardDevDependencies
454
+ }
455
+ };
456
+ }
457
+ function planNxJson(nxJson) {
458
+ assertReservedNxValues("named input", nxJson.namedInputs, standardNamedInputs, nativeNxPresetNamedInputs);
459
+ assertReservedNxValues("target default", nxJson.targetDefaults, standardTargetDefaults);
460
+ const plugins = planNxEslintRegistration(nxJson.plugins);
461
+ return {
462
+ ...nxJson,
463
+ plugins,
464
+ namedInputs: {
465
+ ...nxJson.namedInputs,
466
+ ...standardNamedInputs
467
+ },
468
+ targetDefaults: {
469
+ ...nxJson.targetDefaults,
470
+ ...standardTargetDefaults
471
+ }
472
+ };
473
+ }
474
+ function planNxEslintRegistration(plugins) {
475
+ const existing = plugins ?? [];
476
+ const matches = existing.filter((plugin) => (typeof plugin === "string" ? plugin : plugin.plugin) === nxEslintPlugin.plugin);
477
+ if (matches.length > 1) throw new Error("nx.json contains multiple Nx ESLint plugin registrations.");
478
+ const match = matches[0];
479
+ if (match !== void 0 && !isDeepStrictEqual(match, nxEslintPlugin)) throw new Error("nx.json contains an incompatible Nx ESLint plugin registration.");
480
+ return match === void 0 ? [...existing, nxEslintPlugin] : [...existing];
481
+ }
482
+ function assertReservedNxValues(kind, existing, canonical, admittedPredecessors = {}) {
483
+ for (const [name, value] of Object.entries(canonical)) {
484
+ const current = existing?.[name];
485
+ const predecessor = admittedPredecessors[name];
486
+ if (current !== void 0 && !isDeepStrictEqual(current, value) && !isDeepStrictEqual(current, predecessor)) throw new Error(`Habitat repository preset found incompatible Nx ${kind} '${name}'.`);
487
+ }
488
+ }
489
+ function planTypeScriptConfig(config) {
490
+ const existing = config?.compilerOptions ?? {};
491
+ for (const [name, value] of Object.entries(standardTypeScriptCompilerOptions)) {
492
+ if (name === "types") continue;
493
+ const current = existing[name];
494
+ if (current !== void 0 && !isDeepStrictEqual(current, value)) throw new Error(`Habitat repository preset found incompatible TypeScript compiler option '${name}'.`);
495
+ }
496
+ return {
497
+ ...config,
498
+ compilerOptions: {
499
+ ...standardTypeScriptCompilerOptions,
500
+ ...existing,
501
+ types: [.../* @__PURE__ */ new Set([...standardTypeScriptCompilerOptions.types, ...existing.types ?? []])]
502
+ }
503
+ };
504
+ }
505
+ function plannedTextFiles(tree) {
506
+ return [
507
+ {
508
+ path: "biome.json",
509
+ contents: biomeConfig
510
+ },
511
+ {
512
+ path: "bunfig.toml",
513
+ contents: bunfig
514
+ },
515
+ {
516
+ path: "eslint.config.mjs",
517
+ contents: eslintConfig
518
+ },
519
+ {
520
+ path: HABITAT_PROJECT_PATH,
521
+ contents: habitatProject
522
+ }
523
+ ].filter((file) => !tree.exists(file.path) || isEmptyTextFile(tree, file.path));
524
+ }
525
+ function isEmptyTextFile(tree, path) {
526
+ return tree.exists(path) && tree.read(path, "utf8")?.trim().length === 0;
527
+ }
528
+ function withoutHabitatProject(tree) {
529
+ return new Proxy(tree, { get(target, property, receiver) {
530
+ if (property === "listChanges") return () => [...target.listChanges().filter((change) => change.path !== HABITAT_PROJECT_PATH), {
531
+ path: HABITAT_PROJECT_PATH,
532
+ type: "DELETE",
533
+ content: null
534
+ }];
535
+ const value = Reflect.get(target, property, receiver);
536
+ return typeof value === "function" ? value.bind(target) : value;
537
+ } });
538
+ }
539
+ function jsonDocument(value) {
540
+ return `${JSON.stringify(value, null, 2)}\n`;
541
+ }
542
+ //#endregion
543
+ export { initializeHabitatBunRepository as n, assertHabitatBunConsumer as t };
@@ -0,0 +1,60 @@
1
+ import { join } from "node:path";
2
+ import { lstatSync } from "node:fs";
3
+ //#region src/generators/verified-writes.ts
4
+ /** Validate the whole plan before staging; native Nx alone publishes the supplied Tree. */
5
+ function stageVerifiedWrites(tree, destination, writes) {
6
+ assertRelativePath(destination.root, true);
7
+ const plan = writes.map((write) => {
8
+ assertRelativePath(write.path, false);
9
+ return {
10
+ path: destination.root ? `${destination.root}/${write.path}` : write.path,
11
+ contents: Buffer.from(write.contents),
12
+ before: write.before === void 0 ? void 0 : Buffer.from(write.before)
13
+ };
14
+ }).sort((left, right) => left.path < right.path ? -1 : left.path > right.path ? 1 : 0);
15
+ const paths = /* @__PURE__ */ new Set();
16
+ for (const write of plan) {
17
+ const key = write.path.toLowerCase();
18
+ if (paths.has(key)) throw new Error(`Duplicate qualified output path: ${write.path}`);
19
+ paths.add(key);
20
+ }
21
+ for (const write of plan) {
22
+ const segments = write.path.split("/");
23
+ for (let depth = 1; depth < segments.length; depth++) {
24
+ const ancestor = segments.slice(0, depth).join("/");
25
+ if (paths.has(ancestor.toLowerCase())) throw new Error(`Qualified output is also a parent path: ${ancestor}`);
26
+ }
27
+ assertExistingPaths(tree, write.path);
28
+ }
29
+ const changes = [];
30
+ for (const write of plan) {
31
+ const current = tree.read(write.path);
32
+ if (current?.equals(write.contents)) continue;
33
+ if (write.before === void 0 ? current !== null : !current?.equals(write.before)) throw new Error(`Qualified output has divergent bytes: ${write.path}`);
34
+ changes.push(write);
35
+ }
36
+ for (const write of changes) tree.write(write.path, write.contents);
37
+ return {
38
+ status: changes.length === 0 ? "converged" : "staged",
39
+ paths: plan.map((write) => write.path)
40
+ };
41
+ }
42
+ function assertRelativePath(path, allowRoot) {
43
+ if (allowRoot && path === "") return;
44
+ const segments = path.split("/");
45
+ if (path.includes("\\") || path.includes(":") || /[\u0000-\u001f<>"|?*]/.test(path) || segments.some((segment) => segment === "" || segment === "." || segment === ".." || /[. ]$/.test(segment) || /^(?:con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\.|$)/i.test(segment))) throw new Error(`Qualified output requires a portable relative path: ${path}`);
46
+ }
47
+ function assertExistingPaths(tree, path) {
48
+ const segments = path.split("/");
49
+ for (let depth = 1; depth <= segments.length; depth++) {
50
+ const current = segments.slice(0, depth).join("/");
51
+ const isOutput = depth === segments.length;
52
+ const disk = lstatSync(join(tree.root, current), { throwIfNoEntry: false });
53
+ if (disk?.isSymbolicLink() || disk !== void 0 && (isOutput ? !disk.isFile() : !disk.isDirectory()) || (isOutput ? tree.exists(current) && !tree.isFile(current) : tree.isFile(current))) throw new Error(`Qualified output has an unsafe existing path: ${current}`);
54
+ const parent = segments.slice(0, depth - 1).join("/");
55
+ const segment = segments[depth - 1];
56
+ if (tree.children(parent).some((child) => child !== segment && child.toLowerCase() === segment.toLowerCase())) throw new Error(`Qualified output has an ambiguous path spelling: ${current}`);
57
+ }
58
+ }
59
+ //#endregion
60
+ export { stageVerifiedWrites as t };
@@ -0,0 +1,20 @@
1
+ {
2
+ "$schema": "https://json-schema.org/schema",
3
+ "title": "Create an official Habitat CLI command",
4
+ "description": "Updates an existing Habitat topic with explicit command membership and statically readable SDK command IDs. Unresolved authoring forms are left untouched, not executed.",
5
+ "type": "object",
6
+ "properties": {
7
+ "topic": {
8
+ "type": "string",
9
+ "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$",
10
+ "description": "Existing Habitat topic name."
11
+ },
12
+ "name": {
13
+ "type": "string",
14
+ "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$",
15
+ "description": "New command name."
16
+ }
17
+ },
18
+ "required": ["topic", "name"],
19
+ "additionalProperties": false
20
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "$schema": "https://json-schema.org/schema",
3
+ "title": "Create a native Oclif extension",
4
+ "type": "object",
5
+ "properties": {
6
+ "id": {
7
+ "type": "string",
8
+ "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$",
9
+ "maxLength": 196,
10
+ "description": "Extension identifier, used in habitat-extension-<id> and <id>:hello."
11
+ },
12
+ "destination": {
13
+ "type": "string",
14
+ "minLength": 1,
15
+ "description": "Explicit portable destination relative to the supplied tree root."
16
+ }
17
+ },
18
+ "required": ["id", "destination"],
19
+ "additionalProperties": false
20
+ }
@@ -23,8 +23,8 @@
23
23
  than claiming runtime erasure.
24
24
  - Module and service routers only compose already-authored operations.
25
25
  - The initial operation uses an inline native `.handler(...)`. When authored operations genuinely
26
- require Effect, install the official `.effect(...)` extension once in `src/service/impl.ts` and
27
- author their generators directly in the operation routers.
26
+ require Effect, import `@habitat-ai/sdk/plugins/server/effect` once in `src/service/impl.ts` and
27
+ author their `.effect(...)` generators directly in the operation routers.
28
28
 
29
29
  ## Validation
30
30
 
@@ -2,7 +2,7 @@ schemaVersion = 1
2
2
  id = <%- nameLiteral %>
3
3
  ownerProject = <%- nameLiteral %>
4
4
  blueprint = "service"
5
- blueprintVersion = 2
5
+ blueprintVersion = 3
6
6
 
7
7
  [roots]
8
8
  project = <%- directoryLiteral %>
package/generators.json CHANGED
@@ -20,6 +20,16 @@
20
20
  "factory": "./dist/generators/service.js",
21
21
  "schema": "./generators/service/schema.json",
22
22
  "description": "Construct one closed Habitat service package."
23
+ },
24
+ "cli-command": {
25
+ "factory": "./dist/generators/cli-command.js",
26
+ "schema": "./generators/cli-command/schema.json",
27
+ "description": "Add one native Habitat command to an existing Habitat topic."
28
+ },
29
+ "cli-extension": {
30
+ "factory": "./dist/generators/cli-extension.js",
31
+ "schema": "./generators/cli-extension/schema.json",
32
+ "description": "Author one standalone native Oclif extension at an explicit destination."
23
33
  }
24
34
  }
25
35
  }