@openchamber/web 1.19.0 → 1.20.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/dist/assets/{CodeMirrorCommentWidgets-DAvopJvy.js → CodeMirrorCommentWidgets-C36E738Y.js} +1 -1
- package/dist/assets/{CommitSection-D9cV-qR9.js → CommitSection-C-F3AX6D.js} +1 -1
- package/dist/assets/{DiagramEditor-B9NCadU7.js → DiagramEditor-BPECg1jS.js} +1 -1
- package/dist/assets/DiagramView-D0YNMix8.js +1 -0
- package/dist/assets/DiffView-BHWaMYCC.js +4 -0
- package/dist/assets/FilesView-NMBCW2Tm.js +14 -0
- package/dist/assets/{GitView-DsWXqWx3.js → GitView-Rp8P1KEI.js} +4 -4
- package/dist/assets/{JsonTreeView-h4dHASlq.js → JsonTreeView-KnXFN2A-.js} +1 -1
- package/dist/assets/{MarkdownImageGallery-n0ikH-xm.js → MarkdownImageGallery-BMn3mtor.js} +1 -1
- package/dist/assets/MarkdownRendererImpl-kD6N03pH.js +12 -0
- package/dist/assets/{OnboardingScreen-CDjgzxEe.js → OnboardingScreen-CenIeD4v.js} +1 -1
- package/dist/assets/{PatchDiff-jPKTJje5.js → PatchDiff-BzVOVog8.js} +1 -1
- package/dist/assets/{PierreDiffViewer-D_Gt4A_6.js → PierreDiffViewer-Dlby4XqT.js} +2 -2
- package/dist/assets/PlanView-Czu1KMJa.js +4 -0
- package/dist/assets/SessionSwitcherDropdown-IETz58DB.js +1 -0
- package/dist/assets/SettingsView-B6vmuf-c.js +28 -0
- package/dist/assets/SettingsWindow-CauZpdD3.js +1 -0
- package/dist/assets/ToolOutputDialog-BB1c--Zr.js +15 -0
- package/dist/assets/ToolPartDiffPreview-DaOIDISD.js +8 -0
- package/dist/assets/{VirtualizedFileDiff-B37yB9jZ.js → VirtualizedFileDiff-lESMT-2b.js} +4 -4
- package/dist/assets/{WalkthroughView-Bxun3k66.js → WalkthroughView-CaSYE0lw.js} +1 -1
- package/dist/assets/{computeVirtualFileMetrics-DYFv_yZS.js → computeVirtualFileMetrics-DkRR5b75.js} +2 -2
- package/dist/assets/{contextPanelEmbeddedChat-BO1wRpaN.js → contextPanelEmbeddedChat-BEARQjgn.js} +1 -1
- package/dist/assets/de-DFdX3ABv.js +9 -0
- package/dist/assets/es-iC-FKvV9.js +15 -0
- package/dist/assets/fr-BBbi_1AL.js +13 -0
- package/dist/assets/{index-BSvmTvZl.js → index-BiEgzzkg.js} +1 -1
- package/dist/assets/index-Cwmuwk3V.js +7 -0
- package/dist/assets/index-GNm1wgUH.css +1 -0
- package/dist/assets/{isDiffPlainText-DwHKxDYc.js → isDiffPlainText-BG53Ixxy.js} +1 -1
- package/dist/assets/{isFilePlainText-Dwq6ILxo.js → isFilePlainText-BbV-39jl.js} +1 -1
- package/dist/assets/ja-DQLQJL2J.js +15 -0
- package/dist/assets/ko-BeElEB4Y.js +15 -0
- package/dist/assets/main-Dpzo18z7.js +2 -0
- package/dist/assets/main-WMjtYzJs.js +921 -0
- package/dist/assets/markdownCore--tDmyI_v.js +2 -0
- package/dist/assets/miniChat-ldEghBLB.js +2 -0
- package/dist/assets/mobile-Dk-VGreF.js +2 -0
- package/dist/assets/{patchFileDiff-BEDPDypx.js → patchFileDiff-BcFaMtMu.js} +2 -2
- package/dist/assets/pl-CLHt2_vV.js +15 -0
- package/dist/assets/pt-BR-C_MPUq7e.js +15 -0
- package/dist/assets/renderElectronMiniChatApp-DIgCOmXY.js +2 -0
- package/dist/assets/{renderMobileApp-BiMbzPq9.js → renderMobileApp-CDfHS5rr.js} +7 -7
- package/dist/assets/runtimeEndpointReset-ovNbaZ-x.js +15 -0
- package/dist/assets/{scheduledTasksApi-01zzfzqH.js → scheduledTasksApi-BFSlqgnG.js} +1 -1
- package/dist/assets/{shikiHighlight-DXYW46vW.js → shikiHighlight-DCT2Sq_z.js} +1 -1
- package/dist/assets/uk-PhsC-c4-.js +15 -0
- package/dist/assets/{useAppFontEffects-CbzHzFop.js → useAppFontEffects-B53Rb6m7.js} +166 -159
- package/dist/assets/useInlineCommentController-DSfrIBKT.js +2 -0
- package/dist/assets/{vendor-base-ui-BYlZTzrw.js → vendor-base-ui-DsHmyMwp.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-data-CiAYDJXN.js → vendor-codemirror-language-data-vch3tJ4c.js} +2 -2
- package/dist/assets/vendor-zod-C9ioTTSo.js +39 -0
- package/dist/assets/{web-components-DCLjCO9n.js → web-components-pcwCTWjC.js} +4 -4
- package/dist/assets/zh-CN-wF-NOFHM.js +15 -0
- package/dist/assets/zh-TW-4m4-A7rT.js +15 -0
- package/dist/index.html +5 -4
- package/dist/mini-chat.html +4 -3
- package/dist/mobile.html +4 -3
- package/package.json +3 -5
- package/server/index.js +36 -0
- package/server/lib/agent-memory/project-resolution.js +10 -1
- package/server/lib/agent-memory/project-resolution.test.js +9 -0
- package/server/lib/agent-memory/runtime.js +7 -2
- package/server/lib/dictation/DOCUMENTATION.md +32 -8
- package/server/lib/dictation/local/sherpa-recognizer.js +35 -78
- package/server/lib/dictation/local/worker-process.js +2 -2
- package/server/lib/dictation/openai-compatible-session.js +3 -2
- package/server/lib/dictation/stream-manager.js +77 -34
- package/server/lib/dictation/stream-manager.test.js +60 -2
- package/server/lib/fs/routes.test.js +76 -0
- package/server/lib/git/routes.js +43 -0
- package/server/lib/git/service.js +85 -5
- package/server/lib/git/service.test.js +93 -0
- package/server/lib/opencode/DOCUMENTATION.md +6 -2
- package/server/lib/opencode/feature-routes-runtime.js +5 -9
- package/server/lib/opencode/lifecycle.js +202 -26
- package/server/lib/opencode/lifecycle.test.js +179 -1
- package/server/lib/opencode/providers.js +9 -4
- package/server/lib/opencode/providers.test.js +27 -0
- package/server/lib/opencode/restart-session-recovery.test.js +59 -0
- package/server/lib/opencode/session-runtime.js +39 -2
- package/server/lib/opencode/session-runtime.test.js +74 -0
- package/server/lib/opencode/settings-helpers.js +15 -0
- package/server/lib/opencode/settings-helpers.test.js +22 -0
- package/server/lib/opencode/settings-normalization-runtime.js +3 -0
- package/server/lib/opencode/settings-normalization-runtime.test.js +16 -0
- package/server/lib/opencode/settings-runtime.js +32 -10
- package/server/lib/opencode/settings-runtime.test.js +85 -0
- package/server/lib/opencode/skill-routes.js +29 -73
- package/server/lib/opencode/skill-routes.test.js +2 -5
- package/server/lib/project-context/DOCUMENTATION.md +2 -0
- package/server/lib/project-context/runtime.js +7 -2
- package/server/lib/projects/project-config.js +7 -2
- package/server/lib/quota/DOCUMENTATION.md +1 -1
- package/server/lib/quota/providers/claude/index.js +2 -2
- package/server/lib/quota/providers/command-code.js +1 -1
- package/server/lib/quota/providers/command-code.test.js +13 -0
- package/server/lib/quota/providers/index.js +12 -4
- package/server/lib/quota/providers/zai.js +26 -6
- package/server/lib/quota/providers/zai.test.js +33 -0
- package/server/lib/session-knowledge/DOCUMENTATION.md +2 -0
- package/server/lib/skills-catalog/DOCUMENTATION.md +18 -45
- package/server/lib/skills-catalog/cache.js +120 -1
- package/server/lib/skills-catalog/cache.test.js +77 -0
- package/server/lib/skills-catalog/curated-sources.js +21 -5
- package/server/lib/skills-catalog/curated-sources.test.js +4 -4
- package/server/lib/skills-catalog/disk-cache.js +52 -0
- package/server/lib/skills-catalog/github-meta.js +139 -0
- package/server/lib/skills-catalog/github-meta.test.js +71 -0
- package/server/lib/skills-catalog/source.js +0 -5
- package/server/lib/small-model/DOCUMENTATION.md +74 -6
- package/server/lib/small-model/call.js +46 -12
- package/server/lib/small-model/call.test.js +79 -0
- package/server/lib/small-model/index.js +51 -8
- package/server/lib/small-model/index.test.js +73 -3
- package/server/lib/small-model/routes.js +1 -1
- package/server/lib/small-model/runtime-providers.js +156 -0
- package/server/lib/small-model/runtime-providers.test.js +112 -0
- package/dist/assets/DiagramView-LKGBwf4G.js +0 -1
- package/dist/assets/DiffView-BWNq-0ov.js +0 -4
- package/dist/assets/FilesView-DB-Q0Gkz.js +0 -14
- package/dist/assets/MarkdownRendererImpl-CT2mjx-s.js +0 -12
- package/dist/assets/PlanView-UvuxIl9-.js +0 -4
- package/dist/assets/SessionSwitcherDropdown-xKU4LRuQ.js +0 -1
- package/dist/assets/SettingsView-3B9VN6Ys.js +0 -28
- package/dist/assets/SettingsWindow-CqQNDKNd.js +0 -1
- package/dist/assets/ToolOutputDialog-PmjlAxVE.js +0 -15
- package/dist/assets/ToolPartDiffPreview-B34Xw9wq.js +0 -8
- package/dist/assets/de-DbV6CLxv.js +0 -9
- package/dist/assets/es-CVDlyzZ4.js +0 -15
- package/dist/assets/fr-Czc-p0g-.js +0 -13
- package/dist/assets/index-1OhiMDBz.css +0 -1
- package/dist/assets/index-DzriVon2.js +0 -7
- package/dist/assets/ja-dwc9NM_S.js +0 -15
- package/dist/assets/ko-Ds1DZ8FX.js +0 -15
- package/dist/assets/main-BF51IOVF.js +0 -921
- package/dist/assets/main-D7UPARut.js +0 -2
- package/dist/assets/markdownCore-BgeBDwD3.js +0 -2
- package/dist/assets/miniChat-BISXSGOo.js +0 -2
- package/dist/assets/mobile-BnYxVuvw.js +0 -2
- package/dist/assets/pl-CLiTO7i-.js +0 -15
- package/dist/assets/pt-BR-GIimJgpK.js +0 -15
- package/dist/assets/renderElectronMiniChatApp-BaOy72Gi.js +0 -2
- package/dist/assets/runtimeEndpointReset-BMBRhIbf.js +0 -15
- package/dist/assets/uk-DLfgD1ki.js +0 -15
- package/dist/assets/useInlineCommentController-CegKdDXi.js +0 -2
- package/dist/assets/vendor-zod-adaMkgkm.js +0 -39
- package/dist/assets/zh-CN-DkeP5awK.js +0 -15
- package/dist/assets/zh-TW-BocaFm3d.js +0 -15
- package/server/lib/skills-catalog/clawdhub/api.js +0 -126
- package/server/lib/skills-catalog/clawdhub/install.js +0 -238
- package/server/lib/skills-catalog/clawdhub/install.test.js +0 -100
- package/server/lib/skills-catalog/clawdhub/scan.js +0 -61
|
@@ -111,12 +111,13 @@ This module provides OpenCode server integration utilities for the web server ru
|
|
|
111
111
|
- `markSessionUnviewed(sessionId, clientId)`
|
|
112
112
|
- `markUserMessageSent(sessionId)`
|
|
113
113
|
- `resetAllSessionActivityToIdle()`
|
|
114
|
+
- `interruptBusySessionsAfterRestart()`: settles every session whose authoritative status is `busy`/`retry` or whose activity phase is still busy, broadcasts `openchamber:session-status` idle plus an OpenCode-shaped `session.error`, resets leftover activity/cooldowns, and returns the interrupted session IDs in stable order.
|
|
114
115
|
- `dispose()`
|
|
115
116
|
|
|
116
117
|
The runtime maintains active-session count incrementally from idempotent activity phase transitions. Upstream stall-timeout and lifecycle health checks read it in O(1); the hourly cleanup removes activity phases older than 24 hours without broadcasting synthetic state transitions. Snapshot generation remains reserved for the session-activity API.
|
|
117
118
|
|
|
118
119
|
## Public exports (lifecycle.js)
|
|
119
|
-
- `createOpenCodeLifecycleRuntime(dependencies)`: creates lifecycle runtime for managed/external OpenCode process orchestration. The optional `onOpenCodeRestarted` dependency (default `null`) is fired after a successful managed restart
|
|
120
|
+
- `createOpenCodeLifecycleRuntime(dependencies)`: creates lifecycle runtime for managed/external OpenCode process orchestration. The optional `onOpenCodeRestarted` dependency (default `null`) is fired after a successful managed restart. `index.js` rebinds event-stream readers to the possibly-new port (#2638), then calls `interruptBusySessionsAfterRestart()` and broadcasts one `opencode-restart-interrupted` UI notification when interrupted turns exist (#2943).
|
|
120
121
|
- Returned API:
|
|
121
122
|
- `startOpenCode()`
|
|
122
123
|
- `restartOpenCode()`
|
|
@@ -147,6 +148,8 @@ macOS `say` voice enumeration starts concurrently with server composition. The s
|
|
|
147
148
|
|
|
148
149
|
Transport-triggered health checks share the periodic monitor's failure accounting interval. Rapid WS reconnect callbacks therefore cannot exhaust the managed-process restart threshold using one cached unhealthy result; an exited managed process still restarts immediately.
|
|
149
150
|
|
|
151
|
+
Managed health failures are classified as `timeout`, `connection_refused`, `connection_reset`, `invalid_response`, or `error`. The lifecycle retains the latest counted failure with a bounded detail string and source. Managed process wrappers continue capturing a sanitized, bounded stderr tail after readiness and retain exit code/signal. Before replacing a managed process, lifecycle snapshots the reason, latest health failure, process diagnostics/aliveness, busy-session count, and timestamp into `lastOpenCodeRestartDiagnostics`; successful startup does not clear this snapshot, and `/health` exposes it for post-restart diagnosis without process environment or credentials.
|
|
152
|
+
|
|
150
153
|
## Public exports (env-runtime.js)
|
|
151
154
|
- `createOpenCodeEnvRuntime(dependencies)`: creates runtime that owns OpenCode CLI environment and binary discovery state.
|
|
152
155
|
- OpenCode CLI resolution order is persisted settings, environment overrides, bundled Desktop CLI when available, PATH, known install locations, then platform shell discovery.
|
|
@@ -204,7 +207,8 @@ Transport-triggered health checks share the periodic monitor's failure accountin
|
|
|
204
207
|
- `readSettingsFromDiskMigrated()`
|
|
205
208
|
- `writeSettingsToDisk(settings)`
|
|
206
209
|
- `persistSettings(changes)`
|
|
207
|
-
|
|
210
|
+
- Persistent permission auto-accept policy is stored under `permissionAutoAccept`; execution ownership lives in `lib/permission-auto-accept/`.
|
|
211
|
+
- Shared sidebar preferences are stored as validated top-level fields: `sidebarProjectDisplayMode`, `sidebarSessionGroupingMode`, `sidebarProjectSortOrder`, and `sidebarShowRecentSection`. Device-local picker selection and sticky-header state do not enter `settings.json`.
|
|
208
212
|
|
|
209
213
|
## Public exports (settings-helpers.js)
|
|
210
214
|
- `createSettingsHelpers(dependencies)`: creates settings helper runtime for settings request/response shaping.
|
|
@@ -45,12 +45,11 @@ import {
|
|
|
45
45
|
import { SKILL_DIR, SKILL_SCOPE, readSkillSupportingFile, writeSkillSupportingFile, deleteSkillSupportingFile } from './shared.js';
|
|
46
46
|
import { getSkillSources, discoverSkills, mergeDiscoveredSkills, createSkill, updateSkill, deleteSkill, renameSkill, isManagedSkillPath } from './skills.js';
|
|
47
47
|
import { getCuratedSkillsSources } from '../skills-catalog/curated-sources.js';
|
|
48
|
-
import { getCacheKey,
|
|
49
|
-
import {
|
|
48
|
+
import { getCacheKey, scanWithCache } from '../skills-catalog/cache.js';
|
|
49
|
+
import { parseSkillRepoSource } from '../skills-catalog/source.js';
|
|
50
50
|
import { scanSkillsRepository } from '../skills-catalog/scan.js';
|
|
51
51
|
import { installSkillsFromRepository } from '../skills-catalog/install.js';
|
|
52
|
-
import {
|
|
53
|
-
import { installSkillsFromClawdHub } from '../skills-catalog/clawdhub/install.js';
|
|
52
|
+
import { fetchGitHubRepoMetas } from '../skills-catalog/github-meta.js';
|
|
54
53
|
|
|
55
54
|
export const createFeatureRoutesRuntime = (dependencies) => {
|
|
56
55
|
const {
|
|
@@ -287,14 +286,11 @@ export const createFeatureRoutesRuntime = (dependencies) => {
|
|
|
287
286
|
SKILL_DIR,
|
|
288
287
|
getCuratedSkillsSources,
|
|
289
288
|
getCacheKey,
|
|
290
|
-
|
|
291
|
-
setCachedScan,
|
|
289
|
+
scanWithCache,
|
|
292
290
|
parseSkillRepoSource,
|
|
293
291
|
scanSkillsRepository,
|
|
294
292
|
installSkillsFromRepository,
|
|
295
|
-
|
|
296
|
-
installSkillsFromClawdHub,
|
|
297
|
-
isClawdHubSource,
|
|
293
|
+
fetchGitHubRepoMetas,
|
|
298
294
|
getProfiles,
|
|
299
295
|
getProfile,
|
|
300
296
|
});
|
|
@@ -22,6 +22,65 @@ const OPENCODE_HEALTH_PATH = '/global/health';
|
|
|
22
22
|
// tails are unlikely to be the user's first click and just add background work.
|
|
23
23
|
const WARMUP_DIRECTORY_LIMIT = 4;
|
|
24
24
|
const WARMUP_REQUEST_TIMEOUT_MS = 30000;
|
|
25
|
+
const MANAGED_STDERR_TAIL_MAX_BYTES = 32 * 1024;
|
|
26
|
+
const HEALTH_FAILURE_DETAIL_MAX_LENGTH = 256;
|
|
27
|
+
|
|
28
|
+
const getBoundedTextTail = (value, maxBytes) => {
|
|
29
|
+
const buffer = Buffer.from(String(value ?? ''));
|
|
30
|
+
if (buffer.byteLength <= maxBytes) return buffer.toString();
|
|
31
|
+
return buffer.subarray(buffer.byteLength - maxBytes).toString();
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const sanitizeDiagnosticText = (value) => String(value ?? '')
|
|
35
|
+
.replace(/(https?:\/\/)[^/\s:@]+:[^/\s@]+@/gi, '$1[redacted]@')
|
|
36
|
+
.replace(/\b(Bearer)\s+[^\s,;]+/gi, '$1 [redacted]')
|
|
37
|
+
// Unquoted `Authorization: <scheme> <credential>` values must be handled
|
|
38
|
+
// before the generic key/value rule below: that rule stops at whitespace, so
|
|
39
|
+
// it would redact only the scheme word and leave the credential intact.
|
|
40
|
+
// Scoped to authorization-style keys so ordinary prose using "basic" or
|
|
41
|
+
// "token" is not mangled.
|
|
42
|
+
.replace(
|
|
43
|
+
/(^|[\s,{\[])((?:"|')?[a-z0-9_.-]{0,80}authorization[a-z0-9_.-]{0,80}(?:"|')?\s*[:=]\s*(?:"|')?(?:basic|bearer|token)\s+)[^\s,;"']+/gim,
|
|
44
|
+
'$1$2[redacted]',
|
|
45
|
+
)
|
|
46
|
+
.replace(/([?&][^=&#\s]*(?:token|api[_-]?key|password|secret|authorization|credential|private[_-]?key)[^=&#\s]*=)[^&#\s]+/gi, '$1[redacted]')
|
|
47
|
+
.replace(
|
|
48
|
+
/(^|[\s,{\[])((?:"|')?[a-z0-9_.-]{0,80}(?:token|api[_-]?key|password|secret|authorization|credential|private[_-]?key)[a-z0-9_.-]{0,80}(?:"|')?\s*[:=]\s*)("[^"]*"|'[^']*'|[^\s,;]+)/gim,
|
|
49
|
+
'$1$2[redacted]',
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
const getHealthFailureDetail = (error) => {
|
|
53
|
+
const name = String(error?.name || 'Error');
|
|
54
|
+
const message = String(error?.message || error || 'Unknown error');
|
|
55
|
+
return sanitizeDiagnosticText(`${name}: ${message}`).slice(0, HEALTH_FAILURE_DETAIL_MAX_LENGTH);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const classifyHealthProbeError = (error) => {
|
|
59
|
+
const name = String(error?.name || '');
|
|
60
|
+
const code = String(error?.code || '').toUpperCase();
|
|
61
|
+
const message = String(error?.message || error || '');
|
|
62
|
+
const normalizedMessage = message.toLowerCase();
|
|
63
|
+
|
|
64
|
+
if (
|
|
65
|
+
name === 'AbortError'
|
|
66
|
+
|| name === 'TimeoutError'
|
|
67
|
+
|| normalizedMessage.includes('the operation was aborted')
|
|
68
|
+
|| normalizedMessage.includes('abortsignal.timeout')
|
|
69
|
+
) {
|
|
70
|
+
return { class: 'timeout', detail: getHealthFailureDetail(error) };
|
|
71
|
+
}
|
|
72
|
+
if (code === 'ECONNREFUSED' || normalizedMessage.includes('econnrefused')) {
|
|
73
|
+
return { class: 'connection_refused', detail: getHealthFailureDetail(error) };
|
|
74
|
+
}
|
|
75
|
+
if (
|
|
76
|
+
code === 'ECONNRESET'
|
|
77
|
+
|| normalizedMessage.includes('econnreset')
|
|
78
|
+
|| normalizedMessage.includes('socket hang up')
|
|
79
|
+
) {
|
|
80
|
+
return { class: 'connection_reset', detail: getHealthFailureDetail(error) };
|
|
81
|
+
}
|
|
82
|
+
return { class: 'error', detail: getHealthFailureDetail(error) };
|
|
83
|
+
};
|
|
25
84
|
|
|
26
85
|
export const createOpenCodeLifecycleRuntime = (deps) => {
|
|
27
86
|
const {
|
|
@@ -88,6 +147,36 @@ export const createOpenCodeLifecycleRuntime = (deps) => {
|
|
|
88
147
|
}
|
|
89
148
|
};
|
|
90
149
|
|
|
150
|
+
const snapshotManagedOpenCodeProcess = (child = state.openCodeProcess) => {
|
|
151
|
+
if (!child) return null;
|
|
152
|
+
const snapshot = {
|
|
153
|
+
pid: child.pid || null,
|
|
154
|
+
exitCode: child.exitCode ?? null,
|
|
155
|
+
signalCode: child.signalCode ?? null,
|
|
156
|
+
stderrTail: getBoundedTextTail(
|
|
157
|
+
sanitizeDiagnosticText(child.stderrTail ?? ''),
|
|
158
|
+
MANAGED_STDERR_TAIL_MAX_BYTES,
|
|
159
|
+
),
|
|
160
|
+
};
|
|
161
|
+
state.lastManagedOpenCodeProcess = snapshot;
|
|
162
|
+
return snapshot;
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
const captureRestartDiagnostics = (reason) => {
|
|
166
|
+
const processSnapshot = snapshotManagedOpenCodeProcess();
|
|
167
|
+
const diagnostics = {
|
|
168
|
+
reason: sanitizeDiagnosticText(String(reason || 'managed-restart')).slice(0, HEALTH_FAILURE_DETAIL_MAX_LENGTH),
|
|
169
|
+
healthFailure: state.lastOpenCodeHealthFailure ? { ...state.lastOpenCodeHealthFailure } : null,
|
|
170
|
+
process: processSnapshot
|
|
171
|
+
? { ...processSnapshot, alive: isManagedOpenCodeProcessAlive() }
|
|
172
|
+
: null,
|
|
173
|
+
busySessionCount: getActiveSessionCount(),
|
|
174
|
+
at: new Date(now()).toISOString(),
|
|
175
|
+
};
|
|
176
|
+
state.lastOpenCodeRestartDiagnostics = diagnostics;
|
|
177
|
+
console.warn('[lifecycle] managed OpenCode restart diagnostics', diagnostics);
|
|
178
|
+
};
|
|
179
|
+
|
|
91
180
|
const waitForChildProcessClose = (child, timeoutMs) => new Promise((resolve) => {
|
|
92
181
|
if (!child || hasChildProcessExited(child)) {
|
|
93
182
|
resolve(true);
|
|
@@ -297,6 +386,34 @@ export const createOpenCodeLifecycleRuntime = (deps) => {
|
|
|
297
386
|
windowsHide: true,
|
|
298
387
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
299
388
|
});
|
|
389
|
+
let runtimeStderrTail = '';
|
|
390
|
+
let runtimeStderrAttached = false;
|
|
391
|
+
let observedExitCode = null;
|
|
392
|
+
let observedSignalCode = null;
|
|
393
|
+
|
|
394
|
+
const getManagedProcessSnapshot = () => ({
|
|
395
|
+
pid: child.pid || null,
|
|
396
|
+
exitCode: observedExitCode ?? child.exitCode ?? null,
|
|
397
|
+
signalCode: observedSignalCode ?? child.signalCode ?? null,
|
|
398
|
+
stderrTail: getBoundedTextTail(sanitizeDiagnosticText(runtimeStderrTail), MANAGED_STDERR_TAIL_MAX_BYTES),
|
|
399
|
+
});
|
|
400
|
+
const recordManagedProcessExit = (code, signal) => {
|
|
401
|
+
if (code !== null && code !== undefined) observedExitCode = code;
|
|
402
|
+
if (signal !== null && signal !== undefined) observedSignalCode = signal;
|
|
403
|
+
state.lastManagedOpenCodeProcess = getManagedProcessSnapshot();
|
|
404
|
+
};
|
|
405
|
+
const attachRuntimeStderrCapture = () => {
|
|
406
|
+
if (runtimeStderrAttached) return;
|
|
407
|
+
runtimeStderrAttached = true;
|
|
408
|
+
child.stderr?.on('data', (chunk) => {
|
|
409
|
+
runtimeStderrTail = getBoundedTextTail(
|
|
410
|
+
`${runtimeStderrTail}${chunk.toString()}`,
|
|
411
|
+
MANAGED_STDERR_TAIL_MAX_BYTES,
|
|
412
|
+
);
|
|
413
|
+
});
|
|
414
|
+
};
|
|
415
|
+
child.on('exit', recordManagedProcessExit);
|
|
416
|
+
child.on('close', recordManagedProcessExit);
|
|
300
417
|
|
|
301
418
|
const url = await new Promise((resolve, reject) => {
|
|
302
419
|
let stdout = '';
|
|
@@ -323,6 +440,7 @@ export const createOpenCodeLifecycleRuntime = (deps) => {
|
|
|
323
440
|
finish(reject, new Error(`Failed to parse server url from output: ${line}`));
|
|
324
441
|
return;
|
|
325
442
|
}
|
|
443
|
+
attachRuntimeStderrCapture();
|
|
326
444
|
finish(resolve, match[1]);
|
|
327
445
|
return;
|
|
328
446
|
}
|
|
@@ -371,10 +489,13 @@ export const createOpenCodeLifecycleRuntime = (deps) => {
|
|
|
371
489
|
url,
|
|
372
490
|
pid: child.pid || null,
|
|
373
491
|
get exitCode() {
|
|
374
|
-
return child.exitCode;
|
|
492
|
+
return observedExitCode ?? child.exitCode;
|
|
375
493
|
},
|
|
376
494
|
get signalCode() {
|
|
377
|
-
return child.signalCode;
|
|
495
|
+
return observedSignalCode ?? child.signalCode;
|
|
496
|
+
},
|
|
497
|
+
get stderrTail() {
|
|
498
|
+
return getManagedProcessSnapshot().stderrTail;
|
|
378
499
|
},
|
|
379
500
|
async close() {
|
|
380
501
|
await closeManagedOpenCodeChild(child);
|
|
@@ -416,9 +537,15 @@ export const createOpenCodeLifecycleRuntime = (deps) => {
|
|
|
416
537
|
});
|
|
417
538
|
};
|
|
418
539
|
|
|
419
|
-
const
|
|
540
|
+
const probeOpenCodeHealthDetailed = async () => {
|
|
420
541
|
if (!state.openCodeProcess || !state.openCodePort) {
|
|
421
|
-
return
|
|
542
|
+
return {
|
|
543
|
+
healthy: false,
|
|
544
|
+
failure: {
|
|
545
|
+
class: 'error',
|
|
546
|
+
detail: 'Managed OpenCode process or port is unavailable',
|
|
547
|
+
},
|
|
548
|
+
};
|
|
422
549
|
}
|
|
423
550
|
|
|
424
551
|
try {
|
|
@@ -430,14 +557,47 @@ export const createOpenCodeLifecycleRuntime = (deps) => {
|
|
|
430
557
|
},
|
|
431
558
|
signal: AbortSignal.timeout(HEALTH_CHECK_TIMEOUT_MS),
|
|
432
559
|
});
|
|
433
|
-
if (!response.ok)
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
560
|
+
if (!response.ok) {
|
|
561
|
+
return {
|
|
562
|
+
healthy: false,
|
|
563
|
+
failure: {
|
|
564
|
+
class: 'invalid_response',
|
|
565
|
+
detail: `Health endpoint returned HTTP ${response.status ?? 'unknown'}`,
|
|
566
|
+
},
|
|
567
|
+
};
|
|
568
|
+
}
|
|
569
|
+
let body;
|
|
570
|
+
try {
|
|
571
|
+
body = await response.json();
|
|
572
|
+
} catch {
|
|
573
|
+
return {
|
|
574
|
+
healthy: false,
|
|
575
|
+
failure: {
|
|
576
|
+
class: 'invalid_response',
|
|
577
|
+
detail: 'Health endpoint returned invalid JSON',
|
|
578
|
+
},
|
|
579
|
+
};
|
|
580
|
+
}
|
|
581
|
+
if (body?.healthy !== true) {
|
|
582
|
+
return {
|
|
583
|
+
healthy: false,
|
|
584
|
+
failure: {
|
|
585
|
+
class: 'invalid_response',
|
|
586
|
+
detail: 'Health endpoint did not report healthy=true',
|
|
587
|
+
},
|
|
588
|
+
};
|
|
589
|
+
}
|
|
590
|
+
return { healthy: true, failure: null };
|
|
591
|
+
} catch (error) {
|
|
592
|
+
return {
|
|
593
|
+
healthy: false,
|
|
594
|
+
failure: classifyHealthProbeError(error),
|
|
595
|
+
};
|
|
438
596
|
}
|
|
439
597
|
};
|
|
440
598
|
|
|
599
|
+
const isOpenCodeProcessHealthy = async () => (await probeOpenCodeHealthDetailed()).healthy;
|
|
600
|
+
|
|
441
601
|
const probeExternalOpenCode = async (port, origin) => {
|
|
442
602
|
if (!port || port <= 0) {
|
|
443
603
|
return false;
|
|
@@ -617,7 +777,7 @@ export const createOpenCodeLifecycleRuntime = (deps) => {
|
|
|
617
777
|
throw lastError;
|
|
618
778
|
};
|
|
619
779
|
|
|
620
|
-
const restartOpenCode = async () => {
|
|
780
|
+
const restartOpenCode = async (reason = 'managed-restart') => {
|
|
621
781
|
if (state.isShuttingDown) return;
|
|
622
782
|
if (state.currentRestartPromise) {
|
|
623
783
|
await state.currentRestartPromise;
|
|
@@ -655,6 +815,7 @@ export const createOpenCodeLifecycleRuntime = (deps) => {
|
|
|
655
815
|
return;
|
|
656
816
|
}
|
|
657
817
|
|
|
818
|
+
captureRestartDiagnostics(reason);
|
|
658
819
|
const portToKill = state.openCodePort;
|
|
659
820
|
|
|
660
821
|
if (state.openCodeProcess) {
|
|
@@ -820,7 +981,7 @@ export const createOpenCodeLifecycleRuntime = (deps) => {
|
|
|
820
981
|
clearResolvedOpenCodeBinary();
|
|
821
982
|
await applyOpencodeBinaryFromSettings();
|
|
822
983
|
|
|
823
|
-
await restartOpenCode();
|
|
984
|
+
await restartOpenCode(reason || 'config-change');
|
|
824
985
|
|
|
825
986
|
// A managed OpenCode process is restarted (and thus re-reads config from
|
|
826
987
|
// disk) by restartOpenCode(). An external OpenCode server is NOT owned by
|
|
@@ -1010,17 +1171,17 @@ export const createOpenCodeLifecycleRuntime = (deps) => {
|
|
|
1010
1171
|
const probeOpenCodeHealth = async () => {
|
|
1011
1172
|
const checkedAt = now();
|
|
1012
1173
|
if (lastHealthProbeResult && checkedAt - lastHealthProbeResult.at < HEALTH_CHECK_RESULT_CACHE_MS) {
|
|
1013
|
-
return lastHealthProbeResult
|
|
1174
|
+
return lastHealthProbeResult;
|
|
1014
1175
|
}
|
|
1015
1176
|
|
|
1016
1177
|
if (healthProbePromise) {
|
|
1017
1178
|
return healthProbePromise;
|
|
1018
1179
|
}
|
|
1019
1180
|
|
|
1020
|
-
healthProbePromise =
|
|
1021
|
-
.then((
|
|
1022
|
-
lastHealthProbeResult = { at: now(),
|
|
1023
|
-
return
|
|
1181
|
+
healthProbePromise = probeOpenCodeHealthDetailed()
|
|
1182
|
+
.then((result) => {
|
|
1183
|
+
lastHealthProbeResult = { at: now(), ...result };
|
|
1184
|
+
return lastHealthProbeResult;
|
|
1024
1185
|
})
|
|
1025
1186
|
.finally(() => {
|
|
1026
1187
|
healthProbePromise = null;
|
|
@@ -1033,13 +1194,13 @@ export const createOpenCodeLifecycleRuntime = (deps) => {
|
|
|
1033
1194
|
const activeCount = getActiveSessionCount();
|
|
1034
1195
|
if (activeCount === 0) {
|
|
1035
1196
|
lastUnhealthyWithBusySessionsAt = 0;
|
|
1036
|
-
return false;
|
|
1197
|
+
return { skip: false, staleBusy: false };
|
|
1037
1198
|
}
|
|
1038
1199
|
|
|
1039
1200
|
const checkedAt = now();
|
|
1040
1201
|
if (!lastUnhealthyWithBusySessionsAt) {
|
|
1041
1202
|
lastUnhealthyWithBusySessionsAt = checkedAt;
|
|
1042
|
-
return true;
|
|
1203
|
+
return { skip: true, staleBusy: false };
|
|
1043
1204
|
}
|
|
1044
1205
|
|
|
1045
1206
|
if (checkedAt - lastUnhealthyWithBusySessionsAt >= STALE_BUSY_GRACE_MS) {
|
|
@@ -1047,10 +1208,10 @@ export const createOpenCodeLifecycleRuntime = (deps) => {
|
|
|
1047
1208
|
`[lifecycle] OpenCode unhealthy with ${activeCount} busy session(s) for > 2 min — forcing restart`
|
|
1048
1209
|
);
|
|
1049
1210
|
lastUnhealthyWithBusySessionsAt = 0;
|
|
1050
|
-
return false;
|
|
1211
|
+
return { skip: false, staleBusy: true };
|
|
1051
1212
|
}
|
|
1052
1213
|
|
|
1053
|
-
return true;
|
|
1214
|
+
return { skip: true, staleBusy: false };
|
|
1054
1215
|
};
|
|
1055
1216
|
|
|
1056
1217
|
const runHealthCheckCycle = async (source) => {
|
|
@@ -1058,13 +1219,13 @@ export const createOpenCodeLifecycleRuntime = (deps) => {
|
|
|
1058
1219
|
if (healthCheckCyclePromise) return healthCheckCyclePromise;
|
|
1059
1220
|
|
|
1060
1221
|
healthCheckCyclePromise = (async () => {
|
|
1061
|
-
const
|
|
1062
|
-
if (!healthy) {
|
|
1222
|
+
const healthResult = await probeOpenCodeHealth();
|
|
1223
|
+
if (!healthResult.healthy) {
|
|
1063
1224
|
if (!isManagedOpenCodeProcessAlive()) {
|
|
1064
1225
|
console.log(`[lifecycle] ${source} health check: OpenCode process exited, restarting...`);
|
|
1065
1226
|
consecutiveHealthFailures = 0;
|
|
1066
1227
|
lastHealthProbeResult = null;
|
|
1067
|
-
await restartOpenCode();
|
|
1228
|
+
await restartOpenCode(`${source}-process-exited`);
|
|
1068
1229
|
return;
|
|
1069
1230
|
}
|
|
1070
1231
|
const checkedAt = now();
|
|
@@ -1073,15 +1234,30 @@ export const createOpenCodeLifecycleRuntime = (deps) => {
|
|
|
1073
1234
|
}
|
|
1074
1235
|
lastCountedHealthFailureAt = checkedAt;
|
|
1075
1236
|
consecutiveHealthFailures += 1;
|
|
1237
|
+
const healthFailure = healthResult.failure || {
|
|
1238
|
+
class: 'error',
|
|
1239
|
+
detail: 'Health check failed without diagnostic detail',
|
|
1240
|
+
};
|
|
1241
|
+
state.lastOpenCodeHealthFailure = {
|
|
1242
|
+
class: healthFailure.class,
|
|
1243
|
+
detail: healthFailure.detail,
|
|
1244
|
+
at: new Date(checkedAt).toISOString(),
|
|
1245
|
+
source,
|
|
1246
|
+
};
|
|
1076
1247
|
console.warn(
|
|
1077
|
-
`[lifecycle] ${source} health check failed (${consecutiveHealthFailures}/${HEALTH_CHECK_MAX_CONSECUTIVE_FAILURES})`
|
|
1248
|
+
`[lifecycle] ${source} health check failed (${consecutiveHealthFailures}/${HEALTH_CHECK_MAX_CONSECUTIVE_FAILURES}) class=${healthFailure.class}`
|
|
1078
1249
|
);
|
|
1079
1250
|
if (consecutiveHealthFailures < HEALTH_CHECK_MAX_CONSECUTIVE_FAILURES) return;
|
|
1080
|
-
|
|
1251
|
+
const busyDecision = shouldSkipRestartForBusySessions();
|
|
1252
|
+
if (busyDecision.skip) return;
|
|
1081
1253
|
console.log(`[lifecycle] ${source} health check failure threshold reached, restarting OpenCode...`);
|
|
1082
1254
|
consecutiveHealthFailures = 0;
|
|
1083
1255
|
lastHealthProbeResult = null;
|
|
1084
|
-
await restartOpenCode(
|
|
1256
|
+
await restartOpenCode(
|
|
1257
|
+
busyDecision.staleBusy
|
|
1258
|
+
? `${source}-stale-busy-health-failure`
|
|
1259
|
+
: `${source}-health-failure`,
|
|
1260
|
+
);
|
|
1085
1261
|
} else {
|
|
1086
1262
|
resetHealthFailureState();
|
|
1087
1263
|
}
|
|
@@ -62,6 +62,9 @@ const createRuntime = (overrides = {}, stateOverrides = {}, envOverrides = {}) =
|
|
|
62
62
|
openCodeApiPrefixDetected: false,
|
|
63
63
|
openCodeApiDetectionTimer: null,
|
|
64
64
|
lastOpenCodeError: null,
|
|
65
|
+
lastOpenCodeHealthFailure: null,
|
|
66
|
+
lastManagedOpenCodeProcess: null,
|
|
67
|
+
lastOpenCodeRestartDiagnostics: null,
|
|
65
68
|
isOpenCodeReady: false,
|
|
66
69
|
openCodeNotReadySince: 0,
|
|
67
70
|
isExternalOpenCode: false,
|
|
@@ -75,7 +78,7 @@ const createRuntime = (overrides = {}, stateOverrides = {}, envOverrides = {}) =
|
|
|
75
78
|
...stateOverrides,
|
|
76
79
|
};
|
|
77
80
|
|
|
78
|
-
|
|
81
|
+
const runtime = createOpenCodeLifecycleRuntime({
|
|
79
82
|
state,
|
|
80
83
|
env: {
|
|
81
84
|
ENV_CONFIGURED_OPENCODE_PORT: 45678,
|
|
@@ -111,6 +114,8 @@ const createRuntime = (overrides = {}, stateOverrides = {}, envOverrides = {}) =
|
|
|
111
114
|
})),
|
|
112
115
|
...overrides,
|
|
113
116
|
});
|
|
117
|
+
runtime.testState = state;
|
|
118
|
+
return runtime;
|
|
114
119
|
};
|
|
115
120
|
|
|
116
121
|
describe('OpenCode lifecycle', () => {
|
|
@@ -234,6 +239,61 @@ describe('OpenCode lifecycle', () => {
|
|
|
234
239
|
warn.mockRestore();
|
|
235
240
|
});
|
|
236
241
|
|
|
242
|
+
it.each([
|
|
243
|
+
{
|
|
244
|
+
name: 'timeout',
|
|
245
|
+
expectedClass: 'timeout',
|
|
246
|
+
fetchResult: () => {
|
|
247
|
+
const error = new Error('The operation was aborted');
|
|
248
|
+
error.name = 'AbortError';
|
|
249
|
+
throw error;
|
|
250
|
+
},
|
|
251
|
+
},
|
|
252
|
+
{
|
|
253
|
+
name: 'connection refusal',
|
|
254
|
+
expectedClass: 'connection_refused',
|
|
255
|
+
fetchResult: () => {
|
|
256
|
+
const error = new Error('connect ECONNREFUSED 127.0.0.1:45678');
|
|
257
|
+
error.code = 'ECONNREFUSED';
|
|
258
|
+
throw error;
|
|
259
|
+
},
|
|
260
|
+
},
|
|
261
|
+
{
|
|
262
|
+
name: 'invalid JSON',
|
|
263
|
+
expectedClass: 'invalid_response',
|
|
264
|
+
fetchResult: () => ({
|
|
265
|
+
ok: true,
|
|
266
|
+
json: async () => {
|
|
267
|
+
throw new SyntaxError('Unexpected token');
|
|
268
|
+
},
|
|
269
|
+
}),
|
|
270
|
+
},
|
|
271
|
+
])('classifies and stores a counted $name health failure', async ({ expectedClass, fetchResult }) => {
|
|
272
|
+
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
273
|
+
globalThis.fetch = vi.fn(fetchResult);
|
|
274
|
+
const runtime = createRuntime({}, {
|
|
275
|
+
openCodePort: 45678,
|
|
276
|
+
openCodeProcess: {
|
|
277
|
+
pid: process.pid,
|
|
278
|
+
exitCode: null,
|
|
279
|
+
signalCode: null,
|
|
280
|
+
close: vi.fn(async () => {}),
|
|
281
|
+
},
|
|
282
|
+
isOpenCodeReady: true,
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
await runtime.triggerHealthCheck();
|
|
286
|
+
|
|
287
|
+
expect(runtime.testState.lastOpenCodeHealthFailure).toEqual({
|
|
288
|
+
class: expectedClass,
|
|
289
|
+
detail: expect.any(String),
|
|
290
|
+
at: expect.any(String),
|
|
291
|
+
source: 'immediate',
|
|
292
|
+
});
|
|
293
|
+
expect(warn).toHaveBeenCalledWith(expect.stringContaining(`class=${expectedClass}`));
|
|
294
|
+
warn.mockRestore();
|
|
295
|
+
});
|
|
296
|
+
|
|
237
297
|
it('does not mistake a live managed process wrapper for an exited child', async () => {
|
|
238
298
|
const close = vi.fn(async () => {});
|
|
239
299
|
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
@@ -320,6 +380,124 @@ describe('OpenCode lifecycle', () => {
|
|
|
320
380
|
expect(onOpenCodeRestarted).toHaveBeenCalledTimes(1);
|
|
321
381
|
});
|
|
322
382
|
|
|
383
|
+
it('retains post-listen stderr and exited process diagnostics across restart', async () => {
|
|
384
|
+
const firstChild = createMockChild();
|
|
385
|
+
const replacement = createMockChild();
|
|
386
|
+
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
387
|
+
globalThis.fetch = vi.fn(async () => ({
|
|
388
|
+
ok: false,
|
|
389
|
+
status: 503,
|
|
390
|
+
json: async () => null,
|
|
391
|
+
}));
|
|
392
|
+
spawnMock.mockImplementationOnce(() => {
|
|
393
|
+
queueMicrotask(() => {
|
|
394
|
+
firstChild.stdout.emit('data', 'opencode server listening on http://127.0.0.1:45678\n');
|
|
395
|
+
});
|
|
396
|
+
return firstChild;
|
|
397
|
+
});
|
|
398
|
+
spawnMock.mockImplementationOnce(() => {
|
|
399
|
+
queueMicrotask(() => {
|
|
400
|
+
replacement.stdout.emit('data', 'opencode server listening on http://127.0.0.1:45678\n');
|
|
401
|
+
});
|
|
402
|
+
return replacement;
|
|
403
|
+
});
|
|
404
|
+
const runtime = createRuntime();
|
|
405
|
+
const server = await runtime.startOpenCode();
|
|
406
|
+
runtime.testState.openCodeProcess = server;
|
|
407
|
+
|
|
408
|
+
firstChild.stderr.emit(
|
|
409
|
+
'data',
|
|
410
|
+
`${'x'.repeat(40 * 1024)}\ntoken=runtime-secret\nruntime worker failed after startup\n`,
|
|
411
|
+
);
|
|
412
|
+
firstChild.exitCode = 7;
|
|
413
|
+
firstChild.emit('exit', 7, null);
|
|
414
|
+
|
|
415
|
+
expect(server.exitCode).toBe(7);
|
|
416
|
+
expect(Buffer.byteLength(server.stderrTail)).toBeLessThanOrEqual(32 * 1024);
|
|
417
|
+
expect(server.stderrTail).not.toContain('runtime-secret');
|
|
418
|
+
expect(server.stderrTail).toContain('runtime worker failed after startup');
|
|
419
|
+
|
|
420
|
+
await runtime.triggerHealthCheck();
|
|
421
|
+
|
|
422
|
+
expect(runtime.testState.lastOpenCodeRestartDiagnostics).toEqual({
|
|
423
|
+
reason: 'immediate-process-exited',
|
|
424
|
+
healthFailure: null,
|
|
425
|
+
process: {
|
|
426
|
+
pid: 12345,
|
|
427
|
+
exitCode: 7,
|
|
428
|
+
signalCode: null,
|
|
429
|
+
stderrTail: expect.stringContaining('runtime worker failed after startup'),
|
|
430
|
+
alive: false,
|
|
431
|
+
},
|
|
432
|
+
busySessionCount: 0,
|
|
433
|
+
at: expect.any(String),
|
|
434
|
+
});
|
|
435
|
+
expect(runtime.testState.lastManagedOpenCodeProcess).toEqual({
|
|
436
|
+
pid: 12345,
|
|
437
|
+
exitCode: 7,
|
|
438
|
+
signalCode: null,
|
|
439
|
+
stderrTail: expect.stringContaining('runtime worker failed after startup'),
|
|
440
|
+
});
|
|
441
|
+
|
|
442
|
+
await runtime.testState.openCodeProcess.close();
|
|
443
|
+
warn.mockRestore();
|
|
444
|
+
});
|
|
445
|
+
|
|
446
|
+
it('redacts Authorization scheme credentials from stderr diagnostics', async () => {
|
|
447
|
+
const firstChild = createMockChild();
|
|
448
|
+
const replacement = createMockChild();
|
|
449
|
+
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
450
|
+
globalThis.fetch = vi.fn(async () => ({
|
|
451
|
+
ok: false,
|
|
452
|
+
status: 503,
|
|
453
|
+
json: async () => null,
|
|
454
|
+
}));
|
|
455
|
+
spawnMock.mockImplementationOnce(() => {
|
|
456
|
+
queueMicrotask(() => {
|
|
457
|
+
firstChild.stdout.emit('data', 'opencode server listening on http://127.0.0.1:45678\n');
|
|
458
|
+
});
|
|
459
|
+
return firstChild;
|
|
460
|
+
});
|
|
461
|
+
spawnMock.mockImplementationOnce(() => {
|
|
462
|
+
queueMicrotask(() => {
|
|
463
|
+
replacement.stdout.emit('data', 'opencode server listening on http://127.0.0.1:45678\n');
|
|
464
|
+
});
|
|
465
|
+
return replacement;
|
|
466
|
+
});
|
|
467
|
+
const runtime = createRuntime();
|
|
468
|
+
const server = await runtime.startOpenCode();
|
|
469
|
+
runtime.testState.openCodeProcess = server;
|
|
470
|
+
|
|
471
|
+
firstChild.stderr.emit(
|
|
472
|
+
'data',
|
|
473
|
+
'request rejected: Authorization: Basic dXNlcjpwYXNz\n'
|
|
474
|
+
+ 'authorization: basic bG93ZXI6Y2FzZQ==\n'
|
|
475
|
+
+ 'Authorization: Bearer fake-bearer-token-value\n'
|
|
476
|
+
+ 'falling back to basic health monitor\n'
|
|
477
|
+
+ 'runtime worker failed after startup\n',
|
|
478
|
+
);
|
|
479
|
+
firstChild.exitCode = 7;
|
|
480
|
+
firstChild.emit('exit', 7, null);
|
|
481
|
+
|
|
482
|
+
expect(server.stderrTail).not.toContain('dXNlcjpwYXNz');
|
|
483
|
+
expect(server.stderrTail).not.toContain('bG93ZXI6Y2FzZQ');
|
|
484
|
+
expect(server.stderrTail).not.toContain('fake-bearer-token-value');
|
|
485
|
+
expect(server.stderrTail).toContain('falling back to basic health monitor');
|
|
486
|
+
expect(server.stderrTail).toContain('runtime worker failed after startup');
|
|
487
|
+
|
|
488
|
+
await runtime.triggerHealthCheck();
|
|
489
|
+
|
|
490
|
+
const diagnosticsTail = runtime.testState.lastOpenCodeRestartDiagnostics.process.stderrTail;
|
|
491
|
+
expect(diagnosticsTail).not.toContain('dXNlcjpwYXNz');
|
|
492
|
+
expect(diagnosticsTail).not.toContain('bG93ZXI6Y2FzZQ');
|
|
493
|
+
expect(diagnosticsTail).not.toContain('fake-bearer-token-value');
|
|
494
|
+
expect(diagnosticsTail).toContain('falling back to basic health monitor');
|
|
495
|
+
expect(diagnosticsTail).toContain('runtime worker failed after startup');
|
|
496
|
+
|
|
497
|
+
await runtime.testState.openCodeProcess.close();
|
|
498
|
+
warn.mockRestore();
|
|
499
|
+
});
|
|
500
|
+
|
|
323
501
|
it('does not call onOpenCodeRestarted when a managed restart fails', async () => {
|
|
324
502
|
const close = vi.fn(async () => {});
|
|
325
503
|
const onOpenCodeRestarted = vi.fn();
|
|
@@ -9,6 +9,11 @@ import {
|
|
|
9
9
|
const PROVIDER_ID_PATTERN = /^[a-z0-9][a-z0-9-_]*$/;
|
|
10
10
|
const BASE_URL_PATTERN = /^https?:\/\//;
|
|
11
11
|
const OPENAI_COMPATIBLE_NPM = '@ai-sdk/openai-compatible';
|
|
12
|
+
const CUSTOM_PROVIDER_NPM_PACKAGES = new Set([
|
|
13
|
+
OPENAI_COMPATIBLE_NPM,
|
|
14
|
+
'@ai-sdk/openai',
|
|
15
|
+
'@ai-sdk/anthropic',
|
|
16
|
+
]);
|
|
12
17
|
|
|
13
18
|
function getProviderSources(providerId, workingDirectory) {
|
|
14
19
|
const layers = readConfigLayers(workingDirectory);
|
|
@@ -42,7 +47,7 @@ function getProviderSources(providerId, workingDirectory) {
|
|
|
42
47
|
}
|
|
43
48
|
|
|
44
49
|
/**
|
|
45
|
-
* Validate a custom
|
|
50
|
+
* Validate a custom provider config payload before persistence.
|
|
46
51
|
* Returns { ok: true, value } or { ok: false, error }.
|
|
47
52
|
*
|
|
48
53
|
* Credentials: either config.env contains a variable name, or hasStoredAuth is true
|
|
@@ -63,8 +68,8 @@ function validateCustomProviderConfig(providerId, config, options = {}) {
|
|
|
63
68
|
}
|
|
64
69
|
|
|
65
70
|
const npm = typeof config.npm === 'string' ? config.npm.trim() : OPENAI_COMPATIBLE_NPM;
|
|
66
|
-
if (npm
|
|
67
|
-
return { ok: false, error:
|
|
71
|
+
if (!CUSTOM_PROVIDER_NPM_PACKAGES.has(npm)) {
|
|
72
|
+
return { ok: false, error: 'Custom providers must use @ai-sdk/openai-compatible, @ai-sdk/openai, or @ai-sdk/anthropic' };
|
|
68
73
|
}
|
|
69
74
|
|
|
70
75
|
const optionsBlock = isPlainObject(config.options) ? config.options : null;
|
|
@@ -102,7 +107,7 @@ function validateCustomProviderConfig(providerId, config, options = {}) {
|
|
|
102
107
|
}
|
|
103
108
|
|
|
104
109
|
const normalized = {
|
|
105
|
-
npm
|
|
110
|
+
npm,
|
|
106
111
|
name,
|
|
107
112
|
options: {
|
|
108
113
|
baseURL,
|