dsh-model-think-level 2.3.6 → 2.4.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.
package/lib/index.js CHANGED
@@ -18,6 +18,8 @@ var UNSET_MARKER = "reasoningEffortsUnset";
18
18
  var INPUT_UNSET_MARKER = "inputUnset";
19
19
  var INPUT_IMAGE_GEN_MARKER = "inputImageGen";
20
20
  var AUTOFILL_MARKER = "reasoningEffortsAutofilled";
21
+ var CAMOUFLAGE_PATH = "/dsh-model-think-level/camouflage";
22
+ var CAMOUFLAGE_FILE = "camouflage.json";
21
23
  var IMAGE_CONFIG_PATH = "/dsh-model-think-level/image-config";
22
24
  var IMAGE_CONFIG_FILE = "image.json";
23
25
  var IMAGE_MCP_PATCH_ID = "dsh-image-mcp";
@@ -847,6 +849,159 @@ function commitUiOrderGuarded(patch, at, file = uiOrderFilePath()) {
847
849
  return { document, stale: false };
848
850
  }
849
851
 
852
+ // src/camouflage-store.ts
853
+ import { mkdirSync as mkdirSync4, readFileSync as readFileSync4, renameSync as renameSync4, unlinkSync as unlinkSync4, writeFileSync as writeFileSync4 } from "node:fs";
854
+ import { dirname as dirname4, join as join4 } from "node:path";
855
+
856
+ // src/camouflage.ts
857
+ import { randomUUID as randomUUID2 } from "node:crypto";
858
+ var CAMOUFLAGE_PRESETS = ["codex", "claude"];
859
+ function isCamouflagePreset(value) {
860
+ return value === "codex" || value === "claude";
861
+ }
862
+ var CLAUDE_CLI_VERSION = "2.1.251";
863
+ var CODEX_CLI_VERSION = "0.55.0";
864
+ var PROCESS_DEVICE_ID = randomUUID2().replace(/-/g, "");
865
+ var PROCESS_SESSION_ID = randomUUID2();
866
+ var PROCESS_CODEX_SESSION_ID = randomUUID2();
867
+ function camouflageUserAgent(preset) {
868
+ return preset === "codex" ? `codex_cli_rs/${CODEX_CLI_VERSION} (macOS 15.6; arm64)` : `claude-cli/${CLAUDE_CLI_VERSION} (external, cli)`;
869
+ }
870
+ function isAnthropicMessagesUrl(url) {
871
+ try {
872
+ const pathname = new URL(url).pathname.replace(/\/+$/, "");
873
+ return pathname.endsWith("/v1/messages") || pathname.endsWith("/messages");
874
+ } catch {
875
+ return false;
876
+ }
877
+ }
878
+ function camouflageHeaders(preset) {
879
+ if (preset === "codex") {
880
+ return {
881
+ "user-agent": camouflageUserAgent("codex"),
882
+ originator: "codex_cli_rs",
883
+ "x-codex-session-id": PROCESS_CODEX_SESSION_ID
884
+ };
885
+ }
886
+ return {
887
+ "user-agent": camouflageUserAgent("claude"),
888
+ "x-app": "cli",
889
+ "anthropic-version": "2023-06-01",
890
+ "anthropic-beta": "claude-code-20250219"
891
+ };
892
+ }
893
+ function applyCamouflageHeaders(headers, preset) {
894
+ let changed = false;
895
+ for (const [name2, value] of Object.entries(camouflageHeaders(preset))) {
896
+ if (name2 === "anthropic-version" && headers.has(name2)) continue;
897
+ if (headers.get(name2) === value) continue;
898
+ try {
899
+ headers.set(name2, value);
900
+ changed = true;
901
+ } catch {
902
+ }
903
+ }
904
+ return changed;
905
+ }
906
+ var CLAUDE_CODE_SYSTEM_TEXT = "You are Claude Code, Anthropic's CLI for Claude.";
907
+ function camouflageClaudeUserId() {
908
+ return `user_${PROCESS_DEVICE_ID}_account_${PROCESS_DEVICE_ID}_session_${PROCESS_SESSION_ID}`;
909
+ }
910
+ function patchCamouflageBody(text, preset, url) {
911
+ if (preset !== "claude") return void 0;
912
+ if (!isAnthropicMessagesUrl(url)) return void 0;
913
+ let body;
914
+ try {
915
+ body = JSON.parse(text);
916
+ } catch {
917
+ return void 0;
918
+ }
919
+ if (typeof body !== "object" || body === null || Array.isArray(body)) return void 0;
920
+ const record = body;
921
+ let changed = false;
922
+ const system = record["system"];
923
+ if (Array.isArray(system)) {
924
+ const first = system[0];
925
+ const firstText = typeof first === "object" && first !== null && !Array.isArray(first) ? first["text"] : void 0;
926
+ if (typeof firstText !== "string" || !firstText.startsWith("You are Claude Code")) {
927
+ system.unshift({ type: "text", text: CLAUDE_CODE_SYSTEM_TEXT });
928
+ changed = true;
929
+ }
930
+ } else if (typeof system === "string") {
931
+ if (!system.startsWith("You are Claude Code")) {
932
+ record["system"] = [
933
+ { type: "text", text: CLAUDE_CODE_SYSTEM_TEXT },
934
+ { type: "text", text: system }
935
+ ];
936
+ changed = true;
937
+ }
938
+ } else {
939
+ record["system"] = [{ type: "text", text: CLAUDE_CODE_SYSTEM_TEXT }];
940
+ changed = true;
941
+ }
942
+ const metadata = record["metadata"];
943
+ const existingUserId = typeof metadata === "object" && metadata !== null && !Array.isArray(metadata) ? metadata["user_id"] : void 0;
944
+ if (typeof existingUserId !== "string" || existingUserId.length === 0) {
945
+ record["metadata"] = {
946
+ ...typeof metadata === "object" && metadata !== null && !Array.isArray(metadata) ? metadata : {},
947
+ user_id: camouflageClaudeUserId()
948
+ };
949
+ changed = true;
950
+ }
951
+ return changed ? JSON.stringify(record) : void 0;
952
+ }
953
+
954
+ // src/camouflage-store.ts
955
+ function emptyCamouflage() {
956
+ return { version: 1, providers: {} };
957
+ }
958
+ function camouflageFilePath(home = harnessHome()) {
959
+ return join4(home, "dsh-model-think-level", CAMOUFLAGE_FILE);
960
+ }
961
+ function parseCamouflage(raw) {
962
+ if (typeof raw !== "object" || raw === null || Array.isArray(raw)) return emptyCamouflage();
963
+ const providers = raw["providers"];
964
+ if (typeof providers !== "object" || providers === null || Array.isArray(providers)) return emptyCamouflage();
965
+ const out = {};
966
+ for (const [route, value] of Object.entries(providers)) {
967
+ if (route.length === 0) continue;
968
+ if (!isCamouflagePreset(value)) continue;
969
+ Object.defineProperty(out, route, { value, enumerable: true, configurable: true, writable: true });
970
+ }
971
+ return { version: 1, providers: out };
972
+ }
973
+ function readCamouflage(file = camouflageFilePath()) {
974
+ try {
975
+ return parseCamouflage(JSON.parse(readFileSync4(file, "utf8")));
976
+ } catch {
977
+ return emptyCamouflage();
978
+ }
979
+ }
980
+ function writeCamouflage(document, file = camouflageFilePath()) {
981
+ mkdirSync4(dirname4(file), { recursive: true });
982
+ const temporary = `${file}.${process.pid}.tmp`;
983
+ writeFileSync4(temporary, `${JSON.stringify(document, null, 2)}
984
+ `, "utf8");
985
+ try {
986
+ renameSync4(temporary, file);
987
+ } catch (error) {
988
+ try {
989
+ unlinkSync4(temporary);
990
+ } catch {
991
+ }
992
+ throw error;
993
+ }
994
+ }
995
+ function setRouteCamouflage(route, preset, file = camouflageFilePath()) {
996
+ const current = readCamouflage(file);
997
+ const providers = { ...current.providers };
998
+ if (preset === void 0) delete providers[route];
999
+ else Object.defineProperty(providers, route, { value: preset, enumerable: true, configurable: true, writable: true });
1000
+ const next = { version: 1, providers };
1001
+ writeCamouflage(next, file);
1002
+ return next;
1003
+ }
1004
+
850
1005
  // src/multi-key-listing.ts
851
1006
  var DEFAULT_PROBE_CONCURRENCY = 4;
852
1007
  var MODEL_ORDER = new Intl.Collator("en", { numeric: true, sensitivity: "base" });
@@ -1060,7 +1215,7 @@ function recordHeaderConflicts(index, existing, route, headers) {
1060
1215
  }
1061
1216
  }
1062
1217
  }
1063
- function buildHeaderIndex(providers) {
1218
+ function buildHeaderIndex(providers, camouflages) {
1064
1219
  const index = emptyIndex();
1065
1220
  const claimedUserAgents = /* @__PURE__ */ new Map();
1066
1221
  for (const [route, rawProfile] of Object.entries(providers)) {
@@ -1072,6 +1227,7 @@ function buildHeaderIndex(providers) {
1072
1227
  const sendable = sendableHeadersOf(profile) ?? {};
1073
1228
  const hasHeaders = Object.keys(sendable).length > 0;
1074
1229
  const userAgent = Object.entries(sendable).find(([name2]) => name2.toLowerCase() === "user-agent")?.[1];
1230
+ const camouflage = camouflages !== void 0 && Object.hasOwn(camouflages, route) ? camouflages[route] : void 0;
1075
1231
  const override = {
1076
1232
  origin,
1077
1233
  pathPrefix: pathPrefixOf(baseURL ?? origin),
@@ -1079,7 +1235,8 @@ function buildHeaderIndex(providers) {
1079
1235
  route,
1080
1236
  modelIds: modelIdsOf(profile),
1081
1237
  hasHeaders,
1082
- ...userAgent === void 0 ? {} : { userAgent }
1238
+ ...userAgent === void 0 ? {} : { userAgent },
1239
+ ...camouflage === void 0 ? {} : { camouflage }
1083
1240
  };
1084
1241
  index.routes.push(override);
1085
1242
  if (!hasHeaders) continue;
@@ -3261,6 +3418,9 @@ function passthroughInit(input, init) {
3261
3418
  headers.delete(WIRE_DISPATCH_HEADER);
3262
3419
  return { ...init, headers };
3263
3420
  }
3421
+ function textByteLength(text) {
3422
+ return new TextEncoder().encode(text).byteLength;
3423
+ }
3264
3424
  function makeWrapper(base, entries) {
3265
3425
  return async function fetchWithProviderHeaders(input, init) {
3266
3426
  const url = requestUrlOf(input);
@@ -3304,6 +3464,9 @@ function makeWrapper(base, entries) {
3304
3464
  if (override === void 0) return base(input, passthroughInit(input, init));
3305
3465
  const patched = seedHeaders(input, init);
3306
3466
  let hasPatch = false;
3467
+ if (override.camouflage !== void 0 && applyCamouflageHeaders(patched, override.camouflage)) {
3468
+ hasPatch = true;
3469
+ }
3307
3470
  if (override.hasHeaders) {
3308
3471
  for (const [name2, value] of Object.entries(override.headers)) {
3309
3472
  try {
@@ -3313,9 +3476,28 @@ function makeWrapper(base, entries) {
3313
3476
  }
3314
3477
  }
3315
3478
  }
3316
- const attempt = (keyValue) => {
3479
+ let camouflageBody;
3480
+ if (override.camouflage === "claude") {
3481
+ const text = await bodyTextOf(input, init);
3482
+ if (text !== void 0) {
3483
+ camouflageBody = patchCamouflageBody(text, "claude", url);
3484
+ if (camouflageBody !== void 0) hasPatch = true;
3485
+ }
3486
+ }
3487
+ const attempt = (keyValue, body = camouflageBody) => {
3317
3488
  const headers = new Headers(patched);
3318
3489
  if (keyValue !== void 0) applyKeyToHeaders(headers, keyValue);
3490
+ if (body !== void 0) {
3491
+ headers.set("content-length", String(textByteLength(body)));
3492
+ if (typeof Request !== "undefined" && input instanceof Request) {
3493
+ try {
3494
+ return base(new Request(input.clone(), { ...init, body, headers }), { ...init, body, headers });
3495
+ } catch {
3496
+ }
3497
+ } else {
3498
+ return base(input, { ...init, body, headers });
3499
+ }
3500
+ }
3319
3501
  if (typeof Request !== "undefined" && input instanceof Request) {
3320
3502
  return base(new Request(input.clone(), { headers }), { ...init, headers });
3321
3503
  }
@@ -3597,6 +3779,30 @@ function routeOverrideOf(source, model) {
3597
3779
  return void 0;
3598
3780
  }
3599
3781
  }
3782
+ function withCamouflageHeaders(merged, preset) {
3783
+ const identity = camouflageHeaders(preset);
3784
+ const present = new Set(Object.keys(merged).map((name2) => name2.toLowerCase()));
3785
+ const next = { ...merged };
3786
+ for (const [name2, value] of Object.entries(identity)) {
3787
+ if (!present.has(name2)) next[name2] = value;
3788
+ }
3789
+ next["user-agent"] = identity["user-agent"];
3790
+ return next;
3791
+ }
3792
+ function withClaudeIdentityContext(context) {
3793
+ if (!isRecord(context)) return context;
3794
+ const systemPrompt = context["systemPrompt"];
3795
+ if (typeof systemPrompt === "string") {
3796
+ if (systemPrompt.startsWith("You are Claude Code")) return context;
3797
+ return { ...context, systemPrompt: `${CLAUDE_CODE_SYSTEM_TEXT}
3798
+
3799
+ ${systemPrompt}` };
3800
+ }
3801
+ if (systemPrompt === void 0 || systemPrompt === null) {
3802
+ return { ...context, systemPrompt: CLAUDE_CODE_SYSTEM_TEXT };
3803
+ }
3804
+ return context;
3805
+ }
3600
3806
  function errorTextOf(event) {
3601
3807
  const error = isRecord(event["error"]) ? event["error"] : void 0;
3602
3808
  const parts = [error?.["message"], error?.["errorMessage"], event["reason"]];
@@ -3620,7 +3826,8 @@ function modelsProxyOf(models, source) {
3620
3826
  const transformHeaders = async (headers) => {
3621
3827
  const merged = existing === void 0 ? headers : await existing(headers);
3622
3828
  const override = routeOverrideOf(source, model);
3623
- return override?.hasHeaders ? { ...merged, ...override.headers } : merged;
3829
+ const identified = override?.camouflage === void 0 ? merged : withCamouflageHeaders(merged, override.camouflage);
3830
+ return override?.hasHeaders ? { ...identified, ...override.headers } : identified;
3624
3831
  };
3625
3832
  const markedTransformHeaders = async (headers) => ({
3626
3833
  ...await transformHeaders(headers),
@@ -3656,7 +3863,15 @@ function modelsProxyOf(models, source) {
3656
3863
  }
3657
3864
  const mergedHeaders = await transformHeaders(isRecord(options["headers"]) ? options["headers"] : {});
3658
3865
  const implementation = await loadProtocol(protocol);
3659
- const dispatchedContext = await normalizeDispatchedContext(context);
3866
+ const switchedToClaude = protocol === "anthropic-messages" && routeOverrideOf(source, model)?.camouflage === "claude";
3867
+ const normalized2 = await normalizeDispatchedContext(context);
3868
+ const dispatchedContext = switchedToClaude ? withClaudeIdentityContext(normalized2) : normalized2;
3869
+ const existingMetadata = isRecord(options["metadata"]) ? options["metadata"] : void 0;
3870
+ const suppliedUserId = existingMetadata?.["user_id"];
3871
+ const metadata = switchedToClaude ? {
3872
+ ...existingMetadata ?? {},
3873
+ user_id: typeof suppliedUserId === "string" && suppliedUserId.length > 0 ? suppliedUserId : camouflageClaudeUserId()
3874
+ } : void 0;
3660
3875
  return implementation.streamSimple(
3661
3876
  { ...modelObject, api: protocol, baseUrl },
3662
3877
  dispatchedContext,
@@ -3664,6 +3879,7 @@ function modelsProxyOf(models, source) {
3664
3879
  ...options,
3665
3880
  apiKey: candidate.value,
3666
3881
  headers: { ...mergedHeaders, [WIRE_DISPATCH_HEADER]: "1" },
3882
+ ...metadata === void 0 ? {} : { metadata },
3667
3883
  transformHeaders: void 0
3668
3884
  }
3669
3885
  );
@@ -3927,9 +4143,9 @@ function installPiAiHeaderTransforms(llm, source) {
3927
4143
  }
3928
4144
 
3929
4145
  // src/headers-conflict.ts
3930
- import { existsSync, readFileSync as readFileSync4 } from "node:fs";
4146
+ import { existsSync, readFileSync as readFileSync5 } from "node:fs";
3931
4147
  import { createRequire } from "node:module";
3932
- import { dirname as dirname4, join as join4, resolve as resolve2 } from "node:path";
4148
+ import { dirname as dirname5, join as join5, resolve as resolve2 } from "node:path";
3933
4149
  var SIBLING_PACKAGES = [
3934
4150
  "dsh-client-masquerade",
3935
4151
  "dsh-llm-headers",
@@ -3941,20 +4157,20 @@ function searchRoots() {
3941
4157
  const roots = /* @__PURE__ */ new Set();
3942
4158
  const entry = process.argv[1];
3943
4159
  if (typeof entry === "string" && entry.length > 0) {
3944
- let dir = dirname4(resolve2(entry));
4160
+ let dir = dirname5(resolve2(entry));
3945
4161
  for (let depth = 0; depth < 8; depth += 1) {
3946
- roots.add(join4(dir, "node_modules"));
3947
- const parent = dirname4(dir);
4162
+ roots.add(join5(dir, "node_modules"));
4163
+ const parent = dirname5(dir);
3948
4164
  if (parent === dir) break;
3949
4165
  dir = parent;
3950
4166
  }
3951
4167
  }
3952
- roots.add(join4(process.cwd(), "node_modules"));
4168
+ roots.add(join5(process.cwd(), "node_modules"));
3953
4169
  try {
3954
4170
  const require2 = createRequire(import.meta.url);
3955
4171
  for (const name2 of SIBLING_PACKAGES) {
3956
4172
  try {
3957
- roots.add(join4(dirname4(dirname4(dirname4(require2.resolve(`${name2}/package.json`)))), "node_modules"));
4173
+ roots.add(join5(dirname5(dirname5(dirname5(require2.resolve(`${name2}/package.json`)))), "node_modules"));
3958
4174
  } catch {
3959
4175
  }
3960
4176
  }
@@ -3963,14 +4179,14 @@ function searchRoots() {
3963
4179
  return [...roots];
3964
4180
  }
3965
4181
  function findAdapterFile() {
3966
- const relative = join4("@deepseek-ai", "dsh-llm-pi-ai", "lib", "index.js");
4182
+ const relative = join5("@deepseek-ai", "dsh-llm-pi-ai", "lib", "index.js");
3967
4183
  const candidates = [];
3968
4184
  try {
3969
4185
  const require2 = createRequire(import.meta.url);
3970
4186
  candidates.push(require2.resolve("@deepseek-ai/dsh-llm-pi-ai"));
3971
4187
  } catch {
3972
4188
  }
3973
- for (const root of searchRoots()) candidates.push(join4(root, relative));
4189
+ for (const root of searchRoots()) candidates.push(join5(root, relative));
3974
4190
  for (const candidate of candidates) {
3975
4191
  if (existsSync(candidate)) return candidate;
3976
4192
  }
@@ -3981,7 +4197,7 @@ function adapterSourcePatched(source) {
3981
4197
  }
3982
4198
  function adapterPatchState(path) {
3983
4199
  try {
3984
- return adapterSourcePatched(readFileSync4(path, "utf8")) ? "patched" : "stock";
4200
+ return adapterSourcePatched(readFileSync5(path, "utf8")) ? "patched" : "stock";
3985
4201
  } catch {
3986
4202
  return "unknown";
3987
4203
  }
@@ -3992,8 +4208,8 @@ function findSiblings() {
3992
4208
  for (const root of searchRoots()) {
3993
4209
  for (const name2 of SIBLING_PACKAGES) {
3994
4210
  if (seen.has(name2)) continue;
3995
- const dir = join4(root, name2);
3996
- const manifest = join4(dir, "package.json");
4211
+ const dir = join5(root, name2);
4212
+ const manifest = join5(dir, "package.json");
3997
4213
  if (!existsSync(manifest)) continue;
3998
4214
  seen.add(name2);
3999
4215
  found.push({ name: name2, path: dir });
@@ -4025,8 +4241,8 @@ function detectHeaderConflicts() {
4025
4241
  }
4026
4242
 
4027
4243
  // src/image/config.ts
4028
- import { mkdirSync as mkdirSync4, readFileSync as readFileSync5, renameSync as renameSync4, unlinkSync as unlinkSync4, writeFileSync as writeFileSync4 } from "node:fs";
4029
- import { dirname as dirname5, join as join5 } from "node:path";
4244
+ import { mkdirSync as mkdirSync5, readFileSync as readFileSync6, renameSync as renameSync5, unlinkSync as unlinkSync5, writeFileSync as writeFileSync5 } from "node:fs";
4245
+ import { dirname as dirname6, join as join6 } from "node:path";
4030
4246
 
4031
4247
  // src/image/sizes.ts
4032
4248
  var IMAGE_SIZE_TIERS = [
@@ -4043,7 +4259,7 @@ var IMAGE_FALLBACK_PARAMS = {
4043
4259
  responseFormat: "b64_json"
4044
4260
  };
4045
4261
  function imageConfigFilePath(home = harnessHome()) {
4046
- return join5(home, "dsh-model-think-level", IMAGE_CONFIG_FILE);
4262
+ return join6(home, "dsh-model-think-level", IMAGE_CONFIG_FILE);
4047
4263
  }
4048
4264
  function emptyImageConfig(now = () => /* @__PURE__ */ new Date()) {
4049
4265
  return {
@@ -4144,7 +4360,7 @@ function parseImageModel(raw) {
4144
4360
  function readImageConfig(file = imageConfigFilePath()) {
4145
4361
  let text;
4146
4362
  try {
4147
- text = readFileSync5(file, "utf8");
4363
+ text = readFileSync6(file, "utf8");
4148
4364
  } catch {
4149
4365
  return emptyImageConfig();
4150
4366
  }
@@ -4155,15 +4371,15 @@ function readImageConfig(file = imageConfigFilePath()) {
4155
4371
  }
4156
4372
  }
4157
4373
  function writeImageConfig(document, file = imageConfigFilePath()) {
4158
- mkdirSync4(dirname5(file), { recursive: true });
4374
+ mkdirSync5(dirname6(file), { recursive: true });
4159
4375
  const temporary = `${file}.${process.pid}.tmp`;
4160
- writeFileSync4(temporary, `${JSON.stringify(document, null, 2)}
4376
+ writeFileSync5(temporary, `${JSON.stringify(document, null, 2)}
4161
4377
  `, "utf8");
4162
4378
  try {
4163
- renameSync4(temporary, file);
4379
+ renameSync5(temporary, file);
4164
4380
  } catch (error) {
4165
4381
  try {
4166
- unlinkSync4(temporary);
4382
+ unlinkSync5(temporary);
4167
4383
  } catch {
4168
4384
  }
4169
4385
  throw error;
@@ -4251,8 +4467,8 @@ function updateImageConfig(mutate, file = imageConfigFilePath()) {
4251
4467
  }
4252
4468
 
4253
4469
  // src/image/generate.ts
4254
- import { mkdirSync as mkdirSync5, readFileSync as readFileSync6, writeFileSync as writeFileSync5, existsSync as existsSync2, statSync } from "node:fs";
4255
- import { dirname as dirname6, join as join6, resolve as resolve3 } from "node:path";
4470
+ import { mkdirSync as mkdirSync6, readFileSync as readFileSync7, writeFileSync as writeFileSync6, existsSync as existsSync2, statSync } from "node:fs";
4471
+ import { dirname as dirname7, join as join7, resolve as resolve3 } from "node:path";
4256
4472
 
4257
4473
  // src/image/deadline.ts
4258
4474
  function createImageDeadline(timeoutMs, caller, errorFor) {
@@ -4492,19 +4708,19 @@ function outputDirOf(deps, config) {
4492
4708
  const home = deps.home?.() ?? harnessHome();
4493
4709
  const dir = config.outputDir;
4494
4710
  if (/^([A-Za-z]:[\\/]|\/)/.test(dir)) return dir;
4495
- return join6(home, "dsh-model-think-level", dir);
4711
+ return join7(home, "dsh-model-think-level", dir);
4496
4712
  }
4497
4713
  function destinationOf(dir, slug, now) {
4498
- const base = join6(dir, `${slug}-${now()}.png`);
4714
+ const base = join7(dir, `${slug}-${now()}.png`);
4499
4715
  if (!existsSync2(base)) return base;
4500
4716
  for (let index = 2; ; index += 1) {
4501
- const candidate = join6(dir, `${slug}-${now()}-${index}.png`);
4717
+ const candidate = join7(dir, `${slug}-${now()}-${index}.png`);
4502
4718
  if (!existsSync2(candidate)) return candidate;
4503
4719
  }
4504
4720
  }
4505
4721
  function resolveDestination(requested, fallbackDir, slug, now) {
4506
4722
  if (requested === void 0 || requested.trim().length === 0) {
4507
- mkdirSync5(fallbackDir, { recursive: true });
4723
+ mkdirSync6(fallbackDir, { recursive: true });
4508
4724
  return destinationOf(fallbackDir, slug, now);
4509
4725
  }
4510
4726
  const target = resolve3(requested.trim());
@@ -4514,10 +4730,10 @@ function resolveDestination(requested, fallbackDir, slug, now) {
4514
4730
  } catch {
4515
4731
  }
4516
4732
  if (isDir || /[\\/]$/.test(target) || !target.toLowerCase().endsWith(".png")) {
4517
- mkdirSync5(target, { recursive: true });
4733
+ mkdirSync6(target, { recursive: true });
4518
4734
  return destinationOf(target, slug, now);
4519
4735
  }
4520
- mkdirSync5(dirname6(target), { recursive: true });
4736
+ mkdirSync6(dirname7(target), { recursive: true });
4521
4737
  if (!existsSync2(target)) return target;
4522
4738
  for (let index = 2; ; index += 1) {
4523
4739
  const candidate = target.replace(/\.png$/i, `-${index}.png`);
@@ -4607,7 +4823,7 @@ async function generateWithinDeadline(deps, request, config, deadline) {
4607
4823
  const absolute = resolve3(path);
4608
4824
  if (!existsSync2(absolute)) throw new GenerateError("reference", `\u53C2\u8003\u56FE\u4E0D\u5B58\u5728\u6216\u4E0D\u53EF\u8BFB\uFF1A${path}`);
4609
4825
  try {
4610
- return { name: absolute.split(/[\\/]/).pop() ?? "image", bytes: readFileSync6(absolute), mime: mimeOfPath(absolute) };
4826
+ return { name: absolute.split(/[\\/]/).pop() ?? "image", bytes: readFileSync7(absolute), mime: mimeOfPath(absolute) };
4611
4827
  } catch {
4612
4828
  throw new GenerateError("reference", `\u53C2\u8003\u56FE\u4E0D\u5B58\u5728\u6216\u4E0D\u53EF\u8BFB\uFF1A${path}`);
4613
4829
  }
@@ -4684,7 +4900,7 @@ async function generateWithinDeadline(deps, request, config, deadline) {
4684
4900
  const filePath = resolveDestination(request.outputPath, outputDirOf(deps, config), promptSlug(prompt), now);
4685
4901
  const bytes = Uint8Array.from(atob(data), (ch) => ch.charCodeAt(0));
4686
4902
  deadline.check();
4687
- writeFileSync5(filePath, bytes);
4903
+ writeFileSync6(filePath, bytes);
4688
4904
  images.push({ filePath, data });
4689
4905
  }
4690
4906
  deadline.check();
@@ -5114,19 +5330,19 @@ function imageToolHint(config) {
5114
5330
  }
5115
5331
 
5116
5332
  // src/image/legacy-cleanup.ts
5117
- import { copyFileSync, existsSync as existsSync3, mkdirSync as mkdirSync6, readFileSync as readFileSync7, readdirSync as readdirSync2, statSync as statSync2, writeFileSync as writeFileSync6 } from "node:fs";
5118
- import { dirname as dirname7, join as join7 } from "node:path";
5333
+ import { copyFileSync, existsSync as existsSync3, mkdirSync as mkdirSync7, readFileSync as readFileSync8, readdirSync as readdirSync2, statSync as statSync2, writeFileSync as writeFileSync7 } from "node:fs";
5334
+ import { dirname as dirname8, join as join8 } from "node:path";
5119
5335
  var MARK_BEGIN = `# >>> ${IMAGE_MCP_PATCH_MARK}:begin`;
5120
5336
  var MARK_END = `# <<< ${IMAGE_MCP_PATCH_MARK}:end`;
5121
5337
  function resolveLegacyPatchFile(home = harnessHome()) {
5122
5338
  const explicit = process.env["DSH_PROFILE"];
5123
- if (explicit !== void 0 && explicit.length > 0) return join7(home, "profiles", explicit, "cordis.patch.yml");
5124
- const profilesDir = join7(home, "profiles");
5339
+ if (explicit !== void 0 && explicit.length > 0) return join8(home, "profiles", explicit, "cordis.patch.yml");
5340
+ const profilesDir = join8(home, "profiles");
5125
5341
  try {
5126
5342
  if (existsSync3(profilesDir)) {
5127
5343
  const candidates = [];
5128
5344
  for (const name2 of readdirSync2(profilesDir)) {
5129
- const file = join7(profilesDir, name2, "cordis.patch.yml");
5345
+ const file = join8(profilesDir, name2, "cordis.patch.yml");
5130
5346
  if (!existsSync3(file)) continue;
5131
5347
  candidates.push({ file, mtime: statSync2(file).mtimeMs });
5132
5348
  }
@@ -5135,8 +5351,8 @@ function resolveLegacyPatchFile(home = harnessHome()) {
5135
5351
  }
5136
5352
  } catch {
5137
5353
  }
5138
- if (existsSync3(join7(home, "cordis.patch.yml"))) return join7(home, "cordis.patch.yml");
5139
- return join7(home, "profiles", "desktop", "cordis.patch.yml");
5354
+ if (existsSync3(join8(home, "cordis.patch.yml"))) return join8(home, "cordis.patch.yml");
5355
+ return join8(home, "profiles", "desktop", "cordis.patch.yml");
5140
5356
  }
5141
5357
  function markerRange(text) {
5142
5358
  const start = text.indexOf(MARK_BEGIN);
@@ -5197,7 +5413,7 @@ function mtimeOf(patchFile) {
5197
5413
  var ModifiedError = class extends Error {
5198
5414
  };
5199
5415
  function spliceOnce(patchFile, mtimeMs) {
5200
- const current = readFileSync7(patchFile, "utf8");
5416
+ const current = readFileSync8(patchFile, "utf8");
5201
5417
  const range = legacyRange(current);
5202
5418
  if (range === void 0) return;
5203
5419
  let next = current.slice(0, range.start) + current.slice(range.end);
@@ -5211,9 +5427,9 @@ function spliceOnce(patchFile, mtimeMs) {
5211
5427
  } catch {
5212
5428
  }
5213
5429
  }
5214
- mkdirSync6(dirname7(patchFile), { recursive: true });
5215
- writeFileSync6(patchFile, next, "utf8");
5216
- const written = readFileSync7(patchFile, "utf8");
5430
+ mkdirSync7(dirname8(patchFile), { recursive: true });
5431
+ writeFileSync7(patchFile, next, "utf8");
5432
+ const written = readFileSync8(patchFile, "utf8");
5217
5433
  if (written !== next) throw new Error("the patch file did not hold the written bytes after the write");
5218
5434
  }
5219
5435
  function removeLegacyImageMcpPatch(home, patchFile) {
@@ -5225,7 +5441,7 @@ function removeLegacyImageMcpPatch(home, patchFile) {
5225
5441
  }
5226
5442
  let text;
5227
5443
  try {
5228
- text = readFileSync7(file, "utf8");
5444
+ text = readFileSync8(file, "utf8");
5229
5445
  } catch {
5230
5446
  return void 0;
5231
5447
  }
@@ -5398,9 +5614,9 @@ function backfillRolePin(model, providers, route) {
5398
5614
  }
5399
5615
 
5400
5616
  // src/fingerprint/bank.ts
5401
- import { existsSync as existsSync4, readFileSync as readFileSync8 } from "node:fs";
5617
+ import { existsSync as existsSync4, readFileSync as readFileSync9 } from "node:fs";
5402
5618
  import { fileURLToPath } from "node:url";
5403
- import { dirname as dirname8, join as join8 } from "node:path";
5619
+ import { dirname as dirname9, join as join9 } from "node:path";
5404
5620
 
5405
5621
  // src/fingerprint/core.ts
5406
5622
  var VALUE_MIN = 1;
@@ -5685,10 +5901,10 @@ function parseBank(raw) {
5685
5901
  }
5686
5902
  function bankCandidates() {
5687
5903
  const candidates = [];
5688
- let dir = dirname8(fileURLToPath(import.meta.url));
5904
+ let dir = dirname9(fileURLToPath(import.meta.url));
5689
5905
  for (let depth = 0; depth < 5; depth += 1) {
5690
- candidates.push(join8(dir, "assets", "unified_bank.json"));
5691
- const parent = dirname8(dir);
5906
+ candidates.push(join9(dir, "assets", "unified_bank.json"));
5907
+ const parent = dirname9(dir);
5692
5908
  if (parent === dir) break;
5693
5909
  dir = parent;
5694
5910
  }
@@ -5705,7 +5921,7 @@ function bankPath() {
5705
5921
  var cached;
5706
5922
  function loadBankSync() {
5707
5923
  if (cached !== void 0) return cached;
5708
- cached = parseBank(JSON.parse(readFileSync8(bankPath(), "utf8")));
5924
+ cached = parseBank(JSON.parse(readFileSync9(bankPath(), "utf8")));
5709
5925
  return cached;
5710
5926
  }
5711
5927
  function summarizeBank(bank) {
@@ -5974,8 +6190,8 @@ async function runChallenge(options) {
5974
6190
  }
5975
6191
 
5976
6192
  // src/fingerprint/store.ts
5977
- import { mkdirSync as mkdirSync7, readFileSync as readFileSync9, renameSync as renameSync5, unlinkSync as unlinkSync5, writeFileSync as writeFileSync7 } from "node:fs";
5978
- import { dirname as dirname9, join as join9 } from "node:path";
6193
+ import { mkdirSync as mkdirSync8, readFileSync as readFileSync10, renameSync as renameSync6, unlinkSync as unlinkSync6, writeFileSync as writeFileSync8 } from "node:fs";
6194
+ import { dirname as dirname10, join as join10 } from "node:path";
5979
6195
  var STATUSES = /* @__PURE__ */ new Set(["identified", "doubtful", "failed"]);
5980
6196
  function emptyFingerprintStore(bankBuiltAt2 = "") {
5981
6197
  return { version: 1, bankBuiltAt: bankBuiltAt2, records: {} };
@@ -5984,7 +6200,7 @@ function recordKeyOf(provider, model) {
5984
6200
  return `${provider}\0${model}`;
5985
6201
  }
5986
6202
  function fingerprintFilePath(home = harnessHome()) {
5987
- return join9(home, "dsh-model-think-level", "fingerprint.json");
6203
+ return join10(home, "dsh-model-think-level", "fingerprint.json");
5988
6204
  }
5989
6205
  function finiteNumber(value, fallback) {
5990
6206
  return typeof value === "number" && Number.isFinite(value) ? value : fallback;
@@ -6102,7 +6318,7 @@ function parseFingerprintStore(raw, bankBuiltAt2 = "") {
6102
6318
  function readFingerprintStore(bankBuiltAt2 = "", file = fingerprintFilePath()) {
6103
6319
  let text;
6104
6320
  try {
6105
- text = readFileSync9(file, "utf8");
6321
+ text = readFileSync10(file, "utf8");
6106
6322
  } catch (error) {
6107
6323
  if (typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT") {
6108
6324
  return emptyFingerprintStore(bankBuiltAt2);
@@ -6118,15 +6334,15 @@ function readFingerprintStore(bankBuiltAt2 = "", file = fingerprintFilePath()) {
6118
6334
  return parseFingerprintStore(raw, bankBuiltAt2);
6119
6335
  }
6120
6336
  function writeFingerprintStore(document, file = fingerprintFilePath()) {
6121
- mkdirSync7(dirname9(file), { recursive: true });
6337
+ mkdirSync8(dirname10(file), { recursive: true });
6122
6338
  const temporary = `${file}.${process.pid}.tmp`;
6123
- writeFileSync7(temporary, `${JSON.stringify(document, null, 2)}
6339
+ writeFileSync8(temporary, `${JSON.stringify(document, null, 2)}
6124
6340
  `, "utf8");
6125
6341
  try {
6126
- renameSync5(temporary, file);
6342
+ renameSync6(temporary, file);
6127
6343
  } catch (error) {
6128
6344
  try {
6129
- unlinkSync5(temporary);
6345
+ unlinkSync6(temporary);
6130
6346
  } catch {
6131
6347
  }
6132
6348
  throw error;
@@ -7015,7 +7231,8 @@ function apply(ctx, config = {}) {
7015
7231
  headerRetryTimers.add(timer);
7016
7232
  };
7017
7233
  const refreshHeaders = () => {
7018
- if (!resolved.uaOverride) {
7234
+ const camouflage = readCamouflage().providers;
7235
+ if (!resolved.uaOverride && Object.keys(camouflage).length === 0) {
7019
7236
  overlaySource.current = emptyIndex();
7020
7237
  stopHeaderRetries();
7021
7238
  return;
@@ -7028,7 +7245,7 @@ function apply(ctx, config = {}) {
7028
7245
  }
7029
7246
  stopHeaderRetries();
7030
7247
  const providers = isRecord(section) && isRecord(section["providers"]) ? section["providers"] : {};
7031
- overlaySource.current = buildHeaderIndex(providers);
7248
+ overlaySource.current = buildHeaderIndex(providers, camouflage);
7032
7249
  };
7033
7250
  refreshHeaders();
7034
7251
  refreshKeyScopes();
@@ -8133,6 +8350,62 @@ function apply(ctx, config = {}) {
8133
8350
  }),
8134
8351
  "dsh-model-think-level: ui-order route"
8135
8352
  );
8353
+ const requestSeamsInstalled = () => {
8354
+ if (headerOverlayInstalled()) return true;
8355
+ const state = headerBridgeState();
8356
+ return isRecord(state) && typeof state["adaptersPatched"] === "number" && state["adaptersPatched"] > 0;
8357
+ };
8358
+ ctx.effect(
8359
+ () => webServerCtx.webServer.register({
8360
+ kind: "exact",
8361
+ path: CAMOUFLAGE_PATH,
8362
+ handler: async (req, res) => {
8363
+ res.setHeader("cache-control", "no-store");
8364
+ if (!isTrustedRequest(req)) {
8365
+ sendJson(res, 403, { ok: false, error: "forbidden" });
8366
+ return;
8367
+ }
8368
+ if (req.method === "GET") {
8369
+ sendJson(res, 200, {
8370
+ ok: true,
8371
+ data: {
8372
+ presets: CAMOUFLAGE_PRESETS,
8373
+ providers: readCamouflage().providers,
8374
+ installed: requestSeamsInstalled()
8375
+ }
8376
+ });
8377
+ return;
8378
+ }
8379
+ if (req.method !== "POST") {
8380
+ sendJson(res, 405, { ok: false, error: "method not allowed" });
8381
+ return;
8382
+ }
8383
+ const body = await readJsonBody(req, 16384);
8384
+ if (!isRecord(body)) {
8385
+ sendJson(res, 400, { ok: false, error: "the body is not a JSON document" });
8386
+ return;
8387
+ }
8388
+ const route = body["route"];
8389
+ const preset = body["preset"];
8390
+ if (typeof route !== "string" || route.length === 0) {
8391
+ sendJson(res, 400, { ok: false, error: "route is required" });
8392
+ return;
8393
+ }
8394
+ if (preset !== null && !isCamouflagePreset(preset)) {
8395
+ sendJson(res, 400, { ok: false, error: "preset must be codex, claude or null" });
8396
+ return;
8397
+ }
8398
+ try {
8399
+ const document = setRouteCamouflage(route, preset ?? void 0);
8400
+ refreshHeaders();
8401
+ sendJson(res, 200, { ok: true, data: document });
8402
+ } catch (error) {
8403
+ sendJson(res, 500, { ok: false, error: error instanceof Error ? error.message : String(error) });
8404
+ }
8405
+ }
8406
+ }),
8407
+ "dsh-model-think-level: camouflage route"
8408
+ );
8136
8409
  ctx.effect(
8137
8410
  () => webServerCtx.webServer.register({
8138
8411
  kind: "exact",