MCPcopy Create free account
hub / github.com/backnotprop/plannotator / handleAnnotateLastCommand

Function handleAnnotateLastCommand

apps/opencode-plugin/commands.ts:373–453  ·  view source on GitHub ↗
(
  event: any,
  deps: CommandDeps
)

Source from the content-addressed store, hash-verified

371 * so the caller can set it as output.parts for the agent to see.
372 */
373export async function handleAnnotateLastCommand(
374 event: any,
375 deps: CommandDeps
376): Promise<string | null> {
377 const { client, htmlContent, getSharingEnabled, getShareBaseUrl, getPasteApiUrl } = deps;
378 const startServer = deps.startAnnotateServer ?? startAnnotateServer;
379
380 // @ts-ignore - Event properties contain arguments
381 const rawArgs = event.properties?.arguments || event.arguments || "";
382 // Support --gate on /plannotator-last (Stop-hook review-gate pattern).
383 const { gate } = parseAnnotateArgs(rawArgs);
384
385 // @ts-ignore - Event properties contain sessionID
386 const sessionId = event.properties?.sessionID;
387 if (!sessionId) {
388 client.app.log({ level: "error", message: "No active session." });
389 return null;
390 }
391
392 // Fetch messages from session
393 const messagesResponse = await client.session.messages({
394 path: { id: sessionId },
395 });
396 const messages = messagesResponse.data;
397
398 const RECENT_LIMIT = 25;
399 const recentMessages: { messageId: string; text: string; timestamp?: string }[] = [];
400 if (messages) {
401 for (let i = messages.length - 1; i >= 0 && recentMessages.length < RECENT_LIMIT; i--) {
402 const msg = messages[i];
403 if (msg.info.role !== "assistant") continue;
404 const textParts = msg.parts
405 .filter((p: any) => p.type === "text" && p.text?.trim())
406 .map((p: any) => p.text);
407 if (textParts.length === 0) continue;
408 recentMessages.push({
409 messageId: msg.info.id ?? `opencode-${i}`,
410 text: textParts.join("\n"),
411 timestamp: msg.info.time?.created ? new Date(msg.info.time.created).toISOString() : undefined,
412 });
413 }
414 }
415
416 const lastText = recentMessages[0]?.text ?? null;
417 if (!lastText) {
418 client.app.log({ level: "error", message: "No assistant message found in session." });
419 return null;
420 }
421
422 client.app.log({ level: "info", message: "Opening annotation UI for last message..." });
423
424 const pickerMessages = recentMessages.length > 1 ? recentMessages : undefined;
425
426 const server = await startServer({
427 markdown: lastText,
428 filePath: "last-message",
429 origin: "opencode",
430 mode: "annotate-last",

Callers 2

commands.test.tsFile · 0.90
handleEmbeddedCommandFunction · 0.85

Calls 6

parseAnnotateArgsFunction · 0.90
getSharingEnabledFunction · 0.85
getShareBaseUrlFunction · 0.85
getPasteApiUrlFunction · 0.85
stopMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected