@liberseek/boft-cli-win32-arm64 0.7.9 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/README.md +1 -1
  2. package/THIRD_PARTY_NOTICES.txt +8 -0
  3. package/app/codexhost-distribution.json +1 -1
  4. package/app/console-server.mjs +232 -21
  5. package/app/console-web.js +9669 -5390
  6. package/app/desktop-controller.mjs +252 -42
  7. package/app/host-runtime.mjs +5361 -1491
  8. package/app/plugins/antigravity/manifest.json +18 -1
  9. package/app/plugins/antigravity/plugin.mjs +276 -42
  10. package/app/plugins/claude-code/manifest.json +28 -0
  11. package/app/plugins/claude-code/plugin.mjs +1055 -391
  12. package/app/plugins/codebuddy/manifest.json +17 -0
  13. package/app/plugins/codebuddy/plugin.mjs +5931 -5358
  14. package/app/plugins/codex-usage/manifest.json +9 -0
  15. package/app/plugins/codex-usage/plugin.mjs +16750 -0
  16. package/app/plugins/cursor-cli/manifest.json +18 -1
  17. package/app/plugins/cursor-cli/plugin.mjs +351 -77
  18. package/app/plugins/deepseek-harness/assets/icon.svg +1 -0
  19. package/app/plugins/deepseek-harness/manifest.json +35 -2
  20. package/app/plugins/deepseek-harness/plugin.mjs +798 -242
  21. package/app/plugins/enabled.json +2 -1
  22. package/app/plugins/grok/manifest.json +21 -1
  23. package/app/plugins/grok/plugin.mjs +898 -268
  24. package/app/plugins/hermes/assets/icon.png +0 -0
  25. package/app/plugins/hermes/manifest.json +30 -2
  26. package/app/plugins/hermes/plugin.mjs +278 -33
  27. package/app/plugins/kimi-code/assets/icon.svg +5 -0
  28. package/app/plugins/kimi-code/manifest.json +25 -2
  29. package/app/plugins/kimi-code/plugin.mjs +555 -36
  30. package/app/plugins/kiro-cli/assets/kiro-agent.svg +11 -0
  31. package/app/plugins/kiro-cli/manifest.json +18 -1
  32. package/app/plugins/kiro-cli/plugin.mjs +284 -22
  33. package/app/plugins/muse/manifest.json +18 -1
  34. package/app/plugins/muse/plugin.mjs +251 -17
  35. package/app/plugins/omp/manifest.json +21 -1
  36. package/app/plugins/omp/plugin.mjs +2741 -1960
  37. package/app/plugins/opencode/manifest.json +18 -1
  38. package/app/plugins/opencode/plugin.mjs +694 -147
  39. package/app/plugins/pi/manifest.json +32 -0
  40. package/app/plugins/pi/plugin.mjs +3396 -2841
  41. package/app/plugins/qoder/manifest.json +18 -1
  42. package/app/plugins/qoder/plugin.mjs +585 -81
  43. package/app/plugins/qoder-cn/manifest.json +18 -1
  44. package/app/plugins/qoder-cn/plugin.mjs +585 -81
  45. package/app/plugins/workbuddy/manifest.json +18 -0
  46. package/app/plugins/workbuddy/plugin.mjs +6317 -5746
  47. package/app/plugins/zcode/manifest.json +19 -1
  48. package/app/plugins/zcode/plugin.mjs +1066 -260
  49. package/app/renderer-extension.js +2731 -2427
  50. package/bin/boft.exe +0 -0
  51. package/libexec/boft-node-repl.exe +0 -0
  52. package/libexec/boft-shim.exe +0 -0
  53. package/libexec/boft-updater.exe +0 -0
  54. package/licenses/Cordis-LICENSE.txt +21 -0
  55. package/licenses/Cosmokit-LICENSE.txt +21 -0
  56. package/package.json +1 -1
  57. package/app/plugins/kiro-cli/assets/icon.svg +0 -5
@@ -4100,7 +4100,7 @@ async function npmInstallation(command, packages, environment) {
4100
4100
  const npm = resolveHarnessExecutable({ id: "npm", command: "npm", installRoots: { posix: [], windows: [] } }, { environment: env });
4101
4101
  let globalInstall = modules === globalRoot;
4102
4102
  if (process.platform === "win32") {
4103
- const project = (await Promise.all(["package.json", "package-lock.json", "npm-shrinkwrap.json"].map((file2) => readFile(path4.join(prefix, file2), "utf8").then(() => true, (error51) => error51.code !== "ENOENT")))).some(Boolean);
4103
+ const project2 = (await Promise.all(["package.json", "package-lock.json", "npm-shrinkwrap.json"].map((file2) => readFile(path4.join(prefix, file2), "utf8").then(() => true, (error51) => error51.code !== "ENOENT")))).some(Boolean);
4104
4104
  const bins = typeof metadata.bin === "string" ? { [name.split("/").at(-1) ?? name]: metadata.bin } : metadata.bin ?? {};
4105
4105
  const launchers = await Promise.all(Object.entries(bins).map(async ([bin, entry]) => {
4106
4106
  if (path4.basename(bin) !== bin || entry.includes(".."))
@@ -4111,7 +4111,7 @@ async function npmInstallation(command, packages, environment) {
4111
4111
  const shim = await readFile(path4.join(prefix, `${bin}.cmd`), "utf8").catch(() => "");
4112
4112
  return referencesNpmBin(shim, name, entry);
4113
4113
  }));
4114
- globalInstall = globalInstall && !project && launchers.some(Boolean);
4114
+ globalInstall = globalInstall && !project2 && launchers.some(Boolean);
4115
4115
  }
4116
4116
  const canUpdate = globalInstall && !!npm;
4117
4117
  return {
@@ -4191,6 +4191,48 @@ function createHarnessInstaller(environment, source) {
4191
4191
  };
4192
4192
  }
4193
4193
 
4194
+ // dist/modern/usage-statistics.js
4195
+ import os2 from "node:os";
4196
+ import path5 from "node:path";
4197
+ import { lstat, readFile as readFile2, readdir } from "node:fs/promises";
4198
+ import { zstdDecompressSync } from "node:zlib";
4199
+
4200
+ // ../../harness-adapter/dist/usage-statistics.js
4201
+ var MAX_SESSION_ID_LENGTH = 512;
4202
+ var MAX_CWD_LENGTH = 4096;
4203
+ function sessionIdOk(value) {
4204
+ return typeof value === "string" && value.length > 0 && value.length <= MAX_SESSION_ID_LENGTH;
4205
+ }
4206
+ function cwdOk(value) {
4207
+ return typeof value === "string" && value.length > 0 && value.length <= MAX_CWD_LENGTH && !value.includes("\0") && (value.startsWith("/") || /^[A-Za-z]:[\\/]/u.test(value) || value.startsWith("\\\\"));
4208
+ }
4209
+ function withUsageSession(entry, session) {
4210
+ const sessionId = sessionIdOk(session.sessionId) ? session.sessionId : void 0;
4211
+ const cwd = cwdOk(session.cwd) ? session.cwd : void 0;
4212
+ if (sessionId === void 0 && cwd === void 0)
4213
+ return entry;
4214
+ return {
4215
+ ...entry,
4216
+ ...sessionId !== void 0 ? { sessionId } : {},
4217
+ ...cwd !== void 0 ? { cwd } : {}
4218
+ };
4219
+ }
4220
+ function usageEntryFromRequest(request, occurredAtMs) {
4221
+ if (!Number.isSafeInteger(occurredAtMs) || occurredAtMs <= 0)
4222
+ return null;
4223
+ return {
4224
+ id: request.requestId,
4225
+ occurredAtMs,
4226
+ ...request.model !== void 0 ? { model: request.model } : {},
4227
+ inputTokens: request.inputTokens,
4228
+ ...request.cachedInputTokens !== void 0 ? { cachedInputTokens: request.cachedInputTokens } : {},
4229
+ ...request.cacheWriteInputTokens !== void 0 ? { cacheWriteInputTokens: request.cacheWriteInputTokens } : {},
4230
+ ...request.cacheWrite1hInputTokens !== void 0 ? { cacheWrite1hInputTokens: request.cacheWrite1hInputTokens } : {},
4231
+ outputTokens: request.outputTokens,
4232
+ ...request.reasoningOutputTokens !== void 0 ? { reasoningOutputTokens: request.reasoningOutputTokens } : {}
4233
+ };
4234
+ }
4235
+
4194
4236
  // ../../../node_modules/zod/v4/classic/external.js
4195
4237
  var external_exports = {};
4196
4238
  __export(external_exports, {
@@ -4957,10 +4999,10 @@ function mergeDefs(...defs) {
4957
4999
  function cloneDef(schema) {
4958
5000
  return mergeDefs(schema._zod.def);
4959
5001
  }
4960
- function getElementAtPath(obj, path8) {
4961
- if (!path8)
5002
+ function getElementAtPath(obj, path9) {
5003
+ if (!path9)
4962
5004
  return obj;
4963
- return path8.reduce((acc, key) => acc?.[key], obj);
5005
+ return path9.reduce((acc, key) => acc?.[key], obj);
4964
5006
  }
4965
5007
  function promiseAllObject(promisesObj) {
4966
5008
  const keys = Object.keys(promisesObj);
@@ -5369,11 +5411,11 @@ function explicitlyAborted(x, startIndex = 0) {
5369
5411
  }
5370
5412
  return false;
5371
5413
  }
5372
- function prefixIssues(path8, issues) {
5414
+ function prefixIssues(path9, issues) {
5373
5415
  return issues.map((iss) => {
5374
5416
  var _a3;
5375
5417
  (_a3 = iss).path ?? (_a3.path = []);
5376
- iss.path.unshift(path8);
5418
+ iss.path.unshift(path9);
5377
5419
  return iss;
5378
5420
  });
5379
5421
  }
@@ -5520,16 +5562,16 @@ function flattenError(error51, mapper = (issue2) => issue2.message) {
5520
5562
  }
5521
5563
  function formatError(error51, mapper = (issue2) => issue2.message) {
5522
5564
  const fieldErrors = { _errors: [] };
5523
- const processError = (error52, path8 = []) => {
5565
+ const processError = (error52, path9 = []) => {
5524
5566
  for (const issue2 of error52.issues) {
5525
5567
  if (issue2.code === "invalid_union" && issue2.errors.length) {
5526
- issue2.errors.map((issues) => processError({ issues }, [...path8, ...issue2.path]));
5568
+ issue2.errors.map((issues) => processError({ issues }, [...path9, ...issue2.path]));
5527
5569
  } else if (issue2.code === "invalid_key") {
5528
- processError({ issues: issue2.issues }, [...path8, ...issue2.path]);
5570
+ processError({ issues: issue2.issues }, [...path9, ...issue2.path]);
5529
5571
  } else if (issue2.code === "invalid_element") {
5530
- processError({ issues: issue2.issues }, [...path8, ...issue2.path]);
5572
+ processError({ issues: issue2.issues }, [...path9, ...issue2.path]);
5531
5573
  } else {
5532
- const fullpath = [...path8, ...issue2.path];
5574
+ const fullpath = [...path9, ...issue2.path];
5533
5575
  if (fullpath.length === 0) {
5534
5576
  fieldErrors._errors.push(mapper(issue2));
5535
5577
  } else {
@@ -5556,17 +5598,17 @@ function formatError(error51, mapper = (issue2) => issue2.message) {
5556
5598
  }
5557
5599
  function treeifyError(error51, mapper = (issue2) => issue2.message) {
5558
5600
  const result = { errors: [] };
5559
- const processError = (error52, path8 = []) => {
5601
+ const processError = (error52, path9 = []) => {
5560
5602
  var _a3, _b;
5561
5603
  for (const issue2 of error52.issues) {
5562
5604
  if (issue2.code === "invalid_union" && issue2.errors.length) {
5563
- issue2.errors.map((issues) => processError({ issues }, [...path8, ...issue2.path]));
5605
+ issue2.errors.map((issues) => processError({ issues }, [...path9, ...issue2.path]));
5564
5606
  } else if (issue2.code === "invalid_key") {
5565
- processError({ issues: issue2.issues }, [...path8, ...issue2.path]);
5607
+ processError({ issues: issue2.issues }, [...path9, ...issue2.path]);
5566
5608
  } else if (issue2.code === "invalid_element") {
5567
- processError({ issues: issue2.issues }, [...path8, ...issue2.path]);
5609
+ processError({ issues: issue2.issues }, [...path9, ...issue2.path]);
5568
5610
  } else {
5569
- const fullpath = [...path8, ...issue2.path];
5611
+ const fullpath = [...path9, ...issue2.path];
5570
5612
  if (fullpath.length === 0) {
5571
5613
  result.errors.push(mapper(issue2));
5572
5614
  continue;
@@ -5598,8 +5640,8 @@ function treeifyError(error51, mapper = (issue2) => issue2.message) {
5598
5640
  }
5599
5641
  function toDotPath(_path) {
5600
5642
  const segs = [];
5601
- const path8 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
5602
- for (const seg of path8) {
5643
+ const path9 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
5644
+ for (const seg of path9) {
5603
5645
  if (typeof seg === "number")
5604
5646
  segs.push(`[${seg}]`);
5605
5647
  else if (typeof seg === "symbol")
@@ -8827,8 +8869,8 @@ function az_default() {
8827
8869
  }
8828
8870
 
8829
8871
  // ../../../node_modules/zod/v4/locales/be.js
8830
- function getBelarusianPlural(count, one, few, many) {
8831
- const absCount = Math.abs(count);
8872
+ function getBelarusianPlural(count3, one, few, many) {
8873
+ const absCount = Math.abs(count3);
8832
8874
  const lastDigit = absCount % 10;
8833
8875
  const lastTwoDigits = absCount % 100;
8834
8876
  if (lastTwoDigits >= 11 && lastTwoDigits <= 19) {
@@ -10906,8 +10948,8 @@ function hu_default() {
10906
10948
  }
10907
10949
 
10908
10950
  // ../../../node_modules/zod/v4/locales/hy.js
10909
- function getArmenianPlural(count, one, many) {
10910
- return Math.abs(count) === 1 ? one : many;
10951
+ function getArmenianPlural(count3, one, many) {
10952
+ return Math.abs(count3) === 1 ? one : many;
10911
10953
  }
10912
10954
  function withDefiniteArticle(word) {
10913
10955
  if (!word)
@@ -13035,8 +13077,8 @@ function ro_default() {
13035
13077
  }
13036
13078
 
13037
13079
  // ../../../node_modules/zod/v4/locales/ru.js
13038
- function getRussianPlural(count, one, few, many) {
13039
- const absCount = Math.abs(count);
13080
+ function getRussianPlural(count3, one, few, many) {
13081
+ const absCount = Math.abs(count3);
13040
13082
  const lastDigit = absCount % 10;
13041
13083
  const lastTwoDigits = absCount % 100;
13042
13084
  if (lastTwoDigits >= 11 && lastTwoDigits <= 19) {
@@ -18291,13 +18333,13 @@ function resolveRef(ref, ctx) {
18291
18333
  if (!ref.startsWith("#")) {
18292
18334
  throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
18293
18335
  }
18294
- const path8 = ref.slice(1).split("/").filter(Boolean);
18295
- if (path8.length === 0) {
18336
+ const path9 = ref.slice(1).split("/").filter(Boolean);
18337
+ if (path9.length === 0) {
18296
18338
  return ctx.rootSchema;
18297
18339
  }
18298
18340
  const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
18299
- if (path8[0] === defsKey) {
18300
- const key = path8[1];
18341
+ if (path9[0] === defsKey) {
18342
+ const key = path9[1];
18301
18343
  if (!key || !ctx.defs[key]) {
18302
18344
  throw new Error(`Reference not found: ${ref}`);
18303
18345
  }
@@ -18705,6 +18747,15 @@ function date4(params) {
18705
18747
  // ../../../node_modules/zod/v4/classic/external.js
18706
18748
  config(en_default());
18707
18749
 
18750
+ // ../../shared-contracts/dist/delegation-read.js
18751
+ var REMOTE_THREAD_REPLY_MAX_BYTES = 16 * 1024 * 1024;
18752
+ var delegationReadParamsSchema = external_exports.strictObject({
18753
+ threadId: external_exports.string().min(1).max(1024),
18754
+ view: external_exports.enum(["result", "messages"]),
18755
+ cursor: external_exports.string().min(1).max(8192).optional(),
18756
+ limit: external_exports.number().int().min(1).max(100).optional()
18757
+ });
18758
+
18708
18759
  // ../../shared-contracts/dist/credential-imports.js
18709
18760
  var credentialSourceSchema = external_exports.object({
18710
18761
  id: external_exports.string().min(1).max(256),
@@ -18775,6 +18826,153 @@ var harnessDisplaySetSchema = external_exports.strictObject({
18775
18826
  initializeOnly: external_exports.boolean().optional()
18776
18827
  });
18777
18828
 
18829
+ // ../../shared-contracts/dist/model-price-overrides.js
18830
+ var usdPerMillionTokens = external_exports.number().finite().nonnegative();
18831
+ var modelPriceOverrideSchema = external_exports.strictObject({
18832
+ input: usdPerMillionTokens,
18833
+ output: usdPerMillionTokens,
18834
+ cacheRead: usdPerMillionTokens.optional(),
18835
+ cacheWrite: usdPerMillionTokens.optional(),
18836
+ cacheWrite1h: usdPerMillionTokens.optional()
18837
+ });
18838
+ var modelPriceKeySchema = external_exports.string().max(512).refine((key) => key.trim() === key && key.length > 0, "Model ID is required");
18839
+ var modelPriceOverridesSchema = external_exports.strictObject({
18840
+ /** Absolute path of the Host's `pricing.json`. */
18841
+ path: external_exports.string(),
18842
+ entries: external_exports.array(external_exports.strictObject({ key: external_exports.string(), price: modelPriceOverrideSchema })),
18843
+ /** Why the existing file is unusable; the Host then ignores it and refuses to overwrite it. */
18844
+ error: external_exports.string().nullable()
18845
+ });
18846
+ var modelPriceOverridesGetSchema = external_exports.strictObject({});
18847
+ var modelPriceOverridesSetSchema = external_exports.strictObject({
18848
+ key: modelPriceKeySchema,
18849
+ price: modelPriceOverrideSchema.nullable(),
18850
+ previousKey: modelPriceKeySchema.optional()
18851
+ });
18852
+ var modelPriceDefaultParamsSchema = external_exports.strictObject({
18853
+ model: modelPriceKeySchema
18854
+ });
18855
+ var modelPriceSuggestionSchema = external_exports.strictObject({
18856
+ /** Verified from catalog canonical links, not inferred from names or equal prices. */
18857
+ official: external_exports.boolean().optional(),
18858
+ canonicalModelId: external_exports.string().min(1).optional(),
18859
+ provider: external_exports.string().min(1).max(512),
18860
+ model: external_exports.string().min(1).max(512),
18861
+ price: modelPriceOverrideSchema
18862
+ });
18863
+ var modelPriceDefaultResultSchema = external_exports.strictObject({
18864
+ price: modelPriceOverrideSchema.nullable(),
18865
+ /** Local catalog suggestions only; never used automatically for pricing. */
18866
+ suggestions: external_exports.array(modelPriceSuggestionSchema).max(6).optional()
18867
+ });
18868
+
18869
+ // ../../shared-contracts/dist/usage-statistics.js
18870
+ var USAGE_STATISTICS_RANGES = ["today", "7d", "30d", "90d", "all"];
18871
+ var count = external_exports.number().int().min(0).max(Number.MAX_SAFE_INTEGER);
18872
+ var localDate = external_exports.string().regex(/^\d{4}-\d{2}-\d{2}$/u);
18873
+ var harness = external_exports.string().min(1).max(128);
18874
+ var model = external_exports.string().min(1).max(512);
18875
+ var project = external_exports.string().min(1).max(4096);
18876
+ var usageStatisticsParamsSchema = external_exports.strictObject({
18877
+ range: external_exports.enum(USAGE_STATISTICS_RANGES),
18878
+ harness: harness.optional(),
18879
+ model: model.nullable().optional(),
18880
+ project: project.nullable().optional(),
18881
+ /** One local date inside the range. */
18882
+ date: localDate.optional()
18883
+ });
18884
+ var usageStatisticsTotalsSchema = external_exports.strictObject({
18885
+ requests: count,
18886
+ inputTokens: count,
18887
+ cachedInputTokens: count,
18888
+ cacheWriteInputTokens: count,
18889
+ cacheKnownInputTokens: count,
18890
+ outputTokens: count,
18891
+ reasoningOutputTokens: count,
18892
+ /** USD at the public price, summed over the priced requests only. */
18893
+ costUsd: external_exports.number().finite().min(0),
18894
+ /** Requests without a price (or the cache data the price needs); not in `costUsd`. */
18895
+ unpricedRequests: count,
18896
+ /**
18897
+ * Requests whose storage gave no token counts: counted as requests, with neither tokens nor
18898
+ * cost, and not as unpriced.
18899
+ */
18900
+ unmeteredRequests: count
18901
+ });
18902
+ var totals = usageStatisticsTotalsSchema.shape;
18903
+ var usageStatisticsSessionSchema = external_exports.strictObject({
18904
+ harness,
18905
+ sessionId: external_exports.string().min(1).max(512),
18906
+ project: project.nullable(),
18907
+ /** Models the session used, most requests first. */
18908
+ models: external_exports.array(model).max(16),
18909
+ firstAtMs: count,
18910
+ lastAtMs: count,
18911
+ ...totals
18912
+ });
18913
+ var usageStatisticsResultSchema = external_exports.strictObject({
18914
+ range: external_exports.enum(USAGE_STATISTICS_RANGES),
18915
+ /** First local date of the range; null for all time. */
18916
+ from: localDate.nullable(),
18917
+ to: localDate,
18918
+ /** The filters these figures apply, echoed so a late answer to older filters is recognised. */
18919
+ filters: external_exports.strictObject({
18920
+ harness: harness.nullable(),
18921
+ model: model.nullable(),
18922
+ unknownModel: external_exports.boolean(),
18923
+ project: project.nullable(),
18924
+ unknownProject: external_exports.boolean(),
18925
+ date: localDate.nullable()
18926
+ }),
18927
+ /** Reading of native storage: incomplete while the first read, or a refresh, is under way. */
18928
+ reading: external_exports.strictObject({ complete: external_exports.boolean(), sources: count, read: count }),
18929
+ /** Harnesses whose storage could not be read; their part is missing, the rest is complete. */
18930
+ failures: external_exports.array(external_exports.strictObject({ harness, message: external_exports.string().max(2048) })).max(256),
18931
+ /** Every value seen in the range, ignoring the filters, to choose filters from. */
18932
+ options: external_exports.strictObject({
18933
+ harnesses: external_exports.array(harness).max(256),
18934
+ models: external_exports.array(model.nullable()).max(4096),
18935
+ projects: external_exports.array(project.nullable()).max(4096)
18936
+ }),
18937
+ /** Current display metadata, scoped by Harness. Never a pricing or filter identity.
18938
+ * Optional for older Hosts; missing/conflicting labels fall back to the native model ID.
18939
+ */
18940
+ modelLabels: external_exports.array(external_exports.strictObject({ harness, model, label: model })).max(4096).optional(),
18941
+ /** Native credits, all filters applied, never combined across Harnesses or treated as USD.
18942
+ * Only groups with at least one reported value appear; reportedRequests exposes partial data.
18943
+ */
18944
+ credits: external_exports.array(external_exports.strictObject({
18945
+ harness,
18946
+ model: model.nullable(),
18947
+ credits: external_exports.number().finite().min(0),
18948
+ reportedRequests: count,
18949
+ requests: count
18950
+ })).max(4096).optional(),
18951
+ /** All filters applied. */
18952
+ totals: usageStatisticsTotalsSchema,
18953
+ /** Each date and Harness of the range: every filter except the day. */
18954
+ daily: external_exports.array(external_exports.strictObject({ date: localDate, harness, ...totals })).max(2e5),
18955
+ /** Local weekday (0 = Sunday) and hour, all filters applied. */
18956
+ hourly: external_exports.array(external_exports.strictObject({
18957
+ weekday: external_exports.number().int().min(0).max(6),
18958
+ hour: external_exports.number().int().min(0).max(23),
18959
+ ...totals
18960
+ })).max(168),
18961
+ byHarness: external_exports.array(external_exports.strictObject({ harness, ...totals })).max(256),
18962
+ byModel: external_exports.array(external_exports.strictObject({
18963
+ model: model.nullable(),
18964
+ ...totals,
18965
+ /** Requests priced by what the Harness recorded they cost, not by a price list. */
18966
+ harnessPricedRequests: count
18967
+ })).max(4096),
18968
+ byProject: external_exports.array(external_exports.strictObject({ project: project.nullable(), ...totals })).max(4096),
18969
+ /**
18970
+ * The sessions that spent the most, by cost and by tokens without cache, all filters applied;
18971
+ * requests without a native session are not listed here but count everywhere else.
18972
+ */
18973
+ sessions: external_exports.array(usageStatisticsSessionSchema).max(100)
18974
+ });
18975
+
18778
18976
  // ../../shared-contracts/dist/ids.js
18779
18977
  var opaqueIdSchema = external_exports.string().refine((value) => value.trim().length > 0, {
18780
18978
  message: "Identifier must not be empty or whitespace"
@@ -18796,13 +18994,40 @@ var HARNESS_PLUGIN_LIMIT = 128;
18796
18994
  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);
18797
18995
  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");
18798
18996
  var documentationUrlSchema = external_exports.url().refine((value) => /^https:\/\/[^/?#@]+(?:[/?#]|$)/iu.test(value), "Plugin documentation links must be credential-free HTTPS URLs");
18997
+ var localizedTextSchema = external_exports.object({ en: external_exports.string().max(4096), "zh-CN": external_exports.string().max(4096).optional() }).strict();
18998
+ var harnessInstallationGuideSchema = external_exports.object({
18999
+ commands: external_exports.array(external_exports.object({ terminal: external_exports.string().max(256), command: external_exports.string().max(4096) }).strict()).max(8),
19000
+ before: localizedTextSchema.optional(),
19001
+ after: localizedTextSchema.optional(),
19002
+ downloads: external_exports.array(external_exports.object({ label: external_exports.string().max(128), url: documentationUrlSchema }).strict()).max(8).optional()
19003
+ }).strict();
18799
19004
  var pluginPresentationShape = {
18800
19005
  id: harnessPluginIdSchema,
18801
19006
  name: external_exports.string().trim().min(1).max(128),
18802
19007
  version: external_exports.string().min(1).max(128),
19008
+ /** Capability-only plugin; omitted for existing session-capable plugins. */
19009
+ kind: external_exports.literal("usage").optional(),
19010
+ /** Original image styling or bounded vector paths; never arbitrary CSS/SVG markup. */
19011
+ iconStyle: external_exports.object({
19012
+ vector: external_exports.object({
19013
+ viewBox: external_exports.string().max(128).regex(/^-?\d+(?:\.\d+)?(?: +-?\d+(?:\.\d+)?){3}$/u),
19014
+ color: external_exports.string().regex(/^(?:currentColor|#[a-f0-9]{6})$/iu),
19015
+ paths: external_exports.array(external_exports.object({
19016
+ d: external_exports.string().min(1).max(32768).regex(/^[MmLlHhVvCcSsQqTtAaZz\d.,+eE\s-]+$/u),
19017
+ fillRule: external_exports.enum(["evenodd", "nonzero"]).optional(),
19018
+ fill: external_exports.string().regex(/^(?:currentColor|#[a-f0-9]{6})$/iu).optional()
19019
+ }).strict()).min(1).max(32)
19020
+ }).strict().optional(),
19021
+ background: external_exports.string().regex(/^#[a-f0-9]{6}$/iu).optional(),
19022
+ borderRadius: external_exports.number().min(0).max(50).optional(),
19023
+ paddingRatio: external_exports.number().min(0).max(0.25).optional()
19024
+ }).strict().optional(),
19025
+ installation: harnessInstallationGuideSchema.optional(),
19026
+ notice: localizedTextSchema.optional(),
18803
19027
  /** The factory accepts a persisted local entrypoint through its construction context. */
18804
19028
  launchCommand: external_exports.literal(true).optional(),
18805
19029
  links: external_exports.object({
19030
+ website: documentationUrlSchema.optional(),
18806
19031
  documentation: documentationUrlSchema.optional(),
18807
19032
  installation: documentationUrlSchema.optional()
18808
19033
  }).strict().optional()
@@ -18879,6 +19104,10 @@ var CONSOLE_HOST_METHODS = Object.freeze([
18879
19104
  "codexhost/account/list",
18880
19105
  "codexhost/account/refresh",
18881
19106
  "codexhost/account/usage/inspect",
19107
+ "codexhost/usage/model-prices/get",
19108
+ "codexhost/usage/model-prices/set",
19109
+ "codexhost/usage/model-prices/default",
19110
+ "codexhost/usage/statistics/get",
18882
19111
  "codexhost/update/check",
18883
19112
  "codexhost/update/start",
18884
19113
  "codexhost/update/status"
@@ -18943,6 +19172,7 @@ var threadUsageSnapshotSchema = external_exports.object({
18943
19172
  cacheWriteInputTokens: nonNegativeSafeIntegerSchema.optional(),
18944
19173
  outputTokens: nonNegativeSafeIntegerSchema.optional(),
18945
19174
  outputTokensPerSecond: finiteNonNegativeNumberSchema.optional(),
19175
+ apiOutputTokensPerSecond: finiteNonNegativeNumberSchema.optional(),
18946
19176
  reasoningOutputTokens: nonNegativeSafeIntegerSchema.optional(),
18947
19177
  totalTokens: nonNegativeSafeIntegerSchema.optional(),
18948
19178
  totalCostUsd: finiteNonNegativeNumberSchema.optional(),
@@ -18954,7 +19184,11 @@ var threadUsageSnapshotSchema = external_exports.object({
18954
19184
  planFiveHourUsedPercent: cacheHitRatePercentSchema.optional(),
18955
19185
  planFiveHourResetsAtUnix: nonNegativeSafeIntegerSchema.optional(),
18956
19186
  planSevenDayUsedPercent: cacheHitRatePercentSchema.optional(),
18957
- planSevenDayResetsAtUnix: nonNegativeSafeIntegerSchema.optional()
19187
+ planSevenDayResetsAtUnix: nonNegativeSafeIntegerSchema.optional(),
19188
+ sessionCacheHitRatePercent: cacheHitRatePercentSchema.optional(),
19189
+ timeToFirstOutputMs: nonNegativeSafeIntegerSchema.optional(),
19190
+ costSource: external_exports.enum(["publicPrice", "native"]).optional(),
19191
+ unpricedModels: external_exports.array(external_exports.string().min(1)).min(1).optional()
18958
19192
  }).strict().superRefine((usage, context) => {
18959
19193
  if (Object.keys(usage).length === 0) {
18960
19194
  context.addIssue({ code: "custom", message: "Thread Usage must contain a reliable field" });
@@ -18975,6 +19209,20 @@ var threadUsageSnapshotSchema = external_exports.object({
18975
19209
  path: ["contextWindowTokens"]
18976
19210
  });
18977
19211
  }
19212
+ if (usage.costSource !== void 0 && usage.totalCostUsd === void 0) {
19213
+ context.addIssue({
19214
+ code: "custom",
19215
+ message: "Thread Usage costSource must be provided with totalCostUsd",
19216
+ path: ["costSource"]
19217
+ });
19218
+ }
19219
+ if (usage.unpricedModels !== void 0 && usage.costSource !== "publicPrice") {
19220
+ context.addIssue({
19221
+ code: "custom",
19222
+ message: "Thread Usage unpricedModels must be provided with a publicPrice cost",
19223
+ path: ["unpricedModels"]
19224
+ });
19225
+ }
18978
19226
  if (usage.planFiveHourResetsAtUnix !== void 0 && usage.planFiveHourUsedPercent === void 0) {
18979
19227
  context.addIssue({
18980
19228
  code: "custom",
@@ -19244,27 +19492,27 @@ var harnessModelCatalogSchema = external_exports.object({
19244
19492
  }).strict().superRefine((catalog, context) => {
19245
19493
  const refs = /* @__PURE__ */ new Set();
19246
19494
  const thinkingIds = new Set(catalog.thinkingOptions.map(({ id }) => id));
19247
- for (const [index, model] of catalog.models.entries()) {
19248
- if (refs.has(model.ref.id)) {
19495
+ for (const [index, model2] of catalog.models.entries()) {
19496
+ if (refs.has(model2.ref.id)) {
19249
19497
  context.addIssue({
19250
19498
  code: "custom",
19251
19499
  message: "Model Catalog refs must be unique",
19252
19500
  path: ["models", index, "ref", "id"]
19253
19501
  });
19254
19502
  }
19255
- refs.add(model.ref.id);
19256
- if (model.fastModel) {
19257
- if (refs.has(model.fastModel.id) || catalog.models.some((entry) => entry.ref.id === model.fastModel?.id)) {
19503
+ refs.add(model2.ref.id);
19504
+ if (model2.fastModel) {
19505
+ if (refs.has(model2.fastModel.id) || catalog.models.some((entry) => entry.ref.id === model2.fastModel?.id)) {
19258
19506
  context.addIssue({
19259
19507
  code: "custom",
19260
19508
  message: "Fast Model refs must be distinct and unique",
19261
19509
  path: ["models", index, "fastModel"]
19262
19510
  });
19263
19511
  }
19264
- refs.add(model.fastModel.id);
19512
+ refs.add(model2.fastModel.id);
19265
19513
  }
19266
19514
  const supportedThinkingIds = /* @__PURE__ */ new Set();
19267
- for (const [optionIndex, optionId] of (model.supportedThinkingOptionIds ?? []).entries()) {
19515
+ for (const [optionIndex, optionId] of (model2.supportedThinkingOptionIds ?? []).entries()) {
19268
19516
  if (supportedThinkingIds.has(optionId)) {
19269
19517
  context.addIssue({
19270
19518
  code: "custom",
@@ -19862,6 +20110,11 @@ var codexSshDraftSchema = external_exports.strictObject({
19862
20110
  });
19863
20111
  var remoteConnectionsRequestSchema = external_exports.discriminatedUnion("action", [
19864
20112
  external_exports.strictObject({ action: external_exports.literal("list") }),
20113
+ external_exports.strictObject({
20114
+ action: external_exports.literal("read-thread"),
20115
+ hostId: hostId.refine((id) => id !== "local"),
20116
+ input: delegationReadParamsSchema
20117
+ }),
19865
20118
  external_exports.strictObject({
19866
20119
  action: external_exports.literal("save"),
19867
20120
  draft: codexSshDraftSchema,
@@ -20015,7 +20268,6 @@ var tokenFields = [
20015
20268
  "cachedInputTokens",
20016
20269
  "cacheWriteInputTokens",
20017
20270
  "outputTokens",
20018
- "outputTokensPerSecond",
20019
20271
  "reasoningOutputTokens",
20020
20272
  "totalTokens",
20021
20273
  "contextWindowTokens",
@@ -20023,10 +20275,12 @@ var tokenFields = [
20023
20275
  ];
20024
20276
  var safeIntegerFields = [
20025
20277
  "planFiveHourResetsAtUnix",
20026
- "planSevenDayResetsAtUnix"
20278
+ "planSevenDayResetsAtUnix",
20279
+ "timeToFirstOutputMs"
20027
20280
  ];
20028
20281
  var percentFields = [
20029
20282
  "cacheHitRatePercent",
20283
+ "sessionCacheHitRatePercent",
20030
20284
  "planFiveHourUsedPercent",
20031
20285
  "planSevenDayUsedPercent"
20032
20286
  ];
@@ -20034,9 +20288,14 @@ var usageFields = /* @__PURE__ */ new Set([
20034
20288
  ...tokenFields,
20035
20289
  ...safeIntegerFields,
20036
20290
  ...percentFields,
20291
+ "sessionCacheUsage",
20037
20292
  "totalCostUsd",
20038
20293
  "totalCredits",
20039
- "contextUsagePercent"
20294
+ "contextUsagePercent",
20295
+ "outputTokensPerSecond",
20296
+ "apiOutputTokensPerSecond",
20297
+ "costSource",
20298
+ "unpricedModels"
20040
20299
  ]);
20041
20300
  function isRecord(value) {
20042
20301
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -20052,7 +20311,11 @@ function parseHostUsage(value) {
20052
20311
  throw new Error(`Harness Usage contains unknown field '${key}'`);
20053
20312
  }
20054
20313
  }
20055
- for (const field of ["totalCredits", "contextUsagePercent"]) {
20314
+ for (const field of [
20315
+ "totalCredits",
20316
+ "contextUsagePercent",
20317
+ "apiOutputTokensPerSecond"
20318
+ ]) {
20056
20319
  const candidate = value[field];
20057
20320
  if (candidate !== void 0 && (typeof candidate !== "number" || !Number.isFinite(candidate) || candidate < 0)) {
20058
20321
  throw new Error(`Harness Usage '${field}' must be a finite non-negative number`);
@@ -20088,6 +20351,12 @@ function parseHostUsage(value) {
20088
20351
  throw new Error(`Harness Usage '${field}' must be between 0 and 100`);
20089
20352
  }
20090
20353
  }
20354
+ if (value.sessionCacheUsage !== void 0) {
20355
+ const totals2 = value.sessionCacheUsage;
20356
+ if (!isRecord(totals2) || Object.keys(totals2).some((key) => key !== "inputTokens" && key !== "cachedInputTokens") || typeof totals2.inputTokens !== "number" || !Number.isSafeInteger(totals2.inputTokens) || totals2.inputTokens < 0 || typeof totals2.cachedInputTokens !== "number" || !Number.isSafeInteger(totals2.cachedInputTokens) || totals2.cachedInputTokens < 0 || totals2.cachedInputTokens > totals2.inputTokens) {
20357
+ throw new Error("Harness Usage 'sessionCacheUsage' must contain complete bounded token totals");
20358
+ }
20359
+ }
20091
20360
  const hasContextUsed = value.contextUsedTokens !== void 0;
20092
20361
  const hasContextWindow = value.contextWindowTokens !== void 0;
20093
20362
  if (hasContextUsed !== hasContextWindow) {
@@ -20102,168 +20371,89 @@ function parseHostUsage(value) {
20102
20371
  if (value.planSevenDayResetsAtUnix !== void 0 && value.planSevenDayUsedPercent === void 0) {
20103
20372
  throw new Error("Harness Usage 'planSevenDayResetsAtUnix' must be provided with 'planSevenDayUsedPercent'");
20104
20373
  }
20374
+ if (value.costSource !== void 0) {
20375
+ if (value.costSource !== "publicPrice" && value.costSource !== "native") {
20376
+ throw new Error("Harness Usage 'costSource' must be 'publicPrice' or 'native'");
20377
+ }
20378
+ if (value.totalCostUsd === void 0) {
20379
+ throw new Error("Harness Usage 'costSource' must be provided with 'totalCostUsd'");
20380
+ }
20381
+ }
20382
+ if (value.unpricedModels !== void 0) {
20383
+ const models = value.unpricedModels;
20384
+ if (!Array.isArray(models) || models.length === 0 || !models.every((model2) => typeof model2 === "string" && model2.length > 0)) {
20385
+ throw new Error("Harness Usage 'unpricedModels' must be a non-empty list of Model IDs");
20386
+ }
20387
+ if (value.costSource !== "publicPrice") {
20388
+ throw new Error("Harness Usage 'unpricedModels' must be provided with a 'publicPrice' cost");
20389
+ }
20390
+ return { ...value, unpricedModels: [...models] };
20391
+ }
20105
20392
  return { ...value };
20106
20393
  }
20107
-
20108
- // dist/harness-commands.js
20109
- var commandDefinitions = [
20110
- {
20111
- id: "dsh.compact",
20112
- invocation: "/compact",
20113
- label: "Compact context",
20114
- description: "Compact the current conversation context",
20115
- argumentMode: "none"
20116
- },
20117
- {
20118
- id: "dsh.goal",
20119
- invocation: "/dsh-goal",
20120
- label: "Goal",
20121
- description: "Set or view the goal for a long-running task",
20122
- argumentMode: "text"
20123
- },
20124
- {
20125
- id: "dsh.plan",
20126
- invocation: "/plan",
20127
- label: "Plan mode",
20128
- description: "Enter or leave plan mode",
20129
- argumentMode: "text"
20130
- }
20394
+ var requestTokenFields = [
20395
+ "inputTokens",
20396
+ "cachedInputTokens",
20397
+ "cacheWriteInputTokens",
20398
+ "cacheWrite1hInputTokens",
20399
+ "outputTokens",
20400
+ "reasoningOutputTokens",
20401
+ "startedAtMs",
20402
+ "completedAtMs"
20131
20403
  ];
20132
- function invalidArguments(message) {
20133
- return {
20134
- ok: false,
20135
- error: { code: "invalidRequest", message, retryable: false }
20136
- };
20137
- }
20138
- function deepSeekHarnessCommandCatalog() {
20139
- return harnessCommandCatalogSchema.parse({
20140
- commands: commandDefinitions
20141
- });
20142
- }
20143
- function parseDeepSeekHarnessCommand(command) {
20144
- const definition = commandDefinitions.find(({ id }) => id === command.commandId);
20145
- if (!definition) {
20146
- return {
20147
- ok: false,
20148
- error: {
20149
- code: "unsupported",
20150
- message: `DeepSeek Harness does not expose command '${command.commandId}'`,
20151
- retryable: false
20152
- }
20153
- };
20154
- }
20155
- const nativeInvocation = definition.id === "dsh.goal" ? "/goal" : definition.invocation;
20156
- const arguments_ = command.arguments;
20157
- if (definition.argumentMode === "none") {
20158
- return arguments_ && Object.keys(arguments_).length > 0 ? invalidArguments(`DeepSeek Harness ${nativeInvocation} command does not accept arguments`) : { ok: true, value: { commandId: definition.id, line: nativeInvocation } };
20159
- }
20160
- if (arguments_?.text !== void 0 && typeof arguments_.text !== "string") {
20161
- return invalidArguments(`DeepSeek Harness ${nativeInvocation} command argument 'text' must be a string`);
20404
+ var requestFields = /* @__PURE__ */ new Set([
20405
+ ...requestTokenFields,
20406
+ "requestId",
20407
+ "historical",
20408
+ "model",
20409
+ "provider"
20410
+ ]);
20411
+ function parseHostUsageRequest(value) {
20412
+ if (!isRecord(value))
20413
+ throw new Error("Harness Usage request must be an object");
20414
+ for (const key of Object.keys(value)) {
20415
+ if (!requestFields.has(key)) {
20416
+ throw new Error(`Harness Usage request contains unknown field '${key}'`);
20417
+ }
20162
20418
  }
20163
- if (arguments_ && Object.keys(arguments_).some((key) => key !== "text")) {
20164
- return invalidArguments(`DeepSeek Harness ${nativeInvocation} command has an unknown argument`);
20419
+ if (typeof value.requestId !== "string" || value.requestId.length === 0) {
20420
+ throw new Error("Harness Usage request 'requestId' must be a non-empty string");
20165
20421
  }
20166
- const text = arguments_?.text?.trim() ?? "";
20167
- if (definition.id === "dsh.goal" && text.toLowerCase() === "edit") {
20168
- return invalidArguments("DeepSeek Harness /goal edit command requires a replacement objective");
20169
- }
20170
- return {
20171
- ok: true,
20172
- value: {
20173
- commandId: definition.id,
20174
- line: text.length > 0 ? `${nativeInvocation} ${text}` : nativeInvocation
20422
+ for (const field of ["model", "provider"]) {
20423
+ const candidate = value[field];
20424
+ if (candidate !== void 0 && (typeof candidate !== "string" || candidate.length === 0)) {
20425
+ throw new Error(`Harness Usage request '${field}' must be a non-empty string`);
20175
20426
  }
20176
- };
20177
- }
20178
-
20179
- // dist/generation-selector.js
20180
- import { spawn } from "node:child_process";
20181
-
20182
- // dist/executable.js
20183
- import { spawnSync } from "node:child_process";
20184
- import { accessSync, constants, statSync } from "node:fs";
20185
- import path5 from "node:path";
20186
- function environmentValue2(environment, name) {
20187
- return Object.entries(environment).find(([key]) => key.toLowerCase() === name.toLowerCase())?.[1];
20188
- }
20189
- function executableCandidates(command, environment) {
20190
- const targetPath2 = process.platform === "win32" ? path5.win32 : path5.posix;
20191
- if (targetPath2.isAbsolute(command) || command.includes("/") || command.includes("\\")) {
20192
- return [command];
20193
20427
  }
20194
- const extensions = process.platform === "win32" && targetPath2.extname(command) === "" ? (environmentValue2(environment, "PATHEXT") ?? ".COM;.EXE;.BAT;.CMD").split(";").map((extension2) => extension2.trim()).filter(Boolean) : [""];
20195
- return (environmentValue2(environment, "PATH") ?? "").split(targetPath2.delimiter).map((directory) => directory.trim().replace(/^"|"$/gu, "")).filter(Boolean).flatMap((directory) => extensions.map((extension2) => targetPath2.join(directory, command + extension2)));
20196
- }
20197
- function resolveExecutable(command, environment) {
20198
- const accessMode = process.platform === "win32" ? constants.F_OK : constants.X_OK;
20199
- for (const candidate of executableCandidates(command, environment)) {
20200
- try {
20201
- accessSync(candidate, accessMode);
20202
- if (statSync(candidate).isFile())
20203
- return candidate;
20204
- } catch {
20428
+ if (value.historical !== void 0 && typeof value.historical !== "boolean") {
20429
+ throw new Error("Harness Usage request 'historical' must be a boolean");
20430
+ }
20431
+ for (const field of requestTokenFields) {
20432
+ const candidate = value[field];
20433
+ if (candidate !== void 0 && (typeof candidate !== "number" || !Number.isSafeInteger(candidate) || candidate < 0)) {
20434
+ throw new Error(`Harness Usage request '${field}' must be a non-negative safe integer`);
20205
20435
  }
20206
20436
  }
20207
- return null;
20208
- }
20209
- function resolveDeepSeekCommand(configured, environment) {
20210
- if (configured) {
20211
- const command = resolveExecutable(configured, environment);
20212
- return command ? { command, arguments: [], kind: "configured" } : null;
20437
+ if (value.inputTokens === void 0 || value.outputTokens === void 0) {
20438
+ throw new Error("Harness Usage request must contain 'inputTokens' and 'outputTokens'");
20213
20439
  }
20214
- const dsh = resolveExecutable("dsh", environment);
20215
- if (dsh)
20216
- return { command: dsh, arguments: [], kind: "dsh" };
20217
- const npx = resolveExecutable(process.platform === "win32" ? "npx.cmd" : "npx", environment);
20218
- return npx ? {
20219
- command: npx,
20220
- arguments: ["--offline", "--no-install", "@deepseek-ai/dsh"],
20221
- kind: "npx"
20222
- } : null;
20223
- }
20224
- function deepSeekProcessInvocation(command, arguments_, environment, platform = process.platform) {
20225
- const extension2 = path5.win32.extname(command).toLowerCase();
20226
- if (platform !== "win32" || ![".cmd", ".bat"].includes(extension2)) {
20227
- return { command, arguments: arguments_, windowsVerbatimArguments: false };
20440
+ const request = value;
20441
+ if ((request.cachedInputTokens ?? 0) + (request.cacheWriteInputTokens ?? 0) > request.inputTokens) {
20442
+ throw new Error("Harness Usage request cache Tokens must not exceed 'inputTokens'");
20228
20443
  }
20229
- const quote = (value) => `"${value.replaceAll("%", "%%").replaceAll('"', '""')}"`;
20230
- const commandLine = [command, ...arguments_].map(quote).join(" ");
20231
- return {
20232
- command: environmentValue2(environment, "ComSpec") ?? "cmd.exe",
20233
- arguments: ["/d", "/v:off", "/s", "/c", `"${commandLine}"`],
20234
- windowsVerbatimArguments: true
20235
- };
20236
- }
20237
- function resolveWindowsTaskkillPath(environment) {
20238
- const systemRoot = environmentValue2(environment, "SystemRoot") ?? environmentValue2(environment, "windir");
20239
- if (!systemRoot || !/^[A-Za-z]:[\\/]/u.test(systemRoot)) {
20240
- throw new Error("Windows SystemRoot is unavailable or invalid");
20444
+ if ((request.reasoningOutputTokens ?? 0) > request.outputTokens) {
20445
+ throw new Error("Harness Usage request 'reasoningOutputTokens' must not exceed 'outputTokens'");
20241
20446
  }
20242
- return path5.win32.join(systemRoot, "System32", "taskkill.exe");
20243
- }
20244
- function killDeepSeekProcessTree(child, platform, timeoutMs) {
20245
- if (!child.pid) {
20246
- if (child.exitCode === null && child.signalCode === null)
20247
- child.kill("SIGKILL");
20248
- return;
20447
+ if (request.cacheWrite1hInputTokens !== void 0 && request.cacheWrite1hInputTokens > (request.cacheWriteInputTokens ?? -1)) {
20448
+ throw new Error("Harness Usage request 'cacheWrite1hInputTokens' must not exceed 'cacheWriteInputTokens'");
20249
20449
  }
20250
- if (platform === "win32") {
20251
- const result = spawnSync(resolveWindowsTaskkillPath(process.env), ["/pid", String(child.pid), "/t", "/f"], {
20252
- stdio: "ignore",
20253
- windowsHide: true,
20254
- timeout: timeoutMs
20255
- });
20256
- if (result.error)
20257
- throw result.error;
20258
- return;
20450
+ if (request.startedAtMs === void 0 !== (request.completedAtMs === void 0)) {
20451
+ throw new Error("Harness Usage request timing fields must be provided together");
20259
20452
  }
20260
- try {
20261
- process.kill(-child.pid, "SIGKILL");
20262
- } catch (error51) {
20263
- if (typeof error51 !== "object" || error51 === null || Reflect.get(error51, "code") !== "ESRCH") {
20264
- throw error51;
20265
- }
20453
+ if (request.startedAtMs !== void 0 && request.completedAtMs !== void 0 && request.completedAtMs < request.startedAtMs) {
20454
+ throw new Error("Harness Usage request 'completedAtMs' must not precede 'startedAtMs'");
20266
20455
  }
20456
+ return { ...request };
20267
20457
  }
20268
20458
 
20269
20459
  // dist/profiles/v4.js
@@ -20640,16 +20830,16 @@ var Diff = class {
20640
20830
  }
20641
20831
  }
20642
20832
  }
20643
- addToPath(path8, added, removed, oldPosInc, options) {
20644
- const last = path8.lastComponent;
20833
+ addToPath(path9, added, removed, oldPosInc, options) {
20834
+ const last = path9.lastComponent;
20645
20835
  if (last && !options.oneChangePerToken && last.added === added && last.removed === removed) {
20646
20836
  return {
20647
- oldPos: path8.oldPos + oldPosInc,
20837
+ oldPos: path9.oldPos + oldPosInc,
20648
20838
  lastComponent: { count: last.count + 1, added, removed, previousComponent: last.previousComponent }
20649
20839
  };
20650
20840
  } else {
20651
20841
  return {
20652
- oldPos: path8.oldPos + oldPosInc,
20842
+ oldPos: path9.oldPos + oldPosInc,
20653
20843
  lastComponent: { count: 1, added, removed, previousComponent: last }
20654
20844
  };
20655
20845
  }
@@ -21846,6 +22036,349 @@ var DEEPSEEK_V4_PROFILE = Object.freeze({
21846
22036
  settlementUsage
21847
22037
  });
21848
22038
 
22039
+ // dist/modern/usage-metering.js
22040
+ function isRecord5(value) {
22041
+ return typeof value === "object" && value !== null && !Array.isArray(value);
22042
+ }
22043
+ function count2(value) {
22044
+ return typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : null;
22045
+ }
22046
+ function firstTokenTime(chunks) {
22047
+ for (const { time: time3, chunk } of chunks) {
22048
+ if ((chunk.type === "reasoning-delta" || chunk.type === "text-delta") && typeof chunk.text === "string" && chunk.text.length > 0 || chunk.type === "tool-call-delta" && typeof chunk.name === "string" && chunk.name.length > 0) {
22049
+ return time3;
22050
+ }
22051
+ }
22052
+ return null;
22053
+ }
22054
+ function deepSeekUsageRecord(event, historical) {
22055
+ if (event.type !== "assistant/message" || event.surfaceOp !== "append")
22056
+ return { kind: "none" };
22057
+ const data = isRecord5(event.data) ? event.data : null;
22058
+ const message = data && isRecord5(data.message) ? data.message : null;
22059
+ const source = message && isRecord5(message.source) ? message.source : null;
22060
+ if (!data || !message || source?.kind !== "model")
22061
+ return { kind: "none" };
22062
+ if (typeof message.id !== "string" || message.id.length === 0)
22063
+ return { kind: "missing" };
22064
+ if (typeof source.model !== "string" || source.model.length === 0)
22065
+ return { kind: "missing" };
22066
+ let chunks;
22067
+ try {
22068
+ chunks = expandAssistantStream(data.stream);
22069
+ } catch {
22070
+ return { kind: "missing" };
22071
+ }
22072
+ let usage = data.usage;
22073
+ for (const { chunk } of chunks)
22074
+ if (chunk.type === "usage")
22075
+ usage = chunk.usage;
22076
+ if (usage === void 0)
22077
+ return data.interrupted === true ? { kind: "none" } : { kind: "missing" };
22078
+ if (!isRecord5(usage))
22079
+ return { kind: "missing" };
22080
+ const input = count2(usage.inputTokens);
22081
+ const output = count2(usage.outputTokens);
22082
+ const cacheRead = count2(usage.cacheReadTokens ?? 0);
22083
+ const cacheWrite = count2(usage.cacheWriteTokens ?? 0);
22084
+ const reasoning2 = usage.reasoningTokens === void 0 ? null : count2(usage.reasoningTokens);
22085
+ if (input === null || output === null || cacheRead === null || cacheWrite === null) {
22086
+ return { kind: "missing" };
22087
+ }
22088
+ const startedAtMs = historical ? null : firstTokenTime(chunks);
22089
+ const completedAtMs = typeof event.time === "number" ? event.time : null;
22090
+ try {
22091
+ return {
22092
+ kind: "request",
22093
+ request: parseHostUsageRequest({
22094
+ requestId: message.id,
22095
+ ...historical ? { historical: true } : {},
22096
+ model: source.model,
22097
+ inputTokens: input + cacheRead + cacheWrite,
22098
+ cachedInputTokens: cacheRead,
22099
+ cacheWriteInputTokens: cacheWrite,
22100
+ outputTokens: output,
22101
+ ...reasoning2 !== null && reasoning2 <= output ? { reasoningOutputTokens: reasoning2 } : {},
22102
+ ...startedAtMs !== null && completedAtMs !== null && completedAtMs >= startedAtMs ? { startedAtMs, completedAtMs } : {}
22103
+ })
22104
+ };
22105
+ } catch {
22106
+ return { kind: "missing" };
22107
+ }
22108
+ }
22109
+ function deepSeekUsageHistory(events) {
22110
+ const requests = /* @__PURE__ */ new Map();
22111
+ let complete = true;
22112
+ for (const event of events) {
22113
+ const record2 = deepSeekUsageRecord(event, true);
22114
+ if (record2.kind === "request")
22115
+ requests.set(record2.request.requestId, record2.request);
22116
+ else if (record2.kind === "missing")
22117
+ complete = false;
22118
+ }
22119
+ return { requests: [...requests.values()], complete };
22120
+ }
22121
+
22122
+ // dist/modern/usage-statistics.js
22123
+ var SESSION_FILE = /^session(?:\.v(\d+))?\.jsonl(\.zstd)?$/u;
22124
+ var ZSTD_MAGIC = 4247762216;
22125
+ function dshHome(environment) {
22126
+ return environment.DSH_HOME || path5.join(environment.HOME || os2.homedir(), ".dsh");
22127
+ }
22128
+ function zstdFrames(buffer) {
22129
+ const frames = [];
22130
+ let offset = 0;
22131
+ while (offset + 8 <= buffer.length) {
22132
+ const magic = buffer.readUInt32LE(offset);
22133
+ if ((magic & 4294967280) === 407710288) {
22134
+ offset += 8 + buffer.readUInt32LE(offset + 4);
22135
+ continue;
22136
+ }
22137
+ if (magic !== ZSTD_MAGIC)
22138
+ throw new Error("dsh session file is not zstd");
22139
+ const start = offset;
22140
+ const descriptor = buffer[offset + 4] ?? 0;
22141
+ const single = descriptor >> 5 & 1;
22142
+ offset += 5 + (single ? 0 : 1);
22143
+ offset += [0, 1, 2, 4][descriptor & 3] ?? 0;
22144
+ offset += [single, 2, 4, 8][descriptor >> 6] ?? 0;
22145
+ for (; ; ) {
22146
+ if (offset + 3 > buffer.length)
22147
+ return frames;
22148
+ const header = buffer.readUIntLE(offset, 3);
22149
+ const type = header >> 1 & 3;
22150
+ if (type === 3)
22151
+ throw new Error("dsh session file has a reserved zstd block");
22152
+ offset += 3 + (type === 1 ? 1 : header >>> 3);
22153
+ if (header & 1)
22154
+ break;
22155
+ }
22156
+ if (descriptor >> 2 & 1)
22157
+ offset += 4;
22158
+ if (offset > buffer.length)
22159
+ return frames;
22160
+ frames.push(buffer.subarray(start, offset));
22161
+ }
22162
+ return frames;
22163
+ }
22164
+ async function readDshUsage(file2) {
22165
+ const buffer = await readFile2(file2);
22166
+ const text = file2.endsWith(".zstd") ? zstdFrames(buffer).map((frame) => zstdDecompressSync(frame).toString("utf8")).join("") : buffer.toString("utf8");
22167
+ const entries = [];
22168
+ let session = {};
22169
+ for (const line of text.split("\n")) {
22170
+ if (entries.length === 0 && line.startsWith('{"type":"session"')) {
22171
+ try {
22172
+ const header = JSON.parse(line);
22173
+ session = {
22174
+ ...typeof header.id === "string" ? { sessionId: header.id } : {},
22175
+ ...typeof header.cwd === "string" ? { cwd: header.cwd } : {}
22176
+ };
22177
+ } catch {
22178
+ }
22179
+ continue;
22180
+ }
22181
+ if (!line.includes('"assistant/message"'))
22182
+ continue;
22183
+ let event;
22184
+ try {
22185
+ event = JSON.parse(line);
22186
+ } catch {
22187
+ continue;
22188
+ }
22189
+ const record2 = deepSeekUsageRecord(event, true);
22190
+ const entry = record2.kind === "request" && usageEntryFromRequest(record2.request, event.time);
22191
+ if (entry)
22192
+ entries.push(withUsageSession(entry, session));
22193
+ }
22194
+ return entries;
22195
+ }
22196
+ function createDshUsageStatistics(environment) {
22197
+ return Object.freeze({
22198
+ async listSources(signal) {
22199
+ const root = path5.join(dshHome(environment), "sessions");
22200
+ const sources = [];
22201
+ for (const project2 of await readdir(root).catch(() => [])) {
22202
+ for (const session of await readdir(path5.join(root, project2)).catch(() => [])) {
22203
+ signal.throwIfAborted();
22204
+ const directory = path5.join(root, project2, session);
22205
+ const latest = (await readdir(directory).catch(() => [])).map((name) => ({ name, version: Number(SESSION_FILE.exec(name)?.[1] ?? 1) })).filter(({ name }) => SESSION_FILE.test(name)).sort((left, right) => right.version - left.version)[0];
22206
+ if (!latest)
22207
+ continue;
22208
+ const file2 = path5.join(directory, latest.name);
22209
+ const info = await lstat(file2).catch(() => null);
22210
+ if (info?.isFile() && info.size > 0) {
22211
+ sources.push({ id: file2, fingerprint: `${info.ino}:${info.size}:${info.mtimeMs}` });
22212
+ }
22213
+ }
22214
+ }
22215
+ return sources;
22216
+ },
22217
+ readSource: (id) => readDshUsage(id)
22218
+ });
22219
+ }
22220
+
22221
+ // dist/harness-commands.js
22222
+ var commandDefinitions = [
22223
+ {
22224
+ id: "dsh.compact",
22225
+ invocation: "/compact",
22226
+ label: "Compact context",
22227
+ description: "Compact the current conversation context",
22228
+ argumentMode: "none"
22229
+ },
22230
+ {
22231
+ id: "dsh.goal",
22232
+ invocation: "/dsh-goal",
22233
+ label: "Goal",
22234
+ description: "Set or view the goal for a long-running task",
22235
+ argumentMode: "text"
22236
+ },
22237
+ {
22238
+ id: "dsh.plan",
22239
+ invocation: "/plan",
22240
+ label: "Plan mode",
22241
+ description: "Enter or leave plan mode",
22242
+ argumentMode: "text"
22243
+ }
22244
+ ];
22245
+ function invalidArguments(message) {
22246
+ return {
22247
+ ok: false,
22248
+ error: { code: "invalidRequest", message, retryable: false }
22249
+ };
22250
+ }
22251
+ function deepSeekHarnessCommandCatalog() {
22252
+ return harnessCommandCatalogSchema.parse({
22253
+ commands: commandDefinitions
22254
+ });
22255
+ }
22256
+ function parseDeepSeekHarnessCommand(command) {
22257
+ const definition = commandDefinitions.find(({ id }) => id === command.commandId);
22258
+ if (!definition) {
22259
+ return {
22260
+ ok: false,
22261
+ error: {
22262
+ code: "unsupported",
22263
+ message: `DeepSeek Harness does not expose command '${command.commandId}'`,
22264
+ retryable: false
22265
+ }
22266
+ };
22267
+ }
22268
+ const nativeInvocation = definition.id === "dsh.goal" ? "/goal" : definition.invocation;
22269
+ const arguments_ = command.arguments;
22270
+ if (definition.argumentMode === "none") {
22271
+ return arguments_ && Object.keys(arguments_).length > 0 ? invalidArguments(`DeepSeek Harness ${nativeInvocation} command does not accept arguments`) : { ok: true, value: { commandId: definition.id, line: nativeInvocation } };
22272
+ }
22273
+ if (arguments_?.text !== void 0 && typeof arguments_.text !== "string") {
22274
+ return invalidArguments(`DeepSeek Harness ${nativeInvocation} command argument 'text' must be a string`);
22275
+ }
22276
+ if (arguments_ && Object.keys(arguments_).some((key) => key !== "text")) {
22277
+ return invalidArguments(`DeepSeek Harness ${nativeInvocation} command has an unknown argument`);
22278
+ }
22279
+ const text = arguments_?.text?.trim() ?? "";
22280
+ if (definition.id === "dsh.goal" && text.toLowerCase() === "edit") {
22281
+ return invalidArguments("DeepSeek Harness /goal edit command requires a replacement objective");
22282
+ }
22283
+ return {
22284
+ ok: true,
22285
+ value: {
22286
+ commandId: definition.id,
22287
+ line: text.length > 0 ? `${nativeInvocation} ${text}` : nativeInvocation
22288
+ }
22289
+ };
22290
+ }
22291
+
22292
+ // dist/generation-selector.js
22293
+ import { spawn } from "node:child_process";
22294
+
22295
+ // dist/executable.js
22296
+ import { spawnSync } from "node:child_process";
22297
+ import { accessSync, constants, statSync } from "node:fs";
22298
+ import path6 from "node:path";
22299
+ function environmentValue2(environment, name) {
22300
+ return Object.entries(environment).find(([key]) => key.toLowerCase() === name.toLowerCase())?.[1];
22301
+ }
22302
+ function executableCandidates(command, environment) {
22303
+ const targetPath2 = process.platform === "win32" ? path6.win32 : path6.posix;
22304
+ if (targetPath2.isAbsolute(command) || command.includes("/") || command.includes("\\")) {
22305
+ return [command];
22306
+ }
22307
+ const extensions = process.platform === "win32" && targetPath2.extname(command) === "" ? (environmentValue2(environment, "PATHEXT") ?? ".COM;.EXE;.BAT;.CMD").split(";").map((extension2) => extension2.trim()).filter(Boolean) : [""];
22308
+ return (environmentValue2(environment, "PATH") ?? "").split(targetPath2.delimiter).map((directory) => directory.trim().replace(/^"|"$/gu, "")).filter(Boolean).flatMap((directory) => extensions.map((extension2) => targetPath2.join(directory, command + extension2)));
22309
+ }
22310
+ function resolveExecutable(command, environment) {
22311
+ const accessMode = process.platform === "win32" ? constants.F_OK : constants.X_OK;
22312
+ for (const candidate of executableCandidates(command, environment)) {
22313
+ try {
22314
+ accessSync(candidate, accessMode);
22315
+ if (statSync(candidate).isFile())
22316
+ return candidate;
22317
+ } catch {
22318
+ }
22319
+ }
22320
+ return null;
22321
+ }
22322
+ function resolveDeepSeekCommand(configured, environment) {
22323
+ if (configured) {
22324
+ const command = resolveExecutable(configured, environment);
22325
+ return command ? { command, arguments: [], kind: "configured" } : null;
22326
+ }
22327
+ const dsh = resolveExecutable("dsh", environment);
22328
+ if (dsh)
22329
+ return { command: dsh, arguments: [], kind: "dsh" };
22330
+ const npx = resolveExecutable(process.platform === "win32" ? "npx.cmd" : "npx", environment);
22331
+ return npx ? {
22332
+ command: npx,
22333
+ arguments: ["--offline", "--no-install", "@deepseek-ai/dsh"],
22334
+ kind: "npx"
22335
+ } : null;
22336
+ }
22337
+ function deepSeekProcessInvocation(command, arguments_, environment, platform = process.platform) {
22338
+ const extension2 = path6.win32.extname(command).toLowerCase();
22339
+ if (platform !== "win32" || ![".cmd", ".bat"].includes(extension2)) {
22340
+ return { command, arguments: arguments_, windowsVerbatimArguments: false };
22341
+ }
22342
+ const quote = (value) => `"${value.replaceAll("%", "%%").replaceAll('"', '""')}"`;
22343
+ const commandLine = [command, ...arguments_].map(quote).join(" ");
22344
+ return {
22345
+ command: environmentValue2(environment, "ComSpec") ?? "cmd.exe",
22346
+ arguments: ["/d", "/v:off", "/s", "/c", `"${commandLine}"`],
22347
+ windowsVerbatimArguments: true
22348
+ };
22349
+ }
22350
+ function resolveWindowsTaskkillPath(environment) {
22351
+ const systemRoot = environmentValue2(environment, "SystemRoot") ?? environmentValue2(environment, "windir");
22352
+ if (!systemRoot || !/^[A-Za-z]:[\\/]/u.test(systemRoot)) {
22353
+ throw new Error("Windows SystemRoot is unavailable or invalid");
22354
+ }
22355
+ return path6.win32.join(systemRoot, "System32", "taskkill.exe");
22356
+ }
22357
+ function killDeepSeekProcessTree(child, platform, timeoutMs) {
22358
+ if (!child.pid) {
22359
+ if (child.exitCode === null && child.signalCode === null)
22360
+ child.kill("SIGKILL");
22361
+ return;
22362
+ }
22363
+ if (platform === "win32") {
22364
+ const result = spawnSync(resolveWindowsTaskkillPath(process.env), ["/pid", String(child.pid), "/t", "/f"], {
22365
+ stdio: "ignore",
22366
+ windowsHide: true,
22367
+ timeout: timeoutMs
22368
+ });
22369
+ if (result.error)
22370
+ throw result.error;
22371
+ return;
22372
+ }
22373
+ try {
22374
+ process.kill(-child.pid, "SIGKILL");
22375
+ } catch (error51) {
22376
+ if (typeof error51 !== "object" || error51 === null || Reflect.get(error51, "code") !== "ESRCH") {
22377
+ throw error51;
22378
+ }
22379
+ }
22380
+ }
22381
+
21849
22382
  // dist/profiles/profile.js
21850
22383
  var DEEPSEEK_MINIMUM_VERSION = DEEPSEEK_V4_FIRST_VERSION;
21851
22384
  var MINIMUM = parseSemVer(DEEPSEEK_MINIMUM_VERSION);
@@ -22218,7 +22751,7 @@ async function probeDeepSeekExecutableGeneration(options = {}, dependencies = {
22218
22751
 
22219
22752
  // dist/modern/deepseek-harness-adapter.js
22220
22753
  import { randomUUID as randomUUID2 } from "node:crypto";
22221
- import path7 from "node:path";
22754
+ import path8 from "node:path";
22222
22755
 
22223
22756
  // dist/modern/catalog.js
22224
22757
  import { Buffer as Buffer3 } from "node:buffer";
@@ -22226,9 +22759,9 @@ import { Buffer as Buffer3 } from "node:buffer";
22226
22759
  // dist/model-catalog.js
22227
22760
  import { Buffer as Buffer2 } from "node:buffer";
22228
22761
  var MODEL_REF_PREFIX = "deepseek-harness-model-v2.";
22229
- function encodeDeepSeekHarnessModelRef(model) {
22230
- const provider = model.provider.trim();
22231
- const modelId = model.model.trim();
22762
+ function encodeDeepSeekHarnessModelRef(model2) {
22763
+ const provider = model2.provider.trim();
22764
+ const modelId = model2.model.trim();
22232
22765
  if (!provider || !modelId)
22233
22766
  throw new Error("DeepSeek Harness Model identity must not be empty");
22234
22767
  const encoded = Buffer2.from(JSON.stringify([provider, modelId]), "utf8").toString("base64url");
@@ -22267,8 +22800,8 @@ function parseDeepSeekThinkingOptionId(value) {
22267
22800
  }
22268
22801
  function normalizeDeepSeekThinkingOptions(models) {
22269
22802
  const group = models.groups.find((candidate) => candidate.id === models.current.provider);
22270
- const model = group?.models.find((candidate) => candidate.id === models.current.model);
22271
- return (model?.reasoning?.efforts ?? []).flatMap((effort) => {
22803
+ const model2 = group?.models.find((candidate) => candidate.id === models.current.model);
22804
+ return (model2?.reasoning?.efforts ?? []).flatMap((effort) => {
22272
22805
  const parsedId = harnessThinkingOptionIdSchema.safeParse(effort.id);
22273
22806
  return parsedId.success ? [{ id: parsedId.data, label: effort.name }] : [];
22274
22807
  });
@@ -22277,8 +22810,8 @@ function normalizeDeepSeekModelCatalog(groups2, selection2) {
22277
22810
  const thinkingOptions = [];
22278
22811
  const knownEffortIds = /* @__PURE__ */ new Set();
22279
22812
  for (const group of groups2) {
22280
- for (const model of group.models) {
22281
- for (const effort of model.reasoning?.efforts ?? []) {
22813
+ for (const model2 of group.models) {
22814
+ for (const effort of model2.reasoning?.efforts ?? []) {
22282
22815
  if (knownEffortIds.has(effort.id))
22283
22816
  continue;
22284
22817
  const parsedId = harnessThinkingOptionIdSchema.safeParse(effort.id);
@@ -22289,16 +22822,16 @@ function normalizeDeepSeekModelCatalog(groups2, selection2) {
22289
22822
  }
22290
22823
  }
22291
22824
  }
22292
- const models = groups2.flatMap((group) => group.models.map((model) => ({
22293
- ref: encodeDeepSeekHarnessModelRef({ provider: group.id, model: model.id }),
22294
- label: `${group.name} / ${model.name}`,
22295
- ...model.reasoning && model.reasoning.efforts.length > 0 ? { supportedThinkingOptionIds: model.reasoning.efforts.map((effort) => effort.id) } : {}
22825
+ const models = groups2.flatMap((group) => group.models.map((model2) => ({
22826
+ ref: encodeDeepSeekHarnessModelRef({ provider: group.id, model: model2.id }),
22827
+ label: `${group.name} / ${model2.name}`,
22828
+ ...model2.reasoning && model2.reasoning.efforts.length > 0 ? { supportedThinkingOptionIds: model2.reasoning.efforts.map((effort) => effort.id) } : {}
22296
22829
  })));
22297
22830
  const defaultModel = selection2 ? encodeDeepSeekHarnessModelRef(selection2) : void 0;
22298
- if (selection2 && defaultModel && !models.some((model) => model.ref.id === defaultModel.id)) {
22831
+ if (selection2 && defaultModel && !models.some((model2) => model2.ref.id === defaultModel.id)) {
22299
22832
  models.unshift({ ref: defaultModel, label: `${selection2.provider} / ${selection2.model}` });
22300
22833
  }
22301
- const defaultReasoning = selection2 ? groups2.find((group) => group.id === selection2.provider)?.models.find((model) => model.id === selection2.model)?.reasoning : void 0;
22834
+ const defaultReasoning = selection2 ? groups2.find((group) => group.id === selection2.provider)?.models.find((model2) => model2.id === selection2.model)?.reasoning : void 0;
22302
22835
  const defaultThinkingOptionId = parseDeepSeekThinkingOptionId(selection2?.reasoningEffort ?? defaultReasoning?.defaultEffort);
22303
22836
  return harnessModelCatalogSchema.parse({
22304
22837
  models,
@@ -23483,32 +24016,32 @@ function groups(value, routable) {
23483
24016
  throw catalogError("protocolError", "DeepSeek Harness returned a non-routable Model group");
23484
24017
  }
23485
24018
  const name = boundedString(candidate.name, MAX_NAME_LENGTH, "Model provider name");
23486
- const models = array2(candidate.models, MAX_MODELS, "Model list").map((model) => {
24019
+ const models = array2(candidate.models, MAX_MODELS, "Model list").map((model2) => {
23487
24020
  modelCount += 1;
23488
24021
  if (modelCount > MAX_MODELS) {
23489
24022
  throw catalogError("limitExceeded", "DeepSeek Harness Model list exceeded its item bound");
23490
24023
  }
23491
- if (!isPlainRecord(model) || !exactKeys2(model, ["id", "name"], ["description", "reasoning"])) {
24024
+ if (!isPlainRecord(model2) || !exactKeys2(model2, ["id", "name"], ["description", "reasoning"])) {
23492
24025
  throw catalogError("protocolError", "DeepSeek Harness returned an invalid Model");
23493
24026
  }
23494
- const modelId = boundedString(model.id, MAX_ID_LENGTH, "Model id");
23495
- const modelName = boundedString(model.name, MAX_NAME_LENGTH, "Model name");
24027
+ const modelId = boundedString(model2.id, MAX_ID_LENGTH, "Model id");
24028
+ const modelName = boundedString(model2.name, MAX_NAME_LENGTH, "Model name");
23496
24029
  if (`${name} / ${modelName}`.length > HARNESS_MODEL_LABEL_MAX_LENGTH) {
23497
24030
  throw catalogError("protocolError", "DeepSeek Harness returned a Model label that is too long");
23498
24031
  }
23499
24032
  return {
23500
24033
  id: modelId,
23501
24034
  name: modelName,
23502
- ...model.description === void 0 ? {} : {
23503
- description: boundedString(model.description, MAX_DESCRIPTION_LENGTH, "Model description", true)
24035
+ ...model2.description === void 0 ? {} : {
24036
+ description: boundedString(model2.description, MAX_DESCRIPTION_LENGTH, "Model description", true)
23504
24037
  },
23505
- ...model.reasoning === void 0 ? {} : { reasoning: reasoning(model.reasoning) }
24038
+ ...model2.reasoning === void 0 ? {} : { reasoning: reasoning(model2.reasoning) }
23506
24039
  };
23507
24040
  });
23508
24041
  if (models.length === 0) {
23509
24042
  throw catalogError("protocolError", "DeepSeek Harness returned an empty Model provider group");
23510
24043
  }
23511
- const modelIds = models.map((model) => model.id);
24044
+ const modelIds = models.map((model2) => model2.id);
23512
24045
  if (new Set(modelIds).size !== modelIds.length) {
23513
24046
  throw catalogError("protocolError", "DeepSeek Harness returned duplicate Model ids");
23514
24047
  }
@@ -23719,11 +24252,11 @@ function sanitizedError(error51, fallback) {
23719
24252
  failure.name = redactModernCredential(error51 instanceof Error ? error51.name : "Error");
23720
24253
  return failure;
23721
24254
  }
23722
- function isRecord5(value) {
24255
+ function isRecord6(value) {
23723
24256
  return typeof value === "object" && value !== null && !Array.isArray(value);
23724
24257
  }
23725
24258
  function isPlainRecord3(value) {
23726
- if (!isRecord5(value))
24259
+ if (!isRecord6(value))
23727
24260
  return false;
23728
24261
  const prototype = Object.getPrototypeOf(value);
23729
24262
  return prototype === Object.prototype || prototype === null;
@@ -23873,7 +24406,7 @@ function projectionRow(value, seq) {
23873
24406
  return Object.freeze({ value: detachedJson(value), seq });
23874
24407
  }
23875
24408
  function parseProjectionBaseline(value, maxKeys) {
23876
- if (!isRecord5(value) || !hasExactKeys4(value, ["asOfSeq", "values"])) {
24409
+ if (!isRecord6(value) || !hasExactKeys4(value, ["asOfSeq", "values"])) {
23877
24410
  throw storeError("protocolError", "DeepSeek Harness control baseline has invalid projections");
23878
24411
  }
23879
24412
  if (!validCursor(value.asOfSeq) || !isPlainRecord3(value.values)) {
@@ -23899,7 +24432,7 @@ function parseProjectionBaseline(value, maxKeys) {
23899
24432
  return { asOfSeq: value.asOfSeq, values, rowBytes };
23900
24433
  }
23901
24434
  function parseBaseline(value, maxSessions, maxKeys) {
23902
- if (!isRecord5(value) || !hasExactKeys4(value, ["projections"]) || !isPlainRecord3(value.projections)) {
24435
+ if (!isRecord6(value) || !hasExactKeys4(value, ["projections"]) || !isPlainRecord3(value.projections)) {
23903
24436
  throw storeError("protocolError", "DeepSeek Harness control stream emitted an invalid baseline");
23904
24437
  }
23905
24438
  const sessions = /* @__PURE__ */ new Set();
@@ -23917,7 +24450,7 @@ function parseBaseline(value, maxSessions, maxKeys) {
23917
24450
  return { projections };
23918
24451
  }
23919
24452
  function parseControlFrame(value, maxSessions, maxKeys) {
23920
- if (!isRecord5(value) || typeof value.type !== "string") {
24453
+ if (!isRecord6(value) || typeof value.type !== "string") {
23921
24454
  throw storeError("protocolError", "DeepSeek Harness control stream emitted an invalid frame");
23922
24455
  }
23923
24456
  if (value.type === "baseline" && hasExactKeys4(value, ["type", "value"])) {
@@ -24642,14 +25175,14 @@ function parseSelection(value, area) {
24642
25175
  throw configurationError("protocolError", `DeepSeek Harness returned an invalid ${area}`);
24643
25176
  }
24644
25177
  const provider = boundedSelectionString(value.provider, `${area} provider`);
24645
- const model = boundedSelectionString(value.model, `${area} Model`);
25178
+ const model2 = boundedSelectionString(value.model, `${area} Model`);
24646
25179
  if (value.reasoningEffort === void 0)
24647
- return { provider, model };
25180
+ return { provider, model: model2 };
24648
25181
  const effort = harnessThinkingOptionIdSchema.safeParse(value.reasoningEffort);
24649
25182
  if (!effort.success) {
24650
25183
  throw configurationError("protocolError", `DeepSeek Harness returned an invalid ${area} reasoning effort`);
24651
25184
  }
24652
- return { provider, model, reasoningEffort: effort.data };
25185
+ return { provider, model: model2, reasoningEffort: effort.data };
24653
25186
  }
24654
25187
  function parseOptionalSelection(value, area) {
24655
25188
  return value === null ? null : parseSelection(value, area);
@@ -24712,22 +25245,22 @@ function readModernConfigurationSnapshot(input) {
24712
25245
  if (!rows) {
24713
25246
  throw configurationError("protocolError", "DeepSeek Harness control state is detached");
24714
25247
  }
24715
- const model = readModernModelSelectionState(rows[MODERN_MODEL_SELECTION_PROJECTION_KEY], input.modelCatalog);
25248
+ const model2 = readModernModelSelectionState(rows[MODERN_MODEL_SELECTION_PROJECTION_KEY], input.modelCatalog);
24716
25249
  const permission = readModernPermissionModeState(rows[MODERN_PERMISSION_PROJECTION_KEY], input.permissionModes);
24717
25250
  return {
24718
- model,
24719
- state: stateForSelection(input.nativeRef, model.selection, input.modelCatalog, permission?.permissionModeId),
25251
+ model: model2,
25252
+ state: stateForSelection(input.nativeRef, model2.selection, input.modelCatalog, permission?.permissionModeId),
24720
25253
  ...permission ? { permissionProjectionSeq: permission.projectionSeq } : {}
24721
25254
  };
24722
25255
  }
24723
- function modernSelectionForModel(catalog, model, thinkingOptionId) {
25256
+ function modernSelectionForModel(catalog, model2, thinkingOptionId) {
24724
25257
  let native;
24725
25258
  try {
24726
- native = decodeDeepSeekHarnessModelRef(model);
25259
+ native = decodeDeepSeekHarnessModelRef(model2);
24727
25260
  } catch (error51) {
24728
25261
  throw configurationError("invalidRequest", error51 instanceof Error ? error51.message : "DeepSeek Harness Model is invalid");
24729
25262
  }
24730
- const catalogModel = catalog.catalog.models.find(({ ref }) => ref.id === model.id);
25263
+ const catalogModel = catalog.catalog.models.find(({ ref }) => ref.id === model2.id);
24731
25264
  if (!catalogModel) {
24732
25265
  throw configurationError("invalidRequest", "DeepSeek Harness Model is unavailable");
24733
25266
  }
@@ -25806,11 +26339,11 @@ function malformedOutcome(event) {
25806
26339
  function isApprovalOutcome(value) {
25807
26340
  return value === "allowed-once" || value === "rejected" || value === "cancelled" || value === "unavailable";
25808
26341
  }
25809
- function isRecord6(value) {
26342
+ function isRecord7(value) {
25810
26343
  return typeof value === "object" && value !== null && !Array.isArray(value);
25811
26344
  }
25812
26345
  function isPlainRecord6(value) {
25813
- if (!isRecord6(value))
26346
+ if (!isRecord7(value))
25814
26347
  return false;
25815
26348
  const prototype = Object.getPrototypeOf(value);
25816
26349
  return prototype === Object.prototype || prototype === null;
@@ -28087,6 +28620,10 @@ var ModernHarnessSession = class {
28087
28620
  this.#fallbackThinkingOptionId = configuration.state.effectiveThinkingOptionId;
28088
28621
  this.capabilities = modernSessionCapabilities(this.#permissionModes);
28089
28622
  this.outputs = this.#channel.outputs;
28623
+ const usageHistory = deepSeekUsageHistory(this.#events);
28624
+ for (const request of usageHistory.requests)
28625
+ this.#emit({ type: "usage.request", request });
28626
+ this.#emit({ type: "usage.history", complete: usageHistory.complete });
28090
28627
  this.commands = {
28091
28628
  list: () => this.#listHarnessCommands(),
28092
28629
  execute: (command) => this.#executeHarnessCommand(command)
@@ -29076,6 +29613,7 @@ ${question.detail}` : question.question;
29076
29613
  this.#validator.accept(event);
29077
29614
  this.#observeAssistantSettlement(event);
29078
29615
  this.#events.push(event);
29616
+ this.#meterUsage(event);
29079
29617
  this.#historyBytes += bytes;
29080
29618
  this.#receive(event);
29081
29619
  }
@@ -30151,6 +30689,14 @@ ${question.detail}` : question.question;
30151
30689
  #emit(event) {
30152
30690
  this.#channel.emit({ kind: "event", event });
30153
30691
  }
30692
+ /** Publishes a live model request settled in the journal to Host usage metering. */
30693
+ #meterUsage(event) {
30694
+ const record2 = deepSeekUsageRecord(event, false);
30695
+ if (record2.kind === "request")
30696
+ this.#emit({ type: "usage.request", request: record2.request });
30697
+ else if (record2.kind === "missing")
30698
+ this.#emit({ type: "usage.history", complete: false });
30699
+ }
30154
30700
  };
30155
30701
  var OperationAborted = class extends Error {
30156
30702
  constructor() {
@@ -30481,7 +31027,7 @@ function safeTimerDelay(value, name) {
30481
31027
 
30482
31028
  // dist/modern/session-list.js
30483
31029
  import { Buffer as Buffer5 } from "node:buffer";
30484
- import path6 from "node:path";
31030
+ import path7 from "node:path";
30485
31031
  var MAX_SESSION_LIST_BYTES = 32 * 1024 * 1024;
30486
31032
  var MAX_SESSION_LIST_DEPTH = 64;
30487
31033
  var MAX_SESSION_LIST_NODES = 2e5;
@@ -30600,7 +31146,7 @@ function parseSummary(value) {
30600
31146
  };
30601
31147
  }
30602
31148
  function isCanonicalAbsoluteCwd(value) {
30603
- return value !== void 0 && value.trim().length > 0 && !value.includes("\0") && path6.isAbsolute(value) && path6.resolve(value) === value;
31149
+ return value !== void 0 && value.trim().length > 0 && !value.includes("\0") && path7.isAbsolute(value) && path7.resolve(value) === value;
30604
31150
  }
30605
31151
  function parseModernSessionCandidates(value) {
30606
31152
  assertBoundedJson4(value);
@@ -30798,7 +31344,7 @@ var ModernDeepSeekHarnessAdapter = class {
30798
31344
  let session;
30799
31345
  let forkExpectation;
30800
31346
  try {
30801
- const cwd = path7.resolve(input.cwd);
31347
+ const cwd = path8.resolve(input.cwd);
30802
31348
  let forkInput = input.kind === "fork" ? parseModernForkInput(input, this.#profile) : void 0;
30803
31349
  const rollbackSourceSessionId = input.kind === "rollbackLastTurn" ? modernSessionId(input.sourceRef, "roll back") : void 0;
30804
31350
  let rollbackPlan;
@@ -30959,6 +31505,14 @@ var ModernDeepSeekHarnessAdapter = class {
30959
31505
  this.#sessions.add(openedSession);
30960
31506
  await this.#startEvents();
30961
31507
  this.#assertAccepting();
31508
+ if (input.kind === "resume" && input.permissionModeId) {
31509
+ const restored = await openedSession.execute({
31510
+ type: "permissionMode.select",
31511
+ permissionModeId: input.permissionModeId
31512
+ });
31513
+ if (!restored.ok)
31514
+ throw new AdapterOperationError(restored.error);
31515
+ }
30962
31516
  return { ok: true, value: openedSession };
30963
31517
  } catch (error51) {
30964
31518
  await session?.close().catch(() => void 0);
@@ -31001,7 +31555,7 @@ var ModernDeepSeekHarnessAdapter = class {
31001
31555
  });
31002
31556
  if (!result.ok)
31003
31557
  throw new AdapterOperationError(remoteFailure2("session/create", result.error));
31004
- if (!isRecord7(result.value) || !hasExactOptionalKeys(result.value, ["sessionId"], ["agentPreset"]) || result.value.sessionId !== requestedSessionId || Object.hasOwn(result.value, "agentPreset") && typeof result.value.agentPreset !== "string" || agentPreset !== void 0 && result.value.agentPreset !== agentPreset) {
31558
+ if (!isRecord8(result.value) || !hasExactOptionalKeys(result.value, ["sessionId"], ["agentPreset"]) || result.value.sessionId !== requestedSessionId || Object.hasOwn(result.value, "agentPreset") && typeof result.value.agentPreset !== "string" || agentPreset !== void 0 && result.value.agentPreset !== agentPreset) {
31005
31559
  throw new AdapterOperationError({
31006
31560
  code: "protocolError",
31007
31561
  message: "DeepSeek Harness session/create returned an invalid Session identity",
@@ -31085,7 +31639,7 @@ var ModernDeepSeekHarnessAdapter = class {
31085
31639
  const result = await this.#connection.call("session/fork", { request: { sessionId: input.sourceSessionId, atSeq } }, this.#lifetime.signal);
31086
31640
  if (!result.ok)
31087
31641
  throw new AdapterOperationError(forkRemoteFailure(result.error));
31088
- if (!isRecord7(result.value) || !hasExactOptionalKeys(result.value, ["sessionId"], []) || typeof result.value.sessionId !== "string" || result.value.sessionId.trim() === "" || result.value.sessionId === input.sourceSessionId) {
31642
+ if (!isRecord8(result.value) || !hasExactOptionalKeys(result.value, ["sessionId"], []) || typeof result.value.sessionId !== "string" || result.value.sessionId.trim() === "" || result.value.sessionId === input.sourceSessionId) {
31089
31643
  throw forkProtocolError();
31090
31644
  }
31091
31645
  return {
@@ -31319,7 +31873,7 @@ function verifyCreateConfiguration(requested, observed) {
31319
31873
  }
31320
31874
  }
31321
31875
  function resolveCreateConfiguration(input, modelCatalog, permissionModes) {
31322
- let model;
31876
+ let model2;
31323
31877
  if (input.model || input.thinkingOptionId) {
31324
31878
  const requestedModel = input.model ?? modelCatalog.catalog.defaultModel;
31325
31879
  if (!requestedModel) {
@@ -31329,7 +31883,7 @@ function resolveCreateConfiguration(input, modelCatalog, permissionModes) {
31329
31883
  retryable: false
31330
31884
  });
31331
31885
  }
31332
- model = modernSelectionForModel(modelCatalog, requestedModel, input.thinkingOptionId);
31886
+ model2 = modernSelectionForModel(modelCatalog, requestedModel, input.thinkingOptionId);
31333
31887
  }
31334
31888
  const unattended = input.executionPolicy === "unattended-full-access";
31335
31889
  const permissionModeId = input.permissionModeId ?? (unattended ? harnessPermissionModeIdSchema.parse(DELEGATION_PERMISSION_PRESET) : void 0);
@@ -31341,7 +31895,7 @@ function resolveCreateConfiguration(input, modelCatalog, permissionModes) {
31341
31895
  });
31342
31896
  }
31343
31897
  return {
31344
- ...model ? { model } : {},
31898
+ ...model2 ? { model: model2 } : {},
31345
31899
  ...permissionModeId ? { permissionModeId } : {},
31346
31900
  unattended
31347
31901
  };
@@ -31351,7 +31905,7 @@ function delegationPermissionIsApplied(events) {
31351
31905
  let sandboxMode;
31352
31906
  let approvalPolicy;
31353
31907
  for (const event of events) {
31354
- if (!isRecord7(event.data))
31908
+ if (!isRecord8(event.data))
31355
31909
  continue;
31356
31910
  if (event.type === "permission/preset" && typeof event.data.preset === "string") {
31357
31911
  preset = event.data.preset;
@@ -31390,10 +31944,10 @@ function parseModernForkInput(input, profile) {
31390
31944
  };
31391
31945
  }
31392
31946
  function sessionLocatorMatches(locator) {
31393
- return locator === void 0 || isRecord7(locator) && Reflect.ownKeys(locator).length === 1 && typeof locator.dshVersion === "string" && isDeepSeekSemVer(locator.dshVersion);
31947
+ return locator === void 0 || isRecord8(locator) && Reflect.ownKeys(locator).length === 1 && typeof locator.dshVersion === "string" && isDeepSeekSemVer(locator.dshVersion);
31394
31948
  }
31395
31949
  function checkpointLocatorMatches(locator, profile) {
31396
- return isRecord7(locator) && Reflect.ownKeys(locator).length === 1 && locator.dshVersion === profile.version;
31950
+ return isRecord8(locator) && Reflect.ownKeys(locator).length === 1 && locator.dshVersion === profile.version;
31397
31951
  }
31398
31952
  function forkCheckpointError() {
31399
31953
  return new AdapterOperationError({
@@ -31555,7 +32109,7 @@ function sanitizedHarnessError2(error51) {
31555
32109
  ...error51.stderrTail ? { stderrTail: sanitizeDiagnosticTail(redactModernCredential(error51.stderrTail)) } : {}
31556
32110
  };
31557
32111
  }
31558
- function isRecord7(value) {
32112
+ function isRecord8(value) {
31559
32113
  return typeof value === "object" && value !== null && !Array.isArray(value);
31560
32114
  }
31561
32115
  function hasExactOptionalKeys(value, required2, optional2) {
@@ -31577,6 +32131,7 @@ var DelegateSelectionError = class extends Error {
31577
32131
  var DeepSeekHarnessAdapter = class {
31578
32132
  commandCatalog = deepSeekHarnessCommandCatalog();
31579
32133
  harnessId = DEEPSEEK_HARNESS_ID4;
32134
+ usageStatistics;
31580
32135
  sessionImport = Object.freeze({
31581
32136
  listCandidates: () => this.#listSessionImportCandidates(),
31582
32137
  resolveCandidate: async (nativeSessionId) => {
@@ -31623,6 +32178,7 @@ var DeepSeekHarnessAdapter = class {
31623
32178
  #terminalFailure;
31624
32179
  constructor(options = {}, dependencies = {}) {
31625
32180
  this.#options = options;
32181
+ this.usageStatistics = createDshUsageStatistics(options.environment ?? process.env);
31626
32182
  this.#probeExecutable = dependencies.probeExecutable ?? ((input) => probeDeepSeekExecutableGeneration(input));
31627
32183
  this.#createModernAdapter = dependencies.createModernAdapter ?? ((modernOptions2) => new ModernDeepSeekHarnessAdapter(modernOptions2));
31628
32184
  }