@stackmemoryai/stackmemory 1.10.5 → 1.14.0
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/LICENSE +131 -64
- package/README.md +107 -24
- package/bin/claude-sm +16 -1
- package/bin/claude-smd +16 -1
- package/bin/codex-smd +16 -1
- package/bin/gemini-sm +16 -1
- package/bin/hermes-sm +21 -0
- package/bin/hermes-smd +21 -0
- package/bin/opencode-sm +16 -1
- package/dist/src/cli/claude-sm.js +266 -84
- package/dist/src/cli/codex-sm.js +225 -33
- package/dist/src/cli/commands/bench.js +209 -2
- package/dist/src/cli/commands/brain.js +206 -0
- package/dist/src/cli/commands/cache.js +126 -0
- package/dist/src/cli/commands/company-os.js +184 -0
- package/dist/src/cli/commands/context.js +5 -0
- package/dist/src/cli/commands/daemon.js +41 -0
- package/dist/src/cli/commands/handoff.js +40 -9
- package/dist/src/cli/commands/onboard.js +70 -3
- package/dist/src/cli/commands/operator.js +127 -0
- package/dist/src/cli/commands/optimize.js +117 -0
- package/dist/src/cli/commands/orchestrate.js +232 -5
- package/dist/src/cli/commands/orchestrator.js +315 -26
- package/dist/src/cli/commands/pack.js +322 -0
- package/dist/src/cli/commands/patterns.js +254 -0
- package/dist/src/cli/commands/portal.js +161 -0
- package/dist/src/cli/commands/scaffold.js +92 -0
- package/dist/src/cli/commands/search.js +40 -1
- package/dist/src/cli/commands/setup.js +178 -11
- package/dist/src/cli/commands/skills.js +10 -1
- package/dist/src/cli/commands/state.js +265 -0
- package/dist/src/cli/commands/sync.js +253 -0
- package/dist/src/cli/commands/tasks.js +130 -1
- package/dist/src/cli/commands/vision.js +221 -0
- package/dist/src/cli/gemini-sm.js +19 -29
- package/dist/src/cli/hermes-sm.js +224 -0
- package/dist/src/cli/index.js +105 -39
- package/dist/src/cli/opencode-sm.js +38 -21
- package/dist/src/cli/utils/determinism-watcher.js +66 -0
- package/dist/src/cli/utils/real-cli-bin.js +116 -0
- package/dist/src/core/brain/brain-store.js +187 -0
- package/dist/src/core/brain/brain-sync.js +193 -0
- package/dist/src/core/brain/index.js +78 -0
- package/dist/src/core/brain/types.js +10 -0
- package/dist/src/core/cache/content-cache.js +238 -0
- package/dist/src/{integrations/diffmem → core/cache}/index.js +5 -5
- package/dist/src/core/cache/token-estimator.js +39 -0
- package/dist/src/core/config/feature-flags.js +2 -6
- package/dist/src/core/context/frame-database.js +79 -27
- package/dist/src/core/context/recursive-context-manager.js +1 -1
- package/dist/src/core/context/rehydration.js +2 -1
- package/dist/src/core/cross-search/cross-project-search.js +269 -0
- package/dist/src/core/cross-search/index.js +10 -0
- package/dist/src/core/database/sqlite-adapter.js +14 -84
- package/dist/src/core/extensions/provider-adapter.js +5 -0
- package/dist/src/core/models/model-router.js +54 -2
- package/dist/src/core/models/provider-pricing.js +58 -4
- package/dist/src/core/monitoring/logger.js +2 -1
- package/dist/src/core/optimization/trace-optimizer.js +413 -0
- package/dist/src/core/patterns/index.js +22 -0
- package/dist/src/core/patterns/pattern-applier.js +39 -0
- package/dist/src/core/patterns/pattern-observer.js +157 -0
- package/dist/src/core/patterns/pattern-store.js +259 -0
- package/dist/src/core/patterns/types.js +19 -0
- package/dist/src/core/provenance/confidence-scorer.js +128 -0
- package/dist/src/core/provenance/index.js +40 -0
- package/dist/src/core/provenance/provenance-store.js +194 -0
- package/dist/src/core/provenance/types.js +82 -0
- package/dist/src/core/retrieval/llm-context-retrieval.js +5 -4
- package/dist/src/core/retrieval/unified-context-assembler.js +11 -66
- package/dist/src/core/session/project-handoff.js +64 -0
- package/dist/src/core/session/session-manager.js +28 -0
- package/dist/src/core/shared-state/canonical-store.js +564 -0
- package/dist/src/core/skill-packs/index.js +18 -0
- package/dist/src/core/skill-packs/parser.js +42 -0
- package/dist/src/core/skill-packs/registry.js +224 -0
- package/dist/src/core/skill-packs/types.js +79 -0
- package/dist/src/core/storage/cloud-sync-manager.js +116 -0
- package/dist/src/core/storage/cloud-sync.js +574 -0
- package/dist/src/core/storage/two-tier-storage.js +5 -1
- package/dist/src/core/tasks/master-tasks-template.js +43 -0
- package/dist/src/core/tasks/md-task-parser.js +138 -0
- package/dist/src/core/trace/trace-event-store.js +282 -0
- package/dist/src/core/vision/index.js +27 -0
- package/dist/src/core/vision/signals.js +79 -0
- package/dist/src/core/vision/types.js +22 -0
- package/dist/src/core/vision/vision-file.js +146 -0
- package/dist/src/core/vision/vision-loop.js +220 -0
- package/dist/src/core/wiki/wiki-compiler.js +103 -1
- package/dist/src/daemon/daemon-config.js +52 -0
- package/dist/src/daemon/services/desire-path-service.js +566 -0
- package/dist/src/daemon/services/github-service.js +126 -0
- package/dist/src/daemon/services/research-stream-service.js +320 -0
- package/dist/src/daemon/services/telemetry-service.js +192 -0
- package/dist/src/daemon/unified-daemon.js +58 -1
- package/dist/src/features/browser/cli-browser-agent.js +417 -0
- package/dist/src/features/browser/stagehand-workflows.js +578 -0
- package/dist/src/features/operator/adapter-factory.js +62 -0
- package/dist/src/features/operator/browser-adapter.js +109 -0
- package/dist/src/features/operator/desktop-adapter.js +125 -0
- package/dist/src/features/operator/index.js +39 -0
- package/dist/src/features/operator/llm-decision.js +137 -0
- package/dist/src/features/operator/operator-logger.js +92 -0
- package/dist/src/features/operator/overnight-runner.js +327 -0
- package/dist/src/features/operator/screen-adapter.js +91 -0
- package/dist/src/features/operator/session-manager.js +127 -0
- package/dist/src/features/operator/state-machine.js +227 -0
- package/dist/src/features/operator/task-queue.js +81 -0
- package/dist/src/features/portal/index.js +26 -0
- package/dist/src/features/portal/server.js +240 -0
- package/dist/src/features/portal/types.js +14 -0
- package/dist/src/features/portal/ui.js +195 -0
- package/dist/src/features/sweep/pty-wrapper.js +13 -5
- package/dist/src/features/tasks/task-aware-context.js +2 -1
- package/dist/src/features/tui/simple-monitor.js +0 -23
- package/dist/src/features/tui/swarm-monitor.js +8 -66
- package/dist/src/features/web/client/hooks/use-socket.js +12 -0
- package/dist/src/{core/merge/index.js → features/web/client/lib/utils.js} +8 -4
- package/dist/src/features/web/client/next-env.d.js +4 -0
- package/dist/src/features/web/client/stores/session-store.js +12 -0
- package/dist/src/features/web/server/gcp-billing.js +76 -0
- package/dist/src/features/web/server/index.js +10 -0
- package/dist/src/features/web/server/spend-calculator.js +228 -0
- package/dist/src/hooks/schemas.js +6 -1
- package/dist/src/integrations/anthropic/client.js +3 -2
- package/dist/src/integrations/claude-code/agent-bridge.js +0 -3
- package/dist/src/integrations/claude-code/subagent-client.js +307 -11
- package/dist/src/integrations/claude-code/task-coordinator.js +2 -1
- package/dist/src/integrations/github/pr-state.js +158 -0
- package/dist/src/integrations/linear/client.js +4 -1
- package/dist/src/integrations/linear/webhook-retry.js +196 -0
- package/dist/src/integrations/linear/webhook-server.js +18 -22
- package/dist/src/integrations/mcp/handlers/cloud-sync-handlers.js +101 -0
- package/dist/src/integrations/mcp/handlers/index.js +40 -84
- package/dist/src/integrations/mcp/server.js +542 -641
- package/dist/src/integrations/mcp/tool-alias-registry.js +297 -0
- package/dist/src/integrations/mcp/tool-definitions.js +152 -682
- package/dist/src/mcp/stackmemory-mcp-server.js +571 -231
- package/dist/src/orchestrators/multimodal/determinism.js +244 -0
- package/dist/src/orchestrators/multimodal/harness.js +149 -78
- package/dist/src/orchestrators/multimodal/providers.js +44 -3
- package/dist/src/skills/recursive-agent-orchestrator.js +2 -4
- package/dist/src/utils/hook-installer.js +0 -8
- package/dist/src/utils/process-cleanup.js +1 -7
- package/docs/README.md +42 -0
- package/docs/guides/README_INSTALL.md +208 -0
- package/package.json +27 -9
- package/packs/coding/python-fastapi/instructions.md +60 -0
- package/packs/coding/python-fastapi/pack.yaml +28 -0
- package/packs/coding/typescript-react/instructions.md +47 -0
- package/packs/coding/typescript-react/pack.yaml +28 -0
- package/packs/core/commands/capture.md +32 -0
- package/packs/core/commands/learn.md +73 -0
- package/packs/core/commands/next.md +36 -0
- package/packs/core/commands/restart.md +58 -0
- package/packs/core/commands/restore.md +29 -0
- package/packs/core/commands/start.md +57 -0
- package/packs/core/commands/stop.md +65 -0
- package/packs/core/commands/summary.md +40 -0
- package/packs/core/manifest.json +24 -0
- package/packs/ops/decision-recovery/instructions.md +65 -0
- package/packs/ops/decision-recovery/pack.yaml +89 -0
- package/scripts/claude-code-wrapper.sh +11 -0
- package/scripts/claude-sm-setup.sh +12 -1
- package/scripts/codex-wrapper.sh +11 -0
- package/scripts/git-hooks/branch-context-manager.sh +11 -0
- package/scripts/git-hooks/post-checkout-stackmemory.sh +11 -0
- package/scripts/git-hooks/post-commit-stackmemory.sh +11 -0
- package/scripts/git-hooks/pre-commit-stackmemory.sh +11 -0
- package/scripts/hooks/cleanup-shell.sh +12 -1
- package/scripts/hooks/task-complete.sh +12 -1
- package/scripts/install-code-execution-hooks.sh +12 -1
- package/scripts/install-sweep-hook.sh +12 -0
- package/scripts/install.sh +11 -0
- package/scripts/opencode-wrapper.sh +11 -0
- package/scripts/portal/cloud-init.yaml +69 -0
- package/scripts/portal/setup.sh +69 -0
- package/scripts/portal/stackmemory-portal.service +34 -0
- package/scripts/setup-claude-integration.sh +12 -1
- package/scripts/smoke-init-db.sh +23 -0
- package/scripts/stackmemory-daemon.sh +11 -0
- package/scripts/verify-dist.cjs +11 -4
- package/dist/src/cli/commands/ralph.js +0 -1053
- package/dist/src/cli/commands/team.js +0 -168
- package/dist/src/core/context/shared-context-layer.js +0 -620
- package/dist/src/core/context/stack-merge-resolver.js +0 -748
- package/dist/src/core/merge/conflict-detector.js +0 -430
- package/dist/src/core/merge/resolution-engine.js +0 -557
- package/dist/src/core/merge/stack-diff.js +0 -531
- package/dist/src/core/merge/unified-merge-resolver.js +0 -302
- package/dist/src/hooks/diffmem-hooks.js +0 -376
- package/dist/src/integrations/diffmem/client.js +0 -208
- package/dist/src/integrations/diffmem/config.js +0 -14
- package/dist/src/integrations/greptile/client.js +0 -101
- package/dist/src/integrations/greptile/config.js +0 -14
- package/dist/src/integrations/greptile/index.js +0 -11
- package/dist/src/integrations/mcp/handlers/cord-handlers.js +0 -397
- package/dist/src/integrations/mcp/handlers/diffmem-handlers.js +0 -455
- package/dist/src/integrations/mcp/handlers/greptile-handlers.js +0 -456
- package/dist/src/integrations/mcp/handlers/provider-handlers.js +0 -227
- package/dist/src/integrations/mcp/handlers/team-handlers.js +0 -211
- package/dist/src/integrations/ralph/bridge/ralph-stackmemory-bridge.js +0 -863
- package/dist/src/integrations/ralph/context/context-budget-manager.js +0 -308
- package/dist/src/integrations/ralph/context/stackmemory-context-loader.js +0 -391
- package/dist/src/integrations/ralph/index.js +0 -17
- package/dist/src/integrations/ralph/learning/pattern-learner.js +0 -435
- package/dist/src/integrations/ralph/lifecycle/iteration-lifecycle.js +0 -448
- package/dist/src/integrations/ralph/loopmax.js +0 -488
- package/dist/src/integrations/ralph/monitoring/swarm-dashboard.js +0 -293
- package/dist/src/integrations/ralph/monitoring/swarm-registry.js +0 -107
- package/dist/src/integrations/ralph/orchestration/multi-loop-orchestrator.js +0 -508
- package/dist/src/integrations/ralph/patterns/compounding-engineering-pattern.js +0 -407
- package/dist/src/integrations/ralph/patterns/extended-coherence-sessions.js +0 -495
- package/dist/src/integrations/ralph/patterns/oracle-worker-pattern.js +0 -387
- package/dist/src/integrations/ralph/performance/performance-optimizer.js +0 -357
- package/dist/src/integrations/ralph/recovery/crash-recovery.js +0 -461
- package/dist/src/integrations/ralph/state/state-reconciler.js +0 -420
- package/dist/src/integrations/ralph/swarm/git-workflow-manager.js +0 -444
- package/dist/src/integrations/ralph/swarm/swarm-coordinator.js +0 -1007
- package/dist/src/integrations/ralph/visualization/ralph-debugger.js +0 -635
- package/scripts/ralph-loop-implementation.js +0 -404
- /package/dist/src/core/{merge → cache}/types.js +0 -0
- /package/dist/src/{integrations/diffmem/types.js → core/storage/cloud-sync-types.js} +0 -0
- /package/dist/src/{integrations/greptile/types.js → core/trace/trace-event.js} +0 -0
- /package/dist/src/{integrations/ralph → features/operator}/types.js +0 -0
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { fileURLToPath as __fileURLToPath } from 'url';
|
|
2
|
+
import { dirname as __pathDirname } from 'path';
|
|
3
|
+
const __filename = __fileURLToPath(import.meta.url);
|
|
4
|
+
const __dirname = __pathDirname(__filename);
|
|
5
|
+
import Database from "better-sqlite3";
|
|
6
|
+
import * as path from "path";
|
|
7
|
+
import * as fs from "fs";
|
|
8
|
+
import { logger } from "../monitoring/logger.js";
|
|
9
|
+
import { SkillPackManifestSchema } from "./types.js";
|
|
10
|
+
const SCHEMA_VERSION = 1;
|
|
11
|
+
const SCHEMA_SQL = `
|
|
12
|
+
CREATE TABLE IF NOT EXISTS schema_version (
|
|
13
|
+
version INTEGER PRIMARY KEY
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
CREATE TABLE IF NOT EXISTS packs (
|
|
17
|
+
name TEXT PRIMARY KEY,
|
|
18
|
+
version TEXT NOT NULL,
|
|
19
|
+
manifest TEXT NOT NULL,
|
|
20
|
+
instructions TEXT,
|
|
21
|
+
installed_at TEXT NOT NULL,
|
|
22
|
+
source TEXT
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
CREATE VIRTUAL TABLE IF NOT EXISTS packs_fts USING fts5(
|
|
26
|
+
name,
|
|
27
|
+
description,
|
|
28
|
+
instructions,
|
|
29
|
+
content='packs',
|
|
30
|
+
content_rowid='rowid'
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
CREATE TRIGGER IF NOT EXISTS packs_ai AFTER INSERT ON packs BEGIN
|
|
34
|
+
INSERT INTO packs_fts(rowid, name, description, instructions)
|
|
35
|
+
VALUES (new.rowid, new.name,
|
|
36
|
+
json_extract(new.manifest, '$.description'),
|
|
37
|
+
COALESCE(new.instructions, ''));
|
|
38
|
+
END;
|
|
39
|
+
|
|
40
|
+
CREATE TRIGGER IF NOT EXISTS packs_ad AFTER DELETE ON packs BEGIN
|
|
41
|
+
INSERT INTO packs_fts(packs_fts, rowid, name, description, instructions)
|
|
42
|
+
VALUES ('delete', old.rowid, old.name,
|
|
43
|
+
json_extract(old.manifest, '$.description'),
|
|
44
|
+
COALESCE(old.instructions, ''));
|
|
45
|
+
END;
|
|
46
|
+
|
|
47
|
+
CREATE TRIGGER IF NOT EXISTS packs_au AFTER UPDATE ON packs BEGIN
|
|
48
|
+
INSERT INTO packs_fts(packs_fts, rowid, name, description, instructions)
|
|
49
|
+
VALUES ('delete', old.rowid, old.name,
|
|
50
|
+
json_extract(old.manifest, '$.description'),
|
|
51
|
+
COALESCE(old.instructions, ''));
|
|
52
|
+
INSERT INTO packs_fts(rowid, name, description, instructions)
|
|
53
|
+
VALUES (new.rowid, new.name,
|
|
54
|
+
json_extract(new.manifest, '$.description'),
|
|
55
|
+
COALESCE(new.instructions, ''));
|
|
56
|
+
END;
|
|
57
|
+
`;
|
|
58
|
+
function getDefaultDbPath() {
|
|
59
|
+
const home = process.env["HOME"] || process.env["USERPROFILE"] || "/tmp";
|
|
60
|
+
return path.join(home, ".stackmemory", "skill-packs.db");
|
|
61
|
+
}
|
|
62
|
+
function rowToPack(row) {
|
|
63
|
+
const manifest = SkillPackManifestSchema.parse(
|
|
64
|
+
JSON.parse(row["manifest"])
|
|
65
|
+
);
|
|
66
|
+
const source = row["source"];
|
|
67
|
+
const metadata = {
|
|
68
|
+
installedAt: row["installed_at"],
|
|
69
|
+
...source ? { source } : {}
|
|
70
|
+
};
|
|
71
|
+
return {
|
|
72
|
+
manifest,
|
|
73
|
+
instructions: row["instructions"] || void 0,
|
|
74
|
+
metadata
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
class SkillPackRegistry {
|
|
78
|
+
db;
|
|
79
|
+
dbPath;
|
|
80
|
+
constructor(dbPath) {
|
|
81
|
+
this.dbPath = dbPath || getDefaultDbPath();
|
|
82
|
+
const dir = path.dirname(this.dbPath);
|
|
83
|
+
if (!fs.existsSync(dir)) {
|
|
84
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
85
|
+
}
|
|
86
|
+
this.db = new Database(this.dbPath);
|
|
87
|
+
this.db.pragma("journal_mode = WAL");
|
|
88
|
+
this.db.pragma("busy_timeout = 5000");
|
|
89
|
+
this.initSchema();
|
|
90
|
+
}
|
|
91
|
+
initSchema() {
|
|
92
|
+
const versionRow = (() => {
|
|
93
|
+
try {
|
|
94
|
+
return this.db.prepare(
|
|
95
|
+
"SELECT name FROM sqlite_master WHERE type='table' AND name='schema_version'"
|
|
96
|
+
).get();
|
|
97
|
+
} catch {
|
|
98
|
+
return void 0;
|
|
99
|
+
}
|
|
100
|
+
})();
|
|
101
|
+
if (!versionRow) {
|
|
102
|
+
this.db.exec(SCHEMA_SQL);
|
|
103
|
+
this.db.prepare("INSERT OR REPLACE INTO schema_version (version) VALUES (?)").run(SCHEMA_VERSION);
|
|
104
|
+
logger.debug("SkillPackRegistry: created schema v" + SCHEMA_VERSION);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
// ============================================================
|
|
108
|
+
// CRUD
|
|
109
|
+
// ============================================================
|
|
110
|
+
/**
|
|
111
|
+
* Install or update a skill pack. Upserts by name.
|
|
112
|
+
*/
|
|
113
|
+
install(pack) {
|
|
114
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
115
|
+
const manifestJson = JSON.stringify(pack.manifest);
|
|
116
|
+
this.db.prepare(
|
|
117
|
+
`INSERT INTO packs (name, version, manifest, instructions, installed_at, source)
|
|
118
|
+
VALUES (?, ?, ?, ?, ?, ?)
|
|
119
|
+
ON CONFLICT(name) DO UPDATE SET
|
|
120
|
+
version = excluded.version,
|
|
121
|
+
manifest = excluded.manifest,
|
|
122
|
+
instructions = excluded.instructions,
|
|
123
|
+
installed_at = excluded.installed_at,
|
|
124
|
+
source = excluded.source`
|
|
125
|
+
).run(
|
|
126
|
+
pack.manifest.name,
|
|
127
|
+
pack.manifest.version,
|
|
128
|
+
manifestJson,
|
|
129
|
+
pack.instructions ?? null,
|
|
130
|
+
pack.metadata?.installedAt ?? now,
|
|
131
|
+
pack.metadata?.source ?? null
|
|
132
|
+
);
|
|
133
|
+
logger.debug(
|
|
134
|
+
`SkillPackRegistry: installed ${pack.manifest.name}@${pack.manifest.version}`
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Uninstall a pack by name.
|
|
139
|
+
*/
|
|
140
|
+
uninstall(name) {
|
|
141
|
+
const result = this.db.prepare("DELETE FROM packs WHERE name = ?").run(name);
|
|
142
|
+
return result.changes > 0;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Get a single pack by name.
|
|
146
|
+
*/
|
|
147
|
+
get(name) {
|
|
148
|
+
const row = this.db.prepare("SELECT * FROM packs WHERE name = ?").get(name);
|
|
149
|
+
return row ? rowToPack(row) : void 0;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* List packs with optional filters.
|
|
153
|
+
*/
|
|
154
|
+
list(query) {
|
|
155
|
+
const conditions = [];
|
|
156
|
+
const params = [];
|
|
157
|
+
if (query?.namespace) {
|
|
158
|
+
conditions.push("name LIKE ? || '/%'");
|
|
159
|
+
params.push(query.namespace);
|
|
160
|
+
}
|
|
161
|
+
if (query?.runtime) {
|
|
162
|
+
conditions.push("json_extract(manifest, '$.runtime.type') = ?");
|
|
163
|
+
params.push(query.runtime);
|
|
164
|
+
}
|
|
165
|
+
const where = conditions.length ? "WHERE " + conditions.join(" AND ") : "";
|
|
166
|
+
const sql = `SELECT * FROM packs ${where} ORDER BY name`;
|
|
167
|
+
const rows = this.db.prepare(sql).all(...params);
|
|
168
|
+
return rows.map(rowToPack);
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Find the pack that provides a given MCP tool name.
|
|
172
|
+
*/
|
|
173
|
+
getByTool(toolName) {
|
|
174
|
+
const rows = this.db.prepare("SELECT * FROM packs").all();
|
|
175
|
+
for (const row of rows) {
|
|
176
|
+
const manifest = JSON.parse(
|
|
177
|
+
row["manifest"]
|
|
178
|
+
);
|
|
179
|
+
const tools = manifest.mcp?.tools ?? [];
|
|
180
|
+
if (tools.some((t) => t.name === toolName)) {
|
|
181
|
+
return rowToPack(row);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return void 0;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Full-text search across pack name, description, and instructions.
|
|
188
|
+
*/
|
|
189
|
+
search(query) {
|
|
190
|
+
const sanitized = query.replace(/[^\w\s/-]/g, "").split(/\s+/).filter(Boolean).map((t) => `"${t}"`).join(" ");
|
|
191
|
+
if (!sanitized) return [];
|
|
192
|
+
const rows = this.db.prepare(
|
|
193
|
+
`SELECT p.* FROM packs p
|
|
194
|
+
JOIN packs_fts f ON p.rowid = f.rowid
|
|
195
|
+
WHERE packs_fts MATCH ?
|
|
196
|
+
ORDER BY rank`
|
|
197
|
+
).all(sanitized);
|
|
198
|
+
return rows.map(rowToPack);
|
|
199
|
+
}
|
|
200
|
+
// ============================================================
|
|
201
|
+
// LIFECYCLE
|
|
202
|
+
// ============================================================
|
|
203
|
+
close() {
|
|
204
|
+
this.db.close();
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
let registryInstance;
|
|
208
|
+
function getSkillPackRegistry(dbPath) {
|
|
209
|
+
if (!registryInstance) {
|
|
210
|
+
registryInstance = new SkillPackRegistry(dbPath);
|
|
211
|
+
}
|
|
212
|
+
return registryInstance;
|
|
213
|
+
}
|
|
214
|
+
function resetSkillPackRegistry() {
|
|
215
|
+
if (registryInstance) {
|
|
216
|
+
registryInstance.close();
|
|
217
|
+
registryInstance = void 0;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
export {
|
|
221
|
+
SkillPackRegistry,
|
|
222
|
+
getSkillPackRegistry,
|
|
223
|
+
resetSkillPackRegistry
|
|
224
|
+
};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { fileURLToPath as __fileURLToPath } from 'url';
|
|
2
|
+
import { dirname as __pathDirname } from 'path';
|
|
3
|
+
const __filename = __fileURLToPath(import.meta.url);
|
|
4
|
+
const __dirname = __pathDirname(__filename);
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
const SemverSchema = z.string().regex(
|
|
7
|
+
/^\d+\.\d+\.\d+(-[\w.]+)?(\+[\w.]+)?$/,
|
|
8
|
+
"version must be valid semver (e.g. 1.0.0)"
|
|
9
|
+
);
|
|
10
|
+
const SkillPackRuntimeTypeSchema = z.enum([
|
|
11
|
+
"local",
|
|
12
|
+
"e2b",
|
|
13
|
+
"cua",
|
|
14
|
+
"modal"
|
|
15
|
+
]);
|
|
16
|
+
const SkillPackRuntimeSchema = z.object({
|
|
17
|
+
type: SkillPackRuntimeTypeSchema.default("local"),
|
|
18
|
+
template: z.string().optional()
|
|
19
|
+
});
|
|
20
|
+
const SkillPackIngestionSchema = z.object({
|
|
21
|
+
sources: z.array(z.string()).default([]),
|
|
22
|
+
scope: z.string().optional()
|
|
23
|
+
});
|
|
24
|
+
const SkillPackOntologySchema = z.object({
|
|
25
|
+
entities: z.array(z.string()).default([]),
|
|
26
|
+
relations: z.array(z.string()).default([])
|
|
27
|
+
});
|
|
28
|
+
const SkillPackMcpToolSchema = z.object({
|
|
29
|
+
name: z.string().min(1),
|
|
30
|
+
description: z.string().min(1),
|
|
31
|
+
inputSchema: z.record(z.unknown()).optional()
|
|
32
|
+
});
|
|
33
|
+
const SkillPackMcpSchema = z.object({
|
|
34
|
+
tools: z.array(SkillPackMcpToolSchema).default([])
|
|
35
|
+
});
|
|
36
|
+
const SkillPackExampleSchema = z.object({
|
|
37
|
+
input: z.string().min(1),
|
|
38
|
+
output: z.string().min(1)
|
|
39
|
+
});
|
|
40
|
+
const KnownLicenseSchema = z.enum([
|
|
41
|
+
"MIT",
|
|
42
|
+
"Apache-2.0",
|
|
43
|
+
"ISC",
|
|
44
|
+
"BSD-2-Clause",
|
|
45
|
+
"BSD-3-Clause",
|
|
46
|
+
"CC-BY-4.0",
|
|
47
|
+
"CC-BY-SA-4.0",
|
|
48
|
+
"CC0-1.0",
|
|
49
|
+
"UNLICENSED"
|
|
50
|
+
]);
|
|
51
|
+
const LicenseSchema = KnownLicenseSchema.or(z.string().min(1));
|
|
52
|
+
const PackNameSchema = z.string().min(1).regex(
|
|
53
|
+
/^[\w-]+\/[\w-]+$/,
|
|
54
|
+
'name must be namespace/pack-name (e.g. "coding/typescript-react")'
|
|
55
|
+
);
|
|
56
|
+
const SkillPackManifestSchema = z.object({
|
|
57
|
+
name: PackNameSchema,
|
|
58
|
+
version: SemverSchema,
|
|
59
|
+
description: z.string().min(1),
|
|
60
|
+
author: z.string().min(1),
|
|
61
|
+
license: LicenseSchema.default("MIT"),
|
|
62
|
+
runtime: SkillPackRuntimeSchema.optional(),
|
|
63
|
+
ingestion: SkillPackIngestionSchema.optional(),
|
|
64
|
+
ontology: SkillPackOntologySchema.optional(),
|
|
65
|
+
mcp: SkillPackMcpSchema.optional(),
|
|
66
|
+
examples: z.array(SkillPackExampleSchema).optional(),
|
|
67
|
+
instructions: z.string().optional()
|
|
68
|
+
});
|
|
69
|
+
export {
|
|
70
|
+
KnownLicenseSchema,
|
|
71
|
+
SkillPackExampleSchema,
|
|
72
|
+
SkillPackIngestionSchema,
|
|
73
|
+
SkillPackManifestSchema,
|
|
74
|
+
SkillPackMcpSchema,
|
|
75
|
+
SkillPackMcpToolSchema,
|
|
76
|
+
SkillPackOntologySchema,
|
|
77
|
+
SkillPackRuntimeSchema,
|
|
78
|
+
SkillPackRuntimeTypeSchema
|
|
79
|
+
};
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { fileURLToPath as __fileURLToPath } from 'url';
|
|
2
|
+
import { dirname as __pathDirname } from 'path';
|
|
3
|
+
const __filename = __fileURLToPath(import.meta.url);
|
|
4
|
+
const __dirname = __pathDirname(__filename);
|
|
5
|
+
import { EventEmitter } from "events";
|
|
6
|
+
import { CloudSyncEngine } from "./cloud-sync.js";
|
|
7
|
+
import { logger } from "../monitoring/logger.js";
|
|
8
|
+
class CloudSyncManager extends EventEmitter {
|
|
9
|
+
engine;
|
|
10
|
+
config;
|
|
11
|
+
periodicTimer;
|
|
12
|
+
debounceTimer;
|
|
13
|
+
running = false;
|
|
14
|
+
constructor(db, config) {
|
|
15
|
+
super();
|
|
16
|
+
this.config = config;
|
|
17
|
+
this.engine = new CloudSyncEngine(db, config);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Start the sync manager (periodic sync if configured)
|
|
21
|
+
*/
|
|
22
|
+
start() {
|
|
23
|
+
if (this.running) return;
|
|
24
|
+
this.running = true;
|
|
25
|
+
if (this.config.autoSync && this.config.syncIntervalMs > 0) {
|
|
26
|
+
this.periodicTimer = setInterval(() => {
|
|
27
|
+
this.performPush("periodic").catch(
|
|
28
|
+
(e) => logger.error("Periodic cloud sync failed", { error: String(e) })
|
|
29
|
+
);
|
|
30
|
+
}, this.config.syncIntervalMs);
|
|
31
|
+
}
|
|
32
|
+
logger.info("Cloud sync manager started", {
|
|
33
|
+
autoSync: this.config.autoSync,
|
|
34
|
+
intervalMs: this.config.syncIntervalMs
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Stop the sync manager
|
|
39
|
+
*/
|
|
40
|
+
stop() {
|
|
41
|
+
if (!this.running) return;
|
|
42
|
+
this.running = false;
|
|
43
|
+
if (this.periodicTimer) {
|
|
44
|
+
clearInterval(this.periodicTimer);
|
|
45
|
+
this.periodicTimer = void 0;
|
|
46
|
+
}
|
|
47
|
+
if (this.debounceTimer) {
|
|
48
|
+
clearTimeout(this.debounceTimer);
|
|
49
|
+
this.debounceTimer = void 0;
|
|
50
|
+
}
|
|
51
|
+
logger.info("Cloud sync manager stopped");
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Schedule a debounced push (used by frame lifecycle hooks)
|
|
55
|
+
*/
|
|
56
|
+
scheduleDebouncedPush(trigger) {
|
|
57
|
+
if (!this.config.enabled || !this.running) return;
|
|
58
|
+
if (this.debounceTimer) {
|
|
59
|
+
clearTimeout(this.debounceTimer);
|
|
60
|
+
}
|
|
61
|
+
this.debounceTimer = setTimeout(() => {
|
|
62
|
+
this.debounceTimer = void 0;
|
|
63
|
+
this.performPush(trigger).catch(
|
|
64
|
+
(e) => logger.error("Debounced cloud sync push failed", {
|
|
65
|
+
error: String(e)
|
|
66
|
+
})
|
|
67
|
+
);
|
|
68
|
+
}, this.config.debounceMs);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Perform a push
|
|
72
|
+
*/
|
|
73
|
+
async performPush(trigger, force = false) {
|
|
74
|
+
const result = await this.engine.push(force);
|
|
75
|
+
this.emit("push", { trigger, result });
|
|
76
|
+
return result;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Perform a pull
|
|
80
|
+
*/
|
|
81
|
+
async performPull(trigger, tables) {
|
|
82
|
+
const result = await this.engine.pull(tables);
|
|
83
|
+
this.emit("pull", { trigger, result });
|
|
84
|
+
return result;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Get sync status
|
|
88
|
+
*/
|
|
89
|
+
getStatus() {
|
|
90
|
+
return this.engine.status();
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Check if manager is running
|
|
94
|
+
*/
|
|
95
|
+
isRunning() {
|
|
96
|
+
return this.running;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const DEFAULT_SYNC_MANAGER_CONFIG = {
|
|
100
|
+
batchSize: 100,
|
|
101
|
+
conflictResolution: "newest_wins",
|
|
102
|
+
generationalPolicy: {
|
|
103
|
+
youngMaxAgeDays: 1,
|
|
104
|
+
matureMaxAgeDays: 7
|
|
105
|
+
},
|
|
106
|
+
timeoutMs: 3e4,
|
|
107
|
+
retryAttempts: 3,
|
|
108
|
+
retryBaseDelayMs: 1e3,
|
|
109
|
+
autoSync: false,
|
|
110
|
+
syncIntervalMs: 0,
|
|
111
|
+
debounceMs: 5e3
|
|
112
|
+
};
|
|
113
|
+
export {
|
|
114
|
+
CloudSyncManager,
|
|
115
|
+
DEFAULT_SYNC_MANAGER_CONFIG
|
|
116
|
+
};
|