@godmode-team/godmode 1.7.0 → 1.7.1
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/index.js +71 -6
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3575,6 +3575,7 @@ var init_tasks = __esm({
|
|
|
3575
3575
|
var impact_ledger_exports = {};
|
|
3576
3576
|
__export(impact_ledger_exports, {
|
|
3577
3577
|
getImpactSummary: () => getImpactSummary,
|
|
3578
|
+
hasSessionImpact: () => hasSessionImpact,
|
|
3578
3579
|
impactLedgerHandlers: () => impactLedgerHandlers,
|
|
3579
3580
|
logImpact: () => logImpact
|
|
3580
3581
|
});
|
|
@@ -3682,6 +3683,10 @@ async function getImpactSummary(daysBack) {
|
|
|
3682
3683
|
byWorkflow
|
|
3683
3684
|
};
|
|
3684
3685
|
}
|
|
3686
|
+
async function hasSessionImpact(sessionId) {
|
|
3687
|
+
const state2 = await readState();
|
|
3688
|
+
return state2.entries.some((e) => e.sessionId === sessionId);
|
|
3689
|
+
}
|
|
3685
3690
|
var STATE_FILE, MAX_ENTRIES, DEFAULT_WORKFLOW_MINUTES, DEFAULT_HOURLY_RATE, LOCK_OPTIONS3, impactLedgerHandlers;
|
|
3686
3691
|
var init_impact_ledger = __esm({
|
|
3687
3692
|
"src/methods/impact-ledger.ts"() {
|
|
@@ -3703,7 +3708,8 @@ var init_impact_ledger = __esm({
|
|
|
3703
3708
|
ops: 20,
|
|
3704
3709
|
task: 30,
|
|
3705
3710
|
url: 10,
|
|
3706
|
-
idea: 15
|
|
3711
|
+
idea: 15,
|
|
3712
|
+
"chat session": 10
|
|
3707
3713
|
};
|
|
3708
3714
|
DEFAULT_HOURLY_RATE = 150;
|
|
3709
3715
|
LOCK_OPTIONS3 = {
|
|
@@ -3717,7 +3723,7 @@ var init_impact_ledger = __esm({
|
|
|
3717
3723
|
respond(false, void 0, { code: "INVALID_PARAMS", message: "workflow is required" });
|
|
3718
3724
|
return;
|
|
3719
3725
|
}
|
|
3720
|
-
const validSources = ["trust-rate", "queue-complete", "manual", "auto"];
|
|
3726
|
+
const validSources = ["trust-rate", "queue-complete", "session", "manual", "auto"];
|
|
3721
3727
|
const resolvedSource = validSources.includes(source) ? source : "manual";
|
|
3722
3728
|
const entry = await logImpact({
|
|
3723
3729
|
workflow,
|
|
@@ -4670,14 +4676,38 @@ async function generateDailyBrief(date) {
|
|
|
4670
4676
|
let impactRaw = carryForward.yesterdayImpact || "";
|
|
4671
4677
|
try {
|
|
4672
4678
|
const { getImpactSummary: getImpactSummary2 } = await Promise.resolve().then(() => (init_impact_ledger(), impact_ledger_exports));
|
|
4679
|
+
const yesterdayImpact = await getImpactSummary2(1);
|
|
4680
|
+
if (yesterdayImpact.count > 0) {
|
|
4681
|
+
const hours = Math.round(yesterdayImpact.totalMinutes / 60 * 10) / 10;
|
|
4682
|
+
const topWorkflows = Object.entries(yesterdayImpact.byWorkflow).sort(([, a], [, b]) => b.minutes - a.minutes).slice(0, 5).map(([name, stats]) => `${name}: ${Math.round(stats.minutes)}m saved ($${Math.round(stats.dollars)})`).join(", ");
|
|
4683
|
+
const sessionCount = yesterdayImpact.count;
|
|
4684
|
+
const yesterdayLine = `Yesterday: ${hours}h saved ($${Math.round(yesterdayImpact.totalDollars)}) across ${sessionCount} interactions. Breakdown: ${topWorkflows}`;
|
|
4685
|
+
impactRaw = impactRaw ? `${impactRaw}
|
|
4686
|
+
|
|
4687
|
+
${yesterdayLine}` : yesterdayLine;
|
|
4688
|
+
}
|
|
4673
4689
|
const weekImpact = await getImpactSummary2(7);
|
|
4674
4690
|
if (weekImpact.count > 0) {
|
|
4675
4691
|
const hours = Math.round(weekImpact.totalMinutes / 60 * 10) / 10;
|
|
4676
|
-
const
|
|
4677
|
-
const ledgerLine = `This week: ${hours}h saved ($${Math.round(weekImpact.totalDollars).toLocaleString()}) across ${weekImpact.count} workflow executions. Top: ${topWorkflows}`;
|
|
4692
|
+
const weekLine = `This week: ${hours}h saved ($${Math.round(weekImpact.totalDollars)}) across ${weekImpact.count} interactions.`;
|
|
4678
4693
|
impactRaw = impactRaw ? `${impactRaw}
|
|
4679
|
-
|
|
4680
|
-
|
|
4694
|
+
${weekLine}` : weekLine;
|
|
4695
|
+
}
|
|
4696
|
+
} catch {
|
|
4697
|
+
}
|
|
4698
|
+
try {
|
|
4699
|
+
const { readDailyLog: readDailyLog2 } = await Promise.resolve().then(() => (init_agent_log(), agent_log_exports));
|
|
4700
|
+
const yesterdayLog = await readDailyLog2(yesterdayDate());
|
|
4701
|
+
if (yesterdayLog?.content) {
|
|
4702
|
+
const completedMatch = yesterdayLog.content.match(/Completed:\s*\*\*(\d+)\*\*/);
|
|
4703
|
+
const errorsMatch = yesterdayLog.content.match(/Errors:\s*\*\*(\d+)\*\*/);
|
|
4704
|
+
const completedCount = completedMatch ? Number(completedMatch[1]) : 0;
|
|
4705
|
+
const errorCount = errorsMatch ? Number(errorsMatch[1]) : 0;
|
|
4706
|
+
if (completedCount > 0 || errorCount > 0) {
|
|
4707
|
+
const logLine = `Agent log: ${completedCount} completed items${errorCount > 0 ? `, ${errorCount} errors` : ""} yesterday.`;
|
|
4708
|
+
impactRaw = impactRaw ? `${impactRaw}
|
|
4709
|
+
${logLine}` : logLine;
|
|
4710
|
+
}
|
|
4681
4711
|
}
|
|
4682
4712
|
} catch {
|
|
4683
4713
|
}
|
|
@@ -34651,6 +34681,9 @@ init_safety_gates();
|
|
|
34651
34681
|
init_safety_gates();
|
|
34652
34682
|
init_guardrails();
|
|
34653
34683
|
init_workspace_session_store();
|
|
34684
|
+
var _sessionTracker = /* @__PURE__ */ new Map();
|
|
34685
|
+
var SESSION_TRACKER_MAX = 200;
|
|
34686
|
+
var SESSION_MIN_MESSAGES = 2;
|
|
34654
34687
|
var lastReceivedMessage = null;
|
|
34655
34688
|
var _dashboardSaveCalled = /* @__PURE__ */ new Set();
|
|
34656
34689
|
var _dashboardSaveCalledTTL = 5 * 60 * 1e3;
|
|
@@ -34733,6 +34766,16 @@ async function handleMessageReceived(event, ctx, api) {
|
|
|
34733
34766
|
sessions2.touch(sessionKey);
|
|
34734
34767
|
} catch {
|
|
34735
34768
|
}
|
|
34769
|
+
const existing = _sessionTracker.get(sessionKey);
|
|
34770
|
+
if (existing) {
|
|
34771
|
+
existing.messageCount++;
|
|
34772
|
+
} else {
|
|
34773
|
+
if (_sessionTracker.size >= SESSION_TRACKER_MAX) {
|
|
34774
|
+
const oldest = _sessionTracker.keys().next().value;
|
|
34775
|
+
if (oldest) _sessionTracker.delete(oldest);
|
|
34776
|
+
}
|
|
34777
|
+
_sessionTracker.set(sessionKey, { startedAt: Date.now(), messageCount: 1 });
|
|
34778
|
+
}
|
|
34736
34779
|
}
|
|
34737
34780
|
try {
|
|
34738
34781
|
const { resetTurnToolUsage: resetTurnToolUsage2 } = await Promise.resolve().then(() => (init_safety_gates(), safety_gates_exports));
|
|
@@ -34786,6 +34829,28 @@ async function handleBeforeReset(event, ctx, api) {
|
|
|
34786
34829
|
} catch (err) {
|
|
34787
34830
|
logger2.warn(`[GodMode] team memory route hook error: ${String(err)}`);
|
|
34788
34831
|
}
|
|
34832
|
+
if (sessionKey) {
|
|
34833
|
+
const tracked = _sessionTracker.get(sessionKey);
|
|
34834
|
+
_sessionTracker.delete(sessionKey);
|
|
34835
|
+
if (tracked && tracked.messageCount >= SESSION_MIN_MESSAGES && !sessionKey.includes(":cron:")) {
|
|
34836
|
+
void (async () => {
|
|
34837
|
+
try {
|
|
34838
|
+
const { hasSessionImpact: hasSessionImpact2, logImpact: logImpact2 } = await Promise.resolve().then(() => (init_impact_ledger(), impact_ledger_exports));
|
|
34839
|
+
if (await hasSessionImpact2(sessionKey)) return;
|
|
34840
|
+
const durationMin = Math.round((Date.now() - tracked.startedAt) / 6e4);
|
|
34841
|
+
const minutesOverride = Math.max(10, Math.min(durationMin, 120));
|
|
34842
|
+
await logImpact2({
|
|
34843
|
+
workflow: "chat session",
|
|
34844
|
+
source: "session",
|
|
34845
|
+
sessionId: sessionKey,
|
|
34846
|
+
note: `${tracked.messageCount} messages, ${durationMin}m duration`,
|
|
34847
|
+
minutesOverride
|
|
34848
|
+
});
|
|
34849
|
+
} catch {
|
|
34850
|
+
}
|
|
34851
|
+
})();
|
|
34852
|
+
}
|
|
34853
|
+
}
|
|
34789
34854
|
}
|
|
34790
34855
|
async function handleBeforeToolCall(event, ctx, api) {
|
|
34791
34856
|
const logger2 = api.logger;
|
package/openclaw.plugin.json
CHANGED