refactor: restructure into herdr/herdr-composer, rename ovis-composer -> herdr-composer, migrate stored data
Co-Authored-By: Ovis Fast (Claude) <[email protected]>
This commit is contained in:
1 parent
6beecaac83
commit
74c1dfaeb8
27 files changed
+253
-97
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/
|
||||
@@ -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.
File renamed without changes.
File renamed without changes.
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,23 +2010,26 @@ export default class Composer extends View {
|
||||
* and only files of that shape are ever touched.
|
||||
*/
|
||||
async cleanupPaste() {
|
||||
try {
|
||||
const dir = this.pasteDir();
|
||||
if (!(await fs.exists(dir))) return;
|
||||
const entries = [];
|
||||
for (const name of await fs.readdir(dir)) {
|
||||
const match = /^paste-(\d+)\.png$/.exec(name);
|
||||
if (match) entries.push({ path: `${dir}\\${name}`, mtimeMs: Number(match[1]) });
|
||||
}
|
||||
for (const path of staleFiles(entries, Date.now())) {
|
||||
try {
|
||||
await fs.unlink(path);
|
||||
} catch {
|
||||
// A file that cannot be removed stays; the next start tries again.
|
||||
// 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 {
|
||||
if (!(await fs.exists(dir))) continue;
|
||||
const entries = [];
|
||||
for (const name of await fs.readdir(dir)) {
|
||||
const match = /^paste-(\d+)\.png$/.exec(name);
|
||||
if (match) entries.push({ path: `${dir}\\${name}`, mtimeMs: Number(match[1]) });
|
||||
}
|
||||
for (const path of staleFiles(entries, Date.now())) {
|
||||
try {
|
||||
await fs.unlink(path);
|
||||
} catch {
|
||||
// A file that cannot be removed stays; the next start tries again.
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// No paste folder, nothing to clean.
|
||||
}
|
||||
} catch {
|
||||
// No paste folder, nothing to clean.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
@@ -51,7 +51,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 +311,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);
|
||||
File renamed without changes.
+83
-22
@@ -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,14 +296,20 @@ export function saveUserMin(store, px) {
|
||||
* @returns {Record<string, number>}
|
||||
*/
|
||||
export function loadUsage(store) {
|
||||
const raw = read(store, KEYS.usage);
|
||||
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return {};
|
||||
return loadMigrating(
|
||||
store,
|
||||
KEYS.usage,
|
||||
(raw) => {
|
||||
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return {};
|
||||
|
||||
const counts = {};
|
||||
for (const [key, value] of Object.entries(raw)) {
|
||||
if (typeof value === "number" && Number.isFinite(value) && value >= 0) counts[key] = value;
|
||||
}
|
||||
return counts;
|
||||
const counts = {};
|
||||
for (const [key, value] of Object.entries(raw)) {
|
||||
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);
|
||||
if (!found) return [];
|
||||
const list = shape ? found.map(shape) : found;
|
||||
return limit > 0 ? list.slice(-limit) : list;
|
||||
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.
@@ -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 });
|
||||
|
||||
@@ -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