Public Access
Make agent file writes append by default
PR and Push Build/Test / build-and-test (push) Failing after 6m36s
PR and Push Build/Test / build-and-test (push) Failing after 6m36s
This commit is contained in:
@@ -249,12 +249,13 @@ public sealed class MeetingSummaryTools
|
||||
string content,
|
||||
int? @from = null,
|
||||
int? to = null,
|
||||
int? insert = null)
|
||||
int? insert = null,
|
||||
bool replace_file = false)
|
||||
{
|
||||
var editMode = FileLineEditMode.Create(@from, to, insert);
|
||||
var editMode = FileLineEditMode.Create(@from, to, insert, replace_file);
|
||||
if (editMode is null)
|
||||
{
|
||||
return "Refused: supply either both from and to for replacement, insert for insertion, or no line arguments for overwrite.";
|
||||
return "Refused: supply either both from and to for replacement, insert for insertion, or no line arguments for append; set replace_file=true only for whole-file replacement.";
|
||||
}
|
||||
|
||||
if (!File.Exists(artifacts.AssistantContextPath))
|
||||
@@ -316,12 +317,13 @@ public sealed class MeetingSummaryTools
|
||||
string content,
|
||||
int? @from = null,
|
||||
int? to = null,
|
||||
int? insert = null)
|
||||
int? insert = null,
|
||||
bool replace_file = false)
|
||||
{
|
||||
var editMode = FileLineEditMode.Create(@from, to, insert);
|
||||
var editMode = FileLineEditMode.Create(@from, to, insert, replace_file);
|
||||
if (editMode is null)
|
||||
{
|
||||
return "Refused: supply either both from and to for replacement, insert for insertion, or no line arguments for overwrite.";
|
||||
return "Refused: supply either both from and to for replacement, insert for insertion, or no line arguments for append; set replace_file=true only for whole-file replacement.";
|
||||
}
|
||||
|
||||
var target = ResolveExistingProjectFilePath(project, path);
|
||||
@@ -544,6 +546,15 @@ public sealed class MeetingSummaryTools
|
||||
return;
|
||||
}
|
||||
|
||||
if (editMode.Kind == FileLineEditKind.Append)
|
||||
{
|
||||
var existing = File.Exists(filePath)
|
||||
? await File.ReadAllTextAsync(filePath)
|
||||
: "";
|
||||
await File.WriteAllTextAsync(filePath, AppendContent(existing, content));
|
||||
return;
|
||||
}
|
||||
|
||||
var lines = File.Exists(filePath)
|
||||
? (await File.ReadAllLinesAsync(filePath)).ToList()
|
||||
: [];
|
||||
@@ -616,6 +627,11 @@ public sealed class MeetingSummaryTools
|
||||
return replacementContent;
|
||||
}
|
||||
|
||||
if (editMode.Kind == FileLineEditKind.Append)
|
||||
{
|
||||
return AppendContent(existingContent, replacementContent);
|
||||
}
|
||||
|
||||
var lines = SplitLines(existingContent);
|
||||
var replacementLines = SplitLines(replacementContent);
|
||||
if (editMode.Kind == FileLineEditKind.Insert)
|
||||
@@ -637,6 +653,24 @@ public sealed class MeetingSummaryTools
|
||||
return string.Join('\n', lines);
|
||||
}
|
||||
|
||||
private static string AppendContent(string existingContent, string content)
|
||||
{
|
||||
if (string.IsNullOrEmpty(existingContent))
|
||||
{
|
||||
return content;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(content))
|
||||
{
|
||||
return existingContent;
|
||||
}
|
||||
|
||||
var separator = existingContent.EndsWith('\n') || existingContent.EndsWith('\r')
|
||||
? ""
|
||||
: "\n";
|
||||
return existingContent + separator + content;
|
||||
}
|
||||
|
||||
private Task<List<BoundMeetingProject>> GetBoundProjectsAsync()
|
||||
{
|
||||
return projectResolver.GetBoundProjectsAsync(artifacts);
|
||||
@@ -778,8 +812,13 @@ public sealed class MeetingSummaryTools
|
||||
int? To = null,
|
||||
int? Insert = null)
|
||||
{
|
||||
public static FileLineEditMode? Create(int? from, int? to, int? insert)
|
||||
public static FileLineEditMode? Create(int? from, int? to, int? insert, bool replaceFile)
|
||||
{
|
||||
if (replaceFile && (from.HasValue || to.HasValue || insert.HasValue))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (insert.HasValue)
|
||||
{
|
||||
return from.HasValue || to.HasValue
|
||||
@@ -794,12 +833,13 @@ public sealed class MeetingSummaryTools
|
||||
: null;
|
||||
}
|
||||
|
||||
return new FileLineEditMode(FileLineEditKind.Overwrite);
|
||||
return new FileLineEditMode(replaceFile ? FileLineEditKind.Overwrite : FileLineEditKind.Append);
|
||||
}
|
||||
}
|
||||
|
||||
private enum FileLineEditKind
|
||||
{
|
||||
Append,
|
||||
Overwrite,
|
||||
Replace,
|
||||
Insert
|
||||
|
||||
Reference in New Issue
Block a user