@rulvar/cli 1.0.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.
@@ -0,0 +1,252 @@
1
+ import { CreateEngineOptions, Engine, JournalStore, KeyDeriver, LeasableStore, ModelRef, RunHandle, RunMeta, RunOutcome, Usage, Workflow, WorkflowEvent, WorkflowRegistry } from "@rulvar/core";
2
+
3
+ //#region src/io.d.ts
4
+ interface CliIo {
5
+ out(line: string): void;
6
+ err(line: string): void;
7
+ /**
8
+ * Asks one question and resolves with the answer line, or undefined
9
+ * when input is exhausted (EOF): the caller leaves the run suspended.
10
+ */
11
+ prompt(question: string): Promise<string | undefined>;
12
+ /** TTY-aware renderers may switch between live and plain output. */
13
+ isTTY: boolean;
14
+ }
15
+ /** The process-backed io the bin entry uses. */
16
+ declare function processIo(): CliIo;
17
+ //#endregion
18
+ //#region src/cli-main.d.ts
19
+ declare const HELP = "rulvar: durable multi-agent workflows (docs/06, section 10.5)\n\n rulvar run <file|name> [--args JSON] [--store PATH] [--budget-usd N]\n rulvar resume <runId> [--store PATH]\n rulvar runs ls [--store PATH]\n rulvar inspect <runId> [--store PATH]\n rulvar plan \"<goal>\" [--dry-run]\n rulvar kb <list | inbox | sweep>\n\nEngine assembly: adapters, defaults, and the workflow registry come from\nrulvar.config.mjs in the working directory (default export\n{ engineOptions?, workflows? }) or from the workflow module's named\nexports. --store selects the JsonlFileStore directory (default .rulvar).\nplan asks the planner model (role plan) to write a workflow script,\nlints and self-repairs it, then runs it in the worker sandbox; --dry-run\nprints the accepted script without running. Requires @rulvar/planner\ninstalled. kb list shows the per-project claim store\n(./rulvar.models.json) with full provenance. kb sweep runs the\nfalsification matrix from the kbSweep section of rulvar.config.mjs\n(fixed pool UNIONED with every model carrying an active negative claim\nplus the re-measure queue; optional canary probes flip drifted claims\nstale first; requires @rulvar/evals installed). kb inbox arrives with\nModelKnowledge phase 3.";
20
+ declare function runCli(argv: string[], options: {
21
+ cwd: string;
22
+ io: CliIo;
23
+ }): Promise<number>;
24
+ //#endregion
25
+ //#region src/commands.d.ts
26
+ interface CommandContext {
27
+ cwd: string;
28
+ io: CliIo;
29
+ }
30
+ declare function runCommand(argv: string[], context: CommandContext): Promise<number>;
31
+ declare function resumeCommand(argv: string[], context: CommandContext): Promise<number>;
32
+ declare function runsLsCommand(argv: string[], context: CommandContext): Promise<number>;
33
+ declare function inspectCommand(argv: string[], context: CommandContext): Promise<number>;
34
+ //#endregion
35
+ //#region src/config.d.ts
36
+ /** The shape both the config module and a workflow module may export. */
37
+ interface CliConfig {
38
+ engineOptions?: Partial<CreateEngineOptions>;
39
+ workflows?: WorkflowRegistry;
40
+ /** rulvar kb sweep configuration (M11-T05; docs/05, "Grounding and decay"). */
41
+ kbSweep?: KbSweepCliConfig;
42
+ }
43
+ /**
44
+ * The kb sweep config: a FIXED pool (sweep volume is never authorized
45
+ * by proposal volume) plus the cases per taskClass. Structural sweep
46
+ * shapes only: the CLI's static dependency stays @rulvar/core and
47
+ * @rulvar/evals loads dynamically at command time (the plan-command
48
+ * precedent), so graders and cases are typed by the config module.
49
+ */
50
+ interface KbSweepCliConfig {
51
+ /** The dedicated committer identity recorded on gates and authors. */
52
+ committerId: string;
53
+ /** The fixed pool; falsification UNIONS in the store's negative-claim and re-measure subjects. */
54
+ models: Array<{
55
+ model: `${string}:${string}`;
56
+ effort?: string;
57
+ }>;
58
+ /** Eval cases tagged by taskClass (constructed with @rulvar/evals inside the config module). */
59
+ cases: Array<{
60
+ taskClass: string;
61
+ case: unknown;
62
+ }>;
63
+ thresholds?: {
64
+ strength?: number;
65
+ weakness?: number;
66
+ };
67
+ /** Optional canary probes run per pool member BEFORE the sweep; drift flips stale. */
68
+ canary?: {
69
+ agentType: string;
70
+ prompts: string[];
71
+ };
72
+ /** Default: kb-sweep-<observedAt ISO>. */
73
+ reportId?: string;
74
+ /** Per-member engine override; default: engineOptions with loop/extract routed at the member. */
75
+ engineFor?: (member: {
76
+ model: `${string}:${string}`;
77
+ effort?: string;
78
+ }) => unknown;
79
+ }
80
+ /** Loads `rulvar.config.mjs`/`.js` from cwd; absent config is fine. */
81
+ declare function loadCliConfig(cwd: string): Promise<CliConfig>;
82
+ interface LoadedWorkflowModule {
83
+ workflow?: Workflow<never, unknown>;
84
+ engineOptions?: Partial<CreateEngineOptions>;
85
+ workflows?: WorkflowRegistry;
86
+ }
87
+ /** Imports a workflow module given on the command line. */
88
+ declare function loadWorkflowModule(file: string, cwd: string): Promise<LoadedWorkflowModule>;
89
+ /** True when the `run` target names a file rather than a registry entry. */
90
+ declare function looksLikeFile(target: string): boolean;
91
+ //#endregion
92
+ //#region src/engine-assembly.d.ts
93
+ declare const DEFAULT_STORE_DIR = ".rulvar";
94
+ interface AssembledCli {
95
+ engine: Engine;
96
+ store: JournalStore;
97
+ workflows: WorkflowRegistry;
98
+ /** The journal-fold price function (table wins over caps; docs/04, section 10). */
99
+ priceUsd: (servedBy: ModelRef, usage: Usage) => number | undefined;
100
+ }
101
+ declare function assembleEngine(options: {
102
+ config: CliConfig;
103
+ module?: LoadedWorkflowModule;
104
+ storePath?: string;
105
+ profile?: string;
106
+ cwd: string;
107
+ }): AssembledCli;
108
+ //#endregion
109
+ //#region src/drive.d.ts
110
+ /**
111
+ * Drives a handle to a terminal outcome, resolving suspensions
112
+ * interactively and resuming until the run settles or input runs dry.
113
+ */
114
+ declare function driveRun(options: {
115
+ engine: Engine;
116
+ workflow: Workflow<never, unknown>;
117
+ first: RunHandle<unknown>;
118
+ io: CliIo; /** Original run arguments: not journaled in v1, the host re-supplies them (docs/14). */
119
+ args?: unknown;
120
+ }): Promise<RunOutcome<unknown>>;
121
+ /** Renders the settled outcome; returns the process exit code. */
122
+ declare function reportOutcome(outcome: RunOutcome<unknown>, io: CliIo): number;
123
+ //#endregion
124
+ //#region src/server.d.ts
125
+ interface CreateServerOptions {
126
+ engine: Engine;
127
+ /** The explicit, first-class registry (docs/06, section 10.4). */
128
+ workflows: WorkflowRegistry;
129
+ /**
130
+ * Prices the journal fold behind GET /runs/:id/cost for runs without a
131
+ * settled in-process outcome (the host assembles pricing exactly as it
132
+ * does for the CLI); absent means those usages surface as `unpriced`,
133
+ * never a silent zero (docs/04, section 10).
134
+ */
135
+ priceUsd?: (servedBy: ModelRef, usage: Usage) => number | undefined;
136
+ /**
137
+ * Opt-in retention (docs/02, 8.2; OQ-20 executed at M8-T04): evaluated
138
+ * when a tracked run settles terminally; a true verdict applies
139
+ * engine.deleteRun (transcript cascade, then the journal) and
140
+ * untracks the run. Absent means everything persists indefinitely.
141
+ */
142
+ retention?: (meta: RunMeta) => boolean;
143
+ }
144
+ interface RulvarServer {
145
+ fetch(req: Request): Promise<Response>;
146
+ }
147
+ declare function createServer(options: CreateServerOptions): RulvarServer;
148
+ //#endregion
149
+ //#region src/worker.d.ts
150
+ /** Appendix A: the committed reference lease ttl (docs/06). */
151
+ declare const DEFAULT_WORKER_TTL_MS = 6e4;
152
+ interface CreateWorkerOptions {
153
+ /**
154
+ * The LeasableStore to lease runs from; MUST be the same journal the
155
+ * engine writes (Engine.stores.journal), or the fencing epoch would
156
+ * protect a store nobody appends to. Verified at start.
157
+ */
158
+ store: LeasableStore;
159
+ /** Appendix A: leased runs per worker process; default 1. */
160
+ concurrency?: number;
161
+ /** Lease owner id; defaults to a per-process identity. */
162
+ owner?: string;
163
+ /**
164
+ * The store's lease ttl; the worker renews at ttl/3 (the normative
165
+ * bound, docs/03 12.3). Default: the Appendix A reference 60000 ms.
166
+ * MUST match the store's configured ttl.
167
+ */
168
+ ttlMs?: number;
169
+ /** Idle sweep cadence for start(); default 1000 ms. */
170
+ pollMs?: number;
171
+ /**
172
+ * The OQ-21 interim channel: original in-process run arguments are not
173
+ * journaled in v1, so the host re-supplies them per run. Absent means
174
+ * args resume as undefined (fully replayed prefixes never notice).
175
+ */
176
+ argsFor?: (meta: RunMeta) => unknown;
177
+ /** DEF-6 window extension, in lockstep with the engine assembly. */
178
+ extraDerivers?: KeyDeriver[];
179
+ /** Observability hook for per-run failures; never throws into the loop. */
180
+ onError?: (runId: string, error: unknown) => void;
181
+ /**
182
+ * Opt-in retention (docs/02, 8.3; OQ-20 executed at M8-T04): evaluated
183
+ * during sweeps over SETTLED runs (terminal meta); a true verdict
184
+ * applies engine.deleteRun under a briefly held lease. Absent means
185
+ * everything persists indefinitely.
186
+ */
187
+ retention?: (meta: RunMeta) => boolean;
188
+ }
189
+ interface Worker {
190
+ /** Begins sweeping on the poll cadence. Idempotent. */
191
+ start(): void;
192
+ /**
193
+ * One sweep: lease and resume eligible runs up to the concurrency
194
+ * cap. Returns the number of runs picked up. Exposed so hosts and
195
+ * tests can drive the worker deterministically without timers.
196
+ */
197
+ sweep(): Promise<number>;
198
+ /** Stops sweeping, cancels in-flight runs, releases held leases. */
199
+ stop(): Promise<void>;
200
+ /** runIds currently held by this worker. */
201
+ active(): string[];
202
+ }
203
+ declare function createWorker(engine: Engine, options: CreateWorkerOptions): Worker;
204
+ //#endregion
205
+ //#region src/tui.d.ts
206
+ /** Renders one event to a line, or undefined for silent event types. */
207
+ declare function renderEventLine(event: WorkflowEvent): string | undefined;
208
+ /** Attaches the renderer to a handle's event stream; returns a detach. */
209
+ declare function attachProgress(handle: RunHandle<unknown>, io: CliIo): () => void;
210
+ //#endregion
211
+ //#region src/otel.d.ts
212
+ /** The tiny subset of the OTel Tracer/Span API the exporter uses. */
213
+ interface SpanLike {
214
+ setAttribute(key: string, value: string | number | boolean): void;
215
+ addEvent(name: string, attributes?: Record<string, string | number | boolean>): void;
216
+ setStatus(status: {
217
+ code: number;
218
+ message?: string;
219
+ }): void;
220
+ end(endTime?: number): void;
221
+ }
222
+ interface TracerLike {
223
+ startSpan(name: string, options?: {
224
+ startTime?: number;
225
+ attributes?: Record<string, string | number | boolean>;
226
+ }, context?: unknown): SpanLike;
227
+ }
228
+ /** Minimal OTel context surface (setSpan/with) for parentage. */
229
+ interface OtelContextApi {
230
+ active(): unknown;
231
+ with<T>(context: unknown, fn: () => T): T;
232
+ }
233
+ interface ToOtelOptions {
234
+ /** OTel context API for parentage; when absent, spans are flat but attributed. */
235
+ contextApi?: OtelContextApi;
236
+ /** trace.setSpan(context, span) equivalent; required with contextApi. */
237
+ setSpan?: (context: unknown, span: SpanLike) => unknown;
238
+ }
239
+ /**
240
+ * Exports one settled run's event stream onto a tracer. The run's
241
+ * events are consumed in seq order; span openers start spans, the
242
+ * matching closers end them, and payload-only events attach as span
243
+ * events on the innermost open span. Returns the number of spans
244
+ * created.
245
+ */
246
+ declare function toOtel(run: {
247
+ runId: string;
248
+ events: AsyncIterable<WorkflowEvent>;
249
+ result: Promise<RunOutcome<unknown>>;
250
+ }, tracer: TracerLike, options?: ToOtelOptions): Promise<number>;
251
+ //#endregion
252
+ export { type AssembledCli, type CliConfig, type CliIo, type CommandContext, type CreateServerOptions, type CreateWorkerOptions, DEFAULT_STORE_DIR, DEFAULT_WORKER_TTL_MS, HELP, type RulvarServer, type SpanLike, type ToOtelOptions, type TracerLike, type Worker, assembleEngine, attachProgress, createServer, createWorker, driveRun, inspectCommand, loadCliConfig, loadWorkflowModule, looksLikeFile, processIo, renderEventLine, reportOutcome, resumeCommand, runCli, runCommand, runsLsCommand, toOtel };