tjl8787/mycodex-skills / skills/tgtool
tgtool
VerifiedUse when the user wants the agent to choose, combine, and actively use the best available local skills for a task.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 36.6 KB |
| agents/openai.yaml | config | 294 B |
| scripts/build_skills_index.js | script | 2.5 KB |
| scripts/context_guard.jsexecutable | script | 3.4 KB |
| skills-index.json | config | 18.7 KB |
scripts/context_guard.js
View on GitHub#!/usr/bin/env node
'use strict';
const fs = require('fs');
const path = require('path');
function parseArgs(argv) {
const args = {};
for (let i = 2; i < argv.length; i++) {
const a = argv[i];
if (!a.startsWith('--')) continue;
const [k, vInline] = a.split('=');
const key = k.slice(2);
if (vInline !== undefined) {
args[key] = vInline;
} else {
const next = argv[i + 1];
if (!next || next.startsWith('--')) {
args[key] = 'true';
} else {
args[key] = next;
i++;
}
}
}
return args;
}
function readText(args) {
let txt = '';
if (args['input-file']) txt += fs.readFileSync(args['input-file'], 'utf8');
if (args['input-text']) txt += args['input-text'];
if (!txt && !process.stdin.isTTY) {
try { txt += fs.readFileSync(0, 'utf8'); } catch (_) {}
}
return txt;
}
function estimateTokens(text) {
let ascii = 0;
let nonAscii = 0;
for (const ch of text) {
if (ch.charCodeAt(0) <= 127) ascii++;
else nonAscii++;
}
const weightedChars = ascii + nonAscii * 1.7;
return Math.ceil(weightedChars / 4);
}
function loadState(stateFile) {
if (!fs.existsSync(stateFile)) return { total_estimated_tokens: 0, turns: 0, updated_at: null };
try {
return JSON.parse(fs.readFileSync(stateFile, 'utf8'));
} catch {
return { total_estimated_tokens: 0, turns: 0, updated_at: null };
}
}
function saveState(stateFile, state) {
fs.mkdirSync(path.dirname(stateFile), { recursive: true });
fs.writeFileSync(stateFile, JSON.stringify(state, null, 2));
}
function level(pct) {
if (pct > 92) return 'critical';
if (pct > 85) return 'preview';
if (pct > 70) return 'warn';
return 'ok';
}
function recommendation(lv) {
if (lv === 'critical') return 'Run final handoff (summary+compact) and start a new session now.';
if (lv === 'preview') return 'Start Phase A preview handoff.';
if (lv === 'warn') return 'Prepare handoff; avoid adding large context.';
return 'Continue normally.';
}
(function main() {
const args = parseArgs(process.argv);
const cwd = process.cwd();
const stateFile = args['state-file'] || path.join(cwd, '.tgtool', 'context_guard_state.json');
const contextLimit = Number(args['context-limit'] || 200000);
const fixedOverhead = Number(args['fixed-overhead'] || 2500);
if (args.reset === 'true') {
const resetState = { total_estimated_tokens: 0, turns: 0, updated_at: new Date().toISOString() };
saveState(stateFile, resetState);
console.log(JSON.stringify({ status: 'reset', state_file: stateFile }, null, 2));
return;
}
const text = readText(args);
const current = estimateTokens(text);
const state = loadState(stateFile);
state.total_estimated_tokens += current;
state.turns += 1;
state.updated_at = new Date().toISOString();
saveState(stateFile, state);
const total = state.total_estimated_tokens + fixedOverhead;
const pct = (total / contextLimit) * 100;
const lv = level(pct);
const out = {
status: 'ok',
state_file: stateFile,
turn_estimated_tokens: current,
rolling_estimated_tokens: state.total_estimated_tokens,
fixed_overhead_tokens: fixedOverhead,
estimated_context_tokens: total,
context_limit_tokens: contextLimit,
estimated_context_pct: Number(pct.toFixed(2)),
threshold_level: lv,
recommendation: recommendation(lv)
};
console.log(JSON.stringify(out, null, 2));
})();
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis. | Stars: 472k | Updated | Claude CodeCodex | Verified | Install |
| diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness. | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |