@probelabs/probe 0.6.0-rc335 → 0.6.0-rc337

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.
@@ -2488,7 +2488,6 @@ export class ProbeAgent {
2488
2488
  this.engine = await createCodexEngine({
2489
2489
  agent: this, // Pass reference to ProbeAgent for tool access
2490
2490
  systemPrompt: systemPrompt,
2491
- customPrompt: this.customPrompt,
2492
2491
  sessionId: this.options?.sessionId,
2493
2492
  debug: this.debug,
2494
2493
  allowedTools: this.allowedTools, // Pass tool filtering configuration
@@ -2503,7 +2502,10 @@ export class ProbeAgent {
2503
2502
  }
2504
2503
  return this.engine;
2505
2504
  } catch (error) {
2506
- if (this.governedCodexProfile) throw error;
2505
+ if (this.governedCodexProfile) {
2506
+ throw normalizeGovernedAnswerFailure(error, 'provider_engine', null, null, null,
2507
+ null, null, 'acquire');
2508
+ }
2507
2509
  console.warn('[WARNING] Failed to load Codex CLI engine:', error.message);
2508
2510
  console.warn('[WARNING] Falling back to Vercel AI SDK');
2509
2511
  this.clientApiProvider = null;
@@ -3334,7 +3336,7 @@ ${extractGuidance2}
3334
3336
  const { prompt } = this._prepareGovernedAnswerPrompt(message, options);
3335
3337
  const systemPrompt = await this._getCachedCodexNativeSystemPrompt();
3336
3338
  const { previewGovernedCodexInitialDispatch } = await import('./engines/codex.js');
3337
- return previewGovernedCodexInitialDispatch({ systemPrompt, customPrompt: this.customPrompt, prompt });
3339
+ return previewGovernedCodexInitialDispatch({ systemPrompt, prompt });
3338
3340
  }
3339
3341
 
3340
3342
  /**
@@ -3530,8 +3532,11 @@ Follow these instructions carefully:
3530
3532
  let engine, answerFailure = null;
3531
3533
  try {
3532
3534
  try { engine = await this.getEngine(); }
3533
- catch { throw governedAnswerFailure('provider_engine'); }
3534
- if (!engine?.query) throw governedAnswerFailure('provider_engine');
3535
+ catch (error) {
3536
+ throw normalizeGovernedAnswerFailure(error, 'provider_engine', null, null, null,
3537
+ null, null, 'acquire');
3538
+ }
3539
+ if (!engine?.query) throw governedAnswerFailure('internal_contract');
3535
3540
  const candidateChunks = [];
3536
3541
  let runtimeAttestation;
3537
3542
  let attestationCount = 0;
@@ -3540,31 +3545,47 @@ Follow these instructions carefully:
3540
3545
  const queryOptions = hasInvocationDigest
3541
3546
  ? { abortSignal: this._abortController.signal, invocationDigest: invocationDigest }
3542
3547
  : { 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');
3548
+ try {
3549
+ for await (const chunk of engine.query(prompt, queryOptions)) {
3550
+ if (chunk.type === 'text' && chunk.content) candidateChunks.push(chunk.content);
3551
+ else if (chunk.type === 'metadata' && chunk.data?.attestation) {
3552
+ runtimeAttestation = chunk.data.attestation;
3553
+ attestationCount++;
3554
+ } else if (chunk.type === 'toolBatch') {
3555
+ nativeToolBatch = chunk;
3556
+ nativeToolBatchCount++;
3557
+ } else if (chunk.type === 'error') {
3558
+ throw normalizeGovernedAnswerFailure(chunk.error, 'provider_engine', null, null, null,
3559
+ null, null, 'query');
3560
+ }
3561
+ }
3562
+ } catch (error) {
3563
+ throw normalizeGovernedAnswerFailure(error, 'provider_engine', null, null, null,
3564
+ null, null, 'query');
3552
3565
  }
3553
3566
  if (hasInvocationDigest) {
3554
3567
  const expectedAttestation = this.governedCodexProfile?.version === 'probe.governed-codex-profile/v2'
3555
3568
  ? 'probe.governed-codex-attestation/v3' : 'probe.governed-codex-attestation/v2';
3556
3569
  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');
3570
+ throw governedAnswerFailure('native_event_grammar', 'live_envelope_session', 'attestation', null,
3571
+ 'invocation_attestation');
3558
3572
  }
3559
- } else if (attestationCount !== 1) throw new Error(`Expected exactly one governed runtime attestation; received ${attestationCount}`);
3573
+ } else if (attestationCount !== 1) {
3574
+ throw governedAnswerFailure('native_event_grammar', 'live_envelope_session', 'attestation', null,
3575
+ 'invocation_attestation');
3576
+ }
3560
3577
  if (this.governedCodexProfile?.version === 'probe.governed-codex-profile/v2') {
3561
3578
  if (nativeToolBatchCount !== 1 || !Number.isSafeInteger(nativeToolBatch?.total) ||
3562
3579
  !Array.isArray(nativeToolBatch?.tools) || nativeToolBatch.total !== runtimeAttestation?.observed?.nativeTools?.total ||
3563
3580
  JSON.stringify(nativeToolBatch.tools) !== JSON.stringify(runtimeAttestation?.observed?.nativeTools?.tools)) {
3564
- throw new Error('Expected exactly one matching governed native capability aggregate');
3581
+ throw governedAnswerFailure('native_event_grammar', 'live_envelope_session', 'attestation', null,
3582
+ 'native_capability_aggregate');
3565
3583
  }
3566
3584
  for (const toolEvent of nativeToolBatch.tools) this.events.emit('toolCall', toolEvent);
3567
- } else if (nativeToolBatchCount !== 0) throw new Error('Unexpected governed native capability aggregate');
3585
+ } else if (nativeToolBatchCount !== 0) {
3586
+ throw governedAnswerFailure('native_event_grammar', 'live_envelope_session', 'attestation', null,
3587
+ 'native_capability_aggregate');
3588
+ }
3568
3589
  const validation = validateJsonResponse(candidateChunks.join(''), {debug:this.debug,schema});
3569
3590
  if (!validation.isValid) throw governedSchemaResultValidationFailure(validation);
3570
3591
  if (hasResultIdentity) {
@@ -3577,12 +3598,15 @@ Follow these instructions carefully:
3577
3598
  }
3578
3599
  return { data: validation.parsed, runtimeAttestation };
3579
3600
  } catch (error) {
3580
- answerFailure = normalizeGovernedAnswerFailure(error, 'unknown');
3601
+ answerFailure = normalizeGovernedAnswerFailure(error, 'internal_contract');
3581
3602
  throw answerFailure;
3582
3603
  } finally {
3583
3604
  if (engine) {
3584
3605
  try { await engine.close(); }
3585
- catch { if (!answerFailure) throw governedAnswerFailure('unknown'); }
3606
+ catch (error) {
3607
+ if (!answerFailure) throw normalizeGovernedAnswerFailure(error, 'provider_engine', null, null, null,
3608
+ null, null, 'close');
3609
+ }
3586
3610
  }
3587
3611
  }
3588
3612
  }
@@ -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
  }