@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.
- package/README.md +62 -4
- package/dist/application-gZ8XAszE.js +80 -0
- package/dist/application.js +2 -18
- package/dist/cli-hhbbymEz.js +4738 -0
- package/dist/cli.js +2 -0
- package/dist/command-DkmTpQvc.js +74 -0
- package/dist/command.d.ts +36 -35
- package/dist/command.js +2 -45
- package/dist/generators/cli-command.js +263 -0
- package/dist/generators/cli-extension.js +192 -0
- package/dist/generators/init.js +20 -20
- package/dist/generators/preset.js +8 -7
- package/dist/generators/remove-hook.js +7 -4
- package/dist/generators/service.js +130 -139
- package/dist/habitat.app-Cl-58zQB.js +16615 -0
- package/dist/habitat.app.js +2 -0
- package/dist/host-BcptPYDL.js +293 -0
- package/dist/host.d.ts +57 -0
- package/dist/host.js +3 -0
- package/dist/index.js +8 -5
- package/dist/initialization-BWDg3bks.js +249 -0
- package/dist/migrations/0-5-7-repository-foundation.js +42 -38
- package/dist/nx-generators-DQDXOkMX.js +44 -0
- package/dist/nx-generators.js +2 -51
- package/dist/nx-plugin.d.ts +4 -1
- package/dist/nx-plugin.js +241 -15
- package/dist/oclif-CJS8CHjO.js +11 -0
- package/dist/oclif.js +3 -0
- package/dist/product-version-Bqc0L8lq.js +18 -0
- package/dist/publish-generator-tree-CgFdcykY.js +14 -0
- package/dist/repository-preset-DYxxe7p3.js +543 -0
- package/dist/verified-writes-Cne-zTxS.js +60 -0
- package/generators/cli-command/schema.json +20 -0
- package/generators/cli-extension/schema.json +20 -0
- package/generators/service/files/AGENTS.md.template +2 -2
- package/generators/service/files/habitat.toml.template +1 -1
- package/generators.json +10 -0
- package/oclif.manifest.json +1094 -27
- package/package.json +72 -8
- package/dist/application.d.ts +0 -14
- package/dist/commands/check.d.ts +0 -15
- package/dist/commands/check.js +0 -32
- package/dist/commands/hook.d.ts +0 -12
- package/dist/commands/hook.js +0 -25
- package/dist/commands/resolve.d.ts +0 -9
- package/dist/commands/resolve.js +0 -15
- package/dist/generators/init.d.ts +0 -3
- package/dist/generators/preset.d.ts +0 -4
- package/dist/generators/remove-hook.d.ts +0 -3
- package/dist/generators/service.d.ts +0 -16
- package/dist/index.d.ts +0 -1
- package/dist/lib/binding.d.ts +0 -10
- package/dist/lib/binding.js +0 -16
- package/dist/lib/output.d.ts +0 -9
- package/dist/lib/output.js +0 -22
- package/dist/migrations/0-5-7-repository-foundation.d.ts +0 -3
- package/dist/nx/initialization.d.ts +0 -62
- package/dist/nx/initialization.js +0 -265
- package/dist/nx/projection.d.ts +0 -29
- package/dist/nx/projection.js +0 -308
- package/dist/nx/repository-preset.d.ts +0 -22
- package/dist/nx/repository-preset.js +0 -595
- package/dist/nx-generators.d.ts +0 -42
- package/dist/product-version.d.ts +0 -2
- package/dist/product-version.js +0 -15
package/dist/generators/init.js
CHANGED
|
@@ -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
|
|
3
|
-
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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 {
|
|
2
|
-
import {
|
|
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
|
-
|
|
5
|
-
|
|
5
|
+
function removeHook(tree) {
|
|
6
|
+
removeHabitatHook(tree, habitatConsumerBinding);
|
|
6
7
|
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { removeHook as default };
|
|
@@ -1,164 +1,155 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
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 {
|
|
7
|
-
import {
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
const SERVICE_GENERATOR_DEPENDENCY_VERSIONS = {
|
|
14
|
+
"@orpc/contract": "2.0.0-beta.32",
|
|
15
|
+
"@orpc/server": "2.0.0-beta.32",
|
|
16
|
+
typebox: "1.3.8"
|
|
16
17
|
};
|
|
17
|
-
const RESERVED_IDENTIFIERS = new Set([
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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
|
-
|
|
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
|
-
|
|
135
|
-
|
|
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
|
-
|
|
145
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 };
|