@theoremjs/agents 0.3.5-next.931.ge6a1c43 → 0.3.5-next.932.g295cc67

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.
@@ -82,10 +82,16 @@ export interface StageResult {
82
82
  abort?: boolean | {
83
83
  reason?: string;
84
84
  };
85
- /** `pre_tool`: refuse the call. `post_tool`: replace the result with this failure. */
85
+ /**
86
+ * `pre_tool`: refuse the call. `post_tool`: replace the result with this failure.
87
+ * `details`, a JSON object, become `failure.details`: the model reads them, and the guardrails
88
+ * read them first. Details that are not a JSON object are a `deny_invalid` warning, and the call
89
+ * is still refused, without details.
90
+ */
86
91
  deny?: {
87
92
  code?: string;
88
93
  message?: string;
94
+ details?: Record<string, unknown>;
89
95
  };
90
96
  /** `pre_tool` only — request a confirm/permission gate. */
91
97
  confirm?: true | {
@@ -166,6 +172,7 @@ export interface StageApplyOutput {
166
172
  deny?: {
167
173
  code: string;
168
174
  message: string;
175
+ details?: Record<string, unknown>;
169
176
  };
170
177
  confirm?: {
171
178
  summary?: string;
@@ -191,7 +191,19 @@ function applyDenyField(result, stage, out) {
191
191
  const message = typeof result.deny.message === 'string' && result.deny.message.trim()
192
192
  ? result.deny.message.trim()
193
193
  : 'Tool execution not authorized'; // labels-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
194
- out.deny = { code, message };
194
+ const details = result.deny.details;
195
+ if (details === undefined) {
196
+ out.deny = { code, message };
197
+ }
198
+ else if (isRecord(details) && jsonValueSchema.safeParse(details).success) {
199
+ out.deny = { code, message, details };
200
+ }
201
+ else {
202
+ // why: A refusal stands even when its details are bad; only the details are dropped.
203
+ out.deny = { code, message };
204
+ // labels-exempt: developer contract / internal diagnostic — not end-user or model copy (P2)
205
+ warn(out.warnings, 'deny_invalid', 'deny', 'deny.details must be a JSON object');
206
+ }
195
207
  }
196
208
  }
197
209
  function applyLabelFailedField(result, stage, out) {
@@ -215,6 +215,7 @@ function* reviseAfterStages(post, guard, reproject, failure) {
215
215
  code: post.deny.code,
216
216
  kind: 'blocked',
217
217
  message: post.deny.message,
218
+ ...(post.deny.details ? { details: post.deny.details } : {}),
218
219
  });
219
220
  }
220
221
  if (post.mutate && 'details' in post.mutate) {
@@ -74,6 +74,7 @@ export type PostToolStageOutcome = {
74
74
  deny?: {
75
75
  code: string;
76
76
  message: string;
77
+ details?: Record<string, unknown>;
77
78
  };
78
79
  /** `output`: the caller validates and projects it again. `details`: the caller fails the call with them. */
79
80
  mutate?: {
@@ -139,7 +139,12 @@ async function* runPreToolStages(args) {
139
139
  return {
140
140
  ok: false,
141
141
  kind: 'failed',
142
- failure: { ...applied.deny, kind: 'blocked' },
142
+ failure: {
143
+ code: applied.deny.code,
144
+ kind: 'blocked',
145
+ message: applied.deny.message,
146
+ ...(applied.deny.details ? { details: applied.deny.details } : {}),
147
+ },
143
148
  denied: true,
144
149
  };
145
150
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theoremjs/agents",
3
- "version": "0.3.5-next.931.ge6a1c43",
3
+ "version": "0.3.5-next.932.g295cc67",
4
4
  "description": "A flat TypeScript agent kernel for typed profiles, deterministic turn execution, registered tools, provider adapters, guardrails, and host-injected traces.",
5
5
  "keywords": [
6
6
  "agent",