@foldrun/core 15.0.0 → 15.1.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/src/runner.ts CHANGED
@@ -3,6 +3,7 @@
3
3
  // fail without failing the flow. A direct agent run is a one-step ad-hoc
4
4
  // flow, so there is a single execution path.
5
5
 
6
+ import { opsLog, opsError } from "./ops-log.ts";
6
7
  import { globMatch } from "./bounded-match.ts";
7
8
  import { latestRevisionId } from "./history.ts";
8
9
  import { recordCallIo, redactionsFor } from "./capture.ts";
@@ -2428,7 +2429,7 @@ async function runStep(
2428
2429
  const why = await platform.checkUntrustedUrl(r.card);
2429
2430
  if (why) {
2430
2431
  cardProblems.set(r.name, why);
2431
- console.warn(`[a2a] remotes: ${r.name} refused for ${tenant}/${path.basename(workspaceRootOf(agentDir))} (${step.agent}): ${why}`);
2432
+ opsLog("warn", "a2a.remote_refused", { tenant, workspace: path.basename(workspaceRootOf(agentDir)), agent: step.agent, tool: r.name });
2432
2433
  }
2433
2434
  }
2434
2435
  const stepRemotes: RemoteSpec[] = remotes.map((r) => {
@@ -4287,7 +4288,8 @@ export function platformModelCredential(env: NodeJS.ProcessEnv = process.env): s
4287
4288
  // thing an operator needs to know about before the next step fails.
4288
4289
  if (!credentialFileWarned) {
4289
4290
  credentialFileWarned = true;
4290
- console.warn(`[model] FOLDRUN_MODEL_KEY_FILE=${file} could not be read; falling back to the environment`);
4291
+ // FOLDRUN_MODEL_KEY_FILE could not be read: the environment's key is used.
4292
+ opsLog("warn", "model.key_file_unreadable", { outcome: "environment" });
4291
4293
  }
4292
4294
  }
4293
4295
  }
@@ -6409,7 +6411,7 @@ export function reconcileRuns(tenant: string, now = Date.now(), live?: ReadonlyS
6409
6411
  const after = readRun(tenant, workspace.name, run.id);
6410
6412
  if (onEnd && after && (after.status === "completed" || after.status === "failed")) return onEnd(tenant, workspace.name, run.id);
6411
6413
  })
6412
- .catch((err) => console.error(`[foldrun] reconcile: ${tenant}/${workspace.name}/${run.id} after resume:`, err));
6414
+ .catch((err) => opsError("reconcile.after_resume_failed", err, { tenant, workspace: workspace.name, runId: run.id }));
6413
6415
  closed.push({
6414
6416
  runId: run.id,
6415
6417
  tenant,
@@ -6457,7 +6459,7 @@ export function reconcileRuns(tenant: string, now = Date.now(), live?: ReadonlyS
6457
6459
  if (onEnd) {
6458
6460
  void Promise.resolve()
6459
6461
  .then(() => onEnd(tenant, workspace.name, run.id))
6460
- .catch((err) => console.error(`[foldrun] reconcile: ${tenant}/${workspace.name}/${run.id} after close:`, err));
6462
+ .catch((err) => opsError("reconcile.after_close_failed", err, { tenant, workspace: workspace.name, runId: run.id }));
6461
6463
  }
6462
6464
  }
6463
6465
  }
package/src/secrets.ts CHANGED
@@ -19,6 +19,7 @@
19
19
  // Secrets are injected as environment variables into the agent's tools at run
20
20
  // time and are never returned by the API.
21
21
 
22
+ import { opsLog, withOpsReason } from "./ops-log.ts";
22
23
  import fs from "node:fs";
23
24
  import path from "node:path";
24
25
  import { dataRoot } from "./paths.ts";
@@ -71,7 +72,7 @@ export function installKeyMaterial(): string {
71
72
  // so; without this, asking for it would quietly mint a NEW random key on
72
73
  // the shared data volume — a second root key nobody chose.
73
74
  if (process.env.FOLDRUN_INSTALL_KEY_ABSENT === "1") {
74
- throw new Error("this process runs without the install key (FOLDRUN_INSTALL_KEY_ABSENT=1) — whatever asked for it belongs in the worker");
75
+ throw withOpsReason(new Error("this process runs without the install key (FOLDRUN_INSTALL_KEY_ABSENT=1) — whatever asked for it belongs in the worker"), "install_key_absent");
75
76
  }
76
77
  fs.mkdirSync(dataRoot(), { recursive: true });
77
78
  if (!fs.existsSync(keyFile())) {
@@ -549,10 +550,8 @@ function decrypt(tenant: string, rec: StoredSecret | undefined, aad?: Buffer): s
549
550
  // "no such secret" — a process that forgot to load the account keys
550
551
  // would look exactly like an account that never set one, which is the
551
552
  // most expensive kind of wrong answer to debug.
552
- console.error(
553
- `[secrets] ${tenant} has account-keyed secrets but no key is loaded — ` +
554
- `call loadTenantKeys() before reading, or the value will read as absent`,
555
- );
553
+ // loadTenantKeys() was not called before reading: the value reads as absent.
554
+ opsLog("error", "secrets.account_key_not_loaded", { tenant });
556
555
  return null;
557
556
  }
558
557
  key = own;
package/src/step-exec.ts CHANGED
@@ -8,6 +8,7 @@
8
8
  // results. That is what lets the same function run somewhere the vault, the
9
9
  // library and the account do not exist.
10
10
 
11
+ import { opsError } from "./ops-log.ts";
11
12
  import { judgeVerdict, JUDGE_VERDICT_INSTRUCTION } from "./judge-verdict.ts";
12
13
  import { runHook, runToolCallHooks, matchesTool, hookLine, resolveHooks, type HookDef, type HookRecord } from "./hooks.ts";
13
14
  import fs from "node:fs";
@@ -1381,16 +1382,21 @@ function runVerify(
1381
1382
  * A model process's failure as a person should read it: one short line. The
1382
1383
  * SDK's error for a CLI that died carries the CLI's stderr, which can be KBs
1383
1384
  * of its minified bundle — internal prompt text included (FOL-107) — so that
1384
- * part goes to the server log, never to an eval result or a trace. An error
1385
- * that is already short (an API error the model answered) is kept as it is.
1385
+ * part goes neither to an eval result or a trace, nor to a hosted log
1386
+ * (FOL-121): there the log line is the failure's class and our frames. An
1387
+ * error that is already short (an API error the model answered) is kept as
1388
+ * it is.
1386
1389
  */
1387
1390
  export function modelProcessError(err: unknown, where: string): Error {
1388
1391
  const full = err instanceof Error ? err.message : String(err);
1389
1392
  const at = full.indexOf(" stderr:");
1390
1393
  if (at < 0 && full.length <= 500) return err instanceof Error ? err : new Error(full);
1391
- console.error(`[foldrun] ${where}: ${full}`);
1394
+ // Inside the hosted boundary this is the class, name and our frames only:
1395
+ // the stderr is the CLI's, and can carry the prompt (FOL-107, FOL-121).
1396
+ // On a laptop the full text comes along, for the person it belongs to.
1397
+ opsError("model.process_failed", err, { where: where.replace(/\W+/g, "_").toLowerCase(), errorClass: "model_error" });
1392
1398
  const head = (at >= 0 ? full.slice(0, at) : full.slice(0, 300)).trim().replace(/[.:]$/, "");
1393
- return new Error(`${head} — the model process failed; the details are in the server log`);
1399
+ return new Error(`${head} — the model process failed`);
1394
1400
  }
1395
1401
 
1396
1402
  export function sdkEnv(base: Record<string, string | undefined> | undefined, extra: Record<string, string> = {}): Record<string, string | undefined> {
package/src/storage.ts CHANGED
@@ -48,6 +48,7 @@
48
48
  // FOLDRUN_STORAGE_MAX_MB per object, default 512
49
49
  // FOLDRUN_STORAGE_QUOTA_MB per workspace, default 5120
50
50
 
51
+ import { opsError } from "./ops-log.ts";
51
52
  import fs from "node:fs";
52
53
  import path from "node:path";
53
54
  import crypto from "node:crypto";
@@ -686,7 +687,7 @@ async function announceFiles(tenant: string, workspace: string, paths: string[],
686
687
  const { fireStorageTriggers } = await import("./triggers.ts");
687
688
  await fireStorageTriggers(tenant, workspace, paths, by);
688
689
  } catch (err) {
689
- console.error(`[foldrun] storage trigger ${tenant}/${workspace}:`, err instanceof Error ? err.message : err);
690
+ opsError("trigger.storage_failed", err, { tenant, workspace });
690
691
  }
691
692
  }
692
693
 
package/src/triggers.ts CHANGED
@@ -12,6 +12,7 @@
12
12
  // read that run's fields; it receives what the run concluded, as text, and
13
13
  // an agent reads it — the same rule as every other handoff in the format.
14
14
 
15
+ import { opsLog, opsError } from "./ops-log.ts";
15
16
  import crypto from "node:crypto";
16
17
  import { platform } from "./platform.ts";
17
18
  import { refusalCode } from "./trigger-log.ts";
@@ -93,7 +94,7 @@ export async function fireChainedFlows(tenant: string, workspace: string, finish
93
94
  try {
94
95
  const gate = await platform.admitTrigger(tenant, workspace, flow, { body, tag: "previous_run", fields: chainFields(finished) });
95
96
  if (!gate.admit) {
96
- console.log(`[foldrun] trigger: flow — ${tenant}/${workspace}/${flow.name} not started: ${gate.detail}`);
97
+ opsLog("info", "trigger.flow_not_started", { tenant, workspace, flow: flow.name, reason: gate.reason });
97
98
  continue;
98
99
  }
99
100
  try {
@@ -103,13 +104,13 @@ export async function fireChainedFlows(tenant: string, workspace: string, finish
103
104
  `after:${finished.flow}`,
104
105
  ], null, finished.test ? { test: true } : {});
105
106
  started.push(run.id);
106
- console.log(`[foldrun] trigger: flow — ${tenant}/${workspace}/${flow.name} started after ${finished.flow} ${finished.status}`);
107
+ opsLog("info", "trigger.flow_started", { tenant, workspace, flow: flow.name, runId: run.id, kind: "previous_run", outcome: finished.status });
107
108
  } catch (err) {
108
109
  await platform.rollbackTrigger(tenant, workspace, flow, { reason: err instanceof Error ? err.message : String(err), code: refusalCode(err) });
109
110
  throw err;
110
111
  }
111
112
  } catch (err) {
112
- console.error(`[foldrun] trigger: flow — ${tenant}/${workspace}/${flow.name}:`, err instanceof Error ? err.message : err);
113
+ opsError("trigger.flow_failed", err, { tenant, workspace, flow: flow.name });
113
114
  }
114
115
  }
115
116
  return started;
@@ -158,7 +159,7 @@ export async function fireStorageTriggers(
158
159
  // forty runs — which is exactly what `debounce:` is for.
159
160
  const gate = await platform.admitTrigger(tenant, workspace, flow, { body, tag: "storage_event", fields: { by, paths: hits } });
160
161
  if (!gate.admit) {
161
- console.log(`[foldrun] trigger: storage — ${tenant}/${workspace}/${flow.name} not started: ${gate.detail}`);
162
+ opsLog("info", "trigger.storage_not_started", { tenant, workspace, flow: flow.name, reason: gate.reason });
162
163
  continue;
163
164
  }
164
165
  try {
@@ -171,7 +172,7 @@ export async function fireStorageTriggers(
171
172
  throw err;
172
173
  }
173
174
  } catch (err) {
174
- console.error(`[foldrun] trigger: storage — ${tenant}/${workspace}/${flow.name}:`, err instanceof Error ? err.message : err);
175
+ opsError("trigger.storage_failed", err, { tenant, workspace, flow: flow.name });
175
176
  }
176
177
  }
177
178
  return started;
package/src/webhook.ts CHANGED
@@ -2,6 +2,7 @@
2
2
  // identity under the install's secret key. Stable across restarts, unique
3
3
  // per flow, and rotating FOLDRUN_SECRET_KEY invalidates every hook at once.
4
4
 
5
+ import { opsLog } from "./ops-log.ts";
5
6
  import fs from "node:fs";
6
7
  import path from "node:path";
7
8
  import { workspaceDir } from "./store.ts";
@@ -225,8 +226,8 @@ function noteRefusal(tenant: string, workspace: string, delivery: HookDelivery)
225
226
  seen.since++;
226
227
  return;
227
228
  }
228
- const more = seen?.since ? ` (and ${seen.since} more since the last note)` : "";
229
- console.warn(`[hooks] refused a delivery to ${key}/${delivery.flow}: ${delivery.outcome}${more}`);
229
+ // count: this one and those refused since the last note.
230
+ opsLog("warn", "webhook.delivery_refused", { tenant, workspace, flow: delivery.flow, outcome: delivery.outcome, count: (seen?.since ?? 0) + 1 });
230
231
  refusalNotes.set(key, { at: now, since: 0 });
231
232
  if (refusalNotes.size > 10_000) refusalNotes.clear(); // bounded: a note lost beats memory
232
233
  }