charness 3.12.0 → 3.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (232) hide show
  1. package/.env.example +5 -0
  2. package/CHANGELOG.md +27 -0
  3. package/DEVELOPMENT.md +78 -15
  4. package/README.md +2 -1
  5. package/SETUP.md +65 -20
  6. package/agent-plugin/skills/charness-delegate-claude/SKILL.md +14 -5
  7. package/dist/accessControl.d.ts +43 -0
  8. package/dist/accessControl.d.ts.map +1 -1
  9. package/dist/accessControl.js +50 -1
  10. package/dist/accessControl.js.map +1 -1
  11. package/dist/adapters/claudeCliAdapter.d.ts.map +1 -1
  12. package/dist/adapters/claudeCliAdapter.js +9 -4
  13. package/dist/adapters/claudeCliAdapter.js.map +1 -1
  14. package/dist/adapters/claudeJsonStreamAdapter.js +1 -1
  15. package/dist/adapters/claudeJsonStreamAdapter.js.map +1 -1
  16. package/dist/adapters/claudePlatformFlags.d.ts +4 -3
  17. package/dist/adapters/claudePlatformFlags.d.ts.map +1 -1
  18. package/dist/adapters/claudePlatformFlags.js +4 -3
  19. package/dist/adapters/claudePlatformFlags.js.map +1 -1
  20. package/dist/adapters/openCodeAdapter.d.ts +37 -13
  21. package/dist/adapters/openCodeAdapter.d.ts.map +1 -1
  22. package/dist/adapters/openCodeAdapter.js +73 -41
  23. package/dist/adapters/openCodeAdapter.js.map +1 -1
  24. package/dist/adapters/terminalAdapter.d.ts.map +1 -1
  25. package/dist/adapters/terminalAdapter.js +5 -3
  26. package/dist/adapters/terminalAdapter.js.map +1 -1
  27. package/dist/agentLogin/agentLogin.d.ts.map +1 -1
  28. package/dist/agentLogin/agentLogin.js +2 -14
  29. package/dist/agentLogin/agentLogin.js.map +1 -1
  30. package/dist/bot.d.ts +12 -3
  31. package/dist/bot.d.ts.map +1 -1
  32. package/dist/bot.js +476 -133
  33. package/dist/bot.js.map +1 -1
  34. package/dist/cli/claudeProfiles.js +2 -2
  35. package/dist/cli/claudeProfiles.js.map +1 -1
  36. package/dist/connectors/jira/client.js +1 -1
  37. package/dist/connectors/jira/client.js.map +1 -1
  38. package/dist/connectors/jira/config.d.ts +7 -0
  39. package/dist/connectors/jira/config.d.ts.map +1 -1
  40. package/dist/connectors/jira/config.js +12 -1
  41. package/dist/connectors/jira/config.js.map +1 -1
  42. package/dist/connectors/jira/connector.d.ts +7 -0
  43. package/dist/connectors/jira/connector.d.ts.map +1 -1
  44. package/dist/connectors/jira/connector.js +20 -3
  45. package/dist/connectors/jira/connector.js.map +1 -1
  46. package/dist/connectors/jira/inbound.d.ts.map +1 -1
  47. package/dist/connectors/jira/inbound.js +4 -3
  48. package/dist/connectors/jira/inbound.js.map +1 -1
  49. package/dist/connectors/jira/issueBlocks.d.ts +1 -1
  50. package/dist/connectors/jira/trustedGroup.d.ts +21 -6
  51. package/dist/connectors/jira/trustedGroup.d.ts.map +1 -1
  52. package/dist/connectors/jira/trustedGroup.js +46 -6
  53. package/dist/connectors/jira/trustedGroup.js.map +1 -1
  54. package/dist/connectors/telegram/commands/botCore.d.ts +19 -2
  55. package/dist/connectors/telegram/commands/botCore.d.ts.map +1 -1
  56. package/dist/connectors/telegram/commands/compaction.d.ts +5 -3
  57. package/dist/connectors/telegram/commands/compaction.d.ts.map +1 -1
  58. package/dist/connectors/telegram/commands/compaction.js +9 -6
  59. package/dist/connectors/telegram/commands/compaction.js.map +1 -1
  60. package/dist/connectors/telegram/commands/todo.d.ts.map +1 -1
  61. package/dist/connectors/telegram/commands/todo.js +2 -2
  62. package/dist/connectors/telegram/commands/todo.js.map +1 -1
  63. package/dist/connectors/telegram/commands/topicAccess.d.ts +30 -0
  64. package/dist/connectors/telegram/commands/topicAccess.d.ts.map +1 -0
  65. package/dist/connectors/telegram/commands/topicAccess.js +399 -0
  66. package/dist/connectors/telegram/commands/topicAccess.js.map +1 -0
  67. package/dist/connectors/telegram/inbound.d.ts +44 -7
  68. package/dist/connectors/telegram/inbound.d.ts.map +1 -1
  69. package/dist/connectors/telegram/inbound.js +142 -24
  70. package/dist/connectors/telegram/inbound.js.map +1 -1
  71. package/dist/i18n/de.d.ts.map +1 -1
  72. package/dist/i18n/de.js +68 -0
  73. package/dist/i18n/de.js.map +1 -1
  74. package/dist/i18n/en.d.ts.map +1 -1
  75. package/dist/i18n/en.js +68 -0
  76. package/dist/i18n/en.js.map +1 -1
  77. package/dist/i18n/es.d.ts.map +1 -1
  78. package/dist/i18n/es.js +68 -0
  79. package/dist/i18n/es.js.map +1 -1
  80. package/dist/i18n/fr.d.ts.map +1 -1
  81. package/dist/i18n/fr.js +68 -0
  82. package/dist/i18n/fr.js.map +1 -1
  83. package/dist/i18n/hi.d.ts.map +1 -1
  84. package/dist/i18n/hi.js +68 -0
  85. package/dist/i18n/hi.js.map +1 -1
  86. package/dist/i18n/ja.d.ts.map +1 -1
  87. package/dist/i18n/ja.js +68 -0
  88. package/dist/i18n/ja.js.map +1 -1
  89. package/dist/i18n/ka.d.ts.map +1 -1
  90. package/dist/i18n/ka.js +68 -0
  91. package/dist/i18n/ka.js.map +1 -1
  92. package/dist/i18n/pt.d.ts.map +1 -1
  93. package/dist/i18n/pt.js +68 -0
  94. package/dist/i18n/pt.js.map +1 -1
  95. package/dist/i18n/ru.d.ts.map +1 -1
  96. package/dist/i18n/ru.js +68 -0
  97. package/dist/i18n/ru.js.map +1 -1
  98. package/dist/i18n/uk.d.ts.map +1 -1
  99. package/dist/i18n/uk.js +68 -0
  100. package/dist/i18n/uk.js.map +1 -1
  101. package/dist/i18n/uz.d.ts.map +1 -1
  102. package/dist/i18n/uz.js +68 -0
  103. package/dist/i18n/uz.js.map +1 -1
  104. package/dist/i18n/zh.d.ts.map +1 -1
  105. package/dist/i18n/zh.js +68 -0
  106. package/dist/i18n/zh.js.map +1 -1
  107. package/dist/installManager.d.ts +37 -1
  108. package/dist/installManager.d.ts.map +1 -1
  109. package/dist/installManager.js +205 -14
  110. package/dist/installManager.js.map +1 -1
  111. package/dist/platform/commandRouter.d.ts +13 -1
  112. package/dist/platform/commandRouter.d.ts.map +1 -1
  113. package/dist/platform/commandRouter.js +14 -2
  114. package/dist/platform/commandRouter.js.map +1 -1
  115. package/dist/platform/inbound.d.ts +2 -0
  116. package/dist/platform/inbound.d.ts.map +1 -1
  117. package/dist/runners/runnerLock.d.ts +36 -1
  118. package/dist/runners/runnerLock.d.ts.map +1 -1
  119. package/dist/runners/runnerLock.js +94 -30
  120. package/dist/runners/runnerLock.js.map +1 -1
  121. package/dist/scheduler/checkRun.d.ts +0 -2
  122. package/dist/scheduler/checkRun.d.ts.map +1 -1
  123. package/dist/scheduler/checkRun.js +0 -10
  124. package/dist/scheduler/checkRun.js.map +1 -1
  125. package/dist/selfUpdate/bootRollback.d.ts.map +1 -1
  126. package/dist/selfUpdate/bootRollback.js +3 -2
  127. package/dist/selfUpdate/bootRollback.js.map +1 -1
  128. package/dist/selfUpdate/updateRuntime.d.ts.map +1 -1
  129. package/dist/selfUpdate/updateRuntime.js +6 -3
  130. package/dist/selfUpdate/updateRuntime.js.map +1 -1
  131. package/dist/state.d.ts +49 -0
  132. package/dist/state.d.ts.map +1 -1
  133. package/dist/state.js +112 -0
  134. package/dist/state.js.map +1 -1
  135. package/dist/threadContextPreamble.d.ts +15 -1
  136. package/dist/threadContextPreamble.d.ts.map +1 -1
  137. package/dist/threadContextPreamble.js +15 -3
  138. package/dist/threadContextPreamble.js.map +1 -1
  139. package/dist/threadRouting.d.ts +47 -4
  140. package/dist/threadRouting.d.ts.map +1 -1
  141. package/dist/threadRouting.js +31 -4
  142. package/dist/threadRouting.js.map +1 -1
  143. package/dist/todos/projects.d.ts +1 -1
  144. package/dist/todos/projects.d.ts.map +1 -1
  145. package/dist/todos/projects.js +3 -14
  146. package/dist/todos/projects.js.map +1 -1
  147. package/dist/topicTalkerMemory.d.ts +37 -0
  148. package/dist/topicTalkerMemory.d.ts.map +1 -0
  149. package/dist/topicTalkerMemory.js +61 -0
  150. package/dist/topicTalkerMemory.js.map +1 -0
  151. package/dist/topicTalkers.d.ts +123 -0
  152. package/dist/topicTalkers.d.ts.map +1 -0
  153. package/dist/topicTalkers.js +276 -0
  154. package/dist/topicTalkers.js.map +1 -0
  155. package/dist/types.d.ts +5 -4
  156. package/dist/types.d.ts.map +1 -1
  157. package/dist/utils/agentEnvironment.d.ts +23 -0
  158. package/dist/utils/agentEnvironment.d.ts.map +1 -1
  159. package/dist/utils/agentEnvironment.js +33 -1
  160. package/dist/utils/agentEnvironment.js.map +1 -1
  161. package/dist/utils/agentPlugin.d.ts +7 -2
  162. package/dist/utils/agentPlugin.d.ts.map +1 -1
  163. package/dist/utils/agentPlugin.js +11 -5
  164. package/dist/utils/agentPlugin.js.map +1 -1
  165. package/dist/utils/authorMark.d.ts +59 -0
  166. package/dist/utils/authorMark.d.ts.map +1 -0
  167. package/dist/utils/authorMark.js +86 -0
  168. package/dist/utils/authorMark.js.map +1 -0
  169. package/dist/utils/claudeLimitSwitch.d.ts +5 -1
  170. package/dist/utils/claudeLimitSwitch.d.ts.map +1 -1
  171. package/dist/utils/claudeLimitSwitch.js +6 -2
  172. package/dist/utils/claudeLimitSwitch.js.map +1 -1
  173. package/dist/utils/claudeProfileUsageLines.d.ts +1 -1
  174. package/dist/utils/claudeProfileUsageLines.js +3 -3
  175. package/dist/utils/claudeProfileUsageLines.js.map +1 -1
  176. package/dist/utils/claudeProfiles.d.ts +7 -0
  177. package/dist/utils/claudeProfiles.d.ts.map +1 -1
  178. package/dist/utils/claudeProfiles.js +15 -0
  179. package/dist/utils/claudeProfiles.js.map +1 -1
  180. package/dist/utils/claudeUsage.d.ts +56 -20
  181. package/dist/utils/claudeUsage.d.ts.map +1 -1
  182. package/dist/utils/claudeUsage.js +81 -38
  183. package/dist/utils/claudeUsage.js.map +1 -1
  184. package/dist/utils/fallbackChain.d.ts.map +1 -1
  185. package/dist/utils/fallbackChain.js +8 -4
  186. package/dist/utils/fallbackChain.js.map +1 -1
  187. package/dist/utils/folderGit.d.ts +9 -0
  188. package/dist/utils/folderGit.d.ts.map +1 -0
  189. package/dist/utils/folderGit.js +33 -0
  190. package/dist/utils/folderGit.js.map +1 -0
  191. package/dist/utils/forwardedMark.d.ts +8 -0
  192. package/dist/utils/forwardedMark.d.ts.map +1 -1
  193. package/dist/utils/forwardedMark.js +2 -0
  194. package/dist/utils/forwardedMark.js.map +1 -1
  195. package/dist/utils/jsonStreamHost.d.ts +2 -1
  196. package/dist/utils/jsonStreamHost.d.ts.map +1 -1
  197. package/dist/utils/jsonStreamHost.js +4 -2
  198. package/dist/utils/jsonStreamHost.js.map +1 -1
  199. package/dist/utils/messageContext.d.ts +22 -7
  200. package/dist/utils/messageContext.d.ts.map +1 -1
  201. package/dist/utils/messageContext.js +19 -5
  202. package/dist/utils/messageContext.js.map +1 -1
  203. package/dist/utils/personLabel.d.ts +13 -0
  204. package/dist/utils/personLabel.d.ts.map +1 -0
  205. package/dist/utils/personLabel.js +15 -0
  206. package/dist/utils/personLabel.js.map +1 -0
  207. package/dist/utils/replyQuote.d.ts +17 -3
  208. package/dist/utils/replyQuote.d.ts.map +1 -1
  209. package/dist/utils/replyQuote.js +25 -2
  210. package/dist/utils/replyQuote.js.map +1 -1
  211. package/dist/utils/talkerAccess.d.ts +9 -0
  212. package/dist/utils/talkerAccess.d.ts.map +1 -0
  213. package/dist/utils/talkerAccess.js +20 -0
  214. package/dist/utils/talkerAccess.js.map +1 -0
  215. package/dist/utils/tmuxExec.d.ts +20 -8
  216. package/dist/utils/tmuxExec.d.ts.map +1 -1
  217. package/dist/utils/tmuxExec.js +27 -7
  218. package/dist/utils/tmuxExec.js.map +1 -1
  219. package/dist/utils/topicAccessScreenPlan.d.ts +253 -0
  220. package/dist/utils/topicAccessScreenPlan.d.ts.map +1 -0
  221. package/dist/utils/topicAccessScreenPlan.js +287 -0
  222. package/dist/utils/topicAccessScreenPlan.js.map +1 -0
  223. package/dist/utils/topicLabel.d.ts +12 -0
  224. package/dist/utils/topicLabel.d.ts.map +1 -0
  225. package/dist/utils/topicLabel.js +12 -0
  226. package/dist/utils/topicLabel.js.map +1 -0
  227. package/dist/utils/topicRequest.d.ts +8 -5
  228. package/dist/utils/topicRequest.d.ts.map +1 -1
  229. package/dist/utils/topicRequest.js +9 -7
  230. package/dist/utils/topicRequest.js.map +1 -1
  231. package/npm-shrinkwrap.json +1003 -0
  232. package/package.json +4 -2
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.OpenCodeAdapter = exports.openCodeServerRestartRetryBudgetMs = exports.openCodeServerRestartRetryDelaysMs = exports.schedulerMcpRetryDelaysMs = exports.openCodeErrorMessageMaxLength = exports.providerRetryReplacementStartTimeoutMs = exports.criticalSseEventTypes = exports.openCodeRuntimeContextHydrationConcurrency = void 0;
36
+ exports.OpenCodeAdapter = exports.mislaunchedServerRecheckDelayMs = exports.openCodeServerRestartRetryBudgetMs = exports.openCodeServerRestartRetryDelaysMs = exports.schedulerMcpRetryDelaysMs = exports.openCodeErrorMessageMaxLength = exports.providerRetryReplacementStartTimeoutMs = exports.criticalSseEventTypes = exports.openCodeRuntimeContextHydrationConcurrency = void 0;
37
37
  exports.listSavedOpenCodeModelLabels = listSavedOpenCodeModelLabels;
38
38
  exports.normaliseOpenCodeSseEvent = normaliseOpenCodeSseEvent;
39
39
  exports.buildDirectoryScopedPath = buildDirectoryScopedPath;
@@ -1010,6 +1010,12 @@ exports.openCodeServerRestartRetryDelaysMs = [2_000, 5_000, 10_000, 15_000, 20_0
1010
1010
  * a hopeless start from holding the topics for minutes.
1011
1011
  */
1012
1012
  exports.openCodeServerRestartRetryBudgetMs = 60_000;
1013
+ /**
1014
+ * How long {@link OpenCodeAdapter.replaceMislaunchedServer} waits before it looks again at a server it must replace while a
1015
+ * session works in it: a plain instance boots rarely, so "the next boot" alone could leave a server without a password open
1016
+ * for days.
1017
+ */
1018
+ exports.mislaunchedServerRecheckDelayMs = 10 * 60_000;
1013
1019
  /**
1014
1020
  * @description The pause before retry number `retryIndex` (0-based), or
1015
1021
  * `null` once the pauses are used up or the retry would start past `budgetMs`
@@ -1028,6 +1034,7 @@ const defaultOpenCodeServerRestartOps = {
1028
1034
  ensureServer: installManager_1.ensureOpenCodeServer,
1029
1035
  restartServer: installManager_1.restartOpenCodeServer,
1030
1036
  readServerLaunch: installManager_1.readOpenCodeServerLaunch,
1037
+ readServerExposure: installManager_1.readOpenCodeServerExposure,
1031
1038
  };
1032
1039
  function buildProviderApiAuthPayload(apiKey) {
1033
1040
  return { type: 'api', key: apiKey };
@@ -1235,7 +1242,6 @@ class OpenCodeAdapter extends events_1.EventEmitter {
1235
1242
  */
1236
1243
  sseDropLogThrottle = new Map();
1237
1244
  baseUrl;
1238
- authHeader;
1239
1245
  /**
1240
1246
  * Grace period (ms) the fallback rename waits for opencode's native
1241
1247
  * auto-title before stepping in. Instance field (initialised from
@@ -1268,8 +1274,12 @@ class OpenCodeAdapter extends events_1.EventEmitter {
1268
1274
  * tests can fail attempts and shrink the pauses — production never changes them.
1269
1275
  */
1270
1276
  serverRestartOps = defaultOpenCodeServerRestartOps;
1271
- /** The skills boot step said once why it leaves the running server alone (`activateAgentSkillsForServer`). */
1272
- isAgentSkillsSkipAnnounced = false;
1277
+ /** The boot step said once why it leaves the running server alone (`replaceMislaunchedServer`). */
1278
+ isMislaunchedServerSkipAnnounced = false;
1279
+ /** The pending look again of {@link replaceMislaunchedServer} at a server a working session kept it from replacing. */
1280
+ mislaunchedServerRecheckTimer = null;
1281
+ /** Instance field only so a test can shorten it; production keeps {@link mislaunchedServerRecheckDelayMs}. */
1282
+ mislaunchedServerRecheckDelayMs = exports.mislaunchedServerRecheckDelayMs;
1273
1283
  serverRestartRetryDelaysMs = exports.openCodeServerRestartRetryDelaysMs;
1274
1284
  serverRestartRetryBudgetMs = exports.openCodeServerRestartRetryBudgetMs;
1275
1285
  /**
@@ -1335,14 +1345,6 @@ class OpenCodeAdapter extends events_1.EventEmitter {
1335
1345
  super();
1336
1346
  // Audit S7 / #34: SSRF guard on OPENCODE_URL before any fetch runs.
1337
1347
  this.baseUrl = validateOpenCodeUrl(process.env.OPENCODE_URL || installManager_1.defaultOpenCodeUrl);
1338
- const password = process.env.OPENCODE_PASSWORD;
1339
- if (password) {
1340
- const username = process.env.OPENCODE_USERNAME || 'opencode';
1341
- this.authHeader = 'Basic ' + Buffer.from(`${username}:${password}`).toString('base64');
1342
- }
1343
- else {
1344
- this.authHeader = null;
1345
- }
1346
1348
  // Listen for unexpected server crashes (OOM kill, segfault, etc.)
1347
1349
  (0, installManager_1.onOpenCodeServerExit)((code, signal) => {
1348
1350
  console.error(`[OpenCode] Server crashed unexpectedly: code=${code}, signal=${signal}`);
@@ -1535,15 +1537,13 @@ class OpenCodeAdapter extends events_1.EventEmitter {
1535
1537
  async reloadProviderAuth() {
1536
1538
  return this.restartServer(true);
1537
1539
  }
1540
+ /** @description Read per request: every server generation the bot starts has a password of its own. */
1538
1541
  getHeaders() {
1539
- const headers = {
1542
+ return {
1540
1543
  'Content-Type': 'application/json',
1541
1544
  'Accept': 'application/json',
1545
+ ...(0, installManager_1.getOpenCodeServerAuthHeaders)(),
1542
1546
  };
1543
- if (this.authHeader) {
1544
- headers['Authorization'] = this.authHeader;
1545
- }
1546
- return headers;
1547
1547
  }
1548
1548
  async apiRequest(method, urlPath, body, options) {
1549
1549
  const url = `${this.baseUrl}${urlPath}`;
@@ -3081,41 +3081,75 @@ class OpenCodeAdapter extends events_1.EventEmitter {
3081
3081
  await Promise.allSettled(Array.from(directories, (directory) => this.reconcileSchedulerMcpForDirectory(directory)));
3082
3082
  }
3083
3083
  /**
3084
- * @description Boot step for the skills the bot gives its agents (`utils/agentPlugin.ts`). OpenCode reads its
3085
- * `OPENCODE_CONFIG_DIR` once, at start, so a server started the other way than the instance's «Bot skills» switch says —
3086
- * without the bot's folder while the switch is ON (an older bot, adopted ever since; the switch turned on since), with it
3087
- * while the switch is OFF — keeps offering the wrong thing. Such a server is replaced through the controlled restart that
3088
- * restores the sessions, but only when the bot owns it (its process record) AND `/proc` shows it is an `opencode … serve`
3089
- * (a server the bot does not own, or a listener it cannot identify, is left as is — one log line per process), the folder
3090
- * it would get is ready, and no session is working: a busy directory, or a status it cannot read, leaves it for the next
3091
- * boot. Only the INSTANCE value counts: one server serves every topic. Best-effort, never rejects.
3084
+ * @description Boot step that replaces a server started the wrong way, which a running server never corrects by itself:
3085
+ * - the skills the bot gives its agents (`utils/agentPlugin.ts`): OpenCode reads its `OPENCODE_CONFIG_DIR` once, at start,
3086
+ * so a server started the other way than the instance's «Bot skills» switch says — without the bot's folder while the
3087
+ * switch is ON (an older bot, adopted ever since; the switch turned on since), with it while the switch is OFF — keeps
3088
+ * offering the wrong thing; only the INSTANCE value counts: one server serves every topic. Replaced only when the bot
3089
+ * owns it (its process record) AND `/proc` shows it is an `opencode … serve`, and the folder it would get is ready;
3090
+ * - its password: a server that answers a request without one lets every local account drive its agents. Read the way such
3091
+ * an account would, on every platform ({@link OpenCodeServerExposure}), and replaced whether the bot owns it or not — like a
3092
+ * stale version — as long as it is an `opencode … serve` the bot may stop: one a bot from before passwords left running,
3093
+ * and also one the operator runs on the bot's port (the idle check sees only the bot's sessions, so a turn of the
3094
+ * operator's own in it ends; the docs tell them to start such a server with `OPENCODE_SERVER_PASSWORD`). A test's
3095
+ * stand-in or another account's process never is.
3096
+ * The replacement is the controlled restart that restores the sessions, and only when no session is working: a busy
3097
+ * directory, or a status it cannot read, makes it look again after {@link mislaunchedServerRecheckDelayMs} (and at the
3098
+ * next boot). A server it leaves for another reason gets one log line per process. Best-effort, never rejects.
3092
3099
  */
3093
- async activateAgentSkillsForServer() {
3100
+ async replaceMislaunchedServer() {
3094
3101
  try {
3095
3102
  const expectation = (0, agentPlugin_1.getOpenCodeAgentSkillsExpectation)(process.env, (0, state_1.resolveDataDir)(), (0, botSkills_1.checkIsBotSkillsEnabled)(null));
3096
- const action = (0, agentPlugin_1.getOpenCodeAgentSkillsServerAction)(await this.serverRestartOps.readServerLaunch(), expectation);
3097
- if (action === 'skipNotOwned' || action === 'skipUnidentified') {
3098
- if (!this.isAgentSkillsSkipAnnounced) {
3099
- this.isAgentSkillsSkipAnnounced = true;
3100
- const reason = action === 'skipNotOwned' ? 'is not owned by the bot' : 'cannot be identified as `opencode serve`';
3101
- console.log(`[OpenCode] the server ${reason}; it is left as is, and offers the bot's skills only if it was started with them`);
3102
- }
3103
- return;
3103
+ const skillsAction = (0, agentPlugin_1.getOpenCodeAgentSkillsServerAction)(await this.serverRestartOps.readServerLaunch(), expectation);
3104
+ const exposure = await this.serverRestartOps.readServerExposure();
3105
+ const faults = [];
3106
+ if (skillsAction === 'replace') {
3107
+ faults.push(expectation.kind === 'offered' ? `without the bot's skills` : `with the bot's skills, which the instance switched off`);
3104
3108
  }
3105
- if (action === 'none')
3109
+ if (exposure === 'openStoppable')
3110
+ faults.push('without a password (every local account can drive its agents)');
3111
+ if (faults.length === 0) {
3112
+ const reasonsLeft = [];
3113
+ if (skillsAction === 'skipNotOwned')
3114
+ reasonsLeft.push(`is not owned by the bot, and offers the bot's skills only if it was started with them`);
3115
+ if (skillsAction === 'skipUnidentified')
3116
+ reasonsLeft.push(`cannot be identified as \`opencode serve\`, and offers the bot's skills only if it was started with them`);
3117
+ if (exposure === 'openUnstoppable')
3118
+ reasonsLeft.push('answers without a password, and is not an `opencode serve` of the bot\'s user it may stop');
3119
+ if (reasonsLeft.length > 0)
3120
+ this.announceMislaunchedServerSkipOnce(`the server ${reasonsLeft.join('; it ')}; it is left as is`);
3106
3121
  return;
3107
- const startedWith = expectation.kind === 'offered' ? `without the bot's skills` : `with the bot's skills, which the instance switched off`;
3122
+ }
3123
+ const startedWith = faults.join(' and ');
3108
3124
  if (!(await this.checkIsEveryActiveSessionIdle())) {
3109
- console.log(`[OpenCode] the server was started ${startedWith}; a session is working, the next boot retries`);
3125
+ console.log(`[OpenCode] the server was started ${startedWith}; a session is working, looking again in ${Math.round(this.mislaunchedServerRecheckDelayMs / 60_000)} min`);
3126
+ this.scheduleMislaunchedServerRecheck();
3110
3127
  return;
3111
3128
  }
3112
3129
  console.log(`[OpenCode] the server was started ${startedWith}; replacing it`);
3113
3130
  await this.restartServer(true);
3114
3131
  }
3115
3132
  catch (e) {
3116
- console.warn(`[OpenCode] could not check the server for the bot's skills:`, e instanceof Error ? e.message : e);
3133
+ console.warn(`[OpenCode] could not check how the server was started:`, e instanceof Error ? e.message : e);
3117
3134
  }
3118
3135
  }
3136
+ /** @description Look again at the server once the delay is over; one pending look at a time, never holding the process open. */
3137
+ scheduleMislaunchedServerRecheck() {
3138
+ if (this.mislaunchedServerRecheckTimer)
3139
+ return;
3140
+ this.mislaunchedServerRecheckTimer = setTimeout(() => {
3141
+ this.mislaunchedServerRecheckTimer = null;
3142
+ void this.replaceMislaunchedServer();
3143
+ }, this.mislaunchedServerRecheckDelayMs);
3144
+ this.mislaunchedServerRecheckTimer.unref();
3145
+ }
3146
+ /** @description Say once per process why {@link replaceMislaunchedServer} leaves the running server alone. */
3147
+ announceMislaunchedServerSkipOnce(line) {
3148
+ if (this.isMislaunchedServerSkipAnnounced)
3149
+ return;
3150
+ this.isMislaunchedServerSkipAnnounced = true;
3151
+ console.log(`[OpenCode] ${line}`);
3152
+ }
3119
3153
  /**
3120
3154
  * @description Whether no active session is working — by the adapter's own view and by each directory's status.
3121
3155
  *
@@ -3469,10 +3503,8 @@ class OpenCodeAdapter extends events_1.EventEmitter {
3469
3503
  const streamLabel = stream.directory;
3470
3504
  const headers = {
3471
3505
  'Accept': 'text/event-stream',
3506
+ ...(0, installManager_1.getOpenCodeServerAuthHeaders)(),
3472
3507
  };
3473
- if (this.authHeader) {
3474
- headers['Authorization'] = this.authHeader;
3475
- }
3476
3508
  // Audit S7 / #12: SSE was previously read with no abort path —
3477
3509
  // `await reader.read()` blocks until bytes arrive, so a teardown during a
3478
3510
  // silent server couldn't actually free the connection. The stream-scoped