MCPcopy
hub / github.com/inkeep/open-knowledge / createBundle

Function createBundle

packages/cli/src/commands/bug-report.ts:105–245  ·  view source on GitHub ↗
(opts: {
  projectSlug: string | null;
  cwd: string;
  noReveal: boolean;
})

Source from the content-addressed store, hash-verified

103}
104
105async function createBundle(opts: {
106 projectSlug: string | null;
107 cwd: string;
108 noReveal: boolean;
109}): Promise<string> {
110 const log = getCliLogger();
111 mkdirSync(OK_BUGS_DIR, { recursive: true });
112
113 const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
114 const zipName = `${timestamp}-bugreport.zip`;
115 const zipPath = join(OK_BUGS_DIR, zipName);
116
117 log?.info({ projectSlug: opts.projectSlug }, 'gathering diagnostic data');
118
119 const sysinfo = collectSysinfo();
120 const { files: logFiles } = collectLogs(opts.projectSlug);
121 const { files: lockFiles } = collectLockDir(opts.cwd);
122 const { files: localSinkFiles } = collectLocalSinkLogs(opts.cwd);
123
124 log?.info(
125 {
126 logFileCount: logFiles.length,
127 lockFileCount: lockFiles.length,
128 localSinkFileCount: localSinkFiles.length,
129 },
130 'files collected',
131 );
132
133 const redactions: BundleRedaction[] = [];
134 const bundleFiles: string[] = [];
135
136 const { ZipFile } = await import('yazl');
137 const zipfile = new ZipFile();
138
139 for (const logFile of logFiles) {
140 try {
141 const raw = readFileSync(logFile, 'utf8');
142 const { redacted, patterns, lineCount } = redactContent(raw);
143 const name = `logs/${basename(logFile)}`;
144 zipfile.addBuffer(Buffer.from(redacted, 'utf8'), name);
145 bundleFiles.push(name);
146 if (patterns.length > 0) {
147 redactions.push({ file: name, lineCount, patterns });
148 }
149 } catch {}
150 }
151
152 for (const lockFile of lockFiles) {
153 try {
154 const raw = readFileSync(lockFile, 'utf8');
155 const { redacted, patterns, lineCount } = redactContent(raw);
156 const name = `lockdir/${basename(lockFile)}`;
157 zipfile.addBuffer(Buffer.from(redacted, 'utf8'), name);
158 bundleFiles.push(name);
159 if (patterns.length > 0) {
160 redactions.push({ file: name, lineCount, patterns });
161 }
162 } catch {}

Callers 1

bugReportCommandFunction · 0.85

Calls 13

getCliLoggerFunction · 0.90
redactContentFunction · 0.90
collectSysinfoFunction · 0.85
collectLogsFunction · 0.85
collectLockDirFunction · 0.85
collectLocalSinkLogsFunction · 0.85
mapMethod · 0.80
infoMethod · 0.65
endMethod · 0.65
onMethod · 0.65
writeMethod · 0.65
basenameFunction · 0.50

Tested by

no test coverage detected