owenloop 0.5.23 → 0.5.25

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/CHANGELOG.md CHANGED
@@ -4,6 +4,20 @@ All notable changes to this project are documented here. The format is based on
4
4
  [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project
5
5
  adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [0.5.25](https://github.com/typicalday/owenloop/compare/v0.5.24...v0.5.25) (2026-08-23)
8
+
9
+
10
+ ### Features
11
+
12
+ * **engine:** scope native judges to workflow modifiers ([#295](https://github.com/typicalday/owenloop/issues/295)) ([d1cb9d5](https://github.com/typicalday/owenloop/commit/d1cb9d5f711b7ea5ed545202a0d2e37189ba1d06))
13
+
14
+ ## [0.5.24](https://github.com/typicalday/owenloop/compare/v0.5.23...v0.5.24) (2026-08-23)
15
+
16
+
17
+ ### Bug Fixes
18
+
19
+ * **work:** enforce exact-root Claude tool gating ([#293](https://github.com/typicalday/owenloop/issues/293)) ([d79da0d](https://github.com/typicalday/owenloop/commit/d79da0dc6fac28e641695ab099f9f5f98b439b95))
20
+
7
21
  ## [0.5.23](https://github.com/typicalday/owenloop/compare/v0.5.22...v0.5.23) (2026-08-23)
8
22
 
9
23
 
@@ -1,12 +1,17 @@
1
- import type { Options, Query, SDKMessage } from '@anthropic-ai/claude-agent-sdk';
1
+ import type { HookCallback, Options, Query, SDKMessage } from '@anthropic-ai/claude-agent-sdk';
2
2
  import { type GatePolicy } from './gatekeeper.ts';
3
3
  import type { ApprovalRequester } from './contract.ts';
4
4
  import type { AgentEvent, DeliverArgs, HarnessAdapter, HarnessRecoveryPolicy, HarnessSessionRef, StartArgs, StepPermissions } from './contract.ts';
5
5
  /** Host-only opt-in liveness controller. Never admitted to the child env. */
6
6
  export declare const CLAUDE_IDLE_TIMEOUT_VAR = "OWENLOOP_CLAUDE_IDLE_TIMEOUT_MS";
7
+ /** Host-only opt-in for the exact snapshot-root Claude audit profile. */
8
+ export declare const CLAUDE_EXACT_WORKDIR_VAR = "OWENLOOP_CLAUDE_EXACT_WORKDIR";
7
9
  /** Parse the one adapter-owned recovery setting without silently opting out. */
8
10
  export declare function parseClaudeIdleTimeout(value: string | undefined): HarnessRecoveryPolicy | undefined;
9
11
  export declare function claudeRecoveryPolicy(env?: Record<string, string | undefined>): HarnessRecoveryPolicy | undefined;
12
+ /** Parse the strict profile as a boolean rather than passing its host spelling onward. */
13
+ export declare function parseClaudeExactWorkdir(value: string | undefined): boolean;
14
+ export declare function claudeExactWorkdir(env?: Record<string, string | undefined>): boolean;
10
15
  /**
11
16
  * Build the environment the harness child runs under.
12
17
  *
@@ -95,6 +100,8 @@ export declare function resolveExecutable(source: Record<string, string | undefi
95
100
  * future SDK that does route it must not find it silently widened here.
96
101
  */
97
102
  export declare function gatePolicyFor(authoredMode: string | undefined): GatePolicy;
103
+ /** Programmatic PreToolUse guard for every path-bearing exposed built-in. */
104
+ export declare function buildExactWorkdirPreToolUse(cwd: string): HookCallback;
98
105
  /** Everything `buildClaudeOptions` reads for either cold start or resume. */
99
106
  export interface ClaudeOptionInputs {
100
107
  cwd: string;
@@ -111,6 +118,8 @@ export interface ClaudeOptionInputs {
111
118
  * refuse-and-route-to-`ask` behavior — see `buildCanUseTool`. */
112
119
  approvals?: ApprovalRequester;
113
120
  recoveryPolicy?: HarnessRecoveryPolicy;
121
+ /** Host-parsed policy bit. Its environment spelling never enters Options. */
122
+ exactWorkdir?: boolean;
114
123
  }
115
124
  /** The non-declarative bits a caller supplies per invocation. */
116
125
  export interface ClaudeOptionExtras {
@@ -171,6 +180,8 @@ export interface ConsumeTurnControl {
171
180
  now?: () => number;
172
181
  setTimer?: (callback: () => void, ms: number) => ReturnType<typeof setTimeout>;
173
182
  clearTimer?: (timer: ReturnType<typeof setTimeout>) => void;
183
+ /** Strict profile's literal provider identity check, never a public arg. */
184
+ expectedModel?: string;
174
185
  }
175
186
  /**
176
187
  * Drive the SDK message stream to TURN END and map it onto `AgentEvent`s.
@@ -26,7 +26,7 @@
26
26
  import { randomUUID } from 'node:crypto';
27
27
  import { accessSync, constants, existsSync } from 'node:fs';
28
28
  import { delimiter, join } from 'node:path';
29
- import { classifyToolCall, READ_ONLY_TOOLS } from "./gatekeeper.js";
29
+ import { classifyExactWorkdirPath, classifyToolCall, EXACT_WORKDIR_DENIAL_MESSAGE, PATH_BEARING_TOOL_NAMES, READ_ONLY_TOOLS, } from "./gatekeeper.js";
30
30
  import { register } from "./registry.js";
31
31
  import { filterOwenloopEnv } from "./child-env.js";
32
32
  import { normalizeStepPermissions, validateHarnessOptions } from "./permissions.js";
@@ -69,6 +69,8 @@ const ALLOW_API_BILLING_VAR = 'OWENLOOP_ALLOW_API_BILLING';
69
69
  const BIN_OVERRIDE_VAR = 'OWENLOOP_CLAUDE_BIN';
70
70
  /** Host-only opt-in liveness controller. Never admitted to the child env. */
71
71
  export const CLAUDE_IDLE_TIMEOUT_VAR = 'OWENLOOP_CLAUDE_IDLE_TIMEOUT_MS';
72
+ /** Host-only opt-in for the exact snapshot-root Claude audit profile. */
73
+ export const CLAUDE_EXACT_WORKDIR_VAR = 'OWENLOOP_CLAUDE_EXACT_WORKDIR';
72
74
  const MIN_IDLE_TIMEOUT_MS = 1_000;
73
75
  const MAX_IDLE_TIMEOUT_MS = 3_600_000;
74
76
  /** Parse the one adapter-owned recovery setting without silently opting out. */
@@ -87,6 +89,17 @@ export function parseClaudeIdleTimeout(value) {
87
89
  export function claudeRecoveryPolicy(env = process.env) {
88
90
  return parseClaudeIdleTimeout(env[CLAUDE_IDLE_TIMEOUT_VAR]);
89
91
  }
92
+ /** Parse the strict profile as a boolean rather than passing its host spelling onward. */
93
+ export function parseClaudeExactWorkdir(value) {
94
+ if (value === undefined)
95
+ return false;
96
+ if (value === '1')
97
+ return true;
98
+ throw new HarnessTurnError('configuration', true, `${CLAUDE_EXACT_WORKDIR_VAR} must be exactly 1 when present`);
99
+ }
100
+ export function claudeExactWorkdir(env = process.env) {
101
+ return parseClaudeExactWorkdir(env[CLAUDE_EXACT_WORKDIR_VAR]);
102
+ }
90
103
  /**
91
104
  * Build the environment the harness child runs under.
92
105
  *
@@ -403,17 +416,30 @@ function approvalTitle(toolName, input, suppliedTitle) {
403
416
  * the behavior is exactly what it was before: deny, and name `ask` as the
404
417
  * channel that does reach someone.
405
418
  */
406
- function buildCanUseTool(cwd, policy, filesystem, onEvent, approvals) {
419
+ function buildCanUseTool(cwd, policy, filesystem, onEvent, approvals, exactWorkdir = false) {
407
420
  return async (toolName, input, options) => {
408
421
  let verdict;
409
422
  try {
410
- verdict = classifyToolCall({ toolName, input, workdir: cwd, blockedPath: options.blockedPath, filesystem }, policy);
423
+ verdict = classifyToolCall({
424
+ toolName,
425
+ input,
426
+ workdir: cwd,
427
+ blockedPath: options.blockedPath,
428
+ filesystem,
429
+ exactWorkdir,
430
+ }, policy);
411
431
  }
412
432
  catch (err) {
413
433
  verdict = { decision: 'escalate', reason: `the gatekeeper could not judge this call (${errText(err)})` };
414
434
  }
415
435
  if (verdict.decision === 'allow')
416
436
  return { behavior: 'allow' };
437
+ // This is a host boundary, not a legacy escalation. It never enters the
438
+ // approval channel and its fixed message cannot serialize a model path.
439
+ if (verdict.decision === 'deny') {
440
+ onEvent({ kind: 'progress', text: `exact work-root policy: ${toolName} denied` });
441
+ return { behavior: 'deny', message: verdict.reason };
442
+ }
417
443
  if (approvals !== undefined) {
418
444
  const title = approvalTitle(toolName, input, options.title);
419
445
  onEvent({
@@ -490,6 +516,7 @@ const READ_ONLY_OWENLOOP_ONLY_NETWORK_TOOLS = [...READ_ONLY_TOOLS]
490
516
  const BORN_BOUND_OWENLOOP_TOOL_NAMES = ['get_order', 'submit', 'ask'];
491
517
  const BORN_BOUND_OWENLOOP_TOOLS = BORN_BOUND_OWENLOOP_TOOL_NAMES.map((name) => `mcp__owenloop__${name}`);
492
518
  const RESTRICTED_OWENLOOP_DENIED_TOOLS = ['mcp__owenloop__reject'];
519
+ const EXACT_WORKDIR_BUILTINS = new Set(['Read', 'Glob', 'Grep']);
493
520
  const OWENLOOP_CONTROL_TOOLS = new Set([
494
521
  ...BORN_BOUND_OWENLOOP_TOOLS,
495
522
  'mcp__plugin_owenloop_owenloop__get_order',
@@ -503,8 +530,43 @@ const OWENLOOP_CONTROL_DENY_SPECS = new Set([
503
530
  'mcp__plugin_owenloop_owenloop__*',
504
531
  'mcp__*',
505
532
  ]);
533
+ function effectiveClaudeTools(permissions) {
534
+ if (permissions.tools !== undefined)
535
+ return permissions.tools;
536
+ if (permissions.filesystem === 'read-only') {
537
+ return permissions.network === 'owenloop-only'
538
+ ? READ_ONLY_OWENLOOP_ONLY_NETWORK_TOOLS
539
+ : [...READ_ONLY_TOOLS];
540
+ }
541
+ if (permissions.network === 'owenloop-only')
542
+ return [...OWENLOOP_ONLY_NETWORK_TOOLS];
543
+ return undefined;
544
+ }
545
+ function strictWorkdirToolIssue(permissions) {
546
+ const effective = effectiveClaudeTools(permissions);
547
+ if (effective === undefined) {
548
+ return {
549
+ field: 'tools',
550
+ message: `${CLAUDE_EXACT_WORKDIR_VAR}=1 requires an explicit or derived built-in surface containing only Read, Glob, and Grep`,
551
+ };
552
+ }
553
+ const unsafe = effective.filter((tool) => !EXACT_WORKDIR_BUILTINS.has(tool) && !BORN_BOUND_OWENLOOP_TOOLS.includes(tool));
554
+ if (unsafe.length === 0)
555
+ return undefined;
556
+ return {
557
+ field: 'tools',
558
+ message: `${CLAUDE_EXACT_WORKDIR_VAR}=1 permits only Read, Glob, Grep, and born-bound Owenloop controls; remove: ${unsafe.join(', ')}`,
559
+ };
560
+ }
506
561
  function claudePreflight(permissions) {
507
562
  const issues = [];
563
+ let exactWorkdir = false;
564
+ try {
565
+ exactWorkdir = claudeExactWorkdir(process.env);
566
+ }
567
+ catch (error) {
568
+ issues.push({ field: CLAUDE_EXACT_WORKDIR_VAR, message: errText(error) });
569
+ }
508
570
  const authoredMode = permissions.permissionMode;
509
571
  if (authoredMode !== undefined) {
510
572
  if (!ACCEPTED_PERMISSION_MODES.includes(authoredMode)) {
@@ -568,6 +630,11 @@ function claudePreflight(permissions) {
568
630
  message: `the born-bound Owenloop control plane must retain get_order/submit access; remove: ${deniedControl.join(', ')}`,
569
631
  });
570
632
  }
633
+ if (exactWorkdir) {
634
+ const strictIssue = strictWorkdirToolIssue(permissions);
635
+ if (strictIssue !== undefined)
636
+ issues.push(strictIssue);
637
+ }
571
638
  return issues;
572
639
  }
573
640
  /**
@@ -581,6 +648,42 @@ const RESUME_FAILURE_RE = /no conversation found|session not found|--resume/i;
581
648
  function isPlainMap(v) {
582
649
  return typeof v === 'object' && v !== null && !Array.isArray(v);
583
650
  }
651
+ /** Programmatic PreToolUse guard for every path-bearing exposed built-in. */
652
+ export function buildExactWorkdirPreToolUse(cwd) {
653
+ return async (input) => {
654
+ const deny = {
655
+ continue: true,
656
+ hookSpecificOutput: {
657
+ hookEventName: 'PreToolUse',
658
+ permissionDecision: 'deny',
659
+ permissionDecisionReason: EXACT_WORKDIR_DENIAL_MESSAGE,
660
+ },
661
+ };
662
+ try {
663
+ if (input.hook_event_name !== 'PreToolUse' || !PATH_BEARING_TOOL_NAMES.has(input.tool_name))
664
+ return deny;
665
+ if (!isPlainMap(input.tool_input))
666
+ return deny;
667
+ const verdict = classifyExactWorkdirPath({
668
+ toolName: input.tool_name,
669
+ input: input.tool_input,
670
+ workdir: cwd,
671
+ });
672
+ if (verdict.decision === 'deny')
673
+ return deny;
674
+ return {
675
+ continue: true,
676
+ hookSpecificOutput: {
677
+ hookEventName: 'PreToolUse',
678
+ permissionDecision: 'allow',
679
+ },
680
+ };
681
+ }
682
+ catch {
683
+ return deny;
684
+ }
685
+ };
686
+ }
584
687
  /** The mount for owenloop's own work-holder MCP surface, built from the worker's
585
688
  * verbatim argv. `alwaysLoad` forces its tools into the turn-1 prompt instead of
586
689
  * deferring them behind tool search — a step agent that cannot see `submit` on
@@ -588,7 +691,7 @@ function isPlainMap(v) {
588
691
  function owenloopMount(mount) {
589
692
  return { type: 'stdio', command: mount.command, args: mount.args, alwaysLoad: true };
590
693
  }
591
- /** Restricted sessions register a positive two-tool subset. The selector is
694
+ /** Restricted sessions register a positive born-bound subset. The selector is
592
695
  * derived from the same names used by `allowedTools`, so the declared exception
593
696
  * and the MCP server's actual `tools/list` cannot drift within this adapter. */
594
697
  function restrictedOwenloopMount(mount) {
@@ -617,8 +720,16 @@ function mergeMcpServers(bagServers, mount) {
617
720
  */
618
721
  export function buildClaudeOptions(inputs, extra) {
619
722
  const { permissions } = inputs;
723
+ const exactWorkdir = inputs.exactWorkdir === true;
724
+ const effectiveTools = effectiveClaudeTools(permissions);
725
+ if (exactWorkdir) {
726
+ const issue = strictWorkdirToolIssue(permissions);
727
+ if (issue !== undefined)
728
+ throw new HarnessTurnError('configuration', true, issue.message);
729
+ }
620
730
  const diagnosticEvent = inputs.recoveryPolicy === undefined ? extra.onEvent : (_event) => { };
621
- const isolated = permissions.tools !== undefined ||
731
+ const isolated = exactWorkdir ||
732
+ permissions.tools !== undefined ||
622
733
  permissions.filesystem === 'read-only' ||
623
734
  permissions.network === 'owenloop-only';
624
735
  const options = {
@@ -638,8 +749,13 @@ export function buildClaudeOptions(inputs, extra) {
638
749
  // Set here, before the `permissionMode` block below, because it is not
639
750
  // conditional on that block running: a step naming no mode at all is exactly
640
751
  // the case that used to reach the SDK's `default` and be denied wholesale.
641
- canUseTool: buildCanUseTool(inputs.cwd, gatePolicyFor(permissions.permissionMode), permissions.filesystem, diagnosticEvent, inputs.approvals),
752
+ canUseTool: buildCanUseTool(inputs.cwd, gatePolicyFor(permissions.permissionMode), permissions.filesystem, diagnosticEvent, inputs.approvals, exactWorkdir),
642
753
  };
754
+ if (exactWorkdir) {
755
+ options.hooks = {
756
+ PreToolUse: [{ matcher: [...PATH_BEARING_TOOL_NAMES].join('|'), hooks: [buildExactWorkdirPreToolUse(inputs.cwd)] }],
757
+ };
758
+ }
643
759
  // Partial messages are provider transport only: they reset liveness below but
644
760
  // are never mapped into progress/evidence output.
645
761
  if (inputs.recoveryPolicy !== undefined)
@@ -703,19 +819,8 @@ export function buildClaudeOptions(inputs, extra) {
703
819
  // exception: the audited built-in list becomes explicit, and `allowedTools`
704
820
  // also auto-allows the born-bound get_order/submit MCP tools so the restricted
705
821
  // agent can inspect and finish its order without an unattended permission prompt.
706
- // The restricted MCP child itself registers exactly those two tools; allowedTools
822
+ // The restricted MCP child itself registers exactly those born-bound tools; allowedTools
707
823
  // is permission automation, not an MCP visibility filter.
708
- let effectiveTools = permissions.tools;
709
- if (effectiveTools === undefined && permissions.filesystem === 'read-only') {
710
- // Filesystem and network are independent. A read-only filesystem still gets
711
- // audited network readers unless the step separately restricts the network.
712
- effectiveTools = permissions.network === 'owenloop-only'
713
- ? READ_ONLY_OWENLOOP_ONLY_NETWORK_TOOLS
714
- : [...READ_ONLY_TOOLS];
715
- }
716
- else if (effectiveTools === undefined && permissions.network === 'owenloop-only') {
717
- effectiveTools = [...OWENLOOP_ONLY_NETWORK_TOOLS];
718
- }
719
824
  if (effectiveTools !== undefined) {
720
825
  options.tools = effectiveTools.filter((tool) => !OWENLOOP_CONTROL_TOOLS.has(tool));
721
826
  options.allowedTools = [
@@ -761,7 +866,7 @@ export function buildClaudeOptions(inputs, extra) {
761
866
  // Outside isolation, `settingSources` and `strictMcpConfig` stay unset so the
762
867
  // SDK preserves its normal settings and MCP behavior, including the full
763
868
  // get_order/submit/reject work-holder server. Isolation sets `settingSources: []`
764
- // and `strictMcpConfig: true` above, mounts the positive two-tool work-holder
869
+ // and `strictMcpConfig: true` above, mounts the positive born-bound work-holder
765
870
  // subset, and removes settings, hooks, skills, or external MCP that could bypass
766
871
  // the authored restriction.
767
872
  // `persistSession` always stays unset: its default is `true`, and disabling it
@@ -918,6 +1023,7 @@ function emitUser(message, onEvent) {
918
1023
  */
919
1024
  export async function consumeTurn(q, onEvent, onInit, expectedSessionId, control = {}) {
920
1025
  let sessionId;
1026
+ let sawInit = false;
921
1027
  let finalResponse;
922
1028
  let terminalFailure;
923
1029
  let timer;
@@ -926,6 +1032,7 @@ export async function consumeTurn(q, onEvent, onInit, expectedSessionId, control
926
1032
  let timerGeneration = 0;
927
1033
  let controlledQueryClosed = false;
928
1034
  const recoveryEnabled = control.idleTimeoutMs !== undefined;
1035
+ const strictModelIdentity = control.expectedModel !== undefined;
929
1036
  const sanitizeProviderTelemetry = control.sanitizeProviderTelemetry === true;
930
1037
  const now = control.now ?? Date.now;
931
1038
  const setTimer = control.setTimer ?? setTimeout;
@@ -998,7 +1105,10 @@ export async function consumeTurn(q, onEvent, onInit, expectedSessionId, control
998
1105
  const next = iterator.next();
999
1106
  const item = timeout === undefined ? await next : await Promise.race([next, timeout]);
1000
1107
  if (item.done) {
1001
- if (recoveryEnabled && terminalFailure !== undefined)
1108
+ if (strictModelIdentity && !sawInit) {
1109
+ throw new HarnessTurnError('model-unavailable', true, 'provider did not confirm the configured literal model');
1110
+ }
1111
+ if ((recoveryEnabled || strictModelIdentity) && terminalFailure !== undefined)
1002
1112
  throw terminalFailure;
1003
1113
  return { sessionId, sawResult: false };
1004
1114
  }
@@ -1007,12 +1117,16 @@ export async function consumeTurn(q, onEvent, onInit, expectedSessionId, control
1007
1117
  // proof of provider liveness.
1008
1118
  arm();
1009
1119
  if (message.type === 'system' && message.subtype === 'init') {
1120
+ sawInit = true;
1010
1121
  if (expectedSessionId !== undefined && message.session_id !== expectedSessionId) {
1011
1122
  if (sanitizeProviderTelemetry) {
1012
1123
  throw new HarnessTurnError('provider', false, 'provider session identity mismatch (details redacted)');
1013
1124
  }
1014
1125
  throw new Error(`provider session id mismatch: expected ${expectedSessionId}, received ${message.session_id}`);
1015
1126
  }
1127
+ if (strictModelIdentity && message.model !== control.expectedModel) {
1128
+ throw new HarnessTurnError('model-unavailable', true, 'provider did not honor the configured literal model');
1129
+ }
1016
1130
  sessionId = message.session_id;
1017
1131
  // The ONLY place these are observable. The live smoke asserts on the
1018
1132
  // `apiKeySource` here (subscription OAuth vs. an API key), and a later
@@ -1029,8 +1143,14 @@ export async function consumeTurn(q, onEvent, onInit, expectedSessionId, control
1029
1143
  }
1030
1144
  onInit?.(sessionId);
1031
1145
  }
1146
+ else if (message.type === 'system' && message.subtype === 'model_refusal_fallback' && strictModelIdentity) {
1147
+ throw new HarnessTurnError('model-unavailable', true, 'provider attempted a model fallback');
1148
+ }
1032
1149
  else if (message.type === 'result') {
1033
- const classified = recoveryEnabled ? terminalFailure ?? classifyResult(message) : undefined;
1150
+ if (strictModelIdentity && !sawInit) {
1151
+ throw new HarnessTurnError('model-unavailable', true, 'provider did not confirm the configured literal model');
1152
+ }
1153
+ const classified = recoveryEnabled || strictModelIdentity ? terminalFailure ?? classifyResult(message) : undefined;
1034
1154
  if (!sanitizeProviderTelemetry && finalResponse !== undefined) {
1035
1155
  onEvent({ kind: 'assistant_response', text: finalResponse });
1036
1156
  }
@@ -1047,7 +1167,7 @@ export async function consumeTurn(q, onEvent, onInit, expectedSessionId, control
1047
1167
  });
1048
1168
  }
1049
1169
  onEvent({ kind: 'turn_ended' });
1050
- if (recoveryEnabled && classified !== undefined)
1170
+ if ((recoveryEnabled || strictModelIdentity) && classified !== undefined)
1051
1171
  throw classified;
1052
1172
  return { sessionId, sawResult: true };
1053
1173
  }
@@ -1056,10 +1176,10 @@ export async function consumeTurn(q, onEvent, onInit, expectedSessionId, control
1056
1176
  emitAssistant(message, onEvent);
1057
1177
  finalResponse = assistantResponse(message) ?? finalResponse;
1058
1178
  }
1059
- if (recoveryEnabled)
1179
+ if (recoveryEnabled || strictModelIdentity)
1060
1180
  terminalFailure ??= classifyAssistantError(message.error);
1061
1181
  }
1062
- else if (recoveryEnabled && message.type === 'auth_status' && message.error !== undefined) {
1182
+ else if ((recoveryEnabled || strictModelIdentity) && message.type === 'auth_status' && message.error !== undefined) {
1063
1183
  // `error` is a structured SDK field. Its prose is deliberately neither
1064
1184
  // logged nor parsed for recovery decisions.
1065
1185
  throw new HarnessTurnError('authentication', true, 'provider authentication status failed');
@@ -1079,7 +1199,7 @@ export async function consumeTurn(q, onEvent, onInit, expectedSessionId, control
1079
1199
  }
1080
1200
  }
1081
1201
  catch (error) {
1082
- if (!recoveryEnabled)
1202
+ if (!recoveryEnabled && !strictModelIdentity)
1083
1203
  throw error;
1084
1204
  if (terminalFailure?.terminal === true)
1085
1205
  throw terminalFailure;
@@ -1115,6 +1235,14 @@ function errText(err) {
1115
1235
  return err instanceof Error ? err.message : String(err);
1116
1236
  }
1117
1237
  export async function startClaude(args, onEvent, dependencies = DEFAULT_START_DEPENDENCIES) {
1238
+ // Parse and validate host policy before even emitting a start marker: a bad
1239
+ // audit configuration must not construct a provider query or a resumable row.
1240
+ const exactWorkdir = claudeExactWorkdir(process.env);
1241
+ if (exactWorkdir) {
1242
+ const issue = strictWorkdirToolIssue(args.permissions);
1243
+ if (issue !== undefined)
1244
+ throw new HarnessTurnError('configuration', true, issue.message);
1245
+ }
1118
1246
  // The provider token exists before any SDK work. `started` is synchronous by
1119
1247
  // contract, so the caller's fsynced active-row append must return before the
1120
1248
  // query factory can initialize a process or receive prompt bytes.
@@ -1134,7 +1262,7 @@ export async function startClaude(args, onEvent, dependencies = DEFAULT_START_DE
1134
1262
  }
1135
1263
  const env = buildChildEnv(process.env, { allowApiBilling: allowApiBillingFrom(process.env) });
1136
1264
  const abortController = new AbortController();
1137
- const options = buildClaudeOptions(args, { env, abortController, onEvent, sessionId });
1265
+ const options = buildClaudeOptions({ ...args, exactWorkdir }, { env, abortController, onEvent, sessionId });
1138
1266
  let q;
1139
1267
  try {
1140
1268
  // A plain STRING prompt, not an AsyncIterable. Query construction is the
@@ -1201,6 +1329,7 @@ export async function startClaude(args, onEvent, dependencies = DEFAULT_START_DE
1201
1329
  sanitizeProviderTelemetry: args.recoveryPolicy !== undefined,
1202
1330
  abortController,
1203
1331
  close: closeExact,
1332
+ ...(exactWorkdir && options.model !== undefined ? { expectedModel: options.model } : {}),
1204
1333
  onActivity: (activity) => onEvent({ kind: 'activity', ...activity }),
1205
1334
  });
1206
1335
  }
@@ -1231,6 +1360,14 @@ export async function startClaude(args, onEvent, dependencies = DEFAULT_START_DE
1231
1360
  return ref;
1232
1361
  }
1233
1362
  export async function deliverClaude(ref, message, args, onEvent, dependencies = DEFAULT_DELIVER_DEPENDENCIES) {
1363
+ // This must precede the session-info preflight too: an incompatible strict
1364
+ // profile is a configuration error, not a reason to ask the provider first.
1365
+ const exactWorkdir = claudeExactWorkdir(process.env);
1366
+ if (exactWorkdir) {
1367
+ const issue = strictWorkdirToolIssue(args.permissions);
1368
+ if (issue !== undefined)
1369
+ throw new HarnessTurnError('configuration', true, issue.message);
1370
+ }
1234
1371
  // Session lookup is scoped to the PROJECT DIRECTORY, so a deleted worktree can
1235
1372
  // never resume no matter how good the token is. Distinct message on purpose —
1236
1373
  // the caller reads these to tell the two failures apart.
@@ -1275,7 +1412,7 @@ export async function deliverClaude(ref, message, args, onEvent, dependencies =
1275
1412
  // A resumed turn does not inherit permission mode / tool lists / model from the
1276
1413
  // session — they are per-invocation flags — which is exactly why they must be
1277
1414
  // re-mapped here.
1278
- const options = buildClaudeOptions(args, {
1415
+ const options = buildClaudeOptions({ ...args, exactWorkdir }, {
1279
1416
  env,
1280
1417
  abortController,
1281
1418
  onEvent,
@@ -1337,6 +1474,7 @@ export async function deliverClaude(ref, message, args, onEvent, dependencies =
1337
1474
  sanitizeProviderTelemetry: args.recoveryPolicy !== undefined,
1338
1475
  abortController,
1339
1476
  close: closeExact,
1477
+ ...(exactWorkdir && options.model !== undefined ? { expectedModel: options.model } : {}),
1340
1478
  onActivity: (activity) => onEvent({ kind: 'activity', ...activity }),
1341
1479
  });
1342
1480
  }
@@ -94,6 +94,13 @@ export interface GateCall {
94
94
  * `unrestricted` declaration may widen audited filesystem reads only.
95
95
  */
96
96
  filesystem?: FilesystemPermission;
97
+ /**
98
+ * The host-owned exact-work-root boundary. This is deliberately separate from
99
+ * an authored filesystem permission: the latter may describe an unrestricted
100
+ * legacy workflow, while this flag is the narrow audit profile that must never
101
+ * be widened by an approval or an SDK shortcut.
102
+ */
103
+ exactWorkdir?: boolean;
97
104
  }
98
105
  /** The gatekeeper's answer. `reason` is written to be shown to a person and to
99
106
  * the agent, so it names the specific thing that triggered it. */
@@ -102,12 +109,26 @@ export type GateVerdict = {
102
109
  } | {
103
110
  decision: 'escalate';
104
111
  reason: string;
112
+ } | {
113
+ decision: 'deny';
114
+ reason: string;
105
115
  };
106
116
  /** Audited built-ins that cannot mutate the filesystem. WebFetch/WebSearch
107
117
  * can read the unrestricted network without weakening a read-only filesystem.
108
118
  * This is the canonical audited read-tool set used by both the adapter's tool
109
119
  * surface and the explicit unrestricted-filesystem containment exception. */
110
120
  export declare const READ_ONLY_TOOLS: ReadonlySet<string>;
121
+ /** The path-bearing built-ins, derived from the same metadata as extraction. */
122
+ export declare const PATH_BEARING_TOOL_NAMES: ReadonlySet<string>;
123
+ /** Fixed, payload-free guidance for the exact audit boundary. */
124
+ export declare const EXACT_WORKDIR_DENIAL_MESSAGE = "The exact work-root policy denied this path-bearing tool call. Work inside the assigned directory, or call the born-bound `ask` tool on the mounted `owenloop` MCP server if the order cannot be completed there.";
125
+ /**
126
+ * Classify a path-bearing call for the host-controlled exact-work-root policy.
127
+ * It deliberately catches model-authored getters/Proxies and path-normalization
128
+ * errors so an unexpected input cannot make a hook throw and leave the SDK
129
+ * waiting for a response.
130
+ */
131
+ export declare function classifyExactWorkdirPath(call: GateCall): GateVerdict;
111
132
  /**
112
133
  * Whether `candidate` resolves inside `root`.
113
134
  *
@@ -63,14 +63,20 @@ export const READ_ONLY_TOOLS = new Set(['Read', 'Glob', 'Grep', 'WebFetch', 'Web
63
63
  * guessed at.
64
64
  */
65
65
  const PATH_ARGS = Object.freeze({
66
- Read: { args: ['file_path'], humanGateSafeRead: true },
67
- Write: { args: ['file_path'] },
68
- Edit: { args: ['file_path'] },
69
- NotebookRead: { args: ['notebook_path'], humanGateSafeRead: true },
70
- NotebookEdit: { args: ['notebook_path'] },
71
- Glob: { args: ['path'], humanGateSafeRead: true },
72
- Grep: { args: ['path'], humanGateSafeRead: true },
66
+ Read: { args: [{ key: 'file_path' }], humanGateSafeRead: true },
67
+ Write: { args: [{ key: 'file_path' }] },
68
+ Edit: { args: [{ key: 'file_path' }] },
69
+ NotebookRead: { args: [{ key: 'notebook_path' }], humanGateSafeRead: true },
70
+ NotebookEdit: { args: [{ key: 'notebook_path' }] },
71
+ // Glob/Grep schemas deliberately default an omitted path to cwd.
72
+ // Empty, non-string, or inaccessible values are NOT that omission.
73
+ Glob: { args: [{ key: 'path', optional: true }], humanGateSafeRead: true },
74
+ Grep: { args: [{ key: 'path', optional: true }], humanGateSafeRead: true },
73
75
  });
76
+ /** The path-bearing built-ins, derived from the same metadata as extraction. */
77
+ export const PATH_BEARING_TOOL_NAMES = new Set(Object.keys(PATH_ARGS));
78
+ /** Fixed, payload-free guidance for the exact audit boundary. */
79
+ export const EXACT_WORKDIR_DENIAL_MESSAGE = 'The exact work-root policy denied this path-bearing tool call. Work inside the assigned directory, or call the born-bound `ask` tool on the mounted `owenloop` MCP server if the order cannot be completed there.';
74
80
  /**
75
81
  * The owenloop MCP mount, which is ALWAYS allowed under every policy.
76
82
  *
@@ -121,6 +127,40 @@ function stringArg(input, key) {
121
127
  const v = input[key];
122
128
  return typeof v === 'string' && v !== '' ? v : undefined;
123
129
  }
130
+ /**
131
+ * Classify a path-bearing call for the host-controlled exact-work-root policy.
132
+ * It deliberately catches model-authored getters/Proxies and path-normalization
133
+ * errors so an unexpected input cannot make a hook throw and leave the SDK
134
+ * waiting for a response.
135
+ */
136
+ export function classifyExactWorkdirPath(call) {
137
+ const spec = PATH_ARGS[call.toolName];
138
+ if (spec === undefined)
139
+ return ALLOW;
140
+ try {
141
+ if (call.blockedPath !== undefined && call.blockedPath !== '') {
142
+ return { decision: 'deny', reason: EXACT_WORKDIR_DENIAL_MESSAGE };
143
+ }
144
+ for (const arg of spec.args) {
145
+ const present = Object.prototype.hasOwnProperty.call(call.input, arg.key);
146
+ if (!present && arg.optional === true)
147
+ continue;
148
+ if (!present)
149
+ return { decision: 'deny', reason: EXACT_WORKDIR_DENIAL_MESSAGE };
150
+ const value = call.input[arg.key];
151
+ if (typeof value !== 'string' || value === '') {
152
+ return { decision: 'deny', reason: EXACT_WORKDIR_DENIAL_MESSAGE };
153
+ }
154
+ if (!isInside(call.workdir, value)) {
155
+ return { decision: 'deny', reason: EXACT_WORKDIR_DENIAL_MESSAGE };
156
+ }
157
+ }
158
+ return ALLOW;
159
+ }
160
+ catch {
161
+ return { decision: 'deny', reason: EXACT_WORKDIR_DENIAL_MESSAGE };
162
+ }
163
+ }
124
164
  /**
125
165
  * Whether `candidate` resolves inside `root`.
126
166
  *
@@ -166,6 +206,13 @@ export function dangerousCommand(command) {
166
206
  export function classifyToolCall(call, policy) {
167
207
  if (call.toolName.startsWith(OWENLOOP_MCP_PREFIX))
168
208
  return ALLOW;
209
+ // This host profile runs before legacy policy semantics. It is intentionally
210
+ // not an escalation: no human approval can widen the exact snapshot boundary.
211
+ if (call.exactWorkdir === true) {
212
+ const exact = classifyExactWorkdirPath(call);
213
+ if (exact.decision === 'deny')
214
+ return exact;
215
+ }
169
216
  if (policy === 'deny-unapproved') {
170
217
  return { decision: 'escalate', reason: `permissionMode denies unapproved tool calls` };
171
218
  }
@@ -178,7 +225,7 @@ export function classifyToolCall(call, policy) {
178
225
  }
179
226
  const pathArgs = PATH_ARGS[call.toolName];
180
227
  const paths = (pathArgs?.args ?? [])
181
- .map((key) => stringArg(call.input, key))
228
+ .map(({ key }) => stringArg(call.input, key))
182
229
  .filter((p) => p !== undefined);
183
230
  // An explicit unrestricted filesystem declaration widens only the declared
184
231
  // boundary of the shared audited read set. It does not change which operation