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

Function writeAdditionalSystemContext

src/node/services/additionalSystemContext.ts:74–97  ·  view source on GitHub ↗
(
  config: SessionDirProvider,
  workspaceId: string,
  record: AdditionalSystemContextRecord
)

Source from the content-addressed store, hash-verified

72}
73
74export async function writeAdditionalSystemContext(
75 config: SessionDirProvider,
76 workspaceId: string,
77 record: AdditionalSystemContextRecord
78): Promise<void> {
79 const filePath = getAdditionalSystemContextPath(config, workspaceId);
80 const disabledPath = getAdditionalSystemContextDisabledPath(config, workspaceId);
81 await ensurePrivateDir(path.dirname(filePath));
82
83 // Empty scratchpads should behave like missing files so fork/copy and prompt
84 // injection don't carry around blank durable state. We also drop the
85 // disabled marker so the next non-empty edit defaults to enabled.
86 if (record.content.length === 0) {
87 await Promise.all([fs.rm(filePath, { force: true }), fs.rm(disabledPath, { force: true })]);
88 return;
89 }
90
91 await fs.writeFile(filePath, record.content, "utf-8");
92 if (record.enabled) {
93 await fs.rm(disabledPath, { force: true });
94 } else {
95 await fs.writeFile(disabledPath, "", "utf-8");
96 }
97}
98
99/**
100 * Effective scratchpad text for prompt injection: the content when enabled,

Calls 4

ensurePrivateDirFunction · 0.90
writeFileMethod · 0.65

Tested by

no test coverage detected