@chinhae/codex-connect-linux-x64 0.11.0 → 0.12.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.
@@ -105,16 +105,16 @@ var Diff = class {
105
105
  }
106
106
  }
107
107
  }
108
- addToPath(path5, added, removed, oldPosInc, options) {
109
- const last = path5.lastComponent;
108
+ addToPath(path7, added, removed, oldPosInc, options) {
109
+ const last = path7.lastComponent;
110
110
  if (last && !options.oneChangePerToken && last.added === added && last.removed === removed) {
111
111
  return {
112
- oldPos: path5.oldPos + oldPosInc,
112
+ oldPos: path7.oldPos + oldPosInc,
113
113
  lastComponent: { count: last.count + 1, added, removed, previousComponent: last.previousComponent }
114
114
  };
115
115
  } else {
116
116
  return {
117
- oldPos: path5.oldPos + oldPosInc,
117
+ oldPos: path7.oldPos + oldPosInc,
118
118
  lastComponent: { count: 1, added, removed, previousComponent: last }
119
119
  };
120
120
  }
@@ -514,9 +514,9 @@ function createTwoFilesPatch(oldFileName, newFileName, oldStr, newStr, oldHeader
514
514
  } }));
515
515
  }
516
516
  }
517
- function splitLines(text) {
518
- const hasTrailingNl = text.endsWith("\n");
519
- const result = text.split("\n").map((line) => line + "\n");
517
+ function splitLines(text2) {
518
+ const hasTrailingNl = text2.endsWith("\n");
519
+ const result = text2.split("\n").map((line) => line + "\n");
520
520
  if (hasTrailingNl) {
521
521
  result.pop();
522
522
  } else {
@@ -527,7 +527,7 @@ function splitLines(text) {
527
527
 
528
528
  // dist/omp-adapter.js
529
529
  import { randomUUID as randomUUID2 } from "node:crypto";
530
- import path4 from "node:path";
530
+ import path6 from "node:path";
531
531
 
532
532
  // ../../../node_modules/zod/v4/classic/external.js
533
533
  var external_exports = {};
@@ -1295,10 +1295,10 @@ function mergeDefs(...defs) {
1295
1295
  function cloneDef(schema) {
1296
1296
  return mergeDefs(schema._zod.def);
1297
1297
  }
1298
- function getElementAtPath(obj, path5) {
1299
- if (!path5)
1298
+ function getElementAtPath(obj, path7) {
1299
+ if (!path7)
1300
1300
  return obj;
1301
- return path5.reduce((acc, key) => acc?.[key], obj);
1301
+ return path7.reduce((acc, key) => acc?.[key], obj);
1302
1302
  }
1303
1303
  function promiseAllObject(promisesObj) {
1304
1304
  const keys = Object.keys(promisesObj);
@@ -1707,11 +1707,11 @@ function explicitlyAborted(x, startIndex = 0) {
1707
1707
  }
1708
1708
  return false;
1709
1709
  }
1710
- function prefixIssues(path5, issues) {
1710
+ function prefixIssues(path7, issues) {
1711
1711
  return issues.map((iss) => {
1712
1712
  var _a3;
1713
1713
  (_a3 = iss).path ?? (_a3.path = []);
1714
- iss.path.unshift(path5);
1714
+ iss.path.unshift(path7);
1715
1715
  return iss;
1716
1716
  });
1717
1717
  }
@@ -1858,16 +1858,16 @@ function flattenError(error51, mapper = (issue2) => issue2.message) {
1858
1858
  }
1859
1859
  function formatError(error51, mapper = (issue2) => issue2.message) {
1860
1860
  const fieldErrors = { _errors: [] };
1861
- const processError = (error52, path5 = []) => {
1861
+ const processError = (error52, path7 = []) => {
1862
1862
  for (const issue2 of error52.issues) {
1863
1863
  if (issue2.code === "invalid_union" && issue2.errors.length) {
1864
- issue2.errors.map((issues) => processError({ issues }, [...path5, ...issue2.path]));
1864
+ issue2.errors.map((issues) => processError({ issues }, [...path7, ...issue2.path]));
1865
1865
  } else if (issue2.code === "invalid_key") {
1866
- processError({ issues: issue2.issues }, [...path5, ...issue2.path]);
1866
+ processError({ issues: issue2.issues }, [...path7, ...issue2.path]);
1867
1867
  } else if (issue2.code === "invalid_element") {
1868
- processError({ issues: issue2.issues }, [...path5, ...issue2.path]);
1868
+ processError({ issues: issue2.issues }, [...path7, ...issue2.path]);
1869
1869
  } else {
1870
- const fullpath = [...path5, ...issue2.path];
1870
+ const fullpath = [...path7, ...issue2.path];
1871
1871
  if (fullpath.length === 0) {
1872
1872
  fieldErrors._errors.push(mapper(issue2));
1873
1873
  } else {
@@ -1894,17 +1894,17 @@ function formatError(error51, mapper = (issue2) => issue2.message) {
1894
1894
  }
1895
1895
  function treeifyError(error51, mapper = (issue2) => issue2.message) {
1896
1896
  const result = { errors: [] };
1897
- const processError = (error52, path5 = []) => {
1897
+ const processError = (error52, path7 = []) => {
1898
1898
  var _a3, _b;
1899
1899
  for (const issue2 of error52.issues) {
1900
1900
  if (issue2.code === "invalid_union" && issue2.errors.length) {
1901
- issue2.errors.map((issues) => processError({ issues }, [...path5, ...issue2.path]));
1901
+ issue2.errors.map((issues) => processError({ issues }, [...path7, ...issue2.path]));
1902
1902
  } else if (issue2.code === "invalid_key") {
1903
- processError({ issues: issue2.issues }, [...path5, ...issue2.path]);
1903
+ processError({ issues: issue2.issues }, [...path7, ...issue2.path]);
1904
1904
  } else if (issue2.code === "invalid_element") {
1905
- processError({ issues: issue2.issues }, [...path5, ...issue2.path]);
1905
+ processError({ issues: issue2.issues }, [...path7, ...issue2.path]);
1906
1906
  } else {
1907
- const fullpath = [...path5, ...issue2.path];
1907
+ const fullpath = [...path7, ...issue2.path];
1908
1908
  if (fullpath.length === 0) {
1909
1909
  result.errors.push(mapper(issue2));
1910
1910
  continue;
@@ -1936,8 +1936,8 @@ function treeifyError(error51, mapper = (issue2) => issue2.message) {
1936
1936
  }
1937
1937
  function toDotPath(_path) {
1938
1938
  const segs = [];
1939
- const path5 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
1940
- for (const seg of path5) {
1939
+ const path7 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
1940
+ for (const seg of path7) {
1941
1941
  if (typeof seg === "number")
1942
1942
  segs.push(`[${seg}]`);
1943
1943
  else if (typeof seg === "symbol")
@@ -5165,8 +5165,8 @@ function az_default() {
5165
5165
  }
5166
5166
 
5167
5167
  // ../../../node_modules/zod/v4/locales/be.js
5168
- function getBelarusianPlural(count, one, few, many) {
5169
- const absCount = Math.abs(count);
5168
+ function getBelarusianPlural(count3, one, few, many) {
5169
+ const absCount = Math.abs(count3);
5170
5170
  const lastDigit = absCount % 10;
5171
5171
  const lastTwoDigits = absCount % 100;
5172
5172
  if (lastTwoDigits >= 11 && lastTwoDigits <= 19) {
@@ -7244,8 +7244,8 @@ function hu_default() {
7244
7244
  }
7245
7245
 
7246
7246
  // ../../../node_modules/zod/v4/locales/hy.js
7247
- function getArmenianPlural(count, one, many) {
7248
- return Math.abs(count) === 1 ? one : many;
7247
+ function getArmenianPlural(count3, one, many) {
7248
+ return Math.abs(count3) === 1 ? one : many;
7249
7249
  }
7250
7250
  function withDefiniteArticle(word) {
7251
7251
  if (!word)
@@ -8167,8 +8167,8 @@ function ko_default() {
8167
8167
  }
8168
8168
 
8169
8169
  // ../../../node_modules/zod/v4/locales/lt.js
8170
- var capitalizeFirstCharacter = (text) => {
8171
- return text.charAt(0).toUpperCase() + text.slice(1);
8170
+ var capitalizeFirstCharacter = (text2) => {
8171
+ return text2.charAt(0).toUpperCase() + text2.slice(1);
8172
8172
  };
8173
8173
  function getUnitTypeFromNumber(number4) {
8174
8174
  const abs = Math.abs(number4);
@@ -9373,8 +9373,8 @@ function ro_default() {
9373
9373
  }
9374
9374
 
9375
9375
  // ../../../node_modules/zod/v4/locales/ru.js
9376
- function getRussianPlural(count, one, few, many) {
9377
- const absCount = Math.abs(count);
9376
+ function getRussianPlural(count3, one, few, many) {
9377
+ const absCount = Math.abs(count3);
9378
9378
  const lastDigit = absCount % 10;
9379
9379
  const lastTwoDigits = absCount % 100;
9380
9380
  if (lastTwoDigits >= 11 && lastTwoDigits <= 19) {
@@ -14629,13 +14629,13 @@ function resolveRef(ref, ctx) {
14629
14629
  if (!ref.startsWith("#")) {
14630
14630
  throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
14631
14631
  }
14632
- const path5 = ref.slice(1).split("/").filter(Boolean);
14633
- if (path5.length === 0) {
14632
+ const path7 = ref.slice(1).split("/").filter(Boolean);
14633
+ if (path7.length === 0) {
14634
14634
  return ctx.rootSchema;
14635
14635
  }
14636
14636
  const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
14637
- if (path5[0] === defsKey) {
14638
- const key = path5[1];
14637
+ if (path7[0] === defsKey) {
14638
+ const key = path7[1];
14639
14639
  if (!key || !ctx.defs[key]) {
14640
14640
  throw new Error(`Reference not found: ${ref}`);
14641
14641
  }
@@ -15151,6 +15151,304 @@ var hostTurnIdSchema = opaqueIdSchema.brand();
15151
15151
  var hostItemIdSchema = opaqueIdSchema.brand();
15152
15152
  var hostInteractionIdSchema = opaqueIdSchema.brand();
15153
15153
 
15154
+ // ../../shared-contracts/dist/harness-plugins.js
15155
+ var HARNESS_PLUGIN_MANIFEST_MAX_BYTES = 32 * 1024;
15156
+ var HARNESS_PLUGIN_ICON_MAX_BYTES = 128 * 1024;
15157
+ var HARNESS_PLUGIN_LIMIT = 128;
15158
+ var harnessPluginIdSchema = external_exports.string().min(1).max(128).regex(/^[a-z][a-z0-9]*(?:[._-][a-z0-9]+)*$/u).refine((id) => id !== "codex", "The official Codex identity is reserved").pipe(harnessIdSchema);
15159
+ var relativeResourceSchema = external_exports.string().min(1).max(512).refine((value) => !/[\\\u0000:#?]/u.test(value) && !value.startsWith("/") && !value.split("/").some((part) => part === ".." || part === ""), "Plugin resources must be relative paths inside the plugin");
15160
+ var documentationUrlSchema = external_exports.url().refine((value) => /^https:\/\/[^/?#@]+(?:[/?#]|$)/iu.test(value), "Plugin documentation links must be credential-free HTTPS URLs");
15161
+ var pluginPresentationShape = {
15162
+ id: harnessPluginIdSchema,
15163
+ name: external_exports.string().trim().min(1).max(128),
15164
+ version: external_exports.string().min(1).max(128),
15165
+ /** The factory accepts a persisted local entrypoint through its construction context. */
15166
+ launchCommand: external_exports.literal(true).optional(),
15167
+ links: external_exports.object({
15168
+ documentation: documentationUrlSchema.optional(),
15169
+ installation: documentationUrlSchema.optional()
15170
+ }).strict().optional()
15171
+ };
15172
+ var harnessPluginManifestSchema = external_exports.object({
15173
+ manifestVersion: external_exports.literal(1),
15174
+ ...pluginPresentationShape,
15175
+ adapterApiVersion: external_exports.number().int().positive(),
15176
+ entry: relativeResourceSchema,
15177
+ icon: relativeResourceSchema.optional()
15178
+ }).strict();
15179
+ var harnessPluginIconSchema = external_exports.string().max(Math.ceil(HARNESS_PLUGIN_ICON_MAX_BYTES / 3) * 4 + 64).regex(/^data:image\/(?:png|jpeg|webp|svg\+xml);base64,[A-Za-z0-9+/]+={0,2}$/u);
15180
+ var harnessPluginDescriptorSchema = external_exports.object({
15181
+ ...pluginPresentationShape,
15182
+ icon: harnessPluginIconSchema.optional()
15183
+ }).strict();
15184
+ var harnessPluginListParamsSchema = external_exports.object({}).strict();
15185
+ var harnessPluginListResultSchema = external_exports.object({
15186
+ plugins: external_exports.array(harnessPluginDescriptorSchema).max(HARNESS_PLUGIN_LIMIT)
15187
+ }).strict();
15188
+ var harnessPluginConfigurationSchema = external_exports.object({
15189
+ version: external_exports.literal(1),
15190
+ enabled: external_exports.array(harnessPluginIdSchema).max(HARNESS_PLUGIN_LIMIT)
15191
+ }).strict().refine((value) => new Set(value.enabled).size === value.enabled.length, {
15192
+ message: "Enabled plugin IDs must be unique",
15193
+ path: ["enabled"]
15194
+ });
15195
+
15196
+ // ../../shared-contracts/dist/local-usage.js
15197
+ var LOCAL_USAGE_CUSTOM_RANGE_MAX_DAYS = 3660;
15198
+ var LOCAL_USAGE_DAILY_MAX_LENGTH = LOCAL_USAGE_CUSTOM_RANGE_MAX_DAYS + 1;
15199
+ var LOCAL_USAGE_HARNESS_MAX_LENGTH = 128;
15200
+ var LOCAL_USAGE_HARNESS_NAME_MAX_LENGTH = 128;
15201
+ var LOCAL_USAGE_PROVIDER_MAX_LENGTH = 128;
15202
+ var LOCAL_USAGE_PROVIDER_NAME_MAX_LENGTH = 1024;
15203
+ var LOCAL_USAGE_PROJECT_MAX_LENGTH = 1e3;
15204
+ var LOCAL_USAGE_PROJECT_NAME_MAX_LENGTH = 1024;
15205
+ var LOCAL_USAGE_TIME_ZONE_MAX_LENGTH = 64;
15206
+ var DAY_MS = 864e5;
15207
+ function dateValue(value) {
15208
+ return Date.parse(`${value}T00:00:00.000Z`);
15209
+ }
15210
+ var localUsageDateSchema = external_exports.string().regex(/^\d{4}-\d{2}-\d{2}$/u).refine((value) => {
15211
+ const time3 = dateValue(value);
15212
+ return Number.isFinite(time3) && new Date(time3).toISOString().slice(0, 10) === value;
15213
+ }, "Invalid calendar date");
15214
+ var timeZoneSchema = external_exports.string().min(1).max(LOCAL_USAGE_TIME_ZONE_MAX_LENGTH).refine((value) => {
15215
+ try {
15216
+ new Intl.DateTimeFormat("en-US", { timeZone: value });
15217
+ return true;
15218
+ } catch {
15219
+ return false;
15220
+ }
15221
+ }, "Unknown time zone");
15222
+ var localUsagePeriodSchema = external_exports.discriminatedUnion("kind", [
15223
+ external_exports.strictObject({ kind: external_exports.literal("day") }),
15224
+ // Weeks start on Monday.
15225
+ external_exports.strictObject({ kind: external_exports.literal("week") }),
15226
+ external_exports.strictObject({ kind: external_exports.literal("month") }),
15227
+ // The first day of the month 23 months ago through today.
15228
+ external_exports.strictObject({ kind: external_exports.literal("total") }),
15229
+ external_exports.strictObject({
15230
+ kind: external_exports.literal("custom"),
15231
+ from: localUsageDateSchema,
15232
+ to: localUsageDateSchema
15233
+ }).superRefine((period, context) => {
15234
+ const days = (dateValue(period.to) - dateValue(period.from)) / DAY_MS;
15235
+ if (days < 0) {
15236
+ context.addIssue({ code: "custom", path: ["to"], message: "Range ends before it starts" });
15237
+ } else if (days >= LOCAL_USAGE_CUSTOM_RANGE_MAX_DAYS) {
15238
+ context.addIssue({ code: "custom", path: ["to"], message: "Range is too long" });
15239
+ }
15240
+ })
15241
+ ]);
15242
+ var localUsageQueryParamsSchema = external_exports.strictObject({
15243
+ period: localUsagePeriodSchema,
15244
+ /** IANA zone used to assign usage to calendar days. */
15245
+ timeZone: timeZoneSchema,
15246
+ /** Read new native records before answering; otherwise reuse this Host's last read. */
15247
+ refresh: external_exports.boolean()
15248
+ });
15249
+ var countSchema = external_exports.number().int().nonnegative().safe();
15250
+ var tokenTotalsShape = {
15251
+ total: countSchema,
15252
+ /** Input tokens excluding cache reads and writes. */
15253
+ input: countSchema,
15254
+ cacheRead: countSchema,
15255
+ cacheWrite: countSchema,
15256
+ output: countSchema,
15257
+ reasoning: countSchema
15258
+ };
15259
+ var usageHarnessIdSchema = external_exports.union([external_exports.literal("codex"), harnessPluginIdSchema]);
15260
+ var localUsageViewSchema = external_exports.strictObject({
15261
+ status: external_exports.literal("ready"),
15262
+ range: external_exports.strictObject({ from: localUsageDateSchema, to: localUsageDateSchema }),
15263
+ totals: external_exports.strictObject({ ...tokenTotalsShape, conversations: countSchema }).refine((totals) => totals.total === totals.input + totals.cacheRead + totals.cacheWrite + totals.output + totals.reasoning, { path: ["total"], message: "Total must equal its parts" }),
15264
+ /**
15265
+ * Estimated Cost of the range in USD: Harness-reported cost where present, otherwise public
15266
+ * model prices applied when queried. Models without a price add 0.
15267
+ */
15268
+ estimatedCostUsd: external_exports.number().nonnegative().finite(),
15269
+ /** Distinct Models with usage in the range, across Harnesses. */
15270
+ models: countSchema,
15271
+ harnesses: external_exports.array(external_exports.strictObject({
15272
+ harnessId: usageHarnessIdSchema,
15273
+ name: external_exports.string().trim().min(1).max(LOCAL_USAGE_HARNESS_NAME_MAX_LENGTH),
15274
+ totalTokens: countSchema,
15275
+ models: countSchema,
15276
+ /** Providers the Harness recorded, by usage; empty when it records none. */
15277
+ providers: external_exports.array(external_exports.strictObject({
15278
+ provider: external_exports.string().min(1).max(LOCAL_USAGE_PROVIDER_NAME_MAX_LENGTH),
15279
+ totalTokens: countSchema,
15280
+ models: countSchema
15281
+ })).max(LOCAL_USAGE_PROVIDER_MAX_LENGTH)
15282
+ }).refine((harness) => harness.providers.reduce((sum, provider) => sum + provider.totalTokens, 0) <= harness.totalTokens, { path: ["providers"], message: "Providers are part of their Harness" })).max(LOCAL_USAGE_HARNESS_MAX_LENGTH),
15283
+ /** Days with usage, newest first. `cacheRead` is the daily cache column. */
15284
+ daily: external_exports.array(external_exports.strictObject({
15285
+ date: localUsageDateSchema,
15286
+ total: countSchema,
15287
+ input: countSchema,
15288
+ output: countSchema,
15289
+ cacheRead: countSchema,
15290
+ reasoning: countSchema,
15291
+ conversations: countSchema
15292
+ })).max(LOCAL_USAGE_DAILY_MAX_LENGTH),
15293
+ /**
15294
+ * Usage with a known working directory, by project, most used first: `owner/repo` from the Git
15295
+ * remote, otherwise the folder name. Only the most used projects are listed.
15296
+ */
15297
+ projects: external_exports.array(external_exports.strictObject({
15298
+ project: external_exports.string().min(1).max(LOCAL_USAGE_PROJECT_NAME_MAX_LENGTH),
15299
+ totalTokens: countSchema,
15300
+ /** Harnesses used in the project, most used first. */
15301
+ harnessIds: external_exports.array(usageHarnessIdSchema).min(1).max(LOCAL_USAGE_HARNESS_MAX_LENGTH)
15302
+ })).max(LOCAL_USAGE_PROJECT_MAX_LENGTH),
15303
+ /** Harnesses whose last read failed; their totals are from their last successful read. */
15304
+ failures: external_exports.array(external_exports.strictObject({
15305
+ harnessId: usageHarnessIdSchema,
15306
+ name: external_exports.string().trim().min(1).max(LOCAL_USAGE_HARNESS_NAME_MAX_LENGTH)
15307
+ })).max(LOCAL_USAGE_HARNESS_MAX_LENGTH),
15308
+ /**
15309
+ * Independent of the selected period. Windows end today; an active day has tokens.
15310
+ * `dailyAverage` is the last 30 days' total over their active days, rounded.
15311
+ */
15312
+ stats: external_exports.strictObject({
15313
+ last7Days: countSchema,
15314
+ last30Days: countSchema,
15315
+ dailyAverage: countSchema,
15316
+ /** Active days across all counted history, not only the "total" period. */
15317
+ activeDays: countSchema,
15318
+ firstActiveDate: localUsageDateSchema.nullable()
15319
+ }).superRefine((stats, context) => {
15320
+ if (stats.firstActiveDate === null !== (stats.activeDays === 0)) {
15321
+ context.addIssue({
15322
+ code: "custom",
15323
+ path: ["firstActiveDate"],
15324
+ message: "First active date exists exactly when there are active days"
15325
+ });
15326
+ }
15327
+ if (stats.last7Days > stats.last30Days) {
15328
+ context.addIssue({
15329
+ code: "custom",
15330
+ path: ["last7Days"],
15331
+ message: "The last 7 days are part of the last 30 days"
15332
+ });
15333
+ }
15334
+ })
15335
+ });
15336
+ var localUsageReadingSchema = external_exports.strictObject({
15337
+ status: external_exports.literal("reading"),
15338
+ /** Native record files read so far by the sources that report progress. */
15339
+ progress: external_exports.strictObject({ processed: countSchema, total: countSchema }).refine((progress) => progress.processed <= progress.total, {
15340
+ path: ["processed"],
15341
+ message: "Processed files are part of the total"
15342
+ })
15343
+ });
15344
+ var localUsageQueryResultSchema = external_exports.discriminatedUnion("status", [
15345
+ localUsageReadingSchema,
15346
+ localUsageViewSchema
15347
+ ]);
15348
+
15349
+ // ../../shared-contracts/dist/harness-session-import.js
15350
+ var HARNESS_SESSION_IMPORT_ID_MAX_LENGTH = 1024;
15351
+ var HARNESS_SESSION_IMPORT_CWD_MAX_LENGTH = 16384;
15352
+ var HARNESS_SESSION_IMPORT_TITLE_MAX_LENGTH = 4096;
15353
+ var HARNESS_SESSION_IMPORT_LIST_MAX_LENGTH = 1e3;
15354
+ var HARNESS_SESSION_IMPORT_UPDATED_AT_MAX = 864e13;
15355
+ var nonBlankTextSchema = external_exports.string().refine((value) => value.trim().length > 0, "Value must not be empty or whitespace").refine((value) => !value.includes("\0"), "Value must not contain NUL");
15356
+ var harnessSessionImportIdSchema = nonBlankTextSchema.max(HARNESS_SESSION_IMPORT_ID_MAX_LENGTH);
15357
+ var harnessSessionImportCandidateSchema = external_exports.object({
15358
+ nativeSessionId: harnessSessionImportIdSchema,
15359
+ title: nonBlankTextSchema.max(HARNESS_SESSION_IMPORT_TITLE_MAX_LENGTH).nullable(),
15360
+ updatedAt: external_exports.number().int().nonnegative().max(HARNESS_SESSION_IMPORT_UPDATED_AT_MAX),
15361
+ cwd: nonBlankTextSchema.max(HARNESS_SESSION_IMPORT_CWD_MAX_LENGTH),
15362
+ // Native file discovery cannot reliably observe another process's activity.
15363
+ running: external_exports.boolean().nullable()
15364
+ }).strict();
15365
+ var harnessSessionImportSourcesParamsSchema = external_exports.object({}).strict();
15366
+ var harnessSessionImportSourcesResultSchema = external_exports.object({
15367
+ harnesses: external_exports.array(external_exports.object({
15368
+ harnessId: harnessPluginIdSchema,
15369
+ name: nonBlankTextSchema.max(128)
15370
+ }).strict()).max(128)
15371
+ }).strict();
15372
+ var harnessSessionListParamsSchema = external_exports.object({
15373
+ harnessId: harnessPluginIdSchema,
15374
+ query: external_exports.string().trim().max(4096).refine((value) => !value.includes("\0")).optional(),
15375
+ offset: external_exports.number().int().nonnegative().safe().optional(),
15376
+ limit: external_exports.number().int().min(1).max(HARNESS_SESSION_IMPORT_LIST_MAX_LENGTH).optional()
15377
+ }).strict();
15378
+ var harnessSessionListResultSchema = external_exports.object({
15379
+ candidates: external_exports.array(harnessSessionImportCandidateSchema).max(HARNESS_SESSION_IMPORT_LIST_MAX_LENGTH),
15380
+ total: external_exports.number().int().nonnegative().safe()
15381
+ }).strict();
15382
+ var harnessSessionImportParamsSchema = external_exports.object({
15383
+ harnessId: harnessPluginIdSchema,
15384
+ nativeSessionId: harnessSessionImportIdSchema
15385
+ }).strict();
15386
+ var harnessSessionImportResultSchema = external_exports.object({
15387
+ threadId: nonBlankTextSchema.max(1024).pipe(hostThreadIdSchema)
15388
+ }).strict();
15389
+
15390
+ // ../../shared-contracts/dist/local-sessions.js
15391
+ var LOCAL_SESSIONS_MAX_LENGTH = 1e5;
15392
+ var LOCAL_SESSIONS_MODEL_MAX_LENGTH = 1024;
15393
+ var LOCAL_SESSIONS_RESUME_COMMAND_MAX_LENGTH = 256;
15394
+ var LOCAL_SESSIONS_RESUME_COMMAND_PATTERN = /^[A-Za-z0-9][A-Za-z0-9 ._:=/-]*$/u;
15395
+ var countSchema2 = external_exports.number().int().nonnegative().safe();
15396
+ var timeSchema = countSchema2;
15397
+ var sessionHarnessIdSchema = external_exports.union([external_exports.literal("codex"), harnessPluginIdSchema]);
15398
+ var harnessNameSchema = external_exports.string().trim().min(1).max(LOCAL_USAGE_HARNESS_NAME_MAX_LENGTH);
15399
+ var localSessionsQueryParamsSchema = external_exports.strictObject({
15400
+ /** Read native records added since the last read before answering. */
15401
+ refresh: external_exports.boolean()
15402
+ });
15403
+ var localSessionSchema = external_exports.strictObject({
15404
+ harnessId: sessionHarnessIdSchema,
15405
+ nativeSessionId: harnessSessionImportIdSchema,
15406
+ /** The Harness's own name for the Session; null shows the project instead. */
15407
+ title: external_exports.string().min(1).max(HARNESS_SESSION_IMPORT_TITLE_MAX_LENGTH).nullable(),
15408
+ /** Working directory, used to copy the project path or a resume command. */
15409
+ cwd: external_exports.string().min(1).max(HARNESS_SESSION_IMPORT_CWD_MAX_LENGTH).nullable(),
15410
+ /** `owner/repo` from the Git remote, otherwise the folder name. */
15411
+ project: external_exports.string().min(1).max(LOCAL_USAGE_PROJECT_NAME_MAX_LENGTH).nullable(),
15412
+ model: external_exports.string().min(1).max(LOCAL_SESSIONS_MODEL_MAX_LENGTH).nullable(),
15413
+ startedAt: timeSchema.nullable(),
15414
+ lastActivityAt: timeSchema,
15415
+ /** Null for Sessions known only from Session import, which has no native usage. */
15416
+ activeMs: countSchema2.nullable(),
15417
+ usage: external_exports.strictObject({
15418
+ /** Includes folded subagents. */
15419
+ totalTokens: countSchema2,
15420
+ estimatedCostUsd: external_exports.number().nonnegative().finite()
15421
+ }).nullable(),
15422
+ turns: countSchema2.nullable(),
15423
+ edits: countSchema2.nullable(),
15424
+ /** Subagent and child Sessions folded into this one. */
15425
+ subagents: countSchema2,
15426
+ /** The Thread this Session is already mapped to. */
15427
+ threadId: hostThreadIdSchema.nullable(),
15428
+ /** Whether Resume can open it as a Thread. */
15429
+ resumable: external_exports.boolean(),
15430
+ /** Null when the Harness cannot tell whether another client is running it. */
15431
+ running: external_exports.boolean().nullable(),
15432
+ /**
15433
+ * Resumes the Session in its Harness's own CLI when run from `cwd`; null when the Harness has
15434
+ * no such command or the Session ID is not safe to paste into a terminal.
15435
+ */
15436
+ resumeCommand: external_exports.string().max(LOCAL_SESSIONS_RESUME_COMMAND_MAX_LENGTH).regex(LOCAL_SESSIONS_RESUME_COMMAND_PATTERN).nullable()
15437
+ });
15438
+ var localSessionsViewSchema = external_exports.strictObject({
15439
+ status: external_exports.literal("ready"),
15440
+ /** Most recently active first. */
15441
+ sessions: external_exports.array(localSessionSchema).max(LOCAL_SESSIONS_MAX_LENGTH),
15442
+ /** Harnesses with listed Sessions, by name. */
15443
+ harnesses: external_exports.array(external_exports.strictObject({ harnessId: sessionHarnessIdSchema, name: harnessNameSchema })).max(LOCAL_USAGE_HARNESS_MAX_LENGTH),
15444
+ /** Sources whose last read failed; their Sessions are from their last successful read. */
15445
+ failures: external_exports.array(external_exports.strictObject({ harnessId: sessionHarnessIdSchema, name: harnessNameSchema })).max(LOCAL_USAGE_HARNESS_MAX_LENGTH)
15446
+ });
15447
+ var localSessionsQueryResultSchema = external_exports.discriminatedUnion("status", [
15448
+ localUsageReadingSchema,
15449
+ localSessionsViewSchema
15450
+ ]);
15451
+
15154
15452
  // ../../shared-contracts/dist/thread-usage.js
15155
15453
  var nonNegativeSafeIntegerSchema = external_exports.number().int().safe().nonnegative();
15156
15454
  var finiteNonNegativeNumberSchema = external_exports.number().finite().nonnegative();
@@ -15214,10 +15512,18 @@ var accountCreditsProductUsageSchema = external_exports.object({
15214
15512
  usagePercent: usagePercentSchema,
15215
15513
  resetsAt: external_exports.string().min(1).optional()
15216
15514
  }).strict();
15515
+ var ACCOUNT_RESET_CREDITS_MAX_LENGTH = 32;
15516
+ var ACCOUNT_RESET_CREDIT_TIME_MAX_LENGTH = 64;
15517
+ var resetCreditTimeSchema = external_exports.string().min(1).max(ACCOUNT_RESET_CREDIT_TIME_MAX_LENGTH);
15518
+ var accountResetCreditSchema = external_exports.object({
15519
+ expiresAt: resetCreditTimeSchema,
15520
+ grantedAt: resetCreditTimeSchema.optional()
15521
+ }).strict();
15217
15522
  var accountResetCreditsSchema = external_exports.object({
15218
15523
  availableCount: external_exports.number().int().safe().positive(),
15219
15524
  nextExpiresAt: external_exports.string().min(1).optional(),
15220
- expiresAt: external_exports.array(external_exports.string().min(1)).min(1).max(32).optional()
15525
+ expiresAt: external_exports.array(external_exports.string().min(1)).min(1).max(ACCOUNT_RESET_CREDITS_MAX_LENGTH).optional(),
15526
+ credits: external_exports.array(accountResetCreditSchema).min(1).max(ACCOUNT_RESET_CREDITS_MAX_LENGTH).optional()
15221
15527
  }).strict();
15222
15528
  var accountCreditsSnapshotSchema = external_exports.object({
15223
15529
  /** Native label when the primary limit is scoped to a model or product group. */
@@ -15337,14 +15643,14 @@ var HARNESS_PERMISSION_MODE_ID_MAX_LENGTH = 128;
15337
15643
  var HARNESS_PERMISSION_MODE_LABEL_MAX_LENGTH = 256;
15338
15644
  var HARNESS_PERMISSION_MODE_DESCRIPTION_MAX_LENGTH = 1024;
15339
15645
  var HARNESS_PERMISSION_MODE_CATALOG_MAX_LENGTH = 32;
15340
- var nonBlankTextSchema = external_exports.string().refine((value) => value.trim().length > 0, {
15646
+ var nonBlankTextSchema2 = external_exports.string().refine((value) => value.trim().length > 0, {
15341
15647
  message: "Value must not be empty or whitespace"
15342
15648
  });
15343
- var harnessPermissionModeIdSchema = nonBlankTextSchema.max(HARNESS_PERMISSION_MODE_ID_MAX_LENGTH).regex(/^[A-Za-z0-9._~-]+$/u, "Permission Mode ID must use transport-safe characters").brand();
15649
+ var harnessPermissionModeIdSchema = nonBlankTextSchema2.max(HARNESS_PERMISSION_MODE_ID_MAX_LENGTH).regex(/^[A-Za-z0-9._~-]+$/u, "Permission Mode ID must use transport-safe characters").brand();
15344
15650
  var harnessPermissionModeSchema = external_exports.object({
15345
15651
  id: harnessPermissionModeIdSchema,
15346
- label: nonBlankTextSchema.max(HARNESS_PERMISSION_MODE_LABEL_MAX_LENGTH),
15347
- description: nonBlankTextSchema.max(HARNESS_PERMISSION_MODE_DESCRIPTION_MAX_LENGTH).optional(),
15652
+ label: nonBlankTextSchema2.max(HARNESS_PERMISSION_MODE_LABEL_MAX_LENGTH),
15653
+ description: nonBlankTextSchema2.max(HARNESS_PERMISSION_MODE_DESCRIPTION_MAX_LENGTH).optional(),
15348
15654
  dangerous: external_exports.boolean().optional()
15349
15655
  }).strict();
15350
15656
  var harnessPermissionModeCatalogSchema = external_exports.object({
@@ -15380,22 +15686,22 @@ var HARNESS_MODEL_REF_MAX_LENGTH = 512;
15380
15686
  var HARNESS_MODEL_LABEL_MAX_LENGTH = 256;
15381
15687
  var HARNESS_THINKING_OPTION_ID_MAX_LENGTH = 128;
15382
15688
  var THREAD_OWNERSHIP_LIST_MAX_LENGTH = 100;
15383
- var nonBlankTextSchema2 = external_exports.string().refine((value) => value.trim().length > 0, {
15689
+ var nonBlankTextSchema3 = external_exports.string().refine((value) => value.trim().length > 0, {
15384
15690
  message: "Value must not be empty or whitespace"
15385
15691
  });
15386
- var harnessModelRefIdSchema = nonBlankTextSchema2.max(HARNESS_MODEL_REF_MAX_LENGTH).regex(/^[A-Za-z0-9._~-]+$/u, "Model Ref must use transport-safe opaque characters").brand();
15692
+ var harnessModelRefIdSchema = nonBlankTextSchema3.max(HARNESS_MODEL_REF_MAX_LENGTH).regex(/^[A-Za-z0-9._~-]+$/u, "Model Ref must use transport-safe opaque characters").brand();
15387
15693
  var harnessModelRefSchema = external_exports.object({
15388
15694
  id: harnessModelRefIdSchema
15389
15695
  }).strict();
15390
- var harnessThinkingOptionIdSchema = nonBlankTextSchema2.max(HARNESS_THINKING_OPTION_ID_MAX_LENGTH).regex(/^[A-Za-z0-9._~-]+$/u, "Thinking option ID must use transport-safe characters").brand();
15391
- var harnessResolvedModelLabelSchema = nonBlankTextSchema2.max(HARNESS_MODEL_LABEL_MAX_LENGTH);
15696
+ var harnessThinkingOptionIdSchema = nonBlankTextSchema3.max(HARNESS_THINKING_OPTION_ID_MAX_LENGTH).regex(/^[A-Za-z0-9._~-]+$/u, "Thinking option ID must use transport-safe characters").brand();
15697
+ var harnessResolvedModelLabelSchema = nonBlankTextSchema3.max(HARNESS_MODEL_LABEL_MAX_LENGTH);
15392
15698
  var harnessThinkingOptionSchema = external_exports.object({
15393
15699
  id: harnessThinkingOptionIdSchema,
15394
- label: nonBlankTextSchema2.max(HARNESS_MODEL_LABEL_MAX_LENGTH)
15700
+ label: nonBlankTextSchema3.max(HARNESS_MODEL_LABEL_MAX_LENGTH)
15395
15701
  }).strict();
15396
15702
  var harnessModelSchema = external_exports.object({
15397
15703
  ref: harnessModelRefSchema,
15398
- label: nonBlankTextSchema2.max(HARNESS_MODEL_LABEL_MAX_LENGTH),
15704
+ label: nonBlankTextSchema3.max(HARNESS_MODEL_LABEL_MAX_LENGTH),
15399
15705
  resolvedModelLabel: harnessResolvedModelLabelSchema.optional(),
15400
15706
  supportedThinkingOptionIds: external_exports.array(harnessThinkingOptionIdSchema).optional()
15401
15707
  }).strict();
@@ -15532,7 +15838,7 @@ var harnessInspectionSchema = external_exports.union([
15532
15838
  ]);
15533
15839
  var harnessInspectParamsSchema = external_exports.object({
15534
15840
  harnessId: harnessIdSchema,
15535
- cwd: nonBlankTextSchema2.max(16384).optional(),
15841
+ cwd: nonBlankTextSchema3.max(16384).optional(),
15536
15842
  refresh: external_exports.boolean().optional()
15537
15843
  }).strict();
15538
15844
  var harnessWebUiOpenParamsSchema = external_exports.object({
@@ -15556,8 +15862,8 @@ var codexThreadInspectionSchema = external_exports.object({
15556
15862
  }).strict();
15557
15863
  var externalThreadInspectionSchema = external_exports.object({
15558
15864
  owner: external_exports.literal("external"),
15559
- harnessId: nonBlankTextSchema2.max(256),
15560
- transportModelId: nonBlankTextSchema2.max(1024),
15865
+ harnessId: nonBlankTextSchema3.max(256),
15866
+ transportModelId: nonBlankTextSchema3.max(1024),
15561
15867
  effectiveModel: harnessModelRefSchema.optional(),
15562
15868
  resolvedModelLabel: harnessResolvedModelLabelSchema.optional(),
15563
15869
  effectiveThinkingOptionId: harnessThinkingOptionIdSchema.optional(),
@@ -15615,48 +15921,6 @@ var threadOwnershipListResultSchema = external_exports.object({
15615
15921
  }
15616
15922
  });
15617
15923
 
15618
- // ../../shared-contracts/dist/harness-plugins.js
15619
- var HARNESS_PLUGIN_MANIFEST_MAX_BYTES = 32 * 1024;
15620
- var HARNESS_PLUGIN_ICON_MAX_BYTES = 128 * 1024;
15621
- var HARNESS_PLUGIN_LIMIT = 128;
15622
- var harnessPluginIdSchema = external_exports.string().min(1).max(128).regex(/^[a-z][a-z0-9]*(?:[._-][a-z0-9]+)*$/u).refine((id) => id !== "codex", "The official Codex identity is reserved").pipe(harnessIdSchema);
15623
- var relativeResourceSchema = external_exports.string().min(1).max(512).refine((value) => !/[\\\u0000:#?]/u.test(value) && !value.startsWith("/") && !value.split("/").some((part) => part === ".." || part === ""), "Plugin resources must be relative paths inside the plugin");
15624
- var documentationUrlSchema = external_exports.url().refine((value) => /^https:\/\/[^/?#@]+(?:[/?#]|$)/iu.test(value), "Plugin documentation links must be credential-free HTTPS URLs");
15625
- var pluginPresentationShape = {
15626
- id: harnessPluginIdSchema,
15627
- name: external_exports.string().trim().min(1).max(128),
15628
- version: external_exports.string().min(1).max(128),
15629
- /** The factory accepts a persisted local entrypoint through its construction context. */
15630
- launchCommand: external_exports.literal(true).optional(),
15631
- links: external_exports.object({
15632
- documentation: documentationUrlSchema.optional(),
15633
- installation: documentationUrlSchema.optional()
15634
- }).strict().optional()
15635
- };
15636
- var harnessPluginManifestSchema = external_exports.object({
15637
- manifestVersion: external_exports.literal(1),
15638
- ...pluginPresentationShape,
15639
- adapterApiVersion: external_exports.number().int().positive(),
15640
- entry: relativeResourceSchema,
15641
- icon: relativeResourceSchema.optional()
15642
- }).strict();
15643
- var harnessPluginIconSchema = external_exports.string().max(Math.ceil(HARNESS_PLUGIN_ICON_MAX_BYTES / 3) * 4 + 64).regex(/^data:image\/(?:png|jpeg|webp|svg\+xml);base64,[A-Za-z0-9+/]+={0,2}$/u);
15644
- var harnessPluginDescriptorSchema = external_exports.object({
15645
- ...pluginPresentationShape,
15646
- icon: harnessPluginIconSchema.optional()
15647
- }).strict();
15648
- var harnessPluginListParamsSchema = external_exports.object({}).strict();
15649
- var harnessPluginListResultSchema = external_exports.object({
15650
- plugins: external_exports.array(harnessPluginDescriptorSchema).max(HARNESS_PLUGIN_LIMIT)
15651
- }).strict();
15652
- var harnessPluginConfigurationSchema = external_exports.object({
15653
- version: external_exports.literal(1),
15654
- enabled: external_exports.array(harnessPluginIdSchema).max(HARNESS_PLUGIN_LIMIT)
15655
- }).strict().refine((value) => new Set(value.enabled).size === value.enabled.length, {
15656
- message: "Enabled plugin IDs must be unique",
15657
- path: ["enabled"]
15658
- });
15659
-
15660
15924
  // ../../shared-contracts/dist/harness-route.js
15661
15925
  var harnessPluginRouteSchema = external_exports.object({
15662
15926
  harnessId: harnessPluginIdSchema,
@@ -15680,7 +15944,7 @@ var harnessLaunchSettingsSchema = external_exports.object({
15680
15944
 
15681
15945
  // ../../shared-contracts/dist/codex-accounts.js
15682
15946
  var accountIdSchema = external_exports.string().min(1).max(256).regex(/^[A-Za-z0-9._~-]+$/u);
15683
- var nonBlankTextSchema3 = external_exports.string().trim().min(1);
15947
+ var nonBlankTextSchema4 = external_exports.string().trim().min(1);
15684
15948
  var codexAccountPlanTypeSchema = external_exports.enum([
15685
15949
  "free",
15686
15950
  "go",
@@ -15702,7 +15966,7 @@ var codexAccountPlanTypeSchema = external_exports.enum([
15702
15966
  ]);
15703
15967
  var codexAccountSchema = external_exports.object({
15704
15968
  accountId: accountIdSchema,
15705
- label: nonBlankTextSchema3.max(256),
15969
+ label: nonBlankTextSchema4.max(256),
15706
15970
  email: external_exports.string().email().max(320).optional(),
15707
15971
  planType: codexAccountPlanTypeSchema.optional()
15708
15972
  }).strict();
@@ -15712,7 +15976,7 @@ var codexAccountListResultSchema = external_exports.object({
15712
15976
  currentAccountId: accountIdSchema.nullable(),
15713
15977
  phase: codexAccountPhaseSchema,
15714
15978
  revision: external_exports.number().int().nonnegative(),
15715
- instanceId: nonBlankTextSchema3.max(1024).optional(),
15979
+ instanceId: nonBlankTextSchema4.max(1024).optional(),
15716
15980
  accounts: external_exports.array(codexAccountSchema).max(1)
15717
15981
  }).strict();
15718
15982
  var codexAccountUsageParamsSchema = external_exports.object({ accountId: accountIdSchema, refresh: external_exports.boolean().optional() }).strict();
@@ -15724,47 +15988,6 @@ var codexAccountUsageResultSchema = external_exports.object({
15724
15988
  observedAt: external_exports.string().datetime().nullable()
15725
15989
  }).strict();
15726
15990
 
15727
- // ../../shared-contracts/dist/harness-session-import.js
15728
- var HARNESS_SESSION_IMPORT_ID_MAX_LENGTH = 1024;
15729
- var HARNESS_SESSION_IMPORT_CWD_MAX_LENGTH = 16384;
15730
- var HARNESS_SESSION_IMPORT_TITLE_MAX_LENGTH = 4096;
15731
- var HARNESS_SESSION_IMPORT_LIST_MAX_LENGTH = 1e3;
15732
- var HARNESS_SESSION_IMPORT_UPDATED_AT_MAX = 864e13;
15733
- var nonBlankTextSchema4 = external_exports.string().refine((value) => value.trim().length > 0, "Value must not be empty or whitespace").refine((value) => !value.includes("\0"), "Value must not contain NUL");
15734
- var harnessSessionImportIdSchema = nonBlankTextSchema4.max(HARNESS_SESSION_IMPORT_ID_MAX_LENGTH);
15735
- var harnessSessionImportCandidateSchema = external_exports.object({
15736
- nativeSessionId: harnessSessionImportIdSchema,
15737
- title: nonBlankTextSchema4.max(HARNESS_SESSION_IMPORT_TITLE_MAX_LENGTH).nullable(),
15738
- updatedAt: external_exports.number().int().nonnegative().max(HARNESS_SESSION_IMPORT_UPDATED_AT_MAX),
15739
- cwd: nonBlankTextSchema4.max(HARNESS_SESSION_IMPORT_CWD_MAX_LENGTH),
15740
- // Native file discovery cannot reliably observe another process's activity.
15741
- running: external_exports.boolean().nullable()
15742
- }).strict();
15743
- var harnessSessionImportSourcesParamsSchema = external_exports.object({}).strict();
15744
- var harnessSessionImportSourcesResultSchema = external_exports.object({
15745
- harnesses: external_exports.array(external_exports.object({
15746
- harnessId: harnessPluginIdSchema,
15747
- name: nonBlankTextSchema4.max(128)
15748
- }).strict()).max(128)
15749
- }).strict();
15750
- var harnessSessionListParamsSchema = external_exports.object({
15751
- harnessId: harnessPluginIdSchema,
15752
- query: external_exports.string().trim().max(4096).refine((value) => !value.includes("\0")).optional(),
15753
- offset: external_exports.number().int().nonnegative().safe().optional(),
15754
- limit: external_exports.number().int().min(1).max(HARNESS_SESSION_IMPORT_LIST_MAX_LENGTH).optional()
15755
- }).strict();
15756
- var harnessSessionListResultSchema = external_exports.object({
15757
- candidates: external_exports.array(harnessSessionImportCandidateSchema).max(HARNESS_SESSION_IMPORT_LIST_MAX_LENGTH),
15758
- total: external_exports.number().int().nonnegative().safe()
15759
- }).strict();
15760
- var harnessSessionImportParamsSchema = external_exports.object({
15761
- harnessId: harnessPluginIdSchema,
15762
- nativeSessionId: harnessSessionImportIdSchema
15763
- }).strict();
15764
- var harnessSessionImportResultSchema = external_exports.object({
15765
- threadId: nonBlankTextSchema4.max(1024).pipe(hostThreadIdSchema)
15766
- }).strict();
15767
-
15768
15991
  // ../../shared-contracts/dist/deepseek-modern-sessions.js
15769
15992
  var DEEPSEEK_MODERN_SESSION_LIST_MAX_LENGTH = HARNESS_SESSION_IMPORT_LIST_MAX_LENGTH;
15770
15993
  var DEEPSEEK_MODERN_HOST_THREAD_ID_MAX_LENGTH = 1024;
@@ -16172,6 +16395,61 @@ function parseHostUsage(value) {
16172
16395
  return { ...value };
16173
16396
  }
16174
16397
 
16398
+ // ../../harness-adapter/dist/native-session-summary.js
16399
+ var NATIVE_SESSION_IDLE_GAP_MS = 30 * 6e4;
16400
+ function emptyNativeSessionActivity() {
16401
+ return {
16402
+ firstActivityAt: null,
16403
+ lastActivityAt: null,
16404
+ activeMs: 0,
16405
+ turns: 0,
16406
+ edits: 0,
16407
+ editing: false
16408
+ };
16409
+ }
16410
+ function count(value) {
16411
+ return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
16412
+ }
16413
+ function parseNativeSessionActivity(value) {
16414
+ if (typeof value !== "object" || value === null)
16415
+ return null;
16416
+ const activity = value;
16417
+ const time3 = (field) => field === null || count(field);
16418
+ return time3(activity.firstActivityAt) && time3(activity.lastActivityAt) && count(activity.activeMs) && count(activity.turns) && count(activity.edits) && typeof activity.editing === "boolean" ? {
16419
+ firstActivityAt: activity.firstActivityAt,
16420
+ lastActivityAt: activity.lastActivityAt,
16421
+ activeMs: activity.activeMs,
16422
+ turns: activity.turns,
16423
+ edits: activity.edits,
16424
+ editing: activity.editing
16425
+ } : null;
16426
+ }
16427
+ function recordNativeSessionActivity(activity, time3) {
16428
+ if (activity.firstActivityAt === null || time3 < activity.firstActivityAt) {
16429
+ activity.firstActivityAt = time3;
16430
+ }
16431
+ if (activity.lastActivityAt !== null) {
16432
+ const gap = time3 - activity.lastActivityAt;
16433
+ if (gap > 0 && gap <= NATIVE_SESSION_IDLE_GAP_MS)
16434
+ activity.activeMs += gap;
16435
+ if (gap <= 0)
16436
+ return;
16437
+ }
16438
+ activity.lastActivityAt = time3;
16439
+ }
16440
+ function startNativeSessionTurn(activity) {
16441
+ if (activity.editing)
16442
+ activity.edits += 1;
16443
+ activity.editing = false;
16444
+ activity.turns += 1;
16445
+ }
16446
+ function recordNativeSessionEdit(activity) {
16447
+ activity.editing = true;
16448
+ }
16449
+ function nativeSessionEdits(activity) {
16450
+ return activity.edits + (activity.editing ? 1 : 0);
16451
+ }
16452
+
16175
16453
  // ../../harness-adapter/dist/live-command-catalog.js
16176
16454
  var COMMON_EXCLUDED_LIVE_COMMANDS = /* @__PURE__ */ new Set([
16177
16455
  // Session lifecycle
@@ -16253,8 +16531,8 @@ function liveHarnessCommandPrompt(catalog, idPrefix, commandId, argumentText) {
16253
16531
  const descriptor = catalog.commands.find(({ id }) => id === commandId);
16254
16532
  if (!descriptor)
16255
16533
  return null;
16256
- const text = typeof argumentText === "string" ? argumentText.trim() : "";
16257
- return text ? `${descriptor.invocation} ${text}` : descriptor.invocation;
16534
+ const text2 = typeof argumentText === "string" ? argumentText.trim() : "";
16535
+ return text2 ? `${descriptor.invocation} ${text2}` : descriptor.invocation;
16258
16536
  }
16259
16537
  function mergeLiveHarnessCommands(builtIns, idPrefix, live, exclusions = {}) {
16260
16538
  if (!live)
@@ -16551,8 +16829,8 @@ function itemOutcome(outcome) {
16551
16829
  return { status: "succeeded" };
16552
16830
  }
16553
16831
  function toolOutput(value) {
16554
- const text = textContent(value);
16555
- return text.length > 0 ? { content: [{ type: "text", text }] } : void 0;
16832
+ const text2 = textContent(value);
16833
+ return text2.length > 0 ? { content: [{ type: "text", text: text2 }] } : void 0;
16556
16834
  }
16557
16835
  function snapshotItems(entries, outcome) {
16558
16836
  const snapshots = [];
@@ -16563,7 +16841,7 @@ function snapshotItems(entries, outcome) {
16563
16841
  continue;
16564
16842
  const content = Array.isArray(nativeMessage.content) ? nativeMessage.content : [];
16565
16843
  if (nativeMessage.role === "assistant") {
16566
- const text = textContent(content);
16844
+ const text2 = textContent(content);
16567
16845
  const reasoning = thinkingContent(content);
16568
16846
  let projectedText = false;
16569
16847
  let projectedReasoning = false;
@@ -16580,11 +16858,11 @@ function snapshotItems(entries, outcome) {
16580
16858
  projectedReasoning = true;
16581
16859
  continue;
16582
16860
  }
16583
- if (part.type === "text" && !projectedText && text.length > 0) {
16861
+ if (part.type === "text" && !projectedText && text2.length > 0) {
16584
16862
  const item2 = {
16585
16863
  type: "agentMessage",
16586
16864
  itemId: itemId(entry.id, "assistant", 0),
16587
- text
16865
+ text: text2
16588
16866
  };
16589
16867
  snapshots.push({ item: item2, outcome: itemOutcome(outcome) });
16590
16868
  projectedText = true;
@@ -16758,16 +17036,575 @@ async function rollbackOmpLastTurn(transport, sourceSessionId, cwd) {
16758
17036
  return { ok: true };
16759
17037
  }
16760
17038
 
17039
+ // dist/omp-native-usage.js
17040
+ import { createReadStream as createReadStream2 } from "node:fs";
17041
+ import { open, opendir as opendir2, stat as stat2 } from "node:fs/promises";
17042
+ import path2 from "node:path";
17043
+
17044
+ // dist/omp-session-import.js
17045
+ import { createReadStream } from "node:fs";
17046
+ import { opendir, realpath, stat } from "node:fs/promises";
17047
+ import os from "node:os";
17048
+ import path from "node:path";
17049
+ import { createInterface } from "node:readline";
17050
+ var OmpSessionChangedError = class extends Error {
17051
+ constructor() {
17052
+ super("Omp Session changed during discovery; refresh and retry");
17053
+ }
17054
+ };
17055
+ function sameFile(left, right) {
17056
+ return left.size === right.size && left.mtimeMs === right.mtimeMs && left.ctimeMs === right.ctimeMs && left.ino === right.ino && left.dev === right.dev;
17057
+ }
17058
+ function isRecord5(value) {
17059
+ return typeof value === "object" && value !== null && !Array.isArray(value);
17060
+ }
17061
+ function missing(error51) {
17062
+ return isRecord5(error51) && error51.code === "ENOENT";
17063
+ }
17064
+ async function isDirectory(directory) {
17065
+ return stat(directory).then((metadata) => metadata.isDirectory(), () => false);
17066
+ }
17067
+ async function ompSessionsDirectory(environment) {
17068
+ const custom2 = environment.PI_CODING_AGENT_SESSION_DIR;
17069
+ if (custom2)
17070
+ return path.resolve(custom2);
17071
+ const home = (process.platform === "win32" ? environment.USERPROFILE : environment.HOME) || os.homedir();
17072
+ const defaultAgent = path.join(home, environment.PI_CONFIG_DIR || ".omp", "agent");
17073
+ const agent = environment.PI_CODING_AGENT_DIR ? path.resolve(environment.PI_CODING_AGENT_DIR) : defaultAgent;
17074
+ if (agent === defaultAgent && environment.XDG_DATA_HOME) {
17075
+ const data = path.join(environment.XDG_DATA_HOME, "omp");
17076
+ if (await isDirectory(data))
17077
+ return path.join(data, "sessions");
17078
+ }
17079
+ return path.join(agent, "sessions");
17080
+ }
17081
+ function title(value) {
17082
+ return typeof value === "string" ? value.replaceAll("\0", "").trim().slice(0, HARNESS_SESSION_IMPORT_TITLE_MAX_LENGTH) || null : null;
17083
+ }
17084
+ function ompUserCustomMessage(entry) {
17085
+ return entry.type === "custom_message" && entry.attribution === "user" && entry.display === true;
17086
+ }
17087
+ function ompUserMessageTitle(message3) {
17088
+ const content = message3.content;
17089
+ return title(typeof content === "string" ? content : Array.isArray(content) ? content.filter((block) => isRecord5(block) && block.type === "text" && typeof block.text === "string").map((block) => block.text).join(" ") : "");
17090
+ }
17091
+ async function sessionFiles(directory, signal) {
17092
+ const files = [];
17093
+ const visit = async (dir, projectLevel) => {
17094
+ signal.throwIfAborted();
17095
+ const entries = await opendir(dir).catch((error51) => {
17096
+ if (missing(error51))
17097
+ return null;
17098
+ throw error51;
17099
+ });
17100
+ if (!entries)
17101
+ return;
17102
+ const names = /* @__PURE__ */ new Set();
17103
+ const folders = [];
17104
+ for await (const entry of entries) {
17105
+ signal.throwIfAborted();
17106
+ if (entry.isFile() && entry.name.endsWith(".jsonl")) {
17107
+ names.add(entry.name);
17108
+ files.push(path.join(dir, entry.name));
17109
+ } else if (projectLevel && entry.isDirectory()) {
17110
+ folders.push(entry.name);
17111
+ }
17112
+ }
17113
+ for (const folder of folders) {
17114
+ if (!names.has(`${folder}.jsonl`))
17115
+ await visit(path.join(dir, folder), false);
17116
+ }
17117
+ };
17118
+ await visit(directory, true);
17119
+ return files;
17120
+ }
17121
+ async function readCandidate(file2, signal) {
17122
+ const before = await stat(file2);
17123
+ if (!before.isFile() || before.size === 0)
17124
+ return null;
17125
+ const stream = createReadStream(file2, { encoding: "utf8", signal, end: before.size - 1 });
17126
+ const lines = createInterface({ input: stream, crlfDelay: Infinity });
17127
+ let header;
17128
+ let slotTitle = null;
17129
+ let firstMessage = null;
17130
+ let hasUser = false;
17131
+ let updatedAt = before.mtimeMs;
17132
+ const entries = /* @__PURE__ */ new Map();
17133
+ try {
17134
+ for await (const line of lines) {
17135
+ signal.throwIfAborted();
17136
+ if (!line.trim())
17137
+ continue;
17138
+ let entry;
17139
+ try {
17140
+ entry = JSON.parse(line);
17141
+ } catch {
17142
+ return null;
17143
+ }
17144
+ if (!isRecord5(entry))
17145
+ return null;
17146
+ if (!header) {
17147
+ if (entry.type === "title") {
17148
+ slotTitle = title(entry.title);
17149
+ continue;
17150
+ }
17151
+ if (entry.type !== "session" || entry.version !== 3 || typeof entry.id !== "string" || typeof entry.cwd !== "string" || !path.isAbsolute(entry.cwd))
17152
+ return null;
17153
+ header = entry;
17154
+ continue;
17155
+ }
17156
+ if (typeof entry.id !== "string" || entry.id.length === 0 || entries.has(entry.id) || entry.parentId !== null && (typeof entry.parentId !== "string" || !entries.has(entry.parentId)))
17157
+ return null;
17158
+ const message3 = isRecord5(entry.message) ? entry.message : null;
17159
+ if (!firstMessage && entry.type === "message" && message3?.role === "user") {
17160
+ firstMessage = ompUserMessageTitle(message3);
17161
+ }
17162
+ hasUser = entry.type === "message" && message3?.role === "user" || ompUserCustomMessage(entry) || typeof entry.parentId === "string" && entries.get(entry.parentId) === true;
17163
+ entries.set(entry.id, hasUser);
17164
+ if (entry.type === "message" && (message3?.role === "user" || message3?.role === "assistant")) {
17165
+ const time3 = typeof message3.timestamp === "number" ? message3.timestamp : typeof entry.timestamp === "string" ? Date.parse(entry.timestamp) : NaN;
17166
+ if (Number.isFinite(time3))
17167
+ updatedAt = time3;
17168
+ }
17169
+ }
17170
+ } finally {
17171
+ lines.close();
17172
+ stream.destroy();
17173
+ }
17174
+ if (!header)
17175
+ return null;
17176
+ if (!hasUser)
17177
+ return null;
17178
+ const after = await stat(file2);
17179
+ if (!sameFile(before, after))
17180
+ throw new OmpSessionChangedError();
17181
+ const cwd = await realpath(String(header.cwd));
17182
+ if (!(await stat(cwd)).isDirectory())
17183
+ return null;
17184
+ const nativeRef = nativeSessionRefSchema.safeParse({
17185
+ harnessId: "omp",
17186
+ nativeSessionId: header.id,
17187
+ locator: { sessionFile: await realpath(file2) },
17188
+ formatVersion: 1
17189
+ });
17190
+ const candidate = harnessSessionImportCandidateSchema.safeParse({
17191
+ nativeSessionId: header.id,
17192
+ cwd,
17193
+ title: slotTitle ?? title(header.title) ?? firstMessage,
17194
+ updatedAt: Math.floor(updatedAt),
17195
+ // OMP has no reliable cross-process running marker.
17196
+ running: null
17197
+ });
17198
+ return candidate.success && nativeRef.success ? { candidate: candidate.data, nativeRef: nativeRef.data } : null;
17199
+ }
17200
+ async function readIdentity(file2, signal) {
17201
+ const stream = createReadStream(file2, { encoding: "utf8", signal });
17202
+ const lines = createInterface({ input: stream, crlfDelay: Infinity });
17203
+ try {
17204
+ for await (const line of lines) {
17205
+ signal.throwIfAborted();
17206
+ if (!line.trim())
17207
+ continue;
17208
+ let header;
17209
+ try {
17210
+ header = JSON.parse(line);
17211
+ } catch {
17212
+ return null;
17213
+ }
17214
+ if (isRecord5(header) && header.type === "title")
17215
+ continue;
17216
+ return isRecord5(header) && header.type === "session" && header.version === 3 && typeof header.id === "string" ? header.id : null;
17217
+ }
17218
+ return null;
17219
+ } finally {
17220
+ lines.close();
17221
+ stream.destroy();
17222
+ }
17223
+ }
17224
+ var OmpSessionImportIndex = class {
17225
+ #environment;
17226
+ #cache = /* @__PURE__ */ new Map();
17227
+ #listing;
17228
+ constructor(environment) {
17229
+ this.#environment = environment;
17230
+ }
17231
+ list(signal) {
17232
+ this.#listing ??= this.#scan(signal).finally(() => {
17233
+ this.#listing = void 0;
17234
+ });
17235
+ return this.#listing;
17236
+ }
17237
+ async #scan(signal) {
17238
+ const files = await sessionFiles(await ompSessionsDirectory(this.#environment), signal);
17239
+ const next = /* @__PURE__ */ new Map();
17240
+ const identities = /* @__PURE__ */ new Set();
17241
+ const sources = [];
17242
+ for (const file2 of files) {
17243
+ signal.throwIfAborted();
17244
+ try {
17245
+ const fingerprint = await stat(file2);
17246
+ const cached2 = this.#cache.get(file2);
17247
+ const source = cached2 && sameFile(cached2.fingerprint, fingerprint) ? cached2.source : await readCandidate(file2, signal);
17248
+ if (!source)
17249
+ continue;
17250
+ if (!(await stat(source.candidate.cwd)).isDirectory())
17251
+ continue;
17252
+ if (identities.has(source.nativeRef.nativeSessionId))
17253
+ throw new Error("Omp Session identity is ambiguous across files");
17254
+ identities.add(source.nativeRef.nativeSessionId);
17255
+ next.set(file2, { fingerprint, source });
17256
+ sources.push(source);
17257
+ } catch (error51) {
17258
+ if (!missing(error51) && !(error51 instanceof OmpSessionChangedError))
17259
+ throw error51;
17260
+ }
17261
+ }
17262
+ this.#cache = next;
17263
+ return structuredClone(sources.sort((left, right) => right.candidate.updatedAt - left.candidate.updatedAt));
17264
+ }
17265
+ async resolve(nativeSessionId, signal) {
17266
+ let selected;
17267
+ for (const file2 of await sessionFiles(await ompSessionsDirectory(this.#environment), signal)) {
17268
+ signal.throwIfAborted();
17269
+ try {
17270
+ const fingerprint = await stat(file2);
17271
+ const cached2 = this.#cache.get(file2);
17272
+ const id = cached2 && sameFile(cached2.fingerprint, fingerprint) ? cached2.source.nativeRef.nativeSessionId : await readIdentity(file2, signal);
17273
+ if (id !== nativeSessionId)
17274
+ continue;
17275
+ if (selected)
17276
+ throw new Error("Omp Session identity is ambiguous across files");
17277
+ selected = file2;
17278
+ } catch (error51) {
17279
+ if (!missing(error51))
17280
+ throw error51;
17281
+ }
17282
+ }
17283
+ if (!selected)
17284
+ return null;
17285
+ try {
17286
+ const source = await readCandidate(selected, signal);
17287
+ return source?.nativeRef.nativeSessionId === nativeSessionId ? source : null;
17288
+ } catch (error51) {
17289
+ if (missing(error51))
17290
+ return null;
17291
+ throw error51;
17292
+ }
17293
+ }
17294
+ };
17295
+
17296
+ // dist/omp-native-usage.js
17297
+ var NEWLINE = 10;
17298
+ var ENTRY_TIMESTAMP = /"timestamp":"([^"]+)"/u;
17299
+ var TITLE_SLOT_MAX_BYTES = 64 * 1024;
17300
+ var TITLE_MAX_LENGTH = 120;
17301
+ var EDIT_TOOLS = /* @__PURE__ */ new Set(["edit", "write"]);
17302
+ function isRecord6(value) {
17303
+ return typeof value === "object" && value !== null && !Array.isArray(value);
17304
+ }
17305
+ function missing2(error51) {
17306
+ return isRecord6(error51) && error51.code === "ENOENT";
17307
+ }
17308
+ function count2(value) {
17309
+ return typeof value === "number" && Number.isSafeInteger(value) && value > 0 ? value : 0;
17310
+ }
17311
+ function text(value) {
17312
+ return typeof value === "string" && value.length > 0 ? value : void 0;
17313
+ }
17314
+ function sessionContext(value) {
17315
+ if (value === null)
17316
+ return null;
17317
+ if (!isRecord6(value) || typeof value.id !== "string")
17318
+ return void 0;
17319
+ if (value.cwd !== void 0 && typeof value.cwd !== "string")
17320
+ return void 0;
17321
+ return value.cwd === void 0 ? { id: value.id } : { id: value.id, cwd: value.cwd };
17322
+ }
17323
+ function emptySummary() {
17324
+ return {
17325
+ title: null,
17326
+ firstMessage: null,
17327
+ model: null,
17328
+ activity: emptyNativeSessionActivity()
17329
+ };
17330
+ }
17331
+ function nullableText(value) {
17332
+ return value === null || typeof value === "string" && value.length > 0;
17333
+ }
17334
+ function fileSummary(value) {
17335
+ if (!isRecord6(value))
17336
+ return void 0;
17337
+ const { title: title2, firstMessage, model } = value;
17338
+ const activity = parseNativeSessionActivity(value.activity);
17339
+ return nullableText(title2) && nullableText(firstMessage) && nullableText(model) && activity ? { title: title2, firstMessage, model, activity } : void 0;
17340
+ }
17341
+ function parseCursor(value) {
17342
+ const empty = { formatVersion: 3, files: {} };
17343
+ if (!isRecord6(value) || value.formatVersion !== 3 || !isRecord6(value.files))
17344
+ return empty;
17345
+ const files = {};
17346
+ for (const [relative, file2] of Object.entries(value.files)) {
17347
+ if (!isRecord6(file2))
17348
+ return empty;
17349
+ const session = sessionContext(file2.session);
17350
+ const summary = fileSummary(file2.summary);
17351
+ const { ino, mtimeMs, offset } = file2;
17352
+ if (typeof ino !== "string" || typeof mtimeMs !== "number" || !Number.isFinite(mtimeMs) || typeof offset !== "number" || !Number.isSafeInteger(offset) || offset < 0 || session === void 0 || summary === void 0) {
17353
+ return empty;
17354
+ }
17355
+ files[relative] = { ino, mtimeMs, offset, session, summary };
17356
+ }
17357
+ return { formatVersion: 3, files };
17358
+ }
17359
+ async function sessionFiles2(directory, signal) {
17360
+ const files = [];
17361
+ const visit = async (dir) => {
17362
+ signal.throwIfAborted();
17363
+ const entries = await opendir2(dir).catch((error51) => {
17364
+ if (missing2(error51))
17365
+ return null;
17366
+ throw error51;
17367
+ });
17368
+ if (!entries)
17369
+ return;
17370
+ for await (const entry of entries) {
17371
+ const child = path2.join(dir, entry.name);
17372
+ if (entry.isDirectory())
17373
+ await visit(child);
17374
+ else if (entry.isFile() && entry.name.endsWith(".jsonl"))
17375
+ files.push(child);
17376
+ }
17377
+ };
17378
+ await visit(directory);
17379
+ return files;
17380
+ }
17381
+ async function* completeLines(file2, start, end) {
17382
+ if (end <= start)
17383
+ return;
17384
+ let carry = Buffer.alloc(0);
17385
+ let carryStart = start;
17386
+ for await (const chunk of createReadStream2(file2, { start, end: end - 1 })) {
17387
+ const buffer = carry.length > 0 ? Buffer.concat([carry, chunk]) : chunk;
17388
+ let lineStart = 0;
17389
+ let newline = buffer.indexOf(NEWLINE, lineStart);
17390
+ while (newline !== -1) {
17391
+ yield { line: buffer.toString("utf8", lineStart, newline), end: carryStart + newline + 1 };
17392
+ lineStart = newline + 1;
17393
+ newline = buffer.indexOf(NEWLINE, lineStart);
17394
+ }
17395
+ carry = buffer.subarray(lineStart);
17396
+ carryStart += lineStart;
17397
+ }
17398
+ }
17399
+ function usageTokens(usage) {
17400
+ const output = count2(usage.output);
17401
+ const reasoning = Math.min(count2(usage.reasoningTokens), output);
17402
+ return {
17403
+ input: count2(usage.input),
17404
+ cacheRead: count2(usage.cacheRead),
17405
+ cacheWrite: count2(usage.cacheWrite),
17406
+ output: output - reasoning,
17407
+ reasoning
17408
+ };
17409
+ }
17410
+ function reportedCost(usage) {
17411
+ const total = isRecord6(usage.cost) ? usage.cost.total : void 0;
17412
+ return typeof total === "number" && Number.isFinite(total) && total > 0 ? total : void 0;
17413
+ }
17414
+ function shortTitle(value) {
17415
+ const title2 = value?.replaceAll(/\s+/gu, " ").trim();
17416
+ if (!title2)
17417
+ return null;
17418
+ const characters = [...title2];
17419
+ return characters.length <= TITLE_MAX_LENGTH ? title2 : `${characters.slice(0, TITLE_MAX_LENGTH - 1).join("").trimEnd()}…`;
17420
+ }
17421
+ async function readTitleSlot(file2) {
17422
+ const handle = await open(file2, "r");
17423
+ try {
17424
+ const buffer = Buffer.alloc(TITLE_SLOT_MAX_BYTES);
17425
+ const { bytesRead } = await handle.read(buffer, 0, buffer.length, 0);
17426
+ const newline = buffer.subarray(0, bytesRead).indexOf(NEWLINE);
17427
+ if (newline === -1)
17428
+ return null;
17429
+ const slot = JSON.parse(buffer.toString("utf8", 0, newline));
17430
+ return isRecord6(slot) && slot.type === "title" && typeof slot.title === "string" ? shortTitle(slot.title) : null;
17431
+ } catch {
17432
+ return null;
17433
+ } finally {
17434
+ await handle.close();
17435
+ }
17436
+ }
17437
+ function summarize(summary, entry) {
17438
+ if (ompUserCustomMessage(entry)) {
17439
+ startNativeSessionTurn(summary.activity);
17440
+ return;
17441
+ }
17442
+ const message3 = isRecord6(entry.message) ? entry.message : null;
17443
+ if (entry.type !== "message" || !message3)
17444
+ return;
17445
+ if (message3.role === "user") {
17446
+ summary.firstMessage ??= shortTitle(ompUserMessageTitle(message3));
17447
+ startNativeSessionTurn(summary.activity);
17448
+ } else if (message3.role === "assistant") {
17449
+ summary.model = text(message3.model) ?? summary.model;
17450
+ if (Array.isArray(message3.content) && message3.content.some((block) => isRecord6(block) && block.type === "toolCall" && typeof block.name === "string" && EDIT_TOOLS.has(block.name))) {
17451
+ recordNativeSessionEdit(summary.activity);
17452
+ }
17453
+ }
17454
+ }
17455
+ function sessionSummary(relative, file2, files) {
17456
+ const { session, summary } = file2;
17457
+ const { activity } = summary;
17458
+ if (!session || activity.firstActivityAt === null || activity.lastActivityAt === null) {
17459
+ return null;
17460
+ }
17461
+ const parentFile = files[`${path2.dirname(relative)}.jsonl`];
17462
+ const parentSessionId = parentFile?.session?.id;
17463
+ const title2 = summary.title ?? summary.firstMessage;
17464
+ return {
17465
+ key: relative,
17466
+ nativeSessionId: session.id,
17467
+ ...parentSessionId ? { parentSessionId } : {},
17468
+ ...title2 ? { title: title2 } : {},
17469
+ ...session.cwd ? { cwd: session.cwd } : {},
17470
+ ...summary.model ? { model: summary.model } : {},
17471
+ firstActivityAt: activity.firstActivityAt,
17472
+ lastActivityAt: activity.lastActivityAt,
17473
+ activeMs: activity.activeMs,
17474
+ turns: activity.turns,
17475
+ edits: nativeSessionEdits(activity)
17476
+ };
17477
+ }
17478
+ function sessionHeader(entry) {
17479
+ const id = text(entry.id);
17480
+ if (!id)
17481
+ return null;
17482
+ const cwd = text(entry.cwd);
17483
+ return { id, ...cwd ? { cwd } : {} };
17484
+ }
17485
+ function assistantRecord(entry, session) {
17486
+ const message3 = isRecord6(entry.message) ? entry.message : null;
17487
+ if (entry.type !== "message" || message3?.role !== "assistant" || !isRecord6(message3.usage)) {
17488
+ return null;
17489
+ }
17490
+ const entryId = text(entry.id);
17491
+ const timestamp = text(entry.timestamp);
17492
+ const time3 = timestamp === void 0 ? Number.NaN : Date.parse(timestamp);
17493
+ if (!entryId || !timestamp || !Number.isFinite(time3))
17494
+ return null;
17495
+ const tokens = usageTokens(message3.usage);
17496
+ const hasTokens = Object.values(tokens).some((value) => value > 0);
17497
+ const provider = text(message3.provider);
17498
+ const model = text(message3.model);
17499
+ const cost = reportedCost(message3.usage);
17500
+ return {
17501
+ // Forks copy entries with their id and timestamp; the pair also avoids short-id collisions.
17502
+ dedupeKey: `message:${entryId}:${timestamp}`,
17503
+ occurredAt: time3,
17504
+ nativeSessionId: session.id,
17505
+ ...provider ? { provider } : {},
17506
+ // A reply without tokens (for example a failed request) only counts as a conversation.
17507
+ ...model && hasTokens ? { model } : {},
17508
+ ...session.cwd ? { cwd: session.cwd } : {},
17509
+ tokens,
17510
+ conversations: 1,
17511
+ ...cost !== void 0 && hasTokens ? { reportedCostUsd: cost } : {}
17512
+ };
17513
+ }
17514
+ async function readFileUsage(file2, input, records) {
17515
+ const { summary } = input;
17516
+ let session = input.start === 0 ? "pending" : input.session;
17517
+ let offset = input.start;
17518
+ for await (const { line, end } of completeLines(file2, input.start, input.end)) {
17519
+ offset = end;
17520
+ if (session !== "pending" && session !== null) {
17521
+ const timestamp = ENTRY_TIMESTAMP.exec(line)?.[1];
17522
+ const time3 = timestamp === void 0 ? Number.NaN : Date.parse(timestamp);
17523
+ if (Number.isFinite(time3))
17524
+ recordNativeSessionActivity(summary.activity, time3);
17525
+ }
17526
+ if (session !== "pending" && !line.includes('"usage"') && !line.includes('"role":"user"') && !line.includes('"attribution":"user"')) {
17527
+ continue;
17528
+ }
17529
+ let entry;
17530
+ try {
17531
+ entry = JSON.parse(line);
17532
+ } catch {
17533
+ if (session === "pending")
17534
+ session = null;
17535
+ continue;
17536
+ }
17537
+ if (session === "pending") {
17538
+ if (isRecord6(entry) && entry.type === "title")
17539
+ continue;
17540
+ session = isRecord6(entry) && entry.type === "session" ? sessionHeader(entry) : null;
17541
+ if (session && isRecord6(entry)) {
17542
+ summary.title ??= shortTitle(text(entry.title) ?? null);
17543
+ const time3 = Date.parse(String(entry.timestamp));
17544
+ if (Number.isFinite(time3))
17545
+ recordNativeSessionActivity(summary.activity, time3);
17546
+ }
17547
+ continue;
17548
+ }
17549
+ if (!session || !isRecord6(entry))
17550
+ continue;
17551
+ summarize(summary, entry);
17552
+ const record2 = assistantRecord(entry, session);
17553
+ if (record2)
17554
+ records.push(record2);
17555
+ }
17556
+ return session === "pending" ? { offset: 0, session: null } : { offset, session };
17557
+ }
17558
+ async function readOmpNativeUsage(environment, cursor, signal, onProgress) {
17559
+ const directory = await ompSessionsDirectory(environment);
17560
+ const previous = parseCursor(cursor);
17561
+ const next = { formatVersion: 3, files: {} };
17562
+ const records = [];
17563
+ const changed = [];
17564
+ const files = await sessionFiles2(directory, signal);
17565
+ onProgress?.({ processed: 0, total: files.length });
17566
+ for (const [index, file2] of files.entries()) {
17567
+ signal.throwIfAborted();
17568
+ const relative = path2.relative(directory, file2);
17569
+ try {
17570
+ const metadata = await stat2(file2, { bigint: true });
17571
+ const ino = metadata.ino.toString();
17572
+ const size = Number(metadata.size);
17573
+ const known = previous.files[relative];
17574
+ const mtimeMs = Number(metadata.mtimeMs);
17575
+ const resume = known && known.ino === ino && known.offset <= size ? known : null;
17576
+ const summary = resume ? structuredClone(resume.summary) : emptySummary();
17577
+ const { offset, session } = await readFileUsage(file2, { start: resume?.offset ?? 0, end: size, session: resume?.session ?? null, summary }, records);
17578
+ const modified = !resume || offset > resume.offset || mtimeMs !== resume.mtimeMs;
17579
+ if (modified && session) {
17580
+ summary.title = await readTitleSlot(file2) ?? summary.title;
17581
+ changed.push(relative);
17582
+ }
17583
+ next.files[relative] = { ino, mtimeMs, offset, session, summary };
17584
+ } catch (error51) {
17585
+ if (!missing2(error51))
17586
+ throw error51;
17587
+ }
17588
+ onProgress?.({ processed: index + 1, total: files.length });
17589
+ }
17590
+ const sessions = changed.flatMap((relative) => {
17591
+ const file2 = next.files[relative];
17592
+ const summary = file2 ? sessionSummary(relative, file2, next.files) : null;
17593
+ return summary ? [summary] : [];
17594
+ });
17595
+ return { records, sessions, cursor: next };
17596
+ }
17597
+
16761
17598
  // dist/omp-rpc-session.js
16762
17599
  import { spawn, spawnSync } from "node:child_process";
16763
17600
  import { randomUUID } from "node:crypto";
16764
- import path3 from "node:path";
17601
+ import path5 from "node:path";
16765
17602
 
16766
17603
  // ../../harness-discovery/dist/environment.js
16767
17604
  import fs from "node:fs";
16768
- import path from "node:path";
17605
+ import path3 from "node:path";
16769
17606
  function targetPath(platform) {
16770
- return platform === "win32" ? path.win32 : path.posix;
17607
+ return platform === "win32" ? path3.win32 : path3.posix;
16771
17608
  }
16772
17609
  function environmentValue(environment, name) {
16773
17610
  const lowered = name.toLowerCase();
@@ -16810,11 +17647,11 @@ function newestFirst(names) {
16810
17647
  }
16811
17648
 
16812
17649
  // ../../harness-discovery/dist/node-runtime.js
16813
- import path2 from "node:path";
17650
+ import path4 from "node:path";
16814
17651
  function withNodeRuntimeOnPath(environment, runtimeExecutable = process.execPath, platform = process.platform) {
16815
17652
  const pathKey = Object.keys(environment).find((name) => name.toLowerCase() === "path") ?? "PATH";
16816
17653
  const delimiter = platform === "win32" ? ";" : ":";
16817
- const runtimeDirectory = path2.dirname(runtimeExecutable);
17654
+ const runtimeDirectory = path4.dirname(runtimeExecutable);
16818
17655
  const directories = (environment[pathKey] ?? "").split(delimiter).filter(Boolean);
16819
17656
  const equal = platform === "win32" ? (value) => value.toLowerCase() : (value) => value;
16820
17657
  if (!directories.some((directory) => equal(directory) === equal(runtimeDirectory))) {
@@ -16824,7 +17661,7 @@ function withNodeRuntimeOnPath(environment, runtimeExecutable = process.execPath
16824
17661
  }
16825
17662
 
16826
17663
  // ../../harness-discovery/dist/resolve.js
16827
- import os from "node:os";
17664
+ import os2 from "node:os";
16828
17665
 
16829
17666
  // ../../harness-discovery/dist/version-managers.js
16830
17667
  function versionManagerBinaryDirectories(context) {
@@ -16890,7 +17727,7 @@ function installRootExtensions(platform) {
16890
17727
  return platform === "win32" ? [".exe", ".cmd"] : [""];
16891
17728
  }
16892
17729
  function resolveHomeDirectory(input) {
16893
- return input.homeDirectory ?? environmentValue(input.environment, "HOME") ?? environmentValue(input.environment, "USERPROFILE") ?? os.homedir();
17730
+ return input.homeDirectory ?? environmentValue(input.environment, "HOME") ?? environmentValue(input.environment, "USERPROFILE") ?? os2.homedir();
16894
17731
  }
16895
17732
  function templateVariables(environment, platform, home) {
16896
17733
  const pathFlavor = targetPath(platform);
@@ -17013,14 +17850,14 @@ function resolveOmpExecutable(input, dependencies = {}) {
17013
17850
  }
17014
17851
 
17015
17852
  // dist/omp-usage.js
17016
- function isRecord5(value) {
17853
+ function isRecord7(value) {
17017
17854
  return typeof value === "object" && value !== null && !Array.isArray(value);
17018
17855
  }
17019
17856
  function nonNegativeSafeInteger(value) {
17020
17857
  return typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : null;
17021
17858
  }
17022
17859
  function optionalOmpCacheHitRatePercent(value) {
17023
- if (!isRecord5(value) || value.role !== "assistant" || !isRecord5(value.usage))
17860
+ if (!isRecord7(value) || value.role !== "assistant" || !isRecord7(value.usage))
17024
17861
  return null;
17025
17862
  const input = nonNegativeSafeInteger(value.usage.input);
17026
17863
  const cacheRead = nonNegativeSafeInteger(value.usage.cacheRead);
@@ -17033,20 +17870,20 @@ function optionalOmpCacheHitRatePercent(value) {
17033
17870
  function latestOmpCacheHitRatePercent(history) {
17034
17871
  let latest = null;
17035
17872
  for (const entry of activeOmpEntries(history)) {
17036
- if (entry.type === "message" && isRecord5(entry.message) && entry.message.role === "assistant") {
17873
+ if (entry.type === "message" && isRecord7(entry.message) && entry.message.role === "assistant") {
17037
17874
  latest = optionalOmpCacheHitRatePercent(entry.message);
17038
17875
  }
17039
17876
  }
17040
17877
  return latest;
17041
17878
  }
17042
17879
  function responseData(response, operation) {
17043
- if (!isRecord5(response.data)) {
17880
+ if (!isRecord7(response.data)) {
17044
17881
  throw new Error(`Omp RPC ${operation} response has no data`);
17045
17882
  }
17046
17883
  return response.data;
17047
17884
  }
17048
17885
  function contextUsage(value) {
17049
- if (!isRecord5(value))
17886
+ if (!isRecord7(value))
17050
17887
  throw new Error("Omp RPC context Usage is invalid");
17051
17888
  return parseHostUsage({
17052
17889
  contextUsedTokens: value.tokens,
@@ -17056,15 +17893,15 @@ function contextUsage(value) {
17056
17893
  function parseOmpSessionUsage(response) {
17057
17894
  const data = responseData(response, "Session stats");
17058
17895
  const tokens = data.tokens;
17059
- if (tokens !== void 0 && !isRecord5(tokens)) {
17896
+ if (tokens !== void 0 && !isRecord7(tokens)) {
17060
17897
  throw new Error("Omp RPC Session stats tokens are invalid");
17061
17898
  }
17062
17899
  return parseHostUsage({
17063
- ...isRecord5(tokens) && tokens.input !== void 0 ? { inputTokens: tokens.input } : {},
17064
- ...isRecord5(tokens) && tokens.cacheRead !== void 0 ? { cachedInputTokens: tokens.cacheRead } : {},
17065
- ...isRecord5(tokens) && tokens.cacheWrite !== void 0 ? { cacheWriteInputTokens: tokens.cacheWrite } : {},
17066
- ...isRecord5(tokens) && tokens.output !== void 0 ? { outputTokens: tokens.output } : {},
17067
- ...isRecord5(tokens) && tokens.total !== void 0 ? { totalTokens: tokens.total } : {},
17900
+ ...isRecord7(tokens) && tokens.input !== void 0 ? { inputTokens: tokens.input } : {},
17901
+ ...isRecord7(tokens) && tokens.cacheRead !== void 0 ? { cachedInputTokens: tokens.cacheRead } : {},
17902
+ ...isRecord7(tokens) && tokens.cacheWrite !== void 0 ? { cacheWriteInputTokens: tokens.cacheWrite } : {},
17903
+ ...isRecord7(tokens) && tokens.output !== void 0 ? { outputTokens: tokens.output } : {},
17904
+ ...isRecord7(tokens) && tokens.total !== void 0 ? { totalTokens: tokens.total } : {},
17068
17905
  ...data.cost !== void 0 ? { totalCostUsd: data.cost } : {},
17069
17906
  ...data.contextUsage !== void 0 ? contextUsage(data.contextUsage) : {}
17070
17907
  });
@@ -17084,16 +17921,16 @@ function optionalOmpStateContextUsage(value) {
17084
17921
  }
17085
17922
 
17086
17923
  // dist/omp-session-file.js
17087
- import { createReadStream } from "node:fs";
17088
- import { open, realpath } from "node:fs/promises";
17924
+ import { createReadStream as createReadStream3 } from "node:fs";
17925
+ import { open as open2, realpath as realpath2 } from "node:fs/promises";
17089
17926
  import readline from "node:readline";
17090
17927
  var MAX_SESSION_HEADER_BYTES = 64 * 1024;
17091
17928
  var utf8Decoder = new TextDecoder("utf-8", { fatal: true });
17092
- function isRecord6(value) {
17929
+ function isRecord8(value) {
17093
17930
  return typeof value === "object" && value !== null && !Array.isArray(value);
17094
17931
  }
17095
17932
  function historyEntry(value) {
17096
- if (!isRecord6(value) || value.type === "title" || value.type === "session" || typeof value.id !== "string" || value.id.length === 0 || value.parentId !== null && typeof value.parentId !== "string" || typeof value.type !== "string") {
17933
+ if (!isRecord8(value) || value.type === "title" || value.type === "session" || typeof value.id !== "string" || value.id.length === 0 || value.parentId !== null && typeof value.parentId !== "string" || typeof value.type !== "string") {
17097
17934
  return null;
17098
17935
  }
17099
17936
  return value;
@@ -17102,7 +17939,7 @@ async function readOmpSessionHistory(sessionFile) {
17102
17939
  const entries = [];
17103
17940
  let leafId = null;
17104
17941
  const lines = readline.createInterface({
17105
- input: createReadStream(sessionFile, { encoding: "utf8" }),
17942
+ input: createReadStream3(sessionFile, { encoding: "utf8" }),
17106
17943
  crlfDelay: Number.POSITIVE_INFINITY
17107
17944
  });
17108
17945
  try {
@@ -17127,7 +17964,7 @@ async function readOmpSessionHistory(sessionFile) {
17127
17964
  return { entries, leafId };
17128
17965
  }
17129
17966
  async function readOmpSessionHeader(sessionFile) {
17130
- const handle = await open(sessionFile, "r");
17967
+ const handle = await open2(sessionFile, "r");
17131
17968
  try {
17132
17969
  const buffer = Buffer.allocUnsafe(MAX_SESSION_HEADER_BYTES);
17133
17970
  const { bytesRead } = await handle.read(buffer, 0, buffer.length, 0);
@@ -17146,7 +17983,7 @@ async function readOmpSessionHeader(sessionFile) {
17146
17983
  } catch {
17147
17984
  continue;
17148
17985
  }
17149
- if (!isRecord6(parsed) || parsed.type !== "session")
17986
+ if (!isRecord8(parsed) || parsed.type !== "session")
17150
17987
  continue;
17151
17988
  if (typeof parsed.id !== "string" || parsed.id.length === 0 || typeof parsed.cwd !== "string" || parsed.cwd.length === 0) {
17152
17989
  throw new Error("Omp Session header is invalid");
@@ -17166,8 +18003,8 @@ async function verifyOmpSessionCwd(input) {
17166
18003
  throw new Error("Omp Fork Session header identity does not match RPC state");
17167
18004
  }
17168
18005
  const [actualCwd, expectedCwd] = await Promise.all([
17169
- realpath(header.cwd),
17170
- realpath(input.expectedCwd)
18006
+ realpath2(header.cwd),
18007
+ realpath2(input.expectedCwd)
17171
18008
  ]);
17172
18009
  if (actualCwd !== expectedCwd) {
17173
18010
  throw new Error("Omp Fork Session did not bind the requested cwd");
@@ -17193,10 +18030,10 @@ var OmpFrameDecoder = class {
17193
18030
  }
17194
18031
  const chunkId = value.chunkId;
17195
18032
  const index = value.index;
17196
- const count = value.count;
18033
+ const count3 = value.count;
17197
18034
  const byteLength = value.byteLength;
17198
18035
  const data = value.data;
17199
- if (typeof chunkId !== "string" || chunkId.length === 0 || chunkId.length > 128 || !Number.isInteger(index) || !Number.isInteger(count) || !Number.isInteger(byteLength) || index < 0 || count < 2 || index >= count || byteLength < MAX_FRAME_BYTES || byteLength > MAX_REASSEMBLED_BYTES || typeof data !== "string" || data.length === 0)
18036
+ if (typeof chunkId !== "string" || chunkId.length === 0 || chunkId.length > 128 || !Number.isInteger(index) || !Number.isInteger(count3) || !Number.isInteger(byteLength) || index < 0 || count3 < 2 || index >= count3 || byteLength < MAX_FRAME_BYTES || byteLength > MAX_REASSEMBLED_BYTES || typeof data !== "string" || data.length === 0)
17200
18037
  throw new Error("Invalid OMP RPC chunk metadata");
17201
18038
  let bytes;
17202
18039
  try {
@@ -17208,7 +18045,7 @@ var OmpFrameDecoder = class {
17208
18045
  throw new Error("Invalid OMP RPC chunk data");
17209
18046
  }
17210
18047
  const chunkIndex = index;
17211
- const chunkCount = count;
18048
+ const chunkCount = count3;
17212
18049
  const declaredByteLength = byteLength;
17213
18050
  if (!this.#pending) {
17214
18051
  if (chunkIndex !== 0)
@@ -17270,7 +18107,7 @@ var OmpRpcUnsupportedCommandError = class extends Error {
17270
18107
  }
17271
18108
  };
17272
18109
  var textDecoder = new TextDecoder("utf-8", { fatal: true });
17273
- function isRecord7(value) {
18110
+ function isRecord9(value) {
17274
18111
  return typeof value === "object" && value !== null && !Array.isArray(value);
17275
18112
  }
17276
18113
  function message2(value) {
@@ -17282,13 +18119,13 @@ function nonBlankString(value) {
17282
18119
  function parseNativeModel(value, context) {
17283
18120
  if (value === null || value === void 0)
17284
18121
  return null;
17285
- if (!isRecord7(value) || !nonBlankString(value.provider) || !nonBlankString(value.id)) {
18122
+ if (!isRecord9(value) || !nonBlankString(value.provider) || !nonBlankString(value.id)) {
17286
18123
  throw new OmpRpcFaultError("protocolError", `Omp RPC returned an invalid ${context} Model`);
17287
18124
  }
17288
18125
  return { provider: value.provider, id: value.id };
17289
18126
  }
17290
18127
  function sessionStateData(response) {
17291
- const data = isRecord7(response.data) ? response.data : null;
18128
+ const data = isRecord9(response.data) ? response.data : null;
17292
18129
  if (!data)
17293
18130
  throw new OmpRpcFaultError("protocolError", "Omp RPC state response has no data");
17294
18131
  return data;
@@ -17303,7 +18140,7 @@ function parseSessionState(response) {
17303
18140
  if (thinkingLevel !== null && !thinkingLevel.success) {
17304
18141
  throw new OmpRpcFaultError("protocolError", "Omp RPC state has an invalid Thinking level");
17305
18142
  }
17306
- const thinking = isRecord7(data.model) && isRecord7(data.model.thinking) ? data.model.thinking : null;
18143
+ const thinking = isRecord9(data.model) && isRecord9(data.model.thinking) ? data.model.thinking : null;
17307
18144
  const availableThinkingLevels = thinking && Array.isArray(thinking.efforts) ? thinking.efforts.flatMap((level) => {
17308
18145
  const parsed = harnessThinkingOptionIdSchema.safeParse(level);
17309
18146
  return parsed.success ? [parsed.data] : [];
@@ -17326,25 +18163,25 @@ function parseSessionStreaming(response) {
17326
18163
  return isStreaming;
17327
18164
  }
17328
18165
  function parseAvailableModels(response) {
17329
- const data = isRecord7(response.data) ? response.data : null;
18166
+ const data = isRecord9(response.data) ? response.data : null;
17330
18167
  if (!data || !Array.isArray(data.models)) {
17331
18168
  throw new OmpRpcFaultError("protocolError", "Omp RPC Model catalog response has no models");
17332
18169
  }
17333
18170
  return data.models.map((model) => {
17334
18171
  const parsed = parseNativeModel(model, "catalog");
17335
- if (!parsed || !isRecord7(model) || typeof model.reasoning !== "boolean") {
18172
+ if (!parsed || !isRecord9(model) || typeof model.reasoning !== "boolean") {
17336
18173
  throw new OmpRpcFaultError("protocolError", "Omp RPC catalog contains a Model without reasoning capability");
17337
18174
  }
17338
18175
  return { ...parsed, reasoning: model.reasoning };
17339
18176
  });
17340
18177
  }
17341
18178
  function parseSubagentMessages(response) {
17342
- const data = isRecord7(response.data) ? response.data : null;
18179
+ const data = isRecord9(response.data) ? response.data : null;
17343
18180
  if (!data || !nonBlankString(data.sessionFile) || !Number.isSafeInteger(data.fromByte) || !Number.isSafeInteger(data.nextByte) || data.fromByte < 0 || data.nextByte < data.fromByte || typeof data.reset !== "boolean" || !Array.isArray(data.entries) || !Array.isArray(data.messages)) {
17344
18181
  throw new OmpRpcFaultError("protocolError", "Omp RPC Subagent transcript response is invalid");
17345
18182
  }
17346
- const entries = data.entries.flatMap((value) => isRecord7(value) ? [value] : []);
17347
- const messages = data.messages.flatMap((value) => isRecord7(value) ? [value] : []);
18183
+ const entries = data.entries.flatMap((value) => isRecord9(value) ? [value] : []);
18184
+ const messages = data.messages.flatMap((value) => isRecord9(value) ? [value] : []);
17348
18185
  if (entries.length !== data.entries.length || messages.length !== data.messages.length) {
17349
18186
  throw new OmpRpcFaultError("protocolError", "Omp RPC Subagent transcript contains invalid data");
17350
18187
  }
@@ -17365,32 +18202,32 @@ function subagentStatus(value) {
17365
18202
  throw new OmpRpcFaultError("protocolError", "Omp RPC Subagent status is invalid");
17366
18203
  }
17367
18204
  function assistantText(value) {
17368
- if (!isRecord7(value) || value.role !== "assistant" || !Array.isArray(value.content))
18205
+ if (!isRecord9(value) || value.role !== "assistant" || !Array.isArray(value.content))
17369
18206
  return null;
17370
- return value.content.filter((content) => isRecord7(content) && content.type === "text" && typeof content.text === "string").map((content) => content.text).join("");
18207
+ return value.content.filter((content) => isRecord9(content) && content.type === "text" && typeof content.text === "string").map((content) => content.text).join("");
17371
18208
  }
17372
18209
  function assistantMessageId(value) {
17373
- if (!isRecord7(value) || value.role !== "assistant")
18210
+ if (!isRecord9(value) || value.role !== "assistant")
17374
18211
  return null;
17375
18212
  return nonBlankString(value.responseId) ? value.responseId : null;
17376
18213
  }
17377
18214
  function extractReasoningText(content) {
17378
- if (!isRecord7(content))
18215
+ if (!isRecord9(content))
17379
18216
  return null;
17380
18217
  const type = String(content.type ?? "");
17381
18218
  if (type === "thinking" || type === "reasoning" || type === "thought") {
17382
- const text = content.thinking ?? content.reasoning ?? content.text ?? content.delta;
17383
- return typeof text === "string" ? text : null;
18219
+ const text2 = content.thinking ?? content.reasoning ?? content.text ?? content.delta;
18220
+ return typeof text2 === "string" ? text2 : null;
17384
18221
  }
17385
18222
  return null;
17386
18223
  }
17387
18224
  function assistantReasoning(value) {
17388
- if (!isRecord7(value) || value.role !== "assistant" || !Array.isArray(value.content))
18225
+ if (!isRecord9(value) || value.role !== "assistant" || !Array.isArray(value.content))
17389
18226
  return null;
17390
- return value.content.map(extractReasoningText).filter((text) => typeof text === "string").join("");
18227
+ return value.content.map(extractReasoningText).filter((text2) => typeof text2 === "string").join("");
17391
18228
  }
17392
18229
  function assistantFailure(value) {
17393
- if (!isRecord7(value) || value.role !== "assistant")
18230
+ if (!isRecord9(value) || value.role !== "assistant")
17394
18231
  return void 0;
17395
18232
  if (value.stopReason !== "error" && value.stopReason !== "aborted")
17396
18233
  return null;
@@ -17410,7 +18247,7 @@ function signalProcessTree(child, signal) {
17410
18247
  try {
17411
18248
  process.kill(-child.pid, signal);
17412
18249
  } catch (error51) {
17413
- if (!isRecord7(error51) || error51.code !== "ESRCH")
18250
+ if (!isRecord9(error51) || error51.code !== "ESRCH")
17414
18251
  throw error51;
17415
18252
  }
17416
18253
  }
@@ -17449,7 +18286,7 @@ function ompRpcProcessCommand(options, dependencies = {}) {
17449
18286
  ...modelArguments,
17450
18287
  ...sessionArguments
17451
18288
  ];
17452
- const extension = path3.win32.extname(command).toLowerCase();
18289
+ const extension = path5.win32.extname(command).toLowerCase();
17453
18290
  if (platform !== "win32" || ![".cmd", ".bat"].includes(extension)) {
17454
18291
  return { command, arguments: arguments_, windowsVerbatimArguments: false };
17455
18292
  }
@@ -17548,7 +18385,7 @@ var OmpRpcSession = class {
17548
18385
  this.#stderrTail = sanitizeDiagnosticTail(`${this.#stderrTail}${chunk.toString()}`);
17549
18386
  });
17550
18387
  child.once("error", (error51) => {
17551
- const kind = isRecord7(error51) && error51.code === "ENOENT" ? "notInstalled" : "unavailable";
18388
+ const kind = isRecord9(error51) && error51.code === "ENOENT" ? "notInstalled" : "unavailable";
17552
18389
  this.#fail(new OmpRpcFaultError(kind, `Omp RPC failed to start: ${error51.message}`, this.stderrTail));
17553
18390
  });
17554
18391
  child.once("exit", (code, signal) => {
@@ -17583,17 +18420,17 @@ var OmpRpcSession = class {
17583
18420
  return await readOmpSessionHistory(this.state.sessionFile);
17584
18421
  }
17585
18422
  const response = await this.#send("get_messages", {});
17586
- const data = isRecord7(response.data) ? response.data : null;
18423
+ const data = isRecord9(response.data) ? response.data : null;
17587
18424
  if (!data || !Array.isArray(data.messages)) {
17588
18425
  throw new OmpRpcFaultError("protocolError", "Omp RPC messages response has no messages");
17589
18426
  }
17590
18427
  let branchEntryIds = null;
17591
18428
  try {
17592
18429
  const branchResponse = await this.#send("get_branch_messages", {});
17593
- const branchData = isRecord7(branchResponse.data) ? branchResponse.data : null;
18430
+ const branchData = isRecord9(branchResponse.data) ? branchResponse.data : null;
17594
18431
  if (branchData && Array.isArray(branchData.messages)) {
17595
18432
  const parsed = branchData.messages.flatMap((entry) => {
17596
- if (!isRecord7(entry) || !nonBlankString(entry.entryId))
18433
+ if (!isRecord9(entry) || !nonBlankString(entry.entryId))
17597
18434
  return [];
17598
18435
  return [entry.entryId];
17599
18436
  });
@@ -17607,11 +18444,11 @@ var OmpRpcSession = class {
17607
18444
  let userIndex = 0;
17608
18445
  let parentId = null;
17609
18446
  const entries = data.messages.map((nativeMessage, index) => {
17610
- const role = isRecord7(nativeMessage) ? nativeMessage.role : void 0;
18447
+ const role = isRecord9(nativeMessage) ? nativeMessage.role : void 0;
17611
18448
  const branchId = role === "user" ? branchEntryIds?.[userIndex] : void 0;
17612
18449
  if (branchId)
17613
18450
  userIndex += 1;
17614
- const id = branchId ?? (isRecord7(nativeMessage) && nonBlankString(nativeMessage.id) ? nativeMessage.id : `omp-message-${index}`);
18451
+ const id = branchId ?? (isRecord9(nativeMessage) && nonBlankString(nativeMessage.id) ? nativeMessage.id : `omp-message-${index}`);
17615
18452
  const entry = { id, parentId, type: "message", message: nativeMessage };
17616
18453
  parentId = id;
17617
18454
  return entry;
@@ -17691,7 +18528,7 @@ var OmpRpcSession = class {
17691
18528
  throw new Error("Omp RPC Fork requires an Entry identity");
17692
18529
  try {
17693
18530
  const response = await this.#send("branch", { entryId });
17694
- const data = isRecord7(response.data) ? response.data : null;
18531
+ const data = isRecord9(response.data) ? response.data : null;
17695
18532
  if (!data || data.cancelled === true) {
17696
18533
  throw new OmpRpcFaultError("unavailable", "Omp RPC Fork was cancelled");
17697
18534
  }
@@ -17741,13 +18578,13 @@ var OmpRpcSession = class {
17741
18578
  throw fault;
17742
18579
  }
17743
18580
  }
17744
- async runTurn(text, onEvent) {
18581
+ async runTurn(text2, onEvent) {
17745
18582
  if (!this.#child || !this.#state || this.#closed || this.#failed) {
17746
18583
  throw new Error("Omp RPC Session is unavailable");
17747
18584
  }
17748
18585
  if (this.#activeTurn)
17749
18586
  throw new Error("Omp RPC Session already has an active Turn");
17750
- if (text.length === 0)
18587
+ if (text2.length === 0)
17751
18588
  throw new Error("Omp text Turn must not be empty");
17752
18589
  const settled = new Promise((resolve, reject) => {
17753
18590
  this.#activeTurn = {
@@ -17772,7 +18609,7 @@ var OmpRpcSession = class {
17772
18609
  };
17773
18610
  });
17774
18611
  try {
17775
- await this.#send("prompt", { message: text });
18612
+ await this.#send("prompt", { message: text2 });
17776
18613
  } catch (error51) {
17777
18614
  this.#rejectActiveTurn(error51 instanceof Error ? error51 : new Error(message2(error51)));
17778
18615
  }
@@ -17884,7 +18721,7 @@ var OmpRpcSession = class {
17884
18721
  continue;
17885
18722
  }
17886
18723
  const value = decoded;
17887
- if (!isRecord7(value) || typeof value.type !== "string") {
18724
+ if (!isRecord9(value) || typeof value.type !== "string") {
17888
18725
  throw new OmpRpcFaultError("protocolError", "Omp RPC returned an invalid envelope");
17889
18726
  }
17890
18727
  this.#handle(value);
@@ -17943,7 +18780,7 @@ var OmpRpcSession = class {
17943
18780
  this.#armCommandTimeout(id, pending);
17944
18781
  }
17945
18782
  }
17946
- const outcome = value.aborted === true ? "cancelled" : isRecord7(value.result) ? "succeeded" : "failed";
18783
+ const outcome = value.aborted === true ? "cancelled" : isRecord9(value.result) ? "succeeded" : "failed";
17947
18784
  const event = {
17948
18785
  type: "compaction.completed",
17949
18786
  outcome,
@@ -17976,12 +18813,12 @@ var OmpRpcSession = class {
17976
18813
  this.#startAssistantMessage(active, value.message);
17977
18814
  return;
17978
18815
  }
17979
- if (value.type === "message_update" && isRecord7(value.assistantMessageEvent)) {
18816
+ if (value.type === "message_update" && isRecord9(value.assistantMessageEvent)) {
17980
18817
  const event = value.assistantMessageEvent;
17981
18818
  const eventType = String(event.type ?? "");
17982
18819
  const isThinking = eventType === "thinking_delta" || eventType === "reasoning_delta" || eventType === "thought_delta" || eventType === "thinking" || eventType === "reasoning";
17983
18820
  const isText = eventType === "text_delta" || eventType === "text" || eventType === "content_block_delta";
17984
- const delta = typeof event.delta === "string" ? event.delta : typeof event.thinking === "string" ? event.thinking : typeof event.reasoning === "string" ? event.reasoning : typeof event.text === "string" ? event.text : isRecord7(event.delta) && typeof event.delta.thinking === "string" ? event.delta.thinking : isRecord7(event.delta) && typeof event.delta.text === "string" ? event.delta.text : null;
18821
+ const delta = typeof event.delta === "string" ? event.delta : typeof event.thinking === "string" ? event.thinking : typeof event.reasoning === "string" ? event.reasoning : typeof event.text === "string" ? event.text : isRecord9(event.delta) && typeof event.delta.thinking === "string" ? event.delta.thinking : isRecord9(event.delta) && typeof event.delta.text === "string" ? event.delta.text : null;
17985
18822
  if (isThinking && delta !== null && delta.length > 0) {
17986
18823
  const messageId = this.#ensureAssistantMessage(active, value.message);
17987
18824
  active.reasoningMessageOpen = true;
@@ -18021,7 +18858,7 @@ var OmpRpcSession = class {
18021
18858
  if (value.type === "agent_end" && Array.isArray(value.messages)) {
18022
18859
  for (let index = value.messages.length - 1; index >= 0; index -= 1) {
18023
18860
  const message3 = value.messages[index];
18024
- if (!isRecord7(message3) || message3.role !== "assistant")
18861
+ if (!isRecord9(message3) || message3.role !== "assistant")
18025
18862
  continue;
18026
18863
  this.#finalizeAssistantMessage(active, message3);
18027
18864
  break;
@@ -18038,8 +18875,8 @@ var OmpRpcSession = class {
18038
18875
  if (value.type !== "subagent_lifecycle" && value.type !== "subagent_progress" && value.type !== "subagent_event") {
18039
18876
  return false;
18040
18877
  }
18041
- const payload = isRecord7(value.payload) ? value.payload : null;
18042
- const progressPayload = value.type === "subagent_progress" && payload && isRecord7(payload.progress) ? payload.progress : null;
18878
+ const payload = isRecord9(value.payload) ? value.payload : null;
18879
+ const progressPayload = value.type === "subagent_progress" && payload && isRecord9(payload.progress) ? payload.progress : null;
18043
18880
  const nativeIdValue = progressPayload?.id ?? payload?.id;
18044
18881
  if (!payload || !nonBlankString(nativeIdValue)) {
18045
18882
  throw new OmpRpcFaultError("protocolError", "Omp RPC Subagent frame has no stable ID");
@@ -18106,9 +18943,9 @@ var OmpRpcSession = class {
18106
18943
  return;
18107
18944
  const requestId = value.id;
18108
18945
  const method = value.method;
18109
- const title = value.title;
18946
+ const title2 = value.title;
18110
18947
  const timeoutMs = value.timeout;
18111
- if (typeof requestId !== "string" || requestId.length === 0 || typeof method !== "string" || typeof title !== "string" || title.length === 0 || timeoutMs !== void 0 && (typeof timeoutMs !== "number" || !Number.isFinite(timeoutMs) || timeoutMs < 0) || active.interactions.has(requestId)) {
18948
+ if (typeof requestId !== "string" || requestId.length === 0 || typeof method !== "string" || typeof title2 !== "string" || title2.length === 0 || timeoutMs !== void 0 && (typeof timeoutMs !== "number" || !Number.isFinite(timeoutMs) || timeoutMs < 0) || active.interactions.has(requestId)) {
18112
18949
  throw new OmpRpcFaultError("protocolError", "Omp RPC returned an invalid Interaction request");
18113
18950
  }
18114
18951
  let request;
@@ -18126,7 +18963,7 @@ var OmpRpcSession = class {
18126
18963
  request = {
18127
18964
  requestId,
18128
18965
  method,
18129
- title,
18966
+ title: title2,
18130
18967
  options: [...value.options],
18131
18968
  ...optionDetails ? { optionDetails } : {},
18132
18969
  ...typeof timeoutMs === "number" ? { timeoutMs } : {}
@@ -18138,7 +18975,7 @@ var OmpRpcSession = class {
18138
18975
  request = {
18139
18976
  requestId,
18140
18977
  method,
18141
- title,
18978
+ title: title2,
18142
18979
  message: value.message,
18143
18980
  ...typeof timeoutMs === "number" ? { timeoutMs } : {}
18144
18981
  };
@@ -18149,7 +18986,7 @@ var OmpRpcSession = class {
18149
18986
  request = {
18150
18987
  requestId,
18151
18988
  method,
18152
- title,
18989
+ title: title2,
18153
18990
  ...typeof value.placeholder === "string" ? { placeholder: value.placeholder } : {},
18154
18991
  ...typeof timeoutMs === "number" ? { timeoutMs } : {}
18155
18992
  };
@@ -18160,7 +18997,7 @@ var OmpRpcSession = class {
18160
18997
  request = {
18161
18998
  requestId,
18162
18999
  method: "editor",
18163
- title,
19000
+ title: title2,
18164
19001
  ...typeof value.prefill === "string" ? { prefill: value.prefill } : {},
18165
19002
  ...typeof timeoutMs === "number" ? { timeoutMs } : {}
18166
19003
  };
@@ -18604,6 +19441,7 @@ var OmpSubagentLifecycle = class {
18604
19441
 
18605
19442
  // dist/omp-adapter.js
18606
19443
  var ompHarnessId2 = harnessIdSchema.parse("omp");
19444
+ var IMPORT_FAILURE = "Omp Session discovery failed; check storage access and duplicate Session identities, then retry after closing native clients";
18607
19445
  var ompCommandCatalog = harnessCommandCatalogSchema.parse({
18608
19446
  commands: [
18609
19447
  {
@@ -18616,7 +19454,7 @@ var ompCommandCatalog = harnessCommandCatalogSchema.parse({
18616
19454
  ]
18617
19455
  });
18618
19456
  var DEFAULT_TOOL_OUTPUT_LIMIT = 64e3;
18619
- function isRecord8(value) {
19457
+ function isRecord10(value) {
18620
19458
  return typeof value === "object" && value !== null && !Array.isArray(value);
18621
19459
  }
18622
19460
  function errorMessage(error51) {
@@ -18631,7 +19469,7 @@ var OmpAdapterFaultError = class extends Error {
18631
19469
  }
18632
19470
  };
18633
19471
  function normalizedError(error51, fallbackCode) {
18634
- if (isRecord8(error51) && error51.code === "ENOENT") {
19472
+ if (isRecord10(error51) && error51.code === "ENOENT") {
18635
19473
  return { code: "notInstalled", message: errorMessage(error51), retryable: false };
18636
19474
  }
18637
19475
  if (error51 instanceof OmpAdapterFaultError)
@@ -18708,7 +19546,7 @@ function nativeModelForHistory(state) {
18708
19546
  return nativeModelFromState(state);
18709
19547
  }
18710
19548
  function sessionFileFromRef(ref) {
18711
- if (ref.harnessId !== ompHarnessId2 || !isRecord8(ref.locator) || typeof ref.locator.sessionFile !== "string" || ref.locator.sessionFile.length === 0) {
19549
+ if (ref.harnessId !== ompHarnessId2 || !isRecord10(ref.locator) || typeof ref.locator.sessionFile !== "string" || ref.locator.sessionFile.length === 0) {
18712
19550
  throw new Error("Omp Native Session Ref has no resumable Session file");
18713
19551
  }
18714
19552
  return ref.locator.sessionFile;
@@ -18723,35 +19561,35 @@ function toolFailure(toolName) {
18723
19561
  function nativeText(value) {
18724
19562
  if (typeof value === "string")
18725
19563
  return value;
18726
- if (!isRecord8(value) || !Array.isArray(value.content))
19564
+ if (!isRecord10(value) || !Array.isArray(value.content))
18727
19565
  return "";
18728
- return value.content.filter((content) => isRecord8(content) && content.type === "text" && typeof content.text === "string").map(({ text }) => text).join("");
19566
+ return value.content.filter((content) => isRecord10(content) && content.type === "text" && typeof content.text === "string").map(({ text: text2 }) => text2).join("");
18729
19567
  }
18730
19568
  function boundedOutput(value, limit) {
18731
- const text = nativeText(value);
18732
- if (text.length === 0)
19569
+ const text2 = nativeText(value);
19570
+ if (text2.length === 0)
18733
19571
  return void 0;
18734
- const truncated = text.length > limit;
19572
+ const truncated = text2.length > limit;
18735
19573
  return {
18736
- content: [{ type: "text", text: truncated ? text.slice(0, limit) : text }],
19574
+ content: [{ type: "text", text: truncated ? text2.slice(0, limit) : text2 }],
18737
19575
  ...truncated ? { truncated: true } : {}
18738
19576
  };
18739
19577
  }
18740
19578
  function outputText(output) {
18741
- return output?.content.filter((content) => content.type === "text").map(({ text }) => text).join("") ?? "";
19579
+ return output?.content.filter((content) => content.type === "text").map(({ text: text2 }) => text2).join("") ?? "";
18742
19580
  }
18743
19581
  function stringField2(value, key) {
18744
- if (!isRecord8(value))
19582
+ if (!isRecord10(value))
18745
19583
  return void 0;
18746
19584
  const field = value[key];
18747
19585
  if (typeof field === "string" && field.length > 0)
18748
19586
  return field;
18749
- if (isRecord8(value.input)) {
19587
+ if (isRecord10(value.input)) {
18750
19588
  const nested = value.input[key];
18751
19589
  if (typeof nested === "string" && nested.length > 0)
18752
19590
  return nested;
18753
19591
  }
18754
- if (isRecord8(value.arguments)) {
19592
+ if (isRecord10(value.arguments)) {
18755
19593
  const nested = value.arguments[key];
18756
19594
  if (typeof nested === "string" && nested.length > 0)
18757
19595
  return nested;
@@ -18759,7 +19597,7 @@ function stringField2(value, key) {
18759
19597
  return void 0;
18760
19598
  }
18761
19599
  function numberField(value, key) {
18762
- if (!isRecord8(value))
19600
+ if (!isRecord10(value))
18763
19601
  return void 0;
18764
19602
  const field = value[key];
18765
19603
  return typeof field === "number" || field === null ? field : void 0;
@@ -18770,10 +19608,10 @@ function stripDiffPrefix(pathString) {
18770
19608
  return pathString.startsWith("a/") || pathString.startsWith("b/") ? pathString.slice(2) : pathString;
18771
19609
  }
18772
19610
  function displayPath(nativePath, cwd) {
18773
- const resolvedCwd = path4.resolve(cwd);
18774
- const resolvedPath = path4.isAbsolute(nativePath) ? path4.resolve(nativePath) : path4.resolve(cwd, nativePath);
18775
- const relative = path4.relative(resolvedCwd, resolvedPath);
18776
- const inside = relative.length > 0 && relative !== ".." && !relative.startsWith(`..${path4.sep}`);
19611
+ const resolvedCwd = path6.resolve(cwd);
19612
+ const resolvedPath = path6.isAbsolute(nativePath) ? path6.resolve(nativePath) : path6.resolve(cwd, nativePath);
19613
+ const relative = path6.relative(resolvedCwd, resolvedPath);
19614
+ const inside = relative.length > 0 && relative !== ".." && !relative.startsWith(`..${path6.sep}`);
18777
19615
  const selected = inside ? relative : resolvedPath;
18778
19616
  const normalized = selected.replaceAll("\\", "/");
18779
19617
  if (normalized.length === 0 || normalized === ".")
@@ -18798,7 +19636,7 @@ function fileMutatingKind(toolName) {
18798
19636
  return null;
18799
19637
  }
18800
19638
  function nestedToolString(value, keys) {
18801
- if (!isRecord8(value))
19639
+ if (!isRecord10(value))
18802
19640
  return void 0;
18803
19641
  for (const key of keys) {
18804
19642
  const field = value[key];
@@ -18813,14 +19651,14 @@ function nestedToolString(value, keys) {
18813
19651
  return void 0;
18814
19652
  }
18815
19653
  function patchFromResult(result) {
18816
- if (!isRecord8(result))
19654
+ if (!isRecord10(result))
18817
19655
  return void 0;
18818
19656
  for (const key of ["patch", "diff", "unifiedDiff"]) {
18819
19657
  const field = result[key];
18820
19658
  if (typeof field === "string" && field.length > 0)
18821
19659
  return field;
18822
19660
  }
18823
- if (isRecord8(result.details)) {
19661
+ if (isRecord10(result.details)) {
18824
19662
  for (const key of ["patch", "diff", "unifiedDiff"]) {
18825
19663
  const field = result.details[key];
18826
19664
  if (typeof field === "string" && field.length > 0)
@@ -19189,8 +20027,8 @@ var OmpHarnessSession = class {
19189
20027
  }
19190
20028
  };
19191
20029
  }
19192
- const text = command.input.map((input) => input.text).join("\n");
19193
- if (text.length === 0) {
20030
+ const text2 = command.input.map((input) => input.text).join("\n");
20031
+ if (text2.length === 0) {
19194
20032
  return {
19195
20033
  ok: false,
19196
20034
  error: {
@@ -19256,7 +20094,7 @@ var OmpHarnessSession = class {
19256
20094
  this.#active = active;
19257
20095
  this.#event({ type: "turn.started", turnId: command.turnId });
19258
20096
  this.#event({ type: "item.started", turnId: command.turnId, item });
19259
- void transport.runTurn(text, (event) => this.#handleTurnEvent(active, event)).then(async (result) => {
20097
+ void transport.runTurn(text2, (event) => this.#handleTurnEvent(active, event)).then(async (result) => {
19260
20098
  try {
19261
20099
  const identity = await this.#completedTurnIdentity(active, transport);
19262
20100
  this.#completeTurn(active, result.cancelled ? {
@@ -20052,16 +20890,16 @@ var OmpHarnessSession = class {
20052
20890
  active.agentMessageId = messageId;
20053
20891
  active.sawAssistantMessage = true;
20054
20892
  }
20055
- #appendText(active, text) {
20893
+ #appendText(active, text2) {
20056
20894
  if (active.agentMessageId === null || !active.agentItem) {
20057
20895
  throw new Error("Omp Assistant text arrived outside an active message");
20058
20896
  }
20059
- active.agentItem = { ...active.agentItem, text: active.agentItem.text + text };
20897
+ active.agentItem = { ...active.agentItem, text: active.agentItem.text + text2 };
20060
20898
  this.#event({
20061
20899
  type: "item.updated",
20062
20900
  turnId: active.command.turnId,
20063
20901
  itemId: active.agentItem.itemId,
20064
- update: { type: "text.append", text }
20902
+ update: { type: "text.append", text: text2 }
20065
20903
  });
20066
20904
  }
20067
20905
  #completeAgentItem(active, outcome, completeEmpty) {
@@ -20072,8 +20910,8 @@ var OmpHarnessSession = class {
20072
20910
  active.agentItem = null;
20073
20911
  this.#completeItem(active, item, outcome);
20074
20912
  }
20075
- #appendReasoning(active, text) {
20076
- if (text.length === 0)
20913
+ #appendReasoning(active, text2) {
20914
+ if (text2.length === 0)
20077
20915
  return;
20078
20916
  if (!active.reasoningItem) {
20079
20917
  active.reasoningItem = {
@@ -20089,13 +20927,13 @@ var OmpHarnessSession = class {
20089
20927
  }
20090
20928
  active.reasoningItem = {
20091
20929
  ...active.reasoningItem,
20092
- text: active.reasoningItem.text + text
20930
+ text: active.reasoningItem.text + text2
20093
20931
  };
20094
20932
  this.#event({
20095
20933
  type: "item.updated",
20096
20934
  turnId: active.command.turnId,
20097
20935
  itemId: active.reasoningItem.itemId,
20098
- update: { type: "text.append", text }
20936
+ update: { type: "text.append", text: text2 }
20099
20937
  });
20100
20938
  }
20101
20939
  #completeReasoning(active, outcome) {
@@ -20339,8 +21177,36 @@ var OmpAdapter = class {
20339
21177
  }
20340
21178
  }
20341
21179
  };
21180
+ sessionImport = Object.freeze({
21181
+ listCandidates: async () => {
21182
+ const result = await this.#readNative((signal) => this.#importIndex.list(signal), IMPORT_FAILURE);
21183
+ return result.ok ? { ok: true, value: result.value.map(({ candidate }) => candidate) } : result;
21184
+ },
21185
+ resolveCandidate: async (nativeSessionId) => {
21186
+ const result = await this.#readNative((signal) => this.#importIndex.resolve(nativeSessionId, signal), IMPORT_FAILURE);
21187
+ if (!result.ok)
21188
+ return result;
21189
+ return result.value ? { ok: true, value: result.value } : {
21190
+ ok: false,
21191
+ error: {
21192
+ code: "sessionNotFound",
21193
+ message: "Omp Session is no longer importable",
21194
+ retryable: false
21195
+ }
21196
+ };
21197
+ }
21198
+ });
21199
+ nativeUsage = Object.freeze({
21200
+ read: (cursor, onProgress) => this.#readNative((signal) => readOmpNativeUsage(this.#environment, cursor, signal, onProgress), "Omp usage records could not be read; check storage access and retry"),
21201
+ resumeCommand: (nativeSessionId) => `omp --resume ${nativeSessionId}`
21202
+ });
20342
21203
  #closeTimeoutMs;
20343
21204
  #createTransport;
21205
+ #environment;
21206
+ #importIndex;
21207
+ /** Aborts reads of native session files when the Adapter closes. */
21208
+ #readAbort = new AbortController();
21209
+ #readRequests = /* @__PURE__ */ new Set();
20344
21210
  #inspectionCache = /* @__PURE__ */ new Map();
20345
21211
  #inspectionInFlight = /* @__PURE__ */ new Map();
20346
21212
  #inspections = /* @__PURE__ */ new Set();
@@ -20352,9 +21218,23 @@ var OmpAdapter = class {
20352
21218
  createTransport: (sessionOptions) => new OmpRpcSession({ ...options, ...sessionOptions })
20353
21219
  }) {
20354
21220
  this.#createTransport = dependencies.createTransport;
21221
+ this.#environment = { ...process.env, ...options.environment };
21222
+ this.#importIndex = new OmpSessionImportIndex(this.#environment);
20355
21223
  this.#closeTimeoutMs = options.closeTimeoutMs ?? 2e3;
20356
21224
  this.#toolOutputLimit = options.toolOutputLimit ?? DEFAULT_TOOL_OUTPUT_LIMIT;
20357
21225
  }
21226
+ /** Reads native session files; the Adapter's close aborts and waits for it. */
21227
+ #readNative(operation, failureMessage) {
21228
+ if (this.#closePromise) {
21229
+ return Promise.resolve({ ok: false, error: invalidState("Omp Adapter is closed") });
21230
+ }
21231
+ const request = operation(this.#readAbort.signal).then((value) => ({ ok: true, value })).catch(() => ({
21232
+ ok: false,
21233
+ error: { code: "unavailable", message: failureMessage, retryable: true }
21234
+ })).finally(() => this.#readRequests.delete(request));
21235
+ this.#readRequests.add(request);
21236
+ return request;
21237
+ }
20358
21238
  async inspect(input = {}) {
20359
21239
  if (this.#closePromise) {
20360
21240
  return {
@@ -20608,7 +21488,9 @@ var OmpAdapter = class {
20608
21488
  }
20609
21489
  close() {
20610
21490
  if (!this.#closePromise) {
21491
+ this.#readAbort.abort();
20611
21492
  this.#closePromise = Promise.all([
21493
+ ...this.#readRequests,
20612
21494
  ...[...this.#inspections].map((transport) => transport.close()),
20613
21495
  ...[...this.#sessions].map((session) => session.close())
20614
21496
  ]).then(() => void 0);