paths.py 1.77 KB
"""graphlemon's own local runtime directory (U-003).

architecture doc §13.2 "原始执行日志的存放位置" / 01-M 1.13 execution_log_file.file_path
both give `~/.graphlemon/logs/<project_id>/<task_id>/<run_id>/<node_exec_id>.jsonl`
as an *example* path, not a hard spec -- this module is what makes that example
the actual convention (overridable via GRAPHLEMON_HOME, e.g. for tests).

The default lives under the user's home directory, deliberately outside this
repo's own checkout -- that's what makes "日志目录不纳入平台自身 Git 历史"
(U-003's Done criterion) true by construction rather than by a .gitignore rule
someone could forget to add.
"""

import os


def platform_home():
    """graphlemon's own local runtime directory root."""
    override = os.environ.get("GRAPHLEMON_HOME")
    if override:
        return os.path.abspath(override)
    return os.path.join(os.path.expanduser("~"), ".graphlemon")


def log_dir():
    return os.path.join(platform_home(), "logs")


def log_file_path(project_id, task_id, run_id, node_exec_id):
    """01-M 1.13 execution_log_file.file_path convention."""
    return os.path.join(log_dir(), project_id, task_id, run_id, node_exec_id + ".jsonl")


def is_separate_from(target_folder_path):
    """True if graphlemon's platform home neither contains nor is contained by
    target_folder_path -- the physical-separation property U-003's Done
    criterion requires between the platform directory and any target project."""
    home = os.path.realpath(platform_home())
    target = os.path.realpath(target_folder_path)
    if home == target:
        return False
    home_prefix = home.rstrip(os.sep) + os.sep
    target_prefix = target.rstrip(os.sep) + os.sep
    return not target.startswith(home_prefix) and not home.startswith(target_prefix)