@habitat-ai/cli 0.5.15 → 0.7.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 +100 -4
  2. package/dist/application-Idvdhc9h.js +80 -0
  3. package/dist/application.js +2 -18
  4. package/dist/cli-DxjKzwlV.js +4757 -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-CgdXa2f2.js +16617 -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 +247 -15
  27. package/dist/oclif-DBwcAyVK.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 +5 -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 -596
  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
@@ -1,596 +0,0 @@
1
- import { isDeepStrictEqual } from "node:util";
2
- import { getProjects, readJson, readNxJson, updateNxJson, writeJson, } from "@nx/devkit";
3
- import { Type } from "typebox";
4
- import { Validator } from "typebox/schema";
5
- import { planHabitatNxRegistration } from "./initialization.js";
6
- const PACKAGE_PATH = "package.json";
7
- const HABITAT_PROJECT_PATH = "scripts/habitat/project.json";
8
- const TYPESCRIPT_CONFIG_PATH = "tsconfig.base.json";
9
- const ALTERNATE_PACKAGE_MANAGER_PATHS = [
10
- "package-lock.json",
11
- "npm-shrinkwrap.json",
12
- "pnpm-lock.yaml",
13
- "pnpm-workspace.yaml",
14
- "yarn.lock",
15
- ];
16
- const BUN_VERSION = "1.3.14";
17
- const BIOME_VERSION = "2.5.3";
18
- const ESLINT_VERSION = "10.0.3";
19
- const NX_VERSION = "23.1.1";
20
- const TYPESCRIPT_ESLINT_PARSER_VERSION = "8.66.0";
21
- const RootPackageSchema = Type.Object({
22
- private: Type.Optional(Type.Boolean({ description: "Whether the repository root is excluded from publication." })),
23
- type: Type.Optional(Type.String({ description: "Module system selected by the repository root." })),
24
- packageManager: Type.Optional(Type.String({ description: "Package manager and version selected by the repository root." })),
25
- workspaces: Type.Optional(Type.Array(Type.String(), { description: "Bun workspace roots owned by the repository." })),
26
- scripts: Type.Optional(Type.Record(Type.String(), Type.String(), {
27
- description: "Root command faces delegated to the Nx scheduler.",
28
- })),
29
- devDependencies: Type.Optional(Type.Record(Type.String(), Type.String(), {
30
- description: "Development tools installed at the repository root.",
31
- })),
32
- dependencies: Type.Optional(Type.Record(Type.String(), Type.String(), {
33
- description: "Runtime dependencies installed at the repository root.",
34
- })),
35
- optionalDependencies: Type.Optional(Type.Record(Type.String(), Type.String(), {
36
- description: "Optional dependencies installed at the repository root.",
37
- })),
38
- peerDependencies: Type.Optional(Type.Record(Type.String(), Type.String(), {
39
- description: "Peer dependencies declared by the repository root.",
40
- })),
41
- overrides: Type.Optional(Type.Record(Type.String(), Type.Unknown(), {
42
- description: "Root dependency versions overridden during Bun resolution.",
43
- })),
44
- resolutions: Type.Optional(Type.Record(Type.String(), Type.Unknown(), {
45
- description: "Root dependency versions selected during Bun resolution.",
46
- })),
47
- patchedDependencies: Type.Optional(Type.Record(Type.String(), Type.String(), {
48
- description: "Dependency patches applied by Bun during installation.",
49
- })),
50
- nx: Type.Optional(Type.Object({
51
- includedScripts: Type.Optional(Type.Array(Type.String(), {
52
- description: "Root scripts intentionally projected into the Nx project graph.",
53
- })),
54
- }, { additionalProperties: true, description: "Nx root package projection controls." })),
55
- }, { additionalProperties: true, description: "Bun Nx repository package metadata." });
56
- const TypeScriptConfigSchema = Type.Object({
57
- compilerOptions: Type.Optional(Type.Object({
58
- types: Type.Optional(Type.Array(Type.String(), {
59
- description: "Ambient type packages loaded by the repository compiler.",
60
- })),
61
- }, {
62
- additionalProperties: true,
63
- description: "Compiler foundation and consumer-specific TypeScript options.",
64
- })),
65
- }, { additionalProperties: true });
66
- const HabitatProjectSchema = Type.Object({
67
- name: Type.Literal("habitat", {
68
- description: "Canonical Nx identity for repository-wide Habitat policy tasks.",
69
- }),
70
- root: Type.Literal("scripts/habitat", {
71
- description: "Canonical owner root for repository-wide Habitat policy tasks.",
72
- }),
73
- tags: Type.Tuple([Type.Literal("type:tool"), Type.Literal("role:architecture-policy")], {
74
- description: "Canonical Nx classification for the Habitat policy owner.",
75
- }),
76
- targets: Type.Record(Type.String(), Type.Unknown(), {
77
- description: "Nx tasks owned by the repository-wide Habitat policy project.",
78
- }),
79
- }, { additionalProperties: true });
80
- const packageValidator = new Validator({}, RootPackageSchema);
81
- const habitatProjectValidator = new Validator({}, HabitatProjectSchema);
82
- const typescriptConfigValidator = new Validator({}, TypeScriptConfigSchema);
83
- const standardWorkspaces = [
84
- "apps/*",
85
- "services/*",
86
- "packages/*",
87
- "resources/*",
88
- "plugins/cli/topics/*",
89
- "plugins/web/*",
90
- "plugins/server/api/*",
91
- "plugins/async/workflows/*",
92
- "plugins/async/schedules/*",
93
- ];
94
- const standardScripts = {
95
- build: "nx run-many -t build",
96
- check: "nx run-many -t check",
97
- ci: "nx run-many -t build,check,test",
98
- "ci:affected": "nx affected -t build,check,test",
99
- format: "nx run habitat:format",
100
- lint: "nx run habitat:lint",
101
- test: "nx run-many -t test",
102
- typecheck: "nx run-many -t typecheck",
103
- };
104
- const standardDevDependencies = {
105
- "@biomejs/biome": BIOME_VERSION,
106
- "@nx/eslint": NX_VERSION,
107
- "@nx/eslint-plugin": NX_VERSION,
108
- "@typescript-eslint/parser": TYPESCRIPT_ESLINT_PARSER_VERSION,
109
- "@types/node": "24.13.3",
110
- "bun-types": BUN_VERSION,
111
- eslint: ESLINT_VERSION,
112
- nx: NX_VERSION,
113
- typescript: "5.9.3",
114
- };
115
- const standardNamedInputs = {
116
- default: ["{projectRoot}/**/*", "!{projectRoot}/dist/**", "!{projectRoot}/coverage/**"],
117
- production: [
118
- "default",
119
- "!{projectRoot}/test/**",
120
- "!{projectRoot}/**/*.test.*",
121
- "!{projectRoot}/**/*.spec.*",
122
- ],
123
- bunToolchain: ["{workspaceRoot}/package.json", "{workspaceRoot}/bun.lock"],
124
- typescriptRuntime: ["{workspaceRoot}/tsconfig.base.json", "{workspaceRoot}/bun.lock"],
125
- };
126
- const nativeNxPresetNamedInputs = {
127
- default: ["{projectRoot}/**/*", "sharedGlobals"],
128
- production: ["default"],
129
- };
130
- const nxEslintPlugin = {
131
- plugin: "@nx/eslint/plugin",
132
- options: { targetName: "check:boundaries" },
133
- };
134
- const standardTargetDefaults = {
135
- build: {
136
- cache: true,
137
- dependsOn: ["^build"],
138
- inputs: ["production", "^production", "typescriptRuntime"],
139
- outputs: ["{projectRoot}/dist"],
140
- },
141
- check: {
142
- cache: false,
143
- dependsOn: [
144
- { projects: ["habitat"], target: "lint" },
145
- "check:boundaries",
146
- "typecheck",
147
- "verify",
148
- "check:policy",
149
- "^check",
150
- ],
151
- outputs: [],
152
- },
153
- test: {
154
- cache: true,
155
- dependsOn: ["^build"],
156
- inputs: ["default", "^default", "typescriptRuntime"],
157
- outputs: [],
158
- },
159
- typecheck: {
160
- cache: true,
161
- dependsOn: ["^build"],
162
- inputs: ["default", "^default", "typescriptRuntime"],
163
- outputs: [],
164
- },
165
- verify: {
166
- cache: false,
167
- dependsOn: ["build", "^build"],
168
- outputs: [],
169
- },
170
- };
171
- const bunfig = `env = false
172
-
173
- [install]
174
- linker = "isolated"
175
- # Registry versions remain registry consumers; source relationships opt in with workspace:*.
176
- linkWorkspacePackages = false
177
- `;
178
- const eslintConfig = `import nxPlugin from "@nx/eslint-plugin";
179
- import tsParser from "@typescript-eslint/parser";
180
-
181
- export default [
182
- ...nxPlugin.configs["flat/base"],
183
- {
184
- files: ["**/*.{js,jsx,cjs,mjs,ts,tsx,cts,mts}"],
185
- ignores: [
186
- "**/node_modules/**",
187
- "**/dist/**",
188
- "**/coverage/**",
189
- "**/.nx/**",
190
- "**/.habitat/cache/**",
191
- "**/.tmp/**",
192
- ],
193
- rules: {
194
- "@nx/enforce-module-boundaries": [
195
- "error",
196
- {
197
- allow: [],
198
- depConstraints: [],
199
- enforceBuildableLibDependency: false,
200
- },
201
- ],
202
- },
203
- },
204
- {
205
- files: ["**/*.{ts,tsx,cts,mts}"],
206
- languageOptions: {
207
- parser: tsParser,
208
- parserOptions: {
209
- ecmaFeatures: { jsx: true },
210
- ecmaVersion: "latest",
211
- sourceType: "module",
212
- },
213
- },
214
- },
215
- ];
216
- `;
217
- const standardTypeScriptCompilerOptions = {
218
- target: "ES2022",
219
- module: "ESNext",
220
- moduleResolution: "Bundler",
221
- lib: ["ES2022"],
222
- strict: true,
223
- skipLibCheck: true,
224
- types: ["bun-types", "node"],
225
- };
226
- /**
227
- * Admits package-owned initialization only for the canonical Bun consumer shape.
228
- * The check runs before the generator plans package, Nx, hook, or policy changes.
229
- */
230
- export function assertHabitatBunConsumer(tree) {
231
- assertBunRepositoryArtifacts(tree);
232
- const packageJson = readRootPackage(tree);
233
- const requiredManager = `bun@${BUN_VERSION}`;
234
- if (packageJson.packageManager !== requiredManager) {
235
- throw new Error(`Habitat initialization requires packageManager '${requiredManager}'; received '${packageJson.packageManager}'.`);
236
- }
237
- const nxPackageManager = requireNxJson(tree).cli?.packageManager;
238
- if (nxPackageManager !== undefined && nxPackageManager !== "bun") {
239
- throw new Error(`Habitat initialization requires Nx package manager 'bun'; received '${nxPackageManager}'.`);
240
- }
241
- }
242
- const biomeConfig = jsonDocument({
243
- $schema: `https://biomejs.dev/schemas/${BIOME_VERSION}/schema.json`,
244
- vcs: {
245
- enabled: true,
246
- clientKind: "git",
247
- useIgnoreFile: true,
248
- },
249
- files: {
250
- ignoreUnknown: true,
251
- includes: [
252
- "**",
253
- "!**/node_modules/**",
254
- "!**/dist/**",
255
- "!**/coverage/**",
256
- "!**/.venv/**",
257
- "!.nx/**",
258
- "!.habitat/cache/**",
259
- "!**/.tmp/**",
260
- ],
261
- },
262
- formatter: {
263
- enabled: true,
264
- useEditorconfig: true,
265
- formatWithErrors: false,
266
- indentStyle: "space",
267
- indentWidth: 2,
268
- lineWidth: 100,
269
- lineEnding: "lf",
270
- },
271
- linter: {
272
- enabled: true,
273
- rules: {
274
- preset: "none",
275
- correctness: {
276
- noConstAssign: "error",
277
- noSelfAssign: "error",
278
- noUnreachable: "error",
279
- noUnreachableSuper: "error",
280
- noUnsafeFinally: "error",
281
- noUnsafeOptionalChaining: "error",
282
- useIsNan: "error",
283
- useValidTypeof: "error",
284
- },
285
- suspicious: {
286
- noDebugger: "error",
287
- noDuplicateCase: "error",
288
- noDuplicateClassMembers: "error",
289
- noDuplicateJsxProps: "error",
290
- noDuplicateObjectKeys: "error",
291
- noDuplicateParameters: "error",
292
- noFallthroughSwitchClause: "error",
293
- noGlobalIsFinite: "error",
294
- noGlobalIsNan: "error",
295
- noSparseArray: "error",
296
- noWith: "error",
297
- useGetterReturn: "error",
298
- },
299
- },
300
- },
301
- javascript: {
302
- formatter: {
303
- quoteStyle: "double",
304
- semicolons: "always",
305
- trailingCommas: "es5",
306
- },
307
- },
308
- assist: {
309
- enabled: true,
310
- actions: {
311
- source: {
312
- organizeImports: "on",
313
- },
314
- },
315
- },
316
- });
317
- const habitatProjectDocument = {
318
- $schema: "../../node_modules/nx/schemas/project-schema.json",
319
- name: "habitat",
320
- root: "scripts/habitat",
321
- tags: ["type:tool", "role:architecture-policy"],
322
- targets: {
323
- lint: {
324
- executor: "nx:run-commands",
325
- cache: true,
326
- inputs: [
327
- "{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}",
328
- "{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}",
329
- "{workspaceRoot}/.editorconfig",
330
- "{workspaceRoot}/.gitignore",
331
- "{workspaceRoot}/biome.json",
332
- "bunToolchain",
333
- ],
334
- outputs: [],
335
- options: {
336
- command: "biome lint --diagnostic-level=error .",
337
- },
338
- },
339
- format: {
340
- executor: "nx:run-commands",
341
- cache: false,
342
- options: {
343
- command: "biome format --write .",
344
- },
345
- },
346
- check: {
347
- executor: "nx:noop",
348
- cache: false,
349
- outputs: [],
350
- },
351
- },
352
- };
353
- const habitatProject = jsonDocument(habitatProjectDocument);
354
- /**
355
- * Converges one repository on Habitat's portable Bun/Nx configuration.
356
- *
357
- * Product inventory, policy selections, documentation routers, aliases, release
358
- * policy, and hosted CI remain consumer-owned and are never generated here.
359
- */
360
- export function initializeHabitatBunRepository(tree, binding, options) {
361
- assertBunManager(options.packageManager);
362
- assertBunRepositoryArtifacts(tree);
363
- const packageJson = readRootPackage(tree);
364
- assertBunPackage(packageJson);
365
- assertCanonicalTextFoundation(tree);
366
- assertHabitatProjectAuthority(tree);
367
- const typescriptConfig = readTypeScriptConfig(tree);
368
- const nxJson = requireNxJson(tree);
369
- const nxRegistration = planHabitatNxRegistration(nxJson, binding);
370
- const nextPackage = planRootPackage(packageJson);
371
- const nextNx = planNxJson(nxRegistration.value);
372
- const nextTypeScriptConfig = planTypeScriptConfig(typescriptConfig);
373
- const files = plannedTextFiles(tree);
374
- if (!isDeepStrictEqual(packageJson, nextPackage))
375
- writeJson(tree, PACKAGE_PATH, nextPackage);
376
- if (!isDeepStrictEqual(nxJson, nextNx))
377
- updateNxJson(tree, nextNx);
378
- if (!isDeepStrictEqual(typescriptConfig, nextTypeScriptConfig)) {
379
- writeJson(tree, TYPESCRIPT_CONFIG_PATH, nextTypeScriptConfig);
380
- }
381
- for (const file of files)
382
- tree.write(file.path, file.contents);
383
- return { packageChanged: !isDeepStrictEqual(packageJson, nextPackage) };
384
- }
385
- function readRootPackage(tree) {
386
- if (!tree.exists(PACKAGE_PATH)) {
387
- throw new Error("Habitat repository generation requires package.json.");
388
- }
389
- const input = readJson(tree, PACKAGE_PATH);
390
- if (!packageValidator.Check(input)) {
391
- throw new Error("package.json is not a supported Bun Nx repository document.");
392
- }
393
- return input;
394
- }
395
- function requireNxJson(tree) {
396
- const nxJson = readNxJson(tree);
397
- if (nxJson === null) {
398
- throw new Error("Habitat repository generation requires nx.json.");
399
- }
400
- return nxJson;
401
- }
402
- function readTypeScriptConfig(tree) {
403
- if (!tree.exists(TYPESCRIPT_CONFIG_PATH) || isEmptyTextFile(tree, TYPESCRIPT_CONFIG_PATH)) {
404
- return undefined;
405
- }
406
- const input = readJson(tree, TYPESCRIPT_CONFIG_PATH);
407
- if (!typescriptConfigValidator.Check(input)) {
408
- throw new Error(`${TYPESCRIPT_CONFIG_PATH} is not a supported TypeScript configuration.`);
409
- }
410
- return input;
411
- }
412
- function assertBunManager(packageManager) {
413
- if (packageManager !== "bun") {
414
- throw new Error(`Habitat repository preset requires Bun; received '${packageManager}'.`);
415
- }
416
- }
417
- function assertBunRepositoryArtifacts(tree) {
418
- const alternate = ALTERNATE_PACKAGE_MANAGER_PATHS.find((path) => tree.exists(path));
419
- if (alternate !== undefined) {
420
- throw new Error(`Habitat repository preset refuses alternate package-manager artifact '${alternate}'.`);
421
- }
422
- }
423
- function assertCanonicalTextFoundation(tree) {
424
- for (const [path, canonical] of [
425
- ["biome.json", biomeConfig],
426
- ["bunfig.toml", bunfig],
427
- ]) {
428
- if (!tree.exists(path) || isEmptyTextFile(tree, path))
429
- continue;
430
- if (tree.read(path, "utf8") !== canonical) {
431
- throw new Error(`Habitat repository preset found incompatible foundation file '${path}'.`);
432
- }
433
- }
434
- }
435
- function assertBunPackage(packageJson) {
436
- const requiredManager = `bun@${BUN_VERSION}`;
437
- if (packageJson.packageManager !== undefined && packageJson.packageManager !== requiredManager) {
438
- throw new Error(`Habitat repository preset requires packageManager '${requiredManager}'; received '${packageJson.packageManager}'.`);
439
- }
440
- if (packageJson.private === false) {
441
- throw new Error("Habitat repository preset requires a private workspace root.");
442
- }
443
- if (packageJson.type !== undefined && packageJson.type !== "module") {
444
- throw new Error("Habitat repository preset requires an ESM workspace root.");
445
- }
446
- const conflictingScript = packageJson.nx?.includedScripts?.find((script) => Object.hasOwn(standardScripts, script));
447
- if (conflictingScript !== undefined) {
448
- throw new Error(`Habitat repository preset requires nx.includedScripts to exclude scheduler script '${conflictingScript}'.`);
449
- }
450
- for (const [name, command] of Object.entries(standardScripts)) {
451
- const existing = packageJson.scripts?.[name];
452
- if (existing !== undefined && existing !== command) {
453
- throw new Error(`Habitat repository preset found incompatible root scheduler script '${name}'.`);
454
- }
455
- }
456
- for (const [name, version] of Object.entries(standardDevDependencies)) {
457
- for (const bucket of ["dependencies", "optionalDependencies", "peerDependencies"]) {
458
- if (packageJson[bucket]?.[name] !== undefined) {
459
- throw new Error(`Habitat repository preset requires tool dependency '${name}' in devDependencies.`);
460
- }
461
- }
462
- const existing = packageJson.devDependencies?.[name];
463
- if (existing !== undefined && existing !== version) {
464
- throw new Error(`Habitat repository preset found incompatible tool dependency '${name}@${existing}'.`);
465
- }
466
- for (const control of ["overrides", "resolutions"]) {
467
- const selected = packageJson[control]?.[name];
468
- if (selected !== undefined && selected !== version) {
469
- throw new Error(`Habitat repository preset found incompatible ${control} selection for tool '${name}'.`);
470
- }
471
- }
472
- const patched = Object.keys(packageJson.patchedDependencies ?? {}).find((specifier) => specifier === name || specifier.startsWith(`${name}@`));
473
- if (patched !== undefined) {
474
- throw new Error(`Habitat repository preset refuses patched foundation tool '${patched}'.`);
475
- }
476
- }
477
- }
478
- function assertHabitatProjectAuthority(tree) {
479
- const emptyHabitatProject = isEmptyTextFile(tree, HABITAT_PROJECT_PATH);
480
- const projects = getProjects(emptyHabitatProject ? withoutHabitatProject(tree) : tree);
481
- const project = projects.get("habitat");
482
- if (project !== undefined && project.root !== "scripts/habitat") {
483
- throw new Error(`Habitat repository preset found project 'habitat' at incompatible root '${project.root}'.`);
484
- }
485
- const conflictingRootOwner = [...projects.entries()].find(([name, configuration]) => name !== "habitat" && configuration.root === "scripts/habitat");
486
- if (conflictingRootOwner !== undefined) {
487
- throw new Error(`Habitat repository preset found root 'scripts/habitat' owned by incompatible project '${conflictingRootOwner[0]}'.`);
488
- }
489
- if (!tree.exists(HABITAT_PROJECT_PATH) || emptyHabitatProject)
490
- return;
491
- const input = readJson(tree, HABITAT_PROJECT_PATH);
492
- if (!habitatProjectValidator.Check(input)) {
493
- throw new Error(`${HABITAT_PROJECT_PATH} is not a compatible Habitat policy project.`);
494
- }
495
- if (Object.hasOwn(input, "projectType")) {
496
- throw new Error(`${HABITAT_PROJECT_PATH} must not declare projectType.`);
497
- }
498
- for (const target of ["check", "format", "lint"]) {
499
- if (!isDeepStrictEqual(input.targets[target], habitatProjectDocument.targets[target])) {
500
- throw new Error(`${HABITAT_PROJECT_PATH} has incompatible Habitat target '${target}'.`);
501
- }
502
- }
503
- }
504
- function planRootPackage(packageJson) {
505
- return {
506
- ...packageJson,
507
- private: true,
508
- type: "module",
509
- packageManager: packageJson.packageManager ?? `bun@${BUN_VERSION}`,
510
- workspaces: [...new Set([...standardWorkspaces, ...(packageJson.workspaces ?? [])])],
511
- scripts: { ...standardScripts, ...packageJson.scripts },
512
- nx: { ...packageJson.nx, includedScripts: [...(packageJson.nx?.includedScripts ?? [])] },
513
- devDependencies: { ...packageJson.devDependencies, ...standardDevDependencies },
514
- };
515
- }
516
- function planNxJson(nxJson) {
517
- assertReservedNxValues("named input", nxJson.namedInputs, standardNamedInputs, nativeNxPresetNamedInputs);
518
- assertReservedNxValues("target default", nxJson.targetDefaults, standardTargetDefaults);
519
- const plugins = planNxEslintRegistration(nxJson.plugins);
520
- return {
521
- ...nxJson,
522
- plugins,
523
- namedInputs: { ...nxJson.namedInputs, ...standardNamedInputs },
524
- targetDefaults: { ...nxJson.targetDefaults, ...standardTargetDefaults },
525
- };
526
- }
527
- function planNxEslintRegistration(plugins) {
528
- const existing = plugins ?? [];
529
- const matches = existing.filter((plugin) => (typeof plugin === "string" ? plugin : plugin.plugin) === nxEslintPlugin.plugin);
530
- if (matches.length > 1) {
531
- throw new Error("nx.json contains multiple Nx ESLint plugin registrations.");
532
- }
533
- const match = matches[0];
534
- if (match !== undefined && !isDeepStrictEqual(match, nxEslintPlugin)) {
535
- throw new Error("nx.json contains an incompatible Nx ESLint plugin registration.");
536
- }
537
- return match === undefined ? [...existing, nxEslintPlugin] : [...existing];
538
- }
539
- function assertReservedNxValues(kind, existing, canonical, admittedPredecessors = {}) {
540
- for (const [name, value] of Object.entries(canonical)) {
541
- const current = existing?.[name];
542
- const predecessor = admittedPredecessors[name];
543
- if (current !== undefined &&
544
- !isDeepStrictEqual(current, value) &&
545
- !isDeepStrictEqual(current, predecessor)) {
546
- throw new Error(`Habitat repository preset found incompatible Nx ${kind} '${name}'.`);
547
- }
548
- }
549
- }
550
- function planTypeScriptConfig(config) {
551
- const existing = (config?.compilerOptions ?? {});
552
- for (const [name, value] of Object.entries(standardTypeScriptCompilerOptions)) {
553
- if (name === "types")
554
- continue;
555
- const current = existing[name];
556
- if (current !== undefined && !isDeepStrictEqual(current, value)) {
557
- throw new Error(`Habitat repository preset found incompatible TypeScript compiler option '${name}'.`);
558
- }
559
- }
560
- return {
561
- ...config,
562
- compilerOptions: {
563
- ...standardTypeScriptCompilerOptions,
564
- ...existing,
565
- types: [...new Set([...standardTypeScriptCompilerOptions.types, ...(existing.types ?? [])])],
566
- },
567
- };
568
- }
569
- function plannedTextFiles(tree) {
570
- return [
571
- { path: "biome.json", contents: biomeConfig },
572
- { path: "bunfig.toml", contents: bunfig },
573
- { path: "eslint.config.mjs", contents: eslintConfig },
574
- { path: HABITAT_PROJECT_PATH, contents: habitatProject },
575
- ].filter((file) => !tree.exists(file.path) || isEmptyTextFile(tree, file.path));
576
- }
577
- function isEmptyTextFile(tree, path) {
578
- return tree.exists(path) && tree.read(path, "utf8")?.trim().length === 0;
579
- }
580
- function withoutHabitatProject(tree) {
581
- return new Proxy(tree, {
582
- get(target, property, receiver) {
583
- if (property === "listChanges") {
584
- return () => [
585
- ...target.listChanges().filter((change) => change.path !== HABITAT_PROJECT_PATH),
586
- { path: HABITAT_PROJECT_PATH, type: "DELETE", content: null },
587
- ];
588
- }
589
- const value = Reflect.get(target, property, receiver);
590
- return typeof value === "function" ? value.bind(target) : value;
591
- },
592
- });
593
- }
594
- function jsonDocument(value) {
595
- return `${JSON.stringify(value, null, 2)}\n`;
596
- }
@@ -1,42 +0,0 @@
1
- /** Exact app-owned identities projected by the public Habitat Nx generators. */
2
- export declare const habitatConsumerBinding: {
3
- readonly defaultCheckScript: "nx run-many -t check";
4
- readonly gitHook: {
5
- readonly path: ".husky/pre-push";
6
- readonly contents: "# Nested Git work must discover its own repository.\nunset $(git rev-parse --local-env-vars)\nbun run check\n";
7
- };
8
- readonly gritPackage: "@getgrit/cli";
9
- readonly husky: {
10
- readonly package: "husky";
11
- readonly version: "9.1.7";
12
- readonly prepare: "husky";
13
- readonly predecessorPrepareScripts: readonly ["./scripts/dev/install-repository-hooks.sh", "git config core.hooksPath scripts/githooks"];
14
- };
15
- readonly nxPlugin: "@habitat-ai/cli/nx-plugin";
16
- readonly predecessorNxPlugins: readonly [{
17
- readonly plugin: "@habitat/cli/nx-plugin";
18
- readonly options: {
19
- readonly checkTargetName: "check:policy";
20
- };
21
- }];
22
- readonly hook: {
23
- readonly _habitat: {
24
- readonly identity: "@habitat-ai/cli:agent-stop";
25
- readonly revision: 1;
26
- };
27
- readonly hooks: [{
28
- readonly type: "command";
29
- readonly command: "bash -lc 'repo=\"${CODEX_WORKSPACE_ROOT:-${CLAUDE_PROJECT_DIR:-}}\"; if [ -n \"$repo\" ]; then repo=\"$(git -C \"$repo\" rev-parse --show-toplevel 2>/dev/null)\"; else repo=\"$(git rev-parse --show-toplevel 2>/dev/null)\"; fi && cd \"$repo\" 2>/dev/null || { printf \"%s\\n\" \"Habitat agent-stop hook must run inside the repository worktree.\" >&2; exit 2; }; bunx --bun --no-install --package @habitat-ai/cli habitat hook agent-stop'";
30
- readonly timeout: 120;
31
- readonly statusMessage: "Checking Habitat structure laws";
32
- }];
33
- };
34
- readonly predecessorHooks: readonly [{
35
- readonly hooks: [{
36
- readonly type: "command";
37
- readonly command: "bash -lc 'repo=\"${CODEX_WORKSPACE_ROOT:-${CLAUDE_PROJECT_DIR:-}}\"; if [ -n \"$repo\" ]; then repo=\"$(git -C \"$repo\" rev-parse --show-toplevel 2>/dev/null)\"; else repo=\"$(git rev-parse --show-toplevel 2>/dev/null)\"; fi && cd \"$repo\" 2>/dev/null || { printf \"%s\\n\" \"Habitat agent-stop hook must run inside the repository worktree.\" >&2; exit 2; }; bun habitat hook agent-stop'";
38
- readonly timeout: 120;
39
- readonly statusMessage: "Checking Habitat structure laws";
40
- }];
41
- }];
42
- };
@@ -1,2 +0,0 @@
1
- /** Returns the exact SDK version paired with the installed Habitat CLI. */
2
- export declare function installedSdkVersion(): string;
@@ -1,15 +0,0 @@
1
- import { readFileSync } from "node:fs";
2
- import { fileURLToPath } from "node:url";
3
- const EXACT_SEMVER_PATTERN = /^(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
4
- const cliPackageJsonPath = fileURLToPath(new URL("../package.json", import.meta.url));
5
- /** Returns the exact SDK version paired with the installed Habitat CLI. */
6
- export function installedSdkVersion() {
7
- const manifest = JSON.parse(readFileSync(cliPackageJsonPath, "utf8"));
8
- const version = manifest.dependencies?.["@habitat-ai/sdk"];
9
- if (typeof version !== "string" ||
10
- !EXACT_SEMVER_PATTERN.test(version) ||
11
- version !== manifest.version) {
12
- throw new Error("Installed @habitat-ai/cli and @habitat-ai/sdk must use one identical exact semantic version.");
13
- }
14
- return version;
15
- }