@devness/useai 0.6.16 → 0.6.17

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 +22 -3
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -684,7 +684,7 @@ var VERSION;
684
684
  var init_version = __esm({
685
685
  "../shared/dist/constants/version.js"() {
686
686
  "use strict";
687
- VERSION = "0.6.16";
687
+ VERSION = "0.6.17";
688
688
  }
689
689
  });
690
690
 
@@ -34595,6 +34595,8 @@ var init_session_state = __esm({
34595
34595
  inProgressSince;
34596
34596
  /** Session ID that was auto-sealed by seal-active hook (for useai_end fallback). */
34597
34597
  autoSealedSessionId;
34598
+ /** Timestamp of the last meaningful activity (tool call, heartbeat). Used for auto-seal duration. */
34599
+ lastActivityTime;
34598
34600
  /** Saved parent session state when a child (subagent) session is active. */
34599
34601
  parentState;
34600
34602
  constructor() {
@@ -34609,6 +34611,7 @@ var init_session_state = __esm({
34609
34611
  this.autoSealedSessionId = null;
34610
34612
  this.parentState = null;
34611
34613
  this.sessionStartTime = Date.now();
34614
+ this.lastActivityTime = this.sessionStartTime;
34612
34615
  this.heartbeatCount = 0;
34613
34616
  this.sessionRecordCount = 0;
34614
34617
  this.clientName = "unknown";
@@ -34623,6 +34626,7 @@ var init_session_state = __esm({
34623
34626
  }
34624
34627
  reset() {
34625
34628
  this.sessionStartTime = Date.now();
34629
+ this.lastActivityTime = this.sessionStartTime;
34626
34630
  this.sessionId = generateSessionId();
34627
34631
  this.heartbeatCount = 0;
34628
34632
  this.sessionRecordCount = 0;
@@ -34662,12 +34666,24 @@ var init_session_state = __esm({
34662
34666
  setModel(id) {
34663
34667
  this.modelId = id;
34664
34668
  }
34669
+ /** Update the last-activity timestamp to now. Called on every meaningful event. */
34670
+ touchActivity() {
34671
+ this.lastActivityTime = Date.now();
34672
+ }
34665
34673
  incrementHeartbeat() {
34666
34674
  this.heartbeatCount++;
34675
+ this.touchActivity();
34667
34676
  }
34668
34677
  getSessionDuration() {
34669
34678
  return Math.round((Date.now() - this.sessionStartTime) / 1e3);
34670
34679
  }
34680
+ /**
34681
+ * Duration based on the last meaningful activity, not the current wall-clock time.
34682
+ * Used by auto-seal to avoid counting idle timeout as active time.
34683
+ */
34684
+ getActiveDuration() {
34685
+ return Math.round((this.lastActivityTime - this.sessionStartTime) / 1e3);
34686
+ }
34671
34687
  /**
34672
34688
  * Save the current session state as the parent, so it can be restored
34673
34689
  * after a child (subagent) session finishes.
@@ -34676,6 +34692,7 @@ var init_session_state = __esm({
34676
34692
  this.parentState = {
34677
34693
  sessionId: this.sessionId,
34678
34694
  sessionStartTime: this.sessionStartTime,
34695
+ lastActivityTime: this.lastActivityTime,
34679
34696
  heartbeatCount: this.heartbeatCount,
34680
34697
  sessionRecordCount: this.sessionRecordCount,
34681
34698
  chainTipHash: this.chainTipHash,
@@ -34701,6 +34718,7 @@ var init_session_state = __esm({
34701
34718
  const p = this.parentState;
34702
34719
  this.sessionId = p.sessionId;
34703
34720
  this.sessionStartTime = p.sessionStartTime;
34721
+ this.lastActivityTime = p.lastActivityTime;
34704
34722
  this.heartbeatCount = p.heartbeatCount;
34705
34723
  this.sessionRecordCount = p.sessionRecordCount;
34706
34724
  this.chainTipHash = p.chainTipHash;
@@ -34746,6 +34764,7 @@ var init_session_state = __esm({
34746
34764
  appendFileSync(this.sessionChainPath(), JSON.stringify(record2) + "\n", "utf-8");
34747
34765
  this.chainTipHash = record2.hash;
34748
34766
  this.sessionRecordCount++;
34767
+ this.touchActivity();
34749
34768
  return record2;
34750
34769
  }
34751
34770
  };
@@ -35999,8 +36018,8 @@ function autoSealSession(active) {
35999
36018
  const { session: session2 } = active;
36000
36019
  if (session2.sessionRecordCount === 0) return;
36001
36020
  if (isSessionAlreadySealed(session2)) return;
36002
- const duration3 = session2.getSessionDuration();
36003
- const now = (/* @__PURE__ */ new Date()).toISOString();
36021
+ const duration3 = session2.getActiveDuration();
36022
+ const now = new Date(session2.lastActivityTime).toISOString();
36004
36023
  const endRecord = session2.appendToChain("session_end", {
36005
36024
  duration_seconds: duration3,
36006
36025
  task_type: session2.sessionTaskType,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devness/useai",
3
- "version": "0.6.16",
3
+ "version": "0.6.17",
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",