agentleFS
aymenfurteraymenfurter/polyclaw/AGENTS.md

polyclaw

AGENTS.md86 starsChanged 10 months agoMITView on GitHub

Polyclaw is an autonomous AI copilot built on the GitHub Copilot SDK. It runs outside the IDE: browser, terminal, messaging apps, and phone calls. The codebase has three main surfaces: a Python backend (app/runtime/), a React + TypeScript frontend (app/frontend/), and a Node.js terminal UI (app/tui/). Production code uses relative imports (from ..config.settings import cfg). Test code uses absolute imports (from app.runtime.config.settings import Settings).

  • Reads credentials
  • Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about code style.

    Of the AGENTS.md files we read, the 35,266 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.

The file

Show its rules and text

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

14 rules. About 0 are common, 5 are distinctive, and 9 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈5

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 9

    Very specific

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

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

    Every file starts with from __future__ import annotations.

    line 24
  2. Very specific:

    Use PEP 604 union syntax (str | None) instead of Optional[str].

    line 25
  3. Very specific:

    Use collections.abc for abstract types (Callable, Awaitable), not typing equivalents.

    line 26
  4. Very specific:

    Use %-style formatting in log calls (lazy evaluation), never f-strings.

    line 28
  5. Very specific:

    Async bridging: Use run_sync() helper to run blocking code in an executor.

    line 60
  6. Very specific:

    Immutable collections: Use frozenset for constant sets (SECRET_ENV_KEYS, _QUIET_PATHS).

    line 63
  7. Very specific:

    Always attach exc_info=True to warning/error calls that catch exceptions.

    line 74
  8. Very specific:

    Test files mirror source: test_<module>.py.

    line 85
  9. Distinctive:

    No component library -- all custom HTML + CSS.

    line 97
  10. Very specific:

    All functional components using named function declarations: export default function TopBar({ onTogglePanel }: Props).

    line 104
  11. Distinctive:

    Keep dependencies minimal.

    line 177
  12. Distinctive:

    Prefer composition over inheritance.

    line 178
  13. Distinctive:

    Use dispatch tables over long if/elif chains.

    line 179
  14. Distinctive:

    Every module has a single-line docstring describing its purpose.

    line 180

≈ “Common” is an estimate: at least 1 in 5 of the 45,344 AGENTS.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
AGENTS.md

AGENTS.md -- Custom Instructions for Polyclaw

Project Overview

Polyclaw is an autonomous AI copilot built on the GitHub Copilot SDK. It runs outside the IDE: browser, terminal, messaging apps, and phone calls. The codebase has three main surfaces: a Python backend (app/runtime/), a React + TypeScript frontend (app/frontend/), and a Node.js terminal UI (app/tui/).

Repository Layout

app/runtime/          Python backend (aiohttp, Copilot SDK, Azure integrations)
app/frontend/         React 19 + TypeScript SPA (Vite, Playwright E2E)
app/tui/              Ink-based terminal UI (TypeScript)
plugins/              Plugin packs (PLUGIN.json + skill markdown files)
skills/               Built-in skill definitions (SKILL.md with YAML frontmatter)
docs/                 Hugo documentation site
scripts/              Shell helpers for local dev

Python Backend (app/runtime/)

Style and Tooling

  • Ruff enforces style: line-length 100, target Python 3.11, rules E, W, F, I (isort), UP (pyupgrade).
  • Every file starts with from __future__ import annotations.
  • Use PEP 604 union syntax (str | None) instead of Optional[str].
  • Use collections.abc for abstract types (Callable, Awaitable), not typing equivalents.
  • Annotate every function signature fully, including -> None on void functions.
  • Use %-style formatting in log calls (lazy evaluation), never f-strings.

Imports

  1. from __future__ import annotations
  2. Standard library
  3. Third-party packages
  4. Relative imports for intra-package references

Production code uses relative imports (from ..config.settings import cfg). Test code uses absolute imports (from app.runtime.config.settings import Settings).

Naming

ElementConventionExample
Modulessnake_caseevent_handler.py
Private modulesLeading underscore_json_store.py
ClassesPascalCaseEventHandler, McpConfigStore
Functions/methodssnake_casebuild_system_prompt()
Private methodsLeading underscore_handle_delta()
ConstantsUPPER_SNAKE_CASEMAX_START_RETRIES
Module-level private constants_UPPER_SNAKE_CASE_BUILTIN_SERVERS

Architecture Patterns

  • Configuration: Singleton cfg = Settings() accessed via from ..config.settings import cfg. Reads from .env file and os.getenv, with @kv: prefix for Azure Key Vault resolution.
  • State stores: JSON-file-backed, built on _json_store.JsonStore with threading.Lock for thread safety. One store class per concern (e.g., McpConfigStore, SessionStore).
  • Singletons: Module-level _instance: T | None = None with get_*() factory and _reset_*() teardown registered via register_singleton() for test isolation.
  • Route handlers: One class per feature area with a register(router) method. App wired in AppFactory.build().
  • Error responses: JSON envelope {"status": "error", "message": "..."} with appropriate HTTP codes.
  • Tools: Defined with @define_tool decorator + pydantic.BaseModel for parameter schemas.
  • Event dispatch: Dict-based dispatch table (_DISPATCH_TABLE) mapping event types to handler methods, not if/elif chains.
  • Async bridging: Use run_sync() helper to run blocking code in an executor. Background loops via asyncio.create_task().
  • Safe teardown: Wrap cleanup in _safe_*() methods that catch all exceptions to prevent cascade failures.
  • Result type: Frozen dataclass with ok()/fail() constructors and boolean evaluation for operations that can fail.
  • Immutable collections: Use frozenset for constant sets (SECRET_ENV_KEYS, _QUIET_PATHS).

Logging

logger = logging.getLogger(__name__)
logger.info("[module.action] key=%s value=%r", key, value)
  • One logger per module.
  • Bracket-prefixed context tags: [agent.start], [chat.dispatch].
  • Always attach exc_info=True to warning/error calls that catch exceptions.

Error Handling

  • ValueError for validation errors, caught at API boundaries and returned as 400.
  • RuntimeError for precondition failures.
  • Defensive except Exception with log-and-continue for non-critical paths (fallback to defaults).

Testing

  • pytest with pytest-asyncio (asyncio_mode = "auto").
  • Test files mirror source: test_<module>.py.
  • Group related tests in class Test<Topic>: with test_<scenario> methods.
  • Isolation via autouse fixtures: _isolate_data_dir (tmp_path + monkeypatch), _reset_singletons.
  • Mock with unittest.mock.patch / AsyncMock / MagicMock, applied as decorators.
  • Route tests use aiohttp.test_utils.TestClient.
  • Mark slow tests with @pytest.mark.slow (skipped unless --run-slow).

Frontend (app/frontend/)

Style and Tooling

  • React 19 + TypeScript (strict mode) + Vite.
  • No component library -- all custom HTML + CSS.
  • Single global CSS file with BEM-like class naming (block__element--modifier).
  • CSS custom properties for design tokens (--gold, --surface, --radius).
  • Dark theme only.

Components

  • All functional components using named function declarations: export default function TopBar({ onTogglePanel }: Props).
  • Props defined via local interface Props above the component. No React.FC.
  • Sub-components are non-exported function declarations co-located in the same file.
  • Pages are lazy-loaded with lazy(() => import(...)) + <Suspense>.
  • React Router v7 with BrowserRouter.

State Management

  • useState / useCallback / useRef only. No global state library.
  • Custom hooks return plain objects: { authenticated, loading, login, logout }.
  • Side effects in useEffect with cleanup returns.

File Naming

TypeConventionExample
ComponentsPascalCase.tsxTopBar.tsx
HookscamelCase.ts with use prefixuseAuth.ts
PagesPascalCase.tsxSetupWizard.tsx
UtilitiescamelCase.tsapi.ts, types.ts

API Layer

  • Central api<T>(path, opts) generic wrapper around fetch with Bearer auth from localStorage.
  • apiFormData() for multipart uploads.
  • createChatSocket() returning a ChatSocket interface for WebSocket.
  • Mock mode via VITE_MOCK=1.

Types

  • Centralized in types.ts. Use interface for object shapes, type for unions.
  • import type for type-only imports.

Testing

  • Playwright E2E only (no unit tests).
  • mockApi(page) and bypassAuth(page) helpers for test isolation.
  • Mock data constants prefixed with MOCK_.

Plugins and Skills

Skills

Markdown files named SKILL.md with YAML frontmatter:

---
name: web-search
description: 'Search the web using a search engine'
metadata:
  verb: search
---

Body contains natural-language instructions for the agent.

Plugins

Directory with PLUGIN.json manifest:

{
  "id": "foundry-agents",
  "name": "Microsoft Foundry Agents",
  "skills": ["foundry-code-interpreter", "foundry-agent-chat"],
  "dependencies": { "cli": ["az"], "pip": ["azure-ai-projects"] }
}

Plugins bundle multiple skills and declare their dependencies.

General Principles

  • Keep dependencies minimal. No unnecessary frameworks or libraries.
  • Prefer composition over inheritance.
  • Use dispatch tables over long if/elif chains.
  • Every module has a single-line docstring describing its purpose.
  • Security defaults to locked-down: auth required on all API routes, whitelist-based channel access.
  • Deferred imports to break circular dependencies when needed.
  • Thread-safe file I/O via locks in shared stores.
  • __all__ in __init__.py files to control public API surface.

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.