@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
|
@@ -1,49 +1,53 @@
|
|
|
1
|
+
import { t as habitatConsumerBinding } from "../nx-generators-DQDXOkMX.js";
|
|
2
|
+
import { n as initializeHabitatBunRepository } from "../repository-preset-DYxxe7p3.js";
|
|
3
|
+
import { installPackagesTask, readJson, writeJson } from "@nx/devkit";
|
|
1
4
|
import { isDeepStrictEqual } from "node:util";
|
|
2
|
-
|
|
3
|
-
import { initializeHabitatBunRepository } from "../nx/repository-preset.js";
|
|
4
|
-
import { habitatConsumerBinding } from "../nx-generators.js";
|
|
5
|
+
//#region src/migrations/0-5-7-repository-foundation.ts
|
|
5
6
|
const PREVIOUS_CHECK_TARGET = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
7
|
+
cache: false,
|
|
8
|
+
dependsOn: [
|
|
9
|
+
{
|
|
10
|
+
projects: ["habitat"],
|
|
11
|
+
target: "lint"
|
|
12
|
+
},
|
|
13
|
+
"typecheck",
|
|
14
|
+
"verify",
|
|
15
|
+
"check:policy",
|
|
16
|
+
"^check"
|
|
17
|
+
],
|
|
18
|
+
outputs: []
|
|
15
19
|
};
|
|
16
20
|
const FIRST_PRESET_NX_VERSION = "23.1.0";
|
|
17
21
|
const CURRENT_NX_VERSION = "23.1.1";
|
|
18
22
|
function normalizeFirstPresetNxVersions(tree) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
const packageJson = readJson(tree, "package.json");
|
|
24
|
+
const previousNx = packageJson.devDependencies?.nx === FIRST_PRESET_NX_VERSION;
|
|
25
|
+
const previousWorkspace = packageJson.devDependencies?.["@nx/workspace"] === FIRST_PRESET_NX_VERSION;
|
|
26
|
+
if (!previousNx && !previousWorkspace) return;
|
|
27
|
+
const devDependencies = { ...packageJson.devDependencies };
|
|
28
|
+
if (previousNx) devDependencies.nx = CURRENT_NX_VERSION;
|
|
29
|
+
if (previousWorkspace) devDependencies["@nx/workspace"] = CURRENT_NX_VERSION;
|
|
30
|
+
writeJson(tree, "package.json", {
|
|
31
|
+
...packageJson,
|
|
32
|
+
devDependencies
|
|
33
|
+
});
|
|
30
34
|
}
|
|
31
35
|
function removePreviousCheckTarget(tree) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
const nxJson = readJson(tree, "nx.json");
|
|
37
|
+
if (!isDeepStrictEqual(nxJson.targetDefaults?.check, PREVIOUS_CHECK_TARGET)) return;
|
|
38
|
+
const targetDefaults = { ...nxJson.targetDefaults };
|
|
39
|
+
delete targetDefaults.check;
|
|
40
|
+
writeJson(tree, "nx.json", {
|
|
41
|
+
...nxJson,
|
|
42
|
+
targetDefaults
|
|
43
|
+
});
|
|
38
44
|
}
|
|
39
45
|
/** Advances an existing Bun/Nx consumer through Habitat's canonical preset. */
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
});
|
|
46
|
-
if (!result.packageChanged)
|
|
47
|
-
return undefined;
|
|
48
|
-
return () => installPackagesTask(tree, false, "", "bun");
|
|
46
|
+
function migrateRepositoryFoundation(tree) {
|
|
47
|
+
normalizeFirstPresetNxVersions(tree);
|
|
48
|
+
removePreviousCheckTarget(tree);
|
|
49
|
+
if (!initializeHabitatBunRepository(tree, habitatConsumerBinding, { packageManager: "bun" }).packageChanged) return void 0;
|
|
50
|
+
return () => installPackagesTask(tree, false, "", "bun");
|
|
49
51
|
}
|
|
52
|
+
//#endregion
|
|
53
|
+
export { migrateRepositoryFoundation as default };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
//#region src/nx-generators.ts
|
|
2
|
+
/** Exact app-owned identities projected by the public Habitat Nx generators. */
|
|
3
|
+
const habitatConsumerBinding = {
|
|
4
|
+
defaultCheckScript: "nx run-many -t check",
|
|
5
|
+
gitHook: {
|
|
6
|
+
path: ".husky/pre-push",
|
|
7
|
+
contents: `# Nested Git work must discover its own repository.
|
|
8
|
+
unset $(git rev-parse --local-env-vars)
|
|
9
|
+
bun run check
|
|
10
|
+
`
|
|
11
|
+
},
|
|
12
|
+
gritPackage: "@getgrit/cli",
|
|
13
|
+
husky: {
|
|
14
|
+
package: "husky",
|
|
15
|
+
version: "9.1.7",
|
|
16
|
+
prepare: "husky",
|
|
17
|
+
predecessorPrepareScripts: ["./scripts/dev/install-repository-hooks.sh", "git config core.hooksPath scripts/githooks"]
|
|
18
|
+
},
|
|
19
|
+
nxPlugin: "@habitat-ai/cli/nx-plugin",
|
|
20
|
+
predecessorNxPlugins: [{
|
|
21
|
+
plugin: "@habitat/cli/nx-plugin",
|
|
22
|
+
options: { checkTargetName: "check:policy" }
|
|
23
|
+
}],
|
|
24
|
+
hook: {
|
|
25
|
+
_habitat: {
|
|
26
|
+
identity: "@habitat-ai/cli:agent-stop",
|
|
27
|
+
revision: 1
|
|
28
|
+
},
|
|
29
|
+
hooks: [{
|
|
30
|
+
type: "command",
|
|
31
|
+
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'",
|
|
32
|
+
timeout: 120,
|
|
33
|
+
statusMessage: "Checking Habitat structure laws"
|
|
34
|
+
}]
|
|
35
|
+
},
|
|
36
|
+
predecessorHooks: [{ hooks: [{
|
|
37
|
+
type: "command",
|
|
38
|
+
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'",
|
|
39
|
+
timeout: 120,
|
|
40
|
+
statusMessage: "Checking Habitat structure laws"
|
|
41
|
+
}] }]
|
|
42
|
+
};
|
|
43
|
+
//#endregion
|
|
44
|
+
export { habitatConsumerBinding as t };
|
package/dist/nx-generators.js
CHANGED
|
@@ -1,51 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
defaultCheckScript: "nx run-many -t check",
|
|
4
|
-
gitHook: {
|
|
5
|
-
path: ".husky/pre-push",
|
|
6
|
-
contents: `# Nested Git work must discover its own repository.
|
|
7
|
-
unset $(git rev-parse --local-env-vars)
|
|
8
|
-
bun run check
|
|
9
|
-
`,
|
|
10
|
-
},
|
|
11
|
-
gritPackage: "@getgrit/cli",
|
|
12
|
-
husky: {
|
|
13
|
-
package: "husky",
|
|
14
|
-
version: "9.1.7",
|
|
15
|
-
prepare: "husky",
|
|
16
|
-
predecessorPrepareScripts: [
|
|
17
|
-
"./scripts/dev/install-repository-hooks.sh",
|
|
18
|
-
"git config core.hooksPath scripts/githooks",
|
|
19
|
-
],
|
|
20
|
-
},
|
|
21
|
-
nxPlugin: "@habitat-ai/cli/nx-plugin",
|
|
22
|
-
predecessorNxPlugins: [
|
|
23
|
-
{
|
|
24
|
-
plugin: "@habitat/cli/nx-plugin",
|
|
25
|
-
options: { checkTargetName: "check:policy" },
|
|
26
|
-
},
|
|
27
|
-
],
|
|
28
|
-
hook: {
|
|
29
|
-
_habitat: { identity: "@habitat-ai/cli:agent-stop", revision: 1 },
|
|
30
|
-
hooks: [
|
|
31
|
-
{
|
|
32
|
-
type: "command",
|
|
33
|
-
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\'',
|
|
34
|
-
timeout: 120,
|
|
35
|
-
statusMessage: "Checking Habitat structure laws",
|
|
36
|
-
},
|
|
37
|
-
],
|
|
38
|
-
},
|
|
39
|
-
predecessorHooks: [
|
|
40
|
-
{
|
|
41
|
-
hooks: [
|
|
42
|
-
{
|
|
43
|
-
type: "command",
|
|
44
|
-
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\'',
|
|
45
|
-
timeout: 120,
|
|
46
|
-
statusMessage: "Checking Habitat structure laws",
|
|
47
|
-
},
|
|
48
|
-
],
|
|
49
|
-
},
|
|
50
|
-
],
|
|
51
|
-
};
|
|
1
|
+
import { t as habitatConsumerBinding } from "./nx-generators-DQDXOkMX.js";
|
|
2
|
+
export { habitatConsumerBinding };
|
package/dist/nx-plugin.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
|
+
//#region src/nx-plugin.d.ts
|
|
1
2
|
/** Native Nx project inference backed by the public Habitat SDK. */
|
|
2
|
-
|
|
3
|
+
declare const createNodes: import("@nx/devkit").CreateNodes<undefined>;
|
|
4
|
+
//#endregion
|
|
5
|
+
export { createNodes };
|
package/dist/nx-plugin.js
CHANGED
|
@@ -1,16 +1,242 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import { n as resolveCatalogForWorkspace } from "./application-gZ8XAszE.js";
|
|
2
|
+
import { t as cliPackageRoot } from "./product-version-Bqc0L8lq.js";
|
|
3
|
+
import { posix } from "node:path";
|
|
4
|
+
//#region src/nx/projection.ts
|
|
5
|
+
const HABITAT_CATALOG_PATHS = [
|
|
6
|
+
".habitat/blueprints/*/blueprint.toml",
|
|
7
|
+
".habitat/blueprints/*/versions/*/blueprint.toml",
|
|
8
|
+
".habitat/index.json",
|
|
9
|
+
".habitat/**/rule.json",
|
|
10
|
+
"**/habitat.toml"
|
|
11
|
+
];
|
|
12
|
+
const HABITAT_AUTHORITY_GLOB = `{${HABITAT_CATALOG_PATHS.join(",")}}`;
|
|
13
|
+
const DEFAULT_CHECK_TARGET = "check:policy";
|
|
14
|
+
const HABITAT_EXECUTABLE = "habitat";
|
|
15
|
+
const PORTABLE_OWNER_PROJECT = /^[A-Za-z0-9@][A-Za-z0-9@._/+:-]*$/u;
|
|
16
|
+
/**
|
|
17
|
+
* Projects resolved Habitat applications and compatibility rules into native Nx targets.
|
|
18
|
+
*
|
|
19
|
+
* The factory receives the app-owned data reader and runtime cache facts.
|
|
20
|
+
* It does not select providers, discover authority, execute checks, or name
|
|
21
|
+
* projects.
|
|
22
|
+
*/
|
|
23
|
+
function createHabitatNxPlugin(binding) {
|
|
24
|
+
return Object.freeze({ createNodes: [HABITAT_AUTHORITY_GLOB, async (configFiles, _options, context) => {
|
|
25
|
+
const matchedFiles = [...new Set(configFiles.map(normalizeWorkspacePath))].sort();
|
|
26
|
+
const result = await binding.resolveForWorkspace(context.workspaceRoot);
|
|
27
|
+
if (result._tag === "Rejected") throw rejectedCatalogError(result);
|
|
28
|
+
return projectCatalogTargets(matchedFiles, result.catalog, binding.runtimeInputs);
|
|
29
|
+
}] });
|
|
30
|
+
}
|
|
31
|
+
function projectCatalogTargets(matchedFiles, catalog, runtimeInputs) {
|
|
32
|
+
if (catalog.applications.length === 0 && catalog.compatibility.rules.length === 0) return [];
|
|
33
|
+
const authorityFiles = new Set(matchedFiles);
|
|
34
|
+
const instances = indexInstances(catalog.instances);
|
|
35
|
+
const rootsByOwner = /* @__PURE__ */ new Map();
|
|
36
|
+
const ownersByRoot = /* @__PURE__ */ new Map();
|
|
37
|
+
const projects = /* @__PURE__ */ new Map();
|
|
38
|
+
for (const [ownerProject, ownerRoot] of Object.entries(catalog.compatibility.ownerRoots).sort(([left], [right]) => compareText(left, right))) recordOwnerRoot(ownerProject, ownerRoot, rootsByOwner, ownersByRoot);
|
|
39
|
+
for (const application of catalog.applications) {
|
|
40
|
+
const instance = requireApplicationInstance(application, instances);
|
|
41
|
+
const manifestPath = requireMatchedManifest(application.manifestPath, authorityFiles, `instance '${instance.id}'`);
|
|
42
|
+
const project = projectFor(projects, recordOwnerRoot(application.ownerProject, projectRootFor(manifestPath), rootsByOwner, ownersByRoot), application.ownerProject);
|
|
43
|
+
project.applicationManifests.add(manifestPath);
|
|
44
|
+
addLeafTarget(project, applicationTargetName(application), applicationTarget(application, runtimeInputs));
|
|
45
|
+
}
|
|
46
|
+
for (const rule of catalog.compatibility.rules) {
|
|
47
|
+
const root = rootsByOwner.get(rule.ownerProject);
|
|
48
|
+
if (root === void 0) throw new Error(`Habitat Nx projection rejected compatibility rule '${rule.ruleId}': owner '${rule.ownerProject}' has no root.`);
|
|
49
|
+
const manifestPath = requireMatchedManifest(rule.manifestPath, authorityFiles, `compatibility rule '${rule.ruleId}'`);
|
|
50
|
+
const project = projectFor(projects, root, rule.ownerProject);
|
|
51
|
+
project.compatibilityManifests.add(manifestPath);
|
|
52
|
+
addLeafTarget(project, compatibilityTargetName(rule), compatibilityTarget(rule, runtimeInputs));
|
|
53
|
+
}
|
|
54
|
+
return [...projects.entries()].sort(([left], [right]) => compareText(left, right)).map(([root, project]) => {
|
|
55
|
+
project.targets[DEFAULT_CHECK_TARGET] = ownerTarget(project.ownerProject, ownerInputs(project.targets, runtimeInputs), project.compatibilityManifests.size > 0);
|
|
56
|
+
return [projectionSource(project), { projects: { [root]: { targets: Object.fromEntries(Object.entries(project.targets).sort(([left], [right]) => compareText(left, right))) } } }];
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
function recordOwnerRoot(ownerProject, ownerRoot, rootsByOwner, ownersByRoot) {
|
|
60
|
+
const root = normalizeWorkspacePath(ownerRoot);
|
|
61
|
+
const priorRoot = rootsByOwner.get(ownerProject);
|
|
62
|
+
if (priorRoot !== void 0 && priorRoot !== root) throw new Error(`Habitat Nx projection rejected owner '${ownerProject}': roots '${priorRoot}' and '${root}' collide.`);
|
|
63
|
+
const priorOwner = ownersByRoot.get(root);
|
|
64
|
+
if (priorOwner !== void 0 && priorOwner !== ownerProject) throw new Error(`Habitat Nx projection rejected root '${root}': owners '${priorOwner}' and '${ownerProject}' collide.`);
|
|
65
|
+
rootsByOwner.set(ownerProject, root);
|
|
66
|
+
ownersByRoot.set(root, ownerProject);
|
|
67
|
+
return root;
|
|
68
|
+
}
|
|
69
|
+
function projectFor(projects, root, ownerProject) {
|
|
70
|
+
const project = projects.get(root);
|
|
71
|
+
if (project !== void 0) {
|
|
72
|
+
if (project.ownerProject !== ownerProject) throw new Error(`Habitat Nx projection rejected root '${root}': owners '${project.ownerProject}' and '${ownerProject}' collide.`);
|
|
73
|
+
return project;
|
|
74
|
+
}
|
|
75
|
+
const created = {
|
|
76
|
+
ownerProject,
|
|
77
|
+
applicationManifests: /* @__PURE__ */ new Set(),
|
|
78
|
+
compatibilityManifests: /* @__PURE__ */ new Set(),
|
|
79
|
+
targets: {}
|
|
80
|
+
};
|
|
81
|
+
projects.set(root, created);
|
|
82
|
+
return created;
|
|
83
|
+
}
|
|
84
|
+
function requireMatchedManifest(path, authorityFiles, subject) {
|
|
85
|
+
const manifestPath = normalizeWorkspacePath(path);
|
|
86
|
+
if (!authorityFiles.has(manifestPath)) throw new Error(`Habitat Nx projection rejected ${subject}: manifest '${manifestPath}' is outside the matched authority files.`);
|
|
87
|
+
return manifestPath;
|
|
88
|
+
}
|
|
89
|
+
function addLeafTarget(project, targetName, target) {
|
|
90
|
+
if (Object.hasOwn(project.targets, targetName)) throw new Error(`Habitat Nx projection rejected duplicate target '${project.ownerProject}:${targetName}'.`);
|
|
91
|
+
project.targets[targetName] = target;
|
|
92
|
+
}
|
|
93
|
+
function projectionSource(project) {
|
|
94
|
+
const applicationManifest = [...project.applicationManifests].sort(compareText)[0];
|
|
95
|
+
if (applicationManifest !== void 0) return applicationManifest;
|
|
96
|
+
const compatibilityManifest = [...project.compatibilityManifests].sort(compareText)[0];
|
|
97
|
+
if (compatibilityManifest === void 0) throw new Error(`Habitat Nx projection rejected owner '${project.ownerProject}': projected targets have no manifest.`);
|
|
98
|
+
return compatibilityManifest;
|
|
99
|
+
}
|
|
100
|
+
function requireApplicationInstance(application, instances) {
|
|
101
|
+
const instance = instances.get(application.instanceId);
|
|
102
|
+
if (!instance) throw new Error(`Habitat Nx projection rejected application '${application.ruleId}': instance '${application.instanceId}' is absent.`);
|
|
103
|
+
const mismatches = [
|
|
104
|
+
instance.ownerProject === application.ownerProject ? void 0 : `owner '${application.ownerProject}' does not match '${instance.ownerProject}'`,
|
|
105
|
+
instance.blueprint === application.blueprint ? void 0 : `blueprint '${application.blueprint}' does not match '${instance.blueprint}'`,
|
|
106
|
+
instance.blueprintVersion === application.blueprintVersion ? void 0 : `blueprint version '${application.blueprintVersion}' does not match '${instance.blueprintVersion}'`,
|
|
107
|
+
normalizeWorkspacePath(instance.manifestPath) === normalizeWorkspacePath(application.manifestPath) ? void 0 : `manifest '${application.manifestPath}' does not match '${instance.manifestPath}'`
|
|
108
|
+
].filter((mismatch) => mismatch !== void 0);
|
|
109
|
+
if (mismatches.length > 0) throw new Error(`Habitat Nx projection rejected instance '${instance.id}': ${mismatches.join("; ")}.`);
|
|
110
|
+
return instance;
|
|
111
|
+
}
|
|
112
|
+
function indexInstances(instances) {
|
|
113
|
+
const indexed = /* @__PURE__ */ new Map();
|
|
114
|
+
for (const instance of instances) {
|
|
115
|
+
if (indexed.has(instance.id)) throw new Error(`Habitat Nx projection rejected duplicate instance '${instance.id}'.`);
|
|
116
|
+
indexed.set(instance.id, instance);
|
|
117
|
+
}
|
|
118
|
+
return indexed;
|
|
119
|
+
}
|
|
120
|
+
function applicationTargetName(application) {
|
|
121
|
+
return `habitat:application:${application.instanceId}:${application.ruleId}`;
|
|
122
|
+
}
|
|
123
|
+
function compatibilityTargetName(rule) {
|
|
124
|
+
return `habitat:rule:${rule.ruleId}`;
|
|
125
|
+
}
|
|
126
|
+
function applicationTarget(application, runtimeInputs) {
|
|
127
|
+
return {
|
|
128
|
+
command: `${HABITAT_EXECUTABLE} check --instance ${application.instanceId} --rule ${application.ruleId}`,
|
|
129
|
+
cache: true,
|
|
130
|
+
parallelism: false,
|
|
131
|
+
inputs: applicationInputs(application, runtimeInputs),
|
|
132
|
+
outputs: [],
|
|
133
|
+
options: { cwd: "{workspaceRoot}" },
|
|
134
|
+
metadata: { description: `Check Habitat application ${application.instanceId}/${application.ruleId}` }
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
function compatibilityTarget(rule, runtimeInputs) {
|
|
138
|
+
return {
|
|
139
|
+
command: `${HABITAT_EXECUTABLE} check --rule ${rule.ruleId}`,
|
|
140
|
+
cache: true,
|
|
141
|
+
parallelism: false,
|
|
142
|
+
inputs: compatibilityInputs(rule, runtimeInputs),
|
|
143
|
+
outputs: [],
|
|
144
|
+
options: { cwd: "{workspaceRoot}" },
|
|
145
|
+
metadata: { description: `Check Habitat compatibility rule ${rule.ruleId}` }
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
function ownerTarget(ownerProject, inputs, hasCompatibility) {
|
|
149
|
+
if (!PORTABLE_OWNER_PROJECT.test(ownerProject)) throw new Error(`Habitat Nx projection rejected owner '${ownerProject}': identity is not portable as an Nx command argument.`);
|
|
150
|
+
return {
|
|
151
|
+
command: `${HABITAT_EXECUTABLE} check --owner ${ownerProject}`,
|
|
152
|
+
cache: true,
|
|
153
|
+
parallelism: false,
|
|
154
|
+
inputs,
|
|
155
|
+
outputs: [],
|
|
156
|
+
options: { cwd: "{workspaceRoot}" },
|
|
157
|
+
metadata: { description: hasCompatibility ? `Check resolved Habitat policy owned by ${ownerProject}` : `Check resolved Habitat applications owned by ${ownerProject}` }
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
function ownerInputs(targets, runtimeInputs) {
|
|
161
|
+
const runtimeStrings = new Set(runtimeInputs.filter((input) => typeof input === "string"));
|
|
162
|
+
const corpusInputs = /* @__PURE__ */ new Set();
|
|
163
|
+
for (const target of Object.values(targets)) for (const input of target.inputs ?? []) if (typeof input === "string" && !runtimeStrings.has(input)) corpusInputs.add(input);
|
|
164
|
+
return [...runtimeInputs, ...[...corpusInputs].sort(compareText)];
|
|
165
|
+
}
|
|
166
|
+
function applicationInputs(application, runtimeInputs) {
|
|
167
|
+
const files = new Set(HABITAT_CATALOG_PATHS.map(workspaceInput));
|
|
168
|
+
if (application.runner.name === "grit") {
|
|
169
|
+
addLocalAssetInput(files, application.runner.pattern);
|
|
170
|
+
for (const entry of application.runner.acquisition.entries) if (entry.source.kind === "root-pattern") files.add(workspaceInput(entry.path));
|
|
171
|
+
else addSubjectInputs(files, entry.path, entry.kind);
|
|
172
|
+
} else {
|
|
173
|
+
addLocalAssetInput(files, application.runner.structure);
|
|
174
|
+
for (const binding of application.runner.rootBindings) if (binding.path !== void 0) addSubjectInputs(files, binding.path, binding.kind);
|
|
175
|
+
}
|
|
176
|
+
return [...runtimeInputs, ...[...files].sort()];
|
|
177
|
+
}
|
|
178
|
+
function compatibilityInputs(rule, runtimeInputs) {
|
|
179
|
+
const files = new Set(HABITAT_CATALOG_PATHS.map(workspaceInput));
|
|
180
|
+
files.add(workspaceInput(".habitat/**"));
|
|
181
|
+
files.add(workspaceInput(rule.manifestPath));
|
|
182
|
+
addLocalAssetInput(files, rule.baseline);
|
|
183
|
+
for (const pattern of rule.coveragePatterns) files.add(workspaceInput(pattern));
|
|
184
|
+
if (rule.runner.name === "grit") {
|
|
185
|
+
addLocalAssetInput(files, rule.runner.pattern);
|
|
186
|
+
for (const entry of rule.runner.acquisition.entries) {
|
|
187
|
+
if (entry.kind === "directory" && entry.path === ".") continue;
|
|
188
|
+
addSubjectInputs(files, entry.path, entry.kind);
|
|
189
|
+
}
|
|
190
|
+
} else addLocalAssetInput(files, rule.runner.structure);
|
|
191
|
+
return [...runtimeInputs, ...[...files].sort(compareText)];
|
|
192
|
+
}
|
|
193
|
+
function addLocalAssetInput(target, asset) {
|
|
194
|
+
if (asset.provenance.kind === "local") target.add(workspaceInput(asset.relativePath));
|
|
195
|
+
}
|
|
196
|
+
function addSubjectInputs(target, path, kind) {
|
|
197
|
+
const exact = workspaceInput(path);
|
|
198
|
+
if (kind === "directory" && path === ".") {
|
|
199
|
+
target.add("{workspaceRoot}/**/*");
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
target.add(exact);
|
|
203
|
+
if (kind === "directory") target.add(`${exact}/**/*`);
|
|
204
|
+
}
|
|
205
|
+
function workspaceInput(path) {
|
|
206
|
+
const normalized = normalizeWorkspacePath(path);
|
|
207
|
+
return normalized === "." ? "{workspaceRoot}" : `{workspaceRoot}/${normalized}`;
|
|
208
|
+
}
|
|
209
|
+
function projectRootFor(manifestPath) {
|
|
210
|
+
const root = posix.dirname(manifestPath);
|
|
211
|
+
return root === "" ? "." : root;
|
|
212
|
+
}
|
|
213
|
+
function normalizeWorkspacePath(path) {
|
|
214
|
+
const slashPath = path.replaceAll("\\", "/");
|
|
215
|
+
if (posix.isAbsolute(slashPath) || /^[A-Za-z]:\//.test(slashPath)) throw new Error(`Habitat Nx projection requires a workspace-relative path: '${path}'.`);
|
|
216
|
+
const normalized = posix.normalize(slashPath).replace(/^\.\//, "");
|
|
217
|
+
if (normalized === ".." || normalized.startsWith("../")) throw new Error(`Habitat Nx projection path escapes the workspace: '${path}'.`);
|
|
218
|
+
return normalized === "" ? "." : normalized;
|
|
219
|
+
}
|
|
220
|
+
function rejectedCatalogError(result) {
|
|
221
|
+
return /* @__PURE__ */ new Error(`Habitat catalog resolution rejected during Nx projection: ${JSON.stringify(result.issues)}`);
|
|
222
|
+
}
|
|
223
|
+
function compareText(left, right) {
|
|
224
|
+
return left < right ? -1 : left > right ? 1 : 0;
|
|
225
|
+
}
|
|
15
226
|
/** Native Nx project inference backed by the public Habitat SDK. */
|
|
16
|
-
|
|
227
|
+
const createNodes = createHabitatNxPlugin({
|
|
228
|
+
resolveForWorkspace: (workspaceRoot) => resolveCatalogForWorkspace({
|
|
229
|
+
appRoot: cliPackageRoot(),
|
|
230
|
+
workspaceRoot,
|
|
231
|
+
development: import.meta.url.endsWith(".ts")
|
|
232
|
+
}),
|
|
233
|
+
runtimeInputs: [
|
|
234
|
+
{ externalDependencies: ["@habitat-ai/cli"] },
|
|
235
|
+
"{workspaceRoot}/bun.lock",
|
|
236
|
+
"{workspaceRoot}/package.json",
|
|
237
|
+
{ env: "HABITAT_COMMAND_TIMEOUT_MS" },
|
|
238
|
+
{ env: "NX_WORKSPACE_ROOT_PATH" }
|
|
239
|
+
]
|
|
240
|
+
}).createNodes;
|
|
241
|
+
//#endregion
|
|
242
|
+
export { createNodes };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { t as entrypoint } from "./cli-hhbbymEz.js";
|
|
2
|
+
import { n as createOclifSourceBundle } from "./host-BcptPYDL.js";
|
|
3
|
+
import { deriveRuntimeArtifacts } from "@habitat-ai/sdk/runtime/derivation";
|
|
4
|
+
//#region src/oclif.ts
|
|
5
|
+
const sourceBundle = createOclifSourceBundle(deriveRuntimeArtifacts({
|
|
6
|
+
entrypoint,
|
|
7
|
+
profileId: entrypoint.profile.id
|
|
8
|
+
}));
|
|
9
|
+
const COMMANDS = sourceBundle.COMMANDS;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { sourceBundle as n, COMMANDS as t };
|
package/dist/oclif.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { readFileSync } from "node:fs";
|
|
4
|
+
//#region src/product-version.ts
|
|
5
|
+
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-]+)*)?$/;
|
|
6
|
+
/** Resolves this CLI package through its own export, independent of bundled chunk placement. */
|
|
7
|
+
function cliPackageRoot() {
|
|
8
|
+
return dirname(createRequire(import.meta.url).resolve("@habitat-ai/cli/package.json"));
|
|
9
|
+
}
|
|
10
|
+
/** Returns the exact SDK version paired with the installed Habitat CLI. */
|
|
11
|
+
function installedSdkVersion() {
|
|
12
|
+
const manifest = JSON.parse(readFileSync(join(cliPackageRoot(), "package.json"), "utf8"));
|
|
13
|
+
const version = manifest.dependencies?.["@habitat-ai/sdk"];
|
|
14
|
+
if (typeof version !== "string" || !EXACT_SEMVER_PATTERN.test(version) || version !== manifest.version) throw new Error("Installed @habitat-ai/cli and @habitat-ai/sdk must use one identical exact semantic version.");
|
|
15
|
+
return version;
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
export { installedSdkVersion as n, cliPackageRoot as t };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { flushChanges } from "nx/src/generators/tree.js";
|
|
2
|
+
//#region src/generators/publish-generator-tree.ts
|
|
3
|
+
/** Publish an already staged native Tree; a failed flush may leave a written prefix. */
|
|
4
|
+
function publishGeneratorTree(tree, options = {}) {
|
|
5
|
+
tree.lock();
|
|
6
|
+
const changes = tree.listChanges();
|
|
7
|
+
if (!options.dryRun) flushChanges(tree.root, changes);
|
|
8
|
+
return Object.freeze({
|
|
9
|
+
status: options.dryRun ? "dry-run" : changes.length === 0 ? "converged" : "created",
|
|
10
|
+
paths: Object.freeze(changes.map((change) => change.path))
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
//#endregion
|
|
14
|
+
export { publishGeneratorTree };
|