mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-06-11 09:35:59 -04:00
script: rename raw_line to opener_line
This commit is contained in:
@@ -622,13 +622,13 @@ fn runScript(self: *Agent, path: []const u8) bool {
|
||||
// Recorded scripts prefix LLM-generated commands with the
|
||||
// natural-language prompt that produced them; keep the
|
||||
// last one around so self-heal can use it as context.
|
||||
if (entry.raw_line.len > 2 and entry.raw_line[0] == '#') {
|
||||
last_comment = std.mem.trim(u8, entry.raw_line[1..], &std.ascii.whitespace);
|
||||
if (entry.opener_line.len > 2 and entry.opener_line[0] == '#') {
|
||||
last_comment = std.mem.trim(u8, entry.opener_line[1..], &std.ascii.whitespace);
|
||||
}
|
||||
continue;
|
||||
},
|
||||
.natural_language => {
|
||||
self.terminal.printErrorFmt("line {d}: unrecognized command: {s}", .{ entry.line_num, entry.raw_line });
|
||||
self.terminal.printErrorFmt("line {d}: unrecognized command: {s}", .{ entry.line_num, entry.opener_line });
|
||||
self.flushReplacements(path, content, replacements.items);
|
||||
return false;
|
||||
},
|
||||
@@ -636,7 +636,7 @@ fn runScript(self: *Agent, path: []const u8) bool {
|
||||
if (self.ai_client == null) {
|
||||
self.terminal.printErrorFmt("line {d}: {s} requires --provider", .{
|
||||
entry.line_num,
|
||||
entry.raw_line,
|
||||
entry.opener_line,
|
||||
});
|
||||
self.flushReplacements(path, content, replacements.items);
|
||||
return false;
|
||||
@@ -645,7 +645,7 @@ fn runScript(self: *Agent, path: []const u8) bool {
|
||||
const text = self.processUserMessage(.{ .prompt = prompt }) catch |err| {
|
||||
self.terminal.printErrorFmt("line {d}: {s} failed: {s}", .{
|
||||
entry.line_num,
|
||||
entry.raw_line,
|
||||
entry.opener_line,
|
||||
@errorName(err),
|
||||
});
|
||||
self.flushReplacements(path, content, replacements.items);
|
||||
@@ -655,7 +655,7 @@ fn runScript(self: *Agent, path: []const u8) bool {
|
||||
self.pruneMessages();
|
||||
},
|
||||
else => {
|
||||
self.terminal.printInfoFmt("[{d}] {s}", .{ entry.line_num, entry.raw_line });
|
||||
self.terminal.printInfoFmt("[{d}] {s}", .{ entry.line_num, entry.opener_line });
|
||||
switch (self.runActionEntry(sa, entry, last_comment)) {
|
||||
.ok => {},
|
||||
.healed => |r| replacements.append(sa, r) catch |err| {
|
||||
@@ -720,8 +720,8 @@ fn runActionEntry(self: *Agent, sa: std.mem.Allocator, entry: Command.ScriptIter
|
||||
.failed => |r| r,
|
||||
.passed, .inconclusive => null,
|
||||
};
|
||||
if (self.attemptSelfHeal(sa, entry.raw_line, reason, last_comment)) |healed_cmds| {
|
||||
const replacement = script.formatHealReplacement(sa, entry.raw_span, entry.raw_line, healed_cmds) catch |err| {
|
||||
if (self.attemptSelfHeal(sa, entry.opener_line, reason, last_comment)) |healed_cmds| {
|
||||
const replacement = script.formatHealReplacement(sa, entry.raw_span, entry.opener_line, healed_cmds) catch |err| {
|
||||
self.terminal.printErrorFmt(
|
||||
"line {d}: failed to record heal: {s} (script left unchanged)",
|
||||
.{ entry.line_num, @errorName(err) },
|
||||
@@ -733,7 +733,7 @@ fn runActionEntry(self: *Agent, sa: std.mem.Allocator, entry: Command.ScriptIter
|
||||
}
|
||||
self.terminal.printErrorFmt("line {d}: command failed: {s}", .{
|
||||
entry.line_num,
|
||||
entry.raw_line,
|
||||
entry.opener_line,
|
||||
});
|
||||
return .fail;
|
||||
}
|
||||
|
||||
@@ -188,12 +188,12 @@ pub fn writeAtomic(
|
||||
pub fn formatHealReplacement(
|
||||
arena: std.mem.Allocator,
|
||||
original_span: []const u8,
|
||||
raw_line: []const u8,
|
||||
opener_line: []const u8,
|
||||
cmds: []const Command,
|
||||
) !Replacement {
|
||||
std.debug.assert(cmds.len > 0);
|
||||
var aw: std.Io.Writer.Allocating = .init(arena);
|
||||
try aw.writer.print("# [Auto-healed] Original: {s}\n", .{raw_line});
|
||||
try aw.writer.print("# [Auto-healed] Original: {s}\n", .{opener_line});
|
||||
for (cmds) |cmd| {
|
||||
try cmd.format(&aw.writer);
|
||||
try aw.writer.writeByte('\n');
|
||||
@@ -207,12 +207,12 @@ pub fn formatHealReplacement(
|
||||
pub fn formatHealReplacementLines(
|
||||
arena: std.mem.Allocator,
|
||||
original_span: []const u8,
|
||||
raw_line: []const u8,
|
||||
opener_line: []const u8,
|
||||
replacement_lines: []const []const u8,
|
||||
) !Replacement {
|
||||
var aw: std.Io.Writer.Allocating = .init(arena);
|
||||
|
||||
try aw.writer.print("# [Auto-healed] Original: {s}\n", .{raw_line});
|
||||
try aw.writer.print("# [Auto-healed] Original: {s}\n", .{opener_line});
|
||||
for (replacement_lines) |line| {
|
||||
try aw.writer.writeAll(line);
|
||||
try aw.writer.writeByte('\n');
|
||||
|
||||
@@ -449,7 +449,11 @@ pub const Command = union(enum) {
|
||||
|
||||
pub const Entry = struct {
|
||||
line_num: u32,
|
||||
raw_line: []const u8,
|
||||
/// Trimmed opener line — the only line for single-line entries,
|
||||
/// the `EVAL '''` / `EXTRACT '''` opener for blocks. Display-only
|
||||
/// (errors, REPL echo, heal-comment headers); use `raw_span` for
|
||||
/// splices that need the full block body.
|
||||
opener_line: []const u8,
|
||||
/// The full slice of the original content buffer covering this entry,
|
||||
/// including trailing newline(s). For multi-line EVAL blocks this spans
|
||||
/// from the EVAL keyword through the closing triple-quote line.
|
||||
@@ -475,7 +479,7 @@ pub const Command = union(enum) {
|
||||
};
|
||||
return .{
|
||||
.line_num = start_line,
|
||||
.raw_line = trimmed,
|
||||
.opener_line = trimmed,
|
||||
.raw_span = self.lines.buffer[line_start..span_end],
|
||||
.command = cmd,
|
||||
};
|
||||
@@ -484,7 +488,7 @@ pub const Command = union(enum) {
|
||||
const span_end = self.lines.index orelse self.lines.buffer.len;
|
||||
return .{
|
||||
.line_num = self.line_num,
|
||||
.raw_line = trimmed,
|
||||
.opener_line = trimmed,
|
||||
.raw_span = self.lines.buffer[line_start..span_end],
|
||||
.command = Command.parse(trimmed),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user