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/bin/noguard.mjs +264 -245
- package/lib/agent.mjs +102 -51
- package/lib/api.mjs +81 -76
- package/lib/auth.mjs +77 -77
- package/lib/chat.mjs +514 -515
- package/lib/config.mjs +57 -57
- package/lib/context.mjs +115 -115
- package/lib/files.mjs +168 -168
- package/lib/persona-eval.mjs +305 -305
- package/lib/render.mjs +400 -398
- package/lib/shell.mjs +84 -84
- package/package.json +23 -23
package/bin/noguard.mjs
CHANGED
|
@@ -1,245 +1,264 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
Run ${BRIGHT_WHITE}${BOLD}noguard${RST} inside a project folder. NoGuard can read, search and edit its files
|
|
18
|
-
and run commands there, asking you before it changes anything.
|
|
19
|
-
|
|
20
|
-
${GOLD}${BOLD}Usage:${RST}
|
|
21
|
-
${BRIGHT_WHITE}noguard${RST} ${SOFT_GRAY}Start a session in the current folder${RST}
|
|
22
|
-
${BRIGHT_WHITE}noguard${RST} ${SKY}"task"${RST} ${SOFT_GRAY}Start a session with a first message${RST}
|
|
23
|
-
${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}
|
|
24
|
-
${BRIGHT_WHITE}noguard login${RST} ${SOFT_GRAY}Sign in with your NoGuard account${RST}
|
|
25
|
-
${BRIGHT_WHITE}noguard logout${RST} ${SOFT_GRAY}Sign out and revoke the token${RST}
|
|
26
|
-
${BRIGHT_WHITE}noguard me${RST} ${SOFT_GRAY}Show your account and credits${RST}
|
|
27
|
-
${BRIGHT_WHITE}noguard models${RST} ${SOFT_GRAY}List available models with tiers and pricing${RST}
|
|
28
|
-
${BRIGHT_WHITE}noguard usage${RST} ${NEON_CYAN}[--days N]${RST} ${SOFT_GRAY}Show credit usage history${RST}
|
|
29
|
-
${BRIGHT_WHITE}noguard config${RST} ${SOFT_GRAY}Show config file location${RST}
|
|
30
|
-
${BRIGHT_WHITE}noguard endpoint${RST} ${SKY}[URL]${RST} ${SOFT_GRAY}Show or set the API endpoint${RST}
|
|
31
|
-
${BRIGHT_WHITE}noguard eval-personas${RST} ${SOFT_GRAY}Run standardized persona evaluations (--help for options)${RST}
|
|
32
|
-
|
|
33
|
-
${GOLD}${BOLD}Options:${RST}
|
|
34
|
-
${NEON_CYAN}--model, -m${RST} ${SKY}<name>${RST} ${SOFT_GRAY}Choose a model (alias or name, e.g. noguard-ultra)${RST}
|
|
35
|
-
${NEON_CYAN}--print, -p${RST} ${SOFT_GRAY}Print mode: run one task and exit${RST}
|
|
36
|
-
${NEON_CYAN}--
|
|
37
|
-
${NEON_CYAN}--
|
|
38
|
-
${NEON_CYAN}--
|
|
39
|
-
${NEON_CYAN}--
|
|
40
|
-
${NEON_CYAN}--
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
${BRIGHT_WHITE}/
|
|
45
|
-
${BRIGHT_WHITE}/
|
|
46
|
-
${BRIGHT_WHITE}/
|
|
47
|
-
${BRIGHT_WHITE}/
|
|
48
|
-
${BRIGHT_WHITE}/
|
|
49
|
-
${BRIGHT_WHITE}/
|
|
50
|
-
${BRIGHT_WHITE}/
|
|
51
|
-
${BRIGHT_WHITE}/
|
|
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
|
-
const
|
|
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
|
-
|
|
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
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { readFileSync } from 'node:fs'
|
|
4
|
+
import { permissionMode } from '../lib/agent.mjs'
|
|
5
|
+
import {
|
|
6
|
+
BOLD, RST, UNDERLINE,
|
|
7
|
+
NEON_CYAN, HOT_PINK, LIME, ORANGE, GOLD, SKY, BRIGHT_WHITE, SOFT_GRAY, DARK_GRAY,
|
|
8
|
+
AMBER, MINT, ROSE, FG_STRONG, MUTED, FAINT,
|
|
9
|
+
gradient, NOGUARD_GRADIENT, sectionHeader, tierPill, creditMeter, sparkline,
|
|
10
|
+
} from '../lib/render.mjs'
|
|
11
|
+
|
|
12
|
+
const { version: VERSION } = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'))
|
|
13
|
+
|
|
14
|
+
function helpText() {
|
|
15
|
+
return `
|
|
16
|
+
${gradient('NoGuard AI CLI', NOGUARD_GRADIENT)} ${SOFT_GRAY}v${VERSION}${RST}
|
|
17
|
+
Run ${BRIGHT_WHITE}${BOLD}noguard${RST} inside a project folder. NoGuard can read, search and edit its files
|
|
18
|
+
and run commands there, asking you before it changes anything.
|
|
19
|
+
|
|
20
|
+
${GOLD}${BOLD}Usage:${RST}
|
|
21
|
+
${BRIGHT_WHITE}noguard${RST} ${SOFT_GRAY}Start a session in the current folder${RST}
|
|
22
|
+
${BRIGHT_WHITE}noguard${RST} ${SKY}"task"${RST} ${SOFT_GRAY}Start a session with a first message${RST}
|
|
23
|
+
${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}
|
|
24
|
+
${BRIGHT_WHITE}noguard login${RST} ${SOFT_GRAY}Sign in with your NoGuard account${RST}
|
|
25
|
+
${BRIGHT_WHITE}noguard logout${RST} ${SOFT_GRAY}Sign out and revoke the token${RST}
|
|
26
|
+
${BRIGHT_WHITE}noguard me${RST} ${SOFT_GRAY}Show your account and credits${RST}
|
|
27
|
+
${BRIGHT_WHITE}noguard models${RST} ${SOFT_GRAY}List available models with tiers and pricing${RST}
|
|
28
|
+
${BRIGHT_WHITE}noguard usage${RST} ${NEON_CYAN}[--days N]${RST} ${SOFT_GRAY}Show credit usage history${RST}
|
|
29
|
+
${BRIGHT_WHITE}noguard config${RST} ${SOFT_GRAY}Show config file location${RST}
|
|
30
|
+
${BRIGHT_WHITE}noguard endpoint${RST} ${SKY}[URL]${RST} ${SOFT_GRAY}Show or set the API endpoint${RST}
|
|
31
|
+
${BRIGHT_WHITE}noguard eval-personas${RST} ${SOFT_GRAY}Run standardized persona evaluations (--help for options)${RST}
|
|
32
|
+
|
|
33
|
+
${GOLD}${BOLD}Options:${RST}
|
|
34
|
+
${NEON_CYAN}--model, -m${RST} ${SKY}<name>${RST} ${SOFT_GRAY}Choose a model (alias or name, e.g. noguard-ultra)${RST}
|
|
35
|
+
${NEON_CYAN}--print, -p${RST} ${SOFT_GRAY}Print mode: run one task and exit${RST}
|
|
36
|
+
${NEON_CYAN}--permission-mode${RST} ${SKY}<mode>${RST} ${SOFT_GRAY}Choose ask, accept-edits or plan${RST}
|
|
37
|
+
${NEON_CYAN}--accept-edits${RST} ${SOFT_GRAY}Let NoGuard edit files without asking (still asks before commands)${RST}
|
|
38
|
+
${NEON_CYAN}--yolo${RST} ${SOFT_GRAY}Let NoGuard edit files and run commands without asking${RST}
|
|
39
|
+
${NEON_CYAN}--no-tools${RST} ${SOFT_GRAY}Chat only: NoGuard can't see or change files${RST}
|
|
40
|
+
${NEON_CYAN}--help, -h${RST} ${SOFT_GRAY}Show this help${RST}
|
|
41
|
+
${NEON_CYAN}--version, -v${RST} ${SOFT_GRAY}Show version${RST}
|
|
42
|
+
|
|
43
|
+
${GOLD}${BOLD}In-session commands:${RST}
|
|
44
|
+
${BRIGHT_WHITE}/models, /model <name>${RST} ${SOFT_GRAY}List models, switch model${RST}
|
|
45
|
+
${BRIGHT_WHITE}/permissions${RST} ${SKY}[mode]${RST} ${SOFT_GRAY}Show or change what needs your approval${RST}
|
|
46
|
+
${BRIGHT_WHITE}/plan${RST} ${SKY}[task]${RST} ${SOFT_GRAY}Inspect project files and plan changes${RST}
|
|
47
|
+
${BRIGHT_WHITE}/status${RST} ${SOFT_GRAY}Show session info, credits, model, and stats${RST}
|
|
48
|
+
${BRIGHT_WHITE}/init${RST} ${SOFT_GRAY}Write a NOGUARD.md describing this project${RST}
|
|
49
|
+
${BRIGHT_WHITE}/compact${RST} ${SOFT_GRAY}Free context by dropping old tool output${RST}
|
|
50
|
+
${BRIGHT_WHITE}/libraries, /library <id>${RST} ${SOFT_GRAY}Research libraries${RST}
|
|
51
|
+
${BRIGHT_WHITE}/clear${RST} ${SOFT_GRAY}Start a new conversation${RST}
|
|
52
|
+
${BRIGHT_WHITE}/credits${RST} ${SOFT_GRAY}Show remaining credits${RST}
|
|
53
|
+
${BRIGHT_WHITE}/help, /exit${RST}
|
|
54
|
+
|
|
55
|
+
${GOLD}${BOLD}Project instructions:${RST}
|
|
56
|
+
NoGuard reads ${SKY}NOGUARD.md${RST} (and ${SKY}CLAUDE.md${RST} or ${SKY}AGENTS.md${RST}) from the project folder and
|
|
57
|
+
its parents, and ${SKY}~/.noguard/NOGUARD.md${RST}, at the start of each session.
|
|
58
|
+
`
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const COMMANDS = new Set(['login', 'logout', 'me', 'models', 'usage', 'config', 'endpoint', 'chat'])
|
|
62
|
+
const VALUE_FLAGS = new Set(['--model', '-m', '--days', '--permission-mode'])
|
|
63
|
+
const BOOLEAN_FLAGS = new Set(['--print', '-p', '--accept-edits', '--yolo', '--dangerously-skip-permissions', '--no-tools', '--help', '-h', '--version', '-v'])
|
|
64
|
+
|
|
65
|
+
function parseArgs(argv) {
|
|
66
|
+
const flags = new Set()
|
|
67
|
+
const values = {}
|
|
68
|
+
const positional = []
|
|
69
|
+
for (let i = 0; i < argv.length; i++) {
|
|
70
|
+
const arg = argv[i]
|
|
71
|
+
if (arg === '--') {
|
|
72
|
+
positional.push(...argv.slice(i + 1))
|
|
73
|
+
break
|
|
74
|
+
}
|
|
75
|
+
if (VALUE_FLAGS.has(arg)) {
|
|
76
|
+
const value = argv[i + 1]
|
|
77
|
+
if (!value || value.startsWith('-')) throw new Error(`Missing value for ${arg}.`)
|
|
78
|
+
values[arg] = value
|
|
79
|
+
i++
|
|
80
|
+
} else if (BOOLEAN_FLAGS.has(arg)) {
|
|
81
|
+
flags.add(arg)
|
|
82
|
+
} else if (arg.startsWith('-') && arg.length > 1) {
|
|
83
|
+
throw new Error(`Unknown option ${arg}. Run noguard --help.`)
|
|
84
|
+
} else {
|
|
85
|
+
positional.push(arg)
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return { flags, values, positional }
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Piped input. With a typed task too, an open stdin that sends nothing (scripts, CI) is not waited on. */
|
|
92
|
+
function readStdin(optional) {
|
|
93
|
+
if (process.stdin.isTTY) return Promise.resolve('')
|
|
94
|
+
return new Promise(resolve => {
|
|
95
|
+
const chunks = []
|
|
96
|
+
const done = () => { clearTimeout(idle); process.stdin.destroy(); resolve(Buffer.concat(chunks).toString('utf8')) }
|
|
97
|
+
const idle = optional ? setTimeout(done, 500) : null
|
|
98
|
+
process.stdin.on('data', chunk => { clearTimeout(idle); chunks.push(chunk) })
|
|
99
|
+
process.stdin.on('end', done)
|
|
100
|
+
process.stdin.on('error', done)
|
|
101
|
+
})
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function fmtNumber(n) {
|
|
105
|
+
return Number(n).toLocaleString('en-US')
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async function main() {
|
|
109
|
+
const args = process.argv.slice(2)
|
|
110
|
+
if (args[0] === 'eval-personas') {
|
|
111
|
+
const { main: evaluatePersonas } = await import('../lib/persona-eval.mjs')
|
|
112
|
+
await evaluatePersonas(args.slice(1))
|
|
113
|
+
return
|
|
114
|
+
}
|
|
115
|
+
const { flags, values, positional } = parseArgs(args)
|
|
116
|
+
const command = COMMANDS.has(positional[0]) ? positional[0] : positional.length ? 'prompt' : undefined
|
|
117
|
+
|
|
118
|
+
if (flags.has('--help') || flags.has('-h')) {
|
|
119
|
+
console.log(helpText())
|
|
120
|
+
return
|
|
121
|
+
}
|
|
122
|
+
if (flags.has('--version') || flags.has('-v')) {
|
|
123
|
+
console.log(`${gradient('NoGuard', NOGUARD_GRADIENT)} ${SOFT_GRAY}v${VERSION}${RST}`)
|
|
124
|
+
return
|
|
125
|
+
}
|
|
126
|
+
const explicitMode = values['--permission-mode']
|
|
127
|
+
const mode = explicitMode ? permissionMode(explicitMode) : null
|
|
128
|
+
if (explicitMode && (!mode || mode === 'yolo')) throw new Error('Unknown permission mode. Choose ask, accept-edits or plan.')
|
|
129
|
+
const session = {
|
|
130
|
+
model: values['--model'] ?? values['-m'],
|
|
131
|
+
tools: !flags.has('--no-tools'),
|
|
132
|
+
mode: mode ?? (flags.has('--yolo') || flags.has('--dangerously-skip-permissions') ? 'yolo' : flags.has('--accept-edits') ? 'accept-edits' : 'ask'),
|
|
133
|
+
}
|
|
134
|
+
if (flags.has('-p') || flags.has('--print')) {
|
|
135
|
+
const typed = (command === 'chat' ? positional.slice(1) : positional).join(' ')
|
|
136
|
+
const piped = await readStdin(Boolean(typed))
|
|
137
|
+
const prompt = [typed, piped.trim()].filter(Boolean).join('\n\n')
|
|
138
|
+
if (!prompt) {
|
|
139
|
+
console.error(`${HOT_PINK}✗${RST} Give a task: ${BRIGHT_WHITE}noguard -p "what to do"${RST} (or pipe text in).`)
|
|
140
|
+
process.exit(1)
|
|
141
|
+
}
|
|
142
|
+
const { runOnce } = await import('../lib/chat.mjs')
|
|
143
|
+
await runOnce({ ...session, prompt })
|
|
144
|
+
return
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
switch (command) {
|
|
148
|
+
case 'login': {
|
|
149
|
+
const { login } = await import('../lib/auth.mjs')
|
|
150
|
+
await login()
|
|
151
|
+
break
|
|
152
|
+
}
|
|
153
|
+
case 'logout': {
|
|
154
|
+
const { logout } = await import('../lib/auth.mjs')
|
|
155
|
+
await logout()
|
|
156
|
+
break
|
|
157
|
+
}
|
|
158
|
+
case 'me': {
|
|
159
|
+
const { getToken } = await import('../lib/config.mjs')
|
|
160
|
+
const { get } = await import('../lib/api.mjs')
|
|
161
|
+
if (!getToken()) { console.log(`${HOT_PINK}✗${RST} Not signed in. Run ${BOLD}noguard login${RST} first.`); return }
|
|
162
|
+
try {
|
|
163
|
+
const me = await get('/api/v1/me')
|
|
164
|
+
const low = me.low_balance || me.available < 100
|
|
165
|
+
const row = (name, value) => console.log(` ${MUTED}${name.padEnd(9)}${RST} ${value}`)
|
|
166
|
+
console.log()
|
|
167
|
+
console.log(sectionHeader('Account'))
|
|
168
|
+
console.log()
|
|
169
|
+
if (me.display_name) row('Name', `${FG_STRONG}${BOLD}${me.display_name}${RST}`)
|
|
170
|
+
row('Email', `${FG_STRONG}${me.email}${RST} ${tierPill(me.tier)}`)
|
|
171
|
+
row('Verified', me.verified ? `${MINT}yes${RST}` : `${ROSE}no${RST}`)
|
|
172
|
+
row('Credits', `${low ? ROSE : AMBER}${BOLD}${fmtNumber(me.available)}${RST} ${MUTED}available${RST} ${FAINT}of ${fmtNumber(me.credits)}${RST} ${creditMeter(me.available, me.credits, { low })}`)
|
|
173
|
+
row('Token', `${SKY}${me.token.name}${RST} ${FAINT}(${me.token.uid})${RST}`)
|
|
174
|
+
console.log()
|
|
175
|
+
} catch (err) {
|
|
176
|
+
if (err.status === 401) console.log(`${HOT_PINK}✗${RST} Session expired. Run ${BOLD}noguard login${RST} again.`)
|
|
177
|
+
else console.error(`${HOT_PINK}✗${RST} ${err.message}`)
|
|
178
|
+
}
|
|
179
|
+
break
|
|
180
|
+
}
|
|
181
|
+
case 'models': {
|
|
182
|
+
const { get } = await import('../lib/api.mjs')
|
|
183
|
+
const { printModels } = await import('../lib/chat.mjs')
|
|
184
|
+
try {
|
|
185
|
+
const res = await get('/api/v1/models')
|
|
186
|
+
printModels(res.data)
|
|
187
|
+
} catch (err) {
|
|
188
|
+
console.error(`${HOT_PINK}✗${RST} ${err.message}`)
|
|
189
|
+
}
|
|
190
|
+
break
|
|
191
|
+
}
|
|
192
|
+
case 'usage': {
|
|
193
|
+
const { getToken } = await import('../lib/config.mjs')
|
|
194
|
+
const { get } = await import('../lib/api.mjs')
|
|
195
|
+
if (!getToken()) { console.log(`${HOT_PINK}✗${RST} Not signed in. Run ${BOLD}noguard login${RST} first.`); return }
|
|
196
|
+
const days = parseInt(values['--days'], 10) || 30
|
|
197
|
+
try {
|
|
198
|
+
const res = await get(`/api/v1/usage?days=${days}`)
|
|
199
|
+
console.log()
|
|
200
|
+
console.log(sectionHeader(`Usage · last ${res.days_covered} days`))
|
|
201
|
+
console.log()
|
|
202
|
+
const list = res.days ?? []
|
|
203
|
+
if (list.length) {
|
|
204
|
+
for (const day of list) {
|
|
205
|
+
console.log(` ${FG_STRONG}${day.day}${RST} ${AMBER}${BOLD}${fmtNumber(day.credits)}${RST} ${MUTED}cr${RST} ${FAINT}${day.requests} req${RST}`)
|
|
206
|
+
}
|
|
207
|
+
const total = res.total_credits ?? list.reduce((a, b) => a + b.credits, 0)
|
|
208
|
+
console.log()
|
|
209
|
+
console.log(` ${sparkline(list.map(d => d.credits))} ${FAINT}${fmtNumber(total)} credits · ${fmtNumber(res.total_requests ?? list.reduce((a, b) => a + b.requests, 0))} requests${RST}`)
|
|
210
|
+
} else {
|
|
211
|
+
console.log(` ${MUTED}No usage yet.${RST}`)
|
|
212
|
+
}
|
|
213
|
+
console.log()
|
|
214
|
+
} catch (err) {
|
|
215
|
+
if (err.status === 401) console.log(`${HOT_PINK}✗${RST} Session expired. Run ${BOLD}noguard login${RST} again.`)
|
|
216
|
+
else console.error(`${HOT_PINK}✗${RST} ${err.message}`)
|
|
217
|
+
}
|
|
218
|
+
break
|
|
219
|
+
}
|
|
220
|
+
case 'config': {
|
|
221
|
+
const { configPath, load } = await import('../lib/config.mjs')
|
|
222
|
+
const cfg = load()
|
|
223
|
+
console.log()
|
|
224
|
+
console.log(sectionHeader('Config'))
|
|
225
|
+
console.log()
|
|
226
|
+
console.log(` ${SOFT_GRAY}File:${RST} ${SKY}${configPath()}${RST}`)
|
|
227
|
+
console.log(` ${SOFT_GRAY}Endpoint:${RST} ${BRIGHT_WHITE}${cfg.endpoint ?? 'https://noguard.ai'}${RST}`)
|
|
228
|
+
console.log(` ${SOFT_GRAY}Signed:${RST} ${cfg.token ? `${LIME}yes${RST}` : `${HOT_PINK}no${RST}`}`)
|
|
229
|
+
if (cfg.account) console.log(` ${SOFT_GRAY}Account:${RST} ${BRIGHT_WHITE}${cfg.account.email}${RST}`)
|
|
230
|
+
console.log()
|
|
231
|
+
break
|
|
232
|
+
}
|
|
233
|
+
case 'endpoint': {
|
|
234
|
+
const sub = positional[1]
|
|
235
|
+
if (sub) {
|
|
236
|
+
const { setEndpoint } = await import('../lib/config.mjs')
|
|
237
|
+
setEndpoint(sub)
|
|
238
|
+
console.log(`${LIME}✓${RST} Endpoint set to ${BRIGHT_WHITE}${BOLD}${sub}${RST}`)
|
|
239
|
+
} else {
|
|
240
|
+
const { getEndpoint } = await import('../lib/config.mjs')
|
|
241
|
+
console.log(getEndpoint())
|
|
242
|
+
}
|
|
243
|
+
break
|
|
244
|
+
}
|
|
245
|
+
case 'prompt':
|
|
246
|
+
case 'chat':
|
|
247
|
+
case undefined: {
|
|
248
|
+
const words = command === 'chat' ? positional.slice(1) : positional
|
|
249
|
+
if (command === 'prompt' && words.length === 1 && !/\s/.test(words[0])) {
|
|
250
|
+
console.log(`${HOT_PINK}✗${RST} Unknown command: ${BRIGHT_WHITE}${words[0]}${RST}`)
|
|
251
|
+
console.log(` Run ${BRIGHT_WHITE}${BOLD}noguard --help${RST} for usage, or quote a task: ${BRIGHT_WHITE}noguard "fix the failing test"${RST}`)
|
|
252
|
+
process.exit(1)
|
|
253
|
+
}
|
|
254
|
+
const { chat } = await import('../lib/chat.mjs')
|
|
255
|
+
await chat({ ...session, prompt: words.join(' ') || undefined })
|
|
256
|
+
break
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
main().catch(err => {
|
|
262
|
+
console.error(`${HOT_PINK}✗${RST} ${err.message}`)
|
|
263
|
+
process.exitCode = 1
|
|
264
|
+
})
|