car-runtime 0.24.1 → 0.26.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 +273 -11
  2. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -667,12 +667,30 @@ export class CarRuntime {
667
667
  /** Set update preferences (JSON `UpdatePreferences` shape). Returns stored prefs JSON. */
668
668
  updatePrefsSet(prefsJson: string): Promise<string>;
669
669
 
670
- /** Route a prompt. Returns the routing decision as JSON. */
670
+ /**
671
+ * Route a prompt. Returns the routing decision as JSON, including
672
+ * `candidates`: the advisory ranking of every scored model
673
+ * (`{ model_id, reliability, score, selected, in_band }`) so callers can see
674
+ * why a model won and what the alternatives cost in reliability terms. Empty
675
+ * on explicit-model and cold-start paths where no ranking occurred.
676
+ */
671
677
  routeModel(prompt: string): Promise<string>;
672
678
 
673
679
  /** Per-model performance profiles. Returns JSON. */
674
680
  modelStats(): Promise<string>;
675
681
 
682
+ /**
683
+ * Persistent outcome scoreboard, folded from the durable outcome ledger.
684
+ * Returns JSON `{ rows: [{ model_id, success_count, fail_count,
685
+ * inconclusive_count, total_input_tokens, total_output_tokens, avg_quality,
686
+ * avg_latency_ms, success_rate, tokens_per_success, usd_per_success }],
687
+ * total_successes, total_failures, total_inconclusive, total_usd,
688
+ * overall_usd_per_success, model_count, receipts }`. Rows are sorted
689
+ * cheapest-correct-outcome first. The cross-session, outcome-denominated view
690
+ * (unlike `modelStats`, the live in-memory profiles).
691
+ */
692
+ outcomeScoreboard(): Promise<string>;
693
+
676
694
  // --- Execution ---
677
695
 
678
696
  /** Count of events in this runtime's execution log. */
@@ -1081,6 +1099,15 @@ export interface IntentHint {
1081
1099
  * then `prefer_quality`, then `prefer_local`.
1082
1100
  */
1083
1101
  prefer_quality?: boolean;
1102
+ /**
1103
+ * The operation is high-stakes — consequential or irreversible (e.g. the
1104
+ * session is authorized for FullAccess actions). Forces the strongest
1105
+ * quality posture regardless of task or any cost/latency preference: never
1106
+ * economize on what you can't take back. Highest precedence — wins over
1107
+ * `prefer_fast`, `prefer_quality`, and `prefer_local`. The daemon sets this
1108
+ * automatically for FullAccess-granted sessions.
1109
+ */
1110
+ high_stakes?: boolean;
1084
1111
  }
1085
1112
 
1086
1113
  // --- Voice streaming (stored-callback pattern) ---
@@ -1401,6 +1428,13 @@ export function resumeWorkflow(pausedJson: string, inputJson: string): Promise<s
1401
1428
  /** Static analysis on a workflow definition. Returns verification report JSON. */
1402
1429
  export function verifyWorkflow(workflowJson: string): string;
1403
1430
 
1431
+ /**
1432
+ * Build the external-item automation recipe (poll → dedup → per-item agent →
1433
+ * deliver) from an `AutomationSpec` JSON into a runnable workflow JSON. Hand the
1434
+ * result to `runWorkflow`, typically on a schedule. Stateless.
1435
+ */
1436
+ export function buildAutomationWorkflow(specJson: string): string;
1437
+
1404
1438
  export interface StartMeetingResponse {
1405
1439
  id: string;
1406
1440
  title: string;
@@ -1486,12 +1520,19 @@ export function reapStaleAgents(
1486
1520
  // --- car-a2a server lifecycle ---
1487
1521
  //
1488
1522
  // Expose CAR as an Agent2Agent (A2A) v1.0 peer programmatically,
1489
- // without shelling out to `car-server --a2a-bind`. Process-global
1490
- // state holds the bound listener and join handle so a later
1491
- // `stopA2aServer` / `a2aServerStatus` call reaches the right server.
1523
+ // without shelling out to `car-server --a2a-bind`. These proxy to the
1524
+ // daemon the `CarRuntime` is connected to, so each takes the runtime as
1525
+ // its first argument.
1526
+ //
1527
+ // NOTE ON NAMING: napi-rs (heck) splits at digit→letter boundaries, so
1528
+ // the Rust `start_a2a_server` camelCases to `startA2AServer` (the `a2a`
1529
+ // segment becomes `A2A`), NOT `startA2aServer`. The exported names are
1530
+ // `startA2AServer` / `stopA2AServer` / `a2AServerStatus` /
1531
+ // `sendA2AMessage` / `a2ADispatch`. (Earlier versions of this file
1532
+ // declared `…A2a…`, which did not exist at runtime — car-releases#65.)
1492
1533
 
1493
1534
  /**
1494
- * Start an A2A listener.
1535
+ * Start an A2A listener on the daemon `rt` is connected to.
1495
1536
  *
1496
1537
  * `paramsJson` shape:
1497
1538
  * ```jsonc
@@ -1510,31 +1551,49 @@ export function reapStaleAgents(
1510
1551
  * the calling `CarRuntime`'s session runtime instead of spawning a
1511
1552
  * fresh one. Tools registered on the session via
1512
1553
  * `registerToolSchema` then appear on the Agent Card's `skills`
1513
- * list, and A2A peer `message/send` calls for those tools route
1514
- * back to the handler installed via `registerToolHandler`. This is
1554
+ * list, and A2A peer `message/send` calls that carry an explicit
1555
+ * tool invocation (a `data` part `{ "tool": "...", "parameters": {...} }`)
1556
+ * route back to the handler installed via `registerToolHandler`. This is
1515
1557
  * the canonical path for host-language agents to project themselves
1516
1558
  * over A2A. Default `false` preserves the legacy fresh-Runtime
1517
1559
  * behaviour (only `register_agent_basics` tools, dispatch in Rust).
1518
1560
  *
1561
+ * A purely *conversational* `message/send` (free text, no tool `data`
1562
+ * part) is routed to the host's `agent.chat` handler — the daemon
1563
+ * reverse-calls `agent.chat` on this session, aggregates the streamed
1564
+ * reply, and returns it as the A2A agent message (car-releases#65). So
1565
+ * register an `agent.chat` handler to serve conversational turns, and/or
1566
+ * a `registerToolHandler` for explicit tool `data` parts.
1567
+ *
1519
1568
  * Returns `'{"bound":"127.0.0.1:8731"}'` on success. Errors if a
1520
1569
  * server is already running, the bind fails, `share_session_runtime`
1521
1570
  * is set but no session runtime is available (e.g. invoked from a
1522
1571
  * non-WS path), or `paramsJson` is malformed.
1523
1572
  */
1524
- export function startA2aServer(paramsJson: string): Promise<string>;
1573
+ export function startA2AServer(rt: CarRuntime, paramsJson: string): Promise<string>;
1525
1574
 
1526
1575
  /**
1527
1576
  * Stop the running A2A listener. Returns `'{"stopped":true}'` on
1528
1577
  * success. Errors if no server is running.
1529
1578
  */
1530
- export function stopA2aServer(): string;
1579
+ export function stopA2AServer(rt: CarRuntime): Promise<string>;
1531
1580
 
1532
1581
  /**
1533
1582
  * Report whether the A2A listener is up. Always returns a JSON
1534
1583
  * object — `{"running":true,"bound":"...","uptime_secs":N}` when
1535
1584
  * running, `{"running":false}` otherwise.
1536
1585
  */
1537
- export function a2aServerStatus(): string;
1586
+ export function a2AServerStatus(rt: CarRuntime): Promise<string>;
1587
+
1588
+ /**
1589
+ * Send a message to a remote A2A peer at `endpoint`.
1590
+ *
1591
+ * `paramsJson` shape: `{ endpoint, message, blocking?, ingest_a2ui?,
1592
+ * route_auth?, allow_untrusted_endpoint? }`. The daemon enforces a
1593
+ * loopback-or-explicit-allow rule on `endpoint` — non-loopback URLs
1594
+ * require `allow_untrusted_endpoint: true`.
1595
+ */
1596
+ export function sendA2AMessage(rt: CarRuntime, paramsJson: string): Promise<string>;
1538
1597
 
1539
1598
  // --- Verification (stateless) ---
1540
1599
 
@@ -1548,6 +1607,15 @@ export function a2aServerStatus(): string;
1548
1607
  * `JSON.stringify([{ name: "echo", parameters: { type: "object",
1549
1608
  * properties: { msg: { type: "string" } }, required: ["msg"] } }])`.
1550
1609
  * When both are given, `toolSchemasJson` takes precedence.
1610
+ *
1611
+ * Returns a JSON string:
1612
+ * `{ valid, issues, simulated_state, execution_levels, conflicts,
1613
+ * evidence }`. `evidence` is the verifier's declared scope (survey
1614
+ * "Code as Agent Harness" §5.2.2): `{ checks: [{ name, ran, verifies,
1615
+ * cannot_verify, findings }], assumptions, untested_regions,
1616
+ * residual_risks, confidence }` — so a `valid: true` verdict can be read
1617
+ * with its scope (what was checked, what was not, coverage confidence)
1618
+ * rather than as a blanket guarantee.
1551
1619
  */
1552
1620
  export function verify(
1553
1621
  proposalJson: string,
@@ -1566,6 +1634,158 @@ export function optimize(proposalJson: string): string;
1566
1634
 
1567
1635
  export function equivalent(proposal1Json: string, proposal2Json: string): boolean;
1568
1636
 
1637
+ /**
1638
+ * Wire protocol version this binding speaks to the `car-server` daemon,
1639
+ * exchanged via the `server.handshake` RPC. Bumped only on a
1640
+ * backward-incompatible JSON-RPC change — independent of the package semver.
1641
+ */
1642
+ export function protocolVersion(): number;
1643
+
1644
+ /**
1645
+ * Check a proposal for transactional conflicts against the current shared
1646
+ * state (survey "Code as Agent Harness" §4.3/§5.2.4 — the shared
1647
+ * code-centric harness substrate). `versionsJson` is a JSON object mapping
1648
+ * state key → current version (from the runtime's versioned state store);
1649
+ * `stateJson` (optional) maps key → current value for value-level
1650
+ * assumption checks.
1651
+ *
1652
+ * Returns the `TransactionReport` JSON: `{ consistent: boolean, conflicts:
1653
+ * [{ kind, key, actions, explanation, resolution }] }` where `kind` is
1654
+ * `"write_write" | "read_write" | "stale_assumption"`. Detects write-write
1655
+ * races and read-write hazards between unordered actions, and stale
1656
+ * assumptions (an action planned against a key at a version/value the
1657
+ * shared state has since moved past — belief divergence). Each conflict
1658
+ * carries a human-actionable explanation and a suggested resolution.
1659
+ */
1660
+ export function transactionCheck(
1661
+ proposalJson: string,
1662
+ versionsJson?: string | null,
1663
+ stateJson?: string | null,
1664
+ ): string;
1665
+
1666
+ /**
1667
+ * Compute harness-level evaluation metrics (survey "Code as Agent Harness"
1668
+ * §5.2.1) from a JSONL tail of a session's event log (one event per line).
1669
+ * Returns the `HarnessMetrics` JSON with six operational-substrate
1670
+ * dimensions — `trajectory_efficiency` (actions, tokens, cost, wall-clock,
1671
+ * success_rate), `verification_strength` (validated/rejected, rejection_rate),
1672
+ * `recovery` (replans, branch decisions, rejected alternatives),
1673
+ * `state_consistency` (changes, snapshots, rollbacks), `safety`
1674
+ * (permission escalations/denials/approvals), and `replayability` — to
1675
+ * complement task-success accuracy when comparing harness variants.
1676
+ */
1677
+ export function harnessMetrics(eventsJsonl: string): string;
1678
+
1679
+ // --- Agentic Harness Engineering: Evolution Agent (survey §3.5, §5.2.3) ---
1680
+ //
1681
+ // A governed meta-agent that proposes harness mutations from telemetry and
1682
+ // gates their adoption. Every mutation carries a change contract; promotion
1683
+ // is regression-gated; safety-affecting changes require human approval.
1684
+
1685
+ /**
1686
+ * Diagnose harness telemetry into governed mutation proposals. `metricsJson`
1687
+ * is a `HarnessMetrics` (from {@link harnessMetrics}); `configJson`
1688
+ * optionally overrides the diagnosis thresholds. Returns a JSON array of
1689
+ * `HarnessMutation`, each `{ id, rationale, contract: { component,
1690
+ * target_failure, predicted_improvement, invariants, falsifying_eval,
1691
+ * rollback } }`. Nothing is applied — proposals must pass
1692
+ * {@link evolutionEvaluate} and, when safety-affecting, human approval.
1693
+ */
1694
+ export function evolutionDiagnose(
1695
+ metricsJson: string,
1696
+ configJson?: string | null,
1697
+ ): string;
1698
+
1699
+ /**
1700
+ * Regression-gate a candidate harness mutation. `mutationJson` is a
1701
+ * `HarnessMutation`; `baselineJson`/`candidateJson` are `HarnessMetrics`
1702
+ * measured before/after applying it on held-out telemetry. Returns the
1703
+ * `PromotionDecision` JSON `{ decision: "promote" | "needs_approval" |
1704
+ * "reject", reason }` — a mutation is promoted only if its target improved
1705
+ * without regressing guarded metrics; safety-affecting mutations route to
1706
+ * `needs_approval` even when they pass.
1707
+ */
1708
+ export function evolutionEvaluate(
1709
+ mutationJson: string,
1710
+ baselineJson: string,
1711
+ candidateJson: string,
1712
+ configJson?: string | null,
1713
+ ): string;
1714
+
1715
+ /**
1716
+ * Apply a mutation's concrete patch to a `HarnessConfig` under governed
1717
+ * authorization (survey §3.5/§5.2.3). `humanApproved=true` applies under the
1718
+ * HITL path — the only path that may land a safety-affecting mutation;
1719
+ * otherwise `decisionJson` (a `PromotionDecision`) must be `promote` and the
1720
+ * mutation must be non-safety. Returns `{ config, rollback }` (the updated
1721
+ * config and the inverse patch that restores it), or throws when refused.
1722
+ */
1723
+ export function evolutionApply(
1724
+ configJson: string,
1725
+ mutationJson: string,
1726
+ decisionJson?: string | null,
1727
+ humanApproved?: boolean,
1728
+ ): string;
1729
+
1730
+ // --- Permission-tier gate (survey "Code as Agent Harness" §3.4.3, §5.2.5) ---
1731
+ //
1732
+ // The harness as safety governor: classify each action's risk tier
1733
+ // (read_only | sandbox_edit | full_access), gate it against the session's
1734
+ // granted standing tier, and record human-in-the-loop approvals as durable,
1735
+ // auditable state (a JSONL ledger keyed by a stable action fingerprint).
1736
+
1737
+ /**
1738
+ * Classify each action in a proposal into its minimum required permission
1739
+ * tier. Returns a JSON array of `{ action_id, tool, required_tier }` where
1740
+ * `required_tier` is `"read_only" | "sandbox_edit" | "full_access"`.
1741
+ */
1742
+ export function permissionClassify(proposalJson: string): string;
1743
+
1744
+ /**
1745
+ * Evaluate each action against a granted standing tier, consulting the
1746
+ * durable approval ledger JSONL at `ledgerPath` when supplied. Returns a
1747
+ * JSON array of per-action decisions, each `{ decision, required, granted,
1748
+ * action_id, fingerprint, ... }` where `decision` is `"allow" |
1749
+ * "needs_approval" | "deny"`. A `needs_approval` decision means autonomy is
1750
+ * suspended pending a human decision; resolve it with
1751
+ * {@link permissionRecordForFingerprint}.
1752
+ */
1753
+ export function permissionEvaluate(
1754
+ proposalJson: string,
1755
+ grantedTier: string,
1756
+ ledgerPath?: string | null,
1757
+ ): string;
1758
+
1759
+ /**
1760
+ * Record a durable human-in-the-loop approval (`approve=true`) or rejection
1761
+ * for the operation an action represents, appending it to the JSONL ledger
1762
+ * at `ledgerPath`. The decision persists and overrides future evaluations
1763
+ * of the same operation. Returns the stored approval record JSON.
1764
+ */
1765
+ export function permissionRecordDecision(
1766
+ actionJson: string,
1767
+ approve: boolean,
1768
+ reviewer: string,
1769
+ reason: string,
1770
+ evidence: string | undefined | null,
1771
+ ledgerPath: string,
1772
+ ): string;
1773
+
1774
+ /**
1775
+ * Like {@link permissionRecordDecision} but keyed by an explicit
1776
+ * `fingerprint` (from a prior `needs_approval` decision) with an annotating
1777
+ * `requiredTier`. Returns the stored approval record JSON.
1778
+ */
1779
+ export function permissionRecordForFingerprint(
1780
+ fingerprint: string,
1781
+ requiredTier: string,
1782
+ approve: boolean,
1783
+ reviewer: string,
1784
+ reason: string,
1785
+ evidence: string | undefined | null,
1786
+ ledgerPath: string,
1787
+ ): string;
1788
+
1569
1789
  // --- Multi-agent coordination ---
1570
1790
 
1571
1791
  /**
@@ -1690,6 +1910,34 @@ export function createTask(
1690
1910
  systemPrompt?: string | null,
1691
1911
  ): string;
1692
1912
 
1913
+ /**
1914
+ * Preview the durable OS-level schedule (launchd plist + crontab line) a task
1915
+ * would install, without installing it. `program` + `argsJson` (a JSON string
1916
+ * array) are the command the OS runs to execute the task once. Returns
1917
+ * `{ label, launchdPlist, launchdError, crontabLine, crontabError }`.
1918
+ */
1919
+ export function renderOsSchedule(taskJson: string, program: string, argsJson: string): string;
1920
+
1921
+ /**
1922
+ * Install a durable OS-level schedule (launchd on macOS, crontab on Linux) so
1923
+ * the task fires even when the CAR daemon is down. Idempotent. Returns the
1924
+ * installed-schedule JSON.
1925
+ */
1926
+ export function installOsSchedule(taskJson: string, program: string, argsJson: string): string;
1927
+
1928
+ /** Remove a task's OS-level schedule (full label or bare task id). Returns `{ label, removed }`. */
1929
+ export function uninstallOsSchedule(labelOrId: string): string;
1930
+
1931
+ /** List labels of all CAR-managed OS-level schedules on this host (JSON string array). */
1932
+ export function listOsSchedules(): string;
1933
+
1934
+ /**
1935
+ * Reap orphaned OS-level schedules — uninstall every CAR-managed launchd/cron
1936
+ * entry whose task is gone from `~/.car/tasks/` or whose trigger is no longer
1937
+ * schedulable. Returns the reconcile report `{ removed, kept, errors }`.
1938
+ */
1939
+ export function reconcileOsSchedules(): string;
1940
+
1693
1941
  /** Run a task once using the registered agent runner. */
1694
1942
  export function runTask(taskJson: string): Promise<string>;
1695
1943
 
@@ -1818,7 +2066,7 @@ export function visionOcr(argsJson: string): Promise<string>;
1818
2066
  * both in one process gives you two task stores (task ids are
1819
2067
  * unique per dispatcher).
1820
2068
  */
1821
- export function a2aDispatch(method: string, paramsJson: string): Promise<string>;
2069
+ export function a2ADispatch(rt: CarRuntime, method: string, paramsJson: string): Promise<string>;
1822
2070
 
1823
2071
  // --- Lifecycle-managed agents (car_registry::supervisor) ---
1824
2072
 
@@ -1923,6 +2171,20 @@ export function agentsStop(id: string, signal?: string | null): Promise<string>;
1923
2171
  */
1924
2172
  export function agentsRestart(id: string): Promise<string>;
1925
2173
 
2174
+ /**
2175
+ * Block until a managed agent reaches one of `targetsJson` (a JSON string array
2176
+ * of statuses like `["running"]` or `["stopped","errored"]`; default
2177
+ * `["running"]`) or `timeoutSecs` (default 30) elapses, polling every `pollMs`
2178
+ * (default 200). Returns the matching `ManagedAgent` JSON; rejects on timeout or
2179
+ * unknown id.
2180
+ */
2181
+ export function agentsWait(
2182
+ id: string,
2183
+ targetsJson?: string | null,
2184
+ timeoutSecs?: number | null,
2185
+ pollMs?: number | null,
2186
+ ): Promise<string>;
2187
+
1926
2188
  /**
1927
2189
  * Read a window of an agent's logs under
1928
2190
  * `~/.car/logs/<id>.{stdout,stderr}.log`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "car-runtime",
3
- "version": "0.24.1",
3
+ "version": "0.26.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",