@webdavis/omp-rex-session-start 0.1.0 → 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/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 went:
19
+ omp's status line shows how it's going:
20
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 |
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 run test # every test, in milliseconds
47
- bun run check # typecheck
48
- bun run format # format with Prettier
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.0",
3
+ "version": "0.2.0",
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
- "test": "bun test --timeout=50",
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
@@ -1,6 +1,6 @@
1
1
  import type { RexFailureReason } from "./rex.ts";
2
2
 
3
- export type Outcome = "sent" | RexFailureReason;
3
+ export type Outcome = "waiting" | "sent" | RexFailureReason;
4
4
 
5
5
  export interface Feedback {
6
6
  status(outcome: Outcome): void;
@@ -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
- const state = outcome === "sent" ? "✓ sent" : `✗ ${outcome}`;
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 {
@@ -1,29 +1,41 @@
1
- import type { ExtensionAPI, ExtensionUIContext } from "@oh-my-pi/pi-coding-agent";
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
- let currentUI: Pick<ExtensionUIContext, "setStatus" | "notify">;
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, new ProcessEnvironment(variables), naming), new SystemClock());
20
- const briefing = new MainAgentBriefing(rex, new WarnOnceFeedback(new OmpFeedback(() => currentUI)));
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("before_agent_start", async (event, ctx) => {
24
- currentUI = ctx.ui;
25
- return { systemPrompt: await briefing.promptFor(event.systemPrompt, ctx.agent.kind === "main") };
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
+ }