# Zot Instruct A Sublime Text 4 plugin that sends the selected code together with an instruction to the active [zot](https://www.zot.sh/) session through the local HTTP server of the `zot-editor-bridge` extension. ## Install Clone the repository into the Sublime Text `Packages` directory: ```bash git clone https://github.com/unlight/ZotInstruct.git \ "$HOME/.config/sublime-text/Packages/ZotInstruct" ``` Default locations: - Linux: `~/.config/sublime-text/Packages/ZotInstruct` - macOS: `~/Library/Application Support/Sublime Text/Packages/ZotInstruct` - Windows: `%APPDATA%\Sublime Text\Packages\ZotInstruct` Restart Sublime Text or run `sublime_plugin.reload_plugin` from the console (``Ctrl+` ``). No third-party dependencies: the plugin uses the bundled Python 3.8 only. Key bindings are opt-in. Run `Preferences > Package Settings > ZotInstruct > Example Key Bindings` (or `Preferences: ZotInstruct Example Key Bindings` from the Command Palette) to open `Example.sublime-keymap` next to your user keymap, then copy the `alt+enter` entries you want. Without bindings use the Command Palette. ## Usage 1. Select code or text. Multiple selections are supported and joined with a blank line. With an empty selection the plugin sends only the instruction. 2. Press `Alt+Enter` (`Option+Enter` on macOS), if the optional bindings are enabled, or run `Zot Instruct: Send Selection with Instruction` from the Command Palette (`Ctrl+Shift+P`). 3. Type the instruction in the input panel and press `Enter`. The panel is prefilled with the last instruction used for this file in the current Sublime Text session, or with the template for the file extension from the settings. The prefilled text is selected, so it can be replaced immediately. Additional command: - `Zot Instruct: Send Prompt Only` (`zot_instruct_prompt`) sends the instruction without code. This is what the optional `Alt+Enter` binding runs when the selection is empty. ## Settings `Preferences > Package Settings > ZotInstruct > Settings` opens the settings; `Example Key Bindings` opens the example keymap next to your user keymap. Files in `Packages/User/` override the defaults. | Setting | Default | Meaning | | --- | --- | --- | | `request_timeout` | `5` | HTTP request timeout in seconds. | | `instruction_defaults` | see the settings file | Instruction templates per extension; the `default` key covers the rest. | Keys in `instruction_defaults` may list several extensions separated by commas: `"ts,tsx,mts"`. ### Per-project overrides Add a `zot_instruct` object to the `settings` section of a `.sublime-project` file: ```json { "folders": [{ "path": "." }], "settings": { "zot_instruct": { "request_timeout": 10 } } } ``` These keys override `ZotInstruct.sublime-settings` for that project only. ## zot-editor-bridge integration The `zot-editor-bridge` extension runs an HTTP server inside each zot process and publishes its port in a file named after the session working directory: ```text editor-bridge-.port ``` The plugin hashes the project root open in Sublime Text (the window folder containing the active file), normalizes it like Go `filepath.Clean`, and checks these locations: 1. `$ZOT_HOME/editor-bridge-.port` when `ZOT_HOME` is set; 2. otherwise in the zot state directory (`$XDG_STATE_HOME/zot` or `~/.local/state/zot` on Linux, `~/Library/Application Support/zot` on macOS, `%LOCALAPPDATA%\zot` on Windows); 3. when `ZOT_HOME` is unset, the compatible `~/.zot` copy. Start zot in the project root: a session started in a subdirectory hashes to a different file and is not found. Before sending, the plugin calls `GET /health` with a one second timeout and requires the reported `cwd` to match the project root. A stale file is removed only if it still contains the same port. Discovery runs on every send, never in the background. Each zot window in a different project gets its own file, so requests reach the session started in that project. Two zot windows in the same project share one file: the last started window wins. To pin the bridge port, set `ZOT_EDITOR_BRIDGE_PORT` before starting zot; the port file still receives the actual port in use. Install the extension: ```bash cd zot-editor-bridge zot ext install . ``` Start zot: the extension reports the port on startup. Run `/editor-bridge` in zot to print its `/send` and `/health` URLs and the port file path. ## Troubleshooting Errors appear in the status bar; details are printed to the Sublime Text console (``Ctrl+` ``) with the `[ZotInstruct]` prefix. - `zot is not running for this project` means no live port file matched the project root: start zot in the project directory. - `HTTP 4xx/5xx` means the server returned an error; the response text is shown in the status bar and the console. ## Development ```bash python3 tests/selfcheck.py ``` The plugin targets the Python 3.8 runtime bundled with Sublime Text 4; CI also runs the self-check on Python 3.12. ## License [MIT](https://opensource.org/licenses/MIT), Copyright (c) 2026