# cockpit_context.dspy — 返回当前上下文(项目/迭代),供前端 context_bar 显示 import json uid = await get_user() session_id = (params_kw or {}).get('session_id', '') dbname = get_module_dbname('pipeline-sdlc') async with DBPools().sqlorContext(dbname) as sor: pid, iid = await get_session_context(sor, uid, session_id) # 拿到项目名和迭代名 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)