Skip to content

Instantly share code, notes, and snippets.

@NyaMisty
Last active July 19, 2025 09:36
Show Gist options
  • Save NyaMisty/850f6b126d7425a71a1d4d35f29a094a to your computer and use it in GitHub Desktop.
Save NyaMisty/850f6b126d7425a71a1d4d35f29a094a to your computer and use it in GitHub Desktop.
Make Trae automatically "continue"
// tested on Trae v2.0.1 20250719
// Trae 全自动继续 (Trae Full Auto)
// will only continues ("继续") if it detects "模型思考次数已达上限"
// paste the code in Trae's developer tool console
window.$ = $
clearInterval(window.autoContinue)
window.autoContinue = setInterval(function() {
var continueText = '继续'
var lastMsg = $('#mc-agent-content-container > div > div > div:last-child > section > div.agent-error-wrap')
if (lastMsg && lastMsg.innerText.startsWith('模型思考次数已达上限') || lastMsg.innerText.startsWith('输出过长') || lastMsg.innerText.startsWith('模型响应超时')) {
console.log('not finished, need more!')
let editor = $('div.chat-input-v2-input-box-editable')
editor.focus()
let evt = new InputEvent('input', { inputType: 'insertText', data: continueText, isComposing: false, bubbles: true, cancelable: false })
editor.dispatchEvent(evt)
var button = $('div.chat-input-v2-editor-part-lower__right > button.chat-input-v2-send-button')
setTimeout(function() {
button.click()
}, 300)
} else {
//console.log('finished!')
}
}, 5000)
@NyaMisty
Copy link
Author

修复trae历史记录过长导致的oom oom

在trae的index.js搜索所有的e.messages引用可以找到两处增加数据的地方,一处是

e.addTurn = function(e, t) {
    var n, r = this.getLatestTurn(e);
    return r ? t.turnIndex = (null !== (n = r.turnIndex) && void 0 !== n ? n : e.messages.length - 1) + 1 : t.turnIndex = e.messages.length,
    e.messages.push(t),
    t
}

另一处通过messages.{0,4}concat正则搜索可以找到在r.appendToSession中

image

下断点在e.addTurn之后,在devtool中按Ctrl-R,等到断点断下后,执行替换掉addTurn

let ori_addTurn = e.addTurn
e.addTurn = function (e, t) {
    console.log("[mistypatch] cur session: ", e)
    var MAXLEN = 80 - 1; 
    if (e.messages.length > MAXLEN) {
        console.log("[mistypatch] dropping old messages: ", e)
        e.messages = e.messages.slice(-MAXLEN);
    } 
    return ori_addTurn.apply(this, arguments); 
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment