opencodekit 0.18.23 → 0.18.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -20,7 +20,7 @@ var __require = /* @__PURE__ */ createRequire(import.meta.url);
20
20
 
21
21
  //#endregion
22
22
  //#region package.json
23
- var version = "0.18.23";
23
+ var version = "0.18.24";
24
24
 
25
25
  //#endregion
26
26
  //#region src/utils/license.ts
Binary file
@@ -11,7 +11,7 @@
11
11
  "type-check": "tsc --noEmit"
12
12
  },
13
13
  "dependencies": {
14
- "@opencode-ai/plugin": "1.2.27"
14
+ "@opencode-ai/plugin": "1.3.0"
15
15
  },
16
16
  "devDependencies": {
17
17
  "@types/node": "^25.3.0",
@@ -43,15 +43,29 @@ interface HookDeps {
43
43
  function extractErrorMessage(value: unknown, maxLen = 200): string {
44
44
  if (!value) return "Unknown error";
45
45
  if (typeof value === "string") return value.slice(0, maxLen);
46
- if (value instanceof Error) return (value.message || value.name || "Error").slice(0, maxLen);
46
+ if (value instanceof Error)
47
+ return (value.message || value.name || "Error").slice(0, maxLen);
47
48
  if (typeof value === "object" && value !== null) {
48
49
  const obj = value as Record<string, unknown>;
50
+
51
+ // Handle OpenCode error structure: { name, data: { message, statusCode } }
52
+ if (typeof obj.data === "object" && obj.data !== null) {
53
+ const data = obj.data as Record<string, unknown>;
54
+ if (typeof data.message === "string") {
55
+ const prefix = typeof obj.name === "string" ? `${obj.name}: ` : "";
56
+ const status =
57
+ typeof data.statusCode === "number" ? ` (${data.statusCode})` : "";
58
+ return `${prefix}${data.message}${status}`.slice(0, maxLen);
59
+ }
60
+ }
61
+
49
62
  // Common error shapes: { message }, { error }, { error: { message } }
50
63
  if (typeof obj.message === "string") return obj.message.slice(0, maxLen);
51
64
  if (typeof obj.error === "string") return obj.error.slice(0, maxLen);
52
65
  if (typeof obj.error === "object" && obj.error !== null) {
53
66
  const inner = obj.error as Record<string, unknown>;
54
- if (typeof inner.message === "string") return inner.message.slice(0, maxLen);
67
+ if (typeof inner.message === "string")
68
+ return inner.message.slice(0, maxLen);
55
69
  }
56
70
  // Last resort: JSON stringify with truncation
57
71
  try {
@@ -123,7 +137,22 @@ export function createHooks(deps: HookDeps) {
123
137
  // --- Session error: classify and guide ---
124
138
  if (event.type === "session.error") {
125
139
  const props = event.properties as Record<string, unknown> | undefined;
126
- const errorMsg = extractErrorMessage(props?.error ?? props?.message ?? "Unknown error");
140
+ const errorObj = props?.error ?? props?.message ?? "Unknown error";
141
+ const errorMsg = extractErrorMessage(errorObj);
142
+
143
+ // Extract status code from error object for classification
144
+ const rawCode =
145
+ typeof errorObj === "object" && errorObj !== null
146
+ ? ((errorObj as Record<string, unknown>).data as Record<string, unknown>
147
+ )?.statusCode ??
148
+ (errorObj as Record<string, unknown>).statusCode
149
+ : undefined;
150
+ const statusCode =
151
+ typeof rawCode === "number"
152
+ ? rawCode
153
+ : typeof rawCode === "string"
154
+ ? Number(rawCode) || undefined
155
+ : undefined;
127
156
 
128
157
  // Log full error for debugging
129
158
  await log(`Session error: ${errorMsg}`, "warn");
@@ -136,13 +165,22 @@ export function createHooks(deps: HookDeps) {
136
165
  ) {
137
166
  guidance = "Context too large — use /compact or start a new session";
138
167
  } else if (
139
- /rate.?limit|429|too many requests/i.test(errorMsg)
168
+ /rate.?limit|too many requests/i.test(errorMsg) ||
169
+ statusCode === 429
140
170
  ) {
141
171
  guidance = "Rate limited — wait a moment and retry";
142
172
  } else if (
143
- /unauthorized|401|403|auth/i.test(errorMsg)
173
+ /unauthorized|auth/i.test(errorMsg) ||
174
+ statusCode === 401 ||
175
+ statusCode === 403
144
176
  ) {
145
177
  guidance = "Auth error — check API key or token";
178
+ } else if (
179
+ statusCode === 400 ||
180
+ /bad request|invalid.*request/i.test(errorMsg)
181
+ ) {
182
+ guidance =
183
+ "Bad request — try starting a new session or using /compact";
146
184
  } else if (
147
185
  /timeout|ETIMEDOUT|ECONNRESET|network|fetch failed/i.test(errorMsg)
148
186
  ) {
@@ -152,14 +190,20 @@ export function createHooks(deps: HookDeps) {
152
190
  ) {
153
191
  guidance = "API format error — try starting a new session";
154
192
  } else if (
155
- /500|502|503|504|internal server|service unavailable/i.test(errorMsg)
193
+ statusCode === 500 ||
194
+ statusCode === 502 ||
195
+ statusCode === 503 ||
196
+ statusCode === 504 ||
197
+ /internal server|service unavailable/i.test(errorMsg)
156
198
  ) {
157
199
  guidance = "Server error — retry in a few seconds";
158
200
  } else {
159
- guidance = "Unexpected error — save work with observation tool if needed";
201
+ guidance =
202
+ "Unexpected error — save work with observation tool if needed";
160
203
  }
161
204
 
162
- const short = errorMsg.length > 80 ? `${errorMsg.slice(0, 80)}…` : errorMsg;
205
+ const short =
206
+ errorMsg.length > 100 ? `${errorMsg.slice(0, 100)}…` : errorMsg;
163
207
  await showToast("Session Error", `${guidance} (${short})`, "warning");
164
208
  }
165
209
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencodekit",
3
- "version": "0.18.23",
3
+ "version": "0.18.24",
4
4
  "description": "CLI tool for bootstrapping and managing OpenCodeKit projects",
5
5
  "keywords": [
6
6
  "agents",