diff --git a/.kagi/README.md b/.kagi/README.md index c4aa542..95d31c5 100644 --- a/.kagi/README.md +++ b/.kagi/README.md @@ -4,14 +4,15 @@ Zed tasks wrapping the `kagi` CLI. Each task spawns `bin/kagi-ask`, which queries Kagi Assistant, writes the markdown result to `.kagi/out/`, and opens it in Zed. -| Task label | Keybinding | Assistant | -| --------------------- | ----------------- | ----------------- | -| `kagi: prompt-refine` | TBD (D3) | `prompt-smith` | -| `kagi: explain` | TBD (D3) | `code-reader` | -| `kagi: review` | TBD (D3) | `code-reviewer` | -| `kagi: ask` | TBD (D3) | *(default)* | +| Task label | Keybinding | Persona | +| --------------------- | --------------------- | ------------------------------------------------------------------ | +| `kagi: prompt-refine` | `cmd-ctrl-r` | Rewrite prompt: minimal-token, unambiguous, agent-ready; fenced output only | +| `kagi: explain` | `cmd-ctrl-shift-e` | Concise code explanation; never restates the code | +| `kagi: review` | `cmd-ctrl-v` | Bug/edge-case/security review; terse bullets; no style nits | +| `kagi: ask` | `cmd-ctrl-a` | *(none — text passed through unchanged)* | - Tasks defined in `.zed/tasks.json`; open via the `task: spawn` modal. - Keybindings land in `~/.config/zed/keymap.json` (deliverable D3). -- Assistants are created with the `kagi` CLI (deliverable D4). +- Personas are inlined in `bin/kagi-ask` (D4 superseded: kagi-cli 0.16.0 + cannot reach custom assistants; see `.kagi/SETUP.md`). - Output files go to `.kagi/out/` (gitignored). diff --git a/.kagi/SETUP.md b/.kagi/SETUP.md index d62adeb..7855f8f 100644 --- a/.kagi/SETUP.md +++ b/.kagi/SETUP.md @@ -21,7 +21,7 @@ Wrapper invoked by Zed tasks. - Usage: `kagi-ask [language]` - Modes: `prompt-refine`, `explain`, `review`, `ask` -- Maps mode -> a custom assistant name (see D4). +- Maps mode -> an inlined persona (see D4). - Writes output to `$ZED_WORKTREE_ROOT/.kagi/out/-.md`, also echoes to stdout. - Must pass `--format markdown` and `--stream`. - Must `set -euo pipefail`, `mkdir -p` the out dir, and handle empty selection with a clear error. @@ -43,14 +43,10 @@ Bind each task with `["task::Spawn", { "task_name": "" }]` under `" Avoid collisions with the VSCode base keymap. ### D4 - custom assistants -Model slugs are unavailable: `kagi assistant models` returns `[]`. This is expected and is NOT a -blocker. Do not investigate it. Create all three WITHOUT `--model`; the account default applies. -Use only flags confirmed by `kagi assistant custom create --help`. -- `prompt-smith` - rewrites a prompt to be minimal-token, unambiguous, agent-ready. - Outputs ONLY the rewritten prompt in a fenced block. No web access. -- `code-reader` - explains code concisely; does not restate the code back. -- `code-reviewer` - bug/edge-case/security focus; terse bullets; no style nits. -Verify with `kagi assistant custom list` after creation. +### D4 - superseded +Personas are inlined in `bin/kagi-ask`; custom assistants are unreachable in +kagi-cli 0.16.0 (`custom create` fails with "assistant form missing name"; +`custom list` returns `[]`). Do not retry. ### D5 - housekeeping - Append `.kagi/out/` to `.gitignore`. @@ -59,5 +55,4 @@ Verify with `kagi assistant custom list` after creation. ## Acceptance - `bin/kagi-ask prompt-refine "write a function" Python` produces a markdown file in `.kagi/out/`. -- `kagi assistant custom list` returns the three assistants. - Each task appears in the `task: spawn` modal. diff --git a/.zed/tasks.json b/.zed/tasks.json index fe858a2..00043ae 100644 --- a/.zed/tasks.json +++ b/.zed/tasks.json @@ -2,7 +2,7 @@ { "label": "kagi: prompt-refine", "command": "$ZED_WORKTREE_ROOT/bin/kagi-ask", - "args": ["prompt-refine", "$ZED_SELECTED_TEXT", "$ZED_LANGUAGE"], + "args": ["prompt-refine", "\"${ZED_SELECTED_TEXT:-}\"", "\"${ZED_LANGUAGE:-unknown}\""], "cwd": "$ZED_WORKTREE_ROOT", "use_new_terminal": false, "allow_concurrent_runs": true, @@ -13,7 +13,7 @@ { "label": "kagi: explain", "command": "$ZED_WORKTREE_ROOT/bin/kagi-ask", - "args": ["explain", "$ZED_SELECTED_TEXT", "$ZED_LANGUAGE"], + "args": ["explain", "\"${ZED_SELECTED_TEXT:-}\"", "\"${ZED_LANGUAGE:-unknown}\""], "cwd": "$ZED_WORKTREE_ROOT", "use_new_terminal": false, "allow_concurrent_runs": true, @@ -24,7 +24,7 @@ { "label": "kagi: review", "command": "$ZED_WORKTREE_ROOT/bin/kagi-ask", - "args": ["review", "$ZED_SELECTED_TEXT", "$ZED_LANGUAGE"], + "args": ["review", "\"${ZED_SELECTED_TEXT:-}\"", "\"${ZED_LANGUAGE:-unknown}\""], "cwd": "$ZED_WORKTREE_ROOT", "use_new_terminal": false, "allow_concurrent_runs": true, @@ -35,7 +35,7 @@ { "label": "kagi: ask", "command": "$ZED_WORKTREE_ROOT/bin/kagi-ask", - "args": ["ask", "$ZED_SELECTED_TEXT", "$ZED_LANGUAGE"], + "args": ["ask", "\"${ZED_SELECTED_TEXT:-}\"", "\"${ZED_LANGUAGE:-unknown}\""], "cwd": "$ZED_WORKTREE_ROOT", "use_new_terminal": false, "allow_concurrent_runs": true, diff --git a/bin/kagi-ask b/bin/kagi-ask index 05d7a3b..4465baa 100755 --- a/bin/kagi-ask +++ b/bin/kagi-ask @@ -8,6 +8,12 @@ MODE="${1:-}" SELECTION="${2:-}" LANGUAGE="${3:-}" +# Personas are inlined here (D4 superseded: kagi-cli 0.16.0 cannot reach +# custom assistants; see .kagi/SETUP.md). +PERSONA_PROMPT_REFINE='Rewrite the provided prompt to be minimal-token, unambiguous, and agent-ready. Output ONLY the rewritten prompt, in a fenced code block. Nothing else: no commentary, no preamble.' +PERSONA_EXPLAIN='Explain the following code concisely. Do not restate the code back. Say what it does, how it works, and any notable details, in the fewest words that remain precise.' +PERSONA_REVIEW='Review the following code with a bug, edge-case, and security focus. Report findings as terse bullet points. Skip style nits.' + # Prefer the Zed-provided worktree root; fall back to the repo root so the # script also works outside Zed (e.g. the acceptance test in SETUP.md). ROOT="${ZED_WORKTREE_ROOT:-$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)}" @@ -22,10 +28,10 @@ usage() { [ -n "$MODE" ] || usage case "$MODE" in - prompt-refine) ASSISTANT="prompt-smith" ;; - explain) ASSISTANT="code-reader" ;; - review) ASSISTANT="code-reviewer" ;; - ask) ASSISTANT="" ;; # no custom assistant; default applies + prompt-refine) PERSONA="$PERSONA_PROMPT_REFINE" ;; + explain) PERSONA="$PERSONA_EXPLAIN" ;; + review) PERSONA="$PERSONA_REVIEW" ;; + ask) PERSONA="" ;; # no persona; pass the text through unchanged *) usage ;; esac @@ -42,17 +48,18 @@ fi mkdir -p "$OUT_DIR" OUT_FILE="$OUT_DIR/$(date +%Y%m%d-%H%M%S)-$MODE.md" -PROMPT="$SELECTION" +# Prompt: + blank line + --- + blank line + . +# ask mode passes the user text through unchanged. +if [ -n "$PERSONA" ]; then + PROMPT="$PERSONA"$'\n\n---\n\n'"$SELECTION" +else + PROMPT="$SELECTION" +fi if [ -n "$LANGUAGE" ]; then PROMPT="$PROMPT"$'\n\n'"Language: $LANGUAGE" fi -KAGI_ARGS=(assistant "$PROMPT" --format markdown --stream) -if [ -n "$ASSISTANT" ]; then - KAGI_ARGS+=(--assistant "$ASSISTANT") -fi - -kagi "${KAGI_ARGS[@]}" | tee "$OUT_FILE" +kagi assistant "$PROMPT" --format markdown --stream --no-web-access | tee "$OUT_FILE" # Open the result in Zed if the CLI is on PATH; skip silently otherwise. if command -v zed >/dev/null 2>&1; then