noguard 1.0.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 CHANGED
@@ -1,46 +1,120 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const VERSION = '1.0.0'
4
- const HELP = `
5
- \x1b[1mNoGuard AI CLI v${VERSION}\x1b[0m
6
- The AI that doesn't say no — from your terminal.
7
-
8
- \x1b[1mUsage:\x1b[0m
9
- noguard Start chatting (same as noguard chat)
10
- noguard chat [--model X] Start an interactive chat session
11
- noguard login Sign in with your NoGuard account
12
- noguard logout Sign out and revoke the token
13
- noguard me Show your account and credits
14
- noguard models List available models with tiers and pricing
15
- noguard usage [--days N] Show credit usage history
16
- noguard config Show config file location
17
- noguard endpoint [URL] Show or set the API endpoint
18
-
19
- \x1b[1mOptions:\x1b[0m
20
- --help, -h Show this help
21
- --version, -v Show version
22
- --model, -m Choose a model (alias or name, e.g. noguard-ultra)
23
-
24
- \x1b[1mIn-chat commands:\x1b[0m
25
- /models List models and switch
26
- /model <name> Switch to a model by alias or name
27
- /libraries Show and toggle research libraries
28
- /clear Start a new conversation
29
- /credits Show remaining credits
30
- /help Show all commands
31
- /exit Leave the chat
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.
32
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
+ }
33
89
 
34
90
  async function main() {
35
91
  const args = process.argv.slice(2)
36
- const command = args[0]?.startsWith('-') ? null : args[0]
92
+ const { flags, values, positional } = parseArgs(args)
93
+ const command = COMMANDS.has(positional[0]) ? positional[0] : positional.length ? 'prompt' : undefined
37
94
 
38
- if (args.includes('--help') || args.includes('-h')) {
39
- console.log(HELP)
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}`)
40
101
  return
41
102
  }
42
- if (args.includes('--version') || args.includes('-v')) {
43
- console.log(VERSION)
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 })
44
118
  return
45
119
  }
46
120
 
@@ -58,20 +132,22 @@ async function main() {
58
132
  case 'me': {
59
133
  const { getToken } = await import('../lib/config.mjs')
60
134
  const { get } = await import('../lib/api.mjs')
61
- if (!getToken()) { console.log('\x1b[31m✗\x1b[0m Not signed in. Run \x1b[1mnoguard login\x1b[0m first.'); return }
135
+ if (!getToken()) { console.log(`${HOT_PINK}✗${RST} Not signed in. Run ${BOLD}noguard login${RST} first.`); return }
62
136
  try {
63
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'))
64
141
  console.log()
65
- console.log(` \x1b[1mAccount\x1b[0m`)
66
- console.log(` Email: ${me.email}`)
67
- console.log(` Tier: ${me.tier}`)
68
- console.log(` Verified: ${me.verified ? '\x1b[32myes\x1b[0m' : '\x1b[31mno\x1b[0m'}`)
69
- console.log(` Credits: \x1b[33m${me.credits}\x1b[0m (${me.available} available)`)
70
- console.log(` Token: ${me.token.name} (${me.token.uid})`)
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}`)
71
147
  console.log()
72
148
  } catch (err) {
73
- if (err.status === 401) console.log('\x1b[31m✗\x1b[0m Session expired. Run \x1b[1mnoguard login\x1b[0m again.')
74
- else console.error(`\x1b[31m✗\x1b[0m ${err.message}`)
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}`)
75
151
  }
76
152
  break
77
153
  }
@@ -82,31 +158,31 @@ async function main() {
82
158
  const res = await get('/api/v1/models')
83
159
  printModels(res.data)
84
160
  } catch (err) {
85
- console.error(`\x1b[31m✗\x1b[0m ${err.message}`)
161
+ console.error(`${HOT_PINK}✗${RST} ${err.message}`)
86
162
  }
87
163
  break
88
164
  }
89
165
  case 'usage': {
90
166
  const { getToken } = await import('../lib/config.mjs')
91
167
  const { get } = await import('../lib/api.mjs')
92
- if (!getToken()) { console.log('\x1b[31m✗\x1b[0m Not signed in. Run \x1b[1mnoguard login\x1b[0m first.'); return }
93
- const daysIdx = args.indexOf('--days')
94
- const days = daysIdx !== -1 ? parseInt(args[daysIdx + 1], 10) || 30 : 30
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
95
170
  try {
96
171
  const res = await get(`/api/v1/usage?days=${days}`)
97
172
  console.log()
98
- console.log(` \x1b[1mUsage (last ${res.days_covered} days)\x1b[0m`)
173
+ console.log(sectionHeader(`Usage (last ${res.days_covered} days)`))
174
+ console.log()
99
175
  if (res.by_day?.length) {
100
176
  for (const day of res.by_day) {
101
- console.log(` ${day.date} \x1b[33m${day.credits_spent}\x1b[0m credits ${day.requests} requests`)
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}`)
102
178
  }
103
179
  } else {
104
- console.log(' \x1b[2mNo usage yet.\x1b[0m')
180
+ console.log(` ${SOFT_GRAY}No usage yet.${RST}`)
105
181
  }
106
182
  console.log()
107
183
  } catch (err) {
108
- if (err.status === 401) console.log('\x1b[31m✗\x1b[0m Session expired. Run \x1b[1mnoguard login\x1b[0m again.')
109
- else console.error(`\x1b[31m✗\x1b[0m ${err.message}`)
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}`)
110
186
  }
111
187
  break
112
188
  }
@@ -114,41 +190,44 @@ async function main() {
114
190
  const { configPath, load } = await import('../lib/config.mjs')
115
191
  const cfg = load()
116
192
  console.log()
117
- console.log(` \x1b[1mConfig\x1b[0m`)
118
- console.log(` File: ${configPath()}`)
119
- console.log(` Endpoint: ${cfg.endpoint ?? 'https://noguard.ai'}`)
120
- console.log(` Signed: ${cfg.token ? '\x1b[32myes\x1b[0m' : '\x1b[31mno\x1b[0m'}`)
121
- if (cfg.account) console.log(` Account: ${cfg.account.email}`)
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}`)
122
199
  console.log()
123
200
  break
124
201
  }
125
202
  case 'endpoint': {
126
- const sub = args[1]
127
- if (sub && !sub.startsWith('-')) {
203
+ const sub = positional[1]
204
+ if (sub) {
128
205
  const { setEndpoint } = await import('../lib/config.mjs')
129
206
  setEndpoint(sub)
130
- console.log(`\x1b[32m✓\x1b[0m Endpoint set to \x1b[1m${sub}\x1b[0m`)
207
+ console.log(`${LIME}✓${RST} Endpoint set to ${BRIGHT_WHITE}${BOLD}${sub}${RST}`)
131
208
  } else {
132
209
  const { getEndpoint } = await import('../lib/config.mjs')
133
210
  console.log(getEndpoint())
134
211
  }
135
212
  break
136
213
  }
214
+ case 'prompt':
137
215
  case 'chat':
138
216
  case undefined: {
139
- const modelIdx = args.indexOf('--model') !== -1 ? args.indexOf('--model') : args.indexOf('-m')
140
- const model = modelIdx !== -1 ? args[modelIdx + 1] : 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
+ }
141
223
  const { chat } = await import('../lib/chat.mjs')
142
- await chat({ model })
224
+ await chat({ ...session, prompt: words.join(' ') || undefined })
143
225
  break
144
226
  }
145
- default:
146
- console.log(`\x1b[31m✗\x1b[0m Unknown command: ${command}`)
147
- console.log(' Run \x1b[1mnoguard --help\x1b[0m for usage.')
148
227
  }
149
228
  }
150
229
 
151
230
  main().catch(err => {
152
- console.error(`\x1b[31m✗\x1b[0m ${err.message}`)
231
+ console.error(`${HOT_PINK}✗${RST} ${err.message}`)
153
232
  process.exit(1)
154
233
  })