@parcha/agentrun-serve 0.0.0-stage → 0.1.0-beta.30
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 +748 -0
- package/LICENSE +202 -0
- package/NOTICE +5 -0
- package/README.md +2190 -2
- package/dist/adapters.d.ts +234 -0
- package/dist/adapters.js +585 -0
- package/dist/agents.d.ts +130 -0
- package/dist/agents.js +308 -0
- package/dist/app.d.ts +7 -0
- package/dist/app.js +384 -0
- package/dist/background.d.ts +28 -0
- package/dist/background.js +376 -0
- package/dist/bound-files.d.ts +4 -0
- package/dist/bound-files.js +164 -0
- package/dist/box/record.d.ts +6 -0
- package/dist/box/record.js +41 -0
- package/dist/box/sweep.d.ts +53 -0
- package/dist/box/sweep.js +193 -0
- package/dist/box-egress.d.ts +98 -0
- package/dist/box-egress.js +259 -0
- package/dist/box-image.d.ts +98 -0
- package/dist/box-image.js +285 -0
- package/dist/box-relay-vm.d.ts +80 -0
- package/dist/box-relay-vm.js +389 -0
- package/dist/box-relay.d.ts +45 -0
- package/dist/box-relay.js +227 -0
- package/dist/boxes.d.ts +72 -0
- package/dist/boxes.js +189 -0
- package/dist/browser-cost.d.ts +41 -0
- package/dist/browser-cost.js +158 -0
- package/dist/cap.d.ts +332 -0
- package/dist/cap.js +992 -0
- package/dist/catalog.d.ts +20 -0
- package/dist/catalog.js +53 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +167 -0
- package/dist/coding-tools.d.ts +35 -0
- package/dist/coding-tools.js +87 -0
- package/dist/console/THIRD-PARTY-NOTICES.txt +1721 -0
- package/dist/console/assets/index-34jfpIbQ.js +481 -0
- package/dist/console/assets/index-DUHbWcIP.css +1 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-400-normal-BEIGL1Tu.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-400-normal-CIEtRijs.woff +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-600-normal-BB5xRk30.woff +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-600-normal-EVf6-Yzo.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-ext-400-normal-BHyURHCj.woff +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-ext-400-normal-C_uLvvQ5.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-ext-600-normal-Dj6eZy5f.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-cyrillic-ext-600-normal-DpeVePZf.woff +0 -0
- package/dist/console/assets/jetbrains-mono-greek-400-normal-C190GLew.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-greek-400-normal-CNojz0t3.woff +0 -0
- package/dist/console/assets/jetbrains-mono-greek-600-normal-3KAm9r92.woff +0 -0
- package/dist/console/assets/jetbrains-mono-greek-600-normal-H7WoG9Et.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-latin-400-normal-B11XCQ5g.woff +0 -0
- package/dist/console/assets/jetbrains-mono-latin-400-normal-V6pRDFza.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-latin-600-normal-C8RAYTDA.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-latin-600-normal-DXv3JcnD.woff +0 -0
- package/dist/console/assets/jetbrains-mono-latin-ext-400-normal-Bc8Ftmh3.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-latin-ext-400-normal-DHMOLxAi.woff +0 -0
- package/dist/console/assets/jetbrains-mono-latin-ext-600-normal-BfB_LPfz.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-latin-ext-600-normal-DiQlUoE6.woff +0 -0
- package/dist/console/assets/jetbrains-mono-vietnamese-400-normal-BeU3T8wf.woff +0 -0
- package/dist/console/assets/jetbrains-mono-vietnamese-400-normal-ByoDsISC.woff2 +0 -0
- package/dist/console/assets/jetbrains-mono-vietnamese-600-normal-CSpzN4cI.woff +0 -0
- package/dist/console/assets/jetbrains-mono-vietnamese-600-normal-Dtizs43-.woff2 +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-400-normal-Cph9ettZ.woff2 +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-400-normal-DfGZKnlb.woff +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-600-normal-BGBUNdzT.woff2 +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-600-normal-COje25QW.woff +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-ext-400-normal-4l4lq8zr.woff2 +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-ext-400-normal-BGzXWJeR.woff +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-ext-600-normal-8_E36CQj.woff2 +0 -0
- package/dist/console/assets/schibsted-grotesk-latin-ext-600-normal-C27an7Zc.woff +0 -0
- package/dist/console/index.html +15 -0
- package/dist/content-filter.d.ts +7 -0
- package/dist/content-filter.js +23 -0
- package/dist/daytona-api.d.ts +21 -0
- package/dist/daytona-api.js +101 -0
- package/dist/decision-rows.d.ts +19 -0
- package/dist/decision-rows.js +123 -0
- package/dist/decisions.d.ts +94 -0
- package/dist/decisions.js +184 -0
- package/dist/effort-guidance.d.ts +5 -0
- package/dist/effort-guidance.js +14 -0
- package/dist/environment.d.ts +5 -0
- package/dist/environment.js +11 -0
- package/dist/errors.d.ts +74 -0
- package/dist/errors.js +69 -0
- package/dist/exa-keyless.d.ts +35 -0
- package/dist/exa-keyless.js +202 -0
- package/dist/fetch-page.d.ts +114 -0
- package/dist/fetch-page.js +182 -0
- package/dist/files.d.ts +65 -0
- package/dist/files.js +158 -0
- package/dist/grade.d.ts +93 -0
- package/dist/grade.js +328 -0
- package/dist/graph-served.d.ts +23 -0
- package/dist/graph-served.js +75 -0
- package/dist/graph-view.d.ts +102 -0
- package/dist/graph-view.js +219 -0
- package/dist/harness-app.d.ts +40 -0
- package/dist/harness-app.js +708 -0
- package/dist/harness-opencode/adapter.d.ts +45 -0
- package/dist/harness-opencode/adapter.js +272 -0
- package/dist/harness-opencode/binary.d.ts +18 -0
- package/dist/harness-opencode/binary.js +87 -0
- package/dist/harness-opencode/config.d.ts +24 -0
- package/dist/harness-opencode/config.js +61 -0
- package/dist/harness-opencode/harness.d.ts +77 -0
- package/dist/harness-opencode/harness.js +620 -0
- package/dist/harness-opencode/host/mcp.d.ts +40 -0
- package/dist/harness-opencode/host/mcp.js +208 -0
- package/dist/harness-opencode/host/policy.d.ts +71 -0
- package/dist/harness-opencode/host/policy.js +419 -0
- package/dist/harness-opencode/host/server.d.ts +55 -0
- package/dist/harness-opencode/host/server.js +165 -0
- package/dist/harness-opencode/index.d.ts +9 -0
- package/dist/harness-opencode/index.js +6 -0
- package/dist/harness-opencode/verify.d.ts +32 -0
- package/dist/harness-opencode/verify.js +75 -0
- package/dist/harness-opencode/versions.d.ts +33 -0
- package/dist/harness-opencode/versions.js +64 -0
- package/dist/harness.d.ts +56 -0
- package/dist/harness.js +77 -0
- package/dist/home-path.d.ts +27 -0
- package/dist/home-path.js +78 -0
- package/dist/host-tools.d.ts +30 -0
- package/dist/host-tools.js +154 -0
- package/dist/host.d.ts +39 -0
- package/dist/host.js +85 -0
- package/dist/hosted-search.d.ts +27 -0
- package/dist/hosted-search.js +133 -0
- package/dist/import-sources.d.ts +104 -0
- package/dist/import-sources.js +629 -0
- package/dist/import-summary.d.ts +25 -0
- package/dist/import-summary.js +75 -0
- package/dist/import-worker.d.ts +26 -0
- package/dist/import-worker.js +41 -0
- package/dist/import.d.ts +145 -0
- package/dist/import.js +1222 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +6 -0
- package/dist/key-check.d.ts +37 -0
- package/dist/key-check.js +112 -0
- package/dist/key-refusal.d.ts +51 -0
- package/dist/key-refusal.js +191 -0
- package/dist/learn/check.d.ts +108 -0
- package/dist/learn/check.js +277 -0
- package/dist/learn/grade.d.ts +80 -0
- package/dist/learn/grade.js +445 -0
- package/dist/learn/index.d.ts +7 -0
- package/dist/learn/index.js +11 -0
- package/dist/learn/invisible.d.ts +5 -0
- package/dist/learn/invisible.js +42 -0
- package/dist/learn/notes.d.ts +59 -0
- package/dist/learn/notes.js +147 -0
- package/dist/learn/reflect.d.ts +49 -0
- package/dist/learn/reflect.js +213 -0
- package/dist/learn/secrets.d.ts +18 -0
- package/dist/learn/secrets.js +131 -0
- package/dist/learn/skills.d.ts +97 -0
- package/dist/learn/skills.js +271 -0
- package/dist/learned-workflow.d.ts +59 -0
- package/dist/learned-workflow.js +191 -0
- package/dist/learning-routes.d.ts +196 -0
- package/dist/learning-routes.js +609 -0
- package/dist/learning-run.d.ts +306 -0
- package/dist/learning-run.js +819 -0
- package/dist/learning-words.d.ts +76 -0
- package/dist/learning-words.js +174 -0
- package/dist/learning.d.ts +418 -0
- package/dist/learning.js +946 -0
- package/dist/llm.d.ts +40 -0
- package/dist/llm.js +37 -0
- package/dist/llms.txt +37 -0
- package/dist/mcp-servers.d.ts +118 -0
- package/dist/mcp-servers.js +450 -0
- package/dist/mcp.d.ts +51 -0
- package/dist/mcp.js +392 -0
- package/dist/model.d.ts +186 -0
- package/dist/model.js +485 -0
- package/dist/monid.d.ts +74 -0
- package/dist/monid.js +277 -0
- package/dist/openapi/agentrun-v2.openapi.json +4806 -0
- package/dist/openapi.d.ts +10 -0
- package/dist/openapi.js +1727 -0
- package/dist/owner.d.ts +55 -0
- package/dist/owner.js +222 -0
- package/dist/packs.d.ts +71 -0
- package/dist/packs.js +180 -0
- package/dist/page.d.ts +32 -0
- package/dist/page.js +133 -0
- package/dist/paid-calls.d.ts +50 -0
- package/dist/paid-calls.js +110 -0
- package/dist/pause.d.ts +70 -0
- package/dist/pause.js +97 -0
- package/dist/pdf-pages.d.ts +44 -0
- package/dist/pdf-pages.js +147 -0
- package/dist/place.d.ts +69 -0
- package/dist/place.js +137 -0
- package/dist/print.d.ts +20 -0
- package/dist/print.js +29 -0
- package/dist/propose.d.ts +40 -0
- package/dist/propose.js +112 -0
- package/dist/quiet-sqlite-warning.d.ts +1 -0
- package/dist/quiet-sqlite-warning.js +14 -0
- package/dist/request-start.d.ts +22 -0
- package/dist/request-start.js +350 -0
- package/dist/result.d.ts +3 -0
- package/dist/result.js +5 -0
- package/dist/rows.d.ts +46 -0
- package/dist/rows.js +121 -0
- package/dist/run-box.d.ts +186 -0
- package/dist/run-box.js +590 -0
- package/dist/run-manifest.d.ts +27 -0
- package/dist/run-manifest.js +60 -0
- package/dist/runnable.d.ts +83 -0
- package/dist/runnable.js +170 -0
- package/dist/runs.d.ts +1062 -0
- package/dist/runs.js +3020 -0
- package/dist/secret-cut.d.ts +27 -0
- package/dist/secret-cut.js +109 -0
- package/dist/secrets.d.ts +62 -0
- package/dist/secrets.js +158 -0
- package/dist/server-lock.d.ts +44 -0
- package/dist/server-lock.js +140 -0
- package/dist/server.d.ts +722 -0
- package/dist/server.js +2118 -0
- package/dist/sessions.d.ts +4 -0
- package/dist/sessions.js +105 -0
- package/dist/sign-ins.d.ts +99 -0
- package/dist/sign-ins.js +288 -0
- package/dist/skills.d.ts +43 -0
- package/dist/skills.js +96 -0
- package/dist/stats.d.ts +106 -0
- package/dist/stats.js +103 -0
- package/dist/tool-gate.d.ts +266 -0
- package/dist/tool-gate.js +554 -0
- package/dist/tool-keys.d.ts +187 -0
- package/dist/tool-keys.js +315 -0
- package/dist/tool-plane.d.ts +228 -0
- package/dist/tool-plane.js +400 -0
- package/dist/tools.d.ts +202 -0
- package/dist/tools.js +372 -0
- package/dist/trigger-secrets.d.ts +32 -0
- package/dist/trigger-secrets.js +143 -0
- package/dist/triggers.d.ts +439 -0
- package/dist/triggers.js +863 -0
- package/dist/turn-end.d.ts +24 -0
- package/dist/turn-end.js +15 -0
- package/dist/turns.d.ts +34 -0
- package/dist/turns.js +202 -0
- package/dist/uploads.d.ts +104 -0
- package/dist/uploads.js +474 -0
- package/dist/usage-lines.d.ts +26 -0
- package/dist/usage-lines.js +28 -0
- package/dist/usage.d.ts +29 -0
- package/dist/usage.js +58 -0
- package/dist/validate.d.ts +57 -0
- package/dist/validate.js +184 -0
- package/dist/web-fetch.d.ts +64 -0
- package/dist/web-fetch.js +262 -0
- package/dist/web-search.d.ts +54 -0
- package/dist/web-search.js +136 -0
- package/dist/webhooks.d.ts +189 -0
- package/dist/webhooks.js +503 -0
- package/dist/workspace-paths.d.ts +33 -0
- package/dist/workspace-paths.js +104 -0
- package/dist/workspace.d.ts +88 -0
- package/dist/workspace.js +369 -0
- package/launcher/agentrun-serve +109 -0
- package/package.json +100 -4
- package/skills/agentrun-serve/SKILL.md +128 -0
package/dist/owner.d.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export declare const OWNER_FILE = "owner.json";
|
|
2
|
+
export declare const SESSION_SECRET_FILE = ".session-secret";
|
|
3
|
+
/** How long a session lasts, from the signed payload (the cookie's Max-Age only tells the browser when to drop it). */
|
|
4
|
+
export declare const SESSION_MS: number;
|
|
5
|
+
/** The most addresses the sign-in limit keeps at once; a new one past it is refused, never let in by evicting another. */
|
|
6
|
+
export declare const SIGN_IN_PEERS = 10000;
|
|
7
|
+
/** Why `password` cannot be the owner's, or undefined. Characters are counted as a person sees them. */
|
|
8
|
+
export declare function passwordProblem(password: unknown): string | undefined;
|
|
9
|
+
export declare class Owner {
|
|
10
|
+
private readonly dir;
|
|
11
|
+
readonly openSetup: boolean;
|
|
12
|
+
private readonly say;
|
|
13
|
+
private readonly addresses;
|
|
14
|
+
private readonly file;
|
|
15
|
+
private readonly secret;
|
|
16
|
+
private readonly tries;
|
|
17
|
+
private setupCode;
|
|
18
|
+
private base;
|
|
19
|
+
/** Taken while a first password is being set, so a second at the same moment is refused. */
|
|
20
|
+
private settingUp;
|
|
21
|
+
/** `openSetup`: no setup code; the first visit sets the password (no public address). `say` prints a setup code. */
|
|
22
|
+
constructor(dir: string, openSetup: boolean, say?: (line: string) => void, addresses?: number);
|
|
23
|
+
private read;
|
|
24
|
+
hasPassword(): boolean;
|
|
25
|
+
/** The address the setup link is printed with, fixed once the server listens. */
|
|
26
|
+
attach(baseUrl: string): void;
|
|
27
|
+
/** The setup page's link: with its code when setup needs one, a new code printed (never answered) when none is good. */
|
|
28
|
+
setupLink(): string;
|
|
29
|
+
/** Whether `given` is the setup code: wrong ones count, and the fifth voids it until a new one is printed. */
|
|
30
|
+
private spendCode;
|
|
31
|
+
/** The first password, from setup: refused once there is one (`exists`) or while another is being set. `byToken`: the
|
|
32
|
+
* server's token stands in for the code. */
|
|
33
|
+
/** `along`: what the setup keeps with the owner (setup's import), written once the setup is the one going on and before
|
|
34
|
+
* the password is: a setup that cannot write it sets no owner, and one whose password is not written takes it back. */
|
|
35
|
+
setFirst(password: string, code: unknown, byToken: boolean, along?: {
|
|
36
|
+
keep: () => Promise<unknown>;
|
|
37
|
+
drop: () => Promise<unknown>;
|
|
38
|
+
}): Promise<"ok" | "exists" | "code">;
|
|
39
|
+
private setPassword;
|
|
40
|
+
/** Whether `peer` may try a password now, counting the try: "limited" past its tries, "full" when the table holds as
|
|
41
|
+
* many addresses as it keeps and this is a new one. Expired addresses are swept before a new one is refused. */
|
|
42
|
+
allow(peer: string): "ok" | "limited" | "full";
|
|
43
|
+
/** Whether `password` is the owner's. scrypt runs for a wrong one as for a right one; the compare is constant-time. */
|
|
44
|
+
check(password: string): Promise<boolean>;
|
|
45
|
+
/** A session cookie's value: its payload and the payload's HMAC. */
|
|
46
|
+
session(): string;
|
|
47
|
+
private mac;
|
|
48
|
+
/** Whether `value` is a session this server made, not past its end, in the current epoch. */
|
|
49
|
+
valid(value: string): boolean;
|
|
50
|
+
/** Ends every session, on every browser. */
|
|
51
|
+
signOutEverywhere(): void;
|
|
52
|
+
}
|
|
53
|
+
/** `agentrun-serve reset-password`: clears the password and ends every session, so the next visit sets a new one. Run
|
|
54
|
+
* where the data directory is (inside the container); never an HTTP route. */
|
|
55
|
+
export declare function resetPassword(dir: string): void;
|
package/dist/owner.js
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
// The owner: the one person this server is for, signed in with a password. DIR/owner.json (0600) holds the password's
|
|
2
|
+
// scrypt hash with its salt and parameters, and the session epoch; DIR/.session-secret (0600) holds the key a session
|
|
3
|
+
// cookie is signed with. A cookie carries when it was made, when it ends (30 days) and the epoch it was made in, under an
|
|
4
|
+
// HMAC: setting the password, signing out and `agentrun-serve reset-password` each move the epoch on, so every cookie
|
|
5
|
+
// made before stops working on every browser. Both files are read again on every check, so a reset run beside a live
|
|
6
|
+
// server takes effect at once. Nothing here is ever logged but the setup code a server with a public address prints.
|
|
7
|
+
import { createHash, createHmac, randomBytes, scrypt, timingSafeEqual } from "node:crypto";
|
|
8
|
+
import { readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
9
|
+
import { join } from "node:path";
|
|
10
|
+
export const OWNER_FILE = "owner.json";
|
|
11
|
+
export const SESSION_SECRET_FILE = ".session-secret";
|
|
12
|
+
/** How long a session lasts, from the signed payload (the cookie's Max-Age only tells the browser when to drop it). */
|
|
13
|
+
export const SESSION_MS = 30 * 86_400_000;
|
|
14
|
+
const MIN_PASSWORD_CHARS = 12;
|
|
15
|
+
/** A longer one would only make scrypt work for nothing. */
|
|
16
|
+
const MAX_PASSWORD_BYTES = 1024;
|
|
17
|
+
/** scrypt's cost: 2^15, r 8, p 1, which OWASP gives for scrypt; kept beside each hash, so it can be raised later. */
|
|
18
|
+
const COST = { N: 2 ** 15, r: 8, p: 1 };
|
|
19
|
+
const KEY_BYTES = 32;
|
|
20
|
+
const SIGN_INS_PER_PEER = 10;
|
|
21
|
+
const SIGN_IN_WINDOW_MS = 15 * 60_000;
|
|
22
|
+
/** The most addresses the sign-in limit keeps at once; a new one past it is refused, never let in by evicting another. */
|
|
23
|
+
export const SIGN_IN_PEERS = 10_000;
|
|
24
|
+
const SETUP_TTL_MS = 30 * 60_000;
|
|
25
|
+
const SETUP_TRIES = 5;
|
|
26
|
+
const derive = (password, salt, { N, r, p }) => new Promise((resolve, reject) => scrypt(password, salt, KEY_BYTES, { N, r, p, maxmem: 256 * N * r }, (error, key) => (error ? reject(error) : resolve(key))));
|
|
27
|
+
/** Writes `text` to `file` whole, mode 0600: a reader sees the old file or the new one. */
|
|
28
|
+
function writePrivate(file, text) {
|
|
29
|
+
writeFileSync(`${file}.partial`, text, { mode: 0o600 });
|
|
30
|
+
renameSync(`${file}.partial`, file);
|
|
31
|
+
}
|
|
32
|
+
/** Why `password` cannot be the owner's, or undefined. Characters are counted as a person sees them. */
|
|
33
|
+
export function passwordProblem(password) {
|
|
34
|
+
if (typeof password !== "string")
|
|
35
|
+
return "password is text";
|
|
36
|
+
if (Buffer.byteLength(password) > MAX_PASSWORD_BYTES)
|
|
37
|
+
return `password is at most ${MAX_PASSWORD_BYTES} bytes`;
|
|
38
|
+
if (Array.from(password).length < MIN_PASSWORD_CHARS)
|
|
39
|
+
return `password is ${MIN_PASSWORD_CHARS} characters or more`;
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
export class Owner {
|
|
43
|
+
dir;
|
|
44
|
+
openSetup;
|
|
45
|
+
say;
|
|
46
|
+
addresses;
|
|
47
|
+
file;
|
|
48
|
+
secret;
|
|
49
|
+
tries = new Map();
|
|
50
|
+
setupCode = null;
|
|
51
|
+
base = "";
|
|
52
|
+
/** Taken while a first password is being set, so a second at the same moment is refused. */
|
|
53
|
+
settingUp = false;
|
|
54
|
+
/** `openSetup`: no setup code; the first visit sets the password (no public address). `say` prints a setup code. */
|
|
55
|
+
constructor(dir, openSetup, say = () => { }, addresses = SIGN_IN_PEERS) {
|
|
56
|
+
this.dir = dir;
|
|
57
|
+
this.openSetup = openSetup;
|
|
58
|
+
this.say = say;
|
|
59
|
+
this.addresses = addresses;
|
|
60
|
+
this.file = join(dir, OWNER_FILE);
|
|
61
|
+
const secretFile = join(dir, SESSION_SECRET_FILE);
|
|
62
|
+
let secret;
|
|
63
|
+
try {
|
|
64
|
+
secret = Buffer.from(readFileSync(secretFile, "utf8").trim(), "base64url");
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
// made below
|
|
68
|
+
}
|
|
69
|
+
if (!secret || secret.length < 32) {
|
|
70
|
+
secret = randomBytes(32);
|
|
71
|
+
writePrivate(secretFile, `${secret.toString("base64url")}\n`);
|
|
72
|
+
}
|
|
73
|
+
this.secret = secret;
|
|
74
|
+
try {
|
|
75
|
+
readFileSync(this.file);
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
writePrivate(this.file, `${JSON.stringify({ v: 1, epoch: 0 })}\n`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
read() {
|
|
82
|
+
const stored = JSON.parse(readFileSync(this.file, "utf8"));
|
|
83
|
+
if (stored.v !== 1 || !Number.isSafeInteger(stored.epoch))
|
|
84
|
+
throw new Error(`${OWNER_FILE} is not one this server reads`);
|
|
85
|
+
return stored;
|
|
86
|
+
}
|
|
87
|
+
hasPassword() {
|
|
88
|
+
return this.read().password !== undefined;
|
|
89
|
+
}
|
|
90
|
+
/** The address the setup link is printed with, fixed once the server listens. */
|
|
91
|
+
attach(baseUrl) {
|
|
92
|
+
this.base = baseUrl;
|
|
93
|
+
}
|
|
94
|
+
/** The setup page's link: with its code when setup needs one, a new code printed (never answered) when none is good. */
|
|
95
|
+
setupLink() {
|
|
96
|
+
if (this.openSetup)
|
|
97
|
+
return `${this.base}/setup`;
|
|
98
|
+
if (!this.setupCode || Date.now() > this.setupCode.until) {
|
|
99
|
+
this.setupCode = { code: randomBytes(16).toString("base64url"), until: Date.now() + SETUP_TTL_MS, tries: 0 };
|
|
100
|
+
this.say(`Set up this server: ${this.base}/setup#code=${this.setupCode.code}`);
|
|
101
|
+
}
|
|
102
|
+
return `${this.base}/setup#code=${this.setupCode.code}`;
|
|
103
|
+
}
|
|
104
|
+
/** Whether `given` is the setup code: wrong ones count, and the fifth voids it until a new one is printed. */
|
|
105
|
+
spendCode(given) {
|
|
106
|
+
const setup = this.setupCode;
|
|
107
|
+
// None good (spent, voided, expired, or the password was reset since): a new one goes to the log.
|
|
108
|
+
if (!setup || Date.now() > setup.until)
|
|
109
|
+
return (this.setupCode = null), this.setupLink(), "none";
|
|
110
|
+
const digest = (text) => createHash("sha256").update(text).digest();
|
|
111
|
+
if (typeof given === "string" && timingSafeEqual(digest(given), digest(setup.code)))
|
|
112
|
+
return (this.setupCode = null), "ok";
|
|
113
|
+
if (++setup.tries >= SETUP_TRIES)
|
|
114
|
+
this.setupCode = null;
|
|
115
|
+
return "wrong";
|
|
116
|
+
}
|
|
117
|
+
/** The first password, from setup: refused once there is one (`exists`) or while another is being set. `byToken`: the
|
|
118
|
+
* server's token stands in for the code. */
|
|
119
|
+
/** `along`: what the setup keeps with the owner (setup's import), written once the setup is the one going on and before
|
|
120
|
+
* the password is: a setup that cannot write it sets no owner, and one whose password is not written takes it back. */
|
|
121
|
+
async setFirst(password, code, byToken, along) {
|
|
122
|
+
if (this.settingUp || this.hasPassword())
|
|
123
|
+
return "exists";
|
|
124
|
+
this.settingUp = true;
|
|
125
|
+
try {
|
|
126
|
+
if (!byToken && !this.openSetup) {
|
|
127
|
+
const spent = this.spendCode(code);
|
|
128
|
+
if (spent !== "ok")
|
|
129
|
+
return "code";
|
|
130
|
+
}
|
|
131
|
+
await along?.keep();
|
|
132
|
+
try {
|
|
133
|
+
await this.setPassword(password);
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
await along?.drop();
|
|
137
|
+
throw error;
|
|
138
|
+
}
|
|
139
|
+
return "ok";
|
|
140
|
+
}
|
|
141
|
+
finally {
|
|
142
|
+
this.settingUp = false;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
async setPassword(password) {
|
|
146
|
+
const salt = randomBytes(16);
|
|
147
|
+
const key = await derive(password, salt, COST);
|
|
148
|
+
const stored = this.read();
|
|
149
|
+
writePrivate(this.file, `${JSON.stringify({ v: 1, epoch: stored.epoch + 1, password: { ...COST, salt: salt.toString("base64url"), hash: key.toString("base64url") } })}\n`);
|
|
150
|
+
}
|
|
151
|
+
/** Whether `peer` may try a password now, counting the try: "limited" past its tries, "full" when the table holds as
|
|
152
|
+
* many addresses as it keeps and this is a new one. Expired addresses are swept before a new one is refused. */
|
|
153
|
+
allow(peer) {
|
|
154
|
+
const now = Date.now();
|
|
155
|
+
const live = (at) => now - at < SIGN_IN_WINDOW_MS;
|
|
156
|
+
if (!this.tries.has(peer) && this.tries.size >= this.addresses) {
|
|
157
|
+
for (const [known, at] of this.tries)
|
|
158
|
+
if (!at.some(live))
|
|
159
|
+
this.tries.delete(known);
|
|
160
|
+
if (this.tries.size >= this.addresses)
|
|
161
|
+
return "full";
|
|
162
|
+
}
|
|
163
|
+
const recent = (this.tries.get(peer) ?? []).filter(live);
|
|
164
|
+
if (recent.length >= SIGN_INS_PER_PEER)
|
|
165
|
+
return (this.tries.set(peer, recent), "limited");
|
|
166
|
+
this.tries.set(peer, [...recent, now]);
|
|
167
|
+
return "ok";
|
|
168
|
+
}
|
|
169
|
+
/** Whether `password` is the owner's. scrypt runs for a wrong one as for a right one; the compare is constant-time. */
|
|
170
|
+
async check(password) {
|
|
171
|
+
const stored = this.read().password;
|
|
172
|
+
const salt = stored ? Buffer.from(stored.salt, "base64url") : randomBytes(16);
|
|
173
|
+
const key = await derive(password, salt, stored ?? COST);
|
|
174
|
+
const expected = stored ? Buffer.from(stored.hash, "base64url") : randomBytes(KEY_BYTES);
|
|
175
|
+
return stored !== undefined && key.length === expected.length && timingSafeEqual(key, expected);
|
|
176
|
+
}
|
|
177
|
+
/** A session cookie's value: its payload and the payload's HMAC. */
|
|
178
|
+
session() {
|
|
179
|
+
const now = Date.now();
|
|
180
|
+
const payload = Buffer.from(JSON.stringify({ iat: now, exp: now + SESSION_MS, epoch: this.read().epoch })).toString("base64url");
|
|
181
|
+
return `${payload}.${this.mac(payload)}`;
|
|
182
|
+
}
|
|
183
|
+
mac(payload) {
|
|
184
|
+
return createHmac("sha256", this.secret).update(payload).digest("base64url");
|
|
185
|
+
}
|
|
186
|
+
/** Whether `value` is a session this server made, not past its end, in the current epoch. */
|
|
187
|
+
valid(value) {
|
|
188
|
+
const dot = value.indexOf(".");
|
|
189
|
+
if (dot <= 0)
|
|
190
|
+
return false;
|
|
191
|
+
const payload = value.slice(0, dot);
|
|
192
|
+
const given = Buffer.from(value.slice(dot + 1));
|
|
193
|
+
const expected = Buffer.from(this.mac(payload));
|
|
194
|
+
if (given.length !== expected.length || !timingSafeEqual(given, expected))
|
|
195
|
+
return false;
|
|
196
|
+
try {
|
|
197
|
+
const { exp, epoch } = JSON.parse(Buffer.from(payload, "base64url").toString("utf8"));
|
|
198
|
+
return typeof exp === "number" && Date.now() < exp && epoch === this.read().epoch && this.hasPassword();
|
|
199
|
+
}
|
|
200
|
+
catch {
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
/** Ends every session, on every browser. */
|
|
205
|
+
signOutEverywhere() {
|
|
206
|
+
const stored = this.read();
|
|
207
|
+
writePrivate(this.file, `${JSON.stringify({ ...stored, epoch: stored.epoch + 1 })}\n`);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
/** `agentrun-serve reset-password`: clears the password and ends every session, so the next visit sets a new one. Run
|
|
211
|
+
* where the data directory is (inside the container); never an HTTP route. */
|
|
212
|
+
export function resetPassword(dir) {
|
|
213
|
+
const file = join(dir, OWNER_FILE);
|
|
214
|
+
let epoch = 0;
|
|
215
|
+
try {
|
|
216
|
+
epoch = JSON.parse(readFileSync(file, "utf8")).epoch;
|
|
217
|
+
}
|
|
218
|
+
catch {
|
|
219
|
+
// no owner yet: written fresh
|
|
220
|
+
}
|
|
221
|
+
writePrivate(file, `${JSON.stringify({ v: 1, epoch: epoch + 1 })}\n`);
|
|
222
|
+
}
|
package/dist/packs.d.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { InputIssue } from "./errors.js";
|
|
2
|
+
import { type Effort, THINKING_LEVELS } from "./model.js";
|
|
3
|
+
/** A pack's name. */
|
|
4
|
+
export declare const PACK_NAME: RegExp;
|
|
5
|
+
/** An output type: a key of a pack's `outputs`. */
|
|
6
|
+
export declare const OUTPUT_TYPE: RegExp;
|
|
7
|
+
/** A skill name a pack names: the name rule Agent Skills and the Claude adapter use. */
|
|
8
|
+
export declare const PACK_SKILL: RegExp;
|
|
9
|
+
/** The most skills one list of a pack names. */
|
|
10
|
+
export declare const MAX_PACK_SKILLS = 32;
|
|
11
|
+
/** The most output types one pack names. */
|
|
12
|
+
export declare const MAX_PACK_OUTPUTS = 32;
|
|
13
|
+
/** The longest output file: the same cap serve applies to a skill path. */
|
|
14
|
+
export declare const MAX_OUTPUT_FILE = 512;
|
|
15
|
+
export type Thinking = (typeof THINKING_LEVELS)[number];
|
|
16
|
+
/** Skill names, in the order the run loads them. */
|
|
17
|
+
export type PackSkills = {
|
|
18
|
+
skills: string[];
|
|
19
|
+
};
|
|
20
|
+
/** One effort's row: its skills, and the thinking level a run at that effort gets, if the pack sets one. */
|
|
21
|
+
export type PackEffort = PackSkills & {
|
|
22
|
+
thinking?: Thinking;
|
|
23
|
+
};
|
|
24
|
+
/** One output type: its writer skills, the file it lands in, and the writer skills that replace them at an effort. */
|
|
25
|
+
export type PackOutput = PackSkills & {
|
|
26
|
+
file?: string;
|
|
27
|
+
effort?: Partial<Record<Effort, PackSkills>>;
|
|
28
|
+
};
|
|
29
|
+
/** A profile pack, version 1. */
|
|
30
|
+
export type Pack = {
|
|
31
|
+
version: 1;
|
|
32
|
+
name: string;
|
|
33
|
+
effort: Record<Effort, PackEffort>;
|
|
34
|
+
outputs: Record<string, PackOutput>;
|
|
35
|
+
default_output?: string;
|
|
36
|
+
};
|
|
37
|
+
/** What a run asks of a pack: its effort (medium when absent) and its output type (the pack's default when absent). */
|
|
38
|
+
export type PackAsk = {
|
|
39
|
+
effort?: Effort;
|
|
40
|
+
output?: string;
|
|
41
|
+
};
|
|
42
|
+
/** A pack read for one run: the effort, its thinking level if the pack sets one, every skill to load in order, and the
|
|
43
|
+
* output type with its file, if the run writes one. */
|
|
44
|
+
export type ResolvedPack = {
|
|
45
|
+
effort: Effort;
|
|
46
|
+
thinking?: Thinking;
|
|
47
|
+
skills: string[];
|
|
48
|
+
output?: {
|
|
49
|
+
type: string;
|
|
50
|
+
file?: string;
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Every issue with `value` as a version 1 pack, none if it is one. Fields are paths into the pack
|
|
55
|
+
* (`effort.low.skills[0]`), under `at` when given (`profile.effort.low.skills[0]`); the pack itself is `at`. A skill
|
|
56
|
+
* list or `outputs` over its limit is `too_many`, and its items up to the limit are checked as any others; items past
|
|
57
|
+
* the limit are not checked, so an oversized pack makes a bounded number of issues.
|
|
58
|
+
*/
|
|
59
|
+
export declare function packIssues(value: unknown, { at }?: {
|
|
60
|
+
at?: string | undefined;
|
|
61
|
+
}): InputIssue[];
|
|
62
|
+
/**
|
|
63
|
+
* `pack` (one packIssues finds nothing wrong with) read for a run at `effort` asked for `output`: the effort row's
|
|
64
|
+
* skills, then the output's writer skills (its skills at that effort if it names some there, else its own), each skill
|
|
65
|
+
* once at its first place. With no output asked, the pack's default_output; with neither, no output and no writer.
|
|
66
|
+
* `thinking` is there only when the effort row sets one, so the caller keeps its own level otherwise. An effort that is
|
|
67
|
+
* not one, or an output type the pack does not name, is an issue on `effort` or `output`.
|
|
68
|
+
*/
|
|
69
|
+
export declare function resolvePack(pack: Pack, { effort, output }?: PackAsk): ResolvedPack | {
|
|
70
|
+
issues: InputIssue[];
|
|
71
|
+
};
|
package/dist/packs.js
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { EFFORTS, THINKING_LEVELS } from "./model.js";
|
|
2
|
+
import { isObject } from "./validate.js";
|
|
3
|
+
/** A pack's name. */
|
|
4
|
+
export const PACK_NAME = /^[a-z0-9][a-z0-9-]{0,63}$/;
|
|
5
|
+
/** An output type: a key of a pack's `outputs`. */
|
|
6
|
+
export const OUTPUT_TYPE = /^[a-z0-9][a-z0-9_-]{0,63}$/;
|
|
7
|
+
/** A skill name a pack names: the name rule Agent Skills and the Claude adapter use. */
|
|
8
|
+
export const PACK_SKILL = /^[a-z0-9][a-z0-9-]{0,63}$/;
|
|
9
|
+
/** The most skills one list of a pack names. */
|
|
10
|
+
export const MAX_PACK_SKILLS = 32;
|
|
11
|
+
/** The most output types one pack names. */
|
|
12
|
+
export const MAX_PACK_OUTPUTS = 32;
|
|
13
|
+
/** The longest output file: the same cap serve applies to a skill path. */
|
|
14
|
+
export const MAX_OUTPUT_FILE = 512;
|
|
15
|
+
const PACK_FIELDS = ["version", "name", "effort", "outputs", "default_output"];
|
|
16
|
+
const EFFORT_FIELDS = ["skills", "thinking"];
|
|
17
|
+
const OUTPUT_FIELDS = ["skills", "file", "effort"];
|
|
18
|
+
const OVERRIDE_FIELDS = ["skills"];
|
|
19
|
+
const issue = (field, reason, message, fix) => ({ field, reason, message, ...(fix ? { fix } : {}) });
|
|
20
|
+
/** `key` under `at`; at the top of a pack with no `at`, the key alone. */
|
|
21
|
+
const under = (at, key) => (at ? `${at}.${key}` : key);
|
|
22
|
+
/** `value`'s own property `key`, never one it inherits (an output type may be named `constructor`). */
|
|
23
|
+
const own = (value, key) => (Object.hasOwn(value, key) ? value[key] : undefined);
|
|
24
|
+
/** Each key of `value` not in `fields` refused. */
|
|
25
|
+
function onlyFields(value, fields, at, out) {
|
|
26
|
+
for (const key of Object.keys(value)) {
|
|
27
|
+
if (!fields.includes(key))
|
|
28
|
+
out.push(issue(under(at, key), "not_allowed", `${at || "the pack"} keeps no field ${key}: it keeps ${fields.join(", ")}`, `Remove ${under(at, key)}.`));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/** A list of skill names: each one PACK_SKILL takes, none twice, at most MAX_PACK_SKILLS. Over the limit, the first
|
|
32
|
+
* MAX_PACK_SKILLS are still checked and the rest are not. */
|
|
33
|
+
function skillList(value, at, out) {
|
|
34
|
+
if (value === undefined)
|
|
35
|
+
return void out.push(issue(at, "missing", `${at} is required`));
|
|
36
|
+
if (!Array.isArray(value))
|
|
37
|
+
return void out.push(issue(at, "wrong_type", `${at} is not a list of skill names`));
|
|
38
|
+
if (value.length > MAX_PACK_SKILLS)
|
|
39
|
+
out.push(issue(at, "too_many", `${at} names ${value.length} skills, more than ${MAX_PACK_SKILLS}`));
|
|
40
|
+
const seen = new Set();
|
|
41
|
+
value.slice(0, MAX_PACK_SKILLS).forEach((name, i) => {
|
|
42
|
+
const field = `${at}[${i}]`;
|
|
43
|
+
if (typeof name !== "string")
|
|
44
|
+
out.push(issue(field, "wrong_type", `${field} is not a skill name`));
|
|
45
|
+
else if (!PACK_SKILL.test(name))
|
|
46
|
+
out.push(issue(field, "bad_format", `${field} is not a skill name: ${JSON.stringify(name)} must match ${PACK_SKILL.source}`));
|
|
47
|
+
else if (seen.has(name))
|
|
48
|
+
out.push(issue(field, "duplicate", `${field} names ${name} again`, `Remove ${field}.`));
|
|
49
|
+
else
|
|
50
|
+
seen.add(name);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/** An object with `skills` and only `fields`, or undefined after its issue. */
|
|
54
|
+
function skillsRow(value, fields, at, out) {
|
|
55
|
+
if (value === undefined)
|
|
56
|
+
return void out.push(issue(at, "missing", `${at} is required`));
|
|
57
|
+
if (!isObject(value))
|
|
58
|
+
return void out.push(issue(at, "wrong_type", `${at} is not an object`));
|
|
59
|
+
onlyFields(value, fields, at, out);
|
|
60
|
+
skillList(value.skills, under(at, "skills"), out);
|
|
61
|
+
return value;
|
|
62
|
+
}
|
|
63
|
+
/** An object keyed by effort, each row checked by `row`; `every` asks for all three. */
|
|
64
|
+
function byEffort(value, at, every, out, row) {
|
|
65
|
+
if (value === undefined)
|
|
66
|
+
return void out.push(issue(at, "missing", `${at} is required`));
|
|
67
|
+
if (!isObject(value))
|
|
68
|
+
return void out.push(issue(at, "wrong_type", `${at} is not an object of efforts`));
|
|
69
|
+
for (const key of Object.keys(value)) {
|
|
70
|
+
if (!EFFORTS.includes(key))
|
|
71
|
+
out.push(issue(under(at, key), "not_allowed", `${key} is not an effort: an effort is one of ${EFFORTS.join(", ")}`, `Remove ${under(at, key)}.`));
|
|
72
|
+
}
|
|
73
|
+
for (const effort of EFFORTS)
|
|
74
|
+
if (every || Object.hasOwn(value, effort))
|
|
75
|
+
row(own(value, effort), under(at, effort));
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* A file a run writes in its workspace, as the run's file route reads it back: relative, `/` between segments, no
|
|
79
|
+
* segment empty or starting with `.` (`.`, `..` and dot-named entries are the run's own), no backslash or NUL.
|
|
80
|
+
*/
|
|
81
|
+
function fileIssue(file, at, out) {
|
|
82
|
+
if (typeof file !== "string")
|
|
83
|
+
out.push(issue(at, "wrong_type", `${at} is not a path`));
|
|
84
|
+
else if (file.length > MAX_OUTPUT_FILE)
|
|
85
|
+
out.push(issue(at, "too_long", `${at} is longer than ${MAX_OUTPUT_FILE} characters`));
|
|
86
|
+
else if (file.includes("\\") || file.includes("\0") || file.split("/").some((part) => part === "" || part.startsWith("."))) {
|
|
87
|
+
out.push(issue(at, "bad_format", `${at} is not a plain relative path in the run's workspace: no leading /, no empty segment, none starting with ., no backslash or NUL`));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Every issue with `value` as a version 1 pack, none if it is one. Fields are paths into the pack
|
|
92
|
+
* (`effort.low.skills[0]`), under `at` when given (`profile.effort.low.skills[0]`); the pack itself is `at`. A skill
|
|
93
|
+
* list or `outputs` over its limit is `too_many`, and its items up to the limit are checked as any others; items past
|
|
94
|
+
* the limit are not checked, so an oversized pack makes a bounded number of issues.
|
|
95
|
+
*/
|
|
96
|
+
export function packIssues(value, { at = "" } = {}) {
|
|
97
|
+
if (!isObject(value))
|
|
98
|
+
return [issue(at, value === undefined ? "missing" : "wrong_type", `${at || "the pack"} is not an object`)];
|
|
99
|
+
const out = [];
|
|
100
|
+
onlyFields(value, PACK_FIELDS, at, out);
|
|
101
|
+
const version = under(at, "version");
|
|
102
|
+
if (value.version === undefined)
|
|
103
|
+
out.push(issue(version, "missing", `${version} is required`));
|
|
104
|
+
else if (typeof value.version !== "number")
|
|
105
|
+
out.push(issue(version, "wrong_type", `${version} is not a number`));
|
|
106
|
+
else if (value.version !== 1)
|
|
107
|
+
out.push(issue(version, "not_an_option", `${version} is 1: this server reads version 1 packs`));
|
|
108
|
+
const name = under(at, "name");
|
|
109
|
+
if (value.name === undefined)
|
|
110
|
+
out.push(issue(name, "missing", `${name} is required`));
|
|
111
|
+
else if (typeof value.name !== "string")
|
|
112
|
+
out.push(issue(name, "wrong_type", `${name} is not a string`));
|
|
113
|
+
else if (!PACK_NAME.test(value.name))
|
|
114
|
+
out.push(issue(name, "bad_format", `${name} must match ${PACK_NAME.source}`));
|
|
115
|
+
byEffort(value.effort, under(at, "effort"), true, out, (row, field) => {
|
|
116
|
+
const checked = skillsRow(row, EFFORT_FIELDS, field, out);
|
|
117
|
+
if (checked?.thinking !== undefined && !THINKING_LEVELS.includes(checked.thinking)) {
|
|
118
|
+
out.push(issue(under(field, "thinking"), "not_an_option", `${under(field, "thinking")} is one of ${THINKING_LEVELS.join(", ")}: thinking is never off`));
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
const outputs = under(at, "outputs");
|
|
122
|
+
if (value.outputs === undefined)
|
|
123
|
+
out.push(issue(outputs, "missing", `${outputs} is required`));
|
|
124
|
+
else if (!isObject(value.outputs))
|
|
125
|
+
out.push(issue(outputs, "wrong_type", `${outputs} is not an object of output types`));
|
|
126
|
+
else {
|
|
127
|
+
const entries = Object.entries(value.outputs);
|
|
128
|
+
if (entries.length > MAX_PACK_OUTPUTS)
|
|
129
|
+
out.push(issue(outputs, "too_many", `${outputs} names ${entries.length} output types, more than ${MAX_PACK_OUTPUTS}`));
|
|
130
|
+
for (const [type, output] of entries.slice(0, MAX_PACK_OUTPUTS)) {
|
|
131
|
+
const field = under(outputs, type);
|
|
132
|
+
if (!OUTPUT_TYPE.test(type))
|
|
133
|
+
out.push(issue(field, "bad_format", `the output type ${JSON.stringify(type)} must match ${OUTPUT_TYPE.source}`));
|
|
134
|
+
const checked = skillsRow(output, OUTPUT_FIELDS, field, out);
|
|
135
|
+
if (checked?.file !== undefined)
|
|
136
|
+
fileIssue(checked.file, under(field, "file"), out);
|
|
137
|
+
if (checked?.effort !== undefined)
|
|
138
|
+
byEffort(checked.effort, under(field, "effort"), false, out, (row, place) => void skillsRow(row, OVERRIDE_FIELDS, place, out));
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
const fallback = under(at, "default_output");
|
|
142
|
+
if (value.default_output !== undefined) {
|
|
143
|
+
if (typeof value.default_output !== "string")
|
|
144
|
+
out.push(issue(fallback, "wrong_type", `${fallback} is not an output type`));
|
|
145
|
+
else if (isObject(value.outputs) && !Object.hasOwn(value.outputs, value.default_output)) {
|
|
146
|
+
const types = Object.keys(value.outputs);
|
|
147
|
+
out.push(issue(fallback, "not_an_option", `${fallback} is one of the pack's output types: ${types.length ? types.join(", ") : "it names none"}`, `Name a key of ${outputs}, or remove ${fallback}.`));
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return out;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* `pack` (one packIssues finds nothing wrong with) read for a run at `effort` asked for `output`: the effort row's
|
|
154
|
+
* skills, then the output's writer skills (its skills at that effort if it names some there, else its own), each skill
|
|
155
|
+
* once at its first place. With no output asked, the pack's default_output; with neither, no output and no writer.
|
|
156
|
+
* `thinking` is there only when the effort row sets one, so the caller keeps its own level otherwise. An effort that is
|
|
157
|
+
* not one, or an output type the pack does not name, is an issue on `effort` or `output`.
|
|
158
|
+
*/
|
|
159
|
+
export function resolvePack(pack, { effort = "medium", output } = {}) {
|
|
160
|
+
const issues = [];
|
|
161
|
+
if (!EFFORTS.includes(effort))
|
|
162
|
+
issues.push(issue("effort", "not_an_option", `effort is one of ${EFFORTS.join(", ")}`));
|
|
163
|
+
if (output !== undefined && (typeof output !== "string" || !Object.hasOwn(pack.outputs, output))) {
|
|
164
|
+
const types = Object.keys(pack.outputs);
|
|
165
|
+
const options = types.length ? `the pack ${pack.name} names ${types.join(", ")}` : `the pack ${pack.name} names no output type`;
|
|
166
|
+
issues.push(issue("output", typeof output === "string" ? "not_an_option" : "wrong_type", `output is an output type of the pack: ${options}`));
|
|
167
|
+
}
|
|
168
|
+
if (issues.length)
|
|
169
|
+
return { issues };
|
|
170
|
+
const row = pack.effort[effort];
|
|
171
|
+
const type = output ?? pack.default_output;
|
|
172
|
+
const writer = type === undefined ? undefined : pack.outputs[type];
|
|
173
|
+
const writers = writer ? (writer.effort?.[effort]?.skills ?? writer.skills) : [];
|
|
174
|
+
return {
|
|
175
|
+
effort,
|
|
176
|
+
...(row.thinking !== undefined ? { thinking: row.thinking } : {}),
|
|
177
|
+
skills: [...new Set([...row.skills, ...writers])],
|
|
178
|
+
...(type !== undefined && writer ? { output: { type, ...(writer.file !== undefined ? { file: writer.file } : {}) } } : {}),
|
|
179
|
+
};
|
|
180
|
+
}
|
package/dist/page.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
2
|
+
import type { Owner } from "./owner.js";
|
|
3
|
+
export declare const overHttps: (req: IncomingMessage) => boolean;
|
|
4
|
+
export declare const ownOrigin: (req: IncomingMessage) => string;
|
|
5
|
+
export declare const isJson: (req: IncomingMessage) => boolean;
|
|
6
|
+
/** The owner's session cookie: `__Host-` on https, so no other host or path can set it; else one per port. */
|
|
7
|
+
export declare const ownerCookieName: (req: IncomingMessage) => string;
|
|
8
|
+
/** A Set-Cookie line for the owner's session: `value`, or an empty one that ends it (`maxAgeS` 0). */
|
|
9
|
+
export declare const ownerCookie: (req: IncomingMessage, value: string, maxAgeS: number) => string;
|
|
10
|
+
/** Whether the request holds a session the owner signed in. */
|
|
11
|
+
export declare const signedIn: (req: IncomingMessage, owner: Owner) => boolean;
|
|
12
|
+
/** `takesBytes`: whether a request of `method` to `path` (under /v2) goes to a route whose body is bytes (server.ts). */
|
|
13
|
+
type PageServer = {
|
|
14
|
+
token: string;
|
|
15
|
+
dir: string;
|
|
16
|
+
authFailed?: (route: string, reason: string) => void;
|
|
17
|
+
owner?: Owner;
|
|
18
|
+
console?: string | undefined;
|
|
19
|
+
takesBytes?: (method: string | undefined, path: string) => boolean;
|
|
20
|
+
};
|
|
21
|
+
/** Whether `req` came from the owner's page under their password session (answerPage). A token, whoever holds it, never
|
|
22
|
+
* did. */
|
|
23
|
+
export declare const byOwnerSession: (req: IncomingMessage) => boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Answers the console's paths ("/" and its /assets/*, and the addresses that moved to "/") and the store's /api/*, and
|
|
26
|
+
* returns true; returns false for every other path. On a /v2 path with no Authorization header, the browser's cookie
|
|
27
|
+
* becomes the Bearer header for a GET or HEAD, and for any other method only when the request's Origin is this server's
|
|
28
|
+
* own origin and its body is application/json, or the request is a PUT or POST to a route that takes bytes, with any
|
|
29
|
+
* content type.
|
|
30
|
+
*/
|
|
31
|
+
export declare function answerPage(req: IncomingMessage, res: ServerResponse, raw: string, server: PageServer): boolean;
|
|
32
|
+
export {};
|