Repository navigation
Expand file tree
/
Copy pathtui.tsx
More file actions
172 lines (166 loc) · 6.72 KB
/
Copy pathtui.tsx
File metadata and controls
172 lines (166 loc) · 6.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/** @jsxImportSource @opentui/solid */
import { Plugin } from "@opencode/plugin/tui";
import { changeProfile, verifyGate } from "./dist/core/commands.js";
import { loadConfig } from "./dist/core/config.js";
import { runCommand } from "./dist/core/host.js";
import { renderConfigStatus, renderHelp, renderRuntimeStatus } from "./dist/core/format-status.js";
import { readRuntimeStatus } from "./dist/core/runtime-status.js";
import type { Profile } from "./dist/core/types.js";
const PROFILES: Profile[] = ["off", "advisory", "standard", "strict"];
export default Plugin.define({
id: "opencode-dev-framework",
setup(ctx) {
const getDirectory = (): string => {
const loc = ctx.location as unknown as { directory?: string } | undefined;
if (loc?.directory) return loc.directory;
try {
const def = (ctx.data as unknown as { location: { default: () => { directory: string } | undefined } }).location.default();
if (def?.directory) return def.directory;
} catch {
// ignore
}
return process.cwd();
};
const register = () => {
try {
(ctx as unknown as { keymap?: { layer: (fn: () => unknown) => void } }).keymap?.layer?.(() => ({
mode: "global",
commands: [
{
id: "df-status",
title: "dev-framework status",
description: "Show the current dev-framework configuration",
group: "dev-framework",
palette: true,
slash: { name: "df-status" },
run: () => {
const dir = getDirectory();
const config = loadConfig(dir);
// The dialog title already carries the heading; drop the
// duplicated first line from the shared text renderer.
const message = renderConfigStatus(config).split("\n").slice(2).join("\n");
const shown = ctx.ui.dialog.alert({
title: "opencode-dev-framework status",
message,
});
// Presentation is core-owned (alert takes no layout opts);
// large+centered is the available lever for long content.
ctx.ui.dialog.set({ size: "large", centered: true });
void shown;
},
},
{
id: "df-help",
title: "dev-framework help",
description: "List available dev-framework commands",
slash: { name: "df-help" },
group: "dev-framework",
palette: true,
run: () => {
void ctx.ui.dialog.alert({
title: "dev-framework commands",
// The dialog title already carries the heading; drop the
// duplicated first line from the shared text renderer.
message: renderHelp().split("\n").slice(2).join("\n"),
});
},
},
{
id: "df-profile",
title: "dev-framework profile",
description: "Change the active dev-framework profile",
group: "dev-framework",
palette: true,
slash: { name: "df-profile", arguments: true },
run: async (input?: string) => {
const dir = getDirectory();
const raw = (input ?? "").trim();
const arg = raw === "df-profile" ? "" : raw;
if (arg && (PROFILES as string[]).includes(arg)) {
const message = await changeProfile(dir, arg as Profile);
ctx.ui.toast.show({ message, variant: "success" });
return;
}
if (arg) {
ctx.ui.toast.show({
message: `Usage: /df-profile <${PROFILES.join("|")}>`,
variant: "warning",
});
return;
}
const selected = await ctx.ui.dialog.select({
title: "dev-framework profile",
options: PROFILES.map((p) => ({ title: p, value: p })),
});
if (selected) {
const message = await changeProfile(dir, selected as Profile);
ctx.ui.toast.show({ message, variant: "success" });
}
},
},
{
id: "df-runtime",
title: "dev-framework runtime",
description: "Show plugin version and live hook/gate runtime state",
group: "dev-framework",
palette: true,
slash: { name: "df-runtime" },
run: async () => {
const dir = getDirectory();
const snapshot = await readRuntimeStatus(dir);
const shown = ctx.ui.dialog.alert({
title: "dev-framework runtime",
// The dialog title already carries the heading; drop the
// duplicated first line from the shared text renderer.
message: renderRuntimeStatus(snapshot).split("\n").slice(2).join("\n"),
});
ctx.ui.dialog.set({ size: "large", centered: true });
await shown;
},
},
{
id: "df-verify",
title: "dev-framework verify",
description: "Run the dev-framework completion gate",
group: "dev-framework",
palette: true,
slash: { name: "df-verify" },
run: async () => {
const dir = getDirectory();
const config = loadConfig(dir);
const { summary, report } = await verifyGate(runCommand, dir, config);
const shown = ctx.ui.dialog.alert({
title: report.ok ? "dev-framework gate passed" : "dev-framework gate failed",
message: summary,
});
ctx.ui.dialog.set({ size: "large", centered: true });
await shown;
ctx.ui.toast.show({ message: summary, variant: report.ok ? "success" : "error" });
},
},
],
}));
} catch (e) {
try {
console.warn("[opencode-dev-framework:tui] keymap registration failed:", String(e));
} catch {}
}
};
try {
const slot = (ctx.ui as unknown as { slot?: (claim: { append: string; render: () => unknown }) => void }).slot;
if (typeof slot === "function") {
slot({
append: "app",
render() {
register();
return null as unknown as null;
},
});
return;
}
} catch {
// ignore, fallback below
}
register();
},
});