Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ Text objects (`iw`/`aw`, the quote/bracket pairs, and the `iq`/`ib` aliases) rou
just dev # Launch v1 with the plugin (uses OPENCODE_TUI_CONFIG=dev-tui.json)
just dev2 # Launch pinned v2/local source with isolated .dev2/ state
bun test # Run characterization tests
just check # Lint + existing fast tests (used in GitHub Actions)
just check # Lint + typecheck + existing fast tests (used in GitHub Actions)
just test-int # On-demand SDK/process integration and parser helpers
just test-e2e # Both pinned PTY hosts (v1 1.18.34, v2 2.0.15); optional v1/v2 selector
just compat-unit # Pure checks for the optional host harness
Expand Down Expand Up @@ -220,7 +220,7 @@ Branch naming: `type/description` — e.g. `feat/replace-char`, `fix/escape-hand

**Shifted key translation** happens in `translateKey()` before the handler sees the key. Handlers work with normalized keys (`$` not `shift+4`, `G` not `shift+g`). Add new shift mappings in `translateKey`, not in handlers.

**TypeScript strictness.** `strict: true` in tsconfig. No `any` in `src/vim/` or `test/`. The `api` parameter in `index.ts` is typed as `any` because the plugin types come from peer deps that may not be installed locally — that's the one acceptable use.
**TypeScript strictness.** `strict: true` in tsconfig. No `any` in `src/vim/` or `test/`. `api` in `index.ts` is typed as `TuiPluginApi` from `@opencode-ai/plugin`; `just check` runs `tsc --noEmit`, so type errors fail CI.

**Cross-platform.** All code must work on macOS, Linux, and Windows. No platform-specific assumptions without a runtime `process.platform` check and fallbacks for other platforms.

Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
just install # install deps
just dev # launch OpenCode v1 with the plugin loaded
just dev2 # launch pinned v2 with local source and separate .dev2/ state
just check # run lint + existing fast tests
just check # run lint + typecheck + existing fast tests
just test # existing fast suite
just test-int # on-demand harness integration checks (including launcher)
just test-e2e # both pinned hosts; inferred private binaries/temp outputs
Expand Down
7 changes: 6 additions & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ install:
test:
bun test

# Type-check src with tsc
typecheck:
bun run typecheck

# Check formatting and lint (warnings are errors)
lint:
bunx biome ci --error-on-warnings .
Expand All @@ -16,9 +20,10 @@ lint:
lint-fix:
bunx biome check --write .

# Run lint + tests
# Run lint + typecheck + tests
check:
just lint
just typecheck
just test

# Optional real-host check: use an empty output dir outside any checkout.
Expand Down
3 changes: 3 additions & 0 deletions mise.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Pins bun for this project (mise). Node comes from the global default.
[tools]
bun = "1.3"
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
"@kitlangton/terminal-control": "1.2.1",
"@opencode-ai/plugin": "^1.15.4",
"@opentui/keymap": "0.5.10",
"tsx": "^4.22.1"
"@types/node": "24.19.2",
"tsx": "^4.22.1",
"typescript": "5.9.3"
}
}
28 changes: 14 additions & 14 deletions src/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,27 @@ export const VERSION = "0.21.1";
// is CDN-cached for up to 5 minutes which delays update detection.
const LATEST_VERSION_URL = "https://api.github.com/repos/rohit-pathak/vimcode/contents/package.json?ref=main";

type Toast = (opts: { message: string; variant: string; duration: number }) => void;
type KV = { get(key: string): Promise<string | undefined>; set(key: string, value: string): Promise<void> };
type Toast = (opts: { message: string; variant: "info" | "success" | "warning" | "error"; duration: number }) => void;
// The v1 TuiKV is synchronous; the v2 facade (src/v2.ts) is async. Accept both:
// results go through Promise.resolve, which passes plain values and promises alike.
type KV = { get(key: string): unknown; set(key: string, value: string): unknown };

const ONE_DAY_MS = 24 * 60 * 60 * 1000;

export function checkForUpdate(toast: Toast, kv?: KV) {
let last: unknown;
try {
const last = kv?.get("lastUpdateCheck");
if (last && typeof last.then === "function") {
last
.then((ts: string | undefined) => {
if (ts && Date.now() - Number(ts) < ONE_DAY_MS) return;
fetchLatest(toast, kv);
})
.catch(() => {});
} else {
fetchLatest(toast, kv);
}
last = kv?.get("lastUpdateCheck");
} catch {
fetchLatest(toast);
return;
}
Promise.resolve(last)
.then((ts) => {
if (ts && Date.now() - Number(ts) < ONE_DAY_MS) return;
fetchLatest(toast, kv);
})
.catch(() => {});
}

function fetchLatest(toast: Toast, kv?: KV) {
Expand All @@ -36,7 +36,7 @@ function fetchLatest(toast: Toast, kv?: KV) {
.then((r) => r.json())
// biome-ignore lint/suspicious/noExplicitAny: untyped JSON response
.then((pkg: any) => {
kv?.set("lastUpdateCheck", Date.now().toString());
Promise.resolve(kv?.set("lastUpdateCheck", Date.now().toString())).catch(() => {});
const latest = pkg?.version;
if (latest && latest !== VERSION) {
toast({ message: `vimcode update available: v${VERSION} → v${latest}`, variant: "info", duration: 5000 });
Expand Down
53 changes: 53 additions & 0 deletions test/version.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { afterEach, beforeEach, describe, expect, it, mock } from "bun:test";
import { checkForUpdate, VERSION } from "../src/version";

const realFetch = globalThis.fetch;
let fetchMock: ReturnType<typeof mock>;

const flush = () => new Promise((resolve) => setTimeout(resolve, 0));
const recent = () => String(Date.now() - 60_000);
const stale = () => String(Date.now() - 2 * 24 * 60 * 60 * 1000);

beforeEach(() => {
fetchMock = mock(async () => new Response(JSON.stringify({ version: "999.0.0" })));
globalThis.fetch = fetchMock as unknown as typeof fetch;
});

afterEach(() => {
globalThis.fetch = realFetch;
});

describe("checkForUpdate", () => {
it("skips the fetch when a sync KV (v1) says it checked today", async () => {
checkForUpdate(() => {}, { get: () => recent(), set: () => {} });
await flush();
expect(fetchMock).not.toHaveBeenCalled();
});

it("skips the fetch when an async KV (v2) says it checked today", async () => {
checkForUpdate(() => {}, { get: async () => recent(), set: async () => {} });
await flush();
expect(fetchMock).not.toHaveBeenCalled();
});

it("fetches, records the check and toasts when the last check is stale", async () => {
const toast = mock(() => {});
const set = mock(() => {});
checkForUpdate(toast, { get: () => stale(), set });
await flush();
await flush();
expect(fetchMock).toHaveBeenCalledTimes(1);
expect(set).toHaveBeenCalledWith("lastUpdateCheck", expect.any(String));
expect(toast).toHaveBeenCalledWith({
message: `vimcode update available: v${VERSION} → v999.0.0`,
variant: "info",
duration: 5000,
});
});

it("fetches when there is no KV", async () => {
checkForUpdate(() => {});
await flush();
expect(fetchMock).toHaveBeenCalledTimes(1);
});
});
Loading