@onkernel/cua-agent 0.1.0 → 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 (123) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +44 -19
  3. package/dist/agent.d.ts +83 -27
  4. package/dist/agent.d.ts.map +1 -1
  5. package/dist/agent.js +176 -74
  6. package/dist/agent.js.map +1 -1
  7. package/dist/index.d.ts +3 -3
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +2 -2
  10. package/dist/index.js.map +1 -1
  11. package/dist/tools.d.ts +1 -1
  12. package/dist/tools.d.ts.map +1 -1
  13. package/dist/tools.js.map +1 -1
  14. package/dist/translator/translator.js +63 -6
  15. package/dist/translator/translator.js.map +1 -1
  16. package/dist/vendor/pi-agent-core/agent-loop.d.ts +24 -0
  17. package/dist/vendor/pi-agent-core/agent-loop.d.ts.map +1 -0
  18. package/dist/vendor/pi-agent-core/agent-loop.js +479 -0
  19. package/dist/vendor/pi-agent-core/agent-loop.js.map +1 -0
  20. package/dist/vendor/pi-agent-core/agent.d.ts +125 -0
  21. package/dist/vendor/pi-agent-core/agent.d.ts.map +1 -0
  22. package/dist/vendor/pi-agent-core/agent.js +402 -0
  23. package/dist/vendor/pi-agent-core/agent.js.map +1 -0
  24. package/dist/vendor/pi-agent-core/harness/agent-harness.d.ts +85 -0
  25. package/dist/vendor/pi-agent-core/harness/agent-harness.d.ts.map +1 -0
  26. package/dist/vendor/pi-agent-core/harness/agent-harness.js +728 -0
  27. package/dist/vendor/pi-agent-core/harness/agent-harness.js.map +1 -0
  28. package/dist/vendor/pi-agent-core/harness/compaction/branch-summarization.d.ts +88 -0
  29. package/dist/vendor/pi-agent-core/harness/compaction/branch-summarization.d.ts.map +1 -0
  30. package/dist/vendor/pi-agent-core/harness/compaction/branch-summarization.js +243 -0
  31. package/dist/vendor/pi-agent-core/harness/compaction/branch-summarization.js.map +1 -0
  32. package/dist/vendor/pi-agent-core/harness/compaction/compaction.d.ts +122 -0
  33. package/dist/vendor/pi-agent-core/harness/compaction/compaction.d.ts.map +1 -0
  34. package/dist/vendor/pi-agent-core/harness/compaction/compaction.js +616 -0
  35. package/dist/vendor/pi-agent-core/harness/compaction/compaction.js.map +1 -0
  36. package/dist/vendor/pi-agent-core/harness/compaction/utils.d.ts +38 -0
  37. package/dist/vendor/pi-agent-core/harness/compaction/utils.d.ts.map +1 -0
  38. package/dist/vendor/pi-agent-core/harness/compaction/utils.js +153 -0
  39. package/dist/vendor/pi-agent-core/harness/compaction/utils.js.map +1 -0
  40. package/dist/vendor/pi-agent-core/harness/env/nodejs.d.ts +44 -0
  41. package/dist/vendor/pi-agent-core/harness/env/nodejs.d.ts.map +1 -0
  42. package/dist/vendor/pi-agent-core/harness/env/nodejs.js +348 -0
  43. package/dist/vendor/pi-agent-core/harness/env/nodejs.js.map +1 -0
  44. package/dist/vendor/pi-agent-core/harness/execution-env.d.ts +4 -0
  45. package/dist/vendor/pi-agent-core/harness/execution-env.d.ts.map +1 -0
  46. package/dist/vendor/pi-agent-core/harness/execution-env.js +3 -0
  47. package/dist/vendor/pi-agent-core/harness/execution-env.js.map +1 -0
  48. package/dist/vendor/pi-agent-core/harness/messages.d.ts +51 -0
  49. package/dist/vendor/pi-agent-core/harness/messages.d.ts.map +1 -0
  50. package/dist/vendor/pi-agent-core/harness/messages.js +102 -0
  51. package/dist/vendor/pi-agent-core/harness/messages.js.map +1 -0
  52. package/dist/vendor/pi-agent-core/harness/prompt-templates.d.ts +45 -0
  53. package/dist/vendor/pi-agent-core/harness/prompt-templates.d.ts.map +1 -0
  54. package/dist/vendor/pi-agent-core/harness/prompt-templates.js +200 -0
  55. package/dist/vendor/pi-agent-core/harness/prompt-templates.js.map +1 -0
  56. package/dist/vendor/pi-agent-core/harness/session/repo/jsonl.d.ts +20 -0
  57. package/dist/vendor/pi-agent-core/harness/session/repo/jsonl.d.ts.map +1 -0
  58. package/dist/vendor/pi-agent-core/harness/session/repo/jsonl.js +92 -0
  59. package/dist/vendor/pi-agent-core/harness/session/repo/jsonl.js.map +1 -0
  60. package/dist/vendor/pi-agent-core/harness/session/repo/memory.d.ts +18 -0
  61. package/dist/vendor/pi-agent-core/harness/session/repo/memory.d.ts.map +1 -0
  62. package/dist/vendor/pi-agent-core/harness/session/repo/memory.js +42 -0
  63. package/dist/vendor/pi-agent-core/harness/session/repo/memory.js.map +1 -0
  64. package/dist/vendor/pi-agent-core/harness/session/repo/shared.d.ts +10 -0
  65. package/dist/vendor/pi-agent-core/harness/session/repo/shared.d.ts.map +1 -0
  66. package/dist/vendor/pi-agent-core/harness/session/repo/shared.js +31 -0
  67. package/dist/vendor/pi-agent-core/harness/session/repo/shared.js.map +1 -0
  68. package/dist/vendor/pi-agent-core/harness/session/session.d.ts +32 -0
  69. package/dist/vendor/pi-agent-core/harness/session/session.d.ts.map +1 -0
  70. package/dist/vendor/pi-agent-core/harness/session/session.js +196 -0
  71. package/dist/vendor/pi-agent-core/harness/session/session.js.map +1 -0
  72. package/dist/vendor/pi-agent-core/harness/session/storage/jsonl.d.ts +30 -0
  73. package/dist/vendor/pi-agent-core/harness/session/storage/jsonl.d.ts.map +1 -0
  74. package/dist/vendor/pi-agent-core/harness/session/storage/jsonl.js +170 -0
  75. package/dist/vendor/pi-agent-core/harness/session/storage/jsonl.js.map +1 -0
  76. package/dist/vendor/pi-agent-core/harness/session/storage/memory.d.ts +26 -0
  77. package/dist/vendor/pi-agent-core/harness/session/storage/memory.d.ts.map +1 -0
  78. package/dist/vendor/pi-agent-core/harness/session/storage/memory.js +90 -0
  79. package/dist/vendor/pi-agent-core/harness/session/storage/memory.js.map +1 -0
  80. package/dist/vendor/pi-agent-core/harness/session/uuid.d.ts +2 -0
  81. package/dist/vendor/pi-agent-core/harness/session/uuid.d.ts.map +1 -0
  82. package/dist/vendor/pi-agent-core/harness/session/uuid.js +40 -0
  83. package/dist/vendor/pi-agent-core/harness/session/uuid.js.map +1 -0
  84. package/dist/vendor/pi-agent-core/harness/skills.d.ts +41 -0
  85. package/dist/vendor/pi-agent-core/harness/skills.d.ts.map +1 -0
  86. package/dist/vendor/pi-agent-core/harness/skills.js +259 -0
  87. package/dist/vendor/pi-agent-core/harness/skills.js.map +1 -0
  88. package/dist/vendor/pi-agent-core/harness/system-prompt.d.ts +3 -0
  89. package/dist/vendor/pi-agent-core/harness/system-prompt.d.ts.map +1 -0
  90. package/dist/vendor/pi-agent-core/harness/system-prompt.js +30 -0
  91. package/dist/vendor/pi-agent-core/harness/system-prompt.js.map +1 -0
  92. package/dist/vendor/pi-agent-core/harness/types.d.ts +525 -0
  93. package/dist/vendor/pi-agent-core/harness/types.d.ts.map +1 -0
  94. package/dist/vendor/pi-agent-core/harness/types.js +16 -0
  95. package/dist/vendor/pi-agent-core/harness/types.js.map +1 -0
  96. package/dist/vendor/pi-agent-core/harness/utils/shell-output.d.ts +14 -0
  97. package/dist/vendor/pi-agent-core/harness/utils/shell-output.d.ts.map +1 -0
  98. package/dist/vendor/pi-agent-core/harness/utils/shell-output.js +97 -0
  99. package/dist/vendor/pi-agent-core/harness/utils/shell-output.js.map +1 -0
  100. package/dist/vendor/pi-agent-core/harness/utils/truncate.d.ts +70 -0
  101. package/dist/vendor/pi-agent-core/harness/utils/truncate.d.ts.map +1 -0
  102. package/dist/vendor/pi-agent-core/harness/utils/truncate.js +205 -0
  103. package/dist/vendor/pi-agent-core/harness/utils/truncate.js.map +1 -0
  104. package/dist/vendor/pi-agent-core/index.d.ts +21 -0
  105. package/dist/vendor/pi-agent-core/index.d.ts.map +1 -0
  106. package/dist/vendor/pi-agent-core/index.js +26 -0
  107. package/dist/vendor/pi-agent-core/index.js.map +1 -0
  108. package/dist/vendor/pi-agent-core/proxy.d.ts +69 -0
  109. package/dist/vendor/pi-agent-core/proxy.d.ts.map +1 -0
  110. package/dist/vendor/pi-agent-core/proxy.js +278 -0
  111. package/dist/vendor/pi-agent-core/proxy.js.map +1 -0
  112. package/dist/vendor/pi-agent-core/types.d.ts +386 -0
  113. package/dist/vendor/pi-agent-core/types.d.ts.map +1 -0
  114. package/dist/vendor/pi-agent-core/types.js +2 -0
  115. package/dist/vendor/pi-agent-core/types.js.map +1 -0
  116. package/examples/agent-openai-smoke.ts +4 -10
  117. package/examples/agent-provider-matrix.ts +4 -0
  118. package/examples/harness-openai-smoke.ts +17 -16
  119. package/examples/harness-provider-matrix.ts +16 -4
  120. package/examples/shared/logging.ts +37 -0
  121. package/package.json +6 -4
  122. package/src/vendor/pi-agent-core/LICENSE +21 -0
  123. package/src/vendor/pi-agent-core/README.md +15 -0
@@ -0,0 +1,97 @@
1
+ import { randomBytes } from "node:crypto";
2
+ import { createWriteStream } from "node:fs";
3
+ import { tmpdir } from "node:os";
4
+ import { join } from "node:path";
5
+ import { DEFAULT_MAX_BYTES, truncateTail } from "./truncate.js";
6
+ export function sanitizeBinaryOutput(str) {
7
+ return Array.from(str)
8
+ .filter((char) => {
9
+ const code = char.codePointAt(0);
10
+ if (code === undefined)
11
+ return false;
12
+ if (code === 0x09 || code === 0x0a || code === 0x0d)
13
+ return true;
14
+ if (code <= 0x1f)
15
+ return false;
16
+ if (code >= 0xfff9 && code <= 0xfffb)
17
+ return false;
18
+ return true;
19
+ })
20
+ .join("");
21
+ }
22
+ export async function executeShellWithCapture(env, command, options) {
23
+ const outputChunks = [];
24
+ let outputBytes = 0;
25
+ const maxOutputBytes = DEFAULT_MAX_BYTES * 2;
26
+ let tempFilePath;
27
+ let tempFileStream;
28
+ let totalBytes = 0;
29
+ const ensureTempFile = () => {
30
+ if (tempFilePath)
31
+ return;
32
+ const id = randomBytes(8).toString("hex");
33
+ tempFilePath = join(tmpdir(), `bash-${id}.log`);
34
+ tempFileStream = createWriteStream(tempFilePath);
35
+ for (const chunk of outputChunks) {
36
+ tempFileStream.write(chunk);
37
+ }
38
+ };
39
+ const onChunk = (chunk) => {
40
+ totalBytes += Buffer.byteLength(chunk, "utf-8");
41
+ const text = sanitizeBinaryOutput(chunk).replace(/\r/g, "");
42
+ if (totalBytes > DEFAULT_MAX_BYTES) {
43
+ ensureTempFile();
44
+ }
45
+ if (tempFileStream) {
46
+ tempFileStream.write(text);
47
+ }
48
+ outputChunks.push(text);
49
+ outputBytes += text.length;
50
+ while (outputBytes > maxOutputBytes && outputChunks.length > 1) {
51
+ const removed = outputChunks.shift();
52
+ outputBytes -= removed.length;
53
+ }
54
+ options?.onChunk?.(text);
55
+ };
56
+ try {
57
+ const result = await env.exec(command, {
58
+ ...(options ?? {}),
59
+ onStdout: onChunk,
60
+ onStderr: onChunk,
61
+ });
62
+ const fullOutput = outputChunks.join("");
63
+ const truncationResult = truncateTail(fullOutput);
64
+ if (truncationResult.truncated) {
65
+ ensureTempFile();
66
+ }
67
+ tempFileStream?.end();
68
+ const cancelled = options?.signal?.aborted ?? false;
69
+ return {
70
+ output: truncationResult.truncated ? truncationResult.content : fullOutput,
71
+ exitCode: cancelled ? undefined : result.exitCode,
72
+ cancelled,
73
+ truncated: truncationResult.truncated,
74
+ fullOutputPath: tempFilePath,
75
+ };
76
+ }
77
+ catch (err) {
78
+ if (options?.signal?.aborted) {
79
+ const fullOutput = outputChunks.join("");
80
+ const truncationResult = truncateTail(fullOutput);
81
+ if (truncationResult.truncated) {
82
+ ensureTempFile();
83
+ }
84
+ tempFileStream?.end();
85
+ return {
86
+ output: truncationResult.truncated ? truncationResult.content : fullOutput,
87
+ exitCode: undefined,
88
+ cancelled: true,
89
+ truncated: truncationResult.truncated,
90
+ fullOutputPath: tempFilePath,
91
+ };
92
+ }
93
+ tempFileStream?.end();
94
+ throw err;
95
+ }
96
+ }
97
+ //# sourceMappingURL=shell-output.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shell-output.js","sourceRoot":"","sources":["../../../../../src/vendor/pi-agent-core/harness/utils/shell-output.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAoB,MAAM,SAAS,CAA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
+ *
4
+ * Truncation is based on two independent limits - whichever is hit first wins:
5
+ * - Line limit (default: 2000 lines)
6
+ * - Byte limit (default: 50KB)
7
+ *
8
+ * Never returns partial lines (except bash tail truncation edge case).
9
+ */
10
+ export declare const DEFAULT_MAX_LINES = 2000;
11
+ export declare const DEFAULT_MAX_BYTES: number;
12
+ export declare const GREP_MAX_LINE_LENGTH = 500;
13
+ export interface TruncationResult {
14
+ /** The truncated content */
15
+ content: string;
16
+ /** Whether truncation occurred */
17
+ truncated: boolean;
18
+ /** Which limit was hit: "lines", "bytes", or null if not truncated */
19
+ truncatedBy: "lines" | "bytes" | null;
20
+ /** Total number of lines in the original content */
21
+ totalLines: number;
22
+ /** Total number of bytes in the original content */
23
+ totalBytes: number;
24
+ /** Number of complete lines in the truncated output */
25
+ outputLines: number;
26
+ /** Number of bytes in the truncated output */
27
+ outputBytes: number;
28
+ /** Whether the last line was partially truncated (only for tail truncation edge case) */
29
+ lastLinePartial: boolean;
30
+ /** Whether the first line exceeded the byte limit (for head truncation) */
31
+ firstLineExceedsLimit: boolean;
32
+ /** The max lines limit that was applied */
33
+ maxLines: number;
34
+ /** The max bytes limit that was applied */
35
+ maxBytes: number;
36
+ }
37
+ export interface TruncationOptions {
38
+ /** Maximum number of lines (default: 2000) */
39
+ maxLines?: number;
40
+ /** Maximum number of bytes (default: 50KB) */
41
+ maxBytes?: number;
42
+ }
43
+ /**
44
+ * Format bytes as human-readable size.
45
+ */
46
+ export declare function formatSize(bytes: number): string;
47
+ /**
48
+ * Truncate content from the head (keep first N lines/bytes).
49
+ * Suitable for file reads where you want to see the beginning.
50
+ *
51
+ * Never returns partial lines. If first line exceeds byte limit,
52
+ * returns empty content with firstLineExceedsLimit=true.
53
+ */
54
+ export declare function truncateHead(content: string, options?: TruncationOptions): TruncationResult;
55
+ /**
56
+ * Truncate content from the tail (keep last N lines/bytes).
57
+ * Suitable for bash output where you want to see the end (errors, final results).
58
+ *
59
+ * May return partial first line if the last line of original content exceeds byte limit.
60
+ */
61
+ export declare function truncateTail(content: string, options?: TruncationOptions): TruncationResult;
62
+ /**
63
+ * Truncate a single line to max characters, adding [truncated] suffix.
64
+ * Used for grep match lines.
65
+ */
66
+ export declare function truncateLine(line: string, maxChars?: number): {
67
+ text: string;
68
+ wasTruncated: boolean;
69
+ };
70
+ //# sourceMappingURL=truncate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"truncate.d.ts","sourceRoot":"","sources":["../../../../../src/vendor/pi-agent-core/harness/utils/truncate.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,eAAO,MAAM,iBAAiB,OAAO,CAAC;AACtC,eAAO,MAAM,iBAAiB,QAAY,CAAC;AAC3C,eAAO,MAAM,oBAAoB,MAAM,CAAC;AAExC,MAAM,WAAW,gBAAgB;IAChC,4BAA4B;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,kCAAkC;IAClC,SAAS,EAAE,OAAO,CAAC;IACnB,sEAAsE;IACtE,WAAW,EAAE,OAAO,GAAG,OAAO,GAAG,IAAI,CAAC;IACtC,oDAAoD;IACpD,UAAU,EAAE,MAAM,CAAC;IACnB,oDAAoD;IACpD,UAAU,EAAE,MAAM,CAAC;IACnB,uDAAuD;IACvD,WAAW,EAAE,MAAM,CAAC;IACpB,8CAA8C;IAC9C,WAAW,EAAE,MAAM,CAAC;IACpB,yFAAyF;IACzF,eAAe,EAAE,OAAO,CAAC;IACzB,2EAA2E;IAC3E,qBAAqB,EAAE,OAAO,CAAC;IAC/B,2CAA2C;IAC3C,QAAQ,EAAE,MAAM,CAAC;IACjB,2CAA2C;IAC3C,QAAQ,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,iBAAiB;IACjC,8CAA8C;IAC9C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,8CAA8C;IAC9C,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAQhD;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,iBAAsB,GAAG,gBAAgB,CAkF/F;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,iBAAsB,GAAG,gBAAgB,CAyE/F;AAuBD;;;GAGG;AACH,wBAAgB,YAAY,CAC3B,IAAI,EAAE,MAAM,EACZ,QAAQ,GAAE,MAA6B,GACrC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,OAAO,CAAA;CAAE,CAKzC"}
@@ -0,0 +1,205 @@
1
+ /**
2
+ * Shared truncation utilities for tool outputs.
3
+ *
4
+ * Truncation is based on two independent limits - whichever is hit first wins:
5
+ * - Line limit (default: 2000 lines)
6
+ * - Byte limit (default: 50KB)
7
+ *
8
+ * Never returns partial lines (except bash tail truncation edge case).
9
+ */
10
+ export const DEFAULT_MAX_LINES = 2000;
11
+ export const DEFAULT_MAX_BYTES = 50 * 1024; // 50KB
12
+ export const GREP_MAX_LINE_LENGTH = 500; // Max chars per grep match line
13
+ /**
14
+ * Format bytes as human-readable size.
15
+ */
16
+ export function formatSize(bytes) {
17
+ if (bytes < 1024) {
18
+ return `${bytes}B`;
19
+ }
20
+ else if (bytes < 1024 * 1024) {
21
+ return `${(bytes / 1024).toFixed(1)}KB`;
22
+ }
23
+ else {
24
+ return `${(bytes / (1024 * 1024)).toFixed(1)}MB`;
25
+ }
26
+ }
27
+ /**
28
+ * Truncate content from the head (keep first N lines/bytes).
29
+ * Suitable for file reads where you want to see the beginning.
30
+ *
31
+ * Never returns partial lines. If first line exceeds byte limit,
32
+ * returns empty content with firstLineExceedsLimit=true.
33
+ */
34
+ export function truncateHead(content, options = {}) {
35
+ const maxLines = options.maxLines ?? DEFAULT_MAX_LINES;
36
+ const maxBytes = options.maxBytes ?? DEFAULT_MAX_BYTES;
37
+ const totalBytes = Buffer.byteLength(content, "utf-8");
38
+ const lines = content.split("\n");
39
+ const totalLines = lines.length;
40
+ // Check if no truncation needed
41
+ if (totalLines <= maxLines && totalBytes <= maxBytes) {
42
+ return {
43
+ content,
44
+ truncated: false,
45
+ truncatedBy: null,
46
+ totalLines,
47
+ totalBytes,
48
+ outputLines: totalLines,
49
+ outputBytes: totalBytes,
50
+ lastLinePartial: false,
51
+ firstLineExceedsLimit: false,
52
+ maxLines,
53
+ maxBytes,
54
+ };
55
+ }
56
+ // Check if first line alone exceeds byte limit
57
+ const firstLineBytes = Buffer.byteLength(lines[0], "utf-8");
58
+ if (firstLineBytes > maxBytes) {
59
+ return {
60
+ content: "",
61
+ truncated: true,
62
+ truncatedBy: "bytes",
63
+ totalLines,
64
+ totalBytes,
65
+ outputLines: 0,
66
+ outputBytes: 0,
67
+ lastLinePartial: false,
68
+ firstLineExceedsLimit: true,
69
+ maxLines,
70
+ maxBytes,
71
+ };
72
+ }
73
+ // Collect complete lines that fit
74
+ const outputLinesArr = [];
75
+ let outputBytesCount = 0;
76
+ let truncatedBy = "lines";
77
+ for (let i = 0; i < lines.length && i < maxLines; i++) {
78
+ const line = lines[i];
79
+ const lineBytes = Buffer.byteLength(line, "utf-8") + (i > 0 ? 1 : 0); // +1 for newline
80
+ if (outputBytesCount + lineBytes > maxBytes) {
81
+ truncatedBy = "bytes";
82
+ break;
83
+ }
84
+ outputLinesArr.push(line);
85
+ outputBytesCount += lineBytes;
86
+ }
87
+ // If we exited due to line limit
88
+ if (outputLinesArr.length >= maxLines && outputBytesCount <= maxBytes) {
89
+ truncatedBy = "lines";
90
+ }
91
+ const outputContent = outputLinesArr.join("\n");
92
+ const finalOutputBytes = Buffer.byteLength(outputContent, "utf-8");
93
+ return {
94
+ content: outputContent,
95
+ truncated: true,
96
+ truncatedBy,
97
+ totalLines,
98
+ totalBytes,
99
+ outputLines: outputLinesArr.length,
100
+ outputBytes: finalOutputBytes,
101
+ lastLinePartial: false,
102
+ firstLineExceedsLimit: false,
103
+ maxLines,
104
+ maxBytes,
105
+ };
106
+ }
107
+ /**
108
+ * Truncate content from the tail (keep last N lines/bytes).
109
+ * Suitable for bash output where you want to see the end (errors, final results).
110
+ *
111
+ * May return partial first line if the last line of original content exceeds byte limit.
112
+ */
113
+ export function truncateTail(content, options = {}) {
114
+ const maxLines = options.maxLines ?? DEFAULT_MAX_LINES;
115
+ const maxBytes = options.maxBytes ?? DEFAULT_MAX_BYTES;
116
+ const totalBytes = Buffer.byteLength(content, "utf-8");
117
+ const lines = content.split("\n");
118
+ const totalLines = lines.length;
119
+ // Check if no truncation needed
120
+ if (totalLines <= maxLines && totalBytes <= maxBytes) {
121
+ return {
122
+ content,
123
+ truncated: false,
124
+ truncatedBy: null,
125
+ totalLines,
126
+ totalBytes,
127
+ outputLines: totalLines,
128
+ outputBytes: totalBytes,
129
+ lastLinePartial: false,
130
+ firstLineExceedsLimit: false,
131
+ maxLines,
132
+ maxBytes,
133
+ };
134
+ }
135
+ // Work backwards from the end
136
+ const outputLinesArr = [];
137
+ let outputBytesCount = 0;
138
+ let truncatedBy = "lines";
139
+ let lastLinePartial = false;
140
+ for (let i = lines.length - 1; i >= 0 && outputLinesArr.length < maxLines; i--) {
141
+ const line = lines[i];
142
+ const lineBytes = Buffer.byteLength(line, "utf-8") + (outputLinesArr.length > 0 ? 1 : 0); // +1 for newline
143
+ if (outputBytesCount + lineBytes > maxBytes) {
144
+ truncatedBy = "bytes";
145
+ // Edge case: if we haven't added ANY lines yet and this line exceeds maxBytes,
146
+ // take the end of the line (partial)
147
+ if (outputLinesArr.length === 0) {
148
+ const truncatedLine = truncateStringToBytesFromEnd(line, maxBytes);
149
+ outputLinesArr.unshift(truncatedLine);
150
+ outputBytesCount = Buffer.byteLength(truncatedLine, "utf-8");
151
+ lastLinePartial = true;
152
+ }
153
+ break;
154
+ }
155
+ outputLinesArr.unshift(line);
156
+ outputBytesCount += lineBytes;
157
+ }
158
+ // If we exited due to line limit
159
+ if (outputLinesArr.length >= maxLines && outputBytesCount <= maxBytes) {
160
+ truncatedBy = "lines";
161
+ }
162
+ const outputContent = outputLinesArr.join("\n");
163
+ const finalOutputBytes = Buffer.byteLength(outputContent, "utf-8");
164
+ return {
165
+ content: outputContent,
166
+ truncated: true,
167
+ truncatedBy,
168
+ totalLines,
169
+ totalBytes,
170
+ outputLines: outputLinesArr.length,
171
+ outputBytes: finalOutputBytes,
172
+ lastLinePartial,
173
+ firstLineExceedsLimit: false,
174
+ maxLines,
175
+ maxBytes,
176
+ };
177
+ }
178
+ /**
179
+ * Truncate a string to fit within a byte limit (from the end).
180
+ * Handles multi-byte UTF-8 characters correctly.
181
+ */
182
+ function truncateStringToBytesFromEnd(str, maxBytes) {
183
+ const buf = Buffer.from(str, "utf-8");
184
+ if (buf.length <= maxBytes) {
185
+ return str;
186
+ }
187
+ // Start from the end, skip maxBytes back
188
+ let start = buf.length - maxBytes;
189
+ // Find a valid UTF-8 boundary (start of a character)
190
+ while (start < buf.length && (buf[start] & 0xc0) === 0x80) {
191
+ start++;
192
+ }
193
+ return buf.slice(start).toString("utf-8");
194
+ }
195
+ /**
196
+ * Truncate a single line to max characters, adding [truncated] suffix.
197
+ * Used for grep match lines.
198
+ */
199
+ export function truncateLine(line, maxChars = GREP_MAX_LINE_LENGTH) {
200
+ if (line.length <= maxChars) {
201
+ return { text: line, wasTruncated: false };
202
+ }
203
+ return { text: `${line.slice(0, maxChars)}... [truncated]`, wasTruncated: true };
204
+ }
205
+ //# sourceMappingURL=truncate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"truncate.js","sourceRoot":"","sources":["../../../../../src/vendor/pi-agent-core/harness/utils/truncate.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,CAAC;AACtC,MAAM,CAAC,MAAM,iBAAiB,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,OAAO;AACnD,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAG,CAAC,CAA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ectEntriesForBranchSummary, generateBranchSummary, prepareBranchEntries, } from "./harness/compaction/branch-summarization.js";
5
+ export { calculateContextTokens, compact, DEFAULT_COMPACTION_SETTINGS, estimateContextTokens, estimateTokens, findCutPoint, findTurnStartIndex, generateSummary, getLastAssistantUsage, prepareCompaction, serializeConversation, shouldCompact, } from "./harness/compaction/compaction.js";
6
+ export * from "./harness/execution-env.js";
7
+ export * from "./harness/messages.js";
8
+ export * from "./harness/prompt-templates.js";
9
+ export * from "./harness/session/repo/jsonl.js";
10
+ export * from "./harness/session/repo/memory.js";
11
+ export * from "./harness/session/repo/shared.js";
12
+ export * from "./harness/session/session.js";
13
+ export { uuidv7 } from "./harness/session/uuid.js";
14
+ export * from "./harness/skills.js";
15
+ export * from "./harness/system-prompt.js";
16
+ export * from "./harness/types.js";
17
+ export * from "./harness/utils/shell-output.js";
18
+ export * from "./harness/utils/truncate.js";
19
+ export * from "./proxy.js";
20
+ export * from "./types.js";
21
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/vendor/pi-agent-core/index.ts"],"names":[],"mappings":"AACA,cAAc,YAAY,CAAC;AAE3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,4BAA4B,CAAC;AAC3C,OAAO,EACN,8BAA8B,EAC9B,qBAAqB,EACrB,oBAAoB,GACpB,MAAM,8CAA8C,CAAC;AACtD,OAAO,EACN,sBAAsB,EACtB,OAAO,EACP,2BAA2B,EAC3B,qBAAqB,EACrB,cAAc,EACd,YAAY,EACZ,kBAAkB,EAClB,eAAe,EACf,qBAAqB,EACrB,iBAAiB,EACjB,qBAAqB,EACrB,aAAa,GACb,MAAM,oCAAoC,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,iCAAiC,CAAC;AAChD,cAAc,kCAAkC,CAAC;AACjD,cAAc,kCAAkC,CAAC;AACjD,cAAc,8BAA8B,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACnD,cAAc,qBAAqB,CAAC;AACpC,cAAc,4BAA4B,CAAC;AAE3C,cAAc,oBAAoB,CAAC;AACnC,cAAc,iCAAiC,CAAC;AAChD,cAAc,6BAA6B,CAAC;AAE5C,cAAc,YAAY,CAAC;AAE3B,cAAc,YAAY,CAAC"}
@@ -0,0 +1,26 @@
1
+ // Core Agent
2
+ export * from "./agent.js";
3
+ // Loop functions
4
+ export * from "./agent-loop.js";
5
+ export * from "./harness/agent-harness.js";
6
+ export { collectEntriesForBranchSummary, generateBranchSummary, prepareBranchEntries, } from "./harness/compaction/branch-summarization.js";
7
+ export { calculateContextTokens, compact, DEFAULT_COMPACTION_SETTINGS, estimateContextTokens, estimateTokens, findCutPoint, findTurnStartIndex, generateSummary, getLastAssistantUsage, prepareCompaction, serializeConversation, shouldCompact, } from "./harness/compaction/compaction.js";
8
+ export * from "./harness/execution-env.js";
9
+ export * from "./harness/messages.js";
10
+ export * from "./harness/prompt-templates.js";
11
+ export * from "./harness/session/repo/jsonl.js";
12
+ export * from "./harness/session/repo/memory.js";
13
+ export * from "./harness/session/repo/shared.js";
14
+ export * from "./harness/session/session.js";
15
+ export { uuidv7 } from "./harness/session/uuid.js";
16
+ export * from "./harness/skills.js";
17
+ export * from "./harness/system-prompt.js";
18
+ // Harness
19
+ export * from "./harness/types.js";
20
+ export * from "./harness/utils/shell-output.js";
21
+ export * from "./harness/utils/truncate.js";
22
+ // Proxy utilities
23
+ export * from "./proxy.js";
24
+ // Types
25
+ export * from "./types.js";
26
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/vendor/pi-agent-core/index.ts"],"names":[],"mappings":"AAAA,aAAa;AACb,cAAc,YAAY,CAAC;AAC3B,iBAAiB;AACjB,cAAc,iBAAiB,CAAC;AAChC,cAAc,4BAA4B,CAAC;AAC3C,OAAO,EACN,8BAA8B,EAC9B,qBAAqB,EACrB,oBAAoB,GACpB,MAAM,8CAA8C,CAAC;AACtD,OAAO,EACN,sBAAsB,EACtB,OAAO,EACP,2BAA2B,EAC3B,qBAAqB,EACrB,cAAc,EACd,YAAY,EACZ,kBAAkB,EAClB,eAAe,EACf,qBAAqB,EACrB,iBAAiB,EACjB,qBAAqB,EACrB,aAAa,GACb,MAAM,oCAAoC,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,iCAAiC,CAAC;AAChD,cAAc,kCAAkC,CAAC;AACjD,cAAc,kCAAkC,CAAC;AACjD,cAAc,8BAA8B,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACnD,cAAc,qBAAqB,CAAC;AACpC,cAAc,4BAA4B,CAAC;AAC3C,UAAU;AACV,cAAc,oBAAoB,CAAC;AACnC,cAAc,iCAAiC,CAAC;AAChD,cAAc,6BAA6B,CAAC;AAC5C,kBAAkB;AAClB,cAAc,YAAY,CAAC;AAC3B,QAAQ;AACR,cAAc,YAAY,CAAC"}
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Proxy stream function for apps that route LLM calls through a server.
3
+ * The server manages auth and proxies requests to LLM providers.
4
+ */
5
+ import { type AssistantMessage, type AssistantMessageEvent, type Context, EventStream, type Model, type SimpleStreamOptions, type StopReason } from "@earendil-works/pi-ai";
6
+ declare class ProxyMessageEventStream extends EventStream<AssistantMessageEvent, AssistantMessage> {
7
+ constructor();
8
+ }
9
+ /**
10
+ * Proxy event types - server sends these with partial field stripped to reduce bandwidth.
11
+ */
12
+ export type ProxyAssistantMessageEvent = {
13
+ type: "start";
14
+ } | {
15
+ type: "text_start";
16
+ contentIndex: number;
17
+ } | {
18
+ type: "text_delta";
19
+ contentIndex: number;
20
+ delta: string;
21
+ } | {
22
+ type: "text_end";
23
+ contentIndex: number;
24
+ contentSignature?: string;
25
+ } | {
26
+ type: "thinking_start";
27
+ contentIndex: number;
28
+ } | {
29
+ type: "thinking_delta";
30
+ contentIndex: number;
31
+ delta: string;
32
+ } | {
33
+ type: "thinking_end";
34
+ contentIndex: number;
35
+ contentSignature?: string;
36
+ } | {
37
+ type: "toolcall_start";
38
+ contentIndex: number;
39
+ id: string;
40
+ toolName: string;
41
+ } | {
42
+ type: "toolcall_delta";
43
+ contentIndex: number;
44
+ delta: string;
45
+ } | {
46
+ type: "toolcall_end";
47
+ contentIndex: number;
48
+ } | {
49
+ type: "done";
50
+ reason: Extract<StopReason, "stop" | "length" | "toolUse">;
51
+ usage: AssistantMessage["usage"];
52
+ } | {
53
+ type: "error";
54
+ reason: Extract<StopReason, "aborted" | "error">;
55
+ errorMessage?: string;
56
+ usage: AssistantMessage["usage"];
57
+ };
58
+ type ProxySerializableStreamOptions = Pick<SimpleStreamOptions, "temperature" | "maxTokens" | "reasoning" | "cacheRetention" | "sessionId" | "headers" | "metadata" | "transport" | "thinkingBudgets" | "maxRetryDelayMs">;
59
+ export interface ProxyStreamOptions extends ProxySerializableStreamOptions {
60
+ /** Local abort signal for the proxy request */
61
+ signal?: AbortSignal;
62
+ /** Auth token for the proxy server */
63
+ authToken: string;
64
+ /** Proxy server URL (e.g., "https://genai.example.com") */
65
+ proxyUrl: string;
66
+ }
67
+ export declare function streamProxy(model: Model<any>, context: Context, options: ProxyStreamOptions): ProxyMessageEventStream;
68
+ export {};
69
+ //# sourceMappingURL=proxy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../../../src/vendor/pi-agent-core/proxy.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EACN,KAAK,gBAAgB,EACrB,KAAK,qBAAqB,EAC1B,KAAK,OAAO,EACZ,WAAW,EACX,KAAK,KAAK,EAEV,KAAK,mBAAmB,EACxB,KAAK,UAAU,EAEf,MAAM,uBAAuB,CAA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