core.ai package

Subpackages

Submodules

core.ai.action_tracker module

Tracks AI assistant file actions for revert support.

class core.ai.action_tracker.AIActionTracker[source]

Bases: object

Records file snapshots before AI tool executions for revert support.

Usage:

tracker.begin_prompt(index) # Before tool loop starts tracker.snapshot_file(path) # Before each file write tracker.end_prompt() # After tool loop completes tracker.revert(index) # Restore files from prompt snapshot

begin_prompt(prompt_index: int)[source]

Start tracking actions for a new prompt.

clear()[source]

Clear all tracked actions.

end_prompt()[source]

Finish tracking. Store the group only if it has actions.

get_modified_files(prompt_index: int) List[str][source]

Get list of files modified by a prompt.

has_actions(prompt_index: int) bool[source]

Check if a prompt had any file-modifying actions.

is_reverted(prompt_index: int) bool[source]

Check if a prompt’s actions have been reverted.

revert(prompt_index: int) Dict[str, str][source]

Revert all file changes from a prompt. Returns dict of path -> status.

snapshot_file(abs_path: str)[source]

Capture file content before modification. Only snapshots once per file per prompt.

class core.ai.action_tracker.FileSnapshot(path: str, content: str | None, existed: bool)[source]

Bases: object

Snapshot of a file before AI modification.

content: str | None
existed: bool
path: str
class core.ai.action_tracker.PromptActionGroup(prompt_index: int, snapshots: Dict[str, ~core.ai.action_tracker.FileSnapshot]=<factory>, reverted: bool = False)[source]

Bases: object

All file actions from a single AI prompt.

property has_actions: bool
prompt_index: int
reverted: bool = False
snapshots: Dict[str, FileSnapshot]

core.ai.api_index module

Complete API reference for the AxisPy Engine, used as context for AI chat.

core.ai.api_index.get_engine_api_reference() str[source]

Return a comprehensive API reference string for the engine.

core.ai.chat_manager module

Chat manager that orchestrates AI conversations with engine context.

class core.ai.chat_manager.ChatManager[source]

Bases: object

Manages AI chat conversations with engine and project context.

Supports an agentic tool-calling loop: when the AI returns tool calls, the manager executes them and feeds results back, up to max_steps.

MAX_TOOL_STEPS = 5
clear_history()[source]

Clear history and active session messages.

create_new_session(name: str = '') str[source]

Create a new session and switch to it.

property current_prompt_index: int

The prompt index of the most recent (or in-progress) prompt.

delete_session(session_id: str) bool[source]

Delete a session.

rename_session(session_id: str, name: str) bool[source]

Rename a session.

revert_prompt(prompt_index: int) Dict[str, str][source]

Revert all file changes from a specific prompt.

send_message(user_message: str) str[source]

Send a message and get a complete response (blocking).

send_message_stream(user_message: str)[source]

Send a message and stream the response via callbacks. Returns the full response when complete.

set_callbacks(on_chunk: Callable[[str], None] = None, on_complete: Callable[[str], None] = None, on_error: Callable[[str], None] = None, on_tool_call: Callable[[str, dict], None] = None, on_tool_result: Callable[[str, str], None] = None, on_session_changed: Callable[[], None] = None)[source]

Set streaming callbacks.

set_project_path(path: str)[source]

Set project path for session persistence and context.

set_provider(provider: AIProvider)[source]
switch_session(session_id: str) bool[source]

Switch to a different session.

class core.ai.chat_manager.ChatMessage(role: str, content: str, tool_call_id: str = '', name: str = '')[source]

Bases: object

A single message in the conversation.

content
name
role
timestamp
tool_call_id

core.ai.context_builder module

Builds context about the user’s project and current editor state for AI chat.

class core.ai.context_builder.ContextBuilder[source]

Bases: object

Collects project structure, scene info, and user scripts to provide rich context to the AI assistant.

build_context() str[source]

Build a context string describing the user’s project and current state.

get_user_script_content(script_path: str) str[source]

Read the content of a user script file.

set_project_path(path: str)[source]
set_scene_getter(getter)[source]

Set a callable that returns the current Scene object.

set_selected_entities_getter(getter)[source]

Set a callable that returns the list of selected entities.

core.ai.session_manager module

Session manager for AI chat conversations — save/load to .axispy/project.ai

class core.ai.session_manager.ChatSession(id: str, name: str, created_at: float, updated_at: float, messages: Dict[str, ~typing.Any]]=<factory>)[source]

Bases: object

A single conversation session.

add_message(role: str, content: str, **kwargs)[source]

Add a message to the session.

classmethod create(name: str = 'New Session') ChatSession[source]
created_at: float
classmethod from_dict(data: dict) ChatSession[source]
id: str
messages: List[Dict[str, Any]]
name: str
to_dict() dict[source]
updated_at: float
class core.ai.session_manager.SessionManager(project_path: str = '')[source]

Bases: object

Manages chat sessions persistence to .axispy/project.ai

active_session_id: str | None
add_message_to_active(role: str, content: str, **kwargs)[source]

Add a message to the active session.

clear_active_session()[source]

Clear all messages from the active session.

create_session(name: str = '') ChatSession[source]

Create a new session and make it active.

delete_session(session_id: str) bool[source]

Delete a session. Returns True if deleted.

get_active_messages() List[Dict[str, Any]][source]

Get messages from the active session.

get_active_session() ChatSession | None[source]

Get the currently active session.

get_session_list() List[ChatSession][source]

Get all sessions sorted by updated_at (newest first).

load() bool[source]

Load sessions from disk. Returns True if loaded successfully.

rename_session(session_id: str, new_name: str) bool[source]

Rename a session.

save() bool[source]

Save sessions to disk. Returns True if saved successfully.

sessions: Dict[str, ChatSession]
set_project_path(path: str)[source]

Set the project path and compute the sessions file path.

switch_session(session_id: str) bool[source]

Switch to a different session.

core.ai.tools module

Engine-specific tools that the AI agent can call to inspect the project.

class core.ai.tools.ToolExecutor[source]

Bases: object

Executes engine tools using callbacks wired to the editor state.

execute(tool_name: str, arguments: Dict[str, Any]) str[source]

Execute a tool by name and return the result as a string.

set_project_path(path: str)[source]
set_scene_getter(getter: Callable)[source]
set_scene_reload_callback(callback: Callable)[source]

Set callback to trigger scene reload after file edits.

set_selected_entities_getter(getter: Callable)[source]

Module contents