@parcha/agentrun-serve 0.1.0-beta.55 → 0.1.0-beta.56

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 (80) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/README.md +44 -10
  3. package/dist/adapters.d.ts +3 -2
  4. package/dist/adapters.js +6 -3
  5. package/dist/answer-json.d.ts +6 -2
  6. package/dist/answer-json.js +22 -4
  7. package/dist/api-only.js +2 -0
  8. package/dist/calendar/tools.js +3 -2
  9. package/dist/chatgpt-plan.d.ts +16 -1
  10. package/dist/chatgpt-plan.js +116 -12
  11. package/dist/claude-login.d.ts +34 -5
  12. package/dist/claude-login.js +31 -7
  13. package/dist/claude-sign-in.d.ts +35 -0
  14. package/dist/claude-sign-in.js +90 -0
  15. package/dist/console/assets/{backend-D5EmB4N3.js → backend-Boh7tC4i.js} +1 -1
  16. package/dist/console/assets/{index-DUYLaqiR.js → index-CQ3cJRzI.js} +130 -130
  17. package/dist/console/assets/index-DKkaS3a0.css +1 -0
  18. package/dist/console/index.html +2 -2
  19. package/dist/host-check.d.ts +4 -0
  20. package/dist/host-check.js +4 -0
  21. package/dist/key-refusal.d.ts +21 -5
  22. package/dist/key-refusal.js +231 -37
  23. package/dist/learn/secrets.d.ts +20 -10
  24. package/dist/learn/secrets.js +44 -184
  25. package/dist/llms.txt +1 -1
  26. package/dist/openapi.d.ts +3 -3
  27. package/dist/openapi.js +70 -18
  28. package/dist/place-offers.d.ts +14 -6
  29. package/dist/place-offers.js +26 -13
  30. package/dist/redact/match.d.ts +74 -0
  31. package/dist/redact/match.js +771 -0
  32. package/dist/run-timeline-served.d.ts +1 -1
  33. package/dist/run-timeline-served.js +4 -4
  34. package/dist/runner/adapter-loop.d.ts +3 -0
  35. package/dist/runner/adapter-loop.js +1 -1
  36. package/dist/runner/adapter-run-spec.js +4 -1
  37. package/dist/runner/beside.js +7 -3
  38. package/dist/runner/cli-run-spec.js +3 -1
  39. package/dist/runner/loop-contract.d.ts +4 -0
  40. package/dist/runner/main.js +8 -4
  41. package/dist/runner/presence.d.ts +4 -3
  42. package/dist/runner/presence.js +4 -2
  43. package/dist/runner/run-child-host.d.ts +2 -0
  44. package/dist/runner/run-child-host.js +2 -2
  45. package/dist/runner/runner.d.ts +4 -0
  46. package/dist/runner/runner.js +33 -3
  47. package/dist/server.d.ts +5 -2
  48. package/dist/server.js +41 -10
  49. package/dist/store/dialect.d.ts +3 -0
  50. package/dist/store/dialect.js +1 -0
  51. package/dist/store/index.d.ts +1 -1
  52. package/dist/store/index.js +1 -1
  53. package/dist/store/postgres/dialect.js +3 -0
  54. package/dist/store/sqlite/store.js +43 -13
  55. package/dist/store/store.d.ts +10 -1
  56. package/dist/store/store.js +7 -0
  57. package/dist/store-view.js +1 -1
  58. package/dist/template-eval.d.ts +2 -2
  59. package/dist/template-eval.js +9 -8
  60. package/dist/timeline/index.d.ts +1 -1
  61. package/dist/timeline/index.js +1 -1
  62. package/dist/timeline/timeline.d.ts +12 -7
  63. package/dist/timeline/timeline.js +14 -6
  64. package/dist/tool-gate.js +3 -1
  65. package/dist/validate.js +1 -1
  66. package/dist/workspace/computer-deps.d.ts +2 -1
  67. package/dist/workspace/computer-deps.js +5 -4
  68. package/dist/workspace/computer-for-claim.d.ts +8 -2
  69. package/dist/workspace/computer-for-claim.js +28 -9
  70. package/dist/workspace/computer-janitor.d.ts +15 -7
  71. package/dist/workspace/computer-janitor.js +33 -8
  72. package/dist/workspace/computer-kept.d.ts +52 -4
  73. package/dist/workspace/computer-kept.js +118 -6
  74. package/dist/workspace/run-end-computers.d.ts +5 -1
  75. package/dist/workspace/run-end-computers.js +27 -1
  76. package/dist/wrapped.d.ts +57 -0
  77. package/dist/wrapped.js +51 -0
  78. package/package.json +11 -11
  79. package/templates/README.md +8 -7
  80. package/dist/console/assets/index-DYhU4adm.css +0 -1
@@ -1,8 +1,9 @@
1
+ import { type Span } from "../redact/match.js";
1
2
  /** Whether `text` ends in a `Bearer` scheme and the blanks after it: the one place a shape is read across whitespace
2
3
  * (the scheme, then its token), so a reader that cuts a text at whitespace must not cut there (key-refusal.ts
3
4
  * redactedAnswer). */
4
5
  export declare const endsInScheme: (text: string) => boolean;
5
- /** The kinds of secret-shaped text in `text`. */
6
+ /** The kinds of secret-shaped text in `text` (redact/match.ts SECRET_SHAPES). */
6
7
  export declare const secretShapes: (text: string) => string[];
7
8
  /** The kinds of text in `text` learning never keeps: every secret shape, and a bank's numbers beside their words. */
8
9
  export declare const learnedSecretShapes: (text: string) => string[];
@@ -14,18 +15,28 @@ export declare const PRINT_MAX = 4096;
14
15
  * any case, base64, a hex identifier in it folded) and each secret-shaped run replaced by "[redacted]": what the
15
16
  * checker prints never holds a secret, wherever it was found, a file's name included, each value as a path names it too
16
17
  * (pathSpellings) and as a URL's path writes it (percentForms). Every form is found in `text` as given, and overlapping
17
- * finds are redacted as one, so
18
- * one value never hides part of another from the search. A text
19
- * that still holds a value or a shape after that (a form not found as it stands: percent encoded, split by whitespace,
20
- * an NFKC variant), or that is over `max` bytes (PRINT_MAX unless the caller names more), is redacted whole, never in
21
- * part. The folded finds only ever add to that: the whole-text check is first made with them left in (a value split by
22
- * a line break is still seen whole, never hidden by its hex part cut alone), and the fold-aware one always after, on
23
- * what is left (a folded value split by whitespace or percent-encoded is found there, never handed back). */
18
+ * finds are redacted as one, so one value never hides part of another from the search. A text that holds a value in a
19
+ * form not found as it stands (percent encoded, split by whitespace, an NFKC variant), read in `text` as given, is
20
+ * redacted whole, never in part, unless every character of it is inside what the finds cut: a cut can hide part of a
21
+ * value, so the rest is looked for before the cut (redact/match.ts planCut). So is a text over `max` bytes (PRINT_MAX
22
+ * unless the caller names more), and one whose cut leaves a value or a shape. */
24
23
  export declare function redactSecrets(text: string, values: readonly string[], max?: number): string;
25
24
  /** `text` as redactSecrets cuts it, and of a bank's numbers beside their words too (MONEY_SHAPES): what learning prints
26
25
  * and serves of what it learned or refused (a problem's path and detail, a note read), never a run's own view, which
27
26
  * may show its user an account number. */
28
27
  export declare function redactLearned(text: string, values: readonly string[], max?: number): string;
28
+ /** redactSecrets, and where it cut: the spans of `text` cut in place and the text so cut, or "whole" where redactSecrets
29
+ * answers "[redacted]". A reader that redacts a text in pieces (key-refusal.ts) reads the pieces as they came for a
30
+ * value split across them (valueLeft), each piece's cuts covering it. */
31
+ export declare function cutSecrets(text: string, values: readonly string[], max?: number): {
32
+ spans: Span[];
33
+ out: string;
34
+ } | "whole";
35
+ /** Whether `text` holds one of `values` in a form valueMatcher finds, a character of which no cut covers: what
36
+ * a reader that cut `text` there would still show of it. The cuts are `cuts` (merged spans of `text`, in order: where a
37
+ * reader that cut it in pieces cut each), or else those redactSecrets makes of `text` whole (its values' forms, hexes
38
+ * and folded identifiers, and the secret shapes, found as they stand). */
39
+ export declare function valueLeft(text: string, values: readonly string[], cuts?: readonly Span[]): boolean;
29
40
  /** A value shorter than this matches too much text by chance to be refused. */
30
41
  export declare const MIN_SECRET = 8;
31
42
  /** An excerpt of a run's input or answer as learning keeps it: `text` cut of the secrets `shown` knows, whole, then
@@ -38,8 +49,7 @@ export declare function excerptShown(text: string, shown: {
38
49
  }, max: number): string;
39
50
  /** A matcher for `values` in a text: plain, split by whitespace, as JSON writes it, percent or form encoded, base64 or
40
51
  * hex, and each hex identifier in a value folded: in any case, its separators dropped or moved (foldedOf). Values
41
- * shorter than MIN_SECRET are left out. `fold: false`, the matcher without the folded needles (redactSecrets' first
42
- * whole-text check). */
52
+ * shorter than MIN_SECRET are left out. `fold: false`, the matcher without the folded needles. */
43
53
  export declare function valueMatcher(values: readonly string[], { fold }?: {
44
54
  fold?: boolean;
45
55
  }): (text: string) => boolean;
@@ -1,60 +1,5 @@
1
1
  import { posix } from "node:path";
2
- const SK_KEY = /(?<![A-Za-z0-9])sk-[A-Za-z0-9_-]{20,}/;
3
- const SLACK_TOKEN = /xox[abposre]-[A-Za-z0-9-]{10,}|xapp-[A-Za-z0-9-]{10,}/;
4
- const GITHUB_TOKEN = /gh[pousr]_[A-Za-z0-9]{30,}|github_pat_[A-Za-z0-9_]{20,}/;
5
- /** A JWT: three base64url parts, the first two JSON objects ("eyJ"). It starts at the first "eyJ" of a run of a part's
6
- * characters, wherever that run starts ("token-eyJ…" too), and not at a later "eyJ" in the same run: read from every
7
- * "eyJ", a long dotless run was read to its end from each, quadratic in its length (180 s over 256 KiB of "eyJ"). A
8
- * later start reaches the same "." the first does with fewer characters, so it finds nothing the first doesn't, and
9
- * the lookbehind reads back only to the "eyJ" before it. */
10
- const JWT = /eyJ(?<!eyJ[A-Za-z0-9_-]*?eyJ)[A-Za-z0-9_-]{8,}\.eyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}/;
11
- /** A private key block's header, its key type (RSA, EC, OPENSSH, ENCRYPTED) at most 64 characters each side: two
12
- * unbounded runs read a long header of repeated words in quadratic time (24 s over 256 KiB of "PRIVATE KEY "). */
13
- const PRIVATE_KEY = /-----BEGIN[ A-Z0-9]{0,64}PRIVATE KEY[ A-Z0-9]{0,64}-----/;
14
- /** A Standard Webhooks signing secret: `whsec_` and base64, this server's or any other's. */
15
- const WEBHOOK_SECRET = /whsec_[A-Za-z0-9+/]{24,}={0,2}/;
16
- /** The token after a `Bearer` scheme (RFC 6750's characters), in any case: twenty characters or more with a digit among
17
- * them, so a word after "bearer" ("bearer authentication/authorization"), a placeholder (`<token>`, `$TOKEN`,
18
- * `YOUR_API_KEY`) and a challenge's parameter (`Bearer realm="x"`) are none. The token alone is the match: the scheme
19
- * before it stays, so a reader still sees a header was there. The scheme is at most three blanks before the token, and
20
- * the digit is looked for only through the token's own characters, so the reading stays linear. */
21
- const BEARER_TOKEN = /(?<=\bBearer\s{1,3})(?=[A-Za-z._~+/-]*\d)[A-Za-z0-9._~+/-]{20,}={0,2}/i;
22
- /** The value of a URL parameter named like a credential, after `?` or `&`: sixteen characters or more, to the next
23
- * separator. The name is the whole parameter's (`token`, never `page_token`), and the value alone is the match, so the
24
- * name stays. A signed URL's signature is one: whoever holds the URL holds what it grants. No bracket is a value's
25
- * character (a URL writes one percent-encoded), so a value already cut to "[redacted]" is never read as one. */
26
- const URL_CREDENTIAL = /(?<=[?&](?:api[_-]?key|access[_-]?token|auth[_-]?token|id[_-]?token|refresh[_-]?token|client[_-]?secret|x-amz-signature|x-amz-security-token|x-goog-signature|token|secret|password|passwd|signature|sig)=)[^\s&#"'`<>\\[\]]{16,}/i;
27
- const URL_PASSWORD = /:\/\/[^\s/?#@:]+:[^\s/?#@]*@/;
28
- /** A complete, single-quoted sed search expression whose password is only a capture pattern.
29
- * The @ inside [^@] is regex syntax, not a password terminator. Require the closing capture,
30
- * substitution/backreference and quote too; bracketed passwords or bare URLs are never exempt. */
31
- const SED_URL_CAPTURE = /(?:^|[\s;(])sed[ \t]+-n[ \t]+'s\|https?:\/\/(?:[A-Za-z0-9._~-]+|\[\^:\]\*):\\\(\[\^@\]\*\\\)@[A-Za-z0-9.-]+\|\\1\|p'/g;
32
- /** A bank account number beside its word: "account", "acct", "a/c" or "bank account", maybe "number", "no.", "#", ":"
33
- * or "is" after it, then six digits or more, single dashes or spaces between them. A count before the word ("4
34
- * accounts"), a date (YYYY-MM-DD), a year or a card's last four is none: the word must come first, the digits right
35
- * after it, and there must be six. Every gap is at most three whitespace characters, so the reading stays linear on a
36
- * text of long blank runs. */
37
- const ACCOUNT_NUMBER = /\b(?:bank\s{1,3})?(?:account|acct|a\/c)(?:\s{1,3}(?:number|no\.?|num))?\s{0,3}(?:#|:|\bis\b)?\s{0,3}(?!\d{4}-\d{2}-\d{2}\b)\d(?:[ -]?\d){5,}/i;
38
- /** An IBAN beside its word: two letters, two check digits, then ten to thirty letters or digits, spaces between. */
39
- const IBAN = /\bIBAN\s{0,3}(?:#|:|\bis\b)?\s{0,3}[A-Z]{2}\d{2}(?:\s?[A-Z0-9]){10,30}/i;
40
- /** A US routing (ABA) number beside its word: nine digits. */
41
- const ROUTING_NUMBER = /\b(?:routing|ABA)(?:\s{1,3}(?:number|no\.?|num))?\s{0,3}(?:#|:|\bis\b)?\s{0,3}\d{9}\b/i;
42
- /** A UK sort code beside its word: three pairs of digits. */
43
- const SORT_CODE = /\bsort\s{1,3}code\s{0,3}(?:#|:|\bis\b)?\s{0,3}\d{2}[- ]?\d{2}[- ]?\d{2}\b/i;
44
- /** Text shaped like a secret, by kind. The same shapes the Pi learning loop's guard refuses. */
45
- const SHAPES = [
46
- ["AWS access key id", /(?:AKIA|ASIA)[0-9A-Z]{16}/],
47
- ["Google API key", /AIza[0-9A-Za-z_-]{35}/],
48
- ["private key block", PRIVATE_KEY],
49
- ["GitHub token", GITHUB_TOKEN],
50
- ["sk- key", SK_KEY],
51
- ["Slack token", SLACK_TOKEN],
52
- ["JWT", JWT],
53
- ["webhook signing secret", WEBHOOK_SECRET],
54
- ["URL with a password", URL_PASSWORD],
55
- ["bearer token", BEARER_TOKEN],
56
- ["URL parameter named like a credential", URL_CREDENTIAL],
57
- ];
2
+ import { cutSpans, holds, MONEY_SHAPES, planCut, SECRET_SHAPES, shapeKinds } from "../redact/match.js";
58
3
  /** Whether `text` ends in a `Bearer` scheme and the blanks after it: the one place a shape is read across whitespace
59
4
  * (the scheme, then its token), so a reader that cuts a text at whitespace must not cut there (key-refusal.ts
60
5
  * redactedAnswer). */
@@ -62,65 +7,12 @@ export const endsInScheme = (text) => {
62
7
  const head = text.trimEnd();
63
8
  return head.length < text.length && text.length - head.length <= 3 && /\bBearer$/i.test(head.slice(-7));
64
9
  };
65
- /** The kinds of secret-shaped text in `text`. */
66
- export const secretShapes = (text) => SHAPES.filter(([, pattern]) => pattern === URL_PASSWORD ? spans(text, pattern).length > 0 : pattern.test(text)).map(([kind]) => kind);
67
- /** A bank's numbers beside their words, which learning never keeps: an account, IBAN, routing or sort-code number. Not
68
- * one of SHAPES: a run may show its user an account number (a finance job's answer), and SHAPES cut every run's view;
69
- * only what learning keeps refuses them (LS-09: graders held "send refunds to account 4471-0098" for the owner's OK,
70
- * which would have served it). */
71
- const MONEY_SHAPES = [
72
- ["bank account number", ACCOUNT_NUMBER],
73
- ["IBAN", IBAN],
74
- ["routing number", ROUTING_NUMBER],
75
- ["sort code", SORT_CODE],
76
- ];
10
+ /** The kinds of secret-shaped text in `text` (redact/match.ts SECRET_SHAPES). */
11
+ export const secretShapes = (text) => shapeKinds(text, SECRET_SHAPES);
12
+ /** Every secret shape, then a bank's numbers beside their words (MONEY_SHAPES): what learning never keeps. */
13
+ const LEARNED_SHAPES = [...SECRET_SHAPES, ...MONEY_SHAPES];
77
14
  /** The kinds of text in `text` learning never keeps: every secret shape, and a bank's numbers beside their words. */
78
- export const learnedSecretShapes = (text) => [...secretShapes(text), ...MONEY_SHAPES.filter(([, pattern]) => pattern.test(text)).map(([kind]) => kind)];
79
- /** Every place `pattern` matches in `text`, overlapping places included. */
80
- function spans(text, pattern) {
81
- const re = new RegExp(pattern.source, `${pattern.flags.replace("g", "")}g`);
82
- const out = [];
83
- const expressions = pattern === URL_PASSWORD ? [...text.matchAll(SED_URL_CAPTURE)].map(match => [match.index, match.index + match[0].length]) : [];
84
- let expression = 0;
85
- const next = RESUME.get(pattern) ?? ((m) => m.index + 1);
86
- for (let m = re.exec(text); m; m = re.exec(text)) {
87
- while (expression < expressions.length && expressions[expression][1] <= m.index)
88
- expression++;
89
- const range = expressions[expression];
90
- if (!range || m.index < range[0] || m.index + m[0].length > range[1])
91
- out.push([m.index, m.index + m[0].length]);
92
- re.lastIndex = Math.max(m.index + 1, next(m));
93
- }
94
- return out;
95
- }
96
- const toEnd = (m) => m.index + m[0].length;
97
- /** Where spans() reads on after a match, by shape: past each place inside it where a match would end where it ends, as
98
- * such a match adds nothing to what is redacted. A shape not here reads on from the next character. Without it, a run
99
- * that repeats a shape's start ("sk-sk-sk-…", "github_pat_github_pat_…", a JWT's first part "eyJeyJ…") is read again
100
- * from every repeat.
101
- * - sk- and Slack: a prefix and one greedy run of a class holding the prefix's characters, so a match inside ends at
102
- * the same end.
103
- * - GitHub: the same for github_pat_. A ghp_ run's class has no "_", and a github_pat_ can start in its last characters
104
- * and run past it, so it reads on from the next character.
105
- * - JWT: a match that starts in the first part reads on through the same second and third parts, so it ends where this
106
- * one does; one that starts in the second part can run past it, into a fourth. It reads on from the second part.
107
- * - A URL's credential: its value runs to the next separator and may hold "?" and "=", so a parameter of the same
108
- * name inside it ("?token=a?token=a…") starts a match that runs to the same end.
109
- * - whsec_: not here. Its run's class has no "_", so a run takes the next secret's "whsec" and stops at its "_": that
110
- * secret starts inside this match and runs past it, and is found only by reading on from the next character. */
111
- const RESUME = new Map([
112
- [SK_KEY, toEnd],
113
- [SLACK_TOKEN, toEnd],
114
- [GITHUB_TOKEN, (m) => (m[0].startsWith("github_pat_") ? toEnd(m) : m.index + 1)],
115
- [JWT, (m) => m.index + m[0].indexOf(".") + 1],
116
- [URL_CREDENTIAL, toEnd],
117
- ]);
118
- function places(text, form) {
119
- const out = [];
120
- for (let at = text.indexOf(form); at >= 0; at = text.indexOf(form, at + 1))
121
- out.push([at, at + form.length]);
122
- return out;
123
- }
15
+ export const learnedSecretShapes = (text) => shapeKinds(text, LEARNED_SHAPES);
124
16
  /** The longest field `redactSecrets` reads, in UTF-8 bytes, unless its caller names another bound. A longer one is printed
125
17
  * whole as "[redacted]", never scanned: no field the checker prints is that long in good faith, and a crafted one (a
126
18
  * long path) costs no scan. */
@@ -129,47 +21,51 @@ export const PRINT_MAX = 4096;
129
21
  * any case, base64, a hex identifier in it folded) and each secret-shaped run replaced by "[redacted]": what the
130
22
  * checker prints never holds a secret, wherever it was found, a file's name included, each value as a path names it too
131
23
  * (pathSpellings) and as a URL's path writes it (percentForms). Every form is found in `text` as given, and overlapping
132
- * finds are redacted as one, so
133
- * one value never hides part of another from the search. A text
134
- * that still holds a value or a shape after that (a form not found as it stands: percent encoded, split by whitespace,
135
- * an NFKC variant), or that is over `max` bytes (PRINT_MAX unless the caller names more), is redacted whole, never in
136
- * part. The folded finds only ever add to that: the whole-text check is first made with them left in (a value split by
137
- * a line break is still seen whole, never hidden by its hex part cut alone), and the fold-aware one always after, on
138
- * what is left (a folded value split by whitespace or percent-encoded is found there, never handed back). */
24
+ * finds are redacted as one, so one value never hides part of another from the search. A text that holds a value in a
25
+ * form not found as it stands (percent encoded, split by whitespace, an NFKC variant), read in `text` as given, is
26
+ * redacted whole, never in part, unless every character of it is inside what the finds cut: a cut can hide part of a
27
+ * value, so the rest is looked for before the cut (redact/match.ts planCut). So is a text over `max` bytes (PRINT_MAX
28
+ * unless the caller names more), and one whose cut leaves a value or a shape. */
139
29
  export function redactSecrets(text, values, max = PRINT_MAX) {
140
- return redactWith(text, values, max, SHAPES, secretShapes);
30
+ return redactWith(text, values, max, SECRET_SHAPES);
141
31
  }
142
32
  /** `text` as redactSecrets cuts it, and of a bank's numbers beside their words too (MONEY_SHAPES): what learning prints
143
33
  * and serves of what it learned or refused (a problem's path and detail, a note read), never a run's own view, which
144
34
  * may show its user an account number. */
145
35
  export function redactLearned(text, values, max = PRINT_MAX) {
146
- return redactWith(text, values, max, [...SHAPES, ...MONEY_SHAPES], learnedSecretShapes);
36
+ return redactWith(text, values, max, LEARNED_SHAPES);
147
37
  }
148
- /** redactSecrets over `shapes`, each found in place, and `shapesOf` read of what is left (a shape still there cuts the
149
- * text whole). */
150
- function redactWith(text, values, max, shapes, shapesOf) {
38
+ /** redactSecrets, and where it cut: the spans of `text` cut in place and the text so cut, or "whole" where redactSecrets
39
+ * answers "[redacted]". A reader that redacts a text in pieces (key-refusal.ts) reads the pieces as they came for a
40
+ * value split across them (valueLeft), each piece's cuts covering it. */
41
+ export function cutSecrets(text, values, max = PRINT_MAX) {
42
+ if (Buffer.byteLength(text) > max)
43
+ return "whole";
44
+ return planCut(text, derivedOf(values), SECRET_SHAPES);
45
+ }
46
+ /** Whether `text` holds one of `values` in a form valueMatcher finds, a character of which no cut covers: what
47
+ * a reader that cut `text` there would still show of it. The cuts are `cuts` (merged spans of `text`, in order: where a
48
+ * reader that cut it in pieces cut each), or else those redactSecrets makes of `text` whole (its values' forms, hexes
49
+ * and folded identifiers, and the secret shapes, found as they stand). */
50
+ export function valueLeft(text, values, cuts) {
51
+ const needles = derivedOf(values);
52
+ return holds(text, needles, { cuts: cuts ?? cutSpans(text, needles, SECRET_SHAPES) });
53
+ }
54
+ /** redactSecrets over `shapes`, each found in place (redact/match.ts planCut). */
55
+ function redactWith(text, values, max, shapes) {
151
56
  if (Buffer.byteLength(text) > max)
152
57
  return "[redacted]";
153
- const { forms, hexes, folds: foldPatterns, matchUnfolded, match } = derivedOf(values);
154
- const found = [
155
- ...forms.flatMap((form) => places(text, form)),
156
- ...hexes.flatMap((hex) => spans(text, hex)),
157
- ...shapes.flatMap(([, pattern]) => spans(text, pattern)),
158
- ];
159
- const unfolded = cutAt(text, found);
160
- if (matchUnfolded(unfolded) || shapesOf(unfolded).length > 0)
161
- return "[redacted]";
162
- // Then the folded finds cut in place, and the fold-aware check over what is left, always: a folded value split by
163
- // whitespace or percent-encoded has no span here, but the matcher's squeezed and decoded views still see it.
164
- const folds = foldPatterns.flatMap((pattern) => spans(text, pattern));
165
- const out = folds.length ? cutAt(text, [...found, ...folds]) : unfolded;
166
- return match(out) || shapesOf(out).length > 0 ? "[redacted]" : out;
58
+ const cut = planCut(text, derivedOf(values), shapes);
59
+ return cut === "whole" ? "[redacted]" : cut.out;
167
60
  }
168
- /** Each value set's Derived, by the array a caller passes, with a copy of the values it was derived of. A run's view
61
+ /** Each value set's Needles, by the array a caller passes, with a copy of the values it was derived of. A run's view
169
62
  * redacts every row of its timeline with one array, and deriving it again for each row (path spellings, base64 at three
170
- * alignments, percent forms, folded patterns, for every value, a private key's PEM among them) took seconds per view.
63
+ * alignments, percent forms, folded needles, for every value, a private key's PEM among them) took seconds per view.
171
64
  * An array whose values changed since is derived again, never served a stale set: what a caller adds is always cut. */
172
65
  const DERIVED = new WeakMap();
66
+ /** What the matcher looks for of a set of values, whatever the text: each value and its path spellings, its forms found
67
+ * as they stand (as written, as JSON writes it, its plain needles and percent forms), its hex and folded needles, and
68
+ * the needles the whole-text check reads (redact/match.ts Needles). */
173
69
  function derivedOf(values) {
174
70
  const kept = DERIVED.get(values);
175
71
  if (kept && kept.values.length === values.length && kept.values.every((value, at) => value === values[at]))
@@ -181,32 +77,13 @@ function derivedOf(values) {
181
77
  const of = needles.get(v);
182
78
  return [v, asJson(v), ...(of ? [...of.plain, ...percentForms(v)] : [])];
183
79
  }).filter((form) => form.length > 0))],
184
- hexes: [...needles.values()].map((of) => new RegExp(of.hex, "i")),
185
- folds: [...needles.values()].flatMap((of) => of.folded.map(foldedPattern)),
186
- matchUnfolded: spelledMatcher(given, false),
187
- match: spelledMatcher(given),
80
+ hexes: [...needles.values()].map((of) => of.hex),
81
+ folds: [...needles.values()].flatMap((of) => of.folded),
82
+ plain: [...new Set([...needles.values()].flatMap((of) => of.plain))],
188
83
  };
189
84
  DERIVED.set(values, { values: [...values], derived });
190
85
  return derived;
191
86
  }
192
- /** `text` with each of `found` replaced by "[redacted]", overlapping ones as one. */
193
- function cutAt(text, found) {
194
- const merged = [];
195
- for (const [start, end] of [...found].sort((a, b) => a[0] - b[0])) {
196
- const last = merged.at(-1);
197
- if (last && start <= last[1])
198
- last[1] = Math.max(last[1], end);
199
- else
200
- merged.push([start, end]);
201
- }
202
- let out = "";
203
- let from = 0;
204
- for (const [start, end] of merged) {
205
- out += `${text.slice(from, start)}[redacted]`;
206
- from = end;
207
- }
208
- return out + text.slice(from);
209
- }
210
87
  /** A value shorter than this matches too much text by chance to be refused. */
211
88
  export const MIN_SECRET = 8;
212
89
  /** An excerpt of a run's input or answer as learning keeps it: `text` cut of the secrets `shown` knows, whole, then
@@ -234,9 +111,6 @@ function base64Needles(secret) {
234
111
  }
235
112
  return [...out];
236
113
  }
237
- function percentDecode(text, plusIsSpace) {
238
- return (plusIsSpace ? text.replaceAll("+", " ") : text).replace(/(?:%[0-9a-fA-F]{2})+/g, (run) => Buffer.from(run.replaceAll("%", ""), "hex").toString("utf8"));
239
- }
240
114
  const asJson = (value) => JSON.stringify(value).slice(1, -1);
241
115
  /** A path with each run of "/" collapsed to one, each "." segment dropped ("/./", a leading "./") and a leading and a
242
116
  * trailing "/" dropped, as a resolver writes it. */
@@ -308,8 +182,6 @@ function foldedOf(value) {
308
182
  }
309
183
  return [...out];
310
184
  }
311
- /** A folded needle as it stands in a text: its hex digits in order, in any case, a separator allowed between any two. */
312
- const foldedPattern = (needle) => new RegExp([...needle].join("[-_:.]?"), "i");
313
185
  /** What a matcher looks for of `value`: its forms as they stand in a squeezed text (plain, as JSON writes it, base64 or
314
186
  * base64url), its hex, in any case, and its hex identifiers folded (foldedOf). */
315
187
  function needlesOf(value) {
@@ -319,20 +191,8 @@ function needlesOf(value) {
319
191
  const longEnough = (value) => [...value].length >= MIN_SECRET;
320
192
  /** A matcher for `values` in a text: plain, split by whitespace, as JSON writes it, percent or form encoded, base64 or
321
193
  * hex, and each hex identifier in a value folded: in any case, its separators dropped or moved (foldedOf). Values
322
- * shorter than MIN_SECRET are left out. `fold: false`, the matcher without the folded needles (redactSecrets' first
323
- * whole-text check). */
194
+ * shorter than MIN_SECRET are left out. `fold: false`, the matcher without the folded needles. */
324
195
  export function valueMatcher(values, { fold = true } = {}) {
325
- return spelledMatcher(withPathSpellings(values), fold);
326
- }
327
- /** valueMatcher over values already given with their path spellings (redactSecrets'), each spelled once. */
328
- function spelledMatcher(spelled, fold = true) {
329
- const needles = spelled.filter(longEnough).map(needlesOf).map((n) => (fold ? n : { ...n, folded: [] }));
330
- if (!needles.length)
331
- return () => false;
332
- return (text) => {
333
- const views = [...new Set([squeeze(text), squeeze(percentDecode(text, false)), squeeze(percentDecode(text, true))])];
334
- const lower = views.map((view) => view.toLowerCase());
335
- const flat = needles.some((n) => n.folded.length) ? views.map(folded) : [];
336
- return needles.some((n) => views.some((view) => n.plain.some((needle) => view.includes(needle))) || lower.some((view) => view.includes(n.hex)) || n.folded.some((needle) => flat.some((view) => view.includes(needle))));
337
- };
196
+ const needles = derivedOf(values);
197
+ return (text) => holds(text, needles, { fold });
338
198
  }
package/dist/llms.txt CHANGED
@@ -15,7 +15,7 @@ Auth: the API's routes take `Authorization: Bearer <token>`, all but `GET /v2/he
15
15
  - [OpenAPI document](/v2/openapi.json): every route and schema, the `agentrun.v2/0` contract with this server's own routes marked `x-agentrun-serve`.
16
16
  - [Capabilities](/v2/capabilities): the harnesses, tools, models and efforts this server has, and what it does not offer.
17
17
  - `POST /v2/agents` with `{definition: {name, instructions, tools, harness?, model?, thinking?}}` makes an agent (a workflow one holds `workflow` in place of `instructions`). A refusal is `422 input_invalid` naming each field. `PUT /v2/agents/{id}/definition` makes its next revision.
18
- - An agentic definition's `output_schema` is the JSON Schema its final answer's last fenced json block meets, read into a completed run's `result.output`. A run a schedule trigger starts is handed that trigger's last completed `result.output` after its message, whole up to 32 KiB (as 2-space JSON). Over 32 KiB, a scheduled run is handed only the fields the producing run's schema names in `x-carried`; carried arrays lose entries from the front until they fit, and the run is told how many. A save refuses an `x-carried` that is not unique root property names.
18
+ - An agentic definition's `output_schema` is the JSON Schema its final answer's json block meets (its last fenced one, or the whole answer when it is one JSON object), read into a completed run's `result.output`. A run a schedule trigger starts is handed that trigger's last completed `result.output` after its message, whole up to 32 KiB (as 2-space JSON). Over 32 KiB, a scheduled run is handed only the fields the producing run's schema names in `x-carried`; carried arrays lose entries from the front until they fit, and the run is told how many. A save refuses an `x-carried` that is not unique root property names.
19
19
  - `POST /v2/agents/{id}/runs` with `{input, file_ids?, effort?, revision?}` starts a run, answered at once, queued. An agentic run's input is `{content: "the first message"}`. An `Idempotency-Key` header makes a retry safe.
20
20
  - `POST /v2/files?path=notes.md` with the file's bytes as the body (`curl --data-binary @notes.md`) uploads a file, answered `201` with the file, ready, its `file_id` under `file`. Name it in a run's `file_ids`, and the run finds it at `inputs/notes.md`. `GET /v2/files` lists the uploads, `DELETE /v2/files/{id}` removes one.
21
21
  - `GET /v2/runs/{id}`: status (`queued`, `working`, `input_required`, `completed`, `failed`, `cancelled`, `paused`), `result` (`final_answer`, or a workflow's `output`), `error`, `cost` (`usd` is null while unknown, never $0), `path` (`agent`, `workflow`, `handed_back`; null until it ends). A run its learned workflow answered alone (`path` `workflow`), or ran first and handed back (`handed_back`), carries `workflow` (`name`, `digest`, and `repick`: `found` when its answer re-picked after a quote miss and found its quotes, `missed` when the re-pick missed too, else null), on the read and on every `GET /v2/runs` row; null on any other run.
package/dist/openapi.d.ts CHANGED
@@ -38,7 +38,7 @@ export declare const REQUEST_EXAMPLES: Record<string, Record<string, {
38
38
  value: Json;
39
39
  }>>;
40
40
  export declare function openapiDocument(capabilityOf: (operationId: string) => string | undefined, adapters?: readonly TriggerAdapter[]): Json;
41
- /** The document as served on `port`: the owner's session cookie named as the console sets it on that port
42
- * (page.ts: `agentrun-<port>`). Without a port, the document as built. */
43
- export declare function servedOpenapi(doc: Json, port: number | undefined): Json;
41
+ /** The document as served with the owner's session cookie under `cookie`, the name the console sets for the request
42
+ * (page.ts ownerCookieName). */
43
+ export declare function servedOpenapi(doc: Json, cookie: string): Json;
44
44
  export {};
package/dist/openapi.js CHANGED
@@ -8,7 +8,7 @@ import { NATIVE_BINDING, NATIVE_RUN, NATIVE_PATHS } from "./native/schema.js";
8
8
  // not serve at all (NOT_SERVED) is left out of the document, and this server's own routes are added as operations marked
9
9
  // `x-agentrun-serve` (true, or the addition that made it, as `stats/1`), listed in `info.x-agentrun-serve`.
10
10
  import { readFileSync } from "node:fs";
11
- import { CALL_RESULT_CHARS, CAPS, TRIGGER_SOURCES } from "./timeline/index.js";
11
+ import { CALL_RESULT_CHARS, CALLS_PAGE_ROWS, CAPS, TRIGGER_SOURCES } from "./timeline/index.js";
12
12
  import { EMAIL_SCOPES, PASSWORD_MAX, SCOPED_TOOLS, SEND_CAP } from "./email/names.js";
13
13
  import { PAYLOAD_KEPT_BYTES } from "./trigger-adapter.js";
14
14
  import { TRIGGER_ADAPTERS } from "./trigger-adapters.js";
@@ -136,6 +136,26 @@ const HARNESS_PROMISES = {
136
136
  };
137
137
  const closed = (properties, description) => ({ type: "object", additionalProperties: false, required: Object.keys(properties), properties, ...(description ? { description } : {}) });
138
138
  const USD = { type: ["number", "null"], minimum: 0, description: "The sum of the known costs, rounded to 1e-6; null when no run's cost is known, never 0 for unknown." };
139
+ /** wrapped/1: GET /wrapped's answer (wrapped.ts). */
140
+ const WRAPPED_TOKENS = closed({ input: COUNT, output: COUNT, cache_read: COUNT, cache_write: COUNT });
141
+ const WRAPPED = closed({
142
+ year: { type: "integer", minimum: 1000, maximum: 9999 },
143
+ sessions: { ...COUNT, description: "Sessions whose first request falls in the year." },
144
+ turns: { ...COUNT, description: "The person's prompts in those sessions." },
145
+ requests: { ...COUNT, description: "Model requests made in the year, each once, subagents' with them." },
146
+ tokens: { ...WRAPPED_TOKENS, description: "The year's requests' tokens: `input` is uncached input, so the whole prompt is input + cache_read + cache_write." },
147
+ cost_usd: { type: "number", minimum: 0, description: "The list price of the requests that could be priced; `unpriced_requests` counts those that could not." },
148
+ unpriced_requests: COUNT,
149
+ days: { type: "array", description: "Each local day with a request, ascending.", items: closed({ day: { type: "string", pattern: "^\\d{4}-\\d{2}-\\d{2}$" }, requests: COUNT, tokens: COUNT }) },
150
+ hours: { type: "array", minItems: 24, maxItems: 24, items: COUNT, description: "Requests by local hour of the day." },
151
+ weekdays: { type: "array", minItems: 7, maxItems: 7, items: COUNT, description: "Requests by local weekday, Sunday first." },
152
+ active_ms: { ...COUNT, description: "Time at work: the gaps between a session's requests, each counted when under 15 minutes." },
153
+ harnesses: { type: "array", items: closed({ harness: { type: "string" }, sessions: COUNT, requests: COUNT, tokens: COUNT }), description: "By the harness that runs what each source ran, most tokens first." },
154
+ models: { type: "array", items: closed({ model: { type: "string", description: "`provider/model`, or `unknown` for a request that names none." }, requests: COUNT, tokens: COUNT, cost_usd: { type: "number", minimum: 0 } }), description: "By the request's model, most tokens first." },
155
+ sources: { type: "array", items: closed({ source: { type: "string" }, sessions: COUNT, requests: COUNT }), description: "By the tool the sessions were read from." },
156
+ imported: { type: "array", items: closed({ source: { type: "string" }, runs: COUNT }), description: "The runs imported here in the year, by source (never `live`)." },
157
+ unread_files: { ...COUNT, description: "Session files that could not be read (gone since listed, or not openable by this user), so the numbers are short by them. A count only: no path." },
158
+ }, "A year of the work under this machine's home, bucketed by each request's time in the server's local zone.");
139
159
  /** Runs counted together (AgentStoreReader.analytics's AnalyticsGroup). */
140
160
  const GROUP = {
141
161
  runs: COUNT, completed: { ...COUNT, description: "Completed, escalated runs included: one completed and waits for a person's review." },
@@ -475,15 +495,16 @@ const CHATGPT_SIGN_IN = {
475
495
  authorize_url: { type: "string", format: "uri", description: "With `pending`: the link that sign-in opens." },
476
496
  expires_at: { type: "string", format: "date-time", description: "With `pending`: when that sign-in stops waiting, as its start answered." },
477
497
  models: { type: "array", items: { type: "string" }, description: "With `signed_in`: the plan's models, read from OpenAI at the sign-in, each named `chatgpt/<model-id>` in a revision." },
498
+ problem: { type: "string", description: "Why the last sign-in ended without signing in, in words a person acts on: a plan OpenAI gave no use of (\"This ChatGPT plan can't be used here: …\"), a workspace whose admin turned off open-source apps (\"Your ChatGPT workspace's admin has turned off open-source apps (External access → OSS → Use ChatGPT plan): …\"), another refusal at OpenAI's sign-in page or of the code (a Free plan's sign-in has ended in one of these, and the words say a Free plan may be the reason), an answer that could not be read, OpenAI out of reach, or a sign-in that could not be saved. Always fixed words, never OpenAI's code (anything on the server's machine can send its loopback callback one). Set once the browser's return or a pasted address got that far (OpenAI's tab has already said the sign-in completed), or when a sign-in waited out its 10 minutes (\"The sign-in timed out before OpenAI sent the code back: start it again.\"); the server's log line `event=chatgpt chatgpt=sign_in_failed reason=…` names it (OpenAI's status and error code, or `timed_out`; never a token or a code). Present while signed in too, when a later sign-in failed. Gone at the next start, sign-in or sign-out; a cancelled sign-in sets none." },
478
499
  },
479
500
  };
480
501
  /** GET /settings/claude-login's answer (claude-login.ts ClaudeLoginView): what Claude Code's CLI says of its login, never
481
502
  * a token. */
482
503
  const CLAUDE_LOGIN = {
483
- type: "object", additionalProperties: false, required: ["state", "place", "command", "can_start"],
504
+ type: "object", additionalProperties: false, required: ["state", "place", "command", "can_start", "folder", "machine"],
484
505
  properties: {
485
506
  state: { enum: ["off", "other_machine", "signed_in", "signed_out", "no_cli", "unknown"], description: "`off`: not turned on. `other_machine`: turned on for another machine than this server's. Else what the CLI says: `signed_in`, `signed_out`, `no_cli` (no Claude Code CLI here yet: claude-agent's first run installs the pinned one), `unknown` (it gave no answer)." },
486
- place: { enum: ["agentrun", "machine"], description: "Where the login is: `agentrun`, AgentRun's own directory in its data (the default); `machine`, this machine's own Claude Code login (~/.claude), which the owner opts into." },
507
+ place: { enum: ["agentrun", "machine"], description: "Where the login is: `agentrun`, AgentRun's own directory in its data (the default); `machine`, this machine's own Claude Code login (`machine.folder`), which the owner opts into." },
487
508
  command: { type: "string", description: "The line that signs the CLI in at `place`, for a terminal on this machine." },
488
509
  can_start: { type: "boolean", description: "Whether POST /settings/claude-login/login can start the CLI's sign-in here: the server is bound to loopback with no public address, so the browser it opens is on this machine." },
489
510
  refused: { type: "string", description: "Why the mode can't be turned on here, in one line: more than one person can start runs on this server." },
@@ -492,6 +513,28 @@ const CLAUDE_LOGIN = {
492
513
  properties: { method: { type: "string" }, email: { type: "string" }, organization: { type: "string" }, plan: { type: "string" } },
493
514
  description: "With `signed_in`: what the CLI's status says of the account (its sign-in method, email, organization and plan), for display.",
494
515
  },
516
+ folder: { type: "string", description: "The folder whose login the CLI is asked about: the login's directory at `place`. The sign-in started here and `command` sign in there, and its status is read there." },
517
+ machine: {
518
+ type: "object", additionalProperties: false, required: ["folder", "source"],
519
+ properties: {
520
+ folder: { type: "string", description: "This machine's own Claude Code login folder, as the CLI finds it for this server's user." },
521
+ source: { enum: ["CLAUDE_CONFIG_DIR", "default"], description: "`CLAUDE_CONFIG_DIR`: the server's environment names the folder (an absolute path). `default`: it does not, so the folder is the CLI's default, `~/.claude`; a Claude Code that keeps its login in another folder is found only when this server is started with `CLAUDE_CONFIG_DIR` set to it." },
522
+ },
523
+ description: "This machine's own Claude Code login, the folder `place: machine` uses.",
524
+ },
525
+ sign_in: {
526
+ type: "object", additionalProperties: false, required: ["state", "started_at", "limit_ms"],
527
+ properties: {
528
+ state: { enum: ["waiting", "signed_in", "timed_out", "failed", "not_started"], description: "`waiting`: for the browser, since `started_at`. `signed_in`: the CLI's sign-in ended signed in. `timed_out`: no answer from the browser within `limit_ms`, so it was ended; a sign-in page still open can't finish, and POST /settings/claude-login/login starts it again. `failed`: the CLI ended without signing in (`exit_code`, or the `signal` that ended it). `not_started`: the CLI could not be started (`error`)." },
529
+ started_at: { type: "string", format: "date-time" },
530
+ ended_at: { type: "string", format: "date-time" },
531
+ limit_ms: { type: "integer", description: "How long it waits for the browser before it is ended (10 minutes)." },
532
+ exit_code: { type: "integer" },
533
+ signal: { type: "string" },
534
+ error: { type: "string" },
535
+ },
536
+ description: "The CLI's sign-in this server started (POST /settings/claude-login/login), as long as this server runs: absent when none was started, or after a turn-off.",
537
+ },
495
538
  },
496
539
  };
497
540
  /** GET /settings/tool-keys's answer (tool-keys.ts): each key's fields by name and where each is set, never a value. */
@@ -1388,7 +1431,7 @@ const TEMPLATE = closed({
1388
1431
  license: NULLABLE_STRING,
1389
1432
  author: { type: ["object", "null"], additionalProperties: false, required: ["name"], properties: { name: { type: "string" }, email: { type: "string" }, url: { type: "string" } }, description: "Who made the package; null when it names no one." },
1390
1433
  repository: NULLABLE_STRING,
1391
- output: { type: ["object", "null"], additionalProperties: false, required: ["schema", "json_schema"], properties: { schema: { type: "string", description: "The schema's file in the package; it ships beside each SKILL.md." }, json_schema: { type: ["object", "null"], description: "The JSON Schema the agent's answer meets (its last fenced json block)." } }, description: "The shape of the agent's answer; null when the package names none." },
1434
+ output: { type: ["object", "null"], additionalProperties: false, required: ["schema", "json_schema"], properties: { schema: { type: "string", description: "The schema's file in the package; it ships beside each SKILL.md." }, json_schema: { type: ["object", "null"], description: "The JSON Schema the agent's answer meets (its last fenced json block, or the whole answer when it is one JSON object)." } }, description: "The shape of the agent's answer; null when the package names none." },
1392
1435
  harness: { type: ["array", "null"], items: { type: "string" }, description: "The harnesses it runs on, in the order it prefers them: apply takes the first this server runs. Null: any, the server's default." },
1393
1436
  model: {
1394
1437
  type: ["object", "null"], additionalProperties: false, required: ["tier"],
@@ -2242,6 +2285,17 @@ const EXTENSIONS = {
2242
2285
  "x-agentrun-serve": "capacity/1",
2243
2286
  },
2244
2287
  },
2288
+ "/wrapped": {
2289
+ get: {
2290
+ operationId: "getWrapped", tags: ["runs"], summary: "A year of the work under this machine's session files",
2291
+ description: "Reads the Claude Code, Codex, pi and other session files under the home of the machine this server runs on, and answers numbers and names only (no prompt, title, path or project). Everything is bucketed by each request's time in the server's local zone, so a session that spans New Year splits; a session counts for the year of its first request. Answered only by a server bound to loopback with no public URL: any other, and the API-only profile, is 403. The answer is kept for a minute.",
2292
+ parameters: [
2293
+ { name: "year", in: "query", required: false, description: "A four-digit year, in the server's local zone. Default the current year.", schema: { type: "integer", minimum: 1000, maximum: 9999 } },
2294
+ ],
2295
+ responses: { "200": json(WRAPPED, "The year, read now."), ...errors(400, 401, 403, 429, 500) },
2296
+ "x-agentrun-serve": "wrapped/1",
2297
+ },
2298
+ },
2245
2299
  "/runs/{run_id}/graph": {
2246
2300
  get: {
2247
2301
  operationId: "getRunGraph", tags: ["runs"], summary: "A workflow run's graph, live",
@@ -3174,7 +3228,7 @@ const EXTENSIONS = {
3174
3228
  "/runs/{run_id}/approvals/{approval_id}": {
3175
3229
  post: {
3176
3230
  operationId: "answerApproval", tags: ["runs"], summary: "Answer a tool call that waits for the owner's approval",
3177
- description: "A tool set to ask parks its run at each call: status input_required, state waiting, and its view's and its summary's pending (kind approval) naming the call; a timeline row of kind tool_approval_requested follows the call's own rows (its call's, and its result's once it ran), then a row with what came of the answer. allow runs the call once, and the session goes on with its result; deny answers the call with the refusal, the note as its reason. The first answer wins: the same answer again is 204, another 409 not_continuable with details {reason: already_answered, decision}. A cancel of the run marks the call canceled, and a stop withdraws it. A person's message while it waits declines it, with the message as the reason: the run goes on in one turn with the refusal and their words, its row reads `Declined by your message`, their words show as their own message row between the approval row and the outcome, and a later answer is 409 with details.decision deny. Only the owner's password session answers, on the page's own origin with a JSON body: a bearer token is 403 forbidden, since a run's process, an agent's MCP client or a script may hold one.",
3231
+ description: "A tool set to ask parks its run at each call: status input_required, state waiting, and its view's and its summary's pending (kind approval) naming the call; a timeline row of kind tool_approval_requested follows the call's own rows (its call's, and its result's once it ran), then a row with what came of the answer. allow runs the call once, and the session goes on with its result: a read the runner lost mid-call may run again on its next claim, a call with a side effect never does; deny answers the call with the refusal, the note as its reason. The first answer wins: the same answer again is 204, another 409 not_continuable with details {reason: already_answered, decision}. A cancel of the run marks the call canceled, and a stop withdraws it. A person's message while it waits declines it, with the message as the reason: the run goes on in one turn with the refusal and their words, its row reads `Declined by your message`, their words show as their own message row between the approval row and the outcome, and a later answer is 409 with details.decision deny. Only the owner's password session answers, on the page's own origin with a JSON body: a bearer token is 403 forbidden, since a run's process, an agent's MCP client or a script may hold one.",
3178
3232
  parameters: [ref("parameters/RunId"), { name: "approval_id", in: "path", required: true, description: "The run's pending.id.", schema: { type: "string" } }],
3179
3233
  requestBody: { required: true, content: { "application/json": { schema: { type: "object", additionalProperties: false, required: ["decision"], properties: { decision: { enum: ["allow", "deny"] }, note: { type: "string", maxLength: 2000, description: "Why: with deny, the refusal's reason the model is told." }, confirm_destructive: { const: true, description: "The second confirm an allow of a destructive call needs (its pending's `destructive`): without it that allow is 422 on `confirm_destructive`, reason `missing`, and the call still waits. A deny needs none.", "x-agentrun-serve": "allowreads/1" } } } } } },
3180
3234
  responses: { "204": { description: "Answered: the run goes on." }, ...errors(400, 401, 403, 404, 409, 415, 422, 429, 500) },
@@ -3904,7 +3958,7 @@ const FIELD_EXTENSIONS = {
3904
3958
  },
3905
3959
  tool_result_text: {
3906
3960
  type: ["string", "null"],
3907
- description: `On a \`tool_result\` row of a timeline read with \`calls=whole\` alone: the head of the call's output, to ${CALL_RESULT_CHARS} characters, through the run's redaction, its URLs' query values elided as \`tool_result_preview\`'s are; null for an empty output. A \`web_search\`'s or \`web_fetch\`'s is its JSON whole but for its long texts: every result's \`url\`, \`title\` and \`published\` (a page's \`url\` and \`title\`) as it came, each snippet, the provider's \`text\` and a page's \`text\` cut to fit and ending in "…" where cut, a page's \`links\` past the cut counted in \`links_cut\`; longer than ${CALL_RESULT_CHARS} only when its urls alone pass it. Absent otherwise.`,
3961
+ description: `On a \`tool_result\` row of a timeline read with \`calls=whole\` alone: the call's output whole to ${CALL_RESULT_CHARS} characters (its head past that), through the run's redaction, its URLs' query values elided as \`tool_result_preview\`'s are; null for an empty output. A \`web_search\`'s or \`web_fetch\`'s is its JSON whole but for its long texts: every result's \`url\`, \`title\` and \`published\` (a page's \`url\` and \`title\`) as it came, each snippet, the provider's \`text\` and a page's \`text\` cut to fit and ending in "…" where cut, a page's \`links\` past the cut counted in \`links_cut\`; longer than ${CALL_RESULT_CHARS} only when its urls alone pass it. Absent otherwise.`,
3908
3962
  "x-agentrun-serve": "callswhole/1",
3909
3963
  },
3910
3964
  learning: {
@@ -4421,8 +4475,8 @@ export function openapiDocument(capabilityOf, adapters = TRIGGER_ADAPTERS) {
4421
4475
  }
4422
4476
  // The console's password session, the one credential approving a workflow draft takes (approveLearningFile).
4423
4477
  doc.components.securitySchemes.ownerSession = {
4424
- type: "apiKey", in: "cookie", name: "agentrun-<port>",
4425
- description: "The owner's console session: the cookie `agentrun-<port>`, this server's port (the document as served names it), that the console sets when the owner signs in with their password (accounts on). Sent from this server's own origin; a token never stands for it.",
4478
+ type: "apiKey", in: "cookie", name: "agentrun-<port>-session",
4479
+ description: "The owner's console session: the cookie the console sets when the owner signs in with their password (accounts on). On http it is `agentrun-<port>-session`, for the port the browser opened (a container's published port, not the one it listens on); over https, `__Host-agentrun-session`. The document as served names the one for the request that fetched it. Sent from this server's own origin; a token never stands for it.",
4426
4480
  "x-agentrun-serve": "learning/2",
4427
4481
  };
4428
4482
  const schemas = doc.components.schemas;
@@ -4491,10 +4545,10 @@ export function openapiDocument(capabilityOf, adapters = TRIGGER_ADAPTERS) {
4491
4545
  }
4492
4546
  // A contract field this server takes with a meaning of its own, said on it.
4493
4547
  definition.properties.max_cost_usd = { ...definition.properties.max_cost_usd, "x-agentrun-serve-note": "The agent's default cap of each run started without a max_cost_usd of its own (a run's own wins), kept with its revision: above 0 sets it, 0 clears it (no default), and an edit that leaves the field out keeps the agent's, so leaving a field out never removes a spend limit. An agentic definition's or a workflow's alike." };
4494
- definition.properties.output_schema = { ...definition.properties.output_schema, "x-agentrun-serve-note": "An agentic definition's alone (a workflow's output is its workflow's): the JSON Schema its final answer's last fenced json block meets, at most 64 KiB, refused at save when it does not compile. A completed run's result.output is that block's value when it meets the schema, else null. An edit that leaves the field out keeps the agent's. A template's answer schema (its manifest's `output`) is set here at apply. Over 32 KiB, a scheduled run is handed only the fields the producing run's schema names in `x-carried`; carried arrays lose entries from the front until they fit, and the run is told how many. A save refuses an `x-carried` that is not unique root property names." };
4548
+ definition.properties.output_schema = { ...definition.properties.output_schema, "x-agentrun-serve-note": "An agentic definition's alone (a workflow's output is its workflow's): the JSON Schema its final answer's json block meets (its last fenced one, or the whole answer when it is one JSON object), at most 64 KiB, refused at save when it does not compile. A completed run's result.output is that block's value when it meets the schema, else null. An edit that leaves the field out keeps the agent's. A template's answer schema (its manifest's `output`) is set here at apply. Over 32 KiB, a scheduled run is handed only the fields the producing run's schema names in `x-carried`; carried arrays lose entries from the front until they fit, and the run is told how many. A save refuses an `x-carried` that is not unique root property names." };
4495
4549
  definition.properties.input_schema = { ...definition.properties.input_schema, "x-agentrun-serve-note": "An agentic definition's alone (a workflow's input is its workflow's own schema): a JSON Schema object schema (`type: object`), at most 64 KiB, refused at save when it does not compile. Every run's `input` is checked against it with the full compiler, by POST /agents/{agent_id}/runs, a trigger's start_run target (at save and when it fires) and a template's triggers, and refused 422 `input_invalid` with an issue at each path (`input.company`, `input.topics.1`). `content` is reserved: named, it is `{type: string}`; it is always taken as text (the run's message). It is required when the schema has no field of its own; when the schema's own fields are all optional, a run gives `content` or one of them, and an input with none is refused at `input.content`. The run's first message is `content`, then the other fields as one fenced json block under the line `Input:`. Absent: `{content: string}`. An edit that leaves the field out keeps the agent's. A template's `inputs` are set here at apply." };
4496
4550
  const runResult = schemas.RunResult;
4497
- runResult.properties.output = { ...runResult.properties.output, "x-agentrun-serve-note": "A workflow run's output, as its workflow ended; an agentic run's, its final answer's last fenced json block when it meets the agent's output_schema, else null (no schema, no block, not JSON, or a value the schema refuses). The runner gives the model the schema in its instructions on every harness, and asks once more, in the same session under the same cap, when the answer misses it; output_error says why one still missed." };
4551
+ runResult.properties.output = { ...runResult.properties.output, "x-agentrun-serve-note": "A workflow run's output, as its workflow ended; an agentic run's, its final answer's json block (its last fenced one, or the whole answer when it is one JSON object) when it meets the agent's output_schema, else null (no schema, no block, not JSON, or a value the schema refuses). The runner gives the model the schema in its instructions on every harness, and asks once more, in the same session under the same cap, when the answer misses it; output_error says why one still missed." };
4498
4552
  // instructions XOR workflow (validate.ts): a workflow revision has none. version, skills and tools: this server
4499
4553
  // mints or keeps them when a write leaves them out (agents-store.ts definitionOf), so none of the four is required of a
4500
4554
  // write; only instructions ever misses from an answer (a workflow revision's), so Definition keeps the rest required.
@@ -4540,8 +4594,8 @@ export function openapiDocument(capabilityOf, adapters = TRIGGER_ADAPTERS) {
4540
4594
  const timeline = doc.paths["/runs/{run_id}/timeline"].get;
4541
4595
  timeline.parameters = [
4542
4596
  ...timeline.parameters,
4543
- { name: "limit", in: "query", required: false, description: "At most this many rows in a page (1 to 500, default 500); has_more says when another waits.", schema: { type: "integer", minimum: 1, maximum: 500, default: 500 } },
4544
- { name: "calls", in: "query", required: false, description: `\`whole\`: each \`tool_use\` row carries its call's arguments (\`tool_input\`) and each \`tool_result\` row the head of its output to ${CALL_RESULT_CHARS} characters (\`tool_result_text\`; a web call's every url, only its long texts cut), both through the run's redaction, for a reader that grades the run (a template eval). Its rows are another page sequence: a cursor (\`after\`, \`Last-Event-ID\`) from one read goes with the same \`calls\`.`, schema: { enum: ["whole"] } },
4597
+ { name: "limit", in: "query", required: false, description: `At most this many rows in a page (1 to 500, default 500; with \`calls=whole\`, 1 to ${CALLS_PAGE_ROWS}, default ${CALLS_PAGE_ROWS}); has_more says when another waits.`, schema: { type: "integer", minimum: 1, maximum: 500, default: 500 } },
4598
+ { name: "calls", in: "query", required: false, description: `\`whole\`: each \`tool_use\` row carries its call's arguments (\`tool_input\`) and each \`tool_result\` row its output whole to ${CALL_RESULT_CHARS} characters (\`tool_result_text\`; a web call's every url, only its long texts cut), both through the run's redaction, for a reader that grades the run (a template eval). Its rows are another page sequence: a cursor (\`after\`, \`Last-Event-ID\`) from one read goes with the same \`calls\`.`, schema: { enum: ["whole"] } },
4545
4599
  ];
4546
4600
  timeline["x-agentrun-serve-changed"] = { limit: "timelinelimit/1", calls: "callswhole/1" };
4547
4601
  changed.push("GET /runs/{run_id}/timeline");
@@ -4884,12 +4938,10 @@ export function openapiDocument(capabilityOf, adapters = TRIGGER_ADAPTERS) {
4884
4938
  }
4885
4939
  return doc;
4886
4940
  }
4887
- /** The document as served on `port`: the owner's session cookie named as the console sets it on that port
4888
- * (page.ts: `agentrun-<port>`). Without a port, the document as built. */
4889
- export function servedOpenapi(doc, port) {
4890
- if (port === undefined)
4891
- return doc;
4941
+ /** The document as served with the owner's session cookie under `cookie`, the name the console sets for the request
4942
+ * (page.ts ownerCookieName). */
4943
+ export function servedOpenapi(doc, cookie) {
4892
4944
  const components = doc.components;
4893
4945
  const schemes = components.securitySchemes;
4894
- return { ...doc, components: { ...components, securitySchemes: { ...schemes, ownerSession: { ...schemes.ownerSession, name: `agentrun-${port}` } } } };
4946
+ return { ...doc, components: { ...components, securitySchemes: { ...schemes, ownerSession: { ...schemes.ownerSession, name: cookie } } } };
4895
4947
  }