@parcha/agentrun-dsl 0.1.0-beta.1 → 0.1.0-beta.100

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.
Files changed (109) hide show
  1. package/NOTICE +2 -0
  2. package/README.md +173 -20
  3. package/dist/author-references.d.ts +8 -0
  4. package/dist/author-references.js +8 -0
  5. package/dist/author.d.ts +97 -0
  6. package/dist/author.js +329 -0
  7. package/dist/authoring.js +5 -4
  8. package/dist/cli.js +19 -13
  9. package/dist/code-exec.d.ts +6 -0
  10. package/dist/code-exec.js +126 -0
  11. package/dist/decision-provider.d.ts +166 -0
  12. package/dist/decision-provider.js +238 -0
  13. package/dist/decision-receipts.d.ts +159 -0
  14. package/dist/decision-receipts.js +93 -0
  15. package/dist/dry-run.d.ts +45 -2
  16. package/dist/dry-run.js +159 -27
  17. package/dist/evidence.d.ts +19 -0
  18. package/dist/evidence.js +63 -0
  19. package/dist/graph.d.ts +169 -0
  20. package/dist/graph.js +433 -0
  21. package/dist/index.d.ts +20 -6
  22. package/dist/index.js +19 -4
  23. package/dist/inspection.d.ts +5 -0
  24. package/dist/inspection.js +16 -3
  25. package/dist/job.d.ts +14 -0
  26. package/dist/job.js +5 -0
  27. package/dist/long-timer.d.ts +7 -0
  28. package/dist/long-timer.js +22 -0
  29. package/dist/observer-snapshot.d.ts +3 -0
  30. package/dist/observer-snapshot.js +46 -0
  31. package/dist/pattern-screen.d.ts +14 -0
  32. package/dist/pattern-screen.js +451 -0
  33. package/dist/predicates.d.ts +33 -0
  34. package/dist/predicates.js +81 -5
  35. package/dist/record.d.ts +4 -0
  36. package/dist/record.js +6 -0
  37. package/dist/recovery/binding.d.ts +10 -0
  38. package/dist/recovery/binding.js +44 -0
  39. package/dist/recovery/call-key.d.ts +9 -0
  40. package/dist/recovery/call-key.js +17 -0
  41. package/dist/recovery/canonical-hash.d.ts +7 -0
  42. package/dist/recovery/canonical-hash.js +22 -0
  43. package/dist/recovery/driver.d.ts +241 -0
  44. package/dist/recovery/driver.js +1333 -0
  45. package/dist/recovery/errors.d.ts +31 -0
  46. package/dist/recovery/errors.js +51 -0
  47. package/dist/recovery/execution-path.d.ts +53 -0
  48. package/dist/recovery/execution-path.js +167 -0
  49. package/dist/recovery/file-store.d.ts +7 -0
  50. package/dist/recovery/file-store.js +131 -0
  51. package/dist/recovery/frozen-snapshot.d.ts +274 -0
  52. package/dist/recovery/frozen-snapshot.js +187 -0
  53. package/dist/recovery/handoff-receipts.d.ts +7 -0
  54. package/dist/recovery/handoff-receipts.js +11 -0
  55. package/dist/recovery/index.d.ts +14 -0
  56. package/dist/recovery/index.js +13 -0
  57. package/dist/recovery/item-state.d.ts +48 -0
  58. package/dist/recovery/item-state.js +89 -0
  59. package/dist/recovery/journal.d.ts +28 -0
  60. package/dist/recovery/journal.js +139 -0
  61. package/dist/recovery/memory-store.d.ts +4 -0
  62. package/dist/recovery/memory-store.js +20 -0
  63. package/dist/recovery/store.d.ts +105 -0
  64. package/dist/recovery/store.js +6 -0
  65. package/dist/recovery/testing/conformance.d.ts +4 -0
  66. package/dist/recovery/testing/conformance.js +268 -0
  67. package/dist/recovery/testing/crash-points.d.ts +18 -0
  68. package/dist/recovery/testing/crash-points.js +43 -0
  69. package/dist/recovery/testing/crash-sweep.d.ts +65 -0
  70. package/dist/recovery/testing/crash-sweep.js +146 -0
  71. package/dist/recovery/testing/index.d.ts +3 -0
  72. package/dist/recovery/testing/index.js +4 -0
  73. package/dist/recovery/testing/preload.d.ts +1 -0
  74. package/dist/recovery/testing/preload.js +3 -0
  75. package/dist/recovery/transport-facts.d.ts +23 -0
  76. package/dist/recovery/transport-facts.js +46 -0
  77. package/dist/recovery/with-recovery.d.ts +50 -0
  78. package/dist/recovery/with-recovery.js +144 -0
  79. package/dist/submit-envelope.d.ts +9 -0
  80. package/dist/submit-envelope.js +44 -0
  81. package/dist/system-one.d.ts +37 -2
  82. package/dist/system-one.js +146 -11
  83. package/dist/testing/decision-provider.d.ts +32 -0
  84. package/dist/testing/decision-provider.js +183 -0
  85. package/dist/testing/index.d.ts +1 -0
  86. package/dist/testing/index.js +2 -0
  87. package/dist/vocabulary.d.ts +50 -0
  88. package/dist/vocabulary.js +84 -0
  89. package/dist/workflow-shape.d.ts +7 -0
  90. package/dist/workflow-shape.js +119 -69
  91. package/dist/workflow.d.ts +356 -29
  92. package/dist/workflow.js +1777 -487
  93. package/dist/zod-json-contract.js +6 -8
  94. package/package.json +29 -5
  95. package/schema/workflow.schema.json +599 -12
  96. package/skills/author/SKILL.md +125 -0
  97. package/skills/author/examples/evidence-gate.input.json +6 -0
  98. package/skills/author/examples/evidence-gate.json +125 -0
  99. package/skills/author/examples/read-file.input.json +1 -0
  100. package/skills/author/examples/read-file.json +44 -0
  101. package/skills/author/examples/read-source-decision.input.json +4 -0
  102. package/skills/author/examples/read-source-decision.json +37 -0
  103. package/skills/author/examples/release-note.txt +10 -0
  104. package/skills/author/examples/review-release-notes.input.json +6 -0
  105. package/skills/author/examples/review-release-notes.json +123 -0
  106. package/skills/author/references/jev-decisions.md +170 -0
  107. package/skills/author/references/language.md +123 -0
  108. package/skills/author/references/sdk-authoring.md +11 -0
  109. package/skills/author/references/workflow-format.md +137 -0
package/dist/index.d.ts CHANGED
@@ -1,14 +1,28 @@
1
1
  export { defineWorkflow, runTypedWorkflow, WorkflowSchemaConversionError } from "./authoring.js";
2
2
  export type { StandardJSONSchema, AuthoringSchema, TypedWorkflow, TypedWorkflowRunResult, WorkflowInput, WorkflowOutput, } from "./authoring.js";
3
- export { runWorkflow, validateWorkflow, workflowSha256, WorkflowInvalidError, WorkflowInputInvalidError, WorkflowOutputInvalidError, WorkflowCodeError, WorkflowStateError, WorkflowVerificationError, EffectFailure, EffectDeadlineExceededError, EffectOutcomeUnknownError, EscalationSignal, } from "./workflow.js";
4
- export type { Workflow, WorkflowNode, WorkflowDeps, WorkflowRunResult, Escalation, EffectSettlement, MapItem, LlmNode, JudgeNode, PickNode, SiftNode, RouteNode, WorkflowInvocation, ArtifactNode, ArtifactState, CallNode, CallRetryClass, CallPredicate, PollClause, ModelTier, WorkflowEffort, WorkflowThinking, VerifyClause, AskPredicate, MechanicalPredicate, Predicate, } from "./workflow.js";
5
- export { dryRunWorkflow, synthesizeInstance } from "./dry-run.js";
3
+ export { runWorkflow, validateWorkflow, workflowSha256, WorkflowInvalidError, WorkflowInputInvalidError, WorkflowOutputInvalidError, WorkflowCodeError, WorkflowStateError, WorkflowVerificationError, WorkflowDecisionRecordError, EffectFailure, EffectDeadlineExceededError, EffectOutcomeUnknownError, EscalationSignal, routesByValue, isItemFailure, MAP_LIMITS, } from "./workflow.js";
4
+ export { defineJob } from "./job.js";
5
+ export type { Job } from "./job.js";
6
+ export { DECISION_RECEIPT_VERSION, DECISION_INTERRUPTED, DECISION_REFUSED, DECISION_STATE_MAX_BYTES, rederiveDecision } from "./decision-receipts.js";
7
+ export type { DecisionImageDigest, DecisionKind, DecisionReceipt, DecisionRule, DecisionStateCut, DecisionStateSent } from "./decision-receipts.js";
8
+ export type { Workflow, WorkflowNode, NodeMetadata, WorkflowDeps, MapLimits, WorkflowEvent, WorkflowRunResult, HostPolicy, HostPolicyContext, Escalation, EffectSettlement, MapItem, MapItemFailure, DecisionExchange, LlmNode, JudgeNode, PickNode, SiftNode, RouteNode, RouteByJudgmentNode, RouteByValueNode, WorkflowInvocation, ArtifactNode, ArtifactState, CallNode, CodeNode, CallRetryClass, EffectFailureCode, CallPredicate, PollClause, ModelTier, AgentContext, WorkflowEffort, WorkflowThinking, VerifyClause, AskPredicate, DecisionEvidenceMode, DecisionImages, MechanicalPredicate, Predicate, ValidationCode, ValidationIssue, ValidateWorkflowOptions, } from "./workflow.js";
9
+ export { dryRunWorkflow, SYNTHESIS_BUDGET, SynthesisTooLarge, synthesizeInstance, type SynthesisBudget } from "./dry-run.js";
6
10
  export type { DryRunOptions, DryRunResult } from "./dry-run.js";
7
- export { compileQuestions, validateAnswers, answersToValue, answersSidecar, answerConfidence, synthesizeAnswers, SYSTEM_ONE_LIMITS, SystemOneError, isSystemOneResponseReason, } from "./system-one.js";
8
- export type { SystemOneQuestion, SystemOneAnswer, SystemOneResult, SystemOneRetryClass, SystemOneResponseReason, CompiledQuestions, AnswersSidecar, } from "./system-one.js";
11
+ export { compileQuestions, validateAnswers, answersToValue, answersSidecar, answerConfidence, synthesizeAnswers, SYSTEM_ONE_LIMITS, SystemOneError, isSystemOneResponseReason, deriveConfidence, completeConfidence, refusedQuestions, } from "./system-one.js";
12
+ export type { SystemOneQuestion, SystemOneAnswer, SystemOneBox, SystemOneResult, SystemOneRetryClass, SystemOneResponseReason, CompiledQuestions, AnswersSidecar, ConfidenceSource, } from "./system-one.js";
13
+ export { judgeFromProvider, judgeFromProviders, checkCapabilities, chargedCost, DecisionProviderError, imageDimensions } from "./decision-provider.js";
14
+ export { evidenceOf, EVIDENCE_EXCERPT_MAX, EVIDENCE_EXCERPTS_PER_ITEM, EVIDENCE_ITEMS_MAX, EVIDENCE_TEXT_MAX, EVIDENCE_TITLE_MAX, type EvidenceOptions } from "./evidence.js";
15
+ export type { DecisionProvider, DecisionCapabilities, DecisionInput, DecisionRequest, DecisionContext, DecisionEvidence, DecisionOutcome, ProviderAnswer, CostBasis, DecisionProviderErrorCode, DecisionImage, LoadImage, JudgeFromProviderOptions, } from "./decision-provider.js";
9
16
  export { inspectWorkflow, formatWorkflowTree } from "./inspection.js";
10
17
  export type { WorkflowInspection, WorkflowInspectionNode } from "./inspection.js";
11
- export { runWorkflowSlice, assertWorkflowCapabilities, desugarWorkflow, stageSchemaForNode, submissionSchemaForNode, mergeStageDelta, REPORT_SCHEMA, SHELL_RESULT_SCHEMA, } from "./workflow.js";
18
+ export { runWorkflowSlice, assertWorkflowCapabilities, desugarWorkflow, stageSchemaForNode, submissionSchemaForNode, mergeStageDelta, REPORT_SCHEMA, SHELL_RESULT_SCHEMA, childSteps, declaredWrites, artifactNodeIsProse, schemaProblems, HOST_STATE_KEY, normalizeStringNullsForSchema, placeholderValue, placeholdersOf, } from "./workflow.js";
19
+ export { compileTransform, compileTransformSyntax, deniedGlobalReferences } from "./code-exec.js";
12
20
  export { resolveSchemaForWorkflow } from "./schema-references.js";
21
+ export { patternRisk, PATTERN_SCREEN_LIMITS } from "./pattern-screen.js";
22
+ export { submitParameters } from "./submit-envelope.js";
13
23
  export { getPath, predicateMatches } from "./predicates.js";
14
24
  export type { StopPredicate, AcceptPredicate } from "./predicates.js";
25
+ export { authorContract, renderAuthorContract, renderAuthorHostAddendum, applyHostOutputTypes, authorWorkflow, authorSkillDirectory, loadAuthorReference, loadAuthorSkillBundle, } from "./author.js";
26
+ export type { AuthorHostAddendum, CandidatePolicyOptions, AuthorWorkflowOptions, AuthoredWorkflow, HostOutputTypeOptions } from "./author.js";
27
+ export { GENERATIVE_NODE_KINDS, JUDGMENT_NODE_KINDS, NODE_FIELDS, HOST_NODE_FIELDS, IGNORED_NODE_FIELDS, MECHANICAL_PREDICATES, WORKFLOW_PREDICATES, PREDICATE_FIELDS, FIELD_TYPES, EFFORT_LEVELS, THINKING_LEVELS, MODEL_TIERS, AGENT_CONTEXTS, CALL_TRANSPORTS, CALL_RETRY_CLASSES, EFFECT_FAILURE_CODES, PROSE_ARTIFACT_TYPES, } from "./vocabulary.js";
28
+ export type { WorkflowNodeKind, WorkflowPredicateName, FieldType } from "./vocabulary.js";
package/dist/index.js CHANGED
@@ -1,8 +1,23 @@
1
1
  export { defineWorkflow, runTypedWorkflow, WorkflowSchemaConversionError } from "./authoring.js";
2
- export { runWorkflow, validateWorkflow, workflowSha256, WorkflowInvalidError, WorkflowInputInvalidError, WorkflowOutputInvalidError, WorkflowCodeError, WorkflowStateError, WorkflowVerificationError, EffectFailure, EffectDeadlineExceededError, EffectOutcomeUnknownError, EscalationSignal, } from "./workflow.js";
3
- export { dryRunWorkflow, synthesizeInstance } from "./dry-run.js";
4
- export { compileQuestions, validateAnswers, answersToValue, answersSidecar, answerConfidence, synthesizeAnswers, SYSTEM_ONE_LIMITS, SystemOneError, isSystemOneResponseReason, } from "./system-one.js";
2
+ export { runWorkflow, validateWorkflow, workflowSha256, WorkflowInvalidError, WorkflowInputInvalidError, WorkflowOutputInvalidError, WorkflowCodeError, WorkflowStateError, WorkflowVerificationError, WorkflowDecisionRecordError, EffectFailure, EffectDeadlineExceededError, EffectOutcomeUnknownError, EscalationSignal, routesByValue, isItemFailure, MAP_LIMITS, } from "./workflow.js";
3
+ export { defineJob } from "./job.js";
4
+ export { DECISION_RECEIPT_VERSION, DECISION_INTERRUPTED, DECISION_REFUSED, DECISION_STATE_MAX_BYTES, rederiveDecision } from "./decision-receipts.js";
5
+ export { dryRunWorkflow, SYNTHESIS_BUDGET, SynthesisTooLarge, synthesizeInstance } from "./dry-run.js";
6
+ export { compileQuestions, validateAnswers, answersToValue, answersSidecar, answerConfidence, synthesizeAnswers, SYSTEM_ONE_LIMITS, SystemOneError, isSystemOneResponseReason, deriveConfidence, completeConfidence, refusedQuestions, } from "./system-one.js";
7
+ export { judgeFromProvider, judgeFromProviders, checkCapabilities, chargedCost, DecisionProviderError, imageDimensions } from "./decision-provider.js";
8
+ export { evidenceOf, EVIDENCE_EXCERPT_MAX, EVIDENCE_EXCERPTS_PER_ITEM, EVIDENCE_ITEMS_MAX, EVIDENCE_TEXT_MAX, EVIDENCE_TITLE_MAX } from "./evidence.js";
5
9
  export { inspectWorkflow, formatWorkflowTree } from "./inspection.js";
6
- export { runWorkflowSlice, assertWorkflowCapabilities, desugarWorkflow, stageSchemaForNode, submissionSchemaForNode, mergeStageDelta, REPORT_SCHEMA, SHELL_RESULT_SCHEMA, } from "./workflow.js";
10
+ export { runWorkflowSlice, assertWorkflowCapabilities, desugarWorkflow, stageSchemaForNode, submissionSchemaForNode, mergeStageDelta, REPORT_SCHEMA, SHELL_RESULT_SCHEMA,
11
+ // Document helpers a host facade needs to speak about a workflow without re-implementing the walk.
12
+ childSteps, declaredWrites, artifactNodeIsProse, schemaProblems, HOST_STATE_KEY,
13
+ // The host-side normalization the interpreter itself uses.
14
+ normalizeStringNullsForSchema,
15
+ // Interpolation's placeholders in a string and its lookup order for one, for a host check of what a step reads.
16
+ placeholderValue, placeholdersOf, } from "./workflow.js";
17
+ export { compileTransform, compileTransformSyntax, deniedGlobalReferences } from "./code-exec.js";
7
18
  export { resolveSchemaForWorkflow } from "./schema-references.js";
19
+ export { patternRisk, PATTERN_SCREEN_LIMITS } from "./pattern-screen.js";
20
+ export { submitParameters } from "./submit-envelope.js";
8
21
  export { getPath, predicateMatches } from "./predicates.js";
22
+ export { authorContract, renderAuthorContract, renderAuthorHostAddendum, applyHostOutputTypes, authorWorkflow, authorSkillDirectory, loadAuthorReference, loadAuthorSkillBundle, } from "./author.js";
23
+ export { GENERATIVE_NODE_KINDS, JUDGMENT_NODE_KINDS, NODE_FIELDS, HOST_NODE_FIELDS, IGNORED_NODE_FIELDS, MECHANICAL_PREDICATES, WORKFLOW_PREDICATES, PREDICATE_FIELDS, FIELD_TYPES, EFFORT_LEVELS, THINKING_LEVELS, MODEL_TIERS, AGENT_CONTEXTS, CALL_TRANSPORTS, CALL_RETRY_CLASSES, EFFECT_FAILURE_CODES, PROSE_ARTIFACT_TYPES, } from "./vocabulary.js";
@@ -11,6 +11,11 @@ export type WorkflowInspectionNode = {
11
11
  /** Effective selection from completed map-item state; absent means whole item state. */
12
12
  resultPath?: string;
13
13
  childWorkflow?: string;
14
+ /** A decision node's (or an `ask` predicate's) provider and pinned model, when it names them, and the tokens of the
15
+ * images it sends. */
16
+ provider?: string;
17
+ model?: string;
18
+ images?: string[];
14
19
  };
15
20
  export type WorkflowInspection = {
16
21
  name: string;
@@ -1,5 +1,17 @@
1
- import { workflowDocumentError, workflowSha256 } from "./workflow.js";
1
+ import { routesByValue, workflowDocumentError, workflowSha256 } from "./workflow.js";
2
2
  import { workflowShapeErrors } from "./workflow-shape.js";
3
+ /** What a decision node, or a loop's or escalate's `ask` predicate, names of its provider, model and images. */
4
+ function decisionFields(node) {
5
+ const source = node.node === "loop" ? node.until : node.node === "escalate" ? node.when
6
+ : ["judge", "pick", "sift"].includes(node.node) || node.node === "route" && !routesByValue(node) ? node : undefined;
7
+ if (!source || ((node.node === "loop" || node.node === "escalate") && source.predicate !== "ask"))
8
+ return {};
9
+ const { provider, model, images } = source;
10
+ return {
11
+ ...(typeof provider === "string" ? { provider } : {}), ...(typeof model === "string" ? { model } : {}),
12
+ ...(images && typeof images === "object" && Object.keys(images).length ? { images: Object.keys(images) } : {}),
13
+ };
14
+ }
3
15
  const pointer = (part) => part.replace(/~/g, "~0").replace(/\//g, "~1");
4
16
  /** Inspect a workflow's structure without running authored code, adapters, or schema probes.
5
17
  * The input must be plain JSON data. This is a review aid, not execution admission: use
@@ -26,11 +38,12 @@ export function inspectWorkflow(value) {
26
38
  ...("out" in node && node.out && node.node !== "sift" ? { outputSchema: node.out } : {}),
27
39
  ...(node.node === "map" && (node.resultPath || "as" in node.body && node.body.as)
28
40
  ? { resultPath: node.resultPath || node.body.as } : {}),
29
- ...(node.node === "workflow" ? { childWorkflow: node.workflow.name } : {}), });
41
+ ...(node.node === "workflow" ? { childWorkflow: node.workflow.name } : {}),
42
+ ...decisionFields(node), });
30
43
  if (["agent", "decide", "extract", "report"].includes(node.node) ||
31
44
  node.node === "artifact" && ["markdown", "report"].includes(node.type))
32
45
  adapters.add("runNode");
33
- if (["judge", "pick", "sift", "route"].includes(node.node) ||
46
+ if (["judge", "pick", "sift"].includes(node.node) || node.node === "route" && !routesByValue(node) ||
34
47
  "verify" in node && node.verify || node.node === "loop" && node.until.predicate === "ask" ||
35
48
  node.node === "escalate" && node.when.predicate === "ask")
36
49
  adapters.add("runJudge");
package/dist/job.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ import type { Workflow } from "./workflow.js";
2
+ /** A unit of work a host runs: the workflow, the input it runs on, and the files it starts with (by path, as bytes). */
3
+ export type Job = {
4
+ workflow: Workflow;
5
+ input: Record<string, unknown>;
6
+ files?: Record<string, Uint8Array>;
7
+ };
8
+ /** Returns `job` itself. It checks the job's shape and keeps the workflow's literal type, so a job written beside a workflow
9
+ * declared `as const satisfies Workflow` still names the workflow's literal values. */
10
+ export declare function defineJob<const W extends Workflow>(job: {
11
+ workflow: W;
12
+ input: Record<string, unknown>;
13
+ files?: Record<string, Uint8Array>;
14
+ }): typeof job;
package/dist/job.js ADDED
@@ -0,0 +1,5 @@
1
+ /** Returns `job` itself. It checks the job's shape and keeps the workflow's literal type, so a job written beside a workflow
2
+ * declared `as const satisfies Workflow` still names the workflow's literal values. */
3
+ export function defineJob(job) {
4
+ return job;
5
+ }
@@ -0,0 +1,7 @@
1
+ export declare const MAX_TIMER_DELAY_MS: number;
2
+ export type LongTimer = {
3
+ clear(): void;
4
+ };
5
+ /** Schedule `fn` after `ms`, re-arming in <= MAX_TIMER_DELAY_MS chunks so a delay past Node's timer
6
+ * limit still fires on time instead of overflowing. `clear()` cancels the pending chunk. */
7
+ export declare function setLongTimeout(fn: () => void, ms: number): LongTimer;
@@ -0,0 +1,22 @@
1
+ // Node's timers accept a delay of at most 2^31-1 ms (~24.8 days); a larger delay silently overflows
2
+ // to a near-immediate fire with a TimeoutOverflowWarning. A workflow's deadline_s, poll.deadline_s,
3
+ // poll.interval_s and retry.backoff_s carry no upper ceiling, so a delay derived from them can exceed
4
+ // that. `setLongTimeout` re-arms in <= MAX_TIMER_DELAY_MS chunks, so the callback fires at the
5
+ // intended time however far out it is, and returns a handle that clears whichever chunk is pending.
6
+ export const MAX_TIMER_DELAY_MS = 2 ** 31 - 1;
7
+ /** Schedule `fn` after `ms`, re-arming in <= MAX_TIMER_DELAY_MS chunks so a delay past Node's timer
8
+ * limit still fires on time instead of overflowing. `clear()` cancels the pending chunk. */
9
+ export function setLongTimeout(fn, ms) {
10
+ let remaining = Number.isFinite(ms) ? Math.max(0, ms) : MAX_TIMER_DELAY_MS;
11
+ let handle;
12
+ const tick = () => {
13
+ if (remaining <= MAX_TIMER_DELAY_MS) {
14
+ handle = setTimeout(fn, remaining);
15
+ return;
16
+ }
17
+ remaining -= MAX_TIMER_DELAY_MS;
18
+ handle = setTimeout(tick, MAX_TIMER_DELAY_MS);
19
+ };
20
+ tick();
21
+ return { clear() { clearTimeout(handle); } };
22
+ }
@@ -0,0 +1,3 @@
1
+ /** Copy observation data without reading accessors or sharing mutable data objects.
2
+ * Keep invalid JSON shapes visible so required host trace validation can reject them. */
3
+ export declare function observerSnapshot<T>(value: T): T;
@@ -0,0 +1,46 @@
1
+ import { isProxy } from "node:util/types";
2
+ /** Copy observation data without reading accessors or sharing mutable data objects.
3
+ * Keep invalid JSON shapes visible so required host trace validation can reject them. */
4
+ export function observerSnapshot(value) {
5
+ const seen = new Map();
6
+ const pending = [];
7
+ const copy = (item) => {
8
+ // A proxy can execute code even when its property descriptors are inspected.
9
+ if (isProxy(item))
10
+ return function unavailable() { };
11
+ if (item === null || typeof item !== "object") {
12
+ // Functions are invalid observation data; an inert function preserves that
13
+ // fact without giving an observer the original callable or its properties.
14
+ return typeof item === "function" ? function unavailable() { } : item;
15
+ }
16
+ const known = seen.get(item);
17
+ if (known)
18
+ return known;
19
+ const prototype = Object.getPrototypeOf(item);
20
+ if (prototype !== Object.prototype && prototype !== Array.prototype && prototype !== null)
21
+ return function unavailable() { };
22
+ const target = Array.isArray(item) ? [] : Object.create(prototype);
23
+ seen.set(item, target);
24
+ pending.push([item, target]);
25
+ return target;
26
+ };
27
+ const result = copy(value);
28
+ while (pending.length) {
29
+ const [source, target] = pending.pop();
30
+ for (const key of Reflect.ownKeys(source)) {
31
+ const descriptor = Object.getOwnPropertyDescriptor(source, key);
32
+ if ("value" in descriptor)
33
+ descriptor.value = copy(descriptor.value);
34
+ else {
35
+ // Never invoke authored getters, including during cloning. Their shape
36
+ // remains an accessor so a JSON-validating host still fails closed.
37
+ if (descriptor.get)
38
+ descriptor.get = () => undefined;
39
+ if (descriptor.set)
40
+ descriptor.set = () => { };
41
+ }
42
+ Object.defineProperty(target, key, descriptor);
43
+ }
44
+ }
45
+ return result;
46
+ }
@@ -0,0 +1,14 @@
1
+ /** The longest pattern read (characters), and the most quantifiers in one: a schema pattern is a few dozen of each. */
2
+ export declare const PATTERN_SCREEN_LIMITS: {
3
+ readonly chars: 4096;
4
+ readonly quantifiers: 128;
5
+ };
6
+ /** Why `pattern` may backtrack exponentially (or could not be read), or undefined when it is safe to test strings
7
+ * against. */
8
+ export declare function patternRisk(pattern: string): string | undefined;
9
+ /** Each pattern `schema` would test strings with (a `pattern`, a `patternProperties` key) that may backtrack
10
+ * exponentially, with why. */
11
+ export declare function riskyPatterns(schema: unknown): {
12
+ pattern: string;
13
+ why: string;
14
+ }[];