Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[target.wasm32-unknown-emscripten]
rustflags = [
"-C", "link-arg=-sINVOKE_RUN=0",
"-C", "link-arg=-sEXIT_RUNTIME=1",
"-C", "link-arg=-sMODULARIZE=1",
"-C", "link-arg=-sEXPORT_NAME=createPathModule",
"-C", "link-arg=-sEXPORTED_RUNTIME_METHODS=callMain,FS",
"-C", "link-arg=-sFORCE_FILESYSTEM=1",
"-C", "link-arg=-sALLOW_MEMORY_GROWTH=1",
"-C", "link-arg=-sENVIRONMENT=web",
"-C", "link-arg=-sSTACK_SIZE=1048576",
]
118 changes: 118 additions & 0 deletions .github/workflows/deploy-site.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
name: CI + Deploy

on:
push:
branches: [main]
pull_request:

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
components: clippy

- name: Cache cargo
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: cargo-test-${{ hashFiles('Cargo.lock') }}
restore-keys: cargo-test-

- name: Test
run: cargo test --workspace

- name: Clippy
run: cargo clippy --workspace -- -D warnings

deploy:
needs: test
runs-on: ubuntu-latest
permissions:
contents: read
deployments: write
pull-requests: write
steps:
- uses: actions/checkout@v4

- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-unknown-emscripten

- name: Cache cargo
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: cargo-wasm-${{ hashFiles('Cargo.lock') }}
restore-keys: cargo-wasm-

- name: Cache emsdk
uses: actions/cache@v4
with:
path: local/emsdk
key: emsdk-latest

- name: Build wasm
run: scripts/build-wasm.sh

- uses: pnpm/action-setup@v4
with:
version: latest

- uses: actions/setup-node@v4
with:
node-version: 20
cache: pnpm
cache-dependency-path: site/pnpm-lock.yaml

- name: Build site
run: cd site && pnpm install && pnpm run build

- name: Deploy to Cloudflare Pages
id: deploy
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: pages deploy site/_site --project-name=toolpath --branch=${{ github.head_ref || 'main' }}

- name: Comment preview URL on PR
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const body = `🔍 **Preview deployed:** ${process.env.DEPLOY_URL}`;
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const existing = comments.find(c => c.body.includes('Preview deployed:'));
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body,
});
}
env:
DEPLOY_URL: ${{ steps.deploy.outputs.deployment-url }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/target
/local
site/wasm/
9 changes: 8 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ license = "Apache-2.0"
[workspace.dependencies]
toolpath = { version = "0.1.3", path = "crates/toolpath" }
toolpath-git = { version = "0.1.2", path = "crates/toolpath-git" }
toolpath-claude = { version = "0.1.2", path = "crates/toolpath-claude" }
toolpath-claude = { version = "0.1.2", path = "crates/toolpath-claude", default-features = false }
toolpath-dot = { version = "0.1.2", path = "crates/toolpath-dot" }

serde = { version = "1.0", features = ["derive"] }
Expand All @@ -29,3 +29,10 @@ tokio = { version = "1.40", features = ["full"] }
notify = { version = "7", features = ["macos_kqueue"] }
similar = "2"
tempfile = "3.15"

[profile.wasm]
inherits = "release"
opt-level = "z"
lto = true
codegen-units = 1
strip = true
9 changes: 7 additions & 2 deletions crates/toolpath-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ path = "src/main.rs"
[dependencies]
toolpath = { workspace = true }
toolpath-git = { workspace = true }
toolpath-claude = { workspace = true }
toolpath-dot = { workspace = true }
clap = { workspace = true }
anyhow = { workspace = true }
Expand All @@ -24,7 +23,13 @@ serde_json = { workspace = true }
similar = { workspace = true }
chrono = { workspace = true }
tempfile = { workspace = true }
git2 = { workspace = true }
rand = "0.9"

[target.'cfg(not(target_os = "emscripten"))'.dependencies]
toolpath-claude = { workspace = true, features = ["watcher"] }
git2 = { workspace = true }

[target.'cfg(target_os = "emscripten")'.dependencies]
toolpath-claude = { workspace = true }

[dev-dependencies]
57 changes: 35 additions & 22 deletions crates/toolpath-cli/src/cmd_derive.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use anyhow::{Context, Result};
#[cfg(not(target_os = "emscripten"))]
use anyhow::Context;
use anyhow::Result;
use clap::Subcommand;
use std::path::PathBuf;

Expand Down Expand Up @@ -67,31 +69,42 @@ fn run_git(
title: Option<String>,
pretty: bool,
) -> Result<()> {
let repo_path = if repo_path.is_absolute() {
repo_path
} else {
std::env::current_dir()?.join(&repo_path)
};
#[cfg(target_os = "emscripten")]
{
let _ = (repo_path, branches, base, remote, title, pretty);
anyhow::bail!(
"'path derive git' requires a native environment with access to a git repository"
);
}

let repo = git2::Repository::open(&repo_path)
.with_context(|| format!("Failed to open repository at {:?}", repo_path))?;
#[cfg(not(target_os = "emscripten"))]
{
let repo_path = if repo_path.is_absolute() {
repo_path
} else {
std::env::current_dir()?.join(&repo_path)
};

let config = toolpath_git::DeriveConfig {
remote,
title,
base,
};
let repo = git2::Repository::open(&repo_path)
.with_context(|| format!("Failed to open repository at {:?}", repo_path))?;

let config = toolpath_git::DeriveConfig {
remote,
title,
base,
};

let doc = toolpath_git::derive(&repo, &branches, &config)?;
let doc = toolpath_git::derive(&repo, &branches, &config)?;

let json = if pretty {
doc.to_json_pretty()?
} else {
doc.to_json()?
};
let json = if pretty {
doc.to_json_pretty()?
} else {
doc.to_json()?
};

println!("{}", json);
Ok(())
println!("{}", json);
Ok(())
}
}

fn run_claude(project: String, session: Option<String>, all: bool, pretty: bool) -> Result<()> {
Expand Down Expand Up @@ -143,7 +156,7 @@ fn run_claude_with_manager(
Ok(())
}

#[cfg(test)]
#[cfg(all(test, not(target_os = "emscripten")))]
mod tests {
use super::*;

Expand Down
91 changes: 52 additions & 39 deletions crates/toolpath-cli/src/cmd_list.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use anyhow::{Context, Result};
#[cfg(not(target_os = "emscripten"))]
use anyhow::Context;
use anyhow::Result;
use clap::Subcommand;
use std::path::PathBuf;

Expand Down Expand Up @@ -30,49 +32,60 @@ pub fn run(source: ListSource, json: bool) -> Result<()> {
}

fn run_git(repo_path: PathBuf, remote: String, json: bool) -> Result<()> {
let repo_path = if repo_path.is_absolute() {
repo_path
} else {
std::env::current_dir()?.join(&repo_path)
};

let repo = git2::Repository::open(&repo_path)
.with_context(|| format!("Failed to open repository at {:?}", repo_path))?;

let uri = toolpath_git::get_repo_uri(&repo, &remote)?;
let branches = toolpath_git::list_branches(&repo)?;
#[cfg(target_os = "emscripten")]
{
let _ = (repo_path, remote, json);
anyhow::bail!(
"'path list git' requires a native environment with access to a git repository"
);
}

if json {
let items: Vec<serde_json::Value> = branches
.iter()
.map(|b| {
serde_json::json!({
"name": b.name,
"head": b.head,
"subject": b.subject,
"author": b.author,
"timestamp": b.timestamp,
#[cfg(not(target_os = "emscripten"))]
{
let repo_path = if repo_path.is_absolute() {
repo_path
} else {
std::env::current_dir()?.join(&repo_path)
};

let repo = git2::Repository::open(&repo_path)
.with_context(|| format!("Failed to open repository at {:?}", repo_path))?;

let uri = toolpath_git::get_repo_uri(&repo, &remote)?;
let branches = toolpath_git::list_branches(&repo)?;

if json {
let items: Vec<serde_json::Value> = branches
.iter()
.map(|b| {
serde_json::json!({
"name": b.name,
"head": b.head,
"subject": b.subject,
"author": b.author,
"timestamp": b.timestamp,
})
})
})
.collect();
let output = serde_json::json!({
"source": "git",
"uri": uri,
"branches": items,
});
println!("{}", serde_json::to_string_pretty(&output)?);
} else {
println!("Repository: {}", uri);
println!();
if branches.is_empty() {
println!(" (no local branches)");
.collect();
let output = serde_json::json!({
"source": "git",
"uri": uri,
"branches": items,
});
println!("{}", serde_json::to_string_pretty(&output)?);
} else {
for b in &branches {
println!(" {} {} {}", b.head_short, b.name, truncate(&b.subject, 60));
println!("Repository: {}", uri);
println!();
if branches.is_empty() {
println!(" (no local branches)");
} else {
for b in &branches {
println!(" {} {} {}", b.head_short, b.name, truncate(&b.subject, 60));
}
}
}
Ok(())
}
Ok(())
}

fn run_claude(project: Option<String>, json: bool) -> Result<()> {
Expand Down Expand Up @@ -167,7 +180,7 @@ fn truncate(s: &str, max: usize) -> String {
}
}

#[cfg(test)]
#[cfg(all(test, not(target_os = "emscripten")))]
mod tests {
use super::*;

Expand Down
2 changes: 1 addition & 1 deletion crates/toolpath-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use clap::{Parser, Subcommand};
use std::path::PathBuf;

#[derive(Parser, Debug)]
#[command(name = "path")]
#[command(name = "path", version)]
#[command(about = "Derive, query, and visualize Toolpath provenance documents")]
struct Cli {
#[command(subcommand)]
Expand Down
4 changes: 3 additions & 1 deletion crates/toolpath-git/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ categories = ["development-tools"]

[dependencies]
toolpath = { workspace = true }
git2 = { workspace = true }
chrono = { workspace = true }
anyhow = { workspace = true }

[target.'cfg(not(target_os = "emscripten"))'.dependencies]
git2 = { workspace = true }

[dev-dependencies]
tempfile = "3"
Loading