@webdavis/omp-rex-session-start 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,49 @@
1
- # Temporary Holding Version
1
+ # omp-rex-session-start
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
+ When [omp](https://github.com/can1357/oh-my-pi) runs in a [Rex](https://www.superlogical.com/rex) pane, this extension sends the main agent Rex's session-start text: that it runs in Rex, and which session and pane it's in. That lets the agent work with Rex on its own, such as splitting its pane or reading another tab's output.
4
+
5
+ Rex gives Claude Code and Codex this text through their hooks. omp has no Rex hook, so this extension asks Rex for the same text.
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ omp plugin install npm:@webdavis/omp-rex-session-start
11
+ ```
12
+
13
+ Restart omp after the install.
14
+
15
+ ## Use
16
+
17
+ There's nothing to do. Inside a Rex pane, the main agent gets the text before its first reply. Subagents don't. Outside Rex, the extension does nothing.
18
+
19
+ omp's status line shows how it went:
20
+
21
+ | Status | Meaning |
22
+ | ------------------------------------ | -------------------------------------- |
23
+ | `rex-session-start: ✓ sent` | The agent got Rex's session-start text |
24
+ | `rex-session-start: ✗ timed out` | Rex didn't answer within a second |
25
+ | `rex-session-start: ✗ rex not found` | omp couldn't find the `rex` command |
26
+ | `rex-session-start: ✗ rex failed` | Rex answered with an error or nothing |
27
+
28
+ A failure also shows a warning, once per session. The extension asks Rex again a minute later.
29
+
30
+ Run `/rex-session-start` to see the text the agent was sent, or why none was, and whether session naming is on.
31
+
32
+ ## Session naming
33
+
34
+ Rex can ask agents to name their sessions. This extension follows the Rex app's "Let agents name sessions" setting, so omp agents name sessions only when Claude Code and Codex agents do.
35
+
36
+ ## Limits
37
+
38
+ - The extension needs omp 19.3 or later.
39
+ - It reads the session naming setting from the Rex app's preferences on macOS. Elsewhere, and when the setting can't be read, agents don't name sessions.
40
+ - The text is fetched once per omp process. A restarted or resumed session asks Rex again.
41
+
42
+ ## Develop
43
+
44
+ ```sh
45
+ bun install
46
+ bun run test # every test, in milliseconds
47
+ bun run check # typecheck
48
+ bun run format # format with Prettier
49
+ ```
package/package.json CHANGED
@@ -1,6 +1,43 @@
1
1
  {
2
2
  "name": "@webdavis/omp-rex-session-start",
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": "Send Rex's session-start text to an omp agent running in a Rex pane.",
5
+ "keywords": [
6
+ "omp",
7
+ "oh-my-pi",
8
+ "omp-plugin",
9
+ "omp-extension",
10
+ "rex"
11
+ ],
12
+ "license": "MIT",
13
+ "author": "Stephen A. Davis (https://github.com/webdavis)",
14
+ "homepage": "https://github.com/webdavis/omp-rex-session-start#readme",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/webdavis/omp-rex-session-start.git"
18
+ },
19
+ "bugs": {
20
+ "url": "https://github.com/webdavis/omp-rex-session-start/issues"
21
+ },
22
+ "type": "module",
23
+ "files": [
24
+ "src"
25
+ ],
26
+ "omp": {
27
+ "extensions": [
28
+ "./src/rex-session-start.ts"
29
+ ]
30
+ },
31
+ "scripts": {
32
+ "test": "bun test --timeout=50",
33
+ "check": "tsc --noEmit",
34
+ "format": "prettier --write .",
35
+ "format:check": "prettier --check ."
36
+ },
37
+ "devDependencies": {
38
+ "@oh-my-pi/pi-coding-agent": "19.3.0",
39
+ "@types/bun": "^1.4.5",
40
+ "prettier": "^3.10.1",
41
+ "typescript": "^7.0.2"
42
+ }
43
+ }
@@ -0,0 +1,3 @@
1
+ export interface Briefing {
2
+ promptFor(basePrompt: string | string[], isMainAgent: boolean): Promise<string[]>;
3
+ }
@@ -0,0 +1,26 @@
1
+ import type { Clock } from "./clock.ts";
2
+ import type { Rex, RexAnswer } from "./rex.ts";
3
+
4
+ const RETRY_AFTER_FAILURE_MS = 60_000;
5
+
6
+ export class CachedRex implements Rex {
7
+ private answer: RexAnswer | undefined;
8
+ private answeredAt = 0;
9
+
10
+ constructor(
11
+ private readonly rex: Rex,
12
+ private readonly clock: Clock,
13
+ ) {}
14
+
15
+ async ask(): Promise<RexAnswer> {
16
+ if (!this.answer || this.failureHasExpired()) {
17
+ this.answer = await this.rex.ask();
18
+ this.answeredAt = this.clock.now();
19
+ }
20
+ return this.answer;
21
+ }
22
+
23
+ private failureHasExpired(): boolean {
24
+ return this.answer?.kind === "failure" && this.clock.now() - this.answeredAt >= RETRY_AFTER_FAILURE_MS;
25
+ }
26
+ }
package/src/clock.ts ADDED
@@ -0,0 +1,3 @@
1
+ export interface Clock {
2
+ now(): number;
3
+ }
@@ -0,0 +1,33 @@
1
+ import type { CommandRunner } from "./command-runner.ts";
2
+ import type { Environment } from "./environment.ts";
3
+ import type { NamingPreference } from "./naming-preference.ts";
4
+ import type { Rex, RexAnswer } from "./rex.ts";
5
+
6
+ const SESSION_START_FOR_OMP = ["__internal", "session-start", "--agent", "omp"];
7
+ const REX_TIMEOUT_MS = 1000;
8
+
9
+ export class CommandRex implements Rex {
10
+ constructor(
11
+ private readonly runner: CommandRunner,
12
+ private readonly environment: Environment,
13
+ private readonly naming: NamingPreference,
14
+ ) {}
15
+
16
+ async ask(): Promise<RexAnswer> {
17
+ if (!this.environment.isInsideRex()) return { kind: "outside" };
18
+ const binDir = this.environment.rexBinDir();
19
+ const rex = binDir ? `${binDir}/rex` : "rex";
20
+ const agentsNameSessions = await this.naming.agentsNameSessions();
21
+ const result = await this.runner.run(
22
+ rex,
23
+ [...SESSION_START_FOR_OMP, `--feature-session-naming=${agentsNameSessions}`],
24
+ REX_TIMEOUT_MS,
25
+ );
26
+ if (result.kind === "exited" && result.code === 0 && result.output.trim()) {
27
+ return { kind: "answer", text: result.output };
28
+ }
29
+ if (result.kind === "not found") return { kind: "failure", reason: "rex not found" };
30
+ if (result.kind === "timed out") return { kind: "failure", reason: "timed out" };
31
+ return { kind: "failure", reason: "rex failed" };
32
+ }
33
+ }
@@ -0,0 +1,6 @@
1
+ export type CommandResult =
2
+ { kind: "exited"; code: number; output: string } | { kind: "timed out" } | { kind: "not found" } | { kind: "failed" };
3
+
4
+ export interface CommandRunner {
5
+ run(command: string, args: string[], timeoutMs: number): Promise<CommandResult>;
6
+ }
package/src/command.ts ADDED
@@ -0,0 +1,3 @@
1
+ export interface Command {
2
+ text(): Promise<string>;
3
+ }
@@ -0,0 +1,4 @@
1
+ export interface Environment {
2
+ isInsideRex(): boolean;
3
+ rexBinDir(): string | undefined;
4
+ }
@@ -0,0 +1,8 @@
1
+ import type { RexFailureReason } from "./rex.ts";
2
+
3
+ export type Outcome = "sent" | RexFailureReason;
4
+
5
+ export interface Feedback {
6
+ status(outcome: Outcome): void;
7
+ warn(reason: RexFailureReason): void;
8
+ }
@@ -0,0 +1,23 @@
1
+ import type { Briefing } from "./briefing.ts";
2
+ import type { Feedback } from "./feedback.ts";
3
+ import type { Rex } from "./rex.ts";
4
+
5
+ export class MainAgentBriefing implements Briefing {
6
+ constructor(
7
+ private readonly rex: Rex,
8
+ private readonly feedback: Feedback,
9
+ ) {}
10
+
11
+ async promptFor(basePrompt: string | string[], isMainAgent: boolean): Promise<string[]> {
12
+ const prompt = [basePrompt].flat();
13
+ if (!isMainAgent) return prompt;
14
+ const answer = await this.rex.ask();
15
+ if (answer.kind === "failure") {
16
+ this.feedback.status(answer.reason);
17
+ this.feedback.warn(answer.reason);
18
+ }
19
+ if (answer.kind !== "answer") return prompt;
20
+ this.feedback.status("sent");
21
+ return [...prompt, answer.text];
22
+ }
23
+ }
@@ -0,0 +1,3 @@
1
+ export interface NamingPreference {
2
+ agentsNameSessions(): Promise<boolean>;
3
+ }
@@ -0,0 +1,17 @@
1
+ import type { ExtensionAPI } from "@oh-my-pi/pi-coding-agent";
2
+ import type { CommandResult, CommandRunner } from "./command-runner.ts";
3
+
4
+ export class OmpCommandRunner implements CommandRunner {
5
+ constructor(private readonly exec: ExtensionAPI["exec"]) {}
6
+
7
+ async run(command: string, args: string[], timeoutMs: number): Promise<CommandResult> {
8
+ try {
9
+ const result = await this.exec(command, args, { timeout: timeoutMs });
10
+ if (result.killed) return { kind: "timed out" };
11
+ return { kind: "exited", code: result.code, output: result.stdout };
12
+ } catch (error) {
13
+ const notFound = error instanceof Error && "code" in error && error.code === "ENOENT";
14
+ return notFound ? { kind: "not found" } : { kind: "failed" };
15
+ }
16
+ }
17
+ }
@@ -0,0 +1,20 @@
1
+ import type { ExtensionUIContext } from "@oh-my-pi/pi-coding-agent";
2
+ import type { Feedback, Outcome } from "./feedback.ts";
3
+ import type { RexFailureReason } from "./rex.ts";
4
+
5
+ type FeedbackUI = Pick<ExtensionUIContext, "setStatus" | "notify">;
6
+
7
+ const EXTENSION = "rex-session-start";
8
+
9
+ export class OmpFeedback implements Feedback {
10
+ constructor(private readonly currentUI: () => FeedbackUI) {}
11
+
12
+ status(outcome: Outcome): void {
13
+ const state = outcome === "sent" ? "✓ sent" : `✗ ${outcome}`;
14
+ this.currentUI().setStatus(EXTENSION, `${EXTENSION}: ${state}`);
15
+ }
16
+
17
+ warn(reason: RexFailureReason): void {
18
+ this.currentUI().notify(`${EXTENSION}: couldn't send Rex's session-start text: ${reason}`, "warning");
19
+ }
20
+ }
@@ -0,0 +1,13 @@
1
+ import type { Environment } from "./environment.ts";
2
+
3
+ export class ProcessEnvironment implements Environment {
4
+ constructor(private readonly variables: Record<string, string | undefined>) {}
5
+
6
+ isInsideRex(): boolean {
7
+ return Boolean(this.variables.REX_BLOCK);
8
+ }
9
+
10
+ rexBinDir(): string | undefined {
11
+ return this.variables.REX_BIN_DIR;
12
+ }
13
+ }
@@ -0,0 +1,14 @@
1
+ import type { CommandRunner } from "./command-runner.ts";
2
+ import type { NamingPreference } from "./naming-preference.ts";
3
+
4
+ const READ_REX_APP_SESSION_NAMING = ["read", "com.superlogical.rex", "rex.agents.names-sessions"];
5
+ const READ_TIMEOUT_MS = 1000;
6
+
7
+ export class RexAppNamingPreference implements NamingPreference {
8
+ constructor(private readonly runner: CommandRunner) {}
9
+
10
+ async agentsNameSessions(): Promise<boolean> {
11
+ const setting = await this.runner.run("defaults", READ_REX_APP_SESSION_NAMING, READ_TIMEOUT_MS);
12
+ return setting.kind === "exited" && setting.output.trim() === "1";
13
+ }
14
+ }
@@ -0,0 +1,23 @@
1
+ import type { Command } from "./command.ts";
2
+ import type { NamingPreference } from "./naming-preference.ts";
3
+ import type { Rex, RexAnswer } from "./rex.ts";
4
+
5
+ const EXTENSION = "rex-session-start";
6
+
7
+ export class RexSessionStartCommand implements Command {
8
+ constructor(
9
+ private readonly rex: Rex,
10
+ private readonly naming: NamingPreference,
11
+ ) {}
12
+
13
+ async text(): Promise<string> {
14
+ const naming = (await this.naming.agentsNameSessions()) ? "on" : "off";
15
+ return `${describe(await this.rex.ask())}\n\nSession naming: ${naming}`;
16
+ }
17
+ }
18
+
19
+ function describe(answer: RexAnswer): string {
20
+ if (answer.kind === "outside") return `${EXTENSION}: omp isn't running in a Rex pane, so nothing was sent`;
21
+ if (answer.kind === "failure") return `${EXTENSION}: couldn't send Rex's session-start text: ${answer.reason}`;
22
+ return `${EXTENSION}: sent Rex's session-start text:\n\n${answer.text}`;
23
+ }
@@ -0,0 +1,36 @@
1
+ import type { ExtensionAPI, ExtensionUIContext } from "@oh-my-pi/pi-coding-agent";
2
+ import { CachedRex } from "./cached-rex.ts";
3
+ import { CommandRex } from "./command-rex.ts";
4
+ import { MainAgentBriefing } from "./main-agent-briefing.ts";
5
+ import { OmpCommandRunner } from "./omp-command-runner.ts";
6
+ import { OmpFeedback } from "./omp-feedback.ts";
7
+ import { ProcessEnvironment } from "./process-environment.ts";
8
+ import { RexAppNamingPreference } from "./rex-app-naming-preference.ts";
9
+ import { RexSessionStartCommand } from "./rex-session-start-command.ts";
10
+ import { SystemClock } from "./system-clock.ts";
11
+ import { WarnOnceFeedback } from "./warn-once-feedback.ts";
12
+
13
+ type Omp = Pick<ExtensionAPI, "exec" | "on" | "registerCommand">;
14
+
15
+ export function rexSessionStartWith(omp: Omp, variables: Record<string, string | undefined>): void {
16
+ let currentUI: Pick<ExtensionUIContext, "setStatus" | "notify">;
17
+ const runner = new OmpCommandRunner((command, args, options) => omp.exec(command, args, options));
18
+ const naming = new RexAppNamingPreference(runner);
19
+ const rex = new CachedRex(new CommandRex(runner, new ProcessEnvironment(variables), naming), new SystemClock());
20
+ const briefing = new MainAgentBriefing(rex, new WarnOnceFeedback(new OmpFeedback(() => currentUI)));
21
+ const command = new RexSessionStartCommand(rex, naming);
22
+
23
+ omp.on("before_agent_start", async (event, ctx) => {
24
+ currentUI = ctx.ui;
25
+ return { systemPrompt: await briefing.promptFor(event.systemPrompt, ctx.agent.kind === "main") };
26
+ });
27
+
28
+ omp.registerCommand("rex-session-start", {
29
+ description: "Show the session-start text Rex sent the agent, and whether session naming is on",
30
+ handler: async (_args, ctx) => ctx.ui.notify(await command.text(), "info"),
31
+ });
32
+ }
33
+
34
+ export default function rexSessionStart(omp: ExtensionAPI): void {
35
+ rexSessionStartWith(omp, process.env);
36
+ }
package/src/rex.ts ADDED
@@ -0,0 +1,8 @@
1
+ export type RexFailureReason = "timed out" | "rex not found" | "rex failed";
2
+
3
+ export type RexAnswer =
4
+ { kind: "outside" } | { kind: "answer"; text: string } | { kind: "failure"; reason: RexFailureReason };
5
+
6
+ export interface Rex {
7
+ ask(): Promise<RexAnswer>;
8
+ }
@@ -0,0 +1,7 @@
1
+ import type { Clock } from "./clock.ts";
2
+
3
+ export class SystemClock implements Clock {
4
+ now(): number {
5
+ return Date.now();
6
+ }
7
+ }
@@ -0,0 +1,18 @@
1
+ import type { Feedback, Outcome } from "./feedback.ts";
2
+ import type { RexFailureReason } from "./rex.ts";
3
+
4
+ export class WarnOnceFeedback implements Feedback {
5
+ private warned = false;
6
+
7
+ constructor(private readonly feedback: Feedback) {}
8
+
9
+ status(outcome: Outcome): void {
10
+ this.feedback.status(outcome);
11
+ }
12
+
13
+ warn(reason: RexFailureReason): void {
14
+ if (this.warned) return;
15
+ this.warned = true;
16
+ this.feedback.warn(reason);
17
+ }
18
+ }