@native-sdk/cli 0.8.4 → 0.9.1
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/build/app.zig +1178 -74
- package/build.zig +715 -17
- package/build.zig.zon +1 -0
- package/native-sdk.d.ts +10 -0
- package/package.json +12 -11
- package/packages/core/compile-surface/core.ts +435 -3
- package/packages/core/package-lock.json +11 -11
- package/packages/core/package.json +2 -2
- package/packages/core/scripts/compiler_typecheck.mjs +116 -15
- package/packages/core/scripts/gen_service_surface.mjs +268 -0
- package/packages/core/scripts/merge_static_archives.mjs +78 -0
- package/packages/core/scripts/npm_static_spike.mjs +64 -0
- package/packages/core/scripts/run_external_core_compiler.mjs +122 -6
- package/packages/core/scripts/run_external_service_compiler.mjs +280 -0
- package/packages/core/scripts/stage_external_core.mjs +9 -1
- package/packages/core/scripts/stage_external_services.mjs +172 -0
- package/packages/core/scripts/surface_manifest_diff.mjs +253 -0
- package/packages/core/scripts/vendor_service_packages.mjs +189 -0
- package/packages/core/sdk/core.d.ts +224 -0
- package/packages/core/sdk/core.ts +694 -22
- package/packages/core/sdk/events.d.ts +89 -0
- package/packages/core/sdk/events.ts +128 -0
- package/packages/core/src/checker.ts +936 -15
- package/packages/core/src/cli.ts +156 -3
- package/packages/core/src/contract.ts +28 -5
- package/packages/core/src/devhost.ts +1876 -16
- package/packages/core/src/devhost_journal.mjs +183 -0
- package/packages/core/src/devhost_resolver.mjs +17 -1
- package/packages/core/src/devhost_service_worker.mjs +90 -0
- package/packages/core/src/diagnostics.ts +179 -22
- package/packages/core/src/frontend.ts +210 -34
- package/packages/core/src/infer.ts +24 -0
- package/packages/core/src/modules.ts +129 -80
- package/packages/core/src/service_contract.ts +597 -0
- package/packages/core/src/sqlite_cli.ts +93 -0
- package/packages/core/src/sqlite_codegen.ts +806 -0
- package/packages/core/src/sqlite_runtime_policy.ts +364 -0
- package/packages/core/src/typed_ast.ts +36 -8
- package/skill-data/automation/SKILL.md +1 -1
- package/skill-data/core/references/project-anatomy.md +1 -1
- package/skill-data/native-ui/SKILL.md +58 -5
- package/skill-data/ts-core/SKILL.md +123 -41
- package/skill-data/ts-services/SKILL.md +126 -0
- package/skill-data/ts-services/references/service-surface.md +604 -0
- package/skill-data/zig/SKILL.md +1 -1
- package/skills/native-sdk/SKILL.md +1 -1
- package/src/app_runner/no_migrations.zig +3 -0
- package/src/app_runner/no_services.zig +20 -0
- package/src/app_runner/root.zig +133 -4
- package/src/app_runner/ts_core_main.zig +254 -8
- package/src/app_runner/ts_core_mobile.zig +241 -0
- package/src/automation/protocol.zig +5 -1
- package/src/automation/snapshot.zig +31 -11
- package/src/embed/app_exports.zig +12 -1
- package/src/embed/c_api.zig +48 -2
- package/src/embed/conversions.zig +4 -5
- package/src/embed/host.zig +109 -1
- package/src/embed/root.zig +8 -0
- package/src/embed/tests.zig +241 -0
- package/src/embed/types.zig +51 -0
- package/src/embed/ui_host.zig +185 -5
- package/src/platform/android/NativeSdkActivity.java +131 -0
- package/src/platform/android/android_host.c +182 -1
- package/src/platform/android/native_sdk_app.h +17 -0
- package/src/platform/ios/native_sdk_app.h +17 -0
- package/src/platform/ios/uikit_host.m +115 -0
- package/src/platform/linux/cef_host.cpp +8 -2
- package/src/platform/linux/gtk_host.c +289 -22
- package/src/platform/linux/gtk_host.h +5 -1
- package/src/platform/linux/root.zig +109 -22
- package/src/platform/macos/appkit_host.h +24 -7
- package/src/platform/macos/appkit_host.m +686 -64
- package/src/platform/macos/cef_host.mm +400 -66
- package/src/platform/macos/root.zig +304 -47
- package/src/platform/null_platform.zig +435 -48
- package/src/platform/null_platform_tests.zig +113 -0
- package/src/platform/root.zig +19 -0
- package/src/platform/types.zig +281 -28
- package/src/platform/windows/root.zig +207 -27
- package/src/platform/windows/webview2_host.cpp +334 -51
- package/src/primitives/app_manifest/comptime_scene.zig +2 -0
- package/src/primitives/app_manifest/root.zig +4 -0
- package/src/primitives/app_manifest/tests.zig +3 -0
- package/src/primitives/app_manifest/types.zig +32 -0
- package/src/primitives/app_manifest/validation.zig +19 -1
- package/src/root.zig +53 -0
- package/src/runtime/api.zig +19 -0
- package/src/runtime/automation_commands.zig +35 -2
- package/src/runtime/automation_snapshot.zig +32 -20
- package/src/runtime/bridge_permission_tests.zig +58 -3
- package/src/runtime/bridge_responses.zig +4 -2
- package/src/runtime/builtin_bridge.zig +11 -1
- package/src/runtime/canvas_frame.zig +18 -11
- package/src/runtime/canvas_frame_animation_tests.zig +4 -0
- package/src/runtime/clock.zig +13 -1
- package/src/runtime/core.zig +145 -7
- package/src/runtime/credentials_store.zig +115 -0
- package/src/runtime/effects.zig +3701 -231
- package/src/runtime/effects_credentials_tests.zig +332 -0
- package/src/runtime/effects_file_tests.zig +587 -0
- package/src/runtime/effects_host_tests.zig +208 -1
- package/src/runtime/effects_notification_tests.zig +11 -0
- package/src/runtime/effects_relational_tests.zig +314 -0
- package/src/runtime/effects_store_tests.zig +211 -0
- package/src/runtime/file_access.zig +400 -0
- package/src/runtime/file_effect_crash_helper.zig +28 -0
- package/src/runtime/file_effect_crash_tests.zig +37 -0
- package/src/runtime/flow.zig +35 -10
- package/src/runtime/gpu_surface_events.zig +6 -1
- package/src/runtime/native_command_event_tests.zig +86 -2
- package/src/runtime/persist_store.zig +666 -0
- package/src/runtime/pty.zig +5 -2
- package/src/runtime/record_store.zig +788 -0
- package/src/runtime/relational_store.zig +854 -0
- package/src/runtime/root.zig +54 -0
- package/src/runtime/runtime_event_tests.zig +70 -0
- package/src/runtime/service_host.zig +711 -0
- package/src/runtime/service_pool.zig +1314 -0
- package/src/runtime/session_blobs.zig +4 -1
- package/src/runtime/session_journal.zig +158 -5
- package/src/runtime/session_record.zig +215 -0
- package/src/runtime/session_replay.zig +206 -11
- package/src/runtime/session_tests.zig +81 -0
- package/src/runtime/shell_layout.zig +1 -0
- package/src/runtime/shell_layout_tests.zig +120 -0
- package/src/runtime/sqlite_engine.zig +474 -0
- package/src/runtime/state.zig +16 -0
- package/src/runtime/system_services.zig +170 -38
- package/src/runtime/tests.zig +4 -0
- package/src/runtime/ts_core_host.zig +1067 -95
- package/src/runtime/ts_core_host_tests.zig +325 -11
- package/src/runtime/ts_ui_app.zig +953 -2
- package/src/runtime/ui_app.zig +434 -96
- package/src/runtime/ui_app_tests.zig +287 -11
- package/src/runtime/ui_app_window_tests.zig +61 -7
- package/src/runtime/validation.zig +42 -0
- package/src/runtime/view.zig +9 -0
- package/src/runtime/window_storage.zig +1 -0
- package/src/runtime/window_view_runtime.zig +2 -3
- package/src/runtime/window_views.zig +19 -0
- package/src/tooling/android.zig +21 -16
- package/src/tooling/db.zig +160 -0
- package/src/tooling/ios.zig +7 -1
- package/src/tooling/manifest.zig +214 -2
- package/src/tooling/package.zig +116 -0
- package/src/tooling/raw_manifest.zig +30 -0
- package/src/tooling/root.zig +1 -0
- package/src/tooling/templates.zig +189 -4
- package/src/tooling/ts_core.zig +366 -17
- package/src/tooling/verbs.zig +7 -0
- package/third_party/sqlite/README.md +13 -0
- package/third_party/sqlite/sqlite3.c +269649 -0
- package/third_party/sqlite/sqlite3.h +14349 -0
- package/tools/corewire/core_abi.zig +14 -2
- package/tools/corewire/emit.zig +98 -29
- package/tools/corewire/emit_facade.zig +442 -27
- package/tools/corewire/emit_profile.zig +6 -2
- package/tools/corewire/emit_service.zig +924 -0
- package/tools/corewire/main.zig +122 -0
- package/tools/corewire/service_contract.zig +250 -0
- package/tools/corewire/sidecar.zig +26 -15
|
@@ -39,7 +39,10 @@ pub const hash_len: usize = runtime_effects.effect_image_blob_hash_len;
|
|
|
39
39
|
|
|
40
40
|
/// The largest payload one blob may hold — the largest journaled effect
|
|
41
41
|
/// payload that goes out of line (an image load's encoded source).
|
|
42
|
-
pub const max_blob_bytes: usize =
|
|
42
|
+
pub const max_blob_bytes: usize = @max(
|
|
43
|
+
runtime_effects.effect_file_stream_chunk_bytes,
|
|
44
|
+
@max(runtime_effects.max_effect_image_bytes, runtime_effects.max_effect_persist_snapshot_bytes),
|
|
45
|
+
);
|
|
43
46
|
|
|
44
47
|
pub const BlobHash = [hash_len]u8;
|
|
45
48
|
|
|
@@ -184,6 +184,8 @@ fn formatLayoutDescription(comptime epoch: u32) []const u8 {
|
|
|
184
184
|
"shortcut=" ++ layout_fingerprint.describe(platform.ShortcutEvent) ++ "\n" ++
|
|
185
185
|
"native_command=" ++ layout_fingerprint.describe(platform.NativeCommandEvent) ++ "\n" ++
|
|
186
186
|
"menu_command=" ++ layout_fingerprint.describe(platform.MenuCommandEvent) ++ "\n" ++
|
|
187
|
+
"tray_command=" ++ layout_fingerprint.describe(platform.TrayCommandEvent) ++ "\n" ++
|
|
188
|
+
"notification_command=" ++ layout_fingerprint.describe(platform.NotificationCommandEvent) ++ "\n" ++
|
|
187
189
|
"timer=" ++ layout_fingerprint.describe(platform.TimerEvent) ++ "\n" ++
|
|
188
190
|
"audio=" ++ layout_fingerprint.describe(platform.AudioEvent) ++ "\n" ++
|
|
189
191
|
"video=" ++ layout_fingerprint.describe(platform.VideoEvent) ++ "\n" ++
|
|
@@ -464,6 +466,8 @@ const EventTag = enum(u8) {
|
|
|
464
466
|
audio = 24,
|
|
465
467
|
video = 25,
|
|
466
468
|
view_focused = 26,
|
|
469
|
+
tray_command = 27,
|
|
470
|
+
notification_command = 28,
|
|
467
471
|
};
|
|
468
472
|
|
|
469
473
|
// The bit assignments below are hand-written wire layout: they are
|
|
@@ -583,9 +587,10 @@ pub fn encodeEvent(event: platform.Event, buffer: []u8) JournalError![]const u8
|
|
|
583
587
|
try cursor.writeInt(u64, message.window_id);
|
|
584
588
|
try cursor.writeStr(message.webview_label);
|
|
585
589
|
},
|
|
586
|
-
.tray_action => |
|
|
590
|
+
.tray_action => |action| {
|
|
587
591
|
try cursor.writeEnum(EventTag.tray_action);
|
|
588
|
-
try cursor.writeInt(u32,
|
|
592
|
+
try cursor.writeInt(u32, action.status_item_id);
|
|
593
|
+
try cursor.writeInt(u32, action.item_id);
|
|
589
594
|
},
|
|
590
595
|
.shortcut => |shortcut| {
|
|
591
596
|
try cursor.writeEnum(EventTag.shortcut);
|
|
@@ -605,6 +610,17 @@ pub fn encodeEvent(event: platform.Event, buffer: []u8) JournalError![]const u8
|
|
|
605
610
|
try cursor.writeStr(command.name);
|
|
606
611
|
try cursor.writeInt(u64, command.window_id);
|
|
607
612
|
},
|
|
613
|
+
.tray_command => |command| {
|
|
614
|
+
try cursor.writeEnum(EventTag.tray_command);
|
|
615
|
+
try cursor.writeStr(command.name);
|
|
616
|
+
try cursor.writeInt(u64, command.window_id);
|
|
617
|
+
try cursor.writeInt(u32, command.status_item_id);
|
|
618
|
+
},
|
|
619
|
+
.notification_command => |command| {
|
|
620
|
+
try cursor.writeEnum(EventTag.notification_command);
|
|
621
|
+
try cursor.writeStr(command.name);
|
|
622
|
+
try cursor.writeInt(u64, command.window_id);
|
|
623
|
+
},
|
|
608
624
|
.timer => |timer| {
|
|
609
625
|
try cursor.writeEnum(EventTag.timer);
|
|
610
626
|
try cursor.writeInt(u64, timer.id);
|
|
@@ -802,7 +818,10 @@ pub fn decodeEvent(bytes: []const u8, storage: *EventDecodeStorage) JournalError
|
|
|
802
818
|
.webview_label = webview_label,
|
|
803
819
|
} };
|
|
804
820
|
},
|
|
805
|
-
.tray_action => .{ .tray_action =
|
|
821
|
+
.tray_action => .{ .tray_action = .{
|
|
822
|
+
.status_item_id = try cursor.readInt(u32),
|
|
823
|
+
.item_id = try cursor.readInt(u32),
|
|
824
|
+
} },
|
|
806
825
|
.shortcut => blk: {
|
|
807
826
|
const id = try cursor.readStr();
|
|
808
827
|
const key = try cursor.readStr();
|
|
@@ -830,6 +849,21 @@ pub fn decodeEvent(bytes: []const u8, storage: *EventDecodeStorage) JournalError
|
|
|
830
849
|
.window_id = try cursor.readInt(u64),
|
|
831
850
|
} };
|
|
832
851
|
},
|
|
852
|
+
.tray_command => blk: {
|
|
853
|
+
const name = try cursor.readStr();
|
|
854
|
+
break :blk .{ .tray_command = .{
|
|
855
|
+
.name = name,
|
|
856
|
+
.window_id = try cursor.readInt(u64),
|
|
857
|
+
.status_item_id = try cursor.readInt(u32),
|
|
858
|
+
} };
|
|
859
|
+
},
|
|
860
|
+
.notification_command => blk: {
|
|
861
|
+
const name = try cursor.readStr();
|
|
862
|
+
break :blk .{ .notification_command = .{
|
|
863
|
+
.name = name,
|
|
864
|
+
.window_id = try cursor.readInt(u64),
|
|
865
|
+
} };
|
|
866
|
+
},
|
|
833
867
|
.timer => blk: {
|
|
834
868
|
const id = try cursor.readInt(u64);
|
|
835
869
|
break :blk .{ .timer = .{
|
|
@@ -1020,7 +1054,12 @@ pub fn encodeEffect(record: EffectResultRecord, buffer: []u8) JournalError![]con
|
|
|
1020
1054
|
try cursor.writeInt(u16, record.status);
|
|
1021
1055
|
try cursor.writeEnum(record.fetch_outcome);
|
|
1022
1056
|
try cursor.writeEnum(record.file_op);
|
|
1057
|
+
try cursor.writeEnum(record.file_event);
|
|
1023
1058
|
try cursor.writeEnum(record.file_outcome);
|
|
1059
|
+
try cursor.writeInt(u64, record.file_total);
|
|
1060
|
+
try cursor.writeInt(i64, record.file_mtime_ms);
|
|
1061
|
+
try cursor.writeBool(record.file_exists);
|
|
1062
|
+
try cursor.writeBool(record.file_rejected_admission);
|
|
1024
1063
|
try cursor.writeEnum(record.clipboard_op);
|
|
1025
1064
|
try cursor.writeEnum(record.clipboard_outcome);
|
|
1026
1065
|
try cursor.writeInt(u64, record.timer_timestamp_ns);
|
|
@@ -1031,6 +1070,8 @@ pub fn encodeEffect(record: EffectResultRecord, buffer: []u8) JournalError![]con
|
|
|
1031
1070
|
try cursor.writeInt(u64, record.audio_duration_ms);
|
|
1032
1071
|
try cursor.writeBool(record.audio_playing);
|
|
1033
1072
|
try cursor.writeBool(record.audio_buffering);
|
|
1073
|
+
try cursor.writeBytes(&record.file_blob_hash);
|
|
1074
|
+
try cursor.writeInt(u64, record.file_blob_len);
|
|
1034
1075
|
try cursor.writeBytes(&record.audio_bands);
|
|
1035
1076
|
// v7: image terminals — outcome, decoded dimensions, and the blob
|
|
1036
1077
|
// store content address of the journaled source bytes.
|
|
@@ -1068,6 +1109,25 @@ pub fn encodeEffect(record: EffectResultRecord, buffer: []u8) JournalError![]con
|
|
|
1068
1109
|
try cursor.writeInt(u32, record.pty_dropped_writes);
|
|
1069
1110
|
try cursor.writeBytes(&record.pty_blob_hash);
|
|
1070
1111
|
try cursor.writeInt(u64, record.pty_blob_len);
|
|
1112
|
+
// Model restore is the first kind-local suffix. Keeping it conditional
|
|
1113
|
+
// preserves every established effect record's byte layout (tests and
|
|
1114
|
+
// tooling deliberately patch those records at known offsets).
|
|
1115
|
+
if (record.kind == .persist) {
|
|
1116
|
+
try cursor.writeEnum(record.persist_outcome);
|
|
1117
|
+
try cursor.writeBytes(&record.persist_blob_hash);
|
|
1118
|
+
try cursor.writeInt(u64, record.persist_blob_len);
|
|
1119
|
+
}
|
|
1120
|
+
if (record.kind == .db) {
|
|
1121
|
+
try cursor.writeBytes(&record.db_blob_hash);
|
|
1122
|
+
try cursor.writeInt(u64, record.db_blob_len);
|
|
1123
|
+
}
|
|
1124
|
+
if (record.kind == .credentials) {
|
|
1125
|
+
try cursor.writeEnum(record.credentials_operation);
|
|
1126
|
+
try cursor.writeEnum(record.credentials_outcome);
|
|
1127
|
+
try cursor.writeInt(u64, record.credentials_secret_len);
|
|
1128
|
+
try cursor.writeBytes(&record.credentials_salt);
|
|
1129
|
+
try cursor.writeBytes(&record.credentials_digest);
|
|
1130
|
+
}
|
|
1071
1131
|
return buffer[0..cursor.len];
|
|
1072
1132
|
}
|
|
1073
1133
|
|
|
@@ -1087,7 +1147,12 @@ pub fn decodeEffect(bytes: []const u8) JournalError!EffectResultRecord {
|
|
|
1087
1147
|
.status = try cursor.readInt(u16),
|
|
1088
1148
|
.fetch_outcome = try cursor.readEnum(runtime_effects.EffectFetchOutcome),
|
|
1089
1149
|
.file_op = try cursor.readEnum(runtime_effects.EffectFileOp),
|
|
1150
|
+
.file_event = try cursor.readEnum(runtime_effects.EffectFileEvent),
|
|
1090
1151
|
.file_outcome = try cursor.readEnum(runtime_effects.EffectFileOutcome),
|
|
1152
|
+
.file_total = try cursor.readInt(u64),
|
|
1153
|
+
.file_mtime_ms = try cursor.readInt(i64),
|
|
1154
|
+
.file_exists = try cursor.readBool(),
|
|
1155
|
+
.file_rejected_admission = try cursor.readBool(),
|
|
1091
1156
|
.clipboard_op = try cursor.readEnum(runtime_effects.EffectClipboardOp),
|
|
1092
1157
|
.clipboard_outcome = try cursor.readEnum(runtime_effects.EffectClipboardOutcome),
|
|
1093
1158
|
.timer_timestamp_ns = try cursor.readInt(u64),
|
|
@@ -1099,6 +1164,8 @@ pub fn decodeEffect(bytes: []const u8) JournalError!EffectResultRecord {
|
|
|
1099
1164
|
.audio_playing = try cursor.readBool(),
|
|
1100
1165
|
.audio_buffering = try cursor.readBool(),
|
|
1101
1166
|
};
|
|
1167
|
+
@memcpy(&record.file_blob_hash, try cursor.readBytes(record.file_blob_hash.len));
|
|
1168
|
+
record.file_blob_len = try cursor.readInt(u64);
|
|
1102
1169
|
@memcpy(&record.audio_bands, try cursor.readBytes(record.audio_bands.len));
|
|
1103
1170
|
// v7: image terminals.
|
|
1104
1171
|
record.image_outcome = try cursor.readEnum(runtime_effects.EffectImageOutcome);
|
|
@@ -1126,6 +1193,22 @@ pub fn decodeEffect(bytes: []const u8) JournalError!EffectResultRecord {
|
|
|
1126
1193
|
record.pty_dropped_writes = try cursor.readInt(u32);
|
|
1127
1194
|
@memcpy(&record.pty_blob_hash, try cursor.readBytes(record.pty_blob_hash.len));
|
|
1128
1195
|
record.pty_blob_len = try cursor.readInt(u64);
|
|
1196
|
+
if (record.kind == .persist) {
|
|
1197
|
+
record.persist_outcome = try cursor.readEnum(runtime_effects.EffectPersistOutcome);
|
|
1198
|
+
@memcpy(&record.persist_blob_hash, try cursor.readBytes(record.persist_blob_hash.len));
|
|
1199
|
+
record.persist_blob_len = try cursor.readInt(u64);
|
|
1200
|
+
}
|
|
1201
|
+
if (record.kind == .db) {
|
|
1202
|
+
@memcpy(&record.db_blob_hash, try cursor.readBytes(record.db_blob_hash.len));
|
|
1203
|
+
record.db_blob_len = try cursor.readInt(u64);
|
|
1204
|
+
}
|
|
1205
|
+
if (record.kind == .credentials) {
|
|
1206
|
+
record.credentials_operation = try cursor.readEnum(runtime_effects.EffectCredentialsOperation);
|
|
1207
|
+
record.credentials_outcome = try cursor.readEnum(runtime_effects.EffectCredentialsOutcome);
|
|
1208
|
+
record.credentials_secret_len = try cursor.readInt(u64);
|
|
1209
|
+
@memcpy(&record.credentials_salt, try cursor.readBytes(record.credentials_salt.len));
|
|
1210
|
+
@memcpy(&record.credentials_digest, try cursor.readBytes(record.credentials_digest.len));
|
|
1211
|
+
}
|
|
1129
1212
|
if (!cursor.done()) return error.JournalCorrupt;
|
|
1130
1213
|
return record;
|
|
1131
1214
|
}
|
|
@@ -1582,8 +1665,19 @@ test "event codec round-trips every payload variant" {
|
|
|
1582
1665
|
try testing.expectEqualStrings("app.about", decoded.menu_command.name);
|
|
1583
1666
|
}
|
|
1584
1667
|
{
|
|
1585
|
-
const decoded = try roundTripEvent(.{ .
|
|
1586
|
-
try testing.
|
|
1668
|
+
const decoded = try roundTripEvent(.{ .tray_command = .{ .name = "app.refresh", .window_id = 3 } });
|
|
1669
|
+
try testing.expectEqualStrings("app.refresh", decoded.tray_command.name);
|
|
1670
|
+
try testing.expectEqual(@as(platform.WindowId, 3), decoded.tray_command.window_id);
|
|
1671
|
+
}
|
|
1672
|
+
{
|
|
1673
|
+
const decoded = try roundTripEvent(.{ .notification_command = .{ .name = "build.open", .window_id = 2 } });
|
|
1674
|
+
try testing.expectEqualStrings("build.open", decoded.notification_command.name);
|
|
1675
|
+
try testing.expectEqual(@as(platform.WindowId, 2), decoded.notification_command.window_id);
|
|
1676
|
+
}
|
|
1677
|
+
{
|
|
1678
|
+
const decoded = try roundTripEvent(.{ .tray_action = .{ .status_item_id = 3, .item_id = 9 } });
|
|
1679
|
+
try testing.expectEqual(@as(platform.StatusItemId, 3), decoded.tray_action.status_item_id);
|
|
1680
|
+
try testing.expectEqual(@as(platform.TrayItemId, 9), decoded.tray_action.item_id);
|
|
1587
1681
|
}
|
|
1588
1682
|
{
|
|
1589
1683
|
const decoded = try roundTripEvent(.{ .window_focused = 4 });
|
|
@@ -1622,6 +1716,17 @@ test "effect codec round-trips payloads and outcomes" {
|
|
|
1622
1716
|
try testing.expect(decoded.truncated);
|
|
1623
1717
|
try testing.expectEqual(@as(u16, 200), decoded.status);
|
|
1624
1718
|
|
|
1719
|
+
const delete_encoded = try encodeEffect(.{
|
|
1720
|
+
.kind = .file,
|
|
1721
|
+
.key = 78,
|
|
1722
|
+
.file_op = .delete,
|
|
1723
|
+
.file_outcome = .not_found,
|
|
1724
|
+
}, &buffer);
|
|
1725
|
+
const delete_decoded = try decodeEffect(delete_encoded);
|
|
1726
|
+
try testing.expectEqual(runtime_effects.EffectResultKind.file, delete_decoded.kind);
|
|
1727
|
+
try testing.expectEqual(runtime_effects.EffectFileOp.delete, delete_decoded.file_op);
|
|
1728
|
+
try testing.expectEqual(runtime_effects.EffectFileOutcome.not_found, delete_decoded.file_outcome);
|
|
1729
|
+
|
|
1625
1730
|
const exit_encoded = try encodeEffect(.{
|
|
1626
1731
|
.kind = .exit,
|
|
1627
1732
|
.key = 5,
|
|
@@ -1724,6 +1829,54 @@ test "effect codec round-trips payloads and outcomes" {
|
|
|
1724
1829
|
try testing.expect(video_decoded.video_buffering);
|
|
1725
1830
|
try testing.expectEqual(@as(u64, 1280), video_decoded.video_width);
|
|
1726
1831
|
try testing.expectEqual(@as(u64, 720), video_decoded.video_height);
|
|
1832
|
+
|
|
1833
|
+
// Persistence is a kind-local suffix: successful restore bytes live in
|
|
1834
|
+
// the blob store, while the journal carries its closed outcome/address.
|
|
1835
|
+
const persist_hash: [runtime_effects.effect_image_blob_hash_len]u8 = @splat(0xa5);
|
|
1836
|
+
const persist_encoded = try encodeEffect(.{
|
|
1837
|
+
.kind = .persist,
|
|
1838
|
+
.key = 0,
|
|
1839
|
+
.persist_outcome = .ok,
|
|
1840
|
+
.persist_blob_hash = persist_hash,
|
|
1841
|
+
.persist_blob_len = 4096,
|
|
1842
|
+
}, &buffer);
|
|
1843
|
+
const persist_decoded = try decodeEffect(persist_encoded);
|
|
1844
|
+
try testing.expectEqual(runtime_effects.EffectResultKind.persist, persist_decoded.kind);
|
|
1845
|
+
try testing.expectEqual(runtime_effects.EffectPersistOutcome.ok, persist_decoded.persist_outcome);
|
|
1846
|
+
try testing.expectEqualSlices(u8, &persist_hash, &persist_decoded.persist_blob_hash);
|
|
1847
|
+
try testing.expectEqual(@as(u64, 4096), persist_decoded.persist_blob_len);
|
|
1848
|
+
|
|
1849
|
+
const db_hash: [runtime_effects.effect_image_blob_hash_len]u8 = @splat(0x5a);
|
|
1850
|
+
const db_encoded = try encodeEffect(.{
|
|
1851
|
+
.kind = .db,
|
|
1852
|
+
.key = 73,
|
|
1853
|
+
.code = runtime_effects.dbJournalCode(.page, .ok),
|
|
1854
|
+
.db_blob_hash = db_hash,
|
|
1855
|
+
.db_blob_len = 96 * 1024,
|
|
1856
|
+
}, &buffer);
|
|
1857
|
+
const db_decoded = try decodeEffect(db_encoded);
|
|
1858
|
+
try testing.expectEqual(runtime_effects.EffectResultKind.db, db_decoded.kind);
|
|
1859
|
+
try testing.expectEqualSlices(u8, &db_hash, &db_decoded.db_blob_hash);
|
|
1860
|
+
try testing.expectEqual(@as(u64, 96 * 1024), db_decoded.db_blob_len);
|
|
1861
|
+
|
|
1862
|
+
const credential_digest: [32]u8 = @splat(0x39);
|
|
1863
|
+
const credential_salt: [16]u8 = @splat(0x17);
|
|
1864
|
+
const credential_encoded = try encodeEffect(.{
|
|
1865
|
+
.kind = .credentials,
|
|
1866
|
+
.key = 81,
|
|
1867
|
+
.credentials_operation = .get,
|
|
1868
|
+
.credentials_outcome = .ok,
|
|
1869
|
+
.credentials_secret_len = 27,
|
|
1870
|
+
.credentials_salt = credential_salt,
|
|
1871
|
+
.credentials_digest = credential_digest,
|
|
1872
|
+
}, &buffer);
|
|
1873
|
+
const credential_decoded = try decodeEffect(credential_encoded);
|
|
1874
|
+
try testing.expectEqual(runtime_effects.EffectResultKind.credentials, credential_decoded.kind);
|
|
1875
|
+
try testing.expectEqual(runtime_effects.EffectCredentialsOperation.get, credential_decoded.credentials_operation);
|
|
1876
|
+
try testing.expectEqual(runtime_effects.EffectCredentialsOutcome.ok, credential_decoded.credentials_outcome);
|
|
1877
|
+
try testing.expectEqual(@as(u64, 27), credential_decoded.credentials_secret_len);
|
|
1878
|
+
try testing.expectEqualSlices(u8, &credential_salt, &credential_decoded.credentials_salt);
|
|
1879
|
+
try testing.expectEqualSlices(u8, &credential_digest, &credential_decoded.credentials_digest);
|
|
1727
1880
|
}
|
|
1728
1881
|
|
|
1729
1882
|
test "header, checkpoint, screenshot, and end codecs round-trip" {
|
|
@@ -27,6 +27,11 @@ const runtime_effects = @import("effects.zig");
|
|
|
27
27
|
const journal = @import("session_journal.zig");
|
|
28
28
|
const session_blobs = @import("session_blobs.zig");
|
|
29
29
|
|
|
30
|
+
/// Keep ordinary query pages self-contained while spilling pages large
|
|
31
|
+
/// enough to dominate the journal. The relational page's own hard ceiling
|
|
32
|
+
/// remains `max_effect_db_page_bytes`.
|
|
33
|
+
pub const max_inline_db_page_bytes: usize = 64 * 1024;
|
|
34
|
+
|
|
30
35
|
pub const Header = journal.Header;
|
|
31
36
|
|
|
32
37
|
/// Where journal bytes go. The app runner backs this with a file opened
|
|
@@ -53,6 +58,11 @@ pub const SessionRecorder = struct {
|
|
|
53
58
|
effect_count: u64 = 0,
|
|
54
59
|
checkpoint_count: u64 = 0,
|
|
55
60
|
screenshot_count: u64 = 0,
|
|
61
|
+
/// Per-session salt for credential replay-placeholder digests. The digest
|
|
62
|
+
/// is deliberately independent of the secret, so a shareable journal is
|
|
63
|
+
/// not an offline guessing oracle. Successful secret bytes are never
|
|
64
|
+
/// written to either the journal or its blob store.
|
|
65
|
+
credentials_salt: [16]u8 = @splat(0),
|
|
56
66
|
/// Frame index of the last recorded checkpoint, so exactly one
|
|
57
67
|
/// checkpoint follows each published frame.
|
|
58
68
|
last_checkpoint_frame: u64 = 0,
|
|
@@ -79,6 +89,20 @@ pub const SessionRecorder = struct {
|
|
|
79
89
|
pub fn begin(self: *SessionRecorder, header: Header) void {
|
|
80
90
|
if (self.began or self.failed) return;
|
|
81
91
|
self.began = true;
|
|
92
|
+
// SessionRecorder deliberately has no ambient-I/O handle. Derive a
|
|
93
|
+
// per-session salt from the already-journaled header identity and
|
|
94
|
+
// timestamp. The resulting placeholder digest is metadata only and
|
|
95
|
+
// never hashes credential bytes.
|
|
96
|
+
var salt_hasher = std.crypto.hash.sha2.Sha256.init(.{});
|
|
97
|
+
salt_hasher.update(header.platform_name);
|
|
98
|
+
salt_hasher.update(header.app_name);
|
|
99
|
+
var salt_scalars: [16]u8 = undefined;
|
|
100
|
+
std.mem.writeInt(u64, salt_scalars[0..8], header.protocol_fingerprint, .little);
|
|
101
|
+
std.mem.writeInt(i64, salt_scalars[8..16], header.recorded_at_wall_ms, .little);
|
|
102
|
+
salt_hasher.update(&salt_scalars);
|
|
103
|
+
var salt_digest: [32]u8 = undefined;
|
|
104
|
+
salt_hasher.final(&salt_digest);
|
|
105
|
+
@memcpy(&self.credentials_salt, salt_digest[0..self.credentials_salt.len]);
|
|
82
106
|
var preamble_buffer: [journal.preamble_len]u8 = undefined;
|
|
83
107
|
self.write(journal.writePreamble(&preamble_buffer));
|
|
84
108
|
const payload = journal.encodeHeader(header, &self.small_buffer) catch {
|
|
@@ -201,6 +225,32 @@ pub const SessionRecorder = struct {
|
|
|
201
225
|
pub fn recordEffect(self: *SessionRecorder, record: runtime_effects.EffectResultRecord) void {
|
|
202
226
|
if (!self.began or self.failed or self.finished) return;
|
|
203
227
|
var journaled = record;
|
|
228
|
+
if (record.kind == .credentials) {
|
|
229
|
+
// Error bytes duplicate the closed outcome and successful get
|
|
230
|
+
// bytes are secrets. Neither belongs in a shareable artifact.
|
|
231
|
+
journaled.payload = "";
|
|
232
|
+
if (record.credentials_operation == .get and record.credentials_outcome == .ok) {
|
|
233
|
+
var hasher = std.crypto.hash.sha2.Sha256.init(.{});
|
|
234
|
+
hasher.update(&self.credentials_salt);
|
|
235
|
+
var ordinal: [8]u8 = undefined;
|
|
236
|
+
std.mem.writeInt(u64, ordinal[0..], self.effect_count, .little);
|
|
237
|
+
hasher.update(&ordinal);
|
|
238
|
+
hasher.update(@tagName(record.credentials_operation));
|
|
239
|
+
hasher.final(&journaled.credentials_digest);
|
|
240
|
+
journaled.credentials_salt = self.credentials_salt;
|
|
241
|
+
journaled.credentials_secret_len = record.payload.len;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
if (record.kind == .file and record.file_event == .chunk and record.payload.len > 0) {
|
|
245
|
+
const blob_sink = self.blob_sink orelse {
|
|
246
|
+
return self.fail("a streamed file chunk needs the session blob store, and none is bound - wire SessionRecorder.blob_sink");
|
|
247
|
+
};
|
|
248
|
+
const hash = session_blobs.hashBytes(record.payload);
|
|
249
|
+
blob_sink.write_fn(blob_sink.context, hash, record.payload) catch |err| return self.fail(@errorName(err));
|
|
250
|
+
journaled.file_blob_hash = hash;
|
|
251
|
+
journaled.file_blob_len = record.payload.len;
|
|
252
|
+
journaled.payload = "";
|
|
253
|
+
}
|
|
204
254
|
if (record.kind == .image and record.payload.len > 0) {
|
|
205
255
|
const blob_sink = self.blob_sink orelse {
|
|
206
256
|
return self.fail("an image effect result needs the session blob store, and none is bound - wire SessionRecorder.blob_sink (the app runner creates blobs/ beside the journal)");
|
|
@@ -229,6 +279,30 @@ pub const SessionRecorder = struct {
|
|
|
229
279
|
journaled.pty_blob_len = record.payload.len;
|
|
230
280
|
journaled.payload = "";
|
|
231
281
|
}
|
|
282
|
+
if (record.kind == .persist and record.payload.len > 0) {
|
|
283
|
+
const blob_sink = self.blob_sink orelse {
|
|
284
|
+
return self.fail("a model restore needs the session blob store, and none is bound - wire SessionRecorder.blob_sink (the app runner creates blobs/ beside the journal)");
|
|
285
|
+
};
|
|
286
|
+
const hash = session_blobs.hashBytes(record.payload);
|
|
287
|
+
blob_sink.write_fn(blob_sink.context, hash, record.payload) catch |err| {
|
|
288
|
+
return self.fail(@errorName(err));
|
|
289
|
+
};
|
|
290
|
+
journaled.persist_blob_hash = hash;
|
|
291
|
+
journaled.persist_blob_len = record.payload.len;
|
|
292
|
+
journaled.payload = "";
|
|
293
|
+
}
|
|
294
|
+
if (record.kind == .db and record.payload.len > max_inline_db_page_bytes) {
|
|
295
|
+
const blob_sink = self.blob_sink orelse {
|
|
296
|
+
return self.fail("a large relational page needs the session blob store, and none is bound - wire SessionRecorder.blob_sink (the app runner creates blobs/ beside the journal)");
|
|
297
|
+
};
|
|
298
|
+
const hash = session_blobs.hashBytes(record.payload);
|
|
299
|
+
blob_sink.write_fn(blob_sink.context, hash, record.payload) catch |err| {
|
|
300
|
+
return self.fail(@errorName(err));
|
|
301
|
+
};
|
|
302
|
+
journaled.db_blob_hash = hash;
|
|
303
|
+
journaled.db_blob_len = record.payload.len;
|
|
304
|
+
journaled.payload = "";
|
|
305
|
+
}
|
|
232
306
|
const payload = journal.encodeEffect(journaled, &self.effect_buffer) catch {
|
|
233
307
|
return self.fail("an effect result exceeded max_session_record_bytes");
|
|
234
308
|
};
|
|
@@ -369,6 +443,147 @@ test "recorder orders effect results before their consuming event" {
|
|
|
369
443
|
try testing.expectEqual(@as(u64, 1), end.end.effect_count);
|
|
370
444
|
}
|
|
371
445
|
|
|
446
|
+
test "recorder moves model restore snapshots into the session blob store" {
|
|
447
|
+
var buffer_sink = BufferSink{};
|
|
448
|
+
var blobs = session_blobs.MemoryBlobStore.init(testing.allocator);
|
|
449
|
+
defer blobs.deinit();
|
|
450
|
+
const recorder = try testing.allocator.create(SessionRecorder);
|
|
451
|
+
defer testing.allocator.destroy(recorder);
|
|
452
|
+
recorder.* = SessionRecorder.init(buffer_sink.sink());
|
|
453
|
+
recorder.blob_sink = blobs.sink();
|
|
454
|
+
|
|
455
|
+
recorder.begin(.{ .platform_name = "test", .app_name = "persisted" });
|
|
456
|
+
recorder.recordEffect(.{ .kind = .persist, .key = 0, .payload = "canonical model", .persist_outcome = .ok });
|
|
457
|
+
recorder.finish();
|
|
458
|
+
try testing.expect(!recorder.failed);
|
|
459
|
+
|
|
460
|
+
var reader = try journal.Reader.init(buffer_sink.bytes());
|
|
461
|
+
_ = (try reader.next()).?;
|
|
462
|
+
const effect = (try reader.next()).?.effect;
|
|
463
|
+
try testing.expectEqual(runtime_effects.EffectResultKind.persist, effect.kind);
|
|
464
|
+
try testing.expectEqual(@as(usize, 0), effect.payload.len);
|
|
465
|
+
try testing.expectEqual(@as(u64, "canonical model".len), effect.persist_blob_len);
|
|
466
|
+
var scratch: [64]u8 = undefined;
|
|
467
|
+
const restored = try blobs.read(effect.persist_blob_hash, &scratch);
|
|
468
|
+
try testing.expectEqualStrings("canonical model", restored);
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
test "recorder moves streamed file chunks into the session blob store" {
|
|
472
|
+
var buffer_sink = BufferSink{};
|
|
473
|
+
var blobs = session_blobs.MemoryBlobStore.init(testing.allocator);
|
|
474
|
+
defer blobs.deinit();
|
|
475
|
+
const recorder = try testing.allocator.create(SessionRecorder);
|
|
476
|
+
defer testing.allocator.destroy(recorder);
|
|
477
|
+
recorder.* = SessionRecorder.init(buffer_sink.sink());
|
|
478
|
+
recorder.blob_sink = blobs.sink();
|
|
479
|
+
recorder.begin(.{ .platform_name = "test", .app_name = "file-stream" });
|
|
480
|
+
recorder.recordEffect(.{
|
|
481
|
+
.kind = .file,
|
|
482
|
+
.key = 91,
|
|
483
|
+
.payload = "streamed bytes",
|
|
484
|
+
.file_op = .read_stream,
|
|
485
|
+
.file_event = .chunk,
|
|
486
|
+
.file_outcome = .ok,
|
|
487
|
+
.file_total = 14,
|
|
488
|
+
});
|
|
489
|
+
recorder.finish();
|
|
490
|
+
var reader = try journal.Reader.init(buffer_sink.bytes());
|
|
491
|
+
_ = (try reader.next()).?;
|
|
492
|
+
const effect = (try reader.next()).?.effect;
|
|
493
|
+
try testing.expectEqual(@as(usize, 0), effect.payload.len);
|
|
494
|
+
try testing.expectEqual(@as(u64, 14), effect.file_blob_len);
|
|
495
|
+
var scratch: [32]u8 = undefined;
|
|
496
|
+
try testing.expectEqualStrings("streamed bytes", try blobs.read(effect.file_blob_hash, &scratch));
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
test "recorder redacts credential bytes from journal and blob storage" {
|
|
500
|
+
const secret = "storage-tier-four-live-token";
|
|
501
|
+
const set_secret = "storage-tier-four-set-token";
|
|
502
|
+
var buffer_sink = BufferSink{};
|
|
503
|
+
var blobs = session_blobs.MemoryBlobStore.init(testing.allocator);
|
|
504
|
+
defer blobs.deinit();
|
|
505
|
+
const recorder = try testing.allocator.create(SessionRecorder);
|
|
506
|
+
defer testing.allocator.destroy(recorder);
|
|
507
|
+
recorder.* = SessionRecorder.init(buffer_sink.sink());
|
|
508
|
+
recorder.blob_sink = blobs.sink();
|
|
509
|
+
|
|
510
|
+
recorder.begin(.{
|
|
511
|
+
.platform_name = "test",
|
|
512
|
+
.app_name = "credentials",
|
|
513
|
+
.recorded_at_wall_ms = 1_723_000_000_000,
|
|
514
|
+
});
|
|
515
|
+
recorder.recordEffect(.{
|
|
516
|
+
.kind = .credentials,
|
|
517
|
+
.key = 44,
|
|
518
|
+
.payload = secret,
|
|
519
|
+
.credentials_operation = .get,
|
|
520
|
+
.credentials_outcome = .ok,
|
|
521
|
+
});
|
|
522
|
+
// Set requests are not journaled at all, but keep the result encoder
|
|
523
|
+
// defensive: if a caller ever supplies request bytes here, credential
|
|
524
|
+
// records elide them for every operation, not only successful gets.
|
|
525
|
+
recorder.recordEffect(.{
|
|
526
|
+
.kind = .credentials,
|
|
527
|
+
.key = 45,
|
|
528
|
+
.payload = set_secret,
|
|
529
|
+
.credentials_operation = .set,
|
|
530
|
+
.credentials_outcome = .ok,
|
|
531
|
+
});
|
|
532
|
+
recorder.finish();
|
|
533
|
+
try testing.expect(!recorder.failed);
|
|
534
|
+
try testing.expect(std.mem.indexOf(u8, buffer_sink.bytes(), secret) == null);
|
|
535
|
+
try testing.expect(std.mem.indexOf(u8, buffer_sink.bytes(), set_secret) == null);
|
|
536
|
+
try testing.expectEqual(@as(usize, 0), blobs.count);
|
|
537
|
+
|
|
538
|
+
var reader = try journal.Reader.init(buffer_sink.bytes());
|
|
539
|
+
_ = (try reader.next()).?;
|
|
540
|
+
const effect = (try reader.next()).?.effect;
|
|
541
|
+
try testing.expectEqual(runtime_effects.EffectResultKind.credentials, effect.kind);
|
|
542
|
+
try testing.expectEqual(runtime_effects.EffectCredentialsOperation.get, effect.credentials_operation);
|
|
543
|
+
try testing.expectEqual(runtime_effects.EffectCredentialsOutcome.ok, effect.credentials_outcome);
|
|
544
|
+
try testing.expectEqual(@as(u64, secret.len), effect.credentials_secret_len);
|
|
545
|
+
try testing.expectEqual(@as(usize, 0), effect.payload.len);
|
|
546
|
+
try testing.expect(!std.mem.allEqual(u8, &effect.credentials_salt, 0));
|
|
547
|
+
try testing.expect(!std.mem.allEqual(u8, &effect.credentials_digest, 0));
|
|
548
|
+
const set_effect = (try reader.next()).?.effect;
|
|
549
|
+
try testing.expectEqual(runtime_effects.EffectCredentialsOperation.set, set_effect.credentials_operation);
|
|
550
|
+
try testing.expectEqual(@as(usize, 0), set_effect.payload.len);
|
|
551
|
+
try testing.expectEqual(@as(u64, 0), set_effect.credentials_secret_len);
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
test "recorder spills large relational pages into the session blob store" {
|
|
555
|
+
var buffer_sink = BufferSink{};
|
|
556
|
+
var blobs = session_blobs.MemoryBlobStore.init(testing.allocator);
|
|
557
|
+
defer blobs.deinit();
|
|
558
|
+
const recorder = try testing.allocator.create(SessionRecorder);
|
|
559
|
+
defer testing.allocator.destroy(recorder);
|
|
560
|
+
recorder.* = SessionRecorder.init(buffer_sink.sink());
|
|
561
|
+
recorder.blob_sink = blobs.sink();
|
|
562
|
+
|
|
563
|
+
const page = try testing.allocator.alloc(u8, max_inline_db_page_bytes + 1);
|
|
564
|
+
defer testing.allocator.free(page);
|
|
565
|
+
@memset(page, 0x5a);
|
|
566
|
+
recorder.begin(.{ .platform_name = "test", .app_name = "relational" });
|
|
567
|
+
recorder.recordEffect(.{
|
|
568
|
+
.kind = .db,
|
|
569
|
+
.key = 73,
|
|
570
|
+
.payload = page,
|
|
571
|
+
.code = runtime_effects.dbJournalCode(.page, .ok),
|
|
572
|
+
});
|
|
573
|
+
recorder.finish();
|
|
574
|
+
try testing.expect(!recorder.failed);
|
|
575
|
+
|
|
576
|
+
var reader = try journal.Reader.init(buffer_sink.bytes());
|
|
577
|
+
_ = (try reader.next()).?;
|
|
578
|
+
const effect = (try reader.next()).?.effect;
|
|
579
|
+
try testing.expectEqual(@as(usize, 0), effect.payload.len);
|
|
580
|
+
try testing.expectEqual(@as(u64, page.len), effect.db_blob_len);
|
|
581
|
+
const scratch = try testing.allocator.alloc(u8, page.len);
|
|
582
|
+
defer testing.allocator.free(scratch);
|
|
583
|
+
const restored = try blobs.read(effect.db_blob_hash, scratch);
|
|
584
|
+
try testing.expectEqualSlices(u8, page, restored);
|
|
585
|
+
}
|
|
586
|
+
|
|
372
587
|
test "recorder commits nested events innermost-first" {
|
|
373
588
|
var buffer_sink = BufferSink{};
|
|
374
589
|
const recorder = try testing.allocator.create(SessionRecorder);
|