noguard 1.1.0 → 1.1.1
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 +233 -216
- package/lib/agent.mjs +17 -17
- package/lib/chat.mjs +480 -377
- package/lib/render.mjs +111 -34
- package/package.json +1 -1
package/bin/noguard.mjs
CHANGED
|
@@ -1,216 +1,233 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
noguard
|
|
21
|
-
noguard
|
|
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
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
console.
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
BOLD, RST, UNDERLINE,
|
|
5
|
+
NEON_CYAN, HOT_PINK, LIME, ORANGE, GOLD, SKY, BRIGHT_WHITE, SOFT_GRAY, DARK_GRAY,
|
|
6
|
+
gradient, NOGUARD_GRADIENT, sectionHeader,
|
|
7
|
+
} from '../lib/render.mjs'
|
|
8
|
+
|
|
9
|
+
const VERSION = '1.1.1'
|
|
10
|
+
|
|
11
|
+
function helpText() {
|
|
12
|
+
return `
|
|
13
|
+
${gradient('NoGuard AI CLI', NOGUARD_GRADIENT)} ${SOFT_GRAY}v${VERSION}${RST}
|
|
14
|
+
${SOFT_GRAY}The AI that doesn't say no — in your terminal, working on your project.${RST}
|
|
15
|
+
|
|
16
|
+
Run ${BRIGHT_WHITE}${BOLD}noguard${RST} inside a project folder. NoGuard can read, search and edit its files
|
|
17
|
+
and run commands there, asking you before it changes anything.
|
|
18
|
+
|
|
19
|
+
${GOLD}${BOLD}Usage:${RST}
|
|
20
|
+
${BRIGHT_WHITE}noguard${RST} ${SOFT_GRAY}Start a session in the current folder${RST}
|
|
21
|
+
${BRIGHT_WHITE}noguard${RST} ${SKY}"task"${RST} ${SOFT_GRAY}Start a session with a first message${RST}
|
|
22
|
+
${BRIGHT_WHITE}noguard${RST} ${NEON_CYAN}-p${RST} ${SKY}"task"${RST} ${SOFT_GRAY}Do one task and print the result (pipe input works too)${RST}
|
|
23
|
+
${BRIGHT_WHITE}noguard login${RST} ${SOFT_GRAY}Sign in with your NoGuard account${RST}
|
|
24
|
+
${BRIGHT_WHITE}noguard logout${RST} ${SOFT_GRAY}Sign out and revoke the token${RST}
|
|
25
|
+
${BRIGHT_WHITE}noguard me${RST} ${SOFT_GRAY}Show your account and credits${RST}
|
|
26
|
+
${BRIGHT_WHITE}noguard models${RST} ${SOFT_GRAY}List available models with tiers and pricing${RST}
|
|
27
|
+
${BRIGHT_WHITE}noguard usage${RST} ${NEON_CYAN}[--days N]${RST} ${SOFT_GRAY}Show credit usage history${RST}
|
|
28
|
+
${BRIGHT_WHITE}noguard config${RST} ${SOFT_GRAY}Show config file location${RST}
|
|
29
|
+
${BRIGHT_WHITE}noguard endpoint${RST} ${SKY}[URL]${RST} ${SOFT_GRAY}Show or set the API endpoint${RST}
|
|
30
|
+
|
|
31
|
+
${GOLD}${BOLD}Options:${RST}
|
|
32
|
+
${NEON_CYAN}--model, -m${RST} ${SKY}<name>${RST} ${SOFT_GRAY}Choose a model (alias or name, e.g. noguard-ultra)${RST}
|
|
33
|
+
${NEON_CYAN}--print, -p${RST} ${SOFT_GRAY}Print mode: run one task and exit${RST}
|
|
34
|
+
${NEON_CYAN}--accept-edits${RST} ${SOFT_GRAY}Let NoGuard edit files without asking (still asks before commands)${RST}
|
|
35
|
+
${NEON_CYAN}--yolo${RST} ${SOFT_GRAY}Let NoGuard edit files and run commands without asking${RST}
|
|
36
|
+
${NEON_CYAN}--no-tools${RST} ${SOFT_GRAY}Chat only: NoGuard can't see or change files${RST}
|
|
37
|
+
${NEON_CYAN}--help, -h${RST} ${SOFT_GRAY}Show this help${RST}
|
|
38
|
+
${NEON_CYAN}--version, -v${RST} ${SOFT_GRAY}Show version${RST}
|
|
39
|
+
|
|
40
|
+
${GOLD}${BOLD}In-session commands:${RST}
|
|
41
|
+
${BRIGHT_WHITE}/models, /model <name>${RST} ${SOFT_GRAY}List models, switch model${RST}
|
|
42
|
+
${BRIGHT_WHITE}/mode${RST} ${SKY}[ask|accept-edits|yolo]${RST} ${SOFT_GRAY}Show or change what needs your approval${RST}
|
|
43
|
+
${BRIGHT_WHITE}/status${RST} ${SOFT_GRAY}Show session info, credits, model, and stats${RST}
|
|
44
|
+
${BRIGHT_WHITE}/init${RST} ${SOFT_GRAY}Write a NOGUARD.md describing this project${RST}
|
|
45
|
+
${BRIGHT_WHITE}/compact${RST} ${SOFT_GRAY}Free context by dropping old tool output${RST}
|
|
46
|
+
${BRIGHT_WHITE}/libraries, /library <id>${RST} ${SOFT_GRAY}Research libraries${RST}
|
|
47
|
+
${BRIGHT_WHITE}/clear${RST} ${SOFT_GRAY}Start a new conversation${RST}
|
|
48
|
+
${BRIGHT_WHITE}/credits${RST} ${SOFT_GRAY}Show remaining credits${RST}
|
|
49
|
+
${BRIGHT_WHITE}/help, /exit${RST}
|
|
50
|
+
|
|
51
|
+
${GOLD}${BOLD}Project instructions:${RST}
|
|
52
|
+
NoGuard reads ${SKY}NOGUARD.md${RST} (and ${SKY}CLAUDE.md${RST} or ${SKY}AGENTS.md${RST}) from the project folder and
|
|
53
|
+
its parents, and ${SKY}~/.noguard/NOGUARD.md${RST}, at the start of each session.
|
|
54
|
+
`
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const COMMANDS = new Set(['login', 'logout', 'me', 'models', 'usage', 'config', 'endpoint', 'chat'])
|
|
58
|
+
const VALUE_FLAGS = new Set(['--model', '-m', '--days'])
|
|
59
|
+
|
|
60
|
+
function parseArgs(argv) {
|
|
61
|
+
const flags = new Set()
|
|
62
|
+
const values = {}
|
|
63
|
+
const positional = []
|
|
64
|
+
for (let i = 0; i < argv.length; i++) {
|
|
65
|
+
const arg = argv[i]
|
|
66
|
+
if (VALUE_FLAGS.has(arg)) values[arg] = argv[++i]
|
|
67
|
+
else if (arg.startsWith('-') && arg.length > 1) flags.add(arg)
|
|
68
|
+
else positional.push(arg)
|
|
69
|
+
}
|
|
70
|
+
return { flags, values, positional }
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Piped input. With a typed task too, an open stdin that sends nothing (scripts, CI) is not waited on. */
|
|
74
|
+
function readStdin(optional) {
|
|
75
|
+
if (process.stdin.isTTY) return Promise.resolve('')
|
|
76
|
+
return new Promise(resolve => {
|
|
77
|
+
const chunks = []
|
|
78
|
+
const done = () => { clearTimeout(idle); process.stdin.destroy(); resolve(Buffer.concat(chunks).toString('utf8')) }
|
|
79
|
+
const idle = optional ? setTimeout(done, 500) : null
|
|
80
|
+
process.stdin.on('data', chunk => { clearTimeout(idle); chunks.push(chunk) })
|
|
81
|
+
process.stdin.on('end', done)
|
|
82
|
+
process.stdin.on('error', done)
|
|
83
|
+
})
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function fmtNumber(n) {
|
|
87
|
+
return Number(n).toLocaleString('en-US')
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async function main() {
|
|
91
|
+
const args = process.argv.slice(2)
|
|
92
|
+
const { flags, values, positional } = parseArgs(args)
|
|
93
|
+
const command = COMMANDS.has(positional[0]) ? positional[0] : positional.length ? 'prompt' : undefined
|
|
94
|
+
|
|
95
|
+
if (flags.has('--help') || flags.has('-h')) {
|
|
96
|
+
console.log(helpText())
|
|
97
|
+
return
|
|
98
|
+
}
|
|
99
|
+
if (flags.has('--version') || flags.has('-v')) {
|
|
100
|
+
console.log(`${gradient('NoGuard', NOGUARD_GRADIENT)} ${SOFT_GRAY}v${VERSION}${RST}`)
|
|
101
|
+
return
|
|
102
|
+
}
|
|
103
|
+
const session = {
|
|
104
|
+
model: values['--model'] ?? values['-m'],
|
|
105
|
+
tools: !flags.has('--no-tools'),
|
|
106
|
+
mode: flags.has('--yolo') || flags.has('--dangerously-skip-permissions') ? 'yolo' : flags.has('--accept-edits') ? 'accept-edits' : 'ask',
|
|
107
|
+
}
|
|
108
|
+
if (flags.has('-p') || flags.has('--print')) {
|
|
109
|
+
const typed = (command === 'chat' ? positional.slice(1) : positional).join(' ')
|
|
110
|
+
const piped = await readStdin(Boolean(typed))
|
|
111
|
+
const prompt = [typed, piped.trim()].filter(Boolean).join('\n\n')
|
|
112
|
+
if (!prompt) {
|
|
113
|
+
console.error(`${HOT_PINK}✗${RST} Give a task: ${BRIGHT_WHITE}noguard -p "what to do"${RST} (or pipe text in).`)
|
|
114
|
+
process.exit(1)
|
|
115
|
+
}
|
|
116
|
+
const { runOnce } = await import('../lib/chat.mjs')
|
|
117
|
+
await runOnce({ ...session, prompt })
|
|
118
|
+
return
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
switch (command) {
|
|
122
|
+
case 'login': {
|
|
123
|
+
const { login } = await import('../lib/auth.mjs')
|
|
124
|
+
await login()
|
|
125
|
+
break
|
|
126
|
+
}
|
|
127
|
+
case 'logout': {
|
|
128
|
+
const { logout } = await import('../lib/auth.mjs')
|
|
129
|
+
await logout()
|
|
130
|
+
break
|
|
131
|
+
}
|
|
132
|
+
case 'me': {
|
|
133
|
+
const { getToken } = await import('../lib/config.mjs')
|
|
134
|
+
const { get } = await import('../lib/api.mjs')
|
|
135
|
+
if (!getToken()) { console.log(`${HOT_PINK}✗${RST} Not signed in. Run ${BOLD}noguard login${RST} first.`); return }
|
|
136
|
+
try {
|
|
137
|
+
const me = await get('/api/v1/me')
|
|
138
|
+
const tierColor = me.tier === 'ultra' ? GOLD : me.tier === 'pro' ? LIME : NEON_CYAN
|
|
139
|
+
console.log()
|
|
140
|
+
console.log(sectionHeader('Account'))
|
|
141
|
+
console.log()
|
|
142
|
+
console.log(` ${SOFT_GRAY}Email:${RST} ${BRIGHT_WHITE}${me.email}${RST}`)
|
|
143
|
+
console.log(` ${SOFT_GRAY}Tier:${RST} ${tierColor}${BOLD}${me.tier}${RST}`)
|
|
144
|
+
console.log(` ${SOFT_GRAY}Verified:${RST} ${me.verified ? `${LIME}yes${RST}` : `${HOT_PINK}no${RST}`}`)
|
|
145
|
+
console.log(` ${SOFT_GRAY}Credits:${RST} ${ORANGE}${BOLD}${fmtNumber(me.credits)}${RST} ${DARK_GRAY}(${fmtNumber(me.available)} available)${RST}`)
|
|
146
|
+
console.log(` ${SOFT_GRAY}Token:${RST} ${SKY}${me.token.name}${RST} ${DARK_GRAY}(${me.token.uid})${RST}`)
|
|
147
|
+
console.log()
|
|
148
|
+
} catch (err) {
|
|
149
|
+
if (err.status === 401) console.log(`${HOT_PINK}✗${RST} Session expired. Run ${BOLD}noguard login${RST} again.`)
|
|
150
|
+
else console.error(`${HOT_PINK}✗${RST} ${err.message}`)
|
|
151
|
+
}
|
|
152
|
+
break
|
|
153
|
+
}
|
|
154
|
+
case 'models': {
|
|
155
|
+
const { get } = await import('../lib/api.mjs')
|
|
156
|
+
const { printModels } = await import('../lib/chat.mjs')
|
|
157
|
+
try {
|
|
158
|
+
const res = await get('/api/v1/models')
|
|
159
|
+
printModels(res.data)
|
|
160
|
+
} catch (err) {
|
|
161
|
+
console.error(`${HOT_PINK}✗${RST} ${err.message}`)
|
|
162
|
+
}
|
|
163
|
+
break
|
|
164
|
+
}
|
|
165
|
+
case 'usage': {
|
|
166
|
+
const { getToken } = await import('../lib/config.mjs')
|
|
167
|
+
const { get } = await import('../lib/api.mjs')
|
|
168
|
+
if (!getToken()) { console.log(`${HOT_PINK}✗${RST} Not signed in. Run ${BOLD}noguard login${RST} first.`); return }
|
|
169
|
+
const days = parseInt(values['--days'], 10) || 30
|
|
170
|
+
try {
|
|
171
|
+
const res = await get(`/api/v1/usage?days=${days}`)
|
|
172
|
+
console.log()
|
|
173
|
+
console.log(sectionHeader(`Usage (last ${res.days_covered} days)`))
|
|
174
|
+
console.log()
|
|
175
|
+
if (res.by_day?.length) {
|
|
176
|
+
for (const day of res.by_day) {
|
|
177
|
+
console.log(` ${BRIGHT_WHITE}${day.date}${RST} ${ORANGE}${BOLD}${fmtNumber(day.credits_spent)}${RST} ${SOFT_GRAY}credits${RST} ${DARK_GRAY}${day.requests} requests${RST}`)
|
|
178
|
+
}
|
|
179
|
+
} else {
|
|
180
|
+
console.log(` ${SOFT_GRAY}No usage yet.${RST}`)
|
|
181
|
+
}
|
|
182
|
+
console.log()
|
|
183
|
+
} catch (err) {
|
|
184
|
+
if (err.status === 401) console.log(`${HOT_PINK}✗${RST} Session expired. Run ${BOLD}noguard login${RST} again.`)
|
|
185
|
+
else console.error(`${HOT_PINK}✗${RST} ${err.message}`)
|
|
186
|
+
}
|
|
187
|
+
break
|
|
188
|
+
}
|
|
189
|
+
case 'config': {
|
|
190
|
+
const { configPath, load } = await import('../lib/config.mjs')
|
|
191
|
+
const cfg = load()
|
|
192
|
+
console.log()
|
|
193
|
+
console.log(sectionHeader('Config'))
|
|
194
|
+
console.log()
|
|
195
|
+
console.log(` ${SOFT_GRAY}File:${RST} ${SKY}${configPath()}${RST}`)
|
|
196
|
+
console.log(` ${SOFT_GRAY}Endpoint:${RST} ${BRIGHT_WHITE}${cfg.endpoint ?? 'https://noguard.ai'}${RST}`)
|
|
197
|
+
console.log(` ${SOFT_GRAY}Signed:${RST} ${cfg.token ? `${LIME}yes${RST}` : `${HOT_PINK}no${RST}`}`)
|
|
198
|
+
if (cfg.account) console.log(` ${SOFT_GRAY}Account:${RST} ${BRIGHT_WHITE}${cfg.account.email}${RST}`)
|
|
199
|
+
console.log()
|
|
200
|
+
break
|
|
201
|
+
}
|
|
202
|
+
case 'endpoint': {
|
|
203
|
+
const sub = positional[1]
|
|
204
|
+
if (sub) {
|
|
205
|
+
const { setEndpoint } = await import('../lib/config.mjs')
|
|
206
|
+
setEndpoint(sub)
|
|
207
|
+
console.log(`${LIME}✓${RST} Endpoint set to ${BRIGHT_WHITE}${BOLD}${sub}${RST}`)
|
|
208
|
+
} else {
|
|
209
|
+
const { getEndpoint } = await import('../lib/config.mjs')
|
|
210
|
+
console.log(getEndpoint())
|
|
211
|
+
}
|
|
212
|
+
break
|
|
213
|
+
}
|
|
214
|
+
case 'prompt':
|
|
215
|
+
case 'chat':
|
|
216
|
+
case undefined: {
|
|
217
|
+
const words = command === 'chat' ? positional.slice(1) : positional
|
|
218
|
+
if (command === 'prompt' && words.length === 1 && !/\s/.test(words[0])) {
|
|
219
|
+
console.log(`${HOT_PINK}✗${RST} Unknown command: ${BRIGHT_WHITE}${words[0]}${RST}`)
|
|
220
|
+
console.log(` Run ${BRIGHT_WHITE}${BOLD}noguard --help${RST} for usage, or quote a task: ${BRIGHT_WHITE}noguard "fix the failing test"${RST}`)
|
|
221
|
+
process.exit(1)
|
|
222
|
+
}
|
|
223
|
+
const { chat } = await import('../lib/chat.mjs')
|
|
224
|
+
await chat({ ...session, prompt: words.join(' ') || undefined })
|
|
225
|
+
break
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
main().catch(err => {
|
|
231
|
+
console.error(`${HOT_PINK}✗${RST} ${err.message}`)
|
|
232
|
+
process.exit(1)
|
|
233
|
+
})
|
package/lib/agent.mjs
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { randomBytes, randomUUID } from 'node:crypto'
|
|
5
5
|
import { ApiError, streamMessages } from './api.mjs'
|
|
6
6
|
import { isInsideReal, resolvePath } from './files.mjs'
|
|
7
|
-
import { clean, MarkdownStream, Spinner, toolHeader, toolResultLine, BOLD,
|
|
7
|
+
import { clean, MarkdownStream, Spinner, toolHeader, toolResultLine, BOLD, DIM, RST, UNDERLINE, NEON_CYAN, HOT_PINK, LIME, ORANGE, BRIGHT_WHITE, SOFT_GRAY } from './render.mjs'
|
|
8
8
|
import { systemPrompt } from './context.mjs'
|
|
9
9
|
import { TOOLS_BY_NAME, toolDefinitions } from './tools.mjs'
|
|
10
10
|
|
|
@@ -183,10 +183,10 @@ export class Agent {
|
|
|
183
183
|
}
|
|
184
184
|
this.messages.push({ role: 'user', content: results })
|
|
185
185
|
if (halt || this.controller.signal.aborted) {
|
|
186
|
-
if (this.controller.signal.aborted) console.log(` ${
|
|
186
|
+
if (this.controller.signal.aborted) console.log(` ${SOFT_GRAY}⎿ Interrupted. Tell NoGuard what to do instead.${RST}`)
|
|
187
187
|
break
|
|
188
188
|
}
|
|
189
|
-
if (step === MAX_STEPS - 1) console.log(`${
|
|
189
|
+
if (step === MAX_STEPS - 1) console.log(`${ORANGE}⚠${RST} Stopped after ${MAX_STEPS} steps. Send a message to continue.`)
|
|
190
190
|
}
|
|
191
191
|
} finally {
|
|
192
192
|
this.spinner.stop()
|
|
@@ -270,7 +270,7 @@ export class Agent {
|
|
|
270
270
|
await new Promise(r => setTimeout(r, 2000))
|
|
271
271
|
continue
|
|
272
272
|
}
|
|
273
|
-
console.log(`${
|
|
273
|
+
console.log(`${HOT_PINK}✗${RST} Connection error: ${err.message}`)
|
|
274
274
|
return { blocks: [], spent: 0, balance: null, stop: true, failed: true }
|
|
275
275
|
}
|
|
276
276
|
}
|
|
@@ -282,10 +282,10 @@ export class Agent {
|
|
|
282
282
|
}
|
|
283
283
|
|
|
284
284
|
#explain(err) {
|
|
285
|
-
if (err.status === 401 || err.code === 'invalid_token') console.log(`${
|
|
286
|
-
else if (err.code === 'out_of_credits' || err.status === 402) console.log(`${
|
|
287
|
-
else if (err.code === 'model_unavailable') console.log(`${
|
|
288
|
-
else console.log(`${
|
|
285
|
+
if (err.status === 401 || err.code === 'invalid_token') console.log(`${HOT_PINK}✗${RST} Session expired. Run ${BOLD}noguard login${RST} again.`)
|
|
286
|
+
else if (err.code === 'out_of_credits' || err.status === 402) console.log(`${ORANGE}⚠${RST} ${err.message}\n Top up at ${NEON_CYAN}${UNDERLINE}https://noguard.ai/credits${RST}`)
|
|
287
|
+
else if (err.code === 'model_unavailable') console.log(`${ORANGE}⚠${RST} ${err.message} Run /models to pick another.`)
|
|
288
|
+
else console.log(`${HOT_PINK}✗${RST} ${err.message}`)
|
|
289
289
|
return err.message
|
|
290
290
|
}
|
|
291
291
|
|
|
@@ -367,7 +367,7 @@ export class Agent {
|
|
|
367
367
|
finished.push(call)
|
|
368
368
|
}
|
|
369
369
|
if (streamError) {
|
|
370
|
-
console.log(`${
|
|
370
|
+
console.log(`${HOT_PINK}✗${RST} ${streamError}`)
|
|
371
371
|
return { blocks: finished.filter(b => b.type === 'text'), spent, balance, stop: true, failed: true }
|
|
372
372
|
}
|
|
373
373
|
if (stopReason === 'max_tokens' && !finished.some(b => b.type === 'tool_use')) {
|
|
@@ -382,19 +382,19 @@ export class Agent {
|
|
|
382
382
|
const fail = (message, extra = {}) => ({ result: { type: 'tool_result', tool_use_id: call.id, content: message, is_error: true }, ...extra })
|
|
383
383
|
if (!tool) {
|
|
384
384
|
console.log(toolHeader(call.name))
|
|
385
|
-
console.log(toolResultLine(`Unknown tool`,
|
|
385
|
+
console.log(toolResultLine(`Unknown tool`, HOT_PINK))
|
|
386
386
|
return fail(`There is no tool named ${call.name}.`)
|
|
387
387
|
}
|
|
388
388
|
let label = ''
|
|
389
389
|
try { label = tool.label(call.input, this.ctx) } catch { /* bad input shows no label */ }
|
|
390
390
|
console.log(toolHeader(tool.name, label))
|
|
391
391
|
if (call.parseError) {
|
|
392
|
-
console.log(toolResultLine('Invalid arguments',
|
|
392
|
+
console.log(toolResultLine('Invalid arguments', HOT_PINK))
|
|
393
393
|
return fail(`The tool arguments were not valid JSON (${call.parseError}). The reply may have been cut off; try again with smaller input.`)
|
|
394
394
|
}
|
|
395
395
|
const missing = (tool.input_schema.required ?? []).filter(key => call.input[key] === undefined)
|
|
396
396
|
if (missing.length) {
|
|
397
|
-
console.log(toolResultLine(`Missing ${missing.join(', ')}`,
|
|
397
|
+
console.log(toolResultLine(`Missing ${missing.join(', ')}`, HOT_PINK))
|
|
398
398
|
return fail(`Missing required argument${missing.length > 1 ? 's' : ''}: ${missing.join(', ')}.`)
|
|
399
399
|
}
|
|
400
400
|
const reason = this.permissions.check(tool, call.input, this.cwd)
|
|
@@ -405,16 +405,16 @@ export class Agent {
|
|
|
405
405
|
if (tool.kind === 'exec') {
|
|
406
406
|
// The header may be shortened: show exactly what will run before asking.
|
|
407
407
|
const command = clean(String(call.input.command ?? ''))
|
|
408
|
-
if (command !== label) console.log(command.split('\n').map(line => ` ${
|
|
408
|
+
if (command !== label) console.log(command.split('\n').map(line => ` ${NEON_CYAN}${line}${RST}`).join('\n'))
|
|
409
409
|
if (call.input.description) console.log(` ${DIM}${clean(String(call.input.description))}${RST}`)
|
|
410
410
|
}
|
|
411
411
|
const always = this.permissions.alwaysLabel(tool, call.input)
|
|
412
|
-
const answer = await this.ui.ask(` ${
|
|
412
|
+
const answer = await this.ui.ask(` ${ORANGE}?${RST} Allow NoGuard to ${reason}? ${LIME}y${RST}es${always ? ` · ${NEON_CYAN}a${RST}lways (${always})` : ''} · ${HOT_PINK}n${RST}o, or type what to do instead ${NEON_CYAN}›${RST} `)
|
|
413
413
|
if (answer === null) {
|
|
414
414
|
const why = this.ui.interactive
|
|
415
415
|
? 'Not run: the user interrupted.'
|
|
416
416
|
: `Not run: this needs approval, and nobody can approve it in print mode. Rerun with --accept-edits or --yolo to allow it.`
|
|
417
|
-
console.log(toolResultLine(this.ui.interactive ? 'Interrupted' : 'Needs approval (print mode)',
|
|
417
|
+
console.log(toolResultLine(this.ui.interactive ? 'Interrupted' : 'Needs approval (print mode)', ORANGE))
|
|
418
418
|
return fail(why, { halt: true })
|
|
419
419
|
}
|
|
420
420
|
const reply = answer.trim()
|
|
@@ -423,7 +423,7 @@ export class Agent {
|
|
|
423
423
|
if (always) this.permissions.alwaysAllow(tool, call.input)
|
|
424
424
|
} else if (!(word === '' || word === 'y' || word === 'yes')) {
|
|
425
425
|
const feedback = ['n', 'no'].includes(word) ? '' : reply
|
|
426
|
-
console.log(toolResultLine('Denied',
|
|
426
|
+
console.log(toolResultLine('Denied', ORANGE))
|
|
427
427
|
if (feedback) {
|
|
428
428
|
return fail('The user denied this action.', { feedback: `The user denied that and said: ${feedback}` })
|
|
429
429
|
}
|
|
@@ -439,7 +439,7 @@ export class Agent {
|
|
|
439
439
|
}
|
|
440
440
|
this.spinner.stop()
|
|
441
441
|
if (outcome.error) {
|
|
442
|
-
console.log(toolResultLine(clean(outcome.error),
|
|
442
|
+
console.log(toolResultLine(clean(outcome.error), HOT_PINK))
|
|
443
443
|
return fail(outcome.error)
|
|
444
444
|
}
|
|
445
445
|
if (outcome.display) console.log(toolResultLine(outcome.display))
|