oh-my-opencode 0.1.14 → 0.1.15

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 (2) hide show
  1. package/dist/index.js +85 -7
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -893,14 +893,71 @@ async function recoverThinkingDisabledViolation(client, sessionID, failedAssista
893
893
  } catch {}
894
894
  return false;
895
895
  }
896
- async function recoverEmptyContentMessage(client, sessionID, failedAssistantMsg, directory) {
897
- const messageID = failedAssistantMsg.info?.id;
898
- const parentMsgID = failedAssistantMsg.info?.parentID;
899
- if (!messageID) {
896
+ var THINKING_TYPES = new Set(["thinking", "redacted_thinking", "reasoning"]);
897
+ function hasNonEmptyOutput(msg) {
898
+ const parts = msg.parts;
899
+ if (!parts || parts.length === 0)
900
+ return false;
901
+ return parts.some((p) => {
902
+ if (THINKING_TYPES.has(p.type))
903
+ return false;
904
+ if (p.type === "step-start" || p.type === "step-finish")
905
+ return false;
906
+ if (p.type === "text" && p.text && p.text.trim())
907
+ return true;
908
+ if (p.type === "tool_use" && p.id)
909
+ return true;
910
+ if (p.type === "tool_result")
911
+ return true;
900
912
  return false;
913
+ });
914
+ }
915
+ function findEmptyContentMessage(msgs) {
916
+ for (let i = 0;i < msgs.length; i++) {
917
+ const msg = msgs[i];
918
+ const isLastMessage = i === msgs.length - 1;
919
+ const isAssistant = msg.info?.role === "assistant";
920
+ if (isLastMessage && isAssistant)
921
+ continue;
922
+ if (!hasNonEmptyOutput(msg)) {
923
+ return msg;
924
+ }
901
925
  }
902
- const revertTargetID = parentMsgID || messageID;
926
+ return null;
927
+ }
928
+ async function recoverEmptyContentMessage(client, sessionID, failedAssistantMsg, directory) {
903
929
  try {
930
+ const messagesResp = await client.session.messages({
931
+ path: { id: sessionID },
932
+ query: { directory }
933
+ });
934
+ const msgs = messagesResp.data;
935
+ if (!msgs || msgs.length === 0)
936
+ return false;
937
+ const emptyMsg = findEmptyContentMessage(msgs) || failedAssistantMsg;
938
+ const messageID = emptyMsg.info?.id;
939
+ if (!messageID)
940
+ return false;
941
+ const existingParts = emptyMsg.parts || [];
942
+ const hasOnlyThinkingOrMeta = existingParts.length > 0 && existingParts.every((p) => THINKING_TYPES.has(p.type) || p.type === "step-start" || p.type === "step-finish");
943
+ if (hasOnlyThinkingOrMeta) {
944
+ const strippedParts = [{ type: "text", text: "(interrupted)" }];
945
+ try {
946
+ await client.message?.update?.({
947
+ path: { id: messageID },
948
+ body: { parts: strippedParts }
949
+ });
950
+ return true;
951
+ } catch {}
952
+ try {
953
+ await client.session.patch?.({
954
+ path: { id: sessionID },
955
+ body: { messageID, parts: strippedParts }
956
+ });
957
+ return true;
958
+ } catch {}
959
+ }
960
+ const revertTargetID = emptyMsg.info?.parentID || messageID;
904
961
  await client.session.revert({
905
962
  path: { id: sessionID },
906
963
  body: { messageID: revertTargetID },
@@ -15494,10 +15551,30 @@ function showOutputToUser(context, output) {
15494
15551
  const ctx = context;
15495
15552
  ctx.metadata?.({ metadata: { output } });
15496
15553
  }
15554
+ var JS_TS_LANGUAGES = ["javascript", "typescript", "tsx"];
15555
+ function validatePatternForCli(pattern, lang) {
15556
+ if (!JS_TS_LANGUAGES.includes(lang)) {
15557
+ return;
15558
+ }
15559
+ const src = pattern.trim();
15560
+ const incompleteFunctionDecl = /^(export\s+)?(default\s+)?(async\s+)?function\s+\$[A-Z_][A-Z0-9_]*\s*$/i.test(src);
15561
+ if (incompleteFunctionDecl) {
15562
+ throw new Error(`Incomplete AST pattern for ${lang}: "${pattern}"
15563
+
15564
+ ` + `ast-grep requires complete AST nodes. Function declarations must include parameters and body.
15565
+
15566
+ ` + `Examples of correct patterns:
15567
+ ` + ` - "export async function $NAME($$$) { $$$ }" (matches export async functions)
15568
+ ` + ` - "function $NAME($$$) { $$$ }" (matches all function declarations)
15569
+ ` + ` - "async function $NAME($$$) { $$$ }" (matches async functions)
15570
+
15571
+ ` + `Your pattern "${pattern}" is missing the parameter list and body.`);
15572
+ }
15573
+ }
15497
15574
  var ast_grep_search = tool({
15498
- description: "Search code patterns across filesystem using AST-aware matching. Supports 25 languages. " + "Use meta-variables: $VAR (single node), $$$ (multiple nodes). " + "Examples: 'console.log($MSG)', 'def $FUNC($$$):', 'async function $NAME($$$)'",
15575
+ description: "Search code patterns across filesystem using AST-aware matching. Supports 25 languages. " + "Use meta-variables: $VAR (single node), $$$ (multiple nodes). " + "IMPORTANT: Patterns must be complete AST nodes (valid code). " + "For functions, include params and body: 'export async function $NAME($$$) { $$$ }' not 'export async function $NAME'. " + "Examples: 'console.log($MSG)', 'def $FUNC($$$):', 'async function $NAME($$$)'",
15499
15576
  args: {
15500
- pattern: tool.schema.string().describe("AST pattern with meta-variables ($VAR, $$$)"),
15577
+ pattern: tool.schema.string().describe("AST pattern with meta-variables ($VAR, $$$). Must be complete AST node."),
15501
15578
  lang: tool.schema.enum(CLI_LANGUAGES).describe("Target language"),
15502
15579
  paths: tool.schema.array(tool.schema.string()).optional().describe("Paths to search (default: ['.'])"),
15503
15580
  globs: tool.schema.array(tool.schema.string()).optional().describe("Include/exclude globs (prefix ! to exclude)"),
@@ -15505,6 +15582,7 @@ var ast_grep_search = tool({
15505
15582
  },
15506
15583
  execute: async (args, context) => {
15507
15584
  try {
15585
+ validatePatternForCli(args.pattern, args.lang);
15508
15586
  const matches = await runSg({
15509
15587
  pattern: args.pattern,
15510
15588
  lang: args.lang,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oh-my-opencode",
3
- "version": "0.1.14",
3
+ "version": "0.1.15",
4
4
  "description": "OpenCode plugin - custom agents (oracle, librarian) and enhanced features",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",