@webdavis/omp-clearscreen 0.0.0-stage → 0.1.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,52 @@
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+L` in [omp](https://github.com/can1357/oh-my-pi) to clear the screen, just like you would in your everyday Bash terminal. The messages move up into the terminal's scrollback, where you can still scroll back to them.
4
+
5
+ The session and the model's context are kept. This is not related to omp's own `/clear`, which drops the context.
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ omp plugin install npm:@webdavis/omp-clearscreen
11
+ ```
12
+
13
+ Restart omp after the install.
14
+
15
+ omp binds `Ctrl+L` to live voice mode, and this extension takes the key first. To keep live voice, [choose another key](#choose-the-key) for clearing, or give live voice another key in `~/.omp/agent/keybindings.yml`:
16
+
17
+ ```yaml
18
+ app.live.toggle: "alt+'"
19
+ ```
20
+
21
+ ## Use
22
+
23
+ Press `Ctrl+L`, or run `/clearscreen`.
24
+
25
+ While a response is running, the extension shows a warning and clears nothing.
26
+
27
+ ## Choose the key
28
+
29
+ `Ctrl+L` is the default. To clear the screen with another key, set it and restart omp:
30
+
31
+ ```sh
32
+ omp plugin config set @webdavis/omp-clearscreen key alt+k
33
+ ```
34
+
35
+ Name the key the way omp's `keybindings.yml` does, such as `alt+k` or `ctrl+shift+k`, with its modifiers in the order `ctrl`, `alt`, `shift`, `super`. A name omp does not know clears nothing. `/clearscreen` works whichever key is set.
36
+
37
+ ## Limits
38
+
39
+ - The extension needs omp 19.2 or later.
40
+ - The key clears the screen only while the prompt has the keyboard.
41
+
42
+ ## Develop
43
+
44
+ ```sh
45
+ bun install
46
+ bun test # the fast tests, which load nothing from omp
47
+ bun run test:all # also the tests that run omp's own code
48
+ bun run check # typecheck
49
+ bun run format # format with Prettier
50
+ ```
51
+
52
+ The idea comes from [pi-clear-hotkey](https://pi.dev/packages/@jetserge/pi-clear-hotkey) for Pi.
package/package.json CHANGED
@@ -1,6 +1,52 @@
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.1.0",
4
+ "description": "Clear omp's screen with Ctrl+L, 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+l",
35
+ "description": "The key that clears the screen, named as in omp's keybindings.yml"
36
+ }
37
+ }
38
+ },
39
+ "scripts": {
40
+ "test": "bun test test/unit",
41
+ "test:omp": "bun test test/omp",
42
+ "test:all": "bun test",
43
+ "check": "tsc --noEmit",
44
+ "format": "prettier --write .",
45
+ "format:check": "prettier --check ."
46
+ },
47
+ "devDependencies": {
48
+ "@oh-my-pi/pi-coding-agent": "19.2.0",
49
+ "prettier": "^3.10.1",
50
+ "typescript": "^7.0.2"
51
+ }
52
+ }
@@ -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 and scrollback, keeping 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+l";
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
+ }