@mortz.prk/opencode-auto-mode 1.0.0 → 1.0.2

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/src/rpc.ts ADDED
@@ -0,0 +1,117 @@
1
+ import { Rpc } from "@opencode/plugin/rpc";
2
+
3
+ /** Bounded status snapshot served to the TUI, the desktop app and external clients. */
4
+ export interface AutoModeStatus {
5
+ enabled: boolean;
6
+ configError?: string;
7
+ classifiers: string[];
8
+ reviewTimeoutMs: number;
9
+ reviewing: { sessionID: string; reviewID: string; startedAt: number }[];
10
+ recent: AutoModeDecision[];
11
+ }
12
+
13
+ export interface AutoModeDecision {
14
+ reviewID: string;
15
+ sessionID: string;
16
+ action: string;
17
+ decision: string;
18
+ stage: string;
19
+ reason: string;
20
+ durationMs: number;
21
+ at: number;
22
+ errorKind?: string;
23
+ }
24
+
25
+ const statusSchema = {
26
+ type: "object",
27
+ properties: {
28
+ enabled: { type: "boolean" },
29
+ configError: { type: "string" },
30
+ classifiers: { type: "array", items: { type: "string" } },
31
+ reviewTimeoutMs: { type: "number" },
32
+ reviewing: {
33
+ type: "array",
34
+ items: {
35
+ type: "object",
36
+ properties: {
37
+ sessionID: { type: "string" },
38
+ reviewID: { type: "string" },
39
+ startedAt: { type: "number" },
40
+ },
41
+ required: ["sessionID", "reviewID", "startedAt"],
42
+ additionalProperties: false,
43
+ },
44
+ },
45
+ recent: {
46
+ type: "array",
47
+ items: {
48
+ type: "object",
49
+ properties: {
50
+ reviewID: { type: "string" },
51
+ sessionID: { type: "string" },
52
+ action: { type: "string" },
53
+ decision: { type: "string" },
54
+ stage: { type: "string" },
55
+ reason: { type: "string" },
56
+ durationMs: { type: "number" },
57
+ at: { type: "number" },
58
+ errorKind: { type: "string" },
59
+ },
60
+ required: ["reviewID", "sessionID", "action", "decision", "stage", "reason", "durationMs", "at"],
61
+ additionalProperties: false,
62
+ },
63
+ },
64
+ },
65
+ required: ["enabled", "classifiers", "reviewTimeoutMs", "reviewing", "recent"],
66
+ additionalProperties: false,
67
+ } as const;
68
+
69
+ const decisionSchema = {
70
+ type: "object",
71
+ properties: {
72
+ reviewID: { type: "string" },
73
+ sessionID: { type: "string" },
74
+ action: { type: "string" },
75
+ decision: { type: "string" },
76
+ stage: { type: "string" },
77
+ reason: { type: "string" },
78
+ durationMs: { type: "number" },
79
+ at: { type: "number" },
80
+ errorKind: { type: "string" },
81
+ },
82
+ required: ["reviewID", "sessionID", "action", "decision", "stage", "reason", "durationMs", "at"],
83
+ additionalProperties: false,
84
+ } as const;
85
+
86
+ /**
87
+ * Contract between the server part and its clients. Clients read a snapshot on
88
+ * connect and follow `decision` events afterwards; events are live-only, so the
89
+ * snapshot is the source of truth after a reconnect.
90
+ */
91
+ export const AutoMode = Rpc.define({
92
+ id: "opencode-auto-mode",
93
+ methods: {
94
+ status: {
95
+ input: {
96
+ type: "object",
97
+ properties: { sessionID: { type: "string" } },
98
+ additionalProperties: false,
99
+ },
100
+ output: statusSchema,
101
+ },
102
+ decisions: {
103
+ input: {
104
+ type: "object",
105
+ properties: {
106
+ sessionID: { type: "string" },
107
+ limit: { type: "number" },
108
+ },
109
+ additionalProperties: false,
110
+ },
111
+ output: { type: "array", items: decisionSchema },
112
+ },
113
+ },
114
+ events: {
115
+ decision: { schema: decisionSchema },
116
+ },
117
+ });