pawnai-matrix 0.2.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 (82) hide show
  1. pawnai_matrix-0.2.0/.codex +0 -0
  2. pawnai_matrix-0.2.0/.dockerignore +165 -0
  3. pawnai_matrix-0.2.0/.github/workflows/publish.yml +66 -0
  4. pawnai_matrix-0.2.0/.gitignore +172 -0
  5. pawnai_matrix-0.2.0/.gitlab-ci.yml +100 -0
  6. pawnai_matrix-0.2.0/.vscode/launch.json +27 -0
  7. pawnai_matrix-0.2.0/.vscode/settings.json +5 -0
  8. pawnai_matrix-0.2.0/CHANGELOG.md +0 -0
  9. pawnai_matrix-0.2.0/CLAUDE.md +96 -0
  10. pawnai_matrix-0.2.0/CONTRIBUTING.md +91 -0
  11. pawnai_matrix-0.2.0/LICENSE +177 -0
  12. pawnai_matrix-0.2.0/PKG-INFO +83 -0
  13. pawnai_matrix-0.2.0/README.md +52 -0
  14. pawnai_matrix-0.2.0/alembic/README +1 -0
  15. pawnai_matrix-0.2.0/alembic/env.py +88 -0
  16. pawnai_matrix-0.2.0/alembic/script.py.mako +26 -0
  17. pawnai_matrix-0.2.0/alembic/versions/1780ad3ce78d_added_room_configuration_table.py +36 -0
  18. pawnai_matrix-0.2.0/alembic/versions/620ce7c88821_added_room_configuration_field.py +30 -0
  19. pawnai_matrix-0.2.0/alembic/versions/8e929aa6d627_initial_migration.py +36 -0
  20. pawnai_matrix-0.2.0/alembic/versions/a1b2c3d4e5f6_added_bot_configuration_table.py +40 -0
  21. pawnai_matrix-0.2.0/alembic/versions/c1d2e3f4a5b6_added_room_message_table.py +42 -0
  22. pawnai_matrix-0.2.0/alembic/versions/d4e5f6a7b8c9_make_room_expert_nullable.py +28 -0
  23. pawnai_matrix-0.2.0/alembic.ini +116 -0
  24. pawnai_matrix-0.2.0/config/sample.config.yaml +68 -0
  25. pawnai_matrix-0.2.0/config/tasks/.gitignore +3 -0
  26. pawnai_matrix-0.2.0/config/tasks/task.agenda.yml +14 -0
  27. pawnai_matrix-0.2.0/docker/Dockerfile +7 -0
  28. pawnai_matrix-0.2.0/docker/docker-compose.yaml +53 -0
  29. pawnai_matrix-0.2.0/docs/AUDIO_TRANSCRIPTION_COMPATIBILITY_PLAN.md +227 -0
  30. pawnai_matrix-0.2.0/docs/CONFIGURATION_STORAGE_SUMMARY.md +212 -0
  31. pawnai_matrix-0.2.0/docs/UTILS_ORGANIZATION_DIAGRAM.md +203 -0
  32. pawnai_matrix-0.2.0/docs/UTILS_QUICK_REFERENCE.md +248 -0
  33. pawnai_matrix-0.2.0/docs/UTILS_REORGANIZATION.md +191 -0
  34. pawnai_matrix-0.2.0/docs/UTILS_REORGANIZATION_SUMMARY.md +163 -0
  35. pawnai_matrix-0.2.0/docs/configuration_storage.md +264 -0
  36. pawnai_matrix-0.2.0/docs/pawn-agent.md +280 -0
  37. pawnai_matrix-0.2.0/docs/setup.md +173 -0
  38. pawnai_matrix-0.2.0/pawnai_matrix/__init__.py +28 -0
  39. pawnai_matrix-0.2.0/pawnai_matrix/__main__.py +4 -0
  40. pawnai_matrix-0.2.0/pawnai_matrix/_version.py +24 -0
  41. pawnai_matrix-0.2.0/pawnai_matrix/app.py +134 -0
  42. pawnai_matrix-0.2.0/pawnai_matrix/callbacks.py +277 -0
  43. pawnai_matrix-0.2.0/pawnai_matrix/cli.py +33 -0
  44. pawnai_matrix-0.2.0/pawnai_matrix/commands/__init__.py +6 -0
  45. pawnai_matrix-0.2.0/pawnai_matrix/commands/conversation_commands.py +87 -0
  46. pawnai_matrix-0.2.0/pawnai_matrix/commands/expert_commands.py +130 -0
  47. pawnai_matrix-0.2.0/pawnai_matrix/commands/index_commands.py +38 -0
  48. pawnai_matrix-0.2.0/pawnai_matrix/commands/room_config_commands.py +239 -0
  49. pawnai_matrix-0.2.0/pawnai_matrix/commands/session_commands.py +139 -0
  50. pawnai_matrix-0.2.0/pawnai_matrix/commands/system_commands.py +234 -0
  51. pawnai_matrix-0.2.0/pawnai_matrix/configuration.py +27 -0
  52. pawnai_matrix-0.2.0/pawnai_matrix/database.py +18 -0
  53. pawnai_matrix-0.2.0/pawnai_matrix/globals.py +207 -0
  54. pawnai_matrix-0.2.0/pawnai_matrix/listeners/__init__.py +0 -0
  55. pawnai_matrix-0.2.0/pawnai_matrix/listeners/room_listener.py +103 -0
  56. pawnai_matrix-0.2.0/pawnai_matrix/models.py +169 -0
  57. pawnai_matrix-0.2.0/pawnai_matrix/openai_client.py +68 -0
  58. pawnai_matrix-0.2.0/pawnai_matrix/processors/__init__.py +0 -0
  59. pawnai_matrix-0.2.0/pawnai_matrix/processors/audio_processor.py +343 -0
  60. pawnai_matrix-0.2.0/pawnai_matrix/processors/tts_processor.py +124 -0
  61. pawnai_matrix-0.2.0/pawnai_matrix/room.py +310 -0
  62. pawnai_matrix-0.2.0/pawnai_matrix/settings.py +145 -0
  63. pawnai_matrix-0.2.0/pawnai_matrix/utils/README.md +182 -0
  64. pawnai_matrix-0.2.0/pawnai_matrix/utils/__init__.py +65 -0
  65. pawnai_matrix-0.2.0/pawnai_matrix/utils/chat.py +230 -0
  66. pawnai_matrix-0.2.0/pawnai_matrix/utils/config.py +216 -0
  67. pawnai_matrix-0.2.0/pawnai_matrix/utils/decorators.py +106 -0
  68. pawnai_matrix-0.2.0/pawnai_matrix/utils/document.py +13 -0
  69. pawnai_matrix-0.2.0/pawnai_matrix/utils/errors.py +12 -0
  70. pawnai_matrix-0.2.0/pawnai_matrix.egg-info/PKG-INFO +83 -0
  71. pawnai_matrix-0.2.0/pawnai_matrix.egg-info/SOURCES.txt +81 -0
  72. pawnai_matrix-0.2.0/pawnai_matrix.egg-info/dependency_links.txt +1 -0
  73. pawnai_matrix-0.2.0/pawnai_matrix.egg-info/entry_points.txt +2 -0
  74. pawnai_matrix-0.2.0/pawnai_matrix.egg-info/requires.txt +17 -0
  75. pawnai_matrix-0.2.0/pawnai_matrix.egg-info/top_level.txt +8 -0
  76. pawnai_matrix-0.2.0/pyproject.toml +64 -0
  77. pawnai_matrix-0.2.0/scripts/import_yaml_config.py +105 -0
  78. pawnai_matrix-0.2.0/scripts/populate_config_defaults.py +86 -0
  79. pawnai_matrix-0.2.0/setup.cfg +7 -0
  80. pawnai_matrix-0.2.0/tests/test_free_speak.py +808 -0
  81. pawnai_matrix-0.2.0/tests/test_openai_client.py +73 -0
  82. pawnai_matrix-0.2.0/uv.lock +1770 -0
File without changes
@@ -0,0 +1,165 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # poetry
98
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102
+ #poetry.lock
103
+
104
+ # pdm
105
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106
+ #pdm.lock
107
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108
+ # in version control.
109
+ # https://pdm.fming.dev/#use-with-ide
110
+ .pdm.toml
111
+
112
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113
+ __pypackages__/
114
+
115
+ # Celery stuff
116
+ celerybeat-schedule
117
+ celerybeat.pid
118
+
119
+ # SageMath parsed files
120
+ *.sage.py
121
+
122
+ # Environments
123
+ .env
124
+ .venv
125
+ env/
126
+ venv/
127
+ ENV/
128
+ env.bak/
129
+ venv.bak/
130
+
131
+ # Spyder project settings
132
+ .spyderproject
133
+ .spyproject
134
+
135
+ # Rope project settings
136
+ .ropeproject
137
+
138
+ # mkdocs documentation
139
+ /site
140
+
141
+ # mypy
142
+ .mypy_cache/
143
+ .dmypy.json
144
+ dmypy.json
145
+
146
+ # Pyre type checker
147
+ .pyre/
148
+
149
+ # pytype static type analyzer
150
+ .pytype/
151
+
152
+ # Cython debug symbols
153
+ cython_debug/
154
+
155
+ # PyCharm
156
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
159
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
160
+ #.idea/
161
+
162
+
163
+ config.yaml
164
+ bob.db
165
+ store
@@ -0,0 +1,66 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - "v[0-9]+.[0-9]+.[0-9]*"
7
+
8
+ permissions:
9
+ contents: read
10
+
11
+ jobs:
12
+ build:
13
+ name: Build distribution
14
+ runs-on: ubuntu-latest
15
+
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+ with:
19
+ # Full history is required for setuptools-scm to derive the version
20
+ fetch-depth: 0
21
+
22
+ - name: Set up Python
23
+ uses: actions/setup-python@v5
24
+ with:
25
+ python-version: "3.12"
26
+
27
+ - name: Install build tools
28
+ run: python -m pip install --upgrade build
29
+
30
+ - name: Build sdist and wheel
31
+ run: python -m build
32
+
33
+ - name: Upload distribution artifacts
34
+ uses: actions/upload-artifact@v4
35
+ with:
36
+ name: dist
37
+ path: dist/
38
+
39
+ publish:
40
+ name: Publish to PyPI
41
+ needs: build
42
+ runs-on: ubuntu-latest
43
+
44
+ # Trusted Publishing: no API token needed — configure this environment
45
+ # on PyPI under your project's "Publishing" settings:
46
+ # Publisher: GitHub Actions
47
+ # Owner: <your-github-org-or-user>
48
+ # Repo: matrix-bob
49
+ # Workflow: publish.yml
50
+ # Environment: pypi
51
+ environment:
52
+ name: pypi
53
+ url: https://pypi.org/p/pawnai-matrix
54
+
55
+ permissions:
56
+ id-token: write # required for OIDC Trusted Publishing
57
+
58
+ steps:
59
+ - name: Download distribution artifacts
60
+ uses: actions/download-artifact@v4
61
+ with:
62
+ name: dist
63
+ path: dist/
64
+
65
+ - name: Publish to PyPI
66
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,172 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # poetry
98
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102
+ #poetry.lock
103
+
104
+ # pdm
105
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106
+ #pdm.lock
107
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108
+ # in version control.
109
+ # https://pdm.fming.dev/#use-with-ide
110
+ .pdm.toml
111
+
112
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113
+ __pypackages__/
114
+
115
+ # Celery stuff
116
+ celerybeat-schedule
117
+ celerybeat.pid
118
+
119
+ # SageMath parsed files
120
+ *.sage.py
121
+
122
+ # Environments
123
+ .env
124
+ .venv
125
+ env/
126
+ venv/
127
+ ENV/
128
+ env.bak/
129
+ venv.bak/
130
+
131
+ # Spyder project settings
132
+ .spyderproject
133
+ .spyproject
134
+
135
+ # Rope project settings
136
+ .ropeproject
137
+
138
+ # mkdocs documentation
139
+ /site
140
+
141
+ # mypy
142
+ .mypy_cache/
143
+ .dmypy.json
144
+ dmypy.json
145
+
146
+ # Pyre type checker
147
+ .pyre/
148
+
149
+ # pytype static type analyzer
150
+ .pytype/
151
+
152
+ # Cython debug symbols
153
+ cython_debug/
154
+
155
+ # PyCharm
156
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
159
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
160
+ #.idea/
161
+
162
+
163
+ config.yaml
164
+ bob.db
165
+ jobs.sqlite
166
+ store
167
+ tmp
168
+ .db
169
+ .idea
170
+
171
+ # Generated by setuptools-scm at build time
172
+ pawnai_matrix/_version.py
@@ -0,0 +1,100 @@
1
+ stages:
2
+ - maintenance
3
+ - build
4
+ - deploy
5
+
6
+ restart_ollama:
7
+ stage: maintenance
8
+ variables:
9
+ GIT_STRATEGY: none
10
+ GIT_CHECKOUT: "false"
11
+ tags:
12
+ - ollama
13
+ - shell
14
+ script:
15
+ - sudo systemctl restart ollama
16
+ - sleep 5
17
+ - sudo systemctl status ollama
18
+ when: manual
19
+
20
+ restart_pawnai_matrix:
21
+ stage: maintenance
22
+ variables:
23
+ GIT_STRATEGY: none
24
+ GIT_CHECKOUT: "false"
25
+ tags:
26
+ - matrix-bob
27
+ - shell
28
+ script:
29
+ - sudo systemctl restart matrix-bob
30
+ - sleep 5
31
+ - sudo systemctl status matrix-bob
32
+ when: manual
33
+
34
+ get_pawnai_matrix_logs:
35
+ stage: maintenance
36
+ variables:
37
+ GIT_STRATEGY: none
38
+ GIT_CHECKOUT: "false"
39
+ tags:
40
+ - matrix-bob
41
+ - shell
42
+ script:
43
+ - sudo journalctl -u matrix-bob -n 1000
44
+ when: manual
45
+
46
+ restart_qdrant:
47
+ stage: maintenance
48
+ variables:
49
+ GIT_STRATEGY: none
50
+ GIT_CHECKOUT: "false"
51
+ tags:
52
+ - matrix-bob
53
+ - shell
54
+ script:
55
+ - sudo systemctl restart docker-qdrant
56
+ - sleep 5
57
+ - sudo systemctl status docker-qdrant
58
+ when: manual
59
+
60
+ build_package:
61
+ stage: build
62
+ image: python:3.12
63
+ script:
64
+ - pip install build twine bump
65
+ - bump
66
+ - python -m build
67
+ - TWINE_PASSWORD=${CI_JOB_TOKEN} TWINE_USERNAME=gitlab-ci-token python -m twine upload --repository-url ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/pypi dist/*
68
+ - git config --global user.email "${GITLAB_USER_EMAIL}"
69
+ - git config --global user.name "${GITLAB_USER_NAME}"
70
+ - git remote set-url origin "https://gitlab-ci-token:${DEPLOY_TOKEN}@gitlab.com/${CI_PROJECT_NAMESPACE}/${CI_PROJECT_NAME}.git"
71
+ - git add .
72
+ - git commit -m "bump version"
73
+ - git push -o ci.skip --tags origin HEAD:${CI_COMMIT_REF_NAME}
74
+ only:
75
+ - master
76
+
77
+ deploy:
78
+ stage: deploy
79
+ variables:
80
+ GIT_STRATEGY: none
81
+ GIT_CHECKOUT: "false"
82
+ tags:
83
+ - matrix-bob
84
+ - shell
85
+ before_script:
86
+ - |
87
+ echo "
88
+ machine gitlab.com
89
+ login gitlab-ci-token
90
+ password $CI_JOB_TOKEN
91
+ " > ~/.netrc
92
+ script:
93
+ - cd /opt/matrix-bob
94
+ - source .venv/bin/activate
95
+ - pip install "matrix-bob" --upgrade --index-url ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/pypi/simple
96
+ - sudo systemctl restart matrix-bob
97
+ - sleep 5
98
+ - sudo systemctl status matrix-bob
99
+ only:
100
+ - master
@@ -0,0 +1,27 @@
1
+ {
2
+ // Use IntelliSense to learn about possible attributes.
3
+ // Hover to view descriptions of existing attributes.
4
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
+ "version": "0.2.0",
6
+ "configurations": [
7
+ {
8
+ "name": "Python Debugger: Run Bob",
9
+ "type": "debugpy",
10
+ "request": "launch",
11
+ "program": "${workspaceFolder}/bin/bob",
12
+ "console": "integratedTerminal",
13
+ "cwd": "${workspaceFolder}/bin",
14
+ "justMyCode": true
15
+ },
16
+ {
17
+ "name": "Python Debugger: scripts/import_yaml_config.py",
18
+ "type": "debugpy",
19
+ "request": "launch",
20
+ "program": "${workspaceFolder}/scripts/import_yaml_config.py",
21
+ "args": ["${workspaceFolder}/bin/config.yaml"],
22
+ "console": "integratedTerminal",
23
+ "cwd": "${workspaceFolder}/bin",
24
+ "justMyCode": true
25
+ }
26
+ ]
27
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "[python]": {
3
+ "editor.defaultFormatter": "eeyore.yapf"
4
+ }
5
+ }
File without changes
@@ -0,0 +1,96 @@
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
+ Matrix BOB is a Matrix protocol bot that integrates LLMs, vector search (RAG), audio transcription, and image processing into Matrix chat rooms. It uses `matrix-nio` for the Matrix client, LlamaIndex + Qdrant for RAG, and an OpenAI-compatible API (e.g. Ollama) for LLM inference.
8
+
9
+ ## Development Setup
10
+
11
+ ```bash
12
+ # Install in editable mode
13
+ python -m venv .venv
14
+ source .venv/bin/activate
15
+ pip install --editable .
16
+
17
+ # Start required services (Qdrant + PostgreSQL + Adminer)
18
+ cd docker && docker-compose up -d
19
+
20
+ # Run database migrations
21
+ alembic upgrade head
22
+
23
+ # Start the bot
24
+ ./bin/bob [config.yaml]
25
+ ```
26
+
27
+ Config file defaults to `bin/config.yaml`. Use `bin/sample.config.yaml` as a template.
28
+
29
+ ## Code Style
30
+
31
+ ```bash
32
+ flake8 pawnai_matrix/
33
+ isort pawnai_matrix/
34
+ ```
35
+
36
+ Flake8 ignores: W503, W504, E203, E731, E501. isort uses multi-line output mode 3 with trailing commas.
37
+
38
+ There are no automated tests.
39
+
40
+ ## Architecture
41
+
42
+ ### Global State (`pawnai_matrix/globals.py`)
43
+
44
+ All major singletons are initialized in `init(config_file_path)` and accessed via getter functions (`settings()`, `config()`, `store()`, `client()`, `room_manager()`). These raise `NotInitializedError` if called before initialization. `config()` returns a flat dict of all bot configuration loaded from the PostgreSQL `BotConfiguration` table (not the YAML directly — YAML populates defaults at startup).
45
+
46
+ ### Configuration System
47
+
48
+ Two-layer config:
49
+ 1. **YAML** (`bin/config.yaml`) — minimal bootstrap: DB connection string, Matrix credentials to seed into DB
50
+ 2. **Database** (`BotConfiguration` table) — runtime config as key-value pairs (e.g. `openai.default_model`, `matrix.command_prefix`). Accessed via `config().get('section.key')`. Use `utils/config.py` helpers (`get_value`, `set_value`, `get_config_dict`) for DB-level config access.
51
+
52
+ ### Command Dispatch (`pawnai_matrix/commands/`)
53
+
54
+ Commands flow: `SystemCommands` → `VisionCommands` → `ConversationCommands`. Each returns a truthy value if it handled the message. Commands use docopt-format docstrings parsed by the `@matrix_command` decorator. Power-user-only commands use `@power_user_function`.
55
+
56
+ `ConversationCommands` is the catch-all — it sends the message to the LLM chat engine.
57
+
58
+ ### Room Configuration (`pawnai_matrix/room.py`)
59
+
60
+ `Room` manages per-room state: assigned expert (LLM config preset), echo mode, index-conversation flag, vision two-step mode, and user display name mapping. Config is persisted to `RoomConfiguration` in PostgreSQL and cached in memory. Access via `room_manager().get(matrix_room)`.
61
+
62
+ ### LLM Client (`pawnai_matrix/openai_client.py`)
63
+
64
+ `OpenAIClient` wraps LlamaIndex with an OpenAI-compatible backend. It manages:
65
+ - LLM + embedding model initialization
66
+ - Qdrant vector store index (collection per room/expert)
67
+ - Chat engine (context mode or ReAct agent mode)
68
+ - `Expert` serialization (save/load named LLM configurations)
69
+
70
+ The client is lazily initialized and stored in the room's configuration dict.
71
+
72
+ ### Event Flow
73
+
74
+ ```
75
+ Matrix event → Callbacks (callbacks.py)
76
+ ├── Text message → RoomListener.store_message_text → SystemCommands → VisionCommands → ConversationCommands
77
+ ├── Audio → RoomListener.transcribe_audio_message → AudioProcessor (Whisper) → command or index
78
+ ├── Image → RoomListener.describe_image → ImageProcessor (vision model) → index
79
+ └── File → RoomListener.store_file → LlamaIndex SimpleDirectoryReader → index
80
+ ```
81
+
82
+ ### Database Models (`pawnai_matrix/models.py`)
83
+
84
+ - `Expert` — named LLM configurations (JSON-serialized `OpenAIClient` state)
85
+ - `RoomConfiguration` — per-room expert assignment + config blob
86
+ - `BotConfiguration` — global key-value config store
87
+ - `RoomMessage` — message history (room_id, author, text, timestamp)
88
+
89
+ Migrations are in `alembic/versions/`.
90
+
91
+ ## Key Patterns
92
+
93
+ - **Async throughout**: All callbacks and processors are `async`. `nest_asyncio` is applied at startup to allow nested event loops.
94
+ - **Encrypted room support**: `matrix-nio[e2e]` handles E2EE. File downloads use `download_event_resources()` context manager which handles decryption and temp file cleanup.
95
+ - **Reply chains**: `get_related_reply_to_events()` in `utils/chat.py` recursively fetches reply chains to build conversation context.
96
+ - **Debug state**: Processing artifacts (transcriptions, vision descriptions, last error) are stored globally via `set_debug_*` and retrievable via `!bob debug` commands.