@adhdev/daemon-core 0.8.73 → 0.8.75
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/cli-adapters/provider-cli-shared.d.ts +2 -0
- package/dist/commands/stream-commands.d.ts +1 -1
- package/dist/config/chat-history.d.ts +5 -4
- package/dist/index.js +239 -111
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +239 -111
- package/dist/index.mjs.map +1 -1
- package/dist/providers/contracts.d.ts +2 -0
- package/node_modules/@adhdev/session-host-core/package.json +2 -2
- package/package.json +2 -2
- package/src/cli-adapters/provider-cli-adapter.ts +8 -2
- package/src/cli-adapters/provider-cli-shared.d.ts +2 -0
- package/src/cli-adapters/provider-cli-shared.ts +2 -0
- package/src/commands/chat-commands.ts +79 -3
- package/src/commands/stream-commands.ts +47 -26
- package/src/config/chat-history.d.ts +5 -4
- package/src/config/chat-history.ts +125 -74
- package/src/daemon/dev-server.ts +15 -1
- package/src/providers/approval-utils.ts +7 -6
- package/src/providers/contracts.d.ts +2 -0
- package/src/providers/contracts.ts +2 -0
package/dist/index.mjs
CHANGED
|
@@ -3003,6 +3003,8 @@ ${data.message || ""}`.trim();
|
|
|
3003
3003
|
}
|
|
3004
3004
|
async sendMessage(text) {
|
|
3005
3005
|
if (!this.ptyProcess) throw new Error(`${this.cliName} is not running`);
|
|
3006
|
+
const allowInputDuringGeneration = this.provider.allowInputDuringGeneration === true;
|
|
3007
|
+
const allowInterventionPrompt = allowInputDuringGeneration && this.isWaitingForResponse && this.currentStatus !== "waiting_approval";
|
|
3006
3008
|
if (this.startupParseGate) {
|
|
3007
3009
|
const deadline = Date.now() + 1e4;
|
|
3008
3010
|
while (this.startupParseGate && Date.now() < deadline) {
|
|
@@ -3010,7 +3012,9 @@ ${data.message || ""}`.trim();
|
|
|
3010
3012
|
await new Promise((resolve11) => setTimeout(resolve11, 50));
|
|
3011
3013
|
}
|
|
3012
3014
|
}
|
|
3013
|
-
|
|
3015
|
+
if (!allowInterventionPrompt) {
|
|
3016
|
+
await this.waitForInteractivePrompt();
|
|
3017
|
+
}
|
|
3014
3018
|
if (!this.ready) {
|
|
3015
3019
|
this.resolveStartupState("send_precheck");
|
|
3016
3020
|
const screenText = this.terminalScreen.getText() || "";
|
|
@@ -3022,7 +3026,7 @@ ${data.message || ""}`.trim();
|
|
|
3022
3026
|
}
|
|
3023
3027
|
}
|
|
3024
3028
|
if (!this.ready) throw new Error(`${this.cliName} not ready (status: ${this.currentStatus})`);
|
|
3025
|
-
if (this.isWaitingForResponse) {
|
|
3029
|
+
if (this.isWaitingForResponse && !allowInputDuringGeneration) {
|
|
3026
3030
|
throw new Error(`${this.cliName} is still processing the previous prompt`);
|
|
3027
3031
|
}
|
|
3028
3032
|
const blockingModal = this.activeModal || this.getStartupConfirmationModal(this.terminalScreen.getText() || "");
|
|
@@ -5921,6 +5925,7 @@ import * as path7 from "path";
|
|
|
5921
5925
|
import * as os5 from "os";
|
|
5922
5926
|
var HISTORY_DIR = path7.join(os5.homedir(), ".adhdev", "history");
|
|
5923
5927
|
var RETAIN_DAYS = 30;
|
|
5928
|
+
var savedHistorySessionCache = /* @__PURE__ */ new Map();
|
|
5924
5929
|
var CODEX_STARTER_PROMPT_RE = /^(?:[›❯]\s*)?(?:Find and fix a bug in @filename|Improve documentation in @filename|Write tests for @filename|Explain this codebase|Summarize recent commits|Implement \{feature\}|Use \/skills(?: to list available skills)?|Run \/review on my current changes)$/i;
|
|
5925
5930
|
function normalizeHistoryComparable(text) {
|
|
5926
5931
|
return String(text || "").replace(/\s+/g, " ").trim();
|
|
@@ -5978,6 +5983,85 @@ function sanitizeHistoryMessage(agentType, message) {
|
|
|
5978
5983
|
content
|
|
5979
5984
|
};
|
|
5980
5985
|
}
|
|
5986
|
+
function sanitizeHistoryFileSegment(value) {
|
|
5987
|
+
return String(value || "").replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
5988
|
+
}
|
|
5989
|
+
function listHistoryFiles(dir, historySessionId) {
|
|
5990
|
+
const sanitizedSessionId = historySessionId ? sanitizeHistoryFileSegment(historySessionId) : "";
|
|
5991
|
+
return fs3.readdirSync(dir).filter((file) => {
|
|
5992
|
+
if (!file.endsWith(".jsonl")) return false;
|
|
5993
|
+
if (sanitizedSessionId) {
|
|
5994
|
+
return file.startsWith(`${sanitizedSessionId}_`);
|
|
5995
|
+
}
|
|
5996
|
+
return true;
|
|
5997
|
+
}).sort().reverse();
|
|
5998
|
+
}
|
|
5999
|
+
function buildSavedHistoryCacheSignature(dir, files) {
|
|
6000
|
+
return files.map((file) => {
|
|
6001
|
+
try {
|
|
6002
|
+
const stat = fs3.statSync(path7.join(dir, file));
|
|
6003
|
+
return `${file}:${stat.size}:${Math.trunc(stat.mtimeMs)}`;
|
|
6004
|
+
} catch {
|
|
6005
|
+
return `${file}:missing`;
|
|
6006
|
+
}
|
|
6007
|
+
}).join("|");
|
|
6008
|
+
}
|
|
6009
|
+
function computeSavedHistorySessionSummaries(agentType, dir, files) {
|
|
6010
|
+
const groupedFiles = /* @__PURE__ */ new Map();
|
|
6011
|
+
const filePattern = /^([A-Za-z0-9_-]+)_\d{4}-\d{2}-\d{2}\.jsonl$/;
|
|
6012
|
+
for (const file of files) {
|
|
6013
|
+
const match = file.match(filePattern);
|
|
6014
|
+
if (!match?.[1]) continue;
|
|
6015
|
+
const historySessionId = match[1];
|
|
6016
|
+
const grouped = groupedFiles.get(historySessionId) || [];
|
|
6017
|
+
grouped.push(file);
|
|
6018
|
+
groupedFiles.set(historySessionId, grouped);
|
|
6019
|
+
}
|
|
6020
|
+
const summaries = [];
|
|
6021
|
+
for (const [historySessionId, grouped] of groupedFiles.entries()) {
|
|
6022
|
+
let messageCount = 0;
|
|
6023
|
+
let firstMessageAt = 0;
|
|
6024
|
+
let lastMessageAt = 0;
|
|
6025
|
+
let sessionTitle = "";
|
|
6026
|
+
let preview = "";
|
|
6027
|
+
let workspace = "";
|
|
6028
|
+
for (const file of grouped.sort()) {
|
|
6029
|
+
const filePath = path7.join(dir, file);
|
|
6030
|
+
const content = fs3.readFileSync(filePath, "utf-8");
|
|
6031
|
+
const lines = content.split("\n").filter(Boolean);
|
|
6032
|
+
for (const line of lines) {
|
|
6033
|
+
let parsed = null;
|
|
6034
|
+
try {
|
|
6035
|
+
parsed = JSON.parse(line);
|
|
6036
|
+
} catch {
|
|
6037
|
+
parsed = null;
|
|
6038
|
+
}
|
|
6039
|
+
if (!parsed || parsed.historySessionId !== historySessionId) continue;
|
|
6040
|
+
if (parsed.kind === "session_start") {
|
|
6041
|
+
if (!workspace && parsed.workspace) workspace = parsed.workspace;
|
|
6042
|
+
continue;
|
|
6043
|
+
}
|
|
6044
|
+
messageCount += 1;
|
|
6045
|
+
if (!firstMessageAt || parsed.receivedAt < firstMessageAt) firstMessageAt = parsed.receivedAt;
|
|
6046
|
+
if (!lastMessageAt || parsed.receivedAt > lastMessageAt) lastMessageAt = parsed.receivedAt;
|
|
6047
|
+
if (parsed.sessionTitle) sessionTitle = parsed.sessionTitle;
|
|
6048
|
+
if (parsed.role !== "system" && parsed.content.trim()) preview = parsed.content.trim();
|
|
6049
|
+
}
|
|
6050
|
+
}
|
|
6051
|
+
if (messageCount === 0 || !lastMessageAt) continue;
|
|
6052
|
+
summaries.push({
|
|
6053
|
+
historySessionId,
|
|
6054
|
+
sessionTitle: sessionTitle || void 0,
|
|
6055
|
+
messageCount,
|
|
6056
|
+
firstMessageAt,
|
|
6057
|
+
lastMessageAt,
|
|
6058
|
+
preview: preview || void 0,
|
|
6059
|
+
workspace: workspace || void 0
|
|
6060
|
+
});
|
|
6061
|
+
}
|
|
6062
|
+
summaries.sort((a, b) => b.lastMessageAt - a.lastMessageAt);
|
|
6063
|
+
return summaries;
|
|
6064
|
+
}
|
|
5981
6065
|
var ChatHistoryWriter = class {
|
|
5982
6066
|
/** Last seen message count per agent (deduplication) */
|
|
5983
6067
|
lastSeenCounts = /* @__PURE__ */ new Map();
|
|
@@ -6306,19 +6390,12 @@ var ChatHistoryWriter = class {
|
|
|
6306
6390
|
return name.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
6307
6391
|
}
|
|
6308
6392
|
};
|
|
6309
|
-
function readChatHistory(agentType, offset = 0, limit = 30, historySessionId) {
|
|
6393
|
+
function readChatHistory(agentType, offset = 0, limit = 30, historySessionId, excludeRecentCount = 0) {
|
|
6310
6394
|
try {
|
|
6311
6395
|
const sanitized = agentType.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
6312
6396
|
const dir = path7.join(HISTORY_DIR, sanitized);
|
|
6313
6397
|
if (!fs3.existsSync(dir)) return { messages: [], hasMore: false };
|
|
6314
|
-
const
|
|
6315
|
-
const files = fs3.readdirSync(dir).filter((f) => {
|
|
6316
|
-
if (!f.endsWith(".jsonl")) return false;
|
|
6317
|
-
if (sanitizedInstance) {
|
|
6318
|
-
return f.startsWith(`${sanitizedInstance}_`);
|
|
6319
|
-
}
|
|
6320
|
-
return true;
|
|
6321
|
-
}).sort().reverse();
|
|
6398
|
+
const files = listHistoryFiles(dir, historySessionId);
|
|
6322
6399
|
const allMessages = [];
|
|
6323
6400
|
const seen = /* @__PURE__ */ new Set();
|
|
6324
6401
|
for (const file of files) {
|
|
@@ -6349,8 +6426,13 @@ function readChatHistory(agentType, offset = 0, limit = 30, historySessionId) {
|
|
|
6349
6426
|
if (message.role !== "system") lastTurn = message;
|
|
6350
6427
|
}
|
|
6351
6428
|
const collapsed = collapseReplayAssistantTurns(agentType, chronological);
|
|
6352
|
-
const
|
|
6353
|
-
const
|
|
6429
|
+
const boundedLimit = Math.max(1, limit);
|
|
6430
|
+
const boundedOffset = Math.max(0, offset);
|
|
6431
|
+
const boundedExclude = Math.max(0, Math.min(excludeRecentCount, collapsed.length));
|
|
6432
|
+
const endExclusive = Math.max(0, collapsed.length - boundedExclude - boundedOffset);
|
|
6433
|
+
const startInclusive = Math.max(0, endExclusive - boundedLimit);
|
|
6434
|
+
const sliced = collapsed.slice(startInclusive, endExclusive);
|
|
6435
|
+
const hasMore = startInclusive > 0;
|
|
6354
6436
|
return { messages: sliced, hasMore };
|
|
6355
6437
|
} catch {
|
|
6356
6438
|
return { messages: [], hasMore: false };
|
|
@@ -6360,61 +6442,20 @@ function listSavedHistorySessions(agentType, options = {}) {
|
|
|
6360
6442
|
try {
|
|
6361
6443
|
const sanitized = agentType.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
6362
6444
|
const dir = path7.join(HISTORY_DIR, sanitized);
|
|
6363
|
-
if (!fs3.existsSync(dir))
|
|
6364
|
-
|
|
6365
|
-
|
|
6366
|
-
|
|
6367
|
-
|
|
6368
|
-
|
|
6369
|
-
|
|
6370
|
-
|
|
6371
|
-
|
|
6372
|
-
|
|
6373
|
-
|
|
6374
|
-
|
|
6375
|
-
const summaries = [];
|
|
6376
|
-
for (const [historySessionId, files] of groupedFiles.entries()) {
|
|
6377
|
-
let messageCount = 0;
|
|
6378
|
-
let firstMessageAt = 0;
|
|
6379
|
-
let lastMessageAt = 0;
|
|
6380
|
-
let sessionTitle = "";
|
|
6381
|
-
let preview = "";
|
|
6382
|
-
let workspace = "";
|
|
6383
|
-
for (const file of files.sort()) {
|
|
6384
|
-
const filePath = path7.join(dir, file);
|
|
6385
|
-
const content = fs3.readFileSync(filePath, "utf-8");
|
|
6386
|
-
const lines = content.split("\n").filter(Boolean);
|
|
6387
|
-
for (const line of lines) {
|
|
6388
|
-
let parsed = null;
|
|
6389
|
-
try {
|
|
6390
|
-
parsed = JSON.parse(line);
|
|
6391
|
-
} catch {
|
|
6392
|
-
parsed = null;
|
|
6393
|
-
}
|
|
6394
|
-
if (!parsed || parsed.historySessionId !== historySessionId) continue;
|
|
6395
|
-
if (parsed.kind === "session_start") {
|
|
6396
|
-
if (!workspace && parsed.workspace) workspace = parsed.workspace;
|
|
6397
|
-
continue;
|
|
6398
|
-
}
|
|
6399
|
-
messageCount += 1;
|
|
6400
|
-
if (!firstMessageAt || parsed.receivedAt < firstMessageAt) firstMessageAt = parsed.receivedAt;
|
|
6401
|
-
if (!lastMessageAt || parsed.receivedAt > lastMessageAt) lastMessageAt = parsed.receivedAt;
|
|
6402
|
-
if (parsed.sessionTitle) sessionTitle = parsed.sessionTitle;
|
|
6403
|
-
if (parsed.role !== "system" && parsed.content.trim()) preview = parsed.content.trim();
|
|
6404
|
-
}
|
|
6405
|
-
}
|
|
6406
|
-
if (messageCount === 0 || !lastMessageAt) continue;
|
|
6407
|
-
summaries.push({
|
|
6408
|
-
historySessionId,
|
|
6409
|
-
sessionTitle: sessionTitle || void 0,
|
|
6410
|
-
messageCount,
|
|
6411
|
-
firstMessageAt,
|
|
6412
|
-
lastMessageAt,
|
|
6413
|
-
preview: preview || void 0,
|
|
6414
|
-
workspace: workspace || void 0
|
|
6445
|
+
if (!fs3.existsSync(dir)) {
|
|
6446
|
+
savedHistorySessionCache.delete(sanitized);
|
|
6447
|
+
return { sessions: [], hasMore: false };
|
|
6448
|
+
}
|
|
6449
|
+
const files = listHistoryFiles(dir);
|
|
6450
|
+
const signature = buildSavedHistoryCacheSignature(dir, files);
|
|
6451
|
+
const cached = savedHistorySessionCache.get(sanitized);
|
|
6452
|
+
const summaries = cached?.signature === signature ? cached.summaries : computeSavedHistorySessionSummaries(agentType, dir, files);
|
|
6453
|
+
if (!cached || cached.signature !== signature) {
|
|
6454
|
+
savedHistorySessionCache.set(sanitized, {
|
|
6455
|
+
signature,
|
|
6456
|
+
summaries
|
|
6415
6457
|
});
|
|
6416
6458
|
}
|
|
6417
|
-
summaries.sort((a, b) => b.lastMessageAt - a.lastMessageAt);
|
|
6418
6459
|
const offset = Math.max(0, options.offset || 0);
|
|
6419
6460
|
const limit = Math.max(1, options.limit || 30);
|
|
6420
6461
|
const sliced = summaries.slice(offset, offset + limit);
|
|
@@ -6915,22 +6956,22 @@ init_read_chat_contract();
|
|
|
6915
6956
|
|
|
6916
6957
|
// src/providers/approval-utils.ts
|
|
6917
6958
|
var DEFAULT_APPROVAL_POSITIVE_HINTS = [
|
|
6918
|
-
"
|
|
6959
|
+
"yes",
|
|
6960
|
+
"allow once",
|
|
6919
6961
|
"approve",
|
|
6920
6962
|
"accept",
|
|
6921
|
-
"allow once",
|
|
6922
|
-
"always allow",
|
|
6923
|
-
"allow",
|
|
6924
|
-
"yes",
|
|
6925
|
-
"proceed",
|
|
6926
6963
|
"continue",
|
|
6964
|
+
"run",
|
|
6965
|
+
"proceed",
|
|
6927
6966
|
"confirm",
|
|
6928
6967
|
"save",
|
|
6929
6968
|
"ok",
|
|
6930
|
-
"trust"
|
|
6969
|
+
"trust",
|
|
6970
|
+
"allow",
|
|
6971
|
+
"always allow"
|
|
6931
6972
|
];
|
|
6932
6973
|
function normalizeApprovalLabel(value) {
|
|
6933
|
-
return String(value || "").toLowerCase().replace(/[^\p{L}\p{N}]+/gu, " ").trim();
|
|
6974
|
+
return String(value || "").toLowerCase().replace(/^[\s\[(<{]*\d+(?:\s*[.)\]}>:-]|\s)+/, "").replace(/[^\p{L}\p{N}]+/gu, " ").trim();
|
|
6934
6975
|
}
|
|
6935
6976
|
function getApprovalPositiveHints(provider) {
|
|
6936
6977
|
const customHints = Array.isArray(provider?.approvalPositiveHints) ? provider.approvalPositiveHints.map((hint) => normalizeApprovalLabel(String(hint || ""))).filter(Boolean) : [];
|
|
@@ -8708,6 +8749,41 @@ function normalizeReadChatMessages(payload) {
|
|
|
8708
8749
|
const messages = Array.isArray(payload.messages) ? payload.messages : [];
|
|
8709
8750
|
return normalizeChatMessages(messages);
|
|
8710
8751
|
}
|
|
8752
|
+
function buildReadChatReplayCollapseSignature(message) {
|
|
8753
|
+
if (!message) return "";
|
|
8754
|
+
const role = typeof message.role === "string" ? message.role.trim().toLowerCase() : "";
|
|
8755
|
+
const kind = typeof message.kind === "string" ? message.kind.trim().toLowerCase() : "standard";
|
|
8756
|
+
const senderName = typeof message.senderName === "string" ? message.senderName.trim().toLowerCase() : "";
|
|
8757
|
+
const content = flattenContent(message.content || "").replace(/\s+/g, " ").trim();
|
|
8758
|
+
return `${role}:${kind}:${senderName}:${content}`;
|
|
8759
|
+
}
|
|
8760
|
+
function shouldCollapseReadChatReplayDuplicate(message) {
|
|
8761
|
+
if (!message) return false;
|
|
8762
|
+
const role = typeof message.role === "string" ? message.role.trim().toLowerCase() : "";
|
|
8763
|
+
if (role !== "assistant" && role !== "system") return false;
|
|
8764
|
+
const kind = typeof message.kind === "string" ? message.kind.trim().toLowerCase() : "standard";
|
|
8765
|
+
return kind === "tool" || kind === "terminal" || kind === "thought" || kind === "system";
|
|
8766
|
+
}
|
|
8767
|
+
function collapseReplayDuplicatesFromReadChat(messages) {
|
|
8768
|
+
const collapsed = [];
|
|
8769
|
+
let lastReplayTurnSignature = "";
|
|
8770
|
+
for (const message of messages) {
|
|
8771
|
+
const signature = buildReadChatReplayCollapseSignature(message);
|
|
8772
|
+
const previous = collapsed[collapsed.length - 1];
|
|
8773
|
+
const previousSignature = buildReadChatReplayCollapseSignature(previous);
|
|
8774
|
+
if (shouldCollapseReadChatReplayDuplicate(message) && signature) {
|
|
8775
|
+
if (previousSignature === signature) continue;
|
|
8776
|
+
if (lastReplayTurnSignature === signature) continue;
|
|
8777
|
+
}
|
|
8778
|
+
collapsed.push(message);
|
|
8779
|
+
if (shouldCollapseReadChatReplayDuplicate(message) && signature) {
|
|
8780
|
+
lastReplayTurnSignature = signature;
|
|
8781
|
+
} else if ((message.role || "").toLowerCase() === "user") {
|
|
8782
|
+
lastReplayTurnSignature = "";
|
|
8783
|
+
}
|
|
8784
|
+
}
|
|
8785
|
+
return collapsed;
|
|
8786
|
+
}
|
|
8711
8787
|
function deriveHistoryDedupKey(message) {
|
|
8712
8788
|
const unitKey = typeof message._unitKey === "string" ? message._unitKey.trim() : "";
|
|
8713
8789
|
if (unitKey) return `read_chat:${unitKey}`;
|
|
@@ -8783,14 +8859,38 @@ function computeReadChatSync(messages, cursor) {
|
|
|
8783
8859
|
lastMessageSignature
|
|
8784
8860
|
};
|
|
8785
8861
|
}
|
|
8862
|
+
function hasNonEmptyModalButtons(activeModal) {
|
|
8863
|
+
if (!activeModal || typeof activeModal !== "object") return false;
|
|
8864
|
+
const buttons = activeModal.buttons;
|
|
8865
|
+
return Array.isArray(buttons) && buttons.some((button) => typeof button === "string" && button.trim().length > 0);
|
|
8866
|
+
}
|
|
8867
|
+
function normalizeReadChatCommandStatus(status, activeModal) {
|
|
8868
|
+
const raw = typeof status === "string" ? status.trim() : "";
|
|
8869
|
+
if (!raw) {
|
|
8870
|
+
return hasNonEmptyModalButtons(activeModal) ? "waiting_approval" : "idle";
|
|
8871
|
+
}
|
|
8872
|
+
switch (raw) {
|
|
8873
|
+
case "starting":
|
|
8874
|
+
return hasNonEmptyModalButtons(activeModal) ? "waiting_approval" : "generating";
|
|
8875
|
+
case "stopped":
|
|
8876
|
+
case "disconnected":
|
|
8877
|
+
case "not_monitored":
|
|
8878
|
+
return "error";
|
|
8879
|
+
default:
|
|
8880
|
+
return raw;
|
|
8881
|
+
}
|
|
8882
|
+
}
|
|
8786
8883
|
function buildReadChatCommandResult(payload, args) {
|
|
8787
8884
|
let validatedPayload;
|
|
8788
8885
|
try {
|
|
8789
|
-
validatedPayload = validateReadChatResultPayload(
|
|
8886
|
+
validatedPayload = validateReadChatResultPayload({
|
|
8887
|
+
...payload,
|
|
8888
|
+
status: normalizeReadChatCommandStatus(payload?.status, payload?.activeModal)
|
|
8889
|
+
}, "read_chat command result");
|
|
8790
8890
|
} catch (error) {
|
|
8791
8891
|
return { success: false, error: error?.message || String(error) };
|
|
8792
8892
|
}
|
|
8793
|
-
const messages = normalizeReadChatMessages(validatedPayload);
|
|
8893
|
+
const messages = collapseReplayDuplicatesFromReadChat(normalizeReadChatMessages(validatedPayload));
|
|
8794
8894
|
const cursor = normalizeReadChatCursor(args);
|
|
8795
8895
|
if (!cursor.knownMessageCount && !cursor.lastMessageSignature && cursor.tailLimit > 0 && messages.length > cursor.tailLimit) {
|
|
8796
8896
|
const tailMessages = messages.slice(-cursor.tailLimit);
|
|
@@ -8872,7 +8972,15 @@ async function handleChatHistory(h, args) {
|
|
|
8872
8972
|
try {
|
|
8873
8973
|
const provider = h.getProvider(agentType);
|
|
8874
8974
|
const agentStr = provider?.type || agentType || getCurrentProviderType(h);
|
|
8875
|
-
const
|
|
8975
|
+
const transport = getTargetTransport(h, provider);
|
|
8976
|
+
let excludeRecentCount = Math.max(0, Number(args?.excludeRecentCount || 0));
|
|
8977
|
+
if (isCliLikeTransport(transport)) {
|
|
8978
|
+
const adapter = getTargetedCliAdapter(h, args, provider?.type);
|
|
8979
|
+
const status = adapter?.getStatus?.();
|
|
8980
|
+
const visibleCount = Array.isArray(status?.messages) ? status.messages.length : 0;
|
|
8981
|
+
if (visibleCount > excludeRecentCount) excludeRecentCount = visibleCount;
|
|
8982
|
+
}
|
|
8983
|
+
const result = readChatHistory(agentStr, offset || 0, limit || 30, historySessionId, excludeRecentCount);
|
|
8876
8984
|
return { success: true, ...result, agent: agentStr };
|
|
8877
8985
|
} catch (e) {
|
|
8878
8986
|
return { success: false, error: e.message };
|
|
@@ -10132,13 +10240,6 @@ function getCliScriptCommand(payload) {
|
|
|
10132
10240
|
|
|
10133
10241
|
// src/commands/stream-commands.ts
|
|
10134
10242
|
init_logger();
|
|
10135
|
-
function getCliPresentationMode(h, targetSessionId) {
|
|
10136
|
-
if (!targetSessionId) return null;
|
|
10137
|
-
const instance = h.ctx.instanceManager?.getInstance(targetSessionId);
|
|
10138
|
-
if (instance?.category !== "cli") return null;
|
|
10139
|
-
const mode = instance.getPresentationMode?.();
|
|
10140
|
-
return mode === "chat" || mode === "terminal" ? mode : null;
|
|
10141
|
-
}
|
|
10142
10243
|
function normalizeOpenPanelCommandResult(result) {
|
|
10143
10244
|
const payload = Object.prototype.hasOwnProperty.call(result, "result") ? result.result : result;
|
|
10144
10245
|
if (payload === true) return { opened: true, visible: true, focused: false };
|
|
@@ -10211,9 +10312,6 @@ async function handleOpenPanel(h, args) {
|
|
|
10211
10312
|
function handlePtyInput(h, args) {
|
|
10212
10313
|
const { cliType, data, targetSessionId } = args || {};
|
|
10213
10314
|
if (!data) return { success: false, error: "data required" };
|
|
10214
|
-
if (getCliPresentationMode(h, targetSessionId) === "chat") {
|
|
10215
|
-
return { success: false, error: "CLI session is in chat mode", code: "CLI_VIEW_MODE_NOT_TERMINAL" };
|
|
10216
|
-
}
|
|
10217
10315
|
const adapter = h.getCliAdapter(targetSessionId || cliType);
|
|
10218
10316
|
if (!adapter || typeof adapter.writeRaw !== "function") {
|
|
10219
10317
|
return { success: false, error: `CLI adapter not found: ${targetSessionId || cliType || "unknown"}` };
|
|
@@ -10221,24 +10319,10 @@ function handlePtyInput(h, args) {
|
|
|
10221
10319
|
adapter.writeRaw(data);
|
|
10222
10320
|
return { success: true };
|
|
10223
10321
|
}
|
|
10224
|
-
function handlePtyResize(
|
|
10225
|
-
const {
|
|
10322
|
+
function handlePtyResize(_h, args) {
|
|
10323
|
+
const { cols, rows } = args || {};
|
|
10226
10324
|
if (!cols || !rows) return { success: false, error: "cols and rows required" };
|
|
10227
|
-
|
|
10228
|
-
return { success: false, error: "CLI session is in chat mode", code: "CLI_VIEW_MODE_NOT_TERMINAL" };
|
|
10229
|
-
}
|
|
10230
|
-
const adapter = h.getCliAdapter(targetSessionId || cliType);
|
|
10231
|
-
if (!adapter || typeof adapter.resize !== "function") {
|
|
10232
|
-
return { success: false, error: `CLI adapter not found: ${targetSessionId || cliType || "unknown"}` };
|
|
10233
|
-
}
|
|
10234
|
-
const resize = adapter.resize;
|
|
10235
|
-
if (force) {
|
|
10236
|
-
resize(cols - 1, rows);
|
|
10237
|
-
setTimeout(() => resize(cols, rows), 50);
|
|
10238
|
-
} else {
|
|
10239
|
-
resize(cols, rows);
|
|
10240
|
-
}
|
|
10241
|
-
return { success: true };
|
|
10325
|
+
return { success: false, error: "PTY resize temporarily disabled", code: "PTY_RESIZE_DISABLED" };
|
|
10242
10326
|
}
|
|
10243
10327
|
function handleGetProviderSettings(h, args) {
|
|
10244
10328
|
const loader = h.ctx.providerLoader;
|
|
@@ -10325,15 +10409,45 @@ function normalizeProviderScriptArgs(args, scriptName) {
|
|
|
10325
10409
|
}
|
|
10326
10410
|
function buildControlScriptResult(scriptName, payload) {
|
|
10327
10411
|
if (!payload || typeof payload !== "object") return {};
|
|
10328
|
-
|
|
10329
|
-
|
|
10412
|
+
const legacyListPayload = (() => {
|
|
10413
|
+
if (Array.isArray(payload.options)) return payload;
|
|
10414
|
+
if (/^listmodels$/i.test(scriptName) && Array.isArray(payload.models)) {
|
|
10415
|
+
return {
|
|
10416
|
+
options: payload.models,
|
|
10417
|
+
currentValue: payload.currentValue ?? payload.current ?? payload.currentModel,
|
|
10418
|
+
...typeof payload.error === "string" ? { error: payload.error } : {}
|
|
10419
|
+
};
|
|
10420
|
+
}
|
|
10421
|
+
if (/^listmodes$/i.test(scriptName) && Array.isArray(payload.modes)) {
|
|
10422
|
+
return {
|
|
10423
|
+
options: payload.modes,
|
|
10424
|
+
currentValue: payload.currentValue ?? payload.current ?? payload.currentMode ?? payload.mode,
|
|
10425
|
+
...typeof payload.error === "string" ? { error: payload.error } : {}
|
|
10426
|
+
};
|
|
10427
|
+
}
|
|
10428
|
+
return null;
|
|
10429
|
+
})();
|
|
10430
|
+
if (legacyListPayload) {
|
|
10431
|
+
return { controlResult: normalizeControlListResult(legacyListPayload) };
|
|
10330
10432
|
}
|
|
10331
|
-
const
|
|
10433
|
+
const legacyMutationPayload = (() => {
|
|
10434
|
+
if (typeof payload.ok === "boolean") return payload;
|
|
10435
|
+
if (typeof payload.success === "boolean") {
|
|
10436
|
+
return {
|
|
10437
|
+
ok: payload.success,
|
|
10438
|
+
currentValue: payload.currentValue ?? payload.value ?? payload.model ?? payload.mode ?? payload.selectedModel ?? payload.selectedMode,
|
|
10439
|
+
...Array.isArray(payload.effects) ? { effects: payload.effects } : {},
|
|
10440
|
+
...typeof payload.error === "string" ? { error: payload.error } : {}
|
|
10441
|
+
};
|
|
10442
|
+
}
|
|
10443
|
+
return null;
|
|
10444
|
+
})();
|
|
10445
|
+
const looksLikeValueMutation = /^set|^change/i.test(scriptName) || payload.currentValue !== void 0 || payload.value !== void 0 || payload.success !== void 0;
|
|
10332
10446
|
if (looksLikeValueMutation) {
|
|
10333
|
-
return { controlResult: normalizeControlSetResult(payload) };
|
|
10447
|
+
return { controlResult: normalizeControlSetResult(legacyMutationPayload || payload) };
|
|
10334
10448
|
}
|
|
10335
10449
|
if (payload.ok !== void 0 || Array.isArray(payload.effects) || typeof payload.error === "string") {
|
|
10336
|
-
return { controlResult: normalizeControlInvokeResult(payload) };
|
|
10450
|
+
return { controlResult: normalizeControlInvokeResult(legacyMutationPayload || payload) };
|
|
10337
10451
|
}
|
|
10338
10452
|
return {};
|
|
10339
10453
|
}
|
|
@@ -10408,7 +10522,7 @@ async function executeProviderScript(h, args, scriptName) {
|
|
|
10408
10522
|
}
|
|
10409
10523
|
const managed = runtimeSessionId ? h.agentStream?.getManagedSession(runtimeSessionId) : null;
|
|
10410
10524
|
const targetSessionId = managed?.cdpSessionId || null;
|
|
10411
|
-
const IDE_LEVEL_SCRIPTS = provider.type === "claude-code-vscode" ? ["listModes", "setMode"] : ["listModes", "setMode", "listModels", "setModel"];
|
|
10525
|
+
const IDE_LEVEL_SCRIPTS = provider.type === "claude-code-vscode" ? ["listModes", "setMode", "listModels", "setModel", "setModelGui"] : ["listModes", "setMode", "listModels", "setModel"];
|
|
10412
10526
|
if (IDE_LEVEL_SCRIPTS.includes(scriptName)) {
|
|
10413
10527
|
if (targetSessionId) {
|
|
10414
10528
|
try {
|
|
@@ -22633,6 +22747,20 @@ var DevServer = class _DevServer {
|
|
|
22633
22747
|
async handleReload(_req, res) {
|
|
22634
22748
|
try {
|
|
22635
22749
|
this.providerLoader.reload();
|
|
22750
|
+
let refreshedInstances = 0;
|
|
22751
|
+
if (this.instanceManager) {
|
|
22752
|
+
for (const id of this.instanceManager.listInstanceIds()) {
|
|
22753
|
+
const instance = this.instanceManager.getInstance(id);
|
|
22754
|
+
const providerType = typeof instance?.type === "string" ? instance.type : "";
|
|
22755
|
+
if (!providerType) continue;
|
|
22756
|
+
const resolved = this.providerLoader.resolve(providerType);
|
|
22757
|
+
if (!resolved) continue;
|
|
22758
|
+
if (instance && typeof instance === "object" && "provider" in instance) {
|
|
22759
|
+
instance.provider = resolved;
|
|
22760
|
+
refreshedInstances += 1;
|
|
22761
|
+
}
|
|
22762
|
+
}
|
|
22763
|
+
}
|
|
22636
22764
|
const providers = this.providerLoader.getAll().map((p) => ({
|
|
22637
22765
|
type: p.type,
|
|
22638
22766
|
name: p.name,
|
|
@@ -22643,7 +22771,7 @@ var DevServer = class _DevServer {
|
|
|
22643
22771
|
cdp.clearTargetId();
|
|
22644
22772
|
}
|
|
22645
22773
|
}
|
|
22646
|
-
this.json(res, 200, { reloaded: true, providers });
|
|
22774
|
+
this.json(res, 200, { reloaded: true, refreshedInstances, providers });
|
|
22647
22775
|
} catch (e) {
|
|
22648
22776
|
this.json(res, 500, { error: e.message });
|
|
22649
22777
|
}
|