@cleocode/core 2026.6.14 → 2026.6.15

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 (114) hide show
  1. package/dist/check/pr-gate.d.ts +6 -2
  2. package/dist/check/pr-gate.d.ts.map +1 -1
  3. package/dist/check/pr-gate.js +14 -32
  4. package/dist/check/pr-gate.js.map +1 -1
  5. package/dist/config/config-repair.d.ts +70 -0
  6. package/dist/config/config-repair.d.ts.map +1 -0
  7. package/dist/config/config-repair.js +248 -0
  8. package/dist/config/config-repair.js.map +1 -0
  9. package/dist/config/registry.d.ts.map +1 -1
  10. package/dist/config/registry.js +4 -4
  11. package/dist/config/registry.js.map +1 -1
  12. package/dist/config.d.ts.map +1 -1
  13. package/dist/config.js +11 -10
  14. package/dist/config.js.map +1 -1
  15. package/dist/docs/export-document.js +17 -16
  16. package/dist/docs/export-document.js.map +2 -2
  17. package/dist/gc/cleanup.d.ts +23 -8
  18. package/dist/gc/cleanup.d.ts.map +1 -1
  19. package/dist/gc/cleanup.js +287 -22
  20. package/dist/gc/cleanup.js.map +1 -1
  21. package/dist/llm/cli-ops.d.ts +16 -0
  22. package/dist/llm/cli-ops.d.ts.map +1 -1
  23. package/dist/llm/cli-ops.js +32 -5
  24. package/dist/llm/cli-ops.js.map +1 -1
  25. package/dist/llm/cross-provider-selector.d.ts +249 -0
  26. package/dist/llm/cross-provider-selector.d.ts.map +1 -0
  27. package/dist/llm/cross-provider-selector.js +572 -0
  28. package/dist/llm/cross-provider-selector.js.map +1 -0
  29. package/dist/llm/index.d.ts +2 -0
  30. package/dist/llm/index.d.ts.map +1 -1
  31. package/dist/llm/index.js +1 -0
  32. package/dist/llm/index.js.map +1 -1
  33. package/dist/llm/local-model-fit.d.ts +260 -0
  34. package/dist/llm/local-model-fit.d.ts.map +1 -0
  35. package/dist/llm/local-model-fit.js +563 -0
  36. package/dist/llm/local-model-fit.js.map +1 -0
  37. package/dist/llm/plugin-facade.js +761 -230
  38. package/dist/llm/plugin-facade.js.map +3 -3
  39. package/dist/llm/provider-registry/builtin/ollama.d.ts +18 -0
  40. package/dist/llm/provider-registry/builtin/ollama.d.ts.map +1 -1
  41. package/dist/llm/provider-registry/builtin/ollama.js +20 -2
  42. package/dist/llm/provider-registry/builtin/ollama.js.map +1 -1
  43. package/dist/llm/role-resolver.d.ts.map +1 -1
  44. package/dist/llm/role-resolver.js +45 -10
  45. package/dist/llm/role-resolver.js.map +1 -1
  46. package/dist/llm/transports/codex-responses.d.ts +111 -88
  47. package/dist/llm/transports/codex-responses.d.ts.map +1 -1
  48. package/dist/llm/transports/codex-responses.js +456 -258
  49. package/dist/llm/transports/codex-responses.js.map +1 -1
  50. package/dist/release/index.d.ts +2 -2
  51. package/dist/release/index.d.ts.map +1 -1
  52. package/dist/release/index.js +1 -1
  53. package/dist/release/index.js.map +1 -1
  54. package/dist/release/reconcile.d.ts +97 -0
  55. package/dist/release/reconcile.d.ts.map +1 -1
  56. package/dist/release/reconcile.js +412 -5
  57. package/dist/release/reconcile.js.map +1 -1
  58. package/dist/resources/backend.d.ts +155 -0
  59. package/dist/resources/backend.d.ts.map +1 -0
  60. package/dist/resources/backend.js +23 -0
  61. package/dist/resources/backend.js.map +1 -0
  62. package/dist/resources/linux-backend.d.ts +167 -0
  63. package/dist/resources/linux-backend.d.ts.map +1 -0
  64. package/dist/resources/linux-backend.js +259 -0
  65. package/dist/resources/linux-backend.js.map +1 -0
  66. package/dist/resources/monitor.d.ts +230 -0
  67. package/dist/resources/monitor.d.ts.map +1 -0
  68. package/dist/resources/monitor.js +255 -0
  69. package/dist/resources/monitor.js.map +1 -0
  70. package/dist/resources/spawn-wrapper.d.ts +265 -0
  71. package/dist/resources/spawn-wrapper.d.ts.map +1 -0
  72. package/dist/resources/spawn-wrapper.js +304 -0
  73. package/dist/resources/spawn-wrapper.js.map +1 -0
  74. package/dist/selfimprove/budget.d.ts +11 -2
  75. package/dist/selfimprove/budget.d.ts.map +1 -1
  76. package/dist/selfimprove/budget.js +11 -2
  77. package/dist/selfimprove/budget.js.map +1 -1
  78. package/dist/selfimprove/fix-gen.d.ts +229 -0
  79. package/dist/selfimprove/fix-gen.d.ts.map +1 -0
  80. package/dist/selfimprove/fix-gen.js +266 -0
  81. package/dist/selfimprove/fix-gen.js.map +1 -0
  82. package/dist/selfimprove/run-loop.d.ts +44 -4
  83. package/dist/selfimprove/run-loop.d.ts.map +1 -1
  84. package/dist/selfimprove/run-loop.js +73 -6
  85. package/dist/selfimprove/run-loop.js.map +1 -1
  86. package/dist/sentient/cross-project-hygiene.d.ts +11 -2
  87. package/dist/sentient/cross-project-hygiene.d.ts.map +1 -1
  88. package/dist/sentient/cross-project-hygiene.js +73 -10
  89. package/dist/sentient/cross-project-hygiene.js.map +1 -1
  90. package/dist/sentient/daemon.d.ts.map +1 -1
  91. package/dist/sentient/daemon.js +7 -2
  92. package/dist/sentient/daemon.js.map +1 -1
  93. package/dist/sentient/worktree-dispatch.d.ts.map +1 -1
  94. package/dist/sentient/worktree-dispatch.js +8 -1
  95. package/dist/sentient/worktree-dispatch.js.map +1 -1
  96. package/dist/spawn/branch-lock.d.ts.map +1 -1
  97. package/dist/spawn/branch-lock.js +7 -1
  98. package/dist/spawn/branch-lock.js.map +1 -1
  99. package/dist/store/attachment-repair.d.ts +110 -0
  100. package/dist/store/attachment-repair.d.ts.map +1 -0
  101. package/dist/store/attachment-repair.js +326 -0
  102. package/dist/store/attachment-repair.js.map +1 -0
  103. package/dist/store/attachment-store.d.ts.map +1 -1
  104. package/dist/store/attachment-store.js +24 -7
  105. package/dist/store/attachment-store.js.map +1 -1
  106. package/dist/tasks/evidence.d.ts +34 -2
  107. package/dist/tasks/evidence.d.ts.map +1 -1
  108. package/dist/tasks/evidence.js +293 -35
  109. package/dist/tasks/evidence.js.map +1 -1
  110. package/dist/verification/verify-tools.d.ts.map +1 -1
  111. package/dist/verification/verify-tools.js +5 -6
  112. package/dist/verification/verify-tools.js.map +1 -1
  113. package/package.json +22 -12
  114. package/templates/workflows/release-prepare.yml.tmpl +48 -2
@@ -0,0 +1,304 @@
1
+ /**
2
+ * Slice-aware launch-wrapper SSoT (T11993 · Epic T11992).
3
+ *
4
+ * This module is the ONLY constructor of `systemd-run` argv for cleo children.
5
+ * Every consumer that needs to launch a cleo child in a memory-capped cgroup
6
+ * MUST call {@link buildSpawnArgs} or {@link spawnWrapped} here instead of
7
+ * constructing `systemd-run` arguments ad-hoc.
8
+ *
9
+ * ## Design
10
+ *
11
+ * Children are placed inside `cleo.slice` when systemd is available:
12
+ *
13
+ * ```
14
+ * cleo.slice
15
+ * ├── cleo-daemon.service (managed by the daemon service unit)
16
+ * └── cleo-<scopeClass>-<n>.scope (transient scopes for child spawns)
17
+ * ```
18
+ *
19
+ * The slice applies MemoryHigh (primary soft throttle) and MemoryMax (hard
20
+ * safety net) at the slice level, shared across all members. Child scopes
21
+ * inherit these limits and may override them downward.
22
+ *
23
+ * ## Staged P1 budget (IMPORTANT — read before tuning)
24
+ *
25
+ * P1 ships MemoryHigh within 5 % of MemoryMax (80 % / 85 % of a reference
26
+ * host total) so that reclaim stalls under the soft limit NEVER block the
27
+ * SQLite WAL write-transaction held by a slice member. A stalled scope
28
+ * holding a WAL write-txn for > 30 s (busy_timeout) cascades SQLITE_BUSY to
29
+ * every other slice member.
30
+ *
31
+ * **P1 installed values (safe defaults):**
32
+ * - `MemoryHigh = undefined` (disabled — no throttle in P1)
33
+ * - `MemoryMax = 32G` (hard cap, benign cgroup kill)
34
+ *
35
+ * The 60 % / 85 % target shape is documented here and in `DEFAULT_SLICE_CONFIG`
36
+ * as the P2 goal once the stall-escalator (T11994) is in place.
37
+ *
38
+ * **With `MemorySwapMax=0`:** reclaim has only page-cache to chew against
39
+ * `MemoryHigh` on anonymous heaps — admission (P2) becomes the primary
40
+ * control, throttling is not load-bearing in P1.
41
+ *
42
+ * ## oomd-avoid (selective)
43
+ *
44
+ * `ManagedOOMPreference=avoid` is applied ONLY to daemon/db-heavy scope
45
+ * classes (`'daemon'`, `'db'`). Bulk agent/test scopes do NOT get `avoid`
46
+ * because Fedora oomd monitors `user@1000.service` at 80 %/20 s and ranks
47
+ * avoid-marked candidates last — blanket avoid redirects oomd kills onto
48
+ * innocent user apps.
49
+ *
50
+ * ## Fallback
51
+ *
52
+ * On hosts without systemd-run (macOS, CI containers, minimal installs)
53
+ * the wrapper degrades log-once to plain `spawn` in a new process-group
54
+ * with NODE_OPTIONS heap cap inherited from the caller. This is mirrored
55
+ * from the writer-lease `pgid-demotion` pattern.
56
+ *
57
+ * ## Return value — ownership handle (T11998 / T11995)
58
+ *
59
+ * {@link SpawnWrappedResult} carries `{ unitName?, pid, mode }` so the
60
+ * suite-containment epic (T11998) and the janitor (T11995) can look up or
61
+ * clean up the transient scope by unit name.
62
+ *
63
+ * @module @cleocode/core/resources/spawn-wrapper
64
+ * @epic T11992
65
+ * @task T11993
66
+ */
67
+ import { spawn, spawnSync } from 'node:child_process';
68
+ import { readFileSync } from 'node:fs';
69
+ // ---------------------------------------------------------------------------
70
+ // Constants
71
+ // ---------------------------------------------------------------------------
72
+ /**
73
+ * The systemd user slice that all cleo child scopes are placed under.
74
+ *
75
+ * The slice unit (`~/.config/systemd/user/cleo.slice`) must be installed
76
+ * by the doctor/install flow before this is effective. Placing an orphan
77
+ * scope under a non-existent slice degrades silently to the default slice —
78
+ * so the slice install is best-effort and the wrapper is always safe to call.
79
+ */
80
+ export const CLEO_SLICE = 'cleo.slice';
81
+ /**
82
+ * Default per-scope memory resource config (P1 staged values).
83
+ *
84
+ * P1: MemoryHigh disabled, MemoryMax=32G.
85
+ * P2 target (after T11994 stall-escalator lands): memoryHigh=0.60, memoryMax=0.85.
86
+ */
87
+ export const DEFAULT_SCOPE_RESOURCES = {
88
+ memoryHigh: 'infinity', // P1: disabled — no throttle (safe until P2 stall-escalator)
89
+ memoryMax: '32G', // P1: hard cap (benign cgroup kill; coredumps suppressed via ulimit -c 0)
90
+ };
91
+ /**
92
+ * Scope classes that receive `ManagedOOMPreference=avoid`.
93
+ *
94
+ * Only write-transaction holders (daemon, db) are marked `avoid` to prevent
95
+ * mid-txn oomd kills. See module-level TSDoc for the Fedora oomd rationale.
96
+ */
97
+ const OOM_AVOID_CLASSES = new Set(['daemon', 'db']);
98
+ // ---------------------------------------------------------------------------
99
+ // Internal helpers
100
+ // ---------------------------------------------------------------------------
101
+ /**
102
+ * Is `systemd-run` available on this host? Probed once and cached.
103
+ * Mirrors the probe in `packages/core/src/check/pr-gate.ts`.
104
+ */
105
+ let _systemdRunAvailable;
106
+ /**
107
+ * Check whether `systemd-run --user` is usable on this host.
108
+ *
109
+ * Returns `false` on non-Linux, when systemd-run is not on PATH, or when
110
+ * DBUS_SESSION_BUS_ADDRESS / XDG_RUNTIME_DIR are absent (CI containers,
111
+ * ssh sessions without a user bus).
112
+ */
113
+ export function hasSystemdRun() {
114
+ if (_systemdRunAvailable !== undefined)
115
+ return _systemdRunAvailable;
116
+ if (process.platform !== 'linux') {
117
+ _systemdRunAvailable = false;
118
+ return false;
119
+ }
120
+ // Quick binary availability check — does NOT test user-bus connectivity.
121
+ const probe = spawnSync('systemd-run', ['--version'], { stdio: 'ignore' });
122
+ _systemdRunAvailable = probe.status === 0;
123
+ return _systemdRunAvailable;
124
+ }
125
+ /**
126
+ * Force-override the cached systemd-run availability.
127
+ *
128
+ * Exposed for unit tests that need to exercise the pgid-fallback or
129
+ * systemd paths without the real binary.
130
+ *
131
+ * @param available - `true` = force systemd path, `false` = force pgid path.
132
+ */
133
+ export function _forceSystemdRunAvailable(available) {
134
+ _systemdRunAvailable = available;
135
+ }
136
+ /** Whether we have already emitted the pgid-demotion log line for this process. */
137
+ let _pgidDemotionLogged = false;
138
+ /**
139
+ * Resolve a memory value to a systemd property string.
140
+ *
141
+ * Numbers in (0, 1] are treated as fractions of a `totalBytes` reference.
142
+ * Strings are passed through verbatim. `undefined` / `'infinity'` resolves
143
+ * to `'infinity'` (disabled).
144
+ */
145
+ function resolveMemoryValue(val, totalBytes) {
146
+ if (val === undefined || val === 'infinity')
147
+ return 'infinity';
148
+ if (typeof val === 'string')
149
+ return val;
150
+ // Fraction: multiply by total and round to nearest mebibyte boundary.
151
+ const bytes = Math.round(val * totalBytes);
152
+ const mib = Math.round(bytes / (1024 * 1024));
153
+ return `${mib}M`;
154
+ }
155
+ /**
156
+ * Read /proc/meminfo MemTotal in bytes. Returns 32 GiB as a safe fallback
157
+ * when unavailable (non-Linux, CI, permission denied).
158
+ */
159
+ function readMemTotalBytes() {
160
+ if (process.platform !== 'linux')
161
+ return 32 * 1024 * 1024 * 1024;
162
+ try {
163
+ const raw = readFileSync('/proc/meminfo', 'utf8');
164
+ const m = raw.match(/^MemTotal:\s+(\d+)\s+kB/m);
165
+ if (m?.[1])
166
+ return parseInt(m[1], 10) * 1024;
167
+ }
168
+ catch {
169
+ // ignore
170
+ }
171
+ return 32 * 1024 * 1024 * 1024;
172
+ }
173
+ /** Counter for generating unique scope discriminators within a process. */
174
+ let _scopeCounter = 0;
175
+ // ---------------------------------------------------------------------------
176
+ // Core API
177
+ // ---------------------------------------------------------------------------
178
+ /**
179
+ * Build the argv for a cleo child spawn.
180
+ *
181
+ * When `systemd-run` is available, the result is:
182
+ *
183
+ * ```
184
+ * ['systemd-run', '--user', '--scope', '--slice=cleo.slice',
185
+ * '--unit=cleo-<class>-<id>.scope',
186
+ * '-p', 'MemoryHigh=<high>', '-p', 'MemoryMax=<max>',
187
+ * '-p', 'MemorySwapMax=0',
188
+ * ['-p', 'ManagedOOMPreference=avoid'], // daemon/db only
189
+ * '--',
190
+ * // when noCoreFile=true (default):
191
+ * 'sh', '-c', 'ulimit -c 0; exec "$@"', 'sh', command, ...args
192
+ * // when noCoreFile=false:
193
+ * command, ...args]
194
+ * ```
195
+ *
196
+ * `LimitCORE` is intentionally NOT used — it is a service-unit EXEC property
197
+ * and is rejected by `systemd-run --scope` with "Unknown assignment: LimitCORE".
198
+ * Core-dump suppression is applied at the process level instead via
199
+ * `ulimit -c 0` (POSIX sh, works in both systemd and pgid-fallback paths).
200
+ *
201
+ * When `systemd-run` is NOT available, the result is `[command, ...args]`
202
+ * (or the sh/ulimit-wrapped form when noCoreFile=true) and `mode` is `'pgid'`.
203
+ *
204
+ * @param command - The executable to run (e.g. `'node'`).
205
+ * @param args - Arguments to pass to the executable.
206
+ * @param opts - Wrapper options (scope class, resources, etc.).
207
+ * @returns Build result with final command, args, mode, and unit name.
208
+ */
209
+ export function buildSpawnArgs(command, args, opts = {}) {
210
+ const { scopeClass = 'agent', scopeId, resources = {}, noCoreFile = true } = opts;
211
+ if (!hasSystemdRun()) {
212
+ if (!_pgidDemotionLogged) {
213
+ _pgidDemotionLogged = true;
214
+ process.stderr.write('[cleo:spawn-wrapper] systemd-run unavailable — falling back to plain pgid spawn ' +
215
+ '(no cgroup containment; set NODE_OPTIONS=--max-old-space-size=<mb> externally)\n');
216
+ }
217
+ if (noCoreFile) {
218
+ // Apply ulimit -c 0 in the pgid path as well so core suppression is
219
+ // consistent regardless of whether systemd is available.
220
+ return {
221
+ command: 'sh',
222
+ args: ['-c', 'ulimit -c 0; exec "$@"', 'sh', command, ...args],
223
+ mode: 'pgid',
224
+ };
225
+ }
226
+ return { command, args: [...args], mode: 'pgid' };
227
+ }
228
+ const totalBytes = readMemTotalBytes();
229
+ const merged = {
230
+ memoryHigh: resources.memoryHigh ?? DEFAULT_SCOPE_RESOURCES.memoryHigh,
231
+ memoryMax: resources.memoryMax ?? DEFAULT_SCOPE_RESOURCES.memoryMax,
232
+ };
233
+ const highStr = resolveMemoryValue(merged.memoryHigh, totalBytes);
234
+ const maxStr = resolveMemoryValue(merged.memoryMax, totalBytes);
235
+ // Build a deterministic, unique unit name.
236
+ const counter = ++_scopeCounter;
237
+ const discriminator = scopeId ? scopeId.replace(/[^a-zA-Z0-9-]/g, '-') : String(counter);
238
+ const unitName = `cleo-${scopeClass}-${discriminator}.scope`;
239
+ const wrapArgs = [
240
+ '--user',
241
+ '--scope',
242
+ `--slice=${CLEO_SLICE}`,
243
+ `--unit=${unitName}`,
244
+ '-p',
245
+ `MemoryMax=${maxStr}`,
246
+ '-p',
247
+ 'MemorySwapMax=0',
248
+ ];
249
+ // MemoryHigh: only emit the directive when it is a real limit (not infinity).
250
+ if (highStr !== 'infinity') {
251
+ wrapArgs.push('-p', `MemoryHigh=${highStr}`);
252
+ }
253
+ // Selective oomd-avoid: only for write-txn holder classes.
254
+ if (OOM_AVOID_CLASSES.has(scopeClass)) {
255
+ wrapArgs.push('-p', 'ManagedOOMPreference=avoid');
256
+ }
257
+ if (noCoreFile) {
258
+ // LimitCORE is a service-unit EXEC property — it is NOT valid on scope
259
+ // units and causes systemd-run to reject the argv with:
260
+ // "Unknown assignment: LimitCORE=0"
261
+ // Suppress coredumps at the process level instead: wrap the inner command
262
+ // in a tiny sh fragment that sets `ulimit -c 0` then execs the real binary.
263
+ // This is equivalent to LimitCORE for our purposes and works on both
264
+ // Fedora and Ubuntu CI runners.
265
+ wrapArgs.push('--', 'sh', '-c', 'ulimit -c 0; exec "$@"', 'sh', command, ...args);
266
+ }
267
+ else {
268
+ wrapArgs.push('--', command, ...args);
269
+ }
270
+ return {
271
+ command: 'systemd-run',
272
+ args: wrapArgs,
273
+ mode: 'systemd',
274
+ unitName,
275
+ };
276
+ }
277
+ /**
278
+ * Spawn a command wrapped in a cleo.slice transient cgroup scope.
279
+ *
280
+ * This is a thin convenience wrapper over {@link buildSpawnArgs} +
281
+ * Node.js `child_process.spawn`. All cleo child spawns SHOULD route through
282
+ * this function instead of constructing `systemd-run` arguments inline.
283
+ *
284
+ * The returned {@link SpawnWrappedResult} carries `unitName` — the systemd
285
+ * transient scope unit name — as the ownership/cleanup handle for
286
+ * T11998 (suite containment) and T11995 (janitor).
287
+ *
288
+ * @param command - The executable to run.
289
+ * @param args - Arguments to pass to the executable.
290
+ * @param spawnOpts - Options forwarded to `child_process.spawn`.
291
+ * @param wrapOpts - Wrapper options (scope class, resources, etc.).
292
+ * @returns Wrapped spawn result.
293
+ */
294
+ export function spawnWrapped(command, args, spawnOpts = {}, wrapOpts = {}) {
295
+ const built = buildSpawnArgs(command, args, wrapOpts);
296
+ const child = spawn(built.command, built.args, spawnOpts);
297
+ return {
298
+ child,
299
+ pid: child.pid,
300
+ mode: built.mode,
301
+ unitName: built.unitName,
302
+ };
303
+ }
304
+ //# sourceMappingURL=spawn-wrapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spawn-wrapper.js","sourceRoot":"","sources":["../../src/resources/spawn-wrapper.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiEG;AAEH,OAAO,EAAqB,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAkIvC,8EAA8E;AAC9E,YAAY;AACZ,8EAA8E;AAE9E;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,YAAqB,CAAC;AAEhD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAkC;IACpE,UAAU,EAAE,UAAU,EAAE,6DAA6D;IACrF,SAAS,EAAE,KAAK,EAAE,0EAA0E;CAC7F,CAAC;AAEF;;;;;GAKG;AACH,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAa,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC;AAEhE,8EAA8E;AAC9E,mBAAmB;AACnB,8EAA8E;AAE9E;;;GAGG;AACH,IAAI,oBAAyC,CAAC;AAE9C;;;;;;GAMG;AACH,MAAM,UAAU,aAAa;IAC3B,IAAI,oBAAoB,KAAK,SAAS;QAAE,OAAO,oBAAoB,CAAC;IACpE,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;QACjC,oBAAoB,GAAG,KAAK,CAAC;QAC7B,OAAO,KAAK,CAAC;IACf,CAAC;IACD,yEAAyE;IACzE,MAA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AC,CAAC;IACxC,CAAC;IAED,OAAO;QACL,OAAO,EAAE,aAAa;QACtB,IAAI,EAAE,QAAQ;QACd,IAAI,EAAE,SAAS;QACf,QAAQ;KACT,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,YAAY,CAC1B,OAAe,EACf,IAAuB,EACvB,YAAyC,EAAE,EAC3C,WAAkC,EAAE;IAEpC,MAAM,KAAK,GAAG,cAAc,CAAC,OAAO,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;IACtD,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IAC1D,OAAO;QACL,KAAK;QACL,GAAG,EAAE,KAAK,CAAC,GAAG;QACd,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,QAAQ,EAAE,KAAK,CAAC,QAAQ;KACzB,CAAC;AACJ,CAAC"}
@@ -75,13 +75,22 @@ export interface SelfImproveBudget {
75
75
  */
76
76
  export declare const DEFAULT_BUDGET: SelfImproveBudget;
77
77
  /**
78
+ * @deprecated Use {@link "../resources/spawn-wrapper.js".buildSpawnArgs} instead.
79
+ *
78
80
  * The launch-boundary memory cap — an OPERATIONAL wrapper, NOT an in-code cap.
79
81
  *
80
82
  * A CORE function cannot portably self-confine to a cgroup (`systemd-run` is
81
83
  * Linux-only; re-exec'ing under it from inside the engine is fragile), so the
82
84
  * runbook / spawn wrapper that invokes `cleo selfimprove run` wraps it on Linux.
83
- * On macOS the gondolin VM's own `memory` option bounds the guest. Exported as a
84
- * documented constant so the spawn wrapper and the runbook share one SSoT string.
85
+ * On macOS the gondolin VM's own `memory` option bounds the guest.
86
+ *
87
+ * **Retired (T11993)**: callers should use
88
+ * `buildSpawnArgs('cleo', ['selfimprove', 'run', ...], {}, { scopeClass: 'agent' })`
89
+ * from `@cleocode/core/resources/spawn-wrapper` instead. This constant remains
90
+ * exported only for backward compatibility until all doc references are updated.
91
+ *
92
+ * The new SSoT places children under `cleo.slice` with coredumps suppressed
93
+ * via `ulimit -c 0` and staged memory budgets (see spawn-wrapper module TSDoc).
85
94
  */
86
95
  export declare const MEMORY_MAX_LAUNCH_WRAPPER: "systemd-run --user --scope -p MemoryMax=32G -p MemorySwapMax=0";
87
96
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"budget.d.ts","sourceRoot":"","sources":["../../src/selfimprove/budget.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH;;;;;GAKG;AACH,MAAM,MAAM,oBAAoB;AAC9B,mEAAmE;AACjE,SAAS;AACX,+EAA+E;GAC7E,kBAAkB;AACpB,+DAA+D;GAC7D,eAAe;AACjB,6CAA6C;GAC3C,SAAS,CAAC;AAEd;;;;;;;;;;GAUG;AACH,MAAM,WAAW,iBAAiB;IAChC,uDAAuD;IACvD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,8CAA8C;IAC9C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,2DAA2D;IAC3D,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,8DAA8D;IAC9D,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;CAC/B;AAED;;;;GAIG;AACH,eAAO,MAAM,cAAc,EAAE,iBAK5B,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,yBAAyB,EACpC,gEAAyE,CAAC;AAE5E;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B,2BAA2B;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,wBAAwB;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,+BAA+B;IAC/B,GAAG,EAAE,MAAM,CAAC;IACZ,kCAAkC;IAClC,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,2CAA2C;AAC3C,wBAAgB,UAAU,IAAI,WAAW,CAExC;AAED;;;GAGG;AACH,MAAM,WAAW,YAAY;I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,EAAE,YAAY,GAAG,IAAI;CA2BzC;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAC3B,SAAS,GAAE,OAAO,CAAC,iBAAiB,CAAM,EAC1C,GAAG,GAAE,MAAM,CAAC,UAAwB,GACnC,iBAAiB,CAenB"}
@@ -44,13 +44,22 @@ export const DEFAULT_BUDGET = {
44
44
  maxWorktrees: 1,
45
45
  };
46
46
  /**
47
+ * @deprecated Use {@link "../resources/spawn-wrapper.js".buildSpawnArgs} instead.
48
+ *
47
49
  * The launch-boundary memory cap — an OPERATIONAL wrapper, NOT an in-code cap.
48
50
  *
49
51
  * A CORE function cannot portably self-confine to a cgroup (`systemd-run` is
50
52
  * Linux-only; re-exec'ing under it from inside the engine is fragile), so the
51
53
  * runbook / spawn wrapper that invokes `cleo selfimprove run` wraps it on Linux.
52
- * On macOS the gondolin VM's own `memory` option bounds the guest. Exported as a
53
- * documented constant so the spawn wrapper and the runbook share one SSoT string.
54
+ * On macOS the gondolin VM's own `memory` option bounds the guest.
55
+ *
56
+ * **Retired (T11993)**: callers should use
57
+ * `buildSpawnArgs('cleo', ['selfimprove', 'run', ...], {}, { scopeClass: 'agent' })`
58
+ * from `@cleocode/core/resources/spawn-wrapper` instead. This constant remains
59
+ * exported only for backward compatibility until all doc references are updated.
60
+ *
61
+ * The new SSoT places children under `cleo.slice` with coredumps suppressed
62
+ * via `ulimit -c 0` and staged memory budgets (see spawn-wrapper module TSDoc).
54
63
  */
55
64
  export const MEMORY_MAX_LAUNCH_WRAPPER = 'systemd-run --user --scope -p MemoryMax=32G -p MemorySwapMax=0';
56
65
  /** A fresh, zeroed {@link BudgetSpend}. */
@@ -1 +1 @@
1
- {"version":3,"file":"budget.js","sourceRoot":"","sources":["../../src/selfimprove/budget.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAwCH;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAsB;IAC/C,SAAS,E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AI,cAAc,CAAC,MAAM,CAAC,CAAC;IACtE,MAAM,YAAY,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,SAAS,CAAC,YAAY,IAAI,cAAc,CAAC,YAAY,CAAC,CAAC;IAExF,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC;AACrD,CAAC"}
@@ -0,0 +1,229 @@
1
+ /**
2
+ * Fix-generation stage for the self-improvement loop (T11889 · T11975).
3
+ *
4
+ * This is the missing autonomous link the v1 loop explicitly stubbed out
5
+ * ("NO autonomous fix-gen in v1", see {@link "./run-loop.js"}): given a detected
6
+ * regression (an open `selfimprove_dhq` + its envelope-diff) plus minimal repo
7
+ * context, it asks the LLM to PROPOSE a unified-diff patch and writes that patch
8
+ * to the path the draft-PR egress ({@link "./draft-pr.js".openDraftPr}) already
9
+ * `existsSync`-checks: `<cwd>/selfimprove-<scenario>.patch`. Once the patch is on
10
+ * disk the existing egress guard opens ONE DRAFT PR — closing the
11
+ * DHQ → fix → draft-PR pipeline end-to-end.
12
+ *
13
+ * ## Hard safety posture (unchanged from v1 — P5 spec §B.7)
14
+ *
15
+ * - **LLM ONLY via the E9 chokepoint.** The real generator
16
+ * ({@link createLlmFixGenerator}) resolves its model strictly through
17
+ * {@link "../llm/system-resolver.js".resolveLLMForSystem} → {@link ModelRunner}
18
+ * (Gate-13). It constructs NO raw provider client, reads NO `*_API_KEY` env,
19
+ * and hardcodes no model id — the resolver/registry is the SSoT. The
20
+ * plaintext token is materialized only at the wire boundary (E10).
21
+ * - **Draft-PR-ONLY, never auto-merge.** This module produces a PATCH FILE only;
22
+ * the egress that consumes it always opens a `--draft` PR against a feature
23
+ * branch (never `main`). This module performs NO git/gh action.
24
+ * - **Graceful degrade, never a rogue mutation.** Every failure (no credential,
25
+ * LLM error, empty / non-unified-diff output) returns a typed
26
+ * {@link FixGenResult} of kind `'skipped'` and writes NO patch file — so the
27
+ * existing egress guard (`existsSync` on the patch path) simply skips the PR.
28
+ * This function NEVER throws.
29
+ * - **Injectable seam.** The LLM dependency is the {@link FixGenerator} port;
30
+ * unit tests inject a deterministic fake that returns a canned patch, so NO
31
+ * real LLM is reached in tests.
32
+ *
33
+ * CORE-first: this engine lives in `core` and owns the `FixGenerator` port TYPE.
34
+ * Import-time side-effect-free.
35
+ *
36
+ * @module @cleocode/core/selfimprove/fix-gen
37
+ * @epic T11889
38
+ * @task T11975
39
+ */
40
+ import type { Logger } from 'pino';
41
+ import type { DiffEntry } from './envelope-diff.js';
42
+ /**
43
+ * The structured request handed to a {@link FixGenerator}. Carries only what the
44
+ * generator needs to draft a patch: the DHQ identity, the scenario, the
45
+ * regression diff, and a minimal slice of repo context.
46
+ */
47
+ export interface FixGenRequest {
48
+ /** The stable `'DHQ-###'` handle of the open regression. */
49
+ readonly dhqId: string;
50
+ /** The scenario whose replay diverged from the golden. */
51
+ readonly scenario: string;
52
+ /** The idempotency hash tying this request to ONE open DHQ row. */
53
+ readonly questionHash: string;
54
+ /** The structured regression entries (the evidence) from the envelope diff. */
55
+ readonly regressions: readonly DiffEntry[];
56
+ /**
57
+ * Minimal repo context the generator may use to ground the patch (e.g. the
58
+ * project root, a short description). Kept small on purpose — the loop does NOT
59
+ * stuff the whole repo into the prompt.
60
+ */
61
+ readonly repoContext: FixGenRepoContext;
62
+ }
63
+ /** Minimal repo context grounding a fix-generation request. */
64
+ export interface FixGenRepoContext {
65
+ /** Absolute project root the patch is generated against. */
66
+ readonly projectRoot: string;
67
+ /** Optional one-line summary of what the scenario exercises. */
68
+ readonly summary?: string;
69
+ }
70
+ /** A generated patch, or an explicit "no usable patch" signal. */
71
+ export type FixGenOutput = {
72
+ /** The generator produced a candidate unified-diff patch. */
73
+ readonly kind: 'patch';
74
+ /** The raw unified-diff text (validated by {@link generateFixPatch}). */
75
+ readonly diff: string;
76
+ /** The model id that produced it (for audit). */
77
+ readonly model: string;
78
+ } | {
79
+ /** The generator produced no usable patch (degrade — never an error throw). */
80
+ readonly kind: 'none';
81
+ /** Machine-stable reason for the absence. */
82
+ readonly reason: string;
83
+ };
84
+ /**
85
+ * The injectable fix-generation port (the LLM seam).
86
+ *
87
+ * The real implementation ({@link createLlmFixGenerator}) drives the E9 chokepoint;
88
+ * tests inject a deterministic fake returning a canned patch. A `FixGenerator`
89
+ * MUST NOT throw — it encodes "no patch" as `{ kind: 'none', reason }`.
90
+ */
91
+ export interface FixGenerator {
92
+ /**
93
+ * Propose a unified-diff patch for one regression.
94
+ *
95
+ * @param request - The structured {@link FixGenRequest}.
96
+ * @returns A {@link FixGenOutput} — a candidate patch or an explicit "none".
97
+ */
98
+ propose(request: FixGenRequest): Promise<FixGenOutput>;
99
+ }
100
+ /** The terminal outcome of {@link generateFixPatch}. */
101
+ export type FixGenResult = {
102
+ /** A validated patch was written to {@link FixGenResultWritten.patchPath}. */
103
+ readonly kind: 'written';
104
+ /** Absolute path the patch was written to. */
105
+ readonly patchPath: string;
106
+ /** Byte length of the written patch. */
107
+ readonly bytes: number;
108
+ /** The model id that produced the patch. */
109
+ readonly model: string;
110
+ } | {
111
+ /** No patch was written; the egress guard will skip the PR. */
112
+ readonly kind: 'skipped';
113
+ /** Machine-stable reason recorded on the DHQ evidence. */
114
+ readonly reason: string;
115
+ };
116
+ /**
117
+ * Options for {@link generateFixPatch}.
118
+ */
119
+ export interface GenerateFixPatchOptions {
120
+ /** The structured fix-generation request. */
121
+ readonly request: FixGenRequest;
122
+ /** The injected generator (real LLM impl or a test fake). */
123
+ readonly generator: FixGenerator;
124
+ /**
125
+ * Working directory the patch path is resolved against — MUST match the `cwd`
126
+ * the downstream {@link "./draft-pr.js".openDraftPr} uses, so the file it writes
127
+ * is the file the egress finds.
128
+ */
129
+ readonly cwd?: string;
130
+ /** Injectable logger (defaults to the module logger). */
131
+ readonly logger?: Logger;
132
+ }
133
+ /**
134
+ * Compute the patch path the draft-PR egress expects for a scenario:
135
+ * `<cwd>/selfimprove-<scenario>.patch`. The scenario is sanitized to a safe file
136
+ * stem so a hostile scenario name cannot escape the cwd.
137
+ *
138
+ * @param scenario - The scenario name.
139
+ * @param cwd - The working directory to resolve against (defaults to `process.cwd`).
140
+ * @returns The absolute patch path.
141
+ */
142
+ export declare function fixPatchPath(scenario: string, cwd?: string): string;
143
+ /**
144
+ * Is `text` a plausible unified diff?
145
+ *
146
+ * A real `git apply`-able patch always carries at least one of the canonical
147
+ * unified-diff markers ({@link UNIFIED_DIFF_MARKERS}). An LLM that returns prose,
148
+ * an apology, or an empty string fails this guard, so the loop degrades to "no
149
+ * patch" rather than writing junk the egress would then fail to `git apply`.
150
+ *
151
+ * This is a cheap structural sniff, NOT a full parse — the authoritative
152
+ * applicability check is `git apply` inside the egress (which fails the PR cut on
153
+ * a bad patch, never `main`).
154
+ *
155
+ * @param text - Candidate patch text.
156
+ * @returns `true` when the text looks like a unified diff.
157
+ */
158
+ export declare function looksLikeUnifiedDiff(text: string): boolean;
159
+ /**
160
+ * Build the system + user prompt the real generator sends to the LLM. Pure
161
+ * (no IO) so it is unit-testable in isolation. The prompt is deliberately strict:
162
+ * "respond with ONLY a unified diff" — anything else fails
163
+ * {@link looksLikeUnifiedDiff} downstream and degrades to "no patch".
164
+ *
165
+ * @param request - The fix-generation request.
166
+ * @returns The `{ system, user }` prompt pair.
167
+ */
168
+ export declare function buildFixGenPrompt(request: FixGenRequest): {
169
+ system: string;
170
+ user: string;
171
+ };
172
+ /**
173
+ * Run the fix-generation stage: ask the injected {@link FixGenerator} for a patch,
174
+ * validate it as a unified diff, and write it to the egress-expected patch path.
175
+ *
176
+ * This function NEVER throws and NEVER mutates anything but the single patch file.
177
+ * On ANY degrade path — generator returns `'none'`, the generator throws, or the
178
+ * returned text is not a unified diff — it writes NO file and returns
179
+ * `{ kind: 'skipped', reason }`, so the downstream `existsSync` egress guard
180
+ * simply skips the PR. The caller records the `reason` on the DHQ evidence.
181
+ *
182
+ * @param opts - See {@link GenerateFixPatchOptions}.
183
+ * @returns A {@link FixGenResult}.
184
+ *
185
+ * @example
186
+ * ```ts
187
+ * const res = await generateFixPatch({
188
+ * request: { dhqId: 'DHQ-abcd1234', scenario, questionHash, regressions, repoContext },
189
+ * generator: createLlmFixGenerator(),
190
+ * cwd: projectRoot,
191
+ * });
192
+ * if (res.kind === 'written') { // openDraftPr will now find selfimprove-<scenario>.patch }
193
+ * ```
194
+ */
195
+ export declare function generateFixPatch(opts: GenerateFixPatchOptions): Promise<FixGenResult>;
196
+ /**
197
+ * Construct the REAL fix generator — the one that drives the E9 LLM chokepoint.
198
+ *
199
+ * Resolution funnels through {@link resolveLLMForSystem}(`'task-executor'`) →
200
+ * {@link ModelRunner.build} → `session.send` (ONE non-streaming completion).
201
+ * It constructs NO raw provider client, reads NO API-key env, and hardcodes no
202
+ * model id (Gate-13). The plaintext credential is materialized ONLY at the
203
+ * `ModelRunner` wire boundary (E10) via the sealed handle. When no credential is
204
+ * reachable it returns `{ kind: 'none' }` — the loop degrades to "no patch", no
205
+ * PR. This function constructs nothing at call time (lazy dynamic imports keep the
206
+ * module import-time side-effect-free + the E9 deps off the hot import path).
207
+ *
208
+ * @param opts - Optional project root threaded into the resolver.
209
+ * @returns A {@link FixGenerator} backed by the E9 chokepoint.
210
+ *
211
+ * @example
212
+ * ```ts
213
+ * const gen = createLlmFixGenerator({ projectRoot });
214
+ * const out = await gen.propose(request); // resolves model via E9, never raw client
215
+ * ```
216
+ */
217
+ export declare function createLlmFixGenerator(opts?: {
218
+ projectRoot?: string;
219
+ }): FixGenerator;
220
+ /**
221
+ * Strip a single surrounding markdown code fence (```diff … ```), if present, so a
222
+ * model that wraps its diff still yields an applyable patch. A bare diff passes
223
+ * through untouched.
224
+ *
225
+ * @param text - Candidate patch text (already trimmed).
226
+ * @returns The fence-stripped text.
227
+ */
228
+ export declare function stripCodeFences(text: string): string;
229
+ //# sourceMappingURL=fix-gen.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fix-gen.d.ts","sourceRoot":"","sources":["../../src/selfimprove/fix-gen.ts"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