leashd 0.4.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- leashd-0.4.0/.editorconfig +11 -0
- leashd-0.4.0/.gitignore +31 -0
- leashd-0.4.0/.python-version +1 -0
- leashd-0.4.0/CHANGELOG.md +63 -0
- leashd-0.4.0/CLAUDE.md +163 -0
- leashd-0.4.0/LICENSE +190 -0
- leashd-0.4.0/PKG-INFO +362 -0
- leashd-0.4.0/README.md +330 -0
- leashd-0.4.0/leashd/__init__.py +3 -0
- leashd-0.4.0/leashd/__main__.py +6 -0
- leashd-0.4.0/leashd/agents/base.py +49 -0
- leashd-0.4.0/leashd/agents/claude_code.py +506 -0
- leashd-0.4.0/leashd/app.py +280 -0
- leashd-0.4.0/leashd/connectors/base.py +203 -0
- leashd-0.4.0/leashd/connectors/telegram.py +1019 -0
- leashd-0.4.0/leashd/core/config.py +146 -0
- leashd-0.4.0/leashd/core/engine.py +1499 -0
- leashd-0.4.0/leashd/core/events.py +64 -0
- leashd-0.4.0/leashd/core/interactions.py +351 -0
- leashd-0.4.0/leashd/core/safety/analyzer.py +157 -0
- leashd-0.4.0/leashd/core/safety/approvals.py +176 -0
- leashd-0.4.0/leashd/core/safety/audit.py +127 -0
- leashd-0.4.0/leashd/core/safety/gatekeeper.py +319 -0
- leashd-0.4.0/leashd/core/safety/policy.py +168 -0
- leashd-0.4.0/leashd/core/safety/sandbox.py +38 -0
- leashd-0.4.0/leashd/core/session.py +171 -0
- leashd-0.4.0/leashd/core/workspace.py +109 -0
- leashd-0.4.0/leashd/exceptions.py +41 -0
- leashd-0.4.0/leashd/git/formatter.py +221 -0
- leashd-0.4.0/leashd/git/handler.py +535 -0
- leashd-0.4.0/leashd/git/models.py +70 -0
- leashd-0.4.0/leashd/git/service.py +468 -0
- leashd-0.4.0/leashd/main.py +104 -0
- leashd-0.4.0/leashd/middleware/auth.py +20 -0
- leashd-0.4.0/leashd/middleware/base.py +48 -0
- leashd-0.4.0/leashd/middleware/rate_limit.py +50 -0
- leashd-0.4.0/leashd/plugins/base.py +40 -0
- leashd-0.4.0/leashd/plugins/builtin/audit_plugin.py +43 -0
- leashd-0.4.0/leashd/plugins/builtin/browser_tools.py +119 -0
- leashd-0.4.0/leashd/plugins/builtin/merge_resolver.py +170 -0
- leashd-0.4.0/leashd/plugins/builtin/test_config_loader.py +56 -0
- leashd-0.4.0/leashd/plugins/builtin/test_runner.py +517 -0
- leashd-0.4.0/leashd/plugins/registry.py +62 -0
- leashd-0.4.0/leashd/policies/.gitkeep +0 -0
- leashd-0.4.0/leashd/policies/default.yaml +114 -0
- leashd-0.4.0/leashd/policies/dev-tools.yaml +28 -0
- leashd-0.4.0/leashd/policies/permissive.yaml +75 -0
- leashd-0.4.0/leashd/policies/strict.yaml +73 -0
- leashd-0.4.0/leashd/storage/base.py +52 -0
- leashd-0.4.0/leashd/storage/memory.py +34 -0
- leashd-0.4.0/leashd/storage/sqlite.py +210 -0
- leashd-0.4.0/pyproject.toml +140 -0
- leashd-0.4.0/uv.lock +1275 -0
leashd-0.4.0/.gitignore
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Virtual environments
|
|
2
|
+
.venv/
|
|
3
|
+
|
|
4
|
+
# Python
|
|
5
|
+
__pycache__/
|
|
6
|
+
*.py[cod]
|
|
7
|
+
*.egg-info/
|
|
8
|
+
dist/
|
|
9
|
+
build/
|
|
10
|
+
|
|
11
|
+
# Environment
|
|
12
|
+
.env
|
|
13
|
+
|
|
14
|
+
# Coverage
|
|
15
|
+
htmlcov/
|
|
16
|
+
.coverage
|
|
17
|
+
.coverage.*
|
|
18
|
+
|
|
19
|
+
# IDE
|
|
20
|
+
.claude/
|
|
21
|
+
!.claude/commands/
|
|
22
|
+
|
|
23
|
+
# Specs
|
|
24
|
+
specs/
|
|
25
|
+
|
|
26
|
+
# OS
|
|
27
|
+
.DS_Store
|
|
28
|
+
|
|
29
|
+
# Logs & sqlite3
|
|
30
|
+
logs/
|
|
31
|
+
*.db
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.13
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [0.4.0] - 2026-03-01
|
|
4
|
+
- **changed**: Rebranded from "tether" to "leashd" — package name, env var prefix (`LEASHD_*`), config dir (`.leashd/`), all imports, CLI entry point, and documentation
|
|
5
|
+
- **added**: Apache 2.0 license
|
|
6
|
+
- **added**: PyPI package metadata (classifiers, URLs, keywords, `py.typed` marker)
|
|
7
|
+
- **added**: `/workspace` (alias `/ws`) — group related repos under named workspaces for multi-repo context. YAML config in `.leashd/workspaces.yaml`, inline keyboard buttons, and workspace-aware system prompt injection
|
|
8
|
+
- **added**: Behavioral integration tests for plan approval flow — verify Write/Edit actually succeed after clean_edit, edit, and default approvals (closes coverage gap that let `_cancel_agent()` deletion slip through)
|
|
9
|
+
- **fixed**: `_SafeSDKClient` now handles SDK returning `None` for unknown message types (compatibility with claude-agent-sdk 0.1.44+)
|
|
10
|
+
|
|
11
|
+
## [0.3.0] - 2026-02-26
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
- `/git merge <branch>` — AI-assisted conflict resolution with auto-resolve/abort buttons and 4-phase merge workflow
|
|
15
|
+
- `/test` command — 9-phase agent-driven test workflow with structured args (`--url`, `--framework`, `--dir`, `--no-e2e`, `--no-unit`, `--no-backend`), project config (`.leashd/test.yaml`), write-ahead crash recovery, and context persistence across sessions
|
|
16
|
+
- `/plan <text>` and `/edit <text>` — switch mode and start agent in one step
|
|
17
|
+
- `/dir` inline keyboard buttons for one-tap directory switching
|
|
18
|
+
- Message interrupt — inline buttons to interrupt or wait during agent execution instead of silent queuing
|
|
19
|
+
- `dev-tools.yaml` policy overlay — auto-allows common dev commands (package managers, linters, test runners)
|
|
20
|
+
- Auto-delete transient messages (interrupt prompts, ack messages, completion notices)
|
|
21
|
+
|
|
22
|
+
### Fixed
|
|
23
|
+
- Git callback buttons now auto-delete after action completes instead of persisting as stale UI
|
|
24
|
+
- Plan approval messages (content + buttons) now fully cleaned up after user decision, with brief ack for proceed actions
|
|
25
|
+
- **fixed**: Comprehensive edge case tests for git callback and plan approval cleanup (8 tests: exception resilience, non-Message guards, missing handlers, empty/missing plan IDs, dedup, ack failures, expired interactions)
|
|
26
|
+
- Agent resilience — exponential backoff on retries, auto-retry for transient API errors, 30-minute execution timeout, human-readable error messages
|
|
27
|
+
- Session continuity — `claude_session_id` persisted on agent timeout so next message resumes
|
|
28
|
+
- Pending messages no longer dropped on transient errors
|
|
29
|
+
- Playwright MCP tools now available when agent works in repos without their own `.mcp.json`
|
|
30
|
+
- **fixed**: Documentation audit — 30+ discrepancies corrected across README, config, plugins, engine, architecture, events, storage, and index docs (wrong defaults, missing features, stale counts, version mismatch)
|
|
31
|
+
|
|
32
|
+
## [0.2.1] - 2026-02-23
|
|
33
|
+
- **added**: Network resilience for Telegram connector — exponential-backoff retries on `NetworkError`/`TimedOut` for startup and send operations
|
|
34
|
+
- **fixed**: Streaming freezes on long responses — overflow now finalizes current message and chains into a new one instead of silently truncating at 4000 chars
|
|
35
|
+
- **fixed**: Sub-agent permission inheritance — map session modes to SDK `PermissionMode` so Task-spawned sub-agents can write/edit files in auto mode
|
|
36
|
+
- **added**: 3-word approval keys — `uv run pytest` and `uv run python` now get distinct auto-approve keys instead of both being `Bash::uv run`
|
|
37
|
+
- **added**: CD prefix stripping — `cd /project && git status` now matches `^git` policy patterns and produces `Bash::git status` approval keys instead of `Bash::cd`
|
|
38
|
+
- **added**: Hierarchical auto-approve matching — stored `Bash::uv run` covers `Bash::uv run pytest` with word-boundary safety
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
## [0.2.0] - 2026-02-23
|
|
42
|
+
|
|
43
|
+
### Added
|
|
44
|
+
- **Git integration** — full `/git` command suite accessible from Telegram with inline action buttons
|
|
45
|
+
- `status`, `branch`, `checkout`, `diff`, `log`, `add`, `commit`, `push`, `pull`
|
|
46
|
+
- Auto-generated commit messages from staged changes
|
|
47
|
+
- Fuzzy branch matching with fallback to remote tracking
|
|
48
|
+
- Interactive workflows: stage files, confirm pushes, enter commit messages via chat
|
|
49
|
+
- **Git service layer** (`leashd/git/service.py`) — async wrapper around git CLI with 30s timeout, input validation against shell injection
|
|
50
|
+
- **Git data models** (`leashd/git/models.py`) — frozen Pydantic models for status, branches, log entries, and results
|
|
51
|
+
- **Git display formatters** (`leashd/git/formatter.py`) — Telegram-friendly formatting with emoji indicators and 4096-char truncation
|
|
52
|
+
- **Git callback routing** — inline button support in Telegram connector for git operations
|
|
53
|
+
- **Audit logging for git operations** — every git command logged with session context and working directory
|
|
54
|
+
|
|
55
|
+
### Changed
|
|
56
|
+
- **Engine** wired to route `/git` commands and git button callbacks to the new handler
|
|
57
|
+
- **App bootstrap** instantiates `GitService` and `GitCommandHandler` during startup
|
|
58
|
+
- **Connector base protocol** extended with `set_git_handler()` for registering git callbacks
|
|
59
|
+
- **Telegram connector** routes `git:` prefix callbacks to the git handler
|
|
60
|
+
|
|
61
|
+
## [0.1.0] - 2026-02-22
|
|
62
|
+
|
|
63
|
+
- Initial release
|
leashd-0.4.0/CLAUDE.md
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## Project Overview
|
|
6
|
+
|
|
7
|
+
leashd is a remote AI-assisted development system with safety constraints. It lets developers drive Claude Code agent sessions from any device (e.g., phone via Telegram) while enforcing YAML-driven safety policies that gate dangerous AI actions behind human approval.
|
|
8
|
+
|
|
9
|
+
## Commands
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
# Install dependencies
|
|
13
|
+
uv sync
|
|
14
|
+
|
|
15
|
+
# Run the CLI
|
|
16
|
+
uv run -m leashd
|
|
17
|
+
|
|
18
|
+
# Run all tests
|
|
19
|
+
uv run pytest tests/
|
|
20
|
+
|
|
21
|
+
# Run a single test file
|
|
22
|
+
uv run pytest tests/test_policy.py -v
|
|
23
|
+
|
|
24
|
+
# Run a specific test
|
|
25
|
+
uv run pytest tests/test_policy.py::test_function_name -v
|
|
26
|
+
|
|
27
|
+
# Run tests with coverage
|
|
28
|
+
uv run pytest --cov=leashd tests/
|
|
29
|
+
|
|
30
|
+
# Lint
|
|
31
|
+
uv run ruff check .
|
|
32
|
+
|
|
33
|
+
# Lint and auto-fix (removes unused imports, sorts imports, etc.)
|
|
34
|
+
uv run ruff check --fix .
|
|
35
|
+
|
|
36
|
+
# Format
|
|
37
|
+
uv run ruff format .
|
|
38
|
+
|
|
39
|
+
# Lint fix + format (equivalent to VS Code save)
|
|
40
|
+
uv run ruff check --fix . && uv run ruff format .
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Architecture
|
|
44
|
+
|
|
45
|
+
The system follows a three-layer safety pipeline: **Sandbox → Policy → Approval**.
|
|
46
|
+
|
|
47
|
+
**Bootstrap** (`app.py`) wires all subsystems together: builds config, storage, connectors, middleware, plugins, safety pipeline, git handler, and engine. Entry point is `main.py` → `app.py`.
|
|
48
|
+
|
|
49
|
+
**Engine** (`core/engine.py`) is the central orchestrator. It receives user messages from connectors, passes them through the middleware chain, routes messages to the Claude Code agent, and sends responses back through connectors. Supports `/dir`, `/plan <text>`, `/edit <text>`, `/git`, and `/workspace` (alias `/ws`) commands.
|
|
50
|
+
|
|
51
|
+
**Safety pipeline** (all in `core/safety/`):
|
|
52
|
+
0. **Gatekeeper** (`gatekeeper.py`) — `ToolGatekeeper` orchestrates the full sandbox → policy → approval chain per tool call, emitting events at each stage. Extracted from Engine to keep it focused on message routing.
|
|
53
|
+
1. **Sandbox** (`sandbox.py`) — enforces directory boundaries, prevents path traversal
|
|
54
|
+
2. **Policy** (`policy.py`) — stateless YAML rule matching that classifies tool calls as ALLOW, DENY, or REQUIRE_APPROVAL based on tool name, command patterns, and path patterns
|
|
55
|
+
3. **Approvals** (`approvals.py`) — async human-in-the-loop approval via connectors with configurable timeout (defaults to deny)
|
|
56
|
+
4. **Analyzer** (`analyzer.py`) — detects risky bash patterns and credential file access, used by the policy engine
|
|
57
|
+
5. **Audit** (`audit.py`) — append-only JSONL log of all tool attempts and decisions
|
|
58
|
+
|
|
59
|
+
**Middleware** (`middleware/`): `MiddlewareChain` processes messages before they reach the Engine. Each middleware can pass through or short-circuit.
|
|
60
|
+
- `AuthMiddleware` — user whitelist via `LEASHD_ALLOWED_USER_IDS`
|
|
61
|
+
- `RateLimitMiddleware` — token-bucket rate limiting per user via `LEASHD_RATE_LIMIT_RPM`
|
|
62
|
+
|
|
63
|
+
**EventBus** (`core/events.py`): Pub/sub system for decoupling subsystems. Plugins and internal components subscribe to named events. Key events: `tool.gated`, `tool.allowed`, `tool.denied`, `message.in`, `message.out`, `approval.requested`, `approval.resolved`, `safety.violation`, `engine.started`, `engine.stopped`, `command.test`, `test.started`, `test.completed`, `command.merge`, `merge.started`, `merge.completed`, `interaction.requested`, `interaction.resolved`, `message.queued`, `execution.interrupted`.
|
|
64
|
+
|
|
65
|
+
**Plugin system** (`plugins/`):
|
|
66
|
+
- `LeashdPlugin` ABC with lifecycle hooks: `initialize → start → stop`
|
|
67
|
+
- `PluginRegistry` for explicit registration (no auto-discovery)
|
|
68
|
+
- Plugins receive a `PluginContext` (event bus + config) and subscribe to `EventBus` events in `initialize()`
|
|
69
|
+
- Built-in: `AuditPlugin` logs sandbox violations from `tool.denied` events
|
|
70
|
+
- Built-in: `BrowserToolsPlugin` provides structured logging for the 28 Playwright MCP browser tools (classifies as readonly vs mutation, logs gated/allowed/denied events)
|
|
71
|
+
- Built-in: `TestRunnerPlugin` activates 9-phase test workflow via `/test` command, auto-approves browser tools and test commands
|
|
72
|
+
- Built-in: `MergeResolverPlugin` handles `/git merge` conflict resolution, auto-approves Edit/Write/Read and git read commands
|
|
73
|
+
- Built-in: `TestConfigLoaderPlugin` loads per-project test configuration from `.leashd/test.yaml` to customize the `/test` workflow
|
|
74
|
+
|
|
75
|
+
**Interactions** (`core/interactions.py`): `InteractionCoordinator` bridges Claude's `AskUserQuestion` and `ExitPlanMode` SDK events to connectors — forwards questions/plan reviews to Telegram, collects user responses, and returns them to the agent.
|
|
76
|
+
|
|
77
|
+
**Session management** (`core/session.py`): `SessionManager` handles session lifecycle — creation, lookup by user+chat pair, working directory switching, and delegation to the storage backend.
|
|
78
|
+
|
|
79
|
+
**Workspaces** (`core/workspace.py`): Groups related repos under a named workspace so the agent gets multi-repo context. `Workspace` is a frozen Pydantic model; `load_workspaces()` reads `.leashd/workspaces.yaml`, validates dirs against `LEASHD_APPROVED_DIRECTORIES`. `/workspace` (alias `/ws`) command activates a workspace — sets cwd to primary dir, injects multi-repo context into system prompt. MCP servers are **not** copied from workspace directories; the agent only uses MCP from the working directory and LeashdConfig.
|
|
80
|
+
|
|
81
|
+
**Git integration** (`git/`): Full `/git` command suite accessible from Telegram with inline action buttons.
|
|
82
|
+
- `GitService` (`service.py`) — async wrapper around git CLI with 30s timeout and input validation
|
|
83
|
+
- `GitCommandHandler` (`handler.py`) — routes `/git` subcommands (status, branch, checkout, diff, log, add, commit, push, pull, merge) and callback buttons
|
|
84
|
+
- `GitFormatter` (`formatter.py`) — Telegram-friendly display with emoji indicators and 4096-char truncation
|
|
85
|
+
- `GitModels` (`models.py`) — frozen Pydantic models for status, branches, log entries, and results
|
|
86
|
+
|
|
87
|
+
**Agent abstraction** (`agents/`): `BaseAgent` protocol with `ClaudeCodeAgent` implementation wrapping `claude-agent-sdk`. Supports session resume for multi-turn continuity.
|
|
88
|
+
|
|
89
|
+
**Connector protocol** (`connectors/base.py`): Abstract interface for I/O transports (Telegram, Slack, etc.). Handles message delivery, typing indicators, approval requests, and file sending.
|
|
90
|
+
|
|
91
|
+
**Policies** (`policies/`): Four built-in YAML policies — `default.yaml` (balanced), `strict.yaml` (maximum restrictions, shorter timeout), `permissive.yaml` (maximum freedom for trusted environments), `dev-tools.yaml` (overlay that auto-allows common dev commands like package managers, linters, test runners — meant to be combined with other policies). All deny credential file access and destructive patterns.
|
|
92
|
+
|
|
93
|
+
**Configuration** (`core/config.py`): `LeashdConfig` uses pydantic-settings, loaded from environment variables prefixed with `LEASHD_`. Required: `LEASHD_APPROVED_DIRECTORIES` (comma-separated paths). `build_directory_names()` derives short names from basenames for the `/dir` command.
|
|
94
|
+
|
|
95
|
+
**Storage** (`storage/`): `SessionStore` ABC with two backends — `MemorySessionStore` (in-process dict) and `SqliteSessionStore` (persistent via aiosqlite). Sessions are keyed by user+chat pair.
|
|
96
|
+
|
|
97
|
+
## Browser Testing (Playwright MCP)
|
|
98
|
+
|
|
99
|
+
leashd integrates with Playwright MCP for browser automation. The `.mcp.json` at project root configures Claude Code to spawn the MCP server (pinned `@playwright/mcp@0.0.41`, headed mode by default). leashd's Python process does not touch Playwright — Claude Code's SDK manages the MCP server lifecycle.
|
|
100
|
+
|
|
101
|
+
- **Prerequisites:** Node.js 18+, one-time `npx playwright install chromium`
|
|
102
|
+
- **28 browser tools** (7 readonly, 21 mutation) flow through the existing safety pipeline — policy rules are defined in all three YAML presets (`default.yaml`, `strict.yaml`, `permissive.yaml`)
|
|
103
|
+
- **`BrowserToolsPlugin`** (`plugins/builtin/browser_tools.py`) provides structured logging; exports `BROWSER_READONLY_TOOLS`, `BROWSER_MUTATION_TOOLS`, `ALL_BROWSER_TOOLS`, `is_browser_tool()`
|
|
104
|
+
- **Playwright test agents:** `npx playwright init-agents --loop=claude` initializes Planner, Generator, and Healer agents
|
|
105
|
+
- **`/healer` slash command** at `.claude/commands/healer.md` runs the healer agent workflow to find and fix broken Playwright tests
|
|
106
|
+
- **`/test` command** activates 9-phase test workflow via `TestRunnerPlugin` (`plugins/builtin/test_runner.py`) — auto-approves all browser tools, test bash commands, and file writes. Accepts `--url`, `--server`, `--framework`, `--dir`, `--unit`, `--backend`, `--no-e2e`, `--no-unit`, `--no-backend` flags.
|
|
107
|
+
- **Setup guide:** `docs/testing-setup.md` covers how to configure target repos for e2e testing (three tiers: zero-config, Playwright Test framework, AI agents)
|
|
108
|
+
|
|
109
|
+
## Code Conventions
|
|
110
|
+
|
|
111
|
+
- Python 3.13+ required
|
|
112
|
+
- **Always use `uv run` for all Python commands** — never use `python3`, `python`, or `python3 -m`. Examples: `uv run pytest`, `uv run ruff`, `uv run mypy`, `uv run leashd`
|
|
113
|
+
- Async-first: all agent/connector operations use asyncio
|
|
114
|
+
- Ruff for linting and formatting (88-char line length, rules: E, F, I, N, W, UP, B, SIM, RUF, S, C4, PT, RET, ARG)
|
|
115
|
+
- Pydantic models for data validation, pydantic-settings for configuration
|
|
116
|
+
- structlog for structured logging — keyword args only, no string interpolation in log messages
|
|
117
|
+
- Protocol classes (`BaseAgent`, `BaseConnector`) define extensibility points
|
|
118
|
+
- Custom exception hierarchy in `exceptions.py`: `ConfigError`, `AgentError`, `SafetyError`, `ApprovalTimeoutError`, `SessionError`, `StorageError`, `PluginError`
|
|
119
|
+
- Tests use `pytest-asyncio` with `asyncio_mode = "auto"`; coverage minimum: 89% (`fail_under = 89`)
|
|
120
|
+
- No `__init__.py` or other boilerplate junk files — use implicit namespace packages
|
|
121
|
+
- No redundant or obvious comments — only comment non-obvious logic
|
|
122
|
+
- Only use `from __future__ import annotations` when necessary (e.g., forward references needed at runtime by Pydantic models)
|
|
123
|
+
- `TYPE_CHECKING` blocks to break circular imports — runtime imports only what's needed
|
|
124
|
+
- Modern union syntax: `X | None` not `Optional[X]`, `X | Y` not `Union[X, Y]`
|
|
125
|
+
- Composition over inheritance; prefer small collaborating objects
|
|
126
|
+
- Flat over nested: early returns, extract before exceeding 2 indentation levels
|
|
127
|
+
- `_` prefix for internal APIs, no `__` name mangling
|
|
128
|
+
- YAGNI: don't build for speculative future requirements
|
|
129
|
+
- Rule of Three: don't abstract until third duplication
|
|
130
|
+
- Test behavior, not implementation details
|
|
131
|
+
|
|
132
|
+
## Logging & Observability
|
|
133
|
+
|
|
134
|
+
leashd produces three data surfaces per project, all under `{project}/.leashd/`:
|
|
135
|
+
|
|
136
|
+
| Surface | Path | Format | Purpose |
|
|
137
|
+
|---------|------|--------|---------|
|
|
138
|
+
| App logs | `logs/app.log` | JSON lines (rotating, 10 MB × 5 backups) | Structured application events from structlog |
|
|
139
|
+
| Audit log | `audit.jsonl` | JSON lines (append-only) | Tool-gating decisions, approvals, security violations |
|
|
140
|
+
| Message store | `messages.db` | SQLite | Conversation history (user/assistant messages, cost, duration) |
|
|
141
|
+
|
|
142
|
+
Session metadata lives in a separate fixed-location store at `{leashd_root}/.leashd/sessions.db`.
|
|
143
|
+
|
|
144
|
+
**Context variable auto-propagation** (`core/engine.py`): The engine binds `request_id`, `chat_id`, and `session_id` to structlog contextvars at the start of each turn. These fields automatically appear in every log entry during that turn without explicit passing. `request_id` is ephemeral (8-char hex, fresh per turn); `session_id` persists across the conversation.
|
|
145
|
+
|
|
146
|
+
**Correlation keys across surfaces**:
|
|
147
|
+
- `session_id` — present in all three surfaces; primary join key
|
|
148
|
+
- `request_id` — app logs only; isolates a single turn's log entries
|
|
149
|
+
- `user_id` + `chat_id` — session store, message store, and app logs
|
|
150
|
+
- `working_directory` — links session store to the correct project's per-project files
|
|
151
|
+
|
|
152
|
+
**Logging env vars**: `LEASHD_LOG_LEVEL` (default `INFO`), `LEASHD_LOG_DIR` (default `.leashd/logs`), `LEASHD_LOG_MAX_BYTES` (default 10 MB), `LEASHD_LOG_BACKUP_COUNT` (default 5), `LEASHD_AUDIT_LOG_PATH` (default `.leashd/audit.jsonl`).
|
|
153
|
+
|
|
154
|
+
## Changelog
|
|
155
|
+
|
|
156
|
+
After completing each feature, bug fix, or notable change, add a concise entry to `CHANGELOG.md` under the **current (latest) version heading**. All new entries accumulate under that version until a new version is explicitly introduced (e.g., bumping from `0.2.1` to `0.2.2` or `0.3.0`).
|
|
157
|
+
|
|
158
|
+
```markdown
|
|
159
|
+
## [0.3.0] - 2026-02-26
|
|
160
|
+
- **category**: Short description of what changed
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
Categories: `added`, `fixed`, `changed`, `removed`. Keep entries to one line each. Do not create a new version heading — append to the existing one.
|
leashd-0.4.0/LICENSE
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding any notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2025 NodeNova
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|