@guilz-dev/belay 0.9.3 → 0.10.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.
Files changed (110) hide show
  1. package/README.md +38 -3
  2. package/dist/adapters/codex/hooks.d.ts +1 -0
  3. package/dist/adapters/codex/hooks.js +3 -0
  4. package/dist/adapters/cursor/dispatcher-generation.d.ts +3 -0
  5. package/dist/adapters/cursor/dispatcher-generation.js +5 -0
  6. package/dist/adapters/cursor/hook-dispatch-entry.d.ts +10 -0
  7. package/dist/adapters/cursor/hook-dispatch-entry.js +137 -0
  8. package/dist/adapters/cursor/hook-router.d.ts +23 -0
  9. package/dist/adapters/cursor/hook-router.js +273 -0
  10. package/dist/adapters/cursor/hooks.d.ts +5 -1
  11. package/dist/adapters/cursor/hooks.js +112 -10
  12. package/dist/adapters/cursor/routing-config-trust.d.ts +1 -0
  13. package/dist/adapters/cursor/routing-config-trust.js +67 -0
  14. package/dist/adapters/cursor/routing-layout.d.ts +5 -0
  15. package/dist/adapters/cursor/routing-layout.js +29 -0
  16. package/dist/adapters/cursor/runtime-entry.d.ts +17 -0
  17. package/dist/adapters/cursor/runtime-entry.js +74 -49
  18. package/dist/adapters/layouts/scope.d.ts +5 -0
  19. package/dist/adapters/layouts/scope.js +71 -0
  20. package/dist/adapters/shared/gate-runtime.js +29 -17
  21. package/dist/bundle/claude-runtime.mjs +2428 -2072
  22. package/dist/bundle/codex-runtime.mjs +2440 -2084
  23. package/dist/bundle/cursor-dispatcher.mjs +517 -0
  24. package/dist/bundle/cursor-runtime.mjs +2521 -2133
  25. package/dist/cli.js +53 -4
  26. package/dist/commands/approval-token.d.ts +10 -0
  27. package/dist/commands/approval-token.js +26 -0
  28. package/dist/commands/audit.d.ts +2 -1
  29. package/dist/commands/audit.js +2 -2
  30. package/dist/commands/config.d.ts +1 -1
  31. package/dist/commands/config.js +28 -2
  32. package/dist/commands/doctor.js +149 -17
  33. package/dist/commands/dogfood-check.d.ts +3 -0
  34. package/dist/commands/dogfood-check.js +116 -0
  35. package/dist/commands/dogfood.d.ts +1 -0
  36. package/dist/commands/dogfood.js +4 -3
  37. package/dist/commands/health-snapshot.js +9 -4
  38. package/dist/commands/judge.js +2 -2
  39. package/dist/commands/recovery-checkpoints.d.ts +3 -3
  40. package/dist/commands/recovery-checkpoints.js +2 -11
  41. package/dist/config-io.d.ts +1 -0
  42. package/dist/config-io.js +19 -3
  43. package/dist/core/audit-legacy-archive.js +43 -25
  44. package/dist/core/classify-tool.js +16 -8
  45. package/dist/core/dogfood-environment.d.ts +8 -0
  46. package/dist/core/dogfood-environment.js +55 -0
  47. package/dist/core/effect-ir/argv-delegate.d.ts +9 -0
  48. package/dist/core/effect-ir/argv-delegate.js +42 -0
  49. package/dist/core/effect-ir/shell-lower/argv-delegate-gate.d.ts +3 -0
  50. package/dist/core/effect-ir/shell-lower/argv-delegate-gate.js +40 -0
  51. package/dist/core/effect-ir/shell-lower/augment.d.ts +4 -0
  52. package/dist/core/effect-ir/shell-lower/augment.js +97 -0
  53. package/dist/core/effect-ir/shell-lower/context.d.ts +10 -0
  54. package/dist/core/effect-ir/shell-lower/context.js +1 -0
  55. package/dist/core/effect-ir/shell-lower/decode-process.d.ts +9 -0
  56. package/dist/core/effect-ir/shell-lower/decode-process.js +201 -0
  57. package/dist/core/effect-ir/shell-lower/decoders/belay.d.ts +2 -0
  58. package/dist/core/effect-ir/shell-lower/decoders/belay.js +41 -0
  59. package/dist/core/effect-ir/shell-lower/decoders/builtins.d.ts +7 -0
  60. package/dist/core/effect-ir/shell-lower/decoders/builtins.js +194 -0
  61. package/dist/core/effect-ir/shell-lower/decoders/decode-package-exec.d.ts +4 -0
  62. package/dist/core/effect-ir/shell-lower/decoders/decode-package-exec.js +68 -0
  63. package/dist/core/effect-ir/shell-lower/decoders/docker.d.ts +3 -0
  64. package/dist/core/effect-ir/shell-lower/decoders/docker.js +43 -0
  65. package/dist/core/effect-ir/shell-lower/decoders/filesystem.d.ts +9 -0
  66. package/dist/core/effect-ir/shell-lower/decoders/filesystem.js +217 -0
  67. package/dist/core/effect-ir/shell-lower/decoders/prisma.d.ts +2 -0
  68. package/dist/core/effect-ir/shell-lower/decoders/prisma.js +54 -0
  69. package/dist/core/effect-ir/shell-lower/decoders/ruby.d.ts +11 -0
  70. package/dist/core/effect-ir/shell-lower/decoders/ruby.js +147 -0
  71. package/dist/core/effect-ir/shell-lower/decoders/toolchain.d.ts +7 -0
  72. package/dist/core/effect-ir/shell-lower/decoders/toolchain.js +155 -0
  73. package/dist/core/effect-ir/shell-lower/requirement.d.ts +12 -0
  74. package/dist/core/effect-ir/shell-lower/requirement.js +65 -0
  75. package/dist/core/effect-ir/shell-lower/segment.d.ts +11 -0
  76. package/dist/core/effect-ir/shell-lower/segment.js +82 -0
  77. package/dist/core/effect-ir/shell-lower/tokens.d.ts +26 -0
  78. package/dist/core/effect-ir/shell-lower/tokens.js +183 -0
  79. package/dist/core/effect-ir/shell-lower.d.ts +2 -7
  80. package/dist/core/effect-ir/shell-lower.js +60 -1502
  81. package/dist/core/egress-approval.js +0 -18
  82. package/dist/core/glob.js +32 -16
  83. package/dist/core/integrity.d.ts +2 -2
  84. package/dist/core/integrity.js +52 -12
  85. package/dist/core/notify.d.ts +8 -2
  86. package/dist/core/notify.js +63 -7
  87. package/dist/core/recovery/operator-guidance.js +4 -4
  88. package/dist/core/replay-scrub.d.ts +2 -0
  89. package/dist/core/replay-scrub.js +8 -0
  90. package/dist/core/repo-config-trust.d.ts +31 -0
  91. package/dist/core/repo-config-trust.js +152 -0
  92. package/dist/core/shell-substitution.js +2 -2
  93. package/dist/core/shell-unparseable.js +3 -1
  94. package/dist/corpus/benign-probe-cores.d.ts +1 -1
  95. package/dist/corpus/benign-probe-cores.js +0 -1
  96. package/dist/defaults.d.ts +7 -3
  97. package/dist/defaults.js +29 -47
  98. package/dist/installer/bootstrap.d.ts +1 -0
  99. package/dist/installer/bootstrap.js +2 -2
  100. package/dist/installer/runtime-artifacts.js +43 -13
  101. package/dist/installer/scope-config.js +2 -2
  102. package/dist/installer.js +48 -13
  103. package/dist/node-resolution.d.ts +1 -0
  104. package/dist/node-resolution.js +61 -0
  105. package/dist/templates.d.ts +7 -4
  106. package/dist/templates.js +42 -4
  107. package/dist/types.d.ts +20 -0
  108. package/dist/version.d.ts +1 -1
  109. package/dist/version.js +1 -1
  110. package/package.json +5 -1
@@ -5,7 +5,6 @@ import path from 'node:path';
5
5
  import { compactApprovals, createApprovalRecordWithEnvelope } from '../../core/approval.js';
6
6
  import { buildReplayHint, buildRetryInstructionForConfig, canAutoReplay, getExecutionLeaseMs, validateReplayEnvelope, } from '../../core/approval-replay.js';
7
7
  import { claimApprovedForReplay, gateApprovalStoreFromDeps, recordApproval, } from '../../core/approval-service.js';
8
- import { issueApprovalToken } from '../../core/approval-token.js';
9
8
  import { buildAuditActionSnapshot, buildAuditReplayContext, } from '../../core/audit-replay-context.js';
10
9
  import { approvalCorrelationId, serializeAuditRecordV3, toolInvocationCorrelationId, } from '../../core/audit-serialize.js';
11
10
  import { boundedUtf8Tail } from '../../core/bounded-output.js';
@@ -37,6 +36,7 @@ import { notifyDeny } from '../../core/notify.js';
37
36
  import { canonicalPath } from '../../core/path-utils.js';
38
37
  import { recoveryFailClosedResult, recoveryFailReasonFromSkip, } from '../../core/recovery/fail-closed.js';
39
38
  import { fingerprintReplayPayload, redactToolInvocationId } from '../../core/replay-scrub.js';
39
+ import { assertRepoConfigTrusted } from '../../core/repo-config-trust.js';
40
40
  import { FILE_CHECKPOINT_ISOLATION_UNAVAILABLE, isTransactionalEligible, runTransactionalExecution, TRANSACTIONAL_ALREADY_APPLIED, TRANSACTIONAL_APPROVAL_BYPASS_REASONS, } from '../../core/transactional/index.js';
41
41
  import { buildAuditProvenanceFields } from '../../runtime-provenance.js';
42
42
  import { egressStatus } from '../../services/egress-service.js';
@@ -91,7 +91,15 @@ async function loadJsonFile(filePath, fallback) {
91
91
  export function createDefaultGateRuntimeDeps() {
92
92
  return {
93
93
  async readConfig(configPath) {
94
- return loadJsonFile(configPath, {});
94
+ try {
95
+ return JSON.parse(await readFile(configPath, 'utf8'));
96
+ }
97
+ catch (error) {
98
+ if (error.code === 'ENOENT') {
99
+ return {};
100
+ }
101
+ throw error;
102
+ }
95
103
  },
96
104
  async appendAudit(ctx, event) {
97
105
  const auditPath = path.join(ctx.repoRoot, ctx.config.audit.logPath);
@@ -149,6 +157,7 @@ export function createDefaultGateRuntimeDeps() {
149
157
  }
150
158
  export async function resolveGateConfig(ctx, deps) {
151
159
  const loaded = await deps.readConfig(ctx.configPath);
160
+ await assertRepoConfigTrusted(ctx.repoRoot, ctx.layout.name, loaded);
152
161
  let teamConfig = null;
153
162
  const teamPath = teamConfigPath();
154
163
  if (existsSync(teamPath)) {
@@ -675,7 +684,23 @@ export async function evaluateGatedAction(ctx, deps, params) {
675
684
  ...authorization,
676
685
  egressProxyActive,
677
686
  };
678
- const predicted = await classifyGatedActionAsync(action, ctx.config, enrichedClassifierOptions);
687
+ let predicted = await classifyGatedActionAsync(action, ctx.config, enrichedClassifierOptions);
688
+ if (action.kind === 'tool' &&
689
+ predicted.reason === 'unclassified_tool' &&
690
+ (ctx.config.policy.codexUnmappedTool ?? 'deny') === 'deny') {
691
+ predicted = {
692
+ ...predicted,
693
+ verdict: 'deny_pending_approval',
694
+ reason: 'unmapped_tool',
695
+ assessment: {
696
+ reversibility: 'irreversible',
697
+ external: false,
698
+ blastRadius: 'unknown tool action',
699
+ confidence: 0.5,
700
+ signals: ['unmapped_tool'],
701
+ },
702
+ };
703
+ }
679
704
  if (action.kind === 'shell' &&
680
705
  action.command &&
681
706
  isContainedUnknownExecutionEligible(ctx.config, action, predicted)) {
@@ -910,6 +935,7 @@ async function gateDecisionToVerdict(ctx, deps, kind, result, auditExtras = {})
910
935
  event: auditEvent,
911
936
  sourceEvent,
912
937
  kind,
938
+ repoLabel: path.basename(ctx.repoRoot),
913
939
  ...(auditExtras.toolInvocationCorrelationId
914
940
  ? { toolInvocationCorrelationId: auditExtras.toolInvocationCorrelationId }
915
941
  : {}),
@@ -936,19 +962,6 @@ async function gateDecisionToVerdict(ctx, deps, kind, result, auditExtras = {})
936
962
  if (created) {
937
963
  await recordGateApprovalAsk(stateDir, result.reason, false);
938
964
  }
939
- let approvalToken;
940
- try {
941
- approvalToken = await issueApprovalToken({
942
- approvalId: approval.approvalId,
943
- fingerprint: approval.fingerprint,
944
- repoRoot: approval.repoRoot,
945
- issuedAt: approval.createdAt,
946
- expiresAt: approval.expiresAt,
947
- }, configuredControlPlaneDir(ctx.config));
948
- }
949
- catch {
950
- approvalToken = undefined;
951
- }
952
965
  const denialReason = failure?.reason ?? result.reason;
953
966
  if (ctx.config.notifications.webhookUrl || ctx.config.notifications.commandHook) {
954
967
  await notifyDeny(ctx.config.notifications, {
@@ -957,7 +970,6 @@ async function gateDecisionToVerdict(ctx, deps, kind, result, auditExtras = {})
957
970
  summary: result.normalizedCommand ?? result.summary ?? '',
958
971
  repoRoot: ctx.repoRoot,
959
972
  fingerprint: result.fingerprint,
960
- approvalToken,
961
973
  });
962
974
  }
963
975
  const failureAuditFields = typeof failure?.auditFields === 'function'