m9k_similar_work
Find similar past work to inform your current complex task. Use this tool at project start to discover previous approaches with rich metadata like multiple tools and files.
Instructions
Find past work similar to what you're about to do. Use at the start of a complex task to see previous approaches. Unlike m9k_search, this prioritizes chunks with rich metadata (multiple tools used, multiple files touched).
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| description | Yes | Description of the current task | |
| limit | No | ||
| source | No | Filter by source type. Default: all sources. |
Implementation Reference
- src/tools/specialized.ts:204-250 (handler)The handler logic for 'm9k_similar_work' tool, which performs a search and applies a bonus score based on metadata (tool calls and touched files).
async ({ description, limit }) => { // Use the same search pipeline as m9k_search const results = await search( ctx.db, { query: description, limit: limit * 3 }, ctx.searchContext, ); // Apply metadata bonus scoring const enriched = results.map((r) => { const chunk = ctx.db .prepare('SELECT metadata_json FROM conv_chunks WHERE id = ?') .get(r.chunkId) as { metadata_json: string } | undefined; let metadataBonus = 0; if (chunk?.metadata_json) { try { const meta = JSON.parse(chunk.metadata_json) as { toolCalls?: string[]; filePaths?: string[]; }; if (meta.toolCalls && meta.toolCalls.length >= 3) metadataBonus += 0.2; if (meta.filePaths && meta.filePaths.length >= 2) metadataBonus += 0.1; } catch { // ignore parse error } } return { chunkId: r.chunkId, snippet: r.snippet, score: r.score + metadataBonus, metadataBonus, project: r.project, timestamp: r.timestamp, matchType: r.matchType, sessionId: r.sessionId, }; }); // Re-sort by adjusted score, take top limit enriched.sort((a, b) => b.score - a.score); return { content: [{ type: 'text' as const, text: JSON.stringify(enriched.slice(0, limit)) }], }; }, ); - src/tools/specialized.ts:189-196 (schema)Schema definition for the inputs to the 'm9k_similar_work' tool.
inputSchema: { description: z.string().describe('Description of the current task'), limit: z.number().int().min(1).max(20).default(5), source: z .enum(['conversations', 'git', 'files']) .optional() .describe('Filter by source type. Default: all sources.'), }, - src/tools/specialized.ts:184-250 (registration)Registration block for the 'm9k_similar_work' tool within the server.
server.registerTool( 'm9k_similar_work', { description: "Find past work similar to what you're about to do. Use at the start of a complex task to see previous approaches. Unlike m9k_search, this prioritizes chunks with rich metadata (multiple tools used, multiple files touched).", inputSchema: { description: z.string().describe('Description of the current task'), limit: z.number().int().min(1).max(20).default(5), source: z .enum(['conversations', 'git', 'files']) .optional() .describe('Filter by source type. Default: all sources.'), }, annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false, }, }, async ({ description, limit }) => { // Use the same search pipeline as m9k_search const results = await search( ctx.db, { query: description, limit: limit * 3 }, ctx.searchContext, ); // Apply metadata bonus scoring const enriched = results.map((r) => { const chunk = ctx.db .prepare('SELECT metadata_json FROM conv_chunks WHERE id = ?') .get(r.chunkId) as { metadata_json: string } | undefined; let metadataBonus = 0; if (chunk?.metadata_json) { try { const meta = JSON.parse(chunk.metadata_json) as { toolCalls?: string[]; filePaths?: string[]; }; if (meta.toolCalls && meta.toolCalls.length >= 3) metadataBonus += 0.2; if (meta.filePaths && meta.filePaths.length >= 2) metadataBonus += 0.1; } catch { // ignore parse error } } return { chunkId: r.chunkId, snippet: r.snippet, score: r.score + metadataBonus, metadataBonus, project: r.project, timestamp: r.timestamp, matchType: r.matchType, sessionId: r.sessionId, }; }); // Re-sort by adjusted score, take top limit enriched.sort((a, b) => b.score - a.score); return { content: [{ type: 'text' as const, text: JSON.stringify(enriched.slice(0, limit)) }], }; }, );