mirror of
https://github.com/profullstack/logicsrc.git
synced 2026-11-30 17:07:50 +00:00
* OpenErrand 0.1: an errand on a website with no API, with the human steps kept human docs/openerrand.md mints OpenErrand: one JSON file per errand (register an account, download a transcript) naming the site, the inputs with a sensitivity class and ordered sources (document, vault, prompt, generate, derive, candidate, literal), field rules matched by id then label, page and wait steps, five human gates a runner never performs (declare, identity-proofing, code, mail, captcha), outcomes, the never-retried shared secret, vault and download outputs, hand-off cards that may name only public inputs, the publisher index at /.well-known/openerrand.json, and thirteen runner rules. The worked example is the MyFTB business registration that cli-tools `ftb` performs (profullstack/cli-tools#125), with no personal data. - @logicsrc/schemas: openerrand + openerrand-index schemas and fixtures - @logicsrc/validators: semantic checks (references, templates, no personal or secret input on a card) and tests that validate the spec's own examples - logicsrc-web: registry entry (process family), /openerrand landing page, the example and the index served as static files, contract tests Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * OpenErrand: hand-off cards stay on the surface that owns the data Anthony's ruling: tax and finance data never touches a social or promotion tool, and nothing is sent to a CPA or preparer. - Hand-off cards are delivered only on the surface that owns the errand's data (for a tax or finance errand, the principal's finance app through its CLI, PWA, MCP server or API, such as CoinPay, or the runner's terminal), never a social, promotion or third-party posting service, and never to anyone but the principal. A card for an errand with personal or secret inputs does not leave that surface. Runner rule 9 says the same. - The run record and the sample run name the card by an opaque id (pin-letter/7f3k2q) instead of a mynaposter.com URL; the myna mention is gone. - `principal: represented` no longer cites a preparer with a power of attorney. - The FTB card's last step no longer suggests sending the PIN to someone else. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * OpenErrand: user-agent rule, captcha solver policy, reference runner note Anthony's answers on #227 ("go with your recommendations"): - Rule 11: a runner may run headless with a normal desktop browser user agent (dropping HeadlessChrome) and nothing more: no fingerprint spoofing beyond the UA string, no stealth plugins, no solving or evading a bot challenge. A challenge the browser completes itself is a wait step; any other is a captcha gate. - Captcha solvers: new site.sector and captcha step `solver` (forbidden by default | allowed). Never allowed on government, tax, financial, healthcare or identity-provider sites, nor on any errand with a declare or identity-proofing step or a secret input; elsewhere only when the file says so, with every use logged. The validator rejects `allowed` in the forbidden set or without a stated sector; six new tests. The FTB example states sector "tax". - Reference runner: @logicsrc/openerrand / `logicsrc errand run`, marked in progress; ftb stays the runner the example was taken from. - Name stays OpenErrand; family stays Agents and process. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
159 lines
7.6 KiB
TypeScript
159 lines
7.6 KiB
TypeScript
import type { ErrorObject } from "ajv";
|
|
|
|
// Called only after the JSON Schema has checked the shape. These are the
|
|
// OpenErrand rules that need sibling values: every reference resolves, every
|
|
// template names an input that exists, and nothing personal or secret can be
|
|
// rendered onto a hand-off card.
|
|
|
|
type Source = { from: string; input?: string };
|
|
type Input = { type: string; sensitivity: "public" | "personal" | "secret"; role?: string; sources: Source[] };
|
|
type Action = { text?: string; gate?: string; choose?: string; answer?: string };
|
|
type Rule = { do: Action };
|
|
type Step = { id: string; kind: string; rules?: Rule[]; handoff?: string; resume?: string; solver?: string };
|
|
type Errand = {
|
|
site: { sector?: string };
|
|
inputs?: Record<string, Input>;
|
|
rules?: Rule[];
|
|
steps: Step[];
|
|
outcomes: Array<{ name: string; then?: string }>;
|
|
outputs?: { vault?: { when?: string; keys: Record<string, string> }; downloads?: Array<{ to: string; when?: string }> };
|
|
handoffs?: Record<string, { title: string; steps: string[]; command?: string }>;
|
|
};
|
|
|
|
/** Step kinds a runner must hand to a person. */
|
|
export const GATE_KINDS = ["declare", "identity-proofing", "code", "mail", "captcha"] as const;
|
|
|
|
/** Sectors where a captcha solver is never allowed. */
|
|
export const NO_SOLVER_SECTORS = ["government", "tax", "financial", "healthcare", "identity-provider"] as const;
|
|
|
|
/** Names a hand-off card may use: none of them is a person's data. */
|
|
export const HANDOFF_BUILTINS = ["expires_on", "errand.title", "site.name"] as const;
|
|
|
|
const TEMPLATE = /\{\{\s*([a-z][a-z0-9_.]*)\s*\}\}/g;
|
|
|
|
export function templateNames(text: string): string[] {
|
|
return [...text.matchAll(TEMPLATE)].map((m) => m[1]!);
|
|
}
|
|
|
|
export function validateOpenErrandReferences(data: unknown): ErrorObject[] {
|
|
const errand = data as Errand;
|
|
const errors: ErrorObject[] = [];
|
|
function report(keyword: string, instancePath: string, message: string) {
|
|
errors.push({ keyword, instancePath, schemaPath: "#/openerrand-semantics", params: {}, message });
|
|
}
|
|
|
|
const inputs = errand.inputs ?? {};
|
|
const steps = new Map<string, Step>();
|
|
errand.steps.forEach((step, i) => {
|
|
if (steps.has(step.id)) report("uniqueStep", `/steps/${i}/id`, "duplicates an existing step id");
|
|
steps.set(step.id, step);
|
|
});
|
|
const outcomes = new Set<string>();
|
|
errand.outcomes.forEach((outcome, i) => {
|
|
if (outcomes.has(outcome.name)) report("uniqueOutcome", `/outcomes/${i}/name`, "duplicates an existing outcome name");
|
|
outcomes.add(outcome.name);
|
|
});
|
|
const handoffs = errand.handoffs ?? {};
|
|
|
|
for (const [name, input] of Object.entries(inputs)) {
|
|
const path = `/inputs/${name}`;
|
|
if (input.role === "shared-secret" && input.sensitivity !== "secret") {
|
|
report("sharedSecretSensitivity", `${path}/sensitivity`, "a shared secret is always sensitivity secret");
|
|
}
|
|
if (input.type === "qa-set" && input.sensitivity === "public") {
|
|
report("qaSetSensitivity", `${path}/sensitivity`, "security answers are never public");
|
|
}
|
|
input.sources.forEach((source, j) => {
|
|
if ((source.from === "derive" || source.from === "candidate") && (!source.input || !(source.input in inputs) || source.input === name)) {
|
|
report("inputReference", `${path}/sources/${j}/input`, "must name another input of this errand");
|
|
}
|
|
if (source.from === "candidate" && source.input && inputs[source.input]?.role !== "shared-secret") {
|
|
report("candidateReference", `${path}/sources/${j}/input`, "a candidate part comes from a shared-secret input");
|
|
}
|
|
});
|
|
}
|
|
|
|
function checkTemplate(text: string, path: string) {
|
|
for (const name of templateNames(text)) {
|
|
if (!(name in inputs)) report("templateReference", path, `{{${name}}} is not an input of this errand`);
|
|
}
|
|
}
|
|
|
|
function checkRules(rules: Rule[] | undefined, base: string) {
|
|
rules?.forEach((rule, i) => {
|
|
const path = `${base}/${i}/do`;
|
|
const action = rule.do;
|
|
if (action.text !== undefined) checkTemplate(action.text, `${path}/text`);
|
|
if (action.gate !== undefined) {
|
|
const target = steps.get(action.gate);
|
|
if (!target || !(GATE_KINDS as readonly string[]).includes(target.kind)) {
|
|
report("gateReference", `${path}/gate`, "must name a declare, identity-proofing, code, mail or captcha step");
|
|
}
|
|
}
|
|
for (const key of ["choose", "answer"] as const) {
|
|
const name = action[key];
|
|
if (name !== undefined && inputs[name]?.type !== "qa-set") {
|
|
report("qaSetReference", `${path}/${key}`, "must name a qa-set input");
|
|
}
|
|
}
|
|
});
|
|
}
|
|
checkRules(errand.rules, "/rules");
|
|
errand.steps.forEach((step, i) => checkRules(step.rules, `/steps/${i}/rules`));
|
|
|
|
errand.steps.forEach((step, i) => {
|
|
if (step.handoff !== undefined && !(step.handoff in handoffs)) {
|
|
report("handoffReference", `/steps/${i}/handoff`, "must name a hand-off card of this errand");
|
|
}
|
|
});
|
|
errand.outcomes.forEach((outcome, i) => {
|
|
if (outcome.then !== undefined && !steps.has(outcome.then)) {
|
|
report("stepReference", `/outcomes/${i}/then`, "must name a step of this errand");
|
|
}
|
|
});
|
|
|
|
const vault = errand.outputs?.vault;
|
|
if (vault) {
|
|
if (vault.when !== undefined && !outcomes.has(vault.when)) report("outcomeReference", "/outputs/vault/when", "must name an outcome");
|
|
for (const [key, value] of Object.entries(vault.keys)) checkTemplate(value, `/outputs/vault/keys/${key}`);
|
|
}
|
|
errand.outputs?.downloads?.forEach((download, i) => {
|
|
if (download.when !== undefined && !outcomes.has(download.when)) report("outcomeReference", `/outputs/downloads/${i}/when`, "must name an outcome");
|
|
checkTemplate(download.to, `/outputs/downloads/${i}/to`);
|
|
});
|
|
|
|
// A captcha solver is allowed only where nothing sensitive is at stake: a
|
|
// stated sector outside the forbidden set, no attestation, no identity
|
|
// proofing and no secret input.
|
|
const sensitive =
|
|
errand.steps.some((step) => step.kind === "declare" || step.kind === "identity-proofing") ||
|
|
Object.values(inputs).some((input) => input.sensitivity === "secret");
|
|
const sector = errand.site?.sector;
|
|
errand.steps.forEach((step, i) => {
|
|
if (step.kind !== "captcha" || step.solver !== "allowed") return;
|
|
const path = `/steps/${i}/solver`;
|
|
if (!sector) report("captchaSolver", path, "an errand that allows a captcha solver states its site.sector");
|
|
else if ((NO_SOLVER_SECTORS as readonly string[]).includes(sector)) report("captchaSolver", path, `a captcha solver is never allowed on a ${sector} site`);
|
|
if (sensitive) report("captchaSolver", path, "a captcha solver is never allowed on an errand with a declare or identity-proofing step or a secret input");
|
|
});
|
|
|
|
// A hand-off card is shared on purpose: it may name built-ins and public
|
|
// inputs, and nothing a person would not post on a fridge.
|
|
for (const [id, card] of Object.entries(handoffs)) {
|
|
const texts: Array<[string, string]> = [
|
|
[`/handoffs/${id}/title`, card.title],
|
|
...card.steps.map((step, i): [string, string] => [`/handoffs/${id}/steps/${i}`, step]),
|
|
...(card.command !== undefined ? [[`/handoffs/${id}/command`, card.command] as [string, string]] : [])
|
|
];
|
|
for (const [path, text] of texts) {
|
|
for (const name of templateNames(text)) {
|
|
if ((HANDOFF_BUILTINS as readonly string[]).includes(name)) continue;
|
|
const input = inputs[name];
|
|
if (!input) report("templateReference", path, `{{${name}}} is not an input or a hand-off built-in`);
|
|
else if (input.sensitivity !== "public") report("handoffSensitivity", path, `{{${name}}} is ${input.sensitivity} and never goes on a hand-off card`);
|
|
}
|
|
}
|
|
}
|
|
|
|
return errors;
|
|
}
|