@zyro-sec/schema 1.0.1 → 1.0.3

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.
Files changed (136) hide show
  1. package/AGENTS.md +95 -95
  2. package/package.json +5 -1
  3. package/script/build.ts +9 -9
  4. package/script/config-schema.ts +86 -86
  5. package/script/config-v1.json +1311 -1311
  6. package/script/pack.ts +5 -5
  7. package/src/agent.ts +68 -68
  8. package/src/artifact.ts +81 -81
  9. package/src/automation.ts +224 -224
  10. package/src/blob-store.ts +25 -25
  11. package/src/command.ts +18 -18
  12. package/src/config/agent.ts +26 -26
  13. package/src/config/command.ts +14 -14
  14. package/src/config/compaction.ts +27 -27
  15. package/src/config/experimental.ts +72 -72
  16. package/src/config/flag.ts +39 -39
  17. package/src/config/formatter.ts +13 -13
  18. package/src/config/lsp.ts +19 -19
  19. package/src/config/mcp.ts +22 -22
  20. package/src/config/media.ts +15 -15
  21. package/src/config/model.ts +37 -37
  22. package/src/config/plugin.ts +14 -14
  23. package/src/config/policy.ts +57 -57
  24. package/src/config/provider.ts +122 -122
  25. package/src/config/reference.ts +23 -23
  26. package/src/config/shell.ts +10 -10
  27. package/src/config/tool-output.ts +9 -9
  28. package/src/config/warming.ts +21 -21
  29. package/src/config/watcher.ts +8 -8
  30. package/src/config/websearch.ts +17 -17
  31. package/src/config/worktree.ts +10 -10
  32. package/src/config.ts +149 -149
  33. package/src/connection.ts +38 -38
  34. package/src/credential-legacy.ts +29 -29
  35. package/src/credential.ts +78 -78
  36. package/src/durable-event-manifest.ts +7 -7
  37. package/src/event-log.ts +21 -21
  38. package/src/event-manifest.ts +108 -108
  39. package/src/event.ts +205 -205
  40. package/src/file-diff.ts +25 -25
  41. package/src/filesystem-v1.ts +1 -1
  42. package/src/filesystem.ts +48 -48
  43. package/src/form.ts +177 -177
  44. package/src/generate.ts +292 -292
  45. package/src/goal.ts +46 -46
  46. package/src/identifier.ts +32 -32
  47. package/src/index.ts +51 -51
  48. package/src/installation-event.ts +20 -20
  49. package/src/instruction-entry.ts +40 -40
  50. package/src/instruction.ts +25 -25
  51. package/src/integration-id.ts +13 -13
  52. package/src/integration.ts +129 -129
  53. package/src/job.ts +79 -79
  54. package/src/legacy-event.ts +1 -1
  55. package/src/llm.ts +6 -6
  56. package/src/location-event.ts +8 -8
  57. package/src/location.ts +36 -36
  58. package/src/lsp-event.ts +7 -7
  59. package/src/mcp-event.ts +63 -63
  60. package/src/mcp.ts +171 -171
  61. package/src/model-compatibility.ts +55 -55
  62. package/src/model.ts +176 -176
  63. package/src/models-dev.ts +9 -9
  64. package/src/money.ts +18 -18
  65. package/src/permission-saved.ts +25 -25
  66. package/src/permission-v1.ts +1 -1
  67. package/src/permission.ts +67 -67
  68. package/src/persistent-pty.ts +73 -73
  69. package/src/plugin.ts +62 -62
  70. package/src/project-id.ts +9 -9
  71. package/src/project.ts +62 -62
  72. package/src/prompt-input.ts +33 -33
  73. package/src/prompt.ts +117 -117
  74. package/src/provider.ts +136 -136
  75. package/src/pty-ticket.ts +10 -10
  76. package/src/pty.ts +61 -61
  77. package/src/push.ts +86 -86
  78. package/src/question.ts +22 -22
  79. package/src/reference.ts +40 -40
  80. package/src/rpc.ts +167 -167
  81. package/src/schema.ts +41 -41
  82. package/src/server-event.ts +8 -8
  83. package/src/session-error.ts +14 -14
  84. package/src/session-event.ts +739 -739
  85. package/src/session-fork.ts +10 -10
  86. package/src/session-id.ts +12 -12
  87. package/src/session-inbox.ts +102 -102
  88. package/src/session-legacy.ts +117 -117
  89. package/src/session-message.ts +352 -352
  90. package/src/session-metadata.ts +11 -11
  91. package/src/session-revert.ts +86 -86
  92. package/src/session-stats.ts +68 -68
  93. package/src/session-status-event.ts +53 -53
  94. package/src/session-transfer.ts +11 -11
  95. package/src/session-v1.ts +1 -1
  96. package/src/session.ts +147 -147
  97. package/src/shell.ts +90 -90
  98. package/src/skill.ts +68 -68
  99. package/src/snapshot.ts +6 -6
  100. package/src/token-usage.ts +18 -18
  101. package/src/tool.ts +143 -143
  102. package/src/tui-event.ts +59 -59
  103. package/src/usage-limits.ts +76 -76
  104. package/src/v1/filesystem.ts +11 -11
  105. package/src/v1/legacy-event.ts +18 -18
  106. package/src/v1/permission.ts +66 -66
  107. package/src/v1/session.ts +667 -667
  108. package/src/vcs-event.ts +14 -14
  109. package/src/vcs.ts +41 -41
  110. package/src/websearch.ts +44 -44
  111. package/src/workspace-event.ts +32 -32
  112. package/src/workspace-id.ts +19 -19
  113. package/src/workspace.ts +20 -20
  114. package/src/worktree-event.ts +22 -22
  115. package/src/worktree.ts +109 -109
  116. package/tsconfig.build.json +11 -11
  117. package/tsconfig.json +14 -14
  118. package/test/agent.test.ts +0 -10
  119. package/test/automation.test.ts +0 -48
  120. package/test/compatibility.test.ts +0 -10
  121. package/test/config.test.ts +0 -194
  122. package/test/contract-hygiene.test.ts +0 -352
  123. package/test/credential-legacy.test.ts +0 -55
  124. package/test/event-manifest.test.ts +0 -228
  125. package/test/event.test.ts +0 -52
  126. package/test/legacy-event.test.ts +0 -46
  127. package/test/mcp.test.ts +0 -37
  128. package/test/model.test.ts +0 -104
  129. package/test/session-cursor.test.ts +0 -16
  130. package/test/session-error.test.ts +0 -51
  131. package/test/session-legacy.test.ts +0 -178
  132. package/test/session-terminal.test.ts +0 -50
  133. package/test/token-usage.test.ts +0 -18
  134. package/test/v1-isolation.test.ts +0 -26
  135. package/test/vcs.test.ts +0 -23
  136. package/test/worktree.test.ts +0 -45
package/tsconfig.json CHANGED
@@ -1,14 +1,14 @@
1
- {
2
- "$schema": "https://json.schemastore.org/tsconfig",
3
- "extends": "@tsconfig/bun/tsconfig.json",
4
- "compilerOptions": {
5
- "types": ["bun"],
6
- "noUnusedLocals": true,
7
- "lib": ["ESNext", "DOM", "DOM.Iterable"],
8
- "module": "NodeNext",
9
- "moduleResolution": "NodeNext",
10
- "allowImportingTsExtensions": false,
11
- "allowJs": false,
12
- "noUncheckedIndexedAccess": false
13
- }
14
- }
1
+ {
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "extends": "@tsconfig/bun/tsconfig.json",
4
+ "compilerOptions": {
5
+ "types": ["bun"],
6
+ "noUnusedLocals": true,
7
+ "lib": ["ESNext", "DOM", "DOM.Iterable"],
8
+ "module": "NodeNext",
9
+ "moduleResolution": "NodeNext",
10
+ "allowImportingTsExtensions": false,
11
+ "allowJs": false,
12
+ "noUncheckedIndexedAccess": false
13
+ }
14
+ }
@@ -1,10 +0,0 @@
1
- import { expect, test } from "bun:test"
2
- import { Schema } from "effect"
3
- import { Agent } from "../src/agent.js"
4
-
5
- test("Agent.Color preserves configured colors at the public boundary", () => {
6
- const encode = Schema.encodeSync(Agent.Color)
7
-
8
- expect(encode("info")).toBe("info")
9
- expect(encode("custom-color")).toBe("custom-color")
10
- })
@@ -1,48 +0,0 @@
1
- import { expect, test } from "bun:test"
2
- import { Result, Schema } from "effect"
3
- import { Agent } from "../src/agent.js"
4
- import { Automation } from "../src/automation.js"
5
-
6
- test("event triggers round-trip producer arguments and omit absent ones", () => {
7
- const event = { type: "event", server: "ci", event: "build.changed" } as const
8
- const encode = Schema.encodeSync(Automation.Trigger)
9
- const decode = Schema.decodeUnknownSync(Automation.Trigger)
10
- expect(encode({ ...event, args: undefined })).toStrictEqual(event)
11
- const filtered = { ...event, args: { build: 7 } }
12
- expect(encode(decode(filtered))).toStrictEqual(filtered)
13
- })
14
-
15
- test("code results independently keep JSON state, stop, or hand off one prompt", () => {
16
- for (const value of [
17
- null,
18
- {},
19
- { state: null },
20
- { done: true },
21
- { send: { prompt: "ready" } },
22
- {
23
- state: { nested: [1, "two"] },
24
- done: false,
25
- send: { prompt: "triage", to: { subagent: Agent.ID.make("reviewer") } },
26
- },
27
- ])
28
- expect(Result.getOrThrow(Automation.decodeCodeResult(value))).toEqual(value)
29
- })
30
-
31
- test("code results reject unsupported destinations and malformed sends instead of stripping keys", () => {
32
- for (const send of [
33
- null,
34
- [],
35
- [{ prompt: "one" }, { prompt: "two" }],
36
- {},
37
- { prompt: "" },
38
- { prompt: " \n " },
39
- { prompt: "x", session: "ses_other" },
40
- { prompt: "x", to: {} },
41
- { prompt: "x", to: { session: "ses_other" } },
42
- { prompt: "x", to: { subagent: "helper", session: "ses_other" } },
43
- { prompt: "x", to: { subagent: "" } },
44
- { prompt: "x", to: { newSession: true } },
45
- ])
46
- expect(Result.isFailure(Automation.decodeCodeResult({ state: 1, done: true, send }))).toBe(true)
47
- expect(Result.isFailure(Automation.decodeCodeResult({ done: "yes", send: { prompt: "x" } }))).toBe(true)
48
- })
@@ -1,10 +0,0 @@
1
- import { describe, expect, test } from "bun:test"
2
- import { FileSystem } from "../src/filesystem.js"
3
-
4
- describe("schema compatibility", () => {
5
- test("moved class schemas remain constructible", () => {
6
- const input = new FileSystem.FindInput({ query: "src" })
7
- expect(input).toBeInstanceOf(FileSystem.FindInput)
8
- expect(input.query).toBe("src")
9
- })
10
- })
@@ -1,194 +0,0 @@
1
- import { describe, expect, test } from "bun:test"
2
- import { Schema } from "effect"
3
- import { Config } from "../src/config.js"
4
- import { ConfigAgent } from "../src/config/agent.js"
5
- import { ConfigFlag } from "../src/config/flag.js"
6
- import { ConfigMCP } from "../src/config/mcp.js"
7
- import { ConfigPolicy } from "../src/config/policy.js"
8
- import { ConfigProvider } from "../src/config/provider.js"
9
- import { Mcp } from "../src/mcp.js"
10
- import { Provider } from "../src/provider.js"
11
- import { AbsolutePath } from "../src/schema.js"
12
- import { WebSearch } from "../src/websearch.js"
13
-
14
- describe("Config.Entry", () => {
15
- test("round-trips tool.use and rejects unsupported action spellings", () => {
16
- const input = {
17
- experimental: {
18
- policies: [
19
- { action: "tool.use", resource: "shell:*", effect: "deny" },
20
- { action: "tool.use", resource: "shell:git *", effect: "allow" },
21
- ],
22
- },
23
- } as const
24
- const decoded = Schema.decodeUnknownSync(Config.Info)(input)
25
- expect(Schema.encodeSync(Config.Info)(decoded)).toEqual(input)
26
- for (const action of ["permission", "tool.execute"])
27
- expect(() =>
28
- Schema.decodeUnknownSync(Config.Info)({
29
- experimental: { policies: [{ action, resource: "*", effect: "deny" }] },
30
- }),
31
- ).toThrow()
32
- })
33
-
34
- test("round-trips websearch.use statements", () => {
35
- const input = {
36
- policies: [
37
- { action: "websearch.use", resource: "*", effect: "deny" },
38
- { action: "websearch.use", resource: "opencode", effect: "allow" },
39
- ],
40
- } as const
41
- expect(Schema.encodeSync(Config.Info)(Schema.decodeUnknownSync(Config.Info)(input))).toEqual(input)
42
- })
43
-
44
- test("normalizes legacy prefixed integration.use statements into mcp.use, skill.use and plugin.use", () => {
45
- const decode = Schema.decodeUnknownSync(Schema.Array(ConfigPolicy.Info))
46
- expect(
47
- decode([
48
- { action: "integration.use", resource: "mcp:*", effect: "deny" },
49
- { action: "integration.use", resource: "mcp:github", effect: "allow" },
50
- { action: "integration.use", resource: "skill:team:review", effect: "deny" },
51
- { action: "integration.use", resource: "plugin:@acme/plugin", effect: "deny" },
52
- { action: "integration.use", resource: "*", effect: "deny" },
53
- { action: "integration.use", resource: "opencode#org_01", effect: "allow" },
54
- { action: "integration.use", resource: "https://ai.acme.com", effect: "allow" },
55
- { action: "integration.use", resource: "constructor:x", effect: "allow" },
56
- { action: "integration.connect", resource: "mcp:x", effect: "allow" },
57
- ]),
58
- ).toEqual([
59
- { action: "mcp.use", resource: "*", effect: "deny" },
60
- { action: "mcp.use", resource: "github", effect: "allow" },
61
- { action: "skill.use", resource: "team:review", effect: "deny" },
62
- { action: "plugin.use", resource: "@acme/plugin", effect: "deny" },
63
- // A bare wildcard keeps its action, which now means every integration.
64
- { action: "integration.use", resource: "*", effect: "deny" },
65
- { action: "integration.use", resource: "opencode#org_01", effect: "allow" },
66
- { action: "integration.use", resource: "https://ai.acme.com", effect: "allow" },
67
- { action: "integration.use", resource: "constructor:x", effect: "allow" },
68
- { action: "integration.connect", resource: "mcp:x", effect: "allow" },
69
- ])
70
- // Config documents decode through the same schema, top-level and experimental alike.
71
- const config = Schema.decodeUnknownSync(Config.Info)({
72
- policies: [{ action: "integration.use", resource: "skill:deploy", effect: "deny" }],
73
- experimental: { policies: [{ action: "integration.use", resource: "plugin:local", effect: "deny" }] },
74
- })
75
- expect(config.policies).toEqual([{ action: "skill.use", resource: "deploy", effect: "deny" }])
76
- expect(config.experimental?.policies).toEqual([{ action: "plugin.use", resource: "local", effect: "deny" }])
77
- })
78
-
79
- test("accepts directory-only worktree config and omits it when absent", () => {
80
- const decode = Schema.decodeUnknownSync(Config.Info)
81
- const input = { worktree: { directory: "../worktrees" } }
82
- expect(Schema.encodeSync(Config.Info)(decode(input))).toEqual(input)
83
- expect(Schema.encodeSync(Config.Info)(new Config.Info({ worktree: undefined }))).not.toHaveProperty("worktree")
84
- expect(() => decode({ worktree: {} })).toThrow()
85
- expect(() => decode({ worktree: { directory: " " } })).toThrow()
86
- expect(() => decode({ worktree: { directory: false } })).toThrow()
87
- })
88
- test("round-trips canonical provider IDs without changing config keys", () => {
89
- const input = { providers: { "console-anthropic": { canonical: "anthropic" } } }
90
- const decoded = Schema.decodeUnknownSync(Config.Info)(input)
91
- expect(decoded.providers?.["console-anthropic"]?.canonical).toBe(Provider.ID.anthropic)
92
- expect(Schema.encodeSync(Config.Info)(decoded)).toEqual(input)
93
- expect(() => Schema.decodeUnknownSync(Config.Info)({ providers: { custom: { canonical: 1 } } })).toThrow()
94
- })
95
-
96
- test("round-trips disabled and numeric provider HTTP timeouts", () => {
97
- const input = {
98
- providers: { custom: { settings: { timeout: 900_000, headerTimeout: 600_000, chunkTimeout: false } } },
99
- } as const
100
- const decoded = Schema.decodeUnknownSync(Config.Info)(input)
101
- expect(Schema.encodeSync(Config.Info)(decoded)).toEqual(input)
102
- expect(Schema.decodeUnknownSync(Provider.Settings)(decoded.providers?.custom?.settings)).toMatchObject({
103
- timeout: 900_000,
104
- headerTimeout: 600_000,
105
- chunkTimeout: false,
106
- })
107
- expect(Schema.decodeUnknownSync(Provider.Settings)({ headerTimeout: false, chunkTimeout: 600_000 })).toMatchObject({
108
- headerTimeout: false,
109
- chunkTimeout: 600_000,
110
- })
111
- })
112
-
113
- test("accepts disabled, fixed, and random web search selection", () => {
114
- const decode = Schema.decodeUnknownSync(Config.Info)
115
-
116
- expect(decode({ websearch: false }).websearch).toBe(false)
117
- expect(decode({ websearch: { provider: "exa" } }).websearch).toEqual({ provider: WebSearch.ID.make("exa") })
118
- expect(decode({ websearch: { provider: "random" } }).websearch).toEqual({ provider: "random" })
119
- })
120
-
121
- test("round-trips every configuration entry type", () => {
122
- const entries = [
123
- new Config.Document({
124
- type: "document",
125
- path: AbsolutePath.make("/project/opencode.json"),
126
- info: new Config.Info({
127
- permissions: [
128
- { action: "shell", resource: "*", effect: "ask" },
129
- { action: "shell", resource: "git status", effect: "allow" },
130
- ],
131
- }),
132
- }),
133
- new Config.Document({ type: "document", info: new Config.Info({ shell: "/bin/zsh" }) }),
134
- new Config.Directory({ type: "directory", path: AbsolutePath.make("/project/.opencode") }),
135
- ]
136
-
137
- const encoded = Schema.encodeSync(Schema.Array(Config.Entry))(entries)
138
- const decoded = Schema.decodeUnknownSync(Schema.Array(Config.Entry))(encoded)
139
-
140
- expect(decoded).toEqual(entries)
141
- expect(decoded[0]).toBeInstanceOf(Config.Document)
142
- expect(decoded[1]).not.toHaveProperty("path")
143
- expect(decoded.map((entry) => entry.type)).toEqual(["document", "document", "directory"])
144
- expect(decoded[0]?.type === "document" ? decoded[0].info.permissions : undefined).toEqual([
145
- { action: "shell", resource: "*", effect: "ask" },
146
- { action: "shell", resource: "git status", effect: "allow" },
147
- ])
148
- })
149
-
150
- test("has a stable public identifier", () => {
151
- expect(Config.Entry.ast.annotations?.identifier).toBe("Config.Entry")
152
- })
153
-
154
- test("omits undefined optional properties while encoding", () => {
155
- const entry = new Config.Document({
156
- type: "document",
157
- path: undefined,
158
- info: new Config.Info({
159
- default_agent: undefined,
160
- agents: { reviewer: new ConfigAgent.Info({ description: undefined }) },
161
- mcp: new ConfigMCP.Info({
162
- timeout: undefined,
163
- servers: {
164
- docs: new Mcp.RemoteConfig({
165
- type: "remote",
166
- url: "https://example.com/mcp",
167
- headers: undefined,
168
- oauth: new Mcp.OAuthConfig({ client_id: undefined }),
169
- }),
170
- },
171
- }),
172
- providers: { custom: new ConfigProvider.Info({ canonical: undefined, headers: undefined }) },
173
- }),
174
- })
175
- const encoded = Schema.encodeSync(Config.Entry)(entry)
176
- if (encoded.type !== "document") throw new Error("Expected a config document")
177
-
178
- expect(encoded).not.toHaveProperty("path")
179
- expect(encoded.info).not.toHaveProperty("default_agent")
180
- expect(encoded.info.agents?.reviewer).not.toHaveProperty("description")
181
- expect(encoded.info.mcp).not.toHaveProperty("timeout")
182
- const docs = encoded.info.mcp?.servers?.docs
183
- if (docs?.type !== "remote" || docs.oauth === false) throw new Error("Expected a remote MCP server")
184
- expect(docs).not.toHaveProperty("headers")
185
- expect(docs.oauth).not.toHaveProperty("client_id")
186
- expect(encoded.info.providers?.custom).not.toHaveProperty("headers")
187
- expect(encoded.info.providers?.custom).not.toHaveProperty("canonical")
188
- })
189
- })
190
-
191
- test("wildcard switches are reserved flag names", () => {
192
- expect(ConfigFlag.registry).not.toHaveProperty("all_flags")
193
- expect(ConfigFlag.registry).not.toHaveProperty(ConfigFlag.wildcard)
194
- })
@@ -1,352 +0,0 @@
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
- })