跳转至

English fallback

This translation is missing; the canonical English reference follows.

Bounded intelligence acquisition

Experimental snapshot selections support explicitly supplied local bytes or one immutable official CISA KEV mirror revision. Acquisition retains observed receiver times, bounded original/partial bytes, immutable terminal records and honest batch outcomes. A failed or incomplete acquisition yields no usable snapshot.

Portable replay requires the original raw owning manifest, exact byte identities and consistent receiver/importer provenance. Existing verified enrichment owns finding application and triage. HTTPS transport and hashes do not authenticate publisher signatures, establish freshness, infer applicability or grant authority.

ADR 0060 and docs/INTELLIGENCE_ACQUISITION.md define this restricted Experimental contract. Other helpers and direct result construction remain Internal.

fuzzy1337.intelligence_acquisition

Experimental bounded intelligence acquisition with immutable terminal evidence receipts.

AcquisitionState

Bases: StrEnum

Distinguish complete publication from acquisition, parsing, or publication failures.

源代码位于: fuzzy1337/intelligence_acquisition.py
64
65
66
67
68
69
70
71
72
73
74
75
76
class AcquisitionState(StrEnum):
    """Distinguish complete publication from acquisition, parsing, or publication failures."""

    SUCCEEDED = "succeeded"
    REDIRECT_REJECTED = "redirect-rejected"
    HTTP_REJECTED = "http-rejected"
    FORMAT_REJECTED = "format-rejected"
    SIZE_EXCEEDED = "size-exceeded"
    TRANSPORT_FAILED = "transport-failed"
    TIMED_OUT = "timed-out"
    DIGEST_MISMATCH = "digest-mismatch"
    PARSE_FAILED = "parse-failed"
    STORAGE_FAILED = "storage-failed"

SyncState

Bases: StrEnum

Summarize explicit per-source outcomes without an all-or-nothing success claim.

源代码位于: fuzzy1337/intelligence_acquisition.py
79
80
81
82
83
84
class SyncState(StrEnum):
    """Summarize explicit per-source outcomes without an all-or-nothing success claim."""

    SUCCEEDED = "succeeded"
    PARTIAL = "partial"
    FAILED = "failed"

SnapshotSource dataclass

Carry caller-declared source facts separately from receiver-observed acquisition time.

源代码位于: fuzzy1337/intelligence_acquisition.py
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
@dataclass(frozen=True, slots=True)
class SnapshotSource:
    """Carry caller-declared source facts separately from receiver-observed acquisition time."""

    feed: IntelligenceFeed
    catalog_version: str
    origin: SourceOrigin
    publisher: str
    source_url: str
    license_name: str
    license_url: str
    expected_sha256: str | None = None

    def __post_init__(self) -> None:
        """Require bounded explicit attribution without fetching or authenticating it."""

        if not isinstance(self.feed, IntelligenceFeed) or not isinstance(self.origin, SourceOrigin):
            raise ValueError("snapshot source requires typed feed and origin")

        IntelligenceText(self.catalog_version, "catalog_version", 256)
        RequireReferenceText(self.publisher, "publisher")
        RequireReferenceText(self.license_name, "license_name")
        RequireReferenceUrl(self.source_url)
        RequireReferenceUrl(self.license_url)

        if self.expected_sha256 is not None:
            RequireReferenceDigest(self.expected_sha256)

    def ToDict(self) -> dict[str, object]:
        """Return declared source selection without claiming its license or publisher is verified.

        Returns:
            Feed, version, origin, attribution, locator, and optional expected byte digest.
        """

        return {
            "feed": self.feed.value, "catalog_version": self.catalog_version,
            "origin": self.origin.value, "publisher": self.publisher,
            "source_url": self.source_url, "license_name": self.license_name,
            "license_url": self.license_url, "expected_sha256": self.expected_sha256,
        }

__post_init__() -> None

Require bounded explicit attribution without fetching or authenticating it.

源代码位于: fuzzy1337/intelligence_acquisition.py
100
101
102
103
104
105
106
107
108
109
110
111
112
113
def __post_init__(self) -> None:
    """Require bounded explicit attribution without fetching or authenticating it."""

    if not isinstance(self.feed, IntelligenceFeed) or not isinstance(self.origin, SourceOrigin):
        raise ValueError("snapshot source requires typed feed and origin")

    IntelligenceText(self.catalog_version, "catalog_version", 256)
    RequireReferenceText(self.publisher, "publisher")
    RequireReferenceText(self.license_name, "license_name")
    RequireReferenceUrl(self.source_url)
    RequireReferenceUrl(self.license_url)

    if self.expected_sha256 is not None:
        RequireReferenceDigest(self.expected_sha256)

ToDict() -> dict[str, object]

Return declared source selection without claiming its license or publisher is verified.

返回:

类型 描述
dict[str, object]

Feed, version, origin, attribution, locator, and optional expected byte digest.

源代码位于: fuzzy1337/intelligence_acquisition.py
115
116
117
118
119
120
121
122
123
124
125
126
127
def ToDict(self) -> dict[str, object]:
    """Return declared source selection without claiming its license or publisher is verified.

    Returns:
        Feed, version, origin, attribution, locator, and optional expected byte digest.
    """

    return {
        "feed": self.feed.value, "catalog_version": self.catalog_version,
        "origin": self.origin.value, "publisher": self.publisher,
        "source_url": self.source_url, "license_name": self.license_name,
        "license_url": self.license_url, "expected_sha256": self.expected_sha256,
    }

SnapshotRequest dataclass

Choose explicit local bytes or one allowed HTTPS snapshot with finite receiver limits.

源代码位于: fuzzy1337/intelligence_acquisition.py
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
@dataclass(frozen=True, slots=True)
class SnapshotRequest:
    """Choose explicit local bytes or one allowed HTTPS snapshot with finite receiver limits."""

    source: SnapshotSource
    payload: bytes | None = None
    max_bytes: int = MAX_SOURCE_BYTES
    timeout_seconds: float = 30.0

    def __post_init__(self) -> None:
        """Reject untyped selections, unbounded limits, and unsupported remote source choices."""

        if not isinstance(self.source, SnapshotSource):
            raise ValueError("snapshot request requires a typed source")

        if self.payload is not None and not isinstance(self.payload, bytes):
            raise ValueError("local snapshot payload must be explicitly supplied bytes")

        if type(self.max_bytes) is not int or not 1 <= self.max_bytes <= MAX_SOURCE_BYTES:
            raise ValueError("acquisition byte limit must be positive and at most 16 MiB")

        if (
            type(self.timeout_seconds) not in (int, float)
            or not math.isfinite(self.timeout_seconds) or not 0.05 <= self.timeout_seconds <= 60
        ):
            raise ValueError("acquisition timeout must be finite and between 0.05 and 60 seconds")

        if self.payload is None:
            RequireRemoteSelection(self.source)

__post_init__() -> None

Reject untyped selections, unbounded limits, and unsupported remote source choices.

源代码位于: fuzzy1337/intelligence_acquisition.py
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
def __post_init__(self) -> None:
    """Reject untyped selections, unbounded limits, and unsupported remote source choices."""

    if not isinstance(self.source, SnapshotSource):
        raise ValueError("snapshot request requires a typed source")

    if self.payload is not None and not isinstance(self.payload, bytes):
        raise ValueError("local snapshot payload must be explicitly supplied bytes")

    if type(self.max_bytes) is not int or not 1 <= self.max_bytes <= MAX_SOURCE_BYTES:
        raise ValueError("acquisition byte limit must be positive and at most 16 MiB")

    if (
        type(self.timeout_seconds) not in (int, float)
        or not math.isfinite(self.timeout_seconds) or not 0.05 <= self.timeout_seconds <= 60
    ):
        raise ValueError("acquisition timeout must be finite and between 0.05 and 60 seconds")

    if self.payload is None:
        RequireRemoteSelection(self.source)

AcquisitionOutcome dataclass

Retain exact publication facts; failed acquisition supplies no usable snapshot.

源代码位于: fuzzy1337/intelligence_acquisition.py
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
@dataclass(frozen=True, slots=True)
class AcquisitionOutcome:
    """Retain exact publication facts; failed acquisition supplies no usable snapshot."""

    state: AcquisitionState
    source: SnapshotSource
    started_at: str
    finished_at: str
    received_bytes: int
    body_complete: bool
    http_status: int | None
    transport: str
    max_bytes: int
    timeout_seconds: float
    raw: EvidenceRecord | None = None
    snapshot: IntelligenceSnapshot | None = None
    snapshot_record: EvidenceRecord | None = None
    receipt: EvidenceRecord | None = None

    def ToDict(self) -> dict[str, object]:
        """Describe terminal facts without raw bytes, local paths, secrets, or inferred approval.

        Returns:
            Controlled schema-v1 acquisition receipt content.
        """

        return {
            "schema_version": ACQUISITION_SCHEMA_VERSION, "state": self.state.value,
            "source": self.source.ToDict(), "started_at": self.started_at,
            "finished_at": self.finished_at, "received_bytes": self.received_bytes,
            "body_complete": self.body_complete, "http_status": self.http_status,
            "transport": self.transport,
            "limits": {"max_bytes": self.max_bytes,
                       "receiver_timeout_seconds": self.timeout_seconds},
            "raw": JsonValue(self.raw) if self.raw is not None else None,
            "snapshot_reference": self.snapshot.Reference() if self.snapshot is not None else None,
            "snapshot_record": (
                JsonValue(self.snapshot_record) if self.snapshot_record is not None else None
            ),
            "publisher_authentication": "not-assessed",
        }

ToDict() -> dict[str, object]

Describe terminal facts without raw bytes, local paths, secrets, or inferred approval.

返回:

类型 描述
dict[str, object]

Controlled schema-v1 acquisition receipt content.

源代码位于: fuzzy1337/intelligence_acquisition.py
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
def ToDict(self) -> dict[str, object]:
    """Describe terminal facts without raw bytes, local paths, secrets, or inferred approval.

    Returns:
        Controlled schema-v1 acquisition receipt content.
    """

    return {
        "schema_version": ACQUISITION_SCHEMA_VERSION, "state": self.state.value,
        "source": self.source.ToDict(), "started_at": self.started_at,
        "finished_at": self.finished_at, "received_bytes": self.received_bytes,
        "body_complete": self.body_complete, "http_status": self.http_status,
        "transport": self.transport,
        "limits": {"max_bytes": self.max_bytes,
                   "receiver_timeout_seconds": self.timeout_seconds},
        "raw": JsonValue(self.raw) if self.raw is not None else None,
        "snapshot_reference": self.snapshot.Reference() if self.snapshot is not None else None,
        "snapshot_record": (
            JsonValue(self.snapshot_record) if self.snapshot_record is not None else None
        ),
        "publisher_authentication": "not-assessed",
    }

SyncOutcome dataclass

Return independent acquisitions in caller order, including actual partial success.

源代码位于: fuzzy1337/intelligence_acquisition.py
243
244
245
246
247
248
@dataclass(frozen=True, slots=True)
class SyncOutcome:
    """Return independent acquisitions in caller order, including actual partial success."""

    state: SyncState
    outcomes: tuple[AcquisitionOutcome, ...]

CisaKevSource(commit: str, catalog_version: str, *, expected_sha256: str | None = None) -> SnapshotSource

Select one immutable official CISA mirror revision without discovering a latest version.

参数:

名称 类型 描述 默认
commit str

Exact lowercase 40-hex repository commit chosen by the caller.

必需
catalog_version str

Exact JSON catalogVersion expected by the existing parser.

必需
expected_sha256 str | None

Optional caller-owned byte pin; never a publisher signature.

None

返回:

类型 描述
SnapshotSource

Explicit CISA KEV mirror JSON and same-revision license attribution.

源代码位于: fuzzy1337/intelligence_acquisition.py
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
def CisaKevSource(
    commit: str, catalog_version: str, *, expected_sha256: str | None = None,
) -> SnapshotSource:
    """Select one immutable official CISA mirror revision without discovering a latest version.

    Args:
        commit: Exact lowercase 40-hex repository commit chosen by the caller.
        catalog_version: Exact JSON catalogVersion expected by the existing parser.
        expected_sha256: Optional caller-owned byte pin; never a publisher signature.

    Returns:
        Explicit CISA KEV mirror JSON and same-revision license attribution.
    """

    if not isinstance(commit, str) or not _COMMIT_PATTERN.fullmatch(commit):
        raise ValueError("CISA KEV requires an exact lowercase repository commit")

    return SnapshotSource(
        IntelligenceFeed.KEV, catalog_version, SourceOrigin.EXTERNAL, "CISA",
        _KEV_PREFIX + commit + _KEV_FILENAME, "CC0-1.0",
        "https://github.com/cisagov/kev-data/blob/" + commit + "/LICENSE", expected_sha256,
    )

RequireRemoteSelection(source: SnapshotSource) -> None

Allow only the documented pinned mirror, never an arbitrary URL or moving ref.

参数:

名称 类型 描述 默认
source SnapshotSource

Explicit selection proposed for HTTPS acquisition.

必需
源代码位于: fuzzy1337/intelligence_acquisition.py
154
155
156
157
158
159
160
161
162
163
164
165
166
def RequireRemoteSelection(source: SnapshotSource) -> None:
    """Allow only the documented pinned mirror, never an arbitrary URL or moving ref.

    Args:
        source: Explicit selection proposed for HTTPS acquisition.
    """

    commit = source.source_url.removeprefix(_KEV_PREFIX).removesuffix(_KEV_FILENAME)

    if not _COMMIT_PATTERN.fullmatch(commit) or source != CisaKevSource(
        commit, source.catalog_version, expected_sha256=source.expected_sha256,
    ):
        raise ValueError("HTTPS acquisition requires the explicitly pinned official CISA selection")

AcquisitionTime() -> str

Observe receiver UTC time without accepting a caller's acquisition timestamp.

返回:

类型 描述
str

Offset-aware UTC timestamp with fixed microsecond precision.

源代码位于: fuzzy1337/intelligence_acquisition.py
251
252
253
254
255
256
257
258
def AcquisitionTime() -> str:
    """Observe receiver UTC time without accepting a caller's acquisition timestamp.

    Returns:
        Offset-aware UTC timestamp with fixed microsecond precision.
    """

    return datetime.now(timezone.utc).isoformat(timespec="microseconds")

FetchRemoteBytes(request: SnapshotRequest) -> tuple[bytes, AcquisitionState, int | None]

Bound the whole isolated HTTPS receiver, retaining only actually delivered body bytes.

参数:

名称 类型 描述 默认
request SnapshotRequest

Prevalidated pinned official source and finite byte/deadline limits.

必需

返回:

类型 描述
tuple[bytes, AcquisitionState, int | None]

Original bounded complete/partial bytes, terminal transport state, and observed HTTP status.

源代码位于: fuzzy1337/intelligence_acquisition.py
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
def FetchRemoteBytes(request: SnapshotRequest) -> tuple[bytes, AcquisitionState, int | None]:
    """Bound the whole isolated HTTPS receiver, retaining only actually delivered body bytes.

    Args:
        request: Prevalidated pinned official source and finite byte/deadline limits.

    Returns:
        Original bounded complete/partial bytes, terminal transport state, and observed HTTP status.
    """

    worker = Path(__file__).with_name("intelligence_transport.py")
    started = time.monotonic()

    try:
        process = subprocess.Popen(
            [sys.executable, "-I", "-S", str(worker), request.source.source_url,
             str(request.max_bytes), str(request.timeout_seconds)],
            stdin=subprocess.DEVNULL, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, env={},
        )

    except OSError:
        return b"", AcquisitionState.TRANSPORT_FAILED, None

    timed_out = False

    try:
        remaining = max(0.0, request.timeout_seconds - (time.monotonic() - started))
        output, _ = process.communicate(timeout=remaining)

    except subprocess.TimeoutExpired:
        timed_out = True
        process.kill()
        output, _ = process.communicate()

    except BaseException:
        process.kill()
        process.communicate()

        raise

    line, separator, body = output.partition(b"\n")
    status = None

    if separator and len(line) <= 128:
        try:
            metadata = json.loads(line)

            if (
                isinstance(metadata, dict) and set(metadata) == {"status"}
                and type(metadata["status"]) is int and 100 <= metadata["status"] <= 599
            ):
                status = metadata["status"]

        except (ValueError, UnicodeError):
            pass

    if status is None or len(body) > request.max_bytes:
        return b"", (
            AcquisitionState.TIMED_OUT if timed_out else AcquisitionState.TRANSPORT_FAILED
        ), status

    state = {
        0: AcquisitionState.SUCCEEDED, REDIRECT_EXIT: AcquisitionState.REDIRECT_REJECTED,
        HTTP_EXIT: AcquisitionState.HTTP_REJECTED, FORMAT_EXIT: AcquisitionState.FORMAT_REJECTED,
        SIZE_EXIT: AcquisitionState.SIZE_EXCEEDED, TIMEOUT_EXIT: AcquisitionState.TIMED_OUT,
    }.get(process.returncode, AcquisitionState.TRANSPORT_FAILED)

    if timed_out:
        state = AcquisitionState.TIMED_OUT

    if state is AcquisitionState.SUCCEEDED and status != 200:
        state = AcquisitionState.TRANSPORT_FAILED

    return body, state, status

AcquireIntelligenceSnapshot(workspace_root: Path, request: SnapshotRequest, *, scope_reference: str) -> AcquisitionOutcome

Acquire one explicit source and publish immutable raw, parsed, and terminal evidence.

参数:

名称 类型 描述 默认
workspace_root Path

Existing owning workspace and evidence partition.

必需
request SnapshotRequest

Explicit local bytes or allowed pinned official HTTPS source.

必需
scope_reference str

Explicit non-secret collection attribution, never scan authority.

必需

返回:

类型 描述
AcquisitionOutcome

Exact terminal outcome. Parse/digest failure retains raw bytes; storage failure can leave

AcquisitionOutcome

immutable orphan bytes or a published snapshot and never claims successful acquisition.

源代码位于: fuzzy1337/intelligence_acquisition.py
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
def AcquireIntelligenceSnapshot(
    workspace_root: Path, request: SnapshotRequest, *, scope_reference: str,
) -> AcquisitionOutcome:
    """Acquire one explicit source and publish immutable raw, parsed, and terminal evidence.

    Args:
        workspace_root: Existing owning workspace and evidence partition.
        request: Explicit local bytes or allowed pinned official HTTPS source.
        scope_reference: Explicit non-secret collection attribution, never scan authority.

    Returns:
        Exact terminal outcome. Parse/digest failure retains raw bytes; storage failure can leave
        immutable orphan bytes or a published snapshot and never claims successful acquisition.
    """

    if not isinstance(request, SnapshotRequest):
        raise ValueError("acquisition requires a typed request")

    RequireReferenceText(scope_reference, "scope_reference")
    workspace = LocalWorkspaceStore(workspace_root)
    owner = workspace.Open()
    store = LocalEvidenceStore(workspace.root / "evidence")
    started_at = AcquisitionTime()

    if request.payload is None:
        payload, state, status = FetchRemoteBytes(request)

    else:
        payload = request.payload[:request.max_bytes]
        state = (
            AcquisitionState.SUCCEEDED if len(request.payload) <= request.max_bytes
            else AcquisitionState.SIZE_EXCEEDED
        )
        status = None

    finished_at = AcquisitionTime()
    outcome = AcquisitionOutcome(
        state, request.source, started_at, finished_at, len(payload),
        state is AcquisitionState.SUCCEEDED, status,
        "https" if request.payload is None else "local-bytes",
        request.max_bytes, request.timeout_seconds,
    )
    provenance = EvidenceProvenance(
        owner.workspace_id, scope_reference, IMPORTER_ID, IMPORTER_VERSION, None,
        started_at, finished_at,
    )

    try:
        if payload or outcome.body_complete:
            raw = store.Put(
                payload, "intelligence-source" if outcome.body_complete else "intelligence-partial",
                _MEDIA_TYPES[request.source.feed], provenance,
            )
            outcome = replace(outcome, raw=raw)

        if outcome.body_complete:
            expected = request.source.expected_sha256

            if expected is not None and hashlib.sha256(payload).hexdigest() != expected:
                outcome = replace(outcome, state=AcquisitionState.DIGEST_MISMATCH)

            else:
                if outcome.raw is None:
                    raise ValueError("complete acquisition requires raw evidence publication")

                source = ReferenceSource(
                    request.source.origin, request.source.publisher, request.source.source_url,
                    outcome.raw.reference.sha256, request.source.license_name,
                    request.source.license_url, finished_at, IMPORTER_ID, IMPORTER_VERSION,
                )

                try:
                    snapshot = ParseIntelligenceSnapshot(
                        payload, request.source.feed, request.source.catalog_version,
                        source, outcome.raw.reference,
                    )
                    serialized = snapshot.Serialize()

                except ValueError:
                    outcome = replace(outcome, state=AcquisitionState.PARSE_FAILED)

                else:
                    snapshot_record = store.Put(
                        serialized, "intelligence-snapshot", "application/json", provenance,
                    )
                    outcome = replace(outcome, snapshot=snapshot, snapshot_record=snapshot_record)

        receipt = store.Put(
            CanonicalModelJson(outcome.ToDict()), "intelligence-acquisition", "application/json",
            provenance,
        )

        return replace(outcome, receipt=receipt)

    except EvidenceError:
        return replace(outcome, state=AcquisitionState.STORAGE_FAILED, snapshot=None)

SyncIntelligenceSnapshots(workspace_root: Path, requests: tuple[SnapshotRequest, ...], *, scope_reference: str) -> SyncOutcome

Acquire a bounded explicit batch without discovery, retries, rollback, or model mutation.

参数:

名称 类型 描述 默认
workspace_root Path

Existing owning workspace.

必需
requests tuple[SnapshotRequest, ...]

One to sixteen explicit independent selections in processing order.

必需
scope_reference str

Explicit collection attribution reused for each source.

必需

返回:

类型 描述
SyncOutcome

All per-source terminal receipts and an honest complete, partial, or failed summary.

源代码位于: fuzzy1337/intelligence_acquisition.py
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
def SyncIntelligenceSnapshots(
    workspace_root: Path, requests: tuple[SnapshotRequest, ...], *, scope_reference: str,
) -> SyncOutcome:
    """Acquire a bounded explicit batch without discovery, retries, rollback, or model mutation.

    Args:
        workspace_root: Existing owning workspace.
        requests: One to sixteen explicit independent selections in processing order.
        scope_reference: Explicit collection attribution reused for each source.

    Returns:
        All per-source terminal receipts and an honest complete, partial, or failed summary.
    """

    if (
        not isinstance(requests, tuple) or not 1 <= len(requests) <= 16
        or any(not isinstance(request, SnapshotRequest) for request in requests)
    ):
        raise ValueError("sync requires one to sixteen explicit typed requests")

    outcomes = tuple(
        AcquireIntelligenceSnapshot(workspace_root, request, scope_reference=scope_reference)
        for request in requests
    )
    successes = sum(outcome.state is AcquisitionState.SUCCEEDED for outcome in outcomes)
    state = (
        SyncState.SUCCEEDED if successes == len(outcomes)
        else SyncState.PARTIAL if successes else SyncState.FAILED
    )

    return SyncOutcome(state, outcomes)

LoadAcquiredSnapshot(workspace_root: Path, evidence_id: str) -> IntelligenceSnapshot

Verify a stored parsed snapshot and reparse its original source before returning it.

参数:

名称 类型 描述 默认
workspace_root Path

Existing owning workspace; foreign copied manifests are rejected.

必需
evidence_id str

Immutable intelligence-snapshot evidence-manifest identity.

必需

返回:

类型 描述
IntelligenceSnapshot

Original verified snapshot ready for the existing verified enrichment consumer.

源代码位于: fuzzy1337/intelligence_acquisition.py
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
def LoadAcquiredSnapshot(workspace_root: Path, evidence_id: str) -> IntelligenceSnapshot:
    """Verify a stored parsed snapshot and reparse its original source before returning it.

    Args:
        workspace_root: Existing owning workspace; foreign copied manifests are rejected.
        evidence_id: Immutable intelligence-snapshot evidence-manifest identity.

    Returns:
        Original verified snapshot ready for the existing verified enrichment consumer.
    """

    workspace = LocalWorkspaceStore(workspace_root)
    owner = workspace.Open()
    store = LocalEvidenceStore(workspace.root / "evidence")
    record = store.Get(evidence_id)

    if record.provenance.workspace_id != owner.workspace_id or (
        record.reference.role != "intelligence-snapshot"
        or record.reference.media_type != "application/json"
        or record.provenance.source_id != IMPORTER_ID
        or record.provenance.source_version != IMPORTER_VERSION
    ):
        raise ValueError("snapshot must be an intelligence artifact in the owning workspace")

    snapshot = IntelligenceSnapshot.Deserialize(store.Read(record.reference))

    if snapshot.evidence.role != "intelligence-source":
        raise ValueError("acquired snapshot must reference a complete original source artifact")

    if (
        snapshot.source.importer_id != record.provenance.source_id
        or snapshot.source.importer_version != record.provenance.source_version
        or snapshot.source.acquired_at != record.provenance.finished_at
        or snapshot.evidence.media_type != _MEDIA_TYPES[snapshot.feed]
    ):
        raise ValueError("snapshot acquisition attribution must match original receiver provenance")

    raw_record = EvidenceRecord(snapshot.evidence, record.provenance)

    if store.Get(raw_record.evidence_id) != raw_record:
        raise ValueError("snapshot must retain the exact owning original acquisition manifest")

    reparsed = ParseIntelligenceSnapshot(
        store.Read(snapshot.evidence), snapshot.feed, snapshot.catalog_version,
        snapshot.source, snapshot.evidence,
    )

    if reparsed != snapshot:
        raise ValueError("stored snapshot disagrees with verified original source bytes")

    return snapshot