dreamer-server 0.1.0__py3-none-any.whl

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 (88) hide show
  1. dreamer/__init__.py +1 -0
  2. dreamer/api/__init__.py +152 -0
  3. dreamer/api/audit.py +22 -0
  4. dreamer/api/auth.py +37 -0
  5. dreamer/api/capabilities.py +78 -0
  6. dreamer/api/compat.py +139 -0
  7. dreamer/api/config.py +451 -0
  8. dreamer/api/contexts.py +744 -0
  9. dreamer/api/dream.py +61 -0
  10. dreamer/api/errors.py +62 -0
  11. dreamer/api/hooks.py +131 -0
  12. dreamer/api/jobs.py +34 -0
  13. dreamer/api/rate_limit.py +29 -0
  14. dreamer/api/runtime_state.py +60 -0
  15. dreamer/api/secrets.py +40 -0
  16. dreamer/api/stores.py +168 -0
  17. dreamer/api/tenants.py +160 -0
  18. dreamer/api/triggers.py +34 -0
  19. dreamer/api/types.py +199 -0
  20. dreamer/api/usage.py +22 -0
  21. dreamer/cli/__init__.py +0 -0
  22. dreamer/cli/main.py +723 -0
  23. dreamer/contrib/__init__.py +0 -0
  24. dreamer/contrib/audit/__init__.py +5 -0
  25. dreamer/contrib/audit/log.py +33 -0
  26. dreamer/contrib/auth/__init__.py +0 -0
  27. dreamer/contrib/auth/simple_token/__init__.py +3 -0
  28. dreamer/contrib/auth/simple_token/backend.py +207 -0
  29. dreamer/contrib/auth/simple_token/cli.py +87 -0
  30. dreamer/contrib/context/__init__.py +0 -0
  31. dreamer/contrib/context/fanout.py +296 -0
  32. dreamer/contrib/context/markdown.py +240 -0
  33. dreamer/contrib/dream/__init__.py +17 -0
  34. dreamer/contrib/dream/_docker.py +52 -0
  35. dreamer/contrib/dream/_local.py +251 -0
  36. dreamer/contrib/dream/claude_agent.py +380 -0
  37. dreamer/contrib/dream/serializers.py +191 -0
  38. dreamer/contrib/gates/__init__.py +6 -0
  39. dreamer/contrib/gates/budget.py +68 -0
  40. dreamer/contrib/gates/empty.py +38 -0
  41. dreamer/contrib/hooks/__init__.py +6 -0
  42. dreamer/contrib/hooks/git.py +574 -0
  43. dreamer/contrib/hooks/log.py +102 -0
  44. dreamer/contrib/jobs/__init__.py +0 -0
  45. dreamer/contrib/jobs/inproc.py +85 -0
  46. dreamer/contrib/ltm/__init__.py +0 -0
  47. dreamer/contrib/ltm/markdown.py +431 -0
  48. dreamer/contrib/mcp_tools/__init__.py +0 -0
  49. dreamer/contrib/rate_limit/__init__.py +5 -0
  50. dreamer/contrib/rate_limit/noop.py +38 -0
  51. dreamer/contrib/secrets/__init__.py +5 -0
  52. dreamer/contrib/secrets/env.py +65 -0
  53. dreamer/contrib/stm/__init__.py +0 -0
  54. dreamer/contrib/stm/sqlite.py +634 -0
  55. dreamer/contrib/tenancy/__init__.py +0 -0
  56. dreamer/contrib/tenancy/single.py +29 -0
  57. dreamer/contrib/tenants/__init__.py +0 -0
  58. dreamer/contrib/tenants/static.py +323 -0
  59. dreamer/contrib/triggers/__init__.py +0 -0
  60. dreamer/contrib/triggers/cron.py +136 -0
  61. dreamer/contrib/triggers/external.py +51 -0
  62. dreamer/contrib/triggers/multitenant.py +351 -0
  63. dreamer/contrib/triggers/threshold.py +141 -0
  64. dreamer/contrib/usage/__init__.py +5 -0
  65. dreamer/contrib/usage/log.py +40 -0
  66. dreamer/server/__init__.py +0 -0
  67. dreamer/server/app.py +567 -0
  68. dreamer/server/bootstrap.py +270 -0
  69. dreamer/server/compliance.py +376 -0
  70. dreamer/server/control.py +144 -0
  71. dreamer/server/mcp_app.py +579 -0
  72. dreamer/server/orchestrator.py +1879 -0
  73. dreamer/server/runtime.py +429 -0
  74. dreamer/server/secret_watcher.py +155 -0
  75. dreamer/server/sinks.py +70 -0
  76. dreamer/testing/__init__.py +5 -0
  77. dreamer/testing/conformance/__init__.py +21 -0
  78. dreamer/testing/conformance/context_store.py +106 -0
  79. dreamer/testing/conformance/dream_lease.py +148 -0
  80. dreamer/testing/conformance/ltm_store.py +137 -0
  81. dreamer/testing/conformance/stm_serializer.py +102 -0
  82. dreamer/testing/conformance/stm_store.py +322 -0
  83. dreamer/testing/fakes.py +656 -0
  84. dreamer_server-0.1.0.dist-info/METADATA +199 -0
  85. dreamer_server-0.1.0.dist-info/RECORD +88 -0
  86. dreamer_server-0.1.0.dist-info/WHEEL +4 -0
  87. dreamer_server-0.1.0.dist-info/entry_points.txt +3 -0
  88. dreamer_server-0.1.0.dist-info/licenses/LICENSE +21 -0
dreamer/__init__.py ADDED
@@ -0,0 +1 @@
1
+ __version__ = "0.1.0"
@@ -0,0 +1,152 @@
1
+ """Public framework interfaces.
2
+
3
+ Stable surface for component authors: Protocols, capability Protocols,
4
+ data types, errors, and the `@implements` decorator. Everything in
5
+ `dreamer.api.*` is the externally consumable contract.
6
+ """
7
+
8
+ from dreamer.api.audit import AuditSink
9
+ from dreamer.api.auth import AuthBackend, Tenancy
10
+ from dreamer.api.capabilities import (
11
+ Lifecycle,
12
+ Middlewares,
13
+ Routes,
14
+ Transactional,
15
+ )
16
+ from dreamer.api.compat import SUPPORTED_PROTOCOL_VERSIONS, implements
17
+ from dreamer.api.dream import ContextPhaseRunner, DreamGate, LTMPhaseRunner
18
+ from dreamer.api.errors import (
19
+ AuthError,
20
+ ConfigError,
21
+ DreamerError,
22
+ DreamFailedError,
23
+ LeaseHeldError,
24
+ ProtocolComplianceError,
25
+ TenantDataError,
26
+ ValidationError,
27
+ WorkspaceError,
28
+ )
29
+ from dreamer.api.hooks import (
30
+ DreamFailedHook,
31
+ DreamProgressHook,
32
+ PostContextUpdateHook,
33
+ PostDreamHook,
34
+ PostLTMUpdateHook,
35
+ PostMemorySubmitHook,
36
+ PreContextUpdateHook,
37
+ PreDreamHook,
38
+ PreLTMUpdateHook,
39
+ PreMemorySubmitHook,
40
+ )
41
+ from dreamer.api.jobs import DreamJob, JobQueue
42
+ from dreamer.api.rate_limit import RateLimitDecision, RateLimiter
43
+ from dreamer.api.secrets import SecretResolver, SecretRotationHook, SecretValue
44
+ from dreamer.api.stores import (
45
+ ContextPendingStore,
46
+ ContextReader,
47
+ ContextStore,
48
+ DreamLeaseStore,
49
+ LTMStore,
50
+ MCPTool,
51
+ STMSerializer,
52
+ STMStore,
53
+ )
54
+ from dreamer.api.tenants import (
55
+ TenantConfigProvider,
56
+ TenantData,
57
+ TenantLifecycle,
58
+ TenantRegistry,
59
+ TenantScope,
60
+ )
61
+ from dreamer.api.triggers import Trigger
62
+ from dreamer.api.types import (
63
+ DEFAULT_TENANT_ID,
64
+ AuditEvent,
65
+ Diff,
66
+ DreamLease,
67
+ FileViewable,
68
+ GateDecision,
69
+ GraphViewable,
70
+ Memory,
71
+ MemoryBatch,
72
+ MemoryType,
73
+ Principal,
74
+ RecordViewable,
75
+ TenantConfig,
76
+ TenantId,
77
+ UsageEvent,
78
+ Workspace,
79
+ )
80
+ from dreamer.api.usage import UsageSink
81
+
82
+ __all__ = [
83
+ "DEFAULT_TENANT_ID",
84
+ "SUPPORTED_PROTOCOL_VERSIONS",
85
+ "AuditEvent",
86
+ "AuditSink",
87
+ "AuthBackend",
88
+ "AuthError",
89
+ "ConfigError",
90
+ "ContextPendingStore",
91
+ "ContextPhaseRunner",
92
+ "ContextReader",
93
+ "ContextStore",
94
+ "Diff",
95
+ "DreamFailedError",
96
+ "DreamFailedHook",
97
+ "DreamGate",
98
+ "DreamJob",
99
+ "DreamLease",
100
+ "DreamLeaseStore",
101
+ "DreamProgressHook",
102
+ "DreamerError",
103
+ "FileViewable",
104
+ "GateDecision",
105
+ "GraphViewable",
106
+ "JobQueue",
107
+ "LTMPhaseRunner",
108
+ "LTMStore",
109
+ "LeaseHeldError",
110
+ "Lifecycle",
111
+ "MCPTool",
112
+ "Memory",
113
+ "MemoryBatch",
114
+ "MemoryType",
115
+ "Middlewares",
116
+ "PostContextUpdateHook",
117
+ "PostDreamHook",
118
+ "PostLTMUpdateHook",
119
+ "PostMemorySubmitHook",
120
+ "PreContextUpdateHook",
121
+ "PreDreamHook",
122
+ "PreLTMUpdateHook",
123
+ "PreMemorySubmitHook",
124
+ "Principal",
125
+ "ProtocolComplianceError",
126
+ "RateLimitDecision",
127
+ "RateLimiter",
128
+ "RecordViewable",
129
+ "Routes",
130
+ "STMSerializer",
131
+ "STMStore",
132
+ "SecretResolver",
133
+ "SecretRotationHook",
134
+ "SecretValue",
135
+ "Tenancy",
136
+ "TenantConfig",
137
+ "TenantConfigProvider",
138
+ "TenantData",
139
+ "TenantDataError",
140
+ "TenantId",
141
+ "TenantLifecycle",
142
+ "TenantRegistry",
143
+ "TenantScope",
144
+ "Transactional",
145
+ "Trigger",
146
+ "UsageEvent",
147
+ "UsageSink",
148
+ "ValidationError",
149
+ "Workspace",
150
+ "WorkspaceError",
151
+ "implements",
152
+ ]
dreamer/api/audit.py ADDED
@@ -0,0 +1,22 @@
1
+ """AuditSink Protocol + re-export of AuditEvent."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import TYPE_CHECKING, ClassVar, Protocol, runtime_checkable
6
+
7
+ from dreamer.api.types import AuditEvent
8
+
9
+ if TYPE_CHECKING:
10
+ from dreamer.api.contexts import AuditContext
11
+
12
+
13
+ @runtime_checkable
14
+ class AuditSink(Protocol):
15
+ """Append-only event trail. Distinct from `UsageSink` (compliance, not billing)."""
16
+
17
+ multi_tenant: ClassVar[bool] = False
18
+
19
+ async def record(self, event: AuditEvent, *, ctx: AuditContext) -> None: ...
20
+
21
+
22
+ __all__ = ["AuditEvent", "AuditSink"]
dreamer/api/auth.py ADDED
@@ -0,0 +1,37 @@
1
+ """AuthBackend and Tenancy Protocols."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import TYPE_CHECKING, ClassVar, Protocol, runtime_checkable
6
+
7
+ from dreamer.api.types import Principal, TenantId
8
+
9
+ if TYPE_CHECKING:
10
+ from starlette.requests import Request
11
+
12
+ from dreamer.api.contexts import AuthContext, TenancyContext
13
+
14
+
15
+ @runtime_checkable
16
+ class AuthBackend(Protocol):
17
+ """Authenticates a request and produces a Principal.
18
+
19
+ Backends MAY also expose Routes and/or Middlewares capabilities (login flows,
20
+ session middleware). Simple bearer-token impls only implement `authenticate`.
21
+ """
22
+
23
+ multi_tenant: ClassVar[bool] = False
24
+
25
+ async def authenticate(self, request: Request, *, ctx: AuthContext) -> Principal: ...
26
+
27
+
28
+ @runtime_checkable
29
+ class Tenancy(Protocol):
30
+ """Override point for deriving tenant id from principal."""
31
+
32
+ multi_tenant: ClassVar[bool] = False
33
+
34
+ async def tenant_for(self, principal: Principal, *, ctx: TenancyContext) -> TenantId: ...
35
+
36
+
37
+ __all__ = ["AuthBackend", "Tenancy"]
@@ -0,0 +1,78 @@
1
+ """Optional capability Protocols.
2
+
3
+ These are *additional* Protocols that any component may implement. The runtime
4
+ probes via `isinstance(component, Capability)` (works because they're
5
+ `@runtime_checkable`) and uses them if present.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ from typing import TYPE_CHECKING, Any, ClassVar, Protocol, runtime_checkable
11
+
12
+ if TYPE_CHECKING:
13
+ from starlette.applications import Starlette
14
+ from starlette.middleware import Middleware
15
+
16
+ from dreamer.api.contexts import (
17
+ LifecycleContext,
18
+ MiddlewaresContext,
19
+ RoutesContext,
20
+ TxBeginContext,
21
+ TxCommitContext,
22
+ TxPrepareContext,
23
+ TxRollbackContext,
24
+ )
25
+
26
+
27
+ TxHandle = Any
28
+
29
+
30
+ @runtime_checkable
31
+ class Lifecycle(Protocol):
32
+ """Component lifecycle hooks dispatched at server start/stop."""
33
+
34
+ multi_tenant: ClassVar[bool] = False
35
+
36
+ async def start(self, *, ctx: LifecycleContext) -> None: ...
37
+ async def stop(self, *, ctx: LifecycleContext) -> None: ...
38
+
39
+
40
+ @runtime_checkable
41
+ class Routes(Protocol):
42
+ """Mount HTTP routes on the Starlette app at server boot."""
43
+
44
+ multi_tenant: ClassVar[bool] = False
45
+
46
+ def register_routes(self, app: Starlette, *, ctx: RoutesContext) -> None: ...
47
+
48
+
49
+ @runtime_checkable
50
+ class Middlewares(Protocol):
51
+ """Provide ASGI middleware factories to install at server boot."""
52
+
53
+ multi_tenant: ClassVar[bool] = False
54
+
55
+ def middlewares(self, *, ctx: MiddlewaresContext) -> list[Middleware]: ...
56
+
57
+
58
+ @runtime_checkable
59
+ class Transactional(Protocol):
60
+ """Optional. When present on both `LTMStore` and `ContextStore`, the
61
+ orchestrator will use a two-phase commit across the dream's LTM and Context
62
+ updates."""
63
+
64
+ multi_tenant: ClassVar[bool] = False
65
+
66
+ async def begin(self, *, ctx: TxBeginContext) -> TxHandle: ...
67
+ async def prepare(self, tx: TxHandle, *, ctx: TxPrepareContext) -> bool: ...
68
+ async def commit(self, tx: TxHandle, *, ctx: TxCommitContext) -> None: ...
69
+ async def rollback(self, tx: TxHandle, *, ctx: TxRollbackContext) -> None: ...
70
+
71
+
72
+ __all__ = [
73
+ "Lifecycle",
74
+ "Middlewares",
75
+ "Routes",
76
+ "Transactional",
77
+ "TxHandle",
78
+ ]
dreamer/api/compat.py ADDED
@@ -0,0 +1,139 @@
1
+ """`@implements(protocol, version)` decorator + `SUPPORTED_PROTOCOL_VERSIONS`.
2
+
3
+ A class decorated with `@implements(P, version=N)` records the declaration on
4
+ the class itself in the `__dreamer_protocols__: dict[type, int]` attribute.
5
+ Multiple `@implements` decorators accumulate (one class can implement many
6
+ Protocols at once).
7
+
8
+ The framework's compatibility window per Protocol is read from
9
+ `SUPPORTED_PROTOCOL_VERSIONS` during startup compliance checks.
10
+ """
11
+
12
+ from __future__ import annotations
13
+
14
+ from collections.abc import Callable
15
+ from typing import TypeVar
16
+
17
+ from dreamer.api.audit import AuditSink
18
+ from dreamer.api.auth import AuthBackend, Tenancy
19
+ from dreamer.api.capabilities import (
20
+ Lifecycle,
21
+ Middlewares,
22
+ Routes,
23
+ Transactional,
24
+ )
25
+ from dreamer.api.dream import (
26
+ ContextPhaseRunner,
27
+ DreamGate,
28
+ LTMPhaseRunner,
29
+ )
30
+ from dreamer.api.hooks import (
31
+ DreamFailedHook,
32
+ DreamProgressHook,
33
+ PostContextUpdateHook,
34
+ PostDreamHook,
35
+ PostLTMUpdateHook,
36
+ PostMemorySubmitHook,
37
+ PreContextUpdateHook,
38
+ PreDreamHook,
39
+ PreLTMUpdateHook,
40
+ PreMemorySubmitHook,
41
+ )
42
+ from dreamer.api.jobs import JobQueue
43
+ from dreamer.api.rate_limit import RateLimiter
44
+ from dreamer.api.secrets import SecretResolver, SecretRotationHook
45
+ from dreamer.api.stores import (
46
+ ContextPendingStore,
47
+ ContextReader,
48
+ ContextStore,
49
+ DreamLeaseStore,
50
+ LTMStore,
51
+ MCPTool,
52
+ STMSerializer,
53
+ STMStore,
54
+ )
55
+ from dreamer.api.tenants import (
56
+ TenantConfigProvider,
57
+ TenantData,
58
+ TenantLifecycle,
59
+ TenantRegistry,
60
+ )
61
+ from dreamer.api.triggers import Trigger
62
+ from dreamer.api.types import (
63
+ FileViewable,
64
+ GraphViewable,
65
+ RecordViewable,
66
+ Workspace,
67
+ )
68
+ from dreamer.api.usage import UsageSink
69
+
70
+ T = TypeVar("T", bound=type)
71
+
72
+
73
+ def implements(protocol: type, *, version: int) -> Callable[[T], T]:
74
+ """Decorator: declare that a class implements `protocol` at `version`.
75
+
76
+ Stores the declaration on the class itself in
77
+ `__dreamer_protocols__: dict[type, int]`. Multiple `@implements` decorators
78
+ on the same class accumulate (one class may implement many Protocols).
79
+ """
80
+
81
+ def deco(cls: T) -> T:
82
+ existing: dict[type, int] = dict(getattr(cls, "__dreamer_protocols__", {}))
83
+ existing[protocol] = version
84
+ cls.__dreamer_protocols__ = existing # type: ignore[attr-defined]
85
+ return cls
86
+
87
+ return deco
88
+
89
+
90
+ SUPPORTED_PROTOCOL_VERSIONS: dict[type, frozenset[int]] = {
91
+ AuthBackend: frozenset({1}),
92
+ Tenancy: frozenset({1}),
93
+ STMStore: frozenset({1}),
94
+ LTMStore: frozenset({1}),
95
+ ContextPendingStore: frozenset({1}),
96
+ ContextStore: frozenset({1}),
97
+ DreamLeaseStore: frozenset({1}),
98
+ LTMPhaseRunner: frozenset({1}),
99
+ ContextPhaseRunner: frozenset({1}),
100
+ Trigger: frozenset({1}),
101
+ PreMemorySubmitHook: frozenset({1}),
102
+ PostMemorySubmitHook: frozenset({1}),
103
+ PreDreamHook: frozenset({1}),
104
+ PostDreamHook: frozenset({1}),
105
+ PreLTMUpdateHook: frozenset({1}),
106
+ PostLTMUpdateHook: frozenset({1}),
107
+ PreContextUpdateHook: frozenset({1}),
108
+ PostContextUpdateHook: frozenset({1}),
109
+ DreamFailedHook: frozenset({1}),
110
+ Lifecycle: frozenset({1}),
111
+ Routes: frozenset({1}),
112
+ Middlewares: frozenset({1}),
113
+ Transactional: frozenset({1}),
114
+ Workspace: frozenset({1}),
115
+ FileViewable: frozenset({1}),
116
+ RecordViewable: frozenset({1}),
117
+ GraphViewable: frozenset({1}),
118
+ TenantRegistry: frozenset({1}),
119
+ TenantConfigProvider: frozenset({1}),
120
+ TenantLifecycle: frozenset({1}),
121
+ TenantData: frozenset({1}),
122
+ JobQueue: frozenset({1}),
123
+ SecretResolver: frozenset({1}),
124
+ SecretRotationHook: frozenset({1}),
125
+ UsageSink: frozenset({1}),
126
+ AuditSink: frozenset({1}),
127
+ RateLimiter: frozenset({1}),
128
+ MCPTool: frozenset({1}),
129
+ STMSerializer: frozenset({1}),
130
+ ContextReader: frozenset({1}),
131
+ DreamGate: frozenset({1}),
132
+ DreamProgressHook: frozenset({1}),
133
+ }
134
+
135
+
136
+ __all__ = [
137
+ "SUPPORTED_PROTOCOL_VERSIONS",
138
+ "implements",
139
+ ]