4 Commits
Author SHA1 Message Date
JianMiauandClaude Fable 5 491ab5bc8f 發佈 0.1.5:換模型後舊會話自動重開
根本原因:
codex 拒絕用不同模型 resume 舊會話(recorded with model X but resuming with Y),
bot 換模型設定後,既有聊天室的會話會直接報錯卡住。

修法:
偵測到模型不匹配(或會話已被清掉)時自動清除會話、開新會話重試,
並在回覆開頭註明已自動開新會話、舊記憶未帶入。

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-07 11:56:22 +08:00
JianMiauandClaude Fable 5 8d4cec9bb3 發佈與版控目標改為 jianmiau
摘要:
publishConfig 與 repository 改指向 jianmiau.ddns.net,之後裸 npm publish
直接發到公開 registry;git origin 也已對調為 jianmiau(catan 降為備用 remote)。

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-04 17:14:01 +08:00
JianMiauandClaude Fable 5 c8b3ff68a7 發佈 0.1.4:README 安裝指令統一用公開 registry
摘要:
安裝與升級指令改為只列 jianmiau.ddns.net 的公開 registry(免登入),
移除公司內部 registry 的說明。

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-04 17:12:43 +08:00
JianMiauandClaude Fable 5 ef9fcb9d4a 發佈 0.1.3:README 圖片改公開網址、安裝說明補公開 registry
摘要:
README 截圖改指向 jianmiau.ddns.net(公開 repo,免登入可看),
兩邊套件頁的圖都能正常顯示;安裝說明補上公開 registry 的裝法。

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-04 17:09:08 +08:00
3 changed files with 22 additions and 13 deletions
+8 -7
View File
@@ -20,9 +20,10 @@
## 快速開始
套件不在官方 npmjs 上,安裝要指定 `--registry`(不用登入):
```bash
# 套件發佈在公司的 npm registry(不是官方 npmjs),安裝要指定 --registry
npm install -g telegram-codex-bot --registry=https://git.catan.com.tw/api/packages/Frontend/npm/
npm install -g telegram-codex-bot --registry=https://jianmiau.ddns.net/api/packages/AI/npm/
telegram-codex-bot start # 先做環境檢查(codex/登入/pm2/git),再把控制台掛上 pm2
```
@@ -30,7 +31,7 @@ telegram-codex-bot start # 先做環境檢查(codex/登入/pm2/git),再
之後升級同樣帶 `--registry`:
```bash
npm update -g telegram-codex-bot --registry=https://git.catan.com.tw/api/packages/Frontend/npm/
npm update -g telegram-codex-bot --registry=https://jianmiau.ddns.net/api/packages/AI/npm/
```
打開 **http://localhost:3799** →「🤖 Bot 管理」→「➕ 新增 Bot」:
@@ -58,7 +59,7 @@ npm update -g telegram-codex-bot --registry=https://git.catan.com.tw/api/package
**① Bot 管理首頁** — 每個 bot 一列:狀態、工作目錄、沙盒與模型設定、遮罩後的 token。
右側按鈕:▶ 啟動 / ⏹ 停止、🔄 重啟、📄 log、✏️ 編輯、🗑 刪除。上方橫幅提醒群組使用要先關 Group Privacy。
![Bot 管理首頁](https://git.catan.com.tw/Frontend/telegram-codex-bot/media/branch/master/docs/01-bots.png)
![Bot 管理首頁](https://jianmiau.ddns.net/AI/telegram-codex-bot/media/branch/master/docs/01-bots.png)
**② 新增 Bot** — 按右上「➕ 新增 Bot」:
@@ -68,15 +69,15 @@ npm update -g telegram-codex-bot --registry=https://git.catan.com.tw/api/package
4. **模型 / 推理強度 / 速度**:下拉選單,預設值自動帶你機器上 codex 的全域設定;清單讀自本機 codex 模型快取,換模型時強度選項會連動(如 ultra 只有支援的模型才出現)
5. 勾「建立後立即啟動」→ 儲存,bot 就上線了
![新增 Bot 表單](https://git.catan.com.tw/Frontend/telegram-codex-bot/media/branch/master/docs/02-create.png)
![新增 Bot 表單](https://jianmiau.ddns.net/AI/telegram-codex-bot/media/branch/master/docs/02-create.png)
**③ PM2 分頁** — 整台機器所有 pm2 程序。Port 可直接點開對應網頁,右側可啟停/重啟/刪除任何程序。
![PM2 分頁](https://git.catan.com.tw/Frontend/telegram-codex-bot/media/branch/master/docs/03-pm2.png)
![PM2 分頁](https://jianmiau.ddns.net/AI/telegram-codex-bot/media/branch/master/docs/03-pm2.png)
**④ Log 檢視** — 點任一程序的「📄 out」/「⚠ err」,下方展開尾端 200 行,可勾自動更新(5s)。
![Log 檢視](https://git.catan.com.tw/Frontend/telegram-codex-bot/media/branch/master/docs/04-log.png)
![Log 檢視](https://jianmiau.ddns.net/AI/telegram-codex-bot/media/branch/master/docs/04-log.png)
- 兩個分頁每 5 秒自動更新
- Bot 設定存於 `~/.tgcodex/bots/<名稱>/tgcodex.config.json`,bot 掛 pm2 的程序名 = bot 名稱
+3 -3
View File
@@ -1,15 +1,15 @@
{
"name": "telegram-codex-bot",
"version": "0.1.2",
"version": "0.1.5",
"description": "Telegram bot powered by the local Codex CLI — zero-dependency, pm2-managed, with a built-in PM2 web viewer",
"license": "MIT",
"type": "commonjs",
"publishConfig": {
"registry": "https://git.catan.com.tw/api/packages/Frontend/npm/"
"registry": "https://jianmiau.ddns.net/api/packages/AI/npm/"
},
"repository": {
"type": "git",
"url": "git@git.catan.com.tw:Frontend/telegram-codex-bot.git"
"url": "ssh://git@jianmiau.ddns.net:8022/AI/telegram-codex-bot.git"
},
"main": "src/index.js",
"bin": {
+11 -3
View File
@@ -224,13 +224,21 @@ function startBot(config) {
const existing = sessions.get(chatId);
let result;
let sessionResetNote = '';
try {
result = await runCodex({ config, prompt, threadId: existing?.threadId || null, images, onProgress });
} catch (err) {
// 舊會話可能已被 codex 清掉,找不到就自動開新會話重試一次
if (existing && /session|thread|conversation/i.test(err.message) && /not.*found|找不到|no .*(session|thread)/i.test(err.message)) {
// 舊會話 resume 不了的情況,自動開新會話重試一次
// 1) 會話已被 codex 清掉(not found
// 2) bot 換了模型,codex 拒絕跨模型 resumerecorded with model X but resuming with Y
const sessionGone = /session|thread|conversation/i.test(err.message) && /not.*found|找不到|no .*(session|thread)/i.test(err.message);
const modelMismatch = /recorded with model/i.test(err.message);
if (existing && (sessionGone || modelMismatch)) {
sessions.clear(chatId);
result = await runCodex({ config, prompt, threadId: null, images, onProgress });
sessionResetNote = modelMismatch
? '🆕 模型設定已變更,舊會話無法沿用,已自動開新會話(先前的對話記憶未帶入)。\n\n'
: '🆕 舊會話已失效,已自動開新會話。\n\n';
} else {
throw err;
}
@@ -239,7 +247,7 @@ function startBot(config) {
if (result.threadId) sessions.set(chatId, result.threadId);
const footer = buildFooter(config, result.usage, modelMeta, codexDefaults);
const html = t.mdToTgHtml((result.text || 'Codex 沒有回覆文字)') + footer);
const html = t.mdToTgHtml(sessionResetNote + (result.text || 'Codex 沒有回覆文字)') + footer);
await t.editOrSplit(chatId, statusMsg.message_id, html, { html: true });
await t.react(chatId, message.message_id, '👍');
} catch (error) {