Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ jobs:

- name: Install Zig
run: |
curl -sL "https://ziglang.org/download/0.15.2/zig-x86_64-linux-0.15.2.tar.xz" | tar -xJ
echo "$PWD/zig-x86_64-linux-0.15.2" >> "$GITHUB_PATH"
curl -sL "https://ziglang.org/download/0.16.0/zig-x86_64-linux-0.16.0.tar.xz" | tar -xJ
echo "$PWD/zig-x86_64-linux-0.16.0" >> "$GITHUB_PATH"

- name: Format check
continue-on-error: true
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.zig-cache/
zig-out/
zig-pkg/
5 changes: 3 additions & 2 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
.name = .sshz,
.version = "0.1.0",
.fingerprint = 0x138d7fea3306d410,
.minimum_zig_version = "0.16.0",
.paths = .{ "build.zig", "build.zig.zon", "src" },
.dependencies = .{
.zigzag = .{
.url = "https://github.com/meszmate/zigzag/archive/refs/tags/v0.1.2.tar.gz",
.hash = "zigzag-0.1.0-YXwYS20gCwATYmA0IOAYQVHykNP--Dl7bKfp2UDE0K2I",
.url = "https://github.com/meszmate/zigzag/archive/refs/tags/v0.1.5.tar.gz",
.hash = "zigzag-0.1.2-YXwYS17aEQBlpxPETTrhY5leFh7vV0DpnXJbHogs4Lsv",
Comment on lines +9 to +10

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: The dependency hash does not match the updated v0.1.5 tarball URL (it is still the old v0.1.2 hash), so Zig will reject this dependency during fetch/resolve and the project will fail to build. Regenerate and commit the correct hash for the v0.1.5 archive. [possible bug]

Severity Level: Critical 🚨
- ❌ `zig build` fails resolving zigzag v0.1.5 dependency.
- ❌ Main TUI binary using zigzag cannot be built.
- ⚠️ CI build pipeline fails at dependency resolution step.
Steps of Reproduction ✅
1. Install Zig 0.16.0 and clone the repository containing `build.zig` and `build.zig.zon`
(dependency config at `build.zig.zon:7-11` shows `zigzag` URL v0.1.5 with hash
`zigzag-0.1.2-...`).

2. From the repo root (`/workspace/sshz`), run `zig build` which loads `build.zig.zon` and
then executes `b.dependency("zigzag", .{ ... })` at `build.zig:7`.

3. The Zig package manager fetches
`https://github.com/meszmate/zigzag/archive/refs/tags/v0.1.5.tar.gz` using the hash from
`build.zig.zon:10` (`zigzag-0.1.2-YXwY...`).

4. Observe Zig abort the build with a dependency hash mismatch error (the stored v0.1.2
hash does not match the v0.1.5 tarball), so no build targets (including the main TUI in
`src/main.zig`) are produced.

Fix in Cursor | Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** build.zig.zon
**Line:** 9:10
**Comment:**
	*Possible Bug: The dependency hash does not match the updated `v0.1.5` tarball URL (it is still the old `v0.1.2` hash), so Zig will reject this dependency during fetch/resolve and the project will fail to build. Regenerate and commit the correct hash for the `v0.1.5` archive.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

検証しました。この指摘は false positive です (4スレッド共通の返信)。

手元の Zig 0.16.0 で zig fetch --save=zigzag https://github.com/meszmate/zigzag/archive/refs/tags/v0.1.5.tar.gz を実行した結果、得られたハッシュは現状の build.zig.zon の値と完全一致しました:

zigzag-0.1.2-YXwYS17aEQBlpxPETTrhY5leFh7vV0DpnXJbHogs4Lsv

ハッシュの prefix zigzag-0.1.2- は 上流 zigzag の v0.1.5 タグ内 build.zig.zon の .version field がまだ "0.1.2" のまま であることに由来しており、Zig パッケージマネージャはこの内部 version を prefix に採用する仕様です (CodeRabbit のスクリプト調査結果と一致)。URL の v0.1.5 と内部 version 0.1.2 の不一致は上流側のメンテナンス問題であって、ハッシュ自体は正しい値です。

zig build および zig build test は Zig 0.16.0 で問題なく成功します。

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Customized review instruction saved!

Instruction:

Do not flag Zig dependency hashes as incorrect solely because the hash prefix version differs from the tarball URL; verify the full hash value against zig fetch/build behavior before reporting a mismatch.

Applied to:

  • **/*.zon

💡 To manage or update this instruction, visit: CodeAnt AI Settings

Comment on lines +9 to +10

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Architect Review — CRITICAL

The zigzag dependency URL was bumped to v0.1.5 while the hash still targets the v0.1.2 artifact, so Zig's package manager will reject the dependency and zig build will fail in normal workflows.

Suggestion: Regenerate and commit the correct hash for zigzag v0.1.5 using a Zig 0.16 toolchain (for example, zig fetch --save=zigzag <v0.1.5 url>) so the recorded hash matches the new URL.

Fix in Cursor | Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is an **Architect / Logical Review** comment left during a code review. These reviews are first-class, important findings — not optional suggestions. Do NOT dismiss this as a 'big architectural change' just because the title says architect review; most of these can be resolved with a small, localized fix once the intent is understood.

**Path:** build.zig.zon
**Line:** 9:10
**Comment:**
	*CRITICAL: The zigzag dependency URL was bumped to v0.1.5 while the hash still targets the v0.1.2 artifact, so Zig's package manager will reject the dependency and `zig build` will fail in normal workflows.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
If a suggested approach is provided above, use it as the authoritative instruction. If no explicit code suggestion is given, you MUST still draft and apply your own minimal, localized fix — do not punt back with 'no suggestion provided, review manually'. Keep the change as small as possible: add a guard clause, gate on a loading state, reorder an await, wrap in a conditional, etc. Do not refactor surrounding code or expand scope beyond the finding.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

検証しました。この指摘は false positive です (4スレッド共通の返信)。

手元の Zig 0.16.0 で zig fetch --save=zigzag https://github.com/meszmate/zigzag/archive/refs/tags/v0.1.5.tar.gz を実行した結果、得られたハッシュは現状の build.zig.zon の値と完全一致しました:

zigzag-0.1.2-YXwYS17aEQBlpxPETTrhY5leFh7vV0DpnXJbHogs4Lsv

ハッシュの prefix zigzag-0.1.2- は 上流 zigzag の v0.1.5 タグ内 build.zig.zon の .version field がまだ "0.1.2" のまま であることに由来しており、Zig パッケージマネージャはこの内部 version を prefix に採用する仕様です (CodeRabbit のスクリプト調査結果と一致)。URL の v0.1.5 と内部 version 0.1.2 の不一致は上流側のメンテナンス問題であって、ハッシュ自体は正しい値です。

zig build および zig build test は Zig 0.16.0 で問題なく成功します。

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Customized review instruction saved!

Instruction:

For Zig build.zig.zon dependency updates, do not flag a mismatch based only on the hash prefix version; verify the dependency with zig fetch/zig build first, since the recorded hash can still be correct even when the upstream tag and embedded package version differ.

Applied to:

  • **/build.zig.zon

💡 To manage or update this instruction, visit: CodeAnt AI Settings

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

As noted in the pull request description, this hash corresponds to version v0.1.2 but the URL points to v0.1.5. This mismatch will cause the build to fail. Please update the hash to the correct value for v0.1.5.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

検証しました。この指摘は false positive です (4スレッド共通の返信)。

手元の Zig 0.16.0 で zig fetch --save=zigzag https://github.com/meszmate/zigzag/archive/refs/tags/v0.1.5.tar.gz を実行した結果、得られたハッシュは現状の build.zig.zon の値と完全一致しました:

zigzag-0.1.2-YXwYS17aEQBlpxPETTrhY5leFh7vV0DpnXJbHogs4Lsv

ハッシュの prefix zigzag-0.1.2- は 上流 zigzag の v0.1.5 タグ内 build.zig.zon の .version field がまだ "0.1.2" のまま であることに由来しており、Zig パッケージマネージャはこの内部 version を prefix に採用する仕様です (CodeRabbit のスクリプト調査結果と一致)。URL の v0.1.5 と内部 version 0.1.2 の不一致は上流側のメンテナンス問題であって、ハッシュ自体は正しい値です。

zig build および zig build test は Zig 0.16.0 で問題なく成功します。

Comment on lines +9 to +10

@coderabbitai coderabbitai Bot May 7, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# zigzag v0.1.5 アーカイブ内の build.zig.zon の .version フィールドを確認する
# 期待値: "0.1.5" (正しく更新されていれば) / "0.1.2" (内部バージョンが古いまま)
curl -sL "https://github.com/meszmate/zigzag/archive/refs/tags/v0.1.5.tar.gz" \
  | tar -xzO --wildcards '*/build.zig.zon' 2>/dev/null | grep -E '\.version'

Repository: midasdf/sshz

Length of output: 1943


🏁 Script executed:

#!/bin/bash
# Download and check the build.zig.zon version in zigzag v0.1.5
curl -sL "https://github.com/meszmate/zigzag/archive/refs/tags/v0.1.5.tar.gz" \
  | tar -xzO --wildcards '*/build.zig.zon' 2>/dev/null | grep -E '\.version|\.name'

Repository: midasdf/sshz

Length of output: 101


URL の v0.1.5 とハッシュが示す内部バージョン 0.1.2 が一致していない

上流パッケージの v0.1.5 タグの build.zig.zon に記載されているバージョンが実際に 0.1.2 であることが確認されました。Zig パッケージマネージャのハッシュプレフィックス(zigzag-0.1.2-)はこの内部バージョンから生成されるため、ハッシュ自体は正しいですが、URL のタグ(v0.1.5)と内部バージョン(0.1.2)のズレが示す通り、上流パッケージのメンテナンスに問題があります。

以下を実行してハッシュを再生成してください:

zig fetch --save=zigzag https://github.com/meszmate/zigzag/archive/refs/tags/v0.1.5.tar.gz

または上流プロジェクト(meszmate/zigzag)に対して、v0.1.5 タグの build.zig.zon のバージョン文字列を 0.1.5 に更新するよう報告することを推奨します。

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@build.zig.zon` around lines 9 - 10, build.zig.zon の .url が v0.1.5 を指している一方で
.hash のプレフィックスは zigzag-0.1.2- と内部バージョンが不一致なので、パッケージハッシュを再生成して一致させてください(対象:
build.zig.zon の .url/.hash、パッケージ名 zigzag)。具体的には上流 URL
https://github.com/meszmate/zigzag/archive/refs/tags/v0.1.5.tar.gz を用いて zig
fetch --save=zigzag を実行して正しいハッシュを取得し、.hash を置き換えるか、あるいは upstream の build.zig.zon
の version フィールドを 0.1.5 に修正するよう報告してください。

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

検証しました。この指摘は false positive です (4スレッド共通の返信)。

手元の Zig 0.16.0 で zig fetch --save=zigzag https://github.com/meszmate/zigzag/archive/refs/tags/v0.1.5.tar.gz を実行した結果、得られたハッシュは現状の build.zig.zon の値と完全一致しました:

zigzag-0.1.2-YXwYS17aEQBlpxPETTrhY5leFh7vV0DpnXJbHogs4Lsv

ハッシュの prefix zigzag-0.1.2- は 上流 zigzag の v0.1.5 タグ内 build.zig.zon の .version field がまだ "0.1.2" のまま であることに由来しており、Zig パッケージマネージャはこの内部 version を prefix に採用する仕様です (CodeRabbit のスクリプト調査結果と一致)。URL の v0.1.5 と内部 version 0.1.2 の不一致は上流側のメンテナンス問題であって、ハッシュ自体は正しい値です。

zig build および zig build test は Zig 0.16.0 で問題なく成功します。

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@midasdf、ご確認とご説明ありがとうございます。おっしゃる通り、この指摘は false positive でした。

Zig パッケージマネージャのハッシュプレフィックスは git タグ ではなく、依存パッケージ自身の build.zig.zon 内 .version フィールド から生成される仕様であることを見落としていました。上流の meszmate/zigzag の v0.1.5 タグ内 .version が "0.1.2" のままであるため、zig fetch が出力するハッシュのプレフィックスが zigzag-0.1.2- となるのは正しい挙動です。

現状の build.zig.zon のハッシュ値は正確であり、問題ありません。失礼しました。


✏️ Learnings added
Learnt from: midasdf
Repo: midasdf/sshz PR: 3
File: build.zig.zon:9-10
Timestamp: 2026-05-07T12:39:04.143Z
Learning: In Zig's package manager (build.zig.zon), the hash prefix for a dependency (e.g., `zigzag-0.1.2-...`) is derived from the `.version` field inside the **dependency's own `build.zig.zon`**, not from the git tag used in the `.url`. Therefore, a mismatch between the URL's git tag version (e.g., `v0.1.5`) and the hash prefix version (e.g., `0.1.2`) is expected when the upstream package's internal version string has not been updated to match the tag. The hash is still valid and correct in such cases.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

},
},
}
189 changes: 136 additions & 53 deletions src/app.zig

Large diffs are not rendered by default.

57 changes: 36 additions & 21 deletions src/checker.zig
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,28 @@ pub const CheckRequest = struct {
};

pub const ResultQueue = struct {
mutex: std.Thread.Mutex = .{},
results: std.ArrayList(CheckResult) = .{},
mutex: std.Io.Mutex = std.Io.Mutex.init,
results: std.ArrayList(CheckResult) = .empty,
allocator: std.mem.Allocator,
io: std.Io,

pub fn init(allocator: std.mem.Allocator) ResultQueue {
return .{ .allocator = allocator };
pub fn init(allocator: std.mem.Allocator, io: std.Io) ResultQueue {
return .{ .allocator = allocator, .io = io };
}

pub fn deinit(self: *ResultQueue) void {
self.results.deinit(self.allocator);
}

pub fn push(self: *ResultQueue, result: CheckResult) void {
self.mutex.lock();
defer self.mutex.unlock();
self.mutex.lockUncancelable(self.io);
defer self.mutex.unlock(self.io);
self.results.append(self.allocator, result) catch {};
}

pub fn drain(self: *ResultQueue, allocator: std.mem.Allocator) []CheckResult {
self.mutex.lock();
defer self.mutex.unlock();
self.mutex.lockUncancelable(self.io);
defer self.mutex.unlock(self.io);
if (self.results.items.len == 0) return &.{};
return self.results.toOwnedSlice(allocator) catch return &.{};
}
Expand All @@ -51,19 +52,21 @@ pub const StatusChecker = struct {
active_count: std.atomic.Value(u32),
max_concurrent: u32 = 3,
shutdown: std.atomic.Value(bool),
threads: std.ArrayList(std.Thread) = .{},
threads_mutex: std.Thread.Mutex = .{},
threads: std.ArrayList(std.Thread) = .empty,
threads_mutex: std.Io.Mutex = std.Io.Mutex.init,
dispatcher_thread: ?std.Thread = null,
generation: std.atomic.Value(u32),
allocator: std.mem.Allocator,
io: std.Io,

pub fn init(queue: *ResultQueue, allocator: std.mem.Allocator) StatusChecker {
pub fn init(queue: *ResultQueue, allocator: std.mem.Allocator, io: std.Io) StatusChecker {
return .{
.queue = queue,
.active_count = std.atomic.Value(u32).init(0),
.shutdown = std.atomic.Value(bool).init(false),
.generation = std.atomic.Value(u32).init(0),
.allocator = allocator,
.io = io,
};
}

Expand All @@ -78,9 +81,12 @@ pub const StatusChecker = struct {
}

fn joinAllThreads(self: *StatusChecker) void {
self.threads_mutex.lock();
const threads = self.threads.toOwnedSlice(self.allocator) catch return;
self.threads_mutex.unlock();
self.threads_mutex.lockUncancelable(self.io);
const threads = self.threads.toOwnedSlice(self.allocator) catch {
self.threads_mutex.unlock(self.io);
return;
};
self.threads_mutex.unlock(self.io);
Comment on lines +84 to +89

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: joinAllThreads acquires threads_mutex and then returns immediately on allocation failure from toOwnedSlice without releasing the mutex. This leaves the mutex permanently locked, so later calls that need the same mutex can block forever. Ensure the mutex is always released on every exit path (including error paths). [possible bug]

Severity Level: Critical 🚨
- ❌ TUI status refresh can deadlock on low-memory allocation failure.
- ❌ `StatusChecker.deinit` may hang, blocking clean TUI shutdown.
- ⚠️ Background status-check worker threads may remain unjoined on error.
Steps of Reproduction ✅
1. Start the TUI via `main` at `src/main.zig:8-36` (which calls `launchTui` at
`src/main.zig:56-77` and constructs `app.Model` through `zz.Program(app.Model).init`).

2. In `Model.init` at `src/app.zig:61-89`, SSH host configuration is loaded and
`startStatusChecks()` is called at `src/app.zig:86`, which builds `CheckRequest` values
and calls `self.status_checker.checkAll(requests.items)` at `src/app.zig:130-131`.

3. Inside `StatusChecker.checkAll` at `src/checker.zig:92-111`, the first operation is
`self.joinAllThreads();` at `src/checker.zig:98`, which calls `joinAllThreads` at
`src/checker.zig:83-89`. There, `threads_mutex` is locked at line 84, and
`self.threads.toOwnedSlice(self.allocator)` at line 85 may fail under memory pressure (it
allocates a copy of the internal `threads` array using the same allocator used throughout
the TUI).

4. When `toOwnedSlice` fails, the `catch return` at `src/checker.zig:85` exits
`joinAllThreads` without executing the unlock at line 86, leaving `threads_mutex`
permanently locked. On the next status refresh (e.g., user presses 'r' in the TUI, which
calls `startStatusChecks` at `src/app.zig:115-133`, leading again to
`status_checker.checkAll` and `joinAllThreads`), or during shutdown via
`self.status_checker.deinit()` at `src/app.zig:92-100`,
`threads_mutex.lockUncancelable(self.io)` at `src/checker.zig:84` blocks forever,
deadlocking the status-checking logic and freezing that part of the TUI.

Fix in Cursor | Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** src/checker.zig
**Line:** 84:86
**Comment:**
	*Possible Bug: `joinAllThreads` acquires `threads_mutex` and then returns immediately on allocation failure from `toOwnedSlice` without releasing the mutex. This leaves the mutex permanently locked, so later calls that need the same mutex can block forever. Ensure the mutex is always released on every exit path (including error paths).

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 3f625e2。toOwnedSlice の OOM 経路で unlock してから return するよう修正しました:

const threads = self.threads.toOwnedSlice(self.allocator) catch {
    self.threads_mutex.unlock(self.io);
    return;
};

for (threads) |t| t.join();
self.allocator.free(threads);
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
Expand Down Expand Up @@ -131,27 +137,36 @@ pub const StatusChecker = struct {
_ = self.active_count.fetchSub(1, .release);
continue;
};
self.threads_mutex.lock();
self.threads_mutex.lockUncancelable(self.io);
self.threads.append(self.allocator, thread) catch {
self.threads_mutex.unlock();
self.threads_mutex.unlock(self.io);
thread.join();
continue;
};
self.threads_mutex.unlock();
self.threads_mutex.unlock(self.io);
}
}

fn checkWorker(self: *StatusChecker, host_index: usize, hostname: []const u8, port: u16, gen: u32) void {
defer _ = self.active_count.fetchSub(1, .release);
if (self.shutdown.load(.acquire)) return;

const status = tcpCheck(hostname, port);
const status = tcpCheck(self.io, hostname, port);
self.queue.push(.{ .host_index = host_index, .status = status, .generation = gen });
}
};

fn tcpCheck(hostname: []const u8, port: u16) HostStatus {
const stream = std.net.tcpConnectToHost(std.heap.page_allocator, hostname, port) catch return .offline;
stream.close();
fn tcpCheck(io: std.Io, hostname: []const u8, port: u16) HostStatus {
// Try IPv4/IPv6 literals first; HostName.init rejects ':' so a bare IPv6
// address would otherwise always report offline.
if (std.Io.net.IpAddress.parse(hostname, port)) |addr| {
const stream = addr.connect(io, .{ .mode = .stream }) catch return .offline;
stream.close(io);
return .online;
} else |_| {}

const host = std.Io.net.HostName.init(hostname) catch return .offline;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Handle IPv6 literals before HostName.init

For SSH configs whose effective HostName is an IPv6 literal such as ::1 or 2001:db8::1, this now returns .offline before any connection attempt because std.Io.net.HostName.init validates DNS host-name characters and rejects :. The previous std.net.tcpConnectToHost path accepted IP literals, so IPv6-only hosts will always show as offline in the status checker even when reachable; parse/connect std.Io.net.IpAddress literals first, or use an API path that accepts both IP literals and names.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 3f625e2。std.Io.net.IpAddress.parse を先に試して、IP リテラル (IPv4/IPv6) は HostName.init をバイパスして直接 addr.connect(io, ...) する経路を追加しました。これで ::1 や 2001:db8::1 のようなホスト名でもステータスチェックが通るようになります。

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Accept resolver names that are not DNS labels

For SSH configs whose effective host name is a resolver/hosts-file name that is valid for ssh but not a strict DNS label, such as db_test, this returns .offline without attempting a lookup because std.Io.net.HostName.init only permits ASCII alphanumerics, -, and .. The old std.net.tcpConnectToHost path delegated these names to the system resolver, so hosts that connect successfully via /etc/hosts or local resolver aliases are now always shown offline; use a lookup/connect path that accepts the same name syntax SSH can resolve, or only apply HostName.init after handling these cases.

Useful? React with 👍 / 👎.

const stream = host.connect(io, port, .{ .mode = .stream }) catch return .offline;
stream.close(io);
return .online;
}
62 changes: 31 additions & 31 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,40 @@ const app = @import("app");

const version = "0.1.0";

pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
const allocator = gpa.allocator();
pub fn main(init: std.process.Init) !void {
const allocator = init.gpa;
const arena_allocator = init.arena.allocator();

const args = try std.process.argsAlloc(allocator);
defer std.process.argsFree(allocator, args);
const args = try init.minimal.args.toSlice(arena_allocator);

if (args.len >= 2 and std.mem.eql(u8, args[1], "--help")) {
printUsage();
printUsage(init.io);
return;
}

if (args.len >= 2 and std.mem.eql(u8, args[1], "--version")) {
const file = std.fs.File{ .handle = std.posix.STDOUT_FILENO };
const file = std.Io.File.stdout();
var buf: [256]u8 = undefined;
var w = file.writer(&buf);
var w = file.writer(init.io, &buf);
try w.interface.print("sshz {s}\n", .{version});
try w.interface.flush();
return;
}

// sshz <host> [command...] — direct connect
if (args.len >= 2 and args[1][0] != '-') {
try directConnect(allocator, args[1], args[2..]);
if (args.len >= 2 and args[1].len > 0 and args[1][0] != '-') {
try directConnect(allocator, init.io, init.environ_map, args[1], args[2..]);
return;
}

// sshz — launch TUI
try launchTui(allocator);
try launchTui(init);
}

fn printUsage() void {
const file = std.fs.File{ .handle = std.posix.STDOUT_FILENO };
fn printUsage(io: std.Io) void {
const file = std.Io.File.stdout();
var buf: [4096]u8 = undefined;
var w = file.writer(&buf);
var w = file.writer(io, &buf);
w.interface.print(
\\SSHZ - SSH Connection Manager
\\
Expand All @@ -55,8 +53,9 @@ fn printUsage() void {
w.interface.flush() catch {};
}

fn launchTui(allocator: std.mem.Allocator) !void {
var program = try zz.Program(app.Model).init(allocator);
fn launchTui(init: std.process.Init) !void {
const allocator = init.gpa;
var program = try zz.Program(app.Model).init(init.gpa, init.io, init.environ_map);
try program.run();

// Grab connect_host before deinit frees it
Expand All @@ -73,39 +72,40 @@ fn launchTui(allocator: std.mem.Allocator) !void {
program.deinit();

if (connect_host) |host_name| {
try directConnect(allocator, host_name, &.{});
try directConnect(allocator, init.io, init.environ_map, host_name, &.{});
}
}

fn directConnect(allocator: std.mem.Allocator, host_name: []const u8, extra_args: []const [:0]u8) !void {
fn directConnect(allocator: std.mem.Allocator, io: std.Io, env: *const std.process.Environ.Map, host_name: []const u8, extra_args: []const [:0]const u8) !void {
// Record connection in meta.json
const meta_path = try meta_mod.defaultMetaPath(allocator);
const meta_path = try meta_mod.defaultMetaPath(allocator, env);
defer allocator.free(meta_path);

var store = try meta_mod.readFile(allocator, meta_path);
var store = try meta_mod.readFile(allocator, io, meta_path);
defer store.deinit(allocator);

try store.recordConnection(allocator, host_name);
meta_mod.writeFile(allocator, &store, meta_path) catch {};
try store.recordConnection(allocator, io, host_name);
meta_mod.writeFile(allocator, io, &store, meta_path) catch {};

// Build args
var argv: std.ArrayList([]const u8) = .{};
var argv: std.ArrayList([]const u8) = .empty;
defer argv.deinit(allocator);

try argv.append(allocator, "ssh");
try argv.append(allocator, host_name);
for (extra_args) |arg| try argv.append(allocator, arg);

// Exec ssh
var child = std.process.Child.init(argv.items, allocator);
child.stdin_behavior = .Inherit;
child.stdout_behavior = .Inherit;
child.stderr_behavior = .Inherit;
try child.spawn();
const term = try child.wait();
var child = try std.process.spawn(io, .{
.argv = argv.items,
.stdin = .inherit,
.stdout = .inherit,
.stderr = .inherit,
});
const term = try child.wait(io);

switch (term) {
.Exited => |code| if (code != 0) std.process.exit(code),
.exited => |code| if (code != 0) std.process.exit(code),
else => std.process.exit(1),
}
}
Loading
Loading