@probelabs/probe 0.6.0-rc335 → 0.6.0-rc336

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.
@@ -2503,7 +2503,10 @@ export class ProbeAgent {
2503
2503
  }
2504
2504
  return this.engine;
2505
2505
  } catch (error) {
2506
- if (this.governedCodexProfile) throw error;
2506
+ if (this.governedCodexProfile) {
2507
+ throw normalizeGovernedAnswerFailure(error, 'provider_engine', null, null, null,
2508
+ null, null, 'acquire');
2509
+ }
2507
2510
  console.warn('[WARNING] Failed to load Codex CLI engine:', error.message);
2508
2511
  console.warn('[WARNING] Falling back to Vercel AI SDK');
2509
2512
  this.clientApiProvider = null;
@@ -3530,8 +3533,11 @@ Follow these instructions carefully:
3530
3533
  let engine, answerFailure = null;
3531
3534
  try {
3532
3535
  try { engine = await this.getEngine(); }
3533
- catch { throw governedAnswerFailure('provider_engine'); }
3534
- if (!engine?.query) throw governedAnswerFailure('provider_engine');
3536
+ catch (error) {
3537
+ throw normalizeGovernedAnswerFailure(error, 'provider_engine', null, null, null,
3538
+ null, null, 'acquire');
3539
+ }
3540
+ if (!engine?.query) throw governedAnswerFailure('internal_contract');
3535
3541
  const candidateChunks = [];
3536
3542
  let runtimeAttestation;
3537
3543
  let attestationCount = 0;
@@ -3540,31 +3546,47 @@ Follow these instructions carefully:
3540
3546
  const queryOptions = hasInvocationDigest
3541
3547
  ? { abortSignal: this._abortController.signal, invocationDigest: invocationDigest }
3542
3548
  : { abortSignal: this._abortController.signal };
3543
- for await (const chunk of engine.query(prompt, queryOptions)) {
3544
- if (chunk.type === 'text' && chunk.content) candidateChunks.push(chunk.content);
3545
- else if (chunk.type === 'metadata' && chunk.data?.attestation) {
3546
- runtimeAttestation = chunk.data.attestation;
3547
- attestationCount++;
3548
- } else if (chunk.type === 'toolBatch') {
3549
- nativeToolBatch = chunk;
3550
- nativeToolBatchCount++;
3551
- } else if (chunk.type === 'error') throw normalizeGovernedAnswerFailure(chunk.error, 'unknown');
3549
+ try {
3550
+ for await (const chunk of engine.query(prompt, queryOptions)) {
3551
+ if (chunk.type === 'text' && chunk.content) candidateChunks.push(chunk.content);
3552
+ else if (chunk.type === 'metadata' && chunk.data?.attestation) {
3553
+ runtimeAttestation = chunk.data.attestation;
3554
+ attestationCount++;
3555
+ } else if (chunk.type === 'toolBatch') {
3556
+ nativeToolBatch = chunk;
3557
+ nativeToolBatchCount++;
3558
+ } else if (chunk.type === 'error') {
3559
+ throw normalizeGovernedAnswerFailure(chunk.error, 'provider_engine', null, null, null,
3560
+ null, null, 'query');
3561
+ }
3562
+ }
3563
+ } catch (error) {
3564
+ throw normalizeGovernedAnswerFailure(error, 'provider_engine', null, null, null,
3565
+ null, null, 'query');
3552
3566
  }
3553
3567
  if (hasInvocationDigest) {
3554
3568
  const expectedAttestation = this.governedCodexProfile?.version === 'probe.governed-codex-profile/v2'
3555
3569
  ? 'probe.governed-codex-attestation/v3' : 'probe.governed-codex-attestation/v2';
3556
3570
  if (attestationCount !== 1 || runtimeAttestation?.version !== expectedAttestation || runtimeAttestation?.executionContext?.source !== 'caller' || runtimeAttestation?.executionContext?.invocationDigest !== invocationDigest) {
3557
- throw new Error('Expected exactly one matching governed invocation attestation');
3571
+ throw governedAnswerFailure('native_event_grammar', 'live_envelope_session', 'attestation', null,
3572
+ 'invocation_attestation');
3558
3573
  }
3559
- } else if (attestationCount !== 1) throw new Error(`Expected exactly one governed runtime attestation; received ${attestationCount}`);
3574
+ } else if (attestationCount !== 1) {
3575
+ throw governedAnswerFailure('native_event_grammar', 'live_envelope_session', 'attestation', null,
3576
+ 'invocation_attestation');
3577
+ }
3560
3578
  if (this.governedCodexProfile?.version === 'probe.governed-codex-profile/v2') {
3561
3579
  if (nativeToolBatchCount !== 1 || !Number.isSafeInteger(nativeToolBatch?.total) ||
3562
3580
  !Array.isArray(nativeToolBatch?.tools) || nativeToolBatch.total !== runtimeAttestation?.observed?.nativeTools?.total ||
3563
3581
  JSON.stringify(nativeToolBatch.tools) !== JSON.stringify(runtimeAttestation?.observed?.nativeTools?.tools)) {
3564
- throw new Error('Expected exactly one matching governed native capability aggregate');
3582
+ throw governedAnswerFailure('native_event_grammar', 'live_envelope_session', 'attestation', null,
3583
+ 'native_capability_aggregate');
3565
3584
  }
3566
3585
  for (const toolEvent of nativeToolBatch.tools) this.events.emit('toolCall', toolEvent);
3567
- } else if (nativeToolBatchCount !== 0) throw new Error('Unexpected governed native capability aggregate');
3586
+ } else if (nativeToolBatchCount !== 0) {
3587
+ throw governedAnswerFailure('native_event_grammar', 'live_envelope_session', 'attestation', null,
3588
+ 'native_capability_aggregate');
3589
+ }
3568
3590
  const validation = validateJsonResponse(candidateChunks.join(''), {debug:this.debug,schema});
3569
3591
  if (!validation.isValid) throw governedSchemaResultValidationFailure(validation);
3570
3592
  if (hasResultIdentity) {
@@ -3577,12 +3599,15 @@ Follow these instructions carefully:
3577
3599
  }
3578
3600
  return { data: validation.parsed, runtimeAttestation };
3579
3601
  } catch (error) {
3580
- answerFailure = normalizeGovernedAnswerFailure(error, 'unknown');
3602
+ answerFailure = normalizeGovernedAnswerFailure(error, 'internal_contract');
3581
3603
  throw answerFailure;
3582
3604
  } finally {
3583
3605
  if (engine) {
3584
3606
  try { await engine.close(); }
3585
- catch { if (!answerFailure) throw governedAnswerFailure('unknown'); }
3607
+ catch (error) {
3608
+ if (!answerFailure) throw normalizeGovernedAnswerFailure(error, 'provider_engine', null, null, null,
3609
+ null, null, 'close');
3610
+ }
3586
3611
  }
3587
3612
  }
3588
3613
  }
@@ -461,7 +461,11 @@ export async function createCodexEngine(options = {}) {
461
461
  try { collector.observe(event); } catch (error) { evidenceFailure ??= normalizeGovernedAnswerFailure(error, 'native_event_grammar'); }
462
462
  });
463
463
  if (opts.abortSignal) {
464
- if (opts.abortSignal.aborted) throw new Error('Codex query cancelled');
464
+ if (opts.abortSignal.aborted) {
465
+ throw governedProfile
466
+ ? governedAnswerFailure('provider_engine', null, null, null, null, null, null, 'query')
467
+ : new Error('Codex query cancelled');
468
+ }
465
469
  abortHandler = () => { void cleanup(new Error('Codex query cancelled')).catch(() => {}); };
466
470
  opts.abortSignal.addEventListener('abort', abortHandler, { once: true });
467
471
  }
@@ -501,7 +505,8 @@ export async function createCodexEngine(options = {}) {
501
505
  try { result = await resultPromise; }
502
506
  catch (error) {
503
507
  throw governedProfile
504
- ? governedAnswerFailure(evidenceFailure ? 'unknown' : 'provider_engine')
508
+ ? evidenceFailure || normalizeGovernedAnswerFailure(error, 'provider_engine', null, null, null,
509
+ null, null, 'query')
505
510
  : error;
506
511
  }
507
512
 
@@ -521,20 +526,31 @@ export async function createCodexEngine(options = {}) {
521
526
  internal = attestGovernedCodexSession({ profile: governedProfile,
522
527
  events: governedProfile.version === 'probe.governed-codex-profile/v2'
523
528
  ? [collected.sessionEvent, collected.capabilities.nativeTools] : [collected.sessionEvent] });
529
+ } catch (error) {
530
+ throw normalizeGovernedAnswerFailure(error, 'native_event_grammar', 'live_envelope_session',
531
+ 'attestation');
532
+ }
533
+ try {
524
534
  probeMcpCallCount = governedProfile.version === 'probe.governed-codex-profile/v2'
525
535
  ? governedProbeMcpCallCount(mcpServer?.getGovernedCallEvidence()) : 0;
526
536
  } catch (error) {
527
- throw normalizeGovernedAnswerFailure(error, 'native_event_grammar', 'live_envelope_session', 'attestation');
537
+ throw normalizeGovernedAnswerFailure(error, 'native_event_grammar', 'live_envelope_session',
538
+ 'attestation', null, null, null, null, 'native_capability_aggregate');
539
+ }
540
+ try {
541
+ attestation = hasInvocationDigest
542
+ ? externalBoundReceipt(internal, dispatch, invocationDigest, {
543
+ nativeCallCount: collected.capabilities.nativeTools.total,
544
+ probeMcpCallCount,
545
+ })
546
+ : externalReceipt(internal, {
547
+ nativeCallCount: collected.capabilities.nativeTools.total,
548
+ probeMcpCallCount,
549
+ });
550
+ } catch (error) {
551
+ throw normalizeGovernedAnswerFailure(error, 'native_event_grammar', 'live_envelope_session',
552
+ 'attestation', null, null, null, null, 'invocation_attestation');
528
553
  }
529
- attestation = hasInvocationDigest
530
- ? externalBoundReceipt(internal, dispatch, invocationDigest, {
531
- nativeCallCount: collected.capabilities.nativeTools.total,
532
- probeMcpCallCount,
533
- })
534
- : externalReceipt(internal, {
535
- nativeCallCount: collected.capabilities.nativeTools.total,
536
- probeMcpCallCount,
537
- });
538
554
  session.setConversationId(collected.sessionEvent.params.msg.session_id);
539
555
  }
540
556
 
@@ -576,7 +592,7 @@ export async function createCodexEngine(options = {}) {
576
592
  };
577
593
 
578
594
  } catch (error) {
579
- if (governedProfile) error = normalizeGovernedAnswerFailure(error, 'unknown');
595
+ if (governedProfile) error = normalizeGovernedAnswerFailure(error, 'internal_contract');
580
596
  queryError = error;
581
597
  if (debug) {
582
598
  console.error('[DEBUG] Codex query error:', error);
@@ -589,7 +605,10 @@ export async function createCodexEngine(options = {}) {
589
605
  if (opts.abortSignal && abortHandler) opts.abortSignal.removeEventListener('abort', abortHandler);
590
606
  if (governedProfile) {
591
607
  try { await cleanup(); }
592
- catch (cleanupError) { if (!queryError) throw cleanupError; }
608
+ catch (cleanupError) {
609
+ if (!queryError) throw normalizeGovernedAnswerFailure(cleanupError, 'provider_engine', null, null,
610
+ null, null, null, 'close');
611
+ }
593
612
  }
594
613
  }
595
614
  },
@@ -1,6 +1,7 @@
1
1
  const GOVERNED_ANSWER_FAILURE_STAGES = new Set([
2
- 'native_event_grammar', 'provider_engine', 'schema_result_validation', 'unknown',
2
+ 'native_event_grammar', 'provider_engine', 'schema_result_validation', 'internal_contract', 'unknown',
3
3
  ]);
4
+ const GOVERNED_PROVIDER_ENGINE_FAILURE_BOUNDARIES = new Set(['acquire', 'query', 'close']);
4
5
  const GOVERNED_NATIVE_EVENT_FAILURE_BOUNDARIES = new Set([
5
6
  'raw_item_predicate', 'live_envelope_session',
6
7
  ]);
@@ -17,6 +18,7 @@ const GOVERNED_NATIVE_EVENT_FAILURE_ATTESTATION_PREDICATES = new Set([
17
18
  'network',
18
19
  'filesystem_shape', 'filesystem_type', 'entries', 'entry', 'access', 'path_shape',
19
20
  'path_type', 'value_shape', 'kind', 'native_tool_evidence', 'internal_contract',
21
+ 'invocation_attestation', 'native_capability_aggregate',
20
22
  ]);
21
23
  const GOVERNED_SCHEMA_RESULT_VALIDATION_SUBREASONS = new Set([
22
24
  'response_json', 'schema_definition', 'schema_mismatch', 'result_identity',
@@ -73,7 +75,8 @@ function governedAttestationPredicate(error) {
73
75
  export class GovernedAnswerFailure extends Error {
74
76
  constructor(stage, nativeEventFailureBoundary = null, nativeEventFailureSubreason = null,
75
77
  nativeEventFailureCorrelationOperand = null, nativeEventFailureAttestationPredicate = null,
76
- schemaResultValidationSubreason = null, schemaResultValidationKeyword = null) {
78
+ schemaResultValidationSubreason = null, schemaResultValidationKeyword = null,
79
+ providerEngineFailureBoundary = null) {
77
80
  super();
78
81
  delete this.stack;
79
82
  const answerFailureStage = GOVERNED_ANSWER_FAILURE_STAGES.has(stage) ? stage : 'unknown';
@@ -82,6 +85,11 @@ export class GovernedAnswerFailure extends Error {
82
85
  value: answerFailureStage,
83
86
  enumerable: true,
84
87
  });
88
+ if (answerFailureStage === 'provider_engine') Object.defineProperty(this, 'providerEngineFailureBoundary', {
89
+ value: GOVERNED_PROVIDER_ENGINE_FAILURE_BOUNDARIES.has(providerEngineFailureBoundary)
90
+ ? providerEngineFailureBoundary : null,
91
+ enumerable: true,
92
+ });
85
93
  if (answerFailureStage === 'native_event_grammar') Object.defineProperty(this, 'nativeEventFailureBoundary', {
86
94
  value: GOVERNED_NATIVE_EVENT_FAILURE_BOUNDARIES.has(nativeEventFailureBoundary)
87
95
  ? nativeEventFailureBoundary : null,
@@ -134,19 +142,22 @@ export class GovernedAnswerFailure extends Error {
134
142
 
135
143
  export function governedAnswerFailure(stage, nativeEventFailureBoundary = null, nativeEventFailureSubreason = null,
136
144
  nativeEventFailureCorrelationOperand = null, nativeEventFailureAttestationPredicate = null,
137
- schemaResultValidationSubreason = null, schemaResultValidationKeyword = null) {
145
+ schemaResultValidationSubreason = null, schemaResultValidationKeyword = null,
146
+ providerEngineFailureBoundary = null) {
138
147
  return new GovernedAnswerFailure(stage, nativeEventFailureBoundary, nativeEventFailureSubreason,
139
148
  nativeEventFailureCorrelationOperand, nativeEventFailureAttestationPredicate,
140
- schemaResultValidationSubreason, schemaResultValidationKeyword);
149
+ schemaResultValidationSubreason, schemaResultValidationKeyword, providerEngineFailureBoundary);
141
150
  }
142
151
 
143
152
  export function normalizeGovernedAnswerFailure(error, fallback = 'unknown', nativeEventFailureBoundary = null,
144
153
  nativeEventFailureSubreason = null, nativeEventFailureCorrelationOperand = null,
145
- schemaResultValidationSubreason = null, schemaResultValidationKeyword = null) {
154
+ schemaResultValidationSubreason = null, schemaResultValidationKeyword = null,
155
+ providerEngineFailureBoundary = null, nativeEventFailureAttestationPredicate = null) {
146
156
  return error instanceof GovernedAnswerFailure ? error
147
157
  : governedAnswerFailure(fallback, nativeEventFailureBoundary, nativeEventFailureSubreason,
148
158
  nativeEventFailureCorrelationOperand,
149
159
  fallback === 'native_event_grammar' && nativeEventFailureBoundary === 'live_envelope_session' &&
150
- nativeEventFailureSubreason === 'attestation' ? governedAttestationPredicate(error) : null,
151
- schemaResultValidationSubreason, schemaResultValidationKeyword);
160
+ nativeEventFailureSubreason === 'attestation'
161
+ ? nativeEventFailureAttestationPredicate ?? governedAttestationPredicate(error) : null,
162
+ schemaResultValidationSubreason, schemaResultValidationKeyword, providerEngineFailureBoundary);
152
163
  }