@pi-ohm/modes 0.3.0-dev.22083116751.1.d12e548

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.
Files changed (3) hide show
  1. package/README.md +12 -0
  2. package/package.json +27 -0
  3. package/src/extension.ts +122 -0
package/README.md ADDED
@@ -0,0 +1,12 @@
1
+ # @pi-ohm/modes
2
+
3
+ Install only smart/rush/deep mode controls for Pi.
4
+
5
+ ```bash
6
+ pi install npm:@pi-ohm/modes
7
+ ```
8
+
9
+ Commands:
10
+
11
+ - `/ohm-modes` — show current/default mode and available modes
12
+ - `/ohm-mode <rush|smart|deep>` — set default mode in extension settings
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@pi-ohm/modes",
3
+ "version": "0.3.0-dev.22083116751.1.d12e548",
4
+ "type": "module",
5
+ "main": "src/extension.ts",
6
+ "types": "src/extension.ts",
7
+ "files": [
8
+ "src/",
9
+ "README.md"
10
+ ],
11
+ "pi": {
12
+ "extensions": [
13
+ "./src/extension.ts"
14
+ ]
15
+ },
16
+ "dependencies": {
17
+ "@mariozechner/pi-coding-agent": "^0.52.0",
18
+ "@pi-ohm/config": "0.3.0-dev.22083116751.1.d12e548"
19
+ },
20
+ "peerDependencies": {
21
+ "@mariozechner/pi-coding-agent": "*"
22
+ },
23
+ "publishConfig": {
24
+ "access": "public",
25
+ "provenance": true
26
+ }
27
+ }
@@ -0,0 +1,122 @@
1
+ import type { ExtensionAPI, ExtensionContext } from "@mariozechner/pi-coding-agent";
2
+ import {
3
+ loadOhmRuntimeConfig,
4
+ registerOhmSettings,
5
+ setOhmSetting,
6
+ type OhmMode,
7
+ } from "@pi-ohm/config";
8
+
9
+ const MODES: readonly OhmMode[] = ["rush", "smart", "deep"] as const;
10
+
11
+ function parseRequestedMode(args: unknown): OhmMode | null {
12
+ if (typeof args === "string") {
13
+ const normalized = args.trim().split(/\s+/)[0]?.toLowerCase();
14
+ if (!normalized) return null;
15
+ if (normalized === "rush" || normalized === "smart" || normalized === "deep") {
16
+ return normalized;
17
+ }
18
+ return null;
19
+ }
20
+
21
+ if (Array.isArray(args)) {
22
+ const first = args.find((value): value is string => typeof value === "string");
23
+ if (!first) return null;
24
+
25
+ const normalized = first.trim().toLowerCase();
26
+ if (normalized === "rush" || normalized === "smart" || normalized === "deep") {
27
+ return normalized;
28
+ }
29
+ return null;
30
+ }
31
+
32
+ if (args && typeof args === "object") {
33
+ const asRecord = args as { args?: unknown; raw?: unknown };
34
+ if (Array.isArray(asRecord.args)) {
35
+ return parseRequestedMode(asRecord.args);
36
+ }
37
+
38
+ if (typeof asRecord.raw === "string") {
39
+ return parseRequestedMode(asRecord.raw);
40
+ }
41
+ }
42
+
43
+ return null;
44
+ }
45
+
46
+ async function refreshModeStatus(ctx: ExtensionContext): Promise<void> {
47
+ const { config } = await loadOhmRuntimeConfig(ctx.cwd);
48
+ if (!ctx.hasUI) return;
49
+
50
+ ctx.ui.setStatus("ohm-mode", `mode:${config.defaultMode}`);
51
+ }
52
+
53
+ export default function registerModesExtension(pi: ExtensionAPI): void {
54
+ registerOhmSettings(pi);
55
+
56
+ pi.on("session_start", async (_event, ctx) => {
57
+ await refreshModeStatus(ctx);
58
+ });
59
+
60
+ pi.on("session_switch", async (_event, ctx) => {
61
+ await refreshModeStatus(ctx);
62
+ });
63
+
64
+ pi.registerCommand("ohm-modes", {
65
+ description: "Show available modes and current default mode",
66
+ handler: async (_args, ctx) => {
67
+ const { config, loadedFrom } = await loadOhmRuntimeConfig(ctx.cwd);
68
+ const text = [
69
+ "Pi OHM modes",
70
+ "",
71
+ `defaultMode: ${config.defaultMode}`,
72
+ `available: ${MODES.join(", ")}`,
73
+ "",
74
+ "Set mode with: /ohm-mode <rush|smart|deep>",
75
+ `loadedFrom: ${loadedFrom.length > 0 ? loadedFrom.join(", ") : "defaults + extension settings"}`,
76
+ ].join("\n");
77
+
78
+ if (!ctx.hasUI) {
79
+ console.log(text);
80
+ return;
81
+ }
82
+
83
+ await ctx.ui.editor("pi-ohm modes", text);
84
+ },
85
+ });
86
+
87
+ pi.registerCommand("ohm-mode", {
88
+ description: "Set default mode (rush|smart|deep)",
89
+ handler: async (args, ctx) => {
90
+ const requestedMode = parseRequestedMode(args);
91
+
92
+ if (!requestedMode) {
93
+ const usage = `Usage: /ohm-mode <${MODES.join("|")}>`;
94
+
95
+ if (!ctx.hasUI) {
96
+ console.log(usage);
97
+ return;
98
+ }
99
+
100
+ await ctx.ui.editor("pi-ohm mode usage", usage);
101
+ return;
102
+ }
103
+
104
+ setOhmSetting("default-mode", requestedMode);
105
+ await refreshModeStatus(ctx);
106
+
107
+ const text = [
108
+ "Pi OHM mode updated",
109
+ "",
110
+ `defaultMode: ${requestedMode}`,
111
+ "Tip: run /ohm-config to inspect merged runtime config.",
112
+ ].join("\n");
113
+
114
+ if (!ctx.hasUI) {
115
+ console.log(text);
116
+ return;
117
+ }
118
+
119
+ await ctx.ui.editor("pi-ohm mode updated", text);
120
+ },
121
+ });
122
+ }