MCPcopy Create free account
hub / github.com/Noumena-Network/code / getPromptForCommand

Function getPromptForCommand

src/skills/bundled/debug.ts:26–102  ·  view source on GitHub ↗
(args)

Source from the content-addressed store, hash-verified

24 disableModelInvocation: true,
25 userInvocable: true,
26 async getPromptForCommand(args) {
27 // Non-Noumena builds don't write debug logs by default — turn logging on now so
28 // subsequent activity in this session is captured.
29 const wasAlreadyLogging = enableDebugLogging()
30 const debugLogPath = getDebugLogPath()
31
32 let logInfo: string
33 try {
34 // Tail the log without reading the whole thing - debug logs grow
35 // unbounded in long sessions and reading them in full spikes RSS.
36 const stats = await stat(debugLogPath)
37 const readSize = Math.min(stats.size, TAIL_READ_BYTES)
38 const startOffset = stats.size - readSize
39 const fd = await open(debugLogPath, 'r')
40 try {
41 const { buffer, bytesRead } = await fd.read({
42 buffer: Buffer.alloc(readSize),
43 position: startOffset,
44 })
45 const tail = buffer
46 .toString('utf-8', 0, bytesRead)
47 .split('\n')
48 .slice(-DEFAULT_DEBUG_LINES_READ)
49 .join('\n')
50 logInfo = `Log size: ${formatFileSize(stats.size)}\n\n### Last ${DEFAULT_DEBUG_LINES_READ} lines\n\n\`\`\`\n${tail}\n\`\`\``
51 } finally {
52 await fd.close()
53 }
54 } catch (e) {
55 logInfo = isENOENT(e)
56 ? 'No debug log exists yet — logging was just enabled.'
57 : `Failed to read last ${DEFAULT_DEBUG_LINES_READ} lines of debug log: ${errorMessage(e)}`
58 }
59
60 const justEnabledSection = wasAlreadyLogging
61 ? ''
62 : `
63## Debug Logging Just Enabled
64
65Debug logging was OFF for this session until now. Nothing prior to this /debug invocation was captured.
66
67Tell the user that debug logging is now active at \`${debugLogPath}\`, ask them to reproduce the issue, then re-read the log. If they can't reproduce, they can also restart with \`ncode --debug\` to capture logs from startup.
68`
69
70 const prompt = `# Debug Skill
71
72Help the user debug an issue they're encountering in this current NCode session.
73${justEnabledSection}
74## Session Debug Log
75
76The debug log for the current session is at: \`${debugLogPath}\`
77
78${logInfo}
79
80For additional context, grep for [ERROR] and [WARN] lines across the full file.
81
82## Issue Description
83

Callers

nothing calls this directly

Calls 11

enableDebugLoggingFunction · 0.85
statFunction · 0.85
openFunction · 0.85
formatFileSizeFunction · 0.85
isENOENTFunction · 0.85
toStringMethod · 0.65
getDebugLogPathFunction · 0.50
errorMessageFunction · 0.50
readMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected