@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,46 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test"
|
|
2
|
+
import { LegacyEventV1 } from "../src/legacy-event.js"
|
|
3
|
+
import { PermissionV1 } from "../src/permission-v1.js"
|
|
4
|
+
import { Project } from "../src/project.js"
|
|
5
|
+
import { SessionV1 } from "../src/session-v1.js"
|
|
6
|
+
|
|
7
|
+
describe("legacy public event schemas", () => {
|
|
8
|
+
test("owns all SessionV1 definitions", () => {
|
|
9
|
+
expect(SessionV1.Event.Definitions.map((event) => event.type)).toEqual([
|
|
10
|
+
"session.created",
|
|
11
|
+
"session.updated",
|
|
12
|
+
"session.deleted",
|
|
13
|
+
"message.updated",
|
|
14
|
+
"message.removed",
|
|
15
|
+
"message.part.updated",
|
|
16
|
+
"message.part.removed",
|
|
17
|
+
"message.part.delta",
|
|
18
|
+
"session.diff",
|
|
19
|
+
"session.error",
|
|
20
|
+
])
|
|
21
|
+
const durable = SessionV1.Event.Definitions.filter((event) => event.durable !== undefined)
|
|
22
|
+
expect(durable).toHaveLength(7)
|
|
23
|
+
expect(durable.every((event) => event.durable?.aggregate === "sessionID")).toBe(true)
|
|
24
|
+
expect(durable.every((event) => event.durable?.version === 1)).toBe(true)
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
test("owns the legacy transient public definitions", () => {
|
|
28
|
+
expect([
|
|
29
|
+
SessionV1.PartDelta.type,
|
|
30
|
+
SessionV1.Diff.type,
|
|
31
|
+
SessionV1.Error.type,
|
|
32
|
+
PermissionV1.Event.Asked.type,
|
|
33
|
+
PermissionV1.Event.Replied.type,
|
|
34
|
+
Project.Event.Updated.type,
|
|
35
|
+
LegacyEventV1.CommandExecuted.type,
|
|
36
|
+
]).toEqual([
|
|
37
|
+
"message.part.delta",
|
|
38
|
+
"session.diff",
|
|
39
|
+
"session.error",
|
|
40
|
+
"permission.asked",
|
|
41
|
+
"permission.replied",
|
|
42
|
+
"project.updated",
|
|
43
|
+
"command.executed",
|
|
44
|
+
])
|
|
45
|
+
})
|
|
46
|
+
})
|
package/test/mcp.test.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test"
|
|
2
|
+
import { Schema } from "effect"
|
|
3
|
+
import { Mcp } from "../src/mcp.js"
|
|
4
|
+
|
|
5
|
+
describe("Mcp resources", () => {
|
|
6
|
+
test("decodes resource catalogs and omits absent metadata", () => {
|
|
7
|
+
const value = Schema.decodeUnknownSync(Mcp.ResourceCatalog)({
|
|
8
|
+
resources: [{ server: "docs", name: "Readme", uri: "docs://readme" }],
|
|
9
|
+
templates: [{ server: "docs", name: "File", uriTemplate: "docs://{path}" }],
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
expect(Schema.encodeSync(Mcp.ResourceCatalog)(value)).toEqual({
|
|
13
|
+
resources: [{ server: "docs", name: "Readme", uri: "docs://readme" }],
|
|
14
|
+
templates: [{ server: "docs", name: "File", uriTemplate: "docs://{path}" }],
|
|
15
|
+
})
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
test("preserves text and base64 blob contents", () => {
|
|
19
|
+
expect(
|
|
20
|
+
Schema.decodeUnknownSync(Mcp.ResourceContent)({
|
|
21
|
+
server: "docs",
|
|
22
|
+
uri: "docs://readme",
|
|
23
|
+
contents: [
|
|
24
|
+
{ type: "text", uri: "docs://readme", text: "hello", mimeType: "text/plain" },
|
|
25
|
+
{ type: "blob", uri: "docs://logo", blob: "aGVsbG8=", mimeType: "image/png" },
|
|
26
|
+
],
|
|
27
|
+
}),
|
|
28
|
+
).toEqual({
|
|
29
|
+
server: "docs",
|
|
30
|
+
uri: "docs://readme",
|
|
31
|
+
contents: [
|
|
32
|
+
{ type: "text", uri: "docs://readme", text: "hello", mimeType: "text/plain" },
|
|
33
|
+
{ type: "blob", uri: "docs://logo", blob: "aGVsbG8=", mimeType: "image/png" },
|
|
34
|
+
],
|
|
35
|
+
})
|
|
36
|
+
})
|
|
37
|
+
})
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test"
|
|
2
|
+
import { Schema } from "effect"
|
|
3
|
+
import { Model } from "../src/model.js"
|
|
4
|
+
import { Provider } from "../src/provider.js"
|
|
5
|
+
|
|
6
|
+
describe("Model.Ref", () => {
|
|
7
|
+
test("parses model references with optional variants", () => {
|
|
8
|
+
const variant = Model.Ref.parse("openrouter/openai/gpt-5#high")
|
|
9
|
+
expect(String(variant.providerID)).toBe("openrouter")
|
|
10
|
+
expect(String(variant.id)).toBe("openai/gpt-5")
|
|
11
|
+
expect(String(variant.variant)).toBe("high")
|
|
12
|
+
|
|
13
|
+
const standard = Model.Ref.parse("anthropic/claude-sonnet")
|
|
14
|
+
expect(String(standard.providerID)).toBe("anthropic")
|
|
15
|
+
expect(String(standard.id)).toBe("claude-sonnet")
|
|
16
|
+
expect(standard.variant).toBeUndefined()
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
test("rejects malformed model references", () => {
|
|
20
|
+
expect(() => Model.Ref.parse("gpt-5")).toThrow()
|
|
21
|
+
expect(() => Model.Ref.parse("openai/gpt-5#")).toThrow()
|
|
22
|
+
expect(() => Model.Ref.parse("openai/gpt-5#high#extra")).toThrow()
|
|
23
|
+
})
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
describe("Model.ReasoningField", () => {
|
|
27
|
+
test("accepts suggested and custom fields", () => {
|
|
28
|
+
const decode = Schema.decodeUnknownSync(Model.ReasoningField)
|
|
29
|
+
|
|
30
|
+
for (const field of ["reasoning", "reasoning_content", "reasoning_text", "vendor_reasoning"])
|
|
31
|
+
expect(decode(field)).toBe(field)
|
|
32
|
+
})
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
describe("Model.Compatibility", () => {
|
|
36
|
+
test("decodes model compatibility overrides", () => {
|
|
37
|
+
const decode = Schema.decodeUnknownSync(Model.Compatibility)
|
|
38
|
+
|
|
39
|
+
expect(decode({})).toEqual({})
|
|
40
|
+
expect(
|
|
41
|
+
decode({
|
|
42
|
+
reasoningField: "vendor_reasoning",
|
|
43
|
+
requireReasoning: true,
|
|
44
|
+
maxTokensField: "max_completion_tokens",
|
|
45
|
+
requireFinishReason: false,
|
|
46
|
+
requireAssistantAfterTool: true,
|
|
47
|
+
}),
|
|
48
|
+
).toEqual({
|
|
49
|
+
reasoningField: "vendor_reasoning",
|
|
50
|
+
requireReasoning: true,
|
|
51
|
+
maxTokensField: "max_completion_tokens",
|
|
52
|
+
requireFinishReason: false,
|
|
53
|
+
requireAssistantAfterTool: true,
|
|
54
|
+
})
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
test("keeps capability overrides that gate protocol features", () => {
|
|
58
|
+
const decode = Schema.decodeUnknownSync(Model.Compatibility)
|
|
59
|
+
|
|
60
|
+
for (const supportsEffortUpdates of [false, true]) {
|
|
61
|
+
expect(decode({ supportsEffortUpdates, supportsThinkingBlockBinding: true })).toEqual({
|
|
62
|
+
supportsEffortUpdates,
|
|
63
|
+
supportsThinkingBlockBinding: true,
|
|
64
|
+
})
|
|
65
|
+
}
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
test("omits undefined protocol capability overrides when encoded", () => {
|
|
69
|
+
expect(
|
|
70
|
+
Schema.encodeSync(Model.Compatibility)({
|
|
71
|
+
supportsEffortUpdates: undefined,
|
|
72
|
+
supportsThinkingBlockBinding: undefined,
|
|
73
|
+
}),
|
|
74
|
+
).toEqual({})
|
|
75
|
+
})
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
describe("Model.Info", () => {
|
|
79
|
+
test("provider compaction policy is a typed setting", () => {
|
|
80
|
+
const model = Model.Info.default(Provider.ID.openai, Model.ID.make("gpt-5.4-mini"))
|
|
81
|
+
expect(Schema.encodeSync(Model.Info)({ ...model, settings: { compaction: undefined } }).settings).toEqual({})
|
|
82
|
+
expect(
|
|
83
|
+
Schema.decodeUnknownSync(Model.Info)({ ...model, settings: { compaction: { type: "native" } } }).settings,
|
|
84
|
+
).toEqual({
|
|
85
|
+
compaction: { type: "native" },
|
|
86
|
+
})
|
|
87
|
+
expect(Schema.decodeUnknownSync(Provider.Compaction)({ type: "summary" })).toEqual({ type: "summary" })
|
|
88
|
+
expect(() => Schema.decodeUnknownSync(Provider.Compaction)({ type: "automatic" })).toThrow()
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
test("uses practical token limits for unknown models", () => {
|
|
92
|
+
const model = Model.Info.default(Provider.ID.make("custom"), Model.ID.make("gpt-5.6"))
|
|
93
|
+
|
|
94
|
+
expect(model.limit).toEqual({ context: 200_000, output: 32_000 })
|
|
95
|
+
})
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
describe("Model.Settings", () => {
|
|
99
|
+
test("preserves provider-specific model options", () => {
|
|
100
|
+
expect(Schema.decodeUnknownSync(Model.Settings)({ providerOption: true })).toEqual({
|
|
101
|
+
providerOption: true,
|
|
102
|
+
})
|
|
103
|
+
})
|
|
104
|
+
})
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test"
|
|
2
|
+
import { Effect } from "effect"
|
|
3
|
+
import { Session } from "../src/session.js"
|
|
4
|
+
|
|
5
|
+
describe("Session.ListCursor", () => {
|
|
6
|
+
test("round trips without Node globals", async () => {
|
|
7
|
+
const input = {
|
|
8
|
+
search: "protocol",
|
|
9
|
+
order: "desc" as const,
|
|
10
|
+
anchor: { id: Session.ID.make("ses_test"), time: 1, direction: "next" as const },
|
|
11
|
+
}
|
|
12
|
+
const cursor = Session.ListCursor.make(input)
|
|
13
|
+
|
|
14
|
+
expect(await Effect.runPromise(Session.ListCursor.parse(cursor))).toEqual(input)
|
|
15
|
+
})
|
|
16
|
+
})
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test"
|
|
2
|
+
import { Schema } from "effect"
|
|
3
|
+
import { LLM, SessionError } from "../src/index.js"
|
|
4
|
+
|
|
5
|
+
describe("SessionError", () => {
|
|
6
|
+
test("exports one identified open envelope", () => {
|
|
7
|
+
expect(SessionError.Error.ast.annotations?.identifier).toBe("Session.StructuredError")
|
|
8
|
+
expect(Object.keys(SessionError).filter((key) => key !== "SessionError")).toEqual(["Error"])
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
test("round trips current and future error types through JSON", () => {
|
|
12
|
+
const values: SessionError.Error[] = [
|
|
13
|
+
{ type: "provider.rate-limit", message: "Slow down" },
|
|
14
|
+
{ type: "provider.rate-limit", message: "Slow down", status: 429, response: { body: '{"error":{}}' } },
|
|
15
|
+
{ type: "provider.auth", message: "Authentication failed" },
|
|
16
|
+
{ type: "provider.free-limit", message: "Free usage limit reached", status: 429, retryAfterMs: 3_600_000 },
|
|
17
|
+
{ type: "provider.future-condition", message: "A future provider failure" },
|
|
18
|
+
{ type: "unknown", message: "Unexpected" },
|
|
19
|
+
]
|
|
20
|
+
const codec = Schema.fromJsonString(SessionError.Error)
|
|
21
|
+
|
|
22
|
+
for (const value of values) {
|
|
23
|
+
const encoded = Schema.encodeSync(codec)(value)
|
|
24
|
+
expect(Schema.decodeUnknownSync(codec)(encoded)).toEqual(value)
|
|
25
|
+
}
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
test("accepts future fields while exposing only the stable envelope", () => {
|
|
29
|
+
expect(
|
|
30
|
+
Schema.decodeUnknownSync(SessionError.Error)({
|
|
31
|
+
type: "provider.timeout",
|
|
32
|
+
message: "Timeout",
|
|
33
|
+
retryable: true,
|
|
34
|
+
}),
|
|
35
|
+
).toEqual({ type: "provider.timeout", message: "Timeout" })
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
test("rejects missing envelope fields", () => {
|
|
39
|
+
expect(() => Schema.decodeUnknownSync(SessionError.Error)({ type: "provider.auth" })).toThrow()
|
|
40
|
+
expect(() => Schema.decodeUnknownSync(SessionError.Error)({ message: "Missing type" })).toThrow()
|
|
41
|
+
expect(() =>
|
|
42
|
+
Schema.decodeUnknownSync(SessionError.Error)({ type: "provider.auth", message: "Failed", response: {} }),
|
|
43
|
+
).toThrow()
|
|
44
|
+
})
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
test("FinishReason is the closed normalized provider set", () => {
|
|
48
|
+
const reasons = ["stop", "length", "tool-calls", "content-filter", "error", "unknown"] as const
|
|
49
|
+
expect(reasons.map((reason) => Schema.decodeUnknownSync(LLM.FinishReason)(reason))).toEqual([...reasons])
|
|
50
|
+
expect(() => Schema.decodeUnknownSync(LLM.FinishReason)("other")).toThrow()
|
|
51
|
+
})
|
|
@@ -0,0 +1,178 @@
|
|
|
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
|
+
})
|
|
@@ -0,0 +1,50 @@
|
|
|
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
|
+
})
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
})
|
|
@@ -0,0 +1,26 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
})
|
|
@@ -0,0 +1,45 @@
|
|
|
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
|
+
})
|
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
|
+
}
|
package/README.md
DELETED