← back to glibalien__obsidian-tools

Function bodies 154 total

All specs Real LLM only Function bodies
append_to_section function · python · L104-L146 (43 LOC)
src/tools/sections.py
def append_to_section(path: str, heading: str, content: str) -> str:
    """Append content at the end of a section.

    Finds a heading by case-insensitive exact match and appends content
    at the end of that section (just before the next same-or-higher-level
    heading, or end of file). Preserves the heading and all existing content.

    Args:
        path: Path to the note (relative to vault or absolute).
        heading: Full heading text including # symbols (e.g., "## Context").
        content: Content to append to the section (may be multiline).

    Returns:
        JSON response: {"success": true, "path": "..."} on success,
        or {"success": false, "error": "..."} on failure.
    """
    file_path, error = resolve_file(path)
    if error:
        return err(error)

    # Read file content
    try:
        file_content = file_path.read_text(encoding="utf-8")
    except Exception as e:
        return err(f"Error reading file: {e}")

    lines = file_content.split("\n")
log_interaction function · python · L9-L33 (25 LOC)
src/tools/utility.py
def log_interaction(
    task_description: str,
    query: str,
    summary: str,
    files: list[str] | None = None,
    full_response: str | None = None,
) -> str:
    """Log a Claude interaction to today's Obsidian daily note.

    Args:
        task_description: Brief description of the task performed.
        query: The original query or prompt.
        summary: Summary of the response (use 'n/a' if full_response provided).
        files: List of referenced file paths (optional).
        full_response: Full response text for conversational logs (optional).

    Returns:
        Confirmation message with the daily note path.
    """
    try:
        path = log_chat(task_description, query, summary, files, full_response)
    except Exception as e:
        return err(f"Logging failed: {e}")

    return ok(f"Logged to {path}")
get_current_date function · python · L36-L42 (7 LOC)
src/tools/utility.py
def get_current_date() -> str:
    """Get the current date in YYYY-MM-DD format.

    Returns:
        Current date as a string in YYYY-MM-DD format.
    """
    return ok(date=datetime.now().strftime("%Y-%m-%d"))
validate_pagination function · python · L6-L42 (37 LOC)
src/tools/_validation.py
def validate_pagination(
    offset: int,
    limit: int,
    *,
    max_limit: int = LIST_MAX_LIMIT,
) -> tuple[int | None, int | None, str | None]:
    """Validate and coerce pagination parameters.

    Args:
        offset: Number of results to skip.
        limit: Maximum number of results to return.
        max_limit: Upper bound for limit to avoid huge payloads.

    Returns:
        Tuple of (coerced_offset, coerced_limit, error_message).
        On error, offset/limit are None and error_message is populated.
    """
    try:
        parsed_offset = int(offset)
    except (TypeError, ValueError):
        return None, None, "Invalid pagination: offset must be an integer"

    try:
        parsed_limit = int(limit)
    except (TypeError, ValueError):
        return None, None, "Invalid pagination: limit must be an integer"

    if parsed_offset < 0:
        return None, None, "Invalid pagination: offset must be >= 0"

    if parsed_limit < 1:
        return None, None, "Invalid pa
‹ prevpage 4 / 4