refactor: rename 'tier' to 'level' across the codebase
- Updated WorkerState type to use 'level' instead of 'tier'. - Modified functions related to worker state management, including parseWorkerState, emptyWorkerState, getSessionForLevel, activateWorker, and deactivateWorker to reflect the new terminology. - Adjusted health check logic to utilize 'level' instead of 'tier'. - Refactored tick and setup tools to accommodate the change from 'tier' to 'level', including model configuration and workspace scaffolding. - Updated tests to ensure consistency with the new 'level' terminology. - Revised documentation and comments to reflect the changes in terminology from 'tier' to 'level'.
This commit is contained in:
94
lib/tiers.ts
94
lib/tiers.ts
@@ -1,17 +1,16 @@
|
||||
/**
|
||||
* Developer tier definitions and model resolution.
|
||||
* Developer level definitions and model resolution.
|
||||
*
|
||||
* Tier names always include the role prefix: "dev.junior", "qa.reviewer", etc.
|
||||
* This makes tier names globally unique and self-documenting.
|
||||
* Level names are plain: "junior", "senior", "reviewer", etc.
|
||||
* Role context (dev/qa) is always provided by the caller or parent structure.
|
||||
*/
|
||||
|
||||
export const DEV_TIERS = ["dev.junior", "dev.medior", "dev.senior"] as const;
|
||||
export const QA_TIERS = ["qa.reviewer", "qa.tester"] as const;
|
||||
export const ALL_TIERS = [...DEV_TIERS, ...QA_TIERS] as const;
|
||||
export const DEV_LEVELS = ["junior", "medior", "senior"] as const;
|
||||
export const QA_LEVELS = ["reviewer", "tester"] as const;
|
||||
|
||||
export type DevTier = (typeof DEV_TIERS)[number];
|
||||
export type QaTier = (typeof QA_TIERS)[number];
|
||||
export type Tier = (typeof ALL_TIERS)[number];
|
||||
export type DevLevel = (typeof DEV_LEVELS)[number];
|
||||
export type QaLevel = (typeof QA_LEVELS)[number];
|
||||
export type Level = DevLevel | QaLevel;
|
||||
|
||||
/** Default models, nested by role. */
|
||||
export const DEFAULT_MODELS = {
|
||||
@@ -27,7 +26,7 @@ export const DEFAULT_MODELS = {
|
||||
};
|
||||
|
||||
/** Emoji used in announcements, nested by role. */
|
||||
export const TIER_EMOJI = {
|
||||
export const LEVEL_EMOJI = {
|
||||
dev: {
|
||||
junior: "⚡",
|
||||
medior: "🔧",
|
||||
@@ -39,77 +38,52 @@ export const TIER_EMOJI = {
|
||||
},
|
||||
};
|
||||
|
||||
/** Check if a string is a valid tier name. */
|
||||
export function isTier(value: string): value is Tier {
|
||||
return (ALL_TIERS as readonly string[]).includes(value);
|
||||
/** Check if a level belongs to the dev role. */
|
||||
export function isDevLevel(value: string): value is DevLevel {
|
||||
return (DEV_LEVELS as readonly string[]).includes(value);
|
||||
}
|
||||
|
||||
/** Check if a tier belongs to the dev role. */
|
||||
export function isDevTier(value: string): value is DevTier {
|
||||
return (DEV_TIERS as readonly string[]).includes(value);
|
||||
/** Check if a level belongs to the qa role. */
|
||||
export function isQaLevel(value: string): value is QaLevel {
|
||||
return (QA_LEVELS as readonly string[]).includes(value);
|
||||
}
|
||||
|
||||
/** Extract the role from a tier name (e.g. "dev.junior" → "dev"). */
|
||||
export function tierRole(tier: string): "dev" | "qa" | undefined {
|
||||
if (tier.startsWith("dev.")) return "dev";
|
||||
if (tier.startsWith("qa.")) return "qa";
|
||||
/** Determine the role a level belongs to. */
|
||||
export function levelRole(level: string): "dev" | "qa" | undefined {
|
||||
if (isDevLevel(level)) return "dev";
|
||||
if (isQaLevel(level)) return "qa";
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/** Extract the short name from a tier (e.g. "dev.junior" → "junior"). */
|
||||
export function tierName(tier: string): string {
|
||||
const dot = tier.indexOf(".");
|
||||
return dot >= 0 ? tier.slice(dot + 1) : tier;
|
||||
/** Get the default model for a role + level. */
|
||||
export function defaultModel(role: "dev" | "qa", level: string): string | undefined {
|
||||
return (DEFAULT_MODELS[role] as Record<string, string>)[level];
|
||||
}
|
||||
|
||||
/** Look up a value from a nested role structure using a full tier name. */
|
||||
function lookupNested<T>(map: Record<string, Record<string, T>>, tier: string): T | undefined {
|
||||
const role = tierRole(tier);
|
||||
if (!role) return undefined;
|
||||
return map[role]?.[tierName(tier)];
|
||||
}
|
||||
|
||||
/** Get the default model for a tier. */
|
||||
export function defaultModel(tier: string): string | undefined {
|
||||
return lookupNested(DEFAULT_MODELS, tier);
|
||||
}
|
||||
|
||||
/** Get the emoji for a tier. */
|
||||
export function tierEmoji(tier: string): string | undefined {
|
||||
return lookupNested(TIER_EMOJI, tier);
|
||||
}
|
||||
|
||||
/** Build a flat Record<Tier, string> of all default models. */
|
||||
export function allDefaultModels(): Record<Tier, string> {
|
||||
const result = {} as Record<Tier, string>;
|
||||
for (const tier of ALL_TIERS) {
|
||||
result[tier] = defaultModel(tier)!;
|
||||
}
|
||||
return result;
|
||||
/** Get the emoji for a role + level. */
|
||||
export function levelEmoji(role: "dev" | "qa", level: string): string | undefined {
|
||||
return (LEVEL_EMOJI[role] as Record<string, string>)[level];
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve a tier name to a full model ID.
|
||||
* Resolve a level to a full model ID.
|
||||
*
|
||||
* Resolution order:
|
||||
* 1. Parse "role.name" → look up config `models.<role>.<name>`
|
||||
* 2. DEFAULT_MODELS[role][name]
|
||||
* 1. Plugin config `models.<role>.<level>`
|
||||
* 2. DEFAULT_MODELS[role][level]
|
||||
* 3. Passthrough (treat as raw model ID)
|
||||
*/
|
||||
export function resolveTierToModel(
|
||||
tier: string,
|
||||
export function resolveModel(
|
||||
role: "dev" | "qa",
|
||||
level: string,
|
||||
pluginConfig?: Record<string, unknown>,
|
||||
): string {
|
||||
const models = (pluginConfig as { models?: Record<string, unknown> })?.models;
|
||||
|
||||
if (models && typeof models === "object") {
|
||||
const role = tierRole(tier);
|
||||
const name = tierName(tier);
|
||||
if (role) {
|
||||
const roleModels = models[role] as Record<string, string> | undefined;
|
||||
if (roleModels?.[name]) return roleModels[name];
|
||||
}
|
||||
const roleModels = models[role] as Record<string, string> | undefined;
|
||||
if (roleModels?.[level]) return roleModels[level];
|
||||
}
|
||||
|
||||
return defaultModel(tier) ?? tier;
|
||||
return defaultModel(role, level) ?? level;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user