@riddledc/riddle-proof 0.1.0 → 0.2.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.
package/dist/index.cjs CHANGED
@@ -33,6 +33,7 @@ __export(index_exports, {
33
33
  normalizeRunParams: () => normalizeRunParams,
34
34
  normalizeTerminalMetadata: () => normalizeTerminalMetadata,
35
35
  recordValue: () => recordValue,
36
+ runRiddleProof: () => runRiddleProof,
36
37
  setRunStatus: () => setRunStatus
37
38
  });
38
39
  module.exports = __toCommonJS(index_exports);
@@ -200,6 +201,401 @@ function setRunStatus(state, status, at = timestamp()) {
200
201
  state.updated_at = at;
201
202
  return state;
202
203
  }
204
+
205
+ // src/runner.ts
206
+ function errorDetails(error) {
207
+ if (error instanceof Error) {
208
+ return {
209
+ name: error.name,
210
+ message: error.message
211
+ };
212
+ }
213
+ return { message: String(error) };
214
+ }
215
+ function adapterBlocker(code, message, checkpoint, details) {
216
+ return {
217
+ code,
218
+ message,
219
+ checkpoint,
220
+ details
221
+ };
222
+ }
223
+ function blockRun(input) {
224
+ input.state.blocker = input.blocker;
225
+ appendRunEvent(input.state, {
226
+ kind: "run.blocked",
227
+ checkpoint: input.blocker.checkpoint,
228
+ stage: input.stage,
229
+ summary: input.blocker.message,
230
+ details: {
231
+ code: input.blocker.code,
232
+ ...input.blocker.details
233
+ }
234
+ });
235
+ setRunStatus(input.state, "blocked");
236
+ return createRunResult({
237
+ state: input.state,
238
+ status: "blocked",
239
+ last_summary: input.blocker.message,
240
+ evidence_bundle: input.evidence_bundle,
241
+ raw: input.raw
242
+ });
243
+ }
244
+ function shouldIterate(assessment) {
245
+ const nextStage = assessment.continue_with_stage || assessment.recommended_stage;
246
+ return nextStage === "implement" || nextStage === "author";
247
+ }
248
+ async function notifyIfConfigured(input) {
249
+ if (!input.notification) return input.result;
250
+ try {
251
+ const notification = await input.notification.notify({
252
+ state: input.state,
253
+ result: input.result
254
+ });
255
+ input.state.notification = notification;
256
+ appendRunEvent(input.state, {
257
+ kind: "notification.completed",
258
+ checkpoint: "notification_completed",
259
+ stage: "notify",
260
+ summary: "Integration notification completed."
261
+ });
262
+ } catch (error) {
263
+ appendRunEvent(input.state, {
264
+ kind: "notification.failed",
265
+ checkpoint: "notification_failed",
266
+ stage: "notify",
267
+ summary: "Integration notification failed.",
268
+ details: errorDetails(error)
269
+ });
270
+ }
271
+ return createRunResult({
272
+ state: input.state,
273
+ status: input.state.status,
274
+ last_summary: input.result.last_summary,
275
+ evidence_bundle: input.result.evidence_bundle,
276
+ raw: input.result.raw
277
+ });
278
+ }
279
+ async function runRiddleProof(input) {
280
+ const state = input.state || createRunState({
281
+ request: input.request,
282
+ state_path: input.state_path
283
+ });
284
+ const adapters = input.adapters || {};
285
+ const maxIterations = Math.max(1, Math.trunc(input.max_iterations ?? 1));
286
+ appendRunEvent(state, {
287
+ kind: "run.started",
288
+ checkpoint: "run_started",
289
+ stage: "setup",
290
+ summary: "Riddle Proof run started.",
291
+ details: {
292
+ max_iterations: maxIterations,
293
+ ship_mode: state.request.ship_mode || "none"
294
+ }
295
+ });
296
+ let workdir = input.workdir;
297
+ let evidenceContext;
298
+ if (adapters.setup) {
299
+ appendRunEvent(state, {
300
+ kind: "setup.started",
301
+ checkpoint: "setup_started",
302
+ stage: "setup",
303
+ summary: "Riddle Proof setup adapter started."
304
+ });
305
+ try {
306
+ const setup = await adapters.setup.setup({ request: state.request, state });
307
+ if (!setup.ok) {
308
+ return blockRun({
309
+ state,
310
+ stage: "setup",
311
+ blocker: adapterBlocker(
312
+ "setup_failed",
313
+ "The setup adapter did not complete successfully.",
314
+ "setup_failed",
315
+ { blockers: setup.blockers }
316
+ ),
317
+ raw: { setup }
318
+ });
319
+ }
320
+ workdir = setup.workdir || workdir;
321
+ evidenceContext = setup.evidence_context;
322
+ appendRunEvent(state, {
323
+ kind: "setup.completed",
324
+ checkpoint: "setup_completed",
325
+ stage: "setup",
326
+ summary: "Riddle Proof setup adapter completed.",
327
+ details: {
328
+ has_workdir: Boolean(workdir),
329
+ has_evidence_context: Boolean(evidenceContext)
330
+ }
331
+ });
332
+ } catch (error) {
333
+ return blockRun({
334
+ state,
335
+ stage: "setup",
336
+ blocker: adapterBlocker("setup_exception", "The setup adapter threw an exception.", "setup_failed", errorDetails(error))
337
+ });
338
+ }
339
+ }
340
+ const changeRequest = state.request.change_request?.trim();
341
+ if (!changeRequest) {
342
+ return blockRun({
343
+ state,
344
+ stage: "setup",
345
+ blocker: adapterBlocker("change_request_required", "A change request is required before implementation.", "request_invalid")
346
+ });
347
+ }
348
+ if (!workdir) {
349
+ return blockRun({
350
+ state,
351
+ stage: "setup",
352
+ blocker: adapterBlocker("workdir_not_configured", "A workdir or setup adapter result is required before implementation.", "setup_required")
353
+ });
354
+ }
355
+ if (!adapters.implementation) {
356
+ return blockRun({
357
+ state,
358
+ stage: "implement",
359
+ blocker: adapterBlocker("implementation_adapter_not_configured", "An implementation adapter is required to change code.", "implementation_required")
360
+ });
361
+ }
362
+ if (!adapters.proof) {
363
+ return blockRun({
364
+ state,
365
+ stage: "prove",
366
+ blocker: adapterBlocker("proof_adapter_not_configured", "A proof adapter is required to capture evidence.", "proof_required")
367
+ });
368
+ }
369
+ if (!adapters.judge) {
370
+ return blockRun({
371
+ state,
372
+ stage: "verify",
373
+ blocker: adapterBlocker("judge_adapter_not_configured", "A judge adapter is required to assess proof.", "judge_required")
374
+ });
375
+ }
376
+ let implementation;
377
+ let evidenceBundle;
378
+ let assessment;
379
+ for (let attempt = 0; attempt < maxIterations; attempt += 1) {
380
+ state.iterations += 1;
381
+ appendRunEvent(state, {
382
+ kind: "implementation.started",
383
+ checkpoint: "implementation_started",
384
+ stage: "implement",
385
+ summary: "Implementation adapter started.",
386
+ details: { iteration: state.iterations }
387
+ });
388
+ try {
389
+ implementation = await adapters.implementation.implement({
390
+ workdir,
391
+ change_request: changeRequest,
392
+ evidence_context: evidenceContext,
393
+ state
394
+ });
395
+ } catch (error) {
396
+ return blockRun({
397
+ state,
398
+ stage: "implement",
399
+ blocker: adapterBlocker("implementation_exception", "The implementation adapter threw an exception.", "implementation_failed", errorDetails(error)),
400
+ evidence_bundle: evidenceBundle
401
+ });
402
+ }
403
+ if (!implementation.ok) {
404
+ return blockRun({
405
+ state,
406
+ stage: "implement",
407
+ blocker: adapterBlocker(
408
+ "implementation_failed",
409
+ "The implementation adapter did not complete successfully.",
410
+ "implementation_failed",
411
+ { blockers: implementation.blockers }
412
+ ),
413
+ evidence_bundle: evidenceBundle,
414
+ raw: { implementation }
415
+ });
416
+ }
417
+ appendRunEvent(state, {
418
+ kind: "implementation.completed",
419
+ checkpoint: "implementation_completed",
420
+ stage: "implement",
421
+ summary: "Implementation adapter completed.",
422
+ details: {
423
+ changed_files: implementation.changed_files,
424
+ tests_run: implementation.tests_run
425
+ }
426
+ });
427
+ appendRunEvent(state, {
428
+ kind: "proof.started",
429
+ checkpoint: "proof_started",
430
+ stage: "prove",
431
+ summary: "Proof adapter started."
432
+ });
433
+ try {
434
+ const proof = await adapters.proof.prove({
435
+ state,
436
+ implementation,
437
+ evidence_context: evidenceContext
438
+ });
439
+ if (!proof.ok || !proof.evidence_bundle) {
440
+ return blockRun({
441
+ state,
442
+ stage: "prove",
443
+ blocker: adapterBlocker(
444
+ "proof_failed",
445
+ "The proof adapter did not produce a usable evidence bundle.",
446
+ "proof_failed",
447
+ { blockers: proof.blockers }
448
+ ),
449
+ raw: { proof }
450
+ });
451
+ }
452
+ evidenceBundle = proof.evidence_bundle;
453
+ appendRunEvent(state, {
454
+ kind: "proof.completed",
455
+ checkpoint: "proof_completed",
456
+ stage: "prove",
457
+ summary: "Proof adapter completed.",
458
+ details: {
459
+ verification_mode: evidenceBundle.verification_mode,
460
+ artifact_count: evidenceBundle.artifacts?.length ?? 0
461
+ }
462
+ });
463
+ } catch (error) {
464
+ return blockRun({
465
+ state,
466
+ stage: "prove",
467
+ blocker: adapterBlocker("proof_exception", "The proof adapter threw an exception.", "proof_failed", errorDetails(error))
468
+ });
469
+ }
470
+ appendRunEvent(state, {
471
+ kind: "judge.started",
472
+ checkpoint: "judge_started",
473
+ stage: "verify",
474
+ summary: "Judge adapter started."
475
+ });
476
+ try {
477
+ assessment = await adapters.judge.assessProof({ state, evidence_bundle: evidenceBundle });
478
+ state.proof_decision = assessment.decision;
479
+ appendRunEvent(state, {
480
+ kind: "judge.completed",
481
+ checkpoint: "judge_completed",
482
+ stage: "verify",
483
+ summary: assessment.summary,
484
+ details: {
485
+ decision: assessment.decision,
486
+ recommended_stage: assessment.recommended_stage,
487
+ continue_with_stage: assessment.continue_with_stage,
488
+ reasons: assessment.reasons
489
+ }
490
+ });
491
+ } catch (error) {
492
+ return blockRun({
493
+ state,
494
+ stage: "verify",
495
+ blocker: adapterBlocker("judge_exception", "The judge adapter threw an exception.", "judge_failed", errorDetails(error)),
496
+ evidence_bundle: evidenceBundle
497
+ });
498
+ }
499
+ if (assessment.decision === "ready_to_ship") break;
500
+ if (attempt + 1 < maxIterations && shouldIterate(assessment)) {
501
+ evidenceContext = evidenceBundle;
502
+ appendRunEvent(state, {
503
+ kind: "run.iterating",
504
+ checkpoint: "iteration_requested",
505
+ stage: "implement",
506
+ summary: "Judge requested another implementation iteration.",
507
+ details: {
508
+ decision: assessment.decision,
509
+ next_iteration: state.iterations + 1
510
+ }
511
+ });
512
+ continue;
513
+ }
514
+ return blockRun({
515
+ state,
516
+ stage: "verify",
517
+ blocker: adapterBlocker(
518
+ "proof_not_ready",
519
+ assessment.summary || "Proof is not ready to ship.",
520
+ "judge_completed",
521
+ {
522
+ decision: assessment.decision,
523
+ recommended_stage: assessment.recommended_stage,
524
+ continue_with_stage: assessment.continue_with_stage,
525
+ reasons: assessment.reasons
526
+ }
527
+ ),
528
+ evidence_bundle: evidenceBundle,
529
+ raw: { assessment }
530
+ });
531
+ }
532
+ if (!assessment || !evidenceBundle) {
533
+ return blockRun({
534
+ state,
535
+ stage: "verify",
536
+ blocker: adapterBlocker("runner_incomplete", "The runner ended without proof assessment.", "runner_incomplete")
537
+ });
538
+ }
539
+ if (state.request.ship_mode !== "ship") {
540
+ setRunStatus(state, "ready_to_ship");
541
+ const result2 = createRunResult({
542
+ state,
543
+ status: "ready_to_ship",
544
+ last_summary: assessment.summary,
545
+ evidence_bundle: evidenceBundle,
546
+ raw: { implementation, assessment }
547
+ });
548
+ return notifyIfConfigured({ state, result: result2, notification: adapters.notification });
549
+ }
550
+ if (!adapters.ship) {
551
+ return blockRun({
552
+ state,
553
+ stage: "ship",
554
+ blocker: adapterBlocker("ship_adapter_not_configured", "A ship adapter is required when ship_mode is ship.", "ship_required"),
555
+ evidence_bundle: evidenceBundle,
556
+ raw: { implementation, assessment }
557
+ });
558
+ }
559
+ appendRunEvent(state, {
560
+ kind: "ship.started",
561
+ checkpoint: "ship_started",
562
+ stage: "ship",
563
+ summary: "Ship adapter started."
564
+ });
565
+ let metadata;
566
+ try {
567
+ metadata = await adapters.ship.ship({ state, assessment });
568
+ } catch (error) {
569
+ return blockRun({
570
+ state,
571
+ stage: "ship",
572
+ blocker: adapterBlocker("ship_exception", "The ship adapter threw an exception.", "ship_failed", errorDetails(error)),
573
+ evidence_bundle: evidenceBundle,
574
+ raw: { implementation, assessment }
575
+ });
576
+ }
577
+ appendRunEvent(state, {
578
+ kind: "ship.completed",
579
+ checkpoint: "ship_completed",
580
+ stage: "ship",
581
+ summary: "Ship adapter completed.",
582
+ details: {
583
+ pr_url: metadata.pr_url,
584
+ marked_ready: metadata.marked_ready,
585
+ finalized: metadata.finalized
586
+ }
587
+ });
588
+ setRunStatus(state, "shipped");
589
+ const result = createRunResult({
590
+ state,
591
+ status: "shipped",
592
+ last_summary: "Riddle Proof shipped.",
593
+ metadata,
594
+ evidence_bundle: evidenceBundle,
595
+ raw: { implementation, assessment }
596
+ });
597
+ return notifyIfConfigured({ state, result, notification: adapters.notification });
598
+ }
203
599
  // Annotate the CommonJS export names for ESM import in node:
204
600
  0 && (module.exports = {
205
601
  RIDDLE_PROOF_RUN_STATE_VERSION,
@@ -215,5 +611,6 @@ function setRunStatus(state, status, at = timestamp()) {
215
611
  normalizeRunParams,
216
612
  normalizeTerminalMetadata,
217
613
  recordValue,
614
+ runRiddleProof,
218
615
  setRunStatus
219
616
  });
package/dist/index.d.cts CHANGED
@@ -1,3 +1,4 @@
1
- export { EvidenceArtifact, EvidenceReference, ImplementationAdapter, ImplementationAdapterInput, ImplementationAdapterResult, IntegrationContext, JsonObject, JsonPrimitive, JsonValue, JudgeAdapter, NotificationAdapter, RiddleProofAssessment, RiddleProofBlocker, RiddleProofDecision, RiddleProofEvent, RiddleProofEvidenceBundle, RiddleProofRunParams, RiddleProofRunResult, RiddleProofRunState, RiddleProofStage, RiddleProofStatus, RiddleProofTerminalMetadata, RiddleProofVerificationMode, ShipAdapter } from './types.cjs';
1
+ export { EvidenceArtifact, EvidenceReference, ImplementationAdapter, ImplementationAdapterInput, ImplementationAdapterResult, IntegrationContext, JsonObject, JsonPrimitive, JsonValue, JudgeAdapter, NotificationAdapter, ProofAdapter, ProofAdapterInput, ProofAdapterResult, RiddleProofAssessment, RiddleProofBlocker, RiddleProofDecision, RiddleProofEvent, RiddleProofEvidenceBundle, RiddleProofRunParams, RiddleProofRunResult, RiddleProofRunState, RiddleProofStage, RiddleProofStatus, RiddleProofTerminalMetadata, RiddleProofVerificationMode, SetupAdapter, SetupAdapterInput, SetupAdapterResult, ShipAdapter } from './types.cjs';
2
2
  export { TerminalMetadataInput, applyTerminalMetadata, compactRecord, createRunResult, isSuccessfulStatus, isTerminalStatus, nonEmptyString, normalizeTerminalMetadata, recordValue } from './result.cjs';
3
3
  export { CreateRunStateInput, RIDDLE_PROOF_RUN_STATE_VERSION, RunEventInput, appendRunEvent, createRunState, normalizeIntegrationContext, normalizeRunParams, setRunStatus } from './state.cjs';
4
+ export { RiddleProofRunnerAdapters, RunRiddleProofInput, runRiddleProof } from './runner.cjs';
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
- export { EvidenceArtifact, EvidenceReference, ImplementationAdapter, ImplementationAdapterInput, ImplementationAdapterResult, IntegrationContext, JsonObject, JsonPrimitive, JsonValue, JudgeAdapter, NotificationAdapter, RiddleProofAssessment, RiddleProofBlocker, RiddleProofDecision, RiddleProofEvent, RiddleProofEvidenceBundle, RiddleProofRunParams, RiddleProofRunResult, RiddleProofRunState, RiddleProofStage, RiddleProofStatus, RiddleProofTerminalMetadata, RiddleProofVerificationMode, ShipAdapter } from './types.js';
1
+ export { EvidenceArtifact, EvidenceReference, ImplementationAdapter, ImplementationAdapterInput, ImplementationAdapterResult, IntegrationContext, JsonObject, JsonPrimitive, JsonValue, JudgeAdapter, NotificationAdapter, ProofAdapter, ProofAdapterInput, ProofAdapterResult, RiddleProofAssessment, RiddleProofBlocker, RiddleProofDecision, RiddleProofEvent, RiddleProofEvidenceBundle, RiddleProofRunParams, RiddleProofRunResult, RiddleProofRunState, RiddleProofStage, RiddleProofStatus, RiddleProofTerminalMetadata, RiddleProofVerificationMode, SetupAdapter, SetupAdapterInput, SetupAdapterResult, ShipAdapter } from './types.js';
2
2
  export { TerminalMetadataInput, applyTerminalMetadata, compactRecord, createRunResult, isSuccessfulStatus, isTerminalStatus, nonEmptyString, normalizeTerminalMetadata, recordValue } from './result.js';
3
3
  export { CreateRunStateInput, RIDDLE_PROOF_RUN_STATE_VERSION, RunEventInput, appendRunEvent, createRunState, normalizeIntegrationContext, normalizeRunParams, setRunStatus } from './state.js';
4
+ export { RiddleProofRunnerAdapters, RunRiddleProofInput, runRiddleProof } from './runner.js';
package/dist/index.js CHANGED
@@ -1,3 +1,6 @@
1
+ import {
2
+ runRiddleProof
3
+ } from "./chunk-GWGXPNON.js";
1
4
  import {
2
5
  RIDDLE_PROOF_RUN_STATE_VERSION,
3
6
  appendRunEvent,
@@ -31,5 +34,6 @@ export {
31
34
  normalizeRunParams,
32
35
  normalizeTerminalMetadata,
33
36
  recordValue,
37
+ runRiddleProof,
34
38
  setRunStatus
35
39
  };