noguard 1.2.1 → 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/auth.mjs CHANGED
@@ -1,77 +1,77 @@
1
- import { post } from './api.mjs'
2
- import { setToken, clearToken, getToken, getEndpoint } from './config.mjs'
3
-
4
- export async function login() {
5
- const token = getToken()
6
- if (token) {
7
- console.log('\x1b[33m⚠\x1b[0m Already signed in. Run \x1b[1mnoguard logout\x1b[0m first to switch accounts.')
8
- return
9
- }
10
- console.log('\x1b[36m◆\x1b[0m Starting sign-in…\n')
11
- const flow = await post('/api/device/code', { client: 'cli' }, { token: null })
12
- const code = flow.user_code
13
- const url = flow.verification_uri_complete
14
-
15
- console.log(' Open this URL in your browser:\n')
16
- console.log(` \x1b[4m\x1b[36m${url}\x1b[0m\n`)
17
- console.log(` Or go to \x1b[1m${flow.verification_uri}\x1b[0m and enter: \x1b[1m${code}\x1b[0m\n`)
18
-
19
- try {
20
- const parsed = new URL(url)
21
- const base = new URL(getEndpoint())
22
- if ((parsed.protocol === 'https:' || parsed.protocol === 'http:') && parsed.hostname === base.hostname) {
23
- const { execFile } = await import('node:child_process')
24
- const platform = process.platform
25
- if (platform === 'win32') execFile('rundll32', ['url.dll,FileProtocolHandler', parsed.href])
26
- else if (platform === 'darwin') execFile('open', ['--', parsed.href])
27
- else execFile('xdg-open', [parsed.href])
28
- }
29
- } catch { /* browser open is best-effort */ }
30
-
31
- console.log(' Waiting for approval…')
32
- const interval = (flow.interval ?? 5) * 1000
33
- const deadline = Date.now() + (flow.expires_in ?? 600) * 1000
34
-
35
- while (Date.now() < deadline) {
36
- await sleep(interval)
37
- try {
38
- const result = await post('/api/device/token', { device_code: flow.device_code }, { token: null })
39
- if (result.access_token) {
40
- setToken(result.access_token, result.account)
41
- console.log(`\n\x1b[32m✓\x1b[0m Signed in as \x1b[1m${result.account.email}\x1b[0m`)
42
- console.log(` Credits: \x1b[33m${result.account.credits}\x1b[0m`)
43
- return
44
- }
45
- } catch (err) {
46
- if (err.code === 'authorization_pending' || err.code === 'slow_down') continue
47
- if (err.code === 'access_denied') {
48
- console.log('\n\x1b[31m✗\x1b[0m Sign-in was denied in the browser.')
49
- return
50
- }
51
- if (err.code === 'expired_token') {
52
- console.log('\n\x1b[31m✗\x1b[0m Sign-in code expired. Run \x1b[1mnoguard login\x1b[0m again.')
53
- return
54
- }
55
- throw err
56
- }
57
- }
58
- console.log('\n\x1b[31m✗\x1b[0m Sign-in timed out. Run \x1b[1mnoguard login\x1b[0m again.')
59
- }
60
-
61
- export async function logout() {
62
- const token = getToken()
63
- if (!token) {
64
- console.log('\x1b[33m⚠\x1b[0m Not signed in.')
65
- return
66
- }
67
- try {
68
- const { del } = await import('./api.mjs')
69
- await del('/api/v1/token')
70
- } catch { /* revoke is best-effort; the token is cleared locally either way */ }
71
- clearToken()
72
- console.log('\x1b[32m✓\x1b[0m Signed out.')
73
- }
74
-
75
- function sleep(ms) {
76
- return new Promise(resolve => setTimeout(resolve, ms))
77
- }
1
+ import { post } from './api.mjs'
2
+ import { setToken, clearToken, getToken, getEndpoint } from './config.mjs'
3
+
4
+ export async function login() {
5
+ const token = getToken()
6
+ if (token) {
7
+ console.log('\x1b[33m⚠\x1b[0m Already signed in. Run \x1b[1mnoguard logout\x1b[0m first to switch accounts.')
8
+ return
9
+ }
10
+ console.log('\x1b[36m◆\x1b[0m Starting sign-in…\n')
11
+ const flow = await post('/api/device/code', { client: 'cli' }, { token: null })
12
+ const code = flow.user_code
13
+ const url = flow.verification_uri_complete
14
+
15
+ console.log(' Open this URL in your browser:\n')
16
+ console.log(` \x1b[4m\x1b[36m${url}\x1b[0m\n`)
17
+ console.log(` Or go to \x1b[1m${flow.verification_uri}\x1b[0m and enter: \x1b[1m${code}\x1b[0m\n`)
18
+
19
+ try {
20
+ const parsed = new URL(url)
21
+ const base = new URL(getEndpoint())
22
+ if ((parsed.protocol === 'https:' || parsed.protocol === 'http:') && parsed.hostname === base.hostname) {
23
+ const { execFile } = await import('node:child_process')
24
+ const platform = process.platform
25
+ if (platform === 'win32') execFile('rundll32', ['url.dll,FileProtocolHandler', parsed.href])
26
+ else if (platform === 'darwin') execFile('open', ['--', parsed.href])
27
+ else execFile('xdg-open', [parsed.href])
28
+ }
29
+ } catch { /* browser open is best-effort */ }
30
+
31
+ console.log(' Waiting for approval…')
32
+ const interval = (flow.interval ?? 5) * 1000
33
+ const deadline = Date.now() + (flow.expires_in ?? 600) * 1000
34
+
35
+ while (Date.now() < deadline) {
36
+ await sleep(interval)
37
+ try {
38
+ const result = await post('/api/device/token', { device_code: flow.device_code }, { token: null })
39
+ if (result.access_token) {
40
+ setToken(result.access_token, result.account)
41
+ console.log(`\n\x1b[32m✓\x1b[0m Signed in as \x1b[1m${result.account.email}\x1b[0m`)
42
+ console.log(` Credits: \x1b[33m${result.account.credits}\x1b[0m`)
43
+ return
44
+ }
45
+ } catch (err) {
46
+ if (err.code === 'authorization_pending' || err.code === 'slow_down') continue
47
+ if (err.code === 'access_denied') {
48
+ console.log('\n\x1b[31m✗\x1b[0m Sign-in was denied in the browser.')
49
+ return
50
+ }
51
+ if (err.code === 'expired_token') {
52
+ console.log('\n\x1b[31m✗\x1b[0m Sign-in code expired. Run \x1b[1mnoguard login\x1b[0m again.')
53
+ return
54
+ }
55
+ throw err
56
+ }
57
+ }
58
+ console.log('\n\x1b[31m✗\x1b[0m Sign-in timed out. Run \x1b[1mnoguard login\x1b[0m again.')
59
+ }
60
+
61
+ export async function logout() {
62
+ const token = getToken()
63
+ if (!token) {
64
+ console.log('\x1b[33m⚠\x1b[0m Not signed in.')
65
+ return
66
+ }
67
+ try {
68
+ const { del } = await import('./api.mjs')
69
+ await del('/api/v1/token')
70
+ } catch { /* revoke is best-effort; the token is cleared locally either way */ }
71
+ clearToken()
72
+ console.log('\x1b[32m✓\x1b[0m Signed out.')
73
+ }
74
+
75
+ function sleep(ms) {
76
+ return new Promise(resolve => setTimeout(resolve, ms))
77
+ }
package/lib/chat.mjs CHANGED
@@ -3,22 +3,22 @@ import { createInterface } from 'node:readline/promises'
3
3
  import { homedir } from 'node:os'
4
4
  import { get } from './api.mjs'
5
5
  import { getToken } from './config.mjs'
6
- import { Agent, MODES, Permissions } from './agent.mjs'
7
- import { instructionFiles } from './context.mjs'
6
+ import { Agent, MODES, Permissions, permissionMode } from './agent.mjs'
8
7
  import { detectShell } from './shell.mjs'
9
8
  import { TOOLS } from './tools.mjs'
10
9
  import {
11
- BOLD, DIM, RST, UNDERLINE,
12
- IRIS, CYAN, MINT, AMBER, ROSE, SKY, MAGENTA, GOLD, LAVENDER,
13
- FG, FG_STRONG, DIMFG, MUTED, FAINT, LINE,
14
- NEON_CYAN, HOT_PINK, ELECTRIC_PURPLE, VIVID_MAGENTA, LIME, ORANGE, CORAL,
15
- BRIGHT_WHITE, SOFT_GRAY, DARK_GRAY, BG_DARK,
16
- sectionHeader, statusBar, gradient, NOGUARD_GRADIENT, stripAnsi, termWidth,
10
+ BOLD, RST, UNDERLINE,
11
+ IRIS, CYAN, MINT, AMBER, ROSE, SKY, MAGENTA, GOLD,
12
+ FG_STRONG, DIMFG, MUTED, FAINT, LINE,
13
+ NEON_CYAN, HOT_PINK, LIME, ORANGE,
14
+ BRIGHT_WHITE, SOFT_GRAY, DARK_GRAY,
15
+ sectionHeader, statusBar, clean, termWidth,
17
16
  creditMeter, tierPill, tierColor, sparkline,
18
17
  } from './render.mjs'
19
18
 
20
19
  const RESET_COMMANDS = new Set(['/clear', '/reset', '/new'])
21
20
  const EXIT_COMMANDS = new Set(['/exit', '/quit', '/bye'])
21
+ const SESSION_COMMANDS = ['/clear', '/compact', '/credits', '/exit', '/help', '/init', '/libraries', '/library', '/model', '/models', '/permissions', '/plan', '/status', '/tools']
22
22
 
23
23
  const TIER_COLORS = { raw: MAGENTA, ultra: GOLD, pro: MINT, paid: MINT, standard: CYAN, free: MUTED }
24
24
  const TIER_ICONS = { raw: '◆', ultra: '✦', pro: '▲', paid: '▲', standard: '⚡', free: '○' }
@@ -96,7 +96,8 @@ function printHelp(agentMode) {
96
96
  cmd('/models', 'List all models with tier info')
97
97
  cmd('/model <name>', 'Switch to a model (alias or display name)')
98
98
  if (agentMode) {
99
- cmd('/mode [mode]', 'Show or set permissions: ask, accept-edits, yolo')
99
+ cmd('/permissions [mode]', 'Show or set permissions')
100
+ cmd('/plan [task]', 'Inspect the workspace and plan changes')
100
101
  cmd('/init', 'Write a NOGUARD.md describing this project')
101
102
  cmd('/compact', 'Free context by dropping old tool output')
102
103
  cmd('/tools', 'List the tools NoGuard can use')
@@ -118,29 +119,31 @@ function printHelp(agentMode) {
118
119
  console.log()
119
120
  }
120
121
 
121
- /** The model a session runs on: the one asked for if it can do the job, else the right default. */
122
- export function pickModel(models, requested, agentMode) {
123
- const usable = m => agentMode ? Boolean(m.build_eligible) && m.supports_tools !== false : m.chat_eligible !== false
122
+ /** Select an eligible model without substituting a different explicit selection. */
123
+ export function pickModel(models, requested, agentMode, tier) {
124
+ const unlocked = model => !model.requires_purchase || tier !== 'free'
125
+ const capable = m => agentMode ? m.build_eligible === true && m.supports_tools === true : m.chat_eligible !== false
126
+ const usable = model => unlocked(model) && capable(model)
124
127
  if (requested) {
125
128
  const name = requested.toLowerCase()
126
129
  const match = models.find(m => m.id === requested || m.id === name || m.display_name.toLowerCase() === name)
127
130
  if (!match) return { model: null, warning: `Model "${requested}" not found. Run /models to see options.` }
128
- if (!usable(match)) return { model: null, warning: `${match.display_name} can't use tools, so it can't work on files. ${agentMode ? 'Pick a model marked "agent" in /models, or run noguard --no-tools to chat with it.' : ''}` }
131
+ if (!unlocked(match)) return { model: null, warning: `${match.display_name} requires a credit pack. Run /models to see other options.` }
132
+ if (!capable(match)) return { model: null, warning: agentMode
133
+ ? `${match.display_name} does not support Build. Choose a Build model or use --no-tools for Chat.`
134
+ : `${match.display_name} does not support Chat. Choose a Chat model or start a Build session.` }
129
135
  return { model: match }
130
136
  }
131
137
  const model = agentMode
132
138
  ? models.find(m => m.default_build && usable(m)) ?? models.find(usable)
133
139
  : models.find(m => (m.default_chat || m.default) && usable(m)) ?? models.find(usable)
134
- return { model: model ?? null }
140
+ return model ? { model } : { model: null, warning: `No ${agentMode ? 'Build' : 'Chat'} model is available to your account.` }
135
141
  }
136
142
 
137
143
  async function loadModels() {
138
- try {
139
- const res = await get('/api/v1/models')
140
- return res.data ?? []
141
- } catch {
142
- return []
143
- }
144
+ const res = await get('/api/v1/models')
145
+ if (!Array.isArray(res?.data)) throw new Error('NoGuard returned an invalid model catalog.')
146
+ return res.data
144
147
  }
145
148
 
146
149
  function shortPath(path) {
@@ -148,41 +151,17 @@ function shortPath(path) {
148
151
  return path.toLowerCase().startsWith(home.toLowerCase()) ? `~${path.slice(home.length)}` : path
149
152
  }
150
153
 
151
- function printBanner({ model, agentMode, cwd, permissions, account }) {
152
- const w = termWidth()
153
- const inner = Math.max(28, Math.min(w - 4, 68))
154
- const row = (name, value) => console.log(` ${MUTED}${name.padEnd(9)}${RST} ${value}`)
155
-
156
- console.log()
157
- console.log(` ${gradient('◆ N O G U A R D', NOGUARD_GRADIENT)} ${FAINT}the AI that doesn't say no${RST}`)
158
- const third = Math.max(4, Math.floor(inner / 3))
159
- console.log(` ${CYAN}${'─'.repeat(third)}${IRIS}${'─'.repeat(third)}${MAGENTA}${'─'.repeat(inner - third * 2)}${RST}`)
160
- console.log()
161
-
162
- if (account) {
163
- const name = account.display_name || (account.email ? account.email.split('@')[0] : 'you')
164
- row('Signed in', `${FG_STRONG}${BOLD}${name}${RST} ${MUTED}${account.email ?? ''}${RST} ${tierPill(account.tier)}`)
165
- const bal = account.credits ?? 0
166
- const avail = account.available ?? bal
167
- const low = account.low_balance || avail < 100
168
- row('Credits', `${low ? ROSE : AMBER}${BOLD}${fmtNumber(avail)}${RST} ${MUTED}available${RST} ${FAINT}of ${fmtNumber(bal)}${RST} ${creditMeter(avail, bal, { low })}`)
154
+ function printBanner({ model, agentMode, cwd }) {
155
+ const width = Math.max(16, Math.min(termWidth() - 4, 68))
156
+ const fit = value => {
157
+ const text = clean(value).replace(/\s+/g, ' ')
158
+ return text.length <= width ? text : `…${text.slice(1 - width)}`
169
159
  }
170
-
171
- const modelName = model?.display_name ?? 'default'
172
- row('Model', `${tierColor(model?.tier)}${BOLD}${modelName}${RST} ${FAINT}(${model?.id ?? 'auto'})${RST}`)
173
-
174
- if (agentMode) {
175
- const modeColor = permissions.mode === 'yolo' ? ROSE : permissions.mode === 'accept-edits' ? AMBER : CYAN
176
- row('Mode', `${modeColor}${BOLD}${permissions.mode}${RST} ${FAINT}${MODES[permissions.mode]} · /mode to change${RST}`)
177
- row('Folder', `${SKY}${shortPath(cwd)}${RST}`)
178
- const files = instructionFiles(cwd)
179
- if (files.length) row('Project', `${LAVENDER}${files.map(shortPath).join(', ')}${RST}`)
180
- if (cwd === homedir()) console.log(` ${ROSE}▲${RST} ${MUTED}You're in your home folder. Start noguard inside a project folder to work on it.${RST}`)
181
- } else {
182
- row('Chat', `${MUTED}chat only — NoGuard can't see or change files in this session${RST}`)
183
- }
184
- console.log()
185
- console.log(` ${FAINT}/help for commands · Esc to interrupt · Ctrl+C twice to exit${RST}`)
160
+ console.log(`\n ${CYAN}${BOLD}NoGuard${RST} ${SOFT_GRAY}${agentMode ? 'Build' : 'Chat'}${RST}`)
161
+ console.log(` ${LINE}${'─'.repeat(width)}${RST}`)
162
+ console.log(` ${fit(model.display_name)}`)
163
+ if (agentMode) console.log(` ${SKY}${fit(shortPath(cwd))}${RST}`)
164
+ console.log(`\n ${MUTED}/help for commands · Esc to interrupt${RST}`)
186
165
  console.log()
187
166
  }
188
167
 
@@ -197,11 +176,10 @@ function buildAllowed(account, wanted, log = console.log) {
197
176
 
198
177
  export async function runOnce(opts) {
199
178
  requireAuth()
200
- const account = opts.tools !== false ? await get('/api/v1/me').catch(() => null) : null
179
+ const [models, account] = await Promise.all([loadModels(), get('/api/v1/me')])
201
180
  const agentMode = buildAllowed(account, opts.tools !== false, line => console.error(line))
202
- const models = await loadModels()
203
- const { model, warning } = pickModel(models, opts.model, agentMode)
204
- if (warning) { console.error(`${ORANGE}⚠${RST} ${warning}`); process.exit(1) }
181
+ const { model, warning } = pickModel(models, opts.model, agentMode, account.tier)
182
+ if (warning) throw new Error(warning)
205
183
  const agent = new Agent({
206
184
  cwd: process.cwd(),
207
185
  ui: { interactive: false, ask: async () => null },
@@ -211,34 +189,27 @@ export async function runOnce(opts) {
211
189
  })
212
190
  const onInt = () => agent.busy ? agent.abort() : process.exit(130)
213
191
  process.on('SIGINT', onInt)
214
- const { ok, spent, balance } = await agent.send(opts.prompt)
215
- if (process.stderr.isTTY && spent) process.stderr.write(`${SOFT_GRAY} ${spent} credits · ${balance ?? '?'} remaining${RST}\n`)
216
- process.off('SIGINT', onInt)
217
- process.exitCode = ok ? 0 : 1
192
+ try {
193
+ const { ok, spent, balance, interrupted } = await agent.send(opts.prompt)
194
+ if (process.stderr.isTTY && spent) process.stderr.write(`${SOFT_GRAY} ${spent} credits · ${balance ?? '?'} remaining${RST}\n`)
195
+ process.exitCode = interrupted ? 130 : ok ? 0 : 1
196
+ } finally {
197
+ process.off('SIGINT', onInt)
198
+ }
218
199
  }
219
200
 
220
201
  export async function chat(opts = {}) {
221
202
  requireAuth()
222
203
  const cwd = process.cwd()
223
- let agentMode = opts.tools !== false
224
-
225
- const [availableModelsRaw, accountInfo] = await Promise.all([
204
+ const [initialModels, accountInfo] = await Promise.all([
226
205
  loadModels(),
227
- get('/api/v1/me').catch(() => null),
206
+ get('/api/v1/me'),
228
207
  ])
229
- let availableModels = availableModelsRaw
230
- agentMode = buildAllowed(accountInfo, agentMode)
231
-
232
- let { model: currentModel, warning } = pickModel(availableModels, opts.model, agentMode)
233
- if (warning) {
234
- console.log(`${ORANGE}⚠${RST} ${warning}`)
235
- currentModel = pickModel(availableModels, null, agentMode).model
236
- }
237
- if (agentMode && availableModels.length && !currentModel) {
238
- console.log(`${ORANGE}⚠${RST} No model that can work on files is available to you, so this is a chat-only session.`)
239
- agentMode = false
240
- currentModel = pickModel(availableModels, null, false).model
241
- }
208
+ let availableModels = initialModels
209
+ const agentMode = buildAllowed(accountInfo, opts.tools !== false)
210
+ const { model, warning } = pickModel(availableModels, opts.model, agentMode, accountInfo.tier)
211
+ if (warning) throw new Error(warning)
212
+ let currentModel = model
242
213
 
243
214
  const permissions = new Permissions(opts.mode ?? 'ask')
244
215
  const activeLibraries = new Set()
@@ -250,7 +221,15 @@ export async function chat(opts = {}) {
250
221
  let sessionCredits = 0
251
222
 
252
223
  const interactive = process.stdin.isTTY !== false
253
- const rl = createInterface({ input: process.stdin, output: process.stdout, terminal: interactive, historySize: 500 })
224
+ const completer = line => {
225
+ const choices = line.startsWith('/model ')
226
+ ? availableModels.map(model => `/model ${model.id}`)
227
+ : line.startsWith('/permissions ')
228
+ ? Object.keys(MODES).map(mode => `/permissions ${mode}`)
229
+ : SESSION_COMMANDS
230
+ return [choices.filter(choice => choice.startsWith(line)), line]
231
+ }
232
+ const rl = createInterface({ input: process.stdin, output: process.stdout, terminal: interactive, historySize: 500, completer })
254
233
  const pasted = []
255
234
  rl.on('line', line => pasted.push(line))
256
235
  let asking = null
@@ -296,7 +275,7 @@ export async function chat(opts = {}) {
296
275
  })
297
276
  }
298
277
 
299
- printBanner({ model: currentModel, agentMode, cwd, permissions, account: accountInfo })
278
+ printBanner({ model: currentModel, agentMode, cwd })
300
279
 
301
280
  function buildPrompt() {
302
281
  const modelName = currentModel?.display_name ?? 'default'
@@ -307,7 +286,7 @@ export async function chat(opts = {}) {
307
286
  const sep = ` ${FAINT}│${RST} `
308
287
  const segs = [
309
288
  `${mColor}${BOLD}${modelName}${RST}${currentModel?.tier ? ` ${FAINT}${currentModel.tier}${RST}` : ''}`,
310
- `${modeColor}${permissions.mode}${RST}`,
289
+ agentMode ? `${modeColor}${permissions.mode}${RST}` : 'Chat',
311
290
  `${low ? ROSE : AMBER}${BOLD}${credStr}${RST} ${FAINT}cr${RST}`,
312
291
  ]
313
292
  const libs = [...activeLibraries]
@@ -447,14 +426,17 @@ export async function chat(opts = {}) {
447
426
  continue
448
427
  }
449
428
  if (lower === '/models') {
450
- if (!availableModels.length) availableModels = await loadModels()
451
- if (availableModels.length) printModels(availableModels, currentModel?.id)
452
- else console.log(` ${SOFT_GRAY}Could not load the model list.${RST}\n`)
429
+ try {
430
+ availableModels = await loadModels()
431
+ printModels(availableModels, currentModel.id)
432
+ } catch (err) {
433
+ console.error(`${HOT_PINK}✗${RST} Could not refresh models. ${err.message}\n`)
434
+ }
453
435
  continue
454
436
  }
455
437
  if (command === '/model') {
456
- if (!arg) { console.log(` ${SOFT_GRAY}Usage: /model <alias or name>${RST}\n`); continue }
457
- const picked = pickModel(availableModels, arg, agentMode)
438
+ if (!arg) { printModels(availableModels, currentModel.id); continue }
439
+ const picked = pickModel(availableModels, arg, agentMode, accountInfo.tier)
458
440
  if (picked.model) {
459
441
  currentModel = picked.model
460
442
  const tierColor = TIER_COLORS[currentModel.tier] ?? NEON_CYAN
@@ -463,9 +445,9 @@ export async function chat(opts = {}) {
463
445
  continue
464
446
  }
465
447
  if (command === '/mode' || command === '/permissions') {
466
- const wanted = rest[0] === 'edits' ? 'accept-edits' : rest[0]
448
+ const wanted = permissionMode(rest[0])
467
449
  if (!agentMode) console.log(` ${SOFT_GRAY}This is a chat-only session.${RST}\n`)
468
- else if (!wanted) {
450
+ else if (!rest.length) {
469
451
  console.log()
470
452
  console.log(sectionHeader('Permission Mode'))
471
453
  console.log()
@@ -475,13 +457,20 @@ export async function chat(opts = {}) {
475
457
  console.log(` ${active ? `${modeColor}●${RST}` : `${DARK_GRAY}○${RST}`} ${active ? `${modeColor}${BOLD}` : SOFT_GRAY}${mode}${RST} ${DARK_GRAY}${about}${RST}`)
476
458
  }
477
459
  console.log(`\n ${SOFT_GRAY}Change with /mode <mode>${RST}\n`)
478
- } else if (MODES[wanted]) {
460
+ } else if (wanted) {
479
461
  permissions.mode = wanted
480
462
  const modeColor = wanted === 'yolo' ? HOT_PINK : wanted === 'accept-edits' ? ORANGE : NEON_CYAN
481
463
  console.log(`${LIME}✓${RST} Mode: ${modeColor}${BOLD}${wanted}${RST} ${DARK_GRAY}(${MODES[wanted]})${RST}\n`)
482
464
  } else console.log(`${HOT_PINK}✗${RST} Unknown mode. Options: ${Object.keys(MODES).join(', ')}\n`)
483
465
  continue
484
466
  }
467
+ if (command === '/plan') {
468
+ if (!agentMode) { console.log(` ${SOFT_GRAY}Start a Build session to inspect project files.${RST}\n`); continue }
469
+ permissions.mode = 'plan'
470
+ console.log(` ${CYAN}Plan mode${RST} · Read workspace files. Use /permissions to change modes.\n`)
471
+ if (arg) await send(arg)
472
+ continue
473
+ }
485
474
  if (lower === '/tools') {
486
475
  if (!agentMode) { console.log(` ${SOFT_GRAY}This is a chat-only session.${RST}\n`); continue }
487
476
  console.log()
package/lib/config.mjs CHANGED
@@ -1,57 +1,57 @@
1
- import { existsSync, mkdirSync, readFileSync, writeFileSync, chmodSync } from 'node:fs'
2
- import { homedir } from 'node:os'
3
- import { join } from 'node:path'
4
-
5
- const DIR = join(homedir(), '.noguard')
6
- const FILE = join(DIR, 'config.json')
7
-
8
- function ensureDir() {
9
- if (!existsSync(DIR)) mkdirSync(DIR, { recursive: true, mode: 0o700 })
10
- try { chmodSync(DIR, 0o700) } catch { /* windows may not support posix perms */ }
11
- }
12
-
13
- export function load() {
14
- try {
15
- return JSON.parse(readFileSync(FILE, 'utf-8'))
16
- } catch {
17
- return {}
18
- }
19
- }
20
-
21
- export function save(data) {
22
- ensureDir()
23
- writeFileSync(FILE, JSON.stringify(data, null, 2) + '\n', { encoding: 'utf-8', mode: 0o600 })
24
- try { chmodSync(FILE, 0o600) } catch { /* windows may not support posix perms */ }
25
- }
26
-
27
- export function getToken() {
28
- return process.env.NOGUARD_TOKEN || load().token || null
29
- }
30
-
31
- export function setToken(token, account) {
32
- const cfg = load()
33
- cfg.token = token
34
- cfg.account = account
35
- save(cfg)
36
- }
37
-
38
- export function clearToken() {
39
- const cfg = load()
40
- delete cfg.token
41
- delete cfg.account
42
- save(cfg)
43
- }
44
-
45
- export function getEndpoint() {
46
- return (process.env.NOGUARD_URL || load().endpoint || 'https://noguard.ai').replace(/\/+$/, '')
47
- }
48
-
49
- export function setEndpoint(url) {
50
- const cfg = load()
51
- cfg.endpoint = url.replace(/\/+$/, '')
52
- save(cfg)
53
- }
54
-
55
- export function configPath() {
56
- return FILE
57
- }
1
+ import { existsSync, mkdirSync, readFileSync, writeFileSync, chmodSync } from 'node:fs'
2
+ import { homedir } from 'node:os'
3
+ import { join } from 'node:path'
4
+
5
+ const DIR = join(homedir(), '.noguard')
6
+ const FILE = join(DIR, 'config.json')
7
+
8
+ function ensureDir() {
9
+ if (!existsSync(DIR)) mkdirSync(DIR, { recursive: true, mode: 0o700 })
10
+ try { chmodSync(DIR, 0o700) } catch { /* windows may not support posix perms */ }
11
+ }
12
+
13
+ export function load() {
14
+ try {
15
+ return JSON.parse(readFileSync(FILE, 'utf-8'))
16
+ } catch {
17
+ return {}
18
+ }
19
+ }
20
+
21
+ export function save(data) {
22
+ ensureDir()
23
+ writeFileSync(FILE, JSON.stringify(data, null, 2) + '\n', { encoding: 'utf-8', mode: 0o600 })
24
+ try { chmodSync(FILE, 0o600) } catch { /* windows may not support posix perms */ }
25
+ }
26
+
27
+ export function getToken() {
28
+ return process.env.NOGUARD_TOKEN || load().token || null
29
+ }
30
+
31
+ export function setToken(token, account) {
32
+ const cfg = load()
33
+ cfg.token = token
34
+ cfg.account = account
35
+ save(cfg)
36
+ }
37
+
38
+ export function clearToken() {
39
+ const cfg = load()
40
+ delete cfg.token
41
+ delete cfg.account
42
+ save(cfg)
43
+ }
44
+
45
+ export function getEndpoint() {
46
+ return (process.env.NOGUARD_URL || load().endpoint || 'https://noguard.ai').replace(/\/+$/, '')
47
+ }
48
+
49
+ export function setEndpoint(url) {
50
+ const cfg = load()
51
+ cfg.endpoint = url.replace(/\/+$/, '')
52
+ save(cfg)
53
+ }
54
+
55
+ export function configPath() {
56
+ return FILE
57
+ }