foldrun 14.3.0 → 14.4.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 +71 -21
- package/docs/api.md +1 -1
- package/docs/cli.md +57 -20
- package/docs/flows.md +3 -0
- package/docs/providers.md +3 -0
- package/docs/secrets.md +6 -1
- package/docs/security.md +3 -3
- package/package.json +2 -2
- package/src/commands.mjs +853 -73
package/src/commands.mjs
CHANGED
|
@@ -3292,9 +3292,9 @@ async function limitingCore() {
|
|
|
3292
3292
|
}
|
|
3293
3293
|
|
|
3294
3294
|
/** Limit an account secret on this machine's vault. */
|
|
3295
|
-
async function localSetWorkspaces(name, workspaces, layout) {
|
|
3295
|
+
async function localSetWorkspaces(name, workspaces, layout, guard = {}) {
|
|
3296
3296
|
const known = localWorkspaceNames(layout);
|
|
3297
|
-
return (await limitingCore()).setSecretWorkspaces("default", name, workspaces, { exists: (w) => known.includes(w) });
|
|
3297
|
+
return (await limitingCore()).setSecretWorkspaces("default", name, workspaces, { exists: (w) => known.includes(w), ...guard });
|
|
3298
3298
|
}
|
|
3299
3299
|
|
|
3300
3300
|
/** `--workspaces a,b` (or `--none`) on `secrets set`: the limit sent with
|
|
@@ -3340,9 +3340,18 @@ async function secretWorkspacesCmd(args, flags, url, layout) {
|
|
|
3340
3340
|
return 0;
|
|
3341
3341
|
}
|
|
3342
3342
|
const workspaces = flags.all === true ? null : flags.none === true ? [] : named;
|
|
3343
|
+
// --if-workspaces a,b (or all, or none): the list read before. Refused (409)
|
|
3344
|
+
// when another admin changed it since, as Settings → Connections does.
|
|
3345
|
+
/** @type {{ ifWorkspaces?: string[] | null }} */
|
|
3346
|
+
const guard = {};
|
|
3347
|
+
if (flags["if-workspaces"] !== undefined) {
|
|
3348
|
+
const v = typeof flags["if-workspaces"] === "string" ? flags["if-workspaces"].trim() : "";
|
|
3349
|
+
if (!v) throw new Error("--if-workspaces takes the list you read: names (a,b), all (every workspace) or none");
|
|
3350
|
+
guard.ifWorkspaces = v === "all" ? null : v === "none" ? [] : v.split(",").map((x) => x.trim()).filter(Boolean);
|
|
3351
|
+
}
|
|
3343
3352
|
const stored = url
|
|
3344
|
-
? (await remoteCall(url, flags, "/api/secrets", { method: "PATCH", body: JSON.stringify({ name, workspaces }) })).workspaces
|
|
3345
|
-
: await localSetWorkspaces(name, workspaces, layout);
|
|
3353
|
+
? (await remoteCall(url, flags, "/api/secrets", { method: "PATCH", body: JSON.stringify({ name, workspaces, ...guard }) })).workspaces
|
|
3354
|
+
: await localSetWorkspaces(name, workspaces, layout, guard);
|
|
3346
3355
|
console.log(`\n ${c.green("✓")} ${describe(stored)}\n`);
|
|
3347
3356
|
return 0;
|
|
3348
3357
|
}
|
|
@@ -3353,6 +3362,42 @@ function siteFlags(flags) {
|
|
|
3353
3362
|
return raw.filter((v) => typeof v === "string").flatMap((v) => v.split(",")).map((v) => v.trim()).filter(Boolean);
|
|
3354
3363
|
}
|
|
3355
3364
|
|
|
3365
|
+
/**
|
|
3366
|
+
* Whether the far end still accepts a secret, as Settings → Connections says
|
|
3367
|
+
* it: accepted, refused (with when it last worked), the host's own failure,
|
|
3368
|
+
* or never used — which is not the same as working.
|
|
3369
|
+
*/
|
|
3370
|
+
function secretHealthLine(health) {
|
|
3371
|
+
if (!health) return c.dim("not used yet — nothing has tried this credential");
|
|
3372
|
+
const { last, refusals, lastAccepted } = health;
|
|
3373
|
+
const on = String(last?.at ?? "").slice(0, 10);
|
|
3374
|
+
const status = last?.status ? ` (${last.status})` : "";
|
|
3375
|
+
if (last?.outcome === "refused") {
|
|
3376
|
+
return c.red(`refused by ${last.host} on ${on}${status}${refusals > 1 ? ` · ${refusals} times running` : ""}${lastAccepted ? ` · last worked ${String(lastAccepted).slice(0, 10)}` : " · never seen working"}`);
|
|
3377
|
+
}
|
|
3378
|
+
if (last?.outcome === "error") return c.amber(`${last.host} failed on ${on}${status} — its end, not the key`);
|
|
3379
|
+
return c.green(`accepted by ${last?.host} on ${on}`);
|
|
3380
|
+
}
|
|
3381
|
+
|
|
3382
|
+
/**
|
|
3383
|
+
* The OAuth app saved under a removed account secret's name, when no
|
|
3384
|
+
* connection uses it any more — the one the dashboard deletes with the
|
|
3385
|
+
* secret. Null when there is none, it is still used, or it cannot be told.
|
|
3386
|
+
*/
|
|
3387
|
+
async function unusedSavedClient(url, flags, name) {
|
|
3388
|
+
const app = name.toLowerCase().replaceAll("_", "-");
|
|
3389
|
+
try {
|
|
3390
|
+
const [{ clients = [] }, { connections = [] }] = await Promise.all([
|
|
3391
|
+
remoteCall(url, flags, "/api/oauth/clients"),
|
|
3392
|
+
remoteCall(url, flags, "/api/oauth/connections"),
|
|
3393
|
+
]);
|
|
3394
|
+
if (!clients.some((k) => k.name === app)) return null;
|
|
3395
|
+
return connections.some((x) => x.client === app) ? null : app;
|
|
3396
|
+
} catch {
|
|
3397
|
+
return null;
|
|
3398
|
+
}
|
|
3399
|
+
}
|
|
3400
|
+
|
|
3356
3401
|
async function secretsCmd(positional, flags, layout) {
|
|
3357
3402
|
// --local: this machine's store even when signed in, the same escape
|
|
3358
3403
|
// hatch deploy and keys have. Without it, a signed-in laptop sent every
|
|
@@ -3376,9 +3421,14 @@ async function secretsCmd(positional, flags, layout) {
|
|
|
3376
3421
|
const [verb, name] = positional;
|
|
3377
3422
|
|
|
3378
3423
|
if (verb === "ls" || verb === undefined) {
|
|
3379
|
-
const
|
|
3380
|
-
?
|
|
3381
|
-
: (await core()).listSecrets("default", scope);
|
|
3424
|
+
const body = url
|
|
3425
|
+
? await remoteCall(url, flags, `/api/secrets${scope ? `?workspace=${encodeURIComponent(scope)}` : ""}`)
|
|
3426
|
+
: { secrets: (await core()).listSecrets("default", scope) };
|
|
3427
|
+
const entries = body.secrets ?? [];
|
|
3428
|
+
if (flags.json === true) {
|
|
3429
|
+
console.log(JSON.stringify(body, null, 2));
|
|
3430
|
+
return 0;
|
|
3431
|
+
}
|
|
3382
3432
|
if (!entries.length) {
|
|
3383
3433
|
console.log(`\n ${c.dim("no secrets yet — foldrun secrets set NAME")}\n`);
|
|
3384
3434
|
return 0;
|
|
@@ -3388,6 +3438,9 @@ async function secretsCmd(positional, flags, layout) {
|
|
|
3388
3438
|
console.log(
|
|
3389
3439
|
` ${c.bold(s.name)} ${c.dim(`${s.scope}${s.shadowed ? " · shadowed" : ""} · ${s.updatedAt ?? ""}${s.sites?.length ? ` · sent only to ${s.sites.join(", ")}` : ""}${Array.isArray(s.workspaces) ? ` · ${s.workspaces.length ? `only in ${s.workspaces.join(", ")}` : "in no workspace"}` : ""}`)}`,
|
|
3390
3440
|
);
|
|
3441
|
+
// The platform says what the far end answered last time; this
|
|
3442
|
+
// machine's vault keeps no such record, so nothing is shown there.
|
|
3443
|
+
if (s.health !== undefined) console.log(` ${secretHealthLine(s.health)}`);
|
|
3391
3444
|
}
|
|
3392
3445
|
console.log();
|
|
3393
3446
|
return 0;
|
|
@@ -3548,6 +3601,18 @@ async function secretsCmd(positional, flags, layout) {
|
|
|
3548
3601
|
if (revoked?.error) console.log(` ${c.amber("!")} ${revoked.error} — revoke the app's access in the provider's own settings`);
|
|
3549
3602
|
else if (revoked?.revoked?.length) console.log(` ${c.dim(`grant revoked at the provider (${revoked.revoked.join(", ")})`)}`);
|
|
3550
3603
|
else if (revoked?.skipped === "shared-grant") console.log(` ${c.dim("grant kept: another secret uses the same app, which the provider may revoke together")}`);
|
|
3604
|
+
// The dashboard also deletes the app saved under this name once nothing
|
|
3605
|
+
// uses it. Here it is only said, unless --with-client asks for it too.
|
|
3606
|
+
// Account secrets only, as there: a saved app is the account's.
|
|
3607
|
+
const app = url && !scope ? await unusedSavedClient(url, flags, name) : null;
|
|
3608
|
+
if (app && flags["with-client"] === true) {
|
|
3609
|
+
if (await confirmed(flags, "secrets rm --with-client", `also delete the saved OAuth client ${app}, which no connection uses now? [y/N] `)) {
|
|
3610
|
+
await remoteCall(url, flags, "/api/oauth/clients", { method: "DELETE", body: JSON.stringify({ client: app }) });
|
|
3611
|
+
console.log(` ${c.green("✓")} saved OAuth client ${app} removed`);
|
|
3612
|
+
} else console.log(` ${c.dim(`saved OAuth client ${app} kept`)}`);
|
|
3613
|
+
} else if (app) {
|
|
3614
|
+
console.log(` ${c.dim(`the saved OAuth client ${app} is no longer used — \`foldrun secrets clients rm ${app}\` removes it`)}`);
|
|
3615
|
+
}
|
|
3551
3616
|
console.log();
|
|
3552
3617
|
return 0;
|
|
3553
3618
|
}
|
|
@@ -3688,6 +3753,169 @@ async function savedInputs(url, flags, ws, flow, name) {
|
|
|
3688
3753
|
return hit.task;
|
|
3689
3754
|
}
|
|
3690
3755
|
|
|
3756
|
+
// A flow's saved input sets, as "Run with…" lists and saves them. The file
|
|
3757
|
+
// layout is foldrun-web's components/flow-inputs-model.ts, kept byte for byte
|
|
3758
|
+
// the same here (the web module is not in core's public API), so a set saved
|
|
3759
|
+
// from the terminal and one saved from the dashboard read alike.
|
|
3760
|
+
const inputsFileOf = (flow) => `evals/${flow}-inputs.md`;
|
|
3761
|
+
|
|
3762
|
+
/** Every set for one flow: its inputs file first, then eval cases; a name
|
|
3763
|
+
* the inputs file has hides an eval case of the same name. */
|
|
3764
|
+
function inputSetsOf(evals, flow) {
|
|
3765
|
+
const own = evals.filter((e) => e.flow === flow && e.inputs === true);
|
|
3766
|
+
const borrowed = evals.filter((e) => e.flow === flow && e.inputs !== true);
|
|
3767
|
+
const out = [];
|
|
3768
|
+
const seen = new Set();
|
|
3769
|
+
for (const [list, source] of [[own, "inputs"], [borrowed, "eval"]]) {
|
|
3770
|
+
for (const e of list) {
|
|
3771
|
+
for (const k of e.cases ?? []) {
|
|
3772
|
+
if (!String(k.task ?? "").trim() || seen.has(k.name)) continue;
|
|
3773
|
+
seen.add(k.name);
|
|
3774
|
+
out.push({ name: k.name, task: k.task, file: e.file, source });
|
|
3775
|
+
}
|
|
3776
|
+
}
|
|
3777
|
+
}
|
|
3778
|
+
return out;
|
|
3779
|
+
}
|
|
3780
|
+
|
|
3781
|
+
/** A set's name is a `## ` heading: one line, nothing a heading cannot say. */
|
|
3782
|
+
const cleanSetName = (name) =>
|
|
3783
|
+
String(name).replace(/\s+/g, " ").trim().replace(/^#+\s*/, "").replace(/^case:\s*/i, "").trim().slice(0, 80);
|
|
3784
|
+
|
|
3785
|
+
/** A task as core's eval parser reads it back: one line, or a `|` block
|
|
3786
|
+
* with a leading `- ` written `* ` (it would end the block). */
|
|
3787
|
+
function layoutInputTask(task) {
|
|
3788
|
+
const t = task.replace(/\r\n/g, "\n").trim();
|
|
3789
|
+
if (!t.includes("\n") && !/^["'|>]|["']$/.test(t)) return `task: ${t}`;
|
|
3790
|
+
return `task: |\n${t
|
|
3791
|
+
.split("\n")
|
|
3792
|
+
.map((l) => (l.trim() ? ` ${l.replace(/^(\s*)-\s/, "$1* ")}` : ""))
|
|
3793
|
+
.join("\n")}`;
|
|
3794
|
+
}
|
|
3795
|
+
|
|
3796
|
+
function newInputsFile(flow) {
|
|
3797
|
+
return [
|
|
3798
|
+
"---",
|
|
3799
|
+
`name: ${flow}-inputs`,
|
|
3800
|
+
`flow: ${flow}`,
|
|
3801
|
+
"inputs: true",
|
|
3802
|
+
"trigger: manual",
|
|
3803
|
+
"---",
|
|
3804
|
+
"",
|
|
3805
|
+
`Saved inputs for the ${flow} flow — "Run with…" on its card, or`,
|
|
3806
|
+
`\`foldrun invoke ${flow} --inputs <name>\`. Not an eval: nothing here is asserted.`,
|
|
3807
|
+
"",
|
|
3808
|
+
].join("\n");
|
|
3809
|
+
}
|
|
3810
|
+
|
|
3811
|
+
/** The inputs file with one set added, or replaced when its name is taken;
|
|
3812
|
+
* everything else in it kept as it was. */
|
|
3813
|
+
function upsertInputSet(existing, flow, name, task) {
|
|
3814
|
+
const heading = cleanSetName(name);
|
|
3815
|
+
if (!heading) throw new Error("an input set needs a name");
|
|
3816
|
+
if (!task.trim()) throw new Error("an input set needs a task");
|
|
3817
|
+
const section = `## ${heading}\n${layoutInputTask(task)}\n`;
|
|
3818
|
+
const base = existing ?? newInputsFile(flow);
|
|
3819
|
+
const lines = base.split("\n");
|
|
3820
|
+
const start = lines.findIndex((l) => {
|
|
3821
|
+
const m = /^##\s+(?:case:\s*)?(.+?)\s*$/.exec(l);
|
|
3822
|
+
return m !== null && m[1] === heading;
|
|
3823
|
+
});
|
|
3824
|
+
if (start === -1) return `${base.replace(/\n*$/, "\n")}\n${section}`;
|
|
3825
|
+
let end = start + 1;
|
|
3826
|
+
while (end < lines.length && !/^##\s/.test(lines[end])) end++;
|
|
3827
|
+
const before = lines.slice(0, start).join("\n");
|
|
3828
|
+
const after = lines.slice(end).join("\n");
|
|
3829
|
+
return `${before}${before ? "\n" : ""}${section}${after ? `\n${after}` : ""}`;
|
|
3830
|
+
}
|
|
3831
|
+
|
|
3832
|
+
/**
|
|
3833
|
+
* `foldrun flow inputs <flow>` — the flow's saved input sets, as the
|
|
3834
|
+
* dashboard's "Run with…" menu lists them. `flow inputs save <flow> <name>
|
|
3835
|
+
* --task "…"` writes one into evals/<flow>-inputs.md (replacing a set of that
|
|
3836
|
+
* name), the file `invoke --inputs <name>` reads. This folder by default;
|
|
3837
|
+
* --to <workspace> works on the deployed copy through the same calls the
|
|
3838
|
+
* dashboard makes: GET …/evals, then GET and PUT …/source with ifMatch.
|
|
3839
|
+
*/
|
|
3840
|
+
async function flowInputsCmd(positional, flags, layout) {
|
|
3841
|
+
const saving = positional[1] === "save" && positional[2] !== undefined;
|
|
3842
|
+
const flow = saving ? positional[2] : positional[1];
|
|
3843
|
+
if (!flow) throw new Error('`foldrun flow inputs <flow>` lists its saved inputs; `foldrun flow inputs save <flow> <name> --task "…"` saves one');
|
|
3844
|
+
const file = inputsFileOf(flow);
|
|
3845
|
+
const platform = namesPlatform(flags);
|
|
3846
|
+
const url = platform ? platformFor(flags, "flow inputs") : null;
|
|
3847
|
+
const ws = platform ? platformWorkspace(flags, layout, `flow inputs ${flow}`) : null;
|
|
3848
|
+
const dir = platform ? null : localDeskDir(layout, flow);
|
|
3849
|
+
const where = platform ? `${ws} on ${url}` : path.relative(process.cwd(), dir) || ".";
|
|
3850
|
+
|
|
3851
|
+
if (!saving) {
|
|
3852
|
+
let evals;
|
|
3853
|
+
if (platform) ({ evals = [] } = await remoteCall(url, flags, `/api/workspaces/${enc(ws)}/evals`));
|
|
3854
|
+
else {
|
|
3855
|
+
const { parseEval } = await core();
|
|
3856
|
+
const evalsDir = path.join(dir, "evals");
|
|
3857
|
+
evals = fs.existsSync(evalsDir)
|
|
3858
|
+
? fs.readdirSync(evalsDir).filter((f) => f.endsWith(".md")).sort().map((f) => parseEval(f, fs.readFileSync(path.join(evalsDir, f), "utf8")))
|
|
3859
|
+
: [];
|
|
3860
|
+
}
|
|
3861
|
+
const sets = inputSetsOf(evals, flow);
|
|
3862
|
+
if (flags.json === true) {
|
|
3863
|
+
console.log(JSON.stringify({ flow, sets }, null, 2));
|
|
3864
|
+
return 0;
|
|
3865
|
+
}
|
|
3866
|
+
if (!sets.length) {
|
|
3867
|
+
console.log(`\n ${c.dim(`${flow} has no saved inputs in ${where} — \`foldrun flow inputs save ${flow} <name> --task "…"\` saves one`)}\n`);
|
|
3868
|
+
return 0;
|
|
3869
|
+
}
|
|
3870
|
+
console.log(`\n ${c.bold(flow)} ${c.dim(`· saved inputs · ${where}`)}\n`);
|
|
3871
|
+
for (const s of sets) {
|
|
3872
|
+
console.log(` ${c.bold(s.name)} ${c.dim(`evals/${s.file}${s.source === "eval" ? " · an eval case" : ""}`)}`);
|
|
3873
|
+
console.log(` ${firstLine(s.task, 100)}`);
|
|
3874
|
+
}
|
|
3875
|
+
const run = platform ? `foldrun invoke ${flow} --to ${ws} --inputs <name>` : `foldrun deploy, then foldrun invoke ${flow} --to <workspace> --inputs <name>`;
|
|
3876
|
+
console.log(`\n ${c.dim(run)}\n`);
|
|
3877
|
+
return 0;
|
|
3878
|
+
}
|
|
3879
|
+
|
|
3880
|
+
const name = positional[3];
|
|
3881
|
+
if (typeof name !== "string" || !cleanSetName(name)) throw new Error(`which name? \`foldrun flow inputs save ${flow} <name> --task "…"\``);
|
|
3882
|
+
const task = typeof flags.task === "string" ? flags.task : typeof flags.file === "string" ? fs.readFileSync(flags.file, "utf8") : "";
|
|
3883
|
+
if (!task.trim()) throw new Error(`what is the task? \`foldrun flow inputs save ${flow} ${name} --task "…"\` (or --file <path>)`);
|
|
3884
|
+
const heading = cleanSetName(name);
|
|
3885
|
+
const message = `input set "${heading}" saved for ${flow}`;
|
|
3886
|
+
|
|
3887
|
+
if (platform) {
|
|
3888
|
+
const at = `/api/workspaces/${enc(ws)}/source`;
|
|
3889
|
+
/** @type {{ content?: string, sha256?: string } | null} */
|
|
3890
|
+
let current = null;
|
|
3891
|
+
try {
|
|
3892
|
+
current = await remoteCall(url, flags, `${at}?path=${enc(file)}`);
|
|
3893
|
+
} catch (err) {
|
|
3894
|
+
if (!(err instanceof HttpError) || !(err.status === 404 || /not found/i.test(err.message))) throw err;
|
|
3895
|
+
}
|
|
3896
|
+
const next = upsertInputSet(current ? (current.content ?? "") : null, flow, heading, task);
|
|
3897
|
+
try {
|
|
3898
|
+
// ifMatch: the bytes just read (null: no file yet), so a set saved by
|
|
3899
|
+
// someone else in between is refused rather than written over.
|
|
3900
|
+
await remoteCall(url, flags, at, { method: "PUT", body: JSON.stringify({ path: file, content: next, message, ifMatch: current ? current.sha256 ?? null : null }) });
|
|
3901
|
+
} catch (err) {
|
|
3902
|
+
if (err instanceof HttpError && err.status === 409) throw new Error(`${file} changed while saving — nothing was written; run the command again`);
|
|
3903
|
+
throw err;
|
|
3904
|
+
}
|
|
3905
|
+
console.log(`\n ${c.green("✓")} saved "${heading}" to ${file} ${c.dim(`in ${ws} — \`foldrun invoke ${flow} --to ${ws} --inputs "${heading}"\` runs it`)}\n`);
|
|
3906
|
+
return 0;
|
|
3907
|
+
}
|
|
3908
|
+
// A set for a flow this folder does not have would fail `check`; say so now.
|
|
3909
|
+
await flowFileOf(await openDesk(flags, layout, `flow inputs save ${flow}`, flow), flow);
|
|
3910
|
+
const abs = path.join(dir, file);
|
|
3911
|
+
const before = fs.existsSync(abs) ? fs.readFileSync(abs, "utf8") : null;
|
|
3912
|
+
const next = upsertInputSet(before, flow, heading, task);
|
|
3913
|
+
fs.mkdirSync(path.dirname(abs), { recursive: true });
|
|
3914
|
+
fs.writeFileSync(abs, next);
|
|
3915
|
+
console.log(`\n ${c.green("✓")} saved "${heading}" to ${path.join(where, file)} ${c.dim("— `foldrun deploy` ships it")}\n`);
|
|
3916
|
+
return 0;
|
|
3917
|
+
}
|
|
3918
|
+
|
|
3691
3919
|
/**
|
|
3692
3920
|
* `foldrun invoke <flow>` — start a flow on a running platform. The remote
|
|
3693
3921
|
* sibling of `foldrun run`: same task flag, but the run continues on the
|
|
@@ -4485,7 +4713,10 @@ async function keysCmd(positional, flags) {
|
|
|
4485
4713
|
: `${k.role ?? "admin"} · ${k.workspaces ? k.workspaces.join(",") || "no workspaces" : "all workspaces"}`;
|
|
4486
4714
|
const expired = !k.revokedAt && k.expiresAt && Date.parse(k.expiresAt) <= Date.now();
|
|
4487
4715
|
const state = k.revokedAt ? c.red("revoked") : expired ? c.red("expired") : c.green("live");
|
|
4488
|
-
|
|
4716
|
+
// A key `foldrun login` minted lasts 90 days and renews itself while
|
|
4717
|
+
// that machine is in use; revoking it signs that machine out.
|
|
4718
|
+
const login = k.origin === "cli-login" && !k.revokedAt ? " [CLI sign-in · renews itself]" : "";
|
|
4719
|
+
console.log(` ${state.padEnd(20)} ${k.id} ${k.prefix}… ${c.bold(k.label)} ${c.dim(what)}${k.createdBy ? c.dim(` by ${k.createdBy}`) : ""}${login}`);
|
|
4489
4720
|
// A rotated key in its grace: still live, but not to be rotated again.
|
|
4490
4721
|
const next = k.replacedBy ? keys.find((n) => n.id === k.replacedBy) : null;
|
|
4491
4722
|
if (k.replacedBy) console.log(` ${" ".repeat(9)}${c.yellow(`rotated → ${k.replacedBy}${next ? ` (${next.prefix}…)` : ""}`)}${c.dim(" — rotate that one, not this")}`);
|
|
@@ -4685,11 +4916,36 @@ async function sourceCmd(positional, flags) {
|
|
|
4685
4916
|
}
|
|
4686
4917
|
if (verb === "put" || verb === "write") {
|
|
4687
4918
|
if (!a) throw new Error("which file? foldrun source put flows/daily.md --file ./daily.md --to <workspace>");
|
|
4688
|
-
|
|
4689
|
-
|
|
4690
|
-
|
|
4691
|
-
|
|
4919
|
+
// --empty writes an empty file on purpose (the dashboard's "+ Add file"
|
|
4920
|
+
// does). Without it an empty input is refused: that is nearly always a
|
|
4921
|
+
// pipe that broke, and the blank file would be live at once.
|
|
4922
|
+
if (flags.empty === true && typeof flags.file === "string") throw new Error("either --empty or --file, not both");
|
|
4923
|
+
const content = flags.empty === true ? "" : typeof flags.file === "string" ? fs.readFileSync(flags.file, "utf8") : fs.readFileSync(0, "utf8");
|
|
4924
|
+
if (!content.trim() && flags.empty !== true) throw new Error("refusing to write an empty file — `foldrun source rm` is the deliberate way to remove one; --empty writes an empty one on purpose");
|
|
4925
|
+
// --check: the editor's checked save — a file a deploy would refuse is
|
|
4926
|
+
// refused (422, with the issues) and nothing is written.
|
|
4927
|
+
const body = { path: a, content, ...(typeof flags.message === "string" ? { message: flags.message } : {}), ...(flags.check === true ? { check: true } : {}) };
|
|
4928
|
+
const printIssues = (issues) => {
|
|
4929
|
+
for (const i of issues ?? []) {
|
|
4930
|
+
const tag = i.level === "error" ? c.red("error") : c.amber(" warn");
|
|
4931
|
+
console.log(` ${tag} ${c.bold(i.where ?? a)} ${i.message}${i.rule ? ` ${c.dim(`[${i.rule}]`)}` : ""}`);
|
|
4932
|
+
}
|
|
4933
|
+
};
|
|
4934
|
+
let saved;
|
|
4935
|
+
try {
|
|
4936
|
+
saved = await remoteCall(url, flags, base, { method: "PUT", body: JSON.stringify(body) });
|
|
4937
|
+
} catch (err) {
|
|
4938
|
+
if (flags.check !== true || !(err instanceof HttpError) || err.status !== 422) throw err;
|
|
4939
|
+
console.log(`\n ${c.red("✗")} ${ws}/${a} ${c.dim("did not check out — nothing was saved")}\n`);
|
|
4940
|
+
printIssues(err.body?.issues);
|
|
4941
|
+
console.log(`\n ${c.dim("fix it, or save it anyway without --check")}\n`);
|
|
4942
|
+
return 1;
|
|
4943
|
+
}
|
|
4692
4944
|
console.log(`\n ${c.green("✓")} ${ws}/${a} ${c.dim(`${content.length} chars · revision recorded${flags.message ? ` · "${flags.message}"` : ""}`)}\n`);
|
|
4945
|
+
if (flags.check === true && saved?.issues?.length) {
|
|
4946
|
+
printIssues(saved.issues);
|
|
4947
|
+
console.log();
|
|
4948
|
+
}
|
|
4693
4949
|
return 0;
|
|
4694
4950
|
}
|
|
4695
4951
|
if (verb === "mv" || verb === "move") {
|
|
@@ -4705,6 +4961,7 @@ async function sourceCmd(positional, flags) {
|
|
|
4705
4961
|
console.log(`\n ${c.green("✓")} removed ${a}\n`);
|
|
4706
4962
|
return 0;
|
|
4707
4963
|
}
|
|
4964
|
+
if (verb === "share" || verb === "promote") return sourceShare(url, flags, ws, base, a);
|
|
4708
4965
|
if (verb === "new") {
|
|
4709
4966
|
// The dashboard's New button for any document (POST …/assets): the
|
|
4710
4967
|
// platform writes the template — a tool folder, a skill, knowledge,
|
|
@@ -4723,7 +4980,114 @@ async function sourceCmd(positional, flags) {
|
|
|
4723
4980
|
console.log(`\n ${c.green("✓")} ${ws}/${r.path ?? b} ${c.dim(`a new ${a.replace(/s$/, "")}${flags.agent ? ` for ${flags.agent}` : ""} · revision recorded`)}\n`);
|
|
4724
4981
|
return 0;
|
|
4725
4982
|
}
|
|
4726
|
-
throw new Error(`source: unknown verb "${verb}" — ls, cat, put, new, mv, rm`);
|
|
4983
|
+
throw new Error(`source: unknown verb "${verb}" — ls, cat, put, new, mv, rm, share`);
|
|
4984
|
+
}
|
|
4985
|
+
|
|
4986
|
+
/** The workspace folders "Move to shared" applies to — the library kinds
|
|
4987
|
+
* but hooks (`foldrun hook add --library` makes a shared one). */
|
|
4988
|
+
const SHAREABLE_KINDS = ["skills", "tools", "scripts", "knowledge", "memory"];
|
|
4989
|
+
|
|
4990
|
+
/**
|
|
4991
|
+
* `foldrun source share <path> --to <ws>` — the dashboard's "Move to shared":
|
|
4992
|
+
* the file goes into the account library (PUT /api/library/<kind>) and,
|
|
4993
|
+
* once it is safely there, out of the workspace (DELETE …/source). A skill
|
|
4994
|
+
* or folder tool moves whole — every file of its folder, where the
|
|
4995
|
+
* dashboard copies the one file it shows — and subfolders keep their
|
|
4996
|
+
* place. A library file of the same path is refused unless --overwrite;
|
|
4997
|
+
* --dry-run lists what would move. Asks first (--yes with no terminal):
|
|
4998
|
+
* it leaves this workspace and every workspace in the account can use it.
|
|
4999
|
+
*/
|
|
5000
|
+
async function sourceShare(url, flags, ws, base, spec) {
|
|
5001
|
+
if (!spec) throw new Error("which file? `foldrun source share skills/house-style --to <workspace>` — a skill, tool, script, knowledge or memory file");
|
|
5002
|
+
const clean = spec.replace(/^(\.\/)+/, "").replace(/\/+$/, "");
|
|
5003
|
+
const [kind, ...rest] = clean.split("/");
|
|
5004
|
+
if (kind === "hooks") throw new Error("a hook is a folder whose run.mjs goes with it — `foldrun hook add <name> --library` makes a shared one");
|
|
5005
|
+
if (!SHAREABLE_KINDS.includes(kind) || !rest.length) throw new Error(`"${spec}" is not under ${SHAREABLE_KINDS.join("/, ")}/ — only those move to the shared library`);
|
|
5006
|
+
// skills/x/SKILL.md or tools/x/tool.md names its folder: the folder is the thing.
|
|
5007
|
+
const unit = (kind === "skills" || kind === "tools") && rest.length >= 2 ? `${kind}/${rest[0]}` : clean;
|
|
5008
|
+
const { files = [] } = await remoteCall(url, flags, base);
|
|
5009
|
+
const members = files.filter((f) => f === unit || f.startsWith(`${unit}/`));
|
|
5010
|
+
if (!members.length) throw new Error(`no ${unit} in ${ws} — \`foldrun source ls ${kind} --to ${ws}\` lists what is there`);
|
|
5011
|
+
const relOf = (f) => f.slice(kind.length + 1);
|
|
5012
|
+
|
|
5013
|
+
/** Which of these the library already has. */
|
|
5014
|
+
const inLibrary = async (list) => {
|
|
5015
|
+
const hits = [];
|
|
5016
|
+
for (const f of list) {
|
|
5017
|
+
try {
|
|
5018
|
+
await remoteCall(url, flags, `/api/library/${kind}?path=${enc(relOf(f))}`);
|
|
5019
|
+
hits.push(f);
|
|
5020
|
+
} catch (err) {
|
|
5021
|
+
if (!(err instanceof HttpError) || !(err.status === 404 || /not found/i.test(err.message))) throw err;
|
|
5022
|
+
}
|
|
5023
|
+
}
|
|
5024
|
+
return hits;
|
|
5025
|
+
};
|
|
5026
|
+
const taken = await inLibrary(members);
|
|
5027
|
+
console.log(`\n ${c.bold(unit)} ${c.dim(`· ${ws} → the shared library`)}\n`);
|
|
5028
|
+
for (const f of members) console.log(` ${c.dim("·")} ${f} → library/${kind}/${relOf(f)}${taken.includes(f) ? c.amber(" (the library has one — replaced)") : ""}`);
|
|
5029
|
+
console.log();
|
|
5030
|
+
if (taken.length && flags.overwrite !== true) {
|
|
5031
|
+
console.log(` ${c.red("✗")} the library already has ${taken.map((f) => `${kind}/${relOf(f)}`).join(", ")} — nothing was moved; --overwrite replaces ${taken.length === 1 ? "it" : "them"}\n`);
|
|
5032
|
+
return 1;
|
|
5033
|
+
}
|
|
5034
|
+
if (flags["dry-run"] === true) {
|
|
5035
|
+
console.log(` ${c.dim("--dry-run: nothing moved")}\n`);
|
|
5036
|
+
return 0;
|
|
5037
|
+
}
|
|
5038
|
+
if (!(await confirmed(flags, "source share", `Move ${unit} to shared? Every workspace in the account will be able to use it, and it leaves ${ws}. [y/N] `))) {
|
|
5039
|
+
console.log(`\n ${c.dim("nothing moved")}\n`);
|
|
5040
|
+
return 0;
|
|
5041
|
+
}
|
|
5042
|
+
// Asked again after the question, which may have waited a long time: a
|
|
5043
|
+
// library file made meanwhile is not replaced without --overwrite. (The
|
|
5044
|
+
// library PUT takes no ifMatch, so this narrows the window, no more.)
|
|
5045
|
+
if (flags.overwrite !== true) {
|
|
5046
|
+
const since = await inLibrary(members);
|
|
5047
|
+
if (since.length) throw new Error(`the library now has ${since.map((f) => `${kind}/${relOf(f)}`).join(", ")} — made while this waited; nothing was moved (--overwrite replaces it)`);
|
|
5048
|
+
}
|
|
5049
|
+
const copied = new Map();
|
|
5050
|
+
for (const f of members) {
|
|
5051
|
+
const { content } = await remoteCall(url, flags, `${base}?path=${enc(f)}`);
|
|
5052
|
+
copied.set(f, content ?? "");
|
|
5053
|
+
try {
|
|
5054
|
+
await remoteCall(url, flags, `/api/library/${kind}`, { method: "PUT", body: JSON.stringify({ path: relOf(f), content: content ?? "" }) });
|
|
5055
|
+
} catch (err) {
|
|
5056
|
+
throw new Error(`could not copy ${f} to the library — ${explain(err)}. ${unit} is still in ${ws}${f === members[0] ? "" : "; what was copied before it is in the library too"}`);
|
|
5057
|
+
}
|
|
5058
|
+
}
|
|
5059
|
+
// The DELETE takes no ifMatch, so read it all again first: a file edited
|
|
5060
|
+
// or added while this copied would be deleted without ever reaching the
|
|
5061
|
+
// library. Changed, it stays in both places and nothing is deleted.
|
|
5062
|
+
const { files: now = [] } = await remoteCall(url, flags, base);
|
|
5063
|
+
const nowMembers = now.filter((f) => f === unit || f.startsWith(`${unit}/`));
|
|
5064
|
+
const moved = [];
|
|
5065
|
+
for (const f of nowMembers) {
|
|
5066
|
+
if (!copied.has(f)) moved.push(f);
|
|
5067
|
+
else if ((await remoteCall(url, flags, `${base}?path=${enc(f)}`)).content !== copied.get(f)) moved.push(f);
|
|
5068
|
+
}
|
|
5069
|
+
if (moved.length) {
|
|
5070
|
+
throw new Error(`copied to shared, but ${moved.join(", ")} changed in ${ws} while it was copied — nothing was deleted, so it is in both places; run it again with --overwrite to copy the new text`);
|
|
5071
|
+
}
|
|
5072
|
+
// Only once every file is in the library, and only the files that were
|
|
5073
|
+
// copied, one by one — never the folder: the source API lists text files
|
|
5074
|
+
// alone, so deleting a skill's folder would take an image or other asset
|
|
5075
|
+
// in it that never reached the library. A failure leaves the rest in both
|
|
5076
|
+
// places, never in neither, and says so.
|
|
5077
|
+
for (const [i, f] of members.entries()) {
|
|
5078
|
+
try {
|
|
5079
|
+
await remoteCall(url, flags, base, { method: "DELETE", body: JSON.stringify({ path: f }) });
|
|
5080
|
+
} catch (err) {
|
|
5081
|
+
const left = members.slice(i);
|
|
5082
|
+
throw new Error(`copied to shared, but ${f} could not be removed from ${ws} — ${explain(err)}. ${left.length === 1 ? "It is" : `These ${left.length} are`} in both now; ${left.map((x) => `\`foldrun source rm ${x} --to ${ws}\``).join(", ")} finish${left.length === 1 ? "es" : ""} the move`);
|
|
5083
|
+
}
|
|
5084
|
+
}
|
|
5085
|
+
console.log(` ${c.green("✓")} ${unit} ${c.dim(`moved to library/${kind}/${relOf(unit)} — every workspace in the account can use it`)}`);
|
|
5086
|
+
if (unit !== clean || members.length > 1 || members[0] !== unit) {
|
|
5087
|
+
console.log(` ${c.dim(`only its text files move: anything else in ${unit}/ (an image, a binary) stays in ${ws}`)}`);
|
|
5088
|
+
}
|
|
5089
|
+
console.log();
|
|
5090
|
+
return 0;
|
|
4727
5091
|
}
|
|
4728
5092
|
|
|
4729
5093
|
// ------------------------------------------------- the account, as a whole
|
|
@@ -5492,8 +5856,65 @@ function humanBytes(n) {
|
|
|
5492
5856
|
* newest file is three weeks old and whose run id nobody recognises is the
|
|
5493
5857
|
* shape staleness actually has.
|
|
5494
5858
|
*/
|
|
5859
|
+
/**
|
|
5860
|
+
* `foldrun storage ls --all` — every workspace's files, as the dashboard's
|
|
5861
|
+
* account Storage page: a block per workspace, those with files first and
|
|
5862
|
+
* the busiest first, then the names of the empty ones. The workspaces are
|
|
5863
|
+
* the ones this key may open (GET /api/workspaces), each listed by its own
|
|
5864
|
+
* storage route.
|
|
5865
|
+
*/
|
|
5866
|
+
async function storageLsAll(url, prefix, flags) {
|
|
5867
|
+
const { workspaces = [] } = await remoteCall(url, flags, "/api/workspaces");
|
|
5868
|
+
const inPrefix = (f) => (prefix ? f.path === prefix || f.path.startsWith(prefix.replace(/\/*$/, "/")) : true);
|
|
5869
|
+
const desks = await Promise.all(
|
|
5870
|
+
workspaces.map(async (w) => {
|
|
5871
|
+
try {
|
|
5872
|
+
const body = await remoteCall(url, flags, `/api/workspaces/${enc(w.name)}/storage`);
|
|
5873
|
+
return { workspace: w.name, ...body, files: (body.files ?? []).filter(inPrefix) };
|
|
5874
|
+
} catch (err) {
|
|
5875
|
+
return { workspace: w.name, files: [], error: err instanceof Error ? err.message : String(err) };
|
|
5876
|
+
}
|
|
5877
|
+
}),
|
|
5878
|
+
);
|
|
5879
|
+
const bytes = (d) => d.files.reduce((n, f) => n + (f.size ?? 0), 0);
|
|
5880
|
+
desks.sort((a, b) => (b.files.length > 0 ? 1 : 0) - (a.files.length > 0 ? 1 : 0) || bytes(b) - bytes(a));
|
|
5881
|
+
if (flags.json === true) {
|
|
5882
|
+
console.log(JSON.stringify({ workspaces: desks }, null, 2));
|
|
5883
|
+
return desks.some((d) => d.error) ? 1 : 0;
|
|
5884
|
+
}
|
|
5885
|
+
const full = desks.filter((d) => d.files.length);
|
|
5886
|
+
if (!full.length && !desks.some((d) => d.error)) {
|
|
5887
|
+
console.log(`\n ${c.dim(`nothing in any workspace's storage${prefix ? ` under ${prefix}` : ""}${desks.length ? "" : " — no workspaces yet"}`)}\n`);
|
|
5888
|
+
return 0;
|
|
5889
|
+
}
|
|
5890
|
+
const all = full.flatMap((d) => d.files);
|
|
5891
|
+
const w = {
|
|
5892
|
+
size: Math.max(0, ...all.map((f) => humanBytes(f.size).length)),
|
|
5893
|
+
path: Math.max(0, ...all.map((f) => f.path.length)),
|
|
5894
|
+
when: Math.max(0, ...all.map((f) => when(f.updatedAt).length)),
|
|
5895
|
+
};
|
|
5896
|
+
for (const d of full) {
|
|
5897
|
+
const files = [...d.files].sort((a, b) => (a.updatedAt < b.updatedAt ? 1 : -1));
|
|
5898
|
+
console.log(`\n ${c.bold(d.workspace)} ${c.dim(`${files.length} file${files.length === 1 ? "" : "s"} · ${humanBytes(bytes(d))}${d.quotaMb ? ` of ${d.quotaMb}MB` : ""}`)}`);
|
|
5899
|
+
for (const f of files) {
|
|
5900
|
+
console.log(` ${pad(f.path, w.path)} ${c.dim(`${pad(humanBytes(f.size), w.size)} ${pad(when(f.updatedAt), w.when)} ${ago(f.updatedAt)} ago ${String(f.by ?? "")}`)}`);
|
|
5901
|
+
}
|
|
5902
|
+
}
|
|
5903
|
+
for (const d of desks.filter((x) => x.error)) console.log(`\n ${c.red("✗")} ${c.bold(d.workspace)} ${c.dim(d.error)}`);
|
|
5904
|
+
const empty = desks.filter((d) => !d.files.length && !d.error).map((d) => d.workspace);
|
|
5905
|
+
if (empty.length) console.log(`\n ${c.dim(`nothing${prefix ? ` under ${prefix}` : ""} in ${empty.join(", ")}`)}`);
|
|
5906
|
+
console.log(`\n ${c.dim(`${all.length} file${all.length === 1 ? "" : "s"} in ${full.length} workspace${full.length === 1 ? "" : "s"} · ${humanBytes(all.reduce((n, f) => n + (f.size ?? 0), 0))} — \`foldrun storage cat <path> --to <workspace>\``)}\n`);
|
|
5907
|
+
return desks.some((d) => d.error) ? 1 : 0;
|
|
5908
|
+
}
|
|
5909
|
+
|
|
5495
5910
|
async function storageCmd(positional, flags, layout) {
|
|
5496
5911
|
const url = platformFor(flags, "storage");
|
|
5912
|
+
// `ls --all`: every workspace's storage, as the account's Storage page.
|
|
5913
|
+
// (On `shares`, --all keeps meaning expired and revoked links too.)
|
|
5914
|
+
if ((positional[0] ?? "ls") === "ls" && flags.all === true) {
|
|
5915
|
+
if (typeof flags.to === "string") throw new Error("`foldrun storage ls --all` lists every workspace — or `--to <workspace>` for one, not both");
|
|
5916
|
+
return storageLsAll(url, positional[1], flags);
|
|
5917
|
+
}
|
|
5497
5918
|
// A folder that is not a workspace is not a workspace: `logs` and `source`
|
|
5498
5919
|
// fall back to the directory's NAME, which from ~/Downloads asks the
|
|
5499
5920
|
// platform for a workspace called "Downloads" and reports a 404 as though
|
|
@@ -5827,8 +6248,16 @@ async function triggersCmd(flags, layout) {
|
|
|
5827
6248
|
const days = Number(flags.since) > 0 ? Math.floor(Number(flags.since)) : 7;
|
|
5828
6249
|
const body = await remoteCall(url, flags, `/api/workspaces/${enc(ws)}/triggers?days=${days}`);
|
|
5829
6250
|
const rows = body.flows ?? [];
|
|
6251
|
+
if (flags.json === true) {
|
|
6252
|
+
console.log(JSON.stringify(body, null, 2));
|
|
6253
|
+
return rows.some((r) => (r.dropped ?? []).some((d) => d.outcome === "quarantined")) ? 1 : 0;
|
|
6254
|
+
}
|
|
5830
6255
|
if (!rows.length) {
|
|
5831
|
-
console.log(`\n ${c.dim(`no trigger fired in ${ws} in the last ${body.days ?? days} day${(body.days ?? days) === 1 ? "" : "s"} — a flow fires when its frontmatter says trigger: schedule, webhook, watch, storage or email`)}
|
|
6256
|
+
console.log(`\n ${c.dim(`no trigger fired in ${ws} in the last ${body.days ?? days} day${(body.days ?? days) === 1 ? "" : "s"} — a flow fires when its frontmatter says trigger: schedule, webhook, watch, storage or email`)}`);
|
|
6257
|
+
// A refused delivery never becomes a trigger event, so it can be the
|
|
6258
|
+
// whole answer to "why did nothing run".
|
|
6259
|
+
printTriggerDeliveries(body.deliveries ?? [], triggerLimit(flags));
|
|
6260
|
+
console.log();
|
|
5832
6261
|
return 0;
|
|
5833
6262
|
}
|
|
5834
6263
|
const w = { flow: Math.max(...rows.map((r) => r.flow.length)), trigger: Math.max(...rows.map((r) => r.trigger.length)) };
|
|
@@ -5843,10 +6272,60 @@ async function triggersCmd(flags, layout) {
|
|
|
5843
6272
|
console.log(` ${quarantined && d.outcome === "quarantined" ? c.red(`${d.count}× ${d.outcome}`) : c.dim(`${d.count}× ${d.outcome}`)} ${c.dim(firstLine(d.detail ?? "", 90))}`);
|
|
5844
6273
|
}
|
|
5845
6274
|
}
|
|
5846
|
-
|
|
6275
|
+
printTriggerEvents(body.events ?? [], triggerLimit(flags));
|
|
6276
|
+
printTriggerDeliveries(body.deliveries ?? [], triggerLimit(flags));
|
|
6277
|
+
console.log(`\n ${c.dim(`${rows.length} flow${rows.length === 1 ? "" : "s"} fired in the last ${body.days ?? days} day${(body.days ?? days) === 1 ? "" : "s"}${held ? ` · ${held} switched off by disable_after — one successful run clears it` : ""} · --since <days>, --limit <n>, --json`)}\n`);
|
|
5847
6278
|
return held ? 1 : 0;
|
|
5848
6279
|
}
|
|
5849
6280
|
|
|
6281
|
+
/** How many decisions and deliveries `triggers` prints: --limit, else 10. */
|
|
6282
|
+
const triggerLimit = (flags) => (Number(flags.limit) > 0 ? Math.floor(Number(flags.limit)) : 10);
|
|
6283
|
+
|
|
6284
|
+
/** Each trigger outcome in the Triggers page's words, and the flow key that decided it. */
|
|
6285
|
+
const TRIGGER_REASON = {
|
|
6286
|
+
started: ["started a run", ""],
|
|
6287
|
+
duplicate: ["duplicate delivery", "idempotency:"],
|
|
6288
|
+
throttled: ["inside the window", "throttle:"],
|
|
6289
|
+
debounced: ["held for the burst", "debounce:"],
|
|
6290
|
+
quarantined: ["flow switched off", "disable_after:"],
|
|
6291
|
+
paused: ["work is done, paused", "pause_when:"],
|
|
6292
|
+
halted: ["paused by a person", "account or workspace pause"],
|
|
6293
|
+
"overlap-skipped": ["previous run still live", "overlap: skip"],
|
|
6294
|
+
missed: ["missed while down", "catchup: none"],
|
|
6295
|
+
filtered: ["did not match the filter", "filter:"],
|
|
6296
|
+
failed: ["could not start", ""],
|
|
6297
|
+
};
|
|
6298
|
+
|
|
6299
|
+
const triggerStamp = (iso) => String(iso ?? "").replace("T", " ").slice(0, 19) + "Z";
|
|
6300
|
+
|
|
6301
|
+
/** The trigger log's raw decisions, newest first — the dashboard's "Every decision". */
|
|
6302
|
+
function printTriggerEvents(events, limit) {
|
|
6303
|
+
if (!events.length) return;
|
|
6304
|
+
const shown = events.slice(0, limit);
|
|
6305
|
+
const w = Math.max(...shown.map((e) => String(e.flow ?? "").length));
|
|
6306
|
+
console.log(`\n ${c.bold("every decision, newest first")}${events.length > shown.length ? c.dim(` (${shown.length} of ${events.length} — --limit <n> for more)`) : ""}`);
|
|
6307
|
+
for (const e of shown) {
|
|
6308
|
+
const [label, key] = TRIGGER_REASON[e.outcome] ?? [String(e.outcome), ""];
|
|
6309
|
+
const tone = e.outcome === "started" ? c.green : e.outcome === "quarantined" || e.outcome === "failed" || e.outcome === "halted" ? c.red : c.dim;
|
|
6310
|
+
console.log(` ${c.dim(triggerStamp(e.t))} ${pad(String(e.flow ?? ""), w)} ${tone(label)}${key ? c.dim(` (${key})`) : ""} ${c.dim(firstLine(e.detail ?? "", 90))}`);
|
|
6311
|
+
}
|
|
6312
|
+
}
|
|
6313
|
+
|
|
6314
|
+
/** Requests at the hook and inbox URLs — whether one arrived and was
|
|
6315
|
+
* authentic, before any flow rule had a say. */
|
|
6316
|
+
function printTriggerDeliveries(deliveries, limit) {
|
|
6317
|
+
if (!deliveries.length) return;
|
|
6318
|
+
const refused = deliveries.filter((d) => d.outcome !== "accepted" && d.outcome !== "dropped").length;
|
|
6319
|
+
const shown = deliveries.slice(0, limit);
|
|
6320
|
+
const w = Math.max(...shown.map((d) => String(d.flow ?? "").length));
|
|
6321
|
+
console.log(`\n ${c.bold("deliveries at the hook and inbox URLs")}${refused ? c.red(` · ${refused} refused before any flow rule applied`) : ""}${deliveries.length > shown.length ? c.dim(` (${shown.length} of ${deliveries.length} — --limit <n> for more)`) : ""}`);
|
|
6322
|
+
for (const d of shown) {
|
|
6323
|
+
const bad = d.outcome !== "accepted" && d.outcome !== "dropped";
|
|
6324
|
+
const outcome = `${d.outcome}${d.count > 1 ? ` ×${d.count}` : ""}`;
|
|
6325
|
+
console.log(` ${c.dim(triggerStamp(d.t))} ${pad(String(d.flow ?? ""), w)} ${bad ? c.red(outcome) : d.outcome === "accepted" ? c.green(outcome) : c.dim(outcome)} ${c.dim(firstLine(d.detail ?? "", 90))}`);
|
|
6326
|
+
}
|
|
6327
|
+
}
|
|
6328
|
+
|
|
5850
6329
|
// -------------------------------------------------------------- schedule
|
|
5851
6330
|
|
|
5852
6331
|
/**
|
|
@@ -5940,7 +6419,8 @@ async function providersCmd(url, flags) {
|
|
|
5940
6419
|
*
|
|
5941
6420
|
* foldrun account model what is set, what runs
|
|
5942
6421
|
* foldrun account model set <provider> --key <api key> a preset (anthropic,
|
|
5943
|
-
* openrouter, openai, groq, …) or `custom --base-url https://… --format openai
|
|
6422
|
+
* openrouter, openai, groq, …) or `custom --base-url https://… --format openai`;
|
|
6423
|
+
* --use also switches to it (use own) in the same request
|
|
5944
6424
|
* foldrun account model remove the key (the choice stays)
|
|
5945
6425
|
* foldrun account model use foldrun --provider <p> run on foldrun's models
|
|
5946
6426
|
* foldrun account model use own back to the account's own key
|
|
@@ -6009,14 +6489,25 @@ async function accountModelCmd(url, positional, flags) {
|
|
|
6009
6489
|
}
|
|
6010
6490
|
if (verb === "use") {
|
|
6011
6491
|
const source = positional[1];
|
|
6492
|
+
// --if-version <n>: the choiceVersion read before (`account model --json`;
|
|
6493
|
+
// 0: never chosen). The platform refuses (409) when someone has chosen
|
|
6494
|
+
// since, as the Settings page does — a script will not undo a newer choice.
|
|
6495
|
+
let guard = {};
|
|
6496
|
+
if (flags["if-version"] !== undefined) {
|
|
6497
|
+
// A bare --if-version parses as true, and Number(true) is 1: only digits count.
|
|
6498
|
+
const raw = typeof flags["if-version"] === "string" ? flags["if-version"].trim() : "";
|
|
6499
|
+
const v = /^\d+$/.test(raw) ? Number(raw) : NaN;
|
|
6500
|
+
if (!Number.isSafeInteger(v)) throw new Error("--if-version takes the choiceVersion `foldrun account model --json` shows (0: never chosen)");
|
|
6501
|
+
guard = { ifVersion: v };
|
|
6502
|
+
}
|
|
6012
6503
|
if (source === "own") {
|
|
6013
|
-
out(await put({ source: "own" }));
|
|
6504
|
+
out(await put({ source: "own", ...guard }));
|
|
6014
6505
|
return 0;
|
|
6015
6506
|
}
|
|
6016
6507
|
if (source !== "foldrun") throw new Error("`foldrun account model use foldrun --provider <anthropic|openai|gemini|deepseek|moonshot>` or `foldrun account model use own`");
|
|
6017
6508
|
const supply = typeof flags.provider === "string" ? flags.provider : positional[2];
|
|
6018
6509
|
if (!supply) throw new Error("which provider? `foldrun account model use foldrun --provider anthropic` (anthropic, openai, gemini, deepseek or moonshot — `foldrun account model prices` lists what each costs)");
|
|
6019
|
-
const r = await put({ source: "foldrun", supply });
|
|
6510
|
+
const r = await put({ source: "foldrun", supply, ...guard });
|
|
6020
6511
|
out(r);
|
|
6021
6512
|
return runnable(r) ? 0 : 1;
|
|
6022
6513
|
}
|
|
@@ -6064,6 +6555,9 @@ async function accountModelCmd(url, positional, flags) {
|
|
|
6064
6555
|
apiKey,
|
|
6065
6556
|
...(typeof flags["base-url"] === "string" ? { baseUrl: flags["base-url"] } : {}),
|
|
6066
6557
|
...(typeof flags.format === "string" ? { format: flags.format } : {}),
|
|
6558
|
+
// --use: run on this key from now on, in the same request — what the
|
|
6559
|
+
// dashboard's Save does. Without it the choice stays as it was.
|
|
6560
|
+
...(flags.use === true ? { source: "own" } : {}),
|
|
6067
6561
|
};
|
|
6068
6562
|
out(await put(body));
|
|
6069
6563
|
return 0;
|
|
@@ -6494,7 +6988,14 @@ async function accountCmd(positional, flags) {
|
|
|
6494
6988
|
}
|
|
6495
6989
|
|
|
6496
6990
|
let patch;
|
|
6497
|
-
if (verb === "clear") {
|
|
6991
|
+
if (verb === "clear" && key === "compute" && positional.length > 2) {
|
|
6992
|
+
// `clear compute disk` — just the named figures, as the dashboard's
|
|
6993
|
+
// emptied field does; the platform keeps the others.
|
|
6994
|
+
patch = { compute: computeClears(positional.slice(2), "`foldrun account clear compute [vcpu] [memory] [disk]` — none named clears all three") };
|
|
6995
|
+
} else if (verb === "clear" && key === "notify" && positional.length > 2) {
|
|
6996
|
+
const { defaults } = await remoteCall(url, flags, "/api/account");
|
|
6997
|
+
patch = { notify: notifyWithout(defaults?.notify, positional[2], "foldrun account clear notify") };
|
|
6998
|
+
} else if (verb === "clear") {
|
|
6498
6999
|
patch = { [key]: null };
|
|
6499
7000
|
} else if (key === "alerts" || key === "judge") {
|
|
6500
7001
|
patch = { [key]: await mergedEntry(url, flags, key, positional.slice(2), null, view, `foldrun account set ${key}`) };
|
|
@@ -6837,6 +7338,51 @@ async function runViewsCmd(flags) {
|
|
|
6837
7338
|
return 0;
|
|
6838
7339
|
}
|
|
6839
7340
|
|
|
7341
|
+
/** The filter flags a saved view keeps, as the runs page's query names them
|
|
7342
|
+
* (run-views-model.ts VIEW_KEYS) — the reverse of what --view reads. */
|
|
7343
|
+
const VIEW_FLAGS = [["status", "status"], ["flow", "flow"], ["to", "workspace"], ["since", "since"], ["q", "q"], ["tool", "tool"], ["agent", "agent"], ["model", "model"], ["min-tokens", "min_tokens"], ["min-secs", "min_secs"]];
|
|
7344
|
+
|
|
7345
|
+
/**
|
|
7346
|
+
* `foldrun runs views save <name> [filters]` and `runs views rm <name>` — the
|
|
7347
|
+
* runs page's "save view" (PATCH /api/me/preferences { runViews }). The route
|
|
7348
|
+
* replaces the whole list, so it is read, changed and written back; a view
|
|
7349
|
+
* saved under a name already taken replaces it, as the dashboard does.
|
|
7350
|
+
*/
|
|
7351
|
+
async function runViewsEditCmd([verb, ...rest], flags) {
|
|
7352
|
+
const url = platformFor(flags, "runs views");
|
|
7353
|
+
const name = rest.join(" ").trim();
|
|
7354
|
+
if (verb !== "save" && verb !== "rm") throw new Error(`\`foldrun runs views\` lists your saved views; its verbs are save <name> and rm <name> — not ${verb}`);
|
|
7355
|
+
if (!name) throw new Error(`\`foldrun runs views ${verb} <name>\`${verb === "save" ? " --status failed --since 7d … (the filters to keep)" : " — `foldrun runs views` lists them"}`);
|
|
7356
|
+
const { runViews = [] } = await remoteCall(url, flags, "/api/me/preferences");
|
|
7357
|
+
let list;
|
|
7358
|
+
if (verb === "save") {
|
|
7359
|
+
if (name.length > 40) throw new Error("a view's name is 1 to 40 characters");
|
|
7360
|
+
// Said, not dropped: the route would keep only the keys it knows.
|
|
7361
|
+
for (const f of ["verdict", "outcome"]) if (flags[f] !== undefined) throw new Error(`a saved view keeps --status, --flow, --to, --since, --q, --tool, --tool-error, --agent, --model, --min-tokens and --min-secs — not --${f}`);
|
|
7362
|
+
const query = new URLSearchParams();
|
|
7363
|
+
for (const [flag, key] of VIEW_FLAGS) if (flags[flag] !== undefined && flags[flag] !== true) query.set(key, String(flags[flag]));
|
|
7364
|
+
if (flags["tool-error"] === true) query.set("tool_error", "1");
|
|
7365
|
+
// The dashboard's windows are today, 7d and 30d; its Today is 24 hours.
|
|
7366
|
+
if (["24h", "1d"].includes(String(query.get("since")).trim().toLowerCase())) query.set("since", "today");
|
|
7367
|
+
if (!query.size) throw new Error("a view needs at least one filter — --status, --flow, --to, --since, --q, --tool, --tool-error, --agent, --model, --min-tokens or --min-secs");
|
|
7368
|
+
list = [...runViews.filter((v) => v.name !== name), { name, query: query.toString() }];
|
|
7369
|
+
const since = query.get("since");
|
|
7370
|
+
const d = await remoteCall(url, flags, "/api/me/preferences", { method: "PATCH", body: JSON.stringify({ runViews: list }) });
|
|
7371
|
+
if (flags.json === true) return console.log(JSON.stringify(d.runViews ?? [], null, 2)), 0;
|
|
7372
|
+
console.log(`\n ${c.green("✓")} ${runViews.some((v) => v.name === name) ? "replaced" : "saved"} the view ${c.bold(name)} ${c.dim(query.toString())}`);
|
|
7373
|
+
if (since && !["today", "7d", "30d"].includes(since)) console.log(` ${c.dim(`the runs page's windows are today, 7d and 30d — it shows since=${since} unfiltered; foldrun runs --view applies it`)}`);
|
|
7374
|
+
console.log(` ${c.dim(`foldrun runs --view "${name}" opens it`)}\n`);
|
|
7375
|
+
return 0;
|
|
7376
|
+
}
|
|
7377
|
+
if (!runViews.some((v) => v.name === name)) throw new Error(`no saved view called ${name}${runViews.length ? ` — yours: ${runViews.map((v) => v.name).join(", ")}` : ""}`);
|
|
7378
|
+
if (!(await sureToDelete(flags, "runs views rm", `The saved view ${name}`))) return 1;
|
|
7379
|
+
list = runViews.filter((v) => v.name !== name);
|
|
7380
|
+
const d = await remoteCall(url, flags, "/api/me/preferences", { method: "PATCH", body: JSON.stringify({ runViews: list }) });
|
|
7381
|
+
if (flags.json === true) return console.log(JSON.stringify(d.runViews ?? [], null, 2)), 0;
|
|
7382
|
+
console.log(`\n ${c.green("✓")} deleted the view ${c.bold(name)}\n`);
|
|
7383
|
+
return 0;
|
|
7384
|
+
}
|
|
7385
|
+
|
|
6840
7386
|
// ---------------------------------------------------------------- insights
|
|
6841
7387
|
|
|
6842
7388
|
/** `foldrun insights` (FOL-72 step 8): recurring problems found in the runs,
|
|
@@ -7083,6 +7629,21 @@ async function inboxCmd(positional, flags) {
|
|
|
7083
7629
|
if (verb) {
|
|
7084
7630
|
const action = ACTIONS[verb];
|
|
7085
7631
|
if (!action) throw new Error(`\`foldrun inbox\` lists what waits on you; its verbs are read, unread, dismiss and restore — not ${verb}`);
|
|
7632
|
+
// `inbox read --all`: the inbox's "Mark all read" — every unread item in
|
|
7633
|
+
// the view (--team, --started, --mine narrow it to a tab; --kind,
|
|
7634
|
+
// --workspace as for the list), in calls of 200, the route's most.
|
|
7635
|
+
if (action === "read" && !ids.length && flags.all === true) {
|
|
7636
|
+
const q = new URLSearchParams({ bucket: flags.team === true ? "team" : flags.started === true ? "started" : flags.mine === true ? "mine" : "all" });
|
|
7637
|
+
if (typeof flags.kind === "string") q.set("kind", flags.kind);
|
|
7638
|
+
if (typeof flags.workspace === "string") q.set("workspace", flags.workspace);
|
|
7639
|
+
const view = await remoteCall(url, flags, `/api/me/inbox?${q}`);
|
|
7640
|
+
const unread = (view.items ?? []).filter((i) => !i.read).map((i) => i.id);
|
|
7641
|
+
for (let i = 0; i < unread.length; i += 200) {
|
|
7642
|
+
await remoteCall(url, flags, "/api/me/inbox", { method: "POST", body: JSON.stringify({ ids: unread.slice(i, i + 200), action }) });
|
|
7643
|
+
}
|
|
7644
|
+
console.log(`\n ${unread.length ? c.green(`marked read ${unread.length} item${unread.length === 1 ? "" : "s"}`) : c.dim("nothing unread")}\n`);
|
|
7645
|
+
return 0;
|
|
7646
|
+
}
|
|
7086
7647
|
if (!ids.length) throw new Error(`\`foldrun inbox ${verb} <id>…\` — the ids are the first column of \`foldrun inbox\``);
|
|
7087
7648
|
await remoteCall(url, flags, "/api/me/inbox", { method: "POST", body: JSON.stringify({ ids, action }) });
|
|
7088
7649
|
console.log(`\n ${c.green(action === "dismiss" ? "set aside" : action === "restore" ? "put back" : `marked ${action}`)} ${ids.length} item${ids.length === 1 ? "" : "s"}\n`);
|
|
@@ -7266,19 +7827,23 @@ async function decideCmd(decision, runId, flags, layout) {
|
|
|
7266
7827
|
// are the steps it chooses from; every other decision is a person's gate.
|
|
7267
7828
|
const payload = flags.payload === undefined ? undefined : eventPayload(flags.payload);
|
|
7268
7829
|
if (payload !== undefined && decision !== "approve") throw new Error("--payload releases a `wait: event` step — it cannot go with reject");
|
|
7269
|
-
|
|
7830
|
+
// --event-wait: reject a step parked on `wait: event` — the event box's
|
|
7831
|
+
// Reject on the run page. Stops waiting; the step fails and the run ends.
|
|
7832
|
+
const onEvent = flags["event-wait"] === true;
|
|
7833
|
+
if (onEvent && decision !== "reject") throw new Error("--event-wait goes with reject — `foldrun approve <run-id> --payload …` releases a `wait: event` step");
|
|
7834
|
+
const waiting = payload === undefined && !onEvent ? waitingSteps(run) : eventSteps(run);
|
|
7270
7835
|
if (!waiting.length) {
|
|
7271
7836
|
throw new Error(
|
|
7272
|
-
payload === undefined
|
|
7273
|
-
? `${runId} in ${ws} is ${run.status} — no step of it is waiting on a person. \`foldrun approvals\` lists the ones that are`
|
|
7274
|
-
: `${runId} in ${ws} is ${run.status} — no step of it is waiting on \`wait: event\`, which is what --payload releases`,
|
|
7837
|
+
payload === undefined && !onEvent
|
|
7838
|
+
? `${runId} in ${ws} is ${run.status} — no step of it is waiting on a person.${eventSteps(run).length && decision === "reject" ? " A step is waiting on `wait: event`: --event-wait rejects that one." : ""} \`foldrun approvals\` lists the ones that are`
|
|
7839
|
+
: `${runId} in ${ws} is ${run.status} — no step of it is waiting on \`wait: event\`, which is what ${onEvent ? "--event-wait rejects" : "--payload releases"}`,
|
|
7275
7840
|
);
|
|
7276
7841
|
}
|
|
7277
7842
|
|
|
7278
7843
|
const only = flags.step === undefined ? null : Number(flags.step) - 1;
|
|
7279
7844
|
if (only !== null && !waiting.some(({ index }) => index === only)) {
|
|
7280
7845
|
throw new Error(
|
|
7281
|
-
`step ${flags.step} of ${runId} is not waiting on ${payload === undefined ? "a person" : "`wait: event`"} — ${waiting.map(({ index }) => index + 1).join(", ")} ${waiting.length === 1 ? "is" : "are"}`,
|
|
7846
|
+
`step ${flags.step} of ${runId} is not waiting on ${payload === undefined && !onEvent ? "a person" : "`wait: event`"} — ${waiting.map(({ index }) => index + 1).join(", ")} ${waiting.length === 1 ? "is" : "are"}`,
|
|
7282
7847
|
);
|
|
7283
7848
|
}
|
|
7284
7849
|
const chosen = only === null ? waiting : waiting.filter(({ index }) => index === only);
|
|
@@ -7303,17 +7868,30 @@ async function decideCmd(decision, runId, flags, layout) {
|
|
|
7303
7868
|
return 1;
|
|
7304
7869
|
}
|
|
7305
7870
|
|
|
7306
|
-
|
|
7307
|
-
|
|
7308
|
-
|
|
7309
|
-
|
|
7310
|
-
|
|
7311
|
-
|
|
7312
|
-
|
|
7313
|
-
|
|
7314
|
-
|
|
7315
|
-
|
|
7316
|
-
|
|
7871
|
+
let count = 0;
|
|
7872
|
+
if (onEvent) {
|
|
7873
|
+
// One call per step, each naming it: a reject with no step refuses every
|
|
7874
|
+
// step that waits, a person's gate included. The dashboard's reason.
|
|
7875
|
+
for (const { index } of chosen) {
|
|
7876
|
+
const answer = await remoteCall(url, flags, `/api/workspaces/${ws}/runs/${runId}/approve`, {
|
|
7877
|
+
method: "POST",
|
|
7878
|
+
body: JSON.stringify({ decision, step: index, reason: note ?? "rejected while waiting for its event", ...(note ? { note } : {}) }),
|
|
7879
|
+
});
|
|
7880
|
+
count += Array.isArray(answer.steps) ? answer.steps.length : 1;
|
|
7881
|
+
}
|
|
7882
|
+
} else {
|
|
7883
|
+
const body = {
|
|
7884
|
+
decision,
|
|
7885
|
+
...(note ? { note, ...(decision === "reject" ? { reason: note } : {}) } : {}),
|
|
7886
|
+
...(only === null ? {} : { step: only }),
|
|
7887
|
+
...(payload === undefined ? {} : { payload }),
|
|
7888
|
+
};
|
|
7889
|
+
const answer = await remoteCall(url, flags, `/api/workspaces/${ws}/runs/${runId}/approve`, {
|
|
7890
|
+
method: "POST",
|
|
7891
|
+
body: JSON.stringify(body),
|
|
7892
|
+
});
|
|
7893
|
+
count = Array.isArray(answer.steps) ? answer.steps.length : chosen.length;
|
|
7894
|
+
}
|
|
7317
7895
|
console.log(
|
|
7318
7896
|
`\n ${decision === "approve" ? c.green("✓") : c.red("✗")} ${decision === "approve" ? "approved" : "rejected"} ${count} step${count === 1 ? "" : "s"} of ${runId}` +
|
|
7319
7897
|
`\n ${c.dim(`foldrun report ${runId} --to ${ws} — or logs ${runId} --to ${ws} --follow`)}\n`,
|
|
@@ -8019,6 +8597,7 @@ async function toolTestCmd(positional, flags, layout) {
|
|
|
8019
8597
|
|
|
8020
8598
|
/**
|
|
8021
8599
|
* `foldrun agent run <name> --task "…"` — one agent, once, on the platform.
|
|
8600
|
+
* `--no-task` instead runs it on its own prompt alone (the dashboard's Run).
|
|
8022
8601
|
*
|
|
8023
8602
|
* A flow of one step, without a flow file: the way to try a desk's agent on
|
|
8024
8603
|
* a real task before wiring it into anything, and the way to ask one a
|
|
@@ -8030,8 +8609,12 @@ async function agentRunCmd(positional, flags, layout) {
|
|
|
8030
8609
|
if (!name) throw new Error('which agent? `foldrun agent run <name> --to <workspace> --task "…"`');
|
|
8031
8610
|
const ws = platformWorkspace(flags, layout, `agent run ${name}`);
|
|
8032
8611
|
const task = typeof flags.task === "string" ? flags.task.trim() : "";
|
|
8033
|
-
|
|
8034
|
-
|
|
8612
|
+
// --no-task is the dashboard's one-click Run: the agent works from its own
|
|
8613
|
+
// prompt alone. Explicit, so a mistyped --task does not start a paid run.
|
|
8614
|
+
const bare = flags["no-task"] === true;
|
|
8615
|
+
if (task && bare) throw new Error("either --task or --no-task, not both");
|
|
8616
|
+
if (!task && !bare) {
|
|
8617
|
+
throw new Error(`what should ${name} do? pass --task "<text>", or --no-task to run it on its own prompt alone, as the dashboard's Run does`);
|
|
8035
8618
|
}
|
|
8036
8619
|
|
|
8037
8620
|
// --wait asks in short pieces, exactly as `invoke` does: whatever sits in
|
|
@@ -8059,7 +8642,7 @@ async function agentRunCmd(positional, flags, layout) {
|
|
|
8059
8642
|
method: "POST",
|
|
8060
8643
|
// --test: the platform marks the run a test run — sends refused or sunk
|
|
8061
8644
|
// at the proxy, send-capable secrets withheld, state/ kept.
|
|
8062
|
-
body: JSON.stringify({ task, ...(flags.test === true ? { test: true } : {}) }),
|
|
8645
|
+
body: JSON.stringify({ ...(task ? { task } : {}), ...(flags.test === true ? { test: true } : {}) }),
|
|
8063
8646
|
}),
|
|
8064
8647
|
);
|
|
8065
8648
|
const runId = body?.runId;
|
|
@@ -8158,6 +8741,16 @@ async function checkRemote(flags, layout) {
|
|
|
8158
8741
|
process.env.FOLDRUN_ACCOUNT = root;
|
|
8159
8742
|
// The baseline belongs to the folder it was written in, not to a temp copy.
|
|
8160
8743
|
const code = await check(dir, { ...flags, "no-baseline": true });
|
|
8744
|
+
// The Checks page's "Rescanned daily, last …" (--online prints it with
|
|
8745
|
+
// its own answer). Only GET …/check knows it; best-effort, so an older
|
|
8746
|
+
// platform or a slow answer costs this line, never the check. The rule
|
|
8747
|
+
// asked for matches nothing: only the rescan is wanted from it.
|
|
8748
|
+
if (flags.online !== true && checkOptions(flags).format === "text") {
|
|
8749
|
+
try {
|
|
8750
|
+
const r = await remoteCall(url, { ...flags, quiet: true }, `/api/workspaces/${enc(ws)}/check?rule=rescan-only`, {}, { seconds: 15 });
|
|
8751
|
+
if (r?.rescan?.checkedAt) say(` ${c.dim(`the daily rescan last ran ${r.rescan.checkedAt} — new security findings go to notify:`)}`);
|
|
8752
|
+
} catch {}
|
|
8753
|
+
}
|
|
8161
8754
|
say(` ${c.dim(`checked what is deployed, not this folder — ${ws} · ${url}`)}\n`);
|
|
8162
8755
|
if (flags.online === true) return Math.max(code, await checkOnline(url, flags, ws));
|
|
8163
8756
|
return code;
|
|
@@ -8937,6 +9530,7 @@ async function flowDupStepCmd(positional, flags, layout) {
|
|
|
8937
9530
|
* shows the diff, refuses one `check` would call a new error, then asks —
|
|
8938
9531
|
* a delete, so no terminal needs --yes. --dry-run writes nothing; --to
|
|
8939
9532
|
* <workspace> sends the canvas's PATCH { edit: { op: "remove" } }.
|
|
9533
|
+
* `--step 2,4` deletes several at once: one write, one PATCH { edits }.
|
|
8940
9534
|
*/
|
|
8941
9535
|
async function flowRmStepCmd(positional, flags, layout) {
|
|
8942
9536
|
const flow = positional[1];
|
|
@@ -8947,15 +9541,21 @@ async function flowRmStepCmd(positional, flags, layout) {
|
|
|
8947
9541
|
const { parseFlow } = await core();
|
|
8948
9542
|
const { removeStep, removeStepImpact } = await patterns();
|
|
8949
9543
|
const steps = parseFlow(path.basename(rel), raw).steps;
|
|
8950
|
-
|
|
8951
|
-
|
|
9544
|
+
// --step 2,4 deletes several in one revision, as the canvas's multi-select
|
|
9545
|
+
// does: highest index first, so each still names the step it did when the
|
|
9546
|
+
// list was made (the platform applies { edits } in the order sent).
|
|
9547
|
+
const specs = typeof flags.step === "string" && flags.step.includes(",") ? flags.step.split(",").map((x) => x.trim()).filter(Boolean) : [flags.step];
|
|
9548
|
+
const picked = [...new Set(specs.map((spec) => pickStep(steps, spec, flow)))].sort((x, y) => y - x);
|
|
9549
|
+
const i = picked[0];
|
|
9550
|
+
const impacts = [...picked].reverse().map((k) => removeStepImpact(raw, k));
|
|
9551
|
+
const impact = picked.length === 1 ? impacts[0] : { label: `${picked.length} steps (${impacts.map((x) => x.label).join(", ")})`, notes: impacts.flatMap((x) => x.notes) };
|
|
8952
9552
|
|
|
8953
9553
|
console.log(`\n ${c.bold(flow)} ${c.dim(`· delete ${impact.label} · ${desk.label}`)}\n`);
|
|
8954
9554
|
for (const n of impact.notes) console.log(` ${c.dim("·")} ${n}`);
|
|
8955
9555
|
console.log();
|
|
8956
9556
|
let next;
|
|
8957
9557
|
try {
|
|
8958
|
-
next = removeStep(
|
|
9558
|
+
next = picked.reduce((text, k) => removeStep(text, k), raw);
|
|
8959
9559
|
} catch (err) {
|
|
8960
9560
|
console.log(` ${c.red("✗")} refused — ${err instanceof Error ? err.message : err}; nothing was written\n`);
|
|
8961
9561
|
return 1;
|
|
@@ -8976,7 +9576,8 @@ async function flowRmStepCmd(positional, flags, layout) {
|
|
|
8976
9576
|
return 0;
|
|
8977
9577
|
}
|
|
8978
9578
|
if (desk.platform) {
|
|
8979
|
-
|
|
9579
|
+
const change = picked.length === 1 ? { edit: { op: "remove", step: i } } : { edits: picked.map((step) => ({ op: "remove", step })) };
|
|
9580
|
+
await remoteCall(desk.url, flags, `/api/workspaces/${enc(desk.ws)}/flows/${enc(flow)}`, { method: "PATCH", body: JSON.stringify({ ...change, expect: textSha(raw) }) });
|
|
8980
9581
|
console.log(` ${c.green("✓")} ${rel} ${c.dim(`in ${desk.ws} — a revision on the platform, as the canvas writes it`)}\n`);
|
|
8981
9582
|
} else {
|
|
8982
9583
|
writeIfUnchanged(desk, rel, raw, next);
|
|
@@ -9685,7 +10286,8 @@ function printComparison(r) {
|
|
|
9685
10286
|
* an eval's cases under two to four models, side by side (POST
|
|
9686
10287
|
* …/evals/<e>/compare, then polled). `--models` takes model[:effort] items
|
|
9687
10288
|
* (`fast:low,max:high`); `--effort` is the effort for the items that name
|
|
9688
|
-
* none; `--agent <name>` compares only that agent's steps of a flow eval
|
|
10289
|
+
* none; `--agent <name>` compares only that agent's steps of a flow eval,
|
|
10290
|
+
* and an item's own `@agent` (`fast@writer`) does so for that item alone;
|
|
9689
10291
|
* `--repeat` (1–5) runs each case more than once; `--max-usd` is the spend
|
|
9690
10292
|
* limit (default 5). Every run is a test run. Waits for the result
|
|
9691
10293
|
* (`--timeout <s>`, default 3600; past it, the id to read it with).
|
|
@@ -9737,11 +10339,22 @@ async function evalCompareCmd(name, flags, layout) {
|
|
|
9737
10339
|
const effort = typeof flags.effort === "string" ? flags.effort : undefined;
|
|
9738
10340
|
const agent = typeof flags.agent === "string" ? flags.agent : undefined;
|
|
9739
10341
|
const configs = flags.models.split(",").map((item) => item.trim()).filter(Boolean).map((item) => {
|
|
10342
|
+
// `@agent` at the end compares only that agent's steps in this setting
|
|
10343
|
+
// (the Compare panel's Steps, per row): fast@writer,max:high@writer. An
|
|
10344
|
+
// agent name starts with a letter, so a Vertex-style model@20240620
|
|
10345
|
+
// stays one model id.
|
|
10346
|
+
// Either order: fast:low@writer or fast@writer:low.
|
|
9740
10347
|
// Only a trailing known effort is an effort: llama3.2:3b stays one model id.
|
|
9741
|
-
const
|
|
9742
|
-
|
|
9743
|
-
|
|
9744
|
-
|
|
10348
|
+
const effortOf = (x) => /^(.*):(low|medium|high|xhigh|max)$/.exec(x);
|
|
10349
|
+
let model = item;
|
|
10350
|
+
let e;
|
|
10351
|
+
let m = effortOf(model);
|
|
10352
|
+
if (m) [, model, e] = m;
|
|
10353
|
+
const at = /^(.*)@([a-z][a-z0-9_-]*)$/i.exec(model);
|
|
10354
|
+
if (at) model = at[1];
|
|
10355
|
+
if (!e && (m = effortOf(model))) [, model, e] = m;
|
|
10356
|
+
const a = at ? at[2] : agent;
|
|
10357
|
+
return { model, ...((e ?? effort) ? { effort: e ?? effort } : {}), ...(a ? { agent: a } : {}) };
|
|
9745
10358
|
});
|
|
9746
10359
|
const body = { configs, ...(flags.repeat !== undefined ? { repeat: Number(flags.repeat) } : {}), ...(flags["max-usd"] !== undefined ? { maxUsd: Number(flags["max-usd"]) } : {}) };
|
|
9747
10360
|
const started = await remoteCall(url, flags, base, { method: "POST", body: JSON.stringify(body) });
|
|
@@ -9984,6 +10597,38 @@ async function bulkCmd(action, flags, layout) {
|
|
|
9984
10597
|
const r = await remoteCall(url, flags, `/api/workspaces/${enc(ws)}/runs/bulk`, { method: "POST", body: JSON.stringify({ action, ...filter, dryRun: true }) });
|
|
9985
10598
|
return { ws, ids: r.matched ?? [] };
|
|
9986
10599
|
});
|
|
10600
|
+
return bulkApply(action, plans, filter.from, flags, url);
|
|
10601
|
+
}
|
|
10602
|
+
|
|
10603
|
+
/**
|
|
10604
|
+
* `foldrun stop|rerun <run-id> <run-id>…` — the runs list's selection bar
|
|
10605
|
+
* (POST …/runs/bulk { action, runIds }, once per workspace). Each id's
|
|
10606
|
+
* workspace is found as for one run (or --to); then it lists, asks and acts.
|
|
10607
|
+
*/
|
|
10608
|
+
async function bulkIdsCmd(action, ids, flags, layout) {
|
|
10609
|
+
const url = platformFor(flags, action);
|
|
10610
|
+
if (hasBulkFilter(flags)) throw new Error(`name the runs or give a filter (--status, --since, --until, --flow), not both — \`foldrun ${action} <run-id>…\``);
|
|
10611
|
+
let from;
|
|
10612
|
+
if (action === "rerun") {
|
|
10613
|
+
// The bulk route reruns from a step number; these have no bulk form.
|
|
10614
|
+
for (const f of ["agent", "instruction", "wait"]) if (flags[f] !== undefined) throw new Error(`--${f} reruns one run — with several ids, --from <n> is the step they all start from`);
|
|
10615
|
+
from = flags.from === undefined ? 1 : Number(flags.from);
|
|
10616
|
+
if (!Number.isInteger(from) || from < 1) throw new Error("--from is a step number, 1 or more");
|
|
10617
|
+
}
|
|
10618
|
+
const unique = [...new Set(ids)];
|
|
10619
|
+
const found = await pool(unique, 4, async (id) => ({ id, ws: await workspaceOfRun(url, flags, layout, id) }));
|
|
10620
|
+
const plans = [];
|
|
10621
|
+
for (const { id, ws } of found) {
|
|
10622
|
+
const plan = plans.find((p) => p.ws === ws) ?? (plans.push({ ws, ids: [] }), plans[plans.length - 1]);
|
|
10623
|
+
plan.ids.push(id);
|
|
10624
|
+
}
|
|
10625
|
+
return bulkApply(action, plans, from, flags, url);
|
|
10626
|
+
}
|
|
10627
|
+
|
|
10628
|
+
/** What a bulk stop or rerun does once it knows the runs: list them, stop at
|
|
10629
|
+
* --dry-run, ask, then act in calls of at most 100 (the route's cap). */
|
|
10630
|
+
async function bulkApply(action, plans, from, flags, url) {
|
|
10631
|
+
const filter = { from };
|
|
9987
10632
|
const total = plans.reduce((n, x) => n + x.ids.length, 0);
|
|
9988
10633
|
console.log();
|
|
9989
10634
|
for (const { ws, ids } of plans.filter((x) => x.ids.length)) {
|
|
@@ -10006,14 +10651,23 @@ async function bulkCmd(action, flags, layout) {
|
|
|
10006
10651
|
}
|
|
10007
10652
|
let bad = 0;
|
|
10008
10653
|
console.log();
|
|
10009
|
-
for (const { ws, ids } of plans.filter((x) => x.ids.length)) {
|
|
10010
|
-
|
|
10011
|
-
|
|
10012
|
-
|
|
10013
|
-
|
|
10014
|
-
|
|
10015
|
-
|
|
10016
|
-
|
|
10654
|
+
for (const { ws, ids: all } of plans.filter((x) => x.ids.length)) {
|
|
10655
|
+
for (let i = 0; i < all.length; i += 100) {
|
|
10656
|
+
const ids = all.slice(i, i + 100);
|
|
10657
|
+
const r = await remoteCall(url, flags, `/api/workspaces/${enc(ws)}/runs/bulk`, {
|
|
10658
|
+
method: "POST",
|
|
10659
|
+
body: JSON.stringify({ action, runIds: ids, ...(action === "rerun" ? { from: filter.from } : {}) }),
|
|
10660
|
+
});
|
|
10661
|
+
for (const x of r.runs ?? []) {
|
|
10662
|
+
if (!x.ok) bad++;
|
|
10663
|
+
console.log(` ${x.ok ? c.green("✓") : c.red("✗")} ${ws} ${x.runId}${x.newRunId ? c.dim(` → ${x.newRunId}`) : ""}${x.error ? c.dim(` — ${x.error}`) : ""}`);
|
|
10664
|
+
}
|
|
10665
|
+
// Asked for but not answered: gone since it was listed.
|
|
10666
|
+
const answered = new Set((r.runs ?? []).map((x) => x.runId));
|
|
10667
|
+
for (const id of ids.filter((x) => !answered.has(x))) {
|
|
10668
|
+
bad++;
|
|
10669
|
+
console.log(` ${c.red("✗")} ${ws} ${id}${c.dim(" — not found (deleted since it was listed?)")}`);
|
|
10670
|
+
}
|
|
10017
10671
|
}
|
|
10018
10672
|
}
|
|
10019
10673
|
console.log(`\n ${c.dim(`${total - bad} of ${total} ${action === "stop" ? "stopped" : "rerun"}${bad ? ` · ${bad} refused` : ""}`)}\n`);
|
|
@@ -10034,6 +10688,38 @@ async function runRmCmd(runId, flags, layout) {
|
|
|
10034
10688
|
return 0;
|
|
10035
10689
|
}
|
|
10036
10690
|
|
|
10691
|
+
/** `foldrun runs rm <run-id> <run-id>…` — the selection bar's Delete: lists
|
|
10692
|
+
* them, asks once, then one DELETE per run (there is no bulk delete route),
|
|
10693
|
+
* each its own outcome so one refusal does not stop the rest. */
|
|
10694
|
+
async function runsRmManyCmd(ids, flags, layout) {
|
|
10695
|
+
const url = platformFor(flags, "runs rm");
|
|
10696
|
+
const unique = [...new Set(ids)];
|
|
10697
|
+
const runs = await pool(unique, 4, async (id) => {
|
|
10698
|
+
const ws = await workspaceOfRun(url, flags, layout, id);
|
|
10699
|
+
const run = await remoteCall(url, flags, `/api/workspaces/${enc(ws)}/runs/${enc(id)}`);
|
|
10700
|
+
return { id, ws, run };
|
|
10701
|
+
});
|
|
10702
|
+
console.log();
|
|
10703
|
+
for (const { id, ws, run } of runs) console.log(` ${statusMark(run.status)} ${ws} ${c.bold(run.flow)} ${c.dim(`${run.status} · ${id}`)}`);
|
|
10704
|
+
const live = runs.filter(({ run }) => run.status !== "completed" && run.status !== "failed").length;
|
|
10705
|
+
console.log();
|
|
10706
|
+
const what = `These ${runs.length} runs — their records and archived outputs${live ? `; ${live} still going ${live === 1 ? "is" : "are"} stopped first` : ""}. The ledger lines stay`;
|
|
10707
|
+
if (!(await sureToDelete(flags, "runs rm", what))) return 1;
|
|
10708
|
+
let bad = 0;
|
|
10709
|
+
console.log();
|
|
10710
|
+
for (const { id, ws } of runs) {
|
|
10711
|
+
try {
|
|
10712
|
+
await remoteCall(url, flags, `/api/workspaces/${enc(ws)}/runs/${enc(id)}`, { method: "DELETE" });
|
|
10713
|
+
console.log(` ${c.green("✓")} ${ws} ${id} deleted`);
|
|
10714
|
+
} catch (err) {
|
|
10715
|
+
bad++;
|
|
10716
|
+
console.log(` ${c.red("✗")} ${ws} ${id}${c.dim(` — ${explain(err)}`)}`);
|
|
10717
|
+
}
|
|
10718
|
+
}
|
|
10719
|
+
console.log(`\n ${c.dim(`${runs.length - bad} of ${runs.length} deleted${bad ? ` · ${bad} refused` : ""}`)}\n`);
|
|
10720
|
+
return bad ? 1 : 0;
|
|
10721
|
+
}
|
|
10722
|
+
|
|
10037
10723
|
const SAFE_NAME = /^[a-z0-9]+(-[a-z0-9]+)*$/;
|
|
10038
10724
|
|
|
10039
10725
|
/**
|
|
@@ -10338,6 +11024,9 @@ async function usageCmd(flags) {
|
|
|
10338
11024
|
const url = platformFor(flags, "usage");
|
|
10339
11025
|
const days = flags.days === undefined ? 56 : Number(flags.days);
|
|
10340
11026
|
if (!Number.isInteger(days) || days < 1 || days > 365) throw new Error("--days is a whole number of days, 1 to 365");
|
|
11027
|
+
// How many rows of the by-flow and by-agent tables (the Usage page's).
|
|
11028
|
+
const limit = flags.limit === undefined ? 10 : Number(flags.limit);
|
|
11029
|
+
if (!Number.isInteger(limit) || limit < 0) throw new Error("--limit is a whole number of rows for by flow and by agent, 0 to hide them");
|
|
10341
11030
|
const [u, h] = await Promise.all([remoteCall(url, flags, "/api/usage"), remoteCall(url, flags, `/api/usage/history?days=${days}`)]);
|
|
10342
11031
|
if (flags.json === true) {
|
|
10343
11032
|
console.log(JSON.stringify({ usage: u, history: h }, null, 2));
|
|
@@ -10368,7 +11057,20 @@ async function usageCmd(flags) {
|
|
|
10368
11057
|
console.log(` ${c.bold(pad(x.name, w))} ${pad(usd(x.totalUsd), 9)} ${pad(`${x.runs} runs`, 9)} ${change} ${c.dim(`vs the ${h.bucket} before`)}`);
|
|
10369
11058
|
}
|
|
10370
11059
|
}
|
|
10371
|
-
|
|
11060
|
+
// By flow and by agent: the charged series the Usage page tables show,
|
|
11061
|
+
// most charged first, the first --limit of each.
|
|
11062
|
+
for (const [title, rows] of [["by flow", h.byFlow ?? []], ["by agent", h.byAgent ?? []]]) {
|
|
11063
|
+
if (!rows.length || !limit) continue;
|
|
11064
|
+
const top = rows.slice().sort((a, b) => (b.totalUsd ?? 0) - (a.totalUsd ?? 0)).slice(0, limit);
|
|
11065
|
+
const w = Math.max(...top.map((x) => String(x.name).length));
|
|
11066
|
+
console.log(`\n ${c.bold(title)} ${c.dim(`charged, ${h.from?.slice(0, 10)} → ${h.to?.slice(0, 10)}`)}`);
|
|
11067
|
+
for (const x of top) {
|
|
11068
|
+
const change = x.change == null ? c.dim("—") : x.change > 0 ? c.amber(`+${Math.round(x.change * 100)}%`) : c.green(`${Math.round(x.change * 100)}%`);
|
|
11069
|
+
console.log(` ${pad(printable(x.name), w)} ${pad(usd(x.totalUsd), 9)} ${pad(x.runs ? `${x.runs} run${x.runs === 1 ? "" : "s"}` : "—", 9)} ${change}`);
|
|
11070
|
+
}
|
|
11071
|
+
if (rows.length > top.length) console.log(` ${c.dim(`and ${rows.length - top.length} more — --limit <n> shows more`)}`);
|
|
11072
|
+
}
|
|
11073
|
+
console.log(`\n ${c.dim("--days <n> for another window · --limit <n> rows by flow and by agent · --json for both documents · foldrun billing for the balance")}\n`);
|
|
10372
11074
|
return 0;
|
|
10373
11075
|
}
|
|
10374
11076
|
|
|
@@ -10397,6 +11099,39 @@ function computePairs(pairs, usage) {
|
|
|
10397
11099
|
return out;
|
|
10398
11100
|
}
|
|
10399
11101
|
|
|
11102
|
+
/**
|
|
11103
|
+
* `disk` / `vcpu memory` → { diskGiB: null, … }: the named figures as null,
|
|
11104
|
+
* which the platform drops while keeping the rest (the dashboard's emptied
|
|
11105
|
+
* field sends the same). Clearing all three is plain `clear compute`.
|
|
11106
|
+
*/
|
|
11107
|
+
function computeClears(names, usage) {
|
|
11108
|
+
const fields = { vcpu: "vcpu", memory: "memGiB", disk: "diskGiB" };
|
|
11109
|
+
/** @type {Record<string, null>} */
|
|
11110
|
+
const out = {};
|
|
11111
|
+
for (const n of names) {
|
|
11112
|
+
if (!(n in fields)) throw new Error(`${usage} — not "${n}"`);
|
|
11113
|
+
out[fields[n]] = null;
|
|
11114
|
+
}
|
|
11115
|
+
return out;
|
|
11116
|
+
}
|
|
11117
|
+
|
|
11118
|
+
/**
|
|
11119
|
+
* The notify block without one channel (email or url), the other and the
|
|
11120
|
+
* events kept. The platform replaces the block whole and refuses one with
|
|
11121
|
+
* neither channel, so the last one goes with a plain `clear notify`.
|
|
11122
|
+
*/
|
|
11123
|
+
function notifyWithout(current, channel, clearAll) {
|
|
11124
|
+
if (channel !== "email" && channel !== "url") throw new Error(`\`${clearAll} email\` or \`${clearAll} url\` drops one channel — \`${clearAll}\` alone turns notify off`);
|
|
11125
|
+
const n = current && typeof current === "object" ? current : {};
|
|
11126
|
+
if (!n[channel]) throw new Error(`notify has no ${channel === "url" ? "webhook URL" : "email"} set here — nothing to clear`);
|
|
11127
|
+
const other = channel === "email" ? "url" : "email";
|
|
11128
|
+
// A key limited to some workspaces sees the account's URL only as hidden;
|
|
11129
|
+
// sending the block without it would drop it.
|
|
11130
|
+
if (other === "url" && !n.url && n.hidden) throw new Error("the webhook URL beside it is hidden from this key — clear the email with a key that holds every workspace");
|
|
11131
|
+
if (!n[other]) throw new Error(`the ${channel === "url" ? "webhook URL" : "email"} is notify's only channel — \`${clearAll}\` turns notify off`);
|
|
11132
|
+
return { [other]: n[other], events: Array.isArray(n.events) && n.events.length ? n.events : ["failed", "awaiting-approval"] };
|
|
11133
|
+
}
|
|
11134
|
+
|
|
10400
11135
|
/** A size as AGENTS.md writes it — 8Gi, 1536Mi, 8g — in GiB; null when none. */
|
|
10401
11136
|
function quantityGiB(q) {
|
|
10402
11137
|
const m = /^(\d+(?:\.\d+)?)\s*(Mi|Gi|m|g)$/.exec(String(q ?? "").trim());
|
|
@@ -10516,7 +11251,7 @@ async function billingVerbCmd(positional, flags) {
|
|
|
10516
11251
|
console.log(` ${c.dim(`burn ${usd(s.burnPerDayUsd)}/day · 7d ${usd(s.spend7dUsd)} · 30d ${usd(s.spend30dUsd)} · month to date ${usd(s.monthToDateUsd)}`)}`);
|
|
10517
11252
|
if (s.daysLeft != null) console.log(` ${s.daysLeft < 7 ? c.amber("!") : c.dim("·")} ${c.dim(`about ${Math.round(s.daysLeft)} days left at this burn${s.emptyOn ? ` — empty on ${s.emptyOn.slice(0, 10)}` : ""}${s.suggestedTopUpUsd ? `; ${usd(s.suggestedTopUpUsd)} covers about a month` : ""}`)}`);
|
|
10518
11253
|
const a = w.autoTopUp;
|
|
10519
|
-
console.log(` auto top-up ${a?.enabled ? `${usd(a.amountUsd)} when the balance falls below ${usd(a.thresholdUsd)}` : c.dim(
|
|
11254
|
+
console.log(` auto top-up ${a?.enabled ? `${usd(a.amountUsd)} when the balance falls below ${usd(a.thresholdUsd)}` : c.dim(`off${a ? ` (${usd(a.amountUsd)} below ${usd(a.thresholdUsd)} kept)` : ""}`)}${w.cardSaved ? "" : c.dim(" · no card saved")}`);
|
|
10520
11255
|
if (w.email) console.log(` receipts ${w.email}`);
|
|
10521
11256
|
// foldrun.ir (3 Nov 2026): paying with an Iranian card, in Toman.
|
|
10522
11257
|
if (w.tomanTopUp?.url) console.log(` in Toman ${w.tomanTopUp.url}`);
|
|
@@ -10524,15 +11259,26 @@ async function billingVerbCmd(positional, flags) {
|
|
|
10524
11259
|
console.log(`\n ${c.dim("foldrun billing wallet set auto-top-up --threshold 10 --amount 50 · set auto-top-up off")}\n`);
|
|
10525
11260
|
return 0;
|
|
10526
11261
|
}
|
|
11262
|
+
// `wallet clear email`: no receipt or warning address (the page's
|
|
11263
|
+
// emptied field sends the same).
|
|
11264
|
+
if (sub === "clear") {
|
|
11265
|
+
if (rest[0] !== "email") throw new Error("`foldrun billing wallet clear email` — no address for receipts and low-balance warnings; `wallet set auto-top-up off` turns the refill off");
|
|
11266
|
+
await ownerOnly(() => remoteCall(url, flags, "/api/billing/wallet", { method: "PUT", body: JSON.stringify({ email: null }) }), "changing the wallet");
|
|
11267
|
+
console.log(`\n ${c.green("✓")} no receipt email — the low-balance warning has nowhere to go until one is set\n`);
|
|
11268
|
+
return 0;
|
|
11269
|
+
}
|
|
10527
11270
|
if (sub !== "set" || !["auto-top-up", "email"].includes(rest[0])) {
|
|
10528
|
-
throw new Error("`foldrun billing wallet set auto-top-up --threshold <usd> --amount <usd>` (or `off`), or `wallet set email <address>`");
|
|
11271
|
+
throw new Error("`foldrun billing wallet set auto-top-up --threshold <usd> --amount <usd>` (or `off`), or `wallet set email <address>` (`wallet clear email` for none)");
|
|
10529
11272
|
}
|
|
10530
11273
|
let body;
|
|
10531
11274
|
if (rest[0] === "email") {
|
|
10532
11275
|
if (!rest[1]) throw new Error("`foldrun billing wallet set email <address>` — where receipts and low-balance warnings go");
|
|
10533
11276
|
body = { email: rest[1] };
|
|
10534
11277
|
} else if (rest[1] === "off") {
|
|
10535
|
-
|
|
11278
|
+
// Off keeps the threshold and the refill for next time, as the
|
|
11279
|
+
// wallet page's switch does; null would forget them.
|
|
11280
|
+
const a = (await ownerOnly(() => remoteCall(url, flags, "/api/billing/wallet"), "changing the wallet")).autoTopUp;
|
|
11281
|
+
body = { autoTopUp: a && a.thresholdUsd > 0 && a.amountUsd >= 5 ? { enabled: false, thresholdUsd: a.thresholdUsd, amountUsd: a.amountUsd } : null };
|
|
10536
11282
|
} else {
|
|
10537
11283
|
const threshold = Number(flags.threshold);
|
|
10538
11284
|
const amount = Number(flags.amount);
|
|
@@ -10542,7 +11288,11 @@ async function billingVerbCmd(positional, flags) {
|
|
|
10542
11288
|
body = { autoTopUp: { enabled: true, thresholdUsd: threshold, amountUsd: amount } };
|
|
10543
11289
|
}
|
|
10544
11290
|
await ownerOnly(() => remoteCall(url, flags, "/api/billing/wallet", { method: "PUT", body: JSON.stringify(body) }), "changing the wallet");
|
|
10545
|
-
const said = body.email
|
|
11291
|
+
const said = body.email
|
|
11292
|
+
? `receipts go to ${body.email}`
|
|
11293
|
+
: body.autoTopUp?.enabled
|
|
11294
|
+
? `auto top-up on: ${usd(body.autoTopUp.amountUsd)} whenever the balance falls below ${usd(body.autoTopUp.thresholdUsd)}`
|
|
11295
|
+
: `auto top-up off${body.autoTopUp ? c.dim(` — ${usd(body.autoTopUp.amountUsd)} below ${usd(body.autoTopUp.thresholdUsd)} kept for next time`) : ""}`;
|
|
10546
11296
|
console.log(`\n ${c.green("✓")} ${said}\n`);
|
|
10547
11297
|
return 0;
|
|
10548
11298
|
}
|
|
@@ -10562,7 +11312,12 @@ async function billingVerbCmd(positional, flags) {
|
|
|
10562
11312
|
return 0;
|
|
10563
11313
|
}
|
|
10564
11314
|
if (sub !== "set") throw new Error("`foldrun billing details` shows them; `details set --name … --abn … --address … --email …` changes them");
|
|
10565
|
-
|
|
11315
|
+
// --clear-address / --clear-email / --clear-abn: the PUT replaces the
|
|
11316
|
+
// details whole, so a field left out of it is gone.
|
|
11317
|
+
for (const k of ["address", "email", "abn"]) {
|
|
11318
|
+
if (flags[`clear-${k}`] === true && typeof flags[k] === "string") throw new Error(`--${k} or --clear-${k}, not both`);
|
|
11319
|
+
}
|
|
11320
|
+
let address = flags["clear-address"] === true ? undefined : d?.address;
|
|
10566
11321
|
if (typeof flags.address === "string") {
|
|
10567
11322
|
// line1[, line2], city, state, postcode, country — the last part is the
|
|
10568
11323
|
// two-letter country, the first is line 1, the rest fill in order.
|
|
@@ -10578,8 +11333,8 @@ async function billingVerbCmd(positional, flags) {
|
|
|
10578
11333
|
}
|
|
10579
11334
|
const next = {
|
|
10580
11335
|
legalName: typeof flags.name === "string" ? flags.name : d?.legalName ?? "",
|
|
10581
|
-
...((typeof flags.email === "string" ? flags.email : d?.email) ? { email: typeof flags.email === "string" ? flags.email : d.email } : {}),
|
|
10582
|
-
...((typeof flags.abn === "string" ? flags.abn : d?.abn) ? { abn: typeof flags.abn === "string" ? flags.abn : d.abn } : {}),
|
|
11336
|
+
...(flags["clear-email"] !== true && (typeof flags.email === "string" ? flags.email : d?.email) ? { email: typeof flags.email === "string" ? flags.email : d.email } : {}),
|
|
11337
|
+
...(flags["clear-abn"] !== true && (typeof flags.abn === "string" ? flags.abn : d?.abn) ? { abn: typeof flags.abn === "string" ? flags.abn : d.abn } : {}),
|
|
10583
11338
|
...(address ? { address } : {}),
|
|
10584
11339
|
};
|
|
10585
11340
|
const r = await ownerOnly(() => remoteCall(url, flags, "/api/billing/details", { method: "PUT", body: JSON.stringify(next) }), "changing the billing details");
|
|
@@ -10669,7 +11424,11 @@ async function workspaceCmd(positional, flags, layout) {
|
|
|
10669
11424
|
|
|
10670
11425
|
/** @type {Record<string, any>} */
|
|
10671
11426
|
let patch;
|
|
10672
|
-
if (verb === "clear"
|
|
11427
|
+
if (verb === "clear" && key === "compute" && rest.length) {
|
|
11428
|
+
patch = { compute: computeClears(rest, `\`foldrun workspace clear compute [vcpu] [memory] [disk] --to ${ws}\` — none named clears all three`) };
|
|
11429
|
+
} else if (verb === "clear" && key === "notify" && rest.length) {
|
|
11430
|
+
patch = { notify: notifyWithout(/** @type {any} */ ((await workspaceDefaults(url, flags, ws)).notify), rest[0], `foldrun workspace clear notify --to ${ws}`) };
|
|
11431
|
+
} else if (verb === "clear") patch = { [key]: key === "description" ? "" : null };
|
|
10673
11432
|
else if (key === "alerts" || key === "judge") {
|
|
10674
11433
|
patch = { [key]: await mergedEntry(url, flags, key, rest, ws, view, `foldrun workspace set ${key}`) };
|
|
10675
11434
|
} else if (key === "compute") {
|
|
@@ -11266,9 +12025,10 @@ async function flowTriggerCmd(positional, flags, layout) {
|
|
|
11266
12025
|
*/
|
|
11267
12026
|
async function flowComputeCmd(positional, flags, layout) {
|
|
11268
12027
|
const flow = positional[1];
|
|
11269
|
-
const usage = "`foldrun flow compute <flow> vcpu <cores> memory <GiB> disk <GiB>` — any of them; `--clear` for no cap of its own";
|
|
12028
|
+
const usage = "`foldrun flow compute <flow> vcpu <cores> memory <GiB> disk <GiB>` — any of them; `--clear` for no cap of its own, `--clear disk` (or vcpu, memory) for one";
|
|
11270
12029
|
if (!flow) throw new Error(usage);
|
|
11271
|
-
|
|
12030
|
+
// `--clear disk`: just the named figures go, the route keeps the rest.
|
|
12031
|
+
const asked = flags.clear === true ? (positional.length > 2 ? computeClears(positional.slice(2), usage) : null) : computePairs(positional.slice(2), usage);
|
|
11272
12032
|
const dry = flags["dry-run"] === true;
|
|
11273
12033
|
if (namesPlatform(flags)) {
|
|
11274
12034
|
// On the platform: the route merges, so nothing needs reading first.
|
|
@@ -11299,9 +12059,12 @@ async function flowComputeCmd(positional, flags, layout) {
|
|
|
11299
12059
|
let value = null;
|
|
11300
12060
|
if (asked) {
|
|
11301
12061
|
value = typeof current === "object" && current && !Array.isArray(current) ? { ...current } : {};
|
|
11302
|
-
|
|
11303
|
-
|
|
11304
|
-
|
|
12062
|
+
for (const [from, to] of [["vcpu", "vcpu"], ["memGiB", "memory"], ["diskGiB", "disk"]]) {
|
|
12063
|
+
if (asked[from] === undefined) continue;
|
|
12064
|
+
if (asked[from] === null) delete value[to];
|
|
12065
|
+
else value[to] = to === "vcpu" ? asked[from] : `${asked[from]}Gi`;
|
|
12066
|
+
}
|
|
12067
|
+
if (!Object.keys(value).length) value = null;
|
|
11305
12068
|
}
|
|
11306
12069
|
const next = patchFrontmatter(raw, { compute: value });
|
|
11307
12070
|
if (dry) {
|
|
@@ -11632,7 +12395,8 @@ async function assistantCmd(positional, flags, layout) {
|
|
|
11632
12395
|
url,
|
|
11633
12396
|
flags,
|
|
11634
12397
|
`/api/workspaces/${enc(ws)}/assistant`,
|
|
11635
|
-
|
|
12398
|
+
// --page: what the dashboard sends as the page you are on ("flows — daily.md").
|
|
12399
|
+
{ method: "POST", body: JSON.stringify({ messages, files: files.map(({ path: p, content }) => ({ path: p, content })), ...(conversation ? { conversation } : {}), ...(typeof flags.page === "string" && flags.page.trim() ? { page: flags.page.trim() } : {}) }) },
|
|
11636
12400
|
{ seconds: Math.max(timeoutSeconds(flags), 300) },
|
|
11637
12401
|
);
|
|
11638
12402
|
} catch (err) {
|
|
@@ -12985,8 +13749,19 @@ async function a2aLsCmd(flags, layout) {
|
|
|
12985
13749
|
* route's PATCH { a2a }, merged there over the flow's block (a key given
|
|
12986
13750
|
* replaces it, a key given as null removes it). */
|
|
12987
13751
|
export function a2aPatchFor(verb, flags) {
|
|
12988
|
-
|
|
12989
|
-
|
|
13752
|
+
// --clear-name, --clear-description, --clear-examples: the card's words
|
|
13753
|
+
// go (null, as the flow page's emptied field sends), on either verb.
|
|
13754
|
+
/** @type {Record<string, unknown>} */
|
|
13755
|
+
const clears = {};
|
|
13756
|
+
for (const k of ["name", "description", "examples"]) {
|
|
13757
|
+
if (flags[`clear-${k}`] !== true) continue;
|
|
13758
|
+
const given = k === "examples" ? many(flags.example).length > 0 : typeof flags[k] === "string";
|
|
13759
|
+
if (given) throw new Error(`--${k === "examples" ? "example" : k} or --clear-${k}, not both`);
|
|
13760
|
+
clears[k] = null;
|
|
13761
|
+
}
|
|
13762
|
+
if (verb !== "publish") return { publish: false, ...clears };
|
|
13763
|
+
/** @type {Record<string, unknown>} */
|
|
13764
|
+
const patch = { publish: true, ...clears };
|
|
12990
13765
|
if (typeof flags.name === "string") patch.name = flags.name;
|
|
12991
13766
|
if (typeof flags.description === "string") patch.description = flags.description;
|
|
12992
13767
|
const examples = many(flags.example);
|
|
@@ -13419,7 +14194,8 @@ export async function run(command, positional, flags, workspace, layout) {
|
|
|
13419
14194
|
// `runs` was a second spelling of `logs`, and --local keeps it one:
|
|
13420
14195
|
// the local store has no table to draw across workspaces, because a
|
|
13421
14196
|
// folder on a laptop is one workspace.
|
|
13422
|
-
if (positional[0] === "rm") return runRmCmd(positional[1], flags, layout);
|
|
14197
|
+
if (positional[0] === "rm") return positional.length > 2 ? runsRmManyCmd(positional.slice(1), flags, layout) : runRmCmd(positional[1], flags, layout);
|
|
14198
|
+
if (positional[0] === "views" && positional[1]) return runViewsEditCmd(positional.slice(1), flags);
|
|
13423
14199
|
if (positional[0] === "views") return runViewsCmd(flags);
|
|
13424
14200
|
// The run doctor (FOL-22): the assistant reads the run and its files,
|
|
13425
14201
|
// says why it failed and proposes the fix as diffs — saved on yes.
|
|
@@ -13450,6 +14226,8 @@ export async function run(command, positional, flags, workspace, layout) {
|
|
|
13450
14226
|
case "stop":
|
|
13451
14227
|
// No run id and a filter: every run the filter matches (runs/bulk).
|
|
13452
14228
|
if (!positional[0] && hasBulkFilter(flags)) return bulkCmd("stop", flags, layout);
|
|
14229
|
+
// Several run ids: the dashboard's selection bar (runs/bulk { runIds }).
|
|
14230
|
+
if (positional.length > 1) return bulkIdsCmd("stop", positional, flags, layout);
|
|
13453
14231
|
return stopCmd(positional[0], flags, layout);
|
|
13454
14232
|
case "answer":
|
|
13455
14233
|
return answerCmd(positional, flags);
|
|
@@ -13457,6 +14235,7 @@ export async function run(command, positional, flags, workspace, layout) {
|
|
|
13457
14235
|
return messageCmd(positional, flags, layout);
|
|
13458
14236
|
case "rerun":
|
|
13459
14237
|
if (!positional[0] && hasBulkFilter(flags)) return bulkCmd("rerun", flags, layout);
|
|
14238
|
+
if (positional.length > 1) return bulkIdsCmd("rerun", positional, flags, layout);
|
|
13460
14239
|
return rerunCmd(positional[0], flags, layout);
|
|
13461
14240
|
case "account":
|
|
13462
14241
|
return accountCmd(positional, flags);
|
|
@@ -13511,6 +14290,7 @@ export async function run(command, positional, flags, workspace, layout) {
|
|
|
13511
14290
|
if (positional[0] === "dup-step") return flowDupStepCmd(positional, flags, layout);
|
|
13512
14291
|
if (positional[0] === "show") return flowShowCmd(positional, flags, layout);
|
|
13513
14292
|
if (positional[0] === "run") return invoke(positional[1], flags);
|
|
14293
|
+
if (positional[0] === "inputs") return flowInputsCmd(positional, flags, layout);
|
|
13514
14294
|
if (positional[0] === "rotate-hook") return rotateHookCmd(positional, flags, layout);
|
|
13515
14295
|
if (positional[0] === "hook") return flowHookCmd(positional, flags, layout);
|
|
13516
14296
|
if (positional[0] === "set") return flowSetCmd(positional, flags, layout);
|