agentleFS
tensorlakeaitensorlakeai/tensorlake/CLAUDE.md

tensorlake

CLAUDE.md1k starsChanged 3 months agoApache-2.0View on GitHub

TensorLake SDK — a Python SDK for document ingestion (DocumentAI) and serverless agentic applications. Users define applications using decorator-based APIs and deploy them to TensorLake Cloud or run locally. For validations that must run inside the real Tensorlake builder image, use a throwaway Python virtualenv with the published tensorlake package. Do this for live environment checks, not normal repo tests. Key points: - Install from PyPI in a fresh venv: python3 -m venv /tmp/tl-validate-venv && /tmp/tl-validate-venv/bin/python -m pip install -q…

  • Reads credentials
  • Installs packages

Trending

Steady talk.thin dataabout the whole repository

Dec 2025: 0 mentionsJan 2026: 0 mentionsFeb 2026: 0 mentionsMar 2026: 0 mentionsApr 2026: 0 mentionsMay 2026: 0 mentionsJun 2026: 0 mentionsJul 2026: 0 mentionsAug 2026: 1 mentionSep 2026: 0 mentionsOct 2026: 1 mentionNov 2026: 0 mentions
Dec 2025Jun 2026Nov 2026
Mentions a month of the tensorlakeai/tensorlake repository that our weekly crawl found: only 2 in all, so this is a hint, not a trend. There is no adoption data for this file yet.

Who's talking about tensorlakeai/tensorlake

The biggest 2 of 2 mentions linking to the repository that our crawl found. Each line is their own headline.

  • In this repositoryOne other file it gives its agents.

The file

We split this CLAUDE.md into the rules it gives an agent

10 rules. About 0 are common, 3 are distinctive, and 7 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 7

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Read the token of the current tl context, but never print it.

    line 43
  2. Very specific:

    Read organization and project from .tensorlake/config.toml and pass them explicitly to SandboxClient.for_cloud(...).

    line 44
  3. Very specific:

    Create the throwaway sandbox from tensorlake/rootfs-builder, run validation commands, and always delete it with client.delete(sandbox_id) …

    line 45
  4. Very specific:

    Run python .github/scripts/bump_version.py <new-version>.

    line 154
  5. Very specific:

    CRITICAL: Always run tests in BOTH local and remote modes: Do NOT skip remote mode or run only local mode unless the user explicitly says …

    line 163
  6. Very specific:

    Check if indexify-server is running (HTTP ping http://localhost:8900)

    line 172
  7. Distinctive:

    If not then stop immediately and ask the user to run it.

    line 173
  8. Distinctive:

    Ask user for the command that runs indexify-dataplane.

    line 174
  9. Distinctive:

    Run indexify-dataplane using the command given by user.

    line 176
  10. Very specific:

    When running remote mode tests using poetry run tests/path_to/test_file.py you need to also define env var …

    line 180

≈ “Common” is an estimate: at least 1 in 5 of the 12,729 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
CLAUDE.md

CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

Project Overview

TensorLake SDK — a Python SDK for document ingestion (DocumentAI) and serverless agentic applications. Users define applications using decorator-based APIs and deploy them to TensorLake Cloud or run locally.

Common Commands

# Install dependencies and build
make build

# Format code (Black + isort)
make fmt

# Check formatting without modifying
make check

# Run all tests (requires TENSORLAKE_API_URL env var)
make test

# Run a specific test suite
cd tests && ./run_tests.sh --applications
cd tests && ./run_tests.sh --function-executor
cd tests && ./run_tests.sh --document-ai
cd tests && ./run_tests.sh --cli

# Run a single test file
cd tests && poetry run python path/to/test_file.py

# Regenerate gRPC stubs from .proto files
make build_proto

Manual Cloud Sandbox Validations

For validations that must run inside the real Tensorlake builder image, use a throwaway Python virtualenv with the published tensorlake package. Do this for live environment checks, not normal repo tests.

Key points:

  • Install from PyPI in a fresh venv: python3 -m venv /tmp/tl-validate-venv && /tmp/tl-validate-venv/bin/python -m pip install -q --upgrade pip tensorlake.
  • Read the token of the current tl context, but never print it. ~/.config/tensorlake/contexts.toml says whether it is in the OS keychain or in credentials.toml. The published SDK reads TENSORLAKE_API_KEY; TENSORLAKE_PAT is not enough for sandbox creation.
  • Read organization and project from .tensorlake/config.toml and pass them explicitly to SandboxClient.for_cloud(...). Relying only on environment variables can produce missing scope headers.
  • Create the throwaway sandbox from tensorlake/rootfs-builder, run validation commands, and always delete it with client.delete(sandbox_id) in a finally block.
  • Commands run as tl-user by default. Builder-image checks that start dockerd must run as root, e.g. sudo -n <script>.

Minimal pattern:

import os
import subprocess
import tomllib
from pathlib import Path
from tensorlake.sandbox import SandboxClient


def token_for(context: str = "default") -> str:
    config = Path.home() / ".config/tensorlake"
    entry = tomllib.loads((config / "contexts.toml").read_text())["contexts"][context]
    if entry.get("storage") == "keychain":
        # macOS. The item belongs to `tl`, so the keychain asks once to allow this.
        return subprocess.run(
            ["security", "find-generic-password", "-s", "tensorlake", "-a", context, "-w"],
            check=True, capture_output=True, text=True,
        ).stdout.strip()
    credentials = tomllib.loads((config / "credentials.toml").read_text())
    return credentials["contexts"][context]["token"]


def local_config() -> dict[str, str]:
    out = {}
    for raw in Path(".tensorlake/config.toml").read_text().splitlines():
        line = raw.strip()
        if "=" in line:
            key, value = line.split("=", 1)
            out[key.strip()] = value.strip().strip('"')
    return out


endpoint = "https://api.tensorlake.ai"
token = token_for()
cfg = local_config()
os.environ["TENSORLAKE_API_KEY"] = token

client = SandboxClient.for_cloud(
    api_key=token,
    api_url=endpoint,
    organization_id=cfg["organization"],
    project_id=cfg["project"],
)
sandbox = None
try:
    sandbox = client.create_and_connect(image="tensorlake/rootfs-builder")
    sandbox.write_file("/tmp/validate.sh", b"#!/usr/bin/env bash\nset -euo pipefail\nsudo -n id\n")
    result = sandbox.run(
        "sh",
        ["-lc", "chmod +x /tmp/validate.sh && sudo -n /tmp/validate.sh"],
        timeout=900,
    )
    print(result.stdout)
    if getattr(result, "exit_code", 0) != 0:
        raise RuntimeError(result.stderr)
finally:
    if sandbox is not None:
        client.delete(sandbox.sandbox_id)

Architecture

Three Public APIs

  1. Applications SDK (src/tensorlake/applications/) — Decorator-based API for defining serverless functions and applications. Public interface is in applications/interface/; everything re-exported through applications/__init__.py via from .interface import *.
  2. Sandbox SDK (src/tensorlake/sandbox) - Client for creating Sandboxes where users can run arbitrary code, copy files, install packages and etc.
  3. DocumentAI SDK (src/tensorlake/documentai/) — Client for document parsing, extraction, and classification.

Applications: Decorator → Function → Runner

Users decorate functions with @application and @function (defined in interface/decorators.py). Decorators create Function objects registered in a global registry (registry.py). Functions support .map() and .reduce() operations and return Future/Awaitable objects for async execution.

Two execution modes:

  • Local (applications/local/) — Direct in-process execution for development/testing via run_local_application(), implemented by LocalRunner class.
  • Remote (applications/remote/) — Cloud deployment via run_remote_application() and gRPC communication, implemented by AllocationRunner class.

Function Executor

src/tensorlake/function_executor/ — gRPC server that executes user functions in sandboxed environments. Proto definitions in function_executor/proto/. Proto files and generated Python stubs must coexist in the same directory (gRPC limitation).

CLI

src/tensorlake/cli/ — Click-based CLI (tensorlake command). Entry points: tensorlake deploy, tensorlake parse, tensorlake login, tensorlake secrets, etc.

Vendored Dependencies

src/tensorlake/vendor/ contains vendored faker and nanoid libraries. Black and isort are configured to skip this directory.

Key Conventions

  • Typed API responses: Deserialize response and error bodies into explicit structs/enums (serde::Deserialize in Rust) and access named fields. Do not parse a body into serde_json::Value and extract known fields with .get() / .as_str(). Reuse wire models or add a focused response struct; represent supported legacy shapes with types, defaults, and aliases. Reserve dynamic JSON for individual fields whose contract permits arbitrary JSON, such as error_details. Preserve raw-body fallback for unrecognized or non-JSON error responses.
  • Python 3.10+, managed with Poetry 2.0.0
  • Formatting: Black + isort (profile "black"). Pre-commit hooks enforce this.
  • Tests: Standard unittest framework with parameterized for parameterized tests. Parameterized tests are main used to run the same test code in local and remote modes and ensure the same results. Claude must not create new Python environments to run test. Instead it should use currrent Poetry environment by i.e. using poetry run python tests/path_to/test_file.py.
  • Pydantic v2 for data models throughout.
  • gRPC stubs are generated with grpcio-tools 1.60.0 (pinned old version for forward compatibility) and reformatted with Black/isort after generation.

Releasing / version bumps

IMPORTANT: After finishing code changes on a branch, before handing back to the user, remind them to bump the version. All packages (Python, Rust, CLI, TypeScript) are released in lockstep at a single shared version, so a release bumps everything together.

How to bump:

  • Run python .github/scripts/bump_version.py <new-version>. A single command updates every version-bearing file used by the PyPI / crates.io / CLI / npm release workflows:
    • pyproject.toml (root, tensorlake PyPI package)
    • Cargo.toml (root, workspace version — all crates inherit via version.workspace = true, including crates/cli)
    • crates/rust-cloud-sdk-py/pyproject.toml
    • typescript/package.json (npm package; publish_npm.yaml reads the version from here)
  • Cargo.lock and typescript/package-lock.json regenerate on build/install — commit them after they refresh, don't hand-edit.

Running Applications tests

CRITICAL: Always run tests in BOTH local and remote modes. Do NOT skip remote mode or run only local mode unless the user explicitly says to run local or remote only. Most test files use @parameterized to run each test case in both modes.

Never reduce test scope to work around infrastructure failures. If tests fail due to missing setup (e.g. deploy_applications fails in setUpClass), this means remote mode is not set up yet — follow the remote mode setup procedure below instead of falling back to running only local tests.

Running remote mode tests

Before running a test in remote mode you MUST first ensure all remote mode dependencies are available:

  1. Check if indexify-server is running (HTTP ping http://localhost:8900)
  2. If not then stop immediately and ask the user to run it. Do not try to run local mode tests to proceed faster.
  3. Ask user for the command that runs indexify-dataplane. Do not assume that indexify-dataplane is running or not running. You have to start it yourself to get access to its stdout/stderr so you can investigate test failures yourself.
  4. Run indexify-dataplane using the command given by user.

The dataplane command stdout/stderr contain logs from indexify-dataplane service and from Function Executors started by indexify-dataplane. Use these Function Executor logs to investigate failures in remote mode.

When running remote mode tests using poetry run tests/path_to/test_file.py you need to also define env var TENSORLAKE_API_URL=http://localhost:8900 by prepending it to the poetry run python command.

Running Local mode tests

Local mode tests don't have any dependency on indexify-dataplane and indexify-server. The logs and backtraces for LocalRunner and related classes are available in stdout/stderr of the test file when you run it. Use these backtraces and logs to investigate local mode test failures.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.