recent_in_dir
Retrieve recent commands executed in a given directory. Helps identify what was done in a specific project folder.
Instructions
List recent commands run in a specific working directory (requires cwd capture, may be empty for legacy entries).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cwd | Yes | ||
| limit | No |
Implementation Reference
- src/search.ts:37-43 (handler)The actual implementation of recentInDir. Queries the 'commands' table filtering by cwd, ordered by timestamp descending.
export function recentInDir(db: Database.Database, cwd: string, limit = 20): SearchRow[] { const stmt = db.prepare(` SELECT id, cmd, ts, shell, cwd, exit_code, duration_ms FROM commands WHERE cwd = ? ORDER BY ts DESC NULLS LAST LIMIT ? `); return stmt.all(cwd, limit) as SearchRow[]; } - src/index.ts:55-66 (schema)Schema definition for the 'recent_in_dir' tool, specifying required 'cwd' string and optional 'limit' number.
{ name: "recent_in_dir", description: "List recent commands run in a specific working directory (requires cwd capture, may be empty for legacy entries).", inputSchema: { type: "object", properties: { cwd: { type: "string" }, limit: { type: "number", default: 20 }, }, required: ["cwd"], }, }, - src/index.ts:110-112 (registration)Registration and handler dispatch for 'recent_in_dir' — parses args with Zod and calls recentInDir, formatting the output.
if (name === "recent_in_dir") { const { cwd, limit } = z.object({ cwd: z.string(), limit: z.number().optional() }).parse(args); return { content: [{ type: "text", text: fmt(recentInDir(db, cwd, limit ?? 20)) }] }; - src/index.ts:22-30 (helper)The fmt helper function that formats SearchRow results into human-readable text output.
function fmt(rows: SearchRow[]): string { if (!rows.length) return "(no results)"; return rows.map((r) => { const when = r.ts ? new Date(r.ts).toISOString() : "?"; const exit = r.exit_code == null ? "" : ` exit=${r.exit_code}`; const cwd = r.cwd ? ` cwd=${r.cwd}` : ""; return `[${r.shell} ${when}${exit}${cwd}] ${r.cmd}`; }).join("\n"); }