car-runtime 0.24.0 → 0.25.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 (2) hide show
  1. package/index.d.ts +176 -5
  2. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -160,8 +160,14 @@ export class CarRuntime {
160
160
  /**
161
161
  * Set replan configuration on this runtime.
162
162
  * `maxReplans` = 0 disables replanning (default).
163
+ * `replanOnRejected` (default false): when true, validator/policy/capability
164
+ * rejections (not just runtime failures) also trigger rollback + replan.
163
165
  */
164
- setReplanConfig(maxReplans: number, delayMs?: number | null): Promise<void>;
166
+ setReplanConfig(
167
+ maxReplans: number,
168
+ delayMs?: number | null,
169
+ replanOnRejected?: boolean | null,
170
+ ): Promise<void>;
165
171
 
166
172
  // --- State ---
167
173
 
@@ -326,9 +332,17 @@ export class CarRuntime {
326
332
  /**
327
333
  * Generate with full tracking. Returns JSON with `text`, `tool_calls`,
328
334
  * `usage`, `model_used`, `latency_ms`, `time_to_first_token_ms`,
329
- * `trace_id`. `time_to_first_token_ms` is wall-clock to the first
330
- * sampled token (populated by local Candle/MLX paths; `null` for
331
- * non-streaming remote calls).
335
+ * `trace_id`, `stop_reason`. `time_to_first_token_ms` is wall-clock to
336
+ * the first sampled token (populated by local Candle/MLX paths; `null`
337
+ * for non-streaming remote calls). `stop_reason` is the raw provider
338
+ * termination reason (OpenAI `finish_reason`, Anthropic `stop_reason`,
339
+ * Google `finishReason`); `null` for local backends or providers that
340
+ * don't report one. A value of `"length"`/`"max_tokens"`/`"MAX_TOKENS"`
341
+ * means the output was truncated at the token cap. On local Qwen3
342
+ * hybrid-thinking models it is also set to `"thinking_recovered"` when
343
+ * reasoning consumed the whole token budget and the runtime retried
344
+ * with reasoning suppressed to produce a direct answer, or
345
+ * `"thinking_truncated"` when even that retry was empty (car-releases#60).
332
346
  *
333
347
  * **Note:** intent is not exposed on the tracked path until the
334
348
  * positional argument list is converted to an options object —
@@ -481,7 +495,10 @@ export class CarRuntime {
481
495
  /**
482
496
  * Unified registry (local + remote). Returns JSON array of
483
497
  * `{ id, name, provider, capabilities, param_count, size_mb,
484
- * context_length, available, is_local, public_benchmarks }`.
498
+ * context_length, available, is_local, max_output_tokens,
499
+ * public_benchmarks }`. `max_output_tokens` is the registry-declared
500
+ * per-model output ceiling (`null` when the entry omits it; callers
501
+ * then fall back to a fraction of `context_length`).
485
502
  * `public_benchmarks` is `[{ name, score, harness?, source_url?,
486
503
  * measured_at? }]` with score on a 0.0–1.0 scale; ships empty in
487
504
  * the built-in catalog and is populated via curated registry data.
@@ -1531,6 +1548,15 @@ export function a2aServerStatus(): string;
1531
1548
  * `JSON.stringify([{ name: "echo", parameters: { type: "object",
1532
1549
  * properties: { msg: { type: "string" } }, required: ["msg"] } }])`.
1533
1550
  * When both are given, `toolSchemasJson` takes precedence.
1551
+ *
1552
+ * Returns a JSON string:
1553
+ * `{ valid, issues, simulated_state, execution_levels, conflicts,
1554
+ * evidence }`. `evidence` is the verifier's declared scope (survey
1555
+ * "Code as Agent Harness" §5.2.2): `{ checks: [{ name, ran, verifies,
1556
+ * cannot_verify, findings }], assumptions, untested_regions,
1557
+ * residual_risks, confidence }` — so a `valid: true` verdict can be read
1558
+ * with its scope (what was checked, what was not, coverage confidence)
1559
+ * rather than as a blanket guarantee.
1534
1560
  */
1535
1561
  export function verify(
1536
1562
  proposalJson: string,
@@ -1549,6 +1575,151 @@ export function optimize(proposalJson: string): string;
1549
1575
 
1550
1576
  export function equivalent(proposal1Json: string, proposal2Json: string): boolean;
1551
1577
 
1578
+ /**
1579
+ * Check a proposal for transactional conflicts against the current shared
1580
+ * state (survey "Code as Agent Harness" §4.3/§5.2.4 — the shared
1581
+ * code-centric harness substrate). `versionsJson` is a JSON object mapping
1582
+ * state key → current version (from the runtime's versioned state store);
1583
+ * `stateJson` (optional) maps key → current value for value-level
1584
+ * assumption checks.
1585
+ *
1586
+ * Returns the `TransactionReport` JSON: `{ consistent: boolean, conflicts:
1587
+ * [{ kind, key, actions, explanation, resolution }] }` where `kind` is
1588
+ * `"write_write" | "read_write" | "stale_assumption"`. Detects write-write
1589
+ * races and read-write hazards between unordered actions, and stale
1590
+ * assumptions (an action planned against a key at a version/value the
1591
+ * shared state has since moved past — belief divergence). Each conflict
1592
+ * carries a human-actionable explanation and a suggested resolution.
1593
+ */
1594
+ export function transactionCheck(
1595
+ proposalJson: string,
1596
+ versionsJson?: string | null,
1597
+ stateJson?: string | null,
1598
+ ): string;
1599
+
1600
+ /**
1601
+ * Compute harness-level evaluation metrics (survey "Code as Agent Harness"
1602
+ * §5.2.1) from a JSONL tail of a session's event log (one event per line).
1603
+ * Returns the `HarnessMetrics` JSON with six operational-substrate
1604
+ * dimensions — `trajectory_efficiency` (actions, tokens, cost, wall-clock,
1605
+ * success_rate), `verification_strength` (validated/rejected, rejection_rate),
1606
+ * `recovery` (replans, branch decisions, rejected alternatives),
1607
+ * `state_consistency` (changes, snapshots, rollbacks), `safety`
1608
+ * (permission escalations/denials/approvals), and `replayability` — to
1609
+ * complement task-success accuracy when comparing harness variants.
1610
+ */
1611
+ export function harnessMetrics(eventsJsonl: string): string;
1612
+
1613
+ // --- Agentic Harness Engineering: Evolution Agent (survey §3.5, §5.2.3) ---
1614
+ //
1615
+ // A governed meta-agent that proposes harness mutations from telemetry and
1616
+ // gates their adoption. Every mutation carries a change contract; promotion
1617
+ // is regression-gated; safety-affecting changes require human approval.
1618
+
1619
+ /**
1620
+ * Diagnose harness telemetry into governed mutation proposals. `metricsJson`
1621
+ * is a `HarnessMetrics` (from {@link harnessMetrics}); `configJson`
1622
+ * optionally overrides the diagnosis thresholds. Returns a JSON array of
1623
+ * `HarnessMutation`, each `{ id, rationale, contract: { component,
1624
+ * target_failure, predicted_improvement, invariants, falsifying_eval,
1625
+ * rollback } }`. Nothing is applied — proposals must pass
1626
+ * {@link evolutionEvaluate} and, when safety-affecting, human approval.
1627
+ */
1628
+ export function evolutionDiagnose(
1629
+ metricsJson: string,
1630
+ configJson?: string | null,
1631
+ ): string;
1632
+
1633
+ /**
1634
+ * Regression-gate a candidate harness mutation. `mutationJson` is a
1635
+ * `HarnessMutation`; `baselineJson`/`candidateJson` are `HarnessMetrics`
1636
+ * measured before/after applying it on held-out telemetry. Returns the
1637
+ * `PromotionDecision` JSON `{ decision: "promote" | "needs_approval" |
1638
+ * "reject", reason }` — a mutation is promoted only if its target improved
1639
+ * without regressing guarded metrics; safety-affecting mutations route to
1640
+ * `needs_approval` even when they pass.
1641
+ */
1642
+ export function evolutionEvaluate(
1643
+ mutationJson: string,
1644
+ baselineJson: string,
1645
+ candidateJson: string,
1646
+ configJson?: string | null,
1647
+ ): string;
1648
+
1649
+ /**
1650
+ * Apply a mutation's concrete patch to a `HarnessConfig` under governed
1651
+ * authorization (survey §3.5/§5.2.3). `humanApproved=true` applies under the
1652
+ * HITL path — the only path that may land a safety-affecting mutation;
1653
+ * otherwise `decisionJson` (a `PromotionDecision`) must be `promote` and the
1654
+ * mutation must be non-safety. Returns `{ config, rollback }` (the updated
1655
+ * config and the inverse patch that restores it), or throws when refused.
1656
+ */
1657
+ export function evolutionApply(
1658
+ configJson: string,
1659
+ mutationJson: string,
1660
+ decisionJson?: string | null,
1661
+ humanApproved?: boolean,
1662
+ ): string;
1663
+
1664
+ // --- Permission-tier gate (survey "Code as Agent Harness" §3.4.3, §5.2.5) ---
1665
+ //
1666
+ // The harness as safety governor: classify each action's risk tier
1667
+ // (read_only | sandbox_edit | full_access), gate it against the session's
1668
+ // granted standing tier, and record human-in-the-loop approvals as durable,
1669
+ // auditable state (a JSONL ledger keyed by a stable action fingerprint).
1670
+
1671
+ /**
1672
+ * Classify each action in a proposal into its minimum required permission
1673
+ * tier. Returns a JSON array of `{ action_id, tool, required_tier }` where
1674
+ * `required_tier` is `"read_only" | "sandbox_edit" | "full_access"`.
1675
+ */
1676
+ export function permissionClassify(proposalJson: string): string;
1677
+
1678
+ /**
1679
+ * Evaluate each action against a granted standing tier, consulting the
1680
+ * durable approval ledger JSONL at `ledgerPath` when supplied. Returns a
1681
+ * JSON array of per-action decisions, each `{ decision, required, granted,
1682
+ * action_id, fingerprint, ... }` where `decision` is `"allow" |
1683
+ * "needs_approval" | "deny"`. A `needs_approval` decision means autonomy is
1684
+ * suspended pending a human decision; resolve it with
1685
+ * {@link permissionRecordForFingerprint}.
1686
+ */
1687
+ export function permissionEvaluate(
1688
+ proposalJson: string,
1689
+ grantedTier: string,
1690
+ ledgerPath?: string | null,
1691
+ ): string;
1692
+
1693
+ /**
1694
+ * Record a durable human-in-the-loop approval (`approve=true`) or rejection
1695
+ * for the operation an action represents, appending it to the JSONL ledger
1696
+ * at `ledgerPath`. The decision persists and overrides future evaluations
1697
+ * of the same operation. Returns the stored approval record JSON.
1698
+ */
1699
+ export function permissionRecordDecision(
1700
+ actionJson: string,
1701
+ approve: boolean,
1702
+ reviewer: string,
1703
+ reason: string,
1704
+ evidence: string | undefined | null,
1705
+ ledgerPath: string,
1706
+ ): string;
1707
+
1708
+ /**
1709
+ * Like {@link permissionRecordDecision} but keyed by an explicit
1710
+ * `fingerprint` (from a prior `needs_approval` decision) with an annotating
1711
+ * `requiredTier`. Returns the stored approval record JSON.
1712
+ */
1713
+ export function permissionRecordForFingerprint(
1714
+ fingerprint: string,
1715
+ requiredTier: string,
1716
+ approve: boolean,
1717
+ reviewer: string,
1718
+ reason: string,
1719
+ evidence: string | undefined | null,
1720
+ ledgerPath: string,
1721
+ ): string;
1722
+
1552
1723
  // --- Multi-agent coordination ---
1553
1724
 
1554
1725
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "car-runtime",
3
- "version": "0.24.0",
3
+ "version": "0.25.0",
4
4
  "description": "Common Agent Runtime — a deterministic execution layer for AI agents",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",