@foldrun/core 24.9.0 → 24.10.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.
- package/dist/src/engine-common.d.ts +4 -0
- package/dist/src/engine-common.js +1 -0
- package/dist/src/engine-loop.d.ts +5 -0
- package/dist/src/engine-loop.js +31 -1
- package/dist/src/ops-log.js +2 -2
- package/dist/src/providers.js +3 -3
- package/package.json +1 -1
- package/src/engine-common.ts +5 -0
- package/src/engine-loop.ts +31 -1
- package/src/ops-log.ts +2 -2
- package/src/providers.ts +3 -3
|
@@ -65,6 +65,10 @@ export interface LoopOptions {
|
|
|
65
65
|
reserveTokens: number;
|
|
66
66
|
keepRecentTokens: number;
|
|
67
67
|
} | false;
|
|
68
|
+
/** Steering (FOL-213): what a person sent while the turn runs, taken
|
|
69
|
+
* (and so removed) each time it is called. The model reads it after the
|
|
70
|
+
* calls it is making, or, about to finish, reads it and goes on. */
|
|
71
|
+
steer: (() => unknown[]) | null;
|
|
68
72
|
}
|
|
69
73
|
export declare function hookFns(hooks: unknown, event: string): HookFn[];
|
|
70
74
|
/** The SDK's options, as this engine reads them. What it cannot honour it
|
|
@@ -98,6 +98,7 @@ export function readOptions(options, engine = "foldrun") {
|
|
|
98
98
|
history: readHistory(options.history),
|
|
99
99
|
mcpServers,
|
|
100
100
|
mcpGranted: mcpTools,
|
|
101
|
+
steer: typeof options.steer === "function" ? options.steer : null,
|
|
101
102
|
compaction: options.compaction === false ? false : compactionFor(typeof options.contextWindow === "number" && Number.isFinite(options.contextWindow) && options.contextWindow >= MIN_CONTEXT_WINDOW ? Math.floor(options.contextWindow) : COMPACTION_DEFAULTS.contextWindow),
|
|
102
103
|
};
|
|
103
104
|
}
|
|
@@ -12,6 +12,11 @@ export type Engine = "sdk" | "foldrun";
|
|
|
12
12
|
* included, so a half-written answer passed as a finished step (FOL-211).
|
|
13
13
|
* The partial reply is still the result's text; `errors` says why it is not
|
|
14
14
|
* a finish, the way the SDK's error results do. */
|
|
15
|
+
/** What this engine can do that a caller may ask about before relying on
|
|
16
|
+
* it: `steer` — messages sent while a turn runs (FOL-213). */
|
|
17
|
+
export declare const ENGINE_FEATURES: {
|
|
18
|
+
readonly steer: true;
|
|
19
|
+
};
|
|
15
20
|
export declare function endOf(stopReason: string | null, calls: number): {
|
|
16
21
|
subtype: string;
|
|
17
22
|
error?: string;
|
package/dist/src/engine-loop.js
CHANGED
|
@@ -65,6 +65,9 @@ function requestHeaders(env) {
|
|
|
65
65
|
* included, so a half-written answer passed as a finished step (FOL-211).
|
|
66
66
|
* The partial reply is still the result's text; `errors` says why it is not
|
|
67
67
|
* a finish, the way the SDK's error results do. */
|
|
68
|
+
/** What this engine can do that a caller may ask about before relying on
|
|
69
|
+
* it: `steer` — messages sent while a turn runs (FOL-213). */
|
|
70
|
+
export const ENGINE_FEATURES = { steer: true };
|
|
68
71
|
export function endOf(stopReason, calls) {
|
|
69
72
|
switch (stopReason) {
|
|
70
73
|
case "end_turn":
|
|
@@ -270,6 +273,19 @@ async function* run(prompt, o, signal, interrupted) {
|
|
|
270
273
|
const sessionId = crypto.randomUUID();
|
|
271
274
|
const startedAt = Date.now();
|
|
272
275
|
const byName = new Map(o.tools.map((t) => [t.name, t]));
|
|
276
|
+
/** What the person sent meanwhile, as text blocks: each a string with
|
|
277
|
+
* words in it, held to a sane size; anything else is dropped. */
|
|
278
|
+
// Taken only when the model will get it: not once the turn is stopped,
|
|
279
|
+
// nor when no request is left under maxTurns (Codex) — it stays with the
|
|
280
|
+
// caller, unsent.
|
|
281
|
+
const steered = () => {
|
|
282
|
+
if (!o.steer || interrupted() || signal.aborted || (o.maxTurns !== null && turns >= o.maxTurns))
|
|
283
|
+
return [];
|
|
284
|
+
const taken = o.steer();
|
|
285
|
+
return (Array.isArray(taken) ? taken : [])
|
|
286
|
+
.filter((t) => typeof t === "string" && t.trim() !== "")
|
|
287
|
+
.map((t) => ({ type: "text", text: t.slice(0, 20_000) }));
|
|
288
|
+
};
|
|
273
289
|
const ctx = { cwd: o.cwd, env: o.shellEnv, signal, reads: new Map(), groups: new Set() };
|
|
274
290
|
// An earlier conversation comes first (foldrun code's local turns carry
|
|
275
291
|
// theirs, 19 Nov 2026); the prompt is always the newest user turn.
|
|
@@ -503,6 +519,19 @@ async function* run(prompt, o, signal, interrupted) {
|
|
|
503
519
|
continue;
|
|
504
520
|
if (turn.stopReason !== "tool_use" || !calls.length) {
|
|
505
521
|
const end = endOf(turn.stopReason, calls.length);
|
|
522
|
+
// About to finish with a message from the person waiting: it is the
|
|
523
|
+
// next user turn, and the model goes on. Not after a turn that failed
|
|
524
|
+
// (it stays with the caller, unsent).
|
|
525
|
+
if (end.subtype === "success") {
|
|
526
|
+
const more = steered();
|
|
527
|
+
if (more.length) {
|
|
528
|
+
// A new question: the answer to come is its own, not this one (Codex).
|
|
529
|
+
lastText = "";
|
|
530
|
+
messages.push({ role: "user", content: more });
|
|
531
|
+
yield { type: "user", message: { role: "user", content: more }, parent_tool_use_id: null, session_id: sessionId };
|
|
532
|
+
continue;
|
|
533
|
+
}
|
|
534
|
+
}
|
|
506
535
|
// A turn that did not finish carries ITS text, empty included — not an
|
|
507
536
|
// earlier turn's "I'll check" passed off as a refusal's words (Codex).
|
|
508
537
|
yield end.error ? { ...result(end.subtype, turn.stopReason), result: text, errors: [end.error] } : result(end.subtype, turn.stopReason);
|
|
@@ -572,7 +601,8 @@ async function* run(prompt, o, signal, interrupted) {
|
|
|
572
601
|
return { type: "tool_result", tool_use_id: String(p.block.id), content, ...(isError ? { is_error: true } : {}) };
|
|
573
602
|
});
|
|
574
603
|
const context = done.flatMap((d) => d.context);
|
|
575
|
-
|
|
604
|
+
// After the results: what hooks add, then what the person sent meanwhile.
|
|
605
|
+
const content = [...results, ...context.map((c) => ({ type: "text", text: c })), ...steered()];
|
|
576
606
|
messages.push({ role: "user", content });
|
|
577
607
|
yield { type: "user", message: { role: "user", content }, parent_tool_use_id: null, session_id: sessionId };
|
|
578
608
|
}
|
package/dist/src/ops-log.js
CHANGED
|
@@ -178,7 +178,7 @@ const boundary = () => shared[BOUNDARY] ?? null;
|
|
|
178
178
|
export function opsBoundaryInstalled() {
|
|
179
179
|
return boundary() !== null;
|
|
180
180
|
}
|
|
181
|
-
function readable(
|
|
181
|
+
function readable(line, detail) {
|
|
182
182
|
const parts = Object.entries(line)
|
|
183
183
|
.filter(([k]) => k !== "ops" && k !== "level" && k !== "event")
|
|
184
184
|
.map(([k, v]) => `${k}=${Array.isArray(v) ? v.join(",") : String(v)}`);
|
|
@@ -192,7 +192,7 @@ function emit(level, line, detail) {
|
|
|
192
192
|
}
|
|
193
193
|
// No boundary: a laptop, a test, `next dev` — the reader is the person
|
|
194
194
|
// whose content it is, so the error's own words come along.
|
|
195
|
-
const text = readable(
|
|
195
|
+
const text = readable(line, detail);
|
|
196
196
|
if (level === "info")
|
|
197
197
|
console.log(text);
|
|
198
198
|
else if (level === "warn")
|
package/dist/src/providers.js
CHANGED
|
@@ -434,20 +434,20 @@ export function readBrowseSession(raw, key = "vendor_session") {
|
|
|
434
434
|
return { error: `${at} is a block — what the vendor's own session is asked for: proxy, captcha, stealth, region, timeout, keep, record, block, options.` };
|
|
435
435
|
}
|
|
436
436
|
const out = {};
|
|
437
|
-
const bool = (
|
|
437
|
+
const bool = (v) => (v === true || v === "true" ? true : v === false || v === "false" ? false : undefined);
|
|
438
438
|
for (const [k, v] of Object.entries(raw)) {
|
|
439
439
|
if (!SESSION_KEYS.includes(k))
|
|
440
440
|
return { error: `${at}.${k}: is not a session setting. They are ${SESSION_KEYS.join(", ")}.` };
|
|
441
441
|
if (v === undefined || v === null || v === "")
|
|
442
442
|
continue;
|
|
443
443
|
if (k === "captcha" || k === "stealth" || k === "record") {
|
|
444
|
-
const b = bool(
|
|
444
|
+
const b = bool(v);
|
|
445
445
|
if (b === undefined)
|
|
446
446
|
return { error: `${at}.${k} is true or false, not ${JSON.stringify(v)}.` };
|
|
447
447
|
out[k] = b;
|
|
448
448
|
}
|
|
449
449
|
else if (k === "proxy") {
|
|
450
|
-
const b = bool(
|
|
450
|
+
const b = bool(v);
|
|
451
451
|
if (b !== undefined) {
|
|
452
452
|
out.proxy = b;
|
|
453
453
|
continue;
|
package/package.json
CHANGED
package/src/engine-common.ts
CHANGED
|
@@ -70,6 +70,10 @@ export interface LoopOptions {
|
|
|
70
70
|
/** Compaction (engine-compact.ts): the model's context window, and false
|
|
71
71
|
* when the caller turned it off (`compaction: false`). */
|
|
72
72
|
compaction: { contextWindow: number; reserveTokens: number; keepRecentTokens: number } | false;
|
|
73
|
+
/** Steering (FOL-213): what a person sent while the turn runs, taken
|
|
74
|
+
* (and so removed) each time it is called. The model reads it after the
|
|
75
|
+
* calls it is making, or, about to finish, reads it and goes on. */
|
|
76
|
+
steer: (() => unknown[]) | null;
|
|
73
77
|
}
|
|
74
78
|
|
|
75
79
|
export function hookFns(hooks: unknown, event: string): HookFn[] {
|
|
@@ -140,6 +144,7 @@ export function readOptions(options: Json, engine = "foldrun"): LoopOptions {
|
|
|
140
144
|
history: readHistory(options.history),
|
|
141
145
|
mcpServers,
|
|
142
146
|
mcpGranted: mcpTools,
|
|
147
|
+
steer: typeof options.steer === "function" ? (options.steer as () => unknown[]) : null,
|
|
143
148
|
compaction: options.compaction === false ? false : compactionFor(
|
|
144
149
|
typeof options.contextWindow === "number" && Number.isFinite(options.contextWindow) && options.contextWindow >= MIN_CONTEXT_WINDOW ? Math.floor(options.contextWindow) : COMPACTION_DEFAULTS.contextWindow,
|
|
145
150
|
),
|
package/src/engine-loop.ts
CHANGED
|
@@ -70,6 +70,10 @@ function requestHeaders(env: Record<string, string | undefined>): Record<string,
|
|
|
70
70
|
* included, so a half-written answer passed as a finished step (FOL-211).
|
|
71
71
|
* The partial reply is still the result's text; `errors` says why it is not
|
|
72
72
|
* a finish, the way the SDK's error results do. */
|
|
73
|
+
/** What this engine can do that a caller may ask about before relying on
|
|
74
|
+
* it: `steer` — messages sent while a turn runs (FOL-213). */
|
|
75
|
+
export const ENGINE_FEATURES = { steer: true } as const;
|
|
76
|
+
|
|
73
77
|
export function endOf(stopReason: string | null, calls: number): { subtype: string; error?: string } {
|
|
74
78
|
switch (stopReason) {
|
|
75
79
|
case "end_turn":
|
|
@@ -258,6 +262,18 @@ async function* run(prompt: string, o: LoopOptions, signal: AbortSignal, interru
|
|
|
258
262
|
const sessionId = crypto.randomUUID();
|
|
259
263
|
const startedAt = Date.now();
|
|
260
264
|
const byName = new Map(o.tools.map((t) => [t.name, t]));
|
|
265
|
+
/** What the person sent meanwhile, as text blocks: each a string with
|
|
266
|
+
* words in it, held to a sane size; anything else is dropped. */
|
|
267
|
+
// Taken only when the model will get it: not once the turn is stopped,
|
|
268
|
+
// nor when no request is left under maxTurns (Codex) — it stays with the
|
|
269
|
+
// caller, unsent.
|
|
270
|
+
const steered = (): Block[] => {
|
|
271
|
+
if (!o.steer || interrupted() || signal.aborted || (o.maxTurns !== null && turns >= o.maxTurns)) return [];
|
|
272
|
+
const taken = o.steer();
|
|
273
|
+
return (Array.isArray(taken) ? taken : [])
|
|
274
|
+
.filter((t): t is string => typeof t === "string" && t.trim() !== "")
|
|
275
|
+
.map((t) => ({ type: "text", text: t.slice(0, 20_000) }));
|
|
276
|
+
};
|
|
261
277
|
const ctx: ToolContext = { cwd: o.cwd, env: o.shellEnv, signal, reads: new Map(), groups: new Set() };
|
|
262
278
|
// An earlier conversation comes first (foldrun code's local turns carry
|
|
263
279
|
// theirs, 19 Nov 2026); the prompt is always the newest user turn.
|
|
@@ -466,6 +482,19 @@ async function* run(prompt: string, o: LoopOptions, signal: AbortSignal, interru
|
|
|
466
482
|
if (turn.stopReason === "pause_turn" && !calls.length) continue;
|
|
467
483
|
if (turn.stopReason !== "tool_use" || !calls.length) {
|
|
468
484
|
const end = endOf(turn.stopReason, calls.length);
|
|
485
|
+
// About to finish with a message from the person waiting: it is the
|
|
486
|
+
// next user turn, and the model goes on. Not after a turn that failed
|
|
487
|
+
// (it stays with the caller, unsent).
|
|
488
|
+
if (end.subtype === "success") {
|
|
489
|
+
const more = steered();
|
|
490
|
+
if (more.length) {
|
|
491
|
+
// A new question: the answer to come is its own, not this one (Codex).
|
|
492
|
+
lastText = "";
|
|
493
|
+
messages.push({ role: "user", content: more });
|
|
494
|
+
yield { type: "user", message: { role: "user", content: more }, parent_tool_use_id: null, session_id: sessionId };
|
|
495
|
+
continue;
|
|
496
|
+
}
|
|
497
|
+
}
|
|
469
498
|
// A turn that did not finish carries ITS text, empty included — not an
|
|
470
499
|
// earlier turn's "I'll check" passed off as a refusal's words (Codex).
|
|
471
500
|
yield end.error ? { ...result(end.subtype, turn.stopReason), result: text, errors: [end.error] } : result(end.subtype, turn.stopReason);
|
|
@@ -533,7 +562,8 @@ async function* run(prompt: string, o: LoopOptions, signal: AbortSignal, interru
|
|
|
533
562
|
return { type: "tool_result", tool_use_id: String(p.block.id), content, ...(isError ? { is_error: true } : {}) };
|
|
534
563
|
});
|
|
535
564
|
const context = done.flatMap((d) => d.context);
|
|
536
|
-
|
|
565
|
+
// After the results: what hooks add, then what the person sent meanwhile.
|
|
566
|
+
const content: Block[] = [...results, ...context.map((c) => ({ type: "text", text: c })), ...steered()];
|
|
537
567
|
messages.push({ role: "user", content });
|
|
538
568
|
yield { type: "user", message: { role: "user", content }, parent_tool_use_id: null, session_id: sessionId };
|
|
539
569
|
}
|
package/src/ops-log.ts
CHANGED
|
@@ -198,7 +198,7 @@ export function opsBoundaryInstalled(): boolean {
|
|
|
198
198
|
return boundary() !== null;
|
|
199
199
|
}
|
|
200
200
|
|
|
201
|
-
function readable(
|
|
201
|
+
function readable(line: Record<string, unknown>, detail?: string): string {
|
|
202
202
|
const parts = Object.entries(line)
|
|
203
203
|
.filter(([k]) => k !== "ops" && k !== "level" && k !== "event")
|
|
204
204
|
.map(([k, v]) => `${k}=${Array.isArray(v) ? v.join(",") : String(v)}`);
|
|
@@ -213,7 +213,7 @@ function emit(level: OpsLevel, line: Record<string, unknown>, detail?: string):
|
|
|
213
213
|
}
|
|
214
214
|
// No boundary: a laptop, a test, `next dev` — the reader is the person
|
|
215
215
|
// whose content it is, so the error's own words come along.
|
|
216
|
-
const text = readable(
|
|
216
|
+
const text = readable(line, detail);
|
|
217
217
|
if (level === "info") console.log(text);
|
|
218
218
|
else if (level === "warn") console.warn(text);
|
|
219
219
|
else console.error(text);
|
package/src/providers.ts
CHANGED
|
@@ -778,16 +778,16 @@ export function readBrowseSession(raw: unknown, key: "vendor_session" | "session
|
|
|
778
778
|
return { error: `${at} is a block — what the vendor's own session is asked for: proxy, captcha, stealth, region, timeout, keep, record, block, options.` };
|
|
779
779
|
}
|
|
780
780
|
const out: BrowseSession = {};
|
|
781
|
-
const bool = (
|
|
781
|
+
const bool = (v: unknown) => (v === true || v === "true" ? true : v === false || v === "false" ? false : undefined);
|
|
782
782
|
for (const [k, v] of Object.entries(raw as Record<string, unknown>)) {
|
|
783
783
|
if (!(SESSION_KEYS as readonly string[]).includes(k)) return { error: `${at}.${k}: is not a session setting. They are ${SESSION_KEYS.join(", ")}.` };
|
|
784
784
|
if (v === undefined || v === null || v === "") continue;
|
|
785
785
|
if (k === "captcha" || k === "stealth" || k === "record") {
|
|
786
|
-
const b = bool(
|
|
786
|
+
const b = bool(v);
|
|
787
787
|
if (b === undefined) return { error: `${at}.${k} is true or false, not ${JSON.stringify(v)}.` };
|
|
788
788
|
out[k] = b;
|
|
789
789
|
} else if (k === "proxy") {
|
|
790
|
-
const b = bool(
|
|
790
|
+
const b = bool(v);
|
|
791
791
|
if (b !== undefined) { out.proxy = b; continue; }
|
|
792
792
|
if (typeof v !== "object" || Array.isArray(v)) return { error: `${at}.proxy is true, false, or a block: country, state, city — or own: a secret holding your proxy's URL.` };
|
|
793
793
|
const p: { country?: string; state?: string; city?: string; own?: string } = {};
|