junecoder 1.0.16 → 1.0.18

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/package.json +1 -1
  2. package/session.mjs +0 -1
  3. package/tui.mjs +6 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "junecoder",
3
- "version": "1.0.16",
3
+ "version": "1.0.18",
4
4
  "description": "Zero Npm Dependencies Agent Framework",
5
5
  "main": "agent.mjs",
6
6
  "type": "module",
package/session.mjs CHANGED
@@ -33,7 +33,6 @@ export function saveSession(agent, displayLines) {
33
33
  history: agent.history,
34
34
  displayLines: displayLines || [],
35
35
  planMode: agent.planMode,
36
- tasks: agent.tasks,
37
36
  goal: agent.goal,
38
37
  savedAt: Date.now(),
39
38
  };
package/tui.mjs CHANGED
@@ -106,7 +106,7 @@ export async function startTUI(agent, opts = {}) {
106
106
  const state = {
107
107
  lines: [], streaming: "", input: [], cursor: 0, history: [], historyIndex: -1,
108
108
  scroll: 0, processing: false, controller: null, permission: null, permissionPreview: [],
109
- question: null, tasks: agent.tasks ?? [], tokens: { prompt: 0, completion: 0 },
109
+ question: null, tasks: agent.tasks ?? [], tokens: { prompt: 0, completion: 0, cacheHit: 0, cacheMiss: 0 },
110
110
  ctxCache: { len: -1, tokens: 0 }, reasoning: "", toolStreams: {},
111
111
  subOutput: "", currentSub: null, currentTool: null, processingStarted: 0, status: "Ready",
112
112
  };
@@ -245,6 +245,7 @@ export async function startTUI(agent, opts = {}) {
245
245
  const taskHint = state.tasks.length > 0 ? " \u2502 \u2713" + state.tasks.filter(t => t.status === "done").length + "/" + state.tasks.length : "";
246
246
  const tk = state.tokens, fmtK = n => n >= 10000 ? Math.round(n/1000) + "k" : n >= 1000 ? (n/1000).toFixed(1) + "k" : String(n);
247
247
  const tokenHint = tk.prompt > 0 ? " \u2502 \u2191" + fmtK(tk.prompt) + " \u2193" + fmtK(tk.completion) : "";
248
+ const cacheHint = tk.cacheHit > 0 ? " \u2502 Hit " + fmtK(tk.cacheHit) : "";
248
249
  const elapsed = state.processing ? " " + Math.floor((Date.now() - state.processingStarted)/1000) + "s" : "";
249
250
  const toolHint = state.currentTool ? " " + state.currentTool + "\u2026" : "";
250
251
  const statusText = state.processing ? state.status + toolHint + elapsed : state.status;
@@ -252,7 +253,7 @@ export async function startTUI(agent, opts = {}) {
252
253
  const ctxThreshold = agent.config?.agent?.compactThreshold ?? 750_000;
253
254
  const ctxPct = Math.round((state.ctxCache.tokens / ctxThreshold) * 100);
254
255
  const ctxHint = ctxPct > 0 ? (ctxPct >= 80 ? " \u2502 " + C.warn + "ctx " + ctxPct + "%" + ansi.reset + ansi.dim : " \u2502 ctx " + ctxPct + "%") : "";
255
- let statusLine = statusText + taskHint + tokenHint + ctxHint + scrollHint + " \u2502 Enter:send \u2502 /:cmds \u2502 Ctrl+C:quit";
256
+ let statusLine = statusText + taskHint + tokenHint + cacheHint + ctxHint + scrollHint + " \u2502 Enter:send \u2502 /:cmds \u2502 Ctrl+C:quit";
256
257
  const autoBanner = agent.autoApprove ? C.warn + "AUTO" + ansi.reset + ansi.dim + "\u2502" : "";
257
258
  const planBanner = agent.planMode ? C.tool + "PLAN" + ansi.reset + ansi.dim + "\u2502" : "";
258
259
  statusLine = sliceByWidth(statusLine, Math.max(10, W));
@@ -450,7 +451,7 @@ export async function startTUI(agent, opts = {}) {
450
451
  onPermissionRequest: (tool, args) => askPermission(tool.name || tool, args),
451
452
  onQuestion: async (q) => askQuestion(q),
452
453
  onCompress: () => pushLine(" [context] Compressed (history truncated)", C.warn),
453
- onUsage: u => { state.tokens.prompt += u.prompt_tokens ?? 0; state.tokens.completion += u.completion_tokens ?? 0; },
454
+ onUsage: u => { state.tokens.prompt += u.prompt_tokens ?? 0; state.tokens.completion += u.completion_tokens ?? 0; state.tokens.cacheHit += u.prompt_cache_hit_tokens ?? u.prompt_tokens_details?.cached_tokens ?? 0; state.tokens.cacheMiss += u.prompt_cache_miss_tokens ?? 0; },
454
455
  onTaskUpdate: items => { state.tasks = items || []; const done = items.filter(i => i.status === "done").length; const cur = items.find(i => i.status === "in_progress"); pushLine(" [task] " + done + "/" + items.length + (cur ? " \u25b6 " + cur.title : ""), C.dim); render(); },
455
456
  onTurnEnd: (() => { let n = 0; return () => { if (++n % 5 === 0) { try { saveSession(agent, state.lines); } catch {} } }; })(),
456
457
  };
@@ -485,8 +486,8 @@ export async function startTUI(agent, opts = {}) {
485
486
  break;
486
487
  }
487
488
  case "session": { const slots = listSlots(agent.cwd); pushLine("Sessions:", C.tool); if (slots.length === 0) pushLine(" (none)", C.dim); else for (const s of slots) pushLine(" " + s.label, C.dim); break; }
488
- case "clear": archiveCurrent(agent.cwd); agent.history = []; state.lines = []; state.streaming = ""; state.reasoning = ""; state.tasks = []; state.scroll = 0; pushLine("Cleared (archived).", C.warn); break;
489
- case "new": archiveCurrent(agent.cwd); agent.history = []; state.lines = []; state.streaming = ""; state.reasoning = ""; state.toolStreams = {}; state.tasks = []; state.scroll = 0; state.tokens = { prompt: 0, completion: 0 }; pushLine("New session.", C.tool); break;
489
+ case "clear": archiveCurrent(agent.cwd); agent.history = []; state.lines = []; state.streaming = ""; state.reasoning = ""; state.tasks = []; agent.tasks = []; state.scroll = 0; pushLine("Cleared (archived).", C.warn); break;
490
+ case "new": archiveCurrent(agent.cwd); agent.history = []; state.lines = []; state.streaming = ""; state.reasoning = ""; state.toolStreams = {}; state.tasks = []; agent.tasks = []; state.scroll = 0; state.tokens = { prompt: 0, completion: 0, cacheHit: 0, cacheMiss: 0 }; pushLine("New session.", C.tool); break;
490
491
  case "tasks": if (state.tasks.length === 0) pushLine("No tasks.", C.dim); else for (const t of state.tasks) pushLine(" " + (t.status === "done" ? "\u2713" : t.status === "in_progress" ? "\u25b6" : "\u25cb") + " " + t.title, C.dim); break;
491
492
  case "stats": pushLine("Tokens: \u2191" + state.tokens.prompt + " \u2193" + state.tokens.completion + " | History: " + agent.history.length + " msgs (~" + estimateTokens(agent.history) + " t) | Lines: " + state.lines.length, C.dim); break;
492
493
  case "quit": case "exit": cleanup(); process.exit(0); return;
@@ -536,7 +537,6 @@ export async function startTUI(agent, opts = {}) {
536
537
  else if (raw && typeof raw.text === "string") state.lines.push(raw);
537
538
  }
538
539
  if (restored.history) agent.history = restored.history;
539
- if (restored.tasks) { state.tasks = restored.tasks; agent.tasks = restored.tasks; }
540
540
  if (restored.goal) agent.goal = restored.goal;
541
541
  if (restored.planMode !== undefined) agent.planMode = restored.planMode;
542
542
  state.status = "Session restored";