foldrun 26.7.1 → 26.9.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/bin/foldrun.mjs +1 -1
- package/docs/cli.md +1 -1
- package/package.json +2 -2
- package/src/commands.mjs +193 -20
package/bin/foldrun.mjs
CHANGED
|
@@ -121,7 +121,7 @@ const HELP = `foldrun — agents are just folders
|
|
|
121
121
|
foldrun check --to <ws> --online also the network checks, run by the platform: known vulnerabilities for exact runtime pins (OSV) and remote MCP servers' tool text — and what could not be checked
|
|
122
122
|
foldrun agent run <name> run one agent once on the platform (--task "…", --to, --wait, --test, --context <id>, --file <path> repeatable)
|
|
123
123
|
foldrun agent run <name> --snapshot [dir|id] …on a folder: sent first (what git would commit, checked for secrets), the agent works on it in snapshot/, and the patch of its changes is on the run (foldrun report <run-id> patch)
|
|
124
|
-
foldrun code [dir] code with an agent on the platform: each message sends the folder (a snapshot), the agent works on it in its own sandbox, and you apply the patch it hands back after git apply --check (--to — made, with its coder agent, after a yes when it does not exist; --agent <name> (default coder, added on first use with a yes), --task "…" one turn and exit, --yes apply without asking, --test, --context <id
|
|
124
|
+
foldrun code [dir] code with an agent on the platform: each message sends the folder (a snapshot), the agent works on it in its own sandbox, and you apply the patch it hands back after git apply --check (--to — made, with its coder agent, after a yes when it does not exist; --agent <name> (default coder, added on first use with a yes), --task "…" one turn and exit, --yes apply without asking, --test, --context <id>, --verbose the platform's notes on each step too)
|
|
125
125
|
foldrun agent run <name> --no-task run it with no instruction, on its own prompt alone — the dashboard's Run (--to, --wait, --test)
|
|
126
126
|
foldrun agent link <agent> add to its team, in its frontmatter: --subagent <worker> (--isolated: sandbox: own on the worker), --consult <agent> or --can-ask (--description for a worker with none)
|
|
127
127
|
foldrun agent unlink <agent> take one away: --subagent <name>, --consult <name> or --can-ask
|
package/docs/cli.md
CHANGED
|
@@ -136,7 +136,7 @@ claude.ai or Claude Code there, nor any MCP configuration on disk.
|
|
|
136
136
|
| `foldrun export [workspace]` | a deployed project as a `.zip` — agents, flows, tools, skills, scripts, evals, knowledge; never memory, state, storage or a secret's value. `--flow <name>` exports that flow with every flow and agent it runs and the tools, skills and scripts they grant; `--agent <name>` that agent and what it grants. Written under the name the platform gives it (`<ws>.zip`, `<ws>-flow-<name>.zip`); `--file <path>` (`-` for stdout), `--force` to replace (`GET …/export`) |
|
|
137
137
|
| `foldrun import <file.zip>` | take a package in: first shows what it adds, what is identical, what it would replace and what it still needs (secrets, tools, skills, scripts, agents, flows), then asks. Never deletes; replacing a file needs `--overwrite`. `--to <workspace>` (a name that does not exist makes it, from a project package), `--dry-run` previews only (`--json` for the plan), `--yes` with no terminal (`POST …/import`) |
|
|
138
138
|
| `foldrun snapshot push [dir]` | send a folder for an agent on foldrun to work on (a snapshot). What goes is what git would commit — tracked files and untracked ones `.gitignore` does not exclude, as they are on disk; links and submodules are left out and named. A secret in any file stops it before anything leaves the machine (remove it, or leave the file out with `.gitignore`); the platform checks again. Answers the snapshot id, kept 7 days from the last send and while a run uses it. `--to <workspace>`, `--dry-run` packs and checks only, `--out <file.tar.gz>` keeps the archive (`--force` over a file that is there), `--json` (`POST …/snapshots`) |
|
|
139
|
-
| `foldrun code [dir]` | code with an agent that works in a sandbox on the platform, not on this computer — see [Coding in a sandbox](#coding-in-a-sandbox). Each message sends the folder as a snapshot (as `snapshot push` does), runs the agent on it in its own sandbox as a turn of one conversation, prints what it does as it does it, and offers the patch it hands back: `git apply --check`, git's stat, a yes, then `git apply`. Ctrl-C stops the run; `/new` starts a fresh conversation, `/quit` leaves. `--to <workspace>` (a project that does not exist is made, blank with its `coder` agent, after a yes), `--agent <name>` (default `coder`, added to the project on first use after a yes), `--task "…"` one turn and exit (for scripts), `--yes` applies without asking (required with no terminal), `--test`, `--context <id
|
|
139
|
+
| `foldrun code [dir]` | code with an agent that works in a sandbox on the platform, not on this computer — see [Coding in a sandbox](#coding-in-a-sandbox). Each message sends the folder as a snapshot (as `snapshot push` does), runs the agent on it in its own sandbox as a turn of one conversation, prints what it does as it does it (its tool calls and words, and any refusal or failure; the platform's other notes on the step stay on the run page, `--verbose` shows them too), and offers the patch it hands back: `git apply --check`, git's stat, a yes, then `git apply`. Ctrl-C stops the run; a dropped connection is followed again, not the end of the turn. After each turn a session line gives the turns so far, the spend, the model, how many tokens the agent read last turn, the time and the conversation id; `/status` prints it, `/new` starts a fresh conversation (and count), `/quit` leaves. `--to <workspace>` (a project that does not exist is made, blank with its `coder` agent, after a yes), `--agent <name>` (default `coder`, added to the project on first use after a yes), `--task "…"` one turn and exit (for scripts), `--yes` applies without asking (required with no terminal), `--test`, `--context <id>`, `--verbose` |
|
|
140
140
|
| `foldrun status [workspace]` | per workspace: what is added, changed and only-on-the-platform, plus which files moved there since your last deploy from here. Reads only |
|
|
141
141
|
| `foldrun status --platform` | is the platform up: overall, each component (dashboard and API, run workers, scheduler, model providers, email, storage) and any incident or maintenance the operator posted, with its latest update. Reads the open `/api/status` — no key needed; the signed-in platform, `--url` / `FOLDRUN_URL`, or the default, dash.foldrun.io. `--json` prints the answer as is. Exits 1, saying *status unavailable — the platform may be down*, when it does not answer. Plain `foldrun status` opens with the same one-line verdict |
|
|
142
142
|
| `foldrun status --platform --history` | what the status page draws as bars: each component's uptime over the window and a mark per day — up, degraded or maintenance, an outage, or no samples — then the incidents and maintenance in it, from the open `GET /api/status/history?days=<n>`. `--days 1-90` (default 90), `--json` |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "foldrun",
|
|
3
|
-
"version": "26.
|
|
3
|
+
"version": "26.9.0",
|
|
4
4
|
"description": "Agents are just folders. Write them, check them, run them — on your machine.",
|
|
5
5
|
"license": "FSL-1.1-ALv2",
|
|
6
6
|
"type": "module",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"node": ">=22"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@foldrun/core": "^24.3.
|
|
14
|
+
"@foldrun/core": "^24.3.1"
|
|
15
15
|
},
|
|
16
16
|
"files": [
|
|
17
17
|
"bin",
|
package/src/commands.mjs
CHANGED
|
@@ -2741,21 +2741,110 @@ function eventLine(e, rawAgent, open) {
|
|
|
2741
2741
|
* tool call is two events — one line per call, printed when it completes.
|
|
2742
2742
|
* `open` carries the calls still in flight across polls and reconnects.
|
|
2743
2743
|
*/
|
|
2744
|
-
function printNew(run, seen, open = new Map(), { skipResult = false } = {}) {
|
|
2744
|
+
export function printNew(run, seen, open = new Map(), { skipResult = false, quiet = false } = {}) {
|
|
2745
2745
|
// skipResult: the caller prints the last top-level step's reply in full
|
|
2746
2746
|
// afterwards (foldrun code), so that one step's reply line is not printed
|
|
2747
|
-
// twice; any other step's (a sub-agent's) stays (Codex).
|
|
2747
|
+
// twice; any other step's (a sub-agent's) stays (Codex). While the run is
|
|
2748
|
+
// live the step has no result yet to compare with, so that step's newest
|
|
2749
|
+
// text is HELD until something follows it: a tool call after it means it
|
|
2750
|
+
// was a remark on the way and it is printed; the run ending with it means
|
|
2751
|
+
// it is the reply (dropHeldReply) — 19 Nov 2026, the reply showed twice.
|
|
2752
|
+
// quiet (foldrun code): the platform's own notes on the step (`info`:
|
|
2753
|
+
// clock, credential, isolation, network, dns, timing, egress …) are left
|
|
2754
|
+
// to the run page; tool calls, the agent's words and errors stay.
|
|
2755
|
+
// An info note is not "something after" the held text: it neither
|
|
2756
|
+
// releases it (a trailing note would print the reply before its result,
|
|
2757
|
+
// then the caller again — Codex) nor, when quiet, shows at all — except a
|
|
2758
|
+
// note that something was refused (a `limits:` refusal is an info note,
|
|
2759
|
+
// and the user must see why a call did not run — Codex).
|
|
2748
2760
|
const own = run.steps.filter((x) => !x.subagentOf);
|
|
2749
2761
|
const replying = skipResult ? own.at(-1) : undefined;
|
|
2762
|
+
const held = heldText(seen);
|
|
2763
|
+
// Steps are visited in order, not in time: an older event of a later step
|
|
2764
|
+
// (a sub-agent's, unseen until this frame) must not release a parent's
|
|
2765
|
+
// newer text — that text may be the reply, whose result is still to come
|
|
2766
|
+
// (Codex). Events carry `t`; without one, the event releases.
|
|
2767
|
+
const release = (by) => {
|
|
2768
|
+
for (const [j, h] of held) {
|
|
2769
|
+
if (by?.t && h.t && String(by.t) < String(h.t)) continue;
|
|
2770
|
+
// The result came in this frame and holds it: it is printed with the
|
|
2771
|
+
// result, once (Codex).
|
|
2772
|
+
const result = run.steps[j]?.result;
|
|
2773
|
+
if (!(result && String(result).includes(String(h.text).trim()))) console.log(eventLine(h, run.steps[j]?.agent, open));
|
|
2774
|
+
held.delete(j);
|
|
2775
|
+
}
|
|
2776
|
+
};
|
|
2777
|
+
// One frame's new events, from every step, in the order they happened
|
|
2778
|
+
// (`t`; stable, so events with no time keep step order): a sub-agent's
|
|
2779
|
+
// call between two of the parent's remarks prints between them (Codex).
|
|
2780
|
+
const fresh = [];
|
|
2750
2781
|
run.steps.forEach((step, i) => {
|
|
2751
2782
|
const from = seen.get(i) ?? 0;
|
|
2752
|
-
|
|
2753
|
-
if (step === replying && e.type === "text" && step.result && String(e.text).trim() === String(step.result).trim()) continue;
|
|
2754
|
-
const line = eventLine(e, step.agent, open);
|
|
2755
|
-
if (line !== null) console.log(line);
|
|
2756
|
-
}
|
|
2783
|
+
step.events.slice(from).forEach((e) => fresh.push({ i, step, e }));
|
|
2757
2784
|
seen.set(i, step.events.length);
|
|
2758
2785
|
});
|
|
2786
|
+
if (fresh.every((x) => x.e.t)) fresh.sort((a, b) => (String(a.e.t) < String(b.e.t) ? -1 : String(a.e.t) > String(b.e.t) ? 1 : 0));
|
|
2787
|
+
for (const { i, step, e } of fresh) {
|
|
2788
|
+
const note = e.type === "info";
|
|
2789
|
+
if (note && quiet && !REFUSED_NOTE.test(String(e.text ?? ""))) continue;
|
|
2790
|
+
if (step === replying && e.type === "text") {
|
|
2791
|
+
// The result holds all the step's words: text already inside it is
|
|
2792
|
+
// printed with it, once (Codex).
|
|
2793
|
+
if (step.result && String(step.result).includes(String(e.text).trim())) continue;
|
|
2794
|
+
release();
|
|
2795
|
+
held.set(i, { ...e, __agent: step.agent });
|
|
2796
|
+
continue;
|
|
2797
|
+
}
|
|
2798
|
+
// Anything else that is not a note — a tool call, an error, any other
|
|
2799
|
+
// step's words (a sub-agent's) — came after the held text: it shows first.
|
|
2800
|
+
// An error in the replying step itself prints without releasing its
|
|
2801
|
+
// held text: a refusal after the agent's last words would otherwise
|
|
2802
|
+
// print the reply as a line, then again in full (seen 19 Nov 2026).
|
|
2803
|
+
if (!note && !(step === replying && e.type === "error")) release(e);
|
|
2804
|
+
const line = eventLine(e, step.agent, open);
|
|
2805
|
+
if (line !== null) console.log(line);
|
|
2806
|
+
}
|
|
2807
|
+
}
|
|
2808
|
+
|
|
2809
|
+
/** An info note that something was refused or went wrong (a `limits:`
|
|
2810
|
+
* refusal, "browser pod: reconnect failed …"): shown even in the quiet view. */
|
|
2811
|
+
// "(WebSearch refused)" is how a refused call ends; the setup note
|
|
2812
|
+
// "limits: … a call past one is refused" is not one (seen on 26.8.0).
|
|
2813
|
+
// Core's other refusals: "refused path: …" (copy-back) and "the model
|
|
2814
|
+
// credential was refused mid-step" (Codex).
|
|
2815
|
+
const REFUSED_NOTE = /\(\S+ refused\)|^refused path:|\bwas refused\b|\b(denied|blocked|failed|failure|error|lost|timed out)\b/i;
|
|
2816
|
+
|
|
2817
|
+
/** Whatever text is still held is printed: the turn is ending another way
|
|
2818
|
+
* (an error, a second Ctrl-C), so no reply follows it (Codex). */
|
|
2819
|
+
export function flushHeld(seen, open) {
|
|
2820
|
+
if (!seen) return;
|
|
2821
|
+
const held = heldText(seen);
|
|
2822
|
+
for (const [, h] of held) console.log(eventLine(h, h.__agent ?? "", open ?? new Map()));
|
|
2823
|
+
held.clear();
|
|
2824
|
+
}
|
|
2825
|
+
|
|
2826
|
+
/** printNew's held text, per step, kept beside `seen` across polls and reconnects. */
|
|
2827
|
+
const HELD = new WeakMap();
|
|
2828
|
+
/** @param {Map<number, number>} seen */
|
|
2829
|
+
function heldText(seen) {
|
|
2830
|
+
let m = HELD.get(seen);
|
|
2831
|
+
if (!m) HELD.set(seen, (m = new Map()));
|
|
2832
|
+
return m;
|
|
2833
|
+
}
|
|
2834
|
+
|
|
2835
|
+
/** The run is over: a held text that is not the reply printed after it is
|
|
2836
|
+
* printed now (the reply itself is not printed twice). */
|
|
2837
|
+
export function dropHeldReply(run, seen, open) {
|
|
2838
|
+
const held = heldText(seen);
|
|
2839
|
+
const own = (run.steps ?? []).filter((x) => !x.subagentOf);
|
|
2840
|
+
const reply = String(own.at(-1)?.result ?? "").trim();
|
|
2841
|
+
for (const [i, e] of held) {
|
|
2842
|
+
// The result holds the step's words, so a held text inside it is
|
|
2843
|
+
// printed with it, not on its own as well.
|
|
2844
|
+
const text = String(e.text).trim();
|
|
2845
|
+
if (!(reply && reply.includes(text))) console.log(eventLine(e, run.steps[i]?.agent, open));
|
|
2846
|
+
}
|
|
2847
|
+
held.clear();
|
|
2759
2848
|
}
|
|
2760
2849
|
|
|
2761
2850
|
/** The stream is over: print a start line for each call that never completed. */
|
|
@@ -2899,19 +2988,33 @@ async function streamOnce(url, flags, ws, runId, seen, open = new Map(), print =
|
|
|
2899
2988
|
* from printing twice. It used to block `invoke --watch` and `logs
|
|
2900
2989
|
* --follow` for as long as a stalled tunnel cared to keep the socket.
|
|
2901
2990
|
*/
|
|
2902
|
-
async function followRemote(url, flags, ws, runId, seen = new Map(), open = new Map(), { holdOpen = false, skipResult = false } = {}) {
|
|
2991
|
+
async function followRemote(url, flags, ws, runId, seen = new Map(), open = new Map(), { holdOpen = false, skipResult = false, quiet = false } = {}) {
|
|
2903
2992
|
for (let attempt = 1; ; attempt++) {
|
|
2904
2993
|
try {
|
|
2905
|
-
const run = await streamOnce(url, flags, ws, runId, seen, open, { skipResult });
|
|
2994
|
+
const run = await streamOnce(url, flags, ws, runId, seen, open, { skipResult, quiet });
|
|
2906
2995
|
// holdOpen: the caller reads the run once more when the stream ended
|
|
2907
2996
|
// with it still live, and flushes after — a start flushed here would
|
|
2908
2997
|
// print a second time when that read brings its completion (Codex).
|
|
2909
2998
|
if (!(holdOpen && run && isLive(run))) flushCalls(open);
|
|
2910
2999
|
return run;
|
|
2911
3000
|
} catch (err) {
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
3001
|
+
// A dropped connection (a laptop's network blinking: "terminated:
|
|
3002
|
+
// read ETIMEDOUT", 19 Nov 2026) is not the run ending: read the run
|
|
3003
|
+
// and follow it again, as when the stream goes quiet.
|
|
3004
|
+
if (!(err instanceof StreamIdle) && !droppedConnection(err)) throw err;
|
|
3005
|
+
// The read has its own three tries, apart from the stream's (Codex).
|
|
3006
|
+
let run;
|
|
3007
|
+
for (let read = 1; ; read++) {
|
|
3008
|
+
try {
|
|
3009
|
+
run = await remoteCall(url, flags, `/api/workspaces/${enc(ws)}/runs/${enc(runId)}`);
|
|
3010
|
+
break;
|
|
3011
|
+
} catch (readErr) {
|
|
3012
|
+
if (!droppedConnection(readErr) || read >= 3) throw readErr;
|
|
3013
|
+
console.error(` ${c.dim(`… ${plainText(String(readErr?.message ?? readErr))}; reading the run again (${read}/3)`)}`);
|
|
3014
|
+
await new Promise((r) => setTimeout(r, 1000 * read));
|
|
3015
|
+
}
|
|
3016
|
+
}
|
|
3017
|
+
printNew(run, seen, open, { skipResult, quiet });
|
|
2915
3018
|
if (!isLive(run)) {
|
|
2916
3019
|
flushCalls(open);
|
|
2917
3020
|
return run;
|
|
@@ -2926,6 +3029,18 @@ async function followRemote(url, flags, ws, runId, seen = new Map(), open = new
|
|
|
2926
3029
|
}
|
|
2927
3030
|
}
|
|
2928
3031
|
|
|
3032
|
+
/**
|
|
3033
|
+
* A network failure the run itself does not share: the socket dropped,
|
|
3034
|
+
* timed out or could not connect. Never an abort (Ctrl-C) or an HTTP answer.
|
|
3035
|
+
* @param {any} err
|
|
3036
|
+
*/
|
|
3037
|
+
export function droppedConnection(err) {
|
|
3038
|
+
if (!err || err.name === "AbortError" || err instanceof StreamIdle) return false;
|
|
3039
|
+
if (typeof err.status === "number") return false;
|
|
3040
|
+
const text = [err.message, err.code, err.cause?.code, err.cause?.message].filter(Boolean).join(" ");
|
|
3041
|
+
return /\bterminated\b|ETIMEDOUT|ECONNRESET|ECONNREFUSED|EPIPE|EAI_AGAIN|ENETUNREACH|EHOSTUNREACH|ENETDOWN|UND_ERR_(SOCKET|CONNECT_TIMEOUT|HEADERS_TIMEOUT|BODY_TIMEOUT)|fetch failed|socket hang up|other side closed|could not reach|did not answer .* within/i.test(text);
|
|
3042
|
+
}
|
|
3043
|
+
|
|
2929
3044
|
/**
|
|
2930
3045
|
* `foldrun open [page]` — the dashboard, from the terminal: this
|
|
2931
3046
|
* workspace's overview, or one of its pages (runs, agents, flows, graph,
|
|
@@ -12855,6 +12970,7 @@ async function codeTurn(s, task) {
|
|
|
12855
12970
|
return;
|
|
12856
12971
|
}
|
|
12857
12972
|
if (cancel.asked && cancel.stop === "acked") {
|
|
12973
|
+
flushHeld(seen, open);
|
|
12858
12974
|
console.log(`\n ${c.dim(`left — the platform took the stop for ${cancel.runId}`)}`);
|
|
12859
12975
|
process.exit(130);
|
|
12860
12976
|
}
|
|
@@ -12873,6 +12989,10 @@ async function codeTurn(s, task) {
|
|
|
12873
12989
|
process.on("SIGINT", onInt);
|
|
12874
12990
|
let run;
|
|
12875
12991
|
let runId;
|
|
12992
|
+
/** @type {Map<number, number> | null} */
|
|
12993
|
+
let seen = null;
|
|
12994
|
+
/** @type {Map<string, unknown> | null} */
|
|
12995
|
+
let open = null;
|
|
12876
12996
|
try {
|
|
12877
12997
|
const { packed, left, unscanned, summary } = await packFolder(dir);
|
|
12878
12998
|
if (cancel.asked) return "cancelled";
|
|
@@ -12902,14 +13022,16 @@ async function codeTurn(s, task) {
|
|
|
12902
13022
|
if (cancel.asked) stop(); // pressed while the run was being started
|
|
12903
13023
|
console.log(` ${c.dim(`run ${plainText(runId)}${started.test ? " (test)" : ""} — Ctrl-C stops it; the dashboard shows it live`)}\n`);
|
|
12904
13024
|
run = await remoteCall(url, flags, `/api/workspaces/${enc(ws)}/runs/${enc(runId)}`);
|
|
12905
|
-
|
|
12906
|
-
|
|
12907
|
-
|
|
12908
|
-
|
|
13025
|
+
seen = new Map();
|
|
13026
|
+
open = new Map();
|
|
13027
|
+
const view = { skipResult: true, quiet: flags.verbose !== true };
|
|
13028
|
+
printNew(run, seen, open, view);
|
|
13029
|
+
if (isLive(run)) run = (await followRemote(url, flags, ws, runId, seen, open, { holdOpen: true, ...view })) ?? run;
|
|
12909
13030
|
if (isLive(run)) {
|
|
12910
13031
|
run = await remoteCall(url, flags, `/api/workspaces/${enc(ws)}/runs/${enc(runId)}`);
|
|
12911
|
-
printNew(run, seen, open,
|
|
13032
|
+
printNew(run, seen, open, view);
|
|
12912
13033
|
}
|
|
13034
|
+
dropHeldReply(run, seen, open);
|
|
12913
13035
|
flushCalls(open);
|
|
12914
13036
|
cancel.phase = "patch";
|
|
12915
13037
|
|
|
@@ -12919,6 +13041,8 @@ async function codeTurn(s, task) {
|
|
|
12919
13041
|
if (reply) console.log(`\n${plainText(String(reply)).trim().split("\n").map((l) => ` ${l}`).join("\n")}`);
|
|
12920
13042
|
const cost = (run.steps ?? []).reduce((sum, x) => sum + (x.costUsd ?? 0), 0);
|
|
12921
13043
|
console.log(`\n ${run.status === "completed" ? c.green("✓") : c.red("✗")} ${plainText(run.status)} ${c.dim(`· $${cost.toFixed(4)} · ${plainText(runId)}`)}`);
|
|
13044
|
+
noteSessionTurn(s, run, cost);
|
|
13045
|
+
console.log(` ${c.dim(sessionLine(s))}`);
|
|
12922
13046
|
if (cancel.asked) {
|
|
12923
13047
|
console.log(` ${c.dim(`stopped by you — nothing applied. What it made, if anything: foldrun report ${runId} patch --to ${ws}`)}\n`);
|
|
12924
13048
|
return "cancelled";
|
|
@@ -12941,6 +13065,9 @@ async function codeTurn(s, task) {
|
|
|
12941
13065
|
}
|
|
12942
13066
|
return run.status;
|
|
12943
13067
|
} finally {
|
|
13068
|
+
// The success path has printed or dropped any held text already; an
|
|
13069
|
+
// error on the way out has not (Codex).
|
|
13070
|
+
flushHeld(seen, open);
|
|
12944
13071
|
// A stop still on its way is waited for on every way out — a thrown
|
|
12945
13072
|
// follower included — so the turn never ends before the platform was
|
|
12946
13073
|
// told, and says so when it cannot tell (Codex).
|
|
@@ -12972,7 +13099,11 @@ async function codeTurn(s, task) {
|
|
|
12972
13099
|
*/
|
|
12973
13100
|
async function codeCmd(positional, flags, layout) {
|
|
12974
13101
|
const dir = path.resolve(positional[0] ?? ".");
|
|
12975
|
-
if (!fs.existsSync(dir) || !fs.statSync(dir).isDirectory())
|
|
13102
|
+
if (!fs.existsSync(dir) || !fs.statSync(dir).isDirectory()) {
|
|
13103
|
+
// `foldrun code to my-project` (19 Nov 2026, a tester): the dashes left off.
|
|
13104
|
+
if (positional[0] === "to" && positional[1]) throw new Error(`${dir} is not a folder — did you mean \`foldrun code --to ${positional[1]}\`?`);
|
|
13105
|
+
throw new Error(`${dir} is not a folder`);
|
|
13106
|
+
}
|
|
12976
13107
|
if (spawnSync("git", ["-C", dir, "rev-parse", "--show-toplevel"], { encoding: "utf8" }).status !== 0) {
|
|
12977
13108
|
throw new Error(`${dir} is not in a git repository — foldrun code sends what git would commit and applies the agent's patch with git, so \`git init\` it first`);
|
|
12978
13109
|
}
|
|
@@ -12994,7 +13125,7 @@ async function codeCmd(positional, flags, layout) {
|
|
|
12994
13125
|
const { createInterface } = await import("node:readline/promises");
|
|
12995
13126
|
console.log(`\n ${c.bold("foldrun code")} ${c.dim(`· ${agent} · ${ws} on ${url}`)}`);
|
|
12996
13127
|
console.log(` ${c.dim(`${dir} — each message sends it to a sandbox; you apply what comes back`)}`);
|
|
12997
|
-
console.log(` ${c.dim("/new a fresh conversation /quit leave")}\n`);
|
|
13128
|
+
console.log(` ${c.dim("/new a fresh conversation /status this session /quit leave")}\n`);
|
|
12998
13129
|
for (;;) {
|
|
12999
13130
|
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
13000
13131
|
// Closing the input (Ctrl-D) leaves question() unsettled on Node 26 —
|
|
@@ -13010,13 +13141,19 @@ async function codeCmd(positional, flags, layout) {
|
|
|
13010
13141
|
console.log();
|
|
13011
13142
|
return 0;
|
|
13012
13143
|
}
|
|
13144
|
+
if (line === "/status") {
|
|
13145
|
+
console.log(` ${c.dim(`${sessionLine(s)} · ${agent} · ${ws} on ${url}`)}\n`);
|
|
13146
|
+
continue;
|
|
13147
|
+
}
|
|
13013
13148
|
if (line === "/new") {
|
|
13014
13149
|
s.context = newContext();
|
|
13150
|
+
// Nothing of the old conversation stays in the count (Codex).
|
|
13151
|
+
for (const k of ["turns", "costUsd", "model", "contextTokens", "secs"]) delete s[k];
|
|
13015
13152
|
console.log(` ${c.dim("a fresh conversation — the agent no longer reads the earlier turns")}\n`);
|
|
13016
13153
|
continue;
|
|
13017
13154
|
}
|
|
13018
13155
|
if (line.startsWith("/")) {
|
|
13019
|
-
console.log(` ${c.dim("/new a fresh conversation /quit leave")}\n`);
|
|
13156
|
+
console.log(` ${c.dim("/new a fresh conversation /status this session /quit leave")}\n`);
|
|
13020
13157
|
continue;
|
|
13021
13158
|
}
|
|
13022
13159
|
try {
|
|
@@ -13027,6 +13164,42 @@ async function codeCmd(positional, flags, layout) {
|
|
|
13027
13164
|
}
|
|
13028
13165
|
}
|
|
13029
13166
|
|
|
13167
|
+
/**
|
|
13168
|
+
* What a foldrun code session has done so far, like Claude Code's status
|
|
13169
|
+
* line (owner, 19 Nov 2026): turns, spend, the model, how much the agent
|
|
13170
|
+
* read last turn (its context), how long it took. `/new` starts the count
|
|
13171
|
+
* again; `/status` prints it.
|
|
13172
|
+
* @param {{ turns?: number, costUsd?: number, model?: string, contextTokens?: number, secs?: number }} s
|
|
13173
|
+
* @param {any} run
|
|
13174
|
+
* @param {number} cost
|
|
13175
|
+
*/
|
|
13176
|
+
export function noteSessionTurn(s, run, cost) {
|
|
13177
|
+
s.turns = (s.turns ?? 0) + 1;
|
|
13178
|
+
s.costUsd = (s.costUsd ?? 0) + (Number.isFinite(cost) ? cost : 0);
|
|
13179
|
+
const step = (run.steps ?? []).filter((x) => !x.subagentOf).at(-1);
|
|
13180
|
+
const started = (step?.events ?? []).find((e) => e.type === "info" && /^step started \(/.test(String(e.text)));
|
|
13181
|
+
const model = started && /model: ([^\s,)]+)/.exec(String(started.text))?.[1];
|
|
13182
|
+
if (model) s.model = model;
|
|
13183
|
+
const t = step?.tokens;
|
|
13184
|
+
s.contextTokens = t ? Number(t.input ?? 0) : undefined;
|
|
13185
|
+
const a = Date.parse(run.startedAt ?? "");
|
|
13186
|
+
const b = Date.parse(run.finishedAt ?? "");
|
|
13187
|
+
s.secs = Number.isFinite(a) && Number.isFinite(b) ? (b - a) / 1000 : undefined;
|
|
13188
|
+
}
|
|
13189
|
+
|
|
13190
|
+
/** @param {{ turns?: number, costUsd?: number, model?: string, contextTokens?: number, secs?: number, context?: string }} s */
|
|
13191
|
+
export function sessionLine(s) {
|
|
13192
|
+
const k = (/** @type {number} */ n) => (n >= 1000 ? `${Math.round(n / 1000)}k` : String(n));
|
|
13193
|
+
return [
|
|
13194
|
+
`session: ${s.turns ?? 0} turn${s.turns === 1 ? "" : "s"}`,
|
|
13195
|
+
`$${(s.costUsd ?? 0).toFixed(4)} in all`,
|
|
13196
|
+
s.model ? plainText(s.model) : null,
|
|
13197
|
+
s.contextTokens !== undefined ? `last turn read ${k(s.contextTokens)} tokens` : null,
|
|
13198
|
+
s.secs !== undefined ? `${s.secs.toFixed(1)}s` : null,
|
|
13199
|
+
s.context ? `conversation ${plainText(s.context)}` : null,
|
|
13200
|
+
].filter(Boolean).join(" · ");
|
|
13201
|
+
}
|
|
13202
|
+
|
|
13030
13203
|
/**
|
|
13031
13204
|
* `foldrun report <run-id> get <agent>/<path>` — one file a run archived:
|
|
13032
13205
|
* whatever an agent left in outputs/, copied under the run when it ended.
|