moshi-opencode-hooks 1.0.17 → 1.0.18

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/index.ts +32 -6
  2. package/package.json +1 -1
package/index.ts CHANGED
@@ -112,6 +112,32 @@ function formatToolName(toolName: string): string {
112
112
  return toolName.charAt(0).toUpperCase() + toolName.slice(1)
113
113
  }
114
114
 
115
+ function formatToolDescription(tool: string, args: any): string {
116
+ switch (tool) {
117
+ case "bash":
118
+ return args?.description?.slice(0, 200) ?? ""
119
+ case "edit":
120
+ return args?.filePath ?? ""
121
+ case "write":
122
+ return args?.filePath ?? ""
123
+ case "read":
124
+ return args?.filePath ?? ""
125
+ case "glob":
126
+ return args?.pattern ?? ""
127
+ case "grep":
128
+ return args?.pattern ?? ""
129
+ case "task":
130
+ return args?.description?.slice(0, 100) ?? ""
131
+ case "apply_patch":
132
+ return args?.description?.slice(0, 200) ?? ""
133
+ case "webfetch":
134
+ case "websearch":
135
+ return args?.url ?? ""
136
+ default:
137
+ return ""
138
+ }
139
+ }
140
+
115
141
  function formatModelName(model: string | undefined): string | undefined {
116
142
  if (!model) return undefined
117
143
  return model.split("/").pop()
@@ -119,16 +145,16 @@ function formatModelName(model: string | undefined): string | undefined {
119
145
 
120
146
  async function getContextPercent(sessionId: string, client: Parameters<Plugin>[0]["client"]): Promise<number | undefined> {
121
147
  try {
122
- const sessionRes = await client.session.get({ path: { id: sessionId } })
123
- const sessionData = (sessionRes as any).data
148
+ const sessionRes = await (client.session.get as any)({ sessionID: sessionId })
149
+ const sessionData = sessionRes.data
124
150
  if (!sessionData) return undefined
125
151
 
126
152
  const model = sessionData.model as { limit?: { context?: number } } | undefined
127
153
  const contextLimit = model?.limit?.context
128
154
  if (!contextLimit) return undefined
129
155
 
130
- const messagesRes = await client.session.messages({ path: { id: sessionId }, query: { limit: 1 } })
131
- const messagesData = (messagesRes as any).data
156
+ const messagesRes = await (client.session.messages as any)({ sessionID: sessionId, limit: 1 })
157
+ const messagesData = messagesRes.data
132
158
  const messages = messagesData?.messages ?? messagesData
133
159
  const lastMsg = Array.isArray(messages) ? messages[messages.length - 1] : messages
134
160
  if (!lastMsg?.tokens?.input) return undefined
@@ -136,8 +162,8 @@ async function getContextPercent(sessionId: string, client: Parameters<Plugin>[0
136
162
  const totalInputTokens = lastMsg.tokens.input
137
163
  return Math.min(100, Math.round((totalInputTokens / contextLimit) * 100))
138
164
  } catch {
165
+ return undefined
139
166
  }
140
- return undefined
141
167
  }
142
168
 
143
169
  const pkg = await import("./package.json", { assert: { type: "json" } })
@@ -239,7 +265,7 @@ export const MoshiHooks: Plugin = async ({ client, directory }) => {
239
265
  sessionId: sessionID,
240
266
  category: "tool_running",
241
267
  title: `Running ${formatToolName(tool)}`,
242
- message: "",
268
+ message: formatToolDescription(tool, output.args),
243
269
  eventId: crypto.randomUUID(),
244
270
  projectName,
245
271
  modelName: formatModelName(await getOrLoadModel(client, sessionID)),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "moshi-opencode-hooks",
3
- "version": "1.0.17",
3
+ "version": "1.0.18",
4
4
  "description": "OpenCode plugin for Moshi live activity integration",
5
5
  "repository": {
6
6
  "type": "git",