@parcha/agentrun-serve 0.1.0-beta.55 → 0.1.0-beta.57
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 +261 -0
- package/README.md +228 -45
- package/dist/acp-package.d.ts +2 -0
- package/dist/adapters.d.ts +18 -5
- package/dist/adapters.js +23 -9
- package/dist/agent-package.d.ts +3 -3
- package/dist/agent-package.js +17 -8
- package/dist/answer-json.d.ts +6 -2
- package/dist/answer-json.js +22 -4
- package/dist/api-keys.d.ts +76 -0
- package/dist/api-keys.js +217 -0
- package/dist/api-only.d.ts +17 -5
- package/dist/api-only.js +36 -8
- package/dist/browser-hold.d.ts +23 -0
- package/dist/browser-hold.js +48 -0
- package/dist/browser-person.d.ts +3 -0
- package/dist/browser-person.js +4 -1
- package/dist/calendar/tools.js +3 -2
- package/dist/chatgpt-plan.d.ts +28 -3
- package/dist/chatgpt-plan.js +182 -21
- package/dist/claude-login.d.ts +101 -14
- package/dist/claude-login.js +232 -49
- package/dist/claude-sign-in.d.ts +46 -0
- package/dist/claude-sign-in.js +93 -0
- package/dist/cli.js +63 -6
- package/dist/composio-made.d.ts +4 -0
- package/dist/composio-made.js +4 -0
- package/dist/composio-preset.d.ts +43 -2
- package/dist/composio-preset.js +92 -4
- package/dist/computer-held-routes.d.ts +5 -4
- package/dist/computer-held-routes.js +29 -8
- package/dist/computer-held.d.ts +6 -1
- package/dist/computer-held.js +14 -0
- package/dist/computer-record.js +4 -2
- package/dist/computer-viewer.js +4 -1
- package/dist/console/assets/{backend-D5EmB4N3.js → backend-DVhHzJX2.js} +19 -19
- package/dist/console/assets/index-Bwn1oTem.css +1 -0
- package/dist/console/assets/index-okP-y8PK.js +747 -0
- package/dist/console/index.html +2 -2
- package/dist/decisions.d.ts +1 -1
- package/dist/decisions.js +1 -1
- package/dist/docker-host-addresses.d.ts +22 -11
- package/dist/docker-host-addresses.js +38 -26
- package/dist/env-switch.d.ts +10 -0
- package/dist/env-switch.js +33 -2
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +2 -0
- package/dist/fal-price.d.ts +58 -20
- package/dist/fal-price.js +341 -82
- package/dist/handed-values.d.ts +43 -1
- package/dist/handed-values.js +119 -2
- package/dist/harness-archive.d.ts +13 -10
- package/dist/harness-archive.js +60 -34
- package/dist/harness-check.d.ts +3 -1
- package/dist/harness-check.js +25 -46
- package/dist/harness-keys.d.ts +73 -27
- package/dist/harness-keys.js +194 -61
- package/dist/harness-recipe-entry.d.ts +8 -7
- package/dist/harness-recipe-entry.js +21 -32
- package/dist/harness-recipe.d.ts +38 -25
- package/dist/harness-recipe.js +49 -36
- package/dist/harness-sign-in.js +12 -23
- package/dist/harness-table.d.ts +10 -3
- package/dist/harness-table.js +26 -21
- package/dist/harness.d.ts +1 -0
- package/dist/harness.js +17 -5
- package/dist/host-check.d.ts +4 -0
- package/dist/host-check.js +4 -0
- package/dist/hosted-search.d.ts +1 -1
- package/dist/hosted-search.js +1 -2
- package/dist/import-worker.d.ts +4 -2
- package/dist/import-worker.js +9 -2
- package/dist/in-flight.d.ts +26 -0
- package/dist/in-flight.js +52 -0
- package/dist/key-refusal.d.ts +26 -5
- package/dist/key-refusal.js +313 -37
- package/dist/learn/secrets.d.ts +31 -11
- package/dist/learn/secrets.js +152 -191
- package/dist/learning-cost.d.ts +6 -3
- package/dist/learning-cost.js +4 -2
- package/dist/link-check.js +1 -1
- package/dist/llms.txt +2 -2
- package/dist/marketplace.d.ts +77 -0
- package/dist/marketplace.js +224 -0
- package/dist/mcp-api-only-origins.d.ts +30 -0
- package/dist/mcp-api-only-origins.js +57 -0
- package/dist/mcp-gateway.d.ts +7 -5
- package/dist/mcp-gateway.js +9 -12
- package/dist/mcp-secret-writes.js +5 -3
- package/dist/mcp-servers-store.d.ts +28 -6
- package/dist/mcp-servers-store.js +53 -4
- package/dist/media-duration.d.ts +3 -0
- package/dist/media-duration.js +90 -9
- package/dist/model-form.d.ts +5 -4
- package/dist/model-form.js +11 -7
- package/dist/model.d.ts +5 -2
- package/dist/model.js +9 -5
- package/dist/ollama-provider.d.ts +7 -1
- package/dist/ollama-provider.js +14 -2
- package/dist/openapi.d.ts +3 -3
- package/dist/openapi.js +245 -42
- package/dist/otel/genai.d.ts +65 -0
- package/dist/otel/genai.js +116 -0
- package/dist/otel/tracer.d.ts +55 -0
- package/dist/otel/tracer.js +308 -0
- package/dist/page.d.ts +2 -0
- package/dist/page.js +3 -1
- package/dist/paid-calls.d.ts +1 -32
- package/dist/paid-calls.js +4 -39
- package/dist/place-offers.d.ts +14 -6
- package/dist/place-offers.js +26 -13
- package/dist/provider.d.ts +9 -0
- package/dist/provider.js +50 -3
- package/dist/redact/match.d.ts +101 -0
- package/dist/redact/match.js +1152 -0
- package/dist/refusal-words.d.ts +11 -0
- package/dist/refusal-words.js +11 -0
- package/dist/run-census.d.ts +67 -0
- package/dist/run-census.js +240 -0
- package/dist/run-computer.d.ts +6 -3
- package/dist/run-computer.js +4 -1
- package/dist/run-cut.d.ts +15 -6
- package/dist/run-cut.js +30 -9
- package/dist/run-files.d.ts +3 -0
- package/dist/run-files.js +3 -0
- package/dist/run-launch.d.ts +12 -1
- package/dist/run-launch.js +9 -10
- package/dist/run-learning-served.d.ts +2 -0
- package/dist/run-model-key.d.ts +8 -0
- package/dist/run-model-key.js +31 -1
- package/dist/run-reads-over-store.d.ts +24 -6
- package/dist/run-reads-over-store.js +67 -23
- package/dist/run-recordings.d.ts +5 -1
- package/dist/run-recordings.js +39 -14
- package/dist/run-timeline-served.d.ts +3 -1
- package/dist/run-timeline-served.js +4 -4
- package/dist/run-usage.d.ts +1 -0
- package/dist/runnable.d.ts +10 -1
- package/dist/runnable.js +20 -8
- package/dist/runner/adapter-loop.d.ts +14 -0
- package/dist/runner/adapter-loop.js +56 -11
- package/dist/runner/adapter-run-spec.d.ts +45 -8
- package/dist/runner/adapter-run-spec.js +154 -29
- package/dist/runner/adapters/pi.js +25 -3
- package/dist/runner/beside.js +11 -6
- package/dist/runner/big-writes.js +1 -10
- package/dist/runner/claim-secrets.d.ts +18 -3
- package/dist/runner/claim-secrets.js +35 -6
- package/dist/runner/cli-run-spec.d.ts +6 -0
- package/dist/runner/cli-run-spec.js +85 -36
- package/dist/runner/computer-journal.d.ts +9 -1
- package/dist/runner/computer-journal.js +26 -0
- package/dist/runner/conformance/harness.js +1 -1
- package/dist/runner/feedback-round.js +3 -0
- package/dist/runner/harness-loops.d.ts +6 -5
- package/dist/runner/harness-loops.js +7 -7
- package/dist/runner/held.d.ts +11 -5
- package/dist/runner/journal-kinds.d.ts +5 -0
- package/dist/runner/journal-kinds.js +5 -0
- package/dist/runner/loop-contract.d.ts +4 -0
- package/dist/runner/main.js +15 -6
- package/dist/runner/mcp-claim.js +30 -3
- package/dist/runner/mcp-run.d.ts +12 -0
- package/dist/runner/mcp-run.js +12 -5
- package/dist/runner/model-route.d.ts +17 -0
- package/dist/runner/model-route.js +120 -2
- package/dist/runner/presence.d.ts +4 -3
- package/dist/runner/presence.js +4 -2
- package/dist/runner/run-child-host.d.ts +5 -0
- package/dist/runner/run-child-host.js +71 -30
- package/dist/runner/run-child.js +5 -2
- package/dist/runner/runner.d.ts +18 -3
- package/dist/runner/runner.js +162 -36
- package/dist/runner/store-port.d.ts +1 -1
- package/dist/runner/store-secrets.d.ts +6 -0
- package/dist/runner/store-secrets.js +49 -7
- package/dist/runner/subagent.js +4 -40
- package/dist/runner/workflow-first.d.ts +11 -4
- package/dist/runner/workflow-first.js +14 -8
- package/dist/runner/workflow-spec.js +3 -2
- package/dist/runs-over-store.d.ts +15 -6
- package/dist/runs-over-store.js +33 -21
- package/dist/scrub-command.d.ts +73 -0
- package/dist/scrub-command.js +307 -0
- package/dist/secret-cut.d.ts +73 -0
- package/dist/secret-cut.js +291 -4
- package/dist/secret-rules.d.ts +143 -0
- package/dist/secret-rules.js +2564 -0
- package/dist/secrets.d.ts +7 -0
- package/dist/secrets.js +20 -0
- package/dist/server-keys.d.ts +20 -0
- package/dist/server-keys.js +25 -6
- package/dist/server.d.ts +57 -13
- package/dist/server.js +371 -113
- package/dist/skills/agentrun-serve/SKILL.md +4 -0
- package/dist/store/dialect.d.ts +3 -0
- package/dist/store/dialect.js +1 -0
- package/dist/store/index.d.ts +1 -1
- package/dist/store/index.js +1 -1
- package/dist/store/journal/storage.js +1 -1
- package/dist/store/postgres/dialect.js +3 -0
- package/dist/store/postgres/migrations/0027_run_launch_census.sql +31 -0
- package/dist/store/schema.d.ts +6 -0
- package/dist/store/schema.js +11 -1
- package/dist/store/seal.d.ts +6 -1
- package/dist/store/seal.js +5 -3
- package/dist/store/sqlite/run-launch.d.ts +9 -1
- package/dist/store/sqlite/run-launch.js +24 -13
- package/dist/store/sqlite/run-patch.d.ts +1 -1
- package/dist/store/sqlite/run-patch.js +13 -4
- package/dist/store/sqlite/store.js +76 -16
- package/dist/store/store.d.ts +53 -3
- package/dist/store/store.js +27 -0
- package/dist/store-reads/learning.d.ts +6 -3
- package/dist/store-reads/learning.js +22 -7
- package/dist/store-view.d.ts +3 -0
- package/dist/store-view.js +4 -4
- package/dist/suggestions.js +3 -2
- package/dist/template-eval.d.ts +22 -11
- package/dist/template-eval.js +124 -41
- package/dist/template-import.d.ts +10 -0
- package/dist/template-import.js +16 -7
- package/dist/templates.d.ts +10 -2
- package/dist/templates.js +28 -8
- package/dist/timeline/index.d.ts +1 -1
- package/dist/timeline/index.js +1 -1
- package/dist/timeline/labels.d.ts +6 -4
- package/dist/timeline/labels.js +18 -6
- package/dist/timeline/timeline.d.ts +17 -7
- package/dist/timeline/timeline.js +28 -14
- package/dist/timeline/util.js +1 -1
- package/dist/timeline/web-calls.d.ts +26 -9
- package/dist/timeline/web-calls.js +124 -37
- package/dist/tool-gate.d.ts +42 -3
- package/dist/tool-gate.js +69 -6
- package/dist/tool-keys-store.d.ts +2 -4
- package/dist/tool-keys-store.js +5 -21
- package/dist/tool-keys.d.ts +2 -2
- package/dist/tool-keys.js +2 -2
- package/dist/tool-list.js +1 -1
- package/dist/tool-plane.d.ts +2 -2
- package/dist/tool-plane.js +35 -33
- package/dist/tools.js +13 -7
- package/dist/trigger-targets.d.ts +4 -0
- package/dist/trigger-targets.js +9 -2
- package/dist/triggers.d.ts +67 -4
- package/dist/triggers.js +171 -22
- package/dist/until.d.ts +3 -0
- package/dist/until.js +11 -0
- package/dist/validate.js +1 -1
- package/dist/web-fake.d.ts +1 -3
- package/dist/web-fake.js +7 -18
- package/dist/web-fetch.d.ts +6 -72
- package/dist/web-fetch.js +11 -265
- package/dist/web-run.d.ts +31 -0
- package/dist/web-run.js +90 -0
- package/dist/web-save.d.ts +6 -4
- package/dist/web-save.js +9 -12
- package/dist/web-search.d.ts +9 -127
- package/dist/web-search.js +23 -259
- package/dist/wires.d.ts +13 -0
- package/dist/wires.js +11 -0
- package/dist/workflow-run.d.ts +5 -4
- package/dist/workflow-run.js +5 -4
- package/dist/workspace/computer-deps.d.ts +3 -1
- package/dist/workspace/computer-deps.js +12 -4
- package/dist/workspace/computer-for-claim.d.ts +19 -2
- package/dist/workspace/computer-for-claim.js +101 -13
- package/dist/workspace/computer-janitor.d.ts +15 -7
- package/dist/workspace/computer-janitor.js +33 -8
- package/dist/workspace/computer-kept.d.ts +55 -4
- package/dist/workspace/computer-kept.js +129 -8
- package/dist/workspace/index.d.ts +1 -1
- package/dist/workspace/index.js +1 -1
- package/dist/workspace/kind-skills.d.ts +4 -0
- package/dist/workspace/kind-skills.js +9 -0
- package/dist/workspace/run-end-computers.d.ts +5 -1
- package/dist/workspace/run-end-computers.js +27 -1
- package/dist/workspace/synced-folder.js +3 -4
- package/dist/wrapped.d.ts +65 -0
- package/dist/wrapped.js +77 -0
- package/package.json +17 -11
- package/skills/agentrun-serve/SKILL.md +4 -0
- package/templates/README.md +38 -15
- package/dist/console/assets/index-DUYLaqiR.js +0 -746
- package/dist/console/assets/index-DYhU4adm.css +0 -1
- package/dist/exa-keyless.d.ts +0 -34
- package/dist/exa-keyless.js +0 -118
- package/dist/firecrawl-keyless.d.ts +0 -41
- package/dist/firecrawl-keyless.js +0 -152
- package/dist/keyless-mcp.d.ts +0 -36
- package/dist/keyless-mcp.js +0 -127
- package/dist/text-urls.d.ts +0 -38
- package/dist/text-urls.js +0 -170
- package/dist/web-fetch-direct.d.ts +0 -119
- package/dist/web-fetch-direct.js +0 -190
package/dist/learn/secrets.js
CHANGED
|
@@ -1,60 +1,5 @@
|
|
|
1
1
|
import { posix } from "node:path";
|
|
2
|
-
|
|
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 { CREDENTIAL_NAMES, cutSpans, holds, MONEY_SHAPES, planCut, SECRET_SHAPES, shapeKinds, squeeze } 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) =>
|
|
67
|
-
/**
|
|
68
|
-
|
|
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) =>
|
|
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,84 +21,91 @@ 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
|
-
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
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. `held`: spans of `text` cut in place
|
|
29
|
+
* beside the finds (heldSpans, of values no longer at hand). */
|
|
30
|
+
export function redactSecrets(text, values, max = PRINT_MAX, held = []) {
|
|
31
|
+
return redactWith(text, values, max, SECRET_SHAPES, held);
|
|
32
|
+
}
|
|
33
|
+
/** Where redactSecrets cuts `values` in `text`, shapes left out: each span it cuts in place (UTF-16 offsets, overlapping
|
|
34
|
+
* ones merged, in order), or "whole" when its checks over them cut the text whole (a value split by a line break,
|
|
35
|
+
* percent encoded, an NFKC variant, read in the text as it came: redact/match.ts planCut). What a run's census keeps of
|
|
36
|
+
* a file, never the values (run-census.ts): redactSecrets given these spans as `held` cuts the text as it would have
|
|
37
|
+
* with the values among its own. */
|
|
38
|
+
export function heldSpans(text, values) {
|
|
39
|
+
const cut = planCut(text, derivedOf(values), []);
|
|
40
|
+
return cut === "whole" ? "whole" : cut.spans;
|
|
141
41
|
}
|
|
142
42
|
/** `text` as redactSecrets cuts it, and of a bank's numbers beside their words too (MONEY_SHAPES): what learning prints
|
|
143
43
|
* 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
44
|
* may show its user an account number. */
|
|
145
45
|
export function redactLearned(text, values, max = PRINT_MAX) {
|
|
146
|
-
return redactWith(text, values, max,
|
|
46
|
+
return redactWith(text, values, max, LEARNED_SHAPES);
|
|
147
47
|
}
|
|
148
|
-
/** redactSecrets
|
|
149
|
-
* text
|
|
150
|
-
|
|
48
|
+
/** redactSecrets, and where it cut: the spans of `text` cut in place and the text so cut, or "whole" where redactSecrets
|
|
49
|
+
* answers "[redacted]". A reader that redacts a text in pieces (key-refusal.ts) reads the pieces as they came for a
|
|
50
|
+
* value split across them (valueLeft), each piece's cuts covering it. */
|
|
51
|
+
export function cutSecrets(text, values, max = PRINT_MAX) {
|
|
52
|
+
if (Buffer.byteLength(text) > max)
|
|
53
|
+
return "whole";
|
|
54
|
+
return planCut(text, derivedOf(values), SECRET_SHAPES);
|
|
55
|
+
}
|
|
56
|
+
/** Whether `text` holds one of `values` in a form valueMatcher finds, a character of which no cut covers: what
|
|
57
|
+
* a reader that cut `text` there would still show of it. The cuts are `cuts` (merged spans of `text`, in order: where a
|
|
58
|
+
* reader that cut it in pieces cut each), or else those redactSecrets makes of `text` whole (its values' forms, hexes
|
|
59
|
+
* and folded identifiers, and the secret shapes, found as they stand). */
|
|
60
|
+
export function valueLeft(text, values, cuts) {
|
|
61
|
+
const needles = derivedOf(values);
|
|
62
|
+
return holds(text, needles, { cuts: cuts ?? cutSpans(text, needles, SECRET_SHAPES) });
|
|
63
|
+
}
|
|
64
|
+
/** redactSecrets over `shapes`, each found in place, and `held` spans cut beside them (redact/match.ts planCut). */
|
|
65
|
+
function redactWith(text, values, max, shapes, held = []) {
|
|
151
66
|
if (Buffer.byteLength(text) > max)
|
|
152
67
|
return "[redacted]";
|
|
153
|
-
const
|
|
154
|
-
|
|
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;
|
|
68
|
+
const cut = planCut(text, derivedOf(values), shapes, held);
|
|
69
|
+
return cut === "whole" ? "[redacted]" : cut.out;
|
|
167
70
|
}
|
|
168
|
-
/** Each value set's
|
|
71
|
+
/** 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
72
|
* 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
|
|
73
|
+
* alignments, percent forms, folded needles, for every value, a private key's PEM among them) took seconds per view.
|
|
171
74
|
* An array whose values changed since is derived again, never served a stale set: what a caller adds is always cut. */
|
|
172
75
|
const DERIVED = new WeakMap();
|
|
76
|
+
/** What the matcher looks for of a set of values, whatever the text: each value, each string of a held JSON value
|
|
77
|
+
* that may be printed alone (heldFields) and their path spellings, their forms found as they stand (as written, as
|
|
78
|
+
* JSON writes it, their plain needles and percent forms), their hex and folded needles, the needles the whole-text
|
|
79
|
+
* check reads (redact/match.ts Needles), and the parts of each of many lines (partsOf), as written and squeezed: of
|
|
80
|
+
* each value but a JSON object or array, and of each string heldFields holds. */
|
|
173
81
|
function derivedOf(values) {
|
|
174
82
|
const kept = DERIVED.get(values);
|
|
175
83
|
if (kept && kept.values.length === values.length && kept.values.every((value, at) => value === values[at]))
|
|
176
84
|
return kept.derived;
|
|
177
|
-
const
|
|
85
|
+
const held = values.filter((v) => v.length > 0);
|
|
86
|
+
const fields = held.map(heldFields);
|
|
87
|
+
const strings = fields.flatMap((of) => of ?? []);
|
|
88
|
+
const whole = [...held, ...strings];
|
|
89
|
+
const given = withPathSpellings(whole);
|
|
178
90
|
const needles = new Map(given.filter(longEnough).map((v) => [v, needlesOf(v)]));
|
|
91
|
+
// A held JSON value's own lines are no parts of it (a pretty-printed one has its public strings on lines of their
|
|
92
|
+
// own); the strings heldFields holds of it have theirs.
|
|
93
|
+
const parts = [...new Set([...held.filter((_, at) => fields[at] === undefined), ...strings].flatMap(partsOf))];
|
|
179
94
|
const derived = {
|
|
180
|
-
forms: [...new Set(given.flatMap((v) => {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
hexes: [...needles.values()].map((of) =>
|
|
185
|
-
folds: [...needles.values()].flatMap((of) => of.folded
|
|
186
|
-
|
|
187
|
-
match: spelledMatcher(given),
|
|
95
|
+
forms: [...new Set([...given.flatMap((v) => {
|
|
96
|
+
const of = needles.get(v);
|
|
97
|
+
return [v, asJson(v), ...(of ? [...of.plain, ...percentForms(v)] : [])];
|
|
98
|
+
}), ...parts].filter((form) => form.length > 0))],
|
|
99
|
+
hexes: [...needles.values()].map((of) => of.hex),
|
|
100
|
+
folds: [...needles.values()].flatMap((of) => of.folded),
|
|
101
|
+
plain: [...new Set([...[...needles.values()].flatMap((of) => of.plain), ...parts.map(squeeze)])],
|
|
188
102
|
};
|
|
189
103
|
DERIVED.set(values, { values: [...values], derived });
|
|
190
104
|
return derived;
|
|
191
105
|
}
|
|
192
|
-
/**
|
|
193
|
-
|
|
194
|
-
|
|
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
|
-
}
|
|
106
|
+
/** What the matcher looks for of `values` (derivedOf, cached by array): the scrubber's held rule (secret-rules.ts) cuts
|
|
107
|
+
* each form, hex and folded identifier in place with redact/match.ts cutSpans. */
|
|
108
|
+
export const heldNeedles = (values) => derivedOf(values);
|
|
210
109
|
/** A value shorter than this matches too much text by chance to be refused. */
|
|
211
110
|
export const MIN_SECRET = 8;
|
|
212
111
|
/** An excerpt of a run's input or answer as learning keeps it: `text` cut of the secrets `shown` knows, whole, then
|
|
@@ -221,7 +120,6 @@ export function excerptShown(text, shown, max) {
|
|
|
221
120
|
const end = /[\uD800-\uDBFF]/.test(clean.charAt(max - 1)) ? max - 1 : max;
|
|
222
121
|
return `${clean.slice(0, end)}…`;
|
|
223
122
|
}
|
|
224
|
-
const squeeze = (text) => text.normalize("NFKC").replace(/\s+/gu, "");
|
|
225
123
|
/** The base64 of `secret` as it can sit inside a longer blob: the characters that depend on the secret's bytes alone,
|
|
226
124
|
* at each of the three alignments, in both alphabets. */
|
|
227
125
|
function base64Needles(secret) {
|
|
@@ -234,9 +132,6 @@ function base64Needles(secret) {
|
|
|
234
132
|
}
|
|
235
133
|
return [...out];
|
|
236
134
|
}
|
|
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
135
|
const asJson = (value) => JSON.stringify(value).slice(1, -1);
|
|
241
136
|
/** A path with each run of "/" collapsed to one, each "." segment dropped ("/./", a leading "./") and a leading and a
|
|
242
137
|
* trailing "/" dropped, as a resolver writes it. */
|
|
@@ -308,8 +203,6 @@ function foldedOf(value) {
|
|
|
308
203
|
}
|
|
309
204
|
return [...out];
|
|
310
205
|
}
|
|
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
206
|
/** What a matcher looks for of `value`: its forms as they stand in a squeezed text (plain, as JSON writes it, base64 or
|
|
314
207
|
* base64url), its hex, in any case, and its hex identifiers folded (foldedOf). */
|
|
315
208
|
function needlesOf(value) {
|
|
@@ -317,22 +210,90 @@ function needlesOf(value) {
|
|
|
317
210
|
return { plain: [...new Set([squeeze(value), squeeze(asJson(value)), ...base64Needles(raw)])], hex: raw.toString("hex"), folded: foldedOf(value) };
|
|
318
211
|
}
|
|
319
212
|
const longEnough = (value) => [...value].length >= MIN_SECRET;
|
|
213
|
+
/** The fewest characters a line of a held value must have to be held as a part of it: a key's base64 line (64) is, a
|
|
214
|
+
* short line any text may hold ("-----END …-----", "}", a JSON field's name and a word) is not. */
|
|
215
|
+
const LINE_MIN = 40;
|
|
216
|
+
const ARMOR_BEGIN = /^-----BEGIN [^-]*-----$/;
|
|
217
|
+
const ARMOR_END = /^-----END [^-]*-----$/;
|
|
218
|
+
/** The parts of a held value of many lines that a reader may print without the rest (`head -n 11 key.pem`, a body
|
|
219
|
+
* with its armor stripped), each held as itself, found as it stands and cut in place, and found in each view: each
|
|
220
|
+
* line of its body of LINE_MIN characters or more, and its body with its line breaks gone. Its body is its lines but
|
|
221
|
+
* a first "-----BEGIN …-----" and a last "-----END …-----", its armor. A key's last body line is mostly shorter than
|
|
222
|
+
* LINE_MIN: one of MIN_SECRET characters or more is held with the END line after it, as written (`tail -n 2 key.pem`).
|
|
223
|
+
* A value of one line has none: it is matched whole. */
|
|
224
|
+
function partsOf(value) {
|
|
225
|
+
const lines = value.split(/\r\n|\r|\n/).map((line) => line.trim()).filter((line) => line.length > 0);
|
|
226
|
+
if (lines.length < 2)
|
|
227
|
+
return [];
|
|
228
|
+
const armored = ARMOR_END.test(lines.at(-1));
|
|
229
|
+
const body = lines.slice(ARMOR_BEGIN.test(lines[0]) ? 1 : 0, armored ? -1 : lines.length);
|
|
230
|
+
const parts = [...body.filter((line) => line.length >= LINE_MIN), body.join("")];
|
|
231
|
+
const last = body.at(-1);
|
|
232
|
+
if (armored && last !== undefined && last.length >= MIN_SECRET && last.length < LINE_MIN) {
|
|
233
|
+
const end = lines.at(-1);
|
|
234
|
+
const endAt = value.lastIndexOf(end);
|
|
235
|
+
parts.push(value.slice(value.lastIndexOf(last, endAt), endAt + end.length));
|
|
236
|
+
}
|
|
237
|
+
return parts.filter(longEnough);
|
|
238
|
+
}
|
|
239
|
+
/** Whether a held JSON value's string under the key `name` is a secret by its name (heldFields): its name with its
|
|
240
|
+
* separators dropped and lowered names a secret, a password, a token, a private value, a credential or an API key, or
|
|
241
|
+
* ends in "key" ("aws_secret_access_key", "SessionToken", "signing_secret", "private_key", "secret_key"); or, lowered,
|
|
242
|
+
* it is a credential parameter's whole name (redact/match.ts CREDENTIAL_NAMES: "signature"). Never one that names a
|
|
243
|
+
* public thing by its end (an id, a URI or URL, a type, an email, an endpoint, an expiry: "client_id", "token_uri",
|
|
244
|
+
* "access_key_id", "token_type"), a public key, or a token that is none (a page's, the next page's). */
|
|
245
|
+
function secretName(name) {
|
|
246
|
+
const flat = name.toLowerCase().replace(/[-_.\s]/g, "");
|
|
247
|
+
if (/(?:uri|url|id|type|email|endpoint|expiry|expires|pagetoken|nexttoken)$/.test(flat) || flat.includes("public"))
|
|
248
|
+
return false;
|
|
249
|
+
return /secret|password|passwd|token|private|credential|apikey/.test(flat) || flat.endsWith("key") || CREDENTIAL_NAMES.has(name.toLowerCase());
|
|
250
|
+
}
|
|
251
|
+
/** A JWK's private members (RFC 7518: an EC or OKP key's "d", an RSA key's "d", "p", "q", "dp", "dq" and "qi", a
|
|
252
|
+
* symmetric key's "k"), held in an object with a "kty" only: elsewhere a one-letter name says nothing. */
|
|
253
|
+
const JWK_PRIVATE = new Set(["d", "p", "q", "dp", "dq", "qi", "k"]);
|
|
254
|
+
/** The strings of a held JSON value (an object or an array, as it parses, at any depth) that may be printed alone, each
|
|
255
|
+
* held as itself (trimmed), as any held value: one that holds a line break (a service account's private key, `jq -r
|
|
256
|
+
* .private_key`), one whose key names a secret (secretName: an OAuth client's "client_secret", an AWS secret access
|
|
257
|
+
* key; never "page_token"), and a JWK's private member beside its "kty" (JWK_PRIVATE). An array's items have no key,
|
|
258
|
+
* so only the line-break rule holds them. Its other strings are not held: an id, a project, an email and public URLs
|
|
259
|
+
* ("client_id", "token_uri") are no secret, and would be cut wherever a text names them. Undefined where `value` is no
|
|
260
|
+
* JSON object or array. */
|
|
261
|
+
function heldFields(value) {
|
|
262
|
+
const head = value.trimStart()[0];
|
|
263
|
+
if (head !== "{" && head !== "[")
|
|
264
|
+
return undefined;
|
|
265
|
+
let parsed;
|
|
266
|
+
try {
|
|
267
|
+
parsed = JSON.parse(value);
|
|
268
|
+
}
|
|
269
|
+
catch {
|
|
270
|
+
return undefined;
|
|
271
|
+
}
|
|
272
|
+
const out = [];
|
|
273
|
+
// Walked with a stack of its own, not a call per level: a value nested thousands deep is read as any other.
|
|
274
|
+
// Each node with its key and whether its object is a JWK (holds a "kty").
|
|
275
|
+
const stack = [[parsed, undefined, false]];
|
|
276
|
+
for (let next = stack.pop(); next !== undefined; next = stack.pop()) {
|
|
277
|
+
const [node, key, jwk] = next;
|
|
278
|
+
if (typeof node === "string") {
|
|
279
|
+
if (/[\r\n]/.test(node) || (key !== undefined && (secretName(key) || (jwk && JWK_PRIVATE.has(key)))))
|
|
280
|
+
out.push(node.trim());
|
|
281
|
+
}
|
|
282
|
+
else if (Array.isArray(node))
|
|
283
|
+
for (const item of node)
|
|
284
|
+
stack.push([item, undefined, false]);
|
|
285
|
+
else if (node !== null && typeof node === "object") {
|
|
286
|
+
const kty = typeof node.kty === "string";
|
|
287
|
+
for (const [name, item] of Object.entries(node))
|
|
288
|
+
stack.push([item, name, kty]);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
return out.filter(longEnough);
|
|
292
|
+
}
|
|
320
293
|
/** A matcher for `values` in a text: plain, split by whitespace, as JSON writes it, percent or form encoded, base64 or
|
|
321
294
|
* 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
|
|
323
|
-
* whole-text check). */
|
|
295
|
+
* shorter than MIN_SECRET are left out. `fold: false`, the matcher without the folded needles. */
|
|
324
296
|
export function valueMatcher(values, { fold = true } = {}) {
|
|
325
|
-
|
|
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
|
-
};
|
|
297
|
+
const needles = derivedOf(values);
|
|
298
|
+
return (text) => holds(text, needles, { fold });
|
|
338
299
|
}
|
package/dist/learning-cost.d.ts
CHANGED
|
@@ -100,8 +100,10 @@ export type AfterState = (typeof AFTER_STATES)[number];
|
|
|
100
100
|
* leaves learning out and the after side keeps it in, so the figure never flatters learning. `withheld`: after a
|
|
101
101
|
* takeover, how many runs either side reads have an unknown cost and how many one known only as at most
|
|
102
102
|
* (`cost_upper_bound`); while any does there is no ratio, null when none does. `hand_backs`: of the served runs from
|
|
103
|
-
* the takeover on, how many handed back
|
|
104
|
-
*
|
|
103
|
+
* the takeover on (`ran`), how many the workflow handed back itself (`back`: an escalate, a failed step, an answer cut
|
|
104
|
+
* by size or schema) and how many a restart cut (`cut`: the run ids `cut` names, its call ended `interrupted`,
|
|
105
|
+
* metrics.workflow_cut); null before a takeover. A cut run stays `handed_back` at agent cost: only the count moves.
|
|
106
|
+
* `replay`: the serving promotion's, as given. Every one is over every run, never only the latest a read lists. */
|
|
105
107
|
export type CostSummary = {
|
|
106
108
|
takeover: {
|
|
107
109
|
n: number;
|
|
@@ -120,6 +122,7 @@ export type CostSummary = {
|
|
|
120
122
|
hand_backs: {
|
|
121
123
|
ran: number;
|
|
122
124
|
back: number;
|
|
125
|
+
cut: number;
|
|
123
126
|
} | null;
|
|
124
127
|
withheld: {
|
|
125
128
|
unknown: number;
|
|
@@ -127,7 +130,7 @@ export type CostSummary = {
|
|
|
127
130
|
} | null;
|
|
128
131
|
replay: CostReplay | null;
|
|
129
132
|
};
|
|
130
|
-
export declare function costSummary(runs: readonly CostRun[], replay?: CostReplay | null): CostSummary;
|
|
133
|
+
export declare function costSummary(runs: readonly CostRun[], replay?: CostReplay | null, cut?: ReadonlySet<string>): CostSummary;
|
|
131
134
|
/** The paths of the runs that do a job: the bill's run index counts these. A replay checks a revision and an audit's
|
|
132
135
|
* shadow audits a run: their spend is learning, booked where it falls (billOf) and carried by the runs they serve. */
|
|
133
136
|
export declare const JOB_PATHS: readonly RunPath[];
|
package/dist/learning-cost.js
CHANGED
|
@@ -67,7 +67,7 @@ export function tookOverOf(runs) {
|
|
|
67
67
|
/** Why the after side has a figure or not: `priced`, it has; `no_served_runs`, no learned workflow has taken over (a
|
|
68
68
|
* replay is no served run); `cost_unknown`, runs were served but none's all-in cost is known exactly. */
|
|
69
69
|
export const AFTER_STATES = ["priced", "no_served_runs", "cost_unknown"];
|
|
70
|
-
export function costSummary(runs, replay = null) {
|
|
70
|
+
export function costSummary(runs, replay = null, cut = new Set()) {
|
|
71
71
|
const first = runs.findIndex((run) => SERVED_PATHS.includes(run.path));
|
|
72
72
|
const beforeSide = (first < 0 ? runs : runs.slice(0, first)).filter((run) => run.path === "agent").map((run) => ({ value: run.cost_usd, bound: run.cost_upper_bound }));
|
|
73
73
|
// Served runs alone: a replay (a check of a new revision, at workflow cost) and a run by hand are never the after side.
|
|
@@ -85,7 +85,9 @@ export function costSummary(runs, replay = null) {
|
|
|
85
85
|
const atMost = read.filter(({ bound }) => bound).length;
|
|
86
86
|
const withheld = first >= 0 && unknown + atMost > 0 ? { unknown, at_most: atMost } : null;
|
|
87
87
|
const times = !withheld && before && after && after.runs >= CHEAPER_AFTER_RUNS && after.mean_usd > 0 ? Math.round((before.mean_usd / after.mean_usd) * 10) / 10 : null;
|
|
88
|
-
const
|
|
88
|
+
const handedBack = served.filter((run) => run.path === "handed_back");
|
|
89
|
+
const cutBack = handedBack.filter((run) => cut.has(run.run_id)).length;
|
|
90
|
+
const handBacks = first < 0 ? null : { ran: served.length, back: handedBack.length - cutBack, cut: cutBack };
|
|
89
91
|
const afterState = after ? "priced" : first < 0 ? "no_served_runs" : "cost_unknown";
|
|
90
92
|
return { takeover: first < 0 ? null : { n: runs[first].n, run_id: runs[first].run_id }, before, after, after_state: afterState, times_cheaper: times, hand_backs: handBacks, withheld, replay };
|
|
91
93
|
}
|
package/dist/link-check.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
// sets equal, and each value equal, except that a call's value read as "…" (a timeline read elides query values,
|
|
7
7
|
// scrubUrls) matches any value for its key. Structural only: whether a cited item is in scope stays the rubric's call.
|
|
8
8
|
import { lastJsonBlock } from "./answer-json.js";
|
|
9
|
-
import { linksOf, linksWritten, TRAILING, trimmed, wholeUrl } from "
|
|
9
|
+
import { linksOf, linksWritten, TRAILING, trimmed, wholeUrl } from "@parcha/agentrun-web";
|
|
10
10
|
import { scrubUrl } from "./timeline/index.js";
|
|
11
11
|
import { WEB_FETCH_TOOL } from "./web-fetch.js";
|
|
12
12
|
import { WEB_SEARCH_TOOL } from "./web-search.js";
|
package/dist/llms.txt
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
> The open platform's server for agents: make an agent (a prompt with tools, or a typed workflow), run it, and read what it did, over one HTTP API at `/v2`, an MCP endpoint at `/v2/mcp`, and a CLI. Every run is kept, with its timeline, its files and its cost.
|
|
4
4
|
|
|
5
|
-
Auth: the API's routes take `Authorization: Bearer <token>`, all but `GET /v2/health`, `GET /v2/capabilities` and `GET /v2/openapi.json`; this file needs none. The MCP endpoint takes the Bearer token only. The token is the server's data directory's `.token` (`--data DIR`; without it, `$XDG_DATA_HOME/agentrun/agents`, else `~/.local/share/agentrun/agents`), or `AGENTRUN_TOKEN` when the server was started with it. Never print it. Links below are relative to this server.
|
|
5
|
+
Auth: the API's routes take `Authorization: Bearer <token>`, all but `GET /v2/health`, `GET /v2/capabilities` and `GET /v2/openapi.json`; this file needs none. The MCP endpoint takes the Bearer token only. The token is the server's data directory's `.token` (`--data DIR`; without it, `$XDG_DATA_HOME/agentrun/agents`, else `~/.local/share/agentrun/agents`), or `AGENTRUN_TOKEN` when the server was started with it. An API key the owner made in the console (Settings, AgentRun API keys; it starts `ar_key_`) is taken wherever the token is, except as the setup code; only the owner's signed-in session makes or revokes one. Never print it. Links below are relative to this server.
|
|
6
6
|
|
|
7
7
|
## Start
|
|
8
8
|
|
|
@@ -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
|
|
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.
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
export declare const MARKETPLACE_URL = "https://marketplace.agentrun.ai";
|
|
2
|
+
export declare const MARKETPLACE_ENV = "AGENTRUN_MARKETPLACE";
|
|
3
|
+
/** How long a list read is answered before it is read again: the site's own cache-control (max-age=300). */
|
|
4
|
+
export declare const MARKETPLACE_TTL_MS: number;
|
|
5
|
+
/** How long a failed read is answered before the next try, so a console open on an offline server asks the network
|
|
6
|
+
* once a minute, not on every page. */
|
|
7
|
+
export declare const MARKETPLACE_RETRY_MS = 60000;
|
|
8
|
+
/** What one read may take: the list's bytes (today's is 68 KB), its entries, and the time the read may last. */
|
|
9
|
+
export declare const MARKETPLACE_LIMITS: {
|
|
10
|
+
readonly bytes: number;
|
|
11
|
+
readonly entries: 1000;
|
|
12
|
+
readonly ms: 10000;
|
|
13
|
+
};
|
|
14
|
+
/** One template on the marketplace. `title`, its display name; `summary`, its card's one line; `description`, the rest;
|
|
15
|
+
* `needs`, what it requires, in the marketplace's words; `harness`, its package's harness preference list (empty: any
|
|
16
|
+
* harness; left out when the list does not say), display only; `page_url`, its page there; `source`, the package an install
|
|
17
|
+
* reads (`github:<owner>/<repo>[/<path>]@<sha>`), when the list names one; `here`, the id of this server's package that
|
|
18
|
+
* is this one, when there is one (a bundled package by its name, or one imported from its source). */
|
|
19
|
+
export type MarketplaceTemplate = {
|
|
20
|
+
name: string;
|
|
21
|
+
title: string;
|
|
22
|
+
summary?: string;
|
|
23
|
+
description?: string;
|
|
24
|
+
category?: string;
|
|
25
|
+
tags: string[];
|
|
26
|
+
needs: string[];
|
|
27
|
+
harness?: string[];
|
|
28
|
+
page_url: string;
|
|
29
|
+
source?: string;
|
|
30
|
+
};
|
|
31
|
+
export type MarketplaceAnswer = {
|
|
32
|
+
/** The site read, or null when the marketplace is off here. */
|
|
33
|
+
url: string | null;
|
|
34
|
+
/** `read`: the list as read within the last 5 minutes; `stale`: the last read failed, and this is the list as read at
|
|
35
|
+
* `read_at`; `unreachable`: no read has worked yet, so the list is empty; `off`: this server reads no marketplace. */
|
|
36
|
+
state: "read" | "stale" | "unreachable" | "off";
|
|
37
|
+
read_at: string | null;
|
|
38
|
+
/** Why the last read failed (`stale`, `unreachable`), or why the marketplace is off. */
|
|
39
|
+
problem?: string;
|
|
40
|
+
templates: (MarketplaceTemplate & {
|
|
41
|
+
here?: string;
|
|
42
|
+
})[];
|
|
43
|
+
};
|
|
44
|
+
/** The marketplace this server reads, from the environment: its address, or null for off. Unset, the public one, except
|
|
45
|
+
* under --faux (a test's or a demo's server, which reaches no network unasked). `off` (or 0, false) turns it off. An
|
|
46
|
+
* address is an https origin (with a path, when the site is served under one); http is taken for a loopback host
|
|
47
|
+
* alone, a local copy of the site. Anything else stops the start: the owner set it, and a typo should not read as off. */
|
|
48
|
+
export declare function marketplaceUrlOf(env: NodeJS.ProcessEnv, faux: boolean): string | null;
|
|
49
|
+
/** One entry of the list read as a template, or undefined for one that is not (no name of a package's shape): an entry's
|
|
50
|
+
* other fields are kept where they are of their shape and dropped where not, so one odd field never hides a template. */
|
|
51
|
+
export declare function entryOf(raw: unknown, site: string): MarketplaceTemplate | undefined;
|
|
52
|
+
/** The list's JSON read as templates, in its order, each name once (its first entry), at most MARKETPLACE_LIMITS.entries.
|
|
53
|
+
* Anything but a list is the read's failure. */
|
|
54
|
+
export declare function listOf(json: unknown, site: string): MarketplaceTemplate[];
|
|
55
|
+
/** The package here that a marketplace entry is, by id: with a source, the package imported from it, else the bundled
|
|
56
|
+
* package of its name when the source is where this server's own packages live; with none (a list that names no
|
|
57
|
+
* sources), the package of its name, a bundled one first. */
|
|
58
|
+
export declare function hereOf(entry: Pick<MarketplaceTemplate, "name" | "source">, packages: readonly {
|
|
59
|
+
id: string;
|
|
60
|
+
name: string;
|
|
61
|
+
origin: unknown;
|
|
62
|
+
}[]): string | undefined;
|
|
63
|
+
/** The marketplace's list as this server reads it: on demand, kept MARKETPLACE_TTL_MS, one read at a time however many
|
|
64
|
+
* ask, and the last good list kept through a failed read. `fetchImpl`, `now` and `deadlineMs` (the read's time limit,
|
|
65
|
+
* MARKETPLACE_LIMITS.ms unless said) are a test's seams. */
|
|
66
|
+
export declare class Marketplace {
|
|
67
|
+
#private;
|
|
68
|
+
readonly url: string | null;
|
|
69
|
+
constructor(url: string | null, options?: {
|
|
70
|
+
fetchImpl?: typeof fetch;
|
|
71
|
+
now?: () => number;
|
|
72
|
+
deadlineMs?: number;
|
|
73
|
+
});
|
|
74
|
+
list(): Promise<Omit<MarketplaceAnswer, "templates"> & {
|
|
75
|
+
templates: MarketplaceTemplate[];
|
|
76
|
+
}>;
|
|
77
|
+
}
|