@shomra/agent 0.3.20 → 0.3.22

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shomra/agent",
3
- "version": "0.3.20",
3
+ "version": "0.3.22",
4
4
  "description": "Shomra - adversarial assurance for AI agents, as a local-first CLI. Blocks dangerous tool-calls before they run, attacks your own guardrails to prove they hold, and gates AI artifacts in your editor and CI.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -11,7 +11,7 @@ export const INJECTION_PHRASES = [
11
11
  ];
12
12
 
13
13
  export const INJECTION_REGEXES = [
14
- { label: 'Instruction-override phrasing', re: /\b(ignore|disregard|override|bypass|circumvent)\b[\s\w,'"()-]{0,40}?\b(instruction|instructions|directive|directives|safety|safeguards?|guardrails?|system\s+prompt|content\s+polic\w+)\b/i },
14
+ { label: 'Instruction-override phrasing', re: /\b(?:ignore|disregard|override|bypass|circumvent|discard|nullify|revoke|rescind|supersede[sd]?|abandon|set\s+aside|put\s+aside|cast\s+aside|pay\s+no\s+(?:attention|heed)\s+to|take\s+no\s+notice\s+of|stop\s+(?:following|obeying|adhering\s+to)|cease\s+(?:following|obeying)|no\s+longer\s+(?:follow|obey|adhere\s+to))\b[\s\w,'"()-]{0,40}?\b(instruction|instructions|directive|directives|safety|safeguards?|guardrails?|guidelines?|safety\s+(?:rules?|filters?|checks?)|system\s+prompt|content\s+polic\w+)\b/i },
15
15
  { label: 'Instructs the agent to conceal an action from the user', re: /\b(?:do\s*n['o]?t|never|without)\s+(?:tell|telling|inform|informing|notify|notifying|alert|alerting|mention|mentioning|disclos\w+|reveal\w*)\s+(?:it\s+|this\s+|them\s+)?(?:to\s+)?(?:the\s+)?(?:user|users|human|operator|owner)\b(?!['']s)(?!\s+(?:to\b|how\s+to\b|when\s+to\b|that\s+they\b|about\b))/i },
16
16
  { label: 'Bulk destructive command', re: /\b(delete|remove|wipe|erase|destroy|drop|purge|nuke|truncate)\b[\s\w,'"()-]{0,20}?\b(all|every|each|entire|whole)\b[\s\w,'"()-]{0,15}?\b(folder|folders|file|files|directory|directories|table|tables|database|databases|record|records|repo|repos|repositor\w*|account|accounts|user|users|row|rows|document|documents|data)\b/i },
17
17
  { label: 'Destructive SQL statement', re: /\b(drop|truncate)\s+(table|database|schema)\b/i },
@@ -13,6 +13,17 @@ function loadModelCache() { try { return JSON.parse(fs.readFileSync(MODEL_CACHE_
13
13
 
14
14
  function saveModelCache(c) { try { fs.mkdirSync(CONFIG_DIR, { recursive: true }); fs.writeFileSync(MODEL_CACHE_FILE, JSON.stringify(c)); } catch { } }
15
15
 
16
+ export const MODEL_CACHE_MAX_ENTRIES = 500;
17
+
18
+ export const MODEL_CACHE_RETAIN_MS = 90 * 24 * 3600 * 1000;
19
+
20
+ export function pruneModelCache(cache, { now = Date.now(), ttl = 0, max = MODEL_CACHE_MAX_ENTRIES } = {}) {
21
+ const horizon = Math.max(MODEL_CACHE_RETAIN_MS, ttl);
22
+ const live = Object.entries(cache ?? {}).filter(([, v]) => v && typeof v.cachedAt === 'number' && now - v.cachedAt < horizon);
23
+ live.sort((a, b) => b[1].cachedAt - a[1].cachedAt);
24
+ return Object.fromEntries(live.slice(0, max));
25
+ }
26
+
16
27
  export async function modelLookup(url, id, sha, timeoutMs) {
17
28
  const key = `${id}@${sha || 'latest'}`;
18
29
  const ttl = clampInt(process.env.SHOMRA_MODEL_CACHE_TTL_MS, 7 * 24 * 3600 * 1000, 0, 365 * 24 * 3600 * 1000);
@@ -39,7 +50,7 @@ export async function modelLookup(url, id, sha, timeoutMs) {
39
50
  if (!res.ok) throw new Error(`HTTP ${res.status}`);
40
51
  const data = await res.json();
41
52
  breakerReset();
42
- if (!modelCacheOff() && data && data.found) { cache[key] = { cachedAt: Date.now(), data }; saveModelCache(cache); }
53
+ if (!modelCacheOff() && data && data.found) { cache[key] = { cachedAt: Date.now(), data }; saveModelCache(pruneModelCache(cache, { ttl })); }
43
54
  return data;
44
55
  } catch (e) {
45
56
  breakerTrip();