OpenSpace/openspace/services/memory/__init__.py
2026-07-17 11:43:42 +08:00

397 lines
11 KiB
Python

"""Memory services for OPENSPACE.md and auto memory."""
from .memdir import (
DIR_EXISTS_GUIDANCE,
DIRS_EXIST_GUIDANCE,
ENTRYPOINT_NAME,
MAX_ENTRYPOINT_BYTES,
MAX_ENTRYPOINT_LINES,
EntrypointTruncation,
build_assistant_daily_log_lines,
build_memory_lines,
build_memory_prompt,
build_searching_past_context_section,
ensure_memory_dir_exists,
get_auto_mem_daily_log_path,
get_auto_mem_entrypoint,
get_auto_mem_path,
get_memory_base_dir,
has_auto_mem_path_override,
is_auto_mem_path,
is_auto_memory_enabled,
is_extract_mode_active,
load_memory_prompt,
truncate_entrypoint_content,
)
from .memory_scan import (
FRONTMATTER_MAX_LINES,
MAX_MEMORY_FILES,
MemoryHeader,
format_memory_manifest,
scan_memory_files,
)
from .memory_types import (
MEMORY_DRIFT_CAVEAT,
MEMORY_FRONTMATTER_EXAMPLE,
MEMORY_TYPES,
TRUSTING_RECALL_SECTION,
TYPES_SECTION_COMBINED,
TYPES_SECTION_INDIVIDUAL,
WHAT_NOT_TO_SAVE_SECTION,
WHEN_TO_ACCESS_SECTION,
MemoryType,
parse_memory_type,
)
from .extract import (
MemoryCursor,
MemoryExtractionResult,
MemoryExtractor,
build_extract_auto_only_prompt,
build_extract_combined_prompt,
count_model_visible_messages_since,
create_auto_mem_can_use_tool,
create_memory_saved_message,
drain_pending_extraction,
execute_extract_memories,
extract_written_paths,
get_memory_extractor,
has_memory_writes_since,
init_extract_memories,
should_schedule_extract_memories,
submit_extract_memories,
)
from .dream import (
AutoDreamConfig,
AutoDreamer,
DreamResult,
DreamTaskState,
DreamTurn,
build_consolidation_prompt,
drain_pending_auto_dream,
execute_auto_dream,
execute_manual_auto_dream,
get_auto_dream_config,
get_auto_dreamer,
get_session_transcript_dir,
init_auto_dream,
is_auto_dream_enabled,
list_sessions_touched_since,
read_last_consolidated_at,
rollback_consolidation_lock,
should_schedule_auto_dream,
submit_auto_dream,
try_acquire_consolidation_lock,
)
from .daily_log import (
LOGS_DIRNAME,
MEMORY_LOG_TOOL_NAME,
OPENSPACE_MEMORY_MODE_ENV,
DailyLogAppendResult,
DailyLogEntry,
DailyLogScanResult,
MemoryLogTool,
append_daily_log_entries,
append_daily_log_entries_to_dir,
build_daily_log_consolidation_prompt,
build_extract_daily_log_prompt,
extract_logged_entries,
format_daily_log_entries,
get_daily_log_path,
get_memory_mode,
is_daily_log_mode,
mark_log_entries_consolidated,
scan_unconsolidated_logs,
)
from .session_memory import (
DEFAULT_SESSION_MEMORY_CONFIG,
DEFAULT_SESSION_MEMORY_TEMPLATE,
EXTRACTION_STALE_THRESHOLD_MS,
EXTRACTION_WAIT_TIMEOUT_MS,
MAX_SECTION_LENGTH,
MAX_TOTAL_SESSION_MEMORY_TOKENS,
SESSION_MEMORY_FILENAME,
MessageCursor,
SessionMemory,
SessionMemoryConfig,
SessionMemoryExtractionResult,
SessionMemoryRuntimeState,
build_session_memory_update_prompt,
count_tool_calls_since,
create_memory_file_can_use_tool,
drain_pending_session_memory,
extract_session_memory,
find_message_cursor_index,
get_last_summarized_message_id,
get_session_memory_runtime_state,
get_session_memory,
get_session_memory_dir,
get_session_memory_path,
get_session_memory_path_for_context,
init_session_memory,
is_session_memory_empty,
is_session_memory_enabled,
load_session_memory_prompt,
load_session_memory_template,
manually_extract_session_memory,
mark_extraction_completed,
mark_extraction_started,
read_session_memory,
reset_session_memory_state,
resolve_session_memory_state_key,
set_last_summarized_message_id,
set_session_memory_config,
should_extract_memory,
should_schedule_session_memory,
submit_session_memory_extraction,
truncate_session_memory_for_compact,
wait_for_session_memory_extraction,
write_session_memory,
)
from .openspace_md import (
MAX_MEMORY_CHARACTER_COUNT,
MEMORY_INSTRUCTION_PROMPT,
MemoryFileInfo,
clear_memory_file_caches,
consume_nested_memory_triggers,
filter_injected_memory_files,
get_conditional_rules_for_cwd_level_directory,
get_directories_to_process,
get_large_memory_files,
get_managed_and_user_conditional_rules,
get_memory_files,
get_memory_files_for_nested_directory,
get_nested_memory_attachments_for_file,
get_openspace_mds,
get_post_compact_nested_memory_attachments,
is_memory_file_path,
memory_files_to_attachments,
process_memory_file,
process_conditioned_md_rules,
process_md_rules,
)
from .paths import (
MANAGED_OPENSPACE_DIR,
MemorySource,
find_project_root,
get_managed_openspace_rules_dir,
get_memory_path,
get_openspace_config_home_dir,
get_user_openspace_rules_dir,
validate_memory_path,
)
from .recall import (
MAX_MEMORY_BYTES,
MAX_MEMORY_LINES,
MAX_SESSION_BYTES,
MEMORY_RECALL_MAX_RESULTS,
MEMORY_RECALL_MAX_TOKENS,
MemoryPrefetch,
RelevantMemory,
SurfacedMemory,
collect_recent_successful_tools,
collect_surfaced_memories,
consume_relevant_memory_prefetch,
create_attachment_message,
filter_duplicate_memory_attachments,
find_relevant_memories,
get_relevant_memory_attachments,
memory_age,
memory_age_days,
memory_freshness_text,
memory_header,
read_memories_for_surfacing,
start_relevant_memory_prefetch,
)
from .background import (
MemoryDrainResult,
drain_all_pending_memory_tasks,
drain_pending_memory_tasks,
)
__all__ = [
"MANAGED_OPENSPACE_DIR",
"DIR_EXISTS_GUIDANCE",
"DIRS_EXIST_GUIDANCE",
"ENTRYPOINT_NAME",
"FRONTMATTER_MAX_LINES",
"LOGS_DIRNAME",
"MAX_ENTRYPOINT_BYTES",
"MAX_ENTRYPOINT_LINES",
"MAX_MEMORY_BYTES",
"MAX_MEMORY_FILES",
"MAX_MEMORY_LINES",
"MAX_MEMORY_CHARACTER_COUNT",
"MAX_SESSION_BYTES",
"MAX_SECTION_LENGTH",
"MAX_TOTAL_SESSION_MEMORY_TOKENS",
"MEMORY_DRIFT_CAVEAT",
"MEMORY_FRONTMATTER_EXAMPLE",
"MEMORY_RECALL_MAX_RESULTS",
"MEMORY_RECALL_MAX_TOKENS",
"MEMORY_INSTRUCTION_PROMPT",
"MEMORY_TYPES",
"MEMORY_LOG_TOOL_NAME",
"OPENSPACE_MEMORY_MODE_ENV",
"AutoDreamConfig",
"AutoDreamer",
"DEFAULT_SESSION_MEMORY_CONFIG",
"DEFAULT_SESSION_MEMORY_TEMPLATE",
"EXTRACTION_STALE_THRESHOLD_MS",
"EXTRACTION_WAIT_TIMEOUT_MS",
"DreamResult",
"DreamTaskState",
"DreamTurn",
"DailyLogAppendResult",
"DailyLogEntry",
"DailyLogScanResult",
"EntrypointTruncation",
"MemoryHeader",
"MemoryLogTool",
"MemoryCursor",
"MemoryExtractionResult",
"MemoryExtractor",
"MemoryFileInfo",
"MemoryPrefetch",
"MemoryDrainResult",
"MessageCursor",
"MemorySource",
"MemoryType",
"RelevantMemory",
"SessionMemory",
"SessionMemoryConfig",
"SessionMemoryExtractionResult",
"SESSION_MEMORY_FILENAME",
"SurfacedMemory",
"TRUSTING_RECALL_SECTION",
"TYPES_SECTION_COMBINED",
"TYPES_SECTION_INDIVIDUAL",
"WHAT_NOT_TO_SAVE_SECTION",
"WHEN_TO_ACCESS_SECTION",
"append_daily_log_entries",
"append_daily_log_entries_to_dir",
"build_assistant_daily_log_lines",
"build_memory_lines",
"build_memory_prompt",
"build_consolidation_prompt",
"build_daily_log_consolidation_prompt",
"build_extract_daily_log_prompt",
"build_extract_auto_only_prompt",
"build_extract_combined_prompt",
"build_searching_past_context_section",
"build_session_memory_update_prompt",
"clear_memory_file_caches",
"collect_recent_successful_tools",
"collect_surfaced_memories",
"consume_nested_memory_triggers",
"consume_relevant_memory_prefetch",
"count_model_visible_messages_since",
"count_tool_calls_since",
"create_attachment_message",
"create_auto_mem_can_use_tool",
"create_memory_file_can_use_tool",
"create_memory_saved_message",
"drain_all_pending_memory_tasks",
"drain_pending_auto_dream",
"drain_pending_extraction",
"drain_pending_memory_tasks",
"drain_pending_session_memory",
"ensure_memory_dir_exists",
"execute_auto_dream",
"execute_manual_auto_dream",
"execute_extract_memories",
"extract_logged_entries",
"extract_session_memory",
"extract_written_paths",
"filter_duplicate_memory_attachments",
"filter_injected_memory_files",
"find_relevant_memories",
"find_message_cursor_index",
"find_project_root",
"format_memory_manifest",
"format_daily_log_entries",
"get_auto_dream_config",
"get_auto_dreamer",
"get_last_summarized_message_id",
"get_auto_mem_daily_log_path",
"get_auto_mem_entrypoint",
"get_auto_mem_path",
"get_daily_log_path",
"get_memory_mode",
"get_memory_extractor",
"get_session_memory",
"get_session_memory_dir",
"get_session_memory_path",
"get_session_memory_path_for_context",
"get_relevant_memory_attachments",
"get_large_memory_files",
"get_conditional_rules_for_cwd_level_directory",
"get_directories_to_process",
"get_managed_and_user_conditional_rules",
"get_managed_openspace_rules_dir",
"get_memory_files",
"get_memory_base_dir",
"get_memory_files_for_nested_directory",
"get_memory_path",
"get_nested_memory_attachments_for_file",
"get_openspace_config_home_dir",
"get_openspace_mds",
"get_post_compact_nested_memory_attachments",
"get_session_transcript_dir",
"get_user_openspace_rules_dir",
"has_auto_mem_path_override",
"has_memory_writes_since",
"init_auto_dream",
"init_extract_memories",
"init_session_memory",
"is_daily_log_mode",
"is_auto_dream_enabled",
"should_schedule_extract_memories",
"is_auto_mem_path",
"is_auto_memory_enabled",
"is_extract_mode_active",
"is_session_memory_empty",
"is_session_memory_enabled",
"load_session_memory_prompt",
"load_session_memory_template",
"manually_extract_session_memory",
"mark_extraction_completed",
"mark_extraction_started",
"is_memory_file_path",
"load_memory_prompt",
"list_sessions_touched_since",
"mark_log_entries_consolidated",
"memory_age",
"memory_age_days",
"memory_freshness_text",
"memory_header",
"memory_files_to_attachments",
"parse_memory_type",
"process_conditioned_md_rules",
"process_memory_file",
"process_md_rules",
"read_memories_for_surfacing",
"read_last_consolidated_at",
"read_session_memory",
"reset_session_memory_state",
"resolve_session_memory_state_key",
"rollback_consolidation_lock",
"scan_memory_files",
"scan_unconsolidated_logs",
"start_relevant_memory_prefetch",
"should_schedule_auto_dream",
"should_extract_memory",
"should_schedule_session_memory",
"set_last_summarized_message_id",
"set_session_memory_config",
"SessionMemoryRuntimeState",
"get_session_memory_runtime_state",
"submit_extract_memories",
"submit_auto_dream",
"submit_session_memory_extraction",
"truncate_session_memory_for_compact",
"truncate_entrypoint_content",
"try_acquire_consolidation_lock",
"validate_memory_path",
"wait_for_session_memory_extraction",
"write_session_memory",
]