Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/shared/src/composerContextReferences.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,16 @@ describe("provider projection", () => {
expect(project("a\n")).toContain("3 | a\n4 | \n</context>");
});

it("emits no terminal lines when the captured range is inverted", () => {
const projected = projectComposerContextForProvider({
text: "[log](t3-context://v1/terminal/ctx_t)",
records: [{ ...terminal, lineStart: 10, lineEnd: 5, text: "a\nb\nc\nd\ne\nf" }],
});
expect(projected).toContain('<context kind="terminal" id="ctx_t">');
expect(projected).toContain("terminal: Terminal 1\n</context>");
expect(projected).not.toContain(" | ");
});

it("emits every marker in place and each payload once, escaped, in first-reference order", () => {
const text = [
"Look at ![shot.png](t3-context://v1/image/ctx_i) and [T1](t3-context://v1/terminal/ctx_t).",
Expand Down
3 changes: 2 additions & 1 deletion packages/shared/src/composerContextReferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,10 @@ function formatComposerContextProviderPayload(record: KnownComposerContextRecord
`attachmentId: ${record.attachmentId}`,
].join("\n");
case "terminal": {
const lineCount = Math.max(0, record.lineEnd - record.lineStart + 1);
const lines = record.text
.split("\n")
.slice(0, record.lineEnd - record.lineStart + 1)
.slice(0, lineCount)
.map((line, index) => `${record.lineStart + index} | ${line}`);
return [`terminal: ${record.terminalLabel}`, ...lines].join("\n");
}
Expand Down
Loading