fraim 2.0.270 → 2.0.271

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.
@@ -70,6 +70,7 @@ const usage_collector_js_1 = require("./usage-collector.js");
70
70
  const otlp_metrics_receiver_js_1 = require("./otlp-metrics-receiver.js");
71
71
  const token_adapter_registry_js_1 = require("./token-adapter-registry.js");
72
72
  const learning_context_builder_js_1 = require("./learning-context-builder.js");
73
+ const learning_usage_store_js_1 = require("./learning-usage-store.js");
73
74
  const learning_domains_js_1 = require("../config/learning-domains.js");
74
75
  const skill_include_dedup_js_1 = require("./skill-include-dedup.js");
75
76
  /**
@@ -1371,6 +1372,7 @@ class FraimLocalMCPServer {
1371
1372
  responseText += teamContextSection;
1372
1373
  this.log(`[req:${requestId}] Injected team context from ${workspaceRoot}`);
1373
1374
  }
1375
+ this.recordUsageOffers(workspaceRoot, userEmail, false, null, 'session', requestId);
1374
1376
  }
1375
1377
  if (this.latestConnectSyncWarning) {
1376
1378
  responseText += `\n\n## Local Catalog\n${this.latestConnectSyncWarning}`;
@@ -1391,10 +1393,51 @@ class FraimLocalMCPServer {
1391
1393
  finalizedResponse.result.content[0].text = text + `\n\n---` + learningSection + teamContextSection;
1392
1394
  this.log(`[req:${requestId}] Injected job-focus learning/team context for ${userEmail} (domain: ${jobDomain ?? 'global'})`);
1393
1395
  }
1396
+ this.recordUsageOffers(workspaceRoot, userEmail, true, jobDomain, String(args.job ?? 'unknown'), requestId);
1394
1397
  }
1395
1398
  }
1396
1399
  return this.processResponseWithHydration(finalizedResponse, requestSessionId);
1397
1400
  }
1401
+ /**
1402
+ * Issue #1103 R1, R2 and R3: record what this context injection delivered.
1403
+ *
1404
+ * Written here because this is the only place that knows all of it at once: the
1405
+ * files that were listed, the job, the agent, and the model. Nothing depends on
1406
+ * the agent reading anything, which is R2, and the three auto-loaded rule files
1407
+ * get a record for the first time, which is R3.
1408
+ *
1409
+ * Never throws and never blocks the response. Usage data is derived and optional:
1410
+ * a failure here must not change what the agent is given.
1411
+ */
1412
+ recordUsageOffers(workspaceRoot, userEmail, forJob, domain, job, requestId) {
1413
+ try {
1414
+ const offered = [
1415
+ ...(0, learning_context_builder_js_1.collectOfferedLearningEntries)(workspaceRoot, userEmail, forJob, domain),
1416
+ ...(0, learning_context_builder_js_1.collectOfferedRuleFiles)(workspaceRoot, forJob),
1417
+ ];
1418
+ if (offered.length === 0)
1419
+ return;
1420
+ const collector = this.usageCollector;
1421
+ const date = new Date().toISOString().slice(0, 10);
1422
+ const limits = (0, learning_usage_store_js_1.resolveUsageLimits)(workspaceRoot);
1423
+ const result = (0, learning_usage_store_js_1.recordOffers)(offered.map((entry) => ({
1424
+ key: entry.key,
1425
+ family: entry.family,
1426
+ title: entry.title,
1427
+ fileType: entry.fileType,
1428
+ level: entry.level,
1429
+ aboveThreshold: entry.aboveThreshold,
1430
+ job,
1431
+ date,
1432
+ agent: collector?.getAgentName() ?? null,
1433
+ model: collector?.getAgentModel() ?? null,
1434
+ })), { limits });
1435
+ this.log(`[req:${requestId}] Recorded ${result.recorded} usage offers for job ${job}`);
1436
+ }
1437
+ catch (error) {
1438
+ this.log(`[req:${requestId}] Usage offer recording skipped: ${error instanceof Error ? error.message : String(error)}`);
1439
+ }
1440
+ }
1398
1441
  /**
1399
1442
  * Resolve the learning domain for a `get_fraim_job` request (issue #806) from
1400
1443
  * the job's registry path, so the loader injects global + that domain's
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fraim",
3
- "version": "2.0.270",
3
+ "version": "2.0.271",
4
4
  "description": "FRAIM core CLI and MCP package.",
5
5
  "main": "index.js",
6
6
  "bin": {