@habitat-ai/plugin-cli 0.2.3 → 0.2.4

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.
@@ -1,5 +1,6 @@
1
1
  import { Command, Flags } from "@oclif/core";
2
2
  import { habitatClientFrom } from "../lib/binding.js";
3
+ import { writeJsonResult } from "../lib/output.js";
3
4
  /** Projects one selected Habitat catalog check into Oclif. */
4
5
  export default class Check extends Command {
5
6
  static description = "Check resolved Habitat applications";
@@ -23,7 +24,7 @@ export default class Check extends Command {
23
24
  ...(flags.runner !== undefined ? { runner: flags.runner } : {}),
24
25
  };
25
26
  const result = await habitatClientFrom(this.config).catalog.check(Object.keys(selectors).length === 0 ? {} : { selectors });
26
- this.log(JSON.stringify(result, null, 2));
27
+ await writeJsonResult(result);
27
28
  if (result._tag !== "Completed" || !result.ok)
28
29
  this.exit(1);
29
30
  return result;
@@ -1,5 +1,6 @@
1
1
  import { Args, Command } from "@oclif/core";
2
2
  import { habitatClientFrom } from "../lib/binding.js";
3
+ import { writeJsonResult } from "../lib/output.js";
3
4
  /** Runs one bounded Habitat operation for a repository-owned local hook. */
4
5
  export default class Hook extends Command {
5
6
  static description = "Run a Habitat local-hook entrypoint";
@@ -16,7 +17,7 @@ export default class Hook extends Command {
16
17
  selectors: { runner: "habitat" },
17
18
  });
18
19
  if (result._tag !== "Completed" || !result.ok) {
19
- this.log(JSON.stringify(result, null, 2));
20
+ await writeJsonResult(result);
20
21
  this.exit(1);
21
22
  }
22
23
  return result;
@@ -1,12 +1,13 @@
1
1
  import { Command } from "@oclif/core";
2
2
  import { habitatClientFrom } from "../lib/binding.js";
3
+ import { writeJsonResult } from "../lib/output.js";
3
4
  /** Projects current-workspace Habitat catalog resolution into Oclif. */
4
5
  export default class Resolve extends Command {
5
6
  static description = "Resolve the current Habitat authority catalog";
6
7
  async run() {
7
8
  await this.parse(Resolve);
8
9
  const result = await habitatClientFrom(this.config).catalog.resolve({});
9
- this.log(JSON.stringify(result, null, 2));
10
+ await writeJsonResult(result);
10
11
  if (result._tag === "Rejected")
11
12
  this.exit(1);
12
13
  return result;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Writes one complete Habitat command result as JSON before the command returns.
3
+ *
4
+ * Awaiting the stream callback prevents Bun from ending the process while a
5
+ * large stdout write is still buffered at the Oclif process boundary. EPIPE
6
+ * remains successful because it means the downstream pipe deliberately
7
+ * stopped reading, matching Oclif's stdout behavior.
8
+ */
9
+ export declare function writeJsonResult(result: unknown): Promise<void>;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Writes one complete Habitat command result as JSON before the command returns.
3
+ *
4
+ * Awaiting the stream callback prevents Bun from ending the process while a
5
+ * large stdout write is still buffered at the Oclif process boundary. EPIPE
6
+ * remains successful because it means the downstream pipe deliberately
7
+ * stopped reading, matching Oclif's stdout behavior.
8
+ */
9
+ export function writeJsonResult(result) {
10
+ return new Promise((resolve, reject) => {
11
+ process.stdout.write(`${JSON.stringify(result, null, 2)}\n`, (error) => {
12
+ if (error && !isBrokenPipe(error)) {
13
+ reject(error);
14
+ return;
15
+ }
16
+ resolve();
17
+ });
18
+ });
19
+ }
20
+ function isBrokenPipe(error) {
21
+ return "code" in error && error.code === "EPIPE";
22
+ }
@@ -99,5 +99,5 @@
99
99
  ]
100
100
  }
101
101
  },
102
- "version": "0.2.3"
102
+ "version": "0.2.4"
103
103
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@habitat-ai/plugin-cli",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",
@@ -29,7 +29,7 @@
29
29
  "test": "vitest run --project plugin-habitat"
30
30
  },
31
31
  "dependencies": {
32
- "@habitat-ai/service": "0.2.3",
32
+ "@habitat-ai/service": "0.2.4",
33
33
  "@oclif/core": "^4.11.4"
34
34
  },
35
35
  "devDependencies": {