archal 0.9.19 → 0.10.0

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 (83) hide show
  1. package/README.md +62 -154
  2. package/agents/openclaw/.archal.json +8 -0
  3. package/agents/openclaw/Dockerfile +97 -0
  4. package/agents/openclaw/README.md +113 -0
  5. package/agents/openclaw/drive.mjs +301 -0
  6. package/agents/openclaw/extract-openclaw-response-text.mjs +49 -0
  7. package/agents/openclaw/package.json +9 -0
  8. package/agents/openclaw/scenarios/acceptance/github-escalation-and-cleanup.md +43 -0
  9. package/agents/openclaw/scenarios/acceptance/jira-linear-release-triage.md +39 -0
  10. package/agents/openclaw/scenarios/acceptance/multi-clone-customer-risk-review.md +45 -0
  11. package/agents/openclaw/scenarios/acceptance/slack-incident-handoff.md +42 -0
  12. package/agents/openclaw/scenarios/acceptance/stripe-dunning-remediation.md +40 -0
  13. package/agents/openclaw/scenarios/close-stale-issues.md +35 -0
  14. package/agents/openclaw/scenarios/github-issue-triage-read-only.md +44 -0
  15. package/agents/openclaw/workspace/AGENTS.md +23 -0
  16. package/agents/openclaw/workspace/IDENTITY.md +8 -0
  17. package/agents/openclaw/workspace/SOUL.md +14 -0
  18. package/agents/openclaw/workspace/TOOLS.md +54 -0
  19. package/clone-assets/apify/tools.json +256 -22
  20. package/clone-assets/calcom/tools.json +2062 -0
  21. package/clone-assets/clickup/tools.json +3245 -0
  22. package/clone-assets/customerio/tools.json +2350 -0
  23. package/clone-assets/datadog/tools.json +734 -0
  24. package/clone-assets/github/tools.json +307 -27
  25. package/clone-assets/gitlab/tools.json +10688 -0
  26. package/clone-assets/google-workspace/tools.json +18 -6
  27. package/clone-assets/hubspot/tools.json +1604 -0
  28. package/clone-assets/jira/fidelity.json +1 -1
  29. package/clone-assets/jira/tools.json +266 -543
  30. package/clone-assets/linear/tools.json +278 -40
  31. package/clone-assets/ownerrez/tools.json +548 -0
  32. package/clone-assets/pricelabs/tools.json +343 -0
  33. package/clone-assets/sentry/tools.json +2821 -0
  34. package/clone-assets/slack/tools.json +1 -2
  35. package/clone-assets/stripe/tools.json +299 -46
  36. package/clone-assets/supabase/tools.json +437 -0
  37. package/clone-assets/unipile/tools.json +408 -0
  38. package/clone-assets/webflow/tools.json +2185 -0
  39. package/dist/autoloop-worker-types-CHaclqtD.d.cts +160 -0
  40. package/dist/cli.cjs +127896 -84811
  41. package/dist/{vitest/chunk-L36NXAU6.js → commands/autoloop-hosted-control-plane-client.cjs} +16344 -18845
  42. package/dist/commands/autoloop-hosted-control-plane-client.d.cts +133 -0
  43. package/dist/commands/autoloop-pr-verification.cjs +4312 -0
  44. package/dist/commands/autoloop-pr-verification.d.cts +19 -0
  45. package/dist/commands/autoloop-result-parser.cjs +27058 -0
  46. package/dist/commands/autoloop-result-parser.d.cts +196 -0
  47. package/dist/commands/autoloop-worker.cjs +38488 -0
  48. package/dist/commands/autoloop-worker.d.cts +102 -0
  49. package/dist/eval-shim.mjs +216 -0
  50. package/dist/index.cjs +15 -2
  51. package/dist/index.d.cts +3 -1
  52. package/dist/layer-1-ziaLpfLr.d.cts +62 -0
  53. package/dist/metafile-cjs.json +1 -0
  54. package/dist/reporter-entry.js +3 -0
  55. package/dist/sdk/index.cjs +51630 -0
  56. package/dist/sdk/index.d.cts +626 -0
  57. package/dist/vitest/chunk-2PDHTPZC.js +4867 -0
  58. package/dist/vitest/chunk-7L4BBB6M.js +2613 -0
  59. package/dist/vitest/index.cjs +6152 -75718
  60. package/dist/vitest/index.d.ts +22 -86
  61. package/dist/vitest/index.js +45 -414
  62. package/dist/vitest/runtime/hosted-session-reaper.cjs +682 -34399
  63. package/dist/vitest/runtime/hosted-session-reaper.js +1 -1
  64. package/dist/vitest/runtime/setup-files.js +2 -2
  65. package/manifest.json +9 -0
  66. package/package.json +20 -14
  67. package/skills/archal-agent/SKILL.md +86 -0
  68. package/skills/autoloop/SKILL.md +391 -0
  69. package/skills/autoloop/references/hosted-sources.md +94 -0
  70. package/skills/autoloop/references/trace-schema-mapping.md +104 -0
  71. package/skills/eval/SKILL.md +17 -15
  72. package/skills/free-account/SKILL.md +103 -0
  73. package/skills/install-agent/SKILL.md +202 -0
  74. package/skills/onboard/SKILL.md +29 -18
  75. package/skills/scenario/SKILL.md +36 -18
  76. package/skills/seed/SKILL.md +238 -0
  77. package/skills/vitest/SKILL.md +3 -2
  78. package/dist/harness.cjs +0 -62
  79. package/dist/harness.d.cts +0 -20
  80. package/dist/seed/dynamic-generator.cjs +0 -45687
  81. package/dist/seed/dynamic-generator.d.cts +0 -106
  82. package/dist/vitest/chunk-WZ7SA4CK.js +0 -47369
  83. package/skills/attach/SKILL.md +0 -402
@@ -0,0 +1,626 @@
1
+ interface FieldChange {
2
+ field: string;
3
+ before: unknown;
4
+ after: unknown;
5
+ }
6
+ interface EntityChange {
7
+ entityId: number;
8
+ entityType: string;
9
+ fields: FieldChange[];
10
+ }
11
+ interface StateDiff {
12
+ added: Record<string, unknown[]>;
13
+ modified: Record<string, unknown[]>;
14
+ removed: Record<string, (string | number)[]>;
15
+ fieldChanges?: EntityChange[];
16
+ }
17
+ interface CloneEvent {
18
+ type: string;
19
+ payload: unknown;
20
+ timestamp: string;
21
+ sourceRule?: string;
22
+ }
23
+
24
+ interface TraceLink {
25
+ traceId: string;
26
+ spanId: string;
27
+ type: 'retry' | 'read_after_write' | 'write_after_write' | 'fan_out' | 'async' | 'manual';
28
+ }
29
+ interface RetryPolicy {
30
+ maxAttempts?: number;
31
+ backoffMs?: number;
32
+ strategy?: 'fixed' | 'linear' | 'exponential' | 'unknown';
33
+ }
34
+ interface OutboundHttpTrace {
35
+ method?: string;
36
+ scheme?: 'http' | 'https';
37
+ host?: string;
38
+ route?: string;
39
+ path?: string;
40
+ statusCode?: number;
41
+ latencyMs?: number;
42
+ requestBytes?: number;
43
+ responseBytes?: number;
44
+ }
45
+ interface CausalLink {
46
+ traceId: string;
47
+ spanId: string;
48
+ type: 'retry' | 'read_after_write' | 'write_after_write';
49
+ }
50
+ type TraceErrorKind = 'validation_error' | 'not_found' | 'authentication_error' | 'permission_denied' | 'rate_limited' | 'timeout' | 'network_error' | 'server_error' | 'agent_error' | 'unknown';
51
+ interface TraceError {
52
+ code: string;
53
+ message: string;
54
+ kind?: TraceErrorKind;
55
+ class?: string;
56
+ normalizedCode?: string;
57
+ name?: string;
58
+ statusCode?: number;
59
+ retryable?: boolean;
60
+ retryAfterSeconds?: number;
61
+ stack?: string;
62
+ stackHash?: string;
63
+ causeChain?: Array<{
64
+ class?: string;
65
+ code?: string;
66
+ message?: string;
67
+ }>;
68
+ retryPolicy?: RetryPolicy;
69
+ details?: unknown;
70
+ }
71
+ interface TraceEntry {
72
+ id: string;
73
+ toolName: string;
74
+ traceId?: string;
75
+ spanId?: string;
76
+ parentSpanId?: string | null;
77
+ links?: TraceLink[];
78
+ runIndex?: number;
79
+ twinName?: string;
80
+ sessionId?: string;
81
+ input: Record<string, unknown>;
82
+ output: unknown;
83
+ startTimestamp?: string;
84
+ endTimestamp?: string;
85
+ queuedAt?: string;
86
+ dequeuedAt?: string;
87
+ startedAt?: string;
88
+ endedAt?: string;
89
+ uploadedAt?: string;
90
+ timestamp: string;
91
+ durationMs: number;
92
+ stateMutations: StateDiff | null;
93
+ error: TraceError | null;
94
+ sequenceIndex?: number;
95
+ requestBytes?: number;
96
+ responseBytes?: number;
97
+ entitiesRead?: Array<{
98
+ collection: string;
99
+ id: string | number;
100
+ }>;
101
+ entitiesWritten?: Array<{
102
+ collection: string;
103
+ id: string | number;
104
+ action: 'create' | 'update' | 'delete';
105
+ }>;
106
+ isRetry?: boolean;
107
+ retriedFromId?: string;
108
+ retryCount?: number;
109
+ rateLimitRemaining?: number;
110
+ triggeredRateLimit?: boolean;
111
+ errorCategory?: 'agent_error' | 'validation_error' | 'not_found' | 'permission_denied' | 'rate_limited' | 'server_error' | 'none';
112
+ causalLinks?: string[];
113
+ causalLinkDetails?: CausalLink[];
114
+ outboundHttp?: OutboundHttpTrace;
115
+ agentInternals?: {
116
+ providerRequestId?: string;
117
+ toolChoiceRationaleSummary?: string;
118
+ tokenUsage?: {
119
+ input?: number;
120
+ output?: number;
121
+ total?: number;
122
+ };
123
+ costUsd?: number;
124
+ latencyMs?: number;
125
+ };
126
+ }
127
+
128
+ interface SuccessCriterion {
129
+ id: string;
130
+ description: string;
131
+ type: 'deterministic' | 'probabilistic';
132
+ critical?: boolean;
133
+ structuredAssertion?: Record<string, unknown>;
134
+ judge?: JudgeCriterionConfig;
135
+ }
136
+ interface JudgeCriterionRubricExample {
137
+ evidence: string;
138
+ verdict: 'pass' | 'fail' | 'partial' | 'inconclusive';
139
+ rationale: string;
140
+ }
141
+ interface JudgeCriterionRubric {
142
+ instructions?: string;
143
+ pass?: string;
144
+ partial?: string;
145
+ fail?: string;
146
+ inconclusive?: string;
147
+ examples?: JudgeCriterionRubricExample[];
148
+ }
149
+ interface JudgeCriterionConfig {
150
+ rubric?: JudgeCriterionRubric;
151
+ promptVersion?: string;
152
+ }
153
+ /**
154
+ * Reasons why an LLM-judged criterion could not be evaluated and must be
155
+ * surfaced as `status: 'error'` (i.e. excluded from the weighted satisfaction
156
+ * score and called out in the report). See #2507.
157
+ *
158
+ * `rate_limited` — Upstream 429 (Gemini RPM/TPM blown, or direct provider
159
+ * rate limit). Keep retrying a later run.
160
+ * `upstream_5xx` — 5xx from upstream including proxy 502 that wraps
161
+ * "Gemini API error: 429 Resource exhausted" (our proxy
162
+ * translates 429 to 502 on the wire).
163
+ * `auth_error` — 401/403 from upstream (misconfigured or revoked key).
164
+ * `provider_error` — Generic/unknown provider failure (kept for back-compat,
165
+ * no longer silently degrades to 0% score).
166
+ */
167
+ type LlmEvalErrorReason = 'rate_limited' | 'upstream_5xx' | 'auth_error' | 'provider_error';
168
+ type JudgeFailureClass = 'none' | 'agent_model_behavior' | 'clone_fidelity_gap' | 'routing_sandbox_gap' | 'evaluator_scenario_gap' | 'infrastructure_gap' | 'missing_evidence' | 'unknown';
169
+ type JudgeEvidenceKind = 'span' | 'state_before' | 'state_after' | 'state_diff' | 'agent_response' | 'agent_trace' | 'clone_event';
170
+ interface JudgeEvidenceRef {
171
+ kind: JudgeEvidenceKind;
172
+ id: string;
173
+ note?: string;
174
+ }
175
+ interface JudgeBenchmarkRecommendation {
176
+ shouldPromote: boolean;
177
+ benchmarkName: string;
178
+ scenarioFamily: string;
179
+ tags: string[];
180
+ rationale: string;
181
+ similarScenarioQuery: string[];
182
+ }
183
+ interface JudgeRegressionRisk {
184
+ status: 'not_assessed' | 'no_regression_evidence' | 'regression_detected' | 'unknown';
185
+ explanation: string;
186
+ evidenceRefs: JudgeEvidenceRef[];
187
+ }
188
+ interface JudgeDiagnosis {
189
+ /**
190
+ * Where this diagnosis came from. `model` means the LLM supplied the structured
191
+ * diagnosis. `fallback` means Archal filled defaults for a legacy/small-shape
192
+ * response. `infrastructure` means Archal generated metadata for judge
193
+ * unavailability or an evaluator-side skip.
194
+ */
195
+ source?: 'model' | 'fallback' | 'infrastructure';
196
+ whatBroke: string;
197
+ howOften: string;
198
+ affectedUsers: string[];
199
+ why: string;
200
+ failureClass: JudgeFailureClass;
201
+ evidenceRefs: JudgeEvidenceRef[];
202
+ missingEvidence: string[];
203
+ benchmarkRecommendation: JudgeBenchmarkRecommendation;
204
+ suggestedFix: string;
205
+ regressionRisk: JudgeRegressionRisk;
206
+ }
207
+ interface EvaluationResult {
208
+ criterionId: string;
209
+ /**
210
+ * `error` means the criterion could NOT be evaluated due to upstream LLM
211
+ * failure (429/5xx/auth). It must not be treated as a pass or a fail for the
212
+ * satisfaction calculation — the final report should surface "N criteria
213
+ * unevaluated, results incomplete" rather than silently under-reporting.
214
+ *
215
+ * `skipped` means evaluation was deliberately short-circuited as a cost
216
+ * optimization — currently only when every deterministic criterion already
217
+ * failed, so spending judge calls on the probabilistic criteria is wasteful.
218
+ * Like `error`, it is EXCLUDED from the weighted satisfaction average (it is
219
+ * not evidence of failure). Unlike `error`, it does NOT mark the run
220
+ * incomplete/untrustworthy: the deterministic verdict is conclusive, so the
221
+ * score stands. See `calculateOverallScore` and `score-trust.ts`.
222
+ *
223
+ * `inconclusive` means the judge ran but evidence could not prove a verdict.
224
+ */
225
+ status: 'pass' | 'fail' | 'partial' | 'inconclusive' | 'error' | 'skipped';
226
+ confidence: number;
227
+ explanation: string;
228
+ fallbackRecommended?: boolean;
229
+ fallbackFailureReason?: 'missing_credentials' | 'rate_limited' | 'context_too_large' | 'provider_error';
230
+ /** Structured reason when `status === 'error'`. Surfaced in the report summary. */
231
+ errorReason?: LlmEvalErrorReason;
232
+ /** Continuous [0,1] grade for partial credit or shaped deterministic rewards. */
233
+ partialScore?: number;
234
+ /**
235
+ * Structured LLM-judge diagnosis. This is explanatory metadata only:
236
+ * satisfaction scoring still depends solely on `status` and `partialScore`.
237
+ */
238
+ diagnosis?: JudgeDiagnosis;
239
+ }
240
+
241
+ /**
242
+ * Inline seed object: entity collections keyed by table, the exact JSON shape
243
+ * the clone `/state` PUT accepts (the file-seed loader's shape without the
244
+ * file).
245
+ */
246
+ type InlineSeed = Record<string, unknown[]>;
247
+ /**
248
+ * A named catalog seed (resolved server-side at provision time) or an inline
249
+ * state object (pushed client-side after provision). File refs arrive with
250
+ * eval-file support.
251
+ */
252
+ type SeedRef = string | InlineSeed;
253
+ interface SdkAuth {
254
+ /** Bearer token. Defaults to the ARCHAL_TOKEN environment variable. */
255
+ token?: string;
256
+ }
257
+ /** Command line for a spawned agent process. */
258
+ interface AgentCommand {
259
+ command: string;
260
+ args?: string[];
261
+ cwd?: string;
262
+ env?: Record<string, string>;
263
+ }
264
+ interface ExecOptions {
265
+ /** The task handed to the agent as AGENT_TASK. */
266
+ task: string;
267
+ /** Agent timeout in seconds. Defaults to 300. */
268
+ timeout?: number;
269
+ /** Advertised to the agent as AGENT_MODEL. */
270
+ model?: string;
271
+ }
272
+ /**
273
+ * How a spawned agent process ended. `exec()` reports agent failures here
274
+ * instead of throwing so the caller can still collect and judge the
275
+ * `outcome()`; it throws only when the process cannot be started at all.
276
+ */
277
+ interface ExecResult {
278
+ exitCode: number | null;
279
+ timedOut: boolean;
280
+ durationMs: number;
281
+ /** The agent's final text, when extractable from its output. */
282
+ response?: string;
283
+ }
284
+ interface ClonesOptions {
285
+ /** Per-service seed, keyed by service name. */
286
+ seed?: Record<string, SeedRef>;
287
+ auth?: SdkAuth;
288
+ /** Session time-to-live in seconds. Defaults to the hosted-session default. */
289
+ ttl?: number;
290
+ }
291
+ /**
292
+ * Everything observable about the session since the last `reset()` (or since
293
+ * `clones()` when never reset). `trace`, `stateAfter`, and `events` are read
294
+ * back from the clones; `stateBefore` and `stateDiff` come from the baseline
295
+ * the Session snapshotted client-side at `clones()`/`reset()` time.
296
+ */
297
+ interface Outcome {
298
+ /** Every tool call, recorded by the clones (not agent self-report). */
299
+ trace: TraceEntry[];
300
+ /** Combined clone state keyed by service name. */
301
+ stateBefore: Record<string, unknown>;
302
+ stateAfter: Record<string, unknown>;
303
+ stateDiff: StateDiff;
304
+ /** The agent's final text. Absent unless the caller supplies it. */
305
+ response?: string;
306
+ /** Clone event logs keyed by service name. Empty for clones without an events endpoint. */
307
+ events: Record<string, CloneEvent[]>;
308
+ }
309
+ /**
310
+ * A provisioned set of clones behind one hosted session (spec 12).
311
+ *
312
+ * Semantics:
313
+ * - `reset()` is the only run boundary. Clone trace buffers are cumulative
314
+ * and clear only on a state load, so two agent executions with no
315
+ * `reset()` between them produce one combined `outcome()`.
316
+ * - The session is billed wall-clock until `stop()`. Use
317
+ * `await using session = await clones(...)` so it never leaks; the library
318
+ * installs no process-global handlers.
319
+ * - The first `stop()` call fences every other operation permanently, even
320
+ * if the hosted delete fails (retry `stop()` in that case). An operation
321
+ * already in flight when `stop()` is called is not cancelled; it fails
322
+ * with clone HTTP errors once the session is gone.
323
+ * - `exec()` is sequential per session: one session means one shared trace
324
+ * and state buffer per clone, so a concurrent `exec()` throws. Parallel
325
+ * runs are parallel sessions. In-process callers skip `exec()` entirely
326
+ * and drive their own agent against `url()`/`env()`.
327
+ */
328
+ interface Session {
329
+ id: string;
330
+ /** Clone REST base URL for SDK/HTTP clients (Octokit baseUrl, etc.). */
331
+ url(service: string): string;
332
+ /** Clone routing env for spawning an agent process: AGENT_CLONE_URLS, ARCHAL_CLONE_NAMES, per-service URL vars, route auth. */
333
+ env(): Record<string, string>;
334
+ /** Spawn an agent with the scrubbed env contract and wait for it to finish. */
335
+ exec(agent: AgentCommand, opts: ExecOptions): Promise<ExecResult>;
336
+ outcome(extras?: {
337
+ response?: string;
338
+ }): Promise<Outcome>;
339
+ /** Re-seed every clone and clear traces, starting the next run. */
340
+ reset(): Promise<void>;
341
+ /** End the session (idempotent). Billing stops here. */
342
+ stop(): Promise<void>;
343
+ [Symbol.asyncDispose](): Promise<void>;
344
+ }
345
+
346
+ declare function clones(services: string[], options?: ClonesOptions): Promise<Session>;
347
+
348
+ declare const ASSERTION_TYPES: readonly ["exact_count", "min_count", "max_count", "exists", "not_exists", "state_check", "no_errors", "no_canary_leaks", "trace_count", "trace_contains", "output_contains", "content_check"];
349
+ interface ParsedAssertion {
350
+ type: (typeof ASSERTION_TYPES)[number];
351
+ subject: string;
352
+ value?: number;
353
+ predicate?: string;
354
+ labelFilter?: string;
355
+ contentPatterns?: string[];
356
+ /** For count assertions: case-insensitive title/summary substring filter. */
357
+ titleIncludes?: string;
358
+ /** For trace_contains: exact tool names accepted for structured service actions. */
359
+ toolNames?: string[];
360
+ requireAllContentPatterns?: boolean;
361
+ /** For content_check: restrict matching to these text-bearing fields. */
362
+ contentFields?: string[];
363
+ negated?: boolean;
364
+ /** For count assertions: restrict matching entities to a channel. */
365
+ channelFilter?: string;
366
+ /** For count assertions: the target clone/service scope */
367
+ targetService?: string;
368
+ /** For state_check: whether ALL items must match (true for "remain" assertions) */
369
+ allMustMatch?: boolean;
370
+ /** For entity-specific assertions: numeric ID extracted from "Issue #42", "PR #7", etc. */
371
+ entityId?: number;
372
+ /** For entity-specific assertions with natural keys, e.g. Jira "CHG-5". */
373
+ entityKey?: string;
374
+ /**
375
+ * For `exists` assertions: when true, the criterion is only satisfied if the
376
+ * subject was newly created during the run (i.e., present in `after` but not
377
+ * in `before`). Set by the parser when the natural-language phrasing implies
378
+ * agent action (e.g., "was created", "was posted", "was sent", "was added",
379
+ * "was opened", "has been created"). When false/undefined, evaluator performs
380
+ * a pure presence check against `after` only -- appropriate for criteria like
381
+ * "X exists" where the agent's job is to verify existing state.
382
+ */
383
+ requireDiff?: boolean;
384
+ }
385
+
386
+ declare const CRITERION: unique symbol;
387
+ interface CriterionOptions {
388
+ critical?: boolean;
389
+ rubric?: JudgeCriterionConfig['rubric'];
390
+ promptVersion?: string;
391
+ }
392
+ /**
393
+ * An SDK success criterion. Opaque — construct with {@link criterion} (an
394
+ * LLM-judged natural-language statement), {@link check} (structured
395
+ * deterministic assertion), or service/entity builders.
396
+ */
397
+ interface Criterion {
398
+ readonly [CRITERION]: true;
399
+ /** @internal consumed by judge() when building SuccessCriterion entries. */
400
+ readonly description: string;
401
+ /** @internal consumed by judge() when building SuccessCriterion entries. */
402
+ readonly type: SuccessCriterion['type'];
403
+ /** @internal consumed by judge() when building SuccessCriterion entries. */
404
+ readonly critical?: boolean;
405
+ /** @internal consumed by judge() when building SuccessCriterion entries. */
406
+ readonly structuredAssertion?: ParsedAssertion;
407
+ /** @internal consumed by judge() when building SuccessCriterion entries. */
408
+ readonly judge?: JudgeCriterionConfig;
409
+ }
410
+ /**
411
+ * An LLM-judged natural-language statement about the outcome.
412
+ */
413
+ declare function criterion(text: string, options?: CriterionOptions): Criterion;
414
+ interface CountOptions {
415
+ count?: number;
416
+ atLeast?: number;
417
+ atMost?: number;
418
+ titleIncludes?: string;
419
+ label?: string;
420
+ channel?: string;
421
+ }
422
+ type CheckDefinition = ParsedAssertion & {
423
+ critical?: boolean;
424
+ description?: string;
425
+ judge?: JudgeCriterionConfig;
426
+ };
427
+ interface EntityCriteriaBuilder {
428
+ exists(options?: CriterionOptions): Criterion;
429
+ notExists(options?: CriterionOptions): Criterion;
430
+ created(count?: CountOptions, options?: CriterionOptions): Criterion;
431
+ updated(count?: CountOptions, options?: CriterionOptions): Criterion;
432
+ deleted(count?: CountOptions, options?: CriterionOptions): Criterion;
433
+ }
434
+ declare function check(definition: CheckDefinition, options?: CriterionOptions): Criterion;
435
+ declare function entity(service: string, subject: string): EntityCriteriaBuilder;
436
+
437
+ interface JudgeOptions {
438
+ /** Expected-behavior context handed to the LLM judge. */
439
+ expected?: string;
440
+ /** Judge model. Defaults to the shared canonical judge model. */
441
+ model?: string;
442
+ /**
443
+ * Bearer token for managed judge routing. Defaults to the ARCHAL_TOKEN
444
+ * environment variable. Without a token the LLM judge cannot run and every
445
+ * criterion reports status 'error' with a suggested fix.
446
+ */
447
+ auth?: {
448
+ token?: string;
449
+ };
450
+ }
451
+ /** Result of judging one {@link Outcome} against a set of criteria. */
452
+ interface Judgment {
453
+ /** Weighted 0-100 score for this single outcome. */
454
+ score: number;
455
+ /**
456
+ * True when `score` >= 80 and every criterion evaluated conclusively
457
+ * (none reported 'error', 'inconclusive', or 'skipped').
458
+ */
459
+ passed: boolean;
460
+ /** Per-criterion status, evidence, and confidence. */
461
+ criteria: EvaluationResult[];
462
+ }
463
+ /**
464
+ * Grade an outcome: `evaluateRun` from `@archal/evaluator`, nothing more.
465
+ * No execution, no upload, no markdown. Safe to call concurrently — the
466
+ * resolved token is scoped to the call, not stored globally.
467
+ */
468
+ declare function judge(outcome: Outcome, criteria: Criterion[], options?: JudgeOptions): Promise<Judgment>;
469
+
470
+ interface AgentMetrics {
471
+ inputTokens: number;
472
+ outputTokens: number;
473
+ llmCallCount: number;
474
+ provider?: string;
475
+ model?: string;
476
+ }
477
+ interface ReportAgentMetricsOptions {
478
+ metricsFile?: string;
479
+ }
480
+ /**
481
+ * Write agent-side token usage for `archal run`.
482
+ *
483
+ * Archal sets AGENT_METRICS_FILE when it launches a harness. Calling this
484
+ * helper before the harness exits lets the dashboard show agent input/output
485
+ * token counts without exposing the artifact wire format to user code.
486
+ */
487
+ declare function reportAgentMetrics(metrics: AgentMetrics, options?: ReportAgentMetricsOptions): Promise<boolean>;
488
+
489
+ interface ScenarioDefinition {
490
+ name: string;
491
+ clones: string[];
492
+ task: string;
493
+ expected?: string;
494
+ agent: AgentCommand;
495
+ criteria?: Criterion[];
496
+ /**
497
+ * Agent execution timeout in seconds. Run options take precedence; when
498
+ * both are absent the SDK session default applies. Workspace-derived
499
+ * scenarios carry the runner's timeout here so both paths score alike.
500
+ */
501
+ timeout?: number;
502
+ }
503
+ interface ScenarioRunOptions extends Pick<ExecOptions, 'model' | 'timeout'> {
504
+ runs?: number;
505
+ auth?: SdkAuth;
506
+ }
507
+ interface ScenarioAttemptResult {
508
+ index: number;
509
+ exec: ExecResult;
510
+ outcome: Outcome;
511
+ judgment?: Judgment;
512
+ /**
513
+ * False when the judgment (or exec fallback) failed, and always false when
514
+ * `toolCallCount` is 0: an agent that never touched a clone did not
515
+ * exercise the scenario, whatever the judge scored — the seeded state can
516
+ * satisfy criteria on its own. `satisfaction` stays report-only.
517
+ */
518
+ passed: boolean;
519
+ satisfaction: number;
520
+ /**
521
+ * Agent tool calls recorded by the clones for this run, with synthetic
522
+ * proxy/canary trace entries excluded.
523
+ */
524
+ toolCallCount: number;
525
+ }
526
+ interface ScenarioResult {
527
+ name: string;
528
+ passed: boolean;
529
+ satisfaction: number;
530
+ runs: ScenarioAttemptResult[];
531
+ }
532
+ interface ScenarioHandle {
533
+ definition: ScenarioDefinition;
534
+ run(options?: ScenarioRunOptions): Promise<ScenarioResult>;
535
+ }
536
+ declare function scenario(definition: ScenarioDefinition): ScenarioHandle;
537
+
538
+ interface BenchmarkDefinition {
539
+ name: string;
540
+ description?: string;
541
+ scenarios: Array<ScenarioDefinition | ScenarioHandle>;
542
+ }
543
+ interface BenchmarkRunOptions extends ScenarioRunOptions {
544
+ /**
545
+ * Correlates every scenario submission of one run() call into a single
546
+ * `benchmark_runs` row. Defaults to a fresh UUID per run() call.
547
+ */
548
+ invocationId?: string;
549
+ /** Workspace to submit results to. Defaults to ARCHAL_WORKSPACE_ID. */
550
+ workspaceId?: string;
551
+ }
552
+ interface BenchmarkScenarioResult {
553
+ definition: ScenarioDefinition;
554
+ result: ScenarioResult;
555
+ }
556
+ interface BenchmarkResult {
557
+ name: string;
558
+ slug: string;
559
+ invocationId: string;
560
+ passed: boolean;
561
+ /** Mean of scenario satisfactions, 0-100. */
562
+ satisfaction: number;
563
+ scenarios: BenchmarkScenarioResult[];
564
+ /** Cloud run id, present when results were submitted. */
565
+ runId?: string;
566
+ /** Absolute dashboard URL for the cloud run, present when submitted. */
567
+ dashboardUrl?: string;
568
+ }
569
+ interface BenchmarkHandle {
570
+ definition: BenchmarkDefinition;
571
+ run(options?: BenchmarkRunOptions): Promise<BenchmarkResult>;
572
+ }
573
+ interface WorkspaceBenchmarkOptions {
574
+ /** Agent command the caller supplies for every member scenario. */
575
+ agent: AgentCommand;
576
+ auth?: SdkAuth;
577
+ /** Workspace to load the benchmark from. Defaults to ARCHAL_WORKSPACE_ID. */
578
+ workspaceId?: string;
579
+ }
580
+ interface PublishOptions {
581
+ auth?: SdkAuth;
582
+ /** Workspace to submit results to. Defaults to ARCHAL_WORKSPACE_ID. */
583
+ workspaceId?: string;
584
+ /** See {@link BenchmarkRunOptions.invocationId}. */
585
+ invocationId?: string;
586
+ }
587
+ interface PublishResult {
588
+ runId: string;
589
+ url: string;
590
+ }
591
+ /**
592
+ * A benchmark is a named group of scenarios. Two forms, one noun:
593
+ *
594
+ * - `benchmark({ name, scenarios })` groups code-first scenarios and returns
595
+ * a handle synchronously.
596
+ * - `benchmark('payment-flows', { agent })` loads a dashboard-authored
597
+ * benchmark by slug, converts each member scenario's markdown into a
598
+ * ScenarioDefinition, and resolves to the same kind of handle (async — it
599
+ * fetches from the workspace). Requires a token (auth.token or
600
+ * ARCHAL_TOKEN) and a workspace id (option or ARCHAL_WORKSPACE_ID).
601
+ *
602
+ * Either way, `handle.run()` runs each scenario (a scenario run is one agent
603
+ * execution plus a judge pass) and, when credentials are present, streams
604
+ * results to the cloud under a single benchmark run.
605
+ */
606
+ declare function benchmark(definition: BenchmarkDefinition): BenchmarkHandle;
607
+ declare function benchmark(workspaceSlug: string, options: WorkspaceBenchmarkOptions): Promise<BenchmarkHandle>;
608
+ /**
609
+ * Submit one already-executed scenario result to the cloud as a
610
+ * single-scenario benchmark run. Unlike benchmark().run(), missing
611
+ * credentials are an error here — publishing IS the upload.
612
+ */
613
+ declare function publish(result: ScenarioResult, definition: ScenarioDefinition, options?: PublishOptions): Promise<PublishResult>;
614
+
615
+ /**
616
+ * Code-first SDK primitives (spec 12: provision / execute / collect / judge).
617
+ *
618
+ * This entry is the extraction target for the SDK-first surface: it must stay
619
+ * light (no pg, no sandbox-runtime, no fidelity in the static graph) and
620
+ * must not touch the ambient credentials store — callers pass tokens
621
+ * explicitly or via ARCHAL_TOKEN.
622
+ */
623
+
624
+ declare const version: string;
625
+
626
+ export { type AgentCommand, type AgentMetrics, type BenchmarkDefinition, type BenchmarkHandle, type BenchmarkResult, type BenchmarkRunOptions, type BenchmarkScenarioResult, type CheckDefinition, type ClonesOptions, type CountOptions, type Criterion, type CriterionOptions, type EntityCriteriaBuilder, type ExecOptions, type ExecResult, type InlineSeed, type JudgeOptions, type Judgment, type Outcome, type PublishOptions, type PublishResult, type ReportAgentMetricsOptions, type ScenarioAttemptResult, type ScenarioDefinition, type ScenarioHandle, type ScenarioResult, type ScenarioRunOptions, type SdkAuth, type SeedRef, type Session, type WorkspaceBenchmarkOptions, benchmark, check, clones, criterion, entity, judge, publish, reportAgentMetrics, scenario, version };