@webdavis/omp-rex-session-start 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 +21 -0
- package/README.md +53 -2
- package/package.json +41 -4
- package/src/briefing.ts +3 -0
- package/src/cached-rex.ts +26 -0
- package/src/clock.ts +3 -0
- package/src/command-rex.ts +33 -0
- package/src/command-runner.ts +6 -0
- package/src/command.ts +3 -0
- package/src/current-ui.ts +17 -0
- package/src/environment.ts +4 -0
- package/src/feedback.ts +8 -0
- package/src/main-agent-briefing.ts +23 -0
- package/src/naming-preference.ts +3 -0
- package/src/omp-command-runner.ts +17 -0
- package/src/omp-feedback.ts +25 -0
- package/src/process-environment.ts +13 -0
- package/src/rex-app-naming-preference.ts +14 -0
- package/src/rex-session-start-command.ts +23 -0
- package/src/rex-session-start.ts +48 -0
- package/src/rex.ts +8 -0
- package/src/session-start-notice.ts +14 -0
- package/src/system-clock.ts +7 -0
- package/src/warn-once-feedback.ts +18 -0
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,54 @@
|
|
|
1
|
-
#
|
|
1
|
+
# omp-rex-session-start
|
|
2
2
|
|
|
3
|
-
|
|
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's going:
|
|
20
|
+
|
|
21
|
+
| Status | Meaning |
|
|
22
|
+
| -------------------------------------------------- | -------------------------------------------------------- |
|
|
23
|
+
| `rex-session-start: waiting for the first prompt…` | omp sends Rex's session-start text with the first prompt |
|
|
24
|
+
| `rex-session-start: ✓ sent` | The agent got Rex's session-start text |
|
|
25
|
+
| `rex-session-start: ✗ timed out` | Rex didn't answer within a second |
|
|
26
|
+
| `rex-session-start: ✗ rex not found` | omp couldn't find the `rex` command |
|
|
27
|
+
| `rex-session-start: ✗ rex failed` | Rex answered with an error or nothing |
|
|
28
|
+
|
|
29
|
+
A failure also shows a warning, once per session. The extension asks Rex again a minute later.
|
|
30
|
+
|
|
31
|
+
Run `/rex-session-start` to see the text the agent was sent, or why none was, and whether session naming is on.
|
|
32
|
+
|
|
33
|
+
## Session naming
|
|
34
|
+
|
|
35
|
+
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.
|
|
36
|
+
|
|
37
|
+
## Limits
|
|
38
|
+
|
|
39
|
+
- The extension needs omp 19.3 or later.
|
|
40
|
+
- 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.
|
|
41
|
+
- The text is fetched once per omp process. A restarted or resumed session asks Rex again.
|
|
42
|
+
|
|
43
|
+
## Develop
|
|
44
|
+
|
|
45
|
+
```sh
|
|
46
|
+
bun install # installs the dependencies listed in package.json
|
|
47
|
+
bun test # runs every test
|
|
48
|
+
bun test test/unit # runs only the isolated tests, which load nothing from omp
|
|
49
|
+
bun test test/integration # runs only the integration tests, which exercise the whole extension against a fake omp
|
|
50
|
+
bun run typechecker # runs the TypeScript compiler's type-checker on the code in src/ and test/
|
|
51
|
+
bun run format # formats with Prettier, rewriting the files
|
|
52
|
+
bun run format:check # checks the formatting without changing any file
|
|
53
|
+
bun run verify # runs what CI runs: the tests, the type-checker and the format check
|
|
54
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,43 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webdavis/omp-rex-session-start",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.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
|
+
"typechecker": "tsc --noEmit",
|
|
33
|
+
"format": "prettier --write .",
|
|
34
|
+
"format:check": "prettier --check .",
|
|
35
|
+
"verify": "bun test --timeout=200 && bun run typechecker && bun run format: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
|
+
}
|
package/src/briefing.ts
ADDED
|
@@ -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,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,17 @@
|
|
|
1
|
+
import type { ExtensionHandler, ExtensionUIContext } from "@oh-my-pi/pi-coding-agent";
|
|
2
|
+
|
|
3
|
+
type UI = Pick<ExtensionUIContext, "setStatus" | "notify">;
|
|
4
|
+
|
|
5
|
+
export class CurrentUI {
|
|
6
|
+
private ui: UI | undefined;
|
|
7
|
+
|
|
8
|
+
get = (): UI => this.ui!;
|
|
9
|
+
|
|
10
|
+
tracking<Handler extends ExtensionHandler<never, unknown>>(handler: Handler): Handler {
|
|
11
|
+
const tracked: ExtensionHandler<never, unknown> = (event, ctx) => {
|
|
12
|
+
this.ui = ctx.ui;
|
|
13
|
+
return handler(event, ctx);
|
|
14
|
+
};
|
|
15
|
+
return tracked as Handler;
|
|
16
|
+
}
|
|
17
|
+
}
|
package/src/feedback.ts
ADDED
|
@@ -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,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,25 @@
|
|
|
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
|
+
function stateOf(outcome: Outcome): string {
|
|
10
|
+
if (outcome === "waiting") return "waiting for the first prompt…";
|
|
11
|
+
if (outcome === "sent") return "✓ sent";
|
|
12
|
+
return `✗ ${outcome}`;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export class OmpFeedback implements Feedback {
|
|
16
|
+
constructor(private readonly currentUI: () => FeedbackUI) {}
|
|
17
|
+
|
|
18
|
+
status(outcome: Outcome): void {
|
|
19
|
+
this.currentUI().setStatus(EXTENSION, `${EXTENSION}: ${stateOf(outcome)}`);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
warn(reason: RexFailureReason): void {
|
|
23
|
+
this.currentUI().notify(`${EXTENSION}: couldn't send Rex's session-start text: ${reason}`, "warning");
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -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,48 @@
|
|
|
1
|
+
import type { ExtensionAPI } from "@oh-my-pi/pi-coding-agent";
|
|
2
|
+
import { CachedRex } from "./cached-rex.ts";
|
|
3
|
+
import { CommandRex } from "./command-rex.ts";
|
|
4
|
+
import { CurrentUI } from "./current-ui.ts";
|
|
5
|
+
import { MainAgentBriefing } from "./main-agent-briefing.ts";
|
|
6
|
+
import { OmpCommandRunner } from "./omp-command-runner.ts";
|
|
7
|
+
import { OmpFeedback } from "./omp-feedback.ts";
|
|
8
|
+
import { ProcessEnvironment } from "./process-environment.ts";
|
|
9
|
+
import { RexAppNamingPreference } from "./rex-app-naming-preference.ts";
|
|
10
|
+
import { RexSessionStartCommand } from "./rex-session-start-command.ts";
|
|
11
|
+
import { SessionStartNotice } from "./session-start-notice.ts";
|
|
12
|
+
import { SystemClock } from "./system-clock.ts";
|
|
13
|
+
import { WarnOnceFeedback } from "./warn-once-feedback.ts";
|
|
14
|
+
|
|
15
|
+
type Omp = Pick<ExtensionAPI, "exec" | "on" | "registerCommand">;
|
|
16
|
+
|
|
17
|
+
export function rexSessionStartWith(omp: Omp, variables: Record<string, string | undefined>): void {
|
|
18
|
+
const ui = new CurrentUI();
|
|
19
|
+
const runner = new OmpCommandRunner((command, args, options) => omp.exec(command, args, options));
|
|
20
|
+
const environment = new ProcessEnvironment(variables);
|
|
21
|
+
const naming = new RexAppNamingPreference(runner);
|
|
22
|
+
const rex = new CachedRex(new CommandRex(runner, environment, naming), new SystemClock());
|
|
23
|
+
const feedback = new WarnOnceFeedback(new OmpFeedback(ui.get));
|
|
24
|
+
const briefing = new MainAgentBriefing(rex, feedback);
|
|
25
|
+
const notice = new SessionStartNotice(environment, feedback);
|
|
26
|
+
const command = new RexSessionStartCommand(rex, naming);
|
|
27
|
+
|
|
28
|
+
omp.on(
|
|
29
|
+
"session_start",
|
|
30
|
+
ui.tracking((_event, ctx) => notice.show(ctx.agent.kind === "main")),
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
omp.on(
|
|
34
|
+
"before_agent_start",
|
|
35
|
+
ui.tracking(async (event, ctx) => ({
|
|
36
|
+
systemPrompt: await briefing.promptFor(event.systemPrompt, ctx.agent.kind === "main"),
|
|
37
|
+
})),
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
omp.registerCommand("rex-session-start", {
|
|
41
|
+
description: "Show the session-start text Rex sent the agent, and whether session naming is on",
|
|
42
|
+
handler: async (_args, ctx) => ctx.ui.notify(await command.text(), "info"),
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export default function rexSessionStart(omp: ExtensionAPI): void {
|
|
47
|
+
rexSessionStartWith(omp, process.env);
|
|
48
|
+
}
|
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,14 @@
|
|
|
1
|
+
import type { Environment } from "./environment.ts";
|
|
2
|
+
import type { Feedback } from "./feedback.ts";
|
|
3
|
+
|
|
4
|
+
export class SessionStartNotice {
|
|
5
|
+
constructor(
|
|
6
|
+
private readonly environment: Pick<Environment, "isInsideRex">,
|
|
7
|
+
private readonly feedback: Pick<Feedback, "status">,
|
|
8
|
+
) {}
|
|
9
|
+
|
|
10
|
+
show(isMainAgent: boolean): void {
|
|
11
|
+
if (!isMainAgent || !this.environment.isInsideRex()) return;
|
|
12
|
+
this.feedback.status("waiting");
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -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
|
+
}
|