staffos 0.1.3 → 0.1.4
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/README.md +8 -0
- package/bin/cli.js +179 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -25,6 +25,14 @@ 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
|
+
Este comando escaneará la base de código de tu proyecto local y generará una tabla detallada con los cálculos en tiempo real.
|
|
35
|
+
|
|
28
36
|
---
|
|
29
37
|
|
|
30
38
|
## 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
|
-
//
|
|
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
|
-
|
|
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,165 @@ 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(
|
|
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
|
|
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
|
+
// Estimate token savings for the current workspace
|
|
125
|
+
function runEstimator() {
|
|
126
|
+
console.log(`${colors.cyan}${colors.bold}=== StaffOS Token & Cost Estimator ===${colors.reset}\n`);
|
|
127
|
+
console.log(`Scanning workspace at: ${colors.gray}${targetDir}${colors.reset}`);
|
|
128
|
+
|
|
129
|
+
const files = getFilesRecursive(targetDir);
|
|
130
|
+
let totalCharacters = 0;
|
|
131
|
+
let textFilesCount = 0;
|
|
132
|
+
|
|
133
|
+
for (const file of files) {
|
|
134
|
+
try {
|
|
135
|
+
const content = fs.readFileSync(file, 'utf8');
|
|
136
|
+
totalCharacters += content.length;
|
|
137
|
+
textFilesCount++;
|
|
138
|
+
} catch (e) {
|
|
139
|
+
// Skip binary or unreadable files
|
|
140
|
+
}
|
|
66
141
|
}
|
|
142
|
+
|
|
143
|
+
// Token math modeling
|
|
144
|
+
// 1 token approx 3.8 characters in code
|
|
145
|
+
const codebaseTokens = Math.round(totalCharacters / 3.8);
|
|
146
|
+
|
|
147
|
+
// Scenario A: Traditional Agent (Unconstrained)
|
|
148
|
+
// - Performs a full repository scan to start.
|
|
149
|
+
// - Runs 4 iterative repair cycles, re-reading context.
|
|
150
|
+
// - Rewrites complete files (avg. 1,500 tokens output) on each cycle.
|
|
151
|
+
const tradInputTokens = codebaseTokens * 4;
|
|
152
|
+
const tradOutputTokens = 1500 * 4;
|
|
153
|
+
|
|
154
|
+
// Pricing model: Claude 3.5 Sonnet / Gemini 1.5 Pro standard rates
|
|
155
|
+
// Input: $3.00 / 1M tokens. Output: $15.00 / 1M tokens.
|
|
156
|
+
const tradInputCost = (tradInputTokens / 1_000_000) * 3.00;
|
|
157
|
+
const tradOutputCost = (tradOutputTokens / 1_000_000) * 15.00;
|
|
158
|
+
const tradTotalCost = tradInputCost + tradOutputCost;
|
|
159
|
+
|
|
160
|
+
// Scenario B: StaffOS Agent
|
|
161
|
+
// - Reads AI_CONTEXT.md + AGENTS.md + SKILL.md.
|
|
162
|
+
// - If they exist, read actual length. If not, default to 1,500 tokens baseline.
|
|
163
|
+
let staffOsContextLength = 0;
|
|
164
|
+
const docsToCheck = [
|
|
165
|
+
path.join(targetDir, 'AGENTS.md'),
|
|
166
|
+
path.join(targetDir, 'skills/staffos/SKILL.md'),
|
|
167
|
+
path.join(targetDir, 'docs/AI_CONTEXT.md'),
|
|
168
|
+
path.join(targetDir, 'docs/HANDOFF.md')
|
|
169
|
+
];
|
|
170
|
+
|
|
171
|
+
let foundDocs = false;
|
|
172
|
+
for (const doc of docsToCheck) {
|
|
173
|
+
if (fs.existsSync(doc)) {
|
|
174
|
+
try {
|
|
175
|
+
staffOsContextLength += fs.readFileSync(doc, 'utf8').length;
|
|
176
|
+
foundDocs = true;
|
|
177
|
+
} catch (e) {}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const staffOsInputTokens = foundDocs
|
|
182
|
+
? Math.round(staffOsContextLength / 3.8)
|
|
183
|
+
: 1500; // default baseline
|
|
184
|
+
|
|
185
|
+
// StaffOS restricts changes to minimal patches (avg. 100 tokens output per task) over 1 cycle
|
|
186
|
+
const staffOsOutputTokens = 100;
|
|
187
|
+
|
|
188
|
+
const staffOsInputCost = (staffOsInputTokens / 1_000_000) * 3.00;
|
|
189
|
+
const staffOsOutputCost = (staffOsOutputTokens / 1_000_000) * 15.00;
|
|
190
|
+
const staffOsTotalCost = staffOsInputCost + staffOsOutputCost;
|
|
191
|
+
|
|
192
|
+
// Savings
|
|
193
|
+
const savingsPercent = tradTotalCost > 0
|
|
194
|
+
? Math.min(99.9, Math.max(0, ((tradTotalCost - staffOsTotalCost) / tradTotalCost) * 100))
|
|
195
|
+
: 0;
|
|
196
|
+
|
|
197
|
+
// Render Table
|
|
198
|
+
console.log(`\nFound ${colors.bold}${textFilesCount}${colors.reset} readable files in codebase (${colors.bold}${Math.round(totalCharacters / 1024)} KB${colors.reset}).`);
|
|
199
|
+
console.log('--------------------------------------------------------------------------------');
|
|
200
|
+
console.log(`${colors.bold}${'Métrica / Escenario'.padEnd(28)} | ${'Agente Tradicional'.padEnd(20)} | ${'Con StaffOS'.padEnd(14)} | ${'Ahorro (%)'.padEnd(10)}${colors.reset}`);
|
|
201
|
+
console.log('--------------------------------------------------------------------------------');
|
|
202
|
+
|
|
203
|
+
console.log(`${'Tokens de Entrada (Lectura)'.padEnd(28)} | ${tradInputTokens.toLocaleString().padEnd(20)} | ${staffOsInputTokens.toLocaleString().padEnd(14)} | ${colors.green}${savingsPercent.toFixed(1)}%${colors.reset}`);
|
|
204
|
+
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}`);
|
|
205
|
+
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}`);
|
|
206
|
+
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}`);
|
|
207
|
+
|
|
208
|
+
console.log('--------------------------------------------------------------------------------');
|
|
209
|
+
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}`);
|
|
210
|
+
console.log('--------------------------------------------------------------------------------');
|
|
211
|
+
|
|
212
|
+
console.log(`\n${colors.green}${colors.bold}🎉 Ahorro Estimado: ~${savingsPercent.toFixed(0)}% en costos de API por tarea.${colors.reset}`);
|
|
213
|
+
console.log(`${colors.gray}* Calculado asumiendo $3.00/1M tokens entrada y $15.00/1M tokens salida (tipo Claude 3.5 Sonnet / Gemini 1.5 Pro).${colors.reset}\n`);
|
|
67
214
|
}
|
|
68
215
|
|
|
69
|
-
|
|
216
|
+
// Help command
|
|
217
|
+
function runHelp() {
|
|
218
|
+
console.log(`\n${colors.cyan}${colors.bold}StaffOS CLI v${currentVersion}${colors.reset}`);
|
|
219
|
+
console.log('Uso:');
|
|
220
|
+
console.log(` ${colors.bold}npx staffos${colors.reset} - Instala e inicializa StaffOS en el proyecto actual.`);
|
|
221
|
+
console.log(` ${colors.bold}npx staffos estimate${colors.reset} - Escanea el proyecto actual y calcula el ahorro estimado de tokens.`);
|
|
222
|
+
console.log(` ${colors.bold}npx staffos help${colors.reset} - Muestra este menú de ayuda.`);
|
|
223
|
+
console.log();
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
async function runInstaller() {
|
|
227
|
+
console.log(`Installing StaffOS v${currentVersion} in:`, targetDir);
|
|
70
228
|
try {
|
|
71
229
|
for (const item of itemsToCopy) {
|
|
72
230
|
const srcPath = path.join(packageRoot, item.src);
|
|
@@ -75,8 +233,9 @@ async function main() {
|
|
|
75
233
|
copyRecursiveSync(srcPath, destPath);
|
|
76
234
|
}
|
|
77
235
|
}
|
|
78
|
-
console.log(
|
|
79
|
-
console.log(
|
|
236
|
+
console.log(`\n${colors.green}${colors.bold}StaffOS instalado con éxito! 🎉${colors.reset}`);
|
|
237
|
+
console.log(`Dile a tu Agente de IA que lea ${colors.bold}AGENTS.md${colors.reset} para comenzar.`);
|
|
238
|
+
console.log(`\n👉 Puedes calcular el ahorro de tokens de este proyecto ejecutando: ${colors.cyan}npx staffos estimate${colors.reset}`);
|
|
80
239
|
|
|
81
240
|
await checkForUpdates();
|
|
82
241
|
} catch (error) {
|
|
@@ -85,4 +244,14 @@ async function main() {
|
|
|
85
244
|
}
|
|
86
245
|
}
|
|
87
246
|
|
|
88
|
-
|
|
247
|
+
// Main router
|
|
248
|
+
const args = process.argv.slice(2);
|
|
249
|
+
const command = args[0];
|
|
250
|
+
|
|
251
|
+
if (command === 'estimate' || command === 'stats' || command === 'calc') {
|
|
252
|
+
runEstimator();
|
|
253
|
+
} else if (command === 'help' || command === '--help' || command === '-h') {
|
|
254
|
+
runHelp();
|
|
255
|
+
} else {
|
|
256
|
+
runInstaller();
|
|
257
|
+
}
|