@zyro-sec/schema 0.0.0-stage → 1.0.1
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/AGENTS.md +95 -0
- package/package.json +31 -4
- package/script/build.ts +9 -0
- package/script/config-schema.ts +86 -0
- package/script/config-v1.json +1312 -0
- package/script/pack.ts +5 -0
- package/src/agent.ts +68 -0
- package/src/artifact.ts +81 -0
- package/src/automation.ts +224 -0
- package/src/blob-store.ts +25 -0
- package/src/command.ts +18 -0
- package/src/config/agent.ts +26 -0
- package/src/config/command.ts +14 -0
- package/src/config/compaction.ts +27 -0
- package/src/config/experimental.ts +72 -0
- package/src/config/flag.ts +39 -0
- package/src/config/formatter.ts +13 -0
- package/src/config/lsp.ts +19 -0
- package/src/config/mcp.ts +22 -0
- package/src/config/media.ts +15 -0
- package/src/config/model.ts +37 -0
- package/src/config/plugin.ts +14 -0
- package/src/config/policy.ts +57 -0
- package/src/config/provider.ts +122 -0
- package/src/config/reference.ts +23 -0
- package/src/config/shell.ts +10 -0
- package/src/config/tool-output.ts +9 -0
- package/src/config/warming.ts +21 -0
- package/src/config/watcher.ts +8 -0
- package/src/config/websearch.ts +17 -0
- package/src/config/worktree.ts +10 -0
- package/src/config.ts +149 -0
- package/src/connection.ts +38 -0
- package/src/credential-legacy.ts +29 -0
- package/src/credential.ts +78 -0
- package/src/durable-event-manifest.ts +7 -0
- package/src/event-log.ts +21 -0
- package/src/event-manifest.ts +108 -0
- package/src/event.ts +205 -0
- package/src/file-diff.ts +25 -0
- package/src/filesystem-v1.ts +1 -0
- package/src/filesystem.ts +48 -0
- package/src/form.ts +177 -0
- package/src/generate.ts +292 -0
- package/src/goal.ts +46 -0
- package/src/identifier.ts +32 -0
- package/src/index.ts +51 -0
- package/src/installation-event.ts +20 -0
- package/src/instruction-entry.ts +40 -0
- package/src/instruction.ts +25 -0
- package/src/integration-id.ts +13 -0
- package/src/integration.ts +129 -0
- package/src/job.ts +79 -0
- package/src/legacy-event.ts +1 -0
- package/src/llm.ts +6 -0
- package/src/location-event.ts +8 -0
- package/src/location.ts +36 -0
- package/src/lsp-event.ts +7 -0
- package/src/mcp-event.ts +63 -0
- package/src/mcp.ts +171 -0
- package/src/model-compatibility.ts +55 -0
- package/src/model.ts +176 -0
- package/src/models-dev.ts +9 -0
- package/src/money.ts +18 -0
- package/src/permission-saved.ts +25 -0
- package/src/permission-v1.ts +1 -0
- package/src/permission.ts +67 -0
- package/src/persistent-pty.ts +73 -0
- package/src/plugin.ts +62 -0
- package/src/project-id.ts +9 -0
- package/src/project.ts +62 -0
- package/src/prompt-input.ts +33 -0
- package/src/prompt.ts +117 -0
- package/src/provider.ts +136 -0
- package/src/pty-ticket.ts +10 -0
- package/src/pty.ts +61 -0
- package/src/push.ts +86 -0
- package/src/question.ts +22 -0
- package/src/reference.ts +40 -0
- package/src/rpc.ts +167 -0
- package/src/schema.ts +41 -0
- package/src/server-event.ts +8 -0
- package/src/session-error.ts +14 -0
- package/src/session-event.ts +739 -0
- package/src/session-fork.ts +10 -0
- package/src/session-id.ts +12 -0
- package/src/session-inbox.ts +102 -0
- package/src/session-legacy.ts +117 -0
- package/src/session-message.ts +352 -0
- package/src/session-metadata.ts +11 -0
- package/src/session-revert.ts +86 -0
- package/src/session-stats.ts +68 -0
- package/src/session-status-event.ts +53 -0
- package/src/session-transfer.ts +11 -0
- package/src/session-v1.ts +1 -0
- package/src/session.ts +147 -0
- package/src/shell.ts +90 -0
- package/src/skill.ts +68 -0
- package/src/snapshot.ts +6 -0
- package/src/token-usage.ts +18 -0
- package/src/tool.ts +143 -0
- package/src/tui-event.ts +59 -0
- package/src/usage-limits.ts +76 -0
- package/src/v1/filesystem.ts +11 -0
- package/src/v1/legacy-event.ts +18 -0
- package/src/v1/permission.ts +66 -0
- package/src/v1/session.ts +667 -0
- package/src/vcs-event.ts +14 -0
- package/src/vcs.ts +41 -0
- package/src/websearch.ts +44 -0
- package/src/workspace-event.ts +32 -0
- package/src/workspace-id.ts +19 -0
- package/src/workspace.ts +20 -0
- package/src/worktree-event.ts +22 -0
- package/src/worktree.ts +109 -0
- package/test/agent.test.ts +10 -0
- package/test/automation.test.ts +48 -0
- package/test/compatibility.test.ts +10 -0
- package/test/config.test.ts +194 -0
- package/test/contract-hygiene.test.ts +352 -0
- package/test/credential-legacy.test.ts +55 -0
- package/test/event-manifest.test.ts +228 -0
- package/test/event.test.ts +52 -0
- package/test/legacy-event.test.ts +46 -0
- package/test/mcp.test.ts +37 -0
- package/test/model.test.ts +104 -0
- package/test/session-cursor.test.ts +16 -0
- package/test/session-error.test.ts +51 -0
- package/test/session-legacy.test.ts +178 -0
- package/test/session-terminal.test.ts +50 -0
- package/test/token-usage.test.ts +18 -0
- package/test/v1-isolation.test.ts +26 -0
- package/test/vcs.test.ts +23 -0
- package/test/worktree.test.ts +45 -0
- package/tsconfig.build.json +11 -0
- package/tsconfig.json +14 -0
- package/README.md +0 -3
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test"
|
|
2
|
+
import path from "node:path"
|
|
3
|
+
import { DateTime, Schema } from "effect"
|
|
4
|
+
import { Agent } from "../src/agent.js"
|
|
5
|
+
import { ConfigAgent } from "../src/config/agent.js"
|
|
6
|
+
import { ConfigProvider } from "../src/config/provider.js"
|
|
7
|
+
import { FileSystem } from "../src/filesystem.js"
|
|
8
|
+
import { Form } from "../src/form.js"
|
|
9
|
+
import { Job } from "../src/job.js"
|
|
10
|
+
import { Mcp } from "../src/mcp.js"
|
|
11
|
+
import { Model } from "../src/model.js"
|
|
12
|
+
import { Project } from "../src/project.js"
|
|
13
|
+
import { SkillAttachment } from "../src/prompt.js"
|
|
14
|
+
import { Provider } from "../src/provider.js"
|
|
15
|
+
import { Pty } from "../src/pty.js"
|
|
16
|
+
import { Session } from "../src/session.js"
|
|
17
|
+
import { SessionMessage } from "../src/session-message.js"
|
|
18
|
+
import { SessionInbox } from "../src/session-inbox.js"
|
|
19
|
+
import { FileDiff } from "../src/file-diff.js"
|
|
20
|
+
import { Money } from "../src/money.js"
|
|
21
|
+
import { Skill } from "../src/skill.js"
|
|
22
|
+
import { Shell } from "../src/shell.js"
|
|
23
|
+
import { Vcs } from "../src/vcs.js"
|
|
24
|
+
import { Worktree } from "../src/worktree.js"
|
|
25
|
+
import { PersistedRevert } from "../src/session-revert.js"
|
|
26
|
+
import { AbsolutePath, optional } from "../src/schema.js"
|
|
27
|
+
|
|
28
|
+
describe("contract hygiene", () => {
|
|
29
|
+
test("restricts agent colors to six-digit hex values", () => {
|
|
30
|
+
const decode = Schema.decodeUnknownSync(ConfigAgent.Color)
|
|
31
|
+
expect(decode("#ff6b6b")).toBe("#ff6b6b")
|
|
32
|
+
expect(() => decode("warning")).toThrow()
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
test("keeps absolute costs distinct from model rates", () => {
|
|
36
|
+
const usd = Money.USD.make(1)
|
|
37
|
+
const rate = Money.USDPerMillionTokens.make(1)
|
|
38
|
+
// @ts-expect-error Model rates are not absolute costs.
|
|
39
|
+
const invalidUSD: Money.USD = rate
|
|
40
|
+
// @ts-expect-error Absolute costs are not model rates.
|
|
41
|
+
const invalidRate: Money.USDPerMillionTokens = usd
|
|
42
|
+
|
|
43
|
+
expect(invalidUSD).toBe(Money.USD.make(1))
|
|
44
|
+
expect(invalidRate).toBe(Money.USDPerMillionTokens.make(1))
|
|
45
|
+
expect(Money.USD.zero).toBe(Money.USD.make(0))
|
|
46
|
+
expect(Money.USDPerMillionTokens.zero).toBe(Money.USDPerMillionTokens.make(0))
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
test("optional properties preserve transformations and omit undefined while encoding", () => {
|
|
50
|
+
const Value = Schema.Struct({ value: optional(Schema.FiniteFromString) })
|
|
51
|
+
expect(Schema.decodeUnknownSync(Value)({ value: "1" })).toEqual({ value: 1 })
|
|
52
|
+
expect(Schema.encodeSync(Value)({ value: 1 })).toEqual({ value: "1" })
|
|
53
|
+
expect(Schema.encodeSync(Value)({ value: undefined })).toEqual({})
|
|
54
|
+
expect(
|
|
55
|
+
Schema.encodeSync(SessionInbox.SyntheticPayload)({
|
|
56
|
+
text: "completed",
|
|
57
|
+
description: undefined,
|
|
58
|
+
metadata: undefined,
|
|
59
|
+
}),
|
|
60
|
+
).toEqual({ text: "completed" })
|
|
61
|
+
|
|
62
|
+
const info = Session.Info.make({
|
|
63
|
+
id: Session.ID.make("ses_untitled"),
|
|
64
|
+
projectID: Project.ID.make("global"),
|
|
65
|
+
cost: Money.USD.zero,
|
|
66
|
+
tokens: { input: 0, output: 0, reasoning: 0, cache: { read: 0, write: 0 } },
|
|
67
|
+
time: {
|
|
68
|
+
created: DateTime.makeUnsafe(0),
|
|
69
|
+
updated: DateTime.makeUnsafe(0),
|
|
70
|
+
idle: undefined,
|
|
71
|
+
viewed: undefined,
|
|
72
|
+
},
|
|
73
|
+
title: undefined,
|
|
74
|
+
location: { directory: AbsolutePath.make("/project") },
|
|
75
|
+
})
|
|
76
|
+
const encoded = Schema.encodeSync(Session.Info)(info)
|
|
77
|
+
expect(encoded).not.toHaveProperty("title")
|
|
78
|
+
expect(encoded.time).toEqual({ created: 0, updated: 0 })
|
|
79
|
+
expect(
|
|
80
|
+
Schema.encodeSync(Session.Info)({
|
|
81
|
+
...info,
|
|
82
|
+
time: { ...info.time, idle: DateTime.makeUnsafe(2), viewed: DateTime.makeUnsafe(1) },
|
|
83
|
+
}).time,
|
|
84
|
+
).toEqual({ created: 0, updated: 0, idle: 2, viewed: 1 })
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
test("skill attachments retain legacy references while accepting prepared instructions", () => {
|
|
88
|
+
const reference = { id: Skill.ID.make("effect"), name: Skill.Name.make("Effect") }
|
|
89
|
+
expect(Schema.decodeUnknownSync(SkillAttachment)(reference)).toEqual(reference)
|
|
90
|
+
expect(Schema.encodeSync(SkillAttachment)({ ...reference, text: undefined })).toEqual(reference)
|
|
91
|
+
expect(Schema.decodeUnknownSync(SkillAttachment)({ ...reference, text: "Use Effect" })).toEqual({
|
|
92
|
+
...reference,
|
|
93
|
+
text: "Use Effect",
|
|
94
|
+
})
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
test("session inbox items omit the internal enqueue sequence", () => {
|
|
98
|
+
expect(
|
|
99
|
+
Schema.encodeSync(SessionInbox.Info)(
|
|
100
|
+
Schema.decodeUnknownSync(SessionInbox.Info)({
|
|
101
|
+
admittedSeq: 3,
|
|
102
|
+
id: "msg_pending",
|
|
103
|
+
sessionID: "ses_pending",
|
|
104
|
+
time: { created: 1 },
|
|
105
|
+
type: "user",
|
|
106
|
+
payload: { text: "hello" },
|
|
107
|
+
delivery: "steer",
|
|
108
|
+
}),
|
|
109
|
+
),
|
|
110
|
+
).toEqual({
|
|
111
|
+
id: "msg_pending",
|
|
112
|
+
sessionID: "ses_pending",
|
|
113
|
+
time: { created: 1 },
|
|
114
|
+
type: "user",
|
|
115
|
+
payload: { text: "hello" },
|
|
116
|
+
delivery: "steer",
|
|
117
|
+
})
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
test("forms require at least one field", () => {
|
|
121
|
+
expect(() =>
|
|
122
|
+
Schema.decodeUnknownSync(Form.Info)({
|
|
123
|
+
id: Form.ID.create(),
|
|
124
|
+
sessionID: "global",
|
|
125
|
+
title: "Empty form",
|
|
126
|
+
fields: [],
|
|
127
|
+
}),
|
|
128
|
+
).toThrow()
|
|
129
|
+
expect(
|
|
130
|
+
Schema.decodeUnknownSync(Form.Info)({
|
|
131
|
+
id: Form.ID.create(),
|
|
132
|
+
sessionID: "global",
|
|
133
|
+
title: "External form",
|
|
134
|
+
fields: [{ key: "authorization", type: "external", url: "https://example.com" }],
|
|
135
|
+
}).fields,
|
|
136
|
+
).toHaveLength(1)
|
|
137
|
+
expect(() =>
|
|
138
|
+
Schema.decodeUnknownSync(Form.Info)({
|
|
139
|
+
id: Form.ID.create(),
|
|
140
|
+
sessionID: "global",
|
|
141
|
+
title: "External form",
|
|
142
|
+
fields: [{ type: "external", url: "https://example.com" }],
|
|
143
|
+
}),
|
|
144
|
+
).toThrow()
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
test("model defaults and provider overlays preserve public invariants", () => {
|
|
148
|
+
const id = Model.ID.make("model")
|
|
149
|
+
expect(Model.Info.default(Provider.ID.make("provider"), id)).toMatchObject({ modelID: id, variants: [] })
|
|
150
|
+
expect(Provider.Info.empty(Provider.ID.make("provider")).activation).toBe("auto")
|
|
151
|
+
expect(
|
|
152
|
+
Schema.decodeUnknownSync(Provider.Info)({
|
|
153
|
+
id: "provider",
|
|
154
|
+
name: "Provider",
|
|
155
|
+
activation: "auto",
|
|
156
|
+
package: "native",
|
|
157
|
+
settings: { arbitrary: 1n },
|
|
158
|
+
}).settings,
|
|
159
|
+
).toEqual({ arbitrary: 1n })
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
test("current ID constructors expose create", () => {
|
|
163
|
+
expect(Form.ID.create()).toStartWith("frm_")
|
|
164
|
+
expect(Pty.ID.create()).toStartWith("pty_")
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
test("VCS info omits unavailable branch names", () => {
|
|
168
|
+
expect(Schema.encodeSync(Vcs.Info)({ branch: { current: undefined, default: undefined } })).toEqual({ branch: {} })
|
|
169
|
+
})
|
|
170
|
+
|
|
171
|
+
test("reusable public identifiers are stable and unique", () => {
|
|
172
|
+
const identifiers = [
|
|
173
|
+
Agent.Color,
|
|
174
|
+
ConfigProvider.ModelSettings,
|
|
175
|
+
ConfigProvider.Settings,
|
|
176
|
+
FileSystem.Submatch,
|
|
177
|
+
Form.Field,
|
|
178
|
+
Form.Fields,
|
|
179
|
+
Form.Info,
|
|
180
|
+
Form.ExternalField,
|
|
181
|
+
Job.Kind,
|
|
182
|
+
Job.Status,
|
|
183
|
+
Job.Time,
|
|
184
|
+
Job.Shell,
|
|
185
|
+
Job.Subagent,
|
|
186
|
+
Job.Image,
|
|
187
|
+
Job.Info,
|
|
188
|
+
Mcp.Resource,
|
|
189
|
+
Mcp.ResourceTemplate,
|
|
190
|
+
Mcp.ResourceCatalog,
|
|
191
|
+
Mcp.ResourceContentPart,
|
|
192
|
+
Mcp.ResourceContent,
|
|
193
|
+
Model.Ref,
|
|
194
|
+
Model.Capabilities,
|
|
195
|
+
Model.Cost,
|
|
196
|
+
Model.Settings,
|
|
197
|
+
Model.Variant,
|
|
198
|
+
Project.Current,
|
|
199
|
+
Worktree.Directory,
|
|
200
|
+
Worktree.List,
|
|
201
|
+
Project.Icon,
|
|
202
|
+
Project.Commands,
|
|
203
|
+
Project.Time,
|
|
204
|
+
Project.Info,
|
|
205
|
+
Pty.Info,
|
|
206
|
+
Session.ListAnchor,
|
|
207
|
+
Session.ListCursor,
|
|
208
|
+
Session.ListFilter,
|
|
209
|
+
Session.Revert,
|
|
210
|
+
SessionInbox.Delivery,
|
|
211
|
+
SessionInbox.UserPayload,
|
|
212
|
+
SessionInbox.SyntheticPayload,
|
|
213
|
+
SessionInbox.CompactionPayload,
|
|
214
|
+
SessionInbox.MovePayload,
|
|
215
|
+
SessionInbox.Item,
|
|
216
|
+
SessionInbox.User,
|
|
217
|
+
SessionInbox.Synthetic,
|
|
218
|
+
SessionInbox.Compaction,
|
|
219
|
+
SessionInbox.Move,
|
|
220
|
+
SessionInbox.Info,
|
|
221
|
+
Vcs.Branch,
|
|
222
|
+
Vcs.Info,
|
|
223
|
+
].map((schema) => schema.ast.annotations?.identifier)
|
|
224
|
+
|
|
225
|
+
expect(identifiers.every((identifier) => typeof identifier === "string")).toBe(true)
|
|
226
|
+
expect(new Set(identifiers).size).toBe(identifiers.length)
|
|
227
|
+
})
|
|
228
|
+
|
|
229
|
+
test("all session inbox item types accept both delivery modes", () => {
|
|
230
|
+
const decode = Schema.decodeUnknownSync(SessionInbox.Info)
|
|
231
|
+
const base = { id: "msg_inbox", sessionID: "ses_inbox", time: { created: 1 } }
|
|
232
|
+
const move = {
|
|
233
|
+
location: { directory: "/project" },
|
|
234
|
+
projectID: "global",
|
|
235
|
+
}
|
|
236
|
+
for (const delivery of ["steer", "queue"] as const) {
|
|
237
|
+
expect(decode({ ...base, type: "user", payload: { text: "hello" }, delivery }).delivery).toBe(delivery)
|
|
238
|
+
expect(decode({ ...base, type: "synthetic", payload: { text: "context" }, delivery }).delivery).toBe(delivery)
|
|
239
|
+
expect(decode({ ...base, type: "compaction", payload: {}, delivery }).delivery).toBe(delivery)
|
|
240
|
+
expect(decode({ ...base, type: "move", payload: move, delivery }).delivery).toBe(delivery)
|
|
241
|
+
}
|
|
242
|
+
})
|
|
243
|
+
|
|
244
|
+
test("current source limits Any to reviewed boundaries and avoids mutable contract wrappers", async () => {
|
|
245
|
+
const files = [...new Bun.Glob("*.ts").scanSync(path.join(import.meta.dir, "../src"))].filter(
|
|
246
|
+
(file) => !file.endsWith("-v1.ts"),
|
|
247
|
+
)
|
|
248
|
+
const sources = await Promise.all(
|
|
249
|
+
files.map(async (file) => ({ file, source: await Bun.file(new URL(`../src/${file}`, import.meta.url)).text() })),
|
|
250
|
+
)
|
|
251
|
+
const source = sources.map((item) => item.source).join("\n")
|
|
252
|
+
|
|
253
|
+
expect(
|
|
254
|
+
sources
|
|
255
|
+
.filter((item) => item.file !== "provider.ts" && item.file !== "model.ts" && item.file !== "integration.ts")
|
|
256
|
+
.map((item) => item.source)
|
|
257
|
+
.join("\n"),
|
|
258
|
+
).not.toContain("Schema.Any")
|
|
259
|
+
expect(sources.find((item) => item.file === "provider.ts")?.source.match(/Schema\.Any/g)).toHaveLength(3)
|
|
260
|
+
expect(sources.find((item) => item.file === "model.ts")?.source.match(/Schema\.Any/g)).toHaveLength(2)
|
|
261
|
+
expect(sources.find((item) => item.file === "integration.ts")?.source.match(/Schema\.Any/g)).toHaveLength(2)
|
|
262
|
+
expect(source).not.toContain("Schema.mutable")
|
|
263
|
+
})
|
|
264
|
+
|
|
265
|
+
test("assistant content keeps only domain identities", () => {
|
|
266
|
+
expect(SessionMessage.AssistantText.make({ type: "text", text: "hello" })).toEqual({
|
|
267
|
+
type: "text",
|
|
268
|
+
text: "hello",
|
|
269
|
+
})
|
|
270
|
+
expect(
|
|
271
|
+
SessionMessage.AssistantReasoning.make({ type: "reasoning", text: "thinking", native: { id: "opaque" } }),
|
|
272
|
+
).toEqual({ type: "reasoning", text: "thinking", native: { id: "opaque" } })
|
|
273
|
+
expect(
|
|
274
|
+
SessionMessage.AssistantTool.make({
|
|
275
|
+
type: "tool",
|
|
276
|
+
id: "call_1",
|
|
277
|
+
name: "search",
|
|
278
|
+
executed: true,
|
|
279
|
+
native: { itemId: "item_1" },
|
|
280
|
+
state: { status: "streaming", input: "" },
|
|
281
|
+
time: { created: DateTime.makeUnsafe(0) },
|
|
282
|
+
}),
|
|
283
|
+
).not.toHaveProperty("provider")
|
|
284
|
+
})
|
|
285
|
+
|
|
286
|
+
test("reviewed session contracts use their canonical current shapes", () => {
|
|
287
|
+
expect(SessionMessage.Info.ast.annotations?.identifier).toBe("Session.Message.Info")
|
|
288
|
+
expect(SessionInbox.Info.ast.annotations?.identifier).toBe("Session.Inbox.Info")
|
|
289
|
+
expect(Money.USD).not.toBe(Money.USDPerMillionTokens)
|
|
290
|
+
expect(
|
|
291
|
+
FileDiff.Info.make({ file: "src/index.ts", patch: "@@", additions: 1, deletions: 0, status: "modified" }),
|
|
292
|
+
).toEqual({ file: "src/index.ts", patch: "@@", additions: 1, deletions: 0, status: "modified" })
|
|
293
|
+
expect(
|
|
294
|
+
SessionMessage.Shell.make({
|
|
295
|
+
id: SessionMessage.ID.make("msg_shell"),
|
|
296
|
+
type: "shell",
|
|
297
|
+
shellID: Shell.ID.make("sh_test"),
|
|
298
|
+
command: "pwd",
|
|
299
|
+
status: "exited",
|
|
300
|
+
exit: 0,
|
|
301
|
+
time: { created: DateTime.makeUnsafe(0) },
|
|
302
|
+
}),
|
|
303
|
+
).not.toHaveProperty("shell")
|
|
304
|
+
expect(
|
|
305
|
+
SessionMessage.Skill.make({
|
|
306
|
+
id: SessionMessage.ID.make("msg_skill"),
|
|
307
|
+
type: "skill",
|
|
308
|
+
skill: Skill.ID.make("effect"),
|
|
309
|
+
name: Skill.Name.make("Effect"),
|
|
310
|
+
text: "Use Effect",
|
|
311
|
+
time: { created: DateTime.makeUnsafe(0) },
|
|
312
|
+
}),
|
|
313
|
+
).toMatchObject({ skill: "effect", name: "Effect" })
|
|
314
|
+
expect(
|
|
315
|
+
SessionMessage.CompactionFailed.make({
|
|
316
|
+
id: SessionMessage.ID.make("msg_compaction"),
|
|
317
|
+
type: "compaction",
|
|
318
|
+
status: "failed",
|
|
319
|
+
reason: "manual",
|
|
320
|
+
error: { type: "compaction.failed", message: "failed" },
|
|
321
|
+
time: { created: DateTime.makeUnsafe(0) },
|
|
322
|
+
}),
|
|
323
|
+
).not.toHaveProperty("summary")
|
|
324
|
+
})
|
|
325
|
+
|
|
326
|
+
test("keeps shared persisted revert compatibility", () => {
|
|
327
|
+
expect(
|
|
328
|
+
Schema.decodeUnknownSync(Session.Revert)({
|
|
329
|
+
messageID: "msg_legacy",
|
|
330
|
+
snapshot: "tree",
|
|
331
|
+
diff: "legacy patch",
|
|
332
|
+
}),
|
|
333
|
+
).not.toHaveProperty("diff")
|
|
334
|
+
|
|
335
|
+
const revert = Schema.decodeUnknownSync(PersistedRevert)({
|
|
336
|
+
messageID: "msg_legacy",
|
|
337
|
+
snapshot: "tree",
|
|
338
|
+
diff: "legacy patch",
|
|
339
|
+
files: [{ path: "src/index.ts", status: "modified", additions: 1, deletions: 0, patch: "@@" }],
|
|
340
|
+
})
|
|
341
|
+
expect(String(revert.messageID)).toBe("msg_legacy")
|
|
342
|
+
expect(String(revert.snapshot)).toBe("tree")
|
|
343
|
+
expect(revert.files).toEqual([
|
|
344
|
+
{ file: "src/index.ts", status: "modified", additions: 1, deletions: 0, patch: "@@" },
|
|
345
|
+
])
|
|
346
|
+
expect(Schema.encodeSync(PersistedRevert)(revert)).toEqual({
|
|
347
|
+
messageID: "msg_legacy",
|
|
348
|
+
snapshot: "tree",
|
|
349
|
+
files: [{ file: "src/index.ts", status: "modified", additions: 1, deletions: 0, patch: "@@" }],
|
|
350
|
+
})
|
|
351
|
+
})
|
|
352
|
+
})
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test"
|
|
2
|
+
import { Schema } from "effect"
|
|
3
|
+
import { Credential } from "../src/credential.js"
|
|
4
|
+
import { CredentialLegacy } from "../src/credential-legacy.js"
|
|
5
|
+
|
|
6
|
+
const decode = Schema.decodeUnknownSync(CredentialLegacy.Value)
|
|
7
|
+
const legacy = {
|
|
8
|
+
type: "key",
|
|
9
|
+
key: "secret",
|
|
10
|
+
metadata: { imported: true, resourceName: "older" },
|
|
11
|
+
configuration: { resourceName: "answered", accountId: "account" },
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
describe("CredentialLegacy", () => {
|
|
15
|
+
test("decodes key form answers written to configuration before v2.1 into metadata, keeping answers first", () => {
|
|
16
|
+
expect(decode(legacy)).toEqual({
|
|
17
|
+
type: "key",
|
|
18
|
+
key: "secret",
|
|
19
|
+
metadata: { imported: true, resourceName: "answered", accountId: "account" },
|
|
20
|
+
})
|
|
21
|
+
expect(decode({ type: "key", key: "secret", configuration: { resourceName: "answered" } })).toEqual({
|
|
22
|
+
type: "key",
|
|
23
|
+
key: "secret",
|
|
24
|
+
metadata: { resourceName: "answered" },
|
|
25
|
+
})
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
test("decodes current values and exported entries unchanged", () => {
|
|
29
|
+
const current = { type: "key", key: "secret", metadata: { resourceName: "answered" } } as const
|
|
30
|
+
expect(decode(current)).toEqual(current)
|
|
31
|
+
const external = { type: "external", methodID: "azure-cli", metadata: { resourceName: "answered" } } as const
|
|
32
|
+
expect(Schema.encodeSync(Credential.Value)(decode(external))).toEqual(external)
|
|
33
|
+
expect(
|
|
34
|
+
Schema.decodeUnknownSync(CredentialLegacy.Entry)({
|
|
35
|
+
id: "cred_legacy",
|
|
36
|
+
integrationID: "azure",
|
|
37
|
+
label: "Work",
|
|
38
|
+
active: true,
|
|
39
|
+
value: legacy,
|
|
40
|
+
}).value,
|
|
41
|
+
).toEqual(decode(legacy))
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
test("rejects invalid legacy configuration", () => {
|
|
45
|
+
expect(() => decode({ type: "key", key: "secret", configuration: "answered" })).toThrow()
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
test("the public credential schema does not know configuration", () => {
|
|
49
|
+
expect(Schema.decodeUnknownSync(Credential.Value)(legacy)).toEqual({
|
|
50
|
+
type: "key",
|
|
51
|
+
key: "secret",
|
|
52
|
+
metadata: { imported: true, resourceName: "older" },
|
|
53
|
+
})
|
|
54
|
+
})
|
|
55
|
+
})
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test"
|
|
2
|
+
import {
|
|
3
|
+
Agent,
|
|
4
|
+
Config,
|
|
5
|
+
Credential,
|
|
6
|
+
FileSystem,
|
|
7
|
+
Form,
|
|
8
|
+
Integration,
|
|
9
|
+
Permission,
|
|
10
|
+
PersistentPty,
|
|
11
|
+
Project,
|
|
12
|
+
Reference,
|
|
13
|
+
Session,
|
|
14
|
+
Workspace,
|
|
15
|
+
} from "../src/index.js"
|
|
16
|
+
import { EventManifest } from "../src/event-manifest.js"
|
|
17
|
+
import { FileSystemV1 } from "../src/filesystem-v1.js"
|
|
18
|
+
import { McpEvent } from "../src/mcp-event.js"
|
|
19
|
+
import { SessionEvent } from "../src/session-event.js"
|
|
20
|
+
import { SessionID } from "../src/session-id.js"
|
|
21
|
+
import { SessionMessage } from "../src/session-message.js"
|
|
22
|
+
import { WorkspaceEvent } from "../src/workspace-event.js"
|
|
23
|
+
|
|
24
|
+
describe("public event manifest", () => {
|
|
25
|
+
test("owns the complete public event surface", () => {
|
|
26
|
+
expect(EventManifest.ServerDefinitions).toContain(Agent.Event.Updated)
|
|
27
|
+
expect(EventManifest.ServerDefinitions.filter((definition) => definition.type === "agent.updated")).toEqual([
|
|
28
|
+
Agent.Event.Updated,
|
|
29
|
+
])
|
|
30
|
+
expect(EventManifest.Definitions).toContain(Agent.Event.Updated)
|
|
31
|
+
expect(EventManifest.Definitions.filter((definition) => definition.type === "agent.updated")).toEqual([
|
|
32
|
+
Agent.Event.Updated,
|
|
33
|
+
])
|
|
34
|
+
expect(Array.from(EventManifest.Latest.keys())).toEqual(
|
|
35
|
+
Array.from(new Set(EventManifest.Definitions.map((definition) => definition.type))),
|
|
36
|
+
)
|
|
37
|
+
expect(EventManifest.Latest.get("agent.updated")).toBe(Agent.Event.Updated)
|
|
38
|
+
expect(EventManifest.Server.get("mcp.status.changed")).toBe(McpEvent.StatusChanged)
|
|
39
|
+
expect(EventManifest.Server.get("mcp.resources.changed")).toBe(McpEvent.ResourcesChanged)
|
|
40
|
+
expect(EventManifest.Server.get("experimental.mcp.event")).toBe(McpEvent.ExperimentalEvent)
|
|
41
|
+
expect(EventManifest.Server.has("experimental.mcp.subscription.changed")).toBe(false)
|
|
42
|
+
expect(EventManifest.Server.get("session.created")).toBe(SessionEvent.Created)
|
|
43
|
+
expect(EventManifest.Server.get("session.deleted")).toBe(SessionEvent.Deleted)
|
|
44
|
+
expect(EventManifest.Server.get("project.updated")).toBe(Project.Event.Updated)
|
|
45
|
+
expect(EventManifest.Server.has("mcp.tools.changed")).toBe(false)
|
|
46
|
+
expect(Agent.Event.Updated.durable).toBeUndefined()
|
|
47
|
+
expect(EventManifest.Durable.has("agent.updated")).toBe(false)
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
test("uses canonical definitions for current public events", () => {
|
|
51
|
+
expect(Session.Event).toBe(SessionEvent)
|
|
52
|
+
expect(Session.Event.Definitions).toBe(SessionEvent.Definitions)
|
|
53
|
+
expect(Workspace.Event).toBe(WorkspaceEvent)
|
|
54
|
+
expect(Workspace.Event.Definitions).toBe(WorkspaceEvent.Definitions)
|
|
55
|
+
expect(EventManifest.Latest.get("session.step.ended")).toBe(SessionEvent.Step.Ended)
|
|
56
|
+
expect(EventManifest.Latest.get("agent.updated")).toBe(Agent.Event.Updated)
|
|
57
|
+
expect(EventManifest.Latest.get("project.updated")).toBe(Project.Event.Updated)
|
|
58
|
+
expect(Agent.Event.Definitions).toEqual([Agent.Event.Updated])
|
|
59
|
+
expect(Credential.Event.Definitions).toEqual([Credential.Event.Updated, Credential.Event.Switched])
|
|
60
|
+
expect(Project.Event.Definitions).toEqual([Project.Event.Updated])
|
|
61
|
+
expect(Config.Event.Definitions).toEqual([Config.Event.Updated])
|
|
62
|
+
expect(FileSystem.Event.Definitions).toEqual([FileSystem.Event.Changed])
|
|
63
|
+
expect(FileSystemV1.Event.Definitions).toEqual([FileSystemV1.Event.Edited])
|
|
64
|
+
expect(Integration.Event.Definitions).toEqual([Integration.Event.Updated])
|
|
65
|
+
expect(Permission.Event.Definitions).toEqual([Permission.Event.Asked, Permission.Event.Replied])
|
|
66
|
+
expect(PersistentPty.Event.Definitions).toEqual([
|
|
67
|
+
PersistentPty.Event.Added,
|
|
68
|
+
PersistentPty.Event.Removed,
|
|
69
|
+
PersistentPty.Event.Updated,
|
|
70
|
+
])
|
|
71
|
+
expect(Form.Event.Definitions).toEqual([Form.Event.Created, Form.Event.Replied, Form.Event.Cancelled])
|
|
72
|
+
expect(Reference.Event.Definitions).toEqual([Reference.Event.Updated])
|
|
73
|
+
expect(McpEvent.Definitions).toEqual([
|
|
74
|
+
McpEvent.ToolsChanged,
|
|
75
|
+
McpEvent.ResourcesChanged,
|
|
76
|
+
McpEvent.StatusChanged,
|
|
77
|
+
McpEvent.ExperimentalEvent,
|
|
78
|
+
McpEvent.ExperimentalSubscriptionChanged,
|
|
79
|
+
])
|
|
80
|
+
expect(EventManifest.Latest.has("mcp.browser.open.failed")).toBe(false)
|
|
81
|
+
expect(EventManifest.Durable.get("session.step.ended.1")).toBe(SessionEvent.Step.Ended)
|
|
82
|
+
expect(EventManifest.Durable.has("session.step.ended.2")).toBe(false)
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
test("keeps credential events public, canonical, and ephemeral", () => {
|
|
86
|
+
const credentialID = Credential.ID.make("cred_test")
|
|
87
|
+
const integrationID = Integration.ID.make("integration_test")
|
|
88
|
+
|
|
89
|
+
for (const definition of Credential.Event.Definitions) {
|
|
90
|
+
expect(EventManifest.ServerDefinitions).toContain(definition)
|
|
91
|
+
expect(EventManifest.Definitions).toContain(definition)
|
|
92
|
+
expect(EventManifest.Server.get(definition.type)).toBe(definition)
|
|
93
|
+
expect(EventManifest.Latest.get(definition.type)).toBe(definition)
|
|
94
|
+
expect(definition.durability).toBe("ephemeral")
|
|
95
|
+
expect(EventManifest.Durable.has(definition.type)).toBe(false)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
expect(Credential.Event.Updated.data.make({ integrationID, credentialID })).toEqual({ integrationID, credentialID })
|
|
99
|
+
expect(Credential.Event.Switched.data.make({ integrationID, credentialID })).toEqual({
|
|
100
|
+
integrationID,
|
|
101
|
+
credentialID,
|
|
102
|
+
})
|
|
103
|
+
expect(Credential.Event.Switched.data.make({ integrationID, credentialID: null })).toEqual({
|
|
104
|
+
integrationID,
|
|
105
|
+
credentialID: null,
|
|
106
|
+
})
|
|
107
|
+
expect(EventManifest.Server.has("credential.created")).toBe(false)
|
|
108
|
+
expect(EventManifest.Server.has("credential.activated")).toBe(false)
|
|
109
|
+
expect(EventManifest.Server.has("credential.deleted")).toBe(false)
|
|
110
|
+
expect(EventManifest.Server.has("integration.connection.updated")).toBe(false)
|
|
111
|
+
expect(EventManifest.Latest.has("integration.connection.updated")).toBe(false)
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
test("derives durable definitions from explicit definition durability", () => {
|
|
115
|
+
expect(Array.from(EventManifest.Durable.keys()).toSorted()).toEqual(
|
|
116
|
+
[
|
|
117
|
+
"session.created.1",
|
|
118
|
+
"session.deleted.2",
|
|
119
|
+
"session.agent.selected.1",
|
|
120
|
+
"session.model.selected.1",
|
|
121
|
+
"session.moved.1",
|
|
122
|
+
"session.renamed.1",
|
|
123
|
+
"session.metadata.updated.1",
|
|
124
|
+
"session.permissions.1",
|
|
125
|
+
"session.viewed.1",
|
|
126
|
+
"session.archived.1",
|
|
127
|
+
"session.unarchived.1",
|
|
128
|
+
"session.message.content.updated.1",
|
|
129
|
+
"session.usage.recorded.1",
|
|
130
|
+
"session.forked.2",
|
|
131
|
+
"session.inbox.delivered.1",
|
|
132
|
+
"session.inbox.enqueued.1",
|
|
133
|
+
"session.inbox.cancelled.1",
|
|
134
|
+
"session.inbox.delivery.changed.1",
|
|
135
|
+
"session.execution.started.1",
|
|
136
|
+
"session.execution.succeeded.1",
|
|
137
|
+
"session.execution.failed.1",
|
|
138
|
+
"session.execution.interrupted.1",
|
|
139
|
+
"session.instructions.updated.2",
|
|
140
|
+
"session.synthetic.1",
|
|
141
|
+
"session.skill.activated.1",
|
|
142
|
+
"session.shell.started.1",
|
|
143
|
+
"session.shell.ended.1",
|
|
144
|
+
"session.step.started.1",
|
|
145
|
+
"session.step.first-token.1",
|
|
146
|
+
"session.step.streamed.1",
|
|
147
|
+
"session.step.ended.1",
|
|
148
|
+
"session.step.failed.1",
|
|
149
|
+
"session.text.started.1",
|
|
150
|
+
"session.text.ended.1",
|
|
151
|
+
"session.tool.input.started.1",
|
|
152
|
+
"session.tool.input.ended.1",
|
|
153
|
+
"session.tool.called.1",
|
|
154
|
+
"session.tool.success.2",
|
|
155
|
+
"session.tool.failed.2",
|
|
156
|
+
"session.reasoning.started.1",
|
|
157
|
+
"session.reasoning.ended.1",
|
|
158
|
+
"session.retry.scheduled.1",
|
|
159
|
+
"session.compaction.started.1",
|
|
160
|
+
"session.compaction.ended.1",
|
|
161
|
+
"session.compaction.failed.1",
|
|
162
|
+
"session.revert.staged.1",
|
|
163
|
+
"session.revert.cleared.1",
|
|
164
|
+
"session.revert.committed.1",
|
|
165
|
+
"worktree.resolved.1",
|
|
166
|
+
].toSorted(),
|
|
167
|
+
)
|
|
168
|
+
expect(SessionEvent.DurableDefinitions).toEqual([
|
|
169
|
+
...SessionEvent.Definitions.filter((definition) => definition.durability === "durable"),
|
|
170
|
+
SessionEvent.UsageRecorded,
|
|
171
|
+
SessionEvent.MessageContentUpdated,
|
|
172
|
+
])
|
|
173
|
+
expect(SessionEvent.UsageRecorded.durability).toBe("durable")
|
|
174
|
+
expect(EventManifest.Durable.get("session.usage.recorded.1")).toBe(SessionEvent.UsageRecorded)
|
|
175
|
+
expect(SessionEvent.Definitions).not.toContain(SessionEvent.UsageRecorded)
|
|
176
|
+
expect(EventManifest.Definitions).not.toContain(SessionEvent.UsageRecorded)
|
|
177
|
+
expect(EventManifest.ServerDefinitions).not.toContain(SessionEvent.UsageRecorded)
|
|
178
|
+
expect(EventManifest.Latest.has("session.usage.recorded")).toBe(false)
|
|
179
|
+
expect(SessionEvent.UsageUpdated.durability).toBe("ephemeral")
|
|
180
|
+
expect(SessionEvent.Compaction.Delta.durability).toBe("ephemeral")
|
|
181
|
+
expect(SessionEvent.Tool.Progress.durability).toBe("ephemeral")
|
|
182
|
+
expect(EventManifest.Server.get("session.tool.progress")).toBe(SessionEvent.Tool.Progress)
|
|
183
|
+
expect(EventManifest.Durable.has("session.compaction.delta.1")).toBe(false)
|
|
184
|
+
expect(EventManifest.ServerDefinitions).toContain(SessionEvent.UsageUpdated)
|
|
185
|
+
expect(EventManifest.Definitions.every((definition) => definition.durability !== undefined)).toBe(true)
|
|
186
|
+
})
|
|
187
|
+
|
|
188
|
+
test("uses the current Session skill event as durable version 1", () => {
|
|
189
|
+
expect(EventManifest.Durable.get("session.skill.activated.1")).toBe(SessionEvent.Skill.Activated)
|
|
190
|
+
expect(EventManifest.Latest.get("session.skill.activated")).toBe(SessionEvent.Skill.Activated)
|
|
191
|
+
})
|
|
192
|
+
|
|
193
|
+
test("keeps simplified session fragment and tool payloads on durable version 1", () => {
|
|
194
|
+
const sessionID = SessionID.make("ses_test")
|
|
195
|
+
const assistantMessageID = SessionMessage.ID.make("msg_test")
|
|
196
|
+
const text = SessionEvent.Text.Started.data.make({ sessionID, assistantMessageID, ordinal: 0 })
|
|
197
|
+
const reasoning = SessionEvent.Reasoning.Ended.data.make({
|
|
198
|
+
sessionID,
|
|
199
|
+
assistantMessageID,
|
|
200
|
+
ordinal: 0,
|
|
201
|
+
text: "thought",
|
|
202
|
+
native: { signature: "sig" },
|
|
203
|
+
})
|
|
204
|
+
const tool = SessionEvent.Tool.Called.data.make({
|
|
205
|
+
sessionID,
|
|
206
|
+
assistantMessageID,
|
|
207
|
+
id: "call_test",
|
|
208
|
+
input: {},
|
|
209
|
+
executed: true,
|
|
210
|
+
native: { itemId: "item_test" },
|
|
211
|
+
})
|
|
212
|
+
|
|
213
|
+
expect(text).not.toHaveProperty("textID")
|
|
214
|
+
expect(reasoning).not.toHaveProperty("reasoningID")
|
|
215
|
+
expect(reasoning).not.toHaveProperty("providerMetadata")
|
|
216
|
+
expect(tool).not.toHaveProperty("tool")
|
|
217
|
+
expect(tool).not.toHaveProperty("provider")
|
|
218
|
+
expect(SessionEvent.Text.Started.durable?.version).toBe(1)
|
|
219
|
+
expect(SessionEvent.Tool.Called.durable?.version).toBe(1)
|
|
220
|
+
})
|
|
221
|
+
|
|
222
|
+
test("keeps current session deletion minimal", () => {
|
|
223
|
+
const sessionID = SessionID.make("ses_test")
|
|
224
|
+
|
|
225
|
+
expect(SessionEvent.Deleted.data.make({ sessionID })).toEqual({ sessionID })
|
|
226
|
+
expect(SessionEvent.Deleted.durable?.version).toBe(2)
|
|
227
|
+
})
|
|
228
|
+
})
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test"
|
|
2
|
+
import { Schema } from "effect"
|
|
3
|
+
import { Event } from "../src/event.js"
|
|
4
|
+
import { EventLog } from "../src/event-log.js"
|
|
5
|
+
|
|
6
|
+
describe("public event schemas", () => {
|
|
7
|
+
test("definition is pure", () => {
|
|
8
|
+
const definitions = Event.inventory()
|
|
9
|
+
Event.ephemeral({ type: "test.pure", schema: { value: Schema.String } })
|
|
10
|
+
expect(definitions).toEqual([])
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
test("latest selection is independent of declaration order", () => {
|
|
14
|
+
const historical = Event.durable({
|
|
15
|
+
type: "test.versioned",
|
|
16
|
+
durable: { aggregate: "id", version: 1 },
|
|
17
|
+
schema: { id: Schema.String },
|
|
18
|
+
})
|
|
19
|
+
const current = Event.durable({
|
|
20
|
+
type: "test.versioned",
|
|
21
|
+
durable: { aggregate: "id", version: 2 },
|
|
22
|
+
schema: { id: Schema.String, value: Schema.String },
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
expect(Event.latest([historical, current]).get(current.type)).toBe(current)
|
|
26
|
+
expect(Event.latest([current, historical]).get(current.type)).toBe(current)
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
test("durable definitions are indexed by type and version", () => {
|
|
30
|
+
const definition = Event.durable({
|
|
31
|
+
type: "test.durable",
|
|
32
|
+
durable: { aggregate: "id", version: 1 },
|
|
33
|
+
schema: { id: Schema.String },
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
expect(Event.durableMap([definition]).get("test.durable.1")).toBe(definition)
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
test("synced marker encodes the captured watermark", () => {
|
|
40
|
+
expect(
|
|
41
|
+
Schema.encodeSync(EventLog.Synced)({
|
|
42
|
+
type: "log.synced",
|
|
43
|
+
aggregateID: "ses_test",
|
|
44
|
+
seq: Event.Seq.make(1),
|
|
45
|
+
}),
|
|
46
|
+
).toEqual({ type: "log.synced", aggregateID: "ses_test", seq: 1 })
|
|
47
|
+
expect(Schema.encodeSync(EventLog.Synced)({ type: "log.synced", aggregateID: "ses_test" })).toEqual({
|
|
48
|
+
type: "log.synced",
|
|
49
|
+
aggregateID: "ses_test",
|
|
50
|
+
})
|
|
51
|
+
})
|
|
52
|
+
})
|