@hasna/economy 0.2.2 → 0.2.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/dist/mcp/index.js CHANGED
@@ -1,13 +1,17 @@
1
1
  #!/usr/bin/env bun
2
2
  // @bun
3
3
  var __defProp = Object.defineProperty;
4
+ var __returnValue = (v) => v;
5
+ function __exportSetter(name, newValue) {
6
+ this[name] = __returnValue.bind(null, newValue);
7
+ }
4
8
  var __export = (target, all) => {
5
9
  for (var name in all)
6
10
  __defProp(target, name, {
7
11
  get: all[name],
8
12
  enumerable: true,
9
13
  configurable: true,
10
- set: (newValue) => all[name] = () => newValue
14
+ set: __exportSetter.bind(all, name)
11
15
  });
12
16
  };
13
17
  var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
@@ -391,6 +395,7 @@ var init_database = () => {};
391
395
 
392
396
  // src/mcp/index.ts
393
397
  init_database();
398
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
394
399
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
395
400
  import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
396
401
 
@@ -595,6 +600,7 @@ async function ingestCodex(db, verbose = false) {
595
600
  init_pricing();
596
601
  var db = openDatabase();
597
602
  ensurePricingSeeded(db);
603
+ var server = new Server({ name: "economy", version: "0.2.2" }, { capabilities: { tools: {} } });
598
604
  var fmtUsd = (n) => "$" + n.toLocaleString("en-US", { minimumFractionDigits: 2, maximumFractionDigits: 2 });
599
605
  var fmtTok = (n) => n >= 1e9 ? `${(n / 1e9).toFixed(1)}B` : n >= 1e6 ? `${(n / 1e6).toFixed(1)}M` : n >= 1000 ? `${(n / 1000).toFixed(1)}k` : String(n);
600
606
  function fmtSession(s) {
@@ -730,5 +736,31 @@ server.setRequestHandler(CallToolRequestSchema, async (req) => {
730
736
  return { content: [{ type: "text", text: `Error: ${e instanceof Error ? e.message : String(e)}` }], isError: true };
731
737
  }
732
738
  });
739
+ var _agentReg = new Map;
740
+ server.tool("register_agent", "Register this agent session. Returns agent_id for use in heartbeat/set_focus.", { name: z.string(), session_id: z.string().optional() }, async (a) => {
741
+ const existing = [..._agentReg.values()].find((x) => x.name === a.name);
742
+ if (existing) {
743
+ existing.last_seen_at = new Date().toISOString();
744
+ return { content: [{ type: "text", text: JSON.stringify(existing) }] };
745
+ }
746
+ const id = Math.random().toString(36).slice(2, 10);
747
+ const ag = { id, name: a.name, last_seen_at: new Date().toISOString() };
748
+ _agentReg.set(id, ag);
749
+ return { content: [{ type: "text", text: JSON.stringify(ag) }] };
750
+ });
751
+ server.tool("heartbeat", "Update last_seen_at to signal agent is active.", { agent_id: z.string() }, async (a) => {
752
+ const ag = _agentReg.get(a.agent_id);
753
+ if (!ag)
754
+ return { content: [{ type: "text", text: `Agent not found: ${a.agent_id}` }], isError: true };
755
+ ag.last_seen_at = new Date().toISOString();
756
+ return { content: [{ type: "text", text: `\u2665 ${ag.name} \u2014 active` }] };
757
+ });
758
+ server.tool("set_focus", "Set active project context for this agent session.", { agent_id: z.string(), project_id: z.string().optional() }, async (a) => {
759
+ const ag = _agentReg.get(a.agent_id);
760
+ if (!ag)
761
+ return { content: [{ type: "text", text: `Agent not found: ${a.agent_id}` }], isError: true };
762
+ ag.project_id = a.project_id;
763
+ return { content: [{ type: "text", text: a.project_id ? `Focus: ${a.project_id}` : "Focus cleared" }] };
764
+ });
733
765
  var transport = new StdioServerTransport;
734
766
  await server.connect(transport);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hasna/economy",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "description": "AI coding cost tracker — CLI + MCP server + REST API + web dashboard for Claude Code, Codex, and Gemini",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -1,8 +0,0 @@
1
- import type { Agent } from '../../types/index.js';
2
- interface WatchOptions {
3
- interval: number;
4
- agent?: Agent;
5
- }
6
- export declare function watchCosts(opts: WatchOptions): Promise<void>;
7
- export {};
8
- //# sourceMappingURL=watch.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"watch.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/watch.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAA;AAEjD,UAAU,YAAY;IACpB,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,CAAC,EAAE,KAAK,CAAA;CACd;AAuBD,wBAAsB,UAAU,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAiElE"}
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env bun
2
- export {};
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":""}