@openchamber/web 1.22.1 → 1.23.0
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/bin/cli.js +11 -1
- package/bin/cli.test.js +92 -0
- package/bin/lib/cli-startup.js +49 -0
- package/bin/lib/commands-startup.js +41 -6
- package/dist/assets/{CodeMirrorCommentWidgets-BO_2OW4E.js → CodeMirrorCommentWidgets-DbcnxAfY.js} +1 -1
- package/dist/assets/DiffView-Dp1tomqK.js +4 -0
- package/dist/assets/{DirtyBranchSwitchDialog-jADfXQnR.js → DirtyBranchSwitchDialog-DE2sKIYv.js} +1 -1
- package/dist/assets/FilesView-C_of2nIT.js +17 -0
- package/dist/assets/{GitView-Cv2xH-S6.js → GitView-CKgUkb5Z.js} +4 -4
- package/dist/assets/{JsonTreeView-DUiIpERC.js → JsonTreeView-Bce2ettZ.js} +1 -1
- package/dist/assets/{LinearIssuesView-CoZ7pQN5.js → LinearIssuesView-BZVWM2zw.js} +1 -1
- package/dist/assets/MarkdownImageGallery-DdROVz29.js +1 -0
- package/dist/assets/MarkdownRendererImpl-CenrzmMN.js +12 -0
- package/dist/assets/OnboardingScreen-DyqYG_NP.js +1 -0
- package/dist/assets/{PatchDiff-BymkP9JA.js → PatchDiff-CR3RVO5I.js} +1 -1
- package/dist/assets/PierreDiffViewer-KihzO94X.js +161 -0
- package/dist/assets/PlanView-jcQAfr2A.js +5 -0
- package/dist/assets/SettingsView-Buvom5A2.js +28 -0
- package/dist/assets/{SettingsWindow-COzgfFxM.js → SettingsWindow-CV_hzB5v.js} +1 -1
- package/dist/assets/SymbolsNerdFontMono-Regular-aK5vsLov.woff2 +0 -0
- package/dist/assets/{ToolOutputDialog-Dlhh_-oe.js → ToolOutputDialog-llKecK_Z.js} +6 -6
- package/dist/assets/{ToolPartDiffPreview-b9joNtXH.js → ToolPartDiffPreview-ZDMTdCGn.js} +2 -2
- package/dist/assets/{VirtualizedFileDiff-vqW3KKo5.js → VirtualizedFileDiff-ClvqQ4j0.js} +1 -1
- package/dist/assets/WalkthroughView-BgpSnSlU.js +4 -0
- package/dist/assets/{computeVirtualFileMetrics-DUnyszhW.js → computeVirtualFileMetrics-Nm5_wabb.js} +2 -2
- package/dist/assets/contextPanelEmbeddedChat-CirXEPJq.js +1 -0
- package/dist/assets/de-DTQDjaiv.js +10 -0
- package/dist/assets/es-SOCFd_r-.js +16 -0
- package/dist/assets/fr-CP6jqIzw.js +14 -0
- package/dist/assets/ghostty-vt-DdA0Zryv.wasm +0 -0
- package/dist/assets/index-B68h5S5B.css +1 -0
- package/dist/assets/index-CRf2xk51.js +39 -0
- package/dist/assets/{index-DLiD86ge.js → index-Du9sZhDb.js} +1 -1
- package/dist/assets/{isDiffPlainText-TNageFjy.js → isDiffPlainText-EQERIius.js} +1 -1
- package/dist/assets/{isFilePlainText-JPmZOYSp.js → isFilePlainText-BCoVpkQy.js} +1 -1
- package/dist/assets/ja-BKfafwsD.js +16 -0
- package/dist/assets/ko-BA5xgCYp.js +16 -0
- package/dist/assets/main-BNiPEont.js +930 -0
- package/dist/assets/{main-DCB4JgVe.js → main-DPf32fO6.js} +2 -2
- package/dist/assets/markdownCore-CQ7CAuuV.js +5 -0
- package/dist/assets/{miniChat-BtV7N5OF.js → miniChat-CHqVTsgj.js} +2 -2
- package/dist/assets/{mobile-DZV_sfX7.js → mobile-BQmgHA57.js} +2 -2
- package/dist/assets/patchFileDiff-C4X_trug.js +13 -0
- package/dist/assets/pl-B215pG1Y.js +16 -0
- package/dist/assets/pt-BR-Bo2pnlEa.js +16 -0
- package/dist/assets/renderElectronMiniChatApp-BUcHPOXW.js +2 -0
- package/dist/assets/renderMobileApp-BvTmuRE-.js +25 -0
- package/dist/assets/runtimeEndpointReset-C8GAA2kS.js +17 -0
- package/dist/assets/scheduledTasksApi-BAScWwt3.js +1 -0
- package/dist/assets/{shikiHighlight-CRpCl7UT.js → shikiHighlight-BTObuQCR.js} +1 -1
- package/dist/assets/surface-BvRzS58U.js +1 -0
- package/dist/assets/tr-CUaxHc8X.js +7 -0
- package/dist/assets/uk-YTJgyqAZ.js +16 -0
- package/dist/assets/{useAppFontEffects-CCgvcQ6u.js → useAppFontEffects-theH_IJL.js} +143 -137
- package/dist/assets/useGitComparison-B94I6kOI.js +1 -0
- package/dist/assets/useInlineCommentController-Bs3PgeA8.js +2 -0
- package/dist/assets/useRootScrollLock-hSYwnxZs.js +1 -0
- package/dist/assets/{vendor-base-ui-BeMD8X_w.js → vendor-base-ui-DdV8vhHn.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-data-BxpoC5Fp.js → vendor-codemirror-language-data-Cxgr01md.js} +2 -2
- package/dist/assets/vendor-legendapp-list-BuBPBC3R.js +1 -0
- package/dist/assets/vendor-zod-BPAANqvH.js +39 -0
- package/dist/assets/{web-components-B6QgbmTo.js → web-components-CaS0ksnZ.js} +1 -1
- package/dist/assets/zh-CN-CZ2BxZS6.js +16 -0
- package/dist/assets/zh-TW-BsUrPdXz.js +16 -0
- package/dist/index.html +5 -43
- package/dist/mini-chat.html +4 -4
- package/dist/mobile.html +4 -4
- package/package.json +3 -4
- package/server/index.d.ts +15 -0
- package/server/index.js +52 -10
- package/server/lib/changelog/update-notes.js +82 -0
- package/server/lib/changelog/update-notes.test.js +59 -0
- package/server/lib/data-dir-migration.js +40 -0
- package/server/lib/data-dir-migration.test.js +59 -0
- package/server/lib/event-stream/runtime.test.js +12 -12
- package/server/lib/fs/DOCUMENTATION.md +5 -0
- package/server/lib/fs/routes.js +63 -21
- package/server/lib/fs/routes.test.js +187 -1
- package/server/lib/git/DOCUMENTATION.md +29 -5
- package/server/lib/git/routes.js +24 -4
- package/server/lib/git/service.js +194 -198
- package/server/lib/git/service.test.js +440 -25
- package/server/lib/inherited-env.js +16 -9
- package/server/lib/inherited-env.test.js +8 -9
- package/server/lib/message-queue/DOCUMENTATION.md +20 -7
- package/server/lib/message-queue/runtime.js +59 -7
- package/server/lib/message-queue/runtime.test.js +59 -3
- package/server/lib/network-defaults.js +23 -0
- package/server/lib/network-defaults.test.js +52 -0
- package/server/lib/opencode/DOCUMENTATION.md +25 -5
- package/server/lib/opencode/bootstrap-runtime.js +2 -0
- package/server/lib/opencode/config-paths.test.js +116 -0
- package/server/lib/opencode/feature-routes-runtime.js +4 -0
- package/server/lib/opencode/input-history-scope.js +14 -0
- package/server/lib/opencode/openchamber-routes.js +64 -4
- package/server/lib/opencode/openchamber-routes.test.js +128 -1
- package/server/lib/opencode/plugins.js +2 -2
- package/server/lib/opencode/providers.js +44 -2
- package/server/lib/opencode/providers.test.js +131 -4
- package/server/lib/opencode/routes.js +9 -7
- package/server/lib/opencode/server-startup-runtime.js +1 -1
- package/server/lib/opencode/settings-files.js +214 -0
- package/server/lib/opencode/settings-helpers.js +113 -41
- package/server/lib/opencode/settings-helpers.test.js +342 -0
- package/server/lib/opencode/settings-registry.json +747 -0
- package/server/lib/opencode/settings-runtime.js +139 -18
- package/server/lib/opencode/settings-runtime.test.js +163 -5
- package/server/lib/opencode/shared.js +4 -1
- package/server/lib/opencode/skill-routes.js +2 -1
- package/server/lib/opencode/snippets.js +1 -2
- package/server/lib/package-manager.js +3 -28
- package/server/lib/project-context/DOCUMENTATION.md +25 -1
- package/server/lib/project-context/routes.http.test.js +18 -0
- package/server/lib/project-context/routes.js +15 -0
- package/server/lib/project-context/runtime.js +248 -23
- package/server/lib/project-context/runtime.test.js +106 -3
- package/server/lib/projects/DOCUMENTATION.md +76 -0
- package/server/lib/projects/project-config.js +142 -9
- package/server/lib/projects/project-id.js +17 -0
- package/server/lib/projects/project-setup.js +409 -0
- package/server/lib/projects/project-setup.test.js +557 -0
- package/server/lib/projects/routes.js +59 -0
- package/server/lib/quota/DOCUMENTATION.md +38 -1
- package/server/lib/quota/index.js +1 -0
- package/server/lib/quota/providers/cline-pass.js +125 -0
- package/server/lib/quota/providers/cline-pass.test.js +103 -0
- package/server/lib/quota/providers/hyper.js +118 -0
- package/server/lib/quota/providers/hyper.test.js +126 -0
- package/server/lib/quota/providers/index.js +15 -0
- package/server/lib/quota/providers/neuralwatt.js +3 -6
- package/server/lib/quota/providers/neuralwatt.test.js +7 -7
- package/server/lib/quota/providers/ollama-cloud.js +31 -0
- package/server/lib/quota/providers/ollama-cloud.test.js +33 -1
- package/server/lib/quota/providers/opencode-go.js +1 -1
- package/server/lib/quota/providers/opencode-go.test.js +26 -1
- package/server/lib/quota/providers/openrouter.js +119 -24
- package/server/lib/quota/providers/openrouter.test.js +330 -0
- package/server/lib/quota/utils/auth.js +1 -1
- package/server/lib/relay/DOCUMENTATION.md +55 -0
- package/server/lib/relay/cross-compat.test.js +26 -0
- package/server/lib/relay/downstream-scheduler.js +154 -0
- package/server/lib/relay/downstream-scheduler.test.js +162 -0
- package/server/lib/relay/e2ee.js +10 -8
- package/server/lib/relay/flow-control.test.js +177 -0
- package/server/lib/relay/host-client.js +37 -8
- package/server/lib/relay/host-client.test.js +9 -1
- package/server/lib/relay/tunnel-codec.js +9 -0
- package/server/lib/relay/tunnel-host.js +66 -17
- package/server/lib/session-assist/runtime.js +6 -10
- package/server/lib/session-goal/DOCUMENTATION.md +20 -7
- package/server/lib/session-goal/runtime.js +80 -20
- package/server/lib/session-goal/runtime.test.js +426 -0
- package/server/lib/skills-catalog/DOCUMENTATION.md +1 -1
- package/server/lib/skills-catalog/install.js +3 -2
- package/server/lib/small-model/DOCUMENTATION.md +3 -2
- package/server/lib/small-model/call.js +9 -4
- package/server/lib/small-model/call.test.js +29 -0
- package/server/lib/small-model/index.js +5 -10
- package/server/lib/small-model/runtime-providers.js +15 -7
- package/server/lib/small-model/runtime-providers.test.js +7 -1
- package/server/lib/terminal/DOCUMENTATION.md +14 -10
- package/server/lib/terminal/runtime.js +160 -24
- package/server/lib/terminal/runtime.test.js +571 -37
- package/server/lib/terminal/shells.js +17 -0
- package/server/lib/terminal/shells.test.js +32 -1
- package/server/lib/walkthrough/DOCUMENTATION.md +33 -14
- package/server/lib/walkthrough/model-settings.js +8 -12
- package/server/lib/walkthrough/prompt.js +3 -1
- package/server/lib/walkthrough/routes.test.js +26 -5
- package/server/lib/walkthrough/sources.js +23 -2
- package/dist/assets/DiffView-CNnDxRmO.js +0 -4
- package/dist/assets/FilesView-8wdiG2mj.js +0 -17
- package/dist/assets/MarkdownImageGallery-DffjmciG.js +0 -1
- package/dist/assets/MarkdownRendererImpl-DxqdYDAx.js +0 -12
- package/dist/assets/OnboardingScreen-CTZe6HZn.js +0 -1
- package/dist/assets/PierreDiffViewer-BvwtCxW4.js +0 -157
- package/dist/assets/PlanView-C1qvAm7m.js +0 -5
- package/dist/assets/SettingsView-xGONHFGS.js +0 -28
- package/dist/assets/WalkthroughView-D-HFgdmM.js +0 -4
- package/dist/assets/contextPanelEmbeddedChat-CV-DwAiX.js +0 -1
- package/dist/assets/de-Cv_4FoXm.js +0 -10
- package/dist/assets/es-BIWNEbnS.js +0 -16
- package/dist/assets/fr-SD3OfMHJ.js +0 -14
- package/dist/assets/index-CHUT_bDS.css +0 -1
- package/dist/assets/index-DDInLQDd.js +0 -40
- package/dist/assets/ja-D7I9HofF.js +0 -16
- package/dist/assets/ko-BsVJM_PQ.js +0 -16
- package/dist/assets/main-De8Z5w49.js +0 -928
- package/dist/assets/markdownCore-BoQVG5-a.js +0 -3
- package/dist/assets/patchFileDiff-Chmiz6hq.js +0 -10
- package/dist/assets/pl-XR9Bs8Be.js +0 -16
- package/dist/assets/pt-BR-Due4be8g.js +0 -16
- package/dist/assets/renderElectronMiniChatApp-8tXADjfl.js +0 -2
- package/dist/assets/renderMobileApp-Cji7Hma5.js +0 -25
- package/dist/assets/runtimeEndpointReset-gWt3Lb5D.js +0 -16
- package/dist/assets/scheduledTasksApi-9e-UX6im.js +0 -1
- package/dist/assets/tr-DBJcAv4y.js +0 -7
- package/dist/assets/uk-COYh2BaN.js +0 -16
- package/dist/assets/useInlineCommentController-BkfXnjNZ.js +0 -2
- package/dist/assets/useRootScrollLock-KzOUytpn.js +0 -1
- package/dist/assets/vendor-ghostty-web-CrxinGGH.js +0 -13
- package/dist/assets/vendor-legendapp-list-gg7YLRW7.js +0 -1
- package/dist/assets/vendor-zod-DVWEh-IS.js +0 -39
- package/dist/assets/zh-CN-Cjk6lzhc.js +0 -16
- package/dist/assets/zh-TW-Dk0dOg03.js +0 -16
|
@@ -15,7 +15,6 @@ import {
|
|
|
15
15
|
createFragmentAssembler,
|
|
16
16
|
decodeJsonPayload,
|
|
17
17
|
decodeTunnelFrame,
|
|
18
|
-
encodeFragmentedMessage,
|
|
19
18
|
encodeJsonPayload,
|
|
20
19
|
encodeTunnelFrame,
|
|
21
20
|
} from './tunnel-codec.js';
|
|
@@ -74,6 +73,11 @@ const BODY_BUFFER_MAX_BYTES = 512 * 1024;
|
|
|
74
73
|
// completes, so a stalled tunnel converts into an ambiguous transport failure
|
|
75
74
|
// (which the client already retries) instead of a hung loopback request.
|
|
76
75
|
const BODY_DELIVERY_TIMEOUT_MS = 15_000;
|
|
76
|
+
const MAX_PENDING_WS_BYTES = 16 * 1024 * 1024;
|
|
77
|
+
const MAX_PENDING_WS_MESSAGES = 1024;
|
|
78
|
+
// Node ws supports read backpressure. Bun's ws shim does not implement pause;
|
|
79
|
+
// there the bounded queue fails the affected substream explicitly on overflow.
|
|
80
|
+
const CAN_PAUSE_WS_READS = !process.versions.bun;
|
|
77
81
|
|
|
78
82
|
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
79
83
|
|
|
@@ -99,13 +103,17 @@ const isWsClosePayload = (parsed) => Boolean(parsed && typeof parsed === 'object
|
|
|
99
103
|
* sendFrame: (plaintextFrame: Uint8Array) => void | Promise<void>,
|
|
100
104
|
* getBufferedAmount: () => number,
|
|
101
105
|
* bodyDeliveryTimeoutMs?: number,
|
|
106
|
+
* responseChunkBytes?: number,
|
|
107
|
+
* cancelPendingFrames?: (streamId: number) => void,
|
|
102
108
|
* }} deps
|
|
103
109
|
*/
|
|
104
|
-
export const createTunnelHost = ({ connectionId, getLocalPort, sendFrame, getBufferedAmount, bodyDeliveryTimeoutMs = BODY_DELIVERY_TIMEOUT_MS }) => {
|
|
110
|
+
export const createTunnelHost = ({ connectionId, getLocalPort, sendFrame, getBufferedAmount, bodyDeliveryTimeoutMs = BODY_DELIVERY_TIMEOUT_MS, responseChunkBytes = MAX_TUNNEL_PAYLOAD_BYTES, cancelPendingFrames = () => {} }) => {
|
|
105
111
|
/** @type {Map<number, { kind: 'http', abort: AbortController, body: { enqueue(payload: Uint8Array): void, close(): void, error(error: Error): void } | null, noBody: boolean } | { kind: 'ws', socket: WebSocket, opened: boolean }>} */
|
|
106
112
|
const streams = new Map();
|
|
107
113
|
const assembler = createFragmentAssembler();
|
|
108
114
|
let closed = false;
|
|
115
|
+
let pendingWsBytes = 0;
|
|
116
|
+
let pendingWsMessages = 0;
|
|
109
117
|
|
|
110
118
|
const send = async (frame) => {
|
|
111
119
|
if (closed) return;
|
|
@@ -128,6 +136,7 @@ export const createTunnelHost = ({ connectionId, getLocalPort, sendFrame, getBuf
|
|
|
128
136
|
const stream = streams.get(streamId);
|
|
129
137
|
if (!stream) return;
|
|
130
138
|
dropStream(streamId);
|
|
139
|
+
cancelPendingFrames(streamId);
|
|
131
140
|
if (stream.kind === 'http') {
|
|
132
141
|
try {
|
|
133
142
|
stream.body?.error(new Error(String(reason ?? 'aborted')));
|
|
@@ -205,17 +214,27 @@ export const createTunnelHost = ({ connectionId, getLocalPort, sendFrame, getBuf
|
|
|
205
214
|
if (STRIPPED_RESPONSE_HEADERS.has(name)) continue;
|
|
206
215
|
responseHeaders[name] = value;
|
|
207
216
|
}
|
|
208
|
-
|
|
217
|
+
if (closed || stream.abort.signal.aborted) {
|
|
218
|
+
await response.body?.cancel();
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
209
221
|
|
|
210
222
|
try {
|
|
223
|
+
await sendJson(TunnelFrameType.HttpResponse, streamId, { status: response.status, headers: responseHeaders });
|
|
211
224
|
if (response.body) {
|
|
212
225
|
for await (const chunk of response.body) {
|
|
213
226
|
if (closed || stream.abort.signal.aborted) return;
|
|
214
227
|
const bytes = chunk instanceof Uint8Array ? chunk : new Uint8Array(chunk);
|
|
215
|
-
|
|
228
|
+
const pieces = chunkPayload(bytes, responseChunkBytes);
|
|
229
|
+
// Offer at most one plaintext-frame budget at a time. The scheduler
|
|
230
|
+
// can batch small slices and interleave streams without buffering the
|
|
231
|
+
// entire source or encrypting hundreds of tiny messages separately.
|
|
232
|
+
const groupSize = Math.max(1, Math.floor(MAX_TUNNEL_PAYLOAD_BYTES / responseChunkBytes));
|
|
233
|
+
for (let offset = 0; offset < pieces.length; offset += groupSize) {
|
|
216
234
|
await waitForBackpressure(stream.abort.signal);
|
|
217
235
|
if (closed || stream.abort.signal.aborted) return;
|
|
218
|
-
await
|
|
236
|
+
await Promise.all(pieces.slice(offset, offset + groupSize).map(piece =>
|
|
237
|
+
send(encodeTunnelFrame(TunnelFrameType.HttpBody, streamId, piece))));
|
|
219
238
|
}
|
|
220
239
|
}
|
|
221
240
|
}
|
|
@@ -448,6 +467,7 @@ export const createTunnelHost = ({ connectionId, getLocalPort, sendFrame, getBuf
|
|
|
448
467
|
try {
|
|
449
468
|
socket = new WebSocket(url, open.protocols, {
|
|
450
469
|
headers: dialHeaders,
|
|
470
|
+
maxPayload: MAX_PENDING_WS_BYTES,
|
|
451
471
|
});
|
|
452
472
|
} catch (error) {
|
|
453
473
|
void sendAbort(streamId, error?.message ?? 'ws dial failed');
|
|
@@ -455,6 +475,8 @@ export const createTunnelHost = ({ connectionId, getLocalPort, sendFrame, getBuf
|
|
|
455
475
|
}
|
|
456
476
|
const stream = { kind: 'ws', socket, opened: false };
|
|
457
477
|
streams.set(streamId, stream);
|
|
478
|
+
let outputChain = Promise.resolve();
|
|
479
|
+
let socketPendingMessages = 0;
|
|
458
480
|
|
|
459
481
|
socket.on('open', () => {
|
|
460
482
|
if (streams.get(streamId) !== stream) return;
|
|
@@ -465,23 +487,47 @@ export const createTunnelHost = ({ connectionId, getLocalPort, sendFrame, getBuf
|
|
|
465
487
|
if (streams.get(streamId) !== stream || closed) return;
|
|
466
488
|
const bytes = Buffer.isBuffer(data) ? new Uint8Array(data) : new Uint8Array(Buffer.concat(data));
|
|
467
489
|
const frameType = isBinary ? TunnelFrameType.WsBinary : TunnelFrameType.WsText;
|
|
468
|
-
|
|
469
|
-
|
|
490
|
+
if (pendingWsBytes + bytes.length > MAX_PENDING_WS_BYTES || pendingWsMessages >= MAX_PENDING_WS_MESSAGES) {
|
|
491
|
+
abortLocalStream(streamId, 'upstream WebSocket exceeded downstream queue limit');
|
|
492
|
+
void sendAbort(streamId, 'upstream WebSocket exceeded downstream queue limit');
|
|
493
|
+
return;
|
|
494
|
+
}
|
|
495
|
+
pendingWsBytes += bytes.length;
|
|
496
|
+
pendingWsMessages += 1;
|
|
497
|
+
socketPendingMessages += 1;
|
|
498
|
+
if (CAN_PAUSE_WS_READS) socket.pause();
|
|
499
|
+
outputChain = outputChain.then(async () => {
|
|
500
|
+
// Serialize entire messages, including their fragments. A later close
|
|
501
|
+
// must also wait here or it can overtake the final output.
|
|
502
|
+
const chunks = chunkPayload(bytes, responseChunkBytes);
|
|
503
|
+
const groupSize = Math.max(1, Math.floor(MAX_TUNNEL_PAYLOAD_BYTES / responseChunkBytes));
|
|
504
|
+
for (let offset = 0; offset < chunks.length; offset += groupSize) {
|
|
470
505
|
await waitForBackpressure(null);
|
|
471
506
|
if (streams.get(streamId) !== stream || closed) return;
|
|
472
|
-
await
|
|
507
|
+
await Promise.all(chunks.slice(offset, offset + groupSize).map((chunk, index) =>
|
|
508
|
+
send(encodeTunnelFrame(frameType, streamId, chunk, offset + index < chunks.length - 1))));
|
|
473
509
|
}
|
|
474
|
-
})()
|
|
510
|
+
}).catch(() => {
|
|
511
|
+
abortLocalStream(streamId, 'upstream WebSocket forwarding failed');
|
|
512
|
+
void sendAbort(streamId, 'upstream WebSocket forwarding failed');
|
|
513
|
+
}).finally(() => {
|
|
514
|
+
pendingWsBytes -= bytes.length;
|
|
515
|
+
pendingWsMessages -= 1;
|
|
516
|
+
socketPendingMessages -= 1;
|
|
517
|
+
if (CAN_PAUSE_WS_READS && socketPendingMessages === 0 && streams.get(streamId) === stream && socket.readyState === WebSocket.OPEN) socket.resume();
|
|
518
|
+
});
|
|
475
519
|
});
|
|
476
520
|
socket.on('close', (code, reasonBuffer) => {
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
521
|
+
void outputChain.then(async () => {
|
|
522
|
+
if (streams.get(streamId) !== stream) return;
|
|
523
|
+
dropStream(streamId);
|
|
524
|
+
const reason = reasonBuffer ? reasonBuffer.toString('utf8') : '';
|
|
525
|
+
if (stream.opened) {
|
|
526
|
+
await sendJson(TunnelFrameType.WsClose, streamId, { code: code || 1000, reason });
|
|
527
|
+
} else {
|
|
528
|
+
await sendAbort(streamId, reason || `upstream ws closed (${code || 'no code'})`);
|
|
529
|
+
}
|
|
530
|
+
});
|
|
485
531
|
});
|
|
486
532
|
socket.on('error', (error) => {
|
|
487
533
|
if (streams.get(streamId) !== stream) return;
|
|
@@ -512,6 +558,7 @@ export const createTunnelHost = ({ connectionId, getLocalPort, sendFrame, getBuf
|
|
|
512
558
|
const stream = streams.get(streamId);
|
|
513
559
|
if (!stream || stream.kind !== 'ws') return;
|
|
514
560
|
dropStream(streamId);
|
|
561
|
+
cancelPendingFrames(streamId);
|
|
515
562
|
let close = { code: 1000, reason: '' };
|
|
516
563
|
try {
|
|
517
564
|
close = decodeJsonPayload(payload, isWsClosePayload);
|
|
@@ -520,6 +567,8 @@ export const createTunnelHost = ({ connectionId, getLocalPort, sendFrame, getBuf
|
|
|
520
567
|
}
|
|
521
568
|
const code = Number.isInteger(close.code) && close.code >= 1000 && close.code <= 4999 ? close.code : 1000;
|
|
522
569
|
try {
|
|
570
|
+
// A paused receiver still needs to read the peer's close handshake.
|
|
571
|
+
if (CAN_PAUSE_WS_READS) stream.socket.resume();
|
|
523
572
|
stream.socket.close(code, typeof close.reason === 'string' ? close.reason : '');
|
|
524
573
|
} catch {
|
|
525
574
|
stream.socket.terminate();
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
import fs from 'fs';
|
|
12
12
|
import os from 'os';
|
|
13
13
|
import path from 'path';
|
|
14
|
+
import { readMergedSettingsSync } from '../opencode/settings-files.js';
|
|
14
15
|
|
|
15
16
|
const OPENCHAMBER_SETTINGS_FILE = path.join(
|
|
16
17
|
process.env.OPENCHAMBER_DATA_DIR
|
|
@@ -23,16 +24,11 @@ const OPENCHAMBER_SETTINGS_FILE = path.join(
|
|
|
23
24
|
// off, no small-model calls and no metadata writes happen at all. Existing
|
|
24
25
|
// payloads stay untouched — clients keep showing them and dismissal still works.
|
|
25
26
|
const getSessionAssistTargets = () => {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
suggestion: settings?.sessionSuggestionEnabled !== false,
|
|
32
|
-
};
|
|
33
|
-
} catch {
|
|
34
|
-
return { recap: true, suggestion: true };
|
|
35
|
-
}
|
|
27
|
+
const settings = readMergedSettingsSync({ fs, path, settingsFilePath: OPENCHAMBER_SETTINGS_FILE });
|
|
28
|
+
return {
|
|
29
|
+
recap: settings.sessionRecapEnabled !== false,
|
|
30
|
+
suggestion: settings.sessionSuggestionEnabled !== false,
|
|
31
|
+
};
|
|
36
32
|
};
|
|
37
33
|
|
|
38
34
|
const IDLE_QUIET_MS = 60_000;
|
|
@@ -108,13 +108,26 @@ before touching the filesystem). Rationale: metadata rides every
|
|
|
108
108
|
stop), with a tick-side safety net. Messages sent while paused leave
|
|
109
109
|
the goal alone; Resume re-arms the loop, and resuming over an aborted
|
|
110
110
|
tail skips the audit and goes straight to a continuation nudge;
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
111
|
+
- terminal checks, cheapest first: assistant turn error → `blocked`;
|
|
112
|
+
`tokensUsed >= tokenBudget` → `budgetLimited`;
|
|
113
|
+
`turnsUsed >= MAX_AUTO_TURNS` (20) → `blocked`;
|
|
114
|
+
- error classification is independent of `finish`: `MessageAbortedError`
|
|
115
|
+
keeps the pause/resume behavior; only a `finish: "length"` with no
|
|
116
|
+
error, or `MessageOutputLengthError`, is an in-progress truncation that
|
|
117
|
+
skips the audit and continues. Any other non-null error wins over a
|
|
118
|
+
length finish and blocks with its non-empty `error.name`, or
|
|
119
|
+
`assistant turn failed` when unnamed;
|
|
120
|
+
- length recovery is bounded separately from the token budget and
|
|
121
|
+
auto-continuation cap: the first truncation permits one continuation, but
|
|
122
|
+
a second consecutive completed, non-summary assistant turn that is also
|
|
123
|
+
truncated settles the goal as `blocked` (`repeated output truncation`).
|
|
124
|
+
The consecutive state is derived from the loaded message history, not
|
|
125
|
+
persisted, using `info.time.created` chronology rather than message IDs.
|
|
126
|
+
Summary messages are not agent turns; an ordinary completed assistant
|
|
127
|
+
turn naturally breaks the consecutive condition. Explicit Resume grants
|
|
128
|
+
one new recovery attempt over the same transcript; the continuation
|
|
129
|
+
consumes that permission, so another truncation blocks again. Resume
|
|
130
|
+
does not bypass assistant errors or the token budget;
|
|
118
131
|
- otherwise, small-model audit of the objective + the last assistant turn
|
|
119
132
|
only — no conversation history and no continuation prompts
|
|
120
133
|
(`restrictToPreferredProvider`, session's own provider/model preferred):
|
|
@@ -19,6 +19,7 @@ import os from 'os';
|
|
|
19
19
|
import path from 'path';
|
|
20
20
|
|
|
21
21
|
import { GOAL_OBJECTIVE_CHAR_LIMIT, readObjective } from './objectives.js';
|
|
22
|
+
import { readMergedSettingsSync } from '../opencode/settings-files.js';
|
|
22
23
|
|
|
23
24
|
const OPENCHAMBER_SETTINGS_FILE = path.join(
|
|
24
25
|
process.env.OPENCHAMBER_DATA_DIR
|
|
@@ -27,15 +28,9 @@ const OPENCHAMBER_SETTINGS_FILE = path.join(
|
|
|
27
28
|
'settings.json',
|
|
28
29
|
);
|
|
29
30
|
|
|
30
|
-
const isSessionGoalEnabled = () =>
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const settings = JSON.parse(raw);
|
|
34
|
-
return settings?.sessionGoalEnabled !== false;
|
|
35
|
-
} catch {
|
|
36
|
-
return true;
|
|
37
|
-
}
|
|
38
|
-
};
|
|
31
|
+
const isSessionGoalEnabled = () => (
|
|
32
|
+
readMergedSettingsSync({ fs, path, settingsFilePath: OPENCHAMBER_SETTINGS_FILE }).sessionGoalEnabled !== false
|
|
33
|
+
);
|
|
39
34
|
|
|
40
35
|
const IDLE_QUIET_MS = 15_000;
|
|
41
36
|
// A goal set while the session is already idle should kick off promptly.
|
|
@@ -244,6 +239,57 @@ const messageTokenTotal = (info) => {
|
|
|
244
239
|
return input + cachedRead + output;
|
|
245
240
|
};
|
|
246
241
|
|
|
242
|
+
const getErrorName = (error) => error?.name?.trim?.() ?? '';
|
|
243
|
+
|
|
244
|
+
const isLengthTruncated = (info, errorName = getErrorName(info?.error)) => {
|
|
245
|
+
const error = info?.error;
|
|
246
|
+
const hasError = error !== null && error !== undefined;
|
|
247
|
+
return errorName === 'MessageOutputLengthError' || (!hasError && info?.finish === 'length');
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
// Summary messages are assistant-shaped, but they are compaction turns rather
|
|
251
|
+
// than agent turns. They must not break or satisfy the consecutive truncation
|
|
252
|
+
// check; only completed, non-summary assistant turns participate. Chronology
|
|
253
|
+
// comes from `time.created`, never from message IDs; array position is only a
|
|
254
|
+
// tie-breaker for equal timestamps.
|
|
255
|
+
const hasRepeatedLengthTail = (messages, latestAssistant, goalCreatedAt) => {
|
|
256
|
+
const latestInfo = latestAssistant?.info;
|
|
257
|
+
if (latestInfo?.summary === true) return false;
|
|
258
|
+
const latestIndex = messages.indexOf(latestAssistant);
|
|
259
|
+
const latestCreated = latestInfo?.time?.created;
|
|
260
|
+
if (
|
|
261
|
+
latestIndex < 0
|
|
262
|
+
|| !(latestInfo?.time?.completed > 0)
|
|
263
|
+
|| !(Number.isFinite(latestCreated) && latestCreated > 0)
|
|
264
|
+
|| !isLengthTruncated(latestInfo)
|
|
265
|
+
) return false;
|
|
266
|
+
|
|
267
|
+
let previous = null;
|
|
268
|
+
for (let i = 0; i < messages.length; i += 1) {
|
|
269
|
+
const info = messages[i]?.info;
|
|
270
|
+
if (info?.role !== 'assistant' || info.summary === true || !(info.time?.completed > 0)) continue;
|
|
271
|
+
const created = info.time?.created;
|
|
272
|
+
// An unknown timestamp cannot safely participate in chronology. Ignore it
|
|
273
|
+
// rather than letting an unrelated older message hide known chronology.
|
|
274
|
+
if (!(Number.isFinite(created) && created > 0)) continue;
|
|
275
|
+
if (i === latestIndex) continue;
|
|
276
|
+
if (created > latestCreated || (created === latestCreated && i > latestIndex)) continue;
|
|
277
|
+
if (
|
|
278
|
+
!previous
|
|
279
|
+
|| created > previous.created
|
|
280
|
+
|| (created === previous.created && i > previous.index)
|
|
281
|
+
) {
|
|
282
|
+
previous = { info, created, index: i };
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
return Boolean(
|
|
287
|
+
previous
|
|
288
|
+
&& previous.created > goalCreatedAt
|
|
289
|
+
&& isLengthTruncated(previous.info),
|
|
290
|
+
);
|
|
291
|
+
};
|
|
292
|
+
|
|
247
293
|
export const createSessionGoalRuntime = ({
|
|
248
294
|
buildOpenCodeUrl,
|
|
249
295
|
getOpenCodeAuthHeaders,
|
|
@@ -609,7 +655,11 @@ export const createSessionGoalRuntime = ({
|
|
|
609
655
|
// resumed over an aborted tail: that is an explicit "keep going", so it
|
|
610
656
|
// falls through to the continuation below (skipping the audit — an
|
|
611
657
|
// aborted reply is not evidence of anything).
|
|
612
|
-
const
|
|
658
|
+
const error = lastAssistantInfo.error;
|
|
659
|
+
const errorName = getErrorName(error);
|
|
660
|
+
const hasError = error !== null && error !== undefined;
|
|
661
|
+
const abortedTail = errorName === 'MessageAbortedError';
|
|
662
|
+
const lengthTail = isLengthTruncated(lastAssistantInfo, errorName);
|
|
613
663
|
if (abortedTail && goal.statusReason !== 'resumed') {
|
|
614
664
|
await writeGoal(sessionId, directory, goal.id, () => ({
|
|
615
665
|
status: 'paused',
|
|
@@ -623,13 +673,12 @@ export const createSessionGoalRuntime = ({
|
|
|
623
673
|
return;
|
|
624
674
|
}
|
|
625
675
|
|
|
626
|
-
//
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
: 'assistant turn failed';
|
|
676
|
+
// Non-length turn error → blocked (prevents runaway auto-continuation into
|
|
677
|
+
// failures). Recognized length cutoffs are in-progress continuations, not
|
|
678
|
+
// hard failures.
|
|
679
|
+
if (!abortedTail && !lengthTail && hasError) {
|
|
631
680
|
await settleGoal({
|
|
632
|
-
sessionId, directory, goal, status: 'blocked', statusReason:
|
|
681
|
+
sessionId, directory, goal, status: 'blocked', statusReason: errorName || 'assistant turn failed', tokensUsed, tokensBaseline, tokensCommitted, lastAccountedMessageID,
|
|
633
682
|
});
|
|
634
683
|
return;
|
|
635
684
|
}
|
|
@@ -650,17 +699,28 @@ export const createSessionGoalRuntime = ({
|
|
|
650
699
|
return;
|
|
651
700
|
}
|
|
652
701
|
|
|
702
|
+
// A second consecutive completed, non-summary length-truncated turn is a
|
|
703
|
+
// bounded recovery failure. Derive this from the loaded transcript rather
|
|
704
|
+
// than persisting another goal counter.
|
|
705
|
+
if (lengthTail && goal.statusReason !== 'resumed' && hasRepeatedLengthTail(messages, lastAssistant, goal.createdAt)) {
|
|
706
|
+
await settleGoal({
|
|
707
|
+
sessionId, directory, goal, status: 'blocked', statusReason: 'repeated output truncation', tokensUsed, tokensBaseline, tokensCommitted, lastAccountedMessageID,
|
|
708
|
+
});
|
|
709
|
+
return;
|
|
710
|
+
}
|
|
711
|
+
|
|
653
712
|
// --- Small-model audit: the sole termination authority besides the hard
|
|
654
713
|
// stops above (turn error, budget, continuation cap). The working agent
|
|
655
714
|
// has no channel to settle its own goal.
|
|
656
715
|
//
|
|
657
|
-
// Exception: when the latest message is a compaction summary
|
|
658
|
-
// by
|
|
659
|
-
// "in progress, not finished".
|
|
716
|
+
// Exception: when the latest message is a compaction summary or was cut off
|
|
717
|
+
// by the output token limit (length stop), the agent by definition ran into
|
|
718
|
+
// the context/output limit mid-work — that IS "in progress, not finished".
|
|
719
|
+
// No audit call; continue unconditionally.
|
|
660
720
|
let audit = null;
|
|
661
721
|
let blockedStreak = 0;
|
|
662
722
|
let auditFailStreak = goal.auditFailStreak;
|
|
663
|
-
if (lastAssistantInfo.summary === true || abortedTail) {
|
|
723
|
+
if (lastAssistantInfo.summary === true || abortedTail || lengthTail) {
|
|
664
724
|
blockedStreak = goal.blockedStreak;
|
|
665
725
|
} else {
|
|
666
726
|
audit = await runAudit({ goal: { ...goal, objective: effectiveObjective }, assistantText, directory, lastAssistantInfo: executionInfo ?? lastAssistantInfo });
|