From 05118f216d524c96ffe936e494b8ecce26303de1 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 29 Sep 2026 11:36:01 -0300 Subject: A builtin's Verbose announcement is the message row's alone, never logged With Verbose on by default, /log filled with msg - DumpDir, msg 4 Grep and the like, with machinery to take an announcement back out when its builtin failed or said something itself. A msg record is now only something said; the take-back machinery goes with it. Co-Authored-By: Claude Opus 5.5 --- src/Messages.zig | 9 ++----- src/exec.zig | 15 ++++-------- src/fs.zig | 7 ------ src/ninep/cols.zig | 11 ++++----- src/ninep/events.zig | 66 ++-------------------------------------------------- 5 files changed, 13 insertions(+), 95 deletions(-) (limited to 'src') diff --git a/src/Messages.zig b/src/Messages.zig index ce7a2a8c..aebaff0c 100644 --- a/src/Messages.zig +++ b/src/Messages.zig @@ -503,9 +503,6 @@ pub fn clip(text: []const u8, max: usize) []const u8 { /// reportError with the words already chosen. pub fn reportFailure(p: *Pardes, id: usize, text: []const u8) void { p.fs.failures +%= 1; - // A failure said later, when the host could not do the work (a Save's - // write): that builtin's announcement goes from the log too. - ctlfs.events.dropFailedAnnouncement(p, text, false); // A builtin a ctl write runs: its first error is also the write's, cut // between words. const failing_write = p.fs.no_prompt or p.fs.capturing; @@ -520,11 +517,9 @@ pub fn reportFailure(p: *Pardes, id: usize, text: []const u8) void { p.fs.failure_len = @intCast(n); } // The write fails with it, and its err record says it: no msg for it, - // and no Verbose announcement before that, so the same failure again is - // the same record again, counted (events.pushCounting). + // so the same failure again is the same record again, counted + // (events.pushCounting). if (failing_write) { - const serial: u32 = if (p.fs.session_write) 0 else if (id < MAX_PANES) if (p.panes[id]) |pane| pane.serial else 0 else 0; - ctlfs.events.dropAnnouncement(p, serial, text); p.fs.unlogged = true; defer p.fs.unlogged = false; return setMessage(p, id, text); diff --git a/src/exec.zig b/src/exec.zig index 1fc38b9c..9e46b434 100644 --- a/src/exec.zig +++ b/src/exec.zig @@ -861,23 +861,16 @@ pub fn runBuiltinFrom(p: *Pardes, b: Builtin, id: usize, txt: []const u8, arg: ? const pane = p.panes[id] orelse return; // A builtin says its own name before it runs, so a tagline click is // legible even when what it did is invisible. Whatever the builtin - // then says for itself replaces the announcement. - // Its log record stands only if it does not fail (events.dropFailedAnnouncement). - var announced: ?u64 = null; + // then says for itself replaces the announcement. It is the message + // row's only, never /log's: a msg record is something said. if (p.announce and p.settings.verbose and builtins.registry.announces(b)) { + p.fs.unlogged = true; p.setMessage(id, @tagName(b)); + p.fs.unlogged = false; pane.msg_announcement = true; - announced = pardes.ctlfs.events.newestSaying(p, @tagName(b)); - p.fs.announced_seq = announced; - const word = @tagName(b)[0..@min(@tagName(b).len, p.fs.announced_word.len)]; - @memcpy(p.fs.announced_word[0..word.len], word); - p.fs.announced_word_len = @intCast(word.len); } - const failures = p.fs.failures; const c: builtins.Ctx = .{ .p = p, .pane = pane, .id = id, .txt = txt, .arg = arg, .from_body = from_body }; builtins.registry.dispatch(b, c); - if (announced != null and p.fs.failures != failures and p.fs.announced_seq == announced) - pardes.ctlfs.events.dropFailedAnnouncement(p, "", true); } pub fn applySettingBuiltin(p: *Pardes, setting: config.Runtime.Setting, arg: ?[]const u8) void { diff --git a/src/fs.zig b/src/fs.zig index 6feaa972..5d7d68e8 100644 --- a/src/fs.zig +++ b/src/fs.zig @@ -1308,11 +1308,6 @@ pub const Namespace = struct { header_held: bool = false, late_failure: [256]u8 = undefined, late_failure_len: u16 = 0, - /// The log record of the last Verbose announcement (`msg - /// `) and its word: a failure of that builtin, now or when its - /// host work fails (a Save, a Dump), takes it back out of the log, so - /// an announcement stands only for a builtin that did what it said. - announced_seq: ?u64 = null, /// The serial of the pane the root's exec or look last ran a line at /// (the keyboard's), 0 before one: its err record names that pane. ran_at: u32 = 0, @@ -1322,8 +1317,6 @@ pub const Namespace = struct { /// Every failure said (Messages.reportFailure), counted: a builtin /// that said one while it ran failed. failures: u32 = 0, - announced_word: [32]u8 = undefined, - announced_word_len: u8 = 0, /// A refusal that quotes the message it refuses, as Plan 9's cmderror /// does (kernel/misc/parse.c:82); answered at once (src/9p_io.zig). ename: [320]u8 = undefined, diff --git a/src/ninep/cols.zig b/src/ninep/cols.zig index aae6d364..6b59f9e5 100644 --- a/src/ninep/cols.zig +++ b/src/ninep/cols.zig @@ -401,19 +401,18 @@ test "tagexec runs a word as a click in the workspace tag; exec files read back try testing.expectEqual(tree.Status.ok, th.look_up(p, tree.root, "tagexec").reply.status); try testing.expectEqual(tree.Status.ok, th.wr(p, tagexec, "Newcol\n").reply.status); try testing.expectEqual(@as(usize, 2), p.ncol); - // What it says is the session's (Newcol announcing itself); a pane's - // word such as Msg is refused there. - try testing.expect(th.logHas(p, "msg - Newcol\n")); + // Its announcement is the message row's, never logged; a pane's word + // such as Msg is refused there. + try testing.expect(!th.logHas(p, "msg - Newcol\n")); try testing.expectEqual(E.INVAL, th.wr(p, tagexec, "Msg from the top\n").errno()); - // A column's exec makes a pane there, reads it back, and its Msg is - // the session's too. + // A column's exec makes a pane there and reads it back. const right = layout.columnSerial(p, 1); try testing.expectEqual(tree.Status.ok, th.wr(p, Node.ofCol(right, .exec), "New\n").reply.status); const made = p.panes[p.col_panes[1][0]].?.serial; var want: [16]u8 = undefined; try testing.expectEqualStrings(try std.fmt.bufPrint(&want, "{d}\n", .{made}), th.rd(p, Node.ofCol(right, .exec), 0, 64).bytes); try testing.expectEqualStrings(try std.fmt.bufPrint(&want, "{d}\n", .{made}), th.rd(p, tagexec, 0, 64).bytes); - try testing.expect(th.logHas(p, "msg - New\n")); + try testing.expect(!th.logHas(p, "msg - New\n")); // announced on the message row only } test "a word run from the workspace's or a column's tag runs in the session's directory, a pane's in its own" { diff --git a/src/ninep/events.zig b/src/ninep/events.zig index 690efbe5..95b4926e 100644 --- a/src/ninep/events.zig +++ b/src/ninep/events.zig @@ -161,10 +161,6 @@ pub fn noteMessage(p: *Pardes, serial: u32, said: []const u8) void { var buf: [pardes.Messages.LoggedMessage.cap + 32]u8 = undefined; const kept = pardes.Messages.clip(said, pardes.Messages.LoggedMessage.cap); const cut = if (kept.len < said.len) "…" else ""; - // A builtin's own word for what it did stands in for its Verbose - // announcement just before (`Undo` then `Undo: nothing to undo`), so - // that 1000 Undos with nothing left are one line, counted, as err's are. - dropAnnouncement(p, serial, kept); pushCounting(p, (if (serial == 0) std.fmt.bufPrint(&buf, "msg - {s}{s}\n", .{ kept, cut }) else @@ -230,61 +226,6 @@ pub fn noteError(p: *Pardes, req: Req, reply: Reply) void { pushCounting(p, record); } -/// Drops the newest record when it is the Verbose announcement (`msg -/// `) of the builtin whose words `text` are (`Word: ...`): -/// what the builtin said, or the err its failure logs, takes its place. -/// Not one a follower has read. -pub fn dropAnnouncement(p: *Pardes, serial: u32, text: []const u8) void { - const last = newest(p) orelse return; - if (followerRead(p, last.seq) or !std.mem.startsWith(u8, last.text, "msg ")) return; - const rest = last.text["msg ".len..]; - const sp = std.mem.indexOfScalar(u8, rest, ' ') orelse rest.len; - const word = rest[@min(sp + 1, rest.len)..]; - var who: [16]u8 = undefined; - const mine = if (serial == 0) "-" else std.fmt.bufPrint(&who, "{d}", .{serial}) catch ""; - if (std.mem.eql(u8, rest[0..sp], mine) and word.len > 0 and std.mem.indexOfScalar(u8, word, ' ') == null and - text.len > word.len and std.mem.startsWith(u8, text, word) and text[word.len] == ':') - p.fs.log.buf.shrinkRetainingCapacity(last.at); -} - -/// The sequence number of the newest log record when it is a msg that -/// ends in `word` alone: not one counted (`(x2)`) over an earlier say. -pub fn newestSaying(p: *Pardes, word: []const u8) ?u64 { - const last = newest(p) orelse return null; - if (!std.mem.startsWith(u8, last.text, "msg ") or !std.mem.endsWith(u8, last.text, word)) return null; - if (last.text[last.text.len - word.len - 1] != ' ') return null; - return last.seq; -} - -/// Takes record `seq` back out of the log, unless a follower has read it. -pub fn dropRecord(p: *Pardes, seq: u64) void { - if (followerRead(p, seq)) return; - const q = &p.fs.log; - var at = q.head; - var s = q.dropped; - while (at + 4 <= q.buf.items.len) : (s += 1) { - const size = 4 + std.mem.readInt(u32, q.buf.items[at..][0..4], .little); - if (s == seq) { - const items = q.buf.items; - std.mem.copyForwards(u8, items[at..], items[at + size ..]); - q.buf.shrinkRetainingCapacity(items.len - size); - return; - } - at += size; - } -} - -/// A builtin's failure: its Verbose announcement goes from the log, when -/// `text` is that builtin's (it starts with its word) or `any`, as for a -/// failure said while the builtin itself runs. -pub fn dropFailedAnnouncement(p: *Pardes, text: []const u8, any: bool) void { - const seq = p.fs.announced_seq orelse return; - const word = p.fs.announced_word[0..p.fs.announced_word_len]; - if (!any and !(std.mem.startsWith(u8, text, word) and text.len > word.len and (text[word.len] == ' ' or text[word.len] == ':'))) return; - p.fs.announced_seq = null; - dropRecord(p, seq); -} - /// Drops the newest record when it is a msg saying `text` (of any pane) /// that no follower has read: a failure its write's err record will say. pub fn dropMessage(p: *Pardes, text: []const u8) void { @@ -1100,12 +1041,9 @@ test "the log records whether or not anyone reads, and an open that follows wait try std.fmt.bufPrint(&expected, "msg {d} save: two lines\n", .{serial}), rdf.next(p, log, fh, frozen).bytes, ); - // A builtin announces itself on the message row, so the log says which ran. + // A builtin announces itself on the message row only: the log has + // what it did. try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .exec), "Del\n").reply.status); - try testing.expectEqualStrings( - try std.fmt.bufPrint(&expected, "msg {d} Del\n", .{serial}), - rdf.next(p, log, fh, frozen).bytes, - ); try testing.expectEqualStrings( try std.fmt.bufPrint(&expected, "del {d} /tmp/logged.txt\n", .{serial}), rdf.next(p, log, fh, frozen).bytes, -- cgit v1.3