@zyro-sec/protocol 1.0.0 → 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.
Files changed (61) hide show
  1. package/openapi.json +33222 -0
  2. package/package.json +7 -14
  3. package/script/build.ts +9 -0
  4. package/script/generate-openapi.ts +25 -0
  5. package/script/openapi-parameters.ts +30 -0
  6. package/script/openapi-stabilize.ts +102 -0
  7. package/script/pack.ts +5 -0
  8. package/src/api.ts +264 -0
  9. package/src/client.ts +127 -0
  10. package/src/errors.ts +398 -0
  11. package/src/groups/agent.ts +39 -0
  12. package/src/groups/artifact.ts +103 -0
  13. package/src/groups/automation.ts +75 -0
  14. package/src/groups/blob.ts +20 -0
  15. package/src/groups/command.ts +27 -0
  16. package/src/groups/config.ts +46 -0
  17. package/src/groups/credential.ts +72 -0
  18. package/src/groups/debug.ts +68 -0
  19. package/src/groups/event.ts +86 -0
  20. package/src/groups/experimental.ts +19 -0
  21. package/src/groups/form.ts +26 -0
  22. package/src/groups/fs.ts +136 -0
  23. package/src/groups/generate.ts +120 -0
  24. package/src/groups/integration.ts +230 -0
  25. package/src/groups/job.ts +57 -0
  26. package/src/groups/location.ts +66 -0
  27. package/src/groups/machine.ts +120 -0
  28. package/src/groups/mcp.ts +167 -0
  29. package/src/groups/media.ts +23 -0
  30. package/src/groups/message.ts +124 -0
  31. package/src/groups/migration.ts +28 -0
  32. package/src/groups/model.ts +52 -0
  33. package/src/groups/permission.ts +164 -0
  34. package/src/groups/persistent-pty.ts +153 -0
  35. package/src/groups/plugin.ts +80 -0
  36. package/src/groups/project.ts +51 -0
  37. package/src/groups/provider.ts +45 -0
  38. package/src/groups/pty.ts +153 -0
  39. package/src/groups/push.ts +94 -0
  40. package/src/groups/reference.ts +42 -0
  41. package/src/groups/rpc.ts +30 -0
  42. package/src/groups/server.ts +80 -0
  43. package/src/groups/session.ts +918 -0
  44. package/src/groups/shell.ts +88 -0
  45. package/src/groups/skill.ts +46 -0
  46. package/src/groups/usage.ts +30 -0
  47. package/src/groups/vcs.ts +131 -0
  48. package/src/groups/voice.ts +96 -0
  49. package/src/groups/websearch.ts +46 -0
  50. package/src/groups/worktree.ts +78 -0
  51. package/src/middleware/authorization.ts +6 -0
  52. package/src/middleware/schema-error.ts +7 -0
  53. package/src/simulation.ts +691 -0
  54. package/test/event.test.ts +34 -0
  55. package/test/experimental-identifiers.test.ts +24 -0
  56. package/test/openapi-parameters.test.ts +43 -0
  57. package/test/openapi-patterns.test.ts +28 -0
  58. package/test/openapi-stabilize.test.ts +161 -0
  59. package/test/session-cursor.test.ts +7 -0
  60. package/tsconfig.build.json +11 -0
  61. package/tsconfig.json +14 -0
@@ -0,0 +1,34 @@
1
+ import { expect, test } from "bun:test"
2
+ import { isOpenCodeEvent, OpenCodeEvent, type OpenCodeEventEncoded } from "../src/groups/event.js"
3
+
4
+ type JsonShape<Value> = Value extends string | number | boolean | null
5
+ ? Value
6
+ : Value extends undefined
7
+ ? never
8
+ : Value extends ReadonlyArray<infer Item>
9
+ ? ReadonlyArray<JsonShape<Item>>
10
+ : Value extends object
11
+ ? {
12
+ readonly [Key in keyof Value as undefined extends Value[Key] ? never : Key]: JsonShape<Value[Key]>
13
+ } & {
14
+ readonly [Key in keyof Value as undefined extends Value[Key] ? Key : never]?: JsonShape<
15
+ Exclude<Value[Key], undefined>
16
+ >
17
+ }
18
+ : Value
19
+
20
+ // JSON.stringify omits undefined object properties, so normalize them before
21
+ // requiring every runtime event shape to fit its encoded wire contract.
22
+ const wireReady: [JsonShape<OpenCodeEvent>] extends [JsonShape<OpenCodeEventEncoded>] ? true : false = true
23
+
24
+ test("classifies public events by type", () => {
25
+ expect(isOpenCodeEvent({ type: "server.connected" })).toBe(true)
26
+ expect(isOpenCodeEvent({ type: "mcp.status.changed" })).toBe(true)
27
+ expect(isOpenCodeEvent({ type: "mcp.resources.changed" })).toBe(true)
28
+ expect(isOpenCodeEvent({ type: "mcp.tools.changed" })).toBe(false)
29
+ expect(isOpenCodeEvent({ type: "acme.updated" })).toBe(false)
30
+ })
31
+
32
+ test("keeps public event runtime values within the encoded contract", () => {
33
+ expect(wireReady).toBe(true)
34
+ })
@@ -0,0 +1,24 @@
1
+ import { expect, test } from "bun:test"
2
+ import { OpenApi } from "effect/http-api"
3
+ import { ClientApi } from "../src/client.js"
4
+
5
+ const methods = ["get", "put", "post", "delete", "patch", "head", "options", "trace"] as const
6
+
7
+ test("routes under /api/experimental, and only those, have experimental.* identifiers", () => {
8
+ const operations = Object.entries(OpenApi.fromApi(ClientApi).paths).flatMap(([path, item]) =>
9
+ methods.flatMap((method) => {
10
+ const operation = item[method]
11
+ return operation ? [{ path, identifier: operation.operationId }] : []
12
+ }),
13
+ )
14
+ const offenders = operations
15
+ .filter(
16
+ ({ path, identifier }) =>
17
+ (path === "/api/experimental" || path.startsWith("/api/experimental/")) !==
18
+ identifier.startsWith("experimental."),
19
+ )
20
+ .map(({ path, identifier }) => `${identifier} ${path}`)
21
+
22
+ expect(operations.length).toBeGreaterThan(100)
23
+ expect(offenders).toEqual([])
24
+ })
@@ -0,0 +1,43 @@
1
+ import { expect, test } from "bun:test"
2
+ import { liftParameterDescriptions } from "../script/openapi-parameters.js"
3
+
4
+ const operation = (parameter: object) => ({ paths: { "/test": { get: { parameters: [parameter] } } } })
5
+
6
+ test("moves a schema description onto the parameter", () => {
7
+ expect(
8
+ liftParameterDescriptions(
9
+ operation({ name: "limit", in: "query", schema: { anyOf: [{ type: "string" }], description: "Page size." } }),
10
+ ),
11
+ ).toEqual(
12
+ operation({ name: "limit", in: "query", description: "Page size.", schema: { anyOf: [{ type: "string" }] } }),
13
+ )
14
+ })
15
+
16
+ test("moves a key description out of allOf and unwraps a lone reference", () => {
17
+ expect(
18
+ liftParameterDescriptions(
19
+ operation({
20
+ name: "sessionID",
21
+ in: "path",
22
+ schema: { allOf: [{ $ref: "#/components/schemas/Session.ID" }, { description: "Session ID." }] },
23
+ }),
24
+ ),
25
+ ).toEqual(
26
+ operation({
27
+ name: "sessionID",
28
+ in: "path",
29
+ description: "Session ID.",
30
+ schema: { $ref: "#/components/schemas/Session.ID" },
31
+ }),
32
+ )
33
+ expect(
34
+ liftParameterDescriptions(
35
+ operation({ name: "name", in: "query", schema: { type: "string", allOf: [{ description: "Name." }] } }),
36
+ ),
37
+ ).toEqual(operation({ name: "name", in: "query", description: "Name.", schema: { type: "string" } }))
38
+ })
39
+
40
+ test("keeps a description already on the parameter", () => {
41
+ const document = operation({ name: "cursor", in: "query", description: "Cursor.", schema: { type: "string" } })
42
+ expect(liftParameterDescriptions(document)).toEqual(document)
43
+ })
@@ -0,0 +1,28 @@
1
+ import { expect, test } from "bun:test"
2
+ import { OpenApi } from "effect/http-api"
3
+ import { ClientApi } from "../src/client.js"
4
+
5
+ test("the OpenAPI document keeps string pattern constraints from protocol schemas", () => {
6
+ const patterns = new Set<string>()
7
+ const collect = (value: unknown): void => {
8
+ if (Array.isArray(value)) return value.forEach(collect)
9
+ if (typeof value !== "object" || value === null) return
10
+ Object.entries(value).forEach(([key, item]) => {
11
+ if (key === "pattern" && typeof item === "string") patterns.add(item)
12
+ collect(item)
13
+ })
14
+ }
15
+ collect(OpenApi.fromApi(ClientApi))
16
+
17
+ expect([...patterns]).toEqual(
18
+ expect.arrayContaining([
19
+ "^[^/#]+\\/[^#]+(?:#[^#]+)?$",
20
+ "^[^/#]+$",
21
+ "^[^#]+$",
22
+ "^#[0-9a-fA-F]{6}$",
23
+ "^[a-z0-9][a-z0-9._-]*$",
24
+ "^[a-z][a-z0-9._-]*$",
25
+ "^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$",
26
+ ]),
27
+ )
28
+ })
@@ -0,0 +1,161 @@
1
+ import { expect, test } from "bun:test"
2
+ import { stabilizeOpenApi } from "../script/openapi-stabilize.js"
3
+
4
+ test("content-addresses anonymous components without changing reference siblings", () => {
5
+ const result = stabilizeOpenApi({
6
+ components: {
7
+ schemas: {
8
+ Union_: { anyOf: [{ type: "string" }, { type: "null" }] },
9
+ Union_2: { type: "number" },
10
+ OAuth_2: { type: "string" },
11
+ },
12
+ },
13
+ paths: {
14
+ "/test": {
15
+ schema: { $ref: "#/components/schemas/Union_", description: "nullable value" },
16
+ },
17
+ },
18
+ }) as {
19
+ components: { schemas: Record<string, unknown> }
20
+ paths: { "/test": { schema: { $ref: string; description: string } } }
21
+ }
22
+
23
+ expect(result.paths["/test"].schema.description).toBe("nullable value")
24
+ expect(result.paths["/test"].schema.$ref).toMatch(/^#\/components\/schemas\/Union_[a-f0-9]{12}$/)
25
+ expect(result.components.schemas.OAuth_2).toEqual({ type: "string" })
26
+ })
27
+
28
+ test("keeps anonymous names stable across encounter order and nested ordinals", () => {
29
+ const generate = (nested: string, parent: string) =>
30
+ stabilizeOpenApi({
31
+ components: {
32
+ schemas: {
33
+ Union_: { type: "boolean" },
34
+ Arrays_: { type: "array", items: { type: "boolean" } },
35
+ [parent]: { type: "array", items: { $ref: `#/components/schemas/${nested}` } },
36
+ [nested]: { type: "string" },
37
+ },
38
+ },
39
+ }) as { components: { schemas: Record<string, unknown> } }
40
+
41
+ expect(generate("Union_1", "Arrays_2")).toEqual(generate("Union_9", "Arrays_7"))
42
+ })
43
+
44
+ test("merges structurally identical anonymous components", () => {
45
+ const result = stabilizeOpenApi({
46
+ components: {
47
+ schemas: {
48
+ Union_: { type: "string" },
49
+ Union_2: { type: "string" },
50
+ },
51
+ },
52
+ }) as { components: { schemas: Record<string, unknown> } }
53
+
54
+ expect(Object.keys(result.components.schemas)).toHaveLength(1)
55
+ })
56
+
57
+ test("includes reference siblings in anonymous component hashes", () => {
58
+ const result = stabilizeOpenApi({
59
+ components: {
60
+ schemas: {
61
+ Union_: { type: "string" },
62
+ Arrays_: { type: "array", items: { $ref: "#/components/schemas/Union_", description: "first" } },
63
+ Arrays_2: { type: "array", items: { $ref: "#/components/schemas/Union_", description: "second" } },
64
+ },
65
+ },
66
+ }) as { components: { schemas: Record<string, unknown> } }
67
+
68
+ expect(Object.keys(result.components.schemas).filter((name) => name.startsWith("Arrays_"))).toHaveLength(2)
69
+ })
70
+
71
+ test("content-addresses encounter-order names of encoded variants", () => {
72
+ const generate = (one: string, two: string) =>
73
+ stabilizeOpenApi({
74
+ components: {
75
+ schemas: {
76
+ [one]: { type: "number", enum: [1] },
77
+ [two]: { type: "number", enum: [2] },
78
+ Event: { anyOf: [{ $ref: `#/components/schemas/${one}` }, { $ref: `#/components/schemas/${two}` }] },
79
+ },
80
+ },
81
+ }) as { components: { schemas: Record<string, unknown> } }
82
+
83
+ const result = generate("Event.VersionEncoded_47", "Event.VersionEncoded_37")
84
+ expect(result).toEqual(generate("Event.VersionEncoded_3", "Event.VersionEncoded_9"))
85
+ expect(
86
+ Object.keys(result.components.schemas).filter((name) => /^Event\.VersionEncoded_[a-f0-9]{12}$/.test(name)),
87
+ ).toHaveLength(2)
88
+ })
89
+
90
+ test("folds numbered copies of a named component only when they are deeply equal", () => {
91
+ const ref = (name: string) => ({ $ref: `#/components/schemas/${name}` })
92
+ const result = stabilizeOpenApi({
93
+ components: {
94
+ schemas: {
95
+ Info: { type: "object", properties: { content: ref("Content") }, required: ["content"] },
96
+ Info_1: { required: ["content"], properties: { content: ref("Content_1") }, type: "object" },
97
+ Content: { type: "string" },
98
+ Content_1: { type: "string" },
99
+ Field: { type: "object", properties: { value: ref("Value") } },
100
+ Field_1: { type: "object", properties: { value: ref("Value_1") } },
101
+ Value: { type: "string", enum: ["a", "b"] },
102
+ Value_1: { type: "string", enum: ["b", "a"] },
103
+ },
104
+ },
105
+ paths: { "/info": { schema: ref("Info_1") }, "/field": { schema: ref("Field_1") } },
106
+ }) as {
107
+ components: { schemas: Record<string, unknown> }
108
+ paths: Record<string, { schema: { $ref: string } }>
109
+ }
110
+
111
+ expect(Object.keys(result.components.schemas).sort()).toEqual([
112
+ "Content",
113
+ "Field",
114
+ "Field_1",
115
+ "Info",
116
+ "Value",
117
+ "Value_1",
118
+ ])
119
+ expect(result.paths["/info"].schema).toEqual(ref("Info"))
120
+ expect(result.paths["/field"].schema).toEqual(ref("Field_1"))
121
+ expect(result.components.schemas.Field_1).toEqual({ type: "object", properties: { value: ref("Value_1") } })
122
+ })
123
+
124
+ test("preserves authored synthetic-looking names without an anonymous family root", () => {
125
+ const result = stabilizeOpenApi({
126
+ components: { schemas: { Union_2: { type: "string" } } },
127
+ }) as { components: { schemas: Record<string, unknown> } }
128
+
129
+ expect(result.components.schemas.Union_2).toEqual({ type: "string" })
130
+ })
131
+
132
+ test("folds a chain of copies onto the original without leaving a dangling reference", () => {
133
+ const result = stabilizeOpenApi({
134
+ components: {
135
+ schemas: {
136
+ OAuth: { type: "string" },
137
+ OAuth_2: { type: "string" },
138
+ OAuth_2_1: { type: "string" },
139
+ Holder: { type: "array", items: [{ $ref: "#/components/schemas/OAuth_2_1" }] },
140
+ },
141
+ },
142
+ }) as { components: { schemas: Record<string, { items?: Array<{ $ref: string }> }> } }
143
+
144
+ expect(Object.keys(result.components.schemas).sort()).toEqual(["Holder", "OAuth"])
145
+ expect(result.components.schemas.Holder?.items?.[0]?.$ref).toBe("#/components/schemas/OAuth")
146
+ })
147
+
148
+ test("names an unsuffixed encoded variant by content when suffixed siblings exist", () => {
149
+ const generate = (versions: Array<number>) => {
150
+ const schemas: Record<string, unknown> = {}
151
+ versions.forEach((version, index) => {
152
+ schemas[index === 0 ? "Event.VersionEncoded" : `Event.VersionEncoded_${index}`] = { enum: [version] }
153
+ })
154
+ return stabilizeOpenApi({ components: { schemas } }) as { components: { schemas: Record<string, unknown> } }
155
+ }
156
+
157
+ const forward = generate([2, 1]).components.schemas
158
+ const reversed = generate([1, 2]).components.schemas
159
+ expect(Object.keys(forward)).not.toContain("Event.VersionEncoded")
160
+ expect(forward).toEqual(reversed)
161
+ })
@@ -0,0 +1,7 @@
1
+ import { expect, test } from "bun:test"
2
+ import { Session } from "@zyro-sec/schema/session"
3
+ import { SessionsCursor } from "../src/groups/session.js"
4
+
5
+ test("SessionsCursor remains the canonical session list cursor", () => {
6
+ expect(SessionsCursor).toBe(Session.ListCursor)
7
+ })
@@ -0,0 +1,11 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "extends": "./tsconfig.json",
4
+ "compilerOptions": {
5
+ "rootDir": "src",
6
+ "outDir": "dist",
7
+ "noEmit": false,
8
+ "declaration": true
9
+ },
10
+ "include": ["src"]
11
+ }
package/tsconfig.json ADDED
@@ -0,0 +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
+ }