@parcha/agentrun-serve 0.1.0-beta.56 → 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 +229 -0
- package/README.md +201 -52
- package/dist/acp-package.d.ts +2 -0
- package/dist/adapters.d.ts +15 -3
- package/dist/adapters.js +17 -6
- package/dist/agent-package.d.ts +3 -3
- package/dist/agent-package.js +17 -8
- 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 +34 -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/chatgpt-plan.d.ts +18 -8
- package/dist/chatgpt-plan.js +91 -34
- package/dist/claude-login.d.ts +74 -16
- package/dist/claude-login.js +215 -56
- package/dist/claude-sign-in.d.ts +17 -6
- package/dist/claude-sign-in.js +42 -39
- 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-Boh7tC4i.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/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 +9 -4
- package/dist/key-refusal.js +107 -25
- package/dist/learn/secrets.d.ts +13 -3
- package/dist/learn/secrets.js +118 -17
- 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 +1 -1
- 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.js +178 -27
- 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/provider.d.ts +9 -0
- package/dist/provider.js +50 -3
- package/dist/redact/match.d.ts +30 -3
- package/dist/redact/match.js +422 -41
- 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 +2 -0
- package/dist/run-timeline-served.js +2 -2
- 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 +11 -0
- package/dist/runner/adapter-loop.js +55 -10
- package/dist/runner/adapter-run-spec.d.ts +45 -8
- package/dist/runner/adapter-run-spec.js +150 -28
- package/dist/runner/adapters/pi.js +25 -3
- package/dist/runner/beside.js +4 -3
- 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 +82 -35
- 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/main.js +7 -2
- 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/run-child-host.d.ts +3 -0
- package/dist/runner/run-child-host.js +69 -28
- package/dist/runner/run-child.js +5 -2
- package/dist/runner/runner.d.ts +14 -3
- package/dist/runner/runner.js +129 -33
- 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 +52 -11
- package/dist/server.js +345 -118
- package/dist/skills/agentrun-serve/SKILL.md +4 -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/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 +34 -4
- package/dist/store/store.d.ts +43 -2
- package/dist/store/store.js +20 -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 +3 -3
- package/dist/suggestions.js +3 -2
- package/dist/template-eval.d.ts +20 -9
- package/dist/template-eval.js +115 -33
- 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/labels.d.ts +6 -4
- package/dist/timeline/labels.js +18 -6
- package/dist/timeline/timeline.d.ts +5 -0
- package/dist/timeline/timeline.js +14 -8
- 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 +66 -5
- 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/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 +2 -1
- package/dist/workspace/computer-deps.js +9 -2
- package/dist/workspace/computer-for-claim.d.ts +12 -1
- package/dist/workspace/computer-for-claim.js +77 -8
- package/dist/workspace/computer-kept.d.ts +3 -0
- package/dist/workspace/computer-kept.js +11 -2
- 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/synced-folder.js +3 -4
- package/dist/wrapped.d.ts +13 -5
- package/dist/wrapped.js +52 -26
- package/package.json +17 -11
- package/skills/agentrun-serve/SKILL.md +4 -0
- package/templates/README.md +30 -8
- package/dist/console/assets/index-CQ3cJRzI.js +0 -746
- package/dist/console/assets/index-DKkaS3a0.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/harness.js
CHANGED
|
@@ -36,7 +36,8 @@ async function withoutModelKeys(env) {
|
|
|
36
36
|
export function harnessOffers(env) {
|
|
37
37
|
let offers = offered.get(env);
|
|
38
38
|
if (!offers) {
|
|
39
|
-
|
|
39
|
+
// A reading no run waits on (ollamaReading): each Ollama model is the kept listing's, at any age, never an /api/show.
|
|
40
|
+
offers = import("./ollama-provider.js").then(({ ollamaReading }) => ollamaReading(async () => {
|
|
40
41
|
const { hostMemory, neverFits } = await import("./host.js");
|
|
41
42
|
const memory = hostMemory();
|
|
42
43
|
const { harnessInstalled } = await import("./adapters.js");
|
|
@@ -78,6 +79,9 @@ export function harnessOffers(env) {
|
|
|
78
79
|
// so the picker never offers one a save would refuse. None for a harness that does not run here.
|
|
79
80
|
const entry = harnessOf(env, offer.id);
|
|
80
81
|
const models = [];
|
|
82
|
+
// Those of them a run takes now: its provider connected here (its key, or the ChatGPT sign-in where that is how
|
|
83
|
+
// it runs), not one that lacks only a key. The console's Model picker lists these first (GRE: filter by provider).
|
|
84
|
+
const ready = [];
|
|
81
85
|
// Whether any model it offers runs here now, not only lacks a key: its default lacking one leaves it available
|
|
82
86
|
// where another runs (noModelRuns).
|
|
83
87
|
let runsOne = false;
|
|
@@ -94,6 +98,7 @@ export function harnessOffers(env) {
|
|
|
94
98
|
const { factsOf } = await import("./harness-table.js");
|
|
95
99
|
const facts = factsOf(env, offer.id);
|
|
96
100
|
const { OLLAMA_PROVIDER, ollamaToolsModels } = await import("./ollama-provider.js");
|
|
101
|
+
const { serverKeyMissing } = await import("./run-model-key.js");
|
|
97
102
|
const toolsModels = ollamaToolsModels(env);
|
|
98
103
|
for (const id of new Set([...pickerCandidates(env, offer.id), ...free.map((m) => m.id)])) {
|
|
99
104
|
if (!MODEL_REF.test(id))
|
|
@@ -112,9 +117,16 @@ export function harnessOffers(env) {
|
|
|
112
117
|
lacksKey = true;
|
|
113
118
|
}
|
|
114
119
|
}
|
|
120
|
+
// A model whose route goes to the gateway runs only on a gateway key: the server's, or each run's own
|
|
121
|
+
// (model_key). Without the server's, a run that brings none is 422 model_key_required, so it is not ready.
|
|
122
|
+
if (!lacksKey && "model" in chosen && serverKeyMissing(env, { kind: "agentic", model: chosen.model }))
|
|
123
|
+
lacksKey = true;
|
|
115
124
|
models.push(id);
|
|
116
|
-
|
|
117
|
-
|
|
125
|
+
if (!lacksKey)
|
|
126
|
+
ready.push(id);
|
|
127
|
+
// A model of the Ollama here that takes no tools stays pickable, and a run on it gets its tools as text, but
|
|
128
|
+
// text tools are unreliable on small models: it is no model a run of this harness has now, as the host's
|
|
129
|
+
// default never is one (model.ts localDefault).
|
|
118
130
|
if (!lacksKey && (!id.startsWith(`${OLLAMA_PROVIDER}/`) || toolsModels.includes(id)))
|
|
119
131
|
runsOne = true;
|
|
120
132
|
}
|
|
@@ -125,9 +137,9 @@ export function harnessOffers(env) {
|
|
|
125
137
|
const wantsKey = offer.available ? resolved !== undefined && "why" in resolved && resolved.needs === "key" : Boolean(offer.keys?.length);
|
|
126
138
|
const sayWhy = !wantsKey ? {} : offer.available ? { reason: resolved.why } : offer.reason ? { reason: withPlanWords(env, offer.id, offer.reason) } : {};
|
|
127
139
|
const needs = wantsKey ? ["key", ...(planWouldRun(env, offer.id) ? ["chatgpt"] : [])] : [];
|
|
128
|
-
return { ...offer, ...sayWhy, default_model: resolved && "model" in resolved ? `${resolved.model.provider}/${resolved.model.modelId}` : null, models, free_models: free.filter((m) => models.includes(m.id)), run_memory_mib: entry.runMib, ...(needs.length ? { needs } : {}), ...(offer.available && needs.length && !runsOne ? { noModelRuns: true } : {}) };
|
|
140
|
+
return { ...offer, ...sayWhy, default_model: resolved && "model" in resolved ? `${resolved.model.provider}/${resolved.model.modelId}` : null, models, ready_models: ready, free_models: free.filter((m) => models.includes(m.id)), run_memory_mib: entry.runMib, ...(needs.length ? { needs } : {}), ...(offer.available && needs.length && !runsOne ? { noModelRuns: true } : {}) };
|
|
129
141
|
}));
|
|
130
|
-
})
|
|
142
|
+
}));
|
|
131
143
|
offered.set(env, offers);
|
|
132
144
|
}
|
|
133
145
|
return offers;
|
package/dist/hosted-search.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Models } from "@earendil-works/pi-ai";
|
|
2
|
-
import { type Search, type Searched } from "
|
|
2
|
+
import { type Search, type Searched } from "@parcha/agentrun-web";
|
|
3
3
|
export declare const HOSTED_MAX_USES = 5;
|
|
4
4
|
/** One search's results billed as input: about 25,000 tokens, a working estimate. */
|
|
5
5
|
export declare const SEARCH_INPUT_TOKENS = 25000;
|
package/dist/hosted-search.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { clip, TITLE_CAP } from "
|
|
2
|
-
import { ANSWER_MAX, snippetOf } from "./web-search.js";
|
|
1
|
+
import { ANSWER_MAX, clip, snippetOf, TITLE_CAP } from "@parcha/agentrun-web";
|
|
3
2
|
export const HOSTED_MAX_USES = 5;
|
|
4
3
|
/** One search's results billed as input: about 25,000 tokens, a working estimate. */
|
|
5
4
|
export const SEARCH_INPUT_TOKENS = 25_000;
|
package/dist/import-worker.d.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import "./quiet-sqlite-warning.js";
|
|
2
2
|
import { type ImportCandidate } from "./import.js";
|
|
3
|
+
import type { WrappedRead } from "./wrapped.js";
|
|
3
4
|
/** `secrets`: the server's own, cut out of everything the import writes and never put in an environment; the seal key
|
|
4
5
|
* among them, so the worker opens the saved tool keys the import cuts too (read over the port from the server's store). */
|
|
5
6
|
export type ImportTask = {
|
|
6
|
-
task: "plan" | "import";
|
|
7
|
+
task: "plan" | "import" | "wrapped";
|
|
7
8
|
data: string;
|
|
8
9
|
home: string;
|
|
9
10
|
temp?: string;
|
|
10
11
|
secrets?: Record<string, string>;
|
|
11
12
|
projects?: readonly string[];
|
|
13
|
+
year?: number;
|
|
12
14
|
};
|
|
13
15
|
/** `took`: what this start's import took (stopped too: what it took before it stopped), its agents by id, so the server
|
|
14
16
|
* adds it to what earlier starts took. */
|
|
@@ -25,4 +27,4 @@ export type ImportAnswer = {
|
|
|
25
27
|
stopped?: true;
|
|
26
28
|
} | {
|
|
27
29
|
stopped: true;
|
|
28
|
-
};
|
|
30
|
+
} | WrappedRead;
|
package/dist/import-worker.js
CHANGED
|
@@ -2,14 +2,16 @@
|
|
|
2
2
|
// every session line happen here, so neither holds up a request the server answers. `plan` counts what an import would
|
|
3
3
|
// take, and names its projects for the owner to choose from; `import` takes it, only the projects chosen when some were
|
|
4
4
|
// (`projects`). The message "stop" ends either between two files or two sessions; what is written stays, and
|
|
5
|
-
// the next import goes on from there.
|
|
5
|
+
// the next import goes on from there. `wrapped` reads a year of the home for GET /v2/wrapped (wrapped.ts), priced at
|
|
6
|
+
// serve's own catalog; it writes nothing, so the server ends it outright when it closes. Its one message back is its answer.
|
|
6
7
|
// Before anything loads node:sqlite, as in the server's own thread: its ExperimentalWarning is not the server's to print.
|
|
7
8
|
import "./quiet-sqlite-warning.js";
|
|
8
9
|
import { parentPort, workerData } from "node:worker_threads";
|
|
9
10
|
import { candidatesOf, ownSecrets, planImport, runImport, sessionsOf } from "./import.js";
|
|
10
11
|
import { importStoreProxy } from "./import-proxy.js";
|
|
12
|
+
import { catalogPrices } from "./model.js";
|
|
11
13
|
import { toolKeysOverStore } from "./tool-keys-store.js";
|
|
12
|
-
const { task, data, home, temp, secrets = {}, projects } = workerData;
|
|
14
|
+
const { task, data, home, temp, secrets = {}, projects, year } = workerData;
|
|
13
15
|
const stop = new AbortController();
|
|
14
16
|
parentPort.on("message", (message) => void (message === "stop" && stop.abort()));
|
|
15
17
|
// The port does not keep the thread alive on its own: the task does (the proxy references it only while it waits for the
|
|
@@ -22,6 +24,11 @@ for (const [name, value] of Object.entries(secrets))
|
|
|
22
24
|
Object.defineProperty(env, name, { value, enumerable: false });
|
|
23
25
|
const options = { home, ...(temp ? { temp } : {}), env, signal: stop.signal };
|
|
24
26
|
const answer = async () => {
|
|
27
|
+
if (task === "wrapped") {
|
|
28
|
+
const failures = [];
|
|
29
|
+
const { wrappedHome } = await import("@parcha/agentrun-import");
|
|
30
|
+
return { wrapped: await wrappedHome(home, year, { failures, catalog: await catalogPrices() }), unread: failures.length };
|
|
31
|
+
}
|
|
25
32
|
if (task === "plan") {
|
|
26
33
|
// A count keeps no transcript: no key scan (a whole history read through secretlint at every start).
|
|
27
34
|
const plan = await planImport({ ...options, keys: false });
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { EntryLike, TimelineEvent } from "./timeline/index.js";
|
|
2
|
+
/** One request in flight. `name`: the model, by the id its request names (`inkling-2-mini`), or the tool. `started_at`: when it was sent (null for a model request a
|
|
3
|
+
* booking recorded before requests were stamped). `for_tool`: a tool's own model request (a web search's, a learned
|
|
4
|
+
* node's), which runs inside that call. `input_tokens_max`: the input a model request was admitted with, at most. */
|
|
5
|
+
export type InFlight = {
|
|
6
|
+
kind: "model" | "tool";
|
|
7
|
+
name: string;
|
|
8
|
+
started_at: string | null;
|
|
9
|
+
tool_use_id?: string;
|
|
10
|
+
for_tool?: string;
|
|
11
|
+
input_tokens_max?: number;
|
|
12
|
+
};
|
|
13
|
+
/** The model requests a run's sessions sent and have not had answered: each `runner.request` with no `runner.turn` of its
|
|
14
|
+
* turn in its conversation. A paid tool's charge (`paid`, its model `paid:<tool>`) is no model request: its call's row
|
|
15
|
+
* says it. A decision's request (`decision:<model>`) is its model's. */
|
|
16
|
+
export declare function modelsInFlight(entries: readonly EntryLike[]): InFlight[];
|
|
17
|
+
/** The tool calls a run made and has not had back: each `tool_use` row with no `tool_result` row of its id in its
|
|
18
|
+
* conversation. A call's id is its session's own (an ACP agent may number its calls from 1), so two sessions' calls can
|
|
19
|
+
* share one. */
|
|
20
|
+
export declare function toolsInFlight(rows: readonly TimelineEvent[]): InFlight[];
|
|
21
|
+
/** Both, oldest first (one with no start time last), and the key a page's change log reads them by: a request sent or
|
|
22
|
+
* answered is a change of the page, so a reader waiting on the page wakes for it, as for a new row. */
|
|
23
|
+
export declare function inFlightOf(models: readonly InFlight[], tools: readonly InFlight[]): {
|
|
24
|
+
list: InFlight[];
|
|
25
|
+
key: string;
|
|
26
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// What a live run is waiting on now (GRE-4835): every request it has sent and not had back, from the moment it was sent,
|
|
2
|
+
// on every harness. A model request is its booking's record (the kernel's `runner.request`, written and stamped `at`
|
|
3
|
+
// before the request leaves) with no `runner.turn` yet: the booking writes both for pi and for every CLI harness, in each
|
|
4
|
+
// model session's conversation. A tool call (MCP, web, a subagent's, a sandbox command, one held for approval) is its
|
|
5
|
+
// Timeline `tool_use` row with no `tool_result` row yet. A timeline page carries the list beside its rows
|
|
6
|
+
// (run-reads-over-store.ts), so a run page shows "inkling-2-mini · 2:13" while a slow local model reads its prompt, where
|
|
7
|
+
// before nothing showed until the answer came back.
|
|
8
|
+
import { RUNNER_RECORDS } from "@parcha/agentrun-kernel";
|
|
9
|
+
const turnKey = (conversation, turn) => `${conversation ?? 0}:${turn}`;
|
|
10
|
+
/** The model requests a run's sessions sent and have not had answered: each `runner.request` with no `runner.turn` of its
|
|
11
|
+
* turn in its conversation. A paid tool's charge (`paid`, its model `paid:<tool>`) is no model request: its call's row
|
|
12
|
+
* says it. A decision's request (`decision:<model>`) is its model's. */
|
|
13
|
+
export function modelsInFlight(entries) {
|
|
14
|
+
const answered = new Set();
|
|
15
|
+
for (const e of entries) {
|
|
16
|
+
const turn = e.kind === RUNNER_RECORDS.turn ? e.data?.turn : undefined;
|
|
17
|
+
if (typeof turn === "number")
|
|
18
|
+
answered.add(turnKey(e.conversationId, turn));
|
|
19
|
+
}
|
|
20
|
+
const out = [];
|
|
21
|
+
for (const e of entries) {
|
|
22
|
+
if (e.kind !== RUNNER_RECORDS.request)
|
|
23
|
+
continue;
|
|
24
|
+
const d = (e.data ?? {});
|
|
25
|
+
if (typeof d.turn !== "number" || typeof d.model !== "string" || d.paid === true || d.model.startsWith("paid:"))
|
|
26
|
+
continue;
|
|
27
|
+
if (answered.has(turnKey(e.conversationId, d.turn)))
|
|
28
|
+
continue;
|
|
29
|
+
out.push({
|
|
30
|
+
kind: "model", name: d.model.startsWith("decision:") ? d.model.slice("decision:".length) : d.model,
|
|
31
|
+
started_at: typeof d.at === "string" ? d.at : null,
|
|
32
|
+
...(typeof d.host === "string" && d.host ? { for_tool: d.host } : {}),
|
|
33
|
+
...(typeof d.inputTokensMax === "number" && Number.isFinite(d.inputTokensMax) ? { input_tokens_max: d.inputTokensMax } : {}),
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
return out;
|
|
37
|
+
}
|
|
38
|
+
/** The tool calls a run made and has not had back: each `tool_use` row with no `tool_result` row of its id in its
|
|
39
|
+
* conversation. A call's id is its session's own (an ACP agent may number its calls from 1), so two sessions' calls can
|
|
40
|
+
* share one. */
|
|
41
|
+
export function toolsInFlight(rows) {
|
|
42
|
+
const callKey = (r) => `${r.conversation_id ?? 0}:${r.tool_use_id}`;
|
|
43
|
+
const returned = new Set(rows.filter((r) => r.kind === "tool_result" && r.tool_use_id).map(callKey));
|
|
44
|
+
return rows.filter((r) => r.kind === "tool_use" && r.tool_use_id && !returned.has(callKey(r)))
|
|
45
|
+
.map((r) => ({ kind: "tool", name: r.tool_name ?? "tool", started_at: r.timestamp || null, tool_use_id: r.tool_use_id }));
|
|
46
|
+
}
|
|
47
|
+
/** Both, oldest first (one with no start time last), and the key a page's change log reads them by: a request sent or
|
|
48
|
+
* answered is a change of the page, so a reader waiting on the page wakes for it, as for a new row. */
|
|
49
|
+
export function inFlightOf(models, tools) {
|
|
50
|
+
const list = [...models, ...tools].sort((a, b) => (a.started_at ?? "").localeCompare(b.started_at ?? ""));
|
|
51
|
+
return { list, key: list.map((f) => `${f.kind}:${f.tool_use_id ?? f.name}@${f.started_at ?? ""}`).join(",") };
|
|
52
|
+
}
|
package/dist/key-refusal.d.ts
CHANGED
|
@@ -28,15 +28,16 @@ export declare const answerPasses: {
|
|
|
28
28
|
* in it, and NEVER cut: an answer is shown whole. The same rule as redacted() (redactSecrets over `secrets`), over the
|
|
29
29
|
* whole text, read in pieces of about ANSWER_PIECE characters cut at whitespace. No form of a held value redactSecrets
|
|
30
30
|
* finds as it stands (as written, JSON-escaped, base64, hex) holds whitespace, so a cut there splits none; the one shape
|
|
31
|
-
* read across whitespace, a Bearer scheme and its token, is never cut between the two (endsInScheme)
|
|
31
|
+
* read across whitespace, a Bearer scheme and its token, is never cut between the two (endsInScheme); nor is a private
|
|
32
|
+
* key block, cut whole by its shape from its BEGIN line to its END line (keyWhole). A run with no
|
|
32
33
|
* whitespace past a piece is cut at the end of a JSON string in it (never in a URL's user and password), or, a run of
|
|
33
34
|
* a JSON array's numbers only, after a comma (runCut), so compact JSON reads in pieces too. A run of more than ANSWER_PIECE characters with neither is no
|
|
34
35
|
* person's text and is shown as "[redacted]", unread, from where its run starts. A value or a secret shape split across
|
|
35
36
|
* a cut, or a form only found across pieces, still shows to one pass over the joined pieces (heldIn: valueLeft over
|
|
36
37
|
* them as they came, and secretShapes over them redacted; with the head of each run left unread, where the rest of a
|
|
37
|
-
* value split before it would be
|
|
38
|
-
* still holds a value. So is an answer whose pieces,
|
|
39
|
-
* returns too). A value split inside one piece withholds only that piece, by the piece's own redaction. */
|
|
38
|
+
* value split before it would be, and its tail, where the head of a value split after it would be), and then the whole
|
|
39
|
+
* answer is "[redacted]", as redactSecrets does with a text that still holds a value. So is an answer whose pieces,
|
|
40
|
+
* as shown, read as a held value together (heldIn reads the text it returns too). A value split inside one piece withholds only that piece, by the piece's own redaction. */
|
|
40
41
|
export declare function redactedAnswer(text: string, secrets: readonly string[]): string;
|
|
41
42
|
/** `text`, a call's result as a grader's read shows it (timeline calls, tool_result_text), with no held secret in it:
|
|
42
43
|
* read in pieces as redactedAnswer reads an answer, each piece redacted, then shown as `show` makes it (the timeline's
|
|
@@ -49,6 +50,10 @@ export declare function redactedAnswer(text: string, secrets: readonly string[])
|
|
|
49
50
|
* character returned was read; the caller cuts it to `shown`. So no redaction pass reads more than a piece, however long
|
|
50
51
|
* the result or its head. */
|
|
51
52
|
export declare function redactedCall(text: string, secrets: readonly string[], shown: number, show?: (piece: string) => string): string;
|
|
53
|
+
/** Whether redactSecrets withholds `text` whole: it holds a held value or a secret shape no cut in place takes (split by
|
|
54
|
+
* whitespace, encoded, written as JSON's \uXXXX escapes). Read whole, never in pieces: the caller bounds what it reads
|
|
55
|
+
* (a web call's strings, joined: timeline calls.holds). */
|
|
56
|
+
export declare function withheldWhole(text: string, secrets: readonly string[]): boolean;
|
|
52
57
|
/** Whether a number shows a held value. A held value can be all digits (a gateway's key), and a record or a call's
|
|
53
58
|
* arguments can quote it as a number: one whose digits hold a held value, by the same rule as a string's, is held. A
|
|
54
59
|
* number can also EQUAL a held value whose text differs from its own (a leading zero, 1e21, a long key read lossy). A
|
package/dist/key-refusal.js
CHANGED
|
@@ -7,6 +7,7 @@ import { harnessOf } from "./harness-table.js";
|
|
|
7
7
|
import { cutSecrets, endsInScheme, redactSecrets, secretShapes, valueLeft, valueMatcher } from "./learn/secrets.js";
|
|
8
8
|
import { hostModel, MODEL_KEYS } from "./model.js";
|
|
9
9
|
import { modelWire, openRouterOnly, WIRES } from "./provider.js";
|
|
10
|
+
import { jsonEscapeAt, privateKeyEnd, scanned, squeeze } from "./redact/match.js";
|
|
10
11
|
import { savedGatewayIn } from "./model-gateway.js";
|
|
11
12
|
const row = (id) => {
|
|
12
13
|
const found = MODEL_KEYS.find((r) => r.id === id);
|
|
@@ -83,15 +84,16 @@ export const answerPasses = { count: 0 };
|
|
|
83
84
|
* in it, and NEVER cut: an answer is shown whole. The same rule as redacted() (redactSecrets over `secrets`), over the
|
|
84
85
|
* whole text, read in pieces of about ANSWER_PIECE characters cut at whitespace. No form of a held value redactSecrets
|
|
85
86
|
* finds as it stands (as written, JSON-escaped, base64, hex) holds whitespace, so a cut there splits none; the one shape
|
|
86
|
-
* read across whitespace, a Bearer scheme and its token, is never cut between the two (endsInScheme)
|
|
87
|
+
* read across whitespace, a Bearer scheme and its token, is never cut between the two (endsInScheme); nor is a private
|
|
88
|
+
* key block, cut whole by its shape from its BEGIN line to its END line (keyWhole). A run with no
|
|
87
89
|
* whitespace past a piece is cut at the end of a JSON string in it (never in a URL's user and password), or, a run of
|
|
88
90
|
* a JSON array's numbers only, after a comma (runCut), so compact JSON reads in pieces too. A run of more than ANSWER_PIECE characters with neither is no
|
|
89
91
|
* person's text and is shown as "[redacted]", unread, from where its run starts. A value or a secret shape split across
|
|
90
92
|
* a cut, or a form only found across pieces, still shows to one pass over the joined pieces (heldIn: valueLeft over
|
|
91
93
|
* them as they came, and secretShapes over them redacted; with the head of each run left unread, where the rest of a
|
|
92
|
-
* value split before it would be
|
|
93
|
-
* still holds a value. So is an answer whose pieces,
|
|
94
|
-
* returns too). A value split inside one piece withholds only that piece, by the piece's own redaction. */
|
|
94
|
+
* value split before it would be, and its tail, where the head of a value split after it would be), and then the whole
|
|
95
|
+
* answer is "[redacted]", as redactSecrets does with a text that still holds a value. So is an answer whose pieces,
|
|
96
|
+
* as shown, read as a held value together (heldIn reads the text it returns too). A value split inside one piece withholds only that piece, by the piece's own redaction. */
|
|
95
97
|
export function redactedAnswer(text, secrets) {
|
|
96
98
|
if (!text)
|
|
97
99
|
return text;
|
|
@@ -118,6 +120,12 @@ export function redactedCall(text, secrets, shown, show = (piece) => piece) {
|
|
|
118
120
|
const result = short ? `${out}...` : out;
|
|
119
121
|
return heldIn(seen, secrets, result) ? "[redacted]" : result;
|
|
120
122
|
}
|
|
123
|
+
/** Whether redactSecrets withholds `text` whole: it holds a held value or a secret shape no cut in place takes (split by
|
|
124
|
+
* whitespace, encoded, written as JSON's \uXXXX escapes). Read whole, never in pieces: the caller bounds what it reads
|
|
125
|
+
* (a web call's strings, joined: timeline calls.holds). */
|
|
126
|
+
export function withheldWhole(text, secrets) {
|
|
127
|
+
return redactSecrets(text, secrets, Number.POSITIVE_INFINITY) === "[redacted]";
|
|
128
|
+
}
|
|
121
129
|
/** Whether the text a reader is about to be shown (`shown`, what the caller returns) holds a held value, or the joined
|
|
122
130
|
* pieces still hold one or a secret shape: one a cut split. `shown` is read whole for a held value (valueMatcher, one
|
|
123
131
|
* linear pass): however the pieces were put together, as each was cut or shown, or an unread run's "[redacted]" between
|
|
@@ -127,16 +135,17 @@ export function redactedCall(text, secrets, shown, show = (piece) => piece) {
|
|
|
127
135
|
* parameter's value cut in place at the end of a piece, the rest of the held value in the next), and the rest then no
|
|
128
136
|
* longer reads as the value. A piece withheld whole covers all of itself, so a value split inside one piece is that
|
|
129
137
|
* piece's own redaction's, and only a value no cut covers across pieces (or in the text read past where they stopped)
|
|
130
|
-
* withholds the text. Each unread run's head
|
|
131
|
-
* split before it
|
|
132
|
-
* peek too long to read (`unread`) withholds
|
|
138
|
+
* withholds the text. Each unread run's head and tail are covered (it shows as "[redacted]") and read: its head for the
|
|
139
|
+
* rest of a value split before it, its tail for the head of a value whose rest comes after it. A shape is looked for in
|
|
140
|
+
* the pieces each redacted (a shape whole in one is no shape a cut split). A peek too long to read (`unread`) withholds
|
|
141
|
+
* the text too. */
|
|
133
142
|
function heldIn(seen, secrets, shown) {
|
|
134
143
|
return seen.unread || valueMatcher(secrets)(shown) || valueLeft(seen.raw, secrets, seen.cuts) || secretShapes(seen.shapes).length > 0;
|
|
135
144
|
}
|
|
136
145
|
/** `text` read in pieces as redactedAnswer says (pieceEnd), each redacted by itself: what the pieces show, joined, and
|
|
137
146
|
* what the pass after them reads (heldIn): each piece as it came and the spans its redaction cut, and each piece
|
|
138
|
-
* redacted, with the head of each unread run put back (covered, as
|
|
139
|
-
* for the shapes). A run runCut cut that then goes on past a piece with
|
|
147
|
+
* redacted, with the head and the tail of each unread run put back (covered, as they came; the head redacted by itself
|
|
148
|
+
* before its "[redacted]" for the shapes). A run runCut cut that then goes on past a piece with
|
|
140
149
|
* no place to cut is unread from its start, the pieces of it already read taken back, so no piece shows the head of a
|
|
141
150
|
* value or a shape the cut split. With `enough`, no piece is read once the pieces show more than `enough` characters,
|
|
142
151
|
* and the text where they stopped, `hold` characters the matcher sees of it (peek), goes to the pass the same way.
|
|
@@ -164,13 +173,17 @@ function inPieces(text, secrets, enough = Number.POSITIVE_INFINITY, show = (piec
|
|
|
164
173
|
shapes.splice(run.at);
|
|
165
174
|
reads.splice(run.at);
|
|
166
175
|
}
|
|
176
|
+
// The run is shown as "[redacted]": its head is read, covered, for the rest of a value split before it, and its
|
|
177
|
+
// tail (tailOf: `hold` characters the matcher sees, at most a piece), covered too, for the head of a value whose
|
|
178
|
+
// rest comes after it. One read, the two joined by a line break, as each piece is one.
|
|
167
179
|
const head = peek(text, start, hold);
|
|
168
|
-
|
|
180
|
+
const tail = head === undefined ? undefined : tailOf(text, start, to, hold);
|
|
181
|
+
if (head === undefined || tail === undefined)
|
|
169
182
|
unread = true;
|
|
170
183
|
else {
|
|
171
184
|
shapes.push(`${redactSecrets(head, secrets, Buffer.byteLength(head))}[redacted]`);
|
|
172
|
-
|
|
173
|
-
reads.push({ text:
|
|
185
|
+
const both = `${head}\n${tail}`;
|
|
186
|
+
reads.push({ text: both, cuts: [[0, both.length]] });
|
|
174
187
|
}
|
|
175
188
|
out.push("[redacted]");
|
|
176
189
|
shown += "[redacted]".length;
|
|
@@ -195,6 +208,7 @@ function inPieces(text, secrets, enough = Number.POSITIVE_INFINITY, show = (piec
|
|
|
195
208
|
if (from < text.length) {
|
|
196
209
|
// Stopped inside a run runCut cut: the rest of it, to its next whitespace (at most a piece), goes to the pass too.
|
|
197
210
|
const space = run ? text.slice(from, from + ANSWER_PIECE).search(/\s/) : 0;
|
|
211
|
+
scanned.chars += space < 0 ? Math.min(ANSWER_PIECE, text.length - from) : space + 1;
|
|
198
212
|
const runTo = from + (space < 0 ? ANSWER_PIECE : space);
|
|
199
213
|
const ahead = peek(text, from, hold);
|
|
200
214
|
if (ahead === undefined)
|
|
@@ -216,18 +230,47 @@ function inPieces(text, secrets, enough = Number.POSITIVE_INFINITY, show = (piec
|
|
|
216
230
|
cuts.push([raw.length + start, raw.length + end]);
|
|
217
231
|
raw += read.text;
|
|
218
232
|
});
|
|
219
|
-
|
|
233
|
+
const [shows, cutShapes] = [out.join(""), shapes.join("")];
|
|
234
|
+
// Each of the three joins read once.
|
|
235
|
+
scanned.chars += raw.length + shows.length + cutShapes.length;
|
|
236
|
+
return { out: shows, seen: { raw, cuts, shapes: cutShapes, unread }, short: from < text.length && shown <= enough };
|
|
220
237
|
}
|
|
221
238
|
/** text from `from` on, as far as `count` characters the matcher sees (all of it, if it holds fewer), each run of
|
|
222
|
-
* whitespace in it one space. The matcher reads "+" as a space and decodes percent-encoded bytes
|
|
223
|
-
*
|
|
224
|
-
*
|
|
225
|
-
* (a
|
|
239
|
+
* whitespace in it one space. The matcher reads "+" as a space and decodes percent-encoded bytes and JSON's escapes
|
|
240
|
+
* (one level and two, as the JSON view reads them), so a "+", an encoded byte and an escape that decodes to whitespace
|
|
241
|
+
* count no more than whitespace does, and any other escape counts as what the view keeps of the character it decodes
|
|
242
|
+
* to. A character that renders as nothing (a zero-width space, a soft hyphen) counts as nothing too: the views drop it.
|
|
243
|
+
* Padding of any of them never hides the rest of a value split before it. Undefined, so the caller withholds the text,
|
|
244
|
+
* when that takes more than a piece of text (a run of whitespace counted as one): no redaction pass reads more than a
|
|
245
|
+
* piece. */
|
|
226
246
|
function peek(text, from, count) {
|
|
247
|
+
const read = visible(text, from, count, text.length);
|
|
248
|
+
return read.span > ANSWER_PIECE ? undefined : read.parts.join("");
|
|
249
|
+
}
|
|
250
|
+
/** The end of the run text[start, to) the pass reads for the head of a value whose rest comes after the run: as few of
|
|
251
|
+
* its last characters as hold `count` characters the matcher sees (at most a piece's worth), counted as peek counts
|
|
252
|
+
* them, so padding the views read as nothing (whitespace, a zero-width space, a soft hyphen, an escape or encoded bytes
|
|
253
|
+
* that decode to either) between that head and the run's end never pushes the head out of it. Read forward from a
|
|
254
|
+
* start moved back from `to`, twice as far each time, so it reads at most two pieces in all. Undefined, so the caller
|
|
255
|
+
* withholds the text, when that takes more than a piece of text. */
|
|
256
|
+
function tailOf(text, start, to, count) {
|
|
257
|
+
const want = Math.min(count, ANSWER_PIECE);
|
|
258
|
+
for (let width = Math.min(want, to - start);; width = Math.min(2 * width, ANSWER_PIECE, to - start)) {
|
|
259
|
+
const from = to - width;
|
|
260
|
+
if (from === start || visible(text, from, want, to).found >= want)
|
|
261
|
+
return text.slice(from, to);
|
|
262
|
+
if (width >= ANSWER_PIECE)
|
|
263
|
+
return undefined;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
/** text[from, to) read as peek says, until `count` characters the matcher sees are found or the read passes a piece
|
|
267
|
+
* of text (`span`, a run of whitespace counted as one): what it read, as peek returns it, and how many it found. */
|
|
268
|
+
function visible(text, from, count, to) {
|
|
227
269
|
const parts = [];
|
|
228
270
|
let span = 0;
|
|
229
271
|
let found = 0;
|
|
230
|
-
|
|
272
|
+
let escape;
|
|
273
|
+
for (let at = from; at < to && found < count && span <= ANSWER_PIECE;) {
|
|
231
274
|
SPACES.lastIndex = at;
|
|
232
275
|
let end = SPACES.test(text) ? SPACES.lastIndex : at;
|
|
233
276
|
if (end > at) {
|
|
@@ -235,34 +278,68 @@ function peek(text, from, count) {
|
|
|
235
278
|
span++;
|
|
236
279
|
}
|
|
237
280
|
else {
|
|
238
|
-
while (end - at <= ANSWER_PIECE && text[end] === "%" && HEX_PAIR.test(text.slice(end + 1, end + 3)))
|
|
281
|
+
while (end - at <= ANSWER_PIECE && end + 3 <= to && text[end] === "%" && HEX_PAIR.test(text.slice(end + 1, end + 3)))
|
|
239
282
|
end += 3;
|
|
240
283
|
if (end > at)
|
|
241
|
-
found += Buffer.from(text.slice(at, end).replaceAll("%", ""), "hex").toString("utf8")
|
|
284
|
+
found += squeeze(Buffer.from(text.slice(at, end).replaceAll("%", ""), "hex").toString("utf8")).length;
|
|
285
|
+
else if (text[at] === "\\" && (escape = jsonEscapeAt(text, at)) !== undefined) {
|
|
286
|
+
end = escape.end;
|
|
287
|
+
found += squeeze(escape.char).length;
|
|
288
|
+
}
|
|
242
289
|
else {
|
|
243
290
|
end = at + 1;
|
|
244
291
|
if (text[at] !== "+")
|
|
245
|
-
found
|
|
292
|
+
found += squeeze(text[at]).length;
|
|
246
293
|
}
|
|
247
294
|
parts.push(text.slice(at, end));
|
|
248
295
|
span += end - at;
|
|
249
296
|
}
|
|
250
|
-
|
|
251
|
-
|
|
297
|
+
// Each character read, a percent-encoded run's twice more (its hex parsed, then decoded).
|
|
298
|
+
scanned.chars += text[at] === "%" && end > at + 1 ? 3 * (end - at) : end - at;
|
|
252
299
|
at = end;
|
|
253
300
|
}
|
|
254
|
-
return parts
|
|
301
|
+
return { parts, found, span };
|
|
255
302
|
}
|
|
256
303
|
const SPACES = /\s+/y;
|
|
257
304
|
const HEX_PAIR = /^[0-9A-Fa-f]{2}$/;
|
|
258
305
|
/** Where the piece of `text` read from `from` ends: at its last whitespace before ANSWER_PIECE characters; with none, at
|
|
259
|
-
* runCut's place, else at the next whitespace (a run read as one, or unread past ANSWER_PIECE).
|
|
306
|
+
* runCut's place, else at the next whitespace (a run read as one, or unread past ANSWER_PIECE). Never inside a private
|
|
307
|
+
* key block whose END line is in reach (keyWhole). */
|
|
260
308
|
function pieceEnd(text, from) {
|
|
309
|
+
return keyWhole(text, from, spaceEnd(text, from));
|
|
310
|
+
}
|
|
311
|
+
/** `end`, the end of the piece read from `from`, or, where a private key block crosses it, where the piece ends instead,
|
|
312
|
+
* so the block is read whole in one piece and cut whole by its shape: a piece cut inside it would show the rest of its
|
|
313
|
+
* body and its END line in the next piece, where no shape starts. Only the last "-----BEGIN" in the piece (at most a
|
|
314
|
+
* piece back from `end`) can start a block that crosses it: the END line an earlier one reads stops at that one's
|
|
315
|
+
* dashes. The piece ends at the last whitespace before the block's BEGIN line, so the next piece starts with the block;
|
|
316
|
+
* with none in the piece (the block starts it, a run glued to it), at the block's END line, so the block is one piece
|
|
317
|
+
* (or, longer than a piece, one run read as "[redacted]"). */
|
|
318
|
+
function keyWhole(text, from, end) {
|
|
319
|
+
if (end >= text.length)
|
|
320
|
+
return end;
|
|
321
|
+
const start = Math.max(from, end - ANSWER_PIECE);
|
|
322
|
+
const window = text.slice(start, end);
|
|
323
|
+
const begin = window.lastIndexOf("-----BEGIN");
|
|
324
|
+
scanned.chars += window.length;
|
|
325
|
+
if (begin < 0)
|
|
326
|
+
return end;
|
|
327
|
+
const block = privateKeyEnd(text, start + begin);
|
|
328
|
+
if (block <= end)
|
|
329
|
+
return end;
|
|
330
|
+
const space = window.slice(0, begin).search(/\s\S*$/);
|
|
331
|
+
return space >= 0 ? start + space + 1 : block;
|
|
332
|
+
}
|
|
333
|
+
/** pieceEnd's place, before keyWhole moves it. */
|
|
334
|
+
function spaceEnd(text, from) {
|
|
261
335
|
const to = Math.min(text.length, from + ANSWER_PIECE);
|
|
262
336
|
if (to === text.length)
|
|
263
337
|
return to;
|
|
264
338
|
const head = text.slice(from, to);
|
|
265
339
|
const space = head.search(/\s[^\s]*$/);
|
|
340
|
+
// The search for the piece's last whitespace reads each run of the piece twice at most (to the run's end, then back);
|
|
341
|
+
// the scheme's check after it, as much again.
|
|
342
|
+
scanned.chars += 4 * head.length;
|
|
266
343
|
if (space <= 0) {
|
|
267
344
|
const cut = runCut(text, from, to);
|
|
268
345
|
return cut > from ? cut : runEnd(text, to);
|
|
@@ -279,6 +356,7 @@ function pieceEnd(text, from) {
|
|
|
279
356
|
/** The next whitespace in `text` at or after `at`, or its end. */
|
|
280
357
|
function runEnd(text, at) {
|
|
281
358
|
const next = text.slice(at).search(/\s/);
|
|
359
|
+
scanned.chars += next < 0 ? text.length - at : next + 1;
|
|
282
360
|
return next < 0 ? text.length : at + next;
|
|
283
361
|
}
|
|
284
362
|
/** Where a run with no whitespace in text[from, to) may be cut, or -1: after the last quote in it that ends a JSON
|
|
@@ -290,6 +368,8 @@ function runEnd(text, at) {
|
|
|
290
368
|
* which is read once per URL, to the end of its run at most. */
|
|
291
369
|
function runCut(text, from, to) {
|
|
292
370
|
const head = text.slice(from, to);
|
|
371
|
+
// The head read three times: back from its end for each quote, and for a JSON array's numbers twice.
|
|
372
|
+
scanned.chars += 3 * head.length;
|
|
293
373
|
const urls = authorities(text, from, head);
|
|
294
374
|
let url = urls.length - 1;
|
|
295
375
|
for (let at = head.lastIndexOf('"'); at >= 0; at = at > 0 ? head.lastIndexOf('"', at - 1) : -1) {
|
|
@@ -313,6 +393,8 @@ function authorities(text, from, head) {
|
|
|
313
393
|
stop.lastIndex = from + at + 3;
|
|
314
394
|
const hit = stop.exec(text);
|
|
315
395
|
const end = (hit?.index ?? text.length) - from;
|
|
396
|
+
// Its authority, from the "://" to the stop (the head's search for "://" counts with runCut's reads).
|
|
397
|
+
scanned.chars += end - at;
|
|
316
398
|
if (hit?.[0] === "@")
|
|
317
399
|
found.push([at, end]);
|
|
318
400
|
if (end >= head.length)
|
package/dist/learn/secrets.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Span } from "../redact/match.js";
|
|
1
|
+
import { type Needles, type Span } from "../redact/match.js";
|
|
2
2
|
/** Whether `text` ends in a `Bearer` scheme and the blanks after it: the one place a shape is read across whitespace
|
|
3
3
|
* (the scheme, then its token), so a reader that cuts a text at whitespace must not cut there (key-refusal.ts
|
|
4
4
|
* redactedAnswer). */
|
|
@@ -19,8 +19,15 @@ export declare const PRINT_MAX = 4096;
|
|
|
19
19
|
* form not found as it stands (percent encoded, split by whitespace, an NFKC variant), read in `text` as given, is
|
|
20
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
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.
|
|
23
|
-
|
|
22
|
+
* unless the caller names more), and one whose cut leaves a value or a shape. `held`: spans of `text` cut in place
|
|
23
|
+
* beside the finds (heldSpans, of values no longer at hand). */
|
|
24
|
+
export declare function redactSecrets(text: string, values: readonly string[], max?: number, held?: readonly (readonly [number, number])[]): string;
|
|
25
|
+
/** Where redactSecrets cuts `values` in `text`, shapes left out: each span it cuts in place (UTF-16 offsets, overlapping
|
|
26
|
+
* ones merged, in order), or "whole" when its checks over them cut the text whole (a value split by a line break,
|
|
27
|
+
* percent encoded, an NFKC variant, read in the text as it came: redact/match.ts planCut). What a run's census keeps of
|
|
28
|
+
* a file, never the values (run-census.ts): redactSecrets given these spans as `held` cuts the text as it would have
|
|
29
|
+
* with the values among its own. */
|
|
30
|
+
export declare function heldSpans(text: string, values: readonly string[]): Span[] | "whole";
|
|
24
31
|
/** `text` as redactSecrets cuts it, and of a bank's numbers beside their words too (MONEY_SHAPES): what learning prints
|
|
25
32
|
* and serves of what it learned or refused (a problem's path and detail, a note read), never a run's own view, which
|
|
26
33
|
* may show its user an account number. */
|
|
@@ -37,6 +44,9 @@ export declare function cutSecrets(text: string, values: readonly string[], max?
|
|
|
37
44
|
* reader that cut it in pieces cut each), or else those redactSecrets makes of `text` whole (its values' forms, hexes
|
|
38
45
|
* and folded identifiers, and the secret shapes, found as they stand). */
|
|
39
46
|
export declare function valueLeft(text: string, values: readonly string[], cuts?: readonly Span[]): boolean;
|
|
47
|
+
/** What the matcher looks for of `values` (derivedOf, cached by array): the scrubber's held rule (secret-rules.ts) cuts
|
|
48
|
+
* each form, hex and folded identifier in place with redact/match.ts cutSpans. */
|
|
49
|
+
export declare const heldNeedles: (values: readonly string[]) => Needles;
|
|
40
50
|
/** A value shorter than this matches too much text by chance to be refused. */
|
|
41
51
|
export declare const MIN_SECRET = 8;
|
|
42
52
|
/** An excerpt of a run's input or answer as learning keeps it: `text` cut of the secrets `shown` knows, whole, then
|