@adhdev/daemon-standalone 0.9.82-rc.325 → 0.9.82-rc.327

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
@@ -30033,10 +30033,10 @@ var require_dist3 = __commonJS({
30033
30033
  }
30034
30034
  function getDaemonBuildInfo() {
30035
30035
  if (cached2) return cached2;
30036
- const commit = readInjected(true ? "a0aeebdac30d9abea5b46e3f2618f864bbff19d0" : void 0) ?? "unknown";
30037
- const commitShort = readInjected(true ? "a0aeebda" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
30038
- const version2 = readInjected(true ? "0.9.82-rc.325" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
30039
- const builtAt = readInjected(true ? "2026-06-19T08:25:17.695Z" : void 0);
30036
+ const commit = readInjected(true ? "993e3922de8abe554822450e2b4c26c2c9f5f64a" : void 0) ?? "unknown";
30037
+ const commitShort = readInjected(true ? "993e3922" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
30038
+ const version2 = readInjected(true ? "0.9.82-rc.327" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
30039
+ const builtAt = readInjected(true ? "2026-06-19T12:31:51.466Z" : void 0);
30040
30040
  cached2 = builtAt ? { commit, commitShort, version: version2, builtAt } : { commit, commitShort, version: version2 };
30041
30041
  return cached2;
30042
30042
  }
@@ -31669,6 +31669,8 @@ ${error48.message || ""}`;
31669
31669
  const node = mesh.nodes.find((n) => n.id === nodeId);
31670
31670
  if (!node) return void 0;
31671
31671
  if (opts.userOverrides) node.userOverrides = { ...node.userOverrides, ...opts.userOverrides };
31672
+ if (opts.reportedPlatform && opts.reportedPlatform.trim()) node.reportedPlatform = opts.reportedPlatform.trim();
31673
+ if (opts.reportedArch && opts.reportedArch.trim()) node.reportedArch = opts.reportedArch.trim();
31672
31674
  if (opts.policy) node.policy = { ...node.policy, ...opts.policy };
31673
31675
  if (opts.worktreeBootstrap) node.worktreeBootstrap = opts.worktreeBootstrap;
31674
31676
  if (Object.prototype.hasOwnProperty.call(opts, "systemPrompt")) {
@@ -32854,11 +32856,15 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
32854
32856
  const value = overrides[key];
32855
32857
  return typeof value === "string" && value.trim() ? value.trim() : null;
32856
32858
  }
32859
+ function readNodeReporter(node, key) {
32860
+ const value = key === "platform" ? node?.reportedPlatform : node?.reportedArch;
32861
+ return typeof value === "string" && value.trim() ? value.trim() : null;
32862
+ }
32857
32863
  function buildMeshNodeCapabilityTags(node, providerType) {
32858
32864
  const provider = typeof providerType === "string" && providerType.trim() ? providerType.trim() : firstProviderPriority(node?.policy);
32859
32865
  const worktreeBranch = typeof node?.worktreeBranch === "string" && node.worktreeBranch.trim() ? node.worktreeBranch.trim() : null;
32860
- const os30 = readNodeOverride(node, "platform") ?? process.platform;
32861
- const arch2 = readNodeOverride(node, "arch") ?? process.arch;
32866
+ const os30 = readNodeOverride(node, "platform") ?? readNodeReporter(node, "platform") ?? process.platform;
32867
+ const arch2 = readNodeOverride(node, "arch") ?? readNodeReporter(node, "arch") ?? process.arch;
32862
32868
  return normalizeMeshCapabilityTags([
32863
32869
  ...Array.isArray(node?.capabilities) ? node.capabilities : [],
32864
32870
  `os=${os30}`,
@@ -39920,6 +39926,652 @@ Next step: ${nextStep}`;
39920
39926
  ]);
39921
39927
  }
39922
39928
  });
39929
+ function normalizeInputEnvelope(input) {
39930
+ const normalized = normalizeInputEnvelopePayload(input);
39931
+ const textFallback = normalized.textFallback ?? flattenInputParts(normalized.parts);
39932
+ return {
39933
+ parts: normalized.parts,
39934
+ textFallback,
39935
+ ...normalized.metadata ? { metadata: normalized.metadata } : {}
39936
+ };
39937
+ }
39938
+ function normalizeMessageParts(content) {
39939
+ if (typeof content === "string") return [{ type: "text", text: content }];
39940
+ if (!Array.isArray(content)) {
39941
+ if (content && typeof content === "object" && typeof content.text === "string") {
39942
+ return [{ type: "text", text: String(content.text) }];
39943
+ }
39944
+ return [];
39945
+ }
39946
+ const parts = [];
39947
+ for (const raw of content) {
39948
+ if (typeof raw === "string") {
39949
+ parts.push({ type: "text", text: raw });
39950
+ continue;
39951
+ }
39952
+ if (!raw || typeof raw !== "object") continue;
39953
+ const part = normalizeMessagePartObject(raw);
39954
+ if (part) parts.push(part);
39955
+ }
39956
+ return parts;
39957
+ }
39958
+ function flattenMessageParts(parts) {
39959
+ return parts.map((part) => {
39960
+ if (part.type === "text") return part.text;
39961
+ if (part.type === "resource") return part.resource.text || "";
39962
+ if (part.type === "image") return part.alt || (part.data ? `[image: ${part.mimeType}]` : "");
39963
+ if (part.type === "audio") return part.transcript || (part.data ? `[audio: ${part.mimeType}]` : "");
39964
+ if (part.type === "video") return part.transcript || (part.data ? `[video: ${part.mimeType}]` : "");
39965
+ if (part.type === "resource_link") return [part.name, part.description].filter(Boolean).join("\n");
39966
+ return "";
39967
+ }).filter((value) => value.length > 0).join("\n");
39968
+ }
39969
+ function normalizeInputEnvelopePayload(input) {
39970
+ if (typeof input === "string") {
39971
+ return { parts: [{ type: "text", text: input }], textFallback: input };
39972
+ }
39973
+ if (!input || typeof input !== "object") {
39974
+ return { parts: [], textFallback: "" };
39975
+ }
39976
+ const record2 = input;
39977
+ const nestedInput = record2.input;
39978
+ if (nestedInput && typeof nestedInput === "object") {
39979
+ const nested = nestedInput;
39980
+ return {
39981
+ parts: normalizeInputParts(nested.parts ?? nested.prompt),
39982
+ textFallback: typeof nested.textFallback === "string" ? nested.textFallback : void 0,
39983
+ metadata: normalizeInputMetadata(nested.metadata)
39984
+ };
39985
+ }
39986
+ const directText = typeof record2.text === "string" ? record2.text : typeof record2.message === "string" ? record2.message : void 0;
39987
+ if (directText !== void 0) {
39988
+ return { parts: [{ type: "text", text: directText }], textFallback: directText };
39989
+ }
39990
+ const directParts = normalizeInputParts(record2.parts ?? record2.prompt);
39991
+ return {
39992
+ parts: directParts,
39993
+ textFallback: typeof record2.textFallback === "string" ? record2.textFallback : void 0,
39994
+ metadata: normalizeInputMetadata(record2.metadata)
39995
+ };
39996
+ }
39997
+ function normalizeInputMetadata(value) {
39998
+ if (!value || typeof value !== "object") return void 0;
39999
+ const record2 = value;
40000
+ const metadata = {};
40001
+ if (record2.source === "dashboard" || record2.source === "shortcut_api" || record2.source === "provider_script" || record2.source === "session_replay") {
40002
+ metadata.source = record2.source;
40003
+ }
40004
+ if (typeof record2.clientTimestamp === "number" && Number.isFinite(record2.clientTimestamp)) {
40005
+ metadata.clientTimestamp = record2.clientTimestamp;
40006
+ }
40007
+ return Object.keys(metadata).length > 0 ? metadata : void 0;
40008
+ }
40009
+ function normalizeInputParts(value) {
40010
+ if (!Array.isArray(value)) return [];
40011
+ const parts = [];
40012
+ for (const raw of value) {
40013
+ if (typeof raw === "string") {
40014
+ parts.push({ type: "text", text: raw });
40015
+ continue;
40016
+ }
40017
+ if (!raw || typeof raw !== "object") continue;
40018
+ const part = normalizeInputPartObject(raw);
40019
+ if (part) parts.push(part);
40020
+ }
40021
+ return parts;
40022
+ }
40023
+ function normalizeInputPartObject(raw) {
40024
+ const type = raw.type;
40025
+ if (type === "text" && typeof raw.text === "string") {
40026
+ return { type, text: raw.text };
40027
+ }
40028
+ if (type === "image" && typeof raw.mimeType === "string") {
40029
+ return {
40030
+ type,
40031
+ mimeType: raw.mimeType,
40032
+ ...typeof raw.uri === "string" ? { uri: raw.uri } : {},
40033
+ ...typeof raw.data === "string" ? { data: raw.data } : {},
40034
+ ...typeof raw.alt === "string" ? { alt: raw.alt } : {}
40035
+ };
40036
+ }
40037
+ if (type === "audio" && typeof raw.mimeType === "string") {
40038
+ return {
40039
+ type,
40040
+ mimeType: raw.mimeType,
40041
+ ...typeof raw.uri === "string" ? { uri: raw.uri } : {},
40042
+ ...typeof raw.data === "string" ? { data: raw.data } : {},
40043
+ ...typeof raw.transcript === "string" ? { transcript: raw.transcript } : {}
40044
+ };
40045
+ }
40046
+ if (type === "video" && typeof raw.mimeType === "string") {
40047
+ return {
40048
+ type,
40049
+ mimeType: raw.mimeType,
40050
+ ...typeof raw.uri === "string" ? { uri: raw.uri } : {},
40051
+ ...typeof raw.data === "string" ? { data: raw.data } : {},
40052
+ ...typeof raw.transcript === "string" ? { transcript: raw.transcript } : {},
40053
+ ...typeof raw.posterUri === "string" ? { posterUri: raw.posterUri } : {}
40054
+ };
40055
+ }
40056
+ if (type === "resource" && typeof raw.uri === "string") {
40057
+ return {
40058
+ type,
40059
+ uri: raw.uri,
40060
+ ...typeof raw.mimeType === "string" ? { mimeType: raw.mimeType } : {},
40061
+ ...typeof raw.name === "string" ? { name: raw.name } : {},
40062
+ ...typeof raw.text === "string" ? { text: raw.text } : {},
40063
+ ...typeof raw.data === "string" ? { data: raw.data } : {}
40064
+ };
40065
+ }
40066
+ if (type === "resource_link" && typeof raw.uri === "string") {
40067
+ return {
40068
+ type,
40069
+ uri: raw.uri,
40070
+ name: typeof raw.name === "string" ? raw.name : getUriDisplayName(raw.uri, "resource"),
40071
+ ...typeof raw.title === "string" ? { title: raw.title } : {},
40072
+ ...typeof raw.description === "string" ? { description: raw.description } : {},
40073
+ ...typeof raw.mimeType === "string" ? { mimeType: raw.mimeType } : {},
40074
+ ...typeof raw.size === "number" && Number.isFinite(raw.size) ? { size: raw.size } : {},
40075
+ ...normalizeAnnotationsProperty(raw.annotations)
40076
+ };
40077
+ }
40078
+ return null;
40079
+ }
40080
+ function normalizeMessagePartObject(raw) {
40081
+ const type = raw.type;
40082
+ if (type === "text" && typeof raw.text === "string") {
40083
+ return { type, text: raw.text };
40084
+ }
40085
+ if (type === "image" && typeof raw.mimeType === "string") {
40086
+ return {
40087
+ type,
40088
+ mimeType: raw.mimeType,
40089
+ ...typeof raw.uri === "string" ? { uri: raw.uri } : {},
40090
+ ...typeof raw.data === "string" ? { data: raw.data } : {},
40091
+ ...typeof raw.alt === "string" ? { alt: raw.alt } : {}
40092
+ };
40093
+ }
40094
+ if (type === "audio" && typeof raw.mimeType === "string") {
40095
+ return {
40096
+ type,
40097
+ mimeType: raw.mimeType,
40098
+ ...typeof raw.uri === "string" ? { uri: raw.uri } : {},
40099
+ ...typeof raw.data === "string" ? { data: raw.data } : {},
40100
+ ...typeof raw.transcript === "string" ? { transcript: raw.transcript } : {}
40101
+ };
40102
+ }
40103
+ if (type === "video" && typeof raw.mimeType === "string") {
40104
+ return {
40105
+ type,
40106
+ mimeType: raw.mimeType,
40107
+ ...typeof raw.uri === "string" ? { uri: raw.uri } : {},
40108
+ ...typeof raw.data === "string" ? { data: raw.data } : {},
40109
+ ...typeof raw.transcript === "string" ? { transcript: raw.transcript } : {},
40110
+ ...typeof raw.posterUri === "string" ? { posterUri: raw.posterUri } : {}
40111
+ };
40112
+ }
40113
+ if (type === "resource_link" && typeof raw.uri === "string" && typeof raw.name === "string") {
40114
+ return {
40115
+ type,
40116
+ uri: raw.uri,
40117
+ name: raw.name,
40118
+ ...typeof raw.title === "string" ? { title: raw.title } : {},
40119
+ ...typeof raw.description === "string" ? { description: raw.description } : {},
40120
+ ...typeof raw.mimeType === "string" ? { mimeType: raw.mimeType } : {},
40121
+ ...typeof raw.size === "number" && Number.isFinite(raw.size) ? { size: raw.size } : {},
40122
+ ...normalizeAnnotationsProperty(raw.annotations)
40123
+ };
40124
+ }
40125
+ if (type === "resource" && raw.resource && typeof raw.resource === "object") {
40126
+ const resource = raw.resource;
40127
+ if (typeof resource.uri !== "string") return null;
40128
+ return {
40129
+ type,
40130
+ resource: {
40131
+ uri: resource.uri,
40132
+ ...typeof resource.mimeType === "string" || resource.mimeType === null ? { mimeType: resource.mimeType } : {},
40133
+ ...typeof resource.text === "string" ? { text: resource.text } : {},
40134
+ ...typeof resource.blob === "string" ? { blob: resource.blob } : {}
40135
+ }
40136
+ };
40137
+ }
40138
+ return null;
40139
+ }
40140
+ function flattenInputParts(parts) {
40141
+ return parts.map((part) => {
40142
+ if (part.type === "text") return part.text;
40143
+ if (part.type === "image") return part.alt || (part.data ? `[image: ${part.mimeType}]` : "");
40144
+ if (part.type === "audio") return part.transcript || (part.data ? `[audio: ${part.mimeType}]` : "");
40145
+ if (part.type === "video") return part.transcript || (part.data ? `[video: ${part.mimeType}]` : "");
40146
+ if (part.type === "resource_link") return [part.title, part.name, part.description, part.uri].filter(Boolean).join("\n");
40147
+ if (part.type === "resource") return part.text || part.name || part.uri;
40148
+ return "";
40149
+ }).filter((value) => value.length > 0).join("\n");
40150
+ }
40151
+ function getUriDisplayName(uri, fallback) {
40152
+ try {
40153
+ const pathname = uri.startsWith("file://") ? new URL(uri).pathname : uri;
40154
+ return pathname.split(/[\\/]/).filter(Boolean).pop() || fallback;
40155
+ } catch {
40156
+ return uri.split(/[\\/]/).filter(Boolean).pop() || fallback;
40157
+ }
40158
+ }
40159
+ function normalizeAnnotationsProperty(value) {
40160
+ if (!value || typeof value !== "object") return {};
40161
+ const record2 = value;
40162
+ const annotations = {};
40163
+ if (Array.isArray(record2.audience)) {
40164
+ const audience = record2.audience.filter((item) => item === "user" || item === "assistant");
40165
+ if (audience.length > 0) annotations.audience = audience;
40166
+ }
40167
+ if (typeof record2.priority === "number" && Number.isFinite(record2.priority)) {
40168
+ annotations.priority = record2.priority;
40169
+ }
40170
+ return Object.keys(annotations).length > 0 ? { annotations } : {};
40171
+ }
40172
+ var init_io_contracts = __esm2({
40173
+ "src/providers/io-contracts.ts"() {
40174
+ "use strict";
40175
+ }
40176
+ });
40177
+ function flattenContent(content) {
40178
+ if (typeof content === "string") return content;
40179
+ return flattenMessageParts(normalizeMessageParts(content));
40180
+ }
40181
+ var init_contracts = __esm2({
40182
+ "src/providers/contracts.ts"() {
40183
+ "use strict";
40184
+ init_io_contracts();
40185
+ init_io_contracts();
40186
+ }
40187
+ });
40188
+ function extractFinalSummaryFromMessages(messages, maxChars = DEFAULT_FINAL_SUMMARY_MAX_CHARS) {
40189
+ if (!Array.isArray(messages) || messages.length === 0) return "";
40190
+ for (let i = messages.length - 1; i >= 0; i--) {
40191
+ const msg = messages[i];
40192
+ if (!msg) continue;
40193
+ const classification = classifyChatMessageVisibility(msg);
40194
+ if (classification.isUserFacing && (msg.role === "assistant" || msg.role === "model")) {
40195
+ const text = flattenContent(msg.content).trim();
40196
+ if (text) return text.slice(0, maxChars);
40197
+ }
40198
+ }
40199
+ return "";
40200
+ }
40201
+ function readChatMessageTimestampIso(message) {
40202
+ if (!message) return void 0;
40203
+ const record2 = message;
40204
+ for (const value of [record2.timestamp, record2.createdAt, record2.created_at, record2.updatedAt, record2.time]) {
40205
+ if (typeof value === "number" && Number.isFinite(value)) {
40206
+ const ms = value > 1e10 ? value : value * 1e3;
40207
+ return new Date(ms).toISOString();
40208
+ }
40209
+ if (typeof value === "string" && value.trim()) {
40210
+ const ms = new Date(value.trim()).getTime();
40211
+ if (Number.isFinite(ms)) return new Date(ms).toISOString();
40212
+ }
40213
+ }
40214
+ return void 0;
40215
+ }
40216
+ function extractFinalAssistantSummaryEvidence(messages, maxChars = DEFAULT_FINAL_SUMMARY_MAX_CHARS) {
40217
+ if (!Array.isArray(messages) || messages.length === 0) return { finalSummary: "" };
40218
+ for (let i = messages.length - 1; i >= 0; i--) {
40219
+ const msg = messages[i];
40220
+ if (!msg) continue;
40221
+ const classification = classifyChatMessageVisibility(msg);
40222
+ if (classification.isUserFacing && (msg.role === "assistant" || msg.role === "model")) {
40223
+ const text = flattenContent(msg.content).trim();
40224
+ if (text) {
40225
+ return {
40226
+ finalSummary: text.slice(0, maxChars),
40227
+ transcriptMessageAt: readChatMessageTimestampIso(msg)
40228
+ };
40229
+ }
40230
+ }
40231
+ }
40232
+ return { finalSummary: "" };
40233
+ }
40234
+ function canonicalizeKindHint(value) {
40235
+ return value.trim().toLowerCase().replace(/[\s-]+/g, "_");
40236
+ }
40237
+ function resolveBuiltinOrAliasKind(kind) {
40238
+ if (typeof kind !== "string") return null;
40239
+ const normalizedKind = canonicalizeKindHint(kind);
40240
+ if (!normalizedKind) return null;
40241
+ if (KNOWN_CHAT_MESSAGE_KINDS.has(normalizedKind)) return normalizedKind;
40242
+ return CHAT_MESSAGE_KIND_ALIASES[normalizedKind] || null;
40243
+ }
40244
+ function inferHintKind(value) {
40245
+ const direct = resolveBuiltinOrAliasKind(value);
40246
+ if (direct) return direct;
40247
+ if (typeof value !== "string") return null;
40248
+ const normalized = canonicalizeKindHint(value);
40249
+ if (!normalized) return null;
40250
+ if (/thought|thinking|reasoning/.test(normalized)) return "thought";
40251
+ if (/tool/.test(normalized)) return "tool";
40252
+ if (/terminal|command|shell|console/.test(normalized)) return "terminal";
40253
+ return null;
40254
+ }
40255
+ function inferKindFromToolCalls(message) {
40256
+ const toolCalls = Array.isArray(message?.toolCalls) ? message.toolCalls : [];
40257
+ if (toolCalls.length === 0) return null;
40258
+ if (toolCalls.some((toolCall) => toolCall?.kind === "think")) return "thought";
40259
+ if (toolCalls.some((toolCall) => toolCall?.kind === "execute")) return "terminal";
40260
+ if (toolCalls.some((toolCall) => Array.isArray(toolCall?.content) && toolCall.content.some((entry) => entry?.type === "terminal"))) {
40261
+ return "terminal";
40262
+ }
40263
+ return "tool";
40264
+ }
40265
+ function inferMissingChatMessageKind(message) {
40266
+ const role = typeof message?.role === "string" ? message.role.trim().toLowerCase() : "";
40267
+ if (role === "system") return "system";
40268
+ const meta3 = message?.meta && typeof message.meta === "object" ? message.meta : void 0;
40269
+ const hintCandidates = [
40270
+ message?._sub,
40271
+ message?._type,
40272
+ meta3?.label,
40273
+ typeof message?.senderName === "string" ? message.senderName : void 0
40274
+ ];
40275
+ for (const candidate of hintCandidates) {
40276
+ const inferred = inferHintKind(candidate);
40277
+ if (inferred) return inferred;
40278
+ }
40279
+ const inferredFromToolCalls = inferKindFromToolCalls(message);
40280
+ if (inferredFromToolCalls) return inferredFromToolCalls;
40281
+ return null;
40282
+ }
40283
+ function isBuiltinChatMessageKind(kind) {
40284
+ return resolveBuiltinOrAliasKind(kind) !== null;
40285
+ }
40286
+ function normalizeChatMessageKind(kind, role) {
40287
+ const resolvedKind = resolveBuiltinOrAliasKind(kind);
40288
+ if (resolvedKind) return resolvedKind;
40289
+ const normalizedRole = typeof role === "string" ? role.trim().toLowerCase() : "";
40290
+ return normalizedRole === "system" ? "system" : "standard";
40291
+ }
40292
+ function resolveChatMessageKind(message) {
40293
+ const explicitKind = resolveBuiltinOrAliasKind(message?.kind);
40294
+ if (explicitKind) return explicitKind;
40295
+ const inferredKind = inferMissingChatMessageKind(message);
40296
+ if (inferredKind) return inferredKind;
40297
+ return normalizeChatMessageKind(message?.kind, message?.role);
40298
+ }
40299
+ function buildChatMessage(message) {
40300
+ return {
40301
+ ...message,
40302
+ kind: resolveChatMessageKind(message)
40303
+ };
40304
+ }
40305
+ function buildSystemChatMessage(message) {
40306
+ return buildChatMessage({
40307
+ ...message,
40308
+ role: "system",
40309
+ kind: message?.kind || "system"
40310
+ });
40311
+ }
40312
+ function buildRuntimeSystemChatMessage(message) {
40313
+ return buildSystemChatMessage({
40314
+ ...message,
40315
+ senderName: typeof message?.senderName === "string" && message.senderName.trim() ? message.senderName : "System"
40316
+ });
40317
+ }
40318
+ function buildAssistantChatMessage(message) {
40319
+ return buildChatMessage({
40320
+ ...message,
40321
+ role: "assistant",
40322
+ kind: message?.kind || "standard"
40323
+ });
40324
+ }
40325
+ function buildThoughtChatMessage(message) {
40326
+ return buildAssistantChatMessage({
40327
+ ...message,
40328
+ kind: message?.kind || "thought"
40329
+ });
40330
+ }
40331
+ function buildToolChatMessage(message) {
40332
+ return buildAssistantChatMessage({
40333
+ ...message,
40334
+ kind: message?.kind || "tool"
40335
+ });
40336
+ }
40337
+ function buildTerminalChatMessage(message) {
40338
+ return buildAssistantChatMessage({
40339
+ ...message,
40340
+ kind: message?.kind || "terminal"
40341
+ });
40342
+ }
40343
+ function buildUserChatMessage(message) {
40344
+ return buildChatMessage({
40345
+ ...message,
40346
+ role: "user",
40347
+ kind: message?.kind || "standard"
40348
+ });
40349
+ }
40350
+ function normalizeChatMessage(message) {
40351
+ return buildChatMessage(message);
40352
+ }
40353
+ function normalizeChatMessages(messages) {
40354
+ return (Array.isArray(messages) ? messages : []).map((message) => normalizeChatMessage(message));
40355
+ }
40356
+ function readMessageMeta(message) {
40357
+ const meta3 = message?.meta;
40358
+ return meta3 && typeof meta3 === "object" && !Array.isArray(meta3) ? meta3 : null;
40359
+ }
40360
+ function readStringField(value) {
40361
+ return typeof value === "string" ? value.trim().toLowerCase() : "";
40362
+ }
40363
+ function readRecordField(message, meta3, key) {
40364
+ const record2 = message;
40365
+ return record2[key] ?? meta3?.[key];
40366
+ }
40367
+ function readVisibilityField(message, meta3) {
40368
+ return readStringField(readRecordField(message, meta3, "visibility"));
40369
+ }
40370
+ function readTranscriptVisibilityField(message, meta3) {
40371
+ const record2 = message;
40372
+ return readStringField(record2.transcriptVisibility ?? meta3?.transcriptVisibility ?? record2.visibility ?? meta3?.visibility);
40373
+ }
40374
+ function hasBooleanMarker(message, meta3, keys) {
40375
+ const record2 = message;
40376
+ return keys.some((key) => record2[key] === true || meta3?.[key] === true);
40377
+ }
40378
+ function isActivityKind(kind) {
40379
+ return kind === "thought" || kind === "tool" || kind === "terminal";
40380
+ }
40381
+ function isOrdinaryVisibleTurn(message, role, kind) {
40382
+ if (role === "user" || role === "human") return kind === "standard" || kind === "";
40383
+ if (role === "assistant") return kind === "standard" || kind === "";
40384
+ return false;
40385
+ }
40386
+ function classifyChatMessageVisibility(message) {
40387
+ if (!message) {
40388
+ return {
40389
+ surface: "internal",
40390
+ isUserFacing: false,
40391
+ isActivityFacing: false,
40392
+ isInternal: true,
40393
+ explicitUserFacing: false,
40394
+ explicitHidden: true,
40395
+ role: "",
40396
+ kind: "standard",
40397
+ visibility: "",
40398
+ transcriptVisibility: "",
40399
+ audience: "",
40400
+ source: ""
40401
+ };
40402
+ }
40403
+ const meta3 = readMessageMeta(message);
40404
+ const role = typeof message.role === "string" ? message.role.trim().toLowerCase() : "";
40405
+ const kind = resolveChatMessageKind(message);
40406
+ const visibility = readVisibilityField(message, meta3);
40407
+ const transcriptVisibility = readTranscriptVisibilityField(message, meta3);
40408
+ const audience = readStringField(readRecordField(message, meta3, "audience"));
40409
+ const source = readStringField(readRecordField(message, meta3, "source"));
40410
+ const explicitHidden = EXPLICIT_HIDDEN_VISIBILITIES.has(visibility) || EXPLICIT_HIDDEN_VISIBILITIES.has(transcriptVisibility) || HIDDEN_AUDIENCES.has(audience) || hasBooleanMarker(message, meta3, ["hidden", "internal", "isInternal", "debug", "statusOnly", "controlOnly"]);
40411
+ const explicitUserFacing = EXPLICIT_VISIBLE_VISIBILITIES.has(visibility) || EXPLICIT_VISIBLE_VISIBILITIES.has(transcriptVisibility) || audience === "chat" || hasBooleanMarker(message, meta3, ["userFacing"]);
40412
+ if (explicitHidden) {
40413
+ const activityLike = isActivityKind(kind) || ACTIVITY_SOURCE_SET.has(source);
40414
+ return {
40415
+ surface: activityLike ? "activity" : "internal",
40416
+ isUserFacing: false,
40417
+ isActivityFacing: activityLike,
40418
+ isInternal: !activityLike,
40419
+ explicitUserFacing,
40420
+ explicitHidden,
40421
+ role,
40422
+ kind,
40423
+ visibility,
40424
+ transcriptVisibility,
40425
+ audience,
40426
+ source
40427
+ };
40428
+ }
40429
+ if (explicitUserFacing) {
40430
+ return {
40431
+ surface: "chat",
40432
+ isUserFacing: true,
40433
+ isActivityFacing: false,
40434
+ isInternal: false,
40435
+ explicitUserFacing,
40436
+ explicitHidden,
40437
+ role,
40438
+ kind,
40439
+ visibility,
40440
+ transcriptVisibility,
40441
+ audience,
40442
+ source
40443
+ };
40444
+ }
40445
+ if (INTERNAL_SOURCE_SET.has(source) || role === "system" || kind === "system") {
40446
+ return {
40447
+ surface: "internal",
40448
+ isUserFacing: false,
40449
+ isActivityFacing: false,
40450
+ isInternal: true,
40451
+ explicitUserFacing,
40452
+ explicitHidden,
40453
+ role,
40454
+ kind,
40455
+ visibility,
40456
+ transcriptVisibility,
40457
+ audience,
40458
+ source
40459
+ };
40460
+ }
40461
+ if (ACTIVITY_SOURCE_SET.has(source) || isActivityKind(kind)) {
40462
+ return {
40463
+ surface: "activity",
40464
+ isUserFacing: false,
40465
+ isActivityFacing: true,
40466
+ isInternal: false,
40467
+ explicitUserFacing,
40468
+ explicitHidden,
40469
+ role,
40470
+ kind,
40471
+ visibility,
40472
+ transcriptVisibility,
40473
+ audience,
40474
+ source
40475
+ };
40476
+ }
40477
+ const isUserFacing = isOrdinaryVisibleTurn(message, role, kind);
40478
+ return {
40479
+ surface: isUserFacing ? "chat" : "internal",
40480
+ isUserFacing,
40481
+ isActivityFacing: false,
40482
+ isInternal: !isUserFacing,
40483
+ explicitUserFacing,
40484
+ explicitHidden,
40485
+ role,
40486
+ kind,
40487
+ visibility,
40488
+ transcriptVisibility,
40489
+ audience,
40490
+ source
40491
+ };
40492
+ }
40493
+ function isUserFacingChatMessage(message) {
40494
+ return classifyChatMessageVisibility(message).isUserFacing;
40495
+ }
40496
+ function isActivityChatMessage(message) {
40497
+ return classifyChatMessageVisibility(message).isActivityFacing;
40498
+ }
40499
+ function isInternalChatMessage(message) {
40500
+ return classifyChatMessageVisibility(message).isInternal;
40501
+ }
40502
+ function filterUserFacingChatMessages(messages) {
40503
+ return (Array.isArray(messages) ? messages : []).filter((message) => isUserFacingChatMessage(message));
40504
+ }
40505
+ function filterActivityChatMessages(messages) {
40506
+ return (Array.isArray(messages) ? messages : []).filter((message) => isActivityChatMessage(message));
40507
+ }
40508
+ function filterInternalChatMessages(messages) {
40509
+ return (Array.isArray(messages) ? messages : []).filter((message) => isInternalChatMessage(message));
40510
+ }
40511
+ function filterChatMessagesByVisibility(messages, surface) {
40512
+ return (Array.isArray(messages) ? messages : []).filter((message) => classifyChatMessageVisibility(message).surface === surface);
40513
+ }
40514
+ var DEFAULT_FINAL_SUMMARY_MAX_CHARS;
40515
+ var BUILTIN_CHAT_MESSAGE_KINDS;
40516
+ var CHAT_MESSAGE_VISIBILITIES;
40517
+ var CHAT_MESSAGE_TRANSCRIPT_VISIBILITIES;
40518
+ var CHAT_MESSAGE_AUDIENCES;
40519
+ var CHAT_MESSAGE_SOURCES;
40520
+ var CHAT_MESSAGE_ACTIVITY_SOURCES;
40521
+ var CHAT_MESSAGE_INTERNAL_SOURCES;
40522
+ var KNOWN_CHAT_MESSAGE_KINDS;
40523
+ var CHAT_MESSAGE_KIND_ALIASES;
40524
+ var EXPLICIT_HIDDEN_VISIBILITIES;
40525
+ var EXPLICIT_VISIBLE_VISIBILITIES;
40526
+ var HIDDEN_AUDIENCES;
40527
+ var ACTIVITY_SOURCE_SET;
40528
+ var INTERNAL_SOURCE_SET;
40529
+ var init_chat_message_normalization = __esm2({
40530
+ "src/providers/chat-message-normalization.ts"() {
40531
+ "use strict";
40532
+ init_contracts();
40533
+ DEFAULT_FINAL_SUMMARY_MAX_CHARS = 4e3;
40534
+ BUILTIN_CHAT_MESSAGE_KINDS = ["standard", "thought", "tool", "terminal", "system"];
40535
+ CHAT_MESSAGE_VISIBILITIES = ["user", "debug", "internal", "hidden"];
40536
+ CHAT_MESSAGE_TRANSCRIPT_VISIBILITIES = ["visible", "chat", "user", "debug", "internal", "hidden"];
40537
+ CHAT_MESSAGE_AUDIENCES = ["chat", "debug", "trace", "internal"];
40538
+ CHAT_MESSAGE_SOURCES = [
40539
+ "assistant_text",
40540
+ "tool_call",
40541
+ "terminal_command",
40542
+ "runtime_activity",
40543
+ "runtime_status",
40544
+ "provider_chrome",
40545
+ "control"
40546
+ ];
40547
+ CHAT_MESSAGE_ACTIVITY_SOURCES = ["tool_call", "terminal_command", "runtime_activity"];
40548
+ CHAT_MESSAGE_INTERNAL_SOURCES = ["runtime_status", "provider_chrome", "control"];
40549
+ KNOWN_CHAT_MESSAGE_KINDS = new Set(BUILTIN_CHAT_MESSAGE_KINDS);
40550
+ CHAT_MESSAGE_KIND_ALIASES = {
40551
+ text: "standard",
40552
+ message: "standard",
40553
+ assistant: "standard",
40554
+ thinking: "thought",
40555
+ think: "thought",
40556
+ reasoning: "thought",
40557
+ reason: "thought",
40558
+ toolcall: "tool",
40559
+ tool_call: "tool",
40560
+ tooluse: "tool",
40561
+ tool_use: "tool",
40562
+ action: "tool",
40563
+ command: "terminal",
40564
+ cmd: "terminal",
40565
+ shell: "terminal",
40566
+ console: "terminal"
40567
+ };
40568
+ EXPLICIT_HIDDEN_VISIBILITIES = /* @__PURE__ */ new Set(["hidden", "debug", "internal"]);
40569
+ EXPLICIT_VISIBLE_VISIBILITIES = /* @__PURE__ */ new Set(["visible", "user", "chat"]);
40570
+ HIDDEN_AUDIENCES = /* @__PURE__ */ new Set(["debug", "trace", "internal"]);
40571
+ ACTIVITY_SOURCE_SET = new Set(CHAT_MESSAGE_ACTIVITY_SOURCES);
40572
+ INTERNAL_SOURCE_SET = new Set(CHAT_MESSAGE_INTERNAL_SOURCES);
40573
+ }
40574
+ });
39923
40575
  function resolveReconcileIntervalMs() {
39924
40576
  const raw = readNonEmptyString2(process.env.MESH_RECONCILE_INTERVAL_MS);
39925
40577
  if (raw) {
@@ -40022,6 +40674,15 @@ Next step: ${nextStep}`;
40022
40674
  LOG2.warn("MeshReconcile", `Pending-claim recovery trigger failed for mesh ${mesh.id}: ${e?.message || e}`);
40023
40675
  }
40024
40676
  }
40677
+ for (const mesh of listMeshes()) {
40678
+ const selfIds = resolveCoordinatorSelfIds(mesh, drainDaemonIds);
40679
+ if (!daemonHostsMesh(mesh, selfIds)) continue;
40680
+ try {
40681
+ await reconcileUnterminatedDirectDispatches(components, mesh, selfIds, localDaemonId);
40682
+ } catch (e) {
40683
+ LOG2.warn("MeshReconcile", `Completion reconcile failed for mesh ${mesh.id}: ${e?.message || e}`);
40684
+ }
40685
+ }
40025
40686
  const coordinators = findLiveCoordinators(components);
40026
40687
  if (coordinators.length === 0) {
40027
40688
  return;
@@ -40115,6 +40776,95 @@ Next step: ${nextStep}`;
40115
40776
  }
40116
40777
  }
40117
40778
  }
40779
+ function unwrapReadChatPayload(raw) {
40780
+ let cursor = raw;
40781
+ for (let depth = 0; depth < 4 && cursor && typeof cursor === "object"; depth++) {
40782
+ const record2 = cursor;
40783
+ if (Array.isArray(record2.messages)) return record2;
40784
+ if (record2.payload && typeof record2.payload === "object") {
40785
+ cursor = record2.payload;
40786
+ continue;
40787
+ }
40788
+ if (record2.result && typeof record2.result === "object") {
40789
+ cursor = record2.result;
40790
+ continue;
40791
+ }
40792
+ if (record2.data && typeof record2.data === "object") {
40793
+ cursor = record2.data;
40794
+ continue;
40795
+ }
40796
+ break;
40797
+ }
40798
+ return cursor && typeof cursor === "object" ? cursor : null;
40799
+ }
40800
+ function readChatPayloadStatus(payload) {
40801
+ return readNonEmptyString2(payload?.status).toLowerCase();
40802
+ }
40803
+ async function reconcileUnterminatedDirectDispatches(components, mesh, selfIds, localDaemonId) {
40804
+ const dispatches = getActiveDirectDispatches(mesh.id);
40805
+ if (dispatches.length === 0) return;
40806
+ const dispatchMeshCommand = components.dispatchMeshCommand;
40807
+ const nodeById = new Map(mesh.nodes.map((n) => [n.id, n]));
40808
+ for (const dispatch of dispatches) {
40809
+ const sessionId = readNonEmptyString2(dispatch.sessionId);
40810
+ const nodeId = readNonEmptyString2(dispatch.nodeId);
40811
+ const taskId = readNonEmptyString2(dispatch.taskId);
40812
+ if (!sessionId || !nodeId || !taskId) continue;
40813
+ const node = nodeById.get(nodeId);
40814
+ const nodeDaemonId = readNonEmptyString2(node?.daemonId);
40815
+ const isLocalNode = !nodeDaemonId || selfIds.includes(nodeDaemonId) || localDaemonId !== void 0 && nodeDaemonId === localDaemonId || !!components.instanceManager.getInstance(sessionId);
40816
+ const providerType = readNonEmptyString2(dispatch.providerType);
40817
+ const readArgs = {
40818
+ sessionId,
40819
+ targetSessionId: sessionId,
40820
+ tailLimit: 10,
40821
+ ...node?.workspace ? { workspace: node.workspace } : {},
40822
+ ...providerType ? { agentType: providerType, providerType } : {}
40823
+ };
40824
+ let payload = null;
40825
+ try {
40826
+ if (isLocalNode) {
40827
+ const result = await components.commandHandler.handle("read_chat", readArgs);
40828
+ if (result && result.success === false) continue;
40829
+ payload = unwrapReadChatPayload(result);
40830
+ } else if (dispatchMeshCommand) {
40831
+ const result = await dispatchMeshCommand(nodeDaemonId, "read_chat", readArgs);
40832
+ payload = unwrapReadChatPayload(result);
40833
+ if (payload && payload.success === false) continue;
40834
+ } else {
40835
+ continue;
40836
+ }
40837
+ } catch {
40838
+ continue;
40839
+ }
40840
+ if (!payload) continue;
40841
+ if (readChatPayloadStatus(payload) !== "idle") continue;
40842
+ const messages = Array.isArray(payload.messages) ? payload.messages : [];
40843
+ const evidence = extractFinalAssistantSummaryEvidence(messages);
40844
+ if (!evidence.finalSummary) continue;
40845
+ const providerSessionId = readNonEmptyString2(payload.providerSessionId);
40846
+ const coordinatorDaemonId = selfIds.find((id) => !!id);
40847
+ try {
40848
+ const result = reconcileDirectDispatchCompletionFromTranscript({
40849
+ meshId: mesh.id,
40850
+ nodeId,
40851
+ sessionId,
40852
+ providerType: providerType || void 0,
40853
+ providerSessionId: providerSessionId || void 0,
40854
+ taskId,
40855
+ finalSummary: evidence.finalSummary,
40856
+ ...evidence.transcriptMessageAt ? { transcriptMessageAt: evidence.transcriptMessageAt } : {},
40857
+ ...coordinatorDaemonId ? { targetCoordinatorDaemonId: coordinatorDaemonId } : {},
40858
+ source: "daemon_reconcile_transcript_completion"
40859
+ });
40860
+ if (result.reconciled) {
40861
+ LOG2.info("MeshReconcile", `Synthesized missing completion (${result.kind}) for task ${taskId} on node ${nodeId} (mesh ${mesh.id})`);
40862
+ }
40863
+ } catch (e) {
40864
+ LOG2.warn("MeshReconcile", `Transcript completion reconcile threw for task ${taskId}: ${e?.message || e}`);
40865
+ }
40866
+ }
40867
+ }
40118
40868
  function extractPendingEvents(raw) {
40119
40869
  if (Array.isArray(raw)) return raw;
40120
40870
  if (raw && typeof raw === "object") {
@@ -40164,6 +40914,9 @@ Next step: ${nextStep}`;
40164
40914
  init_mesh_events_coordinator();
40165
40915
  init_mesh_unresolved_forward_outbox();
40166
40916
  init_mesh_events_utils();
40917
+ init_mesh_work_queue();
40918
+ init_mesh_events_stale();
40919
+ init_chat_message_normalization();
40167
40920
  DEFAULT_RECONCILE_INTERVAL_MS = 4e3;
40168
40921
  }
40169
40922
  });
@@ -43931,6 +44684,8 @@ ${lastSnapshot}`;
43931
44684
  errorMessage: this.parseErrorMessage || this.engine.providerErrorMessage || void 0,
43932
44685
  errorReason: this.parseErrorMessage ? "parse_error" : this.engine.providerErrorReason || void 0,
43933
44686
  providerSessionId: this.providerSessionId || void 0,
44687
+ lastOutputAt: this.lastOutputAt,
44688
+ lastScreenChangeAt: this.lastScreenChangeAt,
43934
44689
  ...bufferState ? { bufferState } : {}
43935
44690
  };
43936
44691
  }
@@ -46963,7 +47718,8 @@ ${lastSnapshot}`;
46963
47718
  if (includeSubmodules !== void 0) statusParams.includeSubmodules = includeSubmodules;
46964
47719
  if (submoduleIgnorePaths && submoduleIgnorePaths.length > 0) statusParams.submoduleIgnorePaths = submoduleIgnorePaths;
46965
47720
  const status = await runService(() => services.getStatus(statusParams));
46966
- return "success" in status ? status : { success: true, status };
47721
+ if ("success" in status) return status;
47722
+ return { success: true, status, reporterPlatform: process.platform, reporterArch: process.arch };
46967
47723
  }
46968
47724
  case "git_diff_summary": {
46969
47725
  if (!services.getDiffSummary) return serviceNotImplemented(command);
@@ -50597,253 +51353,8 @@ ${lastSnapshot}`;
50597
51353
  }
50598
51354
  };
50599
51355
  var crypto2 = __toESM2(require("crypto"));
50600
- function normalizeInputEnvelope(input) {
50601
- const normalized = normalizeInputEnvelopePayload(input);
50602
- const textFallback = normalized.textFallback ?? flattenInputParts(normalized.parts);
50603
- return {
50604
- parts: normalized.parts,
50605
- textFallback,
50606
- ...normalized.metadata ? { metadata: normalized.metadata } : {}
50607
- };
50608
- }
50609
- function normalizeMessageParts(content) {
50610
- if (typeof content === "string") return [{ type: "text", text: content }];
50611
- if (!Array.isArray(content)) {
50612
- if (content && typeof content === "object" && typeof content.text === "string") {
50613
- return [{ type: "text", text: String(content.text) }];
50614
- }
50615
- return [];
50616
- }
50617
- const parts = [];
50618
- for (const raw of content) {
50619
- if (typeof raw === "string") {
50620
- parts.push({ type: "text", text: raw });
50621
- continue;
50622
- }
50623
- if (!raw || typeof raw !== "object") continue;
50624
- const part = normalizeMessagePartObject(raw);
50625
- if (part) parts.push(part);
50626
- }
50627
- return parts;
50628
- }
50629
- function flattenMessageParts(parts) {
50630
- return parts.map((part) => {
50631
- if (part.type === "text") return part.text;
50632
- if (part.type === "resource") return part.resource.text || "";
50633
- if (part.type === "image") return part.alt || (part.data ? `[image: ${part.mimeType}]` : "");
50634
- if (part.type === "audio") return part.transcript || (part.data ? `[audio: ${part.mimeType}]` : "");
50635
- if (part.type === "video") return part.transcript || (part.data ? `[video: ${part.mimeType}]` : "");
50636
- if (part.type === "resource_link") return [part.name, part.description].filter(Boolean).join("\n");
50637
- return "";
50638
- }).filter((value) => value.length > 0).join("\n");
50639
- }
50640
- function normalizeInputEnvelopePayload(input) {
50641
- if (typeof input === "string") {
50642
- return { parts: [{ type: "text", text: input }], textFallback: input };
50643
- }
50644
- if (!input || typeof input !== "object") {
50645
- return { parts: [], textFallback: "" };
50646
- }
50647
- const record2 = input;
50648
- const nestedInput = record2.input;
50649
- if (nestedInput && typeof nestedInput === "object") {
50650
- const nested = nestedInput;
50651
- return {
50652
- parts: normalizeInputParts(nested.parts ?? nested.prompt),
50653
- textFallback: typeof nested.textFallback === "string" ? nested.textFallback : void 0,
50654
- metadata: normalizeInputMetadata(nested.metadata)
50655
- };
50656
- }
50657
- const directText = typeof record2.text === "string" ? record2.text : typeof record2.message === "string" ? record2.message : void 0;
50658
- if (directText !== void 0) {
50659
- return { parts: [{ type: "text", text: directText }], textFallback: directText };
50660
- }
50661
- const directParts = normalizeInputParts(record2.parts ?? record2.prompt);
50662
- return {
50663
- parts: directParts,
50664
- textFallback: typeof record2.textFallback === "string" ? record2.textFallback : void 0,
50665
- metadata: normalizeInputMetadata(record2.metadata)
50666
- };
50667
- }
50668
- function normalizeInputMetadata(value) {
50669
- if (!value || typeof value !== "object") return void 0;
50670
- const record2 = value;
50671
- const metadata = {};
50672
- if (record2.source === "dashboard" || record2.source === "shortcut_api" || record2.source === "provider_script" || record2.source === "session_replay") {
50673
- metadata.source = record2.source;
50674
- }
50675
- if (typeof record2.clientTimestamp === "number" && Number.isFinite(record2.clientTimestamp)) {
50676
- metadata.clientTimestamp = record2.clientTimestamp;
50677
- }
50678
- return Object.keys(metadata).length > 0 ? metadata : void 0;
50679
- }
50680
- function normalizeInputParts(value) {
50681
- if (!Array.isArray(value)) return [];
50682
- const parts = [];
50683
- for (const raw of value) {
50684
- if (typeof raw === "string") {
50685
- parts.push({ type: "text", text: raw });
50686
- continue;
50687
- }
50688
- if (!raw || typeof raw !== "object") continue;
50689
- const part = normalizeInputPartObject(raw);
50690
- if (part) parts.push(part);
50691
- }
50692
- return parts;
50693
- }
50694
- function normalizeInputPartObject(raw) {
50695
- const type = raw.type;
50696
- if (type === "text" && typeof raw.text === "string") {
50697
- return { type, text: raw.text };
50698
- }
50699
- if (type === "image" && typeof raw.mimeType === "string") {
50700
- return {
50701
- type,
50702
- mimeType: raw.mimeType,
50703
- ...typeof raw.uri === "string" ? { uri: raw.uri } : {},
50704
- ...typeof raw.data === "string" ? { data: raw.data } : {},
50705
- ...typeof raw.alt === "string" ? { alt: raw.alt } : {}
50706
- };
50707
- }
50708
- if (type === "audio" && typeof raw.mimeType === "string") {
50709
- return {
50710
- type,
50711
- mimeType: raw.mimeType,
50712
- ...typeof raw.uri === "string" ? { uri: raw.uri } : {},
50713
- ...typeof raw.data === "string" ? { data: raw.data } : {},
50714
- ...typeof raw.transcript === "string" ? { transcript: raw.transcript } : {}
50715
- };
50716
- }
50717
- if (type === "video" && typeof raw.mimeType === "string") {
50718
- return {
50719
- type,
50720
- mimeType: raw.mimeType,
50721
- ...typeof raw.uri === "string" ? { uri: raw.uri } : {},
50722
- ...typeof raw.data === "string" ? { data: raw.data } : {},
50723
- ...typeof raw.transcript === "string" ? { transcript: raw.transcript } : {},
50724
- ...typeof raw.posterUri === "string" ? { posterUri: raw.posterUri } : {}
50725
- };
50726
- }
50727
- if (type === "resource" && typeof raw.uri === "string") {
50728
- return {
50729
- type,
50730
- uri: raw.uri,
50731
- ...typeof raw.mimeType === "string" ? { mimeType: raw.mimeType } : {},
50732
- ...typeof raw.name === "string" ? { name: raw.name } : {},
50733
- ...typeof raw.text === "string" ? { text: raw.text } : {},
50734
- ...typeof raw.data === "string" ? { data: raw.data } : {}
50735
- };
50736
- }
50737
- if (type === "resource_link" && typeof raw.uri === "string") {
50738
- return {
50739
- type,
50740
- uri: raw.uri,
50741
- name: typeof raw.name === "string" ? raw.name : getUriDisplayName(raw.uri, "resource"),
50742
- ...typeof raw.title === "string" ? { title: raw.title } : {},
50743
- ...typeof raw.description === "string" ? { description: raw.description } : {},
50744
- ...typeof raw.mimeType === "string" ? { mimeType: raw.mimeType } : {},
50745
- ...typeof raw.size === "number" && Number.isFinite(raw.size) ? { size: raw.size } : {},
50746
- ...normalizeAnnotationsProperty(raw.annotations)
50747
- };
50748
- }
50749
- return null;
50750
- }
50751
- function normalizeMessagePartObject(raw) {
50752
- const type = raw.type;
50753
- if (type === "text" && typeof raw.text === "string") {
50754
- return { type, text: raw.text };
50755
- }
50756
- if (type === "image" && typeof raw.mimeType === "string") {
50757
- return {
50758
- type,
50759
- mimeType: raw.mimeType,
50760
- ...typeof raw.uri === "string" ? { uri: raw.uri } : {},
50761
- ...typeof raw.data === "string" ? { data: raw.data } : {},
50762
- ...typeof raw.alt === "string" ? { alt: raw.alt } : {}
50763
- };
50764
- }
50765
- if (type === "audio" && typeof raw.mimeType === "string") {
50766
- return {
50767
- type,
50768
- mimeType: raw.mimeType,
50769
- ...typeof raw.uri === "string" ? { uri: raw.uri } : {},
50770
- ...typeof raw.data === "string" ? { data: raw.data } : {},
50771
- ...typeof raw.transcript === "string" ? { transcript: raw.transcript } : {}
50772
- };
50773
- }
50774
- if (type === "video" && typeof raw.mimeType === "string") {
50775
- return {
50776
- type,
50777
- mimeType: raw.mimeType,
50778
- ...typeof raw.uri === "string" ? { uri: raw.uri } : {},
50779
- ...typeof raw.data === "string" ? { data: raw.data } : {},
50780
- ...typeof raw.transcript === "string" ? { transcript: raw.transcript } : {},
50781
- ...typeof raw.posterUri === "string" ? { posterUri: raw.posterUri } : {}
50782
- };
50783
- }
50784
- if (type === "resource_link" && typeof raw.uri === "string" && typeof raw.name === "string") {
50785
- return {
50786
- type,
50787
- uri: raw.uri,
50788
- name: raw.name,
50789
- ...typeof raw.title === "string" ? { title: raw.title } : {},
50790
- ...typeof raw.description === "string" ? { description: raw.description } : {},
50791
- ...typeof raw.mimeType === "string" ? { mimeType: raw.mimeType } : {},
50792
- ...typeof raw.size === "number" && Number.isFinite(raw.size) ? { size: raw.size } : {},
50793
- ...normalizeAnnotationsProperty(raw.annotations)
50794
- };
50795
- }
50796
- if (type === "resource" && raw.resource && typeof raw.resource === "object") {
50797
- const resource = raw.resource;
50798
- if (typeof resource.uri !== "string") return null;
50799
- return {
50800
- type,
50801
- resource: {
50802
- uri: resource.uri,
50803
- ...typeof resource.mimeType === "string" || resource.mimeType === null ? { mimeType: resource.mimeType } : {},
50804
- ...typeof resource.text === "string" ? { text: resource.text } : {},
50805
- ...typeof resource.blob === "string" ? { blob: resource.blob } : {}
50806
- }
50807
- };
50808
- }
50809
- return null;
50810
- }
50811
- function flattenInputParts(parts) {
50812
- return parts.map((part) => {
50813
- if (part.type === "text") return part.text;
50814
- if (part.type === "image") return part.alt || (part.data ? `[image: ${part.mimeType}]` : "");
50815
- if (part.type === "audio") return part.transcript || (part.data ? `[audio: ${part.mimeType}]` : "");
50816
- if (part.type === "video") return part.transcript || (part.data ? `[video: ${part.mimeType}]` : "");
50817
- if (part.type === "resource_link") return [part.title, part.name, part.description, part.uri].filter(Boolean).join("\n");
50818
- if (part.type === "resource") return part.text || part.name || part.uri;
50819
- return "";
50820
- }).filter((value) => value.length > 0).join("\n");
50821
- }
50822
- function getUriDisplayName(uri, fallback) {
50823
- try {
50824
- const pathname = uri.startsWith("file://") ? new URL(uri).pathname : uri;
50825
- return pathname.split(/[\\/]/).filter(Boolean).pop() || fallback;
50826
- } catch {
50827
- return uri.split(/[\\/]/).filter(Boolean).pop() || fallback;
50828
- }
50829
- }
50830
- function normalizeAnnotationsProperty(value) {
50831
- if (!value || typeof value !== "object") return {};
50832
- const record2 = value;
50833
- const annotations = {};
50834
- if (Array.isArray(record2.audience)) {
50835
- const audience = record2.audience.filter((item) => item === "user" || item === "assistant");
50836
- if (audience.length > 0) annotations.audience = audience;
50837
- }
50838
- if (typeof record2.priority === "number" && Number.isFinite(record2.priority)) {
50839
- annotations.priority = record2.priority;
50840
- }
50841
- return Object.keys(annotations).length > 0 ? { annotations } : {};
50842
- }
50843
- function flattenContent(content) {
50844
- if (typeof content === "string") return content;
50845
- return flattenMessageParts(normalizeMessageParts(content));
50846
- }
51356
+ init_contracts();
51357
+ init_contracts();
50847
51358
  var DEFAULT_MONITOR_CONFIG = {
50848
51359
  approvalAlert: true,
50849
51360
  longGeneratingAlert: true,
@@ -50954,339 +51465,8 @@ ${lastSnapshot}`;
50954
51465
  }
50955
51466
  }
50956
51467
  };
50957
- var DEFAULT_FINAL_SUMMARY_MAX_CHARS = 4e3;
50958
- function extractFinalSummaryFromMessages(messages, maxChars = DEFAULT_FINAL_SUMMARY_MAX_CHARS) {
50959
- if (!Array.isArray(messages) || messages.length === 0) return "";
50960
- for (let i = messages.length - 1; i >= 0; i--) {
50961
- const msg = messages[i];
50962
- if (!msg) continue;
50963
- const classification = classifyChatMessageVisibility(msg);
50964
- if (classification.isUserFacing && (msg.role === "assistant" || msg.role === "model")) {
50965
- const text = flattenContent(msg.content).trim();
50966
- if (text) return text.slice(0, maxChars);
50967
- }
50968
- }
50969
- return "";
50970
- }
50971
- var BUILTIN_CHAT_MESSAGE_KINDS = ["standard", "thought", "tool", "terminal", "system"];
50972
- var CHAT_MESSAGE_VISIBILITIES = ["user", "debug", "internal", "hidden"];
50973
- var CHAT_MESSAGE_TRANSCRIPT_VISIBILITIES = ["visible", "chat", "user", "debug", "internal", "hidden"];
50974
- var CHAT_MESSAGE_AUDIENCES = ["chat", "debug", "trace", "internal"];
50975
- var CHAT_MESSAGE_SOURCES = [
50976
- "assistant_text",
50977
- "tool_call",
50978
- "terminal_command",
50979
- "runtime_activity",
50980
- "runtime_status",
50981
- "provider_chrome",
50982
- "control"
50983
- ];
50984
- var CHAT_MESSAGE_ACTIVITY_SOURCES = ["tool_call", "terminal_command", "runtime_activity"];
50985
- var CHAT_MESSAGE_INTERNAL_SOURCES = ["runtime_status", "provider_chrome", "control"];
50986
- var KNOWN_CHAT_MESSAGE_KINDS = new Set(BUILTIN_CHAT_MESSAGE_KINDS);
50987
- var CHAT_MESSAGE_KIND_ALIASES = {
50988
- text: "standard",
50989
- message: "standard",
50990
- assistant: "standard",
50991
- thinking: "thought",
50992
- think: "thought",
50993
- reasoning: "thought",
50994
- reason: "thought",
50995
- toolcall: "tool",
50996
- tool_call: "tool",
50997
- tooluse: "tool",
50998
- tool_use: "tool",
50999
- action: "tool",
51000
- command: "terminal",
51001
- cmd: "terminal",
51002
- shell: "terminal",
51003
- console: "terminal"
51004
- };
51005
- function canonicalizeKindHint(value) {
51006
- return value.trim().toLowerCase().replace(/[\s-]+/g, "_");
51007
- }
51008
- function resolveBuiltinOrAliasKind(kind) {
51009
- if (typeof kind !== "string") return null;
51010
- const normalizedKind = canonicalizeKindHint(kind);
51011
- if (!normalizedKind) return null;
51012
- if (KNOWN_CHAT_MESSAGE_KINDS.has(normalizedKind)) return normalizedKind;
51013
- return CHAT_MESSAGE_KIND_ALIASES[normalizedKind] || null;
51014
- }
51015
- function inferHintKind(value) {
51016
- const direct = resolveBuiltinOrAliasKind(value);
51017
- if (direct) return direct;
51018
- if (typeof value !== "string") return null;
51019
- const normalized = canonicalizeKindHint(value);
51020
- if (!normalized) return null;
51021
- if (/thought|thinking|reasoning/.test(normalized)) return "thought";
51022
- if (/tool/.test(normalized)) return "tool";
51023
- if (/terminal|command|shell|console/.test(normalized)) return "terminal";
51024
- return null;
51025
- }
51026
- function inferKindFromToolCalls(message) {
51027
- const toolCalls = Array.isArray(message?.toolCalls) ? message.toolCalls : [];
51028
- if (toolCalls.length === 0) return null;
51029
- if (toolCalls.some((toolCall) => toolCall?.kind === "think")) return "thought";
51030
- if (toolCalls.some((toolCall) => toolCall?.kind === "execute")) return "terminal";
51031
- if (toolCalls.some((toolCall) => Array.isArray(toolCall?.content) && toolCall.content.some((entry) => entry?.type === "terminal"))) {
51032
- return "terminal";
51033
- }
51034
- return "tool";
51035
- }
51036
- function inferMissingChatMessageKind(message) {
51037
- const role = typeof message?.role === "string" ? message.role.trim().toLowerCase() : "";
51038
- if (role === "system") return "system";
51039
- const meta3 = message?.meta && typeof message.meta === "object" ? message.meta : void 0;
51040
- const hintCandidates = [
51041
- message?._sub,
51042
- message?._type,
51043
- meta3?.label,
51044
- typeof message?.senderName === "string" ? message.senderName : void 0
51045
- ];
51046
- for (const candidate of hintCandidates) {
51047
- const inferred = inferHintKind(candidate);
51048
- if (inferred) return inferred;
51049
- }
51050
- const inferredFromToolCalls = inferKindFromToolCalls(message);
51051
- if (inferredFromToolCalls) return inferredFromToolCalls;
51052
- return null;
51053
- }
51054
- function isBuiltinChatMessageKind(kind) {
51055
- return resolveBuiltinOrAliasKind(kind) !== null;
51056
- }
51057
- function normalizeChatMessageKind(kind, role) {
51058
- const resolvedKind = resolveBuiltinOrAliasKind(kind);
51059
- if (resolvedKind) return resolvedKind;
51060
- const normalizedRole = typeof role === "string" ? role.trim().toLowerCase() : "";
51061
- return normalizedRole === "system" ? "system" : "standard";
51062
- }
51063
- function resolveChatMessageKind(message) {
51064
- const explicitKind = resolveBuiltinOrAliasKind(message?.kind);
51065
- if (explicitKind) return explicitKind;
51066
- const inferredKind = inferMissingChatMessageKind(message);
51067
- if (inferredKind) return inferredKind;
51068
- return normalizeChatMessageKind(message?.kind, message?.role);
51069
- }
51070
- function buildChatMessage(message) {
51071
- return {
51072
- ...message,
51073
- kind: resolveChatMessageKind(message)
51074
- };
51075
- }
51076
- function buildSystemChatMessage(message) {
51077
- return buildChatMessage({
51078
- ...message,
51079
- role: "system",
51080
- kind: message?.kind || "system"
51081
- });
51082
- }
51083
- function buildRuntimeSystemChatMessage(message) {
51084
- return buildSystemChatMessage({
51085
- ...message,
51086
- senderName: typeof message?.senderName === "string" && message.senderName.trim() ? message.senderName : "System"
51087
- });
51088
- }
51089
- function buildAssistantChatMessage(message) {
51090
- return buildChatMessage({
51091
- ...message,
51092
- role: "assistant",
51093
- kind: message?.kind || "standard"
51094
- });
51095
- }
51096
- function buildThoughtChatMessage(message) {
51097
- return buildAssistantChatMessage({
51098
- ...message,
51099
- kind: message?.kind || "thought"
51100
- });
51101
- }
51102
- function buildToolChatMessage(message) {
51103
- return buildAssistantChatMessage({
51104
- ...message,
51105
- kind: message?.kind || "tool"
51106
- });
51107
- }
51108
- function buildTerminalChatMessage(message) {
51109
- return buildAssistantChatMessage({
51110
- ...message,
51111
- kind: message?.kind || "terminal"
51112
- });
51113
- }
51114
- function buildUserChatMessage(message) {
51115
- return buildChatMessage({
51116
- ...message,
51117
- role: "user",
51118
- kind: message?.kind || "standard"
51119
- });
51120
- }
51121
- function normalizeChatMessage(message) {
51122
- return buildChatMessage(message);
51123
- }
51124
- function normalizeChatMessages(messages) {
51125
- return (Array.isArray(messages) ? messages : []).map((message) => normalizeChatMessage(message));
51126
- }
51127
- function readMessageMeta(message) {
51128
- const meta3 = message?.meta;
51129
- return meta3 && typeof meta3 === "object" && !Array.isArray(meta3) ? meta3 : null;
51130
- }
51131
- function readStringField(value) {
51132
- return typeof value === "string" ? value.trim().toLowerCase() : "";
51133
- }
51134
- function readRecordField(message, meta3, key) {
51135
- const record2 = message;
51136
- return record2[key] ?? meta3?.[key];
51137
- }
51138
- function readVisibilityField(message, meta3) {
51139
- return readStringField(readRecordField(message, meta3, "visibility"));
51140
- }
51141
- function readTranscriptVisibilityField(message, meta3) {
51142
- const record2 = message;
51143
- return readStringField(record2.transcriptVisibility ?? meta3?.transcriptVisibility ?? record2.visibility ?? meta3?.visibility);
51144
- }
51145
- var EXPLICIT_HIDDEN_VISIBILITIES = /* @__PURE__ */ new Set(["hidden", "debug", "internal"]);
51146
- var EXPLICIT_VISIBLE_VISIBILITIES = /* @__PURE__ */ new Set(["visible", "user", "chat"]);
51147
- var HIDDEN_AUDIENCES = /* @__PURE__ */ new Set(["debug", "trace", "internal"]);
51148
- var ACTIVITY_SOURCE_SET = new Set(CHAT_MESSAGE_ACTIVITY_SOURCES);
51149
- var INTERNAL_SOURCE_SET = new Set(CHAT_MESSAGE_INTERNAL_SOURCES);
51150
- function hasBooleanMarker(message, meta3, keys) {
51151
- const record2 = message;
51152
- return keys.some((key) => record2[key] === true || meta3?.[key] === true);
51153
- }
51154
- function isActivityKind(kind) {
51155
- return kind === "thought" || kind === "tool" || kind === "terminal";
51156
- }
51157
- function isOrdinaryVisibleTurn(message, role, kind) {
51158
- if (role === "user" || role === "human") return kind === "standard" || kind === "";
51159
- if (role === "assistant") return kind === "standard" || kind === "";
51160
- return false;
51161
- }
51162
- function classifyChatMessageVisibility(message) {
51163
- if (!message) {
51164
- return {
51165
- surface: "internal",
51166
- isUserFacing: false,
51167
- isActivityFacing: false,
51168
- isInternal: true,
51169
- explicitUserFacing: false,
51170
- explicitHidden: true,
51171
- role: "",
51172
- kind: "standard",
51173
- visibility: "",
51174
- transcriptVisibility: "",
51175
- audience: "",
51176
- source: ""
51177
- };
51178
- }
51179
- const meta3 = readMessageMeta(message);
51180
- const role = typeof message.role === "string" ? message.role.trim().toLowerCase() : "";
51181
- const kind = resolveChatMessageKind(message);
51182
- const visibility = readVisibilityField(message, meta3);
51183
- const transcriptVisibility = readTranscriptVisibilityField(message, meta3);
51184
- const audience = readStringField(readRecordField(message, meta3, "audience"));
51185
- const source = readStringField(readRecordField(message, meta3, "source"));
51186
- const explicitHidden = EXPLICIT_HIDDEN_VISIBILITIES.has(visibility) || EXPLICIT_HIDDEN_VISIBILITIES.has(transcriptVisibility) || HIDDEN_AUDIENCES.has(audience) || hasBooleanMarker(message, meta3, ["hidden", "internal", "isInternal", "debug", "statusOnly", "controlOnly"]);
51187
- const explicitUserFacing = EXPLICIT_VISIBLE_VISIBILITIES.has(visibility) || EXPLICIT_VISIBLE_VISIBILITIES.has(transcriptVisibility) || audience === "chat" || hasBooleanMarker(message, meta3, ["userFacing"]);
51188
- if (explicitHidden) {
51189
- const activityLike = isActivityKind(kind) || ACTIVITY_SOURCE_SET.has(source);
51190
- return {
51191
- surface: activityLike ? "activity" : "internal",
51192
- isUserFacing: false,
51193
- isActivityFacing: activityLike,
51194
- isInternal: !activityLike,
51195
- explicitUserFacing,
51196
- explicitHidden,
51197
- role,
51198
- kind,
51199
- visibility,
51200
- transcriptVisibility,
51201
- audience,
51202
- source
51203
- };
51204
- }
51205
- if (explicitUserFacing) {
51206
- return {
51207
- surface: "chat",
51208
- isUserFacing: true,
51209
- isActivityFacing: false,
51210
- isInternal: false,
51211
- explicitUserFacing,
51212
- explicitHidden,
51213
- role,
51214
- kind,
51215
- visibility,
51216
- transcriptVisibility,
51217
- audience,
51218
- source
51219
- };
51220
- }
51221
- if (INTERNAL_SOURCE_SET.has(source) || role === "system" || kind === "system") {
51222
- return {
51223
- surface: "internal",
51224
- isUserFacing: false,
51225
- isActivityFacing: false,
51226
- isInternal: true,
51227
- explicitUserFacing,
51228
- explicitHidden,
51229
- role,
51230
- kind,
51231
- visibility,
51232
- transcriptVisibility,
51233
- audience,
51234
- source
51235
- };
51236
- }
51237
- if (ACTIVITY_SOURCE_SET.has(source) || isActivityKind(kind)) {
51238
- return {
51239
- surface: "activity",
51240
- isUserFacing: false,
51241
- isActivityFacing: true,
51242
- isInternal: false,
51243
- explicitUserFacing,
51244
- explicitHidden,
51245
- role,
51246
- kind,
51247
- visibility,
51248
- transcriptVisibility,
51249
- audience,
51250
- source
51251
- };
51252
- }
51253
- const isUserFacing = isOrdinaryVisibleTurn(message, role, kind);
51254
- return {
51255
- surface: isUserFacing ? "chat" : "internal",
51256
- isUserFacing,
51257
- isActivityFacing: false,
51258
- isInternal: !isUserFacing,
51259
- explicitUserFacing,
51260
- explicitHidden,
51261
- role,
51262
- kind,
51263
- visibility,
51264
- transcriptVisibility,
51265
- audience,
51266
- source
51267
- };
51268
- }
51269
- function isUserFacingChatMessage(message) {
51270
- return classifyChatMessageVisibility(message).isUserFacing;
51271
- }
51272
- function isActivityChatMessage(message) {
51273
- return classifyChatMessageVisibility(message).isActivityFacing;
51274
- }
51275
- function isInternalChatMessage(message) {
51276
- return classifyChatMessageVisibility(message).isInternal;
51277
- }
51278
- function filterUserFacingChatMessages(messages) {
51279
- return (Array.isArray(messages) ? messages : []).filter((message) => isUserFacingChatMessage(message));
51280
- }
51281
- function filterActivityChatMessages(messages) {
51282
- return (Array.isArray(messages) ? messages : []).filter((message) => isActivityChatMessage(message));
51283
- }
51284
- function filterInternalChatMessages(messages) {
51285
- return (Array.isArray(messages) ? messages : []).filter((message) => isInternalChatMessage(message));
51286
- }
51287
- function filterChatMessagesByVisibility(messages, surface) {
51288
- return (Array.isArray(messages) ? messages : []).filter((message) => classifyChatMessageVisibility(message).surface === surface);
51289
- }
51468
+ init_contracts();
51469
+ init_chat_message_normalization();
51290
51470
  function extractProviderControlValues(controls, data) {
51291
51471
  if (!data || typeof data !== "object") return void 0;
51292
51472
  const values = {};
@@ -51481,6 +51661,7 @@ ${cleanBody}`;
51481
51661
  var fs6 = __toESM2(require("fs"));
51482
51662
  var path14 = __toESM2(require("path"));
51483
51663
  var os8 = __toESM2(require("os"));
51664
+ init_chat_message_normalization();
51484
51665
  var HISTORY_DIR = path14.join(os8.homedir(), ".adhdev", "history");
51485
51666
  var RETAIN_DAYS = 30;
51486
51667
  var SAVED_HISTORY_INDEX_VERSION = 1;
@@ -53016,6 +53197,7 @@ ${cleanBody}`;
53016
53197
  })
53017
53198
  };
53018
53199
  }
53200
+ init_chat_message_normalization();
53019
53201
  var IDE_PROVIDER_SESSION_CAPABILITIES_BASE = [
53020
53202
  "read_chat",
53021
53203
  "send_message",
@@ -53445,6 +53627,7 @@ ${effect.notification.body || ""}`.trim();
53445
53627
  }
53446
53628
  };
53447
53629
  init_logger();
53630
+ init_contracts();
53448
53631
  var CHAT_CONTRACT_VERSION_V1 = "1.0";
53449
53632
  var VALID_STATUSES = ["idle", "generating", "waiting_approval", "error", "panel_hidden", "starting", "streaming", "long_generating"];
53450
53633
  var VALID_ROLES = ["user", "assistant", "system", "human"];
@@ -53657,6 +53840,7 @@ ${effect.notification.body || ""}`.trim();
53657
53840
  if (/what do you want to do\?/i.test(text) && /^\s*\d+[.)]\s+\S/m.test(text)) return true;
53658
53841
  return false;
53659
53842
  }
53843
+ init_chat_message_normalization();
53660
53844
  async function withTimeout(promise2, timeoutMs, label) {
53661
53845
  let timer = null;
53662
53846
  try {
@@ -55287,6 +55471,7 @@ ${effect.notification.body || ""}`.trim();
55287
55471
  var os9 = __toESM2(require("os"));
55288
55472
  var path15 = __toESM2(require("path"));
55289
55473
  var import_node_crypto3 = require("crypto");
55474
+ init_contracts();
55290
55475
  init_logger();
55291
55476
  init_debug_config();
55292
55477
  function summarizeString(value) {
@@ -55765,6 +55950,7 @@ ${effect.notification.body || ""}`.trim();
55765
55950
  return `v1:${providerType}:${sessionId}:${ts2 ?? ""}:${positionalSeq}:${role}`;
55766
55951
  }
55767
55952
  var CHAT_SOURCE_REGISTRY = new ChatSourceRegistry();
55953
+ init_chat_message_normalization();
55768
55954
  var RECENT_SEND_WINDOW_MS = 1200;
55769
55955
  var READ_CHAT_PROVIDER_EVAL_TIMEOUT_MS = 25e3;
55770
55956
  var HOT_TAIL_MIN_LIMIT = 60;
@@ -60585,6 +60771,7 @@ ${formatManifestValidationIssues2(validation.issues)}`,
60585
60771
  var crypto4 = __toESM2(require("crypto"));
60586
60772
  var fs16 = __toESM2(require("fs"));
60587
60773
  var import_node_module = require("module");
60774
+ init_contracts();
60588
60775
  var fs15 = __toESM2(require("fs"));
60589
60776
  var path23 = __toESM2(require("path"));
60590
60777
  init_provider_cli_adapter();
@@ -63098,6 +63285,7 @@ ${formatManifestValidationIssues2(validation.issues)}`,
63098
63285
  }
63099
63286
  return normalizedId;
63100
63287
  }
63288
+ init_chat_message_normalization();
63101
63289
  function workingDirBasename(p) {
63102
63290
  return (p || "").split(/[\\/]/).filter(Boolean).pop() || "session";
63103
63291
  }
@@ -64225,7 +64413,7 @@ ${formatManifestValidationIssues2(validation.issues)}`,
64225
64413
  const dirName = workingDirBasename(this.workingDir);
64226
64414
  const chatTitle = `${this.provider.name} \xB7 ${dirName}`;
64227
64415
  const partial2 = this.adapter.getPartialResponse();
64228
- const progressFingerprint = newStatus === "generating" ? `${partial2 || ""}`.slice(-2e3) : void 0;
64416
+ const progressFingerprint = newStatus === "generating" ? `${`${partial2 || ""}`.slice(-2e3)}::scr=${adapterStatus.lastScreenChangeAt ?? 0}::out=${adapterStatus.lastOutputAt ?? 0}` : void 0;
64229
64417
  const previousStatus = this.lastStatus;
64230
64418
  if (newStatus !== this.lastStatus) {
64231
64419
  LOG2.info("CLI", `[${this.type}] status: ${this.lastStatus} \u2192 ${newStatus}`);
@@ -64899,6 +65087,8 @@ ${effect.notification.body || ""}`.trim();
64899
65087
  var import_stream = require("stream");
64900
65088
  var import_child_process5 = require("child_process");
64901
65089
  var import_sdk = (init_acp(), __toCommonJS(acp_exports));
65090
+ init_contracts();
65091
+ init_chat_message_normalization();
64902
65092
  init_logger();
64903
65093
  function getPromptCapabilityFlags(agentCapabilities) {
64904
65094
  const prompt = agentCapabilities?.promptCapabilities || {};
@@ -66126,6 +66316,7 @@ ${rawInput}` : rawInput;
66126
66316
  return this.agentCapabilities;
66127
66317
  }
66128
66318
  };
66319
+ init_contracts();
66129
66320
  init_logger();
66130
66321
  function shouldRestoreHostedRuntime(record2, managerTag) {
66131
66322
  if (!managerTag) return true;
@@ -72570,7 +72761,9 @@ ${formatManifestValidationIssues2(validation2.issues)}`);
72570
72761
  };
72571
72762
  }
72572
72763
  function recordInlineMeshDirectGitTruth(node, git, source) {
72573
- if (!node || typeof node !== "object" || Array.isArray(node)) return;
72764
+ if (!node || typeof node !== "object" || Array.isArray(node)) {
72765
+ return { reporterPlatform: null, reporterArch: null };
72766
+ }
72574
72767
  const checkedAt = readNumberValue(git.lastCheckedAt) ?? Date.now();
72575
72768
  const updatedAt = new Date(checkedAt).toISOString();
72576
72769
  const nextGit = {
@@ -72588,6 +72781,38 @@ ${formatManifestValidationIssues2(validation2.issues)}`);
72588
72781
  node.lastSeenAt = updatedAt;
72589
72782
  const repoRoot = readStringValue(nextGit.repoRoot);
72590
72783
  if (repoRoot && !readStringValue(node.repoRoot)) node.repoRoot = repoRoot;
72784
+ const isLocalSource = source === "selected_coordinator_local_git";
72785
+ const reporterPlatform = readStringValue(git.reporterPlatform) ?? (isLocalSource ? process.platform : null);
72786
+ const reporterArch = readStringValue(git.reporterArch) ?? (isLocalSource ? process.arch : null);
72787
+ stampNodeReporterPlatform(node, reporterPlatform, reporterArch);
72788
+ if (reporterPlatform) node.reportedPlatform = reporterPlatform;
72789
+ if (reporterArch) node.reportedArch = reporterArch;
72790
+ return { reporterPlatform, reporterArch };
72791
+ }
72792
+ function stampNodeReporterPlatform(node, platform10, arch2) {
72793
+ if (!node || typeof node !== "object" || Array.isArray(node)) return;
72794
+ if (!platform10 && !arch2) return;
72795
+ const overrides = node.userOverrides && typeof node.userOverrides === "object" && !Array.isArray(node.userOverrides) ? node.userOverrides : {};
72796
+ let changed = false;
72797
+ if (platform10 && !readStringValue(overrides.platform)) {
72798
+ overrides.platform = platform10;
72799
+ changed = true;
72800
+ }
72801
+ if (arch2 && !readStringValue(overrides.arch)) {
72802
+ overrides.arch = arch2;
72803
+ changed = true;
72804
+ }
72805
+ if (changed) node.userOverrides = overrides;
72806
+ }
72807
+ function persistNodeReporterPlatform(meshSource, mesh, nodeId, reporter) {
72808
+ if (meshSource !== "local_config") return;
72809
+ const meshId = readStringValue(mesh?.id);
72810
+ if (!meshId || !nodeId) return;
72811
+ const reportedPlatform = reporter.reporterPlatform ?? void 0;
72812
+ const reportedArch = reporter.reporterArch ?? void 0;
72813
+ if (!reportedPlatform && !reportedArch) return;
72814
+ void Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports)).then(({ updateNode: updateNode2 }) => updateNode2(meshId, nodeId, { reportedPlatform, reportedArch })).catch(() => {
72815
+ });
72591
72816
  }
72592
72817
  function buildCachedInlineMeshGitStatus(node) {
72593
72818
  const liveGit = buildInlineMeshTransitGitStatus(node);
@@ -73081,7 +73306,13 @@ ${formatManifestValidationIssues2(validation2.issues)}`);
73081
73306
  new Promise((_, reject) => setTimeout(() => reject(new Error("timeout")), args.timeoutMs))
73082
73307
  ]);
73083
73308
  const remoteGit = remoteResult?.status ?? remoteResult?.git ?? remoteResult;
73084
- return remoteGit && typeof remoteGit === "object" && typeof remoteGit.isGitRepo === "boolean" ? remoteGit : null;
73309
+ if (!remoteGit || typeof remoteGit !== "object" || typeof remoteGit.isGitRepo !== "boolean") return null;
73310
+ const reporterPlatform = readStringValue(remoteResult?.reporterPlatform);
73311
+ const reporterArch = readStringValue(remoteResult?.reporterArch);
73312
+ const git = remoteGit;
73313
+ if (reporterPlatform) git.reporterPlatform = reporterPlatform;
73314
+ if (reporterArch) git.reporterArch = reporterArch;
73315
+ return git;
73085
73316
  }
73086
73317
  var MESH_DIRECT_PROBE_MAX_RETRIES = 2;
73087
73318
  function readMeshConnectionState(connection) {
@@ -73164,7 +73395,8 @@ ${formatManifestValidationIssues2(validation2.issues)}`);
73164
73395
  try {
73165
73396
  const localGit = await getGitRepoStatus(workspace, { timeoutMs: 1e4, refreshUpstream: true });
73166
73397
  if (localGit?.isGitRepo) {
73167
- recordInlineMeshDirectGitTruth(node, localGit, "selected_coordinator_local_git");
73398
+ const reporter = recordInlineMeshDirectGitTruth(node, localGit, "selected_coordinator_local_git");
73399
+ persistNodeReporterPlatform(args.meshSource, args.mesh, nodeId, reporter);
73168
73400
  localConfirmedCount += 1;
73169
73401
  continue;
73170
73402
  }
@@ -73194,7 +73426,8 @@ ${formatManifestValidationIssues2(validation2.issues)}`);
73194
73426
  });
73195
73427
  const remoteGit = args.probeCache ? await args.probeCache.probe(daemonId, workspace, runProbe) : await runProbe();
73196
73428
  if (remoteGit) {
73197
- recordInlineMeshDirectGitTruth(node, remoteGit, "selected_coordinator_mesh_p2p_git");
73429
+ const reporter = recordInlineMeshDirectGitTruth(node, remoteGit, "selected_coordinator_mesh_p2p_git");
73430
+ persistNodeReporterPlatform(args.meshSource, args.mesh, nodeId, reporter);
73198
73431
  peerConfirmedCount += 1;
73199
73432
  continue;
73200
73433
  }
@@ -79411,7 +79644,8 @@ ${ptyResult.output.slice(-2e3)}`);
79411
79644
  if (!connectionReported || connectionState === "unknown") {
79412
79645
  status.connection = buildLivePeerGitConnection(connection, refreshedAt);
79413
79646
  }
79414
- recordInlineMeshDirectGitTruth(node, remoteGit, "selected_coordinator_mesh_p2p_git");
79647
+ const reporter = recordInlineMeshDirectGitTruth(node, remoteGit, "selected_coordinator_mesh_p2p_git");
79648
+ persistNodeReporterPlatform(meshRecord.source, mesh, nodeId, reporter);
79415
79649
  remoteProbeApplied = true;
79416
79650
  }
79417
79651
  }
@@ -79443,7 +79677,8 @@ ${ptyResult.output.slice(-2e3)}`);
79443
79677
  try {
79444
79678
  const gitStatus = await getGitRepoStatus(workspace, { timeoutMs: 1e4, refreshUpstream: true });
79445
79679
  status.git = gitStatus;
79446
- recordInlineMeshDirectGitTruth(node, gitStatus, "selected_coordinator_local_git");
79680
+ const reporter = recordInlineMeshDirectGitTruth(node, gitStatus, "selected_coordinator_local_git");
79681
+ persistNodeReporterPlatform(meshRecord.source, mesh, nodeId, reporter);
79447
79682
  if (gitStatus.isGitRepo) {
79448
79683
  status.health = deriveMeshNodeHealthFromGit(gitStatus);
79449
79684
  } else {
@@ -79973,6 +80208,7 @@ ${ptyResult.output.slice(-2e3)}`);
79973
80208
  init_debug_config();
79974
80209
  var DEFAULT_DAEMON_PORT2 = 19222;
79975
80210
  var DAEMON_WS_PATH2 = "/ipc";
80211
+ init_chat_message_normalization();
79976
80212
  function normalizeModalButtons(value) {
79977
80213
  return Array.isArray(value) ? value.filter((button) => typeof button === "string") : [];
79978
80214
  }
@@ -80109,6 +80345,7 @@ ${ptyResult.output.slice(-2e3)}`);
80109
80345
  });
80110
80346
  await Promise.all(runners);
80111
80347
  }
80348
+ init_chat_message_normalization();
80112
80349
  var ProviderStreamAdapter = class {
80113
80350
  agentType;
80114
80351
  agentName;
@@ -80789,6 +81026,7 @@ ${ptyResult.output.slice(-2e3)}`);
80789
81026
  }
80790
81027
  };
80791
81028
  init_logger();
81029
+ init_chat_message_normalization();
80792
81030
  var AgentStreamPoller = class {
80793
81031
  deps;
80794
81032
  timer = null;
@@ -81305,6 +81543,8 @@ ${ptyResult.output.slice(-2e3)}`);
81305
81543
  this.eventListeners = [];
81306
81544
  }
81307
81545
  };
81546
+ init_io_contracts();
81547
+ init_chat_message_normalization();
81308
81548
  var fs27 = __toESM2(require("fs"));
81309
81549
  var path37 = __toESM2(require("path"));
81310
81550
  var os28 = __toESM2(require("os"));