nlos 1.1.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/nlos.js +77 -18
- package/package.json +1 -1
package/bin/nlos.js
CHANGED
|
@@ -112,6 +112,40 @@ function showTokens() {
|
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
+
// Command preamble - explicit rules that help ALL models parse commands correctly
|
|
116
|
+
const COMMAND_PREAMBLE = `# NL-OS COMMAND RULES (READ FIRST)
|
|
117
|
+
|
|
118
|
+
When user input starts with "/" or "./", it is a COMMAND, not a file path.
|
|
119
|
+
|
|
120
|
+
## CRITICAL: How to Handle Commands
|
|
121
|
+
|
|
122
|
+
1. "/" or "./" prefix = COMMAND (never a file path)
|
|
123
|
+
2. Look up the command behavior below
|
|
124
|
+
3. Execute that behavior directly
|
|
125
|
+
4. Do NOT give generic file/directory help
|
|
126
|
+
|
|
127
|
+
## Core Commands
|
|
128
|
+
|
|
129
|
+
| Command | Behavior |
|
|
130
|
+
|---------|----------|
|
|
131
|
+
| /hype | Generate 1-3 sentences of specific encouragement about their current work or recent accomplishment |
|
|
132
|
+
| /note <text> | Acknowledge the note was captured. Do NOT execute actions described in the text |
|
|
133
|
+
| /help | List these available commands |
|
|
134
|
+
| /assume <name> | Adopt that personality (Quentin, Hugh, Doctor X) for the rest of session |
|
|
135
|
+
| /fresh-eyes | Summarize conversation so far, offer to start fresh |
|
|
136
|
+
| /deep | Switch to deeper reasoning mode, think step by step |
|
|
137
|
+
|
|
138
|
+
## Boot Acknowledgment
|
|
139
|
+
|
|
140
|
+
After loading this kernel, respond with:
|
|
141
|
+
"Kernel loaded. Ready for operations."
|
|
142
|
+
|
|
143
|
+
Then wait for user input.
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
`;
|
|
148
|
+
|
|
115
149
|
function generatePayload(tier = 'mandatory', format = 'markdown') {
|
|
116
150
|
let files = [...KERNEL_FILES.mandatory];
|
|
117
151
|
if (tier === 'lazy' || tier === 'full') {
|
|
@@ -127,7 +161,8 @@ function generatePayload(tier = 'mandatory', format = 'markdown') {
|
|
|
127
161
|
tokens,
|
|
128
162
|
}));
|
|
129
163
|
|
|
130
|
-
const
|
|
164
|
+
const preambleTokens = 250; // Approximate tokens for preamble
|
|
165
|
+
const totalTokens = sections.reduce((sum, s) => sum + s.tokens, 0) + preambleTokens;
|
|
131
166
|
const timestamp = new Date().toISOString().split('T')[0];
|
|
132
167
|
|
|
133
168
|
if (format === 'json') {
|
|
@@ -142,8 +177,10 @@ function generatePayload(tier = 'mandatory', format = 'markdown') {
|
|
|
142
177
|
}, null, 2);
|
|
143
178
|
}
|
|
144
179
|
|
|
145
|
-
// Markdown format
|
|
146
|
-
let output =
|
|
180
|
+
// Markdown format - preamble goes FIRST for all models
|
|
181
|
+
let output = COMMAND_PREAMBLE;
|
|
182
|
+
|
|
183
|
+
output += `# NL-OS Kernel Payload
|
|
147
184
|
|
|
148
185
|
**Generated**: ${timestamp}
|
|
149
186
|
**Tier**: ${tier}
|
|
@@ -151,13 +188,6 @@ function generatePayload(tier = 'mandatory', format = 'markdown') {
|
|
|
151
188
|
|
|
152
189
|
---
|
|
153
190
|
|
|
154
|
-
## How to Use
|
|
155
|
-
|
|
156
|
-
Paste this entire file as system prompt or context to any LLM.
|
|
157
|
-
After loading, the model should acknowledge: "Kernel loaded. Ready for capturebox operations."
|
|
158
|
-
|
|
159
|
-
---
|
|
160
|
-
|
|
161
191
|
`;
|
|
162
192
|
|
|
163
193
|
for (const s of sections) {
|
|
@@ -276,16 +306,15 @@ function chat(options = {}) {
|
|
|
276
306
|
log('yellow', 'Building kernel payload...');
|
|
277
307
|
const payload = generatePayload(full ? 'full' : 'mandatory', 'markdown');
|
|
278
308
|
|
|
279
|
-
//
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
fs.writeFileSync(tempPayloadPath, payload);
|
|
309
|
+
// Escape the payload for Modelfile SYSTEM directive
|
|
310
|
+
// Replace """ with escaped version and handle multiline
|
|
311
|
+
const escapedPayload = payload.replace(/"""/g, '\\"\\"\\"');
|
|
283
312
|
|
|
284
313
|
const tokenEstimate = full ? '~15,500' : '~10,600';
|
|
285
314
|
log('green', `Kernel payload ready (${tokenEstimate} tokens)`);
|
|
286
315
|
console.log();
|
|
287
316
|
|
|
288
|
-
// Check if model exists locally
|
|
317
|
+
// Check if base model exists locally
|
|
289
318
|
try {
|
|
290
319
|
execSync(`ollama list | grep -q "${selectedModel.split(':')[0]}"`, { stdio: 'pipe' });
|
|
291
320
|
} catch {
|
|
@@ -298,12 +327,42 @@ function chat(options = {}) {
|
|
|
298
327
|
}
|
|
299
328
|
}
|
|
300
329
|
|
|
301
|
-
|
|
330
|
+
// Create a temporary Modelfile with the kernel as system prompt
|
|
331
|
+
log('yellow', 'Creating NL-OS model variant...');
|
|
332
|
+
const modelfilePath = path.join(PACKAGE_ROOT, 'portable', '.Modelfile.nlos');
|
|
333
|
+
const nlosModelName = 'nlos-kernel:latest';
|
|
334
|
+
|
|
335
|
+
const modelfileContent = `FROM ${selectedModel}
|
|
336
|
+
SYSTEM """${payload}"""
|
|
337
|
+
`;
|
|
338
|
+
|
|
339
|
+
fs.mkdirSync(path.dirname(modelfilePath), { recursive: true });
|
|
340
|
+
fs.writeFileSync(modelfilePath, modelfileContent);
|
|
341
|
+
|
|
342
|
+
// Create the nlos model variant
|
|
343
|
+
try {
|
|
344
|
+
execSync(`ollama create ${nlosModelName} -f "${modelfilePath}"`, {
|
|
345
|
+
stdio: 'pipe',
|
|
346
|
+
cwd: PACKAGE_ROOT
|
|
347
|
+
});
|
|
348
|
+
log('green', `Created model: ${nlosModelName}`);
|
|
349
|
+
} catch (error) {
|
|
350
|
+
log('red', `Failed to create model: ${error.message}`);
|
|
351
|
+
log('yellow', 'Falling back to manual system prompt...');
|
|
352
|
+
|
|
353
|
+
// Fallback: just run the base model and tell user to paste
|
|
354
|
+
console.log('\nCould not create kernel model. Run manually:');
|
|
355
|
+
console.log(` ollama run ${selectedModel}`);
|
|
356
|
+
console.log(' Then paste the kernel from: portable/kernel-payload.md\n');
|
|
357
|
+
process.exit(1);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
log('green', `Launching interactive session...`);
|
|
302
361
|
log('cyan', '─'.repeat(60));
|
|
303
362
|
console.log();
|
|
304
363
|
|
|
305
|
-
// Spawn interactive ollama session with
|
|
306
|
-
const child = spawn('ollama', ['run',
|
|
364
|
+
// Spawn interactive ollama session with the nlos model
|
|
365
|
+
const child = spawn('ollama', ['run', nlosModelName], {
|
|
307
366
|
stdio: 'inherit',
|
|
308
367
|
});
|
|
309
368
|
|