@adhdev/daemon-core 0.8.35 → 0.8.37
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/boot/daemon-lifecycle.d.ts +4 -0
- package/dist/commands/router.d.ts +3 -0
- package/dist/config/config.d.ts +5 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +458 -154
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +457 -154
- package/dist/index.mjs.map +1 -1
- package/dist/shared-types.d.ts +248 -16
- package/dist/status/builders.d.ts +5 -1
- package/dist/status/normalize.d.ts +11 -1
- package/dist/status/normalize.js +36 -16
- package/dist/status/normalize.js.map +1 -1
- package/dist/status/normalize.mjs +35 -16
- package/dist/status/normalize.mjs.map +1 -1
- package/dist/status/reporter.d.ts +4 -0
- package/dist/status/snapshot.d.ts +5 -5
- package/dist/types.d.ts +1 -1
- package/node_modules/@adhdev/session-host-core/package.json +1 -1
- package/package.json +1 -1
- package/src/boot/daemon-lifecycle.ts +7 -0
- package/src/commands/chat-commands.ts +192 -17
- package/src/commands/router.ts +25 -0
- package/src/commands/stream-commands.ts +14 -10
- package/src/config/config.ts +8 -0
- package/src/index.d.ts +2 -2
- package/src/index.ts +32 -1
- package/src/shared-types.d.ts +125 -16
- package/src/shared-types.ts +279 -16
- package/src/status/builders.ts +110 -54
- package/src/status/normalize.ts +54 -19
- package/src/status/reporter.ts +88 -13
- package/src/status/snapshot.ts +79 -41
- package/src/types.ts +1 -1
package/dist/index.mjs
CHANGED
|
@@ -62,6 +62,7 @@ function normalizeConfig(raw) {
|
|
|
62
62
|
const parsed = isPlainObject(raw) ? raw : {};
|
|
63
63
|
return {
|
|
64
64
|
serverUrl: typeof parsed.serverUrl === "string" && parsed.serverUrl.trim() ? parsed.serverUrl : DEFAULT_CONFIG.serverUrl,
|
|
65
|
+
allowServerApiProxy: asBoolean(parsed.allowServerApiProxy, DEFAULT_CONFIG.allowServerApiProxy ?? false),
|
|
65
66
|
selectedIde: asNullableString(parsed.selectedIde),
|
|
66
67
|
configuredIdes: asStringArray(parsed.configuredIdes),
|
|
67
68
|
installedExtensions: asStringArray(parsed.installedExtensions),
|
|
@@ -206,6 +207,7 @@ var init_config = __esm({
|
|
|
206
207
|
"use strict";
|
|
207
208
|
DEFAULT_CONFIG = {
|
|
208
209
|
serverUrl: "https://api.adhf.dev",
|
|
210
|
+
allowServerApiProxy: false,
|
|
209
211
|
selectedIde: null,
|
|
210
212
|
configuredIdes: [],
|
|
211
213
|
installedExtensions: [],
|
|
@@ -6898,11 +6900,24 @@ var WORKING_STATUSES = /* @__PURE__ */ new Set([
|
|
|
6898
6900
|
"thinking",
|
|
6899
6901
|
"active"
|
|
6900
6902
|
]);
|
|
6901
|
-
var
|
|
6902
|
-
|
|
6903
|
-
|
|
6904
|
-
|
|
6905
|
-
|
|
6903
|
+
var FULL_STATUS_ACTIVE_CHAT_OPTIONS = {
|
|
6904
|
+
includeMessages: true,
|
|
6905
|
+
includeInputContent: true,
|
|
6906
|
+
includeActiveModal: true,
|
|
6907
|
+
messageLimit: 60,
|
|
6908
|
+
totalBytesLimit: 96 * 1024,
|
|
6909
|
+
stringLimit: 4 * 1024,
|
|
6910
|
+
fallbackStringLimit: 1024
|
|
6911
|
+
};
|
|
6912
|
+
var LIVE_STATUS_ACTIVE_CHAT_OPTIONS = {
|
|
6913
|
+
includeMessages: false,
|
|
6914
|
+
includeInputContent: false,
|
|
6915
|
+
includeActiveModal: false,
|
|
6916
|
+
messageLimit: 0,
|
|
6917
|
+
totalBytesLimit: 0,
|
|
6918
|
+
stringLimit: 512,
|
|
6919
|
+
fallbackStringLimit: 256
|
|
6920
|
+
};
|
|
6906
6921
|
var STATUS_MODAL_MESSAGE_LIMIT = 2 * 1024;
|
|
6907
6922
|
var STATUS_MODAL_BUTTON_LIMIT = 120;
|
|
6908
6923
|
function truncateString(value, maxChars) {
|
|
@@ -6941,19 +6956,20 @@ function normalizeMessageTime(message) {
|
|
|
6941
6956
|
}
|
|
6942
6957
|
return msg;
|
|
6943
6958
|
}
|
|
6944
|
-
function trimMessagesForStatus(messages) {
|
|
6959
|
+
function trimMessagesForStatus(messages, options) {
|
|
6960
|
+
if (!options.includeMessages || options.messageLimit <= 0 || options.totalBytesLimit <= 0) return [];
|
|
6945
6961
|
if (!Array.isArray(messages) || messages.length === 0) return [];
|
|
6946
|
-
const recent = messages.slice(-
|
|
6962
|
+
const recent = messages.slice(-options.messageLimit);
|
|
6947
6963
|
const kept = [];
|
|
6948
6964
|
let totalBytes = 0;
|
|
6949
6965
|
for (let i = recent.length - 1; i >= 0; i -= 1) {
|
|
6950
|
-
let normalized = normalizeMessageTime(trimMessageForStatus(recent[i],
|
|
6966
|
+
let normalized = normalizeMessageTime(trimMessageForStatus(recent[i], options.stringLimit));
|
|
6951
6967
|
let size = estimateBytes(normalized);
|
|
6952
|
-
if (size >
|
|
6953
|
-
normalized = normalizeMessageTime(trimMessageForStatus(recent[i],
|
|
6968
|
+
if (size > options.totalBytesLimit) {
|
|
6969
|
+
normalized = normalizeMessageTime(trimMessageForStatus(recent[i], options.fallbackStringLimit));
|
|
6954
6970
|
size = estimateBytes(normalized);
|
|
6955
6971
|
}
|
|
6956
|
-
if (kept.length > 0 && totalBytes + size >
|
|
6972
|
+
if (kept.length > 0 && totalBytes + size > options.totalBytesLimit) {
|
|
6957
6973
|
continue;
|
|
6958
6974
|
}
|
|
6959
6975
|
kept.push(normalized);
|
|
@@ -6983,23 +6999,40 @@ function isManagedStatusWorking(status) {
|
|
|
6983
6999
|
function isManagedStatusWaiting(status, opts) {
|
|
6984
7000
|
return normalizeManagedStatus(status, opts) === "waiting_approval";
|
|
6985
7001
|
}
|
|
6986
|
-
function normalizeActiveChatData(activeChat) {
|
|
7002
|
+
function normalizeActiveChatData(activeChat, options = FULL_STATUS_ACTIVE_CHAT_OPTIONS) {
|
|
6987
7003
|
if (!activeChat) return activeChat;
|
|
7004
|
+
const resolvedOptions = {
|
|
7005
|
+
...FULL_STATUS_ACTIVE_CHAT_OPTIONS,
|
|
7006
|
+
...options
|
|
7007
|
+
};
|
|
6988
7008
|
return {
|
|
6989
7009
|
...activeChat,
|
|
6990
7010
|
status: normalizeManagedStatus(activeChat.status, { activeModal: activeChat.activeModal }),
|
|
6991
|
-
messages: trimMessagesForStatus(activeChat.messages),
|
|
6992
|
-
activeModal: activeChat.activeModal ? {
|
|
7011
|
+
messages: trimMessagesForStatus(activeChat.messages, resolvedOptions),
|
|
7012
|
+
activeModal: resolvedOptions.includeActiveModal && activeChat.activeModal ? {
|
|
6993
7013
|
message: truncateString(activeChat.activeModal.message || "", STATUS_MODAL_MESSAGE_LIMIT),
|
|
6994
7014
|
buttons: (activeChat.activeModal.buttons || []).map(
|
|
6995
7015
|
(button) => truncateString(String(button || ""), STATUS_MODAL_BUTTON_LIMIT)
|
|
6996
7016
|
)
|
|
6997
|
-
} :
|
|
6998
|
-
inputContent: activeChat.inputContent ? truncateString(activeChat.inputContent,
|
|
7017
|
+
} : null,
|
|
7018
|
+
inputContent: resolvedOptions.includeInputContent && activeChat.inputContent ? truncateString(activeChat.inputContent, 2 * 1024) : void 0
|
|
6999
7019
|
};
|
|
7000
7020
|
}
|
|
7001
7021
|
|
|
7002
7022
|
// src/status/builders.ts
|
|
7023
|
+
function getActiveChatOptions(profile) {
|
|
7024
|
+
if (profile === "full") return {};
|
|
7025
|
+
return LIVE_STATUS_ACTIVE_CHAT_OPTIONS;
|
|
7026
|
+
}
|
|
7027
|
+
function shouldIncludeSessionControls(profile) {
|
|
7028
|
+
return profile !== "live";
|
|
7029
|
+
}
|
|
7030
|
+
function shouldIncludeSessionMetadata(profile) {
|
|
7031
|
+
return profile !== "live";
|
|
7032
|
+
}
|
|
7033
|
+
function shouldIncludeRuntimeMetadata(profile) {
|
|
7034
|
+
return profile !== "live";
|
|
7035
|
+
}
|
|
7003
7036
|
function findCdpManager(cdpManagers, key) {
|
|
7004
7037
|
const exact = cdpManagers.get(key);
|
|
7005
7038
|
if (exact) return exact;
|
|
@@ -7107,74 +7140,88 @@ var ACP_SESSION_CAPABILITIES = [
|
|
|
7107
7140
|
"set_mode",
|
|
7108
7141
|
"set_thought_level"
|
|
7109
7142
|
];
|
|
7110
|
-
function buildIdeWorkspaceSession(state, cdpManagers) {
|
|
7111
|
-
const
|
|
7143
|
+
function buildIdeWorkspaceSession(state, cdpManagers, options) {
|
|
7144
|
+
const profile = options.profile || "full";
|
|
7145
|
+
const activeChat = normalizeActiveChatData(state.activeChat, getActiveChatOptions(profile));
|
|
7146
|
+
const includeSessionMetadata = shouldIncludeSessionMetadata(profile);
|
|
7147
|
+
const includeSessionControls = shouldIncludeSessionControls(profile);
|
|
7112
7148
|
const title = activeChat?.title || state.name;
|
|
7113
7149
|
return {
|
|
7114
7150
|
id: state.instanceId || state.type,
|
|
7115
7151
|
parentId: null,
|
|
7116
7152
|
providerType: state.type,
|
|
7117
|
-
providerName: state.name,
|
|
7153
|
+
...includeSessionMetadata && { providerName: state.name },
|
|
7118
7154
|
kind: "workspace",
|
|
7119
7155
|
transport: "cdp-page",
|
|
7120
7156
|
status: normalizeManagedStatus(activeChat?.status || state.status, {
|
|
7121
7157
|
activeModal: activeChat?.activeModal || null
|
|
7122
7158
|
}),
|
|
7123
7159
|
title,
|
|
7124
|
-
workspace: state.workspace || null,
|
|
7160
|
+
...includeSessionMetadata && { workspace: state.workspace || null },
|
|
7125
7161
|
activeChat,
|
|
7126
|
-
capabilities: IDE_SESSION_CAPABILITIES,
|
|
7162
|
+
...includeSessionMetadata && { capabilities: IDE_SESSION_CAPABILITIES },
|
|
7127
7163
|
cdpConnected: state.cdpConnected ?? isCdpConnected(cdpManagers, state.type),
|
|
7128
7164
|
currentModel: state.currentModel,
|
|
7129
7165
|
currentPlan: state.currentPlan,
|
|
7130
7166
|
currentAutoApprove: state.currentAutoApprove,
|
|
7131
|
-
|
|
7132
|
-
|
|
7133
|
-
|
|
7134
|
-
|
|
7135
|
-
|
|
7136
|
-
|
|
7167
|
+
...includeSessionControls && {
|
|
7168
|
+
controlValues: state.controlValues,
|
|
7169
|
+
providerControls: buildFallbackControls(
|
|
7170
|
+
state.providerControls,
|
|
7171
|
+
state.currentModel,
|
|
7172
|
+
state.currentPlan
|
|
7173
|
+
)
|
|
7174
|
+
},
|
|
7137
7175
|
errorMessage: state.errorMessage,
|
|
7138
7176
|
errorReason: state.errorReason,
|
|
7139
7177
|
lastUpdated: state.lastUpdated
|
|
7140
7178
|
};
|
|
7141
7179
|
}
|
|
7142
|
-
function buildExtensionAgentSession(parent, ext) {
|
|
7143
|
-
const
|
|
7180
|
+
function buildExtensionAgentSession(parent, ext, options) {
|
|
7181
|
+
const profile = options.profile || "full";
|
|
7182
|
+
const activeChat = normalizeActiveChatData(ext.activeChat, getActiveChatOptions(profile));
|
|
7183
|
+
const includeSessionMetadata = shouldIncludeSessionMetadata(profile);
|
|
7184
|
+
const includeSessionControls = shouldIncludeSessionControls(profile);
|
|
7144
7185
|
return {
|
|
7145
7186
|
id: ext.instanceId || `${parent.instanceId}:${ext.type}`,
|
|
7146
7187
|
parentId: parent.instanceId || parent.type,
|
|
7147
7188
|
providerType: ext.type,
|
|
7148
|
-
providerName: ext.name,
|
|
7189
|
+
...includeSessionMetadata && { providerName: ext.name },
|
|
7149
7190
|
kind: "agent",
|
|
7150
7191
|
transport: "cdp-webview",
|
|
7151
7192
|
status: normalizeManagedStatus(activeChat?.status || ext.status, {
|
|
7152
7193
|
activeModal: activeChat?.activeModal || null
|
|
7153
7194
|
}),
|
|
7154
7195
|
title: activeChat?.title || ext.name,
|
|
7155
|
-
workspace: parent.workspace || null,
|
|
7196
|
+
...includeSessionMetadata && { workspace: parent.workspace || null },
|
|
7156
7197
|
activeChat,
|
|
7157
|
-
capabilities: EXTENSION_SESSION_CAPABILITIES,
|
|
7198
|
+
...includeSessionMetadata && { capabilities: EXTENSION_SESSION_CAPABILITIES },
|
|
7158
7199
|
currentModel: ext.currentModel,
|
|
7159
7200
|
currentPlan: ext.currentPlan,
|
|
7160
|
-
|
|
7161
|
-
|
|
7162
|
-
|
|
7163
|
-
|
|
7164
|
-
|
|
7165
|
-
|
|
7201
|
+
...includeSessionControls && {
|
|
7202
|
+
controlValues: ext.controlValues,
|
|
7203
|
+
providerControls: buildFallbackControls(
|
|
7204
|
+
ext.providerControls,
|
|
7205
|
+
ext.currentModel,
|
|
7206
|
+
ext.currentPlan
|
|
7207
|
+
)
|
|
7208
|
+
},
|
|
7166
7209
|
errorMessage: ext.errorMessage,
|
|
7167
7210
|
errorReason: ext.errorReason,
|
|
7168
7211
|
lastUpdated: ext.lastUpdated
|
|
7169
7212
|
};
|
|
7170
7213
|
}
|
|
7171
|
-
function buildCliSession(state) {
|
|
7172
|
-
const
|
|
7214
|
+
function buildCliSession(state, options) {
|
|
7215
|
+
const profile = options.profile || "full";
|
|
7216
|
+
const activeChat = normalizeActiveChatData(state.activeChat, getActiveChatOptions(profile));
|
|
7217
|
+
const includeSessionMetadata = shouldIncludeSessionMetadata(profile);
|
|
7218
|
+
const includeRuntimeMetadata = shouldIncludeRuntimeMetadata(profile);
|
|
7219
|
+
const includeSessionControls = shouldIncludeSessionControls(profile);
|
|
7173
7220
|
return {
|
|
7174
7221
|
id: state.instanceId,
|
|
7175
7222
|
parentId: null,
|
|
7176
7223
|
providerType: state.type,
|
|
7177
|
-
providerName: state.name,
|
|
7224
|
+
...includeSessionMetadata && { providerName: state.name },
|
|
7178
7225
|
providerSessionId: state.providerSessionId,
|
|
7179
7226
|
kind: "agent",
|
|
7180
7227
|
transport: "pty",
|
|
@@ -7182,74 +7229,85 @@ function buildCliSession(state) {
|
|
|
7182
7229
|
activeModal: activeChat?.activeModal || null
|
|
7183
7230
|
}),
|
|
7184
7231
|
title: activeChat?.title || state.name,
|
|
7185
|
-
workspace: state.workspace || null,
|
|
7186
|
-
|
|
7187
|
-
|
|
7188
|
-
|
|
7189
|
-
|
|
7190
|
-
|
|
7232
|
+
...includeSessionMetadata && { workspace: state.workspace || null },
|
|
7233
|
+
...includeRuntimeMetadata && {
|
|
7234
|
+
runtimeKey: state.runtime?.runtimeKey,
|
|
7235
|
+
runtimeDisplayName: state.runtime?.displayName,
|
|
7236
|
+
runtimeWorkspaceLabel: state.runtime?.workspaceLabel,
|
|
7237
|
+
runtimeWriteOwner: state.runtime?.writeOwner || null,
|
|
7238
|
+
runtimeAttachedClients: state.runtime?.attachedClients || []
|
|
7239
|
+
},
|
|
7191
7240
|
mode: state.mode,
|
|
7192
7241
|
resume: state.resume,
|
|
7193
7242
|
activeChat,
|
|
7194
|
-
|
|
7195
|
-
|
|
7196
|
-
|
|
7197
|
-
|
|
7198
|
-
|
|
7243
|
+
...includeSessionMetadata && {
|
|
7244
|
+
capabilities: state.mode === "terminal" ? PTY_SESSION_CAPABILITIES : CLI_CHAT_SESSION_CAPABILITIES
|
|
7245
|
+
},
|
|
7246
|
+
...includeSessionControls && {
|
|
7247
|
+
controlValues: state.controlValues,
|
|
7248
|
+
providerControls: buildFallbackControls(
|
|
7249
|
+
state.providerControls
|
|
7250
|
+
)
|
|
7251
|
+
},
|
|
7199
7252
|
errorMessage: state.errorMessage,
|
|
7200
7253
|
errorReason: state.errorReason,
|
|
7201
7254
|
lastUpdated: state.lastUpdated
|
|
7202
7255
|
};
|
|
7203
7256
|
}
|
|
7204
|
-
function buildAcpSession(state) {
|
|
7205
|
-
const
|
|
7257
|
+
function buildAcpSession(state, options) {
|
|
7258
|
+
const profile = options.profile || "full";
|
|
7259
|
+
const activeChat = normalizeActiveChatData(state.activeChat, getActiveChatOptions(profile));
|
|
7260
|
+
const includeSessionMetadata = shouldIncludeSessionMetadata(profile);
|
|
7261
|
+
const includeSessionControls = shouldIncludeSessionControls(profile);
|
|
7206
7262
|
return {
|
|
7207
7263
|
id: state.instanceId,
|
|
7208
7264
|
parentId: null,
|
|
7209
7265
|
providerType: state.type,
|
|
7210
|
-
providerName: state.name,
|
|
7266
|
+
...includeSessionMetadata && { providerName: state.name },
|
|
7211
7267
|
kind: "agent",
|
|
7212
7268
|
transport: "acp",
|
|
7213
7269
|
status: normalizeManagedStatus(activeChat?.status || state.status, {
|
|
7214
7270
|
activeModal: activeChat?.activeModal || null
|
|
7215
7271
|
}),
|
|
7216
7272
|
title: activeChat?.title || state.name,
|
|
7217
|
-
workspace: state.workspace || null,
|
|
7273
|
+
...includeSessionMetadata && { workspace: state.workspace || null },
|
|
7218
7274
|
activeChat,
|
|
7219
|
-
capabilities: ACP_SESSION_CAPABILITIES,
|
|
7275
|
+
...includeSessionMetadata && { capabilities: ACP_SESSION_CAPABILITIES },
|
|
7220
7276
|
currentModel: state.currentModel,
|
|
7221
7277
|
currentPlan: state.currentPlan,
|
|
7222
|
-
|
|
7223
|
-
|
|
7224
|
-
|
|
7225
|
-
|
|
7226
|
-
|
|
7227
|
-
|
|
7228
|
-
|
|
7229
|
-
|
|
7230
|
-
|
|
7231
|
-
|
|
7278
|
+
...includeSessionControls && {
|
|
7279
|
+
acpConfigOptions: state.acpConfigOptions,
|
|
7280
|
+
acpModes: state.acpModes,
|
|
7281
|
+
controlValues: state.controlValues,
|
|
7282
|
+
providerControls: buildFallbackControls(
|
|
7283
|
+
state.providerControls,
|
|
7284
|
+
state.currentModel,
|
|
7285
|
+
state.currentPlan,
|
|
7286
|
+
state.acpConfigOptions,
|
|
7287
|
+
state.acpModes
|
|
7288
|
+
)
|
|
7289
|
+
},
|
|
7232
7290
|
errorMessage: state.errorMessage,
|
|
7233
7291
|
errorReason: state.errorReason,
|
|
7234
7292
|
lastUpdated: state.lastUpdated
|
|
7235
7293
|
};
|
|
7236
7294
|
}
|
|
7237
|
-
function buildSessionEntries(allStates, cdpManagers) {
|
|
7295
|
+
function buildSessionEntries(allStates, cdpManagers, options = {}) {
|
|
7238
7296
|
const sessions = [];
|
|
7239
7297
|
const ideStates = allStates.filter((s) => s.category === "ide");
|
|
7240
7298
|
const cliStates = allStates.filter((s) => s.category === "cli");
|
|
7241
7299
|
const acpStates = allStates.filter((s) => s.category === "acp");
|
|
7242
7300
|
for (const state of ideStates) {
|
|
7243
|
-
sessions.push(buildIdeWorkspaceSession(state, cdpManagers));
|
|
7301
|
+
sessions.push(buildIdeWorkspaceSession(state, cdpManagers, options));
|
|
7244
7302
|
for (const ext of state.extensions) {
|
|
7245
|
-
sessions.push(buildExtensionAgentSession(state, ext));
|
|
7303
|
+
sessions.push(buildExtensionAgentSession(state, ext, options));
|
|
7246
7304
|
}
|
|
7247
7305
|
}
|
|
7248
7306
|
for (const state of cliStates) {
|
|
7249
|
-
sessions.push(buildCliSession(state));
|
|
7307
|
+
sessions.push(buildCliSession(state, options));
|
|
7250
7308
|
}
|
|
7251
7309
|
for (const state of acpStates) {
|
|
7252
|
-
sessions.push(buildAcpSession(state));
|
|
7310
|
+
sessions.push(buildAcpSession(state, options));
|
|
7253
7311
|
}
|
|
7254
7312
|
const extensionParentIds = new Set(
|
|
7255
7313
|
sessions.filter((session) => session.transport === "cdp-webview" && !!session.parentId).map((session) => session.parentId)
|
|
@@ -7310,10 +7368,29 @@ function reconcileIdeRuntimeSessions(instanceManager, sessionRegistry) {
|
|
|
7310
7368
|
// src/commands/handler.ts
|
|
7311
7369
|
init_logger();
|
|
7312
7370
|
|
|
7371
|
+
// src/providers/contracts.ts
|
|
7372
|
+
function flattenContent(content) {
|
|
7373
|
+
if (typeof content === "string") return content;
|
|
7374
|
+
return content.filter((b) => b.type === "text").map((b) => b.text).join("\n");
|
|
7375
|
+
}
|
|
7376
|
+
|
|
7313
7377
|
// src/commands/chat-commands.ts
|
|
7314
7378
|
init_logger();
|
|
7315
7379
|
var RECENT_SEND_WINDOW_MS = 1200;
|
|
7316
7380
|
var recentSendByTarget = /* @__PURE__ */ new Map();
|
|
7381
|
+
function hashSignatureParts(parts) {
|
|
7382
|
+
let hash = 2166136261;
|
|
7383
|
+
for (const part of parts) {
|
|
7384
|
+
const text = String(part || "");
|
|
7385
|
+
for (let i = 0; i < text.length; i += 1) {
|
|
7386
|
+
hash ^= text.charCodeAt(i);
|
|
7387
|
+
hash = Math.imul(hash, 16777619) >>> 0;
|
|
7388
|
+
}
|
|
7389
|
+
hash ^= 255;
|
|
7390
|
+
hash = Math.imul(hash, 16777619) >>> 0;
|
|
7391
|
+
}
|
|
7392
|
+
return hash.toString(16).padStart(8, "0");
|
|
7393
|
+
}
|
|
7317
7394
|
function getCurrentProviderType(h, fallback = "") {
|
|
7318
7395
|
return h.currentSession?.providerType || h.currentProviderType || fallback;
|
|
7319
7396
|
}
|
|
@@ -7387,6 +7464,134 @@ function parseMaybeJson(value) {
|
|
|
7387
7464
|
return value;
|
|
7388
7465
|
}
|
|
7389
7466
|
}
|
|
7467
|
+
function getChatMessageSignature(message) {
|
|
7468
|
+
if (!message) return "";
|
|
7469
|
+
let content = "";
|
|
7470
|
+
try {
|
|
7471
|
+
content = JSON.stringify(message.content ?? "");
|
|
7472
|
+
} catch {
|
|
7473
|
+
content = String(message.content ?? "");
|
|
7474
|
+
}
|
|
7475
|
+
return hashSignatureParts([
|
|
7476
|
+
String(message.id || ""),
|
|
7477
|
+
String(message.index ?? ""),
|
|
7478
|
+
String(message.role || ""),
|
|
7479
|
+
String(message.receivedAt ?? message.timestamp ?? ""),
|
|
7480
|
+
content
|
|
7481
|
+
]);
|
|
7482
|
+
}
|
|
7483
|
+
function normalizeReadChatCursor(args) {
|
|
7484
|
+
const knownMessageCount = Math.max(0, Number(args?.knownMessageCount || 0));
|
|
7485
|
+
const lastMessageSignature = typeof args?.lastMessageSignature === "string" ? args.lastMessageSignature : "";
|
|
7486
|
+
const tailLimit = Math.max(0, Number(args?.tailLimit || 0));
|
|
7487
|
+
return { knownMessageCount, lastMessageSignature, tailLimit };
|
|
7488
|
+
}
|
|
7489
|
+
function normalizeReadChatMessages(payload) {
|
|
7490
|
+
const messages = Array.isArray(payload.messages) ? payload.messages : [];
|
|
7491
|
+
return messages;
|
|
7492
|
+
}
|
|
7493
|
+
function deriveHistoryDedupKey(message) {
|
|
7494
|
+
const unitKey = typeof message._unitKey === "string" ? message._unitKey.trim() : "";
|
|
7495
|
+
if (unitKey) return `read_chat:${unitKey}`;
|
|
7496
|
+
const turnKey = typeof message._turnKey === "string" ? message._turnKey.trim() : "";
|
|
7497
|
+
if (!turnKey) return void 0;
|
|
7498
|
+
let content = "";
|
|
7499
|
+
try {
|
|
7500
|
+
content = JSON.stringify(message.content ?? "");
|
|
7501
|
+
} catch {
|
|
7502
|
+
content = String(message.content ?? "");
|
|
7503
|
+
}
|
|
7504
|
+
return `read_chat:${turnKey}:${String(message.role || "").toLowerCase()}:${content}`;
|
|
7505
|
+
}
|
|
7506
|
+
function toHistoryPersistedMessages(messages) {
|
|
7507
|
+
return messages.map((message) => ({
|
|
7508
|
+
role: message.role,
|
|
7509
|
+
content: flattenContent(message.content),
|
|
7510
|
+
receivedAt: typeof message.receivedAt === "number" ? message.receivedAt : void 0,
|
|
7511
|
+
kind: typeof message.kind === "string" ? message.kind : void 0,
|
|
7512
|
+
senderName: typeof message.senderName === "string" ? message.senderName : void 0,
|
|
7513
|
+
historyDedupKey: deriveHistoryDedupKey(message)
|
|
7514
|
+
}));
|
|
7515
|
+
}
|
|
7516
|
+
function computeReadChatSync(messages, cursor) {
|
|
7517
|
+
const totalMessages = messages.length;
|
|
7518
|
+
const lastMessageSignature = getChatMessageSignature(messages[totalMessages - 1]);
|
|
7519
|
+
const { knownMessageCount, lastMessageSignature: knownSignature } = cursor;
|
|
7520
|
+
if (!knownMessageCount || !knownSignature) {
|
|
7521
|
+
return {
|
|
7522
|
+
syncMode: "full",
|
|
7523
|
+
replaceFrom: 0,
|
|
7524
|
+
messages,
|
|
7525
|
+
totalMessages,
|
|
7526
|
+
lastMessageSignature
|
|
7527
|
+
};
|
|
7528
|
+
}
|
|
7529
|
+
if (knownMessageCount > totalMessages) {
|
|
7530
|
+
return {
|
|
7531
|
+
syncMode: "full",
|
|
7532
|
+
replaceFrom: 0,
|
|
7533
|
+
messages,
|
|
7534
|
+
totalMessages,
|
|
7535
|
+
lastMessageSignature
|
|
7536
|
+
};
|
|
7537
|
+
}
|
|
7538
|
+
if (knownMessageCount === totalMessages && knownSignature === lastMessageSignature) {
|
|
7539
|
+
return {
|
|
7540
|
+
syncMode: "noop",
|
|
7541
|
+
replaceFrom: totalMessages,
|
|
7542
|
+
messages: [],
|
|
7543
|
+
totalMessages,
|
|
7544
|
+
lastMessageSignature
|
|
7545
|
+
};
|
|
7546
|
+
}
|
|
7547
|
+
if (knownMessageCount < totalMessages) {
|
|
7548
|
+
const anchorSignature = getChatMessageSignature(messages[knownMessageCount - 1]);
|
|
7549
|
+
if (anchorSignature === knownSignature) {
|
|
7550
|
+
return {
|
|
7551
|
+
syncMode: "append",
|
|
7552
|
+
replaceFrom: knownMessageCount,
|
|
7553
|
+
messages: messages.slice(knownMessageCount),
|
|
7554
|
+
totalMessages,
|
|
7555
|
+
lastMessageSignature
|
|
7556
|
+
};
|
|
7557
|
+
}
|
|
7558
|
+
}
|
|
7559
|
+
const replaceFrom = Math.max(0, Math.min(knownMessageCount - 1, totalMessages));
|
|
7560
|
+
return {
|
|
7561
|
+
syncMode: replaceFrom === 0 ? "full" : "replace_tail",
|
|
7562
|
+
replaceFrom,
|
|
7563
|
+
messages: replaceFrom === 0 ? messages : messages.slice(replaceFrom),
|
|
7564
|
+
totalMessages,
|
|
7565
|
+
lastMessageSignature
|
|
7566
|
+
};
|
|
7567
|
+
}
|
|
7568
|
+
function buildReadChatCommandResult(payload, args) {
|
|
7569
|
+
const messages = normalizeReadChatMessages(payload);
|
|
7570
|
+
const cursor = normalizeReadChatCursor(args);
|
|
7571
|
+
if (!cursor.knownMessageCount && !cursor.lastMessageSignature && cursor.tailLimit > 0 && messages.length > cursor.tailLimit) {
|
|
7572
|
+
const tailMessages = messages.slice(-cursor.tailLimit);
|
|
7573
|
+
const lastMessageSignature = getChatMessageSignature(tailMessages[tailMessages.length - 1]);
|
|
7574
|
+
return {
|
|
7575
|
+
success: true,
|
|
7576
|
+
...payload,
|
|
7577
|
+
messages: tailMessages,
|
|
7578
|
+
syncMode: "full",
|
|
7579
|
+
replaceFrom: 0,
|
|
7580
|
+
totalMessages: messages.length,
|
|
7581
|
+
lastMessageSignature
|
|
7582
|
+
};
|
|
7583
|
+
}
|
|
7584
|
+
const sync = computeReadChatSync(messages, cursor);
|
|
7585
|
+
return {
|
|
7586
|
+
success: true,
|
|
7587
|
+
...payload,
|
|
7588
|
+
messages: sync.messages,
|
|
7589
|
+
syncMode: sync.syncMode,
|
|
7590
|
+
replaceFrom: sync.replaceFrom,
|
|
7591
|
+
totalMessages: sync.totalMessages,
|
|
7592
|
+
lastMessageSignature: sync.lastMessageSignature
|
|
7593
|
+
};
|
|
7594
|
+
}
|
|
7390
7595
|
function didProviderConfirmSend(result) {
|
|
7391
7596
|
const parsed = parseMaybeJson(result);
|
|
7392
7597
|
if (parsed === true) return true;
|
|
@@ -7460,12 +7665,11 @@ async function handleReadChat(h, args) {
|
|
|
7460
7665
|
_log(`${transport} adapter: ${adapter.cliType}`);
|
|
7461
7666
|
const status = adapter.getStatus();
|
|
7462
7667
|
if (status) {
|
|
7463
|
-
return {
|
|
7464
|
-
success: true,
|
|
7668
|
+
return buildReadChatCommandResult({
|
|
7465
7669
|
messages: status.messages || [],
|
|
7466
7670
|
status: status.status,
|
|
7467
7671
|
activeModal: status.activeModal
|
|
7468
|
-
};
|
|
7672
|
+
}, args);
|
|
7469
7673
|
}
|
|
7470
7674
|
}
|
|
7471
7675
|
return { success: false, error: `${transport} adapter not found` };
|
|
@@ -7485,12 +7689,12 @@ async function handleReadChat(h, args) {
|
|
|
7485
7689
|
_log(`Extension OK: ${parsed.messages?.length || 0} msgs`);
|
|
7486
7690
|
h.historyWriter.appendNewMessages(
|
|
7487
7691
|
provider?.type || "unknown_extension",
|
|
7488
|
-
parsed
|
|
7692
|
+
toHistoryPersistedMessages(normalizeReadChatMessages(parsed)),
|
|
7489
7693
|
parsed.title,
|
|
7490
7694
|
args?.targetSessionId,
|
|
7491
7695
|
historySessionId
|
|
7492
7696
|
);
|
|
7493
|
-
return
|
|
7697
|
+
return buildReadChatCommandResult(parsed, args);
|
|
7494
7698
|
}
|
|
7495
7699
|
}
|
|
7496
7700
|
} catch (e) {
|
|
@@ -7502,21 +7706,25 @@ async function handleReadChat(h, args) {
|
|
|
7502
7706
|
if (cdp2 && parentSessionId) {
|
|
7503
7707
|
const stream = await h.agentStream.collectActiveSession(cdp2, parentSessionId);
|
|
7504
7708
|
if (stream?.agentType !== provider?.type) {
|
|
7505
|
-
return {
|
|
7709
|
+
return buildReadChatCommandResult({ messages: [], status: "idle" }, args);
|
|
7506
7710
|
}
|
|
7507
7711
|
if (stream) {
|
|
7508
7712
|
h.historyWriter.appendNewMessages(
|
|
7509
7713
|
stream.agentType,
|
|
7510
|
-
stream.messages || [],
|
|
7714
|
+
toHistoryPersistedMessages(stream.messages || []),
|
|
7511
7715
|
void 0,
|
|
7512
7716
|
args?.targetSessionId,
|
|
7513
7717
|
historySessionId
|
|
7514
7718
|
);
|
|
7515
|
-
return {
|
|
7719
|
+
return buildReadChatCommandResult({
|
|
7720
|
+
messages: stream.messages || [],
|
|
7721
|
+
status: stream.status,
|
|
7722
|
+
agentType: stream.agentType
|
|
7723
|
+
}, args);
|
|
7516
7724
|
}
|
|
7517
7725
|
}
|
|
7518
7726
|
}
|
|
7519
|
-
return {
|
|
7727
|
+
return buildReadChatCommandResult({ messages: [], status: "idle" }, args);
|
|
7520
7728
|
}
|
|
7521
7729
|
const cdp = h.getCdp();
|
|
7522
7730
|
if (!cdp?.isConnected) return { success: false, error: "CDP not connected" };
|
|
@@ -7538,18 +7746,18 @@ async function handleReadChat(h, args) {
|
|
|
7538
7746
|
_log(`Webview OK: ${parsed.messages?.length || 0} msgs`);
|
|
7539
7747
|
h.historyWriter.appendNewMessages(
|
|
7540
7748
|
provider?.type || getCurrentProviderType(h, "unknown_webview"),
|
|
7541
|
-
parsed
|
|
7749
|
+
toHistoryPersistedMessages(normalizeReadChatMessages(parsed)),
|
|
7542
7750
|
parsed.title,
|
|
7543
7751
|
args?.targetSessionId,
|
|
7544
7752
|
historySessionId
|
|
7545
7753
|
);
|
|
7546
|
-
return
|
|
7754
|
+
return buildReadChatCommandResult(parsed, args);
|
|
7547
7755
|
}
|
|
7548
7756
|
}
|
|
7549
7757
|
} catch (e) {
|
|
7550
7758
|
_log(`Webview readChat error: ${e.message}`);
|
|
7551
7759
|
}
|
|
7552
|
-
return {
|
|
7760
|
+
return buildReadChatCommandResult({ messages: [], status: "idle" }, args);
|
|
7553
7761
|
}
|
|
7554
7762
|
const script = h.getProviderScript("readChat") || h.getProviderScript("read_chat");
|
|
7555
7763
|
if (script) {
|
|
@@ -7566,18 +7774,18 @@ async function handleReadChat(h, args) {
|
|
|
7566
7774
|
_log(`OK: ${parsed.messages?.length} msgs`);
|
|
7567
7775
|
h.historyWriter.appendNewMessages(
|
|
7568
7776
|
provider?.type || getCurrentProviderType(h, "unknown_ide"),
|
|
7569
|
-
parsed
|
|
7777
|
+
toHistoryPersistedMessages(normalizeReadChatMessages(parsed)),
|
|
7570
7778
|
parsed.title,
|
|
7571
7779
|
args?.targetSessionId,
|
|
7572
7780
|
historySessionId
|
|
7573
7781
|
);
|
|
7574
|
-
return
|
|
7782
|
+
return buildReadChatCommandResult(parsed, args);
|
|
7575
7783
|
}
|
|
7576
7784
|
} catch (e) {
|
|
7577
7785
|
LOG.info("Command", `[read_chat] Script error: ${e.message}`);
|
|
7578
7786
|
}
|
|
7579
7787
|
}
|
|
7580
|
-
return {
|
|
7788
|
+
return buildReadChatCommandResult({ messages: [], status: "idle" }, args);
|
|
7581
7789
|
}
|
|
7582
7790
|
async function handleSendChat(h, args) {
|
|
7583
7791
|
const text = args?.text || args?.message;
|
|
@@ -8698,21 +8906,21 @@ function applyProviderPatch(h, args, payload) {
|
|
|
8698
8906
|
});
|
|
8699
8907
|
}
|
|
8700
8908
|
async function executeProviderScript(h, args, scriptName) {
|
|
8701
|
-
const
|
|
8702
|
-
if (!
|
|
8909
|
+
const resolvedProviderType = h.currentSession?.providerType || h.currentProviderType || args?.agentType || args?.providerType;
|
|
8910
|
+
if (!resolvedProviderType) return { success: false, error: "targetSessionId or providerType is required" };
|
|
8703
8911
|
const loader = h.ctx.providerLoader;
|
|
8704
8912
|
if (!loader) return { success: false, error: "ProviderLoader not initialized" };
|
|
8705
|
-
const provider = loader.resolve(
|
|
8706
|
-
if (!provider) return { success: false, error: `Provider not found: ${
|
|
8913
|
+
const provider = loader.resolve(resolvedProviderType);
|
|
8914
|
+
if (!provider) return { success: false, error: `Provider not found: ${resolvedProviderType}` };
|
|
8707
8915
|
const webviewScriptName = `webview${scriptName.charAt(0).toUpperCase() + scriptName.slice(1)}`;
|
|
8708
8916
|
const hasWebviewScript = provider.category === "ide" && !!provider.scripts?.[webviewScriptName];
|
|
8709
8917
|
const actualScriptName = hasWebviewScript ? webviewScriptName : scriptName;
|
|
8710
8918
|
if (!provider.scripts?.[actualScriptName]) {
|
|
8711
|
-
return { success: false, error: `Script '${actualScriptName}' not available for ${
|
|
8919
|
+
return { success: false, error: `Script '${actualScriptName}' not available for ${resolvedProviderType}` };
|
|
8712
8920
|
}
|
|
8713
8921
|
const normalizedArgs = normalizeProviderScriptArgs(args);
|
|
8714
8922
|
if (provider.category === "cli") {
|
|
8715
|
-
const adapter = h.getCliAdapter(args?.targetSessionId ||
|
|
8923
|
+
const adapter = h.getCliAdapter(args?.targetSessionId || resolvedProviderType);
|
|
8716
8924
|
if (!adapter?.invokeScript) {
|
|
8717
8925
|
return { success: false, error: `CLI adapter does not support script '${actualScriptName}'` };
|
|
8718
8926
|
}
|
|
@@ -8737,7 +8945,7 @@ async function executeProviderScript(h, args, scriptName) {
|
|
|
8737
8945
|
const scriptFn = provider.scripts[actualScriptName];
|
|
8738
8946
|
const scriptCode = scriptFn(normalizedArgs);
|
|
8739
8947
|
if (!scriptCode) return { success: false, error: `Script '${actualScriptName}' returned null` };
|
|
8740
|
-
const cdpKey = provider.category === "ide" ? h.currentSession?.cdpManagerKey || h.currentManagerKey ||
|
|
8948
|
+
const cdpKey = provider.category === "ide" ? h.currentSession?.cdpManagerKey || h.currentManagerKey || resolvedProviderType : h.currentSession?.cdpManagerKey || h.currentManagerKey;
|
|
8741
8949
|
LOG.info("Command", `[ExtScript] provider=${provider.type} category=${provider.category} cdpKey=${cdpKey}`);
|
|
8742
8950
|
const cdp = h.getCdp(cdpKey);
|
|
8743
8951
|
if (!cdp?.isConnected) return { success: false, error: `No CDP connection for ${cdpKey || "any"}` };
|
|
@@ -8745,7 +8953,7 @@ async function executeProviderScript(h, args, scriptName) {
|
|
|
8745
8953
|
let result;
|
|
8746
8954
|
if (provider.category === "extension") {
|
|
8747
8955
|
const runtimeSessionId = h.currentSession?.sessionId || args?.targetSessionId;
|
|
8748
|
-
if (!runtimeSessionId) return { success: false, error: `No target session found for ${
|
|
8956
|
+
if (!runtimeSessionId) return { success: false, error: `No target session found for ${resolvedProviderType}` };
|
|
8749
8957
|
const parentSessionId = h.currentSession?.parentSessionId;
|
|
8750
8958
|
if (parentSessionId) {
|
|
8751
8959
|
await h.agentStream?.setActiveSession(cdp, parentSessionId, runtimeSessionId);
|
|
@@ -8774,7 +8982,7 @@ async function executeProviderScript(h, args, scriptName) {
|
|
|
8774
8982
|
}
|
|
8775
8983
|
} else {
|
|
8776
8984
|
if (!targetSessionId) {
|
|
8777
|
-
return { success: false, error: `No active session found for ${
|
|
8985
|
+
return { success: false, error: `No active session found for ${resolvedProviderType}` };
|
|
8778
8986
|
}
|
|
8779
8987
|
result = await cdp.evaluateInSessionFrame(targetSessionId, scriptCode);
|
|
8780
8988
|
}
|
|
@@ -10162,14 +10370,6 @@ import {
|
|
|
10162
10370
|
RequestError,
|
|
10163
10371
|
PROTOCOL_VERSION
|
|
10164
10372
|
} from "@agentclientprotocol/sdk";
|
|
10165
|
-
|
|
10166
|
-
// src/providers/contracts.ts
|
|
10167
|
-
function flattenContent(content) {
|
|
10168
|
-
if (typeof content === "string") return content;
|
|
10169
|
-
return content.filter((b) => b.type === "text").map((b) => b.text).join("\n");
|
|
10170
|
-
}
|
|
10171
|
-
|
|
10172
|
-
// src/providers/acp-provider-instance.ts
|
|
10173
10373
|
init_logger();
|
|
10174
10374
|
var AcpProviderInstance = class {
|
|
10175
10375
|
constructor(provider, workingDir, cliArgs = []) {
|
|
@@ -13535,6 +13735,37 @@ function buildAvailableProviders(providerLoader) {
|
|
|
13535
13735
|
...provider.detectedPath !== void 0 ? { detectedPath: provider.detectedPath } : {}
|
|
13536
13736
|
}));
|
|
13537
13737
|
}
|
|
13738
|
+
function buildMachineInfo(profile = "full") {
|
|
13739
|
+
const base = {
|
|
13740
|
+
hostname: os16.hostname(),
|
|
13741
|
+
platform: os16.platform()
|
|
13742
|
+
};
|
|
13743
|
+
if (profile === "live") {
|
|
13744
|
+
return base;
|
|
13745
|
+
}
|
|
13746
|
+
if (profile === "metadata") {
|
|
13747
|
+
const memSnap2 = getHostMemorySnapshot();
|
|
13748
|
+
return {
|
|
13749
|
+
...base,
|
|
13750
|
+
arch: os16.arch(),
|
|
13751
|
+
cpus: os16.cpus().length,
|
|
13752
|
+
totalMem: memSnap2.totalMem,
|
|
13753
|
+
release: os16.release()
|
|
13754
|
+
};
|
|
13755
|
+
}
|
|
13756
|
+
const memSnap = getHostMemorySnapshot();
|
|
13757
|
+
return {
|
|
13758
|
+
...base,
|
|
13759
|
+
arch: os16.arch(),
|
|
13760
|
+
cpus: os16.cpus().length,
|
|
13761
|
+
totalMem: memSnap.totalMem,
|
|
13762
|
+
freeMem: memSnap.freeMem,
|
|
13763
|
+
availableMem: memSnap.availableMem,
|
|
13764
|
+
loadavg: os16.loadavg(),
|
|
13765
|
+
uptime: os16.uptime(),
|
|
13766
|
+
release: os16.release()
|
|
13767
|
+
};
|
|
13768
|
+
}
|
|
13538
13769
|
function parseMessageTime(value) {
|
|
13539
13770
|
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
13540
13771
|
if (typeof value === "string") {
|
|
@@ -13590,26 +13821,35 @@ function buildRecentLaunches(recentActivity) {
|
|
|
13590
13821
|
})).sort((a, b) => b.lastLaunchedAt - a.lastLaunchedAt).slice(0, 12);
|
|
13591
13822
|
}
|
|
13592
13823
|
function buildStatusSnapshot(options) {
|
|
13824
|
+
const profile = options.profile || "full";
|
|
13593
13825
|
const cfg = loadConfig();
|
|
13594
13826
|
const state = loadState();
|
|
13595
13827
|
const wsState = getWorkspaceState(cfg);
|
|
13596
|
-
const memSnap = getHostMemorySnapshot();
|
|
13597
13828
|
const recentActivity = getRecentActivity(state, 20);
|
|
13598
|
-
const
|
|
13829
|
+
const unreadSourceSessions = buildSessionEntries(
|
|
13599
13830
|
options.allStates,
|
|
13600
|
-
options.cdpManagers
|
|
13831
|
+
options.cdpManagers,
|
|
13832
|
+
{ profile: "full" }
|
|
13601
13833
|
);
|
|
13602
|
-
|
|
13603
|
-
|
|
13604
|
-
|
|
13605
|
-
|
|
13606
|
-
|
|
13607
|
-
|
|
13608
|
-
|
|
13609
|
-
|
|
13834
|
+
const sessions = profile === "full" ? unreadSourceSessions : buildSessionEntries(
|
|
13835
|
+
options.allStates,
|
|
13836
|
+
options.cdpManagers,
|
|
13837
|
+
{ profile }
|
|
13838
|
+
);
|
|
13839
|
+
const sessionsById = new Map(sessions.map((session) => [session.id, session]));
|
|
13840
|
+
for (const sourceSession of unreadSourceSessions) {
|
|
13841
|
+
const session = sessionsById.get(sourceSession.id);
|
|
13842
|
+
if (!session) continue;
|
|
13843
|
+
const lastSeenAt = getSessionSeenAt(state, sourceSession.id);
|
|
13844
|
+
const seenCompletionMarker = getSessionSeenMarker(state, sourceSession.id);
|
|
13845
|
+
const lastUsedAt = getSessionLastUsedAt(sourceSession);
|
|
13846
|
+
const completionMarker = getSessionCompletionMarker(sourceSession);
|
|
13847
|
+
const { unread, inboxBucket } = sourceSession.surfaceHidden ? { unread: false, inboxBucket: "idle" } : getUnreadState(
|
|
13848
|
+
getSessionMessageUpdatedAt(sourceSession) > 0,
|
|
13849
|
+
sourceSession.status,
|
|
13610
13850
|
lastUsedAt,
|
|
13611
13851
|
lastSeenAt,
|
|
13612
|
-
getLastMessageRole(
|
|
13852
|
+
getLastMessageRole(sourceSession),
|
|
13613
13853
|
completionMarker,
|
|
13614
13854
|
seenCompletionMarker
|
|
13615
13855
|
);
|
|
@@ -13619,39 +13859,30 @@ function buildStatusSnapshot(options) {
|
|
|
13619
13859
|
if (READ_DEBUG_ENABLED && (session.unread || session.inboxBucket !== "idle" || session.providerType.includes("codex"))) {
|
|
13620
13860
|
LOG.info(
|
|
13621
13861
|
"RecentRead",
|
|
13622
|
-
`snapshot session id=${session.id} provider=${session.providerType} status=${String(session.status || "")} bucket=${inboxBucket} unread=${String(unread)} lastSeenAt=${lastSeenAt} completionMarker=${completionMarker || "-"} seenMarker=${seenCompletionMarker || "-"} lastUpdated=${String(session.lastUpdated || 0)} lastUsedAt=${lastUsedAt} lastRole=${getLastMessageRole(
|
|
13862
|
+
`snapshot session id=${session.id} provider=${session.providerType} status=${String(session.status || "")} bucket=${inboxBucket} unread=${String(unread)} lastSeenAt=${lastSeenAt} completionMarker=${completionMarker || "-"} seenMarker=${seenCompletionMarker || "-"} lastUpdated=${String(session.lastUpdated || 0)} lastUsedAt=${lastUsedAt} lastRole=${getLastMessageRole(sourceSession)} msgUpdatedAt=${getSessionMessageUpdatedAt(sourceSession)}`
|
|
13623
13863
|
);
|
|
13624
13864
|
}
|
|
13625
13865
|
}
|
|
13626
|
-
const
|
|
13866
|
+
const includeMachineMetadata = profile !== "live";
|
|
13867
|
+
const terminalBackend = includeMachineMetadata ? getTerminalBackendRuntimeStatus() : void 0;
|
|
13627
13868
|
return {
|
|
13628
13869
|
instanceId: options.instanceId,
|
|
13629
|
-
version: options.version,
|
|
13630
|
-
|
|
13631
|
-
|
|
13632
|
-
hostname: os16.hostname(),
|
|
13633
|
-
platform: os16.platform(),
|
|
13634
|
-
arch: os16.arch(),
|
|
13635
|
-
cpus: os16.cpus().length,
|
|
13636
|
-
totalMem: memSnap.totalMem,
|
|
13637
|
-
freeMem: memSnap.freeMem,
|
|
13638
|
-
availableMem: memSnap.availableMem,
|
|
13639
|
-
loadavg: os16.loadavg(),
|
|
13640
|
-
uptime: os16.uptime(),
|
|
13641
|
-
release: os16.release()
|
|
13642
|
-
},
|
|
13643
|
-
machineNickname: options.machineNickname ?? cfg.machineNickname ?? null,
|
|
13870
|
+
...includeMachineMetadata ? { version: options.version } : {},
|
|
13871
|
+
machine: buildMachineInfo(profile),
|
|
13872
|
+
...includeMachineMetadata ? { machineNickname: options.machineNickname ?? cfg.machineNickname ?? null } : {},
|
|
13644
13873
|
timestamp: options.timestamp ?? Date.now(),
|
|
13645
|
-
detectedIdes: buildDetectedIdeInfos(options.detectedIdes, options.cdpManagers),
|
|
13646
13874
|
...options.p2p ? { p2p: options.p2p } : {},
|
|
13647
13875
|
sessions,
|
|
13648
|
-
|
|
13649
|
-
|
|
13650
|
-
|
|
13651
|
-
|
|
13652
|
-
|
|
13653
|
-
|
|
13654
|
-
|
|
13876
|
+
...terminalBackend ? { terminalBackend } : {},
|
|
13877
|
+
...includeMachineMetadata && {
|
|
13878
|
+
detectedIdes: buildDetectedIdeInfos(options.detectedIdes, options.cdpManagers),
|
|
13879
|
+
workspaces: wsState.workspaces,
|
|
13880
|
+
defaultWorkspaceId: wsState.defaultWorkspaceId,
|
|
13881
|
+
defaultWorkspacePath: wsState.defaultWorkspacePath,
|
|
13882
|
+
terminalSizingMode: cfg.terminalSizingMode || "measured",
|
|
13883
|
+
recentLaunches: buildRecentLaunches(recentActivity),
|
|
13884
|
+
availableProviders: buildAvailableProviders(options.providerLoader)
|
|
13885
|
+
}
|
|
13655
13886
|
};
|
|
13656
13887
|
}
|
|
13657
13888
|
|
|
@@ -14207,6 +14438,25 @@ var DaemonCommandRouter = class {
|
|
|
14207
14438
|
updateConfig({ userName: name });
|
|
14208
14439
|
return { success: true, userName: name };
|
|
14209
14440
|
}
|
|
14441
|
+
case "get_status_metadata": {
|
|
14442
|
+
const snapshot = buildStatusSnapshot({
|
|
14443
|
+
allStates: this.deps.instanceManager.collectAllStates(),
|
|
14444
|
+
cdpManagers: this.deps.cdpManagers,
|
|
14445
|
+
providerLoader: this.deps.providerLoader,
|
|
14446
|
+
detectedIdes: this.deps.detectedIdes.value,
|
|
14447
|
+
instanceId: this.deps.statusInstanceId || loadConfig().machineId || "daemon",
|
|
14448
|
+
version: this.deps.statusVersion || "unknown",
|
|
14449
|
+
profile: "metadata"
|
|
14450
|
+
});
|
|
14451
|
+
return { success: true, status: snapshot };
|
|
14452
|
+
}
|
|
14453
|
+
case "get_machine_runtime_stats": {
|
|
14454
|
+
return {
|
|
14455
|
+
success: true,
|
|
14456
|
+
machine: buildMachineInfo("full"),
|
|
14457
|
+
timestamp: Date.now()
|
|
14458
|
+
};
|
|
14459
|
+
}
|
|
14210
14460
|
case "mark_session_seen": {
|
|
14211
14461
|
const sessionId = args?.sessionId;
|
|
14212
14462
|
if (!sessionId || typeof sessionId !== "string") {
|
|
@@ -14412,9 +14662,58 @@ var DaemonStatusReporter = class {
|
|
|
14412
14662
|
}, 5e3 - elapsed);
|
|
14413
14663
|
}
|
|
14414
14664
|
}
|
|
14665
|
+
toDaemonStatusEventName(value) {
|
|
14666
|
+
switch (value) {
|
|
14667
|
+
case "agent:generating_started":
|
|
14668
|
+
case "agent:waiting_approval":
|
|
14669
|
+
case "agent:generating_completed":
|
|
14670
|
+
case "agent:stopped":
|
|
14671
|
+
case "monitor:long_generating":
|
|
14672
|
+
return value;
|
|
14673
|
+
default:
|
|
14674
|
+
return null;
|
|
14675
|
+
}
|
|
14676
|
+
}
|
|
14677
|
+
buildServerStatusEvent(event) {
|
|
14678
|
+
const eventName = this.toDaemonStatusEventName(event.event);
|
|
14679
|
+
if (!eventName) return null;
|
|
14680
|
+
if (eventName.startsWith("provider:")) {
|
|
14681
|
+
return null;
|
|
14682
|
+
}
|
|
14683
|
+
const payload = {
|
|
14684
|
+
event: eventName,
|
|
14685
|
+
timestamp: typeof event.timestamp === "number" && Number.isFinite(event.timestamp) ? event.timestamp : Date.now()
|
|
14686
|
+
};
|
|
14687
|
+
if (typeof event.targetSessionId === "string" && event.targetSessionId.trim()) {
|
|
14688
|
+
payload.targetSessionId = event.targetSessionId.trim();
|
|
14689
|
+
}
|
|
14690
|
+
const providerType = typeof event.providerType === "string" && event.providerType.trim() ? event.providerType.trim() : typeof event.ideType === "string" && event.ideType.trim() ? event.ideType.trim() : "";
|
|
14691
|
+
if (providerType) {
|
|
14692
|
+
payload.providerType = providerType;
|
|
14693
|
+
}
|
|
14694
|
+
if (typeof event.duration === "number" && Number.isFinite(event.duration)) {
|
|
14695
|
+
payload.duration = event.duration;
|
|
14696
|
+
}
|
|
14697
|
+
if (typeof event.elapsedSec === "number" && Number.isFinite(event.elapsedSec)) {
|
|
14698
|
+
payload.elapsedSec = event.elapsedSec;
|
|
14699
|
+
}
|
|
14700
|
+
if (typeof event.modalMessage === "string" && event.modalMessage.trim()) {
|
|
14701
|
+
payload.modalMessage = event.modalMessage;
|
|
14702
|
+
}
|
|
14703
|
+
if (Array.isArray(event.modalButtons)) {
|
|
14704
|
+
const modalButtons = event.modalButtons.filter((button) => typeof button === "string" && button.trim().length > 0);
|
|
14705
|
+
if (modalButtons.length > 0) {
|
|
14706
|
+
payload.modalButtons = modalButtons;
|
|
14707
|
+
}
|
|
14708
|
+
}
|
|
14709
|
+
return payload;
|
|
14710
|
+
}
|
|
14415
14711
|
emitStatusEvent(event) {
|
|
14416
14712
|
LOG.info("StatusEvent", `${event.event} (${event.providerType || event.ideType || ""})`);
|
|
14417
|
-
this.
|
|
14713
|
+
const serverEvent = this.buildServerStatusEvent(event);
|
|
14714
|
+
if (!serverEvent) return;
|
|
14715
|
+
this.deps.p2p?.sendStatusEvent(serverEvent);
|
|
14716
|
+
this.deps.serverConn?.sendMessage("status_event", serverEvent);
|
|
14418
14717
|
}
|
|
14419
14718
|
removeAgentTracking(_key) {
|
|
14420
14719
|
}
|
|
@@ -14483,17 +14782,16 @@ var DaemonStatusReporter = class {
|
|
|
14483
14782
|
detectedIdes: this.deps.detectedIdes || [],
|
|
14484
14783
|
instanceId: this.deps.instanceId,
|
|
14485
14784
|
version: this.deps.daemonVersion || "unknown",
|
|
14486
|
-
daemonMode: true,
|
|
14487
14785
|
timestamp: now,
|
|
14488
14786
|
p2p: {
|
|
14489
14787
|
available: p2p?.isAvailable || false,
|
|
14490
14788
|
state: p2p?.connectionState || "unavailable",
|
|
14491
14789
|
peers: p2p?.connectedPeerCount || 0,
|
|
14492
14790
|
screenshotActive: p2p?.screenshotActive || false
|
|
14493
|
-
}
|
|
14791
|
+
},
|
|
14792
|
+
profile: "live"
|
|
14494
14793
|
}),
|
|
14495
|
-
screenshotUsage: this.deps.getScreenshotUsage?.() || null
|
|
14496
|
-
connectedExtensions: []
|
|
14794
|
+
screenshotUsage: this.deps.getScreenshotUsage?.() || null
|
|
14497
14795
|
};
|
|
14498
14796
|
const payloadBytes = JSON.stringify(payload).length;
|
|
14499
14797
|
const p2pSent = this.sendP2PPayload(payload);
|
|
@@ -14508,16 +14806,15 @@ var DaemonStatusReporter = class {
|
|
|
14508
14806
|
}
|
|
14509
14807
|
if (opts?.p2pOnly) return;
|
|
14510
14808
|
const wsPayload = {
|
|
14511
|
-
daemonMode: true,
|
|
14512
14809
|
sessions: sessions.map((session) => ({
|
|
14513
14810
|
id: session.id,
|
|
14514
14811
|
parentId: session.parentId,
|
|
14515
14812
|
providerType: session.providerType,
|
|
14516
|
-
providerName: session.providerName,
|
|
14813
|
+
providerName: session.providerName || session.providerType,
|
|
14517
14814
|
kind: session.kind,
|
|
14518
14815
|
transport: session.transport,
|
|
14519
14816
|
status: session.status,
|
|
14520
|
-
workspace: session.workspace,
|
|
14817
|
+
workspace: session.workspace ?? null,
|
|
14521
14818
|
title: session.title,
|
|
14522
14819
|
cdpConnected: session.cdpConnected,
|
|
14523
14820
|
currentModel: session.currentModel,
|
|
@@ -14525,9 +14822,7 @@ var DaemonStatusReporter = class {
|
|
|
14525
14822
|
currentAutoApprove: session.currentAutoApprove
|
|
14526
14823
|
})),
|
|
14527
14824
|
p2p: payload.p2p,
|
|
14528
|
-
timestamp: now
|
|
14529
|
-
detectedIdes: payload.detectedIdes,
|
|
14530
|
-
availableProviders: payload.availableProviders
|
|
14825
|
+
timestamp: now
|
|
14531
14826
|
};
|
|
14532
14827
|
const wsHash = this.simpleHash(JSON.stringify({
|
|
14533
14828
|
...wsPayload,
|
|
@@ -14544,10 +14839,15 @@ var DaemonStatusReporter = class {
|
|
|
14544
14839
|
// ─── P2P ─────────────────────────────────────────
|
|
14545
14840
|
sendP2PPayload(payload) {
|
|
14546
14841
|
const { timestamp: _ts, system: _sys, ...hashTarget } = payload;
|
|
14842
|
+
const sessions = Array.isArray(hashTarget.sessions) ? hashTarget.sessions.map((session) => {
|
|
14843
|
+
if (!session || typeof session !== "object") return session;
|
|
14844
|
+
const { lastUpdated: _lu, ...stableSession } = session;
|
|
14845
|
+
return stableSession;
|
|
14846
|
+
}) : hashTarget.sessions;
|
|
14547
14847
|
const hashPayload = hashTarget.machine ? (() => {
|
|
14548
14848
|
const { freeMem: _f, availableMem: _a, loadavg: _l, uptime: _u, ...stableMachine } = hashTarget.machine;
|
|
14549
|
-
return { ...hashTarget, machine: stableMachine };
|
|
14550
|
-
})() : hashTarget;
|
|
14849
|
+
return { ...hashTarget, sessions, machine: stableMachine };
|
|
14850
|
+
})() : { ...hashTarget, sessions };
|
|
14551
14851
|
const h = this.simpleHash(JSON.stringify(hashPayload));
|
|
14552
14852
|
if (h !== this.lastP2PStatusHash) {
|
|
14553
14853
|
this.lastP2PStatusHash = h;
|
|
@@ -21650,6 +21950,8 @@ async function initDaemonComponents(config) {
|
|
|
21650
21950
|
onStatusChange: config.onStatusChange,
|
|
21651
21951
|
onPostChatCommand: config.onPostChatCommand,
|
|
21652
21952
|
sessionHostControl: config.sessionHostControl,
|
|
21953
|
+
statusInstanceId: config.statusInstanceId,
|
|
21954
|
+
statusVersion: config.statusVersion,
|
|
21653
21955
|
getCdpLogFn: config.getCdpLogFn || ((ideType) => LOG.forComponent(`CDP:${ideType}`).asLogFn())
|
|
21654
21956
|
});
|
|
21655
21957
|
poller = new AgentStreamPoller({
|
|
@@ -21751,6 +22053,7 @@ export {
|
|
|
21751
22053
|
SessionHostPtyTransportFactory,
|
|
21752
22054
|
VersionArchive,
|
|
21753
22055
|
appendRecentActivity,
|
|
22056
|
+
buildMachineInfo,
|
|
21754
22057
|
buildSessionEntries,
|
|
21755
22058
|
buildStatusSnapshot,
|
|
21756
22059
|
connectCdpManager,
|