@openchamber/web 1.18.4 → 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/README.md +1 -0
- package/dist/assets/{CodeMirrorCommentWidgets-4qZbrEXU.js → CodeMirrorCommentWidgets-C36E738Y.js} +1 -1
- package/dist/assets/{CommitSection-MJmntVPJ.js → CommitSection-C-F3AX6D.js} +1 -1
- package/dist/assets/{DiagramEditor-jnG3Hbxg.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-DBFrDDBv.js → GitView-Rp8P1KEI.js} +4 -4
- package/dist/assets/{JsonTreeView-DLW2Wy1g.js → JsonTreeView-KnXFN2A-.js} +1 -1
- package/dist/assets/MarkdownImageGallery-BMn3mtor.js +1 -0
- package/dist/assets/MarkdownRendererImpl-kD6N03pH.js +12 -0
- package/dist/assets/OnboardingScreen-CenIeD4v.js +1 -0
- package/dist/assets/{PatchDiff-BuLPx7AN.js → PatchDiff-BzVOVog8.js} +1 -1
- package/dist/assets/{PierreDiffViewer-BHm4Yr0X.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-CwGocYQd.js → VirtualizedFileDiff-lESMT-2b.js} +4 -4
- package/dist/assets/{WalkthroughView-5DyvN03T.js → WalkthroughView-CaSYE0lw.js} +2 -2
- package/dist/assets/{computeVirtualFileMetrics-Da00Jg7M.js → computeVirtualFileMetrics-DkRR5b75.js} +2 -2
- package/dist/assets/contextPanelEmbeddedChat-BEARQjgn.js +1 -0
- package/dist/assets/de-DFdX3ABv.js +9 -0
- package/dist/assets/document-attachments-DFAWlG3U.js +31 -0
- package/dist/assets/es-iC-FKvV9.js +15 -0
- package/dist/assets/fr-BBbi_1AL.js +13 -0
- package/dist/assets/index-BiEgzzkg.js +1 -0
- package/dist/assets/index-Cwmuwk3V.js +7 -0
- package/dist/assets/index-GNm1wgUH.css +1 -0
- package/dist/assets/{isDiffPlainText-D9YpoLrV.js → isDiffPlainText-BG53Ixxy.js} +1 -1
- package/dist/assets/{isFilePlainText-gTibdNIe.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/{lua-BgMRiT3U.js → lua-VAEuO923.js} +1 -1
- 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-KNkxM1C1.js → patchFileDiff-BcFaMtMu.js} +1 -1
- 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-CDfHS5rr.js +25 -0
- package/dist/assets/runtimeEndpointReset-ovNbaZ-x.js +15 -0
- package/dist/assets/scheduledTasksApi-BFSlqgnG.js +1 -0
- package/dist/assets/{shikiHighlight-C7LTbwFx.js → shikiHighlight-DCT2Sq_z.js} +1 -1
- package/dist/assets/uk-PhsC-c4-.js +15 -0
- package/dist/assets/{useAppFontEffects-BikB6enL.js → useAppFontEffects-B53Rb6m7.js} +168 -164
- package/dist/assets/useInlineCommentController-DSfrIBKT.js +2 -0
- package/dist/assets/{vendor-base-ui-D_V6hAcE.js → vendor-base-ui-DsHmyMwp.js} +1 -1
- package/dist/assets/vendor-codemirror-autocomplete-DzPz9Wgq.js +1 -0
- package/dist/assets/vendor-codemirror-commands-B7H_j0iU.js +1 -0
- package/dist/assets/{vendor-codemirror-lang-angular-CgY7_gQ1.js → vendor-codemirror-lang-angular-DEPs2M5t.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-cpp-B5Ta4enQ.js → vendor-codemirror-lang-cpp-DhkseaMo.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-css-VgNqFSH-.js → vendor-codemirror-lang-css-O0cZX78y.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-go-LxLz62pp.js → vendor-codemirror-lang-go-fMdQYcON.js} +1 -1
- package/dist/assets/vendor-codemirror-lang-html-CfgK872x.js +1 -0
- package/dist/assets/{vendor-codemirror-lang-java-Bksi1PH4.js → vendor-codemirror-lang-java-CQj4S3zl.js} +1 -1
- package/dist/assets/vendor-codemirror-lang-javascript-Cc2ZYbgX.js +13 -0
- package/dist/assets/{vendor-codemirror-lang-jinja-C7npuDD7.js → vendor-codemirror-lang-jinja-BmZZv8g-.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-json-ryCw7nab.js → vendor-codemirror-lang-json-CMBS2tG9.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-less-BxsZJD6N.js → vendor-codemirror-lang-less-C6Eo8hVS.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-liquid-De6qch10.js → vendor-codemirror-lang-liquid-DSTR47-H.js} +1 -1
- package/dist/assets/vendor-codemirror-lang-markdown-BPGOH9ye.js +1 -0
- package/dist/assets/{vendor-codemirror-lang-php-Cm1es33p.js → vendor-codemirror-lang-php-DD9udfPH.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-python-N414WYK-.js → vendor-codemirror-lang-python-HahnQaAS.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-rust-C_WuUStH.js → vendor-codemirror-lang-rust-nLTovbjv.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-sass-8UHTCAOM.js → vendor-codemirror-lang-sass-pL2Yc72v.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-sql-CV3sMA5D.js → vendor-codemirror-lang-sql-BVBnan19.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-vue-DzvC1Dhk.js → vendor-codemirror-lang-vue-BqGzJVm1.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-wast-jlr-LDdA.js → vendor-codemirror-lang-wast-B0_m5DqU.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-xml-CrO63OVp.js → vendor-codemirror-lang-xml-Dj3voadT.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-yaml-dxi6CISW.js → vendor-codemirror-lang-yaml-yu-9Z5u7.js} +1 -1
- package/dist/assets/vendor-codemirror-language-BgPj_McA.js +3 -0
- package/dist/assets/{vendor-codemirror-language-data-CLHw8NWn.js → vendor-codemirror-language-data-vch3tJ4c.js} +2 -2
- package/dist/assets/vendor-codemirror-search-BmS-GmcX.js +2 -0
- package/dist/assets/{vendor-codemirror-state-CNWM3Q8V.js → vendor-codemirror-state-C9awkmn-.js} +5 -5
- package/dist/assets/vendor-codemirror-view-CiLROUVV.js +4 -0
- package/dist/assets/vendor-replit-codemirror-vim-B2DJlAhT.js +6 -0
- package/dist/assets/vendor-replit-codemirror-vim-core-FHzKdNUS.js +34 -0
- package/dist/assets/vendor-zod-C9ioTTSo.js +39 -0
- package/dist/assets/{web-components-GMc3oR3i.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 +152 -3
- package/server/lib/agent-memory/actions.js +243 -0
- package/server/lib/agent-memory/actions.test.js +343 -0
- package/server/lib/agent-memory/feature-flag.js +19 -0
- package/server/lib/agent-memory/feature-flag.test.js +38 -0
- package/server/lib/agent-memory/project-resolution.js +65 -0
- package/server/lib/agent-memory/project-resolution.test.js +94 -0
- package/server/lib/agent-memory/routes.http.test.js +270 -0
- package/server/lib/agent-memory/routes.js +169 -0
- package/server/lib/agent-memory/runtime.js +432 -0
- package/server/lib/agent-memory/runtime.test.js +344 -0
- package/server/lib/agent-memory/threat-patterns.js +61 -0
- package/server/lib/agent-memory/threat-patterns.test.js +61 -0
- package/server/lib/agent-tool/DOCUMENTATION.md +14 -0
- package/server/lib/agent-tool/runtime.js +63 -13
- package/server/lib/agent-tool/runtime.test.js +85 -2
- package/server/lib/context-obligatory/runtime.js +34 -3
- package/server/lib/context-obligatory/runtime.test.js +114 -0
- 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/DOCUMENTATION.md +3 -0
- package/server/lib/fs/routes.js +149 -32
- package/server/lib/fs/routes.test.js +301 -0
- package/server/lib/git/DOCUMENTATION.md +8 -0
- package/server/lib/git/routes.js +43 -0
- package/server/lib/git/service.js +206 -72
- package/server/lib/git/service.test.js +222 -0
- package/server/lib/github/DOCUMENTATION.md +14 -3
- package/server/lib/github/pr-status.js +188 -83
- package/server/lib/github/pr-status.test.js +182 -0
- package/server/lib/github/routes.js +36 -30
- package/server/lib/notifications/template-runtime.js +2 -3
- package/server/lib/openchamber-control/action-resolution.test.js +65 -0
- package/server/lib/openchamber-control/actions.js +78 -0
- package/server/lib/openchamber-control/service.js +7 -0
- package/server/lib/openchamber-sessions/routes.js +14 -0
- package/server/lib/opencode/DOCUMENTATION.md +12 -6
- package/server/lib/opencode/claude-cli-auth.js +60 -0
- package/server/lib/opencode/claude-cli-auth.test.js +54 -0
- package/server/lib/opencode/feature-routes-runtime.js +16 -9
- package/server/lib/opencode/lifecycle.js +202 -26
- package/server/lib/opencode/lifecycle.test.js +179 -1
- package/server/lib/opencode/plugins.js +12 -3
- package/server/lib/opencode/plugins.test.js +18 -0
- package/server/lib/opencode/providers.js +9 -4
- package/server/lib/opencode/providers.test.js +27 -0
- package/server/lib/opencode/proxy-agent-wiring.test.js +152 -0
- package/server/lib/opencode/proxy.js +116 -6
- package/server/lib/opencode/proxy.test.js +158 -1
- package/server/lib/opencode/restart-session-recovery.test.js +59 -0
- package/server/lib/opencode/routes.js +4 -1
- 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 +26 -0
- package/server/lib/opencode/settings-helpers.test.js +57 -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 +83 -10
- package/server/lib/opencode/settings-runtime.test.js +85 -0
- package/server/lib/opencode/shared.js +120 -16
- package/server/lib/opencode/shared.test.js +185 -1
- 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 +160 -0
- package/server/lib/project-context/routes.http.test.js +264 -0
- package/server/lib/project-context/routes.js +237 -0
- package/server/lib/project-context/runtime.js +672 -0
- package/server/lib/project-context/runtime.test.js +498 -0
- package/server/lib/projects/project-config.js +7 -2
- package/server/lib/quota/DOCUMENTATION.md +17 -2
- package/server/lib/quota/providers/claude/auth.js +113 -0
- package/server/lib/quota/providers/claude/auth.test.js +117 -0
- package/server/lib/quota/providers/claude/index.js +151 -0
- package/server/lib/quota/providers/claude/index.test.js +147 -0
- package/server/lib/quota/providers/claude/transforms.js +127 -0
- package/server/lib/quota/providers/claude/transforms.test.js +82 -0
- package/server/lib/quota/providers/command-code.js +90 -0
- package/server/lib/quota/providers/command-code.test.js +85 -0
- package/server/lib/quota/providers/index.js +30 -2
- package/server/lib/quota/providers/index.test.js +10 -1
- package/server/lib/quota/providers/zai.js +26 -6
- package/server/lib/quota/providers/zai.test.js +33 -0
- package/server/lib/quota/utils/formatters.js +2 -1
- package/server/lib/scheduled-tasks/runtime.js +21 -2
- package/server/lib/session-knowledge/DOCUMENTATION.md +89 -0
- package/server/lib/session-knowledge/routes.js +107 -0
- package/server/lib/session-knowledge/runtime.js +331 -0
- package/server/lib/session-knowledge/runtime.test.js +275 -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 +10 -0
- 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 +57 -6
- package/server/lib/small-model/index.test.js +102 -2
- package/server/lib/small-model/routes.js +4 -2
- 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-CFXxgg_a.js +0 -1
- package/dist/assets/DiffView-DZIoOnV7.js +0 -4
- package/dist/assets/FilesView-BKL6YlKG.js +0 -14
- package/dist/assets/MarkdownImageGallery-DKIylIK7.js +0 -1
- package/dist/assets/MarkdownRendererImpl-CLv8hxvv.js +0 -12
- package/dist/assets/OnboardingScreen-D2Y6djMw.js +0 -1
- package/dist/assets/PlanView-ZYEJn8A_.js +0 -4
- package/dist/assets/SessionSwitcherDropdown-rro-SsaO.js +0 -1
- package/dist/assets/SettingsView-5RmswFZe.js +0 -28
- package/dist/assets/SettingsWindow-BZhAYFdS.js +0 -1
- package/dist/assets/ToolOutputDialog-Za6V4VMJ.js +0 -15
- package/dist/assets/ToolPartDiffPreview-BL-9ixyC.js +0 -8
- package/dist/assets/contextPanelEmbeddedChat-B-bSg3P5.js +0 -1
- package/dist/assets/de-u7gSnqWs.js +0 -9
- package/dist/assets/document-attachments-CX_YaDsu.js +0 -30
- package/dist/assets/es-T9O7aAOr.js +0 -15
- package/dist/assets/fr-Oor7ewbE.js +0 -13
- package/dist/assets/index-BzIpNlNE.css +0 -1
- package/dist/assets/index-C0yNhuZw.js +0 -1
- package/dist/assets/index-DRpChWux.js +0 -7
- package/dist/assets/ja-DHpqbVmr.js +0 -15
- package/dist/assets/ko-CwLkS3nx.js +0 -15
- package/dist/assets/main-D7UcL3VQ.js +0 -2
- package/dist/assets/main-DPMd2iKS.js +0 -915
- package/dist/assets/markdownCore-DDrHVneM.js +0 -2
- package/dist/assets/miniChat-O_GVoEbc.js +0 -2
- package/dist/assets/mobile-Br4TtAqc.js +0 -2
- package/dist/assets/pl-CcZILN8q.js +0 -15
- package/dist/assets/pt-BR-DYHhVK6o.js +0 -15
- package/dist/assets/renderElectronMiniChatApp-CJpdxTT1.js +0 -2
- package/dist/assets/renderMobileApp-toj9cXoh.js +0 -25
- package/dist/assets/runtimeEndpointReset-BVmispdD.js +0 -13
- package/dist/assets/scheduledTasksApi-ByKya3Un.js +0 -1
- package/dist/assets/uk-BA2kZR38.js +0 -15
- package/dist/assets/useInlineCommentController-CYPvYJDt.js +0 -2
- package/dist/assets/vendor-codemirror-autocomplete-BjbBRsUA.js +0 -1
- package/dist/assets/vendor-codemirror-commands-ARAOgp1x.js +0 -1
- package/dist/assets/vendor-codemirror-lang-html-B3Qe3OpS.js +0 -1
- package/dist/assets/vendor-codemirror-lang-javascript-Bbw3D7r0.js +0 -13
- package/dist/assets/vendor-codemirror-lang-markdown-FGQydhTc.js +0 -1
- package/dist/assets/vendor-codemirror-language-DUOssd4j.js +0 -3
- package/dist/assets/vendor-codemirror-search-8kyQdB3f.js +0 -2
- package/dist/assets/vendor-codemirror-view-DSzLbZiS.js +0 -4
- package/dist/assets/vendor-replit-codemirror-vim-B0Ecqnlh.js +0 -39
- package/dist/assets/zh-CN-dlOQK6v9.js +0 -15
- package/dist/assets/zh-TW-BnqQ-WL5.js +0 -15
- package/server/lib/quota/providers/claude.js +0 -107
- 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
|
@@ -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();
|
|
@@ -4,6 +4,7 @@ import path from 'path';
|
|
|
4
4
|
import {
|
|
5
5
|
AGENT_SCOPE,
|
|
6
6
|
readConfigFile,
|
|
7
|
+
readConfigLayer,
|
|
7
8
|
writeConfig,
|
|
8
9
|
} from './shared.js';
|
|
9
10
|
import { isPathSpec } from './plugin-spec.js';
|
|
@@ -111,15 +112,23 @@ function readPluginConfigLayers(workingDirectory) {
|
|
|
111
112
|
const customPath = getActiveCustomConfigPath();
|
|
112
113
|
const userPath = getPrimaryUserConfigPath();
|
|
113
114
|
const projectPath = getProjectConfigPath(workingDirectory);
|
|
115
|
+
const userLayer = readConfigLayer(userPath);
|
|
116
|
+
const projectLayer = readConfigLayer(projectPath);
|
|
117
|
+
const customLayer = readConfigLayer(customPath);
|
|
114
118
|
return {
|
|
115
|
-
userConfig:
|
|
116
|
-
projectConfig:
|
|
117
|
-
customConfig:
|
|
119
|
+
userConfig: userLayer.config,
|
|
120
|
+
projectConfig: projectLayer.config,
|
|
121
|
+
customConfig: customLayer.config,
|
|
118
122
|
paths: {
|
|
119
123
|
userPath,
|
|
120
124
|
projectPath,
|
|
121
125
|
customPath,
|
|
122
126
|
},
|
|
127
|
+
layerErrors: [
|
|
128
|
+
userLayer.error && { path: userPath, code: userLayer.error.code, message: userLayer.error.message },
|
|
129
|
+
projectLayer.error && projectPath && { path: projectPath, code: projectLayer.error.code, message: projectLayer.error.message },
|
|
130
|
+
customLayer.error && customPath && { path: customPath, code: customLayer.error.code, message: customLayer.error.message },
|
|
131
|
+
].filter(Boolean),
|
|
123
132
|
};
|
|
124
133
|
}
|
|
125
134
|
|
|
@@ -121,6 +121,24 @@ describe('opencode plugins data layer', () => {
|
|
|
121
121
|
expect(readJson(userConfigPath)).toEqual({});
|
|
122
122
|
});
|
|
123
123
|
|
|
124
|
+
test('lists user plugins when a project layer is unparseable', () => {
|
|
125
|
+
const partialProject = [
|
|
126
|
+
'{',
|
|
127
|
+
' "$schema": "https://opencode.ai/config.json",',
|
|
128
|
+
' plugin: ["broken-project-plugin"],',
|
|
129
|
+
'}',
|
|
130
|
+
'',
|
|
131
|
+
].join('\n');
|
|
132
|
+
writeJson(userConfigPath, { plugin: ['user-plugin'] });
|
|
133
|
+
const projectFile = path.join(projectDir, '.opencode', 'opencode.jsonc');
|
|
134
|
+
fs.mkdirSync(path.dirname(projectFile), { recursive: true });
|
|
135
|
+
fs.writeFileSync(projectFile, partialProject, 'utf8');
|
|
136
|
+
|
|
137
|
+
expect(plugins.listPluginEntries(projectDir).map((entry) => entry.spec)).toEqual(['user-plugin']);
|
|
138
|
+
expect(fs.readFileSync(projectFile, 'utf8')).toBe(partialProject);
|
|
139
|
+
expect(fs.existsSync(`${projectFile}.openchamber.backup`)).toBe(false);
|
|
140
|
+
});
|
|
141
|
+
|
|
124
142
|
test('lists entries from user and project layers with scopes and parsed kinds', () => {
|
|
125
143
|
writeJson(userConfigPath, { plugin: ['npm-plugin', '/abs/plugin.js', '@scope/pkg@1.0.0'] });
|
|
126
144
|
writeJson(path.join(projectDir, '.opencode', 'opencode.json'), { plugin: ['./local-plugin.js'] });
|
|
@@ -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,
|