/** * Template Service * * Loads, lists, and applies team templates from config/templates/. * Supports both the new TeamTemplate format (with verificationPipeline) * and legacy flat JSON format (backward compatible). * * @module services/template/template */ import type { TeamTemplate, TemplateOnboarding } from '../../types/team-template.types.js'; import type { Team } from '../../types/index.js'; import { type CloudTier } from '../../constants.js'; /** Result of creating a team from a template */ export interface CreateFromTemplateResult { /** The created team */ team: Team; /** Template ID used */ templateId: string; /** Number of members created */ memberCount: number; } /** Template source — local disk */ export type TemplateSource = 'local'; /** Minimal template summary for listing */ export interface TemplateSummary { id: string; name: string; description: string; category: string; hierarchical: boolean; roleCount: number; version: string; tags?: string[]; icon?: string; /** Where this template was loaded from */ source: TemplateSource; /** Minimum tier required to use this template */ requiredTier?: CloudTier; /** First-run starter metadata (only on onboarding starters) */ onboarding?: TemplateOnboarding; } /** * TemplateService manages team templates. * Loads templates from config/templates/ directory, provides * listing/querying, and creates teams from templates. * * Singleton pattern matching other Crewly services. */ export declare class TemplateService { private static instance; /** Loaded templates indexed by ID */ private templates; /** Templates directory path */ private templatesDir; /** * Templates loaded from `CREWLY_TEMPLATE_DIRS` (e.g. Crewly Pro's): id → * the directory they came from, where their norms live. */ private extraRoots; /** Whether templates have been loaded */ private loaded; private constructor(); /** * Get the singleton instance. * * @param templatesDir - Optional override for templates directory * @returns The singleton instance */ static getInstance(templatesDir?: string): TemplateService; /** * Clear the singleton instance (for testing). */ static clearInstance(): void; /** * Load all templates from the templates directory. * Scans for template.json files in subdirectories and * legacy flat JSON files at the root level. * * @returns Number of templates loaded */ loadTemplates(): number; /** * Load every template in one directory into the registry. * * @param dir - Directory holding `/template.json` subdirs and/or flat JSON files */ private loadTemplatesFrom; /** * Templates that came from `CREWLY_TEMPLATE_DIRS` rather than the OSS * templates dir — on a Crewly Pro install, the paid templates. Onboarding * offers these alongside its built-in recommendations. * * @returns The extra templates, in load order */ listExtraTemplates(): TeamTemplate[]; /** * The directory a template's own files (template.json, norms/) are in. * * @param templateId - Template ID * @returns `/` */ private templateHome; /** * List local templates as summaries. * * @returns Array of local template summaries */ listTemplates(): TemplateSummary[]; /** * The first-run starter templates (those with `onboarding` metadata), * ordered by `onboarding.order`. * * @returns Starter templates, first-shown first * * @example * ```ts * const [recommended] = TemplateService.getInstance().listOnboardingStarters(); * ``` */ listOnboardingStarters(): TeamTemplate[]; /** * Get a specific template by ID. * * @param id - Template ID * @returns The template, or null if not found */ getTemplate(id: string): TeamTemplate | null; /** * Create a team from a template. * Generates TeamMember objects with IDs, session names, * and hierarchy fields based on the template's role definitions. * * @param templateId - ID of the template to use * @param teamName - Name for the new team * @param nameOverrides - Optional map of role to custom name * @returns The created team result, or null if template not found */ createTeamFromTemplate(templateId: string, teamName: string, nameOverrides?: Record, userTier?: CloudTier): CreateFromTemplateResult | null; /** * Copy norms files from a template to the team's norms directory. * * Copies config/templates/{templateId}/norms/*.md to ~/.crewly/teams/{teamId}/norms/. * Also copies the norms config from template.json into the team's config.json. * * @param templateId - Source template ID * @param teamId - Target team ID */ private copyTeamNorms; /** * Load the raw template.json for a template (including norms config). * * @param templateId - Template ID * @returns Parsed template.json or null */ private loadTemplateJson; /** * Get the number of loaded templates. * * @returns Template count */ getTemplateCount(): number; /** * Load a new-format template.json file. * * @param filePath - Absolute path to the template.json file * @param dirName - Directory name containing the template */ private loadTemplateFile; /** * Load a legacy flat JSON template (e.g., web-dev-team.json). * Converts to TeamTemplate format with sensible defaults. * * @param filePath - Absolute path to the JSON file * @param fileName - File name of the template */ private loadLegacyTemplate; } //# sourceMappingURL=template.service.d.ts.map