+// compactionParts returns the input parts of a first try for the compaction
+// view context and the task text: the opening tag, one part for each whole
+// block of viewBlock lines, and then one part with the rest of the lines, the
+// closing tag, a newline, and the task. Joined, the parts are the view, a
+// newline, and the task.
+func compactionParts(context, task string) []string {
+ lines := strings.SplitAfter(strings.TrimPrefix(context, "<chat>\n"), "\n")
+ whole := len(lines) - 1 - (len(lines)-1)%viewBlock
+ parts := []string{"<chat>\n"}
+ for n := 0; n < whole; n += viewBlock {
+ parts = append(parts, strings.Join(lines[n:n+viewBlock], ""))
+ }
+
+ return append(parts, strings.Join(lines[whole:], "")+"\n"+task)
+}
+