@vibest/schema 0.0.0-stage → 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 iamdin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/package.json CHANGED
@@ -1,6 +1,29 @@
1
1
  {
2
2
  "name": "@vibest/schema",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.0.1-beta.20",
4
+ "description": "The schemas of vibest's facts and wire types, shared by vibestd and the plugin API.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/vibest-dev/vibest.git",
9
+ "directory": "packages/schema"
10
+ },
11
+ "files": [
12
+ "src",
13
+ "LICENSE"
14
+ ],
15
+ "type": "module",
16
+ "exports": {
17
+ "./*": "./src/*.ts"
18
+ },
19
+ "publishConfig": {
20
+ "access": "public"
21
+ },
22
+ "dependencies": {
23
+ "effect": "4.0.2"
24
+ },
25
+ "scripts": {
26
+ "typecheck": "tsrs --noEmit --fast",
27
+ "test": "cd ../.. && bun ./node_modules/vitest/vitest.mjs run packages/schema"
28
+ }
6
29
  }
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 ADDED
@@ -0,0 +1,242 @@
1
+ import { Effect, Schema } from "effect"
2
+
3
+ import { factOf } from "./event-fact.ts"
4
+ import { Routing } from "./plugin.ts"
5
+
6
+ export type Aggregate = "project" | "session" | "ledger"
7
+
8
+ export interface Definition<T extends string = string, S extends Schema.Top = Schema.Top> {
9
+ readonly type: T
10
+ readonly aggregate: Aggregate
11
+ readonly data: S
12
+ }
13
+
14
+ export const fact = <const T extends string, const F extends Schema.Struct.Fields>(
15
+ type: T,
16
+ aggregate: Aggregate,
17
+ fields: F,
18
+ ): Definition<T, Schema.Struct<F>> => ({ type, aggregate, data: Schema.Struct(fields) })
19
+
20
+ const Text = Schema.NonEmptyString
21
+ const optional = <S extends Schema.Top>(schema: S) => Schema.optionalKey(schema)
22
+ const Seq = Schema.Int.check(Schema.isGreaterThan(0))
23
+ const Pid = Schema.Int.check(Schema.isGreaterThan(0))
24
+
25
+ const Repository = Schema.Struct({ path: Text, remote: optional(Text) })
26
+ const Repositories = Schema.Array(Repository)
27
+
28
+ export const ProjectCreated = fact("project.created", "project", {
29
+ directory: optional(Text),
30
+ repositories: Repositories,
31
+ })
32
+
33
+ export const ProjectMoved = fact("project.moved", "project", { from: Text, to: Text, repositories: Repositories })
34
+
35
+ export const ProjectRepositoriesChanged = fact("project.repositories_changed", "project", {
36
+ repositories: Repositories,
37
+ })
38
+
39
+ export const ProjectEntryChanged = fact("project.entry_changed", "project", { session: optional(Text) })
40
+
41
+ export const SessionCreated = fact("session.created", "session", {
42
+ project: Text,
43
+ agent: Text,
44
+ name: Text,
45
+ directory: Schema.String,
46
+ parent: optional(Text),
47
+ origin: optional(Schema.Struct({ peer: Text, project: Text, session: optional(Text) })),
48
+ })
49
+
50
+ export const SessionRenamed = fact("session.renamed", "session", { name: Text })
51
+ export const SessionDirectoryChanged = fact("session.directory_changed", "session", { directory: Text })
52
+ export const SessionEnded = fact("session.ended", "session", { reason: Schema.Literals(["archived", "replaced"]) })
53
+
54
+ export const ProcessStarted = fact("process.started", "session", {
55
+ harness: Text,
56
+ provider: optional(Text),
57
+ model: optional(Text),
58
+ routing: optional(Routing),
59
+ resume: optional(Text),
60
+ runtime: Text,
61
+ terminal: optional(Text),
62
+ pid: optional(Pid),
63
+ })
64
+
65
+ export const ProcessPlaced = fact("process.placed", "session", { process: Seq, terminal: Text, pid: optional(Pid) })
66
+
67
+ export const ProcessReady = fact("process.ready", "session", {
68
+ process: Seq,
69
+ pid: optional(Pid),
70
+ integration: optional(Schema.Struct({ version: Text, protocol: Schema.Int })),
71
+ })
72
+
73
+ export const ProcessPid = fact("process.pid", "session", { process: Seq, pid: Pid })
74
+ export const ProcessConversation = fact("process.conversation", "session", { process: Seq, conversation: Text })
75
+
76
+ export const ProcessEndReason = Schema.Literals([
77
+ "exited",
78
+ "limited",
79
+ "restart",
80
+ "move",
81
+ "archived",
82
+ "launch_failed",
83
+ "superseded",
84
+ ])
85
+
86
+ export type ProcessEndReason = typeof ProcessEndReason.Type
87
+
88
+ export const ProcessEnded = fact("process.ended", "session", { process: Seq, reason: ProcessEndReason })
89
+
90
+ export const ExecutionStarted = fact("execution.started", "session", {
91
+ process: optional(Seq),
92
+ typed: optional(Text),
93
+ })
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")) })),
102
+ conversation: optional(Text),
103
+ reply: optional(Schema.String),
104
+ })
105
+
106
+ export const InboxKind = Schema.Literals(["task", "send", "notice"])
107
+
108
+ export type InboxKind = typeof InboxKind.Type
109
+
110
+ export const InboxQueued = fact("inbox.queued", "session", {
111
+ kind: InboxKind,
112
+ recipient: optional(Text),
113
+ sender: optional(Text),
114
+ content: Schema.String,
115
+ status: Schema.Literals(["pending", "delivered", "dropped"]),
116
+ request: optional(Text),
117
+ peerItem: optional(Text),
118
+ })
119
+
120
+ export const InboxMoved = fact("inbox.moved", "session", {
121
+ inbox: Seq,
122
+ to: Schema.Literals(["pending", "delivering", "delivered", "failed", "dropped"]),
123
+ execution: optional(Seq),
124
+ })
125
+
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 })
129
+
130
+ export const PeerSeen = fact("peer.seen", "ledger", { id: Text, name: Text })
131
+
132
+ export const OutboxQueued = fact("outbox.queued", "ledger", {
133
+ id: Text,
134
+ peer: Text,
135
+ session: Text,
136
+ recipient: optional(Text),
137
+ kind: optional(Schema.Literals(["send", "notice"])),
138
+ content: Schema.String,
139
+ })
140
+
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]
174
+
175
+ export type FactType = Defined["type"]
176
+
177
+ export const CATALOG_VERSION = 2
178
+
179
+ export type Fact = {
180
+ readonly [D in Defined as D["type"]]: {
181
+ readonly aggregate: string
182
+ readonly seq: number
183
+ readonly at: number
184
+ readonly type: D["type"]
185
+ readonly projectId?: string
186
+ readonly sessionId?: string
187
+ readonly data: D["data"]["Type"]
188
+ }
189
+ }[FactType]
190
+
191
+ export type FactOf<T extends FactType> = Extract<Fact, { readonly type: T }>
192
+
193
+ export interface Row {
194
+ readonly aggregate: string
195
+ readonly seq: number
196
+ readonly at: number
197
+ readonly type: string
198
+ readonly data: string
199
+ }
200
+
201
+ export class UnknownFact extends Schema.TaggedError<UnknownFact>()("UnknownFact", {
202
+ aggregate: Schema.String,
203
+ seq: Schema.Number,
204
+ type: Schema.String,
205
+ message: Schema.String,
206
+ }) {}
207
+
208
+ const strict = { onExcessProperty: "error" } as const
209
+
210
+ export const encodeData = <D extends Defined>(
211
+ definition: D,
212
+ data: D["data"]["Type"],
213
+ ): Effect.Effect<string, Schema.SchemaError> =>
214
+ Schema.encodeUnknownEffect(definition.data)(data, strict).pipe(
215
+ Effect.map((encoded) => JSON.stringify(encoded)),
216
+ Effect.tap((json) => Schema.decodeUnknownEffect(definition.data)(JSON.parse(json), strict)),
217
+ )
218
+
219
+ export const isFactOf = <T extends FactType>(type: T, fact: Fact): fact is FactOf<T> => fact.type === type
220
+
221
+ export const decodeRow = (row: Row): Effect.Effect<Fact, UnknownFact> => {
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
+
231
+ return Effect.try({
232
+ try: () => JSON.parse(row.data),
233
+ catch: (cause) => refuse(`${row.type} data is not JSON: ${String(cause)}`),
234
+ }).pipe(
235
+ Effect.flatMap((json) =>
236
+ Schema.decodeUnknownEffect(definition.data)(json, strict).pipe(
237
+ Effect.mapError((cause) => refuse(`${row.type} does not decode: ${cause.message}`)),
238
+ ),
239
+ ),
240
+ Effect.map((data) => factOf(row, definition, data)),
241
+ )
242
+ }
package/src/id.ts ADDED
@@ -0,0 +1,20 @@
1
+ import { Effect, Schema } from "effect"
2
+
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
+
5
+ export const RequestId = Schema.String.check(Schema.isUUID(4))
6
+
7
+ export const shortId = (id: string) => id.slice(0, 8)
8
+
9
+ declare const crypto: { readonly randomUUID: () => string }
10
+
11
+ export const randomId = (): string => crypto.randomUUID()
12
+
13
+ export const newId = <E = never, R = never>(
14
+ taken: (short: string) => Effect.Effect<boolean, E, R> = () => Effect.succeed(false),
15
+ ) =>
16
+ Effect.sync(randomId).pipe(
17
+ Effect.flatMap((id) => taken(shortId(id)).pipe(Effect.map((used) => (used ? undefined : id)))),
18
+ Effect.repeat({ until: (id): id is string => id !== undefined }),
19
+ Effect.map((id) => id!),
20
+ )
package/src/layout.ts ADDED
@@ -0,0 +1,64 @@
1
+ import { Config, Context, Effect, Layer, Path } from "effect"
2
+
3
+ export class Layout extends Context.Service<
4
+ Layout,
5
+ {
6
+ readonly home: string
7
+ readonly database: string
8
+ readonly socket: string
9
+ readonly httpSocket: string
10
+ readonly daemonInfo: string
11
+ readonly log: string
12
+ readonly identity: string
13
+ readonly worktrees: string
14
+ readonly projects: string
15
+ readonly config: string
16
+ readonly plugins: string
17
+ readonly allocationWorktree: (repository: string, name: string) => string
18
+ readonly project: (projectId: string) => string
19
+ readonly artifacts: (projectId: string) => string
20
+ readonly sessionFolder: (projectId: string, sessionId: string) => string
21
+ }
22
+ >()("vibest/Layout") {
23
+ static readonly make = (home: string) =>
24
+ Effect.gen(function* () {
25
+ const path = yield* Path.Path
26
+
27
+ return Layout.of({
28
+ home,
29
+ database: path.join(home, "vibest.db"),
30
+ socket: path.join(home, "vibest.sock"),
31
+ httpSocket: path.join(home, "vibest-http.sock"),
32
+ daemonInfo: path.join(home, "vibestd.pid"),
33
+ log: path.join(home, "vibestd.log"),
34
+ identity: path.join(home, "identity.json"),
35
+ worktrees: path.join(home, "worktrees"),
36
+ projects: path.join(home, "projects"),
37
+ config: path.join(home, "vibest.json"),
38
+ plugins: path.join(home, "plugins"),
39
+ allocationWorktree: (repository, name) => path.join(home, "worktrees", repository, name),
40
+ project: (projectId) => path.join(home, "projects", projectId),
41
+ artifacts: (projectId) => path.join(home, "projects", projectId, "artifacts"),
42
+ sessionFolder: (projectId, sessionId) => path.join(home, "projects", projectId, "sessions", sessionId),
43
+ })
44
+ })
45
+
46
+ static readonly layer = Layer.effect(
47
+ Layout,
48
+ Effect.gen(function* () {
49
+ const path = yield* Path.Path
50
+
51
+ const home = yield* Config.String("VIBEST_HOME").pipe(
52
+ Config.orElse(() => Config.String("HOME").pipe(Config.map((h) => path.join(h, ".vibest")))),
53
+ )
54
+
55
+ return yield* Layout.make(home)
56
+ }),
57
+ )
58
+ }
59
+
60
+ export const VibestCommand = Context.Reference<ReadonlyArray<string>>("vibest/VibestCommand", {
61
+ defaultValue: () => ["vibest"],
62
+ })
63
+
64
+ export const shellQuote = (s: string) => (/^[\w@%+=:,./-]+$/.test(s) ? s : `'${s.replace(/'/g, `'\\''`)}'`)
package/src/machine.ts ADDED
@@ -0,0 +1,114 @@
1
+ import { Schema, Struct } from "effect"
2
+
3
+ export class MachineFailed extends Schema.TaggedError<MachineFailed>()("MachineFailed", { message: Schema.String }) {}
4
+
5
+ export class UnknownMachine extends Schema.TaggedError<UnknownMachine>()("UnknownMachine", {
6
+ machine: Schema.String,
7
+ machines: Schema.Array(Schema.String),
8
+ }) {
9
+ override get message() {
10
+ const known =
11
+ this.machines.length === 0 ? "none is added (vibest machine add)" : `machines: ${this.machines.join(", ")}`
12
+
13
+ return `unknown machine ${JSON.stringify(this.machine)}; ${known}`
14
+ }
15
+ }
16
+
17
+ export class MachineUnavailable extends Schema.TaggedError<MachineUnavailable>()("MachineUnavailable", {
18
+ machine: Schema.String,
19
+ message: Schema.String,
20
+ }) {}
21
+
22
+ export class MachineIncompatible extends Schema.TaggedError<MachineIncompatible>()("MachineIncompatible", {
23
+ machine: Schema.String,
24
+ message: Schema.String,
25
+ }) {}
26
+
27
+ export class AlreadyAdded extends Schema.TaggedError<AlreadyAdded>()("AlreadyAdded", {
28
+ machine: Schema.String,
29
+ id: Schema.String,
30
+ }) {
31
+ override get message() {
32
+ return `this is the vibestd already added as ${this.machine} (${this.id.slice(0, 8)}); use that name`
33
+ }
34
+ }
35
+
36
+ export const MachineState = Schema.Literals(["connecting", "connected", "unreachable", "different"])
37
+
38
+ export type MachineState = typeof MachineState.Type
39
+
40
+ export const MachineNote = Schema.Struct({
41
+ plugin: Schema.optional(Schema.String),
42
+ message: Schema.String,
43
+ fix: Schema.optional(Schema.String),
44
+ })
45
+
46
+ export type MachineNote = typeof MachineNote.Type
47
+
48
+ export const RuntimeThere = Schema.Struct({
49
+ kind: Schema.String,
50
+ status: Schema.Literals(["online", "offline", "blocked"]),
51
+ reason: Schema.optional(Schema.String),
52
+ link: Schema.optional(Schema.Record(Schema.String, Schema.String)),
53
+ })
54
+
55
+ export type RuntimeThere = typeof RuntimeThere.Type
56
+
57
+ export const RuntimeView = Schema.Struct({
58
+ kind: Schema.String,
59
+ status: RuntimeThere.fields.status,
60
+ reason: Schema.optional(Schema.String),
61
+ here: Schema.Struct({
62
+ visible: Schema.Boolean,
63
+ as: Schema.optional(Schema.String),
64
+ note: Schema.optional(Schema.String),
65
+ }),
66
+ })
67
+
68
+ export type RuntimeView = typeof RuntimeView.Type
69
+
70
+ export const MachineInfo = Schema.Struct({
71
+ name: Schema.String,
72
+ target: Schema.String,
73
+ id: Schema.String,
74
+ state: MachineState,
75
+ since: Schema.Number,
76
+ reason: Schema.optional(Schema.String),
77
+ connectedAt: Schema.Number,
78
+ vibestd: Schema.optional(Schema.String),
79
+ version: Schema.optional(Schema.String),
80
+ runtimes: Schema.optional(Schema.Array(RuntimeView)),
81
+ runtimesAt: Schema.optional(Schema.Number),
82
+ notes: Schema.optional(Schema.Array(Schema.Struct({ ...MachineNote.fields, at: Schema.Number }))),
83
+ })
84
+
85
+ export type MachineInfo = typeof MachineInfo.Type
86
+
87
+ export const ListedMachine = MachineInfo.mapFields(Struct.pick(["name", "state", "since", "reason"]))
88
+
89
+ export type ListedMachine = typeof ListedMachine.Type
90
+
91
+ export class NoProject extends Schema.TaggedError<NoProject>()("NoProject", { message: Schema.String }) {}
92
+
93
+ export class NoCommit extends Schema.TaggedError<NoCommit>()("NoCommit", { message: Schema.String }) {}
94
+
95
+ export const OUTBOX_ITEM_MAX = 1024 * 1024
96
+
97
+ export const PROMPT_MAX = 1024 * 1024
98
+
99
+ export class PromptTooLarge extends Schema.TaggedError<PromptTooLarge>()("PromptTooLarge", { bytes: Schema.Number }) {
100
+ override get message() {
101
+ return `the prompt is ${this.bytes} bytes; another machine takes at most ${PROMPT_MAX} bytes (1 MiB)`
102
+ }
103
+ }
104
+
105
+ export const OutboxItem = Schema.Struct({
106
+ id: Schema.String,
107
+ session: Schema.String,
108
+ recipient: Schema.String,
109
+ kind: Schema.Literals(["send", "notice"]),
110
+ content: Schema.String,
111
+ cut: Schema.optional(Schema.Boolean),
112
+ })
113
+
114
+ export type OutboxItem = typeof OutboxItem.Type
package/src/model.ts ADDED
@@ -0,0 +1,5 @@
1
+ import { Schema } from "effect"
2
+
3
+ export const MessageStatus = Schema.Literals(["working", "completed", "failed", "interrupted", "lost", "not_started"])
4
+
5
+ export type MessageStatus = typeof MessageStatus.Type
package/src/plugin.ts ADDED
@@ -0,0 +1,63 @@
1
+ import { Schema } from "effect"
2
+
3
+ export class AgentRefused extends Schema.TaggedError<AgentRefused>()("AgentRefused", {
4
+ plugin: Schema.String,
5
+ reason: Schema.String,
6
+ }) {
7
+ override get message() {
8
+ return `refused by ${this.plugin}: ${this.reason}`
9
+ }
10
+ }
11
+
12
+ export class HookFailed extends Schema.TaggedError<HookFailed>()("HookFailed", { message: Schema.String }) {}
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
+
22
+ export const Change = Schema.Struct({
23
+ field: Schema.String,
24
+ from: Schema.optional(Schema.Unknown),
25
+ to: Schema.optional(Schema.Unknown),
26
+ overwrote: Schema.optional(Schema.String),
27
+ })
28
+
29
+ export const TraceEntry = Schema.Struct({
30
+ plugin: Schema.String,
31
+ hook: Schema.String,
32
+ outcome: Schema.Literals(["ok", "refused", "crashed", "timeout"]),
33
+ ms: Schema.Number,
34
+ changes: Schema.Array(Change),
35
+ reason: Schema.optional(Schema.String),
36
+ error: Schema.optional(Schema.String),
37
+ })
38
+
39
+ export type TraceEntry = typeof TraceEntry.Type
40
+
41
+ export const Routing = Schema.Struct({
42
+ decidedBy: Schema.Record(Schema.String, Schema.String),
43
+ trace: Schema.Array(TraceEntry),
44
+ })
45
+
46
+ export type Routing = typeof Routing.Type
47
+
48
+ export const PluginInfo = Schema.Struct({
49
+ id: Schema.String,
50
+ source: Schema.String,
51
+ revision: Schema.String,
52
+ loadedAt: Schema.Number,
53
+ status: Schema.Literals(["active", "failed"]),
54
+ error: Schema.optional(Schema.String),
55
+ calls: Schema.Number,
56
+ changed: Schema.Number,
57
+ crashed: Schema.Number,
58
+ timedOut: Schema.Number,
59
+ refused: Schema.Number,
60
+ lastError: Schema.optional(Schema.String),
61
+ })
62
+
63
+ export type PluginInfo = typeof PluginInfo.Type
package/src/project.ts ADDED
@@ -0,0 +1,23 @@
1
+ import { Schema } from "effect"
2
+
3
+ export const ProjectKind = Schema.Literals(["docs", "memories", "artifacts"])
4
+
5
+ export type ProjectKind = typeof ProjectKind.Type
6
+
7
+ export const ProjectInfoResult = Schema.Struct({
8
+ directory: Schema.String,
9
+ preferences: Schema.String,
10
+ docs: Schema.String,
11
+ memories: Schema.String,
12
+ artifacts: Schema.String,
13
+ })
14
+
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 ADDED
@@ -0,0 +1,14 @@
1
+ import { Schema } from "effect"
2
+
3
+ export const RemoveOutcome = Schema.Struct({
4
+ id: Schema.String,
5
+ processes: Schema.Literals(["exited", "alive", "unknown"]),
6
+ pane: Schema.Literals(["closed", "kept", "none"]),
7
+ workspace: Schema.Literals(["closed", "kept", "none"]),
8
+ worktree: Schema.Literals(["removed", "kept", "gone"]),
9
+ path: Schema.String,
10
+ branch: Schema.NullOr(Schema.String),
11
+ reasons: Schema.Array(Schema.String),
12
+ })
13
+
14
+ export type RemoveOutcome = typeof RemoveOutcome.Type
package/src/session.ts ADDED
@@ -0,0 +1,188 @@
1
+ import { Schema } from "effect"
2
+
3
+ import { InboxKind } from "./event.ts"
4
+
5
+ export const AgentStatus = Schema.Literals(["idle", "working", "blocked", "done", "unknown"])
6
+
7
+ export type AgentStatus = typeof AgentStatus.Type
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
+
23
+ export type InboxStatus = typeof InboxStatus.Type
24
+
25
+ export const RuntimeAddress = Schema.Struct({
26
+ machine: Schema.String,
27
+ id: Schema.String,
28
+ })
29
+
30
+ export type RuntimeAddress = typeof RuntimeAddress.Type
31
+
32
+ export const RuntimeLocation = Schema.Union([
33
+ Schema.Struct({ socketPath: Schema.String }),
34
+ Schema.Struct({ session: Schema.String }),
35
+ ])
36
+
37
+ export type RuntimeLocation = typeof RuntimeLocation.Type
38
+
39
+ export const RuntimeMachine = Schema.Struct({
40
+ id: Schema.String,
41
+ target: Schema.optional(Schema.String),
42
+ })
43
+
44
+ export type RuntimeMachine = typeof RuntimeMachine.Type
45
+
46
+ export const InboxRow = Schema.Struct({
47
+ id: Schema.Number,
48
+ sender: Schema.NullOr(Schema.String),
49
+ recipient: Schema.NullOr(Schema.String),
50
+ kind: InboxKind,
51
+ message: Schema.String,
52
+ status: InboxStatus,
53
+ })
54
+
55
+ export type InboxRow = typeof InboxRow.Type
56
+
57
+ export type Taken = {
58
+ readonly execution: number
59
+ readonly ids: ReadonlyArray<number>
60
+ readonly line: string
61
+ readonly text: string
62
+ }
63
+
64
+ export type HarnessId = string
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
+
69
+ export class HarnessUnavailable extends Schema.TaggedError<HarnessUnavailable>()("HarnessUnavailable", {
70
+ harness: Schema.String,
71
+ message: Schema.String,
72
+ }) {}
73
+
74
+ export class RuntimeUnreachable extends Schema.TaggedError<RuntimeUnreachable>()("RuntimeUnreachable", {
75
+ session: Schema.String,
76
+ message: Schema.String,
77
+ }) {}
78
+
79
+ export class NoRuntime extends Schema.TaggedError<NoRuntime>()("NoRuntime", { message: Schema.String }) {}
80
+
81
+ export class RuntimeIncompatible extends Schema.TaggedError<RuntimeIncompatible>()("RuntimeIncompatible", {
82
+ session: Schema.String,
83
+ message: Schema.String,
84
+ }) {}
85
+
86
+ export class NoSuchSession extends Schema.TaggedError<NoSuchSession>()("NoSuchSession", {
87
+ id: Schema.String,
88
+ message: Schema.String,
89
+ }) {}
90
+
91
+ export class AmbiguousSession extends Schema.TaggedError<AmbiguousSession>()("AmbiguousSession", {
92
+ prefix: Schema.String,
93
+ matches: Schema.Array(Schema.String),
94
+ }) {
95
+ override get message() {
96
+ return `${this.prefix} matches ${this.matches.join(", ")}; give more characters of the session id`
97
+ }
98
+ }
99
+
100
+ export class MoveRefused extends Schema.TaggedError<MoveRefused>()("MoveRefused", {
101
+ message: Schema.String,
102
+ }) {}
103
+
104
+ export class AllocationFailed extends Schema.TaggedError<AllocationFailed>()("AllocationFailed", {
105
+ message: Schema.String,
106
+ }) {}
107
+
108
+ export class SessionBusy extends Schema.TaggedError<SessionBusy>()("SessionBusy", {
109
+ id: Schema.String,
110
+ message: Schema.String,
111
+ }) {}
112
+
113
+ export class LimitReached extends Schema.TaggedError<LimitReached>()("LimitReached", { limit: Schema.Number }) {
114
+ override get message() {
115
+ return `VIBEST_MAX_SESSIONS=${this.limit} sessions are already open (working or kept); vibest archive one first`
116
+ }
117
+ }
118
+
119
+ export class NotReady extends Schema.TaggedError<NotReady>()("NotReady", {
120
+ id: Schema.String,
121
+ message: Schema.String,
122
+ }) {}
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
+ }) {
134
+ override get message() {
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)}`
149
+ }
150
+ }
151
+
152
+ export class LaunchFailed extends Schema.TaggedError<LaunchFailed>()("LaunchFailed", {
153
+ message: Schema.String,
154
+ }) {}
155
+
156
+ export class NotInRepository extends Schema.TaggedError<NotInRepository>()("NotInRepository", { path: Schema.String }) {
157
+ override get message() {
158
+ return `${this.path} is not inside a git repository`
159
+ }
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
@@ -0,0 +1,30 @@
1
+ import { Schema } from "effect"
2
+
3
+ export const SubscriptionAccount = Schema.Struct({
4
+ kind: Schema.Literals(["subscription", "api-key", "none"]),
5
+ plan: Schema.optional(Schema.String),
6
+ provider: Schema.optional(Schema.String),
7
+ })
8
+
9
+ export type SubscriptionAccount = typeof SubscriptionAccount.Type
10
+
11
+ export const SubscriptionLimit = Schema.Struct({
12
+ window: Schema.String,
13
+ percent: Schema.Number,
14
+ status: Schema.Literals(["available", "limited"]),
15
+ resetTime: Schema.NullOr(Schema.Number),
16
+ })
17
+
18
+ export type SubscriptionLimit = typeof SubscriptionLimit.Type
19
+
20
+ export const Subscription = Schema.Struct({
21
+ harness: Schema.String,
22
+ provider: Schema.String,
23
+ machine: Schema.Literal("local"),
24
+ account: SubscriptionAccount,
25
+ limits: Schema.Array(SubscriptionLimit),
26
+ updatedAt: Schema.Number,
27
+ error: Schema.optional(Schema.String),
28
+ })
29
+
30
+ export type Subscription = typeof Subscription.Type
package/src/version.ts ADDED
@@ -0,0 +1 @@
1
+ export const PROTOCOL = 11
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.