@evomap/evolver-core 2.0.0-beta.2 → 2.0.0-beta.22

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 (240) hide show
  1. package/assets/gep/genes.jsonl +5 -5
  2. package/dist/algo/bans.d.ts +10 -1
  3. package/dist/algo/bans.js +56 -6
  4. package/dist/algo/candidateAssembly.d.ts +25 -2
  5. package/dist/algo/candidateAssembly.js +171 -26
  6. package/dist/algo/capabilityCandidates.js +10 -0
  7. package/dist/algo/conversationSniffer.js +25 -8
  8. package/dist/algo/cycleEngine.d.ts +63 -5
  9. package/dist/algo/cycleEngine.js +320 -42
  10. package/dist/algo/cycleFailureClassifier.d.ts +1 -1
  11. package/dist/algo/evolutionEvent.d.ts +26 -0
  12. package/dist/algo/evolutionEvent.js +32 -0
  13. package/dist/algo/exploration.d.ts +7 -0
  14. package/dist/algo/exploration.js +16 -3
  15. package/dist/algo/geneHealth.d.ts +36 -3
  16. package/dist/algo/geneHealth.js +47 -4
  17. package/dist/algo/geneIntake.d.ts +46 -1
  18. package/dist/algo/geneIntake.js +121 -10
  19. package/dist/algo/geneSelection.d.ts +126 -6
  20. package/dist/algo/geneSelection.js +479 -36
  21. package/dist/algo/index.d.ts +6 -1
  22. package/dist/algo/index.js +6 -1
  23. package/dist/algo/kautoProjection.d.ts +41 -0
  24. package/dist/algo/kautoProjection.js +95 -0
  25. package/dist/algo/kautoValidator.d.ts +68 -0
  26. package/dist/algo/kautoValidator.js +256 -0
  27. package/dist/algo/memoryGraph.d.ts +62 -0
  28. package/dist/algo/memoryGraph.js +86 -0
  29. package/dist/algo/orchestrator.d.ts +17 -1
  30. package/dist/algo/orchestrator.js +30 -4
  31. package/dist/algo/publishEligibility.d.ts +34 -0
  32. package/dist/algo/publishEligibility.js +52 -0
  33. package/dist/algo/solidify.d.ts +11 -2
  34. package/dist/algo/solidify.js +37 -7
  35. package/dist/algo/ucb1.d.ts +53 -0
  36. package/dist/algo/ucb1.js +156 -0
  37. package/dist/assetrepair/hubRejection.d.ts +12 -0
  38. package/dist/assetrepair/hubRejection.js +109 -0
  39. package/dist/assetrepair/index.d.ts +2 -0
  40. package/dist/assetrepair/index.js +2 -0
  41. package/dist/assetrepair/repair.d.ts +33 -0
  42. package/dist/assetrepair/repair.js +155 -0
  43. package/dist/assetstore/assetSidecarRecords.d.ts +28 -0
  44. package/dist/assetstore/assetSidecarRecords.js +384 -0
  45. package/dist/assetstore/assetSidecarRecovery.d.ts +48 -0
  46. package/dist/assetstore/assetSidecarRecovery.js +288 -0
  47. package/dist/assetstore/assetStoreHealth.d.ts +81 -0
  48. package/dist/assetstore/assetStoreHealth.js +319 -0
  49. package/dist/assetstore/assetStoreLayout.d.ts +2 -0
  50. package/dist/assetstore/assetStoreLayout.js +6 -0
  51. package/dist/assetstore/assetStoreStorage.d.ts +42 -0
  52. package/dist/assetstore/assetStoreStorage.js +336 -0
  53. package/dist/assetstore/assetSyncLedger.d.ts +91 -1
  54. package/dist/assetstore/assetSyncLedger.js +718 -59
  55. package/dist/assetstore/foreignJsonlSource.d.ts +48 -0
  56. package/dist/assetstore/foreignJsonlSource.js +150 -0
  57. package/dist/assetstore/index.d.ts +5 -0
  58. package/dist/assetstore/index.js +5 -0
  59. package/dist/assetstore/learningHistory.js +3 -3
  60. package/dist/assetstore/localAssetStoreSnapshot.d.ts +51 -0
  61. package/dist/assetstore/localAssetStoreSnapshot.js +329 -0
  62. package/dist/assetstore/localJsonl.d.ts +12 -1
  63. package/dist/assetstore/localJsonl.js +251 -42
  64. package/dist/assetstore/provenance.d.ts +93 -4
  65. package/dist/assetstore/provenance.js +368 -84
  66. package/dist/assetstore/provider.d.ts +63 -0
  67. package/dist/assetstore/provider.js +97 -6
  68. package/dist/assetstore/reviewFilter.d.ts +19 -1
  69. package/dist/assetstore/reviewFilter.js +39 -1
  70. package/dist/assetstore/reviewLedger.d.ts +8 -2
  71. package/dist/assetstore/reviewLedger.js +71 -45
  72. package/dist/assetstore/unionReadStore.d.ts +25 -0
  73. package/dist/assetstore/unionReadStore.js +119 -0
  74. package/dist/benchmark/antiGeneBenchmark.d.ts +2 -0
  75. package/dist/benchmark/antiGeneBenchmark.js +4 -3
  76. package/dist/benchmark/antiGeneRollout.d.ts +2 -0
  77. package/dist/benchmark/antiGeneRollout.js +4 -3
  78. package/dist/benchmark/index.d.ts +3 -1
  79. package/dist/benchmark/index.js +3 -1
  80. package/dist/benchmark/selectionFlatAbstention.d.ts +152 -0
  81. package/dist/benchmark/selectionFlatAbstention.js +481 -0
  82. package/dist/benchmark/triggerShift.d.ts +62 -0
  83. package/dist/benchmark/triggerShift.js +106 -0
  84. package/dist/bootstrap/envFingerprint.d.ts +9 -0
  85. package/dist/bootstrap/envFingerprint.js +5 -0
  86. package/dist/bootstrap/index.d.ts +3 -1
  87. package/dist/bootstrap/index.js +3 -1
  88. package/dist/bootstrap/lifecycleBootstrap.d.ts +111 -0
  89. package/dist/bootstrap/lifecycleBootstrap.js +433 -0
  90. package/dist/bootstrap/v1EnvCompat.d.ts +113 -0
  91. package/dist/bootstrap/v1EnvCompat.js +303 -0
  92. package/dist/events/eventArchive.d.ts +2 -0
  93. package/dist/events/eventArchive.js +13 -3
  94. package/dist/events/eventSchema.d.ts +7 -7
  95. package/dist/events/eventStore.d.ts +2 -0
  96. package/dist/events/eventStore.js +5 -1
  97. package/dist/events/ingest.d.ts +2 -1
  98. package/dist/events/ingest.js +15 -0
  99. package/dist/events/paths.d.ts +12 -10
  100. package/dist/events/paths.js +24 -20
  101. package/dist/events/public.d.ts +2 -2
  102. package/dist/events/public.js +2 -2
  103. package/dist/events/reports.d.ts +2 -0
  104. package/dist/events/reports.js +4 -0
  105. package/dist/exec/autoExec.d.ts +68 -4
  106. package/dist/exec/autoExec.js +392 -33
  107. package/dist/exec/autonomousCycle.d.ts +31 -4
  108. package/dist/exec/autonomousCycle.js +71 -13
  109. package/dist/exec/claudeBridge.d.ts +80 -15
  110. package/dist/exec/claudeBridge.js +845 -76
  111. package/dist/exec/executionBinding.d.ts +414 -0
  112. package/dist/exec/executionBinding.js +588 -0
  113. package/dist/exec/index.d.ts +1 -0
  114. package/dist/exec/index.js +1 -0
  115. package/dist/exec/openPrRegistry.d.ts +8 -2
  116. package/dist/exec/openPrRegistry.js +32 -22
  117. package/dist/exec/prompt.js +14 -1
  118. package/dist/exec/proofOfWork.d.ts +1 -1
  119. package/dist/exec/proofOfWork.js +2 -2
  120. package/dist/exec/runnerRegistry.d.ts +153 -36
  121. package/dist/exec/runnerRegistry.js +848 -65
  122. package/dist/exec/selfPr.js +1 -7
  123. package/dist/feedback/envelope.d.ts +61 -0
  124. package/dist/feedback/envelope.js +168 -0
  125. package/dist/feedback/index.d.ts +1 -0
  126. package/dist/feedback/index.js +1 -0
  127. package/dist/hooks/hooks.js +1 -0
  128. package/dist/hub/assetCallLog.d.ts +35 -1
  129. package/dist/hub/assetCallLog.js +124 -1
  130. package/dist/hub/bindings.d.ts +8 -1
  131. package/dist/hub/bindings.js +29 -8
  132. package/dist/hub/capability.d.ts +130 -4
  133. package/dist/hub/conversationDistiller.d.ts +19 -0
  134. package/dist/hub/conversationDistiller.js +115 -37
  135. package/dist/hub/fake.d.ts +3 -2
  136. package/dist/hub/fake.js +2 -1
  137. package/dist/hub/index.d.ts +1 -0
  138. package/dist/hub/index.js +1 -0
  139. package/dist/hub/questionGenerator.d.ts +5 -1
  140. package/dist/hub/questionGenerator.js +8 -6
  141. package/dist/hub/recipeCompose.d.ts +27 -0
  142. package/dist/hub/recipeCompose.js +90 -0
  143. package/dist/hub/sanitize.js +122 -7
  144. package/dist/index.d.ts +6 -1
  145. package/dist/index.js +7 -1
  146. package/dist/issueReporter/index.d.ts +156 -0
  147. package/dist/issueReporter/index.js +1688 -0
  148. package/dist/mailbox/dispatch.d.ts +1 -1
  149. package/dist/mailbox/dispatch.js +22 -6
  150. package/dist/mailbox/envelope.d.ts +7 -1
  151. package/dist/mailbox/envelope.js +9 -2
  152. package/dist/mailbox/ipcServer.d.ts +12 -2
  153. package/dist/mailbox/ipcServer.js +183 -13
  154. package/dist/mailbox/store.d.ts +89 -3
  155. package/dist/mailbox/store.js +895 -41
  156. package/dist/modelCompatibility.d.ts +164 -0
  157. package/dist/modelCompatibility.js +309 -0
  158. package/dist/observers/valueDigestObserver.d.ts +9 -0
  159. package/dist/observers/valueDigestObserver.js +35 -2
  160. package/dist/ops/cleanup.js +1 -1
  161. package/dist/ops/evolutionGraphProjection.d.ts +20 -0
  162. package/dist/ops/evolutionGraphProjection.js +315 -0
  163. package/dist/ops/index.d.ts +2 -1
  164. package/dist/ops/index.js +2 -1
  165. package/dist/ops/savingsCore.js +1 -2
  166. package/dist/ops/selfUpdate.d.ts +18 -1
  167. package/dist/ops/selfUpdate.js +88 -23
  168. package/dist/ops/valueOutreach.d.ts +3 -1
  169. package/dist/ops/valueOutreach.js +5 -1
  170. package/dist/personality/schema.d.ts +24 -24
  171. package/dist/schema/evolutionGraph.d.ts +784 -0
  172. package/dist/schema/evolutionGraph.js +187 -0
  173. package/dist/schema/index.d.ts +1 -0
  174. package/dist/schema/index.js +1 -0
  175. package/dist/schema/proofOfWork.d.ts +125 -6
  176. package/dist/schema/proofOfWork.js +102 -4
  177. package/dist/schema/signal.d.ts +3 -3
  178. package/dist/schema/signal.js +1 -1
  179. package/dist/shadow/shadowHub.js +1 -0
  180. package/dist/signals/curriculum.d.ts +55 -0
  181. package/dist/signals/curriculum.js +202 -0
  182. package/dist/signals/cycleHistoryFromEvents.js +17 -8
  183. package/dist/signals/expand.d.ts +15 -1
  184. package/dist/signals/expand.js +169 -1
  185. package/dist/signals/extractor.d.ts +2 -2
  186. package/dist/signals/extractor.js +31 -6
  187. package/dist/signals/index.d.ts +4 -1
  188. package/dist/signals/index.js +4 -1
  189. package/dist/signals/metaSignals.d.ts +4 -0
  190. package/dist/signals/metaSignals.js +42 -0
  191. package/dist/signals/scopeVocabulary.d.ts +75 -0
  192. package/dist/signals/scopeVocabulary.js +91 -0
  193. package/dist/signals/signalGate.js +1 -1
  194. package/dist/signals/taskDomain.d.ts +22 -0
  195. package/dist/signals/taskDomain.js +43 -0
  196. package/dist/strategy/constraintAblation.d.ts +64 -0
  197. package/dist/strategy/constraintAblation.js +2820 -0
  198. package/dist/strategy/constraintAblationPredicates.d.ts +31 -0
  199. package/dist/strategy/constraintAblationPredicates.js +339 -0
  200. package/dist/strategy/index.d.ts +2 -1
  201. package/dist/strategy/index.js +2 -1
  202. package/dist/trace/index.d.ts +3 -1
  203. package/dist/trace/index.js +3 -1
  204. package/dist/trace/learningTrace.d.ts +216 -0
  205. package/dist/trace/learningTrace.js +298 -0
  206. package/dist/trace/proxyTurns.d.ts +31 -0
  207. package/dist/trace/proxyTurns.js +137 -0
  208. package/dist/trace/trajectory.d.ts +8 -0
  209. package/dist/trace/trajectory.js +14 -2
  210. package/dist/util/fetchPort.d.ts +1 -0
  211. package/dist/util/fetchPort.js +11 -0
  212. package/dist/util/fileLock.d.ts +113 -7
  213. package/dist/util/fileLock.js +1035 -80
  214. package/dist/util/index.d.ts +3 -1
  215. package/dist/util/index.js +2 -1
  216. package/dist/verify/index.d.ts +2 -1
  217. package/dist/verify/index.js +1 -1
  218. package/dist/verify/sandboxRunner.d.ts +30 -0
  219. package/dist/verify/sandboxRunner.js +370 -27
  220. package/dist/verify/sandboxedValidation.d.ts +16 -2
  221. package/dist/verify/sandboxedValidation.js +200 -22
  222. package/dist/verify/validation.d.ts +35 -4
  223. package/dist/verify/validation.js +164 -16
  224. package/dist/wire/geneHints.d.ts +88 -16
  225. package/dist/wire/geneHints.js +124 -15
  226. package/dist/wire/index.d.ts +8 -3
  227. package/dist/wire/index.js +2 -2
  228. package/dist/wire/schemaGate.d.ts +21 -0
  229. package/dist/wire/schemaGate.js +119 -10
  230. package/dist/workflow/dsl.d.ts +24 -3
  231. package/dist/workflow/dsl.js +4 -0
  232. package/dist/workflow/engine.d.ts +5 -1
  233. package/dist/workflow/engine.js +3 -0
  234. package/dist/workflow/index.d.ts +3 -1
  235. package/dist/workflow/index.js +3 -1
  236. package/dist/workflow/runtime.d.ts +110 -0
  237. package/dist/workflow/runtime.js +1298 -0
  238. package/dist/workflow/stateStore.d.ts +172 -0
  239. package/dist/workflow/stateStore.js +1044 -0
  240. package/package.json +12 -4
@@ -4,8 +4,10 @@ import type { ReviewLedger } from '../assetstore/reviewLedger.js';
4
4
  import type { Mutation } from '../wire/index.js';
5
5
  import type { GeneDecision } from '../algo/geneSelection.js';
6
6
  import type { ExecutionResult } from '../algo/cycleEngine.js';
7
- import { type GeneResolver, type ValidateHook, type AgentRunnerOptions, type RunnerName, type AgentRunner, type GitRunner } from './claudeBridge.js';
7
+ import { type GeneResolver, type ValidateHook, type AgentRunnerOptions, type AgentSessionResume, type RunnerName, type AgentRunner, type GitRunner } from './claudeBridge.js';
8
8
  import type { PersonalityStore } from '../personality/store.js';
9
+ import type { AgentRunTraceRecorder } from '../trace/learningTrace.js';
10
+ import type { ExecutionObserver } from './claudeBridge.js';
9
11
  /**
10
12
  * Resolve a gene's strategy from the store and whether it is safe to EMBED into an autonomous agent's prompt —
11
13
  * the exec-side link from #30 (provenance ledger) and the review-state gate to #45 (requireTrustedGene gate). A
@@ -18,9 +20,11 @@ export declare function makeTrustedGeneResolver(store: AssetStoreProvider, prove
18
20
  export interface AutonomousSafety {
19
21
  /** Deny-by-default repo allowlist (#41). Required — an empty array refuses everything. */
20
22
  allowedRoots: readonly string[];
21
- /** Which built-in runner (#66). Default 'claude'. The same safety controls wrap whichever runner. cursor is a scaffold (unverified). */
23
+ /** Which built-in runner (#66). Default 'codex'. The same safety controls wrap whichever runner. cursor is a scaffold (unverified). */
22
24
  runner?: RunnerName;
23
- /** Agent runner options (#38/#40). Default: bounded skip-permissions (Read/Edit/Write). */
25
+ /** Explicit opt-in to continue a native session owned by the selected runner. */
26
+ resume?: AgentSessionResume;
27
+ /** Agent runner options (#38/#40). Default: no pre-authorized host access. */
24
28
  agentOptions?: AgentRunnerOptions;
25
29
  /** Strip evolver/hub secrets from the agent env (#42). Default true. */
26
30
  scrubEnv?: boolean;
@@ -29,11 +33,26 @@ export interface AutonomousSafety {
29
33
  /** Only embed trusted gene strategies (#45). Default true. */
30
34
  requireTrustedGene?: boolean;
31
35
  timeoutMs?: number;
36
+ /** Cooperative cancellation propagated to the spawned runner process tree. */
37
+ signal?: AbortSignal;
32
38
  }
39
+ export declare class UnsupportedCursorAutonomousIsolationError extends Error {
40
+ constructor();
41
+ }
42
+ export declare class UnsupportedAutonomousHostAccessError extends Error {
43
+ constructor();
44
+ }
45
+ export declare class UnsupportedAutonomousClaudeRunnerError extends Error {
46
+ constructor();
47
+ }
48
+ export declare class UnsupportedAutonomousCodexRunnerError extends Error {
49
+ constructor();
50
+ }
51
+ export declare function resolveAutonomousAgentOptions(runner: RunnerName | undefined, isolation: AutonomousSafety['isolation'], overrides?: AgentRunnerOptions): AgentRunnerOptions;
33
52
  /**
34
53
  * Build the fully-hardened `execute` for an autonomous run against `repo`. Composes every exec-bridge control
35
54
  * with secure defaults so they can't be forgotten piecemeal: deny-by-default allowedRoots (#41) + worktree
36
- * isolation (#43) + env scrub (#42) + bounded skip-permissions agent (#38/#40) + trusted-gene gate fed by
55
+ * isolation (#43) + env scrub (#42) + non-bypassing agent permissions (#38/#40) + trusted-gene gate fed by
37
56
  * provenance (#45/#30). Pass the result as runEvolutionCycle's `execute`.
38
57
  */
39
58
  export declare function makeSafeExecute(repo: string, store: AssetStoreProvider, safety: AutonomousSafety, opts?: {
@@ -45,4 +64,12 @@ export declare function makeSafeExecute(repo: string, store: AssetStoreProvider,
45
64
  personality?: PersonalityStore;
46
65
  agent?: AgentRunner;
47
66
  git?: GitRunner;
67
+ /** Optional learning-trace recorder forwarded to the exec bridge (Learning Ops slice 2). */
68
+ traceRecorder?: AgentRunTraceRecorder;
69
+ executionObserver?: ExecutionObserver;
70
+ executionLimits?: {
71
+ maxRuntimeMs: number;
72
+ maxFiles: number;
73
+ maxLines: number;
74
+ };
48
75
  }): (mutation: Mutation, decision: GeneDecision) => Promise<ExecutionResult>;
@@ -1,4 +1,4 @@
1
- import { makeClaudeExecBridge } from './claudeBridge.js';
1
+ import { CLAUDE_SAFE_AUTONOMOUS_TOOLS, hasBoundedClaudeFileAccess, makeClaudeExecBridge, validateAgentSessionResume } from './claudeBridge.js';
2
2
  const asStrings = (v) => (Array.isArray(v) ? v.filter((x) => typeof x === 'string') : []);
3
3
  /**
4
4
  * Resolve a gene's strategy from the store and whether it is safe to EMBED into an autonomous agent's prompt —
@@ -33,43 +33,101 @@ export function makeTrustedGeneResolver(store, provenance, review, includeProbat
33
33
  return info;
34
34
  };
35
35
  }
36
- // Claude's safe default: bypass the permission prompts but BOUND the agent to file edits (#38/#40).
37
- const CLAUDE_DEFAULT_AGENT_OPTIONS = { skipPermissions: true, allowedTools: ['Read', 'Edit', 'Write'] };
38
- // Codex's safe default is SANDBOXED (no skip): the autonomous-bypass flag is gated until verified (#66), so
39
- // skipPermissions would throw at construction. `codex exec` still runs non-interactively under its own sandbox.
36
+ // Keep Claude's project path checks enabled and expose only file/search tools.
37
+ // Bash, web, task, and MCP tools remain unavailable.
38
+ const CLAUDE_DEFAULT_AGENT_OPTIONS = {
39
+ permissionMode: 'acceptEdits',
40
+ tools: CLAUDE_SAFE_AUTONOMOUS_TOOLS,
41
+ };
42
+ // Codex workspace-write prevents host writes but does not contain host reads. It therefore remains explicit.
40
43
  const CODEX_DEFAULT_AGENT_OPTIONS = {};
41
- // Cursor's safe default keeps skip OFF (#66 SCAFFOLD). The runner is flag-confirmed via `cursor-agent --help`
42
- // but not yet run-verified end to end (needs an authed cursor-agent). The `-p --force --trust` bypass would
43
- // auto-approve shell+write, but Cursor has no verified per-run allowlist/sandbox mapping yet, so skipPermissions
44
- // is refused outright. Use default cursor with worktree isolation until the CLI is run-verified.
44
+ // Cursor has no verified host filesystem/network sandbox. Worktree isolation cannot safely authorize `--trust`.
45
45
  const CURSOR_DEFAULT_AGENT_OPTIONS = {};
46
- /** Per-runner safe default agent options — claude bypasses-with-bounds; codex + cursor stay non-bypassing (codex sandboxed; cursor skip refused, #66). */
46
+ // Gemini's verified safe default is `--approval-mode auto_edit`; shell remains gated and --yolo is refused.
47
+ const GEMINI_DEFAULT_AGENT_OPTIONS = {};
48
+ /** Per-runner safe default agent options. Host permission bypass is never enabled by default. */
47
49
  function defaultAgentOptions(runner) {
48
50
  if (runner === 'codex')
49
51
  return CODEX_DEFAULT_AGENT_OPTIONS;
50
52
  if (runner === 'cursor')
51
53
  return CURSOR_DEFAULT_AGENT_OPTIONS;
54
+ if (runner === 'gemini')
55
+ return GEMINI_DEFAULT_AGENT_OPTIONS;
52
56
  return CLAUDE_DEFAULT_AGENT_OPTIONS;
53
57
  }
58
+ export class UnsupportedCursorAutonomousIsolationError extends Error {
59
+ constructor() {
60
+ super('Autonomous Cursor cannot use worktree isolation because --trust grants host filesystem and network access');
61
+ this.name = 'UnsupportedCursorAutonomousIsolationError';
62
+ }
63
+ }
64
+ export class UnsupportedAutonomousHostAccessError extends Error {
65
+ constructor() {
66
+ super('Autonomous Claude requires project-scoped acceptEdits with bounded file/search tools; host access bypass or unsupported tools are forbidden because a worktree is not a security boundary');
67
+ this.name = 'UnsupportedAutonomousHostAccessError';
68
+ }
69
+ }
70
+ export class UnsupportedAutonomousClaudeRunnerError extends Error {
71
+ constructor() {
72
+ super('Autonomous claude is disabled because its headless edit mode has no verified host filesystem sandbox; inject an externally sandboxed agent or explicitly select a runner after reviewing its host-access boundary');
73
+ this.name = 'UnsupportedAutonomousClaudeRunnerError';
74
+ }
75
+ }
76
+ export class UnsupportedAutonomousCodexRunnerError extends Error {
77
+ constructor() {
78
+ super('Autonomous codex is disabled because workspace-write does not restrict host filesystem reads; inject an externally sandboxed agent');
79
+ this.name = 'UnsupportedAutonomousCodexRunnerError';
80
+ }
81
+ }
82
+ export function resolveAutonomousAgentOptions(runner, isolation, overrides) {
83
+ const options = {
84
+ ...defaultAgentOptions(runner),
85
+ ...(isolation !== 'none' ? { workspaceTrust: 'isolated-worktree' } : {}),
86
+ ...(overrides ?? {}),
87
+ };
88
+ if (runner === 'cursor' && isolation !== 'none') {
89
+ throw new UnsupportedCursorAutonomousIsolationError();
90
+ }
91
+ const effectiveRunner = runner ?? 'claude';
92
+ const unsafeClaudeOptions = effectiveRunner === 'claude' && !hasBoundedClaudeFileAccess(options);
93
+ if (unsafeClaudeOptions) {
94
+ throw new UnsupportedAutonomousHostAccessError();
95
+ }
96
+ return options;
97
+ }
54
98
  /**
55
99
  * Build the fully-hardened `execute` for an autonomous run against `repo`. Composes every exec-bridge control
56
100
  * with secure defaults so they can't be forgotten piecemeal: deny-by-default allowedRoots (#41) + worktree
57
- * isolation (#43) + env scrub (#42) + bounded skip-permissions agent (#38/#40) + trusted-gene gate fed by
101
+ * isolation (#43) + env scrub (#42) + non-bypassing agent permissions (#38/#40) + trusted-gene gate fed by
58
102
  * provenance (#45/#30). Pass the result as runEvolutionCycle's `execute`.
59
103
  */
60
104
  export function makeSafeExecute(repo, store, safety, opts = {}) {
105
+ const runner = safety.runner ?? (opts.agent ? undefined : 'claude');
106
+ if (safety.resume && runner)
107
+ validateAgentSessionResume(safety.resume, runner);
108
+ if (!opts.agent && runner === 'claude') {
109
+ throw new UnsupportedAutonomousClaudeRunnerError();
110
+ }
111
+ if (!opts.agent && runner === 'codex') {
112
+ throw new UnsupportedAutonomousCodexRunnerError();
113
+ }
61
114
  return makeClaudeExecBridge({
62
115
  cwd: repo,
63
116
  enabled: true,
64
117
  ...(opts.agent ? { agent: opts.agent } : {}),
65
118
  ...(opts.git ? { git: opts.git } : {}),
119
+ ...(opts.traceRecorder ? { traceRecorder: opts.traceRecorder } : {}),
120
+ ...(opts.executionObserver ? { executionObserver: opts.executionObserver } : {}),
121
+ ...(opts.executionLimits ? { executionLimits: opts.executionLimits } : {}),
66
122
  allowedRoots: safety.allowedRoots,
67
- ...(safety.runner ? { runner: safety.runner } : {}),
123
+ ...(runner ? { runner } : {}),
124
+ ...(safety.resume ? { resume: safety.resume } : {}),
68
125
  ...(safety.isolation === 'none' ? {} : { isolation: 'worktree' }),
69
126
  scrubEnv: safety.scrubEnv ?? true,
70
127
  requireTrustedGene: safety.requireTrustedGene ?? true,
71
- agentOptions: safety.agentOptions ?? defaultAgentOptions(safety.runner),
128
+ agentOptions: resolveAutonomousAgentOptions(runner, safety.isolation, safety.agentOptions),
72
129
  ...(safety.timeoutMs !== undefined ? { timeoutMs: safety.timeoutMs } : {}),
130
+ ...(safety.signal ? { signal: safety.signal } : {}),
73
131
  resolveGene: makeTrustedGeneResolver(store, opts.provenance, opts.review, opts.includeProbation ?? false),
74
132
  ...(opts.validate ? { validate: opts.validate } : {}),
75
133
  ...(opts.validationCmds ? { validationCmds: opts.validationCmds } : {}),
@@ -3,21 +3,34 @@ import type { GeneDecision } from '../algo/geneSelection.js';
3
3
  import type { ExecutionResult } from '../algo/cycleEngine.js';
4
4
  import { type GeneStrategyInfo } from './prompt.js';
5
5
  import type { PersonalityStore } from '../personality/store.js';
6
- import { type AgentRunner, type AgentRunnerOptions, type RunnerName } from './runnerRegistry.js';
7
- export { resolveSpawnCommand, spawnCapture, UnboundedSkipPermissionsError, UnsupportedCursorSkipPermissionsError, claudeRunnerArgs, makeClaudeHeadlessRunner, claudeHeadlessRunner, codexRunnerArgs, makeCodexHeadlessRunner, cursorRunnerArgs, makeCursorHeadlessRunner, getRunnerSpec, } from './runnerRegistry.js';
8
- export type { AgentRunContext, AgentRunResult, AgentRunner, RunnerName, AgentRunnerOptions, ClaudeRunnerOptions, CodexRunnerOptions, AgentRunnerSpec, } from './runnerRegistry.js';
6
+ import type { AgentRunTraceRecorder } from '../trace/learningTrace.js';
7
+ import type { PolicyDecision, ProofReference, ToolDecision, ValidatorEvidence } from './executionBinding.js';
8
+ import { type AgentRunner, type AgentRunnerOptions, type AgentSessionResume, type RunnerName } from './runnerRegistry.js';
9
+ export { resolveSpawnCommand, spawnCapture, DEFAULT_MAX_CAPTURE_BYTES, MAX_AGENT_SESSION_ID_CHARS, AgentSessionResumeError, validateAgentSessionResume, UnboundedSkipPermissionsError, UnsupportedCodexPermissionOptionsError, UnsupportedCursorAllowedToolsError, UnsupportedCursorSkipPermissionsError, UnsupportedCursorWorkspaceTrustError, UnsupportedGeminiPermissionOptionsError, claudeRunnerArgs, makeClaudeHeadlessRunner, claudeHeadlessRunner, codexRunnerArgs, makeCodexHeadlessRunner, cursorRunnerArgs, makeCursorHeadlessRunner, getRunnerSpec, hasBoundedClaudeFileAccess, CLAUDE_SAFE_AUTONOMOUS_TOOLS, geminiRunnerArgs, makeGeminiHeadlessRunner, classifyGeminiRunnerResult, } from './runnerRegistry.js';
10
+ export type { AgentRunContext, AgentRunResult, AgentRunner, RunnerName, AgentRunnerOptions, ClaudeRunnerOptions, CodexRunnerOptions, AgentRunnerSpec, AgentSessionResume, } from './runnerRegistry.js';
11
+ export interface GitRunnerOptions {
12
+ processSignalMode?: 'cancel' | 'ignore';
13
+ }
9
14
  /** Run a git subcommand in cwd and return its stdout. */
10
- export type GitRunner = (args: readonly string[], cwd: string) => Promise<string>;
15
+ export type GitRunner = (args: readonly string[], cwd: string, signal?: AbortSignal, options?: GitRunnerOptions) => Promise<string>;
16
+ export type GitPatchWriter = (args: readonly string[], cwd: string, destination: string, signal?: AbortSignal,
17
+ /** Call immediately after this writer exclusively creates `destination`. */
18
+ onDestinationOpened?: () => void) => Promise<void>;
11
19
  /** Resolve the selected gene's learned strategy (for prompt enrichment). */
12
20
  export type GeneResolver = (geneId: string) => Promise<GeneStrategyInfo | null> | GeneStrategyInfo | null;
13
21
  /** Decide success from the post-run working tree (e.g. run the gene's validation plan). */
14
- export type ValidateHook = (mutation: Mutation, decision: GeneDecision, cwd: string) => Promise<{
15
- passed: boolean;
16
- score?: number;
17
- }> | {
22
+ export interface ValidateHookResult {
18
23
  passed: boolean;
19
24
  score?: number;
20
- };
25
+ validator?: ValidatorEvidence;
26
+ }
27
+ export type ValidateHook = (mutation: Mutation, decision: GeneDecision, cwd: string, signal: AbortSignal) => Promise<ValidateHookResult> | ValidateHookResult;
28
+ export interface ExecutionObserver {
29
+ onToolDecision?(decision: ToolDecision, signal?: AbortSignal): Promise<void> | void;
30
+ onPolicyDecision?(decision: PolicyDecision, signal?: AbortSignal): Promise<void> | void;
31
+ onValidatorDecision?(decision: ValidatorEvidence, signal?: AbortSignal): Promise<void> | void;
32
+ onProofReference?(reference: ProofReference, signal?: AbortSignal): Promise<void> | void;
33
+ }
21
34
  export interface ExecBridgeOptions {
22
35
  /** Working directory the agent edits and git is measured in. */
23
36
  cwd: string;
@@ -25,10 +38,18 @@ export interface ExecBridgeOptions {
25
38
  agent?: AgentRunner;
26
39
  /** Which built-in runner to use when `agent` is not injected (#66). Default 'claude' (byte-identical). cursor is a scaffold (unverified runner). */
27
40
  runner?: RunnerName;
41
+ /** Explicit native session continuation. Must name the same runner selected above. */
42
+ resume?: AgentSessionResume;
28
43
  /** When `agent` is not injected, options for the built-in headless runner (permission bypass / allowed tools / model). */
29
44
  agentOptions?: AgentRunnerOptions;
30
45
  /** Default: spawns `git`. Inject a fake in tests. */
31
46
  git?: GitRunner;
47
+ /** Optional complete-patch sink. The default streams built-in git output directly to disk. */
48
+ gitPatchWriter?: GitPatchWriter;
49
+ /** Test seam for fallback patch persistence; production callers should use the exclusive private writer. */
50
+ writePatchFile?: (path: string, patch: string) => void;
51
+ /** Test seam for temporary patch cleanup; production callers should use the filesystem default. */
52
+ removePatchFile?: (path: string) => void;
32
53
  /** Default: EVOLVE_EXEC_BRIDGE === '1'. Set true to force-enable (e.g. integration tests). */
33
54
  enabled?: boolean;
34
55
  /**
@@ -45,7 +66,7 @@ export interface ExecBridgeOptions {
45
66
  /**
46
67
  * Run the agent in a throwaway git worktree of `cwd` instead of the repo's real working tree (finding #39.4):
47
68
  * the agent's edits land in an isolated checkout, never touching the user's working tree. The diff is measured
48
- * there, captured as a patch (proof.gitDiff.patchRef), and the worktree is removed. `cwd` must be a git repo.
69
+ * there, captured as a patch (proof.git_diff.patch_ref), and the worktree is removed. `cwd` must be a git repo.
49
70
  */
50
71
  isolation?: 'worktree';
51
72
  /**
@@ -57,12 +78,22 @@ export interface ExecBridgeOptions {
57
78
  requireTrustedGene?: boolean;
58
79
  /** Per-run agent timeout. Default 600_000ms (10 min). */
59
80
  timeoutMs?: number;
81
+ /** Cooperative cancellation propagated to the runner process tree. */
82
+ signal?: AbortSignal;
83
+ /** Binding hard limits are intersected with the existing policy/runner controls; never widen local safety. */
84
+ executionLimits?: {
85
+ maxRuntimeMs: number;
86
+ maxFiles: number;
87
+ maxLines: number;
88
+ };
60
89
  /** Optional: enrich the prompt with the selected gene's strategy. */
61
90
  resolveGene?: GeneResolver;
62
91
  /** Optional: validation commands surfaced in the prompt's done-criteria. */
63
92
  validationCmds?: readonly string[];
64
93
  /** Optional: authoritative success decision after the agent runs. Falls back to "agent ok + produced a diff". */
65
94
  validate?: ValidateHook;
95
+ /** Bound execution provenance observer. Failures are authoritative and fail the execution closed. */
96
+ executionObserver?: ExecutionObserver;
66
97
  /**
67
98
  * Optional evolvable personality (use-case ①): when set, the agent prompt gets a behavioral-style block
68
99
  * rendered from the store's CURRENT persisted state. CycleEngine's applySelectForRun has already run and
@@ -72,6 +103,12 @@ export interface ExecBridgeOptions {
72
103
  * the store's default state (store.load never throws), it never fails the run.
73
104
  */
74
105
  personality?: PersonalityStore;
106
+ /**
107
+ * Optional learning-trace recorder (Learning Ops slice 2): when set, the bridge emits `model.called` around
108
+ * each agent spawn and `tool.failed`/`retry.attempted` metadata on failures. Best-effort observability — a
109
+ * recorder/sink failure must never affect the execution result, so every emission is wrapped defensively.
110
+ */
111
+ traceRecorder?: AgentRunTraceRecorder;
75
112
  }
76
113
  export declare class ExecBridgeDisabledError extends Error {
77
114
  constructor();
@@ -84,16 +121,33 @@ export declare class ExecBridgeForbiddenError extends Error {
84
121
  * Thrown when a FULL-ACCESS (or unverified) agent run is requested without worktree isolation. The throwaway
85
122
  * worktree is the containment WE control — allowedRoots gates the cwd but cannot stop an auto-approved or
86
123
  * unsandboxed process writing/running outside it. Gated runners:
87
- * - codex with skipPermissions `--sandbox danger-full-access` (no inner OS sandbox). Without skip it stays
88
- * workspace-write, so only the skip path is gated.
124
+ * - codex permission overrides are refused by the runner because it has no enforceable per-tool allowlist.
89
125
  * - cursor default → gated UNCONDITIONALLY. cursor-agent base `-p` already documents write+shell access, cursor
90
126
  * skipPermissions is rejected by the runner layer, and the scaffold remains unverified (#66/#181) — so default
91
127
  * cursor still needs the wrapper worktree rather than risk mutating the real tree.
92
- * claude is exempt: its skip is bounded by --allowedTools (finding #80).
128
+ * Claude is fail-closed below because a tool-name allowlist does not constrain absolute filesystem paths.
93
129
  */
94
130
  export declare class UnsandboxedFullAccessRequiresIsolationError extends Error {
95
131
  constructor();
96
132
  }
133
+ export declare class WorkspaceTrustRequiresIsolationError extends Error {
134
+ readonly code = "WORKSPACE_TRUST_REQUIRES_ISOLATION";
135
+ constructor();
136
+ }
137
+ export declare class UnsupportedCursorBuiltInRunnerError extends Error {
138
+ constructor();
139
+ }
140
+ export declare class UnsupportedClaudeBuiltInRunnerError extends Error {
141
+ constructor();
142
+ }
143
+ export declare class UnsupportedCodexBuiltInRunnerError extends Error {
144
+ constructor();
145
+ }
146
+ export declare class UnsafeWorktreePathError extends Error {
147
+ constructor(reason: string);
148
+ }
149
+ /** Whether `child` is the same as, or nested under, `root`, including filesystem symlink resolution. */
150
+ export declare function isWithinRoot(child: string, root: string): boolean;
97
151
  /**
98
152
  * Whitelist-filter `env` for a spawned agent/tool: keep ONLY the minimal runtime env + the caller-declared
99
153
  * extras (the runner's own auth via allowPrefixes/allowKeys); drop everything else. Fail-safe by construction —
@@ -103,10 +157,21 @@ export declare function scrubAgentEnv(env: NodeJS.ProcessEnv, opts?: {
103
157
  allowKeys?: readonly string[];
104
158
  allowPrefixes?: readonly string[];
105
159
  }): NodeJS.ProcessEnv;
106
- /** Default git runner: spawn `git <args>` in cwd, return stdout (empty string on error). Env scrubbed — git never needs evolver/hub secrets. */
160
+ /**
161
+ * 绑定执行不能接受无法收到权威截止时间取消信号的旧验证器或写入器。
162
+ * AbortSignal 本身是协作式的;先拒绝不暴露该信号的回调,避免旧 hook
163
+ * 被静默地当作无界工作运行。
164
+ */
165
+ export declare class ExecBridgeCancellationContractError extends Error {
166
+ constructor(hook: 'validate' | 'gitPatchWriter');
167
+ }
168
+ /** Default git runner: every incomplete command result fails closed. */
107
169
  export declare const defaultGitRunner: GitRunner;
170
+ export declare const defaultGitPatchWriter: GitPatchWriter;
108
171
  /**
109
172
  * Build the `execute` function CycleEngine/runEvolutionCycle consume. Default-off: throws
110
173
  * ExecBridgeDisabledError on first call unless enabled.
111
174
  */
112
- export declare function makeClaudeExecBridge(opts: ExecBridgeOptions): (mutation: Mutation, decision: GeneDecision) => Promise<ExecutionResult>;
175
+ export declare function makeClaudeExecBridge(opts: ExecBridgeOptions, internal?: {
176
+ cursorWorktreeRoot?: string;
177
+ }): (mutation: Mutation, decision: GeneDecision) => Promise<ExecutionResult>;