Bug Description
When running opencode with the notifier plugin, opencode fails to launch with the following error:
{
"name": "UnknownError",
"data": {
"message": "TypeError: undefined is not a function (near '...sessionTitle.match(/\\s*\\(@([^\\s)]+)\\s+subagent\\)\\s*$/)...')\n at extractAgentNameFromSessionTitle (/home/abreu/.cache/opencode/node_modules/@mohak34/opencode-notifier/dist/index.js:849:30)"
}
}
Root Cause
The extractAgentNameFromSessionTitle function in dist/index.js:845-851 has a type safety bug:
function extractAgentNameFromSessionTitle(sessionTitle) {
if (!sessionTitle) {
return "";
}
const match = sessionTitle.match(/\s*\(@([^\s)]+)\s+subagent\)\s*$/);
return match ? match[1] : "";
}
Problem: The guard if (!sessionTitle) only catches falsy values (null, undefined, "", 0, false). If sessionTitle is a truthy non-string value (e.g., anumber, object, or array), it passes the guard, but .match() doesn't exist on non-string types, causing undefined is not a function.
Data flow:
getSessionInfo() calls client.session.get() API
- Returns
{ title: response.data?.title ?? null } (line973)
- The API response
title might not be a string
- This non-string value gets passed to
extractAgentNameFromSessionTitle() (line1027)
Suggested Fix
Add a type check before calling .match():
function extractAgentNameFromSessionTitle(sessionTitle) {
if (!sessionTitle || typeof sessionTitle !== 'string') {
return "";
}
const match = sessionTitle.match(/\s*\(@([^\s)]+)\s+subagent\)\s*$/);
return match ? match[1] : "";
}
Or convert to string safely:
function extractAgentNameFromSessionTitle(sessionTitle) {
const title = String(sessionTitle ?? "");
const match = title.match(/\s*\(@([^\s)]+)\s+subagent\)\s*$/);
return match ? match[1] : "";
}
##Environment
- Plugin version: (installed via npm from
@mohak34/opencode-notifier)
- OpenCode version: Latest
- OS: NixOS Linux
Workaround
Currently removing the plugin from opencode configuration to avoid the crash.
Bug Description
When running opencode with the notifier plugin, opencode fails to launch with the following error:
{ "name": "UnknownError", "data": { "message": "TypeError: undefined is not a function (near '...sessionTitle.match(/\\s*\\(@([^\\s)]+)\\s+subagent\\)\\s*$/)...')\n at extractAgentNameFromSessionTitle (/home/abreu/.cache/opencode/node_modules/@mohak34/opencode-notifier/dist/index.js:849:30)" } }Root Cause
The
extractAgentNameFromSessionTitlefunction indist/index.js:845-851has a type safety bug:Problem: The guard
if (!sessionTitle)only catches falsy values (null,undefined,"",0,false). IfsessionTitleis a truthy non-string value (e.g., anumber, object, or array), it passes the guard, but.match()doesn't exist on non-string types, causingundefined is not a function.Data flow:
getSessionInfo()callsclient.session.get()API{ title: response.data?.title ?? null }(line973)titlemight not be a stringextractAgentNameFromSessionTitle()(line1027)Suggested Fix
Add a type check before calling
.match():Or convert to string safely:
##Environment
@mohak34/opencode-notifier)Workaround
Currently removing the plugin from opencode configuration to avoid the crash.