feat: organize project conversations and add coding teacher side chat
This commit is contained in:
@@ -225,6 +225,8 @@ export function normalizeCodingProjectConfigV2(value: unknown): CodingProjectCon
|
||||
projectType,
|
||||
...(record.projectId !== undefined ? { projectId: record.projectId } : {}),
|
||||
initialized: record.initialized === true,
|
||||
...(typeof record.defaultAgentId === 'string' && AGENT_ID_PATTERN.test(record.defaultAgentId)
|
||||
? { defaultAgentId: record.defaultAgentId } : {}),
|
||||
agents,
|
||||
knowledgeDirectory: 'knowledge',
|
||||
createdAt,
|
||||
@@ -232,6 +234,27 @@ export function normalizeCodingProjectConfigV2(value: unknown): CodingProjectCon
|
||||
};
|
||||
}
|
||||
|
||||
export function ensureDefaultCodingAgent(config: CodingProjectConfigV2, now = new Date().toISOString()): CodingProjectConfigV2 {
|
||||
const usable = config.agents.filter((agent) => agent.enabled && !agent.archivedAt);
|
||||
const current = usable.find((agent) => agent.id === config.defaultAgentId);
|
||||
if (current && config.initialized) return config;
|
||||
const existing = current ?? usable.find((agent) => agent.pinned) ?? usable[0];
|
||||
if (existing) return { ...config, defaultAgentId: existing.id, initialized: true, updatedAt: now };
|
||||
let id = 'coding-default';
|
||||
let suffix = 1;
|
||||
while (config.agents.some((agent) => agent.id === id)) id = `coding-default-${suffix++}`;
|
||||
let name = '编程助手';
|
||||
suffix = 1;
|
||||
while (config.agents.some((agent) => agent.name === name)) name = `编程助手 ${suffix++}`;
|
||||
const agent: CodingProjectAgentV2 = {
|
||||
id, name, avatarId: 'avatar-01', roleName: '编程助手', builtIn: true, enabled: true,
|
||||
model: null, modelResolution: 'required', skillIds: [], prompt: '',
|
||||
responsibility: { mission: '协助完成当前项目的编程任务。', owns: [], boundaries: [], collaborators: [], principles: [] },
|
||||
archivedAt: null, pinned: true, createdAt: now, updatedAt: now,
|
||||
};
|
||||
return { ...config, defaultAgentId: id, initialized: true, agents: [...config.agents, agent], updatedAt: now };
|
||||
}
|
||||
|
||||
export function createCodingProjectConfigV2(
|
||||
now = new Date().toISOString(),
|
||||
projectType: ProjectType = 'custom',
|
||||
@@ -240,7 +263,7 @@ export function createCodingProjectConfigV2(
|
||||
if (projectId !== undefined && !isCanonicalCodingProjectId(projectId)) {
|
||||
throw new Error('Project identity is invalid');
|
||||
}
|
||||
return {
|
||||
return ensureDefaultCodingAgent({
|
||||
schemaVersion: 2,
|
||||
projectType,
|
||||
...(projectId !== undefined ? { projectId } : {}),
|
||||
@@ -249,7 +272,7 @@ export function createCodingProjectConfigV2(
|
||||
knowledgeDirectory: 'knowledge',
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
};
|
||||
}, now);
|
||||
}
|
||||
|
||||
export async function readCodingProjectConfigV2(
|
||||
@@ -281,6 +304,7 @@ export async function createCodingProjectMetadata(
|
||||
options: {
|
||||
projectType?: ProjectType;
|
||||
projectId?: string;
|
||||
defaultModel?: ProductModelRef | null;
|
||||
now?: string;
|
||||
writer?: JsonFileWriter;
|
||||
} = {},
|
||||
@@ -292,6 +316,10 @@ export async function createCodingProjectMetadata(
|
||||
if ((error as NodeJS.ErrnoException).code !== 'ENOENT') throw error;
|
||||
}
|
||||
const config = createCodingProjectConfigV2(options.now, options.projectType, options.projectId);
|
||||
if (options.defaultModel) {
|
||||
config.agents[0].model = normalizeProductModelRef(options.defaultModel);
|
||||
config.agents[0].modelResolution = 'resolved';
|
||||
}
|
||||
await Promise.all([
|
||||
mkdir(path.join(projectPath, '.makelore'), { recursive: true }),
|
||||
mkdir(path.join(projectPath, 'knowledge'), { recursive: true }),
|
||||
|
||||
Reference in New Issue
Block a user