@pheem49/mint 1.5.5 → 1.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.codex +0 -0
- package/.github/FUNDING.yml +2 -0
- package/.github/workflows/ci.yml +45 -0
- package/.github/workflows/release.yml +79 -0
- package/Cargo.lock +5792 -0
- package/Cargo.toml +32 -0
- package/README.md +387 -353
- package/assets/icon.png +0 -0
- package/bin/mint +0 -0
- package/crates/mint-cli/Cargo.toml +23 -0
- package/crates/mint-cli/src/agent.rs +851 -0
- package/crates/mint-cli/src/gmail.rs +216 -0
- package/crates/mint-cli/src/image.rs +142 -0
- package/crates/mint-cli/src/main.rs +2837 -0
- package/crates/mint-cli/src/mcp.rs +63 -0
- package/crates/mint-cli/src/onboard.rs +1149 -0
- package/crates/mint-cli/src/setup.rs +390 -0
- package/crates/mint-cli/src/skills.rs +8 -0
- package/crates/mint-cli/src/updater.rs +279 -0
- package/crates/mint-core/Cargo.toml +22 -0
- package/crates/mint-core/src/agent_loop.rs +94 -0
- package/crates/mint-core/src/api_server.rs +991 -0
- package/crates/mint-core/src/channels.rs +248 -0
- package/crates/mint-core/src/chat.rs +895 -0
- package/crates/mint-core/src/code_tools.rs +729 -0
- package/crates/mint-core/src/config.rs +368 -0
- package/crates/mint-core/src/files.rs +159 -0
- package/crates/mint-core/src/knowledge.rs +541 -0
- package/crates/mint-core/src/lib.rs +84 -0
- package/crates/mint-core/src/mcp.rs +273 -0
- package/crates/mint-core/src/memory.rs +673 -0
- package/crates/mint-core/src/orchestration.rs +2157 -0
- package/crates/mint-core/src/pictures.rs +314 -0
- package/crates/mint-core/src/plugins.rs +727 -0
- package/crates/mint-core/src/safety.rs +416 -0
- package/crates/mint-core/src/semantic.rs +254 -0
- package/crates/mint-core/src/shell.rs +317 -0
- package/crates/mint-core/src/skills.rs +71 -0
- package/crates/mint-core/src/symbols.rs +157 -0
- package/crates/mint-core/src/tasks.rs +308 -0
- package/crates/mint-core/src/tts.rs +92 -0
- package/crates/mint-core/src/weather.rs +93 -0
- package/crates/mint-core/src/web_search.rs +200 -0
- package/crates/mint-core/src/workflows.rs +81 -0
- package/crates/mint-core/tests/mcp_stdio.rs +45 -0
- package/crates/mint-core/tests/memory_persistence.rs +172 -0
- package/crates/mint-core/tests/pictures_storage.rs +14 -0
- package/crates/mint-core/tests/task_lifecycle.rs +87 -0
- package/package.json +35 -99
- package/src/bin/index.js +16 -0
- package/src/renderer/index-web.html +17 -0
- package/src/renderer/index.html +17 -0
- package/src/renderer/public/Live2DCubismCore.js +9 -0
- package/src/renderer/public/assets/icon.png +0 -0
- package/src/renderer/public/models/Shiroko_Model/Shiroko/Shiroko_Core/shiroko.model3.json +36 -0
- package/src/renderer/src/App.tsx +33 -0
- package/src/renderer/src/calculator.ts +47 -0
- package/src/renderer/src/components/ChatPanel.tsx +1598 -0
- package/src/renderer/src/components/DashboardSidebar.tsx +358 -0
- package/src/renderer/src/components/Live2DStage.tsx +374 -0
- package/src/renderer/src/components/MintDashboard.tsx +950 -0
- package/src/renderer/src/components/ModelPanel.tsx +154 -0
- package/src/renderer/src/components/PicturesLibrary.tsx +46 -0
- package/src/renderer/src/components/ProactiveGlow.tsx +19 -0
- package/src/renderer/src/components/ScreenPicker.tsx +579 -0
- package/src/renderer/src/components/SettingsWindow.tsx +1467 -0
- package/src/renderer/src/components/SpotlightWindow.tsx +280 -0
- package/src/renderer/src/components/WidgetWindow.tsx +36 -0
- package/src/renderer/src/components/WorkspacePanel.tsx +268 -0
- package/src/{UI → renderer/src/css}/settings.css +69 -16
- package/src/renderer/src/css/spotlight.css +113 -0
- package/src/renderer/src/css/styles.css +3722 -0
- package/src/renderer/src/css/widget.css +185 -0
- package/src/renderer/src/env.d.ts +116 -0
- package/src/renderer/src/index.css +379 -0
- package/src/renderer/src/main.tsx +13 -0
- package/src/renderer/src/tauri.ts +996 -0
- package/src/renderer/src-web/App.tsx +25 -0
- package/src/renderer/src-web/calculator.ts +47 -0
- package/src/renderer/src-web/components/ChatPanel.tsx +1662 -0
- package/src/renderer/src-web/components/DashboardSidebar.tsx +242 -0
- package/src/renderer/src-web/components/MintDashboard.tsx +763 -0
- package/src/renderer/src-web/components/PicturesLibrary.tsx +73 -0
- package/src/renderer/src-web/components/SettingsWindow.tsx +1500 -0
- package/src/renderer/src-web/css/settings.css +1100 -0
- package/src/{UI → renderer/src-web/css}/spotlight.css +4 -4
- package/src/{UI → renderer/src-web/css}/styles.css +1055 -159
- package/src/{UI → renderer/src-web/css}/widget.css +2 -2
- package/src/renderer/src-web/env.d.ts +107 -0
- package/src/renderer/src-web/index.css +379 -0
- package/src/renderer/src-web/main.tsx +13 -0
- package/src/renderer/src-web/tauri.ts +983 -0
- package/tsconfig.json +30 -0
- package/vite.config.ts +33 -0
- package/vite.config.web.ts +51 -0
- package/GUIDE_TH.md +0 -125
- package/assets/Agent_Mint.png +0 -0
- package/assets/CLI_Screen.png +0 -0
- package/assets/Settings.png +0 -0
- package/benchmark_ai.js +0 -71
- package/install.ps1 +0 -64
- package/install.sh +0 -54
- package/main.js +0 -139
- package/mint-cli-logic.js +0 -3
- package/mint-cli.js +0 -410
- package/models/Shiroko_Model/Shiroko/Shiroko_Core//351/235/242/351/245/2740.model3.json +0 -47
- package/models/Shiroko_Model/Shiroko//342/232/241/351/253/230/344/272/256/342/232/241/344/275/277/347/224/250/346/225/231/347/250/213/344/270/216/346/263/250/346/204/217/344/272/213/351/241/271.txt +0 -23
- package/preload-picker.js +0 -11
- package/preload-settings.js +0 -11
- package/preload.js +0 -41
- package/scripts/install_linux_desktop_entry.js +0 -48
- package/src/AI_Brain/Gemini_API.js +0 -813
- package/src/AI_Brain/agent_orchestrator.js +0 -73
- package/src/AI_Brain/autonomous_brain.js +0 -179
- package/src/AI_Brain/behavior_memory.js +0 -135
- package/src/AI_Brain/headless_agent.js +0 -143
- package/src/AI_Brain/knowledge_base.js +0 -349
- package/src/AI_Brain/memory_store.js +0 -662
- package/src/AI_Brain/proactive_engine.js +0 -172
- package/src/AI_Brain/provider_adapter.js +0 -365
- package/src/Automation_Layer/browser_automation.js +0 -149
- package/src/Automation_Layer/file_operations.js +0 -286
- package/src/Automation_Layer/open_app.js +0 -85
- package/src/Automation_Layer/open_website.js +0 -38
- package/src/CLI/approval_handler.js +0 -47
- package/src/CLI/chat_router.js +0 -247
- package/src/CLI/chat_ui.js +0 -1159
- package/src/CLI/cli_colors.js +0 -115
- package/src/CLI/cli_formatters.js +0 -94
- package/src/CLI/code_agent.js +0 -1667
- package/src/CLI/code_session_memory.js +0 -62
- package/src/CLI/gmail_auth.js +0 -210
- package/src/CLI/image_input.js +0 -90
- package/src/CLI/intent_detectors.js +0 -181
- package/src/CLI/interactive_chat.js +0 -658
- package/src/CLI/list_features.js +0 -64
- package/src/CLI/onboarding.js +0 -416
- package/src/CLI/repo_summarizer.js +0 -282
- package/src/CLI/semantic_code_search.js +0 -312
- package/src/CLI/skill_manager.js +0 -41
- package/src/CLI/slash_command_handler.js +0 -418
- package/src/CLI/symbol_indexer.js +0 -231
- package/src/CLI/updater.js +0 -230
- package/src/CLI/workspace_manager.js +0 -90
- package/src/Channels/brave_search_bridge.js +0 -35
- package/src/Channels/discord_bridge.js +0 -66
- package/src/Channels/google_search_bridge.js +0 -38
- package/src/Channels/line_bridge.js +0 -60
- package/src/Channels/slack_bridge.js +0 -48
- package/src/Channels/telegram_bridge.js +0 -41
- package/src/Channels/whatsapp_bridge.js +0 -57
- package/src/Command_Parser/parser.js +0 -45
- package/src/Plugins/dev_tools.js +0 -41
- package/src/Plugins/discord.js +0 -20
- package/src/Plugins/docker.js +0 -47
- package/src/Plugins/gmail.js +0 -251
- package/src/Plugins/google_calendar.js +0 -252
- package/src/Plugins/mcp_manager.js +0 -95
- package/src/Plugins/notion.js +0 -256
- package/src/Plugins/obsidian.js +0 -54
- package/src/Plugins/plugin_manager.js +0 -81
- package/src/Plugins/spotify.js +0 -173
- package/src/Plugins/system_metrics.js +0 -31
- package/src/Plugins/system_monitor.js +0 -72
- package/src/System/action_executor.js +0 -178
- package/src/System/bridge_manager.js +0 -76
- package/src/System/chat_history_manager.js +0 -83
- package/src/System/config_manager.js +0 -194
- package/src/System/custom_workflows.js +0 -163
- package/src/System/daemon_manager.js +0 -67
- package/src/System/google_tts_urls.js +0 -51
- package/src/System/granular_automation.js +0 -157
- package/src/System/ipc_handlers.js +0 -332
- package/src/System/notifications.js +0 -23
- package/src/System/optional_require.js +0 -23
- package/src/System/picture_store.js +0 -109
- package/src/System/proactive_loop.js +0 -153
- package/src/System/safety_manager.js +0 -273
- package/src/System/sandbox_runner.js +0 -182
- package/src/System/screen_capture.js +0 -175
- package/src/System/smart_context.js +0 -227
- package/src/System/system_automation.js +0 -162
- package/src/System/system_events.js +0 -79
- package/src/System/system_info.js +0 -125
- package/src/System/task_manager.js +0 -222
- package/src/System/tool_registry.js +0 -293
- package/src/System/window_manager.js +0 -220
- package/src/UI/floating.css +0 -80
- package/src/UI/floating.html +0 -17
- package/src/UI/floating.js +0 -67
- package/src/UI/live2d_manager.js +0 -600
- package/src/UI/preload-floating.js +0 -7
- package/src/UI/preload-spotlight.js +0 -11
- package/src/UI/preload-widget.js +0 -5
- package/src/UI/proactive-glow.html +0 -42
- package/src/UI/renderer.js +0 -2127
- package/src/UI/screenPicker.html +0 -214
- package/src/UI/screenPicker.js +0 -262
- package/src/UI/settings.html +0 -577
- package/src/UI/settings.js +0 -770
- package/src/UI/spotlight.html +0 -23
- package/src/UI/spotlight.js +0 -185
- package/src/UI/widget.html +0 -29
- package/src/UI/widget.js +0 -10
- /package/{models → src/renderer/public/models}/Shiroko_Model/Shiroko/Shiroko_Core/72d86db84cfa9730b894c241fd24c0db.png +0 -0
- /package/{models/Shiroko_Model/Shiroko/Shiroko_Core//345/233/264/350/243/231.exp3.json" → src/renderer/public/models/Shiroko_Model/Shiroko/Shiroko_Core/apron.exp3.json} +0 -0
- /package/{models/Shiroko_Model/Shiroko/Shiroko_Core//347/214/253/345/222/252/346/273/244/351/225/234.exp3.json" → src/renderer/public/models/Shiroko_Model/Shiroko/Shiroko_Core/catfilter.exp3.json} +0 -0
- /package/{models/Shiroko_Model/Shiroko/Shiroko_Core//347/202/271/344/270/200/344/270/213.exp3.json" → src/renderer/public/models/Shiroko_Model/Shiroko/Shiroko_Core/click.exp3.json} +0 -0
- /package/{models/Shiroko_Model/Shiroko/Shiroko_Core//345/221/206/347/214/253.exp3.json" → src/renderer/public/models/Shiroko_Model/Shiroko/Shiroko_Core/dazed.exp3.json} +0 -0
- /package/{models/Shiroko_Model/Shiroko/Shiroko_Core//345/221/206/347/214/253/347/234/274/347/217/240/346/221/207/346/231/203.exp3.json" → src/renderer/public/models/Shiroko_Model/Shiroko/Shiroko_Core/dazedeyes.exp3.json} +0 -0
- /package/{models/Shiroko_Model/Shiroko/Shiroko_Core//347/234/274/351/225/234.exp3.json" → src/renderer/public/models/Shiroko_Model/Shiroko/Shiroko_Core/glasses.exp3.json} +0 -0
- /package/{models → src/renderer/public/models}/Shiroko_Model/Shiroko/Shiroko_Core/items_pinned_to_model.json +0 -0
- /package/{models/Shiroko_Model/Shiroko/Shiroko_Core//346/213/277/347/254/224.exp3.json" → src/renderer/public/models/Shiroko_Model/Shiroko/Shiroko_Core/pen.exp3.json} +0 -0
- /package/{models/Shiroko_Model/Shiroko/Shiroko_Core//346/213/215/347/205/247.exp3.json" → src/renderer/public/models/Shiroko_Model/Shiroko/Shiroko_Core/photo.exp3.json} +0 -0
- /package/{models/Shiroko_Model/Shiroko/Shiroko_Core//351/235/242/351/245/2740.4096/texture_00.png" → src/renderer/public/models/Shiroko_Model/Shiroko/Shiroko_Core/shiroko.4096/texture_00.png} +0 -0
- /package/{models/Shiroko_Model/Shiroko/Shiroko_Core//351/235/242/351/245/2740.4096/texture_01.png" → src/renderer/public/models/Shiroko_Model/Shiroko/Shiroko_Core/shiroko.4096/texture_01.png} +0 -0
- /package/{models/Shiroko_Model/Shiroko/Shiroko_Core//351/235/242/351/245/2740.4096/texture_02.png" → src/renderer/public/models/Shiroko_Model/Shiroko/Shiroko_Core/shiroko.4096/texture_02.png} +0 -0
- /package/{models/Shiroko_Model/Shiroko/Shiroko_Core//351/235/242/351/245/2740.4096/texture_03.png" → src/renderer/public/models/Shiroko_Model/Shiroko/Shiroko_Core/shiroko.4096/texture_03.png} +0 -0
- /package/{models/Shiroko_Model/Shiroko/Shiroko_Core//351/235/242/351/245/2740.cdi3.json" → src/renderer/public/models/Shiroko_Model/Shiroko/Shiroko_Core/shiroko.cdi3.json} +0 -0
- /package/{models/Shiroko_Model/Shiroko/Shiroko_Core//351/235/242/351/245/2740.moc3" → src/renderer/public/models/Shiroko_Model/Shiroko/Shiroko_Core/shiroko.moc3} +0 -0
- /package/{models/Shiroko_Model/Shiroko/Shiroko_Core//351/235/242/351/245/2740.physics3.json" → src/renderer/public/models/Shiroko_Model/Shiroko/Shiroko_Core/shiroko.physics3.json} +0 -0
- /package/{models/Shiroko_Model/Shiroko/Shiroko_Core//351/235/242/351/245/2740.vtube.json" → src/renderer/public/models/Shiroko_Model/Shiroko/Shiroko_Core/shiroko.vtube.json} +0 -0
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
use std::{
|
|
2
|
+
path::{Path, PathBuf},
|
|
3
|
+
process::{Command, Output},
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
use serde::Serialize;
|
|
7
|
+
use thiserror::Error;
|
|
8
|
+
|
|
9
|
+
use crate::{
|
|
10
|
+
Capability, MintConfig, SafetyError, SafetyTier, assert_path_capability,
|
|
11
|
+
classify_shell_command, shell_mode_allowed,
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
#[derive(Debug, Clone, Serialize, PartialEq, Eq)]
|
|
15
|
+
#[serde(rename_all = "camelCase")]
|
|
16
|
+
pub struct ShellOutput {
|
|
17
|
+
pub command: String,
|
|
18
|
+
pub cwd: PathBuf,
|
|
19
|
+
pub mode: String,
|
|
20
|
+
pub status: Option<i32>,
|
|
21
|
+
pub success: bool,
|
|
22
|
+
pub sandboxed: bool,
|
|
23
|
+
pub stdout: String,
|
|
24
|
+
pub stderr: String,
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
#[derive(Debug, Error)]
|
|
28
|
+
pub enum ShellError {
|
|
29
|
+
#[error("shell command requires explicit approval: {0}")]
|
|
30
|
+
ApprovalRequired(String),
|
|
31
|
+
#[error("blocked unsafe shell command ({reason}): {command}")]
|
|
32
|
+
Blocked { command: String, reason: String },
|
|
33
|
+
#[error("shell command mode '{mode}' is not allowed by policy: {command}")]
|
|
34
|
+
ModeDenied { command: String, mode: String },
|
|
35
|
+
#[error("shell working directory must be a directory: {0}")]
|
|
36
|
+
InvalidWorkingDirectory(PathBuf),
|
|
37
|
+
#[error(transparent)]
|
|
38
|
+
Safety(#[from] SafetyError),
|
|
39
|
+
#[error("sandbox mode is enforced but sandbox command '{0}' is unavailable")]
|
|
40
|
+
SandboxUnavailable(String),
|
|
41
|
+
#[error("unable to execute shell command: {0}")]
|
|
42
|
+
Execute(#[from] std::io::Error),
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
pub fn run_shell_command(
|
|
46
|
+
command: &str,
|
|
47
|
+
cwd: &Path,
|
|
48
|
+
approved: bool,
|
|
49
|
+
config: &MintConfig,
|
|
50
|
+
) -> Result<ShellOutput, ShellError> {
|
|
51
|
+
let classification = classify_shell_command(command);
|
|
52
|
+
if classification.tier == SafetyTier::Blocked {
|
|
53
|
+
return Err(ShellError::Blocked {
|
|
54
|
+
command: command.into(),
|
|
55
|
+
reason: classification.reason,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
if config.safety_enabled && !shell_mode_allowed(config, classification.mode) {
|
|
59
|
+
return Err(ShellError::ModeDenied {
|
|
60
|
+
command: command.into(),
|
|
61
|
+
mode: classification.mode.as_str().into(),
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
if !approved {
|
|
65
|
+
return Err(ShellError::ApprovalRequired(command.into()));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
let cwd = assert_path_capability(cwd, Capability::Write, config)?;
|
|
69
|
+
if !cwd.is_dir() {
|
|
70
|
+
return Err(ShellError::InvalidWorkingDirectory(cwd));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
let sandbox_mode = config.sandbox_mode.trim().to_ascii_lowercase();
|
|
74
|
+
if config.safety_enabled && sandbox_mode != "off" {
|
|
75
|
+
if let Some(output) = run_in_sandbox(command, &cwd, config)? {
|
|
76
|
+
return Ok(shell_output(
|
|
77
|
+
command,
|
|
78
|
+
cwd,
|
|
79
|
+
classification.mode.as_str(),
|
|
80
|
+
true,
|
|
81
|
+
output,
|
|
82
|
+
));
|
|
83
|
+
}
|
|
84
|
+
if sandbox_mode == "enforce" {
|
|
85
|
+
return Err(ShellError::SandboxUnavailable(
|
|
86
|
+
config.sandbox_command.clone(),
|
|
87
|
+
));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
let output = shell_command(command).current_dir(&cwd).output()?;
|
|
92
|
+
Ok(shell_output(
|
|
93
|
+
command,
|
|
94
|
+
cwd,
|
|
95
|
+
classification.mode.as_str(),
|
|
96
|
+
false,
|
|
97
|
+
output,
|
|
98
|
+
))
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
fn run_in_sandbox(
|
|
102
|
+
command: &str,
|
|
103
|
+
cwd: &Path,
|
|
104
|
+
config: &MintConfig,
|
|
105
|
+
) -> Result<Option<Output>, ShellError> {
|
|
106
|
+
#[cfg(target_os = "linux")]
|
|
107
|
+
{
|
|
108
|
+
let sandbox = config.sandbox_command.trim();
|
|
109
|
+
if sandbox.is_empty() || !command_exists(sandbox) {
|
|
110
|
+
return Ok(None);
|
|
111
|
+
}
|
|
112
|
+
let mut process = Command::new(sandbox);
|
|
113
|
+
process
|
|
114
|
+
.args(["--die-with-parent", "--ro-bind", "/", "/", "--dev", "/dev"])
|
|
115
|
+
.args(["--proc", "/proc", "--tmpfs", "/tmp"]);
|
|
116
|
+
for root in writable_roots(config, cwd) {
|
|
117
|
+
process.arg("--bind").arg(&root).arg(&root);
|
|
118
|
+
}
|
|
119
|
+
let output = process
|
|
120
|
+
.arg("--chdir")
|
|
121
|
+
.arg(cwd)
|
|
122
|
+
.args(["bash", "-lc", command])
|
|
123
|
+
.output()?;
|
|
124
|
+
return Ok(Some(output));
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
#[cfg(target_os = "macos")]
|
|
128
|
+
{
|
|
129
|
+
let sandbox = config.sandbox_command.trim();
|
|
130
|
+
if sandbox.is_empty() || !command_exists(sandbox) {
|
|
131
|
+
return Ok(None);
|
|
132
|
+
}
|
|
133
|
+
let output = Command::new(sandbox)
|
|
134
|
+
.arg("-p")
|
|
135
|
+
.arg(mac_sandbox_profile(config, cwd))
|
|
136
|
+
.args(["bash", "-lc", command])
|
|
137
|
+
.current_dir(cwd)
|
|
138
|
+
.output()?;
|
|
139
|
+
return Ok(Some(output));
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
|
|
143
|
+
{
|
|
144
|
+
let _ = (command, cwd, config);
|
|
145
|
+
Ok(None)
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
#[cfg(target_os = "macos")]
|
|
150
|
+
fn mac_sandbox_profile(config: &MintConfig, cwd: &Path) -> String {
|
|
151
|
+
let mut read_roots = vec![
|
|
152
|
+
cwd.to_path_buf(),
|
|
153
|
+
PathBuf::from("/bin"),
|
|
154
|
+
PathBuf::from("/sbin"),
|
|
155
|
+
PathBuf::from("/usr"),
|
|
156
|
+
PathBuf::from("/System"),
|
|
157
|
+
PathBuf::from("/Library"),
|
|
158
|
+
];
|
|
159
|
+
read_roots.extend(config.allowed_read_paths.iter().cloned());
|
|
160
|
+
read_roots.extend(config.allowed_write_paths.iter().cloned());
|
|
161
|
+
|
|
162
|
+
let mut write_roots = vec![cwd.to_path_buf(), std::env::temp_dir()];
|
|
163
|
+
write_roots.extend(config.allowed_write_paths.iter().cloned());
|
|
164
|
+
|
|
165
|
+
format!(
|
|
166
|
+
"(version 1)\n\
|
|
167
|
+
(deny default)\n\
|
|
168
|
+
(allow process*)\n\
|
|
169
|
+
(allow sysctl-read)\n\
|
|
170
|
+
(allow signal (target self))\n\
|
|
171
|
+
(allow file-read-metadata)\n\
|
|
172
|
+
(allow file-read*\n{})\n\
|
|
173
|
+
(allow file-write*\n{})",
|
|
174
|
+
sandbox_subpaths(read_roots),
|
|
175
|
+
sandbox_subpaths(write_roots),
|
|
176
|
+
)
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
#[cfg(target_os = "macos")]
|
|
180
|
+
fn sandbox_subpaths(mut roots: Vec<PathBuf>) -> String {
|
|
181
|
+
roots.sort();
|
|
182
|
+
roots.dedup();
|
|
183
|
+
roots
|
|
184
|
+
.into_iter()
|
|
185
|
+
.filter(|root| root.exists())
|
|
186
|
+
.map(|root| {
|
|
187
|
+
format!(
|
|
188
|
+
" (subpath \"{}\")",
|
|
189
|
+
root.to_string_lossy()
|
|
190
|
+
.replace('\\', "\\\\")
|
|
191
|
+
.replace('"', "\\\"")
|
|
192
|
+
)
|
|
193
|
+
})
|
|
194
|
+
.collect::<Vec<_>>()
|
|
195
|
+
.join("\n")
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
#[cfg(target_os = "linux")]
|
|
199
|
+
fn writable_roots(config: &MintConfig, cwd: &Path) -> Vec<PathBuf> {
|
|
200
|
+
let mut roots = config
|
|
201
|
+
.allowed_write_paths
|
|
202
|
+
.iter()
|
|
203
|
+
.filter(|root| root.exists())
|
|
204
|
+
.cloned()
|
|
205
|
+
.collect::<Vec<_>>();
|
|
206
|
+
if !roots.iter().any(|root| cwd.starts_with(root)) {
|
|
207
|
+
roots.push(cwd.to_path_buf());
|
|
208
|
+
}
|
|
209
|
+
roots.sort();
|
|
210
|
+
roots.dedup();
|
|
211
|
+
roots
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
|
215
|
+
fn command_exists(command: &str) -> bool {
|
|
216
|
+
Command::new("which")
|
|
217
|
+
.arg(command)
|
|
218
|
+
.output()
|
|
219
|
+
.is_ok_and(|output| output.status.success())
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
fn shell_command(command: &str) -> Command {
|
|
223
|
+
#[cfg(target_os = "windows")]
|
|
224
|
+
{
|
|
225
|
+
let mut process = Command::new("powershell.exe");
|
|
226
|
+
process.args([
|
|
227
|
+
"-NoLogo",
|
|
228
|
+
"-NoProfile",
|
|
229
|
+
"-NonInteractive",
|
|
230
|
+
"-ExecutionPolicy",
|
|
231
|
+
"Bypass",
|
|
232
|
+
"-Command",
|
|
233
|
+
command,
|
|
234
|
+
]);
|
|
235
|
+
process
|
|
236
|
+
}
|
|
237
|
+
#[cfg(not(target_os = "windows"))]
|
|
238
|
+
{
|
|
239
|
+
let mut process = Command::new("bash");
|
|
240
|
+
process.args(["-lc", command]);
|
|
241
|
+
process
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
fn shell_output(
|
|
246
|
+
command: &str,
|
|
247
|
+
cwd: PathBuf,
|
|
248
|
+
mode: &str,
|
|
249
|
+
sandboxed: bool,
|
|
250
|
+
output: Output,
|
|
251
|
+
) -> ShellOutput {
|
|
252
|
+
ShellOutput {
|
|
253
|
+
command: command.into(),
|
|
254
|
+
cwd,
|
|
255
|
+
mode: mode.into(),
|
|
256
|
+
status: output.status.code(),
|
|
257
|
+
success: output.status.success(),
|
|
258
|
+
sandboxed,
|
|
259
|
+
stdout: String::from_utf8_lossy(&output.stdout).into_owned(),
|
|
260
|
+
stderr: String::from_utf8_lossy(&output.stderr).into_owned(),
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
#[cfg(test)]
|
|
265
|
+
mod tests {
|
|
266
|
+
use super::*;
|
|
267
|
+
|
|
268
|
+
fn local_config() -> MintConfig {
|
|
269
|
+
MintConfig {
|
|
270
|
+
safety_enabled: false,
|
|
271
|
+
sandbox_mode: "off".into(),
|
|
272
|
+
..MintConfig::default()
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
#[test]
|
|
277
|
+
fn requires_explicit_approval() {
|
|
278
|
+
let error =
|
|
279
|
+
run_shell_command("printf mint", Path::new("."), false, &local_config()).unwrap_err();
|
|
280
|
+
assert!(matches!(error, ShellError::ApprovalRequired(_)));
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
#[test]
|
|
284
|
+
fn blocks_destructive_commands_even_when_approved() {
|
|
285
|
+
let error = run_shell_command(
|
|
286
|
+
"git reset --hard HEAD",
|
|
287
|
+
Path::new("."),
|
|
288
|
+
true,
|
|
289
|
+
&local_config(),
|
|
290
|
+
)
|
|
291
|
+
.unwrap_err();
|
|
292
|
+
assert!(matches!(error, ShellError::Blocked { .. }));
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
#[test]
|
|
296
|
+
fn runs_an_approved_local_command() {
|
|
297
|
+
let output =
|
|
298
|
+
run_shell_command("printf mint", Path::new("."), true, &local_config()).unwrap();
|
|
299
|
+
assert!(output.success);
|
|
300
|
+
assert!(!output.sandboxed);
|
|
301
|
+
assert_eq!(output.stdout, "mint");
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
#[test]
|
|
305
|
+
fn reports_non_zero_exit_status() {
|
|
306
|
+
let output = run_shell_command(
|
|
307
|
+
"printf failure >&2; exit 7",
|
|
308
|
+
Path::new("."),
|
|
309
|
+
true,
|
|
310
|
+
&local_config(),
|
|
311
|
+
)
|
|
312
|
+
.unwrap();
|
|
313
|
+
assert!(!output.success);
|
|
314
|
+
assert_eq!(output.status, Some(7));
|
|
315
|
+
assert_eq!(output.stderr, "failure");
|
|
316
|
+
}
|
|
317
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
use std::{fs, path::Path};
|
|
2
|
+
|
|
3
|
+
use thiserror::Error;
|
|
4
|
+
|
|
5
|
+
use crate::{LearnedSkill, MemoryError, MemoryStore};
|
|
6
|
+
|
|
7
|
+
const MAX_SKILL_BYTES: u64 = 256 * 1024;
|
|
8
|
+
const MAX_CONTEXT_BYTES: usize = 16 * 1024;
|
|
9
|
+
|
|
10
|
+
#[derive(Debug, Error)]
|
|
11
|
+
pub enum SkillError {
|
|
12
|
+
#[error("unable to resolve skill file {path}: {source}")]
|
|
13
|
+
Resolve {
|
|
14
|
+
path: String,
|
|
15
|
+
source: std::io::Error,
|
|
16
|
+
},
|
|
17
|
+
#[error("skill path is not a file: {0}")]
|
|
18
|
+
NotFile(String),
|
|
19
|
+
#[error("skill file is too large ({0} bytes); limit is {MAX_SKILL_BYTES} bytes")]
|
|
20
|
+
TooLarge(u64),
|
|
21
|
+
#[error("Mint learn supports .md and .txt files only")]
|
|
22
|
+
UnsupportedExtension,
|
|
23
|
+
#[error(transparent)]
|
|
24
|
+
Io(#[from] std::io::Error),
|
|
25
|
+
#[error(transparent)]
|
|
26
|
+
Memory(#[from] MemoryError),
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
pub fn learn_skill(path: &Path) -> Result<LearnedSkill, SkillError> {
|
|
30
|
+
let path = path.canonicalize().map_err(|source| SkillError::Resolve {
|
|
31
|
+
path: path.display().to_string(),
|
|
32
|
+
source,
|
|
33
|
+
})?;
|
|
34
|
+
let metadata = fs::metadata(&path)?;
|
|
35
|
+
if !metadata.is_file() {
|
|
36
|
+
return Err(SkillError::NotFile(path.display().to_string()));
|
|
37
|
+
}
|
|
38
|
+
if metadata.len() > MAX_SKILL_BYTES {
|
|
39
|
+
return Err(SkillError::TooLarge(metadata.len()));
|
|
40
|
+
}
|
|
41
|
+
if !path
|
|
42
|
+
.extension()
|
|
43
|
+
.and_then(|value| value.to_str())
|
|
44
|
+
.is_some_and(|extension| matches!(extension.to_ascii_lowercase().as_str(), "md" | "txt"))
|
|
45
|
+
{
|
|
46
|
+
return Err(SkillError::UnsupportedExtension);
|
|
47
|
+
}
|
|
48
|
+
let content = fs::read_to_string(&path)?;
|
|
49
|
+
let name = path
|
|
50
|
+
.file_name()
|
|
51
|
+
.and_then(|value| value.to_str())
|
|
52
|
+
.unwrap_or("skill");
|
|
53
|
+
Ok(MemoryStore::open_default()?.add_learned_skill(name, &path.to_string_lossy(), &content)?)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
pub fn learned_skills_context() -> Result<String, SkillError> {
|
|
57
|
+
let skills = MemoryStore::open_default()?.learned_skills(20)?;
|
|
58
|
+
let value = skills
|
|
59
|
+
.into_iter()
|
|
60
|
+
.map(|skill| format!("Skill: {}\n{}", skill.name, skill.content))
|
|
61
|
+
.collect::<Vec<_>>()
|
|
62
|
+
.join("\n\n");
|
|
63
|
+
if value.len() <= MAX_CONTEXT_BYTES {
|
|
64
|
+
return Ok(value);
|
|
65
|
+
}
|
|
66
|
+
let mut end = MAX_CONTEXT_BYTES;
|
|
67
|
+
while !value.is_char_boundary(end) {
|
|
68
|
+
end -= 1;
|
|
69
|
+
}
|
|
70
|
+
Ok(format!("{}\n...<learned skills truncated>", &value[..end]))
|
|
71
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
use std::{
|
|
2
|
+
collections::BTreeMap,
|
|
3
|
+
fs,
|
|
4
|
+
path::{Path, PathBuf},
|
|
5
|
+
sync::LazyLock,
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
use regex::Regex;
|
|
9
|
+
use serde::Serialize;
|
|
10
|
+
use thiserror::Error;
|
|
11
|
+
|
|
12
|
+
use crate::{CodeInspectionError, MintConfig, list_code_files};
|
|
13
|
+
|
|
14
|
+
static PATTERNS: LazyLock<Vec<(&'static str, Regex)>> = LazyLock::new(|| {
|
|
15
|
+
[
|
|
16
|
+
(
|
|
17
|
+
"function",
|
|
18
|
+
r"^\s*(?:pub\s+)?(?:async\s+)?fn\s+([A-Za-z_][A-Za-z0-9_]*)\s*\(",
|
|
19
|
+
),
|
|
20
|
+
(
|
|
21
|
+
"function",
|
|
22
|
+
r"^\s*(?:export\s+)?(?:async\s+)?function\s+([A-Za-z_$][A-Za-z0-9_$]*)\s*\(",
|
|
23
|
+
),
|
|
24
|
+
(
|
|
25
|
+
"function",
|
|
26
|
+
r"^\s*(?:async\s+)?def\s+([A-Za-z_][A-Za-z0-9_]*)\s*\(",
|
|
27
|
+
),
|
|
28
|
+
(
|
|
29
|
+
"class",
|
|
30
|
+
r"^\s*(?:export\s+)?class\s+([A-Za-z_$][A-Za-z0-9_$]*)\b",
|
|
31
|
+
),
|
|
32
|
+
(
|
|
33
|
+
"struct",
|
|
34
|
+
r"^\s*(?:pub\s+)?struct\s+([A-Za-z_][A-Za-z0-9_]*)\b",
|
|
35
|
+
),
|
|
36
|
+
("enum", r"^\s*(?:pub\s+)?enum\s+([A-Za-z_][A-Za-z0-9_]*)\b"),
|
|
37
|
+
(
|
|
38
|
+
"trait",
|
|
39
|
+
r"^\s*(?:pub\s+)?trait\s+([A-Za-z_][A-Za-z0-9_]*)\b",
|
|
40
|
+
),
|
|
41
|
+
(
|
|
42
|
+
"interface",
|
|
43
|
+
r"^\s*(?:export\s+)?interface\s+([A-Za-z_$][A-Za-z0-9_$]*)\b",
|
|
44
|
+
),
|
|
45
|
+
(
|
|
46
|
+
"type",
|
|
47
|
+
r"^\s*(?:export\s+)?type\s+([A-Za-z_$][A-Za-z0-9_$]*)\b",
|
|
48
|
+
),
|
|
49
|
+
]
|
|
50
|
+
.into_iter()
|
|
51
|
+
.map(|(kind, pattern)| (kind, Regex::new(pattern).unwrap()))
|
|
52
|
+
.collect()
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
#[derive(Debug, Error)]
|
|
56
|
+
pub enum SymbolError {
|
|
57
|
+
#[error(transparent)]
|
|
58
|
+
Inspect(#[from] CodeInspectionError),
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
#[derive(Debug, Clone, Serialize, PartialEq, Eq)]
|
|
62
|
+
#[serde(rename_all = "camelCase")]
|
|
63
|
+
pub struct CodeSymbol {
|
|
64
|
+
pub name: String,
|
|
65
|
+
pub kind: String,
|
|
66
|
+
pub file: PathBuf,
|
|
67
|
+
pub line: usize,
|
|
68
|
+
pub signature: String,
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
#[derive(Debug, Clone, Serialize, PartialEq, Eq)]
|
|
72
|
+
#[serde(rename_all = "camelCase")]
|
|
73
|
+
pub struct SymbolIndex {
|
|
74
|
+
pub root: PathBuf,
|
|
75
|
+
pub file_count: usize,
|
|
76
|
+
pub symbol_count: usize,
|
|
77
|
+
pub kind_counts: BTreeMap<String, usize>,
|
|
78
|
+
pub symbols: Vec<CodeSymbol>,
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
pub fn build_symbol_index(
|
|
82
|
+
root: &Path,
|
|
83
|
+
limit: usize,
|
|
84
|
+
config: &MintConfig,
|
|
85
|
+
) -> Result<SymbolIndex, SymbolError> {
|
|
86
|
+
let files = list_code_files(root, usize::MAX, config)?;
|
|
87
|
+
let mut symbols = Vec::new();
|
|
88
|
+
for file in &files {
|
|
89
|
+
if symbols.len() >= limit {
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
let Some(extension) = file.path.extension().and_then(|value| value.to_str()) else {
|
|
93
|
+
continue;
|
|
94
|
+
};
|
|
95
|
+
if !matches!(
|
|
96
|
+
extension,
|
|
97
|
+
"rs" | "js" | "jsx" | "ts" | "tsx" | "py" | "cjs" | "mjs"
|
|
98
|
+
) {
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
let Ok(content) = fs::read_to_string(&file.path) else {
|
|
102
|
+
continue;
|
|
103
|
+
};
|
|
104
|
+
for (index, line) in content.lines().enumerate() {
|
|
105
|
+
for (kind, pattern) in PATTERNS.iter() {
|
|
106
|
+
let Some(found) = pattern.captures(line).and_then(|captures| captures.get(1))
|
|
107
|
+
else {
|
|
108
|
+
continue;
|
|
109
|
+
};
|
|
110
|
+
symbols.push(CodeSymbol {
|
|
111
|
+
name: found.as_str().into(),
|
|
112
|
+
kind: (*kind).into(),
|
|
113
|
+
file: file.path.clone(),
|
|
114
|
+
line: index + 1,
|
|
115
|
+
signature: line.trim().into(),
|
|
116
|
+
});
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
if symbols.len() >= limit {
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
let mut kind_counts = BTreeMap::new();
|
|
125
|
+
for symbol in &symbols {
|
|
126
|
+
*kind_counts.entry(symbol.kind.clone()).or_insert(0) += 1;
|
|
127
|
+
}
|
|
128
|
+
Ok(SymbolIndex {
|
|
129
|
+
root: root.to_path_buf(),
|
|
130
|
+
file_count: files.len(),
|
|
131
|
+
symbol_count: symbols.len(),
|
|
132
|
+
kind_counts,
|
|
133
|
+
symbols,
|
|
134
|
+
})
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
#[cfg(test)]
|
|
138
|
+
mod tests {
|
|
139
|
+
use super::*;
|
|
140
|
+
|
|
141
|
+
#[test]
|
|
142
|
+
fn indexes_rust_and_typescript_symbols() {
|
|
143
|
+
let root = std::env::temp_dir().join("mint-symbol-index");
|
|
144
|
+
let _ = fs::remove_dir_all(&root);
|
|
145
|
+
fs::create_dir_all(&root).unwrap();
|
|
146
|
+
fs::write(root.join("main.rs"), "pub struct Mint;\npub fn run() {}\n").unwrap();
|
|
147
|
+
fs::write(root.join("ui.ts"), "export interface Widget {}\n").unwrap();
|
|
148
|
+
let config = MintConfig {
|
|
149
|
+
allowed_read_paths: vec![root.clone()],
|
|
150
|
+
blocked_paths: vec![],
|
|
151
|
+
..MintConfig::default()
|
|
152
|
+
};
|
|
153
|
+
let index = build_symbol_index(&root, 20, &config).unwrap();
|
|
154
|
+
assert_eq!(index.symbol_count, 3);
|
|
155
|
+
let _ = fs::remove_dir_all(root);
|
|
156
|
+
}
|
|
157
|
+
}
|