memoryking 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.
- memoryking/__init__.py +3 -0
- memoryking/__main__.py +1328 -0
- memoryking/adapters/__init__.py +1 -0
- memoryking/adapters/adapter_state.py +242 -0
- memoryking/adapters/anchor_schema.sql +7 -0
- memoryking/adapters/atlas.py +441 -0
- memoryking/adapters/browser_commands.py +125 -0
- memoryking/adapters/dashboard.py +510 -0
- memoryking/adapters/dense_search.py +86 -0
- memoryking/adapters/egress_policy.py +244 -0
- memoryking/adapters/egress_schema.sql +13 -0
- memoryking/adapters/embedding.schema.json +302 -0
- memoryking/adapters/embedding_store.py +469 -0
- memoryking/adapters/execution.py +369 -0
- memoryking/adapters/experience.py +423 -0
- memoryking/adapters/experience.schema.json +1508 -0
- memoryking/adapters/experience_records.py +239 -0
- memoryking/adapters/experience_schema.sql +23 -0
- memoryking/adapters/handoff.py +494 -0
- memoryking/adapters/handoff.schema.json +299 -0
- memoryking/adapters/handoff_schema.sql +17 -0
- memoryking/adapters/index_schema.sql +11 -0
- memoryking/adapters/inference.py +454 -0
- memoryking/adapters/inference.schema.json +541 -0
- memoryking/adapters/inspection.py +1128 -0
- memoryking/adapters/inspection.schema.json +568 -0
- memoryking/adapters/knowledge.schema.json +633 -0
- memoryking/adapters/knowledge_schema.sql +37 -0
- memoryking/adapters/knowledge_store.py +800 -0
- memoryking/adapters/legacy_snapshot.py +358 -0
- memoryking/adapters/legacy_tables.py +49 -0
- memoryking/adapters/local_contract.py +45 -0
- memoryking/adapters/local_embeddings.py +189 -0
- memoryking/adapters/local_files.py +242 -0
- memoryking/adapters/local_ipc.py +258 -0
- memoryking/adapters/local_schema.sql +44 -0
- memoryking/adapters/local_store.py +632 -0
- memoryking/adapters/local_wire.schema.json +7672 -0
- memoryking/adapters/models/minilm-l6-v2-onnx.json +57 -0
- memoryking/adapters/models/ms-marco-minilm-l6-v2-onnx.json +57 -0
- memoryking/adapters/optional_schema.sql +43 -0
- memoryking/adapters/plan_dashboard.py +51 -0
- memoryking/adapters/plans.py +253 -0
- memoryking/adapters/postgres_admin.py +300 -0
- memoryking/adapters/postgres_anchor_schema.sql +9 -0
- memoryking/adapters/postgres_counter.sql +14 -0
- memoryking/adapters/postgres_egress_schema.sql +15 -0
- memoryking/adapters/postgres_experience_schema.sql +39 -0
- memoryking/adapters/postgres_index_schema.sql +7 -0
- memoryking/adapters/postgres_optional_schema.sql +71 -0
- memoryking/adapters/postgres_pool.py +77 -0
- memoryking/adapters/postgres_recovery.py +525 -0
- memoryking/adapters/postgres_schema.sql +365 -0
- memoryking/adapters/postgres_sql.py +102 -0
- memoryking/adapters/postgres_store.py +428 -0
- memoryking/adapters/postgres_summary_schema.sql +12 -0
- memoryking/adapters/postgres_trust_schema.sql +20 -0
- memoryking/adapters/processing.schema.json +471 -0
- memoryking/adapters/processing_store.py +346 -0
- memoryking/adapters/projects.py +83 -0
- memoryking/adapters/proposals.py +238 -0
- memoryking/adapters/ranking.py +315 -0
- memoryking/adapters/repository.schema.json +664 -0
- memoryking/adapters/repository_git.py +264 -0
- memoryking/adapters/repository_schema.sql +25 -0
- memoryking/adapters/repository_store.py +960 -0
- memoryking/adapters/retrieval.py +1285 -0
- memoryking/adapters/retrieval.schema.json +553 -0
- memoryking/adapters/retrieval_schema.sql +10 -0
- memoryking/adapters/shared_control.py +40 -0
- memoryking/adapters/shared_dashboard.py +636 -0
- memoryking/adapters/shared_gateway.py +63 -0
- memoryking/adapters/shared_http.py +216 -0
- memoryking/adapters/shared_mcp.py +159 -0
- memoryking/adapters/shared_service.py +124 -0
- memoryking/adapters/stdio.py +193 -0
- memoryking/adapters/stdio.tools.json +6776 -0
- memoryking/adapters/summary_schema.sql +10 -0
- memoryking/adapters/team.py +253 -0
- memoryking/adapters/timeline.py +80 -0
- memoryking/adapters/token_count.py +55 -0
- memoryking/adapters/tokenizers/LICENSE +21 -0
- memoryking/adapters/tokenizers/cl100k_base.tiktoken +100256 -0
- memoryking/adapters/trust.py +123 -0
- memoryking/adapters/trust_schema.sql +13 -0
- memoryking/adapters/web/app.css +1251 -0
- memoryking/adapters/web/app.js +907 -0
- memoryking/adapters/web/brand.js +44 -0
- memoryking/adapters/web/crown-mono.svg +1 -0
- memoryking/adapters/web/crown.svg +8 -0
- memoryking/adapters/web/elephant.png +0 -0
- memoryking/adapters/web/favicon.svg +8 -0
- memoryking/adapters/web/graph-layout.js +52 -0
- memoryking/adapters/web/graph-worker.js +10 -0
- memoryking/adapters/web/graph.js +570 -0
- memoryking/adapters/web/index.html +208 -0
- memoryking/adapters/web/observatory.js +1208 -0
- memoryking/adapters/web/team.js +151 -0
- memoryking/adapters/web/wordmark.svg +1 -0
- memoryking/adapters/working.py +971 -0
- memoryking/adapters/working.schema.json +1717 -0
- memoryking/adapters/working_schema.sql +24 -0
- memoryking/application/__init__.py +1 -0
- memoryking/application/conformance.py +50 -0
- memoryking/application/legacy_import.py +337 -0
- memoryking/application/local_port.py +9 -0
- memoryking/application/storage.py +117 -0
- memoryking/application/store_core.py +1292 -0
- memoryking/backups.py +131 -0
- memoryking/contracts/__init__.py +6 -0
- memoryking/contracts/__main__.py +20 -0
- memoryking/contracts/canonical.py +88 -0
- memoryking/contracts/embedding.schema.json +302 -0
- memoryking/contracts/embedding_generated.py +65 -0
- memoryking/contracts/experience.schema.json +1508 -0
- memoryking/contracts/experience_generated.py +239 -0
- memoryking/contracts/generated.py +122 -0
- memoryking/contracts/handoff.schema.json +299 -0
- memoryking/contracts/handoff_generated.py +69 -0
- memoryking/contracts/inference.schema.json +541 -0
- memoryking/contracts/inference_generated.py +106 -0
- memoryking/contracts/processing.schema.json +471 -0
- memoryking/contracts/processing_generated.py +82 -0
- memoryking/contracts/py.typed +0 -0
- memoryking/contracts/repository.schema.json +664 -0
- memoryking/contracts/repository_generated.py +144 -0
- memoryking/contracts/retrieval.schema.json +553 -0
- memoryking/contracts/retrieval_generated.py +110 -0
- memoryking/contracts/schema.json +696 -0
- memoryking/contracts/validation.py +92 -0
- memoryking/contracts/working.schema.json +1717 -0
- memoryking/contracts/working_generated.py +291 -0
- memoryking/domain/__init__.py +1 -0
- memoryking/domain/anchors.py +97 -0
- memoryking/domain/briefing.py +108 -0
- memoryking/domain/briefing_text.py +222 -0
- memoryking/domain/checkpoint.py +118 -0
- memoryking/domain/compression.py +64 -0
- memoryking/domain/delta.py +129 -0
- memoryking/domain/embeddings.py +90 -0
- memoryking/domain/hints.py +465 -0
- memoryking/domain/http_status.py +45 -0
- memoryking/domain/learning.py +62 -0
- memoryking/domain/local.py +65 -0
- memoryking/domain/plans.py +140 -0
- memoryking/domain/repository.py +118 -0
- memoryking/domain/selectors.py +356 -0
- memoryking/domain/summary.py +88 -0
- memoryking/domain/usage.py +163 -0
- memoryking/embedding_loop.py +98 -0
- memoryking/embedding_worker.py +131 -0
- memoryking/harness.py +882 -0
- memoryking/harness_context.py +376 -0
- memoryking/hooks.py +171 -0
- memoryking/host_hooks.py +454 -0
- memoryking/lean.py +352 -0
- memoryking/memory_tool.py +776 -0
- memoryking/migration.py +194 -0
- memoryking/model_install.py +78 -0
- memoryking/observability.py +101 -0
- memoryking/observability_metrics.py +100 -0
- memoryking/profiles.py +150 -0
- memoryking/providers.py +330 -0
- memoryking/py.typed +0 -0
- memoryking/pytest_plugin.py +69 -0
- memoryking/reference_agent.py +152 -0
- memoryking/repository_worker.py +57 -0
- memoryking/resume_adapter.py +154 -0
- memoryking/sdk.py +302 -0
- memoryking/shared.py +301 -0
- memoryking/shared_sdk.py +101 -0
- memoryking/vault.py +176 -0
- memoryking-0.1.0.dist-info/METADATA +157 -0
- memoryking-0.1.0.dist-info/RECORD +179 -0
- memoryking-0.1.0.dist-info/WHEEL +5 -0
- memoryking-0.1.0.dist-info/entry_points.txt +7 -0
- memoryking-0.1.0.dist-info/licenses/LICENSE +202 -0
- memoryking-0.1.0.dist-info/licenses/NOTICE +12 -0
- memoryking-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Transport/storage/provider adapters; none are implemented by the P01 foundation."""
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
"""Current-authorized resume deltas with independent full model-artifact retention."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import hashlib
|
|
6
|
+
import json
|
|
7
|
+
from typing import TYPE_CHECKING, Any
|
|
8
|
+
|
|
9
|
+
from memoryking.adapters.inference import EGRESS_REVISION
|
|
10
|
+
from memoryking.adapters.local_store import MAX_COUNTER, uid
|
|
11
|
+
from memoryking.adapters.token_count import counter
|
|
12
|
+
from memoryking.contracts.canonical import canonical_bytes, canonical_hash
|
|
13
|
+
from memoryking.domain.briefing import counted
|
|
14
|
+
from memoryking.domain.delta import MAX_BYTES, SCHEMA, SERIALIZATION, apply, changes
|
|
15
|
+
from memoryking.domain.local import Decision, LocalError
|
|
16
|
+
|
|
17
|
+
if TYPE_CHECKING:
|
|
18
|
+
from memoryking.adapters.working import Working
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def resume(
|
|
22
|
+
working: Working, who: dict[str, Any], args: dict[str, Any], decision: Decision, receipt: str
|
|
23
|
+
) -> tuple[bytes, list[dict[str, str]]]:
|
|
24
|
+
s, db, r, at = working.s, working.db, working.r, decision.evaluated_ms
|
|
25
|
+
epochs = db.execute(
|
|
26
|
+
"SELECT policy_epoch,purge_epoch FROM tenants WHERE tenant=?", (who["tenant"],)
|
|
27
|
+
).fetchone()
|
|
28
|
+
binding = {
|
|
29
|
+
"store": s.store_id,
|
|
30
|
+
"tenant": who["tenant"],
|
|
31
|
+
"principal": who["principal"],
|
|
32
|
+
"incarnation": s.incarnation,
|
|
33
|
+
"project": args["project"],
|
|
34
|
+
"authorization_epoch": epochs[0],
|
|
35
|
+
"purge_epoch": epochs[1],
|
|
36
|
+
"delegation_chain": who.get("delegation_chain", []),
|
|
37
|
+
"egress_policy_revision": EGRESS_REVISION,
|
|
38
|
+
"model_session": args["adapter_context"]["model_session"],
|
|
39
|
+
"context_epoch": args["adapter_context"]["context_epoch"],
|
|
40
|
+
"view_hash": canonical_hash(
|
|
41
|
+
{
|
|
42
|
+
key: args[key]
|
|
43
|
+
for key in ("project", "task", "run", "checkpoint", "bindings", "tokenizer")
|
|
44
|
+
}
|
|
45
|
+
),
|
|
46
|
+
}
|
|
47
|
+
context_receipt = uid("rcpt")
|
|
48
|
+
packet_raw, deps = working._resume(who, args, decision, context_receipt)
|
|
49
|
+
packet = json.loads(packet_raw)
|
|
50
|
+
db.execute(
|
|
51
|
+
"INSERT INTO receipts VALUES (?,?,?,?,?,?,?,?,?,?)",
|
|
52
|
+
(
|
|
53
|
+
who["tenant"],
|
|
54
|
+
context_receipt,
|
|
55
|
+
who["principal"],
|
|
56
|
+
s.incarnation,
|
|
57
|
+
at,
|
|
58
|
+
decision.deadline_ms,
|
|
59
|
+
*epochs,
|
|
60
|
+
hashlib.sha256(packet_raw).hexdigest(),
|
|
61
|
+
json.dumps([d["id"] for d in deps if d["kind"] == "observation"]),
|
|
62
|
+
),
|
|
63
|
+
)
|
|
64
|
+
db.execute("DELETE FROM adapter_bases WHERE tenant=? AND expires<=?", (who["tenant"], at))
|
|
65
|
+
base = None
|
|
66
|
+
base_deps: list[dict[str, str]] = []
|
|
67
|
+
reason = "new_base"
|
|
68
|
+
offered = args["base"]
|
|
69
|
+
if offered is not None:
|
|
70
|
+
reason = "base_unavailable"
|
|
71
|
+
row = db.execute(
|
|
72
|
+
"SELECT id,binding,dependencies,body_hash FROM adapter_bases WHERE tenant=? AND principal=? AND project=? AND incarnation=? AND id=? AND expires>?",
|
|
73
|
+
(who["tenant"], who["principal"], args["project"], s.incarnation, offered["id"], at),
|
|
74
|
+
).fetchone()
|
|
75
|
+
if row is not None:
|
|
76
|
+
reason = "binding_changed"
|
|
77
|
+
if json.loads(row["binding"]) == binding:
|
|
78
|
+
reason = "base_incompatible"
|
|
79
|
+
if row["body_hash"] == offered["hash"] and offered["schema"] == SCHEMA:
|
|
80
|
+
try:
|
|
81
|
+
for dep in json.loads(row["dependencies"]):
|
|
82
|
+
r._dependency(who, dep, at)
|
|
83
|
+
body = bytes(
|
|
84
|
+
db.execute(
|
|
85
|
+
"SELECT body FROM adapter_bases WHERE tenant=? AND id=?",
|
|
86
|
+
(who["tenant"], row["id"]),
|
|
87
|
+
).fetchone()[0]
|
|
88
|
+
)
|
|
89
|
+
candidate = json.loads(body)
|
|
90
|
+
if (
|
|
91
|
+
hashlib.sha256(body).hexdigest() == offered["hash"]
|
|
92
|
+
and candidate["sequence"] == offered["sequence"]
|
|
93
|
+
and candidate["sequence"] < MAX_COUNTER
|
|
94
|
+
):
|
|
95
|
+
previous = candidate["packet"].get("checkpoint")
|
|
96
|
+
current = packet.get("checkpoint")
|
|
97
|
+
if (
|
|
98
|
+
previous
|
|
99
|
+
and current
|
|
100
|
+
and 0 <= current["revision"] - previous["revision"] <= 1
|
|
101
|
+
):
|
|
102
|
+
base = candidate
|
|
103
|
+
base_deps = json.loads(row["dependencies"])
|
|
104
|
+
else:
|
|
105
|
+
reason = "revision_gap"
|
|
106
|
+
except (LocalError, ValueError, KeyError, TypeError):
|
|
107
|
+
reason = "base_unavailable"
|
|
108
|
+
target = {"sequence": base["sequence"] + 1 if base else 1, "packet": packet}
|
|
109
|
+
count, usage = counter(args["tokenizer"])
|
|
110
|
+
envelope = {
|
|
111
|
+
"version": 1,
|
|
112
|
+
"status": packet["status"],
|
|
113
|
+
"schema": SCHEMA,
|
|
114
|
+
"serialization": SERIALIZATION,
|
|
115
|
+
"mode": "full",
|
|
116
|
+
"binding": binding,
|
|
117
|
+
"sequence": target["sequence"],
|
|
118
|
+
"base_hash": None,
|
|
119
|
+
"target_hash": canonical_hash(target),
|
|
120
|
+
"base_id": receipt,
|
|
121
|
+
"receipt": receipt,
|
|
122
|
+
"evaluated_ms": at,
|
|
123
|
+
"deadline_ms": decision.deadline_ms,
|
|
124
|
+
"target": target,
|
|
125
|
+
"fallback_reason": reason,
|
|
126
|
+
"usage": {
|
|
127
|
+
**usage,
|
|
128
|
+
"max_output_tokens": args["max_output_tokens"],
|
|
129
|
+
"budget_compliant": True,
|
|
130
|
+
"materialized_tokens": count(packet_raw.decode()),
|
|
131
|
+
"materialized_bytes": len(packet_raw),
|
|
132
|
+
"model_context": "full_essential_state",
|
|
133
|
+
"provider_usage": "unknown",
|
|
134
|
+
},
|
|
135
|
+
}
|
|
136
|
+
full_raw, _ = counted(envelope, count)
|
|
137
|
+
if base is not None:
|
|
138
|
+
try:
|
|
139
|
+
operations = changes(base, target)
|
|
140
|
+
if canonical_hash(apply(base, operations)) != canonical_hash(target):
|
|
141
|
+
raise LocalError("delta_target_mismatch")
|
|
142
|
+
delta = {key: value for key, value in envelope.items() if key != "target"}
|
|
143
|
+
before = {(dep["kind"], dep["id"]) for dep in base_deps}
|
|
144
|
+
after = {(dep["kind"], dep["id"]) for dep in deps}
|
|
145
|
+
changed_references = [
|
|
146
|
+
{"kind": kind, "id": identifier, "change": change}
|
|
147
|
+
for change, items in (("removed", before - after), ("added", after - before))
|
|
148
|
+
for kind, identifier in sorted(items)
|
|
149
|
+
]
|
|
150
|
+
if len(changed_references) > 256:
|
|
151
|
+
raise LocalError("delta_limit")
|
|
152
|
+
delta.update(
|
|
153
|
+
mode="delta",
|
|
154
|
+
base_hash=canonical_hash(base),
|
|
155
|
+
changes=operations,
|
|
156
|
+
fallback_reason=None,
|
|
157
|
+
changed_references=changed_references,
|
|
158
|
+
essential_state_changes=[
|
|
159
|
+
operation["path"]
|
|
160
|
+
for operation in operations
|
|
161
|
+
if operation["path"][:3] == ["packet", "checkpoint", "state"]
|
|
162
|
+
or operation["path"][:2]
|
|
163
|
+
in (["packet", "constraints"], ["packet", "operations"])
|
|
164
|
+
],
|
|
165
|
+
)
|
|
166
|
+
delta_raw, delta_tokens = counted(delta, count)
|
|
167
|
+
if len(delta_raw) < len(full_raw) and delta_tokens <= args["max_output_tokens"]:
|
|
168
|
+
envelope = delta
|
|
169
|
+
else:
|
|
170
|
+
envelope["fallback_reason"] = "no_transport_savings"
|
|
171
|
+
except LocalError:
|
|
172
|
+
envelope["fallback_reason"] = "delta_limit"
|
|
173
|
+
raw, used = counted(envelope, count)
|
|
174
|
+
if used > args["max_output_tokens"] or len(raw) > MAX_BYTES:
|
|
175
|
+
envelope = {
|
|
176
|
+
key: value for key, value in envelope.items() if key not in {"target", "changes"}
|
|
177
|
+
}
|
|
178
|
+
envelope.update(
|
|
179
|
+
status="budget_insufficient",
|
|
180
|
+
mode="unavailable",
|
|
181
|
+
base_id=None,
|
|
182
|
+
minimum_required_tokens=used,
|
|
183
|
+
reason="adapter_envelope_does_not_fit",
|
|
184
|
+
)
|
|
185
|
+
envelope["usage"]["budget_compliant"] = False
|
|
186
|
+
raw, used = counted(envelope, count)
|
|
187
|
+
deps = []
|
|
188
|
+
else:
|
|
189
|
+
# Bounded convenience state: evict the oldest owned base before adding.
|
|
190
|
+
owned = db.execute(
|
|
191
|
+
"SELECT id FROM adapter_bases WHERE tenant=? AND principal=? ORDER BY created,id",
|
|
192
|
+
(who["tenant"], who["principal"]),
|
|
193
|
+
).fetchall()
|
|
194
|
+
for row in owned[: max(0, len(owned) - 63)]:
|
|
195
|
+
db.execute(
|
|
196
|
+
"DELETE FROM adapter_bases WHERE tenant=? AND id=?", (who["tenant"], row["id"])
|
|
197
|
+
)
|
|
198
|
+
total, size = db.execute(
|
|
199
|
+
"SELECT count(*),coalesce(sum(length(body)),0) FROM adapter_bases WHERE tenant=?",
|
|
200
|
+
(who["tenant"],),
|
|
201
|
+
).fetchone()
|
|
202
|
+
target_raw = canonical_bytes(target)
|
|
203
|
+
if total < 512 and size + len(target_raw) <= 67108864:
|
|
204
|
+
db.execute(
|
|
205
|
+
"INSERT INTO adapter_bases VALUES (?,?,?,?,?,?,?,?,?,?,?)",
|
|
206
|
+
(
|
|
207
|
+
who["tenant"],
|
|
208
|
+
receipt,
|
|
209
|
+
args["project"],
|
|
210
|
+
who["principal"],
|
|
211
|
+
s.incarnation,
|
|
212
|
+
json.dumps(binding),
|
|
213
|
+
target_raw,
|
|
214
|
+
canonical_hash(target),
|
|
215
|
+
json.dumps(deps),
|
|
216
|
+
at,
|
|
217
|
+
at + 300000,
|
|
218
|
+
),
|
|
219
|
+
)
|
|
220
|
+
else:
|
|
221
|
+
envelope["base_id"] = None
|
|
222
|
+
raw, used = counted(envelope, count)
|
|
223
|
+
if used > args["max_output_tokens"] or len(raw) > MAX_BYTES:
|
|
224
|
+
raise LocalError("budget_insufficient")
|
|
225
|
+
r._retain(
|
|
226
|
+
who,
|
|
227
|
+
args,
|
|
228
|
+
receipt,
|
|
229
|
+
raw,
|
|
230
|
+
{
|
|
231
|
+
"kind": "adapter_resume",
|
|
232
|
+
"status": envelope["status"],
|
|
233
|
+
"mode": envelope["mode"],
|
|
234
|
+
"context_receipt": context_receipt,
|
|
235
|
+
"trace": [],
|
|
236
|
+
"usage": {**envelope["usage"], "output_tokens": used, "serialized_bytes": len(raw)},
|
|
237
|
+
"fallback_reason": envelope["fallback_reason"],
|
|
238
|
+
},
|
|
239
|
+
deps,
|
|
240
|
+
at,
|
|
241
|
+
)
|
|
242
|
+
return raw, deps
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
BEGIN IMMEDIATE;
|
|
2
|
+
CREATE TABLE IF NOT EXISTS anchors (
|
|
3
|
+
tenant TEXT NOT NULL REFERENCES tenants, id TEXT NOT NULL, anchor TEXT NOT NULL, kind TEXT NOT NULL,
|
|
4
|
+
PRIMARY KEY(tenant,id,anchor));
|
|
5
|
+
CREATE INDEX IF NOT EXISTS anchors_lookup ON anchors(tenant,anchor,id);
|
|
6
|
+
PRAGMA user_version=13;
|
|
7
|
+
COMMIT;
|