@opencode-cockpit/protocol 0.1.4 → 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/dist/build.js +32 -0
- package/dist/contract.js +6 -0
- package/dist/daemon.js +51 -0
- package/dist/framing.js +27 -0
- package/dist/index.js +19 -0
- package/dist/paths.js +16 -0
- package/dist/rpc.js +53 -0
- package/dist/shell/common.js +13 -0
- package/dist/shell/contract.js +55 -0
- package/dist/shell/index.js +6 -0
- package/dist/shell/info.js +33 -0
- package/dist/shell/params.js +132 -0
- package/dist/shell/watch.js +37 -0
- package/package.json +11 -4
- package/types/build.d.ts +6 -0
- package/{src/contract.ts → types/contract.d.ts} +10 -17
- package/types/daemon.d.ts +80 -0
- package/types/framing.d.ts +10 -0
- package/types/index.d.ts +754 -0
- package/types/paths.d.ts +12 -0
- package/types/rpc.d.ts +63 -0
- package/types/shell/common.d.ts +16 -0
- package/types/shell/contract.d.ts +698 -0
- package/types/shell/index.d.ts +6 -0
- package/types/shell/info.d.ts +48 -0
- package/types/shell/params.d.ts +215 -0
- package/types/shell/watch.d.ts +46 -0
- package/src/build.ts +0 -32
- package/src/daemon.ts +0 -48
- package/src/framing.ts +0 -26
- package/src/index.ts +0 -21
- package/src/paths.ts +0 -25
- package/src/rpc.ts +0 -96
- package/src/shell.ts +0 -187
package/src/shell.ts
DELETED
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
import { z } from "zod"
|
|
2
|
-
import { method } from "./contract.ts"
|
|
3
|
-
|
|
4
|
-
export const ShellId = z.string().regex(/^sh_[a-z2-7]{8}$/, "expected sh_ followed by 8 base32 chars")
|
|
5
|
-
|
|
6
|
-
export const Owner = z.object({
|
|
7
|
-
/** Absolute project directory the shell belongs to. */
|
|
8
|
-
project: z.string().min(1),
|
|
9
|
-
/** OpenCode session that started it, when started by an agent. */
|
|
10
|
-
session: z.string().min(1).optional(),
|
|
11
|
-
/** Opaque id of the client instance that started it; used to route notifications to one place. */
|
|
12
|
-
instance: z.string().min(1).optional(),
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
export const ShellStatus = z.enum(["running", "exited", "killed", "failed"])
|
|
16
|
-
|
|
17
|
-
export const ShellInfo = z.object({
|
|
18
|
-
id: ShellId,
|
|
19
|
-
title: z.string(),
|
|
20
|
-
command: z.string(),
|
|
21
|
-
args: z.array(z.string()),
|
|
22
|
-
cwd: z.string(),
|
|
23
|
-
owner: Owner,
|
|
24
|
-
status: ShellStatus,
|
|
25
|
-
run: z.number().int().positive(),
|
|
26
|
-
pid: z.number().int().optional(),
|
|
27
|
-
exitCode: z.number().int().optional(),
|
|
28
|
-
signal: z.string().optional(),
|
|
29
|
-
error: z.string().optional(),
|
|
30
|
-
/** Set when a run ends: the last error-looking line of the run, else its last line. */
|
|
31
|
-
summary: z.string().optional(),
|
|
32
|
-
startedAt: z.number(),
|
|
33
|
-
endedAt: z.number().optional(),
|
|
34
|
-
cols: z.number().int(),
|
|
35
|
-
rows: z.number().int(),
|
|
36
|
-
lines: z.object({ first: z.number().int(), last: z.number().int() }),
|
|
37
|
-
/** Absolute raw byte offset written so far (for UI attach/replay). */
|
|
38
|
-
bytes: z.number().int(),
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
const Dimension = z.number().int().min(2).max(1000)
|
|
42
|
-
|
|
43
|
-
export const StartParams = z.object({
|
|
44
|
-
command: z.string().min(1),
|
|
45
|
-
args: z.array(z.string()).default([]),
|
|
46
|
-
cwd: z.string().min(1),
|
|
47
|
-
env: z.record(z.string(), z.string()).optional(),
|
|
48
|
-
title: z.string().min(1).max(200).optional(),
|
|
49
|
-
cols: Dimension.default(120),
|
|
50
|
-
rows: Dimension.default(32),
|
|
51
|
-
owner: Owner,
|
|
52
|
-
/** Stop the shell automatically after this long. */
|
|
53
|
-
timeoutMs: z.number().int().positive().optional(),
|
|
54
|
-
/**
|
|
55
|
-
* Restart a finished shell with the same command, args, cwd, project and session instead of
|
|
56
|
-
* creating a new one. Repeated runs then share one id and one log.
|
|
57
|
-
*/
|
|
58
|
-
reuse: z.boolean().default(false),
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
export const ClearParams = z
|
|
62
|
-
.object({
|
|
63
|
-
owner: Owner.partial().optional(),
|
|
64
|
-
/** Only remove shells that finished at least this long ago. */
|
|
65
|
-
finishedBeforeMs: z.number().int().min(0).optional(),
|
|
66
|
-
})
|
|
67
|
-
.default({})
|
|
68
|
-
|
|
69
|
-
export const ListParams = z
|
|
70
|
-
.object({
|
|
71
|
-
owner: Owner.partial().optional(),
|
|
72
|
-
includeExited: z.boolean().default(true),
|
|
73
|
-
})
|
|
74
|
-
.default({ includeExited: true })
|
|
75
|
-
|
|
76
|
-
export const IdParams = z.object({ id: ShellId })
|
|
77
|
-
|
|
78
|
-
export const LogLine = z.object({ n: z.number().int(), text: z.string() })
|
|
79
|
-
|
|
80
|
-
export const ReadParams = z.object({
|
|
81
|
-
id: ShellId,
|
|
82
|
-
/** Cursor: return only lines numbered strictly greater than this. */
|
|
83
|
-
after: z.number().int().min(0).optional(),
|
|
84
|
-
/** When no cursor is given, return the last N lines. */
|
|
85
|
-
tail: z.number().int().positive().max(10_000).default(100),
|
|
86
|
-
limit: z.number().int().positive().max(10_000).default(500),
|
|
87
|
-
grep: z.string().min(1).max(500).optional(),
|
|
88
|
-
ignoreCase: z.boolean().default(false),
|
|
89
|
-
})
|
|
90
|
-
|
|
91
|
-
export const ReadResult = z.object({
|
|
92
|
-
lines: z.array(LogLine),
|
|
93
|
-
firstLine: z.number().int(),
|
|
94
|
-
lastLine: z.number().int(),
|
|
95
|
-
/** Pass as `after` to continue. */
|
|
96
|
-
nextCursor: z.number().int(),
|
|
97
|
-
/** True when requested lines were already evicted. */
|
|
98
|
-
truncated: z.boolean(),
|
|
99
|
-
/** True when more lines exist beyond `limit`. */
|
|
100
|
-
hasMore: z.boolean(),
|
|
101
|
-
status: ShellStatus,
|
|
102
|
-
})
|
|
103
|
-
|
|
104
|
-
export const ScreenResult = z.object({
|
|
105
|
-
text: z.string(),
|
|
106
|
-
cols: z.number().int(),
|
|
107
|
-
rows: z.number().int(),
|
|
108
|
-
cursor: z.object({ x: z.number().int(), y: z.number().int() }),
|
|
109
|
-
})
|
|
110
|
-
|
|
111
|
-
export const WriteParams = z.object({ id: ShellId, data: z.string().max(1_000_000) })
|
|
112
|
-
|
|
113
|
-
export const ResizeParams = z.object({ id: ShellId, cols: Dimension, rows: Dimension })
|
|
114
|
-
|
|
115
|
-
export const WaitUntil = z
|
|
116
|
-
.object({
|
|
117
|
-
pattern: z.string().min(1).max(500).optional(),
|
|
118
|
-
ignoreCase: z.boolean().optional(),
|
|
119
|
-
exit: z.boolean().optional(),
|
|
120
|
-
idleMs: z.number().int().positive().optional(),
|
|
121
|
-
port: z.number().int().min(1).max(65_535).optional(),
|
|
122
|
-
host: z.string().optional(),
|
|
123
|
-
})
|
|
124
|
-
.refine((u) => u.pattern !== undefined || u.exit || u.idleMs !== undefined || u.port !== undefined, {
|
|
125
|
-
message: "until needs at least one of pattern, exit, idleMs, port",
|
|
126
|
-
})
|
|
127
|
-
|
|
128
|
-
export const WaitParams = z.object({
|
|
129
|
-
id: ShellId,
|
|
130
|
-
until: WaitUntil,
|
|
131
|
-
timeoutMs: z.number().int().positive().max(3_600_000),
|
|
132
|
-
/** Only consider lines after this cursor for `pattern`. Defaults to the current last line. */
|
|
133
|
-
after: z.number().int().min(0).optional(),
|
|
134
|
-
})
|
|
135
|
-
|
|
136
|
-
export const WaitReason = z.enum(["pattern", "exit", "idle", "port", "timeout"])
|
|
137
|
-
|
|
138
|
-
export const WaitResult = z.object({
|
|
139
|
-
reason: WaitReason,
|
|
140
|
-
match: LogLine.optional(),
|
|
141
|
-
info: ShellInfo,
|
|
142
|
-
})
|
|
143
|
-
|
|
144
|
-
export const StopParams = z.object({
|
|
145
|
-
id: ShellId,
|
|
146
|
-
signal: z.enum(["SIGTERM", "SIGINT", "SIGHUP", "SIGKILL"]).default("SIGTERM"),
|
|
147
|
-
graceMs: z.number().int().min(0).max(60_000).default(3000),
|
|
148
|
-
})
|
|
149
|
-
|
|
150
|
-
export const AttachParams = z.object({ id: ShellId, fromOffset: z.number().int().min(0).optional() })
|
|
151
|
-
|
|
152
|
-
export const shellContract = {
|
|
153
|
-
"shell.start": method(StartParams, ShellInfo),
|
|
154
|
-
"shell.list": method(ListParams, z.array(ShellInfo)),
|
|
155
|
-
"shell.get": method(IdParams, ShellInfo),
|
|
156
|
-
"shell.read": method(ReadParams, ReadResult),
|
|
157
|
-
"shell.screen": method(IdParams, ScreenResult),
|
|
158
|
-
"shell.write": method(WriteParams, z.object({ bytes: z.number().int() })),
|
|
159
|
-
"shell.resize": method(ResizeParams, z.object({})),
|
|
160
|
-
"shell.wait": method(WaitParams, WaitResult),
|
|
161
|
-
"shell.stop": method(StopParams, ShellInfo),
|
|
162
|
-
"shell.restart": method(IdParams, ShellInfo),
|
|
163
|
-
"shell.remove": method(IdParams, z.object({})),
|
|
164
|
-
"shell.clear": method(ClearParams, z.object({ removed: z.array(ShellId) })),
|
|
165
|
-
"shell.attach": method(AttachParams, z.object({ offset: z.number().int(), replay: z.string() })),
|
|
166
|
-
"shell.detach": method(IdParams, z.object({})),
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
export const shellEvents = {
|
|
170
|
-
"shell.started": ShellInfo,
|
|
171
|
-
"shell.exited": ShellInfo,
|
|
172
|
-
"shell.removed": z.object({ id: ShellId }),
|
|
173
|
-
"shell.output": z.object({ id: ShellId, offset: z.number().int(), data: z.string() }),
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
export type Owner = z.output<typeof Owner>
|
|
177
|
-
export type ShellStatus = z.output<typeof ShellStatus>
|
|
178
|
-
export type ShellInfo = z.output<typeof ShellInfo>
|
|
179
|
-
export type StartParams = z.output<typeof StartParams>
|
|
180
|
-
export type ReadParams = z.output<typeof ReadParams>
|
|
181
|
-
export type ReadResult = z.output<typeof ReadResult>
|
|
182
|
-
export type ScreenResult = z.output<typeof ScreenResult>
|
|
183
|
-
export type WaitParams = z.output<typeof WaitParams>
|
|
184
|
-
export type WaitResult = z.output<typeof WaitResult>
|
|
185
|
-
export type WaitReason = z.output<typeof WaitReason>
|
|
186
|
-
export type StopParams = z.output<typeof StopParams>
|
|
187
|
-
export type LogLine = z.output<typeof LogLine>
|