MCPcopy
hub / github.com/coder/mux / writeChatWithBoundary

Function writeChatWithBoundary

src/node/services/historyService.test.ts:809–863  ·  view source on GitHub ↗

* Helper: write a chat.jsonl file with messages that include a compaction boundary. * Returns { preBoundaryIds, boundaryId, postBoundaryIds }.

(
    cfg: Config,
    workspaceId: string,
    opts: { preBoundaryCount: number; postBoundaryCount: number; epoch?: number }
  )

Source from the content-addressed store, hash-verified

807 * Returns { preBoundaryIds, boundaryId, postBoundaryIds }.
808 */
809 async function writeChatWithBoundary(
810 cfg: Config,
811 workspaceId: string,
812 opts: { preBoundaryCount: number; postBoundaryCount: number; epoch?: number }
813 ) {
814 const workspaceDir = cfg.getSessionDir(workspaceId);
815 await fs.mkdir(workspaceDir, { recursive: true });
816
817 const epoch = opts.epoch ?? 1;
818 const lines: string[] = [];
819 const preBoundaryIds: string[] = [];
820 const postBoundaryIds: string[] = [];
821 let seq = 0;
822
823 // Pre-boundary messages
824 for (let i = 0; i < opts.preBoundaryCount; i++) {
825 const id = `pre-${i}`;
826 preBoundaryIds.push(id);
827 lines.push(
828 JSON.stringify({
829 ...createMuxMessage(id, "user", `message ${i}`, { historySequence: seq++ }),
830 workspaceId,
831 })
832 );
833 }
834
835 // Compaction boundary message
836 const boundaryId = `boundary-${epoch}`;
837 lines.push(
838 JSON.stringify({
839 ...createMuxMessage(boundaryId, "assistant", "Compaction summary", {
840 historySequence: seq++,
841 compactionBoundary: true,
842 compacted: "user",
843 compactionEpoch: epoch,
844 }),
845 workspaceId,
846 })
847 );
848
849 // Post-boundary messages
850 for (let i = 0; i < opts.postBoundaryCount; i++) {
851 const id = `post-${i}`;
852 postBoundaryIds.push(id);
853 lines.push(
854 JSON.stringify({
855 ...createMuxMessage(id, "user", `post message ${i}`, { historySequence: seq++ }),
856 workspaceId,
857 })
858 );
859 }
860
861 await fs.writeFile(path.join(workspaceDir, "chat.jsonl"), lines.join("\n") + "\n");
862 return { preBoundaryIds, boundaryId, postBoundaryIds };
863 }
864
865 describe("getHistoryFromLatestBoundary", () => {
866 it("should return full history when no boundary exists", async () => {

Callers 1

Calls 4

createMuxMessageFunction · 0.90
getSessionDirMethod · 0.65
pushMethod · 0.65
writeFileMethod · 0.65

Tested by

no test coverage detected