Merge main into agent/issue-88 and resolve workspace aliases

This commit is contained in:
xmanrui 2026-09-03 00:47:02 +08:00
commit 3240632bef
90 changed files with 6394 additions and 619 deletions

View file

@ -11,8 +11,11 @@ import {
hasInboundImages,
imagePromptDiagnostic,
imagePromptUserMessage,
promptContentForMessage,
} from '../shared/image-prompt.mjs';
import {
hasReplyReference,
promptContentForInboundMessage,
} from '../shared/semantic/reply-reference.mjs';
import {
hasInboundFiles,
inboundFileUserMessage,
@ -44,7 +47,12 @@ import {
isPresetCommand,
runPresetCommand,
} from '../shared/preset-command.mjs';
import { runWorkspaceCommand, resolveSessionListWorkspace, workspacePathSnapshot } from '../shared/workspace-command.mjs';
import {
parseSessionListArgument,
resolveSessionListWorkspace,
runWorkspaceCommand,
workspacePathSnapshot,
} from '../shared/workspace-command.mjs';
import { askInWorkspaceSession } from '../shared/workspace-session.mjs';
import { captureContextEnhancement, enhanceContextContent } from '../shared/context-enhancement.mjs';
import { deliverOutboundArtifacts } from '../shared/semantic/artifact-delivery.mjs';
@ -156,8 +164,8 @@ const WORKSPACE_HELP_LINES = [
'/workspace 工作区序号或绝对路径 切换工作区',
'/session Session ID 或当前工作区序号 将当前聊天绑定到指定会话',
'/workspacelist 列出工作区绝对路径',
'/ws、/wsl、/workspaces 工作区命令别名',
'/sessionlist 或 /sessions [工作区序号或绝对路径] 列出会话 ID 和标题',
'/sessionlist --limit N 仅列出当前工作区前 N 个会话',
];
/** Safe user-facing text for bind/workspace failures (no raw messages). */
@ -627,7 +635,9 @@ export class FeishuHarnessBridge {
&& (this.#queues.has(key) || pending || this.#approvals.hasPending(key))
? { handled: true, kind: 'busy', message: batchInputBusyMessage() }
: this.#batchInputs.handle(key, batchText, {
plainText: event.message.message_type === 'text' && Boolean(batchText),
plainText: event.message.message_type === 'text'
&& Boolean(batchText)
&& !hasReplyReference(commandMessage),
});
if (result.handled) {
if (result.kind === 'submit') {
@ -1033,11 +1043,12 @@ export class FeishuHarnessBridge {
const text = message.content;
const hasImages = hasInboundImages(message);
const hasFiles = hasInboundFiles(message);
const hasReply = hasReplyReference(message);
// 命令识别对 text 与纯文本 post 一视同仁:post 富文本若仅含单个
// 文本段落(如复制粘贴的 /new),同样按命令处理;带图片/文件不认。
// accept() 侧已用 nonEmptyString(content) 判定,两侧保持一致。
const commandText = !hasImages && !hasFiles && text ? text.trim() : null;
if (!text && !hasImages && !hasFiles) {
if (!text && !hasImages && !hasFiles && !hasReply) {
await this.#send(event.message.chat_id, t('目前支持文字、图片和文件消息。'), { replyTo: event.message.message_id });
return;
}
@ -1080,8 +1091,18 @@ export class FeishuHarnessBridge {
return;
}
if (SESSION_LIST_PREFIX.test(commandText)) {
const selector = commandText.replace(/^\/(?:sessionlist|sessions)/i, '').trim() || null;
await this.#showSessions({ chatId: event.message.chat_id, key, replyTo: event.message.message_id }, selector, 0);
const argument = commandText.replace(/^\/(?:sessionlist|sessions)/i, '').trim();
const request = parseSessionListArgument(argument);
if (request.error) {
await this.#send(event.message.chat_id, request.error, { replyTo: event.message.message_id });
return;
}
await this.#showSessions(
{ chatId: event.message.chat_id, key, replyTo: event.message.message_id },
request.selector || null,
0,
{ limit: request.limit },
);
return;
}
if (WORKSPACE_LIST_COMMAND.test(commandText)) {
@ -1845,6 +1866,7 @@ export class FeishuHarnessBridge {
messageId = null,
sessionWorkspace = null,
sessionPage = 0,
sessionLimit = null,
selections = [],
}) {
// Confirmations triggered by a card interaction stay anchored to the
@ -1856,7 +1878,7 @@ export class FeishuHarnessBridge {
{ chatId, key, replyTo: messageId },
sessionWorkspace,
page,
{ updateMessageId: messageId },
{ updateMessageId: messageId, limit: sessionLimit },
);
return;
}
@ -2035,7 +2057,7 @@ export class FeishuHarnessBridge {
{ chatId, key, replyTo: messageId },
sessionWorkspace,
sessionPage,
{ updateMessageId: messageId },
{ updateMessageId: messageId, limit: sessionLimit },
);
}
return;
@ -2051,7 +2073,7 @@ export class FeishuHarnessBridge {
{ chatId, key, replyTo: messageId },
sessionWorkspace,
sessionPage,
{ updateMessageId: messageId },
{ updateMessageId: messageId, limit: sessionLimit },
);
}
}
@ -2136,7 +2158,7 @@ export class FeishuHarnessBridge {
{ chatId, key, replyTo = null },
selector,
page = 0,
{ updateMessageId = null } = {},
{ updateMessageId = null, limit = null } = {},
) {
try {
const signal = this.#cardDataSignal();
@ -2146,7 +2168,11 @@ export class FeishuHarnessBridge {
return;
}
const listed = await this.#harness.listWorkspaceSessions(resolved.workspace, { signal });
const sessions = this.#visibleSessions(Array.isArray(listed?.sessions) ? listed.sessions : []);
const visibleSessions = this.#visibleSessions(Array.isArray(listed?.sessions) ? listed.sessions : []);
const sessionLimit = Number.isSafeInteger(limit) && limit > 0 ? limit : null;
const sessions = sessionLimit === null
? visibleSessions
: visibleSessions.slice(0, sessionLimit);
const workspace = listed?.workspace ?? resolved.workspace;
if (sessions.length === 0) {
await this.#send(chatId, t('工作区:{workspace}\n该工作区暂无会话。', { workspace }), { replyTo });
@ -2173,6 +2199,7 @@ export class FeishuHarnessBridge {
// list response's workspace is display data and is not authoritative.
sessionWorkspace: resolved.workspace,
sessionPage: safePage,
sessionLimit,
},
);
} catch (error) {
@ -2241,6 +2268,9 @@ export class FeishuHarnessBridge {
sessionPage: Number.isSafeInteger(options.sessionPage) && options.sessionPage >= 0
? options.sessionPage
: 0,
sessionLimit: Number.isSafeInteger(options.sessionLimit) && options.sessionLimit > 0
? options.sessionLimit
: null,
});
if (this.#cardKeys.size > 200) {
const oldest = this.#cardKeys.keys().next().value;
@ -3290,15 +3320,20 @@ export class FeishuHarnessBridge {
askCompleted = true;
onAskComplete?.();
};
let content = hasInboundImages(message)
? await promptContentForMessage(message, { signal: this.#signal })
let content = hasInboundImages(message) || hasReplyReference(message)
? await promptContentForInboundMessage(message, { signal: this.#signal })
: undefined;
const snapshot = this.#acceptedMessageIds.get(messageId);
let contextEnhanced = false;
if (snapshot) {
content = enhanceContextContent(content ?? text, snapshot, () => ({
const originalContent = content ?? text;
content = enhanceContextContent(originalContent, snapshot, () => ({
channel: 'feishu',
senderId: senderOpenId(event),
chatId: event.message.chat_id,
threadId: event.message.thread_id,
}));
contextEnhanced = content !== originalContent;
}
if (!this.#channel?.stream) {
const { answer, artifacts = [] } = await askInWorkspaceSession({
@ -3307,6 +3342,7 @@ export class FeishuHarnessBridge {
key,
text,
content,
contextEnhanced,
createOptions: { signal: this.#signal },
existsOptions: { signal: this.#signal },
askOptions: this.#interactionAskOptions(event, key, message.files),
@ -3353,8 +3389,18 @@ export class FeishuHarnessBridge {
stream = await this.#channel.stream(chatId, {
markdown: async (controller) => {
promptStarted = true;
const baseAskOptions = this.#interactionAskOptions(event, key, message.files);
const askOptions = {
...this.#interactionAskOptions(event, key, message.files),
...baseAskOptions,
// issue #86:独立交互消息(提问/审批)会落在占位卡下方,呈现前
// 先换卡,让最终答案落在交互消息之后的新流式卡上。
onInteraction: async (interaction) => {
if ((interaction?.kind === 'question' || interaction?.kind === 'approval')
&& typeof controller?.rotate === 'function') {
await controller.rotate();
}
await baseAskOptions.onInteraction(interaction);
},
onUpdate: async (update) => {
await controller.setContent(this.#progressText(update));
this.#status.streamUpdates = (this.#status.streamUpdates ?? 0) + 1;
@ -3366,6 +3412,7 @@ export class FeishuHarnessBridge {
key,
text,
content,
contextEnhanced,
createOptions: { signal: this.#signal },
existsOptions: { signal: this.#signal },
askOptions,
@ -3429,6 +3476,7 @@ export class FeishuHarnessBridge {
key,
text,
content,
contextEnhanced,
createOptions: { signal: this.#signal },
existsOptions: { signal: this.#signal },
askOptions: this.#interactionAskOptions(event, key, message.files),