PMFlow/backend/app/services/project_knowledge_graph_ser.../shared.py

61 lines
1.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""Project Knowledge Graph service.
第一阶段目标:
1. 构建统一实体/关系/证据写入能力
2. 支持结构化数据(project/task/signal/user)同步
3. 支持代码目录扫描快照
4. 提供图谱概览统计
"""
from __future__ import annotations
import hashlib
import json
import os
from datetime import datetime, timedelta, timezone
from pathlib import Path
from typing import Any, Optional
from sqlalchemy import and_, func, select
from sqlalchemy.ext.asyncio import AsyncSession
from ...models import (
IngestEvent,
IngestOffset,
KGEvidence,
KGEntity,
KGRelation,
KGSyncRun,
Project,
FeishuItem,
Signal,
SymbolDefinition,
SymbolReference,
Task,
User,
)
from ..context_cache_service import context_cache_service
from ..signal.symbol_index import SymbolIndexService
from ...utils.timezone import now_cn_naive
def _utc_now_naive() -> datetime:
return now_cn_naive()
DDL_BLOCKED_PREFIXES = [
"CREATE",
"ALTER",
"DROP",
"TRUNCATE",
"RENAME",
"COMMENT",
"GRANT",
"REVOKE",
]
DDL_GUARDRAIL_POLICY_KEY = "policy:ddl_via_interface_only"
DDL_GUARDRAIL_POLICY_NAME = "DDL 只能通过受控接口/迁移流程"
__all__ = [name for name in globals() if not name.startswith("__")]