@habitat-ai/plugin-cli 0.2.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/commands/check.d.ts +15 -0
- package/dist/commands/check.js +31 -0
- package/dist/commands/hook.d.ts +12 -0
- package/dist/commands/hook.js +24 -0
- package/dist/commands/resolve.d.ts +9 -0
- package/dist/commands/resolve.js +14 -0
- package/dist/lib/binding.d.ts +10 -0
- package/dist/lib/binding.js +16 -0
- package/oclif.manifest.json +103 -0
- package/package.json +63 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Client } from "@habitat-ai/service/client";
|
|
2
|
+
import { Command } from "@oclif/core";
|
|
3
|
+
type CheckResult = Awaited<ReturnType<Client["catalog"]["check"]>>;
|
|
4
|
+
/** Projects one selected Habitat catalog check into Oclif. */
|
|
5
|
+
export default class Check extends Command {
|
|
6
|
+
static description: string;
|
|
7
|
+
static flags: {
|
|
8
|
+
readonly instance: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
9
|
+
readonly owner: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
10
|
+
readonly rule: import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
11
|
+
readonly runner: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
12
|
+
};
|
|
13
|
+
run(): Promise<CheckResult>;
|
|
14
|
+
}
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Command, Flags } from "@oclif/core";
|
|
2
|
+
import { habitatClientFrom } from "../lib/binding.js";
|
|
3
|
+
/** Projects one selected Habitat catalog check into Oclif. */
|
|
4
|
+
export default class Check extends Command {
|
|
5
|
+
static description = "Check resolved Habitat applications";
|
|
6
|
+
static flags = {
|
|
7
|
+
instance: Flags.string({ description: "Exact Habitat instance identity" }),
|
|
8
|
+
owner: Flags.string({ description: "Repository project whose applications enter the check" }),
|
|
9
|
+
rule: Flags.string({
|
|
10
|
+
description: "Habitat rule identity; repeat to select a rule set",
|
|
11
|
+
multiple: true,
|
|
12
|
+
}),
|
|
13
|
+
runner: Flags.string({ description: "Mechanical runner identity" }),
|
|
14
|
+
};
|
|
15
|
+
async run() {
|
|
16
|
+
const { flags } = await this.parse(Check);
|
|
17
|
+
const rules = Array.isArray(flags.rule) ? flags.rule : flags.rule ? [flags.rule] : [];
|
|
18
|
+
const selectors = {
|
|
19
|
+
...(flags.instance !== undefined ? { instance: flags.instance } : {}),
|
|
20
|
+
...(flags.owner !== undefined ? { owner: flags.owner } : {}),
|
|
21
|
+
...(rules.length === 1 ? { rule: rules[0] } : {}),
|
|
22
|
+
...(rules.length > 1 ? { rules } : {}),
|
|
23
|
+
...(flags.runner !== undefined ? { runner: flags.runner } : {}),
|
|
24
|
+
};
|
|
25
|
+
const result = await habitatClientFrom(this.config).catalog.check(Object.keys(selectors).length === 0 ? {} : { selectors });
|
|
26
|
+
this.log(JSON.stringify(result, null, 2));
|
|
27
|
+
if (result._tag !== "Completed" || !result.ok)
|
|
28
|
+
this.exit(1);
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Client } from "@habitat-ai/service/client";
|
|
2
|
+
import { Command } from "@oclif/core";
|
|
3
|
+
type HookResult = Awaited<ReturnType<Client["catalog"]["check"]>>;
|
|
4
|
+
/** Runs one bounded Habitat operation for a repository-owned local hook. */
|
|
5
|
+
export default class Hook extends Command {
|
|
6
|
+
static description: string;
|
|
7
|
+
static args: {
|
|
8
|
+
readonly name: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
9
|
+
};
|
|
10
|
+
run(): Promise<HookResult>;
|
|
11
|
+
}
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Args, Command } from "@oclif/core";
|
|
2
|
+
import { habitatClientFrom } from "../lib/binding.js";
|
|
3
|
+
/** Runs one bounded Habitat operation for a repository-owned local hook. */
|
|
4
|
+
export default class Hook extends Command {
|
|
5
|
+
static description = "Run a Habitat local-hook entrypoint";
|
|
6
|
+
static args = {
|
|
7
|
+
name: Args.string({
|
|
8
|
+
required: true,
|
|
9
|
+
options: ["agent-stop"],
|
|
10
|
+
description: "Named Habitat hook operation",
|
|
11
|
+
}),
|
|
12
|
+
};
|
|
13
|
+
async run() {
|
|
14
|
+
await this.parse(Hook);
|
|
15
|
+
const result = await habitatClientFrom(this.config).catalog.check({
|
|
16
|
+
selectors: { runner: "habitat" },
|
|
17
|
+
});
|
|
18
|
+
if (result._tag !== "Completed" || !result.ok) {
|
|
19
|
+
this.log(JSON.stringify(result, null, 2));
|
|
20
|
+
this.exit(1);
|
|
21
|
+
}
|
|
22
|
+
return result;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Client } from "@habitat-ai/service/client";
|
|
2
|
+
import { Command } from "@oclif/core";
|
|
3
|
+
type ResolveResult = Awaited<ReturnType<Client["catalog"]["resolve"]>>;
|
|
4
|
+
/** Projects current-workspace Habitat catalog resolution into Oclif. */
|
|
5
|
+
export default class Resolve extends Command {
|
|
6
|
+
static description: string;
|
|
7
|
+
run(): Promise<ResolveResult>;
|
|
8
|
+
}
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Command } from "@oclif/core";
|
|
2
|
+
import { habitatClientFrom } from "../lib/binding.js";
|
|
3
|
+
/** Projects current-workspace Habitat catalog resolution into Oclif. */
|
|
4
|
+
export default class Resolve extends Command {
|
|
5
|
+
static description = "Resolve the current Habitat authority catalog";
|
|
6
|
+
async run() {
|
|
7
|
+
await this.parse(Resolve);
|
|
8
|
+
const result = await habitatClientFrom(this.config).catalog.resolve({});
|
|
9
|
+
this.log(JSON.stringify(result, null, 2));
|
|
10
|
+
if (result._tag === "Rejected")
|
|
11
|
+
this.exit(1);
|
|
12
|
+
return result;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Client } from "@habitat-ai/service/client";
|
|
2
|
+
import { type Config } from "@oclif/core";
|
|
3
|
+
/** Oclif load options carrying the ready Habitat client selected by the app. */
|
|
4
|
+
export type HabitatOclifLoadOptions = Config["options"] & {
|
|
5
|
+
readonly habitatClient: Client;
|
|
6
|
+
};
|
|
7
|
+
/** Adds the app-owned Habitat client to one native Oclif configuration. */
|
|
8
|
+
export declare function bindHabitatClient(options: Config["options"], client: Client): HabitatOclifLoadOptions;
|
|
9
|
+
/** Reads the ready Habitat client from the current native Oclif configuration. */
|
|
10
|
+
export declare function habitatClientFrom(config: Config): Client;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Errors } from "@oclif/core";
|
|
2
|
+
const HABITAT_CLIENT = "habitatClient";
|
|
3
|
+
/** Adds the app-owned Habitat client to one native Oclif configuration. */
|
|
4
|
+
export function bindHabitatClient(options, client) {
|
|
5
|
+
return Object.freeze({ ...options, [HABITAT_CLIENT]: client });
|
|
6
|
+
}
|
|
7
|
+
/** Reads the ready Habitat client from the current native Oclif configuration. */
|
|
8
|
+
export function habitatClientFrom(config) {
|
|
9
|
+
if (!hasHabitatClient(config.options)) {
|
|
10
|
+
throw new Errors.CLIError("The Habitat app did not supply its service binding.");
|
|
11
|
+
}
|
|
12
|
+
return config.options.habitatClient;
|
|
13
|
+
}
|
|
14
|
+
function hasHabitatClient(options) {
|
|
15
|
+
return HABITAT_CLIENT in options && options.habitatClient !== undefined;
|
|
16
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
{
|
|
2
|
+
"commands": {
|
|
3
|
+
"hook": {
|
|
4
|
+
"aliases": [],
|
|
5
|
+
"args": {
|
|
6
|
+
"name": {
|
|
7
|
+
"description": "Named Habitat hook operation",
|
|
8
|
+
"name": "name",
|
|
9
|
+
"options": [
|
|
10
|
+
"agent-stop"
|
|
11
|
+
],
|
|
12
|
+
"required": true
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"description": "Run a Habitat local-hook entrypoint",
|
|
16
|
+
"flags": {},
|
|
17
|
+
"hasDynamicHelp": false,
|
|
18
|
+
"hiddenAliases": [],
|
|
19
|
+
"id": "hook",
|
|
20
|
+
"pluginAlias": "@habitat-ai/plugin-cli",
|
|
21
|
+
"pluginName": "@habitat-ai/plugin-cli",
|
|
22
|
+
"pluginType": "core",
|
|
23
|
+
"strict": true,
|
|
24
|
+
"enableJsonFlag": false,
|
|
25
|
+
"isESM": true,
|
|
26
|
+
"relativePath": [
|
|
27
|
+
"dist",
|
|
28
|
+
"commands",
|
|
29
|
+
"hook.js"
|
|
30
|
+
]
|
|
31
|
+
},
|
|
32
|
+
"resolve": {
|
|
33
|
+
"aliases": [],
|
|
34
|
+
"args": {},
|
|
35
|
+
"description": "Resolve the current Habitat authority catalog",
|
|
36
|
+
"flags": {},
|
|
37
|
+
"hasDynamicHelp": false,
|
|
38
|
+
"hiddenAliases": [],
|
|
39
|
+
"id": "resolve",
|
|
40
|
+
"pluginAlias": "@habitat-ai/plugin-cli",
|
|
41
|
+
"pluginName": "@habitat-ai/plugin-cli",
|
|
42
|
+
"pluginType": "core",
|
|
43
|
+
"strict": true,
|
|
44
|
+
"enableJsonFlag": false,
|
|
45
|
+
"isESM": true,
|
|
46
|
+
"relativePath": [
|
|
47
|
+
"dist",
|
|
48
|
+
"commands",
|
|
49
|
+
"resolve.js"
|
|
50
|
+
]
|
|
51
|
+
},
|
|
52
|
+
"check": {
|
|
53
|
+
"aliases": [],
|
|
54
|
+
"args": {},
|
|
55
|
+
"description": "Check resolved Habitat applications",
|
|
56
|
+
"flags": {
|
|
57
|
+
"instance": {
|
|
58
|
+
"description": "Exact Habitat instance identity",
|
|
59
|
+
"name": "instance",
|
|
60
|
+
"hasDynamicHelp": false,
|
|
61
|
+
"multiple": false,
|
|
62
|
+
"type": "option"
|
|
63
|
+
},
|
|
64
|
+
"owner": {
|
|
65
|
+
"description": "Repository project whose applications enter the check",
|
|
66
|
+
"name": "owner",
|
|
67
|
+
"hasDynamicHelp": false,
|
|
68
|
+
"multiple": false,
|
|
69
|
+
"type": "option"
|
|
70
|
+
},
|
|
71
|
+
"rule": {
|
|
72
|
+
"description": "Habitat rule identity; repeat to select a rule set",
|
|
73
|
+
"name": "rule",
|
|
74
|
+
"hasDynamicHelp": false,
|
|
75
|
+
"multiple": true,
|
|
76
|
+
"type": "option"
|
|
77
|
+
},
|
|
78
|
+
"runner": {
|
|
79
|
+
"description": "Mechanical runner identity",
|
|
80
|
+
"name": "runner",
|
|
81
|
+
"hasDynamicHelp": false,
|
|
82
|
+
"multiple": false,
|
|
83
|
+
"type": "option"
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
"hasDynamicHelp": false,
|
|
87
|
+
"hiddenAliases": [],
|
|
88
|
+
"id": "check",
|
|
89
|
+
"pluginAlias": "@habitat-ai/plugin-cli",
|
|
90
|
+
"pluginName": "@habitat-ai/plugin-cli",
|
|
91
|
+
"pluginType": "core",
|
|
92
|
+
"strict": true,
|
|
93
|
+
"enableJsonFlag": false,
|
|
94
|
+
"isESM": true,
|
|
95
|
+
"relativePath": [
|
|
96
|
+
"dist",
|
|
97
|
+
"commands",
|
|
98
|
+
"check.js"
|
|
99
|
+
]
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
"version": "0.2.0"
|
|
103
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@habitat-ai/plugin-cli",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "Native Oclif projections for the Habitat catalog service",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist",
|
|
10
|
+
"oclif.manifest.json",
|
|
11
|
+
"package.json"
|
|
12
|
+
],
|
|
13
|
+
"exports": {
|
|
14
|
+
"./binding": {
|
|
15
|
+
"types": "./dist/lib/binding.d.ts",
|
|
16
|
+
"default": "./dist/lib/binding.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsc -p tsconfig.build.json",
|
|
21
|
+
"manifest": "NODE_ENV=production bun --bun oclif manifest",
|
|
22
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
23
|
+
"check:test": "tsc -p tsconfig.test.json --noEmit",
|
|
24
|
+
"test": "vitest run --project plugin-habitat"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@habitat-ai/service": "0.2.0",
|
|
28
|
+
"@oclif/core": "^4.11.4"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@effect/platform-node": "4.0.0-beta.101",
|
|
32
|
+
"effect": "4.0.0-beta.101",
|
|
33
|
+
"oclif": "4.23.27",
|
|
34
|
+
"typescript": "^5.9.3"
|
|
35
|
+
},
|
|
36
|
+
"oclif": {
|
|
37
|
+
"commands": "./dist/commands",
|
|
38
|
+
"topicSeparator": " "
|
|
39
|
+
},
|
|
40
|
+
"nx": {
|
|
41
|
+
"tags": [
|
|
42
|
+
"type:plugin",
|
|
43
|
+
"surface:cli",
|
|
44
|
+
"capability:habitat"
|
|
45
|
+
],
|
|
46
|
+
"targets": {
|
|
47
|
+
"check:test": {
|
|
48
|
+
"dependsOn": [
|
|
49
|
+
"build",
|
|
50
|
+
"^build"
|
|
51
|
+
]
|
|
52
|
+
},
|
|
53
|
+
"test": {
|
|
54
|
+
"dependsOn": [
|
|
55
|
+
"build"
|
|
56
|
+
]
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
"publishConfig": {
|
|
61
|
+
"access": "public"
|
|
62
|
+
}
|
|
63
|
+
}
|