@parcha/agentrun-serve 0.1.0-beta.60 → 0.1.0-beta.61

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.
Files changed (93) hide show
  1. package/CHANGELOG.md +58 -0
  2. package/README.md +42 -14
  3. package/dist/acp-package.d.ts +4 -0
  4. package/dist/api-only.d.ts +19 -1
  5. package/dist/api-only.js +38 -3
  6. package/dist/browser-person.d.ts +1 -1
  7. package/dist/browser-person.js +1 -1
  8. package/dist/calendar/tools.js +1 -1
  9. package/dist/cli.js +42 -10
  10. package/dist/console/assets/{backend-QnwGVBeU.js → backend-C9ffXUR5.js} +1 -1
  11. package/dist/console/assets/index-BnZV3lvW.js +639 -0
  12. package/dist/console/assets/{share-pz61zIn9.js → share-B1o5mJ56.js} +2 -2
  13. package/dist/console/assets/{styles-CcceGcu2.js → styles-D_znYrHR.js} +2 -2
  14. package/dist/console/index.html +2 -2
  15. package/dist/console/share.html +2 -2
  16. package/dist/errors.d.ts +1 -0
  17. package/dist/errors.js +2 -0
  18. package/dist/harness-check.js +2 -1
  19. package/dist/harness-recipe.d.ts +13 -2
  20. package/dist/harness-recipe.js +30 -7
  21. package/dist/harness-sign-in.js +2 -1
  22. package/dist/harness-table.d.ts +5 -3
  23. package/dist/harness-table.js +7 -5
  24. package/dist/key-refusal.js +6 -4
  25. package/dist/learn/secrets.d.ts +2 -1
  26. package/dist/learn/secrets.js +2 -2
  27. package/dist/learned-nodes.d.ts +36 -0
  28. package/dist/learned-nodes.js +23 -0
  29. package/dist/local-model.d.ts +144 -0
  30. package/dist/local-model.js +214 -0
  31. package/dist/mcp-probe.d.ts +7 -0
  32. package/dist/mcp-probe.js +7 -0
  33. package/dist/ollama-provider.d.ts +35 -0
  34. package/dist/ollama-provider.js +108 -2
  35. package/dist/openapi.js +59 -7
  36. package/dist/place.d.ts +7 -6
  37. package/dist/place.js +13 -10
  38. package/dist/print.js +1 -1
  39. package/dist/redact/match.d.ts +17 -4
  40. package/dist/redact/match.js +57 -15
  41. package/dist/run-export.js +4 -2
  42. package/dist/run-usage.js +3 -2
  43. package/dist/runner/adapter-loop.d.ts +8 -1
  44. package/dist/runner/adapter-loop.js +100 -20
  45. package/dist/runner/adapter-run-spec.d.ts +3 -5
  46. package/dist/runner/adapter-run-spec.js +26 -43
  47. package/dist/runner/adapters/pi.d.ts +3 -2
  48. package/dist/runner/adapters/pi.js +3 -1
  49. package/dist/runner/audit.d.ts +1 -1
  50. package/dist/runner/cli-run-spec.js +13 -10
  51. package/dist/runner/compare-end.d.ts +1 -1
  52. package/dist/runner/dispatch.js +2 -2
  53. package/dist/runner/harness-loops.d.ts +9 -0
  54. package/dist/runner/harness-loops.js +47 -4
  55. package/dist/runner/held.d.ts +4 -1
  56. package/dist/runner/live-ticker.js +3 -4
  57. package/dist/runner/mcp-claim.js +3 -2
  58. package/dist/runner/mcp-run.d.ts +19 -4
  59. package/dist/runner/mcp-run.js +29 -2
  60. package/dist/runner/metrics.d.ts +4 -0
  61. package/dist/runner/metrics.js +9 -3
  62. package/dist/runner/monid-run.js +3 -1
  63. package/dist/runner/native-loop.js +1 -1
  64. package/dist/runner/redact.d.ts +3 -0
  65. package/dist/runner/redact.js +7 -0
  66. package/dist/runner/run-child-host.js +1 -1
  67. package/dist/runner/sdk-loop.js +5 -3
  68. package/dist/runner/workflow-calls.d.ts +4 -1
  69. package/dist/runner/workflow-calls.js +35 -18
  70. package/dist/runner/workflow-loop.d.ts +1 -1
  71. package/dist/runner/workflow-loop.js +3 -1
  72. package/dist/runner/workflow-spec.d.ts +4 -0
  73. package/dist/runner/workflow-spec.js +18 -13
  74. package/dist/runs-over-store.d.ts +2 -2
  75. package/dist/runs-over-store.js +1 -1
  76. package/dist/secret-cut.js +7 -4
  77. package/dist/secret-rules.js +97 -83
  78. package/dist/server.d.ts +7 -0
  79. package/dist/server.js +97 -34
  80. package/dist/slack.js +2 -1
  81. package/dist/store/postgres/migrate.js +3 -1
  82. package/dist/store-reads/learning.d.ts +5 -4
  83. package/dist/store-reads/learning.js +7 -4
  84. package/dist/tool-plane.d.ts +23 -1
  85. package/dist/tool-plane.js +70 -2
  86. package/dist/tools.d.ts +12 -2
  87. package/dist/tools.js +42 -7
  88. package/dist/trigger-launch-hook.d.ts +2 -2
  89. package/dist/trigger-launch-hook.js +1 -1
  90. package/dist/triggers.d.ts +7 -4
  91. package/dist/triggers.js +4 -4
  92. package/package.json +12 -12
  93. package/dist/console/assets/index-DZi-muIj.js +0 -629
@@ -24,7 +24,7 @@ import { modelPortFor, SessionFenced } from "@parcha/agentrun-kernel";
24
24
  import { beforeRequestOf } from "@parcha/agentrun-kernel/kernel/cap";
25
25
  import { archivePlatform } from "./harness-archive.js";
26
26
  import { egressProxy, egressVars } from "./harness-egress.js";
27
- import { AGENT_VARS, installHolds, loadRecipe, recipeInstall, RecipeRefused, writeChecked } from "./harness-recipe.js";
27
+ import { AGENT_VARS, installHolds, loadRecipe, recipeInstall, RecipeRefused, recipeSaid, writeChecked } from "./harness-recipe.js";
28
28
  import { recipeEntryOf } from "./harness-recipe-entry.js";
29
29
  import { providerModels } from "./model.js";
30
30
  import { capModelOf } from "./runner/cli-run-spec.js";
@@ -154,6 +154,7 @@ async function checkRun(options, held) {
154
154
  held.push(...recipe.keys.map((name) => options.env[name]).filter((value) => typeof value === "string"));
155
155
  const head = { recipe: { id: recipe.id, label: recipe.label, file: loaded.file, sha256: loaded.sha256 }, checkedAt };
156
156
  const refuse = (code, message) => ({ ok: false, ...head, refused: { code, message: `${code}: ${message}` }, failures: [`${code}: ${message}`] });
157
+ say(recipeSaid(recipe.label, loaded.file, loaded.bundled));
157
158
  say(`${recipe.label}: the recipe holds the five rules (${loaded.file})`);
158
159
  // What the agent runs on: the recipe's keys, read from this shell, alone (a proxy-billed one's: none, the model proxy's).
159
160
  // A check never runs on its owner's own sign-in, which a schedule, a check and a shared server never take
@@ -136,15 +136,26 @@ export declare function recipeProblems(parsed: unknown): {
136
136
  }[];
137
137
  /** The recipe in `text`, or RecipeRefused with every problem. */
138
138
  export declare function parseRecipe(text: string): Recipe;
139
- /** The recipe file at `path`, read and loaded. */
139
+ /** The file `given` names, from `cwd`: the recipe the ACP package ships (bundledRecipePath: Google Antigravity's) when
140
+ * `given` is its name, else the file at that path. A name a file in `cwd` also holds is refused, saying both, so the
141
+ * owner's own file is never passed over silently (`./<name>` names the file). A bundled name is never a built-in
142
+ * harness's id: the recipe's own id is that name, and a built-in id is refused as a recipe's (parseRecipe). */
143
+ export declare function resolveRecipe(given: string, cwd?: string): {
144
+ file: string;
145
+ bundled: boolean;
146
+ };
147
+ /** Which recipe resolved, as a command says it before anything else: the one AgentRun ships, or the owner's file. */
148
+ export declare const recipeSaid: (label: string, file: string, bundled: boolean) => string;
149
+ /** The recipe at `path` (a file, or the name of a recipe AgentRun ships: resolveRecipe), read and loaded. */
140
150
  export declare function loadRecipe(path: string): {
141
151
  recipe: Recipe;
142
152
  file: string;
143
153
  sha256: string;
154
+ bundled: boolean;
144
155
  };
145
156
  /** The recipe's release for `platform` (this host's by default), or undefined where it lists none. */
146
157
  export declare const releaseFor: (recipe: Recipe, platform?: string | undefined) => RecipeArchive | undefined;
147
- /** The owner's command that installs the recipe at `file` into `data`. */
158
+ /** The owner's command that installs the recipe at `file` into `data` (one AgentRun ships by its name, as goose's is). */
148
159
  export declare const recipeInstallLine: (file: string, data: string, env?: NodeJS.ProcessEnv) => string;
149
160
  /** Where the recipe's binary is once installed: `<data>/harnesses/<id>/<cmd>`. */
150
161
  export declare const recipeBinaryOf: (data: string, recipe: Recipe, release: RecipeArchive) => string;
@@ -400,9 +400,32 @@ export function parseRecipe(text) {
400
400
  ...(r.signIn ? { signIn: Object.freeze({ args: Object.freeze([...r.signIn.args]), homeArg: r.signIn.homeArg, ...(r.signIn.terms ? { terms: r.signIn.terms } : {}) }) } : {}),
401
401
  });
402
402
  }
403
- /** The recipe file at `path`, read and loaded. */
403
+ /** The file `given` names, from `cwd`: the recipe the ACP package ships (bundledRecipePath: Google Antigravity's) when
404
+ * `given` is its name, else the file at that path. A name a file in `cwd` also holds is refused, saying both, so the
405
+ * owner's own file is never passed over silently (`./<name>` names the file). A bundled name is never a built-in
406
+ * harness's id: the recipe's own id is that name, and a built-in id is refused as a recipe's (parseRecipe). */
407
+ export function resolveRecipe(given, cwd = process.cwd()) {
408
+ const local = resolve(cwd, given);
409
+ const shipped = acpPackage()?.bundledRecipePath?.(given);
410
+ // The shipped file named by its path is the shipped recipe too.
411
+ if (!shipped)
412
+ return { file: local, bundled: bundledName(local) !== undefined };
413
+ if (existsSync(local))
414
+ throw new RecipeRefused(RECIPE_CODES.invalid, [{ code: RECIPE_CODES.invalid, words: `${given} names both the recipe AgentRun ships (${shipped}) and the file ${local} in this directory: write ./${given} for your file, or name the shipped one from another directory` }]);
415
+ return { file: shipped, bundled: true };
416
+ }
417
+ /** The name of the recipe at `file` when the ACP package ships it, else undefined. */
418
+ const bundledName = (file) => {
419
+ const acp = acpPackage();
420
+ return acp?.BUNDLED_RECIPES?.find((each) => acp.bundledRecipePath?.(each) === resolve(file));
421
+ };
422
+ /** The word a printed command names the recipe at `file` by: its bundled name, else the file. */
423
+ const recipeWord = (file) => bundledName(file) ?? shellWord(file);
424
+ /** Which recipe resolved, as a command says it before anything else: the one AgentRun ships, or the owner's file. */
425
+ export const recipeSaid = (label, file, bundled) => `${label}: ${bundled ? `the recipe AgentRun ships (${file})` : `the recipe file ${file}`}`;
426
+ /** The recipe at `path` (a file, or the name of a recipe AgentRun ships: resolveRecipe), read and loaded. */
404
427
  export function loadRecipe(path) {
405
- const file = resolve(path);
428
+ const { file, bundled } = resolveRecipe(path);
406
429
  let text;
407
430
  try {
408
431
  text = readFileSync(file, "utf8");
@@ -410,12 +433,12 @@ export function loadRecipe(path) {
410
433
  catch (error) {
411
434
  throw new RecipeRefused(RECIPE_CODES.invalid, [{ code: RECIPE_CODES.invalid, words: `the recipe file ${file} cannot be read (${error.code ?? error.message})` }]);
412
435
  }
413
- return { recipe: parseRecipe(text), file, sha256: createHash("sha256").update(text).digest("hex") };
436
+ return { recipe: parseRecipe(text), file, sha256: createHash("sha256").update(text).digest("hex"), bundled };
414
437
  }
415
438
  /** The recipe's release for `platform` (this host's by default), or undefined where it lists none. */
416
439
  export const releaseFor = (recipe, platform = archivePlatform()) => (platform ? recipe.release.archives[platform] : undefined);
417
- /** The owner's command that installs the recipe at `file` into `data`. */
418
- export const recipeInstallLine = (file, data, env = process.env) => `agentrun harness install --recipe ${shellWord(file)}${resolve(data) === commandData(env) ? "" : ` --data ${shellWord(data)}`}`;
440
+ /** The owner's command that installs the recipe at `file` into `data` (one AgentRun ships by its name, as goose's is). */
441
+ export const recipeInstallLine = (file, data, env = process.env) => `agentrun harness install ${bundledName(file) ?? `--recipe ${shellWord(file)}`}${resolve(data) === commandData(env) ? "" : ` --data ${shellWord(data)}`}`;
419
442
  /** Where the recipe's binary is once installed: `<data>/harnesses/<id>/<cmd>`. */
420
443
  export const recipeBinaryOf = (data, recipe, release) => join(installDirOf(data, recipe.id), insideHome(release.cmd));
421
444
  /** A first-seen digest record in a file of its own (one line, the sha256), written once and never over another's. */
@@ -482,7 +505,7 @@ export const signInHomeOf = (data, id) => join(harnessesOf(data), `${id}.sign-in
482
505
  * `<data>/harnesses/<id>.signed-in`, holding when and on which version. It holds nothing of the sign-in. */
483
506
  export const signedInNoteOf = (data, id) => join(harnessesOf(data), `${id}.signed-in`);
484
507
  /** The owner's command that signs the recipe at `file` in, on `data`. */
485
- export const recipeSignInLine = (file, data, env = process.env) => `agentrun harness sign-in --recipe ${shellWord(file)}${resolve(data) === commandData(env) ? "" : ` --data ${shellWord(data)}`}`;
508
+ export const recipeSignInLine = (file, data, env = process.env) => `agentrun harness sign-in --recipe ${recipeWord(file)}${resolve(data) === commandData(env) ? "" : ` --data ${shellWord(data)}`}`;
486
509
  /** Whether the agent's own sign-in ended well on `data` (signedInNoteOf): nothing in its folder is read to say so.
487
510
  * Whether the sign-in still holds is the agent's to say when it runs (an ACP -32000, Authentication required). */
488
511
  export const signedIn = (data, recipe) => recipe.signIn !== undefined && existsSync(signedInNoteOf(data, recipe.id));
@@ -521,4 +544,4 @@ export async function installRecipe(recipe, file, data, options = {}, env = proc
521
544
  return { version: recipe.release.version, pinnedBy, ...done };
522
545
  }
523
546
  /** The owner's command that checks the recipe at `file`, installed into `data`. */
524
- export const recipeCheckLine = (file, data, env = process.env) => `agentrun harness-check --recipe ${shellWord(file)}${resolve(data) === commandData(env) ? "" : ` --data ${shellWord(data)}`}`;
547
+ export const recipeCheckLine = (file, data, env = process.env) => `agentrun harness-check --recipe ${recipeWord(file)}${resolve(data) === commandData(env) ? "" : ` --data ${shellWord(data)}`}`;
@@ -11,7 +11,7 @@ import { chmodSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:f
11
11
  import { tmpdir } from "node:os";
12
12
  import { join } from "node:path";
13
13
  import { archivePlatform } from "./harness-archive.js";
14
- import { AGENT_VARS, installHolds, loadRecipe, recipeInstall, RecipeRefused, signedInNoteOf, signInHomeOf } from "./harness-recipe.js";
14
+ import { AGENT_VARS, installHolds, loadRecipe, recipeInstall, RecipeRefused, recipeSaid, signedInNoteOf, signInHomeOf } from "./harness-recipe.js";
15
15
  /** A recipe with no signIn: it runs on its keys alone, and has nothing to sign in. */
16
16
  export const HARNESS_NO_SIGN_IN = "HARNESS_NO_SIGN_IN";
17
17
  /** The agent's own sign-in did not end well: its exit status, a signal, or the time ran out. */
@@ -35,6 +35,7 @@ export async function signInHarness(options) {
35
35
  return { ok: false, code: error.code, message: error.message };
36
36
  }
37
37
  const { recipe, file } = loaded;
38
+ say(recipeSaid(recipe.label, file, loaded.bundled));
38
39
  if (!recipe.signIn)
39
40
  return refuse(HARNESS_NO_SIGN_IN, `${recipe.label}'s recipe names no signIn: it runs on its keys (${recipe.keys.join(", ") || "none"}), and has nothing to sign in`);
40
41
  // The installed binary and every file beside it, the pinned ones, as a check finds them (recipeInstall, installHolds):
@@ -220,10 +220,12 @@ export declare const HARNESS_KEY_OWNED = "HARNESS_KEY_OWNED";
220
220
  export declare const HARNESS_RECIPES_ENV = "AGENTRUN_HARNESS_RECIPES";
221
221
  /** The owner's setting that names harness recipes when no option does: recipe files, comma-separated. */
222
222
  export declare const HARNESS_RECIPES_SETTING = "AGENTRUN_SERVE_HARNESS_RECIPES";
223
- /** The recipe files `given` names (a server's or a runner's `--harness-recipe`, else HARNESS_RECIPES_SETTING). */
223
+ /** The recipe files `given` names (a server's or a runner's `--harness-recipe`, else HARNESS_RECIPES_SETTING): each a
224
+ * file, or the name of a recipe AgentRun ships (harness-recipe.ts resolveRecipe). */
224
225
  export declare const harnessRecipesOf: (given: readonly string[] | undefined, env: NodeJS.ProcessEnv) => string[];
225
- /** HARNESS_RECIPES_ENV for the recipe files `files` names, installed into `data`: none for none. `signIn` only where the
226
- * server's start proved --harness-sign-in. */
226
+ /** HARNESS_RECIPES_ENV for the recipes `files` names (each resolved by resolveRecipe: a shipped one's name to its file, a
227
+ * name a file here also holds refused), installed into `data`: none for none. `signIn` only where the server's start
228
+ * proved --harness-sign-in. */
227
229
  export declare const harnessRecipesEnv: (files: readonly string[], data: string, { signIn }?: {
228
230
  signIn?: boolean;
229
231
  }) => NodeJS.ProcessEnv;
@@ -22,7 +22,7 @@ import { chooseModel, hostModel } from "./model.js";
22
22
  import { HarnessUnavailable, modelOn, openRouterOnly, priceModelFor, providerFor } from "./provider.js";
23
23
  import { modelWire, routedId, wireOf, WIRES } from "./wires.js";
24
24
  import { PLAN_PROVIDER, signedIn } from "./chatgpt-plan.js";
25
- import { loadRecipe } from "./harness-recipe.js";
25
+ import { loadRecipe, resolveRecipe } from "./harness-recipe.js";
26
26
  import { recipeServerEntry } from "./harness-recipe-entry.js";
27
27
  /** A module of entries a test merges over the built-in ones (HarnessTableModule), by absolute path. */
28
28
  export const HARNESS_TABLE_ENV = "AGENTRUN_HARNESS_TABLE";
@@ -473,11 +473,13 @@ function recipesOf(env) {
473
473
  }
474
474
  /** The owner's setting that names harness recipes when no option does: recipe files, comma-separated. */
475
475
  export const HARNESS_RECIPES_SETTING = "AGENTRUN_SERVE_HARNESS_RECIPES";
476
- /** The recipe files `given` names (a server's or a runner's `--harness-recipe`, else HARNESS_RECIPES_SETTING). */
476
+ /** The recipe files `given` names (a server's or a runner's `--harness-recipe`, else HARNESS_RECIPES_SETTING): each a
477
+ * file, or the name of a recipe AgentRun ships (harness-recipe.ts resolveRecipe). */
477
478
  export const harnessRecipesOf = (given, env) => given?.length ? [...given] : (env[HARNESS_RECIPES_SETTING] ?? "").split(",").map((name) => name.trim()).filter(Boolean);
478
- /** HARNESS_RECIPES_ENV for the recipe files `files` names, installed into `data`: none for none. `signIn` only where the
479
- * server's start proved --harness-sign-in. */
480
- export const harnessRecipesEnv = (files, data, { signIn = false } = {}) => (files.length ? { [HARNESS_RECIPES_ENV]: JSON.stringify({ data: resolve(data), files: files.map((file) => resolve(file)), ...(signIn ? { signIn: true } : {}) }) } : {});
479
+ /** HARNESS_RECIPES_ENV for the recipes `files` names (each resolved by resolveRecipe: a shipped one's name to its file, a
480
+ * name a file here also holds refused), installed into `data`: none for none. `signIn` only where the server's start
481
+ * proved --harness-sign-in. */
482
+ export const harnessRecipesEnv = (files, data, { signIn = false } = {}) => (files.length ? { [HARNESS_RECIPES_ENV]: JSON.stringify({ data: resolve(data), files: files.map((file) => resolveRecipe(file).file), ...(signIn ? { signIn: true } : {}) }) } : {});
481
483
  /** The table `env` runs on: the built-in entries; then, only under a test runner (node --test's NODE_TEST_CONTEXT, which a
482
484
  * server's and a run's processes there carry), a test's module's (HARNESS_TABLE_ENV) merged over them by id; then the
483
485
  * harnesses each of the owner's harness modules adds (HARNESS_MODULES_ENV), under a test runner or not. A module adds
@@ -249,7 +249,8 @@ function inPieces(text, secrets, enough = Number.POSITIVE_INFINITY, show = (piec
249
249
  * single-quoted dict through them does) and HTML's character references (named and numeric), so a "+", an encoded
250
250
  * byte, an escape and a reference that decode to whitespace count no more than whitespace does, and any other escape
251
251
  * counts as what the view keeps of the character it decodes to. A character that renders as nothing (a zero-width
252
- * space, a soft hyphen) or a combining mark counts as nothing too: the views drop it. So does a quote, an apostrophe
252
+ * space, a soft hyphen, a control character that is no whitespace: a NUL, an escape, a delete; U+FFFF; as it stands or as
253
+ * "\u0001", "\x01", "%01" or "&#1;" decodes) or a combining mark counts as nothing too: the views drop it (kept). So does a quote, an apostrophe
253
254
  * or JSON's punctuation ("{", "}", "[", "]", ",", ":"), which the join views drop between a text's strings, and, with
254
255
  * `fold` (a held value folds: learn/secrets.ts foldsHeld), a separator ("-", "_", ":", "."), which the fold view
255
256
  * drops. Padding of any of them never hides the rest of a value split before it. Undefined, so the caller withholds
@@ -262,7 +263,7 @@ function peek(text, from, count, fold) {
262
263
  /** The end of the run text[start, to) the pass reads for the head of a value whose rest comes after the run: as few of
263
264
  * its last characters as hold `count` characters the matcher sees (at most a piece's worth), counted as peek counts
264
265
  * them (with `fold` as peek's), so padding the views read as nothing (whitespace, a zero-width space, a soft hyphen, a
265
- * quote or JSON's punctuation, a separator a folded value drops, an escape, a character reference or encoded bytes
266
+ * control character, U+FFFF, a quote or JSON's punctuation, a separator a folded value drops, an escape, a character reference or encoded bytes
266
267
  * that decode to any of them) between that head and the run's end never pushes the head out of it. Read forward from
267
268
  * a start moved back from `to`, twice as far each time, so it reads at most two pieces in all. Undefined, so the
268
269
  * caller withholds the text, when that takes more than a piece of text. */
@@ -339,8 +340,9 @@ const HEX_PAIR = /^[0-9A-Fa-f]{2}$/;
339
340
  const JOIN_DROPS = new Set(['"', "'", "{", "}", "[", "]", ",", ":"]);
340
341
  /** What the fold view drops: the separators of a hex identifier. */
341
342
  const FOLD_DROPS = new Set(["-", "_", ":", "."]);
342
- /** How many characters the views keep of `chars` at the least (peek): squeezed, less each the join view drops, and,
343
- * with `fold`, each the fold view drops. */
343
+ /** How many characters the views keep of `chars` at the least (peek): squeezed (a control character that is no
344
+ * whitespace, and U+FFFF, as the views drop them, count 0), less each the join view drops, and, with `fold`, each the
345
+ * fold view drops. */
344
346
  function kept(chars, fold) {
345
347
  let count = 0;
346
348
  for (const char of squeeze(chars))
@@ -64,6 +64,7 @@ export declare function excerptShown(text: string, shown: {
64
64
  /** A matcher for `values` in a text: plain, split by whitespace, as JSON writes it, percent or form encoded, base64 or
65
65
  * hex, and each hex identifier in a value folded: in any case, its separators dropped or moved (foldedOf). Values
66
66
  * shorter than MIN_SECRET are left out. `fold: false`, the matcher without the folded needles. */
67
- export declare function valueMatcher(values: readonly string[], { fold }?: {
67
+ export declare function valueMatcher(values: readonly string[], { fold, separated }?: {
68
68
  fold?: boolean;
69
+ separated?: boolean;
69
70
  }): (text: string) => boolean;
@@ -305,7 +305,7 @@ function heldFields(value) {
305
305
  /** A matcher for `values` in a text: plain, split by whitespace, as JSON writes it, percent or form encoded, base64 or
306
306
  * hex, and each hex identifier in a value folded: in any case, its separators dropped or moved (foldedOf). Values
307
307
  * shorter than MIN_SECRET are left out. `fold: false`, the matcher without the folded needles. */
308
- export function valueMatcher(values, { fold = true } = {}) {
308
+ export function valueMatcher(values, { fold = true, separated = false } = {}) {
309
309
  const needles = derivedOf(values);
310
- return (text) => holds(text, needles, { fold });
310
+ return (text) => holds(text, needles, { fold, separated });
311
311
  }
@@ -12,6 +12,42 @@ export declare const LEARNED_NODES = "agentrun.learned_nodes";
12
12
  * however many nodes failed on the way and were recovered, a map's collected item say), or `failed` (it threw, or was
13
13
  * refused before any node ran). */
14
14
  export type LearnedEnded = "complete" | "escalated" | "failed";
15
+ /** The record of a learned_workflow call that ended `failed` with no node kept, where the tool kept none: an agent's call
16
+ * a crash cut mid-call, refused when it was issued again (adapter-loop.ts learnedEntry, learnedCallRan). An earlier
17
+ * attempt may have run nodes and spent, so it is no refusal: its $ is what its call id booked. */
18
+ export declare const failedRecord: (call: string, workflow: string, digest: string, caller: "platform" | "agent") => {
19
+ call: string;
20
+ workflow: string;
21
+ digest: string;
22
+ caller: "platform" | "agent";
23
+ nodes: never[];
24
+ ended: LearnedEnded;
25
+ };
26
+ /** The record of a learned_workflow call refused before the tool saw it (`refused`: it ran nothing), which the loop keeps
27
+ * where the tool never ran: the platform's call its gate refused (runner/adapter-loop.ts serveFirst), and an agent's its
28
+ * gate refused with no attempt of it let go since its last refusal (adapter-loop.ts learnedEntry). Either reads
29
+ * `failed` once anything was booked under its call id (runner/workflow-calls.ts workflowCallsOf). */
30
+ export declare const refusedRecord: (call: string, workflow: string, digest: string, caller: "platform" | "agent") => {
31
+ refused: true;
32
+ call: string;
33
+ workflow: string;
34
+ digest: string;
35
+ caller: "platform" | "agent";
36
+ nodes: never[];
37
+ ended: LearnedEnded;
38
+ };
39
+ /** The mark an agent's learned_workflow call on a CLI gets in the run's journal when its gate lets it go, before it runs:
40
+ * `{ call }`, its call's id (adapter-loop.ts sessionGate). An attempt a crash cuts before its record is kept leaves
41
+ * this, so a later refusal of the call issued again knows an attempt after any earlier refusal may have run. */
42
+ export declare const LEARNED_ALLOWED = "agentrun.learned_allowed";
43
+ /** Whether an attempt of learned_workflow call `call` may have run, from its root's `entries`: the newest of its allow
44
+ * marks (LEARNED_ALLOWED) and its records (LEARNED_NODES) is a mark, or a record not `refused`. Neither: `replayed`, the
45
+ * bridge's word that the call is issued again (a run begun before the marks existed has none), else no attempt was let
46
+ * go, so none ran. */
47
+ export declare function learnedCallRan(entries: readonly {
48
+ readonly kind: string;
49
+ readonly data?: unknown;
50
+ }[], call: string, replayed?: boolean): boolean;
15
51
  /** The most nodes a call keeps: a map over a long list runs its body once per item. */
16
52
  export declare const LEARNED_NODES_MAX = 64;
17
53
  /** One node of a learned workflow's run, as the DSL ended it (its `node.end` event): its label, its kind, how it ended
@@ -7,6 +7,29 @@
7
7
  * `refused: true` on one refused before any node ran (it ran nothing). A run's `workflow_calls` read these
8
8
  * (runner/workflow-calls.ts). */
9
9
  export const LEARNED_NODES = "agentrun.learned_nodes";
10
+ /** The record of a learned_workflow call that ended `failed` with no node kept, where the tool kept none: an agent's call
11
+ * a crash cut mid-call, refused when it was issued again (adapter-loop.ts learnedEntry, learnedCallRan). An earlier
12
+ * attempt may have run nodes and spent, so it is no refusal: its $ is what its call id booked. */
13
+ export const failedRecord = (call, workflow, digest, caller) => ({ call, workflow, digest, caller, nodes: [], ended: "failed" });
14
+ /** The record of a learned_workflow call refused before the tool saw it (`refused`: it ran nothing), which the loop keeps
15
+ * where the tool never ran: the platform's call its gate refused (runner/adapter-loop.ts serveFirst), and an agent's its
16
+ * gate refused with no attempt of it let go since its last refusal (adapter-loop.ts learnedEntry). Either reads
17
+ * `failed` once anything was booked under its call id (runner/workflow-calls.ts workflowCallsOf). */
18
+ export const refusedRecord = (call, workflow, digest, caller) => ({ ...failedRecord(call, workflow, digest, caller), refused: true });
19
+ /** The mark an agent's learned_workflow call on a CLI gets in the run's journal when its gate lets it go, before it runs:
20
+ * `{ call }`, its call's id (adapter-loop.ts sessionGate). An attempt a crash cuts before its record is kept leaves
21
+ * this, so a later refusal of the call issued again knows an attempt after any earlier refusal may have run. */
22
+ export const LEARNED_ALLOWED = "agentrun.learned_allowed";
23
+ /** Whether an attempt of learned_workflow call `call` may have run, from its root's `entries`: the newest of its allow
24
+ * marks (LEARNED_ALLOWED) and its records (LEARNED_NODES) is a mark, or a record not `refused`. Neither: `replayed`, the
25
+ * bridge's word that the call is issued again (a run begun before the marks existed has none), else no attempt was let
26
+ * go, so none ran. */
27
+ export function learnedCallRan(entries, call, replayed = false) {
28
+ const newest = entries.findLast((entry) => (entry.kind === LEARNED_ALLOWED || entry.kind === LEARNED_NODES) && entry.data?.call === call);
29
+ if (newest === undefined)
30
+ return replayed;
31
+ return newest.kind === LEARNED_ALLOWED || newest.data.refused !== true;
32
+ }
10
33
  /** The most nodes a call keeps: a map over a long list runs its body once per item. */
11
34
  export const LEARNED_NODES_MAX = 64;
12
35
  /** The LEARNED_NODES entry that counts for each learned_workflow call in `entries`, by the call's id, as its index in
@@ -0,0 +1,144 @@
1
+ import { type OllamaPullLine } from "./ollama-provider.js";
2
+ /** The GPU where it is cheap to read: Apple silicon's unified memory (darwin on arm64), an NVIDIA card as nvidia-smi names
3
+ * it, else unknown. */
4
+ export type Gpu = {
5
+ readonly kind: "apple";
6
+ readonly unified: true;
7
+ } | {
8
+ readonly kind: "nvidia";
9
+ readonly name: string;
10
+ readonly memory_bytes: number;
11
+ } | {
12
+ readonly kind: "unknown";
13
+ };
14
+ /** What this machine is. */
15
+ export type Machine = {
16
+ readonly platform: string;
17
+ readonly arch: string;
18
+ readonly ram_bytes: number;
19
+ readonly gpu: Gpu;
20
+ };
21
+ /** The Ollama here: whether this server asks one at all (never under the faux model or a model gateway, model.ts
22
+ * asksOllama), whether it answered, and the version it says. */
23
+ export type OllamaFacts = {
24
+ readonly asked: false;
25
+ readonly reachable: false;
26
+ readonly version: null;
27
+ } | {
28
+ readonly asked: true;
29
+ readonly reachable: false;
30
+ readonly version: null;
31
+ } | {
32
+ readonly asked: true;
33
+ readonly reachable: true;
34
+ readonly version: string;
35
+ };
36
+ /** Everything the recommendation reads: the machine, its Ollama, and the tags that Ollama has pulled. */
37
+ export type LocalFacts = {
38
+ readonly machine: Machine;
39
+ readonly ollama: OllamaFacts;
40
+ readonly pulled: readonly string[];
41
+ };
42
+ /** The model recommended here, and why in words; `tag` null where none fits, and the words say what to do instead. */
43
+ export type Recommendation = {
44
+ readonly tag: string;
45
+ readonly why: string;
46
+ readonly pulled: boolean;
47
+ } | {
48
+ readonly tag: null;
49
+ readonly why: string;
50
+ readonly pulled: false;
51
+ };
52
+ /** The non-Apple pick, and Apple's where Inkling does not run: one line. A measurement (qwen3:8b against qwen3:30b-a3b,
53
+ * through this server's own runs) sets it. */
54
+ export declare const QWEN3_DEFAULT = "qwen3:8b";
55
+ /** Apple silicon's pick, where its Ollama runs it (MLX, on Apple silicon alone). */
56
+ export declare const INKLING = "inkling-2-mini";
57
+ /** The first Ollama that runs INKLING. */
58
+ export declare const INKLING_OLLAMA = "0.40.17";
59
+ /** Where Ollama is installed from. */
60
+ export declare const OLLAMA_DOWNLOAD = "https://ollama.com/download";
61
+ /** The least memory (total RAM; Apple silicon's unified memory) each tag is offered on, in GiB: its weights at Ollama's
62
+ * default quantization, the KV cache of the context this server asks (ollama-provider.ts contextOf), and room for the
63
+ * system. A machine sold as 16 GB reads about 15.5 GiB, so each floor sits under the size it is meant for. */
64
+ export declare const RAM_FLOOR_GIB: Readonly<Record<string, number>>;
65
+ /** Every tag the recommendation can name, and so the only tags a pull here takes. */
66
+ export declare const LOCAL_MODEL_TAGS: readonly string[];
67
+ /** A tag as Ollama lists it: with no `:`, `:latest`. */
68
+ export declare const fullTag: (tag: string) => string;
69
+ /** `version` at or past `floor`, both dotted numbers (a suffix such as `-rc1` ignored); an unreadable version is not. */
70
+ export declare function versionAtLeast(version: string, floor: string): boolean;
71
+ /**
72
+ * The model this server recommends for `facts`, and why. No Ollama: none, and where to install it. Apple silicon with an
73
+ * Ollama at INKLING_OLLAMA or later and the memory for it: INKLING. Everyone else: QWEN3_DEFAULT, or the next smaller qwen3
74
+ * that fits in memory, or none, saying what each needs; Apple silicon on an older Ollama is told to update for INKLING. A
75
+ * tag already pulled says so: no pull needed.
76
+ */
77
+ export declare function recommendLocalModel(facts: LocalFacts): Recommendation;
78
+ /** How long nvidia-smi is waited for. */
79
+ export declare const NVIDIA_SMI_TIMEOUT_MS = 2000;
80
+ /** nvidia-smi's first line, `<name>, <MiB>`, as a GPU; unknown for anything else. */
81
+ export declare function nvidiaOf(out: string | undefined): Gpu;
82
+ /** This machine, read once: what a server serves for its life. A test hands its own (ServeOptions.machine). */
83
+ export declare function readMachine(): Promise<Machine>;
84
+ /** The pull here, as the read surface shows it. */
85
+ export type PullView = {
86
+ tag: string;
87
+ state: "pulling" | "done" | "failed";
88
+ status: string;
89
+ completed_bytes: number;
90
+ total_bytes: number;
91
+ error?: string;
92
+ };
93
+ /** One pull at a time, through `pull`; `finished` once it succeeds (the listing dropped and read again), before it reads
94
+ * done. A log line at its start, its end and its failure: the tag, the bytes and the milliseconds, nothing else. */
95
+ export declare function localPulls({ pull, finished, log, signal }: {
96
+ pull: (tag: string, onLine: (line: OllamaPullLine) => void, signal: AbortSignal) => Promise<void>;
97
+ finished: (tag: string) => Promise<void>;
98
+ log?: (line: string) => void;
99
+ signal: AbortSignal;
100
+ }): {
101
+ view: () => PullView | null;
102
+ pulling: () => boolean;
103
+ /** Starts pulling `tag` (checked by the caller), behind the answer. */
104
+ start(tag: string): PullView;
105
+ };
106
+ export type LocalPulls = ReturnType<typeof localPulls>;
107
+ /** Whether the Ollama `env` names is on another machine: OLLAMA_HOST names an address that is not this machine's own
108
+ * (a loopback name). This server reads only its own memory and GPU, so it recommends and pulls nothing for that one. An
109
+ * address the base rule refuses is no Ollama asked at all, and not said to be elsewhere. */
110
+ export declare function ollamaElsewhere(env: NodeJS.ProcessEnv): boolean;
111
+ /** The words for an Ollama on another machine (ollamaElsewhere), which never name its address. */
112
+ export declare const OLLAMA_ELSEWHERE = "The Ollama OLLAMA_HOST names is on another machine, and this server reads only its own memory and GPU, so it recommends and pulls no model for that one. Pull one where that Ollama runs: ollama pull <tag>.";
113
+ /** Why no pull is made through the Ollama `env` names, in words, or undefined where one may: the faux model or a model
114
+ * gateway takes every model here (asksOllama); a server that is not one owner's own on their own machine (`notOwn`,
115
+ * server.ts whyNotOwnMachine's reasons) pulls nothing into an Ollama that is not theirs. */
116
+ export declare function pullRefusal(env: NodeJS.ProcessEnv, notOwn: readonly string[]): string | undefined;
117
+ /** What GET /settings/local-model and POST /settings/local-model/pull read. */
118
+ export type LocalModelDeps = {
119
+ env: NodeJS.ProcessEnv;
120
+ notOwn: readonly string[];
121
+ machine: () => Promise<Machine>;
122
+ pulls: LocalPulls;
123
+ };
124
+ /** The read surface: the machine, its Ollama, the recommendation, the pull here, and whether a pull may be made. */
125
+ export declare function localModelView({ env, notOwn, machine, pulls }: LocalModelDeps): Promise<{
126
+ machine: Machine;
127
+ ollama: OllamaFacts;
128
+ recommended: Recommendation;
129
+ pull: PullView | null;
130
+ can_pull: boolean;
131
+ refused: string | null;
132
+ }>;
133
+ /** POST /settings/local-model/pull: `{ tag }`, one of LOCAL_MODEL_TAGS (422 otherwise), where a pull may be made (403 in
134
+ * words otherwise), none under way (409 local_model_pulling). Answers the read surface with the pull started. */
135
+ export declare function pullLocalModel(deps: LocalModelDeps, body: unknown): Promise<{
136
+ machine: Machine;
137
+ ollama: OllamaFacts;
138
+ recommended: Recommendation;
139
+ pull: PullView | null;
140
+ can_pull: boolean;
141
+ refused: string | null;
142
+ }>;
143
+ /** The real pull: through the Ollama `env` names (ollama-provider.ts ollamaPull). */
144
+ export declare const pullThrough: (env: () => NodeJS.ProcessEnv, stallMs?: number) => (tag: string, onLine: (line: OllamaPullLine) => void, signal: AbortSignal) => Promise<void>;