@yaag/cli 0.1.2 → 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.
Files changed (41) hide show
  1. package/assets/types/runtime/agent.d.ts +4 -2
  2. package/assets/types/runtime/ask-contract-identity.d.ts +11 -2
  3. package/assets/types/runtime/ask-exchange-events.d.ts +11 -1
  4. package/assets/types/runtime/ask-exchange-options.d.ts +7 -2
  5. package/assets/types/runtime/ask-hash.d.ts +4 -3
  6. package/assets/types/runtime/ask-limit.d.ts +2 -0
  7. package/assets/types/runtime/ask-output-steering.d.ts +0 -2
  8. package/assets/types/runtime/ask-output.d.ts +16 -4
  9. package/assets/types/runtime/ask-turn.d.ts +5 -0
  10. package/assets/types/runtime/cassette-loader.d.ts +10 -0
  11. package/assets/types/runtime/cassette-schema.d.ts +9 -1
  12. package/assets/types/runtime/cassette.d.ts +4 -2
  13. package/assets/types/runtime/checkpoint-flush.d.ts +31 -0
  14. package/assets/types/runtime/connection.d.ts +12 -0
  15. package/assets/types/runtime/define-agent.d.ts +10 -5
  16. package/assets/types/runtime/errors.d.ts +7 -1
  17. package/assets/types/runtime/events.d.ts +24 -2
  18. package/assets/types/runtime/fake-transport.d.ts +10 -0
  19. package/assets/types/runtime/frame-queue.d.ts +2 -0
  20. package/assets/types/runtime/index.d.ts +3 -2
  21. package/assets/types/runtime/model-resolution.d.ts +45 -0
  22. package/assets/types/runtime/model-suffix.d.ts +16 -0
  23. package/assets/types/runtime/pi-state.d.ts +16 -0
  24. package/assets/types/runtime/report-result-extension.d.ts +44 -0
  25. package/assets/types/runtime/report-result-output.d.ts +37 -0
  26. package/assets/types/runtime/report-result-steering.d.ts +35 -0
  27. package/assets/types/runtime/report-result.d.ts +66 -0
  28. package/assets/types/runtime/run-checkpoint.d.ts +35 -13
  29. package/assets/types/runtime/run.d.ts +3 -2
  30. package/assets/types/runtime/stall-watchdog.d.ts +70 -0
  31. package/assets/types/runtime/summary-agent.d.ts +7 -1
  32. package/assets/types/runtime/summary.d.ts +10 -0
  33. package/assets/types/runtime/thinking-level.d.ts +11 -0
  34. package/assets/types/runtime/transport.d.ts +41 -4
  35. package/assets/types/runtime/types.d.ts +49 -14
  36. package/package.json +5 -5
  37. package/src/cli.ts +19 -10
  38. package/src/interactive-run.ts +3 -2
  39. package/src/output-channel.ts +35 -0
  40. package/src/presenter.ts +2 -1
  41. package/src/runtime-alias.ts +6 -8
@@ -15,6 +15,7 @@ import type { RunViewResult, TreeState } from "@yaag/tui";
15
15
  import { createAltScreen } from "./alt-screen.ts";
16
16
  import { createFatalSignal, type FatalExit, type FatalSignal } from "./fatal-signal.ts";
17
17
  import { finalFrame } from "./final-frame.ts";
18
+ import { writeChannel } from "./output-channel.ts";
18
19
  import { createPlainPresenter } from "./presenter.ts";
19
20
  import { errorText, executeOptions, formatResult, type RunFlags } from "./run-invocation.ts";
20
21
  import { type FinalOutput, startTreeApp, type TreeApp } from "./tree-app.ts";
@@ -146,8 +147,8 @@ export async function runInteractive(options: InteractiveRunOptions): Promise<nu
146
147
  startTreeApp({
147
148
  tui: createAltScreen(),
148
149
  stop,
149
- writeStdout: (text) => process.stdout.write(text),
150
- writeStderr: (text) => process.stderr.write(text),
150
+ writeStdout: (text) => writeChannel(process.stdout, text),
151
+ writeStderr: (text) => writeChannel(process.stderr, text),
151
152
  }),
152
153
  startRun: (events, signal) =>
153
154
  executeRun(options.program, executeOptions(options.flags, options.events(events), signal)),
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Best-effort writes to the Run's output channels (architecture §9, ADR-0031).
3
+ *
4
+ * The Orchestrator is detached from its Host Session. When that session dies,
5
+ * stdout, stderr, and the events descriptor become broken pipes. A write to a
6
+ * broken pipe must not end the Run: it becomes a no-op, the Run keeps going as
7
+ * an Orphaned Run, and `yaag_stop` remains the way to end one.
8
+ */
9
+ import { writeSync } from "node:fs";
10
+
11
+ const silenced = new WeakSet<NodeJS.WriteStream>();
12
+
13
+ /** Writes one chunk to a stream; a broken or failed pipe is ignored. */
14
+ export function writeChannel(stream: NodeJS.WriteStream, text: string): void {
15
+ // A stream reports a broken pipe asynchronously, and an unheard `error`
16
+ // event ends the process. One no-op listener per stream absorbs it.
17
+ if (!silenced.has(stream)) {
18
+ silenced.add(stream);
19
+ stream.on("error", () => {});
20
+ }
21
+ try {
22
+ stream.write(text);
23
+ } catch {
24
+ // The Host Session closed the pipe; the Run continues without an observer.
25
+ }
26
+ }
27
+
28
+ /** Writes one whole line to a descriptor; a broken or failed pipe is ignored. */
29
+ export function writeChannelFd(fd: number, text: string): void {
30
+ try {
31
+ writeSync(fd, text);
32
+ } catch {
33
+ // The Host Session closed the descriptor; the Run continues without an observer.
34
+ }
35
+ }
package/src/presenter.ts CHANGED
@@ -5,6 +5,7 @@
5
5
  * gets the interactive alt-screen tree instead (`tree-app.ts`).
6
6
  */
7
7
  import type { StampedEventSink } from "@yaag/runtime";
8
+ import { writeChannel } from "./output-channel.ts";
8
9
  import { type PlainRenderMode, renderEvent } from "./render.ts";
9
10
 
10
11
  /**
@@ -24,7 +25,7 @@ export function createPlainPresenter(quiet: boolean): EventPresenter {
24
25
  return {
25
26
  present: (event) => {
26
27
  const rendered = renderEvent(event, mode);
27
- if (rendered !== null) process.stderr.write(`${rendered}\n`);
28
+ if (rendered !== null) writeChannel(process.stderr, `${rendered}\n`);
28
29
  },
29
30
  dispose: () => {},
30
31
  };
@@ -1,11 +1,3 @@
1
- import { fileURLToPath } from "node:url";
2
-
3
- const runtimeEntry = fileURLToPath(
4
- new URL("../../../packages/runtime/src/index.ts", import.meta.url),
5
- );
6
- const typeboxEntry = fileURLToPath(
7
- new URL("../node_modules/typebox/build/index.mjs", import.meta.url),
8
- );
9
1
  const runtimeValues = [
10
2
  "CASSETTE_VERSION",
11
3
  "loadCassette",
@@ -39,6 +31,12 @@ let registered = false;
39
31
  */
40
32
  export function registerRuntimeAlias(): void {
41
33
  if (registered) return;
34
+ // Resolved from this CLI package (ADR-0018), so each entry is the same copy
35
+ // the CLI itself imports in the monorepo layout and in the published npm
36
+ // layout, where typebox is hoisted and no packages/ sibling exists. A
37
+ // failure here means a corrupt CLI install, so Bun's ResolveMessage stands.
38
+ const runtimeEntry = Bun.resolveSync("@yaag/runtime", import.meta.dir);
39
+ const typeboxEntry = Bun.resolveSync("typebox", import.meta.dir);
42
40
  Bun.plugin({
43
41
  name: "yaag-runtime-entry-alias",
44
42
  setup(build) {