// tools/tool-registry-helpers.ts — Shared helpers to reduce boilerplate in register-*.ts files
// SPEC-465: Extracts the resolveProjectId + missingProjectIdError pattern common to ~26 files.
import { z } from 'zod';
import { resolveProjectId, missingProjectIdError } from './resolve-project-id.js';
// ── Shared schema fragments ──────────────────────────────────────────────────
/** Standard dual projectId/projectPath optional Zod fields. Spread into inputSchema. */
export const projectIdSchema = {
    projectId: z.string().max(500).optional().describe('Project ID hash. Prefer projectPath.'),
    projectPath: z
        .string()
        .max(4096)
        .optional()
        .describe('Absolute path to project root. Derives projectId automatically.'),
};
/**
 * Wraps a handler that requires a resolved projectId.
 * Resolves projectId from projectId or projectPath; returns missingProjectIdError if neither.
 *
 * Usage (replaces the 5-line resolveProjectId block in each safeTracked/safeLicensed callback):
 * ```ts
 * // Before:
 * safeLicensed('tool', async (args) => {
 *   const pid = resolveProjectId(args as { projectId?: string; projectPath?: string });
 *   if (!pid) return missingProjectIdError;
 *   return handleFoo({ ...args, projectId: pid } as FooInput);
 * })
 *
 * // After:
 * safeLicensed('tool', withProject((args) => handleFoo(args as never)))
 * ```
 */
export function withProject(handler) {
    return async (args) => {
        const projectId = resolveProjectId(args);
        if (!projectId) {
            return missingProjectIdError;
        }
        return handler({ ...args, projectId });
    };
}
//# sourceMappingURL=tool-registry-helpers.js.map