@agenr/openclaw-plugin 3.3.0 → 2026.6.2

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.
@@ -0,0 +1,41 @@
1
+ // src/core/dreaming/efficiency.ts
2
+ var PROFILE_DURABLE_TOKEN_ESTIMATE = 36;
3
+ var PROFILE_DIRECTIVE_TOKEN_ESTIMATE = 24;
4
+ function buildDreamEfficiencySummary(input) {
5
+ const evidenceItemsRead = input.scan.episodesSinceLastRun + input.scan.ingestFilesSinceLastRun + input.scan.durablesCreatedSinceLastRun;
6
+ const profileInjectionTokenEstimate = estimateProfileInjectionTokens(input.profileDurableCount, input.directiveCount);
7
+ return {
8
+ evidenceItemsRead,
9
+ synthesizedDurableMutations: input.synthesizedDurableMutations,
10
+ costPerSynthesizedDurableUsd: input.synthesizedDurableMutations > 0 ? roundEfficiencyMetric(input.estimatedCostUsd / input.synthesizedDurableMutations) : null,
11
+ profileInjectionTokenEstimate,
12
+ recomputeRatio: evidenceItemsRead === 0 ? 0 : roundEfficiencyMetric(input.synthesizedDurableMutations / evidenceItemsRead)
13
+ };
14
+ }
15
+ function deriveDreamEfficiencySummary(summary, estimatedCostUsd) {
16
+ if (!summary.scan || !summary.project) {
17
+ return null;
18
+ }
19
+ return buildDreamEfficiencySummary({
20
+ scan: summary.scan,
21
+ estimatedCostUsd,
22
+ synthesizedDurableMutations: countSynthesizedDurableMutations(summary),
23
+ profileDurableCount: summary.project.profileDurableCount,
24
+ directiveCount: summary.project.directiveCount
25
+ });
26
+ }
27
+ function countSynthesizedDurableMutations(summary) {
28
+ return (summary.extract?.durablesInserted ?? 0) + (summary.temporalize?.revisionsApplied ?? 0) + (summary.prune?.durablesStaled ?? 0);
29
+ }
30
+ function estimateProfileInjectionTokens(profileDurableCount, directiveCount) {
31
+ return profileDurableCount * PROFILE_DURABLE_TOKEN_ESTIMATE + directiveCount * PROFILE_DIRECTIVE_TOKEN_ESTIMATE;
32
+ }
33
+ function roundEfficiencyMetric(value) {
34
+ return Number(value.toFixed(6));
35
+ }
36
+
37
+ export {
38
+ buildDreamEfficiencySummary,
39
+ deriveDreamEfficiencySummary,
40
+ estimateProfileInjectionTokens
41
+ };
@@ -0,0 +1,44 @@
1
+ // src/app/dreaming/scan.ts
2
+ async function runDreamScan(options, deps) {
3
+ const since = await resolveScanSince(options, deps.port);
4
+ const [episodesSinceLastRun, ingestFilesSinceLastRun, durablesCreatedSinceLastRun, unsynthesizedImportanceSum] = await Promise.all([
5
+ deps.port.countEpisodesSince(since, options.project),
6
+ deps.port.countIngestFilesSince(since),
7
+ deps.port.countDurablesCreatedSince(since, options.project),
8
+ deps.port.sumDurableImportanceCreatedSince(since, options.project)
9
+ ]);
10
+ const evidenceRefs = [];
11
+ if (ingestFilesSinceLastRun > 0) {
12
+ evidenceRefs.push({
13
+ kind: "ingest_log",
14
+ locator: `since:${since}`,
15
+ observedAt: options.now().toISOString()
16
+ });
17
+ }
18
+ if (episodesSinceLastRun > 0) {
19
+ evidenceRefs.push({
20
+ kind: "episode",
21
+ locator: `since:${since}`,
22
+ observedAt: options.now().toISOString()
23
+ });
24
+ }
25
+ return {
26
+ episodesSinceLastRun,
27
+ ingestFilesSinceLastRun,
28
+ durablesCreatedSinceLastRun,
29
+ evidenceRefs,
30
+ unsynthesizedImportanceSum
31
+ };
32
+ }
33
+ async function resolveScanSince(options, port) {
34
+ if (options.fullBacklog === true) {
35
+ return "1970-01-01T00:00:00.000Z";
36
+ }
37
+ const lastRun = await port.getLastRun();
38
+ const lastSuccessfulAt = lastRun?.status === "completed" ? lastRun.completedAt : null;
39
+ return lastSuccessfulAt ?? "1970-01-01T00:00:00.000Z";
40
+ }
41
+
42
+ export {
43
+ runDreamScan
44
+ };