Skip to content

Commit ac69b71

Browse files
committed
feat: include commit history in viz export
- Add VizCommit struct to viz module for serializing commits - Include commits array in VizExport (default empty, skip if empty) - Update push --viz to populate commits from db.log() - Update export --format viz-json to include commits - Export VizCommit from lib.rs
1 parent cc269a5 commit ac69b71

4 files changed

Lines changed: 54 additions & 6 deletions

File tree

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub use remote::{Remote, RemoteConfig, SyncClient, SyncConfig, SyncState, PullRe
4646
pub use remote::refresh_access_token;
4747
pub use search::SearchResult;
4848
pub use store::ObjectStore;
49-
pub use viz::{VizExport, VizMeta, VizThought};
49+
pub use viz::{VizCommit, VizExport, VizMeta, VizThought};
5050

5151
#[cfg(feature = "viz")]
5252
pub use viz::project_to_3d;

src/main.rs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,20 @@ fn main() -> anyhow::Result<()> {
882882
#[cfg(feature = "viz")]
883883
let viz_export = if viz {
884884
let thoughts = db.list_thoughts()?;
885-
Some(indra_db::project_to_3d(&thoughts)?)
885+
let commits = db.log(None)?;
886+
let mut export = indra_db::project_to_3d(&thoughts)?;
887+
// Add commit history to viz export
888+
export.commits = commits
889+
.into_iter()
890+
.map(|(hash, commit)| indra_db::VizCommit {
891+
hash: hash.to_hex(),
892+
message: commit.message,
893+
author: commit.author,
894+
timestamp: commit.timestamp,
895+
parents: commit.parents.into_iter().map(|p| p.to_hex()).collect(),
896+
})
897+
.collect();
898+
Some(export)
886899
} else {
887900
None
888901
};
@@ -1664,7 +1677,20 @@ fn main() -> anyhow::Result<()> {
16641677
)?;
16651678

16661679
let thoughts = db.list_thoughts()?;
1667-
let viz_export = indra_db::project_to_3d(&thoughts)?;
1680+
let commits = db.log(None)?;
1681+
let mut viz_export = indra_db::project_to_3d(&thoughts)?;
1682+
1683+
// Add commit history
1684+
viz_export.commits = commits
1685+
.into_iter()
1686+
.map(|(hash, commit)| indra_db::VizCommit {
1687+
hash: hash.to_hex(),
1688+
message: commit.message,
1689+
author: commit.author,
1690+
timestamp: commit.timestamp,
1691+
parents: commit.parents.into_iter().map(|p| p.to_hex()).collect(),
1692+
})
1693+
.collect();
16681694

16691695
let json = serde_json::to_string_pretty(&viz_export)?;
16701696

@@ -1677,7 +1703,8 @@ fn main() -> anyhow::Result<()> {
16771703
"message": format!("Exported to {}", path.display()),
16781704
"thoughts": viz_export.meta.total_thoughts,
16791705
"embedded": viz_export.meta.embedded_thoughts,
1680-
"method": viz_export.meta.reduction_method
1706+
"method": viz_export.meta.reduction_method,
1707+
"commits": viz_export.commits.len()
16811708
}),
16821709
);
16831710
} else {

src/viz/mod.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,29 @@ pub struct VizThought {
2929
pub created_at: u64,
3030
}
3131

32+
/// A commit in visualization export format
33+
#[derive(Debug, Clone, Serialize, Deserialize)]
34+
pub struct VizCommit {
35+
/// The commit hash
36+
pub hash: String,
37+
/// Commit message
38+
pub message: String,
39+
/// Author identifier
40+
pub author: String,
41+
/// Timestamp (unix millis)
42+
pub timestamp: u64,
43+
/// Parent commit hashes
44+
pub parents: Vec<String>,
45+
}
46+
3247
/// Export format for visualization data
3348
#[derive(Debug, Clone, Serialize, Deserialize)]
3449
pub struct VizExport {
3550
/// The thoughts with 3D positions
3651
pub thoughts: Vec<VizThought>,
52+
/// Commit history (newest first)
53+
#[serde(default, skip_serializing_if = "Vec::is_empty")]
54+
pub commits: Vec<VizCommit>,
3755
/// Metadata about the export
3856
pub meta: VizMeta,
3957
}

src/viz/pca.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! PCA-based dimensionality reduction for visualization
22
3-
use crate::model::Thought;
4-
use crate::viz::{VizExport, VizMeta, VizThought};
3+
use crate::model::{Commit, Thought};
4+
use crate::viz::{VizCommit, VizExport, VizMeta, VizThought};
55
use crate::Result;
66

77
use linfa::traits::{Fit, Transformer};
@@ -31,6 +31,7 @@ pub fn project_to_3d(thoughts: &[Thought]) -> Result<VizExport> {
3131

3232
return Ok(VizExport {
3333
thoughts: viz_thoughts,
34+
commits: vec![],
3435
meta: VizMeta {
3536
total_thoughts: thoughts.len(),
3637
embedded_thoughts: 0,
@@ -82,6 +83,7 @@ pub fn project_to_3d(thoughts: &[Thought]) -> Result<VizExport> {
8283

8384
return Ok(VizExport {
8485
thoughts: viz_thoughts,
86+
commits: vec![],
8587
meta: VizMeta {
8688
total_thoughts: thoughts.len(),
8789
embedded_thoughts: embedded.len(),
@@ -196,6 +198,7 @@ pub fn project_to_3d(thoughts: &[Thought]) -> Result<VizExport> {
196198

197199
Ok(VizExport {
198200
thoughts: viz_thoughts,
201+
commits: vec![],
199202
meta: VizMeta {
200203
total_thoughts: thoughts.len(),
201204
embedded_thoughts: embedded.len(),

0 commit comments

Comments
 (0)