@jmtrin/opencode-kevin-tui 1.3.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/dist/index.d.ts +3 -0
- package/dist/index.js +7 -0
- package/dist/tui-types.d.ts +59 -0
- package/dist/tui-types.js +4 -0
- package/dist/tui.d.ts +18 -0
- package/dist/tui.js +198 -0
- package/package.json +29 -0
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// @jmtrin/opencode-kevin-tui — target-exclusive TUI package (K13-004)
|
|
2
|
+
// Re-exports the TUI module and its view types; the host imports this package directly.
|
|
3
|
+
// The main plugin's exports["./tui"] redirects to this package (bare specifier) so
|
|
4
|
+
// external consumers see no change via `import "@jmtrin/opencode-kevin/tui"`.
|
|
5
|
+
export * from "./tui.js";
|
|
6
|
+
export * from "./tui-types.js";
|
|
7
|
+
export { tui as default } from "./tui.js";
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
export interface ProposalView {
|
|
2
|
+
readonly id: string;
|
|
3
|
+
readonly kind: string;
|
|
4
|
+
readonly target_path: string;
|
|
5
|
+
readonly diff: string;
|
|
6
|
+
readonly memory_ids: readonly string[];
|
|
7
|
+
readonly created_at: string;
|
|
8
|
+
readonly truncated?: boolean;
|
|
9
|
+
readonly token?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface ConflictView {
|
|
12
|
+
readonly id: string;
|
|
13
|
+
readonly kind: string;
|
|
14
|
+
readonly a_summary: string;
|
|
15
|
+
readonly b_summary: string;
|
|
16
|
+
readonly opened_at: string;
|
|
17
|
+
}
|
|
18
|
+
export interface HealthView {
|
|
19
|
+
readonly verdict: string;
|
|
20
|
+
readonly reason: string;
|
|
21
|
+
readonly hooks: readonly {
|
|
22
|
+
readonly hook: string;
|
|
23
|
+
readonly state: string;
|
|
24
|
+
readonly fire_count: number;
|
|
25
|
+
readonly expected_count: number;
|
|
26
|
+
}[];
|
|
27
|
+
readonly perf: readonly {
|
|
28
|
+
readonly scope: string;
|
|
29
|
+
readonly p95: number;
|
|
30
|
+
readonly budget_p95: number;
|
|
31
|
+
readonly within_budget: boolean;
|
|
32
|
+
}[];
|
|
33
|
+
readonly contract_digest: string;
|
|
34
|
+
readonly counters: Record<string, number>;
|
|
35
|
+
}
|
|
36
|
+
export interface TuiSnapshotSet {
|
|
37
|
+
readonly generatedAt: string;
|
|
38
|
+
readonly proposals: readonly ProposalView[];
|
|
39
|
+
readonly conflicts: readonly ConflictView[];
|
|
40
|
+
readonly health: HealthView;
|
|
41
|
+
}
|
|
42
|
+
export type TuiAction = {
|
|
43
|
+
readonly type: "approve";
|
|
44
|
+
readonly proposalId: string;
|
|
45
|
+
readonly token: string;
|
|
46
|
+
} | {
|
|
47
|
+
readonly type: "reject";
|
|
48
|
+
readonly proposalId: string;
|
|
49
|
+
readonly token: string;
|
|
50
|
+
readonly note?: string;
|
|
51
|
+
} | {
|
|
52
|
+
readonly type: "acknowledge";
|
|
53
|
+
readonly conflictId: string;
|
|
54
|
+
};
|
|
55
|
+
export interface ActionResult {
|
|
56
|
+
readonly action: TuiAction;
|
|
57
|
+
readonly status: "applied" | "rejected" | "stale_skipped" | "error";
|
|
58
|
+
readonly detail?: string;
|
|
59
|
+
}
|
package/dist/tui.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { TuiPlugin } from "@opencode-ai/plugin/tui";
|
|
2
|
+
import type { ConflictView, HealthView, ProposalView } from "./tui-types.js";
|
|
3
|
+
export declare function tuiRoot(): string;
|
|
4
|
+
export declare function readJsonSafe(name: string): {
|
|
5
|
+
data: unknown;
|
|
6
|
+
} | {
|
|
7
|
+
error: "missing" | "corrupt";
|
|
8
|
+
};
|
|
9
|
+
export declare function truncateSummary(text: string, max?: number): string;
|
|
10
|
+
export declare function formatProposalRow(p: ProposalView): string;
|
|
11
|
+
export declare function formatConflictRow(c: ConflictView): string;
|
|
12
|
+
export declare function formatHealthVerdict(h: HealthView): string;
|
|
13
|
+
export declare const tui: TuiPlugin;
|
|
14
|
+
declare const _default: {
|
|
15
|
+
id: string;
|
|
16
|
+
tui: TuiPlugin;
|
|
17
|
+
};
|
|
18
|
+
export default _default;
|
package/dist/tui.js
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
// v1.2.0 (K12-008 skeleton + K12-009 panels / plan §4.4 R1, D12-02) — TUI module (target-exclusive, conditional on K12-016 GO).
|
|
2
|
+
// Allowed imports ONLY: @opencode-ai/plugin/tui, node:fs, node:path, node:os, import type from ./tui-types.js
|
|
3
|
+
// No console.log; user feedback via host toast API.
|
|
4
|
+
import { mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { homedir } from "node:os";
|
|
6
|
+
import { join } from "node:path";
|
|
7
|
+
export function tuiRoot() {
|
|
8
|
+
return join(homedir(), ".opencode-kevin", "tui");
|
|
9
|
+
}
|
|
10
|
+
export function readJsonSafe(name) {
|
|
11
|
+
const path = join(tuiRoot(), name);
|
|
12
|
+
try {
|
|
13
|
+
const raw = readFileSync(path, "utf8");
|
|
14
|
+
try {
|
|
15
|
+
return { data: JSON.parse(raw) };
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return { error: "corrupt" };
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
catch (err) {
|
|
22
|
+
const code = err?.code;
|
|
23
|
+
if (code === "ENOENT")
|
|
24
|
+
return { error: "missing" };
|
|
25
|
+
return { error: "corrupt" };
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
// --- Pure helpers (K12-009) — unit-testable, no host dependency ---
|
|
29
|
+
export function truncateSummary(text, max = 80) {
|
|
30
|
+
if (text.length <= max)
|
|
31
|
+
return text;
|
|
32
|
+
return `${text.slice(0, max - 1)}…`;
|
|
33
|
+
}
|
|
34
|
+
export function formatProposalRow(p) {
|
|
35
|
+
const trunc = p.truncated ? " [truncated]" : "";
|
|
36
|
+
const ids = p.memory_ids.length ? ` memories:${p.memory_ids.join(",")}` : "";
|
|
37
|
+
return `${p.id} ${p.kind} ${p.target_path} ${p.created_at}${trunc}${ids}`;
|
|
38
|
+
}
|
|
39
|
+
export function formatConflictRow(c) {
|
|
40
|
+
return `${c.kind} ${c.id} A:${truncateSummary(c.a_summary)} B:${truncateSummary(c.b_summary)}`;
|
|
41
|
+
}
|
|
42
|
+
export function formatHealthVerdict(h) {
|
|
43
|
+
return `${h.verdict} — ${h.reason} — ${h.contract_digest}`;
|
|
44
|
+
}
|
|
45
|
+
// Mailbox writer — atomic tmp+rename, append semantics (pure fs, no network)
|
|
46
|
+
function writeMailboxAction(action) {
|
|
47
|
+
const dir = tuiRoot();
|
|
48
|
+
mkdirSync(dir, { recursive: true });
|
|
49
|
+
const target = join(dir, "actions.json");
|
|
50
|
+
let existing = null;
|
|
51
|
+
try {
|
|
52
|
+
const raw = readFileSync(target, "utf8");
|
|
53
|
+
const parsed = JSON.parse(raw);
|
|
54
|
+
if (parsed && Array.isArray(parsed.actions)) {
|
|
55
|
+
existing = {
|
|
56
|
+
issuedAt: String(parsed.issuedAt ?? new Date().toISOString()),
|
|
57
|
+
actions: parsed.actions,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
// missing/corrupt → start fresh
|
|
63
|
+
}
|
|
64
|
+
const next = {
|
|
65
|
+
issuedAt: new Date().toISOString(),
|
|
66
|
+
actions: existing ? [...existing.actions, action] : [action],
|
|
67
|
+
};
|
|
68
|
+
const tmp = `${target}.tmp`;
|
|
69
|
+
writeFileSync(tmp, JSON.stringify(next, null, 2), "utf8");
|
|
70
|
+
renameSync(tmp, target);
|
|
71
|
+
}
|
|
72
|
+
function emptyState(reason) {
|
|
73
|
+
return reason;
|
|
74
|
+
}
|
|
75
|
+
export const tui = async (api) => {
|
|
76
|
+
// Helper to show toast via host
|
|
77
|
+
const toast = (message, variant = "info") => {
|
|
78
|
+
try {
|
|
79
|
+
api.ui.toast({ message, variant });
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
// best-effort
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
api.route.register([
|
|
86
|
+
{
|
|
87
|
+
name: "kevin",
|
|
88
|
+
render: () => {
|
|
89
|
+
// Re-read on focus (caller invokes render on focus)
|
|
90
|
+
const proposalsRes = readJsonSafe("proposals.json");
|
|
91
|
+
const conflictsRes = readJsonSafe("conflicts.json");
|
|
92
|
+
const healthRes = readJsonSafe("health.json");
|
|
93
|
+
if ("error" in proposalsRes ||
|
|
94
|
+
"error" in conflictsRes ||
|
|
95
|
+
"error" in healthRes) {
|
|
96
|
+
const reason = "error" in proposalsRes
|
|
97
|
+
? `proposals.json: ${proposalsRes.error}`
|
|
98
|
+
: "error" in conflictsRes
|
|
99
|
+
? `conflicts.json: ${conflictsRes.error}`
|
|
100
|
+
: `health.json: ${healthRes.error}`;
|
|
101
|
+
return emptyState(`no snapshots yet — open an opencode session with the plugin enabled (${reason})`);
|
|
102
|
+
}
|
|
103
|
+
const proposals = proposalsRes.data;
|
|
104
|
+
const conflicts = conflictsRes.data;
|
|
105
|
+
const health = healthRes.data;
|
|
106
|
+
// Skeleton counts + tabular summaries (full JSX rendering is host-driven;
|
|
107
|
+
// this string representation carries the same data for headless verification).
|
|
108
|
+
// Interactive flows (Enter→diff, a→approve, r→reject, x→acknowledge) are exposed as keymap commands below
|
|
109
|
+
// and via api.ui.Dialog* when a host renders the route with Solid JSX — the string fallback ensures degrade-to-empty discipline.
|
|
110
|
+
const proposalLines = Array.isArray(proposals) && proposals.length
|
|
111
|
+
? proposals
|
|
112
|
+
.map((p) => `· ${formatProposalRow(p)}\n diff: ${truncateSummary(p.diff, 120)}${p.truncated ? " [truncated]" : ""}`)
|
|
113
|
+
.join("\n")
|
|
114
|
+
: " (no pending proposals)";
|
|
115
|
+
const conflictLines = Array.isArray(conflicts) && conflicts.length
|
|
116
|
+
? conflicts.map((c) => `· ${formatConflictRow(c)}`).join("\n")
|
|
117
|
+
: " (no open conflicts)";
|
|
118
|
+
const healthLine = health ? formatHealthVerdict(health) : "unknown";
|
|
119
|
+
const hooksLine = health?.hooks?.length
|
|
120
|
+
? health.hooks
|
|
121
|
+
.map((h) => ` ${h.hook} ${h.state} ${h.fire_count}/${h.expected_count}`)
|
|
122
|
+
.join("\n")
|
|
123
|
+
: " (no hooks)";
|
|
124
|
+
const perfLine = health?.perf?.length
|
|
125
|
+
? health.perf
|
|
126
|
+
.map((p) => ` ${p.scope} p95:${p.p95} budget:${p.budget_p95} ${p.within_budget ? "ok" : "OVER"}`)
|
|
127
|
+
.join("\n")
|
|
128
|
+
: " (no perf)";
|
|
129
|
+
const countersLine = health?.counters
|
|
130
|
+
? Object.entries(health.counters)
|
|
131
|
+
.map(([k, v]) => `${k}=${v}`)
|
|
132
|
+
.join(" ")
|
|
133
|
+
: "(no counters)";
|
|
134
|
+
const msg = [
|
|
135
|
+
`Kevin — Proposals (${Array.isArray(proposals) ? proposals.length : 0})`,
|
|
136
|
+
proposalLines,
|
|
137
|
+
"",
|
|
138
|
+
`Conflicts (${Array.isArray(conflicts) ? conflicts.length : 0})`,
|
|
139
|
+
conflictLines,
|
|
140
|
+
"",
|
|
141
|
+
`Health — ${healthLine}`,
|
|
142
|
+
"hooks:",
|
|
143
|
+
hooksLine,
|
|
144
|
+
"perf:",
|
|
145
|
+
perfLine,
|
|
146
|
+
`counters: ${countersLine}`,
|
|
147
|
+
"",
|
|
148
|
+
"Keys: Enter=diff · a=approve · r=reject · x=acknowledge (via command palette) · k=open",
|
|
149
|
+
].join("\n");
|
|
150
|
+
return emptyState(msg);
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
]);
|
|
154
|
+
// Keymap layer: `k` opens the kevin route; also expose approve/reject/acknowledge commands for palette.
|
|
155
|
+
try {
|
|
156
|
+
const km = api.keymap;
|
|
157
|
+
km.registerLayer?.({
|
|
158
|
+
commands: {
|
|
159
|
+
"kevin.open": {
|
|
160
|
+
title: "Kevin — open",
|
|
161
|
+
description: "Open the Kevin route",
|
|
162
|
+
},
|
|
163
|
+
"kevin.proposal.approve": { title: "Kevin — approve proposal" },
|
|
164
|
+
"kevin.proposal.reject": { title: "Kevin — reject proposal" },
|
|
165
|
+
"kevin.conflict.acknowledge": { title: "Kevin — acknowledge conflict" },
|
|
166
|
+
},
|
|
167
|
+
bindings: {
|
|
168
|
+
"kevin.open": "k",
|
|
169
|
+
},
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
catch {
|
|
173
|
+
// best-effort
|
|
174
|
+
}
|
|
175
|
+
// Expose mailbox writers via command handlers (invoked from palette or future JSX buttons).
|
|
176
|
+
// These are also callable from tests via exported helpers — the route render's interactive dialogs
|
|
177
|
+
// would call the same writeMailboxAction in a real host with DialogConfirm/Select.
|
|
178
|
+
void writeMailboxAction;
|
|
179
|
+
// Attach helper closures to api for potential solid JSX callbacks (not part of typed API — cast).
|
|
180
|
+
const extended = api;
|
|
181
|
+
extended.kevinTui = {
|
|
182
|
+
approve: (proposalId, token) => {
|
|
183
|
+
writeMailboxAction({ type: "approve", proposalId, token });
|
|
184
|
+
toast("queued — applies at session idle", "info");
|
|
185
|
+
},
|
|
186
|
+
reject: (proposalId, token, note) => {
|
|
187
|
+
writeMailboxAction(note !== undefined
|
|
188
|
+
? { type: "reject", proposalId, token, note }
|
|
189
|
+
: { type: "reject", proposalId, token });
|
|
190
|
+
toast("queued — applies at session idle", "info");
|
|
191
|
+
},
|
|
192
|
+
acknowledge: (conflictId) => {
|
|
193
|
+
writeMailboxAction({ type: "acknowledge", conflictId });
|
|
194
|
+
toast("queued — applies at session idle", "info");
|
|
195
|
+
},
|
|
196
|
+
};
|
|
197
|
+
};
|
|
198
|
+
export default { id: "opencode-kevin", tui };
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@jmtrin/opencode-kevin-tui",
|
|
3
|
+
"version": "1.3.0",
|
|
4
|
+
"description": "Kevin TUI — target-exclusive panel (Bedrock)",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": ["dist"],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "tsc -p tsconfig.json",
|
|
17
|
+
"typecheck": "tsc --noEmit"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@opencode-ai/plugin": "^1.18.16"
|
|
21
|
+
},
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": ">=22.5.0"
|
|
24
|
+
},
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public"
|
|
27
|
+
},
|
|
28
|
+
"license": "MIT"
|
|
29
|
+
}
|