🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
♻️ refactor(task): remove custom identifier prefixes (#20687)
Bryane2eb7616c5d4
diff --git a/apps/cli/src/commands/task/index.ts b/apps/cli/src/commands/task/index.tsindex 595f1fb6ea9..2fd49023285 100644--- a/apps/cli/src/commands/task/index.ts+++ b/apps/cli/src/commands/task/index.ts@@ -527,7 +527,6 @@ export function registerTaskCommand(program: Command) {.option('--user <idOrEmail>', 'Assign to a workspace member (user id, email or username)').option('--parent <id>', 'Parent task ID').option('--priority <n>', 'Priority (0=none, 1=urgent, 2=high, 3=normal, 4=low)', '0')- .option('--prefix <prefix>', 'Identifier prefix', 'T').option('--json [fields]', 'Output JSON').action(async (options: {@@ -536,7 +535,6 @@ export function registerTaskCommand(program: Command) {json?: string | boolean;name?: string;parent?: string;- prefix?: string;priority?: string;user?: string;}) => {@@ -545,7 +543,7 @@ export function registerTaskCommand(program: Command) {const assigneeUserId = await resolveUserOption(client, options.user);if (assigneeUserId === false) return;- const input: Record<string, any> = {+ const input: Parameters<typeof client.task.create.mutate>[0] = {instruction: options.instruction,};if (options.name) input.name = options.name;@@ -553,9 +551,8 @@ export function registerTaskCommand(program: Command) {if (assigneeUserId) input.assigneeUserId = assigneeUserId;if (options.parent) input.parentTaskId = options.parent;if (options.priority) input.priority = Number.parseInt(options.priority, 10);- if (options.prefix) input.identifierPrefix = options.prefix;- const result = await client.task.create.mutate(input as any);+ const result = await client.task.create.mutate(input);const url = buildUrl(taskPath(result.data.identifier, result.data.name));if (options.json !== undefined) {diff --git a/apps/server/src/routers/lambda/__tests__/integration/task.integration.test.ts b/apps/server/src/routers/lambda/__tests__/integration/task.integration.test.tsindex be8c9ae7570..6641612e56d 100644--- a/apps/server/src/routers/lambda/__tests__/integration/task.integration.test.ts+++ b/apps/server/src/routers/lambda/__tests__/integration/task.integration.test.ts@@ -4,6 +4,7 @@ import { getTestDB } from '@lobechat/database/test-utils';import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';import { AcceptanceModel } from '@/database/models/acceptance';+import { ProjectModel } from '@/database/models/project';import { TaskModel } from '@/database/models/task';import { TaskTopicModel } from '@/database/models/taskTopic';import { TaskService } from '@/server/services/task';@@ -118,6 +119,46 @@ describe('Task Router Integration', () => {});describe('create + find + detail', () => {+ it.each(['personal', 'workspace'])(+ 'ignores legacy prefixes and inherits project numbering in %s',+ async (scope) => {+ let workspaceId: string | undefined;+ if (scope === 'workspace') {+ workspaceId = 'task-prefix-integration-workspace';+ const { workspaces, workspaceMembers } = await import('@/database/schemas');+ await serverDB.insert(workspaces).values({+ id: workspaceId,+ name: 'Task prefixes',+ primaryOwnerId: userId,+ slug: workspaceId,+ });+ await serverDB.insert(workspaceMembers).values({ role: 'owner', userId, workspaceId });+ }+ const scopedCaller = taskRouter.createCaller({ ...createTestContext(userId), workspaceId });+ const model = new TaskModel(serverDB, userId, workspaceId);+ const project = await new ProjectModel(serverDB, userId, workspaceId).create({+ identifier: 'PROJ',+ name: 'Prefix project',+ });+ for (const identifierPrefix of ['T', 'CUSTOM', '', null, 42]) {+ const legacyInput = { identifierPrefix, instruction: 'Standalone' };+ const standalone = await scopedCaller.create(legacyInput);+ expect(standalone.success).toBe(true);+ expect(standalone.data.identifier).toBe(`T-${standalone.data.seq}`);+ const projectInput = { ...legacyInput, projectId: project.id };+ const parent = await scopedCaller.create(projectInput);+ expect(parent.data.identifier).toBe(`PROJ-${parent.data.seq}`);+ for (const parentTaskId of [parent.data.id, parent.data.identifier]) {+ const childInput = { ...legacyInput, parentTaskId };+ const child = await scopedCaller.create(childInput);+ expect(child.data.projectId).toBe(project.id);+ expect(child.data.identifier).toBe(`PROJ-${child.data.seq}`);+ expect((await model.findById(child.data.id))?.identifier).toBe(child.data.identifier);+ }+ }+ },+ );+it('should create a task and retrieve it', async () => {const result = await caller.create({instruction: 'Write a book',diff --git a/apps/server/src/routers/lambda/task.ts b/apps/server/src/routers/lambda/task.tsindex 43344d1d07a..09d65315a01 100644--- a/apps/server/src/routers/lambda/task.ts+++ b/apps/server/src/routers/lambda/task.ts@@ -85,6 +85,9 @@ const taskVerifyConfigPatchSchema = z.object({});// Priority: 0=None, 1=Urgent, 2=High, 3=Normal, 4=Low+// Unknown fields are stripped, including the removed identifierPrefix. Released+// CLI clients send 'T' by default; ignore it so project subtasks use their project+// identifier without breaking ordinary creates from those clients.const createSchema = z.object({assigneeAgentId: z.string().optional(),assigneeUserId: z.string().optional(),@@ -96,7 +99,6 @@ const createSchema = z.object({createdByAgentId: z.string().optional(),description: z.string().optional(),editorData: z.unknown().optional(),- identifierPrefix: z.string().optional(),instruction: z.string().min(1),name: z.string().optional(),parentTaskId: z.string().optional(),diff --git a/apps/server/src/services/task/index.ts b/apps/server/src/services/task/index.tsindex e55c1151129..210ca6b0ca1 100644--- a/apps/server/src/services/task/index.ts+++ b/apps/server/src/services/task/index.ts@@ -83,7 +83,6 @@ export interface CreateTaskInput {description?: string;editorData?: unknown;fileIds?: string[];- identifierPrefix?: string;instruction: string;name?: string;parentTaskId?: string;@@ -174,7 +173,6 @@ export class TaskService {if (createData.projectId) {const project = await this.projectModel.findManageableById(createData.projectId);if (!project) throw new TRPCError({ code: 'NOT_FOUND', message: 'Project not found' });- createData.identifierPrefix ??= project.identifier;}// Pull the model/provider snapshot and the agent's visibility in a singlediff --git a/packages/database/src/models/__tests__/task.test.ts b/packages/database/src/models/__tests__/task.test.tsindex fb7b69bdd30..4e41b36c26f 100644--- a/packages/database/src/models/__tests__/task.test.ts+++ b/packages/database/src/models/__tests__/task.test.ts@@ -115,16 +115,6 @@ describe('TaskModel', () => {expect(task3.identifier).toBe('T-3');});- it('should support custom identifier prefix', async () => {- const model = new TaskModel(serverDB, userId);- const result = await model.create({- identifierPrefix: 'PROJ',- instruction: 'Build WAKE system',- });-- expect(result.identifier).toBe('PROJ-1');- });-it('should create task with all optional fields', async () => {const model = new TaskModel(serverDB, userId);await createAgent('agent-1');diff --git a/packages/database/src/models/task.ts b/packages/database/src/models/task.tsindex 812521c054f..dae32443ca6 100644--- a/packages/database/src/models/task.ts+++ b/packages/database/src/models/task.ts@@ -63,6 +63,9 @@ import { acceptances } from '../schemas/verify';import { works } from '../schemas/work';import type { LobeChatDatabase } from '../type';import { buildWorkspaceWhere } from '../utils/workspace';+import { ProjectModel } from './project';++const DEFAULT_TASK_IDENTIFIER_PREFIX = 'T';/** Columns whose change is worth a line in the task activity feed. */const TRACKED_TASK_COLUMNS = [@@ -436,12 +439,34 @@ export class TaskModel {// ========== CRUD ==========async create(- data: Omit<NewTask, 'id' | 'identifier' | 'seq' | 'createdByUserId'> & {- identifierPrefix?: string;- },+ data: Omit<NewTask, 'id' | 'identifier' | 'seq' | 'createdByUserId'>,options: { maxRetries?: number } = {},): Promise<TaskItem> {- const { identifierPrefix = 'T', ...rest } = normalizeTaskRefs(data);+ const createData = normalizeTaskRefs(data);++ // Keep the invariant at the write boundary, including direct model callers.+ // Parent references here are canonical database ids; the service resolves+ // display identifiers before calling the model.+ if (createData.parentTaskId) {+ const parent = await this.findById(createData.parentTaskId);+ if (!parent) throw new Error('Task not found');+ if (createData.projectId && createData.projectId !== parent.projectId) {+ throw new Error('Subtask must belong to the same project as its parent');+ }+ createData.projectId ??= parent.projectId;+ }++ // A prefix is derived from placement, never accepted as a creation field.+ let identifierPrefix = DEFAULT_TASK_IDENTIFIER_PREFIX;+ if (createData.projectId) {+ const project = await new ProjectModel(+ this.db,+ this.userId,+ this.workspaceId,+ ).findManageableById(createData.projectId);+ if (!project) throw new Error('Project not found');+ identifierPrefix = project.identifier;+ }// Retry loop to handle concurrent creates (parallel tool calls)const maxRetries = options.maxRetries ?? 5;@@ -468,7 +493,7 @@ export class TaskModel {const [task] = await this.db.insert(tasks).values({- ...rest,+ ...createData,createdByUserId: this.userId,identifier,seq: nextSeq,@@ -2596,7 +2621,7 @@ export class TaskModel {const newParentId =currentId === taskId ? null : (idMap.get(original.parentTaskId!) ?? null);- const identifier = `T-${seq}`;+ const identifier = `${DEFAULT_TASK_IDENTIFIER_PREFIX}-${seq}`;const inserted = (await (trx as LobeChatDatabase).insert(tasks).values({diff --git a/src/services/task.ts b/src/services/task.tsindex 2b8499c8a2d..0401df935b5 100644--- a/src/services/task.ts+++ b/src/services/task.ts@@ -104,8 +104,6 @@ class TaskService {createdByAgentId?: string;description?: string;editorData?: unknown;- /** Bind a goal entity (`goals` row) to the created task. */- identifierPrefix?: string;instruction: string;name?: string;parentTaskId?: string;