@webdavis/omp-clearscreen 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Stephen A. Davis
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,61 @@
1
- # Temporary Holding Version
1
+ # omp-clearscreen
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Press `Ctrl+\`, or run the `/clearscreen` command in [omp](https://github.com/can1357/oh-my-pi) to clear the screen.
4
+
5
+ `/clearscreen` works just like `Ctrl+L` does in a Bash terminal. The messages move up into the terminal's scrollback. If
6
+ you need to see what was on the screen before, just scroll up and it's still there.
7
+
8
+ > The session and the model's context are kept. This is not related to omp's own `/clear`, which drops the context from
9
+ > your session.
10
+
11
+ ## Requirements
12
+
13
+ - The extension requires omp 19.2+
14
+ - The keyboard shortcut clears the screen only while the prompt has the keyboard
15
+
16
+ ## Install
17
+
18
+ ```sh
19
+ omp plugin install npm:@webdavis/omp-clearscreen
20
+ ```
21
+
22
+ Restart omp after the install.
23
+
24
+ ## Usage
25
+
26
+ Press `Ctrl+\`, or run `/clearscreen`.
27
+
28
+ > [!NOTE]
29
+ > If you run clearscreen while a response is running, the extension shows a warning and clears nothing.
30
+
31
+ ## Configuring a different key binding
32
+
33
+ `Ctrl+\` is the default. To clear the screen with another key, set it and then start a new session or restart omp:
34
+
35
+ ```sh
36
+ omp plugin config set @webdavis/omp-clearscreen key ctrl+l
37
+ ```
38
+
39
+ Alternatively, you can configure it in your `~/.omp/plugins/omp-plugins.lock.json` file, like so:
40
+
41
+ ```json
42
+ "settings": {
43
+ "@webdavis/omp-clearscreen": {
44
+ "key": "ctrl+l"
45
+ }
46
+ }
47
+ ```
48
+
49
+ ## Develop
50
+
51
+ ```sh
52
+ bun install # installs the dependencies listed in package.json
53
+ bun test # runs every test
54
+ bun test test/unit # runs only the isolated tests, which load nothing from omp
55
+ bun test test/integration # runs only the integration tests, which exercise the whole extension against a fake omp
56
+ bun test test/omp # runs only the tests that load omp's real code
57
+ bun run typechecker # runs the TypeScript compiler's type-checker on the code in src/ and test/
58
+ bun run format # formats with Prettier, rewriting the files
59
+ bun run format:check # checks the formatting without changing any file
60
+ bun run verify # runs what CI runs: the tests, the type-checker and the format check
61
+ ```
package/package.json CHANGED
@@ -1,6 +1,51 @@
1
1
  {
2
2
  "name": "@webdavis/omp-clearscreen",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.0",
4
+ "description": "Clear omp's screen, keeping the scrollback, the session and its context.",
5
+ "keywords": [
6
+ "omp",
7
+ "oh-my-pi",
8
+ "omp-plugin",
9
+ "omp-extension",
10
+ "clearscreen",
11
+ "keybinding"
12
+ ],
13
+ "license": "MIT",
14
+ "author": "Stephen A. Davis (https://github.com/webdavis)",
15
+ "homepage": "https://github.com/webdavis/omp-clearscreen#readme",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/webdavis/omp-clearscreen.git"
19
+ },
20
+ "bugs": {
21
+ "url": "https://github.com/webdavis/omp-clearscreen/issues"
22
+ },
23
+ "type": "module",
24
+ "files": [
25
+ "src"
26
+ ],
27
+ "omp": {
28
+ "extensions": [
29
+ "./src/clearscreen.ts"
30
+ ],
31
+ "settings": {
32
+ "key": {
33
+ "type": "string",
34
+ "default": "ctrl+\\",
35
+ "description": "The key that clears the screen. If you change the key, it applies once you start a new session or restart omp."
36
+ }
37
+ }
38
+ },
39
+ "scripts": {
40
+ "typechecker": "tsc --noEmit",
41
+ "format": "prettier --write .",
42
+ "format:check": "prettier --check .",
43
+ "verify": "bun test --timeout=2000 && bun run typechecker && bun run format:check"
44
+ },
45
+ "devDependencies": {
46
+ "@oh-my-pi/pi-coding-agent": "19.2.0",
47
+ "@types/bun": "^1.4.5",
48
+ "prettier": "^3.10.1",
49
+ "typescript": "^7.0.2"
50
+ }
51
+ }
@@ -0,0 +1,16 @@
1
+ import type { KeyListener } from "./key-listener.ts";
2
+ import type { Keyboard } from "./keyboard.ts";
3
+ import type { ScreenClearer } from "./screen-clearer.ts";
4
+
5
+ export class ClearKeyListener implements KeyListener {
6
+ constructor(
7
+ private readonly keyboard: Keyboard,
8
+ private readonly clearer: ScreenClearer,
9
+ ) {}
10
+
11
+ handleKey(keyId: string): boolean {
12
+ if (!this.keyboard.isClearKey(keyId)) return false;
13
+ void this.clearer.clear();
14
+ return true;
15
+ }
16
+ }
@@ -0,0 +1,37 @@
1
+ import type { ExtensionAPI, ExtensionContext } from "@oh-my-pi/pi-coding-agent";
2
+ import { ClearKeyListener } from "./clear-key-listener.ts";
3
+ import { IdleScreenClearer } from "./idle-screen-clearer.ts";
4
+ import { OmpKeyboard } from "./omp-keyboard.ts";
5
+ import { OmpPluginSettingsStore } from "./omp-plugin-settings-store.ts";
6
+ import { OmpScreen } from "./omp-screen.ts";
7
+ import { OmpSettings } from "./omp-settings.ts";
8
+ import type { ScreenClearer } from "./screen-clearer.ts";
9
+ import type { Settings } from "./settings.ts";
10
+
11
+ function clearerFor(ctx: ExtensionContext): ScreenClearer {
12
+ return new IdleScreenClearer(new OmpScreen(ctx));
13
+ }
14
+
15
+ export function clearscreenExtensionWith(settings: Settings) {
16
+ return (pi: Pick<ExtensionAPI, "on" | "registerCommand">) => {
17
+ pi.registerCommand("clearscreen", {
18
+ description: "Clear the screen, keeping the scrollback, the session and its context",
19
+ handler: (_args, ctx) => clearerFor(ctx).clear(),
20
+ });
21
+
22
+ const nothingToStop = () => {};
23
+ let stopListening = nothingToStop;
24
+ const listenForTheClearKeyInTheCurrentSession = async (_event: unknown, ctx: ExtensionContext) => {
25
+ const keyboard = new OmpKeyboard(await settings.clearKey(ctx.cwd));
26
+ const listener = new ClearKeyListener(keyboard, clearerFor(ctx));
27
+ stopListening();
28
+ stopListening = ctx.ui.composer?.addKeyHandler((key) => listener.handleKey(key.id)) ?? nothingToStop;
29
+ };
30
+
31
+ pi.on("session_start", listenForTheClearKeyInTheCurrentSession);
32
+ pi.on("session_switch", listenForTheClearKeyInTheCurrentSession);
33
+ pi.on("session_branch", listenForTheClearKeyInTheCurrentSession);
34
+ };
35
+ }
36
+
37
+ export default clearscreenExtensionWith(new OmpSettings(new OmpPluginSettingsStore()));
@@ -0,0 +1,14 @@
1
+ import type { Screen } from "./screen.ts";
2
+ import type { ScreenClearer } from "./screen-clearer.ts";
3
+
4
+ export class IdleScreenClearer implements ScreenClearer {
5
+ constructor(private readonly screen: Screen) {}
6
+
7
+ async clear(): Promise<void> {
8
+ if (this.screen.isBusy()) {
9
+ this.screen.warn("Clear the screen once the current response has finished.");
10
+ return;
11
+ }
12
+ this.screen.clear();
13
+ }
14
+ }
@@ -0,0 +1,3 @@
1
+ export interface KeyListener {
2
+ handleKey(keyId: string): boolean;
3
+ }
@@ -0,0 +1,3 @@
1
+ export interface Keyboard {
2
+ isClearKey(keyId: string): boolean;
3
+ }
@@ -0,0 +1,9 @@
1
+ import type { Keyboard } from "./keyboard.ts";
2
+
3
+ export class OmpKeyboard implements Keyboard {
4
+ constructor(private readonly clearKey: string) {}
5
+
6
+ isClearKey(keyId: string): boolean {
7
+ return keyId === this.clearKey;
8
+ }
9
+ }
@@ -0,0 +1,12 @@
1
+ import type { PluginSettingsStore } from "./plugin-settings-store.ts";
2
+
3
+ function importOmpPluginLoaderOnFirstRead() {
4
+ return import("@oh-my-pi/pi-coding-agent/extensibility/plugins/loader");
5
+ }
6
+
7
+ export class OmpPluginSettingsStore implements PluginSettingsStore {
8
+ async read(plugin: string, cwd: string): Promise<Record<string, unknown>> {
9
+ const { getPluginSettings } = await importOmpPluginLoaderOnFirstRead();
10
+ return getPluginSettings(plugin, cwd);
11
+ }
12
+ }
@@ -0,0 +1,37 @@
1
+ import type { ExtensionContext } from "@oh-my-pi/pi-coding-agent";
2
+ import type { Screen } from "./screen.ts";
3
+
4
+ export type OmpContext = Pick<ExtensionContext, "isIdle"> & {
5
+ ui: Pick<ExtensionContext["ui"], "notify" | "setWidget">;
6
+ };
7
+
8
+ const BLANK_ROWS_WIDGET = "omp-clearscreen";
9
+
10
+ function blankRows(count: number): string[] {
11
+ return new Array<string>(count).fill("");
12
+ }
13
+
14
+ export class OmpScreen implements Screen {
15
+ constructor(private readonly context: OmpContext) {}
16
+
17
+ isBusy(): boolean {
18
+ return !this.context.isIdle();
19
+ }
20
+
21
+ warn(message: string): void {
22
+ this.context.ui.notify(message, "warning");
23
+ }
24
+
25
+ clear(): void {
26
+ this.context.ui.setWidget(BLANK_ROWS_WIDGET, (host) => ({
27
+ render: () => {
28
+ this.removeBlankRowsOnceDrawn();
29
+ return blankRows(host.size().rows);
30
+ },
31
+ }));
32
+ }
33
+
34
+ private removeBlankRowsOnceDrawn(): void {
35
+ setTimeout(() => this.context.ui.setWidget(BLANK_ROWS_WIDGET, undefined));
36
+ }
37
+ }
@@ -0,0 +1,17 @@
1
+ import type { PluginSettingsStore } from "./plugin-settings-store.ts";
2
+ import type { Settings } from "./settings.ts";
3
+
4
+ const DEFAULT_KEY = "ctrl+\\";
5
+
6
+ export class OmpSettings implements Settings {
7
+ constructor(private readonly store: PluginSettingsStore) {}
8
+
9
+ async clearKey(cwd: string): Promise<string> {
10
+ try {
11
+ const { key } = await this.store.read("@webdavis/omp-clearscreen", cwd);
12
+ return typeof key === "string" ? key : DEFAULT_KEY;
13
+ } catch {
14
+ return DEFAULT_KEY;
15
+ }
16
+ }
17
+ }
@@ -0,0 +1,3 @@
1
+ export interface PluginSettingsStore {
2
+ read(plugin: string, cwd: string): Promise<Record<string, unknown>>;
3
+ }
@@ -0,0 +1,3 @@
1
+ export interface ScreenClearer {
2
+ clear(): Promise<void>;
3
+ }
package/src/screen.ts ADDED
@@ -0,0 +1,5 @@
1
+ export interface Screen {
2
+ isBusy(): boolean;
3
+ clear(): void;
4
+ warn(message: string): void;
5
+ }
@@ -0,0 +1,3 @@
1
+ export interface Settings {
2
+ clearKey(cwd: string): Promise<string>;
3
+ }