chore: directory migration - gateway→server, web→client/electron

This commit is contained in:
2026-09-08 19:16:35 +08:00
parent fd9f99a3f9
commit f9d757b5e5
243 changed files with 5095 additions and 228 deletions

View File

@ -0,0 +1,55 @@
/**
* 崩溃/异常终止时通过 Gateway API 发送邮件通知用户。
*
* 约束同 pi-mail-bridge/lib/crash-notify.mjs
* - 不依赖外部库,只用 Node 内置 http
* - 所有错误静默
* - 只在崩溃路径调用
*/
const http = require('http');
const GATEWAY_URL = process.env.AGENTMAIL_GATEWAY_URL || 'http://127.0.0.1:8180';
const AGENT_NAME = process.env.AGENTMAIL_AGENT_NAME || 'opencode';
const AGENT_KEY = process.env.AGENTMAIL_AGENT_KEY || '';
function notifyCrash(reason, err) {
if (!AGENT_KEY) return;
const body = JSON.stringify({
to: 'jianf@',
subject: `[${AGENT_NAME}] 桥进程异常终止`,
body: [
`**${AGENT_NAME}** 桥进程遇到未处理异常,已终止。`,
'',
`**原因**${reason}`,
err ? `**错误信息**${err.message || String(err)}` : '',
err?.stack ? `\n**堆栈**(首 500 字):\n\`\`\`\n${err.stack.slice(0, 500)}\n\`\`\`` : '',
'',
`**自动重启**systemd 将在 10 秒内自动拉起。`,
`如果反复崩溃,请检查日志:`,
`- \`journalctl -u ${AGENT_NAME}-serve -n 50 --no-pager\``,
].filter(Boolean).join('\n'),
});
const parsed = new URL(`${GATEWAY_URL}/api/v1/agent/send`);
const req = http.request({
hostname: parsed.hostname,
port: parsed.port || 80,
path: parsed.pathname,
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-API-Key': AGENT_KEY,
'Content-Length': Buffer.byteLength(body),
},
timeout: 5000,
}, () => {});
req.on('error', () => {});
req.on('timeout', () => { req.destroy(); });
req.write(body);
req.end();
}
module.exports = { notifyCrash };

View File

@ -32,7 +32,7 @@
*
* # 为什么必须共用
*
* 标记格式是**服务端正则的镜像**`gateway/internal/handler/rename_proposal.go`)。
* 标记格式是**服务端正则的镜像**`server/internal/handler/rename_proposal.go`)。
* 各平台各写一遍拼接,某一处少个空格或把双引号写成单引号,服务端匹配不上 ——
* 而失败是静默的:邮件照常发出,提议凭空消失,模型以为自己提过了。
*/

View File

@ -7,7 +7,7 @@ import {
} from '../lib/rename-proposal.js';
// 这一组测试钉住的是「插件拼的标记与服务端正则逐字符对应」。
// 服务端那条正则在 gateway/internal/handler/rename_proposal.go
// 服务端那条正则在 server/internal/handler/rename_proposal.go
// <!--\s*agentmail:rename-session\s+alias="([^"]*)"(?:\s+reason="([^"]*)")?\s*-->
// 拼错不会报错 —— 邮件照常发出,提议凭空消失。