@liberseek/boft-cli-linux-x64 0.7.6 → 0.7.8

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.
@@ -4616,8 +4616,14 @@ async function resolveInstalledUpdateContext(options2) {
4616
4616
  // packages/update-manager/dist/github-release.js
4617
4617
  var CODEXHOST_LATEST_RELEASE_URL = "https://api.github.com/repos/LiberSeek/BOFT-CLI/releases/latest";
4618
4618
  var SHA256_DIGEST_PATTERN = /^sha256:([0-9a-f]{64})$/u;
4619
- var RELEASE_NOTES_URL_PATTERN = /^https:\/\/github\.com\/LiberSeek\/BOFT-CLI\/releases\/tag\/(v[0-9A-Za-z.+-]+)$/u;
4620
- var DOWNLOAD_URL_PREFIX = "https://github.com/LiberSeek/BOFT-CLI/releases/download/";
4619
+ var RELEASE_NOTES_URL_PATTERN = /^https:\/\/github\.com\/(LiberSeek|LIBERSEEK)\/BOFT-CLI\/releases\/tag\/(v[0-9A-Za-z.+-]+)$/u;
4620
+ var DOWNLOAD_URL_PREFIXES = [
4621
+ "https://github.com/LiberSeek/BOFT-CLI/releases/download/",
4622
+ "https://github.com/LIBERSEEK/BOFT-CLI/releases/download/"
4623
+ ];
4624
+ function isBoftReleaseDownloadUrl(url2, version2) {
4625
+ return DOWNLOAD_URL_PREFIXES.some((prefix) => url2.startsWith(version2 === void 0 ? prefix : `${prefix}v${version2}/`));
4626
+ }
4621
4627
  function record(value2, label) {
4622
4628
  if (typeof value2 !== "object" || value2 === null || Array.isArray(value2)) {
4623
4629
  throw new Error(`${label} must be an object`);
@@ -4626,7 +4632,7 @@ function record(value2, label) {
4626
4632
  }
4627
4633
  function releaseAsset(value2) {
4628
4634
  const asset = record(value2, "GitHub Release asset");
4629
- if (typeof asset.name !== "string" || asset.name.length === 0 || asset.name.length > 160 || !Number.isSafeInteger(asset.size) || asset.size <= 0 || asset.size > 2 * 1024 * 1024 * 1024 || asset.digest != null && typeof asset.digest !== "string" || typeof asset.browser_download_url !== "string" || !asset.browser_download_url.startsWith(DOWNLOAD_URL_PREFIX)) {
4635
+ if (typeof asset.name !== "string" || asset.name.length === 0 || asset.name.length > 160 || !Number.isSafeInteger(asset.size) || asset.size <= 0 || asset.size > 2 * 1024 * 1024 * 1024 || asset.digest != null && typeof asset.digest !== "string" || typeof asset.browser_download_url !== "string" || !isBoftReleaseDownloadUrl(asset.browser_download_url)) {
4630
4636
  throw new Error("GitHub Release asset is invalid");
4631
4637
  }
4632
4638
  const url2 = new URL(asset.browser_download_url);
@@ -4647,7 +4653,7 @@ function parseLatestGitHubRelease(value2) {
4647
4653
  }
4648
4654
  const version2 = requireSemanticVersion(release.tag_name.slice(1));
4649
4655
  const notesMatch = RELEASE_NOTES_URL_PATTERN.exec(release.html_url);
4650
- if (!notesMatch || notesMatch[1] !== release.tag_name) {
4656
+ if (!notesMatch || notesMatch[2] !== release.tag_name) {
4651
4657
  throw new Error("GitHub Release notes URL does not match its tag");
4652
4658
  }
4653
4659
  const releaseNotes = typeof release.body === "string" && release.body.trim().length > 0 ? release.body.slice(0, 2e4) : null;
@@ -4734,8 +4740,7 @@ function selectInstallerReleaseArtifact(release, target) {
4734
4740
  const sha256 = digest2?.[1];
4735
4741
  if (!sha256)
4736
4742
  throw new Error(`GitHub Release asset ${name} has no valid SHA-256 digest`);
4737
- const expectedPrefix = `${DOWNLOAD_URL_PREFIX}v${release.version}/`;
4738
- if (!asset.downloadUrl.startsWith(expectedPrefix) || !asset.downloadUrl.endsWith(`/${name}`)) {
4743
+ if (!isBoftReleaseDownloadUrl(asset.downloadUrl, release.version) || !asset.downloadUrl.endsWith(`/${name}`)) {
4739
4744
  throw new Error(`GitHub Release asset ${name} has an unexpected download URL`);
4740
4745
  }
4741
4746
  return Object.freeze({
@@ -19918,6 +19923,72 @@ var harnessDisplaySetSchema = external_exports.strictObject({
19918
19923
  initializeOnly: external_exports.boolean().optional()
19919
19924
  });
19920
19925
 
19926
+ // packages/shared-contracts/dist/ids.js
19927
+ var opaqueIdSchema = external_exports.string().refine((value2) => value2.trim().length > 0, {
19928
+ message: "Identifier must not be empty or whitespace"
19929
+ });
19930
+ var harnessIdSchema = opaqueIdSchema.brand();
19931
+ var hostThreadIdSchema = opaqueIdSchema.brand();
19932
+ var hostTurnIdSchema = opaqueIdSchema.brand();
19933
+ var hostItemIdSchema = opaqueIdSchema.brand();
19934
+ var hostInteractionIdSchema = opaqueIdSchema.brand();
19935
+
19936
+ // packages/shared-contracts/dist/harness-plugins.js
19937
+ var HARNESS_PLUGIN_API_VERSION = 1;
19938
+ var HARNESS_PLUGIN_MANIFEST_MAX_BYTES = 32 * 1024;
19939
+ var HARNESS_PLUGIN_ICON_MAX_BYTES = 128 * 1024;
19940
+ var HARNESS_PLUGIN_LIMIT = 128;
19941
+ var harnessPluginIdSchema = external_exports.string().min(1).max(128).regex(/^[a-z][a-z0-9]*(?:[._-][a-z0-9]+)*$/u).refine((id2) => id2 !== "codex", "The official Codex identity is reserved").pipe(harnessIdSchema);
19942
+ var relativeResourceSchema = external_exports.string().min(1).max(512).refine((value2) => !/[\\\u0000:#?]/u.test(value2) && !value2.startsWith("/") && !value2.split("/").some((part) => part === ".." || part === ""), "Plugin resources must be relative paths inside the plugin");
19943
+ var documentationUrlSchema = external_exports.url().refine((value2) => /^https:\/\/[^/?#@]+(?:[/?#]|$)/iu.test(value2), "Plugin documentation links must be credential-free HTTPS URLs");
19944
+ var pluginPresentationShape = {
19945
+ id: harnessPluginIdSchema,
19946
+ name: external_exports.string().trim().min(1).max(128),
19947
+ version: external_exports.string().min(1).max(128),
19948
+ /** The factory accepts a persisted local entrypoint through its construction context. */
19949
+ launchCommand: external_exports.literal(true).optional(),
19950
+ links: external_exports.object({
19951
+ documentation: documentationUrlSchema.optional(),
19952
+ installation: documentationUrlSchema.optional()
19953
+ }).strict().optional()
19954
+ };
19955
+ var harnessPluginManifestSchema = external_exports.object({
19956
+ manifestVersion: external_exports.literal(1),
19957
+ ...pluginPresentationShape,
19958
+ adapterApiVersion: external_exports.number().int().positive(),
19959
+ entry: relativeResourceSchema,
19960
+ icon: relativeResourceSchema.optional()
19961
+ }).strict();
19962
+ var harnessPluginIconSchema = external_exports.string().max(Math.ceil(HARNESS_PLUGIN_ICON_MAX_BYTES / 3) * 4 + 64).regex(/^data:image\/(?:png|jpeg|webp|svg\+xml);base64,[A-Za-z0-9+/]+={0,2}$/u);
19963
+ var harnessPluginDescriptorSchema = external_exports.object({
19964
+ ...pluginPresentationShape,
19965
+ icon: harnessPluginIconSchema.optional()
19966
+ }).strict();
19967
+ var harnessPluginListParamsSchema = external_exports.object({}).strict();
19968
+ var harnessPluginListResultSchema = external_exports.object({
19969
+ plugins: external_exports.array(harnessPluginDescriptorSchema).max(HARNESS_PLUGIN_LIMIT)
19970
+ }).strict();
19971
+ var harnessPluginConfigurationSchema = external_exports.object({
19972
+ version: external_exports.literal(1),
19973
+ enabled: external_exports.array(harnessPluginIdSchema).max(HARNESS_PLUGIN_LIMIT)
19974
+ }).strict().refine((value2) => new Set(value2.enabled).size === value2.enabled.length, {
19975
+ message: "Enabled plugin IDs must be unique",
19976
+ path: ["enabled"]
19977
+ });
19978
+
19979
+ // packages/shared-contracts/dist/harness-long-context.js
19980
+ var HARNESS_LONG_CONTEXT_GET_METHOD = "codexhost/harness/long-context/get";
19981
+ var HARNESS_LONG_CONTEXT_SET_METHOD = "codexhost/harness/long-context/set";
19982
+ var harnessLongContextGetSchema = external_exports.object({
19983
+ harnessId: harnessPluginIdSchema
19984
+ }).strict();
19985
+ var harnessLongContextSetSchema = harnessLongContextGetSchema.extend({
19986
+ enabled: external_exports.boolean()
19987
+ });
19988
+ var harnessLongContextSchema = external_exports.object({
19989
+ enabled: external_exports.boolean()
19990
+ }).strict();
19991
+
19921
19992
  // packages/shared-contracts/dist/console.js
19922
19993
  var consoleAnnouncementSchema = external_exports.strictObject({
19923
19994
  title: external_exports.string().trim().min(1).max(200),
@@ -19935,8 +20006,11 @@ var CONSOLE_HOST_METHODS = Object.freeze([
19935
20006
  "codexhost/harness/display-settings/get",
19936
20007
  "codexhost/harness/display-settings/set",
19937
20008
  "codexhost/harness/inspect",
20009
+ "codexhost/harness/installation",
19938
20010
  "codexhost/harness/launch-settings/get",
19939
20011
  "codexhost/harness/launch-settings/set",
20012
+ HARNESS_LONG_CONTEXT_GET_METHOD,
20013
+ HARNESS_LONG_CONTEXT_SET_METHOD,
19940
20014
  "codexhost/harness/web-ui/open",
19941
20015
  "codexhost/harness/accounts/sources",
19942
20016
  "codexhost/harness/accounts/list",
@@ -20001,16 +20075,6 @@ var loadedSessionsSchema = external_exports.array(external_exports.strictObject(
20001
20075
  inactiveMs: external_exports.number().nonnegative()
20002
20076
  }));
20003
20077
 
20004
- // packages/shared-contracts/dist/ids.js
20005
- var opaqueIdSchema = external_exports.string().refine((value2) => value2.trim().length > 0, {
20006
- message: "Identifier must not be empty or whitespace"
20007
- });
20008
- var harnessIdSchema = opaqueIdSchema.brand();
20009
- var hostThreadIdSchema = opaqueIdSchema.brand();
20010
- var hostTurnIdSchema = opaqueIdSchema.brand();
20011
- var hostItemIdSchema = opaqueIdSchema.brand();
20012
- var hostInteractionIdSchema = opaqueIdSchema.brand();
20013
-
20014
20078
  // packages/shared-contracts/dist/manual-compaction.js
20015
20079
  var THREAD_MANUAL_COMPACTION_STARTED_METHOD = "codexhost/thread/manual-compaction/started";
20016
20080
  var threadManualCompactionStartedSchema = external_exports.strictObject({
@@ -20550,49 +20614,6 @@ var threadOwnershipListResultSchema = external_exports.object({
20550
20614
  }
20551
20615
  });
20552
20616
 
20553
- // packages/shared-contracts/dist/harness-plugins.js
20554
- var HARNESS_PLUGIN_API_VERSION = 1;
20555
- var HARNESS_PLUGIN_MANIFEST_MAX_BYTES = 32 * 1024;
20556
- var HARNESS_PLUGIN_ICON_MAX_BYTES = 128 * 1024;
20557
- var HARNESS_PLUGIN_LIMIT = 128;
20558
- var harnessPluginIdSchema = external_exports.string().min(1).max(128).regex(/^[a-z][a-z0-9]*(?:[._-][a-z0-9]+)*$/u).refine((id2) => id2 !== "codex", "The official Codex identity is reserved").pipe(harnessIdSchema);
20559
- var relativeResourceSchema = external_exports.string().min(1).max(512).refine((value2) => !/[\\\u0000:#?]/u.test(value2) && !value2.startsWith("/") && !value2.split("/").some((part) => part === ".." || part === ""), "Plugin resources must be relative paths inside the plugin");
20560
- var documentationUrlSchema = external_exports.url().refine((value2) => /^https:\/\/[^/?#@]+(?:[/?#]|$)/iu.test(value2), "Plugin documentation links must be credential-free HTTPS URLs");
20561
- var pluginPresentationShape = {
20562
- id: harnessPluginIdSchema,
20563
- name: external_exports.string().trim().min(1).max(128),
20564
- version: external_exports.string().min(1).max(128),
20565
- /** The factory accepts a persisted local entrypoint through its construction context. */
20566
- launchCommand: external_exports.literal(true).optional(),
20567
- links: external_exports.object({
20568
- documentation: documentationUrlSchema.optional(),
20569
- installation: documentationUrlSchema.optional()
20570
- }).strict().optional()
20571
- };
20572
- var harnessPluginManifestSchema = external_exports.object({
20573
- manifestVersion: external_exports.literal(1),
20574
- ...pluginPresentationShape,
20575
- adapterApiVersion: external_exports.number().int().positive(),
20576
- entry: relativeResourceSchema,
20577
- icon: relativeResourceSchema.optional()
20578
- }).strict();
20579
- var harnessPluginIconSchema = external_exports.string().max(Math.ceil(HARNESS_PLUGIN_ICON_MAX_BYTES / 3) * 4 + 64).regex(/^data:image\/(?:png|jpeg|webp|svg\+xml);base64,[A-Za-z0-9+/]+={0,2}$/u);
20580
- var harnessPluginDescriptorSchema = external_exports.object({
20581
- ...pluginPresentationShape,
20582
- icon: harnessPluginIconSchema.optional()
20583
- }).strict();
20584
- var harnessPluginListParamsSchema = external_exports.object({}).strict();
20585
- var harnessPluginListResultSchema = external_exports.object({
20586
- plugins: external_exports.array(harnessPluginDescriptorSchema).max(HARNESS_PLUGIN_LIMIT)
20587
- }).strict();
20588
- var harnessPluginConfigurationSchema = external_exports.object({
20589
- version: external_exports.literal(1),
20590
- enabled: external_exports.array(harnessPluginIdSchema).max(HARNESS_PLUGIN_LIMIT)
20591
- }).strict().refine((value2) => new Set(value2.enabled).size === value2.enabled.length, {
20592
- message: "Enabled plugin IDs must be unique",
20593
- path: ["enabled"]
20594
- });
20595
-
20596
20617
  // packages/shared-contracts/dist/harness-route.js
20597
20618
  var HARNESS_PLUGIN_ROUTE_PREFIX = "codexhost/plugin-v1@";
20598
20619
  var MAX_ROUTE_LENGTH = 4096;
@@ -20644,14 +20665,17 @@ var harnessLaunchSettingsSchema = external_exports.object({
20644
20665
  var HARNESS_INSTALLATION_METHOD = "codexhost/harness/installation";
20645
20666
  var harnessInstallationParamsSchema = external_exports.object({
20646
20667
  harnessId: harnessIdSchema,
20647
- action: external_exports.enum(["check", "update"])
20668
+ action: external_exports.enum(["check", "update", "install"])
20648
20669
  }).strict();
20649
20670
  var harnessInstallationStateSchema = external_exports.object({
20650
20671
  currentVersion: external_exports.string().min(1).max(128),
20651
20672
  latestVersion: external_exports.string().min(1).max(128),
20652
20673
  updateAvailable: external_exports.boolean(),
20653
20674
  canUpdate: external_exports.boolean(),
20654
- message: external_exports.string().max(2048).optional()
20675
+ // Adapter-owned diagnostic text; UI uses messageCode rather than displaying it verbatim.
20676
+ message: external_exports.string().max(2048).optional(),
20677
+ messageCode: external_exports.string().min(1).max(128).optional(),
20678
+ latestVersionKind: external_exports.enum(["unknown", "tracking-branch"]).optional()
20655
20679
  }).strict();
20656
20680
 
20657
20681
  // packages/shared-contracts/dist/codex-accounts.js
@@ -20951,7 +20975,7 @@ var updateStatusSchema = external_exports.strictObject({
20951
20975
  }
20952
20976
  });
20953
20977
  var updateEmptyParamsSchema = external_exports.strictObject({});
20954
- var githubReleaseNotesUrlSchema = external_exports.string().max(300).regex(/^https:\/\/github\.com\/LiberSeek\/BOFT-CLI\/releases\/tag\/v[0-9A-Za-z.+-]+$/u, "release notes URL must identify a codexhost GitHub Release");
20978
+ var githubReleaseNotesUrlSchema = external_exports.string().max(300).regex(/^https:\/\/github\.com\/(LiberSeek|LIBERSEEK)\/BOFT-CLI\/releases\/tag\/v[0-9A-Za-z.+-]+$/u, "release notes URL must identify a codexhost GitHub Release");
20955
20979
  var updateCheckResultSchema = external_exports.strictObject({
20956
20980
  currentVersion: updateSemanticVersionSchema,
20957
20981
  installation: updateInstallationSchema.nullable(),
@@ -21207,6 +21231,7 @@ var HarnessInstallationError = class extends Error {
21207
21231
  }
21208
21232
  code;
21209
21233
  };
21234
+ var installing = /* @__PURE__ */ new WeakMap();
21210
21235
  async function handleHarnessInstallation(params, adapters) {
21211
21236
  const parsed = harnessInstallationParamsSchema.safeParse(params);
21212
21237
  if (!parsed.success)
@@ -21217,16 +21242,74 @@ async function handleHarnessInstallation(params, adapters) {
21217
21242
  -32078,
21218
21243
  "Harness version management is unavailable on this Host"
21219
21244
  );
21245
+ const install = adapter.install?.bind(adapter);
21246
+ const installation = adapter.installation.bind(adapter);
21247
+ if (parsed.data.action === "install" && !install)
21248
+ throw new HarnessInstallationError(
21249
+ -32078,
21250
+ "Automatic installation is unavailable on this Host. Use the official installation guide."
21251
+ );
21220
21252
  try {
21253
+ const pending = installing.get(adapter);
21254
+ if (pending) return await pending;
21255
+ if (parsed.data.action === "install") {
21256
+ const operation = (async () => {
21257
+ const inspection = await adapter.inspect({ refresh: true });
21258
+ if (inspection.status !== "notInstalled")
21259
+ throw new Error("Harness is already installed or its state is uncertain");
21260
+ if (!install) throw new Error("Installation capability unavailable");
21261
+ await install();
21262
+ return harnessInstallationStateSchema.parse(await installation("check"));
21263
+ })();
21264
+ installing.set(adapter, operation);
21265
+ try {
21266
+ return await operation;
21267
+ } finally {
21268
+ installing.delete(adapter);
21269
+ }
21270
+ }
21221
21271
  return harnessInstallationStateSchema.parse(await adapter.installation(parsed.data.action));
21222
21272
  } catch {
21223
21273
  throw new HarnessInstallationError(
21224
21274
  -32077,
21225
- parsed.data.action === "update" ? "Harness update failed or its new version could not be confirmed. Check the native installation and check for updates again." : "Could not check Harness versions. Check the native installation and retry."
21275
+ parsed.data.action === "install" ? "Harness installation failed or its CLI version could not be confirmed. Check network access, prerequisites and installation permissions in the official guide, then diagnose the connection before retrying." : parsed.data.action === "update" ? "Harness update failed or its new version could not be confirmed. Check the native installation and check for updates again." : "Could not check Harness versions. Check the native installation and retry."
21226
21276
  );
21227
21277
  }
21228
21278
  }
21229
21279
 
21280
+ // packages/host-runtime/src/harness-long-context.ts
21281
+ var HarnessLongContextError = class extends Error {
21282
+ constructor(code, message) {
21283
+ super(message);
21284
+ this.code = code;
21285
+ this.name = "HarnessLongContextError";
21286
+ }
21287
+ code;
21288
+ };
21289
+ async function handleHarnessLongContext(method, params, adapters) {
21290
+ try {
21291
+ if (method === HARNESS_LONG_CONTEXT_SET_METHOD) {
21292
+ const parsed2 = harnessLongContextSetSchema.safeParse(params);
21293
+ if (!parsed2.success) throw new HarnessLongContextError(-32602, "Invalid 1M context request");
21294
+ const adapter2 = adapters.get(parsed2.data.harnessId);
21295
+ if (!adapter2?.setLongContext) {
21296
+ throw new HarnessLongContextError(-32078, "1M context is unavailable for this Harness");
21297
+ }
21298
+ return harnessLongContextSchema.parse(await adapter2.setLongContext(parsed2.data.enabled));
21299
+ }
21300
+ const parsed = harnessLongContextGetSchema.safeParse(params);
21301
+ if (!parsed.success) throw new HarnessLongContextError(-32602, "Invalid 1M context request");
21302
+ const adapter = adapters.get(parsed.data.harnessId);
21303
+ if (!adapter?.getLongContext) {
21304
+ throw new HarnessLongContextError(-32078, "1M context is unavailable for this Harness");
21305
+ }
21306
+ return harnessLongContextSchema.parse(await adapter.getLongContext());
21307
+ } catch (error51) {
21308
+ if (error51 instanceof HarnessLongContextError) throw error51;
21309
+ throw new HarnessLongContextError(-32077, "Could not read or save the 1M context setting");
21310
+ }
21311
+ }
21312
+
21230
21313
  // packages/host-runtime/src/account/codex-credential-export.ts
21231
21314
  import { createHash as createHash2 } from "node:crypto";
21232
21315
  import { readFile as readFile5 } from "node:fs/promises";
@@ -21856,7 +21939,12 @@ var storedTurnMappingV1Schema = external_exports.object({
21856
21939
  nativeTurnRef: nativeTurnRefSchema,
21857
21940
  nativeCheckpointRef: nativeCheckpointRefSchema.optional()
21858
21941
  }).strict();
21859
- var storedThreadRecordV1Schema = external_exports.object({
21942
+ var storedGitInfoV1Schema = external_exports.object({
21943
+ branch: nonBlankTextSchema6.max(4096).optional(),
21944
+ originUrl: nonBlankTextSchema6.max(16384).optional(),
21945
+ sha: nonBlankTextSchema6.max(1024).optional()
21946
+ }).strict();
21947
+ var storedThreadCoreV1Shape = {
21860
21948
  formatVersion: external_exports.literal(1),
21861
21949
  revision: external_exports.number().int().positive(),
21862
21950
  hostThreadId: storedHostThreadIdSchema,
@@ -21884,7 +21972,19 @@ var storedThreadRecordV1Schema = external_exports.object({
21884
21972
  turnMappings: external_exports.array(storedTurnMappingV1Schema),
21885
21973
  createdAt: isoDateSchema,
21886
21974
  updatedAt: isoDateSchema
21887
- }).strict().superRefine((record4, context) => {
21975
+ };
21976
+ var storedThreadMetadataFieldsShape = {
21977
+ projectId: nonBlankTextSchema6.max(1024).optional(),
21978
+ daybreakEnabled: external_exports.boolean().optional(),
21979
+ gitInfo: storedGitInfoV1Schema.optional()
21980
+ };
21981
+ var THREAD_METADATA_FIELDS = ["projectId", "daybreakEnabled", "gitInfo"];
21982
+ var storedThreadMetadataV1Schema = external_exports.object({
21983
+ formatVersion: external_exports.literal(1),
21984
+ hostThreadId: storedHostThreadIdSchema,
21985
+ ...storedThreadMetadataFieldsShape
21986
+ }).strict();
21987
+ function refineThreadRecord(record4, context) {
21888
21988
  if (record4.state === "ready" && !record4.nativeSessionRef) {
21889
21989
  context.addIssue({
21890
21990
  code: "custom",
@@ -21941,7 +22041,9 @@ var storedThreadRecordV1Schema = external_exports.object({
21941
22041
  }
21942
22042
  }
21943
22043
  }
21944
- });
22044
+ }
22045
+ var storedThreadCoreV1Schema = external_exports.object(storedThreadCoreV1Shape).strict().superRefine(refineThreadRecord);
22046
+ var storedThreadRecordV1Schema = external_exports.object({ ...storedThreadCoreV1Shape, ...storedThreadMetadataFieldsShape }).strict().superRefine(refineThreadRecord);
21945
22047
  var delegationStatusSchema = external_exports.enum([
21946
22048
  "creating",
21947
22049
  "running",
@@ -22060,6 +22162,83 @@ function nativeTurnKey(mapping) {
22060
22162
  function sameJson(left, right) {
22061
22163
  return JSON.stringify(left) === JSON.stringify(right);
22062
22164
  }
22165
+ function withoutUrlCredentials(value2) {
22166
+ let url2;
22167
+ try {
22168
+ url2 = new URL(value2);
22169
+ } catch {
22170
+ return withoutUnparsedUrlCredentials(value2);
22171
+ }
22172
+ if (!url2.host)
22173
+ return withoutUnparsedUrlCredentials(value2);
22174
+ const keepUser = url2.protocol === "ssh:" || url2.protocol === "git+ssh:";
22175
+ if (!url2.password && (keepUser || !url2.username))
22176
+ return value2;
22177
+ url2.password = "";
22178
+ if (!keepUser)
22179
+ url2.username = "";
22180
+ return url2.toString();
22181
+ }
22182
+ function withoutUnparsedUrlCredentials(value2) {
22183
+ const scheme = /^([a-z][a-z0-9+.-]*):\/\//i.exec(value2);
22184
+ const authorityStart = scheme ? scheme[0].length : 0;
22185
+ const authorityEnd = value2.slice(authorityStart).search(scheme ? /[/?#]/ : /\//);
22186
+ const authority = authorityEnd === -1 ? value2.slice(authorityStart) : value2.slice(authorityStart, authorityStart + authorityEnd);
22187
+ const at = scheme ? authority.lastIndexOf("@") : authority.indexOf("@");
22188
+ if (at === -1)
22189
+ return value2;
22190
+ const userInfo = authority.slice(0, at);
22191
+ const protocol = scheme?.[1]?.toLowerCase();
22192
+ const keepUser = scheme ? protocol === "ssh" || protocol === "git+ssh" : true;
22193
+ const kept = keepUser && !userInfo.includes(":") ? `${userInfo}@` : "";
22194
+ return value2.slice(0, authorityStart) + kept + value2.slice(authorityStart + at + 1);
22195
+ }
22196
+ function threadMetadataOf(record4) {
22197
+ const fields = Object.fromEntries(THREAD_METADATA_FIELDS.filter((name) => record4[name] !== void 0).map((name) => [
22198
+ name,
22199
+ record4[name]
22200
+ ]));
22201
+ if (Object.keys(fields).length === 0)
22202
+ return null;
22203
+ return { formatVersion: 1, hostThreadId: record4.hostThreadId, ...fields };
22204
+ }
22205
+ function withoutThreadMetadata(record4) {
22206
+ const { projectId, daybreakEnabled, gitInfo, ...core } = record4;
22207
+ void [projectId, daybreakEnabled, gitInfo];
22208
+ return core;
22209
+ }
22210
+ function withThreadMetadata(record4, metadata) {
22211
+ const core = withoutThreadMetadata(record4);
22212
+ for (const name of THREAD_METADATA_FIELDS) {
22213
+ if (metadata[name] !== void 0)
22214
+ Object.assign(core, { [name]: metadata[name] });
22215
+ }
22216
+ return core;
22217
+ }
22218
+ function applyThreadMetadataPatch(current, patch) {
22219
+ const next = { ...current };
22220
+ if (patch.projectId !== void 0) {
22221
+ if (patch.projectId === null)
22222
+ delete next.projectId;
22223
+ else
22224
+ next.projectId = patch.projectId;
22225
+ }
22226
+ if (patch.daybreakEnabled !== void 0)
22227
+ next.daybreakEnabled = patch.daybreakEnabled;
22228
+ if (patch.gitInfo !== void 0) {
22229
+ const gitInfo = {};
22230
+ for (const name of ["branch", "originUrl", "sha"]) {
22231
+ const value2 = patch.gitInfo[name] === void 0 ? current.gitInfo?.[name] : patch.gitInfo[name];
22232
+ if (value2)
22233
+ gitInfo[name] = name === "originUrl" ? withoutUrlCredentials(value2) : value2;
22234
+ }
22235
+ if (Object.keys(gitInfo).length === 0)
22236
+ delete next.gitInfo;
22237
+ else
22238
+ next.gitInfo = gitInfo;
22239
+ }
22240
+ return next;
22241
+ }
22063
22242
  function systemErrorCode2(error51) {
22064
22243
  return typeof error51 === "object" && error51 !== null && "code" in error51 ? String(error51.code) : null;
22065
22244
  }
@@ -22159,6 +22338,7 @@ var MappingStore = class {
22159
22338
  #directory;
22160
22339
  #instanceId;
22161
22340
  #lockPath;
22341
+ #metadataDirectory;
22162
22342
  #now;
22163
22343
  #quarantineDirectory;
22164
22344
  #sectionsDirectory;
@@ -22183,6 +22363,7 @@ var MappingStore = class {
22183
22363
  this.#backupsDirectory = path11.join(this.#directory, "backups");
22184
22364
  this.#quarantineDirectory = path11.join(this.#directory, "quarantine");
22185
22365
  this.#sectionsDirectory = path11.join(this.#directory, "sections");
22366
+ this.#metadataDirectory = path11.join(this.#directory, "thread-metadata");
22186
22367
  this.#lockPath = path11.join(this.#directory, "store.lock");
22187
22368
  this.#instanceId = options2.instanceId ?? randomUUID6();
22188
22369
  this.#now = options2.now ?? (() => /* @__PURE__ */ new Date());
@@ -22196,7 +22377,8 @@ var MappingStore = class {
22196
22377
  mkdir6(this.#delegationsDirectory, { recursive: true }),
22197
22378
  mkdir6(this.#backupsDirectory, { recursive: true }),
22198
22379
  mkdir6(this.#quarantineDirectory, { recursive: true }),
22199
- mkdir6(this.#sectionsDirectory, { recursive: true })
22380
+ mkdir6(this.#sectionsDirectory, { recursive: true }),
22381
+ mkdir6(this.#metadataDirectory, { recursive: true })
22200
22382
  ]);
22201
22383
  await this.#acquireLock();
22202
22384
  try {
@@ -22223,10 +22405,19 @@ var MappingStore = class {
22223
22405
  if (record4.state === "creating" && !record4.nativeSessionRef) {
22224
22406
  await rm7(primary, { force: true });
22225
22407
  await rm7(backup, { force: true });
22408
+ await rm7(this.#metadataPath(record4.hostThreadId), { force: true });
22226
22409
  continue;
22227
22410
  }
22411
+ const metadata = await this.#readMetadata(record4.hostThreadId);
22412
+ if (metadata) {
22413
+ record4 = withThreadMetadata(record4, metadata);
22414
+ } else if (threadMetadataOf(record4)) {
22415
+ await this.#writeMetadataFile(record4.hostThreadId, threadMetadataOf(record4));
22416
+ await this.#replaceFile(primary, record4, false);
22417
+ }
22228
22418
  this.#records.set(record4.hostThreadId, record4);
22229
22419
  }
22420
+ await Promise.all((await readdir3(this.#metadataDirectory)).filter((name) => name.endsWith(".json") && !this.#records.has(name.slice(0, -5))).map((name) => rm7(path11.join(this.#metadataDirectory, name), { force: true })));
22230
22421
  const delegationNames = (await readdir3(this.#delegationsDirectory)).filter((name) => name.endsWith(".json"));
22231
22422
  for (const name of delegationNames) {
22232
22423
  const file2 = path11.join(this.#delegationsDirectory, name);
@@ -22504,6 +22695,19 @@ var MappingStore = class {
22504
22695
  async setPinned(hostThreadId, isPinned) {
22505
22696
  return this.#update(hostThreadId, (current) => current.isPinned === isPinned ? null : { ...current, isPinned });
22506
22697
  }
22698
+ /**
22699
+ * Patch Desktop metadata. With `ifProjectId`, the patch applies only while the
22700
+ * stored assignment still equals it; otherwise the current record is returned.
22701
+ */
22702
+ async updateMetadata(hostThreadId, patch, options2 = {}) {
22703
+ return this.#update(hostThreadId, (current) => {
22704
+ if (options2.ifProjectId !== void 0 && current.projectId !== options2.ifProjectId) {
22705
+ return null;
22706
+ }
22707
+ const next = applyThreadMetadataPatch(current, patch);
22708
+ return sameJson(next, current) ? null : next;
22709
+ });
22710
+ }
22507
22711
  /** Section placements of stored External Threads, in insertion order. */
22508
22712
  async listSectionPlacements() {
22509
22713
  this.#requireInitialized();
@@ -22558,7 +22762,8 @@ var MappingStore = class {
22558
22762
  return;
22559
22763
  await Promise.all([
22560
22764
  rm7(this.#recordPath(hostThreadId), { force: true }),
22561
- rm7(this.#backupPath(hostThreadId), { force: true })
22765
+ rm7(this.#backupPath(hostThreadId), { force: true }),
22766
+ rm7(this.#metadataPath(hostThreadId), { force: true })
22562
22767
  ]);
22563
22768
  this.#records.delete(hostThreadId);
22564
22769
  this.#rebuildIndexes();
@@ -22596,6 +22801,15 @@ var MappingStore = class {
22596
22801
  });
22597
22802
  this.#validateGlobal(next, hostThreadId);
22598
22803
  await this.#replaceFile(this.#recordPath(hostThreadId), next, true);
22804
+ const metadata = threadMetadataOf(next);
22805
+ if (!sameJson(threadMetadataOf(current), metadata)) {
22806
+ try {
22807
+ await this.#writeMetadataFile(hostThreadId, metadata);
22808
+ } catch (error51) {
22809
+ await this.#replaceFile(this.#recordPath(hostThreadId), current, false).catch(() => void 0);
22810
+ throw error51;
22811
+ }
22812
+ }
22599
22813
  this.#records.set(hostThreadId, next);
22600
22814
  this.#rebuildIndexes();
22601
22815
  result = cloneRecord(next);
@@ -22645,7 +22859,7 @@ var MappingStore = class {
22645
22859
  try {
22646
22860
  await this.#beforeReplace?.(cloneRecord(record4));
22647
22861
  handle = await open6(temp, "wx", constants2.S_IRUSR | constants2.S_IWUSR);
22648
- await handle.writeFile(`${JSON.stringify(record4, null, 2)}
22862
+ await handle.writeFile(`${JSON.stringify(withoutThreadMetadata(record4), null, 2)}
22649
22863
  `, "utf8");
22650
22864
  await handle.sync();
22651
22865
  await handle.close();
@@ -22664,6 +22878,52 @@ var MappingStore = class {
22664
22878
  });
22665
22879
  }
22666
22880
  }
22881
+ /** Atomically writes, or with null removes, a Thread's Desktop metadata file. */
22882
+ async #writeMetadataFile(hostThreadId, metadata) {
22883
+ const target = this.#metadataPath(hostThreadId);
22884
+ const temp = `${target}.tmp-${randomUUID6()}`;
22885
+ let handle = null;
22886
+ try {
22887
+ if (!metadata) {
22888
+ await rm7(target, { force: true });
22889
+ return;
22890
+ }
22891
+ handle = await open6(temp, "wx", constants2.S_IRUSR | constants2.S_IWUSR);
22892
+ await handle.writeFile(`${JSON.stringify(metadata, null, 2)}
22893
+ `, "utf8");
22894
+ await handle.sync();
22895
+ await handle.close();
22896
+ handle = null;
22897
+ await rename6(temp, target);
22898
+ } catch (error51) {
22899
+ await handle?.close().catch(() => void 0);
22900
+ await rm7(temp, { force: true }).catch(() => void 0);
22901
+ throw new MappingStoreError("IO_ERROR", "Thread metadata atomic replacement failed", {
22902
+ cause: error51
22903
+ });
22904
+ }
22905
+ }
22906
+ /** Reads a Thread's metadata file; an invalid file is quarantined rather than blocking the Thread. */
22907
+ async #readMetadata(hostThreadId) {
22908
+ const file2 = this.#metadataPath(hostThreadId);
22909
+ let text2;
22910
+ try {
22911
+ text2 = await readFile9(file2, "utf8");
22912
+ } catch (error51) {
22913
+ if (systemErrorCode2(error51) === "ENOENT")
22914
+ return null;
22915
+ throw error51;
22916
+ }
22917
+ try {
22918
+ const parsed = storedThreadMetadataV1Schema.parse(JSON.parse(text2));
22919
+ if (parsed.hostThreadId !== hostThreadId)
22920
+ throw new Error("Thread ID mismatch");
22921
+ return parsed;
22922
+ } catch {
22923
+ await rename6(file2, path11.join(this.#quarantineDirectory, `${hostThreadId}.json.${this.#now().getTime()}.invalid-metadata`)).catch(() => void 0);
22924
+ return null;
22925
+ }
22926
+ }
22667
22927
  async #replaceDelegationFile(record4) {
22668
22928
  const target = this.#delegationPath(record4.delegationId);
22669
22929
  const temp = `${target}.tmp-${randomUUID6()}`;
@@ -22699,16 +22959,18 @@ var MappingStore = class {
22699
22959
  return parsed.data;
22700
22960
  }
22701
22961
  async #cleanupResidue() {
22702
- const [threadNames, delegationNames, sectionNames, rootNames] = await Promise.all([
22962
+ const [threadNames, delegationNames, sectionNames, rootNames, metadataNames] = await Promise.all([
22703
22963
  readdir3(this.#threadsDirectory),
22704
22964
  readdir3(this.#delegationsDirectory),
22705
22965
  readdir3(this.#sectionsDirectory),
22706
- readdir3(this.#directory)
22966
+ readdir3(this.#directory),
22967
+ readdir3(this.#metadataDirectory)
22707
22968
  ]);
22708
22969
  await Promise.all([
22709
22970
  ...threadNames.filter((name) => name.includes(".tmp-")).map((name) => rm7(path11.join(this.#threadsDirectory, name), { force: true })),
22710
22971
  ...delegationNames.filter((name) => name.includes(".tmp-")).map((name) => rm7(path11.join(this.#delegationsDirectory, name), { force: true })),
22711
22972
  ...sectionNames.filter((name) => name.includes(".tmp-")).map((name) => rm7(path11.join(this.#sectionsDirectory, name), { force: true })),
22973
+ ...metadataNames.filter((name) => name.includes(".tmp-")).map((name) => rm7(path11.join(this.#metadataDirectory, name), { force: true })),
22712
22974
  // Renamed aside by #acquireLock; nothing reads them back, and they accumulate one per run.
22713
22975
  ...rootNames.filter((name) => name.startsWith(`${path11.basename(this.#lockPath)}.stale-`)).map((name) => rm7(path11.join(this.#directory, name), { force: true }))
22714
22976
  ]);
@@ -22819,6 +23081,9 @@ var MappingStore = class {
22819
23081
  get #sectionPlacementsPath() {
22820
23082
  return path11.join(this.#sectionsDirectory, "placements.json");
22821
23083
  }
23084
+ #metadataPath(hostThreadId) {
23085
+ return path11.join(this.#metadataDirectory, `${hostThreadId}.json`);
23086
+ }
22822
23087
  #backupPath(hostThreadId) {
22823
23088
  return path11.join(this.#backupsDirectory, `${hostThreadId}.json`);
22824
23089
  }
@@ -25339,6 +25604,7 @@ function mapExternalThreadHarnessError(error51, operation) {
25339
25604
  case "notInstalled":
25340
25605
  case "unavailable":
25341
25606
  case "authenticationRequired":
25607
+ case "configurationRequired":
25342
25608
  return { code: -32077, message: "External Harness is unavailable" };
25343
25609
  case "nativeFailure":
25344
25610
  case "protocolError":
@@ -25389,6 +25655,7 @@ var THREAD_LIST_FIELDS = /* @__PURE__ */ new Set([
25389
25655
  "limit",
25390
25656
  "modelProviders",
25391
25657
  "parentThreadId",
25658
+ "projectId",
25392
25659
  "searchTerm",
25393
25660
  "sectionId",
25394
25661
  "sortDirection",
@@ -25545,6 +25812,7 @@ function decodeThreadListRequest(request) {
25545
25812
  if (parentThreadId !== null && ancestorThreadId !== null) {
25546
25813
  throw new Error("thread/list cannot combine parentThreadId and ancestorThreadId");
25547
25814
  }
25815
+ const projectId = params.projectId === void 0 ? void 0 : nullableText(params.projectId, "thread/list params.projectId");
25548
25816
  const searchTerm = nullableText(params.searchTerm, "thread/list params.searchTerm");
25549
25817
  const sectionId = params.sectionId === void 0 ? void 0 : nullableText(params.sectionId, "thread/list params.sectionId");
25550
25818
  const sortKey = decodeSortKey(params.sortKey);
@@ -25563,6 +25831,7 @@ function decodeThreadListRequest(request) {
25563
25831
  isPinned,
25564
25832
  modelProviders,
25565
25833
  parentThreadId,
25834
+ ...projectId === void 0 ? {} : { projectId },
25566
25835
  searchTerm,
25567
25836
  ...sectionId === void 0 ? {} : { sectionId },
25568
25837
  ...sortKey === "section_position" ? { sortDirection: sortDirection2 } : {},
@@ -25595,6 +25864,7 @@ function decodeThreadListRequest(request) {
25595
25864
  modelProviders,
25596
25865
  parentThreadId,
25597
25866
  ancestorThreadId,
25867
+ projectId,
25598
25868
  searchTerm,
25599
25869
  sectionId,
25600
25870
  sortDirection: sortDirection2,
@@ -25651,6 +25921,21 @@ function decodeThreadArchiveRequest(request) {
25651
25921
  }
25652
25922
  return { threadId: params.threadId };
25653
25923
  }
25924
+ var THREAD_METADATA_UPDATE_FIELDS = /* @__PURE__ */ new Set([
25925
+ "threadId",
25926
+ "projectId",
25927
+ "daybreakEnabled",
25928
+ "gitInfo"
25929
+ ]);
25930
+ var GIT_INFO_FIELDS = /* @__PURE__ */ new Set(["branch", "originUrl", "sha"]);
25931
+ function nonBlankTextOrNull(value2, name) {
25932
+ if (value2 === null)
25933
+ return null;
25934
+ if (typeof value2 !== "string" || value2.trim().length === 0) {
25935
+ throw new Error(`${name} must be non-empty text or null`);
25936
+ }
25937
+ return value2;
25938
+ }
25654
25939
  function decodeThreadMetadataUpdateRequest(request) {
25655
25940
  if (request.method !== "thread/metadata/update")
25656
25941
  return null;
@@ -25658,31 +25943,48 @@ function decodeThreadMetadataUpdateRequest(request) {
25658
25943
  if (typeof params.threadId !== "string" || params.threadId.length === 0) {
25659
25944
  throw new Error("thread/metadata/update params.threadId must be non-empty text");
25660
25945
  }
25661
- const isPinned = nullableBoolean(params.isPinned, "thread/metadata/update params.isPinned");
25662
- let gitInfo;
25663
- if (params.gitInfo === null) {
25664
- gitInfo = null;
25665
- } else if (params.gitInfo !== void 0) {
25946
+ const decoded = {
25947
+ threadId: params.threadId,
25948
+ unsupportedFields: Object.keys(params).filter((name) => !THREAD_METADATA_UPDATE_FIELDS.has(name)).sort()
25949
+ };
25950
+ if (params.isPinned !== void 0) {
25951
+ decoded.isPinned = nullableBoolean(params.isPinned, "thread/metadata/update params.isPinned");
25952
+ }
25953
+ const projectId = nullableText(params.projectId, "thread/metadata/update params.projectId");
25954
+ if (projectId !== null) {
25955
+ decoded.projectId = projectId.length === 0 ? null : nonBlankTextOrNull(projectId, "thread/metadata/update params.projectId");
25956
+ }
25957
+ const daybreakEnabled = nullableBoolean(params.daybreakEnabled, "thread/metadata/update params.daybreakEnabled");
25958
+ if (daybreakEnabled !== null)
25959
+ decoded.daybreakEnabled = daybreakEnabled;
25960
+ if (params.gitInfo !== void 0 && params.gitInfo !== null) {
25666
25961
  if (!isRecord8(params.gitInfo)) {
25667
25962
  throw new Error("thread/metadata/update params.gitInfo must be an object or null");
25668
25963
  }
25669
- gitInfo = {};
25964
+ const gitInfo = {};
25670
25965
  for (const name of ["branch", "originUrl", "sha"]) {
25671
25966
  const value2 = params.gitInfo[name];
25672
- if (value2 !== void 0 && value2 !== null && typeof value2 !== "string") {
25673
- throw new Error(`thread/metadata/update params.gitInfo.${name} must be text or null`);
25967
+ if (value2 !== void 0) {
25968
+ gitInfo[name] = nonBlankTextOrNull(value2, `thread/metadata/update params.gitInfo.${name}`);
25674
25969
  }
25675
- if (value2 !== void 0)
25676
- gitInfo[name] = value2;
25677
25970
  }
25971
+ decoded.gitInfo = gitInfo;
25972
+ for (const name of Object.keys(params.gitInfo)) {
25973
+ if (!GIT_INFO_FIELDS.has(name))
25974
+ decoded.unsupportedFields.push(`gitInfo.${name}`);
25975
+ }
25976
+ decoded.unsupportedFields.sort();
25678
25977
  }
25679
- const decoded = { threadId: params.threadId };
25680
- if (params.isPinned !== void 0)
25681
- decoded.isPinned = isPinned;
25682
- if (params.gitInfo !== void 0)
25683
- decoded.gitInfo = gitInfo ?? null;
25684
25978
  return decoded;
25685
25979
  }
25980
+ function observeDeletedProject(value2) {
25981
+ if (!isRecord8(value2) || value2.method !== "project/changed" || "id" in value2)
25982
+ return null;
25983
+ const params = value2.params;
25984
+ if (!isRecord8(params) || params.changeType !== "deleted")
25985
+ return null;
25986
+ return typeof params.projectId === "string" && params.projectId.length > 0 ? params.projectId : null;
25987
+ }
25686
25988
  function optionalCursor(value2, name) {
25687
25989
  if (value2 === void 0 || value2 === null)
25688
25990
  return null;
@@ -26815,6 +27117,9 @@ var ExternalThreadRepository = class {
26815
27117
  setPinned(hostThreadId, isPinned) {
26816
27118
  return this.store.setPinned(hostThreadId, isPinned);
26817
27119
  }
27120
+ updateMetadata(hostThreadId, patch, options2) {
27121
+ return this.store.updateMetadata(hostThreadId, patch, options2);
27122
+ }
26818
27123
  removeProvisional(hostThreadId) {
26819
27124
  return this.store.removeProvisional(hostThreadId);
26820
27125
  }
@@ -27057,13 +27362,19 @@ function externalThreadValue(input) {
27057
27362
  turns: input.turns,
27058
27363
  preview: previewText,
27059
27364
  name: record4.title || null,
27060
- gitInfo: null,
27365
+ gitInfo: record4.gitInfo ? {
27366
+ branch: record4.gitInfo.branch ?? null,
27367
+ originUrl: record4.gitInfo.originUrl ?? null,
27368
+ sha: record4.gitInfo.sha ?? null
27369
+ } : null,
27061
27370
  forkedFromId: record4.forkSource?.hostThreadId ?? null,
27062
27371
  parentThreadId: record4.subagent?.parentHostThreadId ?? null,
27063
27372
  ephemeral: record4.ephemeral,
27064
27373
  canAcceptDirectInput: record4.subagent ? false : input.loaded === false ? null : true,
27065
27374
  historyMode: record4.historyMode,
27066
27375
  isPinned: record4.isPinned,
27376
+ projectId: record4.projectId ?? null,
27377
+ daybreakEnabled: record4.daybreakEnabled ?? null,
27067
27378
  ...threadSectionFields(input.placement),
27068
27379
  agentNickname: record4.subagent ? record4.title || null : null,
27069
27380
  agentRole: record4.subagent?.role ?? null,
@@ -31318,6 +31629,7 @@ function includesExternalRecord(record4, query, byId, sectionId) {
31318
31629
  return false;
31319
31630
  }
31320
31631
  if (record4.archived !== query.archived) return false;
31632
+ if (query.projectId !== void 0 && (record4.projectId ?? null) !== query.projectId) return false;
31321
31633
  if (query.cwd !== null && !query.cwd.includes(record4.cwd)) return false;
31322
31634
  if (query.modelProviders !== null && query.modelProviders.length > 0 && !query.modelProviders.includes("codexhost")) {
31323
31635
  return false;
@@ -32635,6 +32947,28 @@ var AppServerHost = class {
32635
32947
  });
32636
32948
  return;
32637
32949
  }
32950
+ if (request.method === HARNESS_LONG_CONTEXT_GET_METHOD || request.method === HARNESS_LONG_CONTEXT_SET_METHOD) {
32951
+ this.#dispatchDesktopRequest(async () => {
32952
+ await this.#waitForPlugins();
32953
+ try {
32954
+ const result = await handleHarnessLongContext(
32955
+ request.method,
32956
+ request.params,
32957
+ this.#externalAdapters
32958
+ );
32959
+ await this.#writer.json(rpcEnvelope(request, { result: jsonValueSchema.parse(result) }));
32960
+ } catch (error51) {
32961
+ await this.#writer.json(
32962
+ rpcError(
32963
+ request,
32964
+ error51 instanceof HarnessLongContextError ? error51.code : -32077,
32965
+ error51 instanceof HarnessLongContextError ? error51.message : "Could not read or save the 1M context setting"
32966
+ )
32967
+ );
32968
+ }
32969
+ });
32970
+ return;
32971
+ }
32638
32972
  if (request.method === "codexhost/harness/web-ui/open") {
32639
32973
  this.#dispatchDesktopRequest(() => this.#openHarnessWebUi(request));
32640
32974
  return;
@@ -32797,31 +33131,29 @@ var AppServerHost = class {
32797
33131
  return;
32798
33132
  }
32799
33133
  if (request.method === "thread/metadata/update") {
32800
- let threadId2;
32801
- let decoded;
33134
+ let update;
32802
33135
  try {
32803
- const parsed = decodeThreadMetadataUpdateRequest(request);
32804
- if (!parsed) throw new Error("Expected thread/metadata/update request");
32805
- decoded = parsed;
32806
- threadId2 = decoded.threadId;
33136
+ const decoded = decodeThreadMetadataUpdateRequest(request);
33137
+ if (!decoded) throw new Error("Expected thread/metadata/update request");
33138
+ update = decoded;
32807
33139
  } catch (error51) {
32808
33140
  await this.#writer.json(rpcError(request, -32602, errorMessage3(error51)));
32809
33141
  return;
32810
33142
  }
32811
- const location = await this.#locateExternalThread(threadId2);
33143
+ const location = await this.#locateExternalThread(update.threadId);
32812
33144
  if (await this.#writeResolutionError(request, location)) return;
32813
33145
  if (location.kind === "official") {
32814
33146
  await this.#forwardOfficialRequest(request, frame);
32815
33147
  return;
32816
33148
  }
32817
- if (location.kind !== "external") return;
32818
- if (decoded.isPinned === void 0 || decoded.gitInfo !== void 0) {
32819
- await this.#writer.json(
32820
- rpcError(request, -32078, "External Thread metadata updates are unsupported")
32821
- );
32822
- return;
33149
+ if (location.kind === "external") {
33150
+ const pinOnly = update.isPinned !== void 0 && update.unsupportedFields.length === 1 && update.unsupportedFields[0] === "isPinned" && update.projectId === void 0 && update.daybreakEnabled === void 0 && update.gitInfo === void 0;
33151
+ if (pinOnly) {
33152
+ await this.#setExternalThreadPinned(request, location, update.isPinned ?? false);
33153
+ } else {
33154
+ await this.#updateExternalThreadMetadata(request, location, update);
33155
+ }
32823
33156
  }
32824
- await this.#setExternalThreadPinned(request, location, decoded.isPinned ?? false);
32825
33157
  return;
32826
33158
  }
32827
33159
  let createRoute;
@@ -33148,6 +33480,12 @@ var AppServerHost = class {
33148
33480
  if (forwarded === parsed) await this.#writer.frame(input.frame);
33149
33481
  else await this.#writer.json(forwarded);
33150
33482
  this.#nativeAccountObserver?.observe(parsed);
33483
+ const deletedProjectId = observeDeletedProject(parsed);
33484
+ if (deletedProjectId) {
33485
+ await this.#clearDeletedProjectAssignments(deletedProjectId).catch(
33486
+ (error51) => this.#diagnose(error51)
33487
+ );
33488
+ }
33151
33489
  }
33152
33490
  async #requestOfficial(method, params) {
33153
33491
  return this.#officialRuntime.request(method, params);
@@ -33783,49 +34121,119 @@ var AppServerHost = class {
33783
34121
  return typeof thread.id === "string" ? { ...thread, ...await this.#externalSectionFields(thread.id) } : thread;
33784
34122
  }
33785
34123
  async #setExternalThreadArchived(request, location, archived) {
33786
- if (location.record.state !== "ready" || !location.record.nativeSessionRef) {
33787
- await this.#writer.json(rpcError(request, -32079, "External Native Session is unavailable"));
34124
+ const updated = await this.#persistExternalThreadRecord(
34125
+ request,
34126
+ location,
34127
+ (hostThreadId) => this.#repository.setArchived(hostThreadId, archived),
34128
+ "External Thread archive state could not be persisted"
34129
+ );
34130
+ if (!updated) return;
34131
+ await this.#writer.json(
34132
+ rpcEnvelope(request, { result: archived ? {} : { thread: updated.thread } })
34133
+ );
34134
+ await this.#writer.json({
34135
+ method: archived ? "thread/archived" : "thread/unarchived",
34136
+ params: { threadId: updated.record.hostThreadId }
34137
+ });
34138
+ }
34139
+ async #updateExternalThreadMetadata(request, location, update) {
34140
+ if (update.unsupportedFields.length > 0) {
34141
+ await this.#writer.json(
34142
+ rpcError(
34143
+ request,
34144
+ -32078,
34145
+ `External Thread metadata fields are unsupported: ${update.unsupportedFields.join(", ")}`
34146
+ )
34147
+ );
33788
34148
  return;
33789
34149
  }
34150
+ if (typeof update.projectId === "string") {
34151
+ const exists2 = await this.#requestOfficial("project/read", {
34152
+ projectId: update.projectId
34153
+ }).then(
34154
+ (response) => !isRecord15(response.error) && isRecord15(response.result) && isRecord15(response.result.project) && response.result.project.id === update.projectId,
34155
+ () => false
34156
+ );
34157
+ if (!exists2) {
34158
+ await this.#writer.json(rpcError(request, -32602, "Project is unavailable"));
34159
+ return;
34160
+ }
34161
+ }
34162
+ const patch = {
34163
+ ...update.projectId !== void 0 ? { projectId: update.projectId } : {},
34164
+ ...update.daybreakEnabled !== void 0 ? { daybreakEnabled: update.daybreakEnabled } : {},
34165
+ ...update.gitInfo !== void 0 ? { gitInfo: update.gitInfo } : {}
34166
+ };
34167
+ const previousProjectId = location.record.projectId ?? null;
34168
+ const updated = await this.#persistExternalThreadRecord(
34169
+ request,
34170
+ location,
34171
+ (hostThreadId) => this.#repository.updateMetadata(hostThreadId, patch),
34172
+ "External Thread metadata could not be persisted",
34173
+ true
34174
+ );
34175
+ if (!updated) return;
34176
+ await this.#writer.json(rpcEnvelope(request, { result: { thread: updated.thread } }));
34177
+ const projectId = updated.record.projectId ?? null;
34178
+ if (projectId !== previousProjectId) {
34179
+ await this.#writer.json({
34180
+ method: "thread/project/updated",
34181
+ params: { threadId: updated.record.hostThreadId, projectId }
34182
+ });
34183
+ }
34184
+ }
34185
+ /** Clear External assignments to a project official Codex reported as deleted. */
34186
+ async #clearDeletedProjectAssignments(projectId) {
34187
+ const records = await this.#repository.list();
34188
+ for (const record4 of records) {
34189
+ if (record4.projectId !== projectId) continue;
34190
+ const updated = await this.#repository.updateMetadata(
34191
+ record4.hostThreadId,
34192
+ { projectId: null },
34193
+ { ifProjectId: projectId }
34194
+ );
34195
+ if (updated.projectId !== void 0) continue;
34196
+ const loaded = this.#externalRuntime.get(updated.hostThreadId);
34197
+ if (loaded) this.#syncLoadedExternalThread(loaded, updated);
34198
+ await this.#writer.json({
34199
+ method: "thread/project/updated",
34200
+ params: { threadId: updated.hostThreadId, projectId: null }
34201
+ });
34202
+ }
34203
+ }
34204
+ #syncLoadedExternalThread(thread, record4) {
34205
+ const projected = externalThreadValue({
34206
+ record: record4,
34207
+ turns: [],
34208
+ sessionId: thread.sessionId,
34209
+ running: thread.running
34210
+ });
34211
+ thread.record = record4;
34212
+ thread.thread = { ...thread.thread, ...projected, turns: thread.thread.turns ?? [] };
34213
+ return projected;
34214
+ }
34215
+ async #persistExternalThreadRecord(request, location, write, failureMessage, allowProvisional = false) {
34216
+ const hasNativeSession = location.record.state === "ready" && location.record.nativeSessionRef !== void 0;
34217
+ if (!hasNativeSession && !(allowProvisional && location.thread)) {
34218
+ await this.#writer.json(rpcError(request, -32079, "External Native Session is unavailable"));
34219
+ return null;
34220
+ }
33790
34221
  const sessionId = location.thread?.sessionId ?? await this.#repository.sessionTreeId(location.record).catch(() => null);
33791
34222
  if (!sessionId) {
33792
34223
  await this.#writer.json(
33793
34224
  rpcError(request, -32081, "External Thread metadata could not be projected")
33794
34225
  );
33795
- return;
34226
+ return null;
33796
34227
  }
33797
34228
  let record4;
33798
34229
  try {
33799
- record4 = await this.#repository.setArchived(location.record.hostThreadId, archived);
34230
+ record4 = await write(location.record.hostThreadId);
33800
34231
  } catch {
33801
- await this.#writer.json(
33802
- rpcError(request, -32081, "External Thread archive state could not be persisted")
33803
- );
33804
- return;
33805
- }
33806
- const projected = externalThreadValue({
33807
- record: record4,
33808
- turns: [],
33809
- sessionId,
33810
- ...location.thread ? { running: location.thread.running } : { loaded: false }
33811
- });
33812
- if (location.thread) {
33813
- location.thread.record = record4;
33814
- location.thread.thread = {
33815
- ...location.thread.thread,
33816
- ...projected,
33817
- turns: location.thread.thread.turns ?? []
33818
- };
34232
+ await this.#writer.json(rpcError(request, -32081, failureMessage));
34233
+ return null;
33819
34234
  }
33820
- await this.#writer.json(
33821
- rpcEnvelope(request, {
33822
- result: archived ? {} : { thread: await this.#withExternalSection(projected) }
33823
- })
33824
- );
33825
- await this.#writer.json({
33826
- method: archived ? "thread/archived" : "thread/unarchived",
33827
- params: { threadId: record4.hostThreadId }
33828
- });
34235
+ const projected = location.thread ? this.#syncLoadedExternalThread(location.thread, record4) : externalThreadValue({ record: record4, turns: [], sessionId, loaded: false });
34236
+ return { record: record4, thread: await this.#withExternalSection(projected) };
33829
34237
  }
33830
34238
  /** 持久化置顶变更,并向 Desktop 返回更新后的 External Thread 投影。 */
33831
34239
  async #setExternalThreadPinned(request, location, isPinned) {