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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "clawshell"
version = "0.2.0"
version = "0.2.1"
edition = "2024"
license-file = "LICENSE"
homepage = "https://clawshell.org/"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ sudo clawshell config --edit # open in $EDITOR
A minimal config looks like this:

```toml
version = "0.2.0"
version = "0.2.1"
log_level = "info"

[server]
Expand Down
2 changes: 1 addition & 1 deletion clawshell.example.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ClawShell Configuration
version = "0.2.0"
version = "0.2.1"

# Log level: trace, debug, info, warn, error
log_level = "info"
Expand Down
2 changes: 1 addition & 1 deletion npm/clawshell-darwin-arm64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@clawshell/clawshell-darwin-arm64",
"version": "0.2.0",
"version": "0.2.1",
"description": "ClawShell binary for macOS ARM64 (Apple Silicon)",
"license": "Apache-2.0",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion npm/clawshell-linux-arm64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@clawshell/clawshell-linux-arm64",
"version": "0.2.0",
"version": "0.2.1",
"description": "ClawShell binary for Linux ARM64",
"license": "Apache-2.0",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion npm/clawshell-linux-x64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@clawshell/clawshell-linux-x64",
"version": "0.2.0",
"version": "0.2.1",
"description": "ClawShell binary for Linux x64",
"license": "Apache-2.0",
"repository": {
Expand Down
8 changes: 4 additions & 4 deletions npm/clawshell/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@clawshell/clawshell",
"version": "0.2.0",
"version": "0.2.1",
"description": "The essential safety harness for OpenClaw's PII & API data",
"license": "Apache-2.0",
"repository": {
Expand All @@ -12,9 +12,9 @@
"clawshell": "bin/clawshell.js"
},
"optionalDependencies": {
"@clawshell/clawshell-darwin-arm64": "0.2.0",
"@clawshell/clawshell-linux-arm64": "0.2.0",
"@clawshell/clawshell-linux-x64": "0.2.0"
"@clawshell/clawshell-darwin-arm64": "0.2.1",
"@clawshell/clawshell-linux-arm64": "0.2.1",
"@clawshell/clawshell-linux-x64": "0.2.1"
},
"engines": {
"node": ">=16"
Expand Down
62 changes: 62 additions & 0 deletions src/migration/targets/clawshell_toml/versions/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod to_v0_1_0_alpha_0;
mod to_v0_2_1;

use crate::migration::core::{AmbiguityResolver, ConfigVersion};
use crate::migration::target::TargetError;
Expand Down Expand Up @@ -33,6 +34,13 @@ pub fn apply_versioned_steps(
output.merge(step_output);
}

let v0_2_1: ConfigVersion = "0.2.1".parse().expect("literal config version must parse");

if from < &v0_2_1 && to >= &v0_2_1 {
let step_output = to_v0_2_1::apply(target_name, table, resolver)?;
output.merge(step_output);
}

Ok(output)
}

Expand Down Expand Up @@ -105,4 +113,58 @@ openai_base_url = "https://api.openai.com"
assert!(output.applied_steps.is_empty());
assert!(output.warnings.is_empty());
}

#[test]
fn test_apply_versioned_steps_adds_stats_from_0_1_1() {
let mut table: toml::value::Table = toml::from_str(
r#"
version = "0.1.1"

[server]
host = "127.0.0.1"
[upstream]
openai_base_url = "https://api.openai.com"
"#,
)
.unwrap();

let from: ConfigVersion = "0.1.1".parse().unwrap();
let to: ConfigVersion = "0.2.1".parse().unwrap();

let mut resolver = NoopResolver;
let output = apply_versioned_steps("clawshell", &mut table, &from, &to, &mut resolver)
.expect("migration should succeed");

assert!(output.applied_steps.iter().any(|s| s.contains("[stats]")));
let stats = table.get("stats").unwrap().as_table().unwrap();
assert_eq!(
stats.get("persist_path").unwrap().as_str().unwrap(),
"/etc/clawshell/stats.json"
);
}

#[test]
fn test_apply_versioned_steps_adds_stats_from_0_2_0() {
let mut table: toml::value::Table = toml::from_str(
r#"
version = "0.2.0"

[server]
host = "127.0.0.1"
[upstream]
openai_base_url = "https://api.openai.com"
"#,
)
.unwrap();

let from: ConfigVersion = "0.2.0".parse().unwrap();
let to: ConfigVersion = "0.2.1".parse().unwrap();

let mut resolver = NoopResolver;
let output = apply_versioned_steps("clawshell", &mut table, &from, &to, &mut resolver)
.expect("migration should succeed");

assert!(output.applied_steps.iter().any(|s| s.contains("[stats]")));
assert!(table.contains_key("stats"));
}
}
93 changes: 93 additions & 0 deletions src/migration/targets/clawshell_toml/versions/to_v0_2_1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
use crate::migration::core::AmbiguityResolver;
use crate::migration::target::TargetError;

use super::VersionStepOutput;

const STEP_ID: &str = "add `[stats]` section with default persist_path";

pub fn apply(
_target_name: &str,
table: &mut toml::value::Table,
_resolver: &mut dyn AmbiguityResolver,
) -> Result<VersionStepOutput, TargetError> {
let mut output = VersionStepOutput::default();

if !table.contains_key("stats") {
let mut stats = toml::value::Table::new();
stats.insert(
"persist_path".to_string(),
toml::Value::String("/etc/clawshell/stats.json".to_string()),
);
table.insert("stats".to_string(), toml::Value::Table(stats));
output.applied_steps.push(STEP_ID.to_string());
}

Ok(output)
}

#[cfg(test)]
mod tests {
use super::*;
use crate::migration::core::{AmbiguityResolutionError, AmbiguousChoice, MigrationIssue};

#[derive(Debug)]
struct NoopResolver;

impl AmbiguityResolver for NoopResolver {
fn resolve(
&mut self,
_issue: &MigrationIssue,
) -> Result<AmbiguousChoice, AmbiguityResolutionError> {
Ok(AmbiguousChoice::ApplyRecommended)
}
}

#[test]
fn test_injects_stats_when_missing() {
let mut table: toml::value::Table = toml::from_str(
r#"
[server]
host = "127.0.0.1"
[upstream]
openai_base_url = "https://api.openai.com"
"#,
)
.unwrap();

let mut resolver = NoopResolver;
let output = apply("clawshell", &mut table, &mut resolver).unwrap();
assert_eq!(output.applied_steps.len(), 1);
assert!(output.applied_steps[0].contains("[stats]"));

let stats = table.get("stats").unwrap().as_table().unwrap();
assert_eq!(
stats.get("persist_path").unwrap().as_str().unwrap(),
"/etc/clawshell/stats.json"
);
}

#[test]
fn test_skips_when_stats_already_present() {
let mut table: toml::value::Table = toml::from_str(
r#"
[server]
host = "127.0.0.1"
[upstream]
openai_base_url = "https://api.openai.com"
[stats]
persist_path = "/custom/path/stats.json"
"#,
)
.unwrap();

let mut resolver = NoopResolver;
let output = apply("clawshell", &mut table, &mut resolver).unwrap();
assert!(output.applied_steps.is_empty());

let stats = table.get("stats").unwrap().as_table().unwrap();
assert_eq!(
stats.get("persist_path").unwrap().as_str().unwrap(),
"/custom/path/stats.json"
);
}
}
Loading