@swarmvaultai/engine 0.7.23 → 0.7.25

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.
@@ -0,0 +1,65 @@
1
+ // src/token-estimation.ts
2
+ function estimateTokens(text) {
3
+ if (!text) {
4
+ return 0;
5
+ }
6
+ let codeChars = 0;
7
+ let proseChars = 0;
8
+ for (const line of text.split("\n")) {
9
+ const trimmed = line.trim();
10
+ if (trimmed.startsWith("```") || trimmed.startsWith("- `") || trimmed.startsWith("import ") || trimmed.startsWith("export ") || trimmed.startsWith("const ") || trimmed.startsWith("function ") || trimmed.startsWith("class ") || trimmed.startsWith("def ") || trimmed.startsWith("fn ") || /^\s*[{}[\]();]/.test(trimmed) || /^\w+\s*[=:]\s*/.test(trimmed)) {
11
+ codeChars += line.length;
12
+ } else {
13
+ proseChars += line.length;
14
+ }
15
+ }
16
+ return Math.ceil(codeChars / 3 + proseChars / 4);
17
+ }
18
+ var KIND_WEIGHTS = {
19
+ index: 10,
20
+ graph_report: 8,
21
+ module: 7,
22
+ concept: 6,
23
+ source: 5,
24
+ community_summary: 5,
25
+ entity: 4,
26
+ output: 3,
27
+ insight: 2
28
+ };
29
+ function estimatePageTokens(pageId, path, kind, content, nodeDegree, confidence) {
30
+ const tokens = estimateTokens(content);
31
+ const kindWeight = KIND_WEIGHTS[kind] ?? 1;
32
+ const priority = kindWeight * (1 + (nodeDegree ?? 0) * 0.1) * (confidence ?? 0.5);
33
+ return { pageId, path, kind, tokens, priority };
34
+ }
35
+ function trimToTokenBudget(pages, maxTokens) {
36
+ const totalTokens = pages.reduce((sum, p) => sum + p.tokens, 0);
37
+ if (totalTokens <= maxTokens) {
38
+ return { kept: pages, dropped: [], totalTokens, budgetTokens: maxTokens, keptTokens: totalTokens };
39
+ }
40
+ const sorted = [...pages].sort((a, b) => b.priority - a.priority);
41
+ const kept = [];
42
+ const dropped = [];
43
+ let accumulated = 0;
44
+ for (const page of sorted) {
45
+ if (accumulated + page.tokens <= maxTokens) {
46
+ kept.push(page);
47
+ accumulated += page.tokens;
48
+ } else {
49
+ dropped.push(page);
50
+ }
51
+ }
52
+ return {
53
+ kept,
54
+ dropped,
55
+ totalTokens,
56
+ budgetTokens: maxTokens,
57
+ keptTokens: accumulated
58
+ };
59
+ }
60
+
61
+ export {
62
+ estimateTokens,
63
+ estimatePageTokens,
64
+ trimToTokenBudget
65
+ };
File without changes
File without changes
File without changes
package/dist/index.d.ts CHANGED
@@ -52,12 +52,12 @@ type Polarity = "positive" | "negative" | "neutral";
52
52
  type OutputOrigin = "query" | "explore" | "source_brief" | "source_review" | "source_guide" | "source_session";
53
53
  type OutputFormat = "markdown" | "report" | "slides" | "chart" | "image";
54
54
  type OutputAssetRole = "primary" | "preview" | "manifest" | "poster";
55
- type GraphExportFormat = "html" | "html-standalone" | "svg" | "graphml" | "cypher" | "json" | "obsidian" | "canvas";
55
+ type GraphExportFormat = "html" | "html-standalone" | "report" | "svg" | "graphml" | "cypher" | "json" | "obsidian" | "canvas";
56
56
  type PageStatus = "draft" | "candidate" | "active" | "archived";
57
57
  type PageManager = "system" | "human";
58
58
  type ApprovalEntryStatus = "pending" | "accepted" | "rejected";
59
59
  type ApprovalChangeType = "create" | "update" | "delete" | "promote";
60
- type ApprovalBundleType = "compile" | "generated_output" | "source_review" | "guided_source" | "guided_session";
60
+ type ApprovalBundleType = "compile" | "generated-output" | "source-review" | "guided-source" | "guided-session";
61
61
  type ApprovalEntryLabel = "source-brief" | "source-review" | "source-guide" | "guided-update";
62
62
  type GuidedSourceSessionStatus = "awaiting_input" | "ready_to_stage" | "staged" | "accepted" | "rejected";
63
63
  type VaultProfilePreset = "reader" | "timeline" | "diligence" | "thesis";
@@ -207,6 +207,11 @@ interface VaultConfig {
207
207
  deepLintProvider: string;
208
208
  };
209
209
  };
210
+ search?: {
211
+ hybrid?: boolean;
212
+ rerank?: boolean;
213
+ };
214
+ autoCommit?: boolean;
210
215
  }
211
216
  interface ResolvedPaths {
212
217
  rootDir: string;
@@ -687,9 +692,22 @@ interface CandidateRecord {
687
692
  createdAt: string;
688
693
  updatedAt: string;
689
694
  }
695
+ interface BlastRadiusResult {
696
+ target: string;
697
+ resolvedModuleId?: string;
698
+ affectedModules: Array<{
699
+ moduleId: string;
700
+ label: string;
701
+ depth: number;
702
+ }>;
703
+ totalAffected: number;
704
+ maxDepth: number;
705
+ summary: string;
706
+ }
690
707
  interface CompileOptions {
691
708
  approve?: boolean;
692
709
  codeOnly?: boolean;
710
+ maxTokens?: number;
693
711
  }
694
712
  interface InitOptions {
695
713
  obsidian?: boolean;
@@ -707,6 +725,12 @@ interface CompileResult {
707
725
  postPassApprovalDir?: string;
708
726
  promotedPageIds: string[];
709
727
  candidatePageCount: number;
728
+ tokenStats?: {
729
+ estimatedTokens: number;
730
+ maxTokens: number;
731
+ pagesKept: number;
732
+ pagesDropped: number;
733
+ };
710
734
  }
711
735
  interface SearchResult {
712
736
  pageId: string;
@@ -1328,6 +1352,10 @@ interface ScheduleController {
1328
1352
  declare function installAgent(rootDir: string, agent: AgentType, options?: InstallAgentOptions): Promise<InstallAgentResult>;
1329
1353
  declare function installConfiguredAgents(rootDir: string): Promise<InstallAgentResult[]>;
1330
1354
 
1355
+ declare function autoCommitWikiChanges(rootDir: string, operation: string, detail?: string, options?: {
1356
+ force?: boolean;
1357
+ }): Promise<string | null>;
1358
+
1331
1359
  declare function defaultVaultConfig(profile?: VaultProfileConfig): VaultConfig;
1332
1360
  declare function defaultVaultSchema(profile?: string | VaultProfileConfig): string;
1333
1361
  declare function resolvePaths(rootDir: string, config?: VaultConfig, configPath?: string, schemaPath?: string): ResolvedPaths;
@@ -1342,7 +1370,8 @@ declare function initWorkspace(rootDir: string, options?: {
1342
1370
  paths: ResolvedPaths;
1343
1371
  }>;
1344
1372
 
1345
- declare function exportGraphFormat(rootDir: string, format: Exclude<GraphExportFormat, "html" | "obsidian" | "canvas">, outputPath: string): Promise<GraphExportResult>;
1373
+ declare function exportGraphFormat(rootDir: string, format: Exclude<GraphExportFormat, "html" | "report" | "obsidian" | "canvas">, outputPath: string): Promise<GraphExportResult>;
1374
+ declare function exportGraphReportHtml(rootDir: string, outputPath: string): Promise<GraphExportResult>;
1346
1375
  declare function exportObsidianVault(rootDir: string, outputDir: string): Promise<GraphExportResult>;
1347
1376
  declare function exportObsidianCanvas(rootDir: string, outputPath: string): Promise<GraphExportResult>;
1348
1377
 
@@ -1364,6 +1393,13 @@ type GraphPushInternalOptions = GraphPushNeo4jOptions & {
1364
1393
  declare function pushGraphNeo4j(rootDir: string, options?: GraphPushInternalOptions): Promise<GraphPushResult>;
1365
1394
 
1366
1395
  declare function graphDiff(oldGraph: GraphArtifact, newGraph: GraphArtifact): GraphDiffResult;
1396
+ /**
1397
+ * Compute the blast radius of changing a file/module by tracing reverse import
1398
+ * edges via BFS. Returns all modules that transitively depend on the target.
1399
+ */
1400
+ declare function blastRadius(graph: GraphArtifact, target: string, options?: {
1401
+ maxDepth?: number;
1402
+ }): BlastRadiusResult;
1367
1403
 
1368
1404
  declare function getGitHookStatus(rootDir: string): Promise<GitHookStatus>;
1369
1405
  declare function installGitHooks(rootDir: string): Promise<GitHookStatus>;
@@ -1432,6 +1468,43 @@ declare function addManagedSource(rootDir: string, input: string, options?: Mana
1432
1468
  declare function reloadManagedSources(rootDir: string, options?: ManagedSourceReloadOptions): Promise<ManagedSourceReloadResult>;
1433
1469
  declare function deleteManagedSource(rootDir: string, id: string): Promise<ManagedSourceDeleteResult>;
1434
1470
 
1471
+ /**
1472
+ * LLM token estimation for context-window budgeting.
1473
+ *
1474
+ * Distinct from tokenize.ts (NLP tokenizer for search indexing).
1475
+ * This module estimates how many LLM tokens a piece of text will consume
1476
+ * and provides a priority-based trimming strategy for wiki output.
1477
+ */
1478
+ /**
1479
+ * Estimate the number of LLM tokens for a text string.
1480
+ * Uses a blended heuristic: ~4 chars/token for prose, ~3 chars/token for code.
1481
+ */
1482
+ declare function estimateTokens(text: string): number;
1483
+ interface PageTokenEstimate {
1484
+ pageId: string;
1485
+ path: string;
1486
+ kind: string;
1487
+ tokens: number;
1488
+ priority: number;
1489
+ }
1490
+ /**
1491
+ * Estimate tokens and priority for a wiki page.
1492
+ * Priority is based on page kind, node degree, and confidence.
1493
+ */
1494
+ declare function estimatePageTokens(pageId: string, path: string, kind: string, content: string, nodeDegree?: number, confidence?: number): PageTokenEstimate;
1495
+ interface TokenBudgetResult {
1496
+ kept: PageTokenEstimate[];
1497
+ dropped: PageTokenEstimate[];
1498
+ totalTokens: number;
1499
+ budgetTokens: number;
1500
+ keptTokens: number;
1501
+ }
1502
+ /**
1503
+ * Given a set of page estimates and a token budget, return which pages to keep.
1504
+ * Lower-priority pages are dropped first. The boundary page is truncated if needed.
1505
+ */
1506
+ declare function trimToTokenBudget(pages: PageTokenEstimate[], maxTokens: number): TokenBudgetResult;
1507
+
1435
1508
  type GeneratedOutputArtifacts = {
1436
1509
  answer: string;
1437
1510
  outputAssets: OutputAsset[];
@@ -1478,6 +1551,9 @@ declare function explainGraphVault(rootDir: string, target: string): Promise<Gra
1478
1551
  declare function listGraphHyperedges(rootDir: string, target?: string, limit?: number): Promise<GraphHyperedge[]>;
1479
1552
  declare function readGraphReport(rootDir: string): Promise<GraphReportArtifact | null>;
1480
1553
  declare function listGodNodes(rootDir: string, limit?: number): Promise<GraphNode[]>;
1554
+ declare function blastRadiusVault(rootDir: string, target: string, options?: {
1555
+ maxDepth?: number;
1556
+ }): Promise<BlastRadiusResult>;
1481
1557
  declare function listPages(rootDir: string): Promise<GraphPage[]>;
1482
1558
  declare function readPage(rootDir: string, relativePath: string): Promise<{
1483
1559
  path: string;
@@ -1534,4 +1610,4 @@ declare function getWatchStatus(rootDir: string): Promise<WatchStatusResult>;
1534
1610
  declare function createWebSearchAdapter(id: string, config: WebSearchProviderConfig, rootDir: string): Promise<WebSearchAdapter>;
1535
1611
  declare function getWebSearchAdapterForTask(rootDir: string, task: "deepLintProvider"): Promise<WebSearchAdapter>;
1536
1612
 
1537
- export { type AddOptions, type AddResult, type AgentType, type AnalyzedTerm, type ApprovalBundleType, type ApprovalChangeType, type ApprovalDetail, type ApprovalEntry, type ApprovalEntryDetail, type ApprovalEntryLabel, type ApprovalEntryStatus, type ApprovalManifest, type ApprovalSummary, type BenchmarkArtifact, type BenchmarkOptions, type BenchmarkQuestionResult, type BenchmarkSummary, type CandidateRecord, type ChartDatum, type ChartSpec, type ClaimStatus, type CodeAnalysis, type CodeDiagnostic, type CodeImport, type CodeIndexArtifact, type CodeIndexEntry, type CodeLanguage, type CodeSymbol, type CodeSymbolKind, type CommandRoleExecutorConfig, type CompileOptions, type CompileResult, type CompileState, type DirectoryIngestResult, type DirectoryIngestSkip, type EmbeddingCacheArtifact, type EmbeddingCacheEntry, type EvidenceClass, type ExploreOptions, type ExploreResult, type ExploreStepResult, type ExtractionClaim, type ExtractionKind, type ExtractionTerm, type Freshness, type GenerationAttachment, type GenerationRequest, type GenerationResponse, type GitHookStatus, type GraphArtifact, type GraphDiffResult, type GraphEdge, type GraphExplainNeighbor, type GraphExplainResult, type GraphExportFormat, type GraphExportResult, type GraphHyperedge, type GraphNode, type GraphPage, type GraphPathResult, type GraphPushCounts, type GraphPushNeo4jOptions, type GraphPushResult, type GraphQueryMatch, type GraphQueryResult, type GraphReportArtifact, type GuidedSessionMode, type GuidedSourceSessionAnswers, type GuidedSourceSessionQuestion, type GuidedSourceSessionRecord, type GuidedSourceSessionStatus, type ImageGenerationRequest, type ImageGenerationResponse, type ImageVisionExtraction, type InboxImportResult, type InboxImportSkip, type IngestOptions, type InitOptions, type InputIngestResult, type InstallAgentOptions, type InstallAgentResult, type LintFinding, type LintOptions, type ManagedSourceAddOptions, type ManagedSourceAddResult, type ManagedSourceDeleteResult, type ManagedSourceKind, type ManagedSourceRecord, type ManagedSourceReloadOptions, type ManagedSourceReloadResult, type ManagedSourceStatus, type ManagedSourceSyncCounts, type ManagedSourcesArtifact, type Neo4jGraphSinkConfig, type OrchestrationConfig, type OrchestrationFinding, type OrchestrationProposal, type OrchestrationRole, type OrchestrationRoleConfig, type OrchestrationRoleResult, type OutputAsset, type OutputAssetRole, type OutputFormat, type OutputOrigin, type PageKind, type PageManager, type PageStatus, type PendingSemanticRefreshEntry, type Polarity, type ProviderAdapter, type ProviderCapability, type ProviderConfig, type ProviderRoleExecutorConfig, type ProviderType, type QueryOptions, type QueryResult, type RepoSyncResult, type ResolvedPaths, type ReviewActionResult, type RoleExecutorConfig, type SceneElement, type SceneSpec, type ScheduleController, type ScheduleJobConfig, type ScheduleStateRecord, type ScheduleTriggerConfig, type ScheduledCompileTask, type ScheduledExploreTask, type ScheduledLintTask, type ScheduledQueryTask, type ScheduledRunResult, type ScheduledTaskConfig, type SearchResult, type SourceAnalysis, type SourceAttachment, type SourceCaptureType, type SourceClaim, type SourceClass, type SourceExtractionArtifact, type SourceGuideResult, type SourceKind, type SourceManifest, type SourceRationale, type SourceReviewResult, type VaultConfig, type VaultDashboardPack, type VaultProfileConfig, type VaultProfilePreset, type WatchController, type WatchOptions, type WatchRepoSyncResult, type WatchRunRecord, type WatchStatusResult, type WebSearchAdapter, type WebSearchProviderConfig, type WebSearchProviderType, type WebSearchResult, acceptApproval, addInput, addManagedSource, agentTypeSchema, archiveCandidate, assertProviderCapability, benchmarkVault, bootstrapDemo, compileVault, createMcpServer, createProvider, createWebSearchAdapter, defaultVaultConfig, defaultVaultSchema, deleteManagedSource, explainGraphVault, exploreVault, exportGraphFormat, exportGraphHtml, exportObsidianCanvas, exportObsidianVault, getGitHookStatus, getProviderForTask, getWatchStatus, getWebSearchAdapterForTask, getWorkspaceInfo, graphDiff, guideManagedSource, guideSourceScope, importInbox, ingestDirectory, ingestInput, ingestInputDetailed, initVault, initWorkspace, installAgent, installConfiguredAgents, installGitHooks, lintVault, listApprovals, listCandidates, listGodNodes, listGraphHyperedges, listManagedSourceRecords, listManifests, listPages, listSchedules, listTrackedRepoRoots, loadVaultConfig, loadVaultSchema, loadVaultSchemas, pathGraphVault, promoteCandidate, providerCapabilitySchema, providerTypeSchema, pushGraphNeo4j, queryGraphVault, queryVault, readApproval, readExtractedText, readGraphReport, readPage, rejectApproval, reloadManagedSources, resolvePaths, resumeSourceSession, reviewManagedSource, reviewSourceScope, runSchedule, runWatchCycle, searchVault, serveSchedules, stageGeneratedOutputPages, startGraphServer, startMcpServer, syncTrackedRepos, syncTrackedReposForWatch, uninstallGitHooks, watchVault, webSearchProviderTypeSchema };
1613
+ export { type AddOptions, type AddResult, type AgentType, type AnalyzedTerm, type ApprovalBundleType, type ApprovalChangeType, type ApprovalDetail, type ApprovalEntry, type ApprovalEntryDetail, type ApprovalEntryLabel, type ApprovalEntryStatus, type ApprovalManifest, type ApprovalSummary, type BenchmarkArtifact, type BenchmarkOptions, type BenchmarkQuestionResult, type BenchmarkSummary, type BlastRadiusResult, type CandidateRecord, type ChartDatum, type ChartSpec, type ClaimStatus, type CodeAnalysis, type CodeDiagnostic, type CodeImport, type CodeIndexArtifact, type CodeIndexEntry, type CodeLanguage, type CodeSymbol, type CodeSymbolKind, type CommandRoleExecutorConfig, type CompileOptions, type CompileResult, type CompileState, type DirectoryIngestResult, type DirectoryIngestSkip, type EmbeddingCacheArtifact, type EmbeddingCacheEntry, type EvidenceClass, type ExploreOptions, type ExploreResult, type ExploreStepResult, type ExtractionClaim, type ExtractionKind, type ExtractionTerm, type Freshness, type GenerationAttachment, type GenerationRequest, type GenerationResponse, type GitHookStatus, type GraphArtifact, type GraphDiffResult, type GraphEdge, type GraphExplainNeighbor, type GraphExplainResult, type GraphExportFormat, type GraphExportResult, type GraphHyperedge, type GraphNode, type GraphPage, type GraphPathResult, type GraphPushCounts, type GraphPushNeo4jOptions, type GraphPushResult, type GraphQueryMatch, type GraphQueryResult, type GraphReportArtifact, type GuidedSessionMode, type GuidedSourceSessionAnswers, type GuidedSourceSessionQuestion, type GuidedSourceSessionRecord, type GuidedSourceSessionStatus, type ImageGenerationRequest, type ImageGenerationResponse, type ImageVisionExtraction, type InboxImportResult, type InboxImportSkip, type IngestOptions, type InitOptions, type InputIngestResult, type InstallAgentOptions, type InstallAgentResult, type LintFinding, type LintOptions, type ManagedSourceAddOptions, type ManagedSourceAddResult, type ManagedSourceDeleteResult, type ManagedSourceKind, type ManagedSourceRecord, type ManagedSourceReloadOptions, type ManagedSourceReloadResult, type ManagedSourceStatus, type ManagedSourceSyncCounts, type ManagedSourcesArtifact, type Neo4jGraphSinkConfig, type OrchestrationConfig, type OrchestrationFinding, type OrchestrationProposal, type OrchestrationRole, type OrchestrationRoleConfig, type OrchestrationRoleResult, type OutputAsset, type OutputAssetRole, type OutputFormat, type OutputOrigin, type PageKind, type PageManager, type PageStatus, type PendingSemanticRefreshEntry, type Polarity, type ProviderAdapter, type ProviderCapability, type ProviderConfig, type ProviderRoleExecutorConfig, type ProviderType, type QueryOptions, type QueryResult, type RepoSyncResult, type ResolvedPaths, type ReviewActionResult, type RoleExecutorConfig, type SceneElement, type SceneSpec, type ScheduleController, type ScheduleJobConfig, type ScheduleStateRecord, type ScheduleTriggerConfig, type ScheduledCompileTask, type ScheduledExploreTask, type ScheduledLintTask, type ScheduledQueryTask, type ScheduledRunResult, type ScheduledTaskConfig, type SearchResult, type SourceAnalysis, type SourceAttachment, type SourceCaptureType, type SourceClaim, type SourceClass, type SourceExtractionArtifact, type SourceGuideResult, type SourceKind, type SourceManifest, type SourceRationale, type SourceReviewResult, type VaultConfig, type VaultDashboardPack, type VaultProfileConfig, type VaultProfilePreset, type WatchController, type WatchOptions, type WatchRepoSyncResult, type WatchRunRecord, type WatchStatusResult, type WebSearchAdapter, type WebSearchProviderConfig, type WebSearchProviderType, type WebSearchResult, acceptApproval, addInput, addManagedSource, agentTypeSchema, archiveCandidate, assertProviderCapability, autoCommitWikiChanges, benchmarkVault, blastRadius, blastRadiusVault, bootstrapDemo, compileVault, createMcpServer, createProvider, createWebSearchAdapter, defaultVaultConfig, defaultVaultSchema, deleteManagedSource, estimatePageTokens, estimateTokens, explainGraphVault, exploreVault, exportGraphFormat, exportGraphHtml, exportGraphReportHtml, exportObsidianCanvas, exportObsidianVault, getGitHookStatus, getProviderForTask, getWatchStatus, getWebSearchAdapterForTask, getWorkspaceInfo, graphDiff, guideManagedSource, guideSourceScope, importInbox, ingestDirectory, ingestInput, ingestInputDetailed, initVault, initWorkspace, installAgent, installConfiguredAgents, installGitHooks, lintVault, listApprovals, listCandidates, listGodNodes, listGraphHyperedges, listManagedSourceRecords, listManifests, listPages, listSchedules, listTrackedRepoRoots, loadVaultConfig, loadVaultSchema, loadVaultSchemas, pathGraphVault, promoteCandidate, providerCapabilitySchema, providerTypeSchema, pushGraphNeo4j, queryGraphVault, queryVault, readApproval, readExtractedText, readGraphReport, readPage, rejectApproval, reloadManagedSources, resolvePaths, resumeSourceSession, reviewManagedSource, reviewSourceScope, runSchedule, runWatchCycle, searchVault, serveSchedules, stageGeneratedOutputPages, startGraphServer, startMcpServer, syncTrackedRepos, syncTrackedReposForWatch, trimToTokenBudget, uninstallGitHooks, watchVault, webSearchProviderTypeSchema };