@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
@@ -1,178 +0,0 @@
1
- import { describe, expect, test } from "bun:test"
2
- import { Schema } from "effect"
3
- import { Durable } from "../src/durable-event-manifest.js"
4
- import { SessionLegacy } from "../src/session-legacy.js"
5
- import { SessionMessage } from "../src/session-message.js"
6
-
7
- const ref = { sessionID: "ses_legacy", assistantMessageID: "msg_legacy" }
8
- const tokens = { input: 0, output: 0, reasoning: 0, cache: { read: 0, write: 0 } }
9
- const native = { signature: "kept" }
10
- const textPart = { type: "text", text: "hi", state: native }
11
- const result = { result: "kept" }
12
- const toolPart = {
13
- type: "tool",
14
- id: "call",
15
- name: "search",
16
- providerState: native,
17
- providerResultState: result,
18
- state: { status: "streaming", input: "" },
19
- time: { created: 0 },
20
- }
21
-
22
- const decode = (type: string, data: unknown) => {
23
- const definition = Durable.get(type)
24
- if (!definition) throw new Error(`Unknown durable event ${type}`)
25
- return Schema.decodeUnknownSync(definition.data)(SessionLegacy.event(definition.type, data))
26
- }
27
-
28
- describe("SessionLegacy", () => {
29
- test.each([
30
- ["session.text.ended.1", { ...ref, ordinal: 0, text: "hi", state: native }],
31
- ["session.reasoning.started.1", { ...ref, ordinal: 0, state: native }],
32
- ["session.reasoning.ended.1", { ...ref, ordinal: 0, text: "thought", state: native }],
33
- ["session.tool.called.1", { ...ref, id: "call", input: {}, executed: true, state: native }],
34
- ["session.step.ended.1", { ...ref, finish: "stop", providerState: native, cost: 0, tokens }],
35
- [
36
- "session.step.failed.1",
37
- { ...ref, error: { type: "provider.unknown", message: "failed" }, providerState: native },
38
- ],
39
- [
40
- "session.compaction.ended.1",
41
- { sessionID: ref.sessionID, reason: "auto", text: "s", recent: "", providerState: native },
42
- ],
43
- ])("upgrades %s", (type, data) => {
44
- expect(decode(type, data)).toMatchObject({ native })
45
- })
46
-
47
- test.each([
48
- ["session.tool.success.2", { ...ref, id: "call", content: [{ type: "text", text: "done" }], executed: true }],
49
- [
50
- "session.tool.failed.2",
51
- { ...ref, id: "call", error: { type: "tool.execution", message: "failed" }, executed: true },
52
- ],
53
- ])("upgrades %s result native data", (type, data) => {
54
- expect(decode(type, { ...data, resultState: native })).toMatchObject({ native })
55
- })
56
-
57
- test("upgrades replaced assistant content without touching tool status", () => {
58
- expect(
59
- decode("session.message.content.updated.1", {
60
- sessionID: ref.sessionID,
61
- messageID: ref.assistantMessageID,
62
- content: [textPart, toolPart],
63
- }),
64
- ).toMatchObject({
65
- content: [
66
- { type: "text", native },
67
- { type: "tool", native: { ...native, ...result }, state: { status: "streaming", input: "" } },
68
- ],
69
- })
70
- })
71
-
72
- test("leaves current and unrelated payloads unchanged", () => {
73
- const current = { ...ref, ordinal: 0, text: "hi", native }
74
- expect(SessionLegacy.event("session.text.ended", current)).toBe(current)
75
- const success = { ...ref, id: "call", content: [], executed: true, native }
76
- expect(SessionLegacy.event("session.tool.success", success)).toBe(success)
77
- const user = { type: "user", text: "hi", state: native }
78
- expect(SessionLegacy.message("user", user)).toBe(user)
79
- })
80
-
81
- test("keeps the current name when a payload carries both", () => {
82
- expect(SessionLegacy.event("session.text.ended", { text: "hi", state: { old: true }, native })).toEqual({
83
- text: "hi",
84
- native,
85
- })
86
- })
87
-
88
- test("merges legacy tool result data over call data without touching lifecycle state", () => {
89
- expect(
90
- SessionLegacy.message("assistant", {
91
- content: [
92
- {
93
- ...toolPart,
94
- native: { itemId: "shared", call: true },
95
- providerResultState: { itemId: "shared", result: true },
96
- },
97
- ],
98
- }),
99
- ).toMatchObject({
100
- content: [{ native: { itemId: "shared", call: true, result: true }, state: toolPart.state }],
101
- })
102
- })
103
-
104
- test("upgrades assistant and compaction messages", () => {
105
- expect(SessionLegacy.message("assistant", { providerState: native, content: [textPart, toolPart] })).toEqual({
106
- native,
107
- content: [
108
- { type: "text", text: "hi", native },
109
- {
110
- type: "tool",
111
- id: "call",
112
- name: "search",
113
- native: { ...native, ...result },
114
- state: toolPart.state,
115
- time: toolPart.time,
116
- },
117
- ],
118
- })
119
- expect(SessionLegacy.message("compaction", { status: "completed", providerState: native })).toEqual({
120
- status: "completed",
121
- native,
122
- })
123
- })
124
-
125
- test("moves the kept text a compaction stored in recent into metadata", () => {
126
- expect(
127
- SessionLegacy.message("compaction", { status: "completed", recent: "[User]: kept", metadata: { source: "x" } }),
128
- ).toEqual({ status: "completed", metadata: { recent: "[User]: kept", source: "x" } })
129
- expect(SessionLegacy.message("compaction", { status: "completed", recent: "" })).toEqual({ status: "completed" })
130
- expect(
131
- SessionLegacy.event("session.compaction.ended", { reason: "auto", text: "s", recent: "[User]: kept" }),
132
- ).toEqual({ reason: "auto", text: "s" })
133
- expect(SessionLegacy.event("session.compaction.started", { reason: "auto", recent: "" })).toEqual({
134
- reason: "auto",
135
- })
136
- })
137
-
138
- test("moves a provider compaction's window from providerContext into native", () => {
139
- const messages = [{ role: "assistant", content: [{ type: "compaction", provider: "openai", encrypted: "opaque" }] }]
140
- const providerContext = { version: 1, provenance: { providerID: "openai" }, messages }
141
- expect(
142
- SessionLegacy.message("compaction", {
143
- status: "completed",
144
- summary: "",
145
- native: { step: true },
146
- providerContext,
147
- }),
148
- ).toEqual({ status: "completed", summary: "", native: { messages } })
149
- expect(SessionLegacy.event("session.compaction.ended", { reason: "auto", text: "", providerContext })).toEqual({
150
- reason: "auto",
151
- text: "",
152
- native: { messages },
153
- })
154
- })
155
-
156
- test("upgrades exported messages before decoding", () => {
157
- const message = {
158
- id: "msg_legacy",
159
- type: "assistant",
160
- agent: "build",
161
- model: { providerID: "anthropic", id: "claude" },
162
- providerState: native,
163
- content: [textPart, { type: "reasoning", text: "thought", state: native }],
164
- time: { created: 0 },
165
- }
166
- expect(
167
- Schema.decodeUnknownSync(Schema.Array(SessionMessage.Info))(SessionLegacy.messages([message])),
168
- ).toMatchObject([
169
- {
170
- native,
171
- content: [
172
- { type: "text", native },
173
- { type: "reasoning", native },
174
- ],
175
- },
176
- ])
177
- })
178
- })
@@ -1,50 +0,0 @@
1
- import { expect, test } from "bun:test"
2
- import { Schema } from "effect"
3
- import { SessionEvent } from "../src/session-event.js"
4
- import { SessionMessage } from "../src/session-message.js"
5
-
6
- const assistant = {
7
- id: "msg_terminal",
8
- type: "assistant" as const,
9
- agent: "build",
10
- model: { providerID: "openai", id: "gpt-test" },
11
- content: [],
12
- time: { created: 0 },
13
- }
14
-
15
- test("assistant terminal diagnostics remain optional and round trip", () => {
16
- const decode = Schema.decodeUnknownSync(SessionMessage.Assistant)
17
- const encode = Schema.encodeSync(SessionMessage.Assistant)
18
-
19
- expect(encode(decode(assistant))).toEqual(assistant)
20
- expect(
21
- encode(
22
- decode({
23
- ...assistant,
24
- finish: "content-filter",
25
- rawFinish: "SAFETY",
26
- native: { promptFeedback: { blockReason: "SAFETY" } },
27
- }),
28
- ),
29
- ).toMatchObject({
30
- finish: "content-filter",
31
- rawFinish: "SAFETY",
32
- native: { promptFeedback: { blockReason: "SAFETY" } },
33
- })
34
- })
35
-
36
- test("failed steps only override the assistant finish for content filters", () => {
37
- const decode = Schema.decodeUnknownSync(SessionEvent.Step.Failed.data)
38
- const input = {
39
- sessionID: "ses_terminal",
40
- assistantMessageID: "msg_terminal",
41
- error: { type: "provider.content-filter", message: "Blocked" },
42
- }
43
-
44
- expect(decode(input)).toMatchObject(input)
45
- expect(decode({ ...input, finish: "content-filter", rawFinish: "SAFETY" })).toMatchObject({
46
- finish: "content-filter",
47
- rawFinish: "SAFETY",
48
- })
49
- expect(() => decode({ ...input, finish: "stop" })).toThrow()
50
- })
@@ -1,18 +0,0 @@
1
- import { expect, test } from "bun:test"
2
- import { TokenUsage } from "../src/token-usage.js"
3
-
4
- test("totals every token category", () => {
5
- expect(TokenUsage.total({ input: 1, output: 2, reasoning: 4, cache: { read: 8, write: 16 } })).toBe(31)
6
- })
7
-
8
- test("supports zero and large usage totals without rounding", () => {
9
- expect(TokenUsage.total({ input: 0, output: 0, reasoning: 0, cache: { read: 0, write: 0 } })).toBe(0)
10
- expect(
11
- TokenUsage.total({
12
- input: 1_000_000_000,
13
- output: 2_000_000_000,
14
- reasoning: 3,
15
- cache: { read: 4_000_000_000, write: 5 },
16
- }),
17
- ).toBe(7_000_000_008)
18
- })
@@ -1,26 +0,0 @@
1
- import { expect, test } from "bun:test"
2
- import path from "node:path"
3
- import { LegacyEventV1 } from "../src/legacy-event.js"
4
- import { PermissionV1 } from "../src/permission-v1.js"
5
- import { SessionV1 } from "../src/session-v1.js"
6
- const isolatedLegacyEvent = await import("../src/v1/legacy-event.js")
7
- const isolatedPermission = await import("../src/v1/permission.js")
8
- const isolatedSession = await import("../src/v1/session.js")
9
-
10
- test("compatibility entrypoints preserve isolated V1 schema identity", () => {
11
- expect(LegacyEventV1).toBe(isolatedLegacyEvent.LegacyEventV1)
12
- expect(PermissionV1).toBe(isolatedPermission.PermissionV1)
13
- expect(SessionV1).toBe(isolatedSession.SessionV1)
14
- })
15
-
16
- test("current source does not import the V1 subtree directly", async () => {
17
- const allowed = new Set(["filesystem-v1.ts", "legacy-event.ts", "permission-v1.ts", "session-v1.ts"])
18
- const files = [...new Bun.Glob("*.ts").scanSync(path.join(import.meta.dir, "../src"))].filter(
19
- (file) => !allowed.has(file),
20
- )
21
- const directImports = await Promise.all(
22
- files.map(async (file) => ({ file, source: await Bun.file(new URL(`../src/${file}`, import.meta.url)).text() })),
23
- ).then((values) => values.filter((value) => value.source.includes('from "./v1/')))
24
-
25
- expect(directImports).toEqual([])
26
- })
package/test/vcs.test.ts DELETED
@@ -1,23 +0,0 @@
1
- import { expect, test } from "bun:test"
2
- import { Schema } from "effect"
3
- import { Vcs } from "../src/vcs.js"
4
-
5
- test("review base preserves its stable identity and local provenance", () => {
6
- expect(Vcs.Base.ast.annotations?.identifier).toBe("Vcs.Base")
7
- const base = { name: "release", ref: "refs/heads/release" }
8
- for (const source of ["reflog", "default"] as const) {
9
- expect(Schema.encodeSync(Vcs.Base)(Schema.decodeUnknownSync(Vcs.Base)({ ...base, source }))).toEqual({
10
- ...base,
11
- source,
12
- })
13
- }
14
- expect(() => Schema.decodeUnknownSync(Vcs.Base)({ ...base, source: "configured" })).toThrow()
15
- expect(() => Schema.decodeUnknownSync(Vcs.Base)({ ...base, source: "worktree" })).toThrow()
16
- })
17
-
18
- test("review modes preserve shipped working and combined branch names", () => {
19
- for (const mode of ["working", "branch", "committed"] as const) {
20
- expect(Schema.decodeUnknownSync(Vcs.Mode)(mode)).toBe(mode)
21
- }
22
- expect(() => Schema.decodeUnknownSync(Vcs.Mode)("unknown")).toThrow()
23
- })
@@ -1,45 +0,0 @@
1
- import { describe, expect, test } from "bun:test"
2
- import { Schema } from "effect"
3
- import { Worktree } from "../src/worktree.js"
4
-
5
- describe("Worktree.CreateInput", () => {
6
- test("allows the server to choose the destination", () => {
7
- const input = Schema.decodeUnknownSync(Worktree.CreateInput)({
8
- projectID: "project",
9
- })
10
- expect(input.directory).toBeUndefined()
11
- expect(Schema.encodeSync(Worktree.CreateInput)({ ...input, directory: undefined })).toEqual({
12
- projectID: "project",
13
- })
14
- })
15
-
16
- test("preserves an explicit destination", () => {
17
- const input = { projectID: "project", directory: "/custom/worktrees" }
18
- expect(Schema.encodeSync(Worktree.CreateInput)(Schema.decodeUnknownSync(Worktree.CreateInput)(input))).toEqual(
19
- input,
20
- )
21
- })
22
- })
23
-
24
- test("worktree mutations require a project and configuration owns strategy selection", () => {
25
- const value = Schema.decodeUnknownSync(Worktree.CreateInput)({ projectID: "project", name: "task" })
26
- expect(Schema.encodeSync(Worktree.CreateInput)(value)).toEqual({ projectID: "project", name: "task" })
27
- expect(() => Schema.decodeUnknownSync(Worktree.CreateInput)({})).toThrow()
28
- expect(() => Schema.decodeUnknownSync(Worktree.RemoveInput)({ directory: "/repo/task", force: false })).toThrow()
29
- expect(Worktree.CreateInput.fields).not.toHaveProperty("strategy")
30
- expect(Worktree.CreateInput.fields).not.toHaveProperty("location")
31
- expect(Worktree.RemoveInput.fields).not.toHaveProperty("location")
32
- })
33
-
34
- test("inventory contains only the directory and its owning strategy", () => {
35
- const value = Schema.decodeUnknownSync(Worktree.Directory)({ directory: "/repo/task", strategy: "git" })
36
- expect(Schema.encodeSync(Worktree.Directory)(value)).toEqual({ directory: "/repo/task", strategy: "git" })
37
- })
38
-
39
- test("strategy failures can request force confirmation without Core or Git dependencies", () => {
40
- const value = new Worktree.OperationError({ message: "Dirty worktree", forceRequired: true })
41
- expect(value.forceRequired).toBe(true)
42
- expect(
43
- Schema.encodeSync(Worktree.OperationError)(new Worktree.OperationError({ message: "Failed" })),
44
- ).not.toHaveProperty("forceRequired")
45
- })