staffos 0.1.3 → 0.1.5

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 (3) hide show
  1. package/README.md +22 -0
  2. package/bin/cli.js +205 -10
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -25,6 +25,28 @@ npx staffos
25
25
 
26
26
  El instalador copiará la estructura automáticamente en tu directorio actual. Además, cuenta con un comprobador de actualizaciones asíncrono e integrado que te avisará si hay una versión superior disponible en NPM.
27
27
 
28
+ Para **analizar y estimar el ahorro exacto de tokens** y el costo proyectado de tu proyecto actual, ejecuta:
29
+
30
+ ```bash
31
+ npx staffos estimate
32
+ ```
33
+
34
+ Puedes especificar un modelo de IA en particular mediante el flag `--model` para obtener estimaciones de costos exactas basadas en las tarifas de 2026:
35
+
36
+ ```bash
37
+ npx staffos estimate --model=gemini-pro
38
+ ```
39
+
40
+ Los modelos de IA soportados son:
41
+ * `claude-sonnet` (Claude 4.8 Sonnet - predeterminado)
42
+ * `claude-opus` (Claude 4.8 Opus)
43
+ * `gemini-pro` (Gemini 3.1 Pro)
44
+ * `gemini-flash` (Gemini 3.5 Flash)
45
+ * `gpt-5.5` (GPT 5.5)
46
+ * `local` (Modelos locales de Ollama/Llama sin costo de API)
47
+
48
+ Este comando escaneará la base de código de tu proyecto local y generará una tabla detallada con los cálculos en tiempo real.
49
+
28
50
  ---
29
51
 
30
52
  ## Ahorro de Tokens e Impacto
package/bin/cli.js CHANGED
@@ -12,7 +12,17 @@ const packageJsonPath = path.join(packageRoot, 'package.json');
12
12
  const pkg = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
13
13
  const currentVersion = pkg.version;
14
14
 
15
- // Files and folders to copy to the user's local project
15
+ // ANSI Color Helpers
16
+ const colors = {
17
+ reset: '\x1b[0m',
18
+ bold: '\x1b[1m',
19
+ green: '\x1b[32m',
20
+ red: '\x1b[31m',
21
+ cyan: '\x1b[36m',
22
+ yellow: '\x1b[33m',
23
+ gray: '\x1b[90m'
24
+ };
25
+
16
26
  const itemsToCopy = [
17
27
  { src: 'AGENTS.md', dest: 'AGENTS.md' },
18
28
  { src: 'skills/staffos/SKILL.md', dest: 'skills/staffos/SKILL.md' },
@@ -24,8 +34,7 @@ const itemsToCopy = [
24
34
 
25
35
  const targetDir = process.cwd();
26
36
 
27
- console.log(`Installing StaffOS v${currentVersion} in:`, targetDir);
28
-
37
+ // Helper to recursively copy directories/files
29
38
  function copyRecursiveSync(src, dest) {
30
39
  const exists = fs.existsSync(src);
31
40
  const stats = exists && fs.statSync(src);
@@ -47,6 +56,7 @@ function copyRecursiveSync(src, dest) {
47
56
  }
48
57
  }
49
58
 
59
+ // Asynchronous update checker
50
60
  async function checkForUpdates() {
51
61
  try {
52
62
  const res = await fetch('https://registry.npmjs.org/staffos/latest', {
@@ -56,17 +66,191 @@ async function checkForUpdates() {
56
66
  const data = await res.json();
57
67
  if (data.version && data.version !== currentVersion) {
58
68
  console.log('\n==================================================');
59
- console.log(`📢 A new version of StaffOS is available: ${data.version} (current: ${currentVersion})`);
60
- console.log("👉 Run 'npx staffos@latest' to update.");
69
+ console.log(`📢 A new version of StaffOS is available: ${colors.bold}${data.version}${colors.reset} (current: ${currentVersion})`);
70
+ console.log(`👉 Run '${colors.cyan}npx staffos@latest${colors.reset}' to update.`);
61
71
  console.log('==================================================\n');
62
72
  }
63
73
  }
64
74
  } catch (error) {
65
- // Fail silently so it doesn't break the offline/slow network installations
75
+ // Fail silently so it doesn't break offline use
76
+ }
77
+ }
78
+
79
+ // Recurse directories to find text files
80
+ function getFilesRecursive(dir, fileList = []) {
81
+ if (!fs.existsSync(dir)) return fileList;
82
+ const files = fs.readdirSync(dir);
83
+ for (const file of files) {
84
+ const filePath = path.join(dir, file);
85
+ let stat;
86
+ try {
87
+ stat = fs.statSync(filePath);
88
+ } catch (e) {
89
+ continue;
90
+ }
91
+
92
+ if (stat.isDirectory()) {
93
+ // Exclude build/vcs/deps folders
94
+ if (
95
+ file === 'node_modules' ||
96
+ file === '.git' ||
97
+ file === '.next' ||
98
+ file === 'dist' ||
99
+ file === 'build' ||
100
+ file === '.opencode' ||
101
+ file === 'out' ||
102
+ file === 'coverage' ||
103
+ file === '.gemini'
104
+ ) {
105
+ continue;
106
+ }
107
+ getFilesRecursive(filePath, fileList);
108
+ } else {
109
+ // Exclude binaries, images, locks
110
+ const ext = path.extname(file).toLowerCase();
111
+ const ignoredExtensions = [
112
+ '.png', '.jpg', '.jpeg', '.gif', '.ico', '.svg', '.mp4', '.mp3', '.pdf', '.zip', '.tar', '.gz',
113
+ '.lock', '.package-lock.json', '.pnpm-lock.yaml', '.yarn.lock', '.woff', '.woff2', '.ttf', '.eot'
114
+ ];
115
+ if (ignoredExtensions.includes(ext) || file.startsWith('.')) {
116
+ continue;
117
+ }
118
+ fileList.push(filePath);
119
+ }
120
+ }
121
+ return fileList;
122
+ }
123
+
124
+ // Model Pricing Registry (2026 Standard Rates per 1M tokens)
125
+ const modelsPricing = {
126
+ 'claude-sonnet': { name: 'Claude 4.8 Sonnet', input: 3.00, output: 15.00 },
127
+ 'claude-opus': { name: 'Claude 4.8 Opus', input: 15.00, output: 75.00 },
128
+ 'gemini-pro': { name: 'Gemini 3.1 Pro', input: 2.00, output: 12.00 },
129
+ 'gemini-flash': { name: 'Gemini 3.5 Flash', input: 0.075, output: 0.30 },
130
+ 'gpt-5.5': { name: 'GPT 5.5', input: 5.00, output: 30.00 },
131
+ 'local': { name: 'Modelos Locales (Ollama/DeepSeek)', input: 0.00, output: 0.00 }
132
+ };
133
+
134
+ function getModelFromArgs() {
135
+ const modelArg = process.argv.find(arg => arg.startsWith('--model='));
136
+ if (modelArg) {
137
+ return modelArg.split('=')[1].toLowerCase();
138
+ }
139
+ const modelIndex = process.argv.indexOf('-m');
140
+ if (modelIndex !== -1 && process.argv[modelIndex + 1]) {
141
+ return process.argv[modelIndex + 1].toLowerCase();
142
+ }
143
+ return 'claude-sonnet'; // default
144
+ }
145
+
146
+ // Estimate token savings for the current workspace
147
+ function runEstimator() {
148
+ const modelKey = getModelFromArgs();
149
+ const pricing = modelsPricing[modelKey] || modelsPricing['claude-sonnet'];
150
+
151
+ console.log(`${colors.cyan}${colors.bold}=== StaffOS Token & Cost Estimator ===${colors.reset}\n`);
152
+ console.log(`Scanning workspace at: ${colors.gray}${targetDir}${colors.reset}`);
153
+ console.log(`Target AI Model: ${colors.yellow}${colors.bold}${pricing.name}${colors.reset} (Input: $${pricing.input}/1M, Output: $${pricing.output}/1M)`);
154
+
155
+ const files = getFilesRecursive(targetDir);
156
+ let totalCharacters = 0;
157
+ let textFilesCount = 0;
158
+
159
+ for (const file of files) {
160
+ try {
161
+ const content = fs.readFileSync(file, 'utf8');
162
+ totalCharacters += content.length;
163
+ textFilesCount++;
164
+ } catch (e) {
165
+ // Skip binary or unreadable files
166
+ }
167
+ }
168
+
169
+ // Token math modeling
170
+ // 1 token approx 3.8 characters in code
171
+ const codebaseTokens = Math.round(totalCharacters / 3.8);
172
+
173
+ // Scenario A: Traditional Agent (Unconstrained)
174
+ const tradInputTokens = codebaseTokens * 4;
175
+ const tradOutputTokens = 1500 * 4;
176
+
177
+ const tradInputCost = (tradInputTokens / 1_000_000) * pricing.input;
178
+ const tradOutputCost = (tradOutputTokens / 1_000_000) * pricing.output;
179
+ const tradTotalCost = tradInputCost + tradOutputCost;
180
+
181
+ // Scenario B: StaffOS Agent
182
+ let staffOsContextLength = 0;
183
+ const docsToCheck = [
184
+ path.join(targetDir, 'AGENTS.md'),
185
+ path.join(targetDir, 'skills/staffos/SKILL.md'),
186
+ path.join(targetDir, 'docs/AI_CONTEXT.md'),
187
+ path.join(targetDir, 'docs/HANDOFF.md')
188
+ ];
189
+
190
+ let foundDocs = false;
191
+ for (const doc of docsToCheck) {
192
+ if (fs.existsSync(doc)) {
193
+ try {
194
+ staffOsContextLength += fs.readFileSync(doc, 'utf8').length;
195
+ foundDocs = true;
196
+ } catch (e) {}
197
+ }
198
+ }
199
+
200
+ const staffOsInputTokens = foundDocs
201
+ ? Math.round(staffOsContextLength / 3.8)
202
+ : 1500; // default baseline
203
+
204
+ const staffOsOutputTokens = 100;
205
+
206
+ const staffOsInputCost = (staffOsInputTokens / 1_000_000) * pricing.input;
207
+ const staffOsOutputCost = (staffOsOutputTokens / 1_000_000) * pricing.output;
208
+ const staffOsTotalCost = staffOsInputCost + staffOsOutputCost;
209
+
210
+ // Savings
211
+ const savingsPercent = tradTotalCost > 0
212
+ ? Math.min(99.9, Math.max(0, ((tradTotalCost - staffOsTotalCost) / tradTotalCost) * 100))
213
+ : 0;
214
+
215
+ // Render Table
216
+ console.log(`\nFound ${colors.bold}${textFilesCount}${colors.reset} readable files in codebase (${colors.bold}${Math.round(totalCharacters / 1024)} KB${colors.reset}).`);
217
+ console.log('--------------------------------------------------------------------------------');
218
+ console.log(`${colors.bold}${'Métrica / Escenario'.padEnd(28)} | ${'Agente Tradicional'.padEnd(20)} | ${'Con StaffOS'.padEnd(14)} | ${'Ahorro (%)'.padEnd(10)}${colors.reset}`);
219
+ console.log('--------------------------------------------------------------------------------');
220
+
221
+ console.log(`${'Tokens de Entrada (Lectura)'.padEnd(28)} | ${tradInputTokens.toLocaleString().padEnd(20)} | ${staffOsInputTokens.toLocaleString().padEnd(14)} | ${colors.green}${savingsPercent.toFixed(1)}%${colors.reset}`);
222
+ console.log(`${'Tokens de Salida (Escritura)'.padEnd(28)} | ${tradOutputTokens.toLocaleString().padEnd(20)} | ${staffOsOutputTokens.toLocaleString().padEnd(14)} | ${colors.green}${(((tradOutputTokens - staffOsOutputTokens)/tradOutputTokens)*100).toFixed(1)}%${colors.reset}`);
223
+ console.log(`${'Costo Estimado de Entrada'.padEnd(28)} | $${tradInputCost.toFixed(4).padEnd(19)} | $${staffOsInputCost.toFixed(4).padEnd(13)} | ${colors.green}${savingsPercent.toFixed(1)}%${colors.reset}`);
224
+ console.log(`${'Costo Estimado de Salida'.padEnd(28)} | $${tradOutputCost.toFixed(4).padEnd(19)} | $${staffOsOutputCost.toFixed(4).padEnd(13)} | ${colors.green}${(((tradOutputCost - staffOsOutputCost)/tradOutputCost)*100).toFixed(1)}%${colors.reset}`);
225
+
226
+ console.log('--------------------------------------------------------------------------------');
227
+ console.log(`${colors.bold}${'COSTO TOTAL ESTIMADO / TAREA'.padEnd(28)} | $${tradTotalCost.toFixed(4).padEnd(19)} | $${staffOsTotalCost.toFixed(4).padEnd(13)} | ${colors.green}${savingsPercent.toFixed(1)}%${colors.reset}`);
228
+ console.log('--------------------------------------------------------------------------------');
229
+
230
+ if (pricing.input === 0) {
231
+ console.log(`\n${colors.green}${colors.bold}🎉 Ahorro Estimado: ~${savingsPercent.toFixed(0)}% en tokens por tarea (ejecución local gratuita).${colors.reset}\n`);
232
+ } else {
233
+ console.log(`\n${colors.green}${colors.bold}🎉 Ahorro Estimado: ~${savingsPercent.toFixed(0)}% en costos de API por tarea.${colors.reset}\n`);
66
234
  }
67
235
  }
68
236
 
69
- async function main() {
237
+ // Help command
238
+ function runHelp() {
239
+ console.log(`\n${colors.cyan}${colors.bold}StaffOS CLI v${currentVersion}${colors.reset}`);
240
+ console.log('Uso:');
241
+ console.log(` ${colors.bold}npx staffos${colors.reset} - Instala e inicializa StaffOS en el proyecto actual.`);
242
+ console.log(` ${colors.bold}npx staffos estimate${colors.reset} - Escanea el proyecto y calcula los ahorros usando el modelo predeterminado.`);
243
+ console.log(` ${colors.bold}npx staffos estimate --model=<tipo>${colors.reset} - Estima usando un modelo de IA específico.`);
244
+ console.log(` ${colors.bold}npx staffos help${colors.reset} - Muestra este menú de ayuda.`);
245
+ console.log('\nModelos de IA soportados para estimación (`--model=`):');
246
+ Object.keys(modelsPricing).forEach(key => {
247
+ console.log(` - ${colors.yellow}${key.padEnd(15)}${colors.reset} : ${modelsPricing[key].name}`);
248
+ });
249
+ console.log();
250
+ }
251
+
252
+ async function runInstaller() {
253
+ console.log(`Installing StaffOS v${currentVersion} in:`, targetDir);
70
254
  try {
71
255
  for (const item of itemsToCopy) {
72
256
  const srcPath = path.join(packageRoot, item.src);
@@ -75,8 +259,9 @@ async function main() {
75
259
  copyRecursiveSync(srcPath, destPath);
76
260
  }
77
261
  }
78
- console.log('\nStaffOS installed successfully! 🎉');
79
- console.log('Ask your AI Agent to read AGENTS.md to begin.');
262
+ console.log(`\n${colors.green}${colors.bold}StaffOS instalado con éxito! 🎉${colors.reset}`);
263
+ console.log(`Dile a tu Agente de IA que lea ${colors.bold}AGENTS.md${colors.reset} para comenzar.`);
264
+ console.log(`\n👉 Puedes calcular el ahorro de tokens de este proyecto ejecutando: ${colors.cyan}npx staffos estimate${colors.reset}`);
80
265
 
81
266
  await checkForUpdates();
82
267
  } catch (error) {
@@ -85,4 +270,14 @@ async function main() {
85
270
  }
86
271
  }
87
272
 
88
- main();
273
+ // Main router
274
+ const args = process.argv.slice(2);
275
+ const command = args[0];
276
+
277
+ if (command === 'estimate' || command === 'stats' || command === 'calc') {
278
+ runEstimator();
279
+ } else if (command === 'help' || command === '--help' || command === '-h') {
280
+ runHelp();
281
+ } else {
282
+ runInstaller();
283
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "staffos",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "StaffOS: Staff Engineer Operating System for AI coding agents",
5
5
  "type": "module",
6
6
  "bin": "bin/cli.js",