toolnet-memory 0.2.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/.env.example +28 -0
- package/README.md +147 -0
- package/bin/toolnet-memory +415 -0
- package/dist/packages/cli/commands.js +1 -0
- package/dist/packages/cli/index.js +1 -0
- package/dist/packages/sdk/client.js +78 -0
- package/dist/packages/sdk/index.js +1 -0
- package/dist/packages/sdk/types.js +1 -0
- package/dist/src/api/index.js +1 -0
- package/dist/src/api/routes/health.js +1 -0
- package/dist/src/api/routes/index.js +1 -0
- package/dist/src/api/routes/memory.js +1 -0
- package/dist/src/api/routes/projects.js +1 -0
- package/dist/src/api/routes/search.js +1 -0
- package/dist/src/api/server.js +1 -0
- package/dist/src/capture/activity-capture.js +21 -0
- package/dist/src/capture/command-capture.js +12 -0
- package/dist/src/capture/error-capture.js +14 -0
- package/dist/src/capture/event-deduplicator.js +28 -0
- package/dist/src/capture/event-queue.js +20 -0
- package/dist/src/capture/file-capture.js +23 -0
- package/dist/src/capture/index.js +8 -0
- package/dist/src/capture/session-capture.js +18 -0
- package/dist/src/capture/tool-capture.js +13 -0
- package/dist/src/code-intelligence/analysis/analysis-engine.js +26 -0
- package/dist/src/code-intelligence/analysis/dead-code-analyzer.js +127 -0
- package/dist/src/code-intelligence/analysis/dependency-analyzer.js +66 -0
- package/dist/src/code-intelligence/analysis/index.js +4 -0
- package/dist/src/code-intelligence/analysis/types.js +1 -0
- package/dist/src/code-intelligence/architecture/architecture-engine.js +48 -0
- package/dist/src/code-intelligence/architecture/clusters.js +322 -0
- package/dist/src/code-intelligence/architecture/entry-points.js +150 -0
- package/dist/src/code-intelligence/architecture/hotspots.js +136 -0
- package/dist/src/code-intelligence/architecture/index.js +6 -0
- package/dist/src/code-intelligence/architecture/layers.js +197 -0
- package/dist/src/code-intelligence/architecture/types.js +1 -0
- package/dist/src/code-intelligence/chunks/index.js +2 -0
- package/dist/src/code-intelligence/chunks/smart-chunker.js +125 -0
- package/dist/src/code-intelligence/chunks/types.js +1 -0
- package/dist/src/code-intelligence/git/git-diff.js +109 -0
- package/dist/src/code-intelligence/git/index.js +1 -0
- package/dist/src/code-intelligence/graph/architecture.js +26 -0
- package/dist/src/code-intelligence/graph/graph-builder.js +213 -0
- package/dist/src/code-intelligence/graph/graph-store.js +57 -0
- package/dist/src/code-intelligence/graph/index.js +1 -0
- package/dist/src/code-intelligence/graph/relationships.js +1 -0
- package/dist/src/code-intelligence/graph/trace.js +65 -0
- package/dist/src/code-intelligence/impact/blast-radius.js +160 -0
- package/dist/src/code-intelligence/impact/change-mapper.js +69 -0
- package/dist/src/code-intelligence/impact/edit-tool-detector.js +92 -0
- package/dist/src/code-intelligence/impact/impact-analyzer.js +60 -0
- package/dist/src/code-intelligence/impact/impact-guard.js +33 -0
- package/dist/src/code-intelligence/impact/index.js +5 -0
- package/dist/src/code-intelligence/incremental/file-hash.js +8 -0
- package/dist/src/code-intelligence/incremental/incremental-indexer.js +106 -0
- package/dist/src/code-intelligence/incremental/manifest-builder.js +19 -0
- package/dist/src/code-intelligence/incremental/manifest.js +31 -0
- package/dist/src/code-intelligence/index.js +23 -0
- package/dist/src/code-intelligence/indexer/file-watcher.js +1 -0
- package/dist/src/code-intelligence/indexer/incremental-indexer.js +1 -0
- package/dist/src/code-intelligence/indexer/index.js +1 -0
- package/dist/src/code-intelligence/indexer/repository-indexer.js +31 -0
- package/dist/src/code-intelligence/indexer/repository-scanner.js +50 -0
- package/dist/src/code-intelligence/parsers/index.js +1 -0
- package/dist/src/code-intelligence/parsers/tree-sitter/index.js +1 -0
- package/dist/src/code-intelligence/parsers/tree-sitter/languages.js +1 -0
- package/dist/src/code-intelligence/parsers/tree-sitter/parser.js +1 -0
- package/dist/src/code-intelligence/parsers/typescript-parser.js +190 -0
- package/dist/src/code-intelligence/query/graph-query-engine.js +275 -0
- package/dist/src/code-intelligence/query/index.js +2 -0
- package/dist/src/code-intelligence/query/types.js +1 -0
- package/dist/src/code-intelligence/resolution/index.js +2 -0
- package/dist/src/code-intelligence/resolution/types.js +1 -0
- package/dist/src/code-intelligence/resolution/typescript-resolver.js +316 -0
- package/dist/src/code-intelligence/rich/index.js +1 -0
- package/dist/src/code-intelligence/rich/rich-graph-enricher.js +463 -0
- package/dist/src/code-intelligence/semantic/index.js +2 -0
- package/dist/src/code-intelligence/semantic/semantic-code-engine.js +213 -0
- package/dist/src/code-intelligence/semantic/source-priority.js +22 -0
- package/dist/src/code-intelligence/symbols/index.js +1 -0
- package/dist/src/code-intelligence/symbols/reference-resolver.js +21 -0
- package/dist/src/code-intelligence/symbols/symbol-extractor.js +1 -0
- package/dist/src/code-intelligence/test-analysis.js +72 -0
- package/dist/src/code-intelligence/test-architecture.js +67 -0
- package/dist/src/code-intelligence/test-impact.js +47 -0
- package/dist/src/code-intelligence/test-incremental.js +24 -0
- package/dist/src/code-intelligence/test-index.js +39 -0
- package/dist/src/code-intelligence/test-resolution.js +54 -0
- package/dist/src/code-intelligence/test-rich-graph.js +48 -0
- package/dist/src/code-intelligence/test-semantic.js +57 -0
- package/dist/src/code-intelligence/test-visualization.js +36 -0
- package/dist/src/code-intelligence/types.js +1 -0
- package/dist/src/code-intelligence/visualization/index.js +2 -0
- package/dist/src/code-intelligence/visualization/types.js +1 -0
- package/dist/src/code-intelligence/visualization/visualization-builder.js +104 -0
- package/dist/src/core/config.js +66 -0
- package/dist/src/core/global-env.js +70 -0
- package/dist/src/core/importance.js +30 -0
- package/dist/src/core/index.js +5 -0
- package/dist/src/core/memory-engine.js +183 -0
- package/dist/src/core/project-manager.js +243 -0
- package/dist/src/core/types.js +1 -0
- package/dist/src/embeddings/batch-embedder.js +1 -0
- package/dist/src/embeddings/cache.js +1 -0
- package/dist/src/embeddings/embedder.js +51 -0
- package/dist/src/embeddings/index.js +4 -0
- package/dist/src/embeddings/local.js +37 -0
- package/dist/src/embeddings/provider.js +1 -0
- package/dist/src/embeddings/remote.js +76 -0
- package/dist/src/embeddings/test-connection.js +16 -0
- package/dist/src/hooks/after-edit.js +3 -0
- package/dist/src/hooks/after-tool.js +3 -0
- package/dist/src/hooks/auto-context.js +68 -0
- package/dist/src/hooks/auto-impact-guard.js +94 -0
- package/dist/src/hooks/auto-retrieval.js +27 -0
- package/dist/src/hooks/before-agent.js +18 -0
- package/dist/src/hooks/before-compact.js +3 -0
- package/dist/src/hooks/before-edit.js +20 -0
- package/dist/src/hooks/index.js +11 -0
- package/dist/src/hooks/runtime.js +110 -0
- package/dist/src/hooks/session-end.js +3 -0
- package/dist/src/hooks/session-start.js +3 -0
- package/dist/src/index.js +22 -0
- package/dist/src/mcp/bootstrap.js +68 -0
- package/dist/src/mcp/context.js +1 -0
- package/dist/src/mcp/index.js +3 -0
- package/dist/src/mcp/server.js +45 -0
- package/dist/src/mcp/tools/analyze-impact.js +41 -0
- package/dist/src/mcp/tools/dead-code.js +55 -0
- package/dist/src/mcp/tools/find-callers.js +24 -0
- package/dist/src/mcp/tools/find-dependencies.js +57 -0
- package/dist/src/mcp/tools/find-symbol.js +7 -0
- package/dist/src/mcp/tools/get-architecture.js +11 -0
- package/dist/src/mcp/tools/graph-dependents.js +24 -0
- package/dist/src/mcp/tools/graph-neighborhood.js +58 -0
- package/dist/src/mcp/tools/graph-path.js +43 -0
- package/dist/src/mcp/tools/graph-query-utils.js +32 -0
- package/dist/src/mcp/tools/impact-guard.js +34 -0
- package/dist/src/mcp/tools/index-repository.js +1 -0
- package/dist/src/mcp/tools/index.js +20 -0
- package/dist/src/mcp/tools/memory-decisions.js +1 -0
- package/dist/src/mcp/tools/memory-forget.js +14 -0
- package/dist/src/mcp/tools/memory-recent.js +1 -0
- package/dist/src/mcp/tools/memory-remember.js +33 -0
- package/dist/src/mcp/tools/memory-rules.js +1 -0
- package/dist/src/mcp/tools/memory-search.js +18 -0
- package/dist/src/mcp/tools/memory-todos.js +1 -0
- package/dist/src/mcp/tools/project-context.js +25 -0
- package/dist/src/mcp/tools/search-code.js +21 -0
- package/dist/src/mcp/tools/semantic-code-search.js +33 -0
- package/dist/src/mcp/tools/snapshot-create.js +13 -0
- package/dist/src/mcp/tools/snapshot-list.js +7 -0
- package/dist/src/mcp/tools/snapshot-restore.js +13 -0
- package/dist/src/mcp/tools/trace-calls.js +37 -0
- package/dist/src/memory/activity.js +5 -0
- package/dist/src/memory/conflict-detector.js +105 -0
- package/dist/src/memory/consolidator.js +104 -0
- package/dist/src/memory/decay.js +59 -0
- package/dist/src/memory/decisions.js +3 -0
- package/dist/src/memory/deduplicate.js +25 -0
- package/dist/src/memory/index.js +11 -0
- package/dist/src/memory/maintenance.js +16 -0
- package/dist/src/memory/remember.js +3 -0
- package/dist/src/memory/rules.js +3 -0
- package/dist/src/memory/search.js +3 -0
- package/dist/src/memory/summaries.js +1 -0
- package/dist/src/memory/todos.js +3 -0
- package/dist/src/processor/decision-extractor.js +13 -0
- package/dist/src/processor/importance-scorer.js +22 -0
- package/dist/src/processor/index.js +7 -0
- package/dist/src/processor/memory-extractor.js +59 -0
- package/dist/src/processor/memory-processor.js +105 -0
- package/dist/src/processor/rule-extractor.js +13 -0
- package/dist/src/processor/summarizer.js +71 -0
- package/dist/src/processor/todo-extractor.js +12 -0
- package/dist/src/production/config-check.js +34 -0
- package/dist/src/production/doctor.js +58 -0
- package/dist/src/production/full-index.js +114 -0
- package/dist/src/production/health.js +58 -0
- package/dist/src/production/index-pipeline.js +151 -0
- package/dist/src/production/index.js +4 -0
- package/dist/src/production/project-lock.js +95 -0
- package/dist/src/production/project-status.js +16 -0
- package/dist/src/production/recovery.js +15 -0
- package/dist/src/production/snapshot-cli.js +58 -0
- package/dist/src/project-manual/cli.js +77 -0
- package/dist/src/project-manual/index.js +2 -0
- package/dist/src/project-manual/manager.js +147 -0
- package/dist/src/project-manual/types.js +1 -0
- package/dist/src/retrieval/bm25/index.js +1 -0
- package/dist/src/retrieval/bm25/search.js +1 -0
- package/dist/src/retrieval/bm25.js +30 -0
- package/dist/src/retrieval/context-budget.js +1 -0
- package/dist/src/retrieval/context-builder.js +22 -0
- package/dist/src/retrieval/graph/index.js +1 -0
- package/dist/src/retrieval/graph/search.js +1 -0
- package/dist/src/retrieval/hybrid/hybrid-search.js +1 -0
- package/dist/src/retrieval/hybrid/index.js +1 -0
- package/dist/src/retrieval/hybrid-search.js +68 -0
- package/dist/src/retrieval/importance.js +16 -0
- package/dist/src/retrieval/index.js +12 -0
- package/dist/src/retrieval/query-analyzer.js +32 -0
- package/dist/src/retrieval/query-classifier.js +1 -0
- package/dist/src/retrieval/query-expansion.js +1 -0
- package/dist/src/retrieval/recency.js +12 -0
- package/dist/src/retrieval/reranker/index.js +1 -0
- package/dist/src/retrieval/reranker/reranker.js +1 -0
- package/dist/src/retrieval/retrieval-engine.js +17 -0
- package/dist/src/retrieval/tokenizer.js +9 -0
- package/dist/src/retrieval/type-priority.js +10 -0
- package/dist/src/retrieval/types.js +1 -0
- package/dist/src/retrieval/vector/index.js +4 -0
- package/dist/src/retrieval/vector/metadata-filter.js +1 -0
- package/dist/src/retrieval/vector/persistence.js +67 -0
- package/dist/src/retrieval/vector/search.js +12 -0
- package/dist/src/retrieval/vector/test-persistence.js +36 -0
- package/dist/src/retrieval/vector/upsert.js +40 -0
- package/dist/src/retrieval/vector/vector-store.js +89 -0
- package/dist/src/retrieval/vector-hybrid-engine.js +91 -0
- package/dist/src/runtime/bootstrap.js +28 -0
- package/dist/src/runtime/graceful.js +17 -0
- package/dist/src/runtime/index.js +3 -0
- package/dist/src/runtime/toolnet-memory-runtime.js +156 -0
- package/dist/src/security/encryption.js +1 -0
- package/dist/src/security/file-filter.js +30 -0
- package/dist/src/security/index.js +3 -0
- package/dist/src/security/sanitizer.js +49 -0
- package/dist/src/security/secret-scanner.js +56 -0
- package/dist/src/session/agy/adapter.js +159 -0
- package/dist/src/session/agy/cli.js +87 -0
- package/dist/src/session/agy/hook-installer.js +62 -0
- package/dist/src/session/agy/hook.js +167 -0
- package/dist/src/session/agy/index.js +5 -0
- package/dist/src/session/agy/project-resolver.js +27 -0
- package/dist/src/session/agy/recovery.js +112 -0
- package/dist/src/session/agy/transcript.js +191 -0
- package/dist/src/session/codex/adapter.js +138 -0
- package/dist/src/session/codex/cli.js +236 -0
- package/dist/src/session/codex/context-hook-installer.js +70 -0
- package/dist/src/session/codex/context-hook.js +69 -0
- package/dist/src/session/codex/discovery.js +138 -0
- package/dist/src/session/codex/index.js +6 -0
- package/dist/src/session/codex/notify-installer.js +135 -0
- package/dist/src/session/codex/project-resolver.js +25 -0
- package/dist/src/session/codex/recovery.js +27 -0
- package/dist/src/session/codex/rollout.js +186 -0
- package/dist/src/session/core.js +239 -0
- package/dist/src/session/identity.js +57 -0
- package/dist/src/session/index.js +9 -0
- package/dist/src/session/learner/cli.js +62 -0
- package/dist/src/session/learner/extractor.js +461 -0
- package/dist/src/session/learner/index.js +4 -0
- package/dist/src/session/learner/journal.js +159 -0
- package/dist/src/session/learner/learner.js +124 -0
- package/dist/src/session/learner/types.js +1 -0
- package/dist/src/session/opencode/adapter.js +553 -0
- package/dist/src/session/opencode/cli.js +121 -0
- package/dist/src/session/opencode/index.js +2 -0
- package/dist/src/session/opencode/plugin-installer.js +230 -0
- package/dist/src/session/store.js +242 -0
- package/dist/src/session/types.js +1 -0
- package/dist/src/session/utils.js +47 -0
- package/dist/src/session/wal.js +303 -0
- package/dist/src/snapshot/index.js +2 -0
- package/dist/src/snapshot/manager.js +130 -0
- package/dist/src/snapshot/test-snapshot.js +28 -0
- package/dist/src/snapshot/types.js +1 -0
- package/dist/src/storage/architecture-store.js +37 -0
- package/dist/src/storage/cleanup-health.js +20 -0
- package/dist/src/storage/code-analysis-store.js +35 -0
- package/dist/src/storage/code-chunk-store.js +25 -0
- package/dist/src/storage/code-graph-store.js +24 -0
- package/dist/src/storage/code-manifest-store.js +24 -0
- package/dist/src/storage/code-vector-store.js +25 -0
- package/dist/src/storage/github/client.js +1 -0
- package/dist/src/storage/github/index.js +1 -0
- package/dist/src/storage/google-drive/client.js +1 -0
- package/dist/src/storage/google-drive/index.js +1 -0
- package/dist/src/storage/huggingface/client.js +116 -0
- package/dist/src/storage/huggingface/index.js +1 -0
- package/dist/src/storage/index.js +16 -0
- package/dist/src/storage/list-bucket-raw.js +14 -0
- package/dist/src/storage/list-bucket-tree.js +38 -0
- package/dist/src/storage/local/client.js +99 -0
- package/dist/src/storage/local/index.js +1 -0
- package/dist/src/storage/memory-store.js +30 -0
- package/dist/src/storage/project/cleanup-layout-v1.js +72 -0
- package/dist/src/storage/project/folder.js +15 -0
- package/dist/src/storage/project/index.js +3 -0
- package/dist/src/storage/project/layout.js +74 -0
- package/dist/src/storage/project/migrate-layout-v2.js +101 -0
- package/dist/src/storage/project/migrate.js +73 -0
- package/dist/src/storage/project/scoped-provider.js +165 -0
- package/dist/src/storage/provider.js +26 -0
- package/dist/src/storage/retrying-provider.js +23 -0
- package/dist/src/storage/test-connection.js +32 -0
- package/dist/src/storage/type-resolution-store.js +26 -0
- package/dist/src/storage/types.js +1 -0
- package/dist/src/storage/vector-store.js +30 -0
- package/dist/src/storage/visualization-store.js +25 -0
- package/dist/src/sync/compressor.js +1 -0
- package/dist/src/sync/conflict-resolver.js +1 -0
- package/dist/src/sync/downloader.js +1 -0
- package/dist/src/sync/index.js +1 -0
- package/dist/src/sync/sync-engine.js +1 -0
- package/dist/src/sync/upload-queue.js +1 -0
- package/dist/src/utils/retry.js +29 -0
- package/dist/src/visualization/server.js +270 -0
- package/dist/src/work-continuity/brief-cache.js +107 -0
- package/dist/src/work-continuity/brief.js +349 -0
- package/dist/src/work-continuity/cli.js +96 -0
- package/dist/src/work-continuity/context-cli.js +106 -0
- package/dist/src/work-continuity/context-runtime-cli.js +88 -0
- package/dist/src/work-continuity/extractor.js +339 -0
- package/dist/src/work-continuity/handoff.js +185 -0
- package/dist/src/work-continuity/index.js +14 -0
- package/dist/src/work-continuity/injection.js +84 -0
- package/dist/src/work-continuity/journal.js +49 -0
- package/dist/src/work-continuity/learner.js +127 -0
- package/dist/src/work-continuity/reducer.js +316 -0
- package/dist/src/work-continuity/semantic-extractor.js +360 -0
- package/dist/src/work-continuity/semantic-journal.js +55 -0
- package/dist/src/work-continuity/semantic-learner.js +125 -0
- package/dist/src/work-continuity/semantic-reducer.js +268 -0
- package/dist/src/work-continuity/semantic-types.js +1 -0
- package/dist/src/work-continuity/types.js +1 -0
- package/dist/visualization/public/index.html +2896 -0
- package/dist/visualization/public/vendor/3d-force-graph.min.js +5 -0
- package/package.json +69 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export function checkProductionConfig() {
|
|
2
|
+
const errors = [];
|
|
3
|
+
const warnings = [];
|
|
4
|
+
const provider = process.env
|
|
5
|
+
.MEMORY_STORAGE_PROVIDER ??
|
|
6
|
+
"local";
|
|
7
|
+
if (provider ===
|
|
8
|
+
"huggingface") {
|
|
9
|
+
const required = [
|
|
10
|
+
"HF_NAMESPACE",
|
|
11
|
+
"HF_BUCKET",
|
|
12
|
+
"HF_S3_ACCESS_KEY_ID",
|
|
13
|
+
"HF_S3_SECRET_ACCESS_KEY",
|
|
14
|
+
];
|
|
15
|
+
for (const key of required) {
|
|
16
|
+
if (!process.env[key]) {
|
|
17
|
+
errors.push(`Missing ${key}`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
if (!process.env.HF_TOKEN) {
|
|
21
|
+
warnings.push("HF_TOKEN missing: semantic embedding will use fallback");
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
const model = process.env
|
|
25
|
+
.HF_EMBEDDING_MODEL;
|
|
26
|
+
if (!model) {
|
|
27
|
+
warnings.push("HF_EMBEDDING_MODEL not set; default model will be used");
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
ok: errors.length === 0,
|
|
31
|
+
errors,
|
|
32
|
+
warnings,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import "dotenv/config";
|
|
2
|
+
import { loadConfig, ProjectManager, } from "../core/index.js";
|
|
3
|
+
import { createStorageProvider, withStorageRetry, MemoryStore, PersistentCodeGraphStore, PersistentVectorStore, PersistentCodeChunkStore, PersistentCodeVectorStore, } from "../storage/index.js";
|
|
4
|
+
import { createEmbeddingProvider, } from "../embeddings/index.js";
|
|
5
|
+
import { SnapshotManager, } from "../snapshot/index.js";
|
|
6
|
+
import { checkProductionConfig, } from "./config-check.js";
|
|
7
|
+
import { ProductionHealth, } from "./health.js";
|
|
8
|
+
async function main() {
|
|
9
|
+
const configCheck = checkProductionConfig();
|
|
10
|
+
if (!configCheck.ok) {
|
|
11
|
+
console.log({
|
|
12
|
+
ok: false,
|
|
13
|
+
config: configCheck,
|
|
14
|
+
});
|
|
15
|
+
process.exit(1);
|
|
16
|
+
}
|
|
17
|
+
const config = loadConfig();
|
|
18
|
+
const project = new ProjectManager()
|
|
19
|
+
.detect();
|
|
20
|
+
const storage = withStorageRetry(createStorageProvider({
|
|
21
|
+
provider: config.storage.provider,
|
|
22
|
+
huggingface: config.storage.huggingface,
|
|
23
|
+
localRoot: config.storage.localRoot,
|
|
24
|
+
}), {
|
|
25
|
+
attempts: 3,
|
|
26
|
+
});
|
|
27
|
+
const embeddings = createEmbeddingProvider();
|
|
28
|
+
const health = await new ProductionHealth(storage, embeddings).run();
|
|
29
|
+
const memories = await new MemoryStore(storage).load(project.id);
|
|
30
|
+
const graph = await new PersistentCodeGraphStore(storage).load(project.id);
|
|
31
|
+
const vectors = await new PersistentVectorStore(storage).load(project.id);
|
|
32
|
+
const chunks = await new PersistentCodeChunkStore(storage).load(project.id);
|
|
33
|
+
const codeVectors = await new PersistentCodeVectorStore(storage).load(project.id);
|
|
34
|
+
const snapshots = await new SnapshotManager(storage).list(project.id);
|
|
35
|
+
console.log({
|
|
36
|
+
ok: health.ok,
|
|
37
|
+
project: project.name,
|
|
38
|
+
storage: health.storage,
|
|
39
|
+
embedding: health.embedding,
|
|
40
|
+
memory: memories.length,
|
|
41
|
+
graphSymbols: graph?.symbols.length ?? 0,
|
|
42
|
+
graphEdges: graph?.edges.length ?? 0,
|
|
43
|
+
memoryVectors: vectors?.records.length ?? 0,
|
|
44
|
+
codeChunks: chunks?.chunks.length ?? 0,
|
|
45
|
+
codeVectors: codeVectors?.records.length ?? 0,
|
|
46
|
+
snapshots: snapshots.length,
|
|
47
|
+
warnings: configCheck.warnings,
|
|
48
|
+
});
|
|
49
|
+
if (!health.ok) {
|
|
50
|
+
process.exit(1);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
main().catch((error) => {
|
|
54
|
+
console.error(error instanceof Error
|
|
55
|
+
? error.message
|
|
56
|
+
: error);
|
|
57
|
+
process.exit(1);
|
|
58
|
+
});
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { closeSync, mkdirSync, openSync, rmSync, writeFileSync, } from "node:fs";
|
|
2
|
+
import { join, } from "node:path";
|
|
3
|
+
import { ProjectManager, } from "../core/index.js";
|
|
4
|
+
import { runProductionIndex, } from "./index-pipeline.js";
|
|
5
|
+
const project = new ProjectManager()
|
|
6
|
+
.detect();
|
|
7
|
+
const toolnetDir = join(project.rootPath, ".toolnet");
|
|
8
|
+
const lockFile = join(toolnetDir, "index.lock");
|
|
9
|
+
const statusFile = join(toolnetDir, "last-index.json");
|
|
10
|
+
mkdirSync(toolnetDir, {
|
|
11
|
+
recursive: true,
|
|
12
|
+
});
|
|
13
|
+
function writeStatus(value) {
|
|
14
|
+
writeFileSync(statusFile, JSON.stringify(value, null, 2) + "\n", {
|
|
15
|
+
encoding: "utf8",
|
|
16
|
+
mode: 0o600,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
let lockFd;
|
|
20
|
+
try {
|
|
21
|
+
lockFd =
|
|
22
|
+
openSync(lockFile, "wx", 0o600);
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
console.error("❌ Index already running for this project.");
|
|
26
|
+
console.error(`Lock: ${lockFile}`);
|
|
27
|
+
process.exit(2);
|
|
28
|
+
}
|
|
29
|
+
const startedAt = new Date()
|
|
30
|
+
.toISOString();
|
|
31
|
+
const completedStages = [];
|
|
32
|
+
try {
|
|
33
|
+
console.log();
|
|
34
|
+
console.log("==============================================");
|
|
35
|
+
console.log(" ToolNet Production Index");
|
|
36
|
+
console.log("==============================================");
|
|
37
|
+
console.log(`Project : ${project.name}`);
|
|
38
|
+
console.log(`Remote : projects/${project.remote ??
|
|
39
|
+
project.name}/`);
|
|
40
|
+
console.log("Runtime : production/dist");
|
|
41
|
+
console.log("Snapshot: disabled");
|
|
42
|
+
writeStatus({
|
|
43
|
+
version: 2,
|
|
44
|
+
state: "running",
|
|
45
|
+
startedAt,
|
|
46
|
+
completedStages,
|
|
47
|
+
project,
|
|
48
|
+
});
|
|
49
|
+
const result = await runProductionIndex(project, {
|
|
50
|
+
onStage: async (event) => {
|
|
51
|
+
if (event.state ===
|
|
52
|
+
"start") {
|
|
53
|
+
console.log();
|
|
54
|
+
console.log(`===== ${event.title} =====`);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
completedStages.push(event.id);
|
|
58
|
+
console.log(`✅ ${event.title} (${((event.durationMs ??
|
|
59
|
+
0) /
|
|
60
|
+
1000).toFixed(1)}s)`);
|
|
61
|
+
}
|
|
62
|
+
writeStatus({
|
|
63
|
+
version: 2,
|
|
64
|
+
state: "running",
|
|
65
|
+
startedAt,
|
|
66
|
+
currentStage: event.id,
|
|
67
|
+
completedStages: [
|
|
68
|
+
...completedStages,
|
|
69
|
+
],
|
|
70
|
+
project,
|
|
71
|
+
});
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
writeStatus({
|
|
75
|
+
version: 2,
|
|
76
|
+
state: "complete",
|
|
77
|
+
startedAt,
|
|
78
|
+
finishedAt: new Date()
|
|
79
|
+
.toISOString(),
|
|
80
|
+
completedStages,
|
|
81
|
+
result,
|
|
82
|
+
});
|
|
83
|
+
console.log();
|
|
84
|
+
console.log("==============================================");
|
|
85
|
+
console.log(" FULL INDEX COMPLETE ✅");
|
|
86
|
+
console.log("==============================================");
|
|
87
|
+
console.log(JSON.stringify(result, null, 2));
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
writeStatus({
|
|
91
|
+
version: 2,
|
|
92
|
+
state: "failed",
|
|
93
|
+
startedAt,
|
|
94
|
+
failedAt: new Date()
|
|
95
|
+
.toISOString(),
|
|
96
|
+
completedStages,
|
|
97
|
+
error: error instanceof Error
|
|
98
|
+
? error.message
|
|
99
|
+
: String(error),
|
|
100
|
+
});
|
|
101
|
+
console.error("FULL INDEX FAILED ❌");
|
|
102
|
+
console.error(error);
|
|
103
|
+
process.exitCode =
|
|
104
|
+
1;
|
|
105
|
+
}
|
|
106
|
+
finally {
|
|
107
|
+
if (lockFd !==
|
|
108
|
+
undefined) {
|
|
109
|
+
closeSync(lockFd);
|
|
110
|
+
}
|
|
111
|
+
rmSync(lockFile, {
|
|
112
|
+
force: true,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { randomUUID, } from "node:crypto";
|
|
2
|
+
export class ProductionHealth {
|
|
3
|
+
storage;
|
|
4
|
+
embeddings;
|
|
5
|
+
constructor(storage, embeddings) {
|
|
6
|
+
this.storage = storage;
|
|
7
|
+
this.embeddings = embeddings;
|
|
8
|
+
}
|
|
9
|
+
async run() {
|
|
10
|
+
const key = `_health/production-${randomUUID()}.txt`;
|
|
11
|
+
const payload = `toolnet-memory:${Date.now()}`;
|
|
12
|
+
let storageOk = false;
|
|
13
|
+
try {
|
|
14
|
+
await this.storage.put(key, payload, "text/plain");
|
|
15
|
+
const value = await this.storage.getText(key);
|
|
16
|
+
storageOk =
|
|
17
|
+
value === payload;
|
|
18
|
+
}
|
|
19
|
+
finally {
|
|
20
|
+
try {
|
|
21
|
+
await this.storage.delete(key);
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
// cleanup only
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
let embedding = null;
|
|
28
|
+
if (this.embeddings) {
|
|
29
|
+
try {
|
|
30
|
+
const vector = await this.embeddings.embed("ToolNet Memory production health check");
|
|
31
|
+
embedding = {
|
|
32
|
+
ok: vector.length > 0,
|
|
33
|
+
dimensions: vector.length,
|
|
34
|
+
mode: vector.length === 384
|
|
35
|
+
? "huggingface"
|
|
36
|
+
: "fallback-or-custom",
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
embedding = {
|
|
41
|
+
ok: false,
|
|
42
|
+
dimensions: 0,
|
|
43
|
+
mode: "failed",
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
ok: storageOk &&
|
|
49
|
+
(embedding === null ||
|
|
50
|
+
embedding.ok),
|
|
51
|
+
storage: {
|
|
52
|
+
ok: storageOk,
|
|
53
|
+
provider: this.storage.name,
|
|
54
|
+
},
|
|
55
|
+
embedding,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { loadConfig, } from "../core/index.js";
|
|
2
|
+
import { createEmbeddingProvider, } from "../embeddings/index.js";
|
|
3
|
+
import { ArchitectureEngine, CodeAnalysisEngine, RepositoryIndexer, RichGraphEnricher, SemanticCodeEngine, TypeScriptTypeResolver, VisualizationBuilder, } from "../code-intelligence/index.js";
|
|
4
|
+
import { createStorageProvider, PersistentArchitectureStore, PersistentCodeAnalysisStore, PersistentCodeGraphStore, PersistentTypeResolutionStore, PersistentVisualizationStore, ProjectScopedStorageProvider, withStorageRetry, } from "../storage/index.js";
|
|
5
|
+
export async function runProductionIndex(project, options = {}) {
|
|
6
|
+
const started = Date.now();
|
|
7
|
+
async function stage(id, title, run) {
|
|
8
|
+
await options.onStage?.({
|
|
9
|
+
id,
|
|
10
|
+
title,
|
|
11
|
+
state: "start",
|
|
12
|
+
});
|
|
13
|
+
const stageStarted = Date.now();
|
|
14
|
+
const result = await run();
|
|
15
|
+
await options.onStage?.({
|
|
16
|
+
id,
|
|
17
|
+
title,
|
|
18
|
+
state: "complete",
|
|
19
|
+
durationMs: Date.now() -
|
|
20
|
+
stageStarted,
|
|
21
|
+
});
|
|
22
|
+
return result;
|
|
23
|
+
}
|
|
24
|
+
const config = loadConfig();
|
|
25
|
+
const rawStorage = withStorageRetry(createStorageProvider({
|
|
26
|
+
provider: config.storage.provider,
|
|
27
|
+
huggingface: config.storage.huggingface,
|
|
28
|
+
localRoot: config.storage.localRoot,
|
|
29
|
+
}), {
|
|
30
|
+
attempts: 3,
|
|
31
|
+
});
|
|
32
|
+
const storage = new ProjectScopedStorageProvider(rawStorage, project.id, project.name, project.remote ??
|
|
33
|
+
project.name);
|
|
34
|
+
const graphStore = new PersistentCodeGraphStore(storage);
|
|
35
|
+
/*
|
|
36
|
+
* 1. SOURCE INDEX
|
|
37
|
+
*/
|
|
38
|
+
const indexed = await stage("source-index", "Source Index", async () => {
|
|
39
|
+
const result = await new RepositoryIndexer()
|
|
40
|
+
.index(project.id, project.rootPath);
|
|
41
|
+
await graphStore.save({
|
|
42
|
+
version: 1,
|
|
43
|
+
projectId: project.id,
|
|
44
|
+
updatedAt: new Date()
|
|
45
|
+
.toISOString(),
|
|
46
|
+
files: result.files,
|
|
47
|
+
symbols: result.graph
|
|
48
|
+
.allSymbols(project.id),
|
|
49
|
+
edges: result.graph
|
|
50
|
+
.allEdges(project.id),
|
|
51
|
+
});
|
|
52
|
+
return result;
|
|
53
|
+
});
|
|
54
|
+
const graph = indexed.graph;
|
|
55
|
+
/*
|
|
56
|
+
* 2. TYPE RESOLUTION
|
|
57
|
+
*/
|
|
58
|
+
const resolution = await stage("type-resolution", "Type Resolution", async () => {
|
|
59
|
+
const result = await new TypeScriptTypeResolver(graph).resolveProject(project.id, project.rootPath);
|
|
60
|
+
await new PersistentTypeResolutionStore(storage).save(result);
|
|
61
|
+
return result;
|
|
62
|
+
});
|
|
63
|
+
/*
|
|
64
|
+
* 3. RICH GRAPH
|
|
65
|
+
*/
|
|
66
|
+
await stage("rich-graph", "Rich Graph", async () => {
|
|
67
|
+
const stats = new RichGraphEnricher(graph).enrich(project.id, project.rootPath, resolution);
|
|
68
|
+
const symbols = graph.allSymbols(project.id);
|
|
69
|
+
const edges = graph.allEdges(project.id);
|
|
70
|
+
await graphStore.save({
|
|
71
|
+
version: 1,
|
|
72
|
+
projectId: project.id,
|
|
73
|
+
updatedAt: new Date()
|
|
74
|
+
.toISOString(),
|
|
75
|
+
files: symbols.filter(item => item.type ===
|
|
76
|
+
"file").length,
|
|
77
|
+
symbols,
|
|
78
|
+
edges,
|
|
79
|
+
});
|
|
80
|
+
return stats;
|
|
81
|
+
});
|
|
82
|
+
/*
|
|
83
|
+
* 4. SEMANTIC INDEX
|
|
84
|
+
*/
|
|
85
|
+
const semantic = await stage("semantic-index", "Semantic Code Index", async () => {
|
|
86
|
+
const engine = new SemanticCodeEngine({
|
|
87
|
+
projectId: project.id,
|
|
88
|
+
rootPath: project.rootPath,
|
|
89
|
+
model: process.env
|
|
90
|
+
.HF_EMBEDDING_MODEL ??
|
|
91
|
+
"sentence-transformers/all-MiniLM-L6-v2",
|
|
92
|
+
storage,
|
|
93
|
+
embeddings: createEmbeddingProvider(),
|
|
94
|
+
graph,
|
|
95
|
+
});
|
|
96
|
+
return engine.initialize();
|
|
97
|
+
});
|
|
98
|
+
/*
|
|
99
|
+
* 5. ARCHITECTURE
|
|
100
|
+
*/
|
|
101
|
+
const architecture = await stage("architecture", "Architecture Intelligence", async () => {
|
|
102
|
+
const result = new ArchitectureEngine(graph).analyze(project.id);
|
|
103
|
+
await new PersistentArchitectureStore(storage).save(result);
|
|
104
|
+
return result;
|
|
105
|
+
});
|
|
106
|
+
/*
|
|
107
|
+
* 6. ANALYSIS
|
|
108
|
+
*/
|
|
109
|
+
const analysis = await stage("analysis", "Graph Analysis", async () => {
|
|
110
|
+
const result = new CodeAnalysisEngine(graph).analyze(project.id);
|
|
111
|
+
await new PersistentCodeAnalysisStore(storage).save(result);
|
|
112
|
+
return result;
|
|
113
|
+
});
|
|
114
|
+
/*
|
|
115
|
+
* 7. VISUALIZATION
|
|
116
|
+
*/
|
|
117
|
+
const visualization = await stage("visualization", "3D Visualization Dataset", async () => {
|
|
118
|
+
const result = new VisualizationBuilder(graph).build(project.id, architecture, analysis);
|
|
119
|
+
await new PersistentVisualizationStore(storage).save(result);
|
|
120
|
+
return result;
|
|
121
|
+
});
|
|
122
|
+
return {
|
|
123
|
+
project: {
|
|
124
|
+
id: project.id,
|
|
125
|
+
name: project.name,
|
|
126
|
+
remote: project.remote ??
|
|
127
|
+
project.name,
|
|
128
|
+
},
|
|
129
|
+
storage: storage.name,
|
|
130
|
+
durationMs: Date.now() -
|
|
131
|
+
started,
|
|
132
|
+
graph: {
|
|
133
|
+
symbols: graph
|
|
134
|
+
.allSymbols(project.id)
|
|
135
|
+
.length,
|
|
136
|
+
edges: graph
|
|
137
|
+
.allEdges(project.id)
|
|
138
|
+
.length,
|
|
139
|
+
},
|
|
140
|
+
resolution: {
|
|
141
|
+
total: resolution.total,
|
|
142
|
+
exact: resolution.exact,
|
|
143
|
+
high: resolution.high,
|
|
144
|
+
fallback: resolution.fallback,
|
|
145
|
+
},
|
|
146
|
+
semantic,
|
|
147
|
+
architecture: architecture.summary,
|
|
148
|
+
analysis: analysis.summary,
|
|
149
|
+
visualization: visualization.summary,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { closeSync, mkdirSync, openSync, readFileSync, unlinkSync, writeFileSync, } from "node:fs";
|
|
2
|
+
import { tmpdir, } from "node:os";
|
|
3
|
+
import { join, } from "node:path";
|
|
4
|
+
function processAlive(pid) {
|
|
5
|
+
try {
|
|
6
|
+
process.kill(pid, 0);
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
catch (error) {
|
|
10
|
+
return (error?.code ===
|
|
11
|
+
"EPERM");
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export class ProjectLock {
|
|
15
|
+
acquired = false;
|
|
16
|
+
path;
|
|
17
|
+
exitHandler = () => {
|
|
18
|
+
this.releaseSync();
|
|
19
|
+
};
|
|
20
|
+
constructor(projectId) {
|
|
21
|
+
const root = join(tmpdir(), "toolnet-memory-locks");
|
|
22
|
+
mkdirSync(root, {
|
|
23
|
+
recursive: true,
|
|
24
|
+
});
|
|
25
|
+
const safeId = projectId.replace(/[^A-Za-z0-9_.-]/g, "_");
|
|
26
|
+
this.path =
|
|
27
|
+
join(root, `${safeId}.lock`);
|
|
28
|
+
}
|
|
29
|
+
async acquire() {
|
|
30
|
+
if (this.acquired) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
34
|
+
try {
|
|
35
|
+
const fd = openSync(this.path, "wx");
|
|
36
|
+
writeFileSync(fd, JSON.stringify({
|
|
37
|
+
pid: process.pid,
|
|
38
|
+
createdAt: new Date()
|
|
39
|
+
.toISOString(),
|
|
40
|
+
}));
|
|
41
|
+
closeSync(fd);
|
|
42
|
+
this.acquired =
|
|
43
|
+
true;
|
|
44
|
+
process.once("exit", this.exitHandler);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
if (error?.code !==
|
|
49
|
+
"EEXIST") {
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
let stale = true;
|
|
53
|
+
try {
|
|
54
|
+
const data = JSON.parse(readFileSync(this.path, "utf8"));
|
|
55
|
+
if (Number.isInteger(data.pid) &&
|
|
56
|
+
processAlive(data.pid)) {
|
|
57
|
+
stale =
|
|
58
|
+
false;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
stale =
|
|
63
|
+
true;
|
|
64
|
+
}
|
|
65
|
+
if (!stale) {
|
|
66
|
+
throw new Error("ToolNet Memory is already running for this project");
|
|
67
|
+
}
|
|
68
|
+
try {
|
|
69
|
+
unlinkSync(this.path);
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
// retry once
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
throw new Error("Unable to acquire ToolNet Memory project lock");
|
|
77
|
+
}
|
|
78
|
+
async release() {
|
|
79
|
+
this.releaseSync();
|
|
80
|
+
}
|
|
81
|
+
releaseSync() {
|
|
82
|
+
if (!this.acquired) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
unlinkSync(this.path);
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
// already removed
|
|
90
|
+
}
|
|
91
|
+
this.acquired =
|
|
92
|
+
false;
|
|
93
|
+
process.off("exit", this.exitHandler);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { join, } from "node:path";
|
|
2
|
+
import { ProjectManager, } from "../core/index.js";
|
|
3
|
+
import { sanitizeProjectFolder, } from "../storage/project/folder.js";
|
|
4
|
+
const project = new ProjectManager()
|
|
5
|
+
.detect();
|
|
6
|
+
const remote = sanitizeProjectFolder(project.remote ??
|
|
7
|
+
project.name);
|
|
8
|
+
console.log(JSON.stringify({
|
|
9
|
+
id: project.id,
|
|
10
|
+
name: project.name,
|
|
11
|
+
remote,
|
|
12
|
+
rootPath: project.rootPath,
|
|
13
|
+
localManifest: join(project.rootPath, ".toolnet", "project.json"),
|
|
14
|
+
remoteNamespace: `projects/${remote}/`,
|
|
15
|
+
isolation: "1 folder = 1 project = 1 remote namespace",
|
|
16
|
+
}, null, 2));
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { SnapshotManager, } from "../snapshot/index.js";
|
|
2
|
+
export async function restoreLatestSnapshot(storage, projectId) {
|
|
3
|
+
const manager = new SnapshotManager(storage);
|
|
4
|
+
const snapshots = await manager.list(projectId);
|
|
5
|
+
const latest = snapshots[0];
|
|
6
|
+
if (!latest) {
|
|
7
|
+
throw new Error("No snapshot available");
|
|
8
|
+
}
|
|
9
|
+
const result = await manager.restore(projectId, latest.id);
|
|
10
|
+
return {
|
|
11
|
+
snapshot: latest.id,
|
|
12
|
+
createdAt: latest.createdAt,
|
|
13
|
+
...result,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import "dotenv/config";
|
|
2
|
+
import { loadConfig, ProjectManager, } from "../core/index.js";
|
|
3
|
+
import { createStorageProvider, withStorageRetry, ProjectScopedStorageProvider, } from "../storage/index.js";
|
|
4
|
+
import { SnapshotManager, } from "../snapshot/index.js";
|
|
5
|
+
import { restoreLatestSnapshot, } from "./recovery.js";
|
|
6
|
+
async function main() {
|
|
7
|
+
const command = process.argv[2];
|
|
8
|
+
const config = loadConfig();
|
|
9
|
+
const project = new ProjectManager()
|
|
10
|
+
.detect();
|
|
11
|
+
const rawStorage = withStorageRetry(createStorageProvider({
|
|
12
|
+
provider: config.storage.provider,
|
|
13
|
+
huggingface: config.storage.huggingface,
|
|
14
|
+
localRoot: config.storage.localRoot,
|
|
15
|
+
}), {
|
|
16
|
+
attempts: 3,
|
|
17
|
+
});
|
|
18
|
+
const storage = new ProjectScopedStorageProvider(rawStorage, project.id, project.name, project.remote ?? project.name);
|
|
19
|
+
const manager = new SnapshotManager(storage);
|
|
20
|
+
if (command === "list") {
|
|
21
|
+
const list = await manager.list(project.id);
|
|
22
|
+
console.log(list.map((snapshot) => ({
|
|
23
|
+
id: snapshot.id,
|
|
24
|
+
createdAt: snapshot.createdAt,
|
|
25
|
+
reason: snapshot.reason,
|
|
26
|
+
})));
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (command === "create") {
|
|
30
|
+
const reason = process.argv
|
|
31
|
+
.slice(3)
|
|
32
|
+
.join(" ") ||
|
|
33
|
+
"manual-cli";
|
|
34
|
+
console.log(await manager.create(project.id, reason));
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (command === "restore") {
|
|
38
|
+
const id = process.argv[3];
|
|
39
|
+
if (!id) {
|
|
40
|
+
throw new Error("snapshot id required");
|
|
41
|
+
}
|
|
42
|
+
await manager.create(project.id, "before-cli-restore");
|
|
43
|
+
console.log(await manager.restore(project.id, id));
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
if (command ===
|
|
47
|
+
"recover-latest") {
|
|
48
|
+
console.log(await restoreLatestSnapshot(storage, project.id));
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
throw new Error("Usage: snapshot-cli list|create|restore|recover-latest");
|
|
52
|
+
}
|
|
53
|
+
main().catch((error) => {
|
|
54
|
+
console.error(error instanceof Error
|
|
55
|
+
? error.message
|
|
56
|
+
: error);
|
|
57
|
+
process.exit(1);
|
|
58
|
+
});
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { readFileSync, } from "node:fs";
|
|
2
|
+
import { loadConfig, ProjectManager, } from "../core/index.js";
|
|
3
|
+
import { createStorageProvider, ProjectScopedStorageProvider, withStorageRetry, } from "../storage/index.js";
|
|
4
|
+
import { ensureProjectManual, loadProjectManual, syncProjectManual, } from "./manager.js";
|
|
5
|
+
function after(args, flag) {
|
|
6
|
+
const index = args.indexOf(flag);
|
|
7
|
+
return index >=
|
|
8
|
+
0
|
|
9
|
+
? args[index + 1]
|
|
10
|
+
: undefined;
|
|
11
|
+
}
|
|
12
|
+
function storageFor(project) {
|
|
13
|
+
const config = loadConfig();
|
|
14
|
+
const raw = withStorageRetry(createStorageProvider({
|
|
15
|
+
provider: config.storage
|
|
16
|
+
.provider,
|
|
17
|
+
huggingface: config.storage
|
|
18
|
+
.huggingface,
|
|
19
|
+
localRoot: config.storage
|
|
20
|
+
.localRoot,
|
|
21
|
+
}), {
|
|
22
|
+
attempts: 3,
|
|
23
|
+
});
|
|
24
|
+
return new ProjectScopedStorageProvider(raw, project.id, project.name, project.remote ??
|
|
25
|
+
project.name);
|
|
26
|
+
}
|
|
27
|
+
async function main() {
|
|
28
|
+
const [command = "help", ...args] = process.argv.slice(2);
|
|
29
|
+
const project = new ProjectManager()
|
|
30
|
+
.detect(after(args, "--project") ??
|
|
31
|
+
process.cwd());
|
|
32
|
+
if (command ===
|
|
33
|
+
"init") {
|
|
34
|
+
const file = ensureProjectManual(project);
|
|
35
|
+
console.log(`✅ Project manual: ${file}`);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (command ===
|
|
39
|
+
"show") {
|
|
40
|
+
const manual = loadProjectManual(project, false);
|
|
41
|
+
if (!manual) {
|
|
42
|
+
console.log("No .toolnet/PROJECT.md yet.");
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
process.stdout.write(readFileSync(manual.path, "utf8"));
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (command ===
|
|
49
|
+
"sync") {
|
|
50
|
+
const manual = await syncProjectManual(project, storageFor(project));
|
|
51
|
+
console.log(JSON.stringify({
|
|
52
|
+
project: project.name,
|
|
53
|
+
path: manual.path,
|
|
54
|
+
digest: manual.digest,
|
|
55
|
+
bytes: manual.bytes,
|
|
56
|
+
rules: manual.rules.length,
|
|
57
|
+
enforce: manual.rules.filter(rule => rule.mode ===
|
|
58
|
+
"enforce").length,
|
|
59
|
+
advisory: manual.rules.filter(rule => rule.mode ===
|
|
60
|
+
"advisory").length,
|
|
61
|
+
}, null, 2));
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
console.log(`Project Manual
|
|
65
|
+
|
|
66
|
+
Commands:
|
|
67
|
+
init [--project PATH]
|
|
68
|
+
show [--project PATH]
|
|
69
|
+
sync [--project PATH]
|
|
70
|
+
`);
|
|
71
|
+
}
|
|
72
|
+
main().catch(error => {
|
|
73
|
+
console.error(error instanceof Error
|
|
74
|
+
? error.message
|
|
75
|
+
: error);
|
|
76
|
+
process.exit(1);
|
|
77
|
+
});
|