Compare commits
10
Commits
75025c2406
...
7fc7d0202c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7fc7d0202c | ||
|
|
ad8c25c713 | ||
|
|
d083cbf88b | ||
|
|
ba22bc2ef2 | ||
|
|
48779cb930 | ||
|
|
df4605bac1 | ||
|
|
cfd9ffe943 | ||
|
|
7ec0c20989 | ||
|
|
74c1dfaeb8 | ||
|
|
6beecaac83 |
No files matched your search
+1
-1
@@ -1,2 +1,2 @@
|
||||
mod/ovis-composer/gpui-kit.d.ts
|
||||
herdr/herdr-composer/mods/herdr-composer/gpui-kit.d.ts
|
||||
node_modules/
|
||||
@@ -1,43 +1,106 @@
|
||||
# herdrMario
|
||||
# herdr-composer
|
||||
|
||||
Source of the `ovis-composer` Herdr mod (Unified Prompt Experience).
|
||||
Pasek wiadomości dla agentów w [Herdr](https://herdr.dev). Jedno pole pod terminalem pisze do agenta, który ma fokus. Do tego:
|
||||
|
||||
- `mod/ovis-composer/` - the mod (ES modules; Herdr does not see changes behind the junction - see Reload)
|
||||
- `layouts/ovis-composer.json` - its layout
|
||||
- `tests/` - Node tests for the pure modules (`npm test`)
|
||||
- `docs/superpowers/` - spec and plan
|
||||
- drafty per agent, które przetrwają restart,
|
||||
- kolejka czekająca na koniec tury agenta,
|
||||
- historia i ulubione,
|
||||
- podpowiedzi `/` i `@`,
|
||||
- jeden sposób dodawania załączników: upuszczenie, przycisk `+`, Ctrl+V.
|
||||
|
||||
## Install
|
||||

|
||||
|
||||
```powershell
|
||||
.\scripts\install.ps1
|
||||
## Wymagania
|
||||
|
||||
- **Windows.** Przycisk `+` i wklejanie obrazów przez Ctrl+V używają PowerShell. Reszta działa wszędzie, gdzie działa Herdr.
|
||||
- **Herdr** (`herdr-app`, `hc`) w `PATH`. Sprawdzone na herdr-core 0.1.21.
|
||||
- **Git** z dostępem do `http://git.mkali.pl/Factor/herdrMario.git` (repo prywatne). Klonowanie użyje Twoich zapisanych poświadczeń.
|
||||
- Do testów: **Node.js ≥ 20**.
|
||||
|
||||
## Instalacja
|
||||
|
||||
Obie drogi dają ten sam wynik.
|
||||
|
||||
**1. Przez agenta** (tak jak layouty z herdr.dev). Wklej agentowi w Herdr:
|
||||
|
||||
```text
|
||||
Read ~/.config/herdr-app/AGENTS.md, then add this layout: clone http://git.mkali.pl/Factor/herdrMario.git and use the folder herdr/herdr-composer
|
||||
```
|
||||
|
||||
Idempotent. An existing real `mods\ovis-composer` directory is renamed to
|
||||
`ovis-composer.bak-20261119` (never deleted), a junction to `mod\ovis-composer`
|
||||
takes its place, and the layout is copied to `~\.config\herdr-app\layouts\`
|
||||
(existing file backed up once as `.bak-20261119`).
|
||||
**2. Jedną komendą** (`cmd`):
|
||||
|
||||
The script ends with `herdr-app do layout.switch '{"name":"ovis-composer"}'`.
|
||||
Check with `herdr-app check <mods>\ovis-composer` and `herdr-app status`.
|
||||
|
||||
## Reload
|
||||
|
||||
Herdr does **not** see changes to the mod files behind the junction: a running
|
||||
copy keeps the code it loaded. After every edit of `mod\ovis-composer`:
|
||||
|
||||
```powershell
|
||||
.\scripts\install.ps1 -Reload
|
||||
```cmd
|
||||
git clone http://git.mkali.pl/Factor/herdrMario.git "%USERPROFILE%\herdrMario" && "%USERPROFILE%\herdrMario\install.cmd"
|
||||
```
|
||||
|
||||
It removes the junction and makes it again (the repo files stay), and Herdr
|
||||
loads the mod from scratch.
|
||||
`install.cmd` uruchamia `scripts\install.ps1` z `-ExecutionPolicy Bypass`, tylko dla tego jednego wywołania. Działa więc także tam, gdzie uruchamianie skryptów `.ps1` jest wyłączone. Instalator:
|
||||
|
||||
## Uninstall
|
||||
- **Aktualizuje repo:** robi `git pull --ff-only`, ale tylko w czystym klonie. Błąd pull to ostrzeżenie, nie przerwanie.
|
||||
- **Kopiuje mod i layout:** mod trafia do `~\.config\herdr-app\mods\herdr-composer` (kopia lustrzana), layout do `layouts\herdr-composer.json`. Herdr sam wczytuje nowe pliki. Jeśli istnieje inny layout o tej nazwie, najpierw robi jego kopię zapasową.
|
||||
- **Dopisuje skrót** do Twojego `keys.json`: `ctrl-shift-space` przenosi fokus do composera. Przed zapisem robi kopię. Klawisza, który masz przypisany do czegoś innego, nie rusza i wypisuje ostrzeżenie. Formatowanie `keys.json` się zmienia, znaczenie nie.
|
||||
- **Usuwa poprzednią wersję `ovis-composer`:** junction albo katalog modu, layout i skrót. Historia, ulubione, drafty i kolejki zostają (patrz [Przejście z ovis-composer](#przejście-z-ovis-composer)).
|
||||
- **Sprawdza i przełącza:** uruchamia `herdr-app check`. Na layout `herdr-composer` przełącza tylko przy pierwszej instalacji albo wtedy, gdy aktywny był `ovis-composer`. W pozostałych przypadkach podpowiada `ctrl-shift-l`.
|
||||
|
||||
```powershell
|
||||
.\scripts\install.ps1 -Uninstall
|
||||
Wszystkie kopie zapasowe trafiają do `~\.config\herdr-app\backups\herdr-composer\<rrrrMMdd-HHmmss>\`, nigdy do `mods\` ani `layouts\`, bo Herdr wczytałby je jako mod lub layout. Pliki repo nigdy nie są usuwane.
|
||||
|
||||
## Aktualizacja
|
||||
|
||||
Uruchom ponownie `install.cmd` albo poproś agenta jeszcze raz. Herdr sam przeładuje mod, bez restartu.
|
||||
|
||||
## Odinstalowanie
|
||||
|
||||
```cmd
|
||||
install.cmd -Uninstall
|
||||
```
|
||||
|
||||
Removes the junction (the repo files stay), restores the `.bak-20261119` mod
|
||||
directory, layout and `keys.json` backups, and switches to the `main` layout.
|
||||
Usuwa `mods\herdr-composer`, `layouts\herdr-composer.json` i skrót z `keys.json`, a potem przełącza na layout `main`. Zostają tylko kopie w `backups\herdr-composer\`.
|
||||
|
||||
## Użycie
|
||||
|
||||
| Klawisz / akcja | Co robi |
|
||||
|---|---|
|
||||
| klik w pole, `Ctrl+Shift+Space` | fokus w composerze (klik w terminal oddaje klawiaturę terminalowi) |
|
||||
| `Enter` / `Shift+Enter` | wyślij / nowa linia |
|
||||
| `Ctrl+Enter` | wyślij teraz, z pominięciem kolejki |
|
||||
| `Alt+Enter` | do kolejki jako wstrzymana (wyślesz ręcznie) |
|
||||
| `Esc` | zamyka menu lub panel; przy pustym polu przerywa pracującego agenta |
|
||||
| `/`, `@` | podpowiedzi komend, skilli i plików; `↑` `↓` wybór, `Enter`/`Tab` wstaw |
|
||||
| `Ctrl+R` albo 🕘 | panel Historia / Ulubione: `↑` `↓`, `Enter` wstawia w miejscu kursora (bez wysyłania), `Tab` przełącza zakładki, `Ctrl+D` lub prawy klik dodaje do ulubionych, `Esc` lub ✕ zamyka |
|
||||
| ☆ | zapisuje bieżący tekst w ulubionych |
|
||||
| `+`, upuszczenie pliku, `Ctrl+V` obrazu | załącznik: kopiowany do agenta przez `hc put` i dopisywany jako `@ścieżka` |
|
||||
|
||||
**Kolejka:** gdy agent pracuje, `Enter` dodaje wiadomość do kolejki. Po zakończeniu tury pojawia się odliczanie 3 s z przyciskiem Anuluj, a potem wiadomość wychodzi. Stop albo `Esc` wstrzymuje całą kolejkę. Gdy agent czeka na Twoją odpowiedź (`blocked`), `Enter` wysyła ją od razu (`hc send --force`).
|
||||
|
||||
**Dane:** historia (500 wpisów), ulubione (100), drafty i kolejki zapisują się lokalnie w `~\.config\herdr-app\shared.json` (klucze `herdr-composer.*`). Obrazy ze schowka trafiają do `~\.config\herdr-app\data\herdr-composer\paste\` i są usuwane po 7 dniach. Nic nie jest wysyłane poza ten komputer.
|
||||
|
||||
## Co mod uruchamia i czyta
|
||||
|
||||
Agent instalujący paczkę poinformuje o tym przed instalacją.
|
||||
|
||||
- **`hc`:** `send`, `put`, `get`, `interrupt`, `keys`. Tak mod rozmawia z terminalami agentów.
|
||||
- **`powershell`:** odczyt schowka, okno wyboru pliku, rozmiary plików, odczyt komend i skilli z `.claude/` projektu. Ścieżki trafiają do skryptów wyłącznie jako Base64.
|
||||
- **`git ls-files`** w folderze agenta: podpowiedzi `@`.
|
||||
- **Pliki spoza folderu modu:** pliki, które sam dodajesz jako załączniki, oraz `.claude/commands` i `.claude/skills` projektu.
|
||||
- **Sieć:** mod nie korzysta z sieci.
|
||||
|
||||
## Przejście z ovis-composer
|
||||
|
||||
Wcześniejsza wersja nazywała się `ovis-composer`. Instalator usuwa ją automatycznie. Mod przy pierwszym odczycie przenosi dane z kluczy `ovis-composer.*` do `herdr-composer.*`; starych kluczy nie kasuje. Instalator nie rusza starych kopii `mods\ovis-composer.bak-*` i `layouts\ovis-composer.json.bak-*`. Możesz je usunąć ręcznie.
|
||||
|
||||
## Rozwiązywanie problemów
|
||||
|
||||
- **Composer się nie pokazuje:** sprawdź `herdr-app status`. Pole `"layout"` powinno mieć wartość `herdr-composer`, a `"errors"` powinno być puste. Layout przełączysz przez `ctrl-shift-l`.
|
||||
- **Mod nie reaguje po zmianie plików:** uruchom ponownie `install.cmd`. Herdr widzi tylko pliki w `~\.config\herdr-app\mods\`, a nie te w repo.
|
||||
- **`Ctrl+Shift+Space` nie działa:** sprawdź, czy w `~\.config\herdr-app\keys.json` (sekcja `global`) jest `"ctrl-shift-space": "herdr-composer.focus"` i czy obok nie powstał plik `keys.error`.
|
||||
- **Coś nie gra po instalacji:** `install.cmd -Uninstall`, a potem przywróć potrzebny plik z `backups\herdr-composer\`. Awaryjnie `ctrl-alt-shift-escape` zawsze wraca do layoutu `main`.
|
||||
|
||||
## Rozwój
|
||||
|
||||
Struktura repo:
|
||||
|
||||
- `herdr/herdr-composer/`: paczka w formacie Herdr (`layouts/`, `mods/herdr-composer/`, `keys.json`, `RECIPE.md`, `preview.png`).
|
||||
- `tests/`: testy czystych modułów (`npm test`).
|
||||
- `scripts/install.ps1`: instalator, wywoływany przez `install.cmd`.
|
||||
- `docs/superpowers/`: specyfikacja, plany, makieta, raporty weryfikacji.
|
||||
|
||||
Cykl pracy: edytuj pliki w `herdr/herdr-composer/mods/herdr-composer/`, uruchom `npm test`, potem `install.cmd`, żeby skopiować zmianę do Herdr. Problemy pokażą `herdr-app check "%USERPROFILE%\.config\herdr-app\mods\herdr-composer"` i `herdr-app status`.
|
||||
@@ -0,0 +1,39 @@
|
||||
# herdr-composer — instalowalna paczka (projekt + plan)
|
||||
|
||||
> Zatwierdzone przez użytkownika 2026-11-19. Wykonawca: Ovis Fast. Review: Ovis Opus.
|
||||
|
||||
## Cel
|
||||
Prywatny mod (repo `http://git.mkali.pl/Factor/herdrMario.git`) instalowany jedną komendą — przez agenta (wzór herdr.dev: „Read ~/.config/herdr-app/AGENTS.md, then add this layout: …”) albo `install.cmd`. Nazwa `herdr-composer` (zamiast `ovis-composer`). Bez publikacji na GitHub/herdr.dev.
|
||||
|
||||
## Decyzje
|
||||
- Format paczki wg `~/.config/herdr-app/AGENTS.md` („Layouts and mods other people made”): folder `herdr/herdr-composer/` = `layouts/herdr-composer.json`, `mods/herdr-composer/*`, `keys.json`, `RECIPE.md`, `preview.png`.
|
||||
- Instalacja przez **kopię** (nie junction) → Herdr sam przeładowuje mod; aktualizacja = ponowne `install.cmd`.
|
||||
- Zmiana nazwy bez utraty danych: odczyt `herdr-composer.*`, a gdy brak — `ovis-composer.*` (i zapis pod nową nazwą).
|
||||
|
||||
## Zadanie A (Ovis Fast) — restrukturyzacja + zmiana nazwy + migracja
|
||||
1. `git mv mod/ovis-composer herdr/herdr-composer/mods/herdr-composer`; `git mv layouts/ovis-composer.json herdr/herdr-composer/layouts/herdr-composer.json` (w layoucie `content.mod` → `herdr-composer`). Usuń puste `mod/`, `layouts/`.
|
||||
2. W kodzie modu wszystkie identyfikatory `ovis-composer` → `herdr-composer`: `CONTEXT`/`key_context`, nazwy akcji `herdr-composer.*` (bind_keys + on_action), klucze `storage.KEYS` (`herdr-composer.history`, `.favorites`, `.usage`, `.userMin`, `.draft:<a>`, `.queue:<a>`), folder obrazów `data/herdr-composer/paste/`, `id()` elementów, komentarze/teksty. `.gitignore`: `herdr/herdr-composer/mods/herdr-composer/gpui-kit.d.ts`.
|
||||
3. Migracja w `storage.js` (czyste, testowane): każda funkcja `load*` czyta nowy klucz; gdy `null/undefined` — czyta klucz `ovis-composer.*` (ta sama końcówka) i, jeśli coś znalazła, zapisuje to pod nowym kluczem. Stare klucze zostają nietknięte. `cleanupPaste` sprząta oba foldery (`data/ovis-composer/paste` i nowy).
|
||||
4. `herdr/herdr-composer/keys.json`: `{"global": {"ctrl-shift-space": "herdr-composer.focus"}}`.
|
||||
5. Testy: importy z `../herdr/herdr-composer/mods/herdr-composer/<m>.js`; nowe testy migracji (nowy klucz wygrywa; fallback ze starego + zapis pod nowym; brak obu → domyślne; śmieci w starym kluczu → ignorowane jak dotąd).
|
||||
6. `grep -ri "ovis-composer"` w `herdr/` i `tests/` → tylko w kodzie migracji i w RECIPE (zdanie o pochodzeniu).
|
||||
|
||||
## Zadanie B (Ovis Fast) — instalator
|
||||
`install.cmd` w korzeniu repo (wywołuje `powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0scripts\install.ps1" %*`) i przepisany `scripts/install.ps1` (PowerShell 5):
|
||||
- `install` (domyślnie): jeśli repo jest klonem git i nie ma lokalnych zmian → `git pull --ff-only` (błąd = ostrzeżenie, kontynuacja). Kopiuje `herdr/herdr-composer/mods/herdr-composer` → `%USERPROFILE%\.config\herdr-app\mods\herdr-composer` (mirror: `robocopy /MIR`, kod wyjścia < 8 = OK; pomija `gpui-kit.d.ts`, `jsconfig.json`) i layout → `layouts\herdr-composer.json`. Scalenie `keys.json` paczki do `keys.json` użytkownika (kopia `keys.json.bak-herdr-composer` raz; nie nadpisuje istniejącego klawisza innego niż nasz — ostrzeżenie). Na końcu `herdr-app check …\mods\herdr-composer` i `herdr-app do layout.switch '{"name":"herdr-composer"}'`; brak `herdr-app` w PATH → ostrzeżenie, nie wyjątek.
|
||||
- **Sprzątanie poprzedniej wersji (`ovis-composer`):** jeśli `mods\ovis-composer` jest junction → `cmd /c rmdir` (tylko link); jeśli zwykły katalog → przenieś do `mods\ovis-composer.bak-<data>`. `layouts\ovis-composer.json` → przenieś do `.bak-<data>`. W `keys.json` usuń wpis wskazujący na `ovis-composer.focus`. Nigdy nie usuwaj plików repo.
|
||||
- `-Uninstall`: usuwa `mods\herdr-composer`, `layouts\herdr-composer.json`, nasz klawisz z `keys.json`, przełącza na `main`.
|
||||
- README: sekcja „Instalacja” — (1) przez agenta: `Read ~/.config/herdr-app/AGENTS.md, then add this layout: clone http://git.mkali.pl/Factor/herdrMario.git and use the folder herdr/herdr-composer`; (2) jedna komenda: `git clone http://git.mkali.pl/Factor/herdrMario.git "%USERPROFILE%\herdrMario" && "%USERPROFILE%\herdrMario\install.cmd"`; aktualizacja: ponownie `install.cmd`; odinstalowanie: `install.cmd -Uninstall`.
|
||||
- Usuń `-Reload` i junction z dokumentacji (nieaktualne).
|
||||
|
||||
## Zadanie C (Ovis Fast) — RECIPE.md + preview.png
|
||||
`herdr/herdr-composer/RECIPE.md` dokładnie wg struktury z AGENTS.md (Name + akapit + ``; What you see; How it behaves; Built from; Watch out). W **Built from/Watch out** jawnie: uruchamia `powershell` (`exec`: schowek, wybór pliku, rozmiary plików — ścieżki tylko jako Base64), `hc` (`send`, `put`, `get`, `interrupt`, `keys`), czyta pliki spoza swojego folderu (pliki użytkownika wskazane jako załączniki, `git ls-files` w folderze agenta); „+” i Ctrl+V obrazu tylko Windows; layout jest klonem `main` (wersja z `cloned_from`); UX inspirowany Ovis (devswha/ovis). `preview.png`: zrzut `herdr-app shot` okna z composerem (po instalacji, Zadanie D).
|
||||
|
||||
## Zadanie D (Ovis Opus) — instalacja na tej maszynie i weryfikacja
|
||||
`install.cmd` na tym komputerze → `herdr-app status` bez błędów, layout `herdr-composer`, historia/ulubione/drafty widoczne (migracja), `Ctrl+Shift+Space`, panel, test w GUI. `preview.png` ze zrzutu.
|
||||
|
||||
## Kryteria akceptacji
|
||||
- `npm test` zielone; `herdr-app check` modu OK.
|
||||
- Po `install.cmd` Herdr pokazuje composer w layoucie `herdr-composer`, historia sprzed zmiany nazwy jest widoczna.
|
||||
- Zmiana w repo + ponowne `install.cmd` → Herdr przeładowuje mod bez dodatkowych kroków.
|
||||
- `install.cmd -Uninstall` zostawia `~/.config/herdr-app` bez śladów `herdr-composer` (poza kopiami `.bak`).
|
||||
@@ -0,0 +1,186 @@
|
||||
# herdr-composer
|
||||
|
||||
A message bar under the terminal. The person types to the focused agent in one
|
||||
field that is theirs: the text survives switching agents and restarting Herdr, a
|
||||
message sent while the agent works waits for its turn and goes out on its own, files
|
||||
and images are dropped, picked or pasted in, and everything sent can be found again
|
||||
(and starred) in a History | Favourites panel. The terminal underneath only shows.
|
||||
|
||||

|
||||
|
||||
It is a layout (a clone of `main`, Herdr 0.1.16) plus one mod. It descends from the
|
||||
`ovis-composer` mod of this repo; the UX is inspired by Ovis (devswha/ovis).
|
||||
|
||||
## What you see
|
||||
|
||||
The window is the `main` layout with one block added. Left to right, top to bottom:
|
||||
|
||||
- **Sidebar**, 268 px, `chrome` background: brand row (46 px), the Spaces list and the
|
||||
Agents list (equal weight, 90 px minimum), the footer (69 px).
|
||||
- **Work column** (resizable): tabs (42 px), then the body (8 px padding, 8 px gap): the
|
||||
terminal pane of the active tab and, on the right, a 368 px panel (280-900 px) with
|
||||
Files and Changes; then **the composer block**; then the status bar (28 px).
|
||||
- **The composer block** starts at 150 px layout height (120-520) and is as tall as its
|
||||
content (see Watch out); its content sits at the bottom edge, 8 px padding, 6 px gap.
|
||||
Top to bottom, only what applies is drawn:
|
||||
1. the suggestion menu (rounded 10, `popover` background, a list 118 px high, groups
|
||||
in 10 px `dim` type, one row per command or file);
|
||||
2. the queue: one row per waiting message (a 7 px colored dot, the text, a state
|
||||
label, buttons);
|
||||
3. the question about an image for a program that may not take it;
|
||||
4. a notice line (11.5 px; `dim`, or `blocked` red for problems);
|
||||
5. **the card** (rounded 12, 1 px `border`, `raised` background): attachment tiles
|
||||
(44 px high: 36 px thumbnail or extension, name, size or reason, "Ponów", x), the
|
||||
field (`background`, rounded 8, 13 px, 1 to 10 rows), and a row of controls: three
|
||||
28 px round buttons `+`, a clock, a star; a flexible gap; the agent pill (rounded 12:
|
||||
a 7 px status dot, the tab's name, the status word, a paperclip and the count when
|
||||
files are attached); and a 32 px round button, a white arrow to send, or a white
|
||||
square (Stop) when the field is empty and the agent works;
|
||||
6. the strip: `space · folder · branch` left (11 px, `dim`), `N / 20000` right
|
||||
(red `Limit 20000 znaków · N za dużo` when over).
|
||||
- **The panel** (Ctrl+R or the clock) covers the whole block (6 px inset, rounded 12,
|
||||
`popover` background): the header (tabs "Historia N" and "Ulubione N", a 30 px search
|
||||
field with a magnifier, a 28 px close x), the list (rows 56 px: the text in two lines
|
||||
with the match lit, a line `DD.MM HH:MM · space · tab`, a star), the footer with the keys.
|
||||
While it is open a block lower than 320 px is made 360 px tall and goes back when it closes.
|
||||
- **The preview** of an image (click a thumbnail): a dark scrim over the block, the image,
|
||||
`name · size · Esc zamyka`.
|
||||
|
||||
Polish is the language of every text of the mod.
|
||||
|
||||
## How it behaves
|
||||
|
||||
**Status of the agent** (pill dot and word): working "pracuje", blocked "czeka na Ciebie",
|
||||
done "skończył", idle "gotowy" (the dot takes the theme color of the status).
|
||||
|
||||
**Focus follows the click.** The composer never takes the keyboard on its own: the field
|
||||
has it after a click on it or `ctrl-shift-space`; a click in a terminal gives the keys to
|
||||
that terminal. A focus on a terminal that is not an agent: the field is replaced by
|
||||
"Ten terminal nie jest agentem. Wybierz agenta z listy, aby pisać." and the draft is kept.
|
||||
|
||||
**Keys in the field:** Enter sends (the message is trimmed; empty is ignored), Shift+Enter
|
||||
a new line, Ctrl+Enter sends now whatever the status, Alt+Enter queues it held
|
||||
("Wstrzymana — wyślij ręcznie"), Ctrl+R opens the panel, Esc closes the menu or the
|
||||
panel and otherwise, with an empty field and a working agent, stops the agent
|
||||
(`hc interrupt`; the queue is held and nothing goes out on its own). Up/Down/Tab move
|
||||
and accept in the suggestion menu; without a menu Up/Down move the cursor between lines.
|
||||
|
||||
**Sending.** Idle or done: out at once ("Wysłano do terminala."). Blocked: out at once with
|
||||
`--force` (an answer), ahead of the queue. Working: into the queue ("Następna tura"). When
|
||||
the turn ends (working or blocked, then idle or done) the first queued message counts
|
||||
down "Wysyłam za 3 s" (button "Anuluj" holds it) and goes out; the next waits for the
|
||||
next turn. One message per turn. A message that goes while another is queued or counting
|
||||
waits at the end of the queue. Queue rows: "Wyślij teraz" (held), "Ponów" (an unconfirmed
|
||||
one), "Edytuj" (back into the field at the caret), "Usuń". After a restart a message that
|
||||
was on the wire is "Nie potwierdzono" and is never sent again on its own.
|
||||
|
||||
**Drafts.** Per agent (the key is the address, `t2`), written 500 ms after the last change
|
||||
and at once when the agent changes; text, caret, attachments. The identity of the terminal
|
||||
(`created_ms` from `hc get`) is stored with it: when the address now belongs to another
|
||||
terminal the draft comes back with "Szkic z poprzedniej sesji agenta" and the whole queue
|
||||
is held.
|
||||
|
||||
**Suggestions.** `/` at the start of a line: the built-in commands of the agent
|
||||
(`claude-code`, `codex`, ...), the project's `.claude/commands/*.md` and
|
||||
`.claude/skills/*/SKILL.md`, ranked by use; `@`: the project's files (`git ls-files`).
|
||||
|
||||
**Attachments.** One pipeline for a drop, the `+` button (a file dialog) and Ctrl+V (an
|
||||
image or copied files; text pastes as text): checked (32 MiB a file, 100 a message, no
|
||||
folders), a tile "dodawanie...", `hc put <agent> <file>`, then ready and `@path` goes
|
||||
into the text - the path the agent sees, in quotes when it has a space. Pasted images are
|
||||
saved in `data/herdr-composer/paste/` (removed after 7 days). An image for a program
|
||||
other than `claude-code`, `codex`, `gemini`, `opencode` asks first ("Anuluj" / "Wyślij mimo to").
|
||||
|
||||
**History and favourites.** Every message that `hc send` accepted is stored (500, newest
|
||||
first, any space or agent). In the panel: type to search (case-insensitive, Polish letters
|
||||
too), Up/Down, Enter inserts at the caret the field had when the panel opened and sends
|
||||
nothing, Tab switches tab, Ctrl+D or a right click stars a row, Esc or the x closes. The
|
||||
star next to the field stars the text in it (100 favourites).
|
||||
|
||||
## Built from
|
||||
|
||||
**Layout** `layouts/herdr-composer.json`, a clone of `main` (`cloned_from` 0.1.16), `canvas`
|
||||
background, no title bar, 1 px `border` dividers. Tree: `root` (row) > `sidebar` (column,
|
||||
268 px, 44-480, `chrome`; `brand` workspace-chrome 46 px, `sidebar-lists` with `spaces` and
|
||||
`agents`, `sidebar-footer` workspace-chrome `{footer: true}` 69 px) and `work` (column,
|
||||
`resizable: true`; `tabs` 42 px, `work-body` row with `main` and `panel` (368 px, 280-900;
|
||||
a stack of `files` and `changes`), `composer`, `status` workspace-status 28 px). The block
|
||||
`composer`: `content: {mod: "herdr-composer"}`, `size: {px: 150}`, `min: 120`, `max: 520`,
|
||||
a `focus` border in `accent`.
|
||||
|
||||
**Mod** `mods/herdr-composer/` (`mod.json`: `place: none`, `focusable: true`): `main.js` (the
|
||||
view), `state.js` (drafts, attachments, queue; pure), `delivery.js` (sending, the gate,
|
||||
countdown rules), `storage.js` (the shared store, migration from `ovis-composer.*`),
|
||||
`history.js`, `attachments.js`, `clipboard.js`, `suggest.js`, `catalog.js`, `keys.js`,
|
||||
`view.js` (helpers), `panel.js` (the panel and the preview). The pure modules import nothing
|
||||
from Herdr and are tested with Node (`npm test`).
|
||||
|
||||
**Herdr API:** `agents`, `panes`, `focused`, `theme`, `settings` (`zoom`), `appHome`,
|
||||
`shared`/`setShared` (the store: `herdr-composer.history`, `.favorites`, `.usage`,
|
||||
`.userMin`, `.draft:<address>`, `.queue:<address>`), `notify` (toast, only for a failed
|
||||
send or `hc` call), `nextCommand`, `run("layout.resize", {id: "composer", px})`,
|
||||
`cx.bind_keys` in the context `herdr-composer > Input` (up, down, tab, ctrl-r,
|
||||
ctrl-enter, alt-enter, escape), `fs/promises` (the paste folder), gpui-kit and gpui-base
|
||||
(`v_flex`, `h_flex`, `Textarea`, `Input`, `v_virtual_list`, `Scrollbar`, `image`,
|
||||
`on_size_change`, `on_drop`, the `paste_other` event of the textarea).
|
||||
|
||||
**`keys.json`:** `global` `ctrl-shift-space` -> `herdr-composer.focus`.
|
||||
|
||||
**Programs it runs - say this before installing:**
|
||||
- `powershell -NoProfile -STA -Command ...` (`exec`): reads the clipboard (files, an
|
||||
image saved as PNG), shows the file dialog, measures the files dropped or picked. Every
|
||||
path goes in as Base64 of UTF-8, never as text of the script.
|
||||
- `hc` (herdr-core): `hc send --json [--force] <terminal> -- <text>`, `hc put <terminal>
|
||||
<file> --json`, `hc get <terminal> --json`, `hc interrupt <terminal> --json`.
|
||||
- `git ls-files` and, for the `/` menu, `sh` or `powershell` reading
|
||||
`.claude/commands/*.md` and `.claude/skills/*/SKILL.md` in the agent's folder.
|
||||
|
||||
**Files outside its own folder:** the files the person drops, picks or copies (to attach
|
||||
them), the agent's project folder (the lists above), `data/herdr-composer/paste/`.
|
||||
It makes no network request.
|
||||
|
||||
**Art:** none; the glyphs `+`, a clock, a star, `x`, a magnifier, a paperclip are text.
|
||||
|
||||
## Watch out
|
||||
|
||||
- `hc send` reads a message that starts with `-` as an option unless the text is after
|
||||
`--`. Always send `["send", "--json", terminal, "--", text]`.
|
||||
- `--force` only for the person's own Enter to a blocked agent, never from the queue.
|
||||
- The block reports its size in logical pixels (layout px times `settings().zoom`);
|
||||
`layout.resize` wants layout px. Divide by the zoom or the block grows by the zoom factor.
|
||||
- The block's height: the content's, floored at the height the person dragged the border
|
||||
to (`herdr-composer.userMin`), 120-520, resized after 120 ms and only for a difference
|
||||
over 4 px; the panel pauses it.
|
||||
- Row handlers cannot live inside a `v_virtual_list` renderer: a row click uses
|
||||
`on_item_click`, so the star in a panel row is a sign; Ctrl+D or a right click toggle it.
|
||||
- `image()` draws only files inside the app's folder (give it the path relative to
|
||||
`appHome()`): thumbnails exist for pasted images; an image from elsewhere gets a tile
|
||||
with its extension and no preview.
|
||||
- The textarea binds the arrows and Tab and eats them; the composer binds the same keys
|
||||
itself in `herdr-composer > Input`. An open panel takes them first, whoever has the keyboard.
|
||||
- Whether Ctrl+Z undoes an insert from the panel is not verified; the notice does not promise it.
|
||||
- A mod copy is loaded once: after an update Herdr must see changed files (`install.cmd`
|
||||
copies them, so it reloads the mod).
|
||||
- Windows only: the clipboard, the `+` dialog and the file sizes use PowerShell.
|
||||
- Limits: 20 000 characters a message, 32 MiB a file, 100 files a message, history 500,
|
||||
favourites 100, the menu shows 20 rows.
|
||||
- The layout is a clone: it keeps the look of `main` as of 0.1.16 and does not follow later
|
||||
changes of `main`.
|
||||
- Data kept under `ovis-composer.*` by the earlier name is read when the new key is empty
|
||||
and written under `herdr-composer.*`; the old keys stay.
|
||||
|
||||
## Done when
|
||||
|
||||
- `herdr-app check mods/herdr-composer` passes and `herdr-app status` shows no errors with
|
||||
the layout `herdr-composer` shown.
|
||||
- Typing in the field, switching to another agent and back, restarting Herdr: the text and
|
||||
the caret are back for each agent.
|
||||
- Enter to an idle agent sends; to a working one queues, and after the turn a 3-second
|
||||
countdown with "Anuluj" precedes the send; Stop empties nothing but holds the queue.
|
||||
- Enter to a blocked agent sends at once.
|
||||
- A message starting with `- ` or `--help` is delivered as text.
|
||||
- Ctrl+V of a screenshot gives a tile and an `@path`; the agent can read the image.
|
||||
- Ctrl+R opens the panel with the sent messages; search lights the match; Enter inserts at
|
||||
the caret and sends nothing; Esc closes it and the block returns to its height.
|
||||
- Ctrl+Shift+Space focuses the field; clicking a terminal gives that terminal the keys.
|
||||
- `npm test` passes.
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"global": {
|
||||
"ctrl-shift-space": "herdr-composer.focus"
|
||||
}
|
||||
}
|
||||
@@ -171,7 +171,7 @@
|
||||
}
|
||||
},
|
||||
"content": {
|
||||
"mod": "ovis-composer"
|
||||
"mod": "herdr-composer"
|
||||
}
|
||||
},
|
||||
{
|
||||
File renamed without changes.
@@ -18,6 +18,7 @@
|
||||
// was read and nothing fit.
|
||||
|
||||
import { GROUP_BUILTIN, GROUP_PROJECT, GROUP_USER, rank } from "./suggest.js";
|
||||
import { decode } from "./powershell.js";
|
||||
|
||||
/**
|
||||
* @typedef {import("./suggest.js").Item} Item
|
||||
@@ -277,17 +278,26 @@ async function tryRead(exec, shell, path, cwd) {
|
||||
return String(result.stdout ?? "");
|
||||
}
|
||||
|
||||
/** The PowerShell that reads one file; the path goes in as a literal. */
|
||||
function readScript(path) {
|
||||
const literal = path.replace(/'/g, "''");
|
||||
/**
|
||||
* The PowerShell that reads one file.
|
||||
*
|
||||
* The path comes from a project that may have been cloned from anywhere, and
|
||||
* PowerShell reads U+2018..U+201B as quotes too: the path is never in the
|
||||
* script as text, only as Base64 that the script decodes (`powershell.js`).
|
||||
*
|
||||
* @param {string} path
|
||||
* @returns {string}
|
||||
*/
|
||||
export function readScript(path) {
|
||||
return (
|
||||
"[Console]::OutputEncoding = [System.Text.UTF8Encoding]::new($false); " +
|
||||
// A file that is gone writes nothing and says nothing - the command
|
||||
// would be a ghost. Without the encoding, Windows PowerShell reads a file
|
||||
// without a BOM as the system's own code page, and the text comes out
|
||||
// garbled.
|
||||
`if (-not (Test-Path -LiteralPath '${literal}')) { exit 1 }; ` +
|
||||
`Get-Content -Raw -Encoding utf8 -ErrorAction Stop -LiteralPath '${literal}'`
|
||||
`$path = ${decode(path)}; ` +
|
||||
"if (-not (Test-Path -LiteralPath $path)) { exit 1 }; " +
|
||||
"Get-Content -Raw -Encoding utf8 -ErrorAction Stop -LiteralPath $path"
|
||||
);
|
||||
}
|
||||
|
||||
+2
-52
@@ -18,6 +18,8 @@
|
||||
// An empty or missing <bytes> means the size could not be read: the caller
|
||||
// does not let such a file through (fail closed).
|
||||
|
||||
import { decode } from "./powershell.js";
|
||||
|
||||
/** How long a pasted image stays in the paste folder. */
|
||||
export const PASTE_MAX_AGE_MS = 7 * 864e5;
|
||||
|
||||
@@ -254,55 +256,3 @@ function toBytes(text) {
|
||||
const value = Number(text);
|
||||
return Number.isFinite(value) && value >= 0 ? value : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* PowerShell that yields `text` - without the text itself being in the
|
||||
* script.
|
||||
*
|
||||
* A path or a name comes from the outside, and PowerShell reads more than the
|
||||
* ASCII apostrophe as a quote (U+2018, U+2019, U+201A, U+201B too), so no
|
||||
* quoting is safe enough. The text goes in as Base64 of its UTF-8 bytes - an
|
||||
* alphabet with no quote, no `$`, no space - and is decoded by PowerShell.
|
||||
*
|
||||
* @param {string} text
|
||||
* @returns {string}
|
||||
*/
|
||||
function decode(text) {
|
||||
return `[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String('${base64(utf8(text))}'))`;
|
||||
}
|
||||
|
||||
/** The UTF-8 bytes of a text (a lone surrogate becomes U+FFFD). */
|
||||
function utf8(text) {
|
||||
const bytes = [];
|
||||
for (const char of String(text)) {
|
||||
let code = char.codePointAt(0);
|
||||
if (code >= 0xd800 && code <= 0xdfff) code = 0xfffd;
|
||||
if (code < 0x80) {
|
||||
bytes.push(code);
|
||||
} else if (code < 0x800) {
|
||||
bytes.push(0xc0 | (code >> 6), 0x80 | (code & 63));
|
||||
} else if (code < 0x10000) {
|
||||
bytes.push(0xe0 | (code >> 12), 0x80 | ((code >> 6) & 63), 0x80 | (code & 63));
|
||||
} else {
|
||||
bytes.push(0xf0 | (code >> 18), 0x80 | ((code >> 12) & 63), 0x80 | ((code >> 6) & 63), 0x80 | (code & 63));
|
||||
}
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
|
||||
const BASE64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
|
||||
/** Base64 of bytes (no Buffer, no btoa: the mods do not have to have them). */
|
||||
function base64(bytes) {
|
||||
let out = "";
|
||||
for (let i = 0; i < bytes.length; i += 3) {
|
||||
const a = bytes[i];
|
||||
const b = bytes[i + 1];
|
||||
const c = bytes[i + 2];
|
||||
out += BASE64[a >> 2];
|
||||
out += BASE64[((a & 3) << 4) | ((b ?? 0) >> 4)];
|
||||
out += b === undefined ? "=" : BASE64[((b & 15) << 2) | ((c ?? 0) >> 6)];
|
||||
out += c === undefined ? "=" : BASE64[c & 63];
|
||||
}
|
||||
return out;
|
||||
}
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -16,7 +16,7 @@
|
||||
// command); a click in a terminal gives the keys to that terminal. While the
|
||||
// field has the keyboard its shortcuts (Enter, Ctrl+Enter, Alt+Enter, Esc,
|
||||
// Ctrl+R, the arrows and Tab of the menu) are bound in the context
|
||||
// `ovis-composer > Input`. The agent is stopped with the Stop button or Esc on
|
||||
// `herdr-composer > Input`. The agent is stopped with the Stop button or Esc on
|
||||
// an empty field (`hc interrupt`).
|
||||
//
|
||||
// `hc send` does not confirm a delivery - it pastes the text and presses
|
||||
@@ -120,7 +120,7 @@ const PANEL_BLOCK_PX = 360;
|
||||
/** The padding of the root, per side (px) - the block is the content plus two of them. */
|
||||
const ROOT_PADDING = 8;
|
||||
|
||||
/** The range the layout gives the composer block (`layouts/ovis-composer.json`), px. */
|
||||
/** The range the layout gives the composer block (`layouts/herdr-composer.json`), px. */
|
||||
const BLOCK_MIN_PX = 120;
|
||||
const BLOCK_MAX_PX = 520;
|
||||
|
||||
@@ -134,7 +134,7 @@ const MENU_LIMIT = 20;
|
||||
const MENU_HEIGHT = 118;
|
||||
|
||||
/** The key context of the composer - the bindings of the mod sit on it. */
|
||||
const CONTEXT = "ovis-composer";
|
||||
const CONTEXT = "herdr-composer";
|
||||
|
||||
export default class Composer extends View {
|
||||
init(_props, cx) {
|
||||
@@ -260,7 +260,7 @@ export default class Composer extends View {
|
||||
//
|
||||
// The keymap is application-wide, so a plain "Input" context would also
|
||||
// match the text fields of other mods and swallow their keys. The
|
||||
// bindings use the descendant predicate "ovis-composer > Input": only a
|
||||
// bindings use the descendant predicate "herdr-composer > Input": only a
|
||||
// field that sits inside the composer's own key context (see
|
||||
// key_context(CONTEXT) on the root) matches.
|
||||
//
|
||||
@@ -268,13 +268,13 @@ export default class Composer extends View {
|
||||
// copy of the composer whose own field has the keyboard acts - the other
|
||||
// copies (a composer in another pane) leave the key alone.
|
||||
cx.bind_keys([
|
||||
{ keystroke: "up", action: "ovis-composer.up", context: `${CONTEXT} > Input` },
|
||||
{ keystroke: "down", action: "ovis-composer.down", context: `${CONTEXT} > Input` },
|
||||
{ keystroke: "tab", action: "ovis-composer.accept", context: `${CONTEXT} > Input` },
|
||||
{ keystroke: "ctrl-r", action: "ovis-composer.panel", context: `${CONTEXT} > Input` },
|
||||
{ keystroke: "ctrl-enter", action: "ovis-composer.send_now", context: `${CONTEXT} > Input` },
|
||||
{ keystroke: "alt-enter", action: "ovis-composer.hold", context: `${CONTEXT} > Input` },
|
||||
{ keystroke: "escape", action: "ovis-composer.escape", context: `${CONTEXT} > Input` },
|
||||
{ keystroke: "up", action: "herdr-composer.up", context: `${CONTEXT} > Input` },
|
||||
{ keystroke: "down", action: "herdr-composer.down", context: `${CONTEXT} > Input` },
|
||||
{ keystroke: "tab", action: "herdr-composer.accept", context: `${CONTEXT} > Input` },
|
||||
{ keystroke: "ctrl-r", action: "herdr-composer.panel", context: `${CONTEXT} > Input` },
|
||||
{ keystroke: "ctrl-enter", action: "herdr-composer.send_now", context: `${CONTEXT} > Input` },
|
||||
{ keystroke: "alt-enter", action: "herdr-composer.hold", context: `${CONTEXT} > Input` },
|
||||
{ keystroke: "escape", action: "herdr-composer.escape", context: `${CONTEXT} > Input` },
|
||||
]);
|
||||
|
||||
// Focus follows the click: nothing here takes the keyboard on its own.
|
||||
@@ -653,7 +653,7 @@ export default class Composer extends View {
|
||||
|
||||
// While the panel is open the keys are the panel's - the keyboard is in
|
||||
// its search field, not in the composer's, and the bindings of the
|
||||
// composer (`ovis-composer > Input`) catch these keys as actions first.
|
||||
// composer (`herdr-composer > Input`) catch these keys as actions first.
|
||||
if (this.panel) {
|
||||
if (command === "up") this.panelCommand("up", cx);
|
||||
else if (command === "down") this.panelCommand("down", cx);
|
||||
@@ -2001,7 +2001,7 @@ export default class Composer extends View {
|
||||
|
||||
/** Where pasted images are saved before they go to the agent. */
|
||||
pasteDir() {
|
||||
return [appHome(), "data", "ovis-composer", "paste"].join("\\");
|
||||
return [appHome(), "data", "herdr-composer", "paste"].join("\\");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2010,9 +2010,11 @@ export default class Composer extends View {
|
||||
* and only files of that shape are ever touched.
|
||||
*/
|
||||
async cleanupPaste() {
|
||||
// The folder of the composer's earlier name is cleaned too: images pasted
|
||||
// before the rename are in `data/ovis-composer/paste`.
|
||||
for (const dir of [this.pasteDir(), [appHome(), "data", "ovis-composer", "paste"].join("\\")]) {
|
||||
try {
|
||||
const dir = this.pasteDir();
|
||||
if (!(await fs.exists(dir))) return;
|
||||
if (!(await fs.exists(dir))) continue;
|
||||
const entries = [];
|
||||
for (const name of await fs.readdir(dir)) {
|
||||
const match = /^paste-(\d+)\.png$/.exec(name);
|
||||
@@ -2029,6 +2031,7 @@ export default class Composer extends View {
|
||||
// No paste folder, nothing to clean.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** The file is not wanted any more - the mention goes with it. */
|
||||
removeFile(agent, id, cx) {
|
||||
@@ -2123,7 +2126,7 @@ export default class Composer extends View {
|
||||
const status = agent ? this.statusOf(agent) : "idle";
|
||||
|
||||
return v_flex()
|
||||
.id("ovis-composer")
|
||||
.id("herdr-composer")
|
||||
.relative()
|
||||
.on_size_change((size, cx) => this.rootSized(size, cx))
|
||||
.track_focus(this.handle)
|
||||
@@ -2132,13 +2135,13 @@ export default class Composer extends View {
|
||||
// Actions that cx.bind_keys dispatches reach the element tree, not
|
||||
// nextCommand() (that one only serves keys.json). The field sits inside
|
||||
// this root, so the actions arrive here.
|
||||
.on_action("ovis-composer.up", (e, cx) => this.runAction("up", cx))
|
||||
.on_action("ovis-composer.down", (e, cx) => this.runAction("down", cx))
|
||||
.on_action("ovis-composer.accept", (e, cx) => this.runAction("accept", cx))
|
||||
.on_action("ovis-composer.panel", (e, cx) => this.runAction("panel", cx))
|
||||
.on_action("ovis-composer.send_now", (e, cx) => this.runAction("send_now", cx))
|
||||
.on_action("ovis-composer.hold", (e, cx) => this.runAction("hold", cx))
|
||||
.on_action("ovis-composer.escape", (e, cx) => this.runAction("escape", cx))
|
||||
.on_action("herdr-composer.up", (e, cx) => this.runAction("up", cx))
|
||||
.on_action("herdr-composer.down", (e, cx) => this.runAction("down", cx))
|
||||
.on_action("herdr-composer.accept", (e, cx) => this.runAction("accept", cx))
|
||||
.on_action("herdr-composer.panel", (e, cx) => this.runAction("panel", cx))
|
||||
.on_action("herdr-composer.send_now", (e, cx) => this.runAction("send_now", cx))
|
||||
.on_action("herdr-composer.hold", (e, cx) => this.runAction("hold", cx))
|
||||
.on_action("herdr-composer.escape", (e, cx) => this.runAction("escape", cx))
|
||||
.size_full()
|
||||
.p(ROOT_PADDING)
|
||||
.gap(6)
|
||||
File renamed without changes.
@@ -16,11 +16,17 @@ import { div, image } from "gpui-kit";
|
||||
import { v_flex, h_flex, Input, Scrollbar, v_virtual_list } from "gpui-base";
|
||||
import { segments, entryMeta } from "./history.js";
|
||||
|
||||
/** The height of one row - the list is virtual, so every row has the same. */
|
||||
export const ROW_HEIGHT = 56;
|
||||
/**
|
||||
* The height of one row - the list is virtual, so every row has the same.
|
||||
*
|
||||
* 7 px of padding above and below, the two lines of text (TEXT_HEIGHT), 2 px
|
||||
* and the line of meta (about 18 px): a row that is lower lets the second
|
||||
* line of the text run into the meta.
|
||||
*/
|
||||
export const ROW_HEIGHT = 76;
|
||||
|
||||
/** The text lines of a row (the rest is cut). */
|
||||
const TEXT_HEIGHT = 34;
|
||||
/** Two lines of the text of a row, at about 20 px a line (the rest is cut). */
|
||||
const TEXT_HEIGHT = 40;
|
||||
|
||||
/**
|
||||
* The panel.
|
||||
@@ -51,7 +57,7 @@ export function renderPanel(t, view, on) {
|
||||
|
||||
return v_flex()
|
||||
.id("composer-panel")
|
||||
.key_context("ovis-composer-panel")
|
||||
.key_context("herdr-composer-panel")
|
||||
.on_key_down((event, cx) => on.key(event, cx))
|
||||
.size_full()
|
||||
.rounded(12)
|
||||
@@ -311,7 +317,7 @@ export function renderPreview(t, preview, handle, on) {
|
||||
return v_flex()
|
||||
.id("composer-preview")
|
||||
.track_focus(handle)
|
||||
.key_context("ovis-composer-preview")
|
||||
.key_context("herdr-composer-preview")
|
||||
.on_key_down((event, cx) => {
|
||||
if (String(event.key).toLowerCase() === "escape") {
|
||||
on.close(cx);
|
||||
@@ -0,0 +1,59 @@
|
||||
// powershell.js - how text from the outside gets into a PowerShell script.
|
||||
//
|
||||
// Pure: no gpui-kit, no gpui-base, no herdr. Every script the mod hands to
|
||||
// `exec("powershell", ["-Command", script])` (clipboard.js, catalog.js) builds
|
||||
// what it needs from a path or a name that is NOT the mod's own - a file the
|
||||
// person dropped, a file in a cloned project - through `decode`, and never by
|
||||
// putting that text between quotes.
|
||||
|
||||
/**
|
||||
* PowerShell that yields `text` - without the text itself being in the
|
||||
* script.
|
||||
*
|
||||
* A path or a name comes from the outside, and PowerShell reads more than the
|
||||
* ASCII apostrophe as a quote (U+2018, U+2019, U+201A, U+201B too), so no
|
||||
* quoting is safe enough. The text goes in as Base64 of its UTF-8 bytes - an
|
||||
* alphabet with no quote, no `$`, no space - and is decoded by PowerShell.
|
||||
*
|
||||
* @param {string} text
|
||||
* @returns {string} a PowerShell expression
|
||||
*/
|
||||
export function decode(text) {
|
||||
return `[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String('${base64(utf8(text))}'))`;
|
||||
}
|
||||
|
||||
/** The UTF-8 bytes of a text (a lone surrogate becomes U+FFFD). */
|
||||
function utf8(text) {
|
||||
const bytes = [];
|
||||
for (const char of String(text)) {
|
||||
let code = char.codePointAt(0);
|
||||
if (code >= 0xd800 && code <= 0xdfff) code = 0xfffd;
|
||||
if (code < 0x80) {
|
||||
bytes.push(code);
|
||||
} else if (code < 0x800) {
|
||||
bytes.push(0xc0 | (code >> 6), 0x80 | (code & 63));
|
||||
} else if (code < 0x10000) {
|
||||
bytes.push(0xe0 | (code >> 12), 0x80 | ((code >> 6) & 63), 0x80 | (code & 63));
|
||||
} else {
|
||||
bytes.push(0xf0 | (code >> 18), 0x80 | ((code >> 12) & 63), 0x80 | ((code >> 6) & 63), 0x80 | (code & 63));
|
||||
}
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
|
||||
const BASE64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
|
||||
/** Base64 of bytes (no Buffer, no btoa: the mods do not have to have them). */
|
||||
function base64(bytes) {
|
||||
let out = "";
|
||||
for (let i = 0; i < bytes.length; i += 3) {
|
||||
const a = bytes[i];
|
||||
const b = bytes[i + 1];
|
||||
const c = bytes[i + 2];
|
||||
out += BASE64[a >> 2];
|
||||
out += BASE64[((a & 3) << 4) | ((b ?? 0) >> 4)];
|
||||
out += b === undefined ? "=" : BASE64[((b & 15) << 2) | ((c ?? 0) >> 6)];
|
||||
out += c === undefined ? "=" : BASE64[c & 63];
|
||||
}
|
||||
return out;
|
||||
}
|
||||
File renamed without changes.
+74
-13
@@ -59,17 +59,26 @@
|
||||
/** The states a queue entry may be in (the ones state.js knows). */
|
||||
const QUEUE_STATES = new Set(["queued", "countdown", "sending", "held", "uncertain"]);
|
||||
|
||||
/**
|
||||
* The composer used to be called `ovis-composer`, and what it kept lives under
|
||||
* keys with that prefix. Every `load*` reads the new key first; when there is
|
||||
* none it reads the old one and - if there is something worth keeping - writes
|
||||
* it under the new key. The old keys are never touched.
|
||||
*/
|
||||
const PREFIX = "herdr-composer.";
|
||||
export const LEGACY_PREFIX = "ovis-composer.";
|
||||
|
||||
/** The keys the composer writes into the shared store. */
|
||||
export const KEYS = {
|
||||
history: "ovis-composer.history",
|
||||
favorites: "ovis-composer.favorites",
|
||||
usage: "ovis-composer.usage",
|
||||
history: "herdr-composer.history",
|
||||
favorites: "herdr-composer.favorites",
|
||||
usage: "herdr-composer.usage",
|
||||
/** The height (layout px) the person dragged the composer to; 0 or none: not set. */
|
||||
userMin: "ovis-composer.userMin",
|
||||
/** The queue is per agent: `ovis-composer.queue:<agent>`. */
|
||||
queue: "ovis-composer.queue",
|
||||
/** The draft is per agent: `ovis-composer.draft:<agent>`. */
|
||||
draft: "ovis-composer.draft",
|
||||
userMin: "herdr-composer.userMin",
|
||||
/** The queue is per agent: `herdr-composer.queue:<agent>`. */
|
||||
queue: "herdr-composer.queue",
|
||||
/** The draft is per agent: `herdr-composer.draft:<agent>`. */
|
||||
draft: "herdr-composer.draft",
|
||||
};
|
||||
|
||||
/** How many entries the history keeps. */
|
||||
@@ -193,7 +202,7 @@ export function draftKey(agent) {
|
||||
*/
|
||||
export function loadDraft(store, agent) {
|
||||
if (typeof agent !== "string" || agent === "") return null;
|
||||
return toDraft(read(store, draftKey(agent)));
|
||||
return loadMigrating(store, draftKey(agent), toDraft, (draft) => draft !== null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -257,8 +266,12 @@ function toDraft(value) {
|
||||
* @returns {number}
|
||||
*/
|
||||
export function loadUserMin(store) {
|
||||
const value = read(store, KEYS.userMin);
|
||||
return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : 0;
|
||||
return loadMigrating(
|
||||
store,
|
||||
KEYS.userMin,
|
||||
(value) => (typeof value === "number" && Number.isFinite(value) && value > 0 ? value : 0),
|
||||
(px) => px > 0,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -283,7 +296,10 @@ export function saveUserMin(store, px) {
|
||||
* @returns {Record<string, number>}
|
||||
*/
|
||||
export function loadUsage(store) {
|
||||
const raw = read(store, KEYS.usage);
|
||||
return loadMigrating(
|
||||
store,
|
||||
KEYS.usage,
|
||||
(raw) => {
|
||||
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return {};
|
||||
|
||||
const counts = {};
|
||||
@@ -291,6 +307,9 @@ export function loadUsage(store) {
|
||||
if (typeof value === "number" && Number.isFinite(value) && value >= 0) counts[key] = value;
|
||||
}
|
||||
return counts;
|
||||
},
|
||||
(counts) => Object.keys(counts).length > 0,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -326,10 +345,52 @@ export function saveUsage(store, counts) {
|
||||
* @returns {any[]}
|
||||
*/
|
||||
function readList(store, key, limit, isValid, shape) {
|
||||
const found = toList(read(store, key), isValid);
|
||||
return loadMigrating(
|
||||
store,
|
||||
key,
|
||||
(raw) => {
|
||||
const found = toList(raw, isValid);
|
||||
if (!found) return [];
|
||||
const list = shape ? found.map(shape) : found;
|
||||
return limit > 0 ? list.slice(-limit) : list;
|
||||
},
|
||||
(list) => list.length > 0,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a value under its key; when the key was never written, under the key
|
||||
* the composer had before it was renamed (`ovis-composer.*`).
|
||||
*
|
||||
* What is found under the old key is parsed like anything else (rubbish gives
|
||||
* the default), and only when the result is worth keeping the old value is
|
||||
* written under the new key. A store that cannot be written to does not break
|
||||
* the read. The old key stays as it was.
|
||||
*
|
||||
* @template T
|
||||
* @param {Store} store
|
||||
* @param {string} key - the new key (`herdr-composer.*`)
|
||||
* @param {(raw:unknown) => T} parse - the value as the composer uses it; `null` gives the default
|
||||
* @param {(parsed:T) => boolean} worthKeeping
|
||||
* @returns {T}
|
||||
*/
|
||||
function loadMigrating(store, key, parse, worthKeeping) {
|
||||
const current = read(store, key);
|
||||
if (current !== null && current !== undefined) return parse(current);
|
||||
if (!key.startsWith(PREFIX)) return parse(null);
|
||||
|
||||
const old = read(store, LEGACY_PREFIX + key.slice(PREFIX.length));
|
||||
if (old === null || old === undefined) return parse(null);
|
||||
|
||||
const parsed = parse(old);
|
||||
if (worthKeeping(parsed)) {
|
||||
try {
|
||||
write(store, key, old);
|
||||
} catch {
|
||||
// The data is read; it is written under the new key next time.
|
||||
}
|
||||
}
|
||||
return parsed;
|
||||
}
|
||||
|
||||
/**
|
||||
File renamed without changes.
File renamed without changes.
Binary file not shown.
|
After Width: | Height: | Size: 810 KiB |
@@ -0,0 +1,5 @@
|
||||
@echo off
|
||||
rem Installs (or updates) the herdr-composer package. Run it again to update;
|
||||
rem "install.cmd -Uninstall" removes it. See README.md.
|
||||
powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0scripts\install.ps1" %*
|
||||
exit /b %ERRORLEVEL%
|
||||
+324
-106
@@ -1,32 +1,63 @@
|
||||
# install.ps1 - link the repo's ovis-composer mod into the Herdr config.
|
||||
# install.ps1 - install the herdr-composer package into the Herdr config.
|
||||
#
|
||||
# .\scripts\install.ps1 install (idempotent)
|
||||
# .\scripts\install.ps1 -Uninstall remove the junction, restore backups
|
||||
# .\scripts\install.ps1 -Reload recreate the junction so Herdr loads the mod again
|
||||
# install.cmd install or update (the same command both times)
|
||||
# install.cmd -Uninstall remove it again
|
||||
#
|
||||
# Herdr does NOT see changes behind the junction on its own: after editing
|
||||
# mod\ovis-composer run -Reload (the junction is removed and made again, and
|
||||
# Herdr reloads the mod).
|
||||
# What install does (Windows PowerShell 5):
|
||||
# 1. git pull --ff-only when this folder is a git clone without local changes
|
||||
# (a failure is a warning - the install goes on with what is here);
|
||||
# 2. COPIES herdr\herdr-composer\mods\herdr-composer to
|
||||
# ~\.config\herdr-app\mods\herdr-composer (a mirror, so Herdr sees the new
|
||||
# files and reloads the mod by itself) and the layout to
|
||||
# ~\.config\herdr-app\layouts\herdr-composer.json (an existing layout that
|
||||
# differs is saved first; an identical one is left alone);
|
||||
# 3. merges the keys of the package (keys.json) into the person's keys.json
|
||||
# (the file is rewritten - the formatting changes, the meaning does not -
|
||||
# and a copy is saved first; a key the person already binds to something
|
||||
# else is left alone, with a warning);
|
||||
# 4. clears away the earlier version (ovis-composer): a junction is only
|
||||
# unlinked, a directory or a layout file is moved out, its key is taken
|
||||
# out of keys.json - files of this repo are never deleted;
|
||||
# 5. herdr-app check on the mod; the layout is switched to herdr-composer on
|
||||
# the first install, or when the earlier ovis-composer was the shown one -
|
||||
# otherwise the person is told how to switch (ctrl-shift-l). No herdr-app
|
||||
# on the PATH is a warning, not an error.
|
||||
#
|
||||
# Works on Windows PowerShell 5.
|
||||
# EVERY copy this script makes goes to
|
||||
# ~\.config\herdr-app\backups\herdr-composer\<yyyyMMdd-HHmmss>\
|
||||
# and never next to the originals: Herdr loads whatever it finds in mods\ and
|
||||
# layouts\, so a backup left there would be loaded as a mod or a layout.
|
||||
#
|
||||
# The person's data (history, favourites, drafts, the queue) is not touched:
|
||||
# the mod reads what the earlier version kept (storage.js).
|
||||
|
||||
[CmdletBinding()]
|
||||
param([switch]$Uninstall, [switch]$Reload)
|
||||
param([switch]$Uninstall)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
$Stamp = '20261119'
|
||||
$Name = 'herdr-composer'
|
||||
$OldName = 'ovis-composer'
|
||||
|
||||
$Repo = Split-Path -Parent $PSScriptRoot
|
||||
$HerdrDir = Join-Path $env:USERPROFILE '.config\herdr-app'
|
||||
$Package = Join-Path $Repo 'herdr\herdr-composer'
|
||||
$ModSrc = Join-Path $Package "mods\$Name"
|
||||
$LayoutSrc = Join-Path $Package "layouts\$Name.json"
|
||||
$KeysSrc = Join-Path $Package 'keys.json'
|
||||
|
||||
$HerdrDir = if ($env:HERDR_APP_HOME) { $env:HERDR_APP_HOME } else { Join-Path $env:USERPROFILE '.config\herdr-app' }
|
||||
$ModsDir = Join-Path $HerdrDir 'mods'
|
||||
$Junction = Join-Path $ModsDir 'ovis-composer'
|
||||
$ModBackup = "$Junction.bak-$Stamp"
|
||||
$ModSource = Join-Path $Repo 'mod\ovis-composer'
|
||||
$LayoutSrc = Join-Path $Repo 'layouts\ovis-composer.json'
|
||||
$LayoutDst = Join-Path $HerdrDir 'layouts\ovis-composer.json'
|
||||
$LayoutBak = "$LayoutDst.bak-$Stamp"
|
||||
$LayoutsDir = Join-Path $HerdrDir 'layouts'
|
||||
$ModDst = Join-Path $ModsDir $Name
|
||||
$LayoutDst = Join-Path $LayoutsDir "$Name.json"
|
||||
$KeysFile = Join-Path $HerdrDir 'keys.json'
|
||||
$KeysBak = "$KeysFile.bak-$Stamp"
|
||||
|
||||
# One folder per run; made when the first copy is saved.
|
||||
$BackupDir = Join-Path $HerdrDir "backups\$Name\$(Get-Date -Format 'yyyyMMdd-HHmmss')"
|
||||
$script:KeysSaved = $false
|
||||
|
||||
$OurAction = "$Name.focus"
|
||||
$OldAction = "$OldName.focus"
|
||||
|
||||
function Test-Junction([string]$Path) {
|
||||
if (-not (Test-Path -LiteralPath $Path)) { return $false }
|
||||
@@ -34,121 +65,308 @@ function Test-Junction([string]$Path) {
|
||||
return [bool]($item.Attributes -band [IO.FileAttributes]::ReparsePoint)
|
||||
}
|
||||
|
||||
function Remove-Junction([string]$Path) {
|
||||
# rmdir on a junction removes only the link, never the target's contents.
|
||||
function Remove-Junction([string]$Path) {
|
||||
cmd /c rmdir "`"$Path`"" | Out-Null
|
||||
if ($LASTEXITCODE -ne 0) { throw "rmdir failed for $Path" }
|
||||
}
|
||||
|
||||
# Merge "ctrl-shift-space": "ovis-composer.focus" into keys.json "global",
|
||||
# leaving every other entry alone. Backs the file up once; idempotent.
|
||||
function Install-KeyEntry {
|
||||
$chord = 'ctrl-shift-space'
|
||||
$action = 'ovis-composer.focus'
|
||||
if (-not (Test-Path -LiteralPath $KeysFile)) {
|
||||
$obj = [pscustomobject]@{ global = [pscustomobject]@{ $chord = $action } }
|
||||
} else {
|
||||
$raw = [IO.File]::ReadAllText($KeysFile)
|
||||
$obj = $raw | ConvertFrom-Json
|
||||
if ($obj -isnot [pscustomobject]) { throw "keys.json is not a JSON object - resolve by hand." }
|
||||
if (-not $obj.PSObject.Properties['global']) {
|
||||
$obj | Add-Member -NotePropertyName 'global' -NotePropertyValue ([pscustomobject]@{})
|
||||
# The path in the backup folder for an item with this name (never an existing one).
|
||||
function Get-BackupPath([string]$ItemName) {
|
||||
New-Item -ItemType Directory -Force -Path $BackupDir | Out-Null
|
||||
$candidate = Join-Path $BackupDir $ItemName
|
||||
$n = 1
|
||||
while (Test-Path -LiteralPath $candidate) {
|
||||
$candidate = Join-Path $BackupDir "$ItemName-$n"
|
||||
$n++
|
||||
}
|
||||
$global = $obj.global
|
||||
if ($global.PSObject.Properties[$chord] -and $global.$chord -eq $action) {
|
||||
Write-Host "keys.json already has $chord"
|
||||
return $candidate
|
||||
}
|
||||
|
||||
# Moves a file or directory out of mods\ / layouts\ into the backup folder.
|
||||
function Move-ToBackup([string]$Path) {
|
||||
$target = Get-BackupPath (Split-Path -Leaf $Path)
|
||||
Move-Item -LiteralPath $Path -Destination $target
|
||||
return $target
|
||||
}
|
||||
|
||||
# Nothing this script deletes or overwrites may be inside the repo.
|
||||
function Assert-OutsideRepo([string]$Path) {
|
||||
$full = [IO.Path]::GetFullPath($Path).TrimEnd([char]92)
|
||||
$repo = [IO.Path]::GetFullPath($Repo).TrimEnd([char]92)
|
||||
if ($full -ieq $repo -or $full.StartsWith($repo + '\', [StringComparison]::OrdinalIgnoreCase)) {
|
||||
throw "$Path is inside the repo - refusing to touch it."
|
||||
}
|
||||
}
|
||||
|
||||
function Test-HerdrApp { return [bool](Get-Command 'herdr-app' -ErrorAction SilentlyContinue) }
|
||||
|
||||
# Runs herdr-app and waits for it.
|
||||
#
|
||||
# herdr-app.exe is a program of the GUI subsystem: PowerShell does not wait for
|
||||
# it and does not set $LASTEXITCODE (whatever the last console program left
|
||||
# there stays - 1 after robocopy means "copied"). So it is started with
|
||||
# Start-Process, waited for, and its exit code and output are read from the
|
||||
# process and from two temporary files.
|
||||
#
|
||||
# Returns ExitCode, Output (stdout) and Error (stderr).
|
||||
function Invoke-HerdrApp([string[]]$Arguments) {
|
||||
$exe = (Get-Command 'herdr-app' -ErrorAction Stop).Source
|
||||
$outFile = [IO.Path]::GetTempFileName()
|
||||
$errFile = [IO.Path]::GetTempFileName()
|
||||
try {
|
||||
$quoted = @($Arguments | ForEach-Object {
|
||||
if ($_ -match '[\s"]') { '"' + ($_ -replace '"', '\"') + '"' } else { $_ }
|
||||
})
|
||||
$process = Start-Process -FilePath $exe -ArgumentList $quoted -NoNewWindow -PassThru `
|
||||
-RedirectStandardOutput $outFile -RedirectStandardError $errFile
|
||||
# Holding the handle keeps ExitCode readable after the process ended.
|
||||
$null = $process.Handle
|
||||
$process.WaitForExit()
|
||||
return [pscustomobject]@{
|
||||
ExitCode = $process.ExitCode
|
||||
Output = [IO.File]::ReadAllText($outFile)
|
||||
Error = [IO.File]::ReadAllText($errFile)
|
||||
}
|
||||
} finally {
|
||||
Remove-Item -LiteralPath $outFile, $errFile -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
}
|
||||
|
||||
# Prints what herdr-app said (stdout, then stderr).
|
||||
function Write-HerdrOutput($Result) {
|
||||
foreach ($text in @($Result.Output, $Result.Error)) {
|
||||
if ($text -and $text.Trim() -ne '') { Write-Host ($text.TrimEnd()) }
|
||||
}
|
||||
}
|
||||
|
||||
# The name of the layout the window shows now, or nothing when it cannot be told.
|
||||
function Get-ActiveLayout {
|
||||
if (-not (Test-HerdrApp)) { return $null }
|
||||
try {
|
||||
$result = Invoke-HerdrApp @('status')
|
||||
if ($result.ExitCode -ne 0) { return $null }
|
||||
return [string]($result.Output | ConvertFrom-Json).layout
|
||||
} catch {
|
||||
return $null
|
||||
}
|
||||
}
|
||||
|
||||
function Switch-Layout([string]$LayoutName) {
|
||||
if (-not (Test-HerdrApp)) {
|
||||
Write-Warning "herdr-app is not on the PATH - switch the layout to '$LayoutName' by hand (ctrl-shift-l)."
|
||||
return
|
||||
}
|
||||
if (-not (Test-Path -LiteralPath $KeysBak)) {
|
||||
Copy-Item -LiteralPath $KeysFile -Destination $KeysBak
|
||||
Write-Host "Backed up keys.json to $KeysBak"
|
||||
# `--name <x>`, not a JSON argument: quotes inside an argument do not survive.
|
||||
$result = Invoke-HerdrApp @('do', 'layout.switch', '--name', $LayoutName)
|
||||
Write-HerdrOutput $result
|
||||
if ($result.ExitCode -ne 0) {
|
||||
Write-Warning "layout.switch to '$LayoutName' failed (exit $($result.ExitCode)) - switch it by hand (ctrl-shift-l)."
|
||||
}
|
||||
$global | Add-Member -NotePropertyName $chord -NotePropertyValue $action -Force
|
||||
}
|
||||
$json = $obj | ConvertTo-Json -Depth 32
|
||||
[IO.File]::WriteAllText($KeysFile, $json, (New-Object Text.UTF8Encoding($false)))
|
||||
Write-Host "keys.json: $chord -> $action"
|
||||
}
|
||||
|
||||
if ($Reload) {
|
||||
if (-not (Test-Junction $Junction)) { throw "$Junction is not a junction - run install.ps1 first." }
|
||||
Remove-Junction $Junction
|
||||
if (-not (Test-Path -LiteralPath (Join-Path $ModSource 'main.js'))) {
|
||||
throw 'Repo files vanished after removing the junction - aborting.'
|
||||
# --- keys.json ----------------------------------------------------------------
|
||||
|
||||
function Read-Json([string]$Path) {
|
||||
$raw = [IO.File]::ReadAllText($Path)
|
||||
if ($raw.Trim() -eq '') { return [pscustomobject]@{} }
|
||||
$obj = $raw | ConvertFrom-Json
|
||||
if ($obj -isnot [pscustomobject]) { throw "$Path is not a JSON object - resolve by hand." }
|
||||
return $obj
|
||||
}
|
||||
cmd /c mklink /J "`"$Junction`"" "`"$ModSource`"" | Out-Null
|
||||
if ($LASTEXITCODE -ne 0) { throw 'mklink /J failed' }
|
||||
Write-Host "Junction recreated: $Junction -> $ModSource (Herdr loads the mod again)"
|
||||
exit 0
|
||||
|
||||
function Write-Json($Object, [string]$Path) {
|
||||
$json = $Object | ConvertTo-Json -Depth 32
|
||||
[IO.File]::WriteAllText($Path, $json, (New-Object Text.UTF8Encoding($false)))
|
||||
}
|
||||
|
||||
# A copy of keys.json, once per run, before it is rewritten.
|
||||
function Save-KeysCopy {
|
||||
if ($script:KeysSaved -or -not (Test-Path -LiteralPath $KeysFile)) { return }
|
||||
$target = Get-BackupPath 'keys.json'
|
||||
Copy-Item -LiteralPath $KeysFile -Destination $target
|
||||
$script:KeysSaved = $true
|
||||
Write-Host "Saved a copy of keys.json: $target"
|
||||
}
|
||||
|
||||
# Takes out every key (in every section) that is bound to one of $Actions.
|
||||
# Returns how many it removed.
|
||||
function Remove-KeyActions($Keys, [string[]]$Actions) {
|
||||
$removed = 0
|
||||
foreach ($section in @($Keys.PSObject.Properties)) {
|
||||
if ($section.Value -isnot [pscustomobject]) { continue }
|
||||
foreach ($key in @($section.Value.PSObject.Properties)) {
|
||||
if ($Actions -contains [string]$key.Value) {
|
||||
$section.Value.PSObject.Properties.Remove($key.Name)
|
||||
$removed++
|
||||
}
|
||||
}
|
||||
}
|
||||
return $removed
|
||||
}
|
||||
|
||||
# Merges the keys of the package into the person's: adds what is missing, keeps
|
||||
# what is there, warns about a key the person binds to something else.
|
||||
function Update-Keys {
|
||||
if (-not (Test-Path -LiteralPath $KeysSrc)) { return }
|
||||
$package = Read-Json $KeysSrc
|
||||
|
||||
if (-not (Test-Path -LiteralPath $KeysFile)) {
|
||||
Write-Json $package $KeysFile
|
||||
Write-Host "keys.json created from the package"
|
||||
return
|
||||
}
|
||||
|
||||
$mine = Read-Json $KeysFile
|
||||
$changed = $false
|
||||
|
||||
# The key of the earlier version points at an action that no longer exists.
|
||||
if ((Remove-KeyActions $mine @($OldAction)) -gt 0) {
|
||||
Save-KeysCopy
|
||||
$changed = $true
|
||||
Write-Host "keys.json: removed the key of $OldName"
|
||||
}
|
||||
|
||||
foreach ($section in $package.PSObject.Properties) {
|
||||
if (-not $mine.PSObject.Properties[$section.Name]) {
|
||||
Save-KeysCopy
|
||||
$mine | Add-Member -NotePropertyName $section.Name -NotePropertyValue ([pscustomobject]@{})
|
||||
$changed = $true
|
||||
}
|
||||
$target = $mine.($section.Name)
|
||||
foreach ($key in $section.Value.PSObject.Properties) {
|
||||
$existing = $target.PSObject.Properties[$key.Name]
|
||||
if ($existing) {
|
||||
if ([string]$existing.Value -ne [string]$key.Value) {
|
||||
Write-Warning "keys.json: '$($key.Name)' is already bound to '$($existing.Value)' - left as it is (the package wants '$($key.Value)')."
|
||||
}
|
||||
continue
|
||||
}
|
||||
Save-KeysCopy
|
||||
$target | Add-Member -NotePropertyName $key.Name -NotePropertyValue $key.Value
|
||||
$changed = $true
|
||||
Write-Host "keys.json: $($key.Name) -> $($key.Value)"
|
||||
}
|
||||
}
|
||||
|
||||
if ($changed) { Write-Json $mine $KeysFile } else { Write-Host "keys.json already has the keys" }
|
||||
}
|
||||
|
||||
function Remove-OurKeys {
|
||||
if (-not (Test-Path -LiteralPath $KeysFile)) { return }
|
||||
$mine = Read-Json $KeysFile
|
||||
if ((Remove-KeyActions $mine @($OurAction, $OldAction)) -gt 0) {
|
||||
Save-KeysCopy
|
||||
Write-Json $mine $KeysFile
|
||||
Write-Host "keys.json: removed the keys of $Name"
|
||||
}
|
||||
}
|
||||
|
||||
# --- uninstall ----------------------------------------------------------------
|
||||
|
||||
if ($Uninstall) {
|
||||
if (Test-Junction $Junction) {
|
||||
Remove-Junction $Junction
|
||||
if (-not (Test-Path -LiteralPath (Join-Path $ModSource 'main.js'))) {
|
||||
throw 'Repo files vanished after removing the junction - aborting.'
|
||||
Assert-OutsideRepo $ModDst
|
||||
if (Test-Junction $ModDst) {
|
||||
Remove-Junction $ModDst
|
||||
Write-Host "Removed junction $ModDst"
|
||||
} elseif (Test-Path -LiteralPath $ModDst) {
|
||||
Remove-Item -LiteralPath $ModDst -Recurse -Force
|
||||
Write-Host "Removed $ModDst"
|
||||
}
|
||||
Write-Host "Removed junction $Junction"
|
||||
if (Test-Path -LiteralPath $LayoutDst) {
|
||||
Remove-Item -LiteralPath $LayoutDst -Force
|
||||
Write-Host "Removed $LayoutDst"
|
||||
}
|
||||
if ((Test-Path -LiteralPath $ModBackup) -and -not (Test-Path -LiteralPath $Junction)) {
|
||||
Move-Item -LiteralPath $ModBackup -Destination $Junction
|
||||
Write-Host "Restored $Junction"
|
||||
}
|
||||
if (Test-Path -LiteralPath $LayoutBak) {
|
||||
Copy-Item -LiteralPath $LayoutBak -Destination $LayoutDst -Force
|
||||
Write-Host "Restored layout"
|
||||
}
|
||||
if (Test-Path -LiteralPath $KeysBak) {
|
||||
Copy-Item -LiteralPath $KeysBak -Destination $KeysFile -Force
|
||||
Write-Host "Restored keys.json"
|
||||
}
|
||||
herdr-app do layout.switch '{"name":"main"}'
|
||||
if ($LASTEXITCODE -ne 0) { Write-Warning "layout.switch to main failed (exit $LASTEXITCODE) - switch the layout by hand." }
|
||||
Remove-OurKeys
|
||||
Switch-Layout 'main'
|
||||
exit 0
|
||||
}
|
||||
|
||||
# 1. Mod directory -> junction to the repo.
|
||||
$relink = $false
|
||||
if (Test-Junction $Junction) {
|
||||
$target = (Get-Item -LiteralPath $Junction -Force).Target
|
||||
if ($target -is [array]) { $target = $target[0] }
|
||||
if ($target -and ([IO.Path]::GetFullPath($target).TrimEnd([char]92) -ieq [IO.Path]::GetFullPath($ModSource).TrimEnd([char]92))) {
|
||||
Write-Host "Junction already in place: $Junction"
|
||||
# --- install ------------------------------------------------------------------
|
||||
|
||||
if (-not (Test-Path -LiteralPath (Join-Path $ModSrc 'main.js'))) { throw "Package not found: $ModSrc" }
|
||||
if (-not (Test-Path -LiteralPath $HerdrDir)) { throw "Herdr config not found: $HerdrDir (is Herdr installed and started once?)" }
|
||||
Assert-OutsideRepo $ModDst
|
||||
Assert-OutsideRepo $LayoutDst
|
||||
|
||||
# What decides whether the layout is switched at the end - read before anything changes.
|
||||
$firstInstall = -not (Test-Path -LiteralPath $LayoutDst)
|
||||
$activeLayout = Get-ActiveLayout
|
||||
|
||||
# 1. Update the repo when it is a clean clone.
|
||||
if ((Test-Path -LiteralPath (Join-Path $Repo '.git')) -and (Get-Command git -ErrorAction SilentlyContinue)) {
|
||||
try {
|
||||
$dirty = & git -C $Repo status --porcelain
|
||||
if ($dirty) {
|
||||
Write-Warning 'Local changes in the repo - not updating it (git pull skipped).'
|
||||
} else {
|
||||
Write-Host "Junction points at '$target' - recreating it for $ModSource"
|
||||
Remove-Junction $Junction
|
||||
$relink = $true
|
||||
& git -C $Repo pull --ff-only
|
||||
if ($LASTEXITCODE -ne 0) { Write-Warning "git pull --ff-only failed (exit $LASTEXITCODE) - installing what is here." }
|
||||
}
|
||||
} else { $relink = $true }
|
||||
if ($relink) {
|
||||
if (Test-Path -LiteralPath $Junction) {
|
||||
if (Test-Path -LiteralPath $ModBackup) { throw "$ModBackup already exists - resolve by hand." }
|
||||
Move-Item -LiteralPath $Junction -Destination $ModBackup
|
||||
Write-Host "Backed up to $ModBackup"
|
||||
} catch {
|
||||
Write-Warning "git pull failed: $($_.Exception.Message) - installing what is here."
|
||||
}
|
||||
cmd /c mklink /J "`"$Junction`"" "`"$ModSource`"" | Out-Null
|
||||
if ($LASTEXITCODE -ne 0) { throw 'mklink /J failed' }
|
||||
Write-Host "Junction: $Junction -> $ModSource"
|
||||
}
|
||||
|
||||
# gpui-kit.d.ts is git-ignored; keep a copy next to the sources for the editor.
|
||||
$kitDst = Join-Path $ModSource 'gpui-kit.d.ts'
|
||||
$kitSrc = if (Test-Path -LiteralPath (Join-Path $ModBackup 'gpui-kit.d.ts')) { Join-Path $ModBackup 'gpui-kit.d.ts' } else { Join-Path $HerdrDir 'gpui-kit.d.ts' }
|
||||
if (-not (Test-Path -LiteralPath $kitDst) -and (Test-Path -LiteralPath $kitSrc)) {
|
||||
Copy-Item -LiteralPath $kitSrc -Destination $kitDst
|
||||
# 2. The earlier version (ovis-composer) goes out of the way.
|
||||
$OldMod = Join-Path $ModsDir $OldName
|
||||
if (Test-Junction $OldMod) {
|
||||
Remove-Junction $OldMod
|
||||
Write-Host "Removed the junction of the earlier version: $OldMod"
|
||||
} elseif (Test-Path -LiteralPath $OldMod) {
|
||||
$saved = Move-ToBackup $OldMod
|
||||
Write-Host "Moved the earlier version to $saved"
|
||||
}
|
||||
$OldLayout = Join-Path $LayoutsDir "$OldName.json"
|
||||
if (Test-Path -LiteralPath $OldLayout) {
|
||||
$saved = Move-ToBackup $OldLayout
|
||||
Write-Host "Moved the earlier layout to $saved"
|
||||
}
|
||||
|
||||
# 2. Layout (back up the existing file once).
|
||||
if ((Test-Path -LiteralPath $LayoutDst) -and -not (Test-Path -LiteralPath $LayoutBak)) {
|
||||
Copy-Item -LiteralPath $LayoutDst -Destination $LayoutBak
|
||||
Write-Host "Backed up layout to $LayoutBak"
|
||||
}
|
||||
# 3. The mod: a mirror copy. gpui-kit.d.ts and jsconfig.json are the editor's,
|
||||
# written by Herdr next to the mod - they are not part of the copy and are not
|
||||
# purged from the destination.
|
||||
New-Item -ItemType Directory -Force -Path $ModsDir | Out-Null
|
||||
if (Test-Junction $ModDst) { Remove-Junction $ModDst }
|
||||
robocopy $ModSrc $ModDst /MIR /XF gpui-kit.d.ts jsconfig.json /NFL /NDL /NJH /NJS /NP | Out-Null
|
||||
$robocopyExit = $LASTEXITCODE
|
||||
# 0-7 are all "fine" for robocopy (1 = files were copied); nothing below may
|
||||
# read this code as if it were the result of its own command.
|
||||
$global:LASTEXITCODE = 0
|
||||
if ($robocopyExit -ge 8) { throw "robocopy failed (exit $robocopyExit)" }
|
||||
Write-Host "Mod copied: $ModDst"
|
||||
|
||||
# 4. The layout: an existing one that differs is saved first, an identical one stays.
|
||||
New-Item -ItemType Directory -Force -Path $LayoutsDir | Out-Null
|
||||
if (Test-Path -LiteralPath $LayoutDst) {
|
||||
$same = (Get-FileHash -LiteralPath $LayoutSrc -Algorithm SHA256).Hash -eq (Get-FileHash -LiteralPath $LayoutDst -Algorithm SHA256).Hash
|
||||
if ($same) {
|
||||
Write-Host "Layout is up to date: $LayoutDst"
|
||||
} else {
|
||||
$saved = Move-ToBackup $LayoutDst
|
||||
Write-Host "Saved the layout that was there: $saved"
|
||||
Copy-Item -LiteralPath $LayoutSrc -Destination $LayoutDst -Force
|
||||
Write-Host "Layout copied"
|
||||
Write-Host "Layout copied: $LayoutDst"
|
||||
}
|
||||
} else {
|
||||
Copy-Item -LiteralPath $LayoutSrc -Destination $LayoutDst -Force
|
||||
Write-Host "Layout copied: $LayoutDst"
|
||||
}
|
||||
|
||||
# 3. Key binding (Task 2).
|
||||
Install-KeyEntry
|
||||
# 5. Keys.
|
||||
Update-Keys
|
||||
|
||||
# 4. Show the layout.
|
||||
herdr-app do layout.switch '{"name":"ovis-composer"}'
|
||||
if ($LASTEXITCODE -ne 0) { Write-Warning "layout.switch to ovis-composer failed (exit $LASTEXITCODE) - switch the layout by hand." }
|
||||
# 6. Check the mod; switch the layout only where the person has not chosen another one.
|
||||
if (Test-HerdrApp) {
|
||||
$check = Invoke-HerdrApp @('check', $ModDst)
|
||||
Write-HerdrOutput $check
|
||||
if ($check.ExitCode -ne 0) { Write-Warning "herdr-app check reported a problem (exit $($check.ExitCode))." }
|
||||
} else {
|
||||
Write-Warning 'herdr-app is not on the PATH - the mod was not checked.'
|
||||
}
|
||||
if ($firstInstall -or $activeLayout -eq $OldName) {
|
||||
Switch-Layout $Name
|
||||
} elseif ($activeLayout -ne $Name) {
|
||||
# ASCII only in this file (Windows PowerShell 5 reads it in the ANSI code page): the Polish letters are built.
|
||||
Write-Host "Prze$([char]0x0142)$([char]0x0105)cz layout: ctrl-shift-l (layout '$Name')"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { LIMITS, validate, validateMany, mention, removeMention } from "../mod/ovis-composer/attachments.js";
|
||||
import { LIMITS, validate, validateMany, mention, removeMention } from "../herdr/herdr-composer/mods/herdr-composer/attachments.js";
|
||||
|
||||
test("validate rejects over 32 MiB", () => {
|
||||
const r = validate({ bytes: 33 * 2 ** 20 });
|
||||
@@ -59,7 +59,7 @@ test("removeMention takes the quoted form and the bare form out", () => {
|
||||
assert.equal(removeMention('see @"/a b/c.png"x now', "/a b/c.png"), 'see @"/a b/c.png"x now');
|
||||
});
|
||||
|
||||
import { formatBytes } from "../mod/ovis-composer/attachments.js";
|
||||
import { formatBytes } from "../herdr/herdr-composer/mods/herdr-composer/attachments.js";
|
||||
|
||||
test("formatBytes", () => {
|
||||
assert.equal(formatBytes(0), "0 B");
|
||||
@@ -71,12 +71,12 @@ test("formatBytes", () => {
|
||||
assert.equal(formatBytes(NaN), "");
|
||||
});
|
||||
|
||||
import { relativeTo } from "../mod/ovis-composer/attachments.js";
|
||||
import { relativeTo } from "../herdr/herdr-composer/mods/herdr-composer/attachments.js";
|
||||
|
||||
test("relativeTo: a file inside the folder, forward slashes, any case", () => {
|
||||
assert.equal(
|
||||
relativeTo("C:\\Users\\Factor\\.config\\herdr-app", "C:\\Users\\Factor\\.config\\herdr-app\\data\\ovis-composer\\paste\\paste-1.png"),
|
||||
"data/ovis-composer/paste/paste-1.png",
|
||||
relativeTo("C:\\Users\\Factor\\.config\\herdr-app", "C:\\Users\\Factor\\.config\\herdr-app\\data\\herdr-composer\\paste\\paste-1.png"),
|
||||
"data/herdr-composer/paste/paste-1.png",
|
||||
);
|
||||
assert.equal(relativeTo("c:/users/factor/.config/herdr-app/", "C:\\Users\\Factor\\.config\\herdr-app\\a b\\ę.png"), "a b/ę.png");
|
||||
});
|
||||
|
||||
@@ -3,7 +3,7 @@ import assert from "node:assert/strict";
|
||||
import {
|
||||
clipboardScript, parseClipboardResult, pickerScript, parsePickerResult,
|
||||
sizeScript, parseSizeResult, staleFiles, supportsImages,
|
||||
} from "../mod/ovis-composer/clipboard.js";
|
||||
} from "../herdr/herdr-composer/mods/herdr-composer/clipboard.js";
|
||||
|
||||
const ok = (stdout) => ({ code: 0, stdout, stderr: "" });
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { decide, gateAfter, onRestart, shouldDrain, shouldStartCountdown, drain } from "../mod/ovis-composer/delivery.js";
|
||||
import { decide, gateAfter, onRestart, shouldDrain, shouldStartCountdown, drain } from "../herdr/herdr-composer/mods/herdr-composer/delivery.js";
|
||||
|
||||
test("decide idle/done -> send", () => {
|
||||
assert.equal(decide("idle").kind, "send");
|
||||
@@ -56,7 +56,7 @@ test("onRestart: countdown -> held without left, sending -> uncertain", () => {
|
||||
});
|
||||
|
||||
test("drain sends an entry whose countdown ran out", async () => {
|
||||
const { createState, reduce } = await import("../mod/ovis-composer/state.js");
|
||||
const { createState, reduce } = await import("../herdr/herdr-composer/mods/herdr-composer/state.js");
|
||||
let s = reduce(createState(), { type: "queue", agent: "t2", item: { id: "1", text: "a", createdAt: 1 } });
|
||||
s = reduce(s, { type: "countdown_start", agent: "t2", id: "1" });
|
||||
const calls = [];
|
||||
@@ -106,7 +106,7 @@ test("shouldStartCountdown tolerates a non-array queue", () => {
|
||||
assert.equal(shouldStartCountdown(sc({ queue: null })), false);
|
||||
});
|
||||
|
||||
import { queueBlocksDirectSend } from "../mod/ovis-composer/delivery.js";
|
||||
import { queueBlocksDirectSend } from "../herdr/herdr-composer/mods/herdr-composer/delivery.js";
|
||||
|
||||
test("queueBlocksDirectSend: a message that waits (queued or counting down) goes first", () => {
|
||||
assert.equal(queueBlocksDirectSend([{ state: "queued" }]), true);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { record, search, toggleFavorite, isFavorite } from "../mod/ovis-composer/history.js";
|
||||
import { loadHistory, saveHistory, loadFavorites, saveFavorites, KEYS } from "../mod/ovis-composer/storage.js";
|
||||
import { record, search, toggleFavorite, isFavorite } from "../herdr/herdr-composer/mods/herdr-composer/history.js";
|
||||
import { loadHistory, saveHistory, loadFavorites, saveFavorites, KEYS } from "../herdr/herdr-composer/mods/herdr-composer/storage.js";
|
||||
|
||||
const memStore = () => {
|
||||
const m = new Map();
|
||||
@@ -107,7 +107,7 @@ test("storage: old favourites (at) load as createdAt", () => {
|
||||
assert.equal(loadFavorites(store)[0].createdAt, 4);
|
||||
});
|
||||
|
||||
import { segments, formatMoment, entryMeta, panelState, moveIndex, otherTab } from "../mod/ovis-composer/history.js";
|
||||
import { segments, formatMoment, entryMeta, panelState, moveIndex, otherTab } from "../herdr/herdr-composer/mods/herdr-composer/history.js";
|
||||
|
||||
test("segments splits a text on the ranges", () => {
|
||||
assert.deepEqual(segments("uruchom testy", [[8, 12]]), [
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { keyIntent } from "../mod/ovis-composer/keys.js";
|
||||
import { keyIntent } from "../herdr/herdr-composer/mods/herdr-composer/keys.js";
|
||||
|
||||
const ev = (key, mods = {}) => ({ key, shift: false, ctrl: false, alt: false, composing: false, ...mods });
|
||||
const ctx = (o = {}) => ({ hasKeyboard: true, menuOpen: false, panelOpen: false, empty: false, status: null, ...o });
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { decode } from "../herdr/herdr-composer/mods/herdr-composer/powershell.js";
|
||||
import { readScript } from "../herdr/herdr-composer/mods/herdr-composer/catalog.js";
|
||||
|
||||
const NASTY = [
|
||||
".claude/commands/it\u2019s.md",
|
||||
".claude/commands/it\u2018s.md",
|
||||
".claude/commands/a\u201Ab\u201Bc.md",
|
||||
".claude/commands/o'brien.md",
|
||||
".claude/commands/$env:USERNAME.md",
|
||||
'.claude/commands/"; calc #.md',
|
||||
".claude/skills/zażółć gęślą/SKILL.md",
|
||||
];
|
||||
|
||||
const b64s = (script) =>
|
||||
[...script.matchAll(/FromBase64String\('([A-Za-z0-9+/=]*)'\)/g)].map((m) => Buffer.from(m[1], "base64").toString("utf8"));
|
||||
|
||||
test("decode: PowerShell that yields the text, with the text itself nowhere in it", () => {
|
||||
for (const text of NASTY) {
|
||||
const expr = decode(text);
|
||||
assert.deepEqual(b64s(expr), [text]);
|
||||
assert.equal(expr.includes(text), false);
|
||||
assert.match(expr, /^\[System\.Text\.Encoding\]::UTF8\.GetString\(\[System\.Convert\]::FromBase64String\('[A-Za-z0-9+/=]*'\)\)$/);
|
||||
}
|
||||
});
|
||||
|
||||
test("decode: every length of tail, emoji, newline, empty", () => {
|
||||
for (const text of ["", "a", "ab", "abc", "abcd", "ęą", "😀x", "a\nb"]) {
|
||||
assert.deepEqual(b64s(decode(text)), [text]);
|
||||
}
|
||||
});
|
||||
|
||||
test("catalog readScript: the path of a project file is only ever Base64", () => {
|
||||
for (const path of NASTY) {
|
||||
const script = readScript(path);
|
||||
assert.deepEqual(b64s(script), [path]);
|
||||
for (const raw of ["\u2019", "\u2018", "\u201A", "\u201B", "$env:USERNAME", "calc", "o'brien", "zażółć"]) {
|
||||
if (path.includes(raw)) assert.equal(script.includes(raw), false, `${raw} in the script`);
|
||||
}
|
||||
// the script still reads the file
|
||||
assert.ok(script.includes("Get-Content"));
|
||||
assert.ok(script.includes("-LiteralPath"));
|
||||
}
|
||||
});
|
||||
@@ -1,6 +1,6 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { sendArgs, parseSendArgs, sendNow } from "../mod/ovis-composer/delivery.js";
|
||||
import { sendArgs, parseSendArgs, sendNow } from "../herdr/herdr-composer/mods/herdr-composer/delivery.js";
|
||||
|
||||
const ok = { code: 0, stdout: "{}", stderr: "" };
|
||||
|
||||
@@ -49,8 +49,8 @@ test("--force is only there when asked for, and before the `--`", async () => {
|
||||
});
|
||||
|
||||
test("the queue never forces: drain sends without --force", async () => {
|
||||
const { createState, reduce } = await import("../mod/ovis-composer/state.js");
|
||||
const { drain } = await import("../mod/ovis-composer/delivery.js");
|
||||
const { createState, reduce } = await import("../herdr/herdr-composer/mods/herdr-composer/state.js");
|
||||
const { drain } = await import("../herdr/herdr-composer/mods/herdr-composer/delivery.js");
|
||||
const state = reduce(createState(), { type: "queue", agent: "t2", item: { id: "1", text: "q", createdAt: 1 } });
|
||||
const calls = [];
|
||||
const result = await drain(
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { createState, reduce, isSending } from "../mod/ovis-composer/state.js";
|
||||
import { createState, reduce, isSending } from "../herdr/herdr-composer/mods/herdr-composer/state.js";
|
||||
|
||||
test("createState starts empty", () => {
|
||||
const s = createState();
|
||||
|
||||
+98
-11
@@ -3,7 +3,7 @@ import assert from "node:assert/strict";
|
||||
import {
|
||||
HISTORY_LIMIT, queueKey, loadHistory, saveHistory, loadQueue, saveQueue, loadUsage, saveUsage,
|
||||
KEYS, draftKey, loadDraft, saveDraft,
|
||||
} from "../mod/ovis-composer/storage.js";
|
||||
} from "../herdr/herdr-composer/mods/herdr-composer/storage.js";
|
||||
|
||||
const memStore = () => {
|
||||
const m = new Map();
|
||||
@@ -23,12 +23,12 @@ test("saveHistory truncates to 500, keeping the newest", () => {
|
||||
|
||||
test("history drops invalid entries on load", () => {
|
||||
const store = memStore();
|
||||
store.set("ovis-composer.history", [{ id: "a", text: "x", at: 1 }, { id: "b" }, null]);
|
||||
store.set("herdr-composer.history", [{ id: "a", text: "x", at: 1 }, { id: "b" }, null]);
|
||||
assert.equal(loadHistory(store).length, 1);
|
||||
});
|
||||
|
||||
test("queueKey is per agent", () => {
|
||||
assert.equal(queueKey("a1"), "ovis-composer.queue:a1");
|
||||
assert.equal(queueKey("a1"), "herdr-composer.queue:a1");
|
||||
});
|
||||
|
||||
test("queue roundtrip; keeps sending state as written", () => {
|
||||
@@ -42,7 +42,7 @@ test("queue roundtrip; keeps sending state as written", () => {
|
||||
test("saveQueue ignores empty agent", () => {
|
||||
const store = memStore();
|
||||
saveQueue(store, "", [{ id: "1", text: "t", state: "queued", createdAt: 1 }]);
|
||||
assert.equal(store.get("ovis-composer.queue:"), undefined);
|
||||
assert.equal(store.get("herdr-composer.queue:"), undefined);
|
||||
});
|
||||
|
||||
test("usage keeps only non-negative finite numbers", () => {
|
||||
@@ -64,8 +64,8 @@ const draft = (over = {}) => ({
|
||||
});
|
||||
|
||||
test("draftKey is per agent", () => {
|
||||
assert.equal(KEYS.draft, "ovis-composer.draft");
|
||||
assert.equal(draftKey("t2"), "ovis-composer.draft:t2");
|
||||
assert.equal(KEYS.draft, "herdr-composer.draft");
|
||||
assert.equal(draftKey("t2"), "herdr-composer.draft:t2");
|
||||
});
|
||||
|
||||
test("draft roundtrip", () => {
|
||||
@@ -97,7 +97,7 @@ test("saveDraft ignores rubbish and empty agent", () => {
|
||||
saveDraft(store, "t2", "x");
|
||||
saveDraft(store, "", draft());
|
||||
assert.equal(loadDraft(store, "t2").text, "hello");
|
||||
assert.equal(store.get("ovis-composer.draft:"), undefined);
|
||||
assert.equal(store.get("herdr-composer.draft:"), undefined);
|
||||
});
|
||||
|
||||
test("empty draft overwrites the old one", () => {
|
||||
@@ -133,7 +133,7 @@ test("queue roundtrip keeps a countdown entry (restart turns it into held)", ()
|
||||
assert.deepEqual(loadQueue(store, "a"), q);
|
||||
});
|
||||
|
||||
import { loadUserMin, saveUserMin } from "../mod/ovis-composer/storage.js";
|
||||
import { loadUserMin, saveUserMin } from "../herdr/herdr-composer/mods/herdr-composer/storage.js";
|
||||
|
||||
test("userMin: the height the person dragged the composer to; 0 is none", () => {
|
||||
const store = memStore();
|
||||
@@ -142,10 +142,97 @@ test("userMin: the height the person dragged the composer to; 0 is none", () =>
|
||||
assert.equal(loadUserMin(store), 300);
|
||||
saveUserMin(store, 0);
|
||||
assert.equal(loadUserMin(store), 0);
|
||||
store.set("ovis-composer.userMin", "x");
|
||||
store.set("herdr-composer.userMin", "x");
|
||||
assert.equal(loadUserMin(store), 0);
|
||||
store.set("ovis-composer.userMin", -5);
|
||||
store.set("herdr-composer.userMin", -5);
|
||||
assert.equal(loadUserMin(store), 0);
|
||||
saveUserMin(store, NaN);
|
||||
assert.equal(store.get("ovis-composer.userMin"), -5);
|
||||
assert.equal(store.get("herdr-composer.userMin"), -5);
|
||||
});
|
||||
|
||||
// --- the rename ovis-composer -> herdr-composer: nothing the person kept is lost
|
||||
|
||||
import { LEGACY_PREFIX, loadFavorites } from "../herdr/herdr-composer/mods/herdr-composer/storage.js";
|
||||
|
||||
const OLD = "ovis-composer.";
|
||||
const NEW = "herdr-composer.";
|
||||
|
||||
test("migration: the legacy prefix", () => {
|
||||
assert.equal(LEGACY_PREFIX, "ovis-composer.");
|
||||
assert.equal(KEYS.history, "herdr-composer.history");
|
||||
assert.equal(queueKey("t2"), "herdr-composer.queue:t2");
|
||||
assert.equal(draftKey("t2"), "herdr-composer.draft:t2");
|
||||
});
|
||||
|
||||
test("migration: the new key wins over the old one", () => {
|
||||
const store = memStore();
|
||||
store.set(OLD + "history", [{ id: "old", text: "old", at: 1 }]);
|
||||
store.set(NEW + "history", [{ id: "new", text: "new", sentAt: 2 }]);
|
||||
assert.deepEqual(loadHistory(store).map((e) => e.id), ["new"]);
|
||||
});
|
||||
|
||||
test("migration: history from the old key is read and written under the new one; the old stays", () => {
|
||||
const store = memStore();
|
||||
const old = [{ id: "old", text: "old", at: 1 }];
|
||||
store.set(OLD + "history", old);
|
||||
assert.deepEqual(loadHistory(store).map((e) => e.id), ["old"]);
|
||||
assert.deepEqual(store.get(NEW + "history"), old);
|
||||
assert.deepEqual(store.get(OLD + "history"), old);
|
||||
});
|
||||
|
||||
test("migration: favourites, usage, queue, draft and userMin come across the same way", () => {
|
||||
const store = memStore();
|
||||
store.set(OLD + "favorites", [{ id: "f", text: "x", at: 4 }]);
|
||||
store.set(OLD + "usage", { review: 2 });
|
||||
store.set(OLD + "queue:t2", [{ id: "1", text: "t", state: "held", createdAt: 5 }]);
|
||||
store.set(OLD + "draft:t2", { text: "szkic", caret: 2, attachments: [], identity: { created_ms: 9, app: null }, savedAt: 1 });
|
||||
store.set(OLD + "userMin", 300);
|
||||
|
||||
assert.equal(loadFavorites(store)[0].createdAt, 4);
|
||||
assert.deepEqual(loadUsage(store), { review: 2 });
|
||||
assert.equal(loadQueue(store, "t2")[0].state, "held");
|
||||
assert.equal(loadDraft(store, "t2").text, "szkic");
|
||||
assert.equal(loadUserMin(store), 300);
|
||||
|
||||
for (const key of ["favorites", "usage", "queue:t2", "draft:t2", "userMin"]) {
|
||||
assert.notEqual(store.get(NEW + key), undefined, key);
|
||||
assert.notEqual(store.get(OLD + key), undefined, key);
|
||||
}
|
||||
});
|
||||
|
||||
test("migration: neither key -> the defaults, and nothing is written", () => {
|
||||
const store = memStore();
|
||||
assert.deepEqual(loadHistory(store), []);
|
||||
assert.deepEqual(loadFavorites(store), []);
|
||||
assert.deepEqual(loadUsage(store), {});
|
||||
assert.deepEqual(loadQueue(store, "t2"), []);
|
||||
assert.equal(loadDraft(store, "t2"), null);
|
||||
assert.equal(loadUserMin(store), 0);
|
||||
assert.equal(store.get(NEW + "history"), undefined);
|
||||
assert.equal(store.get(NEW + "draft:t2"), undefined);
|
||||
});
|
||||
|
||||
test("migration: rubbish in the old key is ignored as before, and not copied", () => {
|
||||
const store = memStore();
|
||||
store.set(OLD + "history", "x");
|
||||
store.set(OLD + "favorites", [{ nope: 1 }]);
|
||||
store.set(OLD + "queue:t2", [{ id: "1" }]);
|
||||
store.set(OLD + "draft:t2", [1, 2]);
|
||||
store.set(OLD + "usage", { a: -1, b: "x" });
|
||||
store.set(OLD + "userMin", -3);
|
||||
assert.deepEqual(loadHistory(store), []);
|
||||
assert.deepEqual(loadFavorites(store), []);
|
||||
assert.deepEqual(loadQueue(store, "t2"), []);
|
||||
assert.equal(loadDraft(store, "t2"), null);
|
||||
assert.deepEqual(loadUsage(store), {});
|
||||
assert.equal(loadUserMin(store), 0);
|
||||
for (const key of ["history", "favorites", "queue:t2", "draft:t2", "usage", "userMin"]) {
|
||||
assert.equal(store.get(NEW + key), undefined, key);
|
||||
}
|
||||
});
|
||||
|
||||
test("migration: a store that cannot be written to still reads the old data", () => {
|
||||
const raw = new Map([[OLD + "history", [{ id: "old", text: "old", at: 1 }]]]);
|
||||
const store = { get: (k) => raw.get(k), set: () => { throw new Error("read-only"); } };
|
||||
assert.deepEqual(loadHistory(store).map((e) => e.id), ["old"]);
|
||||
});
|
||||
@@ -1,6 +1,6 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { detect, startsLine, rank, merge, GROUPS } from "../mod/ovis-composer/suggest.js";
|
||||
import { detect, startsLine, rank, merge, GROUPS } from "../herdr/herdr-composer/mods/herdr-composer/suggest.js";
|
||||
|
||||
test("detect finds a slash command at caret", () => {
|
||||
assert.deepEqual(detect("ala /re", 7), { trigger: "/", needle: "re", start: 4 });
|
||||
|
||||
+6
-6
@@ -3,7 +3,7 @@ import assert from "node:assert/strict";
|
||||
import {
|
||||
targetAgent, agentKey, agentName, agentStatus, createGate, gatePasses, openGate, closeGate,
|
||||
isPlainEnter, statusText, queueLabel, applySuggestion, insertedNewline,
|
||||
} from "../mod/ovis-composer/view.js";
|
||||
} from "../herdr/herdr-composer/mods/herdr-composer/view.js";
|
||||
|
||||
const agents = [{ address: "t1", app: "claude-code" }, { address: "a2" }];
|
||||
|
||||
@@ -55,7 +55,7 @@ test("insertedNewline finds the index", () => {
|
||||
});
|
||||
|
||||
test("canAutoSend waits for the draft/identity check of the agent", async () => {
|
||||
const { canAutoSend } = await import("../mod/ovis-composer/view.js");
|
||||
const { canAutoSend } = await import("../herdr/herdr-composer/mods/herdr-composer/view.js");
|
||||
assert.equal(canAutoSend(new Set(), "t2"), false);
|
||||
assert.equal(canAutoSend(new Set(["t2"]), "t2"), true);
|
||||
assert.equal(canAutoSend(new Set(["t3"]), "t2"), false);
|
||||
@@ -70,7 +70,7 @@ test("queueLabel for every state", () => {
|
||||
assert.equal(queueLabel({ state: "countdown", left: 2 }), "Wysyłam za 2 s");
|
||||
});
|
||||
|
||||
import { stillSameAgent } from "../mod/ovis-composer/view.js";
|
||||
import { stillSameAgent } from "../herdr/herdr-composer/mods/herdr-composer/view.js";
|
||||
|
||||
test("stillSameAgent: only when the field and the focus are on one agent", () => {
|
||||
assert.equal(stillSameAgent({ before: "t2", after: "t2", target: "t2" }), true);
|
||||
@@ -82,7 +82,7 @@ test("stillSameAgent: only when the field and the focus are on one agent", () =>
|
||||
assert.equal(stillSameAgent({ before: "", after: "t2", target: "t2" }), false);
|
||||
});
|
||||
|
||||
import { directSendBlocked } from "../mod/ovis-composer/view.js";
|
||||
import { directSendBlocked } from "../herdr/herdr-composer/mods/herdr-composer/view.js";
|
||||
|
||||
test("directSendBlocked: who must wait behind the queue", () => {
|
||||
const queue = [{ state: "queued" }];
|
||||
@@ -101,7 +101,7 @@ test("directSendBlocked: who must wait behind the queue", () => {
|
||||
assert.equal(directSendBlocked({ draining: false, mode: "auto", status: "idle", queue: [{ state: "held" }] }), false);
|
||||
});
|
||||
|
||||
import { blockTargetPx, shouldResize, isManualResize } from "../mod/ovis-composer/view.js";
|
||||
import { blockTargetPx, shouldResize, isManualResize } from "../herdr/herdr-composer/mods/herdr-composer/view.js";
|
||||
|
||||
const fit = (over = {}) => ({ contentHeight: 100, padding: 16, zoom: 1.2, userMin: 0, min: 120, max: 520, ...over });
|
||||
|
||||
@@ -145,7 +145,7 @@ test("isManualResize: a height nobody ordered is the person's drag", () => {
|
||||
assert.equal(isManualResize({ reportedPx: NaN, orderedPx: 200 }), false);
|
||||
});
|
||||
|
||||
import { luminance, fieldBackground } from "../mod/ovis-composer/view.js";
|
||||
import { luminance, fieldBackground } from "../herdr/herdr-composer/mods/herdr-composer/view.js";
|
||||
|
||||
test("luminance: black is darker than grey is darker than white; alpha and rubbish are tolerated", () => {
|
||||
assert.ok(luminance("#000000") < luminance("#808080"));
|
||||
|
||||
Reference in new issue
Block a user