Nodes/ComfyUI_EmAySee_CustomNodes/EmAySee Context Manager V2
ComfyUI Node

EmAySee Context Manager V2

The chatty rewrite — Context Manager V2 and its console-debug spam

By EmAySee·Created about a year ago·Updated 4 months ago· 2
EmAySee Context Manager V2
    • STRING
    file_pathprompt_v2.txt
    history_count2
    mode
    force_resetfalse
    new_generation

    EmAySee Context Manager V2 is what happened when the author got frustrated debugging the original: the same rolling text-file context memory, but instrumented to tell you exactly what it's doing - every single time it runs.

    Functionally it's the twin of the V1 Context Manager. Same file_path + history_count + mode + force_reset inputs, same optional new_generation, same Read_Context / Append_and_Prune modes, same single STRING output, and the same PROMPT:/STATE: block format on disk. The differences are cosmetic and diagnostic. The default file is now prompt_v2.txt (so it won't clobber a V1 file), and the code prints its working directory, the resolved file path, the number of valid blocks found, and a status line to the ComfyUI console on every execution.

    That console chatter is the whole personality of this node. It's the debugging build shipped as the production node - the author was clearly chasing the "ghost file" problem where ComfyUI's temp folders make relative paths behave mysteriously. If you ever wonder why your context file isn't where you think it is, run this once and it'll scream the answer at you.

    How it works

    Same core loop as V1, in py/EmAySee_ContextManager_V2.py: read the file, regex-extract PROMPT:.*?STATE:.*? blocks, return the last N on read, or append-and-prune on write. The write path uses atomic-style writes with flush and fsync. The additions are the debug lines (--- [EmAySee V2] DEBUG: Working Directory is ... ---, --- [EmAySee V2] DEBUG: Looking for file at ... ---, --- [EmAySee V2] SUCCESS: Passing N blocks to LLM. ---) and a hard print when a read finds neither a file nor a seed input - it literally tells you "CRITICAL: No file and no seed input!"

    The inputs that matter

    • file_path (default prompt_v2.txt) - the history file. Relative paths resolve against ComfyUI's working directory, so consider an absolute path.
    • history_count (2) - blocks to keep/return.
    • mode - Read_Context or Append_and_Prune.
    • force_reset - deletes the file to start clean.
    • new_generation (optional) - seed (read mode) or text to append (write mode).

    Output: a single STRING.

    Install

    Part of the EmAySee pack:

    cd ComfyUI/custom_nodes
    git clone https://github.com/EmAySee/ComfyUI_EmAySee_CustomNodes
    

    Restart ComfyUI (or Manager → "ComfyUI_EmAySee_CustomNodes"). Category: EmAySee_Automation (note: underscore, not the slash used by V1 - a small inconsistency that makes the menu slightly confusing).

    Gotchas

    The console spam is the feature, but it's also the annoyance - every run prints five or more lines, so an automated loop buries your log. Don't be surprised by it. The real functional gotcha is inherited from V1: the regex requires both PROMPT: and STATE: in every block, and this node doesn't add them for you. Append a block without a STATE: header and the read side silently returns nothing - the debug prints will show "Found 0 valid PROMPT/STATE blocks," which at least makes the failure obvious. And it's unsupported hobbyware like everything in this pack; the good news is the debug output means it debugs itself.

    CategoryEmAySee_Automation

    Inputs (5)

    NameTypeDefaultDescription
    file_pathSTRINGprompt_v2.txt
    history_countINT21–10
    modeCOMBO2 options: Read_Context, Append_and_Prune
    force_resetBOOLEANfalse
    new_generationoptSTRING

    Outputs (1)

    NameTypeDescription
    STRINGSTRING