@humain/terminal 0.0.7 → 0.0.10

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 (120) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/README.md +7 -6
  3. package/dist/bundle/chunks/chunk-74NVHVNZ.js +16 -0
  4. package/dist/bundle/chunks/{chunk-M2GYSCCG.js → chunk-PSKDLDLZ.js} +1 -1
  5. package/dist/bundle/chunks/{chunk-HNVPY4LZ.js → chunk-SCJNLX2E.js} +94 -103
  6. package/dist/bundle/chunks/{google-generative-ai-XT7NQJ2E.js → google-generative-ai-FF7M7XHT.js} +1 -1
  7. package/dist/bundle/chunks/{google-vertex-IDQ6Z53W.js → google-vertex-YMUBFRBA.js} +1 -1
  8. package/dist/bundle/chunks/https-proxy-agent-562J2I52.js +2 -0
  9. package/dist/bundle/chunks/{mistral-conversations-HHDZ4FHR.js → mistral-conversations-O4M7IQML.js} +1 -1
  10. package/dist/bundle/chunks/{openai-completions-6QBYTBXY.js → openai-completions-L4AHDQ5D.js} +1 -1
  11. package/dist/bundle/cli.js +1 -1
  12. package/dist/bundle/index.js +1 -1
  13. package/dist/bundle/rpc-entry.js +1 -1
  14. package/dist/cli/startup-ui.d.ts.map +1 -1
  15. package/dist/cli/startup-ui.js +2 -1
  16. package/dist/cli/startup-ui.js.map +1 -1
  17. package/dist/core/agent-session.d.ts +12 -1
  18. package/dist/core/agent-session.d.ts.map +1 -1
  19. package/dist/core/agent-session.js +77 -9
  20. package/dist/core/agent-session.js.map +1 -1
  21. package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
  22. package/dist/core/compaction/branch-summarization.js +4 -3
  23. package/dist/core/compaction/branch-summarization.js.map +1 -1
  24. package/dist/core/compaction/compaction.d.ts +5 -0
  25. package/dist/core/compaction/compaction.d.ts.map +1 -1
  26. package/dist/core/compaction/compaction.js +19 -5
  27. package/dist/core/compaction/compaction.js.map +1 -1
  28. package/dist/core/extensions/index.d.ts +1 -1
  29. package/dist/core/extensions/index.d.ts.map +1 -1
  30. package/dist/core/extensions/index.js.map +1 -1
  31. package/dist/core/extensions/runner.d.ts +5 -0
  32. package/dist/core/extensions/runner.d.ts.map +1 -1
  33. package/dist/core/extensions/runner.js +44 -1
  34. package/dist/core/extensions/runner.js.map +1 -1
  35. package/dist/core/extensions/types.d.ts +18 -1
  36. package/dist/core/extensions/types.d.ts.map +1 -1
  37. package/dist/core/extensions/types.js.map +1 -1
  38. package/dist/core/session-manager.d.ts.map +1 -1
  39. package/dist/core/session-manager.js +4 -2
  40. package/dist/core/session-manager.js.map +1 -1
  41. package/dist/core/settings-manager.d.ts +8 -1
  42. package/dist/core/settings-manager.d.ts.map +1 -1
  43. package/dist/core/settings-manager.js +17 -0
  44. package/dist/core/settings-manager.js.map +1 -1
  45. package/dist/extensions/llama/client.d.ts +6 -0
  46. package/dist/extensions/llama/client.d.ts.map +1 -1
  47. package/dist/extensions/llama/client.js +7 -0
  48. package/dist/extensions/llama/client.js.map +1 -1
  49. package/dist/extensions/llama/provider.d.ts +3 -1
  50. package/dist/extensions/llama/provider.d.ts.map +1 -1
  51. package/dist/extensions/llama/provider.js +27 -6
  52. package/dist/extensions/llama/provider.js.map +1 -1
  53. package/dist/humain/agent-execution-failure.d.ts +4 -0
  54. package/dist/humain/agent-execution-failure.d.ts.map +1 -0
  55. package/dist/humain/agent-execution-failure.js +58 -0
  56. package/dist/humain/agent-execution-failure.js.map +1 -0
  57. package/dist/humain/agent-execution-runtime.d.ts +2 -2
  58. package/dist/humain/agent-execution-runtime.d.ts.map +1 -1
  59. package/dist/humain/agent-execution-runtime.js +13 -5
  60. package/dist/humain/agent-execution-runtime.js.map +1 -1
  61. package/dist/humain/mcp-adapter/vendor/package.json +2 -2
  62. package/dist/humain/pi-agent-execution-host.d.ts +1 -0
  63. package/dist/humain/pi-agent-execution-host.d.ts.map +1 -1
  64. package/dist/humain/pi-agent-execution-host.js +10 -3
  65. package/dist/humain/pi-agent-execution-host.js.map +1 -1
  66. package/dist/index.d.ts +2 -1
  67. package/dist/index.d.ts.map +1 -1
  68. package/dist/index.js +1 -0
  69. package/dist/index.js.map +1 -1
  70. package/dist/main.d.ts.map +1 -1
  71. package/dist/main.js +2 -0
  72. package/dist/main.js.map +1 -1
  73. package/dist/modes/interactive/components/settings-selector.d.ts +2 -0
  74. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  75. package/dist/modes/interactive/components/settings-selector.js +10 -0
  76. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  77. package/dist/modes/interactive/interactive-mode.d.ts +4 -0
  78. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  79. package/dist/modes/interactive/interactive-mode.js +48 -24
  80. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  81. package/dist/modes/rpc/jsonl.d.ts +6 -1
  82. package/dist/modes/rpc/jsonl.d.ts.map +1 -1
  83. package/dist/modes/rpc/jsonl.js +38 -11
  84. package/dist/modes/rpc/jsonl.js.map +1 -1
  85. package/dist/modes/rpc/rpc-client.d.ts +7 -0
  86. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  87. package/dist/modes/rpc/rpc-client.js +7 -0
  88. package/dist/modes/rpc/rpc-client.js.map +1 -1
  89. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  90. package/dist/modes/rpc/rpc-mode.js +99 -4
  91. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  92. package/dist/modes/rpc/rpc-types.d.ts +12 -0
  93. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  94. package/dist/modes/rpc/rpc-types.js.map +1 -1
  95. package/dist/utils/shell.d.ts.map +1 -1
  96. package/dist/utils/shell.js +6 -4
  97. package/dist/utils/shell.js.map +1 -1
  98. package/docs/compaction.md +2 -0
  99. package/docs/custom-provider.md +7 -7
  100. package/docs/environment-variables.md +4 -1
  101. package/docs/extensions.md +18 -0
  102. package/docs/keybindings.md +1 -1
  103. package/docs/quickstart.md +1 -1
  104. package/docs/rpc.md +23 -0
  105. package/docs/settings.md +12 -4
  106. package/docs/terminal-setup.md +12 -0
  107. package/docs/usage.md +4 -3
  108. package/examples/extensions/custom-provider-anthropic/package-lock.json +6 -6
  109. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  110. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  111. package/examples/extensions/gondolin/package-lock.json +2 -2
  112. package/examples/extensions/gondolin/package.json +1 -1
  113. package/examples/extensions/sandbox/package-lock.json +2 -2
  114. package/examples/extensions/sandbox/package.json +1 -1
  115. package/examples/extensions/with-deps/package-lock.json +2 -2
  116. package/examples/extensions/with-deps/package.json +1 -1
  117. package/npm-shrinkwrap.json +27 -26
  118. package/package.json +8 -8
  119. package/dist/bundle/chunks/chunk-3D3G2X5U.js +0 -6
  120. package/dist/bundle/chunks/dist-7DSXV2TY.js +0 -9
@@ -6,6 +6,11 @@ import type { Readable } from "node:stream";
6
6
  * U+2028 and U+2029. Clients must split records on `\n` only.
7
7
  */
8
8
  export declare function serializeJsonLine(value: unknown): string;
9
+ export interface JsonlLineReaderOptions {
10
+ /** Maximum UTF-16 characters retained for one line. Oversized lines are discarded through the next LF. */
11
+ maxLineLength: number;
12
+ onLineTooLong(): void;
13
+ }
9
14
  /**
10
15
  * Attach an LF-only JSONL reader to a stream.
11
16
  *
@@ -13,5 +18,5 @@ export declare function serializeJsonLine(value: unknown): string;
13
18
  * Unicode separators that are valid inside JSON strings and therefore does not
14
19
  * implement strict JSONL framing.
15
20
  */
16
- export declare function attachJsonlLineReader(stream: Readable, onLine: (line: string) => void): () => void;
21
+ export declare function attachJsonlLineReader(stream: Readable, onLine: (line: string) => void, options?: JsonlLineReaderOptions): () => void;
17
22
  //# sourceMappingURL=jsonl.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"jsonl.d.ts","sourceRoot":"","sources":["../../../src/modes/rpc/jsonl.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAG5C;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAExD;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,GAAG,MAAM,IAAI,CAqClG"}
1
+ {"version":3,"file":"jsonl.d.ts","sourceRoot":"","sources":["../../../src/modes/rpc/jsonl.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAG5C;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAExD;AAED,MAAM,WAAW,sBAAsB;IACtC,0GAA0G;IAC1G,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,IAAI,IAAI,CAAC;CACtB;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACpC,MAAM,EAAE,QAAQ,EAChB,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,EAC9B,OAAO,CAAC,EAAE,sBAAsB,GAC9B,MAAM,IAAI,CA+DZ"}
@@ -15,26 +15,53 @@ export function serializeJsonLine(value) {
15
15
  * Unicode separators that are valid inside JSON strings and therefore does not
16
16
  * implement strict JSONL framing.
17
17
  */
18
- export function attachJsonlLineReader(stream, onLine) {
18
+ export function attachJsonlLineReader(stream, onLine, options) {
19
+ if (options && (!Number.isSafeInteger(options.maxLineLength) || options.maxLineLength < 1)) {
20
+ throw new TypeError("JSONL line limit must be a positive integer");
21
+ }
19
22
  const decoder = new StringDecoder("utf8");
20
23
  let buffer = "";
24
+ let discardingOversizedLine = false;
21
25
  const emitLine = (line) => {
22
26
  onLine(line.endsWith("\r") ? line.slice(0, -1) : line);
23
27
  };
24
- const onData = (chunk) => {
25
- buffer += typeof chunk === "string" ? chunk : decoder.write(chunk);
26
- while (true) {
27
- const newlineIndex = buffer.indexOf("\n");
28
- if (newlineIndex === -1) {
29
- return;
28
+ const consume = (text) => {
29
+ let offset = 0;
30
+ while (offset < text.length) {
31
+ const newlineIndex = text.indexOf("\n", offset);
32
+ if (discardingOversizedLine) {
33
+ if (newlineIndex === -1)
34
+ return;
35
+ discardingOversizedLine = false;
36
+ offset = newlineIndex + 1;
37
+ continue;
30
38
  }
31
- emitLine(buffer.slice(0, newlineIndex));
32
- buffer = buffer.slice(newlineIndex + 1);
39
+ const end = newlineIndex === -1 ? text.length : newlineIndex;
40
+ const segmentLength = end - offset;
41
+ if (options && buffer.length + segmentLength > options.maxLineLength) {
42
+ buffer = "";
43
+ options.onLineTooLong();
44
+ if (newlineIndex === -1) {
45
+ discardingOversizedLine = true;
46
+ return;
47
+ }
48
+ offset = newlineIndex + 1;
49
+ continue;
50
+ }
51
+ buffer += text.slice(offset, end);
52
+ if (newlineIndex === -1)
53
+ return;
54
+ emitLine(buffer);
55
+ buffer = "";
56
+ offset = newlineIndex + 1;
33
57
  }
34
58
  };
59
+ const onData = (chunk) => {
60
+ consume(typeof chunk === "string" ? chunk : decoder.write(chunk));
61
+ };
35
62
  const onEnd = () => {
36
- buffer += decoder.end();
37
- if (buffer.length > 0) {
63
+ consume(decoder.end());
64
+ if (!discardingOversizedLine && buffer.length > 0) {
38
65
  emitLine(buffer);
39
66
  buffer = "";
40
67
  }
@@ -1 +1 @@
1
- {"version":3,"file":"jsonl.js","sourceRoot":"","sources":["../../../src/modes/rpc/jsonl.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAc;IAC/C,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC;AACrC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,CAAC,MAAgB,EAAE,MAA8B;IACrF,MAAM,OAAO,GAAG,IAAI,aAAa,CAAC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E,MAAM,CAAC,CAAC;QAC3B,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IAC1B,CAAC,CAAC;AACH,CAAC","sourcesContent":["import type { Readable } from \"node:stream\";\nimport { StringDecoder } from \"node:string_decoder\";\n\n/**\n * Serialize a single strict JSONL record.\n *\n * Framing is LF-only. Payload strings may contain other Unicode separators such as\n * U+2028 and U+2029. Clients must split records on `\\n` only.\n */\nexport function serializeJsonLine(value: unknown): string {\n\treturn `${JSON.stringify(value)}\\n`;\n}\n\n/**\n * Attach an LF-only JSONL reader to a stream.\n *\n * This intentionally does not use Node readline. Readline splits on additional\n * Unicode separators that are valid inside JSON strings and therefore does not\n * implement strict JSONL framing.\n */\nexport function attachJsonlLineReader(stream: Readable, onLine: (line: string) => void): () => void {\n\tconst decoder = new StringDecoder(\"utf8\");\n\tlet buffer = \"\";\n\n\tconst emitLine = (line: string) => {\n\t\tonLine(line.endsWith(\"\\r\") ? line.slice(0, -1) : line);\n\t};\n\n\tconst onData = (chunk: string | Buffer) => {\n\t\tbuffer += typeof chunk === \"string\" ? chunk : decoder.write(chunk);\n\n\t\twhile (true) {\n\t\t\tconst newlineIndex = buffer.indexOf(\"\\n\");\n\t\t\tif (newlineIndex === -1) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\temitLine(buffer.slice(0, newlineIndex));\n\t\t\tbuffer = buffer.slice(newlineIndex + 1);\n\t\t}\n\t};\n\n\tconst onEnd = () => {\n\t\tbuffer += decoder.end();\n\t\tif (buffer.length > 0) {\n\t\t\temitLine(buffer);\n\t\t\tbuffer = \"\";\n\t\t}\n\t};\n\n\tstream.on(\"data\", onData);\n\tstream.on(\"end\", onEnd);\n\n\treturn () => {\n\t\tstream.off(\"data\", onData);\n\t\tstream.off(\"end\", onEnd);\n\t};\n}\n"]}
1
+ {"version":3,"file":"jsonl.js","sourceRoot":"","sources":["../../../src/modes/rpc/jsonl.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAA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CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1B,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IAExB,OAAO,GAAG,EAAE;QACX,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC3B,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IAC1B,CAAC,CAAC;AACH,CAAC","sourcesContent":["import type { Readable } from \"node:stream\";\nimport { StringDecoder } from \"node:string_decoder\";\n\n/**\n * Serialize a single strict JSONL record.\n *\n * Framing is LF-only. Payload strings may contain other Unicode separators such as\n * U+2028 and U+2029. Clients must split records on `\\n` only.\n */\nexport function serializeJsonLine(value: unknown): string {\n\treturn `${JSON.stringify(value)}\\n`;\n}\n\nexport interface JsonlLineReaderOptions {\n\t/** Maximum UTF-16 characters retained for one line. Oversized lines are discarded through the next LF. */\n\tmaxLineLength: number;\n\tonLineTooLong(): void;\n}\n\n/**\n * Attach an LF-only JSONL reader to a stream.\n *\n * This intentionally does not use Node readline. Readline splits on additional\n * Unicode separators that are valid inside JSON strings and therefore does not\n * implement strict JSONL framing.\n */\nexport function attachJsonlLineReader(\n\tstream: Readable,\n\tonLine: (line: string) => void,\n\toptions?: JsonlLineReaderOptions,\n): () => void {\n\tif (options && (!Number.isSafeInteger(options.maxLineLength) || options.maxLineLength < 1)) {\n\t\tthrow new TypeError(\"JSONL line limit must be a positive integer\");\n\t}\n\tconst decoder = new StringDecoder(\"utf8\");\n\tlet buffer = \"\";\n\tlet discardingOversizedLine = false;\n\n\tconst emitLine = (line: string) => {\n\t\tonLine(line.endsWith(\"\\r\") ? line.slice(0, -1) : line);\n\t};\n\n\tconst consume = (text: string) => {\n\t\tlet offset = 0;\n\t\twhile (offset < text.length) {\n\t\t\tconst newlineIndex = text.indexOf(\"\\n\", offset);\n\t\t\tif (discardingOversizedLine) {\n\t\t\t\tif (newlineIndex === -1) return;\n\t\t\t\tdiscardingOversizedLine = false;\n\t\t\t\toffset = newlineIndex + 1;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst end = newlineIndex === -1 ? text.length : newlineIndex;\n\t\t\tconst segmentLength = end - offset;\n\t\t\tif (options && buffer.length + segmentLength > options.maxLineLength) {\n\t\t\t\tbuffer = \"\";\n\t\t\t\toptions.onLineTooLong();\n\t\t\t\tif (newlineIndex === -1) {\n\t\t\t\t\tdiscardingOversizedLine = true;\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\toffset = newlineIndex + 1;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tbuffer += text.slice(offset, end);\n\t\t\tif (newlineIndex === -1) return;\n\t\t\temitLine(buffer);\n\t\t\tbuffer = \"\";\n\t\t\toffset = newlineIndex + 1;\n\t\t}\n\t};\n\n\tconst onData = (chunk: string | Buffer) => {\n\t\tconsume(typeof chunk === \"string\" ? chunk : decoder.write(chunk));\n\t};\n\n\tconst onEnd = () => {\n\t\tconsume(decoder.end());\n\t\tif (!discardingOversizedLine && buffer.length > 0) {\n\t\t\temitLine(buffer);\n\t\t\tbuffer = \"\";\n\t\t}\n\t};\n\n\tstream.on(\"data\", onData);\n\tstream.on(\"end\", onEnd);\n\n\treturn () => {\n\t\tstream.off(\"data\", onData);\n\t\tstream.off(\"end\", onEnd);\n\t};\n}\n"]}
@@ -83,6 +83,13 @@ export declare class RpcClient {
83
83
  * Abort current operation.
84
84
  */
85
85
  abort(): Promise<void>;
86
+ /**
87
+ * Clear queued steering and follow-up messages, returning their text.
88
+ */
89
+ clearQueue(): Promise<{
90
+ steering: string[];
91
+ followUp: string[];
92
+ }>;
86
93
  /**
87
94
  * Start a new session, optionally with parent tracking.
88
95
  * @param parentSession - Optional parent session path for lineage tracking
@@ -1 +1 @@
1
- {"version":3,"file":"rpc-client.d.ts","sourceRoot":"","sources":["../../../src/modes/rpc/rpc-client.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,YAA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O,SAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAe1C;IAED;;OAEG;IACH,aAAa,CAAC,OAAO,SAAQ,GAAG,OAAO,CAAC,qBAAqB,EAAE,CAAC,CAkB/D;IAED;;OAEG;IACG,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,YAAY,EAAE,EAAE,OAAO,SAAQ,GAAG,OAAO,CAAC,qBAAqB,EAAE,CAAC,CAI/G;IAMD,OAAO,CAAC,UAAU;IA8BlB,OAAO,CAAC,kBAAkB;IAM1B,OAAO,CAAC,sBAAsB;IAI9B,OAAO,CAAC,qBAAqB;YAOf,IAAI;IAmDlB,OAAO,CAAC,OAAO;CAUf"}
@@ -190,6 +190,13 @@ export class RpcClient {
190
190
  async abort() {
191
191
  await this.send({ type: "abort" });
192
192
  }
193
+ /**
194
+ * Clear queued steering and follow-up messages, returning their text.
195
+ */
196
+ async clearQueue() {
197
+ const response = await this.send({ type: "clear_queue" });
198
+ return this.getData(response);
199
+ }
193
200
  /**
194
201
  * Start a new session, optionally with parent tracking.
195
202
  * @param parentSession - Optional parent session path for lineage tracking
@@ -1 +1 @@
1
- {"version":3,"file":"rpc-client.js","sourceRoot":"","sources":["../../../src/modes/rpc/rpc-client.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAqB,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAG9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAMnE,OAAO,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAwCtE,+EAA+E;AAC/E,aAAa;AACb,+EAA+E;AAE/E,MAAM,OAAO,SAAS;IAgBrB,YAAY,OAAO,GAAqB,EAAE;QAflC,YAAO,GAAwB,IAAI,CAAC;QACpC,sBAAiB,GAAwB,IAAI,CAAC;QAC9C,mBAAc,GAAuB,EAAE,CAAC;QACxC,eAAU,GAAyB,IAAI,CAAC;QACxC,iBAAY,GAGf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B,MAAM,CAAC,KAAK,CAAC,CAAC;gBACf,CAAC;aACD,CAAC,CAAC;YAEH,IAAI,CAAC;gBACJ,KAAK,CAAC,KAAK,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC,CAAC;YAC7C,CAAC;YAAC,OAAO,KAAc,EAAE,CAAC;gBACzB,MAAM,UAAU,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;gBAC7E,MAAM,OAAO,GAAG,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;gBAC7C,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;gBAChC,OAAO,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC;YAC7B,CAAC;QACF,CAAC,CAAC,CAAC;IACJ,CAAC;IAEO,OAAO,CAAI,QAAqB;QACvC,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;YACvB,MAAM,aAAa,GAAG,QAAoD,CAAC;YAC3E,MAAM,IAAI,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QACtC,CAAC;QACD,8EAA8E;QAC9E,mFAAmF;QACnF,MAAM,eAAe,GAAG,QAAkE,CAAC;QAC3F,OAAO,eAAe,CAAC,IAAS,CAAC;IAClC,CAAC;CACD","sourcesContent":["/**\n * RPC Client for programmatic access to the coding agent.\n *\n * Spawns the agent in RPC mode and provides a typed API for all operations.\n */\n\nimport { type ChildProcess, spawn } from \"node:child_process\";\nimport type { AgentMessage, ThinkingLevel } from \"@earendil-works/pi-agent-core\";\nimport type { ImageContent } from \"@earendil-works/pi-ai\";\nimport { parseRpcWireFrame } from \"@humain/terminal-contracts/rpc\";\nimport type { SessionStats } from \"../../core/agent-session.ts\";\nimport type { BashResult } from \"../../core/bash-executor.ts\";\nimport type { CompactionResult } from \"../../core/compaction/index.ts\";\nimport type { SessionEntry, SessionTreeNode } from \"../../core/session-manager.ts\";\nimport type { JsonAgentSessionEvent } from \"../json-event.ts\";\nimport { attachJsonlLineReader, serializeJsonLine } from \"./jsonl.ts\";\nimport type { RpcCommand, RpcReadyEvent, RpcResponse, RpcSessionState, RpcSlashCommand } from \"./rpc-types.ts\";\n\n// ============================================================================\n// Types\n// ============================================================================\n\n/** Distributive Omit that works with union types */\ntype DistributiveOmit<T, K extends keyof T> = T extends unknown ? Omit<T, K> : never;\n\n/** RpcCommand without the id field (for internal send) */\ntype RpcCommandBody = DistributiveOmit<RpcCommand, \"id\">;\n\nexport interface RpcClientOptions {\n\t/** Additional Node.js arguments before the CLI entrypoint */\n\tnodeArgs?: string[];\n\t/** Path to the CLI entry point (default: searches for dist/cli.js) */\n\tcliPath?: string;\n\t/** Working directory for the agent */\n\tcwd?: string;\n\t/** Environment variables */\n\tenv?: Record<string, string>;\n\t/** Provider to use */\n\tprovider?: string;\n\t/** Model ID to use */\n\tmodel?: string;\n\t/** Additional CLI arguments */\n\targs?: string[];\n}\n\nexport interface ModelInfo {\n\tprovider: string;\n\tid: string;\n\tcontextWindow: number;\n\treasoning: boolean;\n}\n\nexport type RpcEvent = JsonAgentSessionEvent | RpcReadyEvent;\nexport type RpcEventListener = (event: RpcEvent) => void;\n\n// ============================================================================\n// RPC Client\n// ============================================================================\n\nexport class RpcClient {\n\tprivate process: ChildProcess | null = null;\n\tprivate stopReadingStdout: (() => void) | null = null;\n\tprivate eventListeners: RpcEventListener[] = [];\n\tprivate readyEvent: RpcReadyEvent | null = null;\n\tprivate readyWaiters: Array<{\n\t\tresolve: (event: RpcReadyEvent) => void;\n\t\treject: (error: Error) => void;\n\t}> = [];\n\tprivate pendingRequests: Map<string, { resolve: (response: RpcResponse) => void; reject: (error: Error) => void }> =\n\t\tnew Map();\n\tprivate requestId = 0;\n\tprivate stderr = \"\";\n\tprivate exitError: Error | null = null;\n\tprivate options: RpcClientOptions;\n\n\tconstructor(options: RpcClientOptions = {}) {\n\t\tthis.options = options;\n\t}\n\n\t/**\n\t * Start the RPC agent process.\n\t */\n\tasync start(): Promise<void> {\n\t\tif (this.process) {\n\t\t\tthrow new Error(\"Client already started\");\n\t\t}\n\n\t\tthis.exitError = null;\n\t\tthis.readyEvent = null;\n\n\t\tconst cliPath = this.options.cliPath ?? \"dist/cli.js\";\n\t\tconst args = [\"--mode\", \"rpc\"];\n\n\t\tif (this.options.provider) {\n\t\t\targs.push(\"--provider\", this.options.provider);\n\t\t}\n\t\tif (this.options.model) {\n\t\t\targs.push(\"--model\", this.options.model);\n\t\t}\n\t\tif (this.options.args) {\n\t\t\targs.push(...this.options.args);\n\t\t}\n\n\t\tconst nodeArgs = this.options.nodeArgs ?? [];\n\t\tconst childProcess = spawn(\"node\", [...nodeArgs, cliPath, ...args], {\n\t\t\tcwd: this.options.cwd,\n\t\t\tenv: { ...process.env, ...this.options.env },\n\t\t\tstdio: [\"pipe\", \"pipe\", \"pipe\"],\n\t\t});\n\t\tthis.process = childProcess;\n\n\t\t// Collect stderr for debugging\n\t\tchildProcess.stderr?.on(\"data\", (data) => {\n\t\t\tthis.stderr += data.toString();\n\t\t\tprocess.stderr.write(data);\n\t\t});\n\n\t\tchildProcess.once(\"exit\", (code, signal) => {\n\t\t\tif (this.process !== childProcess) return;\n\t\t\tthis.readyEvent = null;\n\t\t\tconst error = this.createProcessExitError(code, signal);\n\t\t\tthis.exitError = error;\n\t\t\tthis.rejectReadyWaiters(error);\n\t\t\tthis.rejectPendingRequests(error);\n\t\t});\n\t\tchildProcess.once(\"error\", (error) => {\n\t\t\tif (this.process !== childProcess) return;\n\t\t\tthis.readyEvent = null;\n\t\t\tconst processError = new Error(`Agent process error: ${error.message}. Stderr: ${this.stderr}`);\n\t\t\tthis.exitError = processError;\n\t\t\tthis.rejectReadyWaiters(processError);\n\t\t\tthis.rejectPendingRequests(processError);\n\t\t});\n\t\tchildProcess.stdin?.on(\"error\", (error) => {\n\t\t\tif (this.process !== childProcess) return;\n\t\t\tconst stdinError =\n\t\t\t\tthis.exitError ?? new Error(`Agent process stdin error: ${error.message}. Stderr: ${this.stderr}`);\n\t\t\tthis.exitError = stdinError;\n\t\t\tthis.rejectPendingRequests(stdinError);\n\t\t});\n\n\t\t// Set up strict JSONL reader for stdout.\n\t\tthis.stopReadingStdout = attachJsonlLineReader(childProcess.stdout!, (line) => {\n\t\t\tthis.handleLine(line);\n\t\t});\n\n\t\t// Wait a moment for process to initialize\n\t\tawait new Promise((resolve) => setTimeout(resolve, 100));\n\n\t\tif (this.process.exitCode !== null) {\n\t\t\tconst error = this.exitError ?? this.createProcessExitError(this.process.exitCode, this.process.signalCode);\n\t\t\tthis.exitError = error;\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\t/** Wait until runtime initialization and session binding have completed. */\n\tasync waitUntilReady(timeout = 30000): Promise<RpcReadyEvent> {\n\t\tif (this.exitError) throw this.exitError;\n\t\tif (!this.process) throw new Error(\"Client not started\");\n\t\tif (this.readyEvent) return this.readyEvent;\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tconst timer = setTimeout(() => {\n\t\t\t\tconst waiter = this.readyWaiters.find((candidate) => candidate.reject === reject);\n\t\t\t\tif (waiter) this.readyWaiters.splice(this.readyWaiters.indexOf(waiter), 1);\n\t\t\t\treject(new Error(`Timed out waiting for RPC agent readiness. Stderr: ${this.stderr}`));\n\t\t\t}, timeout);\n\t\t\tthis.readyWaiters.push({\n\t\t\t\tresolve: (event) => {\n\t\t\t\t\tclearTimeout(timer);\n\t\t\t\t\tresolve(event);\n\t\t\t\t},\n\t\t\t\treject,\n\t\t\t});\n\t\t});\n\t}\n\n\t/**\n\t * Stop the RPC agent process.\n\t */\n\tasync stop(): Promise<void> {\n\t\tthis.readyEvent = null;\n\t\tif (!this.process) return;\n\t\tconst stopError = new Error(\"Client stopped before the agent process exited\");\n\n\t\tthis.stopReadingStdout?.();\n\t\tthis.stopReadingStdout = null;\n\t\tthis.process.kill(\"SIGTERM\");\n\n\t\t// Wait for process to exit\n\t\tawait new Promise<void>((resolve) => {\n\t\t\tconst timeout = setTimeout(() => {\n\t\t\t\tthis.process?.kill(\"SIGKILL\");\n\t\t\t\tthis.rejectReadyWaiters(stopError);\n\t\t\t\tthis.rejectPendingRequests(stopError);\n\t\t\t\tresolve();\n\t\t\t}, 1000);\n\n\t\t\tthis.process?.on(\"exit\", () => {\n\t\t\t\tclearTimeout(timeout);\n\t\t\t\tresolve();\n\t\t\t});\n\t\t});\n\n\t\tthis.process = null;\n\t\tthis.rejectReadyWaiters(stopError);\n\t\tthis.rejectPendingRequests(stopError);\n\t}\n\n\t/**\n\t * Subscribe to agent events.\n\t */\n\tonEvent(listener: RpcEventListener): () => void {\n\t\tthis.eventListeners.push(listener);\n\t\treturn () => {\n\t\t\tconst index = this.eventListeners.indexOf(listener);\n\t\t\tif (index !== -1) {\n\t\t\t\tthis.eventListeners.splice(index, 1);\n\t\t\t}\n\t\t};\n\t}\n\n\t/**\n\t * Get collected stderr output (useful for debugging).\n\t */\n\tgetStderr(): string {\n\t\treturn this.stderr;\n\t}\n\n\t// =========================================================================\n\t// Command Methods\n\t// =========================================================================\n\n\t/**\n\t * Send a prompt to the agent.\n\t * Returns immediately after sending; use onEvent() to receive streaming events.\n\t * Use waitForIdle() to wait for completion.\n\t */\n\tasync prompt(message: string, images?: ImageContent[]): Promise<void> {\n\t\tawait this.send({ type: \"prompt\", message, images });\n\t}\n\n\t/**\n\t * Queue a steering message to interrupt the agent mid-run.\n\t */\n\tasync steer(message: string, images?: ImageContent[]): Promise<void> {\n\t\tawait this.send({ type: \"steer\", message, images });\n\t}\n\n\t/**\n\t * Queue a follow-up message to be processed after the agent finishes.\n\t */\n\tasync followUp(message: string, images?: ImageContent[]): Promise<void> {\n\t\tawait this.send({ type: \"follow_up\", message, images });\n\t}\n\n\t/**\n\t * Abort current operation.\n\t */\n\tasync abort(): Promise<void> {\n\t\tawait this.send({ type: \"abort\" });\n\t}\n\n\t/**\n\t * Start a new session, optionally with parent tracking.\n\t * @param parentSession - Optional parent session path for lineage tracking\n\t * @returns Object with `cancelled: true` if an extension cancelled the new session\n\t */\n\tasync newSession(parentSession?: string): Promise<{ cancelled: boolean }> {\n\t\tconst response = await this.send({ type: \"new_session\", parentSession });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Get current session state.\n\t */\n\tasync getState(): Promise<RpcSessionState> {\n\t\tconst response = await this.send({ type: \"get_state\" });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Set model by provider and ID.\n\t */\n\tasync setModel(provider: string, modelId: string): Promise<{ provider: string; id: string }> {\n\t\tconst response = await this.send({ type: \"set_model\", provider, modelId });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Cycle to next model.\n\t */\n\tasync cycleModel(): Promise<{\n\t\tmodel: { provider: string; id: string };\n\t\tthinkingLevel: ThinkingLevel;\n\t\tisScoped: boolean;\n\t} | null> {\n\t\tconst response = await this.send({ type: \"cycle_model\" });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Get list of available models.\n\t */\n\tasync getAvailableModels(): Promise<ModelInfo[]> {\n\t\tconst response = await this.send({ type: \"get_available_models\" });\n\t\treturn this.getData<{ models: ModelInfo[] }>(response).models;\n\t}\n\n\t/**\n\t * Set thinking level.\n\t */\n\tasync setThinkingLevel(level: ThinkingLevel): Promise<void> {\n\t\tawait this.send({ type: \"set_thinking_level\", level });\n\t}\n\n\t/**\n\t * Cycle thinking level.\n\t */\n\tasync cycleThinkingLevel(): Promise<{ level: ThinkingLevel } | null> {\n\t\tconst response = await this.send({ type: \"cycle_thinking_level\" });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Get list of available thinking levels for the current model.\n\t */\n\tasync getAvailableThinkingLevels(): Promise<ThinkingLevel[]> {\n\t\tconst response = await this.send({ type: \"get_available_thinking_levels\" });\n\t\treturn this.getData<{ levels: ThinkingLevel[] }>(response).levels;\n\t}\n\n\t/**\n\t * Set steering mode.\n\t */\n\tasync setSteeringMode(mode: \"all\" | \"one-at-a-time\"): Promise<void> {\n\t\tawait this.send({ type: \"set_steering_mode\", mode });\n\t}\n\n\t/**\n\t * Set follow-up mode.\n\t */\n\tasync setFollowUpMode(mode: \"all\" | \"one-at-a-time\"): Promise<void> {\n\t\tawait this.send({ type: \"set_follow_up_mode\", mode });\n\t}\n\n\t/**\n\t * Compact session context.\n\t */\n\tasync compact(customInstructions?: string): Promise<CompactionResult> {\n\t\tconst response = await this.send({ type: \"compact\", customInstructions });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Set auto-compaction enabled/disabled.\n\t */\n\tasync setAutoCompaction(enabled: boolean): Promise<void> {\n\t\tawait this.send({ type: \"set_auto_compaction\", enabled });\n\t}\n\n\t/**\n\t * Set auto-retry enabled/disabled.\n\t */\n\tasync setAutoRetry(enabled: boolean): Promise<void> {\n\t\tawait this.send({ type: \"set_auto_retry\", enabled });\n\t}\n\n\t/**\n\t * Abort in-progress retry.\n\t */\n\tasync abortRetry(): Promise<void> {\n\t\tawait this.send({ type: \"abort_retry\" });\n\t}\n\n\t/**\n\t * Execute a bash command.\n\t */\n\tasync bash(command: string): Promise<BashResult> {\n\t\tconst response = await this.send({ type: \"bash\", command });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Abort running bash command.\n\t */\n\tasync abortBash(): Promise<void> {\n\t\tawait this.send({ type: \"abort_bash\" });\n\t}\n\n\t/**\n\t * Get session statistics.\n\t */\n\tasync getSessionStats(): Promise<SessionStats> {\n\t\tconst response = await this.send({ type: \"get_session_stats\" });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Export session to HTML.\n\t */\n\tasync exportHtml(outputPath?: string): Promise<{ path: string }> {\n\t\tconst response = await this.send({ type: \"export_html\", outputPath });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Switch to a different session file.\n\t * @returns Object with `cancelled: true` if an extension cancelled the switch\n\t */\n\tasync switchSession(sessionPath: string): Promise<{ cancelled: boolean }> {\n\t\tconst response = await this.send({ type: \"switch_session\", sessionPath });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Fork from a specific message.\n\t * @returns Object with `text` (the message text) and `cancelled` (if extension cancelled)\n\t */\n\tasync fork(entryId: string): Promise<{ text: string; cancelled: boolean }> {\n\t\tconst response = await this.send({ type: \"fork\", entryId });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Clone the current active branch into a new session.\n\t * @returns Object with `cancelled: true` if an extension cancelled the clone\n\t */\n\tasync clone(): Promise<{ cancelled: boolean }> {\n\t\tconst response = await this.send({ type: \"clone\" });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Get messages available for forking.\n\t */\n\tasync getForkMessages(): Promise<Array<{ entryId: string; text: string }>> {\n\t\tconst response = await this.send({ type: \"get_fork_messages\" });\n\t\treturn this.getData<{ messages: Array<{ entryId: string; text: string }> }>(response).messages;\n\t}\n\n\t/**\n\t * Get session entries in append order, optionally only those after the `since` entry id.\n\t */\n\tasync getEntries(since?: string): Promise<{ entries: SessionEntry[]; leafId: string | null }> {\n\t\tconst response = await this.send({ type: \"get_entries\", since });\n\t\treturn this.getData<{ entries: SessionEntry[]; leafId: string | null }>(response);\n\t}\n\n\t/**\n\t * Get the session entry tree.\n\t */\n\tasync getTree(): Promise<{ tree: SessionTreeNode[]; leafId: string | null }> {\n\t\tconst response = await this.send({ type: \"get_tree\" });\n\t\treturn this.getData<{ tree: SessionTreeNode[]; leafId: string | null }>(response);\n\t}\n\n\t/**\n\t * Get text of last assistant message.\n\t */\n\tasync getLastAssistantText(): Promise<string | null> {\n\t\tconst response = await this.send({ type: \"get_last_assistant_text\" });\n\t\treturn this.getData<{ text: string | null }>(response).text;\n\t}\n\n\t/**\n\t * Set the session display name.\n\t */\n\tasync setSessionName(name: string): Promise<void> {\n\t\tawait this.send({ type: \"set_session_name\", name });\n\t}\n\n\t/**\n\t * Get all messages in the session.\n\t */\n\tasync getMessages(): Promise<AgentMessage[]> {\n\t\tconst response = await this.send({ type: \"get_messages\" });\n\t\treturn this.getData<{ messages: AgentMessage[] }>(response).messages;\n\t}\n\n\t/**\n\t * Get available commands (extension commands, prompt templates, skills).\n\t */\n\tasync getCommands(): Promise<RpcSlashCommand[]> {\n\t\tconst response = await this.send({ type: \"get_commands\" });\n\t\treturn this.getData<{ commands: RpcSlashCommand[] }>(response).commands;\n\t}\n\n\t// =========================================================================\n\t// Helpers\n\t// =========================================================================\n\n\t/**\n\t * Wait for agent to become idle (no streaming).\n\t * Resolves when agent_settled event is received.\n\t */\n\twaitForIdle(timeout = 60000): Promise<void> {\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tconst timer = setTimeout(() => {\n\t\t\t\tunsubscribe();\n\t\t\t\treject(new Error(`Timeout waiting for agent to become idle. Stderr: ${this.stderr}`));\n\t\t\t}, timeout);\n\n\t\t\tconst unsubscribe = this.onEvent((event) => {\n\t\t\t\tif (event.type === \"agent_settled\") {\n\t\t\t\t\tclearTimeout(timer);\n\t\t\t\t\tunsubscribe();\n\t\t\t\t\tresolve();\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\t}\n\n\t/**\n\t * Collect events until agent becomes idle.\n\t */\n\tcollectEvents(timeout = 60000): Promise<JsonAgentSessionEvent[]> {\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tconst events: JsonAgentSessionEvent[] = [];\n\t\t\tconst timer = setTimeout(() => {\n\t\t\t\tunsubscribe();\n\t\t\t\treject(new Error(`Timeout collecting events. Stderr: ${this.stderr}`));\n\t\t\t}, timeout);\n\n\t\t\tconst unsubscribe = this.onEvent((event) => {\n\t\t\t\tif (event.type === \"ready\") return;\n\t\t\t\tevents.push(event);\n\t\t\t\tif (event.type === \"agent_settled\") {\n\t\t\t\t\tclearTimeout(timer);\n\t\t\t\t\tunsubscribe();\n\t\t\t\t\tresolve(events);\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\t}\n\n\t/**\n\t * Send prompt and wait for completion, returning all events.\n\t */\n\tasync promptAndWait(message: string, images?: ImageContent[], timeout = 60000): Promise<JsonAgentSessionEvent[]> {\n\t\tconst eventsPromise = this.collectEvents(timeout);\n\t\tawait this.prompt(message, images);\n\t\treturn eventsPromise;\n\t}\n\n\t// =========================================================================\n\t// Internal\n\t// =========================================================================\n\n\tprivate handleLine(line: string): void {\n\t\ttry {\n\t\t\tconst data = parseRpcWireFrame(line);\n\n\t\t\tif (data.type === \"ready\") {\n\t\t\t\tthis.readyEvent = data as RpcReadyEvent;\n\t\t\t\tconst waiters = this.readyWaiters;\n\t\t\t\tthis.readyWaiters = [];\n\t\t\t\tfor (const waiter of waiters) waiter.resolve(this.readyEvent);\n\t\t\t\tfor (const listener of this.eventListeners) listener(this.readyEvent);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Check if it's a response to a pending request\n\t\t\tif (data.type === \"response\" && typeof data.id === \"string\" && this.pendingRequests.has(data.id)) {\n\t\t\t\tconst pending = this.pendingRequests.get(data.id)!;\n\t\t\t\tthis.pendingRequests.delete(data.id);\n\t\t\t\tpending.resolve(data as RpcResponse);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Otherwise it's an event\n\t\t\tfor (const listener of this.eventListeners) {\n\t\t\t\tlistener(data as JsonAgentSessionEvent);\n\t\t\t}\n\t\t} catch {\n\t\t\t// Ignore non-JSON lines\n\t\t}\n\t}\n\n\tprivate rejectReadyWaiters(error: Error): void {\n\t\tconst waiters = this.readyWaiters;\n\t\tthis.readyWaiters = [];\n\t\tfor (const waiter of waiters) waiter.reject(error);\n\t}\n\n\tprivate createProcessExitError(code: number | null, signal: NodeJS.Signals | null): Error {\n\t\treturn new Error(`Agent process exited (code=${code} signal=${signal}). Stderr: ${this.stderr}`);\n\t}\n\n\tprivate rejectPendingRequests(error: Error): void {\n\t\tfor (const pending of this.pendingRequests.values()) {\n\t\t\tpending.reject(error);\n\t\t}\n\t\tthis.pendingRequests.clear();\n\t}\n\n\tprivate async send(command: RpcCommandBody): Promise<RpcResponse> {\n\t\tconst childProcess = this.process;\n\t\tconst stdin = childProcess?.stdin;\n\t\tif (!childProcess || !stdin) {\n\t\t\tthrow new Error(\"Client not started\");\n\t\t}\n\t\tif (this.exitError) {\n\t\t\tthrow this.exitError;\n\t\t}\n\t\tif (childProcess.exitCode !== null) {\n\t\t\tconst error = this.createProcessExitError(childProcess.exitCode, childProcess.signalCode);\n\t\t\tthis.exitError = error;\n\t\t\tthrow error;\n\t\t}\n\t\tif (stdin.destroyed || !stdin.writable) {\n\t\t\tconst error = new Error(`Agent process stdin is not writable. Stderr: ${this.stderr}`);\n\t\t\tthis.exitError = error;\n\t\t\tthrow error;\n\t\t}\n\n\t\tconst id = `req_${++this.requestId}`;\n\t\tconst fullCommand = { ...command, id } as RpcCommand;\n\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tconst timeout = setTimeout(() => {\n\t\t\t\tthis.pendingRequests.delete(id);\n\t\t\t\treject(new Error(`Timeout waiting for response to ${command.type}. Stderr: ${this.stderr}`));\n\t\t\t}, 30000);\n\n\t\t\tthis.pendingRequests.set(id, {\n\t\t\t\tresolve: (response) => {\n\t\t\t\t\tclearTimeout(timeout);\n\t\t\t\t\tresolve(response);\n\t\t\t\t},\n\t\t\t\treject: (error) => {\n\t\t\t\t\tclearTimeout(timeout);\n\t\t\t\t\treject(error);\n\t\t\t\t},\n\t\t\t});\n\n\t\t\ttry {\n\t\t\t\tstdin.write(serializeJsonLine(fullCommand));\n\t\t\t} catch (error: unknown) {\n\t\t\t\tconst writeError = error instanceof Error ? error : new Error(String(error));\n\t\t\t\tconst pending = this.pendingRequests.get(id);\n\t\t\t\tthis.pendingRequests.delete(id);\n\t\t\t\tpending?.reject(writeError);\n\t\t\t}\n\t\t});\n\t}\n\n\tprivate getData<T>(response: RpcResponse): T {\n\t\tif (!response.success) {\n\t\t\tconst errorResponse = response as Extract<RpcResponse, { success: false }>;\n\t\t\tthrow new Error(errorResponse.error);\n\t\t}\n\t\t// Type assertion: we trust response.data matches T based on the command sent.\n\t\t// This is safe because each public method specifies the correct T for its command.\n\t\tconst successResponse = response as Extract<RpcResponse, { success: true; data: unknown }>;\n\t\treturn successResponse.data as T;\n\t}\n}\n"]}
1
+ {"version":3,"file":"rpc-client.js","sourceRoot":"","sources":["../../../src/modes/rpc/rpc-client.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAqB,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAG9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAMnE,OAAO,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAwCtE,+EAA+E;AAC/E,aAAa;AACb,+EAA+E;AAE/E,MAAM,OAAO,SAAS;IAgBrB,YAAY,OAAO,GAAqB,EAAE;QAflC,YAAO,GAAwB,IAAI,CAAC;QACpC,sBAAiB,GAAwB,IAAI,CAAC;QAC9C,mBAAc,GAAuB,EAAE,CAAC;QACxC,eAAU,GAAyB,IAAI,CAAC;QACxC,iBAAY,GAGf,EAAE,CAAC;QACA,oBAAe,GACtB,IAAI,GAAG,EAAE,CAAC;QACH,cAAS,GAAG,CAAC,CAAC;QACd,WAAM,GAAG,EAAE,CAAC;QACZ,cAAS,GAAiB,IAAI,CAAC;QAItC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACxB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,KAAK;QACV,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YAClB,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;QAC3C,CAAC;QAED,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QACtB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;QAEvB,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,IAAI,aAAa,CAAC;QACtD,MAAM,IAAI,GAAG,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;QAE/B,IAAI,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE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C,CAAC;gBAC7C,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;gBAChC,OAAO,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC;YAC7B,CAAC;QACF,CAAC,CAAC,CAAC;IACJ,CAAC;IAEO,OAAO,CAAI,QAAqB;QACvC,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;YACvB,MAAM,aAAa,GAAG,QAAoD,CAAC;YAC3E,MAAM,IAAI,KAAK,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QACtC,CAAC;QACD,8EAA8E;QAC9E,mFAAmF;QACnF,MAAM,eAAe,GAAG,QAAkE,CAAC;QAC3F,OAAO,eAAe,CAAC,IAAS,CAAC;IAClC,CAAC;CACD","sourcesContent":["/**\n * RPC Client for programmatic access to the coding agent.\n *\n * Spawns the agent in RPC mode and provides a typed API for all operations.\n */\n\nimport { type ChildProcess, spawn } from \"node:child_process\";\nimport type { AgentMessage, ThinkingLevel } from \"@earendil-works/pi-agent-core\";\nimport type { ImageContent } from \"@earendil-works/pi-ai\";\nimport { parseRpcWireFrame } from \"@humain/terminal-contracts/rpc\";\nimport type { SessionStats } from \"../../core/agent-session.ts\";\nimport type { BashResult } from \"../../core/bash-executor.ts\";\nimport type { CompactionResult } from \"../../core/compaction/index.ts\";\nimport type { SessionEntry, SessionTreeNode } from \"../../core/session-manager.ts\";\nimport type { JsonAgentSessionEvent } from \"../json-event.ts\";\nimport { attachJsonlLineReader, serializeJsonLine } from \"./jsonl.ts\";\nimport type { RpcCommand, RpcReadyEvent, RpcResponse, RpcSessionState, RpcSlashCommand } from \"./rpc-types.ts\";\n\n// ============================================================================\n// Types\n// ============================================================================\n\n/** Distributive Omit that works with union types */\ntype DistributiveOmit<T, K extends keyof T> = T extends unknown ? Omit<T, K> : never;\n\n/** RpcCommand without the id field (for internal send) */\ntype RpcCommandBody = DistributiveOmit<RpcCommand, \"id\">;\n\nexport interface RpcClientOptions {\n\t/** Additional Node.js arguments before the CLI entrypoint */\n\tnodeArgs?: string[];\n\t/** Path to the CLI entry point (default: searches for dist/cli.js) */\n\tcliPath?: string;\n\t/** Working directory for the agent */\n\tcwd?: string;\n\t/** Environment variables */\n\tenv?: Record<string, string>;\n\t/** Provider to use */\n\tprovider?: string;\n\t/** Model ID to use */\n\tmodel?: string;\n\t/** Additional CLI arguments */\n\targs?: string[];\n}\n\nexport interface ModelInfo {\n\tprovider: string;\n\tid: string;\n\tcontextWindow: number;\n\treasoning: boolean;\n}\n\nexport type RpcEvent = JsonAgentSessionEvent | RpcReadyEvent;\nexport type RpcEventListener = (event: RpcEvent) => void;\n\n// ============================================================================\n// RPC Client\n// ============================================================================\n\nexport class RpcClient {\n\tprivate process: ChildProcess | null = null;\n\tprivate stopReadingStdout: (() => void) | null = null;\n\tprivate eventListeners: RpcEventListener[] = [];\n\tprivate readyEvent: RpcReadyEvent | null = null;\n\tprivate readyWaiters: Array<{\n\t\tresolve: (event: RpcReadyEvent) => void;\n\t\treject: (error: Error) => void;\n\t}> = [];\n\tprivate pendingRequests: Map<string, { resolve: (response: RpcResponse) => void; reject: (error: Error) => void }> =\n\t\tnew Map();\n\tprivate requestId = 0;\n\tprivate stderr = \"\";\n\tprivate exitError: Error | null = null;\n\tprivate options: RpcClientOptions;\n\n\tconstructor(options: RpcClientOptions = {}) {\n\t\tthis.options = options;\n\t}\n\n\t/**\n\t * Start the RPC agent process.\n\t */\n\tasync start(): Promise<void> {\n\t\tif (this.process) {\n\t\t\tthrow new Error(\"Client already started\");\n\t\t}\n\n\t\tthis.exitError = null;\n\t\tthis.readyEvent = null;\n\n\t\tconst cliPath = this.options.cliPath ?? \"dist/cli.js\";\n\t\tconst args = [\"--mode\", \"rpc\"];\n\n\t\tif (this.options.provider) {\n\t\t\targs.push(\"--provider\", this.options.provider);\n\t\t}\n\t\tif (this.options.model) {\n\t\t\targs.push(\"--model\", this.options.model);\n\t\t}\n\t\tif (this.options.args) {\n\t\t\targs.push(...this.options.args);\n\t\t}\n\n\t\tconst nodeArgs = this.options.nodeArgs ?? [];\n\t\tconst childProcess = spawn(\"node\", [...nodeArgs, cliPath, ...args], {\n\t\t\tcwd: this.options.cwd,\n\t\t\tenv: { ...process.env, ...this.options.env },\n\t\t\tstdio: [\"pipe\", \"pipe\", \"pipe\"],\n\t\t});\n\t\tthis.process = childProcess;\n\n\t\t// Collect stderr for debugging\n\t\tchildProcess.stderr?.on(\"data\", (data) => {\n\t\t\tthis.stderr += data.toString();\n\t\t\tprocess.stderr.write(data);\n\t\t});\n\n\t\tchildProcess.once(\"exit\", (code, signal) => {\n\t\t\tif (this.process !== childProcess) return;\n\t\t\tthis.readyEvent = null;\n\t\t\tconst error = this.createProcessExitError(code, signal);\n\t\t\tthis.exitError = error;\n\t\t\tthis.rejectReadyWaiters(error);\n\t\t\tthis.rejectPendingRequests(error);\n\t\t});\n\t\tchildProcess.once(\"error\", (error) => {\n\t\t\tif (this.process !== childProcess) return;\n\t\t\tthis.readyEvent = null;\n\t\t\tconst processError = new Error(`Agent process error: ${error.message}. Stderr: ${this.stderr}`);\n\t\t\tthis.exitError = processError;\n\t\t\tthis.rejectReadyWaiters(processError);\n\t\t\tthis.rejectPendingRequests(processError);\n\t\t});\n\t\tchildProcess.stdin?.on(\"error\", (error) => {\n\t\t\tif (this.process !== childProcess) return;\n\t\t\tconst stdinError =\n\t\t\t\tthis.exitError ?? new Error(`Agent process stdin error: ${error.message}. Stderr: ${this.stderr}`);\n\t\t\tthis.exitError = stdinError;\n\t\t\tthis.rejectPendingRequests(stdinError);\n\t\t});\n\n\t\t// Set up strict JSONL reader for stdout.\n\t\tthis.stopReadingStdout = attachJsonlLineReader(childProcess.stdout!, (line) => {\n\t\t\tthis.handleLine(line);\n\t\t});\n\n\t\t// Wait a moment for process to initialize\n\t\tawait new Promise((resolve) => setTimeout(resolve, 100));\n\n\t\tif (this.process.exitCode !== null) {\n\t\t\tconst error = this.exitError ?? this.createProcessExitError(this.process.exitCode, this.process.signalCode);\n\t\t\tthis.exitError = error;\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\t/** Wait until runtime initialization and session binding have completed. */\n\tasync waitUntilReady(timeout = 30000): Promise<RpcReadyEvent> {\n\t\tif (this.exitError) throw this.exitError;\n\t\tif (!this.process) throw new Error(\"Client not started\");\n\t\tif (this.readyEvent) return this.readyEvent;\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tconst timer = setTimeout(() => {\n\t\t\t\tconst waiter = this.readyWaiters.find((candidate) => candidate.reject === reject);\n\t\t\t\tif (waiter) this.readyWaiters.splice(this.readyWaiters.indexOf(waiter), 1);\n\t\t\t\treject(new Error(`Timed out waiting for RPC agent readiness. Stderr: ${this.stderr}`));\n\t\t\t}, timeout);\n\t\t\tthis.readyWaiters.push({\n\t\t\t\tresolve: (event) => {\n\t\t\t\t\tclearTimeout(timer);\n\t\t\t\t\tresolve(event);\n\t\t\t\t},\n\t\t\t\treject,\n\t\t\t});\n\t\t});\n\t}\n\n\t/**\n\t * Stop the RPC agent process.\n\t */\n\tasync stop(): Promise<void> {\n\t\tthis.readyEvent = null;\n\t\tif (!this.process) return;\n\t\tconst stopError = new Error(\"Client stopped before the agent process exited\");\n\n\t\tthis.stopReadingStdout?.();\n\t\tthis.stopReadingStdout = null;\n\t\tthis.process.kill(\"SIGTERM\");\n\n\t\t// Wait for process to exit\n\t\tawait new Promise<void>((resolve) => {\n\t\t\tconst timeout = setTimeout(() => {\n\t\t\t\tthis.process?.kill(\"SIGKILL\");\n\t\t\t\tthis.rejectReadyWaiters(stopError);\n\t\t\t\tthis.rejectPendingRequests(stopError);\n\t\t\t\tresolve();\n\t\t\t}, 1000);\n\n\t\t\tthis.process?.on(\"exit\", () => {\n\t\t\t\tclearTimeout(timeout);\n\t\t\t\tresolve();\n\t\t\t});\n\t\t});\n\n\t\tthis.process = null;\n\t\tthis.rejectReadyWaiters(stopError);\n\t\tthis.rejectPendingRequests(stopError);\n\t}\n\n\t/**\n\t * Subscribe to agent events.\n\t */\n\tonEvent(listener: RpcEventListener): () => void {\n\t\tthis.eventListeners.push(listener);\n\t\treturn () => {\n\t\t\tconst index = this.eventListeners.indexOf(listener);\n\t\t\tif (index !== -1) {\n\t\t\t\tthis.eventListeners.splice(index, 1);\n\t\t\t}\n\t\t};\n\t}\n\n\t/**\n\t * Get collected stderr output (useful for debugging).\n\t */\n\tgetStderr(): string {\n\t\treturn this.stderr;\n\t}\n\n\t// =========================================================================\n\t// Command Methods\n\t// =========================================================================\n\n\t/**\n\t * Send a prompt to the agent.\n\t * Returns immediately after sending; use onEvent() to receive streaming events.\n\t * Use waitForIdle() to wait for completion.\n\t */\n\tasync prompt(message: string, images?: ImageContent[]): Promise<void> {\n\t\tawait this.send({ type: \"prompt\", message, images });\n\t}\n\n\t/**\n\t * Queue a steering message to interrupt the agent mid-run.\n\t */\n\tasync steer(message: string, images?: ImageContent[]): Promise<void> {\n\t\tawait this.send({ type: \"steer\", message, images });\n\t}\n\n\t/**\n\t * Queue a follow-up message to be processed after the agent finishes.\n\t */\n\tasync followUp(message: string, images?: ImageContent[]): Promise<void> {\n\t\tawait this.send({ type: \"follow_up\", message, images });\n\t}\n\n\t/**\n\t * Abort current operation.\n\t */\n\tasync abort(): Promise<void> {\n\t\tawait this.send({ type: \"abort\" });\n\t}\n\n\t/**\n\t * Clear queued steering and follow-up messages, returning their text.\n\t */\n\tasync clearQueue(): Promise<{ steering: string[]; followUp: string[] }> {\n\t\tconst response = await this.send({ type: \"clear_queue\" });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Start a new session, optionally with parent tracking.\n\t * @param parentSession - Optional parent session path for lineage tracking\n\t * @returns Object with `cancelled: true` if an extension cancelled the new session\n\t */\n\tasync newSession(parentSession?: string): Promise<{ cancelled: boolean }> {\n\t\tconst response = await this.send({ type: \"new_session\", parentSession });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Get current session state.\n\t */\n\tasync getState(): Promise<RpcSessionState> {\n\t\tconst response = await this.send({ type: \"get_state\" });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Set model by provider and ID.\n\t */\n\tasync setModel(provider: string, modelId: string): Promise<{ provider: string; id: string }> {\n\t\tconst response = await this.send({ type: \"set_model\", provider, modelId });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Cycle to next model.\n\t */\n\tasync cycleModel(): Promise<{\n\t\tmodel: { provider: string; id: string };\n\t\tthinkingLevel: ThinkingLevel;\n\t\tisScoped: boolean;\n\t} | null> {\n\t\tconst response = await this.send({ type: \"cycle_model\" });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Get list of available models.\n\t */\n\tasync getAvailableModels(): Promise<ModelInfo[]> {\n\t\tconst response = await this.send({ type: \"get_available_models\" });\n\t\treturn this.getData<{ models: ModelInfo[] }>(response).models;\n\t}\n\n\t/**\n\t * Set thinking level.\n\t */\n\tasync setThinkingLevel(level: ThinkingLevel): Promise<void> {\n\t\tawait this.send({ type: \"set_thinking_level\", level });\n\t}\n\n\t/**\n\t * Cycle thinking level.\n\t */\n\tasync cycleThinkingLevel(): Promise<{ level: ThinkingLevel } | null> {\n\t\tconst response = await this.send({ type: \"cycle_thinking_level\" });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Get list of available thinking levels for the current model.\n\t */\n\tasync getAvailableThinkingLevels(): Promise<ThinkingLevel[]> {\n\t\tconst response = await this.send({ type: \"get_available_thinking_levels\" });\n\t\treturn this.getData<{ levels: ThinkingLevel[] }>(response).levels;\n\t}\n\n\t/**\n\t * Set steering mode.\n\t */\n\tasync setSteeringMode(mode: \"all\" | \"one-at-a-time\"): Promise<void> {\n\t\tawait this.send({ type: \"set_steering_mode\", mode });\n\t}\n\n\t/**\n\t * Set follow-up mode.\n\t */\n\tasync setFollowUpMode(mode: \"all\" | \"one-at-a-time\"): Promise<void> {\n\t\tawait this.send({ type: \"set_follow_up_mode\", mode });\n\t}\n\n\t/**\n\t * Compact session context.\n\t */\n\tasync compact(customInstructions?: string): Promise<CompactionResult> {\n\t\tconst response = await this.send({ type: \"compact\", customInstructions });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Set auto-compaction enabled/disabled.\n\t */\n\tasync setAutoCompaction(enabled: boolean): Promise<void> {\n\t\tawait this.send({ type: \"set_auto_compaction\", enabled });\n\t}\n\n\t/**\n\t * Set auto-retry enabled/disabled.\n\t */\n\tasync setAutoRetry(enabled: boolean): Promise<void> {\n\t\tawait this.send({ type: \"set_auto_retry\", enabled });\n\t}\n\n\t/**\n\t * Abort in-progress retry.\n\t */\n\tasync abortRetry(): Promise<void> {\n\t\tawait this.send({ type: \"abort_retry\" });\n\t}\n\n\t/**\n\t * Execute a bash command.\n\t */\n\tasync bash(command: string): Promise<BashResult> {\n\t\tconst response = await this.send({ type: \"bash\", command });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Abort running bash command.\n\t */\n\tasync abortBash(): Promise<void> {\n\t\tawait this.send({ type: \"abort_bash\" });\n\t}\n\n\t/**\n\t * Get session statistics.\n\t */\n\tasync getSessionStats(): Promise<SessionStats> {\n\t\tconst response = await this.send({ type: \"get_session_stats\" });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Export session to HTML.\n\t */\n\tasync exportHtml(outputPath?: string): Promise<{ path: string }> {\n\t\tconst response = await this.send({ type: \"export_html\", outputPath });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Switch to a different session file.\n\t * @returns Object with `cancelled: true` if an extension cancelled the switch\n\t */\n\tasync switchSession(sessionPath: string): Promise<{ cancelled: boolean }> {\n\t\tconst response = await this.send({ type: \"switch_session\", sessionPath });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Fork from a specific message.\n\t * @returns Object with `text` (the message text) and `cancelled` (if extension cancelled)\n\t */\n\tasync fork(entryId: string): Promise<{ text: string; cancelled: boolean }> {\n\t\tconst response = await this.send({ type: \"fork\", entryId });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Clone the current active branch into a new session.\n\t * @returns Object with `cancelled: true` if an extension cancelled the clone\n\t */\n\tasync clone(): Promise<{ cancelled: boolean }> {\n\t\tconst response = await this.send({ type: \"clone\" });\n\t\treturn this.getData(response);\n\t}\n\n\t/**\n\t * Get messages available for forking.\n\t */\n\tasync getForkMessages(): Promise<Array<{ entryId: string; text: string }>> {\n\t\tconst response = await this.send({ type: \"get_fork_messages\" });\n\t\treturn this.getData<{ messages: Array<{ entryId: string; text: string }> }>(response).messages;\n\t}\n\n\t/**\n\t * Get session entries in append order, optionally only those after the `since` entry id.\n\t */\n\tasync getEntries(since?: string): Promise<{ entries: SessionEntry[]; leafId: string | null }> {\n\t\tconst response = await this.send({ type: \"get_entries\", since });\n\t\treturn this.getData<{ entries: SessionEntry[]; leafId: string | null }>(response);\n\t}\n\n\t/**\n\t * Get the session entry tree.\n\t */\n\tasync getTree(): Promise<{ tree: SessionTreeNode[]; leafId: string | null }> {\n\t\tconst response = await this.send({ type: \"get_tree\" });\n\t\treturn this.getData<{ tree: SessionTreeNode[]; leafId: string | null }>(response);\n\t}\n\n\t/**\n\t * Get text of last assistant message.\n\t */\n\tasync getLastAssistantText(): Promise<string | null> {\n\t\tconst response = await this.send({ type: \"get_last_assistant_text\" });\n\t\treturn this.getData<{ text: string | null }>(response).text;\n\t}\n\n\t/**\n\t * Set the session display name.\n\t */\n\tasync setSessionName(name: string): Promise<void> {\n\t\tawait this.send({ type: \"set_session_name\", name });\n\t}\n\n\t/**\n\t * Get all messages in the session.\n\t */\n\tasync getMessages(): Promise<AgentMessage[]> {\n\t\tconst response = await this.send({ type: \"get_messages\" });\n\t\treturn this.getData<{ messages: AgentMessage[] }>(response).messages;\n\t}\n\n\t/**\n\t * Get available commands (extension commands, prompt templates, skills).\n\t */\n\tasync getCommands(): Promise<RpcSlashCommand[]> {\n\t\tconst response = await this.send({ type: \"get_commands\" });\n\t\treturn this.getData<{ commands: RpcSlashCommand[] }>(response).commands;\n\t}\n\n\t// =========================================================================\n\t// Helpers\n\t// =========================================================================\n\n\t/**\n\t * Wait for agent to become idle (no streaming).\n\t * Resolves when agent_settled event is received.\n\t */\n\twaitForIdle(timeout = 60000): Promise<void> {\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tconst timer = setTimeout(() => {\n\t\t\t\tunsubscribe();\n\t\t\t\treject(new Error(`Timeout waiting for agent to become idle. Stderr: ${this.stderr}`));\n\t\t\t}, timeout);\n\n\t\t\tconst unsubscribe = this.onEvent((event) => {\n\t\t\t\tif (event.type === \"agent_settled\") {\n\t\t\t\t\tclearTimeout(timer);\n\t\t\t\t\tunsubscribe();\n\t\t\t\t\tresolve();\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\t}\n\n\t/**\n\t * Collect events until agent becomes idle.\n\t */\n\tcollectEvents(timeout = 60000): Promise<JsonAgentSessionEvent[]> {\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tconst events: JsonAgentSessionEvent[] = [];\n\t\t\tconst timer = setTimeout(() => {\n\t\t\t\tunsubscribe();\n\t\t\t\treject(new Error(`Timeout collecting events. Stderr: ${this.stderr}`));\n\t\t\t}, timeout);\n\n\t\t\tconst unsubscribe = this.onEvent((event) => {\n\t\t\t\tif (event.type === \"ready\") return;\n\t\t\t\tevents.push(event);\n\t\t\t\tif (event.type === \"agent_settled\") {\n\t\t\t\t\tclearTimeout(timer);\n\t\t\t\t\tunsubscribe();\n\t\t\t\t\tresolve(events);\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\t}\n\n\t/**\n\t * Send prompt and wait for completion, returning all events.\n\t */\n\tasync promptAndWait(message: string, images?: ImageContent[], timeout = 60000): Promise<JsonAgentSessionEvent[]> {\n\t\tconst eventsPromise = this.collectEvents(timeout);\n\t\tawait this.prompt(message, images);\n\t\treturn eventsPromise;\n\t}\n\n\t// =========================================================================\n\t// Internal\n\t// =========================================================================\n\n\tprivate handleLine(line: string): void {\n\t\ttry {\n\t\t\tconst data = parseRpcWireFrame(line);\n\n\t\t\tif (data.type === \"ready\") {\n\t\t\t\tthis.readyEvent = data as RpcReadyEvent;\n\t\t\t\tconst waiters = this.readyWaiters;\n\t\t\t\tthis.readyWaiters = [];\n\t\t\t\tfor (const waiter of waiters) waiter.resolve(this.readyEvent);\n\t\t\t\tfor (const listener of this.eventListeners) listener(this.readyEvent);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Check if it's a response to a pending request\n\t\t\tif (data.type === \"response\" && typeof data.id === \"string\" && this.pendingRequests.has(data.id)) {\n\t\t\t\tconst pending = this.pendingRequests.get(data.id)!;\n\t\t\t\tthis.pendingRequests.delete(data.id);\n\t\t\t\tpending.resolve(data as RpcResponse);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Otherwise it's an event\n\t\t\tfor (const listener of this.eventListeners) {\n\t\t\t\tlistener(data as JsonAgentSessionEvent);\n\t\t\t}\n\t\t} catch {\n\t\t\t// Ignore non-JSON lines\n\t\t}\n\t}\n\n\tprivate rejectReadyWaiters(error: Error): void {\n\t\tconst waiters = this.readyWaiters;\n\t\tthis.readyWaiters = [];\n\t\tfor (const waiter of waiters) waiter.reject(error);\n\t}\n\n\tprivate createProcessExitError(code: number | null, signal: NodeJS.Signals | null): Error {\n\t\treturn new Error(`Agent process exited (code=${code} signal=${signal}). Stderr: ${this.stderr}`);\n\t}\n\n\tprivate rejectPendingRequests(error: Error): void {\n\t\tfor (const pending of this.pendingRequests.values()) {\n\t\t\tpending.reject(error);\n\t\t}\n\t\tthis.pendingRequests.clear();\n\t}\n\n\tprivate async send(command: RpcCommandBody): Promise<RpcResponse> {\n\t\tconst childProcess = this.process;\n\t\tconst stdin = childProcess?.stdin;\n\t\tif (!childProcess || !stdin) {\n\t\t\tthrow new Error(\"Client not started\");\n\t\t}\n\t\tif (this.exitError) {\n\t\t\tthrow this.exitError;\n\t\t}\n\t\tif (childProcess.exitCode !== null) {\n\t\t\tconst error = this.createProcessExitError(childProcess.exitCode, childProcess.signalCode);\n\t\t\tthis.exitError = error;\n\t\t\tthrow error;\n\t\t}\n\t\tif (stdin.destroyed || !stdin.writable) {\n\t\t\tconst error = new Error(`Agent process stdin is not writable. Stderr: ${this.stderr}`);\n\t\t\tthis.exitError = error;\n\t\t\tthrow error;\n\t\t}\n\n\t\tconst id = `req_${++this.requestId}`;\n\t\tconst fullCommand = { ...command, id } as RpcCommand;\n\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tconst timeout = setTimeout(() => {\n\t\t\t\tthis.pendingRequests.delete(id);\n\t\t\t\treject(new Error(`Timeout waiting for response to ${command.type}. Stderr: ${this.stderr}`));\n\t\t\t}, 30000);\n\n\t\t\tthis.pendingRequests.set(id, {\n\t\t\t\tresolve: (response) => {\n\t\t\t\t\tclearTimeout(timeout);\n\t\t\t\t\tresolve(response);\n\t\t\t\t},\n\t\t\t\treject: (error) => {\n\t\t\t\t\tclearTimeout(timeout);\n\t\t\t\t\treject(error);\n\t\t\t\t},\n\t\t\t});\n\n\t\t\ttry {\n\t\t\t\tstdin.write(serializeJsonLine(fullCommand));\n\t\t\t} catch (error: unknown) {\n\t\t\t\tconst writeError = error instanceof Error ? error : new Error(String(error));\n\t\t\t\tconst pending = this.pendingRequests.get(id);\n\t\t\t\tthis.pendingRequests.delete(id);\n\t\t\t\tpending?.reject(writeError);\n\t\t\t}\n\t\t});\n\t}\n\n\tprivate getData<T>(response: RpcResponse): T {\n\t\tif (!response.success) {\n\t\t\tconst errorResponse = response as Extract<RpcResponse, { success: false }>;\n\t\t\tthrow new Error(errorResponse.error);\n\t\t}\n\t\t// Type assertion: we trust response.data matches T based on the command sent.\n\t\t// This is safe because each public method specifies the correct T for its command.\n\t\tconst successResponse = response as Extract<RpcResponse, { success: true; data: unknown }>;\n\t\treturn successResponse.data as T;\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"rpc-mode.d.ts","sourceRoot":"","sources":["../../../src/modes/rpc/rpc-mode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AA4B/E,YAAY,EACX,UAAU,EACV,qBAAqB,EACrB,sBAAsB,EACtB,aAAa,EACb,WAAW,EACX,eAAe,GACf,MAAM,gBAAgB,CAAC;AAExB;;;GAGG;AACH,wBAAsB,UAAU,CAAC,WAAW,EAAE,mBAAmB,GAAG,OAAO,CAAC,KAAK,CAAC,CAqwBjF"}
1
+ {"version":3,"file":"rpc-mode.d.ts","sourceRoot":"","sources":["../../../src/modes/rpc/rpc-mode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AA4B/E,YAAY,EACX,UAAU,EACV,qBAAqB,EACrB,sBAAsB,EACtB,aAAa,EACb,WAAW,EACX,eAAe,GACf,MAAM,gBAAgB,CAAC;AAyFxB;;;GAGG;AACH,wBAAsB,UAAU,CAAC,WAAW,EAAE,mBAAmB,GAAG,OAAO,CAAC,KAAK,CAAC,CAkzBjF"}
@@ -11,11 +11,84 @@
11
11
  * - Extension UI: Extension UI requests are emitted, client responds with extension_ui_response
12
12
  */
13
13
  import * as crypto from "node:crypto";
14
+ import { MAX_RPC_FRAME_LENGTH } from "@humain/terminal-contracts/rpc";
14
15
  import { flushRawStdout, takeOverStdout, waitForRawStdoutBackpressure, writeRawStdout, } from "../../core/output-guard.js";
15
16
  import { killTrackedDetachedChildren } from "../../utils/shell.js";
16
17
  import { theme } from "../interactive/theme/theme.js";
17
18
  import { toJsonEvent } from "../json-event.js";
18
19
  import { attachJsonlLineReader, serializeJsonLine } from "./jsonl.js";
20
+ // Bounds the UTF-16 string retained by the JSONL reader for one persistent RPC command.
21
+ const MAX_RPC_INPUT_LINE_LENGTH = MAX_RPC_FRAME_LENGTH;
22
+ function isRecord(value) {
23
+ return typeof value === "object" && value !== null && !Array.isArray(value);
24
+ }
25
+ function invalidRpcCommand(command) {
26
+ if (command.id !== undefined && typeof command.id !== "string")
27
+ return "id must be a string";
28
+ if (typeof command.type !== "string" || command.type.length === 0)
29
+ return "expected a non-empty string type";
30
+ const requireString = (field) => typeof command[field] === "string" ? undefined : `${command.type}.${field} must be a string`;
31
+ const requireOptionalString = (field) => command[field] === undefined || typeof command[field] === "string"
32
+ ? undefined
33
+ : `${command.type}.${field} must be a string`;
34
+ const requireBoolean = (field) => typeof command[field] === "boolean" ? undefined : `${command.type}.${field} must be a boolean`;
35
+ switch (command.type) {
36
+ case "prompt":
37
+ return (requireString("message") ??
38
+ (command.images === undefined || Array.isArray(command.images)
39
+ ? undefined
40
+ : "prompt.images must be an array") ??
41
+ (command.streamingBehavior === undefined ||
42
+ command.streamingBehavior === "steer" ||
43
+ command.streamingBehavior === "followUp"
44
+ ? undefined
45
+ : "prompt.streamingBehavior must be steer or followUp"));
46
+ case "steer":
47
+ case "follow_up":
48
+ return (requireString("message") ??
49
+ (command.images === undefined || Array.isArray(command.images)
50
+ ? undefined
51
+ : `${command.type}.images must be an array`));
52
+ case "new_session":
53
+ return requireOptionalString("parentSession");
54
+ case "set_model":
55
+ return requireString("provider") ?? requireString("modelId");
56
+ case "set_thinking_level":
57
+ return requireString("level");
58
+ case "set_steering_mode":
59
+ case "set_follow_up_mode":
60
+ return command.mode === "all" || command.mode === "one-at-a-time"
61
+ ? undefined
62
+ : `${command.type}.mode must be all or one-at-a-time`;
63
+ case "compact":
64
+ return requireOptionalString("customInstructions");
65
+ case "set_auto_compaction":
66
+ case "set_auto_retry":
67
+ return requireBoolean("enabled");
68
+ case "bash":
69
+ return (requireString("command") ??
70
+ (command.excludeFromContext === undefined || typeof command.excludeFromContext === "boolean"
71
+ ? undefined
72
+ : "bash.excludeFromContext must be a boolean"));
73
+ case "export_html":
74
+ return requireOptionalString("outputPath");
75
+ case "switch_session":
76
+ return requireString("sessionPath");
77
+ case "fork":
78
+ return requireString("entryId");
79
+ case "get_entries":
80
+ return requireOptionalString("since");
81
+ case "set_session_name":
82
+ return requireString("name");
83
+ default:
84
+ return undefined;
85
+ }
86
+ }
87
+ function isRpcExtensionUIResponse(value) {
88
+ return (value.type === "extension_ui_response" &&
89
+ typeof value.id === "string" &&
90
+ (typeof value.value === "string" || typeof value.confirmed === "boolean" || value.cancelled === true));
91
+ }
19
92
  /**
20
93
  * Run in RPC mode.
21
94
  * Listens for JSON commands on stdin, outputs events and responses on stdout.
@@ -339,6 +412,9 @@ export async function runRpcMode(runtimeHost) {
339
412
  await session.abort();
340
413
  return success(id, "abort");
341
414
  }
415
+ case "clear_queue": {
416
+ return success(id, "clear_queue", session.clearQueue());
417
+ }
342
418
  case "new_session": {
343
419
  const options = command.parentSession ? { parentSession: command.parentSession } : undefined;
344
420
  const result = await runtimeHost.newSession(options);
@@ -617,11 +693,18 @@ export async function runRpcMode(runtimeHost) {
617
693
  await waitForRawStdoutBackpressure();
618
694
  return;
619
695
  }
696
+ if (!isRecord(parsed)) {
697
+ output(error(undefined, "parse", "Invalid command: expected a JSON object"));
698
+ await waitForRawStdoutBackpressure();
699
+ return;
700
+ }
620
701
  // Handle extension UI responses
621
- if (typeof parsed === "object" &&
622
- parsed !== null &&
623
- "type" in parsed &&
624
- parsed.type === "extension_ui_response") {
702
+ if (parsed.type === "extension_ui_response") {
703
+ if (!isRpcExtensionUIResponse(parsed)) {
704
+ output(error(typeof parsed.id === "string" ? parsed.id : undefined, "extension_ui_response", "Invalid command: malformed extension_ui_response"));
705
+ await waitForRawStdoutBackpressure();
706
+ return;
707
+ }
625
708
  const response = parsed;
626
709
  const pending = pendingExtensionRequests.get(response.id);
627
710
  if (pending) {
@@ -630,6 +713,12 @@ export async function runRpcMode(runtimeHost) {
630
713
  }
631
714
  return;
632
715
  }
716
+ const invalid = invalidRpcCommand(parsed);
717
+ if (invalid) {
718
+ output(error(typeof parsed.id === "string" ? parsed.id : undefined, typeof parsed.type === "string" ? parsed.type : "parse", `Invalid command: ${invalid}`));
719
+ await waitForRawStdoutBackpressure();
720
+ return;
721
+ }
633
722
  const command = parsed;
634
723
  try {
635
724
  const response = await handleCommand(command);
@@ -651,6 +740,12 @@ export async function runRpcMode(runtimeHost) {
651
740
  detachInput = (() => {
652
741
  const detachJsonl = attachJsonlLineReader(process.stdin, (line) => {
653
742
  void handleInputLine(line);
743
+ }, {
744
+ maxLineLength: MAX_RPC_INPUT_LINE_LENGTH,
745
+ onLineTooLong: () => {
746
+ output(error(undefined, "parse", `RPC command exceeds the ${MAX_RPC_INPUT_LINE_LENGTH}-character input limit`));
747
+ void waitForRawStdoutBackpressure();
748
+ },
654
749
  });
655
750
  return () => {
656
751
  detachJsonl();