plural-agent 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 (156) hide show
  1. plural_agent-0.1.0/.github/workflows/ci.yml +23 -0
  2. plural_agent-0.1.0/.github/workflows/release.yml +52 -0
  3. plural_agent-0.1.0/.gitignore +81 -0
  4. plural_agent-0.1.0/CONTRIBUTING.md +8 -0
  5. plural_agent-0.1.0/LICENSE +202 -0
  6. plural_agent-0.1.0/PKG-INFO +316 -0
  7. plural_agent-0.1.0/README.md +281 -0
  8. plural_agent-0.1.0/SECURITY.md +5 -0
  9. plural_agent-0.1.0/deploy/Caddyfile +3 -0
  10. plural_agent-0.1.0/deploy/docker-compose.yml +17 -0
  11. plural_agent-0.1.0/deploy/relay.Dockerfile +8 -0
  12. plural_agent-0.1.0/docs/adr/0001-hexagonal-event-sourced-host.md +14 -0
  13. plural_agent-0.1.0/docs/adr/0002-own-harness-official-sdk-providers.md +16 -0
  14. plural_agent-0.1.0/docs/adr/0003-simple-compaction.md +44 -0
  15. plural_agent-0.1.0/docs/protocol.md +13 -0
  16. plural_agent-0.1.0/docs/threat-model.md +17 -0
  17. plural_agent-0.1.0/install.sh +36 -0
  18. plural_agent-0.1.0/pyproject.toml +155 -0
  19. plural_agent-0.1.0/scripts/gen_schema.py +38 -0
  20. plural_agent-0.1.0/scripts/install.sh +10 -0
  21. plural_agent-0.1.0/src/plural/__init__.py +1 -0
  22. plural_agent-0.1.0/src/plural/agent/__init__.py +0 -0
  23. plural_agent-0.1.0/src/plural/agent/compaction.py +28 -0
  24. plural_agent-0.1.0/src/plural/agent/context.py +20 -0
  25. plural_agent-0.1.0/src/plural/agent/events.py +50 -0
  26. plural_agent-0.1.0/src/plural/agent/gate.py +18 -0
  27. plural_agent-0.1.0/src/plural/agent/interrupt.py +29 -0
  28. plural_agent-0.1.0/src/plural/agent/loop.py +414 -0
  29. plural_agent-0.1.0/src/plural/agent/messages.py +73 -0
  30. plural_agent-0.1.0/src/plural/agent/providers/__init__.py +0 -0
  31. plural_agent-0.1.0/src/plural/agent/providers/anthropic_api.py +204 -0
  32. plural_agent-0.1.0/src/plural/agent/providers/base.py +90 -0
  33. plural_agent-0.1.0/src/plural/agent/providers/fake.py +69 -0
  34. plural_agent-0.1.0/src/plural/agent/providers/openai_compat.py +209 -0
  35. plural_agent-0.1.0/src/plural/agent/sandbox/__init__.py +0 -0
  36. plural_agent-0.1.0/src/plural/agent/sandbox/base.py +72 -0
  37. plural_agent-0.1.0/src/plural/agent/sandbox/local.py +76 -0
  38. plural_agent-0.1.0/src/plural/agent/tools/__init__.py +0 -0
  39. plural_agent-0.1.0/src/plural/agent/tools/base.py +97 -0
  40. plural_agent-0.1.0/src/plural/agent/tools/bash.py +40 -0
  41. plural_agent-0.1.0/src/plural/agent/tools/diffs.py +22 -0
  42. plural_agent-0.1.0/src/plural/agent/tools/edit.py +35 -0
  43. plural_agent-0.1.0/src/plural/agent/tools/glob.py +43 -0
  44. plural_agent-0.1.0/src/plural/agent/tools/grep.py +57 -0
  45. plural_agent-0.1.0/src/plural/agent/tools/ls.py +31 -0
  46. plural_agent-0.1.0/src/plural/agent/tools/read.py +30 -0
  47. plural_agent-0.1.0/src/plural/agent/tools/registry.py +42 -0
  48. plural_agent-0.1.0/src/plural/agent/tools/truncation.py +29 -0
  49. plural_agent-0.1.0/src/plural/agent/tools/write.py +31 -0
  50. plural_agent-0.1.0/src/plural/cli/__init__.py +0 -0
  51. plural_agent-0.1.0/src/plural/cli/main.py +192 -0
  52. plural_agent-0.1.0/src/plural/cli/output.py +61 -0
  53. plural_agent-0.1.0/src/plural/client/__init__.py +0 -0
  54. plural_agent-0.1.0/src/plural/client/connection.py +95 -0
  55. plural_agent-0.1.0/src/plural/client/presenter.py +155 -0
  56. plural_agent-0.1.0/src/plural/client/projection.py +55 -0
  57. plural_agent-0.1.0/src/plural/client/reconnect.py +108 -0
  58. plural_agent-0.1.0/src/plural/client/slash.py +49 -0
  59. plural_agent-0.1.0/src/plural/core/__init__.py +0 -0
  60. plural_agent-0.1.0/src/plural/core/approvals.py +24 -0
  61. plural_agent-0.1.0/src/plural/core/errors.py +30 -0
  62. plural_agent-0.1.0/src/plural/core/policies.py +66 -0
  63. plural_agent-0.1.0/src/plural/core/policy/__init__.py +0 -0
  64. plural_agent-0.1.0/src/plural/core/policy/engine.py +55 -0
  65. plural_agent-0.1.0/src/plural/core/policy/rejections.py +46 -0
  66. plural_agent-0.1.0/src/plural/core/policy/rules.py +55 -0
  67. plural_agent-0.1.0/src/plural/core/ports.py +24 -0
  68. plural_agent-0.1.0/src/plural/core/proposals.py +38 -0
  69. plural_agent-0.1.0/src/plural/core/provenance.py +19 -0
  70. plural_agent-0.1.0/src/plural/core/roles.py +53 -0
  71. plural_agent-0.1.0/src/plural/core/state.py +125 -0
  72. plural_agent-0.1.0/src/plural/host/__init__.py +0 -0
  73. plural_agent-0.1.0/src/plural/host/actor.py +502 -0
  74. plural_agent-0.1.0/src/plural/host/agent_run.py +69 -0
  75. plural_agent-0.1.0/src/plural/host/approval_registry.py +23 -0
  76. plural_agent-0.1.0/src/plural/host/attachments.py +19 -0
  77. plural_agent-0.1.0/src/plural/host/bootstrap.py +188 -0
  78. plural_agent-0.1.0/src/plural/host/config.py +43 -0
  79. plural_agent-0.1.0/src/plural/host/gateway.py +70 -0
  80. plural_agent-0.1.0/src/plural/host/inbox.py +48 -0
  81. plural_agent-0.1.0/src/plural/host/invites.py +39 -0
  82. plural_agent-0.1.0/src/plural/host/policy_gate.py +81 -0
  83. plural_agent-0.1.0/src/plural/host/publisher.py +77 -0
  84. plural_agent-0.1.0/src/plural/host/system.py +21 -0
  85. plural_agent-0.1.0/src/plural/host/transport/__init__.py +0 -0
  86. plural_agent-0.1.0/src/plural/host/transport/base.py +19 -0
  87. plural_agent-0.1.0/src/plural/host/transport/direct.py +82 -0
  88. plural_agent-0.1.0/src/plural/host/transport/relay_link.py +106 -0
  89. plural_agent-0.1.0/src/plural/protocol/__init__.py +0 -0
  90. plural_agent-0.1.0/src/plural/protocol/capability.py +12 -0
  91. plural_agent-0.1.0/src/plural/protocol/codec.py +112 -0
  92. plural_agent-0.1.0/src/plural/protocol/commands.py +116 -0
  93. plural_agent-0.1.0/src/plural/protocol/envelope.py +48 -0
  94. plural_agent-0.1.0/src/plural/protocol/events.py +237 -0
  95. plural_agent-0.1.0/src/plural/protocol/models.py +177 -0
  96. plural_agent-0.1.0/src/plural/protocol/relay.py +28 -0
  97. plural_agent-0.1.0/src/plural/relay/__init__.py +0 -0
  98. plural_agent-0.1.0/src/plural/relay/app.py +33 -0
  99. plural_agent-0.1.0/src/plural/relay/limits.py +34 -0
  100. plural_agent-0.1.0/src/plural/relay/rooms.py +150 -0
  101. plural_agent-0.1.0/src/plural/security/__init__.py +0 -0
  102. plural_agent-0.1.0/src/plural/security/keys.py +25 -0
  103. plural_agent-0.1.0/src/plural/security/secrets.py +63 -0
  104. plural_agent-0.1.0/src/plural/security/tokens.py +65 -0
  105. plural_agent-0.1.0/src/plural/storage/__init__.py +0 -0
  106. plural_agent-0.1.0/src/plural/storage/jsonl_export.py +11 -0
  107. plural_agent-0.1.0/src/plural/storage/migrations/0001_init.sql +13 -0
  108. plural_agent-0.1.0/src/plural/storage/migrations/__init__.py +30 -0
  109. plural_agent-0.1.0/src/plural/storage/sqlite_store.py +75 -0
  110. plural_agent-0.1.0/src/plural/tui/__init__.py +0 -0
  111. plural_agent-0.1.0/src/plural/tui/app.py +184 -0
  112. plural_agent-0.1.0/src/plural/tui/widgets/__init__.py +0 -0
  113. plural_agent-0.1.0/src/plural/tui/widgets/dialogs.py +58 -0
  114. plural_agent-0.1.0/src/plural/tui/widgets/policy.py +100 -0
  115. plural_agent-0.1.0/src/plural/tui/widgets/sidebar.py +25 -0
  116. plural_agent-0.1.0/src/plural/tui/widgets/transcript.py +18 -0
  117. plural_agent-0.1.0/tests/__init__.py +0 -0
  118. plural_agent-0.1.0/tests/doubles.py +46 -0
  119. plural_agent-0.1.0/tests/e2e/__init__.py +0 -0
  120. plural_agent-0.1.0/tests/e2e/conftest.py +25 -0
  121. plural_agent-0.1.0/tests/e2e/support.py +133 -0
  122. plural_agent-0.1.0/tests/e2e/test_abort.py +56 -0
  123. plural_agent-0.1.0/tests/e2e/test_compaction.py +69 -0
  124. plural_agent-0.1.0/tests/e2e/test_flow.py +135 -0
  125. plural_agent-0.1.0/tests/e2e/test_policy.py +152 -0
  126. plural_agent-0.1.0/tests/e2e/test_rejections.py +57 -0
  127. plural_agent-0.1.0/tests/e2e/test_tui.py +101 -0
  128. plural_agent-0.1.0/tests/fixtures/protocol/prompt_submit.json +20 -0
  129. plural_agent-0.1.0/tests/harness/test_compaction.py +200 -0
  130. plural_agent-0.1.0/tests/harness/test_loop.py +294 -0
  131. plural_agent-0.1.0/tests/integration/test_host_flow.py +193 -0
  132. plural_agent-0.1.0/tests/loop_support.py +61 -0
  133. plural_agent-0.1.0/tests/unit/test_bootstrap.py +39 -0
  134. plural_agent-0.1.0/tests/unit/test_cli.py +64 -0
  135. plural_agent-0.1.0/tests/unit/test_policies.py +136 -0
  136. plural_agent-0.1.0/tests/unit/test_policy.py +75 -0
  137. plural_agent-0.1.0/tests/unit/test_policy_gate.py +104 -0
  138. plural_agent-0.1.0/tests/unit/test_presenter.py +128 -0
  139. plural_agent-0.1.0/tests/unit/test_projection.py +24 -0
  140. plural_agent-0.1.0/tests/unit/test_protocol.py +56 -0
  141. plural_agent-0.1.0/tests/unit/test_providers.py +376 -0
  142. plural_agent-0.1.0/tests/unit/test_rejections.py +89 -0
  143. plural_agent-0.1.0/tests/unit/test_roles.py +17 -0
  144. plural_agent-0.1.0/tests/unit/test_security.py +64 -0
  145. plural_agent-0.1.0/tests/unit/test_sqlite_store.py +26 -0
  146. plural_agent-0.1.0/tests/unit/test_state.py +88 -0
  147. plural_agent-0.1.0/tests/unit/test_tools.py +59 -0
  148. plural_agent-0.1.0/uv.lock +1813 -0
  149. plural_agent-0.1.0/web/index.html +12 -0
  150. plural_agent-0.1.0/web/package.json +23 -0
  151. plural_agent-0.1.0/web/src/components/App.tsx +8 -0
  152. plural_agent-0.1.0/web/src/main.tsx +9 -0
  153. plural_agent-0.1.0/web/src/protocol/schema.json +2091 -0
  154. plural_agent-0.1.0/web/src/state/reduce.ts +44 -0
  155. plural_agent-0.1.0/web/tsconfig.json +14 -0
  156. plural_agent-0.1.0/web/vite.config.ts +4 -0
@@ -0,0 +1,23 @@
1
+ name: ci
2
+ on:
3
+ push:
4
+ branches: [main]
5
+ pull_request:
6
+
7
+ jobs:
8
+ python:
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - uses: actions/checkout@v4
12
+ - uses: astral-sh/setup-uv@v5
13
+ with:
14
+ python-version: "3.12"
15
+ - run: uv sync --frozen
16
+ - run: uv run ruff check .
17
+ - run: uv run ruff format --check .
18
+ - run: uv run pyright
19
+ - run: uv run lint-imports
20
+ - run: uv run python scripts/gen_schema.py --check
21
+ - run: uv run coverage run -m pytest && uv run coverage report
22
+ - run: uv run pip-audit
23
+
@@ -0,0 +1,52 @@
1
+ name: release
2
+ on:
3
+ push:
4
+ tags: ["v*"]
5
+
6
+ jobs:
7
+ build:
8
+ runs-on: ubuntu-latest
9
+ steps:
10
+ - uses: actions/checkout@v4
11
+ - uses: astral-sh/setup-uv@v5
12
+ with:
13
+ python-version: "3.12"
14
+ - name: Check tag matches package version
15
+ run: |
16
+ version=$(sed -n 's/^__version__ = "\(.*\)"/\1/p' src/plural/__init__.py)
17
+ test "v${version}" = "${GITHUB_REF_NAME}"
18
+ - run: uv sync --frozen
19
+ - run: uv run pytest
20
+ - run: uv build
21
+ - uses: actions/upload-artifact@v4
22
+ with:
23
+ name: dist
24
+ path: dist/
25
+
26
+ publish:
27
+ needs: build
28
+ runs-on: ubuntu-latest
29
+ environment: pypi
30
+ permissions:
31
+ id-token: write
32
+ steps:
33
+ - uses: actions/download-artifact@v4
34
+ with:
35
+ name: dist
36
+ path: dist/
37
+ - uses: pypa/gh-action-pypi-publish@release/v1
38
+
39
+ github-release:
40
+ needs: publish
41
+ runs-on: ubuntu-latest
42
+ permissions:
43
+ contents: write
44
+ steps:
45
+ - uses: actions/download-artifact@v4
46
+ with:
47
+ name: dist
48
+ path: dist/
49
+ - uses: softprops/action-gh-release@v2
50
+ with:
51
+ files: dist/*
52
+ generate_release_notes: true
@@ -0,0 +1,81 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.so
6
+ *.egg
7
+ *.egg-info/
8
+ .eggs/
9
+ build/
10
+ dist/
11
+ wheels/
12
+ sdist/
13
+ pip-wheel-metadata/
14
+ *.manifest
15
+ *.spec
16
+
17
+ # Virtual environments
18
+ .venv/
19
+ venv/
20
+ env/
21
+ ENV/
22
+ .python-version
23
+
24
+ # Tooling caches
25
+ .pytest_cache/
26
+ .ruff_cache/
27
+ .mypy_cache/
28
+ .pyright/
29
+ .hypothesis/
30
+ .import_linter_cache/
31
+ .tox/
32
+ .nox/
33
+ .cache/
34
+
35
+ # Coverage
36
+ .coverage
37
+ .coverage.*
38
+ coverage.xml
39
+ htmlcov/
40
+ *.cover
41
+
42
+ # Secrets and local config
43
+ .env
44
+ .env.*
45
+ !.env.example
46
+ *.pem
47
+ *.key
48
+ secrets/
49
+
50
+ # Plural runtime data
51
+ .plural/
52
+ *.sqlite
53
+ *.sqlite-wal
54
+ *.sqlite-shm
55
+ *.db
56
+ *.db-wal
57
+ *.db-shm
58
+ session*.jsonl
59
+ *.log
60
+
61
+ # Web
62
+ web/node_modules/
63
+ web/dist/
64
+ web/.vite/
65
+ web/src/protocol/types.ts
66
+ npm-debug.log*
67
+ yarn-error.log*
68
+ pnpm-debug.log*
69
+
70
+ # Editors and OS
71
+ .idea/
72
+ .vscode/
73
+ *.swp
74
+ *.swo
75
+ *~
76
+ .DS_Store
77
+ Thumbs.db
78
+
79
+ # Local agent notes
80
+ .claude/
81
+ CLAUDE.local.md
@@ -0,0 +1,8 @@
1
+ # Contributing
2
+
3
+ - Sign off every commit (`git commit -s`), we use the [DCO](https://developercertificate.org/).
4
+ - Conventional Commits, small PRs.
5
+ - Respect layer contracts (`uv run lint-imports`): `protocol` and `core` do no I/O, `relay` never decides permissions.
6
+ - Every tool call goes through `PolicyGate`. No bypasses, not even temporary ones.
7
+ - Protocol change: models → `uv run python scripts/gen_schema.py` → `docs/protocol.md` → golden fixtures.
8
+ - New behaviour ships with tests; harness tests use `FakeProvider`.
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,316 @@
1
+ Metadata-Version: 2.5
2
+ Name: plural-agent
3
+ Version: 0.1.0
4
+ Summary: Multiplayer sessions for one AI agent: shared context, host approvals, attribution, isolation.
5
+ Project-URL: Homepage, https://github.com/Plural-Organization/Plural
6
+ Project-URL: Issues, https://github.com/Plural-Organization/Plural/issues
7
+ Project-URL: Changelog, https://github.com/Plural-Organization/Plural/releases
8
+ Author: Plural team
9
+ License-Expression: Apache-2.0
10
+ License-File: LICENSE
11
+ Keywords: agent,ai,coding-agent,llm,multiplayer,tui
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Environment :: Console
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: Apache Software License
16
+ Classifier: Operating System :: MacOS
17
+ Classifier: Operating System :: POSIX :: Linux
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Software Development
20
+ Requires-Python: >=3.12
21
+ Requires-Dist: aiosqlite>=0.21
22
+ Requires-Dist: anthropic>=2.3.0
23
+ Requires-Dist: cryptography>=44
24
+ Requires-Dist: openai>=3.37.0
25
+ Requires-Dist: pydantic-settings>=2.8
26
+ Requires-Dist: pydantic>=2.11
27
+ Requires-Dist: rich>=13.9
28
+ Requires-Dist: starlette>=0.46
29
+ Requires-Dist: structlog>=25.1
30
+ Requires-Dist: textual>=2.1
31
+ Requires-Dist: typer>=0.15
32
+ Requires-Dist: uvicorn>=0.34
33
+ Requires-Dist: websockets>=15
34
+ Description-Content-Type: text/markdown
35
+
36
+ <div align="center">
37
+
38
+ # Plural
39
+
40
+ **Multiplayer sessions for one AI coding agent.**
41
+
42
+ One agent. One host. Everyone in the room.
43
+
44
+ [![Python](https://img.shields.io/badge/python-3.12%2B-3776AB?logo=python&logoColor=white)](https://www.python.org/downloads/)
45
+ [![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](LICENSE)
46
+ [![uv](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json)](https://github.com/astral-sh/uv)
47
+ [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
48
+ [![Checked with pyright](https://microsoft.github.io/pyright/img/pyright_badge.svg)](https://microsoft.github.io/pyright/)
49
+ [![Status](https://img.shields.io/badge/status-alpha-orange.svg)](#roadmap)
50
+
51
+ [Quick start](#quick-start) · [How it works](#how-it-works) · [Security](#security-model) · [Architecture](#architecture) · [Contributing](#contributing)
52
+
53
+ </div>
54
+
55
+ ---
56
+
57
+ Plural turns a solo AI agent session into a shared one. The agent runs on the **host's machine** with the **host's API key**. Teammates join from a terminal or a browser, watch the run live, and propose prompts. The host stays in control: every proposal and every risky tool call goes through the host's approval.
58
+
59
+ ```text
60
+ ┌────────────┐ ┌──────────────┐ ┌─────────────┐
61
+ │ guest TUI │◀──ws──▶│ │◀──ws──▶│ host │
62
+ ├────────────┤ │ relay │ │ ├ agent │──▶ LLM API
63
+ │ guest web │◀──ws──▶│ (optional, │ │ ├ policy │
64
+ └────────────┘ │ dumb pipe) │ │ ├ tools │──▶ workspace
65
+ └──────────────┘ │ └ event log│
66
+ └─────────────┘
67
+ ```
68
+
69
+ ## Features
70
+
71
+ - **Shared live session.** Everyone sees the same transcript, tool calls and diffs as they stream.
72
+ - **Proposals, not prompts.** Guests suggest prompts. The host approves, edits or rejects them.
73
+ - **Host-only approvals.** Write and exec actions need host consent. Guest-originated turns are tainted and always ask. Rejected actions are not re-asked: after repeated rejections of the same kind the agent is told to ask the user instead, and "Block (session)" denies a whole command class.
74
+ - **Attribution.** Every turn records who wrote it and who approved it.
75
+ - **Policy engine.** Allow, ask and deny rules with last-match-wins. Base deny rules cannot be overridden.
76
+ - **Event-sourced.** An append-only SQLite log is the source of truth. Reconnect, replay and audit come for free.
77
+ - **Isolation.** Tools are confined to the workspace. Secret paths are denied and output is redacted.
78
+ - **Direct or relayed.** Connect over LAN directly, or through a relay that never sees permissions and never stores content.
79
+ - **Terminal clients.** A Textual TUI and a plain line mode. A browser client is in progress.
80
+ - **Bring your own key.** API keys only. Plural never touches subscription credentials.
81
+
82
+ ## Requirements
83
+
84
+ - Python **3.12** or newer
85
+ - [uv](https://docs.astral.sh/uv/) 0.5+
86
+ - macOS or Linux (Windows through WSL)
87
+ - Node.js 22+ (only to work on the in-progress web client)
88
+
89
+ ## Installation
90
+
91
+ ```sh
92
+ curl -fsSL https://raw.githubusercontent.com/Plural-Organization/Plural/main/install.sh | sh
93
+ ```
94
+
95
+ The script installs [uv](https://docs.astral.sh/uv/) if it is missing, then Plural. Or install it yourself:
96
+
97
+ ```sh
98
+ uv tool install plural-agent
99
+ ```
100
+
101
+ The package is `plural-agent`; it installs the `plural` command. Other ways:
102
+
103
+ ```sh
104
+ pipx install plural-agent
105
+ uvx --from plural-agent plural host
106
+ ```
107
+
108
+ From source, clone the repository and run from its root:
109
+
110
+ ```sh
111
+ uv sync
112
+ ```
113
+
114
+ Check your environment:
115
+
116
+ ```sh
117
+ plural doctor
118
+ ```
119
+
120
+ ## Quick start
121
+
122
+ Start a session in your project:
123
+
124
+ ```sh
125
+ uv run plural host --workspace .
126
+ ```
127
+
128
+ The host prints a one-time invite link and opens the TUI. Send the link to a teammate:
129
+
130
+ ```sh
131
+ uv run plural join "ws://127.0.0.1:7777/r_…?invite=…" --name alia
132
+ ```
133
+
134
+ The default provider is `fake`, a scripted demo that needs no API key. Plain text lists the workspace. `$ cmd` asks to run `cmd` through `bash` and waits for host approval.
135
+
136
+ ### Through a relay
137
+
138
+ ```sh
139
+ uv run plural relay --bind 0.0.0.0 --port 8787
140
+ uv run plural host --relay wss://relay.example.com
141
+ ```
142
+
143
+ A ready-made deployment with Caddy and TLS lives in [`deploy/`](deploy/).
144
+
145
+ ## Usage
146
+
147
+ ### Commands
148
+
149
+ | Command | Purpose |
150
+ |---|---|
151
+ | `plural host` | Start a host session, direct mode or `--relay URL` |
152
+ | `plural join <link>` | Join as a guest, `--plain` for a line-mode stream |
153
+ | `plural relay` | Run the relay router |
154
+ | `plural doctor` | Check the environment and workspace |
155
+ | `plural export <room>` | Dump a session's event log to JSONL |
156
+
157
+ Run `plural <command> --help` for all options.
158
+
159
+ ### TUI keys
160
+
161
+ | Key | Action |
162
+ |---|---|
163
+ | `ctrl+r` | Review pending proposals and approvals |
164
+ | `ctrl+o` | Create an invite link |
165
+ | `ctrl+p` | View and edit session policy rules (host) |
166
+ | `esc` | Abort the current run |
167
+ | `ctrl+q` | Quit |
168
+
169
+ Prompt-line commands work in the TUI and in `plural join --plain`: `/abort`, `/compact`, `/policy` (list rules), `/policy allow|ask|deny <tool> <pattern>`, `/policy rm <rule id>`.
170
+
171
+ ### Configuration
172
+
173
+ Every setting can be passed as an environment variable with the `PLURAL_` prefix.
174
+
175
+ | Variable | Default | Description |
176
+ |---|---|---|
177
+ | `PLURAL_PROVIDER` | `fake` | `fake`, `anthropic` or `openai` |
178
+ | `PLURAL_MODEL` | `claude-opus-5-5` for `anthropic` | Model id, required for `openai` |
179
+ | `PLURAL_API_KEY` | `ANTHROPIC_API_KEY` / `OPENAI_API_KEY` | Provider API key |
180
+ | `PLURAL_BASE_URL` | provider default | Custom endpoint, e.g. a local OpenAI-compatible server |
181
+ | `PLURAL_EFFORT` | provider default | `low`, `medium`, `high`, `xhigh` or `max` |
182
+ | `PLURAL_MAX_OUTPUT_TOKENS` | provider default | Output token cap per model response |
183
+ | `PLURAL_WORKSPACE` | current directory | Directory the agent works in |
184
+ | `PLURAL_DATA_DIR` | `~/.plural` | Event logs, host key, attachments |
185
+ | `PLURAL_BIND_HOST` | `127.0.0.1` | Bind address for direct mode |
186
+ | `PLURAL_PORT` | `7777` | Port for direct mode |
187
+ | `PLURAL_RELAY_URL` | none | Relay URL |
188
+ | `PLURAL_PUBLIC_URL` | none | Public URL used in invite links |
189
+ | `PLURAL_FIRST_TOKEN_TIMEOUT_S` | `120` | Seconds to wait for the model's first output before the run fails |
190
+ | `PLURAL_IDLE_TIMEOUT_S` | `60` | Seconds of silence mid-response before the run fails |
191
+ | `PLURAL_CONTEXT_WINDOW` | `128000` | Model context size in tokens; set it to the server's real window for local models |
192
+ | `PLURAL_COMPACT_AT` | `0.75` | Fraction of the window at which the conversation is summarized |
193
+ | `PLURAL_APPROVAL_TIMEOUT_S` | `120` | Seconds before an approval expires |
194
+ | `PLURAL_REJECTION_LIMIT` | `2` | Rejections of one kind of action per run before the agent stops asking the host |
195
+ | `PLURAL_TOKEN_TTL_S` | `86400` | Capability token lifetime, at most 24h |
196
+ | `PLURAL_INVITE_TTL_S` | `3600` | Invite link lifetime |
197
+
198
+ ### Providers
199
+
200
+ Two adapters cover most models: `anthropic` uses the official Anthropic SDK, and `openai` speaks the OpenAI Chat Completions format, which also covers OpenRouter, Groq, Gemini, DeepSeek and local servers such as Ollama.
201
+
202
+ ```sh
203
+ PLURAL_PROVIDER=anthropic ANTHROPIC_API_KEY=sk-ant-... plural host
204
+
205
+ PLURAL_PROVIDER=openai PLURAL_MODEL=gpt-5 OPENAI_API_KEY=sk-... plural host
206
+
207
+ PLURAL_PROVIDER=openai PLURAL_MODEL=qwen2.5-coder PLURAL_BASE_URL=http://localhost:11434/v1 plural host
208
+ ```
209
+
210
+ > [!NOTE]
211
+ > Local servers truncate silently when a prompt exceeds their window (Ollama defaults to 4096 tokens). Start the server with a larger window (`OLLAMA_CONTEXT_LENGTH`) and set `PLURAL_CONTEXT_WINDOW` to the same value so compaction triggers in time.
212
+
213
+ > [!IMPORTANT]
214
+ > Plural uses API keys only. It never reads subscription logins or other credentials stored by vendor tools.
215
+
216
+ ## How it works
217
+
218
+ 1. The **host** starts a session. A `SessionActor` owns the room and processes every command in order: append to the log, reduce state, publish.
219
+ 2. A **guest** joins with an invite and receives a signed Ed25519 capability token bound to the room and connection.
220
+ 3. The guest **proposes** a prompt. The host approves it, and it enters the agent's queue attributed as `[alia, proposal approved by host]`.
221
+ 4. The **agent loop** streams the model's reply. Each tool call is prepared, evaluated by the `PolicyGate`, and either runs, waits for the host, or is denied.
222
+ 5. Every event goes to the **event log** first and is then fanned out to clients. A client that reconnects asks for events `since` its last `seq`.
223
+
224
+ ## Security model
225
+
226
+ - The agent and the API key live only on the host. Guests never see the key.
227
+ - Permission decisions are made only by the host. The relay is a dumb pipe.
228
+ - No tool runs without passing the `PolicyGate`. There are no bypasses.
229
+ - Tools are confined to the workspace with `realpath` checks and a deny-list for secret files such as `.env`, keys and credentials.
230
+ - `bash` runs with a clean environment, in its own process group, with a timeout.
231
+ - Secrets are redacted before anything is written to the log or sent to clients.
232
+
233
+ See [`SECURITY.md`](SECURITY.md) to report a vulnerability and [`docs/threat-model.md`](docs/threat-model.md) for the full threat model.
234
+
235
+ ## Architecture
236
+
237
+ Plural is a hexagonal, event-sourced Python app. Layers are enforced with `import-linter`.
238
+
239
+ ```text
240
+ src/plural/
241
+ ├── protocol/ wire models, envelope, codec (pure)
242
+ ├── core/ state reducer, roles, policy engine (pure)
243
+ ├── security/ tokens, host keys, redaction
244
+ ├── agent/ harness: loop, tools, sandbox, providers
245
+ ├── storage/ SQLite event store, migrations, export
246
+ ├── host/ session actor, gateway, transports
247
+ ├── relay/ dumb relay router
248
+ ├── client/ connection, reconnect, projection
249
+ ├── cli/ Typer entry point
250
+ └── tui/ Textual app
251
+ web/ browser client (in progress)
252
+ ```
253
+
254
+ - `core` and `protocol` do no I/O.
255
+ - `agent` knows nothing about transports or storage.
256
+ - `relay` knows nothing about sessions, policy or content.
257
+ - `client` knows nothing about the host internals.
258
+
259
+ Design notes: [`docs/adr/`](docs/adr/) · Wire protocol: [`docs/protocol.md`](docs/protocol.md)
260
+
261
+ ## Development
262
+
263
+ ```sh
264
+ uv sync
265
+ uv run pytest
266
+ ```
267
+
268
+ Full check, the same one CI runs:
269
+
270
+ ```sh
271
+ uv run ruff check . && uv run ruff format --check . && uv run pyright && uv run lint-imports && uv run pytest
272
+ ```
273
+
274
+ Regenerate the protocol JSON schema for the web client:
275
+
276
+ ```sh
277
+ uv run python scripts/gen_schema.py
278
+ ```
279
+
280
+ Web client (in progress):
281
+
282
+ ```sh
283
+ cd web
284
+ npm ci
285
+ npm run dev
286
+ ```
287
+
288
+ ## Roadmap
289
+
290
+ - [x] Protocol, event log and session actor
291
+ - [x] Policy engine and host approvals
292
+ - [x] Workspace tools and local sandbox
293
+ - [x] Direct and relay transports
294
+ - [x] TUI and plain clients
295
+ - [x] Anthropic and OpenAI-compatible providers
296
+ - [ ] Web client (in progress)
297
+ - [x] Context compaction
298
+ - [ ] Container sandbox
299
+ - [ ] End-to-end and load tests
300
+
301
+ ## Contributing
302
+
303
+ Contributions are welcome. Read [`CONTRIBUTING.md`](CONTRIBUTING.md) first. In short:
304
+
305
+ - Open an issue before large changes.
306
+ - Use [Conventional Commits](https://www.conventionalcommits.org/).
307
+ - New dependencies need discussion, and large ones need an ADR.
308
+ - Make sure the full check passes.
309
+
310
+ ## Acknowledgements
311
+
312
+ Plural learns from [Pi](https://github.com/badlogic/pi-mono), [OpenCode](https://github.com/sst/opencode) and [Hermes](https://github.com/NousResearch/hermes-agent).
313
+
314
+ ## License
315
+
316
+ Plural is licensed under the [Apache License 2.0](LICENSE).