@stackmemoryai/stackmemory 1.2.2 → 1.2.4

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 (63) hide show
  1. package/dist/src/cli/codex-sm.js +6 -8
  2. package/dist/src/cli/commands/config.js +0 -81
  3. package/dist/src/cli/commands/context-rehydrate.js +133 -47
  4. package/dist/src/cli/commands/db.js +35 -8
  5. package/dist/src/cli/commands/handoff.js +1 -1
  6. package/dist/src/cli/commands/linear.js +9 -0
  7. package/dist/src/cli/commands/ralph.js +2 -2
  8. package/dist/src/cli/commands/setup.js +2 -2
  9. package/dist/src/cli/commands/signup.js +3 -1
  10. package/dist/src/cli/commands/storage-tier.js +26 -8
  11. package/dist/src/cli/index.js +1 -57
  12. package/dist/src/core/config/feature-flags.js +0 -4
  13. package/dist/src/core/context/dual-stack-manager.js +10 -3
  14. package/dist/src/core/context/frame-database.js +32 -0
  15. package/dist/src/core/context/frame-handoff-manager.js +2 -2
  16. package/dist/src/core/context/{refactored-frame-manager.js → frame-manager.js} +3 -3
  17. package/dist/src/core/context/index.js +2 -2
  18. package/dist/src/core/database/sqlite-adapter.js +161 -1
  19. package/dist/src/core/digest/frame-digest-integration.js +1 -1
  20. package/dist/src/core/digest/index.js +1 -1
  21. package/dist/src/core/execution/parallel-executor.js +5 -1
  22. package/dist/src/core/projects/project-isolation.js +18 -4
  23. package/dist/src/core/security/index.js +2 -0
  24. package/dist/src/core/security/input-sanitizer.js +23 -0
  25. package/dist/src/core/utils/update-checker.js +10 -6
  26. package/dist/src/daemon/daemon-config.js +2 -1
  27. package/dist/src/daemon/services/auto-save-service.js +121 -0
  28. package/dist/src/daemon/services/maintenance-service.js +76 -1
  29. package/dist/src/features/sweep/prompt-builder.js +2 -2
  30. package/dist/src/integrations/linear/config.js +3 -1
  31. package/dist/src/integrations/linear/sync.js +18 -5
  32. package/dist/src/integrations/mcp/handlers/code-execution-handlers.js +33 -7
  33. package/dist/src/integrations/mcp/handlers/cord-handlers.js +397 -0
  34. package/dist/src/integrations/mcp/handlers/index.js +55 -1
  35. package/dist/src/integrations/mcp/handlers/task-handlers.js +55 -12
  36. package/dist/src/integrations/mcp/handlers/team-handlers.js +211 -0
  37. package/dist/src/integrations/mcp/handlers/trace-handlers.js +25 -9
  38. package/dist/src/integrations/mcp/index.js +2 -2
  39. package/dist/src/integrations/mcp/refactored-server.js +31 -10
  40. package/dist/src/integrations/mcp/tool-definitions.js +215 -1
  41. package/dist/src/integrations/ralph/context/context-budget-manager.js +10 -2
  42. package/dist/src/integrations/ralph/context/stackmemory-context-loader.js +54 -22
  43. package/dist/src/integrations/ralph/learning/pattern-learner.js +59 -24
  44. package/dist/src/integrations/ralph/orchestration/multi-loop-orchestrator.js +81 -35
  45. package/dist/src/integrations/ralph/patterns/compounding-engineering-pattern.js +12 -4
  46. package/dist/src/integrations/ralph/patterns/extended-coherence-sessions.js +32 -9
  47. package/dist/src/integrations/ralph/swarm/git-workflow-manager.js +25 -8
  48. package/dist/src/integrations/ralph/swarm/swarm-coordinator.js +17 -5
  49. package/dist/src/integrations/ralph/visualization/ralph-debugger.js +73 -22
  50. package/dist/src/skills/claude-skills.js +0 -102
  51. package/dist/src/utils/hook-installer.js +8 -0
  52. package/package.json +5 -5
  53. package/scripts/install-claude-hooks-auto.js +8 -0
  54. package/templates/claude-hooks/cord-trace.js +225 -0
  55. package/dist/src/core/config/storage-config.js +0 -114
  56. package/dist/src/core/storage/chromadb-adapter.js +0 -379
  57. package/dist/src/integrations/claude-code/enhanced-pre-clear-hooks.js +0 -458
  58. package/dist/src/integrations/ralph/coordination/enhanced-coordination.js +0 -409
  59. package/dist/src/skills/repo-ingestion-skill.js +0 -631
  60. package/templates/claude-hooks/chromadb-wrapper +0 -21
  61. /package/dist/src/core/context/{enhanced-rehydration.js → rehydration.js} +0 -0
  62. /package/dist/src/core/digest/{enhanced-hybrid-digest.js → hybrid-digest.js} +0 -0
  63. /package/dist/src/core/session/{enhanced-handoff.js → handoff.js} +0 -0
@@ -13,7 +13,9 @@ import chalk from "chalk";
13
13
  import * as os from "os";
14
14
  import * as path from "path";
15
15
  function createStorageTierCommand() {
16
- const cmd = new Command("storage").description("Manage two-tier storage system");
16
+ const cmd = new Command("storage").description(
17
+ "Manage two-tier storage system"
18
+ );
17
19
  cmd.command("status").description("Show storage tier status and statistics").option("--json", "Output as JSON").action(async (options) => {
18
20
  try {
19
21
  const storage = await initializeStorage();
@@ -56,10 +58,18 @@ function createStorageTierCommand() {
56
58
  console.log(table.toString());
57
59
  console.log(`
58
60
  \u{1F4C8} Summary:`);
59
- console.log(` Local Usage: ${chalk.cyan(stats.localUsageMB.toFixed(1))} MB`);
60
- console.log(` Compression Ratio: ${chalk.cyan(stats.compressionRatio.toFixed(2))}x`);
61
- console.log(` Pending Migrations: ${chalk.yellow(stats.migrationsPending)}`);
62
- console.log(` Last Migration: ${stats.lastMigration ? chalk.green(stats.lastMigration.toISOString()) : chalk.gray("Never")}`);
61
+ console.log(
62
+ ` Local Usage: ${chalk.cyan(stats.localUsageMB.toFixed(1))} MB`
63
+ );
64
+ console.log(
65
+ ` Compression Ratio: ${chalk.cyan(stats.compressionRatio.toFixed(2))}x`
66
+ );
67
+ console.log(
68
+ ` Pending Migrations: ${chalk.yellow(stats.migrationsPending)}`
69
+ );
70
+ console.log(
71
+ ` Last Migration: ${stats.lastMigration ? chalk.green(stats.lastMigration.toISOString()) : chalk.gray("Never")}`
72
+ );
63
73
  await storage.shutdown();
64
74
  } catch (error) {
65
75
  logger.error("Failed to get storage status", { error });
@@ -75,7 +85,9 @@ function createStorageTierCommand() {
75
85
  console.log("Would migrate based on current triggers");
76
86
  } else {
77
87
  console.log("\u{1F504} Starting migration process...");
78
- console.log("Migration triggered. Use `storage status` to monitor progress.");
88
+ console.log(
89
+ "Migration triggered. Use `storage status` to monitor progress."
90
+ );
79
91
  }
80
92
  await storage.shutdown();
81
93
  } catch (error) {
@@ -87,7 +99,9 @@ function createStorageTierCommand() {
87
99
  cmd.command("cleanup").description("Clean up old data and optimize storage").option("--force", "Force cleanup without confirmation").option("--tier <tier>", "Clean specific tier only").action(async (options) => {
88
100
  try {
89
101
  if (!options.force) {
90
- console.log("\u26A0\uFE0F This will permanently delete old data. Use --force to confirm.");
102
+ console.log(
103
+ "\u26A0\uFE0F This will permanently delete old data. Use --force to confirm."
104
+ );
91
105
  process.exit(1);
92
106
  }
93
107
  const storage = await initializeStorage();
@@ -172,7 +186,11 @@ function getStorageConfig() {
172
186
  },
173
187
  migration: {
174
188
  ...defaultTwoTierConfig.migration,
175
- offlineQueuePath: path.join(homeDir, ".stackmemory", "offline-queue.json")
189
+ offlineQueuePath: path.join(
190
+ homeDir,
191
+ ".stackmemory",
192
+ "offline-queue.json"
193
+ )
176
194
  }
177
195
  };
178
196
  return config;
@@ -61,8 +61,6 @@ import { filterPending } from "../integrations/mcp/pending-utils.js";
61
61
  import { ProjectManager } from "../core/projects/project-manager.js";
62
62
  import { join } from "path";
63
63
  import { existsSync, mkdirSync } from "fs";
64
- import inquirer from "inquirer";
65
- import { enableChromaDB } from "../core/config/storage-config.js";
66
64
  import { createRequire } from "module";
67
65
  import { fileURLToPath } from "url";
68
66
  import * as pathModule from "path";
@@ -104,10 +102,7 @@ program.name("stackmemory").description(
104
102
  ).version(VERSION);
105
103
  program.command("init").description(
106
104
  "Initialize StackMemory in current project (zero-config by default)"
107
- ).option("-i, --interactive", "Interactive mode with configuration prompts").option(
108
- "--chromadb",
109
- "Enable ChromaDB for semantic search (prompts for API key)"
110
- ).option("--daemon", "Start the background daemon after initialization").action(async (options) => {
105
+ ).option("-i, --interactive", "Interactive mode with configuration prompts").option("--daemon", "Start the background daemon after initialization").action(async (options) => {
111
106
  try {
112
107
  const projectRoot = process.cwd();
113
108
  const dbDir = join(projectRoot, ".stackmemory");
@@ -120,28 +115,6 @@ program.command("init").description(
120
115
  if (!existsSync(dbDir)) {
121
116
  mkdirSync(dbDir, { recursive: true });
122
117
  }
123
- if (options.chromadb) {
124
- await promptAndEnableChromaDB();
125
- } else if (options.interactive && process.stdin.isTTY) {
126
- console.log(chalk.cyan("\nStorage Configuration"));
127
- console.log(
128
- chalk.gray("SQLite (default) is fast and requires no setup.")
129
- );
130
- console.log(
131
- chalk.gray("ChromaDB adds semantic search but requires an API key.\n")
132
- );
133
- const { enableChroma } = await inquirer.prompt([
134
- {
135
- type: "confirm",
136
- name: "enableChroma",
137
- message: "Enable ChromaDB for semantic search?",
138
- default: false
139
- }
140
- ]);
141
- if (enableChroma) {
142
- await promptAndEnableChromaDB();
143
- }
144
- }
145
118
  const dbPath = join(dbDir, "context.db");
146
119
  if (!isTestEnv()) {
147
120
  const db = await openDatabase(dbPath);
@@ -195,35 +168,6 @@ program.command("init").description(
195
168
  process.exit(1);
196
169
  }
197
170
  });
198
- async function promptAndEnableChromaDB() {
199
- const answers = await inquirer.prompt([
200
- {
201
- type: "password",
202
- name: "apiKey",
203
- message: "Enter your ChromaDB API key:",
204
- validate: (input) => {
205
- if (!input || input.trim().length === 0) {
206
- return "API key is required for ChromaDB";
207
- }
208
- return true;
209
- }
210
- },
211
- {
212
- type: "input",
213
- name: "apiUrl",
214
- message: "ChromaDB API URL (press Enter for default):",
215
- default: "https://api.trychroma.com"
216
- }
217
- ]);
218
- enableChromaDB({
219
- apiKey: answers.apiKey,
220
- apiUrl: answers.apiUrl
221
- });
222
- console.log(chalk.green("[OK] ChromaDB enabled for semantic search."));
223
- console.log(
224
- chalk.gray("API key saved to ~/.stackmemory/storage-config.json")
225
- );
226
- }
227
171
  program.command("status").description("Show current StackMemory status").option("--all", "Show all active frames across sessions").option("--project", "Show all active frames in current project").option("--session <id>", "Show frames for specific session").action(async (options) => {
228
172
  return trace.command("stackmemory-status", options, async () => {
229
173
  try {
@@ -11,8 +11,6 @@ function isFeatureEnabled(feature) {
11
11
  switch (feature) {
12
12
  case "linear":
13
13
  return process.env["STACKMEMORY_LINEAR"] !== "false" && (!!process.env["LINEAR_API_KEY"] || !!process.env["LINEAR_OAUTH_TOKEN"]);
14
- case "chromadb":
15
- return process.env["STACKMEMORY_CHROMADB"] === "true";
16
14
  case "aiSummaries":
17
15
  return process.env["STACKMEMORY_AI"] !== "false" && (!!process.env["ANTHROPIC_API_KEY"] || !!process.env["OPENAI_API_KEY"]);
18
16
  case "skills":
@@ -29,7 +27,6 @@ function getFeatureFlags() {
29
27
  return {
30
28
  core: true,
31
29
  linear: isFeatureEnabled("linear"),
32
- chromadb: isFeatureEnabled("chromadb"),
33
30
  aiSummaries: isFeatureEnabled("aiSummaries"),
34
31
  skills: isFeatureEnabled("skills"),
35
32
  ralph: isFeatureEnabled("ralph"),
@@ -46,7 +43,6 @@ function logFeatureStatus() {
46
43
  console.log(
47
44
  ` Linear: ${flags.linear ? "enabled" : "disabled (no API key)"}`
48
45
  );
49
- console.log(` ChromaDB: ${flags.chromadb ? "enabled" : "disabled"}`);
50
46
  console.log(
51
47
  ` AI Summaries: ${flags.aiSummaries ? "enabled" : "disabled (no API key)"}`
52
48
  );
@@ -99,9 +99,16 @@ class DualStackManager {
99
99
  )
100
100
  `;
101
101
  if (this.adapter.isConnected()) {
102
- await this.adapter.execute?.(createStackContextsTable) || this.executeSchemaQuery(createStackContextsTable);
103
- await this.adapter.execute?.(createHandoffRequestsTable) || this.executeSchemaQuery(createHandoffRequestsTable);
104
- await this.adapter.execute?.(createStackSyncLogTable) || this.executeSchemaQuery(createStackSyncLogTable);
102
+ const adapterAny = this.adapter;
103
+ if (!await adapterAny.execute?.(createStackContextsTable)) {
104
+ this.executeSchemaQuery(createStackContextsTable);
105
+ }
106
+ if (!await adapterAny.execute?.(createHandoffRequestsTable)) {
107
+ this.executeSchemaQuery(createHandoffRequestsTable);
108
+ }
109
+ if (!await adapterAny.execute?.(createStackSyncLogTable)) {
110
+ this.executeSchemaQuery(createStackSyncLogTable);
111
+ }
105
112
  }
106
113
  await this.adapter.commitTransaction();
107
114
  logger.info("Dual stack schema initialized successfully");
@@ -56,6 +56,7 @@ class FrameDatabase {
56
56
  created_at INTEGER NOT NULL DEFAULT (unixepoch()),
57
57
  closed_at INTEGER,
58
58
  retention_policy TEXT DEFAULT 'default',
59
+ importance_score REAL DEFAULT 0.5,
59
60
  FOREIGN KEY (parent_frame_id) REFERENCES frames(frame_id)
60
61
  );
61
62
  `);
@@ -90,6 +91,12 @@ class FrameDatabase {
90
91
  );
91
92
  } catch {
92
93
  }
94
+ try {
95
+ this.db.exec(
96
+ "ALTER TABLE frames ADD COLUMN importance_score REAL DEFAULT 0.5"
97
+ );
98
+ } catch {
99
+ }
93
100
  this.db.exec(`
94
101
  CREATE INDEX IF NOT EXISTS idx_frames_run ON frames(run_id);
95
102
  CREATE INDEX IF NOT EXISTS idx_frames_project ON frames(project_id);
@@ -99,6 +106,7 @@ class FrameDatabase {
99
106
  CREATE INDEX IF NOT EXISTS idx_frames_project_state ON frames(project_id, state);
100
107
  CREATE INDEX IF NOT EXISTS idx_frames_project_created ON frames(project_id, created_at DESC);
101
108
  CREATE INDEX IF NOT EXISTS idx_frames_retention_created ON frames(retention_policy, created_at);
109
+ CREATE INDEX IF NOT EXISTS idx_frames_gc_score ON frames(state, retention_policy, importance_score ASC, created_at ASC);
102
110
  CREATE INDEX IF NOT EXISTS idx_events_frame ON events(frame_id);
103
111
  CREATE INDEX IF NOT EXISTS idx_events_seq ON events(frame_id, seq);
104
112
  CREATE INDEX IF NOT EXISTS idx_anchors_frame ON anchors(frame_id);
@@ -142,6 +150,30 @@ class FrameDatabase {
142
150
  -- Set initial schema version if not exists
143
151
  INSERT OR IGNORE INTO schema_version (version) VALUES (1);
144
152
  `);
153
+ this.db.exec(`
154
+ CREATE TABLE IF NOT EXISTS cord_tasks (
155
+ task_id TEXT PRIMARY KEY,
156
+ parent_id TEXT,
157
+ project_id TEXT NOT NULL,
158
+ run_id TEXT NOT NULL,
159
+ goal TEXT NOT NULL,
160
+ prompt TEXT NOT NULL DEFAULT '',
161
+ result TEXT,
162
+ status TEXT NOT NULL DEFAULT 'pending'
163
+ CHECK (status IN ('pending','active','completed','blocked','asked')),
164
+ context_mode TEXT NOT NULL DEFAULT 'spawn'
165
+ CHECK (context_mode IN ('spawn','fork','ask')),
166
+ blocked_by TEXT NOT NULL DEFAULT '[]',
167
+ depth INTEGER NOT NULL DEFAULT 0,
168
+ created_at INTEGER NOT NULL DEFAULT (unixepoch()),
169
+ completed_at INTEGER,
170
+ FOREIGN KEY (parent_id) REFERENCES cord_tasks(task_id)
171
+ );
172
+ CREATE INDEX IF NOT EXISTS idx_cord_tasks_project ON cord_tasks(project_id);
173
+ CREATE INDEX IF NOT EXISTS idx_cord_tasks_parent ON cord_tasks(parent_id);
174
+ CREATE INDEX IF NOT EXISTS idx_cord_tasks_status ON cord_tasks(status);
175
+ CREATE INDEX IF NOT EXISTS idx_cord_tasks_project_status ON cord_tasks(project_id, status);
176
+ `);
145
177
  logger.info("Frame database schema initialized");
146
178
  } catch (error) {
147
179
  throw new DatabaseError(
@@ -583,12 +583,12 @@ class FrameHandoffManager {
583
583
  ErrorCode.RESOURCE_NOT_FOUND
584
584
  );
585
585
  }
586
- const self = this;
586
+ const activeHandoffs = this.activeHandoffs;
587
587
  return {
588
588
  async *[Symbol.asyncIterator]() {
589
589
  let lastStatus = progress.status;
590
590
  while (lastStatus !== "completed" && lastStatus !== "failed" && lastStatus !== "cancelled") {
591
- const currentProgress = self.activeHandoffs.get(requestId);
591
+ const currentProgress = activeHandoffs.get(requestId);
592
592
  if (currentProgress && currentProgress.status !== lastStatus) {
593
593
  lastStatus = currentProgress.status;
594
594
  yield currentProgress;
@@ -18,7 +18,7 @@ import { FrameDatabase } from "./frame-database.js";
18
18
  import { FrameStack } from "./frame-stack.js";
19
19
  import { FrameDigestGenerator } from "./frame-digest.js";
20
20
  import { FrameRecovery } from "./frame-recovery.js";
21
- class RefactoredFrameManager {
21
+ class FrameManager {
22
22
  frameDb;
23
23
  frameStack;
24
24
  digestGenerator;
@@ -53,7 +53,7 @@ class RefactoredFrameManager {
53
53
  this.frameRecovery = new FrameRecovery(db);
54
54
  this.frameRecovery.setCurrentRunId(this.currentRunId);
55
55
  this.frameDb.initSchema();
56
- logger.info("RefactoredFrameManager initialized", {
56
+ logger.info("FrameManager initialized", {
57
57
  projectId: this.projectId,
58
58
  runId: this.currentRunId,
59
59
  sessionId: this.sessionId
@@ -756,5 +756,5 @@ class RefactoredFrameManager {
756
756
  }
757
757
  }
758
758
  export {
759
- RefactoredFrameManager
759
+ FrameManager
760
760
  };
@@ -2,7 +2,7 @@ import { fileURLToPath as __fileURLToPath } from 'url';
2
2
  import { dirname as __pathDirname } from 'path';
3
3
  const __filename = __fileURLToPath(import.meta.url);
4
4
  const __dirname = __pathDirname(__filename);
5
- import { RefactoredFrameManager } from "./refactored-frame-manager.js";
5
+ import { FrameManager } from "./frame-manager.js";
6
6
  import { FrameDatabase } from "./frame-database.js";
7
7
  import { FrameStack } from "./frame-stack.js";
8
8
  import { FrameDigestGenerator } from "./frame-digest.js";
@@ -16,7 +16,7 @@ import {
16
16
  export {
17
17
  FrameDatabase,
18
18
  FrameDigestGenerator,
19
- RefactoredFrameManager as FrameManager,
19
+ FrameManager,
20
20
  FrameRecovery,
21
21
  FrameStack,
22
22
  frameLifecycleHooks,
@@ -237,6 +237,10 @@ class SQLiteAdapter extends FeatureAwareDatabaseAdapter {
237
237
  "FTS5 index populated from existing frames (migration v1\u2192v2)"
238
238
  );
239
239
  }
240
+ if (version < 3) {
241
+ this.db.prepare("INSERT OR REPLACE INTO schema_version (version) VALUES (?)").run(3);
242
+ logger.info("Schema migration v2\u2192v3: GC importance_score support");
243
+ }
240
244
  }
241
245
  /**
242
246
  * Initialize sqlite-vec for vector search
@@ -305,6 +309,7 @@ class SQLiteAdapter extends FeatureAwareDatabaseAdapter {
305
309
  const retentionDays = options.retentionDays ?? 90;
306
310
  const batchSize = options.batchSize ?? 100;
307
311
  const dryRun = options.dryRun ?? false;
312
+ const protectedRunIds = options.protectedRunIds ?? [];
308
313
  const nowSec = Math.floor(Date.now() / 1e3);
309
314
  const defaultCutoff = nowSec - retentionDays * 86400;
310
315
  const ttl30dCutoff = nowSec - 30 * 86400;
@@ -317,8 +322,17 @@ class SQLiteAdapter extends FeatureAwareDatabaseAdapter {
317
322
  OR (retention_policy = 'ttl_7d' AND created_at < ?)
318
323
  )
319
324
  AND retention_policy != 'keep_forever'
325
+ AND state = 'closed'
326
+ AND run_id NOT IN (SELECT value FROM json_each(?))
327
+ ORDER BY importance_score ASC, created_at ASC
320
328
  LIMIT ?`
321
- ).all(defaultCutoff, ttl30dCutoff, ttl7dCutoff, batchSize);
329
+ ).all(
330
+ defaultCutoff,
331
+ ttl30dCutoff,
332
+ ttl7dCutoff,
333
+ JSON.stringify(protectedRunIds),
334
+ batchSize
335
+ );
322
336
  const frameIds = candidates.map((r) => r.frame_id);
323
337
  if (frameIds.length === 0) {
324
338
  return {
@@ -388,6 +402,69 @@ class SQLiteAdapter extends FeatureAwareDatabaseAdapter {
388
402
  ftsEntriesDeleted: frameIds.length
389
403
  };
390
404
  }
405
+ /**
406
+ * Compute importance score for a single frame.
407
+ * Score range: [0.0, 1.0] — higher means more important, less likely to be GC'd.
408
+ */
409
+ computeImportanceScore(frameId) {
410
+ if (!this.db)
411
+ throw new DatabaseError(
412
+ "Database not connected",
413
+ ErrorCode.DB_CONNECTION_FAILED
414
+ );
415
+ const frame = this.db.prepare(
416
+ "SELECT frame_id, digest_text, created_at FROM frames WHERE frame_id = ?"
417
+ ).get(frameId);
418
+ if (!frame) return 0.3;
419
+ let score = 0.3;
420
+ const decisionCount = this.db.prepare(
421
+ "SELECT COUNT(*) as count FROM anchors WHERE frame_id = ? AND type = 'DECISION'"
422
+ ).get(frameId).count;
423
+ if (decisionCount > 0) score += 0.15;
424
+ const eventCount = this.db.prepare("SELECT COUNT(*) as count FROM events WHERE frame_id = ?").get(frameId).count;
425
+ if (eventCount > 3) score += 0.1;
426
+ if (frame.digest_text) score += 0.15;
427
+ const childCount = this.db.prepare(
428
+ "SELECT COUNT(*) as count FROM frames WHERE parent_frame_id = ?"
429
+ ).get(frameId).count;
430
+ if (childCount > 0) score += 0.1;
431
+ const nowSec = Math.floor(Date.now() / 1e3);
432
+ if (nowSec - frame.created_at < 86400) score += 0.1;
433
+ return Math.round(Math.min(score, 1) * 100) / 100;
434
+ }
435
+ /**
436
+ * Recompute importance scores for frames still at default score (0.5).
437
+ * Processes oldest frames first in batches.
438
+ * Returns count of frames updated.
439
+ */
440
+ recomputeImportanceScores(batchSize = 100) {
441
+ if (!this.db)
442
+ throw new DatabaseError(
443
+ "Database not connected",
444
+ ErrorCode.DB_CONNECTION_FAILED
445
+ );
446
+ const frames = this.db.prepare(
447
+ "SELECT frame_id FROM frames WHERE importance_score = 0.5 ORDER BY created_at ASC LIMIT ?"
448
+ ).all(batchSize);
449
+ const updateStmt = this.db.prepare(
450
+ "UPDATE frames SET importance_score = ? WHERE frame_id = ?"
451
+ );
452
+ let updated = 0;
453
+ for (const { frame_id } of frames) {
454
+ const score = this.computeImportanceScore(frame_id);
455
+ if (score !== 0.5) {
456
+ updateStmt.run(score, frame_id);
457
+ updated++;
458
+ }
459
+ }
460
+ if (updated > 0) {
461
+ logger.info("Recomputed importance scores", {
462
+ checked: frames.length,
463
+ updated
464
+ });
465
+ }
466
+ return updated;
467
+ }
391
468
  async migrateSchema(targetVersion) {
392
469
  if (!this.db)
393
470
  throw new DatabaseError(
@@ -1252,6 +1329,89 @@ class SQLiteAdapter extends FeatureAwareDatabaseAdapter {
1252
1329
  }
1253
1330
  return Buffer.from(JSON.stringify(data, null, 2));
1254
1331
  }
1332
+ /**
1333
+ * Get recent frames from other run_ids within the same project.
1334
+ * Used by team tools to read cross-agent context.
1335
+ */
1336
+ async getRecentFramesExcludingRun(projectId, excludeRunId, opts) {
1337
+ if (!this.db)
1338
+ throw new DatabaseError(
1339
+ "Database not connected",
1340
+ ErrorCode.DB_CONNECTION_FAILED
1341
+ );
1342
+ const limit = opts?.limit ?? 10;
1343
+ const params = [projectId, excludeRunId];
1344
+ let whereExtra = "";
1345
+ if (opts?.since) {
1346
+ whereExtra += " AND created_at > ?";
1347
+ params.push(Math.floor(opts.since / 1e3));
1348
+ }
1349
+ if (opts?.types && opts.types.length > 0) {
1350
+ const placeholders = opts.types.map(() => "?").join(",");
1351
+ whereExtra += ` AND type IN (${placeholders})`;
1352
+ params.push(...opts.types);
1353
+ }
1354
+ params.push(limit);
1355
+ const rows = this.db.prepare(
1356
+ `SELECT * FROM frames
1357
+ WHERE project_id = ? AND run_id != ?${whereExtra}
1358
+ ORDER BY created_at DESC
1359
+ LIMIT ?`
1360
+ ).all(...params);
1361
+ const frameIds = rows.map((r) => r.frame_id);
1362
+ const anchorsByFrame = /* @__PURE__ */ new Map();
1363
+ if (frameIds.length > 0) {
1364
+ const placeholders = frameIds.map(() => "?").join(",");
1365
+ const anchorRows = this.db.prepare(
1366
+ `SELECT * FROM anchors WHERE frame_id IN (${placeholders})
1367
+ ORDER BY priority DESC, created_at ASC`
1368
+ ).all(...frameIds);
1369
+ for (const row of anchorRows) {
1370
+ const list = anchorsByFrame.get(row.frame_id) || [];
1371
+ list.push({ ...row, metadata: JSON.parse(row.metadata || "{}") });
1372
+ anchorsByFrame.set(row.frame_id, list);
1373
+ }
1374
+ }
1375
+ return rows.map((row) => ({
1376
+ ...row,
1377
+ inputs: JSON.parse(row.inputs || "{}"),
1378
+ outputs: JSON.parse(row.outputs || "{}"),
1379
+ digest_json: JSON.parse(row.digest_json || "{}"),
1380
+ anchors: anchorsByFrame.get(row.frame_id) || []
1381
+ }));
1382
+ }
1383
+ /**
1384
+ * Get anchors explicitly shared for team visibility.
1385
+ * Finds anchors where metadata contains `"shared":true`.
1386
+ */
1387
+ async getSharedAnchors(projectId, opts) {
1388
+ if (!this.db)
1389
+ throw new DatabaseError(
1390
+ "Database not connected",
1391
+ ErrorCode.DB_CONNECTION_FAILED
1392
+ );
1393
+ const limit = opts?.limit ?? 20;
1394
+ const params = [projectId];
1395
+ let whereExtra = "";
1396
+ if (opts?.since) {
1397
+ whereExtra += " AND a.created_at > ?";
1398
+ params.push(Math.floor(opts.since / 1e3));
1399
+ }
1400
+ params.push(limit);
1401
+ const rows = this.db.prepare(
1402
+ `SELECT a.*, f.name as frame_name, f.run_id
1403
+ FROM anchors a
1404
+ JOIN frames f ON a.frame_id = f.frame_id
1405
+ WHERE f.project_id = ?
1406
+ AND a.metadata LIKE '%"shared":true%'${whereExtra}
1407
+ ORDER BY a.priority DESC, a.created_at DESC
1408
+ LIMIT ?`
1409
+ ).all(...params);
1410
+ return rows.map((row) => ({
1411
+ ...row,
1412
+ metadata: JSON.parse(row.metadata || "{}")
1413
+ }));
1414
+ }
1255
1415
  async importData(data, format, options) {
1256
1416
  if (!this.db)
1257
1417
  throw new DatabaseError(
@@ -2,7 +2,7 @@ import { fileURLToPath as __fileURLToPath } from 'url';
2
2
  import { dirname as __pathDirname } from 'path';
3
3
  const __filename = __fileURLToPath(import.meta.url);
4
4
  const __dirname = __pathDirname(__filename);
5
- import { EnhancedHybridDigestGenerator } from "./enhanced-hybrid-digest.js";
5
+ import { EnhancedHybridDigestGenerator } from "./hybrid-digest.js";
6
6
  import { logger } from "../monitoring/logger.js";
7
7
  class FrameDigestIntegration {
8
8
  frameManager;
@@ -4,5 +4,5 @@ const __filename = __fileURLToPath(import.meta.url);
4
4
  const __dirname = __pathDirname(__filename);
5
5
  export * from "./types.js";
6
6
  export * from "./hybrid-digest-generator.js";
7
- export * from "./enhanced-hybrid-digest.js";
7
+ export * from "./hybrid-digest.js";
8
8
  export * from "./frame-digest-integration.js";
@@ -106,7 +106,11 @@ class ParallelExecutor extends EventEmitter {
106
106
  taskId,
107
107
  error: lastError.message
108
108
  });
109
- this.emit("task-retry", { taskId, attempt: attempts, error: lastError });
109
+ this.emit("task-retry", {
110
+ taskId,
111
+ attempt: attempts,
112
+ error: lastError
113
+ });
110
114
  if (attempts < maxRetries) {
111
115
  await this.delay(Math.pow(2, attempts) * 1e3);
112
116
  }
@@ -25,9 +25,20 @@ class ProjectIsolationManager {
25
25
  try {
26
26
  const remoteUrl = this.getGitRemoteUrl(projectRoot);
27
27
  const gitInfo = this.parseGitRemote(remoteUrl);
28
- const projectId = this.createStableProjectId(gitInfo.organization, gitInfo.repository);
29
- const workspaceFilter = this.createWorkspaceFilter(gitInfo.organization, gitInfo.repository, projectRoot);
30
- const linearConfig = this.getLinearConfiguration(gitInfo.organization, gitInfo.repository, projectRoot);
28
+ const projectId = this.createStableProjectId(
29
+ gitInfo.organization,
30
+ gitInfo.repository
31
+ );
32
+ const workspaceFilter = this.createWorkspaceFilter(
33
+ gitInfo.organization,
34
+ gitInfo.repository,
35
+ projectRoot
36
+ );
37
+ const linearConfig = this.getLinearConfiguration(
38
+ gitInfo.organization,
39
+ gitInfo.repository,
40
+ projectRoot
41
+ );
31
42
  const identification = {
32
43
  projectId,
33
44
  organization: gitInfo.organization,
@@ -45,7 +56,10 @@ class ProjectIsolationManager {
45
56
  });
46
57
  return identification;
47
58
  } catch (error) {
48
- logger.warn("Could not determine git remote, using fallback identification", { error });
59
+ logger.warn(
60
+ "Could not determine git remote, using fallback identification",
61
+ { error }
62
+ );
49
63
  const fallback = this.createFallbackIdentification(projectRoot);
50
64
  this.projectCache.set(cacheKey, fallback);
51
65
  return fallback;
@@ -15,6 +15,7 @@ import {
15
15
  validateInput,
16
16
  createAggregateSchema,
17
17
  validateShellArg,
18
+ validateShellCommand,
18
19
  safeJsonParse
19
20
  } from "./input-sanitizer.js";
20
21
  export {
@@ -30,5 +31,6 @@ export {
30
31
  sanitizeIdentifier,
31
32
  validateInput,
32
33
  validateShellArg,
34
+ validateShellCommand,
33
35
  validateTableName
34
36
  };
@@ -280,6 +280,28 @@ function createAggregateSchema(allowedFields) {
280
280
  limit: z.number().int().min(1).max(1e3).optional()
281
281
  });
282
282
  }
283
+ const DANGEROUS_SHELL_PATTERNS = [
284
+ /\brm\s+(-[a-zA-Z]*r[a-zA-Z]*f|--recursive)\b/i,
285
+ // rm -rf, rm -fr, rm --recursive
286
+ /\brm\s+-[a-zA-Z]*r\b/i,
287
+ // rm -r (any flag combo with r)
288
+ /\bmkfs\b/i,
289
+ /\bdd\s+if=/i,
290
+ /\b:\(\)\s*\{/i
291
+ // fork bomb
292
+ ];
293
+ function validateShellCommand(command) {
294
+ for (const pattern of DANGEROUS_SHELL_PATTERNS) {
295
+ if (pattern.test(command)) {
296
+ throw new ValidationError(
297
+ `Blocked dangerous shell command: ${command.substring(0, 80)}`,
298
+ ErrorCode.VALIDATION_FAILED,
299
+ { reason: "dangerous_command" }
300
+ );
301
+ }
302
+ }
303
+ return command;
304
+ }
283
305
  function validateShellArg(arg) {
284
306
  if (!arg) return "";
285
307
  const dangerousChars = /[;&|`$(){}[\]<>!#*?~\n\r]/;
@@ -316,5 +338,6 @@ export {
316
338
  sanitizeIdentifier,
317
339
  validateInput,
318
340
  validateShellArg,
341
+ validateShellCommand,
319
342
  validateTableName
320
343
  };
@@ -63,12 +63,16 @@ class UpdateChecker {
63
63
  static async fetchLatestVersion() {
64
64
  try {
65
65
  const fetchVersion = async () => {
66
- const output = execFileSync("npm", ["view", this.PACKAGE_NAME, "version"], {
67
- encoding: "utf-8",
68
- stdio: ["pipe", "pipe", "ignore"],
69
- timeout: 5e3
70
- // 5 second timeout
71
- }).trim();
66
+ const output = execFileSync(
67
+ "npm",
68
+ ["view", this.PACKAGE_NAME, "version"],
69
+ {
70
+ encoding: "utf-8",
71
+ stdio: ["pipe", "pipe", "ignore"],
72
+ timeout: 5e3
73
+ // 5 second timeout
74
+ }
75
+ ).trim();
72
76
  return output;
73
77
  };
74
78
  return await gracefulDegrade(
@@ -30,8 +30,9 @@ const DEFAULT_DAEMON_CONFIG = {
30
30
  ftsRebuildInterval: 24,
31
31
  // hours
32
32
  embeddingBatchSize: 50,
33
- vacuumInterval: 168
33
+ vacuumInterval: 168,
34
34
  // weekly
35
+ gcIntervalSeconds: 60
35
36
  },
36
37
  memory: {
37
38
  enabled: true,