@neuralnomads/codenomad-dev 0.20.0-dev-20260922-0a31a8b3 → 0.20.0-dev-20260924-70aae0b1

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.
Files changed (155) hide show
  1. package/README.md +1 -0
  2. package/dist/api-types.js.map +1 -1
  3. package/dist/opencode/runtime-support.js +1 -1
  4. package/dist/opencode/runtime-support.js.map +1 -1
  5. package/dist/opencode/runtime-support.test.js +2 -2
  6. package/dist/opencode/runtime-support.test.js.map +1 -1
  7. package/dist/opencode-update/installation-lock.js +43 -0
  8. package/dist/opencode-update/installation-lock.js.map +1 -0
  9. package/dist/opencode-update/npm-runtime.js +22 -0
  10. package/dist/opencode-update/npm-runtime.js.map +1 -0
  11. package/dist/opencode-update/retired-installation.js +41 -0
  12. package/dist/opencode-update/retired-installation.js.map +1 -0
  13. package/dist/opencode-update/retired-installation.test.js +39 -0
  14. package/dist/opencode-update/retired-installation.test.js.map +1 -0
  15. package/dist/opencode-update/service.js +18 -10
  16. package/dist/opencode-update/service.js.map +1 -1
  17. package/dist/opencode-update/service.test.js +29 -7
  18. package/dist/opencode-update/service.test.js.map +1 -1
  19. package/dist/opencode-update/shared-installation.js +189 -0
  20. package/dist/opencode-update/shared-installation.js.map +1 -0
  21. package/dist/opencode-update/shared-installation.test.js +270 -0
  22. package/dist/opencode-update/shared-installation.test.js.map +1 -0
  23. package/dist/opencode-update/user-path.js +85 -0
  24. package/dist/opencode-update/user-path.js.map +1 -0
  25. package/dist/plugins/session-pruning/plugin.mjs +15 -3
  26. package/dist/server/__tests__/session-environment.test.js +21 -1
  27. package/dist/server/__tests__/session-environment.test.js.map +1 -1
  28. package/dist/server/http-server.js +52 -16
  29. package/dist/server/http-server.js.map +1 -1
  30. package/dist/server/routes/opencode-update.js +3 -0
  31. package/dist/server/routes/opencode-update.js.map +1 -1
  32. package/dist/server/routes/opencode-update.test.js +18 -0
  33. package/dist/server/routes/opencode-update.test.js.map +1 -1
  34. package/dist/server/routes/settings.js +2 -1
  35. package/dist/server/routes/settings.js.map +1 -1
  36. package/dist/server/routes/workspaces.js +5 -2
  37. package/dist/server/routes/workspaces.js.map +1 -1
  38. package/dist/server/routes/worktrees.js +3 -0
  39. package/dist/server/routes/worktrees.js.map +1 -1
  40. package/dist/settings/binaries.js +9 -5
  41. package/dist/settings/binaries.js.map +1 -1
  42. package/dist/settings/binaries.test.js +2 -2
  43. package/dist/settings/binaries.test.js.map +1 -1
  44. package/dist/workspaces/git-requirement.js +34 -0
  45. package/dist/workspaces/git-requirement.js.map +1 -0
  46. package/dist/workspaces/git-requirement.test.js +139 -0
  47. package/dist/workspaces/git-requirement.test.js.map +1 -0
  48. package/dist/workspaces/git-worktrees.js +2 -1
  49. package/dist/workspaces/git-worktrees.js.map +1 -1
  50. package/dist/workspaces/manager.js +15 -2
  51. package/dist/workspaces/manager.js.map +1 -1
  52. package/dist/workspaces/native-worktrees.js +12 -1
  53. package/dist/workspaces/native-worktrees.js.map +1 -1
  54. package/dist/workspaces/session-git-context.js +41 -0
  55. package/dist/workspaces/session-git-context.js.map +1 -0
  56. package/dist/workspaces/spawn.js +7 -2
  57. package/dist/workspaces/spawn.js.map +1 -1
  58. package/dist/workspaces/worktree-directory.js +2 -1
  59. package/dist/workspaces/worktree-directory.js.map +1 -1
  60. package/dist/workspaces/worktree-session-evacuation.js +11 -3
  61. package/dist/workspaces/worktree-session-evacuation.js.map +1 -1
  62. package/dist/workspaces/worktree-session-evacuation.test.js +18 -0
  63. package/dist/workspaces/worktree-session-evacuation.test.js.map +1 -1
  64. package/package.json +3 -3
  65. package/public/assets/{App-CkXPZUpS.js → App-DXfroBn-.js} +25 -25
  66. package/public/assets/App-DXfroBn-.js.map +1 -0
  67. package/public/assets/{FilesTab-C4o3_OHJ.js → FilesTab-JN0c2Op2.js} +2 -2
  68. package/public/assets/{FilesTab-C4o3_OHJ.js.map → FilesTab-JN0c2Op2.js.map} +1 -1
  69. package/public/assets/{GitChangesTab-ClsL5QrZ.js → GitChangesTab-8MxRVYHz.js} +2 -2
  70. package/public/assets/{GitChangesTab-ClsL5QrZ.js.map → GitChangesTab-8MxRVYHz.js.map} +1 -1
  71. package/public/assets/{SplitFilePanel-C_dI-kjb.js → SplitFilePanel-VXkE7jgT.js} +2 -2
  72. package/public/assets/{SplitFilePanel-C_dI-kjb.js.map → SplitFilePanel-VXkE7jgT.js.map} +1 -1
  73. package/public/assets/{StatusTab-_gvxV-qq.js → StatusTab-DljyzM07.js} +2 -2
  74. package/public/assets/{StatusTab-_gvxV-qq.js.map → StatusTab-DljyzM07.js.map} +1 -1
  75. package/public/assets/{align-justify-CboH-c3n.js → align-justify-BMi4r2XK.js} +2 -2
  76. package/public/assets/{align-justify-CboH-c3n.js.map → align-justify-BMi4r2XK.js.map} +1 -1
  77. package/public/assets/{bundle-full-CL2fEEcE.js → bundle-full-LgLNZmib.js} +2 -2
  78. package/public/assets/{bundle-full-CL2fEEcE.js.map → bundle-full-LgLNZmib.js.map} +1 -1
  79. package/public/assets/{client-state-BB0go4Xe.js → client-state-DTQzqBPJ.js} +2 -2
  80. package/public/assets/{client-state-BB0go4Xe.js.map → client-state-DTQzqBPJ.js.map} +1 -1
  81. package/public/assets/{diff-viewer-C-B3vwne.js → diff-viewer-Dxjea-rB.js} +2 -2
  82. package/public/assets/{diff-viewer-C-B3vwne.js.map → diff-viewer-Dxjea-rB.js.map} +1 -1
  83. package/public/assets/index-9bba6B1A.js +2 -0
  84. package/public/assets/index-9bba6B1A.js.map +1 -0
  85. package/public/assets/index-C5i7ut9u.js +2 -0
  86. package/public/assets/index-C5i7ut9u.js.map +1 -0
  87. package/public/assets/index-CLtLzsWy.js +2 -0
  88. package/public/assets/index-CLtLzsWy.js.map +1 -0
  89. package/public/assets/index-CTVIWXHZ.js +2 -0
  90. package/public/assets/index-CTVIWXHZ.js.map +1 -0
  91. package/public/assets/{index-DrTKEExa.js → index-Cgp1TEtC.js} +2 -2
  92. package/public/assets/{index-DrTKEExa.js.map → index-Cgp1TEtC.js.map} +1 -1
  93. package/public/assets/index-Cqd_P8c4.js +2 -0
  94. package/public/assets/index-Cqd_P8c4.js.map +1 -0
  95. package/public/assets/{index-CheaKG9m.js → index-DTGOXoDH.js} +2 -2
  96. package/public/assets/{index-CheaKG9m.js.map → index-DTGOXoDH.js.map} +1 -1
  97. package/public/assets/index-D_H_gYdX.js +2 -0
  98. package/public/assets/index-D_H_gYdX.js.map +1 -0
  99. package/public/assets/index-Dsd7n295.js +2 -0
  100. package/public/assets/index-Dsd7n295.js.map +1 -0
  101. package/public/assets/index-DwKq8v48.js +3 -0
  102. package/public/assets/index-DwKq8v48.js.map +1 -0
  103. package/public/assets/index-TnTncRlr.js +2 -0
  104. package/public/assets/index-TnTncRlr.js.map +1 -0
  105. package/public/assets/index-eb2qu-xk.js +2 -0
  106. package/public/assets/index-eb2qu-xk.js.map +1 -0
  107. package/public/assets/{loading-Cs2CSqHx.js → loading-j5J_ghLL.js} +2 -2
  108. package/public/assets/{loading-Cs2CSqHx.js.map → loading-j5J_ghLL.js.map} +1 -1
  109. package/public/assets/main-Cv7E0c7r.js +42 -0
  110. package/public/assets/main-Cv7E0c7r.js.map +1 -0
  111. package/public/assets/{markdown-DheZTu4V.js → markdown-Cg65SCwC.js} +4 -4
  112. package/public/assets/{markdown-DheZTu4V.js.map → markdown-Cg65SCwC.js.map} +1 -1
  113. package/public/assets/{startup-state-settings-card-CmMXcnR-.js → startup-state-settings-card-DMFtdRoa.js} +2 -2
  114. package/public/assets/{startup-state-settings-card-CmMXcnR-.js.map → startup-state-settings-card-DMFtdRoa.js.map} +1 -1
  115. package/public/assets/{terminal-square-ypyAq6Ni.js → terminal-square-DCn_Ac2k.js} +2 -2
  116. package/public/assets/{terminal-square-ypyAq6Ni.js.map → terminal-square-DCn_Ac2k.js.map} +1 -1
  117. package/public/assets/{todo-Cgy3-kyM.js → todo-DyaFCX9E.js} +2 -2
  118. package/public/assets/{todo-Cgy3-kyM.js.map → todo-DyaFCX9E.js.map} +1 -1
  119. package/public/assets/{tool-call-0UMa6igS.js → tool-call-DlJUX9AW.js} +21 -21
  120. package/public/assets/{tool-call-0UMa6igS.js.map → tool-call-DlJUX9AW.js.map} +1 -1
  121. package/public/assets/{unified-picker-C-lhbMQ0.js → unified-picker-CrW1bp1Y.js} +2 -2
  122. package/public/assets/{unified-picker-C-lhbMQ0.js.map → unified-picker-CrW1bp1Y.js.map} +1 -1
  123. package/public/assets/{wrap-text-BjODGwnM.js → wrap-text-DLR5jp4s.js} +2 -2
  124. package/public/assets/{wrap-text-BjODGwnM.js.map → wrap-text-DLR5jp4s.js.map} +1 -1
  125. package/public/index.html +2 -2
  126. package/public/loading.html +2 -2
  127. package/public/sw.js +1 -1
  128. package/public/sw.js.map +1 -1
  129. package/dist/opencode-update/managed-installation.js +0 -102
  130. package/dist/opencode-update/managed-installation.js.map +0 -1
  131. package/dist/opencode-update/managed-installation.test.js +0 -102
  132. package/dist/opencode-update/managed-installation.test.js.map +0 -1
  133. package/public/assets/App-CkXPZUpS.js.map +0 -1
  134. package/public/assets/index-4LEntpq0.js +0 -2
  135. package/public/assets/index-4LEntpq0.js.map +0 -1
  136. package/public/assets/index-B2wje_CF.js +0 -2
  137. package/public/assets/index-B2wje_CF.js.map +0 -1
  138. package/public/assets/index-BDbkD8FO.js +0 -2
  139. package/public/assets/index-BDbkD8FO.js.map +0 -1
  140. package/public/assets/index-BbUJLdzG.js +0 -2
  141. package/public/assets/index-BbUJLdzG.js.map +0 -1
  142. package/public/assets/index-Bdh_-CtJ.js +0 -2
  143. package/public/assets/index-Bdh_-CtJ.js.map +0 -1
  144. package/public/assets/index-C9Jqb-tF.js +0 -2
  145. package/public/assets/index-C9Jqb-tF.js.map +0 -1
  146. package/public/assets/index-CIT8ANJK.js +0 -3
  147. package/public/assets/index-CIT8ANJK.js.map +0 -1
  148. package/public/assets/index-DbnGqvtc.js +0 -2
  149. package/public/assets/index-DbnGqvtc.js.map +0 -1
  150. package/public/assets/index-DhOvQD1j.js +0 -2
  151. package/public/assets/index-DhOvQD1j.js.map +0 -1
  152. package/public/assets/index-Gk3Kwcb2.js +0 -2
  153. package/public/assets/index-Gk3Kwcb2.js.map +0 -1
  154. package/public/assets/main-DAwgVcRN.js +0 -42
  155. package/public/assets/main-DAwgVcRN.js.map +0 -1
package/README.md CHANGED
@@ -20,6 +20,7 @@
20
20
 
21
21
  ## Prerequisites
22
22
 
23
+ - **Git**: A prerequisite in the backend process's `PATH` for repository identity, Git operations and worktree management. Without Git, directory-only conversations in the explicitly opened physical folder remain available so the user can ask the agent for installation help. Owned session prompts/custom commands update the native `codenomad.git-availability` instruction; it reports the backend platform and is removed when Git becomes available. Git/worktree operations still fail explicitly with `503`/`git_required`. Install from https://git-scm.com/downloads and restart the backend after changing `PATH`. A Windows per-user installation is sufficient; Git inside WSL alone is insufficient for a Windows backend.
23
24
  - **OpenCode V2**: Install a compatible `opencode2` CLI. CodeNomad uses the CLI's official `service status`, `service start`, and `service get password` lifecycle to connect to OpenCode's externally owned global daemon, then validates its authenticated loopback `/api/status` response rather than enforcing an exact CLI version string.
24
25
  - **OpenCode data**: The global daemon owns its platform-default storage, database, and service registration. Configured startup environment applies only when CodeNomad starts a missing daemon; an existing daemon is unchanged.
25
26
  - **Windows to WSL**: A configured WSL UNC binary uses Linux `service status`, `service start`, and `service get password`; Windows must have WSL localhost forwarding enabled to reach its loopback service.
@@ -1 +1 @@
1
- {"version":3,"file":"api-types.js","sourceRoot":"","sources":["../src/api-types.ts"],"names":[],"mappings":"AA8RA,MAAM,CAAC,MAAM,mBAAmB,GAAG,YAAY,CAAA;AA8E/C,MAAM,CAAC,MAAM,+BAA+B,GAAG,sBAA+B,CAAA;AAC9E,MAAM,CAAC,MAAM,qCAAqC,GAAG,4BAAqC,CAAA","sourcesContent":["import type {\n AgentModelSelection,\n AgentModelSelections,\n ModelPreference,\n OpenCodeBinary,\n Preferences,\n RecentFolder,\n} from \"./config/schema\"\nimport type { OpenCodeEvent } from \"@opencode/client\"\n\n/**\n * Canonical HTTP/SSE contract for the CLI server.\n * These types are consumed by both the CLI implementation and any UI clients.\n */\n\nexport type WorkspaceStatus = \"starting\" | \"ready\" | \"stopped\" | \"error\"\n\nexport interface WorkspaceDescriptor {\n id: string\n /** Correlates creation events with the client request that initiated them. */\n requestId?: string\n /** Absolute path on the server host. */\n path: string\n name?: string\n status: WorkspaceStatus\n /** PID/port are populated when the workspace is running. */\n pid?: number\n port?: number\n /** Canonical proxy path the CLI exposes for this instance. */\n proxyPath: string\n /** Identifier of the binary resolved from config. */\n binaryId: string\n binaryLabel: string\n binaryVersion?: string\n createdAt: string\n updatedAt: string\n /** Present when `status` is \"error\". */\n error?: string\n}\n\nexport interface WorkspaceCreateRequest {\n path: string\n name?: string\n requestId?: string\n}\n\nexport interface WorkspaceCloneRequest {\n repositoryUrl: string\n destinationPath: string\n cleanup?: boolean\n}\n\nexport interface WorkspaceCloneResponse {\n path: string\n}\n\nexport type WorkspaceCreateResponse = WorkspaceDescriptor & {\n /** True when this request did not own creation of the returned workspace. */\n reused?: true\n}\nexport type WorkspaceListResponse = WorkspaceDescriptor[]\nexport type WorkspaceDetailResponse = WorkspaceDescriptor\n\nexport interface WorkspaceDeleteResponse {\n id: string\n status: WorkspaceStatus\n}\n\nexport interface ProviderUsageWindow {\n usedPercent: number | null\n remainingPercent: number | null\n windowSeconds: number | null\n resetAt: number | null\n valueLabel?: string\n}\n\nexport interface ProviderUsageResponse {\n requestedProviderId: string\n providerId: string | null\n providerName: string\n modelId?: string\n supported: boolean\n configured: boolean\n ok: boolean\n windows: Record<string, ProviderUsageWindow>\n fetchedAt: number\n}\n\nexport type WorktreeKind = \"root\" | \"worktree\"\n\nexport interface WorktreeDescriptor {\n /** Stable identifier used by CodeNomad + clients (\"root\" for the selected workspace folder). */\n slug: string\n /** Presentation only; the worktree identifier does not change with its branch. */\n label?: string\n /** Absolute directory path on the server host. */\n directory: string\n /** Equivalent path in the OpenCode service namespace (notably WSL). */\n serviceDirectory?: string\n /** Native checkout root (before mirroring a nested workspace folder). */\n serviceRoot?: string\n /** Exact path registered in Git's worktree inventory. */\n registeredDirectory?: string\n kind: WorktreeKind\n /** False for the opened folder and Git's main checkout. */\n removable?: boolean\n /** Optional VCS branch name when available. */\n branch?: string\n /** Commit recorded by the Git worktree inventory. */\n head?: string\n}\n\nexport interface WorktreeListResponse {\n worktrees: WorktreeDescriptor[]\n /** Default creation parent in the OpenCode service namespace. */\n defaultDirectory?: string\n /** True when the workspace folder resolves to a Git repository. */\n isGitRepo?: boolean\n}\n\nexport interface WorktreeCreateRequest {\n slug: string\n fromSlug?: string\n /** Optional branch name (defaults to slug). */\n branch?: string\n}\n\nexport interface WorktreeSessionMoveRequest {\n worktreeSlug: string\n}\n\nexport interface WorktreeSessionMoveResponse {\n rootSessionId: string\n sessionIds: string[]\n worktreeSlug: string\n}\n\nexport type GitChangeKind = \"added\" | \"modified\" | \"deleted\" | \"renamed\" | \"copied\" | \"untracked\" | \"unmerged\"\n\nexport interface WorktreeGitStatusEntry {\n path: string\n originalPath?: string | null\n stagedStatus: GitChangeKind | null\n stagedAdditions: number\n stagedDeletions: number\n unstagedStatus: GitChangeKind | null\n unstagedAdditions: number\n unstagedDeletions: number\n}\n\nexport type WorktreeGitStatusResponse = WorktreeGitStatusEntry[]\n\nexport type WorktreeGitDiffScope = \"staged\" | \"unstaged\"\n\nexport interface WorktreeGitPathsRequest {\n paths: string[]\n}\n\nexport interface WorktreeGitMutationResponse {\n ok: true\n}\n\nexport interface WorktreeGitCommitRequest {\n message: string\n}\n\nexport interface WorktreeGitCommitResponse {\n ok: true\n commitSha?: string\n}\n\nexport interface WorktreeGitDiffResponse {\n path: string\n originalPath?: string | null\n scope: WorktreeGitDiffScope\n before: string\n after: string\n isBinary?: boolean\n}\n\nexport interface WorktreeGitDiffRequest {\n path: string\n originalPath?: string | null\n scope: WorktreeGitDiffScope\n}\n\nexport type LogLevel = \"debug\" | \"info\" | \"warn\" | \"error\"\n\nexport interface WorkspaceLogEntry {\n workspaceId: string\n timestamp: string\n level: LogLevel\n message: string\n}\n\nexport interface FileSystemEntry {\n name: string\n /**\n * Path identifier for the entry. Relative to the server root in restricted\n * single-root listings (\".\" represents the root itself); absolute in\n * unrestricted, drives, and multi-root top-level listings.\n */\n path: string\n /** Absolute path when available (unrestricted and multi-root listings). */\n absolutePath?: string\n type: \"file\" | \"directory\"\n size?: number\n /** ISO timestamp of last modification when available. */\n modifiedAt?: string\n}\n\nexport type FileSystemScope = \"restricted\" | \"unrestricted\"\nexport type FileSystemPathKind = \"relative\" | \"absolute\" | \"drives\"\n\nexport interface FileSystemListingMetadata {\n scope: FileSystemScope\n /**\n * Canonical identifier of the current view:\n * - \".\" for restricted single-root listings\n * - WINDOWS_DRIVES_ROOT for the Windows drives pseudo-root\n * - absolute path otherwise\n */\n currentPath: string\n /** Optional parent path if navigation upward is allowed. */\n parentPath?: string\n /** Absolute path representing the root or origin point for this listing. */\n rootPath: string\n /** Absolute home directory of the CLI host (useful defaults for unrestricted mode). */\n homePath: string\n /** Human-friendly label for the current path. */\n displayPath: string\n /** Indicates whether entry paths are relative, absolute, or represent the drive pseudo-view. */\n pathKind: FileSystemPathKind\n}\n\nexport interface FileSystemListResponse {\n entries: FileSystemEntry[]\n metadata: FileSystemListingMetadata\n}\n\nexport interface FileSystemCreateFolderRequest {\n /**\n * Path identifier for the currently browsed directory.\n * Matches the `path` parameter used for `/api/filesystem`.\n */\n parentPath?: string\n /** Single folder name (no separators). */\n name: string\n}\n\nexport interface FileSystemCreateFolderResponse {\n /**\n * Path identifier that can be passed back to `/api/filesystem` to browse the new folder.\n * Relative for restricted listings and absolute for unrestricted listings.\n */\n path: string\n /** Absolute folder path on the server host. */\n absolutePath: string\n}\n\nexport interface FileSystemFileContentResponse {\n path: string\n contents: string\n encoding: \"utf-8\" | \"base64\"\n}\n\nexport interface ConfigFileDescriptor {\n id: string\n label: string\n path: string\n language: string\n}\n\nexport type ConfigFileListResponse = ConfigFileDescriptor[]\n\nexport interface ConfigFileContentResponse {\n id: string\n path: string\n contents: string\n exists: boolean\n}\n\nexport interface ConfigFileContentRequest {\n contents: string\n}\n\nexport const WINDOWS_DRIVES_ROOT = \"__drives__\"\n\nexport interface WorkspaceFileResponse {\n workspaceId: string\n relativePath: string\n /** UTF-8 file contents; binary files should be base64 encoded by the caller. */\n contents: string\n encoding?: \"utf-8\" | \"base64\"\n}\n\nexport type WorkspaceFileSearchResponse = FileSystemEntry[]\n\nexport interface InstanceData {\n messageHistory: string[]\n agentModelSelections: AgentModelSelection\n}\n\nexport type InstanceStreamStatus = \"connecting\" | \"connected\" | \"error\" | \"disconnected\"\n\nexport type InstanceStreamEvent = OpenCodeEvent\n\nexport type SideCarKind = \"port\"\n\nexport type SideCarPrefixMode = \"strip\" | \"preserve\"\n\nexport type SideCarStatus = \"running\" | \"stopped\"\n\nexport interface SideCar {\n id: string\n kind: SideCarKind\n name: string\n port: number\n insecure: boolean\n prefixMode: SideCarPrefixMode\n status: SideCarStatus\n createdAt: string\n updatedAt: string\n}\n\nexport interface PreviewSession {\n token: string\n sessionId: string\n targetUrl: string\n proxyUrl: string\n createdAt: string\n}\n\nexport interface BinaryRecord {\n id: string\n path: string\n label: string\n version?: string\n\n /** Indicates that this binary will be picked when workspaces omit an explicit choice. */\n isDefault: boolean\n lastValidatedAt?: string\n validationError?: string\n}\n\nexport type SettingsOwner = string\nexport type SettingsBucket = Record<string, unknown>\nexport type SettingsDoc = Record<string, unknown>\n\nexport interface BinaryListResponse {\n binaries: BinaryRecord[]\n}\n\nexport interface BinaryCreateRequest {\n path: string\n label?: string\n makeDefault?: boolean\n}\n\nexport interface BinaryUpdateRequest {\n label?: string\n makeDefault?: boolean\n}\n\nexport const OPENCODE_V2_REQUIRED_ERROR_CODE = \"opencode_v2_required\" as const\nexport const SESSION_ENVIRONMENT_FAILED_ERROR_CODE = \"session_environment_failed\" as const\n\nexport interface BinaryValidationResult {\n valid: boolean\n version?: string\n error?: string\n errorCode?: typeof OPENCODE_V2_REQUIRED_ERROR_CODE\n}\n\nexport interface OpenCodeUpdateStatus {\n currentVersion: string | null\n latestVersion: string | null\n updateAvailable: boolean | null\n canUpgrade: boolean\n checkError?: \"update_check_failed\"\n minimumVersion: string\n recommendedVersion: string\n versionAssessment: \"tested\" | \"untested\" | \"incompatible\"\n incompatibilityReason?: \"step_timestamp\" | \"canonical_api\" | \"session_environment\"\n state: \"missing\" | \"update_required\" | \"ready\" | \"error\"\n binaryPath: string\n daemonVersion?: string\n serviceState?: \"stopped\" | \"ready\" | \"restart_required\" | \"restart_available\" | \"incompatible\" | \"error\"\n canReload?: boolean\n serviceError?: string\n target: \"host\" | \"wsl\"\n canRestart: boolean\n}\n\nexport interface OpenCodeUpdateResponse {\n success: boolean\n version: string\n}\n\nexport interface SpeechSegment {\n startMs: number\n endMs: number\n text: string\n}\n\nexport interface SpeechCapabilitiesResponse {\n available: boolean\n configured: boolean\n provider: string\n supportsStt: boolean\n supportsTts: boolean\n supportsStreamingTts: boolean\n baseUrl?: string\n sttModel: string\n ttsModel: string\n ttsVoice: string\n ttsFormats: string[]\n streamingTtsFormats: string[]\n separateProviders?: boolean\n sttConfigured?: boolean\n ttsConfigured?: boolean\n sttBaseUrl?: string\n ttsBaseUrl?: string\n}\n\nexport interface SpeechTranscriptionResponse {\n text: string\n language?: string\n durationMs?: number\n segments?: SpeechSegment[]\n}\n\nexport interface SpeechSynthesisResponse {\n audioBase64: string\n mimeType: string\n}\n\nexport interface YoloStateResponse {\n enabled: boolean\n}\n\nexport interface RemoteServerProfile {\n id: string\n name: string\n baseUrl: string\n skipTlsVerify: boolean\n createdAt: string\n updatedAt: string\n lastConnectedAt?: string\n}\n\nexport interface RemoteServerProbeRequest {\n baseUrl: string\n skipTlsVerify?: boolean\n}\n\nexport interface RemoteServerProbeResponse {\n ok: boolean\n reachable: boolean\n normalizedUrl: string\n skipTlsVerify: boolean\n requiresAuth: boolean\n authenticated: boolean\n error?: string\n errorCode?: string\n}\n\nexport interface RemoteProxySessionCreateRequest {\n baseUrl: string\n skipTlsVerify?: boolean\n}\n\nexport interface RemoteProxySessionCreateResponse {\n sessionId: string\n windowUrl: string\n}\n\nexport type WorkspaceEventType =\n | \"workspace.created\"\n | \"workspace.started\"\n | \"workspace.error\"\n | \"workspace.stopped\"\n | \"workspace.log\"\n | \"workspace.worktreesChanged\"\n | \"sidecar.updated\"\n | \"sidecar.removed\"\n | \"storage.configChanged\"\n | \"storage.stateChanged\"\n | \"instance.dataChanged\"\n | \"instance.event\"\n | \"instance.eventStatus\"\n | \"yolo.stateChanged\"\n | \"yolo.autoAccepted\"\n\nexport type WorkspaceEventPayload =\n | { type: \"workspace.created\"; workspace: WorkspaceDescriptor }\n | { type: \"workspace.started\"; workspace: WorkspaceDescriptor }\n | { type: \"workspace.error\"; workspace: WorkspaceDescriptor }\n | { type: \"workspace.stopped\"; workspaceId: string; reason?: \"deleted\" | \"stopped\" }\n | { type: \"workspace.log\"; entry: WorkspaceLogEntry }\n | { type: \"workspace.worktreesChanged\"; workspaceId: string }\n | { type: \"sidecar.updated\"; sidecar: SideCar }\n | { type: \"sidecar.removed\"; sidecarId: string }\n | { type: \"storage.configChanged\"; owner: SettingsOwner; value: SettingsBucket }\n | { type: \"storage.stateChanged\"; owner: SettingsOwner; value: SettingsBucket }\n | { type: \"instance.dataChanged\"; instanceId: string; data: InstanceData }\n | { type: \"instance.event\"; instanceId: string; event: InstanceStreamEvent }\n | { type: \"instance.eventStatus\"; instanceId: string; status: InstanceStreamStatus; generation: number; reason?: string }\n | { type: \"yolo.stateChanged\"; instanceId: string; sessionId: string; enabled: boolean }\n | { type: \"yolo.autoAccepted\"; instanceId: string; sessionId: string; permissionId: string }\n\nexport interface NetworkAddress {\n ip: string\n family: \"ipv4\" | \"ipv6\"\n scope: \"external\" | \"internal\" | \"loopback\"\n /** Remote URL using the server's remote protocol/port for this IP. */\n remoteUrl: string\n}\n\nexport interface LatestReleaseInfo {\n version: string\n tag: string\n url: string\n channel: \"stable\" | \"dev\"\n publishedAt?: string\n notes?: string\n}\n\nexport interface UiMeta {\n version?: string\n source: \"bundled\" | \"downloaded\" | \"previous\" | \"override\" | \"dev-proxy\" | \"missing\"\n}\n\nexport interface SupportMeta {\n supported: boolean\n message?: string\n minServerVersion?: string\n latestServerVersion?: string\n latestServerUrl?: string\n}\n\nexport interface ServerMeta {\n /** URL desktop apps should use to connect (prefers loopback HTTP when enabled). */\n localUrl: string\n /** URL remote clients should use (prefers HTTPS when enabled). */\n remoteUrl?: string\n /** SSE endpoint advertised to clients (`/api/events` by default). */\n eventsUrl: string\n /** Host the server is bound to (e.g., 127.0.0.1 or 0.0.0.0). */\n host: string\n /** Listening mode derived from host binding. */\n listeningMode: \"local\" | \"all\"\n /** Actual local port in use after binding. */\n localPort: number\n /** Actual remote port in use after binding (when remoteUrl is set). */\n remotePort?: number\n /** Display label for the host (e.g., hostname or friendly name). */\n hostLabel: string\n /** Absolute path of the filesystem root exposed to clients. */\n workspaceRoot: string\n /** Reachable addresses for this server, external first. */\n addresses: NetworkAddress[]\n serverVersion?: string\n ui?: UiMeta\n support?: SupportMeta\n /** Optional update info (dev channel only). */\n update?: LatestReleaseInfo | null\n}\n\nexport type {\n Preferences,\n ModelPreference,\n AgentModelSelections,\n RecentFolder,\n OpenCodeBinary,\n}\nexport type { PruneRequest, PruneResult } from \"./opencode/session-pruning/contract\"\n"]}
1
+ {"version":3,"file":"api-types.js","sourceRoot":"","sources":["../src/api-types.ts"],"names":[],"mappings":"AAkSA,MAAM,CAAC,MAAM,mBAAmB,GAAG,YAAY,CAAA;AA8E/C,MAAM,CAAC,MAAM,+BAA+B,GAAG,sBAA+B,CAAA;AAC9E,MAAM,CAAC,MAAM,qCAAqC,GAAG,4BAAqC,CAAA","sourcesContent":["import type {\n AgentModelSelection,\n AgentModelSelections,\n ModelPreference,\n OpenCodeBinary,\n Preferences,\n RecentFolder,\n} from \"./config/schema\"\nimport type { OpenCodeEvent } from \"@opencode/client\"\n\n/**\n * Canonical HTTP/SSE contract for the CLI server.\n * These types are consumed by both the CLI implementation and any UI clients.\n */\n\nexport type WorkspaceStatus = \"starting\" | \"ready\" | \"stopped\" | \"error\"\n\nexport interface WorkspaceDescriptor {\n id: string\n /** Correlates creation events with the client request that initiated them. */\n requestId?: string\n /** Absolute path on the server host. */\n path: string\n name?: string\n status: WorkspaceStatus\n /** PID/port are populated when the workspace is running. */\n pid?: number\n port?: number\n /** Canonical proxy path the CLI exposes for this instance. */\n proxyPath: string\n /** Identifier of the binary resolved from config. */\n binaryId: string\n binaryLabel: string\n binaryVersion?: string\n createdAt: string\n updatedAt: string\n /** Present when `status` is \"error\". */\n error?: string\n}\n\nexport interface WorkspaceCreateRequest {\n path: string\n name?: string\n requestId?: string\n}\n\nexport interface WorkspaceCloneRequest {\n repositoryUrl: string\n destinationPath: string\n cleanup?: boolean\n}\n\nexport interface WorkspaceCloneResponse {\n path: string\n}\n\nexport type WorkspaceCreateResponse = WorkspaceDescriptor & {\n /** True when this request did not own creation of the returned workspace. */\n reused?: true\n}\nexport type WorkspaceListResponse = WorkspaceDescriptor[]\nexport type WorkspaceDetailResponse = WorkspaceDescriptor\n\nexport interface WorkspaceDeleteResponse {\n id: string\n status: WorkspaceStatus\n}\n\nexport interface ProviderUsageWindow {\n usedPercent: number | null\n remainingPercent: number | null\n windowSeconds: number | null\n resetAt: number | null\n valueLabel?: string\n}\n\nexport interface ProviderUsageResponse {\n requestedProviderId: string\n providerId: string | null\n providerName: string\n modelId?: string\n supported: boolean\n configured: boolean\n ok: boolean\n windows: Record<string, ProviderUsageWindow>\n fetchedAt: number\n}\n\nexport type WorktreeKind = \"root\" | \"worktree\"\n\nexport interface WorktreeDescriptor {\n /** Stable identifier used by CodeNomad + clients (\"root\" for the selected workspace folder). */\n slug: string\n /** Presentation only; the worktree identifier does not change with its branch. */\n label?: string\n /** Absolute directory path on the server host. */\n directory: string\n /** Equivalent path in the OpenCode service namespace (notably WSL). */\n serviceDirectory?: string\n /** Native checkout root (before mirroring a nested workspace folder). */\n serviceRoot?: string\n /** Exact path registered in Git's worktree inventory. */\n registeredDirectory?: string\n /** Degraded mode: only this exact physical directory authorizes sessions. */\n directoryOnly?: boolean\n kind: WorktreeKind\n /** False for the opened folder and Git's main checkout. */\n removable?: boolean\n /** Optional VCS branch name when available. */\n branch?: string\n /** Commit recorded by the Git worktree inventory. */\n head?: string\n}\n\nexport interface WorktreeListResponse {\n /** False means directory-only degraded mode; repository membership is unknown. */\n gitAvailable?: boolean\n worktrees: WorktreeDescriptor[]\n /** Default creation parent in the OpenCode service namespace. */\n defaultDirectory?: string\n /** True when the workspace folder resolves to a Git repository. */\n isGitRepo?: boolean\n}\n\nexport interface WorktreeCreateRequest {\n slug: string\n fromSlug?: string\n /** Optional branch name (defaults to slug). */\n branch?: string\n}\n\nexport interface WorktreeSessionMoveRequest {\n worktreeSlug: string\n}\n\nexport interface WorktreeSessionMoveResponse {\n rootSessionId: string\n sessionIds: string[]\n worktreeSlug: string\n}\n\nexport type GitChangeKind = \"added\" | \"modified\" | \"deleted\" | \"renamed\" | \"copied\" | \"untracked\" | \"unmerged\"\n\nexport interface WorktreeGitStatusEntry {\n path: string\n originalPath?: string | null\n stagedStatus: GitChangeKind | null\n stagedAdditions: number\n stagedDeletions: number\n unstagedStatus: GitChangeKind | null\n unstagedAdditions: number\n unstagedDeletions: number\n}\n\nexport type WorktreeGitStatusResponse = WorktreeGitStatusEntry[]\n\nexport type WorktreeGitDiffScope = \"staged\" | \"unstaged\"\n\nexport interface WorktreeGitPathsRequest {\n paths: string[]\n}\n\nexport interface WorktreeGitMutationResponse {\n ok: true\n}\n\nexport interface WorktreeGitCommitRequest {\n message: string\n}\n\nexport interface WorktreeGitCommitResponse {\n ok: true\n commitSha?: string\n}\n\nexport interface WorktreeGitDiffResponse {\n path: string\n originalPath?: string | null\n scope: WorktreeGitDiffScope\n before: string\n after: string\n isBinary?: boolean\n}\n\nexport interface WorktreeGitDiffRequest {\n path: string\n originalPath?: string | null\n scope: WorktreeGitDiffScope\n}\n\nexport type LogLevel = \"debug\" | \"info\" | \"warn\" | \"error\"\n\nexport interface WorkspaceLogEntry {\n workspaceId: string\n timestamp: string\n level: LogLevel\n message: string\n}\n\nexport interface FileSystemEntry {\n name: string\n /**\n * Path identifier for the entry. Relative to the server root in restricted\n * single-root listings (\".\" represents the root itself); absolute in\n * unrestricted, drives, and multi-root top-level listings.\n */\n path: string\n /** Absolute path when available (unrestricted and multi-root listings). */\n absolutePath?: string\n type: \"file\" | \"directory\"\n size?: number\n /** ISO timestamp of last modification when available. */\n modifiedAt?: string\n}\n\nexport type FileSystemScope = \"restricted\" | \"unrestricted\"\nexport type FileSystemPathKind = \"relative\" | \"absolute\" | \"drives\"\n\nexport interface FileSystemListingMetadata {\n scope: FileSystemScope\n /**\n * Canonical identifier of the current view:\n * - \".\" for restricted single-root listings\n * - WINDOWS_DRIVES_ROOT for the Windows drives pseudo-root\n * - absolute path otherwise\n */\n currentPath: string\n /** Optional parent path if navigation upward is allowed. */\n parentPath?: string\n /** Absolute path representing the root or origin point for this listing. */\n rootPath: string\n /** Absolute home directory of the CLI host (useful defaults for unrestricted mode). */\n homePath: string\n /** Human-friendly label for the current path. */\n displayPath: string\n /** Indicates whether entry paths are relative, absolute, or represent the drive pseudo-view. */\n pathKind: FileSystemPathKind\n}\n\nexport interface FileSystemListResponse {\n entries: FileSystemEntry[]\n metadata: FileSystemListingMetadata\n}\n\nexport interface FileSystemCreateFolderRequest {\n /**\n * Path identifier for the currently browsed directory.\n * Matches the `path` parameter used for `/api/filesystem`.\n */\n parentPath?: string\n /** Single folder name (no separators). */\n name: string\n}\n\nexport interface FileSystemCreateFolderResponse {\n /**\n * Path identifier that can be passed back to `/api/filesystem` to browse the new folder.\n * Relative for restricted listings and absolute for unrestricted listings.\n */\n path: string\n /** Absolute folder path on the server host. */\n absolutePath: string\n}\n\nexport interface FileSystemFileContentResponse {\n path: string\n contents: string\n encoding: \"utf-8\" | \"base64\"\n}\n\nexport interface ConfigFileDescriptor {\n id: string\n label: string\n path: string\n language: string\n}\n\nexport type ConfigFileListResponse = ConfigFileDescriptor[]\n\nexport interface ConfigFileContentResponse {\n id: string\n path: string\n contents: string\n exists: boolean\n}\n\nexport interface ConfigFileContentRequest {\n contents: string\n}\n\nexport const WINDOWS_DRIVES_ROOT = \"__drives__\"\n\nexport interface WorkspaceFileResponse {\n workspaceId: string\n relativePath: string\n /** UTF-8 file contents; binary files should be base64 encoded by the caller. */\n contents: string\n encoding?: \"utf-8\" | \"base64\"\n}\n\nexport type WorkspaceFileSearchResponse = FileSystemEntry[]\n\nexport interface InstanceData {\n messageHistory: string[]\n agentModelSelections: AgentModelSelection\n}\n\nexport type InstanceStreamStatus = \"connecting\" | \"connected\" | \"error\" | \"disconnected\"\n\nexport type InstanceStreamEvent = OpenCodeEvent\n\nexport type SideCarKind = \"port\"\n\nexport type SideCarPrefixMode = \"strip\" | \"preserve\"\n\nexport type SideCarStatus = \"running\" | \"stopped\"\n\nexport interface SideCar {\n id: string\n kind: SideCarKind\n name: string\n port: number\n insecure: boolean\n prefixMode: SideCarPrefixMode\n status: SideCarStatus\n createdAt: string\n updatedAt: string\n}\n\nexport interface PreviewSession {\n token: string\n sessionId: string\n targetUrl: string\n proxyUrl: string\n createdAt: string\n}\n\nexport interface BinaryRecord {\n id: string\n path: string\n label: string\n version?: string\n\n /** Indicates that this binary will be picked when workspaces omit an explicit choice. */\n isDefault: boolean\n lastValidatedAt?: string\n validationError?: string\n}\n\nexport type SettingsOwner = string\nexport type SettingsBucket = Record<string, unknown>\nexport type SettingsDoc = Record<string, unknown>\n\nexport interface BinaryListResponse {\n binaries: BinaryRecord[]\n}\n\nexport interface BinaryCreateRequest {\n path: string\n label?: string\n makeDefault?: boolean\n}\n\nexport interface BinaryUpdateRequest {\n label?: string\n makeDefault?: boolean\n}\n\nexport const OPENCODE_V2_REQUIRED_ERROR_CODE = \"opencode_v2_required\" as const\nexport const SESSION_ENVIRONMENT_FAILED_ERROR_CODE = \"session_environment_failed\" as const\n\nexport interface BinaryValidationResult {\n valid: boolean\n version?: string\n error?: string\n errorCode?: typeof OPENCODE_V2_REQUIRED_ERROR_CODE\n}\n\nexport interface OpenCodeUpdateStatus {\n currentVersion: string | null\n latestVersion: string | null\n updateAvailable: boolean | null\n canUpgrade: boolean\n checkError?: \"update_check_failed\"\n minimumVersion: string\n recommendedVersion: string\n versionAssessment: \"tested\" | \"untested\" | \"incompatible\"\n incompatibilityReason?: \"step_timestamp\" | \"canonical_api\" | \"session_environment\"\n state: \"missing\" | \"update_required\" | \"ready\" | \"error\"\n binaryPath: string\n installationSource?: \"path\" | \"user\"\n needsSharedInstallation?: boolean\n daemonVersion?: string\n serviceState?: \"stopped\" | \"ready\" | \"restart_required\" | \"restart_available\" | \"incompatible\" | \"error\"\n canReload?: boolean\n serviceError?: string\n target: \"host\" | \"wsl\"\n canRestart: boolean\n}\n\nexport interface OpenCodeUpdateResponse {\n success: boolean\n version: string\n}\n\nexport interface SpeechSegment {\n startMs: number\n endMs: number\n text: string\n}\n\nexport interface SpeechCapabilitiesResponse {\n available: boolean\n configured: boolean\n provider: string\n supportsStt: boolean\n supportsTts: boolean\n supportsStreamingTts: boolean\n baseUrl?: string\n sttModel: string\n ttsModel: string\n ttsVoice: string\n ttsFormats: string[]\n streamingTtsFormats: string[]\n separateProviders?: boolean\n sttConfigured?: boolean\n ttsConfigured?: boolean\n sttBaseUrl?: string\n ttsBaseUrl?: string\n}\n\nexport interface SpeechTranscriptionResponse {\n text: string\n language?: string\n durationMs?: number\n segments?: SpeechSegment[]\n}\n\nexport interface SpeechSynthesisResponse {\n audioBase64: string\n mimeType: string\n}\n\nexport interface YoloStateResponse {\n enabled: boolean\n}\n\nexport interface RemoteServerProfile {\n id: string\n name: string\n baseUrl: string\n skipTlsVerify: boolean\n createdAt: string\n updatedAt: string\n lastConnectedAt?: string\n}\n\nexport interface RemoteServerProbeRequest {\n baseUrl: string\n skipTlsVerify?: boolean\n}\n\nexport interface RemoteServerProbeResponse {\n ok: boolean\n reachable: boolean\n normalizedUrl: string\n skipTlsVerify: boolean\n requiresAuth: boolean\n authenticated: boolean\n error?: string\n errorCode?: string\n}\n\nexport interface RemoteProxySessionCreateRequest {\n baseUrl: string\n skipTlsVerify?: boolean\n}\n\nexport interface RemoteProxySessionCreateResponse {\n sessionId: string\n windowUrl: string\n}\n\nexport type WorkspaceEventType =\n | \"workspace.created\"\n | \"workspace.started\"\n | \"workspace.error\"\n | \"workspace.stopped\"\n | \"workspace.log\"\n | \"workspace.worktreesChanged\"\n | \"sidecar.updated\"\n | \"sidecar.removed\"\n | \"storage.configChanged\"\n | \"storage.stateChanged\"\n | \"instance.dataChanged\"\n | \"instance.event\"\n | \"instance.eventStatus\"\n | \"yolo.stateChanged\"\n | \"yolo.autoAccepted\"\n\nexport type WorkspaceEventPayload =\n | { type: \"workspace.created\"; workspace: WorkspaceDescriptor }\n | { type: \"workspace.started\"; workspace: WorkspaceDescriptor }\n | { type: \"workspace.error\"; workspace: WorkspaceDescriptor }\n | { type: \"workspace.stopped\"; workspaceId: string; reason?: \"deleted\" | \"stopped\" }\n | { type: \"workspace.log\"; entry: WorkspaceLogEntry }\n | { type: \"workspace.worktreesChanged\"; workspaceId: string }\n | { type: \"sidecar.updated\"; sidecar: SideCar }\n | { type: \"sidecar.removed\"; sidecarId: string }\n | { type: \"storage.configChanged\"; owner: SettingsOwner; value: SettingsBucket }\n | { type: \"storage.stateChanged\"; owner: SettingsOwner; value: SettingsBucket }\n | { type: \"instance.dataChanged\"; instanceId: string; data: InstanceData }\n | { type: \"instance.event\"; instanceId: string; event: InstanceStreamEvent }\n | { type: \"instance.eventStatus\"; instanceId: string; status: InstanceStreamStatus; generation: number; reason?: string }\n | { type: \"yolo.stateChanged\"; instanceId: string; sessionId: string; enabled: boolean }\n | { type: \"yolo.autoAccepted\"; instanceId: string; sessionId: string; permissionId: string }\n\nexport interface NetworkAddress {\n ip: string\n family: \"ipv4\" | \"ipv6\"\n scope: \"external\" | \"internal\" | \"loopback\"\n /** Remote URL using the server's remote protocol/port for this IP. */\n remoteUrl: string\n}\n\nexport interface LatestReleaseInfo {\n version: string\n tag: string\n url: string\n channel: \"stable\" | \"dev\"\n publishedAt?: string\n notes?: string\n}\n\nexport interface UiMeta {\n version?: string\n source: \"bundled\" | \"downloaded\" | \"previous\" | \"override\" | \"dev-proxy\" | \"missing\"\n}\n\nexport interface SupportMeta {\n supported: boolean\n message?: string\n minServerVersion?: string\n latestServerVersion?: string\n latestServerUrl?: string\n}\n\nexport interface ServerMeta {\n /** URL desktop apps should use to connect (prefers loopback HTTP when enabled). */\n localUrl: string\n /** URL remote clients should use (prefers HTTPS when enabled). */\n remoteUrl?: string\n /** SSE endpoint advertised to clients (`/api/events` by default). */\n eventsUrl: string\n /** Host the server is bound to (e.g., 127.0.0.1 or 0.0.0.0). */\n host: string\n /** Listening mode derived from host binding. */\n listeningMode: \"local\" | \"all\"\n /** Actual local port in use after binding. */\n localPort: number\n /** Actual remote port in use after binding (when remoteUrl is set). */\n remotePort?: number\n /** Display label for the host (e.g., hostname or friendly name). */\n hostLabel: string\n /** Absolute path of the filesystem root exposed to clients. */\n workspaceRoot: string\n /** Reachable addresses for this server, external first. */\n addresses: NetworkAddress[]\n serverVersion?: string\n ui?: UiMeta\n support?: SupportMeta\n /** Optional update info (dev channel only). */\n update?: LatestReleaseInfo | null\n}\n\nexport type {\n Preferences,\n ModelPreference,\n AgentModelSelections,\n RecentFolder,\n OpenCodeBinary,\n}\nexport type { PruneRequest, PruneResult } from \"./opencode/session-pruning/contract\"\n"]}
@@ -5,7 +5,7 @@
5
5
  */
6
6
  export const MINIMUM_OPENCODE_VERSION = "2.0.7";
7
7
  /** Qualification target, independent of the technically required minimum. */
8
- export const RECOMMENDED_OPENCODE_VERSION = "2.0.11";
8
+ export const RECOMMENDED_OPENCODE_VERSION = "2.0.15";
9
9
  export const OPENCODE_UPDATE_REQUIRED = "opencode_update_required";
10
10
  export function isBelowOpenCodeMinimum(version) {
11
11
  // These historical V2 beta publications predate the stable event contract.
@@ -1 +1 @@
1
- {"version":3,"file":"runtime-support.js","sourceRoot":"","sources":["../../src/opencode/runtime-support.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,OAAO,CAAA;AAC/C,6EAA6E;AAC7E,MAAM,CAAC,MAAM,4BAA4B,GAAG,QAAQ,CAAA;AACpD,MAAM,CAAC,MAAM,wBAAwB,GAAG,0BAA0B,CAAA;AAElE,MAAM,UAAU,sBAAsB,CAAC,OAAe;IACpD,2EAA2E;IAC3E,IAAI,oBAAoB,CAAC,IAAI,CAAC,OAAO,CAAC;QAAE,OAAO,IAAI,CAAA;IACnD,MAAM,KAAK,GAAG,qCAAqC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IACjE,2EAA2E;IAC3E,4EAA4E;IAC5E,IAAI,CAAC,KAAK;QAAE,OAAO,KAAK,CAAA;IACxB,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;IACxD,MAAM,CAAC,YAAY,EAAE,YAAY,EAAE,YAAY,CAAC,GAAG,wBAAwB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;IAClG,OAAO,KAAM,GAAG,YAAa,IAAI,CAAC,KAAK,KAAK,YAAY,IAAI,CAAC,KAAM,GAAG,YAAa;WAC9E,CAAC,KAAK,KAAK,YAAY,IAAI,KAAM,GAAG,YAAa,CAAC,CAAC,CAAC,CAAA;AAC3D,CAAC;AAID,MAAM,OAAO,wBAAyB,SAAQ,KAAK;IAIjD,YAAqB,aAAqB,EAAW,SAAkC,gBAAgB;QACrG,KAAK,CAAC,GAAG,wBAAwB,cAAc,aAAa,KAAK,MAAM,KAAK,gBAAgB;YAC1F,CAAC,CAAC,iFAAiF,wBAAwB,EAAE;YAC7G,CAAC,CAAC,MAAM,KAAK,qBAAqB,CAAC,CAAC,CAAC,kEAAkE;gBACrG,CAAC,CAAC,gFAAgF,EAAE,CAAC,CAAA;QAJtE,kBAAa,GAAb,aAAa,CAAQ;QAAW,WAAM,GAAN,MAAM,CAA4C;QAH9F,SAAI,GAAG,wBAAwB,CAAA;QAC/B,eAAU,GAAG,GAAG,CAAA;QAChB,mBAAc,GAAG,wBAAwB,CAAA;QAMhD,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAA;IACxC,CAAC;CACF;AAED,MAAM,UAAU,uBAAuB,CAAC,OAAe;IACrD,IAAI,sBAAsB,CAAC,OAAO,CAAC;QAAE,MAAM,IAAI,wBAAwB,CAAC,OAAO,CAAC,CAAA;AAClF,CAAC","sourcesContent":["/**\n * 2.0.7 introduces session.step.started.data.started. The current Solid reducer\n * consumes this native timestamp directly; earlier releases need a retired\n * event adapter. This is a technical floor, not the latest qualified release.\n */\nexport const MINIMUM_OPENCODE_VERSION = \"2.0.7\"\n/** Qualification target, independent of the technically required minimum. */\nexport const RECOMMENDED_OPENCODE_VERSION = \"2.0.11\"\nexport const OPENCODE_UPDATE_REQUIRED = \"opencode_update_required\"\n\nexport function isBelowOpenCodeMinimum(version: string): boolean {\n // These historical V2 beta publications predate the stable event contract.\n if (/^0\\.0\\.0-beta-\\d+$/.test(version)) return true\n const match = /^(\\d+)\\.(\\d+)\\.(\\d+)(?:\\+[\\w.-]+)?$/.exec(version)\n // Custom/prerelease labels are unverified, not automatically incompatible.\n // Their authenticated API contract is inspected before functional requests.\n if (!match) return false\n const [major, minor, patch] = match.slice(1).map(Number)\n const [minimumMajor, minimumMinor, minimumPatch] = MINIMUM_OPENCODE_VERSION.split(\".\").map(Number)\n return major! < minimumMajor! || (major === minimumMajor && (minor! < minimumMinor!\n || (minor === minimumMinor && patch! < minimumPatch!)))\n}\n\nexport type OpenCodeIncompatibility = \"step_timestamp\" | \"canonical_api\" | \"session_environment\"\n\nexport class UnsupportedOpenCodeError extends Error {\n readonly code = OPENCODE_UPDATE_REQUIRED\n readonly statusCode = 426\n readonly minimumVersion = MINIMUM_OPENCODE_VERSION\n constructor(readonly actualVersion: string, readonly reason: OpenCodeIncompatibility = \"step_timestamp\") {\n super(`${OPENCODE_UPDATE_REQUIRED}: OpenCode ${actualVersion}; ${reason === \"step_timestamp\"\n ? `requires the native session.step.started.data.started timestamp introduced in ${MINIMUM_OPENCODE_VERSION}`\n : reason === \"session_environment\" ? \"requires PUT /api/session/{sessionID}/environment with variables\"\n : \"does not expose the canonical session, permission, Form and inbox API contract\"}`)\n this.name = \"UnsupportedOpenCodeError\"\n }\n}\n\nexport function assertSupportedOpenCode(version: string): void {\n if (isBelowOpenCodeMinimum(version)) throw new UnsupportedOpenCodeError(version)\n}\n"]}
1
+ {"version":3,"file":"runtime-support.js","sourceRoot":"","sources":["../../src/opencode/runtime-support.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,OAAO,CAAA;AAC/C,6EAA6E;AAC7E,MAAM,CAAC,MAAM,4BAA4B,GAAG,QAAQ,CAAA;AACpD,MAAM,CAAC,MAAM,wBAAwB,GAAG,0BAA0B,CAAA;AAElE,MAAM,UAAU,sBAAsB,CAAC,OAAe;IACpD,2EAA2E;IAC3E,IAAI,oBAAoB,CAAC,IAAI,CAAC,OAAO,CAAC;QAAE,OAAO,IAAI,CAAA;IACnD,MAAM,KAAK,GAAG,qCAAqC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IACjE,2EAA2E;IAC3E,4EAA4E;IAC5E,IAAI,CAAC,KAAK;QAAE,OAAO,KAAK,CAAA;IACxB,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;IACxD,MAAM,CAAC,YAAY,EAAE,YAAY,EAAE,YAAY,CAAC,GAAG,wBAAwB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;IAClG,OAAO,KAAM,GAAG,YAAa,IAAI,CAAC,KAAK,KAAK,YAAY,IAAI,CAAC,KAAM,GAAG,YAAa;WAC9E,CAAC,KAAK,KAAK,YAAY,IAAI,KAAM,GAAG,YAAa,CAAC,CAAC,CAAC,CAAA;AAC3D,CAAC;AAID,MAAM,OAAO,wBAAyB,SAAQ,KAAK;IAIjD,YAAqB,aAAqB,EAAW,SAAkC,gBAAgB;QACrG,KAAK,CAAC,GAAG,wBAAwB,cAAc,aAAa,KAAK,MAAM,KAAK,gBAAgB;YAC1F,CAAC,CAAC,iFAAiF,wBAAwB,EAAE;YAC7G,CAAC,CAAC,MAAM,KAAK,qBAAqB,CAAC,CAAC,CAAC,kEAAkE;gBACrG,CAAC,CAAC,gFAAgF,EAAE,CAAC,CAAA;QAJtE,kBAAa,GAAb,aAAa,CAAQ;QAAW,WAAM,GAAN,MAAM,CAA4C;QAH9F,SAAI,GAAG,wBAAwB,CAAA;QAC/B,eAAU,GAAG,GAAG,CAAA;QAChB,mBAAc,GAAG,wBAAwB,CAAA;QAMhD,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAA;IACxC,CAAC;CACF;AAED,MAAM,UAAU,uBAAuB,CAAC,OAAe;IACrD,IAAI,sBAAsB,CAAC,OAAO,CAAC;QAAE,MAAM,IAAI,wBAAwB,CAAC,OAAO,CAAC,CAAA;AAClF,CAAC","sourcesContent":["/**\n * 2.0.7 introduces session.step.started.data.started. The current Solid reducer\n * consumes this native timestamp directly; earlier releases need a retired\n * event adapter. This is a technical floor, not the latest qualified release.\n */\nexport const MINIMUM_OPENCODE_VERSION = \"2.0.7\"\n/** Qualification target, independent of the technically required minimum. */\nexport const RECOMMENDED_OPENCODE_VERSION = \"2.0.15\"\nexport const OPENCODE_UPDATE_REQUIRED = \"opencode_update_required\"\n\nexport function isBelowOpenCodeMinimum(version: string): boolean {\n // These historical V2 beta publications predate the stable event contract.\n if (/^0\\.0\\.0-beta-\\d+$/.test(version)) return true\n const match = /^(\\d+)\\.(\\d+)\\.(\\d+)(?:\\+[\\w.-]+)?$/.exec(version)\n // Custom/prerelease labels are unverified, not automatically incompatible.\n // Their authenticated API contract is inspected before functional requests.\n if (!match) return false\n const [major, minor, patch] = match.slice(1).map(Number)\n const [minimumMajor, minimumMinor, minimumPatch] = MINIMUM_OPENCODE_VERSION.split(\".\").map(Number)\n return major! < minimumMajor! || (major === minimumMajor && (minor! < minimumMinor!\n || (minor === minimumMinor && patch! < minimumPatch!)))\n}\n\nexport type OpenCodeIncompatibility = \"step_timestamp\" | \"canonical_api\" | \"session_environment\"\n\nexport class UnsupportedOpenCodeError extends Error {\n readonly code = OPENCODE_UPDATE_REQUIRED\n readonly statusCode = 426\n readonly minimumVersion = MINIMUM_OPENCODE_VERSION\n constructor(readonly actualVersion: string, readonly reason: OpenCodeIncompatibility = \"step_timestamp\") {\n super(`${OPENCODE_UPDATE_REQUIRED}: OpenCode ${actualVersion}; ${reason === \"step_timestamp\"\n ? `requires the native session.step.started.data.started timestamp introduced in ${MINIMUM_OPENCODE_VERSION}`\n : reason === \"session_environment\" ? \"requires PUT /api/session/{sessionID}/environment with variables\"\n : \"does not expose the canonical session, permission, Form and inbox API contract\"}`)\n this.name = \"UnsupportedOpenCodeError\"\n }\n}\n\nexport function assertSupportedOpenCode(version: string): void {\n if (isBelowOpenCodeMinimum(version)) throw new UnsupportedOpenCodeError(version)\n}\n"]}
@@ -5,8 +5,8 @@ import { rememberRuntime } from "./compatibility/runtime";
5
5
  import { OpenCodeSharedService } from "../workspaces/opencode-service";
6
6
  test("native timestamp minimum is distinct from recommendation and unfamiliar version labels", () => {
7
7
  assert.equal(MINIMUM_OPENCODE_VERSION, "2.0.7");
8
- assert.equal(RECOMMENDED_OPENCODE_VERSION, "2.0.11");
9
- for (const version of ["2.0.7", "2.0.8", "2.0.9", "2.0.10", "2.0.11", "2.0.12", "2.1.0", "2.0.11-dev.1", "3.0.0", "custom-build"]) {
8
+ assert.equal(RECOMMENDED_OPENCODE_VERSION, "2.0.15");
9
+ for (const version of ["2.0.7", "2.0.8", "2.0.9", "2.0.10", "2.0.11", "2.0.12", "2.0.13", "2.0.14", "2.0.15", "2.1.0", "2.0.15-dev.1", "3.0.0", "custom-build"]) {
10
10
  assert.equal(isBelowOpenCodeMinimum(version), false, version);
11
11
  }
12
12
  for (const version of ["2.0.0", "2.0.4", "2.0.5", "2.0.6", "0.0.0-beta-19507"])
@@ -1 +1 @@
1
- {"version":3,"file":"runtime-support.test.js","sourceRoot":"","sources":["../../src/opencode/runtime-support.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAA;AACvC,OAAO,IAAI,MAAM,WAAW,CAAA;AAE5B,OAAO,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,wBAAwB,EAAE,4BAA4B,EAAE,MAAM,mBAAmB,CAAA;AAC5I,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AACzD,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAA;AAEtE,IAAI,CAAC,wFAAwF,EAAE,GAAG,EAAE;IAClG,MAAM,CAAC,KAAK,CAAC,wBAAwB,EAAE,OAAO,CAAC,CAAA;IAC/C,MAAM,CAAC,KAAK,CAAC,4BAA4B,EAAE,QAAQ,CAAC,CAAA;IACpD,KAAK,MAAM,OAAO,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,cAAc,CAAC,EAAE,CAAC;QAClI,MAAM,CAAC,KAAK,CAAC,sBAAsB,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,CAAA;IAC/D,CAAC;IACD,KAAK,MAAM,OAAO,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,kBA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c,KAAK,OAAO,IAAI,KAAK,CAAC,MAAM,KAAK,gBAAgB,CAAC,CAAA;IAC9G,MAAM,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC,CAAA;IAC5B,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAA;AAC3B,CAAC,CAAC,CAAA","sourcesContent":["import assert from \"node:assert/strict\"\nimport test from \"node:test\"\nimport type { Endpoint } from \"@opencode/client/service\"\nimport { isBelowOpenCodeMinimum, UnsupportedOpenCodeError, MINIMUM_OPENCODE_VERSION, RECOMMENDED_OPENCODE_VERSION } from \"./runtime-support\"\nimport { rememberRuntime } from \"./compatibility/runtime\"\nimport { OpenCodeSharedService } from \"../workspaces/opencode-service\"\n\ntest(\"native timestamp minimum is distinct from recommendation and unfamiliar version labels\", () => {\n assert.equal(MINIMUM_OPENCODE_VERSION, \"2.0.7\")\n assert.equal(RECOMMENDED_OPENCODE_VERSION, \"2.0.11\")\n for (const version of [\"2.0.7\", \"2.0.8\", \"2.0.9\", \"2.0.10\", \"2.0.11\", \"2.0.12\", \"2.1.0\", \"2.0.11-dev.1\", \"3.0.0\", \"custom-build\"]) {\n assert.equal(isBelowOpenCodeMinimum(version), false, version)\n }\n for (const version of [\"2.0.0\", \"2.0.4\", \"2.0.5\", \"2.0.6\", \"0.0.0-beta-19507\"]) assert.equal(isBelowOpenCodeMinimum(version), true, version)\n})\n\ntest(\"refuses old authenticated daemons before client calls or plugin preparation\", async () => {\n let constructed = 0, prepared = 0\n const endpoint: Endpoint = { url: \"http://127.0.0.1:4321\" }\n rememberRuntime(endpoint, { version: \"2.0.6\", pid: 1, discovery: \"info\" })\n const service = new OpenCodeSharedService({ headers: () => ({ authorization: \"fixture\" }), makeClient: () => { constructed++; throw new Error(\"not reached\") } })\n const options = { kind: \"lifecycle\" as const, identity: \"fixture\",\n lifecycle: { discover: async () => endpoint, ensure: async () => { throw new Error(\"must not start\") } },\n prepareDesktopPlugins: async () => { prepared++; return true },\n }\n await assert.rejects(service.client(options), (error: unknown) => error instanceof UnsupportedOpenCodeError\n && error.actualVersion === \"2.0.6\" && error.minimumVersion === \"2.0.7\" && error.reason === \"step_timestamp\")\n assert.equal(constructed, 0)\n assert.equal(prepared, 0)\n})\n"]}
1
+ {"version":3,"file":"runtime-support.test.js","sourceRoot":"","sources":["../../src/opencode/runtime-support.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAA;AACvC,OAAO,IAAI,MAAM,WAAW,CAAA;AAE5B,OAAO,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,wBAAwB,EAAE,4BAA4B,EAAE,MAAM,mBAAmB,CAAA;AAC5I,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AACzD,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAA;AAEtE,IAAI,CAAC,wFAAwF,EAAE,GAAG,EAAE;IAClG,MAAM,CAAC,KAAK,CAAC,wBAAwB,EAAE,OAAO,CAAC,CAAA;IAC/C,MAAM,CAAC,KAAK,CAAC,4BAA4B,EAAE,QAAQ,CAAC,CAAA;IACpD,KAAK,MAAM,OAAO,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,cAAc,CAAC,EAAE,CAAC;QAChK,MAAM,CAAC,KAAK,CAAC,sBAAsB,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,CAAA;IAC/D,CAAC;IACD,KAAK,MAAM,OAAO,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,kBAAkB,CAAC;QAAE,MAAM,CAAC,KAAK,CAAC,sBAAsB,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,CAAA;AAC9I,CAAC,CAAC,CAAA;A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5B,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAA;AAC3B,CAAC,CAAC,CAAA","sourcesContent":["import assert from \"node:assert/strict\"\nimport test from \"node:test\"\nimport type { Endpoint } from \"@opencode/client/service\"\nimport { isBelowOpenCodeMinimum, UnsupportedOpenCodeError, MINIMUM_OPENCODE_VERSION, RECOMMENDED_OPENCODE_VERSION } from \"./runtime-support\"\nimport { rememberRuntime } from \"./compatibility/runtime\"\nimport { OpenCodeSharedService } from \"../workspaces/opencode-service\"\n\ntest(\"native timestamp minimum is distinct from recommendation and unfamiliar version labels\", () => {\n assert.equal(MINIMUM_OPENCODE_VERSION, \"2.0.7\")\n assert.equal(RECOMMENDED_OPENCODE_VERSION, \"2.0.15\")\n for (const version of [\"2.0.7\", \"2.0.8\", \"2.0.9\", \"2.0.10\", \"2.0.11\", \"2.0.12\", \"2.0.13\", \"2.0.14\", \"2.0.15\", \"2.1.0\", \"2.0.15-dev.1\", \"3.0.0\", \"custom-build\"]) {\n assert.equal(isBelowOpenCodeMinimum(version), false, version)\n }\n for (const version of [\"2.0.0\", \"2.0.4\", \"2.0.5\", \"2.0.6\", \"0.0.0-beta-19507\"]) assert.equal(isBelowOpenCodeMinimum(version), true, version)\n})\n\ntest(\"refuses old authenticated daemons before client calls or plugin preparation\", async () => {\n let constructed = 0, prepared = 0\n const endpoint: Endpoint = { url: \"http://127.0.0.1:4321\" }\n rememberRuntime(endpoint, { version: \"2.0.6\", pid: 1, discovery: \"info\" })\n const service = new OpenCodeSharedService({ headers: () => ({ authorization: \"fixture\" }), makeClient: () => { constructed++; throw new Error(\"not reached\") } })\n const options = { kind: \"lifecycle\" as const, identity: \"fixture\",\n lifecycle: { discover: async () => endpoint, ensure: async () => { throw new Error(\"must not start\") } },\n prepareDesktopPlugins: async () => { prepared++; return true },\n }\n await assert.rejects(service.client(options), (error: unknown) => error instanceof UnsupportedOpenCodeError\n && error.actualVersion === \"2.0.6\" && error.minimumVersion === \"2.0.7\" && error.reason === \"step_timestamp\")\n assert.equal(constructed, 0)\n assert.equal(prepared, 0)\n})\n"]}
@@ -0,0 +1,43 @@
1
+ import { mkdir, open, rm } from "node:fs/promises";
2
+ import path from "node:path";
3
+ export class InstallationBusyError extends Error {
4
+ constructor(code, message) {
5
+ super(message);
6
+ this.code = code;
7
+ }
8
+ }
9
+ /** Serializes CodeNomad backends sharing a standard npm prefix. Never steal a
10
+ * lock on a timeout: an orphaned npm child can outlive its backend. After a crash,
11
+ * remove the lock only after checking that the installer has exited. */
12
+ export async function withInstallationLock(prefix, install) {
13
+ await mkdir(prefix, { recursive: true });
14
+ const lock = path.join(prefix, ".codenomad-opencode-install.lock");
15
+ const handle = await open(lock, "wx", 0o600).catch(error => {
16
+ if (error.code === "EEXIST")
17
+ throw new InstallationBusyError("installation_busy", `OpenCode installation lock exists: ${lock}`);
18
+ throw error;
19
+ });
20
+ try {
21
+ await handle.writeFile(JSON.stringify({ pid: process.pid, started: new Date().toISOString() }));
22
+ return await install();
23
+ }
24
+ finally {
25
+ await handle.close();
26
+ await rm(lock);
27
+ }
28
+ }
29
+ /** Windows forbids writing a mapped executable. Check before npm can retire the
30
+ * old package; do not stop the daemon or leave a partially replaced installation. */
31
+ export async function assertExecutableWritable(binary, platform = process.platform) {
32
+ if (platform !== "win32")
33
+ return;
34
+ try {
35
+ await (await open(binary, "r+")).close();
36
+ }
37
+ catch (error) {
38
+ if (error.code === "ENOENT")
39
+ return;
40
+ throw new InstallationBusyError("installation_in_use", "The OpenCode executable is in use or not writable");
41
+ }
42
+ }
43
+ //# sourceMappingURL=installation-lock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"installation-lock.js","sourceRoot":"","sources":["../../src/opencode-update/installation-lock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAA;AAClD,OAAO,IAAI,MAAM,WAAW,CAAA;AAE5B,MAAM,OAAO,qBAAsB,SA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CAAC,CAAC,KAAK,EAAE,CAAA;IAAC,CAAC;IAChD,OAAO,KAAK,EAAE,CAAC;QACb,IAAK,KAA+B,CAAC,IAAI,KAAK,QAAQ;YAAE,OAAM;QAC9D,MAAM,IAAI,qBAAqB,CAAC,qBAAqB,EAAE,mDAAmD,CAAC,CAAA;IAC7G,CAAC;AACH,CAAC","sourcesContent":["import { mkdir, open, rm } from \"node:fs/promises\"\nimport path from \"node:path\"\n\nexport class InstallationBusyError extends Error {\n constructor(readonly code: \"installation_busy\" | \"installation_in_use\", message: string) {\n super(message)\n }\n}\n\n/** Serializes CodeNomad backends sharing a standard npm prefix. Never steal a\n * lock on a timeout: an orphaned npm child can outlive its backend. After a crash,\n * remove the lock only after checking that the installer has exited. */\nexport async function withInstallationLock<T>(prefix: string, install: () => Promise<T>): Promise<T> {\n await mkdir(prefix, { recursive: true })\n const lock = path.join(prefix, \".codenomad-opencode-install.lock\")\n const handle = await open(lock, \"wx\", 0o600).catch(error => {\n if (error.code === \"EEXIST\") throw new InstallationBusyError(\"installation_busy\", `OpenCode installation lock exists: ${lock}`)\n throw error\n })\n try {\n await handle.writeFile(JSON.stringify({ pid: process.pid, started: new Date().toISOString() }))\n return await install()\n } finally {\n await handle.close()\n await rm(lock)\n }\n}\n\n/** Windows forbids writing a mapped executable. Check before npm can retire the\n * old package; do not stop the daemon or leave a partially replaced installation. */\nexport async function assertExecutableWritable(binary: string, platform = process.platform) {\n if (platform !== \"win32\") return\n try { await (await open(binary, \"r+\")).close() }\n catch (error) {\n if ((error as NodeJS.ErrnoException).code === \"ENOENT\") return\n throw new InstallationBusyError(\"installation_in_use\", \"The OpenCode executable is in use or not writable\")\n }\n}\n"]}
@@ -0,0 +1,22 @@
1
+ import { execFile } from "node:child_process";
2
+ import { existsSync } from "node:fs";
3
+ import path from "node:path";
4
+ /** npm from the official Node archive, beside the backend runtime on both hosts. */
5
+ export function bundledNpm(execPath = process.execPath) {
6
+ const directory = path.dirname(execPath);
7
+ const candidates = [path.join(directory, "node_modules", "npm", "bin", "npm-cli.js"),
8
+ path.join(directory, "..", "lib", "node_modules", "npm", "bin", "npm-cli.js")];
9
+ return candidates.find(candidate => existsSync(candidate));
10
+ }
11
+ export function executeInstaller(file, args, env) {
12
+ return new Promise((resolve, reject) => {
13
+ execFile(file, args, { env, windowsHide: true, timeout: 300_000, maxBuffer: 1024 * 1024 }, error => {
14
+ // Do not return npm's environment/config diagnostics to the browser.
15
+ if (error)
16
+ reject(new Error(`OpenCode installation failed (${error.killed ? "timeout" : error.code ?? "execution"})`));
17
+ else
18
+ resolve();
19
+ });
20
+ });
21
+ }
22
+ //# sourceMappingURL=npm-runtime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"npm-runtime.js","sourceRoot":"","sources":["../../src/opencode-update/npm-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AACpC,OAAO,IAAI,MAAM,WAAW,CAAA;AAE5B,oFAAoF;AACpF,MAAM,UAAU,UAAU,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ;IACpD,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;IACxC,MAAM,UAAU,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,cAAc,EAAE,KAAK,EAAE,KAAK,EAAE,YAAY,CAAC;QAClF,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,KAAK,EAAE,YAAY,CAAC,CAAC,CAAA;IAChF,OAAO,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAA;AAC5D,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,IAAY,EAAE,IAAc,EAAE,GAAsB;IACnF,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,GAAG,IAAI,EAAE,EAAE,KAAK,CAAC,EAAE;YACjG,qEAAqE;YACrE,IAAI,KAAK;gBAAE,MAAM,CAAC,IAAI,KAAK,CAAC,iCAAiC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,IAAI,WAAW,GAAG,CAAC,CAAC,CAAA;;gBACjH,OAAO,EAAE,CAAA;QAChB,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import { execFile } from \"node:child_process\"\nimport { existsSync } from \"node:fs\"\nimport path from \"node:path\"\n\n/** npm from the official Node archive, beside the backend runtime on both hosts. */\nexport function bundledNpm(execPath = process.execPath): string | undefined {\n const directory = path.dirname(execPath)\n const candidates = [path.join(directory, \"node_modules\", \"npm\", \"bin\", \"npm-cli.js\"),\n path.join(directory, \"..\", \"lib\", \"node_modules\", \"npm\", \"bin\", \"npm-cli.js\")]\n return candidates.find(candidate => existsSync(candidate))\n}\n\nexport function executeInstaller(file: string, args: string[], env: NodeJS.ProcessEnv): Promise<void> {\n return new Promise((resolve, reject) => {\n execFile(file, args, { env, windowsHide: true, timeout: 300_000, maxBuffer: 1024 * 1024 }, error => {\n // Do not return npm's environment/config diagnostics to the browser.\n if (error) reject(new Error(`OpenCode installation failed (${error.killed ? \"timeout\" : error.code ?? \"execution\"})`))\n else resolve()\n })\n })\n}\n"]}
@@ -0,0 +1,41 @@
1
+ import { accessSync, constants, realpathSync, statSync } from "node:fs";
2
+ import path from "node:path";
3
+ // The prerelease private runtime is no longer an executable source, including
4
+ // saved selections and PATH aliases. Do not read receipts or delete its files.
5
+ export function isRetiredInstallation(binary) {
6
+ const retired = (value) => /(?:^|\/)\.local\/share\/codenomad\/opencode(?:\/|$)/i
7
+ .test(path.posix.normalize(value.replaceAll("\\", "/")));
8
+ if (retired(binary))
9
+ return true;
10
+ // WSL/network paths are checked lexically, never synchronously probed through
11
+ // the host filesystem just to decide whether this local tree was retired.
12
+ if (/^(?:\\\\|\/\/)/.test(binary))
13
+ return false;
14
+ try {
15
+ return retired(realpathSync(binary));
16
+ }
17
+ catch {
18
+ return false;
19
+ }
20
+ }
21
+ export function assertCurrentInstallation(binary, env = process.env) {
22
+ if (process.platform !== "win32" && !binary.includes("/")) {
23
+ for (const directory of (env.PATH ?? "").split(path.delimiter)) {
24
+ const candidate = path.resolve(directory || ".", binary);
25
+ try {
26
+ if (!statSync(candidate).isFile())
27
+ continue;
28
+ accessSync(candidate, constants.X_OK);
29
+ }
30
+ catch {
31
+ continue;
32
+ }
33
+ binary = candidate;
34
+ break;
35
+ }
36
+ }
37
+ if (isRetiredInstallation(binary)) {
38
+ throw Object.assign(new Error("opencode_private_installation_retired"), { code: "ENOENT" });
39
+ }
40
+ }
41
+ //# sourceMappingURL=retired-installation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retired-installation.js","sourceRoot":"","sources":["../../src/opencode-update/retired-installation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AACvE,OAAO,IAAI,MAAM,WAAW,CAAA;AAE5B,8EAA8E;AAC9E,+EAA+E;AAC/E,MAAM,UAAU,qBAAqB,CAAC,MAAc;IAClD,MAAM,OAAO,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,sDAAsD;SACtF,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,CAAA;IAC1D,IAAI,OAAO,CAAC,MAAM,CAAC;QAAE,OAAO,IAAI,CAAA;IAChC,8EAA8E;IAC9E,0EAA0E;IAC1E,IAAI,gBAAgB,CAAC,IAAI,CAAC,MAAM,CAAC;QAAE,OAAO,KAAK,CAAA;IAC/C,IAAI,CAAC;QAAC,OAAO,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAA;IAAC,CAAC;IAAC,MAAM,CAAC;QAAC,OAAO,KAAK,CAAA;IAAC,CAAC;AACrE,CAAC;AAED,MAAM,UAAU,yBAAyB,CAAC,MAAc,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG;IACzE,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QAC1D,KAAK,MAAM,SAAS,IAAI,CAAC,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;YAC/D,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,IAAI,GAAG,EAAE,MAAM,CAAC,CAAA;YACxD,IAAI,CAAC;gBACH,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE;oBAAE,SAAQ;gBAC3C,UAAU,CAAC,SAAS,EAAE,SAAS,CAAC,IAAI,CAAC,CAAA;YACvC,CAAC;YAAC,MAAM,CAAC;gBAAC,SAAQ;YAAC,CAAC;YACpB,MAAM,GAAG,SAAS,CAAA;YAClB,MAAK;QACP,CAAC;IACH,CAAC;IACD,IAAI,qBAAqB,CAAC,MAAM,CAAC,EAAE,CAAC;QAClC,MAAM,MAAM,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,uCAAuC,CAAC,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAA;IAC7F,CAAC;AACH,CAAC","sourcesContent":["import { accessSync, constants, realpathSync, statSync } from \"node:fs\"\nimport path from \"node:path\"\n\n// The prerelease private runtime is no longer an executable source, including\n// saved selections and PATH aliases. Do not read receipts or delete its files.\nexport function isRetiredInstallation(binary: string): boolean {\n const retired = (value: string) => /(?:^|\\/)\\.local\\/share\\/codenomad\\/opencode(?:\\/|$)/i\n .test(path.posix.normalize(value.replaceAll(\"\\\\\", \"/\")))\n if (retired(binary)) return true\n // WSL/network paths are checked lexically, never synchronously probed through\n // the host filesystem just to decide whether this local tree was retired.\n if (/^(?:\\\\\\\\|\\/\\/)/.test(binary)) return false\n try { return retired(realpathSync(binary)) } catch { return false }\n}\n\nexport function assertCurrentInstallation(binary: string, env = process.env): void {\n if (process.platform !== \"win32\" && !binary.includes(\"/\")) {\n for (const directory of (env.PATH ?? \"\").split(path.delimiter)) {\n const candidate = path.resolve(directory || \".\", binary)\n try {\n if (!statSync(candidate).isFile()) continue\n accessSync(candidate, constants.X_OK)\n } catch { continue }\n binary = candidate\n break\n }\n }\n if (isRetiredInstallation(binary)) {\n throw Object.assign(new Error(\"opencode_private_installation_retired\"), { code: \"ENOENT\" })\n }\n}\n"]}
@@ -0,0 +1,39 @@
1
+ import assert from "node:assert/strict";
2
+ import test from "node:test";
3
+ import { mkdtemp, mkdir, writeFile, rm } from "node:fs/promises";
4
+ import os from "node:os";
5
+ import path from "node:path";
6
+ import { BinaryResolver } from "../settings/binaries";
7
+ import { buildServiceLaunchSpec, buildSpawnSpec, probeOpenCodeBinary } from "../workspaces/spawn";
8
+ import { resolveDefaultInstallation, sharedInstallPrefix, userNpmPrefix } from "./shared-installation";
9
+ test("private executables are rejected before validation or launch, including an explicit selection", async () => {
10
+ const binary = path.join(os.homedir(), ".local/share/codenomad/opencode/2.0.15/node_modules/@opencode/cli/bin/opencode.exe");
11
+ let executed = false;
12
+ const validation = await probeOpenCodeBinary(binary, async () => { executed = true; return { status: 0, stdout: "opencode v2.0.15" }; });
13
+ assert.equal(validation.valid, false);
14
+ assert.equal(executed, false);
15
+ assert.throws(() => buildSpawnSpec(binary, ["service", "start"]), /opencode_private_installation_retired/);
16
+ assert.throws(() => buildServiceLaunchSpec(binary), /opencode_private_installation_retired/);
17
+ const settings = { getOwner: (scope) => scope === "config"
18
+ ? { opencodeBinary: binary } : { opencodeBinaries: [{ path: binary }, { path: "custom" }] } };
19
+ const resolver = new BinaryResolver(settings, () => ({ path: "opencode2" }));
20
+ assert.equal(resolver.resolveDefault().path, "opencode2");
21
+ assert.deepEqual(resolver.list(), [{ path: "custom" }]);
22
+ });
23
+ test("private PATH entries cannot be launched or selected as a shared install prefix", async () => {
24
+ const home = await mkdtemp(path.join(os.tmpdir(), "retired-opencode-"));
25
+ try {
26
+ const directory = path.join(home, ".local/share/codenomad/opencode/2.0.15/bin");
27
+ await mkdir(directory, { recursive: true });
28
+ await writeFile(path.join(directory, process.platform === "win32" ? "opencode2.exe" : "opencode2"), "retired", { mode: 0o755 });
29
+ const host = { home, env: { PATH: directory, APPDATA: path.join(home, "AppData") } };
30
+ assert.deepEqual(resolveDefaultInstallation(host), { path: "opencode2" });
31
+ assert.equal(sharedInstallPrefix(host), userNpmPrefix(host));
32
+ assert.throws(() => buildSpawnSpec("opencode2", ["service", "start"], { env: host.env }), /opencode_private_installation_retired/);
33
+ assert.equal(sharedInstallPrefix({ ...host, env: { ...host.env, npm_config_prefix: directory } }), undefined);
34
+ }
35
+ finally {
36
+ await rm(home, { recursive: true, force: true });
37
+ }
38
+ });
39
+ //# sourceMappingURL=retired-installation.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retired-installation.test.js","sourceRoot":"","sources":["../../src/opencode-update/retired-installation.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAA;AACvC,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAA;AAChE,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAErD,O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AI,CAAC,CAAC,CAAA;QAC5D,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,cAAc,CAAC,WAAW,EAAE,CAAC,SAAS,EAAE,OAAO,CAAC,EAAE,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE,uCAAuC,CAAC,CAAA;QAClI,MAAM,CAAC,KAAK,CAAC,mBAAmB,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,iBAAiB,EAAE,SAAS,EAAE,EAAE,CAAC,EAAE,SAAS,CAAC,CAAA;IAC/G,CAAC;YAAS,CAAC;QAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAA;IAAC,CAAC;AAChE,CAAC,CAAC,CAAA","sourcesContent":["import assert from \"node:assert/strict\"\nimport test from \"node:test\"\nimport { mkdtemp, mkdir, writeFile, rm } from \"node:fs/promises\"\nimport os from \"node:os\"\nimport path from \"node:path\"\nimport { BinaryResolver } from \"../settings/binaries\"\nimport type { SettingsService } from \"../settings/service\"\nimport { buildServiceLaunchSpec, buildSpawnSpec, probeOpenCodeBinary } from \"../workspaces/spawn\"\nimport { resolveDefaultInstallation, sharedInstallPrefix, userNpmPrefix } from \"./shared-installation\"\n\ntest(\"private executables are rejected before validation or launch, including an explicit selection\", async () => {\n const binary = path.join(os.homedir(), \".local/share/codenomad/opencode/2.0.15/node_modules/@opencode/cli/bin/opencode.exe\")\n let executed = false\n const validation = await probeOpenCodeBinary(binary, async () => { executed = true; return { status: 0, stdout: \"opencode v2.0.15\" } })\n assert.equal(validation.valid, false)\n assert.equal(executed, false)\n assert.throws(() => buildSpawnSpec(binary, [\"service\", \"start\"]), /opencode_private_installation_retired/)\n assert.throws(() => buildServiceLaunchSpec(binary), /opencode_private_installation_retired/)\n const settings = { getOwner: (scope: string) => scope === \"config\"\n ? { opencodeBinary: binary } : { opencodeBinaries: [{ path: binary }, { path: \"custom\" }] } } as unknown as SettingsService\n const resolver = new BinaryResolver(settings, () => ({ path: \"opencode2\" }))\n assert.equal(resolver.resolveDefault().path, \"opencode2\")\n assert.deepEqual(resolver.list(), [{ path: \"custom\" }])\n})\n\ntest(\"private PATH entries cannot be launched or selected as a shared install prefix\", async () => {\n const home = await mkdtemp(path.join(os.tmpdir(), \"retired-opencode-\"))\n try {\n const directory = path.join(home, \".local/share/codenomad/opencode/2.0.15/bin\")\n await mkdir(directory, { recursive: true })\n await writeFile(path.join(directory, process.platform === \"win32\" ? \"opencode2.exe\" : \"opencode2\"), \"retired\", { mode: 0o755 })\n const host = { home, env: { PATH: directory, APPDATA: path.join(home, \"AppData\") } }\n assert.deepEqual(resolveDefaultInstallation(host), { path: \"opencode2\" })\n assert.equal(sharedInstallPrefix(host), userNpmPrefix(host))\n assert.throws(() => buildSpawnSpec(\"opencode2\", [\"service\", \"start\"], { env: host.env }), /opencode_private_installation_retired/)\n assert.equal(sharedInstallPrefix({ ...host, env: { ...host.env, npm_config_prefix: directory } }), undefined)\n } finally { await rm(home, { recursive: true, force: true }) }\n})\n"]}
@@ -5,7 +5,10 @@ import { compareVersionStrings, stripTagPrefix } from "../releases/release-monit
5
5
  import { assertSupportedOpenCode, isBelowOpenCodeMinimum, MINIMUM_OPENCODE_VERSION, RECOMMENDED_OPENCODE_VERSION, UnsupportedOpenCodeError } from "../opencode/runtime-support";
6
6
  import { contractProfile, runtimeIdentity } from "../opencode/compatibility/runtime";
7
7
  import { createRuntimeTransport } from "../opencode/compatibility/transport";
8
- import { bundledNpm, installManagedOpenCode } from "./managed-installation";
8
+ import { bundledNpm } from "./npm-runtime";
9
+ import { isRetiredInstallation } from "./retired-installation";
10
+ import { installSharedOpenCode, sharedInstallPrefix } from "./shared-installation";
11
+ import { InstallationBusyError } from "./installation-lock";
9
12
  import { parseWslUncPath } from "../workspaces/spawn";
10
13
  const OPENCODE_REGISTRY_URL = "https://registry.npmjs.org/-/package/%40opencode%2Fcli/dist-tags";
11
14
  export const TARGET_OPENCODE_CHANNEL = "latest";
@@ -45,9 +48,10 @@ export class OpenCodeUpdateService {
45
48
  ? !currentVersion || compareOpenCodeVersionStrings(latestVersion, currentVersion) > 0 : null;
46
49
  const status = {
47
50
  currentVersion, latestVersion, updateAvailable,
48
- canUpgrade: !invalid && Boolean(updateAvailable) && Boolean(latestVersion && !isBelowOpenCodeMinimum(latestVersion)) && this.deps.canUpgradeBinary(binary),
51
+ canUpgrade: !invalid && Boolean(updateAvailable || needsSharedInstallation(binary)) && Boolean(latestVersion && !isBelowOpenCodeMinimum(latestVersion)) && this.deps.canUpgradeBinary(binary),
49
52
  minimumVersion: MINIMUM_OPENCODE_VERSION, recommendedVersion: RECOMMENDED_OPENCODE_VERSION,
50
53
  versionAssessment: "untested", state, binaryPath: binary.path,
54
+ installationSource: binary.source, needsSharedInstallation: needsSharedInstallation(binary),
51
55
  target: parseWslUncPath(binary.path) ? "wsl" : "host", canRestart: false,
52
56
  ...(!latestVersion ? { checkError: "update_check_failed" } : {}),
53
57
  };
@@ -187,25 +191,26 @@ export class OpenCodeUpdateService {
187
191
  if (currentVersion && !comparableVersion(currentVersion)) {
188
192
  throw new OpenCodeUpdateError("unsupported_binary", "Cannot order this custom OpenCode version for an automatic update");
189
193
  }
190
- if (currentVersion && compareOpenCodeVersionStrings(latestVersion, currentVersion) <= 0) {
194
+ if (currentVersion && compareOpenCodeVersionStrings(latestVersion, currentVersion) <= 0 && !needsSharedInstallation(binary)) {
191
195
  return { success: true, version: currentVersion };
192
196
  }
193
197
  if (!this.deps.canUpgradeBinary(binary)) {
194
- throw new OpenCodeUpdateError("unsupported_binary", "Automatic updates are only available for the managed opencode2 command");
198
+ throw new OpenCodeUpdateError("unsupported_binary", "Automatic updates require the default command and a writable npm installation");
195
199
  }
196
200
  try {
197
- const result = await this.deps.upgradeBinary(binary, latestVersion);
201
+ const targetVersion = currentVersion && compareOpenCodeVersionStrings(currentVersion, latestVersion) > 0 ? currentVersion : latestVersion;
202
+ const result = await this.deps.upgradeBinary(binary, targetVersion);
198
203
  if (!result.success) {
199
204
  throw new OpenCodeUpdateError("upgrade_failed", result.error);
200
205
  }
201
206
  const installedVersion = await this.readCurrentVersion(this.deps.resolveBinary().path);
202
- if (isBelowOpenCodeMinimum(installedVersion) || !/^\d+\.\d+\.\d+$/.test(installedVersion) || compareOpenCodeVersionStrings(installedVersion, latestVersion) < 0) {
207
+ if (isBelowOpenCodeMinimum(installedVersion) || !/^\d+\.\d+\.\d+$/.test(installedVersion) || compareOpenCodeVersionStrings(installedVersion, targetVersion) < 0) {
203
208
  throw new OpenCodeUpdateError("upgrade_verification_failed", `OpenCode reported ${result.version}, but the configured binary is ${installedVersion} instead of ${latestVersion}`);
204
209
  }
205
210
  return { success: true, version: installedVersion };
206
211
  }
207
212
  catch (error) {
208
- if (error instanceof OpenCodeUpdateError)
213
+ if (error instanceof OpenCodeUpdateError || error instanceof InstallationBusyError)
209
214
  throw error;
210
215
  throw new OpenCodeUpdateError("upgrade_failed", error instanceof Error ? error.message : "OpenCode upgrade failed");
211
216
  }
@@ -264,12 +269,12 @@ export function createOpenCodeUpdateService(settings, workspaceManager) {
264
269
  },
265
270
  probeBinary: probeBinaryVersionAsync,
266
271
  resolveLatestVersion: resolveLatestOpenCodeVersion,
267
- canUpgradeBinary: () => {
272
+ canUpgradeBinary: binary => {
268
273
  const configured = settings.getOwner("config", "server").opencodeBinary;
269
- return (!configured || configured === "opencode" || configured === "opencode2") && Boolean(bundledNpm());
274
+ return !parseWslUncPath(binary.path) && (!configured || configured === "opencode" || configured === "opencode2" || (typeof configured === "string" && isRetiredInstallation(configured))) && Boolean(bundledNpm()) && Boolean(sharedInstallPrefix());
270
275
  },
271
276
  upgradeBinary: async (_binary, version) => {
272
- await installManagedOpenCode(version);
277
+ await installSharedOpenCode(version);
273
278
  return { success: true, version };
274
279
  },
275
280
  lifecycle: binary => workspaceManager.setupServiceOptions(binary.path).then(options => options.lifecycle),
@@ -281,4 +286,7 @@ export function createOpenCodeUpdateService(settings, workspaceManager) {
281
286
  function comparableVersion(version) {
282
287
  return /^\d+\.\d+\.\d+$/.test(version) || /^0\.0\.0-beta-\d+$/.test(version);
283
288
  }
289
+ function needsSharedInstallation(binary) {
290
+ return binary.source === "user";
291
+ }
284
292
  //# sourceMappingURL=service.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"service.js","sourceRoot":"","sources":["../../src/opencode-update/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAA;AAG9B,OAAO,EAAE,cAAc,EAAuB,MAAM,sBAAsB,CAAA;AAE1E,OAAO,EAAsB,uBAAuB,EAAE,MAAM,qBAAqB,CAAA;AACjF,OAAO,EAAE,qBAAqB,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AACnF,OAAO,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,4BAA4B,EAAE,wBAAwB,EAAE,MAAM,6BAA6B,CAAA;AAC/K,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAA;AACpF,OAAO,EAAE,sBAAsB,EAAE,MAAM,qCAAqC,CAAA;AAE5E,OAAO,EAAE,UAAU,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAA;AAE3E,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAErD,MAAM,qBAAqB,GAAG,kEAAkE,CAAA;AAChG,MAAM,CAAC,MAAM,uBAAuB,GAAG,QAAQ,CAAA;AAC/C,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAA2C,CAAA;AAkB3E,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAC5C,YACW,IAKwB,EACjC,OAAe;QAEf,KAAK,CAAC,OAAO,CAAC,CAAA;QARL,SAAI,GAAJ,IAAI,CAKoB;QAIjC,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAA;IACnC,CAAC;CACF;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,MAAM,CAAC,IAAI,CAAC;QACtE,eAAe,EAAE,MAAM,CAAC,EAAE,CAAC,gBAAgB,CAAC,wBAAwB,CAAC,MAAM,CAAC,IAAI,CAAC;QACjF,MAAM,EAAE,CAAC,MAAM,EAAE,aAAa,EAAE,EAAE,CAAC,gBAAgB,CAAC,6BAA6B,CAAC,MAAM,CAAC,IAAI,EAAE,aAAa,CAAC;KAC9G,CAAC,CAAA;AACJ,CAAC;AAED,SAAS,iBAAiB,CAAC,OAAe;IACxC,OAAO,iBAAiB,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,oBAAoB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;AAC9E,CAAC","sourcesContent":["import { fetch } from \"undici\"\nimport type { OpenCodeUpdateResponse, OpenCodeUpdateStatus } from \"../api-types\"\nimport type { SettingsService } from \"../settings/service\"\nimport { BinaryResolver, type ResolvedBinary } from \"../settings/binaries\"\nimport type { WorkspaceManager } from \"../workspaces/manager\"\nimport { probeBinaryVersion, probeBinaryVersionAsync } from \"../workspaces/spawn\"\nimport { compareVersionStrings, stripTagPrefix } from \"../releases/release-monitor\"\nimport { assertSupportedOpenCode, isBelowOpenCodeMinimum, MINIMUM_OPENCODE_VERSION, RECOMMENDED_OPENCODE_VERSION, UnsupportedOpenCodeError } from \"../opencode/runtime-support\"\nimport { contractProfile, runtimeIdentity } from \"../opencode/compatibility/runtime\"\nimport { createRuntimeTransport } from \"../opencode/compatibility/transport\"\nimport type { Endpoint } from \"@opencode/client/service\"\nimport { bundledNpm, installManagedOpenCode } from \"./managed-installation\"\nimport type { OpenCodeServiceLifecycle } from \"../workspaces/opencode-service\"\nimport { parseWslUncPath } from \"../workspaces/spawn\"\n\nconst OPENCODE_REGISTRY_URL = \"https://registry.npmjs.org/-/package/%40opencode%2Fcli/dist-tags\"\nexport const TARGET_OPENCODE_CHANNEL = \"latest\"\nconst inFlightUpgrades = new Map<string, Promise<OpenCodeUpdateResponse>>()\ntype ServiceAction = \"start\" | \"restart\" | \"reload\"\n\ntype UpgradeResult = { success: true; version: string } | { success: false; error: string }\n\nexport interface OpenCodeUpdateServiceDeps {\n resolveBinary: () => ResolvedBinary\n probeBinary: (path: string) => ReturnType<typeof probeBinaryVersion> | Promise<ReturnType<typeof probeBinaryVersion>>\n resolveLatestVersion: () => Promise<string>\n canUpgradeBinary: (binary: ResolvedBinary) => boolean\n upgradeBinary: (binary: ResolvedBinary, target: string) => Promise<UpgradeResult>\n lifecycle?: (binary: ResolvedBinary) => Promise<OpenCodeServiceLifecycle>\n reconnect?: (binary: ResolvedBinary) => Promise<void>\n admitActivation?: (binary: ResolvedBinary) => void\n reload?: (binary: ResolvedBinary, assertCurrent: () => void) => Promise<void>\n inspectRuntime?: (endpoint: Endpoint) => Promise<{ reload: boolean }>\n}\n\nexport class OpenCodeUpdateError extends Error {\n constructor(\n readonly code:\n | \"binary_unavailable\"\n | \"unsupported_binary\"\n | \"update_check_failed\"\n | \"upgrade_failed\"\n | \"upgrade_verification_failed\",\n message: string,\n ) {\n super(message)\n this.name = \"OpenCodeUpdateError\"\n }\n}\n\nexport class OpenCodeUpdateService {\n private activation?: { binaryPath: string; action: ServiceAction; pending: Promise<OpenCodeUpdateStatus> }\n\n constructor(private readonly deps: OpenCodeUpdateServiceDeps) {}\n\n async getStatus(): Promise<OpenCodeUpdateStatus> {\n const binary = this.deps.resolveBinary()\n let currentVersion: string | null = null\n let missing = false\n let invalid = false\n const probe = await this.deps.probeBinary(binary.path)\n try { currentVersion = await this.readCurrentVersion(binary.path, probe) }\n catch { missing = probe.missing === true; invalid = !missing }\n let latestVersion: string | null = null\n try { latestVersion = await this.readLatestVersion() } catch { /* Local admission remains available offline. */ }\n const state = invalid ? \"error\" : missing ? \"missing\"\n : currentVersion && !isBelowOpenCodeMinimum(currentVersion) ? \"ready\" : \"update_required\"\n const updateAvailable = latestVersion && (!currentVersion || comparableVersion(currentVersion))\n ? !currentVersion || compareOpenCodeVersionStrings(latestVersion, currentVersion) > 0 : null\n const status: OpenCodeUpdateStatus = {\n currentVersion, latestVersion, updateAvailable,\n canUpgrade: !invalid && Boolean(updateAvailable) && Boolean(latestVersion && !isBelowOpenCodeMinimum(latestVersion)) && this.deps.canUpgradeBinary(binary),\n minimumVersion: MINIMUM_OPENCODE_VERSION, recommendedVersion: RECOMMENDED_OPENCODE_VERSION,\n versionAssessment: \"untested\", state, binaryPath: binary.path,\n target: parseWslUncPath(binary.path) ? \"wsl\" : \"host\", canRestart: false,\n ...(!latestVersion ? { checkError: \"update_check_failed\" as const } : {}),\n }\n if (!missing && !invalid && this.deps.lifecycle) {\n try {\n const lifecycle = await this.deps.lifecycle(binary)\n const endpoint = await lifecycle.discover()\n const identity = endpoint && runtimeIdentity(endpoint)\n status.daemonVersion = identity?.version\n const olderDaemon = identity && currentVersion && comparableVersion(identity.version) && comparableVersion(currentVersion)\n && compareOpenCodeVersionStrings(currentVersion, identity.version) > 0\n status.serviceState = \"stopped\"\n if (endpoint) {\n try {\n const capabilities = await this.inspectRuntime(endpoint)\n status.serviceState = olderDaemon ? \"restart_available\" : \"ready\"\n // The running daemon, not an older discovery CLI, serves requests.\n status.state = \"ready\"\n status.canReload = Boolean(this.deps.reload) && capabilities.reload\n } catch (error) {\n if (!(error instanceof UnsupportedOpenCodeError)) throw error\n status.incompatibilityReason = error.reason\n status.serviceState = olderDaemon ? \"restart_required\" : \"incompatible\"\n }\n }\n status.canRestart = Boolean(lifecycle.restart) && state === \"ready\"\n && (status.serviceState === \"restart_required\" || status.serviceState === \"restart_available\")\n } catch { status.serviceState = \"error\"; status.serviceError = \"service_check_failed\" }\n }\n const effectiveVersion = status.daemonVersion ?? currentVersion\n if (!status.incompatibilityReason && effectiveVersion && isBelowOpenCodeMinimum(effectiveVersion)) status.incompatibilityReason = \"step_timestamp\"\n status.versionAssessment = status.incompatibilityReason ? \"incompatible\"\n : effectiveVersion === RECOMMENDED_OPENCODE_VERSION ? \"tested\" : \"untested\"\n return status\n }\n\n private async inspectRuntime(endpoint: Endpoint): Promise<{ reload: boolean }> {\n const identity = runtimeIdentity(endpoint)\n if (!identity) throw new Error(\"OpenCode did not report an authenticated runtime version\")\n assertSupportedOpenCode(identity.version)\n if (this.deps.inspectRuntime) return this.deps.inspectRuntime(endpoint)\n await createRuntimeTransport(endpoint).profile()\n return { reload: identity.contract?.reload ?? contractProfile(identity) === \"modern\" }\n }\n\n start(restart = false): Promise<OpenCodeUpdateStatus> {\n return this.runServiceAction(restart ? \"restart\" : \"start\")\n }\n\n reload(): Promise<OpenCodeUpdateStatus> {\n return this.runServiceAction(\"reload\")\n }\n\n private runServiceAction(action: ServiceAction): Promise<OpenCodeUpdateStatus> {\n const binary = this.deps.resolveBinary()\n // One updater owns one manager/shared-service authority. Executable selection\n // is mutable and cannot be the lock key for daemon-wide operations.\n const existing = this.activation\n if (existing) return existing.action === action && existing.binaryPath === binary.path\n ? existing.pending : Promise.reject(new Error(\"Another OpenCode service action is in progress\"))\n const pending = this.activate(binary, action).finally(() => {\n if (this.activation?.pending === pending) this.activation = undefined\n })\n this.activation = { binaryPath: binary.path, action, pending }\n return pending\n }\n\n private async activate(binary: ResolvedBinary, action: ServiceAction): Promise<OpenCodeUpdateStatus> {\n const restart = action === \"restart\"\n const installedVersion = await this.readCurrentVersion(binary.path)\n const lifecycle = await this.deps.lifecycle?.(binary)\n if (!lifecycle) throw new Error(\"OpenCode service lifecycle unavailable\")\n const previous = await lifecycle.discover()\n if (!previous || restart) assertSupportedOpenCode(installedVersion)\n if (restart && previous) {\n const identity = runtimeIdentity(previous)\n if (!identity || !comparableVersion(identity.version) || !comparableVersion(installedVersion)\n || compareOpenCodeVersionStrings(installedVersion, identity.version) <= 0) {\n throw new Error(\"The shared daemon is not an older runtime eligible for this update\")\n }\n }\n const assertCurrent = () => {\n if (this.deps.resolveBinary().path !== binary.path) throw new Error(\"OpenCode selection changed during activation\")\n this.deps.admitActivation?.(binary)\n }\n assertCurrent()\n if (action === \"reload\") {\n const identity = previous && runtimeIdentity(previous)\n if (!identity || !this.deps.reload) throw new Error(\"OpenCode configuration reload unavailable\")\n const capabilities = await this.inspectRuntime(previous!)\n if (!capabilities.reload) throw new Error(\"OpenCode does not expose configuration reload\")\n assertCurrent()\n // Explicit daemon-wide mutation: never use this as an automatic watcher\n // fallback, because native reload cancels pending Forms and permissions.\n await this.deps.reload(binary, assertCurrent)\n assertCurrent()\n return this.getStatus()\n }\n const endpoint = restart && previous ? await lifecycle.restart?.() : previous ?? await lifecycle.ensure()\n const identity = endpoint && runtimeIdentity(endpoint)\n if (!identity) throw new Error(\"OpenCode did not report an authenticated runtime version\")\n await this.inspectRuntime(endpoint!)\n if (this.deps.resolveBinary().path !== binary.path) throw new Error(\"OpenCode selection changed during activation\")\n await this.deps.reconnect?.(binary)\n return this.getStatus()\n }\n\n upgrade(): Promise<OpenCodeUpdateResponse> {\n const binary = this.deps.resolveBinary()\n const existing = inFlightUpgrades.get(binary.path)\n if (existing) return existing\n\n const pending = this.performUpgrade(binary).finally(() => {\n if (inFlightUpgrades.get(binary.path) === pending) inFlightUpgrades.delete(binary.path)\n })\n inFlightUpgrades.set(binary.path, pending)\n return pending\n }\n\n private async performUpgrade(binary: ResolvedBinary): Promise<OpenCodeUpdateResponse> {\n const probe = await this.deps.probeBinary(binary.path)\n const currentVersion = probe.missing ? null : await this.readCurrentVersion(binary.path, probe)\n const latestVersion = await this.readLatestVersion()\n assertSupportedOpenCode(latestVersion)\n\n if (currentVersion && !comparableVersion(currentVersion)) {\n throw new OpenCodeUpdateError(\"unsupported_binary\", \"Cannot order this custom OpenCode version for an automatic update\")\n }\n\n if (currentVersion && compareOpenCodeVersionStrings(latestVersion, currentVersion) <= 0) {\n return { success: true, version: currentVersion }\n }\n\n if (!this.deps.canUpgradeBinary(binary)) {\n throw new OpenCodeUpdateError(\n \"unsupported_binary\",\n \"Automatic updates are only available for the managed opencode2 command\",\n )\n }\n\n try {\n const result = await this.deps.upgradeBinary(binary, latestVersion)\n if (!result.success) {\n throw new OpenCodeUpdateError(\"upgrade_failed\", result.error)\n }\n const installedVersion = await this.readCurrentVersion(this.deps.resolveBinary().path)\n if (isBelowOpenCodeMinimum(installedVersion) || !/^\\d+\\.\\d+\\.\\d+$/.test(installedVersion) || compareOpenCodeVersionStrings(installedVersion, latestVersion) < 0) {\n throw new OpenCodeUpdateError(\n \"upgrade_verification_failed\",\n `OpenCode reported ${result.version}, but the configured binary is ${installedVersion} instead of ${latestVersion}`,\n )\n }\n return { success: true, version: installedVersion }\n } catch (error) {\n if (error instanceof OpenCodeUpdateError) throw error\n throw new OpenCodeUpdateError(\n \"upgrade_failed\",\n error instanceof Error ? error.message : \"OpenCode upgrade failed\",\n )\n }\n }\n\n private async readCurrentVersion(binaryPath: string, probe?: ReturnType<typeof probeBinaryVersion>): Promise<string> {\n if (process.platform === \"win32\" && /[\"\\r\\n]/.test(binaryPath)) {\n throw new OpenCodeUpdateError(\"binary_unavailable\", \"The configured OpenCode binary path is invalid\")\n }\n const result = probe ?? await this.deps.probeBinary(binaryPath)\n if (!result.valid) {\n throw new OpenCodeUpdateError(\"binary_unavailable\", result.error ?? \"Unable to read OpenCode version\")\n }\n // Successful unknown/empty labels are diagnostic information. Admission is\n // established against the authenticated daemon, not inferred from this label.\n return result.version?.trim() || \"unknown\"\n }\n\n private async readLatestVersion(): Promise<string> {\n try {\n const version = stripTagPrefix(await this.deps.resolveLatestVersion())\n if (!version) throw new Error(`The ${TARGET_OPENCODE_CHANNEL} channel did not resolve to a version`)\n return version\n } catch (error) {\n throw new OpenCodeUpdateError(\n \"update_check_failed\",\n error instanceof Error ? error.message : \"Unable to resolve the latest stable OpenCode release\",\n )\n }\n }\n}\n\nexport function compareOpenCodeVersionStrings(left: string, right: string): number {\n const leftBeta = stripTagPrefix(left)?.match(/^0\\.0\\.0-beta-(\\d+)$/)\n const rightBeta = stripTagPrefix(right)?.match(/^0\\.0\\.0-beta-(\\d+)$/)\n if (leftBeta && rightBeta) return Number(leftBeta[1]) - Number(rightBeta[1])\n return compareVersionStrings(left, right)\n}\n\ntype RegistryFetch = (\n url: string,\n init: Parameters<typeof fetch>[1],\n) => Promise<Pick<Awaited<ReturnType<typeof fetch>>, \"ok\" | \"status\" | \"json\">>\n\nexport async function resolveLatestOpenCodeVersion(fetchRegistry: RegistryFetch = fetch): Promise<string> {\n const response = await fetchRegistry(OPENCODE_REGISTRY_URL, {\n headers: { Accept: \"application/json\" },\n signal: AbortSignal.timeout(10_000),\n })\n if (!response.ok) throw new Error(`OpenCode registry responded with ${response.status}`)\n\n const metadata = (await response.json()) as Record<string, unknown>\n const version = metadata[TARGET_OPENCODE_CHANNEL]\n if (typeof version !== \"string\" || !/^\\d+\\.\\d+\\.\\d+$/.test(version)) {\n throw new Error(`The ${TARGET_OPENCODE_CHANNEL} channel did not resolve to a valid version`)\n }\n return version\n}\n\nexport function createOpenCodeUpdateService(\n settings: SettingsService,\n workspaceManager: WorkspaceManager,\n): OpenCodeUpdateService {\n const binaryResolver = new BinaryResolver(settings)\n return new OpenCodeUpdateService({\n resolveBinary: () => {\n const binary = binaryResolver.resolveDefault()\n return { ...binary, path: workspaceManager.resolveBinaryPath(binary.path) }\n },\n probeBinary: probeBinaryVersionAsync,\n resolveLatestVersion: resolveLatestOpenCodeVersion,\n canUpgradeBinary: () => {\n const configured = settings.getOwner(\"config\", \"server\").opencodeBinary\n return (!configured || configured === \"opencode\" || configured === \"opencode2\") && Boolean(bundledNpm())\n },\n upgradeBinary: async (_binary, version) => {\n await installManagedOpenCode(version)\n return { success: true, version }\n },\n lifecycle: binary => workspaceManager.setupServiceOptions(binary.path).then(options => options.lifecycle),\n reconnect: binary => workspaceManager.reconnectAfterSetup(binary.path),\n admitActivation: binary => workspaceManager.assertSetupExecutionHost(binary.path),\n reload: (binary, assertCurrent) => workspaceManager.reloadConfigurationAfterSetup(binary.path, assertCurrent),\n })\n}\n\nfunction comparableVersion(version: string): boolean {\n return /^\\d+\\.\\d+\\.\\d+$/.test(version) || /^0\\.0\\.0-beta-\\d+$/.test(version)\n}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tP,CAAC;QACD,aAAa,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE;YACxC,MAAM,qBAAqB,CAAC,OAAO,CAAC,CAAA;YACpC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CAAA;QACnC,CAAC;QACD,SAAS,EAAE,MAAM,CAAC,EAAE,CAAC,gBAAgB,CAAC,mBAAmB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC;QACzG,SAAS,EAAE,MAAM,CAAC,EAAE,CAAC,gBAAgB,CAAC,mBAAmB,CAAC,MAAM,CAAC,IAAI,CAAC;QACtE,eAAe,EAAE,MAAM,CAAC,EAAE,CAAC,gBAAgB,CAAC,wBAAwB,CAAC,MAAM,CAAC,IAAI,CAAC;QACjF,MAAM,EAAE,CAAC,MAAM,EAAE,aAAa,EAAE,EAAE,CAAC,gBAAgB,CAAC,6BAA6B,CAAC,MAAM,CAAC,IAAI,EAAE,aAAa,CAAC;KAC9G,CAAC,CAAA;AACJ,CAAC;AAED,SAAS,iBAAiB,CAAC,OAAe;IACxC,OAAO,iBAAiB,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,oBAAoB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;AAC9E,CAAC;AAED,SAAS,uBAAuB,CAAC,MAAsB;IACrD,OAAO,MAAM,CAAC,MAAM,KAAK,MAAM,CAAA;AACjC,CAAC","sourcesContent":["import { fetch } from \"undici\"\nimport type { OpenCodeUpdateResponse, OpenCodeUpdateStatus } from \"../api-types\"\nimport type { SettingsService } from \"../settings/service\"\nimport { BinaryResolver, type ResolvedBinary } from \"../settings/binaries\"\nimport type { WorkspaceManager } from \"../workspaces/manager\"\nimport { probeBinaryVersion, probeBinaryVersionAsync } from \"../workspaces/spawn\"\nimport { compareVersionStrings, stripTagPrefix } from \"../releases/release-monitor\"\nimport { assertSupportedOpenCode, isBelowOpenCodeMinimum, MINIMUM_OPENCODE_VERSION, RECOMMENDED_OPENCODE_VERSION, UnsupportedOpenCodeError } from \"../opencode/runtime-support\"\nimport { contractProfile, runtimeIdentity } from \"../opencode/compatibility/runtime\"\nimport { createRuntimeTransport } from \"../opencode/compatibility/transport\"\nimport type { Endpoint } from \"@opencode/client/service\"\nimport { bundledNpm } from \"./npm-runtime\"\nimport { isRetiredInstallation } from \"./retired-installation\"\nimport { installSharedOpenCode, sharedInstallPrefix } from \"./shared-installation\"\nimport { InstallationBusyError } from \"./installation-lock\"\nimport type { OpenCodeServiceLifecycle } from \"../workspaces/opencode-service\"\nimport { parseWslUncPath } from \"../workspaces/spawn\"\n\nconst OPENCODE_REGISTRY_URL = \"https://registry.npmjs.org/-/package/%40opencode%2Fcli/dist-tags\"\nexport const TARGET_OPENCODE_CHANNEL = \"latest\"\nconst inFlightUpgrades = new Map<string, Promise<OpenCodeUpdateResponse>>()\ntype ServiceAction = \"start\" | \"restart\" | \"reload\"\n\ntype UpgradeResult = { success: true; version: string } | { success: false; error: string }\n\nexport interface OpenCodeUpdateServiceDeps {\n resolveBinary: () => ResolvedBinary\n probeBinary: (path: string) => ReturnType<typeof probeBinaryVersion> | Promise<ReturnType<typeof probeBinaryVersion>>\n resolveLatestVersion: () => Promise<string>\n canUpgradeBinary: (binary: ResolvedBinary) => boolean\n upgradeBinary: (binary: ResolvedBinary, target: string) => Promise<UpgradeResult>\n lifecycle?: (binary: ResolvedBinary) => Promise<OpenCodeServiceLifecycle>\n reconnect?: (binary: ResolvedBinary) => Promise<void>\n admitActivation?: (binary: ResolvedBinary) => void\n reload?: (binary: ResolvedBinary, assertCurrent: () => void) => Promise<void>\n inspectRuntime?: (endpoint: Endpoint) => Promise<{ reload: boolean }>\n}\n\nexport class OpenCodeUpdateError extends Error {\n constructor(\n readonly code:\n | \"binary_unavailable\"\n | \"unsupported_binary\"\n | \"update_check_failed\"\n | \"upgrade_failed\"\n | \"upgrade_verification_failed\",\n message: string,\n ) {\n super(message)\n this.name = \"OpenCodeUpdateError\"\n }\n}\n\nexport class OpenCodeUpdateService {\n private activation?: { binaryPath: string; action: ServiceAction; pending: Promise<OpenCodeUpdateStatus> }\n\n constructor(private readonly deps: OpenCodeUpdateServiceDeps) {}\n\n async getStatus(): Promise<OpenCodeUpdateStatus> {\n const binary = this.deps.resolveBinary()\n let currentVersion: string | null = null\n let missing = false\n let invalid = false\n const probe = await this.deps.probeBinary(binary.path)\n try { currentVersion = await this.readCurrentVersion(binary.path, probe) }\n catch { missing = probe.missing === true; invalid = !missing }\n let latestVersion: string | null = null\n try { latestVersion = await this.readLatestVersion() } catch { /* Local admission remains available offline. */ }\n const state = invalid ? \"error\" : missing ? \"missing\"\n : currentVersion && !isBelowOpenCodeMinimum(currentVersion) ? \"ready\" : \"update_required\"\n const updateAvailable = latestVersion && (!currentVersion || comparableVersion(currentVersion))\n ? !currentVersion || compareOpenCodeVersionStrings(latestVersion, currentVersion) > 0 : null\n const status: OpenCodeUpdateStatus = {\n currentVersion, latestVersion, updateAvailable,\n canUpgrade: !invalid && Boolean(updateAvailable || needsSharedInstallation(binary)) && Boolean(latestVersion && !isBelowOpenCodeMinimum(latestVersion)) && this.deps.canUpgradeBinary(binary),\n minimumVersion: MINIMUM_OPENCODE_VERSION, recommendedVersion: RECOMMENDED_OPENCODE_VERSION,\n versionAssessment: \"untested\", state, binaryPath: binary.path,\n installationSource: binary.source, needsSharedInstallation: needsSharedInstallation(binary),\n target: parseWslUncPath(binary.path) ? \"wsl\" : \"host\", canRestart: false,\n ...(!latestVersion ? { checkError: \"update_check_failed\" as const } : {}),\n }\n if (!missing && !invalid && this.deps.lifecycle) {\n try {\n const lifecycle = await this.deps.lifecycle(binary)\n const endpoint = await lifecycle.discover()\n const identity = endpoint && runtimeIdentity(endpoint)\n status.daemonVersion = identity?.version\n const olderDaemon = identity && currentVersion && comparableVersion(identity.version) && comparableVersion(currentVersion)\n && compareOpenCodeVersionStrings(currentVersion, identity.version) > 0\n status.serviceState = \"stopped\"\n if (endpoint) {\n try {\n const capabilities = await this.inspectRuntime(endpoint)\n status.serviceState = olderDaemon ? \"restart_available\" : \"ready\"\n // The running daemon, not an older discovery CLI, serves requests.\n status.state = \"ready\"\n status.canReload = Boolean(this.deps.reload) && capabilities.reload\n } catch (error) {\n if (!(error instanceof UnsupportedOpenCodeError)) throw error\n status.incompatibilityReason = error.reason\n status.serviceState = olderDaemon ? \"restart_required\" : \"incompatible\"\n }\n }\n status.canRestart = Boolean(lifecycle.restart) && state === \"ready\"\n && (status.serviceState === \"restart_required\" || status.serviceState === \"restart_available\")\n } catch { status.serviceState = \"error\"; status.serviceError = \"service_check_failed\" }\n }\n const effectiveVersion = status.daemonVersion ?? currentVersion\n if (!status.incompatibilityReason && effectiveVersion && isBelowOpenCodeMinimum(effectiveVersion)) status.incompatibilityReason = \"step_timestamp\"\n status.versionAssessment = status.incompatibilityReason ? \"incompatible\"\n : effectiveVersion === RECOMMENDED_OPENCODE_VERSION ? \"tested\" : \"untested\"\n return status\n }\n\n private async inspectRuntime(endpoint: Endpoint): Promise<{ reload: boolean }> {\n const identity = runtimeIdentity(endpoint)\n if (!identity) throw new Error(\"OpenCode did not report an authenticated runtime version\")\n assertSupportedOpenCode(identity.version)\n if (this.deps.inspectRuntime) return this.deps.inspectRuntime(endpoint)\n await createRuntimeTransport(endpoint).profile()\n return { reload: identity.contract?.reload ?? contractProfile(identity) === \"modern\" }\n }\n\n start(restart = false): Promise<OpenCodeUpdateStatus> {\n return this.runServiceAction(restart ? \"restart\" : \"start\")\n }\n\n reload(): Promise<OpenCodeUpdateStatus> {\n return this.runServiceAction(\"reload\")\n }\n\n private runServiceAction(action: ServiceAction): Promise<OpenCodeUpdateStatus> {\n const binary = this.deps.resolveBinary()\n // One updater owns one manager/shared-service authority. Executable selection\n // is mutable and cannot be the lock key for daemon-wide operations.\n const existing = this.activation\n if (existing) return existing.action === action && existing.binaryPath === binary.path\n ? existing.pending : Promise.reject(new Error(\"Another OpenCode service action is in progress\"))\n const pending = this.activate(binary, action).finally(() => {\n if (this.activation?.pending === pending) this.activation = undefined\n })\n this.activation = { binaryPath: binary.path, action, pending }\n return pending\n }\n\n private async activate(binary: ResolvedBinary, action: ServiceAction): Promise<OpenCodeUpdateStatus> {\n const restart = action === \"restart\"\n const installedVersion = await this.readCurrentVersion(binary.path)\n const lifecycle = await this.deps.lifecycle?.(binary)\n if (!lifecycle) throw new Error(\"OpenCode service lifecycle unavailable\")\n const previous = await lifecycle.discover()\n if (!previous || restart) assertSupportedOpenCode(installedVersion)\n if (restart && previous) {\n const identity = runtimeIdentity(previous)\n if (!identity || !comparableVersion(identity.version) || !comparableVersion(installedVersion)\n || compareOpenCodeVersionStrings(installedVersion, identity.version) <= 0) {\n throw new Error(\"The shared daemon is not an older runtime eligible for this update\")\n }\n }\n const assertCurrent = () => {\n if (this.deps.resolveBinary().path !== binary.path) throw new Error(\"OpenCode selection changed during activation\")\n this.deps.admitActivation?.(binary)\n }\n assertCurrent()\n if (action === \"reload\") {\n const identity = previous && runtimeIdentity(previous)\n if (!identity || !this.deps.reload) throw new Error(\"OpenCode configuration reload unavailable\")\n const capabilities = await this.inspectRuntime(previous!)\n if (!capabilities.reload) throw new Error(\"OpenCode does not expose configuration reload\")\n assertCurrent()\n // Explicit daemon-wide mutation: never use this as an automatic watcher\n // fallback, because native reload cancels pending Forms and permissions.\n await this.deps.reload(binary, assertCurrent)\n assertCurrent()\n return this.getStatus()\n }\n const endpoint = restart && previous ? await lifecycle.restart?.() : previous ?? await lifecycle.ensure()\n const identity = endpoint && runtimeIdentity(endpoint)\n if (!identity) throw new Error(\"OpenCode did not report an authenticated runtime version\")\n await this.inspectRuntime(endpoint!)\n if (this.deps.resolveBinary().path !== binary.path) throw new Error(\"OpenCode selection changed during activation\")\n await this.deps.reconnect?.(binary)\n return this.getStatus()\n }\n\n upgrade(): Promise<OpenCodeUpdateResponse> {\n const binary = this.deps.resolveBinary()\n const existing = inFlightUpgrades.get(binary.path)\n if (existing) return existing\n\n const pending = this.performUpgrade(binary).finally(() => {\n if (inFlightUpgrades.get(binary.path) === pending) inFlightUpgrades.delete(binary.path)\n })\n inFlightUpgrades.set(binary.path, pending)\n return pending\n }\n\n private async performUpgrade(binary: ResolvedBinary): Promise<OpenCodeUpdateResponse> {\n const probe = await this.deps.probeBinary(binary.path)\n const currentVersion = probe.missing ? null : await this.readCurrentVersion(binary.path, probe)\n const latestVersion = await this.readLatestVersion()\n assertSupportedOpenCode(latestVersion)\n\n if (currentVersion && !comparableVersion(currentVersion)) {\n throw new OpenCodeUpdateError(\"unsupported_binary\", \"Cannot order this custom OpenCode version for an automatic update\")\n }\n\n if (currentVersion && compareOpenCodeVersionStrings(latestVersion, currentVersion) <= 0 && !needsSharedInstallation(binary)) {\n return { success: true, version: currentVersion }\n }\n\n if (!this.deps.canUpgradeBinary(binary)) {\n throw new OpenCodeUpdateError(\n \"unsupported_binary\",\n \"Automatic updates require the default command and a writable npm installation\",\n )\n }\n\n try {\n const targetVersion = currentVersion && compareOpenCodeVersionStrings(currentVersion, latestVersion) > 0 ? currentVersion : latestVersion\n const result = await this.deps.upgradeBinary(binary, targetVersion)\n if (!result.success) {\n throw new OpenCodeUpdateError(\"upgrade_failed\", result.error)\n }\n const installedVersion = await this.readCurrentVersion(this.deps.resolveBinary().path)\n if (isBelowOpenCodeMinimum(installedVersion) || !/^\\d+\\.\\d+\\.\\d+$/.test(installedVersion) || compareOpenCodeVersionStrings(installedVersion, targetVersion) < 0) {\n throw new OpenCodeUpdateError(\n \"upgrade_verification_failed\",\n `OpenCode reported ${result.version}, but the configured binary is ${installedVersion} instead of ${latestVersion}`,\n )\n }\n return { success: true, version: installedVersion }\n } catch (error) {\n if (error instanceof OpenCodeUpdateError || error instanceof InstallationBusyError) throw error\n throw new OpenCodeUpdateError(\n \"upgrade_failed\",\n error instanceof Error ? error.message : \"OpenCode upgrade failed\",\n )\n }\n }\n\n private async readCurrentVersion(binaryPath: string, probe?: ReturnType<typeof probeBinaryVersion>): Promise<string> {\n if (process.platform === \"win32\" && /[\"\\r\\n]/.test(binaryPath)) {\n throw new OpenCodeUpdateError(\"binary_unavailable\", \"The configured OpenCode binary path is invalid\")\n }\n const result = probe ?? await this.deps.probeBinary(binaryPath)\n if (!result.valid) {\n throw new OpenCodeUpdateError(\"binary_unavailable\", result.error ?? \"Unable to read OpenCode version\")\n }\n // Successful unknown/empty labels are diagnostic information. Admission is\n // established against the authenticated daemon, not inferred from this label.\n return result.version?.trim() || \"unknown\"\n }\n\n private async readLatestVersion(): Promise<string> {\n try {\n const version = stripTagPrefix(await this.deps.resolveLatestVersion())\n if (!version) throw new Error(`The ${TARGET_OPENCODE_CHANNEL} channel did not resolve to a version`)\n return version\n } catch (error) {\n throw new OpenCodeUpdateError(\n \"update_check_failed\",\n error instanceof Error ? error.message : \"Unable to resolve the latest stable OpenCode release\",\n )\n }\n }\n}\n\nexport function compareOpenCodeVersionStrings(left: string, right: string): number {\n const leftBeta = stripTagPrefix(left)?.match(/^0\\.0\\.0-beta-(\\d+)$/)\n const rightBeta = stripTagPrefix(right)?.match(/^0\\.0\\.0-beta-(\\d+)$/)\n if (leftBeta && rightBeta) return Number(leftBeta[1]) - Number(rightBeta[1])\n return compareVersionStrings(left, right)\n}\n\ntype RegistryFetch = (\n url: string,\n init: Parameters<typeof fetch>[1],\n) => Promise<Pick<Awaited<ReturnType<typeof fetch>>, \"ok\" | \"status\" | \"json\">>\n\nexport async function resolveLatestOpenCodeVersion(fetchRegistry: RegistryFetch = fetch): Promise<string> {\n const response = await fetchRegistry(OPENCODE_REGISTRY_URL, {\n headers: { Accept: \"application/json\" },\n signal: AbortSignal.timeout(10_000),\n })\n if (!response.ok) throw new Error(`OpenCode registry responded with ${response.status}`)\n\n const metadata = (await response.json()) as Record<string, unknown>\n const version = metadata[TARGET_OPENCODE_CHANNEL]\n if (typeof version !== \"string\" || !/^\\d+\\.\\d+\\.\\d+$/.test(version)) {\n throw new Error(`The ${TARGET_OPENCODE_CHANNEL} channel did not resolve to a valid version`)\n }\n return version\n}\n\nexport function createOpenCodeUpdateService(\n settings: SettingsService,\n workspaceManager: WorkspaceManager,\n): OpenCodeUpdateService {\n const binaryResolver = new BinaryResolver(settings)\n return new OpenCodeUpdateService({\n resolveBinary: () => {\n const binary = binaryResolver.resolveDefault()\n return { ...binary, path: workspaceManager.resolveBinaryPath(binary.path) }\n },\n probeBinary: probeBinaryVersionAsync,\n resolveLatestVersion: resolveLatestOpenCodeVersion,\n canUpgradeBinary: binary => {\n const configured = settings.getOwner(\"config\", \"server\").opencodeBinary\n return !parseWslUncPath(binary.path) && (!configured || configured === \"opencode\" || configured === \"opencode2\" || (typeof configured === \"string\" && isRetiredInstallation(configured))) && Boolean(bundledNpm()) && Boolean(sharedInstallPrefix())\n },\n upgradeBinary: async (_binary, version) => {\n await installSharedOpenCode(version)\n return { success: true, version }\n },\n lifecycle: binary => workspaceManager.setupServiceOptions(binary.path).then(options => options.lifecycle),\n reconnect: binary => workspaceManager.reconnectAfterSetup(binary.path),\n admitActivation: binary => workspaceManager.assertSetupExecutionHost(binary.path),\n reload: (binary, assertCurrent) => workspaceManager.reloadConfigurationAfterSetup(binary.path, assertCurrent),\n })\n}\n\nfunction comparableVersion(version: string): boolean {\n return /^\\d+\\.\\d+\\.\\d+$/.test(version) || /^0\\.0\\.0-beta-\\d+$/.test(version)\n}\n\nfunction needsSharedInstallation(binary: ResolvedBinary): boolean {\n return binary.source === \"user\"\n}\n"]}