@kitman-sh/cli 0.42.2 → 0.44.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 (28) hide show
  1. package/dist/{chunk-3gax0xq6.js → chunk-134jdvs6.js} +2 -2
  2. package/dist/{chunk-hfy8nmat.js → chunk-1c4wk9dr.js} +3 -3
  3. package/dist/{chunk-q6qn9c47.js → chunk-1k6z8q79.js} +135 -297
  4. package/dist/{chunk-sasjamqz.js → chunk-3mbp8cse.js} +205 -44
  5. package/dist/{chunk-1w517sym.js → chunk-3zy2vbp0.js} +10 -10
  6. package/dist/{chunk-17715h5w.js → chunk-5ccz7ghp.js} +69 -55
  7. package/dist/{chunk-1gr39h4v.js → chunk-7rj9d0rp.js} +21 -2
  8. package/dist/{chunk-wre79w3z.js → chunk-8a7337s1.js} +1 -1
  9. package/dist/{chunk-qndcafax.js → chunk-9h16pekj.js} +1 -1
  10. package/dist/{chunk-gqgbah9q.js → chunk-d0rx9esz.js} +6 -6
  11. package/dist/{chunk-t8y2y7ha.js → chunk-d2tpz1yp.js} +1 -1
  12. package/dist/{chunk-re7cr0kk.js → chunk-dj873p0e.js} +17 -17
  13. package/dist/{chunk-r5b36fgg.js → chunk-dp6v658s.js} +4 -4
  14. package/dist/{chunk-vjkgbsry.js → chunk-dre4f6s4.js} +9 -9
  15. package/dist/{chunk-33zd0yt4.js → chunk-gw0pc35c.js} +17 -17
  16. package/dist/{chunk-sbk4evb4.js → chunk-hmctc4eq.js} +3 -3
  17. package/dist/{chunk-hg9y4ykj.js → chunk-j60f2tr1.js} +4 -4
  18. package/dist/{chunk-tpmyf5mk.js → chunk-k2re3tp5.js} +1 -1
  19. package/dist/{chunk-drw8m50d.js → chunk-ncp13gyf.js} +2 -2
  20. package/dist/{chunk-rc4wvjf2.js → chunk-qkwkxn4d.js} +349 -102
  21. package/dist/{chunk-2bt9e1fj.js → chunk-wh3pjr9r.js} +11 -11
  22. package/dist/{chunk-c3ms91a6.js → chunk-wkg1v0kd.js} +20 -20
  23. package/dist/{chunk-mc0xxx2z.js → chunk-wvnsqt17.js} +6 -6
  24. package/dist/{chunk-b4td2pgc.js → chunk-x0ma41ys.js} +94 -84
  25. package/dist/{chunk-dhe1fwhw.js → chunk-zkvrxna8.js} +2 -2
  26. package/dist/{chunk-y6mjtq6n.js → chunk-zvmdyf3v.js} +53 -33
  27. package/dist/index.js +4 -4
  28. package/package.json +1 -1
@@ -38,31 +38,39 @@ import {
38
38
  isSuccess,
39
39
  getSuccess,
40
40
  chunksOf,
41
+ toPredicate,
42
+ has,
43
+ compose,
41
44
  TaggedError,
45
+ forkUnsafe,
42
46
  succeed3,
43
47
  void_2,
44
48
  isSuccess2,
45
49
  isFailure2,
46
50
  hasInterrupts,
47
51
  makeUnsafe5,
48
- make15,
52
+ make16,
49
53
  _await,
50
54
  fail5,
51
55
  isDoneUnsafe,
52
56
  succeed4,
53
57
  doneUnsafe,
58
+ into,
54
59
  makeUnsafe6,
55
60
  provide,
56
61
  succeed5,
57
62
  effect,
58
63
  mergeAll,
59
64
  die2,
65
+ hasInterruptsOnly,
60
66
  findErrorOption,
67
+ filterInterruptors,
61
68
  pretty,
62
69
  exponential,
63
70
  jittered,
64
71
  spaced,
65
72
  upTo,
73
+ isEffect,
66
74
  all3,
67
75
  validate,
68
76
  findFirst,
@@ -82,6 +90,7 @@ import {
82
90
  die3,
83
91
  try_2,
84
92
  yieldNow,
93
+ withFiber2,
85
94
  flatMap3,
86
95
  andThen2,
87
96
  tap2,
@@ -122,12 +131,14 @@ import {
122
131
  addFinalizer2,
123
132
  ensuring2,
124
133
  onExit,
134
+ interrupt3,
125
135
  uninterruptible,
126
136
  forever,
127
137
  repeat,
128
138
  forkIn,
129
139
  forkScoped,
130
140
  forkDetach,
141
+ runFork,
131
142
  fnUntraced,
132
143
  logWarning,
133
144
  logError,
@@ -175,7 +186,58 @@ import {
175
186
  decodeJsonStringSync,
176
187
  encodeUnknownJsonStringSync,
177
188
  storable
178
- } from "./chunk-b4td2pgc.js";
189
+ } from "./chunk-x0ma41ys.js";
190
+ import {
191
+ empty2,
192
+ currentTimeMillis,
193
+ join,
194
+ interrupt,
195
+ interruptAll,
196
+ unbounded,
197
+ publishUnsafe,
198
+ unbounded2,
199
+ offer,
200
+ makeUnsafe3,
201
+ make11,
202
+ fromQueue,
203
+ fromPubSub,
204
+ map2,
205
+ filter,
206
+ take2,
207
+ mapAccum,
208
+ decodeText,
209
+ encodeText,
210
+ splitLines,
211
+ run,
212
+ runCollect,
213
+ runFold,
214
+ runHead,
215
+ runForEach,
216
+ FileSystem,
217
+ Path,
218
+ embeddedFile,
219
+ extractEmbeddedFile,
220
+ withDefault,
221
+ String2,
222
+ optionalEnv,
223
+ operatorConfigHome,
224
+ tempDirectoryScoped,
225
+ harnessesUnsupportedInSrt2,
226
+ harnessesUnsupportedInDocker2,
227
+ compiled2,
228
+ pinnedSrtCommand2,
229
+ pinnedSrtStepCommand2,
230
+ runSrtCli2,
231
+ kitmanCacheDirectory2,
232
+ srtSettings2,
233
+ srtCacheEnvironment2,
234
+ srtInheritedEnv2,
235
+ inheritedEnvironment2,
236
+ withOnlyEnvironment2,
237
+ writeSrtSettings2,
238
+ srtStepArgv2,
239
+ srtArgv2
240
+ } from "./chunk-3mbp8cse.js";
179
241
  import {
180
242
  SecureRandom,
181
243
  layerWebCrypto,
@@ -231,6 +293,7 @@ import {
231
293
  layer4,
232
294
  SetupArchive,
233
295
  kitMcpSecretNames,
296
+ WorkAvailable,
234
297
  RunSettled,
235
298
  UpdateAvailable,
236
299
  HERDR_CORE_GENERATION2,
@@ -264,56 +327,7 @@ import {
264
327
  checkServicesFile,
265
328
  checkServices,
266
329
  serviceChecks
267
- } from "./chunk-q6qn9c47.js";
268
- import {
269
- currentTimeMillis,
270
- join,
271
- interrupt,
272
- unbounded,
273
- publishUnsafe,
274
- unbounded2,
275
- offer,
276
- makeUnsafe3,
277
- make10,
278
- fromQueue,
279
- fromPubSub,
280
- map2,
281
- filter,
282
- take2,
283
- mapAccum,
284
- decodeText,
285
- encodeText,
286
- splitLines,
287
- run,
288
- runCollect,
289
- runFold,
290
- runHead,
291
- runForEach,
292
- FileSystem,
293
- Path,
294
- embeddedFile,
295
- extractEmbeddedFile,
296
- withDefault,
297
- String2,
298
- optionalEnv,
299
- operatorConfigHome,
300
- tempDirectoryScoped,
301
- harnessesUnsupportedInSrt2,
302
- harnessesUnsupportedInDocker2,
303
- compiled2,
304
- pinnedSrtCommand2,
305
- pinnedSrtStepCommand2,
306
- runSrtCli2,
307
- kitmanCacheDirectory2,
308
- srtSettings2,
309
- srtCacheEnvironment2,
310
- srtInheritedEnv2,
311
- inheritedEnvironment2,
312
- withOnlyEnvironment2,
313
- writeSrtSettings2,
314
- srtStepArgv2,
315
- srtArgv2
316
- } from "./chunk-sasjamqz.js";
330
+ } from "./chunk-1k6z8q79.js";
317
331
  import {
318
332
  writeAgentEnvironmentConfigFile2,
319
333
  readManifestSkillPaths2,
@@ -329,8 +343,8 @@ import {
329
343
  applyAgentEnvironmentMaterialization2,
330
344
  isPathWithin2,
331
345
  skillIdentity2
332
- } from "./chunk-vjkgbsry.js";
333
- import"./chunk-sbk4evb4.js";
346
+ } from "./chunk-dre4f6s4.js";
347
+ import"./chunk-hmctc4eq.js";
334
348
  import {
335
349
  egressAllowed,
336
350
  writeSecretRegistry,
@@ -340,7 +354,7 @@ import {
340
354
  secretFilter2,
341
355
  opaqueTunnelRefusal2,
342
356
  isOpaqueConnectReason2
343
- } from "./chunk-dhe1fwhw.js";
357
+ } from "./chunk-zkvrxna8.js";
344
358
  import {
345
359
  sliceBytes2,
346
360
  maxLineBytes2,
@@ -350,29 +364,29 @@ import {
350
364
  lookAtOpencode2,
351
365
  readOpencode2,
352
366
  databaseStamp2
353
- } from "./chunk-2bt9e1fj.js";
367
+ } from "./chunk-wh3pjr9r.js";
354
368
  import {
355
369
  uploadRunFile,
356
370
  programLease,
357
371
  rpcRunFiles,
358
372
  programHostsEnv,
359
373
  undeclaredHostsEnv
360
- } from "./chunk-re7cr0kk.js";
361
- import"./chunk-gqgbah9q.js";
374
+ } from "./chunk-dj873p0e.js";
375
+ import"./chunk-d0rx9esz.js";
362
376
  import {
363
377
  nextInt
364
- } from "./chunk-wre79w3z.js";
365
- import"./chunk-tpmyf5mk.js";
378
+ } from "./chunk-8a7337s1.js";
379
+ import"./chunk-k2re3tp5.js";
366
380
  import {
367
381
  ChildProcessSpawner,
368
382
  make3
369
- } from "./chunk-3gax0xq6.js";
370
- import"./chunk-c3ms91a6.js";
383
+ } from "./chunk-134jdvs6.js";
384
+ import"./chunk-wkg1v0kd.js";
371
385
  import {
372
386
  Id,
373
387
  secretReference,
374
388
  secretPlaceholder
375
- } from "./chunk-qndcafax.js";
389
+ } from "./chunk-9h16pekj.js";
376
390
 
377
391
  // packages/core/src/sync-kit.ts
378
392
  import { createHash } from "crypto";
@@ -644,6 +658,91 @@ var outputTailWithParallelFailures = (failures, output) => {
644
658
  `);
645
659
  };
646
660
 
661
+ // node_modules/.bun/effect@4.1.2/node_modules/effect/dist/FiberSet.js
662
+ var TypeId = "~effect/FiberSet";
663
+ var isFiberSet = (u) => hasProperty(u, TypeId);
664
+ var Proto = {
665
+ [TypeId]: TypeId,
666
+ [Symbol.iterator]() {
667
+ if (this.state._tag === "Closed") {
668
+ return empty2();
669
+ }
670
+ return this.state.backing[Symbol.iterator]();
671
+ },
672
+ ...PipeInspectableProto,
673
+ toJSON() {
674
+ return {
675
+ _id: "FiberSet",
676
+ state: this.state
677
+ };
678
+ }
679
+ };
680
+ var makeUnsafe = (backing, deferred) => {
681
+ const self = Object.create(Proto);
682
+ self.state = {
683
+ _tag: "Open",
684
+ backing
685
+ };
686
+ self.deferred = deferred;
687
+ return self;
688
+ };
689
+ var make = () => acquireRelease(sync2(() => makeUnsafe(new Set, makeUnsafe5())), (set) => suspend3(() => {
690
+ const state = set.state;
691
+ if (state._tag === "Closed")
692
+ return void_3;
693
+ set.state = {
694
+ _tag: "Closed"
695
+ };
696
+ const fibers = state.backing;
697
+ return interruptAll(fibers).pipe(into(set.deferred));
698
+ }));
699
+ var internalFiberId = -1;
700
+ var isInternalInterruption = /* @__PURE__ */ toPredicate(/* @__PURE__ */ compose(filterInterruptors, /* @__PURE__ */ has(internalFiberId)));
701
+ var addUnsafe = /* @__PURE__ */ dual((args) => isFiberSet(args[0]), (self, fiber, options) => {
702
+ if (self.state._tag === "Closed") {
703
+ fiber.interruptUnsafe(internalFiberId);
704
+ return;
705
+ } else if (self.state.backing.has(fiber)) {
706
+ return;
707
+ }
708
+ self.state.backing.add(fiber);
709
+ fiber.addObserver((exit) => {
710
+ if (self.state._tag === "Closed") {
711
+ return;
712
+ }
713
+ self.state.backing.delete(fiber);
714
+ if (isFailure2(exit) && (options?.propagateInterruption === true ? !isInternalInterruption(exit.cause) : !hasInterruptsOnly(exit.cause))) {
715
+ doneUnsafe(self.deferred, exit);
716
+ }
717
+ });
718
+ });
719
+ var constInterruptedFiber = /* @__PURE__ */ function() {
720
+ let fiber = undefined;
721
+ return () => {
722
+ if (fiber === undefined) {
723
+ fiber = runFork(interrupt3);
724
+ }
725
+ return fiber;
726
+ };
727
+ }();
728
+ var run2 = function() {
729
+ const self = arguments[0];
730
+ if (!isEffect(arguments[1])) {
731
+ const options = arguments[1];
732
+ return (effect) => runImpl(self, effect, options);
733
+ }
734
+ return runImpl(self, arguments[1], arguments[2]);
735
+ };
736
+ var runImpl = (self, effect, options) => withFiber2((parent) => {
737
+ if (self.state._tag === "Closed") {
738
+ return sync2(constInterruptedFiber);
739
+ }
740
+ const fiber = forkUnsafe(parent, effect, options?.startImmediately ?? true, true);
741
+ addUnsafe(self, fiber, options);
742
+ return succeed6(fiber);
743
+ });
744
+ var join2 = (self) => _await(self.deferred);
745
+
647
746
  // packages/agent-runtime/src/agent-environment.ts
648
747
  class AgentEnvironmentResolutionError extends TaggedError("AgentEnvironmentResolutionError") {
649
748
  get message() {
@@ -3220,10 +3319,10 @@ var stepKitSetup = (agent, harness) => gen(function* () {
3220
3319
  import { homedir as homedir2 } from "os";
3221
3320
 
3222
3321
  // node_modules/.bun/effect@4.1.2/node_modules/effect/dist/SubscriptionRef.js
3223
- var TypeId = "~effect/SubscriptionRef";
3224
- var Proto = {
3322
+ var TypeId2 = "~effect/SubscriptionRef";
3323
+ var Proto2 = {
3225
3324
  ...PipeInspectableProto,
3226
- [TypeId]: {
3325
+ [TypeId2]: {
3227
3326
  _A: identity
3228
3327
  },
3229
3328
  toJSON() {
@@ -3233,10 +3332,10 @@ var Proto = {
3233
3332
  };
3234
3333
  }
3235
3334
  };
3236
- var make = (value) => map9(unbounded({
3335
+ var make2 = (value) => map9(unbounded({
3237
3336
  replay: 1
3238
3337
  }), (pubsub) => {
3239
- const self = Object.create(Proto);
3338
+ const self = Object.create(Proto2);
3240
3339
  self.semaphore = makeUnsafe3(1);
3241
3340
  self.value = value;
3242
3341
  self.pubsub = pubsub;
@@ -4505,12 +4604,58 @@ var systemStepProcessesLayer = effect(StepProcesses, gen(function* () {
4505
4604
  }));
4506
4605
 
4507
4606
  // packages/agent-runtime/src/thread-budget.ts
4607
+ import { readFileSync } from "fs";
4508
4608
  import { availableParallelism } from "os";
4609
+ var cpuQuota = (cpuMax) => {
4610
+ const [max, period] = (cpuMax ?? "max").trim().split(/\s+/);
4611
+ const quota = Number(max) / Number(period);
4612
+ return Number.isFinite(quota) && quota > 0 ? quota : undefined;
4613
+ };
4614
+ var readText = (file) => {
4615
+ try {
4616
+ return readFileSync(file, "utf8");
4617
+ } catch {
4618
+ return;
4619
+ }
4620
+ };
4621
+ var readBytes = (file) => {
4622
+ try {
4623
+ return readFileSync(file, "latin1");
4624
+ } catch {
4625
+ return;
4626
+ }
4627
+ };
4628
+ var readAtBytePath = (file) => {
4629
+ try {
4630
+ return readFileSync(Buffer.from(file, "latin1"), "utf8");
4631
+ } catch {
4632
+ return;
4633
+ }
4634
+ };
4635
+ var lineAfter = (text, prefix) => text.split(`
4636
+ `).find((line) => line.startsWith(prefix))?.slice(prefix.length);
4637
+ var cpuListSize = (list) => list.trim().split(",").filter((range) => range !== "").reduce((size, range) => {
4638
+ const [first, last = first] = range.split("-").map(Number);
4639
+ return size + (last ?? 0) - (first ?? 0) + 1;
4640
+ }, 0);
4641
+ var affinityCores = (status = readText("/proc/self/status")) => {
4642
+ const list = status === undefined ? undefined : lineAfter(status, "Cpus_allowed_list:")?.trim();
4643
+ const size = list === undefined ? Number.NaN : cpuListSize(list);
4644
+ return Number.isInteger(size) && size > 0 ? size : availableParallelism();
4645
+ };
4646
+ var cgroupCpuQuota = (procCgroup, read) => {
4647
+ const path = procCgroup === undefined ? undefined : lineAfter(procCgroup, "0::/");
4648
+ const named = path === undefined ? [] : path.split("/").filter((part) => part !== "" && part !== ".");
4649
+ const parts = named.includes("..") ? [] : named;
4650
+ const quotas = parts.map((_, depth) => parts.slice(0, parts.length - depth).join("/")).concat("").map((dir) => cpuQuota(read(`/sys/fs/cgroup${dir === "" ? "" : `/${dir}`}/cpu.max`))).filter((quota) => quota !== undefined);
4651
+ return quotas.length === 0 ? undefined : Math.min(...quotas);
4652
+ };
4653
+ var effectiveCores = (affinity = affinityCores(), quota = cgroupCpuQuota(readBytes("/proc/self/cgroup"), readAtBytePath)) => quota === undefined ? affinity : Math.min(affinity, quota);
4509
4654
  var threadBudget = (cores, concurrency) => Math.max(2, Math.floor(cores / concurrency));
4510
- var hostThreadBudget = (concurrency) => threadBudget(availableParallelism(), concurrency);
4511
- var checkThreadBudget = (settings) => {
4512
- const cap = verificationCap(settings);
4513
- return cap < settings.concurrency ? hostThreadBudget(cap) : undefined;
4655
+ var runnerVerificationCap = (settings, cores = effectiveCores()) => verificationCap(settings, cores);
4656
+ var checkThreadBudget = (settings, cores = effectiveCores()) => {
4657
+ const cap = runnerVerificationCap(settings, cores);
4658
+ return cap < settings.concurrency ? threadBudget(cores, cap) : undefined;
4514
4659
  };
4515
4660
  var threadBudgetVariables = [
4516
4661
  "GOMAXPROCS",
@@ -5020,7 +5165,7 @@ var runAttempt = (request, options) => gen(function* () {
5020
5165
  return isTagged(terminal.failure, "HerdrCoreRpcError") ? failed("harness_launch_failed", `herdr-core refused to start the Harness: ${terminal.failure.message}`) : { status: "unreported", reason: "herdr_unavailable" };
5021
5166
  }
5022
5167
  const { address } = terminal.success;
5023
- const seen = yield* make({ status: null, turn: 0, end: undefined });
5168
+ const seen = yield* make2({ status: null, turn: 0, end: undefined });
5024
5169
  yield* forkScoped(follow(options.core, attempt.id, address, seen));
5025
5170
  const stop = gen(function* () {
5026
5171
  if ((yield* get2(seen)).end === "unreachable")
@@ -5848,9 +5993,9 @@ var needsNothing = (git, input) => gen(function* () {
5848
5993
  });
5849
5994
 
5850
5995
  // node_modules/.bun/effect@4.1.2/node_modules/effect/dist/internal/matcher.js
5851
- var TypeId2 = "~effect/Match/Matcher";
5996
+ var TypeId3 = "~effect/Match/Matcher";
5852
5997
  var TypeMatcherProto = {
5853
- [TypeId2]: {
5998
+ [TypeId3]: {
5854
5999
  _input: identity,
5855
6000
  _filters: identity,
5856
6001
  _remaining: identity,
@@ -5873,7 +6018,7 @@ function makeTypeMatcher(select, cases) {
5873
6018
  return matcher;
5874
6019
  }
5875
6020
  var ValueMatcherProto = {
5876
- [TypeId2]: {
6021
+ [TypeId3]: {
5877
6022
  _input: identity,
5878
6023
  _filters: identity,
5879
6024
  _result: identity,
@@ -6207,31 +6352,36 @@ function superviseReplica(input) {
6207
6352
  });
6208
6353
  const claimTurn = makeUnsafe3(1);
6209
6354
  let emptyAt = -1;
6210
- const wokenControl = (control, gate, signals) => ({
6211
- ...control,
6212
- claim: (idempotencyKey, options) => claimTurn.withPermit(gen(function* () {
6213
- const generation = yield* signals.generation;
6214
- if (generation <= emptyAt)
6215
- return {};
6216
- const { claimed, asked } = yield* claimThrough(control, gate, idempotencyKey, options);
6217
- if (claimed.workUnit === undefined && asked?.takesVerifications !== false)
6218
- emptyAt = Math.max(emptyAt, generation);
6219
- return claimed;
6220
- }))
6221
- });
6222
- const runSlot = (capacitySlot, index) => gen(function* () {
6355
+ const wokenControl = (control, gate, signals, demand) => {
6356
+ let lastAsked;
6357
+ return {
6358
+ ...control,
6359
+ claim: (idempotencyKey, options) => claimTurn.withPermit(gen(function* () {
6360
+ const generation = yield* signals.generation;
6361
+ const retry = lastAsked === idempotencyKey;
6362
+ lastAsked = idempotencyKey;
6363
+ if (!retry && generation <= emptyAt)
6364
+ return {};
6365
+ const { claimed, asked } = yield* claimThrough(control, gate, idempotencyKey, options);
6366
+ if (claimed.workUnit === undefined && asked?.takesVerifications !== false && (demand === undefined || (yield* demand.offeredNew)))
6367
+ emptyAt = Math.max(emptyAt, generation);
6368
+ return claimed;
6369
+ }))
6370
+ };
6371
+ };
6372
+ const runSlot = (capacitySlot, demand) => gen(function* () {
6223
6373
  let idleIterations = 0;
6224
- let woken = true;
6374
+ let woken = demand === undefined;
6225
6375
  while (true) {
6226
- if (input.concurrency !== undefined && index >= (yield* input.concurrency)) {
6227
- yield* sleep(ConcurrencyRecheck);
6228
- continue;
6229
- }
6376
+ if (demand !== undefined && (yield* demand.past))
6377
+ return;
6230
6378
  const seen = signals === undefined ? 0 : yield* signals.generation;
6231
- const control = input.control(capacitySlot);
6379
+ const control = demand === undefined ? input.control(capacitySlot) : demand.claiming(input.control(capacitySlot));
6232
6380
  const gate = input.verifications === undefined ? undefined : verificationGate(input.verifications);
6233
- const claiming = signals !== undefined && woken ? wokenControl(control, gate, signals) : gatedControl(control, gate);
6381
+ const claiming = signals !== undefined && woken ? wokenControl(control, gate, signals, demand) : gatedControl(control, gate);
6234
6382
  const exit2 = yield* exit(runReplica(claiming, input.executor, signals).pipe(ensuring2(gate?.free ?? void_3)));
6383
+ if (demand !== undefined)
6384
+ yield* demand.free;
6235
6385
  if (isSuccess2(exit2) && exit2.value.status === "completed") {
6236
6386
  idleIterations = 0;
6237
6387
  woken = false;
@@ -6242,6 +6392,8 @@ function superviseReplica(input) {
6242
6392
  woken = true;
6243
6393
  continue;
6244
6394
  }
6395
+ if (isSuccess2(exit2) && demand !== undefined && (yield* demand.spare))
6396
+ return;
6245
6397
  if (isSuccess2(exit2) && signals !== undefined) {
6246
6398
  woken = isSome(yield* signals.workSignalledAfter(seen).pipe(timeoutOption(IdleRecheck)));
6247
6399
  continue;
@@ -6255,10 +6407,17 @@ function superviseReplica(input) {
6255
6407
  yield* sleep(idleBackoff(idleIterations++));
6256
6408
  }
6257
6409
  });
6258
- const heartbeat = input.control(input.slots[0] ?? "slot-1").heartbeatReplica;
6410
+ const slotName = (index) => input.slots?.[index] ?? `slot-${index + 1}`;
6411
+ const heartbeat = input.control(slotName(0)).heartbeatReplica;
6412
+ let wakeAfterHeartbeat = false;
6413
+ const wake = signals === undefined ? void_3 : signals.push(WorkAvailable.make({}));
6259
6414
  const replicaHeartbeat = gen(function* () {
6260
6415
  while (true) {
6261
6416
  const exit2 = yield* exit(retryTransient(heartbeatCall(heartbeat)));
6417
+ if (isSuccess2(exit2) && wakeAfterHeartbeat) {
6418
+ wakeAfterHeartbeat = false;
6419
+ yield* wake;
6420
+ }
6262
6421
  if (isFailure2(exit2)) {
6263
6422
  const error = findErrorOption(exit2.cause);
6264
6423
  if (isSome(error) && error.value.kind === "unauthorized")
@@ -6268,7 +6427,88 @@ function superviseReplica(input) {
6268
6427
  yield* sleep(ReplicaHeartbeatInterval);
6269
6428
  }
6270
6429
  });
6271
- return all3([replicaHeartbeat, forEach(input.slots, runSlot, { concurrency: "unbounded", discard: true })], {
6430
+ const slots = input.concurrency === undefined ? forEach(input.slots, (slot) => runSlot(slot), { concurrency: "unbounded", discard: true }) : slotsOnDemand(input.concurrency);
6431
+ function slotsOnDemand(concurrency) {
6432
+ return scoped(gen(function* () {
6433
+ const fibers = yield* make();
6434
+ const started = new Set;
6435
+ let idle = 0;
6436
+ let busySlots = 0;
6437
+ let claimsInFlight = 0;
6438
+ let lastConcurrency = 0;
6439
+ const startSpare = gen(function* () {
6440
+ if (idle > 0 || started.size >= (yield* concurrency))
6441
+ return;
6442
+ let index = 0;
6443
+ while (started.has(index))
6444
+ index += 1;
6445
+ started.add(index);
6446
+ idle += 1;
6447
+ yield* run2(fibers, runSlot(slotName(index), slotDemand(index)).pipe(ensuring2(sync2(() => started.delete(index)))));
6448
+ });
6449
+ const slotDemand = (index) => {
6450
+ let busy = false;
6451
+ const claimed = suspend3(() => {
6452
+ if (busy)
6453
+ return void_3;
6454
+ busy = true;
6455
+ busySlots += 1;
6456
+ idle -= 1;
6457
+ return startSpare;
6458
+ });
6459
+ const stop = () => {
6460
+ idle -= 1;
6461
+ return true;
6462
+ };
6463
+ let lastAsked;
6464
+ let offeredNew = false;
6465
+ const claimWithin = (control, idempotencyKey, options) => gen(function* () {
6466
+ const full = busySlots + claimsInFlight >= (yield* concurrency);
6467
+ const retry = lastAsked === idempotencyKey;
6468
+ lastAsked = idempotencyKey;
6469
+ offeredNew = !full;
6470
+ if (full && !retry)
6471
+ return {};
6472
+ let reserved = !full;
6473
+ if (reserved)
6474
+ claimsInFlight += 1;
6475
+ const unreserve = sync2(() => {
6476
+ if (reserved)
6477
+ claimsInFlight -= 1;
6478
+ reserved = false;
6479
+ });
6480
+ return yield* control.claim(idempotencyKey, full ? { ...options, heldOnly: true } : options).pipe(tap2((result) => result.workUnit === undefined ? void_3 : andThen2(unreserve, claimed)), ensuring2(unreserve));
6481
+ });
6482
+ return {
6483
+ claiming: (control) => ({
6484
+ ...control,
6485
+ claim: (idempotencyKey, options) => claimWithin(control, idempotencyKey, options)
6486
+ }),
6487
+ free: sync2(() => {
6488
+ if (!busy)
6489
+ return;
6490
+ busy = false;
6491
+ busySlots -= 1;
6492
+ idle += 1;
6493
+ }),
6494
+ past: map9(concurrency, (limit) => (index >= limit || busySlots >= limit) && stop()),
6495
+ spare: sync2(() => idle > 1 && stop()),
6496
+ offeredNew: sync2(() => offeredNew)
6497
+ };
6498
+ };
6499
+ const wakeOnRise = flatMap3(concurrency, (now) => {
6500
+ const rose = lastConcurrency > 0 && now > lastConcurrency;
6501
+ lastConcurrency = now;
6502
+ if (!rose)
6503
+ return void_3;
6504
+ wakeAfterHeartbeat = true;
6505
+ return wake;
6506
+ });
6507
+ const keepSpare = forever(andThen2(wakeOnRise, andThen2(startSpare, sleep(ConcurrencyRecheck))));
6508
+ return yield* raceFirst(keepSpare, join2(fibers));
6509
+ }));
6510
+ }
6511
+ return all3([replicaHeartbeat, slots], {
6272
6512
  concurrency: "unbounded",
6273
6513
  discard: true
6274
6514
  }).pipe(andThen2(never));
@@ -8689,7 +8929,7 @@ var codexAppServer = (binary = "codex") => (env) => gen(function* () {
8689
8929
  return {
8690
8930
  request: (method, params) => gen(function* () {
8691
8931
  const id = ++lastId;
8692
- const deferred = yield* make15();
8932
+ const deferred = yield* make16();
8693
8933
  pending.set(id, deferred);
8694
8934
  yield* send({ id, method, params });
8695
8935
  return yield* _await(deferred).pipe(mapError2((error) => new CodexAppServerFailed({ reason: `${method}: ${error.message}` })));
@@ -8832,7 +9072,7 @@ var kitmanMcpPreflight = (mcp) => gen(function* () {
8832
9072
  const server = yield* spawner.spawn(make3(mcp.command, [...mcp.args], {
8833
9073
  extendEnv: true,
8834
9074
  env: mcp.env,
8835
- stdin: { stream: make10(new TextEncoder().encode(handshake)), endOnDone: false },
9075
+ stdin: { stream: make11(new TextEncoder().encode(handshake)), endOnDone: false },
8836
9076
  stderr: "ignore"
8837
9077
  }));
8838
9078
  const reply = yield* server.stdout.pipe(decodeText, splitLines, map2((line) => getOrUndefined(decodeJsonStringOption(line))), filter((message) => isJsonObject(message) && message.id === 2), runHead);
@@ -8906,7 +9146,7 @@ var programProcessExecutor = (input) => (work) => gen(function* () {
8906
9146
  const exitCode = sandbox === undefined ? yield* gen(function* () {
8907
9147
  const spawner = yield* ChildProcessSpawner;
8908
9148
  const handle = yield* spawner.spawn(make3(input.bun ?? process.execPath, [file], {
8909
- stdin: make10(new TextEncoder().encode(stdin)),
9149
+ stdin: make11(new TextEncoder().encode(stdin)),
8910
9150
  stdout: "inherit",
8911
9151
  stderr: "inherit",
8912
9152
  extendEnv: false,
@@ -10400,6 +10640,7 @@ export {
10400
10640
  SkillMaterializationRefused2 as SkillMaterializationRefused,
10401
10641
  StepAttemptLabel,
10402
10642
  StepProcesses,
10643
+ affinityCores,
10403
10644
  afterFreshService,
10404
10645
  afterMergeRunner,
10405
10646
  agentStepExecutionLimit,
@@ -10412,6 +10653,7 @@ export {
10412
10653
  attemptTempDirectory,
10413
10654
  carriedLoginHosts,
10414
10655
  carriedProviderHosts,
10656
+ cgroupCpuQuota,
10415
10657
  checkDockerAlias,
10416
10658
  checkDockerClientConfig,
10417
10659
  checkDockerDaemonArgs,
@@ -10432,6 +10674,8 @@ export {
10432
10674
  compiled2 as compiled,
10433
10675
  composeAgentEnvironmentSyncPlan,
10434
10676
  controlFailureKind,
10677
+ cpuListSize,
10678
+ cpuQuota,
10435
10679
  defaultAgentRuntimeUserConfigPath,
10436
10680
  detectHarnesses2 as detectHarnesses,
10437
10681
  diskSpaceFromDf,
@@ -10445,6 +10689,7 @@ export {
10445
10689
  dockerMissing,
10446
10690
  dockerRootDirectory,
10447
10691
  dockerStepContainers,
10692
+ effectiveCores,
10448
10693
  failed,
10449
10694
  failedWhenUnrun,
10450
10695
  firstMessage,
@@ -10468,7 +10713,6 @@ export {
10468
10713
  herdrRunnerCapabilitiesForRepoBinding2 as herdrRunnerCapabilitiesForRepoBinding,
10469
10714
  herdrSandboxBackends,
10470
10715
  homeDirectories,
10471
- hostThreadBudget,
10472
10716
  inheritedEnvironment2 as inheritedEnvironment,
10473
10717
  isPathWithin2 as isPathWithin,
10474
10718
  kitMcpHosts,
@@ -10503,6 +10747,8 @@ export {
10503
10747
  psProcessTable,
10504
10748
  publishedPort,
10505
10749
  pushWork,
10750
+ readAtBytePath,
10751
+ readBytes,
10506
10752
  readManifestSkillPaths2 as readManifestSkillPaths,
10507
10753
  redactedWith,
10508
10754
  redactingSecrets,
@@ -10529,6 +10775,7 @@ export {
10529
10775
  runSrtCli2 as runSrtCli,
10530
10776
  runnerStateSandboxPolicy,
10531
10777
  runnerStepAttemptFromAgentStep,
10778
+ runnerVerificationCap,
10532
10779
  runsOnHost,
10533
10780
  sampleMetrics,
10534
10781
  sandboxedLaunch,