@contenthero/cli 0.3.4 → 0.3.5

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/index.js CHANGED
@@ -12,12 +12,37 @@ import pc from 'picocolors';
12
12
  import { buildProgram } from './program.js';
13
13
  import { EXIT, exitCodeForError, messageForError } from './errors.js';
14
14
  import { releaseCliPresence } from './context.js';
15
+ /**
16
+ * Exit only once stdout has actually reached the OS.
17
+ *
18
+ * `process.exit()` does NOT flush buffered stdout, and Node's stdout is ASYNCHRONOUS when
19
+ * it is a pipe (it is synchronous for files and TTYs, which is why this never showed up
20
+ * by hand). So a command whose output exceeds the 64KB pipe buffer had the remainder
21
+ * discarded the moment we exited.
22
+ *
23
+ * Measured on cli 0.3.4: `contenthero schema` wrote 93,998 bytes to a file and 65,536
24
+ * bytes through a pipe. The whole point of `schema` is that an agent can discover the
25
+ * command surface, and agents read through pipes, so every agent calling it received
26
+ * truncated JSON that could not be parsed. Any command whose output crosses 64KB was
27
+ * affected, not just this one.
28
+ *
29
+ * Setting `process.exitCode` and returning would also fix the truncation, but it leaves
30
+ * the process alive until every handle closes, and an HTTP keep-alive socket can hold it
31
+ * open for seconds after the work is done. Draining first and then exiting keeps the
32
+ * immediate exit and loses nothing.
33
+ */
34
+ async function exitAfterFlush(code) {
35
+ if (process.stdout.writableLength > 0) {
36
+ await new Promise((resolve) => process.stdout.write('', () => resolve()));
37
+ }
38
+ process.exit(code);
39
+ }
15
40
  async function main() {
16
41
  const program = buildProgram();
17
42
  // Bare invocation: show help and exit cleanly rather than erroring.
18
43
  if (process.argv.slice(2).length === 0) {
19
44
  program.outputHelp();
20
- process.exit(EXIT.OK);
45
+ await exitAfterFlush(EXIT.OK);
21
46
  }
22
47
  // Compute the exit code, then release editor presence BEFORE exiting (process.exit would skip a finally), so
23
48
  // an open editor's "Editing via CLI" badge clears immediately rather than lingering on the sliding TTL.
@@ -43,7 +68,7 @@ async function main() {
43
68
  }
44
69
  }
45
70
  await releaseCliPresence().catch(() => { });
46
- process.exit(exitCode);
71
+ await exitAfterFlush(exitCode);
47
72
  }
48
73
  void main();
49
74
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;;;;;;GAOG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAC1C,OAAO,EAAE,MAAM,YAAY,CAAA;AAC3B,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,EAAE,IAAI,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AACrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AAEjD,KAAK,UAAU,IAAI;IACjB,MAAM,OAAO,GAAG,YAAY,EAAE,CAAA;IAE9B,oEAAoE;IACpE,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvC,OAAO,CAAC,UAAU,EAAE,CAAA;QACpB,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IACvB,CAAC;IAED,6GAA6G;IAC7G,wGAAwG;IACxG,IAAI,QAAQ,GAAW,IAAI,CAAC,EAAE,CAAA;IAC9B,IAAI,CAAC;QACH,MAAM,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;IACxC,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,8EAA8E;QAC9E,kEAAkE;QAClE,IAAI,GAAG,YAAY,cAAc,EAAE,CAAC;YAClC,QAAQ,GAAG,GAAG,CAAC,QAAQ,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAA;QACtD,CAAC;aAAM,CAAC;YACN,QAAQ,GAAG,gBAAgB,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,SAAS,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,CAAA;YAC9F,CAAC;QACH,CAAC;IACH,CAAC;IAED,MAAM,kBAAkB,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAA;IAC1C,MAAM,cAAc,CAAC,QAAQ,CAAC,CAAA;AAChC,CAAC;AAED,KAAK,IAAI,EAAE,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contenthero/cli",
3
- "version": "0.3.4",
3
+ "version": "0.3.5",
4
4
  "description": "Official ContentHero CLI. Generate media, run the content pipeline, and read your brand/research context from the terminal or any agent shell. Rides the @contenthero/sdk kernel.",
5
5
  "type": "module",
6
6
  "bin": {