noguard 1.0.0 → 1.1.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/bin/noguard.mjs +216 -154
- package/lib/agent.mjs +449 -0
- package/lib/chat.mjs +377 -325
- package/lib/config.mjs +2 -2
- package/lib/context.mjs +115 -0
- package/lib/files.mjs +168 -0
- package/lib/render.mjs +253 -0
- package/lib/shell.mjs +84 -0
- package/lib/tools.mjs +528 -0
- package/package.json +2 -2
package/bin/noguard.mjs
CHANGED
|
@@ -1,154 +1,216 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const VERSION = '1.
|
|
4
|
-
const HELP = `
|
|
5
|
-
\x1b[1mNoGuard AI CLI v${VERSION}\x1b[0m
|
|
6
|
-
The AI that doesn't say no —
|
|
7
|
-
|
|
8
|
-
\x1b[
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
noguard
|
|
13
|
-
noguard
|
|
14
|
-
noguard
|
|
15
|
-
noguard
|
|
16
|
-
noguard
|
|
17
|
-
noguard
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
break
|
|
112
|
-
}
|
|
113
|
-
case '
|
|
114
|
-
const {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
if (
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
console.log(
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
console.log(
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
case
|
|
139
|
-
const
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const VERSION = '1.1.0'
|
|
4
|
+
const HELP = `
|
|
5
|
+
\x1b[1mNoGuard AI CLI v${VERSION}\x1b[0m
|
|
6
|
+
The AI that doesn't say no — in your terminal, working on your project.
|
|
7
|
+
|
|
8
|
+
Run \x1b[1mnoguard\x1b[0m inside a project folder. NoGuard can read, search and edit its files
|
|
9
|
+
and run commands there, asking you before it changes anything.
|
|
10
|
+
|
|
11
|
+
\x1b[1mUsage:\x1b[0m
|
|
12
|
+
noguard Start a session in the current folder
|
|
13
|
+
noguard "task" Start a session with a first message
|
|
14
|
+
noguard -p "task" Do one task and print the result (no prompts; pipe input works too)
|
|
15
|
+
noguard login Sign in with your NoGuard account
|
|
16
|
+
noguard logout Sign out and revoke the token
|
|
17
|
+
noguard me Show your account and credits
|
|
18
|
+
noguard models List available models with tiers and pricing
|
|
19
|
+
noguard usage [--days N] Show credit usage history
|
|
20
|
+
noguard config Show config file location
|
|
21
|
+
noguard endpoint [URL] Show or set the API endpoint
|
|
22
|
+
|
|
23
|
+
\x1b[1mOptions:\x1b[0m
|
|
24
|
+
--model, -m <name> Choose a model (alias or name, e.g. noguard-ultra)
|
|
25
|
+
--print, -p Print mode: run one task and exit
|
|
26
|
+
--accept-edits Let NoGuard edit files without asking (still asks before commands)
|
|
27
|
+
--yolo Let NoGuard edit files and run commands without asking
|
|
28
|
+
--no-tools Chat only: NoGuard can't see or change files
|
|
29
|
+
--help, -h Show this help
|
|
30
|
+
--version, -v Show version
|
|
31
|
+
|
|
32
|
+
\x1b[1mIn-session commands:\x1b[0m
|
|
33
|
+
/models, /model <name> List models, switch model
|
|
34
|
+
/mode [ask|accept-edits|yolo] Show or change what needs your approval
|
|
35
|
+
/init Write a NOGUARD.md describing this project
|
|
36
|
+
/compact Free context by dropping old tool output
|
|
37
|
+
/libraries, /library <id> Research libraries
|
|
38
|
+
/clear Start a new conversation
|
|
39
|
+
/credits Show remaining credits
|
|
40
|
+
/help, /exit
|
|
41
|
+
|
|
42
|
+
\x1b[1mProject instructions:\x1b[0m
|
|
43
|
+
NoGuard reads NOGUARD.md (and CLAUDE.md or AGENTS.md) from the project folder and
|
|
44
|
+
its parents, and ~/.noguard/NOGUARD.md, at the start of each session.
|
|
45
|
+
`
|
|
46
|
+
|
|
47
|
+
const COMMANDS = new Set(['login', 'logout', 'me', 'models', 'usage', 'config', 'endpoint', 'chat'])
|
|
48
|
+
const VALUE_FLAGS = new Set(['--model', '-m', '--days'])
|
|
49
|
+
|
|
50
|
+
function parseArgs(argv) {
|
|
51
|
+
const flags = new Set()
|
|
52
|
+
const values = {}
|
|
53
|
+
const positional = []
|
|
54
|
+
for (let i = 0; i < argv.length; i++) {
|
|
55
|
+
const arg = argv[i]
|
|
56
|
+
if (VALUE_FLAGS.has(arg)) values[arg] = argv[++i]
|
|
57
|
+
else if (arg.startsWith('-') && arg.length > 1) flags.add(arg)
|
|
58
|
+
else positional.push(arg)
|
|
59
|
+
}
|
|
60
|
+
return { flags, values, positional }
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Piped input. With a typed task too, an open stdin that sends nothing (scripts, CI) is not waited on. */
|
|
64
|
+
function readStdin(optional) {
|
|
65
|
+
if (process.stdin.isTTY) return Promise.resolve('')
|
|
66
|
+
return new Promise(resolve => {
|
|
67
|
+
const chunks = []
|
|
68
|
+
const done = () => { clearTimeout(idle); process.stdin.destroy(); resolve(Buffer.concat(chunks).toString('utf8')) }
|
|
69
|
+
const idle = optional ? setTimeout(done, 500) : null
|
|
70
|
+
process.stdin.on('data', chunk => { clearTimeout(idle); chunks.push(chunk) })
|
|
71
|
+
process.stdin.on('end', done)
|
|
72
|
+
process.stdin.on('error', done)
|
|
73
|
+
})
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
async function main() {
|
|
77
|
+
const args = process.argv.slice(2)
|
|
78
|
+
const { flags, values, positional } = parseArgs(args)
|
|
79
|
+
const command = COMMANDS.has(positional[0]) ? positional[0] : positional.length ? 'prompt' : undefined
|
|
80
|
+
|
|
81
|
+
if (flags.has('--help') || flags.has('-h')) {
|
|
82
|
+
console.log(HELP)
|
|
83
|
+
return
|
|
84
|
+
}
|
|
85
|
+
if (flags.has('--version') || flags.has('-v')) {
|
|
86
|
+
console.log(VERSION)
|
|
87
|
+
return
|
|
88
|
+
}
|
|
89
|
+
const session = {
|
|
90
|
+
model: values['--model'] ?? values['-m'],
|
|
91
|
+
tools: !flags.has('--no-tools'),
|
|
92
|
+
mode: flags.has('--yolo') || flags.has('--dangerously-skip-permissions') ? 'yolo' : flags.has('--accept-edits') ? 'accept-edits' : 'ask',
|
|
93
|
+
}
|
|
94
|
+
if (flags.has('-p') || flags.has('--print')) {
|
|
95
|
+
const typed = (command === 'chat' ? positional.slice(1) : positional).join(' ')
|
|
96
|
+
const piped = await readStdin(Boolean(typed))
|
|
97
|
+
const prompt = [typed, piped.trim()].filter(Boolean).join('\n\n')
|
|
98
|
+
if (!prompt) {
|
|
99
|
+
console.error('\x1b[31m✗\x1b[0m Give a task: noguard -p "what to do" (or pipe text in).')
|
|
100
|
+
process.exit(1)
|
|
101
|
+
}
|
|
102
|
+
const { runOnce } = await import('../lib/chat.mjs')
|
|
103
|
+
await runOnce({ ...session, prompt })
|
|
104
|
+
return
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
switch (command) {
|
|
108
|
+
case 'login': {
|
|
109
|
+
const { login } = await import('../lib/auth.mjs')
|
|
110
|
+
await login()
|
|
111
|
+
break
|
|
112
|
+
}
|
|
113
|
+
case 'logout': {
|
|
114
|
+
const { logout } = await import('../lib/auth.mjs')
|
|
115
|
+
await logout()
|
|
116
|
+
break
|
|
117
|
+
}
|
|
118
|
+
case 'me': {
|
|
119
|
+
const { getToken } = await import('../lib/config.mjs')
|
|
120
|
+
const { get } = await import('../lib/api.mjs')
|
|
121
|
+
if (!getToken()) { console.log('\x1b[31m✗\x1b[0m Not signed in. Run \x1b[1mnoguard login\x1b[0m first.'); return }
|
|
122
|
+
try {
|
|
123
|
+
const me = await get('/api/v1/me')
|
|
124
|
+
console.log()
|
|
125
|
+
console.log(` \x1b[1mAccount\x1b[0m`)
|
|
126
|
+
console.log(` Email: ${me.email}`)
|
|
127
|
+
console.log(` Tier: ${me.tier}`)
|
|
128
|
+
console.log(` Verified: ${me.verified ? '\x1b[32myes\x1b[0m' : '\x1b[31mno\x1b[0m'}`)
|
|
129
|
+
console.log(` Credits: \x1b[33m${me.credits}\x1b[0m (${me.available} available)`)
|
|
130
|
+
console.log(` Token: ${me.token.name} (${me.token.uid})`)
|
|
131
|
+
console.log()
|
|
132
|
+
} catch (err) {
|
|
133
|
+
if (err.status === 401) console.log('\x1b[31m✗\x1b[0m Session expired. Run \x1b[1mnoguard login\x1b[0m again.')
|
|
134
|
+
else console.error(`\x1b[31m✗\x1b[0m ${err.message}`)
|
|
135
|
+
}
|
|
136
|
+
break
|
|
137
|
+
}
|
|
138
|
+
case 'models': {
|
|
139
|
+
const { get } = await import('../lib/api.mjs')
|
|
140
|
+
const { printModels } = await import('../lib/chat.mjs')
|
|
141
|
+
try {
|
|
142
|
+
const res = await get('/api/v1/models')
|
|
143
|
+
printModels(res.data)
|
|
144
|
+
} catch (err) {
|
|
145
|
+
console.error(`\x1b[31m✗\x1b[0m ${err.message}`)
|
|
146
|
+
}
|
|
147
|
+
break
|
|
148
|
+
}
|
|
149
|
+
case 'usage': {
|
|
150
|
+
const { getToken } = await import('../lib/config.mjs')
|
|
151
|
+
const { get } = await import('../lib/api.mjs')
|
|
152
|
+
if (!getToken()) { console.log('\x1b[31m✗\x1b[0m Not signed in. Run \x1b[1mnoguard login\x1b[0m first.'); return }
|
|
153
|
+
const days = parseInt(values['--days'], 10) || 30
|
|
154
|
+
try {
|
|
155
|
+
const res = await get(`/api/v1/usage?days=${days}`)
|
|
156
|
+
console.log()
|
|
157
|
+
console.log(` \x1b[1mUsage (last ${res.days_covered} days)\x1b[0m`)
|
|
158
|
+
if (res.by_day?.length) {
|
|
159
|
+
for (const day of res.by_day) {
|
|
160
|
+
console.log(` ${day.date} \x1b[33m${day.credits_spent}\x1b[0m credits ${day.requests} requests`)
|
|
161
|
+
}
|
|
162
|
+
} else {
|
|
163
|
+
console.log(' \x1b[2mNo usage yet.\x1b[0m')
|
|
164
|
+
}
|
|
165
|
+
console.log()
|
|
166
|
+
} catch (err) {
|
|
167
|
+
if (err.status === 401) console.log('\x1b[31m✗\x1b[0m Session expired. Run \x1b[1mnoguard login\x1b[0m again.')
|
|
168
|
+
else console.error(`\x1b[31m✗\x1b[0m ${err.message}`)
|
|
169
|
+
}
|
|
170
|
+
break
|
|
171
|
+
}
|
|
172
|
+
case 'config': {
|
|
173
|
+
const { configPath, load } = await import('../lib/config.mjs')
|
|
174
|
+
const cfg = load()
|
|
175
|
+
console.log()
|
|
176
|
+
console.log(` \x1b[1mConfig\x1b[0m`)
|
|
177
|
+
console.log(` File: ${configPath()}`)
|
|
178
|
+
console.log(` Endpoint: ${cfg.endpoint ?? 'https://noguard.ai'}`)
|
|
179
|
+
console.log(` Signed: ${cfg.token ? '\x1b[32myes\x1b[0m' : '\x1b[31mno\x1b[0m'}`)
|
|
180
|
+
if (cfg.account) console.log(` Account: ${cfg.account.email}`)
|
|
181
|
+
console.log()
|
|
182
|
+
break
|
|
183
|
+
}
|
|
184
|
+
case 'endpoint': {
|
|
185
|
+
const sub = positional[1]
|
|
186
|
+
if (sub) {
|
|
187
|
+
const { setEndpoint } = await import('../lib/config.mjs')
|
|
188
|
+
setEndpoint(sub)
|
|
189
|
+
console.log(`\x1b[32m✓\x1b[0m Endpoint set to \x1b[1m${sub}\x1b[0m`)
|
|
190
|
+
} else {
|
|
191
|
+
const { getEndpoint } = await import('../lib/config.mjs')
|
|
192
|
+
console.log(getEndpoint())
|
|
193
|
+
}
|
|
194
|
+
break
|
|
195
|
+
}
|
|
196
|
+
case 'prompt':
|
|
197
|
+
case 'chat':
|
|
198
|
+
case undefined: {
|
|
199
|
+
const words = command === 'chat' ? positional.slice(1) : positional
|
|
200
|
+
// A lone word is more likely a mistyped command than a task.
|
|
201
|
+
if (command === 'prompt' && words.length === 1 && !/\s/.test(words[0])) {
|
|
202
|
+
console.log(`\x1b[31m✗\x1b[0m Unknown command: ${words[0]}`)
|
|
203
|
+
console.log(' Run \x1b[1mnoguard --help\x1b[0m for usage, or quote a task: noguard "fix the failing test"')
|
|
204
|
+
process.exit(1)
|
|
205
|
+
}
|
|
206
|
+
const { chat } = await import('../lib/chat.mjs')
|
|
207
|
+
await chat({ ...session, prompt: words.join(' ') || undefined })
|
|
208
|
+
break
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
main().catch(err => {
|
|
214
|
+
console.error(`\x1b[31m✗\x1b[0m ${err.message}`)
|
|
215
|
+
process.exit(1)
|
|
216
|
+
})
|