switchplane 0.1.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.
Potentially problematic release.
This version of switchplane might be problematic. Click here for more details.
- switchplane-0.1.0/.github/labeler.yml +21 -0
- switchplane-0.1.0/.github/release.yml +20 -0
- switchplane-0.1.0/.github/workflows/ci.yml +45 -0
- switchplane-0.1.0/.github/workflows/labeler.yml +16 -0
- switchplane-0.1.0/.github/workflows/publish.yml +66 -0
- switchplane-0.1.0/.gitignore +31 -0
- switchplane-0.1.0/CLAUDE.md +150 -0
- switchplane-0.1.0/CODEOWNERS +3 -0
- switchplane-0.1.0/CODE_OF_CONDUCT.md +105 -0
- switchplane-0.1.0/CONTRIBUTING.md +83 -0
- switchplane-0.1.0/LICENSE +191 -0
- switchplane-0.1.0/Makefile +33 -0
- switchplane-0.1.0/PKG-INFO +802 -0
- switchplane-0.1.0/README.md +766 -0
- switchplane-0.1.0/SECURITY.md +7 -0
- switchplane-0.1.0/TODO.md +45 -0
- switchplane-0.1.0/examples/chatbot/chatbot/__init__.py +0 -0
- switchplane-0.1.0/examples/chatbot/chatbot/agents/__init__.py +0 -0
- switchplane-0.1.0/examples/chatbot/chatbot/agents/bot/__init__.py +0 -0
- switchplane-0.1.0/examples/chatbot/chatbot/agents/bot/agent.py +3 -0
- switchplane-0.1.0/examples/chatbot/chatbot/agents/bot/tasks/__init__.py +0 -0
- switchplane-0.1.0/examples/chatbot/chatbot/agents/bot/tasks/chat.py +83 -0
- switchplane-0.1.0/examples/chatbot/chatbot/app.py +10 -0
- switchplane-0.1.0/examples/chatbot/chatbot/config.toml +3 -0
- switchplane-0.1.0/examples/chatbot/pyproject.toml +21 -0
- switchplane-0.1.0/examples/devops/devops/__init__.py +0 -0
- switchplane-0.1.0/examples/devops/devops/agents/__init__.py +0 -0
- switchplane-0.1.0/examples/devops/devops/agents/sre/__init__.py +0 -0
- switchplane-0.1.0/examples/devops/devops/agents/sre/agent.py +5 -0
- switchplane-0.1.0/examples/devops/devops/agents/sre/tasks/__init__.py +0 -0
- switchplane-0.1.0/examples/devops/devops/agents/sre/tasks/review.py +446 -0
- switchplane-0.1.0/examples/devops/devops/app.py +10 -0
- switchplane-0.1.0/examples/devops/devops/config.toml +2 -0
- switchplane-0.1.0/examples/devops/pyproject.toml +22 -0
- switchplane-0.1.0/examples/hello/hello/__init__.py +0 -0
- switchplane-0.1.0/examples/hello/hello/agents/__init__.py +0 -0
- switchplane-0.1.0/examples/hello/hello/agents/example/__init__.py +0 -0
- switchplane-0.1.0/examples/hello/hello/agents/example/agent.py +5 -0
- switchplane-0.1.0/examples/hello/hello/agents/example/tasks/__init__.py +0 -0
- switchplane-0.1.0/examples/hello/hello/agents/example/tasks/hello.py +80 -0
- switchplane-0.1.0/examples/hello/hello/app.py +8 -0
- switchplane-0.1.0/examples/hello/pyproject.toml +14 -0
- switchplane-0.1.0/examples/weather/pyproject.toml +15 -0
- switchplane-0.1.0/examples/weather/weather/__init__.py +0 -0
- switchplane-0.1.0/examples/weather/weather/agents/__init__.py +0 -0
- switchplane-0.1.0/examples/weather/weather/agents/weather/__init__.py +0 -0
- switchplane-0.1.0/examples/weather/weather/agents/weather/agent.py +5 -0
- switchplane-0.1.0/examples/weather/weather/agents/weather/tasks/__init__.py +0 -0
- switchplane-0.1.0/examples/weather/weather/agents/weather/tasks/watch.py +264 -0
- switchplane-0.1.0/examples/weather/weather/app.py +8 -0
- switchplane-0.1.0/pyproject.toml +78 -0
- switchplane-0.1.0/src/switchplane/__init__.py +12 -0
- switchplane-0.1.0/src/switchplane/__main__.py +4 -0
- switchplane-0.1.0/src/switchplane/_util.py +36 -0
- switchplane-0.1.0/src/switchplane/agent.py +46 -0
- switchplane-0.1.0/src/switchplane/agent_runtime.py +555 -0
- switchplane-0.1.0/src/switchplane/app.py +157 -0
- switchplane-0.1.0/src/switchplane/checkpoint.py +365 -0
- switchplane-0.1.0/src/switchplane/cli.py +596 -0
- switchplane-0.1.0/src/switchplane/config.py +83 -0
- switchplane-0.1.0/src/switchplane/control_plane.py +643 -0
- switchplane-0.1.0/src/switchplane/daemon.py +350 -0
- switchplane-0.1.0/src/switchplane/discovery.py +155 -0
- switchplane-0.1.0/src/switchplane/fmt.py +132 -0
- switchplane-0.1.0/src/switchplane/llm.py +96 -0
- switchplane-0.1.0/src/switchplane/logging.py +103 -0
- switchplane-0.1.0/src/switchplane/mcp.py +305 -0
- switchplane-0.1.0/src/switchplane/oauth.py +465 -0
- switchplane-0.1.0/src/switchplane/persistence.py +498 -0
- switchplane-0.1.0/src/switchplane/protocol.py +73 -0
- switchplane-0.1.0/src/switchplane/shell.py +386 -0
- switchplane-0.1.0/src/switchplane/subprocess_manager.py +425 -0
- switchplane-0.1.0/src/switchplane/task.py +204 -0
- switchplane-0.1.0/src/switchplane/transport.py +234 -0
- switchplane-0.1.0/src/switchplane/tui.py +1380 -0
- switchplane-0.1.0/tests/__init__.py +0 -0
- switchplane-0.1.0/tests/conftest.py +62 -0
- switchplane-0.1.0/tests/test_agent.py +69 -0
- switchplane-0.1.0/tests/test_agent_runtime.py +505 -0
- switchplane-0.1.0/tests/test_app.py +104 -0
- switchplane-0.1.0/tests/test_checkpoint.py +214 -0
- switchplane-0.1.0/tests/test_cli.py +591 -0
- switchplane-0.1.0/tests/test_config.py +97 -0
- switchplane-0.1.0/tests/test_control_plane.py +374 -0
- switchplane-0.1.0/tests/test_daemon.py +92 -0
- switchplane-0.1.0/tests/test_discovery.py +162 -0
- switchplane-0.1.0/tests/test_llm.py +294 -0
- switchplane-0.1.0/tests/test_mcp.py +363 -0
- switchplane-0.1.0/tests/test_persistence.py +320 -0
- switchplane-0.1.0/tests/test_protocol.py +137 -0
- switchplane-0.1.0/tests/test_shell.py +260 -0
- switchplane-0.1.0/tests/test_subprocess_manager.py +693 -0
- switchplane-0.1.0/tests/test_task.py +290 -0
- switchplane-0.1.0/tests/test_transport.py +195 -0
- switchplane-0.1.0/tests/test_tui.py +1501 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
feature:
|
|
2
|
+
- head-branch: ['^feat/', '^feature/']
|
|
3
|
+
|
|
4
|
+
bug:
|
|
5
|
+
- head-branch: ['^fix/', '^bug/']
|
|
6
|
+
|
|
7
|
+
docs:
|
|
8
|
+
- changed-files:
|
|
9
|
+
- any-glob-to-any-file: ['docs/**', '*.md']
|
|
10
|
+
|
|
11
|
+
tests:
|
|
12
|
+
- changed-files:
|
|
13
|
+
- any-glob-to-any-file: ['tests/**']
|
|
14
|
+
|
|
15
|
+
ci:
|
|
16
|
+
- changed-files:
|
|
17
|
+
- any-glob-to-any-file: ['.github/**']
|
|
18
|
+
|
|
19
|
+
examples:
|
|
20
|
+
- changed-files:
|
|
21
|
+
- any-glob-to-any-file: ['examples/**']
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
changelog:
|
|
2
|
+
exclude:
|
|
3
|
+
labels:
|
|
4
|
+
- skip-changelog
|
|
5
|
+
categories:
|
|
6
|
+
- title: Breaking Changes
|
|
7
|
+
labels:
|
|
8
|
+
- breaking
|
|
9
|
+
- title: Features
|
|
10
|
+
labels:
|
|
11
|
+
- feature
|
|
12
|
+
- title: Bug Fixes
|
|
13
|
+
labels:
|
|
14
|
+
- bug
|
|
15
|
+
- title: Documentation
|
|
16
|
+
labels:
|
|
17
|
+
- docs
|
|
18
|
+
- title: Other Changes
|
|
19
|
+
labels:
|
|
20
|
+
- "*"
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
lint:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
steps:
|
|
13
|
+
- uses: actions/checkout@v4
|
|
14
|
+
- uses: astral-sh/setup-uv@v5
|
|
15
|
+
- name: Install dependencies
|
|
16
|
+
run: |
|
|
17
|
+
uv venv
|
|
18
|
+
make install-test
|
|
19
|
+
- name: Check formatting
|
|
20
|
+
run: make formatcheck
|
|
21
|
+
- name: Check linting
|
|
22
|
+
run: make static
|
|
23
|
+
|
|
24
|
+
test:
|
|
25
|
+
runs-on: ubuntu-latest
|
|
26
|
+
strategy:
|
|
27
|
+
fail-fast: false
|
|
28
|
+
matrix:
|
|
29
|
+
python-version: ["3.12", "3.13", "3.14"]
|
|
30
|
+
|
|
31
|
+
steps:
|
|
32
|
+
- uses: actions/checkout@v4
|
|
33
|
+
|
|
34
|
+
- uses: astral-sh/setup-uv@v5
|
|
35
|
+
|
|
36
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
37
|
+
run: uv python install ${{ matrix.python-version }}
|
|
38
|
+
|
|
39
|
+
- name: Install dependencies
|
|
40
|
+
run: |
|
|
41
|
+
uv venv --python ${{ matrix.python-version }}
|
|
42
|
+
make install-test
|
|
43
|
+
|
|
44
|
+
- name: Run tests
|
|
45
|
+
run: make test
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
name: Labeler
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
types: [opened, synchronize, reopened]
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
label:
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
permissions:
|
|
11
|
+
contents: read
|
|
12
|
+
pull-requests: write
|
|
13
|
+
steps:
|
|
14
|
+
- uses: actions/labeler@v5
|
|
15
|
+
with:
|
|
16
|
+
configuration-path: .github/labeler.yml
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
|
|
7
|
+
permissions:
|
|
8
|
+
contents: read
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
validate:
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
steps:
|
|
14
|
+
- uses: actions/checkout@v4
|
|
15
|
+
- name: Check version matches tag
|
|
16
|
+
run: |
|
|
17
|
+
TAG="${GITHUB_REF#refs/tags/v}"
|
|
18
|
+
PKG_VERSION=$(python3 -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])")
|
|
19
|
+
if [ "$TAG" != "$PKG_VERSION" ]; then
|
|
20
|
+
echo "::error::Tag v${TAG} does not match package version ${PKG_VERSION}"
|
|
21
|
+
exit 1
|
|
22
|
+
fi
|
|
23
|
+
|
|
24
|
+
test:
|
|
25
|
+
runs-on: ubuntu-latest
|
|
26
|
+
strategy:
|
|
27
|
+
fail-fast: true
|
|
28
|
+
matrix:
|
|
29
|
+
python-version: ["3.12", "3.13", "3.14"]
|
|
30
|
+
steps:
|
|
31
|
+
- uses: actions/checkout@v4
|
|
32
|
+
- uses: astral-sh/setup-uv@v5
|
|
33
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
34
|
+
run: uv python install ${{ matrix.python-version }}
|
|
35
|
+
- name: Install dependencies
|
|
36
|
+
run: |
|
|
37
|
+
uv venv --python ${{ matrix.python-version }}
|
|
38
|
+
make install-test
|
|
39
|
+
- name: Run tests
|
|
40
|
+
run: make test
|
|
41
|
+
|
|
42
|
+
build:
|
|
43
|
+
needs: [validate, test]
|
|
44
|
+
runs-on: ubuntu-latest
|
|
45
|
+
steps:
|
|
46
|
+
- uses: actions/checkout@v4
|
|
47
|
+
- uses: astral-sh/setup-uv@v5
|
|
48
|
+
- name: Build package
|
|
49
|
+
run: uv build
|
|
50
|
+
- uses: actions/upload-artifact@v4
|
|
51
|
+
with:
|
|
52
|
+
name: dist
|
|
53
|
+
path: dist/
|
|
54
|
+
|
|
55
|
+
publish:
|
|
56
|
+
needs: build
|
|
57
|
+
runs-on: ubuntu-latest
|
|
58
|
+
environment: pypi
|
|
59
|
+
permissions:
|
|
60
|
+
id-token: write
|
|
61
|
+
steps:
|
|
62
|
+
- uses: actions/download-artifact@v4
|
|
63
|
+
with:
|
|
64
|
+
name: dist
|
|
65
|
+
path: dist/
|
|
66
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*.egg-info/
|
|
5
|
+
*.egg
|
|
6
|
+
dist/
|
|
7
|
+
build/
|
|
8
|
+
|
|
9
|
+
# Virtual environment
|
|
10
|
+
.venv/
|
|
11
|
+
|
|
12
|
+
# uv
|
|
13
|
+
uv.lock
|
|
14
|
+
|
|
15
|
+
# IDE
|
|
16
|
+
.idea/
|
|
17
|
+
.vscode/
|
|
18
|
+
*.swp
|
|
19
|
+
*.swo
|
|
20
|
+
|
|
21
|
+
# OS
|
|
22
|
+
.DS_Store
|
|
23
|
+
|
|
24
|
+
# Switchplane runtime
|
|
25
|
+
*.db
|
|
26
|
+
*.sock
|
|
27
|
+
*.pid
|
|
28
|
+
|
|
29
|
+
# testing
|
|
30
|
+
.tmp/*
|
|
31
|
+
.coverage
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
# CLAUDE.md — Switchplane
|
|
2
|
+
|
|
3
|
+
## What is this project?
|
|
4
|
+
|
|
5
|
+
Switchplane is a Python runtime control plane for agent-based task execution. It is LangGraph-native — tasks are defined as LangGraph StateGraph graphs. Each app built with Switchplane becomes a standalone CLI with its own isolated daemon and runtime directory.
|
|
6
|
+
|
|
7
|
+
## Architecture in one sentence
|
|
8
|
+
|
|
9
|
+
Each app gets its own CLI that sends requests over a Unix socket to a per-app daemonized control plane, which spawns agent subprocesses that communicate bidirectionally over a per-agent Unix socketpair using length-prefixed JSON framing.
|
|
10
|
+
|
|
11
|
+
## Project layout
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
src/switchplane/ # Main package (pip-installable)
|
|
15
|
+
__init__.py # Public API re-exports: Application, Shell, Task, command, Field
|
|
16
|
+
app.py # Application container and McpServerConfig
|
|
17
|
+
shell.py # Sandboxed subprocess execution with path/command allowlists, LangChain tool factory
|
|
18
|
+
agent.py # AgentSpec and AgentRecord models
|
|
19
|
+
task.py # Task ABC, TaskRecord, TaskStatus, @command decorator, parameter introspection
|
|
20
|
+
protocol.py # IPC message types: CliRequest/Response, AgentEvent/Command
|
|
21
|
+
transport.py # Unix socket server (async) + client (sync), 4-byte length-prefixed framing
|
|
22
|
+
persistence.py # SQLite Store (aiosqlite, WAL mode) — tasks, agents, events tables
|
|
23
|
+
checkpoint.py # LangGraph BaseCheckpointSaver backed by SQLite
|
|
24
|
+
discovery.py # Agent/task discovery via module import (no entry point discovery)
|
|
25
|
+
daemon.py # Daemonization (double-fork), signal handling, idle timer, RuntimePaths
|
|
26
|
+
control_plane.py # Central orchestrator — request dispatch, single app, idle shutdown
|
|
27
|
+
subprocess_manager.py # Agent subprocess lifecycle — socketpair creation, event reading, command sending
|
|
28
|
+
agent_runtime.py # Runs inside agent subprocess — AgentContext, bidirectional IPC over socketpair
|
|
29
|
+
cli.py # Click CLI factory — build_cli(app) generates run, runtime, agent, task command groups
|
|
30
|
+
tui.py # prompt_toolkit full-screen TUI — tab-based task viewer with system tab [0]
|
|
31
|
+
fmt.py # Shared formatting utilities (e.g. tree rendering for detail payloads)
|
|
32
|
+
config.py # TOML config loading — cascading: app defaults + user overrides
|
|
33
|
+
|
|
34
|
+
mcp.py # MCP client lifecycle: McpSession, McpManager, LangChain tool wrapper
|
|
35
|
+
|
|
36
|
+
examples/hello/ # Simple LangGraph graph (get_user → say_hello)
|
|
37
|
+
examples/weather/ # Long-running polling task (Open-Meteo weather watch, @command for coordinates)
|
|
38
|
+
examples/devops/ # Ops review: deterministic pandas analysis + LLM summary
|
|
39
|
+
examples/chatbot/ # Interactive LLM chat with interrupts
|
|
40
|
+
tests/ # Test directory (pytest)
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Key design rules
|
|
44
|
+
|
|
45
|
+
- **The control plane owns task/event persistence.** Agents write only checkpoint data via a separate WAL-mode connection.
|
|
46
|
+
- **The control plane never runs domain logic.** All user code runs inside agent subprocesses.
|
|
47
|
+
- **Tasks are first-class.** Agents are just execution hosts. Every task has an ID, status, events, and stored results.
|
|
48
|
+
- **LangGraph-native.** Do not introduce generic workflow abstractions. Tasks use LangGraph StateGraph directly.
|
|
49
|
+
- **One app per runtime.** Each Application gets its own daemon, database, and socket.
|
|
50
|
+
|
|
51
|
+
## Application entry point
|
|
52
|
+
|
|
53
|
+
`Application(name="myapp")` creates an app. `app.discover_agents("myapp.agents")` registers discovery roots. `app.run()` discovers agents, builds the CLI, and starts it. The `name` determines the runtime directory (`~/.myapp/`). The CLI entry point is registered via `[project.scripts]` in pyproject.toml.
|
|
54
|
+
|
|
55
|
+
## Configuration
|
|
56
|
+
|
|
57
|
+
Two-layer cascading TOML config. App-bundled defaults (specified via `Application(default_config=Path(...))`) are deep-merged with user-level overrides at `~/.{app_name}/config.toml`. User config wins on conflict. Apps ship base URLs, model defaults, and agent settings; users provide personal config like API keys. Pydantic model: `AppConfig` with `LLMConfig` and per-agent dicts. Config is passed to agent subprocesses via the `execute_task` command payload and available as `ctx.config` in the agent runtime.
|
|
58
|
+
|
|
59
|
+
## How to run
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
# Setup
|
|
63
|
+
uv venv .venv && source .venv/bin/activate
|
|
64
|
+
uv pip install -e . -e examples/hello -e examples/weather -e examples/devops -e examples/chatbot
|
|
65
|
+
|
|
66
|
+
# Run a task (streams events inline, Ctrl+C detaches)
|
|
67
|
+
hello run example hello --name Alice
|
|
68
|
+
|
|
69
|
+
# Run detached
|
|
70
|
+
weather run weather watch -d
|
|
71
|
+
|
|
72
|
+
# Bare app invocation opens the full-screen TUI (auto-discovers running tasks)
|
|
73
|
+
hello
|
|
74
|
+
|
|
75
|
+
# Operator commands
|
|
76
|
+
hello runtime start|stop|status
|
|
77
|
+
hello task list|show|cancel|follow|resume|clear
|
|
78
|
+
hello agent list
|
|
79
|
+
|
|
80
|
+
# Send command to running task
|
|
81
|
+
weather task <task_id> <command> [--key value ...]
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## CLI and TUI
|
|
85
|
+
|
|
86
|
+
**CLI** is always plain-text. `run`, `follow`, and `resume` stream events inline and support interactive command input (stdin reader thread). The TUI is **only** launched on a bare `<app>` call with a TTY. Non-TTY invocations always get plain text.
|
|
87
|
+
|
|
88
|
+
**TUI** (`tui.py`) is a full-screen prompt_toolkit app with tab-based navigation. Tab `[0] system` is always present and receives daemon command output. Task tabs start at `[1]`. The shared arg parser `_parse_kv_args` lives in `tui.py` and is imported by `cli.py`.
|
|
89
|
+
|
|
90
|
+
**Input prefixes** use a three-tier scheme designed to reserve freeform text for future interactive LLM tasks:
|
|
91
|
+
- `:` prefix → daemon commands: `:run`, `:task follow <id>`, `:runtime status`, `:agent list`, `:help`
|
|
92
|
+
- `/` prefix → task commands on the focused task: `/set_location --lat 40.7`
|
|
93
|
+
- Plain text → reserved for future freeform LLM interaction (currently shows a hint)
|
|
94
|
+
|
|
95
|
+
In CLI attached mode (`run`/`follow`/`resume`), only `/` task commands are supported inline. Daemon commands are not available — detach with Ctrl+C and use CLI subcommands directly.
|
|
96
|
+
|
|
97
|
+
**Event buffers** are capped at a configurable `max_buffer_lines` (default 10,000) per tab to bound memory in long-running sessions.
|
|
98
|
+
|
|
99
|
+
## Build system
|
|
100
|
+
|
|
101
|
+
- **uv** for package management
|
|
102
|
+
- **hatchling** build backend
|
|
103
|
+
- No global CLI entry point — each app defines its own via `[project.scripts]`
|
|
104
|
+
- Virtual environment at `.venv/`
|
|
105
|
+
|
|
106
|
+
## Dependencies
|
|
107
|
+
|
|
108
|
+
click, pydantic v2, aiosqlite, langgraph, prompt_toolkit, structlog. Optional: `langchain-core` via `switchplane[llm]`; `mcp` + `langchain-core` via `switchplane[mcp]`. Example-specific: langchain-anthropic (devops, chatbot), httpx (weather), pandas + numpy (devops).
|
|
109
|
+
|
|
110
|
+
## IPC protocols
|
|
111
|
+
|
|
112
|
+
**CLI ↔ Control Plane:** Unix socket at `~/.{app_name}/runtime.sock`. Messages are 4-byte big-endian length prefix + JSON body. Types: `CliRequest` / `CliResponse`.
|
|
113
|
+
|
|
114
|
+
**Agent ↔ Control Plane:** Bidirectional over a per-agent Unix socketpair (`socket.socketpair(AF_UNIX)`). The CP creates the pair, passes one fd to the child via `--ipc-fd` + `pass_fds`. Same 4-byte length-prefixed JSON framing as CLI protocol. CP sends `AgentCommand`, agent sends `AgentEvent`. This allows mid-execution cancel/shutdown — the agent runs a command listener concurrently with task execution. stdout/stderr are freed for normal logging.
|
|
115
|
+
|
|
116
|
+
## Database
|
|
117
|
+
|
|
118
|
+
SQLite at `~/.{app_name}/state.db` with WAL mode. Tables: `agents`, `tasks`, `events`, `checkpoints`, `checkpoint_writes`. Use Pydantic v2 `model_dump_json()` / `model_validate_json()` for JSON columns.
|
|
119
|
+
|
|
120
|
+
## Adding a task
|
|
121
|
+
|
|
122
|
+
1. Create a task module at `<app>/agents/<agent>/tasks/<task>.py`
|
|
123
|
+
2. Subclass `Task` from `switchplane` — set `name`, `description`, and optionally `mode` (`"ephemeral"` or `"long_running"`) class attributes
|
|
124
|
+
3. Declare parameters as class attributes using `Field()` from `switchplane` (re-exported from Pydantic). Parameters are validated before execution and set as instance attributes.
|
|
125
|
+
4. Implement `async def run(self, ctx: AgentContext)` — access params via `self.<param>`, build a LangGraph `StateGraph`, compile, `ainvoke`, then `ctx.complete(result)`
|
|
126
|
+
5. Optionally add `@command`-decorated methods for runtime commands on long-running tasks. Command parameters are typed and auto-coerced.
|
|
127
|
+
6. Discovery auto-registers the task from the `tasks/` subpackage — no need to declare it in `AgentSpec`
|
|
128
|
+
|
|
129
|
+
## MCP integration
|
|
130
|
+
|
|
131
|
+
MCP servers are registered at the app level via `McpServerConfig` (provide `command` for stdio, `url` for HTTP — transport is inferred). Agents declare which servers they need via `AgentSpec.mcp_servers`. The agent runtime manages client lifecycle (spawning stdio processes or connecting to HTTP endpoints) and exposes tools via `ctx.mcp` (raw sessions) and `ctx.mcp_tools()` (LangChain `StructuredTool` wrappers). MCP is an optional dependency: `pip install switchplane[mcp]`.
|
|
132
|
+
|
|
133
|
+
## Checkpoint and resume
|
|
134
|
+
|
|
135
|
+
Tasks opt into checkpointing by passing `ctx.checkpointer` to `graph.compile(checkpointer=ctx.checkpointer)` and using `ctx.task_id` as the LangGraph thread ID. The checkpointer is a `SqliteCheckpointSaver` backed by the app's `state.db` — each agent subprocess opens its own connection in WAL mode. LangGraph saves state after each node; on resume, it finds the existing checkpoint by thread ID and continues from the last completed node.
|
|
136
|
+
|
|
137
|
+
Resume flow: CLI sends `resume_task` request → control plane validates terminal status (failed/cancelled/completed) → resets to PENDING → re-launches with the same task ID. The `task resume <task_id>` CLI command handles this. Tasks that don't use `ctx.checkpointer` run without checkpointing and will re-execute from the beginning on resume.
|
|
138
|
+
|
|
139
|
+
## Testing
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
make test
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Style
|
|
146
|
+
|
|
147
|
+
- Python 3.12+ type annotations (use `X | None` not `Optional[X]`)
|
|
148
|
+
- Pydantic v2 (`model_dump()` not `.dict()`, `model_validate()` not `parse_obj()`)
|
|
149
|
+
- asyncio throughout the control plane; sync only in CLI client and daemon bootstrap
|
|
150
|
+
- Minimal abstractions — prefer direct code over premature generalization
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# Salesforce Open Source Community Code of Conduct
|
|
2
|
+
|
|
3
|
+
## About the Code of Conduct
|
|
4
|
+
|
|
5
|
+
Equality is a core value at Salesforce. We believe a diverse and inclusive
|
|
6
|
+
community fosters innovation and creativity, and are committed to building a
|
|
7
|
+
culture where everyone feels included.
|
|
8
|
+
|
|
9
|
+
Salesforce open-source projects are committed to providing a friendly, safe, and
|
|
10
|
+
welcoming environment for all, regardless of gender identity and expression,
|
|
11
|
+
sexual orientation, disability, physical appearance, body size, ethnicity, nationality,
|
|
12
|
+
race, age, religion, level of experience, education, socioeconomic status, or
|
|
13
|
+
other similar personal characteristics.
|
|
14
|
+
|
|
15
|
+
The goal of this code of conduct is to specify a baseline standard of behavior so
|
|
16
|
+
that people with different social values and communication styles can work
|
|
17
|
+
together effectively, productively, and respectfully in our open source community.
|
|
18
|
+
It also establishes a mechanism for reporting issues and resolving conflicts.
|
|
19
|
+
|
|
20
|
+
All questions and reports of abusive, harassing, or otherwise unacceptable behavior
|
|
21
|
+
in a Salesforce open-source project may be reported by contacting the Salesforce
|
|
22
|
+
Open Source Conduct Committee at ossconduct@salesforce.com.
|
|
23
|
+
|
|
24
|
+
## Our Pledge
|
|
25
|
+
|
|
26
|
+
In the interest of fostering an open and welcoming environment, we as
|
|
27
|
+
contributors and maintainers pledge to making participation in our project and
|
|
28
|
+
our community a harassment-free experience for everyone, regardless of gender
|
|
29
|
+
identity and expression, sexual orientation, disability, physical appearance,
|
|
30
|
+
body size, ethnicity, nationality, race, age, religion, level of experience, education,
|
|
31
|
+
socioeconomic status, or other similar personal characteristics.
|
|
32
|
+
|
|
33
|
+
## Our Standards
|
|
34
|
+
|
|
35
|
+
Examples of behavior that contributes to creating a positive environment
|
|
36
|
+
include:
|
|
37
|
+
|
|
38
|
+
* Using welcoming and inclusive language
|
|
39
|
+
* Being respectful of differing viewpoints and experiences
|
|
40
|
+
* Gracefully accepting constructive criticism
|
|
41
|
+
* Focusing on what is best for the community
|
|
42
|
+
* Showing empathy toward other community members
|
|
43
|
+
|
|
44
|
+
Examples of unacceptable behavior by participants include:
|
|
45
|
+
|
|
46
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
47
|
+
advances
|
|
48
|
+
* Personal attacks, insulting/derogatory comments, or trolling
|
|
49
|
+
* Public or private harassment
|
|
50
|
+
* Publishing, or threatening to publish, others' private information—such as
|
|
51
|
+
a physical or electronic address—without explicit permission
|
|
52
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
53
|
+
professional setting
|
|
54
|
+
* Advocating for or encouraging any of the above behaviors
|
|
55
|
+
|
|
56
|
+
## Our Responsibilities
|
|
57
|
+
|
|
58
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
|
59
|
+
behavior and are expected to take appropriate and fair corrective action in
|
|
60
|
+
response to any instances of unacceptable behavior.
|
|
61
|
+
|
|
62
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
|
63
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
64
|
+
that are not aligned with this Code of Conduct, or to ban temporarily or
|
|
65
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
|
66
|
+
threatening, offensive, or harmful.
|
|
67
|
+
|
|
68
|
+
## Scope
|
|
69
|
+
|
|
70
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
|
71
|
+
when an individual is representing the project or its community. Examples of
|
|
72
|
+
representing a project or community include using an official project email
|
|
73
|
+
address, posting via an official social media account, or acting as an appointed
|
|
74
|
+
representative at an online or offline event. Representation of a project may be
|
|
75
|
+
further defined and clarified by project maintainers.
|
|
76
|
+
|
|
77
|
+
## Enforcement
|
|
78
|
+
|
|
79
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
80
|
+
reported by contacting the Salesforce Open Source Conduct Committee
|
|
81
|
+
at ossconduct@salesforce.com. All complaints will be reviewed and investigated
|
|
82
|
+
and will result in a response that is deemed necessary and appropriate to the
|
|
83
|
+
circumstances. The committee is obligated to maintain confidentiality with
|
|
84
|
+
regard to the reporter of an incident. Further details of specific enforcement
|
|
85
|
+
policies may be posted separately.
|
|
86
|
+
|
|
87
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
88
|
+
faith may face temporary or permanent repercussions as determined by other
|
|
89
|
+
members of the project's leadership and the Salesforce Open Source Conduct
|
|
90
|
+
Committee.
|
|
91
|
+
|
|
92
|
+
## Attribution
|
|
93
|
+
|
|
94
|
+
This Code of Conduct is adapted from the [Contributor Covenant][contributor-covenant-home],
|
|
95
|
+
version 1.4, available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html.
|
|
96
|
+
It includes adaptions and additions from [Go Community Code of Conduct][golang-coc],
|
|
97
|
+
[CNCF Code of Conduct][cncf-coc], and [Microsoft Open Source Code of Conduct][microsoft-coc].
|
|
98
|
+
|
|
99
|
+
This Code of Conduct is licensed under the [Creative Commons Attribution 3.0 License][cc-by-3-us].
|
|
100
|
+
|
|
101
|
+
[contributor-covenant-home]: https://www.contributor-covenant.org (https://www.contributor-covenant.org/)
|
|
102
|
+
[golang-coc]: https://golang.org/conduct
|
|
103
|
+
[cncf-coc]: https://github.com/cncf/foundation/blob/master/code-of-conduct.md
|
|
104
|
+
[microsoft-coc]: https://opensource.microsoft.com/codeofconduct/
|
|
105
|
+
[cc-by-3-us]: https://creativecommons.org/licenses/by/3.0/us/
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# Contributing Guide For switchplane
|
|
2
|
+
|
|
3
|
+
This page lists the operational governance model of this project, as well as the recommendations and requirements for how to best contribute to {PROJECT}. We strive to obey these as best as possible. As always, thanks for contributing – we hope these guidelines make it easier and shed some light on our approach and processes.
|
|
4
|
+
|
|
5
|
+
# Governance Model
|
|
6
|
+
|
|
7
|
+
## Community Based
|
|
8
|
+
|
|
9
|
+
The intent and goal of open sourcing this project is to increase the contributor and user base. The governance model is one where new project leads (`admins`) will be added to the project based on their contributions and efforts, a so-called "do-acracy" or "meritocracy" similar to that used by all Apache Software Foundation projects.
|
|
10
|
+
|
|
11
|
+
# Issues, requests & ideas
|
|
12
|
+
|
|
13
|
+
Use GitHub Issues page to submit issues, enhancement requests and discuss ideas.
|
|
14
|
+
|
|
15
|
+
### Bug Reports and Fixes
|
|
16
|
+
- If you find a bug, please search for it in the [Issues](https://github.com/salesforce-misc/switchplane/issues), and if it isn't already tracked,
|
|
17
|
+
[create a new issue](https://github.com/salesforce-misc/switchplane/issues/new). Fill out the "Bug Report" section of the issue template. Even if an Issue is closed, feel free to comment and add details, it will still
|
|
18
|
+
be reviewed.
|
|
19
|
+
- Issues that have already been identified as a bug (note: able to reproduce) will be labelled `bug`.
|
|
20
|
+
- If you'd like to submit a fix for a bug, [send a Pull Request](#creating_a_pull_request) and mention the Issue number.
|
|
21
|
+
- Include tests that isolate the bug and verifies that it was fixed.
|
|
22
|
+
|
|
23
|
+
### New Features
|
|
24
|
+
- If you'd like to add new functionality to this project, describe the problem you want to solve in a [new Issue](https://github.com/salesforce-misc/switchplane/issues/new).
|
|
25
|
+
- Issues that have been identified as a feature request will be labelled `enhancement`.
|
|
26
|
+
- If you'd like to implement the new feature, please wait for feedback from the project
|
|
27
|
+
maintainers before spending too much time writing the code. In some cases, `enhancement`s may
|
|
28
|
+
not align well with the project objectives at the time.
|
|
29
|
+
|
|
30
|
+
### Tests, Documentation, Miscellaneous
|
|
31
|
+
- If you'd like to improve the tests, you want to make the documentation clearer, you have an
|
|
32
|
+
alternative implementation of something that may have advantages over the way its currently
|
|
33
|
+
done, or you have any other change, we would be happy to hear about it!
|
|
34
|
+
- If its a trivial change, go ahead and [send a Pull Request](#creating_a_pull_request) with the changes you have in mind.
|
|
35
|
+
- If not, [open an Issue](https://github.com/salesforce-misc/switchplane/issues/new) to discuss the idea first.
|
|
36
|
+
|
|
37
|
+
If you're new to our project and looking for some way to make your first contribution, look for
|
|
38
|
+
Issues labelled `good first contribution`.
|
|
39
|
+
|
|
40
|
+
# Contribution Checklist
|
|
41
|
+
|
|
42
|
+
- [x] Clean, simple, well styled code
|
|
43
|
+
- [x] Commits should be atomic and messages must be descriptive. Related issues should be mentioned by Issue number.
|
|
44
|
+
- [x] Comments
|
|
45
|
+
- Module-level & function-level comments.
|
|
46
|
+
- Comments on complex blocks of code or algorithms (include references to sources).
|
|
47
|
+
- [x] Tests
|
|
48
|
+
- The test suite, if provided, must be complete and pass
|
|
49
|
+
- Increase code coverage, not versa.
|
|
50
|
+
- Use any of our testkits that contains a bunch of testing facilities you would need. For example: `import com.salesforce.op.test._` and borrow inspiration from existing tests.
|
|
51
|
+
- [x] Dependencies
|
|
52
|
+
- Minimize number of dependencies.
|
|
53
|
+
- Prefer Apache 2.0, BSD3, MIT, ISC and MPL licenses.
|
|
54
|
+
- [x] Reviews
|
|
55
|
+
- Changes must be approved via peer code review
|
|
56
|
+
|
|
57
|
+
# Creating a Pull Request
|
|
58
|
+
|
|
59
|
+
1. **Ensure the bug/feature was not already reported** by searching on GitHub under Issues. If none exists, create a new issue so that other contributors can keep track of what you are trying to add/fix and offer suggestions (or let you know if there is already an effort in progress).
|
|
60
|
+
2. **Clone** the forked repo to your machine.
|
|
61
|
+
3. **Create** a new branch to contain your work (e.g. `git br fix-issue-11`)
|
|
62
|
+
4. **Commit** changes to your own branch.
|
|
63
|
+
5. **Push** your work back up to your fork. (e.g. `git push fix-issue-11`)
|
|
64
|
+
6. **Submit** a Pull Request against the `main` branch and refer to the issue(s) you are fixing. Try not to pollute your pull request with unintended changes. Keep it simple and small.
|
|
65
|
+
7. **Sign** the Salesforce CLA (you will be prompted to do so when submitting the Pull Request)
|
|
66
|
+
|
|
67
|
+
> **NOTE**: Be sure to [sync your fork](https://help.github.com/articles/syncing-a-fork/) before making a pull request.
|
|
68
|
+
|
|
69
|
+
# Contributor License Agreement ("CLA")
|
|
70
|
+
In order to accept your pull request, we need you to submit a CLA. You only need
|
|
71
|
+
to do this once to work on any of Salesforce's open source projects.
|
|
72
|
+
|
|
73
|
+
Complete your CLA here: <https://cla.salesforce.com/sign-cla>
|
|
74
|
+
|
|
75
|
+
# Issues
|
|
76
|
+
We use GitHub issues to track public bugs. Please ensure your description is
|
|
77
|
+
clear and has sufficient instructions to be able to reproduce the issue.
|
|
78
|
+
|
|
79
|
+
# Code of Conduct
|
|
80
|
+
Please follow our [Code of Conduct](CODE_OF_CONDUCT.md).
|
|
81
|
+
|
|
82
|
+
# License
|
|
83
|
+
By contributing your code, you agree to license your contribution under the terms of our project [LICENSE](LICENSE.txt) and to sign the [Salesforce CLA](https://cla.salesforce.com/sign-cla)
|