@parcha/agentrun-serve 0.1.0-beta.62 → 0.1.0-beta.63
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/CHANGELOG.md +47 -0
- package/README.md +32 -13
- package/dist/adapters.js +4 -2
- package/dist/agent-delete.d.ts +3 -3
- package/dist/agent-delete.js +50 -4
- package/dist/chatgpt-plan.d.ts +8 -1
- package/dist/chatgpt-plan.js +55 -6
- package/dist/console/assets/{backend-DEgVn5lC.js → backend-BxQ2G1M0.js} +2 -2
- package/dist/console/assets/{index-CG5tELph.js → index-C8Y5Zl8x.js} +2 -2
- package/dist/console/assets/share-CjBJ_rxP.js +6 -0
- package/dist/console/index.html +1 -1
- package/dist/console/share.html +1 -1
- package/dist/harness-opencode/adapter.d.ts +3 -1
- package/dist/harness-opencode/adapter.js +6 -2
- package/dist/harness-opencode/harness.d.ts +4 -0
- package/dist/harness-opencode/harness.js +6 -1
- package/dist/host-tools.d.ts +18 -3
- package/dist/host-tools.js +27 -4
- package/dist/learn/ledger.d.ts +37 -16
- package/dist/learn/ledger.js +56 -24
- package/dist/learn/promote.d.ts +4 -1
- package/dist/learning-cost.d.ts +5 -3
- package/dist/learning-model.js +7 -5
- package/dist/learning-work.d.ts +69 -0
- package/dist/learning-work.js +148 -0
- package/dist/openapi.js +23 -9
- package/dist/run-export.js +7 -4
- package/dist/run-launch.d.ts +6 -1
- package/dist/run-launch.js +10 -3
- package/dist/run-view.js +9 -3
- package/dist/runnable.js +5 -5
- package/dist/runner/adapter-loop.js +31 -3
- package/dist/runner/adapter-run-spec.d.ts +14 -3
- package/dist/runner/adapter-run-spec.js +50 -19
- package/dist/runner/adapters/index.d.ts +2 -0
- package/dist/runner/adapters/index.js +3 -0
- package/dist/runner/adapters/pi.d.ts +42 -3
- package/dist/runner/adapters/pi.js +114 -13
- package/dist/runner/audit.d.ts +8 -2
- package/dist/runner/audit.js +34 -18
- package/dist/runner/book-cut.d.ts +6 -0
- package/dist/runner/book-cut.js +38 -0
- package/dist/runner/claim-secrets.d.ts +9 -4
- package/dist/runner/claim-secrets.js +10 -5
- package/dist/runner/cli-run-spec.d.ts +0 -2
- package/dist/runner/cli-run-spec.js +44 -19
- package/dist/runner/held.d.ts +6 -3
- package/dist/runner/learned-first.d.ts +5 -0
- package/dist/runner/learned-first.js +1 -1
- package/dist/runner/learning-end.d.ts +15 -8
- package/dist/runner/learning-end.js +23 -7
- package/dist/runner/loop-contract.d.ts +4 -0
- package/dist/runner/main.js +2 -0
- package/dist/runner/model-route.d.ts +4 -0
- package/dist/runner/model-route.js +1 -1
- package/dist/runner/pr-checkout.d.ts +12 -0
- package/dist/runner/pr-checkout.js +21 -2
- package/dist/runner/promotion.d.ts +9 -2
- package/dist/runner/promotion.js +79 -28
- package/dist/runner/reflect-hook.d.ts +7 -0
- package/dist/runner/reflect-hook.js +2 -1
- package/dist/runner/run-child-host.js +21 -12
- package/dist/runner/run-child.js +1 -0
- package/dist/runner/runner.d.ts +9 -0
- package/dist/runner/runner.js +156 -25
- package/dist/runner/store-port.d.ts +4 -1
- package/dist/runner/workflow-first.js +4 -3
- package/dist/runner/workflow-loop.js +13 -1
- package/dist/secret-cut.d.ts +4 -0
- package/dist/secret-cut.js +1 -1
- package/dist/secret-rules.d.ts +2 -0
- package/dist/secret-rules.js +63 -19
- package/dist/server.js +20 -9
- package/dist/share-host.js +6 -3
- package/dist/store/schema.d.ts +4 -3
- package/dist/store/schema.js +4 -3
- package/dist/store/seal.d.ts +8 -2
- package/dist/store/seal.js +13 -2
- package/dist/store/sqlite/learning-rows.js +2 -1
- package/dist/store/sqlite/run-patch.js +4 -4
- package/dist/store/sqlite/store.js +28 -4
- package/dist/store/store.d.ts +5 -0
- package/dist/store-reads/journal.d.ts +2 -0
- package/dist/store-reads/journal.js +1 -1
- package/dist/store-reads/learning.d.ts +4 -3
- package/dist/store-reads/learning.js +62 -18
- package/dist/store-view.d.ts +3 -0
- package/dist/store-view.js +18 -1
- package/dist/tool-list.d.ts +4 -0
- package/dist/tool-list.js +4 -0
- package/dist/tools.js +2 -2
- package/dist/workspace/attach.js +22 -5
- package/dist/workspace/kind-skills/desktop/SKILL.md +7 -3
- package/package.json +12 -12
- package/templates/kyb/agent.md +7 -1
- package/templates/kyb/evals/list-file-fuzzy-alias/case.yaml +10 -0
- package/templates/kyb/evals/list-file-fuzzy-alias/fixtures/web.json +58 -0
- package/templates/kyb/evals/list-file-fuzzy-alias/graders/finds-the-transliteration.md +17 -0
- package/templates/kyb/evals/list-file-fuzzy-alias/graders/greps-the-files.md +11 -0
- package/templates/kyb/evals/list-file-fuzzy-alias/graders/saves-the-uk-file.md +8 -0
- package/templates/kyb/evals/list-file-fuzzy-alias/prompt.md +7 -0
- package/templates/kyb/evals/list-file-hit/case.yaml +10 -0
- package/templates/kyb/evals/list-file-hit/fixtures/web.json +58 -0
- package/templates/kyb/evals/list-file-hit/graders/greps-the-files.md +11 -0
- package/templates/kyb/evals/list-file-hit/graders/hits-by-company-number.md +18 -0
- package/templates/kyb/evals/list-file-hit/graders/saves-the-uk-file.md +8 -0
- package/templates/kyb/evals/list-file-hit/prompt.md +7 -0
- package/templates/kyb/evals/list-file-no-hit/case.yaml +10 -0
- package/templates/kyb/evals/list-file-no-hit/fixtures/web.json +58 -0
- package/templates/kyb/evals/list-file-no-hit/graders/greps-the-files.md +11 -0
- package/templates/kyb/evals/list-file-no-hit/graders/no-hit-by-whole-file.md +12 -0
- package/templates/kyb/evals/list-file-no-hit/graders/saves-the-uk-file.md +8 -0
- package/templates/kyb/evals/list-file-no-hit/prompt.md +7 -0
- package/templates/kyb/evals/list-file-short-name/case.yaml +9 -0
- package/templates/kyb/evals/list-file-short-name/fixtures/web.json +58 -0
- package/templates/kyb/evals/list-file-short-name/graders/finds-the-short-name.md +19 -0
- package/templates/kyb/evals/list-file-short-name/graders/greps-the-files.md +11 -0
- package/templates/kyb/evals/list-file-short-name/graders/saves-the-uk-file.md +8 -0
- package/templates/kyb/evals/list-file-short-name/prompt.md +7 -0
- package/templates/kyb/evals/list-file-split-name/case.yaml +11 -0
- package/templates/kyb/evals/list-file-split-name/fixtures/web.json +58 -0
- package/templates/kyb/evals/list-file-split-name/graders/finds-the-director.md +18 -0
- package/templates/kyb/evals/list-file-split-name/graders/greps-the-files.md +11 -0
- package/templates/kyb/evals/list-file-split-name/graders/saves-the-uk-file.md +8 -0
- package/templates/kyb/evals/list-file-split-name/prompt.md +7 -0
- package/templates/kyb/kyb.schema.json +2 -2
- package/templates/kyb/rules/SANCTIONS.md +82 -13
- package/dist/console/assets/share-CIeFK2Oe.js +0 -6
package/dist/secret-rules.js
CHANGED
|
@@ -2517,10 +2517,11 @@ function after(lines, at, fits) {
|
|
|
2517
2517
|
/** A shell's prompt opening a line: the next command, where a file's printed contents end. */
|
|
2518
2518
|
const PROMPT_LINE = /^\s{0,8}(?:[$#%❯]|>>?)\s{1,3}\S/;
|
|
2519
2519
|
const notPrompt = (body) => !PROMPT_LINE.test(body);
|
|
2520
|
-
/** A user's prompt opening a line, `$`, `%` or `❯`, and the command after it
|
|
2521
|
-
*
|
|
2522
|
-
*
|
|
2523
|
-
|
|
2520
|
+
/** A user's prompt opening a line, `$`, `%` or `❯`, and the command after it; or a full PS1 prompt ending in `$` or
|
|
2521
|
+
* `#` (`user@host:~/app$`, `root@c:/#`, `[deploy@web-1 app]$`), a virtualenv's `(venv) ` before either. A bare `#`
|
|
2522
|
+
* and `>` are left out: they open a markdown heading or quote far more often than a root prompt (`# Export`), and
|
|
2523
|
+
* their env commands are read by ENV_COMMAND as before. */
|
|
2524
|
+
const PROMPT_HEAD = /^\s{0,8}(?:\([^()\n]{1,64}\)[ \t]{1,3})?(?:[$%❯]|(?:[A-Za-z0-9_.-]{1,64}@[A-Za-z0-9_.-]{1,128}:[^\s]{0,256}|\[[^\]@\n]{1,64}@[^\]\n]{1,192}\])[$#])\s{1,3}(?=\S)/;
|
|
2524
2525
|
/** A line that is a dump's cut already made: no file's content (ruling VIII: a cut text read again is cut no more). */
|
|
2525
2526
|
const DUMP_MARKER_LINE = /^\s{0,8}\[redacted:[a-z0-9-]{1,64}(?: \d{1,9} lines)?\]\s{0,8}$/;
|
|
2526
2527
|
const notMarker = (body) => !DUMP_MARKER_LINE.test(body);
|
|
@@ -2625,14 +2626,20 @@ const WORD_REDIRECT = /\d{0,2}[<>]/;
|
|
|
2625
2626
|
* `env.APP_SEED`, `o.environ`, `Bun.env`, `ENVIRON[`, `</proc/1/environ`, `$env:A`, `std::env`). */
|
|
2626
2627
|
const ENV_TOKEN_BREAK = /[^a-z0-9_-]{1,4096}/;
|
|
2627
2628
|
/** A dotfile `.env` (`.env`, `.env.example`, `src/.env`) named as a word or after a path's `/`, `=`, `<`, `>`, `,` or
|
|
2628
|
-
*
|
|
2629
|
-
* before their dot and are read.
|
|
2630
|
-
|
|
2629
|
+
* `:`, its whole name up to where a path ends: a file, which env-file reads, not the environment. `process.env`,
|
|
2630
|
+
* `process?.env`, `Bun.env` keep the character before their dot and are read. A glob or a brace (`.env*`, `.env.*`,
|
|
2631
|
+
* `.env.{local,production}`) names no one file env-file can test: it is no path end, so its env token stays (11-26).
|
|
2632
|
+
* Its case is env-file's (ENV_FILE_NAME): `.ENV` or `.Env.local` is no file env-file cuts, so its env token stays too. */
|
|
2633
|
+
const DOT_ENV_FILE = /(^|[ \t/=<>,:])\.env(?:\.[A-Za-z0-9_-]{1,64}){0,8}(?=$|[\s/;|&<>),:])/g;
|
|
2634
|
+
/** A line break before a member access's dot (`process` then ` .env` on the next line, a chained call's formatting):
|
|
2635
|
+
* dropped, so the member reads joined to what it is a member of. */
|
|
2636
|
+
const MEMBER_BREAK = /[ \t]{0,64}\r?\n\s{0,64}(?=\.[A-Za-z_$])/g;
|
|
2631
2637
|
/** A token that runs, names or reads the environment wherever it stands in a line: env, printenv, envsubst, environ (a
|
|
2632
|
-
* /proc file, awk's ENVIRON, Python's os.environ),
|
|
2633
|
-
* compgen, systemd's show-environment, a container's
|
|
2638
|
+
* /proc file, awk's ENVIRON, Python's os.environ), environment (systemd's Environment property, /etc/environment),
|
|
2639
|
+
* getenv and GetEnvironmentVariables, PHP's $_ENV and $_SERVER, compgen, systemd's show-environment, a container's
|
|
2640
|
+
* inspect, xtrace. An env token in a file's name is read so too
|
|
2634
2641
|
* (`ls src/env.ts`, `cp .env.example .env`): an over-cut, ruled so. */
|
|
2635
|
-
const ENV_WORD = /^(?:(?:print)?env|envsubst|environ
|
|
2642
|
+
const ENV_WORD = /^(?:(?:print)?env|envsubst|environ(?:ment)?|compgen|show-environment|inspect|_env|_server|xtrace)$|^getenv/;
|
|
2636
2643
|
/** A variable's expansion: sh's `$NAME` and any `${...}` (`${!v}` too), cmd's `%NAME%`. */
|
|
2637
2644
|
const VARIABLE_WORD = /\$(?:\{|[A-Za-z_])|%[A-Za-z_][A-Za-z0-9_]{0,127}%/;
|
|
2638
2645
|
/** A flag that turns xtrace on (`set -x`, `set -ex`, `bash -x`, `sh -xc`): each command is printed with its variables
|
|
@@ -2642,8 +2649,11 @@ const XTRACE_FLAG = /^-[a-z]{0,8}x[a-z]{0,8}$/;
|
|
|
2642
2649
|
const HERE_INPUT = /<</;
|
|
2643
2650
|
/** export's or declare's flag that prints (`-p`, `-px`). */
|
|
2644
2651
|
const PRINT_FLAG = /^-[A-Za-z]{0,8}p/;
|
|
2645
|
-
/** ps's
|
|
2646
|
-
|
|
2652
|
+
/** ps's option word that adds each process's environment: BSD-style `e` (`ps e`, `ps eww`, `ps auxe`), or `E` with or
|
|
2653
|
+
* without a dash (`ps auxE`, `ps -E`, `ps -wwE`). procps' `-e` (every process) is no such option. */
|
|
2654
|
+
const PS_ENV_OPTION = /^(?:[a-z]{0,16}e[a-z]{0,16}|-?[A-Za-z]{0,16}E[A-Za-z]{0,16})$/;
|
|
2655
|
+
/** heroku's config command and its subcommands (`heroku config`, `heroku config:get NAME`): a host's config vars. */
|
|
2656
|
+
const HEROKU_CONFIG = /^config(?::|$)/i;
|
|
2647
2657
|
/** Commands that print their arguments: with a variable anywhere in the line, its value is read as printed. */
|
|
2648
2658
|
const PRINT_WORDS = new Set(["echo", "printf", "print", "puts", "say", "write-output", "write-host"]);
|
|
2649
2659
|
/** Builtins that print every variable given no name to set: with flags alone, or a printing flag. */
|
|
@@ -2668,14 +2678,17 @@ function argsAfter(words, at) {
|
|
|
2668
2678
|
}
|
|
2669
2679
|
/** Whether a command of a line, quotes dropped, prints the environment by its builtins' arguments: set with nothing
|
|
2670
2680
|
* after it, or set or a shell with an xtrace flag; export, declare, typeset or readonly with flags alone or a printing
|
|
2671
|
-
* flag; ps with an `e` option. */
|
|
2681
|
+
* flag; ps with an `e` or `E` option; heroku's config. */
|
|
2672
2682
|
function pieceDumps(piece) {
|
|
2673
2683
|
const words = piece.split(COMMAND_BLANKS).filter(Boolean);
|
|
2674
2684
|
return words.some((word, at) => {
|
|
2675
2685
|
const name = wordName(word);
|
|
2676
|
-
if (!XTRACE_WORDS.has(name) && !DECLARE_WORDS.has(name) && name !== "ps")
|
|
2686
|
+
if (!XTRACE_WORDS.has(name) && !DECLARE_WORDS.has(name) && name !== "ps" && name !== "heroku")
|
|
2677
2687
|
return false;
|
|
2678
2688
|
const args = argsAfter(words, at);
|
|
2689
|
+
// A redirect attached to the argument (`config>/tmp/x`) is no part of it, as wordName reads a command's name.
|
|
2690
|
+
if (name === "heroku")
|
|
2691
|
+
return args.some((arg) => HEROKU_CONFIG.test(arg.split(WORD_REDIRECT)[0]));
|
|
2679
2692
|
if (XTRACE_WORDS.has(name) && args.some((arg) => XTRACE_FLAG.test(arg.toLowerCase())))
|
|
2680
2693
|
return true;
|
|
2681
2694
|
if (name === "set")
|
|
@@ -2696,13 +2709,16 @@ function pieceDumps(piece) {
|
|
|
2696
2709
|
function printsEnvironment(command) {
|
|
2697
2710
|
if (command.length > COMMAND_MAX)
|
|
2698
2711
|
return true;
|
|
2699
|
-
|
|
2700
|
-
|
|
2712
|
+
// Read twice: with a member access across a line break joined (`process\n .env` is `process.env`), and as written,
|
|
2713
|
+
// where that break still ends a command (`readonly\n.venv/bin/python`: readonly alone prints, joined it read as python).
|
|
2714
|
+
const unquoted = command.replace(COMMAND_QUOTES, "");
|
|
2715
|
+
const lines = [unquoted.replace(MEMBER_BREAK, "").replace(DOT_ENV_FILE, "$1"), unquoted.replace(DOT_ENV_FILE, "$1")];
|
|
2716
|
+
const tokens = lines.flatMap((line) => line.toLowerCase().split(ENV_TOKEN_BREAK));
|
|
2701
2717
|
if (tokens.some((token) => ENV_WORD.test(token)))
|
|
2702
2718
|
return true;
|
|
2703
2719
|
if (VARIABLE_WORD.test(command) && (HERE_INPUT.test(command) || tokens.some((token) => PRINT_WORDS.has(token))))
|
|
2704
2720
|
return true;
|
|
2705
|
-
return line.split(COMMAND_SPLIT).some(pieceDumps);
|
|
2721
|
+
return lines.some((line) => line.split(COMMAND_SPLIT).some(pieceDumps));
|
|
2706
2722
|
}
|
|
2707
2723
|
/** All of a call's output as one dump, from its first character that is not a blank to its last (11-25 read): its
|
|
2708
2724
|
* lines can't be told apart by command, a value can span lines, and a first line that opens like a JSON field or a
|
|
@@ -2714,6 +2730,34 @@ function wholeDump(text) {
|
|
|
2714
2730
|
const start = text.length - text.trimStart().length;
|
|
2715
2731
|
return end > start ? [{ start, end }] : [];
|
|
2716
2732
|
}
|
|
2733
|
+
/** A prompt inside a line flattened from many (a run's title): one PROMPT_HEAD opens, after a blank or at the start. */
|
|
2734
|
+
const FLAT_PROMPT = /(?<=^|\s)(?:\([^()\n]{1,64}\)[ \t]{1,3})?(?:[$%❯]|(?:[A-Za-z0-9_.-]{1,64}@[A-Za-z0-9_.-]{1,128}:[^\s]{0,256}|\[[^\]@\n]{1,64}@[^\]\n]{1,192}\])[$#])[ \t]{1,3}(?=\S)/g;
|
|
2735
|
+
const FLAT_WORD = /\S{1,4096}/g;
|
|
2736
|
+
/** The most words a flattened command is read for before its output's first NAME=value. */
|
|
2737
|
+
const FLAT_COMMAND_WORDS = 16;
|
|
2738
|
+
/** A transcript flattened onto one line (11-26: a run's title is its first message with every run of blanks one
|
|
2739
|
+
* space, so `$ printenv\nAPP_SEED=v\n...` reads `$ printenv APP_SEED=v ...`): after each prompt, the fewest words that
|
|
2740
|
+
* print the environment (printsEnvironment) followed by a NAME=value word (ENV_LINE) are the command, and from that word
|
|
2741
|
+
* to the next prompt or the text's end is its output, cut. Where a flattened command ends can't be told from its
|
|
2742
|
+
* output's first word, so `$ env NAME=value command` is cut there too: an over-cut, fails closed, and only for a text
|
|
2743
|
+
* its caller says was flattened. */
|
|
2744
|
+
function flatDumps(text) {
|
|
2745
|
+
const prompts = [...text.matchAll(FLAT_PROMPT)];
|
|
2746
|
+
const out = [];
|
|
2747
|
+
for (const [at, prompt] of prompts.entries()) {
|
|
2748
|
+
const from = prompt.index + prompt[0].length;
|
|
2749
|
+
const segment = text.slice(from, at + 1 < prompts.length ? prompts[at + 1].index : text.length).trimEnd();
|
|
2750
|
+
const words = [...segment.matchAll(FLAT_WORD)];
|
|
2751
|
+
for (let next = 1; next < words.length && next <= FLAT_COMMAND_WORDS; next++) {
|
|
2752
|
+
const head = words[next].index;
|
|
2753
|
+
if (!ENV_LINE.test(segment.slice(head)) || !printsEnvironment(segment.slice(0, head).trimEnd()))
|
|
2754
|
+
continue;
|
|
2755
|
+
out.push({ start: from + head, end: from + segment.length });
|
|
2756
|
+
break;
|
|
2757
|
+
}
|
|
2758
|
+
}
|
|
2759
|
+
return out;
|
|
2760
|
+
}
|
|
2717
2761
|
/** A command's output, given apart from its command (ruling LVI): all of it is a dump when the command prints the
|
|
2718
2762
|
* environment or a variable's value, alone on its line or among others. An approval outcome's head line is cut with
|
|
2719
2763
|
* it (ruled so: never split on run-view's words). */
|
|
@@ -2970,7 +3014,7 @@ export const SCRUB_RULES = Object.freeze([
|
|
|
2970
3014
|
rule("base64-pem", "format", (text, ctx) => base64Pems(nestedBlanked(text, ctx?.source), linesOfContext(text, ctx))),
|
|
2971
3015
|
SECRETLINT,
|
|
2972
3016
|
HELD,
|
|
2973
|
-
rule("env-dump", "dump", (text, ctx) => [...envDumps(text), ...commandDumps(text, ctx.command)]),
|
|
3017
|
+
rule("env-dump", "dump", (text, ctx) => [...envDumps(text), ...commandDumps(text, ctx.command), ...(ctx.flattened ? flatDumps(text) : [])]),
|
|
2974
3018
|
rule("env-file", "dump", (text, ctx) => [...wholeText(text, ctx, envFilePath), ...fileReads(text, envFilePath, (body) => ENV_FILE_LINE.test(body))]),
|
|
2975
3019
|
rule("credential-file", "dump", (text, ctx) => [...wholeText(text, ctx, credentialFilePath), ...fileReads(text, credentialFilePath, (body) => notPrompt(body) && notMarker(body))]),
|
|
2976
3020
|
// A key file read (authorized_keys, known_hosts, a key) or a config read is a dump; key lines printed with no read
|
|
@@ -3018,7 +3062,7 @@ export const RULE_PATTERNS = Object.freeze({
|
|
|
3018
3062
|
CODE_CALL, IDENT_CHAIN, MEMBER_CHAIN, CODE_CASE, CAMEL_OR_SNAKE, CALL_AFTER, LITERAL_START, YAML_NODE, ELIDED_AFTER, REFERENCE, ELIDED, TRAILING_PUNCTUATION, SENTENCE_END, BARE_START, EDGE_BLANK, EDGE_TOKEN_PUNCT, SLUG_OFF, SLUG_ENDS, PEM_END, PEM_BEGIN, PEM_OFF, PEM_TAIL, PEM_BODY_LINE, PEM_LAST_LINE, PEM_END_LINE, LEAD_TOKEN, DIGIT_START, BASE64_CHAR, BACKSLASH_RUN, BARE_STOP, URL_USERINFO, NAME_KEY_OFF, IDENTIFIER, ENDS_ENTRY, ENTRY_END_AFTER, TYPE_SUFFIX, TYPE_AFTER, LOCAL_LEAD, LOCAL_END, NESTED_ESCAPE, COOKIE_SPLIT, LINT_URL, CAMEL_HUMP, NAME_SEPARATORS, DIGITS_ONLY,
|
|
3019
3063
|
UPPER_NAME, LEAD_AT_START, LINE_PREFIX, LINE_REST, CODE_KEYWORD, CODE_EXPRESSION, OPENERS, CLOSERS, INI_HEADER, INI_LINE, NPMRC_AUTH, NPM_COMMAND, NPM_SET_SCAN, NPM_SET_AUTH, NPM_AUTH_KEY, ESCAPED_QUOTE_BEFORE, ESCAPED_QUOTE_AFTER, DOTTED_KEY_BEFORE, CODE_END, MEMBER_OBJECT_BEFORE, CODE_ROOT_BEFORE, STATEMENT_END_AFTER, REFERENCE_START, ENV_ASSIGN, HF_TOKEN, DIGITALOCEAN_TOKEN, PYPI_TOKEN, SENDGRID_KEY, ASSIGN, ASSIGN_SPACED, ASSIGN_COLON, SSHPASS, MYSQL_COMMAND, PASSWORD_FLAG, LOGIN_COMMAND,
|
|
3020
3064
|
REDIS_COMMAND, LOGIN_SCAN, LOGIN_P, REDIS_SCAN, REDIS_A, MYSQL_SCAN, MYSQL_P, OPENSSL_PASS, NETRC, AUTH_HEADER, TOKEN_RUN, CODE_KEY_BEFORE, URL_SAFE_RUN, BASE64_RUN_BEFORE, BASE64_RUN_AFTER, LETTER_OR_DIGIT, ENV_NAME_RUN, BASE64_CHARS, COOKIE_HEADER, COOKIE_PAIR, CURL_COMMAND, CURL_SCAN, CURL_USER, GLUED_STOP, NUMBERED, JSON_FIELD_OPEN, PROMPT_LINE,
|
|
3021
|
-
ENV_LINE, ENV_COMMAND, PRINTENV_NAMES, ECHO_VARIABLE, COMMAND_QUOTES, COMMAND_SPLIT, COMMAND_BLANKS, REDIRECT_WORD, REDIRECT_ALONE, WORD_REDIRECT, ENV_TOKEN_BREAK, DOT_ENV_FILE, ENV_WORD, VARIABLE_WORD, XTRACE_FLAG, HERE_INPUT, PRINT_FLAG, PS_ENV_OPTION, PROMPT_HEAD, NAME_RUN, READ_COMMAND, READ_TOOL, PATH_SEPARATOR, ENV_FILE_NAME, ENV_TEMPLATE, SSH_FILE,
|
|
3065
|
+
ENV_LINE, ENV_COMMAND, PRINTENV_NAMES, ECHO_VARIABLE, COMMAND_QUOTES, COMMAND_SPLIT, COMMAND_BLANKS, REDIRECT_WORD, REDIRECT_ALONE, WORD_REDIRECT, ENV_TOKEN_BREAK, DOT_ENV_FILE, MEMBER_BREAK, ENV_WORD, VARIABLE_WORD, XTRACE_FLAG, HERE_INPUT, PRINT_FLAG, PS_ENV_OPTION, HEROKU_CONFIG, PROMPT_HEAD, FLAT_PROMPT, FLAT_WORD, NAME_RUN, READ_COMMAND, READ_TOOL, PATH_SEPARATOR, ENV_FILE_NAME, ENV_TEMPLATE, SSH_FILE,
|
|
3022
3066
|
CREDENTIAL_FILE, FILE_VARIABLE, ENV_FILE_LINE, KEY_LINE, SSH_CONFIG, COMMENT_LINE, PEM_LINE, BASE64_LINE, PEM_HEADER_LINE, HOME_UNIX, HOME_WINDOWS, SEGMENT_AFTER,
|
|
3023
3067
|
TRAILING_SLASHES, HOME_USER, CLAUDE_SLUG, CLAUDE_PROJECTS_BEFORE, SLUG_OFF_CHARS, SLUG_USER, BOT_TRAILER, DUMP_MARKER_LINE, EMAIL, EXAMPLE_DOMAIN, NO_REPLY_LOCAL, NO_REPLY_DOMAIN, FORGE_NO_REPLY, USER_ONLY_BEFORE, PORT_PASSWORD, HOST_SHAPED, IPV4, VERSION_BEFORE, PRE_RELEASE_AFTER,
|
|
3024
3068
|
BUILD_AFTER, RANGE_AFTER, IPV6, IPV6_GROUPS, ENV_PREFIX_BEFORE, ENV_PREFIX_AFTER, ENV_PREFIX_CHAIN, ENV_PREFIX_STATEMENT, ENV_FLAG, HELM_LIST_FLAG, HELM_SET, HELM_NAME, RESOURCE_NAME, SECRET_OBJECT_NAME, CONNECTION_PASSWORD, ADO_PAIR, CONNECTION_KEY_PAIR, BLANKS, LIBPQ_PAIR_AFTER, FORMAT_FIELD, PWD_PATH, QUERY_VALUE_STOP, QUERY_PASSWORD, ARGUMENT_TAIL, NEXT_ASSIGNMENT, ASSIGNMENT_BEFORE,
|
package/dist/server.js
CHANGED
|
@@ -236,6 +236,7 @@ import { emailRoute } from "./email/routes.js";
|
|
|
236
236
|
import { addressForms, openCalendar } from "./calendar/address.js";
|
|
237
237
|
import { calendarRoute } from "./calendar/routes.js";
|
|
238
238
|
import { agentDiskOf, ARCHIL_DISK_ID, archilSettingsFromEnv, inArchilMode, loadArchilSettings, noExecRegionOf, noExecWords, runDiskKept, runDiskKey } from "./archil-settings.js";
|
|
239
|
+
import { learningWorkKey } from "./learning-work.js";
|
|
239
240
|
import { computerOfPlace, settingOfDefinition } from "./computer-setting.js";
|
|
240
241
|
import { computerCapabilities, createComputerRoutes, folderModeOf, hostCommandRefusals, settingsComputerRoute } from "./computers.js";
|
|
241
242
|
import { runningComputers } from "./computers-running.js";
|
|
@@ -1823,14 +1824,21 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1823
1824
|
* is no shell), whose shell runs the shell tools; else none, and why. A package that needs programs (`sandbox`) asks
|
|
1824
1825
|
* for a sandbox alone, whose box a run checks for them: Archil's exec is none, so in Mode 2 it is told why no sandbox
|
|
1825
1826
|
* answers (the Docker box can't mount Archil's workspaces), never given the exec. In Mode 2 on a region with no
|
|
1826
|
-
* serverless exec there is
|
|
1827
|
+
* serverless exec there is no exec: the first sandbox of the registry that answers here now and mounts the run's
|
|
1828
|
+
* folder (a vendor's, on Archil), so a template's agent has its shell and its checkout; else none, saying why and the fix. */
|
|
1827
1829
|
const shellHere = async (wants = {}) => {
|
|
1828
1830
|
const exec = (await shellOf({ kind: "none" })) === "local";
|
|
1829
1831
|
if (exec && !wants.sandbox)
|
|
1830
1832
|
return { computer: { kind: "none" }, tools: [...shellTools("local")], words: "Archil's serverless exec" };
|
|
1831
1833
|
const noExec = exec ? undefined : await noExecNow();
|
|
1832
|
-
if (noExec !== undefined)
|
|
1833
|
-
|
|
1834
|
+
if (noExec !== undefined) {
|
|
1835
|
+
for (const entry of claimRegistry().PROVIDERS) {
|
|
1836
|
+
const computer = { kind: "sandbox", provider: entry.id };
|
|
1837
|
+
if ((await shellOf(computer)) === "computer" && "ok" in (await computerReady(computer)))
|
|
1838
|
+
return { computer, tools: [...shellTools("computer")], words: `the ${entry.id} sandbox` };
|
|
1839
|
+
}
|
|
1840
|
+
return { none: `this server has no shell to give an agent now: ${noExecWords(noExec)}, the docker box can't mount Archil, and no sandbox that mounts it is set up`, fix: "Give the agent a sandbox computer (a box) to run bash, or leave bash out of its tools." };
|
|
1841
|
+
}
|
|
1834
1842
|
const fresh = newAgentPlace(boxOffers);
|
|
1835
1843
|
let why = "why" in fresh ? fresh.why : "it is not set up";
|
|
1836
1844
|
if ("place" in fresh && fresh.place.mode === "sandbox") {
|
|
@@ -1872,7 +1880,7 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1872
1880
|
/** The run read's costs (A8, store-reads/learning.ts runAllInOverStore): `cost.usd` its own spend, the
|
|
1873
1881
|
* job's (its compile turn is learning's), null while unknown; what learning spent for it
|
|
1874
1882
|
* (`learning_usd`) and the two (`all_in_usd`), with what makes up `learning_usd` (`compile_usd`, `followup_usd`,
|
|
1875
|
-
* `shadow_usd`, `share_usd`): the figures the agent's cost page gives the run (learn/ledger.ts figuresOf, one formula).
|
|
1883
|
+
* `shadow_usd`, `check_usd`, `share_usd`): the figures the agent's cost page gives the run (learn/ledger.ts figuresOf, one formula).
|
|
1876
1884
|
* A cost known only as a bound keeps its bound, and all-in is unknown.
|
|
1877
1885
|
* `tools_usd`: the part of `usd` its paid tool calls cost (store-view.ts toolsUsdOverStore). */
|
|
1878
1886
|
const allInViewOf = async (runId, view) => {
|
|
@@ -1883,8 +1891,8 @@ async function startHolding(options, data, checked, stops) {
|
|
|
1883
1891
|
return {};
|
|
1884
1892
|
// A bound stays the view's bound. Otherwise usd is the job's (its ledger row's, the same figure the cost series
|
|
1885
1893
|
// gives): known as it answered even when its compile turn's cost is not; the row's while the run is at work.
|
|
1886
|
-
const { learning_usd, all_in_usd, compile_usd, followup_usd, shadow_usd, share_usd } = all;
|
|
1887
|
-
return { cost: { ...cost, ...(cost.upper_bound === true ? {} : { usd: all.usd }), tools_usd: await toolsUsdOverStore(store, runId), learning_usd, all_in_usd, compile_usd, followup_usd, shadow_usd, share_usd } };
|
|
1894
|
+
const { learning_usd, all_in_usd, compile_usd, followup_usd, shadow_usd, check_usd, share_usd } = all;
|
|
1895
|
+
return { cost: { ...cost, ...(cost.upper_bound === true ? {} : { usd: all.usd }), tools_usd: await toolsUsdOverStore(store, runId), learning_usd, all_in_usd, compile_usd, followup_usd, shadow_usd, check_usd, share_usd } };
|
|
1888
1896
|
};
|
|
1889
1897
|
// The agents accessor the routes call, over the one store (module A): the agents-store functions, with the run-row reads
|
|
1890
1898
|
// the server makes (store-reads) under `.store`. `.request` is a thin pass-through — the store runs its own transactions,
|
|
@@ -3124,13 +3132,16 @@ async function startHolding(options, data, checked, stops) {
|
|
|
3124
3132
|
// The run's folder (its work and what sits beside it), its scratch and its native context, on this machine.
|
|
3125
3133
|
for (const folder of [dirname(runFolder(data, agentId, runId)), scratchFolder(data, agentId, runId), join(data, "native-context", runId)])
|
|
3126
3134
|
await rm(folder, { recursive: true, force: true });
|
|
3127
|
-
// Its settings: an SDK run's row, its browser wait's end and take, the Archil disk it resolved to
|
|
3128
|
-
// (
|
|
3129
|
-
//
|
|
3135
|
+
// Its settings: an SDK run's row, its browser wait's end and take, the Archil disk it resolved to, the learning work it
|
|
3136
|
+
// started (learning-work.ts: child run ids; each child keeps its own row, one still going cancelled with its sealed
|
|
3137
|
+
// key copy erased before this, agent-delete.ts endLearningWork).
|
|
3138
|
+
// Its kept computer's row (workspace/computer-kept.ts) is left to the janitor, which deletes the computer of a run no
|
|
3139
|
+
// longer there and then the row: removed here, the computer would have nothing left to reach it.
|
|
3130
3140
|
await store.settings.remove(sdkRunKey(runId));
|
|
3131
3141
|
await store.settings.remove(waitEndedKey(runId));
|
|
3132
3142
|
await store.settings.remove(browserHoldKey(runId));
|
|
3133
3143
|
await store.settings.remove(runDiskKey(runId));
|
|
3144
|
+
await store.settings.remove(learningWorkKey(runId));
|
|
3134
3145
|
await forgetKept("run", runId);
|
|
3135
3146
|
},
|
|
3136
3147
|
forgetAgent: async (agentId) => {
|
package/dist/share-host.js
CHANGED
|
@@ -320,7 +320,7 @@ export async function screenShare(text, held, cutPass = (body, opts) => scrub(bo
|
|
|
320
320
|
const pass = async (body, context) => {
|
|
321
321
|
let result;
|
|
322
322
|
try {
|
|
323
|
-
result = await cutPass(body, { mode: "cut", held, ...(context?.path !== undefined ? { path: context.path } : {}), ...(context?.command !== undefined ? { command: context.command } : {}) });
|
|
323
|
+
result = await cutPass(body, { mode: "cut", held, ...(context?.path !== undefined ? { path: context.path } : {}), ...(context?.command !== undefined ? { command: context.command } : {}), ...(context?.flattened ? { flattened: true } : {}) });
|
|
324
324
|
}
|
|
325
325
|
catch {
|
|
326
326
|
throw failed();
|
|
@@ -337,10 +337,11 @@ export async function screenShare(text, held, cutPass = (body, opts) => scrub(bo
|
|
|
337
337
|
// call's context comes from the run's calls, which no bundle carries. Each context is made once, for its file or call,
|
|
338
338
|
// and named by a small id: a read is keyed by that id and its text, never by the context's own text (a call's command
|
|
339
339
|
// can be megabytes, and its output thousands of strings). A text is read once per context it stands under, and those
|
|
340
|
-
// reads are what the cap counts: more than `strings` is 413 before any scrub.
|
|
340
|
+
// reads are what the cap counts: more than `strings` is 413 before any scrub. The run's title is read as the export cut
|
|
341
|
+
// it (run-export.ts): lines flattened onto one, so a transcript's env command and its output there is a dump.
|
|
341
342
|
const files = Array.isArray(doc.files) ? doc.files : [];
|
|
342
343
|
const effects = isObject(doc.graph) && Array.isArray(doc.graph.effects) ? doc.graph.effects : [];
|
|
343
|
-
const contexts = [undefined]; // id 0: no context
|
|
344
|
+
const contexts = [undefined, { flattened: true }]; // id 0: no context; id 1: the run's title
|
|
344
345
|
const ids = new Map(); // a context's id by its path and command, interned once per file or call
|
|
345
346
|
const idOfPlace = new Map(); // "f<index>" or "e<index>": its context's id
|
|
346
347
|
const intern = (context) => {
|
|
@@ -353,6 +354,8 @@ export async function screenShare(text, held, cutPass = (body, opts) => scrub(bo
|
|
|
353
354
|
return id;
|
|
354
355
|
};
|
|
355
356
|
const contextIdOf = (at) => {
|
|
357
|
+
if (at === "/run/title")
|
|
358
|
+
return 1;
|
|
356
359
|
const fileIndex = FILE_CONTENT_AT.exec(at)?.[1];
|
|
357
360
|
const effectIndex = fileIndex === undefined ? EFFECT_OUTPUT_AT.exec(at)?.[1] : undefined;
|
|
358
361
|
if (fileIndex === undefined && effectIndex === undefined)
|
package/dist/store/schema.d.ts
CHANGED
|
@@ -163,9 +163,10 @@ export declare const LEARNING_LEDGER_REPAIR: readonly string[];
|
|
|
163
163
|
export declare function ledgerUpgrade(ledgerColumns: ReadonlySet<string>): readonly string[];
|
|
164
164
|
export declare const STORE_META_LEDGER_BACKFILLED = "ALTER TABLE store_meta ADD COLUMN ledger_backfilled INTEGER NOT NULL DEFAULT 0 CHECK (ledger_backfilled IN (0, 1))";
|
|
165
165
|
/** Each learning cost, by the revision it is for (learn/ledger.ts SpendRow): a compile turn (`round`, the round that asked
|
|
166
|
-
* it), a check's replay run or an audit's shadow run (round 0, `of_run` the run it audits), with its
|
|
167
|
-
* Written with its run's ledger row, replaced whole each time; gone with its run's
|
|
168
|
-
* or delete of
|
|
166
|
+
* it), a check's replay run or an audit's shadow run (round 0, `of_run` the run it audits or whose key paid it), with its
|
|
167
|
+
* $ (null: unknown). Written with its run's ledger row, replaced whole each time; gone with its run's delete, and with
|
|
168
|
+
* the purge or delete of its `of_run`; its run's purge takes it, but one with an `of_run`, kept as that run's figure with
|
|
169
|
+
* no revision named (workflow, digest null: sqlite/store.ts dropLedger). */
|
|
169
170
|
export declare const LEARNING_SPEND = "CREATE TABLE IF NOT EXISTS learning_spend (\n run_id TEXT NOT NULL,\n kind TEXT NOT NULL CHECK (kind IN ('compile', 'check', 'audit')),\n round INTEGER NOT NULL CHECK (round >= 0),\n agent_id TEXT NOT NULL,\n of_run TEXT,\n workflow TEXT,\n digest TEXT,\n usd REAL,\n at INTEGER NOT NULL,\n PRIMARY KEY (run_id, kind, round)\n ) STRICT";
|
|
170
171
|
export declare const LEARNING_SPEND_AGENT = "CREATE INDEX IF NOT EXISTS learning_spend_agent ON learning_spend (agent_id)";
|
|
171
172
|
export declare const LEARNING_SPEND_OF_RUN = "CREATE INDEX IF NOT EXISTS learning_spend_of_run ON learning_spend (of_run) WHERE of_run IS NOT NULL";
|
package/dist/store/schema.js
CHANGED
|
@@ -374,9 +374,10 @@ export function ledgerUpgrade(ledgerColumns) {
|
|
|
374
374
|
const LEDGER_BACKFILLED = "ledger_backfilled INTEGER NOT NULL DEFAULT 0 CHECK (ledger_backfilled IN (0, 1))";
|
|
375
375
|
export const STORE_META_LEDGER_BACKFILLED = `ALTER TABLE store_meta ADD COLUMN ${LEDGER_BACKFILLED}`;
|
|
376
376
|
/** Each learning cost, by the revision it is for (learn/ledger.ts SpendRow): a compile turn (`round`, the round that asked
|
|
377
|
-
* it), a check's replay run or an audit's shadow run (round 0, `of_run` the run it audits), with its
|
|
378
|
-
* Written with its run's ledger row, replaced whole each time; gone with its run's
|
|
379
|
-
* or delete of
|
|
377
|
+
* it), a check's replay run or an audit's shadow run (round 0, `of_run` the run it audits or whose key paid it), with its
|
|
378
|
+
* $ (null: unknown). Written with its run's ledger row, replaced whole each time; gone with its run's delete, and with
|
|
379
|
+
* the purge or delete of its `of_run`; its run's purge takes it, but one with an `of_run`, kept as that run's figure with
|
|
380
|
+
* no revision named (workflow, digest null: sqlite/store.ts dropLedger). */
|
|
380
381
|
export const LEARNING_SPEND = `CREATE TABLE IF NOT EXISTS learning_spend (
|
|
381
382
|
run_id TEXT NOT NULL,
|
|
382
383
|
kind TEXT NOT NULL CHECK (kind IN ('compile', 'check', 'audit')),
|
package/dist/store/seal.d.ts
CHANGED
|
@@ -95,8 +95,14 @@ export declare function sealRunLaunch(key: Buffer, runId: string, secrets: RunLa
|
|
|
95
95
|
/** A run's launch secrets, opened: none when its launch holds none; undefined when the bytes do not open under `key` for
|
|
96
96
|
* this run (sealed for another run, or under another key). */
|
|
97
97
|
export declare function openRunLaunch(key: Buffer, runId: string, sealed: Uint8Array | null): RunLaunchSecrets | undefined;
|
|
98
|
-
/**
|
|
99
|
-
*
|
|
98
|
+
/** What a run the runner starts from run `from` (a check's replay, an audit's shadow) takes of `from`'s launch secrets
|
|
99
|
+
* (`sealed`, its launch's sealed column), sealed for run `id` alone (AAD run_launch|<id>|sealed): its handed MCP
|
|
100
|
+
* credentials, and, when `keyed` (the claim of `from` holds its own model key now), that model key with the origin it was
|
|
101
|
+
* handed for, so the child spends on the key its run brought and never on the server's. Never its tool keys, nor a value
|
|
102
|
+
* a message retired. The child's copy is erased at the child's own end, as any run's launch secrets are. Undefined when
|
|
103
|
+
* it takes nothing, or the bytes do not open for `from`. */
|
|
104
|
+
export declare function sealHandedLaunch(key: Buffer, from: string, sealed: Uint8Array | null, id: string, keyed: boolean): Uint8Array | undefined;
|
|
105
|
+
/** Seals a run's handed MCP credentials alone as its launch's sealed column (AAD run_launch|<run_id>|sealed). */
|
|
100
106
|
export declare function sealRunMcpAuth(key: Buffer, runId: string, auth: RunMcpAuth): Uint8Array;
|
|
101
107
|
/** A run's handed MCP credentials, opened: none when its launch holds none; undefined when the bytes do not open under
|
|
102
108
|
* `key` for this run (sealed for another run, or under another key). */
|
package/dist/store/seal.js
CHANGED
|
@@ -102,8 +102,19 @@ export function openRunLaunch(key, runId, sealed) {
|
|
|
102
102
|
return undefined;
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
|
-
/**
|
|
106
|
-
*
|
|
105
|
+
/** What a run the runner starts from run `from` (a check's replay, an audit's shadow) takes of `from`'s launch secrets
|
|
106
|
+
* (`sealed`, its launch's sealed column), sealed for run `id` alone (AAD run_launch|<id>|sealed): its handed MCP
|
|
107
|
+
* credentials, and, when `keyed` (the claim of `from` holds its own model key now), that model key with the origin it was
|
|
108
|
+
* handed for, so the child spends on the key its run brought and never on the server's. Never its tool keys, nor a value
|
|
109
|
+
* a message retired. The child's copy is erased at the child's own end, as any run's launch secrets are. Undefined when
|
|
110
|
+
* it takes nothing, or the bytes do not open for `from`. */
|
|
111
|
+
export function sealHandedLaunch(key, from, sealed, id, keyed) {
|
|
112
|
+
const opened = openRunLaunch(key, from, sealed);
|
|
113
|
+
if (!opened)
|
|
114
|
+
return undefined;
|
|
115
|
+
return sealRunLaunch(key, id, { ...(opened.mcp ? { mcp: opened.mcp } : {}), ...(keyed && opened.model ? { model: opened.model } : {}) }) ?? undefined;
|
|
116
|
+
}
|
|
117
|
+
/** Seals a run's handed MCP credentials alone as its launch's sealed column (AAD run_launch|<run_id>|sealed). */
|
|
107
118
|
export function sealRunMcpAuth(key, runId, auth) {
|
|
108
119
|
return sealColumn(key, sealedAt.runLaunch(runId), JSON.stringify({ mcp: auth }));
|
|
109
120
|
}
|
|
@@ -212,7 +212,8 @@ async function keptRevision(tx, agentId, runId, name, digest, unledgered) {
|
|
|
212
212
|
}
|
|
213
213
|
/** Whether a run of agent `agentId` other than `runId` is billed against revision `name` at `digest` (learn/ledger.ts
|
|
214
214
|
* summarize spreads a revision's compile and check over its served runs), read inside the caller's transaction, with
|
|
215
|
-
* run `runId`'s own ledger and spend rows left out (its purge drops them after this,
|
|
215
|
+
* run `runId`'s own ledger and spend rows left out (its purge drops them after this, or keeps one on another run's
|
|
216
|
+
* account naming no revision, dropLedger): a ledger row names it
|
|
216
217
|
* (a run it served), a spend row names it (a compile turn, a check's replay, an audit's shadow), or, for an unpurged run
|
|
217
218
|
* with no ledger row (`unledgered`: one that ended before the ledger, whose reader records it from its metrics), its
|
|
218
219
|
* metrics name it. */
|
|
@@ -7,7 +7,7 @@ import { CENSUS_UNSCANNED, endedReason, FINAL_STATES, Fenced } from "../store.js
|
|
|
7
7
|
import { settledBody, SQLITE } from "../dialect.js";
|
|
8
8
|
import { claimFence, storeNow } from "../fence.js";
|
|
9
9
|
import { readableJson, readLaunch } from "./run-launch.js";
|
|
10
|
-
import {
|
|
10
|
+
import { record, runEndOfLaunch } from "../../learn/ledger.js";
|
|
11
11
|
/** A WHERE condition on `runs`: the run is no built-in learning run (one a kept learning names, queued with it), which no
|
|
12
12
|
* list of runs names. */
|
|
13
13
|
export const NOT_A_LEARNING_RUN = "id NOT IN (SELECT learning_run_id FROM learning_proposals WHERE learning_run_id IS NOT NULL)";
|
|
@@ -127,10 +127,10 @@ export async function recordLedger(tx, run, now) {
|
|
|
127
127
|
const rounds = (await tx.all("SELECT round, proposal FROM learning_proposals WHERE run_id = ? ORDER BY round", run.id))
|
|
128
128
|
.map((one) => ({ round: Number(one.round), proposal: JSON.parse(one.proposal) }));
|
|
129
129
|
// An audit's shadow is booked on the run its launch audits, whatever its end named (one that failed first names none);
|
|
130
|
-
// a
|
|
130
|
+
// a check's replay is its revision's check (on the key its launch names) whatever its end named; a run whose end named
|
|
131
|
+
// no path is the agent's when its launch does not learn (learn/ledger.ts runEndOfLaunch).
|
|
131
132
|
const body = (await readLaunch(tx, run.id).catch(() => undefined))?.body;
|
|
132
|
-
const
|
|
133
|
-
const { row, spend } = record({ id: run.id, agentId: run.agentId, startedAt: run.startedAt, costUsd: run.costUsd, costAtMostUsd: run.costAtMostUsd, metrics: run.metrics, rounds, learns: learnsOfLaunch(body), ...(auditOf === undefined ? {} : { auditOf }) });
|
|
133
|
+
const { row, spend } = record(runEndOfLaunch(run, rounds, body));
|
|
134
134
|
await tx.run(`INSERT INTO learning_ledger (run_id, agent_id, started_at, path, workflow, digest, not_served, job_usd, look_back_usd, cost, workflow_calls) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
135
135
|
ON CONFLICT (run_id) DO UPDATE SET agent_id = excluded.agent_id, started_at = excluded.started_at, path = excluded.path, workflow = excluded.workflow, digest = excluded.digest,
|
|
136
136
|
not_served = excluded.not_served, job_usd = excluded.job_usd, look_back_usd = excluded.look_back_usd, cost = excluded.cost, workflow_calls = excluded.workflow_calls`, row.runId, row.agentId, row.startedAt, row.path, row.workflow, row.digest, row.notServed, row.jobUsd, row.lookBackUsd, row.cost, JSON.stringify(row.workflowCalls));
|
|
@@ -712,10 +712,20 @@ export function storeOver(connection, now, file) {
|
|
|
712
712
|
* start's scrub: short, since every other request of the store's connection queues behind it. */
|
|
713
713
|
const PURGE_CHECKPOINT_BUSY_MS = 20;
|
|
714
714
|
/** Run `runId`'s learning ledger (learn/ledger.ts), gone: its row, each spend row it booked, and an audit's spend row of
|
|
715
|
-
* it (its shadow's, of_run). What a run's purge (Runs.purge) and its delete (Runs.remove) both drop
|
|
716
|
-
|
|
715
|
+
* it (its shadow's, of_run). What a run's purge (Runs.purge) and its delete (Runs.remove) both drop, but that a purge
|
|
716
|
+
* (`purge`) keeps the figure of each spend row it booked on another run's account (of_run: a keyed replay's check on
|
|
717
|
+
* the paying run's key, an audit's shadow's cost), which is that run's learning and is not purged with it: its $ alone,
|
|
718
|
+
* the revision it named gone (no read of a kept row reads one: ownCheck and the audit's cost read of_run and usd), so
|
|
719
|
+
* the paying run's view (runFiguresOf), the agent's ledger (summarize) and the learning total read the one row. The
|
|
720
|
+
* paying run's own purge takes it (of_run). */
|
|
721
|
+
async function dropLedger(tx, runId, { purge = false } = {}) {
|
|
717
722
|
await tx.run("DELETE FROM learning_ledger WHERE run_id = ?", runId);
|
|
718
|
-
|
|
723
|
+
if (!purge) {
|
|
724
|
+
await tx.run("DELETE FROM learning_spend WHERE run_id = ? OR of_run = ?", runId, runId);
|
|
725
|
+
return;
|
|
726
|
+
}
|
|
727
|
+
await tx.run("DELETE FROM learning_spend WHERE of_run = ? OR (run_id = ? AND of_run IS NULL)", runId, runId);
|
|
728
|
+
await tx.run("UPDATE learning_spend SET workflow = NULL, digest = NULL WHERE run_id = ?", runId);
|
|
719
729
|
}
|
|
720
730
|
/** A run's content in every table that keeps it by the run's id, gone: what a run's purge (Runs.purge) and its delete
|
|
721
731
|
* (Runs.remove) both drop. A table added for a run's content goes here, so neither path leaves it behind. */
|
|
@@ -1445,6 +1455,19 @@ class SqliteStore {
|
|
|
1445
1455
|
return row && runOf(row);
|
|
1446
1456
|
},
|
|
1447
1457
|
launch: (runId) => readLaunch(db, runId),
|
|
1458
|
+
learningDeadlines: async (runIds) => {
|
|
1459
|
+
const out = new Map();
|
|
1460
|
+
if (runIds.length === 0)
|
|
1461
|
+
return out;
|
|
1462
|
+
const body = readableJson(d, "body");
|
|
1463
|
+
const rows = await db.all(`SELECT run_id, ${d.jsonText(body, ["replay", "deadline_at"])} AS replay, ${d.jsonText(body, ["audit", "deadline_at"])} AS audit FROM run_launch WHERE run_id IN (${runIds.map(() => "?").join(", ")})`, ...runIds);
|
|
1464
|
+
for (const row of rows) {
|
|
1465
|
+
const at = Date.parse(row.replay ?? row.audit ?? "");
|
|
1466
|
+
if (Number.isFinite(at))
|
|
1467
|
+
out.set(row.run_id, at);
|
|
1468
|
+
}
|
|
1469
|
+
return out;
|
|
1470
|
+
},
|
|
1448
1471
|
usageMetadata: (runId, options) => readUsageMetadata(db, runId, options),
|
|
1449
1472
|
projectCheckpoints: (filter) => readProjectCheckpoints(db, filter),
|
|
1450
1473
|
learningStarts: (agentId) => readLearningStarts(db, agentId, NOT_A_LEARNING_RUN),
|
|
@@ -1675,7 +1698,8 @@ class SqliteStore {
|
|
|
1675
1698
|
}
|
|
1676
1699
|
// Its ledger row and every spend row it booked or that audits it, as a remove takes them: what it cost stays on its
|
|
1677
1700
|
// tombstone (cost_usd, the metrics' figures), which the readers of money (usage, stats) read; no series shows it.
|
|
1678
|
-
|
|
1701
|
+
// What it booked on another run's account stays that run's, its figure alone (dropLedger `purge`).
|
|
1702
|
+
await dropLedger(tx, runId, { purge: true });
|
|
1679
1703
|
// Its row's content, its metrics cut to their figures and names (tombstoneMetrics), with what its spend's readers
|
|
1680
1704
|
// read from its journal folded in. Its outcome stays: a code (RunOutcome), never words.
|
|
1681
1705
|
const metrics = tombstoneMetrics(run.metrics === null ? null : JSON.parse(run.metrics), kept);
|
package/dist/store/store.d.ts
CHANGED
|
@@ -1304,6 +1304,11 @@ export interface Runs {
|
|
|
1304
1304
|
/** The run's launch row (the runner reads it at its claim; the server for views). StoreLaunchMissing when the run has
|
|
1305
1305
|
* none (it was not started with one), never a default. */
|
|
1306
1306
|
launch(runId: string): Promise<RunLaunchRow>;
|
|
1307
|
+
/** The learning deadlines (ms) of those of `runIds` that are learning children (a check's replay run, an audit's shadow
|
|
1308
|
+
* run): its launch's replay or audit `deadline_at` (run-launch.ts Replay.deadlineAt). One read for every id, projecting
|
|
1309
|
+
* that member alone: what a runner reads for a whole batch of claims before any loop starts on them. A run that is no
|
|
1310
|
+
* learning child, or has no launch row, is absent. */
|
|
1311
|
+
learningDeadlines(runIds: readonly string[]): Promise<Map<string, number>>;
|
|
1307
1312
|
/** Only the immutable CLI accounting identity/turn and (when requested) SDK completion usage. Projects these JSON
|
|
1308
1313
|
* members in the database: no launch input, policy, sealed bytes, completion answer or replay events are returned.
|
|
1309
1314
|
* Undefined for an absent run; absent members stay undefined. Historical identity may be read without completion.
|
|
@@ -7,6 +7,8 @@ import type { Store } from "../store/store.js";
|
|
|
7
7
|
/** A run's entries from the one store, in log order (by id across every conversation), as the old "SELECT record FROM
|
|
8
8
|
* entries ORDER BY id" read them for a settled run. A run with no journal reads as none. */
|
|
9
9
|
export declare function runEntries(store: Store, runId: string, context: Context): Promise<EntryLike[]>;
|
|
10
|
+
/** `entries` (a journal read's, conversation by conversation) in log order: by id across every conversation. */
|
|
11
|
+
export declare const inLogOrder: (entries: readonly unknown[]) => EntryLike[];
|
|
10
12
|
/** Where a run's end-of-run turn is in its journal, as the server's Reflect names it for labelled(): its newest round's
|
|
11
13
|
* `after`, the entry before its input, and `until`, the run's end entry once written; `earlier`, each earlier round's (a
|
|
12
14
|
* follow-up opened the run again after it). Undefined for a run that asked none. */
|
|
@@ -25,7 +25,7 @@ export async function runEntries(store, runId, context) {
|
|
|
25
25
|
return inLogOrder(await journalEntries(store.readJournal(runId), context));
|
|
26
26
|
}
|
|
27
27
|
/** `entries` (a journal read's, conversation by conversation) in log order: by id across every conversation. */
|
|
28
|
-
const inLogOrder = (entries) => entries.slice().sort((a, b) => Number(a.id ?? 0) - Number(b.id ?? 0));
|
|
28
|
+
export const inLogOrder = (entries) => entries.slice().sort((a, b) => Number(a.id ?? 0) - Number(b.id ?? 0));
|
|
29
29
|
/** Where a run's end-of-run turn is in its journal, as the server's Reflect names it for labelled(): its newest round's
|
|
30
30
|
* `after`, the entry before its input, and `until`, the run's end entry once written; `earlier`, each earlier round's (a
|
|
31
31
|
* follow-up opened the run again after it). Undefined for a run that asked none. */
|
|
@@ -105,13 +105,14 @@ export declare function revisionsOf(records: readonly PromotionRecord[], reset?:
|
|
|
105
105
|
/** A run's costs as GET /runs/{id} shows them (RunAllIn, runAllInOverStore). */
|
|
106
106
|
export type RunAllIn = {
|
|
107
107
|
path: RunPath | null;
|
|
108
|
-
} & Pick<RunFigures, "usd" | "learning_usd" | "all_in_usd" | "compile_usd" | "followup_usd" | "shadow_usd" | "share_usd">;
|
|
108
|
+
} & Pick<RunFigures, "usd" | "learning_usd" | "all_in_usd" | "compile_usd" | "followup_usd" | "shadow_usd" | "check_usd" | "share_usd">;
|
|
109
109
|
/** Run `runId`'s path and its costs as GET /runs/{id} shows them (A8), the figures GET .../learning/cost reads for it
|
|
110
110
|
* (learn/ledger.ts figuresOf over its ledger row: one formula): `path` its record's (metrics.path, RUN_PATHS: `agent`
|
|
111
111
|
* for a run that does not learn; null while it has not ended, for a workflow revision's run, and for a run that learns
|
|
112
112
|
* whose end named none); `usd` its own spend, the job's (its look-back left out); `learning_usd` what learning spent for
|
|
113
|
-
* it: its follow-up rounds' turns, its audit shadow's cost,
|
|
114
|
-
*
|
|
113
|
+
* it: its follow-up rounds' turns, its audit shadow's cost, the replays of a check it started on its own model key
|
|
114
|
+
* (`check_usd`, null while one runs), and its share of its revision's compile and check (its own compile turns are its
|
|
115
|
+
* revision's: `compile_usd`); `all_in_usd` the two; and `learning_usd`'s parts. A replay or a
|
|
115
116
|
* shadow run carries none: its spend is on the runs it serves, so its `learning_usd` and `all_in_usd` are 0, and the sum
|
|
116
117
|
* of every run's `all_in_usd` and the bill's `unattributed_usd` is the booked total. `rowUsd`: the cost its view reads
|
|
117
118
|
* (its row's when absent); one other than its row's (an imported run's estimate, a booking where its end stored none)
|