MCPcopy
hub / github.com/continuedev/continue / logFragment

Method logFragment

core/llm/logFormatter.ts:157–219  ·  view source on GitHub ↗
(
    item: LLMInteractionItem,
    fragment: string,
    startAt: number,
    marker: string = "",
    joinBefore: boolean = false,
    joinAfter: boolean = false,
    wrap: boolean = false,
  )

Source from the content-addressed store, hash-verified

155
156 // the implementation behind logLines and logMessageText
157 private logFragment(
158 item: LLMInteractionItem,
159 fragment: string,
160 startAt: number,
161 marker: string = "",
162 joinBefore: boolean = false,
163 joinAfter: boolean = false,
164 wrap: boolean = false,
165 ) {
166 const interaction = this.getInteractionData(item);
167
168 if (
169 this.openLine &&
170 (!joinBefore || item.interactionId !== this.lastItem?.interactionId)
171 ) {
172 this.openLine = false;
173 this.openLineChars = 0;
174 this.output.write("\n");
175 }
176
177 let continueAt = null;
178 if (
179 wrap &&
180 fragment.length - startAt > this.wrapWidth - this.openLineChars
181 ) {
182 continueAt = startAt + this.wrapWidth - this.openLineChars;
183
184 // Look for a better line-breaking point at whitespace
185 const searchBackwardLimit = Math.max(startAt, continueAt - 20); // Don't look back too far
186 for (let i = continueAt; i > searchBackwardLimit; i--) {
187 if (/\s/.test(fragment.charAt(i))) {
188 continueAt = i + 1; // Break after the whitespace
189 break;
190 }
191 }
192
193 // When there's whitespace immediately after the wrap width,
194 // the above will result in breaking *after* that, so we exceed
195 // the wrap width. The trimEnd() avoids that.
196 fragment = fragment.substring(startAt, continueAt).trimEnd();
197 joinAfter = false;
198 } else if (startAt > 0) {
199 fragment = fragment.substring(startAt);
200 }
201
202 if (!this.openLine || !this.openLine) {
203 let timestamp = this.formatTimestamp(interaction, item);
204 this.output.write(`${interaction.prefix}${timestamp} ${marker}`);
205 this.lastLineStartItem = item;
206 }
207
208 this.output.write(fragment);
209 this.openLine = joinAfter;
210 this.lastItem = item;
211 if (!this.openLine) {
212 this.output.write("\n");
213 this.openLineChars = 0;
214 } else {

Callers 2

logLinesMethod · 0.95
logMessageTextMethod · 0.95

Calls 3

getInteractionDataMethod · 0.95
formatTimestampMethod · 0.95
testMethod · 0.80

Tested by

no test coverage detected