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/lib/chat.mjs
CHANGED
|
@@ -1,515 +1,514 @@
|
|
|
1
|
-
import { emitKeypressEvents } from 'node:readline'
|
|
2
|
-
import { createInterface } from 'node:readline/promises'
|
|
3
|
-
import { homedir } from 'node:os'
|
|
4
|
-
import { get } from './api.mjs'
|
|
5
|
-
import { getToken } from './config.mjs'
|
|
6
|
-
import { Agent, MODES, Permissions } from './agent.mjs'
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
const TIER_COLORS = { raw: MAGENTA, ultra: GOLD, pro: MINT, paid: MINT, standard: CYAN, free: MUTED }
|
|
24
|
-
const TIER_ICONS = { raw: '◆', ultra: '✦', pro: '▲', paid: '▲', standard: '⚡', free: '○' }
|
|
25
|
-
const LIB_COLORS = { cyber: ROSE, engineering: CYAN, bio: MINT, creative: IRIS }
|
|
26
|
-
|
|
27
|
-
const LIBRARIES = [
|
|
28
|
-
{ id: 'cyber', label: 'Cipher · Cyber', summary: 'Exploits, offensive security, reverse engineering' },
|
|
29
|
-
{ id: 'engineering', label: 'Forge · Engineering', summary: 'Software, systems and hardware engineering' },
|
|
30
|
-
{ id: 'bio', label: 'Helix · Bio', summary: 'Pharmacology, substance data, harm reduction' },
|
|
31
|
-
{ id: 'creative', label: 'Muse · Creative', summary: 'Uncensored creative writing and full artistic freedom' },
|
|
32
|
-
]
|
|
33
|
-
|
|
34
|
-
const INIT_PROMPT = `Look through this project and write a NOGUARD.md file at the root of the working directory for future sessions to read. Cover, briefly:
|
|
35
|
-
- what the project is and how it is laid out (the main folders and entry points),
|
|
36
|
-
- the commands to install, build, run, lint and test it (check package.json, Makefiles, pyproject, Cargo.toml, CI config and so on),
|
|
37
|
-
- conventions a contributor must follow that are not obvious from a single file.
|
|
38
|
-
Keep it short and specific to this project. If a NOGUARD.md, CLAUDE.md or AGENTS.md already exists, improve on it rather than repeating it.`
|
|
39
|
-
|
|
40
|
-
function fmtNumber(n) {
|
|
41
|
-
return Number(n).toLocaleString('en-US')
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function requireAuth() {
|
|
45
|
-
if (!getToken()) {
|
|
46
|
-
console.log(`${HOT_PINK}✗${RST} Not signed in. Run ${BOLD}noguard login${RST} first.`)
|
|
47
|
-
process.exit(1)
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export function printModels(models, current = null) {
|
|
52
|
-
console.log()
|
|
53
|
-
console.log(sectionHeader('Available Models'))
|
|
54
|
-
console.log()
|
|
55
|
-
for (const model of models) {
|
|
56
|
-
const tierColor = TIER_COLORS[model.tier] ?? NEON_CYAN
|
|
57
|
-
const icon = TIER_ICONS[model.tier] ?? '●'
|
|
58
|
-
const tags = []
|
|
59
|
-
if (model.default_chat) tags.push(`${LIME}chat default${RST}`)
|
|
60
|
-
if (model.default_build) tags.push(`${LIME}agent default${RST}`)
|
|
61
|
-
if (model.default && !model.default_chat && !model.default_build) tags.push(`${LIME}default${RST}`)
|
|
62
|
-
const active = current && model.id === current ? ` ${ORANGE}← active${RST}` : ''
|
|
63
|
-
const tagStr = tags.length ? ` ${tags.join(` ${DARK_GRAY}·${RST} `)}` : ''
|
|
64
|
-
const cost = model.cost_indicator ?? '$'
|
|
65
|
-
console.log(` ${tierColor}${icon}${RST} ${tierColor}${BOLD}${model.display_name}${RST} ${SOFT_GRAY}${model.id}${RST} ${GOLD}${cost}${RST}${tagStr}${active}`)
|
|
66
|
-
if (model.description) console.log(` ${SOFT_GRAY}${model.description}${RST}`)
|
|
67
|
-
const caps = []
|
|
68
|
-
if (model.chat_eligible) caps.push('chat')
|
|
69
|
-
if (model.build_eligible && model.supports_tools !== false) caps.push('agent (files and commands)')
|
|
70
|
-
if (caps.length) console.log(` ${DARK_GRAY}Supports: ${caps.join(', ')} · Context: ${(model.context_window / 1000).toFixed(0)}k · Max output: ${(model.max_output_tokens / 1000).toFixed(0)}k${RST}`)
|
|
71
|
-
console.log()
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function printLibraries(activeLibs) {
|
|
76
|
-
console.log()
|
|
77
|
-
console.log(sectionHeader('Research Libraries'))
|
|
78
|
-
console.log(` ${SOFT_GRAY}Toggle with /library <id> — active libraries inject curated sources into your questions.${RST}`)
|
|
79
|
-
console.log()
|
|
80
|
-
for (const lib of LIBRARIES) {
|
|
81
|
-
const active = activeLibs.has(lib.id)
|
|
82
|
-
const color = LIB_COLORS[lib.id] ?? NEON_CYAN
|
|
83
|
-
const mark = active ? `${color}●${RST}` : `${DARK_GRAY}○${RST}`
|
|
84
|
-
const label = active ? `${BOLD}${color}${lib.label}${RST}` : `${SOFT_GRAY}${lib.label}${RST}`
|
|
85
|
-
console.log(` ${mark} ${label} ${DARK_GRAY}(${lib.id})${RST}`)
|
|
86
|
-
console.log(` ${SOFT_GRAY}${lib.summary}${RST}`)
|
|
87
|
-
}
|
|
88
|
-
console.log()
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function printHelp(agentMode) {
|
|
92
|
-
console.log()
|
|
93
|
-
console.log(sectionHeader('Commands'))
|
|
94
|
-
console.log()
|
|
95
|
-
const cmd = (name, desc) => console.log(` ${NEON_CYAN}${name.padEnd(22)}${RST} ${SOFT_GRAY}${desc}${RST}`)
|
|
96
|
-
cmd('/models', 'List all models with tier info')
|
|
97
|
-
cmd('/model <name>', 'Switch to a model (alias or display name)')
|
|
98
|
-
if (agentMode) {
|
|
99
|
-
cmd('/
|
|
100
|
-
cmd('/
|
|
101
|
-
cmd('/
|
|
102
|
-
cmd('/
|
|
103
|
-
cmd('/
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
cmd('/
|
|
107
|
-
cmd('/
|
|
108
|
-
cmd('/
|
|
109
|
-
cmd('/
|
|
110
|
-
|
|
111
|
-
console.log(
|
|
112
|
-
console.log()
|
|
113
|
-
|
|
114
|
-
key
|
|
115
|
-
key('Ctrl+C
|
|
116
|
-
key('
|
|
117
|
-
key('
|
|
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
|
-
console.log()
|
|
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
|
-
const
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
let
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
const
|
|
234
|
-
|
|
235
|
-
let
|
|
236
|
-
let
|
|
237
|
-
|
|
238
|
-
const
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
})
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
const
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
const
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
row('
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
} catch {
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
if (
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
console.log(
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
console.log()
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
console.log()
|
|
478
|
-
console.log(
|
|
479
|
-
console.log()
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
}
|
|
493
|
-
if (
|
|
494
|
-
|
|
495
|
-
const
|
|
496
|
-
|
|
497
|
-
if (
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
}
|
|
1
|
+
import { emitKeypressEvents } from 'node:readline'
|
|
2
|
+
import { createInterface } from 'node:readline/promises'
|
|
3
|
+
import { homedir } from 'node:os'
|
|
4
|
+
import { get } from './api.mjs'
|
|
5
|
+
import { getToken } from './config.mjs'
|
|
6
|
+
import { Agent, MODES, Permissions, permissionMode } from './agent.mjs'
|
|
7
|
+
import { detectShell } from './shell.mjs'
|
|
8
|
+
import { TOOLS } from './tools.mjs'
|
|
9
|
+
import {
|
|
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,
|
|
16
|
+
creditMeter, tierPill, tierColor, sparkline,
|
|
17
|
+
} from './render.mjs'
|
|
18
|
+
|
|
19
|
+
const RESET_COMMANDS = new Set(['/clear', '/reset', '/new'])
|
|
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
|
+
|
|
23
|
+
const TIER_COLORS = { raw: MAGENTA, ultra: GOLD, pro: MINT, paid: MINT, standard: CYAN, free: MUTED }
|
|
24
|
+
const TIER_ICONS = { raw: '◆', ultra: '✦', pro: '▲', paid: '▲', standard: '⚡', free: '○' }
|
|
25
|
+
const LIB_COLORS = { cyber: ROSE, engineering: CYAN, bio: MINT, creative: IRIS }
|
|
26
|
+
|
|
27
|
+
const LIBRARIES = [
|
|
28
|
+
{ id: 'cyber', label: 'Cipher · Cyber', summary: 'Exploits, offensive security, reverse engineering' },
|
|
29
|
+
{ id: 'engineering', label: 'Forge · Engineering', summary: 'Software, systems and hardware engineering' },
|
|
30
|
+
{ id: 'bio', label: 'Helix · Bio', summary: 'Pharmacology, substance data, harm reduction' },
|
|
31
|
+
{ id: 'creative', label: 'Muse · Creative', summary: 'Uncensored creative writing and full artistic freedom' },
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
const INIT_PROMPT = `Look through this project and write a NOGUARD.md file at the root of the working directory for future sessions to read. Cover, briefly:
|
|
35
|
+
- what the project is and how it is laid out (the main folders and entry points),
|
|
36
|
+
- the commands to install, build, run, lint and test it (check package.json, Makefiles, pyproject, Cargo.toml, CI config and so on),
|
|
37
|
+
- conventions a contributor must follow that are not obvious from a single file.
|
|
38
|
+
Keep it short and specific to this project. If a NOGUARD.md, CLAUDE.md or AGENTS.md already exists, improve on it rather than repeating it.`
|
|
39
|
+
|
|
40
|
+
function fmtNumber(n) {
|
|
41
|
+
return Number(n).toLocaleString('en-US')
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function requireAuth() {
|
|
45
|
+
if (!getToken()) {
|
|
46
|
+
console.log(`${HOT_PINK}✗${RST} Not signed in. Run ${BOLD}noguard login${RST} first.`)
|
|
47
|
+
process.exit(1)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function printModels(models, current = null) {
|
|
52
|
+
console.log()
|
|
53
|
+
console.log(sectionHeader('Available Models'))
|
|
54
|
+
console.log()
|
|
55
|
+
for (const model of models) {
|
|
56
|
+
const tierColor = TIER_COLORS[model.tier] ?? NEON_CYAN
|
|
57
|
+
const icon = TIER_ICONS[model.tier] ?? '●'
|
|
58
|
+
const tags = []
|
|
59
|
+
if (model.default_chat) tags.push(`${LIME}chat default${RST}`)
|
|
60
|
+
if (model.default_build) tags.push(`${LIME}agent default${RST}`)
|
|
61
|
+
if (model.default && !model.default_chat && !model.default_build) tags.push(`${LIME}default${RST}`)
|
|
62
|
+
const active = current && model.id === current ? ` ${ORANGE}← active${RST}` : ''
|
|
63
|
+
const tagStr = tags.length ? ` ${tags.join(` ${DARK_GRAY}·${RST} `)}` : ''
|
|
64
|
+
const cost = model.cost_indicator ?? '$'
|
|
65
|
+
console.log(` ${tierColor}${icon}${RST} ${tierColor}${BOLD}${model.display_name}${RST} ${SOFT_GRAY}${model.id}${RST} ${GOLD}${cost}${RST}${tagStr}${active}`)
|
|
66
|
+
if (model.description) console.log(` ${SOFT_GRAY}${model.description}${RST}`)
|
|
67
|
+
const caps = []
|
|
68
|
+
if (model.chat_eligible) caps.push('chat')
|
|
69
|
+
if (model.build_eligible && model.supports_tools !== false) caps.push('agent (files and commands)')
|
|
70
|
+
if (caps.length) console.log(` ${DARK_GRAY}Supports: ${caps.join(', ')} · Context: ${(model.context_window / 1000).toFixed(0)}k · Max output: ${(model.max_output_tokens / 1000).toFixed(0)}k${RST}`)
|
|
71
|
+
console.log()
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function printLibraries(activeLibs) {
|
|
76
|
+
console.log()
|
|
77
|
+
console.log(sectionHeader('Research Libraries'))
|
|
78
|
+
console.log(` ${SOFT_GRAY}Toggle with /library <id> — active libraries inject curated sources into your questions.${RST}`)
|
|
79
|
+
console.log()
|
|
80
|
+
for (const lib of LIBRARIES) {
|
|
81
|
+
const active = activeLibs.has(lib.id)
|
|
82
|
+
const color = LIB_COLORS[lib.id] ?? NEON_CYAN
|
|
83
|
+
const mark = active ? `${color}●${RST}` : `${DARK_GRAY}○${RST}`
|
|
84
|
+
const label = active ? `${BOLD}${color}${lib.label}${RST}` : `${SOFT_GRAY}${lib.label}${RST}`
|
|
85
|
+
console.log(` ${mark} ${label} ${DARK_GRAY}(${lib.id})${RST}`)
|
|
86
|
+
console.log(` ${SOFT_GRAY}${lib.summary}${RST}`)
|
|
87
|
+
}
|
|
88
|
+
console.log()
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function printHelp(agentMode) {
|
|
92
|
+
console.log()
|
|
93
|
+
console.log(sectionHeader('Commands'))
|
|
94
|
+
console.log()
|
|
95
|
+
const cmd = (name, desc) => console.log(` ${NEON_CYAN}${name.padEnd(22)}${RST} ${SOFT_GRAY}${desc}${RST}`)
|
|
96
|
+
cmd('/models', 'List all models with tier info')
|
|
97
|
+
cmd('/model <name>', 'Switch to a model (alias or display name)')
|
|
98
|
+
if (agentMode) {
|
|
99
|
+
cmd('/permissions [mode]', 'Show or set permissions')
|
|
100
|
+
cmd('/plan [task]', 'Inspect the workspace and plan changes')
|
|
101
|
+
cmd('/init', 'Write a NOGUARD.md describing this project')
|
|
102
|
+
cmd('/compact', 'Free context by dropping old tool output')
|
|
103
|
+
cmd('/tools', 'List the tools NoGuard can use')
|
|
104
|
+
cmd('/status', 'Show session info, credits, model, and stats')
|
|
105
|
+
}
|
|
106
|
+
cmd('/libraries, /libs', 'Show research libraries and their status')
|
|
107
|
+
cmd('/library <id>, /lib', 'Toggle a library on/off')
|
|
108
|
+
cmd('/clear, /reset, /new', 'Start a new conversation')
|
|
109
|
+
cmd('/credits', 'Show remaining credits')
|
|
110
|
+
cmd('/exit, /quit', 'Leave')
|
|
111
|
+
console.log()
|
|
112
|
+
console.log(sectionHeader('Keys'))
|
|
113
|
+
console.log()
|
|
114
|
+
const key = (name, desc) => console.log(` ${GOLD}${name.padEnd(22)}${RST} ${SOFT_GRAY}${desc}${RST}`)
|
|
115
|
+
key('Esc or Ctrl+C', 'Stop NoGuard mid-reply or mid-command')
|
|
116
|
+
key('Ctrl+C twice', 'Exit at the prompt')
|
|
117
|
+
key('End line with \\', 'Continue on the next line (pasting works too)')
|
|
118
|
+
key('Type """', 'Start/end a multi-line block')
|
|
119
|
+
console.log()
|
|
120
|
+
}
|
|
121
|
+
|
|
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)
|
|
127
|
+
if (requested) {
|
|
128
|
+
const name = requested.toLowerCase()
|
|
129
|
+
const match = models.find(m => m.id === requested || m.id === name || m.display_name.toLowerCase() === name)
|
|
130
|
+
if (!match) return { model: null, warning: `Model "${requested}" not found. Run /models to see options.` }
|
|
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.` }
|
|
135
|
+
return { model: match }
|
|
136
|
+
}
|
|
137
|
+
const model = agentMode
|
|
138
|
+
? models.find(m => m.default_build && usable(m)) ?? models.find(usable)
|
|
139
|
+
: models.find(m => (m.default_chat || m.default) && usable(m)) ?? models.find(usable)
|
|
140
|
+
return model ? { model } : { model: null, warning: `No ${agentMode ? 'Build' : 'Chat'} model is available to your account.` }
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
async function loadModels() {
|
|
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
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function shortPath(path) {
|
|
150
|
+
const home = homedir()
|
|
151
|
+
return path.toLowerCase().startsWith(home.toLowerCase()) ? `~${path.slice(home.length)}` : path
|
|
152
|
+
}
|
|
153
|
+
|
|
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)}`
|
|
159
|
+
}
|
|
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}`)
|
|
165
|
+
console.log()
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** `noguard -p "…"`: one task, no prompts, then exit. Edits and commands need --accept-edits or --yolo. */
|
|
169
|
+
/** Build (tools) comes with any credit pack; a free account chats. Says so once and returns whether tools stay on. */
|
|
170
|
+
function buildAllowed(account, wanted, log = console.log) {
|
|
171
|
+
if (!wanted || !account || account.tier === 'paid') return wanted
|
|
172
|
+
log(`${ORANGE}⚠${RST} Build mode (working on files and running commands) comes with any credit pack. This is a chat-only session.`)
|
|
173
|
+
log(` ${FAINT}Unlock Build, NoGuard Ultra and the desktop app: https://noguard.ai/credits${RST}`)
|
|
174
|
+
return false
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export async function runOnce(opts) {
|
|
178
|
+
requireAuth()
|
|
179
|
+
const [models, account] = await Promise.all([loadModels(), get('/api/v1/me')])
|
|
180
|
+
const agentMode = buildAllowed(account, opts.tools !== false, line => console.error(line))
|
|
181
|
+
const { model, warning } = pickModel(models, opts.model, agentMode, account.tier)
|
|
182
|
+
if (warning) throw new Error(warning)
|
|
183
|
+
const agent = new Agent({
|
|
184
|
+
cwd: process.cwd(),
|
|
185
|
+
ui: { interactive: false, ask: async () => null },
|
|
186
|
+
getModel: () => model,
|
|
187
|
+
permissions: new Permissions(opts.mode ?? 'ask'),
|
|
188
|
+
tools: agentMode,
|
|
189
|
+
})
|
|
190
|
+
const onInt = () => agent.busy ? agent.abort() : process.exit(130)
|
|
191
|
+
process.on('SIGINT', onInt)
|
|
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
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export async function chat(opts = {}) {
|
|
202
|
+
requireAuth()
|
|
203
|
+
const cwd = process.cwd()
|
|
204
|
+
const [initialModels, accountInfo] = await Promise.all([
|
|
205
|
+
loadModels(),
|
|
206
|
+
get('/api/v1/me'),
|
|
207
|
+
])
|
|
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
|
|
213
|
+
|
|
214
|
+
const permissions = new Permissions(opts.mode ?? 'ask')
|
|
215
|
+
const activeLibraries = new Set()
|
|
216
|
+
let credits = accountInfo?.credits ?? null
|
|
217
|
+
let available = accountInfo?.available ?? null
|
|
218
|
+
|
|
219
|
+
const sessionStart = Date.now()
|
|
220
|
+
let sessionMessages = 0
|
|
221
|
+
let sessionCredits = 0
|
|
222
|
+
|
|
223
|
+
const interactive = process.stdin.isTTY !== false
|
|
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 })
|
|
233
|
+
const pasted = []
|
|
234
|
+
rl.on('line', line => pasted.push(line))
|
|
235
|
+
let asking = null
|
|
236
|
+
let lastInterrupt = 0
|
|
237
|
+
|
|
238
|
+
const ui = {
|
|
239
|
+
interactive: true,
|
|
240
|
+
async ask(question) {
|
|
241
|
+
asking = new AbortController()
|
|
242
|
+
try {
|
|
243
|
+
return await rl.question(question, { signal: asking.signal })
|
|
244
|
+
} catch {
|
|
245
|
+
return null
|
|
246
|
+
} finally {
|
|
247
|
+
asking = null
|
|
248
|
+
}
|
|
249
|
+
},
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
const agent = new Agent({
|
|
253
|
+
cwd,
|
|
254
|
+
ui,
|
|
255
|
+
getModel: () => currentModel,
|
|
256
|
+
permissions,
|
|
257
|
+
tools: agentMode,
|
|
258
|
+
getLibraries: () => [...activeLibraries],
|
|
259
|
+
})
|
|
260
|
+
|
|
261
|
+
rl.on('SIGINT', () => {
|
|
262
|
+
if (asking) { asking.abort(); agent.abort(); return }
|
|
263
|
+
if (agent.busy) { agent.abort(); return }
|
|
264
|
+
if (rl.line) { rl.write(null, { ctrl: true, name: 'u' }); return }
|
|
265
|
+
if (Date.now() - lastInterrupt < 2000) { console.log(`\n${SOFT_GRAY} Bye.${RST}`); process.exit(0) }
|
|
266
|
+
lastInterrupt = Date.now()
|
|
267
|
+
process.stdout.write(`\n${SOFT_GRAY} Press Ctrl+C again to exit.${RST}\n`)
|
|
268
|
+
rl.prompt()
|
|
269
|
+
})
|
|
270
|
+
rl.on('close', () => { console.log(`${SOFT_GRAY} Bye.${RST}`); process.exit(0) })
|
|
271
|
+
if (interactive) {
|
|
272
|
+
emitKeypressEvents(process.stdin, rl)
|
|
273
|
+
process.stdin.on('keypress', (_, key) => {
|
|
274
|
+
if (key?.name === 'escape' && agent.busy && !asking) agent.abort()
|
|
275
|
+
})
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
printBanner({ model: currentModel, agentMode, cwd })
|
|
279
|
+
|
|
280
|
+
function buildPrompt() {
|
|
281
|
+
const modelName = currentModel?.display_name ?? 'default'
|
|
282
|
+
const mColor = tierColor(currentModel?.tier)
|
|
283
|
+
const modeColor = permissions.mode === 'yolo' ? ROSE : permissions.mode === 'accept-edits' ? AMBER : CYAN
|
|
284
|
+
const low = credits !== null && credits < 100
|
|
285
|
+
const credStr = credits !== null ? fmtNumber(credits) : '?'
|
|
286
|
+
const sep = ` ${FAINT}│${RST} `
|
|
287
|
+
const segs = [
|
|
288
|
+
`${mColor}${BOLD}${modelName}${RST}${currentModel?.tier ? ` ${FAINT}${currentModel.tier}${RST}` : ''}`,
|
|
289
|
+
agentMode ? `${modeColor}${permissions.mode}${RST}` : 'Chat',
|
|
290
|
+
`${low ? ROSE : AMBER}${BOLD}${credStr}${RST} ${FAINT}cr${RST}`,
|
|
291
|
+
]
|
|
292
|
+
const libs = [...activeLibraries]
|
|
293
|
+
if (libs.length) segs.push(`${CYAN}${libs.map(id => LIBRARIES.find(l => l.id === id)?.label.split(' · ')[0] ?? id).join(', ')} ●${RST}`)
|
|
294
|
+
if (agentMode) {
|
|
295
|
+
try {
|
|
296
|
+
const left = agent.contextUse().left
|
|
297
|
+
segs.push(`${DIMFG}${Math.round(left / 4000)}k${RST} ${FAINT}ctx${RST}`)
|
|
298
|
+
} catch { /* context estimate is best-effort */ }
|
|
299
|
+
}
|
|
300
|
+
return ` ${segs.join(sep)}\n ${CYAN}❯${RST} `
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
const more = `${DARK_GRAY} …${RST} `
|
|
304
|
+
|
|
305
|
+
async function readInput() {
|
|
306
|
+
pasted.length = 0
|
|
307
|
+
const first = await rl.question(buildPrompt())
|
|
308
|
+
if (interactive) await new Promise(r => setTimeout(r, 30))
|
|
309
|
+
const lines = [first, ...(interactive ? pasted.splice(0) : [])]
|
|
310
|
+
if (lines.length === 1 && lines[0].trim() === '"""') {
|
|
311
|
+
const block = []
|
|
312
|
+
for (;;) {
|
|
313
|
+
const line = await rl.question(more)
|
|
314
|
+
if (line.trim() === '"""') break
|
|
315
|
+
block.push(line)
|
|
316
|
+
}
|
|
317
|
+
return block.join('\n')
|
|
318
|
+
}
|
|
319
|
+
while (lines.at(-1).endsWith('\\')) {
|
|
320
|
+
lines[lines.length - 1] = lines.at(-1).slice(0, -1)
|
|
321
|
+
lines.push(await rl.question(more))
|
|
322
|
+
}
|
|
323
|
+
return lines.join('\n')
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
async function send(text) {
|
|
327
|
+
console.log()
|
|
328
|
+
const { spent, balance } = await agent.send(text)
|
|
329
|
+
if (balance != null) { credits = balance; available = balance }
|
|
330
|
+
if (spent) { sessionCredits += spent; sessionMessages++ }
|
|
331
|
+
console.log()
|
|
332
|
+
if (spent) {
|
|
333
|
+
console.log(statusBar([
|
|
334
|
+
['used', `${spent} cr`, AMBER],
|
|
335
|
+
['balance', `${fmtNumber(credits ?? '?')}`, credits !== null && credits < 100 ? ROSE : MINT],
|
|
336
|
+
['model', currentModel?.display_name ?? 'default', tierColor(currentModel?.tier)],
|
|
337
|
+
['mode', permissions.mode, permissions.mode === 'yolo' ? ROSE : permissions.mode === 'accept-edits' ? AMBER : CYAN],
|
|
338
|
+
]))
|
|
339
|
+
}
|
|
340
|
+
console.log()
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
if (opts.prompt) await send(opts.prompt)
|
|
344
|
+
|
|
345
|
+
for (;;) {
|
|
346
|
+
let input
|
|
347
|
+
try {
|
|
348
|
+
input = await readInput()
|
|
349
|
+
} catch {
|
|
350
|
+
break
|
|
351
|
+
}
|
|
352
|
+
const trimmed = input.trim()
|
|
353
|
+
if (!trimmed) continue
|
|
354
|
+
const lower = trimmed.toLowerCase()
|
|
355
|
+
const [command, ...rest] = lower.split(/\s+/)
|
|
356
|
+
const arg = trimmed.split(/\s+/).slice(1).join(' ')
|
|
357
|
+
|
|
358
|
+
if (EXIT_COMMANDS.has(lower)) break
|
|
359
|
+
if (RESET_COMMANDS.has(lower)) {
|
|
360
|
+
agent.reset()
|
|
361
|
+
sessionMessages = 0; sessionCredits = 0
|
|
362
|
+
console.log(`${LIME}✓${RST} New conversation.\n`)
|
|
363
|
+
continue
|
|
364
|
+
}
|
|
365
|
+
if (lower === '/help' || lower === '/?') { printHelp(agentMode); continue }
|
|
366
|
+
if (lower === '/status') {
|
|
367
|
+
console.log()
|
|
368
|
+
console.log(sectionHeader('Session'))
|
|
369
|
+
console.log()
|
|
370
|
+
const row = (name, value) => console.log(` ${MUTED}${name.padEnd(10)}${RST} ${value}`)
|
|
371
|
+
const elapsed = Math.floor((Date.now() - sessionStart) / 60000)
|
|
372
|
+
const modeColor = permissions.mode === 'yolo' ? ROSE : permissions.mode === 'accept-edits' ? AMBER : CYAN
|
|
373
|
+
if (accountInfo) row('Account', `${FG_STRONG}${BOLD}${accountInfo.display_name || accountInfo.email.split('@')[0]}${RST} ${tierPill(accountInfo.tier)} ${MUTED}${accountInfo.email}${RST}`)
|
|
374
|
+
row('Model', `${tierColor(currentModel?.tier)}${BOLD}${currentModel?.display_name ?? 'default'}${RST} ${FAINT}(${currentModel?.id ?? 'auto'})${RST}`)
|
|
375
|
+
row('Mode', `${modeColor}${BOLD}${permissions.mode}${RST}`)
|
|
376
|
+
row('Folder', `${SKY}${shortPath(cwd)}${RST}`)
|
|
377
|
+
row('Shell', `${DIMFG}${detectShell().label}${RST}`)
|
|
378
|
+
if (credits !== null) {
|
|
379
|
+
const low = credits < 100
|
|
380
|
+
row('Credits', `${low ? ROSE : AMBER}${BOLD}${fmtNumber(available ?? credits)}${RST} ${MUTED}available${RST} ${FAINT}of ${fmtNumber(credits)}${RST} ${creditMeter(available ?? credits, credits, { low })}`)
|
|
381
|
+
}
|
|
382
|
+
const libs = [...activeLibraries]
|
|
383
|
+
if (libs.length) row('Libraries', libs.map(id => `${LIB_COLORS[id] ?? CYAN}${id}${RST}`).join(', '))
|
|
384
|
+
console.log(` ${LINE}${'─'.repeat(Math.max(10, Math.min(termWidth() - 4, 58)))}${RST}`)
|
|
385
|
+
row('This run', `${IRIS}${BOLD}${sessionMessages}${RST} ${MUTED}msgs${RST} ${FAINT}·${RST} ${IRIS}${BOLD}${fmtNumber(sessionCredits)}${RST} ${MUTED}cr${RST} ${FAINT}·${RST} ${IRIS}${BOLD}${elapsed}${RST} ${MUTED}min${RST}`)
|
|
386
|
+
console.log()
|
|
387
|
+
continue
|
|
388
|
+
}
|
|
389
|
+
if (lower === '/credits') {
|
|
390
|
+
console.log()
|
|
391
|
+
console.log(sectionHeader('Credits'))
|
|
392
|
+
console.log()
|
|
393
|
+
try {
|
|
394
|
+
const me = await get('/api/v1/me')
|
|
395
|
+
credits = me.credits; available = me.available
|
|
396
|
+
const low = me.low_balance || me.available < 100
|
|
397
|
+
const row = (name, value) => console.log(` ${MUTED}${name.padEnd(10)}${RST} ${value}`)
|
|
398
|
+
row('Balance', `${AMBER}${BOLD}${fmtNumber(me.credits)}${RST}`)
|
|
399
|
+
row('Available', `${low ? ROSE : AMBER}${BOLD}${fmtNumber(me.available)}${RST} ${creditMeter(me.available, me.credits, { low })}`)
|
|
400
|
+
const held = Math.max(0, me.credits - me.available)
|
|
401
|
+
if (held) row('On hold', `${MUTED}${fmtNumber(held)}${RST}`)
|
|
402
|
+
if (sessionCredits) row('This run', `${IRIS}${BOLD}${fmtNumber(sessionCredits)}${RST} ${MUTED}spent${RST}`)
|
|
403
|
+
try {
|
|
404
|
+
const usage = await get('/api/v1/usage?days=14')
|
|
405
|
+
const byDay = new Map((usage.days ?? []).map(d => [d.day, d.credits]))
|
|
406
|
+
if (byDay.size) {
|
|
407
|
+
const arr = []
|
|
408
|
+
const now = new Date()
|
|
409
|
+
for (let i = 13; i >= 0; i--) {
|
|
410
|
+
const dt = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate() - i))
|
|
411
|
+
arr.push(byDay.get(dt.toISOString().slice(0, 10)) ?? 0)
|
|
412
|
+
}
|
|
413
|
+
const total = arr.reduce((a, b) => a + b, 0)
|
|
414
|
+
console.log()
|
|
415
|
+
console.log(` ${MUTED}credits / day${RST} ${FAINT}· last 14 days · ${fmtNumber(total)} total${RST}`)
|
|
416
|
+
console.log(` ${sparkline(arr)} ${FAINT}today${RST} ${AMBER}${BOLD}${fmtNumber(arr.at(-1))}${RST}`)
|
|
417
|
+
}
|
|
418
|
+
} catch { /* usage sparkline is best-effort */ }
|
|
419
|
+
console.log()
|
|
420
|
+
console.log(` ${FAINT}top up at${RST} ${SKY}${UNDERLINE}https://noguard.ai/credits${RST}`)
|
|
421
|
+
} catch {
|
|
422
|
+
if (credits !== null) console.log(` ${AMBER}${fmtNumber(credits)}${RST} credits remaining.`)
|
|
423
|
+
else console.log(` ${MUTED}Could not load your balance.${RST}`)
|
|
424
|
+
}
|
|
425
|
+
console.log()
|
|
426
|
+
continue
|
|
427
|
+
}
|
|
428
|
+
if (lower === '/models') {
|
|
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
|
+
}
|
|
435
|
+
continue
|
|
436
|
+
}
|
|
437
|
+
if (command === '/model') {
|
|
438
|
+
if (!arg) { printModels(availableModels, currentModel.id); continue }
|
|
439
|
+
const picked = pickModel(availableModels, arg, agentMode, accountInfo.tier)
|
|
440
|
+
if (picked.model) {
|
|
441
|
+
currentModel = picked.model
|
|
442
|
+
const tierColor = TIER_COLORS[currentModel.tier] ?? NEON_CYAN
|
|
443
|
+
console.log(`${LIME}✓${RST} Switched to ${tierColor}${BOLD}${currentModel.display_name}${RST} ${DARK_GRAY}(${currentModel.id})${RST}\n`)
|
|
444
|
+
} else console.log(`${HOT_PINK}✗${RST} ${picked.warning}\n`)
|
|
445
|
+
continue
|
|
446
|
+
}
|
|
447
|
+
if (command === '/mode' || command === '/permissions') {
|
|
448
|
+
const wanted = permissionMode(rest[0])
|
|
449
|
+
if (!agentMode) console.log(` ${SOFT_GRAY}This is a chat-only session.${RST}\n`)
|
|
450
|
+
else if (!rest.length) {
|
|
451
|
+
console.log()
|
|
452
|
+
console.log(sectionHeader('Permission Mode'))
|
|
453
|
+
console.log()
|
|
454
|
+
for (const [mode, about] of Object.entries(MODES)) {
|
|
455
|
+
const modeColor = mode === 'yolo' ? HOT_PINK : mode === 'accept-edits' ? ORANGE : NEON_CYAN
|
|
456
|
+
const active = mode === permissions.mode
|
|
457
|
+
console.log(` ${active ? `${modeColor}●${RST}` : `${DARK_GRAY}○${RST}`} ${active ? `${modeColor}${BOLD}` : SOFT_GRAY}${mode}${RST} ${DARK_GRAY}${about}${RST}`)
|
|
458
|
+
}
|
|
459
|
+
console.log(`\n ${SOFT_GRAY}Change with /mode <mode>${RST}\n`)
|
|
460
|
+
} else if (wanted) {
|
|
461
|
+
permissions.mode = wanted
|
|
462
|
+
const modeColor = wanted === 'yolo' ? HOT_PINK : wanted === 'accept-edits' ? ORANGE : NEON_CYAN
|
|
463
|
+
console.log(`${LIME}✓${RST} Mode: ${modeColor}${BOLD}${wanted}${RST} ${DARK_GRAY}(${MODES[wanted]})${RST}\n`)
|
|
464
|
+
} else console.log(`${HOT_PINK}✗${RST} Unknown mode. Options: ${Object.keys(MODES).join(', ')}\n`)
|
|
465
|
+
continue
|
|
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
|
+
}
|
|
474
|
+
if (lower === '/tools') {
|
|
475
|
+
if (!agentMode) { console.log(` ${SOFT_GRAY}This is a chat-only session.${RST}\n`); continue }
|
|
476
|
+
console.log()
|
|
477
|
+
console.log(sectionHeader('Available Tools'))
|
|
478
|
+
console.log()
|
|
479
|
+
for (const tool of TOOLS) console.log(` ${LIME}${BOLD}${tool.name.padEnd(12)}${RST} ${SOFT_GRAY}${tool.description.split('\n')[0]}${RST}`)
|
|
480
|
+
console.log(`\n ${DARK_GRAY}Commands run in ${BRIGHT_WHITE}${detectShell().label}${DARK_GRAY}.${RST}\n`)
|
|
481
|
+
continue
|
|
482
|
+
}
|
|
483
|
+
if (lower === '/compact') {
|
|
484
|
+
console.log(agent.compact() ? `${LIME}✓${RST} Dropped older tool output.\n` : ` ${SOFT_GRAY}Nothing to compact yet.${RST}\n`)
|
|
485
|
+
continue
|
|
486
|
+
}
|
|
487
|
+
if (lower === '/init') {
|
|
488
|
+
if (!agentMode) { console.log(` ${SOFT_GRAY}This is a chat-only session.${RST}\n`); continue }
|
|
489
|
+
await send(INIT_PROMPT)
|
|
490
|
+
continue
|
|
491
|
+
}
|
|
492
|
+
if (lower === '/libraries' || lower === '/libs') { printLibraries(activeLibraries); continue }
|
|
493
|
+
if (command === '/library' || command === '/lib') {
|
|
494
|
+
const id = rest[0]
|
|
495
|
+
const lib = LIBRARIES.find(l => l.id === id)
|
|
496
|
+
if (!lib) console.log(`${HOT_PINK}✗${RST} Unknown library "${id ?? ''}". Options: ${LIBRARIES.map(l => l.id).join(', ')}\n`)
|
|
497
|
+
else if (activeLibraries.has(id)) {
|
|
498
|
+
activeLibraries.delete(id)
|
|
499
|
+
console.log(`${LIME}✓${RST} Disabled ${LIB_COLORS[id] ?? NEON_CYAN}${BOLD}${lib.label}${RST}\n`)
|
|
500
|
+
} else {
|
|
501
|
+
activeLibraries.add(id)
|
|
502
|
+
console.log(`${LIME}✓${RST} Enabled ${LIB_COLORS[id] ?? NEON_CYAN}${BOLD}${lib.label}${RST}\n`)
|
|
503
|
+
}
|
|
504
|
+
continue
|
|
505
|
+
}
|
|
506
|
+
if (trimmed.startsWith('/') && !trimmed.includes(' ') && trimmed.length < 20) {
|
|
507
|
+
console.log(`${HOT_PINK}✗${RST} Unknown command ${BRIGHT_WHITE}${trimmed}${RST}. Type /help for the list.\n`)
|
|
508
|
+
continue
|
|
509
|
+
}
|
|
510
|
+
await send(input)
|
|
511
|
+
}
|
|
512
|
+
console.log(`${SOFT_GRAY} Bye.${RST}`)
|
|
513
|
+
process.exit(0)
|
|
514
|
+
}
|