Skip to content
Draft
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
14 changes: 14 additions & 0 deletions src-tauri/capabilities/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@
"core:default",
"core:webview:allow-set-webview-zoom",
"opener:default",
{
"identifier": "opener:allow-open-path",
"allow": [
{
"path": "$HOME/**"
},
{
"path": "$HOME/.codex/**"
},
{
"path": "$HOME/**/.codex/**"
}
]
},
"dialog:default",
"process:default",
"updater:default",
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/src/bin/codex_monitor_daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ impl DaemonState {
}

async fn skills_list(&self, workspace_id: String) -> Result<Value, String> {
codex_core::skills_list_core(&self.sessions, workspace_id).await
codex_core::skills_list_core(&self.sessions, &self.workspaces, workspace_id).await
}

async fn apps_list(
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/src/codex/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ pub(crate) async fn skills_list(
.await;
}

codex_core::skills_list_core(&state.sessions, workspace_id).await
codex_core::skills_list_core(&state.sessions, &state.workspaces, workspace_id).await
}

#[tauri::command]
Expand Down
54 changes: 53 additions & 1 deletion src-tauri/src/shared/codex_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ async fn resolve_codex_home_for_workspace_core(
.ok_or_else(|| "Unable to resolve CODEX_HOME".to_string())
}

fn resolve_skills_cwd(entry: &WorkspaceEntry, parent_entry: Option<&WorkspaceEntry>) -> String {
if entry.kind.is_worktree() {
if let Some(parent) = parent_entry {
return parent.path.clone();
}
}
entry.path.clone()
}

pub(crate) async fn start_thread_core(
sessions: &Mutex<HashMap<String, Arc<WorkspaceSession>>>,
workspace_id: String,
Expand Down Expand Up @@ -435,10 +444,13 @@ pub(crate) async fn codex_login_cancel_core(

pub(crate) async fn skills_list_core(
sessions: &Mutex<HashMap<String, Arc<WorkspaceSession>>>,
workspaces: &Mutex<HashMap<String, WorkspaceEntry>>,
workspace_id: String,
) -> Result<Value, String> {
let session = get_session_clone(sessions, &workspace_id).await?;
let params = json!({ "cwd": session.entry.path });
let (entry, parent_entry) = resolve_workspace_and_parent(workspaces, &workspace_id).await?;
let cwd = resolve_skills_cwd(&entry, parent_entry.as_ref());
let params = json!({ "cwd": cwd });
session.send_request("skills/list", params).await
}

Expand Down Expand Up @@ -495,3 +507,43 @@ pub(crate) async fn get_config_model_core(
let model = codex_config::read_config_model(Some(codex_home))?;
Ok(json!({ "model": model }))
}

#[cfg(test)]
mod tests {
use super::resolve_skills_cwd;
use crate::types::{WorkspaceEntry, WorkspaceKind, WorkspaceSettings, WorktreeInfo};

fn workspace_entry(kind: WorkspaceKind, path: &str, parent_id: Option<&str>) -> WorkspaceEntry {
WorkspaceEntry {
id: "id".to_string(),
name: "name".to_string(),
path: path.to_string(),
codex_bin: None,
kind,
parent_id: parent_id.map(|value| value.to_string()),
worktree: if kind.is_worktree() {
Some(WorktreeInfo {
branch: "branch".to_string(),
})
} else {
None
},
settings: WorkspaceSettings::default(),
}
}

#[test]
fn uses_entry_path_for_main_workspace_skills() {
let entry = workspace_entry(WorkspaceKind::Main, "/repo", None);
let cwd = resolve_skills_cwd(&entry, None);
assert_eq!(cwd, "/repo");
}

#[test]
fn uses_parent_path_for_worktree_skills() {
let parent = workspace_entry(WorkspaceKind::Main, "/repo", None);
let entry = workspace_entry(WorkspaceKind::Worktree, "/repo/wt", Some("parent"));
let cwd = resolve_skills_cwd(&entry, Some(&parent));
assert_eq!(cwd, "/repo");
}
}
10 changes: 9 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import "./styles/worktree-modal.css";
import "./styles/clone-modal.css";
import "./styles/branch-switcher-modal.css";
import "./styles/settings.css";
import "./styles/skills.css";
import "./styles/compact-base.css";
import "./styles/compact-phone.css";
import "./styles/compact-tablet.css";
Expand Down Expand Up @@ -468,7 +469,7 @@ function MainApp() {
reasoningSupported,
onFocusComposer: () => composerInputRef.current?.focus(),
});
const { skills } = useSkills({ activeWorkspace, onDebug: addDebugEntry });
const { skills, refreshSkills } = useSkills({ activeWorkspace, onDebug: addDebugEntry });
const { apps } = useApps({
activeWorkspace,
enabled: appSettings.experimentalAppsEnabled,
Expand Down Expand Up @@ -2360,6 +2361,13 @@ function MainApp() {
onDownloadDictationModel: dictationModel.download,
onCancelDictationDownload: dictationModel.cancel,
onRemoveDictationModel: dictationModel.remove,
skills,
onUseSkill: (name: string) => {
handleInsertComposerText(`/skill ${name}`);
},
onRefreshSkills: () => {
void refreshSkills();
},
}}
/>
</div>
Expand Down
85 changes: 83 additions & 2 deletions src/features/composer/hooks/useComposerAutocompleteState.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,19 @@ describe("useComposerAutocompleteState slash commands", () => {
"new",
"resume",
"review",
"skill",
"status",
]),
);
expect(labels.slice(0, 8)).toEqual([
expect(labels.slice(0, 9)).toEqual([
"apps",
"compact",
"fork",
"mcp",
"new",
"resume",
"review",
"skill",
"status",
]);
});
Expand Down Expand Up @@ -148,7 +150,86 @@ describe("useComposerAutocompleteState slash commands", () => {

const labels = result.current.autocompleteMatches.map((item) => item.label);
expect(labels).not.toContain("apps");
expect(labels).toEqual(["compact", "fork", "mcp", "new", "resume", "review", "status"]);
expect(labels).toEqual([
"compact",
"fork",
"mcp",
"new",
"resume",
"review",
"skill",
"status",
]);
});
});

describe("useComposerAutocompleteState /skill completions", () => {
it("shows skills after /skill and a space", () => {
const text = "/skill ";
const selectionStart = text.length;
const textareaRef = createRef<HTMLTextAreaElement>();
textareaRef.current = {
focus: vi.fn(),
setSelectionRange: vi.fn(),
} as unknown as HTMLTextAreaElement;

const { result } = renderHook(() =>
useComposerAutocompleteState({
text,
selectionStart,
disabled: false,
appsEnabled: true,
skills: [
{ name: "build_project", description: "Build it" },
{ name: "debug_app", description: "Debug it" },
],
apps: [],
prompts: [],
files: [],
textareaRef,
setText: vi.fn(),
setSelectionStart: vi.fn(),
}),
);

expect(result.current.isAutocompleteOpen).toBe(true);
expect(result.current.autocompleteMatches.map((item) => item.label)).toEqual([
"build_project",
"debug_app",
]);
});

it("filters skills after /skill with a query", () => {
const text = "/skill deb";
const selectionStart = text.length;
const textareaRef = createRef<HTMLTextAreaElement>();
textareaRef.current = {
focus: vi.fn(),
setSelectionRange: vi.fn(),
} as unknown as HTMLTextAreaElement;

const { result } = renderHook(() =>
useComposerAutocompleteState({
text,
selectionStart,
disabled: false,
appsEnabled: true,
skills: [
{ name: "build_project", description: "Build it" },
{ name: "debug_app", description: "Debug it" },
],
apps: [],
prompts: [],
files: [],
textareaRef,
setText: vi.fn(),
setSelectionStart: vi.fn(),
}),
);

expect(result.current.autocompleteMatches.map((item) => item.label)).toEqual([
"debug_app",
]);
});
});

Expand Down
Loading
Loading