╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ try.zig ──────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
449 .{ 450 .title = "Support environment variable expansion in config paths", 451 .description = "Paths in the config file are taken literally, so shared configs can't refer to the home directory portably. Expand environment variables when loading.", 452 .tags = "enhancement config", 453 }, 454 .{ 455 .title = "Log rotation deletes the newest file instead of the oldest", 456 .description = "When the log directory hits its size cap, the rotation logic sorts by name rather than mtime and removes the most recent log. Sort by modification time.", 457 .tags = "bug logging", 458 .status = .closed, 459 }, 460 .{ 461 .title = "Add man pages for all subcommands", 462 .description = "Only the top-level command has a man page. Generate one per subcommand from the existing help text as part of the release build.", 463 .tags = "documentation cli", 464 }, 465 .{ 466 .title = "High CPU usage while idle in the background", 467 .description = "The main loop polls for file changes every 10 ms even when no window is visible. Switch to native file watching and idle at zero CPU.", 468 .tags = "performance priority-high", 469 }, 470 .{ 471 .title = "Paste from clipboard drops the final newline", 472 .description = "Pasting text that ends with a newline silently trims it, which breaks pasted shell snippets. Preserve the clipboard content exactly.", 473 .tags = "bug editor clipboard", 474 }, 475 .{ 476 .title = "Improve error message for expired credentials", 477 .description = "An expired token currently surfaces as a bare 401 with no guidance. Detect the expiry case and tell the user how to re-authenticate.", 478 .tags = "enhancement ux auth", 479 }, 480 .{ 481 .title = "Crash when window is resized during startup animation", 482 .description = "Resizing the window while the splash animation is running dereferences a freed layout node. Cancel the animation before rebuilding the layout.", 483 .tags = "bug crash ui", 484 }, 485 .{ 486 .title = "Add integration tests for the sync engine", 487 .description = "The sync engine only has unit tests with mocked transports. Add end-to-end tests that run two instances against a real local server.", 488 .tags = "testing sync", 489 }, 490 .{ 491 .title = "Timestamps display in UTC instead of local time", 492 .description = "All timestamps in the activity feed render in UTC regardless of the system timezone. Convert to local time and include the offset in tooltips.", 493 .tags = "bug i18n time", 494 }, 495 .{ 496 .title = "Deprecate the legacy plugin format", 497 .description = "Both plugin formats are currently loaded, doubling the maintenance surface. Warn on legacy plugins this release and drop support in the next.", 498 .tags = "maintenance plugins", 499 }, 500 }; 501 502 var issue_events: [issue_data.len]evt.EventWithId = undefined; 503 for (issue_data, 0..) |issue, i| { 504 issue_events[i] = .{ 505 .id = std.fmt.bytesToHex(evt.EventWithId.randomId(prng.random()), .lower), 506 // stepped timestamps so the issues list in a stable order 507 .timestamp = @intCast(i + 1), 508 .event = .{ 509 .issue = .{ 510 .title = issue.title, 511 .description = issue.description, 512 .tags = issue.tags, 513 .status = issue.status, 514 }, 515 }, 516 }; 517 } 518 try evt.commitAndConsume(.xit, .{}, io, allocator, &template_repo, evt.events_ref, &issue_events); 519 } 520 521 // copy the template to each repo's on-disk location, named by its 522 // hex-encoded event id. the template repo is deinitialized above, so its 523 // db file is fully written before we copy it. 524 { 525 var template_dir = try cwd.openDir(io, template_path, .{ .iterate = true }); 526 defer template_dir.close(io); 527 528 for (repo_event_ids) |id_bytes| { 529 const repo_id = std.fmt.bytesToHex(id_bytes, .lower); 530 const repo_path = try std.fs.path.join(arena.allocator(), &.{ cwd_path, temp_dir_name, "server", "repos", &repo_id }); 531 var dest_dir = try cwd.createDirPathOpen(io, repo_path, .{}); 532 defer dest_dir.close(io); 533 try copyDir(io, template_dir, dest_dir); 534 } 535 } 536 537 break :blk try ui.Session.init(&session_arena, &repo, .{}); 538 }; 539 session.is_terminal = true; 540 // try uses the default serve options below, so the footer's url points at 541 // the default web UI port. 542 session.web_port = try (srv.Options{}).wuiPort(); 543 544 // start the server 545 546 var cli = false; 547 548 var arg_it = try init.minimal.args.iterateAllocator(allocator); 549 defer arg_it.deinit(); 550 _ = arg_it.skip(); 551 while (arg_it.next()) |arg| { 552 if (std.mem.eql(u8, "--cli", arg)) { 553 cli = true; 554 } 555 } 556 557 const server_path = try std.fs.path.join(allocator, &.{ cwd_path, temp_dir_name, "server" }); 558 defer allocator.free(server_path); 559 560 // let the native TUI's page builders open the on-disk repos for the file tree 561 session.io = io; 562 session.repos_dir = try std.fs.path.join(session_arena.allocator(), &.{ server_path, "repos" }); 563 564 if (cli) { 565 var stdout_writer = std.Io.File.stdout().writer(io, &.{}); 566 var stderr_writer = std.Io.File.stderr().writer(io, &.{}); 567 const run_opts = hx.main.RunOpts{ .out = &stdout_writer.interface, .err = &stderr_writer.interface }; 568 569 const key_path = try std.fs.path.join(allocator, &.{ cwd_path, temp_dir_name, "key" }); 570 defer allocator.free(key_path); 571 572 const Runnable = struct { 573 io: std.Io, 574 key_path: []const u8, 575 576 pub fn run(self: @This()) !void { 577 std.debug.print( 578 \\ 579 \\connect to the TUI with: 580 \\ ssh -p 8022 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null localhost 581 \\ 582 \\create a git repo and push over SSH: 583 \\ mkdir -p temp-try/client/test 584 \\ cd temp-try/client/test 585 \\ git init 586 \\ echo "hello" > hello.txt 587 \\ git add hello.txt 588 \\ git commit -m "let there be light" 589 \\ GIT_SSH_COMMAND='ssh -p 8022 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes -i {s}' git push localhost:admin/test HEAD:master 590 \\ 591 \\to quit, press enter. 592 \\ 593 , .{self.key_path}); 594 // portable stdin read via std.Io — equivalent to the 595 // std.posix.read(STDIN_FILENO, ...) that doesn't compile 596 // on windows. 597 var buf: [1]u8 = undefined; 598 var stdin_reader = std.Io.File.stdin().reader(self.io, &buf); 599 _ = stdin_reader.interface.takeByte() catch {}; 600 } 601 }; 602 603 try srv.run(.xit, .{}, io, allocator, cwd_path, .{ 604 .data_dir = server_path, 605 }, run_opts.err, Runnable{ .io = io, .key_path = key_path }); 606 } else { 607 var null_writer = std.Io.Writer.Discarding.init(&.{}); 608 const run_opts = hx.main.RunOpts{ .out = &null_writer.writer, .err = &null_writer.writer }; 609 610 const Runnable = struct { 611 io: std.Io, 612 allocator: std.mem.Allocator, 613 session: *ui.Session, 614 repo: *Repo, 615 616 pub fn run(self: @This()) !void { 617 // launch the TUI 618 try hx.ui.run(self.io, self.allocator, self.session, self.repo); 619 } 620 }; 621 622 try srv.run(.xit, .{}, io, allocator, cwd_path, .{ 623 .data_dir = server_path, 624 }, run_opts.err, Runnable{ .io = io, .allocator = allocator, .session = &session, .repo = &repo }); 625 } 626 } 627 628 // words cycled through to pad generated lines into prose-like content 629 const scatter_words = [_][]const u8{ 630 "lorem", "ipsum", "dolor", "sit", "amet", "consectetur", 631 "quantum", "vector", "matrix", "buffer", "kernel", "socket", 632 "falcon", "otter", "badger", "walrus", "ferret", "marmot", 633 "scatter", "gather", "encode", "decode", "render", "commit", 634 }; 635 636 // write `path` as 40 lines of mostly-stable filler. revision `c` and file 637 // index `fi` shift which lines change and the words used, so each (c, fi) 638 // yields a distinct multi-hunk diff against the previous revision. untouched 639 // lines stay byte-identical across revisions, so a bump in `c` is a scatter of 640 // small hunks rather than a full rewrite. 641 fn writeScatterFile(io: std.Io, allocator: std.mem.Allocator, repo_dir: std.Io.Dir, path: []const u8, fi: usize, c: usize) !void { 642 const file = try repo_dir.createFile(io, path, .{}); 643 defer file.close(io); 644 var writer = std.Io.Writer.Allocating.init(allocator); 645 defer writer.deinit(); 646 for (0..40) |line| { 647 const start = writer.written().len; 648 if ((line + fi + c) % 8 == 0) { 649 const tag = scatter_words[(line + fi + c * 3) % scatter_words.len]; 650 try writer.writer.print("rev {d} {s}", .{ c, tag }); 651 } 652 const target = 40 + (line * 17 + fi * 23) % 70; 653 var w = line + fi; 654 while (true) : (w += 1) { 655 const word = scatter_words[w % scatter_words.len]; 656 const len = writer.written().len - start; 657 if (len >= target or len + 1 + word.len > 120) break; 658 if (len == 0) 659 try writer.writer.print("{s}", .{word}) 660 else 661 try writer.writer.print(" {s}", .{word}); 662 } 663 try writer.writer.writeByte('\n'); 664 } 665 try file.writeStreamingAll(io, writer.written()); 666 } 667 668 // tag the current HEAD as the next sequential version: v1, v2, and so on 669 fn addNextTag(repo: *rp.Repo(.xit, .{}), io: std.Io, allocator: std.mem.Allocator, n: *usize) !void { 670 var buf: [16]u8 = undefined; 671 const name = try std.fmt.bufPrint(&buf, "v{d}", .{n.*}); 672 _ = try repo.addTag(io, allocator, .{ .name = name }); 673 n.* += 1; 674 } 675 676 // recursively copy the contents of src_dir into dest_dir 677 fn copyDir(io: std.Io, src_dir: std.Io.Dir, dest_dir: std.Io.Dir) !void { 678 var iter = src_dir.iterate(); 679 while (try iter.next(io)) |entry| { 680 switch (entry.kind) { 681 .file => try src_dir.copyFile(entry.name, dest_dir, entry.name, io, .{}), 682 .directory => { 683 try dest_dir.createDirPath(io, entry.name); 684 var dest_entry_dir = try dest_dir.openDir(io, entry.name, .{ .access_sub_paths = true, .iterate = true, .follow_symlinks = false }); 685 defer dest_entry_dir.close(io); 686 var src_entry_dir = try src_dir.openDir(io, entry.name, .{ .access_sub_paths = true, .iterate = true, .follow_symlinks = false }); 687 defer src_entry_dir.close(io); 688 try copyDir(io, src_entry_dir, dest_entry_dir); 689 }, 690 else => {}, 691 } 692 } 693 } 694