@vibest/schema 0.0.1-beta.0 → 0.0.1-beta.20
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/package.json +1 -1
- package/src/error.ts +1 -0
- package/src/event-fact.ts +14 -0
- package/src/event.ts +94 -95
- package/src/id.ts +6 -3
- package/src/layout.ts +7 -0
- package/src/machine.ts +9 -1
- package/src/model.ts +1 -0
- package/src/plugin.ts +11 -0
- package/src/project.ts +10 -0
- package/src/remove.ts +1 -0
- package/src/session.ts +91 -14
- package/src/subscription.ts +3 -0
- package/src/version.ts +1 -0
package/package.json
CHANGED
package/src/error.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const messageOf = (cause: unknown) => (cause instanceof Error ? cause.message : String(cause))
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Catalog, Fact, Row } from "./event.ts"
|
|
2
|
+
|
|
3
|
+
type Defined = (typeof Catalog)[keyof typeof Catalog]
|
|
4
|
+
|
|
5
|
+
export const factOf = (row: Row, definition: Defined, data: Defined["data"]["Type"]): Fact =>
|
|
6
|
+
({
|
|
7
|
+
aggregate: row.aggregate,
|
|
8
|
+
seq: row.seq,
|
|
9
|
+
at: row.at,
|
|
10
|
+
type: definition.type,
|
|
11
|
+
...(definition.aggregate === "project" && { projectId: row.aggregate }),
|
|
12
|
+
...(definition.aggregate === "session" && { sessionId: row.aggregate }),
|
|
13
|
+
data,
|
|
14
|
+
}) as Fact
|
package/src/event.ts
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import { Effect, Schema } from "effect"
|
|
2
2
|
|
|
3
|
+
import { factOf } from "./event-fact.ts"
|
|
3
4
|
import { Routing } from "./plugin.ts"
|
|
4
5
|
|
|
5
|
-
export type
|
|
6
|
+
export type Aggregate = "project" | "session" | "ledger"
|
|
6
7
|
|
|
7
8
|
export interface Definition<T extends string = string, S extends Schema.Top = Schema.Top> {
|
|
8
9
|
readonly type: T
|
|
9
|
-
readonly
|
|
10
|
+
readonly aggregate: Aggregate
|
|
10
11
|
readonly data: S
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
export const fact = <const T extends string, const F extends Schema.Struct.Fields>(
|
|
14
15
|
type: T,
|
|
15
|
-
|
|
16
|
+
aggregate: Aggregate,
|
|
16
17
|
fields: F,
|
|
17
|
-
): Definition<T, Schema.Struct<F>> => ({ type,
|
|
18
|
+
): Definition<T, Schema.Struct<F>> => ({ type, aggregate, data: Schema.Struct(fields) })
|
|
18
19
|
|
|
19
20
|
const Text = Schema.NonEmptyString
|
|
20
21
|
const optional = <S extends Schema.Top>(schema: S) => Schema.optionalKey(schema)
|
|
@@ -28,21 +29,24 @@ export const ProjectCreated = fact("project.created", "project", {
|
|
|
28
29
|
directory: optional(Text),
|
|
29
30
|
repositories: Repositories,
|
|
30
31
|
})
|
|
32
|
+
|
|
31
33
|
export const ProjectMoved = fact("project.moved", "project", { from: Text, to: Text, repositories: Repositories })
|
|
34
|
+
|
|
32
35
|
export const ProjectRepositoriesChanged = fact("project.repositories_changed", "project", {
|
|
33
36
|
repositories: Repositories,
|
|
34
37
|
})
|
|
38
|
+
|
|
35
39
|
export const ProjectEntryChanged = fact("project.entry_changed", "project", { session: optional(Text) })
|
|
36
40
|
|
|
37
41
|
export const SessionCreated = fact("session.created", "session", {
|
|
38
|
-
|
|
42
|
+
project: Text,
|
|
43
|
+
agent: Text,
|
|
39
44
|
name: Text,
|
|
40
45
|
directory: Schema.String,
|
|
41
46
|
parent: optional(Text),
|
|
42
|
-
|
|
43
|
-
archiveOnCompletion: Schema.Boolean,
|
|
44
|
-
origin: optional(Schema.Struct({ peer: Text, project: Text, parent: optional(Text), reportTo: optional(Text) })),
|
|
47
|
+
origin: optional(Schema.Struct({ peer: Text, project: Text, session: optional(Text) })),
|
|
45
48
|
})
|
|
49
|
+
|
|
46
50
|
export const SessionRenamed = fact("session.renamed", "session", { name: Text })
|
|
47
51
|
export const SessionDirectoryChanged = fact("session.directory_changed", "session", { directory: Text })
|
|
48
52
|
export const SessionEnded = fact("session.ended", "session", { reason: Schema.Literals(["archived", "replaced"]) })
|
|
@@ -57,14 +61,18 @@ export const ProcessStarted = fact("process.started", "session", {
|
|
|
57
61
|
terminal: optional(Text),
|
|
58
62
|
pid: optional(Pid),
|
|
59
63
|
})
|
|
64
|
+
|
|
60
65
|
export const ProcessPlaced = fact("process.placed", "session", { process: Seq, terminal: Text, pid: optional(Pid) })
|
|
66
|
+
|
|
61
67
|
export const ProcessReady = fact("process.ready", "session", {
|
|
62
68
|
process: Seq,
|
|
63
69
|
pid: optional(Pid),
|
|
64
70
|
integration: optional(Schema.Struct({ version: Text, protocol: Schema.Int })),
|
|
65
71
|
})
|
|
72
|
+
|
|
66
73
|
export const ProcessPid = fact("process.pid", "session", { process: Seq, pid: Pid })
|
|
67
74
|
export const ProcessConversation = fact("process.conversation", "session", { process: Seq, conversation: Text })
|
|
75
|
+
|
|
68
76
|
export const ProcessEndReason = Schema.Literals([
|
|
69
77
|
"exited",
|
|
70
78
|
"limited",
|
|
@@ -74,100 +82,103 @@ export const ProcessEndReason = Schema.Literals([
|
|
|
74
82
|
"launch_failed",
|
|
75
83
|
"superseded",
|
|
76
84
|
])
|
|
85
|
+
|
|
77
86
|
export type ProcessEndReason = typeof ProcessEndReason.Type
|
|
87
|
+
|
|
78
88
|
export const ProcessEnded = fact("process.ended", "session", { process: Seq, reason: ProcessEndReason })
|
|
79
89
|
|
|
80
|
-
export const
|
|
81
|
-
export const TurnReported = fact("turn.reported", "session", {
|
|
90
|
+
export const ExecutionStarted = fact("execution.started", "session", {
|
|
82
91
|
process: optional(Seq),
|
|
83
|
-
|
|
84
|
-
text: Schema.String,
|
|
85
|
-
error: optional(Text),
|
|
86
|
-
conversation: optional(Text),
|
|
87
|
-
interrupted: optional(Schema.Literal(true)),
|
|
92
|
+
typed: optional(Text),
|
|
88
93
|
})
|
|
89
|
-
|
|
90
|
-
export const
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
94
|
+
|
|
95
|
+
export const ExecutionAccepted = fact("execution.accepted", "session", { execution: Seq })
|
|
96
|
+
export const ExecutionOutcome = Schema.Literals(["completed", "failed", "interrupted", "lost", "not_started"])
|
|
97
|
+
|
|
98
|
+
export const ExecutionEnded = fact("execution.ended", "session", {
|
|
99
|
+
execution: Seq,
|
|
100
|
+
outcome: ExecutionOutcome,
|
|
101
|
+
failure: optional(Schema.Struct({ message: Text, kind: optional(Schema.Literal("limit")) })),
|
|
95
102
|
conversation: optional(Text),
|
|
96
103
|
reply: optional(Schema.String),
|
|
97
104
|
})
|
|
98
105
|
|
|
99
|
-
export const InboxKind = Schema.Literals(["task", "send", "
|
|
106
|
+
export const InboxKind = Schema.Literals(["task", "send", "notice"])
|
|
107
|
+
|
|
100
108
|
export type InboxKind = typeof InboxKind.Type
|
|
109
|
+
|
|
101
110
|
export const InboxQueued = fact("inbox.queued", "session", {
|
|
102
111
|
kind: InboxKind,
|
|
103
112
|
recipient: optional(Text),
|
|
104
113
|
sender: optional(Text),
|
|
105
114
|
content: Schema.String,
|
|
106
115
|
status: Schema.Literals(["pending", "delivered", "dropped"]),
|
|
107
|
-
turn: optional(Seq),
|
|
108
116
|
request: optional(Text),
|
|
109
117
|
peerItem: optional(Text),
|
|
110
118
|
})
|
|
119
|
+
|
|
111
120
|
export const InboxMoved = fact("inbox.moved", "session", {
|
|
112
121
|
inbox: Seq,
|
|
113
122
|
to: Schema.Literals(["pending", "delivering", "delivered", "failed", "dropped"]),
|
|
114
|
-
|
|
123
|
+
execution: optional(Seq),
|
|
115
124
|
})
|
|
116
125
|
|
|
117
|
-
export const MachineAdded = fact("machine.added", "
|
|
118
|
-
export const MachineConnected = fact("machine.connected", "
|
|
119
|
-
export const MachineRemoved = fact("machine.removed", "
|
|
126
|
+
export const MachineAdded = fact("machine.added", "ledger", { name: Text, target: Text, vibestd: Text })
|
|
127
|
+
export const MachineConnected = fact("machine.connected", "ledger", { name: Text })
|
|
128
|
+
export const MachineRemoved = fact("machine.removed", "ledger", { name: Text })
|
|
120
129
|
|
|
121
|
-
export const PeerSeen = fact("peer.seen", "
|
|
130
|
+
export const PeerSeen = fact("peer.seen", "ledger", { id: Text, name: Text })
|
|
122
131
|
|
|
123
|
-
export const OutboxQueued = fact("outbox.queued", "
|
|
132
|
+
export const OutboxQueued = fact("outbox.queued", "ledger", {
|
|
124
133
|
id: Text,
|
|
125
134
|
peer: Text,
|
|
126
|
-
|
|
135
|
+
session: Text,
|
|
136
|
+
recipient: optional(Text),
|
|
137
|
+
kind: optional(Schema.Literals(["send", "notice"])),
|
|
127
138
|
content: Schema.String,
|
|
128
139
|
})
|
|
129
|
-
export const OutboxAcked = fact("outbox.acked", "none", { peer: Text, ids: Schema.NonEmptyArray(Text) })
|
|
130
|
-
|
|
131
|
-
const definitions = [
|
|
132
|
-
ProjectCreated,
|
|
133
|
-
ProjectMoved,
|
|
134
|
-
ProjectRepositoriesChanged,
|
|
135
|
-
ProjectEntryChanged,
|
|
136
|
-
SessionCreated,
|
|
137
|
-
SessionRenamed,
|
|
138
|
-
SessionDirectoryChanged,
|
|
139
|
-
SessionEnded,
|
|
140
|
-
ProcessStarted,
|
|
141
|
-
ProcessPlaced,
|
|
142
|
-
ProcessReady,
|
|
143
|
-
ProcessPid,
|
|
144
|
-
ProcessConversation,
|
|
145
|
-
ProcessEnded,
|
|
146
|
-
TurnStarted,
|
|
147
|
-
TurnReported,
|
|
148
|
-
TurnEnded,
|
|
149
|
-
InboxQueued,
|
|
150
|
-
InboxMoved,
|
|
151
|
-
MachineAdded,
|
|
152
|
-
MachineConnected,
|
|
153
|
-
MachineRemoved,
|
|
154
|
-
PeerSeen,
|
|
155
|
-
OutboxQueued,
|
|
156
|
-
OutboxAcked,
|
|
157
|
-
] as const
|
|
158
|
-
|
|
159
|
-
type Defined = (typeof definitions)[number]
|
|
160
140
|
|
|
161
|
-
export
|
|
141
|
+
export const OutboxAcked = fact("outbox.acked", "ledger", { peer: Text, ids: Schema.NonEmptyArray(Text) })
|
|
142
|
+
|
|
143
|
+
export const Catalog = {
|
|
144
|
+
[ProjectCreated.type]: ProjectCreated,
|
|
145
|
+
[ProjectMoved.type]: ProjectMoved,
|
|
146
|
+
[ProjectRepositoriesChanged.type]: ProjectRepositoriesChanged,
|
|
147
|
+
[ProjectEntryChanged.type]: ProjectEntryChanged,
|
|
148
|
+
[SessionCreated.type]: SessionCreated,
|
|
149
|
+
[SessionRenamed.type]: SessionRenamed,
|
|
150
|
+
[SessionDirectoryChanged.type]: SessionDirectoryChanged,
|
|
151
|
+
[SessionEnded.type]: SessionEnded,
|
|
152
|
+
[ProcessStarted.type]: ProcessStarted,
|
|
153
|
+
[ProcessPlaced.type]: ProcessPlaced,
|
|
154
|
+
[ProcessReady.type]: ProcessReady,
|
|
155
|
+
[ProcessPid.type]: ProcessPid,
|
|
156
|
+
[ProcessConversation.type]: ProcessConversation,
|
|
157
|
+
[ProcessEnded.type]: ProcessEnded,
|
|
158
|
+
[ExecutionStarted.type]: ExecutionStarted,
|
|
159
|
+
[ExecutionAccepted.type]: ExecutionAccepted,
|
|
160
|
+
[ExecutionEnded.type]: ExecutionEnded,
|
|
161
|
+
[InboxQueued.type]: InboxQueued,
|
|
162
|
+
[InboxMoved.type]: InboxMoved,
|
|
163
|
+
[MachineAdded.type]: MachineAdded,
|
|
164
|
+
[MachineConnected.type]: MachineConnected,
|
|
165
|
+
[MachineRemoved.type]: MachineRemoved,
|
|
166
|
+
[PeerSeen.type]: PeerSeen,
|
|
167
|
+
[OutboxQueued.type]: OutboxQueued,
|
|
168
|
+
[OutboxAcked.type]: OutboxAcked,
|
|
169
|
+
} as const
|
|
170
|
+
|
|
171
|
+
const byType: ReadonlyMap<string, Defined> = new Map(Object.values(Catalog).map((d) => [d.type, d]))
|
|
172
|
+
|
|
173
|
+
type Defined = (typeof Catalog)[keyof typeof Catalog]
|
|
162
174
|
|
|
163
|
-
export
|
|
164
|
-
readonly [D in Defined as D["type"]]: D
|
|
165
|
-
}
|
|
175
|
+
export type FactType = Defined["type"]
|
|
166
176
|
|
|
167
|
-
export const CATALOG_VERSION =
|
|
177
|
+
export const CATALOG_VERSION = 2
|
|
168
178
|
|
|
169
179
|
export type Fact = {
|
|
170
180
|
readonly [D in Defined as D["type"]]: {
|
|
181
|
+
readonly aggregate: string
|
|
171
182
|
readonly seq: number
|
|
172
183
|
readonly at: number
|
|
173
184
|
readonly type: D["type"]
|
|
@@ -180,15 +191,15 @@ export type Fact = {
|
|
|
180
191
|
export type FactOf<T extends FactType> = Extract<Fact, { readonly type: T }>
|
|
181
192
|
|
|
182
193
|
export interface Row {
|
|
194
|
+
readonly aggregate: string
|
|
183
195
|
readonly seq: number
|
|
184
196
|
readonly at: number
|
|
185
197
|
readonly type: string
|
|
186
|
-
readonly project_id: string | null
|
|
187
|
-
readonly session_id: string | null
|
|
188
198
|
readonly data: string
|
|
189
199
|
}
|
|
190
200
|
|
|
191
201
|
export class UnknownFact extends Schema.TaggedError<UnknownFact>()("UnknownFact", {
|
|
202
|
+
aggregate: Schema.String,
|
|
192
203
|
seq: Schema.Number,
|
|
193
204
|
type: Schema.String,
|
|
194
205
|
message: Schema.String,
|
|
@@ -196,13 +207,6 @@ export class UnknownFact extends Schema.TaggedError<UnknownFact>()("UnknownFact"
|
|
|
196
207
|
|
|
197
208
|
const strict = { onExcessProperty: "error" } as const
|
|
198
209
|
|
|
199
|
-
const envelopeFits = (envelope: Envelope, row: Pick<Row, "project_id" | "session_id">) =>
|
|
200
|
-
envelope === "none"
|
|
201
|
-
? row.project_id === null && row.session_id === null
|
|
202
|
-
: envelope === "project"
|
|
203
|
-
? row.project_id !== null && row.session_id === null
|
|
204
|
-
: row.project_id !== null && row.session_id !== null
|
|
205
|
-
|
|
206
210
|
export const encodeData = <D extends Defined>(
|
|
207
211
|
definition: D,
|
|
208
212
|
data: D["data"]["Type"],
|
|
@@ -212,32 +216,27 @@ export const encodeData = <D extends Defined>(
|
|
|
212
216
|
Effect.tap((json) => Schema.decodeUnknownEffect(definition.data)(JSON.parse(json), strict)),
|
|
213
217
|
)
|
|
214
218
|
|
|
219
|
+
export const isFactOf = <T extends FactType>(type: T, fact: Fact): fact is FactOf<T> => fact.type === type
|
|
220
|
+
|
|
215
221
|
export const decodeRow = (row: Row): Effect.Effect<Fact, UnknownFact> => {
|
|
216
|
-
const
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
+
const where = `event ${row.aggregate} ${row.seq}`
|
|
223
|
+
|
|
224
|
+
const refuse = (message: string) =>
|
|
225
|
+
new UnknownFact({ aggregate: row.aggregate, seq: row.seq, type: row.type, message: `${where}: ${message}` })
|
|
226
|
+
|
|
227
|
+
const definition = byType.get(row.type)
|
|
228
|
+
|
|
229
|
+
if (definition === undefined) return Effect.fail(refuse(`${row.type} is not in the event catalog`))
|
|
230
|
+
|
|
222
231
|
return Effect.try({
|
|
223
|
-
try: () => JSON.parse(row.data)
|
|
224
|
-
catch: (cause) => refuse(
|
|
232
|
+
try: () => JSON.parse(row.data),
|
|
233
|
+
catch: (cause) => refuse(`${row.type} data is not JSON: ${String(cause)}`),
|
|
225
234
|
}).pipe(
|
|
226
235
|
Effect.flatMap((json) =>
|
|
227
236
|
Schema.decodeUnknownEffect(definition.data)(json, strict).pipe(
|
|
228
|
-
Effect.mapError((cause) => refuse(
|
|
237
|
+
Effect.mapError((cause) => refuse(`${row.type} does not decode: ${cause.message}`)),
|
|
229
238
|
),
|
|
230
239
|
),
|
|
231
|
-
Effect.map(
|
|
232
|
-
(data) =>
|
|
233
|
-
({
|
|
234
|
-
seq: row.seq,
|
|
235
|
-
at: row.at,
|
|
236
|
-
type: definition.type,
|
|
237
|
-
...(row.project_id === null ? {} : { projectId: row.project_id }),
|
|
238
|
-
...(row.session_id === null ? {} : { sessionId: row.session_id }),
|
|
239
|
-
data,
|
|
240
|
-
}) as Fact,
|
|
241
|
-
),
|
|
240
|
+
Effect.map((data) => factOf(row, definition, data)),
|
|
242
241
|
)
|
|
243
242
|
}
|
package/src/id.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import { Effect } from "effect"
|
|
1
|
+
import { Effect, Schema } from "effect"
|
|
2
2
|
|
|
3
3
|
export const ID = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/
|
|
4
4
|
|
|
5
|
+
export const RequestId = Schema.String.check(Schema.isUUID(4))
|
|
6
|
+
|
|
5
7
|
export const shortId = (id: string) => id.slice(0, 8)
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
declare const crypto: { readonly randomUUID: () => string }
|
|
10
|
+
|
|
11
|
+
export const randomId = (): string => crypto.randomUUID()
|
|
9
12
|
|
|
10
13
|
export const newId = <E = never, R = never>(
|
|
11
14
|
taken: (short: string) => Effect.Effect<boolean, E, R> = () => Effect.succeed(false),
|
package/src/layout.ts
CHANGED
|
@@ -8,6 +8,7 @@ export class Layout extends Context.Service<
|
|
|
8
8
|
readonly socket: string
|
|
9
9
|
readonly httpSocket: string
|
|
10
10
|
readonly daemonInfo: string
|
|
11
|
+
readonly log: string
|
|
11
12
|
readonly identity: string
|
|
12
13
|
readonly worktrees: string
|
|
13
14
|
readonly projects: string
|
|
@@ -16,17 +17,20 @@ export class Layout extends Context.Service<
|
|
|
16
17
|
readonly allocationWorktree: (repository: string, name: string) => string
|
|
17
18
|
readonly project: (projectId: string) => string
|
|
18
19
|
readonly artifacts: (projectId: string) => string
|
|
20
|
+
readonly sessionFolder: (projectId: string, sessionId: string) => string
|
|
19
21
|
}
|
|
20
22
|
>()("vibest/Layout") {
|
|
21
23
|
static readonly make = (home: string) =>
|
|
22
24
|
Effect.gen(function* () {
|
|
23
25
|
const path = yield* Path.Path
|
|
26
|
+
|
|
24
27
|
return Layout.of({
|
|
25
28
|
home,
|
|
26
29
|
database: path.join(home, "vibest.db"),
|
|
27
30
|
socket: path.join(home, "vibest.sock"),
|
|
28
31
|
httpSocket: path.join(home, "vibest-http.sock"),
|
|
29
32
|
daemonInfo: path.join(home, "vibestd.pid"),
|
|
33
|
+
log: path.join(home, "vibestd.log"),
|
|
30
34
|
identity: path.join(home, "identity.json"),
|
|
31
35
|
worktrees: path.join(home, "worktrees"),
|
|
32
36
|
projects: path.join(home, "projects"),
|
|
@@ -35,6 +39,7 @@ export class Layout extends Context.Service<
|
|
|
35
39
|
allocationWorktree: (repository, name) => path.join(home, "worktrees", repository, name),
|
|
36
40
|
project: (projectId) => path.join(home, "projects", projectId),
|
|
37
41
|
artifacts: (projectId) => path.join(home, "projects", projectId, "artifacts"),
|
|
42
|
+
sessionFolder: (projectId, sessionId) => path.join(home, "projects", projectId, "sessions", sessionId),
|
|
38
43
|
})
|
|
39
44
|
})
|
|
40
45
|
|
|
@@ -42,9 +47,11 @@ export class Layout extends Context.Service<
|
|
|
42
47
|
Layout,
|
|
43
48
|
Effect.gen(function* () {
|
|
44
49
|
const path = yield* Path.Path
|
|
50
|
+
|
|
45
51
|
const home = yield* Config.String("VIBEST_HOME").pipe(
|
|
46
52
|
Config.orElse(() => Config.String("HOME").pipe(Config.map((h) => path.join(h, ".vibest")))),
|
|
47
53
|
)
|
|
54
|
+
|
|
48
55
|
return yield* Layout.make(home)
|
|
49
56
|
}),
|
|
50
57
|
)
|
package/src/machine.ts
CHANGED
|
@@ -9,6 +9,7 @@ export class UnknownMachine extends Schema.TaggedError<UnknownMachine>()("Unknow
|
|
|
9
9
|
override get message() {
|
|
10
10
|
const known =
|
|
11
11
|
this.machines.length === 0 ? "none is added (vibest machine add)" : `machines: ${this.machines.join(", ")}`
|
|
12
|
+
|
|
12
13
|
return `unknown machine ${JSON.stringify(this.machine)}; ${known}`
|
|
13
14
|
}
|
|
14
15
|
}
|
|
@@ -33,6 +34,7 @@ export class AlreadyAdded extends Schema.TaggedError<AlreadyAdded>()("AlreadyAdd
|
|
|
33
34
|
}
|
|
34
35
|
|
|
35
36
|
export const MachineState = Schema.Literals(["connecting", "connected", "unreachable", "different"])
|
|
37
|
+
|
|
36
38
|
export type MachineState = typeof MachineState.Type
|
|
37
39
|
|
|
38
40
|
export const MachineNote = Schema.Struct({
|
|
@@ -40,6 +42,7 @@ export const MachineNote = Schema.Struct({
|
|
|
40
42
|
message: Schema.String,
|
|
41
43
|
fix: Schema.optional(Schema.String),
|
|
42
44
|
})
|
|
45
|
+
|
|
43
46
|
export type MachineNote = typeof MachineNote.Type
|
|
44
47
|
|
|
45
48
|
export const RuntimeThere = Schema.Struct({
|
|
@@ -48,6 +51,7 @@ export const RuntimeThere = Schema.Struct({
|
|
|
48
51
|
reason: Schema.optional(Schema.String),
|
|
49
52
|
link: Schema.optional(Schema.Record(Schema.String, Schema.String)),
|
|
50
53
|
})
|
|
54
|
+
|
|
51
55
|
export type RuntimeThere = typeof RuntimeThere.Type
|
|
52
56
|
|
|
53
57
|
export const RuntimeView = Schema.Struct({
|
|
@@ -60,6 +64,7 @@ export const RuntimeView = Schema.Struct({
|
|
|
60
64
|
note: Schema.optional(Schema.String),
|
|
61
65
|
}),
|
|
62
66
|
})
|
|
67
|
+
|
|
63
68
|
export type RuntimeView = typeof RuntimeView.Type
|
|
64
69
|
|
|
65
70
|
export const MachineInfo = Schema.Struct({
|
|
@@ -76,9 +81,11 @@ export const MachineInfo = Schema.Struct({
|
|
|
76
81
|
runtimesAt: Schema.optional(Schema.Number),
|
|
77
82
|
notes: Schema.optional(Schema.Array(Schema.Struct({ ...MachineNote.fields, at: Schema.Number }))),
|
|
78
83
|
})
|
|
84
|
+
|
|
79
85
|
export type MachineInfo = typeof MachineInfo.Type
|
|
80
86
|
|
|
81
87
|
export const ListedMachine = MachineInfo.mapFields(Struct.pick(["name", "state", "since", "reason"]))
|
|
88
|
+
|
|
82
89
|
export type ListedMachine = typeof ListedMachine.Type
|
|
83
90
|
|
|
84
91
|
export class NoProject extends Schema.TaggedError<NoProject>()("NoProject", { message: Schema.String }) {}
|
|
@@ -99,8 +106,9 @@ export const OutboxItem = Schema.Struct({
|
|
|
99
106
|
id: Schema.String,
|
|
100
107
|
session: Schema.String,
|
|
101
108
|
recipient: Schema.String,
|
|
102
|
-
kind: Schema.Literals(["
|
|
109
|
+
kind: Schema.Literals(["send", "notice"]),
|
|
103
110
|
content: Schema.String,
|
|
104
111
|
cut: Schema.optional(Schema.Boolean),
|
|
105
112
|
})
|
|
113
|
+
|
|
106
114
|
export type OutboxItem = typeof OutboxItem.Type
|
package/src/model.ts
CHANGED
package/src/plugin.ts
CHANGED
|
@@ -11,6 +11,14 @@ export class AgentRefused extends Schema.TaggedError<AgentRefused>()("AgentRefus
|
|
|
11
11
|
|
|
12
12
|
export class HookFailed extends Schema.TaggedError<HookFailed>()("HookFailed", { message: Schema.String }) {}
|
|
13
13
|
|
|
14
|
+
export class PluginsNotActive extends Schema.TaggedError<PluginsNotActive>()("PluginsNotActive", {
|
|
15
|
+
plugins: Schema.Array(Schema.String),
|
|
16
|
+
}) {
|
|
17
|
+
override get message() {
|
|
18
|
+
return this.plugins.length === 0 ? "plugins still loading" : `plugins still loading: ${this.plugins.join(", ")}`
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
14
22
|
export const Change = Schema.Struct({
|
|
15
23
|
field: Schema.String,
|
|
16
24
|
from: Schema.optional(Schema.Unknown),
|
|
@@ -27,12 +35,14 @@ export const TraceEntry = Schema.Struct({
|
|
|
27
35
|
reason: Schema.optional(Schema.String),
|
|
28
36
|
error: Schema.optional(Schema.String),
|
|
29
37
|
})
|
|
38
|
+
|
|
30
39
|
export type TraceEntry = typeof TraceEntry.Type
|
|
31
40
|
|
|
32
41
|
export const Routing = Schema.Struct({
|
|
33
42
|
decidedBy: Schema.Record(Schema.String, Schema.String),
|
|
34
43
|
trace: Schema.Array(TraceEntry),
|
|
35
44
|
})
|
|
45
|
+
|
|
36
46
|
export type Routing = typeof Routing.Type
|
|
37
47
|
|
|
38
48
|
export const PluginInfo = Schema.Struct({
|
|
@@ -49,4 +59,5 @@ export const PluginInfo = Schema.Struct({
|
|
|
49
59
|
refused: Schema.Number,
|
|
50
60
|
lastError: Schema.optional(Schema.String),
|
|
51
61
|
})
|
|
62
|
+
|
|
52
63
|
export type PluginInfo = typeof PluginInfo.Type
|
package/src/project.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Schema } from "effect"
|
|
2
2
|
|
|
3
3
|
export const ProjectKind = Schema.Literals(["docs", "memories", "artifacts"])
|
|
4
|
+
|
|
4
5
|
export type ProjectKind = typeof ProjectKind.Type
|
|
5
6
|
|
|
6
7
|
export const ProjectInfoResult = Schema.Struct({
|
|
@@ -10,4 +11,13 @@ export const ProjectInfoResult = Schema.Struct({
|
|
|
10
11
|
memories: Schema.String,
|
|
11
12
|
artifacts: Schema.String,
|
|
12
13
|
})
|
|
14
|
+
|
|
13
15
|
export const ProjectSearchInput = Schema.Struct({ query: Schema.String, kind: Schema.optional(ProjectKind) })
|
|
16
|
+
|
|
17
|
+
export const ProjectActivity = Schema.Literals(["blocked", "done", "working", "idle"])
|
|
18
|
+
|
|
19
|
+
export type ProjectActivity = typeof ProjectActivity.Type
|
|
20
|
+
|
|
21
|
+
export class ProjectCreateFailed extends Schema.TaggedError<ProjectCreateFailed>()("ProjectCreateFailed", {
|
|
22
|
+
message: Schema.String,
|
|
23
|
+
}) {}
|
package/src/remove.ts
CHANGED
package/src/session.ts
CHANGED
|
@@ -3,28 +3,44 @@ import { Schema } from "effect"
|
|
|
3
3
|
import { InboxKind } from "./event.ts"
|
|
4
4
|
|
|
5
5
|
export const AgentStatus = Schema.Literals(["idle", "working", "blocked", "done", "unknown"])
|
|
6
|
+
|
|
6
7
|
export type AgentStatus = typeof AgentStatus.Type
|
|
7
|
-
|
|
8
|
-
export
|
|
9
|
-
|
|
8
|
+
|
|
9
|
+
export const ExecutionState = Schema.Literals([
|
|
10
|
+
"none",
|
|
11
|
+
"open",
|
|
12
|
+
"completed",
|
|
13
|
+
"failed",
|
|
14
|
+
"interrupted",
|
|
15
|
+
"lost",
|
|
16
|
+
"not_started",
|
|
17
|
+
])
|
|
18
|
+
|
|
19
|
+
export type ExecutionState = typeof ExecutionState.Type
|
|
20
|
+
|
|
21
|
+
export const InboxStatus = Schema.Literals(["pending", "delivering", "delivered", "failed", "dropped"])
|
|
22
|
+
|
|
10
23
|
export type InboxStatus = typeof InboxStatus.Type
|
|
11
24
|
|
|
12
25
|
export const RuntimeAddress = Schema.Struct({
|
|
13
26
|
machine: Schema.String,
|
|
14
27
|
id: Schema.String,
|
|
15
28
|
})
|
|
29
|
+
|
|
16
30
|
export type RuntimeAddress = typeof RuntimeAddress.Type
|
|
17
31
|
|
|
18
32
|
export const RuntimeLocation = Schema.Union([
|
|
19
33
|
Schema.Struct({ socketPath: Schema.String }),
|
|
20
34
|
Schema.Struct({ session: Schema.String }),
|
|
21
35
|
])
|
|
36
|
+
|
|
22
37
|
export type RuntimeLocation = typeof RuntimeLocation.Type
|
|
23
38
|
|
|
24
39
|
export const RuntimeMachine = Schema.Struct({
|
|
25
40
|
id: Schema.String,
|
|
26
41
|
target: Schema.optional(Schema.String),
|
|
27
42
|
})
|
|
43
|
+
|
|
28
44
|
export type RuntimeMachine = typeof RuntimeMachine.Type
|
|
29
45
|
|
|
30
46
|
export const InboxRow = Schema.Struct({
|
|
@@ -35,10 +51,21 @@ export const InboxRow = Schema.Struct({
|
|
|
35
51
|
message: Schema.String,
|
|
36
52
|
status: InboxStatus,
|
|
37
53
|
})
|
|
54
|
+
|
|
38
55
|
export type InboxRow = typeof InboxRow.Type
|
|
39
56
|
|
|
57
|
+
export type Taken = {
|
|
58
|
+
readonly execution: number
|
|
59
|
+
readonly ids: ReadonlyArray<number>
|
|
60
|
+
readonly line: string
|
|
61
|
+
readonly text: string
|
|
62
|
+
}
|
|
63
|
+
|
|
40
64
|
export type HarnessId = string
|
|
41
65
|
|
|
66
|
+
export const addPluginHint =
|
|
67
|
+
"a harness comes from a plugin: add one that provides it to `plugins` in vibest.json in the vibest home"
|
|
68
|
+
|
|
42
69
|
export class HarnessUnavailable extends Schema.TaggedError<HarnessUnavailable>()("HarnessUnavailable", {
|
|
43
70
|
harness: Schema.String,
|
|
44
71
|
message: Schema.String,
|
|
@@ -60,6 +87,7 @@ export class NoSuchSession extends Schema.TaggedError<NoSuchSession>()("NoSuchSe
|
|
|
60
87
|
id: Schema.String,
|
|
61
88
|
message: Schema.String,
|
|
62
89
|
}) {}
|
|
90
|
+
|
|
63
91
|
export class AmbiguousSession extends Schema.TaggedError<AmbiguousSession>()("AmbiguousSession", {
|
|
64
92
|
prefix: Schema.String,
|
|
65
93
|
matches: Schema.Array(Schema.String),
|
|
@@ -68,15 +96,11 @@ export class AmbiguousSession extends Schema.TaggedError<AmbiguousSession>()("Am
|
|
|
68
96
|
return `${this.prefix} matches ${this.matches.join(", ")}; give more characters of the session id`
|
|
69
97
|
}
|
|
70
98
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
override get message() {
|
|
77
|
-
return `the project moved from ${this.from} to ${this.to}; run vibest here to move it`
|
|
78
|
-
}
|
|
79
|
-
}
|
|
99
|
+
|
|
100
|
+
export class MoveRefused extends Schema.TaggedError<MoveRefused>()("MoveRefused", {
|
|
101
|
+
message: Schema.String,
|
|
102
|
+
}) {}
|
|
103
|
+
|
|
80
104
|
export class AllocationFailed extends Schema.TaggedError<AllocationFailed>()("AllocationFailed", {
|
|
81
105
|
message: Schema.String,
|
|
82
106
|
}) {}
|
|
@@ -85,18 +109,43 @@ export class SessionBusy extends Schema.TaggedError<SessionBusy>()("SessionBusy"
|
|
|
85
109
|
id: Schema.String,
|
|
86
110
|
message: Schema.String,
|
|
87
111
|
}) {}
|
|
112
|
+
|
|
88
113
|
export class LimitReached extends Schema.TaggedError<LimitReached>()("LimitReached", { limit: Schema.Number }) {
|
|
89
114
|
override get message() {
|
|
90
115
|
return `VIBEST_MAX_SESSIONS=${this.limit} sessions are already open (working or kept); vibest archive one first`
|
|
91
116
|
}
|
|
92
117
|
}
|
|
118
|
+
|
|
93
119
|
export class NotReady extends Schema.TaggedError<NotReady>()("NotReady", {
|
|
94
120
|
id: Schema.String,
|
|
95
121
|
message: Schema.String,
|
|
96
122
|
}) {}
|
|
97
|
-
|
|
123
|
+
|
|
124
|
+
export class NoCallingSession extends Schema.TaggedError<NoCallingSession>()("NoCallingSession", {}) {
|
|
125
|
+
override get message() {
|
|
126
|
+
return "vibest run is run by an agent in a session; to start working, run vibest in a terminal"
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export class UnknownAgent extends Schema.TaggedError<UnknownAgent>()("UnknownAgent", {
|
|
131
|
+
agent: Schema.String,
|
|
132
|
+
known: Schema.Array(Schema.Struct({ id: Schema.String, description: Schema.String })),
|
|
133
|
+
}) {
|
|
98
134
|
override get message() {
|
|
99
|
-
|
|
135
|
+
const known = this.known.map((definition) => `${definition.id} (${definition.description})`).join("; ")
|
|
136
|
+
|
|
137
|
+
return `no agent definition ${this.agent}; registered: ${known || "none"}`
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export const runnableNote = (runnable: ReadonlyArray<string>) =>
|
|
142
|
+
runnable.length === 0 ? "" : `; this machine can run: ${runnable.join(", ")}`
|
|
143
|
+
|
|
144
|
+
export class NoHarnessChosen extends Schema.TaggedError<NoHarnessChosen>()("NoHarnessChosen", {
|
|
145
|
+
runnable: Schema.Array(Schema.String),
|
|
146
|
+
}) {
|
|
147
|
+
override get message() {
|
|
148
|
+
return `no harness to inherit: name one, for example \`vibest run claude -- <prompt>\`${runnableNote(this.runnable)}`
|
|
100
149
|
}
|
|
101
150
|
}
|
|
102
151
|
|
|
@@ -109,3 +158,31 @@ export class NotInRepository extends Schema.TaggedError<NotInRepository>()("NotI
|
|
|
109
158
|
return `${this.path} is not inside a git repository`
|
|
110
159
|
}
|
|
111
160
|
}
|
|
161
|
+
|
|
162
|
+
export const describeSpawn = (s: {
|
|
163
|
+
harness: string
|
|
164
|
+
provider?: string | undefined
|
|
165
|
+
model?: string | undefined
|
|
166
|
+
decidedBy: Readonly<Record<string, string>>
|
|
167
|
+
}) => {
|
|
168
|
+
const plugins = [...new Set(Object.values(s.decidedBy))]
|
|
169
|
+
const by = plugins.length === 0 ? "" : ` (chosen by plugin ${plugins.join(", ")})`
|
|
170
|
+
|
|
171
|
+
return [s.harness, s.provider, s.model].filter(Boolean).join(" / ") + by
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export const HarnessModel = Schema.Struct({
|
|
175
|
+
provider: Schema.NullOr(Schema.String),
|
|
176
|
+
model: Schema.String,
|
|
177
|
+
name: Schema.String,
|
|
178
|
+
default: Schema.Boolean,
|
|
179
|
+
})
|
|
180
|
+
|
|
181
|
+
export const HarnessChoice = Schema.Struct({
|
|
182
|
+
harness: Schema.String,
|
|
183
|
+
binary: Schema.String,
|
|
184
|
+
problem: Schema.NullOr(Schema.String),
|
|
185
|
+
models: Schema.Array(HarnessModel),
|
|
186
|
+
})
|
|
187
|
+
|
|
188
|
+
export type HarnessChoice = typeof HarnessChoice.Type
|
package/src/subscription.ts
CHANGED
|
@@ -5,6 +5,7 @@ export const SubscriptionAccount = Schema.Struct({
|
|
|
5
5
|
plan: Schema.optional(Schema.String),
|
|
6
6
|
provider: Schema.optional(Schema.String),
|
|
7
7
|
})
|
|
8
|
+
|
|
8
9
|
export type SubscriptionAccount = typeof SubscriptionAccount.Type
|
|
9
10
|
|
|
10
11
|
export const SubscriptionLimit = Schema.Struct({
|
|
@@ -13,6 +14,7 @@ export const SubscriptionLimit = Schema.Struct({
|
|
|
13
14
|
status: Schema.Literals(["available", "limited"]),
|
|
14
15
|
resetTime: Schema.NullOr(Schema.Number),
|
|
15
16
|
})
|
|
17
|
+
|
|
16
18
|
export type SubscriptionLimit = typeof SubscriptionLimit.Type
|
|
17
19
|
|
|
18
20
|
export const Subscription = Schema.Struct({
|
|
@@ -24,4 +26,5 @@ export const Subscription = Schema.Struct({
|
|
|
24
26
|
updatedAt: Schema.Number,
|
|
25
27
|
error: Schema.optional(Schema.String),
|
|
26
28
|
})
|
|
29
|
+
|
|
27
30
|
export type Subscription = typeof Subscription.Type
|
package/src/version.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const PROTOCOL = 11
|