@native-sdk/cli 0.9.0 → 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 +331 -24
- package/build.zig +179 -11
- package/native-sdk.d.ts +8 -0
- package/package.json +10 -10
- package/packages/core/compile-surface/core.ts +70 -1
- package/packages/core/package-lock.json +11 -11
- package/packages/core/package.json +2 -2
- package/packages/core/scripts/merge_static_archives.mjs +78 -0
- package/packages/core/scripts/run_external_core_compiler.mjs +52 -7
- package/packages/core/scripts/run_external_service_compiler.mjs +53 -13
- package/packages/core/scripts/stage_external_services.mjs +1 -1
- package/packages/core/sdk/core.d.ts +75 -0
- package/packages/core/sdk/core.ts +167 -12
- package/packages/core/sdk/events.d.ts +53 -0
- package/packages/core/sdk/events.ts +78 -7
- package/packages/core/src/checker.ts +470 -2
- package/packages/core/src/cli.ts +13 -0
- package/packages/core/src/contract.ts +3 -1
- package/packages/core/src/devhost.ts +30 -1
- package/packages/core/src/devhost_journal.mjs +10 -8
- package/packages/core/src/diagnostics.ts +99 -8
- package/packages/core/src/frontend.ts +6 -0
- package/packages/core/src/infer.ts +24 -0
- package/skill-data/automation/SKILL.md +1 -1
- package/skill-data/native-ui/SKILL.md +11 -5
- package/skill-data/ts-core/SKILL.md +53 -20
- package/skill-data/ts-services/SKILL.md +4 -4
- package/skill-data/ts-services/references/service-surface.md +2 -1
- package/skill-data/zig/SKILL.md +1 -1
- package/src/app_runner/root.zig +29 -0
- package/src/app_runner/ts_core_main.zig +5 -0
- package/src/app_runner/ts_core_mobile.zig +241 -0
- package/src/automation/protocol.zig +5 -1
- package/src/automation/snapshot.zig +8 -6
- package/src/embed/app_exports.zig +1 -0
- package/src/embed/root.zig +1 -0
- package/src/embed/tests.zig +28 -0
- package/src/embed/ui_host.zig +68 -2
- package/src/platform/linux/cef_host.cpp +7 -1
- package/src/platform/linux/gtk_host.c +200 -5
- package/src/platform/linux/gtk_host.h +2 -1
- package/src/platform/linux/root.zig +69 -4
- package/src/platform/macos/appkit_host.h +11 -7
- package/src/platform/macos/appkit_host.m +210 -88
- package/src/platform/macos/cef_host.mm +210 -88
- package/src/platform/macos/root.zig +77 -30
- package/src/platform/null_platform.zig +234 -51
- package/src/platform/null_platform_tests.zig +39 -0
- package/src/platform/root.zig +10 -0
- package/src/platform/types.zig +105 -16
- package/src/platform/windows/root.zig +20 -6
- package/src/platform/windows/webview2_host.cpp +41 -5
- package/src/root.zig +7 -0
- package/src/runtime/api.zig +8 -0
- package/src/runtime/automation_commands.zig +35 -2
- package/src/runtime/automation_snapshot.zig +32 -24
- package/src/runtime/bridge_permission_tests.zig +35 -1
- package/src/runtime/bridge_responses.zig +1 -1
- package/src/runtime/builtin_bridge.zig +11 -1
- package/src/runtime/core.zig +12 -6
- package/src/runtime/effects.zig +1323 -35
- package/src/runtime/effects_file_tests.zig +587 -0
- package/src/runtime/effects_notification_tests.zig +11 -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 +21 -9
- package/src/runtime/native_command_event_tests.zig +44 -2
- package/src/runtime/pty.zig +5 -2
- package/src/runtime/root.zig +5 -0
- package/src/runtime/session_blobs.zig +4 -1
- package/src/runtime/session_journal.zig +56 -5
- package/src/runtime/session_record.zig +38 -0
- package/src/runtime/session_replay.zig +97 -7
- package/src/runtime/session_tests.zig +81 -0
- package/src/runtime/state.zig +10 -0
- package/src/runtime/system_services.zig +129 -36
- package/src/runtime/ts_core_host.zig +281 -11
- package/src/runtime/ts_core_host_tests.zig +95 -1
- package/src/runtime/ts_ui_app.zig +461 -8
- package/src/runtime/ui_app.zig +321 -109
- package/src/runtime/ui_app_tests.zig +132 -6
- package/src/runtime/ui_app_window_tests.zig +61 -7
- package/src/runtime/validation.zig +20 -0
- package/src/tooling/templates.zig +28 -0
- package/src/tooling/ts_core.zig +83 -0
- package/tools/corewire/emit.zig +3 -3
- package/tools/corewire/emit_facade.zig +65 -5
- package/tools/corewire/emit_profile.zig +2 -2
- package/tools/corewire/emit_service.zig +2 -2
- package/tools/corewire/service_contract.zig +4 -4
- package/tools/corewire/sidecar.zig +4 -4
|
@@ -185,6 +185,7 @@ fn formatLayoutDescription(comptime epoch: u32) []const u8 {
|
|
|
185
185
|
"native_command=" ++ layout_fingerprint.describe(platform.NativeCommandEvent) ++ "\n" ++
|
|
186
186
|
"menu_command=" ++ layout_fingerprint.describe(platform.MenuCommandEvent) ++ "\n" ++
|
|
187
187
|
"tray_command=" ++ layout_fingerprint.describe(platform.TrayCommandEvent) ++ "\n" ++
|
|
188
|
+
"notification_command=" ++ layout_fingerprint.describe(platform.NotificationCommandEvent) ++ "\n" ++
|
|
188
189
|
"timer=" ++ layout_fingerprint.describe(platform.TimerEvent) ++ "\n" ++
|
|
189
190
|
"audio=" ++ layout_fingerprint.describe(platform.AudioEvent) ++ "\n" ++
|
|
190
191
|
"video=" ++ layout_fingerprint.describe(platform.VideoEvent) ++ "\n" ++
|
|
@@ -466,6 +467,7 @@ const EventTag = enum(u8) {
|
|
|
466
467
|
video = 25,
|
|
467
468
|
view_focused = 26,
|
|
468
469
|
tray_command = 27,
|
|
470
|
+
notification_command = 28,
|
|
469
471
|
};
|
|
470
472
|
|
|
471
473
|
// The bit assignments below are hand-written wire layout: they are
|
|
@@ -585,9 +587,10 @@ pub fn encodeEvent(event: platform.Event, buffer: []u8) JournalError![]const u8
|
|
|
585
587
|
try cursor.writeInt(u64, message.window_id);
|
|
586
588
|
try cursor.writeStr(message.webview_label);
|
|
587
589
|
},
|
|
588
|
-
.tray_action => |
|
|
590
|
+
.tray_action => |action| {
|
|
589
591
|
try cursor.writeEnum(EventTag.tray_action);
|
|
590
|
-
try cursor.writeInt(u32,
|
|
592
|
+
try cursor.writeInt(u32, action.status_item_id);
|
|
593
|
+
try cursor.writeInt(u32, action.item_id);
|
|
591
594
|
},
|
|
592
595
|
.shortcut => |shortcut| {
|
|
593
596
|
try cursor.writeEnum(EventTag.shortcut);
|
|
@@ -611,6 +614,12 @@ pub fn encodeEvent(event: platform.Event, buffer: []u8) JournalError![]const u8
|
|
|
611
614
|
try cursor.writeEnum(EventTag.tray_command);
|
|
612
615
|
try cursor.writeStr(command.name);
|
|
613
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);
|
|
614
623
|
},
|
|
615
624
|
.timer => |timer| {
|
|
616
625
|
try cursor.writeEnum(EventTag.timer);
|
|
@@ -809,7 +818,10 @@ pub fn decodeEvent(bytes: []const u8, storage: *EventDecodeStorage) JournalError
|
|
|
809
818
|
.webview_label = webview_label,
|
|
810
819
|
} };
|
|
811
820
|
},
|
|
812
|
-
.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
|
+
} },
|
|
813
825
|
.shortcut => blk: {
|
|
814
826
|
const id = try cursor.readStr();
|
|
815
827
|
const key = try cursor.readStr();
|
|
@@ -842,6 +854,14 @@ pub fn decodeEvent(bytes: []const u8, storage: *EventDecodeStorage) JournalError
|
|
|
842
854
|
break :blk .{ .tray_command = .{
|
|
843
855
|
.name = name,
|
|
844
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),
|
|
845
865
|
} };
|
|
846
866
|
},
|
|
847
867
|
.timer => blk: {
|
|
@@ -1034,7 +1054,12 @@ pub fn encodeEffect(record: EffectResultRecord, buffer: []u8) JournalError![]con
|
|
|
1034
1054
|
try cursor.writeInt(u16, record.status);
|
|
1035
1055
|
try cursor.writeEnum(record.fetch_outcome);
|
|
1036
1056
|
try cursor.writeEnum(record.file_op);
|
|
1057
|
+
try cursor.writeEnum(record.file_event);
|
|
1037
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);
|
|
1038
1063
|
try cursor.writeEnum(record.clipboard_op);
|
|
1039
1064
|
try cursor.writeEnum(record.clipboard_outcome);
|
|
1040
1065
|
try cursor.writeInt(u64, record.timer_timestamp_ns);
|
|
@@ -1045,6 +1070,8 @@ pub fn encodeEffect(record: EffectResultRecord, buffer: []u8) JournalError![]con
|
|
|
1045
1070
|
try cursor.writeInt(u64, record.audio_duration_ms);
|
|
1046
1071
|
try cursor.writeBool(record.audio_playing);
|
|
1047
1072
|
try cursor.writeBool(record.audio_buffering);
|
|
1073
|
+
try cursor.writeBytes(&record.file_blob_hash);
|
|
1074
|
+
try cursor.writeInt(u64, record.file_blob_len);
|
|
1048
1075
|
try cursor.writeBytes(&record.audio_bands);
|
|
1049
1076
|
// v7: image terminals — outcome, decoded dimensions, and the blob
|
|
1050
1077
|
// store content address of the journaled source bytes.
|
|
@@ -1120,7 +1147,12 @@ pub fn decodeEffect(bytes: []const u8) JournalError!EffectResultRecord {
|
|
|
1120
1147
|
.status = try cursor.readInt(u16),
|
|
1121
1148
|
.fetch_outcome = try cursor.readEnum(runtime_effects.EffectFetchOutcome),
|
|
1122
1149
|
.file_op = try cursor.readEnum(runtime_effects.EffectFileOp),
|
|
1150
|
+
.file_event = try cursor.readEnum(runtime_effects.EffectFileEvent),
|
|
1123
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(),
|
|
1124
1156
|
.clipboard_op = try cursor.readEnum(runtime_effects.EffectClipboardOp),
|
|
1125
1157
|
.clipboard_outcome = try cursor.readEnum(runtime_effects.EffectClipboardOutcome),
|
|
1126
1158
|
.timer_timestamp_ns = try cursor.readInt(u64),
|
|
@@ -1132,6 +1164,8 @@ pub fn decodeEffect(bytes: []const u8) JournalError!EffectResultRecord {
|
|
|
1132
1164
|
.audio_playing = try cursor.readBool(),
|
|
1133
1165
|
.audio_buffering = try cursor.readBool(),
|
|
1134
1166
|
};
|
|
1167
|
+
@memcpy(&record.file_blob_hash, try cursor.readBytes(record.file_blob_hash.len));
|
|
1168
|
+
record.file_blob_len = try cursor.readInt(u64);
|
|
1135
1169
|
@memcpy(&record.audio_bands, try cursor.readBytes(record.audio_bands.len));
|
|
1136
1170
|
// v7: image terminals.
|
|
1137
1171
|
record.image_outcome = try cursor.readEnum(runtime_effects.EffectImageOutcome);
|
|
@@ -1636,8 +1670,14 @@ test "event codec round-trips every payload variant" {
|
|
|
1636
1670
|
try testing.expectEqual(@as(platform.WindowId, 3), decoded.tray_command.window_id);
|
|
1637
1671
|
}
|
|
1638
1672
|
{
|
|
1639
|
-
const decoded = try roundTripEvent(.{ .
|
|
1640
|
-
try testing.
|
|
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);
|
|
1641
1681
|
}
|
|
1642
1682
|
{
|
|
1643
1683
|
const decoded = try roundTripEvent(.{ .window_focused = 4 });
|
|
@@ -1676,6 +1716,17 @@ test "effect codec round-trips payloads and outcomes" {
|
|
|
1676
1716
|
try testing.expect(decoded.truncated);
|
|
1677
1717
|
try testing.expectEqual(@as(u16, 200), decoded.status);
|
|
1678
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
|
+
|
|
1679
1730
|
const exit_encoded = try encodeEffect(.{
|
|
1680
1731
|
.kind = .exit,
|
|
1681
1732
|
.key = 5,
|
|
@@ -241,6 +241,16 @@ pub const SessionRecorder = struct {
|
|
|
241
241
|
journaled.credentials_secret_len = record.payload.len;
|
|
242
242
|
}
|
|
243
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
|
+
}
|
|
244
254
|
if (record.kind == .image and record.payload.len > 0) {
|
|
245
255
|
const blob_sink = self.blob_sink orelse {
|
|
246
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)");
|
|
@@ -458,6 +468,34 @@ test "recorder moves model restore snapshots into the session blob store" {
|
|
|
458
468
|
try testing.expectEqualStrings("canonical model", restored);
|
|
459
469
|
}
|
|
460
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
|
+
|
|
461
499
|
test "recorder redacts credential bytes from journal and blob storage" {
|
|
462
500
|
const secret = "storage-tier-four-live-token";
|
|
463
501
|
const set_secret = "storage-tier-four-set-token";
|
|
@@ -178,6 +178,13 @@ pub fn replaySession(
|
|
|
178
178
|
},
|
|
179
179
|
.effect => |effect_record| {
|
|
180
180
|
var effect = effect_record;
|
|
181
|
+
if (effect.kind == .file and fileRecordDamaged(effect)) {
|
|
182
|
+
std.debug.print(
|
|
183
|
+
"replay refused after event {d}: file record for key {d} has an invalid stream/stat payload shape\n",
|
|
184
|
+
.{ report.events_replayed, effect.key },
|
|
185
|
+
);
|
|
186
|
+
return error.ReplayDamagedRecord;
|
|
187
|
+
}
|
|
181
188
|
// A `.loaded` image record ALWAYS names source bytes:
|
|
182
189
|
// the recorder journals `.loaded` only after those
|
|
183
190
|
// exact bytes decoded and registered (a failed decode
|
|
@@ -362,6 +369,16 @@ pub fn replaySession(
|
|
|
362
369
|
};
|
|
363
370
|
effect.payload = bytes;
|
|
364
371
|
}
|
|
372
|
+
if (effect.kind == .file and effect.file_blob_len > 0) {
|
|
373
|
+
const bytes = resolveBlob(effect.file_blob_hash, effect.file_blob_len, runtime_effects.effect_file_stream_chunk_bytes, options.blobs, &blob_scratch) catch |err| {
|
|
374
|
+
std.debug.print(
|
|
375
|
+
"replay refused after event {d}: file stream for key {d} references blob {s} ({d} bytes) that could not be resolved ({s})\n",
|
|
376
|
+
.{ report.events_replayed, effect.key, session_blobs.hexName(effect.file_blob_hash), effect.file_blob_len, @errorName(err) },
|
|
377
|
+
);
|
|
378
|
+
return error.ReplayMissingBlob;
|
|
379
|
+
};
|
|
380
|
+
effect.payload = bytes;
|
|
381
|
+
}
|
|
365
382
|
if (effect.kind == .image and effect.image_blob_len > 0) {
|
|
366
383
|
const bytes = resolveBlob(effect.image_blob_hash, effect.image_blob_len, runtime_effects.max_effect_image_bytes, options.blobs, &blob_scratch) catch |err| {
|
|
367
384
|
std.debug.print(
|
|
@@ -592,6 +609,25 @@ fn dbRecordDamaged(record: journal.EffectResultRecord) bool {
|
|
|
592
609
|
};
|
|
593
610
|
}
|
|
594
611
|
|
|
612
|
+
fn fileRecordDamaged(record: journal.EffectResultRecord) bool {
|
|
613
|
+
if (record.file_rejected_admission) switch (record.file_outcome) {
|
|
614
|
+
.rejected => {},
|
|
615
|
+
.sink_missing, .out_of_order => if (record.file_op != .write_stream_chunk and record.file_op != .write_stream_close) return true,
|
|
616
|
+
else => return true,
|
|
617
|
+
};
|
|
618
|
+
if (record.file_blob_len > runtime_effects.effect_file_stream_chunk_bytes) return true;
|
|
619
|
+
if (record.file_event == .chunk) {
|
|
620
|
+
return record.file_op != .read_stream or record.file_outcome != .ok or
|
|
621
|
+
record.payload.len != 0 or record.file_blob_len == 0;
|
|
622
|
+
}
|
|
623
|
+
if (record.file_blob_len != 0) return true;
|
|
624
|
+
if (record.file_event == .done) {
|
|
625
|
+
return record.file_op != .read_stream or record.file_outcome != .ok or record.payload.len != 0;
|
|
626
|
+
}
|
|
627
|
+
if (record.file_op == .stat and record.file_outcome == .ok) return record.payload.len != 0;
|
|
628
|
+
return record.file_total != 0 or record.file_mtime_ms != 0 or record.file_exists;
|
|
629
|
+
}
|
|
630
|
+
|
|
595
631
|
fn credentialsRecordDamaged(record: journal.EffectResultRecord) bool {
|
|
596
632
|
if (record.payload.len != 0 or record.exit_reason != .exited) return true;
|
|
597
633
|
const redacted_get = record.credentials_operation == .get and record.credentials_outcome == .ok;
|
|
@@ -731,15 +767,13 @@ fn effectRegeneratesUnderReplay(record: journal.EffectResultRecord) bool {
|
|
|
731
767
|
return switch (record.kind) {
|
|
732
768
|
.timer => true,
|
|
733
769
|
.exit => record.exit_reason == .rejected,
|
|
734
|
-
// Only DETERMINISTIC admission
|
|
735
|
-
//
|
|
736
|
-
//
|
|
737
|
-
//
|
|
738
|
-
// are external inputs and must be fed, even when their reason
|
|
739
|
-
// is `.rejected`.
|
|
770
|
+
// Only DETERMINISTIC admission/protocol results regenerate — marked
|
|
771
|
+
// by each effect family's provenance bit. Executor-truth terminals —
|
|
772
|
+
// start failures, platform refusals, output, and real exits — are
|
|
773
|
+
// external inputs and must be fed, even when their reason is rejected.
|
|
740
774
|
.pty => record.pty_kind == .exit and record.truncated,
|
|
741
775
|
.response => record.fetch_outcome == .rejected,
|
|
742
|
-
.file => record.
|
|
776
|
+
.file => record.file_rejected_admission,
|
|
743
777
|
.clipboard => record.clipboard_outcome == .rejected,
|
|
744
778
|
// Audio rejections are loop-side validation (path bounds) that
|
|
745
779
|
// refuses again; everything else — loaded acknowledgments,
|
|
@@ -791,6 +825,62 @@ fn effectRegeneratesUnderReplay(record: journal.EffectResultRecord) bool {
|
|
|
791
825
|
};
|
|
792
826
|
}
|
|
793
827
|
|
|
828
|
+
test "only admission-tagged file results regenerate" {
|
|
829
|
+
try std.testing.expect(effectRegeneratesUnderReplay(.{
|
|
830
|
+
.kind = .file,
|
|
831
|
+
.key = 1,
|
|
832
|
+
.file_outcome = .rejected,
|
|
833
|
+
.file_rejected_admission = true,
|
|
834
|
+
}));
|
|
835
|
+
try std.testing.expect(!fileRecordDamaged(.{
|
|
836
|
+
.kind = .file,
|
|
837
|
+
.key = 2,
|
|
838
|
+
.file_op = .write_stream_chunk,
|
|
839
|
+
.file_outcome = .sink_missing,
|
|
840
|
+
.file_rejected_admission = true,
|
|
841
|
+
}));
|
|
842
|
+
try std.testing.expect(fileRecordDamaged(.{
|
|
843
|
+
.kind = .file,
|
|
844
|
+
.key = 2,
|
|
845
|
+
.file_op = .write_stream_chunk,
|
|
846
|
+
.file_outcome = .ok,
|
|
847
|
+
.file_rejected_admission = true,
|
|
848
|
+
}));
|
|
849
|
+
try std.testing.expect(!effectRegeneratesUnderReplay(.{
|
|
850
|
+
.kind = .file,
|
|
851
|
+
.key = 1,
|
|
852
|
+
.file_op = .read_stream,
|
|
853
|
+
.file_outcome = .rejected,
|
|
854
|
+
}));
|
|
855
|
+
try std.testing.expect(effectRegeneratesUnderReplay(.{
|
|
856
|
+
.kind = .file,
|
|
857
|
+
.key = 2,
|
|
858
|
+
.file_op = .write_stream_chunk,
|
|
859
|
+
.file_outcome = .sink_missing,
|
|
860
|
+
.file_rejected_admission = true,
|
|
861
|
+
}));
|
|
862
|
+
try std.testing.expect(effectRegeneratesUnderReplay(.{
|
|
863
|
+
.kind = .file,
|
|
864
|
+
.key = 3,
|
|
865
|
+
.file_op = .write_stream_close,
|
|
866
|
+
.file_outcome = .out_of_order,
|
|
867
|
+
.file_rejected_admission = true,
|
|
868
|
+
}));
|
|
869
|
+
try std.testing.expect(!fileRecordDamaged(.{
|
|
870
|
+
.kind = .file,
|
|
871
|
+
.key = 4,
|
|
872
|
+
.file_op = .write_stream_chunk,
|
|
873
|
+
.file_outcome = .ok,
|
|
874
|
+
}));
|
|
875
|
+
try std.testing.expect(fileRecordDamaged(.{
|
|
876
|
+
.kind = .file,
|
|
877
|
+
.key = 4,
|
|
878
|
+
.file_op = .write_stream_chunk,
|
|
879
|
+
.file_outcome = .ok,
|
|
880
|
+
.file_total = 1,
|
|
881
|
+
}));
|
|
882
|
+
}
|
|
883
|
+
|
|
794
884
|
/// Re-render a journaled screenshot mark through the same deterministic
|
|
795
885
|
/// reference renderer the automation `screenshot` verb used at record
|
|
796
886
|
/// time, and hash the PNG.
|
|
@@ -1448,6 +1448,8 @@ const ImageSessionModel = struct {
|
|
|
1448
1448
|
exits: u32 = 0,
|
|
1449
1449
|
exits_rejected: u32 = 0,
|
|
1450
1450
|
files: u32 = 0,
|
|
1451
|
+
stream_bytes: u64 = 0,
|
|
1452
|
+
stream_done: bool = false,
|
|
1451
1453
|
/// Armed by `.arm_fetch_chain` / `.arm_file_chain`: the NEXT
|
|
1452
1454
|
/// terminal of that family answers by reissuing the SAME key from
|
|
1453
1455
|
/// inside its own update (one-shot) — the poll/reload idiom whose
|
|
@@ -1475,6 +1477,7 @@ const ImageSessionMsg = union(enum) {
|
|
|
1475
1477
|
fetch_cover,
|
|
1476
1478
|
spawn_cover,
|
|
1477
1479
|
read_note,
|
|
1480
|
+
stream_note,
|
|
1478
1481
|
line: effects_mod.EffectLine,
|
|
1479
1482
|
image: effects_mod.EffectImageResult,
|
|
1480
1483
|
response: effects_mod.EffectResponse,
|
|
@@ -1519,6 +1522,7 @@ fn imageSessionUpdate(model: *ImageSessionModel, msg: ImageSessionMsg, fx: *Imag
|
|
|
1519
1522
|
// A file read on its own key (26 — never colliding with the
|
|
1520
1523
|
// image/fetch/spawn probes above).
|
|
1521
1524
|
.read_note => fx.readFile(.{ .key = 26, .path = "notes/session.txt", .on_result = ImageSessionApp.Effects.fileMsg(.file) }),
|
|
1525
|
+
.stream_note => fx.readFileStream(.{ .key = 27, .path = "notes/large.bin", .on_result = ImageSessionApp.Effects.fileMsg(.file) }),
|
|
1522
1526
|
// Aimed at the cover's id: against a running load this marks
|
|
1523
1527
|
// it cancelled; against a staged start-failure rejection (no
|
|
1524
1528
|
// slot exists) it is a no-op and the rejection stands.
|
|
@@ -1547,6 +1551,10 @@ fn imageSessionUpdate(model: *ImageSessionModel, msg: ImageSessionMsg, fx: *Imag
|
|
|
1547
1551
|
},
|
|
1548
1552
|
.file => |result| {
|
|
1549
1553
|
model.files += 1;
|
|
1554
|
+
if (result.op == .read_stream) {
|
|
1555
|
+
if (result.event == .chunk) model.stream_bytes += result.bytes.len;
|
|
1556
|
+
if (result.event == .done) model.stream_done = true;
|
|
1557
|
+
}
|
|
1550
1558
|
// The armed reload idiom, the fetch chain's file twin.
|
|
1551
1559
|
if (model.chain_next_file and result.key == 26) {
|
|
1552
1560
|
model.chain_next_file = false;
|
|
@@ -1590,6 +1598,7 @@ fn imageSessionView(ui: *ImageSessionApp.Ui, model: *const ImageSessionModel) Im
|
|
|
1590
1598
|
ui.text(.{}, ui.fmt("{d} lines, {d} before image", .{ model.lines_seen, model.lines_before_image })),
|
|
1591
1599
|
ui.text(.{}, ui.fmt("{d}/{d} responses, {d}/{d} exits rejected", .{ model.responses_rejected, model.responses, model.exits_rejected, model.exits })),
|
|
1592
1600
|
ui.text(.{}, ui.fmt("{d} files", .{model.files})),
|
|
1601
|
+
ui.text(.{}, ui.fmt("stream {d} done {}", .{ model.stream_bytes, model.stream_done })),
|
|
1593
1602
|
});
|
|
1594
1603
|
}
|
|
1595
1604
|
|
|
@@ -1604,6 +1613,7 @@ fn imageSessionCommand(name: []const u8) ?ImageSessionMsg {
|
|
|
1604
1613
|
if (std.mem.eql(u8, name, "image.fetch-chain")) return .arm_fetch_chain;
|
|
1605
1614
|
if (std.mem.eql(u8, name, "image.file-chain")) return .arm_file_chain;
|
|
1606
1615
|
if (std.mem.eql(u8, name, "image.read-note")) return .read_note;
|
|
1616
|
+
if (std.mem.eql(u8, name, "image.stream-note")) return .stream_note;
|
|
1607
1617
|
if (std.mem.eql(u8, name, "image.cancel")) return .cancel_cover;
|
|
1608
1618
|
if (std.mem.eql(u8, name, "image.chatty")) return .start_chatty;
|
|
1609
1619
|
if (std.mem.eql(u8, name, "image.fetch-cover")) return .fetch_cover;
|
|
@@ -2522,6 +2532,77 @@ test "a same-key retry from a fetch or file terminal handler is accepted live an
|
|
|
2522
2532
|
try std.testing.expectEqual(recorded.fingerprint, harness.runtime.sessionStateFingerprint());
|
|
2523
2533
|
}
|
|
2524
2534
|
|
|
2535
|
+
test "a multi-megabyte file stream records through blobs and replays byte-identically" {
|
|
2536
|
+
const gpa = std.testing.allocator;
|
|
2537
|
+
const buffer = try std.heap.page_allocator.create(JournalBuffer);
|
|
2538
|
+
defer std.heap.page_allocator.destroy(buffer);
|
|
2539
|
+
buffer.len = 0;
|
|
2540
|
+
var store = session_blobs.MemoryBlobStore.init(gpa);
|
|
2541
|
+
defer store.deinit();
|
|
2542
|
+
|
|
2543
|
+
const recorder = try std.heap.page_allocator.create(session_record.SessionRecorder);
|
|
2544
|
+
defer std.heap.page_allocator.destroy(recorder);
|
|
2545
|
+
recorder.* = session_record.SessionRecorder.init(buffer.sink());
|
|
2546
|
+
recorder.blob_sink = store.sink();
|
|
2547
|
+
recorder.begin(.{ .platform_name = "test", .app_name = "file-stream-session", .window_width = 400, .window_height = 300 });
|
|
2548
|
+
|
|
2549
|
+
const harness = try core.TestHarness().create(gpa, .{ .size = geometry.SizeF.init(400, 300) });
|
|
2550
|
+
defer harness.destroy(gpa);
|
|
2551
|
+
harness.null_platform.gpu_surfaces = true;
|
|
2552
|
+
harness.runtime.options.session_recorder = recorder;
|
|
2553
|
+
const app_state = try gpa.create(ImageSessionApp);
|
|
2554
|
+
defer gpa.destroy(app_state);
|
|
2555
|
+
app_state.* = ImageSessionApp.init(std.heap.page_allocator, .{}, imageSessionOptions());
|
|
2556
|
+
defer app_state.deinit();
|
|
2557
|
+
app_state.effects.executor = .fake;
|
|
2558
|
+
const app = app_state.app();
|
|
2559
|
+
try harness.start(app);
|
|
2560
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .gpu_surface_frame = .{
|
|
2561
|
+
.label = image_canvas_label,
|
|
2562
|
+
.size = geometry.SizeF.init(400, 300),
|
|
2563
|
+
.scale_factor = 1,
|
|
2564
|
+
.frame_index = 1,
|
|
2565
|
+
.timestamp_ns = 1_000_000,
|
|
2566
|
+
} });
|
|
2567
|
+
try harness.runtime.dispatchPlatformEvent(app, .{ .menu_command = .{ .name = "image.stream-note", .window_id = 1 } });
|
|
2568
|
+
const stream_key: u64 = 27;
|
|
2569
|
+
const chunk = try gpa.alloc(u8, effects_mod.effect_file_stream_chunk_bytes);
|
|
2570
|
+
defer gpa.free(chunk);
|
|
2571
|
+
var total: u64 = 0;
|
|
2572
|
+
for (0..5) |chunk_index| {
|
|
2573
|
+
for (chunk, 0..) |*byte, index| byte.* = @truncate(index + chunk_index * 17);
|
|
2574
|
+
total += chunk.len;
|
|
2575
|
+
try app_state.effects.feedFileResultDetailed(.{ .key = stream_key, .op = .read_stream, .event = .chunk, .outcome = .ok, .bytes = chunk, .total = total });
|
|
2576
|
+
try harness.runtime.dispatchPlatformEvent(app, .wake);
|
|
2577
|
+
}
|
|
2578
|
+
try std.testing.expect(total > effects_mod.max_effect_file_bytes);
|
|
2579
|
+
try app_state.effects.feedFileResultDetailed(.{ .key = stream_key, .op = .read_stream, .event = .done, .outcome = .ok, .total = total });
|
|
2580
|
+
try harness.runtime.dispatchPlatformEvent(app, .wake);
|
|
2581
|
+
try harness.runtime.dispatchPlatformEvent(app, .frame_requested);
|
|
2582
|
+
recorder.finish();
|
|
2583
|
+
try std.testing.expect(!recorder.failed);
|
|
2584
|
+
try std.testing.expectEqual(@as(usize, 5), store.count);
|
|
2585
|
+
const recorded_model = app_state.model;
|
|
2586
|
+
const recorded_fingerprint = harness.runtime.sessionStateFingerprint();
|
|
2587
|
+
|
|
2588
|
+
const replay_harness = try core.TestHarness().create(gpa, .{ .size = geometry.SizeF.init(400, 300) });
|
|
2589
|
+
defer replay_harness.destroy(gpa);
|
|
2590
|
+
replay_harness.null_platform.gpu_surfaces = true;
|
|
2591
|
+
const replay_app = try gpa.create(ImageSessionApp);
|
|
2592
|
+
defer gpa.destroy(replay_app);
|
|
2593
|
+
replay_app.* = ImageSessionApp.init(std.heap.page_allocator, .{}, imageSessionOptions());
|
|
2594
|
+
defer replay_app.deinit();
|
|
2595
|
+
const report = try session_replay.replaySession(&replay_harness.runtime, replay_app.app(), buffer.journalBytes(), .{
|
|
2596
|
+
.verify = true,
|
|
2597
|
+
.require_same_platform = false,
|
|
2598
|
+
.blobs = store.source(),
|
|
2599
|
+
});
|
|
2600
|
+
try std.testing.expect(report.ok());
|
|
2601
|
+
try std.testing.expectEqual(@as(u64, 6), report.effects_fed);
|
|
2602
|
+
try std.testing.expectEqualDeep(recorded_model, replay_app.model);
|
|
2603
|
+
try std.testing.expectEqual(recorded_fingerprint, replay_harness.runtime.sessionStateFingerprint());
|
|
2604
|
+
}
|
|
2605
|
+
|
|
2525
2606
|
/// Record the queue-saturation reference session: a chatty spawn and
|
|
2526
2607
|
/// an image load whose results journal as ONE unbroken run — 64 line
|
|
2527
2608
|
/// records (the completion queue's whole capacity) followed by the
|
package/src/runtime/state.zig
CHANGED
|
@@ -88,6 +88,16 @@ pub const RuntimeTrayItem = struct {
|
|
|
88
88
|
key_storage: [platform.max_menu_key_bytes]u8 = undefined,
|
|
89
89
|
};
|
|
90
90
|
|
|
91
|
+
pub const RuntimeStatusItem = struct {
|
|
92
|
+
id: platform.StatusItemId = 0,
|
|
93
|
+
active: bool = false,
|
|
94
|
+
visible: bool = true,
|
|
95
|
+
title: []const u8 = "",
|
|
96
|
+
title_storage: [platform.max_tray_title_bytes]u8 = undefined,
|
|
97
|
+
items: [platform.max_tray_items]RuntimeTrayItem = undefined,
|
|
98
|
+
item_count: usize = 0,
|
|
99
|
+
};
|
|
100
|
+
|
|
91
101
|
pub const ShellApplyMode = enum {
|
|
92
102
|
create,
|
|
93
103
|
update,
|