@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,23 +1,23 @@
1
+ import { t as habitatConsumerBinding } from "../nx-generators-DQDXOkMX.js";
2
+ import { t as initializeHabitatConsumer } from "../initialization-BWDg3bks.js";
3
+ import { n as initializeHabitatBunRepository, t as assertHabitatBunConsumer } from "../repository-preset-DYxxe7p3.js";
1
4
  import { execSync } from "node:child_process";
2
- import { getPackageManagerCommand, installPackagesTask, runTasksInSerial, } from "@nx/devkit";
3
- import { initializeHabitatConsumer } from "../nx/initialization.js";
4
- import { assertHabitatBunConsumer, initializeHabitatBunRepository, } from "../nx/repository-preset.js";
5
- import { habitatConsumerBinding } from "../nx-generators.js";
5
+ import { getPackageManagerCommand, installPackagesTask, runTasksInSerial } from "@nx/devkit";
6
+ //#region src/generators/init.ts
6
7
  /** Initializes the installed Habitat package inside one Nx consumer. */
7
- export default function initializeHabitat(tree) {
8
- assertHabitatBunConsumer(tree);
9
- const repository = initializeHabitatBunRepository(tree, habitatConsumerBinding, {
10
- packageManager: "bun",
11
- });
12
- const consumer = initializeHabitatConsumer(tree, habitatConsumerBinding);
13
- const activateHusky = () => {
14
- const command = `${getPackageManagerCommand("bun").exec} husky`;
15
- execSync(command, {
16
- cwd: tree.root,
17
- stdio: "inherit",
18
- });
19
- };
20
- if (!repository.packageChanged && !consumer.packageChanged)
21
- return activateHusky;
22
- return runTasksInSerial(() => installPackagesTask(tree, false, "", "bun"), activateHusky);
8
+ function initializeHabitat(tree) {
9
+ assertHabitatBunConsumer(tree);
10
+ const repository = initializeHabitatBunRepository(tree, habitatConsumerBinding, { packageManager: "bun" });
11
+ const consumer = initializeHabitatConsumer(tree, habitatConsumerBinding);
12
+ const activateHusky = () => {
13
+ const command = `${getPackageManagerCommand("bun").exec} husky`;
14
+ execSync(command, {
15
+ cwd: tree.root,
16
+ stdio: "inherit"
17
+ });
18
+ };
19
+ if (!repository.packageChanged && !consumer.packageChanged) return activateHusky;
20
+ return runTasksInSerial(() => installPackagesTask(tree, false, "", "bun"), activateHusky);
23
21
  }
22
+ //#endregion
23
+ export { initializeHabitat as default };
@@ -1,10 +1,11 @@
1
+ import { t as habitatConsumerBinding } from "../nx-generators-DQDXOkMX.js";
2
+ import { n as initializeHabitatBunRepository } from "../repository-preset-DYxxe7p3.js";
1
3
  import { installPackagesTask } from "@nx/devkit";
2
- import { initializeHabitatBunRepository, } from "../nx/repository-preset.js";
3
- import { habitatConsumerBinding } from "../nx-generators.js";
4
+ //#region src/generators/preset.ts
4
5
  /** Creates Habitat's portable Bun/Nx repository spine before Git initialization. */
5
- export default function createHabitatRepository(tree, options) {
6
- const result = initializeHabitatBunRepository(tree, habitatConsumerBinding, options);
7
- if (!result.packageChanged)
8
- return undefined;
9
- return () => installPackagesTask(tree, false, "", "bun");
6
+ function createHabitatRepository(tree, options) {
7
+ if (!initializeHabitatBunRepository(tree, habitatConsumerBinding, options).packageChanged) return void 0;
8
+ return () => installPackagesTask(tree, false, "", "bun");
10
9
  }
10
+ //#endregion
11
+ export { createHabitatRepository as default };
@@ -1,6 +1,9 @@
1
- import { removeHabitatHook } from "../nx/initialization.js";
2
- import { habitatConsumerBinding } from "../nx-generators.js";
1
+ import { t as habitatConsumerBinding } from "../nx-generators-DQDXOkMX.js";
2
+ import { r as removeHabitatHook } from "../initialization-BWDg3bks.js";
3
+ //#region src/generators/remove-hook.ts
3
4
  /** Removes only Habitat's named Codex hook contribution from one Nx consumer. */
4
- export default function removeHook(tree) {
5
- removeHabitatHook(tree, habitatConsumerBinding);
5
+ function removeHook(tree) {
6
+ removeHabitatHook(tree, habitatConsumerBinding);
6
7
  }
8
+ //#endregion
9
+ export { removeHook as default };
@@ -1,164 +1,155 @@
1
- import { fileURLToPath } from "node:url";
2
- import { addProjectConfiguration, generateFiles, getProjects, installPackagesTask, names, OverwriteStrategy, readJson, } from "@nx/devkit";
3
- import { buildPackageJsonPatterns, buildPackageJsonWorkspacesMatcher, } from "nx/src/plugins/package-json";
1
+ import { n as installedSdkVersion, t as cliPackageRoot } from "../product-version-Bqc0L8lq.js";
2
+ import { t as assertHabitatBunConsumer } from "../repository-preset-DYxxe7p3.js";
4
3
  import { Type } from "typebox";
5
4
  import { Validator } from "typebox/schema";
6
- import { assertHabitatBunConsumer } from "../nx/repository-preset.js";
7
- import { installedSdkVersion } from "../product-version.js";
5
+ import { join } from "node:path";
6
+ import { OverwriteStrategy, addProjectConfiguration, generateFiles, getProjects, installPackagesTask, names, readJson } from "@nx/devkit";
7
+ import { buildPackageJsonPatterns, buildPackageJsonWorkspacesMatcher } from "nx/src/plugins/package-json";
8
+ //#region src/generators/service.ts
8
9
  const PACKAGE_NAME_PATTERN = "^(?:@[a-z0-9][a-z0-9._-]*/)?[a-z0-9][a-z0-9._-]*$";
9
10
  const KEBAB_NAME_PATTERN = "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$";
10
11
  const STRICT_IDENTIFIER_PATTERN = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
11
12
  /** Exact non-SDK dependency pins emitted into every constructed service package. */
12
- export const SERVICE_GENERATOR_DEPENDENCY_VERSIONS = {
13
- "@orpc/contract": "2.0.0-beta.23",
14
- "@orpc/server": "2.0.0-beta.23",
15
- typebox: "1.3.8",
13
+ const SERVICE_GENERATOR_DEPENDENCY_VERSIONS = {
14
+ "@orpc/contract": "2.0.0-beta.51",
15
+ "@orpc/server": "2.0.0-beta.51",
16
+ typebox: "1.3.8"
16
17
  };
17
- const RESERVED_IDENTIFIERS = new Set([
18
- "arguments",
19
- "await",
20
- "break",
21
- "case",
22
- "catch",
23
- "class",
24
- "const",
25
- "continue",
26
- "debugger",
27
- "default",
28
- "delete",
29
- "do",
30
- "else",
31
- "enum",
32
- "eval",
33
- "export",
34
- "extends",
35
- "false",
36
- "finally",
37
- "for",
38
- "function",
39
- "if",
40
- "implements",
41
- "import",
42
- "in",
43
- "instanceof",
44
- "interface",
45
- "let",
46
- "new",
47
- "null",
48
- "package",
49
- "private",
50
- "protected",
51
- "public",
52
- "return",
53
- "static",
54
- "super",
55
- "switch",
56
- "this",
57
- "throw",
58
- "true",
59
- "try",
60
- "typeof",
61
- "var",
62
- "void",
63
- "while",
64
- "with",
65
- "yield",
18
+ const RESERVED_IDENTIFIERS = /* @__PURE__ */ new Set([
19
+ "arguments",
20
+ "await",
21
+ "break",
22
+ "case",
23
+ "catch",
24
+ "class",
25
+ "const",
26
+ "continue",
27
+ "debugger",
28
+ "default",
29
+ "delete",
30
+ "do",
31
+ "else",
32
+ "enum",
33
+ "eval",
34
+ "export",
35
+ "extends",
36
+ "false",
37
+ "finally",
38
+ "for",
39
+ "function",
40
+ "if",
41
+ "implements",
42
+ "import",
43
+ "in",
44
+ "instanceof",
45
+ "interface",
46
+ "let",
47
+ "new",
48
+ "null",
49
+ "package",
50
+ "private",
51
+ "protected",
52
+ "public",
53
+ "return",
54
+ "static",
55
+ "super",
56
+ "switch",
57
+ "this",
58
+ "throw",
59
+ "true",
60
+ "try",
61
+ "typeof",
62
+ "var",
63
+ "void",
64
+ "while",
65
+ "with",
66
+ "yield"
67
+ ]);
68
+ const ORPC_IMPLEMENTER_MEMBERS = /* @__PURE__ */ new Set([
69
+ "lazy",
70
+ "middleware",
71
+ "router",
72
+ "use"
73
+ ]);
74
+ const SERVICE_CONTEXT_LANES = /* @__PURE__ */ new Set([
75
+ "config",
76
+ "deps",
77
+ "invocation",
78
+ "provided",
79
+ "scope"
66
80
  ]);
67
- const ORPC_IMPLEMENTER_MEMBERS = new Set(["lazy", "middleware", "router", "use"]);
68
- const SERVICE_CONTEXT_LANES = new Set(["config", "deps", "invocation", "provided", "scope"]);
69
81
  const ServiceGeneratorOptionsSchema = Type.Object({
70
- name: Type.String({ minLength: 1, maxLength: 214, pattern: PACKAGE_NAME_PATTERN }),
71
- directory: Type.String({ minLength: 1 }),
72
- module: Type.String({ pattern: KEBAB_NAME_PATTERN }),
73
- operation: Type.String({ pattern: KEBAB_NAME_PATTERN }),
82
+ name: Type.String({
83
+ minLength: 1,
84
+ maxLength: 214,
85
+ pattern: PACKAGE_NAME_PATTERN
86
+ }),
87
+ directory: Type.String({ minLength: 1 }),
88
+ module: Type.String({ pattern: KEBAB_NAME_PATTERN }),
89
+ operation: Type.String({ pattern: KEBAB_NAME_PATTERN })
74
90
  }, { additionalProperties: false });
75
91
  const optionsValidator = new Validator({}, ServiceGeneratorOptionsSchema);
76
92
  /** Constructs a private service package through Nx and schedules Bun dependency installation. */
77
- export default async function createService(tree, options) {
78
- assertOptions(options);
79
- assertPortableDirectory(options.directory);
80
- assertHabitatBunConsumer(tree);
81
- assertWorkspaceDestination(tree, options.directory);
82
- const moduleNames = names(options.module);
83
- const operationNames = names(options.operation);
84
- assertStrictIdentifier("module", moduleNames.propertyName);
85
- assertStrictIdentifier("operation", operationNames.propertyName);
86
- assertAvailableModuleName(moduleNames.propertyName);
87
- const stagedProjects = getProjects(tree);
88
- if (stagedProjects.has(options.name)) {
89
- throw new Error(`Cannot generate service '${options.name}': an Nx project already uses that name.`);
90
- }
91
- const stagedRootCollision = [...stagedProjects.entries()].find(([, project]) => project.root === options.directory);
92
- if (stagedRootCollision !== undefined) {
93
- throw new Error(`Cannot generate service '${options.name}': destination '${options.directory}' is already owned by staged Nx project '${stagedRootCollision[0]}'.`);
94
- }
95
- if (tree.exists(options.directory) || tree.children(options.directory).length > 0) {
96
- throw new Error(`Cannot generate service '${options.name}': destination '${options.directory}' is occupied.`);
97
- }
98
- const tsconfigBasePath = `${"../".repeat(options.directory.split("/").length)}tsconfig.base.json`;
99
- const templateRoot = fileURLToPath(new URL("../../generators/service/files", import.meta.url));
100
- const dependenciesJson = indentJson({
101
- "@habitat-ai/sdk": installedSdkVersion(),
102
- ...SERVICE_GENERATOR_DEPENDENCY_VERSIONS,
103
- }, 2);
104
- generateFiles(tree, templateRoot, options.directory, {
105
- directory: options.directory,
106
- directoryLiteral: JSON.stringify(options.directory),
107
- dependenciesJson,
108
- moduleFileName: moduleNames.fileName,
109
- moduleName: moduleNames.propertyName,
110
- moduleLocalName: moduleNames.propertyName,
111
- name: options.name,
112
- nameLiteral: JSON.stringify(options.name),
113
- operationFileName: operationNames.fileName,
114
- operationName: operationNames.propertyName,
115
- tsconfigBasePath,
116
- }, { overwriteStrategy: OverwriteStrategy.ThrowIfExisting });
117
- addProjectConfiguration(tree, options.name, {
118
- root: options.directory,
119
- tags: ["type:service", "role:servicepackage"],
120
- targets: {
121
- check: {
122
- executor: "nx:noop",
123
- },
124
- },
125
- });
126
- return () => installPackagesTask(tree, true, "", "bun");
93
+ async function createService(tree, options) {
94
+ assertOptions(options);
95
+ assertPortableDirectory(options.directory);
96
+ assertHabitatBunConsumer(tree);
97
+ assertWorkspaceDestination(tree, options.directory);
98
+ const moduleNames = names(options.module);
99
+ const operationNames = names(options.operation);
100
+ assertStrictIdentifier("module", moduleNames.propertyName);
101
+ assertStrictIdentifier("operation", operationNames.propertyName);
102
+ assertAvailableModuleName(moduleNames.propertyName);
103
+ const stagedProjects = getProjects(tree);
104
+ if (stagedProjects.has(options.name)) throw new Error(`Cannot generate service '${options.name}': an Nx project already uses that name.`);
105
+ const stagedRootCollision = [...stagedProjects.entries()].find(([, project]) => project.root === options.directory);
106
+ if (stagedRootCollision !== void 0) throw new Error(`Cannot generate service '${options.name}': destination '${options.directory}' is already owned by staged Nx project '${stagedRootCollision[0]}'.`);
107
+ if (tree.exists(options.directory) || tree.children(options.directory).length > 0) throw new Error(`Cannot generate service '${options.name}': destination '${options.directory}' is occupied.`);
108
+ const tsconfigBasePath = `${"../".repeat(options.directory.split("/").length)}tsconfig.base.json`;
109
+ const templateRoot = join(cliPackageRoot(), "generators/service/files");
110
+ const dependenciesJson = indentJson({
111
+ "@habitat-ai/sdk": installedSdkVersion(),
112
+ ...SERVICE_GENERATOR_DEPENDENCY_VERSIONS
113
+ }, 2);
114
+ generateFiles(tree, templateRoot, options.directory, {
115
+ directory: options.directory,
116
+ directoryLiteral: JSON.stringify(options.directory),
117
+ dependenciesJson,
118
+ moduleFileName: moduleNames.fileName,
119
+ moduleName: moduleNames.propertyName,
120
+ moduleLocalName: moduleNames.propertyName,
121
+ name: options.name,
122
+ nameLiteral: JSON.stringify(options.name),
123
+ operationFileName: operationNames.fileName,
124
+ operationName: operationNames.propertyName,
125
+ tsconfigBasePath
126
+ }, { overwriteStrategy: OverwriteStrategy.ThrowIfExisting });
127
+ addProjectConfiguration(tree, options.name, {
128
+ root: options.directory,
129
+ tags: ["type:service", "role:servicepackage"],
130
+ targets: { check: { executor: "nx:noop" } }
131
+ });
132
+ return () => installPackagesTask(tree, true, "", "bun");
127
133
  }
128
134
  function assertOptions(options) {
129
- if (!optionsValidator.Check(options)) {
130
- throw new Error("Service generator options require a valid package name, workspace-relative directory, and kebab-case module and operation.");
131
- }
135
+ if (!optionsValidator.Check(options)) throw new Error("Service generator options require a valid package name, workspace-relative directory, and kebab-case module and operation.");
132
136
  }
133
137
  function assertPortableDirectory(directory) {
134
- const segments = directory.split("/");
135
- if (directory.startsWith("/") ||
136
- /^[A-Za-z]:/.test(directory) ||
137
- directory.includes("\\") ||
138
- directory.trim() !== directory ||
139
- segments.some((segment) => segment === "" || segment === "." || segment === "..")) {
140
- throw new Error(`Cannot generate service in '${directory}': directory must be a normalized workspace-relative path without traversal.`);
141
- }
138
+ const segments = directory.split("/");
139
+ if (directory.startsWith("/") || /^[A-Za-z]:/.test(directory) || directory.includes("\\") || directory.trim() !== directory || segments.some((segment) => segment === "" || segment === "." || segment === "..")) throw new Error(`Cannot generate service in '${directory}': directory must be a normalized workspace-relative path without traversal.`);
142
140
  }
143
141
  function assertWorkspaceDestination(tree, directory) {
144
- const patterns = buildPackageJsonPatterns(tree.root, (path) => readJson(tree, path));
145
- const isWorkspacePackage = buildPackageJsonWorkspacesMatcher(patterns);
146
- if (!isWorkspacePackage(`${directory}/package.json`)) {
147
- throw new Error(`Cannot generate service in '${directory}': destination must match a Bun workspace declared in package.json.`);
148
- }
142
+ const patterns = buildPackageJsonPatterns(tree.root, (path) => readJson(tree, path));
143
+ if (!buildPackageJsonWorkspacesMatcher(patterns)(`${directory}/package.json`)) throw new Error(`Cannot generate service in '${directory}': destination must match a Bun workspace declared in package.json.`);
149
144
  }
150
145
  function assertStrictIdentifier(kind, identifier) {
151
- if (!STRICT_IDENTIFIER_PATTERN.test(identifier) ||
152
- RESERVED_IDENTIFIERS.has(identifier) ||
153
- ORPC_IMPLEMENTER_MEMBERS.has(identifier)) {
154
- throw new Error(`Cannot generate service: ${kind} '${identifier}' collides with JavaScript or oRPC implementer syntax.`);
155
- }
146
+ if (!STRICT_IDENTIFIER_PATTERN.test(identifier) || RESERVED_IDENTIFIERS.has(identifier) || ORPC_IMPLEMENTER_MEMBERS.has(identifier)) throw new Error(`Cannot generate service: ${kind} '${identifier}' collides with JavaScript or oRPC implementer syntax.`);
156
147
  }
157
148
  function assertAvailableModuleName(identifier) {
158
- if (SERVICE_CONTEXT_LANES.has(identifier)) {
159
- throw new Error(`Cannot generate service: module '${identifier}' is reserved for the service context.`);
160
- }
149
+ if (SERVICE_CONTEXT_LANES.has(identifier)) throw new Error(`Cannot generate service: module '${identifier}' is reserved for the service context.`);
161
150
  }
162
151
  function indentJson(value, spaces) {
163
- return JSON.stringify(value, null, 2).replaceAll("\n", `\n${" ".repeat(spaces)}`);
152
+ return JSON.stringify(value, null, 2).replaceAll("\n", `\n${" ".repeat(spaces)}`);
164
153
  }
154
+ //#endregion
155
+ export { SERVICE_GENERATOR_DEPENDENCY_VERSIONS, createService as default };