nlos 1.0.0 → 1.2.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.
Files changed (2) hide show
  1. package/bin/nlos.js +114 -5
  2. package/package.json +1 -1
package/bin/nlos.js CHANGED
@@ -6,7 +6,8 @@
6
6
  * A model-agnostic kernel that turns any LLM into a cognitive operating system.
7
7
  *
8
8
  * Usage:
9
- * nlos boot [options] Boot NL-OS with a local LLM
9
+ * nlos chat [options] Interactive NL-OS chat session (recommended)
10
+ * nlos boot [options] Boot NL-OS and verify kernel loads
10
11
  * nlos payload [options] Generate portable kernel payloads
11
12
  * nlos verify Verify kernel files exist
12
13
  * nlos tokens Show token estimates
@@ -247,6 +248,108 @@ function boot(options = {}) {
247
248
  }
248
249
  }
249
250
 
251
+ function chat(options = {}) {
252
+ const {
253
+ model = 'qwen2.5:3b',
254
+ full = false,
255
+ profile = null,
256
+ } = options;
257
+
258
+ // Resolve model based on profile
259
+ let selectedModel = model;
260
+ if (profile) {
261
+ const profiles = {
262
+ speed: 'qwen2.5:3b',
263
+ balanced: 'mistral:7b',
264
+ quality: 'llama3.1:8b',
265
+ memory_constrained: 'qwen2.5:3b',
266
+ };
267
+ selectedModel = profiles[profile] || model;
268
+ }
269
+
270
+ log('blue', `Starting NL-OS chat session...`);
271
+ log('cyan', `Model: ${selectedModel}`);
272
+ log('cyan', `Tier: ${full ? 'FULL' : 'MANDATORY'}`);
273
+ console.log();
274
+
275
+ // Generate the kernel payload
276
+ log('yellow', 'Building kernel payload...');
277
+ const payload = generatePayload(full ? 'full' : 'mandatory', 'markdown');
278
+
279
+ // Escape the payload for Modelfile SYSTEM directive
280
+ // Replace """ with escaped version and handle multiline
281
+ const escapedPayload = payload.replace(/"""/g, '\\"\\"\\"');
282
+
283
+ const tokenEstimate = full ? '~15,500' : '~10,600';
284
+ log('green', `Kernel payload ready (${tokenEstimate} tokens)`);
285
+ console.log();
286
+
287
+ // Check if base model exists locally
288
+ try {
289
+ execSync(`ollama list | grep -q "${selectedModel.split(':')[0]}"`, { stdio: 'pipe' });
290
+ } catch {
291
+ log('yellow', `Model ${selectedModel} not found locally. Pulling...`);
292
+ try {
293
+ execSync(`ollama pull ${selectedModel}`, { stdio: 'inherit' });
294
+ } catch (error) {
295
+ log('red', `Failed to pull model: ${error.message}`);
296
+ process.exit(1);
297
+ }
298
+ }
299
+
300
+ // Create a temporary Modelfile with the kernel as system prompt
301
+ log('yellow', 'Creating NL-OS model variant...');
302
+ const modelfilePath = path.join(PACKAGE_ROOT, 'portable', '.Modelfile.nlos');
303
+ const nlosModelName = 'nlos-kernel:latest';
304
+
305
+ const modelfileContent = `FROM ${selectedModel}
306
+ SYSTEM """${payload}"""
307
+ `;
308
+
309
+ fs.mkdirSync(path.dirname(modelfilePath), { recursive: true });
310
+ fs.writeFileSync(modelfilePath, modelfileContent);
311
+
312
+ // Create the nlos model variant
313
+ try {
314
+ execSync(`ollama create ${nlosModelName} -f "${modelfilePath}"`, {
315
+ stdio: 'pipe',
316
+ cwd: PACKAGE_ROOT
317
+ });
318
+ log('green', `Created model: ${nlosModelName}`);
319
+ } catch (error) {
320
+ log('red', `Failed to create model: ${error.message}`);
321
+ log('yellow', 'Falling back to manual system prompt...');
322
+
323
+ // Fallback: just run the base model and tell user to paste
324
+ console.log('\nCould not create kernel model. Run manually:');
325
+ console.log(` ollama run ${selectedModel}`);
326
+ console.log(' Then paste the kernel from: portable/kernel-payload.md\n');
327
+ process.exit(1);
328
+ }
329
+
330
+ log('green', `Launching interactive session...`);
331
+ log('cyan', '─'.repeat(60));
332
+ console.log();
333
+
334
+ // Spawn interactive ollama session with the nlos model
335
+ const child = spawn('ollama', ['run', nlosModelName], {
336
+ stdio: 'inherit',
337
+ });
338
+
339
+ child.on('error', (error) => {
340
+ log('red', `Error: ${error.message}`);
341
+ log('yellow', 'Make sure Ollama is installed and running: https://ollama.ai');
342
+ process.exit(1);
343
+ });
344
+
345
+ child.on('exit', (code) => {
346
+ console.log();
347
+ log('cyan', '─'.repeat(60));
348
+ log('blue', 'NL-OS session ended.');
349
+ process.exit(code || 0);
350
+ });
351
+ }
352
+
250
353
  function payload(options = {}) {
251
354
  const {
252
355
  tier = 'mandatory',
@@ -298,7 +401,8 @@ ${colors.yellow}Usage:${colors.reset}
298
401
  nlos <command> [options]
299
402
 
300
403
  ${colors.yellow}Commands:${colors.reset}
301
- boot Boot NL-OS with a local LLM
404
+ chat Interactive NL-OS chat session (recommended)
405
+ boot Boot NL-OS and verify kernel loads
302
406
  payload Generate portable kernel payloads
303
407
  verify Verify kernel files exist
304
408
  tokens Show token estimates
@@ -318,9 +422,10 @@ ${colors.yellow}Payload Options:${colors.reset}
318
422
  --all Generate all variants
319
423
 
320
424
  ${colors.yellow}Examples:${colors.reset}
321
- nlos boot # Boot with default model
322
- nlos boot --model llama3.1:8b # Boot with specific model
323
- nlos boot --profile quality --full # Quality mode with full kernel
425
+ nlos chat # Start interactive chat (recommended)
426
+ nlos chat --model llama3.1:8b # Chat with specific model
427
+ nlos chat --profile quality --full # Quality mode with full kernel
428
+ nlos boot # Verify kernel loads (one-shot)
324
429
  nlos boot --dry-run # Preview system prompt
325
430
  nlos payload # Generate default payload
326
431
  nlos payload --all # Generate all payloads
@@ -372,6 +477,10 @@ const command = args[0];
372
477
  const options = parseArgs(args.slice(1));
373
478
 
374
479
  switch (command) {
480
+ case 'chat':
481
+ chat(options);
482
+ break;
483
+
375
484
  case 'boot':
376
485
  boot(options);
377
486
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nlos",
3
- "version": "1.0.0",
3
+ "version": "1.2.0",
4
4
  "description": "Natural Language Operating System - A model-agnostic kernel for any LLM",
5
5
  "main": "bin/nlos.js",
6
6
  "bin": {