fix(framework): add real-time pressure to ffs command
- Add --tokens=<current>/<budget> parameter to framework-stats.js - Calculate and display real-time context pressure when tokens provided - Show data source (real-time/cached/history/stats) in output - Display warning when showing cached data - Include token budget and usage percentage in output Fixes issue where ffs showed stale 0% pressure from cached session state 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
d6abefefdb
commit
1c4b1dfda2
1 changed files with 53 additions and 8 deletions
|
|
@ -140,6 +140,21 @@ async function getAuditLogStats() {
|
|||
|
||||
async function main() {
|
||||
try {
|
||||
// Parse command-line arguments
|
||||
const args = process.argv.slice(2);
|
||||
const tokensArg = args.find(arg => arg.startsWith('--tokens='));
|
||||
let currentTokens = null;
|
||||
let tokenBudget = null;
|
||||
|
||||
if (tokensArg) {
|
||||
const tokensValue = tokensArg.split('=')[1];
|
||||
const [current, budget] = tokensValue.split('/').map(t => parseInt(t.trim()));
|
||||
if (!isNaN(current) && !isNaN(budget)) {
|
||||
currentTokens = current;
|
||||
tokenBudget = budget;
|
||||
}
|
||||
}
|
||||
|
||||
// Connect to MongoDB
|
||||
await mongoose.connect('mongodb://localhost:27017/tractatus_dev', {
|
||||
serverSelectionTimeoutMS: 2000
|
||||
|
|
@ -168,6 +183,12 @@ async function main() {
|
|||
? pressureHistory[pressureHistory.length - 1]
|
||||
: null;
|
||||
|
||||
// Calculate real-time pressure if tokens provided
|
||||
let realTimePressure = null;
|
||||
if (currentTokens !== null && tokenBudget !== null) {
|
||||
realTimePressure = await ContextPressureMonitor.analyzePressure(currentTokens, tokenBudget, 1);
|
||||
}
|
||||
|
||||
// Build report
|
||||
const report = {
|
||||
timestamp: new Date().toISOString(),
|
||||
|
|
@ -187,22 +208,33 @@ async function main() {
|
|||
nextCheckpoint: tokenCheckpoints.checkpoints.find(c => !c.reached)
|
||||
} : null,
|
||||
|
||||
contextPressure: sessionStats?.pressureMonitoring ? {
|
||||
contextPressure: realTimePressure ? {
|
||||
level: realTimePressure.pressureLevel?.name || 'NORMAL',
|
||||
score: Math.round(realTimePressure.overallScore * 10) / 10,
|
||||
tokenCount: currentTokens,
|
||||
tokenBudget: tokenBudget,
|
||||
source: 'real-time',
|
||||
timestamp: new Date().toISOString(),
|
||||
metrics: realTimePressure.metrics
|
||||
} : (sessionStats?.pressureMonitoring ? {
|
||||
level: sessionStats.pressureMonitoring.last_level || 'UNKNOWN',
|
||||
score: sessionStats.pressureMonitoring.last_score || 0,
|
||||
lastChecked: sessionStats.pressureMonitoring.timestamp,
|
||||
messageNumber: sessionStats.pressureMonitoring.message,
|
||||
tokenCount: sessionStats.pressureMonitoring.tokens
|
||||
tokenCount: sessionStats.pressureMonitoring.tokens,
|
||||
source: 'cached'
|
||||
} : (latestPressure ? {
|
||||
level: latestPressure.pressureLevel?.name || 'UNKNOWN',
|
||||
score: latestPressure.overallScore,
|
||||
timestamp: latestPressure.timestamp,
|
||||
metrics: latestPressure.metrics
|
||||
metrics: latestPressure.metrics,
|
||||
source: 'history'
|
||||
} : (monitorStats ? {
|
||||
level: 'UNKNOWN',
|
||||
score: 0,
|
||||
stats: monitorStats
|
||||
} : null)),
|
||||
stats: monitorStats,
|
||||
source: 'stats'
|
||||
} : null))),
|
||||
|
||||
autoCompacts: sessionStats?.autoCompactEvents ? {
|
||||
total: sessionStats.autoCompactEvents.length,
|
||||
|
|
@ -280,13 +312,26 @@ async function main() {
|
|||
console.log('⚠️ CONTEXT PRESSURE');
|
||||
console.log(` Level: ${report.contextPressure.level}`);
|
||||
console.log(` Overall Score: ${report.contextPressure.score}%`);
|
||||
console.log(` Data Source: ${report.contextPressure.source || 'unknown'}`);
|
||||
|
||||
if (report.contextPressure.source === 'cached') {
|
||||
console.log(' ⚠️ WARNING: Showing cached data. Use --tokens=<current>/<budget> for real-time.');
|
||||
}
|
||||
|
||||
if (report.contextPressure.tokenCount) {
|
||||
console.log(` Token Count: ${report.contextPressure.tokenCount?.toLocaleString()}`);
|
||||
}
|
||||
if (report.contextPressure.tokenBudget) {
|
||||
console.log(` Token Budget: ${report.contextPressure.tokenBudget?.toLocaleString()}`);
|
||||
const percentUsed = ((report.contextPressure.tokenCount / report.contextPressure.tokenBudget) * 100).toFixed(1);
|
||||
console.log(` Tokens Used: ${percentUsed}%`);
|
||||
}
|
||||
if (report.contextPressure.lastChecked) {
|
||||
console.log(` Last Checked: ${new Date(report.contextPressure.lastChecked).toLocaleString()}`);
|
||||
console.log(` At Message: #${report.contextPressure.messageNumber}`);
|
||||
console.log(` Token Count: ${report.contextPressure.tokenCount?.toLocaleString() || 'N/A'}`);
|
||||
}
|
||||
if (report.contextPressure.timestamp) {
|
||||
console.log(` Last Updated: ${new Date(report.contextPressure.timestamp).toLocaleString()}`);
|
||||
if (report.contextPressure.timestamp && report.contextPressure.source !== 'cached') {
|
||||
console.log(` Calculated: ${new Date(report.contextPressure.timestamp).toLocaleString()}`);
|
||||
}
|
||||
if (report.contextPressure.metrics) {
|
||||
console.log(' Metrics:');
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue