@probelabs/probe 0.6.0-rc339 → 0.6.0-rc341

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 (30) hide show
  1. package/bin/binaries/{probe-v0.6.0-rc339-x86_64-apple-darwin.tar.gz → probe-v0.6.0-rc341-aarch64-apple-darwin.tar.gz} +0 -0
  2. package/bin/binaries/{probe-v0.6.0-rc339-aarch64-unknown-linux-musl.tar.gz → probe-v0.6.0-rc341-aarch64-unknown-linux-musl.tar.gz} +0 -0
  3. package/bin/binaries/{probe-v0.6.0-rc339-x86_64-pc-windows-msvc.zip → probe-v0.6.0-rc341-x86_64-apple-darwin.tar.gz} +0 -0
  4. package/bin/binaries/probe-v0.6.0-rc341-x86_64-pc-windows-msvc.zip +0 -0
  5. package/bin/binaries/{probe-v0.6.0-rc339-x86_64-unknown-linux-musl.tar.gz → probe-v0.6.0-rc341-x86_64-unknown-linux-musl.tar.gz} +0 -0
  6. package/build/agent/ProbeAgent.d.ts +37 -9
  7. package/build/agent/ProbeAgent.js +196 -62
  8. package/build/agent/acp/tools.js +1 -1
  9. package/build/agent/engines/codex.js +189 -52
  10. package/build/agent/engines/governed-answer-failure.js +164 -5
  11. package/build/agent/engines/governed-codex-exec.js +1227 -0
  12. package/build/agent/engines/governed-codex-profile.js +80 -28
  13. package/build/agent/governance/index.d.ts +18 -0
  14. package/build/agent/governance/index.js +14 -0
  15. package/build/index.js +26 -0
  16. package/cjs/agent/ProbeAgent.cjs +3291 -1117
  17. package/cjs/index.cjs +3318 -1119
  18. package/index.d.ts +53 -7
  19. package/package.json +1 -1
  20. package/src/agent/ProbeAgent.d.ts +37 -9
  21. package/src/agent/ProbeAgent.js +196 -62
  22. package/src/agent/acp/tools.js +1 -1
  23. package/src/agent/engines/codex.js +189 -52
  24. package/src/agent/engines/governed-answer-failure.js +164 -5
  25. package/src/agent/engines/governed-codex-exec.js +1227 -0
  26. package/src/agent/engines/governed-codex-profile.js +80 -28
  27. package/src/agent/governance/index.d.ts +18 -0
  28. package/src/agent/governance/index.js +14 -0
  29. package/src/index.js +26 -0
  30. package/bin/binaries/probe-v0.6.0-rc339-aarch64-apple-darwin.tar.gz +0 -0
@@ -5,6 +5,16 @@ const GOVERNED_PROVIDER_ENGINE_FAILURE_BOUNDARIES = new Set(['acquire', 'query',
5
5
  const GOVERNED_NATIVE_EVENT_FAILURE_BOUNDARIES = new Set([
6
6
  'raw_item_predicate', 'live_envelope_session',
7
7
  ]);
8
+ const GOVERNED_NATIVE_EVENT_FAILURE_RAW_ITEM_PREDICATES = new Set([
9
+ 'shape', 'type', 'id', 'duplicate', 'phase', 'content', 'passthrough',
10
+ 'tool_name_or_allow', 'status', 'input', 'call_output_pairing', 'event_limit', 'tool_event_limit', 'tool_call_limit',
11
+ 'message_content_array', 'message_content_empty', 'message_content_limit', 'message_content_kind',
12
+ 'message_content_text_type', 'message_content_text_limit', 'reasoning_summary_array',
13
+ 'reasoning_summary_nonempty', 'reasoning_encrypted_content_type', 'reasoning_encrypted_content_limit',
14
+ 'tool_output_array', 'tool_output_limit', 'tool_output_kind', 'tool_output_text_type',
15
+ 'tool_output_text_limit',
16
+ 'final_answer_cardinality',
17
+ ]);
8
18
  const GOVERNED_NATIVE_EVENT_FAILURE_SUBREASONS = new Set([
9
19
  'session_sequence', 'envelope_shape', 'correlation', 'attestation',
10
20
  ]);
@@ -27,6 +37,28 @@ const GOVERNED_SCHEMA_RESULT_VALIDATION_KEYWORDS = new Set([
27
37
  'required', 'additionalProperties', 'type', 'pattern', 'enum', 'minItems', 'maxItems',
28
38
  'multiple', 'unknown',
29
39
  ]);
40
+ const GOVERNED_CODEX_EXEC_FAILURE_VERSION = 'probe.governed-codex-exec-failure/v1';
41
+ const GOVERNED_CODEX_EXEC_FAILURE_CODES = new Set([
42
+ 'ANSWER_CARDINALITY', 'CANCELLED', 'CANONICAL', 'CLEANUP', 'CONFIG', 'DUPLICATE', 'EVENT',
43
+ 'EVENT_CATEGORY', 'EVENT_LIMIT', 'EVENT_ORDER', 'INCOMPLETE', 'INCOMPLETE_ITEM', 'ITEM',
44
+ 'ITEM_ORDER', 'ITEM_STATUS', 'JSONL', 'MCP', 'MCP_EVIDENCE', 'ONE_QUERY', 'OUTPUT_OVERFLOW',
45
+ 'SETUP', 'SPAWN', 'TIMEOUT', 'TOOL_POLICY', 'USAGE', 'VERSION', 'EXIT',
46
+ ].map(code => `GOVERNED_CODEX_EXEC_${code}`));
47
+ const GOVERNED_CODEX_EXEC_STDERR_DIGEST = /^sha256:[0-9a-f]{64}$/;
48
+ const GOVERNED_CODEX_EXEC_ITEM_PREDICATES = new Set([
49
+ 'item_keys', 'item_id', 'item_text', 'item_phase', 'item_summary', 'item_server',
50
+ 'item_command', 'item_aggregated_output', 'item_exit_code', 'item_changes', 'item_status',
51
+ 'item_error', 'item_started_payload', 'tool_id',
52
+ ]);
53
+ const GOVERNED_CODEX_EXEC_ITEM_EVENT_TYPES = new Set(['item.started', 'item.completed']);
54
+ const GOVERNED_CODEX_EXEC_FAILURE_EVENT_TYPES = new Set(['error', 'turn.failed']);
55
+ const GOVERNED_CODEX_EXEC_SCHEMA_PROVIDER_ERROR = Object.freeze({
56
+ type: 'invalid_request_error', status: 400, code: 'invalid_json_schema',
57
+ param: 'text.format.schema', schemaKeyword: 'uniqueItems',
58
+ });
59
+ const GOVERNED_CODEX_EXEC_ITEM_TYPES = new Set(['agent_message', 'reasoning', 'mcp_tool_call', 'command_execution', 'file_change']);
60
+ const GOVERNED_CODEX_EXEC_FIELD_TYPES = new Set(['null', 'array', 'object', 'string', 'number', 'boolean']);
61
+ const GOVERNED_CODEX_EXEC_SAFE_FIELD_NAME = /^[A-Za-z_][A-Za-z0-9_.-]{0,63}$/;
30
62
  const GOVERNED_ATTESTATION_ERROR_PREDICATES = new Map([
31
63
  ['Invalid event', 'event_shape'], ['Invalid event.method', 'event_shape'],
32
64
  ['Invalid event.jsonrpc', 'jsonrpc'], ['Invalid event.params', 'params_shape'],
@@ -72,11 +104,117 @@ function governedAttestationPredicate(error) {
72
104
  return error instanceof TypeError ? GOVERNED_ATTESTATION_ERROR_PREDICATES.get(error.message) ?? null : null;
73
105
  }
74
106
 
107
+ function closeRejectedItemFields(value) {
108
+ if (!Array.isArray(value) || value.length > 32) return null;
109
+ let previousName = null;
110
+ const fields = [];
111
+ for (const field of value) {
112
+ if (!field || typeof field !== 'object' || Array.isArray(field)) return null;
113
+ const keys = Object.keys(field);
114
+ if (keys.length < 2 || keys.length > 3 || !keys.includes('name') || !keys.includes('type') ||
115
+ (keys.length === 3 && !keys.includes('size'))) return null;
116
+ const name = ownDataValue(field, 'name');
117
+ const type = ownDataValue(field, 'type');
118
+ if (typeof name !== 'string' || (name !== '<unsafe>' && !GOVERNED_CODEX_EXEC_SAFE_FIELD_NAME.test(name)) ||
119
+ !GOVERNED_CODEX_EXEC_FIELD_TYPES.has(type) || (previousName !== null && name < previousName)) return null;
120
+ const hasSize = Object.prototype.hasOwnProperty.call(field, 'size');
121
+ const size = ownDataValue(field, 'size');
122
+ if (hasSize && (type !== 'string' && type !== 'array' || !Number.isSafeInteger(size) || size < 0)) return null;
123
+ if (!hasSize && (type === 'string' || type === 'array')) return null;
124
+ fields.push(Object.freeze({ name, type, ...(hasSize ? { size } : {}) }));
125
+ previousName = name;
126
+ }
127
+ return Object.freeze(fields);
128
+ }
129
+
130
+ function closeRejectedItemEvent(value) {
131
+ if (!value || typeof value !== 'object' || Array.isArray(value)) return null;
132
+ const keys = Object.keys(value).sort();
133
+ const baseKeys = 'eventFields,eventType,itemFields,itemType,predicate,source';
134
+ const statusKeys = 'eventFields,eventType,itemFields,itemStatus,itemType,predicate,source';
135
+ if (keys.join(',') !== baseKeys && keys.join(',') !== statusKeys) return null;
136
+ const source = ownDataValue(value, 'source');
137
+ const predicate = ownDataValue(value, 'predicate');
138
+ const eventType = ownDataValue(value, 'eventType');
139
+ const itemType = ownDataValue(value, 'itemType');
140
+ const itemStatus = ownDataValue(value, 'itemStatus');
141
+ const eventFields = closeRejectedItemFields(ownDataValue(value, 'eventFields'));
142
+ const itemFields = closeRejectedItemFields(ownDataValue(value, 'itemFields'));
143
+ if (source !== 'codex-exec-rejected-item/v1' || !GOVERNED_CODEX_EXEC_ITEM_PREDICATES.has(predicate) ||
144
+ !GOVERNED_CODEX_EXEC_ITEM_EVENT_TYPES.has(eventType) || !GOVERNED_CODEX_EXEC_ITEM_TYPES.has(itemType) ||
145
+ !eventFields || !itemFields || (itemStatus !== undefined && predicate !== 'item_status') ||
146
+ (itemStatus !== undefined && itemStatus !== 'failed' && itemStatus !== 'declined') ||
147
+ (itemStatus === undefined && keys.includes('itemStatus'))) return null;
148
+ return Object.freeze({ source, predicate, eventType, itemType, eventFields, itemFields,
149
+ ...(itemStatus === undefined ? {} : { itemStatus }) });
150
+ }
151
+
152
+ function closeRejectedFailureEvent(value) {
153
+ if (!value || typeof value !== 'object' || Array.isArray(value)) return null;
154
+ const keys = Object.keys(value).sort();
155
+ const baseKeys = 'category,eventFields,eventType,source';
156
+ const providerKeys = 'category,eventFields,eventType,providerError,source';
157
+ if (keys.join(',') !== baseKeys && keys.join(',') !== providerKeys) return null;
158
+ const source = ownDataValue(value, 'source');
159
+ const category = ownDataValue(value, 'category');
160
+ const eventType = ownDataValue(value, 'eventType');
161
+ const eventFields = closeRejectedItemFields(ownDataValue(value, 'eventFields'));
162
+ const providerError = ownDataValue(value, 'providerError');
163
+ const providerErrorKeys = providerError && typeof providerError === 'object' && !Array.isArray(providerError)
164
+ ? Object.keys(providerError).sort().join(',') : null;
165
+ if (source !== 'codex-exec-rejected-failure/v1' || category !== 'failure' ||
166
+ !GOVERNED_CODEX_EXEC_FAILURE_EVENT_TYPES.has(eventType) || !eventFields ||
167
+ (keys.join(',') === providerKeys && providerErrorKeys !== 'code,param,schemaKeyword,status,type') ||
168
+ (keys.join(',') === baseKeys && providerError !== undefined)) return null;
169
+ if (providerError !== undefined &&
170
+ (ownDataValue(providerError, 'type') !== 'invalid_request_error' || ownDataValue(providerError, 'status') !== 400 ||
171
+ ownDataValue(providerError, 'code') !== 'invalid_json_schema' || ownDataValue(providerError, 'param') !== 'text.format.schema' ||
172
+ ownDataValue(providerError, 'schemaKeyword') !== 'uniqueItems')) return null;
173
+ return Object.freeze({ source, category, eventType, eventFields,
174
+ ...(providerError === undefined ? {} : { providerError: GOVERNED_CODEX_EXEC_SCHEMA_PROVIDER_ERROR }) });
175
+ }
176
+
177
+ function ownDataValue(value, key) {
178
+ if (!value || (typeof value !== 'object' && typeof value !== 'function')) return undefined;
179
+ try {
180
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
181
+ return descriptor && 'value' in descriptor ? descriptor.value : undefined;
182
+ } catch { return undefined; }
183
+ }
184
+
185
+ function closeProviderEngineDiagnostic(value) {
186
+ if (!value || typeof value !== 'object' || Array.isArray(value)) return null;
187
+ const keys = Object.keys(value);
188
+ if (keys.length < 2 || keys.length > 4 || !keys.includes('version') || !keys.includes('code') ||
189
+ keys.some(key => !['version', 'code', 'stderr', 'event'].includes(key))) return null;
190
+ const version = ownDataValue(value, 'version');
191
+ const code = ownDataValue(value, 'code');
192
+ if (version !== GOVERNED_CODEX_EXEC_FAILURE_VERSION || typeof code !== 'string' || !GOVERNED_CODEX_EXEC_FAILURE_CODES.has(code)) return null;
193
+ const stderr = ownDataValue(value, 'stderr');
194
+ let closedStderr;
195
+ if (stderr !== undefined) {
196
+ if (!stderr || typeof stderr !== 'object' || Array.isArray(stderr) ||
197
+ ![...Object.keys(stderr)].every(key => ['source', 'bytes', 'digest', 'safeMessage'].includes(key)) ||
198
+ Object.keys(stderr).length < 3 || Object.keys(stderr).length > 4 ||
199
+ ownDataValue(stderr, 'source') !== 'codex-exec-stderr/v1' ||
200
+ !Number.isSafeInteger(ownDataValue(stderr, 'bytes')) || ownDataValue(stderr, 'bytes') < 1 || ownDataValue(stderr, 'bytes') > 1048576 ||
201
+ !GOVERNED_CODEX_EXEC_STDERR_DIGEST.test(ownDataValue(stderr, 'digest'))) return null;
202
+ const safeMessage = ownDataValue(stderr, 'safeMessage');
203
+ closedStderr = Object.freeze({ source: 'codex-exec-stderr/v1', bytes: ownDataValue(stderr, 'bytes'), digest: ownDataValue(stderr, 'digest'),
204
+ ...(safeMessage === 'access_token_refresh_revoked' ? { safeMessage } : {}) });
205
+ }
206
+ const event = ownDataValue(value, 'event');
207
+ const closedEvent = event === undefined ? null : closeRejectedItemEvent(event) ?? closeRejectedFailureEvent(event);
208
+ if (event !== undefined && !closedEvent) return null;
209
+ return Object.freeze({ version, code, ...(closedStderr ? { stderr: closedStderr } : {}), ...(closedEvent ? { event: closedEvent } : {}) });
210
+ }
211
+
75
212
  export class GovernedAnswerFailure extends Error {
76
213
  constructor(stage, nativeEventFailureBoundary = null, nativeEventFailureSubreason = null,
77
214
  nativeEventFailureCorrelationOperand = null, nativeEventFailureAttestationPredicate = null,
78
215
  schemaResultValidationSubreason = null, schemaResultValidationKeyword = null,
79
- providerEngineFailureBoundary = null) {
216
+ providerEngineFailureBoundary = null, nativeEventFailureRawItemPredicate = null,
217
+ providerEngineDiagnostic = null) {
80
218
  super();
81
219
  delete this.stack;
82
220
  const answerFailureStage = GOVERNED_ANSWER_FAILURE_STAGES.has(stage) ? stage : 'unknown';
@@ -90,11 +228,27 @@ export class GovernedAnswerFailure extends Error {
90
228
  ? providerEngineFailureBoundary : null,
91
229
  enumerable: true,
92
230
  });
231
+ if (answerFailureStage === 'provider_engine' && providerEngineDiagnostic !== null &&
232
+ providerEngineDiagnostic !== undefined) {
233
+ const closedDiagnostic = closeProviderEngineDiagnostic(providerEngineDiagnostic);
234
+ if (closedDiagnostic) Object.defineProperty(this, 'providerEngineDiagnostic', {
235
+ value: closedDiagnostic,
236
+ enumerable: true,
237
+ });
238
+ }
93
239
  if (answerFailureStage === 'native_event_grammar') Object.defineProperty(this, 'nativeEventFailureBoundary', {
94
240
  value: GOVERNED_NATIVE_EVENT_FAILURE_BOUNDARIES.has(nativeEventFailureBoundary)
95
241
  ? nativeEventFailureBoundary : null,
96
242
  enumerable: true,
97
243
  });
244
+ if (answerFailureStage === 'native_event_grammar' &&
245
+ nativeEventFailureBoundary === 'raw_item_predicate') {
246
+ Object.defineProperty(this, 'nativeEventFailureRawItemPredicate', {
247
+ value: GOVERNED_NATIVE_EVENT_FAILURE_RAW_ITEM_PREDICATES.has(nativeEventFailureRawItemPredicate)
248
+ ? nativeEventFailureRawItemPredicate : null,
249
+ enumerable: true,
250
+ });
251
+ }
98
252
  if (answerFailureStage === 'native_event_grammar' &&
99
253
  nativeEventFailureBoundary === 'live_envelope_session') {
100
254
  Object.defineProperty(this, 'nativeEventFailureSubreason', {
@@ -143,21 +297,26 @@ export class GovernedAnswerFailure extends Error {
143
297
  export function governedAnswerFailure(stage, nativeEventFailureBoundary = null, nativeEventFailureSubreason = null,
144
298
  nativeEventFailureCorrelationOperand = null, nativeEventFailureAttestationPredicate = null,
145
299
  schemaResultValidationSubreason = null, schemaResultValidationKeyword = null,
146
- providerEngineFailureBoundary = null) {
300
+ providerEngineFailureBoundary = null, nativeEventFailureRawItemPredicate = null,
301
+ providerEngineDiagnostic = null) {
147
302
  return new GovernedAnswerFailure(stage, nativeEventFailureBoundary, nativeEventFailureSubreason,
148
303
  nativeEventFailureCorrelationOperand, nativeEventFailureAttestationPredicate,
149
- schemaResultValidationSubreason, schemaResultValidationKeyword, providerEngineFailureBoundary);
304
+ schemaResultValidationSubreason, schemaResultValidationKeyword, providerEngineFailureBoundary,
305
+ nativeEventFailureRawItemPredicate, providerEngineDiagnostic);
150
306
  }
151
307
 
152
308
  export function normalizeGovernedAnswerFailure(error, fallback = 'unknown', nativeEventFailureBoundary = null,
153
309
  nativeEventFailureSubreason = null, nativeEventFailureCorrelationOperand = null,
154
310
  schemaResultValidationSubreason = null, schemaResultValidationKeyword = null,
155
- providerEngineFailureBoundary = null, nativeEventFailureAttestationPredicate = null) {
311
+ providerEngineFailureBoundary = null, nativeEventFailureAttestationPredicate = null,
312
+ nativeEventFailureRawItemPredicate = null) {
156
313
  return error instanceof GovernedAnswerFailure ? error
157
314
  : governedAnswerFailure(fallback, nativeEventFailureBoundary, nativeEventFailureSubreason,
158
315
  nativeEventFailureCorrelationOperand,
159
316
  fallback === 'native_event_grammar' && nativeEventFailureBoundary === 'live_envelope_session' &&
160
317
  nativeEventFailureSubreason === 'attestation'
161
318
  ? nativeEventFailureAttestationPredicate ?? governedAttestationPredicate(error) : null,
162
- schemaResultValidationSubreason, schemaResultValidationKeyword, providerEngineFailureBoundary);
319
+ schemaResultValidationSubreason, schemaResultValidationKeyword, providerEngineFailureBoundary,
320
+ fallback === 'native_event_grammar' && nativeEventFailureBoundary === 'raw_item_predicate'
321
+ ? nativeEventFailureRawItemPredicate : null);
163
322
  }