osuite 2.14.2 → 2.15.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/runtime/hook.mjs CHANGED
@@ -158,7 +158,22 @@ export async function runHook(data, localConfig, dependencies = {}) {
158
158
  }
159
159
  await emitRuntimeEvent(api, config, context, 'tool_preflight', null, { tool_input_digest: context.tool_input_digest, install_check: config.installCheck === true });
160
160
  if (!fenceUnchanged()) return deny(accessChanged);
161
- const result = await admitAction(context, { api, config, ...dependencies.admission, beforeRelease: response => validateGitPublication(context, response) });
161
+ const operationKey = `operation:${session}:${context.tool_use_id}`;
162
+ const rememberOperation = ['claude', 'codex'].includes(config.host) && config.privateKeyBase64 && !config.installCheck
163
+ ? actionId => {
164
+ const current = store.update(operationKey, prior => prior || { action_id: actionId, input_digest: context.tool_input_digest });
165
+ return current.action_id === actionId && current.input_digest === context.tool_input_digest;
166
+ } : undefined;
167
+ const result = await admitAction(context, { api, config, ...dependencies.admission, rememberOperation,
168
+ beforeRelease: response => validateGitPublication(context, response) });
169
+ const dispatchBody = result.hookOperationId ? { hook_action_id: result.hookOperationId, tool_input_digest: context.tool_input_digest } : null;
170
+ const cancelUnreleased = async () => {
171
+ if (!dispatchBody || !fenceUnchanged()) return;
172
+ await api.request('PATCH', `/api/actions/${result.hookOperationId}`, {
173
+ ...dispatchBody, status: 'cancelled', error_message: 'CLIENT_BLOCKED', timestamp_end: new Date(now()).toISOString(),
174
+ output_summary: 'The hook stopped the tool before releasing it to the host.',
175
+ }, { timeoutMs: 1500 });
176
+ };
162
177
  if (result.degraded) {
163
178
  rememberGap(store, result.reason, now());
164
179
  await emitRuntimeEvent(api, config, context, 'governance_unavailable', null, { decision: result.decision === 'allow' ? 'guard_unavailable' : 'guard_unavailable_blocked' });
@@ -174,12 +189,24 @@ export async function runHook(data, localConfig, dependencies = {}) {
174
189
  try {
175
190
  store.write(`action:${context.tool_use_id}`, { schema: 'osuite.node_action.v1', action_id: result.actionId,
176
191
  runtime_session_id: session, tool_name: data.tool_name, tool_use_id: context.tool_use_id,
177
- tool_input_digest: context.tool_input_digest, require_signature: config.signatureMode === 'required', install_check: config.installCheck === true });
178
- } catch { return deny('Cannot persist the exact-action receipt state. The admitted tool was not released; reconcile its action in Studio before retrying.'); }
192
+ tool_input_digest: context.tool_input_digest, require_signature: config.signatureMode === 'required', install_check: config.installCheck === true,
193
+ ...(dispatchBody ? { hook_dispatch: true } : {}) });
194
+ } catch {
195
+ await cancelUnreleased();
196
+ return deny('Cannot persist the exact-action receipt state. The admitted tool was not released; reconcile its action in Studio before retrying.');
197
+ }
198
+ if (dispatchBody) {
199
+ const claim = await api.request('POST', `/api/actions/${result.hookOperationId}/dispatch`, dispatchBody, { timeoutMs: 2000 });
200
+ if (!claim.ok || claim.status !== 201 || claim.body?.action_id !== result.hookOperationId
201
+ || !Number.isFinite(Date.parse(claim.body.hook_dispatch_at))) {
202
+ return deny(`Dispatch was not confirmed for ${result.hookOperationId}. No tool was released by this hook. Reconcile in Studio.`);
203
+ }
204
+ }
179
205
  updatePending(store, context);
180
206
  await emitRuntimeEvent(api, config, context, 'tool_allowed', result.actionId, { decision: result.decision, install_check: config.installCheck === true });
181
207
  return checkedNote(config.mode === 'observe' && !result.ruleRolloutBinding ? 'Observe mode recorded a policy result; it does not enforce OSuite policy.' : result.decision === 'warn' ? 'OSuite authorized this call with a policy warning.' : '');
182
208
  }
209
+ if (result.reason === 'action_evidence_changed') await cancelUnreleased();
183
210
  if (result.decision === 'require_approval') {
184
211
  if (result.observeOnly !== true) updatePending(store, context, { action_id: result.actionId, agent_id: config.agentId,
185
212
  runtime_session_id: session, tool_input_digest: context.tool_input_digest, fingerprint: cavaFingerprint(result.response) });
@@ -14,7 +14,13 @@ export function terminalOutcome(config, data, now = Date.now()) {
14
14
  const structured = isObject(response.structuredContent) ? response.structuredContent : response;
15
15
  const error = [response, structured].some(value => value.error || value.isError === true || value.is_error === true || value.interrupted === true);
16
16
  const exitCode = Object.hasOwn(response, 'exit_code') ? response.exit_code : structured.exit_code;
17
- if (error) {
17
+ if (response.interrupted === true || structured.interrupted === true) {
18
+ status = 'cancelled';
19
+ summary = 'Runtime reported that the tool was interrupted.';
20
+ } else if (config.host === 'codex' && structured.error_kind === 'sandbox_launch_failed') {
21
+ status = 'failed';
22
+ summary = 'Codex reported a sandbox launch failure.';
23
+ } else if (error) {
18
24
  status = 'failed';
19
25
  summary = 'Runtime reported a tool error; details omitted.';
20
26
  } else if (Number.isSafeInteger(exitCode)) {
@@ -33,14 +39,14 @@ export function terminalOutcome(config, data, now = Date.now()) {
33
39
 
34
40
  function validReport(report, provenance) {
35
41
  const outcome = report?.outcome;
36
- return isObject(outcome) && (provenance.schema === 'osuite.diagnostic_terminal_report.v1' ? outcome.status === 'cancelled' : ['completed', 'failed'].includes(outcome.status))
42
+ return isObject(outcome) && (provenance.schema === 'osuite.diagnostic_terminal_report.v1' ? outcome.status === 'cancelled' : ['completed', 'failed', 'cancelled'].includes(outcome.status))
37
43
  && Object.keys(outcome).sort().join(',') === 'output_summary,status,timestamp_end'
38
44
  && typeof outcome.output_summary === 'string' && Number.isFinite(Date.parse(outcome.timestamp_end))
39
45
  && typeof report.action_reported === 'boolean'
40
46
  && canonicalJson(report.provenance) === canonicalJson(provenance);
41
47
  }
42
48
 
43
- export async function recordOutcome(config, data, { api, store, now = Date.now } = {}) {
49
+ export async function recordOutcome(config, data, { api, store, now = Date.now, nativeOutcome = null } = {}) {
44
50
  if (!isObject(data)) return pending('invalid_hook_input');
45
51
  const toolId = deriveToolUseId(data);
46
52
  if (!safeId(toolId)) return pending('invalid_tool_id');
@@ -61,7 +67,9 @@ export async function recordOutcome(config, data, { api, store, now = Date.now }
61
67
  if (report !== undefined && !validReport(report, provenance)) return pending('untrusted_outcome_state');
62
68
  if (report === undefined) {
63
69
  const outcome = state.install_check ? { status: 'cancelled', timestamp_end: new Date(now()).toISOString(),
64
- output_summary: 'Inert diagnostic hook probe; the tool was not executed.' } : terminalOutcome(config, data, now());
70
+ output_summary: 'Inert diagnostic hook probe; the tool was not executed.' } : nativeOutcome
71
+ ? { status: nativeOutcome.status, output_summary: nativeOutcome.summary, timestamp_end: new Date(now()).toISOString() }
72
+ : terminalOutcome(config, data, now());
65
73
  if (!outcome) return pending('terminal_evidence_missing');
66
74
  report = { outcome, action_reported: false, provenance };
67
75
  state.outcome_report = report;
@@ -69,7 +77,10 @@ export async function recordOutcome(config, data, { api, store, now = Date.now }
69
77
  }
70
78
  const outcome = report.outcome;
71
79
  if (!report.action_reported) {
72
- const response = await api.request('PATCH', `/api/actions/${encodeURIComponent(state.action_id)}`, outcome, { timeoutMs: 2000 });
80
+ const response = await api.request('PATCH', `/api/actions/${encodeURIComponent(state.action_id)}`, {
81
+ ...outcome,
82
+ ...(state.hook_dispatch ? { hook_action_id: state.action_id, tool_input_digest: state.tool_input_digest } : {}),
83
+ }, { timeoutMs: 2000 });
73
84
  const action = response.body?.action;
74
85
  if (!response.ok || response.status !== 200 || !isObject(action)
75
86
  || action.action_id !== state.action_id || action.status !== outcome.status || action.timestamp_end !== outcome.timestamp_end) {
@@ -82,7 +93,7 @@ export async function recordOutcome(config, data, { api, store, now = Date.now }
82
93
  const event = {
83
94
  event_id: `evt_outcome_${sha256(`${state.runtime_session_id}|${state.action_id}|${toolId}|${outcome.timestamp_end}`).slice(0, 24)}`,
84
95
  runtime_session_id: state.runtime_session_id,
85
- event_type: state.install_check ? 'turn_stopped' : outcome.status === 'completed' ? 'tool_completed' : 'tool_failed',
96
+ event_type: outcome.status === 'cancelled' ? 'turn_stopped' : outcome.status === 'completed' ? 'tool_completed' : 'tool_failed',
86
97
  tool_name: state.tool_name, tool_use_id: toolId, action_id: state.action_id,
87
98
  timestamp: outcome.timestamp_end,
88
99
  payload: { status: outcome.status, output_summary: outcome.output_summary, ...(state.install_check ? { install_check: true } : {}) },
package/runtime/shell.mjs CHANGED
@@ -48,7 +48,20 @@ export function parseShell(command) {
48
48
  return { segments, errors: [...new Set(errors)] };
49
49
  }
50
50
 
51
- function unwrap(tokens) {
51
+ function stdoutPrintfArgv(argv) {
52
+ if (argv[0] !== 'printf') return false;
53
+ const format = argv[1] === '--' ? argv[2] : argv[1];
54
+ // Bash printf -v assigns a variable. %n can assign through a format operand.
55
+ return typeof format === 'string' && (argv[1] === '--' || !format.startsWith('-'))
56
+ && !/%[-+#0 '.0-9*$]*n/.test(format.replace(/%%/g, ''));
57
+ }
58
+
59
+ export function isStdoutPrintf(command) {
60
+ const { segments, errors } = parseShell(command);
61
+ return errors.length === 0 && segments.length === 1 && stdoutPrintfArgv(segments[0]);
62
+ }
63
+
64
+ export function unwrapShellArgv(tokens) {
52
65
  let argv = [...tokens];
53
66
  for (let depth = 0; depth < 8 && argv.length; depth += 1) {
54
67
  while (/^[A-Za-z_][A-Za-z0-9_]*=/.test(argv[0] || '')) argv.shift();
@@ -112,7 +125,7 @@ function boundedObservation(exe, args) {
112
125
  }
113
126
 
114
127
  function classifyArgv(tokens, cwd, depth) {
115
- const argv = unwrap(tokens), exe = basename(argv[0]), args = argv.slice(1);
128
+ const argv = unwrapShellArgv(tokens), exe = basename(argv[0]), args = argv.slice(1);
116
129
  if (!exe) return incomplete(tokens, cwd, ['unsupported_wrapper']);
117
130
  if (shells.has(exe)) {
118
131
  const index = args.findIndex(arg => /^-[a-z]*c$/.test(arg));
@@ -121,6 +134,7 @@ function classifyArgv(tokens, cwd, depth) {
121
134
  }
122
135
  const canonical = { runtime: 'bash', executable: exe, operation: args[0] || '', tool_category: 'other', cwd, systems_touched: [exe] };
123
136
  const classified = (type, risk, reversible, category = 'deployment') => result(type, risk, reversible, { ...canonical, tool_category: category });
137
+ if (stdoutPrintfArgv(tokens)) return classified('other', 10, true, 'observation');
124
138
  if (exe === 'git') {
125
139
  let index = 0;
126
140
  while (index < args.length && args[index].startsWith('-')) { const flag = args[index++]; if (gitValueFlags.has(flag)) index += 1; }