Arachne 1.0
Arachne - the perpetual stitcher of Wikidata entities.
Loading...
Searching...
No Matches
inbox.hpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2026 Yaroslav Riabtsev
3 * SPDX-License-Identifier: MIT
4 */
5
6#ifndef ARACHNE_PENELOPE_INBOX_HPP
7#define ARACHNE_PENELOPE_INBOX_HPP
8
9#include <cstddef>
10#include <filesystem>
11#include <stdexcept>
12#include <string>
13#include <vector>
14
15namespace arachne::penelope {
16
17struct inbox_issue final {
18 std::string batch_id;
19 std::string code;
20 std::string json_path;
21 std::string message;
22 std::string value_json;
23};
24
31
32struct inbox_batch_report final {
33 std::filesystem::path path;
34 std::string batch_id;
37};
38
39struct inbox_result final {
40 bool ok { false };
41 bool applied { false };
42 std::size_t valid_count { 0 };
43 std::size_t applied_count { 0 };
44 std::size_t already_applied_count { 0 };
45 std::size_t rejected_count { 0 };
47};
48
49class inbox_error : public std::runtime_error {
50public:
51 using std::runtime_error::runtime_error;
52};
53
54/**
55 * Validate every plain-JSON batch under `<repository_root>/inbox`.
56 *
57 * The database is opened read-only. No issue rows, hints, files, or product
58 * records are modified.
59 */
60[[nodiscard]] inbox_result
61check_product_inbox(const std::filesystem::path& repository_root);
62
63/**
64 * Validate every pending batch first, then apply valid batches directly to the
65 * schema-v5 product database, one BEGIN IMMEDIATE transaction per batch.
66 */
67[[nodiscard]] inbox_result
68apply_product_inbox(const std::filesystem::path& repository_root);
69
70/** Rebuild review-only merge hints without merging any entity. */
71[[nodiscard]] std::size_t
72rebuild_product_merge_hints(const std::filesystem::path& repository_root);
73
74[[nodiscard]] const char* to_string(inbox_batch_status status) noexcept;
75
76} // namespace arachne::penelope
77
78#endif // ARACHNE_PENELOPE_INBOX_HPP
cli_error(std::string message, const int exit_code=2)
Definition main.cpp:57
bool flag(const std::string_view name) const
Definition main.cpp:243
const std::string & require(const std::string_view name) const
Definition main.cpp:226
std::map< std::string, std::string, std::less<> > values_
Definition main.cpp:248
std::optional< std::string > optional(const std::string_view name) const
Definition main.cpp:235
std::set< std::string, std::less<> > present_flags_
Definition main.cpp:249
options(const std::vector< std::string > &arguments, const std::size_t first, const std::initializer_list< std::string_view > allowed, const std::initializer_list< std::string_view > flags={})
Definition main.cpp:187
envelope_record intake(const intake_request &request)
void capture_inbox_baseline(const std::filesystem::path &inbox_root)
snapshot_result replace_candidate_snapshot(const candidate_snapshot_request &request)
Definition store.cpp:1523
acquired_artifact_v1 execute(const fetch_request_v1 &request) const
int main(const int argc, char **argv)
Definition main.cpp:2205
std::string join_strings(const std::span< const std::string > values, const std::string_view separator)
Definition main.cpp:1575
int command_inbox_baseline(const options &arguments)
Definition main.cpp:1218
const json & required_object(const json &parent, const std::string_view key)
Definition main.cpp:313
std::string validation_details(const arachnespace::contracts::validation_result &result, const std::string_view description)
Definition main.cpp:171
int command_fetch(const options &arguments)
Definition main.cpp:1506
std::size_t size_value(const json &object, const std::string_view key, const std::size_t fallback)
Definition main.cpp:281
written_run_manifest write_graph_run_manifest(const configuration &config, const std::string_view domain_directory, const std::string_view graph_domain, const std::string_view run_id, ordered_json configuration_hashes, ordered_json inputs, const arachne::penelope::snapshot_result &snapshot)
Definition main.cpp:601
void emit(const json &document)
Definition main.cpp:167
void atomic_write(const fs::path &destination, const std::string_view bytes, const bool replace)
Definition main.cpp:487
int command_contract_validate(const options &arguments)
Definition main.cpp:1117
ordered_json envelope_json(const arachne::coordination::envelope_record &envelope)
Definition main.cpp:560
json candidate_tables_for_viewer(const json &tables)
Definition main.cpp:916
fs::path resolved_path(const fs::path &path, const fs::path &relative_root)
Definition main.cpp:76
ordered_json wikidata_point_fetch_request(const configuration &config, const json &plan, const json &planned, const std::span< const std::string > entities, const std::string &request_id)
Definition main.cpp:1588
std::string read_bytes(const fs::path &path, const std::uintmax_t maximum_bytes, const std::string_view description)
Definition main.cpp:101
constexpr std::uintmax_t maximum_config_bytes
Definition main.cpp:49
resolved_snapshot_export resolve_snapshot_export(const configuration &config, const fs::path &control_path, const arachnespace::contracts::contract_name expected_contract, const std::string_view expected_kind)
Definition main.cpp:762
std::string form_encode(const std::string_view value)
Definition main.cpp:1548
void write_immutable_exact(const fs::path &destination, const std::string_view bytes, const std::string_view description)
Definition main.cpp:539
ordered_json snapshot_json(const arachne::penelope::snapshot_result &snapshot)
Definition main.cpp:579
int command_candidate_rebuild(const options &arguments)
Definition main.cpp:1354
int command_fetch_plan(const options &arguments)
Definition main.cpp:1782
void verify_external_source_snapshot(const configuration &config, const json &external_graph)
Definition main.cpp:836
arachne::ariadne::candidate_configuration candidate_configuration_from(const configuration &config)
Definition main.cpp:1081
constexpr std::uintmax_t maximum_export_bytes
Definition main.cpp:51
std::optional< fs::path > conventional_legacy_inbox()
Definition main.cpp:91
int command_intake(const options &arguments)
Definition main.cpp:1154
int command_cocoon_transition(const options &arguments)
Definition main.cpp:1177
json materialize_jsonl_export(const fs::path &path, const bool candidate)
Definition main.cpp:993
ordered_json actor_inbox_issues(const arachne::coordination::operational_ledger &ledger, const fs::path &inbox)
Definition main.cpp:1205
int dispatch(const std::vector< std::string > &arguments)
Definition main.cpp:2116
std::string policy_configuration_hash(const configuration &config, const std::string_view section)
Definition main.cpp:455
bool path_is_in_protected_legacy(const fs::path &path, const configuration &config)
Definition main.cpp:479
ordered_json wikidata_bulk_fetch_request(const json &plan, const json &planned, std::string request_id, std::string locator)
Definition main.cpp:1698
fs::path resolve_plan_artifact(const configuration &config, const fs::path &control_path, const std::string_view storage_ref)
Definition main.cpp:715
bool wikidata_entity_id(const std::string_view value)
Definition main.cpp:1566
configuration load_configuration(const fs::path &input_path)
Definition main.cpp:323
std::atomic< std::uint64_t > temporary_sequence
Definition main.cpp:53
ordered_json capabilities()
Definition main.cpp:2103
bool valid_logical_date(const std::string_view value)
Definition main.cpp:1056
int command_candidate_plan(const options &arguments)
Definition main.cpp:1951
int command_viewer_build(const options &arguments)
Definition main.cpp:2025
json parse_embedded_json(const json &row, const std::string_view key, json fallback)
Definition main.cpp:896
ordered_json issue_json(std::string path, std::string message)
Definition main.cpp:693
bool path_has_symlink(const fs::path &root, const fs::path &candidate)
Definition main.cpp:698
void verify_product_coverage(const json &external_graph, const json &product_tables)
Definition main.cpp:859
int command_inbox_verify(const options &arguments)
Definition main.cpp:1265
std::uint64_t unsigned_value(const json &object, const std::string_view key, const std::uint64_t default_value, const bool positive)
Definition main.cpp:252
int command_product_inbox(const bool apply)
Definition main.cpp:1297
fs::path command_path(const std::string &value)
Definition main.cpp:474
json read_json(const fs::path &path, const std::uintmax_t maximum_bytes, const std::string_view description)
Definition main.cpp:142
constexpr std::uintmax_t maximum_control_bytes
Definition main.cpp:50
std::string sha256(std::span< const std::byte > bytes)
Definition crypto.cpp:209
std::string sha256_file(const std::filesystem::path &path)
Definition crypto.cpp:221
inbox_result apply_product_inbox(const std::filesystem::path &repository_root)
const char * to_string(inbox_batch_status status) noexcept
Definition inbox.cpp:6133
inbox_result check_product_inbox(const std::filesystem::path &repository_root)
std::size_t rebuild_product_merge_hints(const std::filesystem::path &repository_root)
std::optional< fs::path > legacy_inbox
Definition main.cpp:299
std::vector< fs::path > protected_legacy_inboxes
Definition main.cpp:300
std::chrono::seconds candidate_lock_stale
Definition main.cpp:309
std::vector< inbox_issue > issues
Definition inbox.hpp:36
std::vector< inbox_batch_report > batches
Definition inbox.hpp:46
std::size_t already_applied_count
Definition inbox.hpp:44