# cockpit_context.dspy — 返回当前上下文(项目/迭代),供前端 context_bar 显示 import json uid = await get_user() dbname = get_module_dbname('pipeline-sdlc') async with DBPools().sqlorContext(dbname) as sor: recs = await sor.sqlExe( "SELECT current_project_id, current_iteration_id FROM pipeline_agent_settings WHERE user_id=${uid}$", {"uid": uid}) pid = '' iid = '' if recs and len(recs) > 0: pid = getattr(recs[0], 'current_project_id', '') or '' iid = getattr(recs[0], 'current_iteration_id', '') or '' # 拿到项目名和迭代名 pname = '' iname = '' ws_dir = '' if pid: precs = await sor.sqlExe( "SELECT name, workspace_dir FROM sd_projects WHERE id=${pid}$", {"pid": pid}) if precs and len(precs) > 0: pname = getattr(precs[0], 'name', '') or '' ws_dir = getattr(precs[0], 'workspace_dir', '') or '' if iid: irecs = await sor.sqlExe( "SELECT iteration_name FROM sd_iterations WHERE id=${iid}$ OR iteration_name=${iid}$ AND project_id=${pid}$", {"iid": iid, "pid": pid}) if irecs and len(irecs) > 0: iname = getattr(irecs[0], 'iteration_name', '') or '' return json.dumps({ "project_name": pname, "iteration_name": iname, "project_id": pid, "iteration_id": iid, "workspace_dir": ws_dir, }, ensure_ascii=False)