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,369 @@
|
|
|
1
|
+
"""Current-authorized task observations; progress comes from checkpoints, never event counts."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from memoryking.adapters.working import Working
|
|
9
|
+
from memoryking.application.store_core import StoreCore
|
|
10
|
+
from memoryking.contracts.canonical import (
|
|
11
|
+
ContractError,
|
|
12
|
+
canonical_bytes,
|
|
13
|
+
canonical_hash,
|
|
14
|
+
load_strict,
|
|
15
|
+
)
|
|
16
|
+
from memoryking.domain.local import LocalError
|
|
17
|
+
|
|
18
|
+
EVENT_KINDS = frozenset(
|
|
19
|
+
{
|
|
20
|
+
"task_started",
|
|
21
|
+
"task_started_recovered",
|
|
22
|
+
"recovered_staged_state",
|
|
23
|
+
"periodic_state",
|
|
24
|
+
"before_action_state",
|
|
25
|
+
"accepted_constraint",
|
|
26
|
+
"structured_state_changed",
|
|
27
|
+
"checkpoint",
|
|
28
|
+
"tool_started",
|
|
29
|
+
"tool_not_dispatched",
|
|
30
|
+
"tool_readback",
|
|
31
|
+
"tool_completed",
|
|
32
|
+
"tool_returned_error",
|
|
33
|
+
"model_started",
|
|
34
|
+
"model_completed",
|
|
35
|
+
"model_failed",
|
|
36
|
+
"model_interrupted",
|
|
37
|
+
"artifact_stored",
|
|
38
|
+
"shutdown",
|
|
39
|
+
}
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def scope_hash(criteria: list[dict[str, Any]]) -> str:
|
|
44
|
+
return canonical_hash(
|
|
45
|
+
sorted(
|
|
46
|
+
({"id": c["id"], "text": c["text"], "weight": c.get("weight", 1)} for c in criteria),
|
|
47
|
+
key=lambda c: c["id"],
|
|
48
|
+
)
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class Execution:
|
|
53
|
+
def __init__(self, store: StoreCore):
|
|
54
|
+
self.s, self.db = store, store.db
|
|
55
|
+
self.w = Working(store)
|
|
56
|
+
|
|
57
|
+
def _evidence(self, who: dict[str, Any], dep: dict[str, str], at: int) -> bool:
|
|
58
|
+
try:
|
|
59
|
+
self.w._dependency(who, dep, at)
|
|
60
|
+
if dep["kind"] == "observation":
|
|
61
|
+
row = self.db.execute(
|
|
62
|
+
"SELECT * FROM observations WHERE tenant=? AND id=?", (who["tenant"], dep["id"])
|
|
63
|
+
).fetchone()
|
|
64
|
+
self.w.r._blob(row)
|
|
65
|
+
else:
|
|
66
|
+
row = self.w.r.k._revision(who["tenant"], dep["id"])
|
|
67
|
+
for ref in self.w.r.k._evidence(who["tenant"], row["id"]):
|
|
68
|
+
observation = self.db.execute(
|
|
69
|
+
"SELECT * FROM observations WHERE tenant=? AND id=?",
|
|
70
|
+
(who["tenant"], ref["observation"]),
|
|
71
|
+
).fetchone()
|
|
72
|
+
self.w.r._blob(observation)
|
|
73
|
+
return True
|
|
74
|
+
except (LocalError, OSError):
|
|
75
|
+
return False
|
|
76
|
+
|
|
77
|
+
def snapshot(
|
|
78
|
+
self, who: dict[str, Any], project: str, at: int, recorded_position: int | None = None
|
|
79
|
+
) -> dict[str, Any]:
|
|
80
|
+
current_position = self.db.execute(
|
|
81
|
+
"SELECT position FROM tenants WHERE tenant=?", (who["tenant"],)
|
|
82
|
+
).fetchone()[0]
|
|
83
|
+
frontier = current_position if recorded_position is None else recorded_position
|
|
84
|
+
if type(frontier) is not int or not 0 <= frontier <= current_position:
|
|
85
|
+
raise LocalError("invalid_recorded_position")
|
|
86
|
+
result: dict[str, Any] = {
|
|
87
|
+
"schema_version": 1,
|
|
88
|
+
"project": project,
|
|
89
|
+
"store": self.s.store_id,
|
|
90
|
+
"tenant": who["tenant"],
|
|
91
|
+
"principal": who["principal"],
|
|
92
|
+
"incarnation": self.s.incarnation,
|
|
93
|
+
"observed_ms": at,
|
|
94
|
+
"fresh_until_ms": at + 15000,
|
|
95
|
+
"status": "available",
|
|
96
|
+
"tasks": [],
|
|
97
|
+
"events": [],
|
|
98
|
+
"coverage": "up_to_8_visible_tasks_from_64_recent_streams_and_32_events_from_128_candidates",
|
|
99
|
+
"authority": "authenticated_producer_reports_with_current_evidence_access; not_independent_test_certification",
|
|
100
|
+
"mode": "live" if recorded_position is None else "historical",
|
|
101
|
+
"recorded_position": frontier,
|
|
102
|
+
"authorization_evaluated_ms": at,
|
|
103
|
+
"external_actions": 0,
|
|
104
|
+
}
|
|
105
|
+
streams = self.db.execute(
|
|
106
|
+
"SELECT c.task,c.stream,c.writer,c.revision,c.id AS latest,c.created FROM checkpoints c WHERE c.tenant=? AND c.project=? AND c.incarnation=? AND c.position<=? AND NOT EXISTS(SELECT 1 FROM checkpoints newer WHERE newer.tenant=c.tenant AND newer.project=c.project AND newer.task=c.task AND newer.stream=c.stream AND newer.incarnation=c.incarnation AND newer.position<=? AND newer.revision>c.revision) ORDER BY c.created DESC,c.task,c.stream LIMIT 64",
|
|
107
|
+
(who["tenant"], project, self.s.incarnation, frontier, frontier),
|
|
108
|
+
).fetchall()
|
|
109
|
+
task_index: dict[tuple[str, str], dict[str, Any]] = {}
|
|
110
|
+
linked_events: dict[tuple[str, str], set[str]] = {}
|
|
111
|
+
for stream in streams:
|
|
112
|
+
if recorded_position is None:
|
|
113
|
+
current_stream = self.db.execute(
|
|
114
|
+
"SELECT writer,revision FROM checkpoint_streams WHERE tenant=? AND project=? AND task=? AND stream=?",
|
|
115
|
+
(who["tenant"], project, stream["task"], stream["stream"]),
|
|
116
|
+
).fetchone()
|
|
117
|
+
if current_stream is not None:
|
|
118
|
+
stream = {**dict(stream), **dict(current_stream)}
|
|
119
|
+
row = self.db.execute(
|
|
120
|
+
"SELECT * FROM checkpoints WHERE tenant=? AND id=?",
|
|
121
|
+
(who["tenant"], stream["latest"]),
|
|
122
|
+
).fetchone()
|
|
123
|
+
if row["state"] != "available" or who["principal"] not in json.loads(row["readers"]):
|
|
124
|
+
continue
|
|
125
|
+
args = {
|
|
126
|
+
"project": project,
|
|
127
|
+
"task": stream["task"],
|
|
128
|
+
"run": None if stream["stream"] == "task" else stream["stream"][4:],
|
|
129
|
+
"checkpoint": row["id"],
|
|
130
|
+
}
|
|
131
|
+
try:
|
|
132
|
+
self.w._checkpoint(who, args, at)
|
|
133
|
+
except LocalError:
|
|
134
|
+
# Do not release a copied title/criterion after a source restriction.
|
|
135
|
+
return {
|
|
136
|
+
**result,
|
|
137
|
+
"status": "unavailable",
|
|
138
|
+
"tasks": [],
|
|
139
|
+
"events": [],
|
|
140
|
+
"reason": "current_source_authorization_unavailable",
|
|
141
|
+
}
|
|
142
|
+
body = json.loads(row["body"])
|
|
143
|
+
history = self.db.execute(
|
|
144
|
+
"SELECT id FROM checkpoints WHERE tenant=? AND project=? AND task=? AND stream=? AND incarnation=? AND revision<? ORDER BY revision DESC LIMIT 129",
|
|
145
|
+
(
|
|
146
|
+
who["tenant"],
|
|
147
|
+
project,
|
|
148
|
+
stream["task"],
|
|
149
|
+
stream["stream"],
|
|
150
|
+
self.s.incarnation,
|
|
151
|
+
row["revision"],
|
|
152
|
+
),
|
|
153
|
+
).fetchall()
|
|
154
|
+
# Never let an audit-only checkpoint rehabilitate a changed definition
|
|
155
|
+
# carrying unchanged proof. Bounded or inaccessible history stays unknown.
|
|
156
|
+
history_complete = len(history) <= 128
|
|
157
|
+
previous_body = None
|
|
158
|
+
prior_bodies = []
|
|
159
|
+
for index, previous in enumerate(history[:128]):
|
|
160
|
+
try:
|
|
161
|
+
prior = json.loads(
|
|
162
|
+
self.w._checkpoint(who, {**args, "checkpoint": previous["id"]}, at)["body"]
|
|
163
|
+
)
|
|
164
|
+
prior_bodies.append(prior)
|
|
165
|
+
if index == 0:
|
|
166
|
+
previous_body = prior
|
|
167
|
+
except LocalError:
|
|
168
|
+
history_complete = False
|
|
169
|
+
old = {} if previous_body is None else {c["id"]: c for c in previous_body["acceptance"]}
|
|
170
|
+
counts = {state: 0 for state in ("passed", "failed", "pending", "waived", "unknown")}
|
|
171
|
+
weighted = dict.fromkeys(counts, 0)
|
|
172
|
+
criteria = []
|
|
173
|
+
for criterion in body["acceptance"]:
|
|
174
|
+
available = bool(criterion["evidence"]) and all(
|
|
175
|
+
self._evidence(who, dep, at) for dep in criterion["evidence"]
|
|
176
|
+
)
|
|
177
|
+
effective = criterion["state"]
|
|
178
|
+
predecessor = old.get(criterion["id"])
|
|
179
|
+
changed = predecessor is not None and predecessor["text"] != criterion["text"]
|
|
180
|
+
# A changed definition carrying the same old proof is not new verification.
|
|
181
|
+
proof = sorted(criterion["evidence"], key=lambda d: (d["kind"], d["id"]))
|
|
182
|
+
needs_reverification = not history_complete or any(
|
|
183
|
+
c["id"] == criterion["id"]
|
|
184
|
+
and c["text"] != criterion["text"]
|
|
185
|
+
and sorted(c["evidence"], key=lambda d: (d["kind"], d["id"])) == proof
|
|
186
|
+
for prior in prior_bodies
|
|
187
|
+
for c in prior["acceptance"]
|
|
188
|
+
)
|
|
189
|
+
if effective == "passed" and (not available or needs_reverification):
|
|
190
|
+
effective = "unknown"
|
|
191
|
+
counts[effective] += 1
|
|
192
|
+
weighted[effective] += criterion.get("weight", 1)
|
|
193
|
+
criteria.append(
|
|
194
|
+
{
|
|
195
|
+
"id": criterion["id"],
|
|
196
|
+
"text": criterion["text"][:360],
|
|
197
|
+
"text_clipped": len(criterion["text"]) > 360,
|
|
198
|
+
"reported": criterion["state"],
|
|
199
|
+
"weight": criterion.get("weight", 1),
|
|
200
|
+
"effective": effective,
|
|
201
|
+
"evidence_available": available,
|
|
202
|
+
"evidence": criterion["evidence"],
|
|
203
|
+
"decision": criterion["decision"],
|
|
204
|
+
"definition_changed": changed,
|
|
205
|
+
"reverification_required": needs_reverification,
|
|
206
|
+
"reopened": predecessor is not None
|
|
207
|
+
and predecessor["state"] == "passed"
|
|
208
|
+
and effective != "passed",
|
|
209
|
+
}
|
|
210
|
+
)
|
|
211
|
+
current_scope = scope_hash(body["acceptance"])
|
|
212
|
+
try:
|
|
213
|
+
operations = (
|
|
214
|
+
[]
|
|
215
|
+
if recorded_position is not None
|
|
216
|
+
else self.w._operations(who, args, at, include_all=True)[0]
|
|
217
|
+
)
|
|
218
|
+
except LocalError:
|
|
219
|
+
return {
|
|
220
|
+
**result,
|
|
221
|
+
"status": "unavailable",
|
|
222
|
+
"tasks": [],
|
|
223
|
+
"events": [],
|
|
224
|
+
"reason": "current_source_authorization_unavailable",
|
|
225
|
+
}
|
|
226
|
+
task = {
|
|
227
|
+
**({"plan_id": stream["task"]} if "plan" in body else {}),
|
|
228
|
+
"task": stream["task"],
|
|
229
|
+
"run": args["run"],
|
|
230
|
+
"checkpoint": row["id"],
|
|
231
|
+
"revision": row["revision"],
|
|
232
|
+
"stream_revision": stream["revision"],
|
|
233
|
+
"writer": stream["writer"],
|
|
234
|
+
"checkpoint_writer": row["writer"],
|
|
235
|
+
"body_hash": row["body_hash"],
|
|
236
|
+
"source_position": row["position"],
|
|
237
|
+
"created_ms": row["created"],
|
|
238
|
+
"objective": body["objective"][:360],
|
|
239
|
+
"summary": self.w.latest_summary(who, row["id"], at),
|
|
240
|
+
"current_state": body["current_state"][:600],
|
|
241
|
+
"display_may_be_clipped": True,
|
|
242
|
+
"criteria": criteria,
|
|
243
|
+
"progress": {
|
|
244
|
+
**counts,
|
|
245
|
+
"total": len(criteria),
|
|
246
|
+
"weighted": {
|
|
247
|
+
**weighted,
|
|
248
|
+
"total": sum(weighted.values()),
|
|
249
|
+
"basis": "declared_weight_default_one",
|
|
250
|
+
},
|
|
251
|
+
"scope_hash": current_scope,
|
|
252
|
+
"history_complete": history_complete,
|
|
253
|
+
"previous_total": None
|
|
254
|
+
if previous_body is None
|
|
255
|
+
else len(previous_body["acceptance"]),
|
|
256
|
+
"scope_changed": None
|
|
257
|
+
if previous_body is None
|
|
258
|
+
else current_scope != scope_hash(previous_body["acceptance"]),
|
|
259
|
+
"reopened": sum(c["reopened"] for c in criteria),
|
|
260
|
+
},
|
|
261
|
+
"blockers": [
|
|
262
|
+
{"text": b["text"][:360], "owner": b["owner"]} for b in body["blockers"]
|
|
263
|
+
],
|
|
264
|
+
"verification": [
|
|
265
|
+
{
|
|
266
|
+
"name": v["name"][:240],
|
|
267
|
+
"result": v["result"],
|
|
268
|
+
"target_revision": v["target_revision"],
|
|
269
|
+
"environment": v["environment"][:120],
|
|
270
|
+
}
|
|
271
|
+
for v in body["verification"]
|
|
272
|
+
],
|
|
273
|
+
"operations": [
|
|
274
|
+
{
|
|
275
|
+
"id": op["id"],
|
|
276
|
+
"state": op["state"],
|
|
277
|
+
"reconciliation_required": op["reconciliation_required"],
|
|
278
|
+
}
|
|
279
|
+
for op in operations
|
|
280
|
+
],
|
|
281
|
+
"capture_gaps": body["capture"]["gaps"],
|
|
282
|
+
"heartbeat": {"status": "unknown", "recorded_ms": None},
|
|
283
|
+
"repository_freshness": "not_evaluated_by_task_projection",
|
|
284
|
+
"operations_coverage": "current"
|
|
285
|
+
if recorded_position is None
|
|
286
|
+
else "historical_operation_versions_not_retained",
|
|
287
|
+
}
|
|
288
|
+
result["tasks"].append(task)
|
|
289
|
+
task_index[(stream["task"], stream["stream"])] = task
|
|
290
|
+
linked_events[(stream["task"], stream["stream"])] = {
|
|
291
|
+
dep["id"] for dep in json.loads(row["dependencies"]) if dep["kind"] == "observation"
|
|
292
|
+
}
|
|
293
|
+
if len(result["tasks"]) >= 8:
|
|
294
|
+
break
|
|
295
|
+
candidates = self.db.execute(
|
|
296
|
+
"SELECT o.*,e.at_ms AS recorded_ms FROM observations o JOIN events e ON e.tenant=o.tenant AND e.position=o.position WHERE o.tenant=? AND o.project=? AND o.position<=? AND o.source IN ('reference-harness-v1','reference-heartbeat-v1') ORDER BY o.position DESC LIMIT 128",
|
|
297
|
+
(who["tenant"], project, frontier),
|
|
298
|
+
).fetchall()
|
|
299
|
+
for row in candidates:
|
|
300
|
+
if not self.s._visible(who, row, at):
|
|
301
|
+
continue
|
|
302
|
+
try:
|
|
303
|
+
event = load_strict(self.w.r._blob(row))
|
|
304
|
+
except (LocalError, OSError, ContractError):
|
|
305
|
+
continue
|
|
306
|
+
if (
|
|
307
|
+
not isinstance(event, dict)
|
|
308
|
+
or event.get("version") != 1
|
|
309
|
+
or event.get("id") != row["source_event"]
|
|
310
|
+
or event.get("project") != project
|
|
311
|
+
):
|
|
312
|
+
continue
|
|
313
|
+
if not isinstance(event.get("task"), str) or (
|
|
314
|
+
event.get("run") is not None and not isinstance(event.get("run"), str)
|
|
315
|
+
):
|
|
316
|
+
continue
|
|
317
|
+
stream_key = (
|
|
318
|
+
event["task"],
|
|
319
|
+
"task" if event.get("run") is None else "run:" + event["run"],
|
|
320
|
+
)
|
|
321
|
+
matched_task = task_index.get(stream_key)
|
|
322
|
+
if matched_task is None:
|
|
323
|
+
continue
|
|
324
|
+
if row["source"] == "reference-heartbeat-v1":
|
|
325
|
+
if recorded_position is not None:
|
|
326
|
+
continue # A historical contact is not current liveness.
|
|
327
|
+
if (
|
|
328
|
+
matched_task["heartbeat"]["status"] != "unknown"
|
|
329
|
+
or event.get("checkpoint") != matched_task["checkpoint"]
|
|
330
|
+
or event.get("revision") != matched_task["revision"]
|
|
331
|
+
or row["principal"] != matched_task["writer"]
|
|
332
|
+
):
|
|
333
|
+
continue
|
|
334
|
+
matched_task["heartbeat"] = {
|
|
335
|
+
"status": "recent" if 0 <= at - row["recorded_ms"] <= 120000 else "stale",
|
|
336
|
+
"recorded_ms": row["recorded_ms"],
|
|
337
|
+
"activity": event.get("activity")
|
|
338
|
+
if isinstance(event.get("activity"), str)
|
|
339
|
+
and event.get("activity") in {"idle", "model", "tool"}
|
|
340
|
+
else "unknown",
|
|
341
|
+
}
|
|
342
|
+
elif (
|
|
343
|
+
row["id"] in linked_events[stream_key]
|
|
344
|
+
and len(result["events"]) < 32
|
|
345
|
+
and isinstance(event.get("kind"), str)
|
|
346
|
+
and event.get("kind") in EVENT_KINDS
|
|
347
|
+
):
|
|
348
|
+
result["events"].append(
|
|
349
|
+
{
|
|
350
|
+
"id": row["id"],
|
|
351
|
+
"event_id": row["source_event"],
|
|
352
|
+
"kind": event["kind"],
|
|
353
|
+
"task": event["task"],
|
|
354
|
+
"run": event.get("run"),
|
|
355
|
+
"actor": row["principal"],
|
|
356
|
+
"recorded_ms": row["recorded_ms"],
|
|
357
|
+
"observed_ms": row["observed_at_ms"],
|
|
358
|
+
"source_position": row["position"],
|
|
359
|
+
}
|
|
360
|
+
)
|
|
361
|
+
if len(canonical_bytes(result)) > 262144:
|
|
362
|
+
return {
|
|
363
|
+
**result,
|
|
364
|
+
"status": "unavailable",
|
|
365
|
+
"tasks": [],
|
|
366
|
+
"events": [],
|
|
367
|
+
"reason": "snapshot_limit",
|
|
368
|
+
}
|
|
369
|
+
return result
|