Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:AMAP ML SkillClaw LocalBucket

From Leeroopedia
Knowledge Sources
Domains Storage, Skill_Evolution
Last Updated 2026-10-22 00:00 GMT

Overview

Concrete local filesystem bucket backend that mimics the `oss2.Bucket` API, enabling the evolve server to read and write sessions and skills from a normal directory tree without remote object storage credentials.

Description

The LocalBucket class (aliased as MockBucket) is a drop-in replacement for `oss2.Bucket` backed by a local directory. It implements `get_object(key)` (returns `_LocalObject` with `read()`), `put_object(key, data)` (writes bytes/str/stream to file), `delete_object(key)`, and `LocalObjectIterator` (walks the directory tree filtering by prefix). The default root directory is `evolve_server/storage/mock/`, but can be overridden via the constructor or the `--local-root` / `--mock-root` CLI flags. `MockBucket` and `MockObjectIterator` are backward-compatible aliases for the original mock-only code path.

Usage

Import and use when you need to:

  • Run the evolve server locally without S3/OSS credentials (`--mock` or `--local-root`)
  • Test storage operations against a local filesystem instead of remote object storage
  • Understand the object storage abstraction used by the evolve server
  • Debug storage operations by inspecting files in a local directory

Code Reference

Source Location

  • Repository: SkillClaw
  • File: `evolve_server/storage/mock_bucket.py:L1-104`

Signature

class LocalBucket:
    """Drop-in replacement for oss2.Bucket backed by a local directory.

    Parameters
    ----------
    root:
        Local directory that acts as the "bucket root".
        Defaults to evolve_server/mock/.
    """

    def __init__(self, root: str | Path | None = None) -> None:
        self._root = str(root or _DEFAULT_LOCAL_DIR)

    def get_object(self, key: str) -> _LocalObject:
        """Read a file from the bucket. Raises FileNotFoundError if missing."""

    def put_object(self, key: str, data: bytes | str | io.IOBase) -> None:
        """Write bytes, string, or stream to a file in the bucket."""

    def delete_object(self, key: str) -> None:
        """Delete a file from the bucket if it exists."""

class LocalObjectIterator:
    """Iterate over files in the local backend that start with prefix.
    Mimics oss2.ObjectIterator(bucket, prefix=...)."""

    def __init__(self, bucket: LocalBucket, prefix: str = "") -> None:
        ...

    def __iter__(self) -> Iterator[_LocalObjectInfo]:
        ...

# Backward-compatible aliases
MockBucket = LocalBucket
MockObjectIterator = LocalObjectIterator

Import

from evolve_server.storage.mock_bucket import LocalBucket, MockBucket, LocalObjectIterator

I/O Contract

Inputs

Name Type Required Description
root Path | None No Local directory acting as bucket root (default: evolve_server/mock/)
key str Yes (get/put/delete) Object key (relative file path within root)
data str | io.IOBase Yes (put) Data to write (bytes, string, or binary stream)
prefix str No (iter) Filter for listing files by key prefix

Outputs

Name Type Description
get_object returns _LocalObject Object with .read() -> bytes and .key attribute
put_object returns None Writes file to filesystem (creates parent dirs)
delete_object returns None Removes file if it exists (no error if missing)
LocalObjectIterator yields _LocalObjectInfo Objects with .key attribute for each matching file

Usage Examples

Basic Local Storage

from evolve_server.storage.mock_bucket import LocalBucket

bucket = LocalBucket("/tmp/my-evolve-store")

# Write a session JSON
bucket.put_object("sessions/abc123.json", b'{"session_id": "abc123", "turns": []}')

# Read it back
obj = bucket.get_object("sessions/abc123.json")
data = obj.read()  # bytes
print(f"Read {len(data)} bytes from {obj.key}")

# Delete it
bucket.delete_object("sessions/abc123.json")

List Objects by Prefix

from evolve_server.storage.mock_bucket import LocalBucket, LocalObjectIterator

bucket = LocalBucket("/tmp/my-evolve-store")

# List all session objects
for obj_info in LocalObjectIterator(bucket, prefix="sessions/"):
    print(f"Found: {obj_info.key}")
    obj = bucket.get_object(obj_info.key)
    # Process obj.read() as needed

Use with Evolve Server

# The evolve server uses LocalBucket when --mock or --local-root is set
# python -m evolve_server --local-root /tmp/my-store --once

from evolve_server.storage.mock_bucket import LocalBucket

# Same interface as oss2.Bucket — no code changes needed
bucket = LocalBucket("/tmp/my-store")
bucket.put_object("skills/my-skill/SKILL.md", "# My Skill\n")
print("Skill stored locally — evolve server can read it")

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment