@webdavis/omp-rex-session-start 0.1.0 → 0.2.1
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/README.md +16 -11
- package/package.json +4 -4
- package/src/current-ui.ts +17 -0
- package/src/feedback.ts +1 -1
- package/src/omp-feedback.ts +7 -2
- package/src/rex-session-start.ts +20 -8
- package/src/session-start-notice.ts +14 -0
package/README.md
CHANGED
|
@@ -16,14 +16,15 @@ Restart omp after the install.
|
|
|
16
16
|
|
|
17
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
18
|
|
|
19
|
-
omp's status line shows how it
|
|
19
|
+
omp's status line shows how it's going:
|
|
20
20
|
|
|
21
|
-
| Status
|
|
22
|
-
|
|
|
23
|
-
| `rex-session-start:
|
|
24
|
-
| `rex-session-start:
|
|
25
|
-
| `rex-session-start: ✗
|
|
26
|
-
| `rex-session-start: ✗ rex
|
|
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 |
|
|
27
28
|
|
|
28
29
|
A failure also shows a warning, once per session. The extension asks Rex again a minute later.
|
|
29
30
|
|
|
@@ -42,8 +43,12 @@ Rex can ask agents to name their sessions. This extension follows the Rex app's
|
|
|
42
43
|
## Develop
|
|
43
44
|
|
|
44
45
|
```sh
|
|
45
|
-
bun install
|
|
46
|
-
bun
|
|
47
|
-
bun
|
|
48
|
-
bun
|
|
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
|
|
49
54
|
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webdavis/omp-rex-session-start",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Send Rex's session-start text to an omp agent running in a Rex pane.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"omp",
|
|
@@ -29,10 +29,10 @@
|
|
|
29
29
|
]
|
|
30
30
|
},
|
|
31
31
|
"scripts": {
|
|
32
|
-
"
|
|
33
|
-
"check": "tsc --noEmit",
|
|
32
|
+
"typechecker": "tsc --noEmit",
|
|
34
33
|
"format": "prettier --write .",
|
|
35
|
-
"format:check": "prettier --check ."
|
|
34
|
+
"format:check": "prettier --check .",
|
|
35
|
+
"verify": "bun test --timeout=200 && bun run typechecker && bun run format:check"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@oh-my-pi/pi-coding-agent": "19.3.0",
|
|
@@ -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
CHANGED
package/src/omp-feedback.ts
CHANGED
|
@@ -6,12 +6,17 @@ type FeedbackUI = Pick<ExtensionUIContext, "setStatus" | "notify">;
|
|
|
6
6
|
|
|
7
7
|
const EXTENSION = "rex-session-start";
|
|
8
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
|
+
|
|
9
15
|
export class OmpFeedback implements Feedback {
|
|
10
16
|
constructor(private readonly currentUI: () => FeedbackUI) {}
|
|
11
17
|
|
|
12
18
|
status(outcome: Outcome): void {
|
|
13
|
-
|
|
14
|
-
this.currentUI().setStatus(EXTENSION, `${EXTENSION}: ${state}`);
|
|
19
|
+
this.currentUI().setStatus(EXTENSION, `${EXTENSION}: ${stateOf(outcome)}`);
|
|
15
20
|
}
|
|
16
21
|
|
|
17
22
|
warn(reason: RexFailureReason): void {
|
package/src/rex-session-start.ts
CHANGED
|
@@ -1,29 +1,41 @@
|
|
|
1
|
-
import type { ExtensionAPI
|
|
1
|
+
import type { ExtensionAPI } from "@oh-my-pi/pi-coding-agent";
|
|
2
2
|
import { CachedRex } from "./cached-rex.ts";
|
|
3
3
|
import { CommandRex } from "./command-rex.ts";
|
|
4
|
+
import { CurrentUI } from "./current-ui.ts";
|
|
4
5
|
import { MainAgentBriefing } from "./main-agent-briefing.ts";
|
|
5
6
|
import { OmpCommandRunner } from "./omp-command-runner.ts";
|
|
6
7
|
import { OmpFeedback } from "./omp-feedback.ts";
|
|
7
8
|
import { ProcessEnvironment } from "./process-environment.ts";
|
|
8
9
|
import { RexAppNamingPreference } from "./rex-app-naming-preference.ts";
|
|
9
10
|
import { RexSessionStartCommand } from "./rex-session-start-command.ts";
|
|
11
|
+
import { SessionStartNotice } from "./session-start-notice.ts";
|
|
10
12
|
import { SystemClock } from "./system-clock.ts";
|
|
11
13
|
import { WarnOnceFeedback } from "./warn-once-feedback.ts";
|
|
12
14
|
|
|
13
15
|
type Omp = Pick<ExtensionAPI, "exec" | "on" | "registerCommand">;
|
|
14
16
|
|
|
15
17
|
export function rexSessionStartWith(omp: Omp, variables: Record<string, string | undefined>): void {
|
|
16
|
-
|
|
18
|
+
const ui = new CurrentUI();
|
|
17
19
|
const runner = new OmpCommandRunner((command, args, options) => omp.exec(command, args, options));
|
|
20
|
+
const environment = new ProcessEnvironment(variables);
|
|
18
21
|
const naming = new RexAppNamingPreference(runner);
|
|
19
|
-
const rex = new CachedRex(new CommandRex(runner,
|
|
20
|
-
const
|
|
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);
|
|
21
26
|
const command = new RexSessionStartCommand(rex, naming);
|
|
22
27
|
|
|
23
|
-
omp.on(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
+
);
|
|
27
39
|
|
|
28
40
|
omp.registerCommand("rex-session-start", {
|
|
29
41
|
description: "Show the session-start text Rex sent the agent, and whether session naming is on",
|
|
@@ -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
|
+
}
|