@aiwg/cli 2026.11.3 → 2026.11.5

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 (169) hide show
  1. package/agentic/code/addons/aiwg-hooks/canonical/aiwg-prompt-discovery.yaml +3 -2
  2. package/agentic/code/addons/aiwg-hooks/hooks/aiwg-prompt-discovery.cjs +12 -9
  3. package/agentic/code/addons/aiwg-utils/rules/anti-laziness.md +2 -0
  4. package/agentic/code/addons/composition-engine/lib/runtime.mjs +5 -26
  5. package/agentic/code/addons/composition-engine/schemas/flow-graph.schema.json +22 -0
  6. package/agentic/code/providers/capability-matrix.yaml +85 -18
  7. package/agentic/code/providers/model-capabilities.v1.json +35 -27
  8. package/dist/src/a2a/hitl-authorization.js +46 -0
  9. package/dist/src/a2a/hitl-driver.js +5 -5
  10. package/dist/src/artifacts/browser-export.js +2 -0
  11. package/dist/src/artifacts/framework-source-digest.js +1 -1
  12. package/dist/src/artifacts/index-builder.js +9 -27
  13. package/dist/src/artifacts/index-capability.js +24 -0
  14. package/dist/src/artifacts/query-engine-discover-output.js +8 -3
  15. package/dist/src/artifacts/query-engine-rules.js +29 -11
  16. package/dist/src/artifacts/query-engine-scoring.js +5 -5
  17. package/dist/src/artifacts/query-engine-show-card.js +5 -1
  18. package/dist/src/artifacts/query-engine-show-load.js +1 -1
  19. package/dist/src/artifacts/query-engine-show.js +3 -3
  20. package/dist/src/artifacts/query-engine-templates.js +10 -4
  21. package/dist/src/artifacts/query-engine-verbose.js +18 -4
  22. package/dist/src/artifacts/relations-builder.js +1 -0
  23. package/dist/src/artifacts/types.js +1 -1
  24. package/dist/src/cli/handlers/checkpoint-handoff.js +2 -1
  25. package/dist/src/cli/handlers/guided-setup.js +3 -1
  26. package/dist/src/cli/handlers/refresh-managed-deployment.js +17 -5
  27. package/dist/src/cli/handlers/rules.js +1 -1
  28. package/dist/src/cli/handlers/script-runner.js +7 -4
  29. package/dist/src/cli/handlers/sessions.js +1 -1
  30. package/dist/src/cli/handlers/steward-format.js +12 -0
  31. package/dist/src/cli/handlers/steward.js +1 -1
  32. package/dist/src/cli/handlers/use.js +14 -6
  33. package/dist/src/cli/handlers/utility-doctor.js +9 -2
  34. package/dist/src/cli/handlers/workspace.js +1 -1
  35. package/dist/src/cli/services/deployment-probe-scope.js +40 -0
  36. package/dist/src/cli/services/deployment-verification.js +4 -5
  37. package/dist/src/config/aiwg-config.js +6 -0
  38. package/dist/src/config/authorization-cli.js +61 -3
  39. package/dist/src/config/cli-help.js +1 -1
  40. package/dist/src/config/cli.js +4 -2
  41. package/dist/src/config/host-resource-runtime.mjs +1 -1
  42. package/dist/src/config/user-registry.js +9 -1
  43. package/dist/src/config/worker-owner-lock.js +90 -10
  44. package/dist/src/decision/graph-flow-adapter.js +1 -1
  45. package/dist/src/effects/authorization-grant.js +50 -0
  46. package/dist/src/effects/authorization-store.js +130 -0
  47. package/dist/src/effects/index.js +2 -0
  48. package/dist/src/effects/ledger.js +1 -0
  49. package/dist/src/effects/lifecycle.js +1 -1
  50. package/dist/src/effects/reader.js +4 -0
  51. package/dist/src/effects/records.js +4 -0
  52. package/dist/src/effects/schema.js +2 -0
  53. package/dist/src/extensions/claude-hooks-installer.js +7 -7
  54. package/dist/src/extensions/manifest.js +6 -0
  55. package/dist/src/extensions/muse-managed-hooks.js +11 -0
  56. package/dist/src/extensions/project-local-discovery.js +21 -1
  57. package/dist/src/extensions/project-local-scaffold.js +19 -7
  58. package/dist/src/extensions/user-hook-diagnostics.js +32 -0
  59. package/dist/src/extensions/verified-hook-command.js +32 -0
  60. package/dist/src/lint/rule-conflicts.js +52 -0
  61. package/dist/src/lint/runner.js +3 -0
  62. package/dist/src/mcp/cli.mjs +3 -1
  63. package/dist/src/mcp/elicitation.mjs +30 -0
  64. package/dist/src/mcp/grok-build-config.mjs +1 -1
  65. package/dist/src/mcp/muse-native-config.mjs +1 -0
  66. package/dist/src/mcp/server.mjs +2 -0
  67. package/dist/src/mcp/tools/authorization.mjs +78 -0
  68. package/dist/src/models/factory-models.js +144 -0
  69. package/dist/src/models/model-capabilities.v1.json +35 -27
  70. package/dist/src/models/model-discovery.js +7 -3
  71. package/dist/src/models/worker-installation.d.mts +2 -0
  72. package/dist/src/models/worker-installation.mjs +11 -2
  73. package/dist/src/models/worker-invocation-policy.js +25 -1
  74. package/dist/src/models/wrapper-enforcement.js +1 -1
  75. package/dist/src/policy/authorization-capture.js +64 -0
  76. package/dist/src/policy/authorization-operations.js +108 -0
  77. package/dist/src/policy/hitl-check.js +3 -2
  78. package/dist/src/policy/hitl-consume.js +14 -0
  79. package/dist/src/policy/hitl-durable-store.js +60 -0
  80. package/dist/src/policy/hitl-durable.js +60 -0
  81. package/dist/src/policy/hitl-receipt.js +5 -0
  82. package/dist/src/policy/hitl.js +44 -6
  83. package/dist/src/policy/repo-access.js +3 -1
  84. package/dist/src/process/bounded-child-process.mjs +49 -39
  85. package/dist/src/providers/capability-matrix.yaml +85 -18
  86. package/dist/src/providers/deployment-ownership.d.mts +1 -0
  87. package/dist/src/providers/deployment-ownership.mjs +29 -3
  88. package/dist/src/providers/deployment-preservation.mjs +44 -3
  89. package/dist/src/providers/grok-build-acp.js +13 -5
  90. package/dist/src/providers/grok-build-dispatch.js +35 -2
  91. package/dist/src/providers/grok-build-headless.js +171 -77
  92. package/dist/src/providers/grok-build-inspect.js +1 -0
  93. package/dist/src/providers/grok-build-paths.js +2 -0
  94. package/dist/src/providers/muse-paths.js +4 -2
  95. package/dist/src/providers/provider-context-contracts.js +12 -4
  96. package/dist/src/providers/provider-definition-schema.js +6 -0
  97. package/dist/src/providers/provider-seeds-1.js +3 -3
  98. package/dist/src/providers/provider-seeds-2.js +6 -4
  99. package/dist/src/providers/provider-seeds-3.js +6 -6
  100. package/dist/src/rules/activation.d.mts +2 -0
  101. package/dist/src/rules/activation.mjs +16 -7
  102. package/dist/src/rules/inline-budget.d.mts +2 -1
  103. package/dist/src/rules/inline-budget.mjs +4 -2
  104. package/dist/src/rules/inventory.js +3 -0
  105. package/dist/src/rules/precedence.d.mts +6 -0
  106. package/dist/src/rules/precedence.mjs +49 -0
  107. package/dist/src/rules/project-precedence.js +73 -0
  108. package/dist/src/rules/rule-frontmatter.schema.json +15 -0
  109. package/dist/src/serve/a2a-terminal-observer.js +12 -3
  110. package/dist/src/serve/mission-hitl.js +20 -1
  111. package/dist/src/serve/worker-stdin-frame.mjs +1 -1
  112. package/dist/src/sessions/adapters/grok-build-fallback.js +33 -0
  113. package/dist/src/sessions/adapters/grok-build-native-records.js +134 -0
  114. package/dist/src/sessions/adapters/grok-build-native.js +237 -98
  115. package/dist/src/sessions/adapters/grok-build.js +95 -32
  116. package/dist/src/sessions/grok-build-cli-output.js +113 -0
  117. package/dist/src/sessions/grok-build-cli.js +4 -28
  118. package/dist/src/sessions/normalization.js +1 -1
  119. package/dist/src/smiths/context-pipeline/bridge-ownership.js +4 -3
  120. package/dist/src/smiths/context-pipeline/finalization.js +5 -0
  121. package/dist/src/smiths/context-pipeline/generator.js +1 -1
  122. package/dist/src/smiths/context-pipeline/workspace-bootstrap.js +20 -17
  123. package/dist/src/smiths/context-pipeline/workspace-doctor.js +6 -1
  124. package/dist/src/smiths/context-pipeline/workspace-document.js +6 -0
  125. package/dist/src/smiths/context-pipeline/workspace-migration.js +2 -12
  126. package/dist/src/smiths/hook-bridge/codex-translator.js +11 -14
  127. package/dist/src/smiths/hook-bridge/codex-trust.js +7 -2
  128. package/dist/src/smiths/hook-bridge/copilot-translator.js +2 -1
  129. package/dist/src/smiths/hook-bridge/factory-trust.js +2 -2
  130. package/dist/src/smiths/hook-bridge/grok-build-translator.js +3 -1
  131. package/dist/src/smiths/hook-bridge/hermes-prompt-discovery.js +81 -0
  132. package/dist/src/smiths/hook-bridge/hermes-translator.js +5 -3
  133. package/dist/src/smiths/hook-bridge/hermes-trust.js +65 -0
  134. package/dist/src/smiths/hook-bridge/index.js +3 -1
  135. package/dist/src/smiths/hook-bridge/prompt-discovery-gaps.js +3 -2
  136. package/package.json +7 -1
  137. package/tools/agents/deploy-agents.mjs +9 -8
  138. package/tools/agents/deploy-options.mjs +3 -0
  139. package/tools/agents/providers/base-frontmatter.mjs +3 -2
  140. package/tools/agents/providers/base-inventory.mjs +3 -1
  141. package/tools/agents/providers/base-kernel-skills.mjs +11 -5
  142. package/tools/agents/providers/claude-post-deploy.mjs +1 -1
  143. package/tools/agents/providers/codex-post-deploy.mjs +1 -1
  144. package/tools/agents/providers/generic.mjs +66 -0
  145. package/tools/agents/providers/grok-build.mjs +34 -41
  146. package/tools/agents/providers/model-wrapper.mjs +2 -5
  147. package/tools/agents/providers/muse-hooks.mjs +13 -11
  148. package/tools/agents/providers/muse-prompt-discovery.mjs +5 -1
  149. package/tools/agents/providers/muse.mjs +2 -1
  150. package/tools/agents/providers/openclaw.mjs +2 -1
  151. package/tools/agents/providers/rule-deployment-commit.mjs +3 -0
  152. package/tools/agents/providers/rule-deployment-prepare.mjs +7 -5
  153. package/tools/agents/providers/rule-deployment-state.mjs +14 -6
  154. package/tools/agents/providers/rule-projection.mjs +39 -4
  155. package/tools/agents/providers/rule-startup.mjs +11 -10
  156. package/tools/agents/providers/skill-copy-prune.mjs +12 -0
  157. package/tools/agents/providers/staged-directory-reference.mjs +14 -0
  158. package/tools/agents/providers/stale-artifact-prune.mjs +24 -10
  159. package/tools/agents/providers/user-hooks.mjs +26 -0
  160. package/tools/cli/authorization-health.mjs +20 -0
  161. package/tools/cli/workspace-status.mjs +7 -0
  162. package/tools/commands/deploy-prompts-codex.mjs +15 -1
  163. package/tools/ralph-external/lib/claude-adapter.mjs +2 -0
  164. package/tools/ralph-external/lib/factory-adapter.mjs +6 -2
  165. package/tools/ralph-external/lib/worker-inputs.mjs +20 -1
  166. package/tools/ralph-external/lib/worker-isolation.mjs +1 -0
  167. package/tools/ralph-external/lib/worker-termination.mjs +21 -12
  168. package/tools/ralph-external/session-launcher.mjs +22 -17
  169. package/vscode-extension/schemas/aiwg.config.v1.json +20 -0
@@ -341,6 +341,8 @@ export class ClaudeAdapter extends ProviderAdapter {
341
341
  * inherited from ProviderAdapter.
342
342
  */
343
343
  export class ClaudeDirectAdapter extends ClaudeAdapter {
344
+ getName() { return 'claude-direct'; }
345
+
344
346
  async parseWorkerFinal(output, options = {}) {
345
347
  // MCP envelopes retain the shared strict parser. Every other input must be
346
348
  // Claude's own stream-json transcript with a validated terminal result: the
@@ -202,8 +202,12 @@ export class FactoryAdapter extends ProviderAdapter {
202
202
  if (FACTORY_RESERVED_MODEL_VALUES.includes(model.toLowerCase())) {
203
203
  throw new Error(`Factory worker requires an explicit observed model, not the CLI's own auto-selection '${model}'`);
204
204
  }
205
+ if (model.startsWith('custom:') && (model.trim() !== model || !/^custom:[^\s\x00-\x1f\x7f]+-\d+$/.test(model))) {
206
+ throw new Error('Factory custom model selector requires a safe normalized name and numeric suffix');
207
+ }
205
208
  const effort = invocation?.selected?.effort?.value ?? null;
206
- if (effort === null || !FACTORY_DIRECT_EFFORT_VALUES.includes(effort)) {
209
+ const customNoEffort = model.startsWith('custom:') && invocation?.selected?.effort?.support === 'not-applicable' && effort === null;
210
+ if (!customNoEffort && (effort === null || !FACTORY_DIRECT_EFFORT_VALUES.includes(effort))) {
207
211
  throw new Error('Factory worker requires an explicit qualified reasoning effort (never a CLI default)');
208
212
  }
209
213
  const sandbox = permissions?.sandbox ?? 'workspace-write';
@@ -225,7 +229,7 @@ export class FactoryAdapter extends ProviderAdapter {
225
229
  const auto = FACTORY_SANDBOX_TO_AUTO[sandbox];
226
230
  const args = ['exec'];
227
231
  if (auto) args.push('--auto', auto);
228
- args.push('-m', model, '-r', effort, '--cwd', cwd, '--output-format', 'stream-json');
232
+ args.push('-m', model, ...(customNoEffort ? [] : ['-r', effort]), '--cwd', cwd, '--output-format', 'stream-json');
229
233
  return args;
230
234
  }
231
235
 
@@ -1,7 +1,7 @@
1
1
  // Read bounded worker inputs through pinned, no-follow directory handles.
2
2
  import { constants } from 'node:fs';
3
3
  import { open } from 'node:fs/promises';
4
- import { isAbsolute } from 'node:path';
4
+ import { basename, dirname, isAbsolute } from 'node:path';
5
5
 
6
6
  // Linux directory handles pin each ancestor. O_NOFOLLOW on a pathname alone
7
7
  // cannot protect an ancestor that the worker replaces after inspection.
@@ -19,6 +19,25 @@ export async function withWorkerPath(filename, operation) {
19
19
  } finally { await directory.close(); }
20
20
  }
21
21
 
22
+ // Reuse one pinned directory for a batch of direct-child operations. Every
23
+ // ancestor and the directory itself are still opened with O_NOFOLLOW;
24
+ // callers retain the leaf operation's own no-follow/exclusive-create checks.
25
+ export async function withWorkerDirectory(directory, operation) {
26
+ return withWorkerPath(directory, async anchored => {
27
+ const handle = await open(anchored, constants.O_RDONLY | constants.O_DIRECTORY | constants.O_NOFOLLOW);
28
+ try {
29
+ return await operation(async (filename, action) => {
30
+ if (filename.includes('\0') || filename.split('/').includes('..')
31
+ || (filename !== directory && dirname(filename) !== directory)) {
32
+ throw new Error('Invalid worker path outside pinned directory');
33
+ }
34
+ const leaf = filename === directory ? '.' : basename(filename);
35
+ return action(`/proc/self/fd/${handle.fd}/${leaf}`);
36
+ });
37
+ } finally { await handle.close(); }
38
+ });
39
+ }
40
+
22
41
  // #2915 review 4 (finding 4): `privateOutput: true` REPAIRS a loose mode
23
42
  // (chmod 0600) rather than rejecting it — correct for the worker's own
24
43
  // final-output file, which the launcher itself created and is free to
@@ -249,6 +249,7 @@ export function launchIsolatedWorker({
249
249
  const outcome = {
250
250
  launched: Number.isInteger(child.pid) && child.pid > 0,
251
251
  mode: detected.mode, child, pid: child.pid,
252
+ ownedGroup: ownedGroup === true,
252
253
  ...(attached ? { transportSupervisor: true } : {}),
253
254
  diagnostic: nativeSandbox ? 'Native CLI sandbox boundary; no cgroup resource confinement' : `launched without resource confinement: ${detected.reason}`,
254
255
  gate: resolvedGate,
@@ -8,7 +8,7 @@ const TERMINATION_BUDGET_MS = 2000;
8
8
  const TERMINATION_ATTEMPT_MS = 100;
9
9
  const TERMINATION_MAX_ATTEMPTS = 21;
10
10
 
11
- export function observeWorkerTermination({ mode, native, workerExited, identity,
11
+ export function observeWorkerTermination({ mode, native, workerExited, identity, detachedPid,
12
12
  supervisor = sampleWorkerIdentity(process.pid), kill = process.kill, invocationId,
13
13
  scan = scanWorkerInvocationProcesses, groupStates = sampleGroupStates, deadline, now = () => performance.now() } = {}) {
14
14
  if (mode === 'systemd-unit') {
@@ -18,20 +18,33 @@ export function observeWorkerTermination({ mode, native, workerExited, identity,
18
18
  ? 'unit inactive evidence' : native?.cgroupEmpty !== true ? 'empty unit cgroup (TasksCurrent=0)' : null };
19
19
  }
20
20
  if (!workerExited) return { confirmed: false, missing: 'launcher-observed worker exit' };
21
- if (!identity || identity.pid !== identity.pgid || identity.uid !== process.getuid?.()
22
- || !supervisor || identity.host !== supervisor.host || identity.bootId !== supervisor.bootId
23
- || !isSafeWorkerGroupTarget(identity.pgid, supervisor)) {
21
+ // A successful detached spawn establishes pgid=pid even if /proc vanished
22
+ // before capture. This is read-only containment evidence, never a recovered
23
+ // birth identity or signal authority. The launcher's birth is a conservative
24
+ // lower bound for descendants; without worker birth, unreadable processes
25
+ // retain the scan's stricter fail-closed handling (no ancestry exclusions).
26
+ const group = identity ?? (Number.isSafeInteger(detachedPid) && supervisor?.pid === process.pid
27
+ && /^\d+$/.test(supervisor.startTicks ?? '') ? {
28
+ pid: detachedPid, pgid: detachedPid, uid: supervisor.uid,
29
+ host: supervisor.host, bootId: supervisor.bootId, startTicks: supervisor.startTicks,
30
+ } : null);
31
+ if (!group || group.pid !== group.pgid || group.uid !== process.getuid?.()
32
+ || !supervisor || group.host !== supervisor.host || group.bootId !== supervisor.bootId
33
+ || !isSafeWorkerGroupTarget(group.pgid, supervisor)) {
24
34
  return { confirmed: false, missing: 'launcher-owned process group identity on this host and boot' };
25
35
  }
36
+ const scanOptions = { invocationId, startTicks: group.startTicks, uid: group.uid, now,
37
+ deadline: deadline ?? now() + TERMINATION_BUDGET_MS,
38
+ ...(identity ? { workerPid: identity.pid, workerPgid: identity.pgid, workerSession: identity.sessionId } : {}) };
26
39
  let groupEmpty = false;
27
40
  try {
28
- kill(-identity.pgid, 0);
41
+ kill(-group.pgid, 0);
29
42
  // Signal 0 also reaches zombies. A reaper that never waits (a container's
30
43
  // PID 1) can leave killed members as zombies indefinitely; a group whose
31
44
  // remaining members are all zombies has no live process (#3853).
32
45
  // Absence from /proc is never proof; only observed zombies explaining
33
46
  // signal 0, with no live or unreadable member, count as an empty group.
34
- const states = groupStates(identity.pgid);
47
+ const states = groupStates(group.pgid);
35
48
  groupEmpty = !!states && states.zombies > 0 && states.live === 0 && states.unreadable === 0;
36
49
  }
37
50
  catch (error) {
@@ -42,16 +55,12 @@ export function observeWorkerTermination({ mode, native, workerExited, identity,
42
55
  if (error.code === 'ESRCH') {
43
56
  // A standalone observation gets one scan, at most 2 s. An explicit
44
57
  // deadline leaves the shared budget and retries to its caller.
45
- return scan({ invocationId, startTicks: identity.startTicks, uid: identity.uid, now,
46
- deadline: deadline ?? now() + TERMINATION_BUDGET_MS,
47
- workerPid: identity.pid, workerPgid: identity.pgid, workerSession: identity.sessionId });
58
+ return scan(scanOptions);
48
59
  }
49
60
  return { confirmed: false, missing: `empty owned process group (signal-0 returned ${error.code ?? 'unknown'})` };
50
61
  }
51
62
  if (groupEmpty) {
52
- return scan({ invocationId, startTicks: identity.startTicks, uid: identity.uid, now,
53
- deadline: deadline ?? now() + TERMINATION_BUDGET_MS,
54
- workerPid: identity.pid, workerPgid: identity.pgid, workerSession: identity.sessionId });
63
+ return scan(scanOptions);
55
64
  }
56
65
  return { confirmed: false, missing: 'empty owned process group (signal-0 still finds members)', retryable: true };
57
66
  }
@@ -49,7 +49,7 @@ import { ScopedFailureBreaker, attributeFailureScope } from './lib/consecutive-f
49
49
  import { assertManagedWorkerLaunch, validateManagedAttempt } from './lib/managed-worker-attempt.mjs';
50
50
  export { assertManagedWorkerLaunch } from './lib/managed-worker-attempt.mjs';
51
51
  import { buildSessionEnvironment } from './lib/session-environment.mjs';
52
- import { withWorkerPath, boundedPrivateRead } from './lib/worker-inputs.mjs';
52
+ import { withWorkerPath, withWorkerDirectory, boundedPrivateRead } from './lib/worker-inputs.mjs';
53
53
  import { collectWorkerFinal } from './lib/worker-final.mjs';
54
54
  import { workerRunDirectoryRefusal } from './lib/worker-run-directory-refusal.mjs';
55
55
  import { workerPromptBrief } from './lib/worker-prompt.mjs';
@@ -1144,7 +1144,8 @@ async function captureOneWorker(owner, ctx) {
1144
1144
  // Require positive kernel evidence of owned containment being empty.
1145
1145
  const terminationEvidence = outcome.mode !== 'systemd-unit' && child.pid === undefined
1146
1146
  ? { confirmed: true, missing: null } : await settleWorkerTermination({ mode: outcome.mode, native,
1147
- workerExited: sawExit, identity, supervisor, invocationId });
1147
+ workerExited: sawExit, identity, supervisor, invocationId,
1148
+ detachedPid: !hasTransport && outcome.ownedGroup === true ? child.pid : undefined });
1148
1149
  const confirmed = terminationEvidence.confirmed;
1149
1150
  // `worker-exit.json`/`worker-identity.json` are written into a directory
1150
1151
  // the worker itself can reach (same UID, no filesystem confinement), so a
@@ -1819,7 +1820,8 @@ async function captureOneWorkerBaseline(owner, ctx) {
1819
1820
  const members = identity ? sampleWorkerGroup(identity.pgid) : null;
1820
1821
  const terminationEvidence = outcome.mode !== 'systemd-unit' && child.pid === undefined
1821
1822
  ? { confirmed: true, missing: null } : await settleWorkerTermination({ mode: outcome.mode, native,
1822
- workerExited: sawExit, identity, supervisor, invocationId });
1823
+ workerExited: sawExit, identity, supervisor, invocationId,
1824
+ detachedPid: !hasTransport && outcome.ownedGroup === true ? child.pid : undefined });
1823
1825
  const confirmed = terminationEvidence.confirmed;
1824
1826
  const workerExit = hasTransport ? await transportRecord('worker-exit.json') : null;
1825
1827
  if (!identity && hasTransport && nativeSupervisor) {
@@ -2301,10 +2303,10 @@ function strictLedgerJson(text) {
2301
2303
  * (someone else already created it) -- never throws for that one case, so
2302
2304
  * callers can treat "lost the create race" as an ordinary branch rather
2303
2305
  * than an exception. */
2304
- async function createLedgerFileExclusive(dir, name, content) {
2306
+ async function createLedgerFileExclusive(dir, name, content, withPath) {
2305
2307
  let handle;
2306
2308
  try {
2307
- handle = await withWorkerPath(join(dir, name), target =>
2309
+ handle = await withPath(join(dir, name), target =>
2308
2310
  open(target, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | constants.O_NOFOLLOW, 0o600));
2309
2311
  } catch (error) {
2310
2312
  if (error.code === 'EEXIST') return false;
@@ -2354,13 +2356,13 @@ const LEDGER_POLICY_LINK_RECHECK_ATTEMPTS = 4;
2354
2356
  * (attempt/correction slots and their `.charged` markers) keeps the
2355
2357
  * unconditional nlink-1 rule -- nothing ever legitimately double-links
2356
2358
  * them. */
2357
- async function statLedgerChainEntry(dir, name) {
2359
+ async function statLedgerChainEntry(dir, name, withPath = withWorkerPath) {
2358
2360
  const target = join(dir, name);
2359
- let stat = await withWorkerPath(target, t => lstat(t));
2361
+ let stat = await withPath(target, t => lstat(t));
2360
2362
  if (name === 'policy') {
2361
2363
  for (let attempt = 0; attempt < LEDGER_POLICY_LINK_RECHECK_ATTEMPTS && stat.nlink === 2; attempt += 1) {
2362
2364
  await new Promise(resolve => setTimeout(resolve, LEDGER_POLICY_LINK_RECHECK_MS));
2363
- stat = await withWorkerPath(target, t => lstat(t));
2365
+ stat = await withPath(target, t => lstat(t));
2364
2366
  }
2365
2367
  }
2366
2368
  return stat;
@@ -2480,9 +2482,9 @@ const CORRECTION_CHARGED_NAME_RE = /^correction-([1-9][0-9]*)\.charged$/;
2480
2482
  * whatever `policy` already pinned -- a correction reserved moments after
2481
2483
  * its attempt handle re-runs this against the CURRENT directory contents,
2482
2484
  * never trusting that nothing changed since the attempt's own reserve. */
2483
- async function validateLedgerChainDirectory(dir, policy) {
2485
+ async function validateLedgerChainDirectory(dir, policy, withPath) {
2484
2486
  let entries;
2485
- try { entries = await withWorkerPath(dir, target => readdir(target)); }
2487
+ try { entries = await withPath(dir, target => readdir(target)); }
2486
2488
  catch (error) { if (error.code === 'ENOENT') return; throw error; }
2487
2489
  if (entries.length > LEDGER_DIR_MAX_ENTRIES) {
2488
2490
  ledgerFail(LEDGER_RECORD_INVALID_CODE, 'Allowance ledger directory has more entries than expected');
@@ -2504,7 +2506,7 @@ async function validateLedgerChainDirectory(dir, policy) {
2504
2506
  }
2505
2507
  }
2506
2508
  let stat;
2507
- try { stat = await statLedgerChainEntry(dir, name); }
2509
+ try { stat = await statLedgerChainEntry(dir, name, withPath); }
2508
2510
  catch (error) { ledgerFail(LEDGER_RECORD_INVALID_CODE, `Allowance ledger entry '${name}' is not inspectable (${error.message})`); }
2509
2511
  if (!stat.isFile() || stat.uid !== process.getuid() || (stat.mode & 0o777) !== 0o600) {
2510
2512
  ledgerFail(LEDGER_RECORD_INVALID_CODE, `Allowance ledger entry '${name}' is not a canonical conductor-owned 0600 regular file`);
@@ -2582,7 +2584,7 @@ async function ensureLedgerChain({ captureRoot, taskChainDigest, maxAttempts, af
2582
2584
  }
2583
2585
  for (const parent of parents.reverse()) await syncLedgerDirectory(parent);
2584
2586
  const policy = await ensureLedgerPolicy(dir, ledgerRoot, taskChainDigest, maxAttempts, afterPolicyWrite);
2585
- await validateLedgerChainDirectory(dir, policy);
2587
+ await withWorkerDirectory(dir, withPath => validateLedgerChainDirectory(dir, policy, withPath));
2586
2588
  return { dir, policy };
2587
2589
  }
2588
2590
 
@@ -2599,11 +2601,11 @@ async function ensureLedgerChain({ captureRoot, taskChainDigest, maxAttempts, af
2599
2601
  * crit-round8 D1: "Lowest-free scanning is safe for the ceiling, not a
2600
2602
  * snapshot of availability"). Returns the won slot number, or `null` once
2601
2603
  * both passes find nothing free. */
2602
- async function reserveLedgerSlotFile(dir, prefix, ceiling, invocationId, { beforeRescan } = {}) {
2604
+ async function reserveLedgerSlotFile(dir, prefix, ceiling, invocationId, { beforeRescan, withPath }) {
2603
2605
  for (let pass = 0; pass < 2; pass += 1) {
2604
2606
  for (let n = 1; n <= ceiling; n += 1) {
2605
2607
  // eslint-disable-next-line no-await-in-loop
2606
- if (await createLedgerFileExclusive(dir, `${prefix}-${n}`, invocationId)) return n;
2608
+ if (await createLedgerFileExclusive(dir, `${prefix}-${n}`, invocationId, withPath)) return n;
2607
2609
  }
2608
2610
  if (pass === 0 && beforeRescan) await beforeRescan();
2609
2611
  }
@@ -2857,7 +2859,8 @@ export async function reserveDirectWorkerAllowance({ captureRoot, taskChainDiges
2857
2859
  dir: null, maxAttempts: chain.maxAttempts });
2858
2860
  }
2859
2861
  const { dir, policy } = await ensureLedgerChain({ captureRoot, taskChainDigest, maxAttempts, afterPolicyWrite });
2860
- const n = await reserveLedgerSlotFile(dir, 'attempt', policy.maxAttempts, invocationId, { beforeRescan: rescan });
2862
+ const n = await withWorkerDirectory(dir, withPath =>
2863
+ reserveLedgerSlotFile(dir, 'attempt', policy.maxAttempts, invocationId, { beforeRescan: rescan, withPath }));
2861
2864
  if (n == null) {
2862
2865
  const occupied = await describeOccupiedLedgerSlots(dir, 'attempt', policy.maxAttempts);
2863
2866
  ledgerFail(ALLOWANCE_EXHAUSTED_CODE, `Task-chain allowance exhausted (${policy.maxAttempts} attempt(s)); occupied: ${occupied}`);
@@ -3031,8 +3034,10 @@ export async function reserveLedgerCorrection({ ledger, reasonCode,
3031
3034
  const chain = _inProcessLedgerChains.get(ledger.taskChainDigest);
3032
3035
  n = chain ? reserveLedgerSlotInProcess(chain.corrections, ceiling, ledger.invocationId) : null;
3033
3036
  } else {
3034
- await validateLedgerChainDirectory(ledger.dir, { maxAttempts: ledger.maxAttempts, maxCorrections: ceiling });
3035
- n = await reserveLedgerSlotFile(ledger.dir, 'correction', ceiling, ledger.invocationId);
3037
+ await withWorkerDirectory(ledger.dir, withPath =>
3038
+ validateLedgerChainDirectory(ledger.dir, { maxAttempts: ledger.maxAttempts, maxCorrections: ceiling }, withPath));
3039
+ n = await withWorkerDirectory(ledger.dir, withPath =>
3040
+ reserveLedgerSlotFile(ledger.dir, 'correction', ceiling, ledger.invocationId, { withPath }));
3036
3041
  }
3037
3042
  if (n == null) return startupCorrectionGate({ correctionsUsed: ceiling, reasonCode });
3038
3043
  if (afterCorrectionReserved) await afterCorrectionReserved();
@@ -1239,6 +1239,26 @@
1239
1239
  "type": "object",
1240
1240
  "additionalProperties": false,
1241
1241
  "properties": {
1242
+ "precedence": {
1243
+ "type": "object",
1244
+ "description": "Per-rule ordering overrides. Non-overridable rules reject every override; rule IDs must resolve unambiguously.",
1245
+ "propertyNames": {
1246
+ "minLength": 1,
1247
+ "not": { "enum": ["__proto__", "prototype", "constructor"] }
1248
+ },
1249
+ "additionalProperties": {
1250
+ "type": "object",
1251
+ "minProperties": 1,
1252
+ "additionalProperties": false,
1253
+ "properties": {
1254
+ "tier": { "type": "string", "enum": ["critical", "high", "medium", "low"] },
1255
+ "project_context": {
1256
+ "type": "boolean",
1257
+ "description": "Explicitly allow WORKSPACE.md project context to outrank this rule."
1258
+ }
1259
+ }
1260
+ }
1261
+ },
1242
1262
  "inline_budget_tokens": {
1243
1263
  "type": "integer",
1244
1264
  "minimum": 0,