openvideo-server 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.
Files changed (112) hide show
  1. openvideo_server-0.1.0/.github/ISSUE_TEMPLATE/bug_report.yml +65 -0
  2. openvideo_server-0.1.0/.github/ISSUE_TEMPLATE/feature_request.yml +33 -0
  3. openvideo_server-0.1.0/.github/dependabot.yml +17 -0
  4. openvideo_server-0.1.0/.github/workflows/ci.yml +106 -0
  5. openvideo_server-0.1.0/.github/workflows/docs.yml +58 -0
  6. openvideo_server-0.1.0/.github/workflows/integration.yml +35 -0
  7. openvideo_server-0.1.0/.github/workflows/release.yml +40 -0
  8. openvideo_server-0.1.0/.gitignore +16 -0
  9. openvideo_server-0.1.0/.python-version +1 -0
  10. openvideo_server-0.1.0/AGENTS.md +262 -0
  11. openvideo_server-0.1.0/CONTRIBUTING.md +88 -0
  12. openvideo_server-0.1.0/LICENSE +201 -0
  13. openvideo_server-0.1.0/NOTICE +2 -0
  14. openvideo_server-0.1.0/PKG-INFO +146 -0
  15. openvideo_server-0.1.0/README.md +110 -0
  16. openvideo_server-0.1.0/ROADMAP.md +306 -0
  17. openvideo_server-0.1.0/SECURITY.md +36 -0
  18. openvideo_server-0.1.0/docs/access.md +90 -0
  19. openvideo_server-0.1.0/docs/api.md +138 -0
  20. openvideo_server-0.1.0/docs/architecture.md +154 -0
  21. openvideo_server-0.1.0/docs/configuration.md +153 -0
  22. openvideo_server-0.1.0/docs/index.md +79 -0
  23. openvideo_server-0.1.0/docs/install.md +153 -0
  24. openvideo_server-0.1.0/docs/license.md +10 -0
  25. openvideo_server-0.1.0/docs/requirements.txt +1 -0
  26. openvideo_server-0.1.0/example.yaml +116 -0
  27. openvideo_server-0.1.0/openvideo_server/__init__.py +5 -0
  28. openvideo_server-0.1.0/openvideo_server/_version.py +24 -0
  29. openvideo_server-0.1.0/openvideo_server/admin/__init__.py +1 -0
  30. openvideo_server-0.1.0/openvideo_server/admin/bridge.py +85 -0
  31. openvideo_server-0.1.0/openvideo_server/admin/client.py +142 -0
  32. openvideo_server-0.1.0/openvideo_server/admin/server.py +73 -0
  33. openvideo_server-0.1.0/openvideo_server/admin/service.py +363 -0
  34. openvideo_server-0.1.0/openvideo_server/admin/ui.py +692 -0
  35. openvideo_server-0.1.0/openvideo_server/api/__init__.py +1 -0
  36. openvideo_server-0.1.0/openvideo_server/api/capabilities.py +25 -0
  37. openvideo_server-0.1.0/openvideo_server/api/dependencies.py +172 -0
  38. openvideo_server-0.1.0/openvideo_server/api/ranges.py +64 -0
  39. openvideo_server-0.1.0/openvideo_server/api/routes_auth.py +298 -0
  40. openvideo_server-0.1.0/openvideo_server/api/routes_downloads.py +340 -0
  41. openvideo_server-0.1.0/openvideo_server/api/routes_history.py +188 -0
  42. openvideo_server-0.1.0/openvideo_server/api/routes_media.py +238 -0
  43. openvideo_server-0.1.0/openvideo_server/api/routes_playback.py +436 -0
  44. openvideo_server-0.1.0/openvideo_server/api/routes_server.py +171 -0
  45. openvideo_server-0.1.0/openvideo_server/api/routes_sources.py +225 -0
  46. openvideo_server-0.1.0/openvideo_server/api/routes_subtitles.py +133 -0
  47. openvideo_server-0.1.0/openvideo_server/cli.py +793 -0
  48. openvideo_server-0.1.0/openvideo_server/config.py +201 -0
  49. openvideo_server-0.1.0/openvideo_server/core/__init__.py +1 -0
  50. openvideo_server-0.1.0/openvideo_server/core/browser.py +501 -0
  51. openvideo_server-0.1.0/openvideo_server/core/download_manager.py +655 -0
  52. openvideo_server-0.1.0/openvideo_server/core/security.py +176 -0
  53. openvideo_server-0.1.0/openvideo_server/core/session_manager.py +1085 -0
  54. openvideo_server-0.1.0/openvideo_server/discovery/__init__.py +1 -0
  55. openvideo_server-0.1.0/openvideo_server/discovery/bonjour.py +256 -0
  56. openvideo_server-0.1.0/openvideo_server/macos/__init__.py +1 -0
  57. openvideo_server-0.1.0/openvideo_server/macos/launch_agent.py +168 -0
  58. openvideo_server-0.1.0/openvideo_server/main.py +281 -0
  59. openvideo_server-0.1.0/openvideo_server/media/__init__.py +1 -0
  60. openvideo_server-0.1.0/openvideo_server/media/binaries.py +264 -0
  61. openvideo_server-0.1.0/openvideo_server/media/cache.py +51 -0
  62. openvideo_server-0.1.0/openvideo_server/media/downloads.py +308 -0
  63. openvideo_server-0.1.0/openvideo_server/media/probe.py +280 -0
  64. openvideo_server-0.1.0/openvideo_server/media/subtitles.py +303 -0
  65. openvideo_server-0.1.0/openvideo_server/media/thumbnails.py +273 -0
  66. openvideo_server-0.1.0/openvideo_server/redaction.py +13 -0
  67. openvideo_server-0.1.0/openvideo_server/runtime.py +103 -0
  68. openvideo_server-0.1.0/openvideo_server/storage/__init__.py +1 -0
  69. openvideo_server-0.1.0/openvideo_server/storage/db.py +47 -0
  70. openvideo_server-0.1.0/openvideo_server/storage/disk.py +20 -0
  71. openvideo_server-0.1.0/openvideo_server/storage/migrations.py +58 -0
  72. openvideo_server-0.1.0/openvideo_server/storage/repository.py +722 -0
  73. openvideo_server-0.1.0/pyproject.toml +87 -0
  74. openvideo_server-0.1.0/tests/conftest.py +6 -0
  75. openvideo_server-0.1.0/tests/packaging/test_wheel.py +63 -0
  76. openvideo_server-0.1.0/tests/unit/support.py +52 -0
  77. openvideo_server-0.1.0/tests/unit/test_admin_client.py +147 -0
  78. openvideo_server-0.1.0/tests/unit/test_admin_service.py +413 -0
  79. openvideo_server-0.1.0/tests/unit/test_admin_ui.py +145 -0
  80. openvideo_server-0.1.0/tests/unit/test_app.py +33 -0
  81. openvideo_server-0.1.0/tests/unit/test_auth_dependency.py +71 -0
  82. openvideo_server-0.1.0/tests/unit/test_auth_routes.py +382 -0
  83. openvideo_server-0.1.0/tests/unit/test_binaries.py +147 -0
  84. openvideo_server-0.1.0/tests/unit/test_bonjour.py +336 -0
  85. openvideo_server-0.1.0/tests/unit/test_browser.py +254 -0
  86. openvideo_server-0.1.0/tests/unit/test_cli.py +791 -0
  87. openvideo_server-0.1.0/tests/unit/test_config.py +201 -0
  88. openvideo_server-0.1.0/tests/unit/test_database.py +62 -0
  89. openvideo_server-0.1.0/tests/unit/test_disk.py +42 -0
  90. openvideo_server-0.1.0/tests/unit/test_download_manager.py +310 -0
  91. openvideo_server-0.1.0/tests/unit/test_download_profiles.py +226 -0
  92. openvideo_server-0.1.0/tests/unit/test_download_repository.py +223 -0
  93. openvideo_server-0.1.0/tests/unit/test_download_routes.py +192 -0
  94. openvideo_server-0.1.0/tests/unit/test_history_routes.py +359 -0
  95. openvideo_server-0.1.0/tests/unit/test_launch_agent.py +87 -0
  96. openvideo_server-0.1.0/tests/unit/test_media_metadata_route.py +116 -0
  97. openvideo_server-0.1.0/tests/unit/test_media_streaming.py +239 -0
  98. openvideo_server-0.1.0/tests/unit/test_playback_routes.py +659 -0
  99. openvideo_server-0.1.0/tests/unit/test_probe.py +242 -0
  100. openvideo_server-0.1.0/tests/unit/test_redaction.py +21 -0
  101. openvideo_server-0.1.0/tests/unit/test_runtime.py +36 -0
  102. openvideo_server-0.1.0/tests/unit/test_security.py +112 -0
  103. openvideo_server-0.1.0/tests/unit/test_server_endpoints_route.py +239 -0
  104. openvideo_server-0.1.0/tests/unit/test_server_info_route.py +84 -0
  105. openvideo_server-0.1.0/tests/unit/test_session_manager.py +937 -0
  106. openvideo_server-0.1.0/tests/unit/test_sources_route.py +298 -0
  107. openvideo_server-0.1.0/tests/unit/test_subtitle_routes.py +184 -0
  108. openvideo_server-0.1.0/tests/unit/test_subtitles.py +103 -0
  109. openvideo_server-0.1.0/tests/unit/test_thumbnail_route.py +291 -0
  110. openvideo_server-0.1.0/tests/unit/test_thumbnails.py +431 -0
  111. openvideo_server-0.1.0/uv.lock +1168 -0
  112. openvideo_server-0.1.0/zensical.toml +61 -0
@@ -0,0 +1,65 @@
1
+ name: Bug report
2
+ description: Report a reproducible problem with OpenVideo Server.
3
+ title: "[Bug]: "
4
+ labels: ["bug"]
5
+ body:
6
+ - type: markdown
7
+ attributes:
8
+ value: |
9
+ Thanks for reporting a problem. Remove pairing tokens, PINs, private
10
+ media paths, and other secrets from logs before submitting.
11
+ - type: input
12
+ id: version
13
+ attributes:
14
+ label: OpenVideo Server version
15
+ description: Paste the output of `openvideo-server --version`.
16
+ placeholder: openvideo-server 0.2.0
17
+ validations:
18
+ required: true
19
+ - type: input
20
+ id: macos
21
+ attributes:
22
+ label: macOS version and architecture
23
+ description: For example, macOS 15.2 on Apple Silicon.
24
+ placeholder: macOS 15.2, arm64
25
+ validations:
26
+ required: true
27
+ - type: textarea
28
+ id: steps
29
+ attributes:
30
+ label: Steps to reproduce
31
+ description: List the smallest sequence that triggers the problem.
32
+ placeholder: |
33
+ 1. Start the server with ...
34
+ 2. Pair the client ...
35
+ 3. Open ...
36
+ validations:
37
+ required: true
38
+ - type: textarea
39
+ id: expected
40
+ attributes:
41
+ label: Expected behavior
42
+ validations:
43
+ required: true
44
+ - type: textarea
45
+ id: actual
46
+ attributes:
47
+ label: Actual behavior
48
+ description: Include the exact error and relevant redacted log lines.
49
+ validations:
50
+ required: true
51
+ - type: textarea
52
+ id: diagnostics
53
+ attributes:
54
+ label: Diagnostics
55
+ description: Paste redacted output from `openvideo-server doctor` if available, otherwise `openvideo-server status`.
56
+ render: text
57
+ - type: checkboxes
58
+ id: checklist
59
+ attributes:
60
+ label: Checklist
61
+ options:
62
+ - label: I removed secrets and private paths from this report.
63
+ required: true
64
+ - label: I searched existing issues for the same problem.
65
+ required: true
@@ -0,0 +1,33 @@
1
+ name: Feature request
2
+ description: Suggest a change to OpenVideo Server.
3
+ title: "[Feature]: "
4
+ labels: ["enhancement"]
5
+ body:
6
+ - type: textarea
7
+ id: problem
8
+ attributes:
9
+ label: Problem
10
+ description: What is difficult or missing today?
11
+ validations:
12
+ required: true
13
+ - type: textarea
14
+ id: proposal
15
+ attributes:
16
+ label: Proposed solution
17
+ description: Describe the behavior or interface you want.
18
+ validations:
19
+ required: true
20
+ - type: textarea
21
+ id: alternatives
22
+ attributes:
23
+ label: Alternatives considered
24
+ description: What workarounds or other designs have you tried?
25
+ - type: checkboxes
26
+ id: scope
27
+ attributes:
28
+ label: Scope
29
+ options:
30
+ - label: This request is for the server, not an iOS or web client.
31
+ required: true
32
+ - label: I searched existing issues for this request.
33
+ required: true
@@ -0,0 +1,17 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: uv
4
+ directory: /
5
+ schedule:
6
+ interval: weekly
7
+ groups:
8
+ python-dependencies:
9
+ patterns: ["*"]
10
+
11
+ - package-ecosystem: github-actions
12
+ directory: /
13
+ schedule:
14
+ interval: weekly
15
+ groups:
16
+ github-actions:
17
+ patterns: ["*"]
@@ -0,0 +1,106 @@
1
+ name: CI
2
+
3
+ on:
4
+ pull_request:
5
+ push:
6
+ branches: [master]
7
+
8
+ permissions:
9
+ contents: read
10
+
11
+ concurrency:
12
+ group: ci-${{ github.workflow }}-${{ github.ref }}
13
+ cancel-in-progress: true
14
+
15
+ env:
16
+ UV_VERSION: "0.13.10"
17
+
18
+ jobs:
19
+ lock:
20
+ name: Lockfile
21
+ runs-on: ubuntu-latest
22
+ timeout-minutes: 10
23
+ steps:
24
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
25
+ - uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
26
+ with:
27
+ version: ${{ env.UV_VERSION }}
28
+ enable-cache: true
29
+ - run: uv lock --check
30
+
31
+ workflow-lint:
32
+ name: Workflow lint
33
+ runs-on: ubuntu-latest
34
+ timeout-minutes: 10
35
+ steps:
36
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
37
+ - uses: raven-actions/actionlint@3d39aea434753780c3b3d4a1a31c854b4dbf49d7 # v2.2.0
38
+
39
+ lint:
40
+ name: Lint
41
+ needs: lock
42
+ runs-on: ubuntu-latest
43
+ timeout-minutes: 10
44
+ steps:
45
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
46
+ - uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
47
+ with:
48
+ version: ${{ env.UV_VERSION }}
49
+ python-version: "3.12"
50
+ enable-cache: true
51
+ - run: uv sync --locked --python 3.12
52
+ - run: uv run --python 3.12 ruff format --check .
53
+ - run: uv run --python 3.12 ruff check .
54
+
55
+ types:
56
+ name: Types
57
+ needs: lock
58
+ runs-on: ubuntu-latest
59
+ timeout-minutes: 10
60
+ steps:
61
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
62
+ - uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
63
+ with:
64
+ version: ${{ env.UV_VERSION }}
65
+ python-version: "3.12"
66
+ enable-cache: true
67
+ - run: uv sync --locked --python 3.12
68
+ - run: uv run --python 3.12 ty check
69
+
70
+ test:
71
+ name: Unit tests (${{ matrix.python-version }})
72
+ needs: lock
73
+ runs-on: ubuntu-latest
74
+ timeout-minutes: 20
75
+ strategy:
76
+ fail-fast: false
77
+ matrix:
78
+ python-version: ["3.12", "3.13", "3.14", "3.15"]
79
+ steps:
80
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
81
+ - uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
82
+ with:
83
+ version: ${{ env.UV_VERSION }}
84
+ python-version: ${{ matrix.python-version }}
85
+ enable-cache: true
86
+ - run: uv sync --locked --python ${{ matrix.python-version }}
87
+ - run: uv run --python ${{ matrix.python-version }} pytest tests/unit -q
88
+
89
+ macos:
90
+ name: Unit tests (macOS, ${{ matrix.python-version }})
91
+ needs: lock
92
+ runs-on: macos-15
93
+ timeout-minutes: 20
94
+ strategy:
95
+ fail-fast: false
96
+ matrix:
97
+ python-version: ["3.12", "3.15"]
98
+ steps:
99
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
100
+ - uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
101
+ with:
102
+ version: ${{ env.UV_VERSION }}
103
+ python-version: ${{ matrix.python-version }}
104
+ enable-cache: true
105
+ - run: uv sync --locked --python ${{ matrix.python-version }}
106
+ - run: uv run --python ${{ matrix.python-version }} pytest tests/unit -q
@@ -0,0 +1,58 @@
1
+ name: Docs
2
+
3
+ on:
4
+ pull_request:
5
+ paths:
6
+ - "docs/**"
7
+ - "zensical.toml"
8
+ - ".github/workflows/docs.yml"
9
+ push:
10
+ branches: [master]
11
+ paths:
12
+ - "docs/**"
13
+ - "zensical.toml"
14
+ - ".github/workflows/docs.yml"
15
+ workflow_dispatch:
16
+
17
+ permissions:
18
+ contents: read
19
+
20
+ concurrency:
21
+ group: pages-${{ github.ref }}
22
+ cancel-in-progress: false
23
+
24
+ jobs:
25
+ build:
26
+ name: Build
27
+ runs-on: ubuntu-latest
28
+ timeout-minutes: 10
29
+ steps:
30
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
31
+ - uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
32
+ with:
33
+ python-version: "3.12"
34
+ - run: pip install -r docs/requirements.txt
35
+ - run: zensical build --clean --strict
36
+ - name: Verify build output
37
+ run: test -s site/index.html
38
+ - if: github.event_name != 'pull_request'
39
+ uses: actions/configure-pages@45bfe0192ca1faeb007ade9deae92b16b8254a0d # v6.0.0
40
+ - if: github.event_name != 'pull_request'
41
+ uses: actions/upload-pages-artifact@fc324d3547104276b827a68afc52ff2a11cc49c9 # v5.0.0
42
+ with:
43
+ path: site
44
+
45
+ deploy:
46
+ name: Deploy
47
+ if: github.event_name != 'pull_request'
48
+ needs: build
49
+ runs-on: ubuntu-latest
50
+ permissions:
51
+ pages: write
52
+ id-token: write
53
+ environment:
54
+ name: github-pages
55
+ url: ${{ steps.deployment.outputs.page_url }}
56
+ steps:
57
+ - id: deployment
58
+ uses: actions/deploy-pages@368f82528645a54fb793d4d04e342629a3f51346 # v5.0.1
@@ -0,0 +1,35 @@
1
+ name: Integration tests
2
+
3
+ on:
4
+ workflow_dispatch:
5
+
6
+ permissions:
7
+ contents: read
8
+
9
+ concurrency:
10
+ group: integration-${{ github.ref }}
11
+ cancel-in-progress: true
12
+
13
+ env:
14
+ UV_VERSION: "0.13.10"
15
+
16
+ jobs:
17
+ integration:
18
+ name: Integration tests (macOS)
19
+ runs-on: macos-15
20
+ timeout-minutes: 45
21
+ steps:
22
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
23
+ - uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
24
+ with:
25
+ version: ${{ env.UV_VERSION }}
26
+ python-version: "3.15"
27
+ enable-cache: true
28
+ - run: uv sync --locked --python 3.15
29
+ - name: Run integration suite when present
30
+ run: |
31
+ if find tests/integration -name 'test_*.py' -print -quit 2>/dev/null | grep -q .; then
32
+ uv run --python 3.15 pytest tests/integration -q
33
+ else
34
+ echo "No integration tests found under tests/integration."
35
+ fi
@@ -0,0 +1,40 @@
1
+ name: Release
2
+
3
+ on:
4
+ push:
5
+ tags: ["v*"]
6
+
7
+ permissions:
8
+ contents: read
9
+
10
+ env:
11
+ UV_VERSION: "0.13.10"
12
+
13
+ jobs:
14
+ release:
15
+ name: Build and publish
16
+ runs-on: ubuntu-latest
17
+ timeout-minutes: 30
18
+ environment:
19
+ name: pypi
20
+ permissions:
21
+ contents: write
22
+ id-token: write
23
+ steps:
24
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
25
+ with:
26
+ fetch-depth: 0
27
+ - uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
28
+ with:
29
+ version: ${{ env.UV_VERSION }}
30
+ python-version: "3.12"
31
+ enable-cache: true
32
+ - run: uv sync --locked --python 3.12
33
+ - run: uv run --python 3.12 pytest tests/unit -q
34
+ - run: uv build
35
+ - uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # release/v1
36
+ with:
37
+ packages-dir: dist/
38
+ - run: gh release create "$GITHUB_REF_NAME" dist/* --generate-notes --verify-tag
39
+ env:
40
+ GH_TOKEN: ${{ github.token }}
@@ -0,0 +1,16 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.py[cod]
4
+ .pytest_cache/
5
+ .ruff_cache/
6
+ .ty_cache/
7
+ dist/
8
+ build/
9
+ site/
10
+ .cache/
11
+
12
+ # Keep config out of the repo
13
+ config.yaml
14
+
15
+ # Generated by hatch-vcs
16
+ openvideo_server/_version.py
@@ -0,0 +1 @@
1
+ 3.15
@@ -0,0 +1,262 @@
1
+ # AGENTS.md — Guidelines for AI Coding Agents (`openvideo-server`)
2
+
3
+ This repository houses the server component of **OpenVideo**, an open-source, lightweight personal media server tailored for macOS (Apple Silicon). It exposes a sandboxed virtual file browser, on-demand FFmpeg/VideoToolbox streaming, and SQLite-backed state tracking via a FastAPI asynchronous REST API.
4
+
5
+ ---
6
+
7
+ ## 1. Core Architectural Tenets (Do Not Deviate)
8
+
9
+ 1. **No Heavyweight Media Catalog:** Do not crawl or index whole directory trees into a database on startup. Directory contents are inspected on demand when a client navigates into them.
10
+ 2. **Zero ORM:** Do not introduce SQLAlchemy, SQLModel, Tortoise, or Peewee. Use raw, parameterized SQL queries executed via `aiosqlite`. Keep database code isolated in the storage layer.
11
+ 3. **No Heavy Task Queues:** Do not introduce Celery, Redis, RQ, or RabbitMQ. All background work (thumbnail extraction, FFmpeg process spawning, session cleanup) must run via Python's built-in `asyncio` primitives (`asyncio.create_subprocess_exec`, `asyncio.TaskGroup`, or `asyncio.create_task`).
12
+ 4. **Sandboxed Filesystem Security:** Clients must NEVER be allowed to traverse arbitrary Mac paths. All filesystem operations MUST enforce strict containment within the designated `path` of a configured source. Validate that `os.path.realpath(target)` begins with `os.path.realpath(source_root)`. Reject any path containing `..` or leading outside the source root.
13
+ 5. **Opaque Identifiers:** The REST API must never expose raw Mac filesystem paths. Use stable, deterministic opaque hashes (e.g., URL-safe base64 or SHA-256 hex of `source_id:relative_path`) for IDs.
14
+ 6. **Client Responsibility Boundary:** If an issue is explicitly a client concern (for example AVPlayer configuration, UI behavior, request construction, or client capability declarations), do not change server behavior to compensate. Report the issue and state the specific change required in the client instead.
15
+ 7. **Single Owner of State:** Only the server process writes `config.yaml`, the SQLite database, and the caches. The native admin window is a presentation client that calls the server; it must never open the database or write configuration itself.
16
+ 8. **Private Admin Transport:** Administration is exposed on a Unix domain socket under Application Support with `0600` permissions. Never add an admin HTTP listener on TCP, never serve admin HTML from the public API, and never weaken the socket permissions to make access easier.
17
+ 9. **Runtime Paths Live in `runtime.py`:** Resolve Application Support paths, the admin socket, and the LaunchAgent plist through `openvideo_server.runtime` (honoring `OPENVIDEO_HOME`). Do not hardcode `~/Library/...` paths in new modules.
18
+ 10. **Optional GUI Dependencies Stay Optional:** `pywebview` lives in the `ui` extra. Import it lazily with `importlib.import_module` inside entry points so the base install, `ruff`, `ty`, and `pytest` work without it.
19
+
20
+ ---
21
+
22
+ ## 2. Technology Stack & Tooling Commands
23
+
24
+ - **Python Version:** 3.12+
25
+ - **Package & Environment Manager:** `uv`
26
+ - **Web Framework:** `fastapi` with `uvicorn` (ASGI)
27
+ - **Data Validation:** `pydantic` v2
28
+ - **Database:** `aiosqlite` (SQLite 3 with WAL mode enabled)
29
+ - **Linter & Formatter:** `ruff`
30
+ - **Type Checker:** `ty` (or `mypy --strict`)
31
+ - **Test Runner:** `pytest` with `pytest-asyncio`
32
+ - **CLI Framework:** `click`
33
+
34
+ ### Deterministic Commands for Agents
35
+
36
+ Run these commands to verify code changes before finalizing work:
37
+
38
+ ```bash
39
+ # Install dependencies
40
+ uv sync
41
+
42
+ # Refresh the lockfile after dependency changes
43
+ uv lock
44
+
45
+ # Run formatters and linters
46
+ uv run ruff format .
47
+ uv run ruff check --fix .
48
+
49
+ # Run type checker
50
+ uv run ty check
51
+
52
+ # Run unit tests (with FFmpeg mocked)
53
+ uv run pytest tests/unit -v
54
+
55
+ # Run integration tests (requires local ffmpeg / ffprobe)
56
+ uv run pytest tests/integration -v
57
+
58
+ # Run the local development server
59
+ uv run openvideo-server --config config.yaml
60
+
61
+ # Background server lifecycle (PID file under Application Support)
62
+ uv run openvideo-server --config config.yaml server --background
63
+ uv run openvideo-server server stop
64
+ uv run openvideo-server server restart
65
+
66
+ # Exercise the installed runtime
67
+ uv run openvideo-server setup
68
+ uv run openvideo-server ffmpeg status
69
+ uv run openvideo-server agent install
70
+ uv run openvideo-server admin
71
+ uv run openvideo-server agent restart
72
+ uv run openvideo-server status
73
+ uv run openvideo-server pair
74
+ uv run openvideo-server --version
75
+ ```
76
+
77
+ `--version` prints the installed package version, configuration path, and
78
+ managed FFmpeg version. `openvideo_server.__version__` comes from the ignored,
79
+ hatch-vcs-generated `openvideo_server/_version.py`; never hardcode it. The
80
+ package version is not `CAPABILITY_VERSION` in `api/routes_server.py`: clients
81
+ gate features on the capability version, while humans and `uv tool upgrade` use
82
+ the package version.
83
+
84
+ Set `OPENVIDEO_PACKAGING_TEST=1` to run the opt-in wheel test, which builds the
85
+ wheel, installs it into a temporary `uv tool` directory, and exercises the
86
+ console script:
87
+
88
+ ```bash
89
+ OPENVIDEO_PACKAGING_TEST=1 uv run pytest tests/packaging -v
90
+ ```
91
+
92
+ 3. Directory Layout & Module Responsibilities
93
+
94
+ Agents must place new files in the appropriate layer according to this structure:
95
+
96
+ openvideo-server/
97
+ ├── pyproject.toml # Dependencies, Ruff, and pytest configs
98
+ ├── AGENTS.md # This instruction file
99
+ ├── README.md # Product summary and documentation link
100
+ ├── zensical.toml # Zensical site configuration
101
+ ├── docs/ # User-facing documentation site
102
+ ├── openvideo_server/
103
+ │ ├── __init__.py
104
+ │ ├── main.py # FastAPI app factory, lifespan, and routing
105
+ │ ├── config.py # Pydantic Settings & YAML configuration loader
106
+ │ ├── cli.py # click commands: server (--background, stop, restart), pair, status, setup, ffmpeg, agent, admin
107
+ │ ├── runtime.py # Application Support paths, admin socket, LaunchAgent plist
108
+ │ ├── admin/ # Local-only administration
109
+ │ │ ├── service.py # Admin FastAPI app (settings, devices, maintenance, restart)
110
+ │ │ ├── server.py # Uvicorn server bound to the 0600 Unix socket
111
+ │ │ ├── client.py # Stdlib JSON client over the Unix socket
112
+ │ │ ├── bridge.py # JavaScript bridge used by the native window
113
+ │ │ └── ui.py # Optional pywebview window and embedded HTML
114
+ │ ├── macos/ # macOS integration
115
+ │ │ └── launch_agent.py # LaunchAgent plist generation and launchctl calls
116
+ │ ├── api/ # REST API routers (FastAPI endpoints)
117
+ │ │ ├── __init__.py
118
+ │ │ ├── capabilities.py # Shared client codec/container capability model
119
+ │ │ ├── dependencies.py # Dependency injection (db connection, auth context)
120
+ │ │ ├── ranges.py # Shared byte-range parsing and file chunking
121
+ │ │ ├── routes_server.py # /server/info, /server/endpoints
122
+ │ │ ├── routes_sources.py # /sources, /sources/{id}/browse
123
+ │ │ ├── routes_media.py # /media/{id}, /thumbnails/{id}.jpg
124
+ │ │ ├── routes_downloads.py # /downloads conversion jobs and artifacts
125
+ │ │ ├── routes_playback.py # /playback/session, HLS manifests, stream endpoints
126
+ │ │ └── routes_history.py # /history, /progress
127
+ │ ├── core/ # Core business logic
128
+ │ │ ├── browser.py # Sandboxed directory reader & opaque ID encoder
129
+ │ │ ├── security.py # Device pairing token validation and path containment
130
+ │ │ ├── download_manager.py # Background conversion jobs, dedup, expiry sweeps
131
+ │ │ └── session_manager.py # Active HLS transcoding processes & cleanup
132
+ │ ├── media/ # Media inspection & manipulation
133
+ │ │ ├── binaries.py # Pinned ffmpeg/ffprobe manifest, resolver, installer
134
+ │ │ ├── downloads.py # Download profile resolution and conversion arguments
135
+ │ │ ├── probe.py # ffprobe wrapper (JSON output, aspect ratio, duration)
136
+ │ │ ├── transcoder.py # FFmpeg subprocess management (VideoToolbox / HLS)
137
+ │ │ ├── thumbnails.py # Async frame extraction & JPEG caching
138
+ │ │ └── subtitles.py # Subtitle extraction & WebVTT conversion
139
+ │ ├── storage/ # Database & filesystem storage
140
+ │ │ ├── db.py # aiosqlite connection pool and migration runner
141
+ │ │ ├── migrations.py # Raw SQL DDL scripts and table initialization
142
+ │ │ └── repository.py # Raw SQL query methods (devices, playback history)
143
+ │ └── discovery/
144
+ │ └── bonjour.py # Zeroconf advertisement (_openvideo._tcp.local)
145
+ └── tests/
146
+ ├── conftest.py # Shared fixtures (temp dirs, in-memory DB, mock FFmpeg)
147
+ ├── unit/ # Unit tests (Mocked subprocesses, pure functions)
148
+ └── integration/ # Integration tests (Real filesystem, real FFmpeg/ffprobe)
149
+
150
+ 4. Coding Standards & Conventions
151
+
152
+ 4.1. Typing & Signatures
153
+
154
+ - Every function, method, and route handler must include explicit Python type annotations for all parameters and return values.
155
+ - Never use untyped dict or bare Any unless wrapping arbitrary dynamic JSON. Use Pydantic models for request/response payloads.
156
+
157
+ 4.2. Database & SQL Rules
158
+
159
+ - All SQL queries must be parameterized (? placeholders). Never concatenate strings into SQL queries.
160
+ - Open SQLite connections with PRAGMA journal_mode = WAL; and PRAGMA foreign_keys = ON;.
161
+ - Keep table schema migrations idempotent (CREATE TABLE IF NOT EXISTS).
162
+
163
+ Example database pattern:
164
+
165
+ async with db.execute(
166
+ """
167
+ INSERT INTO playback_history (id, media_id, device_id, position_seconds, duration_seconds, completed, updated_at)
168
+ VALUES (?, ?, ?, ?, ?, ?, ?)
169
+ ON CONFLICT(id) DO UPDATE SET
170
+ position_seconds = excluded.position_seconds,
171
+ completed = excluded.completed,
172
+ updated_at = excluded.updated_at
173
+ """,
174
+ (history_id, media_id, device_id, position, duration, 1 if completed else 0, now_ts)
175
+ ) as cursor:
176
+ await db.commit()
177
+
178
+ 4.3. FFmpeg & Subprocess Rules
179
+
180
+ - Never use blocking subprocess.run or os.system.
181
+ - Always use await asyncio.create_subprocess_exec(*args, stdout=..., stderr=...).
182
+ - Capture stderr on failure and log the tail of the FFmpeg output for debugging.
183
+ - Use h264_videotoolbox when hardware acceleration is enabled; fall back to software libx264 if unavailable.
184
+ - Always isolate HLS segments into unique per-session directories (~/Library/Application Support/OpenVideo/transcode//). Clean up these directories when sessions terminate.
185
+ - Write the HLS media playlist as an EVENT playlist (`-hls_playlist_type event`) and publish it as soon as the first segment exists. On-demand sessions must never wait for `#EXT-X-ENDLIST` before answering a playlist request; that reintroduces the "Preparing stream" hang on long files. `HlsSessionManager.wait_for_playlist_start` handles this with `PLAYLIST_START_TIMEOUT_SECONDS`, and the API answers `503` plus `Retry-After` when the encoder is slower than the timeout.
186
+ - Keep the transcode filter chain ending in `crop=trunc(iw/2)*2:trunc(ih/2)*2`. Legacy AVI and WMV sources routinely have odd dimensions, and H.264 encoders reject them without the crop.
187
+ - `h264_videotoolbox` can exist but fail to start (for example `Cannot create compression session`). Keep the `HARDWARE_STARTUP_WAIT_SECONDS` retry that restarts the session with the software encoder.
188
+ - Thumbnail extraction seeks to ~10% of the duration on a cache miss, so pass a `duration_provider` (backed by `probe_media`) when the caller has no duration; without it the seek is skipped and legacy files can yield a black lead-in frame. Never add per-container thumbnail special cases.
189
+ - Direct Play eligibility is decided from the probed container plus every audio and video codec. When adding codec support, extend the codec sets and the `/server/info` capability payload together, and cover both the direct-play and forced-transcode paths in tests.
190
+ - Offline conversions are separate from live playback: `DownloadManager` owns its own concurrency semaphore (`download.conversion_sessions`), queue, and artifact directory, and must never consume an HLS playback slot. Start FFmpeg conversions with `nice -n 10` where available and prefer VideoToolbox encoders, falling back to software exactly as the playback path does. Read only the first audio track.
191
+ - Prefer a remux when the client declares it can play the source container and codecs; re-encode only the tracks that are incompatible. Video artifacts are H.264/AAC MP4 and audio-only artifacts are M4A. Never claim a target codec the client did not ask for.
192
+ - Download artifacts are per-device, never shared. Deduplicate only against a non-terminal job with the same device, media, source fingerprint, and resolved profile. Acknowledged or expired jobs are gone: a later request starts a fresh conversion. Do not add a "delete your local copy first" rule on the server.
193
+ - Every interested client is a polling client. Return the job JSON and let it poll; do not hold a request open for the conversion. `POST /downloads` returns `202` for a new job and `200` when it reuses an active one.
194
+ - Conversions write to a `.part` file and atomically replace the final artifact only after the process exits successfully. Check the configured disk-buffer percentage before launching, and return `DISK_LOW`/`FFMPEG_UNAVAILABLE` as `503` instead of starting a doomed encode.
195
+ - The sweeper is the only component that deletes expired artifacts, and it must skip artifacts with an open byte-range stream (`stream_opened`/`stream_closed`). Acknowledging shortens the expiry to `download.ack_grace_seconds`; TTL and ack grace are "whichever comes first", not additive. Admin cache clearing must expire ready jobs whose artifact vanished.
196
+ - Changing the download HTTP or job-state contract requires updating `docs/api.md`, `DOWNLOAD_CLIENT.md`, and `capability_version` together.
197
+
198
+ 4.4. Error Handling & HTTP Responses
199
+
200
+ - Use FastAPI's HTTPException with explicit status codes:
201
+ - 400 Bad Request for malformed path requests.
202
+ - 403 Forbidden for path traversal attempts or unauthorized pairing.
203
+ - 404 Not Found for missing files, directories, or sessions.
204
+ - 422 Unprocessable Entity for invalid query parameters or unparseable media.
205
+ - Never leak absolute Mac filesystem paths in HTTP error bodies.
206
+
207
+ 4.5. Administration and UI Rules
208
+
209
+ - Keep the admin API narrow: settings, paired devices, PIN issuance, cache clearing, database optimize/reset, and restart. Do not add arbitrary SQL, filesystem browsing, or shell execution endpoints.
210
+ - The admin app receives the running `AppConfig`, the config path, the database path, the pairing manager, cache roots, and resolved binaries. It must not import the public API routers.
211
+ - Configuration writes go through `_write_config`: validate with `AppConfig.model_validate`, copy the current file to `<name>.bak`, write a temporary file, `fsync`, then `os.replace`. Never truncate `config.yaml` in place.
212
+ - Destructive operations require explicit confirmation (`RESET` for the database) and serialize through the admin maintenance lock.
213
+ - Revoking a device removes its playback history. `delete_paired_device` deletes the rows explicitly (so databases created before the `playback_history.device_id` foreign key still lose them) and `ON DELETE CASCADE` covers current schemas.
214
+ - "Optimize database" purges history rows whose `device_id` no longer exists (`repository.purge_orphaned_playback_history`) before `PRAGMA optimize`, `wal_checkpoint(TRUNCATE)`, and `VACUUM`, and reports the count through `MaintenanceResult.removed_records`. Keep that order: orphans must be gone before `VACUUM` reclaims the pages.
215
+ - The UI is static HTML with no build step and no external assets. Call server operations through the `AdminBridge` envelope (`{"ok": true, "data": ...}` or `{"ok": false, "error": ...}`) so failures render as messages instead of unhandled promise rejections.
216
+ - Source folders are chosen with the native webview dialog (`window.create_file_dialog(webview.FileDialog.FOLDER)`, wired through `AdminBridge.choose_source_folder`). The page only receives the id, name, and path, and returns them through `save_settings`, so the server stays the only writer.
217
+ - Every entry in the settings `FIELDS` array carries a one-sentence `hint`. The page renders it as a `title` tooltip on the label, the `?` marker, and the input, so every configuration option explains itself without a separate help page. Keep hints in sync with the configuration reference in `docs/configuration.md`.
218
+ - Source rows keep the fields the table does not edit (`read_only`, and any future keys) and merge the visible columns over them, so saving from the window never drops configuration it did not show.
219
+ - Do not add an HTTP admin listener, and do not fetch the socket from the page; the page talks to Python through the webview bridge.
220
+
221
+ 4.6. macOS Integration Rules
222
+
223
+ - LaunchAgent plists use `RunAtLoad` and `KeepAlive` with `SuccessfulExit: false`, an absolute `ProgramArguments[0]` (launchd has no login-shell `PATH`), an explicit `--config`, and `WorkingDirectory` set to Application Support.
224
+ - Restart through `launchctl kickstart -k gui/<uid>/<label>`; install with `bootout` (tolerating "not loaded"), `bootstrap`, then `enable`.
225
+ - Keep `runner` injectable in launch-agent helpers so tests never touch the real `launchctl`.
226
+ - Managed binaries are pinned by URL and SHA-256 per architecture. Never download an unpinned "latest" build, and never skip checksum verification.
227
+
228
+ 4.7. Server Identity and Advertised Endpoints
229
+
230
+ - `GET /api/v1/server/info` is the public identity probe. Keep it unauthenticated and keep returning `server_id`.
231
+ - `GET /api/v1/server/endpoints` requires the normal device bearer dependency. Never expose the endpoint list from Bonjour TXT or any unauthenticated route.
232
+ - `lan` entries come from `local_ipv4_addresses()` in `discovery/bonjour.py`, which enumerates physical interfaces (`en*`) and skips virtual adapters (VMware Fusion `vmnet*`, VPN `utun*`, Docker/bridge devices). Do not derive LAN addresses from `getaddrinfo`/hostname resolution: a VPN or DNS override can surface an unreachable address. Operators add virtual or proxy addresses through `network.advertised_urls`.
233
+ - `network.advertised_urls` entries are validated by `_normalize_advertised_url` in `config.py`: absolute `http`/`https`, host required, no credentials, query, or fragment, trailing slash stripped, and exact duplicates after normalization rejected. Do not verify reachability from the server; hairpin NAT makes self-checks misleading.
234
+ - `server_id` is derived from the server name and hostname. Renaming either invalidates saved pairings; document that behavior, and if it must change, persist an ID instead and describe the migration.
235
+
236
+ 5. Testing Requirements for Agents
237
+
238
+ 1. Unit Tests (tests/unit/):
239
+ - Must run completely offline without depending on external binaries (ffmpeg, ffprobe).
240
+ - Mock subprocess calls using unittest.mock.patch("asyncio.create_subprocess_exec").
241
+ - Test directory containment rigorously: supply paths like ../../etc/passwd or /System and assert that the browser raises a security exception.
242
+ - Test database queries using an in-memory SQLite database (:memory:).
243
+
244
+ 2. Integration Tests (tests/integration/):
245
+ - Marked with @pytest.mark.integration.
246
+ - Only run when real ffmpeg is available on the machine.
247
+ - Use small synthetic media fixtures (e.g., 2-second generated test MP4 clips).
248
+
249
+ 3. Coverage Expectations:
250
+ - Any new endpoint or service method added by an agent must be accompanied by corresponding unit tests.
251
+ - Both successful operations and failure edge cases (invalid tokens, file not found, unreadable media) must be verified.
252
+
253
+ 4. Administration and UI Tests:
254
+ - Use `fastapi.testclient.TestClient` against `create_admin_app` for admin routes; assert on-disk YAML, the `.bak` copy, and `restart_required`.
255
+ - Exercise `AdminClient` with an injected `connection_factory` instead of a real socket; restricted sandboxes may deny `AF_UNIX` bind.
256
+ - Do not require `pywebview` in tests; monkeypatch `importlib.import_module` to assert the friendly missing-dependency error.
257
+
258
+ 5. CLI Tests:
259
+ - Drive commands with `click.testing.CliRunner` and pass `--config` explicitly.
260
+ - Stub the HTTP probe (`urllib.request.urlopen`) instead of starting a server, and seed SQLite fixtures through `connect_database` rather than hand-written inserts.
261
+ - `status` must exit zero when the server is stopped or the configuration is missing; only an unreadable configuration file exits non-zero.
262
+ - `status` also reports the background PID file state; a missing, stale, or unrelated PID must not make it fail.