@habitat-ai/cli 0.3.0 → 0.4.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/dist/application.d.ts +1 -1
- package/dist/application.js +3 -3
- package/dist/commands/check.d.ts +15 -0
- package/dist/commands/check.js +32 -0
- package/dist/commands/hook.d.ts +12 -0
- package/dist/commands/hook.js +25 -0
- package/dist/commands/resolve.d.ts +9 -0
- package/dist/commands/resolve.js +15 -0
- package/dist/generators/init.d.ts +3 -0
- package/dist/generators/init.js +10 -0
- package/dist/generators/remove-hook.d.ts +3 -0
- package/dist/generators/remove-hook.js +6 -0
- package/dist/lib/binding.d.ts +10 -0
- package/dist/lib/binding.js +16 -0
- package/dist/lib/output.d.ts +9 -0
- package/dist/lib/output.js +22 -0
- package/dist/nx/initialization.d.ts +45 -0
- package/dist/nx/initialization.js +201 -0
- package/dist/nx/projection.d.ts +29 -0
- package/dist/nx/projection.js +293 -0
- package/dist/nx-generators.d.ts +31 -0
- package/dist/nx-generators.js +34 -0
- package/dist/nx-plugin.d.ts +2 -0
- package/dist/nx-plugin.js +11 -52394
- package/generators.json +2 -2
- package/oclif.manifest.json +101 -2
- package/package.json +16 -28
- package/dist/composition.d.ts +0 -8
- package/dist/composition.js +0 -59
- package/dist/generators/init.cjs +0 -252
- package/dist/generators/remove-hook.cjs +0 -191
- package/src/nx-plugin.d.ts +0 -4
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
function __accessProp(key) {
|
|
6
|
-
return this[key];
|
|
7
|
-
}
|
|
8
|
-
var __toCommonJS = (from) => {
|
|
9
|
-
var entry = (__moduleCache ??= new WeakMap).get(from), desc;
|
|
10
|
-
if (entry)
|
|
11
|
-
return entry;
|
|
12
|
-
entry = __defProp({}, "__esModule", { value: true });
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (var key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(entry, key))
|
|
16
|
-
__defProp(entry, key, {
|
|
17
|
-
get: __accessProp.bind(from, key),
|
|
18
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
__moduleCache.set(from, entry);
|
|
22
|
-
return entry;
|
|
23
|
-
};
|
|
24
|
-
var __moduleCache;
|
|
25
|
-
var __returnValue = (v) => v;
|
|
26
|
-
function __exportSetter(name, newValue) {
|
|
27
|
-
this[name] = __returnValue.bind(null, newValue);
|
|
28
|
-
}
|
|
29
|
-
var __export = (target, all) => {
|
|
30
|
-
for (var name in all)
|
|
31
|
-
__defProp(target, name, {
|
|
32
|
-
get: all[name],
|
|
33
|
-
enumerable: true,
|
|
34
|
-
configurable: true,
|
|
35
|
-
set: __exportSetter.bind(all, name)
|
|
36
|
-
});
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
// src/generators/remove-hook.ts
|
|
40
|
-
var exports_remove_hook = {};
|
|
41
|
-
__export(exports_remove_hook, {
|
|
42
|
-
default: () => removeHook
|
|
43
|
-
});
|
|
44
|
-
module.exports = __toCommonJS(exports_remove_hook);
|
|
45
|
-
|
|
46
|
-
// ../../plugins/nx/habitat/src/initialization.ts
|
|
47
|
-
var import_node_util = require("node:util");
|
|
48
|
-
var import_devkit = require("@nx/devkit");
|
|
49
|
-
var import_typebox = require("typebox");
|
|
50
|
-
var import_schema = require("typebox/schema");
|
|
51
|
-
var CODEX_HOOKS_PATH = ".codex/hooks.json";
|
|
52
|
-
var HabitatHookMarkerSchema = import_typebox.Type.Object({
|
|
53
|
-
identity: import_typebox.Type.String({
|
|
54
|
-
minLength: 1,
|
|
55
|
-
description: "Stable package-owned identity for one Habitat hook contribution."
|
|
56
|
-
}),
|
|
57
|
-
revision: import_typebox.Type.Integer({
|
|
58
|
-
minimum: 0,
|
|
59
|
-
description: "Monotonic payload revision for the named Habitat contribution."
|
|
60
|
-
})
|
|
61
|
-
}, { additionalProperties: false, description: "Habitat hook ownership marker." });
|
|
62
|
-
var HookGroupSchema = import_typebox.Type.Object({
|
|
63
|
-
_habitat: import_typebox.Type.Optional(HabitatHookMarkerSchema),
|
|
64
|
-
hooks: import_typebox.Type.Array(import_typebox.Type.Unknown(), {
|
|
65
|
-
description: "Ordered command contributions in one Codex hook group."
|
|
66
|
-
})
|
|
67
|
-
}, { additionalProperties: true, description: "One consumer-owned Codex hook group." });
|
|
68
|
-
var HabitatHookCommandSchema = import_typebox.Type.Object({
|
|
69
|
-
type: import_typebox.Type.Literal("command", {
|
|
70
|
-
description: "Codex hook handler kind owned by the Habitat initializer."
|
|
71
|
-
}),
|
|
72
|
-
command: import_typebox.Type.String({
|
|
73
|
-
minLength: 1,
|
|
74
|
-
description: "Installed Habitat command executed by the Codex hook."
|
|
75
|
-
}),
|
|
76
|
-
statusMessage: import_typebox.Type.String({
|
|
77
|
-
minLength: 1,
|
|
78
|
-
description: "Operator-facing status rendered while Habitat checks run."
|
|
79
|
-
}),
|
|
80
|
-
timeout: import_typebox.Type.Integer({
|
|
81
|
-
minimum: 1,
|
|
82
|
-
description: "Maximum seconds allowed for the Habitat hook command."
|
|
83
|
-
})
|
|
84
|
-
}, { additionalProperties: false, description: "One Habitat-owned Codex hook command." });
|
|
85
|
-
var HabitatOwnedHookGroupSchema = import_typebox.Type.Object({
|
|
86
|
-
_habitat: HabitatHookMarkerSchema,
|
|
87
|
-
hooks: import_typebox.Type.Array(HabitatHookCommandSchema, {
|
|
88
|
-
minItems: 1,
|
|
89
|
-
description: "Commands contributed by the installed Habitat package."
|
|
90
|
-
})
|
|
91
|
-
}, { additionalProperties: false, description: "The named Habitat Codex hook contribution." });
|
|
92
|
-
var CodexHooksSchema = import_typebox.Type.Object({
|
|
93
|
-
hooks: import_typebox.Type.Optional(import_typebox.Type.Record(import_typebox.Type.String(), import_typebox.Type.Array(HookGroupSchema), {
|
|
94
|
-
description: "Ordered hook groups keyed by Codex event identity."
|
|
95
|
-
}))
|
|
96
|
-
}, { additionalProperties: true, description: "Consumer-owned Codex hook configuration." });
|
|
97
|
-
var ConsumerPackageSchema = import_typebox.Type.Object({
|
|
98
|
-
trustedDependencies: import_typebox.Type.Optional(import_typebox.Type.Array(import_typebox.Type.String({ minLength: 1 }), {
|
|
99
|
-
description: "Package lifecycle scripts explicitly trusted by the Bun consumer."
|
|
100
|
-
}))
|
|
101
|
-
}, { additionalProperties: true, description: "Nx consumer package metadata." });
|
|
102
|
-
var hooksValidator = new import_schema.Validator({}, CodexHooksSchema);
|
|
103
|
-
var packageValidator = new import_schema.Validator({}, ConsumerPackageSchema);
|
|
104
|
-
function removeHabitatHook(tree, binding) {
|
|
105
|
-
const hooks = readHooks(tree);
|
|
106
|
-
const hookPlan = planHookRemoval(hooks, binding);
|
|
107
|
-
if (hookPlan.changed)
|
|
108
|
-
import_devkit.writeJson(tree, CODEX_HOOKS_PATH, hookPlan.value);
|
|
109
|
-
}
|
|
110
|
-
function readHooks(tree) {
|
|
111
|
-
if (!tree.exists(CODEX_HOOKS_PATH))
|
|
112
|
-
return { hooks: {} };
|
|
113
|
-
const input = import_devkit.readJson(tree, CODEX_HOOKS_PATH);
|
|
114
|
-
if (!hooksValidator.Check(input)) {
|
|
115
|
-
throw new Error(`${CODEX_HOOKS_PATH} is not a supported Codex hook document.`);
|
|
116
|
-
}
|
|
117
|
-
return input;
|
|
118
|
-
}
|
|
119
|
-
function planHookRemoval(hooks, binding) {
|
|
120
|
-
const location = oneOwnedHookLocation(hooks, binding);
|
|
121
|
-
if (location === undefined)
|
|
122
|
-
return { changed: false, value: hooks };
|
|
123
|
-
if (!import_node_util.isDeepStrictEqual(location.group, binding.hook) && !binding.predecessorHooks.some((predecessor) => import_node_util.isDeepStrictEqual(predecessor, location.group))) {
|
|
124
|
-
throw new Error(`${CODEX_HOOKS_PATH} contains an incompatible Habitat hook contribution.`);
|
|
125
|
-
}
|
|
126
|
-
const events = hooks.hooks ?? {};
|
|
127
|
-
const stop = events.Stop ?? [];
|
|
128
|
-
return {
|
|
129
|
-
changed: true,
|
|
130
|
-
value: {
|
|
131
|
-
...hooks,
|
|
132
|
-
hooks: { ...events, Stop: stop.filter((_group, index) => index !== location.index) }
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
function oneOwnedHookLocation(hooks, binding) {
|
|
137
|
-
const identity = binding.hook._habitat.identity;
|
|
138
|
-
const locations = Object.entries(hooks.hooks ?? {}).flatMap(([event, groups]) => groups.flatMap((group, index) => {
|
|
139
|
-
const marked = group._habitat?.identity === identity;
|
|
140
|
-
const predecessor = binding.predecessorHooks.some((candidate) => import_node_util.isDeepStrictEqual(candidate, group));
|
|
141
|
-
return marked || predecessor ? [{ event, group, index }] : [];
|
|
142
|
-
}));
|
|
143
|
-
if (locations.length > 1) {
|
|
144
|
-
throw new Error(`${CODEX_HOOKS_PATH} contains multiple Habitat hook contributions.`);
|
|
145
|
-
}
|
|
146
|
-
const location = locations[0];
|
|
147
|
-
if (location !== undefined && location.event !== "Stop") {
|
|
148
|
-
throw new Error(`${CODEX_HOOKS_PATH} contains a Habitat hook contribution outside Stop.`);
|
|
149
|
-
}
|
|
150
|
-
return location;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// src/nx-generators.ts
|
|
154
|
-
var habitatConsumerBinding = {
|
|
155
|
-
gritPackage: "@getgrit/cli",
|
|
156
|
-
nxPlugin: "@habitat-ai/cli/nx-plugin",
|
|
157
|
-
predecessorNxPlugins: [
|
|
158
|
-
{
|
|
159
|
-
plugin: "@habitat/cli/nx-plugin",
|
|
160
|
-
options: { checkTargetName: "check:policy" }
|
|
161
|
-
}
|
|
162
|
-
],
|
|
163
|
-
hook: {
|
|
164
|
-
_habitat: { identity: "@habitat-ai/cli:agent-stop", revision: 1 },
|
|
165
|
-
hooks: [
|
|
166
|
-
{
|
|
167
|
-
type: "command",
|
|
168
|
-
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\'',
|
|
169
|
-
timeout: 120,
|
|
170
|
-
statusMessage: "Checking Habitat structure laws"
|
|
171
|
-
}
|
|
172
|
-
]
|
|
173
|
-
},
|
|
174
|
-
predecessorHooks: [
|
|
175
|
-
{
|
|
176
|
-
hooks: [
|
|
177
|
-
{
|
|
178
|
-
type: "command",
|
|
179
|
-
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\'',
|
|
180
|
-
timeout: 120,
|
|
181
|
-
statusMessage: "Checking Habitat structure laws"
|
|
182
|
-
}
|
|
183
|
-
]
|
|
184
|
-
}
|
|
185
|
-
]
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
// src/generators/remove-hook.ts
|
|
189
|
-
function removeHook(tree) {
|
|
190
|
-
removeHabitatHook(tree, habitatConsumerBinding);
|
|
191
|
-
}
|
package/src/nx-plugin.d.ts
DELETED