charness 4.4.0 → 4.4.1
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/CHANGELOG.md +19 -0
- package/DEVELOPMENT.md +3 -1
- package/README.md +1 -0
- package/agent-plugin/README.md +6 -5
- package/agent-plugin/skills/charness-delegate-opencode/SKILL.md +4 -1
- package/agent-plugin/skills/charness-delivery-loop/SKILL.md +9 -9
- package/agent-plugin/skills/charness-orchestration/SKILL.md +6 -2
- package/dist/adapters/adapterEventRouting.d.ts +2 -1
- package/dist/adapters/adapterEventRouting.d.ts.map +1 -1
- package/dist/adapters/adapterEventRouting.js +3 -0
- package/dist/adapters/adapterEventRouting.js.map +1 -1
- package/dist/adapters/claudeCliAdapter.d.ts.map +1 -1
- package/dist/adapters/claudeCliAdapter.js +11 -6
- package/dist/adapters/claudeCliAdapter.js.map +1 -1
- package/dist/adapters/claudeJsonStreamAdapter.d.ts +11 -3
- package/dist/adapters/claudeJsonStreamAdapter.d.ts.map +1 -1
- package/dist/adapters/claudeJsonStreamAdapter.js +48 -16
- package/dist/adapters/claudeJsonStreamAdapter.js.map +1 -1
- package/dist/adapters/createAdapter.d.ts +1 -0
- package/dist/adapters/createAdapter.d.ts.map +1 -1
- package/dist/adapters/createAdapter.js +4 -0
- package/dist/adapters/createAdapter.js.map +1 -1
- package/dist/adapters/openCodeAdapter.d.ts +68 -11
- package/dist/adapters/openCodeAdapter.d.ts.map +1 -1
- package/dist/adapters/openCodeAdapter.js +194 -70
- package/dist/adapters/openCodeAdapter.js.map +1 -1
- package/dist/adapters/terminalAdapter.js +1 -1
- package/dist/adapters/terminalAdapter.js.map +1 -1
- package/dist/bot.d.ts.map +1 -1
- package/dist/bot.js +70 -70
- package/dist/bot.js.map +1 -1
- package/dist/botFileStorage.d.ts.map +1 -1
- package/dist/botFileStorage.js +6 -5
- package/dist/botFileStorage.js.map +1 -1
- package/dist/cli/bot.d.ts +2 -1
- package/dist/cli/bot.d.ts.map +1 -1
- package/dist/cli/bot.js +14 -10
- package/dist/cli/bot.js.map +1 -1
- package/dist/cli/claudeProfiles.d.ts.map +1 -1
- package/dist/cli/claudeProfiles.js +36 -1
- package/dist/cli/claudeProfiles.js.map +1 -1
- package/dist/cli/hot.d.ts +3 -0
- package/dist/cli/hot.d.ts.map +1 -1
- package/dist/cli/hot.js +32 -3
- package/dist/cli/hot.js.map +1 -1
- package/dist/configDirFile.d.ts +23 -5
- package/dist/configDirFile.d.ts.map +1 -1
- package/dist/configDirFile.js +59 -19
- package/dist/configDirFile.js.map +1 -1
- package/dist/configDirectory.d.ts +9 -0
- package/dist/configDirectory.d.ts.map +1 -0
- package/dist/configDirectory.js +57 -0
- package/dist/configDirectory.js.map +1 -0
- package/dist/connectors/jira/agentBinaries.d.ts.map +1 -1
- package/dist/connectors/jira/agentBinaries.js +7 -6
- package/dist/connectors/jira/agentBinaries.js.map +1 -1
- package/dist/connectors/jira/attachmentDownload.d.ts.map +1 -1
- package/dist/connectors/jira/attachmentDownload.js +3 -3
- package/dist/connectors/jira/attachmentDownload.js.map +1 -1
- package/dist/connectors/jira/attachmentTool.d.ts.map +1 -1
- package/dist/connectors/jira/attachmentTool.js +4 -3
- package/dist/connectors/jira/attachmentTool.js.map +1 -1
- package/dist/connectors/jira/contextLedger.d.ts.map +1 -1
- package/dist/connectors/jira/contextLedger.js +5 -4
- package/dist/connectors/jira/contextLedger.js.map +1 -1
- package/dist/connectors/jira/promptSpill.d.ts.map +1 -1
- package/dist/connectors/jira/promptSpill.js +5 -5
- package/dist/connectors/jira/promptSpill.js.map +1 -1
- package/dist/dataDirFs.d.ts +95 -0
- package/dist/dataDirFs.d.ts.map +1 -0
- package/dist/dataDirFs.js +348 -0
- package/dist/dataDirFs.js.map +1 -0
- package/dist/diagLog.d.ts.map +1 -1
- package/dist/diagLog.js +7 -3
- package/dist/diagLog.js.map +1 -1
- package/dist/installManager.d.ts +2 -2
- package/dist/installManager.d.ts.map +1 -1
- package/dist/installManager.js +53 -64
- package/dist/installManager.js.map +1 -1
- package/dist/instanceLock.d.ts +95 -0
- package/dist/instanceLock.d.ts.map +1 -1
- package/dist/instanceLock.js +293 -28
- package/dist/instanceLock.js.map +1 -1
- package/dist/instanceSettings.d.ts +4 -1
- package/dist/instanceSettings.d.ts.map +1 -1
- package/dist/instanceSettings.js +5 -1
- package/dist/instanceSettings.js.map +1 -1
- package/dist/legacyNames.d.ts +11 -0
- package/dist/legacyNames.d.ts.map +1 -1
- package/dist/legacyNames.js +12 -1
- package/dist/legacyNames.js.map +1 -1
- package/dist/mcpConfig.d.ts.map +1 -1
- package/dist/mcpConfig.js +10 -9
- package/dist/mcpConfig.js.map +1 -1
- package/dist/outputTrace.d.ts.map +1 -1
- package/dist/outputTrace.js +12 -6
- package/dist/outputTrace.js.map +1 -1
- package/dist/processIdentity.d.ts +18 -0
- package/dist/processIdentity.d.ts.map +1 -0
- package/dist/processIdentity.js +136 -0
- package/dist/processIdentity.js.map +1 -0
- package/dist/remoteRun/commands.d.ts.map +1 -1
- package/dist/remoteRun/commands.js +4 -4
- package/dist/remoteRun/commands.js.map +1 -1
- package/dist/remoteRun/heldBackNotice.d.ts.map +1 -1
- package/dist/remoteRun/heldBackNotice.js +4 -3
- package/dist/remoteRun/heldBackNotice.js.map +1 -1
- package/dist/remoteRun/jobFiles.d.ts.map +1 -1
- package/dist/remoteRun/jobFiles.js +3 -2
- package/dist/remoteRun/jobFiles.js.map +1 -1
- package/dist/remoteRun/jobRecords.d.ts.map +1 -1
- package/dist/remoteRun/jobRecords.js +4 -3
- package/dist/remoteRun/jobRecords.js.map +1 -1
- package/dist/remoteRun/runners.d.ts.map +1 -1
- package/dist/remoteRun/runners.js +5 -4
- package/dist/remoteRun/runners.js.map +1 -1
- package/dist/remoteRun/safeCopy.d.ts.map +1 -1
- package/dist/remoteRun/safeCopy.js +5 -4
- package/dist/remoteRun/safeCopy.js.map +1 -1
- package/dist/remoteRun/ssh.d.ts.map +1 -1
- package/dist/remoteRun/ssh.js +4 -4
- package/dist/remoteRun/ssh.js.map +1 -1
- package/dist/remoteRun/submit.d.ts.map +1 -1
- package/dist/remoteRun/submit.js +2 -1
- package/dist/remoteRun/submit.js.map +1 -1
- package/dist/requests/wakeUpEngine.d.ts +8 -0
- package/dist/requests/wakeUpEngine.d.ts.map +1 -1
- package/dist/requests/wakeUpEngine.js +19 -2
- package/dist/requests/wakeUpEngine.js.map +1 -1
- package/dist/runnerUtility/appInstall.d.ts.map +1 -1
- package/dist/runnerUtility/appInstall.js +11 -10
- package/dist/runnerUtility/appInstall.js.map +1 -1
- package/dist/runnerUtility/appUpdate.d.ts.map +1 -1
- package/dist/runnerUtility/appUpdate.js +3 -3
- package/dist/runnerUtility/appUpdate.js.map +1 -1
- package/dist/runnerUtility/execEnv.d.ts +0 -5
- package/dist/runnerUtility/execEnv.d.ts.map +1 -1
- package/dist/runnerUtility/execEnv.js +2 -24
- package/dist/runnerUtility/execEnv.js.map +1 -1
- package/dist/runnerUtility/guiAgent.d.ts.map +1 -1
- package/dist/runnerUtility/guiAgent.js +12 -11
- package/dist/runnerUtility/guiAgent.js.map +1 -1
- package/dist/runnerUtility/guiAgentHeal.d.ts.map +1 -1
- package/dist/runnerUtility/guiAgentHeal.js +4 -3
- package/dist/runnerUtility/guiAgentHeal.js.map +1 -1
- package/dist/runnerUtility/iosCheck.d.ts.map +1 -1
- package/dist/runnerUtility/iosCheck.js +2 -1
- package/dist/runnerUtility/iosCheck.js.map +1 -1
- package/dist/runnerUtility/keepAwake.d.ts.map +1 -1
- package/dist/runnerUtility/keepAwake.js +2 -1
- package/dist/runnerUtility/keepAwake.js.map +1 -1
- package/dist/runnerUtility/launcher.d.ts.map +1 -1
- package/dist/runnerUtility/launcher.js +2 -1
- package/dist/runnerUtility/launcher.js.map +1 -1
- package/dist/runnerUtility/nodeUpkeep.d.ts.map +1 -1
- package/dist/runnerUtility/nodeUpkeep.js +4 -3
- package/dist/runnerUtility/nodeUpkeep.js.map +1 -1
- package/dist/runnerUtility/packageManagerShims.d.ts.map +1 -1
- package/dist/runnerUtility/packageManagerShims.js +5 -4
- package/dist/runnerUtility/packageManagerShims.js.map +1 -1
- package/dist/runnerUtility/pueueDaemon.d.ts.map +1 -1
- package/dist/runnerUtility/pueueDaemon.js +3 -2
- package/dist/runnerUtility/pueueDaemon.js.map +1 -1
- package/dist/runnerUtility/runnerCli.js +2 -1
- package/dist/runnerUtility/runnerCli.js.map +1 -1
- package/dist/runnerUtility/runnerCommands.d.ts.map +1 -1
- package/dist/runnerUtility/runnerCommands.js +6 -5
- package/dist/runnerUtility/runnerCommands.js.map +1 -1
- package/dist/runnerUtility/runnerConfig.d.ts.map +1 -1
- package/dist/runnerUtility/runnerConfig.js +2 -1
- package/dist/runnerUtility/runnerConfig.js.map +1 -1
- package/dist/runnerUtility/runnerFlags.d.ts.map +1 -1
- package/dist/runnerUtility/runnerFlags.js +3 -2
- package/dist/runnerUtility/runnerFlags.js.map +1 -1
- package/dist/runnerUtility/runnerKeys.d.ts.map +1 -1
- package/dist/runnerUtility/runnerKeys.js +2 -1
- package/dist/runnerUtility/runnerKeys.js.map +1 -1
- package/dist/runnerUtility/serviceManager.d.ts.map +1 -1
- package/dist/runnerUtility/serviceManager.js +15 -14
- package/dist/runnerUtility/serviceManager.js.map +1 -1
- package/dist/runnerUtility/simctlGuard.d.ts.map +1 -1
- package/dist/runnerUtility/simctlGuard.js +3 -2
- package/dist/runnerUtility/simctlGuard.js.map +1 -1
- package/dist/runnerUtility/toolInstall.d.ts.map +1 -1
- package/dist/runnerUtility/toolInstall.js +11 -10
- package/dist/runnerUtility/toolInstall.js.map +1 -1
- package/dist/runners/authorizedKeys.d.ts.map +1 -1
- package/dist/runners/authorizedKeys.js +2 -1
- package/dist/runners/authorizedKeys.js.map +1 -1
- package/dist/runners/gateLink.d.ts.map +1 -1
- package/dist/runners/gateLink.js +4 -3
- package/dist/runners/gateLink.js.map +1 -1
- package/dist/runners/hubLock.d.ts.map +1 -1
- package/dist/runners/hubLock.js +9 -8
- package/dist/runners/hubLock.js.map +1 -1
- package/dist/runners/hubPackage.d.ts.map +1 -1
- package/dist/runners/hubPackage.js +5 -4
- package/dist/runners/hubPackage.js.map +1 -1
- package/dist/runners/linkControl.d.ts.map +1 -1
- package/dist/runners/linkControl.js +7 -6
- package/dist/runners/linkControl.js.map +1 -1
- package/dist/scheduler/injection.d.ts +5 -3
- package/dist/scheduler/injection.d.ts.map +1 -1
- package/dist/scheduler/injection.js +15 -4
- package/dist/scheduler/injection.js.map +1 -1
- package/dist/scheduler/mcpSurface.d.ts.map +1 -1
- package/dist/scheduler/mcpSurface.js +16 -12
- package/dist/scheduler/mcpSurface.js.map +1 -1
- package/dist/selfUpdate/gitSource.d.ts.map +1 -1
- package/dist/selfUpdate/gitSource.js +2 -2
- package/dist/selfUpdate/gitSource.js.map +1 -1
- package/dist/selfUpdate/hostLock.d.ts.map +1 -1
- package/dist/selfUpdate/hostLock.js +4 -3
- package/dist/selfUpdate/hostLock.js.map +1 -1
- package/dist/selfUpdate/restart.d.ts +8 -0
- package/dist/selfUpdate/restart.d.ts.map +1 -1
- package/dist/selfUpdate/restart.js +10 -0
- package/dist/selfUpdate/restart.js.map +1 -1
- package/dist/selfUpdate/selfCheck.d.ts.map +1 -1
- package/dist/selfUpdate/selfCheck.js +3 -2
- package/dist/selfUpdate/selfCheck.js.map +1 -1
- package/dist/selfUpdate/updatePending.d.ts.map +1 -1
- package/dist/selfUpdate/updatePending.js +2 -1
- package/dist/selfUpdate/updatePending.js.map +1 -1
- package/dist/state.d.ts +10 -4
- package/dist/state.d.ts.map +1 -1
- package/dist/state.js +38 -20
- package/dist/state.js.map +1 -1
- package/dist/stt/sttAutoInstall.d.ts.map +1 -1
- package/dist/stt/sttAutoInstall.js +9 -2
- package/dist/stt/sttAutoInstall.js.map +1 -1
- package/dist/stt/sttInstall.d.ts.map +1 -1
- package/dist/stt/sttInstall.js +18 -17
- package/dist/stt/sttInstall.js.map +1 -1
- package/dist/stt/sttInstallEntry.js +12 -2
- package/dist/stt/sttInstallEntry.js.map +1 -1
- package/dist/stt/sttSettings.d.ts.map +1 -1
- package/dist/stt/sttSettings.js +6 -2
- package/dist/stt/sttSettings.js.map +1 -1
- package/dist/stt/sttSidecarOwner.d.ts +0 -3
- package/dist/stt/sttSidecarOwner.d.ts.map +1 -1
- package/dist/stt/sttSidecarOwner.js +11 -12
- package/dist/stt/sttSidecarOwner.js.map +1 -1
- package/dist/todos/projects.d.ts.map +1 -1
- package/dist/todos/projects.js +2 -1
- package/dist/todos/projects.js.map +1 -1
- package/dist/todos/store.d.ts.map +1 -1
- package/dist/todos/store.js +5 -4
- package/dist/todos/store.js.map +1 -1
- package/dist/types.d.ts +8 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/agentEnvironment.d.ts +19 -8
- package/dist/utils/agentEnvironment.d.ts.map +1 -1
- package/dist/utils/agentEnvironment.js +32 -12
- package/dist/utils/agentEnvironment.js.map +1 -1
- package/dist/utils/agentPlugin.d.ts +2 -0
- package/dist/utils/agentPlugin.d.ts.map +1 -1
- package/dist/utils/agentPlugin.js +8 -6
- package/dist/utils/agentPlugin.js.map +1 -1
- package/dist/utils/claudeApiCredit.d.ts.map +1 -1
- package/dist/utils/claudeApiCredit.js +4 -1
- package/dist/utils/claudeApiCredit.js.map +1 -1
- package/dist/utils/claudeCompactHook.js +5 -5
- package/dist/utils/claudeCompactHook.js.map +1 -1
- package/dist/utils/claudeProfiles.d.ts +9 -0
- package/dist/utils/claudeProfiles.d.ts.map +1 -1
- package/dist/utils/claudeProfiles.js +19 -17
- package/dist/utils/claudeProfiles.js.map +1 -1
- package/dist/utils/claudeStreamJson.d.ts +1 -0
- package/dist/utils/claudeStreamJson.d.ts.map +1 -1
- package/dist/utils/claudeStreamJson.js +2 -1
- package/dist/utils/claudeStreamJson.js.map +1 -1
- package/dist/utils/claudeTranscriptContent.d.ts.map +1 -1
- package/dist/utils/claudeTranscriptContent.js +2 -1
- package/dist/utils/claudeTranscriptContent.js.map +1 -1
- package/dist/utils/compactSelfReviewFlags.d.ts.map +1 -1
- package/dist/utils/compactSelfReviewFlags.js +5 -4
- package/dist/utils/compactSelfReviewFlags.js.map +1 -1
- package/dist/utils/consoleFileTap.d.ts +11 -5
- package/dist/utils/consoleFileTap.d.ts.map +1 -1
- package/dist/utils/consoleFileTap.js +55 -18
- package/dist/utils/consoleFileTap.js.map +1 -1
- package/dist/utils/download.d.ts.map +1 -1
- package/dist/utils/download.js +3 -4
- package/dist/utils/download.js.map +1 -1
- package/dist/utils/fileSendService.js +6 -4
- package/dist/utils/fileSendService.js.map +1 -1
- package/dist/utils/jsonStreamHost.d.ts +1 -1
- package/dist/utils/jsonStreamHost.d.ts.map +1 -1
- package/dist/utils/jsonStreamHost.js +6 -5
- package/dist/utils/jsonStreamHost.js.map +1 -1
- package/dist/utils/jsonStreamUnconsumedInput.d.ts +2 -0
- package/dist/utils/jsonStreamUnconsumedInput.d.ts.map +1 -1
- package/dist/utils/jsonStreamUnconsumedInput.js.map +1 -1
- package/dist/utils/midTurnAnswerWatch.d.ts +69 -0
- package/dist/utils/midTurnAnswerWatch.d.ts.map +1 -0
- package/dist/utils/midTurnAnswerWatch.js +87 -0
- package/dist/utils/midTurnAnswerWatch.js.map +1 -0
- package/dist/utils/midTurnInbox.d.ts.map +1 -1
- package/dist/utils/midTurnInbox.js +9 -8
- package/dist/utils/midTurnInbox.js.map +1 -1
- package/dist/utils/openCodeCompactPlugin.d.ts +6 -0
- package/dist/utils/openCodeCompactPlugin.d.ts.map +1 -1
- package/dist/utils/openCodeCompactPlugin.js +46 -7
- package/dist/utils/openCodeCompactPlugin.js.map +1 -1
- package/dist/utils/openCodeMessageId.d.ts +16 -0
- package/dist/utils/openCodeMessageId.d.ts.map +1 -0
- package/dist/utils/openCodeMessageId.js +51 -0
- package/dist/utils/openCodeMessageId.js.map +1 -0
- package/dist/utils/parseEnvFile.d.ts +11 -0
- package/dist/utils/parseEnvFile.d.ts.map +1 -0
- package/dist/utils/parseEnvFile.js +31 -0
- package/dist/utils/parseEnvFile.js.map +1 -0
- package/dist/utils/promptDelivery.d.ts +37 -1
- package/dist/utils/promptDelivery.d.ts.map +1 -1
- package/dist/utils/promptDelivery.js +52 -0
- package/dist/utils/promptDelivery.js.map +1 -1
- package/dist/utils/rotatingJsonlFile.d.ts.map +1 -1
- package/dist/utils/rotatingJsonlFile.js +4 -3
- package/dist/utils/rotatingJsonlFile.js.map +1 -1
- package/dist/utils/rotatingLogFile.d.ts.map +1 -1
- package/dist/utils/rotatingLogFile.js +2 -1
- package/dist/utils/rotatingLogFile.js.map +1 -1
- package/dist/utils/tmuxExec.d.ts +6 -6
- package/dist/utils/tmuxExec.d.ts.map +1 -1
- package/dist/utils/tmuxExec.js +9 -9
- package/dist/utils/tmuxExec.js.map +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
|
@@ -80,6 +80,8 @@ const resumeContext_1 = require("../resumeContext");
|
|
|
80
80
|
const threadContextPreamble_1 = require("../threadContextPreamble");
|
|
81
81
|
const openCodeOpenQuestion_1 = require("../openCodeOpenQuestion");
|
|
82
82
|
const injection_1 = require("../scheduler/injection");
|
|
83
|
+
const midTurnAnswerWatch_1 = require("../utils/midTurnAnswerWatch");
|
|
84
|
+
const openCodeMessageId_1 = require("../utils/openCodeMessageId");
|
|
83
85
|
const legacyNames_1 = require("../legacyNames");
|
|
84
86
|
const checkIsRecord_1 = require("../utils/checkIsRecord");
|
|
85
87
|
const openCodeSessionTitle_1 = require("../openCodeSessionTitle");
|
|
@@ -93,6 +95,7 @@ const openCodeCompactPlugin_1 = require("../utils/openCodeCompactPlugin");
|
|
|
93
95
|
const agentPlugin_1 = require("../utils/agentPlugin");
|
|
94
96
|
const botSkills_1 = require("../utils/botSkills");
|
|
95
97
|
const openCodeAuthLogin_1 = require("../utils/openCodeAuthLogin");
|
|
98
|
+
const dataDirFs_1 = require("../dataDirFs");
|
|
96
99
|
const execFileAsync = (0, util_1.promisify)(child_process_1.execFile);
|
|
97
100
|
/**
|
|
98
101
|
* Persist per-thread model selection so it survives bot restarts.
|
|
@@ -129,10 +132,10 @@ function loadSavedModel(key) {
|
|
|
129
132
|
// save can start clean; previous silent return left users wondering
|
|
130
133
|
// why /model selections didn't stick across restarts.
|
|
131
134
|
console.error(`[OpenCode] loadSavedModel failed:`, e instanceof Error ? e.message : e);
|
|
132
|
-
if (fs.existsSync(modelStateFile)) {
|
|
135
|
+
if (fs.existsSync(modelStateFile) && (0, dataDirFs_1.checkMayWriteAt)(modelStateFile)) {
|
|
133
136
|
const ts = new Date().toISOString().replace(/[:.]/g, '-');
|
|
134
137
|
try {
|
|
135
|
-
|
|
138
|
+
dataDirFs_1.dataDirFs.renameSync(modelStateFile, `${modelStateFile}.corrupted-${ts}`);
|
|
136
139
|
}
|
|
137
140
|
catch (re) {
|
|
138
141
|
console.warn(`[OpenCode] archive of corrupt prefs failed:`, re);
|
|
@@ -170,7 +173,9 @@ function saveModelPref(key, label) {
|
|
|
170
173
|
data = JSON.parse(fs.readFileSync(modelStateFile, 'utf-8'));
|
|
171
174
|
}
|
|
172
175
|
data[(0, sessionKey_1.keyToString)(key)] = label;
|
|
173
|
-
|
|
176
|
+
if (!(0, dataDirFs_1.checkMayWriteAt)(modelStateFile))
|
|
177
|
+
return;
|
|
178
|
+
dataDirFs_1.dataDirFs.writeFileSync(modelStateFile, JSON.stringify(data, null, 2));
|
|
174
179
|
}
|
|
175
180
|
catch (e) {
|
|
176
181
|
console.error(`[OpenCode] Failed to save model pref:`, e instanceof Error ? e.message : e);
|
|
@@ -199,10 +204,10 @@ function loadEffortPrefs() {
|
|
|
199
204
|
}
|
|
200
205
|
catch (e) {
|
|
201
206
|
console.error(`[OpenCode] loadEffortPrefs failed:`, e instanceof Error ? e.message : e);
|
|
202
|
-
if (fs.existsSync(effortStateFile)) {
|
|
207
|
+
if (fs.existsSync(effortStateFile) && (0, dataDirFs_1.checkMayWriteAt)(effortStateFile)) {
|
|
203
208
|
const ts = new Date().toISOString().replace(/[:.]/g, '-');
|
|
204
209
|
try {
|
|
205
|
-
|
|
210
|
+
dataDirFs_1.dataDirFs.renameSync(effortStateFile, `${effortStateFile}.corrupted-${ts}`);
|
|
206
211
|
}
|
|
207
212
|
catch (re) {
|
|
208
213
|
console.warn(`[OpenCode] archive of corrupt effort prefs failed:`, re);
|
|
@@ -219,7 +224,9 @@ function saveEffortPref(key, level) {
|
|
|
219
224
|
try {
|
|
220
225
|
const data = loadEffortPrefs();
|
|
221
226
|
data[(0, sessionKey_1.keyToString)(key)] = level;
|
|
222
|
-
|
|
227
|
+
if (!(0, dataDirFs_1.checkMayWriteAt)(effortStateFile))
|
|
228
|
+
return;
|
|
229
|
+
dataDirFs_1.dataDirFs.writeFileSync(effortStateFile, JSON.stringify(data, null, 2));
|
|
223
230
|
}
|
|
224
231
|
catch (e) {
|
|
225
232
|
console.error(`[OpenCode] Failed to save effort pref:`, e instanceof Error ? e.message : e);
|
|
@@ -231,14 +238,16 @@ function clearEffortPref(key) {
|
|
|
231
238
|
if (!((0, sessionKey_1.keyToString)(key) in data))
|
|
232
239
|
return;
|
|
233
240
|
delete data[(0, sessionKey_1.keyToString)(key)];
|
|
234
|
-
|
|
241
|
+
if (!(0, dataDirFs_1.checkMayWriteAt)(effortStateFile))
|
|
242
|
+
return;
|
|
243
|
+
dataDirFs_1.dataDirFs.writeFileSync(effortStateFile, JSON.stringify(data, null, 2));
|
|
235
244
|
}
|
|
236
245
|
catch (e) {
|
|
237
246
|
console.error(`[OpenCode] Failed to clear effort pref:`, e instanceof Error ? e.message : e);
|
|
238
247
|
}
|
|
239
248
|
}
|
|
240
|
-
/** How many recent
|
|
241
|
-
const
|
|
249
|
+
/** How many recent message ids a session remembers: the user messages it counted, and the `parentID` of each own step. */
|
|
250
|
+
const recentMessageIdsMax = 100;
|
|
242
251
|
/**
|
|
243
252
|
* OpenCode `/global/event` wraps the real event in `payload`, while `/event`
|
|
244
253
|
* emits it directly. Normalise both shapes before dispatching.
|
|
@@ -866,12 +875,14 @@ const providerIdRe = /^[a-z0-9][a-z0-9._-]*$/;
|
|
|
866
875
|
* `variant` — can be unit-tested without a live session. Both are optional and
|
|
867
876
|
* ride the same body, parallel to each other.
|
|
868
877
|
*
|
|
869
|
-
* @returns Body with `parts` always present
|
|
870
|
-
*
|
|
878
|
+
* @returns Body with `parts` and `messageID` always present — the bot names every user message it posts
|
|
879
|
+
* (`utils/openCodeMessageId.ts`), so a body cannot be built without one; `model` only when a model override is set; `variant`
|
|
880
|
+
* only when an effort level is set.
|
|
871
881
|
*/
|
|
872
|
-
function buildPromptBody(input, modelOverride, effortLevel) {
|
|
882
|
+
function buildPromptBody(input, modelOverride, effortLevel, messageId) {
|
|
873
883
|
const body = {
|
|
874
884
|
parts: [{ type: 'text', text: input }],
|
|
885
|
+
messageID: messageId,
|
|
875
886
|
};
|
|
876
887
|
if (modelOverride) {
|
|
877
888
|
const modelParam = { modelID: modelOverride.modelID };
|
|
@@ -1801,6 +1812,12 @@ class OpenCodeAdapter extends events_1.EventEmitter {
|
|
|
1801
1812
|
isBusy: false,
|
|
1802
1813
|
awaitingTurnResponse: false,
|
|
1803
1814
|
sawTurnActivity: false,
|
|
1815
|
+
midTurnAnswerWatch: (0, midTurnAnswerWatch_1.createIdleMidTurnAnswerWatch)(),
|
|
1816
|
+
isAbortIdlePending: false,
|
|
1817
|
+
midTurnWatchedMessageId: null,
|
|
1818
|
+
newestMessageId: null,
|
|
1819
|
+
newestAnswerParentId: null,
|
|
1820
|
+
assistantMessageParentIds: new Map(),
|
|
1804
1821
|
handledTurnErrorTexts: new Set(),
|
|
1805
1822
|
unconsumedInputCount: 0,
|
|
1806
1823
|
seenUserMessageIds: new Set(),
|
|
@@ -1915,13 +1932,23 @@ class OpenCodeAdapter extends events_1.EventEmitter {
|
|
|
1915
1932
|
const session = this.sessions.get((0, sessionKey_1.keyToString)(key));
|
|
1916
1933
|
if (!session)
|
|
1917
1934
|
return;
|
|
1918
|
-
// The batch window ending early: the same emit its timer makes
|
|
1919
|
-
if (session.outputTimer) {
|
|
1920
|
-
clearTimeout(session.outputTimer);
|
|
1921
|
-
session.outputTimer = null;
|
|
1922
|
-
}
|
|
1935
|
+
// The batch window ending early: the same emit its timer makes (the emit clears the timer).
|
|
1923
1936
|
this.emitResponseTail(key, session);
|
|
1924
1937
|
}
|
|
1938
|
+
/** @description Whether a step announced in this session read the watched mid-turn message (its `parentID` is that id or a later one). */
|
|
1939
|
+
checkIsWatchedMessageRead(session) {
|
|
1940
|
+
return [...session.assistantMessageParentIds.values()].some((parentId) => (0, midTurnAnswerWatch_1.checkIsParentAtOrAfterWatchedMessage)(parentId, session.midTurnWatchedMessageId));
|
|
1941
|
+
}
|
|
1942
|
+
/**
|
|
1943
|
+
* @description End the batch windows early: send the sub-agent's text that is waiting in its window first (it streamed earlier than
|
|
1944
|
+
* the parent's closing text), then the agent's; each emit clears its own timer. Nothing is reset here; the caller decides: a post
|
|
1945
|
+
* into the running turn keeps the buffers, while a post that starts a turn and {@link flushOutput} reset them after it. `isFinal`
|
|
1946
|
+
* rides the turn's last flush.
|
|
1947
|
+
*/
|
|
1948
|
+
emitPendingResponseTails(key, session, isFinal = false) {
|
|
1949
|
+
this.emitChildResponseTail(key, session);
|
|
1950
|
+
this.emitResponseTail(key, session, isFinal);
|
|
1951
|
+
}
|
|
1925
1952
|
checkHasUnconsumedInput(key) {
|
|
1926
1953
|
return (this.sessions.get((0, sessionKey_1.keyToString)(key))?.unconsumedInputCount ?? 0) > 0;
|
|
1927
1954
|
}
|
|
@@ -1934,13 +1961,43 @@ class OpenCodeAdapter extends events_1.EventEmitter {
|
|
|
1934
1961
|
if (messageId === undefined || session.seenUserMessageIds.has(messageId))
|
|
1935
1962
|
return;
|
|
1936
1963
|
session.seenUserMessageIds.add(messageId);
|
|
1937
|
-
if (session.seenUserMessageIds.size >
|
|
1964
|
+
if (session.seenUserMessageIds.size > recentMessageIdsMax) {
|
|
1938
1965
|
const oldestId = session.seenUserMessageIds.values().next().value;
|
|
1939
1966
|
if (oldestId !== undefined)
|
|
1940
1967
|
session.seenUserMessageIds.delete(oldestId);
|
|
1941
1968
|
}
|
|
1942
1969
|
session.unconsumedInputCount = Math.max(0, session.unconsumedInputCount - 1);
|
|
1943
1970
|
}
|
|
1971
|
+
/** Remember which user message the own-session step `messageId` read (bounded: the oldest entry goes). */
|
|
1972
|
+
noteAssistantMessageParent(session, messageId, parentId) {
|
|
1973
|
+
session.assistantMessageParentIds.set(messageId, parentId);
|
|
1974
|
+
if (session.assistantMessageParentIds.size > recentMessageIdsMax) {
|
|
1975
|
+
const oldestId = session.assistantMessageParentIds.keys().next().value;
|
|
1976
|
+
if (oldestId !== undefined)
|
|
1977
|
+
session.assistantMessageParentIds.delete(oldestId);
|
|
1978
|
+
}
|
|
1979
|
+
}
|
|
1980
|
+
/**
|
|
1981
|
+
* A delivered answer (a send tool's or `answer_request`'s completed call) of the own-session step `stepMessageId`: remembered as
|
|
1982
|
+
* answered in this turn (by the step's `parentID`), and the answer of the watched message when that step read it or a later user message.
|
|
1983
|
+
*/
|
|
1984
|
+
noteDeliveredAnswerStep(session, stepMessageId) {
|
|
1985
|
+
const parentId = stepMessageId ? session.assistantMessageParentIds.get(stepMessageId) : undefined;
|
|
1986
|
+
if (parentId === undefined)
|
|
1987
|
+
return;
|
|
1988
|
+
if (session.newestAnswerParentId === null || parentId > session.newestAnswerParentId)
|
|
1989
|
+
session.newestAnswerParentId = parentId;
|
|
1990
|
+
if ((0, midTurnAnswerWatch_1.checkIsParentAtOrAfterWatchedMessage)(parentId, session.midTurnWatchedMessageId)) {
|
|
1991
|
+
session.midTurnAnswerWatch = (0, midTurnAnswerWatch_1.getWatchAfterDeliveredAnswer)(session.midTurnAnswerWatch);
|
|
1992
|
+
}
|
|
1993
|
+
}
|
|
1994
|
+
/** The newest own-session message id shown so far (ids ascend; an id of another shape says nothing about the order). */
|
|
1995
|
+
noteSessionMessageId(session, messageId) {
|
|
1996
|
+
if (!(0, openCodeMessageId_1.checkIsOpenCodeMessageId)(messageId))
|
|
1997
|
+
return;
|
|
1998
|
+
if (session.newestMessageId === null || messageId > session.newestMessageId)
|
|
1999
|
+
session.newestMessageId = messageId;
|
|
2000
|
+
}
|
|
1944
2001
|
checkIsBusy(key) {
|
|
1945
2002
|
const session = this.sessions.get((0, sessionKey_1.keyToString)(key));
|
|
1946
2003
|
if (!session?.isActive)
|
|
@@ -1951,16 +2008,25 @@ class OpenCodeAdapter extends events_1.EventEmitter {
|
|
|
1951
2008
|
busyChildCount: session.busyChildSessionIds.size,
|
|
1952
2009
|
});
|
|
1953
2010
|
}
|
|
1954
|
-
sendInput(key, input) {
|
|
1955
|
-
this.sendPromptAsync(key, input);
|
|
2011
|
+
sendInput(key, input, options = {}) {
|
|
2012
|
+
this.sendPromptAsync(key, input, options.isMidTurnAnswerWatched === true);
|
|
2013
|
+
}
|
|
2014
|
+
/**
|
|
2015
|
+
* @description The body of a prompt the bot posts into `session`, named by the bot: EVERY post goes through here, so the bot's posts
|
|
2016
|
+
* sort in the order it made them and never before the newest message the session has shown (`utils/openCodeMessageId.ts`).
|
|
2017
|
+
*/
|
|
2018
|
+
createSessionPromptBody(session, text) {
|
|
2019
|
+
const messageId = (0, openCodeMessageId_1.createOpenCodeMessageId)(session.newestMessageId);
|
|
2020
|
+
return { body: buildPromptBody(text, session.modelOverride, session.effortLevel, messageId), messageId };
|
|
1956
2021
|
}
|
|
1957
2022
|
/**
|
|
1958
2023
|
* @description A note into the RUNNING turn (`AgentAdapter.queueNoteIntoRunningTurn`): `prompt_async` queues it and
|
|
1959
|
-
* OpenCode reads it between steps. Unlike {@link sendPromptAsync} nothing of the turn is reset — the
|
|
1960
|
-
*
|
|
1961
|
-
*
|
|
1962
|
-
* before the retry, and {@link sendPromptAsync}'s path
|
|
1963
|
-
* is not busy. The prompt counts as unconsumed until
|
|
2024
|
+
* OpenCode reads it between steps. Unlike {@link sendPromptAsync} nothing of the turn is reset — the tool-result
|
|
2025
|
+
* and error dedup and the wedged-turn detector stay as they are (a prompt resets them; like a prompt into a running
|
|
2026
|
+
* turn, a note keeps the response accumulators, so the text being streamed goes on as one message). Refused while
|
|
2027
|
+
* the turn waits out a provider retry (posting would not be read before the retry, and {@link sendPromptAsync}'s path
|
|
2028
|
+
* would abort it), during a server restart, or when the session is not busy. The prompt counts as unconsumed until
|
|
2029
|
+
* OpenCode shows it as a user message, like any prompt.
|
|
1964
2030
|
*/
|
|
1965
2031
|
async queueNoteIntoRunningTurn(key, text) {
|
|
1966
2032
|
const session = this.sessions.get((0, sessionKey_1.keyToString)(key));
|
|
@@ -1970,7 +2036,8 @@ class OpenCodeAdapter extends events_1.EventEmitter {
|
|
|
1970
2036
|
return false;
|
|
1971
2037
|
session.unconsumedInputCount += 1;
|
|
1972
2038
|
try {
|
|
1973
|
-
|
|
2039
|
+
// Named like every post of the bot: a note sent just before a watched message sorts before it.
|
|
2040
|
+
await this.apiRequest('POST', `/session/${session.sessionId}/prompt_async`, this.createSessionPromptBody(session, text).body);
|
|
1974
2041
|
return true;
|
|
1975
2042
|
}
|
|
1976
2043
|
catch (e) {
|
|
@@ -1993,13 +2060,13 @@ class OpenCodeAdapter extends events_1.EventEmitter {
|
|
|
1993
2060
|
* — the same per-prompt override the prompt endpoint already uses for the
|
|
1994
2061
|
* model selector. No separate request, no env configuration.
|
|
1995
2062
|
*/
|
|
1996
|
-
sendPromptAsync(key, input) {
|
|
2063
|
+
sendPromptAsync(key, input, isMidTurnAnswerWatched = false) {
|
|
1997
2064
|
if (this.serverRestart) {
|
|
1998
2065
|
// Posted now, the prompt would hit the server that is down and be lost with
|
|
1999
2066
|
// a raw `fetch failed`; it goes out once the restart has restored the session.
|
|
2000
2067
|
// A restart that failed has stopped the session: the topic was told to send again.
|
|
2001
2068
|
console.log(`[OpenCode] holding a prompt for ${(0, sessionKey_1.keyToString)(key)} until the server restart ends`);
|
|
2002
|
-
void this.serverRestart.then(() => this.sendPromptAsync(key, input));
|
|
2069
|
+
void this.serverRestart.then(() => this.sendPromptAsync(key, input, isMidTurnAnswerWatched));
|
|
2003
2070
|
return;
|
|
2004
2071
|
}
|
|
2005
2072
|
const session = this.sessions.get((0, sessionKey_1.keyToString)(key));
|
|
@@ -2010,21 +2077,46 @@ class OpenCodeAdapter extends events_1.EventEmitter {
|
|
|
2010
2077
|
}
|
|
2011
2078
|
console.log(`[OpenCode] sendPromptAsync: "${input}"`);
|
|
2012
2079
|
session.unconsumedInputCount += 1;
|
|
2080
|
+
const isReplacingProviderRetry = session.providerRetrySignature !== null || session.providerRetryAbortPromise !== null;
|
|
2081
|
+
// Every prompt the bot posts is named by the bot (`postedMessageId`), so its posts sort in the order it made them whatever order the
|
|
2082
|
+
// server receives them in — an unnamed post sent just before a watched one would get a LATER id from the server. A watched message into
|
|
2083
|
+
// a running turn (not one that replaces a provider retry, which aborts that turn): only a step that READ it — whose `parentID` is its
|
|
2084
|
+
// id or a later one — can answer it, and no event is needed to learn which message that is. A post that fails puts the watch back.
|
|
2085
|
+
// Model + reasoning-effort overrides ride the prompt body (see buildPromptBody).
|
|
2086
|
+
const { body, messageId: postedMessageId } = this.createSessionPromptBody(session, input);
|
|
2087
|
+
// What the batch windows still hold is sent first, on EVERY post: the agent's text of a step in flight, and a sub-agent's, which
|
|
2088
|
+
// goes on streaming after the parent went idle (a backgrounded sub-agent). It is sent before the prompt goes out, before the
|
|
2089
|
+
// arm. On an idle session with nothing pending this sends nothing.
|
|
2090
|
+
this.emitPendingResponseTails(key, session);
|
|
2091
|
+
// A post into the RUNNING turn (not one that replaces a provider retry, which aborts it): the step in flight goes on, so the buffers
|
|
2092
|
+
// are kept. A post right after a bot-issued abort reads so too — it joins no running turn (`isAbortIdlePending`), but the abort's
|
|
2093
|
+
// idle flushes and resets the buffers anyway.
|
|
2094
|
+
const isPostIntoRunningTurn = session.isBusy && !isReplacingProviderRetry;
|
|
2095
|
+
const watchBeforePost = session.midTurnAnswerWatch;
|
|
2096
|
+
const watchedMessageIdBeforePost = session.midTurnWatchedMessageId;
|
|
2097
|
+
const isWatchedPost = isMidTurnAnswerWatched && isPostIntoRunningTurn && !session.isAbortIdlePending;
|
|
2098
|
+
const armedWatch = isWatchedPost ? (0, midTurnAnswerWatch_1.getWatchAfterMidTurnMessage)() : null;
|
|
2099
|
+
if (armedWatch !== null) {
|
|
2100
|
+
session.midTurnAnswerWatch = armedWatch;
|
|
2101
|
+
session.midTurnWatchedMessageId = postedMessageId;
|
|
2102
|
+
}
|
|
2013
2103
|
// Bot-side fallback naming (R1 safety net): on the first MEANINGFUL prompt
|
|
2014
2104
|
// of an untitled session, schedule a rename that only fires if opencode's
|
|
2015
2105
|
// own auto-title never lands. Uses the RAW user text (preamble stripped) so
|
|
2016
2106
|
// a fallback title can never carry the service header. Fire-and-forget — it
|
|
2017
2107
|
// must not gate prompt delivery, and a failure leaves the placeholder.
|
|
2018
2108
|
this.maybeScheduleFallbackRename(session, input);
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2109
|
+
if (!isPostIntoRunningTurn) {
|
|
2110
|
+
// A prompt that starts a turn starts its response afresh (what was pending was sent above). The child (sub-agent) accumulator
|
|
2111
|
+
// resets with the parent's. Never for a post into the running turn: the step in flight goes on in the same message, and its own
|
|
2112
|
+
// finish flush already starts the next step afresh.
|
|
2113
|
+
session.currentResponseText = '';
|
|
2114
|
+
session.lastEmittedLength = 0;
|
|
2115
|
+
session.responseMessageId = null;
|
|
2116
|
+
session.isResponseCompactionSummary = false;
|
|
2117
|
+
session.childResponseText = '';
|
|
2118
|
+
session.childLastEmittedLength = 0;
|
|
2119
|
+
}
|
|
2028
2120
|
// New turn → previous turn's tool-result dedup ids can no longer matter
|
|
2029
2121
|
// (see the field's JSDoc for why the turn flush is too early to clear).
|
|
2030
2122
|
session.emittedToolResultPartIds.clear();
|
|
@@ -2032,7 +2124,6 @@ class OpenCodeAdapter extends events_1.EventEmitter {
|
|
|
2032
2124
|
// Mark busy optimistically so an immediately-following message correctly
|
|
2033
2125
|
// sees a turn in flight; the `session.status` stream corrects/confirms it.
|
|
2034
2126
|
session.isBusy = true;
|
|
2035
|
-
const isReplacingProviderRetry = session.providerRetrySignature !== null || session.providerRetryAbortPromise !== null;
|
|
2036
2127
|
if (!isReplacingProviderRetry) {
|
|
2037
2128
|
// Arm the wedged-turn detector: a healthy turn sets `sawTurnActivity` from
|
|
2038
2129
|
// its first assistant message/part; if the next own-session idle arrives
|
|
@@ -2048,8 +2139,6 @@ class OpenCodeAdapter extends events_1.EventEmitter {
|
|
|
2048
2139
|
session.awaitingTurnResponse = false;
|
|
2049
2140
|
session.sawTurnActivity = false;
|
|
2050
2141
|
}
|
|
2051
|
-
// Model + reasoning-effort overrides ride the prompt body (see buildPromptBody).
|
|
2052
|
-
const body = buildPromptBody(input, session.modelOverride, session.effortLevel);
|
|
2053
2142
|
void (async () => {
|
|
2054
2143
|
try {
|
|
2055
2144
|
const retryAbortPromise = this.getProviderRetryAbortPromise(session);
|
|
@@ -2074,6 +2163,14 @@ class OpenCodeAdapter extends events_1.EventEmitter {
|
|
|
2074
2163
|
// idle to clear it if the POST failed — clear it so the next prompt
|
|
2075
2164
|
// doesn't eat a spurious abort + wait.
|
|
2076
2165
|
const current = this.sessions.get((0, sessionKey_1.keyToString)(key));
|
|
2166
|
+
// The agent never got the message: no reminder may ever name it. Only the watch this post set is put back — a later watched post,
|
|
2167
|
+
// an answer or a turn end may have moved it on during the (up to 30 s) wait for this failure.
|
|
2168
|
+
// The watch put back is judged against what was already answered meanwhile (a step that read its message sent the answer).
|
|
2169
|
+
if (armedWatch !== null && session.midTurnAnswerWatch === armedWatch) {
|
|
2170
|
+
session.midTurnWatchedMessageId = watchedMessageIdBeforePost;
|
|
2171
|
+
const isAnsweredMeanwhile = (0, midTurnAnswerWatch_1.checkIsParentAtOrAfterWatchedMessage)(session.newestAnswerParentId ?? undefined, watchedMessageIdBeforePost);
|
|
2172
|
+
session.midTurnAnswerWatch = isAnsweredMeanwhile ? (0, midTurnAnswerWatch_1.getWatchAfterDeliveredAnswer)(watchBeforePost) : watchBeforePost;
|
|
2173
|
+
}
|
|
2077
2174
|
if (current && !current.providerRetrySignature) {
|
|
2078
2175
|
current.isBusy = false;
|
|
2079
2176
|
current.awaitingTurnResponse = false;
|
|
@@ -2262,6 +2359,10 @@ class OpenCodeAdapter extends events_1.EventEmitter {
|
|
|
2262
2359
|
return;
|
|
2263
2360
|
console.log(`[OpenCode] Aborting session (${trigger})`);
|
|
2264
2361
|
session.awaitingTurnResponse = false;
|
|
2362
|
+
// An interrupted turn owes no reminder for a message it took in.
|
|
2363
|
+
session.midTurnAnswerWatch = (0, midTurnAnswerWatch_1.createIdleMidTurnAnswerWatch)();
|
|
2364
|
+
// A message posted before the abort's idle joins no running turn.
|
|
2365
|
+
session.isAbortIdlePending = true;
|
|
2265
2366
|
this.apiRequest('POST', `/session/${session.sessionId}/abort`).catch((e) => {
|
|
2266
2367
|
console.error(`[OpenCode] abort error:`, e);
|
|
2267
2368
|
});
|
|
@@ -3075,6 +3176,12 @@ class OpenCodeAdapter extends events_1.EventEmitter {
|
|
|
3075
3176
|
isBusy: false,
|
|
3076
3177
|
awaitingTurnResponse: false,
|
|
3077
3178
|
sawTurnActivity: false,
|
|
3179
|
+
midTurnAnswerWatch: (0, midTurnAnswerWatch_1.createIdleMidTurnAnswerWatch)(),
|
|
3180
|
+
isAbortIdlePending: false,
|
|
3181
|
+
midTurnWatchedMessageId: null,
|
|
3182
|
+
newestMessageId: null,
|
|
3183
|
+
newestAnswerParentId: null,
|
|
3184
|
+
assistantMessageParentIds: new Map(),
|
|
3078
3185
|
handledTurnErrorTexts: new Set(),
|
|
3079
3186
|
unconsumedInputCount: 0,
|
|
3080
3187
|
seenUserMessageIds: new Set(),
|
|
@@ -4381,10 +4488,7 @@ class OpenCodeAdapter extends events_1.EventEmitter {
|
|
|
4381
4488
|
if (session.outputTimer) {
|
|
4382
4489
|
clearTimeout(session.outputTimer);
|
|
4383
4490
|
}
|
|
4384
|
-
session.outputTimer = setTimeout(() =>
|
|
4385
|
-
session.outputTimer = null;
|
|
4386
|
-
this.emitResponseTail(key, session);
|
|
4387
|
-
}, sseOutputBatchMs);
|
|
4491
|
+
session.outputTimer = setTimeout(() => this.emitResponseTail(key, session), sseOutputBatchMs);
|
|
4388
4492
|
}
|
|
4389
4493
|
/**
|
|
4390
4494
|
* @description Keep the buffer's text and its tails to ONE message at the edge of a compaction summary. The buffer holds
|
|
@@ -4398,10 +4502,6 @@ class OpenCodeAdapter extends events_1.EventEmitter {
|
|
|
4398
4502
|
const isSummaryMessage = messageId === session.compactionSummaryMessageId;
|
|
4399
4503
|
const isNewMessage = session.responseMessageId !== null && messageId !== session.responseMessageId;
|
|
4400
4504
|
if (isNewMessage && (isSummaryMessage || session.isResponseCompactionSummary)) {
|
|
4401
|
-
if (session.outputTimer) {
|
|
4402
|
-
clearTimeout(session.outputTimer);
|
|
4403
|
-
session.outputTimer = null;
|
|
4404
|
-
}
|
|
4405
4505
|
this.emitResponseTail(key, session);
|
|
4406
4506
|
session.currentResponseText = '';
|
|
4407
4507
|
session.lastEmittedLength = 0;
|
|
@@ -4423,8 +4523,15 @@ class OpenCodeAdapter extends events_1.EventEmitter {
|
|
|
4423
4523
|
* response (nothing emitted yet), so it is NOT a continuation. `flushOutput`
|
|
4424
4524
|
* resets `lastEmittedLength` to 0 after the final tail, so the next response
|
|
4425
4525
|
* again starts with a non-continuation first tail.
|
|
4526
|
+
*
|
|
4527
|
+
* It clears the batch-window timer first, so no window stays armed after an early emit (a flush, a post, a summary's edge); the
|
|
4528
|
+
* timer's own call finds it already fired.
|
|
4426
4529
|
*/
|
|
4427
4530
|
emitResponseTail(key, session, isFinal = false) {
|
|
4531
|
+
if (session.outputTimer) {
|
|
4532
|
+
clearTimeout(session.outputTimer);
|
|
4533
|
+
session.outputTimer = null;
|
|
4534
|
+
}
|
|
4428
4535
|
const tail = session.currentResponseText.slice(session.lastEmittedLength);
|
|
4429
4536
|
if (!tail.trim())
|
|
4430
4537
|
return;
|
|
@@ -4470,10 +4577,7 @@ class OpenCodeAdapter extends events_1.EventEmitter {
|
|
|
4470
4577
|
if (session.childOutputTimer) {
|
|
4471
4578
|
clearTimeout(session.childOutputTimer);
|
|
4472
4579
|
}
|
|
4473
|
-
session.childOutputTimer = setTimeout(() =>
|
|
4474
|
-
session.childOutputTimer = null;
|
|
4475
|
-
this.emitChildResponseTail(key, session);
|
|
4476
|
-
}, sseOutputBatchMs);
|
|
4580
|
+
session.childOutputTimer = setTimeout(() => this.emitChildResponseTail(key, session), sseOutputBatchMs);
|
|
4477
4581
|
}
|
|
4478
4582
|
/**
|
|
4479
4583
|
* @description Emit the unsent tail of the CHILD (sub-agent) accumulator as
|
|
@@ -4483,9 +4587,13 @@ class OpenCodeAdapter extends events_1.EventEmitter {
|
|
|
4483
4587
|
* `isContinuation`: the bot renders every sub-agent chunk as its own marked
|
|
4484
4588
|
* message outside the parent's edit-in-place chain (acceptable v1 — `full`
|
|
4485
4589
|
* is opt-in). The empty-string guard doubles as runtime tolerance for test
|
|
4486
|
-
* fixtures that inject minimal session shapes.
|
|
4590
|
+
* fixtures that inject minimal session shapes. Like {@link emitResponseTail} it clears its own batch-window timer first.
|
|
4487
4591
|
*/
|
|
4488
4592
|
emitChildResponseTail(key, session) {
|
|
4593
|
+
if (session.childOutputTimer) {
|
|
4594
|
+
clearTimeout(session.childOutputTimer);
|
|
4595
|
+
session.childOutputTimer = null;
|
|
4596
|
+
}
|
|
4489
4597
|
if (!session.childResponseText)
|
|
4490
4598
|
return;
|
|
4491
4599
|
const tail = session.childResponseText.slice(session.childLastEmittedLength);
|
|
@@ -4550,6 +4658,9 @@ class OpenCodeAdapter extends events_1.EventEmitter {
|
|
|
4550
4658
|
const state = part.state;
|
|
4551
4659
|
if (!state)
|
|
4552
4660
|
return;
|
|
4661
|
+
// A send tool counts as the answer once it delivered (`completed`, never `error`); the agent's own call only.
|
|
4662
|
+
if (!isSubagent && state.status === 'completed' && (0, midTurnAnswerWatch_1.checkIsAnswerTool)(toolName))
|
|
4663
|
+
this.noteDeliveredAnswerStep(session, part.messageID);
|
|
4553
4664
|
// Whether THIS part is the PARENT's own in-flight delegation whose
|
|
4554
4665
|
// "working" indicator is owned by the dedicated `subagentStatus` message
|
|
4555
4666
|
// (minimal/short) — in that case the shared-status "Delegating…" emit below
|
|
@@ -4774,6 +4885,10 @@ class OpenCodeAdapter extends events_1.EventEmitter {
|
|
|
4774
4885
|
// every wedge as "active" and masked it (live miss 2026-08-16).
|
|
4775
4886
|
if (info.role === 'assistant')
|
|
4776
4887
|
session.sawTurnActivity = true;
|
|
4888
|
+
if (isParentAssistantMessage && info.id && info.parentID)
|
|
4889
|
+
this.noteAssistantMessageParent(session, info.id, info.parentID);
|
|
4890
|
+
if (info.id && (!info.sessionID || info.sessionID === session.sessionId))
|
|
4891
|
+
this.noteSessionMessageId(session, info.id);
|
|
4777
4892
|
// The summary message is stored (and announced here) before its text streams.
|
|
4778
4893
|
if (isParentAssistantMessage && info.summary === true && info.id) {
|
|
4779
4894
|
session.compactionSummaryMessageId = info.id;
|
|
@@ -4876,6 +4991,9 @@ class OpenCodeAdapter extends events_1.EventEmitter {
|
|
|
4876
4991
|
}
|
|
4877
4992
|
session?.handledTurnErrorTexts.add(errorMsg);
|
|
4878
4993
|
console.error(`[OpenCode] ${(0, sessionKey_1.keyToString)(key)}: turn failure (${channel}):`, getOpenCodeErrorLogText(error));
|
|
4994
|
+
// A failed turn owes no reminder for a message it took in.
|
|
4995
|
+
if (session)
|
|
4996
|
+
session.midTurnAnswerWatch = (0, midTurnAnswerWatch_1.createIdleMidTurnAnswerWatch)();
|
|
4879
4997
|
// A PARENT-session error aborts the current turn/generation, so the
|
|
4880
4998
|
// delegation the dedicated sub-agent status describes is no longer running:
|
|
4881
4999
|
// close it defensively (mirrors the parent-idle / parent-finish closes) so
|
|
@@ -4912,6 +5030,8 @@ class OpenCodeAdapter extends events_1.EventEmitter {
|
|
|
4912
5030
|
if (sessionId && !(0, openCodeSessionRouting_1.checkIsEventForSession)(sessionId, session.sessionId, this.sessionLineage))
|
|
4913
5031
|
return;
|
|
4914
5032
|
const isOwnIdle = !sessionId || sessionId === session.sessionId;
|
|
5033
|
+
if (isOwnIdle)
|
|
5034
|
+
session.isAbortIdlePending = false;
|
|
4915
5035
|
if (isOwnIdle &&
|
|
4916
5036
|
// A turn we are actively waiting on owns its idle: the abort guard may
|
|
4917
5037
|
// still be armed when the replacement bound expired without the aborted
|
|
@@ -4975,8 +5095,9 @@ class OpenCodeAdapter extends events_1.EventEmitter {
|
|
|
4975
5095
|
// bot can auto-recover (fresh session + replay); the session is
|
|
4976
5096
|
// unrecoverable in place, so a notice alone leaves the topic dead. Resolved
|
|
4977
5097
|
// once per prompt: the pending flag is cleared on this own idle regardless.
|
|
5098
|
+
let isWedged = false;
|
|
4978
5099
|
if (isOwnIdle && session.awaitingTurnResponse) {
|
|
4979
|
-
|
|
5100
|
+
isWedged = (0, openCodeTurnActivity_1.checkIsWedgedTurn)({
|
|
4980
5101
|
awaitingResponse: true,
|
|
4981
5102
|
sawActivity: session.sawTurnActivity,
|
|
4982
5103
|
wasCompacting,
|
|
@@ -4986,6 +5107,18 @@ class OpenCodeAdapter extends events_1.EventEmitter {
|
|
|
4986
5107
|
if (isWedged)
|
|
4987
5108
|
this.reportNoTurnResponse(key, session, 'wedgedIdle');
|
|
4988
5109
|
}
|
|
5110
|
+
// Decided after the wedge check: a wedged idle is a failed turn (its recovery replays the person's prompt, which a reminder written
|
|
5111
|
+
// first would replace). A failure or an abort already cleared the watch. Only a message a step of this turn READ is owed an answer:
|
|
5112
|
+
// one posted just as the server ended the turn (its idle still on its way) opens a turn of its own instead — a lost event of the only
|
|
5113
|
+
// step that read it costs a missed reminder instead of a false one.
|
|
5114
|
+
if (isOwnIdle) {
|
|
5115
|
+
const isMidTurnAnswerReminderDue = (0, midTurnAnswerWatch_1.checkIsMidTurnAnswerReminderDue)(session.midTurnAnswerWatch, { isFailedOrInterrupted: isWedged })
|
|
5116
|
+
&& this.checkIsWatchedMessageRead(session);
|
|
5117
|
+
session.midTurnAnswerWatch = (0, midTurnAnswerWatch_1.createIdleMidTurnAnswerWatch)();
|
|
5118
|
+
session.newestAnswerParentId = null;
|
|
5119
|
+
if (isMidTurnAnswerReminderDue)
|
|
5120
|
+
this.emit('midTurnAnswerMissing', key);
|
|
5121
|
+
}
|
|
4989
5122
|
}
|
|
4990
5123
|
/**
|
|
4991
5124
|
* @description Track live busy/idle/retry from `session.status`. The own
|
|
@@ -5023,9 +5156,11 @@ class OpenCodeAdapter extends events_1.EventEmitter {
|
|
|
5023
5156
|
if (!isOwnSession)
|
|
5024
5157
|
return;
|
|
5025
5158
|
// A turn the bot did not start with a prompt (`/compact`'s summarize, one started outside the bot) begins here:
|
|
5026
|
-
// the previous turn's handled failures must not silence its own.
|
|
5027
|
-
if (status?.type === 'busy' && !wasBusy)
|
|
5159
|
+
// the previous turn's handled failures must not silence its own, and no abort is waiting for its idle any more.
|
|
5160
|
+
if (status?.type === 'busy' && !wasBusy) {
|
|
5028
5161
|
session.handledTurnErrorTexts.clear();
|
|
5162
|
+
session.isAbortIdlePending = false;
|
|
5163
|
+
}
|
|
5029
5164
|
if (status?.type === 'busy' && session.isAwaitingProviderRetryReplacementStart) {
|
|
5030
5165
|
// `busy` is the observable boundary for the replacement request. Older
|
|
5031
5166
|
// retry termination events can no longer consume this new turn's idle, and
|
|
@@ -5399,10 +5534,6 @@ class OpenCodeAdapter extends events_1.EventEmitter {
|
|
|
5399
5534
|
const session = this.sessions.get((0, sessionKey_1.keyToString)(key));
|
|
5400
5535
|
if (!session)
|
|
5401
5536
|
return;
|
|
5402
|
-
if (session.outputTimer) {
|
|
5403
|
-
clearTimeout(session.outputTimer);
|
|
5404
|
-
session.outputTimer = null;
|
|
5405
|
-
}
|
|
5406
5537
|
// Flush any pending status before flushing text output
|
|
5407
5538
|
if (session.statusDebounceTimer) {
|
|
5408
5539
|
clearTimeout(session.statusDebounceTimer);
|
|
@@ -5416,16 +5547,9 @@ class OpenCodeAdapter extends events_1.EventEmitter {
|
|
|
5416
5547
|
// `message.updated` finish and `session.idle`. Idempotent — a no-op if a
|
|
5417
5548
|
// non-reasoning part already ended reasoning (signal #1).
|
|
5418
5549
|
this.endReasoning(key, session);
|
|
5419
|
-
//
|
|
5420
|
-
//
|
|
5421
|
-
|
|
5422
|
-
// routes here too (lineage), so a finished sub-agent flushes promptly.
|
|
5423
|
-
if (session.childOutputTimer) {
|
|
5424
|
-
clearTimeout(session.childOutputTimer);
|
|
5425
|
-
session.childOutputTimer = null;
|
|
5426
|
-
}
|
|
5427
|
-
this.emitChildResponseTail(key, session);
|
|
5428
|
-
this.emitResponseTail(key, session, isFinal);
|
|
5550
|
+
// Both unsent tails before the reset below would drop them. The child idle event routes here too (lineage), so a finished
|
|
5551
|
+
// sub-agent flushes promptly.
|
|
5552
|
+
this.emitPendingResponseTails(key, session, isFinal);
|
|
5429
5553
|
session.currentResponseText = '';
|
|
5430
5554
|
session.lastEmittedLength = 0;
|
|
5431
5555
|
session.responseMessageId = null;
|