@kitman-sh/cli 0.10.105 → 0.11.0-rc.4

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 (26) hide show
  1. package/dist/{chunk-cazap5by.js → chunk-0h5et1rg.js} +6 -6
  2. package/dist/{chunk-2cznmt28.js → chunk-2aj4ym2c.js} +7 -7
  3. package/dist/{chunk-5esfnamp.js → chunk-2sfgqfgq.js} +2 -2
  4. package/dist/{chunk-qcct8vjh.js → chunk-4ngdyd3k.js} +165 -49
  5. package/dist/{chunk-fe65rbvv.js → chunk-6zrq5xq2.js} +9 -9
  6. package/dist/{chunk-pme28eew.js → chunk-7d8prq0a.js} +4 -4
  7. package/dist/{chunk-kadsqvtm.js → chunk-9ew87kjc.js} +7 -212
  8. package/dist/{chunk-c7ym0ce7.js → chunk-anf9ddey.js} +2 -2
  9. package/dist/{chunk-xckn5gax.js → chunk-bj73db3f.js} +1 -1
  10. package/dist/{chunk-30mfra3r.js → chunk-bv9e34qz.js} +1 -1
  11. package/dist/{chunk-7z9m11z3.js → chunk-cbwmsy27.js} +487 -130
  12. package/dist/{chunk-tbrpndp2.js → chunk-cegdw7gw.js} +2 -2
  13. package/dist/{chunk-01fzz2j3.js → chunk-dc681k94.js} +4 -4
  14. package/dist/{chunk-044h6f3n.js → chunk-k2b10qys.js} +21 -19
  15. package/dist/{chunk-t80dhv1r.js → chunk-k6mfj25g.js} +3 -3
  16. package/dist/{chunk-s27r6x3a.js → chunk-kbhm8p3c.js} +5 -5
  17. package/dist/{chunk-0xjrc51m.js → chunk-nb36pw5d.js} +8 -8
  18. package/dist/{chunk-1hw35x4x.js → chunk-pqz98b85.js} +5 -5
  19. package/dist/{chunk-yjnrw9yb.js → chunk-rjdptgqf.js} +4 -4
  20. package/dist/{chunk-hv44tcjs.js → chunk-tx61h9d8.js} +6 -6
  21. package/dist/{chunk-che5w0y4.js → chunk-txyp31q5.js} +66 -60
  22. package/dist/{chunk-hxqxdy21.js → chunk-xmq9zpr1.js} +1 -1
  23. package/dist/{chunk-fzsbapgz.js → chunk-y0q2574w.js} +12 -12
  24. package/dist/{chunk-9nrr1dwr.js → chunk-znh6xbze.js} +28 -177
  25. package/dist/index.js +4 -4
  26. package/package.json +1 -1
@@ -12,7 +12,7 @@ import {
12
12
  add,
13
13
  getOrUndefinedUnsafe,
14
14
  getUnsafe,
15
- get4,
15
+ get3,
16
16
  Reference,
17
17
  toMillis,
18
18
  isSuccess,
@@ -96,7 +96,7 @@ import {
96
96
  Defect,
97
97
  Exit,
98
98
  toCodecJson
99
- } from "./chunk-che5w0y4.js";
99
+ } from "./chunk-txyp31q5.js";
100
100
  import {
101
101
  interrupt,
102
102
  getCurrent,
@@ -108,7 +108,7 @@ import {
108
108
  shutdownUnsafe,
109
109
  fromQueue,
110
110
  unwrap
111
- } from "./chunk-9nrr1dwr.js";
111
+ } from "./chunk-znh6xbze.js";
112
112
  import {
113
113
  Clock,
114
114
  empty,
@@ -123,7 +123,7 @@ import {
123
123
  ParseOptions,
124
124
  RpcClientDefect,
125
125
  RpcClientError
126
- } from "./chunk-7z9m11z3.js";
126
+ } from "./chunk-cbwmsy27.js";
127
127
 
128
128
  // node_modules/.bun/effect@4.1.2/node_modules/effect/dist/workers/Transferable.js
129
129
  class Collector extends (/* @__PURE__ */ Service2()("effect/workers/Transferable/Collector")) {
@@ -237,7 +237,7 @@ var makeNoSerialization = /* @__PURE__ */ fnUntraced(function* (group, options)
237
237
  const disableTracing = options?.disableTracing ?? false;
238
238
  const generateRequestId = options?.generateRequestId ?? (() => requestIdCounter++);
239
239
  const services = yield* context();
240
- const scope = get4(services, Scope);
240
+ const scope = get3(services, Scope);
241
241
  const entries = new Map;
242
242
  let isShutdown = false;
243
243
  yield* addFinalizer(scope, withFiber2((parent) => {
@@ -643,7 +643,7 @@ var makeRpcSchemas = (codecFor) => {
643
643
  return entry;
644
644
  }
645
645
  const streamSchemas = getStreamSchemas(rpc.successSchema);
646
- const parseOptions = get4(rpc.annotations, ParseOptions);
646
+ const parseOptions = get3(rpc.annotations, ParseOptions);
647
647
  const exitSchema2 = exitSchema(rpc);
648
648
  let decodeDiscardExit;
649
649
  entry = {
@@ -4,13 +4,13 @@ import {
4
4
  runnerRpcUrl2,
5
5
  makeRunnerRpcClient2,
6
6
  makeProgramRpcClient2
7
- } from "./chunk-pme28eew.js";
8
- import"./chunk-cazap5by.js";
9
- import"./chunk-7z9m11z3.js";
10
- import"./chunk-30mfra3r.js";
11
- import"./chunk-hxqxdy21.js";
12
- import"./chunk-9nrr1dwr.js";
13
- import"./chunk-che5w0y4.js";
7
+ } from "./chunk-7d8prq0a.js";
8
+ import"./chunk-0h5et1rg.js";
9
+ import"./chunk-cbwmsy27.js";
10
+ import"./chunk-bv9e34qz.js";
11
+ import"./chunk-xmq9zpr1.js";
12
+ import"./chunk-znh6xbze.js";
13
+ import"./chunk-txyp31q5.js";
14
14
  export {
15
15
  makeProgramRpcClient2 as makeProgramRpcClient,
16
16
  makeRunnerRpcClient2 as makeRunnerRpcClient,
@@ -22,7 +22,7 @@ import {
22
22
  map8,
23
23
  raceFirst,
24
24
  scoped
25
- } from "./chunk-che5w0y4.js";
25
+ } from "./chunk-txyp31q5.js";
26
26
  import {
27
27
  unwrap,
28
28
  drainFork,
@@ -31,7 +31,7 @@ import {
31
31
  runCollect,
32
32
  runDrain,
33
33
  mkString
34
- } from "./chunk-9nrr1dwr.js";
34
+ } from "./chunk-znh6xbze.js";
35
35
 
36
36
  // node_modules/.bun/effect@4.1.2/node_modules/effect/dist/internal/redacted.js
37
37
  var redactedRegistry = /* @__PURE__ */ new WeakMap;
@@ -1,12 +1,18 @@
1
1
  // @bun
2
2
  import {
3
3
  isTagged,
4
+ none,
4
5
  isSome,
5
6
  getOrElse,
6
7
  getOrUndefined,
7
8
  Reference,
9
+ minutes,
10
+ toMillis,
11
+ toMinutes,
12
+ succeed,
13
+ isSuccess,
8
14
  TaggedError,
9
- make16,
15
+ make15,
10
16
  _await,
11
17
  fail5,
12
18
  succeed5,
@@ -35,8 +41,10 @@ import {
35
41
  flatMap3,
36
42
  andThen2,
37
43
  tap2,
44
+ result,
38
45
  map8,
39
46
  as,
47
+ asSome2,
40
48
  asVoid,
41
49
  catch_,
42
50
  catchTag,
@@ -87,7 +95,7 @@ import {
87
95
  decodeJsonString,
88
96
  encodeJsonStringSync,
89
97
  encodePrettyJsonString
90
- } from "./chunk-che5w0y4.js";
98
+ } from "./chunk-txyp31q5.js";
91
99
  import {
92
100
  tap,
93
101
  mapError,
@@ -99,7 +107,7 @@ import {
99
107
  withDefault,
100
108
  option,
101
109
  String2
102
- } from "./chunk-9nrr1dwr.js";
110
+ } from "./chunk-znh6xbze.js";
103
111
  import {
104
112
  currentTimeMillis,
105
113
  SecureRandom,
@@ -207,10 +215,10 @@ import {
207
215
  harnessNames,
208
216
  herdrRunnerCapabilities2,
209
217
  declaredChecks
210
- } from "./chunk-7z9m11z3.js";
218
+ } from "./chunk-cbwmsy27.js";
211
219
  import {
212
220
  Id
213
- } from "./chunk-30mfra3r.js";
221
+ } from "./chunk-bv9e34qz.js";
214
222
  import {
215
223
  toJsonValue,
216
224
  isOneOf,
@@ -220,11 +228,11 @@ import {
220
228
  isObject,
221
229
  isJsonObject,
222
230
  isString
223
- } from "./chunk-hxqxdy21.js";
231
+ } from "./chunk-xmq9zpr1.js";
224
232
  import {
225
233
  ChildProcessSpawner,
226
234
  make3
227
- } from "./chunk-5esfnamp.js";
235
+ } from "./chunk-2sfgqfgq.js";
228
236
 
229
237
  // apps/cli/src/cli-error.ts
230
238
  function cliErrorCode(error, status) {
@@ -479,6 +487,18 @@ var kitmanVersion = undefined;
479
487
  // apps/cli/src/runner-startup.ts
480
488
  class RunnerStopped extends TaggedError("RunnerStopped") {
481
489
  }
490
+
491
+ class ClientProtocolOutdated extends TaggedError("ClientProtocolOutdated") {
492
+ get message() {
493
+ return "Kitman refuses this Runner's client protocol";
494
+ }
495
+ }
496
+ var refusedForClientProtocol = (error) => (error instanceof KitmanClientError || is(RunnerRpcError)(error)) && error.status === 426;
497
+ var updateRequired = {
498
+ code: "update_required",
499
+ message: "Kitman refuses this Runner's calls: it speaks another client protocol than Kitman, and cannot update itself here.",
500
+ fix: "Run it from an image with the kitman release your Kitman serves, then start it again."
501
+ };
482
502
  var pairFix = "Run `kitman pair` on this machine. Not signed in there? Mint a Pairing Code on the Runners page and run the command it shows.";
483
503
  var credentialMissing = (runnerId) => ({
484
504
  code: "credential_missing",
@@ -507,10 +527,10 @@ var sandboxMissing = (sandbox, missing) => ({
507
527
  var personalCheckBackend = (agentSandbox, dockerAvailable) => agentSandbox === "srt" || agentSandbox === "docker" && dockerAvailable ? agentSandbox : undefined;
508
528
  var herdrCoreSession = (runnerId, personal) => personal ? undefined : `kitman-${sha2562(runnerId).slice(0, 16)}`;
509
529
  var OpenHerdrCore = Reference("kitman/cli/OpenHerdrCore", {
510
- defaultValue: () => (options) => flatMap3(promise(() => import("./chunk-01fzz2j3.js")), ({ HerdrCore, herdrCoreLayer }) => provide3(service(HerdrCore), herdrCoreLayer(options)))
530
+ defaultValue: () => (options) => flatMap3(promise(() => import("./chunk-dc681k94.js")), ({ HerdrCore, herdrCoreLayer }) => provide3(service(HerdrCore), herdrCoreLayer(options)))
511
531
  });
512
532
  var UpdateHerdrCore = Reference("kitman/cli/UpdateHerdrCore", {
513
- defaultValue: () => (options) => flatMap3(promise(() => import("./chunk-01fzz2j3.js")), (module) => module.updateHerdrCore(options))
533
+ defaultValue: () => (options) => flatMap3(promise(() => import("./chunk-dc681k94.js")), (module) => module.updateHerdrCore(options))
514
534
  });
515
535
  var herdrCoreMissing = (error) => {
516
536
  if (isTagged(error, "HerdrCoreMissing"))
@@ -540,6 +560,8 @@ var herdrCoreUpdateFailed = (error, runnerId) => ({
540
560
  var stopOnRefusal = (call) => mapError2(call, (error) => {
541
561
  if (!(error instanceof KitmanClientError) && !is(RunnerRpcError)(error))
542
562
  return error;
563
+ if (error.status === 426)
564
+ return new ClientProtocolOutdated;
543
565
  if (error.status === 401 || error.status === 403)
544
566
  return new RunnerStopped({ problem: credentialRefused });
545
567
  return error.status === 404 ? new RunnerStopped({ problem: runnerRemoved }) : error;
@@ -553,7 +575,7 @@ var refused = (error) => error instanceof RunnerStopped && error.problem.code ==
553
575
  class StepTimedOut extends TaggedError("StepTimedOut") {
554
576
  }
555
577
  var startupStep = (step, bound, attempt) => attempt.pipe(timeoutOrElse({ duration: bound, orElse: () => fail7(new StepTimedOut) }), tapError2((error2) => unreachable(error2) ? error(`Runner start: ${step} failed, trying again: ${error2.message}`) : void_3), retry({ schedule: backoff, while: unreachable }), tapError2((error2) => refused(error2) ? error(`Runner start: Kitman refused this Runner's credential at ${step}, trying again`) : void_3), retry({ schedule: refusalRetries, while: refused }), mapError2((error) => {
556
- if (error instanceof RunnerStopped)
578
+ if (error instanceof RunnerStopped || error instanceof ClientProtocolOutdated)
557
579
  return error;
558
580
  if (error instanceof StepTimedOut)
559
581
  return new CliError({ message: `Runner start: ${step} did not finish within ${bound}` });
@@ -712,20 +734,27 @@ var runningManagedInstall = (platform) => gen(function* () {
712
734
  const executable = yield* fs.realPath(process.execPath).pipe(orElseSucceed(() => process.execPath));
713
735
  return executable.startsWith(`${versions}/`);
714
736
  });
715
- var downloadManagedKitman = (apiUrl, platform) => gen(function* () {
716
- const fs = yield* FileSystem;
717
- const path = yield* Path;
737
+ var fetchFrom = (url) => gen(function* () {
718
738
  const fetch = yield* Fetch;
719
- const get = (url) => tryPromise({
739
+ return yield* tryPromise({
720
740
  try: () => fetch(url),
721
741
  catch: (error) => new CliError({ message: `Fetching ${url} failed: ${String(error)}` })
722
742
  });
723
- const answer = yield* get(new URL("/v1/runner-release", apiUrl).toString());
743
+ });
744
+ var servedKitmanRelease = (apiUrl) => gen(function* () {
745
+ const answer = yield* fetchFrom(new URL("/v1/runner-release", apiUrl).toString());
724
746
  if (answer.status === 404)
725
747
  return;
726
748
  if (!answer.ok)
727
749
  return yield* new CliError({ message: `${apiUrl} answered ${answer.status} for its kitman release` });
728
- const manifest = yield* tryPromise(() => answer.json()).pipe(flatMap3(decodeUnknownEffect2(RunnerReleaseManifest)), mapError2(() => new CliError({ message: `${apiUrl} served a kitman release this kitman cannot read` })));
750
+ return yield* tryPromise(() => answer.json()).pipe(flatMap3(decodeUnknownEffect2(RunnerReleaseManifest)), mapError2(() => new CliError({ message: `${apiUrl} served a kitman release this kitman cannot read` })));
751
+ });
752
+ var downloadManagedKitman = (apiUrl, platform) => gen(function* () {
753
+ const fs = yield* FileSystem;
754
+ const path = yield* Path;
755
+ const manifest = yield* servedKitmanRelease(apiUrl);
756
+ if (manifest === undefined)
757
+ return;
729
758
  const os = platform === "darwin" ? "darwin" : "linux";
730
759
  const architecture = process.arch === "x64" ? "amd64" : process.arch;
731
760
  const release = manifest.platforms.find((entry) => entry.os === os && entry.architecture === architecture && entry.sha256 !== "");
@@ -735,7 +764,7 @@ var downloadManagedKitman = (apiUrl, platform) => gen(function* () {
735
764
  const kitman = path.join(versions, manifest.version, "kitman");
736
765
  const installed = !(yield* fs.exists(kitman));
737
766
  if (installed) {
738
- const binary = yield* get(release.url).pipe(filterOrFail((downloaded) => downloaded.ok, (downloaded) => new CliError({ message: `Downloading kitman ${manifest.version} answered ${downloaded.status}` })), flatMap3((downloaded) => tryPromise({
767
+ const binary = yield* fetchFrom(release.url).pipe(filterOrFail((downloaded) => downloaded.ok, (downloaded) => new CliError({ message: `Downloading kitman ${manifest.version} answered ${downloaded.status}` })), flatMap3((downloaded) => tryPromise({
739
768
  try: () => downloaded.arrayBuffer(),
740
769
  catch: (error) => new CliError({ message: `Downloading kitman ${manifest.version} failed: ${String(error)}` })
741
770
  })), map8((bytes) => new Uint8Array(bytes)));
@@ -779,24 +808,39 @@ class UpdateStepFailed extends TaggedError("UpdateStepFailed") {
779
808
  }
780
809
  var step = (name) => (effect) => mapError2(effect, (error) => new UpdateStepFailed({ step: name, reason: error.message }));
781
810
  var DrainLimit = "30 minutes";
811
+ var RequiredRetryAfter = minutes(10);
812
+ var releaseNumbers = (version) => /^v?(\d+)\.(\d+)\.(\d+)/u.exec(version)?.slice(1).map(Number);
813
+ var newerThan = (candidate, running) => {
814
+ const [a, b] = [releaseNumbers(candidate), releaseNumbers(running)];
815
+ if (a === undefined || b === undefined)
816
+ return true;
817
+ const differing = a.findIndex((part, index) => part !== b[index]);
818
+ return differing !== -1 && (a[differing] ?? 0) > (b[differing] ?? 0);
819
+ };
782
820
  var runnerUpdater = (input) => {
783
821
  let claiming = true;
784
822
  let updating = false;
785
823
  let problems = [];
786
824
  const failed = new Set;
787
- const attempt = gen(function* () {
825
+ let requiredFailedAt;
826
+ const drain = (onLimit) => suspend3(() => {
827
+ claiming = false;
828
+ return gen(function* () {
829
+ while ((yield* input.inFlight) > 0)
830
+ yield* sleep("1 second");
831
+ }).pipe(timeoutOrElse({ duration: DrainLimit, orElse: () => onLimit }));
832
+ });
833
+ const attempt = (required) => gen(function* () {
788
834
  const downloaded = yield* downloadManagedKitman(input.apiUrl, input.platform).pipe(filterOrFail((found) => found !== undefined, () => new UpdateStepFailed({ step: "download", reason: `${input.apiUrl} serves no kitman` })), step("download"));
835
+ if (required && input.version !== undefined && !newerThan(downloaded.version, input.version))
836
+ return yield* new UpdateStepFailed({
837
+ step: "download",
838
+ reason: `${input.apiUrl} serves kitman ${downloaded.version}, not newer than this Runner's ${input.version}`
839
+ });
789
840
  const reported = (yield* runCommand2(downloaded.kitman, ["--version"], { timeout: "30 seconds" }).pipe(step("start"))).trim();
790
841
  if (reported !== downloaded.version)
791
842
  return yield* new UpdateStepFailed({ step: "start", reason: `it reported version ${reported || "none"}` });
792
- claiming = false;
793
- yield* gen(function* () {
794
- while ((yield* input.inFlight) > 0)
795
- yield* sleep("1 second");
796
- }).pipe(timeoutOrElse({
797
- duration: DrainLimit,
798
- orElse: () => fail7(new UpdateStepFailed({ step: "drain", reason: "its work in flight did not finish in 30 minutes" }))
799
- }));
843
+ yield* drain(required ? void_3 : fail7(new UpdateStepFailed({ step: "drain", reason: "its work in flight did not finish in 30 minutes" })));
800
844
  yield* linkManagedKitman(downloaded.kitman).pipe(step("switch"));
801
845
  return yield* new RunnerUpdated({ version: downloaded.version });
802
846
  });
@@ -804,7 +848,7 @@ var runnerUpdater = (input) => {
804
848
  if (updating || failed.has(version))
805
849
  return void_3;
806
850
  updating = true;
807
- return attempt.pipe(catchTag("UpdateStepFailed", ({ step: failedStep, reason }) => sync2(() => {
851
+ return attempt(false).pipe(catchTag("UpdateStepFailed", ({ step: failedStep, reason }) => sync2(() => {
808
852
  failed.add(version);
809
853
  claiming = true;
810
854
  problems = [
@@ -816,10 +860,37 @@ var runnerUpdater = (input) => {
816
860
  ];
817
861
  })), ensuring2(sync2(() => updating = false)));
818
862
  });
863
+ const updateRequired = gen(function* () {
864
+ const now = yield* currentTimeMillis;
865
+ if (updating || requiredFailedAt !== undefined && now - requiredFailedAt < toMillis(RequiredRetryAfter))
866
+ return;
867
+ updating = true;
868
+ return yield* attempt(true).pipe(catchTag("UpdateStepFailed", ({ step: failedStep, reason }) => gen(function* () {
869
+ requiredFailedAt = yield* currentTimeMillis;
870
+ claiming = true;
871
+ yield* error(`Kitman refuses this Runner's client protocol, and updating kitman failed at the ${failedStep} step: ${reason}. Trying again in ${toMinutes(RequiredRetryAfter)} minutes.`);
872
+ })), ensuring2(sync2(() => updating = false)));
873
+ });
874
+ const servesNewer = (served) => input.version === undefined || served === undefined || newerThan(served.version, input.version);
875
+ const stopWhenDrained = (stop) => gen(function* () {
876
+ const now = yield* currentTimeMillis;
877
+ if (updating || requiredFailedAt !== undefined && now - requiredFailedAt < toMillis(RequiredRetryAfter))
878
+ return;
879
+ updating = true;
880
+ const served = input.version === undefined ? succeed(undefined) : yield* result(servedKitmanRelease(input.apiUrl));
881
+ if (isSuccess(served) && servesNewer(served.success))
882
+ return yield* andThen2(drain(void_3), fail7(stop));
883
+ requiredFailedAt = now;
884
+ updating = false;
885
+ const reason = isSuccess(served) ? `serves kitman ${served.success?.version}, not newer than this Runner's ${input.version}` : `its release could not be read: ${served.failure.message}`;
886
+ yield* error(`Kitman refuses this Runner's client protocol, but ${reason}. Checking again in ${toMinutes(RequiredRetryAfter)} minutes.`);
887
+ });
819
888
  return {
820
889
  claiming: () => claiming,
821
890
  problems: () => problems,
822
- update
891
+ update,
892
+ updateRequired,
893
+ stopWhenDrained
823
894
  };
824
895
  };
825
896
 
@@ -861,7 +932,7 @@ var syncTargets = (harness) => gen(function* () {
861
932
  });
862
933
  var syncKits = (input) => gen(function* () {
863
934
  const fs = yield* FileSystem;
864
- const { syncKitSetup } = yield* promise(() => import("./chunk-0xjrc51m.js"));
935
+ const { syncKitSetup } = yield* promise(() => import("./chunk-nb36pw5d.js"));
865
936
  const harnesses = yield* syncTargets(input.harness);
866
937
  const chain = yield* input.client.getKitChain(input.workspaceId);
867
938
  for (const { name, problem } of chain.skipped)
@@ -1779,7 +1850,7 @@ var package_default = {
1779
1850
  };
1780
1851
 
1781
1852
  // apps/cli/src/scaffold.ts
1782
- var cliVersion = "0.10.105";
1853
+ var cliVersion = "0.11.0-rc.4";
1783
1854
  var packageJson = (name, scaffold) => `${JSON.stringify({
1784
1855
  name,
1785
1856
  private: true,
@@ -2039,7 +2110,7 @@ var Usage = [
2039
2110
  "Every run, loop, agent, verify, constraint, secret, claim, deploy, dev and kit command takes --json."
2040
2111
  ].join(`
2041
2112
  `);
2042
- var agentRuntime = promise(() => import("./chunk-044h6f3n.js"));
2113
+ var agentRuntime = promise(() => import("./chunk-k2b10qys.js"));
2043
2114
  var TuiLauncher = Reference("kitman/cli/TuiLauncher", {
2044
2115
  defaultValue: () => gen(function* () {
2045
2116
  const tui = yield* tryPromise({
@@ -2990,7 +3061,7 @@ var SandboxHostProbe = Reference("kitman/cli/SandboxHostProbe", {
2990
3061
  });
2991
3062
  var OpenRunnerRpc = Reference("kitman/cli/OpenRunnerRpc", {
2992
3063
  defaultValue: () => (options) => gen(function* () {
2993
- const { makeRunnerRpcClient, runnerRpcUrl, runnerWebSocketProtocol } = yield* promise(() => import("./chunk-2cznmt28.js"));
3064
+ const { makeRunnerRpcClient, runnerRpcUrl, runnerWebSocketProtocol } = yield* promise(() => import("./chunk-2aj4ym2c.js"));
2994
3065
  return yield* makeRunnerRpcClient({
2995
3066
  runnerId: options.runnerId,
2996
3067
  bearer: options.bearer,
@@ -3023,8 +3094,42 @@ var herdrRunnerRootDir = gen(function* () {
3023
3094
  return yield* new CliError({ message: "herdr_runner_root_unavailable" });
3024
3095
  return path.join(home, ".kitman-herdr-runner");
3025
3096
  });
3097
+ var ContainerMarkers = Reference("kitman/cli/ContainerMarkers", {
3098
+ defaultValue: () => ["/.dockerenv", "/run/.containerenv"]
3099
+ });
3100
+ var runsInContainer = (credentialGiven) => gen(function* () {
3101
+ const fs = yield* FileSystem;
3102
+ if (credentialGiven)
3103
+ return true;
3104
+ for (const marker of yield* ContainerMarkers)
3105
+ if (yield* fs.exists(marker).pipe(orElseSucceed(() => false)))
3106
+ return true;
3107
+ return false;
3108
+ });
3109
+ var restartOntoUpdate = (runnerId) => gen(function* () {
3110
+ const invocation = yield* option(String2("INVOCATION_ID"));
3111
+ if (process.platform === "linux" && isSome(invocation))
3112
+ yield* ignore(restartRunnerService(runnerServiceName(runnerId)));
3113
+ });
3114
+ var updateRefusedRunner = (input) => gen(function* () {
3115
+ const version = yield* RunningKitmanVersion;
3116
+ const updater = runnerUpdater({
3117
+ apiUrl: input.apiUrl,
3118
+ runnerId: input.runnerId,
3119
+ platform: process.platform,
3120
+ inFlight: succeed6(0),
3121
+ ...version === undefined ? undefined : { version }
3122
+ });
3123
+ if (input.container)
3124
+ yield* updater.stopWhenDrained(new RunnerStopped({ problem: updateRequired }));
3125
+ else {
3126
+ yield* error("Kitman refuses this Runner's client protocol: updating kitman to the release it serves");
3127
+ yield* updater.updateRequired.pipe(tapError2(() => restartOntoUpdate(input.runnerId)));
3128
+ }
3129
+ yield* sleep(RequiredRetryAfter);
3130
+ });
3026
3131
  function startCanonicalHerdrRunnerCommand(input) {
3027
- return gen(function* () {
3132
+ const startOnce = gen(function* () {
3028
3133
  const {
3029
3134
  AgentBackend,
3030
3135
  agentStepExecutor,
@@ -3070,7 +3175,7 @@ function startCanonicalHerdrRunnerCommand(input) {
3070
3175
  const hostSettings = yield* runnerHostSettings;
3071
3176
  const { fullAccess, sshAgentAvailable } = hostSettings;
3072
3177
  const fs = yield* FileSystem;
3073
- const container = input.credential !== undefined || (yield* fs.exists("/.dockerenv").pipe(orElseSucceed(() => false))) || (yield* fs.exists("/run/.containerenv").pipe(orElseSucceed(() => false)));
3178
+ const container = yield* runsInContainer(input.credential !== undefined);
3074
3179
  const version = yield* RunningKitmanVersion;
3075
3180
  const reported = { ...version === undefined ? undefined : { version }, container };
3076
3181
  const credential = input.credential ?? (yield* startupStep("load the Runner credential", "10 seconds", storedHerdrRunnerCredential(input.apiUrl, input.runnerId)));
@@ -3122,7 +3227,7 @@ function startCanonicalHerdrRunnerCommand(input) {
3122
3227
  if (unready !== undefined)
3123
3228
  return yield* stopOn(unready);
3124
3229
  const teamId = input.teamId;
3125
- const repoBinding = teamId === undefined ? undefined : (yield* startupStep("read the repo binding", "30 seconds", controlPlane.client.listRepoBindings(runner.workspaceId))).items.find((binding) => binding.status === "active" && binding.teamId === teamId);
3230
+ const repoBinding = teamId === undefined ? undefined : (yield* startupStep("read the repo binding", "30 seconds", stopOnRefusal(controlPlane.client.listRepoBindings(runner.workspaceId)))).items.find((binding) => binding.status === "active" && binding.teamId === teamId);
3126
3231
  const path = yield* Path;
3127
3232
  const runnerRootDir = yield* herdrRunnerRootDir;
3128
3233
  yield* fs.makeDirectory(path.join(runnerRootDir, ".kitman", "worktrees"), { recursive: true });
@@ -3143,10 +3248,14 @@ function startCanonicalHerdrRunnerCommand(input) {
3143
3248
  const inSrt = sandbox === "srt" ? yield* startupStep("start each Harness in srt", "120 seconds", harnessesInSrt({ detection: detected, runner: runnerState })) : undefined;
3144
3249
  const live = { settings, sandbox, sandboxProblem: chosen.problem, inSrt };
3145
3250
  const srtBinaries = { ...inSrt?.binaries };
3251
+ let reached = [];
3252
+ const repositoryProbeInterval = "5 minutes";
3253
+ const repositoryRetryInterval = "30 seconds";
3146
3254
  const capabilitiesNow = () => {
3147
3255
  const harnesses = live.sandbox === "srt" && live.inSrt !== undefined ? live.inSrt.detection : detected;
3148
3256
  const profile = {
3149
3257
  harnesses,
3258
+ reached,
3150
3259
  fullAccess,
3151
3260
  sandbox: host,
3152
3261
  shared: !personal,
@@ -3200,7 +3309,8 @@ function startCanonicalHerdrRunnerCommand(input) {
3200
3309
  apiUrl: input.apiUrl,
3201
3310
  runnerId: input.runnerId,
3202
3311
  platform: process.platform,
3203
- inFlight: sync2(() => activeSlots.size + claimsInFlight)
3312
+ inFlight: sync2(() => activeSlots.size + claimsInFlight),
3313
+ ...version === undefined ? undefined : { version }
3204
3314
  });
3205
3315
  return yield* gen(function* () {
3206
3316
  const agentBackend = yield* AgentBackend;
@@ -3229,21 +3339,20 @@ function startCanonicalHerdrRunnerCommand(input) {
3229
3339
  cacheDir: bundleCache
3230
3340
  });
3231
3341
  const checkouts = runCheckouts(path.join(runnerRootDir, ".kitman"), rpc.gitCredential);
3342
+ yield* controlPlane.client.listRepoBindings(runner.workspaceId).pipe(flatMap3(({ items }) => forEach(items.filter((binding) => binding.status === "active" && (teamId === undefined || binding.teamId === teamId)), (repoBinding) => map8(checkouts.reaches(repoBinding), (reachable) => ({ repoBinding, reachable })), { concurrency: 4 })), tap2((probed) => sync2(() => reached = probed)), catch_((error) => logWarning("runner_repository_probe_failed", error.message)), flatMap3(() => sleep(reached.some((probe) => !probe.reachable) ? repositoryRetryInterval : repositoryProbeInterval)), forever, forkScoped);
3232
3343
  const platform = yield* context();
3233
- const updated = yield* make16();
3344
+ const updated = yield* make15();
3234
3345
  const scope = yield* scope2;
3346
+ const startUpdate = (update) => update.pipe(catch_((error) => andThen2(restartOntoUpdate(input.runnerId), fail5(updated, error))), provideContext2(platform), forkIn(scope), asVoid);
3347
+ const refusedForProtocol = container ? updater.stopWhenDrained(new RunnerStopped({ problem: updateRequired })).pipe(catch_((stopped) => fail5(updated, stopped)), forkIn(scope), asVoid) : startUpdate(updater.updateRequired);
3348
+ const onProtocolRefusal = (error) => refusedForClientProtocol(error) ? refusedForProtocol : void_3;
3235
3349
  yield* listenForSignals({
3236
3350
  rpc,
3237
3351
  runnerReplicaId: replica.id,
3238
3352
  signals,
3239
3353
  checkouts,
3240
3354
  reconnectAfter: "2 seconds",
3241
- update: (version) => container ? void_3 : updater.update(version).pipe(catch_((error) => gen(function* () {
3242
- const invocation = yield* option(String2("INVOCATION_ID"));
3243
- if (process.platform === "linux" && isSome(invocation))
3244
- yield* ignore(restartRunnerService(runnerServiceName(input.runnerId)));
3245
- return yield* fail5(updated, error);
3246
- })), provideContext2(platform), forkIn(scope), asVoid)
3355
+ update: (version) => container ? void_3 : startUpdate(updater.update(version))
3247
3356
  }).pipe(forkScoped);
3248
3357
  const sharedSandbox = personal ? undefined : {
3249
3358
  runner: runnerState,
@@ -3395,7 +3504,7 @@ function startCanonicalHerdrRunnerCommand(input) {
3395
3504
  }).pipe(tap2((result) => sync2(() => {
3396
3505
  if (result.workUnit !== undefined)
3397
3506
  activeSlots.add(capacitySlot);
3398
- })), ensuring2(sync2(() => claimsInFlight -= 1)));
3507
+ })), ensuring2(sync2(() => claimsInFlight -= 1)), tapError2(onProtocolRefusal));
3399
3508
  }),
3400
3509
  finished: () => sync2(() => activeSlots.delete(capacitySlot)),
3401
3510
  heartbeatReplica: () => flatMap3(stepProcesses.problems, (unreaped) => controlPlane.client.heartbeatRunner(input.runnerId, {
@@ -3409,7 +3518,7 @@ function startCanonicalHerdrRunnerCommand(input) {
3409
3518
  drainState: updater.claiming() ? "accepting" : "draining",
3410
3519
  capacity: { maxConcurrentRuns: live.settings.concurrency },
3411
3520
  telemetry: { activeWorkUnits: activeSlots.size }
3412
- }).pipe(asVoid))),
3521
+ }).pipe(asVoid)), tapError2(onProtocolRefusal)),
3413
3522
  heartbeatWork: (workUnitId, lease) => rpc.heartbeat({ workUnitId, lease }),
3414
3523
  complete: (completion) => rpc.complete(completion),
3415
3524
  release: (workUnitId, lease, crashed) => rpc.release({
@@ -3443,7 +3552,14 @@ function startCanonicalHerdrRunnerCommand(input) {
3443
3552
  return yield* raceFirst(stopWhenRefused(supervised), _await(updated));
3444
3553
  }));
3445
3554
  }).pipe(ensuring2(ignore(controlPlane.client.stopRunnerReplica(input.runnerId, replica.id))), provide3(provideMerge(root, layer3)));
3446
- }).pipe(scoped, catchTag("RunnerStopped", ({ problem }) => error(`Runner stopped (${problem.code}): ${problem.message}
3555
+ }).pipe(scoped);
3556
+ return gen(function* () {
3557
+ while (true) {
3558
+ const started = yield* startOnce.pipe(asSome2, catchTag("ClientProtocolOutdated", () => flatMap3(runsInContainer(input.credential !== undefined), (container) => as(updateRefusedRunner({ apiUrl: input.apiUrl, runnerId: input.runnerId, container }), none()))));
3559
+ if (isSome(started))
3560
+ return started.value;
3561
+ }
3562
+ }).pipe(catchTag("RunnerStopped", ({ problem }) => error(`Runner stopped (${problem.code}): ${problem.message}
3447
3563
  Fix: ${problem.fix}`)));
3448
3564
  }
3449
3565
  function checkHerdrRunnerReadiness(runner) {
@@ -3468,7 +3584,7 @@ function mcpCommand(args) {
3468
3584
  if (command.action === "run") {
3469
3585
  if (command.args.length > 0)
3470
3586
  return yield* new CliError({ message: `Unknown command: ${args.join(" ")}` });
3471
- const { runMcpServerCommand } = yield* promise(() => import("./chunk-fe65rbvv.js"));
3587
+ const { runMcpServerCommand } = yield* promise(() => import("./chunk-6zrq5xq2.js"));
3472
3588
  return yield* runMcpServerCommand({ flags: command.flags });
3473
3589
  }
3474
3590
  if (command.action !== "setup")
@@ -4722,9 +4838,9 @@ function changeRequestCommand(args) {
4722
4838
  yield* log(command.action === "approve" ? `Approved ${short} of ${changeRequest.title}. A Run waiting on approval of ${short} resumes; one waiting on another head does not.` : `Requested changes to ${short} of ${changeRequest.title}`);
4723
4839
  });
4724
4840
  }
4725
- var KitWriter = map8(promise(() => import("./chunk-fzsbapgz.js")), (build) => build.writeKit);
4841
+ var KitWriter = map8(promise(() => import("./chunk-y0q2574w.js")), (build) => build.writeKit);
4726
4842
  var KitBuilder = Reference("kitman/cli/KitBuilder", {
4727
- defaultValue: () => (directory) => flatMap3(promise(() => import("./chunk-fzsbapgz.js")), (build) => build.buildKit(directory))
4843
+ defaultValue: () => (directory) => flatMap3(promise(() => import("./chunk-y0q2574w.js")), (build) => build.buildKit(directory))
4728
4844
  });
4729
4845
  var uploadKit = (client, workspaceId, built) => gen(function* () {
4730
4846
  yield* client.uploadKitBundle(workspaceId, built.digest, { bundle: encode2(built.bundle) });