@bitkyc08/opencodex 2.99.0-preview.20261108 → 2.100.0
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.
- package/AGENTS_INSTALL.md +19 -1
- package/README.md +37 -33
- package/SPONSORS.md +5 -1
- package/bin/ocx.mjs +1 -1
- package/gui/dist/assets/{App-C1hGwaN1.css → App-COo8Yopd.css} +1 -1
- package/gui/dist/assets/App-CitvEefy.js +59 -0
- package/gui/dist/assets/Tray-CeKVWQyB.js +1 -0
- package/gui/dist/assets/{brand-mark-DpiBmFGI.js → brand-mark-M92UnxX2.js} +1 -1
- package/gui/dist/assets/index-BP47do6-.js +94 -0
- package/gui/dist/assets/index-DmDooSAG.css +2 -0
- package/gui/dist/assets/{segment-thumb-features-JcszQ18T.js → segment-thumb-features-CcxZBnxv.js} +1 -1
- package/gui/dist/classic/assets/App-aYgIQMxI.js +58 -0
- package/gui/dist/classic/assets/{Tray-5v86r9Az.js → Tray-D8jfUXpQ.js} +1 -1
- package/gui/dist/classic/assets/index-CfGqHooN.js +94 -0
- package/gui/dist/classic/assets/quota-summary-R-ih7OlS.js +1 -0
- package/gui/dist/classic/index.html +1 -1
- package/gui/dist/index.html +2 -2
- package/native/ocx-child/Cargo.lock +215 -0
- package/native/ocx-child/Cargo.toml +31 -0
- package/native/ocx-child/src/cli.rs +1901 -0
- package/native/ocx-child/src/codex_home.rs +429 -0
- package/native/ocx-child/src/codex_settings.rs +231 -0
- package/native/ocx-child/src/daemon.rs +363 -0
- package/native/ocx-child/src/http_wire.rs +619 -0
- package/native/ocx-child/src/journal.rs +977 -0
- package/native/ocx-child/src/lib.rs +22 -0
- package/native/ocx-child/src/main.rs +9 -0
- package/native/ocx-child/src/parity.rs +102 -0
- package/native/ocx-child/src/platform.rs +1487 -0
- package/native/ocx-child/src/relay.rs +1288 -0
- package/native/ocx-child/src/relay_auth.rs +166 -0
- package/native/ocx-child/src/routes.rs +236 -0
- package/native/ocx-child/src/state.rs +190 -0
- package/native/ocx-child/src/test_hooks.rs +58 -0
- package/native/ocx-child/src/toml_surgeon.rs +1156 -0
- package/package.json +8 -2
- package/src/adapters/anthropic.ts +28 -2
- package/src/adapters/claude-cli/adapter.ts +5 -25
- package/src/adapters/claude-cli/instruction-images.ts +31 -0
- package/src/adapters/claude-cli/stable-replay.ts +42 -14
- package/src/adapters/claude-cli/usage-admission.ts +53 -64
- package/src/adapters/coding-agent/protocol.ts +1 -1
- package/src/adapters/devin/live-models.ts +3 -0
- package/src/adapters/google-http.ts +3 -0
- package/src/adapters/google-vertex-key-project.ts +10 -2
- package/src/adapters/google.ts +40 -8
- package/src/adapters/kiro/usage.ts +3 -13
- package/src/adapters/openai-responses/passthrough.ts +5 -2
- package/src/adapters/openai-responses/request-strips.ts +32 -0
- package/src/adapters/openai-responses/tool-schema.ts +9 -4
- package/src/chat/inbound.ts +1 -1
- package/src/claude/auth-detect.ts +26 -8
- package/src/claude/inbound-content-options.ts +18 -3
- package/src/claude/inbound.ts +5 -2
- package/src/cli/bundled-bun-diagnostic.ts +91 -0
- package/src/cli/capabilities-agents-routing.ts +2 -2
- package/src/cli/capabilities-observe-system.ts +60 -0
- package/src/cli/combo-input.ts +6 -0
- package/src/cli/combo-result.ts +1 -1
- package/src/cli/combo.ts +4 -0
- package/src/cli/config-command.ts +16 -2
- package/src/cli/connect.ts +12 -10
- package/src/cli/dispatch.ts +4 -0
- package/src/cli/doctor.ts +11 -0
- package/src/cli/help.ts +1 -0
- package/src/cli/init.ts +4 -0
- package/src/cli/link-enrollment.ts +152 -25
- package/src/cli/link-local-control.ts +49 -0
- package/src/cli/link.ts +37 -10
- package/src/cli/provider-lifecycle-runtime.ts +4 -2
- package/src/cli/registry.ts +13 -0
- package/src/cli/star-prompt.ts +2 -0
- package/src/cli/status.ts +1 -1
- package/src/cli/telemetry-profile.ts +206 -0
- package/src/cli/telemetry.ts +260 -0
- package/src/client/hub-relay.ts +26 -0
- package/src/client/machine-api.ts +3 -0
- package/src/clients/config-export/t3code.ts +44 -5
- package/src/clients/omo-role-models.ts +1 -1
- package/src/codex/catalog/bundled.ts +44 -2
- package/src/codex/runtime.ts +12 -0
- package/src/codex/shim-restore-lock.ts +67 -30
- package/src/combos/types.ts +21 -1
- package/src/config/atomic-write.ts +24 -1
- package/src/config/diagnostics.ts +15 -0
- package/src/config/live-reconcile.ts +17 -0
- package/src/config/load-degrade.ts +16 -0
- package/src/config/provider-validation.ts +29 -0
- package/src/config/schema/config-schema.ts +24 -0
- package/src/config/schema/leaf-validators.ts +17 -0
- package/src/config/telemetry-carry.ts +30 -0
- package/src/config.ts +13 -1
- package/src/generated/compatibility-version.json +405 -153
- package/src/generated/model-metadata.ts +3 -3
- package/src/integrations/aside-profiles.ts +7 -1
- package/src/integrations/owned-refresh.ts +9 -2
- package/src/lab/artifacts/secure-fs.ts +12 -11
- package/src/lab/fabric/scratch.ts +11 -9
- package/src/lab/public/community.ts +2 -3
- package/src/lab/public/file-safety.ts +18 -20
- package/src/lab/public/mutation-lock.ts +109 -337
- package/src/lab/public/private-file.ts +4 -3
- package/src/lib/bun-runtime-preflight.ts +1 -1
- package/src/lib/codex-catalog-read-only.ts +122 -0
- package/src/lib/config-ownership.ts +49 -18
- package/src/lib/errors.ts +11 -0
- package/src/lib/gcp-adc.ts +167 -48
- package/src/lib/jsonc.ts +4 -2
- package/src/lib/local-control-socket.ts +88 -0
- package/src/lib/privacy.ts +15 -0
- package/src/lib/provider-client-headers.ts +3 -0
- package/src/lib/token-estimate.ts +13 -2
- package/src/link/child-binary-source.ts +228 -0
- package/src/link/ephemeral-child.ts +45 -0
- package/src/link/remote-plant.ts +306 -0
- package/src/link/remote-windows.ts +59 -5
- package/src/link/ssh-argv.ts +71 -8
- package/src/link/status-projection.ts +2 -0
- package/src/link/store.ts +5 -1
- package/src/oauth/claude-keychain-read.ts +165 -0
- package/src/oauth/local-token-detect.ts +14 -17
- package/src/protocols/envelope.ts +20 -2
- package/src/providers/api-key-selection.ts +8 -2
- package/src/providers/claude-cli-usage-state.ts +93 -0
- package/src/providers/github-copilot-auto.ts +25 -5
- package/src/providers/meta-muse-plan-refusal.ts +94 -0
- package/src/providers/model-rename-fields.ts +3 -0
- package/src/providers/quota/vendor-probes-key.ts +23 -4
- package/src/providers/quota/vendor-probes-oauth.ts +59 -0
- package/src/providers/quota/workbuddy.ts +2 -2
- package/src/providers/quota.ts +25 -18
- package/src/providers/registry/entries-core.ts +7 -4
- package/src/providers/registry/entries-extended.ts +39 -7
- package/src/providers/registry/model-seeds.ts +10 -2
- package/src/providers/resolved-model-policy.ts +4 -0
- package/src/providers/routed-config.ts +30 -3
- package/src/providers/stale-no-vision-seed-migration.ts +7 -0
- package/src/providers/vertex-environment-authority.ts +50 -0
- package/src/providers/workbuddy-credit-balance.ts +38 -6
- package/src/quota-pool/assemble.ts +14 -6
- package/src/router.ts +1 -0
- package/src/server/adapter-resolve.ts +11 -6
- package/src/server/audio-dictation.ts +21 -7
- package/src/server/auth-cors.ts +19 -0
- package/src/server/background-lifecycle.ts +71 -0
- package/src/server/chat-completions.ts +2 -0
- package/src/server/claude-messages.ts +30 -3
- package/src/server/index/live-sideband.ts +15 -1
- package/src/server/index/local-control-listener.ts +515 -0
- package/src/server/index/optional-listeners.ts +21 -1
- package/src/server/index/serve-options.ts +4 -3
- package/src/server/index/websocket-handler.ts +2 -0
- package/src/server/index.ts +3 -0
- package/src/server/management/combo-routes.ts +6 -1
- package/src/server/management/context.ts +1 -0
- package/src/server/management/link-child-preflight.ts +74 -0
- package/src/server/management/link-enrollment.ts +190 -25
- package/src/server/management/link-route-state.ts +6 -1
- package/src/server/management/link-routes.ts +27 -9
- package/src/server/management/model-rows.ts +4 -0
- package/src/server/management/oauth-account-routes.ts +9 -4
- package/src/server/management/provider-overwrite-carry.ts +9 -2
- package/src/server/management/provider-routes.ts +14 -0
- package/src/server/management/provider-thinking-display-patch.ts +54 -0
- package/src/server/management/route-registry.ts +7 -0
- package/src/server/management/session-routes.ts +4 -1
- package/src/server/management/telemetry-routes.ts +37 -0
- package/src/server/management/usage-aggregate-cache.ts +290 -67
- package/src/server/management-api.ts +11 -2
- package/src/server/messages-native-preflight.ts +166 -0
- package/src/server/messages-native.ts +143 -43
- package/src/server/messages-shared.ts +14 -0
- package/src/server/proxy-liveness.ts +99 -6
- package/src/server/request-log-conversation.ts +18 -2
- package/src/server/request-log.ts +7 -2
- package/src/server/responses/adapter-continuation.ts +1 -0
- package/src/server/responses/adapter-dispatch.ts +11 -28
- package/src/server/responses/adapter-failure-message.ts +68 -0
- package/src/server/responses/combo-stream-preflight.ts +14 -2
- package/src/server/responses/core-auth.ts +26 -5
- package/src/server/responses/core-codex-account.ts +8 -1
- package/src/server/responses/core-combo-failure.ts +6 -1
- package/src/server/responses/core-combo-native.ts +150 -37
- package/src/server/responses/core-combo.ts +15 -9
- package/src/server/responses/core-normalize.ts +1 -0
- package/src/server/responses/core-options.ts +7 -1
- package/src/server/responses/core-pipeline.ts +21 -1
- package/src/server/responses/fetch-helpers.ts +5 -0
- package/src/server/responses/opengateway-completion-guard.ts +7 -3
- package/src/server/responses/passthrough-delivery.ts +8 -1
- package/src/server/responses/passthrough-error.ts +22 -0
- package/src/server/responses/request-prepare.ts +7 -1
- package/src/server/responses/request-transport.ts +28 -5
- package/src/server/responses/run-turn-execution.ts +13 -0
- package/src/server/sse-frame-buffer.ts +5 -0
- package/src/server/ws-bridge.ts +10 -0
- package/src/service/launchd.ts +78 -4
- package/src/telemetry/aggregate.ts +348 -0
- package/src/telemetry/consent.ts +128 -0
- package/src/telemetry/contract.ts +403 -0
- package/src/telemetry/disclosure.ts +19 -0
- package/src/telemetry/install-id.ts +226 -0
- package/src/telemetry/payload.ts +129 -0
- package/src/telemetry/profile/client.ts +150 -0
- package/src/telemetry/profile/contract.ts +288 -0
- package/src/telemetry/profile/disclosure.ts +14 -0
- package/src/telemetry/profile/paths.ts +13 -0
- package/src/telemetry/profile/routes.ts +99 -0
- package/src/telemetry/profile/service.ts +234 -0
- package/src/telemetry/profile/state.ts +189 -0
- package/src/telemetry/profile/sync.ts +276 -0
- package/src/telemetry/routes.ts +183 -0
- package/src/telemetry/scheduler.ts +386 -0
- package/src/telemetry/sender.ts +97 -0
- package/src/telemetry/state.ts +334 -0
- package/src/types/combo-jev-effort-mode.ts +11 -0
- package/src/types/config.ts +3 -0
- package/src/types/provider.ts +11 -1
- package/src/types/request.ts +2 -0
- package/src/types/telemetry.ts +15 -0
- package/src/types/wire.ts +10 -0
- package/src/types.ts +5 -0
- package/src/update/index.ts +7 -1
- package/src/update/minisign.d.mts +17 -0
- package/src/update/minisign.mjs +88 -0
- package/src/update/signed-supply.d.mts +59 -0
- package/src/update/signed-supply.mjs +289 -0
- package/src/update/trust-root.json +38 -0
- package/src/update/update-bounded-json.d.mts +4 -0
- package/src/update/update-bounded-json.mjs +113 -0
- package/src/update/update-bytes.d.mts +2 -0
- package/src/update/update-bytes.mjs +23 -0
- package/src/update/update-candidate-id.d.mts +2 -0
- package/src/update/update-candidate-id.mjs +23 -0
- package/src/update/update-checkpoint-codec.d.mts +33 -0
- package/src/update/update-checkpoint-codec.mjs +217 -0
- package/src/update/update-contracts.d.mts +24 -0
- package/src/update/update-contracts.mjs +207 -0
- package/src/update/update-signature-threshold.d.mts +12 -0
- package/src/update/update-signature-threshold.mjs +47 -0
- package/src/update/update-signed-version.d.mts +5 -0
- package/src/update/update-signed-version.mjs +25 -0
- package/src/update/update-trust-anchor.d.mts +2 -0
- package/src/update/update-trust-anchor.mjs +2 -0
- package/src/usage/cache-diagnostic.ts +195 -50
- package/src/usage/expected-prices.ts +20 -2
- package/src/usage/filter-index.ts +1469 -0
- package/src/usage/ledger-scanner.ts +245 -4
- package/src/usage/source-filter.ts +10 -2
- package/src/usage/summary.ts +16 -0
- package/src/web-search/parse.ts +244 -38
- package/gui/dist/assets/App-CWz0areF.js +0 -59
- package/gui/dist/assets/Tray-BosDoskm.js +0 -1
- package/gui/dist/assets/index-CAxjGWkm.js +0 -94
- package/gui/dist/assets/index-bnUWypyz.css +0 -2
- package/gui/dist/classic/assets/App-BOEsFmiN.js +0 -58
- package/gui/dist/classic/assets/index-ClZ_zZ77.js +0 -94
- package/gui/dist/classic/assets/quota-summary-xwvDtvu7.js +0 -1
|
@@ -0,0 +1,977 @@
|
|
|
1
|
+
use std::collections::{HashMap, HashSet};
|
|
2
|
+
use std::fs;
|
|
3
|
+
use std::path::Path;
|
|
4
|
+
|
|
5
|
+
use base64::Engine;
|
|
6
|
+
use base64::engine::general_purpose::STANDARD as BASE64;
|
|
7
|
+
use serde::{Deserialize, Serialize};
|
|
8
|
+
|
|
9
|
+
use crate::codex_home::{CodexHomeGuard, RestoreStepError};
|
|
10
|
+
use crate::codex_settings::HomeCodexSettings;
|
|
11
|
+
use crate::platform::{
|
|
12
|
+
DirectoryIdentity, directory_identity, ensure_private_dir, reject_symlink, sha256_hex,
|
|
13
|
+
write_private_atomic, write_regular_atomic,
|
|
14
|
+
};
|
|
15
|
+
use crate::state::ChildPaths;
|
|
16
|
+
use crate::toml_surgeon::{
|
|
17
|
+
ChildInjectedLedger, apply_design_b_config, detect_unowned_root_routing_conflict,
|
|
18
|
+
surgical_detach_config,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
pub const CHILD_JOURNAL_SCHEMA: &str = "ocx.child.journal/1";
|
|
22
|
+
|
|
23
|
+
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
|
24
|
+
#[serde(rename_all = "camelCase", deny_unknown_fields)]
|
|
25
|
+
pub struct ChildJournalV1 {
|
|
26
|
+
pub schema: String,
|
|
27
|
+
pub link_id: String,
|
|
28
|
+
pub api_key_id: String,
|
|
29
|
+
pub opencodex_home: String,
|
|
30
|
+
pub codex_home: String,
|
|
31
|
+
#[serde(default)]
|
|
32
|
+
pub opencodex_home_identity: Option<DirectoryIdentity>,
|
|
33
|
+
#[serde(default)]
|
|
34
|
+
pub codex_home_identity: Option<DirectoryIdentity>,
|
|
35
|
+
pub catalog_path: String,
|
|
36
|
+
pub pre_attach_config_existed: bool,
|
|
37
|
+
pub pre_attach_config_bytes_b64: Option<String>,
|
|
38
|
+
pub pre_attach_config_sha256: Option<String>,
|
|
39
|
+
pub first_injected_config_sha256: String,
|
|
40
|
+
pub latest_injected_config_sha256: String,
|
|
41
|
+
#[serde(default)]
|
|
42
|
+
pub previous_injected_config_sha256: Option<String>,
|
|
43
|
+
pub untouched_by_external_writer: bool,
|
|
44
|
+
pub pre_attach_catalog_existed: bool,
|
|
45
|
+
pub pre_attach_catalog_bytes_b64: Option<String>,
|
|
46
|
+
pub latest_catalog_sha256: String,
|
|
47
|
+
#[serde(default)]
|
|
48
|
+
pub previous_catalog_sha256: Option<String>,
|
|
49
|
+
pub pre_attach_models_cache_existed: bool,
|
|
50
|
+
pub pre_attach_models_cache_bytes_b64: Option<String>,
|
|
51
|
+
pub latest_models_cache_sha256: Option<String>,
|
|
52
|
+
#[serde(default)]
|
|
53
|
+
pub previous_models_cache_sha256: Option<String>,
|
|
54
|
+
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
|
|
55
|
+
pub retained_external_cache_entries: bool,
|
|
56
|
+
pub ledger: ChildInjectedLedger,
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/// Deterministic fault-injection points for write-ahead crash-recovery tests.
|
|
60
|
+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
61
|
+
pub enum JournalWriteFault {
|
|
62
|
+
AfterJournalWrite,
|
|
63
|
+
AfterCatalogWrite,
|
|
64
|
+
AfterCacheWrite,
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
68
|
+
pub enum DetachOutcome {
|
|
69
|
+
ExactRestore,
|
|
70
|
+
SurgicalRestore,
|
|
71
|
+
NotAttached,
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
75
|
+
pub enum DetachError {
|
|
76
|
+
Conflict(String),
|
|
77
|
+
Io(String),
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
pub fn read_journal(path: &Path) -> Result<Option<ChildJournalV1>, String> {
|
|
81
|
+
reject_symlink(path)?;
|
|
82
|
+
let bytes = match fs::read(path) {
|
|
83
|
+
Ok(b) => b,
|
|
84
|
+
Err(e) if e.kind() == std::io::ErrorKind::NotFound => return Ok(None),
|
|
85
|
+
Err(e) => return Err(format!("failed reading journal {}: {e}", path.display())),
|
|
86
|
+
};
|
|
87
|
+
let parsed: ChildJournalV1 =
|
|
88
|
+
serde_json::from_slice(&bytes).map_err(|e| format!("corrupt child journal: {e}"))?;
|
|
89
|
+
if parsed.schema != CHILD_JOURNAL_SCHEMA {
|
|
90
|
+
return Err(format!("unsupported journal schema: {}", parsed.schema));
|
|
91
|
+
}
|
|
92
|
+
Ok(Some(parsed))
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
pub fn write_journal(path: &Path, journal: &ChildJournalV1) -> Result<(), String> {
|
|
96
|
+
let mut bytes = serde_json::to_vec_pretty(journal)
|
|
97
|
+
.map_err(|e| format!("failed serializing journal: {e}"))?;
|
|
98
|
+
bytes.push(b'\n');
|
|
99
|
+
write_private_atomic(path, &bytes)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
fn validate_journal_paths(paths: &ChildPaths, journal: &ChildJournalV1) -> Result<(), String> {
|
|
103
|
+
let current_ocx = fs::canonicalize(&paths.opencodex_home)
|
|
104
|
+
.map_err(|e| format!("cannot resolve current OpenCodex home: {e}"))?;
|
|
105
|
+
let current_codex = fs::canonicalize(&paths.codex_home)
|
|
106
|
+
.map_err(|e| format!("cannot resolve current Codex home: {e}"))?;
|
|
107
|
+
let catalog = Path::new(&journal.catalog_path);
|
|
108
|
+
let expected_ocx_identity = journal
|
|
109
|
+
.opencodex_home_identity
|
|
110
|
+
.as_ref()
|
|
111
|
+
.ok_or("child journal lacks OpenCodex directory identity")?;
|
|
112
|
+
let expected_codex_identity = journal
|
|
113
|
+
.codex_home_identity
|
|
114
|
+
.as_ref()
|
|
115
|
+
.ok_or("child journal lacks Codex directory identity")?;
|
|
116
|
+
if current_ocx != Path::new(&journal.opencodex_home)
|
|
117
|
+
|| current_codex != Path::new(&journal.codex_home)
|
|
118
|
+
|| catalog != current_codex.join("opencodex-catalog.json")
|
|
119
|
+
|| &directory_identity(¤t_ocx)? != expected_ocx_identity
|
|
120
|
+
|| &directory_identity(¤t_codex)? != expected_codex_identity
|
|
121
|
+
{
|
|
122
|
+
return Err("child journal belongs to a different home or catalog path".to_owned());
|
|
123
|
+
}
|
|
124
|
+
Ok(())
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/// Verify an existing journal before any lifecycle operation changes state or stops a daemon.
|
|
128
|
+
pub fn validate_existing_journal_paths(paths: &ChildPaths) -> Result<bool, String> {
|
|
129
|
+
match read_journal(&paths.journal_file)? {
|
|
130
|
+
Some(journal) => {
|
|
131
|
+
validate_journal_paths(paths, &journal)?;
|
|
132
|
+
Ok(true)
|
|
133
|
+
}
|
|
134
|
+
None => Ok(false),
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/// Fail-closed check ensuring full `ocx` does not own `$OPENCODEX_HOME` or `$CODEX_HOME`.
|
|
139
|
+
pub fn assert_no_full_ocx_conflict(paths: &ChildPaths) -> Result<(), String> {
|
|
140
|
+
for name in [
|
|
141
|
+
"runtime-port.json",
|
|
142
|
+
"ocx.pid",
|
|
143
|
+
"service-api-token",
|
|
144
|
+
"client-connect-pending",
|
|
145
|
+
] {
|
|
146
|
+
let candidate = paths.opencodex_home.join(name);
|
|
147
|
+
if candidate.exists() {
|
|
148
|
+
return Err(format!(
|
|
149
|
+
"attach refused: full OpenCodex runtime state exists at {}",
|
|
150
|
+
candidate.display()
|
|
151
|
+
));
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
let cfg_json = paths.opencodex_home.join("config.json");
|
|
155
|
+
if let Ok(raw) = fs::read(&cfg_json) {
|
|
156
|
+
let non_empty = serde_json::from_slice::<serde_json::Value>(&raw)
|
|
157
|
+
.ok()
|
|
158
|
+
.and_then(|v| v.as_object().cloned())
|
|
159
|
+
.is_some_and(|obj| !obj.is_empty());
|
|
160
|
+
if non_empty {
|
|
161
|
+
return Err(format!(
|
|
162
|
+
"attach refused: full OpenCodex config.json exists at {}",
|
|
163
|
+
cfg_json.display()
|
|
164
|
+
));
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
for jname in ["opencodex-journal.json", ".opencodex-journal.json"] {
|
|
168
|
+
let jpath = paths.codex_home.join(jname);
|
|
169
|
+
if jpath.exists() {
|
|
170
|
+
return Err(format!(
|
|
171
|
+
"attach refused: full OpenCodex Codex journal exists at {}",
|
|
172
|
+
jpath.display()
|
|
173
|
+
));
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
Ok(())
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
pub fn validate_catalog_json(bytes: &[u8]) -> Result<Vec<serde_json::Value>, String> {
|
|
180
|
+
if bytes.len() > 4 * 1024 * 1024 {
|
|
181
|
+
return Err("downloaded catalog exceeds 4 MiB safety bound".to_owned());
|
|
182
|
+
}
|
|
183
|
+
let val: serde_json::Value =
|
|
184
|
+
serde_json::from_slice(bytes).map_err(|e| format!("invalid catalog JSON: {e}"))?;
|
|
185
|
+
let models = val
|
|
186
|
+
.get("models")
|
|
187
|
+
.and_then(serde_json::Value::as_array)
|
|
188
|
+
.ok_or_else(|| "catalog JSON missing models array".to_owned())?;
|
|
189
|
+
if models.len() > 2000 {
|
|
190
|
+
return Err("catalog models array exceeds 2000 entries".to_owned());
|
|
191
|
+
}
|
|
192
|
+
let mut seen = HashSet::with_capacity(models.len());
|
|
193
|
+
for item in models {
|
|
194
|
+
let slug = item
|
|
195
|
+
.get("slug")
|
|
196
|
+
.and_then(serde_json::Value::as_str)
|
|
197
|
+
.filter(|s| !s.trim().is_empty() && s.bytes().all(|b| (0x21..=0x7e).contains(&b)))
|
|
198
|
+
.ok_or_else(|| "catalog contains missing or invalid model slug".to_owned())?;
|
|
199
|
+
if !seen.insert(slug.to_owned()) {
|
|
200
|
+
return Err(format!("catalog contains duplicate slug: {slug}"));
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
Ok(models.clone())
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/// Prepares updated `$CODEX_HOME/models_cache.json` bytes (if changed) and SHA-256 without writing yet.
|
|
207
|
+
pub fn prepare_codex_models_cache(
|
|
208
|
+
cache_path: &Path,
|
|
209
|
+
catalog_models: &[serde_json::Value],
|
|
210
|
+
) -> Result<(Option<Vec<u8>>, String), String> {
|
|
211
|
+
reject_symlink(cache_path)?;
|
|
212
|
+
let existing_bytes = match fs::read(cache_path) {
|
|
213
|
+
Ok(b) => Some(b),
|
|
214
|
+
Err(e) if e.kind() == std::io::ErrorKind::NotFound => None,
|
|
215
|
+
Err(e) => return Err(format!("failed reading models_cache.json: {e}")),
|
|
216
|
+
};
|
|
217
|
+
render_codex_models_cache(existing_bytes.as_deref(), catalog_models, false)
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
fn render_codex_models_cache(
|
|
221
|
+
existing_bytes: Option<&[u8]>,
|
|
222
|
+
catalog_models: &[serde_json::Value],
|
|
223
|
+
retain_unmarked: bool,
|
|
224
|
+
) -> Result<(Option<Vec<u8>>, String), String> {
|
|
225
|
+
let catalog_slugs: HashSet<&str> = catalog_models
|
|
226
|
+
.iter()
|
|
227
|
+
.filter_map(|m| m.get("slug").and_then(serde_json::Value::as_str))
|
|
228
|
+
.collect();
|
|
229
|
+
let mut observed_native = Vec::new();
|
|
230
|
+
if let Some(raw) = existing_bytes
|
|
231
|
+
&& let Ok(val) = serde_json::from_slice::<serde_json::Value>(raw)
|
|
232
|
+
&& let Some(arr) = val.get("models").and_then(serde_json::Value::as_array)
|
|
233
|
+
{
|
|
234
|
+
for entry in arr {
|
|
235
|
+
let is_obs = entry
|
|
236
|
+
.get("opencodex_account_observed_native")
|
|
237
|
+
.and_then(serde_json::Value::as_bool)
|
|
238
|
+
== Some(true);
|
|
239
|
+
let slug = entry
|
|
240
|
+
.get("slug")
|
|
241
|
+
.and_then(serde_json::Value::as_str)
|
|
242
|
+
.unwrap_or("");
|
|
243
|
+
if retain_unmarked && slug.is_empty() {
|
|
244
|
+
return Err(
|
|
245
|
+
"client_models_cache_conflict: local model is missing a slug".to_owned(),
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
if (is_obs || retain_unmarked) && !slug.is_empty() && !catalog_slugs.contains(slug) {
|
|
249
|
+
observed_native.push(entry.clone());
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
let mut combined = Vec::with_capacity(catalog_models.len() + observed_native.len());
|
|
254
|
+
combined.extend_from_slice(catalog_models);
|
|
255
|
+
combined.extend(observed_native);
|
|
256
|
+
let wrapper = serde_json::json!({
|
|
257
|
+
"fetched_at": "2000-01-01T00:00:00Z",
|
|
258
|
+
"client_version": "0.0.0",
|
|
259
|
+
"models": combined,
|
|
260
|
+
});
|
|
261
|
+
let mut rendered = serde_json::to_vec_pretty(&wrapper)
|
|
262
|
+
.map_err(|e| format!("failed serializing models_cache.json: {e}"))?;
|
|
263
|
+
rendered.push(b'\n');
|
|
264
|
+
let digest = sha256_hex(&rendered);
|
|
265
|
+
let to_write = (existing_bytes != Some(rendered.as_slice())).then_some(rendered);
|
|
266
|
+
Ok((to_write, digest))
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
pub fn refresh_codex_models_cache(
|
|
270
|
+
cache_path: &Path,
|
|
271
|
+
catalog_models: &[serde_json::Value],
|
|
272
|
+
) -> Result<String, String> {
|
|
273
|
+
let (to_write, digest) = prepare_codex_models_cache(cache_path, catalog_models)?;
|
|
274
|
+
if let Some(rendered) = to_write {
|
|
275
|
+
write_regular_atomic(cache_path, &rendered)?;
|
|
276
|
+
}
|
|
277
|
+
Ok(digest)
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
pub fn apply_attach_or_sync(
|
|
281
|
+
guard: &CodexHomeGuard,
|
|
282
|
+
link_id: &str,
|
|
283
|
+
api_key_id: &str,
|
|
284
|
+
listen_port: u16,
|
|
285
|
+
catalog_bytes: &[u8],
|
|
286
|
+
settings: &HomeCodexSettings,
|
|
287
|
+
) -> Result<ChildJournalV1, String> {
|
|
288
|
+
apply_attach_or_sync_with_fault(
|
|
289
|
+
guard,
|
|
290
|
+
link_id,
|
|
291
|
+
api_key_id,
|
|
292
|
+
listen_port,
|
|
293
|
+
catalog_bytes,
|
|
294
|
+
settings,
|
|
295
|
+
None,
|
|
296
|
+
)
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
pub fn apply_attach_or_sync_with_fault(
|
|
300
|
+
guard: &CodexHomeGuard,
|
|
301
|
+
link_id: &str,
|
|
302
|
+
api_key_id: &str,
|
|
303
|
+
listen_port: u16,
|
|
304
|
+
catalog_bytes: &[u8],
|
|
305
|
+
settings: &HomeCodexSettings,
|
|
306
|
+
fault: Option<JournalWriteFault>,
|
|
307
|
+
) -> Result<ChildJournalV1, String> {
|
|
308
|
+
if !guard.is_owner() {
|
|
309
|
+
return Err("attach refused: this OpenCodex home does not own the Codex home".to_owned());
|
|
310
|
+
}
|
|
311
|
+
let paths = guard.paths();
|
|
312
|
+
assert_no_full_ocx_conflict(paths)?;
|
|
313
|
+
let catalog_models = validate_catalog_json(catalog_bytes)?;
|
|
314
|
+
let config_path = paths.codex_config_path();
|
|
315
|
+
let catalog_path = paths.codex_catalog_path();
|
|
316
|
+
let cache_path = paths.codex_models_cache_path();
|
|
317
|
+
reject_symlink(&config_path)?;
|
|
318
|
+
reject_symlink(&catalog_path)?;
|
|
319
|
+
reject_symlink(&cache_path)?;
|
|
320
|
+
|
|
321
|
+
let existing_journal = read_journal(&paths.journal_file)?;
|
|
322
|
+
if let Some(journal) = &existing_journal {
|
|
323
|
+
validate_journal_paths(paths, journal)?;
|
|
324
|
+
}
|
|
325
|
+
let current_cfg_bytes = match fs::read(&config_path) {
|
|
326
|
+
Ok(b) => Some(b),
|
|
327
|
+
Err(e) if e.kind() == std::io::ErrorKind::NotFound => None,
|
|
328
|
+
Err(e) => return Err(format!("failed reading {}: {e}", config_path.display())),
|
|
329
|
+
};
|
|
330
|
+
let current_cfg_text = match ¤t_cfg_bytes {
|
|
331
|
+
Some(b) => std::str::from_utf8(b)
|
|
332
|
+
.map_err(|_| "config.toml is not valid UTF-8".to_owned())?
|
|
333
|
+
.to_owned(),
|
|
334
|
+
None => String::new(),
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
if existing_journal.is_none() && !current_cfg_text.is_empty() {
|
|
338
|
+
detect_unowned_root_routing_conflict(¤t_cfg_text)?;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
ensure_private_dir(&paths.child_dir)?;
|
|
342
|
+
fs::create_dir_all(&paths.codex_home)
|
|
343
|
+
.map_err(|e| format!("failed to create Codex home: {e}"))?;
|
|
344
|
+
let canonical_ocx = fs::canonicalize(&paths.opencodex_home)
|
|
345
|
+
.map_err(|e| format!("cannot resolve OpenCodex home: {e}"))?;
|
|
346
|
+
let canonical_codex = fs::canonicalize(&paths.codex_home)
|
|
347
|
+
.map_err(|e| format!("cannot resolve Codex home: {e}"))?;
|
|
348
|
+
let catalog_path_str = canonical_codex
|
|
349
|
+
.join("opencodex-catalog.json")
|
|
350
|
+
.to_str()
|
|
351
|
+
.ok_or("canonical catalog path is not UTF-8")?
|
|
352
|
+
.to_owned();
|
|
353
|
+
let (next_cfg_text, next_ledger) = apply_design_b_config(
|
|
354
|
+
¤t_cfg_text,
|
|
355
|
+
listen_port,
|
|
356
|
+
&catalog_path_str,
|
|
357
|
+
settings,
|
|
358
|
+
existing_journal.as_ref().map(|j| &j.ledger),
|
|
359
|
+
)?;
|
|
360
|
+
let next_cfg_sha = sha256_hex(next_cfg_text.as_bytes());
|
|
361
|
+
let next_cat_sha = sha256_hex(catalog_bytes);
|
|
362
|
+
|
|
363
|
+
let (pre_cfg_existed, pre_cfg_b64, pre_cfg_sha, first_inj_sha, prev_inj_sha, untouched) =
|
|
364
|
+
if let Some(prev) = &existing_journal {
|
|
365
|
+
let cur_sha = current_cfg_bytes.as_ref().map(|b| sha256_hex(b));
|
|
366
|
+
let cur_matches_owned = cur_sha.as_deref()
|
|
367
|
+
== Some(prev.latest_injected_config_sha256.as_str())
|
|
368
|
+
|| (cur_sha.is_some() && cur_sha == prev.previous_injected_config_sha256);
|
|
369
|
+
let still_untouched = prev.untouched_by_external_writer
|
|
370
|
+
&& (cur_matches_owned || cur_sha == prev.pre_attach_config_sha256);
|
|
371
|
+
let carried_prev_cfg = if cur_matches_owned {
|
|
372
|
+
cur_sha
|
|
373
|
+
} else {
|
|
374
|
+
prev.previous_injected_config_sha256
|
|
375
|
+
.clone()
|
|
376
|
+
.or_else(|| Some(prev.latest_injected_config_sha256.clone()))
|
|
377
|
+
};
|
|
378
|
+
(
|
|
379
|
+
prev.pre_attach_config_existed,
|
|
380
|
+
prev.pre_attach_config_bytes_b64.clone(),
|
|
381
|
+
prev.pre_attach_config_sha256.clone(),
|
|
382
|
+
prev.first_injected_config_sha256.clone(),
|
|
383
|
+
carried_prev_cfg,
|
|
384
|
+
still_untouched,
|
|
385
|
+
)
|
|
386
|
+
} else {
|
|
387
|
+
let b64 = current_cfg_bytes.as_ref().map(|b| BASE64.encode(b));
|
|
388
|
+
let sha = current_cfg_bytes.as_ref().map(|b| sha256_hex(b));
|
|
389
|
+
(
|
|
390
|
+
current_cfg_bytes.is_some(),
|
|
391
|
+
b64,
|
|
392
|
+
sha,
|
|
393
|
+
next_cfg_sha.clone(),
|
|
394
|
+
None,
|
|
395
|
+
true,
|
|
396
|
+
)
|
|
397
|
+
};
|
|
398
|
+
|
|
399
|
+
let (pre_cat_existed, pre_cat_b64, prev_cat_sha) = if let Some(prev) = &existing_journal {
|
|
400
|
+
let mut carried_prev_cat = prev
|
|
401
|
+
.previous_catalog_sha256
|
|
402
|
+
.clone()
|
|
403
|
+
.or_else(|| Some(prev.latest_catalog_sha256.clone()));
|
|
404
|
+
if catalog_path.exists() {
|
|
405
|
+
let existing_cat = fs::read(&catalog_path)
|
|
406
|
+
.map_err(|e| format!("failed reading {}: {e}", catalog_path.display()))?;
|
|
407
|
+
let existing_cat_sha = sha256_hex(&existing_cat);
|
|
408
|
+
let matches_owned_injected = existing_cat_sha == prev.latest_catalog_sha256
|
|
409
|
+
|| Some(existing_cat_sha.as_str()) == prev.previous_catalog_sha256.as_deref();
|
|
410
|
+
let matches_pre_attach = prev
|
|
411
|
+
.pre_attach_catalog_bytes_b64
|
|
412
|
+
.as_ref()
|
|
413
|
+
.and_then(|b64| BASE64.decode(b64).ok())
|
|
414
|
+
.is_some_and(|p| p == existing_cat);
|
|
415
|
+
if !matches_owned_injected && !matches_pre_attach {
|
|
416
|
+
return Err(
|
|
417
|
+
"client_catalog_ownership_changed: opencodex-catalog.json was modified externally"
|
|
418
|
+
.to_owned(),
|
|
419
|
+
);
|
|
420
|
+
}
|
|
421
|
+
if matches_owned_injected {
|
|
422
|
+
carried_prev_cat = Some(existing_cat_sha);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
(
|
|
426
|
+
prev.pre_attach_catalog_existed,
|
|
427
|
+
prev.pre_attach_catalog_bytes_b64.clone(),
|
|
428
|
+
carried_prev_cat,
|
|
429
|
+
)
|
|
430
|
+
} else {
|
|
431
|
+
match fs::read(&catalog_path) {
|
|
432
|
+
Ok(b) => (true, Some(BASE64.encode(&b)), None),
|
|
433
|
+
Err(e) if e.kind() == std::io::ErrorKind::NotFound => (false, None, None),
|
|
434
|
+
Err(e) => return Err(format!("failed reading {}: {e}", catalog_path.display())),
|
|
435
|
+
}
|
|
436
|
+
};
|
|
437
|
+
|
|
438
|
+
let (mut pre_cache_existed, mut pre_cache_b64, prev_cache_sha) =
|
|
439
|
+
if let Some(prev) = &existing_journal {
|
|
440
|
+
let carried_prev_cache = match fs::read(&cache_path) {
|
|
441
|
+
Ok(existing_cache) => {
|
|
442
|
+
let existing_cache_sha = sha256_hex(&existing_cache);
|
|
443
|
+
let matches_owned = Some(existing_cache_sha.as_str())
|
|
444
|
+
== prev.latest_models_cache_sha256.as_deref()
|
|
445
|
+
|| Some(existing_cache_sha.as_str())
|
|
446
|
+
== prev.previous_models_cache_sha256.as_deref();
|
|
447
|
+
if matches_owned {
|
|
448
|
+
Some(existing_cache_sha)
|
|
449
|
+
} else {
|
|
450
|
+
prev.previous_models_cache_sha256
|
|
451
|
+
.clone()
|
|
452
|
+
.or_else(|| prev.latest_models_cache_sha256.clone())
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
Err(e) if e.kind() == std::io::ErrorKind::NotFound => prev
|
|
456
|
+
.previous_models_cache_sha256
|
|
457
|
+
.clone()
|
|
458
|
+
.or_else(|| prev.latest_models_cache_sha256.clone()),
|
|
459
|
+
Err(e) => return Err(format!("failed reading {}: {e}", cache_path.display())),
|
|
460
|
+
};
|
|
461
|
+
(
|
|
462
|
+
prev.pre_attach_models_cache_existed,
|
|
463
|
+
prev.pre_attach_models_cache_bytes_b64.clone(),
|
|
464
|
+
carried_prev_cache,
|
|
465
|
+
)
|
|
466
|
+
} else {
|
|
467
|
+
match fs::read(&cache_path) {
|
|
468
|
+
Ok(b) => (true, Some(BASE64.encode(&b)), None),
|
|
469
|
+
Err(e) if e.kind() == std::io::ErrorKind::NotFound => (false, None, None),
|
|
470
|
+
Err(e) => return Err(format!("failed reading {}: {e}", cache_path.display())),
|
|
471
|
+
}
|
|
472
|
+
};
|
|
473
|
+
|
|
474
|
+
let mut retained_external_cache_entries = existing_journal
|
|
475
|
+
.as_ref()
|
|
476
|
+
.is_some_and(|j| j.retained_external_cache_entries);
|
|
477
|
+
let (prepared_cache, latest_cache_sha) = if let Some(prev) = &existing_journal {
|
|
478
|
+
let current = match fs::read(&cache_path) {
|
|
479
|
+
Ok(bytes) => Some(bytes),
|
|
480
|
+
Err(e) if e.kind() == std::io::ErrorKind::NotFound => None,
|
|
481
|
+
Err(e) => return Err(format!("failed reading models_cache.json: {e}")),
|
|
482
|
+
};
|
|
483
|
+
let externally_modified = current.as_ref().is_some_and(|bytes| {
|
|
484
|
+
let hash = sha256_hex(bytes);
|
|
485
|
+
Some(hash.as_str()) != prev.latest_models_cache_sha256.as_deref()
|
|
486
|
+
&& Some(hash.as_str()) != prev.previous_models_cache_sha256.as_deref()
|
|
487
|
+
});
|
|
488
|
+
if current.is_some() && (externally_modified || retained_external_cache_entries) {
|
|
489
|
+
let original = match (
|
|
490
|
+
&prev.pre_attach_models_cache_bytes_b64,
|
|
491
|
+
prev.pre_attach_models_cache_existed,
|
|
492
|
+
) {
|
|
493
|
+
(Some(encoded), true) => Some(
|
|
494
|
+
BASE64
|
|
495
|
+
.decode(encoded)
|
|
496
|
+
.map_err(|e| format!("bad models_cache snapshot: {e}"))?,
|
|
497
|
+
),
|
|
498
|
+
(None, false) => None,
|
|
499
|
+
_ => return Err("missing pre-attach models_cache snapshot".to_owned()),
|
|
500
|
+
};
|
|
501
|
+
let current = current
|
|
502
|
+
.as_deref()
|
|
503
|
+
.ok_or("models_cache disappeared during sync")?;
|
|
504
|
+
// `reconciled` is the detach snapshot: injected slugs carry their pre-attach
|
|
505
|
+
// versions there. The live cache below lets the new catalog win every shared slug,
|
|
506
|
+
// exactly as first attach does, and keeps only entries whose slug it does not carry.
|
|
507
|
+
let reconciled = reconcile_modified_models_cache(
|
|
508
|
+
current,
|
|
509
|
+
original.as_deref(),
|
|
510
|
+
&paths.catalog_backup_file,
|
|
511
|
+
)?;
|
|
512
|
+
let (rendered, hash) =
|
|
513
|
+
render_codex_models_cache(Some(&reconciled), &catalog_models, true)?;
|
|
514
|
+
pre_cache_existed = true;
|
|
515
|
+
pre_cache_b64 = Some(BASE64.encode(&reconciled));
|
|
516
|
+
retained_external_cache_entries = true;
|
|
517
|
+
(rendered.or(Some(reconciled)), hash)
|
|
518
|
+
} else {
|
|
519
|
+
prepare_codex_models_cache(&cache_path, &catalog_models)?
|
|
520
|
+
}
|
|
521
|
+
} else {
|
|
522
|
+
prepare_codex_models_cache(&cache_path, &catalog_models)?
|
|
523
|
+
};
|
|
524
|
+
// Until the cache write lands, the cache may still hold the previous catalog's entries, so
|
|
525
|
+
// the backup that tells reconciliation which slugs the Child injected names both catalogs.
|
|
526
|
+
let interim_backup = match &existing_journal {
|
|
527
|
+
Some(_) => interim_catalog_backup(&paths.catalog_backup_file, &catalog_models)?,
|
|
528
|
+
None => None,
|
|
529
|
+
};
|
|
530
|
+
|
|
531
|
+
let journal = ChildJournalV1 {
|
|
532
|
+
schema: CHILD_JOURNAL_SCHEMA.to_owned(),
|
|
533
|
+
link_id: link_id.to_owned(),
|
|
534
|
+
api_key_id: api_key_id.to_owned(),
|
|
535
|
+
opencodex_home: canonical_ocx
|
|
536
|
+
.to_str()
|
|
537
|
+
.ok_or("canonical OpenCodex home is not UTF-8")?
|
|
538
|
+
.to_owned(),
|
|
539
|
+
codex_home: canonical_codex
|
|
540
|
+
.to_str()
|
|
541
|
+
.ok_or("canonical Codex home is not UTF-8")?
|
|
542
|
+
.to_owned(),
|
|
543
|
+
opencodex_home_identity: Some(directory_identity(&canonical_ocx)?),
|
|
544
|
+
codex_home_identity: Some(directory_identity(&canonical_codex)?),
|
|
545
|
+
catalog_path: catalog_path_str,
|
|
546
|
+
pre_attach_config_existed: pre_cfg_existed,
|
|
547
|
+
pre_attach_config_bytes_b64: pre_cfg_b64,
|
|
548
|
+
pre_attach_config_sha256: pre_cfg_sha,
|
|
549
|
+
first_injected_config_sha256: first_inj_sha,
|
|
550
|
+
latest_injected_config_sha256: next_cfg_sha,
|
|
551
|
+
previous_injected_config_sha256: prev_inj_sha,
|
|
552
|
+
untouched_by_external_writer: untouched,
|
|
553
|
+
pre_attach_catalog_existed: pre_cat_existed,
|
|
554
|
+
pre_attach_catalog_bytes_b64: pre_cat_b64,
|
|
555
|
+
latest_catalog_sha256: next_cat_sha,
|
|
556
|
+
previous_catalog_sha256: prev_cat_sha,
|
|
557
|
+
pre_attach_models_cache_existed: pre_cache_existed,
|
|
558
|
+
pre_attach_models_cache_bytes_b64: pre_cache_b64,
|
|
559
|
+
latest_models_cache_sha256: Some(latest_cache_sha),
|
|
560
|
+
previous_models_cache_sha256: prev_cache_sha,
|
|
561
|
+
retained_external_cache_entries,
|
|
562
|
+
ledger: next_ledger,
|
|
563
|
+
};
|
|
564
|
+
// Persist recovery journal BEFORE mutating any file in $CODEX_HOME (write-ahead durability).
|
|
565
|
+
write_journal(&paths.journal_file, &journal)?;
|
|
566
|
+
if fault == Some(JournalWriteFault::AfterJournalWrite) {
|
|
567
|
+
return Err("injected fault: AfterJournalWrite".to_owned());
|
|
568
|
+
}
|
|
569
|
+
write_regular_atomic(&catalog_path, catalog_bytes)?;
|
|
570
|
+
write_private_atomic(
|
|
571
|
+
&paths.catalog_backup_file,
|
|
572
|
+
interim_backup.as_deref().unwrap_or(catalog_bytes),
|
|
573
|
+
)?;
|
|
574
|
+
if fault == Some(JournalWriteFault::AfterCatalogWrite) {
|
|
575
|
+
return Err("injected fault: AfterCatalogWrite".to_owned());
|
|
576
|
+
}
|
|
577
|
+
if let Some(cache_bytes) = prepared_cache {
|
|
578
|
+
write_regular_atomic(&cache_path, &cache_bytes)?;
|
|
579
|
+
}
|
|
580
|
+
if interim_backup.is_some() {
|
|
581
|
+
write_private_atomic(&paths.catalog_backup_file, catalog_bytes)?;
|
|
582
|
+
}
|
|
583
|
+
if fault == Some(JournalWriteFault::AfterCacheWrite) {
|
|
584
|
+
return Err("injected fault: AfterCacheWrite".to_owned());
|
|
585
|
+
}
|
|
586
|
+
write_regular_atomic(&config_path, next_cfg_text.as_bytes())?;
|
|
587
|
+
Ok(journal)
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
/// Catalog backup naming the slugs of both the new catalog and the last one the Child injected,
|
|
591
|
+
/// or `None` when there is no previous backup to merge.
|
|
592
|
+
fn interim_catalog_backup(
|
|
593
|
+
backup_path: &Path,
|
|
594
|
+
catalog_models: &[serde_json::Value],
|
|
595
|
+
) -> Result<Option<Vec<u8>>, String> {
|
|
596
|
+
reject_symlink(backup_path)?;
|
|
597
|
+
let previous = match fs::read(backup_path) {
|
|
598
|
+
Ok(bytes) => bytes,
|
|
599
|
+
Err(e) if e.kind() == std::io::ErrorKind::NotFound => return Ok(None),
|
|
600
|
+
Err(e) => return Err(format!("failed reading catalog backup: {e}")),
|
|
601
|
+
};
|
|
602
|
+
let previous: serde_json::Value = serde_json::from_slice(&previous).map_err(|e| {
|
|
603
|
+
format!("client_models_cache_reconcile_failed: invalid catalog backup JSON: {e}")
|
|
604
|
+
})?;
|
|
605
|
+
let previous_models = previous
|
|
606
|
+
.get("models")
|
|
607
|
+
.and_then(serde_json::Value::as_array)
|
|
608
|
+
.ok_or("client_models_cache_reconcile_failed: catalog backup missing models array")?;
|
|
609
|
+
let new_slugs: HashSet<&str> = catalog_models
|
|
610
|
+
.iter()
|
|
611
|
+
.filter_map(|m| m.get("slug").and_then(serde_json::Value::as_str))
|
|
612
|
+
.collect();
|
|
613
|
+
let mut merged = catalog_models.to_vec();
|
|
614
|
+
merged.extend(
|
|
615
|
+
previous_models
|
|
616
|
+
.iter()
|
|
617
|
+
.filter(|m| {
|
|
618
|
+
m.get("slug")
|
|
619
|
+
.and_then(serde_json::Value::as_str)
|
|
620
|
+
.is_some_and(|slug| !new_slugs.contains(slug))
|
|
621
|
+
})
|
|
622
|
+
.cloned(),
|
|
623
|
+
);
|
|
624
|
+
serde_json::to_vec(&serde_json::json!({ "models": merged }))
|
|
625
|
+
.map(Some)
|
|
626
|
+
.map_err(|e| format!("failed serializing catalog backup: {e}"))
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
/// Performs 100% offline two-tier restoration of `config.toml`, `opencodex-catalog.json`, and `models_cache.json`.
|
|
630
|
+
pub fn offline_detach(
|
|
631
|
+
guard: &CodexHomeGuard,
|
|
632
|
+
keep_catalog: bool,
|
|
633
|
+
) -> Result<DetachOutcome, DetachError> {
|
|
634
|
+
offline_detach_inner(guard, keep_catalog, false)
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
/// Restore client files while retaining recovery records until lifecycle cleanup succeeds.
|
|
638
|
+
pub fn offline_detach_deferred(
|
|
639
|
+
guard: &CodexHomeGuard,
|
|
640
|
+
keep_catalog: bool,
|
|
641
|
+
) -> Result<DetachOutcome, DetachError> {
|
|
642
|
+
offline_detach_inner(guard, keep_catalog, true)
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
pub fn remove_optional_file(path: &Path) -> Result<(), String> {
|
|
646
|
+
match fs::remove_file(path) {
|
|
647
|
+
Ok(()) => {
|
|
648
|
+
#[cfg(unix)]
|
|
649
|
+
{
|
|
650
|
+
let parent = path.parent().ok_or("removed file has no parent")?;
|
|
651
|
+
crate::platform::sync_parent_directory(parent)?;
|
|
652
|
+
}
|
|
653
|
+
Ok(())
|
|
654
|
+
}
|
|
655
|
+
Err(e) if e.kind() == std::io::ErrorKind::NotFound => Ok(()),
|
|
656
|
+
Err(e) => {
|
|
657
|
+
let name = path
|
|
658
|
+
.file_name()
|
|
659
|
+
.and_then(|name| name.to_str())
|
|
660
|
+
.unwrap_or("file");
|
|
661
|
+
Err(format!("failed removing {name}: {e}"))
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
fn offline_detach_inner(
|
|
667
|
+
guard: &CodexHomeGuard,
|
|
668
|
+
keep_catalog: bool,
|
|
669
|
+
defer_cleanup: bool,
|
|
670
|
+
) -> Result<DetachOutcome, DetachError> {
|
|
671
|
+
let paths = guard.paths();
|
|
672
|
+
let Some(mut journal) = read_journal(&paths.journal_file).map_err(DetachError::Io)? else {
|
|
673
|
+
return Ok(DetachOutcome::NotAttached);
|
|
674
|
+
};
|
|
675
|
+
validate_journal_paths(paths, &journal).map_err(DetachError::Conflict)?;
|
|
676
|
+
let config_path = paths.codex_config_path();
|
|
677
|
+
let catalog_path = Path::new(&journal.catalog_path);
|
|
678
|
+
let cache_path = paths.codex_models_cache_path();
|
|
679
|
+
reject_symlink(&config_path).map_err(DetachError::Io)?;
|
|
680
|
+
reject_symlink(catalog_path).map_err(DetachError::Io)?;
|
|
681
|
+
reject_symlink(&cache_path).map_err(DetachError::Io)?;
|
|
682
|
+
|
|
683
|
+
let prior_catalog =
|
|
684
|
+
if !keep_catalog && journal.pre_attach_catalog_existed {
|
|
685
|
+
let encoded = journal
|
|
686
|
+
.pre_attach_catalog_bytes_b64
|
|
687
|
+
.as_ref()
|
|
688
|
+
.ok_or_else(|| {
|
|
689
|
+
DetachError::Conflict("missing pre-attach catalog snapshot".to_owned())
|
|
690
|
+
})?;
|
|
691
|
+
Some(BASE64.decode(encoded).map_err(|e| {
|
|
692
|
+
DetachError::Conflict(format!("bad pre-attach catalog snapshot: {e}"))
|
|
693
|
+
})?)
|
|
694
|
+
} else {
|
|
695
|
+
None
|
|
696
|
+
};
|
|
697
|
+
|
|
698
|
+
if !keep_catalog && catalog_path.exists() {
|
|
699
|
+
let cat_bytes = fs::read(catalog_path)
|
|
700
|
+
.map_err(|e| DetachError::Io(format!("failed reading catalog: {e}")))?;
|
|
701
|
+
let cur_cat_sha = sha256_hex(&cat_bytes);
|
|
702
|
+
let matches_known_injected = cur_cat_sha == journal.latest_catalog_sha256
|
|
703
|
+
|| Some(cur_cat_sha.as_str()) == journal.previous_catalog_sha256.as_deref();
|
|
704
|
+
if !matches_known_injected {
|
|
705
|
+
let matches_prior = prior_catalog
|
|
706
|
+
.as_ref()
|
|
707
|
+
.is_some_and(|prior| *prior == cat_bytes);
|
|
708
|
+
if !matches_prior {
|
|
709
|
+
return Err(DetachError::Conflict(
|
|
710
|
+
"client_catalog_ownership_changed: opencodex-catalog.json was modified externally".to_owned(),
|
|
711
|
+
));
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
enum CacheDetachPlan {
|
|
717
|
+
Noop,
|
|
718
|
+
Remove,
|
|
719
|
+
Write(Vec<u8>),
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
let cache_plan = if cache_path.exists() {
|
|
723
|
+
let cur_cache = fs::read(&cache_path)
|
|
724
|
+
.map_err(|e| DetachError::Io(format!("failed reading models_cache.json: {e}")))?;
|
|
725
|
+
let cur_cache_sha = sha256_hex(&cur_cache);
|
|
726
|
+
let cache_untouched = Some(cur_cache_sha.as_str())
|
|
727
|
+
== journal.latest_models_cache_sha256.as_deref()
|
|
728
|
+
|| Some(cur_cache_sha.as_str()) == journal.previous_models_cache_sha256.as_deref();
|
|
729
|
+
if journal.pre_attach_models_cache_existed {
|
|
730
|
+
let prior_cache = journal
|
|
731
|
+
.pre_attach_models_cache_bytes_b64
|
|
732
|
+
.as_ref()
|
|
733
|
+
.ok_or_else(|| {
|
|
734
|
+
DetachError::Conflict("missing pre-attach models_cache snapshot".to_owned())
|
|
735
|
+
})
|
|
736
|
+
.and_then(|b64| {
|
|
737
|
+
BASE64.decode(b64).map_err(|e| {
|
|
738
|
+
DetachError::Conflict(format!("bad models_cache snapshot: {e}"))
|
|
739
|
+
})
|
|
740
|
+
})?;
|
|
741
|
+
if cache_untouched || cur_cache == prior_cache {
|
|
742
|
+
if cur_cache != prior_cache {
|
|
743
|
+
CacheDetachPlan::Write(prior_cache)
|
|
744
|
+
} else {
|
|
745
|
+
CacheDetachPlan::Noop
|
|
746
|
+
}
|
|
747
|
+
} else {
|
|
748
|
+
let reconciled = reconcile_modified_models_cache(
|
|
749
|
+
&cur_cache,
|
|
750
|
+
Some(&prior_cache),
|
|
751
|
+
&paths.catalog_backup_file,
|
|
752
|
+
)
|
|
753
|
+
.map_err(DetachError::Conflict)?;
|
|
754
|
+
CacheDetachPlan::Write(reconciled)
|
|
755
|
+
}
|
|
756
|
+
} else if cache_untouched {
|
|
757
|
+
CacheDetachPlan::Remove
|
|
758
|
+
} else {
|
|
759
|
+
let reconciled =
|
|
760
|
+
reconcile_modified_models_cache(&cur_cache, None, &paths.catalog_backup_file)
|
|
761
|
+
.map_err(DetachError::Conflict)?;
|
|
762
|
+
CacheDetachPlan::Write(reconciled)
|
|
763
|
+
}
|
|
764
|
+
} else {
|
|
765
|
+
CacheDetachPlan::Noop
|
|
766
|
+
};
|
|
767
|
+
|
|
768
|
+
let cur_cfg_bytes = match fs::read(&config_path) {
|
|
769
|
+
Ok(b) => Some(b),
|
|
770
|
+
Err(e) if e.kind() == std::io::ErrorKind::NotFound => None,
|
|
771
|
+
Err(e) => return Err(DetachError::Io(format!("failed reading config.toml: {e}"))),
|
|
772
|
+
};
|
|
773
|
+
|
|
774
|
+
let outcome = match cur_cfg_bytes {
|
|
775
|
+
None if !journal.pre_attach_config_existed && journal.untouched_by_external_writer => {
|
|
776
|
+
DetachOutcome::ExactRestore
|
|
777
|
+
}
|
|
778
|
+
None => DetachOutcome::SurgicalRestore,
|
|
779
|
+
Some(bytes) => {
|
|
780
|
+
let cur_sha = sha256_hex(&bytes);
|
|
781
|
+
let matches_untouched_sha = cur_sha == journal.latest_injected_config_sha256
|
|
782
|
+
|| Some(cur_sha.as_str()) == journal.pre_attach_config_sha256.as_deref()
|
|
783
|
+
|| Some(cur_sha.as_str()) == journal.previous_injected_config_sha256.as_deref();
|
|
784
|
+
if journal.untouched_by_external_writer && matches_untouched_sha {
|
|
785
|
+
if journal.pre_attach_config_existed {
|
|
786
|
+
let orig = journal
|
|
787
|
+
.pre_attach_config_bytes_b64
|
|
788
|
+
.as_ref()
|
|
789
|
+
.ok_or_else(|| {
|
|
790
|
+
DetachError::Conflict("missing pre-attach config snapshot".to_owned())
|
|
791
|
+
})
|
|
792
|
+
.and_then(|b64| {
|
|
793
|
+
BASE64.decode(b64).map_err(|e| {
|
|
794
|
+
DetachError::Conflict(format!("bad snapshot base64: {e}"))
|
|
795
|
+
})
|
|
796
|
+
})?;
|
|
797
|
+
guard
|
|
798
|
+
.restore_step(|| write_regular_atomic(&config_path, &orig))
|
|
799
|
+
.map_err(step_err)?;
|
|
800
|
+
} else {
|
|
801
|
+
guard
|
|
802
|
+
.restore_step(|| remove_optional_file(&config_path))
|
|
803
|
+
.map_err(step_err)?;
|
|
804
|
+
}
|
|
805
|
+
DetachOutcome::ExactRestore
|
|
806
|
+
} else {
|
|
807
|
+
let text = std::str::from_utf8(&bytes)
|
|
808
|
+
.map_err(|_| DetachError::Conflict("config.toml is not UTF-8".to_owned()))?;
|
|
809
|
+
let stripped =
|
|
810
|
+
surgical_detach_config(text, &journal.ledger).map_err(DetachError::Conflict)?;
|
|
811
|
+
match stripped {
|
|
812
|
+
Some(updated) => {
|
|
813
|
+
guard
|
|
814
|
+
.restore_step(|| write_regular_atomic(&config_path, updated.as_bytes()))
|
|
815
|
+
.map_err(step_err)?;
|
|
816
|
+
}
|
|
817
|
+
None => {
|
|
818
|
+
guard
|
|
819
|
+
.restore_step(|| remove_optional_file(&config_path))
|
|
820
|
+
.map_err(step_err)?;
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
DetachOutcome::SurgicalRestore
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
};
|
|
827
|
+
|
|
828
|
+
if !keep_catalog {
|
|
829
|
+
if journal.pre_attach_catalog_existed {
|
|
830
|
+
if let Some(prior_bytes) = &prior_catalog {
|
|
831
|
+
guard
|
|
832
|
+
.restore_step(|| write_regular_atomic(catalog_path, prior_bytes))
|
|
833
|
+
.map_err(step_err)?;
|
|
834
|
+
}
|
|
835
|
+
} else {
|
|
836
|
+
guard
|
|
837
|
+
.restore_step(|| remove_optional_file(catalog_path))
|
|
838
|
+
.map_err(step_err)?;
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
match cache_plan {
|
|
843
|
+
CacheDetachPlan::Noop => {}
|
|
844
|
+
CacheDetachPlan::Remove => {
|
|
845
|
+
guard
|
|
846
|
+
.restore_step(|| remove_optional_file(&cache_path))
|
|
847
|
+
.map_err(step_err)?;
|
|
848
|
+
}
|
|
849
|
+
CacheDetachPlan::Write(reconciled) => {
|
|
850
|
+
guard
|
|
851
|
+
.restore_step(|| write_regular_atomic(&cache_path, &reconciled))
|
|
852
|
+
.map_err(step_err)?;
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
// A retry after cleanup starts must recognize the restored cache without
|
|
857
|
+
// relying on the catalog backup, which cleanup may already have removed.
|
|
858
|
+
match fs::read(&cache_path) {
|
|
859
|
+
Ok(restored) => {
|
|
860
|
+
journal.pre_attach_models_cache_existed = true;
|
|
861
|
+
journal.pre_attach_models_cache_bytes_b64 = Some(BASE64.encode(&restored));
|
|
862
|
+
journal.latest_models_cache_sha256 = Some(sha256_hex(&restored));
|
|
863
|
+
}
|
|
864
|
+
Err(e) if e.kind() == std::io::ErrorKind::NotFound => {
|
|
865
|
+
journal.pre_attach_models_cache_existed = false;
|
|
866
|
+
journal.pre_attach_models_cache_bytes_b64 = None;
|
|
867
|
+
journal.latest_models_cache_sha256 = None;
|
|
868
|
+
}
|
|
869
|
+
Err(e) => {
|
|
870
|
+
return Err(DetachError::Io(format!(
|
|
871
|
+
"failed reading restored cache: {e}"
|
|
872
|
+
)));
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
journal.previous_models_cache_sha256 = None;
|
|
876
|
+
guard
|
|
877
|
+
.restore_step(|| write_journal(&paths.journal_file, &journal))
|
|
878
|
+
.map_err(step_err)?;
|
|
879
|
+
|
|
880
|
+
if !defer_cleanup {
|
|
881
|
+
guard
|
|
882
|
+
.restore_step(|| remove_optional_file(&paths.catalog_backup_file))
|
|
883
|
+
.map_err(step_err)?;
|
|
884
|
+
guard
|
|
885
|
+
.restore_step(|| remove_optional_file(&paths.journal_file))
|
|
886
|
+
.map_err(step_err)?;
|
|
887
|
+
}
|
|
888
|
+
Ok(outcome)
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
fn step_err(e: RestoreStepError) -> DetachError {
|
|
892
|
+
DetachError::Io(e.into_message())
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
/// Rebuilds the pre-attach view of a `models_cache.json` that changed externally while attached.
|
|
896
|
+
///
|
|
897
|
+
/// Every slug of the last catalog the Child injected is Child-owned while attached, whatever its
|
|
898
|
+
/// current content: Codex rewrites the cache and may re-serialize those entries. Such an entry is
|
|
899
|
+
/// replaced by its pre-attach version, or dropped when the pre-attach cache did not have the slug.
|
|
900
|
+
/// Entries with any other slug were added outside the Child and are kept as they are.
|
|
901
|
+
fn reconcile_modified_models_cache(
|
|
902
|
+
cur_cache_bytes: &[u8],
|
|
903
|
+
prior_cache_bytes: Option<&[u8]>,
|
|
904
|
+
last_child_catalog_path: &Path,
|
|
905
|
+
) -> Result<Vec<u8>, String> {
|
|
906
|
+
let mut cur_val: serde_json::Value = serde_json::from_slice(cur_cache_bytes).map_err(|e| {
|
|
907
|
+
format!("client_models_cache_reconcile_failed: invalid models_cache.json: {e}")
|
|
908
|
+
})?;
|
|
909
|
+
let cur_models = cur_val
|
|
910
|
+
.get("models")
|
|
911
|
+
.and_then(serde_json::Value::as_array)
|
|
912
|
+
.cloned()
|
|
913
|
+
.ok_or_else(|| {
|
|
914
|
+
"client_models_cache_reconcile_failed: models_cache.json missing models array"
|
|
915
|
+
.to_owned()
|
|
916
|
+
})?;
|
|
917
|
+
let backup_bytes = fs::read(last_child_catalog_path).map_err(|e| {
|
|
918
|
+
format!("client_models_cache_reconcile_failed: missing catalog backup: {e}")
|
|
919
|
+
})?;
|
|
920
|
+
let backup_val: serde_json::Value = serde_json::from_slice(&backup_bytes).map_err(|e| {
|
|
921
|
+
format!("client_models_cache_reconcile_failed: invalid catalog backup JSON: {e}")
|
|
922
|
+
})?;
|
|
923
|
+
let backup_models = backup_val
|
|
924
|
+
.get("models")
|
|
925
|
+
.and_then(serde_json::Value::as_array)
|
|
926
|
+
.ok_or_else(|| {
|
|
927
|
+
"client_models_cache_reconcile_failed: catalog backup missing models array".to_owned()
|
|
928
|
+
})?;
|
|
929
|
+
let child_slugs: HashSet<&str> = backup_models
|
|
930
|
+
.iter()
|
|
931
|
+
.filter_map(|m| m.get("slug").and_then(serde_json::Value::as_str))
|
|
932
|
+
.collect();
|
|
933
|
+
let prior_by_slug: HashMap<String, serde_json::Value> = match prior_cache_bytes {
|
|
934
|
+
Some(raw) => {
|
|
935
|
+
let pv: serde_json::Value = serde_json::from_slice(raw).map_err(|e| {
|
|
936
|
+
format!(
|
|
937
|
+
"client_models_cache_reconcile_failed: invalid prior models_cache snapshot: {e}"
|
|
938
|
+
)
|
|
939
|
+
})?;
|
|
940
|
+
pv.get("models")
|
|
941
|
+
.and_then(serde_json::Value::as_array)
|
|
942
|
+
.ok_or_else(|| {
|
|
943
|
+
"client_models_cache_reconcile_failed: prior models_cache missing models array"
|
|
944
|
+
.to_owned()
|
|
945
|
+
})?
|
|
946
|
+
.iter()
|
|
947
|
+
.filter_map(|m| {
|
|
948
|
+
m.get("slug")
|
|
949
|
+
.and_then(serde_json::Value::as_str)
|
|
950
|
+
.map(|s| (s.to_owned(), m.clone()))
|
|
951
|
+
})
|
|
952
|
+
.collect()
|
|
953
|
+
}
|
|
954
|
+
None => HashMap::new(),
|
|
955
|
+
};
|
|
956
|
+
let kept: Vec<serde_json::Value> = cur_models
|
|
957
|
+
.into_iter()
|
|
958
|
+
.filter_map(|entry| {
|
|
959
|
+
let slug = entry
|
|
960
|
+
.get("slug")
|
|
961
|
+
.and_then(serde_json::Value::as_str)
|
|
962
|
+
.unwrap_or("");
|
|
963
|
+
if child_slugs.contains(slug) {
|
|
964
|
+
prior_by_slug.get(slug).cloned()
|
|
965
|
+
} else {
|
|
966
|
+
Some(entry)
|
|
967
|
+
}
|
|
968
|
+
})
|
|
969
|
+
.collect();
|
|
970
|
+
if let Some(obj) = cur_val.as_object_mut() {
|
|
971
|
+
obj.insert("models".to_owned(), serde_json::Value::Array(kept));
|
|
972
|
+
}
|
|
973
|
+
let mut out = serde_json::to_vec_pretty(&cur_val)
|
|
974
|
+
.map_err(|e| format!("client_models_cache_reconcile_failed: {e}"))?;
|
|
975
|
+
out.push(b'\n');
|
|
976
|
+
Ok(out)
|
|
977
|
+
}
|