@theokit/sdk-tools 0.25.0 → 0.26.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +27 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +40 -5
- package/dist/index.d.ts +40 -5
- package/dist/index.js +27 -6
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -13,6 +13,7 @@ var child_process = require('child_process');
|
|
|
13
13
|
var interactive = require('@theokit/sdk/interactive');
|
|
14
14
|
var promises$1 = require('dns/promises');
|
|
15
15
|
var net = require('net');
|
|
16
|
+
var crypto = require('crypto');
|
|
16
17
|
|
|
17
18
|
// src/apply-patch.ts
|
|
18
19
|
|
|
@@ -2545,24 +2546,44 @@ function createTodolistTool() {
|
|
|
2545
2546
|
getItems: (threadId) => ops(threadId).getItems()
|
|
2546
2547
|
};
|
|
2547
2548
|
}
|
|
2549
|
+
function decodeWholeCodePoints(buf) {
|
|
2550
|
+
return new TextDecoder("utf-8").decode(buf, { stream: true });
|
|
2551
|
+
}
|
|
2548
2552
|
function truncateOutput(output, opts) {
|
|
2549
2553
|
const maxBytes = opts?.maxBytes ?? 3e4;
|
|
2550
2554
|
const outputDir = opts?.outputDir ?? ".theocode/tool-output";
|
|
2551
|
-
const
|
|
2552
|
-
|
|
2553
|
-
|
|
2555
|
+
const mode = opts?.mode ?? "head";
|
|
2556
|
+
const originalBytes = Buffer.byteLength(output, "utf-8");
|
|
2557
|
+
if (originalBytes <= maxBytes) {
|
|
2558
|
+
return { content: output, truncated: false, originalBytes };
|
|
2554
2559
|
}
|
|
2555
2560
|
fs.mkdirSync(outputDir, { recursive: true });
|
|
2556
|
-
const filename = `overflow-${Date.now()}.txt`;
|
|
2561
|
+
const filename = `overflow-${Date.now()}-${crypto.randomUUID().slice(0, 8)}.txt`;
|
|
2557
2562
|
const overflowPath = path.join(outputDir, filename);
|
|
2558
2563
|
fs.writeFileSync(overflowPath, output, "utf-8");
|
|
2559
|
-
const
|
|
2564
|
+
const buf = Buffer.from(output, "utf-8");
|
|
2560
2565
|
const trailer = `
|
|
2561
2566
|
|
|
2562
2567
|
[Output truncated. Full output: ${overflowPath}]`;
|
|
2568
|
+
if (mode === "head-tail") {
|
|
2569
|
+
const half = Math.floor(maxBytes / 2);
|
|
2570
|
+
const head = decodeWholeCodePoints(buf.subarray(0, half));
|
|
2571
|
+
const tail = decodeWholeCodePoints(buf.subarray(buf.length - half));
|
|
2572
|
+
return {
|
|
2573
|
+
content: `${head}
|
|
2574
|
+
|
|
2575
|
+
[\u2026 ${String(originalBytes - maxBytes)} bytes omitted \u2026]
|
|
2576
|
+
|
|
2577
|
+
${tail}${trailer}`,
|
|
2578
|
+
truncated: true,
|
|
2579
|
+
originalBytes,
|
|
2580
|
+
overflowPath
|
|
2581
|
+
};
|
|
2582
|
+
}
|
|
2563
2583
|
return {
|
|
2564
|
-
content:
|
|
2584
|
+
content: decodeWholeCodePoints(buf.subarray(0, maxBytes)) + trailer,
|
|
2565
2585
|
truncated: true,
|
|
2586
|
+
originalBytes,
|
|
2566
2587
|
overflowPath
|
|
2567
2588
|
};
|
|
2568
2589
|
}
|