@operad-io/harness-process 0.3.1 → 0.4.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/package.json +4 -4
- package/src/jsonl-log.ts +1 -1
- package/src/keep.ts +1 -1
- package/src/step.ts +19 -1
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@operad-io/harness-process",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./src/index.ts"
|
|
7
7
|
},
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@operad-io/access-match": "0.
|
|
10
|
-
"@operad-io/engine": "0.
|
|
11
|
-
"@operad-io/mcp": "0.
|
|
9
|
+
"@operad-io/access-match": "0.4.1",
|
|
10
|
+
"@operad-io/engine": "0.4.1",
|
|
11
|
+
"@operad-io/mcp": "0.4.1"
|
|
12
12
|
},
|
|
13
13
|
"description": "operad: the shared process and log helpers of the harness plugins",
|
|
14
14
|
"repository": {
|
package/src/jsonl-log.ts
CHANGED
|
@@ -89,7 +89,7 @@ export class JsonlLog {
|
|
|
89
89
|
|
|
90
90
|
/** Writes the rest and waits for every queued write. */
|
|
91
91
|
async end(): Promise<void> {
|
|
92
|
-
this.flush();
|
|
92
|
+
void this.flush();
|
|
93
93
|
if (!this.wrote) {
|
|
94
94
|
this.chain = this.chain.then(() => this.logger.write("")).then(() => undefined);
|
|
95
95
|
}
|
package/src/keep.ts
CHANGED
|
@@ -46,7 +46,7 @@ function canonical(value: unknown): unknown {
|
|
|
46
46
|
* they do not name the worker.
|
|
47
47
|
*/
|
|
48
48
|
export function keepKeyOf(config: Readonly<Record<string, unknown>>): string {
|
|
49
|
-
const { prompt: _prompt, images: _images, resumeSession: _resume, ...rest } = config;
|
|
49
|
+
const { prompt: _prompt, images: _images, resumeSession: _resume, compact: _compact, ...rest } = config;
|
|
50
50
|
const accessValue = rest["access"];
|
|
51
51
|
const access =
|
|
52
52
|
typeof accessValue === "object" && accessValue !== null
|
package/src/step.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { directoryError } from "@operad-io/engine";
|
|
8
|
-
import type { AgentResultData, CostQuality, PluginStepResult } from "@operad-io/engine";
|
|
8
|
+
import type { AgentCompaction, AgentResultData, CostQuality, PluginStepResult } from "@operad-io/engine";
|
|
9
9
|
import { MAX_SKIPPED_LINE_CHARS, type AgentRunOutcome } from "./process.ts";
|
|
10
10
|
import { standardUsage, type RawCounts, type UsageSource } from "./usage.ts";
|
|
11
11
|
import { isRecord } from "@operad-io/engine";
|
|
@@ -26,6 +26,8 @@ export interface AgentWorkerResult {
|
|
|
26
26
|
readonly incomplete?: true;
|
|
27
27
|
} | null;
|
|
28
28
|
readonly finalMessage: string | null;
|
|
29
|
+
/** Set when this run compacted the session: tokens before and after, and whether a memory flush ran first. */
|
|
30
|
+
readonly compaction?: AgentCompaction | undefined;
|
|
29
31
|
/** The model that did the work, when the worker reports it. */
|
|
30
32
|
readonly model?: string | null;
|
|
31
33
|
/** The context at the end of a finished reply, when the worker can tell. */
|
|
@@ -217,6 +219,20 @@ export function contextOf(value: unknown): { readonly used: number; readonly win
|
|
|
217
219
|
return { used, ...(known === undefined ? {} : { window: known }) };
|
|
218
220
|
}
|
|
219
221
|
|
|
222
|
+
/** A worker's compaction note, when it has one in the shape the chat reads. */
|
|
223
|
+
function compactionOf(value: unknown): AgentCompaction | undefined {
|
|
224
|
+
if (!isRecord(value)) return undefined;
|
|
225
|
+
const before = value.before;
|
|
226
|
+
const after = value.after;
|
|
227
|
+
if (typeof before !== "number" || !Number.isFinite(before)) return undefined;
|
|
228
|
+
return {
|
|
229
|
+
reason: value.reason === "manual" ? "manual" : "threshold",
|
|
230
|
+
before,
|
|
231
|
+
...(typeof after === "number" && Number.isFinite(after) ? { after } : {}),
|
|
232
|
+
flushed: value.flushed === true,
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
|
|
220
236
|
export function agentData(
|
|
221
237
|
who: UsageSource,
|
|
222
238
|
outcome: AgentRunOutcome,
|
|
@@ -233,6 +249,7 @@ export function agentData(
|
|
|
233
249
|
estimated: result.cost.quality === "estimated",
|
|
234
250
|
};
|
|
235
251
|
const context = contextOf(result?.context);
|
|
252
|
+
const compaction = compactionOf(result?.compaction);
|
|
236
253
|
return {
|
|
237
254
|
exitCode: outcome.exitCode,
|
|
238
255
|
signal: outcome.signal,
|
|
@@ -241,6 +258,7 @@ export function agentData(
|
|
|
241
258
|
...(result?.message === undefined ? {} : { message: result.message }),
|
|
242
259
|
usage: standardUsage(who, result?.usage, cost),
|
|
243
260
|
...(context === undefined ? {} : { context }),
|
|
261
|
+
...(compaction === undefined ? {} : { compacted: true as const, compaction }),
|
|
244
262
|
log,
|
|
245
263
|
durationMs,
|
|
246
264
|
stderr: outcome.stderrTail,
|