@sjawhar/pi-legion-envoy 1.59.1 → 1.60.1

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.
package/dist/envoy.js CHANGED
@@ -29783,6 +29783,7 @@ var MessageEventPayloadSchema = object({
29783
29783
  target: string2().nullish(),
29784
29784
  in_reply_to: string2().nullish(),
29785
29785
  reply_body: string2().optional(),
29786
+ thread_target: string2().optional(),
29786
29787
  author: object({ kind: string2(), id: string2() }).optional()
29787
29788
  });
29788
29789
  var DispatchTargetedResourceIDSchema = uuid2();
package/dist/legion.js CHANGED
@@ -16144,7 +16144,7 @@ import { logger } from "@oh-my-pi/pi-utils";
16144
16144
  // package.json
16145
16145
  var package_default = {
16146
16146
  name: "@sjawhar/pi-legion-envoy",
16147
- version: "1.59.1",
16147
+ version: "1.60.1",
16148
16148
  type: "module",
16149
16149
  omp: {
16150
16150
  extensions: [
@@ -16156,7 +16156,8 @@ var package_default = {
16156
16156
  ]
16157
16157
  },
16158
16158
  legion: {
16159
- daemonApiVersion: 8
16159
+ daemonApiVersion: 8,
16160
+ goDaemonApiVersion: 1
16160
16161
  },
16161
16162
  repository: {
16162
16163
  type: "git",
@@ -16187,6 +16188,247 @@ var package_default = {
16187
16188
  }
16188
16189
  };
16189
16190
 
16191
+ // ../../node_modules/.bun/zod@4.3.6/node_modules/zod/v4/classic/external.js
16192
+ var exports_external = {};
16193
+ __export(exports_external, {
16194
+ $brand: () => $brand,
16195
+ $input: () => $input,
16196
+ $output: () => $output,
16197
+ NEVER: () => NEVER,
16198
+ TimePrecision: () => TimePrecision,
16199
+ ZodAny: () => ZodAny,
16200
+ ZodArray: () => ZodArray,
16201
+ ZodBase64: () => ZodBase64,
16202
+ ZodBase64URL: () => ZodBase64URL,
16203
+ ZodBigInt: () => ZodBigInt,
16204
+ ZodBigIntFormat: () => ZodBigIntFormat,
16205
+ ZodBoolean: () => ZodBoolean,
16206
+ ZodCIDRv4: () => ZodCIDRv4,
16207
+ ZodCIDRv6: () => ZodCIDRv6,
16208
+ ZodCUID: () => ZodCUID,
16209
+ ZodCUID2: () => ZodCUID2,
16210
+ ZodCatch: () => ZodCatch,
16211
+ ZodCodec: () => ZodCodec,
16212
+ ZodCustom: () => ZodCustom,
16213
+ ZodCustomStringFormat: () => ZodCustomStringFormat,
16214
+ ZodDate: () => ZodDate,
16215
+ ZodDefault: () => ZodDefault,
16216
+ ZodDiscriminatedUnion: () => ZodDiscriminatedUnion,
16217
+ ZodE164: () => ZodE164,
16218
+ ZodEmail: () => ZodEmail,
16219
+ ZodEmoji: () => ZodEmoji,
16220
+ ZodEnum: () => ZodEnum,
16221
+ ZodError: () => ZodError,
16222
+ ZodExactOptional: () => ZodExactOptional,
16223
+ ZodFile: () => ZodFile,
16224
+ ZodFirstPartyTypeKind: () => ZodFirstPartyTypeKind,
16225
+ ZodFunction: () => ZodFunction,
16226
+ ZodGUID: () => ZodGUID,
16227
+ ZodIPv4: () => ZodIPv4,
16228
+ ZodIPv6: () => ZodIPv6,
16229
+ ZodISODate: () => ZodISODate,
16230
+ ZodISODateTime: () => ZodISODateTime,
16231
+ ZodISODuration: () => ZodISODuration,
16232
+ ZodISOTime: () => ZodISOTime,
16233
+ ZodIntersection: () => ZodIntersection,
16234
+ ZodIssueCode: () => ZodIssueCode,
16235
+ ZodJWT: () => ZodJWT,
16236
+ ZodKSUID: () => ZodKSUID,
16237
+ ZodLazy: () => ZodLazy,
16238
+ ZodLiteral: () => ZodLiteral,
16239
+ ZodMAC: () => ZodMAC,
16240
+ ZodMap: () => ZodMap,
16241
+ ZodNaN: () => ZodNaN,
16242
+ ZodNanoID: () => ZodNanoID,
16243
+ ZodNever: () => ZodNever,
16244
+ ZodNonOptional: () => ZodNonOptional,
16245
+ ZodNull: () => ZodNull,
16246
+ ZodNullable: () => ZodNullable,
16247
+ ZodNumber: () => ZodNumber,
16248
+ ZodNumberFormat: () => ZodNumberFormat,
16249
+ ZodObject: () => ZodObject,
16250
+ ZodOptional: () => ZodOptional,
16251
+ ZodPipe: () => ZodPipe,
16252
+ ZodPrefault: () => ZodPrefault,
16253
+ ZodPromise: () => ZodPromise,
16254
+ ZodReadonly: () => ZodReadonly,
16255
+ ZodRealError: () => ZodRealError,
16256
+ ZodRecord: () => ZodRecord,
16257
+ ZodSet: () => ZodSet,
16258
+ ZodString: () => ZodString,
16259
+ ZodStringFormat: () => ZodStringFormat,
16260
+ ZodSuccess: () => ZodSuccess,
16261
+ ZodSymbol: () => ZodSymbol,
16262
+ ZodTemplateLiteral: () => ZodTemplateLiteral,
16263
+ ZodTransform: () => ZodTransform,
16264
+ ZodTuple: () => ZodTuple,
16265
+ ZodType: () => ZodType,
16266
+ ZodULID: () => ZodULID,
16267
+ ZodURL: () => ZodURL,
16268
+ ZodUUID: () => ZodUUID,
16269
+ ZodUndefined: () => ZodUndefined,
16270
+ ZodUnion: () => ZodUnion,
16271
+ ZodUnknown: () => ZodUnknown,
16272
+ ZodVoid: () => ZodVoid,
16273
+ ZodXID: () => ZodXID,
16274
+ ZodXor: () => ZodXor,
16275
+ _ZodString: () => _ZodString,
16276
+ _default: () => _default2,
16277
+ _function: () => _function,
16278
+ any: () => any,
16279
+ array: () => array,
16280
+ base64: () => base642,
16281
+ base64url: () => base64url2,
16282
+ bigint: () => bigint2,
16283
+ boolean: () => boolean2,
16284
+ catch: () => _catch2,
16285
+ check: () => check,
16286
+ cidrv4: () => cidrv42,
16287
+ cidrv6: () => cidrv62,
16288
+ clone: () => clone,
16289
+ codec: () => codec,
16290
+ coerce: () => exports_coerce,
16291
+ config: () => config,
16292
+ core: () => exports_core2,
16293
+ cuid: () => cuid3,
16294
+ cuid2: () => cuid22,
16295
+ custom: () => custom,
16296
+ date: () => date3,
16297
+ decode: () => decode2,
16298
+ decodeAsync: () => decodeAsync2,
16299
+ describe: () => describe2,
16300
+ discriminatedUnion: () => discriminatedUnion,
16301
+ e164: () => e1642,
16302
+ email: () => email2,
16303
+ emoji: () => emoji2,
16304
+ encode: () => encode2,
16305
+ encodeAsync: () => encodeAsync2,
16306
+ endsWith: () => _endsWith,
16307
+ enum: () => _enum2,
16308
+ exactOptional: () => exactOptional,
16309
+ file: () => file,
16310
+ flattenError: () => flattenError,
16311
+ float32: () => float32,
16312
+ float64: () => float64,
16313
+ formatError: () => formatError,
16314
+ fromJSONSchema: () => fromJSONSchema,
16315
+ function: () => _function,
16316
+ getErrorMap: () => getErrorMap,
16317
+ globalRegistry: () => globalRegistry,
16318
+ gt: () => _gt,
16319
+ gte: () => _gte,
16320
+ guid: () => guid2,
16321
+ hash: () => hash,
16322
+ hex: () => hex2,
16323
+ hostname: () => hostname2,
16324
+ httpUrl: () => httpUrl,
16325
+ includes: () => _includes,
16326
+ instanceof: () => _instanceof,
16327
+ int: () => int,
16328
+ int32: () => int32,
16329
+ int64: () => int64,
16330
+ intersection: () => intersection,
16331
+ ipv4: () => ipv42,
16332
+ ipv6: () => ipv62,
16333
+ iso: () => exports_iso,
16334
+ json: () => json,
16335
+ jwt: () => jwt,
16336
+ keyof: () => keyof,
16337
+ ksuid: () => ksuid2,
16338
+ lazy: () => lazy,
16339
+ length: () => _length,
16340
+ literal: () => literal,
16341
+ locales: () => exports_locales,
16342
+ looseObject: () => looseObject,
16343
+ looseRecord: () => looseRecord,
16344
+ lowercase: () => _lowercase,
16345
+ lt: () => _lt,
16346
+ lte: () => _lte,
16347
+ mac: () => mac2,
16348
+ map: () => map,
16349
+ maxLength: () => _maxLength,
16350
+ maxSize: () => _maxSize,
16351
+ meta: () => meta2,
16352
+ mime: () => _mime,
16353
+ minLength: () => _minLength,
16354
+ minSize: () => _minSize,
16355
+ multipleOf: () => _multipleOf,
16356
+ nan: () => nan,
16357
+ nanoid: () => nanoid2,
16358
+ nativeEnum: () => nativeEnum,
16359
+ negative: () => _negative,
16360
+ never: () => never,
16361
+ nonnegative: () => _nonnegative,
16362
+ nonoptional: () => nonoptional,
16363
+ nonpositive: () => _nonpositive,
16364
+ normalize: () => _normalize,
16365
+ null: () => _null3,
16366
+ nullable: () => nullable,
16367
+ nullish: () => nullish2,
16368
+ number: () => number2,
16369
+ object: () => object,
16370
+ optional: () => optional,
16371
+ overwrite: () => _overwrite,
16372
+ parse: () => parse3,
16373
+ parseAsync: () => parseAsync2,
16374
+ partialRecord: () => partialRecord,
16375
+ pipe: () => pipe,
16376
+ positive: () => _positive,
16377
+ prefault: () => prefault,
16378
+ preprocess: () => preprocess,
16379
+ prettifyError: () => prettifyError,
16380
+ promise: () => promise,
16381
+ property: () => _property,
16382
+ readonly: () => readonly,
16383
+ record: () => record,
16384
+ refine: () => refine,
16385
+ regex: () => _regex,
16386
+ regexes: () => exports_regexes,
16387
+ registry: () => registry,
16388
+ safeDecode: () => safeDecode2,
16389
+ safeDecodeAsync: () => safeDecodeAsync2,
16390
+ safeEncode: () => safeEncode2,
16391
+ safeEncodeAsync: () => safeEncodeAsync2,
16392
+ safeParse: () => safeParse2,
16393
+ safeParseAsync: () => safeParseAsync2,
16394
+ set: () => set,
16395
+ setErrorMap: () => setErrorMap,
16396
+ size: () => _size,
16397
+ slugify: () => _slugify,
16398
+ startsWith: () => _startsWith,
16399
+ strictObject: () => strictObject,
16400
+ string: () => string2,
16401
+ stringFormat: () => stringFormat,
16402
+ stringbool: () => stringbool,
16403
+ success: () => success,
16404
+ superRefine: () => superRefine,
16405
+ symbol: () => symbol,
16406
+ templateLiteral: () => templateLiteral,
16407
+ toJSONSchema: () => toJSONSchema,
16408
+ toLowerCase: () => _toLowerCase,
16409
+ toUpperCase: () => _toUpperCase,
16410
+ transform: () => transform,
16411
+ treeifyError: () => treeifyError,
16412
+ trim: () => _trim,
16413
+ tuple: () => tuple,
16414
+ uint32: () => uint32,
16415
+ uint64: () => uint64,
16416
+ ulid: () => ulid2,
16417
+ undefined: () => _undefined3,
16418
+ union: () => union,
16419
+ unknown: () => unknown,
16420
+ uppercase: () => _uppercase,
16421
+ url: () => url,
16422
+ util: () => exports_util,
16423
+ uuid: () => uuid2,
16424
+ uuidv4: () => uuidv4,
16425
+ uuidv6: () => uuidv6,
16426
+ uuidv7: () => uuidv7,
16427
+ void: () => _void2,
16428
+ xid: () => xid2,
16429
+ xor: () => xor
16430
+ });
16431
+
16190
16432
  // ../../node_modules/.bun/zod@4.3.6/node_modules/zod/v4/core/index.js
16191
16433
  var exports_core2 = {};
16192
16434
  __export(exports_core2, {
@@ -28966,6 +29208,518 @@ function json(params) {
28966
29208
  function preprocess(fn, schema) {
28967
29209
  return pipe(transform(fn), schema);
28968
29210
  }
29211
+ // ../../node_modules/.bun/zod@4.3.6/node_modules/zod/v4/classic/compat.js
29212
+ var ZodIssueCode = {
29213
+ invalid_type: "invalid_type",
29214
+ too_big: "too_big",
29215
+ too_small: "too_small",
29216
+ invalid_format: "invalid_format",
29217
+ not_multiple_of: "not_multiple_of",
29218
+ unrecognized_keys: "unrecognized_keys",
29219
+ invalid_union: "invalid_union",
29220
+ invalid_key: "invalid_key",
29221
+ invalid_element: "invalid_element",
29222
+ invalid_value: "invalid_value",
29223
+ custom: "custom"
29224
+ };
29225
+ function setErrorMap(map) {
29226
+ config({
29227
+ customError: map
29228
+ });
29229
+ }
29230
+ function getErrorMap() {
29231
+ return config().customError;
29232
+ }
29233
+ var ZodFirstPartyTypeKind;
29234
+ (function(ZodFirstPartyTypeKind) {})(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
29235
+ // ../../node_modules/.bun/zod@4.3.6/node_modules/zod/v4/classic/from-json-schema.js
29236
+ var z = {
29237
+ ...exports_schemas2,
29238
+ ...exports_checks2,
29239
+ iso: exports_iso
29240
+ };
29241
+ var RECOGNIZED_KEYS = new Set([
29242
+ "$schema",
29243
+ "$ref",
29244
+ "$defs",
29245
+ "definitions",
29246
+ "$id",
29247
+ "id",
29248
+ "$comment",
29249
+ "$anchor",
29250
+ "$vocabulary",
29251
+ "$dynamicRef",
29252
+ "$dynamicAnchor",
29253
+ "type",
29254
+ "enum",
29255
+ "const",
29256
+ "anyOf",
29257
+ "oneOf",
29258
+ "allOf",
29259
+ "not",
29260
+ "properties",
29261
+ "required",
29262
+ "additionalProperties",
29263
+ "patternProperties",
29264
+ "propertyNames",
29265
+ "minProperties",
29266
+ "maxProperties",
29267
+ "items",
29268
+ "prefixItems",
29269
+ "additionalItems",
29270
+ "minItems",
29271
+ "maxItems",
29272
+ "uniqueItems",
29273
+ "contains",
29274
+ "minContains",
29275
+ "maxContains",
29276
+ "minLength",
29277
+ "maxLength",
29278
+ "pattern",
29279
+ "format",
29280
+ "minimum",
29281
+ "maximum",
29282
+ "exclusiveMinimum",
29283
+ "exclusiveMaximum",
29284
+ "multipleOf",
29285
+ "description",
29286
+ "default",
29287
+ "contentEncoding",
29288
+ "contentMediaType",
29289
+ "contentSchema",
29290
+ "unevaluatedItems",
29291
+ "unevaluatedProperties",
29292
+ "if",
29293
+ "then",
29294
+ "else",
29295
+ "dependentSchemas",
29296
+ "dependentRequired",
29297
+ "nullable",
29298
+ "readOnly"
29299
+ ]);
29300
+ function detectVersion(schema, defaultTarget) {
29301
+ const $schema = schema.$schema;
29302
+ if ($schema === "https://json-schema.org/draft/2020-12/schema") {
29303
+ return "draft-2020-12";
29304
+ }
29305
+ if ($schema === "http://json-schema.org/draft-07/schema#") {
29306
+ return "draft-7";
29307
+ }
29308
+ if ($schema === "http://json-schema.org/draft-04/schema#") {
29309
+ return "draft-4";
29310
+ }
29311
+ return defaultTarget ?? "draft-2020-12";
29312
+ }
29313
+ function resolveRef(ref, ctx) {
29314
+ if (!ref.startsWith("#")) {
29315
+ throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
29316
+ }
29317
+ const path = ref.slice(1).split("/").filter(Boolean);
29318
+ if (path.length === 0) {
29319
+ return ctx.rootSchema;
29320
+ }
29321
+ const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
29322
+ if (path[0] === defsKey) {
29323
+ const key = path[1];
29324
+ if (!key || !ctx.defs[key]) {
29325
+ throw new Error(`Reference not found: ${ref}`);
29326
+ }
29327
+ return ctx.defs[key];
29328
+ }
29329
+ throw new Error(`Reference not found: ${ref}`);
29330
+ }
29331
+ function convertBaseSchema(schema, ctx) {
29332
+ if (schema.not !== undefined) {
29333
+ if (typeof schema.not === "object" && Object.keys(schema.not).length === 0) {
29334
+ return z.never();
29335
+ }
29336
+ throw new Error("not is not supported in Zod (except { not: {} } for never)");
29337
+ }
29338
+ if (schema.unevaluatedItems !== undefined) {
29339
+ throw new Error("unevaluatedItems is not supported");
29340
+ }
29341
+ if (schema.unevaluatedProperties !== undefined) {
29342
+ throw new Error("unevaluatedProperties is not supported");
29343
+ }
29344
+ if (schema.if !== undefined || schema.then !== undefined || schema.else !== undefined) {
29345
+ throw new Error("Conditional schemas (if/then/else) are not supported");
29346
+ }
29347
+ if (schema.dependentSchemas !== undefined || schema.dependentRequired !== undefined) {
29348
+ throw new Error("dependentSchemas and dependentRequired are not supported");
29349
+ }
29350
+ if (schema.$ref) {
29351
+ const refPath = schema.$ref;
29352
+ if (ctx.refs.has(refPath)) {
29353
+ return ctx.refs.get(refPath);
29354
+ }
29355
+ if (ctx.processing.has(refPath)) {
29356
+ return z.lazy(() => {
29357
+ if (!ctx.refs.has(refPath)) {
29358
+ throw new Error(`Circular reference not resolved: ${refPath}`);
29359
+ }
29360
+ return ctx.refs.get(refPath);
29361
+ });
29362
+ }
29363
+ ctx.processing.add(refPath);
29364
+ const resolved = resolveRef(refPath, ctx);
29365
+ const zodSchema = convertSchema(resolved, ctx);
29366
+ ctx.refs.set(refPath, zodSchema);
29367
+ ctx.processing.delete(refPath);
29368
+ return zodSchema;
29369
+ }
29370
+ if (schema.enum !== undefined) {
29371
+ const enumValues = schema.enum;
29372
+ if (ctx.version === "openapi-3.0" && schema.nullable === true && enumValues.length === 1 && enumValues[0] === null) {
29373
+ return z.null();
29374
+ }
29375
+ if (enumValues.length === 0) {
29376
+ return z.never();
29377
+ }
29378
+ if (enumValues.length === 1) {
29379
+ return z.literal(enumValues[0]);
29380
+ }
29381
+ if (enumValues.every((v) => typeof v === "string")) {
29382
+ return z.enum(enumValues);
29383
+ }
29384
+ const literalSchemas = enumValues.map((v) => z.literal(v));
29385
+ if (literalSchemas.length < 2) {
29386
+ return literalSchemas[0];
29387
+ }
29388
+ return z.union([literalSchemas[0], literalSchemas[1], ...literalSchemas.slice(2)]);
29389
+ }
29390
+ if (schema.const !== undefined) {
29391
+ return z.literal(schema.const);
29392
+ }
29393
+ const type = schema.type;
29394
+ if (Array.isArray(type)) {
29395
+ const typeSchemas = type.map((t) => {
29396
+ const typeSchema = { ...schema, type: t };
29397
+ return convertBaseSchema(typeSchema, ctx);
29398
+ });
29399
+ if (typeSchemas.length === 0) {
29400
+ return z.never();
29401
+ }
29402
+ if (typeSchemas.length === 1) {
29403
+ return typeSchemas[0];
29404
+ }
29405
+ return z.union(typeSchemas);
29406
+ }
29407
+ if (!type) {
29408
+ return z.any();
29409
+ }
29410
+ let zodSchema;
29411
+ switch (type) {
29412
+ case "string": {
29413
+ let stringSchema = z.string();
29414
+ if (schema.format) {
29415
+ const format = schema.format;
29416
+ if (format === "email") {
29417
+ stringSchema = stringSchema.check(z.email());
29418
+ } else if (format === "uri" || format === "uri-reference") {
29419
+ stringSchema = stringSchema.check(z.url());
29420
+ } else if (format === "uuid" || format === "guid") {
29421
+ stringSchema = stringSchema.check(z.uuid());
29422
+ } else if (format === "date-time") {
29423
+ stringSchema = stringSchema.check(z.iso.datetime());
29424
+ } else if (format === "date") {
29425
+ stringSchema = stringSchema.check(z.iso.date());
29426
+ } else if (format === "time") {
29427
+ stringSchema = stringSchema.check(z.iso.time());
29428
+ } else if (format === "duration") {
29429
+ stringSchema = stringSchema.check(z.iso.duration());
29430
+ } else if (format === "ipv4") {
29431
+ stringSchema = stringSchema.check(z.ipv4());
29432
+ } else if (format === "ipv6") {
29433
+ stringSchema = stringSchema.check(z.ipv6());
29434
+ } else if (format === "mac") {
29435
+ stringSchema = stringSchema.check(z.mac());
29436
+ } else if (format === "cidr") {
29437
+ stringSchema = stringSchema.check(z.cidrv4());
29438
+ } else if (format === "cidr-v6") {
29439
+ stringSchema = stringSchema.check(z.cidrv6());
29440
+ } else if (format === "base64") {
29441
+ stringSchema = stringSchema.check(z.base64());
29442
+ } else if (format === "base64url") {
29443
+ stringSchema = stringSchema.check(z.base64url());
29444
+ } else if (format === "e164") {
29445
+ stringSchema = stringSchema.check(z.e164());
29446
+ } else if (format === "jwt") {
29447
+ stringSchema = stringSchema.check(z.jwt());
29448
+ } else if (format === "emoji") {
29449
+ stringSchema = stringSchema.check(z.emoji());
29450
+ } else if (format === "nanoid") {
29451
+ stringSchema = stringSchema.check(z.nanoid());
29452
+ } else if (format === "cuid") {
29453
+ stringSchema = stringSchema.check(z.cuid());
29454
+ } else if (format === "cuid2") {
29455
+ stringSchema = stringSchema.check(z.cuid2());
29456
+ } else if (format === "ulid") {
29457
+ stringSchema = stringSchema.check(z.ulid());
29458
+ } else if (format === "xid") {
29459
+ stringSchema = stringSchema.check(z.xid());
29460
+ } else if (format === "ksuid") {
29461
+ stringSchema = stringSchema.check(z.ksuid());
29462
+ }
29463
+ }
29464
+ if (typeof schema.minLength === "number") {
29465
+ stringSchema = stringSchema.min(schema.minLength);
29466
+ }
29467
+ if (typeof schema.maxLength === "number") {
29468
+ stringSchema = stringSchema.max(schema.maxLength);
29469
+ }
29470
+ if (schema.pattern) {
29471
+ stringSchema = stringSchema.regex(new RegExp(schema.pattern));
29472
+ }
29473
+ zodSchema = stringSchema;
29474
+ break;
29475
+ }
29476
+ case "number":
29477
+ case "integer": {
29478
+ let numberSchema = type === "integer" ? z.number().int() : z.number();
29479
+ if (typeof schema.minimum === "number") {
29480
+ numberSchema = numberSchema.min(schema.minimum);
29481
+ }
29482
+ if (typeof schema.maximum === "number") {
29483
+ numberSchema = numberSchema.max(schema.maximum);
29484
+ }
29485
+ if (typeof schema.exclusiveMinimum === "number") {
29486
+ numberSchema = numberSchema.gt(schema.exclusiveMinimum);
29487
+ } else if (schema.exclusiveMinimum === true && typeof schema.minimum === "number") {
29488
+ numberSchema = numberSchema.gt(schema.minimum);
29489
+ }
29490
+ if (typeof schema.exclusiveMaximum === "number") {
29491
+ numberSchema = numberSchema.lt(schema.exclusiveMaximum);
29492
+ } else if (schema.exclusiveMaximum === true && typeof schema.maximum === "number") {
29493
+ numberSchema = numberSchema.lt(schema.maximum);
29494
+ }
29495
+ if (typeof schema.multipleOf === "number") {
29496
+ numberSchema = numberSchema.multipleOf(schema.multipleOf);
29497
+ }
29498
+ zodSchema = numberSchema;
29499
+ break;
29500
+ }
29501
+ case "boolean": {
29502
+ zodSchema = z.boolean();
29503
+ break;
29504
+ }
29505
+ case "null": {
29506
+ zodSchema = z.null();
29507
+ break;
29508
+ }
29509
+ case "object": {
29510
+ const shape = {};
29511
+ const properties = schema.properties || {};
29512
+ const requiredSet = new Set(schema.required || []);
29513
+ for (const [key, propSchema] of Object.entries(properties)) {
29514
+ const propZodSchema = convertSchema(propSchema, ctx);
29515
+ shape[key] = requiredSet.has(key) ? propZodSchema : propZodSchema.optional();
29516
+ }
29517
+ if (schema.propertyNames) {
29518
+ const keySchema = convertSchema(schema.propertyNames, ctx);
29519
+ const valueSchema = schema.additionalProperties && typeof schema.additionalProperties === "object" ? convertSchema(schema.additionalProperties, ctx) : z.any();
29520
+ if (Object.keys(shape).length === 0) {
29521
+ zodSchema = z.record(keySchema, valueSchema);
29522
+ break;
29523
+ }
29524
+ const objectSchema = z.object(shape).passthrough();
29525
+ const recordSchema = z.looseRecord(keySchema, valueSchema);
29526
+ zodSchema = z.intersection(objectSchema, recordSchema);
29527
+ break;
29528
+ }
29529
+ if (schema.patternProperties) {
29530
+ const patternProps = schema.patternProperties;
29531
+ const patternKeys = Object.keys(patternProps);
29532
+ const looseRecords = [];
29533
+ for (const pattern of patternKeys) {
29534
+ const patternValue = convertSchema(patternProps[pattern], ctx);
29535
+ const keySchema = z.string().regex(new RegExp(pattern));
29536
+ looseRecords.push(z.looseRecord(keySchema, patternValue));
29537
+ }
29538
+ const schemasToIntersect = [];
29539
+ if (Object.keys(shape).length > 0) {
29540
+ schemasToIntersect.push(z.object(shape).passthrough());
29541
+ }
29542
+ schemasToIntersect.push(...looseRecords);
29543
+ if (schemasToIntersect.length === 0) {
29544
+ zodSchema = z.object({}).passthrough();
29545
+ } else if (schemasToIntersect.length === 1) {
29546
+ zodSchema = schemasToIntersect[0];
29547
+ } else {
29548
+ let result = z.intersection(schemasToIntersect[0], schemasToIntersect[1]);
29549
+ for (let i = 2;i < schemasToIntersect.length; i++) {
29550
+ result = z.intersection(result, schemasToIntersect[i]);
29551
+ }
29552
+ zodSchema = result;
29553
+ }
29554
+ break;
29555
+ }
29556
+ const objectSchema = z.object(shape);
29557
+ if (schema.additionalProperties === false) {
29558
+ zodSchema = objectSchema.strict();
29559
+ } else if (typeof schema.additionalProperties === "object") {
29560
+ zodSchema = objectSchema.catchall(convertSchema(schema.additionalProperties, ctx));
29561
+ } else {
29562
+ zodSchema = objectSchema.passthrough();
29563
+ }
29564
+ break;
29565
+ }
29566
+ case "array": {
29567
+ const prefixItems = schema.prefixItems;
29568
+ const items = schema.items;
29569
+ if (prefixItems && Array.isArray(prefixItems)) {
29570
+ const tupleItems = prefixItems.map((item) => convertSchema(item, ctx));
29571
+ const rest = items && typeof items === "object" && !Array.isArray(items) ? convertSchema(items, ctx) : undefined;
29572
+ if (rest) {
29573
+ zodSchema = z.tuple(tupleItems).rest(rest);
29574
+ } else {
29575
+ zodSchema = z.tuple(tupleItems);
29576
+ }
29577
+ if (typeof schema.minItems === "number") {
29578
+ zodSchema = zodSchema.check(z.minLength(schema.minItems));
29579
+ }
29580
+ if (typeof schema.maxItems === "number") {
29581
+ zodSchema = zodSchema.check(z.maxLength(schema.maxItems));
29582
+ }
29583
+ } else if (Array.isArray(items)) {
29584
+ const tupleItems = items.map((item) => convertSchema(item, ctx));
29585
+ const rest = schema.additionalItems && typeof schema.additionalItems === "object" ? convertSchema(schema.additionalItems, ctx) : undefined;
29586
+ if (rest) {
29587
+ zodSchema = z.tuple(tupleItems).rest(rest);
29588
+ } else {
29589
+ zodSchema = z.tuple(tupleItems);
29590
+ }
29591
+ if (typeof schema.minItems === "number") {
29592
+ zodSchema = zodSchema.check(z.minLength(schema.minItems));
29593
+ }
29594
+ if (typeof schema.maxItems === "number") {
29595
+ zodSchema = zodSchema.check(z.maxLength(schema.maxItems));
29596
+ }
29597
+ } else if (items !== undefined) {
29598
+ const element = convertSchema(items, ctx);
29599
+ let arraySchema = z.array(element);
29600
+ if (typeof schema.minItems === "number") {
29601
+ arraySchema = arraySchema.min(schema.minItems);
29602
+ }
29603
+ if (typeof schema.maxItems === "number") {
29604
+ arraySchema = arraySchema.max(schema.maxItems);
29605
+ }
29606
+ zodSchema = arraySchema;
29607
+ } else {
29608
+ zodSchema = z.array(z.any());
29609
+ }
29610
+ break;
29611
+ }
29612
+ default:
29613
+ throw new Error(`Unsupported type: ${type}`);
29614
+ }
29615
+ if (schema.description) {
29616
+ zodSchema = zodSchema.describe(schema.description);
29617
+ }
29618
+ if (schema.default !== undefined) {
29619
+ zodSchema = zodSchema.default(schema.default);
29620
+ }
29621
+ return zodSchema;
29622
+ }
29623
+ function convertSchema(schema, ctx) {
29624
+ if (typeof schema === "boolean") {
29625
+ return schema ? z.any() : z.never();
29626
+ }
29627
+ let baseSchema = convertBaseSchema(schema, ctx);
29628
+ const hasExplicitType = schema.type || schema.enum !== undefined || schema.const !== undefined;
29629
+ if (schema.anyOf && Array.isArray(schema.anyOf)) {
29630
+ const options = schema.anyOf.map((s) => convertSchema(s, ctx));
29631
+ const anyOfUnion = z.union(options);
29632
+ baseSchema = hasExplicitType ? z.intersection(baseSchema, anyOfUnion) : anyOfUnion;
29633
+ }
29634
+ if (schema.oneOf && Array.isArray(schema.oneOf)) {
29635
+ const options = schema.oneOf.map((s) => convertSchema(s, ctx));
29636
+ const oneOfUnion = z.xor(options);
29637
+ baseSchema = hasExplicitType ? z.intersection(baseSchema, oneOfUnion) : oneOfUnion;
29638
+ }
29639
+ if (schema.allOf && Array.isArray(schema.allOf)) {
29640
+ if (schema.allOf.length === 0) {
29641
+ baseSchema = hasExplicitType ? baseSchema : z.any();
29642
+ } else {
29643
+ let result = hasExplicitType ? baseSchema : convertSchema(schema.allOf[0], ctx);
29644
+ const startIdx = hasExplicitType ? 0 : 1;
29645
+ for (let i = startIdx;i < schema.allOf.length; i++) {
29646
+ result = z.intersection(result, convertSchema(schema.allOf[i], ctx));
29647
+ }
29648
+ baseSchema = result;
29649
+ }
29650
+ }
29651
+ if (schema.nullable === true && ctx.version === "openapi-3.0") {
29652
+ baseSchema = z.nullable(baseSchema);
29653
+ }
29654
+ if (schema.readOnly === true) {
29655
+ baseSchema = z.readonly(baseSchema);
29656
+ }
29657
+ const extraMeta = {};
29658
+ const coreMetadataKeys = ["$id", "id", "$comment", "$anchor", "$vocabulary", "$dynamicRef", "$dynamicAnchor"];
29659
+ for (const key of coreMetadataKeys) {
29660
+ if (key in schema) {
29661
+ extraMeta[key] = schema[key];
29662
+ }
29663
+ }
29664
+ const contentMetadataKeys = ["contentEncoding", "contentMediaType", "contentSchema"];
29665
+ for (const key of contentMetadataKeys) {
29666
+ if (key in schema) {
29667
+ extraMeta[key] = schema[key];
29668
+ }
29669
+ }
29670
+ for (const key of Object.keys(schema)) {
29671
+ if (!RECOGNIZED_KEYS.has(key)) {
29672
+ extraMeta[key] = schema[key];
29673
+ }
29674
+ }
29675
+ if (Object.keys(extraMeta).length > 0) {
29676
+ ctx.registry.add(baseSchema, extraMeta);
29677
+ }
29678
+ return baseSchema;
29679
+ }
29680
+ function fromJSONSchema(schema, params) {
29681
+ if (typeof schema === "boolean") {
29682
+ return schema ? z.any() : z.never();
29683
+ }
29684
+ const version = detectVersion(schema, params?.defaultTarget);
29685
+ const defs = schema.$defs || schema.definitions || {};
29686
+ const ctx = {
29687
+ version,
29688
+ defs,
29689
+ refs: new Map,
29690
+ processing: new Set,
29691
+ rootSchema: schema,
29692
+ registry: params?.registry ?? globalRegistry
29693
+ };
29694
+ return convertSchema(schema, ctx);
29695
+ }
29696
+ // ../../node_modules/.bun/zod@4.3.6/node_modules/zod/v4/classic/coerce.js
29697
+ var exports_coerce = {};
29698
+ __export(exports_coerce, {
29699
+ bigint: () => bigint3,
29700
+ boolean: () => boolean3,
29701
+ date: () => date4,
29702
+ number: () => number3,
29703
+ string: () => string3
29704
+ });
29705
+ function string3(params) {
29706
+ return _coercedString(ZodString, params);
29707
+ }
29708
+ function number3(params) {
29709
+ return _coercedNumber(ZodNumber, params);
29710
+ }
29711
+ function boolean3(params) {
29712
+ return _coercedBoolean(ZodBoolean, params);
29713
+ }
29714
+ function bigint3(params) {
29715
+ return _coercedBigint(ZodBigInt, params);
29716
+ }
29717
+ function date4(params) {
29718
+ return _coercedDate(ZodDate, params);
29719
+ }
29720
+
29721
+ // ../../node_modules/.bun/zod@4.3.6/node_modules/zod/v4/classic/external.js
29722
+ config(en_default());
28969
29723
  // ../contracts/src/dispatch-api.ts
28970
29724
  function serviceSubjectLabel(subject) {
28971
29725
  const parts = subject.split(":");
@@ -29101,6 +29855,7 @@ var MessageEventPayloadSchema = object({
29101
29855
  target: string2().nullish(),
29102
29856
  in_reply_to: string2().nullish(),
29103
29857
  reply_body: string2().optional(),
29858
+ thread_target: string2().optional(),
29104
29859
  author: object({ kind: string2(), id: string2() }).optional()
29105
29860
  });
29106
29861
  var DispatchTargetedResourceIDSchema = uuid2();
@@ -30499,6 +31254,220 @@ async function writeGrantFile(file, grantId) {
30499
31254
  }
30500
31255
  }
30501
31256
 
31257
+ // ../contracts/src/legion-go-api.ts
31258
+ var nonEmptyString2 = string2().min(1);
31259
+ var timestamp = exports_iso.datetime({ offset: true });
31260
+ var LEGION_GO_PHASES = [
31261
+ "admitted",
31262
+ "planning",
31263
+ "implementing",
31264
+ "testing",
31265
+ "reviewing",
31266
+ "retro",
31267
+ "merging",
31268
+ "awaiting_merge",
31269
+ "production_check",
31270
+ "done",
31271
+ "held"
31272
+ ];
31273
+ var LEGION_GO_CLAIM_STATES = [
31274
+ "queued",
31275
+ "launch_uncertain",
31276
+ "launching",
31277
+ "shim_connected",
31278
+ "registered",
31279
+ "ready",
31280
+ "working",
31281
+ "idle",
31282
+ "suspended",
31283
+ "failed",
31284
+ "retired"
31285
+ ];
31286
+ var legionGoLocator = discriminatedUnion("runtime", [
31287
+ strictObject({
31288
+ runtime: literal("tmux"),
31289
+ claim: nonEmptyString2,
31290
+ incarnation: nonEmptyString2,
31291
+ tmux: strictObject({ window: nonEmptyString2, pane: nonEmptyString2 })
31292
+ }),
31293
+ strictObject({
31294
+ runtime: literal("sandbox"),
31295
+ claim: nonEmptyString2,
31296
+ incarnation: nonEmptyString2,
31297
+ sandbox: strictObject({ namespace: nonEmptyString2, name: nonEmptyString2 })
31298
+ })
31299
+ ]);
31300
+ var legionGoClaimView = strictObject({
31301
+ session: string2(),
31302
+ state: _enum2(LEGION_GO_CLAIM_STATES),
31303
+ locator: legionGoLocator.optional()
31304
+ });
31305
+ var legionGoPhaseView = strictObject({
31306
+ claim: legionGoClaimView,
31307
+ handoffCommit: nonEmptyString2.optional(),
31308
+ rounds: number2().int().nonnegative()
31309
+ });
31310
+ var legionGoPullRequestView = strictObject({
31311
+ number: number2().int().positive(),
31312
+ head: nonEmptyString2,
31313
+ checksVerdict: nonEmptyString2.optional(),
31314
+ reviewDecision: nonEmptyString2.optional(),
31315
+ fixAttempts: number2().int().nonnegative()
31316
+ });
31317
+ var legionGoGateView = strictObject({
31318
+ artifactId: nonEmptyString2,
31319
+ currentVersion: number2().int().positive(),
31320
+ approvedVersion: number2().int().positive().nullable()
31321
+ });
31322
+ var legionGoSlotView = strictObject({
31323
+ index: number2().int().nonnegative(),
31324
+ admittedAt: timestamp
31325
+ });
31326
+ var legionGoIssue = strictObject({
31327
+ key: nonEmptyString2,
31328
+ generation: number2().int().nonnegative(),
31329
+ phase: _enum2(LEGION_GO_PHASES),
31330
+ architect: legionGoClaimView.optional(),
31331
+ workers: partialRecord(_enum2(LEGION_ROLES), legionGoPhaseView),
31332
+ pullRequest: legionGoPullRequestView.optional(),
31333
+ designGate: legionGoGateView.optional(),
31334
+ slot: legionGoSlotView.optional()
31335
+ });
31336
+ var goDaemonInfo = strictObject({
31337
+ project: nonEmptyString2,
31338
+ schemaVersion: number2().int().nonnegative(),
31339
+ boots: number2().int().nonnegative(),
31340
+ firstBootAt: timestamp,
31341
+ startedAt: timestamp
31342
+ });
31343
+ var legionGoAdmission = strictObject({
31344
+ cap: number2().int().nonnegative(),
31345
+ active: array(nonEmptyString2),
31346
+ waiting: array(nonEmptyString2)
31347
+ });
31348
+ var LegionGoStateResponse = strictObject({
31349
+ daemon: goDaemonInfo,
31350
+ admission: legionGoAdmission,
31351
+ issues: record(string2(), legionGoIssue)
31352
+ });
31353
+ var LegionGoRegisterResponse = strictObject({
31354
+ claimToken: nonEmptyString2,
31355
+ tree: nonEmptyString2,
31356
+ issue: nonEmptyString2,
31357
+ role: _enum2(LEGION_ROLES),
31358
+ generation: number2().int().positive(),
31359
+ secret: nonEmptyString2
31360
+ });
31361
+ var LegionGoErrorResponse = strictObject({
31362
+ error: nonEmptyString2
31363
+ });
31364
+ var legionGoDeliveryView = strictObject({
31365
+ id: nonEmptyString2,
31366
+ task: nonEmptyString2,
31367
+ queuedAt: timestamp,
31368
+ deliveredAt: timestamp.optional(),
31369
+ confirmedAt: timestamp.optional()
31370
+ });
31371
+ var LegionGoOperatorClaimResponse = strictObject({
31372
+ token: nonEmptyString2,
31373
+ tree: nonEmptyString2,
31374
+ issue: nonEmptyString2,
31375
+ role: _enum2(LEGION_ROLES),
31376
+ generation: number2().int().nonnegative(),
31377
+ state: _enum2(LEGION_GO_CLAIM_STATES),
31378
+ session: string2(),
31379
+ sessionFile: string2(),
31380
+ locator: legionGoLocator.optional(),
31381
+ budgets: strictObject({
31382
+ launchFailures: number2().int().nonnegative(),
31383
+ promptFailures: number2().int().nonnegative(),
31384
+ promptRetires: number2().int().nonnegative()
31385
+ }),
31386
+ uncertainStreak: number2().int().nonnegative(),
31387
+ pending: legionGoDeliveryView.optional()
31388
+ });
31389
+ var LegionGoOperatorClaimsResponse = strictObject({
31390
+ claims: array(LegionGoOperatorClaimResponse)
31391
+ });
31392
+
31393
+ // src/legion/go-daemon-client.ts
31394
+ class LegionGoDaemonApiError extends Error {
31395
+ method;
31396
+ path;
31397
+ status;
31398
+ detail;
31399
+ constructor(method, path, status, detail) {
31400
+ super(`${method} ${path} failed with ${status}: ${detail}`);
31401
+ this.method = method;
31402
+ this.path = path;
31403
+ this.status = status;
31404
+ this.detail = detail;
31405
+ this.name = "LegionGoDaemonApiError";
31406
+ }
31407
+ }
31408
+
31409
+ class LegionGoDaemonContractError extends Error {
31410
+ method;
31411
+ path;
31412
+ status;
31413
+ constructor(method, path, status, problem) {
31414
+ super(`${method} ${path} answered ${status} with a body the Go daemon API contract does not describe: ${problem}`);
31415
+ this.method = method;
31416
+ this.path = path;
31417
+ this.status = status;
31418
+ this.name = "LegionGoDaemonContractError";
31419
+ }
31420
+ }
31421
+ function parseStrictly(schema, body) {
31422
+ let json;
31423
+ try {
31424
+ json = JSON.parse(body);
31425
+ } catch (error) {
31426
+ return { problem: `not JSON (${messageFor(error)})` };
31427
+ }
31428
+ const parsed = schema.safeParse(json);
31429
+ if (parsed.success)
31430
+ return { value: parsed.data };
31431
+ return {
31432
+ problem: parsed.error.issues.map((issue) => `${issue.path.join(".") || "(root)"}: ${issue.message}`).join("; ")
31433
+ };
31434
+ }
31435
+ function createLegionGoDaemonClient(baseUrl, fetchFn = fetch) {
31436
+ const endpoint = baseUrl.replace(/\/+$/, "");
31437
+ const call = async (method, path, body) => {
31438
+ const response = await fetchFn(`${endpoint}${path}`, body === undefined ? undefined : {
31439
+ method,
31440
+ headers: { "Content-Type": "application/json" },
31441
+ body: JSON.stringify(body)
31442
+ });
31443
+ const text = await response.text();
31444
+ if (response.ok)
31445
+ return { status: response.status, text };
31446
+ const refusal = parseStrictly(LegionGoErrorResponse, text);
31447
+ throw new LegionGoDaemonApiError(method, path, response.status, "value" in refusal ? refusal.value.error : `${JSON.stringify(text)} is not the Go daemon's refusal shape (${refusal.problem})`);
31448
+ };
31449
+ const read = async (method, path, schema, body) => {
31450
+ const { status, text } = await call(method, path, body);
31451
+ const parsed = parseStrictly(schema, text);
31452
+ if ("problem" in parsed) {
31453
+ throw new LegionGoDaemonContractError(method, path, status, parsed.problem);
31454
+ }
31455
+ return parsed.value;
31456
+ };
31457
+ const acknowledge = async (path, body) => {
31458
+ const { status, text } = await call("POST", path, body);
31459
+ if (status !== 204 || text !== "") {
31460
+ throw new LegionGoDaemonContractError("POST", path, status, "the route answers 204 with no body");
31461
+ }
31462
+ };
31463
+ return {
31464
+ state: () => read("GET", "/legion/v1/state", LegionGoStateResponse),
31465
+ register: (input) => read("POST", "/legion/v1/claims/register", LegionGoRegisterResponse, input),
31466
+ ready: (input) => acknowledge("/legion/v1/claims/ready", input),
31467
+ exit: (input) => acknowledge("/legion/v1/claims/exit", input)
31468
+ };
31469
+ }
31470
+
30502
31471
  // src/legion/jj-attribution.ts
30503
31472
  import { execFile } from "child_process";
30504
31473
  import { mkdir, rename as rename2, writeFile as writeFile2 } from "fs/promises";
@@ -30546,6 +31515,114 @@ commit_trailers = '"Omp-Session: ${id}"'
30546
31515
  }
30547
31516
  }
30548
31517
 
31518
+ // src/legion/go-bootstrap.ts
31519
+ var READY_RETRY_ATTEMPTS = 3;
31520
+ var READY_RETRY_DELAY_MS = 1000;
31521
+ function isNetworkOrTimeoutError(error) {
31522
+ if (!(error instanceof Error))
31523
+ return false;
31524
+ if (error.name === "NetworkError" || error.name === "TimeoutError")
31525
+ return true;
31526
+ const code = "code" in error && typeof error.code === "string" ? error.code : undefined;
31527
+ return code === "ConnectionRefused" || code === "ConnectionTimeout" || code === "EAI_AGAIN" || code === "ECONNREFUSED" || code === "ECONNRESET" || code === "EHOSTUNREACH" || code === "ENETUNREACH" || code === "ENOTFOUND" || code === "ETIMEDOUT" || error instanceof TypeError && (error.message === "Failed to fetch" || error.message === "fetch failed");
31528
+ }
31529
+ function exitOnGoRegistrationRefusal(error, exitProcess) {
31530
+ if (error instanceof LegionGoDaemonApiError) {
31531
+ console.error(`[legion] claims/register registration failed (${error.status}): ${error.detail}`);
31532
+ if (error.status >= 400 && error.status < 500)
31533
+ exitProcess(1);
31534
+ }
31535
+ throw error;
31536
+ }
31537
+ async function callGoReadyWithRetry(label, call) {
31538
+ for (let attempt = 1;; attempt++) {
31539
+ try {
31540
+ await call();
31541
+ return;
31542
+ } catch (error) {
31543
+ const retryable = error instanceof LegionGoDaemonApiError ? error.status >= 500 && error.status < 600 : isNetworkOrTimeoutError(error);
31544
+ if (!retryable)
31545
+ throw error;
31546
+ if (attempt === READY_RETRY_ATTEMPTS) {
31547
+ console.error(`[legion] ${label} failed after ${attempt} attempts: ${messageFor(error)}`);
31548
+ throw error;
31549
+ }
31550
+ console.error(`[legion] ${label} failed (attempt ${attempt}/${READY_RETRY_ATTEMPTS}), retrying: ${messageFor(error)}`);
31551
+ const retryDelay = Promise.withResolvers();
31552
+ setTimeout(retryDelay.resolve, READY_RETRY_DELAY_MS);
31553
+ await retryDelay.promise;
31554
+ }
31555
+ }
31556
+ }
31557
+ async function bootstrapGoClaim(context, state) {
31558
+ const classification = classifySession(process.env);
31559
+ if (classification.kind === "not-legion")
31560
+ return;
31561
+ if (classification.kind === "controller") {
31562
+ throw new Error("LEGION_DAEMON_API=go names the Go daemon, which launches no controller session");
31563
+ }
31564
+ const sessionID = context.sessionManager.getSessionId();
31565
+ const capability = state.capability();
31566
+ if (capability !== undefined && capability.sessionID !== sessionID)
31567
+ return;
31568
+ const existing = state.bootstrap();
31569
+ if (existing !== undefined)
31570
+ return existing;
31571
+ const bootToken = requiredSecret(process.env, "LEGION_BOOT_TOKEN");
31572
+ const daemon = createLegionGoDaemonClient(requiredEnvironment(process.env, "LEGION_DAEMON_URL"));
31573
+ const bootstrap = (async () => {
31574
+ const { sessionFile, agentId } = await state.persistedTranscript(context);
31575
+ state.recordBootstrappedSession(sessionFile);
31576
+ const claim = await daemon.register({
31577
+ bootToken,
31578
+ sessionId: sessionID,
31579
+ ompSessionFile: sessionFile,
31580
+ agentId,
31581
+ pluginContract: package_default.legion.goDaemonApiVersion
31582
+ }).catch((error) => exitOnGoRegistrationRefusal(error, state.exitProcess));
31583
+ const ready = {
31584
+ claimToken: claim.claimToken,
31585
+ sessionId: sessionID,
31586
+ secret: claim.secret,
31587
+ generation: claim.generation
31588
+ };
31589
+ try {
31590
+ await exportJjSessionAttribution(sessionFile, requiredEnvironment(process.env, "LEGION_STATE_DIR"));
31591
+ state.setCapability({
31592
+ kind: "phase-worker",
31593
+ sessionID,
31594
+ tree: claim.tree,
31595
+ issue: claim.issue,
31596
+ role: claim.role,
31597
+ roleToken: claim.claimToken,
31598
+ secret: claim.secret
31599
+ });
31600
+ await claimEnvoyRole(sessionID, claim.claimToken, context);
31601
+ await callGoReadyWithRetry("claims/ready", () => daemon.ready(ready));
31602
+ onEnvoyRoleRegained(async (role, reason) => {
31603
+ if (role !== claim.claimToken)
31604
+ return;
31605
+ try {
31606
+ await callGoReadyWithRetry("claims/ready after role regain", () => daemon.ready(ready));
31607
+ console.error(`[legion] re-ran claims/ready after role ${role} was ${reason}`);
31608
+ } catch (error) {
31609
+ console.error(`[legion] claims/ready after role ${role} was ${reason} failed; the daemon's queued task stays undelivered until the next regain or boot: ${messageFor(error)}`);
31610
+ }
31611
+ });
31612
+ } catch (error) {
31613
+ console.error(`[legion] Go claim boot failed after claims/register registered ${claim.claimToken}; exiting so the daemon launches it again: ${messageFor(error)}`);
31614
+ state.exitProcess(1);
31615
+ }
31616
+ })();
31617
+ state.setBootstrap(bootstrap);
31618
+ try {
31619
+ await bootstrap;
31620
+ } catch (error) {
31621
+ state.setBootstrap(undefined);
31622
+ throw error;
31623
+ }
31624
+ }
31625
+
30549
31626
  // src/legion/tools.ts
30550
31627
  import { randomUUID as randomUUID2 } from "crypto";
30551
31628
 
@@ -30748,9 +31825,9 @@ function exitOnRegistrationRefusal(route, error) {
30748
31825
  }
30749
31826
  throw error;
30750
31827
  }
30751
- var READY_RETRY_ATTEMPTS = 3;
30752
- var READY_RETRY_DELAY_MS = 1000;
30753
- function isNetworkOrTimeoutError(error) {
31828
+ var READY_RETRY_ATTEMPTS2 = 3;
31829
+ var READY_RETRY_DELAY_MS2 = 1000;
31830
+ function isNetworkOrTimeoutError2(error) {
30754
31831
  if (!(error instanceof Error))
30755
31832
  return false;
30756
31833
  if (error.name === "NetworkError" || error.name === "TimeoutError")
@@ -30759,21 +31836,21 @@ function isNetworkOrTimeoutError(error) {
30759
31836
  return code === "ConnectionRefused" || code === "ConnectionTimeout" || code === "EAI_AGAIN" || code === "ECONNREFUSED" || code === "ECONNRESET" || code === "EHOSTUNREACH" || code === "ENETUNREACH" || code === "ENOTFOUND" || code === "ETIMEDOUT" || error instanceof TypeError && (error.message === "Failed to fetch" || error.message === "fetch failed");
30760
31837
  }
30761
31838
  var callReadyWithRetry = async (label, call) => {
30762
- for (let attempt = 1;attempt <= READY_RETRY_ATTEMPTS; attempt++) {
31839
+ for (let attempt = 1;attempt <= READY_RETRY_ATTEMPTS2; attempt++) {
30763
31840
  try {
30764
31841
  await call();
30765
31842
  return;
30766
31843
  } catch (error) {
30767
- const retryable = error instanceof LegionDaemonApiError ? error.status >= 500 && error.status < 600 : isNetworkOrTimeoutError(error);
31844
+ const retryable = error instanceof LegionDaemonApiError ? error.status >= 500 && error.status < 600 : isNetworkOrTimeoutError2(error);
30768
31845
  if (!retryable)
30769
31846
  throw error;
30770
- if (attempt === READY_RETRY_ATTEMPTS) {
31847
+ if (attempt === READY_RETRY_ATTEMPTS2) {
30771
31848
  console.error(`[legion] ${label} failed after ${attempt} attempts: ${messageFor(error)}`);
30772
31849
  throw error;
30773
31850
  }
30774
- console.error(`[legion] ${label} failed (attempt ${attempt}/${READY_RETRY_ATTEMPTS}), retrying: ${messageFor(error)}`);
31851
+ console.error(`[legion] ${label} failed (attempt ${attempt}/${READY_RETRY_ATTEMPTS2}), retrying: ${messageFor(error)}`);
30775
31852
  const retryDelay = Promise.withResolvers();
30776
- setTimeout(retryDelay.resolve, READY_RETRY_DELAY_MS);
31853
+ setTimeout(retryDelay.resolve, READY_RETRY_DELAY_MS2);
30777
31854
  await retryDelay.promise;
30778
31855
  }
30779
31856
  }
@@ -31185,6 +32262,21 @@ function legionExtension(pi) {
31185
32262
  pi.on("session_start", async (_event, context) => {
31186
32263
  if (await checkSubagentSession(context))
31187
32264
  return;
32265
+ if (process.env.LEGION_DAEMON_API === "go") {
32266
+ return bootstrapGoClaim(context, {
32267
+ capability: () => capability,
32268
+ setCapability: (next) => {
32269
+ capability = next;
32270
+ },
32271
+ bootstrap: () => bootstrap,
32272
+ setBootstrap: (next) => {
32273
+ bootstrap = next;
32274
+ },
32275
+ exitProcess,
32276
+ persistedTranscript,
32277
+ recordBootstrappedSession
32278
+ });
32279
+ }
31188
32280
  const classification = classifySession(process.env);
31189
32281
  switch (classification.kind) {
31190
32282
  case "controller":
@@ -265,8 +265,8 @@ later phase keeps it current rather than replacing it:
265
265
  resolved <thread URL>
266
266
  left open <thread URL> — newest reply by <login> is not an acceptance
267
267
 
268
- **Thermo:** thermonuclear-deep-review + thermonuclear-code-quality run once at <head-sha>:
269
- <verdict>. (omitted entirely on a docs-only PR — no thermo pass runs)
268
+ **Thermo:** `ce-simplify-code` once at <head-sha>: <0 applied | applied → new head <sha>>; thermonuclear pair at the final head <sha>:
269
+ <verdict>. (omitted entirely on a docs-only PR — there is no code for either pass, so neither runs)
270
270
 
271
271
  **E2E (implementer):** <surface> — ran `<command or run id>`, observed <result>, at head <sha>.
272
272
  Negative control: <deliberately broken input> → <refusal or failure observed>.
@@ -367,9 +367,22 @@ this proof.
367
367
  `E2E` line's head to the new SHA with
368
368
  `rebase re-check <old-sha> → <new-sha>: fingerprint unchanged, bare gates only`; the
369
369
  real-surface verification is not repeated. Different: a full test round.
370
+ - **The implementer runs `ce-simplify-code` once per pull request, after the last review round
371
+ closes and before the reviewer's final pass, when the diff touches runtime code; a docs-only
372
+ diff gets none.** It is scoped to the pull request's own diff, at the head where the last review
373
+ round closed: nothing applied leaves that head final; applied → the applied head is the final
374
+ head: CI runs on it, the pair runs once on it, and the E2E proof re-runs on it for the surface
375
+ the simplify diff touched (Sami, 2026-09-13: test on the real surface before merging, no
376
+ shortcuts — a refactor that "preserves behaviour" is a claim until it is executed). That cost is
377
+ why 0-applied is the expected outcome and a pass that applies is spent sparingly. At the applied
378
+ head the implementer re-cites the `CI` line and re-runs its own proof into `E2E (implementer)`,
379
+ and the tester re-runs its proof for the touched surface into `E2E (tester)`, before the
380
+ reviewer's final pass. Simplify is the last code change; the pair is the last review. Record it
381
+ in the `Thermo` line.
370
382
  - The reviewer verifies the `CI`, `Threads`, and `E2E` facts against GitHub directly —
371
383
  never from a handoff — then runs `task(agent="thermonuclear-deep-review")` and
372
- `task(agent="thermonuclear-code-quality")` once at that head and records the verdict.
384
+ `task(agent="thermonuclear-code-quality")` once at that head — the head the implementer's
385
+ simplify pass left final — and records the verdict.
373
386
  Approval is refused while either `E2E (implementer)` or `E2E (tester)` is missing: `REQUEST_CHANGES` naming the missing line.
374
387
  Skip the `Thermo` line entirely on a docs-only PR. Submit **one review per round** —
375
388
  `REQUEST_CHANGES` when any correctness finding stands, otherwise `COMMENT` while the head
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sjawhar/pi-legion-envoy",
3
- "version": "1.59.1",
3
+ "version": "1.60.1",
4
4
  "type": "module",
5
5
  "omp": {
6
6
  "extensions": [
@@ -12,7 +12,8 @@
12
12
  ]
13
13
  },
14
14
  "legion": {
15
- "daemonApiVersion": 8
15
+ "daemonApiVersion": 8,
16
+ "goDaemonApiVersion": 1
16
17
  },
17
18
  "repository": {
18
19
  "type": "git",