@sorbetai/tools-node 0.1.0-alpha.17 → 0.1.0-alpha.18
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.d.ts +13 -1
- package/dist/index.js +43 -44
- package/dist/index.js.map +1 -1
- package/dist/plugin/workspace-component.js +856 -687
- package/package.json +8 -8
package/dist/index.d.ts
CHANGED
|
@@ -121,6 +121,18 @@ interface CommandTaskOptions {
|
|
|
121
121
|
readonly maxCompleted?: number;
|
|
122
122
|
/** Explicit retained-output quota; omitted streams the complete output to disk. */
|
|
123
123
|
readonly maxOutputBytes?: number;
|
|
124
|
+
/**
|
|
125
|
+
* Execution ceiling in seconds applied when a command omits its own timeout;
|
|
126
|
+
* defaults to 1,800. An explicit `timeout` always wins. Omit only to leave
|
|
127
|
+
* commands unbounded.
|
|
128
|
+
*/
|
|
129
|
+
readonly defaultTimeoutSeconds?: number;
|
|
130
|
+
/**
|
|
131
|
+
* Seconds of output silence after which a backgrounded command is stopped;
|
|
132
|
+
* defaults to 300. Foreground commands are never idle-killed — silence there
|
|
133
|
+
* may be legitimate work.
|
|
134
|
+
*/
|
|
135
|
+
readonly backgroundIdleSeconds?: number;
|
|
124
136
|
}
|
|
125
137
|
//#endregion
|
|
126
138
|
//#region src/commands/tasks.d.ts
|
|
@@ -515,7 +527,7 @@ declare function createWorkspacePluginPackage(): Promise<StoredPluginPackage>;
|
|
|
515
527
|
interface CommandJournal {
|
|
516
528
|
readFacts(options?: JournalReadOptions): Promise<JournalPage>;
|
|
517
529
|
}
|
|
518
|
-
type CommandExecutionOptions = Pick<CommandTaskOptions, 'foregroundMs' | 'maxProcesses' | 'maxCompleted' | 'maxOutputBytes'>;
|
|
530
|
+
type CommandExecutionOptions = Pick<CommandTaskOptions, 'foregroundMs' | 'maxProcesses' | 'maxCompleted' | 'maxOutputBytes' | 'defaultTimeoutSeconds' | 'backgroundIdleSeconds'>;
|
|
519
531
|
/** Node Host owns processes and evidence; Core owns the originating Tool Effect. */
|
|
520
532
|
declare class SessionCommands {
|
|
521
533
|
#private;
|
package/dist/index.js
CHANGED
|
@@ -11,7 +11,7 @@ import toError from "ensure-error";
|
|
|
11
11
|
import { tmpdir } from "node:os";
|
|
12
12
|
import * as Context from "effect/Context";
|
|
13
13
|
import * as Effect from "effect/Effect";
|
|
14
|
-
import { JsonValueSchema, RunInputProjection, defineTask } from "@sorbetai/runtime";
|
|
14
|
+
import { JsonValueSchema, RunInputProjection, defineTask, readPagesToEnd } from "@sorbetai/runtime";
|
|
15
15
|
import { fileTypeFromBuffer } from "file-type";
|
|
16
16
|
import * as photon from "@silvia-odwyer/photon-node";
|
|
17
17
|
import * as Diff from "diff";
|
|
@@ -218,7 +218,8 @@ var CommandTasks = class {
|
|
|
218
218
|
outputLimitExceeded: false,
|
|
219
219
|
wallTime: 0
|
|
220
220
|
};
|
|
221
|
-
|
|
221
|
+
const timeoutSeconds = input.timeout ?? this.#options.defaultTimeoutSeconds ?? 1800;
|
|
222
|
+
result.timeoutAt = new Date(Date.now() + timeoutSeconds * 1e3).toISOString();
|
|
222
223
|
let resolve$1 = (_result) => {};
|
|
223
224
|
let reject = (_failure) => {};
|
|
224
225
|
let markReady = () => {};
|
|
@@ -328,7 +329,17 @@ var CommandTasks = class {
|
|
|
328
329
|
task.stopReason = "timed_out";
|
|
329
330
|
task.controller.abort();
|
|
330
331
|
}, Math.max(0, Date.parse(result.timeoutAt) - Date.parse(task.record.startedAt) - (performance.now() - task.startTime)));
|
|
332
|
+
const idleMs = (this.#options.backgroundIdleSeconds ?? 300) * 1e3;
|
|
333
|
+
let lastOutputAt = Date.now();
|
|
334
|
+
const idleCheck = setInterval(() => {
|
|
335
|
+
if (task.record.background === true && Date.now() - lastOutputAt >= idleMs) {
|
|
336
|
+
task.stopReason = "timed_out";
|
|
337
|
+
task.controller.abort();
|
|
338
|
+
}
|
|
339
|
+
}, Math.min(idleMs, 6e4));
|
|
340
|
+
idleCheck.unref();
|
|
331
341
|
const append = (text) => {
|
|
342
|
+
lastOutputAt = Date.now();
|
|
332
343
|
const bytes = Buffer.from(text);
|
|
333
344
|
const remaining = this.#limits.maxOutputBytes === void 0 ? bytes.length : Math.max(0, this.#limits.maxOutputBytes - result.outputBytes);
|
|
334
345
|
const retained = bytes.subarray(0, remaining);
|
|
@@ -405,6 +416,7 @@ var CommandTasks = class {
|
|
|
405
416
|
};
|
|
406
417
|
} finally {
|
|
407
418
|
clearTimeout(deadline);
|
|
419
|
+
clearInterval(idleCheck);
|
|
408
420
|
closeSync(fd);
|
|
409
421
|
task.detach();
|
|
410
422
|
task.detach = () => {};
|
|
@@ -1385,19 +1397,7 @@ function truncateHead(content, options = {}) {
|
|
|
1385
1397
|
const totalBytes = Buffer.byteLength(content, "utf-8");
|
|
1386
1398
|
const lines = splitLinesForCounting(content);
|
|
1387
1399
|
const totalLines = lines.length;
|
|
1388
|
-
if (totalLines <= maxLines && totalBytes <= maxBytes) return
|
|
1389
|
-
content,
|
|
1390
|
-
truncated: false,
|
|
1391
|
-
truncatedBy: null,
|
|
1392
|
-
totalLines,
|
|
1393
|
-
totalBytes,
|
|
1394
|
-
outputLines: totalLines,
|
|
1395
|
-
outputBytes: totalBytes,
|
|
1396
|
-
lastLinePartial: false,
|
|
1397
|
-
firstLineExceedsLimit: false,
|
|
1398
|
-
maxLines,
|
|
1399
|
-
maxBytes
|
|
1400
|
-
};
|
|
1400
|
+
if (totalLines <= maxLines && totalBytes <= maxBytes) return wholeResult(content, totalLines, totalBytes, maxLines, maxBytes);
|
|
1401
1401
|
if (Buffer.byteLength(lines[0] ?? "", "utf-8") > maxBytes) return {
|
|
1402
1402
|
content: "",
|
|
1403
1403
|
truncated: true,
|
|
@@ -1424,12 +1424,10 @@ function truncateHead(content, options = {}) {
|
|
|
1424
1424
|
outputLinesArr.push(line);
|
|
1425
1425
|
outputBytesCount += lineBytes;
|
|
1426
1426
|
}
|
|
1427
|
-
if (outputLinesArr.length >= maxLines && outputBytesCount <= maxBytes) truncatedBy = "lines";
|
|
1428
1427
|
const outputContent = outputLinesArr.join("\n");
|
|
1429
1428
|
const finalOutputBytes = Buffer.byteLength(outputContent, "utf-8");
|
|
1430
|
-
return {
|
|
1429
|
+
return truncatedResult({
|
|
1431
1430
|
content: outputContent,
|
|
1432
|
-
truncated: true,
|
|
1433
1431
|
truncatedBy,
|
|
1434
1432
|
totalLines,
|
|
1435
1433
|
totalBytes,
|
|
@@ -1439,7 +1437,7 @@ function truncateHead(content, options = {}) {
|
|
|
1439
1437
|
firstLineExceedsLimit: false,
|
|
1440
1438
|
maxLines,
|
|
1441
1439
|
maxBytes
|
|
1442
|
-
};
|
|
1440
|
+
});
|
|
1443
1441
|
}
|
|
1444
1442
|
/**
|
|
1445
1443
|
* Truncate content from the tail (keep last N lines/bytes).
|
|
@@ -1453,19 +1451,7 @@ function truncateTail(content, options = {}) {
|
|
|
1453
1451
|
const totalBytes = Buffer.byteLength(content, "utf-8");
|
|
1454
1452
|
const lines = splitLinesForCounting(content);
|
|
1455
1453
|
const totalLines = lines.length;
|
|
1456
|
-
if (totalLines <= maxLines && totalBytes <= maxBytes) return
|
|
1457
|
-
content,
|
|
1458
|
-
truncated: false,
|
|
1459
|
-
truncatedBy: null,
|
|
1460
|
-
totalLines,
|
|
1461
|
-
totalBytes,
|
|
1462
|
-
outputLines: totalLines,
|
|
1463
|
-
outputBytes: totalBytes,
|
|
1464
|
-
lastLinePartial: false,
|
|
1465
|
-
firstLineExceedsLimit: false,
|
|
1466
|
-
maxLines,
|
|
1467
|
-
maxBytes
|
|
1468
|
-
};
|
|
1454
|
+
if (totalLines <= maxLines && totalBytes <= maxBytes) return wholeResult(content, totalLines, totalBytes, maxLines, maxBytes);
|
|
1469
1455
|
const outputLinesArr = [];
|
|
1470
1456
|
let outputBytesCount = 0;
|
|
1471
1457
|
let truncatedBy = "lines";
|
|
@@ -1486,12 +1472,10 @@ function truncateTail(content, options = {}) {
|
|
|
1486
1472
|
outputLinesArr.unshift(line);
|
|
1487
1473
|
outputBytesCount += lineBytes;
|
|
1488
1474
|
}
|
|
1489
|
-
if (outputLinesArr.length >= maxLines && outputBytesCount <= maxBytes) truncatedBy = "lines";
|
|
1490
1475
|
const outputContent = outputLinesArr.join("\n");
|
|
1491
1476
|
const finalOutputBytes = Buffer.byteLength(outputContent, "utf-8");
|
|
1492
|
-
return {
|
|
1477
|
+
return truncatedResult({
|
|
1493
1478
|
content: outputContent,
|
|
1494
|
-
truncated: true,
|
|
1495
1479
|
truncatedBy,
|
|
1496
1480
|
totalLines,
|
|
1497
1481
|
totalBytes,
|
|
@@ -1501,6 +1485,27 @@ function truncateTail(content, options = {}) {
|
|
|
1501
1485
|
firstLineExceedsLimit: false,
|
|
1502
1486
|
maxLines,
|
|
1503
1487
|
maxBytes
|
|
1488
|
+
});
|
|
1489
|
+
}
|
|
1490
|
+
function wholeResult(content, totalLines, totalBytes, maxLines, maxBytes) {
|
|
1491
|
+
return {
|
|
1492
|
+
content,
|
|
1493
|
+
truncated: false,
|
|
1494
|
+
truncatedBy: null,
|
|
1495
|
+
totalLines,
|
|
1496
|
+
totalBytes,
|
|
1497
|
+
outputLines: totalLines,
|
|
1498
|
+
outputBytes: totalBytes,
|
|
1499
|
+
lastLinePartial: false,
|
|
1500
|
+
firstLineExceedsLimit: false,
|
|
1501
|
+
maxLines,
|
|
1502
|
+
maxBytes
|
|
1503
|
+
};
|
|
1504
|
+
}
|
|
1505
|
+
function truncatedResult(result) {
|
|
1506
|
+
return {
|
|
1507
|
+
...result,
|
|
1508
|
+
truncated: true
|
|
1504
1509
|
};
|
|
1505
1510
|
}
|
|
1506
1511
|
/**
|
|
@@ -2737,7 +2742,7 @@ var NodeWorkspace = class NodeWorkspace {
|
|
|
2737
2742
|
|
|
2738
2743
|
//#endregion
|
|
2739
2744
|
//#region package.json
|
|
2740
|
-
var version = "0.1.0-alpha.
|
|
2745
|
+
var version = "0.1.0-alpha.18";
|
|
2741
2746
|
|
|
2742
2747
|
//#endregion
|
|
2743
2748
|
//#region src/plugins/workspace-component.ts
|
|
@@ -3082,12 +3087,9 @@ var SessionCommands = class {
|
|
|
3082
3087
|
try {
|
|
3083
3088
|
let cursor = this.#runStartCursor;
|
|
3084
3089
|
let requested;
|
|
3085
|
-
|
|
3086
|
-
while (hasMore) {
|
|
3087
|
-
const page = await this.#boundRuntime().readFacts({ after: cursor });
|
|
3090
|
+
for await (const page of readPagesToEnd((pageOptions) => this.#boundRuntime().readFacts(pageOptions), this.#runStartCursor)) {
|
|
3088
3091
|
for (const fact of page.facts) if (fact.kind === "effect.requested" && fact.runId === runId && fact.payload.toolCallId === toolCallId) requested = fact;
|
|
3089
3092
|
cursor = page.cursor;
|
|
3090
|
-
hasMore = page.hasMore;
|
|
3091
3093
|
}
|
|
3092
3094
|
this.#cursor = cursor;
|
|
3093
3095
|
if (requested === void 0) throw new Error("Command execution requires a committed Effect intent");
|
|
@@ -3155,9 +3157,7 @@ var SessionCommands = class {
|
|
|
3155
3157
|
async #refreshCoverage() {
|
|
3156
3158
|
await this.#coverageLock.acquire();
|
|
3157
3159
|
try {
|
|
3158
|
-
|
|
3159
|
-
while (hasMore) {
|
|
3160
|
-
const page = await this.#boundRuntime().readFacts({ after: this.#coverageCursor });
|
|
3160
|
+
for await (const page of readPagesToEnd((pageOptions) => this.#boundRuntime().readFacts(pageOptions), this.#coverageCursor)) {
|
|
3161
3161
|
for (const fact of page.facts) {
|
|
3162
3162
|
if (fact.kind === "submission.withdrawn" && DeliveredWithdrawals.some((prefix) => fact.payload.commandId.startsWith(prefix))) this.#covered.add(fact.operationId);
|
|
3163
3163
|
const input = this.#inputs.apply(fact);
|
|
@@ -3181,7 +3181,6 @@ var SessionCommands = class {
|
|
|
3181
3181
|
if (fact.kind === "model.request.unknown") this.#requests.delete(fact.payload.modelRequestId);
|
|
3182
3182
|
}
|
|
3183
3183
|
this.#coverageCursor = page.cursor;
|
|
3184
|
-
hasMore = page.hasMore;
|
|
3185
3184
|
}
|
|
3186
3185
|
} finally {
|
|
3187
3186
|
this.#coverageLock.release();
|