adhdev 0.8.63 → 0.8.66

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -974,6 +974,51 @@ var init_host_memory = __esm({
974
974
  }
975
975
  });
976
976
 
977
+ // ../../oss/packages/daemon-core/src/status/chat-tail-hot-sessions.ts
978
+ function parseMessageTimestamp(value) {
979
+ if (typeof value === "number" && Number.isFinite(value)) return value;
980
+ if (typeof value === "string") {
981
+ const parsed = Date.parse(value);
982
+ if (Number.isFinite(parsed)) return parsed;
983
+ }
984
+ return 0;
985
+ }
986
+ function classifyHotChatSessionsForSubscriptionFlush(sessions, previousHotSessionIds, options = {}) {
987
+ const now = options.now ?? Date.now();
988
+ const recentMessageGraceMs = Math.max(
989
+ 0,
990
+ Number.isFinite(options.recentMessageGraceMs) ? Number(options.recentMessageGraceMs) : DEFAULT_CHAT_TAIL_RECENT_MESSAGE_GRACE_MS
991
+ );
992
+ const activeStatuses = options.activeStatuses ?? DEFAULT_ACTIVE_CHAT_POLL_STATUSES;
993
+ const active = /* @__PURE__ */ new Set();
994
+ for (const session of sessions) {
995
+ const sessionId = typeof session?.id === "string" ? session.id : "";
996
+ if (!sessionId) continue;
997
+ const status = String(session?.status || "").toLowerCase();
998
+ const lastMessageAt = parseMessageTimestamp(session?.lastMessageAt);
999
+ const recentlyUpdated = lastMessageAt > 0 && now - lastMessageAt <= recentMessageGraceMs;
1000
+ if (activeStatuses.has(status) || recentlyUpdated) {
1001
+ active.add(sessionId);
1002
+ }
1003
+ }
1004
+ const finalizing = new Set(
1005
+ Array.from(previousHotSessionIds).filter((sessionId) => !active.has(sessionId))
1006
+ );
1007
+ return { active, finalizing };
1008
+ }
1009
+ var DEFAULT_ACTIVE_CHAT_POLL_STATUSES, DEFAULT_CHAT_TAIL_RECENT_MESSAGE_GRACE_MS;
1010
+ var init_chat_tail_hot_sessions = __esm({
1011
+ "../../oss/packages/daemon-core/src/status/chat-tail-hot-sessions.ts"() {
1012
+ "use strict";
1013
+ DEFAULT_ACTIVE_CHAT_POLL_STATUSES = /* @__PURE__ */ new Set([
1014
+ "generating",
1015
+ "waiting_approval",
1016
+ "starting"
1017
+ ]);
1018
+ DEFAULT_CHAT_TAIL_RECENT_MESSAGE_GRACE_MS = 8e3;
1019
+ }
1020
+ });
1021
+
977
1022
  // ../../oss/packages/daemon-core/src/logging/logger.ts
978
1023
  function setLogLevel(level) {
979
1024
  currentLevel = level;
@@ -2839,19 +2884,75 @@ var init_status_monitor = __esm({
2839
2884
  });
2840
2885
 
2841
2886
  // ../../oss/packages/daemon-core/src/providers/chat-message-normalization.ts
2887
+ function canonicalizeKindHint(value) {
2888
+ return value.trim().toLowerCase().replace(/[\s-]+/g, "_");
2889
+ }
2890
+ function resolveBuiltinOrAliasKind(kind) {
2891
+ if (typeof kind !== "string") return null;
2892
+ const normalizedKind = canonicalizeKindHint(kind);
2893
+ if (!normalizedKind) return null;
2894
+ if (KNOWN_CHAT_MESSAGE_KINDS.has(normalizedKind)) return normalizedKind;
2895
+ return CHAT_MESSAGE_KIND_ALIASES[normalizedKind] || null;
2896
+ }
2897
+ function inferHintKind(value) {
2898
+ const direct = resolveBuiltinOrAliasKind(value);
2899
+ if (direct) return direct;
2900
+ if (typeof value !== "string") return null;
2901
+ const normalized = canonicalizeKindHint(value);
2902
+ if (!normalized) return null;
2903
+ if (/thought|thinking|reasoning/.test(normalized)) return "thought";
2904
+ if (/tool/.test(normalized)) return "tool";
2905
+ if (/terminal|command|shell|console/.test(normalized)) return "terminal";
2906
+ return null;
2907
+ }
2908
+ function inferKindFromToolCalls(message) {
2909
+ const toolCalls = Array.isArray(message?.toolCalls) ? message.toolCalls : [];
2910
+ if (toolCalls.length === 0) return null;
2911
+ if (toolCalls.some((toolCall) => toolCall?.kind === "think")) return "thought";
2912
+ if (toolCalls.some((toolCall) => toolCall?.kind === "execute")) return "terminal";
2913
+ if (toolCalls.some((toolCall) => Array.isArray(toolCall?.content) && toolCall.content.some((entry) => entry?.type === "terminal"))) {
2914
+ return "terminal";
2915
+ }
2916
+ return "tool";
2917
+ }
2918
+ function inferMissingChatMessageKind(message) {
2919
+ const role = typeof message?.role === "string" ? message.role.trim().toLowerCase() : "";
2920
+ if (role === "system") return "system";
2921
+ const meta3 = message?.meta && typeof message.meta === "object" ? message.meta : void 0;
2922
+ const hintCandidates = [
2923
+ message?._sub,
2924
+ message?._type,
2925
+ meta3?.label,
2926
+ typeof message?.senderName === "string" ? message.senderName : void 0
2927
+ ];
2928
+ for (const candidate of hintCandidates) {
2929
+ const inferred = inferHintKind(candidate);
2930
+ if (inferred) return inferred;
2931
+ }
2932
+ const inferredFromToolCalls = inferKindFromToolCalls(message);
2933
+ if (inferredFromToolCalls) return inferredFromToolCalls;
2934
+ return null;
2935
+ }
2842
2936
  function isBuiltinChatMessageKind(kind) {
2843
- return typeof kind === "string" && KNOWN_CHAT_MESSAGE_KINDS.has(kind.trim().toLowerCase());
2937
+ return resolveBuiltinOrAliasKind(kind) !== null;
2844
2938
  }
2845
2939
  function normalizeChatMessageKind(kind, role) {
2846
- const normalizedKind = typeof kind === "string" ? kind.trim().toLowerCase() : "";
2847
- if (normalizedKind && KNOWN_CHAT_MESSAGE_KINDS.has(normalizedKind)) return normalizedKind;
2940
+ const resolvedKind = resolveBuiltinOrAliasKind(kind);
2941
+ if (resolvedKind) return resolvedKind;
2848
2942
  const normalizedRole = typeof role === "string" ? role.trim().toLowerCase() : "";
2849
2943
  return normalizedRole === "system" ? "system" : "standard";
2850
2944
  }
2945
+ function resolveChatMessageKind(message) {
2946
+ const explicitKind = resolveBuiltinOrAliasKind(message?.kind);
2947
+ if (explicitKind) return explicitKind;
2948
+ const inferredKind = inferMissingChatMessageKind(message);
2949
+ if (inferredKind) return inferredKind;
2950
+ return normalizeChatMessageKind(message?.kind, message?.role);
2951
+ }
2851
2952
  function buildChatMessage(message) {
2852
2953
  return {
2853
2954
  ...message,
2854
- kind: normalizeChatMessageKind(message?.kind, message?.role)
2955
+ kind: resolveChatMessageKind(message)
2855
2956
  };
2856
2957
  }
2857
2958
  function buildSystemChatMessage(message) {
@@ -2874,6 +2975,24 @@ function buildAssistantChatMessage(message) {
2874
2975
  kind: message?.kind || "standard"
2875
2976
  });
2876
2977
  }
2978
+ function buildThoughtChatMessage(message) {
2979
+ return buildAssistantChatMessage({
2980
+ ...message,
2981
+ kind: message?.kind || "thought"
2982
+ });
2983
+ }
2984
+ function buildToolChatMessage(message) {
2985
+ return buildAssistantChatMessage({
2986
+ ...message,
2987
+ kind: message?.kind || "tool"
2988
+ });
2989
+ }
2990
+ function buildTerminalChatMessage(message) {
2991
+ return buildAssistantChatMessage({
2992
+ ...message,
2993
+ kind: message?.kind || "terminal"
2994
+ });
2995
+ }
2877
2996
  function buildUserChatMessage(message) {
2878
2997
  return buildChatMessage({
2879
2998
  ...message,
@@ -2887,12 +3006,30 @@ function normalizeChatMessage(message) {
2887
3006
  function normalizeChatMessages(messages) {
2888
3007
  return (Array.isArray(messages) ? messages : []).map((message) => normalizeChatMessage(message));
2889
3008
  }
2890
- var BUILTIN_CHAT_MESSAGE_KINDS, KNOWN_CHAT_MESSAGE_KINDS;
3009
+ var BUILTIN_CHAT_MESSAGE_KINDS, KNOWN_CHAT_MESSAGE_KINDS, CHAT_MESSAGE_KIND_ALIASES;
2891
3010
  var init_chat_message_normalization = __esm({
2892
3011
  "../../oss/packages/daemon-core/src/providers/chat-message-normalization.ts"() {
2893
3012
  "use strict";
2894
3013
  BUILTIN_CHAT_MESSAGE_KINDS = ["standard", "thought", "tool", "terminal", "system"];
2895
3014
  KNOWN_CHAT_MESSAGE_KINDS = new Set(BUILTIN_CHAT_MESSAGE_KINDS);
3015
+ CHAT_MESSAGE_KIND_ALIASES = {
3016
+ text: "standard",
3017
+ message: "standard",
3018
+ assistant: "standard",
3019
+ thinking: "thought",
3020
+ think: "thought",
3021
+ reasoning: "thought",
3022
+ reason: "thought",
3023
+ toolcall: "tool",
3024
+ tool_call: "tool",
3025
+ tooluse: "tool",
3026
+ tool_use: "tool",
3027
+ action: "tool",
3028
+ command: "terminal",
3029
+ cmd: "terminal",
3030
+ shell: "terminal",
3031
+ console: "terminal"
3032
+ };
2896
3033
  }
2897
3034
  });
2898
3035
 
@@ -3017,38 +3154,37 @@ function buildPersistedProviderEffectMessage(effect) {
3017
3154
  return null;
3018
3155
  }
3019
3156
  function normalizeControlListResult(data) {
3020
- if (data && typeof data === "object" && Array.isArray(data.options)) {
3021
- return {
3022
- options: normalizeControlOptions(data.options),
3023
- ...isScalarControlValue(data.currentValue) ? { currentValue: data.currentValue } : {},
3024
- ...typeof data.error === "string" ? { error: data.error } : {}
3025
- };
3157
+ if (!data || typeof data !== "object" || !Array.isArray(data.options)) {
3158
+ throw new Error("Provider control list results must use the typed shape { options, currentValue?, error? }");
3026
3159
  }
3027
- const rawOptions = Array.isArray(data?.models) ? data.models : Array.isArray(data?.modes) ? data.modes : Array.isArray(data?.options) ? data.options : [];
3028
- const options = normalizeControlOptions(rawOptions);
3029
3160
  return {
3030
- options,
3031
- ...isScalarControlValue(data?.current) ? { currentValue: data.current } : {},
3032
- ...isScalarControlValue(data?.currentValue) ? { currentValue: data.currentValue } : {},
3033
- ...typeof data?.error === "string" ? { error: data.error } : {}
3161
+ options: normalizeControlOptions(data.options),
3162
+ ...isScalarControlValue(data.currentValue) ? { currentValue: data.currentValue } : {},
3163
+ ...typeof data.error === "string" ? { error: data.error } : {}
3034
3164
  };
3035
3165
  }
3036
3166
  function normalizeControlSetResult(data) {
3037
- const currentValue = isScalarControlValue(data?.currentValue) ? data.currentValue : isScalarControlValue(data?.value) ? data.value : void 0;
3167
+ if (!data || typeof data !== "object" || typeof data.ok !== "boolean") {
3168
+ throw new Error("Provider control set results must use the typed shape { ok, currentValue?, effects?, error? }");
3169
+ }
3170
+ const currentValue = isScalarControlValue(data.currentValue) ? data.currentValue : isScalarControlValue(data.value) ? data.value : void 0;
3038
3171
  return {
3039
- ok: data?.ok === true || data?.success === true,
3172
+ ok: data.ok,
3040
3173
  ...currentValue !== void 0 ? { currentValue } : {},
3041
- ...Array.isArray(data?.effects) ? { effects: normalizeProviderEffects(data) } : {},
3042
- ...typeof data?.error === "string" ? { error: data.error } : {}
3174
+ ...Array.isArray(data.effects) ? { effects: normalizeProviderEffects(data) } : {},
3175
+ ...typeof data.error === "string" ? { error: data.error } : {}
3043
3176
  };
3044
3177
  }
3045
3178
  function normalizeControlInvokeResult(data) {
3046
- const currentValue = isScalarControlValue(data?.currentValue) ? data.currentValue : isScalarControlValue(data?.value) ? data.value : void 0;
3179
+ if (!data || typeof data !== "object" || typeof data.ok !== "boolean") {
3180
+ throw new Error("Provider control invoke results must use the typed shape { ok, currentValue?, effects?, error? }");
3181
+ }
3182
+ const currentValue = isScalarControlValue(data.currentValue) ? data.currentValue : isScalarControlValue(data.value) ? data.value : void 0;
3047
3183
  return {
3048
- ok: data?.ok === true || data?.success === true,
3184
+ ok: data.ok,
3049
3185
  ...currentValue !== void 0 ? { currentValue } : {},
3050
- ...Array.isArray(data?.effects) ? { effects: normalizeProviderEffects(data) } : {},
3051
- ...typeof data?.error === "string" ? { error: data.error } : {}
3186
+ ...Array.isArray(data.effects) ? { effects: normalizeProviderEffects(data) } : {},
3187
+ ...typeof data.error === "string" ? { error: data.error } : {}
3052
3188
  };
3053
3189
  }
3054
3190
  function normalizeControlOptions(options) {
@@ -3968,19 +4104,37 @@ var init_extension_provider_instance = __esm({
3968
4104
  );
3969
4105
  }
3970
4106
  }
4107
+ buildSyntheticTurnKey(message, occurrence) {
4108
+ const role = typeof message?.role === "string" ? message.role : "";
4109
+ const kind = typeof message?.kind === "string" ? message.kind : "";
4110
+ const senderName = typeof message?.senderName === "string" ? message.senderName : "";
4111
+ const content = flattenContent(message?.content).replace(/\s+/g, " ").trim().slice(0, 500);
4112
+ return `${role}|${kind}|${senderName}|${content}|${occurrence}`;
4113
+ }
3971
4114
  /**
3972
- * Assign stable receivedAt to extension messages.
3973
- * Same pattern as IdeProviderInstance.readChat() prevByHash
3974
- * preserves first-seen timestamp across polling cycles.
4115
+ * Assign stable receivedAt / synthetic _turnKey to extension messages.
4116
+ * Same transcript should keep the same identity across polling cycles and
4117
+ * stream resets, while repeated identical text later in the transcript still
4118
+ * produces a distinct completion marker via the occurrence suffix.
3975
4119
  */
3976
4120
  assignReceivedAt(messages) {
3977
4121
  const now = Date.now();
3978
4122
  const nextHashes = /* @__PURE__ */ new Map();
4123
+ const occurrenceByBaseKey = /* @__PURE__ */ new Map();
3979
4124
  for (const msg of messages) {
3980
- const hash2 = `${msg.role}:${(msg.content || "").slice(0, 100)}`;
3981
- const prevTime = this.prevMessageHashes.get(hash2);
4125
+ const explicitTurnKey = typeof msg?._turnKey === "string" && msg._turnKey.trim() ? msg._turnKey.trim() : "";
4126
+ const explicitId = typeof msg?.id === "string" && msg.id.trim() ? `id:${msg.id.trim()}` : "";
4127
+ const explicitIndex = typeof msg?.index === "number" && Number.isFinite(msg.index) ? `idx:${msg.index}` : "";
4128
+ const baseKey = explicitTurnKey || explicitId || explicitIndex || `${msg?.role || ""}:${flattenContent(msg?.content || "").slice(0, 500)}`;
4129
+ const occurrence = (occurrenceByBaseKey.get(baseKey) || 0) + 1;
4130
+ occurrenceByBaseKey.set(baseKey, occurrence);
4131
+ const syntheticTurnKey = explicitTurnKey || explicitId || explicitIndex || this.buildSyntheticTurnKey(msg, occurrence);
4132
+ if (!explicitTurnKey && !explicitId && !explicitIndex) {
4133
+ msg._turnKey = syntheticTurnKey;
4134
+ }
4135
+ const prevTime = this.prevMessageHashes.get(syntheticTurnKey);
3982
4136
  msg.receivedAt = prevTime || now;
3983
- nextHashes.set(hash2, msg.receivedAt);
4137
+ nextHashes.set(syntheticTurnKey, msg.receivedAt);
3984
4138
  }
3985
4139
  this.prevMessageHashes = nextHashes;
3986
4140
  return normalizeChatMessages(messages);
@@ -4057,6 +4211,128 @@ ${effect.notification.body || ""}`.trim();
4057
4211
  }
4058
4212
  });
4059
4213
 
4214
+ // ../../oss/packages/daemon-core/src/providers/read-chat-contract.ts
4215
+ function isPlainObject3(value) {
4216
+ return !!value && typeof value === "object" && !Array.isArray(value);
4217
+ }
4218
+ function isFiniteNumber(value) {
4219
+ return typeof value === "number" && Number.isFinite(value);
4220
+ }
4221
+ function validateStatus(status, source) {
4222
+ if (typeof status !== "string" || !VALID_STATUSES.includes(status)) {
4223
+ throw new Error(`${source}: status must be one of ${VALID_STATUSES.join(", ")}`);
4224
+ }
4225
+ return status;
4226
+ }
4227
+ function validateRole(role, source, index) {
4228
+ if (typeof role !== "string" || !VALID_ROLES.includes(role)) {
4229
+ throw new Error(`${source}: messages[${index}].role must be one of ${VALID_ROLES.join(", ")}`);
4230
+ }
4231
+ return role;
4232
+ }
4233
+ function validateMessageContent(content, source, index) {
4234
+ if (typeof content === "string") return content;
4235
+ if (Array.isArray(content)) return normalizeMessageParts(content);
4236
+ throw new Error(`${source}: messages[${index}].content must be a string or structured content array`);
4237
+ }
4238
+ function validateMessage(message, source, index) {
4239
+ if (!isPlainObject3(message)) {
4240
+ throw new Error(`${source}: messages[${index}] must be an object`);
4241
+ }
4242
+ const normalized = {
4243
+ role: validateRole(message.role, source, index),
4244
+ content: validateMessageContent(message.content, source, index)
4245
+ };
4246
+ if (typeof message.kind === "string") normalized.kind = message.kind;
4247
+ if (typeof message.id === "string") normalized.id = message.id;
4248
+ if (isFiniteNumber(message.index)) normalized.index = message.index;
4249
+ if (isFiniteNumber(message.timestamp)) normalized.timestamp = message.timestamp;
4250
+ if (isFiniteNumber(message.receivedAt)) normalized.receivedAt = message.receivedAt;
4251
+ if (Array.isArray(message.toolCalls)) normalized.toolCalls = message.toolCalls;
4252
+ if (isPlainObject3(message.meta)) normalized.meta = message.meta;
4253
+ if (typeof message.senderName === "string") normalized.senderName = message.senderName;
4254
+ if (typeof message._type === "string") normalized._type = message._type;
4255
+ if (typeof message._sub === "string") normalized._sub = message._sub;
4256
+ return normalized;
4257
+ }
4258
+ function validateModal(activeModal, status, source) {
4259
+ if (activeModal == null) {
4260
+ if (status === "waiting_approval") {
4261
+ throw new Error(`${source}: waiting_approval status requires activeModal with buttons`);
4262
+ }
4263
+ return activeModal === null ? null : void 0;
4264
+ }
4265
+ if (!isPlainObject3(activeModal)) {
4266
+ throw new Error(`${source}: activeModal must be an object when provided`);
4267
+ }
4268
+ if (typeof activeModal.message !== "string") {
4269
+ throw new Error(`${source}: activeModal.message must be a string`);
4270
+ }
4271
+ if (!Array.isArray(activeModal.buttons) || activeModal.buttons.some((button) => typeof button !== "string" || !button.trim())) {
4272
+ throw new Error(`${source}: activeModal.buttons must be a non-empty string array`);
4273
+ }
4274
+ const normalized = {
4275
+ message: activeModal.message,
4276
+ buttons: activeModal.buttons.map((button) => button.trim())
4277
+ };
4278
+ if (isFiniteNumber(activeModal.width)) normalized.width = activeModal.width;
4279
+ if (isFiniteNumber(activeModal.height)) normalized.height = activeModal.height;
4280
+ return normalized;
4281
+ }
4282
+ function validateControlValues(controlValues, source) {
4283
+ if (controlValues === void 0) return void 0;
4284
+ if (!isPlainObject3(controlValues)) {
4285
+ throw new Error(`${source}: controlValues must be an object when provided`);
4286
+ }
4287
+ const normalized = {};
4288
+ for (const [key, value] of Object.entries(controlValues)) {
4289
+ if (typeof value !== "string" && typeof value !== "number" && typeof value !== "boolean") {
4290
+ throw new Error(`${source}: controlValues.${key} must be string, number, or boolean`);
4291
+ }
4292
+ normalized[key] = value;
4293
+ }
4294
+ return normalized;
4295
+ }
4296
+ function validateReadChatResultPayload(raw, source = "read_chat") {
4297
+ if (!isPlainObject3(raw)) {
4298
+ throw new Error(`${source}: payload must be an object`);
4299
+ }
4300
+ const status = validateStatus(raw.status, source);
4301
+ if (!Array.isArray(raw.messages)) {
4302
+ throw new Error(`${source}: messages must be an array`);
4303
+ }
4304
+ const messages = raw.messages.map((message, index) => validateMessage(message, source, index));
4305
+ const activeModal = validateModal(raw.activeModal, status, source);
4306
+ const controlValues = validateControlValues(raw.controlValues, source);
4307
+ const normalized = {
4308
+ status,
4309
+ messages
4310
+ };
4311
+ if (activeModal !== void 0) normalized.activeModal = activeModal;
4312
+ if (typeof raw.id === "string") normalized.id = raw.id;
4313
+ if (typeof raw.title === "string") normalized.title = raw.title;
4314
+ if (typeof raw.agentType === "string") normalized.agentType = raw.agentType;
4315
+ if (typeof raw.agentName === "string") normalized.agentName = raw.agentName;
4316
+ if (typeof raw.extensionId === "string") normalized.extensionId = raw.extensionId;
4317
+ if (typeof raw.inputContent === "string") normalized.inputContent = raw.inputContent;
4318
+ if (typeof raw.isVisible === "boolean") normalized.isVisible = raw.isVisible;
4319
+ if (typeof raw.isWelcomeScreen === "boolean") normalized.isWelcomeScreen = raw.isWelcomeScreen;
4320
+ if (controlValues) normalized.controlValues = controlValues;
4321
+ if (raw.summaryMetadata !== void 0) normalized.summaryMetadata = raw.summaryMetadata;
4322
+ if (Array.isArray(raw.effects)) normalized.effects = raw.effects;
4323
+ if (typeof raw.providerSessionId === "string") normalized.providerSessionId = raw.providerSessionId;
4324
+ return normalized;
4325
+ }
4326
+ var VALID_STATUSES, VALID_ROLES;
4327
+ var init_read_chat_contract = __esm({
4328
+ "../../oss/packages/daemon-core/src/providers/read-chat-contract.ts"() {
4329
+ "use strict";
4330
+ init_contracts();
4331
+ VALID_STATUSES = ["idle", "generating", "waiting_approval", "error", "panel_hidden", "streaming", "long_generating"];
4332
+ VALID_ROLES = ["user", "assistant", "system", "human"];
4333
+ }
4334
+ });
4335
+
4060
4336
  // ../../oss/packages/daemon-core/src/providers/approval-utils.ts
4061
4337
  function normalizeApprovalLabel(value) {
4062
4338
  return String(value || "").toLowerCase().replace(/[^\p{L}\p{N}]+/gu, " ").trim();
@@ -4122,6 +4398,7 @@ var init_ide_provider_instance = __esm({
4122
4398
  init_chat_history();
4123
4399
  init_logger();
4124
4400
  init_control_effects();
4401
+ init_read_chat_contract();
4125
4402
  init_approval_utils();
4126
4403
  init_provider_patch_state();
4127
4404
  init_chat_message_normalization();
@@ -4356,7 +4633,7 @@ var init_ide_provider_instance = __esm({
4356
4633
  }
4357
4634
  }
4358
4635
  if (!raw || typeof raw !== "object") return;
4359
- const chat = raw;
4636
+ const chat = validateReadChatResultPayload(raw, `${this.type} readChat`);
4360
4637
  let { activeModal } = chat;
4361
4638
  if (activeModal) {
4362
4639
  const w = activeModal.width ?? Infinity;
@@ -4377,11 +4654,13 @@ var init_ide_provider_instance = __esm({
4377
4654
  if (pm.receivedAt) prevByHash.set(h, pm.receivedAt);
4378
4655
  }
4379
4656
  const now = Date.now();
4380
- const messages = chat.messages || [];
4381
- for (const msg of messages) {
4657
+ const rawMessages = chat.messages || [];
4658
+ for (const msg of rawMessages) {
4382
4659
  const h = `${msg.role}:${(msg.content || "").slice(0, 100)}`;
4383
4660
  msg.receivedAt = prevByHash.get(h) || now;
4384
4661
  }
4662
+ chat.messages = normalizeChatMessages(rawMessages);
4663
+ const messages = chat.messages || [];
4385
4664
  if (messages.length > 0) {
4386
4665
  const hiddenKinds = /* @__PURE__ */ new Set();
4387
4666
  if (this.settings.showThinking === false) hiddenKinds.add("thought");
@@ -5541,6 +5820,67 @@ var init_reconcile = __esm({
5541
5820
  }
5542
5821
  });
5543
5822
 
5823
+ // ../../oss/packages/daemon-core/src/providers/provider-input-support.ts
5824
+ function getProviderLabel(provider) {
5825
+ return provider?.name || provider?.type || "This provider";
5826
+ }
5827
+ function hasNonEmptyFallbackText(input) {
5828
+ return typeof input.textFallback === "string" && input.textFallback.trim().length > 0;
5829
+ }
5830
+ function getRequestedInputMediaTypes(input) {
5831
+ const types = /* @__PURE__ */ new Set();
5832
+ if (hasNonEmptyFallbackText(input) && !input.parts.some((part) => part.type === "text")) {
5833
+ types.add("text");
5834
+ }
5835
+ for (const part of input.parts) {
5836
+ if (VALID_INPUT_MEDIA_TYPES.has(part.type)) {
5837
+ types.add(part.type);
5838
+ }
5839
+ }
5840
+ return Array.from(types);
5841
+ }
5842
+ function getEffectiveSemanticPartCount(input) {
5843
+ let count = input.parts.length;
5844
+ if (hasNonEmptyFallbackText(input) && !input.parts.some((part) => part.type === "text")) {
5845
+ count += 1;
5846
+ }
5847
+ return count;
5848
+ }
5849
+ function assertTextOnlyInput(provider, input) {
5850
+ const unsupported = getRequestedInputMediaTypes(input).filter((type) => type !== "text");
5851
+ if (unsupported.length === 0) return;
5852
+ const label = getProviderLabel(provider);
5853
+ const suffix = unsupported.length === 1 ? "" : "s";
5854
+ throw new Error(`${label} only supports text input; unsupported input type${suffix}: ${unsupported.join(", ")}`);
5855
+ }
5856
+ function getDeclaredProviderInputSupport(provider) {
5857
+ const rawMediaTypes = Array.isArray(provider?.capabilities?.input?.mediaTypes) ? provider?.capabilities?.input?.mediaTypes.filter((type) => VALID_INPUT_MEDIA_TYPES.has(type)) : [];
5858
+ return {
5859
+ multipart: provider?.capabilities?.input?.multipart === true,
5860
+ mediaTypes: new Set(rawMediaTypes.length > 0 ? rawMediaTypes : ["text"])
5861
+ };
5862
+ }
5863
+ function assertProviderSupportsDeclaredInput(provider, input) {
5864
+ const label = getProviderLabel(provider);
5865
+ const support = getDeclaredProviderInputSupport(provider);
5866
+ const requestedTypes = getRequestedInputMediaTypes(input);
5867
+ const unsupported = requestedTypes.filter((type) => !support.mediaTypes.has(type));
5868
+ if (unsupported.length > 0) {
5869
+ const suffix = unsupported.length === 1 ? "" : "s";
5870
+ throw new Error(`${label} does not support input type${suffix}: ${unsupported.join(", ")}`);
5871
+ }
5872
+ if (getEffectiveSemanticPartCount(input) > 1 && !support.multipart) {
5873
+ throw new Error(`${label} does not support multipart input`);
5874
+ }
5875
+ }
5876
+ var VALID_INPUT_MEDIA_TYPES;
5877
+ var init_provider_input_support = __esm({
5878
+ "../../oss/packages/daemon-core/src/providers/provider-input-support.ts"() {
5879
+ "use strict";
5880
+ VALID_INPUT_MEDIA_TYPES = /* @__PURE__ */ new Set(["text", "image", "audio", "video", "resource"]);
5881
+ }
5882
+ });
5883
+
5544
5884
  // ../../oss/packages/daemon-core/src/logging/debug-config.ts
5545
5885
  function normalizeCategories(categories) {
5546
5886
  if (!Array.isArray(categories)) return [];
@@ -5730,10 +6070,15 @@ function isCliLikeTransport(transport) {
5730
6070
  function isExtensionTransport(transport) {
5731
6071
  return transport === "cdp-webview";
5732
6072
  }
5733
- function buildRecentSendKey(h, args, provider, text) {
6073
+ function buildRecentSendKey(h, args, provider, signature) {
5734
6074
  const transport = getTargetTransport(h, provider) || "unknown";
5735
6075
  const target = args?.targetSessionId || args?.agentType || h.currentSession?.providerType || h.currentProviderType || h.currentManagerKey || "unknown";
5736
- return `${transport}:${target}:${text.trim()}`;
6076
+ return `${transport}:${target}:${signature.trim()}`;
6077
+ }
6078
+ function buildSendInputSignature(input) {
6079
+ const text = typeof input.textFallback === "string" ? input.textFallback.trim() : "";
6080
+ if (text) return text;
6081
+ return JSON.stringify(input.parts || []);
5737
6082
  }
5738
6083
  function getSendChatInputEnvelope(args) {
5739
6084
  return normalizeInputEnvelope(args?.input ? { input: args.input } : args);
@@ -5886,14 +6231,20 @@ function computeReadChatSync(messages, cursor) {
5886
6231
  };
5887
6232
  }
5888
6233
  function buildReadChatCommandResult(payload, args) {
5889
- const messages = normalizeReadChatMessages(payload);
6234
+ let validatedPayload;
6235
+ try {
6236
+ validatedPayload = validateReadChatResultPayload(payload, "read_chat command result");
6237
+ } catch (error48) {
6238
+ return { success: false, error: error48?.message || String(error48) };
6239
+ }
6240
+ const messages = normalizeReadChatMessages(validatedPayload);
5890
6241
  const cursor = normalizeReadChatCursor(args);
5891
6242
  if (!cursor.knownMessageCount && !cursor.lastMessageSignature && cursor.tailLimit > 0 && messages.length > cursor.tailLimit) {
5892
6243
  const tailMessages = messages.slice(-cursor.tailLimit);
5893
6244
  const lastMessageSignature = getChatMessageSignature(tailMessages[tailMessages.length - 1]);
5894
6245
  return {
5895
6246
  success: true,
5896
- ...payload,
6247
+ ...validatedPayload,
5897
6248
  messages: tailMessages,
5898
6249
  syncMode: "full",
5899
6250
  replaceFrom: 0,
@@ -5904,7 +6255,7 @@ function buildReadChatCommandResult(payload, args) {
5904
6255
  const sync = computeReadChatSync(messages, cursor);
5905
6256
  return {
5906
6257
  success: true,
5907
- ...payload,
6258
+ ...validatedPayload,
5908
6259
  messages: sync.messages,
5909
6260
  syncMode: sync.syncMode,
5910
6261
  replaceFrom: sync.replaceFrom,
@@ -5983,12 +6334,18 @@ async function handleReadChat(h, args) {
5983
6334
  const adapter = getTargetedCliAdapter(h, args, provider?.type);
5984
6335
  if (adapter) {
5985
6336
  _log(`${transport} adapter: ${adapter.cliType}`);
5986
- const status = adapter.getStatus();
6337
+ const parsedStatus = typeof adapter.getScriptParsedStatus === "function" ? parseMaybeJson(adapter.getScriptParsedStatus()) : null;
6338
+ const parsedRecord = parsedStatus && typeof parsedStatus === "object" ? parsedStatus : null;
6339
+ const status = parsedRecord || adapter.getStatus();
6340
+ const title = typeof parsedRecord?.title === "string" ? parsedRecord.title : void 0;
6341
+ const providerSessionId = typeof parsedRecord?.providerSessionId === "string" ? parsedRecord.providerSessionId : void 0;
5987
6342
  if (status) {
5988
6343
  return buildReadChatCommandResult({
5989
6344
  messages: status.messages || [],
5990
6345
  status: status.status,
5991
- activeModal: status.activeModal
6346
+ activeModal: status.activeModal,
6347
+ ...title ? { title } : {},
6348
+ ...providerSessionId ? { providerSessionId } : {}
5992
6349
  }, args);
5993
6350
  }
5994
6351
  }
@@ -6006,25 +6363,26 @@ async function handleReadChat(h, args) {
6006
6363
  }
6007
6364
  }
6008
6365
  if (parsed && typeof parsed === "object") {
6009
- _log(`Extension OK: ${parsed.messages?.length || 0} msgs`);
6366
+ const validated = validateReadChatResultPayload(parsed, "extension read_chat");
6367
+ _log(`Extension OK: ${validated.messages?.length || 0} msgs`);
6010
6368
  traceProviderEvent(args, "provider", "extension.read_chat.success", {
6011
6369
  h,
6012
6370
  provider,
6013
6371
  payload: {
6014
6372
  method: "evaluateProviderScript",
6015
6373
  result: evalResult.result,
6016
- parsed,
6017
- messageCount: Array.isArray(parsed.messages) ? parsed.messages.length : 0
6374
+ parsed: validated,
6375
+ messageCount: Array.isArray(validated.messages) ? validated.messages.length : 0
6018
6376
  }
6019
6377
  });
6020
6378
  h.historyWriter.appendNewMessages(
6021
6379
  provider?.type || "unknown_extension",
6022
- toHistoryPersistedMessages(normalizeReadChatMessages(parsed)),
6023
- parsed.title,
6380
+ toHistoryPersistedMessages(normalizeReadChatMessages(validated)),
6381
+ validated.title,
6024
6382
  args?.targetSessionId,
6025
6383
  historySessionId
6026
6384
  );
6027
- return buildReadChatCommandResult(parsed, args);
6385
+ return buildReadChatCommandResult(validated, args);
6028
6386
  }
6029
6387
  }
6030
6388
  } catch (e) {
@@ -6079,15 +6437,16 @@ async function handleReadChat(h, args) {
6079
6437
  }
6080
6438
  }
6081
6439
  if (parsed && typeof parsed === "object") {
6082
- _log(`Webview OK: ${parsed.messages?.length || 0} msgs`);
6440
+ const validated = validateReadChatResultPayload(parsed, "webview read_chat");
6441
+ _log(`Webview OK: ${validated.messages?.length || 0} msgs`);
6083
6442
  h.historyWriter.appendNewMessages(
6084
6443
  provider?.type || getCurrentProviderType(h, "unknown_webview"),
6085
- toHistoryPersistedMessages(normalizeReadChatMessages(parsed)),
6086
- parsed.title,
6444
+ toHistoryPersistedMessages(normalizeReadChatMessages(validated)),
6445
+ validated.title,
6087
6446
  args?.targetSessionId,
6088
6447
  historySessionId
6089
6448
  );
6090
- return buildReadChatCommandResult(parsed, args);
6449
+ return buildReadChatCommandResult(validated, args);
6091
6450
  }
6092
6451
  }
6093
6452
  } catch (e) {
@@ -6108,25 +6467,26 @@ async function handleReadChat(h, args) {
6108
6467
  }
6109
6468
  }
6110
6469
  if (parsed && typeof parsed === "object" && parsed.messages?.length > 0) {
6111
- _log(`OK: ${parsed.messages?.length} msgs`);
6470
+ const validated = validateReadChatResultPayload(parsed, "ide read_chat");
6471
+ _log(`OK: ${validated.messages?.length} msgs`);
6112
6472
  traceProviderEvent(args, "provider", "ide.read_chat.success", {
6113
6473
  h,
6114
6474
  provider,
6115
6475
  payload: {
6116
6476
  method: "evaluate",
6117
6477
  result: evalResult.result,
6118
- parsed,
6119
- messageCount: Array.isArray(parsed.messages) ? parsed.messages.length : 0
6478
+ parsed: validated,
6479
+ messageCount: Array.isArray(validated.messages) ? validated.messages.length : 0
6120
6480
  }
6121
6481
  });
6122
6482
  h.historyWriter.appendNewMessages(
6123
6483
  provider?.type || getCurrentProviderType(h, "unknown_ide"),
6124
- toHistoryPersistedMessages(normalizeReadChatMessages(parsed)),
6125
- parsed.title,
6484
+ toHistoryPersistedMessages(normalizeReadChatMessages(validated)),
6485
+ validated.title,
6126
6486
  args?.targetSessionId,
6127
6487
  historySessionId
6128
6488
  );
6129
- return buildReadChatCommandResult(parsed, args);
6489
+ return buildReadChatCommandResult(validated, args);
6130
6490
  }
6131
6491
  }
6132
6492
  } catch (e) {
@@ -6144,11 +6504,12 @@ async function handleReadChat(h, args) {
6144
6504
  async function handleSendChat(h, args) {
6145
6505
  const input = getSendChatInputEnvelope(args);
6146
6506
  const text = input.textFallback;
6147
- if (!text) return { success: false, error: "text required" };
6507
+ const hasInput = input.parts.length > 0 || typeof text === "string" && text.trim().length > 0;
6508
+ if (!hasInput) return { success: false, error: "input required" };
6148
6509
  const _log = (msg) => LOG.debug("Command", `[send_chat] ${msg}`);
6149
6510
  const provider = h.getProvider(args?.agentType);
6150
6511
  const transport = getTargetTransport(h, provider);
6151
- const dedupeKey = buildRecentSendKey(h, args, provider, text);
6512
+ const dedupeKey = buildRecentSendKey(h, args, provider, buildSendInputSignature(input));
6152
6513
  const _logSendSuccess = (method, targetAgent) => {
6153
6514
  return { success: true, sent: true, method, targetAgent };
6154
6515
  };
@@ -6156,11 +6517,26 @@ async function handleSendChat(h, args) {
6156
6517
  _log(`Suppressed duplicate send for ${dedupeKey}`);
6157
6518
  return { success: true, sent: false, deduplicated: true };
6158
6519
  }
6159
- if (isCliLikeTransport(transport)) {
6520
+ if (transport === "acp") {
6521
+ const target = getTargetInstance(h, args);
6522
+ if (!target || target.category !== "acp") {
6523
+ return { success: false, error: `ACP instance not found for ${provider?.type || args?.agentType || "unknown"}` };
6524
+ }
6525
+ try {
6526
+ assertProviderSupportsDeclaredInput(provider, input);
6527
+ target.onEvent("send_message", { input });
6528
+ return _logSendSuccess("acp-instance", target.type);
6529
+ } catch (e) {
6530
+ return { success: false, error: `acp send failed: ${e.message}` };
6531
+ }
6532
+ }
6533
+ if (transport === "pty") {
6160
6534
  const adapter = getTargetedCliAdapter(h, args, provider?.type);
6161
6535
  if (adapter) {
6162
6536
  _log(`${transport} adapter: ${adapter.cliType}`);
6163
6537
  try {
6538
+ assertTextOnlyInput(provider, input);
6539
+ if (!text) return { success: false, error: "text required for PTY send" };
6164
6540
  await adapter.sendMessage(text);
6165
6541
  return _logSendSuccess(`${transport}-adapter`, adapter.cliType);
6166
6542
  } catch (e) {
@@ -6168,6 +6544,8 @@ async function handleSendChat(h, args) {
6168
6544
  }
6169
6545
  }
6170
6546
  }
6547
+ assertTextOnlyInput(provider, input);
6548
+ if (!text) return { success: false, error: "text required" };
6171
6549
  if (isExtensionTransport(transport)) {
6172
6550
  _log(`Extension: ${provider?.type || "unknown_extension"}`);
6173
6551
  try {
@@ -6783,6 +7161,8 @@ var init_chat_commands = __esm({
6783
7161
  "../../oss/packages/daemon-core/src/commands/chat-commands.ts"() {
6784
7162
  "use strict";
6785
7163
  init_contracts();
7164
+ init_provider_input_support();
7165
+ init_read_chat_contract();
6786
7166
  init_chat_history();
6787
7167
  init_logger();
6788
7168
  init_debug_trace();
@@ -7357,14 +7737,14 @@ function normalizeProviderScriptArgs(args, scriptName) {
7357
7737
  }
7358
7738
  function buildControlScriptResult(scriptName, payload) {
7359
7739
  if (!payload || typeof payload !== "object") return {};
7360
- if (Array.isArray(payload.options) || Array.isArray(payload.models) || Array.isArray(payload.modes)) {
7740
+ if (Array.isArray(payload.options)) {
7361
7741
  return { controlResult: normalizeControlListResult(payload) };
7362
7742
  }
7363
7743
  const looksLikeValueMutation = /^set|^change/i.test(scriptName) || payload.currentValue !== void 0 || payload.value !== void 0;
7364
7744
  if (looksLikeValueMutation) {
7365
7745
  return { controlResult: normalizeControlSetResult(payload) };
7366
7746
  }
7367
- if (payload.ok !== void 0 || payload.success !== void 0 || Array.isArray(payload.effects)) {
7747
+ if (payload.ok !== void 0 || Array.isArray(payload.effects) || typeof payload.error === "string") {
7368
7748
  return { controlResult: normalizeControlInvokeResult(payload) };
7369
7749
  }
7370
7750
  return {};
@@ -9772,6 +10152,7 @@ var init_provider_cli_adapter = __esm({
9772
10152
  init_pty_transport();
9773
10153
  init_provider_cli_shared();
9774
10154
  init_chat_message_normalization();
10155
+ init_read_chat_contract();
9775
10156
  init_provider_cli_parse();
9776
10157
  init_provider_cli_config();
9777
10158
  init_provider_cli_runtime();
@@ -10917,6 +11298,9 @@ var init_provider_cli_adapter = __esm({
10917
11298
  runtimeSettings: this.runtimeSettings
10918
11299
  });
10919
11300
  const parsed = this.cliScripts.parseOutput(input);
11301
+ if (parsed && typeof parsed === "object") {
11302
+ Object.assign(parsed, validateReadChatResultPayload(parsed, `${this.cliType} parseOutput`));
11303
+ }
10920
11304
  const refinedStatus = this.refineDetectedStatus(typeof parsed?.status === "string" ? parsed.status : null, input.recentBuffer, input.screenText);
10921
11305
  if (parsed && refinedStatus && parsed.status !== refinedStatus) {
10922
11306
  parsed.status = refinedStatus;
@@ -11553,6 +11937,7 @@ var init_cli_provider_instance = __esm({
11553
11937
  fs5 = __toESM(require("fs"));
11554
11938
  import_node_module = require("module");
11555
11939
  init_contracts();
11940
+ init_provider_input_support();
11556
11941
  init_provider_cli_adapter();
11557
11942
  init_status_monitor();
11558
11943
  init_chat_history();
@@ -11813,6 +12198,7 @@ var init_cli_provider_instance = __esm({
11813
12198
  onEvent(event, data) {
11814
12199
  if (event === "send_message") {
11815
12200
  const input = normalizeInputEnvelope(data);
12201
+ assertTextOnlyInput(this.provider, input);
11816
12202
  if (input.textFallback) {
11817
12203
  void this.adapter.sendMessage(input.textFallback).catch((e) => {
11818
12204
  LOG.warn("CLI", `[${this.type}] send_message failed: ${e?.message || e}`);
@@ -12368,7 +12754,7 @@ __export(util_exports, {
12368
12754
  getSizableOrigin: () => getSizableOrigin,
12369
12755
  hexToUint8Array: () => hexToUint8Array,
12370
12756
  isObject: () => isObject,
12371
- isPlainObject: () => isPlainObject3,
12757
+ isPlainObject: () => isPlainObject4,
12372
12758
  issue: () => issue,
12373
12759
  joinValues: () => joinValues,
12374
12760
  jsonStringifyReplacer: () => jsonStringifyReplacer,
@@ -12504,10 +12890,10 @@ function mergeDefs(...defs) {
12504
12890
  function cloneDef(schema) {
12505
12891
  return mergeDefs(schema._zod.def);
12506
12892
  }
12507
- function getElementAtPath(obj, path30) {
12508
- if (!path30)
12893
+ function getElementAtPath(obj, path29) {
12894
+ if (!path29)
12509
12895
  return obj;
12510
- return path30.reduce((acc, key) => acc?.[key], obj);
12896
+ return path29.reduce((acc, key) => acc?.[key], obj);
12511
12897
  }
12512
12898
  function promiseAllObject(promisesObj) {
12513
12899
  const keys = Object.keys(promisesObj);
@@ -12537,7 +12923,7 @@ function slugify(input) {
12537
12923
  function isObject(data) {
12538
12924
  return typeof data === "object" && data !== null && !Array.isArray(data);
12539
12925
  }
12540
- function isPlainObject3(o) {
12926
+ function isPlainObject4(o) {
12541
12927
  if (isObject(o) === false)
12542
12928
  return false;
12543
12929
  const ctor = o.constructor;
@@ -12554,7 +12940,7 @@ function isPlainObject3(o) {
12554
12940
  return true;
12555
12941
  }
12556
12942
  function shallowClone(o) {
12557
- if (isPlainObject3(o))
12943
+ if (isPlainObject4(o))
12558
12944
  return { ...o };
12559
12945
  if (Array.isArray(o))
12560
12946
  return [...o];
@@ -12690,7 +13076,7 @@ function omit(schema, mask2) {
12690
13076
  return clone(schema, def);
12691
13077
  }
12692
13078
  function extend(schema, shape) {
12693
- if (!isPlainObject3(shape)) {
13079
+ if (!isPlainObject4(shape)) {
12694
13080
  throw new Error("Invalid input to extend: expected a plain object");
12695
13081
  }
12696
13082
  const checks = schema._zod.def.checks;
@@ -12713,7 +13099,7 @@ function extend(schema, shape) {
12713
13099
  return clone(schema, def);
12714
13100
  }
12715
13101
  function safeExtend(schema, shape) {
12716
- if (!isPlainObject3(shape)) {
13102
+ if (!isPlainObject4(shape)) {
12717
13103
  throw new Error("Invalid input to safeExtend: expected a plain object");
12718
13104
  }
12719
13105
  const def = mergeDefs(schema._zod.def, {
@@ -12819,11 +13205,11 @@ function aborted(x, startIndex = 0) {
12819
13205
  }
12820
13206
  return false;
12821
13207
  }
12822
- function prefixIssues(path30, issues) {
13208
+ function prefixIssues(path29, issues) {
12823
13209
  return issues.map((iss) => {
12824
13210
  var _a2;
12825
13211
  (_a2 = iss).path ?? (_a2.path = []);
12826
- iss.path.unshift(path30);
13212
+ iss.path.unshift(path29);
12827
13213
  return iss;
12828
13214
  });
12829
13215
  }
@@ -13066,7 +13452,7 @@ function formatError(error48, mapper = (issue2) => issue2.message) {
13066
13452
  }
13067
13453
  function treeifyError(error48, mapper = (issue2) => issue2.message) {
13068
13454
  const result = { errors: [] };
13069
- const processError = (error49, path30 = []) => {
13455
+ const processError = (error49, path29 = []) => {
13070
13456
  var _a2, _b;
13071
13457
  for (const issue2 of error49.issues) {
13072
13458
  if (issue2.code === "invalid_union" && issue2.errors.length) {
@@ -13076,7 +13462,7 @@ function treeifyError(error48, mapper = (issue2) => issue2.message) {
13076
13462
  } else if (issue2.code === "invalid_element") {
13077
13463
  processError({ issues: issue2.issues }, issue2.path);
13078
13464
  } else {
13079
- const fullpath = [...path30, ...issue2.path];
13465
+ const fullpath = [...path29, ...issue2.path];
13080
13466
  if (fullpath.length === 0) {
13081
13467
  result.errors.push(mapper(issue2));
13082
13468
  continue;
@@ -13108,8 +13494,8 @@ function treeifyError(error48, mapper = (issue2) => issue2.message) {
13108
13494
  }
13109
13495
  function toDotPath(_path) {
13110
13496
  const segs = [];
13111
- const path30 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
13112
- for (const seg of path30) {
13497
+ const path29 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
13498
+ for (const seg of path29) {
13113
13499
  if (typeof seg === "number")
13114
13500
  segs.push(`[${seg}]`);
13115
13501
  else if (typeof seg === "symbol")
@@ -14196,7 +14582,7 @@ function mergeValues(a, b) {
14196
14582
  if (a instanceof Date && b instanceof Date && +a === +b) {
14197
14583
  return { valid: true, data: a };
14198
14584
  }
14199
- if (isPlainObject3(a) && isPlainObject3(b)) {
14585
+ if (isPlainObject4(a) && isPlainObject4(b)) {
14200
14586
  const bKeys = Object.keys(b);
14201
14587
  const sharedKeys = Object.keys(a).filter((key) => bKeys.indexOf(key) !== -1);
14202
14588
  const newObj = { ...a, ...b };
@@ -15391,7 +15777,7 @@ var init_schemas = __esm({
15391
15777
  $ZodType.init(inst, def);
15392
15778
  inst._zod.parse = (payload, ctx) => {
15393
15779
  const input = payload.value;
15394
- if (!isPlainObject3(input)) {
15780
+ if (!isPlainObject4(input)) {
15395
15781
  payload.issues.push({
15396
15782
  expected: "record",
15397
15783
  code: "invalid_type",
@@ -25873,13 +26259,13 @@ function resolveRef(ref, ctx) {
25873
26259
  if (!ref.startsWith("#")) {
25874
26260
  throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
25875
26261
  }
25876
- const path30 = ref.slice(1).split("/").filter(Boolean);
25877
- if (path30.length === 0) {
26262
+ const path29 = ref.slice(1).split("/").filter(Boolean);
26263
+ if (path29.length === 0) {
25878
26264
  return ctx.rootSchema;
25879
26265
  }
25880
26266
  const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
25881
- if (path30[0] === defsKey) {
25882
- const key = path30[1];
26267
+ if (path29[0] === defsKey) {
26268
+ const key = path29[1];
25883
26269
  if (!key || !ctx.defs[key]) {
25884
26270
  throw new Error(`Reference not found: ${ref}`);
25885
26271
  }
@@ -28561,25 +28947,6 @@ function getPromptCapabilityFlags(agentCapabilities) {
28561
28947
  embeddedContext: prompt2.embeddedContext === true
28562
28948
  };
28563
28949
  }
28564
- function getResourceNameFromUri(uri, fallback2) {
28565
- try {
28566
- if (uri.startsWith("file://")) {
28567
- return path12.basename(new URL(uri).pathname) || fallback2;
28568
- }
28569
- return path12.basename(uri) || fallback2;
28570
- } catch {
28571
- return fallback2;
28572
- }
28573
- }
28574
- function inputPartToResourceLink(part, fallbackName) {
28575
- if (!part.uri) return null;
28576
- return {
28577
- type: "resource_link",
28578
- uri: part.uri,
28579
- name: getResourceNameFromUri(part.uri, fallbackName),
28580
- ...part.mimeType ? { mimeType: part.mimeType } : {}
28581
- };
28582
- }
28583
28950
  function appendPromptText(promptParts, text) {
28584
28951
  const normalized = typeof text === "string" ? text.trim() : "";
28585
28952
  if (!normalized) return;
@@ -28596,67 +28963,72 @@ function buildAcpPromptParts(input, agentCapabilities) {
28596
28963
  continue;
28597
28964
  }
28598
28965
  if (part.type === "image") {
28599
- if (caps.image && part.data) {
28600
- promptParts.push({
28601
- type: "image",
28602
- data: part.data,
28603
- mimeType: part.mimeType,
28604
- ...part.uri ? { uri: part.uri } : {}
28605
- });
28606
- continue;
28966
+ if (!caps.image) {
28967
+ throw new Error("ACP agent does not support input type: image");
28968
+ }
28969
+ if (!part.data) {
28970
+ throw new Error("ACP image input requires inline image data");
28607
28971
  }
28608
- const fallback2 = inputPartToResourceLink(part, "image");
28609
- if (fallback2) promptParts.push(fallback2);
28610
- appendPromptText(promptParts, part.alt || (!part.uri ? `Attached image (${part.mimeType})` : void 0));
28972
+ promptParts.push({
28973
+ type: "image",
28974
+ data: part.data,
28975
+ mimeType: part.mimeType,
28976
+ ...part.uri ? { uri: part.uri } : {}
28977
+ });
28611
28978
  continue;
28612
28979
  }
28613
28980
  if (part.type === "audio") {
28614
- if (caps.audio && part.data) {
28615
- promptParts.push({
28616
- type: "audio",
28617
- data: part.data,
28618
- mimeType: part.mimeType
28619
- });
28620
- continue;
28981
+ if (!caps.audio) {
28982
+ throw new Error("ACP agent does not support input type: audio");
28983
+ }
28984
+ if (!part.data) {
28985
+ throw new Error("ACP audio input requires inline audio data");
28621
28986
  }
28622
- const fallback2 = inputPartToResourceLink(part, "audio");
28623
- if (fallback2) promptParts.push(fallback2);
28624
- appendPromptText(promptParts, part.transcript || (!part.uri ? `Attached audio (${part.mimeType})` : void 0));
28987
+ promptParts.push({
28988
+ type: "audio",
28989
+ data: part.data,
28990
+ mimeType: part.mimeType
28991
+ });
28625
28992
  continue;
28626
28993
  }
28627
28994
  if (part.type === "resource") {
28628
- if (caps.embeddedContext && (part.text || part.data)) {
28995
+ if (!caps.embeddedContext) {
28996
+ throw new Error("ACP agent does not support input type: resource");
28997
+ }
28998
+ if (part.text) {
28629
28999
  promptParts.push({
28630
29000
  type: "resource",
28631
- resource: part.text ? { uri: part.uri, text: part.text, mimeType: part.mimeType ?? null } : { uri: part.uri, blob: part.data || "", mimeType: part.mimeType ?? null }
29001
+ resource: { uri: part.uri, text: part.text, mimeType: part.mimeType ?? null }
28632
29002
  });
28633
29003
  continue;
28634
29004
  }
28635
- const fallback2 = inputPartToResourceLink(part, part.name || "resource");
28636
- if (fallback2) promptParts.push(fallback2);
28637
- appendPromptText(promptParts, part.text || (!part.uri && part.name ? part.name : void 0));
28638
- continue;
29005
+ if (part.data) {
29006
+ promptParts.push({
29007
+ type: "resource",
29008
+ resource: { uri: part.uri, blob: part.data, mimeType: part.mimeType ?? null }
29009
+ });
29010
+ continue;
29011
+ }
29012
+ throw new Error("ACP resource input requires embedded text or binary data");
28639
29013
  }
28640
29014
  if (part.type === "video") {
28641
- const fallback2 = inputPartToResourceLink(part, "video");
28642
- if (fallback2) promptParts.push(fallback2);
28643
- appendPromptText(promptParts, !part.uri ? `Attached video (${part.mimeType})` : void 0);
29015
+ throw new Error("ACP agent does not support input type: video");
28644
29016
  }
28645
29017
  }
28646
29018
  if (!promptParts.some((part) => part.type === "text") && input.textFallback) {
28647
- promptParts.unshift({ type: "text", text: input.textFallback });
29019
+ appendPromptText(promptParts, input.textFallback);
28648
29020
  }
28649
29021
  return promptParts;
28650
29022
  }
28651
- var path12, import_stream, import_child_process5, AcpProviderInstance;
29023
+ var import_stream, import_child_process5, AcpProviderInstance;
28652
29024
  var init_acp_provider_instance = __esm({
28653
29025
  "../../oss/packages/daemon-core/src/providers/acp-provider-instance.ts"() {
28654
29026
  "use strict";
28655
- path12 = __toESM(require("path"));
28656
29027
  import_stream = require("stream");
28657
29028
  import_child_process5 = require("child_process");
28658
29029
  init_acp();
28659
29030
  init_contracts();
29031
+ init_provider_input_support();
28660
29032
  init_status_monitor();
28661
29033
  init_summary_metadata();
28662
29034
  init_chat_message_normalization();
@@ -28692,6 +29064,7 @@ var init_acp_provider_instance = __esm({
28692
29064
  activeToolCalls = [];
28693
29065
  stopReason = null;
28694
29066
  partialContent = "";
29067
+ partialThoughtContent = "";
28695
29068
  /** Rich content blocks accumulated during streaming */
28696
29069
  partialBlocks = [];
28697
29070
  /** Tool calls collected during current turn */
@@ -28737,6 +29110,10 @@ var init_acp_provider_instance = __esm({
28737
29110
  content
28738
29111
  });
28739
29112
  }));
29113
+ if (this.currentStatus === "generating") {
29114
+ const partialThoughtMessage = this.buildPartialThoughtMessage(Date.now());
29115
+ if (partialThoughtMessage) recentMessages.push(partialThoughtMessage);
29116
+ }
28740
29117
  if (this.currentStatus === "generating" && (this.partialContent || this.partialBlocks.length > 0)) {
28741
29118
  const blocks = this.buildPartialBlocks();
28742
29119
  if (blocks.length > 0) {
@@ -28783,6 +29160,7 @@ var init_acp_provider_instance = __esm({
28783
29160
  onEvent(event, data) {
28784
29161
  if (event === "send_message") {
28785
29162
  const input = normalizeInputEnvelope(data);
29163
+ assertProviderSupportsDeclaredInput(this.provider, input);
28786
29164
  const promptParts = buildAcpPromptParts(input, this.agentCapabilities);
28787
29165
  this.sendPrompt(input.textFallback, promptParts.length > 0 ? promptParts : void 0).catch(
28788
29166
  (e) => this.log.warn(`[${this.type}] sendPrompt error: ${e?.message}`)
@@ -29295,6 +29673,7 @@ var init_acp_provider_instance = __esm({
29295
29673
  }));
29296
29674
  this.currentStatus = "generating";
29297
29675
  this.partialContent = "";
29676
+ this.partialThoughtContent = "";
29298
29677
  this.partialBlocks = [];
29299
29678
  this.turnToolCalls = [];
29300
29679
  this.detectStatusTransition();
@@ -29377,7 +29756,14 @@ var init_acp_provider_instance = __esm({
29377
29756
  this.currentStatus = "generating";
29378
29757
  break;
29379
29758
  }
29380
- case "agent_thought_chunk":
29759
+ case "agent_thought_chunk": {
29760
+ const content = update.content;
29761
+ if (content?.type === "text" && typeof content.text === "string") {
29762
+ this.partialThoughtContent += content.text;
29763
+ }
29764
+ this.currentStatus = "generating";
29765
+ break;
29766
+ }
29381
29767
  case "user_message_chunk": {
29382
29768
  break;
29383
29769
  }
@@ -29532,8 +29918,82 @@ var init_acp_provider_instance = __esm({
29532
29918
  blocks.push(...this.partialBlocks);
29533
29919
  return blocks;
29534
29920
  }
29921
+ buildPartialThoughtMessage(timestamp = Date.now()) {
29922
+ const content = this.partialThoughtContent.trim();
29923
+ if (!content) return null;
29924
+ return buildThoughtChatMessage({
29925
+ content,
29926
+ timestamp,
29927
+ meta: {
29928
+ label: "Thought",
29929
+ isRunning: this.currentStatus === "generating"
29930
+ }
29931
+ });
29932
+ }
29933
+ buildToolCallBubbleKind(toolCall) {
29934
+ if (toolCall.kind === "think") return "thought";
29935
+ if (toolCall.kind === "execute") return "terminal";
29936
+ if (Array.isArray(toolCall.content) && toolCall.content.some((entry) => entry?.type === "terminal")) return "terminal";
29937
+ return "tool";
29938
+ }
29939
+ summarizeToolCallBubbleContent(toolCall) {
29940
+ const rawOutput = typeof toolCall.rawOutput === "string" ? toolCall.rawOutput.trim() : toolCall.rawOutput != null ? JSON.stringify(toolCall.rawOutput) : "";
29941
+ if (rawOutput) return rawOutput;
29942
+ const contentText = Array.isArray(toolCall.content) ? toolCall.content.map((entry) => {
29943
+ if (!entry || typeof entry !== "object") return "";
29944
+ if (entry.type === "content") return flattenContent([entry.content]).trim();
29945
+ if (entry.type === "diff") return `${entry.path}
29946
+ ${entry.newText || ""}`.trim();
29947
+ if (entry.type === "terminal") return `Terminal: ${entry.terminalId || ""}`.trim();
29948
+ return "";
29949
+ }).filter(Boolean).join("\n\n").trim() : "";
29950
+ if (contentText) return contentText;
29951
+ const rawInput = typeof toolCall.rawInput === "string" ? toolCall.rawInput.trim() : toolCall.rawInput != null ? JSON.stringify(toolCall.rawInput) : "";
29952
+ if (rawInput) {
29953
+ return toolCall.title ? `${toolCall.title}
29954
+ ${rawInput}` : rawInput;
29955
+ }
29956
+ return toolCall.title || "";
29957
+ }
29958
+ buildTurnToolCallMessages(timestamp = Date.now()) {
29959
+ return this.turnToolCalls.map((toolCall) => {
29960
+ const content = this.summarizeToolCallBubbleContent(toolCall);
29961
+ if (!content) return null;
29962
+ const isRunning = toolCall.status === "pending" || toolCall.status === "in_progress";
29963
+ const label = toolCall.title || void 0;
29964
+ const kind = this.buildToolCallBubbleKind(toolCall);
29965
+ if (kind === "thought") {
29966
+ return buildThoughtChatMessage({
29967
+ content,
29968
+ timestamp,
29969
+ meta: { label: label || "Thought", isRunning }
29970
+ });
29971
+ }
29972
+ if (kind === "terminal") {
29973
+ return buildTerminalChatMessage({
29974
+ content,
29975
+ timestamp,
29976
+ meta: { label: label || "Ran command", isRunning }
29977
+ });
29978
+ }
29979
+ return buildToolChatMessage({
29980
+ content,
29981
+ timestamp,
29982
+ meta: { label: label || "Tool call", isRunning }
29983
+ });
29984
+ }).filter(Boolean);
29985
+ }
29535
29986
  /** Finalize streaming content into an assistant message */
29536
29987
  finalizeAssistantMessage() {
29988
+ const timestamp = Date.now();
29989
+ const thoughtMessage = this.buildPartialThoughtMessage(timestamp);
29990
+ if (thoughtMessage) {
29991
+ this.messages.push(thoughtMessage);
29992
+ }
29993
+ const toolCallMessages = this.buildTurnToolCallMessages(timestamp);
29994
+ if (toolCallMessages.length > 0) {
29995
+ this.messages.push(...toolCallMessages);
29996
+ }
29537
29997
  const blocks = this.buildPartialBlocks();
29538
29998
  const finalBlocks = blocks.map((b) => {
29539
29999
  if (b.type === "text" && b.text.endsWith("...")) {
@@ -29549,6 +30009,7 @@ var init_acp_provider_instance = __esm({
29549
30009
  }));
29550
30010
  }
29551
30011
  this.partialContent = "";
30012
+ this.partialThoughtContent = "";
29552
30013
  this.partialBlocks = [];
29553
30014
  this.turnToolCalls = [];
29554
30015
  }
@@ -29759,12 +30220,12 @@ function resolveCliSessionBinding(provider, normalizedType, cliArgs, requestedRe
29759
30220
  launchMode: "new"
29760
30221
  };
29761
30222
  }
29762
- var os14, path13, crypto4, chalkModule, chalkApi, DaemonCliManager;
30223
+ var os14, path12, crypto4, chalkModule, chalkApi, DaemonCliManager;
29763
30224
  var init_cli_manager = __esm({
29764
30225
  "../../oss/packages/daemon-core/src/commands/cli-manager.ts"() {
29765
30226
  "use strict";
29766
30227
  os14 = __toESM(require("os"));
29767
- path13 = __toESM(require("path"));
30228
+ path12 = __toESM(require("path"));
29768
30229
  crypto4 = __toESM(require("crypto"));
29769
30230
  init_source();
29770
30231
  init_provider_cli_adapter();
@@ -29778,6 +30239,7 @@ var init_cli_manager = __esm({
29778
30239
  init_cli_provider_instance();
29779
30240
  init_acp_provider_instance();
29780
30241
  init_contracts();
30242
+ init_provider_input_support();
29781
30243
  init_logger();
29782
30244
  init_hosted_runtime_restore();
29783
30245
  chalkModule = source_default;
@@ -29924,7 +30386,7 @@ var init_cli_manager = __esm({
29924
30386
  async startSession(cliType, workingDir, cliArgs, initialModel, options) {
29925
30387
  const trimmed = (workingDir || "").trim();
29926
30388
  if (!trimmed) throw new Error("working directory required");
29927
- const resolvedDir = trimmed.startsWith("~") ? trimmed.replace(/^~/, os14.homedir()) : path13.resolve(trimmed);
30389
+ const resolvedDir = trimmed.startsWith("~") ? trimmed.replace(/^~/, os14.homedir()) : path12.resolve(trimmed);
29928
30390
  const normalizedType = this.providerLoader.resolveAlias(cliType);
29929
30391
  const provider = this.providerLoader.getByAlias(cliType);
29930
30392
  const key = crypto4.randomUUID();
@@ -30383,6 +30845,12 @@ Run 'adhdev doctor' for detailed diagnostics.`
30383
30845
  const { adapter, key } = found;
30384
30846
  if (action === "send_chat") {
30385
30847
  const input = normalizeInputEnvelope(args?.input ? { input: args.input } : args);
30848
+ const provider = this.providerLoader.resolve(agentType) || this.providerLoader.getMeta(agentType);
30849
+ if (provider?.category === "acp") {
30850
+ assertProviderSupportsDeclaredInput(provider, input);
30851
+ } else {
30852
+ assertTextOnlyInput(provider, input);
30853
+ }
30386
30854
  const message = input.textFallback;
30387
30855
  if (!message) throw new Error("message required for send_chat");
30388
30856
  await adapter.sendMessage(message);
@@ -30507,7 +30975,7 @@ var init_readdirp = __esm({
30507
30975
  this._directoryFilter = normalizeFilter(opts.directoryFilter);
30508
30976
  const statMethod = opts.lstat ? import_promises.lstat : import_promises.stat;
30509
30977
  if (wantBigintFsStats) {
30510
- this._stat = (path30) => statMethod(path30, { bigint: true });
30978
+ this._stat = (path29) => statMethod(path29, { bigint: true });
30511
30979
  } else {
30512
30980
  this._stat = statMethod;
30513
30981
  }
@@ -30532,8 +31000,8 @@ var init_readdirp = __esm({
30532
31000
  const par = this.parent;
30533
31001
  const fil = par && par.files;
30534
31002
  if (fil && fil.length > 0) {
30535
- const { path: path30, depth } = par;
30536
- const slice = fil.splice(0, batch).map((dirent) => this._formatEntry(dirent, path30));
31003
+ const { path: path29, depth } = par;
31004
+ const slice = fil.splice(0, batch).map((dirent) => this._formatEntry(dirent, path29));
30537
31005
  const awaited = await Promise.all(slice);
30538
31006
  for (const entry of awaited) {
30539
31007
  if (!entry)
@@ -30573,21 +31041,21 @@ var init_readdirp = __esm({
30573
31041
  this.reading = false;
30574
31042
  }
30575
31043
  }
30576
- async _exploreDir(path30, depth) {
31044
+ async _exploreDir(path29, depth) {
30577
31045
  let files;
30578
31046
  try {
30579
- files = await (0, import_promises.readdir)(path30, this._rdOptions);
31047
+ files = await (0, import_promises.readdir)(path29, this._rdOptions);
30580
31048
  } catch (error48) {
30581
31049
  this._onError(error48);
30582
31050
  }
30583
- return { files, depth, path: path30 };
31051
+ return { files, depth, path: path29 };
30584
31052
  }
30585
- async _formatEntry(dirent, path30) {
31053
+ async _formatEntry(dirent, path29) {
30586
31054
  let entry;
30587
- const basename9 = this._isDirent ? dirent.name : dirent;
31055
+ const basename8 = this._isDirent ? dirent.name : dirent;
30588
31056
  try {
30589
- const fullPath = (0, import_node_path.resolve)((0, import_node_path.join)(path30, basename9));
30590
- entry = { path: (0, import_node_path.relative)(this._root, fullPath), fullPath, basename: basename9 };
31057
+ const fullPath = (0, import_node_path.resolve)((0, import_node_path.join)(path29, basename8));
31058
+ entry = { path: (0, import_node_path.relative)(this._root, fullPath), fullPath, basename: basename8 };
30591
31059
  entry[this._statsProp] = this._isDirent ? dirent : await this._stat(fullPath);
30592
31060
  } catch (err) {
30593
31061
  this._onError(err);
@@ -30643,16 +31111,16 @@ var init_readdirp = __esm({
30643
31111
  });
30644
31112
 
30645
31113
  // ../../oss/packages/daemon-core/node_modules/chokidar/handler.js
30646
- function createFsWatchInstance(path30, options, listener, errHandler, emitRaw) {
31114
+ function createFsWatchInstance(path29, options, listener, errHandler, emitRaw) {
30647
31115
  const handleEvent = (rawEvent, evPath) => {
30648
- listener(path30);
30649
- emitRaw(rawEvent, evPath, { watchedPath: path30 });
30650
- if (evPath && path30 !== evPath) {
30651
- fsWatchBroadcast(sp.resolve(path30, evPath), KEY_LISTENERS, sp.join(path30, evPath));
31116
+ listener(path29);
31117
+ emitRaw(rawEvent, evPath, { watchedPath: path29 });
31118
+ if (evPath && path29 !== evPath) {
31119
+ fsWatchBroadcast(sp.resolve(path29, evPath), KEY_LISTENERS, sp.join(path29, evPath));
30652
31120
  }
30653
31121
  };
30654
31122
  try {
30655
- return (0, import_node_fs.watch)(path30, {
31123
+ return (0, import_node_fs.watch)(path29, {
30656
31124
  persistent: options.persistent
30657
31125
  }, handleEvent);
30658
31126
  } catch (error48) {
@@ -31001,12 +31469,12 @@ var init_handler2 = __esm({
31001
31469
  listener(val1, val2, val3);
31002
31470
  });
31003
31471
  };
31004
- setFsWatchListener = (path30, fullPath, options, handlers) => {
31472
+ setFsWatchListener = (path29, fullPath, options, handlers) => {
31005
31473
  const { listener, errHandler, rawEmitter } = handlers;
31006
31474
  let cont = FsWatchInstances.get(fullPath);
31007
31475
  let watcher;
31008
31476
  if (!options.persistent) {
31009
- watcher = createFsWatchInstance(path30, options, listener, errHandler, rawEmitter);
31477
+ watcher = createFsWatchInstance(path29, options, listener, errHandler, rawEmitter);
31010
31478
  if (!watcher)
31011
31479
  return;
31012
31480
  return watcher.close.bind(watcher);
@@ -31017,7 +31485,7 @@ var init_handler2 = __esm({
31017
31485
  addAndConvert(cont, KEY_RAW, rawEmitter);
31018
31486
  } else {
31019
31487
  watcher = createFsWatchInstance(
31020
- path30,
31488
+ path29,
31021
31489
  options,
31022
31490
  fsWatchBroadcast.bind(null, fullPath, KEY_LISTENERS),
31023
31491
  errHandler,
@@ -31032,7 +31500,7 @@ var init_handler2 = __esm({
31032
31500
  cont.watcherUnusable = true;
31033
31501
  if (isWindows && error48.code === "EPERM") {
31034
31502
  try {
31035
- const fd = await (0, import_promises2.open)(path30, "r");
31503
+ const fd = await (0, import_promises2.open)(path29, "r");
31036
31504
  await fd.close();
31037
31505
  broadcastErr(error48);
31038
31506
  } catch (err) {
@@ -31063,7 +31531,7 @@ var init_handler2 = __esm({
31063
31531
  };
31064
31532
  };
31065
31533
  FsWatchFileInstances = /* @__PURE__ */ new Map();
31066
- setFsWatchFileListener = (path30, fullPath, options, handlers) => {
31534
+ setFsWatchFileListener = (path29, fullPath, options, handlers) => {
31067
31535
  const { listener, rawEmitter } = handlers;
31068
31536
  let cont = FsWatchFileInstances.get(fullPath);
31069
31537
  const copts = cont && cont.options;
@@ -31085,7 +31553,7 @@ var init_handler2 = __esm({
31085
31553
  });
31086
31554
  const currmtime = curr.mtimeMs;
31087
31555
  if (curr.size !== prev.size || currmtime > prev.mtimeMs || currmtime === 0) {
31088
- foreach(cont.listeners, (listener2) => listener2(path30, curr));
31556
+ foreach(cont.listeners, (listener2) => listener2(path29, curr));
31089
31557
  }
31090
31558
  })
31091
31559
  };
@@ -31115,13 +31583,13 @@ var init_handler2 = __esm({
31115
31583
  * @param listener on fs change
31116
31584
  * @returns closer for the watcher instance
31117
31585
  */
31118
- _watchWithNodeFs(path30, listener) {
31586
+ _watchWithNodeFs(path29, listener) {
31119
31587
  const opts = this.fsw.options;
31120
- const directory = sp.dirname(path30);
31121
- const basename9 = sp.basename(path30);
31588
+ const directory = sp.dirname(path29);
31589
+ const basename8 = sp.basename(path29);
31122
31590
  const parent = this.fsw._getWatchedDir(directory);
31123
- parent.add(basename9);
31124
- const absolutePath = sp.resolve(path30);
31591
+ parent.add(basename8);
31592
+ const absolutePath = sp.resolve(path29);
31125
31593
  const options = {
31126
31594
  persistent: opts.persistent
31127
31595
  };
@@ -31130,13 +31598,13 @@ var init_handler2 = __esm({
31130
31598
  let closer;
31131
31599
  if (opts.usePolling) {
31132
31600
  const enableBin = opts.interval !== opts.binaryInterval;
31133
- options.interval = enableBin && isBinaryPath(basename9) ? opts.binaryInterval : opts.interval;
31134
- closer = setFsWatchFileListener(path30, absolutePath, options, {
31601
+ options.interval = enableBin && isBinaryPath(basename8) ? opts.binaryInterval : opts.interval;
31602
+ closer = setFsWatchFileListener(path29, absolutePath, options, {
31135
31603
  listener,
31136
31604
  rawEmitter: this.fsw._emitRaw
31137
31605
  });
31138
31606
  } else {
31139
- closer = setFsWatchListener(path30, absolutePath, options, {
31607
+ closer = setFsWatchListener(path29, absolutePath, options, {
31140
31608
  listener,
31141
31609
  errHandler: this._boundHandleError,
31142
31610
  rawEmitter: this.fsw._emitRaw
@@ -31153,12 +31621,12 @@ var init_handler2 = __esm({
31153
31621
  return;
31154
31622
  }
31155
31623
  const dirname9 = sp.dirname(file2);
31156
- const basename9 = sp.basename(file2);
31624
+ const basename8 = sp.basename(file2);
31157
31625
  const parent = this.fsw._getWatchedDir(dirname9);
31158
31626
  let prevStats = stats;
31159
- if (parent.has(basename9))
31627
+ if (parent.has(basename8))
31160
31628
  return;
31161
- const listener = async (path30, newStats) => {
31629
+ const listener = async (path29, newStats) => {
31162
31630
  if (!this.fsw._throttle(THROTTLE_MODE_WATCH, file2, 5))
31163
31631
  return;
31164
31632
  if (!newStats || newStats.mtimeMs === 0) {
@@ -31172,18 +31640,18 @@ var init_handler2 = __esm({
31172
31640
  this.fsw._emit(EV.CHANGE, file2, newStats2);
31173
31641
  }
31174
31642
  if ((isMacos || isLinux || isFreeBSD) && prevStats.ino !== newStats2.ino) {
31175
- this.fsw._closeFile(path30);
31643
+ this.fsw._closeFile(path29);
31176
31644
  prevStats = newStats2;
31177
31645
  const closer2 = this._watchWithNodeFs(file2, listener);
31178
31646
  if (closer2)
31179
- this.fsw._addPathCloser(path30, closer2);
31647
+ this.fsw._addPathCloser(path29, closer2);
31180
31648
  } else {
31181
31649
  prevStats = newStats2;
31182
31650
  }
31183
31651
  } catch (error48) {
31184
- this.fsw._remove(dirname9, basename9);
31652
+ this.fsw._remove(dirname9, basename8);
31185
31653
  }
31186
- } else if (parent.has(basename9)) {
31654
+ } else if (parent.has(basename8)) {
31187
31655
  const at = newStats.atimeMs;
31188
31656
  const mt = newStats.mtimeMs;
31189
31657
  if (!at || at <= mt || mt !== prevStats.mtimeMs) {
@@ -31208,7 +31676,7 @@ var init_handler2 = __esm({
31208
31676
  * @param item basename of this item
31209
31677
  * @returns true if no more processing is needed for this entry.
31210
31678
  */
31211
- async _handleSymlink(entry, directory, path30, item) {
31679
+ async _handleSymlink(entry, directory, path29, item) {
31212
31680
  if (this.fsw.closed) {
31213
31681
  return;
31214
31682
  }
@@ -31218,7 +31686,7 @@ var init_handler2 = __esm({
31218
31686
  this.fsw._incrReadyCount();
31219
31687
  let linkPath;
31220
31688
  try {
31221
- linkPath = await (0, import_promises2.realpath)(path30);
31689
+ linkPath = await (0, import_promises2.realpath)(path29);
31222
31690
  } catch (e) {
31223
31691
  this.fsw._emitReady();
31224
31692
  return true;
@@ -31228,12 +31696,12 @@ var init_handler2 = __esm({
31228
31696
  if (dir.has(item)) {
31229
31697
  if (this.fsw._symlinkPaths.get(full) !== linkPath) {
31230
31698
  this.fsw._symlinkPaths.set(full, linkPath);
31231
- this.fsw._emit(EV.CHANGE, path30, entry.stats);
31699
+ this.fsw._emit(EV.CHANGE, path29, entry.stats);
31232
31700
  }
31233
31701
  } else {
31234
31702
  dir.add(item);
31235
31703
  this.fsw._symlinkPaths.set(full, linkPath);
31236
- this.fsw._emit(EV.ADD, path30, entry.stats);
31704
+ this.fsw._emit(EV.ADD, path29, entry.stats);
31237
31705
  }
31238
31706
  this.fsw._emitReady();
31239
31707
  return true;
@@ -31263,9 +31731,9 @@ var init_handler2 = __esm({
31263
31731
  return;
31264
31732
  }
31265
31733
  const item = entry.path;
31266
- let path30 = sp.join(directory, item);
31734
+ let path29 = sp.join(directory, item);
31267
31735
  current.add(item);
31268
- if (entry.stats.isSymbolicLink() && await this._handleSymlink(entry, directory, path30, item)) {
31736
+ if (entry.stats.isSymbolicLink() && await this._handleSymlink(entry, directory, path29, item)) {
31269
31737
  return;
31270
31738
  }
31271
31739
  if (this.fsw.closed) {
@@ -31274,8 +31742,8 @@ var init_handler2 = __esm({
31274
31742
  }
31275
31743
  if (item === target || !target && !previous.has(item)) {
31276
31744
  this.fsw._incrReadyCount();
31277
- path30 = sp.join(dir, sp.relative(dir, path30));
31278
- this._addToNodeFs(path30, initialAdd, wh, depth + 1);
31745
+ path29 = sp.join(dir, sp.relative(dir, path29));
31746
+ this._addToNodeFs(path29, initialAdd, wh, depth + 1);
31279
31747
  }
31280
31748
  }).on(EV.ERROR, this._boundHandleError);
31281
31749
  return new Promise((resolve15, reject) => {
@@ -31344,13 +31812,13 @@ var init_handler2 = __esm({
31344
31812
  * @param depth Child path actually targeted for watch
31345
31813
  * @param target Child path actually targeted for watch
31346
31814
  */
31347
- async _addToNodeFs(path30, initialAdd, priorWh, depth, target) {
31815
+ async _addToNodeFs(path29, initialAdd, priorWh, depth, target) {
31348
31816
  const ready = this.fsw._emitReady;
31349
- if (this.fsw._isIgnored(path30) || this.fsw.closed) {
31817
+ if (this.fsw._isIgnored(path29) || this.fsw.closed) {
31350
31818
  ready();
31351
31819
  return false;
31352
31820
  }
31353
- const wh = this.fsw._getWatchHelpers(path30);
31821
+ const wh = this.fsw._getWatchHelpers(path29);
31354
31822
  if (priorWh) {
31355
31823
  wh.filterPath = (entry) => priorWh.filterPath(entry);
31356
31824
  wh.filterDir = (entry) => priorWh.filterDir(entry);
@@ -31366,8 +31834,8 @@ var init_handler2 = __esm({
31366
31834
  const follow = this.fsw.options.followSymlinks;
31367
31835
  let closer;
31368
31836
  if (stats.isDirectory()) {
31369
- const absPath = sp.resolve(path30);
31370
- const targetPath = follow ? await (0, import_promises2.realpath)(path30) : path30;
31837
+ const absPath = sp.resolve(path29);
31838
+ const targetPath = follow ? await (0, import_promises2.realpath)(path29) : path29;
31371
31839
  if (this.fsw.closed)
31372
31840
  return;
31373
31841
  closer = await this._handleDir(wh.watchPath, stats, initialAdd, depth, target, wh, targetPath);
@@ -31377,29 +31845,29 @@ var init_handler2 = __esm({
31377
31845
  this.fsw._symlinkPaths.set(absPath, targetPath);
31378
31846
  }
31379
31847
  } else if (stats.isSymbolicLink()) {
31380
- const targetPath = follow ? await (0, import_promises2.realpath)(path30) : path30;
31848
+ const targetPath = follow ? await (0, import_promises2.realpath)(path29) : path29;
31381
31849
  if (this.fsw.closed)
31382
31850
  return;
31383
31851
  const parent = sp.dirname(wh.watchPath);
31384
31852
  this.fsw._getWatchedDir(parent).add(wh.watchPath);
31385
31853
  this.fsw._emit(EV.ADD, wh.watchPath, stats);
31386
- closer = await this._handleDir(parent, stats, initialAdd, depth, path30, wh, targetPath);
31854
+ closer = await this._handleDir(parent, stats, initialAdd, depth, path29, wh, targetPath);
31387
31855
  if (this.fsw.closed)
31388
31856
  return;
31389
31857
  if (targetPath !== void 0) {
31390
- this.fsw._symlinkPaths.set(sp.resolve(path30), targetPath);
31858
+ this.fsw._symlinkPaths.set(sp.resolve(path29), targetPath);
31391
31859
  }
31392
31860
  } else {
31393
31861
  closer = this._handleFile(wh.watchPath, stats, initialAdd);
31394
31862
  }
31395
31863
  ready();
31396
31864
  if (closer)
31397
- this.fsw._addPathCloser(path30, closer);
31865
+ this.fsw._addPathCloser(path29, closer);
31398
31866
  return false;
31399
31867
  } catch (error48) {
31400
31868
  if (this.fsw._handleError(error48)) {
31401
31869
  ready();
31402
- return path30;
31870
+ return path29;
31403
31871
  }
31404
31872
  }
31405
31873
  }
@@ -31434,24 +31902,24 @@ function createPattern(matcher) {
31434
31902
  }
31435
31903
  return () => false;
31436
31904
  }
31437
- function normalizePath(path30) {
31438
- if (typeof path30 !== "string")
31905
+ function normalizePath(path29) {
31906
+ if (typeof path29 !== "string")
31439
31907
  throw new Error("string expected");
31440
- path30 = sp2.normalize(path30);
31441
- path30 = path30.replace(/\\/g, "/");
31908
+ path29 = sp2.normalize(path29);
31909
+ path29 = path29.replace(/\\/g, "/");
31442
31910
  let prepend = false;
31443
- if (path30.startsWith("//"))
31911
+ if (path29.startsWith("//"))
31444
31912
  prepend = true;
31445
- path30 = path30.replace(DOUBLE_SLASH_RE, "/");
31913
+ path29 = path29.replace(DOUBLE_SLASH_RE, "/");
31446
31914
  if (prepend)
31447
- path30 = "/" + path30;
31448
- return path30;
31915
+ path29 = "/" + path29;
31916
+ return path29;
31449
31917
  }
31450
31918
  function matchPatterns(patterns, testString, stats) {
31451
- const path30 = normalizePath(testString);
31919
+ const path29 = normalizePath(testString);
31452
31920
  for (let index = 0; index < patterns.length; index++) {
31453
31921
  const pattern = patterns[index];
31454
- if (pattern(path30, stats)) {
31922
+ if (pattern(path29, stats)) {
31455
31923
  return true;
31456
31924
  }
31457
31925
  }
@@ -31514,19 +31982,19 @@ var init_chokidar = __esm({
31514
31982
  }
31515
31983
  return str;
31516
31984
  };
31517
- normalizePathToUnix = (path30) => toUnix(sp2.normalize(toUnix(path30)));
31518
- normalizeIgnored = (cwd = "") => (path30) => {
31519
- if (typeof path30 === "string") {
31520
- return normalizePathToUnix(sp2.isAbsolute(path30) ? path30 : sp2.join(cwd, path30));
31985
+ normalizePathToUnix = (path29) => toUnix(sp2.normalize(toUnix(path29)));
31986
+ normalizeIgnored = (cwd = "") => (path29) => {
31987
+ if (typeof path29 === "string") {
31988
+ return normalizePathToUnix(sp2.isAbsolute(path29) ? path29 : sp2.join(cwd, path29));
31521
31989
  } else {
31522
- return path30;
31990
+ return path29;
31523
31991
  }
31524
31992
  };
31525
- getAbsolutePath = (path30, cwd) => {
31526
- if (sp2.isAbsolute(path30)) {
31527
- return path30;
31993
+ getAbsolutePath = (path29, cwd) => {
31994
+ if (sp2.isAbsolute(path29)) {
31995
+ return path29;
31528
31996
  }
31529
- return sp2.join(cwd, path30);
31997
+ return sp2.join(cwd, path29);
31530
31998
  };
31531
31999
  EMPTY_SET = Object.freeze(/* @__PURE__ */ new Set());
31532
32000
  DirEntry = class {
@@ -31591,10 +32059,10 @@ var init_chokidar = __esm({
31591
32059
  dirParts;
31592
32060
  followSymlinks;
31593
32061
  statMethod;
31594
- constructor(path30, follow, fsw) {
32062
+ constructor(path29, follow, fsw) {
31595
32063
  this.fsw = fsw;
31596
- const watchPath = path30;
31597
- this.path = path30 = path30.replace(REPLACER_RE, "");
32064
+ const watchPath = path29;
32065
+ this.path = path29 = path29.replace(REPLACER_RE, "");
31598
32066
  this.watchPath = watchPath;
31599
32067
  this.fullWatchPath = sp2.resolve(watchPath);
31600
32068
  this.dirParts = [];
@@ -31734,20 +32202,20 @@ var init_chokidar = __esm({
31734
32202
  this._closePromise = void 0;
31735
32203
  let paths = unifyPaths(paths_);
31736
32204
  if (cwd) {
31737
- paths = paths.map((path30) => {
31738
- const absPath = getAbsolutePath(path30, cwd);
32205
+ paths = paths.map((path29) => {
32206
+ const absPath = getAbsolutePath(path29, cwd);
31739
32207
  return absPath;
31740
32208
  });
31741
32209
  }
31742
- paths.forEach((path30) => {
31743
- this._removeIgnoredPath(path30);
32210
+ paths.forEach((path29) => {
32211
+ this._removeIgnoredPath(path29);
31744
32212
  });
31745
32213
  this._userIgnored = void 0;
31746
32214
  if (!this._readyCount)
31747
32215
  this._readyCount = 0;
31748
32216
  this._readyCount += paths.length;
31749
- Promise.all(paths.map(async (path30) => {
31750
- const res = await this._nodeFsHandler._addToNodeFs(path30, !_internal, void 0, 0, _origAdd);
32217
+ Promise.all(paths.map(async (path29) => {
32218
+ const res = await this._nodeFsHandler._addToNodeFs(path29, !_internal, void 0, 0, _origAdd);
31751
32219
  if (res)
31752
32220
  this._emitReady();
31753
32221
  return res;
@@ -31769,17 +32237,17 @@ var init_chokidar = __esm({
31769
32237
  return this;
31770
32238
  const paths = unifyPaths(paths_);
31771
32239
  const { cwd } = this.options;
31772
- paths.forEach((path30) => {
31773
- if (!sp2.isAbsolute(path30) && !this._closers.has(path30)) {
32240
+ paths.forEach((path29) => {
32241
+ if (!sp2.isAbsolute(path29) && !this._closers.has(path29)) {
31774
32242
  if (cwd)
31775
- path30 = sp2.join(cwd, path30);
31776
- path30 = sp2.resolve(path30);
32243
+ path29 = sp2.join(cwd, path29);
32244
+ path29 = sp2.resolve(path29);
31777
32245
  }
31778
- this._closePath(path30);
31779
- this._addIgnoredPath(path30);
31780
- if (this._watched.has(path30)) {
32246
+ this._closePath(path29);
32247
+ this._addIgnoredPath(path29);
32248
+ if (this._watched.has(path29)) {
31781
32249
  this._addIgnoredPath({
31782
- path: path30,
32250
+ path: path29,
31783
32251
  recursive: true
31784
32252
  });
31785
32253
  }
@@ -31843,38 +32311,38 @@ var init_chokidar = __esm({
31843
32311
  * @param stats arguments to be passed with event
31844
32312
  * @returns the error if defined, otherwise the value of the FSWatcher instance's `closed` flag
31845
32313
  */
31846
- async _emit(event, path30, stats) {
32314
+ async _emit(event, path29, stats) {
31847
32315
  if (this.closed)
31848
32316
  return;
31849
32317
  const opts = this.options;
31850
32318
  if (isWindows)
31851
- path30 = sp2.normalize(path30);
32319
+ path29 = sp2.normalize(path29);
31852
32320
  if (opts.cwd)
31853
- path30 = sp2.relative(opts.cwd, path30);
31854
- const args = [path30];
32321
+ path29 = sp2.relative(opts.cwd, path29);
32322
+ const args = [path29];
31855
32323
  if (stats != null)
31856
32324
  args.push(stats);
31857
32325
  const awf = opts.awaitWriteFinish;
31858
32326
  let pw;
31859
- if (awf && (pw = this._pendingWrites.get(path30))) {
32327
+ if (awf && (pw = this._pendingWrites.get(path29))) {
31860
32328
  pw.lastChange = /* @__PURE__ */ new Date();
31861
32329
  return this;
31862
32330
  }
31863
32331
  if (opts.atomic) {
31864
32332
  if (event === EVENTS.UNLINK) {
31865
- this._pendingUnlinks.set(path30, [event, ...args]);
32333
+ this._pendingUnlinks.set(path29, [event, ...args]);
31866
32334
  setTimeout(() => {
31867
- this._pendingUnlinks.forEach((entry, path31) => {
32335
+ this._pendingUnlinks.forEach((entry, path30) => {
31868
32336
  this.emit(...entry);
31869
32337
  this.emit(EVENTS.ALL, ...entry);
31870
- this._pendingUnlinks.delete(path31);
32338
+ this._pendingUnlinks.delete(path30);
31871
32339
  });
31872
32340
  }, typeof opts.atomic === "number" ? opts.atomic : 100);
31873
32341
  return this;
31874
32342
  }
31875
- if (event === EVENTS.ADD && this._pendingUnlinks.has(path30)) {
32343
+ if (event === EVENTS.ADD && this._pendingUnlinks.has(path29)) {
31876
32344
  event = EVENTS.CHANGE;
31877
- this._pendingUnlinks.delete(path30);
32345
+ this._pendingUnlinks.delete(path29);
31878
32346
  }
31879
32347
  }
31880
32348
  if (awf && (event === EVENTS.ADD || event === EVENTS.CHANGE) && this._readyEmitted) {
@@ -31892,16 +32360,16 @@ var init_chokidar = __esm({
31892
32360
  this.emitWithAll(event, args);
31893
32361
  }
31894
32362
  };
31895
- this._awaitWriteFinish(path30, awf.stabilityThreshold, event, awfEmit);
32363
+ this._awaitWriteFinish(path29, awf.stabilityThreshold, event, awfEmit);
31896
32364
  return this;
31897
32365
  }
31898
32366
  if (event === EVENTS.CHANGE) {
31899
- const isThrottled = !this._throttle(EVENTS.CHANGE, path30, 50);
32367
+ const isThrottled = !this._throttle(EVENTS.CHANGE, path29, 50);
31900
32368
  if (isThrottled)
31901
32369
  return this;
31902
32370
  }
31903
32371
  if (opts.alwaysStat && stats === void 0 && (event === EVENTS.ADD || event === EVENTS.ADD_DIR || event === EVENTS.CHANGE)) {
31904
- const fullPath = opts.cwd ? sp2.join(opts.cwd, path30) : path30;
32372
+ const fullPath = opts.cwd ? sp2.join(opts.cwd, path29) : path29;
31905
32373
  let stats2;
31906
32374
  try {
31907
32375
  stats2 = await (0, import_promises3.stat)(fullPath);
@@ -31932,23 +32400,23 @@ var init_chokidar = __esm({
31932
32400
  * @param timeout duration of time to suppress duplicate actions
31933
32401
  * @returns tracking object or false if action should be suppressed
31934
32402
  */
31935
- _throttle(actionType, path30, timeout) {
32403
+ _throttle(actionType, path29, timeout) {
31936
32404
  if (!this._throttled.has(actionType)) {
31937
32405
  this._throttled.set(actionType, /* @__PURE__ */ new Map());
31938
32406
  }
31939
32407
  const action = this._throttled.get(actionType);
31940
32408
  if (!action)
31941
32409
  throw new Error("invalid throttle");
31942
- const actionPath = action.get(path30);
32410
+ const actionPath = action.get(path29);
31943
32411
  if (actionPath) {
31944
32412
  actionPath.count++;
31945
32413
  return false;
31946
32414
  }
31947
32415
  let timeoutObject;
31948
32416
  const clear = () => {
31949
- const item = action.get(path30);
32417
+ const item = action.get(path29);
31950
32418
  const count = item ? item.count : 0;
31951
- action.delete(path30);
32419
+ action.delete(path29);
31952
32420
  clearTimeout(timeoutObject);
31953
32421
  if (item)
31954
32422
  clearTimeout(item.timeoutObject);
@@ -31956,7 +32424,7 @@ var init_chokidar = __esm({
31956
32424
  };
31957
32425
  timeoutObject = setTimeout(clear, timeout);
31958
32426
  const thr = { timeoutObject, clear, count: 0 };
31959
- action.set(path30, thr);
32427
+ action.set(path29, thr);
31960
32428
  return thr;
31961
32429
  }
31962
32430
  _incrReadyCount() {
@@ -31970,44 +32438,44 @@ var init_chokidar = __esm({
31970
32438
  * @param event
31971
32439
  * @param awfEmit Callback to be called when ready for event to be emitted.
31972
32440
  */
31973
- _awaitWriteFinish(path30, threshold, event, awfEmit) {
32441
+ _awaitWriteFinish(path29, threshold, event, awfEmit) {
31974
32442
  const awf = this.options.awaitWriteFinish;
31975
32443
  if (typeof awf !== "object")
31976
32444
  return;
31977
32445
  const pollInterval = awf.pollInterval;
31978
32446
  let timeoutHandler;
31979
- let fullPath = path30;
31980
- if (this.options.cwd && !sp2.isAbsolute(path30)) {
31981
- fullPath = sp2.join(this.options.cwd, path30);
32447
+ let fullPath = path29;
32448
+ if (this.options.cwd && !sp2.isAbsolute(path29)) {
32449
+ fullPath = sp2.join(this.options.cwd, path29);
31982
32450
  }
31983
32451
  const now = /* @__PURE__ */ new Date();
31984
32452
  const writes = this._pendingWrites;
31985
32453
  function awaitWriteFinishFn(prevStat) {
31986
32454
  (0, import_node_fs2.stat)(fullPath, (err, curStat) => {
31987
- if (err || !writes.has(path30)) {
32455
+ if (err || !writes.has(path29)) {
31988
32456
  if (err && err.code !== "ENOENT")
31989
32457
  awfEmit(err);
31990
32458
  return;
31991
32459
  }
31992
32460
  const now2 = Number(/* @__PURE__ */ new Date());
31993
32461
  if (prevStat && curStat.size !== prevStat.size) {
31994
- writes.get(path30).lastChange = now2;
32462
+ writes.get(path29).lastChange = now2;
31995
32463
  }
31996
- const pw = writes.get(path30);
32464
+ const pw = writes.get(path29);
31997
32465
  const df = now2 - pw.lastChange;
31998
32466
  if (df >= threshold) {
31999
- writes.delete(path30);
32467
+ writes.delete(path29);
32000
32468
  awfEmit(void 0, curStat);
32001
32469
  } else {
32002
32470
  timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval, curStat);
32003
32471
  }
32004
32472
  });
32005
32473
  }
32006
- if (!writes.has(path30)) {
32007
- writes.set(path30, {
32474
+ if (!writes.has(path29)) {
32475
+ writes.set(path29, {
32008
32476
  lastChange: now,
32009
32477
  cancelWait: () => {
32010
- writes.delete(path30);
32478
+ writes.delete(path29);
32011
32479
  clearTimeout(timeoutHandler);
32012
32480
  return event;
32013
32481
  }
@@ -32018,8 +32486,8 @@ var init_chokidar = __esm({
32018
32486
  /**
32019
32487
  * Determines whether user has asked to ignore this path.
32020
32488
  */
32021
- _isIgnored(path30, stats) {
32022
- if (this.options.atomic && DOT_RE.test(path30))
32489
+ _isIgnored(path29, stats) {
32490
+ if (this.options.atomic && DOT_RE.test(path29))
32023
32491
  return true;
32024
32492
  if (!this._userIgnored) {
32025
32493
  const { cwd } = this.options;
@@ -32029,17 +32497,17 @@ var init_chokidar = __esm({
32029
32497
  const list = [...ignoredPaths.map(normalizeIgnored(cwd)), ...ignored];
32030
32498
  this._userIgnored = anymatch(list, void 0);
32031
32499
  }
32032
- return this._userIgnored(path30, stats);
32500
+ return this._userIgnored(path29, stats);
32033
32501
  }
32034
- _isntIgnored(path30, stat4) {
32035
- return !this._isIgnored(path30, stat4);
32502
+ _isntIgnored(path29, stat4) {
32503
+ return !this._isIgnored(path29, stat4);
32036
32504
  }
32037
32505
  /**
32038
32506
  * Provides a set of common helpers and properties relating to symlink handling.
32039
32507
  * @param path file or directory pattern being watched
32040
32508
  */
32041
- _getWatchHelpers(path30) {
32042
- return new WatchHelper(path30, this.options.followSymlinks, this);
32509
+ _getWatchHelpers(path29) {
32510
+ return new WatchHelper(path29, this.options.followSymlinks, this);
32043
32511
  }
32044
32512
  // Directory helpers
32045
32513
  // -----------------
@@ -32071,63 +32539,63 @@ var init_chokidar = __esm({
32071
32539
  * @param item base path of item/directory
32072
32540
  */
32073
32541
  _remove(directory, item, isDirectory) {
32074
- const path30 = sp2.join(directory, item);
32075
- const fullPath = sp2.resolve(path30);
32076
- isDirectory = isDirectory != null ? isDirectory : this._watched.has(path30) || this._watched.has(fullPath);
32077
- if (!this._throttle("remove", path30, 100))
32542
+ const path29 = sp2.join(directory, item);
32543
+ const fullPath = sp2.resolve(path29);
32544
+ isDirectory = isDirectory != null ? isDirectory : this._watched.has(path29) || this._watched.has(fullPath);
32545
+ if (!this._throttle("remove", path29, 100))
32078
32546
  return;
32079
32547
  if (!isDirectory && this._watched.size === 1) {
32080
32548
  this.add(directory, item, true);
32081
32549
  }
32082
- const wp = this._getWatchedDir(path30);
32550
+ const wp = this._getWatchedDir(path29);
32083
32551
  const nestedDirectoryChildren = wp.getChildren();
32084
- nestedDirectoryChildren.forEach((nested) => this._remove(path30, nested));
32552
+ nestedDirectoryChildren.forEach((nested) => this._remove(path29, nested));
32085
32553
  const parent = this._getWatchedDir(directory);
32086
32554
  const wasTracked = parent.has(item);
32087
32555
  parent.remove(item);
32088
32556
  if (this._symlinkPaths.has(fullPath)) {
32089
32557
  this._symlinkPaths.delete(fullPath);
32090
32558
  }
32091
- let relPath = path30;
32559
+ let relPath = path29;
32092
32560
  if (this.options.cwd)
32093
- relPath = sp2.relative(this.options.cwd, path30);
32561
+ relPath = sp2.relative(this.options.cwd, path29);
32094
32562
  if (this.options.awaitWriteFinish && this._pendingWrites.has(relPath)) {
32095
32563
  const event = this._pendingWrites.get(relPath).cancelWait();
32096
32564
  if (event === EVENTS.ADD)
32097
32565
  return;
32098
32566
  }
32099
- this._watched.delete(path30);
32567
+ this._watched.delete(path29);
32100
32568
  this._watched.delete(fullPath);
32101
32569
  const eventName = isDirectory ? EVENTS.UNLINK_DIR : EVENTS.UNLINK;
32102
- if (wasTracked && !this._isIgnored(path30))
32103
- this._emit(eventName, path30);
32104
- this._closePath(path30);
32570
+ if (wasTracked && !this._isIgnored(path29))
32571
+ this._emit(eventName, path29);
32572
+ this._closePath(path29);
32105
32573
  }
32106
32574
  /**
32107
32575
  * Closes all watchers for a path
32108
32576
  */
32109
- _closePath(path30) {
32110
- this._closeFile(path30);
32111
- const dir = sp2.dirname(path30);
32112
- this._getWatchedDir(dir).remove(sp2.basename(path30));
32577
+ _closePath(path29) {
32578
+ this._closeFile(path29);
32579
+ const dir = sp2.dirname(path29);
32580
+ this._getWatchedDir(dir).remove(sp2.basename(path29));
32113
32581
  }
32114
32582
  /**
32115
32583
  * Closes only file-specific watchers
32116
32584
  */
32117
- _closeFile(path30) {
32118
- const closers = this._closers.get(path30);
32585
+ _closeFile(path29) {
32586
+ const closers = this._closers.get(path29);
32119
32587
  if (!closers)
32120
32588
  return;
32121
32589
  closers.forEach((closer) => closer());
32122
- this._closers.delete(path30);
32590
+ this._closers.delete(path29);
32123
32591
  }
32124
- _addPathCloser(path30, closer) {
32592
+ _addPathCloser(path29, closer) {
32125
32593
  if (!closer)
32126
32594
  return;
32127
- let list = this._closers.get(path30);
32595
+ let list = this._closers.get(path29);
32128
32596
  if (!list) {
32129
32597
  list = [];
32130
- this._closers.set(path30, list);
32598
+ this._closers.set(path29, list);
32131
32599
  }
32132
32600
  list.push(closer);
32133
32601
  }
@@ -32176,6 +32644,7 @@ function validateProviderDefinition(raw) {
32176
32644
  warnings.push("disableUpstream is deprecated in provider definitions; use machine-level provider source policy instead");
32177
32645
  }
32178
32646
  const category = provider.category;
32647
+ const controls = Array.isArray(provider.controls) ? provider.controls : [];
32179
32648
  if (category === "cli" || category === "acp") {
32180
32649
  const spawn6 = provider.spawn;
32181
32650
  const command = spawn6 && typeof spawn6 === "object" ? spawn6.command : void 0;
@@ -32193,11 +32662,61 @@ function validateProviderDefinition(raw) {
32193
32662
  if (category === "extension" && !provider.extensionId) {
32194
32663
  warnings.push("Extension providers should have extensionId");
32195
32664
  }
32196
- for (const control of Array.isArray(provider.controls) ? provider.controls : []) {
32665
+ validateCapabilities(provider, controls, errors);
32666
+ for (const control of controls) {
32197
32667
  validateControl(control, errors);
32198
32668
  }
32199
32669
  return { errors, warnings };
32200
32670
  }
32671
+ function validateCapabilities(provider, controls, errors) {
32672
+ const capabilities = provider.capabilities;
32673
+ if (provider.contractVersion === 2) {
32674
+ if (!capabilities || typeof capabilities !== "object") {
32675
+ errors.push("contractVersion 2 providers must declare capabilities");
32676
+ return;
32677
+ }
32678
+ }
32679
+ if (!capabilities || typeof capabilities !== "object") {
32680
+ return;
32681
+ }
32682
+ const input = capabilities.input;
32683
+ if (!input || typeof input !== "object") {
32684
+ errors.push("capabilities.input is required");
32685
+ } else {
32686
+ if (typeof input.multipart !== "boolean") {
32687
+ errors.push("capabilities.input.multipart must be boolean");
32688
+ }
32689
+ if (!Array.isArray(input.mediaTypes) || input.mediaTypes.length === 0) {
32690
+ errors.push("capabilities.input.mediaTypes must be a non-empty array");
32691
+ } else if (input.mediaTypes.some((type) => typeof type !== "string" || !VALID_CAPABILITY_MEDIA_TYPES.has(type))) {
32692
+ errors.push(`capabilities.input.mediaTypes must only include: ${Array.from(VALID_CAPABILITY_MEDIA_TYPES).join(", ")}`);
32693
+ }
32694
+ }
32695
+ const output = capabilities.output;
32696
+ if (!output || typeof output !== "object") {
32697
+ errors.push("capabilities.output is required");
32698
+ } else {
32699
+ if (typeof output.richContent !== "boolean") {
32700
+ errors.push("capabilities.output.richContent must be boolean");
32701
+ }
32702
+ if (!Array.isArray(output.mediaTypes) || output.mediaTypes.length === 0) {
32703
+ errors.push("capabilities.output.mediaTypes must be a non-empty array");
32704
+ } else if (output.mediaTypes.some((type) => typeof type !== "string" || !VALID_CAPABILITY_MEDIA_TYPES.has(type))) {
32705
+ errors.push(`capabilities.output.mediaTypes must only include: ${Array.from(VALID_CAPABILITY_MEDIA_TYPES).join(", ")}`);
32706
+ }
32707
+ }
32708
+ const controlCapabilities = capabilities.controls;
32709
+ if (!controlCapabilities || typeof controlCapabilities !== "object") {
32710
+ errors.push("capabilities.controls is required");
32711
+ return;
32712
+ }
32713
+ if (typeof controlCapabilities.typedResults !== "boolean") {
32714
+ errors.push("capabilities.controls.typedResults must be boolean");
32715
+ }
32716
+ if (controls.length > 0 && controlCapabilities.typedResults !== true) {
32717
+ errors.push("providers declaring controls must set capabilities.controls.typedResults=true");
32718
+ }
32719
+ }
32201
32720
  function validateControl(control, errors) {
32202
32721
  if (!control || typeof control !== "object") {
32203
32722
  errors.push("controls: each control must be an object");
@@ -32229,10 +32748,11 @@ function validateControl(control, errors) {
32229
32748
  errors.push(`${prefix}: readFrom must be a non-empty string when provided`);
32230
32749
  }
32231
32750
  }
32232
- var KNOWN_PROVIDER_FIELDS, VALUE_CONTROL_TYPES;
32751
+ var VALID_CAPABILITY_MEDIA_TYPES, KNOWN_PROVIDER_FIELDS, VALUE_CONTROL_TYPES;
32233
32752
  var init_provider_schema = __esm({
32234
32753
  "../../oss/packages/daemon-core/src/providers/provider-schema.ts"() {
32235
32754
  "use strict";
32755
+ VALID_CAPABILITY_MEDIA_TYPES = /* @__PURE__ */ new Set(["text", "image", "audio", "video", "resource"]);
32236
32756
  KNOWN_PROVIDER_FIELDS = /* @__PURE__ */ new Set([
32237
32757
  "type",
32238
32758
  "name",
@@ -32283,6 +32803,7 @@ var init_provider_schema = __esm({
32283
32803
  "sendDelayMs",
32284
32804
  "sendKey",
32285
32805
  "submitStrategy",
32806
+ "timeouts",
32286
32807
  "disableUpstream"
32287
32808
  ]);
32288
32809
  VALUE_CONTROL_TYPES = /* @__PURE__ */ new Set(["select", "toggle", "cycle", "slider"]);
@@ -32290,12 +32811,12 @@ var init_provider_schema = __esm({
32290
32811
  });
32291
32812
 
32292
32813
  // ../../oss/packages/daemon-core/src/providers/provider-loader.ts
32293
- var fs6, path14, os15, ProviderLoader;
32814
+ var fs6, path13, os15, ProviderLoader;
32294
32815
  var init_provider_loader = __esm({
32295
32816
  "../../oss/packages/daemon-core/src/providers/provider-loader.ts"() {
32296
32817
  "use strict";
32297
32818
  fs6 = __toESM(require("fs"));
32298
- path14 = __toESM(require("path"));
32819
+ path13 = __toESM(require("path"));
32299
32820
  os15 = __toESM(require("os"));
32300
32821
  init_chokidar();
32301
32822
  init_ide_detector();
@@ -32322,9 +32843,9 @@ var init_provider_loader = __esm({
32322
32843
  static META_FILE = ".meta.json";
32323
32844
  constructor(options) {
32324
32845
  this.logFn = options?.logFn || LOG.forComponent("Provider").asLogFn();
32325
- this.defaultProvidersDir = path14.join(os15.homedir(), ".adhdev", "providers");
32846
+ this.defaultProvidersDir = path13.join(os15.homedir(), ".adhdev", "providers");
32326
32847
  this.userDir = this.defaultProvidersDir;
32327
- this.upstreamDir = path14.join(this.defaultProvidersDir, ".upstream");
32848
+ this.upstreamDir = path13.join(this.defaultProvidersDir, ".upstream");
32328
32849
  this.disableUpstream = false;
32329
32850
  this.applySourceConfig({
32330
32851
  userDir: options?.userDir,
@@ -32372,7 +32893,7 @@ var init_provider_loader = __esm({
32372
32893
  }
32373
32894
  this.sourceMode = nextSourceMode;
32374
32895
  this.userDir = this.explicitProviderDir || this.defaultProvidersDir;
32375
- this.upstreamDir = path14.join(this.defaultProvidersDir, ".upstream");
32896
+ this.upstreamDir = path13.join(this.defaultProvidersDir, ".upstream");
32376
32897
  this.disableUpstream = this.sourceMode === "no-upstream";
32377
32898
  if (this.explicitProviderDir) {
32378
32899
  this.log(`Config 'providerDir' applied: ${this.userDir}`);
@@ -32386,7 +32907,7 @@ var init_provider_loader = __esm({
32386
32907
  * Canonical provider directory shape for a given root.
32387
32908
  */
32388
32909
  getProviderDir(root, category, type) {
32389
- return path14.join(root, category, type);
32910
+ return path13.join(root, category, type);
32390
32911
  }
32391
32912
  /**
32392
32913
  * Canonical user override directory for a provider.
@@ -32413,7 +32934,7 @@ var init_provider_loader = __esm({
32413
32934
  resolveProviderFile(type, ...segments) {
32414
32935
  const dir = this.findProviderDirInternal(type);
32415
32936
  if (!dir) return null;
32416
- return path14.join(dir, ...segments);
32937
+ return path13.join(dir, ...segments);
32417
32938
  }
32418
32939
  /**
32419
32940
  * Load all providers (3-tier priority)
@@ -32452,7 +32973,7 @@ var init_provider_loader = __esm({
32452
32973
  if (!fs6.existsSync(this.upstreamDir)) return false;
32453
32974
  try {
32454
32975
  return fs6.readdirSync(this.upstreamDir).some(
32455
- (d) => fs6.statSync(path14.join(this.upstreamDir, d)).isDirectory()
32976
+ (d) => fs6.statSync(path13.join(this.upstreamDir, d)).isDirectory()
32456
32977
  );
32457
32978
  } catch {
32458
32979
  return false;
@@ -32767,8 +33288,8 @@ var init_provider_loader = __esm({
32767
33288
  resolved._resolvedScriptDir = entry.scriptDir;
32768
33289
  resolved._resolvedScriptsSource = `compatibility:${entry.ideVersion}`;
32769
33290
  if (providerDir) {
32770
- const fullDir = path14.join(providerDir, entry.scriptDir);
32771
- resolved._resolvedScriptsPath = fs6.existsSync(path14.join(fullDir, "scripts.js")) ? path14.join(fullDir, "scripts.js") : fullDir;
33291
+ const fullDir = path13.join(providerDir, entry.scriptDir);
33292
+ resolved._resolvedScriptsPath = fs6.existsSync(path13.join(fullDir, "scripts.js")) ? path13.join(fullDir, "scripts.js") : fullDir;
32772
33293
  }
32773
33294
  matched = true;
32774
33295
  }
@@ -32783,8 +33304,8 @@ var init_provider_loader = __esm({
32783
33304
  resolved._resolvedScriptDir = base.defaultScriptDir;
32784
33305
  resolved._resolvedScriptsSource = "defaultScriptDir:version_miss";
32785
33306
  if (providerDir) {
32786
- const fullDir = path14.join(providerDir, base.defaultScriptDir);
32787
- resolved._resolvedScriptsPath = fs6.existsSync(path14.join(fullDir, "scripts.js")) ? path14.join(fullDir, "scripts.js") : fullDir;
33307
+ const fullDir = path13.join(providerDir, base.defaultScriptDir);
33308
+ resolved._resolvedScriptsPath = fs6.existsSync(path13.join(fullDir, "scripts.js")) ? path13.join(fullDir, "scripts.js") : fullDir;
32788
33309
  }
32789
33310
  }
32790
33311
  resolved._versionWarning = `Version ${currentVersion} not in compatibility matrix. Using default scripts.`;
@@ -32801,8 +33322,8 @@ var init_provider_loader = __esm({
32801
33322
  resolved._resolvedScriptDir = dirOverride;
32802
33323
  resolved._resolvedScriptsSource = `versions:${range}`;
32803
33324
  if (providerDir) {
32804
- const fullDir = path14.join(providerDir, dirOverride);
32805
- resolved._resolvedScriptsPath = fs6.existsSync(path14.join(fullDir, "scripts.js")) ? path14.join(fullDir, "scripts.js") : fullDir;
33325
+ const fullDir = path13.join(providerDir, dirOverride);
33326
+ resolved._resolvedScriptsPath = fs6.existsSync(path13.join(fullDir, "scripts.js")) ? path13.join(fullDir, "scripts.js") : fullDir;
32806
33327
  }
32807
33328
  }
32808
33329
  } else if (override.scripts) {
@@ -32818,8 +33339,8 @@ var init_provider_loader = __esm({
32818
33339
  resolved._resolvedScriptDir = base.defaultScriptDir;
32819
33340
  resolved._resolvedScriptsSource = "defaultScriptDir:no_version";
32820
33341
  if (providerDir) {
32821
- const fullDir = path14.join(providerDir, base.defaultScriptDir);
32822
- resolved._resolvedScriptsPath = fs6.existsSync(path14.join(fullDir, "scripts.js")) ? path14.join(fullDir, "scripts.js") : fullDir;
33342
+ const fullDir = path13.join(providerDir, base.defaultScriptDir);
33343
+ resolved._resolvedScriptsPath = fs6.existsSync(path13.join(fullDir, "scripts.js")) ? path13.join(fullDir, "scripts.js") : fullDir;
32823
33344
  }
32824
33345
  }
32825
33346
  }
@@ -32844,14 +33365,14 @@ var init_provider_loader = __esm({
32844
33365
  this.log(` [loadScriptsFromDir] ${type}: providerDir not found`);
32845
33366
  return null;
32846
33367
  }
32847
- const dir = path14.join(providerDir, scriptDir);
33368
+ const dir = path13.join(providerDir, scriptDir);
32848
33369
  if (!fs6.existsSync(dir)) {
32849
33370
  this.log(` [loadScriptsFromDir] ${type}: dir not found: ${dir}`);
32850
33371
  return null;
32851
33372
  }
32852
33373
  const cached2 = this.scriptsCache.get(dir);
32853
33374
  if (cached2) return cached2;
32854
- const scriptsJs = path14.join(dir, "scripts.js");
33375
+ const scriptsJs = path13.join(dir, "scripts.js");
32855
33376
  if (fs6.existsSync(scriptsJs)) {
32856
33377
  try {
32857
33378
  delete require.cache[require.resolve(scriptsJs)];
@@ -32893,7 +33414,7 @@ var init_provider_loader = __esm({
32893
33414
  return;
32894
33415
  }
32895
33416
  if (filePath.endsWith(".js") || filePath.endsWith(".json")) {
32896
- this.log(`File changed: ${path14.basename(filePath)}, reloading...`);
33417
+ this.log(`File changed: ${path13.basename(filePath)}, reloading...`);
32897
33418
  this.reload();
32898
33419
  }
32899
33420
  };
@@ -32948,7 +33469,7 @@ var init_provider_loader = __esm({
32948
33469
  }
32949
33470
  const https = require("https");
32950
33471
  const { execSync: execSync7 } = require("child_process");
32951
- const metaPath = path14.join(this.upstreamDir, _ProviderLoader.META_FILE);
33472
+ const metaPath = path13.join(this.upstreamDir, _ProviderLoader.META_FILE);
32952
33473
  let prevEtag = "";
32953
33474
  let prevTimestamp = 0;
32954
33475
  try {
@@ -33008,17 +33529,17 @@ var init_provider_loader = __esm({
33008
33529
  return { updated: false };
33009
33530
  }
33010
33531
  this.log("Downloading latest providers from GitHub...");
33011
- const tmpTar = path14.join(os15.tmpdir(), `adhdev-providers-${Date.now()}.tar.gz`);
33012
- const tmpExtract = path14.join(os15.tmpdir(), `adhdev-providers-extract-${Date.now()}`);
33532
+ const tmpTar = path13.join(os15.tmpdir(), `adhdev-providers-${Date.now()}.tar.gz`);
33533
+ const tmpExtract = path13.join(os15.tmpdir(), `adhdev-providers-extract-${Date.now()}`);
33013
33534
  await this.downloadFile(_ProviderLoader.GITHUB_TARBALL_URL, tmpTar);
33014
33535
  fs6.mkdirSync(tmpExtract, { recursive: true });
33015
33536
  execSync7(`tar -xzf "${tmpTar}" -C "${tmpExtract}"`, { timeout: 3e4 });
33016
33537
  const extracted = fs6.readdirSync(tmpExtract);
33017
33538
  const rootDir = extracted.find(
33018
- (d) => fs6.statSync(path14.join(tmpExtract, d)).isDirectory() && d.startsWith("adhdev-providers")
33539
+ (d) => fs6.statSync(path13.join(tmpExtract, d)).isDirectory() && d.startsWith("adhdev-providers")
33019
33540
  );
33020
33541
  if (!rootDir) throw new Error("Unexpected tarball structure");
33021
- const sourceDir = path14.join(tmpExtract, rootDir);
33542
+ const sourceDir = path13.join(tmpExtract, rootDir);
33022
33543
  const backupDir = this.upstreamDir + ".bak";
33023
33544
  if (fs6.existsSync(this.upstreamDir)) {
33024
33545
  if (fs6.existsSync(backupDir)) fs6.rmSync(backupDir, { recursive: true, force: true });
@@ -33093,8 +33614,8 @@ var init_provider_loader = __esm({
33093
33614
  copyDirRecursive(src, dest) {
33094
33615
  fs6.mkdirSync(dest, { recursive: true });
33095
33616
  for (const entry of fs6.readdirSync(src, { withFileTypes: true })) {
33096
- const srcPath = path14.join(src, entry.name);
33097
- const destPath = path14.join(dest, entry.name);
33617
+ const srcPath = path13.join(src, entry.name);
33618
+ const destPath = path13.join(dest, entry.name);
33098
33619
  if (entry.isDirectory()) {
33099
33620
  this.copyDirRecursive(srcPath, destPath);
33100
33621
  } else {
@@ -33105,7 +33626,7 @@ var init_provider_loader = __esm({
33105
33626
  /** .meta.json save */
33106
33627
  writeMeta(metaPath, etag, timestamp) {
33107
33628
  try {
33108
- fs6.mkdirSync(path14.dirname(metaPath), { recursive: true });
33629
+ fs6.mkdirSync(path13.dirname(metaPath), { recursive: true });
33109
33630
  fs6.writeFileSync(metaPath, JSON.stringify({
33110
33631
  etag,
33111
33632
  timestamp,
@@ -33122,7 +33643,7 @@ var init_provider_loader = __esm({
33122
33643
  const scan = (d) => {
33123
33644
  try {
33124
33645
  for (const entry of fs6.readdirSync(d, { withFileTypes: true })) {
33125
- if (entry.isDirectory()) scan(path14.join(d, entry.name));
33646
+ if (entry.isDirectory()) scan(path13.join(d, entry.name));
33126
33647
  else if (entry.name === "provider.json") count++;
33127
33648
  }
33128
33649
  } catch {
@@ -33307,17 +33828,17 @@ var init_provider_loader = __esm({
33307
33828
  for (const root of searchRoots) {
33308
33829
  if (!fs6.existsSync(root)) continue;
33309
33830
  const candidate = this.getProviderDir(root, cat, type);
33310
- if (fs6.existsSync(path14.join(candidate, "provider.json"))) return candidate;
33311
- const catDir = path14.join(root, cat);
33831
+ if (fs6.existsSync(path13.join(candidate, "provider.json"))) return candidate;
33832
+ const catDir = path13.join(root, cat);
33312
33833
  if (fs6.existsSync(catDir)) {
33313
33834
  try {
33314
33835
  for (const entry of fs6.readdirSync(catDir, { withFileTypes: true })) {
33315
33836
  if (!entry.isDirectory()) continue;
33316
- const jsonPath = path14.join(catDir, entry.name, "provider.json");
33837
+ const jsonPath = path13.join(catDir, entry.name, "provider.json");
33317
33838
  if (fs6.existsSync(jsonPath)) {
33318
33839
  try {
33319
33840
  const data = JSON.parse(fs6.readFileSync(jsonPath, "utf-8"));
33320
- if (data.type === type) return path14.join(catDir, entry.name);
33841
+ if (data.type === type) return path13.join(catDir, entry.name);
33321
33842
  } catch {
33322
33843
  }
33323
33844
  }
@@ -33334,7 +33855,7 @@ var init_provider_loader = __esm({
33334
33855
  * (template substitution is NOT applied here — scripts.js handles that)
33335
33856
  */
33336
33857
  buildScriptWrappersFromDir(dir) {
33337
- const scriptsJs = path14.join(dir, "scripts.js");
33858
+ const scriptsJs = path13.join(dir, "scripts.js");
33338
33859
  if (fs6.existsSync(scriptsJs)) {
33339
33860
  try {
33340
33861
  delete require.cache[require.resolve(scriptsJs)];
@@ -33348,7 +33869,7 @@ var init_provider_loader = __esm({
33348
33869
  for (const file2 of fs6.readdirSync(dir)) {
33349
33870
  if (!file2.endsWith(".js")) continue;
33350
33871
  const scriptName = toCamel(file2.replace(".js", ""));
33351
- const filePath = path14.join(dir, file2);
33872
+ const filePath = path13.join(dir, file2);
33352
33873
  result[scriptName] = (...args) => {
33353
33874
  try {
33354
33875
  let content = fs6.readFileSync(filePath, "utf-8");
@@ -33408,7 +33929,7 @@ var init_provider_loader = __esm({
33408
33929
  }
33409
33930
  const hasJson = entries.some((e) => e.name === "provider.json");
33410
33931
  if (hasJson) {
33411
- const jsonPath = path14.join(d, "provider.json");
33932
+ const jsonPath = path13.join(d, "provider.json");
33412
33933
  try {
33413
33934
  const raw = fs6.readFileSync(jsonPath, "utf-8");
33414
33935
  const mod = JSON.parse(raw);
@@ -33429,7 +33950,7 @@ var init_provider_loader = __esm({
33429
33950
  this.log(`\u26A0 Invalid provider at ${jsonPath}: ${validation.errors.join("; ")}`);
33430
33951
  } else {
33431
33952
  const hasCompatibility = Array.isArray(normalizedProvider.compatibility);
33432
- const scriptsPath = path14.join(d, "scripts.js");
33953
+ const scriptsPath = path13.join(d, "scripts.js");
33433
33954
  if (!hasCompatibility && fs6.existsSync(scriptsPath)) {
33434
33955
  try {
33435
33956
  delete require.cache[require.resolve(scriptsPath)];
@@ -33455,7 +33976,7 @@ var init_provider_loader = __esm({
33455
33976
  if (!entry.isDirectory()) continue;
33456
33977
  if (entry.name.startsWith("_") || entry.name.startsWith(".")) continue;
33457
33978
  if (excludeDirs && d === dir && excludeDirs.includes(entry.name)) continue;
33458
- scan(path14.join(d, entry.name));
33979
+ scan(path13.join(d, entry.name));
33459
33980
  }
33460
33981
  }
33461
33982
  };
@@ -33714,8 +34235,8 @@ function detectCurrentWorkspace(ideId) {
33714
34235
  const appNameMap = getMacAppIdentifiers();
33715
34236
  const appName = appNameMap[ideId];
33716
34237
  if (appName) {
33717
- const storagePath = path15.join(
33718
- process.env.APPDATA || path15.join(os16.homedir(), "AppData", "Roaming"),
34238
+ const storagePath = path14.join(
34239
+ process.env.APPDATA || path14.join(os16.homedir(), "AppData", "Roaming"),
33719
34240
  appName,
33720
34241
  "storage.json"
33721
34242
  );
@@ -33886,14 +34407,14 @@ async function launchLinux(ide, port, workspace, newWindow) {
33886
34407
  function getAvailableIdeIds() {
33887
34408
  return getProviderLoader().getAvailableIdeTypes();
33888
34409
  }
33889
- var import_child_process6, net2, os16, path15, _providerLoader;
34410
+ var import_child_process6, net2, os16, path14, _providerLoader;
33890
34411
  var init_launch = __esm({
33891
34412
  "../../oss/packages/daemon-core/src/launch.ts"() {
33892
34413
  "use strict";
33893
34414
  import_child_process6 = require("child_process");
33894
34415
  net2 = __toESM(require("net"));
33895
34416
  os16 = __toESM(require("os"));
33896
- path15 = __toESM(require("path"));
34417
+ path14 = __toESM(require("path"));
33897
34418
  init_ide_detector();
33898
34419
  init_provider_loader();
33899
34420
  _providerLoader = null;
@@ -33924,7 +34445,7 @@ function checkRotation() {
33924
34445
  const today = getDateStr2();
33925
34446
  if (today !== currentDate2) {
33926
34447
  currentDate2 = today;
33927
- currentFile = path16.join(LOG_DIR2, `commands-${currentDate2}.jsonl`);
34448
+ currentFile = path15.join(LOG_DIR2, `commands-${currentDate2}.jsonl`);
33928
34449
  cleanOldFiles();
33929
34450
  }
33930
34451
  }
@@ -33938,7 +34459,7 @@ function cleanOldFiles() {
33938
34459
  const dateMatch = file2.match(/commands-(\d{4}-\d{2}-\d{2})/);
33939
34460
  if (dateMatch && dateMatch[1] < cutoffStr) {
33940
34461
  try {
33941
- fs7.unlinkSync(path16.join(LOG_DIR2, file2));
34462
+ fs7.unlinkSync(path15.join(LOG_DIR2, file2));
33942
34463
  } catch {
33943
34464
  }
33944
34465
  }
@@ -34007,14 +34528,14 @@ function getRecentCommands(count = 50) {
34007
34528
  return [];
34008
34529
  }
34009
34530
  }
34010
- var fs7, path16, os17, LOG_DIR2, MAX_FILE_SIZE, MAX_DAYS, SENSITIVE_KEYS, currentDate2, currentFile, writeCount2, SKIP_COMMANDS;
34531
+ var fs7, path15, os17, LOG_DIR2, MAX_FILE_SIZE, MAX_DAYS, SENSITIVE_KEYS, currentDate2, currentFile, writeCount2, SKIP_COMMANDS;
34011
34532
  var init_command_log = __esm({
34012
34533
  "../../oss/packages/daemon-core/src/logging/command-log.ts"() {
34013
34534
  "use strict";
34014
34535
  fs7 = __toESM(require("fs"));
34015
- path16 = __toESM(require("path"));
34536
+ path15 = __toESM(require("path"));
34016
34537
  os17 = __toESM(require("os"));
34017
- LOG_DIR2 = process.platform === "win32" ? path16.join(process.env.LOCALAPPDATA || process.env.APPDATA || path16.join(os17.homedir(), "AppData", "Local"), "adhdev", "logs") : process.platform === "darwin" ? path16.join(os17.homedir(), "Library", "Logs", "adhdev") : path16.join(os17.homedir(), ".local", "share", "adhdev", "logs");
34538
+ LOG_DIR2 = process.platform === "win32" ? path15.join(process.env.LOCALAPPDATA || process.env.APPDATA || path15.join(os17.homedir(), "AppData", "Local"), "adhdev", "logs") : process.platform === "darwin" ? path15.join(os17.homedir(), "Library", "Logs", "adhdev") : path15.join(os17.homedir(), ".local", "share", "adhdev", "logs");
34018
34539
  MAX_FILE_SIZE = 5 * 1024 * 1024;
34019
34540
  MAX_DAYS = 7;
34020
34541
  try {
@@ -34033,7 +34554,7 @@ var init_command_log = __esm({
34033
34554
  "text"
34034
34555
  ]);
34035
34556
  currentDate2 = getDateStr2();
34036
- currentFile = path16.join(LOG_DIR2, `commands-${currentDate2}.jsonl`);
34557
+ currentFile = path15.join(LOG_DIR2, `commands-${currentDate2}.jsonl`);
34037
34558
  writeCount2 = 0;
34038
34559
  SKIP_COMMANDS = /* @__PURE__ */ new Set([
34039
34560
  "heartbeat",
@@ -34187,6 +34708,9 @@ function parseMessageTime(value) {
34187
34708
  }
34188
34709
  return 0;
34189
34710
  }
34711
+ function getMessageEventTime(message) {
34712
+ return parseMessageTime(message?.receivedAt) || parseMessageTime(message?.timestamp) || 0;
34713
+ }
34190
34714
  function stringifyPreviewContent(content) {
34191
34715
  if (typeof content === "string") return content;
34192
34716
  if (Array.isArray(content)) {
@@ -34231,7 +34755,7 @@ function getLastDisplayMessage(session) {
34231
34755
  return {
34232
34756
  role,
34233
34757
  preview,
34234
- receivedAt: parseMessageTime(candidate?.receivedAt),
34758
+ receivedAt: getMessageEventTime(candidate),
34235
34759
  hash: simplePreviewHash(`${role}:${preview}`)
34236
34760
  };
34237
34761
  }
@@ -34240,7 +34764,7 @@ function getLastDisplayMessage(session) {
34240
34764
  function getSessionMessageUpdatedAt(session) {
34241
34765
  const lastMessage = session.activeChat?.messages?.at?.(-1);
34242
34766
  if (!lastMessage) return 0;
34243
- return parseMessageTime(lastMessage.receivedAt) || 0;
34767
+ return getMessageEventTime(lastMessage);
34244
34768
  }
34245
34769
  function getSessionCompletionMarker(session) {
34246
34770
  const lastMessage = session.activeChat?.messages?.at?.(-1);
@@ -34250,7 +34774,7 @@ function getSessionCompletionMarker(session) {
34250
34774
  if (typeof lastMessage._turnKey === "string" && lastMessage._turnKey) return `turn:${lastMessage._turnKey}`;
34251
34775
  if (typeof lastMessage.id === "string" && lastMessage.id) return `id:${lastMessage.id}`;
34252
34776
  if (typeof lastMessage.index === "number" && Number.isFinite(lastMessage.index)) return `idx:${lastMessage.index}`;
34253
- const timestamp = parseMessageTime(lastMessage.receivedAt);
34777
+ const timestamp = getMessageEventTime(lastMessage);
34254
34778
  return timestamp > 0 ? `ts:${timestamp}` : "";
34255
34779
  }
34256
34780
  function getSessionLastUsedAt(session) {
@@ -34390,9 +34914,9 @@ var init_snapshot = __esm({
34390
34914
  // ../../oss/packages/daemon-core/src/commands/upgrade-helper.ts
34391
34915
  function getUpgradeLogPath() {
34392
34916
  const home = os19.homedir();
34393
- const dir = path17.join(home, ".adhdev");
34917
+ const dir = path16.join(home, ".adhdev");
34394
34918
  fs8.mkdirSync(dir, { recursive: true });
34395
- return path17.join(dir, "daemon-upgrade.log");
34919
+ return path16.join(dir, "daemon-upgrade.log");
34396
34920
  }
34397
34921
  function appendUpgradeLog(message) {
34398
34922
  const line = `[${(/* @__PURE__ */ new Date()).toISOString()}] ${message}
@@ -34432,7 +34956,7 @@ async function waitForPidExit(pid, timeoutMs) {
34432
34956
  }
34433
34957
  }
34434
34958
  function stopSessionHostProcesses(appName) {
34435
- const pidFile = path17.join(os19.homedir(), ".adhdev", `${appName}-session-host.pid`);
34959
+ const pidFile = path16.join(os19.homedir(), ".adhdev", `${appName}-session-host.pid`);
34436
34960
  try {
34437
34961
  if (fs8.existsSync(pidFile)) {
34438
34962
  const pid = Number.parseInt(fs8.readFileSync(pidFile, "utf8").trim(), 10);
@@ -34461,7 +34985,7 @@ function stopSessionHostProcesses(appName) {
34461
34985
  }
34462
34986
  }
34463
34987
  function removeDaemonPidFile() {
34464
- const pidFile = path17.join(os19.homedir(), ".adhdev", "daemon.pid");
34988
+ const pidFile = path16.join(os19.homedir(), ".adhdev", "daemon.pid");
34465
34989
  try {
34466
34990
  fs8.unlinkSync(pidFile);
34467
34991
  } catch {
@@ -34472,7 +34996,7 @@ function cleanupStaleGlobalInstallDirs(pkgName) {
34472
34996
  const npmRoot = (0, import_child_process7.execFileSync)(getNpmExecutable(), ["root", "-g"], { encoding: "utf8", ...npmExecOpts }).trim();
34473
34997
  if (!npmRoot) return;
34474
34998
  const npmPrefix = (0, import_child_process7.execFileSync)(getNpmExecutable(), ["prefix", "-g"], { encoding: "utf8", ...npmExecOpts }).trim();
34475
- const binDir = process.platform === "win32" ? npmPrefix : path17.join(npmPrefix, "bin");
34999
+ const binDir = process.platform === "win32" ? npmPrefix : path16.join(npmPrefix, "bin");
34476
35000
  const packageBaseName = pkgName.startsWith("@") ? pkgName.split("/")[1] : pkgName;
34477
35001
  const binNames = /* @__PURE__ */ new Set([packageBaseName]);
34478
35002
  if (pkgName === "@adhdev/daemon-standalone") {
@@ -34480,25 +35004,25 @@ function cleanupStaleGlobalInstallDirs(pkgName) {
34480
35004
  }
34481
35005
  if (pkgName.startsWith("@")) {
34482
35006
  const [scope, name] = pkgName.split("/");
34483
- const scopeDir = path17.join(npmRoot, scope);
35007
+ const scopeDir = path16.join(npmRoot, scope);
34484
35008
  if (!fs8.existsSync(scopeDir)) return;
34485
35009
  for (const entry of fs8.readdirSync(scopeDir)) {
34486
35010
  if (!entry.startsWith(`.${name}-`)) continue;
34487
- fs8.rmSync(path17.join(scopeDir, entry), { recursive: true, force: true });
34488
- appendUpgradeLog(`Removed stale scoped staging dir: ${path17.join(scopeDir, entry)}`);
35011
+ fs8.rmSync(path16.join(scopeDir, entry), { recursive: true, force: true });
35012
+ appendUpgradeLog(`Removed stale scoped staging dir: ${path16.join(scopeDir, entry)}`);
34489
35013
  }
34490
35014
  } else {
34491
35015
  for (const entry of fs8.readdirSync(npmRoot)) {
34492
35016
  if (!entry.startsWith(`.${pkgName}-`)) continue;
34493
- fs8.rmSync(path17.join(npmRoot, entry), { recursive: true, force: true });
34494
- appendUpgradeLog(`Removed stale staging dir: ${path17.join(npmRoot, entry)}`);
35017
+ fs8.rmSync(path16.join(npmRoot, entry), { recursive: true, force: true });
35018
+ appendUpgradeLog(`Removed stale staging dir: ${path16.join(npmRoot, entry)}`);
34495
35019
  }
34496
35020
  }
34497
35021
  if (fs8.existsSync(binDir)) {
34498
35022
  for (const entry of fs8.readdirSync(binDir)) {
34499
35023
  if (![...binNames].some((name) => entry.startsWith(`.${name}-`))) continue;
34500
- fs8.rmSync(path17.join(binDir, entry), { recursive: true, force: true });
34501
- appendUpgradeLog(`Removed stale bin staging entry: ${path17.join(binDir, entry)}`);
35024
+ fs8.rmSync(path16.join(binDir, entry), { recursive: true, force: true });
35025
+ appendUpgradeLog(`Removed stale bin staging entry: ${path16.join(binDir, entry)}`);
34502
35026
  }
34503
35027
  }
34504
35028
  }
@@ -34573,7 +35097,7 @@ async function maybeRunDaemonUpgradeHelperFromEnv() {
34573
35097
  process.exit(1);
34574
35098
  }
34575
35099
  }
34576
- var import_child_process7, import_child_process8, fs8, os19, path17, UPGRADE_HELPER_ENV;
35100
+ var import_child_process7, import_child_process8, fs8, os19, path16, UPGRADE_HELPER_ENV;
34577
35101
  var init_upgrade_helper = __esm({
34578
35102
  "../../oss/packages/daemon-core/src/commands/upgrade-helper.ts"() {
34579
35103
  "use strict";
@@ -34581,7 +35105,7 @@ var init_upgrade_helper = __esm({
34581
35105
  import_child_process8 = require("child_process");
34582
35106
  fs8 = __toESM(require("fs"));
34583
35107
  os19 = __toESM(require("os"));
34584
- path17 = __toESM(require("path"));
35108
+ path16 = __toESM(require("path"));
34585
35109
  UPGRADE_HELPER_ENV = "ADHDEV_DAEMON_UPGRADE_HELPER";
34586
35110
  }
34587
35111
  });
@@ -35582,7 +36106,9 @@ var init_provider_adapter = __esm({
35582
36106
  "../../oss/packages/daemon-core/src/agent-stream/provider-adapter.ts"() {
35583
36107
  "use strict";
35584
36108
  init_control_effects();
36109
+ init_read_chat_contract();
35585
36110
  init_provider_patch_state();
36111
+ init_chat_message_normalization();
35586
36112
  ProviderStreamAdapter = class {
35587
36113
  agentType;
35588
36114
  agentName;
@@ -35687,26 +36213,29 @@ var init_provider_adapter = __esm({
35687
36213
  }
35688
36214
  return state2;
35689
36215
  }
36216
+ const validated = validateReadChatResultPayload(data, `${this.agentType} readChat`);
36217
+ const validatedStatus = validated.status;
36218
+ const streamStatus = validatedStatus === "generating" || validatedStatus === "long_generating" ? "streaming" : validatedStatus;
35690
36219
  const state = {
35691
36220
  agentType: this.agentType,
35692
36221
  agentName: this.agentName,
35693
36222
  extensionId: this.extensionId,
35694
- status: data.status || "idle",
35695
- messages: data.messages || [],
35696
- inputContent: data.inputContent || "",
35697
- activeModal: data.activeModal
36223
+ status: streamStatus,
36224
+ messages: normalizeChatMessages(validated.messages),
36225
+ inputContent: typeof validated.inputContent === "string" ? validated.inputContent : "",
36226
+ ...validated.activeModal ? { activeModal: validated.activeModal } : {}
35698
36227
  };
35699
- if (typeof data.title === "string" && data.title.trim()) {
35700
- state.title = data.title.trim();
36228
+ if (typeof validated.title === "string" && validated.title.trim()) {
36229
+ state.title = validated.title.trim();
35701
36230
  }
35702
- const controlValues = extractProviderControlValues(this.provider.controls, data);
36231
+ const controlValues = extractProviderControlValues(this.provider.controls, validated);
35703
36232
  const surface = resolveProviderStateSurface({
35704
36233
  controlValues,
35705
- summaryMetadata: data.summaryMetadata
36234
+ summaryMetadata: validated.summaryMetadata
35706
36235
  });
35707
36236
  if (surface.controlValues) state.controlValues = surface.controlValues;
35708
36237
  if (surface.summaryMetadata) state.summaryMetadata = surface.summaryMetadata;
35709
- const effects = normalizeProviderEffects(data);
36238
+ const effects = normalizeProviderEffects(validated);
35710
36239
  if (effects.length > 0) state.effects = effects;
35711
36240
  if (state.messages.length > 0) {
35712
36241
  this.lastSuccessState = state;
@@ -36643,7 +37172,7 @@ function checkPathExists2(paths) {
36643
37172
  for (const p of paths) {
36644
37173
  if (p.includes("*")) {
36645
37174
  const home = os20.homedir();
36646
- const resolved = p.replace(/\*/g, home.split(path18.sep).pop() || "");
37175
+ const resolved = p.replace(/\*/g, home.split(path17.sep).pop() || "");
36647
37176
  if (fs10.existsSync(resolved)) return resolved;
36648
37177
  } else {
36649
37178
  if (fs10.existsSync(p)) return p;
@@ -36653,7 +37182,7 @@ function checkPathExists2(paths) {
36653
37182
  }
36654
37183
  function getMacAppVersion(appPath) {
36655
37184
  if ((0, import_os3.platform)() !== "darwin" || !appPath.endsWith(".app")) return null;
36656
- const plistPath = path18.join(appPath, "Contents", "Info.plist");
37185
+ const plistPath = path17.join(appPath, "Contents", "Info.plist");
36657
37186
  if (!fs10.existsSync(plistPath)) return null;
36658
37187
  const raw = runCommand(`/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "${plistPath}"`);
36659
37188
  return raw || null;
@@ -36679,7 +37208,7 @@ async function detectAllVersions(loader, archive) {
36679
37208
  const cliBin = provider.cli ? findBinary2(provider.cli) : null;
36680
37209
  let resolvedBin = cliBin;
36681
37210
  if (!resolvedBin && appPath && currentOs === "darwin") {
36682
- const bundled = path18.join(appPath, "Contents", "Resources", "app", "bin", provider.cli || "");
37211
+ const bundled = path17.join(appPath, "Contents", "Resources", "app", "bin", provider.cli || "");
36683
37212
  if (provider.cli && fs10.existsSync(bundled)) resolvedBin = bundled;
36684
37213
  }
36685
37214
  info.installed = !!(appPath || resolvedBin);
@@ -36716,16 +37245,16 @@ async function detectAllVersions(loader, archive) {
36716
37245
  }
36717
37246
  return results;
36718
37247
  }
36719
- var fs10, path18, os20, import_child_process9, import_os3, ARCHIVE_PATH, MAX_ENTRIES_PER_PROVIDER, VersionArchive;
37248
+ var fs10, path17, os20, import_child_process9, import_os3, ARCHIVE_PATH, MAX_ENTRIES_PER_PROVIDER, VersionArchive;
36720
37249
  var init_version_archive = __esm({
36721
37250
  "../../oss/packages/daemon-core/src/providers/version-archive.ts"() {
36722
37251
  "use strict";
36723
37252
  fs10 = __toESM(require("fs"));
36724
- path18 = __toESM(require("path"));
37253
+ path17 = __toESM(require("path"));
36725
37254
  os20 = __toESM(require("os"));
36726
37255
  import_child_process9 = require("child_process");
36727
37256
  import_os3 = require("os");
36728
- ARCHIVE_PATH = path18.join(os20.homedir(), ".adhdev", "version-history.json");
37257
+ ARCHIVE_PATH = path17.join(os20.homedir(), ".adhdev", "version-history.json");
36729
37258
  MAX_ENTRIES_PER_PROVIDER = 20;
36730
37259
  VersionArchive = class {
36731
37260
  history = {};
@@ -36772,7 +37301,7 @@ var init_version_archive = __esm({
36772
37301
  }
36773
37302
  save() {
36774
37303
  try {
36775
- fs10.mkdirSync(path18.dirname(ARCHIVE_PATH), { recursive: true });
37304
+ fs10.mkdirSync(path17.dirname(ARCHIVE_PATH), { recursive: true });
36776
37305
  fs10.writeFileSync(ARCHIVE_PATH, JSON.stringify(this.history, null, 2));
36777
37306
  } catch {
36778
37307
  }
@@ -37300,17 +37829,17 @@ async function handleScriptHints(ctx, type, _req, res) {
37300
37829
  return;
37301
37830
  }
37302
37831
  let scriptsPath = "";
37303
- const directScripts = path19.join(dir, "scripts.js");
37832
+ const directScripts = path18.join(dir, "scripts.js");
37304
37833
  if (fs11.existsSync(directScripts)) {
37305
37834
  scriptsPath = directScripts;
37306
37835
  } else {
37307
- const scriptsDir = path19.join(dir, "scripts");
37836
+ const scriptsDir = path18.join(dir, "scripts");
37308
37837
  if (fs11.existsSync(scriptsDir)) {
37309
37838
  const versions = fs11.readdirSync(scriptsDir).filter((d) => {
37310
- return fs11.statSync(path19.join(scriptsDir, d)).isDirectory();
37839
+ return fs11.statSync(path18.join(scriptsDir, d)).isDirectory();
37311
37840
  }).sort().reverse();
37312
37841
  for (const ver of versions) {
37313
- const p = path19.join(scriptsDir, ver, "scripts.js");
37842
+ const p = path18.join(scriptsDir, ver, "scripts.js");
37314
37843
  if (fs11.existsSync(p)) {
37315
37844
  scriptsPath = p;
37316
37845
  break;
@@ -38136,12 +38665,12 @@ async function handleDomContext(ctx, type, req, res) {
38136
38665
  ctx.json(res, 500, { error: `DOM context collection failed: ${e.message}` });
38137
38666
  }
38138
38667
  }
38139
- var fs11, path19;
38668
+ var fs11, path18;
38140
38669
  var init_dev_cdp_handlers = __esm({
38141
38670
  "../../oss/packages/daemon-core/src/daemon/dev-cdp-handlers.ts"() {
38142
38671
  "use strict";
38143
38672
  fs11 = __toESM(require("fs"));
38144
- path19 = __toESM(require("path"));
38673
+ path18 = __toESM(require("path"));
38145
38674
  init_logger();
38146
38675
  }
38147
38676
  });
@@ -38156,11 +38685,11 @@ function getCliFixtureDir(ctx, type) {
38156
38685
  if (!providerDir) {
38157
38686
  throw new Error(`Provider directory not found for '${type}'`);
38158
38687
  }
38159
- return path20.join(providerDir, "fixtures");
38688
+ return path19.join(providerDir, "fixtures");
38160
38689
  }
38161
38690
  function readCliFixture(ctx, type, name) {
38162
38691
  const fixtureDir = getCliFixtureDir(ctx, type);
38163
- const filePath = path20.join(fixtureDir, `${name}.json`);
38692
+ const filePath = path19.join(fixtureDir, `${name}.json`);
38164
38693
  if (!fs12.existsSync(filePath)) {
38165
38694
  throw new Error(`Fixture not found: ${filePath}`);
38166
38695
  }
@@ -38927,7 +39456,7 @@ async function handleCliFixtureCapture(ctx, req, res) {
38927
39456
  },
38928
39457
  notes: typeof body?.notes === "string" ? body.notes : void 0
38929
39458
  };
38930
- const filePath = path20.join(fixtureDir, `${name}.json`);
39459
+ const filePath = path19.join(fixtureDir, `${name}.json`);
38931
39460
  fs12.writeFileSync(filePath, JSON.stringify(fixture, null, 2));
38932
39461
  ctx.json(res, 200, {
38933
39462
  saved: true,
@@ -38951,7 +39480,7 @@ async function handleCliFixtureList(ctx, type, _req, res) {
38951
39480
  return;
38952
39481
  }
38953
39482
  const fixtures = fs12.readdirSync(fixtureDir).filter((file2) => file2.endsWith(".json")).sort((a, b) => b.localeCompare(a, void 0, { numeric: true, sensitivity: "base" })).map((file2) => {
38954
- const fullPath = path20.join(fixtureDir, file2);
39483
+ const fullPath = path19.join(fixtureDir, file2);
38955
39484
  try {
38956
39485
  const raw = JSON.parse(fs12.readFileSync(fullPath, "utf-8"));
38957
39486
  return {
@@ -39084,12 +39613,12 @@ async function handleCliRaw(ctx, req, res) {
39084
39613
  ctx.json(res, 500, { error: `Raw send failed: ${e.message}` });
39085
39614
  }
39086
39615
  }
39087
- var fs12, path20;
39616
+ var fs12, path19;
39088
39617
  var init_dev_cli_debug = __esm({
39089
39618
  "../../oss/packages/daemon-core/src/daemon/dev-cli-debug.ts"() {
39090
39619
  "use strict";
39091
39620
  fs12 = __toESM(require("fs"));
39092
- path20 = __toESM(require("path"));
39621
+ path19 = __toESM(require("path"));
39093
39622
  }
39094
39623
  });
39095
39624
 
@@ -39149,22 +39678,22 @@ function getLatestScriptVersionDir(scriptsDir) {
39149
39678
  if (!fs13.existsSync(scriptsDir)) return null;
39150
39679
  const versions = fs13.readdirSync(scriptsDir).filter((d) => {
39151
39680
  try {
39152
- return fs13.statSync(path21.join(scriptsDir, d)).isDirectory();
39681
+ return fs13.statSync(path20.join(scriptsDir, d)).isDirectory();
39153
39682
  } catch {
39154
39683
  return false;
39155
39684
  }
39156
39685
  }).sort((a, b) => b.localeCompare(a, void 0, { numeric: true, sensitivity: "base" }));
39157
39686
  if (versions.length === 0) return null;
39158
- return path21.join(scriptsDir, versions[0]);
39687
+ return path20.join(scriptsDir, versions[0]);
39159
39688
  }
39160
39689
  function resolveAutoImplWritableProviderDir(ctx, category, type, requestedDir) {
39161
- const canonicalUserDir = path21.resolve(ctx.providerLoader.getUserProviderDir(category, type));
39162
- const desiredDir = requestedDir ? path21.resolve(requestedDir) : canonicalUserDir;
39163
- const upstreamRoot = path21.resolve(ctx.providerLoader.getUpstreamDir());
39164
- if (desiredDir === upstreamRoot || desiredDir.startsWith(`${upstreamRoot}${path21.sep}`)) {
39690
+ const canonicalUserDir = path20.resolve(ctx.providerLoader.getUserProviderDir(category, type));
39691
+ const desiredDir = requestedDir ? path20.resolve(requestedDir) : canonicalUserDir;
39692
+ const upstreamRoot = path20.resolve(ctx.providerLoader.getUpstreamDir());
39693
+ if (desiredDir === upstreamRoot || desiredDir.startsWith(`${upstreamRoot}${path20.sep}`)) {
39165
39694
  return { dir: null, reason: `Refusing to write into upstream provider directory: ${desiredDir}` };
39166
39695
  }
39167
- if (path21.basename(desiredDir) !== type) {
39696
+ if (path20.basename(desiredDir) !== type) {
39168
39697
  return { dir: null, reason: `Requested writable provider directory must end with '${type}': ${desiredDir}` };
39169
39698
  }
39170
39699
  const sourceDir = ctx.findProviderDir(type);
@@ -39172,11 +39701,11 @@ function resolveAutoImplWritableProviderDir(ctx, category, type, requestedDir) {
39172
39701
  return { dir: null, reason: `Provider source directory not found for '${type}'` };
39173
39702
  }
39174
39703
  if (!fs13.existsSync(desiredDir)) {
39175
- fs13.mkdirSync(path21.dirname(desiredDir), { recursive: true });
39704
+ fs13.mkdirSync(path20.dirname(desiredDir), { recursive: true });
39176
39705
  fs13.cpSync(sourceDir, desiredDir, { recursive: true });
39177
39706
  ctx.log(`Auto-implement writable copy created: ${desiredDir}`);
39178
39707
  }
39179
- const providerJson = path21.join(desiredDir, "provider.json");
39708
+ const providerJson = path20.join(desiredDir, "provider.json");
39180
39709
  if (!fs13.existsSync(providerJson)) {
39181
39710
  return { dir: null, reason: `provider.json not found in writable provider directory: ${desiredDir}` };
39182
39711
  }
@@ -39187,13 +39716,13 @@ function loadAutoImplReferenceScripts(ctx, referenceType) {
39187
39716
  const refDir = ctx.findProviderDir(referenceType);
39188
39717
  if (!refDir || !fs13.existsSync(refDir)) return {};
39189
39718
  const referenceScripts = {};
39190
- const scriptsDir = path21.join(refDir, "scripts");
39719
+ const scriptsDir = path20.join(refDir, "scripts");
39191
39720
  const latestDir = getLatestScriptVersionDir(scriptsDir);
39192
39721
  if (!latestDir) return referenceScripts;
39193
39722
  for (const file2 of fs13.readdirSync(latestDir)) {
39194
39723
  if (!file2.endsWith(".js")) continue;
39195
39724
  try {
39196
- referenceScripts[file2] = fs13.readFileSync(path21.join(latestDir, file2), "utf-8");
39725
+ referenceScripts[file2] = fs13.readFileSync(path20.join(latestDir, file2), "utf-8");
39197
39726
  } catch {
39198
39727
  }
39199
39728
  }
@@ -39301,9 +39830,9 @@ async function handleAutoImplement(ctx, type, req, res) {
39301
39830
  });
39302
39831
  const referenceScripts = loadAutoImplReferenceScripts(ctx, resolvedReference);
39303
39832
  const prompt2 = buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domContext, referenceScripts, comment, resolvedReference, verification);
39304
- const tmpDir = path21.join(os21.tmpdir(), "adhdev-autoimpl");
39833
+ const tmpDir = path20.join(os21.tmpdir(), "adhdev-autoimpl");
39305
39834
  if (!fs13.existsSync(tmpDir)) fs13.mkdirSync(tmpDir, { recursive: true });
39306
- const promptFile = path21.join(tmpDir, `prompt-${type}-${Date.now()}.md`);
39835
+ const promptFile = path20.join(tmpDir, `prompt-${type}-${Date.now()}.md`);
39307
39836
  fs13.writeFileSync(promptFile, prompt2, "utf-8");
39308
39837
  ctx.log(`Auto-implement prompt written to ${promptFile} (${prompt2.length} chars)`);
39309
39838
  const agentProvider = ctx.providerLoader.resolve(agent) || ctx.providerLoader.getMeta(agent);
@@ -39740,7 +40269,7 @@ function buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domCon
39740
40269
  setMode: "set_mode.js"
39741
40270
  };
39742
40271
  const targetFileNames = new Set(functions.map((fn) => funcToFile[fn]).filter(Boolean));
39743
- const scriptsDir = path21.join(providerDir, "scripts");
40272
+ const scriptsDir = path20.join(providerDir, "scripts");
39744
40273
  const latestScriptsDir = getLatestScriptVersionDir(scriptsDir);
39745
40274
  if (latestScriptsDir) {
39746
40275
  lines.push(`Scripts version directory: \`${latestScriptsDir}\``);
@@ -39751,7 +40280,7 @@ function buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domCon
39751
40280
  for (const file2 of fs13.readdirSync(latestScriptsDir)) {
39752
40281
  if (file2.endsWith(".js") && targetFileNames.has(file2)) {
39753
40282
  try {
39754
- const content = fs13.readFileSync(path21.join(latestScriptsDir, file2), "utf-8");
40283
+ const content = fs13.readFileSync(path20.join(latestScriptsDir, file2), "utf-8");
39755
40284
  lines.push(`### \`${file2}\` \u270F\uFE0F EDIT`);
39756
40285
  lines.push("```javascript");
39757
40286
  lines.push(content);
@@ -39768,7 +40297,7 @@ function buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domCon
39768
40297
  lines.push("");
39769
40298
  for (const file2 of refFiles) {
39770
40299
  try {
39771
- const content = fs13.readFileSync(path21.join(latestScriptsDir, file2), "utf-8");
40300
+ const content = fs13.readFileSync(path20.join(latestScriptsDir, file2), "utf-8");
39772
40301
  lines.push(`### \`${file2}\` \u{1F512}`);
39773
40302
  lines.push("```javascript");
39774
40303
  lines.push(content);
@@ -39809,10 +40338,10 @@ function buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domCon
39809
40338
  lines.push("");
39810
40339
  }
39811
40340
  }
39812
- const docsDir = path21.join(providerDir, "../../docs");
40341
+ const docsDir = path20.join(providerDir, "../../docs");
39813
40342
  const loadGuide = (name) => {
39814
40343
  try {
39815
- const p = path21.join(docsDir, name);
40344
+ const p = path20.join(docsDir, name);
39816
40345
  if (fs13.existsSync(p)) return fs13.readFileSync(p, "utf-8");
39817
40346
  } catch {
39818
40347
  }
@@ -40049,7 +40578,7 @@ function buildCliAutoImplPrompt(ctx, type, provider, providerDir, functions, ref
40049
40578
  parseApproval: "parse_approval.js"
40050
40579
  };
40051
40580
  const targetFileNames = new Set(functions.map((fn) => funcToFile[fn]).filter(Boolean));
40052
- const scriptsDir = path21.join(providerDir, "scripts");
40581
+ const scriptsDir = path20.join(providerDir, "scripts");
40053
40582
  const latestScriptsDir = getLatestScriptVersionDir(scriptsDir);
40054
40583
  if (latestScriptsDir) {
40055
40584
  lines.push(`Scripts version directory: \`${latestScriptsDir}\``);
@@ -40061,7 +40590,7 @@ function buildCliAutoImplPrompt(ctx, type, provider, providerDir, functions, ref
40061
40590
  if (!file2.endsWith(".js")) continue;
40062
40591
  if (!targetFileNames.has(file2)) continue;
40063
40592
  try {
40064
- const content = fs13.readFileSync(path21.join(latestScriptsDir, file2), "utf-8");
40593
+ const content = fs13.readFileSync(path20.join(latestScriptsDir, file2), "utf-8");
40065
40594
  lines.push(`### \`${file2}\` \u270F\uFE0F EDIT`);
40066
40595
  lines.push("```javascript");
40067
40596
  lines.push(content);
@@ -40077,7 +40606,7 @@ function buildCliAutoImplPrompt(ctx, type, provider, providerDir, functions, ref
40077
40606
  lines.push("");
40078
40607
  for (const file2 of refFiles) {
40079
40608
  try {
40080
- const content = fs13.readFileSync(path21.join(latestScriptsDir, file2), "utf-8");
40609
+ const content = fs13.readFileSync(path20.join(latestScriptsDir, file2), "utf-8");
40081
40610
  lines.push(`### \`${file2}\` \u{1F512}`);
40082
40611
  lines.push("```javascript");
40083
40612
  lines.push(content);
@@ -40110,10 +40639,10 @@ function buildCliAutoImplPrompt(ctx, type, provider, providerDir, functions, ref
40110
40639
  lines.push("");
40111
40640
  }
40112
40641
  }
40113
- const docsDir = path21.join(providerDir, "../../docs");
40642
+ const docsDir = path20.join(providerDir, "../../docs");
40114
40643
  const loadGuide = (name) => {
40115
40644
  try {
40116
- const p = path21.join(docsDir, name);
40645
+ const p = path20.join(docsDir, name);
40117
40646
  if (fs13.existsSync(p)) return fs13.readFileSync(p, "utf-8");
40118
40647
  } catch {
40119
40648
  }
@@ -40425,12 +40954,12 @@ data: ${JSON.stringify(msg.data)}
40425
40954
  }
40426
40955
  }
40427
40956
  }
40428
- var fs13, path21, os21;
40957
+ var fs13, path20, os21;
40429
40958
  var init_dev_auto_implement = __esm({
40430
40959
  "../../oss/packages/daemon-core/src/daemon/dev-auto-implement.ts"() {
40431
40960
  "use strict";
40432
40961
  fs13 = __toESM(require("fs"));
40433
- path21 = __toESM(require("path"));
40962
+ path20 = __toESM(require("path"));
40434
40963
  os21 = __toESM(require("os"));
40435
40964
  init_dev_server();
40436
40965
  init_dev_cli_debug();
@@ -40470,13 +40999,13 @@ function toProviderListEntry(provider) {
40470
40999
  }
40471
41000
  return base;
40472
41001
  }
40473
- var http2, fs14, path23, DEV_SERVER_PORT, DevServer;
41002
+ var http2, fs14, path21, DEV_SERVER_PORT, DevServer;
40474
41003
  var init_dev_server = __esm({
40475
41004
  "../../oss/packages/daemon-core/src/daemon/dev-server.ts"() {
40476
41005
  "use strict";
40477
41006
  http2 = __toESM(require("http"));
40478
41007
  fs14 = __toESM(require("fs"));
40479
- path23 = __toESM(require("path"));
41008
+ path21 = __toESM(require("path"));
40480
41009
  init_provider_schema();
40481
41010
  init_config();
40482
41011
  init_provider_source_config();
@@ -40588,8 +41117,8 @@ var init_dev_server = __esm({
40588
41117
  }
40589
41118
  getEndpointList() {
40590
41119
  return this.routes.map((r) => {
40591
- const path30 = typeof r.pattern === "string" ? r.pattern : r.pattern.source.replace(/\\\//g, "/").replace(/\(\[.*?\]\+\)/g, ":type").replace(/[\^$]/g, "");
40592
- return `${r.method.padEnd(5)} ${path30}`;
41120
+ const path29 = typeof r.pattern === "string" ? r.pattern : r.pattern.source.replace(/\\\//g, "/").replace(/\(\[.*?\]\+\)/g, ":type").replace(/[\^$]/g, "");
41121
+ return `${r.method.padEnd(5)} ${path29}`;
40593
41122
  });
40594
41123
  }
40595
41124
  async start(port = DEV_SERVER_PORT) {
@@ -40870,12 +41399,12 @@ var init_dev_server = __esm({
40870
41399
  // ─── DevConsole SPA ───
40871
41400
  getConsoleDistDir() {
40872
41401
  const candidates = [
40873
- path23.resolve(__dirname, "../../web-devconsole/dist"),
40874
- path23.resolve(__dirname, "../../../web-devconsole/dist"),
40875
- path23.join(process.cwd(), "packages/web-devconsole/dist")
41402
+ path21.resolve(__dirname, "../../web-devconsole/dist"),
41403
+ path21.resolve(__dirname, "../../../web-devconsole/dist"),
41404
+ path21.join(process.cwd(), "packages/web-devconsole/dist")
40876
41405
  ];
40877
41406
  for (const dir of candidates) {
40878
- if (fs14.existsSync(path23.join(dir, "index.html"))) return dir;
41407
+ if (fs14.existsSync(path21.join(dir, "index.html"))) return dir;
40879
41408
  }
40880
41409
  return null;
40881
41410
  }
@@ -40885,7 +41414,7 @@ var init_dev_server = __esm({
40885
41414
  this.json(res, 500, { error: "DevConsole not found. Run: npm run build -w packages/web-devconsole" });
40886
41415
  return;
40887
41416
  }
40888
- const htmlPath = path23.join(distDir, "index.html");
41417
+ const htmlPath = path21.join(distDir, "index.html");
40889
41418
  try {
40890
41419
  const html = fs14.readFileSync(htmlPath, "utf-8");
40891
41420
  res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
@@ -40910,15 +41439,15 @@ var init_dev_server = __esm({
40910
41439
  this.json(res, 404, { error: "Not found" });
40911
41440
  return;
40912
41441
  }
40913
- const safePath = path23.normalize(pathname).replace(/^\.\.\//, "");
40914
- const filePath = path23.join(distDir, safePath);
41442
+ const safePath = path21.normalize(pathname).replace(/^\.\.\//, "");
41443
+ const filePath = path21.join(distDir, safePath);
40915
41444
  if (!filePath.startsWith(distDir)) {
40916
41445
  this.json(res, 403, { error: "Forbidden" });
40917
41446
  return;
40918
41447
  }
40919
41448
  try {
40920
41449
  const content = fs14.readFileSync(filePath);
40921
- const ext = path23.extname(filePath);
41450
+ const ext = path21.extname(filePath);
40922
41451
  const contentType = _DevServer.MIME_MAP[ext] || "application/octet-stream";
40923
41452
  res.writeHead(200, { "Content-Type": contentType, "Cache-Control": "public, max-age=31536000, immutable" });
40924
41453
  res.end(content);
@@ -41031,9 +41560,9 @@ var init_dev_server = __esm({
41031
41560
  const rel = prefix ? `${prefix}/${entry.name}` : entry.name;
41032
41561
  if (entry.isDirectory()) {
41033
41562
  files.push({ path: rel, size: 0, type: "dir" });
41034
- scan(path23.join(d, entry.name), rel);
41563
+ scan(path21.join(d, entry.name), rel);
41035
41564
  } else {
41036
- const stat4 = fs14.statSync(path23.join(d, entry.name));
41565
+ const stat4 = fs14.statSync(path21.join(d, entry.name));
41037
41566
  files.push({ path: rel, size: stat4.size, type: "file" });
41038
41567
  }
41039
41568
  }
@@ -41056,7 +41585,7 @@ var init_dev_server = __esm({
41056
41585
  this.json(res, 404, { error: `Provider directory not found: ${type}` });
41057
41586
  return;
41058
41587
  }
41059
- const fullPath = path23.resolve(dir, path23.normalize(filePath));
41588
+ const fullPath = path21.resolve(dir, path21.normalize(filePath));
41060
41589
  if (!fullPath.startsWith(dir)) {
41061
41590
  this.json(res, 403, { error: "Forbidden" });
41062
41591
  return;
@@ -41081,14 +41610,14 @@ var init_dev_server = __esm({
41081
41610
  this.json(res, 404, { error: `Provider directory not found: ${type}` });
41082
41611
  return;
41083
41612
  }
41084
- const fullPath = path23.resolve(dir, path23.normalize(filePath));
41613
+ const fullPath = path21.resolve(dir, path21.normalize(filePath));
41085
41614
  if (!fullPath.startsWith(dir)) {
41086
41615
  this.json(res, 403, { error: "Forbidden" });
41087
41616
  return;
41088
41617
  }
41089
41618
  try {
41090
41619
  if (fs14.existsSync(fullPath)) fs14.copyFileSync(fullPath, fullPath + ".bak");
41091
- fs14.mkdirSync(path23.dirname(fullPath), { recursive: true });
41620
+ fs14.mkdirSync(path21.dirname(fullPath), { recursive: true });
41092
41621
  fs14.writeFileSync(fullPath, content, "utf-8");
41093
41622
  this.log(`File saved: ${fullPath} (${content.length} chars)`);
41094
41623
  this.providerLoader.reload();
@@ -41105,7 +41634,7 @@ var init_dev_server = __esm({
41105
41634
  return;
41106
41635
  }
41107
41636
  for (const name of ["scripts.js", "provider.json"]) {
41108
- const p = path23.join(dir, name);
41637
+ const p = path21.join(dir, name);
41109
41638
  if (fs14.existsSync(p)) {
41110
41639
  const source = fs14.readFileSync(p, "utf-8");
41111
41640
  this.json(res, 200, { type, path: p, source, lines: source.split("\n").length });
@@ -41126,8 +41655,8 @@ var init_dev_server = __esm({
41126
41655
  this.json(res, 404, { error: `Provider not found: ${type}` });
41127
41656
  return;
41128
41657
  }
41129
- const target = fs14.existsSync(path23.join(dir, "scripts.js")) ? "scripts.js" : "provider.json";
41130
- const targetPath = path23.join(dir, target);
41658
+ const target = fs14.existsSync(path21.join(dir, "scripts.js")) ? "scripts.js" : "provider.json";
41659
+ const targetPath = path21.join(dir, target);
41131
41660
  try {
41132
41661
  if (fs14.existsSync(targetPath)) fs14.copyFileSync(targetPath, targetPath + ".bak");
41133
41662
  fs14.writeFileSync(targetPath, source, "utf-8");
@@ -41274,7 +41803,7 @@ var init_dev_server = __esm({
41274
41803
  }
41275
41804
  let targetDir;
41276
41805
  targetDir = this.providerLoader.getUserProviderDir(category, type);
41277
- const jsonPath = path23.join(targetDir, "provider.json");
41806
+ const jsonPath = path21.join(targetDir, "provider.json");
41278
41807
  if (fs14.existsSync(jsonPath)) {
41279
41808
  this.json(res, 409, { error: `Provider already exists at ${targetDir}`, path: targetDir });
41280
41809
  return;
@@ -41286,8 +41815,8 @@ var init_dev_server = __esm({
41286
41815
  const createdFiles = ["provider.json"];
41287
41816
  if (result.files) {
41288
41817
  for (const [relPath, content] of Object.entries(result.files)) {
41289
- const fullPath = path23.join(targetDir, relPath);
41290
- fs14.mkdirSync(path23.dirname(fullPath), { recursive: true });
41818
+ const fullPath = path21.join(targetDir, relPath);
41819
+ fs14.mkdirSync(path21.dirname(fullPath), { recursive: true });
41291
41820
  fs14.writeFileSync(fullPath, content, "utf-8");
41292
41821
  createdFiles.push(relPath);
41293
41822
  }
@@ -41340,22 +41869,22 @@ var init_dev_server = __esm({
41340
41869
  if (!fs14.existsSync(scriptsDir)) return null;
41341
41870
  const versions = fs14.readdirSync(scriptsDir).filter((d) => {
41342
41871
  try {
41343
- return fs14.statSync(path23.join(scriptsDir, d)).isDirectory();
41872
+ return fs14.statSync(path21.join(scriptsDir, d)).isDirectory();
41344
41873
  } catch {
41345
41874
  return false;
41346
41875
  }
41347
41876
  }).sort((a, b) => b.localeCompare(a, void 0, { numeric: true, sensitivity: "base" }));
41348
41877
  if (versions.length === 0) return null;
41349
- return path23.join(scriptsDir, versions[0]);
41878
+ return path21.join(scriptsDir, versions[0]);
41350
41879
  }
41351
41880
  resolveAutoImplWritableProviderDir(category, type, requestedDir) {
41352
- const canonicalUserDir = path23.resolve(this.providerLoader.getUserProviderDir(category, type));
41353
- const desiredDir = requestedDir ? path23.resolve(requestedDir) : canonicalUserDir;
41354
- const upstreamRoot = path23.resolve(this.providerLoader.getUpstreamDir());
41355
- if (desiredDir === upstreamRoot || desiredDir.startsWith(`${upstreamRoot}${path23.sep}`)) {
41881
+ const canonicalUserDir = path21.resolve(this.providerLoader.getUserProviderDir(category, type));
41882
+ const desiredDir = requestedDir ? path21.resolve(requestedDir) : canonicalUserDir;
41883
+ const upstreamRoot = path21.resolve(this.providerLoader.getUpstreamDir());
41884
+ if (desiredDir === upstreamRoot || desiredDir.startsWith(`${upstreamRoot}${path21.sep}`)) {
41356
41885
  return { dir: null, reason: `Refusing to write into upstream provider directory: ${desiredDir}` };
41357
41886
  }
41358
- if (path23.basename(desiredDir) !== type) {
41887
+ if (path21.basename(desiredDir) !== type) {
41359
41888
  return { dir: null, reason: `Requested writable provider directory must end with '${type}': ${desiredDir}` };
41360
41889
  }
41361
41890
  const sourceDir = this.findProviderDir(type);
@@ -41363,11 +41892,11 @@ var init_dev_server = __esm({
41363
41892
  return { dir: null, reason: `Provider source directory not found for '${type}'` };
41364
41893
  }
41365
41894
  if (!fs14.existsSync(desiredDir)) {
41366
- fs14.mkdirSync(path23.dirname(desiredDir), { recursive: true });
41895
+ fs14.mkdirSync(path21.dirname(desiredDir), { recursive: true });
41367
41896
  fs14.cpSync(sourceDir, desiredDir, { recursive: true });
41368
41897
  this.log(`Auto-implement writable copy created: ${desiredDir}`);
41369
41898
  }
41370
- const providerJson = path23.join(desiredDir, "provider.json");
41899
+ const providerJson = path21.join(desiredDir, "provider.json");
41371
41900
  if (!fs14.existsSync(providerJson)) {
41372
41901
  return { dir: null, reason: `provider.json not found in writable provider directory: ${desiredDir}` };
41373
41902
  }
@@ -41403,7 +41932,7 @@ var init_dev_server = __esm({
41403
41932
  setMode: "set_mode.js"
41404
41933
  };
41405
41934
  const targetFileNames = new Set(functions.map((fn) => funcToFile[fn]).filter(Boolean));
41406
- const scriptsDir = path23.join(providerDir, "scripts");
41935
+ const scriptsDir = path21.join(providerDir, "scripts");
41407
41936
  const latestScriptsDir = this.getLatestScriptVersionDir(scriptsDir);
41408
41937
  if (latestScriptsDir) {
41409
41938
  lines.push(`Scripts version directory: \`${latestScriptsDir}\``);
@@ -41414,7 +41943,7 @@ var init_dev_server = __esm({
41414
41943
  for (const file2 of fs14.readdirSync(latestScriptsDir)) {
41415
41944
  if (file2.endsWith(".js") && targetFileNames.has(file2)) {
41416
41945
  try {
41417
- const content = fs14.readFileSync(path23.join(latestScriptsDir, file2), "utf-8");
41946
+ const content = fs14.readFileSync(path21.join(latestScriptsDir, file2), "utf-8");
41418
41947
  lines.push(`### \`${file2}\` \u270F\uFE0F EDIT`);
41419
41948
  lines.push("```javascript");
41420
41949
  lines.push(content);
@@ -41431,7 +41960,7 @@ var init_dev_server = __esm({
41431
41960
  lines.push("");
41432
41961
  for (const file2 of refFiles) {
41433
41962
  try {
41434
- const content = fs14.readFileSync(path23.join(latestScriptsDir, file2), "utf-8");
41963
+ const content = fs14.readFileSync(path21.join(latestScriptsDir, file2), "utf-8");
41435
41964
  lines.push(`### \`${file2}\` \u{1F512}`);
41436
41965
  lines.push("```javascript");
41437
41966
  lines.push(content);
@@ -41472,10 +42001,10 @@ var init_dev_server = __esm({
41472
42001
  lines.push("");
41473
42002
  }
41474
42003
  }
41475
- const docsDir = path23.join(providerDir, "../../docs");
42004
+ const docsDir = path21.join(providerDir, "../../docs");
41476
42005
  const loadGuide = (name) => {
41477
42006
  try {
41478
- const p = path23.join(docsDir, name);
42007
+ const p = path21.join(docsDir, name);
41479
42008
  if (fs14.existsSync(p)) return fs14.readFileSync(p, "utf-8");
41480
42009
  } catch {
41481
42010
  }
@@ -41649,7 +42178,7 @@ var init_dev_server = __esm({
41649
42178
  parseApproval: "parse_approval.js"
41650
42179
  };
41651
42180
  const targetFileNames = new Set(functions.map((fn) => funcToFile[fn]).filter(Boolean));
41652
- const scriptsDir = path23.join(providerDir, "scripts");
42181
+ const scriptsDir = path21.join(providerDir, "scripts");
41653
42182
  const latestScriptsDir = this.getLatestScriptVersionDir(scriptsDir);
41654
42183
  if (latestScriptsDir) {
41655
42184
  lines.push(`Scripts version directory: \`${latestScriptsDir}\``);
@@ -41661,7 +42190,7 @@ var init_dev_server = __esm({
41661
42190
  if (!file2.endsWith(".js")) continue;
41662
42191
  if (!targetFileNames.has(file2)) continue;
41663
42192
  try {
41664
- const content = fs14.readFileSync(path23.join(latestScriptsDir, file2), "utf-8");
42193
+ const content = fs14.readFileSync(path21.join(latestScriptsDir, file2), "utf-8");
41665
42194
  lines.push(`### \`${file2}\` \u270F\uFE0F EDIT`);
41666
42195
  lines.push("```javascript");
41667
42196
  lines.push(content);
@@ -41677,7 +42206,7 @@ var init_dev_server = __esm({
41677
42206
  lines.push("");
41678
42207
  for (const file2 of refFiles) {
41679
42208
  try {
41680
- const content = fs14.readFileSync(path23.join(latestScriptsDir, file2), "utf-8");
42209
+ const content = fs14.readFileSync(path21.join(latestScriptsDir, file2), "utf-8");
41681
42210
  lines.push(`### \`${file2}\` \u{1F512}`);
41682
42211
  lines.push("```javascript");
41683
42212
  lines.push(content);
@@ -41710,10 +42239,10 @@ var init_dev_server = __esm({
41710
42239
  lines.push("");
41711
42240
  }
41712
42241
  }
41713
- const docsDir = path23.join(providerDir, "../../docs");
42242
+ const docsDir = path21.join(providerDir, "../../docs");
41714
42243
  const loadGuide = (name) => {
41715
42244
  try {
41716
- const p = path23.join(docsDir, name);
42245
+ const p = path21.join(docsDir, name);
41717
42246
  if (fs14.existsSync(p)) return fs14.readFileSync(p, "utf-8");
41718
42247
  } catch {
41719
42248
  }
@@ -42963,6 +43492,8 @@ __export(src_exports, {
42963
43492
  CdpDomHandlers: () => CdpDomHandlers,
42964
43493
  CliProviderInstance: () => CliProviderInstance,
42965
43494
  DAEMON_WS_PATH: () => DAEMON_WS_PATH,
43495
+ DEFAULT_ACTIVE_CHAT_POLL_STATUSES: () => DEFAULT_ACTIVE_CHAT_POLL_STATUSES,
43496
+ DEFAULT_CHAT_TAIL_RECENT_MESSAGE_GRACE_MS: () => DEFAULT_CHAT_TAIL_RECENT_MESSAGE_GRACE_MS,
42966
43497
  DEFAULT_DAEMON_PORT: () => DEFAULT_DAEMON_PORT,
42967
43498
  DEFAULT_SESSION_HOST_APP_NAME: () => DEFAULT_SESSION_HOST_APP_NAME,
42968
43499
  DEFAULT_STANDALONE_SESSION_HOST_APP_NAME: () => DEFAULT_STANDALONE_SESSION_HOST_APP_NAME,
@@ -42991,7 +43522,11 @@ __export(src_exports, {
42991
43522
  buildSessionEntries: () => buildSessionEntries,
42992
43523
  buildStatusSnapshot: () => buildStatusSnapshot,
42993
43524
  buildSystemChatMessage: () => buildSystemChatMessage,
43525
+ buildTerminalChatMessage: () => buildTerminalChatMessage,
43526
+ buildThoughtChatMessage: () => buildThoughtChatMessage,
43527
+ buildToolChatMessage: () => buildToolChatMessage,
42994
43528
  buildUserChatMessage: () => buildUserChatMessage,
43529
+ classifyHotChatSessionsForSubscriptionFlush: () => classifyHotChatSessionsForSubscriptionFlush,
42995
43530
  clearDebugTrace: () => clearDebugTrace,
42996
43531
  configureDebugTraceStore: () => configureDebugTraceStore,
42997
43532
  connectCdpManager: () => connectCdpManager,
@@ -43058,6 +43593,7 @@ __export(src_exports, {
43058
43593
  resetConfig: () => resetConfig,
43059
43594
  resetDebugRuntimeConfig: () => resetDebugRuntimeConfig,
43060
43595
  resetState: () => resetState,
43596
+ resolveChatMessageKind: () => resolveChatMessageKind,
43061
43597
  resolveDebugRuntimeConfig: () => resolveDebugRuntimeConfig,
43062
43598
  resolveSessionHostAppName: () => resolveSessionHostAppName,
43063
43599
  saveConfig: () => saveConfig,
@@ -43084,6 +43620,7 @@ var init_src = __esm({
43084
43620
  init_ide_detector();
43085
43621
  init_cli_detector();
43086
43622
  init_host_memory();
43623
+ init_chat_tail_hot_sessions();
43087
43624
  init_manager();
43088
43625
  init_devtools();
43089
43626
  init_setup();
@@ -44167,12 +44704,12 @@ var init_peer_connection_manager = __esm({
44167
44704
  });
44168
44705
 
44169
44706
  // src/daemon-p2p/index.ts
44170
- var fs15, path24, import_node_module2, esmRequire, DaemonP2PSender;
44707
+ var fs15, path23, import_node_module2, esmRequire, DaemonP2PSender;
44171
44708
  var init_daemon_p2p = __esm({
44172
44709
  "src/daemon-p2p/index.ts"() {
44173
44710
  "use strict";
44174
44711
  fs15 = __toESM(require("fs"));
44175
- path24 = __toESM(require("path"));
44712
+ path23 = __toESM(require("path"));
44176
44713
  import_node_module2 = require("module");
44177
44714
  init_data_channel_router();
44178
44715
  init_screenshot_sender();
@@ -44245,15 +44782,15 @@ ${e?.stack || ""}`);
44245
44782
  const prebuildKey = `${platform13}-${arch4}`;
44246
44783
  try {
44247
44784
  const candidates = [
44248
- path24.join(__dirname, "node_modules", "node-datachannel"),
44249
- path24.join(__dirname, "..", "node_modules", "node-datachannel"),
44250
- path24.join(__dirname, "..", "..", "node_modules", "node-datachannel")
44785
+ path23.join(__dirname, "node_modules", "node-datachannel"),
44786
+ path23.join(__dirname, "..", "node_modules", "node-datachannel"),
44787
+ path23.join(__dirname, "..", "..", "node_modules", "node-datachannel")
44251
44788
  ];
44252
44789
  for (const candidate of candidates) {
44253
- const prebuildPath = path24.join(candidate, "prebuilds", prebuildKey, "node_datachannel.node");
44790
+ const prebuildPath = path23.join(candidate, "prebuilds", prebuildKey, "node_datachannel.node");
44254
44791
  if (fs15.existsSync(prebuildPath)) {
44255
- const targetDir = path24.join(candidate, "build", "Release");
44256
- const targetPath = path24.join(targetDir, "node_datachannel.node");
44792
+ const targetDir = path23.join(candidate, "build", "Release");
44793
+ const targetPath = path23.join(targetDir, "node_datachannel.node");
44257
44794
  fs15.mkdirSync(targetDir, { recursive: true });
44258
44795
  fs15.copyFileSync(prebuildPath, targetPath);
44259
44796
  try {
@@ -44575,16 +45112,16 @@ var require_filesystem = __commonJS({
44575
45112
  var LDD_PATH = "/usr/bin/ldd";
44576
45113
  var SELF_PATH = "/proc/self/exe";
44577
45114
  var MAX_LENGTH = 2048;
44578
- var readFileSync19 = (path30) => {
44579
- const fd = fs24.openSync(path30, "r");
45115
+ var readFileSync19 = (path29) => {
45116
+ const fd = fs24.openSync(path29, "r");
44580
45117
  const buffer = Buffer.alloc(MAX_LENGTH);
44581
45118
  const bytesRead = fs24.readSync(fd, buffer, 0, MAX_LENGTH, 0);
44582
45119
  fs24.close(fd, () => {
44583
45120
  });
44584
45121
  return buffer.subarray(0, bytesRead);
44585
45122
  };
44586
- var readFile = (path30) => new Promise((resolve15, reject) => {
44587
- fs24.open(path30, "r", (err, fd) => {
45123
+ var readFile = (path29) => new Promise((resolve15, reject) => {
45124
+ fs24.open(path29, "r", (err, fd) => {
44588
45125
  if (err) {
44589
45126
  reject(err);
44590
45127
  } else {
@@ -44703,11 +45240,11 @@ var require_detect_libc = __commonJS({
44703
45240
  }
44704
45241
  return null;
44705
45242
  };
44706
- var familyFromInterpreterPath = (path30) => {
44707
- if (path30) {
44708
- if (path30.includes("/ld-musl-")) {
45243
+ var familyFromInterpreterPath = (path29) => {
45244
+ if (path29) {
45245
+ if (path29.includes("/ld-musl-")) {
44709
45246
  return MUSL;
44710
- } else if (path30.includes("/ld-linux-")) {
45247
+ } else if (path29.includes("/ld-linux-")) {
44711
45248
  return GLIBC;
44712
45249
  }
44713
45250
  }
@@ -44754,8 +45291,8 @@ var require_detect_libc = __commonJS({
44754
45291
  cachedFamilyInterpreter = null;
44755
45292
  try {
44756
45293
  const selfContent = await readFile(SELF_PATH);
44757
- const path30 = interpreterPath(selfContent);
44758
- cachedFamilyInterpreter = familyFromInterpreterPath(path30);
45294
+ const path29 = interpreterPath(selfContent);
45295
+ cachedFamilyInterpreter = familyFromInterpreterPath(path29);
44759
45296
  } catch (e) {
44760
45297
  }
44761
45298
  return cachedFamilyInterpreter;
@@ -44767,8 +45304,8 @@ var require_detect_libc = __commonJS({
44767
45304
  cachedFamilyInterpreter = null;
44768
45305
  try {
44769
45306
  const selfContent = readFileSync19(SELF_PATH);
44770
- const path30 = interpreterPath(selfContent);
44771
- cachedFamilyInterpreter = familyFromInterpreterPath(path30);
45307
+ const path29 = interpreterPath(selfContent);
45308
+ cachedFamilyInterpreter = familyFromInterpreterPath(path29);
44772
45309
  } catch (e) {
44773
45310
  }
44774
45311
  return cachedFamilyInterpreter;
@@ -46487,18 +47024,18 @@ var require_sharp = __commonJS({
46487
47024
  `@img/sharp-${runtimePlatform}/sharp.node`,
46488
47025
  "@img/sharp-wasm32/sharp.node"
46489
47026
  ];
46490
- var path30;
47027
+ var path29;
46491
47028
  var sharp;
46492
47029
  var errors = [];
46493
- for (path30 of paths) {
47030
+ for (path29 of paths) {
46494
47031
  try {
46495
- sharp = require(path30);
47032
+ sharp = require(path29);
46496
47033
  break;
46497
47034
  } catch (err) {
46498
47035
  errors.push(err);
46499
47036
  }
46500
47037
  }
46501
- if (sharp && path30.startsWith("@img/sharp-linux-x64") && !sharp._isUsingX64V2()) {
47038
+ if (sharp && path29.startsWith("@img/sharp-linux-x64") && !sharp._isUsingX64V2()) {
46502
47039
  const err = new Error("Prebuilt binaries for linux-x64 require v2 microarchitecture");
46503
47040
  err.code = "Unsupported CPU";
46504
47041
  errors.push(err);
@@ -49407,15 +49944,15 @@ var require_color = __commonJS({
49407
49944
  };
49408
49945
  }
49409
49946
  function wrapConversion(toModel, graph) {
49410
- const path30 = [graph[toModel].parent, toModel];
49947
+ const path29 = [graph[toModel].parent, toModel];
49411
49948
  let fn = conversions_default[graph[toModel].parent][toModel];
49412
49949
  let cur = graph[toModel].parent;
49413
49950
  while (graph[cur].parent) {
49414
- path30.unshift(graph[cur].parent);
49951
+ path29.unshift(graph[cur].parent);
49415
49952
  fn = link(conversions_default[graph[cur].parent][cur], fn);
49416
49953
  cur = graph[cur].parent;
49417
49954
  }
49418
- fn.conversion = path30;
49955
+ fn.conversion = path29;
49419
49956
  return fn;
49420
49957
  }
49421
49958
  function route(fromModel) {
@@ -50032,7 +50569,7 @@ var require_channel = __commonJS({
50032
50569
  var require_output = __commonJS({
50033
50570
  "../../node_modules/sharp/lib/output.js"(exports2, module2) {
50034
50571
  "use strict";
50035
- var path30 = require("path");
50572
+ var path29 = require("path");
50036
50573
  var is = require_is();
50037
50574
  var sharp = require_sharp();
50038
50575
  var formats = /* @__PURE__ */ new Map([
@@ -50063,9 +50600,9 @@ var require_output = __commonJS({
50063
50600
  let err;
50064
50601
  if (!is.string(fileOut)) {
50065
50602
  err = new Error("Missing output file path");
50066
- } else if (is.string(this.options.input.file) && path30.resolve(this.options.input.file) === path30.resolve(fileOut)) {
50603
+ } else if (is.string(this.options.input.file) && path29.resolve(this.options.input.file) === path29.resolve(fileOut)) {
50067
50604
  err = new Error("Cannot use same file for input and output");
50068
- } else if (jp2Regex.test(path30.extname(fileOut)) && !this.constructor.format.jp2k.output.file) {
50605
+ } else if (jp2Regex.test(path29.extname(fileOut)) && !this.constructor.format.jp2k.output.file) {
50069
50606
  err = errJp2Save();
50070
50607
  }
50071
50608
  if (err) {
@@ -51307,11 +51844,11 @@ function quarantineLegacyStandaloneSessions(options) {
51307
51844
  const homeDir = options.homeDir || os23.homedir();
51308
51845
  const now = options.now || (() => /* @__PURE__ */ new Date());
51309
51846
  const isPidRunning = options.isPidRunning || defaultPidRunning;
51310
- const runtimesDir = path25.join(homeDir, ".adhdev", "session-host", options.appName, "runtimes");
51847
+ const runtimesDir = path24.join(homeDir, ".adhdev", "session-host", options.appName, "runtimes");
51311
51848
  if (!fs16.existsSync(runtimesDir)) {
51312
51849
  return { movedCount: 0, skippedActiveCount: 0, backupDir: null };
51313
51850
  }
51314
- const candidates = fs16.readdirSync(runtimesDir).filter((name) => name.endsWith(".json")).map((name) => path25.join(runtimesDir, name));
51851
+ const candidates = fs16.readdirSync(runtimesDir).filter((name) => name.endsWith(".json")).map((name) => path24.join(runtimesDir, name));
51315
51852
  let movedCount = 0;
51316
51853
  let skippedActiveCount = 0;
51317
51854
  let backupDir = null;
@@ -51329,26 +51866,26 @@ function quarantineLegacyStandaloneSessions(options) {
51329
51866
  continue;
51330
51867
  }
51331
51868
  if (!backupDir) {
51332
- backupDir = path25.join(
51869
+ backupDir = path24.join(
51333
51870
  homeDir,
51334
51871
  ".adhdev",
51335
51872
  "session-host-backups",
51336
51873
  `legacy-standalone-${options.appName}-${formatTimestamp(now())}`
51337
51874
  );
51338
- fs16.mkdirSync(path25.join(backupDir, "runtimes"), { recursive: true });
51875
+ fs16.mkdirSync(path24.join(backupDir, "runtimes"), { recursive: true });
51339
51876
  }
51340
- fs16.renameSync(sourcePath, path25.join(backupDir, "runtimes", path25.basename(sourcePath)));
51877
+ fs16.renameSync(sourcePath, path24.join(backupDir, "runtimes", path24.basename(sourcePath)));
51341
51878
  movedCount += 1;
51342
51879
  }
51343
51880
  return { movedCount, skippedActiveCount, backupDir };
51344
51881
  }
51345
- var fs16, os23, path25, LEGACY_STANDALONE_MANAGER_TAG;
51882
+ var fs16, os23, path24, LEGACY_STANDALONE_MANAGER_TAG;
51346
51883
  var init_session_host_hygiene = __esm({
51347
51884
  "src/session-host-hygiene.ts"() {
51348
51885
  "use strict";
51349
51886
  fs16 = __toESM(require("fs"));
51350
51887
  os23 = __toESM(require("os"));
51351
- path25 = __toESM(require("path"));
51888
+ path24 = __toESM(require("path"));
51352
51889
  init_src();
51353
51890
  LEGACY_STANDALONE_MANAGER_TAG = "adhdev-standalone";
51354
51891
  }
@@ -51362,8 +51899,8 @@ function buildSessionHostEnv(baseEnv) {
51362
51899
  }
51363
51900
  function resolveSessionHostEntry() {
51364
51901
  const packagedCandidates = [
51365
- path26.resolve(__dirname, "../vendor/session-host-daemon/index.js"),
51366
- path26.resolve(__dirname, "../../vendor/session-host-daemon/index.js")
51902
+ path25.resolve(__dirname, "../vendor/session-host-daemon/index.js"),
51903
+ path25.resolve(__dirname, "../../vendor/session-host-daemon/index.js")
51367
51904
  ];
51368
51905
  for (const candidate of packagedCandidates) {
51369
51906
  if (fs17.existsSync(candidate)) {
@@ -51373,7 +51910,7 @@ function resolveSessionHostEntry() {
51373
51910
  return require.resolve("@adhdev/session-host-daemon");
51374
51911
  }
51375
51912
  function getSessionHostPidFile() {
51376
- return path26.join(os24.homedir(), ".adhdev", `${SESSION_HOST_APP_NAME}-session-host.pid`);
51913
+ return path25.join(os24.homedir(), ".adhdev", `${SESSION_HOST_APP_NAME}-session-host.pid`);
51377
51914
  }
51378
51915
  function killPid2(pid) {
51379
51916
  try {
@@ -51490,9 +52027,9 @@ async function ensureSessionHostReady2() {
51490
52027
  }
51491
52028
  const spawnHost = () => {
51492
52029
  const entry = resolveSessionHostEntry();
51493
- const logDir = path26.join(os24.homedir(), ".adhdev", "logs");
52030
+ const logDir = path25.join(os24.homedir(), ".adhdev", "logs");
51494
52031
  fs17.mkdirSync(logDir, { recursive: true });
51495
- const logFd = fs17.openSync(path26.join(logDir, "session-host.log"), "a");
52032
+ const logFd = fs17.openSync(path25.join(logDir, "session-host.log"), "a");
51496
52033
  const child = (0, import_child_process11.spawn)(process.execPath, [entry], {
51497
52034
  detached: true,
51498
52035
  stdio: ["ignore", logFd, logFd],
@@ -51527,14 +52064,14 @@ async function ensureSessionHostReady2() {
51527
52064
  async function listHostedCliRuntimes2(endpoint) {
51528
52065
  return listHostedCliRuntimes(endpoint);
51529
52066
  }
51530
- var import_child_process11, fs17, os24, path26, SESSION_HOST_APP_NAME, SESSION_HOST_START_TIMEOUT_MS;
52067
+ var import_child_process11, fs17, os24, path25, SESSION_HOST_APP_NAME, SESSION_HOST_START_TIMEOUT_MS;
51531
52068
  var init_session_host = __esm({
51532
52069
  "src/session-host.ts"() {
51533
52070
  "use strict";
51534
52071
  import_child_process11 = require("child_process");
51535
52072
  fs17 = __toESM(require("fs"));
51536
52073
  os24 = __toESM(require("os"));
51537
- path26 = __toESM(require("path"));
52074
+ path25 = __toESM(require("path"));
51538
52075
  init_src();
51539
52076
  init_dist();
51540
52077
  init_session_host_hygiene();
@@ -52295,10 +52832,10 @@ function resolveDaemonPort(ref = {}) {
52295
52832
  return Number.isFinite(ref.port) && Number(ref.port) > 0 ? Number(ref.port) : DEFAULT_DAEMON_PORT;
52296
52833
  }
52297
52834
  function getDaemonPidFile(ref = {}) {
52298
- const dir = path27.join(ref.homeDir || os26.homedir(), ".adhdev");
52835
+ const dir = path26.join(ref.homeDir || os26.homedir(), ".adhdev");
52299
52836
  if (!fs18.existsSync(dir)) fs18.mkdirSync(dir, { recursive: true });
52300
52837
  const port = resolveDaemonPort(ref);
52301
- return path27.join(dir, port === DEFAULT_DAEMON_PORT ? "daemon.pid" : `daemon-${port}.pid`);
52838
+ return path26.join(dir, port === DEFAULT_DAEMON_PORT ? "daemon.pid" : `daemon-${port}.pid`);
52302
52839
  }
52303
52840
  function writeDaemonPid(pid, ref = {}) {
52304
52841
  const pidFile = getDaemonPidFile(ref);
@@ -52403,7 +52940,7 @@ function stopDaemon(ref = {}) {
52403
52940
  return false;
52404
52941
  }
52405
52942
  }
52406
- var os26, fs18, path27, import_http, import_ws3, pkgVersion, ACTIVE_CHAT_POLL_STATUSES, AdhdevDaemon;
52943
+ var os26, fs18, path26, import_http, import_ws3, pkgVersion, AdhdevDaemon;
52407
52944
  var init_adhdev_daemon = __esm({
52408
52945
  "src/adhdev-daemon.ts"() {
52409
52946
  "use strict";
@@ -52417,17 +52954,13 @@ var init_adhdev_daemon = __esm({
52417
52954
  init_session_host_controller();
52418
52955
  os26 = __toESM(require("os"));
52419
52956
  fs18 = __toESM(require("fs"));
52420
- path27 = __toESM(require("path"));
52957
+ path26 = __toESM(require("path"));
52421
52958
  import_http = require("http");
52422
52959
  import_ws3 = require("ws");
52423
52960
  init_source2();
52424
52961
  init_version();
52425
- pkgVersion = resolvePackageVersion({ injectedVersion: "0.8.63" });
52426
- ACTIVE_CHAT_POLL_STATUSES = /* @__PURE__ */ new Set([
52427
- "generating",
52428
- "waiting_approval",
52429
- "starting"
52430
- ]);
52962
+ init_src();
52963
+ pkgVersion = resolvePackageVersion({ injectedVersion: "0.8.66" });
52431
52964
  AdhdevDaemon = class _AdhdevDaemon {
52432
52965
  localHttpServer = null;
52433
52966
  localWss = null;
@@ -52654,14 +53187,12 @@ var init_adhdev_daemon = __esm({
52654
53187
  }
52655
53188
  getHotChatSessionIdsForP2PFlush() {
52656
53189
  const snapshot = this.buildLiveStatusSnapshot();
52657
- const active = new Set(
52658
- snapshot.sessions.filter((session) => ACTIVE_CHAT_POLL_STATUSES.has(String(session.status || "").toLowerCase())).map((session) => session.id)
52659
- );
52660
- const finalizing = new Set(
52661
- Array.from(this.hotP2PChatSessionIds).filter((sessionId) => !active.has(sessionId))
53190
+ const hotSessions = classifyHotChatSessionsForSubscriptionFlush(
53191
+ snapshot.sessions,
53192
+ this.hotP2PChatSessionIds
52662
53193
  );
52663
- this.hotP2PChatSessionIds = active;
52664
- return { active, finalizing };
53194
+ this.hotP2PChatSessionIds = hotSessions.active;
53195
+ return hotSessions;
52665
53196
  }
52666
53197
  async flushP2PChatSubscriptions(options = {}) {
52667
53198
  if (!this.p2p?.isConnected || !this.p2p.hasChatSubscriptions()) return;
@@ -64843,15 +65374,15 @@ var require_route = __commonJS({
64843
65374
  };
64844
65375
  }
64845
65376
  function wrapConversion(toModel, graph) {
64846
- const path30 = [graph[toModel].parent, toModel];
65377
+ const path29 = [graph[toModel].parent, toModel];
64847
65378
  let fn = conversions[graph[toModel].parent][toModel];
64848
65379
  let cur = graph[toModel].parent;
64849
65380
  while (graph[cur].parent) {
64850
- path30.unshift(graph[cur].parent);
65381
+ path29.unshift(graph[cur].parent);
64851
65382
  fn = link(conversions[graph[cur].parent][cur], fn);
64852
65383
  cur = graph[cur].parent;
64853
65384
  }
64854
- fn.conversion = path30;
65385
+ fn.conversion = path29;
64855
65386
  return fn;
64856
65387
  }
64857
65388
  module2.exports = function(fromModel) {
@@ -82721,9 +83252,9 @@ var init_prompt = __esm({
82721
83252
  init_utils();
82722
83253
  init_baseUI();
82723
83254
  _ = {
82724
- set: (obj, path30 = "", value) => {
83255
+ set: (obj, path29 = "", value) => {
82725
83256
  let pointer = obj;
82726
- path30.split(".").forEach((key, index, arr) => {
83257
+ path29.split(".").forEach((key, index, arr) => {
82727
83258
  if (key === "__proto__" || key === "constructor") return;
82728
83259
  if (index === arr.length - 1) {
82729
83260
  pointer[key] = value;
@@ -82733,8 +83264,8 @@ var init_prompt = __esm({
82733
83264
  pointer = pointer[key];
82734
83265
  });
82735
83266
  },
82736
- get: (obj, path30 = "", defaultValue) => {
82737
- const travel = (regexp) => String.prototype.split.call(path30, regexp).filter(Boolean).reduce(
83267
+ get: (obj, path29 = "", defaultValue) => {
83268
+ const travel = (regexp) => String.prototype.split.call(path29, regexp).filter(Boolean).reduce(
82738
83269
  // @ts-expect-error implicit any on res[key]
82739
83270
  (res, key) => res !== null && res !== void 0 ? res[key] : res,
82740
83271
  obj