Skip to main content

open_kioku_cli/
lib.rs

1use anyhow::Context;
2use clap::{Args, Parser, Subcommand, ValueEnum};
3use open_kioku_architecture::{
4    evaluate_policy, evaluate_public_api_boundary, ArchitectureDetector, PolicyResolver,
5};
6use open_kioku_config::{
7    load_architecture_policy, load_architecture_policy_from_path, ArchitecturePolicy, OkConfig,
8    PolicySource, RankingConfig, ScipMode,
9};
10use open_kioku_context::{expanded_task_search_terms, ContextPackBuilder, ContextPackFormat};
11use open_kioku_context_compress::ContextHandleStore;
12use open_kioku_contract::{
13    ApiSurfaceConstraint, ChangeContractV1, ContractFile, ContractId, ContractStore,
14    DependencyDeltaConstraint, FsContractStore, StoredContractRecord,
15};
16use open_kioku_core::{
17    ChurnSummary, Confidence, ContextHandleId, EdgeId, EnforcedEdgeType, Evidence, EvidenceId,
18    EvidenceSourceType, FileProvenance, GitChangeKind, GitCochangeEdge, GitCommitId,
19    GitCommitRecord, GraphEdge, GraphEdgeType, GraphNode, HistoryRecordId, HistorySnapshot,
20    HistorySummary, IndexManifest, IndexMode, NodeId, Owner, OwnerSuggestion, OwnershipEvidence,
21    OwnershipReport, OwnershipSourceType, PlanReport, PolicyCheckReport, PolicyComponentMatch,
22    PolicyExemptionEvidence, PolicyViolation, ProvenanceTouch, ReviewerAvailability,
23    ReviewerEvidence, ReviewerRole, ReviewerSuggestionReport, ScoreComponent, SearchResult,
24    SimilarChangeQuery, SimilarChangeReport, Symbol, SymbolId, SymbolProvenance,
25};
26use open_kioku_graph::InMemoryGraph;
27use open_kioku_impact::ImpactEngine;
28use open_kioku_ingest::{IndexProgress, Indexer};
29use open_kioku_memory::RepoMemoryStore;
30use open_kioku_patch::{
31    ChangeVerificationReport, ChangeVerifier, ContractVerificationReport, ContractVerifier,
32    PatchPlanner, VerificationVerdict, VerifyChangeInput,
33};
34use open_kioku_plan::{ContractBuilder, PlanEngine, PlanFormat};
35use open_kioku_ranking::{
36    rerank_baseline, rerank_with_options, top_score_signals, RankingMode, RankingOptions,
37    RankingSignal, RankingWeights,
38};
39use open_kioku_search_regex::search_chunks;
40use open_kioku_search_tantivy::{
41    default_index_dir, rebuild_disk_index_with_graph, TantivySearchIndex,
42};
43use open_kioku_semantic::SemanticIndexManager;
44use open_kioku_storage::{
45    GraphStore, HistoryStore, IndexData, MetadataStore, OkStore, SearchIndex,
46};
47use open_kioku_storage_sqlite::{SqliteStore, SQLITE_SUPPORTED_INDEX_SCHEMA_VERSION};
48use open_kioku_symbols::SymbolEngine;
49use open_kioku_tests::TestSelector;
50use rusqlite::{params, Connection, OpenFlags, OptionalExtension};
51use serde::{Deserialize, Serialize};
52use sha2::{Digest, Sha256};
53use std::collections::{BTreeMap, BTreeSet, HashMap};
54use std::fmt;
55use std::fs::{self, File};
56use std::io::Write;
57use std::path::{Path, PathBuf};
58use std::process::Command as ProcessCommand;
59use std::sync::{Arc, Mutex};
60use std::thread;
61use std::time::{Duration, Instant};
62
63include!("types.rs");
64include!("commands/mod.rs");
65include!("commands/architecture.rs");
66include!("reports/status_setup_doctor.rs");
67include!("bench/mod.rs");
68include!("commands/verification.rs");
69include!("commands/contract.rs");
70include!("reports/ranking.rs");
71include!("reports/proof.rs");
72include!("commands/context.rs");
73include!("commands/index.rs");
74include!("commands/snapshot.rs");
75include!("search.rs");
76
77#[cfg(test)]
78mod tests {
79    use super::*;
80
81    #[test]
82    fn resolve_repo_prefers_command_path_over_global_default() {
83        assert_eq!(
84            resolve_repo(Path::new("."), PathBuf::from("/tmp/open-kioku-target")),
85            PathBuf::from("/tmp/open-kioku-target")
86        );
87    }
88
89    #[test]
90    fn resolve_repo_uses_global_path_when_command_path_is_default() {
91        assert_eq!(
92            resolve_repo(Path::new("/tmp/open-kioku-global"), PathBuf::from(".")),
93            PathBuf::from("/tmp/open-kioku-global")
94        );
95    }
96}