MCPcopy Index your code
hub / github.com/Noumena-Network/code / getClaudeCodeSnapshotContent

Function getClaudeCodeSnapshotContent

src/utils/bash/ShellSnapshot.ts:270–341  ·  view source on GitHub ↗

* Generates NCode specific snapshot content * This content is always included regardless of user configuration

()

Source from the content-addressed store, hash-verified

268 * This content is always included regardless of user configuration
269 */
270async function getClaudeCodeSnapshotContent(): Promise<string> {
271 // Get the appropriate PATH based on platform
272 let pathValue = process.env.PATH
273 if (getPlatform() === 'windows') {
274 // On Windows with git-bash, read the Cygwin PATH
275 const cygwinResult = await execa('echo $PATH', {
276 shell: true,
277 reject: false,
278 })
279 if (cygwinResult.exitCode === 0 && cygwinResult.stdout) {
280 pathValue = cygwinResult.stdout.trim()
281 }
282 // Fall back to process.env.PATH if we can't get Cygwin PATH
283 }
284
285 const rgIntegration = createRipgrepShellIntegration()
286
287 let content = ''
288
289 // Check if rg is available, if not create an alias/function to bundled ripgrep
290 // We use a subshell to unalias rg before checking, so that user aliases like
291 // `alias rg='rg --smart-case'` don't shadow the real binary check. The subshell
292 // ensures we don't modify the user's aliases in the parent shell.
293 content += `
294 # Check for rg availability
295 echo "# Check for rg availability" >> "$SNAPSHOT_FILE"
296 echo "if ! (unalias rg 2>/dev/null; command -v rg) >/dev/null 2>&1; then" >> "$SNAPSHOT_FILE"
297 `
298
299 if (rgIntegration.type === 'function') {
300 // For embedded ripgrep, write the function definition using heredoc
301 content += `
302 cat >> "$SNAPSHOT_FILE" << 'RIPGREP_FUNC_END'
303 ${rgIntegration.snippet}
304RIPGREP_FUNC_END
305 `
306 } else {
307 // For regular ripgrep, write a simple alias
308 const escapedSnippet = rgIntegration.snippet.replace(/'/g, "'\\''")
309 content += `
310 echo ' alias rg='"'${escapedSnippet}'" >> "$SNAPSHOT_FILE"
311 `
312 }
313
314 content += `
315 echo "fi" >> "$SNAPSHOT_FILE"
316 `
317
318 // For ant-native builds, shadow find/grep with bfs/ugrep embedded in the bun
319 // binary. Unlike rg (which only activates if system rg is absent), we always
320 // shadow find/grep since bfs/ugrep are drop-in replacements and we want
321 // consistent fast behavior in NCode's shell.
322 const findGrepIntegration = createFindGrepShellIntegration()
323 if (findGrepIntegration !== null) {
324 content += `
325 # Shadow find/grep with embedded bfs/ugrep (ant-native only)
326 echo "# Shadow find/grep with embedded bfs/ugrep" >> "$SNAPSHOT_FILE"
327 cat >> "$SNAPSHOT_FILE" << 'FIND_GREP_FUNC_END'

Callers 1

getSnapshotScriptFunction · 0.85

Calls 4

getPlatformFunction · 0.85
quoteFunction · 0.85

Tested by

no test coverage detected