noguard 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/shell.mjs CHANGED
@@ -1,84 +1,84 @@
1
- // Running the model's shell commands: Git Bash or PowerShell on Windows, the user's shell elsewhere.
2
-
3
- import { spawn, spawnSync } from 'node:child_process'
4
- import { existsSync } from 'node:fs'
5
- import { basename, join } from 'node:path'
6
-
7
- const MAX_CAPTURE = 4 * 1024 * 1024
8
-
9
- let detected
10
- export function detectShell() {
11
- if (detected) return detected
12
- const override = process.env.NOGUARD_SHELL
13
- if (override) {
14
- const name = basename(override).toLowerCase()
15
- const kind = name.startsWith('pwsh') || name.startsWith('powershell') ? 'powershell' : name.startsWith('cmd') ? 'cmd' : 'bash'
16
- return (detected = { kind, path: override, label: name })
17
- }
18
- if (process.platform === 'win32') {
19
- const roots = [process.env.ProgramFiles, process.env['ProgramFiles(x86)'], process.env.LOCALAPPDATA && join(process.env.LOCALAPPDATA, 'Programs')]
20
- for (const root of roots.filter(Boolean)) {
21
- const bash = join(root, 'Git', 'bin', 'bash.exe')
22
- if (existsSync(bash)) return (detected = { kind: 'bash', path: bash, label: 'Git Bash' })
23
- }
24
- const pwsh = spawnSync('pwsh', ['-NoLogo', '-NoProfile', '-Command', '$PSVersionTable.PSVersion.Major'], { stdio: 'ignore', windowsHide: true }).status === 0
25
- return (detected = pwsh
26
- ? { kind: 'powershell', path: 'pwsh', label: 'PowerShell 7' }
27
- : { kind: 'powershell', path: 'powershell.exe', label: 'Windows PowerShell 5.1' })
28
- }
29
- const shell = process.env.SHELL && existsSync(process.env.SHELL) ? process.env.SHELL : existsSync('/bin/bash') ? '/bin/bash' : '/bin/sh'
30
- return (detected = { kind: 'bash', path: shell, label: basename(shell) })
31
- }
32
-
33
- function argsFor(shell, command) {
34
- if (shell.kind === 'powershell') {
35
- // -EncodedCommand sidesteps Windows command-line quoting entirely.
36
- const script = `[Console]::OutputEncoding=[System.Text.Encoding]::UTF8; $ProgressPreference='SilentlyContinue'\n${command}`
37
- return ['-NoLogo', '-NoProfile', '-NonInteractive', '-ExecutionPolicy', 'Bypass', '-EncodedCommand', Buffer.from(script, 'utf16le').toString('base64')]
38
- }
39
- if (shell.kind === 'cmd') return ['/d', '/s', '/c', command]
40
- return ['-c', command]
41
- }
42
-
43
- function killTree(child) {
44
- if (!child.pid) return
45
- if (process.platform === 'win32') spawn('taskkill', ['/pid', String(child.pid), '/T', '/F'], { stdio: 'ignore', windowsHide: true })
46
- else {
47
- try { process.kill(-child.pid, 'SIGKILL') } catch { try { child.kill('SIGKILL') } catch { /* already gone */ } }
48
- }
49
- }
50
-
51
- /** Runs one command to completion. Output is stdout and stderr interleaved, as a terminal would show it. */
52
- export function runCommand(command, { cwd, timeoutMs = 120_000, signal } = {}) {
53
- const shell = detectShell()
54
- return new Promise(resolvePromise => {
55
- const child = spawn(shell.path, argsFor(shell, command), {
56
- cwd,
57
- windowsHide: true,
58
- detached: process.platform !== 'win32',
59
- stdio: ['ignore', 'pipe', 'pipe'],
60
- env: { ...process.env, NOGUARD: '1', GIT_PAGER: 'cat', PAGER: 'cat', GIT_TERMINAL_PROMPT: '0' },
61
- })
62
- const chunks = []
63
- let size = 0
64
- const take = chunk => {
65
- if (size < MAX_CAPTURE) chunks.push(chunk)
66
- size += chunk.length
67
- }
68
- child.stdout.on('data', take)
69
- child.stderr.on('data', take)
70
- let timedOut = false, aborted = false
71
- const timer = setTimeout(() => { timedOut = true; killTree(child) }, timeoutMs)
72
- const onAbort = () => { aborted = true; killTree(child) }
73
- signal?.addEventListener('abort', onAbort, { once: true })
74
- const finish = (code, error) => {
75
- clearTimeout(timer)
76
- signal?.removeEventListener('abort', onAbort)
77
- let output = Buffer.concat(chunks).toString('utf8').replace(/\r\n/g, '\n')
78
- if (size > MAX_CAPTURE) output += `\n… [${size - MAX_CAPTURE} more bytes not captured]`
79
- resolvePromise({ output, code, timedOut, aborted, error })
80
- }
81
- child.on('error', error => finish(null, error.message))
82
- child.on('close', code => finish(code))
83
- })
84
- }
1
+ // Running the model's shell commands: Git Bash or PowerShell on Windows, the user's shell elsewhere.
2
+
3
+ import { spawn, spawnSync } from 'node:child_process'
4
+ import { existsSync } from 'node:fs'
5
+ import { basename, join } from 'node:path'
6
+
7
+ const MAX_CAPTURE = 4 * 1024 * 1024
8
+
9
+ let detected
10
+ export function detectShell() {
11
+ if (detected) return detected
12
+ const override = process.env.NOGUARD_SHELL
13
+ if (override) {
14
+ const name = basename(override).toLowerCase()
15
+ const kind = name.startsWith('pwsh') || name.startsWith('powershell') ? 'powershell' : name.startsWith('cmd') ? 'cmd' : 'bash'
16
+ return (detected = { kind, path: override, label: name })
17
+ }
18
+ if (process.platform === 'win32') {
19
+ const roots = [process.env.ProgramFiles, process.env['ProgramFiles(x86)'], process.env.LOCALAPPDATA && join(process.env.LOCALAPPDATA, 'Programs')]
20
+ for (const root of roots.filter(Boolean)) {
21
+ const bash = join(root, 'Git', 'bin', 'bash.exe')
22
+ if (existsSync(bash)) return (detected = { kind: 'bash', path: bash, label: 'Git Bash' })
23
+ }
24
+ const pwsh = spawnSync('pwsh', ['-NoLogo', '-NoProfile', '-Command', '$PSVersionTable.PSVersion.Major'], { stdio: 'ignore', windowsHide: true }).status === 0
25
+ return (detected = pwsh
26
+ ? { kind: 'powershell', path: 'pwsh', label: 'PowerShell 7' }
27
+ : { kind: 'powershell', path: 'powershell.exe', label: 'Windows PowerShell 5.1' })
28
+ }
29
+ const shell = process.env.SHELL && existsSync(process.env.SHELL) ? process.env.SHELL : existsSync('/bin/bash') ? '/bin/bash' : '/bin/sh'
30
+ return (detected = { kind: 'bash', path: shell, label: basename(shell) })
31
+ }
32
+
33
+ function argsFor(shell, command) {
34
+ if (shell.kind === 'powershell') {
35
+ // -EncodedCommand sidesteps Windows command-line quoting entirely.
36
+ const script = `[Console]::OutputEncoding=[System.Text.Encoding]::UTF8; $ProgressPreference='SilentlyContinue'\n${command}`
37
+ return ['-NoLogo', '-NoProfile', '-NonInteractive', '-ExecutionPolicy', 'Bypass', '-EncodedCommand', Buffer.from(script, 'utf16le').toString('base64')]
38
+ }
39
+ if (shell.kind === 'cmd') return ['/d', '/s', '/c', command]
40
+ return ['-c', command]
41
+ }
42
+
43
+ function killTree(child) {
44
+ if (!child.pid) return
45
+ if (process.platform === 'win32') spawn('taskkill', ['/pid', String(child.pid), '/T', '/F'], { stdio: 'ignore', windowsHide: true })
46
+ else {
47
+ try { process.kill(-child.pid, 'SIGKILL') } catch { try { child.kill('SIGKILL') } catch { /* already gone */ } }
48
+ }
49
+ }
50
+
51
+ /** Runs one command to completion. Output is stdout and stderr interleaved, as a terminal would show it. */
52
+ export function runCommand(command, { cwd, timeoutMs = 120_000, signal } = {}) {
53
+ const shell = detectShell()
54
+ return new Promise(resolvePromise => {
55
+ const child = spawn(shell.path, argsFor(shell, command), {
56
+ cwd,
57
+ windowsHide: true,
58
+ detached: process.platform !== 'win32',
59
+ stdio: ['ignore', 'pipe', 'pipe'],
60
+ env: { ...process.env, NOGUARD: '1', GIT_PAGER: 'cat', PAGER: 'cat', GIT_TERMINAL_PROMPT: '0' },
61
+ })
62
+ const chunks = []
63
+ let size = 0
64
+ const take = chunk => {
65
+ if (size < MAX_CAPTURE) chunks.push(chunk)
66
+ size += chunk.length
67
+ }
68
+ child.stdout.on('data', take)
69
+ child.stderr.on('data', take)
70
+ let timedOut = false, aborted = false
71
+ const timer = setTimeout(() => { timedOut = true; killTree(child) }, timeoutMs)
72
+ const onAbort = () => { aborted = true; killTree(child) }
73
+ signal?.addEventListener('abort', onAbort, { once: true })
74
+ const finish = (code, error) => {
75
+ clearTimeout(timer)
76
+ signal?.removeEventListener('abort', onAbort)
77
+ let output = Buffer.concat(chunks).toString('utf8').replace(/\r\n/g, '\n')
78
+ if (size > MAX_CAPTURE) output += `\n… [${size - MAX_CAPTURE} more bytes not captured]`
79
+ resolvePromise({ output, code, timedOut, aborted, error })
80
+ }
81
+ child.on('error', error => finish(null, error.message))
82
+ child.on('close', code => finish(code))
83
+ })
84
+ }
package/package.json CHANGED
@@ -1,23 +1,23 @@
1
- {
2
- "name": "noguard",
3
- "version": "1.2.0",
4
- "description": "NoGuard AI — the AI that doesn't say no. An agent in your terminal that reads, edits and runs your project.",
5
- "type": "module",
6
- "bin": {
7
- "noguard": "bin/noguard.mjs"
8
- },
9
- "files": [
10
- "bin/",
11
- "lib/"
12
- ],
13
- "keywords": [
14
- "noguard",
15
- "ai",
16
- "cli",
17
- "chat"
18
- ],
19
- "license": "UNLICENSED",
20
- "engines": {
21
- "node": ">=18"
22
- }
23
- }
1
+ {
2
+ "name": "noguard",
3
+ "version": "1.3.0",
4
+ "description": "NoGuard AI — the AI that doesn't say no. An agent in your terminal that reads, edits and runs your project.",
5
+ "type": "module",
6
+ "bin": {
7
+ "noguard": "bin/noguard.mjs"
8
+ },
9
+ "files": [
10
+ "bin/",
11
+ "lib/"
12
+ ],
13
+ "keywords": [
14
+ "noguard",
15
+ "ai",
16
+ "cli",
17
+ "chat"
18
+ ],
19
+ "license": "UNLICENSED",
20
+ "engines": {
21
+ "node": ">=18"
22
+ }
23
+ }