@devness/useai 0.4.7 → 0.4.9

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 (2) hide show
  1. package/dist/index.js +27 -12
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -112,7 +112,7 @@ var VERSION;
112
112
  var init_version = __esm({
113
113
  "../shared/dist/constants/version.js"() {
114
114
  "use strict";
115
- VERSION = "0.4.7";
115
+ VERSION = "0.4.9";
116
116
  }
117
117
  });
118
118
 
@@ -1081,6 +1081,15 @@ function getSessions() {
1081
1081
  function getMilestones() {
1082
1082
  return readJson(MILESTONES_FILE, []);
1083
1083
  }
1084
+ function resolveClient(server2, session2) {
1085
+ if (session2.clientName !== "unknown") return;
1086
+ const clientInfo = server2.server.getClientVersion();
1087
+ if (clientInfo?.name) {
1088
+ session2.setClient(normalizeMcpClientName(clientInfo.name));
1089
+ return;
1090
+ }
1091
+ session2.setClient(detectClient());
1092
+ }
1084
1093
  function registerTools(server2, session2) {
1085
1094
  server2.tool(
1086
1095
  "useai_session_start",
@@ -1090,9 +1099,7 @@ function registerTools(server2, session2) {
1090
1099
  },
1091
1100
  async ({ task_type }) => {
1092
1101
  session2.reset();
1093
- if (session2.clientName === "unknown") {
1094
- session2.setClient(detectClient());
1095
- }
1102
+ resolveClient(server2, session2);
1096
1103
  session2.setTaskType(task_type ?? "coding");
1097
1104
  const record = session2.appendToChain("session_start", {
1098
1105
  client: session2.clientName,
@@ -3118,9 +3125,14 @@ function sealOrphanedSessions() {
3118
3125
  console.log(`Sealed ${sealed} orphaned session${sealed === 1 ? "" : "s"}`);
3119
3126
  }
3120
3127
  }
3128
+ function isSessionAlreadySealed(session2) {
3129
+ const activePath = join7(ACTIVE_DIR, `${session2.sessionId}.jsonl`);
3130
+ return !existsSync9(activePath);
3131
+ }
3121
3132
  function autoSealSession(active) {
3122
3133
  const { session: session2 } = active;
3123
3134
  if (session2.sessionRecordCount === 0) return;
3135
+ if (isSessionAlreadySealed(session2)) return;
3124
3136
  const duration = session2.getSessionDuration();
3125
3137
  const now = (/* @__PURE__ */ new Date()).toISOString();
3126
3138
  const endRecord = session2.appendToChain("session_end", {
@@ -3181,6 +3193,10 @@ function autoSealSession(active) {
3181
3193
  allSessions.push(seal);
3182
3194
  writeJson(SESSIONS_FILE, allSessions);
3183
3195
  }
3196
+ function sealSessionData(active) {
3197
+ autoSealSession(active);
3198
+ active.session.reset();
3199
+ }
3184
3200
  function resetIdleTimer(sessionId) {
3185
3201
  const active = sessions.get(sessionId);
3186
3202
  if (!active) return;
@@ -3286,15 +3302,18 @@ async function startDaemon(port) {
3286
3302
  return;
3287
3303
  }
3288
3304
  if (url.pathname === "/api/seal-active" && req.method === "POST") {
3289
- const sids = [...sessions.keys()];
3290
- for (const sid of sids) {
3291
- await cleanupSession(sid);
3305
+ let sealed = 0;
3306
+ for (const [, active] of sessions) {
3307
+ if (active.session.sessionRecordCount > 0 && !isSessionAlreadySealed(active.session)) {
3308
+ sealSessionData(active);
3309
+ sealed++;
3310
+ }
3292
3311
  }
3293
3312
  res.writeHead(200, {
3294
3313
  "Content-Type": "application/json",
3295
3314
  "Access-Control-Allow-Origin": "*"
3296
3315
  });
3297
- res.end(JSON.stringify({ sealed: sids.length }));
3316
+ res.end(JSON.stringify({ sealed }));
3298
3317
  return;
3299
3318
  }
3300
3319
  if ((url.pathname.startsWith("/api/local/") || url.pathname === "/api/seal-active") && req.method === "OPTIONS") {
@@ -3339,10 +3358,6 @@ async function startDaemon(port) {
3339
3358
  const transport = new StreamableHTTPServerTransport({
3340
3359
  sessionIdGenerator: () => randomUUID4(),
3341
3360
  onsessioninitialized: (newSid) => {
3342
- const clientInfo = mcpServer.server.getClientVersion();
3343
- if (clientInfo?.name) {
3344
- sessionState.setClient(normalizeMcpClientName(clientInfo.name));
3345
- }
3346
3361
  const idleTimer = setTimeout(async () => {
3347
3362
  await cleanupSession(newSid);
3348
3363
  }, IDLE_TIMEOUT_MS);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devness/useai",
3
- "version": "0.4.7",
3
+ "version": "0.4.9",
4
4
  "description": "Track your AI-assisted development workflow. MCP server that records usage metrics across all your AI tools.",
5
5
  "keywords": [
6
6
  "mcp",