From c0ab677d53f3842503b10cf05da279d0a91ba983 Mon Sep 17 00:00:00 2001 From: tercel Date: Fri, 13 Feb 2026 16:42:53 +0800 Subject: [PATCH 0001/1289] feat: Initial commit for apcore project Initialize apcore - a schema-driven module development framework for AI-perceivable interfaces. Features: - Schema-driven modules with Pydantic validation - 10-step execution pipeline with safety checks and ACL enforcement - @module decorator for zero-boilerplate module definition - YAML-based module bindings - Pattern-based access control (ACL) - Composable middleware system with before/after hooks - Built-in observability: tracing, metrics, and context logging - Async/await support for synchronous and asynchronous execution - Safety guards: call depth limits, circular detection, frequency throttling Project structure: - src/apcore: Core framework implementation - executor: Task execution engine - middleware: Composable middleware pipeline system - registry: Module registration and discovery - schema: Pydantic schema handling and validation - observability: Tracing, metrics, and logging utilities - acl: Access control enforcement - bindings: YAML-based module binding support - tests: Comprehensive test suite with unit and integration tests - examples: Sample modules demonstrating framework usage Dependencies: - Python >= 3.11 - Pydantic >= 2.0 - PyYAML >= 6.0 - pluggy >= 1.0 --- .github/CODEOWNERS | 3 + .github/copilot-ignore | 13 + .github/copilot-instructions.md | 61 + .github/workflows/ci.yml | 50 + .gitignore | 16 + .gitmessage | 60 + .pre-commit-config.yaml | 26 + CLAUDE.md | 61 + README.md | 161 +++ examples/bindings/format_date/binding.yaml | 25 + examples/bindings/format_date/format_date.py | 17 + examples/modules/decorated_add.py | 9 + examples/modules/get_user.py | 48 + examples/modules/greet.py | 35 + examples/modules/send_email.py | 75 + pyproject.toml | 38 + src/apcore/__init__.py | 116 ++ src/apcore/acl.py | 269 ++++ src/apcore/bindings.py | 252 ++++ src/apcore/config.py | 29 + src/apcore/context.py | 60 + src/apcore/decorator.py | 264 ++++ src/apcore/errors.py | 380 +++++ src/apcore/executor.py | 620 +++++++++ src/apcore/middleware/__init__.py | 15 + src/apcore/middleware/adapters.py | 39 + src/apcore/middleware/base.py | 31 + src/apcore/middleware/logging.py | 88 ++ src/apcore/middleware/manager.py | 110 ++ src/apcore/module.py | 58 + src/apcore/observability/__init__.py | 37 + src/apcore/observability/context_logger.py | 169 +++ src/apcore/observability/metrics.py | 175 +++ src/apcore/observability/tracing.py | 261 ++++ src/apcore/registry/__init__.py | 36 + src/apcore/registry/dependencies.py | 113 ++ src/apcore/registry/entry_point.py | 89 ++ src/apcore/registry/metadata.py | 116 ++ src/apcore/registry/registry.py | 388 ++++++ src/apcore/registry/scanner.py | 147 ++ src/apcore/registry/schema_export.py | 189 +++ src/apcore/registry/types.py | 51 + src/apcore/registry/validation.py | 46 + src/apcore/schema/__init__.py | 45 + src/apcore/schema/annotations.py | 62 + src/apcore/schema/exporter.py | 95 ++ src/apcore/schema/loader.py | 372 +++++ src/apcore/schema/ref_resolver.py | 200 +++ src/apcore/schema/strict.py | 105 ++ src/apcore/schema/types.py | 109 ++ src/apcore/schema/validator.py | 102 ++ src/apcore/utils/__init__.py | 5 + src/apcore/utils/pattern.py | 46 + tests/binding_helpers.py | 33 + tests/conftest.py | 195 +++ tests/examples/__init__.py | 0 tests/examples/test_example_modules.py | 169 +++ tests/integration/__init__.py | 0 tests/integration/conftest.py | 152 ++ tests/integration/test_acl_enforcement.py | 48 + tests/integration/test_async_flows.py | 35 + tests/integration/test_binding_modules.py | 84 ++ tests/integration/test_decorator_modules.py | 59 + tests/integration/test_e2e_flow.py | 60 + tests/integration/test_error_propagation.py | 58 + tests/integration/test_infra_smoke.py | 36 + tests/integration/test_middleware_chain.py | 95 ++ tests/observability/__init__.py | 0 tests/observability/test_context_logger.py | 317 +++++ tests/observability/test_metrics.py | 344 +++++ .../test_observability_package.py | 75 + tests/observability/test_tracing.py | 569 ++++++++ tests/registry/__init__.py | 0 tests/registry/conftest.py | 138 ++ .../test_circular_dependency_error.py | 39 + tests/registry/test_dependencies.py | 121 ++ tests/registry/test_entry_point.py | 197 +++ tests/registry/test_integration.py | 289 ++++ tests/registry/test_metadata.py | 189 +++ tests/registry/test_registry.py | 749 ++++++++++ tests/registry/test_scanner.py | 238 ++++ tests/registry/test_schema_export.py | 254 ++++ tests/registry/test_types.py | 161 +++ tests/registry/test_validation.py | 151 ++ tests/schema/__init__.py | 0 tests/schema/conftest.py | 82 ++ tests/schema/fixtures/circular_a.schema.yaml | 24 + tests/schema/fixtures/circular_b.schema.yaml | 24 + .../fixtures/common/address.schema.yaml | 18 + .../schema/fixtures/common/error.schema.yaml | 13 + tests/schema/fixtures/empty.schema.yaml | 0 tests/schema/fixtures/invalid_syntax.yaml | 2 + .../fixtures/llm_extensions.schema.yaml | 36 + .../fixtures/nested_objects.schema.yaml | 50 + tests/schema/fixtures/simple.schema.yaml | 21 + tests/schema/fixtures/with_refs.schema.yaml | 35 + tests/schema/test_annotations.py | 122 ++ tests/schema/test_edge_cases.py | 265 ++++ tests/schema/test_exporter.py | 228 +++ tests/schema/test_loader.py | 619 +++++++++ tests/schema/test_ref_resolver.py | 324 +++++ tests/schema/test_strict.py | 216 +++ tests/schema/test_types.py | 209 +++ tests/schema/test_validator.py | 228 +++ tests/test_acl.py | 541 ++++++++ tests/test_bindings.py | 490 +++++++ tests/test_decorator.py | 1217 +++++++++++++++++ tests/test_executor.py | 559 ++++++++ tests/test_executor_async.py | 233 ++++ tests/test_executor_types.py | 71 + tests/test_integration_executor.py | 297 ++++ tests/test_logging_middleware.py | 251 ++++ tests/test_middleware.py | 163 +++ tests/test_middleware_manager.py | 382 ++++++ tests/test_public_api.py | 288 ++++ tests/test_redaction.py | 173 +++ uv.lock | 626 +++++++++ 117 files changed, 18649 insertions(+) create mode 100644 .github/CODEOWNERS create mode 100644 .github/copilot-ignore create mode 100644 .github/copilot-instructions.md create mode 100644 .github/workflows/ci.yml create mode 100644 .gitignore create mode 100644 .gitmessage create mode 100644 .pre-commit-config.yaml create mode 100644 CLAUDE.md create mode 100644 README.md create mode 100644 examples/bindings/format_date/binding.yaml create mode 100644 examples/bindings/format_date/format_date.py create mode 100644 examples/modules/decorated_add.py create mode 100644 examples/modules/get_user.py create mode 100644 examples/modules/greet.py create mode 100644 examples/modules/send_email.py create mode 100644 pyproject.toml create mode 100644 src/apcore/__init__.py create mode 100644 src/apcore/acl.py create mode 100644 src/apcore/bindings.py create mode 100644 src/apcore/config.py create mode 100644 src/apcore/context.py create mode 100644 src/apcore/decorator.py create mode 100644 src/apcore/errors.py create mode 100644 src/apcore/executor.py create mode 100644 src/apcore/middleware/__init__.py create mode 100644 src/apcore/middleware/adapters.py create mode 100644 src/apcore/middleware/base.py create mode 100644 src/apcore/middleware/logging.py create mode 100644 src/apcore/middleware/manager.py create mode 100644 src/apcore/module.py create mode 100644 src/apcore/observability/__init__.py create mode 100644 src/apcore/observability/context_logger.py create mode 100644 src/apcore/observability/metrics.py create mode 100644 src/apcore/observability/tracing.py create mode 100644 src/apcore/registry/__init__.py create mode 100644 src/apcore/registry/dependencies.py create mode 100644 src/apcore/registry/entry_point.py create mode 100644 src/apcore/registry/metadata.py create mode 100644 src/apcore/registry/registry.py create mode 100644 src/apcore/registry/scanner.py create mode 100644 src/apcore/registry/schema_export.py create mode 100644 src/apcore/registry/types.py create mode 100644 src/apcore/registry/validation.py create mode 100644 src/apcore/schema/__init__.py create mode 100644 src/apcore/schema/annotations.py create mode 100644 src/apcore/schema/exporter.py create mode 100644 src/apcore/schema/loader.py create mode 100644 src/apcore/schema/ref_resolver.py create mode 100644 src/apcore/schema/strict.py create mode 100644 src/apcore/schema/types.py create mode 100644 src/apcore/schema/validator.py create mode 100644 src/apcore/utils/__init__.py create mode 100644 src/apcore/utils/pattern.py create mode 100644 tests/binding_helpers.py create mode 100644 tests/conftest.py create mode 100644 tests/examples/__init__.py create mode 100644 tests/examples/test_example_modules.py create mode 100644 tests/integration/__init__.py create mode 100644 tests/integration/conftest.py create mode 100644 tests/integration/test_acl_enforcement.py create mode 100644 tests/integration/test_async_flows.py create mode 100644 tests/integration/test_binding_modules.py create mode 100644 tests/integration/test_decorator_modules.py create mode 100644 tests/integration/test_e2e_flow.py create mode 100644 tests/integration/test_error_propagation.py create mode 100644 tests/integration/test_infra_smoke.py create mode 100644 tests/integration/test_middleware_chain.py create mode 100644 tests/observability/__init__.py create mode 100644 tests/observability/test_context_logger.py create mode 100644 tests/observability/test_metrics.py create mode 100644 tests/observability/test_observability_package.py create mode 100644 tests/observability/test_tracing.py create mode 100644 tests/registry/__init__.py create mode 100644 tests/registry/conftest.py create mode 100644 tests/registry/test_circular_dependency_error.py create mode 100644 tests/registry/test_dependencies.py create mode 100644 tests/registry/test_entry_point.py create mode 100644 tests/registry/test_integration.py create mode 100644 tests/registry/test_metadata.py create mode 100644 tests/registry/test_registry.py create mode 100644 tests/registry/test_scanner.py create mode 100644 tests/registry/test_schema_export.py create mode 100644 tests/registry/test_types.py create mode 100644 tests/registry/test_validation.py create mode 100644 tests/schema/__init__.py create mode 100644 tests/schema/conftest.py create mode 100644 tests/schema/fixtures/circular_a.schema.yaml create mode 100644 tests/schema/fixtures/circular_b.schema.yaml create mode 100644 tests/schema/fixtures/common/address.schema.yaml create mode 100644 tests/schema/fixtures/common/error.schema.yaml create mode 100644 tests/schema/fixtures/empty.schema.yaml create mode 100644 tests/schema/fixtures/invalid_syntax.yaml create mode 100644 tests/schema/fixtures/llm_extensions.schema.yaml create mode 100644 tests/schema/fixtures/nested_objects.schema.yaml create mode 100644 tests/schema/fixtures/simple.schema.yaml create mode 100644 tests/schema/fixtures/with_refs.schema.yaml create mode 100644 tests/schema/test_annotations.py create mode 100644 tests/schema/test_edge_cases.py create mode 100644 tests/schema/test_exporter.py create mode 100644 tests/schema/test_loader.py create mode 100644 tests/schema/test_ref_resolver.py create mode 100644 tests/schema/test_strict.py create mode 100644 tests/schema/test_types.py create mode 100644 tests/schema/test_validator.py create mode 100644 tests/test_acl.py create mode 100644 tests/test_bindings.py create mode 100644 tests/test_decorator.py create mode 100644 tests/test_executor.py create mode 100644 tests/test_executor_async.py create mode 100644 tests/test_executor_types.py create mode 100644 tests/test_integration_executor.py create mode 100644 tests/test_logging_middleware.py create mode 100644 tests/test_middleware.py create mode 100644 tests/test_middleware_manager.py create mode 100644 tests/test_public_api.py create mode 100644 tests/test_redaction.py create mode 100644 uv.lock diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 00000000..53a651f4 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,3 @@ +# all workflow and CODEOWNERS itself modification must be approved by repository owner or core maintainer +.github/workflows/ @tercel +.github/CODEOWNERS @tercel \ No newline at end of file diff --git a/.github/copilot-ignore b/.github/copilot-ignore new file mode 100644 index 00000000..c0619a02 --- /dev/null +++ b/.github/copilot-ignore @@ -0,0 +1,13 @@ +# Environment variables (sensitive data) +.env +.data + +# Secrets +secrets/ +*.pem +*.key + +.claude/ +CLAUDE.md +.cursor/ + diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md new file mode 100644 index 00000000..84ad35a8 --- /dev/null +++ b/.github/copilot-instructions.md @@ -0,0 +1,61 @@ +# High-Quality Code Specification – Simplicity, Readability, and Maintainability First + +## Project Overview +The core of `apcore` is **task orchestration and execution specifications**. It provides a unified task orchestration framework that supports execution of multiple task types. + +## Core Principles +- Prioritize **simplicity, readability, and maintainability** above all. +- Avoid premature abstraction, optimization, or over-engineering. +- Code should be understandable in ≤10 seconds; favor straightforward over clever. +- Always follow: Understand → Plan → Implement minimally → Test/Validate → Commit. + +## Python Code Quality + +### Readability +- Use precise, full-word names (standard abbreviations only when conventional). +- Functions ≤50 lines, single responsibility, verb-named. +- Avoid obscure tricks, heavy comprehensions, excessive *args/**kwargs, unnecessary decorators. +- Break complex logic into small, well-named helpers. + +### Types (Mandatory) +- Full type annotations everywhere. +- Avoid `Any` except for dynamic/external data. +- Prefer `dataclass`, `TypedDict`, `Protocol`, `NewType`. + +### Design +- Favor functional style + data classes; minimize inheritance. +- Composition > inheritance; use Protocols/ABCs only for true interfaces. +- No circular imports. +- Dependency injection for config, logging, DB, etc. + +### Errors & Resources +- Explicit exception handling; no bare `except:`. +- Context managers for files/DB/connections. +- Validate/sanitize all public inputs. + +### Logging +- Use `logging.info` for key paths. +- `logging.error` + context for exceptions. +- No `print()` in production/debug code. + +### Testing +- Unit tests in `tests/`, ≥90% coverage on core logic. +- Name: `test__`. +- Never change prod code without/updating tests. + +### Formatting & Linting +- After changes, always run: + - ruff check --fix . + - black . + - pyright . +- Zero errors/warnings before commit. + +### Security & Performance +- Never hardcode secrets; use env/config. +- Validate/sanitize inputs. +- Avoid unjustified quadratic+ complexity in hot paths. + +## General Guidelines +- English ONLY for comments, docstrings, logs, errors, commit messages. +- Fully understand surrounding code before changes. +- Do not generate unnecessary documentation, examples, stubs, or bloated `__init__.py` files unless explicitly requested. \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..8fee0be5 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,50 @@ +name: CI + +permissions: + contents: read + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + test: + name: Test on Python ${{ matrix.python-version }} + runs-on: ubuntu-latest + # container: + # image: python:${{ matrix.python-version }} + strategy: + fail-fast: false + matrix: + # Pin CI to a single, consistent Python version to reduce version-related + # test flakiness. Use 3.12 for CI stability; expand matrix later if desired. + python-version: ["3.12"] + + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + + - name: Set up Python + uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0 + with: + python-version: ${{ matrix.python-version }} + cache: pip + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + # If a constraints.txt file is present, use it to pin critical dependency versions. + if [ -f constraints.txt ]; then + pip install -e ".[dev]" -c constraints.txt + else + pip install -e ".[dev]" + fi + + - name: Lint with Ruff + run: | + ruff check src/ tests/ + + - name: Run tests + run: | + pytest diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..f0b2257b --- /dev/null +++ b/.gitignore @@ -0,0 +1,16 @@ +__pycache__/ +*.py[cod] +*.egg-info/ +dist/ +build/ +.eggs/ +.claude/ +.idea/ +.vscode/ +.DS_Store +.ruff_cache/ +.pytest_cache/ +.venv/ +venv/ +env/ +.env diff --git a/.gitmessage b/.gitmessage new file mode 100644 index 00000000..13607a73 --- /dev/null +++ b/.gitmessage @@ -0,0 +1,60 @@ +# (): +# +# +# +#