@tangle-network/agent-bench 0.11.2 → 0.13.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 (174) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/HARNESS.md +6 -2
  3. package/README.md +1 -4
  4. package/dist/benchmarks/swe-bench.js +4 -9
  5. package/dist/benchmarks/swe-bench.js.map +1 -1
  6. package/package.json +5 -5
  7. package/scripts/run-package-tests.mjs +2 -2
  8. package/src/benchmarks/swe-bench.test.mts +49 -0
  9. package/src/benchmarks/swe-bench.ts +4 -9
  10. package/src/quant-arena/README.md +0 -144
  11. package/src/quant-arena/backtest.test.mts +0 -135
  12. package/src/quant-arena/backtest.ts +0 -218
  13. package/src/quant-arena/data.test.mts +0 -44
  14. package/src/quant-arena/data.ts +0 -141
  15. package/src/quant-arena/driver.test.mts +0 -253
  16. package/src/quant-arena/driver.ts +0 -219
  17. package/src/quant-arena/fixtures/data/PROVENANCE.md +0 -26
  18. package/src/quant-arena/fixtures/data/holdout/IDX.csv +0 -523
  19. package/src/quant-arena/fixtures/data/holdout/S01.csv +0 -523
  20. package/src/quant-arena/fixtures/data/holdout/S02.csv +0 -523
  21. package/src/quant-arena/fixtures/data/holdout/S03.csv +0 -523
  22. package/src/quant-arena/fixtures/data/holdout/S04.csv +0 -523
  23. package/src/quant-arena/fixtures/data/holdout/S05.csv +0 -523
  24. package/src/quant-arena/fixtures/data/holdout/S06.csv +0 -523
  25. package/src/quant-arena/fixtures/data/holdout/S07.csv +0 -523
  26. package/src/quant-arena/fixtures/data/holdout/S08.csv +0 -523
  27. package/src/quant-arena/fixtures/data/holdout/S09.csv +0 -523
  28. package/src/quant-arena/fixtures/data/holdout/S10.csv +0 -523
  29. package/src/quant-arena/fixtures/data/insample/IDX.csv +0 -2087
  30. package/src/quant-arena/fixtures/data/insample/S01.csv +0 -2087
  31. package/src/quant-arena/fixtures/data/insample/S02.csv +0 -2087
  32. package/src/quant-arena/fixtures/data/insample/S03.csv +0 -2087
  33. package/src/quant-arena/fixtures/data/insample/S04.csv +0 -2087
  34. package/src/quant-arena/fixtures/data/insample/S05.csv +0 -2087
  35. package/src/quant-arena/fixtures/data/insample/S06.csv +0 -2087
  36. package/src/quant-arena/fixtures/data/insample/S07.csv +0 -2087
  37. package/src/quant-arena/fixtures/data/insample/S08.csv +0 -2087
  38. package/src/quant-arena/fixtures/data/insample/S09.csv +0 -2087
  39. package/src/quant-arena/fixtures/data/insample/S10.csv +0 -2087
  40. package/src/quant-arena/fixtures/demo-campaign/cost-ledger.jsonl +0 -16
  41. package/src/quant-arena/fixtures/demo-campaign/notebook.jsonl +0 -5
  42. package/src/quant-arena/fixtures/demo-campaign/rollout-manifest.json +0 -171
  43. package/src/quant-arena/fixtures/demo-campaign/strategies/cand-001-default-author/strategy.ts +0 -119
  44. package/src/quant-arena/fixtures/demo-campaign/strategies/cand-002-default-author/strategy.ts +0 -119
  45. package/src/quant-arena/fixtures/demo-campaign/strategies/cand-003-quant-researcher/strategy.ts +0 -105
  46. package/src/quant-arena/fixtures/demo-campaign/strategies/cand-004-quant-researcher/strategy.ts +0 -102
  47. package/src/quant-arena/fixtures/demo-campaign-v2/cost-ledger.jsonl +0 -4
  48. package/src/quant-arena/fixtures/demo-campaign-v2/notebook.jsonl +0 -2
  49. package/src/quant-arena/fixtures/demo-campaign-v2/rollout-manifest.json +0 -84
  50. package/src/quant-arena/fixtures/demo-campaign-v2/strategies/cand-001-quant-researcher/strategy.ts +0 -117
  51. package/src/quant-arena/holdout-certify.mts +0 -206
  52. package/src/quant-arena/holdout-certify.test.mts +0 -82
  53. package/src/quant-arena/leak-audit.test.mts +0 -79
  54. package/src/quant-arena/leak-audit.ts +0 -95
  55. package/src/quant-arena/make-fixtures.mts +0 -161
  56. package/src/quant-arena/multiplicity.test.mts +0 -68
  57. package/src/quant-arena/multiplicity.ts +0 -87
  58. package/src/quant-arena/nautilus-certify.ts +0 -31
  59. package/src/quant-arena/oms.ts +0 -90
  60. package/src/quant-arena/profiles/quant-researcher.profile.json +0 -12
  61. package/src/quant-arena/python/pyproject.toml +0 -8
  62. package/src/quant-arena/python/uv.lock +0 -1297
  63. package/src/quant-arena/python/vbt-worker.py +0 -192
  64. package/src/quant-arena/quant-loop.mts +0 -840
  65. package/src/quant-arena/quant-loop.test.mts +0 -75
  66. package/src/quant-arena/strategies/buy-hold-index/strategy.ts +0 -11
  67. package/src/quant-arena/strategies/equal-weight/strategy.ts +0 -20
  68. package/src/quant-arena/strategies/sma-crossover/strategy.ts +0 -42
  69. package/src/quant-arena/types.ts +0 -133
  70. package/src/quant-arena/vbt-client.ts +0 -321
  71. package/src/quant-arena/vbt-parity.test.mts +0 -183
  72. package/src/quant-arena/windows.test.mts +0 -45
  73. package/src/quant-arena/windows.ts +0 -54
  74. package/src/rollout-ledger/backfill-swe-arena.mts +0 -610
  75. package/src/rollout-ledger/backfill-swe-arena.test.mts +0 -347
  76. package/src/rollout-ledger/settle-capture.mts +0 -448
  77. package/src/rollout-ledger/settle-capture.test.mts +0 -270
  78. package/src/swe-arena/activation.mts +0 -225
  79. package/src/swe-arena/activation.test.mts +0 -300
  80. package/src/swe-arena/analyze.ts +0 -211
  81. package/src/swe-arena/arms.ts +0 -862
  82. package/src/swe-arena/bootstrap-meta.mts +0 -188
  83. package/src/swe-arena/bootstrap-meta.test.mts +0 -51
  84. package/src/swe-arena/briefing.mts +0 -217
  85. package/src/swe-arena/briefing.test.mts +0 -179
  86. package/src/swe-arena/calibrate.ts +0 -217
  87. package/src/swe-arena/capabilities.mts +0 -76
  88. package/src/swe-arena/capabilities.test.mts +0 -57
  89. package/src/swe-arena/capacity.ts +0 -198
  90. package/src/swe-arena/cell-evidence.mts +0 -437
  91. package/src/swe-arena/cell-evidence.test.mts +0 -248
  92. package/src/swe-arena/diagnosis-ensemble.test.mts +0 -210
  93. package/src/swe-arena/diagnosis-ensemble.ts +0 -523
  94. package/src/swe-arena/execution.test.mts +0 -1171
  95. package/src/swe-arena/factory-command-container.ts +0 -284
  96. package/src/swe-arena/factory-judge-child.mts +0 -228
  97. package/src/swe-arena/factory.test.mts +0 -645
  98. package/src/swe-arena/fixtures/analyze.py +0 -80
  99. package/src/swe-arena/fixtures/excludes.txt +0 -8
  100. package/src/swe-arena/fixtures/factory/agent-eval-309/calibration.md +0 -51
  101. package/src/swe-arena/fixtures/factory/agent-eval-309/manifest.json +0 -29
  102. package/src/swe-arena/fixtures/factory/agent-eval-309/spec.md +0 -64
  103. package/src/swe-arena/fixtures/factory/agent-runtime-232/calibration.md +0 -48
  104. package/src/swe-arena/fixtures/factory/agent-runtime-232/manifest.json +0 -29
  105. package/src/swe-arena/fixtures/factory/agent-runtime-232/spec.md +0 -48
  106. package/src/swe-arena/fixtures/factory/loops-28/calibration.md +0 -47
  107. package/src/swe-arena/fixtures/factory/loops-28/manifest.json +0 -30
  108. package/src/swe-arena/fixtures/factory/loops-28/spec.md +0 -50
  109. package/src/swe-arena/fixtures/gen1-salvage/README.md +0 -45
  110. package/src/swe-arena/fixtures/gen1-salvage/cand0-e6d7361.diff +0 -116
  111. package/src/swe-arena/fixtures/gen1-salvage/cand1-76a8590.diff +0 -293
  112. package/src/swe-arena/fixtures/holdout-preregister.log +0 -12
  113. package/src/swe-arena/fixtures/holdout.json +0 -44
  114. package/src/swe-arena/fixtures/instances.json +0 -146
  115. package/src/swe-arena/fixtures/ledger.jsonl +0 -12
  116. package/src/swe-arena/fixtures/patches/pallets__flask-5014.solo.patch +0 -36
  117. package/src/swe-arena/fixtures/patches/pydata__xarray-4687.sup.patch +0 -33
  118. package/src/swe-arena/fixtures/rejudge.jsonl +0 -15
  119. package/src/swe-arena/fixtures/rematch.jsonl +0 -3
  120. package/src/swe-arena/fixtures/rematch2.jsonl +0 -3
  121. package/src/swe-arena/fixtures/rematch3.jsonl +0 -3
  122. package/src/swe-arena/fixtures/run-report/README.md +0 -43
  123. package/src/swe-arena/fixtures/run-report/factory-agent-eval-309-FSUP0.json +0 -173
  124. package/src/swe-arena/fixtures/run-report/factory-agent-eval-309-FSUP0.md +0 -100
  125. package/src/swe-arena/fixtures/run-report/gen3-rollup.json +0 -551
  126. package/src/swe-arena/fixtures/run-report/gen3-rollup.md +0 -64
  127. package/src/swe-arena/fixtures/sup-journal-true.json +0 -19
  128. package/src/swe-arena/fixtures/verify/astropy__astropy-13033.sh +0 -48
  129. package/src/swe-arena/fixtures/verify/django__django-11532.sh +0 -50
  130. package/src/swe-arena/fixtures/verify/matplotlib__matplotlib-20826.sh +0 -76
  131. package/src/swe-arena/fixtures/verify/pydata__xarray-4687.sh +0 -44
  132. package/src/swe-arena/fixtures/verify/pytest-dev__pytest-6197.sh +0 -32
  133. package/src/swe-arena/fixtures/verify/sphinx-doc__sphinx-9658.sh +0 -51
  134. package/src/swe-arena/fixtures/worker-tokens.json +0 -42
  135. package/src/swe-arena/fixtures.ts +0 -237
  136. package/src/swe-arena/gepa-seat.mts +0 -886
  137. package/src/swe-arena/gepa-seat.test.mts +0 -1136
  138. package/src/swe-arena/holdout-certify.mts +0 -408
  139. package/src/swe-arena/holdout-certify.test.mts +0 -160
  140. package/src/swe-arena/implementation-ref.test.mts +0 -64
  141. package/src/swe-arena/implementation-ref.ts +0 -62
  142. package/src/swe-arena/judge-child.mts +0 -37
  143. package/src/swe-arena/ledger-orphans.mts +0 -77
  144. package/src/swe-arena/ledger-orphans.test.mts +0 -149
  145. package/src/swe-arena/manifest.mts +0 -293
  146. package/src/swe-arena/manifest.test.mts +0 -169
  147. package/src/swe-arena/materialize.ts +0 -142
  148. package/src/swe-arena/outer-loop.mts +0 -2854
  149. package/src/swe-arena/outer-loop.test.mts +0 -714
  150. package/src/swe-arena/parity.test.mts +0 -87
  151. package/src/swe-arena/premeasured-from-cells.mts +0 -296
  152. package/src/swe-arena/premeasured-from-cells.test.mts +0 -201
  153. package/src/swe-arena/proc.test.mts +0 -172
  154. package/src/swe-arena/proc.ts +0 -260
  155. package/src/swe-arena/profiles/deepseek-author.profile.json +0 -12
  156. package/src/swe-arena/profiles/default-author.profile.json +0 -12
  157. package/src/swe-arena/proposer-fanout.mts +0 -736
  158. package/src/swe-arena/proposer-fanout.test.mts +0 -660
  159. package/src/swe-arena/proposer-provenance.mts +0 -176
  160. package/src/swe-arena/proposer-provenance.test.mts +0 -106
  161. package/src/swe-arena/reconcile.ts +0 -0
  162. package/src/swe-arena/replay.mts +0 -183
  163. package/src/swe-arena/replay.test.mts +0 -300
  164. package/src/swe-arena/run-experiment.mts +0 -729
  165. package/src/swe-arena/run-report.mts +0 -75
  166. package/src/swe-arena/run-supervisor.mjs +0 -297
  167. package/src/swe-arena/run-supervisor.test.mts +0 -539
  168. package/src/swe-arena/score-split.mts +0 -140
  169. package/src/swe-arena/score-split.test.mts +0 -123
  170. package/src/swe-arena/scratch-worktree-serialization.test.mts +0 -72
  171. package/src/swe-arena/scratch-worktree.test.mts +0 -56
  172. package/src/swe-arena/scratch-worktree.ts +0 -64
  173. package/src/swe-arena/serialized-judge.ts +0 -414
  174. package/src/swe-arena/types.ts +0 -218
@@ -1,172 +0,0 @@
1
- import { access, mkdtemp, readFile, rm } from 'node:fs/promises'
2
- import { tmpdir } from 'node:os'
3
- import { join } from 'node:path'
4
- import { afterAll, describe, expect, it } from 'vitest'
5
- import { waitForCapacity, type EndpointCapacityGate } from './capacity.ts'
6
- import { installProcessSignalAbort, run, TIMEOUT_RC } from './proc.ts'
7
-
8
- const dirs: string[] = []
9
- const cleanupPids: number[] = []
10
-
11
- afterAll(async () => {
12
- for (const pid of cleanupPids) {
13
- try {
14
- process.kill(pid, 'SIGKILL')
15
- } catch {
16
- // The expected path already removed it.
17
- }
18
- }
19
- await Promise.all(dirs.map((dir) => rm(dir, { recursive: true, force: true })))
20
- })
21
-
22
- describe('run process-group timeout', () => {
23
- it('does not spawn when the caller signal is already aborted', () => {
24
- const controller = new AbortController()
25
- controller.abort(new Error('stop before spawn'))
26
- expect(() => run(process.execPath, ['-e', 'process.exit(99)'], { signal: controller.signal })).toThrow(
27
- 'stop before spawn',
28
- )
29
- })
30
-
31
- it('allows a SIGTERM handler to finish cleanup before returning timeout', async () => {
32
- const dir = await mkdtemp(join(tmpdir(), 'swe-proc-term-'))
33
- dirs.push(dir)
34
- const marker = join(dir, 'cleanup.txt')
35
- const result = await run(process.execPath, [
36
- '-e',
37
- `const fs=require('node:fs'); const marker=process.argv[1]; process.on('SIGTERM',()=>{fs.writeFileSync(marker,'settled'); setTimeout(()=>process.exit(0),25)}); setInterval(()=>{},1000)`,
38
- marker,
39
- ], { timeoutMs: 1_000, killGraceMs: 500 })
40
-
41
- expect(result.code).toBe(TIMEOUT_RC)
42
- expect(result.timedOut).toBe(true)
43
- expect(await readFile(marker, 'utf8')).toBe('settled')
44
- })
45
-
46
- it('force-kills a process group that ignores SIGTERM after the grace period', async () => {
47
- const dir = await mkdtemp(join(tmpdir(), 'swe-proc-kill-'))
48
- dirs.push(dir)
49
- const marker = join(dir, 'should-not-exist.txt')
50
- const started = Date.now()
51
- const result = await run(process.execPath, [
52
- '-e',
53
- `const fs=require('node:fs'); const marker=process.argv[1]; process.on('SIGTERM',()=>{}); setTimeout(()=>fs.writeFileSync(marker,'escaped'),5000); setInterval(()=>{},1000)`,
54
- marker,
55
- ], { timeoutMs: 60, killGraceMs: 80 })
56
-
57
- expect(result.code).toBe(TIMEOUT_RC)
58
- expect(result.timedOut).toBe(true)
59
- expect(Date.now() - started).toBeLessThan(2_000)
60
- await expect(access(marker)).rejects.toMatchObject({ code: 'ENOENT' })
61
- })
62
-
63
- it('kills a TERM-ignoring grandchild when its direct parent exits on TERM', async () => {
64
- if (process.platform === 'win32') return
65
- const dir = await mkdtemp(join(tmpdir(), 'swe-proc-tree-'))
66
- dirs.push(dir)
67
- const pidFile = join(dir, 'grandchild.pid')
68
- const grandchild = `process.on('SIGTERM',()=>{}); require('node:fs').writeFileSync(process.argv[1],String(process.pid)); setInterval(()=>{},1000)`
69
- const parent = [
70
- `const {spawn}=require('node:child_process')`,
71
- `spawn(process.execPath,['-e',${JSON.stringify(grandchild)},process.argv[1]],{stdio:'ignore'})`,
72
- `process.on('SIGTERM',()=>process.exit(0))`,
73
- `setInterval(()=>{},1000)`,
74
- ].join(';')
75
-
76
- const result = await run(process.execPath, ['-e', parent, pidFile], {
77
- timeoutMs: 2_000,
78
- killGraceMs: 50,
79
- })
80
- const grandchildPid = Number(await readFile(pidFile, 'utf8'))
81
- cleanupPids.push(grandchildPid)
82
-
83
- expect(result.code).toBe(TIMEOUT_RC)
84
- expect(result.timedOut).toBe(true)
85
- expect(() => process.kill(grandchildPid, 0)).toThrow(expect.objectContaining({ code: 'ESRCH' }))
86
- })
87
-
88
- it('kills a TERM-ignoring grandchild when its direct parent exits normally', async () => {
89
- if (process.platform === 'win32') return
90
- const dir = await mkdtemp(join(tmpdir(), 'swe-proc-normal-exit-tree-'))
91
- dirs.push(dir)
92
- const pidFile = join(dir, 'grandchild.pid')
93
- const grandchild = [
94
- `const fs=require('node:fs')`,
95
- `process.on('SIGTERM',()=>{})`,
96
- `fs.writeFileSync(process.argv[1],String(process.pid))`,
97
- `setInterval(()=>{},1000)`,
98
- ].join(';')
99
- const parent = [
100
- `const {spawn}=require('node:child_process')`,
101
- `const fs=require('node:fs')`,
102
- `spawn(process.execPath,['-e',${JSON.stringify(grandchild)},process.argv[1]],{stdio:'ignore'})`,
103
- `const ready=setInterval(()=>{if(fs.existsSync(process.argv[1])){clearInterval(ready);process.exit(0)}},5)`,
104
- ].join(';')
105
-
106
- const result = await run(process.execPath, ['-e', parent, pidFile], { killGraceMs: 50 })
107
- const grandchildPid = Number(await readFile(pidFile, 'utf8'))
108
- cleanupPids.push(grandchildPid)
109
-
110
- expect(result.code).toBe(0)
111
- expect(result.timedOut).toBe(false)
112
- expect(result.aborted).toBe(false)
113
- expect(() => process.kill(grandchildPid, 0)).toThrow(expect.objectContaining({ code: 'ESRCH' }))
114
- })
115
- })
116
-
117
- describe('cooperative process cancellation', () => {
118
- it('maps the first terminal signal to cancellation and removes its handlers', () => {
119
- const oldExitCode = process.exitCode
120
- const beforeInt = new Set(process.rawListeners('SIGINT'))
121
- const beforeTerm = process.listenerCount('SIGTERM')
122
- const interrupt = installProcessSignalAbort('test-run')
123
- const listener = process.rawListeners('SIGINT').find((candidate) => !beforeInt.has(candidate))
124
- expect(listener).toBeDefined()
125
- listener?.call(process, 'SIGINT')
126
- expect(interrupt.signal.aborted).toBe(true)
127
- expect((interrupt.signal.reason as Error).message).toBe('test-run interrupted by SIGINT')
128
- expect(interrupt.receivedSignal).toBe('SIGINT')
129
- expect(process.exitCode).toBe(130)
130
- interrupt.dispose()
131
- expect(process.rawListeners('SIGINT').filter((candidate) => !beforeInt.has(candidate))).toHaveLength(0)
132
- expect(process.listenerCount('SIGTERM')).toBe(beforeTerm)
133
- process.exitCode = oldExitCode
134
- })
135
-
136
- it('cancels during a capacity retry sleep and never starts another probe', async () => {
137
- const controller = new AbortController()
138
- let probes = 0
139
- const gate: EndpointCapacityGate = {
140
- name: 'cancel-test',
141
- probe: async () => {
142
- probes += 1
143
- return false
144
- },
145
- kOfN: { k: 1, n: 1 },
146
- waitCeilingMs: 10_000,
147
- retryDelayMs: 10_000,
148
- }
149
- const waiting = waitForCapacity(gate, controller.signal)
150
- await new Promise((resolve) => setTimeout(resolve, 20))
151
- controller.abort(new Error('capacity cancelled'))
152
- await expect(waiting).rejects.toThrow('capacity cancelled')
153
- expect(probes).toBe(1)
154
- })
155
-
156
- it('runs zero capacity probes when already aborted', async () => {
157
- const controller = new AbortController()
158
- controller.abort(new Error('cancelled before probing'))
159
- let probes = 0
160
- const gate: EndpointCapacityGate = {
161
- name: 'pre-abort',
162
- probe: async () => {
163
- probes += 1
164
- return true
165
- },
166
- kOfN: { k: 1, n: 1 },
167
- waitCeilingMs: 1_000,
168
- }
169
- await expect(waitForCapacity(gate, controller.signal)).rejects.toThrow('cancelled before probing')
170
- expect(probes).toBe(0)
171
- })
172
- })
@@ -1,260 +0,0 @@
1
- /**
2
- * Process helpers shared by the swe-arena execution path (materialize /
3
- * calibrate / arms / serialized-judge). One place owns spawn semantics so
4
- * every port of a bash script gets identical rc/timeout behavior:
5
- *
6
- * - `run` never throws on a nonzero exit — the bash scripts branched on `$?`,
7
- * so callers get `{ code, stdout, stderr, timedOut }` and decide.
8
- * - timeouts signal the whole process GROUP (detached spawn), because the
9
- * arm commands are `dotenvx → bash -c → opencode/node` chains; killing only
10
- * the leader would orphan the model call exactly like a dropped `timeout`.
11
- * SIGTERM gets a short cleanup window before SIGKILL so children can cancel
12
- * their own detached workers and flush terminal evidence.
13
- * - `code` is 124 on timeout, mirroring coreutils `timeout` so ledger rc
14
- * fields keep the bash experiment's encoding.
15
- */
16
-
17
- import { spawn } from 'node:child_process'
18
-
19
- export interface RunResult {
20
- code: number
21
- stdout: string
22
- stderr: string
23
- timedOut: boolean
24
- aborted: boolean
25
- }
26
-
27
- export interface RunOptions {
28
- cwd?: string
29
- env?: NodeJS.ProcessEnv
30
- /** 0 / undefined = no timeout. On expiry the process group gets TERM then KILL. */
31
- timeoutMs?: number
32
- /** Grace between timeout SIGTERM and fallback SIGKILL. Default 1 second. */
33
- killGraceMs?: number
34
- /** Cancels the complete process group and waits until it is gone. */
35
- signal?: AbortSignal
36
- /** Cap captured stdout/stderr (bytes); beyond it output is dropped, not buffered. */
37
- maxBuffer?: number
38
- /** Piped to the child's stdin, then stdin is closed. */
39
- stdin?: string
40
- }
41
-
42
- const DEFAULT_MAX_BUFFER = 64 * 1024 * 1024
43
- const PROCESS_GROUP_EXIT_CONFIRM_MS = 1_000
44
- const PROCESS_GROUP_EXIT_POLL_MS = 10
45
-
46
- const exitKillGroups = new Set<number>()
47
- const killRegisteredGroupsOnExit = (): void => {
48
- for (const processGroupId of exitKillGroups) {
49
- try {
50
- process.kill(process.platform === 'win32' ? processGroupId : -processGroupId, 'SIGKILL')
51
- } catch {
52
- // The group may have settled between its final async check and process exit.
53
- }
54
- }
55
- }
56
-
57
- function registerExitKill(processGroupId: number | undefined): () => void {
58
- if (processGroupId === undefined) return () => {}
59
- if (exitKillGroups.size === 0) process.once('exit', killRegisteredGroupsOnExit)
60
- exitKillGroups.add(processGroupId)
61
- return () => {
62
- exitKillGroups.delete(processGroupId)
63
- if (exitKillGroups.size === 0) process.removeListener('exit', killRegisteredGroupsOnExit)
64
- }
65
- }
66
-
67
- /** coreutils `timeout` exit code — kept so ledger rc columns stay comparable. */
68
- export const TIMEOUT_RC = 124
69
- export const ABORT_RC = 130
70
-
71
- export interface ProcessSignalAbort {
72
- signal: AbortSignal
73
- /** First signal received; null until interrupted. */
74
- readonly receivedSignal: NodeJS.Signals | null
75
- /** Removes handlers after the caller has awaited cleanup. */
76
- dispose: () => void
77
- }
78
-
79
- /**
80
- * Translate terminal interrupts into cooperative cancellation. The handler
81
- * never exits immediately: callers await their normal cleanup in `finally`,
82
- * then dispose it. Repeated interrupts remain cooperative rather than
83
- * bypassing cleanup.
84
- */
85
- export function installProcessSignalAbort(label: string): ProcessSignalAbort {
86
- const controller = new AbortController()
87
- let receivedSignal: NodeJS.Signals | null = null
88
- const onSignal = (signal: NodeJS.Signals): void => {
89
- if (receivedSignal !== null) return
90
- receivedSignal = signal
91
- process.exitCode = signal === 'SIGINT' ? 130 : 143
92
- controller.abort(new Error(`${label} interrupted by ${signal}`))
93
- }
94
- const onSigint = (): void => onSignal('SIGINT')
95
- const onSigterm = (): void => onSignal('SIGTERM')
96
- process.on('SIGINT', onSigint)
97
- process.on('SIGTERM', onSigterm)
98
- return {
99
- signal: controller.signal,
100
- get receivedSignal() {
101
- return receivedSignal
102
- },
103
- dispose: () => {
104
- process.removeListener('SIGINT', onSigint)
105
- process.removeListener('SIGTERM', onSigterm)
106
- },
107
- }
108
- }
109
-
110
- function processGroupExists(processGroupId: number): boolean {
111
- try {
112
- process.kill(-processGroupId, 0)
113
- return true
114
- } catch (err) {
115
- return (err as NodeJS.ErrnoException).code !== 'ESRCH'
116
- }
117
- }
118
-
119
- async function waitUntil(deadline: number, predicate: () => boolean): Promise<boolean> {
120
- while (predicate()) {
121
- if (Date.now() >= deadline) return false
122
- await new Promise((resolve) => setTimeout(resolve, PROCESS_GROUP_EXIT_POLL_MS))
123
- }
124
- return true
125
- }
126
-
127
- export function run(bin: string, argv: string[], opts: RunOptions = {}): Promise<RunResult> {
128
- opts.signal?.throwIfAborted()
129
- return new Promise((resolve, reject) => {
130
- const child = spawn(bin, argv, {
131
- cwd: opts.cwd,
132
- env: opts.env ?? process.env,
133
- detached: true,
134
- stdio: ['pipe', 'pipe', 'pipe'],
135
- })
136
- const unregisterExitKill = registerExitKill(child.pid)
137
- const cap = opts.maxBuffer ?? DEFAULT_MAX_BUFFER
138
- let stdout = ''
139
- let stderr = ''
140
- let outBytes = 0
141
- let errBytes = 0
142
- let timedOut = false
143
- let aborted = false
144
- let settled = false
145
- let timer: NodeJS.Timeout | undefined
146
- const signalGroup = (signal: NodeJS.Signals) => {
147
- try {
148
- process.kill(-child.pid!, signal)
149
- } catch {
150
- try {
151
- child.kill(signal)
152
- } catch {
153
- /* already dead */
154
- }
155
- }
156
- }
157
- let termination: Promise<void> | undefined
158
- const terminate = (): Promise<void> => {
159
- termination ??= (async () => {
160
- signalGroup('SIGTERM')
161
- if (process.platform === 'win32' || typeof child.pid !== 'number') return
162
- const processGroupId = child.pid
163
- const exitedOnTerm = await waitUntil(
164
- Date.now() + Math.max(0, opts.killGraceMs ?? 1_000),
165
- () => processGroupExists(processGroupId),
166
- )
167
- if (exitedOnTerm) return
168
- signalGroup('SIGKILL')
169
- const exitedOnKill = await waitUntil(
170
- Date.now() + PROCESS_GROUP_EXIT_CONFIRM_MS,
171
- () => processGroupExists(processGroupId),
172
- )
173
- if (!exitedOnKill) throw new Error(`process group ${processGroupId} survived SIGKILL`)
174
- })()
175
- // The close handler owns the rejection. Attaching this handler prevents
176
- // an early unhandled rejection while the direct child is still closing.
177
- void termination.catch(() => undefined)
178
- return termination
179
- }
180
- const onAbort = () => {
181
- aborted = true
182
- void terminate()
183
- }
184
- if (opts.timeoutMs && opts.timeoutMs > 0) {
185
- timer = setTimeout(() => {
186
- timedOut = true
187
- void terminate()
188
- }, opts.timeoutMs)
189
- }
190
- opts.signal?.addEventListener('abort', onAbort, { once: true })
191
- if (opts.signal?.aborted) onAbort()
192
- child.stdout.on('data', (c: Buffer) => {
193
- outBytes += c.length
194
- if (outBytes <= cap) stdout += c.toString('utf8')
195
- })
196
- child.stderr.on('data', (c: Buffer) => {
197
- errBytes += c.length
198
- if (errBytes <= cap) stderr += c.toString('utf8')
199
- })
200
- child.on('error', (err) => {
201
- if (settled) return
202
- settled = true
203
- if (timer) clearTimeout(timer)
204
- opts.signal?.removeEventListener('abort', onAbort)
205
- unregisterExitKill()
206
- reject(err)
207
- })
208
- child.on('close', (code, signal) => {
209
- if (settled) return
210
- if (timer) clearTimeout(timer)
211
- opts.signal?.removeEventListener('abort', onAbort)
212
- void (async () => {
213
- try {
214
- if (
215
- !termination &&
216
- process.platform !== 'win32' &&
217
- typeof child.pid === 'number' &&
218
- processGroupExists(child.pid)
219
- ) {
220
- await terminate()
221
- }
222
- if (termination) await termination
223
- if (settled) return
224
- settled = true
225
- unregisterExitKill()
226
- resolve({
227
- code: timedOut ? TIMEOUT_RC : aborted ? ABORT_RC : (code ?? (signal ? 1 : 0)),
228
- stdout,
229
- stderr,
230
- timedOut,
231
- aborted,
232
- })
233
- } catch (err) {
234
- if (settled) return
235
- settled = true
236
- unregisterExitKill()
237
- reject(err)
238
- }
239
- })()
240
- })
241
- if (opts.stdin !== undefined) child.stdin.end(opts.stdin)
242
- else child.stdin.end()
243
- })
244
- }
245
-
246
- /** `run` that throws (with captured stderr) on nonzero exit — for steps the bash aborted on. */
247
- export async function runOk(bin: string, argv: string[], opts: RunOptions = {}): Promise<RunResult> {
248
- const res = await run(bin, argv, opts)
249
- opts.signal?.throwIfAborted()
250
- if (res.code !== 0) {
251
- const detail = (res.stderr || res.stdout).slice(0, 1500)
252
- throw new Error(`${bin} ${argv.join(' ')} exited ${res.code}${res.timedOut ? ' (timeout)' : ''}: ${detail}`)
253
- }
254
- return res
255
- }
256
-
257
- /** Single-quote shell escaping — identical to the quoting the bash scripts relied on. */
258
- export function shq(value: string): string {
259
- return `'${value.replace(/'/g, `'\\''`)}'`
260
- }
@@ -1,12 +0,0 @@
1
- {
2
- "name": "swe-arena-deepseek-author",
3
- "description": "Pi author using DeepSeek V4 Flash through Tangle Router.",
4
- "harness": "pi",
5
- "model": {
6
- "provider": "tangle-router",
7
- "default": "deepseek-v4-flash"
8
- },
9
- "prompt": {
10
- "systemPrompt": "Improve the candidate worktree from measured failure evidence. Make the smallest coherent change, verify it, and leave the edit uncommitted."
11
- }
12
- }
@@ -1,12 +0,0 @@
1
- {
2
- "name": "swe-arena-default-author",
3
- "description": "Pi author for measured SWE arena code improvement.",
4
- "harness": "pi",
5
- "model": {
6
- "provider": "tangle-router",
7
- "default": "glm-5.2"
8
- },
9
- "prompt": {
10
- "systemPrompt": "Improve the candidate worktree from measured failure evidence. Make the smallest coherent change, verify it, and leave the edit uncommitted."
11
- }
12
- }