@parcha/agentrun-serve 0.1.0-beta.49 → 0.1.0-beta.51
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 +173 -9
- package/README.md +246 -39
- package/dist/agent-delete.d.ts +3 -2
- package/dist/agent-delete.js +29 -4
- package/dist/agents-store.js +7 -3
- package/dist/api-only.d.ts +8 -10
- package/dist/api-only.js +11 -12
- package/dist/capacity.d.ts +50 -0
- package/dist/capacity.js +49 -0
- package/dist/cli-learning/claude-wire.d.ts +41 -0
- package/dist/cli-learning/claude-wire.js +258 -0
- package/dist/cli-learning/cli.d.ts +11 -0
- package/dist/cli-learning/cli.js +241 -0
- package/dist/cli-learning/codex-worktree.d.ts +10 -0
- package/dist/cli-learning/codex-worktree.js +119 -0
- package/dist/cli-learning/connections.d.ts +62 -0
- package/dist/cli-learning/connections.js +87 -0
- package/dist/cli-learning/entry.d.ts +1 -0
- package/dist/cli-learning/entry.js +4 -0
- package/dist/cli-learning/evidence.d.ts +78 -0
- package/dist/cli-learning/evidence.js +492 -0
- package/dist/cli-learning/hook.d.ts +33 -0
- package/dist/cli-learning/hook.js +544 -0
- package/dist/cli-learning/install.d.ts +33 -0
- package/dist/cli-learning/install.js +335 -0
- package/dist/cli-learning/observation-proof.d.ts +14 -0
- package/dist/cli-learning/observation-proof.js +10 -0
- package/dist/cli-learning/policy.d.ts +48 -0
- package/dist/cli-learning/policy.js +363 -0
- package/dist/cli-learning/schema.d.ts +16 -0
- package/dist/cli-learning/schema.js +27 -0
- package/dist/cli-learning/state.d.ts +23 -0
- package/dist/cli-learning/state.js +61 -0
- package/dist/cli.js +24 -2
- package/dist/compute-cost.d.ts +101 -0
- package/dist/compute-cost.js +250 -0
- package/dist/console/assets/index-Bt1B51b7.js +733 -0
- package/dist/console/assets/index-sVftE9Ht.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/email/email-faux.d.ts +3 -1
- package/dist/email/email-faux.js +3 -2
- package/dist/email/routes.js +22 -12
- package/dist/eval-previous.d.ts +52 -0
- package/dist/eval-previous.js +164 -0
- package/dist/file-types.d.ts +2 -0
- package/dist/file-types.js +3 -1
- package/dist/harness-install.d.ts +6 -2
- package/dist/harness-install.js +40 -8
- package/dist/harness.d.ts +1 -1
- package/dist/harness.js +3 -2
- package/dist/learn/check.d.ts +8 -5
- package/dist/learn/check.js +25 -24
- package/dist/learn/repick.d.ts +22 -13
- package/dist/learn/repick.js +57 -56
- package/dist/learn/secrets.js +14 -3
- package/dist/learn/workflow-draft.d.ts +4 -0
- package/dist/learn/workflow-draft.js +10 -7
- package/dist/learned-workflow.js +8 -8
- package/dist/learning-setting.js +2 -2
- package/dist/learning-words.d.ts +1 -1
- package/dist/learning-words.js +1 -1
- package/dist/mcp-pin-first.js +2 -1
- package/dist/mcp-private-hosts.d.ts +24 -3
- package/dist/mcp-private-hosts.js +53 -3
- package/dist/model-gateway.d.ts +2 -0
- package/dist/model-gateway.js +3 -1
- package/dist/native/runtimes.d.ts +2 -0
- package/dist/native/runtimes.js +2 -0
- package/dist/observation/learning.d.ts +32 -0
- package/dist/observation/learning.js +66 -0
- package/dist/observation/observer.d.ts +8 -1
- package/dist/observation/observer.js +89 -9
- package/dist/observation/schema.js +12 -4
- package/dist/observation/usage-identity.d.ts +9 -0
- package/dist/observation/usage-identity.js +11 -0
- package/dist/openapi.js +113 -29
- package/dist/paid-calls.d.ts +13 -6
- package/dist/paid-calls.js +14 -8
- package/dist/run-launch.d.ts +16 -2
- package/dist/run-launch.js +6 -1
- package/dist/run-timeline-served.js +5 -3
- package/dist/run-usage.d.ts +23 -8
- package/dist/run-usage.js +100 -18
- package/dist/run-view.d.ts +2 -0
- package/dist/run-view.js +12 -7
- package/dist/runner/adapter-loop.d.ts +4 -0
- package/dist/runner/adapter-loop.js +44 -27
- package/dist/runner/adapter-run-spec.d.ts +8 -3
- package/dist/runner/adapter-run-spec.js +15 -8
- package/dist/runner/beside.d.ts +13 -0
- package/dist/runner/beside.js +27 -8
- package/dist/runner/big-writes.d.ts +33 -0
- package/dist/runner/big-writes.js +105 -0
- package/dist/runner/cli-run-spec.js +16 -8
- package/dist/runner/disk-free.d.ts +44 -0
- package/dist/runner/disk-free.js +96 -0
- package/dist/runner/feedback-round.d.ts +12 -8
- package/dist/runner/feedback-round.js +16 -30
- package/dist/runner/harness-loops.js +3 -1
- package/dist/runner/held.d.ts +4 -1
- package/dist/runner/journal-kinds.d.ts +1 -1
- package/dist/runner/learning-end.js +13 -4
- package/dist/runner/main.d.ts +17 -6
- package/dist/runner/main.js +187 -45
- package/dist/runner/metrics.d.ts +4 -0
- package/dist/runner/metrics.js +9 -0
- package/dist/runner/presence.d.ts +11 -2
- package/dist/runner/presence.js +31 -3
- package/dist/runner/run-child-host.d.ts +27 -17
- package/dist/runner/run-child-host.js +70 -116
- package/dist/runner/run-child.js +3 -0
- package/dist/runner/run-errors.js +2 -0
- package/dist/runner/runner-check.d.ts +51 -0
- package/dist/runner/runner-check.js +206 -0
- package/dist/runner/runner-metrics.d.ts +19 -0
- package/dist/runner/runner-metrics.js +49 -0
- package/dist/runner/runner.d.ts +37 -0
- package/dist/runner/runner.js +43 -3
- package/dist/runner/save-slots.d.ts +9 -0
- package/dist/runner/save-slots.js +91 -0
- package/dist/runner/sdk-loop.js +34 -22
- package/dist/runs-over-store.d.ts +8 -1
- package/dist/runs-over-store.js +57 -9
- package/dist/sdk/runs.d.ts +25 -6
- package/dist/sdk/runs.js +107 -35
- package/dist/sdk/runtimes.d.ts +19 -0
- package/dist/sdk/runtimes.js +23 -0
- package/dist/sdk/schema.d.ts +14 -8
- package/dist/sdk/schema.js +18 -6
- package/dist/server.d.ts +7 -0
- package/dist/server.js +151 -28
- package/dist/skills/agentrun-serve/SKILL.md +52 -7
- package/dist/start-switches.js +2 -0
- package/dist/stats.d.ts +4 -0
- package/dist/stats.js +1 -1
- package/dist/store/agent-body.d.ts +13 -2
- package/dist/store/agent-body.js +19 -4
- package/dist/store/dialect.d.ts +2 -0
- package/dist/store/dialect.js +1 -0
- package/dist/store/index.d.ts +3 -3
- package/dist/store/index.js +2 -2
- package/dist/store/postgres/connection.d.ts +5 -2
- package/dist/store/postgres/connection.js +19 -7
- package/dist/store/postgres/dialect.js +1 -0
- package/dist/store/postgres/migrate.d.ts +30 -0
- package/dist/store/postgres/migrate.js +72 -5
- package/dist/store/postgres/migration-lint.d.ts +8 -0
- package/dist/store/postgres/migration-lint.js +119 -0
- package/dist/store/postgres/migrations/0023_computer_interval_resources.sql +14 -0
- package/dist/store/postgres/migrations/0024_runner_capacity.sql +28 -0
- package/dist/store/postgres/store.d.ts +8 -3
- package/dist/store/postgres/store.js +31 -11
- package/dist/store/schema.d.ts +26 -4
- package/dist/store/schema.js +45 -4
- package/dist/store/sqlite/connection.d.ts +3 -3
- package/dist/store/sqlite/connection.js +3 -3
- package/dist/store/sqlite/run-launch.d.ts +9 -1
- package/dist/store/sqlite/run-launch.js +44 -0
- package/dist/store/sqlite/store.d.ts +19 -4
- package/dist/store/sqlite/store.js +180 -93
- package/dist/store/store-schema.d.ts +34 -0
- package/dist/store/store-schema.js +125 -0
- package/dist/store/store.d.ts +61 -2
- package/dist/store/store.js +13 -0
- package/dist/store-reads/analytics.d.ts +3 -2
- package/dist/store-reads/analytics.js +20 -8
- package/dist/store-reads/cap.d.ts +9 -5
- package/dist/store-reads/cap.js +28 -2
- package/dist/store-reads/decisions.d.ts +21 -0
- package/dist/store-reads/decisions.js +22 -0
- package/dist/store-reads/journal.d.ts +8 -2
- package/dist/store-reads/journal.js +27 -8
- package/dist/store-view.d.ts +9 -4
- package/dist/store-view.js +48 -25
- package/dist/template-eval.d.ts +15 -1
- package/dist/template-eval.js +92 -13
- package/dist/templates.d.ts +4 -3
- package/dist/templates.js +4 -3
- package/dist/timeline/labels.js +17 -0
- package/dist/tool-gate.d.ts +4 -2
- package/dist/tool-list.js +1 -0
- package/dist/tools.d.ts +6 -2
- package/dist/tools.js +13 -1
- package/dist/trigger-targets.d.ts +21 -5
- package/dist/trigger-targets.js +13 -10
- package/dist/unified-usage.d.ts +24 -0
- package/dist/unified-usage.js +400 -0
- package/dist/uploads-archil.d.ts +100 -0
- package/dist/uploads-archil.js +430 -0
- package/dist/uploads.d.ts +55 -1
- package/dist/uploads.js +185 -98
- package/dist/validate.js +1 -1
- package/dist/web-fake.d.ts +25 -0
- package/dist/web-fake.js +38 -1
- package/dist/web-save.d.ts +75 -0
- package/dist/web-save.js +235 -0
- package/dist/workspace/archil-claim.d.ts +5 -2
- package/dist/workspace/archil-claim.js +5 -2
- package/dist/workspace/archil-disk.d.ts +11 -1
- package/dist/workspace/archil-disk.js +43 -10
- package/dist/workspace/archil.d.ts +3 -0
- package/dist/workspace/archil.js +102 -16
- package/dist/workspace/computer-for-claim.d.ts +14 -0
- package/dist/workspace/computer-for-claim.js +46 -7
- package/dist/workspace/computer-intervals.d.ts +9 -3
- package/dist/workspace/computer-intervals.js +17 -8
- package/dist/workspace/pieced.d.ts +14 -0
- package/dist/workspace/pieced.js +23 -0
- package/dist/workspace/run-disk.js +32 -12
- package/dist/workspace/run-workspace.d.ts +1 -1
- package/dist/workspace/run-workspace.js +11 -6
- package/package.json +10 -10
- package/skills/agentrun-serve/SKILL.md +52 -7
- package/templates/README.md +36 -7
- package/dist/console/assets/index-Bzn4eUYF.js +0 -715
- package/dist/console/assets/index-CR2ZGei1.css +0 -1
package/dist/harness-install.js
CHANGED
|
@@ -506,6 +506,24 @@ export function processIdentity(pid) {
|
|
|
506
506
|
return undefined;
|
|
507
507
|
}
|
|
508
508
|
}
|
|
509
|
+
/** Only the kernel UUID and numeric process-start format proves a boot. An absent,
|
|
510
|
+
* malformed or adapter-specific identity cannot establish that an owner is gone. */
|
|
511
|
+
function identityBoot(value) {
|
|
512
|
+
if (typeof value !== "string")
|
|
513
|
+
return undefined;
|
|
514
|
+
const match = /^([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}):[0-9]+$/i.exec(value);
|
|
515
|
+
return match?.[0] === value ? match[1].toLowerCase() : undefined;
|
|
516
|
+
}
|
|
517
|
+
/** A caller protecting legacy ownerless locks needs a complete, well-formed owner
|
|
518
|
+
* record before process liveness or boot identity can authorize recovery. */
|
|
519
|
+
function ownerProof(held) {
|
|
520
|
+
return held !== undefined && typeof held.host === "string" && held.host.length > 0
|
|
521
|
+
&& typeof held.pid === "number" && Number.isSafeInteger(held.pid) && held.pid > 0 && held.pid <= 0x7fffffff
|
|
522
|
+
&& typeof held.startedAt === "number" && Number.isSafeInteger(held.startedAt) && held.startedAt >= 0
|
|
523
|
+
&& typeof held.token === "string" && held.token.length > 0
|
|
524
|
+
&& (held.pidns === undefined || (typeof held.pidns === "string" && /^pid:\[[0-9]+\]$/.exec(held.pidns)?.[0] === held.pidns))
|
|
525
|
+
&& (held.identity === undefined || identityBoot(held.identity) !== undefined);
|
|
526
|
+
}
|
|
509
527
|
/** The hold at `at` as written, or undefined when it cannot be read (gone, cut short, not one). */
|
|
510
528
|
async function readHold(at) {
|
|
511
529
|
try {
|
|
@@ -525,17 +543,29 @@ async function readHold(at) {
|
|
|
525
543
|
* way. A hold its installer left (gone, or past that bound, or unreadable and older than HOLD_WRITING_MS) is taken over
|
|
526
544
|
* by one taker alone: the one that links it to a name of that very file's removes it, and only while it is still that
|
|
527
545
|
* file, so a hold another taker made meanwhile is never removed. */
|
|
528
|
-
export async function takeHold(dir, { isAlive = alive, identity = processIdentity, host = hostname(), pidns = pidNamespace(), timeoutMs = INSTALL_TIMEOUT_MS } = {}) {
|
|
529
|
-
const at =
|
|
546
|
+
export async function takeHold(dir, { isAlive = alive, identity = processIdentity, host = hostname(), pidns = pidNamespace(), timeoutMs = INSTALL_TIMEOUT_MS, holdPath = installHoldOf(dir), recoverUnknownOwner = true } = {}) {
|
|
547
|
+
const at = holdPath;
|
|
530
548
|
await mkdir(dirname(at), { recursive: true });
|
|
531
549
|
const token = randomUUID();
|
|
532
550
|
const draft = `${at}.${token}`;
|
|
533
551
|
const own = identity(process.pid);
|
|
534
|
-
|
|
552
|
+
const ownBoot = identityBoot(own);
|
|
553
|
+
await writeFile(draft, JSON.stringify({ host, ...(pidns ? { pidns } : {}), pid: process.pid, ...(own ? { identity: own } : {}), startedAt: Date.now(), token }), { mode: 0o600 });
|
|
535
554
|
/** Whether a hold's pid can be asked of this process table: written on this host, in this pid namespace where both
|
|
536
555
|
* name one. Another namespace's (another container's on the same data, with the same hostname) is judged as another
|
|
537
|
-
* host's. */
|
|
538
|
-
const local = (held) => held.host === host && (
|
|
556
|
+
* host's. Strict owner proof also withholds a PID check when only one side knows its namespace. */
|
|
557
|
+
const local = (held) => held.host === host && (recoverUnknownOwner
|
|
558
|
+
? typeof held.pidns !== "string" || pidns === undefined || held.pidns === pidns
|
|
559
|
+
: held.pidns === pidns);
|
|
560
|
+
/** An unbounded local-command hold cannot expire after a reboot. A known previous
|
|
561
|
+
* kernel boot on this host proves its owner gone even if the PID namespace changed.
|
|
562
|
+
* A container recreated within the same boot still needs proof that its old namespace
|
|
563
|
+
* died; never inspect its PID from this namespace or steal a live sibling's hold.
|
|
564
|
+
* Finite installer holds retain their existing foreign-namespace timeout policy. */
|
|
565
|
+
const previousBoot = (held) => {
|
|
566
|
+
const boot = identityBoot(held.identity);
|
|
567
|
+
return timeoutMs === Infinity && held.host === host && ownBoot !== undefined && boot !== undefined && boot !== ownBoot;
|
|
568
|
+
};
|
|
539
569
|
/** Whether a hold of this host's is still its installer's: that process alive, by its identity where both are known. */
|
|
540
570
|
const installing = (held) => {
|
|
541
571
|
if (!isAlive(held.pid))
|
|
@@ -557,8 +587,10 @@ export async function takeHold(dir, { isAlive = alive, identity = processIdentit
|
|
|
557
587
|
if (!judged)
|
|
558
588
|
continue;
|
|
559
589
|
const held = await readHold(at);
|
|
590
|
+
if (!recoverUnknownOwner && !ownerProof(held))
|
|
591
|
+
return undefined;
|
|
560
592
|
const live = typeof held?.pid === "number" && typeof held.startedAt === "number"
|
|
561
|
-
? local(held) ? installing(held) : Date.now() - held.startedAt <= timeoutMs + HOLD_STOP_MS
|
|
593
|
+
? !previousBoot(held) && (local(held) ? installing(held) : Date.now() - held.startedAt <= timeoutMs + HOLD_STOP_MS)
|
|
562
594
|
: Date.now() - judged.mtimeMs <= HOLD_WRITING_MS;
|
|
563
595
|
if (live)
|
|
564
596
|
return undefined;
|
|
@@ -596,8 +628,8 @@ export async function takeHold(dir, { isAlive = alive, identity = processIdentit
|
|
|
596
628
|
}
|
|
597
629
|
/** Lets go of the hold on installs into `dir` that `token` took; a hold of another's (one that took over this one past
|
|
598
630
|
* its bound) stays. */
|
|
599
|
-
export async function releaseHold(dir, token) {
|
|
600
|
-
const at =
|
|
631
|
+
export async function releaseHold(dir, token, { holdPath = installHoldOf(dir) } = {}) {
|
|
632
|
+
const at = holdPath;
|
|
601
633
|
if ((await readHold(at))?.token === token)
|
|
602
634
|
await rm(at, { force: true });
|
|
603
635
|
}
|
package/dist/harness.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export declare const DEFAULT_HARNESS: HarnessId;
|
|
|
9
9
|
export declare const HARNESS_ID_PATTERN = "^[a-z][a-z0-9-]{0,39}$";
|
|
10
10
|
/** The names serve's own runs carry where a harness id goes, so a harness module may not take one (its start is refused):
|
|
11
11
|
* `learning`, the launch harness the stores' learning queries match; `sdk`, an SDK run's launch harness
|
|
12
|
-
* (sdk/runs.ts); and the names analytics files a run's harness under: `workflow`, a workflow revision's, and each SDK
|
|
12
|
+
* (sdk/runs.ts); `cli`, a connected CLI capture; and the names analytics files a run's harness under: `workflow`, a workflow revision's, and each SDK
|
|
13
13
|
* runtime's (sdk/schema.ts SDK_BINDING). Also every name a plain object already has that the id pattern admits
|
|
14
14
|
* (`constructor`): serve looks harnesses up by id in plain objects, where such an id would read Object's own member. */
|
|
15
15
|
export declare const RESERVED_HARNESS_IDS: readonly string[];
|
package/dist/harness.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SDK_RUNTIMES } from "./sdk/runtimes.js";
|
|
1
2
|
/** The built-in harnesses' ids, in the table's order (harness-table.ts BUILTIN; harness-one-table.test.mjs holds them
|
|
2
3
|
* equal): the ids a definition may name on any server, and the type of a built-in one. What a server runs is its table's
|
|
3
4
|
* (harnessIds), which an owner's harness module may add to. */
|
|
@@ -7,11 +8,11 @@ export const DEFAULT_HARNESS = "pi";
|
|
|
7
8
|
export const HARNESS_ID_PATTERN = "^[a-z][a-z0-9-]{0,39}$";
|
|
8
9
|
/** The names serve's own runs carry where a harness id goes, so a harness module may not take one (its start is refused):
|
|
9
10
|
* `learning`, the launch harness the stores' learning queries match; `sdk`, an SDK run's launch harness
|
|
10
|
-
* (sdk/runs.ts); and the names analytics files a run's harness under: `workflow`, a workflow revision's, and each SDK
|
|
11
|
+
* (sdk/runs.ts); `cli`, a connected CLI capture; and the names analytics files a run's harness under: `workflow`, a workflow revision's, and each SDK
|
|
11
12
|
* runtime's (sdk/schema.ts SDK_BINDING). Also every name a plain object already has that the id pattern admits
|
|
12
13
|
* (`constructor`): serve looks harnesses up by id in plain objects, where such an id would read Object's own member. */
|
|
13
14
|
export const RESERVED_HARNESS_IDS = Object.freeze([
|
|
14
|
-
"learning", "sdk", "
|
|
15
|
+
"learning", "sdk", "cli", "codex-cli", "claude-code-cli", "workflow", ...SDK_RUNTIMES,
|
|
15
16
|
...Object.getOwnPropertyNames(Object.prototype).filter((name) => new RegExp(HARNESS_ID_PATTERN).test(name)),
|
|
16
17
|
]);
|
|
17
18
|
/** The harnesses that run on a person's ChatGPT plan (chatgpt-plan.ts): those whose requests go to OpenAI's Responses
|
package/dist/learn/check.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type RepickSite } from "./repick.js";
|
|
1
2
|
import { type DraftDecisions, type DraftDryRun, type DraftReader } from "./workflow-draft.js";
|
|
2
3
|
/** Byte caps (UTF-8). Over a cap is refused, never cut. */
|
|
3
4
|
export declare const CAPS: Readonly<{
|
|
@@ -79,9 +80,9 @@ export declare function answerTierProblems(doc: unknown): string[];
|
|
|
79
80
|
* child sees an input key as a page when its value reads one. Pages reach a step on the agent's model only through a fast-tier step's
|
|
80
81
|
* output: chain14b's drafts fed whole pages to the answering step (4.1 requests a run at ~70k cached tokens each,
|
|
81
82
|
* $0.364 a served run), where the research shape (a fast extract's compact facts to the answering step) booked ~$0.08.
|
|
82
|
-
* One line each, in words the compile retry acts on. With `repick` (the agent's learning.repick),
|
|
83
|
-
* loop
|
|
84
|
-
* clone its pass 2 runs reads the pages by the owner's setting, the one page read on the agent's model a draft may
|
|
83
|
+
* One line each, in words the compile retry acts on. With `repick` (the agent's learning.repick), the answer's re-pick
|
|
84
|
+
* loop (repickSiteOf), when its body is the host's pass marker, is read as its pass 1 (learn/repick.ts repickMarked):
|
|
85
|
+
* the clone its pass 2 runs reads the pages by the owner's setting, the one page read on the agent's model a draft may
|
|
85
86
|
* hold, and only that exact clone at that place. */
|
|
86
87
|
export declare function compactStateProblems(doc: unknown, { repick }?: {
|
|
87
88
|
readonly repick?: boolean;
|
|
@@ -95,8 +96,10 @@ export declare function compactStateProblems(doc: unknown, { repick }?: {
|
|
|
95
96
|
* H5's judge flagged 149 of 170 answers while 416 of 429 quotes were in the pages, and could not tell the 8 answers
|
|
96
97
|
* quoting text no page held from the rest; code can. One line each, in words the compile retry acts on. */
|
|
97
98
|
export declare function quoteCheckProblems(doc: unknown): string[];
|
|
98
|
-
/**
|
|
99
|
-
|
|
99
|
+
/** Where `workflow`'s answer is re-picked (quoteRule `repick`): what learning.repick rewrites (learn/repick.ts). */
|
|
100
|
+
export declare const repickSiteOf: (workflow: unknown) => RepickSite | undefined;
|
|
101
|
+
/** The labels a run's loop events give `workflow`'s quote re-pick (repickSiteOf): what marks a loop's exit a re-pick
|
|
102
|
+
* (learned-nodes.ts LoopRow `repick`). Any other loop that ran twice is an ordinary loop. */
|
|
100
103
|
export declare function repickLabels(workflow: unknown): Set<string>;
|
|
101
104
|
/** What must never be stored, in every change's name and text, whatever the checks would refuse it for first: the
|
|
102
105
|
* name and text scans (nameScanned, textOf) of each change, its text read whole (a file over its cap, one not a regular
|
package/dist/learn/check.js
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
// host's secrets and of text shaped like one, and a field over PRINT_MAX is redacted whole.
|
|
5
5
|
import { placeholdersOf, placeholderValue } from "@parcha/agentrun-dsl";
|
|
6
6
|
import { hiddenCharacter } from "./invisible.js";
|
|
7
|
-
import { REPICK_PASSES, repickCheckOf, repickMarked } from "./repick.js";
|
|
7
|
+
import { REPICK_PASSES, repickCheckOf, repickLabelOf, repickMarked } from "./repick.js";
|
|
8
8
|
import { learnedSecretShapes, redactLearned, valueMatcher } from "./secrets.js";
|
|
9
|
-
import { childNodes, draftProblems, decodedStrings, DECODED_DEPTH, DRY_RUN_FAILED, frontKeys, frontValues, LEARNED_KEYS, learnedPlace, readmeProblems, WORKFLOW_NAME, WORKFLOWS_DIR } from "./workflow-draft.js";
|
|
9
|
+
import { childNodes, draftProblems, decodedStrings, DECODED_DEPTH, DRY_RUN_FAILED, frontKeys, frontValues, LEARNED_KEYS, isNode, isObject, learnedPlace, readmeProblems, WORKFLOW_NAME, WORKFLOWS_DIR } from "./workflow-draft.js";
|
|
10
10
|
/** Byte caps (UTF-8). Over a cap is refused, never cut. */
|
|
11
11
|
export const CAPS = Object.freeze({
|
|
12
12
|
/** One draft's workflow.json. */
|
|
@@ -88,7 +88,6 @@ function decodedScanned(path, text, refused, add, deep = true) {
|
|
|
88
88
|
/** The model node kinds a tier routes (model.ts MODEL_NODES); a decision node (judge, pick, sift) goes to its decision
|
|
89
89
|
* provider, never a tier. */
|
|
90
90
|
export const TIERED_KINDS = new Set(["agent", "decide", "extract", "report"]);
|
|
91
|
-
const isNode = (value) => value !== null && typeof value === "object" && !Array.isArray(value) && typeof value.node === "string";
|
|
92
91
|
/** The state key a step writes (the DSL's writeKeyOf): a report's `report_markdown`, else its `as`, else an agent's,
|
|
93
92
|
* decide's or extract's label. */
|
|
94
93
|
const writeKeyOf = (node) => (node.node === "report" ? "report_markdown" : typeof node.as === "string" && node.as ? node.as : ["agent", "decide", "extract"].includes(node.node) ? node.label : undefined);
|
|
@@ -183,14 +182,14 @@ function pagesRead(value, state, out = new Set(), depth = 0) {
|
|
|
183
182
|
* child sees an input key as a page when its value reads one. Pages reach a step on the agent's model only through a fast-tier step's
|
|
184
183
|
* output: chain14b's drafts fed whole pages to the answering step (4.1 requests a run at ~70k cached tokens each,
|
|
185
184
|
* $0.364 a served run), where the research shape (a fast extract's compact facts to the answering step) booked ~$0.08.
|
|
186
|
-
* One line each, in words the compile retry acts on. With `repick` (the agent's learning.repick),
|
|
187
|
-
* loop
|
|
188
|
-
* clone its pass 2 runs reads the pages by the owner's setting, the one page read on the agent's model a draft may
|
|
185
|
+
* One line each, in words the compile retry acts on. With `repick` (the agent's learning.repick), the answer's re-pick
|
|
186
|
+
* loop (repickSiteOf), when its body is the host's pass marker, is read as its pass 1 (learn/repick.ts repickMarked):
|
|
187
|
+
* the clone its pass 2 runs reads the pages by the owner's setting, the one page read on the agent's model a draft may
|
|
189
188
|
* hold, and only that exact clone at that place. */
|
|
190
189
|
export function compactStateProblems(doc, { repick = false } = {}) {
|
|
191
190
|
const problems = new Set();
|
|
192
|
-
// The
|
|
193
|
-
const marked =
|
|
191
|
+
// The answer's re-pick loop alone (repickMarked): a marker anywhere else is read as written.
|
|
192
|
+
const marked = repick ? repickMarked(repickSiteOf(doc)) : undefined;
|
|
194
193
|
const walk = (node, pages, depth) => {
|
|
195
194
|
const after = new Set(pages);
|
|
196
195
|
if (!isNode(node) || depth > 32)
|
|
@@ -239,7 +238,7 @@ export function compactStateProblems(doc, { repick = false } = {}) {
|
|
|
239
238
|
// until the marks stop changing. The set read grows on each further pass, so it stops within one pass a key the
|
|
240
239
|
// workflow names, and never past maxIters; each pass's way out holds the ones before it.
|
|
241
240
|
const passes = typeof node.maxIters === "number" && node.maxIters >= 1 ? Math.floor(node.maxIters) : Number.POSITIVE_INFINITY;
|
|
242
|
-
const body = marked.
|
|
241
|
+
const body = node === marked?.loop ? marked.step : node.body;
|
|
243
242
|
let read = after;
|
|
244
243
|
let out = walk(body, read, depth + 1);
|
|
245
244
|
for (let pass = 2; pass <= passes; pass++) {
|
|
@@ -299,7 +298,6 @@ export function compactStateProblems(doc, { repick = false } = {}) {
|
|
|
299
298
|
}
|
|
300
299
|
/** The property names that make an answer carry quotes. */
|
|
301
300
|
const QUOTE_KEYS = new Set(["quote", "quotes"]);
|
|
302
|
-
const isObject = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
303
301
|
const QUOTE_SITES_MAX = 8;
|
|
304
302
|
function quoteSite(keys) {
|
|
305
303
|
const lists = keys.filter((key) => key === "[]").length;
|
|
@@ -507,10 +505,13 @@ const repickOn = (step, check) => {
|
|
|
507
505
|
const of = repickCheckOf(step);
|
|
508
506
|
return !!of && of.path === check.path && (of.field ?? "") === check.field && JSON.stringify(of.pages) === JSON.stringify(check.pages);
|
|
509
507
|
};
|
|
510
|
-
/**
|
|
511
|
-
|
|
508
|
+
/** Where `workflow`'s answer is re-picked (quoteRule `repick`): what learning.repick rewrites (learn/repick.ts). */
|
|
509
|
+
export const repickSiteOf = (workflow) => (isObject(workflow) ? quoteRule(workflow, {}).repick : undefined);
|
|
510
|
+
/** The labels a run's loop events give `workflow`'s quote re-pick (repickSiteOf): what marks a loop's exit a re-pick
|
|
511
|
+
* (learned-nodes.ts LoopRow `repick`). Any other loop that ran twice is an ordinary loop. */
|
|
512
512
|
export function repickLabels(workflow) {
|
|
513
|
-
|
|
513
|
+
const site = repickSiteOf(workflow);
|
|
514
|
+
return new Set(site ? [repickLabelOf(site)] : []);
|
|
514
515
|
}
|
|
515
516
|
/** Whether a step's `state` map names state key `key` as the whole marked placeholder `"{answer?}"` (a whole string):
|
|
516
517
|
* null on a re-pick loop's first pass, before any draft exists, and the failed draft on its second. No path below the
|
|
@@ -558,23 +559,23 @@ const quoteEscalatesIn = (node, depth = 0) => {
|
|
|
558
559
|
* (its path and field; a place no one pair reads is refused, as quote_missing reads none of it). Its pages are state keys holding a page as
|
|
559
560
|
* fetched (holdsPage). A composed workflow node writing the whole answer (its `as` the answer's path) whose child
|
|
560
561
|
* passes this rule in its own state has checked the places in the answer its child's schema declares too; the parent
|
|
561
|
-
* still checks any other place its own schema declares. `checked`: the places a passing workflow checked. `
|
|
562
|
-
* the answer
|
|
563
|
-
*
|
|
564
|
-
*
|
|
562
|
+
* still checks any other place its own schema declares. `checked`: the places a passing workflow checked. `repick`:
|
|
563
|
+
* where the answer is re-picked, whether the rule applies or not: the step writing the answer when it is a loop of
|
|
564
|
+
* REPICK_PASSES until `not` of a quote_missing, else that step's composed child's, which the DSL labels
|
|
565
|
+
* `<step>/<its label>` (scopeDepsToChild). */
|
|
565
566
|
function quoteRule(workflow, schemasAround, depth = 0) {
|
|
566
567
|
const output = isObject(workflow.output) ? workflow.output : {};
|
|
567
568
|
const answerPath = typeof output.path === "string" ? output.path : "";
|
|
568
569
|
const schemas = isObject(workflow.schemas) ? workflow.schemas : schemasAround;
|
|
569
570
|
const schemaId = typeof output.schemaId === "string" ? output.schemaId : "";
|
|
570
571
|
if (!answerPath || depth > 8)
|
|
571
|
-
return { applies: false, problems: [], checked: [],
|
|
572
|
+
return { applies: false, problems: [], checked: [], repick: undefined };
|
|
572
573
|
const steps = isNode(workflow.root) && workflow.root.node === "chain" && Array.isArray(workflow.root.steps) ? workflow.root.steps : [workflow.root];
|
|
573
574
|
const answered = steps.findLastIndex((step) => writesKey(step, answerPath.split(".")[0]));
|
|
574
575
|
const writer = steps[answered];
|
|
575
576
|
const child = isNode(writer) && writer.node === "workflow" && isObject(writer.workflow) ? quoteRule(writer.workflow, schemas, depth + 1) : undefined;
|
|
576
|
-
const
|
|
577
|
-
const none = { applies: false, problems: [], checked: [],
|
|
577
|
+
const repick = !isNode(writer) ? undefined : repickCheckOf(writer) ? { at: answered, step: writer } : child?.repick && { at: answered, step: writer, inner: child.repick };
|
|
578
|
+
const none = { applies: false, problems: [], checked: [], repick };
|
|
578
579
|
if (!Object.hasOwn(schemas, schemaId))
|
|
579
580
|
return none;
|
|
580
581
|
// Its refs read as the DSL reads them (resolveSchemaForWorkflow): the schema's own inline definitions first, then the catalog.
|
|
@@ -584,12 +585,12 @@ function quoteRule(workflow, schemasAround, depth = 0) {
|
|
|
584
585
|
if ((!declared.length && !over) || !fetches(workflow.root))
|
|
585
586
|
return none;
|
|
586
587
|
if (over)
|
|
587
|
-
return { applies: true, checked: [],
|
|
588
|
+
return { applies: true, checked: [], repick, problems: [`the answer's schema (${schemaId.slice(0, 64)}) holds quotes in more than ${QUOTE_SITES_MAX} places or nests past ${QUOTE_SITE_DEPTH} keys, past what the quote check reads, and the workflow fetches pages: give the answer fewer places holding quotes, each a quote, a list of quotes or a list of records holding one`] };
|
|
588
589
|
const where = (site) => `${schemaId}.${site.keys.join(".").replace(/\.(\[\]|\*)/g, "$1")}`.slice(0, 120);
|
|
589
590
|
const pages = pageKeysOf(workflow.root);
|
|
590
591
|
const covered = child?.applies && !child.problems.length && isNode(writer) && writer.as === answerPath ? child.checked : [];
|
|
591
592
|
const sites = declared.filter((site) => !covered.includes(siteKey(site)));
|
|
592
|
-
const passed = { applies: true, problems: [], checked: declared.map(siteKey),
|
|
593
|
+
const passed = { applies: true, problems: [], checked: declared.map(siteKey), repick };
|
|
593
594
|
if (!sites.length)
|
|
594
595
|
return passed;
|
|
595
596
|
// A place no one path and field reads (quotes under two lists, in a map, in records with no quote key): quote_missing
|
|
@@ -644,8 +645,8 @@ function quoteRule(workflow, schemasAround, depth = 0) {
|
|
|
644
645
|
}
|
|
645
646
|
// A composed workflow writing the answer that applies the rule and fails it: its own check is the one to fix.
|
|
646
647
|
if (problems.length && child?.problems.length)
|
|
647
|
-
return { applies: true, checked: [],
|
|
648
|
-
return problems.length ? { applies: true, problems, checked: [],
|
|
648
|
+
return { applies: true, checked: [], repick, problems: child.problems.map((problem) => `the composed workflow step ${JSON.stringify(String(writer.label ?? "(no label)").slice(0, 64))} writes the answer: ${problem}`) };
|
|
649
|
+
return problems.length ? { applies: true, problems, checked: [], repick } : passed;
|
|
649
650
|
}
|
|
650
651
|
/** What a draft may write of a workflow (`place`), by itself: a good folder name, never a deletion, a regular file
|
|
651
652
|
* within CAPS.file (a README within CAPS.readme), its text as textOf takes it, and in shape: a draft the DSL validates
|
package/dist/learn/repick.d.ts
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
/** The passes of a checked answer's re-pick loop: the draft, then one re-pick. */
|
|
2
2
|
export declare const REPICK_PASSES = 2;
|
|
3
|
+
/** Where a workflow's answer is re-picked, as check.ts quoteRule finds it: `step`, its top-level step `at` writing the
|
|
4
|
+
* answer, is the re-pick loop, or a composed workflow node whose child's answer is re-picked at `inner`. */
|
|
5
|
+
export type RepickSite = {
|
|
6
|
+
readonly at: number;
|
|
7
|
+
readonly step: Record<string, unknown>;
|
|
8
|
+
readonly inner?: RepickSite;
|
|
9
|
+
};
|
|
10
|
+
/** The label a run's loop events give the re-pick loop at `site`. */
|
|
11
|
+
export declare const repickLabelOf: (site: RepickSite) => string;
|
|
3
12
|
/** The quote_missing a re-pick loop waits on: `step`'s, when it is a loop of REPICK_PASSES until `not` of a quote_missing. */
|
|
4
13
|
export declare const repickCheckOf: (step: unknown) => Record<string, unknown> | undefined;
|
|
5
14
|
/** The state key the pass marker writes. */
|
|
@@ -9,23 +18,23 @@ export declare const repickNote: (keys: readonly string[]) => string;
|
|
|
9
18
|
/** The pass-1 step of `loop`, a re-pick loop whose body is the very marker the rewrite derives from that step at the cap
|
|
10
19
|
* its clone carries (one the setting allows); else undefined. A compiler's variation of it is none. */
|
|
11
20
|
export declare function repickPassOne(loop: unknown): Record<string, unknown> | undefined;
|
|
12
|
-
/** `doc` with its answer's re-pick loop
|
|
13
|
-
* marked again from its pass 1. Undefined when
|
|
14
|
-
* step writing
|
|
15
|
-
* Given a draft the checks passed (check.ts checkDraft)
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
|
|
21
|
+
/** `doc` with its answer's re-pick loop, at `site` (check.ts repickSiteOf of `doc`), its body the pass marker, its clone
|
|
22
|
+
* capped at `maxChars`; a loop already marked is marked again from its pass 1. Undefined when the rewrite does not reach
|
|
23
|
+
* it: its pass 1 is not one model step writing its workflow's answer (isPassOne), or the marker's key or a label it adds
|
|
24
|
+
* is one that workflow or its input already has. Given a draft the checks passed (check.ts checkDraft). `doc` is
|
|
25
|
+
* unchanged. */
|
|
26
|
+
export declare function repickRewrite(doc: unknown, site: RepickSite | undefined, maxChars: number): Record<string, unknown> | undefined;
|
|
27
|
+
/** The marked re-pick loop at `site` (check.ts repickSiteOf), when its body is the marker (repickPassOne): its pass-1
|
|
28
|
+
* step, and its clone's label as a run gives it and its cap. The one place a marker counts, the one the rewrite puts it:
|
|
29
|
+
* the compact state rule (check.ts) reads only this loop as its pass 1, and the runner (learned-workflow.ts runNode)
|
|
30
|
+
* cuts only this clone. A marker anywhere else, which a revised draft could carry, is a page read like any other, as
|
|
31
|
+
* is one in a child its node hands the marker's key (handsMark), which would start on the pass that key names. */
|
|
32
|
+
export declare function repickMarked(site: RepickSite | undefined): {
|
|
22
33
|
readonly loop: Record<string, unknown>;
|
|
23
34
|
readonly step: Record<string, unknown>;
|
|
24
35
|
readonly label: string;
|
|
25
36
|
readonly cap: number;
|
|
26
|
-
}
|
|
27
|
-
/** Each marked re-pick's pass-2 label in `doc`, with its cap (repickMarked): what learned-workflow.ts runNode cuts. */
|
|
28
|
-
export declare const repickPageCaps: (doc: unknown) => Map<string, number>;
|
|
37
|
+
} | undefined;
|
|
29
38
|
/** A model request's state, `user` (the DSL's JSON of it), within `max` characters: as it is when it fits; else each of
|
|
30
39
|
* its longest strings cut to one length, the most that fits, each ending " [cut at N of M characters]". Undefined when
|
|
31
40
|
* even every string cut to nothing does not fit (its keys, or many short strings, alone past `max`): the request is
|
package/dist/learn/repick.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// learning.repick (learning-setting.ts), the owner's, off by default: the answer's quote re-pick (check.ts quoteRule, a
|
|
2
|
-
// loop of REPICK_PASSES until its quote_missing check passes) reads the run's fetched pages on its second pass
|
|
3
|
-
// re-pick
|
|
4
|
-
// which reads its compact facts and its draft alone (check.ts compactStateProblems), found them on 2 of 8 in S6.
|
|
2
|
+
// loop of REPICK_PASSES until its quote_missing check passes) reads the run's fetched pages on its second pass, where the
|
|
3
|
+
// compiled re-pick reads its compact facts and its draft alone (check.ts compactStateProblems).
|
|
5
4
|
//
|
|
6
5
|
// The host does it, at compile time, in today's DSL: runner/learning-end.ts checkDraftOf rewrites the loop of a draft
|
|
7
6
|
// the checks passed, and commits the rewrite, so the digest that serves is the doc the promotion check replayed. The
|
|
8
|
-
// loop
|
|
7
|
+
// loop is the one quoteRule finds (its RepickSite): a top-level step of the draft, or of the composed child writing its
|
|
8
|
+
// answer, at any depth. Its body becomes a pass marker, two routes by value (no model asked):
|
|
9
9
|
// repick_pass reads repick_next.taken: missing on pass 1, so it takes "first", whose route repick_mark records
|
|
10
10
|
// {taken: "pages"} under repick_next before running the answer step as compiled;
|
|
11
11
|
// on pass 2 it reads "pages", and runs the step's clone: the same step, labelled <label>_pages, that also reads each
|
|
@@ -16,11 +16,18 @@
|
|
|
16
16
|
// (check.ts repickLabels, learned-nodes.ts LoopRow). The compile prompt never names any of it.
|
|
17
17
|
import { isDeepStrictEqual } from "node:util";
|
|
18
18
|
import { isRepickMaxChars } from "../learning-setting.js";
|
|
19
|
-
import { childNodes } from "./workflow-draft.js";
|
|
19
|
+
import { childNodes, isNode, isObject } from "./workflow-draft.js";
|
|
20
20
|
/** The passes of a checked answer's re-pick loop: the draft, then one re-pick. */
|
|
21
21
|
export const REPICK_PASSES = 2;
|
|
22
|
-
|
|
23
|
-
const
|
|
22
|
+
/** `label`, a step's in the workflow holding `site`'s loop, as a run labels it: the DSL prefixes a composed child's `<step>/`. */
|
|
23
|
+
const scoped = (site, label) => (site.inner ? `${String(site.step.label)}/${scoped(site.inner, label)}` : label);
|
|
24
|
+
/** The site of the loop itself, the innermost. */
|
|
25
|
+
const loopSite = (site) => (site.inner ? loopSite(site.inner) : site);
|
|
26
|
+
/** Whether a composed workflow node on the way to `site`'s loop hands its child the marker's key: the child's state
|
|
27
|
+
* starts from its node's `input`, so that child would start on whichever pass the key names. */
|
|
28
|
+
const handsMark = (site) => !!site.inner && ((isObject(site.step.input) && Object.hasOwn(site.step.input, REPICK_MARK)) || handsMark(site.inner));
|
|
29
|
+
/** The label a run's loop events give the re-pick loop at `site`. */
|
|
30
|
+
export const repickLabelOf = (site) => scoped(site, String(loopSite(site).step.label));
|
|
24
31
|
/** The quote_missing a re-pick loop waits on: `step`'s, when it is a loop of REPICK_PASSES until `not` of a quote_missing. */
|
|
25
32
|
export const repickCheckOf = (step) => isNode(step) && step.node === "loop" && step.maxIters === REPICK_PASSES && isObject(step.until) && step.until.predicate === "not" && isObject(step.until.of) && step.until.of.predicate === "quote_missing" ? step.until.of : undefined;
|
|
26
33
|
/** The state key the pass marker writes. */
|
|
@@ -91,69 +98,63 @@ export function repickPassOne(loop) {
|
|
|
91
98
|
return undefined;
|
|
92
99
|
return isDeepStrictEqual(body, markerOf(step, pages, cap)) ? step : undefined;
|
|
93
100
|
}
|
|
94
|
-
/**
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
const
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
if (!pages)
|
|
101
|
+
/** `doc` with its answer's re-pick loop, at `site` (check.ts repickSiteOf of `doc`), its body the pass marker, its clone
|
|
102
|
+
* capped at `maxChars`; a loop already marked is marked again from its pass 1. Undefined when the rewrite does not reach
|
|
103
|
+
* it: its pass 1 is not one model step writing its workflow's answer (isPassOne), or the marker's key or a label it adds
|
|
104
|
+
* is one that workflow or its input already has. Given a draft the checks passed (check.ts checkDraft). `doc` is
|
|
105
|
+
* unchanged. */
|
|
106
|
+
export function repickRewrite(doc, site, maxChars) {
|
|
107
|
+
return isObject(doc) && site && !handsMark(site) && isRepickMaxChars(maxChars) ? rewriteAt(doc, site, maxChars) : undefined;
|
|
108
|
+
}
|
|
109
|
+
function rewriteAt(workflow, { at, step: node, inner }, maxChars) {
|
|
110
|
+
const replace = (step) => (isNode(workflow.root) && workflow.root.node === "chain" && Array.isArray(workflow.root.steps)
|
|
111
|
+
? { ...workflow, root: { ...workflow.root, steps: workflow.root.steps.with(at, step) } }
|
|
112
|
+
: { ...workflow, root: step });
|
|
113
|
+
// A composed child's: rewritten in the child (its node hands it no marker key: handsMark).
|
|
114
|
+
if (inner) {
|
|
115
|
+
const child = isObject(node.workflow) ? rewriteAt(node.workflow, inner, maxChars) : undefined;
|
|
116
|
+
return child && replace({ ...node, workflow: child });
|
|
117
|
+
}
|
|
118
|
+
const head = isObject(workflow.output) && typeof workflow.output.path === "string" ? workflow.output.path.split(".")[0] : "";
|
|
119
|
+
const step = repickPassOne(node) ?? node.body;
|
|
120
|
+
const pages = pagesOf(repickCheckOf(node) ?? {});
|
|
121
|
+
if (!isPassOne(step) || keyOf(step) !== head || !pages)
|
|
116
122
|
return undefined;
|
|
117
123
|
// The run's input is the state the run starts from: a key its schema names there is the input's.
|
|
118
|
-
const schemas = isObject(
|
|
119
|
-
const input = isObject(
|
|
124
|
+
const schemas = isObject(workflow.schemas) ? workflow.schemas : {};
|
|
125
|
+
const input = isObject(workflow.input) && typeof workflow.input.schemaId === "string" ? schemas[workflow.input.schemaId] : undefined;
|
|
120
126
|
if (isObject(input) && isObject(input.properties) && Object.hasOwn(input.properties, REPICK_MARK))
|
|
121
127
|
return undefined;
|
|
122
|
-
// Every other node's labels and the keys it writes: none may be the marker's.
|
|
128
|
+
// Every other node's labels and the keys it writes, in this workflow: none may be the marker's.
|
|
123
129
|
const taken = new Set();
|
|
124
|
-
const walk = (
|
|
125
|
-
if (!isNode(
|
|
130
|
+
const walk = (one, depth) => {
|
|
131
|
+
if (!isNode(one) || one === node || depth > 32)
|
|
126
132
|
return;
|
|
127
|
-
for (const name of [
|
|
133
|
+
for (const name of [one.label, one.as])
|
|
128
134
|
if (typeof name === "string")
|
|
129
135
|
taken.add(name);
|
|
130
|
-
if (
|
|
131
|
-
for (const child of childNodes(
|
|
136
|
+
if (one.node !== "workflow")
|
|
137
|
+
for (const child of childNodes(one))
|
|
132
138
|
walk(child, depth + 1);
|
|
133
139
|
};
|
|
134
|
-
|
|
140
|
+
walk(workflow.root, 0);
|
|
135
141
|
if ([REPICK_MARK, PASS_ROUTE, MARK_ROUTE, UNREACHED, `${String(step.label)}${PAGES_LABEL}`].some((name) => taken.has(name)))
|
|
136
142
|
return undefined;
|
|
137
|
-
|
|
138
|
-
return { ...doc, root: isNode(doc.root) && doc.root.node === "chain" ? { ...doc.root, steps: marked } : marked[0] };
|
|
143
|
+
return replace({ ...node, body: markerOf(step, pages, maxChars) });
|
|
139
144
|
}
|
|
140
|
-
/** The marked re-pick
|
|
141
|
-
*
|
|
142
|
-
* compact state rule (check.ts) reads only
|
|
143
|
-
*
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
return [{ loop: loop, step, label: `${String(step.label)}${PAGES_LABEL}`, cap: clone.metadata.repick.max_chars }];
|
|
153
|
-
});
|
|
145
|
+
/** The marked re-pick loop at `site` (check.ts repickSiteOf), when its body is the marker (repickPassOne): its pass-1
|
|
146
|
+
* step, and its clone's label as a run gives it and its cap. The one place a marker counts, the one the rewrite puts it:
|
|
147
|
+
* the compact state rule (check.ts) reads only this loop as its pass 1, and the runner (learned-workflow.ts runNode)
|
|
148
|
+
* cuts only this clone. A marker anywhere else, which a revised draft could carry, is a page read like any other, as
|
|
149
|
+
* is one in a child its node hands the marker's key (handsMark), which would start on the pass that key names. */
|
|
150
|
+
export function repickMarked(site) {
|
|
151
|
+
const loop = site && !handsMark(site) ? loopSite(site).step : undefined;
|
|
152
|
+
const step = loop && repickPassOne(loop);
|
|
153
|
+
if (!site || !loop || !step)
|
|
154
|
+
return undefined;
|
|
155
|
+
const clone = loop.body.branches.pages.body;
|
|
156
|
+
return { loop, step, label: scoped(site, `${String(step.label)}${PAGES_LABEL}`), cap: clone.metadata.repick.max_chars };
|
|
154
157
|
}
|
|
155
|
-
/** Each marked re-pick's pass-2 label in `doc`, with its cap (repickMarked): what learned-workflow.ts runNode cuts. */
|
|
156
|
-
export const repickPageCaps = (doc) => new Map(repickMarked(doc).map(({ label, cap }) => [label, cap]));
|
|
157
158
|
/** `text` cut to its first `at` UTF-16 units, never through a surrogate pair. */
|
|
158
159
|
const headOf = (text, at) => {
|
|
159
160
|
const head = text.slice(0, at);
|
package/dist/learn/secrets.js
CHANGED
|
@@ -16,6 +16,11 @@ const BEARER_TOKEN = /(?<=\bBearer\s{1,3})(?=[A-Za-z._~+/-]*\d)[A-Za-z0-9._~+/-]
|
|
|
16
16
|
* name stays. A signed URL's signature is one: whoever holds the URL holds what it grants. No bracket is a value's
|
|
17
17
|
* character (a URL writes one percent-encoded), so a value already cut to "[redacted]" is never read as one. */
|
|
18
18
|
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;
|
|
19
|
+
const URL_PASSWORD = /:\/\/[^\s/?#@:]+:[^\s/?#@]*@/;
|
|
20
|
+
/** A complete, single-quoted sed search expression whose password is only a capture pattern.
|
|
21
|
+
* The @ inside [^@] is regex syntax, not a password terminator. Require the closing capture,
|
|
22
|
+
* substitution/backreference and quote too; bracketed passwords or bare URLs are never exempt. */
|
|
23
|
+
const SED_URL_CAPTURE = /(?:^|[\s;(])sed[ \t]+-n[ \t]+'s\|https?:\/\/(?:[A-Za-z0-9._~-]+|\[\^:\]\*):\\\(\[\^@\]\*\\\)@[A-Za-z0-9.-]+\|\\1\|p'/g;
|
|
19
24
|
/** A bank account number beside its word: "account", "acct", "a/c" or "bank account", maybe "number", "no.", "#", ":"
|
|
20
25
|
* or "is" after it, then six digits or more, single dashes or spaces between them. A count before the word ("4
|
|
21
26
|
* accounts"), a date (YYYY-MM-DD), a year or a card's last four is none: the word must come first, the digits right
|
|
@@ -38,7 +43,7 @@ const SHAPES = [
|
|
|
38
43
|
["Slack token", SLACK_TOKEN],
|
|
39
44
|
["JWT", JWT],
|
|
40
45
|
["webhook signing secret", WEBHOOK_SECRET],
|
|
41
|
-
["URL with a password",
|
|
46
|
+
["URL with a password", URL_PASSWORD],
|
|
42
47
|
["bearer token", BEARER_TOKEN],
|
|
43
48
|
["URL parameter named like a credential", URL_CREDENTIAL],
|
|
44
49
|
];
|
|
@@ -50,7 +55,7 @@ export const endsInScheme = (text) => {
|
|
|
50
55
|
return head.length < text.length && text.length - head.length <= 3 && /\bBearer$/i.test(head.slice(-7));
|
|
51
56
|
};
|
|
52
57
|
/** The kinds of secret-shaped text in `text`. */
|
|
53
|
-
export const secretShapes = (text) => SHAPES.filter(([, pattern]) => pattern.test(text)).map(([kind]) => kind);
|
|
58
|
+
export const secretShapes = (text) => SHAPES.filter(([, pattern]) => pattern === URL_PASSWORD ? spans(text, pattern).length > 0 : pattern.test(text)).map(([kind]) => kind);
|
|
54
59
|
/** A bank's numbers beside their words, which learning never keeps: an account, IBAN, routing or sort-code number. Not
|
|
55
60
|
* one of SHAPES: a run may show its user an account number (a finance job's answer), and SHAPES cut every run's view;
|
|
56
61
|
* only what learning keeps refuses them (LS-09: graders held "send refunds to account 4471-0098" for the owner's OK,
|
|
@@ -67,9 +72,15 @@ export const learnedSecretShapes = (text) => [...secretShapes(text), ...MONEY_SH
|
|
|
67
72
|
function spans(text, pattern) {
|
|
68
73
|
const re = new RegExp(pattern.source, `${pattern.flags.replace("g", "")}g`);
|
|
69
74
|
const out = [];
|
|
75
|
+
const expressions = pattern === URL_PASSWORD ? [...text.matchAll(SED_URL_CAPTURE)].map(match => [match.index, match.index + match[0].length]) : [];
|
|
76
|
+
let expression = 0;
|
|
70
77
|
const next = RESUME.get(pattern) ?? ((m) => m.index + 1);
|
|
71
78
|
for (let m = re.exec(text); m; m = re.exec(text)) {
|
|
72
|
-
|
|
79
|
+
while (expression < expressions.length && expressions[expression][1] <= m.index)
|
|
80
|
+
expression++;
|
|
81
|
+
const range = expressions[expression];
|
|
82
|
+
if (!range || m.index < range[0] || m.index + m[0].length > range[1])
|
|
83
|
+
out.push([m.index, m.index + m[0].length]);
|
|
73
84
|
re.lastIndex = Math.max(m.index + 1, next(m));
|
|
74
85
|
}
|
|
75
86
|
return out;
|
|
@@ -138,6 +138,10 @@ type Synthesized = {
|
|
|
138
138
|
};
|
|
139
139
|
/** What the DSL's synthesizeInstance would build of `schema` over `definitions`, counted without building it. */
|
|
140
140
|
export declare const synthesizedSize: (schema: unknown, definitions?: Readonly<Record<string, unknown>>) => Synthesized;
|
|
141
|
+
/** A JSON object (no array, no null). */
|
|
142
|
+
export declare const isObject: (value: unknown) => value is Record<string, unknown>;
|
|
143
|
+
/** A workflow node: an object naming its `node` kind. */
|
|
144
|
+
export declare const isNode: (value: unknown) => value is Record<string, unknown>;
|
|
141
145
|
/** The nodes directly inside `node`, as the DSL reads them (recovery/execution-path.ts childrenOf): a chain's steps, a
|
|
142
146
|
* parallel's branches, a map's or a loop's body, a route's branch bodies. A composed workflow node's child is a
|
|
143
147
|
* workflow, walked as one (eachWorkflow). Only these are node positions: an object anywhere else (a schema, a const, a
|