rename sc2 to sci and move old dev-part stuff into the c2vi part

This commit is contained in:
Sebastian Moser
2026-10-12 14:53:10 +02:00
parent 759e6cad66
commit a7db7da9d2
7 changed files with 392 additions and 8 deletions

View File

@@ -22,6 +22,10 @@ use spacetimedb_sdk::{
TableWithPrimaryKey, TableWithPrimaryKey,
}; };
static MIZE_SRC: &str = "/home/me/work/config/mize";
static SRC: &str = "/home/me/work/config";
static RSYNC_EXCLUDES: &str = "--exclude=node_modules --exclude=target --exclude=mize_config.toml --exclude=rust_dist --exclude=deno_dist --exclude=dist --exclude=result --exclude=pkg";
#[mize_part] #[mize_part]
#[derive(Default)] #[derive(Default)]
pub struct C2vi { pub struct C2vi {
@@ -53,6 +57,8 @@ impl C2vi {
} }
pub fn part_c2vi(mize: &mut Mize) -> MizeResult<()> { pub fn part_c2vi(mize: &mut Mize) -> MizeResult<()> {
c2vi_deploy_things(mize)?;
#[cfg(feature = "desktop")] #[cfg(feature = "desktop")]
if mize if mize
.get_config("c2vi.dash.enable") .get_config("c2vi.dash.enable")
@@ -82,6 +88,49 @@ pub fn part_c2vi(mize: &mut Mize) -> MizeResult<()> {
Ok(()) Ok(())
} }
fn c2vi_deploy_things(mize: &mut Mize) -> MizeResult<()> {
let mut cli = mize.get_part_native::<CliPart>("cli")?;
cli.set_command("dev");
cli.subcommand(
Command::new("deploy-lush").alias("dlu").arg(&bin_arg),
Box::new(move |matches: &ArgMatches, mize| remote_deploy(matches, mize, "lush")),
)?;
cli.subcommand(
Command::new("deploy-mac").alias("dmc").arg(&bin_arg),
Box::new(move |matches: &ArgMatches, mize| remote_deploy(matches, mize, "mac")),
)?;
cli.subcommand(
Command::new("deploy-files").alias("dfi").arg(&bin_arg),
Box::new(move |matches: &ArgMatches, mize| remote_deploy(matches, mize, "files")),
)?;
cli.subcommand(
Command::new("deploy-ppc").alias("dpp").arg(&bin_arg),
Box::new(move |matches: &ArgMatches, mize| remote_deploy(matches, mize, "ppc-hosting")),
)?;
cli.subcommand(
Command::new("deploy-nico").alias("dni").arg(&bin_arg),
Box::new(move |matches: &ArgMatches, mize| remote_deploy(matches, mize, "nico")),
)?;
cli.subcommand(
Command::new("deploy-main").alias("dma").arg(&bin_arg),
Box::new(main_deploy),
)?;
cli.subcommand(
Command::new("deploy-obsidian").alias("do").arg(&bin_arg),
Box::new(obsidian_deploy),
)?;
cli.subcommand(
Command::new("deploy-spacetime").alias("dsp").arg(&bin_arg),
Box::new(deploy_spacetime),
)?;
cli.subcommand(
Command::new("generate").alias("gen").arg(&bin_arg),
Box::new(md_generate),
)?;
Ok(())
}
#[cfg(feature = "desktop")] #[cfg(feature = "desktop")]
pub fn launch_c2vi_dashboard(mize: &mut Mize) { pub fn launch_c2vi_dashboard(mize: &mut Mize) {
use dioxus::desktop::{muda::Menu, Config, WindowBuilder}; use dioxus::desktop::{muda::Menu, Config, WindowBuilder};
@@ -707,3 +756,181 @@ fn dump_habitica_logs(mize: &mut Mize) -> MizeResult<()> {
Ok(()) Ok(())
}) })
} }
pub fn remote_deploy(matches: &ArgMatches, _: Mize, hostname: &str) -> MizeResult<()> {
unsafe {
/*
std::env::set_var(
"PATH",
"/home/me/work/path-extra/nix/var/nix/profiles/default/bin:/run/current-system/sw/bin:/home/me/.local/state/nix/profile/bin:/home/me/.nix-profile/bin",
);
*/
std::env::set_var("SRC", SRC);
std::env::set_var("HOSTNAME", hostname);
}
let mut do_mize_restart = false;
let bin = match matches.get_one::<String>("bin") {
Some(val) => val.to_owned(),
None => {
do_mize_restart = true;
format!("{}-os", hostname)
}
};
let remote_src_dir = match hostname {
"lush" => "/home/me/here/config",
"mac" => "/data/external/config",
"files" => "/home/files/here/config",
"nico" => "/root/work/config-c2vi",
"ppc-hosting" => "/root/host/c2vi-config",
_ => "main-idk",
};
let mize_store_dir = match hostname {
"lush" => "/home/me/host/mize",
"mac" => "/home/me/host/mize",
"files" => "/home/files/storage/files/mize",
"nico" => "/root/work/app-data/mize",
"ppc-hosting" => "/root/host/mize",
_ => "/tmp/idk",
};
let rclone_flag = match hostname {
"nico" => "--chown=root:root",
_ => "",
};
sh!(rsync -r -u -v -a --delete --perms $rclone_flag --include=".git/" --include=".git/**" --exclude="target" --mkpath $RSYNC_EXCLUDES $SRC/ $hostname:$remote_src_dir)?;
let ssh_cmd = format!(
r#"
if ! tmux has-session -t mize-deploy 2>/dev/null; then
echo "Created new tmux session...."
tmux new-session -d -s mize-deploy "nix develop git+file://{remote_src_dir}/mize#buildShell --max-jobs 1"
else
echo "using existing session..."
fi
tmux send-keys -t mize-deploy "DO_MIZE_RESTART={do_mize_restart}" Enter
tmux send-keys -t mize-deploy "cargo build --manifest-path {remote_src_dir}/Cargo.toml --bin {bin}" Enter
tmux send-keys -t mize-deploy 'BUILD_SUCCESS=$?' Enter
tmux send-keys -t mize-deploy '[[ "$BUILD_SUCCESS" == "0" ]] && echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH" > {mize_store_dir}/daemon.env' Enter
tmux send-keys -t mize-deploy '[[ "$BUILD_SUCCESS" == "0" ]] && echo "MIZE_CONFIG_FILES={mize_store_dir}/config.toml" >> {mize_store_dir}/daemon.env' Enter
tmux send-keys -t mize-deploy '[[ "$BUILD_SUCCESS" == "0" ]] && [[ "$HOSTNAME" == "nico" ]] && echo "PATH=/root/work/path-extra:$PATH" >> {mize_store_dir}/daemon.env' Enter
tmux send-keys -t mize-deploy '[[ "$BUILD_SUCCESS" == "0" ]] && [[ "$DO_MIZE_RESTART" == "true" ]] && systemctl --user restart mize' Enter
"#
);
sh!(ssh $hostname $ssh_cmd)?;
Ok(())
}
pub fn deploy_spacetime(_: &ArgMatches, _: Mize) -> MizeResult<()> {
unsafe {
/*
std::env::set_var(
"PATH",
"/home/me/work/path-extra/nix/var/nix/profiles/default/bin:/run/current-system/sw/bin:/home/me/.local/state/nix/profile/bin:/home/me/.nix-profile/bin",
);
*/
std::env::set_var("SRC", SRC);
}
let cmd = format!(
r#"
if ! tmux has-session -t mize-deploy 2>/dev/null; then
echo "Created new tmux session...."
systemd-run --user --scope --description="mize deploy tmux session" tmux new-session -d -s mize-deploy "nix develop git+file://$SRC/mize --impure"
else
echo "using existing session..."
tmux send-keys -t mize-deploy "echo hoooooooooooooo" Enter
fi
tmux send-keys -t mize-deploy "spacetime publish -p $SRC/mize/marts/spacetime/ --yes mize" Enter
"#
);
sh!(/bin/sh -c "$cmd")?;
Ok(())
}
pub fn obsidian_deploy(_: &ArgMatches, _: Mize) -> MizeResult<()> {
unsafe {
std::env::set_var(
"PATH",
"/home/me/work/path-extra/nix/var/nix/profiles/default/bin:/run/current-system/sw/bin:/home/me/.local/state/nix/profile/bin:/home/me/.nix-profile/bin",
);
std::env::set_var("SRC", SRC);
}
let cmd = format!(
r#"
if ! tmux has-session -t mize-deploy 2>/dev/null; then
echo "Created new tmux session...."
systemd-run --user --scope --description="mize deploy tmux session" tmux new-session -d -s mize-deploy "nix develop git+file://$SRC/mize --impure"
else
echo "using existing session..."
fi
tmux send-keys -t mize-deploy "deno run --config {SRC}/mize/apps/obsidian-plugin/deno.json build" Enter
tmux send-keys -t mize-deploy "cp -r {SRC}/mize/apps/obsidian-plugin/dist/* ~/work/things/.obsidian/plugins/mize/" Enter
"#
);
sh!(/bin/sh -c "$cmd")?;
Ok(())
}
pub fn main_deploy(_: &ArgMatches, _: Mize) -> MizeResult<()> {
unsafe {
std::env::set_var(
"PATH",
"/home/me/work/path-extra/nix/var/nix/profiles/default/bin:/run/current-system/sw/bin:/home/me/.local/state/nix/profile/bin:/home/me/.nix-profile/bin",
);
std::env::set_var("SRC", SRC);
}
let cmd = str!(
r#"
if ! tmux has-session -t mize-deploy 2>/dev/null; then
systemd-run --user --scope --description="mize deploy tmux session" tmux new-session -d -s mize-deploy "nix develop git+file://$SRC/mize#buildShell"
else
echo "using existing session..."
fi
tmux send-keys -t mize-deploy "cargo build --manifest-path $SRC/mize/Cargo.toml --bin mize" Enter
tmux send-keys -t mize-deploy 'echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH" > /home/me/work/app-data/mize/daemon.env' Enter
tmux send-keys -t mize-deploy "systemctl --user restart mize" Enter
"#
);
sh!(/bin/sh -c "$cmd")?;
Ok(())
}
pub fn nico_notes_sync_thread(mize: Mize) -> MizeResult<()> {
tracing::info!("starting nico_notes_sync_thread");
loop {
let res = sh!(/bin/bash -c r#"
cd /root/work/nico/notes/c2vi
git add .
git commit -m "nico notes sync"
git pull --rebase
git push
cd /root/work/nico/notes/nexus
git add .
git commit -m "nico nexus notes sync"
git pull --rebase
git push
cd /root/work/nico/notes/ppc-wiki
git add .
git commit -m "nico ppc-wiki notes sync"
git pull --rebase
git push
"#);
if let Err(e) = res {
tracing::error!("error in nico_notes_sync_thread: {}", e);
};
std::thread::sleep(std::time::Duration::from_mins(2));
}
}

View File

@@ -297,3 +297,59 @@ impl CliPart {
Ok(()) Ok(())
} }
} }
// impl smth like this to run cli commands in the daemon.
pub fn mize_thin_cli_client(bin_name: Option<&str>) -> MizeResult<()> {
use std::io::Write;
use std::os::unix::net::UnixStream;
let store_path =
std::env::var("MIZE_STORE").map_err(|_| mize_err!("MIZE_STORE not set in environment"))?;
let sock_path = store_path + "/sock";
println!("sock_path: {}", sock_path);
let mut cmd_line = std::env::args().collect::<Vec<_>>();
if let Some(bin_name) = bin_name {
cmd_line[0] = bin_name.to_owned();
}
let msg = MizeMessage::new_custom("cli", cmd_line, 0);
let mut stream = UnixStream::connect(sock_path)?;
stream.write_all(&msg.bytes())?;
// Optional: Ensure all buffered data is pushed to the socket
stream.flush()?;
let mut reader = BufReader::new(stream.try_clone()?);
loop {
let msg: Value = ciborium::from_reader(&mut reader)?;
let mut msg = MizeMessage::new(msg, 0);
match msg.cmd()? {
MessageCmd::Custom(kind) => {
if kind == "cli.done".into_item_data() {
break;
}
if kind == "cli.stdout".into_item_data() {
println!("{}", msg.data()?.value_string()?);
}
if kind == "cli.stderr".into_item_data() {
eprintln!("{}", msg.data()?.value_string()?);
}
if kind == "cli.spawn".into_item_data() {
let cmd = msg.data()?.value_string()?;
std::process::Command::new("/bin/sh")
.arg("-c")
.arg(&cmd)
.status()?;
let done_msg = MizeMessage::new_custom("cli.spawn_done", ItemData::new(), 0);
stream.write_all(&done_msg.bytes())?;
}
}
_ => {
continue;
}
}
}
Ok(())
}

17
marts/src/dev/mod.rs Normal file
View File

@@ -0,0 +1,17 @@
use mize::{Mize, MizeResult, MizeError, mize_err};
use crate::CliPart;
// spacetime gen command: sh!(RUST_LOG=error RUST_BACKTRACE=0 spacetime generate --build-options="--lint-dir=" -p $SRC/mize/marts/spacetime -o $SRC/mize/marts/generated/src/spacetime --lang rust)?;
pub fn part_dev(mize: &mut Mize) -> MizeResult<()> {
let mut cli = mize.get_part_native::<CliPart>("cli")?;
cli.set_command("dev");
let bin_arg = Arg::new("bin").short('b');
mize.add_name_only_part("dev");
Ok(())
}

View File

@@ -17,6 +17,11 @@ pub mod c2vi {
} }
pub use c2vi::part::*; pub use c2vi::part::*;
#[cfg(feature = "target-os")]
pub mod dev;
#[cfg(feature = "target-os")]
pub use dev::part_dev;
#[cfg(feature = "target-obsidian")] #[cfg(feature = "target-obsidian")]
pub mod obsidian; pub mod obsidian;
#[cfg(feature = "target-obsidian")] #[cfg(feature = "target-obsidian")]
@@ -40,7 +45,7 @@ pub mod matrix;
#[cfg(feature = "target-obsidian")] #[cfg(feature = "target-obsidian")]
pub use matrix::part_matrix; pub use matrix::part_matrix;
pub mod sc2; pub mod sci;
//#[cfg(feature = "target-os")] //#[cfg(feature = "target-os")]
//pub mod js; //pub mod js;

View File

@@ -1,7 +0,0 @@
use mize::*;
pub fn part_sc2(mize: &mut Mize) -> MizeResult<()> {
Ok(())
}

30
marts/src/sci/mod.rs Normal file
View File

@@ -0,0 +1,30 @@
use mize::*;
pub mod timetrack;
pub fn part_sci(mize: &mut Mize) -> MizeResult<()> {
part_add_thought(mize)?;
Ok(())
}
pub fn part_add_thought(mize: &mut Mize) -> MizeResult<()> {
use marts::generated::spacetime::add_thought;
let mut cli = mize.get_part_native::<marts::CliPart>("cli")?;
cli.set_command("sci");
cli.subcommand(Command::new("inputThought").alias("ti"), |matches, mut mize| {
let tmp_file = std::env::temp_dir().join(format!(
"sc2-input-thought-{}.txt",
chrono::Utc::now().timestamp()
));
marts::cli_spawn(format!("nvim {}", tmp_file.display()))?;
let new_file_content = std::fs::read_to_string(&tmp_file)
.map_err(|e| mize_err!("Failed to read temp file: {}", e))?;
let _ = std::fs::remove_file(&tmp_file);
let spacetime = mize.get_part_native::<marts::SpacetimePart>("spacetime")?;
spacetime.con().reducers.add_thought(new_file_content)?;
Ok(())
})?;
Ok(())
}

View File

@@ -23,6 +23,8 @@ pub struct TimeTrack {
} }
pub fn part_timetrack(mize: &mut Mize) -> MizeResult<()> { pub fn part_timetrack(mize: &mut Mize) -> MizeResult<()> {
part_timetrack_export(mize)?;
#[cfg(feature = "target-os")] { #[cfg(feature = "target-os")] {
let mut cli = mize.get_part_native::<crate::CliPart>("cli")?; let mut cli = mize.get_part_native::<crate::CliPart>("cli")?;
cli.set_command("sci"); cli.set_command("sci");
@@ -542,3 +544,57 @@ fn parse_activities_from_text(
Ok(()) Ok(())
} }
pub fn part_timetrack_export(mize: &mut Mize) -> MizeResult<()> {
use std::path::Path;
let mut cli = mize.get_part_native::<marts::CliPart>("cli")?;
cli.set_command("ppc");
cli.subcommand(Command::new("exportTimetrack").alias("et").arg(Arg::new("date").short('d')).arg(Arg::new("all").short('a').action(ArgAction::SetTrue)), |matches , mut mize| {
let spacetime = mize.get_part_native::<marts::SpacetimePart>("spacetime")?;
let notes_dir = mize.get_config("sc2.userNotesDir").unwrap_or_default().value_string()?;
let today = Local::now().format("%Y-%m-%d").to_string();
let mut date = matches.get_one::<String>("date").unwrap_or(&today);
std::fs::create_dir_all(Path::new(&notes_dir).join("timetrack_exports"))?;
let all = matches.get_flag("all");
if all {
let (tx, rx) = oneshot::channel();
spacetime.con().procedures.first_timetrack_date_then("c2vi".to_string(), |_, res| {tx.send(res);});
let res = rx.recv()???;
let dates = dates_until_today(&res)?;
for date in dates {
out!("date: {}", date);
let (tx, rx) = oneshot::channel();
spacetime.con().procedures.export_timetrack_then("c2vi".to_string(), date.to_owned(), |_, res| {tx.send(res);});
let res = rx.recv()???;
let mut file = OpenOptions::new().create(true).write(true).open(Path::new(&notes_dir).join("timetrack_exports").join(format!("timetrack_export_{}.md", date)))?;
file.write_all(res.as_bytes())?;
}
return Ok(());
}
out!("date: {}", date);
let (tx, rx) = oneshot::channel();
spacetime.con().procedures.export_timetrack_then("c2vi".to_string(), date.to_owned(), |_, res| {tx.send(res);});
let res = rx.recv()???;
let mut file = OpenOptions::new().create(true).write(true).open(Path::new(&notes_dir).join("timetrack_exports").join(format!("timetrack_export_{}.md", date)))?;
file.write_all(res.as_bytes())?;
Ok(())
})?;
Ok(())
}
fn dates_until_today(start: &str) -> Result<Vec<String>, chrono::ParseError> {
use chrono::NaiveDate;
let mut current = NaiveDate::parse_from_str(start, "%Y-%m-%d")?;
let today = Local::now().date_naive();
let mut dates = Vec::new();
while current <= today {
dates.push(current.format("%Y-%m-%d").to_string());
current += TimeDelta::days(1);
}
Ok(dates)
}